@@ -521,14 +521,14 @@ void ModuleImport::addDebugIntrinsic(llvm::CallInst *intrinsic) {
521521
522522static Attribute convertCGProfileModuleFlagValue (ModuleOp mlirModule,
523523 llvm::MDTuple *mdTuple) {
524- auto getFunctionSymbol =
525- [&](const llvm::MDOperand &funcMDO) -> std::optional<FlatSymbolRefAttr> {
524+ auto getLLVMFunction =
525+ [&](const llvm::MDOperand &funcMDO) -> llvm::Function * {
526526 auto *f = cast_or_null<llvm::ValueAsMetadata>(funcMDO);
527527 // nullptr is a valid value for the function pointer.
528528 if (!f)
529- return std:: nullopt ;
529+ return nullptr ;
530530 auto *llvmFn = cast<llvm::Function>(f->getValue ()->stripPointerCasts ());
531- return FlatSymbolRefAttr::get (mlirModule-> getContext (), llvmFn-> getName ()) ;
531+ return llvmFn;
532532 };
533533
534534 // Each tuple element becomes one ModuleFlagCGProfileEntryAttr.
@@ -539,9 +539,17 @@ static Attribute convertCGProfileModuleFlagValue(ModuleOp mlirModule,
539539 llvm::Constant *llvmConstant =
540540 cast<llvm::ConstantAsMetadata>(cgEntry->getOperand (2 ))->getValue ();
541541 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());
542545 cgProfile.push_back (ModuleFlagCGProfileEntryAttr::get (
543- mlirModule->getContext (), getFunctionSymbol (cgEntry->getOperand (0 )),
544- 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));
545553 }
546554 return ArrayAttr::get (mlirModule->getContext (), cgProfile);
547555}
0 commit comments