Skip to content

Commit dd8b762

Browse files
committed
[mlir][llvm] adds an attribute for the module level assembly
1 parent 9164d20 commit dd8b762

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
@@ -83,6 +83,9 @@ def LLVM_Dialect : Dialect {
8383
return "llvm.emit_c_interface";
8484
}
8585

86+
/// Name of the module level assembly attribute.
87+
static StringRef getModuleLevelAsmAttrName() { return "llvm.module_asm"; }
88+
8689
/// Name of the dependent libraries attribute.
8790
static StringRef getDependentLibrariesAttrName() {
8891
return "llvm.dependent_libraries";

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,10 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
22762276
llvmModule->setTargetTriple(
22772277
llvm::Triple(cast<StringAttr>(targetTripleAttr).getValue()));
22782278

2279+
if (auto asmAttr =
2280+
m->getDiscardableAttr(LLVM::LLVMDialect::getModuleLevelAsmAttrName()))
2281+
llvmModule->setModuleInlineAsm(cast<StringAttr>(asmAttr).getValue());
2282+
22792283
return llvmModule;
22802284
}
22812285

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)