Skip to content

[MLIR][NVVM] Enable inlining of func's calling nvvm intrinsics #122650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions mlir/include/mlir/InitAllDialects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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>();
});
}
16 changes: 16 additions & 0 deletions mlir/test/Dialect/LLVMIR/inlining-nvvm.mlir
Original file line number Diff line number Diff line change
@@ -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
}
Loading