Skip to content

Commit 133197a

Browse files
authored
[mlir][ROCDL] Swap range metadata to range attribute (#94853)
Swap out range metadata to range attribute for calls to be able to deprecate range metadata on calls in the future.
1 parent 57e4360 commit 133197a

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

mlir/lib/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include "mlir/IR/Operation.h"
1818
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
1919

20+
#include "llvm/IR/ConstantRange.h"
2021
#include "llvm/IR/IRBuilder.h"
2122
#include "llvm/IR/IntrinsicsAMDGPU.h"
22-
#include "llvm/IR/MDBuilder.h"
2323
#include "llvm/Support/raw_ostream.h"
2424

2525
using namespace mlir;
@@ -32,12 +32,9 @@ static llvm::Value *createIntrinsicCallWithRange(llvm::IRBuilderBase &builder,
3232
auto *inst = llvm::cast<llvm::CallInst>(
3333
createIntrinsicCall(builder, intrinsic, {}, {}));
3434
if (maybeRange) {
35-
SmallVector<llvm::APInt, 2> apInts;
36-
for (int32_t i : maybeRange.asArrayRef())
37-
apInts.push_back(llvm::APInt(32, i));
38-
llvm::MDBuilder mdBuilder(builder.getContext());
39-
llvm::MDNode *range = mdBuilder.createRange(apInts[0], apInts[1]);
40-
inst->setMetadata(llvm::LLVMContext::MD_range, range);
35+
llvm::ConstantRange Range(APInt(32, maybeRange[0]),
36+
APInt(32, maybeRange[1]));
37+
inst->addRangeRetAttr(Range);
4138
}
4239
return inst;
4340
}

mlir/test/Target/LLVMIR/rocdl.mlir

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ llvm.func @rocdl_special_regs() -> i32 {
2727
// CHECK: call i64 @__ockl_get_num_groups(i32 2)
2828
%12 = rocdl.grid.dim.z : i64
2929

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

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

0 commit comments

Comments
 (0)