[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


================
@@ -270,6 +270,19 @@ static void convertLinkerOptionsOp(ArrayAttr options,
   linkerMDNode->addOperand(listMDNode);
 }
 
+static void convertModuleFlagsOp(ArrayAttr flags, llvm::IRBuilderBase &builder,
+                                 LLVM::ModuleTranslation &moduleTranslation) {
+  llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
+  for (Attribute attr : flags) {
+    auto flag = cast<ModuleFlagAttr>(attr);
+    auto intVal = dyn_cast<IntegerAttr>(flag.getValue());
+    assert(intVal && "expected integer attribute");
+    llvmModule->addModuleFlag(
----------------
xlauko wrote:

What is LLVM's policy about cstyle casts?

I would expect here:

```
auto behavior = static_cast<llvm::Module::ModFlagBehavior>(
    flag.getBehavior().getValue());
auto value = static_cast<uint32_t>(intVal.getUInt());

llvmModule->addModuleFlag(behavior, flag.getKey().getValue(), value);
```

And probably more "correct" way would be to use the following to convert behavior?

```
convertModFlagBehaviorToLLVM(flag.getBehavior())
```


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


More information about the Mlir-commits mailing list