diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleImport.h b/mlir/include/mlir/Target/LLVMIR/ModuleImport.h index 84aecbd4373e0..80ae4d679624c 100644 --- a/mlir/include/mlir/Target/LLVMIR/ModuleImport.h +++ b/mlir/include/mlir/Target/LLVMIR/ModuleImport.h @@ -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; } diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp index e23ffdedd9a60..5ebde22cccbdf 100644 --- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp @@ -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))) @@ -2451,6 +2456,6 @@ mlir::translateLLVMIRToModule(std::unique_ptr llvmModule, return {}; if (failed(moduleImport.convertFunctions())) return {}; - + moduleImport.convertTargetTriple(); return module; } diff --git a/mlir/test/Target/LLVMIR/Import/target-triple.ll b/mlir/test/Target/LLVMIR/Import/target-triple.ll new file mode 100644 index 0000000000000..a04b41a7aeb55 --- /dev/null +++ b/mlir/test/Target/LLVMIR/Import/target-triple.ll @@ -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" +