[Mlir-commits] [mlir] [MLIR][LLVM] Add CG Profile module flags support (PR #137115)

Tobias Gysi llvmlistbot at llvm.org
Wed Apr 23 23:22:53 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:

I just checked there seems to be a verifier for this metadata so a cast instead of dyn_cast probably works as well.

https://github.com/llvm/llvm-project/pull/137115


More information about the Mlir-commits mailing list