Skip to content
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
11 changes: 11 additions & 0 deletions mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Operation.h"
#include "mlir/Transforms/InliningUtils.h"
#include "llvm/ADT/TypeSwitch.h"

using namespace mlir;
Expand Down Expand Up @@ -180,6 +181,15 @@ void RawBufferAtomicUMinOp::print(mlir::OpAsmPrinter &p) {
// ROCDLDialect initialization, type parsing, and registration.
//===----------------------------------------------------------------------===//

namespace {
struct ROCDLInlinerInterface final : DialectInlinerInterface {
using DialectInlinerInterface::DialectInlinerInterface;
bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
return true;
}
};
} // namespace

// TODO: This should be the llvm.rocdl dialect once this is supported.
void ROCDLDialect::initialize() {
addOperations<
Expand All @@ -194,6 +204,7 @@ void ROCDLDialect::initialize() {

// Support unknown operations because not all ROCDL operations are registered.
allowUnknownOperations();
addInterfaces<ROCDLInlinerInterface>();
declarePromisedInterface<gpu::TargetAttrInterface, ROCDLTargetAttr>();
}

Expand Down
14 changes: 14 additions & 0 deletions mlir/test/Dialect/LLVMIR/inlining-rocdl.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: mlir-opt %s --inline | FileCheck %s

llvm.func @threadidx() -> i32 {
%tid = rocdl.workitem.id.x : i32
llvm.return %tid : i32
}

// CHECK-LABEL: func @caller
llvm.func @caller() -> i32 {
// CHECK-NOT: llvm.call @threadidx
// CHECK: rocdl.workitem.id.x
%z = llvm.call @threadidx() : () -> (i32)
llvm.return %z : i32
}