@@ -521,10 +521,14 @@ void ModuleImport::addDebugIntrinsic(llvm::CallInst *intrinsic) {
521
521
522
522
static Attribute convertCGProfileModuleFlagValue (ModuleOp mlirModule,
523
523
llvm::MDTuple *mdTuple) {
524
- auto getFunctionSymbol = [&](const llvm::MDOperand &funcMDO) {
525
- auto *f = cast<llvm::ValueAsMetadata>(funcMDO);
524
+ auto getLLVMFunction =
525
+ [&](const llvm::MDOperand &funcMDO) -> llvm::Function * {
526
+ auto *f = cast_or_null<llvm::ValueAsMetadata>(funcMDO);
527
+ // nullptr is a valid value for the function pointer.
528
+ if (!f)
529
+ return nullptr ;
526
530
auto *llvmFn = cast<llvm::Function>(f->getValue ()->stripPointerCasts ());
527
- return FlatSymbolRefAttr::get (mlirModule-> getContext (), llvmFn-> getName ()) ;
531
+ return llvmFn;
528
532
};
529
533
530
534
// Each tuple element becomes one ModuleFlagCGProfileEntryAttr.
@@ -535,9 +539,17 @@ static Attribute convertCGProfileModuleFlagValue(ModuleOp mlirModule,
535
539
llvm::Constant *llvmConstant =
536
540
cast<llvm::ConstantAsMetadata>(cgEntry->getOperand (2 ))->getValue ();
537
541
uint64_t count = cast<llvm::ConstantInt>(llvmConstant)->getZExtValue ();
542
+ auto *fromFn = getLLVMFunction (cgEntry->getOperand (0 ));
543
+ auto *toFn = getLLVMFunction (cgEntry->getOperand (1 ));
544
+ // FlatSymbolRefAttr::get(mlirModule->getContext(), llvmFn->getName());
538
545
cgProfile.push_back (ModuleFlagCGProfileEntryAttr::get (
539
- mlirModule->getContext (), getFunctionSymbol (cgEntry->getOperand (0 )),
540
- getFunctionSymbol (cgEntry->getOperand (1 )), count));
546
+ mlirModule->getContext (),
547
+ fromFn ? FlatSymbolRefAttr::get (mlirModule->getContext (),
548
+ fromFn->getName ())
549
+ : nullptr ,
550
+ toFn ? FlatSymbolRefAttr::get (mlirModule->getContext (), toFn->getName ())
551
+ : nullptr ,
552
+ count));
541
553
}
542
554
return ArrayAttr::get (mlirModule->getContext (), cgProfile);
543
555
}
@@ -570,7 +582,8 @@ LogicalResult ModuleImport::convertModuleFlagsMetadata() {
570
582
571
583
if (!valAttr) {
572
584
emitWarning (mlirModule.getLoc ())
573
- << " unsupported module flag value: " << diagMD (val, llvmModule.get ());
585
+ << " unsupported module flag value for key '" << key->getString ()
586
+ << " ' : " << diagMD (val, llvmModule.get ());
574
587
continue ;
575
588
}
576
589
0 commit comments