[Mlir-commits] [mlir] 4cfbe55 - [MLIR][LLVM] Import LLVM target triple into MLIR LLVM Dialect (#125084)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jan 31 02:26:43 PST 2025
Author: Guojin
Date: 2025-01-31T11:26:39+01:00
New Revision: 4cfbe55d9157054c62a63aa4597305afa7e8bfa1
URL: https://github.com/llvm/llvm-project/commit/4cfbe55d9157054c62a63aa4597305afa7e8bfa1
DIFF: https://github.com/llvm/llvm-project/commit/4cfbe55d9157054c62a63aa4597305afa7e8bfa1.diff
LOG: [MLIR][LLVM] Import LLVM target triple into MLIR LLVM Dialect (#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.
Added:
mlir/test/Target/LLVMIR/Import/target-triple.ll
Modified:
mlir/include/mlir/Target/LLVMIR/ModuleImport.h
mlir/lib/Target/LLVMIR/ModuleImport.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleImport.h b/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
index 84aecbd4373e05..80ae4d679624c2 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 e23ffdedd9a60c..5ebde22cccbdf3 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<llvm::Module> 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 00000000000000..a04b41a7aeb551
--- /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"
+
More information about the Mlir-commits
mailing list