[Mlir-commits] [mlir] [MLIR][LLVM] Allow strings in module flag value (PR #136793)

Bruno Cardoso Lopes llvmlistbot at llvm.org
Wed Apr 23 16:31:13 PDT 2025


================
@@ -273,10 +273,18 @@ static void convertLinkerOptionsOp(ArrayAttr options,
 static void convertModuleFlagsOp(ArrayAttr flags, llvm::IRBuilderBase &builder,
                                  LLVM::ModuleTranslation &moduleTranslation) {
   llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
-  for (auto flagAttr : flags.getAsRange<ModuleFlagAttr>())
-    llvmModule->addModuleFlag(
-        convertModFlagBehaviorToLLVM(flagAttr.getBehavior()),
-        flagAttr.getKey().getValue(), flagAttr.getValue());
+  for (auto flagAttr : flags.getAsRange<ModuleFlagAttr>()) {
+    if (auto intAttr = dyn_cast<mlir::IntegerAttr>(flagAttr.getValue()))
+      llvmModule->addModuleFlag(
+          convertModFlagBehaviorToLLVM(flagAttr.getBehavior()),
+          flagAttr.getKey().getValue(), intAttr.getUInt());
+    else if (auto strAttr = dyn_cast<mlir::StringAttr>(flagAttr.getValue())) {
----------------
bcardosolopes wrote:

Changed to a type switch, looks nicer!

> We should never see something else than an integer or string here

We can have values that are metadata, but those will come in future PRs.

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


More information about the Mlir-commits mailing list