Skip to content

Commit 414295e

Browse files
committed
[DirectX] Differentiate between 1 overload and zero in the OpBuilder
DXIL operations that only have one signature behave one of two ways - either they are always suffixed with a type like `dx.op.ThreadId.i32` and hence have exactly one overload, or they're never suffixed like `dx.op.CreateHandle` and hence have zero overloads. Update DXIL.td for operations that have one overload and remove the hack in the builder that was adjusting names for unoverloaded ops.
1 parent 1c7540c commit 414295e

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -671,26 +671,29 @@ def Dot4 : DXILOp<56, dot4> {
671671
def ThreadId : DXILOp<93, threadId> {
672672
let Doc = "Reads the thread ID";
673673
let LLVMIntrinsic = int_dx_thread_id;
674-
let arguments = [i32Ty];
675-
let result = i32Ty;
674+
let arguments = [overloadTy];
675+
let result = overloadTy;
676+
let overloads = [Overloads<DXIL1_0, [i32Ty]>];
676677
let stages = [Stages<DXIL1_0, [compute, mesh, amplification, node]>];
677678
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
678679
}
679680

680681
def GroupId : DXILOp<94, groupId> {
681682
let Doc = "Reads the group ID (SV_GroupID)";
682683
let LLVMIntrinsic = int_dx_group_id;
683-
let arguments = [i32Ty];
684-
let result = i32Ty;
684+
let arguments = [overloadTy];
685+
let result = overloadTy;
686+
let overloads = [Overloads<DXIL1_0, [i32Ty]>];
685687
let stages = [Stages<DXIL1_0, [compute, mesh, amplification, node]>];
686688
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
687689
}
688690

689691
def ThreadIdInGroup : DXILOp<95, threadIdInGroup> {
690692
let Doc = "Reads the thread ID within the group (SV_GroupThreadID)";
691693
let LLVMIntrinsic = int_dx_thread_id_in_group;
692-
let arguments = [i32Ty];
693-
let result = i32Ty;
694+
let arguments = [overloadTy];
695+
let result = overloadTy;
696+
let overloads = [Overloads<DXIL1_0, [i32Ty]>];
694697
let stages = [Stages<DXIL1_0, [compute, mesh, amplification, node]>];
695698
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
696699
}
@@ -699,7 +702,8 @@ def FlattenedThreadIdInGroup : DXILOp<96, flattenedThreadIdInGroup> {
699702
let Doc = "Provides a flattened index for a given thread within a given "
700703
"group (SV_GroupIndex)";
701704
let LLVMIntrinsic = int_dx_flattened_thread_id_in_group;
702-
let result = i32Ty;
705+
let result = overloadTy;
706+
let overloads = [Overloads<DXIL1_0, [i32Ty]>];
703707
let stages = [Stages<DXIL1_0, [compute, mesh, amplification, node]>];
704708
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
705709
}

llvm/lib/Target/DirectX/DXILOpBuilder.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ static const char *getOverloadTypeName(OverloadKind Kind) {
8787
}
8888

8989
static OverloadKind getOverloadKind(Type *Ty) {
90+
if (!Ty)
91+
return OverloadKind::VOID;
92+
9093
Type::TypeID T = Ty->getTypeID();
9194
switch (T) {
9295
case Type::VoidTyID:
@@ -379,11 +382,7 @@ Expected<CallInst *> DXILOpBuilder::tryCreateOp(dxil::OpCode OpCode,
379382

380383
uint16_t ValidTyMask = Prop->Overloads[*OlIndexOrErr].ValidTys;
381384

382-
// If we don't have an overload type, use the function's return type. This is
383-
// a bit of a hack, but it's necessary to get the type suffix on unoverloaded
384-
// DXIL ops correct, like `dx.op.threadId.i32`.
385-
OverloadKind Kind =
386-
getOverloadKind(OverloadTy ? OverloadTy : DXILOpFT->getReturnType());
385+
OverloadKind Kind = getOverloadKind(OverloadTy);
387386

388387
// Check if the operation supports overload types and OverloadTy is valid
389388
// per the specified types for the operation

0 commit comments

Comments
 (0)