Skip to content

Commit 4cfbe55

Browse files
authored
[MLIR][LLVM] Import LLVM target triple into MLIR LLVM Dialect (llvm#125084)
It would be essential and useful info to have it in MLIR when we are doing optimizations at MLIR level using LLVM IR as input.
1 parent a5f237f commit 4cfbe55

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

mlir/include/mlir/Target/LLVMIR/ModuleImport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class ModuleImport {
7171
/// specification.
7272
LogicalResult convertDataLayout();
7373

74+
/// Converts target triple of the LLVM module to an MLIR target triple
75+
/// specification.
76+
void convertTargetTriple();
77+
7478
/// Stores the mapping between an LLVM value and its MLIR counterpart.
7579
void mapValue(llvm::Value *llvm, Value mlir) { mapValue(llvm) = mlir; }
7680

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,11 @@ LogicalResult ModuleImport::convertDataLayout() {
662662
return success();
663663
}
664664

665+
void ModuleImport::convertTargetTriple() {
666+
mlirModule->setAttr(LLVM::LLVMDialect::getTargetTripleAttrName(),
667+
builder.getStringAttr(llvmModule->getTargetTriple()));
668+
}
669+
665670
LogicalResult ModuleImport::convertFunctions() {
666671
for (llvm::Function &func : llvmModule->functions())
667672
if (failed(processFunction(&func)))
@@ -2451,6 +2456,6 @@ mlir::translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
24512456
return {};
24522457
if (failed(moduleImport.convertFunctions()))
24532458
return {};
2454-
2459+
moduleImport.convertTargetTriple();
24552460
return module;
24562461
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; RUN: mlir-translate -import-llvm %s | FileCheck %s
2+
; CHECK: module attributes {
3+
; CHECK-SAME: llvm.target_triple = "aarch64-none-linux-android21"
4+
target triple = "aarch64-none-linux-android21"
5+

0 commit comments

Comments
 (0)