Skip to content

Commit 6cca5c9

Browse files
committed
Renamed everything, no longer duplicating the structs three times
1 parent 065fc8e commit 6cca5c9

File tree

3 files changed

+61
-86
lines changed

3 files changed

+61
-86
lines changed

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -302,28 +302,24 @@ defvar BarrierMode_AllMemoryBarrier = 10;
302302
defvar BarrierMode_AllMemoryBarrierWithGroupSync = 11;
303303

304304
// Intrinsic arg selection
305-
class Arg {
306-
int index = -1;
307-
int value = 0;
308-
bit is_i8 = 0;
309-
bit is_i32 = 0;
310-
}
311-
class ArgSelect<int index_> : Arg {
312-
let index = index_;
313-
}
314-
class ArgI32<int value_> : Arg {
315-
let value = value_;
316-
let is_i32 = 1;
317-
}
318-
class ArgI8<int value_> : Arg {
319-
let value = value_;
320-
let is_i8 = 1;
305+
class IntrinArgSelectType;
306+
def IntrinArgSelect_Index : IntrinArgSelectType;
307+
def IntrinArgSelect_I8 : IntrinArgSelectType;
308+
def IntrinArgSelect_I32 : IntrinArgSelectType;
309+
310+
class IntrinArgSelect<IntrinArgSelectType type_, int value_> {
311+
IntrinArgSelectType type = type_;
312+
int value = value_;
321313
}
314+
class IntrinArgIndex<int index> : IntrinArgSelect<IntrinArgSelect_Index, index>;
315+
class IntrinArgI8 <int value> : IntrinArgSelect<IntrinArgSelect_I8, value>;
316+
class IntrinArgI32 <int value> : IntrinArgSelect<IntrinArgSelect_I32, value>;
322317

323-
class IntrinsicSelect<Intrinsic intrinsic_, list<Arg> args_> {
318+
class IntrinWithArgs<Intrinsic intrinsic_, list<IntrinArgSelect> arg_selects_> {
324319
Intrinsic intrinsic = intrinsic_;
325-
list<Arg> args = args_;
320+
list<IntrinArgSelect> arg_selects = arg_selects_;
326321
}
322+
class Intrin<Intrinsic intrinsic_> : IntrinWithArgs<intrinsic_, []> {}
327323

328324
// Abstraction DXIL Operation
329325
class DXILOp<int opcode, DXILOpClass opclass> {
@@ -340,7 +336,7 @@ class DXILOp<int opcode, DXILOpClass opclass> {
340336
Intrinsic LLVMIntrinsic = ?;
341337

342338
// Non-trivial LLVM Intrinsics DXIL Operation maps to
343-
list<IntrinsicSelect> intrinsic_selects = [];
339+
list<IntrinWithArgs> intrinsic_selects = [];
344340

345341
// Result type of the op
346342
DXILOpParamType result;
@@ -951,9 +947,9 @@ def WaveAllBitCount : DXILOp<135, waveAllOp> {
951947
def Barrier : DXILOp<80, barrier> {
952948
let Doc = "inserts a memory barrier in the shader";
953949
let intrinsic_selects = [
954-
IntrinsicSelect<
950+
IntrinWithArgs<
955951
int_dx_group_memory_barrier_with_group_sync,
956-
[ ArgI32<BarrierMode_GroupMemoryBarrierWithGroupSync> ]>,
952+
[ IntrinArgI32<BarrierMode_GroupMemoryBarrierWithGroupSync> ]>,
957953
];
958954

959955
let arguments = [Int32Ty];

llvm/lib/Target/DirectX/DXILOpLowering.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,32 +106,25 @@ class OpLowerer {
106106
return false;
107107
}
108108

109-
struct ArgSelect {
110-
enum class Type {
111-
Index,
112-
I8,
113-
I32,
114-
};
115-
Type Type = Type::Index;
116-
int Value = -1;
117-
};
109+
#define DXIL_OP_INTRINSIC_ARG_SELECT_TYPES
110+
#include "DXILOperation.inc"
118111

119112
[[nodiscard]] bool replaceFunctionWithOp(Function &F, dxil::OpCode DXILOp,
120-
ArrayRef<ArgSelect> ArgSelects) {
113+
ArrayRef<IntrinArgSelect> ArgSelects) {
121114
bool IsVectorArgExpansion = isVectorArgExpansion(F);
122115
return replaceFunction(F, [&](CallInst *CI) -> Error {
123116
OpBuilder.getIRB().SetInsertPoint(CI);
124117
SmallVector<Value *> Args;
125118
if (ArgSelects.size()) {
126-
for (const ArgSelect &A : ArgSelects) {
119+
for (const IntrinArgSelect &A : ArgSelects) {
127120
switch (A.Type) {
128-
case ArgSelect::Type::Index:
121+
case IntrinArgSelect::Type::Index:
129122
Args.push_back(CI->getArgOperand(A.Value));
130123
break;
131-
case ArgSelect::Type::I8:
124+
case IntrinArgSelect::Type::I8:
132125
Args.push_back(OpBuilder.getIRB().getInt8((uint8_t)A.Value));
133126
break;
134-
case ArgSelect::Type::I32:
127+
case IntrinArgSelect::Type::I32:
135128
Args.push_back(OpBuilder.getIRB().getInt32(A.Value));
136129
break;
137130
}
@@ -668,7 +661,7 @@ class OpLowerer {
668661
#define DXIL_OP_INTRINSIC(OpCode, Intrin, ...) \
669662
case Intrin: \
670663
HasErrors |= \
671-
replaceFunctionWithOp(F, OpCode, ArrayRef<ArgSelect>{__VA_ARGS__}); \
664+
replaceFunctionWithOp(F, OpCode, ArrayRef<IntrinArgSelect>{__VA_ARGS__}); \
672665
break;
673666
#include "DXILOperation.inc"
674667
case Intrinsic::dx_handle_fromBinding:

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@ using namespace llvm::dxil;
3232

3333
namespace {
3434

35-
struct DXILArgSelect {
36-
enum class Type {
37-
Index,
38-
I32,
39-
I8,
40-
};
41-
Type Type = Type::Index;
42-
int Value = -1;
43-
};
4435
struct DXILIntrinsicSelect {
4536
StringRef Intrinsic;
46-
SmallVector<DXILArgSelect, 4> Args;
37+
SmallVector<const Record *> ArgSelectRecords;
4738
};
4839

40+
static StringRef StripIntrinArgSelectTypePrefix(StringRef Type) {
41+
StringRef Prefix = "IntrinArgSelect_";
42+
if (!Type.starts_with(Prefix)) {
43+
PrintFatalError("IntrinArgSelectType definintion must be prefixed with 'IntrinArgSelect_'");
44+
}
45+
return Type.substr(Prefix.size());
46+
}
47+
4948
struct DXILOperationDesc {
5049
std::string OpName; // name of DXIL operation
5150
int OpCode; // ID of DXIL operation
@@ -203,32 +202,9 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
203202
for (const Record *R : IntrinsicSelectRecords) {
204203
DXILIntrinsicSelect IntrSelect;
205204
IntrSelect.Intrinsic = GetIntrinsicName(R->getValue("intrinsic"));
206-
auto Args = R->getValueAsListOfDefs("args");
207-
for (const Record *Arg : Args) {
208-
bool IsI8 = Arg->getValueAsBit("is_i8");
209-
bool IsI32 = Arg->getValueAsBit("is_i32");
210-
int Index = Arg->getValueAsInt("index");
211-
int Value = Arg->getValueAsInt("value");
212-
213-
DXILArgSelect ArgSelect;
214-
if (IsI8) {
215-
ArgSelect.Type = DXILArgSelect::Type::I8;
216-
ArgSelect.Value = Value;
217-
} else if (IsI32) {
218-
ArgSelect.Type = DXILArgSelect::Type::I32;
219-
ArgSelect.Value = Value;
220-
} else {
221-
if (Index < 0) {
222-
PrintFatalError(
223-
R, Twine("Index in ArgSelect<index> must be equal to or "
224-
"greater than 0 for DXIL operation - ") +
225-
OpName);
226-
}
227-
ArgSelect.Type = DXILArgSelect::Type::Index;
228-
ArgSelect.Value = Index;
229-
}
230-
231-
IntrSelect.Args.emplace_back(std::move(ArgSelect));
205+
auto Args = R->getValueAsListOfDefs("arg_selects");
206+
for (const Record *ArgSelect : Args) {
207+
IntrSelect.ArgSelectRecords.emplace_back(ArgSelect);
232208
}
233209
IntrinsicSelects.emplace_back(std::move(IntrSelect));
234210
}
@@ -441,6 +417,7 @@ static void emitDXILOpFunctionTypes(ArrayRef<DXILOperationDesc> Ops,
441417
/// \param Output stream
442418
static void emitDXILIntrinsicMap(ArrayRef<DXILOperationDesc> Ops,
443419
raw_ostream &OS) {
420+
444421
OS << "#ifdef DXIL_OP_INTRINSIC\n";
445422
OS << "\n";
446423
for (const auto &Op : Ops) {
@@ -450,20 +427,12 @@ static void emitDXILIntrinsicMap(ArrayRef<DXILOperationDesc> Ops,
450427
for (const DXILIntrinsicSelect &MappedIntr : Op.IntrinsicSelects) {
451428
OS << "DXIL_OP_INTRINSIC(dxil::OpCode::" << Op.OpName
452429
<< ", Intrinsic::" << MappedIntr.Intrinsic << ", ";
453-
for (const DXILArgSelect &ArgSelect : MappedIntr.Args) {
454-
OS << "(ArgSelect { ";
455-
switch (ArgSelect.Type) {
456-
case DXILArgSelect::Type::Index:
457-
OS << "ArgSelect::Type::Index, ";
458-
break;
459-
case DXILArgSelect::Type::I8:
460-
OS << "ArgSelect::Type::I8, ";
461-
break;
462-
case DXILArgSelect::Type::I32:
463-
OS << "ArgSelect::Type::I32, ";
464-
break;
465-
}
466-
OS << ArgSelect.Value << "}), ";
430+
for (const Record *ArgSelect : MappedIntr.ArgSelectRecords) {
431+
std::string Type = ArgSelect->getValueAsDef("type")->getNameInitAsString();
432+
int Value = ArgSelect->getValueAsInt("value");
433+
OS << "(IntrinArgSelect{"
434+
<< "IntrinArgSelect::Type::" << StripIntrinArgSelectTypePrefix(Type) << ","
435+
<< Value << "}), ";
467436
}
468437
OS << ")\n";
469438
}
@@ -473,6 +442,22 @@ static void emitDXILIntrinsicMap(ArrayRef<DXILOperationDesc> Ops,
473442
OS << "#endif\n\n";
474443
}
475444

445+
static void emitDXILIntrinsicArgSelectTypes(const RecordKeeper &Records, raw_ostream &OS) {
446+
OS << "#ifdef DXIL_OP_INTRINSIC_ARG_SELECT_TYPES\n";
447+
OS << "struct IntrinArgSelect {\n";
448+
OS << " enum class Type {\n";
449+
for (const Record *Records : Records.getAllDerivedDefinitions("IntrinArgSelectType")) {
450+
StringRef StrippedName = StripIntrinArgSelectTypePrefix(Records->getName());
451+
OS << " " << StrippedName << ",\n";
452+
}
453+
OS << " };\n";
454+
OS << " Type Type;\n";
455+
OS << " int Value;\n";
456+
OS << "};\n";
457+
OS << "#undef DXIL_OP_INTRINSIC_ARG_SELECT_TYPES\n";
458+
OS << "#endif\n\n";
459+
}
460+
476461
/// Emit DXIL operation table
477462
/// \param A vector of DXIL Ops
478463
/// \param Output stream
@@ -613,6 +598,7 @@ static void emitDxilOperation(const RecordKeeper &Records, raw_ostream &OS) {
613598
emitDXILOpClasses(Records, OS);
614599
emitDXILOpParamTypes(Records, OS);
615600
emitDXILOpFunctionTypes(DXILOps, OS);
601+
emitDXILIntrinsicArgSelectTypes(Records, OS);
616602
emitDXILIntrinsicMap(DXILOps, OS);
617603
OS << "#ifdef DXIL_OP_OPERATION_TABLE\n\n";
618604
emitDXILOperationTableDataStructs(Records, OS);

0 commit comments

Comments
 (0)