@@ -42,6 +42,7 @@ struct DXILOperationDesc {
4242 SmallVector<const Record *> OverloadRecs;
4343 SmallVector<const Record *> StageRecs;
4444 SmallVector<const Record *> AttrRecs;
45+ SmallVector<const Record *> PropRecs;
4546 StringRef Intrinsic; // The llvm intrinsic map to OpName. Default is "" which
4647 // means no map exists
4748 SmallVector<StringRef, 4 >
@@ -149,6 +150,13 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
149150 AttrRecs.push_back (CR);
150151 }
151152
153+ Recs = R->getValueAsListOfDefs (" properties" );
154+
155+ // Get property records
156+ for (const Record *CR : Recs) {
157+ PropRecs.push_back (CR);
158+ }
159+
152160 // Get the operation class
153161 OpClass = R->getValueAsDef (" OpClass" )->getName ();
154162
@@ -318,6 +326,28 @@ static std::string getAttributeListString(ArrayRef<const Record *> Recs) {
318326 return ListString;
319327}
320328
329+ // / Return a string representation of valid property information denoted
330+ // by input records
331+ //
332+ // / \param Recs A vector of records of TableGen Property records
333+ // / \return std::string string representation of properties list string
334+ // {Attr1, Attr2, ...}
335+ static std::string getPropertyListString (ArrayRef<const Record *> Recs) {
336+ std::string ListString = " " ;
337+ std::string Prefix = " " ;
338+ ListString.append (" {" );
339+
340+ std::string CommaPrefix = " " ;
341+ for (const auto *Rec : Recs) {
342+ ListString.append (CommaPrefix)
343+ .append (" dxil::Property::" )
344+ .append (Rec->getName ());
345+ CommaPrefix = " , " ;
346+ }
347+ ListString.append (" }" );
348+ return ListString;
349+ }
350+
321351// / Emit a mapping of DXIL opcode to opname
322352static void emitDXILOpCodes (ArrayRef<DXILOperationDesc> Ops, raw_ostream &OS) {
323353 OS << " #ifdef DXIL_OPCODE\n " ;
@@ -356,6 +386,30 @@ static void emitDXILAttributes(const RecordKeeper &Records, raw_ostream &OS) {
356386 OS << " #endif\n\n " ;
357387}
358388
389+ // / Emit a list of DXIL op properties and their query functions
390+ static void emitDXILProperties (const RecordKeeper &Records, raw_ostream &OS) {
391+ // Generate their definitions
392+ OS << " #ifdef DXIL_PROPERTY\n " ;
393+ for (const Record *Prop: Records.getAllDerivedDefinitions (" DXILProperty" ))
394+ OS << " DXIL_PROPERTY(" << Prop->getName () << " )\n " ;
395+ OS << " #undef DXIL_PROPERTY\n " ;
396+ OS << " #endif\n\n " ;
397+ }
398+
399+ static void emitDXILPropertyHelpers (const RecordKeeper &Records, raw_ostream &OS) {
400+ // Generate their helper functions
401+ for (const Record *Prop: Records.getAllDerivedDefinitions (" DXILProperty" )) {
402+ OS << " [[maybe_unused]]\n " ;
403+ OS << " static bool has" << Prop->getName () << " (dxil::OpCode Op) {\n " ;
404+ OS << " auto *OpCodeProp = getOpCodeProperty(Op);\n " ;
405+ OS << " for (auto Prop : OpCodeProp->Properties)\n " ;
406+ OS << " if (Prop == dxil::Property::" << Prop->getName () << " )\n " ;
407+ OS << " return true;\n " ;
408+ OS << " return false;\n " ;
409+ OS << " }\n\n " ;
410+ }
411+ }
412+
359413// / Emit a list of DXIL op function types
360414static void emitDXILOpFunctionTypes (ArrayRef<DXILOperationDesc> Ops,
361415 raw_ostream &OS) {
@@ -426,7 +480,8 @@ static void emitDXILOperationTable(ArrayRef<DXILOperationDesc> Ops,
426480 << OpClassStrings.get (Op.OpClass .data ()) << " , "
427481 << getOverloadMaskString (Op.OverloadRecs ) << " , "
428482 << getStageMaskString (Op.StageRecs ) << " , "
429- << getAttributeListString (Op.AttrRecs ) << " , " << Op.OverloadParamIndex
483+ << getAttributeListString (Op.AttrRecs ) << " , "
484+ << getPropertyListString (Op.PropRecs ) << " , " << Op.OverloadParamIndex
430485 << " }" ;
431486 Prefix = " ,\n " ;
432487 }
@@ -532,11 +587,13 @@ static void emitDxilOperation(const RecordKeeper &Records, raw_ostream &OS) {
532587 emitDXILOpClasses (Records, OS);
533588 emitDXILOpParamTypes (Records, OS);
534589 emitDXILAttributes (Records, OS);
590+ emitDXILProperties (Records, OS);
535591 emitDXILOpFunctionTypes (DXILOps, OS);
536592 emitDXILIntrinsicMap (DXILOps, OS);
537593 OS << " #ifdef DXIL_OP_OPERATION_TABLE\n\n " ;
538594 emitDXILOperationTableDataStructs (Records, OS);
539595 emitDXILOperationTable (DXILOps, OS);
596+ emitDXILPropertyHelpers (Records, OS);
540597 OS << " #undef DXIL_OP_OPERATION_TABLE\n " ;
541598 OS << " #endif\n\n " ;
542599}
0 commit comments