diff options
author | gitoleg <forown@yandex.ru> | 2025-07-31 15:10:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-31 14:10:21 +0200 |
commit | 49b001474229cd935bf71340bb327f03721d9d00 (patch) | |
tree | 931aaf7ebb69da5d71bb8c5a7ab48d307b565319 /mlir/lib/Target/LLVMIR/ModuleImport.cpp | |
parent | 7f5655c50793444b1c3ce3ecea332efc03b9b323 (diff) | |
download | llvm-49b001474229cd935bf71340bb327f03721d9d00.zip llvm-49b001474229cd935bf71340bb327f03721d9d00.tar.gz llvm-49b001474229cd935bf71340bb327f03721d9d00.tar.bz2 |
[mlir][llvm] adds an attribute for the module level assembly (#151318)
Adds support for the module level assembly in the LLVM IR dialect.
---------
Co-authored-by: Tobias Gysi <tobias.gysi@nextsilicon.com>
Diffstat (limited to 'mlir/lib/Target/LLVMIR/ModuleImport.cpp')
-rw-r--r-- | mlir/lib/Target/LLVMIR/ModuleImport.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp index a207cce..6325480 100644 --- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp @@ -30,6 +30,7 @@ #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/ScopeExit.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/IR/Comdat.h" #include "llvm/IR/Constants.h" @@ -1063,6 +1064,18 @@ void ModuleImport::convertTargetTriple() { builder.getStringAttr(llvmModule->getTargetTriple().str())); } +void ModuleImport::convertModuleLevelAsm() { + llvm::StringRef asmStr = llvmModule->getModuleInlineAsm(); + llvm::SmallVector<mlir::Attribute> asmArrayAttr; + + for (llvm::StringRef line : llvm::split(asmStr, '\n')) + if (!line.empty()) + asmArrayAttr.push_back(builder.getStringAttr(line)); + + mlirModule->setAttr(LLVM::LLVMDialect::getModuleLevelAsmAttrName(), + builder.getArrayAttr(asmArrayAttr)); +} + LogicalResult ModuleImport::convertFunctions() { for (llvm::Function &func : llvmModule->functions()) if (failed(processFunction(&func))) @@ -3195,5 +3208,6 @@ OwningOpRef<ModuleOp> mlir::translateLLVMIRToModule( if (failed(moduleImport.convertIFuncs())) return {}; moduleImport.convertTargetTriple(); + moduleImport.convertModuleLevelAsm(); return module; } |