Skip to content

Commit a02be32

Browse files
committed
[mlir][llvm] adds an attribute for the module level assembly
1 parent 95b423e commit a02be32

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def LLVM_Dialect : Dialect {
7171
return "llvm.emit_c_interface";
7272
}
7373

74+
/// Name of the module level assembly attribute.
75+
static StringRef getModuleLevelAsmAttrName() { return "llvm.module_asm"; }
76+
7477
/// Returns `true` if the given type is compatible with the LLVM dialect.
7578
static bool isCompatibleType(Type);
7679

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,10 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
15311531
m->getDiscardableAttr(LLVM::LLVMDialect::getTargetTripleAttrName()))
15321532
llvmModule->setTargetTriple(cast<StringAttr>(targetTripleAttr).getValue());
15331533

1534+
if (auto asmAttr =
1535+
m->getDiscardableAttr(LLVM::LLVMDialect::getModuleLevelAsmAttrName()))
1536+
llvmModule->setModuleInlineAsm(cast<StringAttr>(asmAttr).getValue());
1537+
15341538
return llvmModule;
15351539
}
15361540

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
2+
3+
module attributes {llvm.module_asm = "foo"} {}
4+
5+
// CHECK: module asm "foo"

0 commit comments

Comments
 (0)