Skip to content

Commit 0c16896

Browse files
committed
[MLIR][NVVM] Enable inlining of func's calling nvvm intrinsics
1 parent b4ce29a commit 0c16896

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

mlir/include/mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ namespace LLVM {
2323
void registerInlinerInterface(DialectRegistry &registry);
2424

2525
} // namespace LLVM
26+
27+
namespace NVVM {
28+
/// Register the `NVVMInlinerInterface` implementation of
29+
/// `DialectInlinerInterface` with the NVVM dialect.
30+
void registerInlinerInterface(DialectRegistry &registry);
31+
}
32+
2633
} // namespace mlir
2734

2835
#endif // MLIR_DIALECT_LLVMIR_TRANSFORMS_INLINERINTERFACEIMPL_H

mlir/include/mlir/InitAllDialects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ inline void registerAllDialects(DialectRegistry &registry) {
167167
gpu::registerBufferDeallocationOpInterfaceExternalModels(registry);
168168
gpu::registerValueBoundsOpInterfaceExternalModels(registry);
169169
LLVM::registerInlinerInterface(registry);
170+
NVVM::registerInlinerInterface(registry);
170171
linalg::registerAllDialectInterfaceImplementations(registry);
171172
linalg::registerRuntimeVerifiableOpInterfaceExternalModels(registry);
172173
memref::registerAllocationOpInterfaceExternalModels(registry);

mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h"
1515
#include "mlir/Analysis/SliceWalk.h"
1616
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
17+
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
1718
#include "mlir/IR/Matchers.h"
1819
#include "mlir/Interfaces/DataLayoutInterfaces.h"
1920
#include "mlir/Interfaces/ViewLikeInterface.h"
@@ -815,3 +816,9 @@ void mlir::LLVM::registerInlinerInterface(DialectRegistry &registry) {
815816
dialect->addInterfaces<LLVMInlinerInterface>();
816817
});
817818
}
819+
820+
void mlir::NVVM::registerInlinerInterface(DialectRegistry &registry) {
821+
registry.addExtension(+[](MLIRContext *ctx, NVVM::NVVMDialect *dialect) {
822+
dialect->addInterfaces<LLVMInlinerInterface>();
823+
});
824+
}

mlir/test/Dialect/LLVMIR/inlining.mlir

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,21 @@ llvm.func @caller(%ptr : !llvm.ptr) -> i32 {
641641

642642
// -----
643643

644+
llvm.func @threadidx() -> i32 {
645+
%tid = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
646+
llvm.return %tid : i32
647+
}
648+
649+
// CHECK-LABEL: func @caller
650+
llvm.func @caller() -> i32 {
651+
// CHECK-NOT: llvm.call @private_func
652+
// CHECK: call i32 @llvm.nvvm.read.ptx.sreg.tid.x
653+
%z = llvm.call @private_func() : () -> (i32)
654+
llvm.return %z : i32
655+
}
656+
657+
// -----
658+
644659
llvm.func @vararg_func(...) {
645660
llvm.return
646661
}

0 commit comments

Comments
 (0)