[Mlir-commits] [mlir] [MLIR][LLVM] Add CG Profile module flags support (PR #137115)
Christian Ulmann
llvmlistbot at llvm.org
Thu Apr 24 03:51:44 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);
+ llvm::Constant *llvmConstant =
+ cast<llvm::ConstantAsMetadata>(cgEntry->getOperand(2))->getValue();
+ uint64_t count = cast<llvm::ConstantInt>(llvmConstant)->getZExtValue();
+ cgProfile.push_back(ModuleFlagCGProfileEntryAttr::get(
+ mlirModule->getContext(), getFunctionSymbol(cgEntry->getOperand(0)),
+ getFunctionSymbol(cgEntry->getOperand(1)), count));
+ }
+ return ArrayAttr::get(mlirModule->getContext(), cgProfile);
+}
+
+// Invoke specific handlers for each known module flag value, returns nullptr if
+// the key is unknown or unimplemented.
----------------
Dinistro wrote:
```suggestion
/// Invoke specific handlers for each known module flag value, returns nullptr if
/// the key is unknown or unimplemented.
```
https://github.com/llvm/llvm-project/pull/137115
More information about the Mlir-commits
mailing list