diff --git a/llvm/lib/Target/DirectX/DXILOpBuilder.cpp b/llvm/lib/Target/DirectX/DXILOpBuilder.cpp index 3b2a5f5061eb..7719d6b10791 100644 --- a/llvm/lib/Target/DirectX/DXILOpBuilder.cpp +++ b/llvm/lib/Target/DirectX/DXILOpBuilder.cpp @@ -386,6 +386,7 @@ static Error makeOpError(dxil::OpCode OpCode, Twine Msg) { Expected DXILOpBuilder::tryCreateOp(dxil::OpCode OpCode, ArrayRef Args, + const Twine &Name, Type *RetTy) { const OpCodeProperty *Prop = getOpCodeProperty(OpCode); @@ -451,12 +452,12 @@ Expected DXILOpBuilder::tryCreateOp(dxil::OpCode OpCode, OpArgs.push_back(IRB.getInt32(llvm::to_underlying(OpCode))); OpArgs.append(Args.begin(), Args.end()); - return IRB.CreateCall(DXILFn, OpArgs); + return IRB.CreateCall(DXILFn, OpArgs, Name); } CallInst *DXILOpBuilder::createOp(dxil::OpCode OpCode, ArrayRef Args, - Type *RetTy) { - Expected Result = tryCreateOp(OpCode, Args, RetTy); + const Twine &Name, Type *RetTy) { + Expected Result = tryCreateOp(OpCode, Args, Name, RetTy); if (Error E = Result.takeError()) llvm_unreachable("Invalid arguments for operation"); return *Result; diff --git a/llvm/lib/Target/DirectX/DXILOpBuilder.h b/llvm/lib/Target/DirectX/DXILOpBuilder.h index a68f0c43f67a..037ae3822cfb 100644 --- a/llvm/lib/Target/DirectX/DXILOpBuilder.h +++ b/llvm/lib/Target/DirectX/DXILOpBuilder.h @@ -39,11 +39,12 @@ public: /// Create a call instruction for the given DXIL op. The arguments /// must be valid for an overload of the operation. CallInst *createOp(dxil::OpCode Op, ArrayRef Args, - Type *RetTy = nullptr); + const Twine &Name = "", Type *RetTy = nullptr); /// Try to create a call instruction for the given DXIL op. Fails if the /// overload is invalid. Expected tryCreateOp(dxil::OpCode Op, ArrayRef Args, + const Twine &Name = "", Type *RetTy = nullptr); /// Get a `%dx.types.ResRet` type with the given element type. diff --git a/llvm/lib/Target/DirectX/DXILOpLowering.cpp b/llvm/lib/Target/DirectX/DXILOpLowering.cpp index d98d0bfde04f..3ee3ee05563c 100644 --- a/llvm/lib/Target/DirectX/DXILOpLowering.cpp +++ b/llvm/lib/Target/DirectX/DXILOpLowering.cpp @@ -118,7 +118,7 @@ public: Args.append(CI->arg_begin(), CI->arg_end()); Expected OpCall = - OpBuilder.tryCreateOp(DXILOp, Args, F.getReturnType()); + OpBuilder.tryCreateOp(DXILOp, Args, CI->getName(), F.getReturnType()); if (Error E = OpCall.takeError()) return E; @@ -198,7 +198,7 @@ public: ConstantInt::get(Int32Ty, Binding.RecordID), CI->getArgOperand(3), CI->getArgOperand(4)}; Expected OpCall = - OpBuilder.tryCreateOp(OpCode::CreateHandle, Args); + OpBuilder.tryCreateOp(OpCode::CreateHandle, Args, CI->getName()); if (Error E = OpCall.takeError()) return E; @@ -233,15 +233,16 @@ public: Binding.LowerBound, UpperBound, Binding.Space, RI.getResourceClass()); std::array BindArgs{ResBind, CI->getArgOperand(3), CI->getArgOperand(4)}; - Expected OpBind = - OpBuilder.tryCreateOp(OpCode::CreateHandleFromBinding, BindArgs); + Expected OpBind = OpBuilder.tryCreateOp( + OpCode::CreateHandleFromBinding, BindArgs, CI->getName()); if (Error E = OpBind.takeError()) return E; std::array AnnotateArgs{ *OpBind, OpBuilder.getResProps(Props.first, Props.second)}; - Expected OpAnnotate = - OpBuilder.tryCreateOp(OpCode::AnnotateHandle, AnnotateArgs); + Expected OpAnnotate = OpBuilder.tryCreateOp( + OpCode::AnnotateHandle, AnnotateArgs, + CI->hasName() ? CI->getName() + "_annot" : Twine()); if (Error E = OpAnnotate.takeError()) return E; @@ -286,7 +287,10 @@ public: if (!CheckOp) { Value *NewEVI = IRB.CreateExtractValue(Op, 4); Expected OpCall = OpBuilder.tryCreateOp( - OpCode::CheckAccessFullyMapped, {NewEVI}, Int32Ty); + OpCode::CheckAccessFullyMapped, {NewEVI}, + OldResult->hasName() ? OldResult->getName() + "_check" + : Twine(), + Int32Ty); if (Error E = OpCall.takeError()) return E; CheckOp = *OpCall; @@ -296,7 +300,8 @@ public: } } - OldResult = cast(IRB.CreateExtractValue(Op, 0)); + OldResult = cast( + IRB.CreateExtractValue(Op, 0, OldResult->getName())); OldTy = ST->getElementType(0); } @@ -403,8 +408,8 @@ public: Type *NewRetTy = OpBuilder.getResRetType(OldTy->getScalarType()); std::array Args{Handle, Index0, Index1}; - Expected OpCall = - OpBuilder.tryCreateOp(OpCode::BufferLoad, Args, NewRetTy); + Expected OpCall = OpBuilder.tryCreateOp( + OpCode::BufferLoad, Args, CI->getName(), NewRetTy); if (Error E = OpCall.takeError()) return E; if (Error E = replaceResRetUses(CI, *OpCall, HasCheckBit)) @@ -447,7 +452,7 @@ public: std::array Args{Handle, Index0, Index1, Data0, Data1, Data2, Data3, Mask}; Expected OpCall = - OpBuilder.tryCreateOp(OpCode::BufferStore, Args); + OpBuilder.tryCreateOp(OpCode::BufferStore, Args, CI->getName()); if (Error E = OpCall.takeError()) return E; diff --git a/llvm/test/CodeGen/DirectX/CreateHandleFromBinding.ll b/llvm/test/CodeGen/DirectX/CreateHandleFromBinding.ll index d0c80c018b8d..dbdd2e61df7a 100644 --- a/llvm/test/CodeGen/DirectX/CreateHandleFromBinding.ll +++ b/llvm/test/CodeGen/DirectX/CreateHandleFromBinding.ll @@ -19,14 +19,14 @@ define void @test_bindings() { %typed0 = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0) @llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_1_0_0( i32 3, i32 5, i32 1, i32 4, i1 false) - ; 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) + ; 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) ; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF0]], %dx.types.ResourceProperties { i32 4106, i32 1033 }) ; RWBuffer Buf : register(u7, space2) %typed1 = call target("dx.TypedBuffer", i32, 1, 0, 1) @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0_0t( i32 2, i32 7, i32 1, i32 6, i1 false) - ; 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) + ; 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) ; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF1]], %dx.types.ResourceProperties { i32 4106, i32 260 }) ; Buffer Buf[24] : register(t3, space5) @@ -35,7 +35,7 @@ define void @test_bindings() { %typed2 = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0) @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_0_0_0t( i32 5, i32 3, i32 24, i32 7, i1 false) - ; 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) + ; 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) ; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF2]], %dx.types.ResourceProperties { i32 10, i32 1029 }) ; struct S { float4 a; uint4 b; }; @@ -43,14 +43,14 @@ define void @test_bindings() { %struct0 = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0) @llvm.dx.handle.fromBinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t( i32 4, i32 2, i32 1, i32 10, i1 true) - ; 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) + ; 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) ; CHECK: = call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF3]], %dx.types.ResourceProperties { i32 1036, i32 32 }) ; ByteAddressBuffer Buf : register(t8, space1) %byteaddr0 = call target("dx.RawBuffer", i8, 0, 0) @llvm.dx.handle.fromBinding.tdx.RawBuffer_i8_0_0t( i32 1, i32 8, i32 1, i32 12, i1 false) - ; 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) + ; 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) ; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF4]], %dx.types.ResourceProperties { i32 11, i32 0 }) ; Buffer Buf[] : register(t0) @@ -59,7 +59,7 @@ define void @test_bindings() { %typed3 = call target("dx.TypedBuffer", <4 x float>, 0, 0, 0) @llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_0_0_0t( i32 0, i32 0, i32 -1, i32 %typed3_ix, i1 false) - ; 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) + ; 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) ; CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 217, %dx.types.Handle [[BUF5]], %dx.types.ResourceProperties { i32 10, i32 1033 }) ret void