@@ -32,20 +32,19 @@ using namespace llvm::dxil;
3232
3333namespace {
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- };
4435struct 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+
4948struct 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
442418static 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