[Mlir-commits] [mlir] [MLIR][NVVM] Enable inlining of func's calling nvvm intrinsics (PR #122650)

William Moses llvmlistbot at llvm.org
Mon Jan 13 07:43:42 PST 2025


https://github.com/wsmoses updated https://github.com/llvm/llvm-project/pull/122650

>From 333941fc994fc750a241cf531688420fd18dc52d 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-nvvm.mlir      | 16 ++++++++++++++++
 4 files changed, 31 insertions(+)
 create mode 100644 mlir/test/Dialect/LLVMIR/inlining-nvvm.mlir

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 &registry);
 
 } // namespace LLVM
+
+namespace NVVM {
+/// Register the `NVVMInlinerInterface` implementation of
+/// `DialectInlinerInterface` with the NVVM dialect.
+void registerInlinerInterface(DialectRegistry &registry);
+} // 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 &registry) {
   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 &registry) {
     dialect->addInterfaces<LLVMInlinerInterface>();
   });
 }
+
+void mlir::NVVM::registerInlinerInterface(DialectRegistry &registry) {
+  registry.addExtension(+[](MLIRContext *ctx, NVVM::NVVMDialect *dialect) {
+    dialect->addInterfaces<LLVMInlinerInterface>();
+  });
+}
diff --git a/mlir/test/Dialect/LLVMIR/inlining-nvvm.mlir b/mlir/test/Dialect/LLVMIR/inlining-nvvm.mlir
new file mode 100644
index 00000000000000..6dc8ebb4315082
--- /dev/null
+++ b/mlir/test/Dialect/LLVMIR/inlining-nvvm.mlir
@@ -0,0 +1,16 @@
+// RUN: mlir-opt %s -inline -split-input-file | FileCheck %s
+
+// UNSUPPORTED: system-windows
+
+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
+}



More information about the Mlir-commits mailing list