[Mlir-commits] [mlir] [mlir][llvm] adds an attribute for the module level assembly (PR #151318)

Tobias Gysi llvmlistbot at llvm.org
Thu Jul 31 04:17:27 PDT 2025


================
@@ -2276,6 +2276,24 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
     llvmModule->setTargetTriple(
         llvm::Triple(cast<StringAttr>(targetTripleAttr).getValue()));
 
+  if (auto asmAttr = m->getDiscardableAttr(
+          LLVM::LLVMDialect::getModuleLevelAsmAttrName())) {
+    if (!isa<ArrayAttr>(asmAttr)) {
+      m->emitError("expected an array attribute for a module level asm");
+      return nullptr;
+    }
+
+    auto arr = cast<ArrayAttr>(asmAttr);
+    for (auto elt : arr) {
+      if (!isa<StringAttr>(elt)) {
+        m->emitError(
+            "expected a string attribute for each entry of a module level asm");
+        return nullptr;
+      }
+      llvmModule->appendModuleInlineAsm(cast<StringAttr>(elt).getValue());
+    }
----------------
gysit wrote:

```suggestion
    for (Attribute asmAttr : asmArrayAttr) {
      auto asmStrAttr = dyn_cast<StringAttr>(asmAttr);
      if (!asmStrAttr) {
        m->emitError(
            "expected a string attribute for each entry of a module level asm");
        return nullptr;
      }
      llvmModule->appendModuleInlineAsm(asmStrAttr.getValue());
    }
```
nit: Here as well.

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


More information about the Mlir-commits mailing list