Skip to content

Commit 54a6cf1

Browse files
authored
[DirectX][NFC] Use LLVM Types in DXIL Operation specifications in DXIL.td (#81692)
This change uniformly uses LLVM Types in the specification of parameter types and overload types of DXIL operation. Updated (a) parameter types accordingly in the specification of existing DXILOperations and (b) DXILEmitter.
1 parent ec24094 commit 54a6cf1

File tree

2 files changed

+69
-90
lines changed

2 files changed

+69
-90
lines changed

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,18 @@ def BinaryUintCategory : DXILOpCategory<"Binary uint">;
3535
def UnaryFloatCategory : DXILOpCategory<"Unary float">;
3636
def ComputeIDCategory : DXILOpCategory<"Compute/Mesh/Amplification shader">;
3737

38-
// Following are the scalar types supported by DXIL operations and are synonymous
39-
// to llvm_*_ty defined for readability and ease of use in the context of this file.
40-
41-
def voidTy : LLVMType<isVoid>;
42-
43-
// Floating point types
44-
def f16Ty : LLVMType<f16>;
45-
def f32Ty : LLVMType<f32>;
46-
def f64Ty : LLVMType<f64>;
47-
48-
// Integer types
49-
def i1Ty : LLVMType<i1>;
50-
def i8Ty : LLVMType<i8>;
51-
def i16Ty : LLVMType<i16>;
52-
def i32Ty : LLVMType<i32>;
53-
def i64Ty : LLVMType<i64>;
38+
// Represent as any pointer type with an option to change to a qualified pointer
39+
// type with address space specified.
40+
def dxil_handle_ty : LLVMAnyPointerType;
41+
def dxil_cbuffer_ty : LLVMAnyPointerType;
42+
def dxil_resource_ty : LLVMAnyPointerType;
5443

5544
// The parameter description for a DXIL operation
56-
class DXILOpParameter<int pos, string type, string name, string doc,
45+
class DXILOpParameter<int pos, LLVMType type, string name, string doc,
5746
bit isConstant = 0, string enumName = "",
5847
int maxValue = 0> {
5948
int Pos = pos; // Position in parameter list
60-
string Type = type; // LLVM type name, $o for overload, $r for resource
61-
// type, $cb for legacy cbuffer, $u4 for u4 struct
49+
LLVMType ParamType = type; // Parameter type
6250
string Name = name; // Short, unique parameter name
6351
string Doc = doc; // Description of this parameter
6452
bit IsConstant = isConstant; // Whether this parameter requires a constant value in the IR
@@ -108,55 +96,55 @@ class DXILOperation<string name, int opCode, DXILOpClass opClass, DXILOpCategory
10896
class LLVMIntrinsic<Intrinsic llvm_intrinsic_> { Intrinsic llvm_intrinsic = llvm_intrinsic_; }
10997

11098
def Sin : DXILOperation<"Sin", 13, UnaryClass, UnaryFloatCategory, "returns sine(theta) for theta in radians.",
111-
[f16Ty,f32Ty], ReadNone,
99+
[llvm_half_ty, llvm_float_ty], ReadNone,
112100
[
113-
DXILOpParameter<0, "$o", "", "operation result">,
114-
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
115-
DXILOpParameter<2, "$o", "value", "input value">
101+
DXILOpParameter<0, llvm_anyfloat_ty, "", "operation result">,
102+
DXILOpParameter<1, llvm_i32_ty, "opcode", "DXIL opcode">,
103+
DXILOpParameter<2, llvm_anyfloat_ty, "value", "input value">
116104
],
117105
["floats"]>,
118106
LLVMIntrinsic<int_sin>;
119107

120-
def UMax : DXILOperation< "UMax", 39, BinaryClass, BinaryUintCategory, "unsigned integer maximum. UMax(a,b) = a > b ? a : b",
121-
[i16Ty,i32Ty,i64Ty], ReadNone,
108+
def UMax : DXILOperation< "UMax", 39, BinaryClass, BinaryUintCategory, "unsigned integer maximum. UMax(a,b) = a > b ? a : b",
109+
[llvm_i16_ty, llvm_i32_ty, llvm_i64_ty], ReadNone,
122110
[
123-
DXILOpParameter<0, "$o", "", "operation result">,
124-
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
125-
DXILOpParameter<2, "$o", "a", "input value">,
126-
DXILOpParameter<3, "$o", "b", "input value">
111+
DXILOpParameter<0, llvm_anyint_ty, "", "operation result">,
112+
DXILOpParameter<1, llvm_i32_ty, "opcode", "DXIL opcode">,
113+
DXILOpParameter<2, llvm_anyint_ty, "a", "input value">,
114+
DXILOpParameter<3, llvm_anyint_ty, "b", "input value">
127115
],
128116
["uints"]>,
129117
LLVMIntrinsic<int_umax>;
130118

131-
def ThreadId : DXILOperation< "ThreadId", 93, ThreadIdClass, ComputeIDCategory, "reads the thread ID", [i32Ty], ReadNone,
119+
def ThreadId : DXILOperation< "ThreadId", 93, ThreadIdClass, ComputeIDCategory, "reads the thread ID", [llvm_i32_ty], ReadNone,
132120
[
133-
DXILOpParameter<0, "i32", "", "thread ID component">,
134-
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
135-
DXILOpParameter<2, "i32", "component", "component to read (x,y,z)">
121+
DXILOpParameter<0, llvm_i32_ty, "", "thread ID component">,
122+
DXILOpParameter<1, llvm_i32_ty, "opcode", "DXIL opcode">,
123+
DXILOpParameter<2, llvm_i32_ty, "component", "component to read (x,y,z)">
136124
]>,
137125
LLVMIntrinsic<int_dx_thread_id>;
138126

139-
def GroupId : DXILOperation< "GroupId", 94, GroupIdClass, ComputeIDCategory, "reads the group ID (SV_GroupID)", [i32Ty], ReadNone,
127+
def GroupId : DXILOperation< "GroupId", 94, GroupIdClass, ComputeIDCategory, "reads the group ID (SV_GroupID)", [llvm_i32_ty], ReadNone,
140128
[
141-
DXILOpParameter<0, "i32", "", "group ID component">,
142-
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
143-
DXILOpParameter<2, "i32", "component", "component to read">
129+
DXILOpParameter<0, llvm_i32_ty, "", "group ID component">,
130+
DXILOpParameter<1, llvm_i32_ty, "opcode", "DXIL opcode">,
131+
DXILOpParameter<2, llvm_i32_ty, "component", "component to read">
144132
]>,
145133
LLVMIntrinsic<int_dx_group_id>;
146134

147-
def ThreadIdInGroup : DXILOperation< "ThreadIdInGroup", 95, ThreadIdInGroupClass, ComputeIDCategory,
148-
"reads the thread ID within the group (SV_GroupThreadID)", [i32Ty], ReadNone,
135+
def ThreadIdInGroup : DXILOperation< "ThreadIdInGroup", 95, ThreadIdInGroupClass, ComputeIDCategory,
136+
"reads the thread ID within the group (SV_GroupThreadID)", [llvm_i32_ty], ReadNone,
149137
[
150-
DXILOpParameter<0, "i32", "", "thread ID in group component">,
151-
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
152-
DXILOpParameter<2, "i32", "component", "component to read (x,y,z)">
138+
DXILOpParameter<0, llvm_i32_ty, "", "thread ID in group component">,
139+
DXILOpParameter<1, llvm_i32_ty, "opcode", "DXIL opcode">,
140+
DXILOpParameter<2, llvm_i32_ty, "component", "component to read (x,y,z)">
153141
]>,
154142
LLVMIntrinsic<int_dx_thread_id_in_group>;
155143

156-
def FlattenedThreadIdInGroup : DXILOperation< "FlattenedThreadIdInGroup", 96, FlattenedThreadIdInGroupClass, ComputeIDCategory,
157-
"provides a flattened index for a given thread within a given group (SV_GroupIndex)", [i32Ty], ReadNone,
144+
def FlattenedThreadIdInGroup : DXILOperation< "FlattenedThreadIdInGroup", 96, FlattenedThreadIdInGroupClass, ComputeIDCategory,
145+
"provides a flattened index for a given thread within a given group (SV_GroupIndex)", [llvm_i32_ty], ReadNone,
158146
[
159-
DXILOpParameter<0, "i32", "", "result">,
160-
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">
147+
DXILOpParameter<0, llvm_i32_ty, "", "result">,
148+
DXILOpParameter<1, llvm_i32_ty, "opcode", "DXIL opcode">
161149
]>,
162150
LLVMIntrinsic<int_dx_flattened_thread_id_in_group>;

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,32 @@ struct DXILOperationDesc {
7474
};
7575
} // end anonymous namespace
7676

77-
// Convert DXIL type name string to dxil::ParameterKind
78-
//
79-
// @param typeNameStr Type name string
80-
// @return ParameterKind as defined in llvm/Support/DXILABI.h
81-
static ParameterKind getDXILTypeNameToKind(StringRef typeNameStr) {
82-
return StringSwitch<ParameterKind>(typeNameStr)
83-
.Case("voidTy", ParameterKind::VOID)
84-
.Case("f16Ty", ParameterKind::HALF)
85-
.Case("f32Ty", ParameterKind::FLOAT)
86-
.Case("f64Ty", ParameterKind::DOUBLE)
87-
.Case("i1Ty", ParameterKind::I1)
88-
.Case("i8Ty", ParameterKind::I8)
89-
.Case("i16Ty", ParameterKind::I16)
90-
.Case("i32Ty", ParameterKind::I32)
91-
.Case("i64Ty", ParameterKind::I64)
92-
.Case("overloadTy", ParameterKind::OVERLOAD)
93-
.Case("handleTy", ParameterKind::DXIL_HANDLE)
94-
.Case("cbufferRetTy", ParameterKind::CBUFFER_RET)
95-
.Case("resourceRetTy", ParameterKind::RESOURCE_RET)
96-
.Default(ParameterKind::INVALID);
97-
}
98-
99-
static ParameterKind parameterTypeNameToKind(StringRef Name) {
100-
return StringSwitch<ParameterKind>(Name)
101-
.Case("void", ParameterKind::VOID)
102-
.Case("half", ParameterKind::HALF)
103-
.Case("float", ParameterKind::FLOAT)
104-
.Case("double", ParameterKind::DOUBLE)
105-
.Case("i1", ParameterKind::I1)
106-
.Case("i8", ParameterKind::I8)
107-
.Case("i16", ParameterKind::I16)
108-
.Case("i32", ParameterKind::I32)
109-
.Case("i64", ParameterKind::I64)
110-
.Case("$o", ParameterKind::OVERLOAD)
111-
.Case("dx.types.Handle", ParameterKind::DXIL_HANDLE)
112-
.Case("dx.types.CBufRet", ParameterKind::CBUFFER_RET)
113-
.Case("dx.types.ResRet", ParameterKind::RESOURCE_RET)
114-
.Default(ParameterKind::INVALID);
77+
/*!
78+
Convert DXIL type name string to dxil::ParameterKind
79+
80+
@param typeNameStr Type name string
81+
@return ParameterKind As defined in llvm/Support/DXILABI.h
82+
*/
83+
static ParameterKind lookupParameterKind(StringRef typeNameStr) {
84+
auto paramKind = StringSwitch<ParameterKind>(typeNameStr)
85+
.Case("llvm_void_ty", ParameterKind::VOID)
86+
.Case("llvm_half_ty", ParameterKind::HALF)
87+
.Case("llvm_float_ty", ParameterKind::FLOAT)
88+
.Case("llvm_double_ty", ParameterKind::DOUBLE)
89+
.Case("llvm_i1_ty", ParameterKind::I1)
90+
.Case("llvm_i8_ty", ParameterKind::I8)
91+
.Case("llvm_i16_ty", ParameterKind::I16)
92+
.Case("llvm_i32_ty", ParameterKind::I32)
93+
.Case("llvm_i64_ty", ParameterKind::I64)
94+
.Case("llvm_anyfloat_ty", ParameterKind::OVERLOAD)
95+
.Case("llvm_anyint_ty", ParameterKind::OVERLOAD)
96+
.Case("dxil_handle_ty", ParameterKind::DXIL_HANDLE)
97+
.Case("dxil_cbuffer_ty", ParameterKind::CBUFFER_RET)
98+
.Case("dxil_resource_ty", ParameterKind::RESOURCE_RET)
99+
.Default(ParameterKind::INVALID);
100+
assert(paramKind != ParameterKind::INVALID &&
101+
"Unsupported DXIL Type specified");
102+
return paramKind;
115103
}
116104

117105
DXILOperationDesc::DXILOperationDesc(const Record *R) {
@@ -143,15 +131,16 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
143131

144132
for (unsigned I = 0; I < OverloadTypeList->size(); ++I) {
145133
Record *R = OverloadTypeList->getElementAsRecord(I);
146-
OverloadTypes.emplace_back(getDXILTypeNameToKind(R->getNameInitAsString()));
134+
OverloadTypes.emplace_back(lookupParameterKind(R->getNameInitAsString()));
147135
}
148136
Attr = StringRef(R->getValue("Attribute")->getNameInitAsString());
149137
}
150138

151139
DXILParameter::DXILParameter(const Record *R) {
152140
Name = R->getValueAsString("Name");
153141
Pos = R->getValueAsInt("Pos");
154-
Kind = parameterTypeNameToKind(R->getValueAsString("Type"));
142+
Kind =
143+
lookupParameterKind(R->getValue("ParamType")->getValue()->getAsString());
155144
if (R->getValue("Doc"))
156145
Doc = R->getValueAsString("Doc");
157146
IsConst = R->getValueAsBit("IsConstant");
@@ -296,10 +285,12 @@ static void emitDXILIntrinsicMap(std::vector<DXILOperationDesc> &Ops,
296285
OS << "\n";
297286
}
298287

299-
// Convert operation attribute string to Attribute enum
300-
//
301-
// @param Attr string reference
302-
// @return std::string Attribute enum string
288+
/*!
289+
Convert operation attribute string to Attribute enum
290+
291+
@param Attr string reference
292+
@return std::string Attribute enum string
293+
*/
303294
static std::string emitDXILOperationAttr(StringRef Attr) {
304295
return StringSwitch<std::string>(Attr)
305296
.Case("ReadNone", "Attribute::ReadNone")

0 commit comments

Comments
 (0)