[Mlir-commits] [mlir] [MLIR][LLVMIR] Add module flags support (PR #130679)
Henrich Lauko
llvmlistbot at llvm.org
Tue Mar 11 01:18:46 PDT 2025
================
@@ -517,6 +517,45 @@ void ModuleImport::addDebugIntrinsic(llvm::CallInst *intrinsic) {
debugIntrinsics.insert(intrinsic);
}
+LogicalResult ModuleImport::convertModuleFlagsMetadata() {
+ SmallVector<llvm::Module::ModuleFlagEntry, 4> llvmModuleFlags;
+ for (const llvm::NamedMDNode &named : llvmModule->named_metadata()) {
+ if (named.getName() != LLVMDialect::getModuleFlags())
+ continue;
+ llvmModule->getModuleFlagsMetadata(llvmModuleFlags);
+ break; // there can only be one module flags.
+ }
+
+ SmallVector<Attribute, 4> moduleFlags;
+ for (const auto [behavior, key, val] : llvmModuleFlags) {
+ // Currently only supports most common: int constant values.
+ auto *constInt = llvm::mdconst::dyn_extract<llvm::ConstantInt>(val);
+ if (!constInt) {
+ return emitWarning(mlirModule.getLoc())
+ << "unsupported module flag value: "
+ << diagMD(val, llvmModule.get())
+ << ", only constant integer currently supported";
+ }
+ auto valAttr = builder.getIntegerAttr(
+ IntegerType::get(context, constInt->getType()->getIntegerBitWidth()),
+ constInt->getValue());
+
+ ModFlagBehaviorAttr behaviorAttr = ModFlagBehaviorAttr::get(
+ builder.getContext(), (ModFlagBehavior)behavior);
----------------
xlauko wrote:
```suggestion
auto behaviorAttr = builder.getAttr<ModFlagBehaviorAttr>(
static_cast<ModFlagBehavior>(behavior));
```
^ again maybe `convertModFlagBehaviorFromLLVM` might be "more" correct
https://github.com/llvm/llvm-project/pull/130679
More information about the Mlir-commits
mailing list