Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mlir/include/mlir/Target/LLVMIR/ModuleImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class ModuleImport {
/// specification.
LogicalResult convertDataLayout();

/// Converts target triple of the LLVM module to an MLIR target triple
/// specification.
void convertTargetTriple();

/// Stores the mapping between an LLVM value and its MLIR counterpart.
void mapValue(llvm::Value *llvm, Value mlir) { mapValue(llvm) = mlir; }

Expand Down
7 changes: 6 additions & 1 deletion mlir/lib/Target/LLVMIR/ModuleImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,11 @@ LogicalResult ModuleImport::convertDataLayout() {
return success();
}

void ModuleImport::convertTargetTriple() {
mlirModule->setAttr(LLVM::LLVMDialect::getTargetTripleAttrName(),
builder.getStringAttr(llvmModule->getTargetTriple()));
}

LogicalResult ModuleImport::convertFunctions() {
for (llvm::Function &func : llvmModule->functions())
if (failed(processFunction(&func)))
Expand Down Expand Up @@ -2451,6 +2456,6 @@ mlir::translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
return {};
if (failed(moduleImport.convertFunctions()))
return {};

moduleImport.convertTargetTriple();
return module;
}
5 changes: 5 additions & 0 deletions mlir/test/Target/LLVMIR/Import/target-triple.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; RUN: mlir-translate -import-llvm %s | FileCheck %s
; CHECK: module attributes {
; CHECK-SAME: llvm.target_triple = "aarch64-none-linux-android21"
target triple = "aarch64-none-linux-android21"