[Mlir-commits] [mlir] [MLIR][LLVM] Add CG Profile module flags support (PR #137115)
Tobias Gysi
llvmlistbot at llvm.org
Wed Apr 23 23:20:40 PDT 2025
================
@@ -519,6 +519,39 @@ void ModuleImport::addDebugIntrinsic(llvm::CallInst *intrinsic) {
debugIntrinsics.insert(intrinsic);
}
+static Attribute convertCGProfileModuleFlagValue(ModuleOp mlirModule,
+ llvm::MDTuple *mdTuple) {
+ auto getFunctionSymbol = [&](const llvm::MDOperand &funcMDO) {
+ auto *f = cast<llvm::ValueAsMetadata>(funcMDO);
+ auto *llvmFn = cast<llvm::Function>(f->getValue()->stripPointerCasts());
+ return FlatSymbolRefAttr::get(mlirModule->getContext(), llvmFn->getName());
+ };
+
+ // Each tuple element becomes one ModuleFlagCGProfileEntryAttr.
+ SmallVector<Attribute> cgProfile;
+ for (unsigned i = 0; i < mdTuple->getNumOperands(); i++) {
+ const llvm::MDOperand &mdo = mdTuple->getOperand(i);
+ auto *cgEntry = dyn_cast_or_null<llvm::MDNode>(mdo);
----------------
gysit wrote:
```suggestion
auto *cgEntry = dyn_cast_or_null<llvm::MDNode>(mdo);
```
Should we check here that cgEntry is not null or maybe cast to assert since we know it is non-null?
In general I think it is good to be conservative in such cases. I.e. we could just add a nullptr to the cgProfile array and then return nullptr at the end if any of the cgProfile entries.
https://github.com/llvm/llvm-project/pull/137115
More information about the Mlir-commits
mailing list