[Mlir-commits] [mlir] 2ef7e20 - [MLIR] Enable converting dialect attributes on external functions
Sergio Afonso
llvmlistbot at llvm.org
Wed Aug 9 04:51:08 PDT 2023
Author: Sergio Afonso
Date: 2023-08-09T12:50:47+01:00
New Revision: 2ef7e2085fd62615e32c3c71348c2ec0317d31c3
URL: https://github.com/llvm/llvm-project/commit/2ef7e2085fd62615e32c3c71348c2ec0317d31c3
DIFF: https://github.com/llvm/llvm-project/commit/2ef7e2085fd62615e32c3c71348c2ec0317d31c3.diff
LOG: [MLIR] Enable converting dialect attributes on external functions
This patch modifies the MLIR-to-LLVMIR translation pass to enable dialect
attributes attached to external functions being processed by the corresponding
dialect's translation interface via `amendOperation()`.
Differential Revision: https://reviews.llvm.org/D156988
Added:
mlir/test/Target/LLVMIR/external-func-dialect-attr.mlir
Modified:
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 7ec7e6528571e0..3071af6c90cd56 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1060,9 +1060,13 @@ LogicalResult ModuleTranslation::convertFunctionSignatures() {
LogicalResult ModuleTranslation::convertFunctions() {
// Convert functions.
for (auto function : getModuleBody(mlirModule).getOps<LLVMFuncOp>()) {
- // Ignore external functions.
- if (function.isExternal())
+ // Do not convert external functions, but do process dialect attributes
+ // attached to them.
+ if (function.isExternal()) {
+ if (failed(convertDialectAttributes(function)))
+ return failure();
continue;
+ }
if (failed(convertOneFunction(function)))
return failure();
diff --git a/mlir/test/Target/LLVMIR/external-func-dialect-attr.mlir b/mlir/test/Target/LLVMIR/external-func-dialect-attr.mlir
new file mode 100644
index 00000000000000..6605f10f128e61
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/external-func-dialect-attr.mlir
@@ -0,0 +1,11 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// Check that dialect attributes are processed for external functions.
+// This might not be an intended use case for `nvvm.minctasm`, but it enables
+// testing this feature easily.
+
+module {
+ llvm.func external @f() attributes { nvvm.minctasm = 10 : i32 }
+ // CHECK: !nvvm.annotations = !{![[NVVM:[0-9]+]]}
+ // CHECK: ![[NVVM]] = !{ptr @f, !"minctasm", i32 10}
+}
More information about the Mlir-commits
mailing list