Skip to content

Commit 3d12901

Browse files
authored
[DirectX] Preserve value names in DXILOpLowering. NFC (#108089)
If the value we're replacing has a name, we might as well preserve it.
1 parent 757d8b3 commit 3d12901

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

llvm/lib/Target/DirectX/DXILOpBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ static Error makeOpError(dxil::OpCode OpCode, Twine Msg) {
386386

387387
Expected<CallInst *> DXILOpBuilder::tryCreateOp(dxil::OpCode OpCode,
388388
ArrayRef<Value *> Args,
389+
const Twine &Name,
389390
Type *RetTy) {
390391
const OpCodeProperty *Prop = getOpCodeProperty(OpCode);
391392

@@ -451,12 +452,12 @@ Expected<CallInst *> DXILOpBuilder::tryCreateOp(dxil::OpCode OpCode,
451452
OpArgs.push_back(IRB.getInt32(llvm::to_underlying(OpCode)));
452453
OpArgs.append(Args.begin(), Args.end());
453454

454-
return IRB.CreateCall(DXILFn, OpArgs);
455+
return IRB.CreateCall(DXILFn, OpArgs, Name);
455456
}
456457

457458
CallInst *DXILOpBuilder::createOp(dxil::OpCode OpCode, ArrayRef<Value *> Args,
458-
Type *RetTy) {
459-
Expected<CallInst *> Result = tryCreateOp(OpCode, Args, RetTy);
459+
const Twine &Name, Type *RetTy) {
460+
Expected<CallInst *> Result = tryCreateOp(OpCode, Args, Name, RetTy);
460461
if (Error E = Result.takeError())
461462
llvm_unreachable("Invalid arguments for operation");
462463
return *Result;

llvm/lib/Target/DirectX/DXILOpBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ class DXILOpBuilder {
3939
/// Create a call instruction for the given DXIL op. The arguments
4040
/// must be valid for an overload of the operation.
4141
CallInst *createOp(dxil::OpCode Op, ArrayRef<Value *> Args,
42-
Type *RetTy = nullptr);
42+
const Twine &Name = "", Type *RetTy = nullptr);
4343

4444
/// Try to create a call instruction for the given DXIL op. Fails if the
4545
/// overload is invalid.
4646
Expected<CallInst *> tryCreateOp(dxil::OpCode Op, ArrayRef<Value *> Args,
47+
const Twine &Name = "",
4748
Type *RetTy = nullptr);
4849

4950
/// Get a `%dx.types.ResRet` type with the given element type.

llvm/lib/Target/DirectX/DXILOpLowering.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class OpLowerer {
118118
Args.append(CI->arg_begin(), CI->arg_end());
119119

120120
Expected<CallInst *> OpCall =
121-
OpBuilder.tryCreateOp(DXILOp, Args, F.getReturnType());
121+
OpBuilder.tryCreateOp(DXILOp, Args, CI->getName(), F.getReturnType());
122122
if (Error E = OpCall.takeError())
123123
return E;
124124

@@ -198,7 +198,7 @@ class OpLowerer {
198198
ConstantInt::get(Int32Ty, Binding.RecordID), CI->getArgOperand(3),
199199
CI->getArgOperand(4)};
200200
Expected<CallInst *> OpCall =
201-
OpBuilder.tryCreateOp(OpCode::CreateHandle, Args);
201+
OpBuilder.tryCreateOp(OpCode::CreateHandle, Args, CI->getName());
202202
if (Error E = OpCall.takeError())
203203
return E;
204204

@@ -233,15 +233,16 @@ class OpLowerer {
233233
Binding.LowerBound, UpperBound, Binding.Space, RI.getResourceClass());
234234
std::array<Value *, 3> BindArgs{ResBind, CI->getArgOperand(3),
235235
CI->getArgOperand(4)};
236-
Expected<CallInst *> OpBind =
237-
OpBuilder.tryCreateOp(OpCode::CreateHandleFromBinding, BindArgs);
236+
Expected<CallInst *> OpBind = OpBuilder.tryCreateOp(
237+
OpCode::CreateHandleFromBinding, BindArgs, CI->getName());
238238
if (Error E = OpBind.takeError())
239239
return E;
240240

241241
std::array<Value *, 2> AnnotateArgs{
242242
*OpBind, OpBuilder.getResProps(Props.first, Props.second)};
243-
Expected<CallInst *> OpAnnotate =
244-
OpBuilder.tryCreateOp(OpCode::AnnotateHandle, AnnotateArgs);
243+
Expected<CallInst *> OpAnnotate = OpBuilder.tryCreateOp(
244+
OpCode::AnnotateHandle, AnnotateArgs,
245+
CI->hasName() ? CI->getName() + "_annot" : Twine());
245246
if (Error E = OpAnnotate.takeError())
246247
return E;
247248

@@ -286,7 +287,10 @@ class OpLowerer {
286287
if (!CheckOp) {
287288
Value *NewEVI = IRB.CreateExtractValue(Op, 4);
288289
Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
289-
OpCode::CheckAccessFullyMapped, {NewEVI}, Int32Ty);
290+
OpCode::CheckAccessFullyMapped, {NewEVI},
291+
OldResult->hasName() ? OldResult->getName() + "_check"
292+
: Twine(),
293+
Int32Ty);
290294
if (Error E = OpCall.takeError())
291295
return E;
292296
CheckOp = *OpCall;
@@ -296,7 +300,8 @@ class OpLowerer {
296300
}
297301
}
298302

299-
OldResult = cast<Instruction>(IRB.CreateExtractValue(Op, 0));
303+
OldResult = cast<Instruction>(
304+
IRB.CreateExtractValue(Op, 0, OldResult->getName()));
300305
OldTy = ST->getElementType(0);
301306
}
302307

@@ -403,8 +408,8 @@ class OpLowerer {
403408
Type *NewRetTy = OpBuilder.getResRetType(OldTy->getScalarType());
404409

405410
std::array<Value *, 3> Args{Handle, Index0, Index1};
406-
Expected<CallInst *> OpCall =
407-
OpBuilder.tryCreateOp(OpCode::BufferLoad, Args, NewRetTy);
411+
Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
412+
OpCode::BufferLoad, Args, CI->getName(), NewRetTy);
408413
if (Error E = OpCall.takeError())
409414
return E;
410415
if (Error E = replaceResRetUses(CI, *OpCall, HasCheckBit))
@@ -447,7 +452,7 @@ class OpLowerer {
447452
std::array<Value *, 8> Args{Handle, Index0, Index1, Data0,
448453
Data1, Data2, Data3, Mask};
449454
Expected<CallInst *> OpCall =
450-
OpBuilder.tryCreateOp(OpCode::BufferStore, Args);
455+
OpBuilder.tryCreateOp(OpCode::BufferStore, Args, CI->getName());
451456
if (Error E = OpCall.takeError())
452457
return E;
453458

llvm/test/CodeGen/DirectX/CreateHandleFromBinding.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ define void @test_bindings() {
1919
%typed0 = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
2020
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_1_0_0(
2121
i32 3, i32 5, i32 1, i32 4, i1 false)
22-
; CHECK: [[BUF0:%[0-9]*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 5, i32 5, i32 3, i8 1 }, i32 4, i1 false)
22+
; CHECK: [[BUF0:%.*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 5, i32 5, i32 3, i8 1 }, i32 4, i1 false)
2323
; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF0]], %dx.types.ResourceProperties { i32 4106, i32 1033 })
2424

2525
; RWBuffer<int> Buf : register(u7, space2)
2626
%typed1 = call target("dx.TypedBuffer", i32, 1, 0, 1)
2727
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0_0t(
2828
i32 2, i32 7, i32 1, i32 6, i1 false)
29-
; CHECK: [[BUF1:%[0-9]*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 7, i32 7, i32 2, i8 1 }, i32 6, i1 false)
29+
; CHECK: [[BUF1:%.*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 7, i32 7, i32 2, i8 1 }, i32 6, i1 false)
3030
; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF1]], %dx.types.ResourceProperties { i32 4106, i32 260 })
3131

3232
; Buffer<uint4> Buf[24] : register(t3, space5)
@@ -35,22 +35,22 @@ define void @test_bindings() {
3535
%typed2 = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)
3636
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_0_0_0t(
3737
i32 5, i32 3, i32 24, i32 7, i1 false)
38-
; CHECK: [[BUF2:%[0-9]*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 3, i32 26, i32 5, i8 0 }, i32 7, i1 false)
38+
; CHECK: [[BUF2:%.*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 3, i32 26, i32 5, i8 0 }, i32 7, i1 false)
3939
; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF2]], %dx.types.ResourceProperties { i32 10, i32 1029 })
4040

4141
; struct S { float4 a; uint4 b; };
4242
; StructuredBuffer<S> Buf : register(t2, space4)
4343
%struct0 = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0)
4444
@llvm.dx.handle.fromBinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
4545
i32 4, i32 2, i32 1, i32 10, i1 true)
46-
; CHECK: [[BUF3:%[0-9]*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 2, i32 2, i32 4, i8 0 }, i32 10, i1 true)
46+
; CHECK: [[BUF3:%.*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 2, i32 2, i32 4, i8 0 }, i32 10, i1 true)
4747
; CHECK: = call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF3]], %dx.types.ResourceProperties { i32 1036, i32 32 })
4848

4949
; ByteAddressBuffer Buf : register(t8, space1)
5050
%byteaddr0 = call target("dx.RawBuffer", i8, 0, 0)
5151
@llvm.dx.handle.fromBinding.tdx.RawBuffer_i8_0_0t(
5252
i32 1, i32 8, i32 1, i32 12, i1 false)
53-
; CHECK: [[BUF4:%[0-9]*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 8, i32 8, i32 1, i8 0 }, i32 12, i1 false)
53+
; CHECK: [[BUF4:%.*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 8, i32 8, i32 1, i8 0 }, i32 12, i1 false)
5454
; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF4]], %dx.types.ResourceProperties { i32 11, i32 0 })
5555

5656
; Buffer<float4> Buf[] : register(t0)
@@ -59,7 +59,7 @@ define void @test_bindings() {
5959
%typed3 = call target("dx.TypedBuffer", <4 x float>, 0, 0, 0)
6060
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_0_0_0t(
6161
i32 0, i32 0, i32 -1, i32 %typed3_ix, i1 false)
62-
; CHECK: [[BUF5:%[0-9]*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 0, i32 -1, i32 0, i8 0 }, i32 %typed3_ix, i1 false)
62+
; CHECK: [[BUF5:%.*]] = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 218, %dx.types.ResBind { i32 0, i32 -1, i32 0, i8 0 }, i32 %typed3_ix, i1 false)
6363
; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF5]], %dx.types.ResourceProperties { i32 10, i32 1033 })
6464

6565
ret void

0 commit comments

Comments
 (0)