[Mlir-commits] [mlir] [MLIR][NVVM] Enable inlining of func's calling nvvm intrinsics (PR #122650)
William Moses
llvmlistbot at llvm.org
Sun Jan 12 13:56:40 PST 2025
https://github.com/wsmoses updated https://github.com/llvm/llvm-project/pull/122650
>From 9b4bf06be33f0fe6a4c487bb9244d8c0f6acab3f Mon Sep 17 00:00:00 2001
From: "William S. Moses" <gh at wsmoses.com>
Date: Sun, 12 Jan 2025 16:50:56 -0500
Subject: [PATCH] [MLIR][NVVM] Enable inlining of func's calling nvvm
intrinsics
---
.../LLVMIR/Transforms/InlinerInterfaceImpl.h | 7 +++++++
mlir/include/mlir/InitAllDialects.h | 1 +
.../LLVMIR/Transforms/InlinerInterfaceImpl.cpp | 7 +++++++
mlir/test/Dialect/LLVMIR/inlining.mlir | 15 +++++++++++++++
4 files changed, 30 insertions(+)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h b/mlir/include/mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h
index e99b0476a6b107..69cc2e32285b62 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h
+++ b/mlir/include/mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h
@@ -23,6 +23,13 @@ namespace LLVM {
void registerInlinerInterface(DialectRegistry ®istry);
} // namespace LLVM
+
+namespace NVVM {
+/// Register the `NVVMInlinerInterface` implementation of
+/// `DialectInlinerInterface` with the NVVM dialect.
+void registerInlinerInterface(DialectRegistry ®istry);
+} // namespace NVVM
+
} // namespace mlir
#endif // MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H
diff --git a/mlir/include/mlir/InitAllDialects.h b/mlir/include/mlir/InitAllDialects.h
index c102f811cce4b1..0da82825c82878 100644
--- a/mlir/include/mlir/InitAllDialects.h
+++ b/mlir/include/mlir/InitAllDialects.h
@@ -167,6 +167,7 @@ inline void registerAllDialects(DialectRegistry ®istry) {
gpu::registerBufferDeallocationOpInterfaceExternalModels(registry);
gpu::registerValueBoundsOpInterfaceExternalModels(registry);
LLVM::registerInlinerInterface(registry);
+ NVVM::registerInlinerInterface(registry);
linalg::registerAllDialectInterfaceImplementations(registry);
linalg::registerRuntimeVerifiableOpInterfaceExternalModels(registry);
memref::registerAllocationOpInterfaceExternalModels(registry);
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
index b3bed5ab5f412f..233cadebeec026 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
@@ -14,6 +14,7 @@
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
#include "mlir/Analysis/SliceWalk.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Interfaces/DataLayoutInterfaces.h"
#include "mlir/Interfaces/ViewLikeInterface.h"
@@ -815,3 +816,9 @@ void mlir::LLVM::registerInlinerInterface(DialectRegistry ®istry) {
dialect->addInterfaces<LLVMInlinerInterface>();
});
}
+
+void mlir::NVVM::registerInlinerInterface(DialectRegistry ®istry) {
+ registry.addExtension(+[](MLIRContext *ctx, NVVM::NVVMDialect *dialect) {
+ dialect->addInterfaces<LLVMInlinerInterface>();
+ });
+}
diff --git a/mlir/test/Dialect/LLVMIR/inlining.mlir b/mlir/test/Dialect/LLVMIR/inlining.mlir
index edaac4da0b044c..8212a4001e047a 100644
--- a/mlir/test/Dialect/LLVMIR/inlining.mlir
+++ b/mlir/test/Dialect/LLVMIR/inlining.mlir
@@ -641,6 +641,21 @@ llvm.func @caller(%ptr : !llvm.ptr) -> i32 {
// -----
+llvm.func @threadidx() -> i32 {
+ %tid = nvvm.read.ptx.sreg.tid.x : i32
+ llvm.return %tid : i32
+}
+
+// CHECK-LABEL: func @caller
+llvm.func @caller() -> i32 {
+ // CHECK-NOT: llvm.call @threadidx
+ // CHECK: nvvm.read.ptx.sreg.tid.x
+ %z = llvm.call @threadidx() : () -> (i32)
+ llvm.return %z : i32
+}
+
+// -----
+
llvm.func @vararg_func(...) {
llvm.return
}
More information about the Mlir-commits
mailing list