[Mlir-commits] [mlir] [mlir][llvm] adds an attribute for the module level assembly (PR #151318)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jul 30 05:48:27 PDT 2025
https://github.com/gitoleg updated https://github.com/llvm/llvm-project/pull/151318
>From dd8b762c237f4a7a8c4087757f695a0879c8f05b Mon Sep 17 00:00:00 2001
From: gitoleg <forown at yandex.ru>
Date: Wed, 30 Jul 2025 15:36:44 +0300
Subject: [PATCH] [mlir][llvm] adds an attribute for the module level assembly
---
mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td | 3 +++
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 4 ++++
mlir/test/Target/LLVMIR/module-asm.mlir | 5 +++++
3 files changed, 12 insertions(+)
create mode 100644 mlir/test/Target/LLVMIR/module-asm.mlir
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td
index b5ea8fc5da500..107bf3edb657a 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td
@@ -83,6 +83,9 @@ def LLVM_Dialect : Dialect {
return "llvm.emit_c_interface";
}
+ /// Name of the module level assembly attribute.
+ static StringRef getModuleLevelAsmAttrName() { return "llvm.module_asm"; }
+
/// Name of the dependent libraries attribute.
static StringRef getDependentLibrariesAttrName() {
return "llvm.dependent_libraries";
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index b997e559885e2..2c2ef598aa6a9 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -2276,6 +2276,10 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
llvmModule->setTargetTriple(
llvm::Triple(cast<StringAttr>(targetTripleAttr).getValue()));
+ if (auto asmAttr =
+ m->getDiscardableAttr(LLVM::LLVMDialect::getModuleLevelAsmAttrName()))
+ llvmModule->setModuleInlineAsm(cast<StringAttr>(asmAttr).getValue());
+
return llvmModule;
}
diff --git a/mlir/test/Target/LLVMIR/module-asm.mlir b/mlir/test/Target/LLVMIR/module-asm.mlir
new file mode 100644
index 0000000000000..fa8158ac2677a
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/module-asm.mlir
@@ -0,0 +1,5 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+module attributes {llvm.module_asm = "foo"} {}
+
+// CHECK: module asm "foo"
\ No newline at end of file
More information about the Mlir-commits
mailing list