Skip to content

[mlir][ROCDL] Swap range metadata to range attribute #94853

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
Jun 12, 2024
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 @@ -17,9 +17,9 @@
#include "mlir/IR/Operation.h"
#include "mlir/Target/LLVMIR/ModuleTranslation.h"

#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicsAMDGPU.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/Support/raw_ostream.h"

using namespace mlir;
Expand All @@ -32,12 +32,9 @@ static llvm::Value *createIntrinsicCallWithRange(llvm::IRBuilderBase &builder,
auto *inst = llvm::cast<llvm::CallInst>(
createIntrinsicCall(builder, intrinsic, {}, {}));
if (maybeRange) {
SmallVector<llvm::APInt, 2> apInts;
for (int32_t i : maybeRange.asArrayRef())
apInts.push_back(llvm::APInt(32, i));
llvm::MDBuilder mdBuilder(builder.getContext());
llvm::MDNode *range = mdBuilder.createRange(apInts[0], apInts[1]);
inst->setMetadata(llvm::LLVMContext::MD_range, range);
llvm::ConstantRange Range(APInt(32, maybeRange[0]),
APInt(32, maybeRange[1]));
inst->addRangeRetAttr(Range);
}
return inst;
}
Expand Down
3 changes: 1 addition & 2 deletions mlir/test/Target/LLVMIR/rocdl.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ llvm.func @rocdl_special_regs() -> i32 {
// CHECK: call i64 @__ockl_get_num_groups(i32 2)
%12 = rocdl.grid.dim.z : i64

// CHECK: call i32 @llvm.amdgcn.workitem.id.x(),{{.*}} !range ![[$RANGE:[0-9]+]]
// CHECK: call range(i32 0, 64) i32 @llvm.amdgcn.workitem.id.x()
%13 = rocdl.workitem.id.x {range = array<i32: 0, 64>} : i32

llvm.return %1 : i32
Expand Down Expand Up @@ -520,5 +520,4 @@ llvm.func @rocdl_8bit_floats(%source: i32, %stoch: i32) -> i32 {
// CHECK-DAG: attributes #[[$KERNEL_WORKGROUP_ATTRS]] = { "amdgpu-flat-work-group-size"="1,1024"
// CHECK-DAG: attributes #[[$KNOWN_BLOCK_SIZE_ATTRS]] = { "amdgpu-flat-work-group-size"="128,128"
// CHECK-DAG: attributes #[[$KERNEL_NO_UNIFORM_WORK_GROUPS_ATTRS]] = { "amdgpu-flat-work-group-size"="1,256" "uniform-work-group-size"="false" }
// CHECK-DAG: ![[$RANGE]] = !{i32 0, i32 64}
// CHECK-DAG: ![[$REQD_WORK_GROUP_SIZE]] = !{i32 16, i32 4, i32 2}
Loading