@@ -319,43 +319,6 @@ static std::string getStageMaskString(ArrayRef<const Record *> Recs) {
319319 return MaskString;
320320}
321321
322- // / Return a string representation of valid attribute information denoted
323- // by input records
324- //
325- // / \param Recs A vector of records of TableGen Attribute records
326- // / \return std::string string representation of attributes list string
327- // / predicated by DXIL Version. E.g.,
328- // {{{1, 0}, {Attr1, ...}}, {{1, 2}, {Attr2, ...}}, ...}
329- static std::string getAttributeListString (ArrayRef<const Record *> Recs) {
330- std::string ListString = " " ;
331- std::string Prefix = " " ;
332- ListString.append (" {" );
333-
334- for (const auto *Rec : Recs) {
335- unsigned Major = Rec->getValueAsDef (" dxil_version" )->getValueAsInt (" Major" );
336- unsigned Minor = Rec->getValueAsDef (" dxil_version" )->getValueAsInt (" Minor" );
337- ListString.append (Prefix)
338- .append (" {{" )
339- .append (std::to_string (Major))
340- .append (" , " )
341- .append (std::to_string (Minor).append (" }, {" ));
342-
343- std::string CommaPrefix = " " ;
344- auto Attrs = Rec->getValueAsListOfDefs (" fn_attrs" );
345- for (const auto *Attr : Attrs) {
346- ListString.append (CommaPrefix)
347- .append (" dxil::Attribute::" )
348- .append (Attr->getName ());
349- CommaPrefix = " , " ;
350- }
351- ListString.append (" }" ); // End of Attrs
352- ListString.append (" }" ); // End of Rec
353- Prefix = " , " ;
354- }
355- ListString.append (" }" ); // End of List
356- return ListString;
357- }
358-
359322// / Return a string representation of valid property information denoted
360323// by input records
361324//
@@ -378,6 +341,20 @@ static std::string getPropertyListString(ArrayRef<const Record *> Recs) {
378341 return ListString;
379342}
380343
344+ // / Emit a list valid DXIL Version records
345+ static void emitDXILVersions (const RecordKeeper &Records, raw_ostream &OS) {
346+ OS << " #ifdef DXIL_VERSION\n " ;
347+ for (const Record *Version : Records.getAllDerivedDefinitions (" Version" )) {
348+ unsigned Major = Version->getValueAsInt (" Major" );
349+ unsigned Minor = Version->getValueAsInt (" Minor" );
350+ OS << " DXIL_VERSION(" ;
351+ OS << std::to_string (Major) << " , " << std::to_string (Minor);
352+ OS << " )\n " ;
353+ }
354+ OS << " #undef DXIL_VERSION\n " ;
355+ OS << " #endif\n\n " ;
356+ }
357+
381358// / Emit a mapping of DXIL opcode to opname
382359static void emitDXILOpCodes (ArrayRef<DXILOperationDesc> Ops, raw_ostream &OS) {
383360 OS << " #ifdef DXIL_OPCODE\n " ;
@@ -416,6 +393,40 @@ static void emitDXILAttributes(const RecordKeeper &Records, raw_ostream &OS) {
416393 OS << " #endif\n\n " ;
417394}
418395
396+ // Determine which function attributes are set for a dxil version
397+ static bool attrIsDefined (std::vector<const Record *> Attrs, const Record *Attr) {
398+ for (auto CurAttr : Attrs)
399+ if (CurAttr->getName () == Attr->getName ())
400+ return true ;
401+ return false ;
402+ }
403+
404+ // / Emit a table of bools denoting a DXIL op's function attributes
405+ static void emitDXILOpAttributes (const RecordKeeper &Records,
406+ ArrayRef<DXILOperationDesc> Ops,
407+ raw_ostream &OS) {
408+ OS << " #ifdef DXIL_OP_ATTRIBUTES\n " ;
409+ for (const auto &Op : Ops) {
410+ for (const auto *Rec : Op.AttrRecs ) {
411+ unsigned Major = Rec->getValueAsDef (" dxil_version" )->getValueAsInt (" Major" );
412+ unsigned Minor = Rec->getValueAsDef (" dxil_version" )->getValueAsInt (" Minor" );
413+ OS << " DXIL_OP_ATTRIBUTES(dxil::OpCode::" << Op.OpName << " , " ;
414+ OS << std::to_string (Major) << " , " << std::to_string (Minor);
415+ auto Attrs = Rec->getValueAsListOfDefs (" fn_attrs" );
416+ for (const Record *Attr : Records.getAllDerivedDefinitions (" DXILAttribute" )) {
417+ std::string HasAttr = " , false" ;
418+ if (attrIsDefined (Attrs, Attr))
419+ HasAttr = " , true" ;
420+ OS << HasAttr;
421+ }
422+ OS << " )\n " ;
423+ }
424+
425+ }
426+ OS << " #undef DXIL_OP_ATTRIBUTES\n " ;
427+ OS << " #endif\n\n " ;
428+ }
429+
419430// / Emit a list of DXIL op properties and their query functions
420431static void emitDXILProperties (const RecordKeeper &Records, raw_ostream &OS) {
421432 // Generate their definitions
@@ -544,7 +555,6 @@ static void emitDXILOperationTable(ArrayRef<DXILOperationDesc> Ops,
544555 << OpClassStrings.get (Op.OpClass .data ()) << " , "
545556 << getOverloadMaskString (Op.OverloadRecs ) << " , "
546557 << getStageMaskString (Op.StageRecs ) << " , "
547- << getAttributeListString (Op.AttrRecs ) << " , "
548558 << getPropertyListString (Op.PropRecs ) << " , " << Op.OverloadParamIndex
549559 << " }" ;
550560 Prefix = " ,\n " ;
@@ -647,10 +657,12 @@ static void emitDxilOperation(const RecordKeeper &Records, raw_ostream &OS) {
647657 PrevOp = Desc.OpCode ;
648658 }
649659
660+ emitDXILVersions (Records, OS);
650661 emitDXILOpCodes (DXILOps, OS);
651662 emitDXILOpClasses (Records, OS);
652663 emitDXILOpParamTypes (Records, OS);
653664 emitDXILAttributes (Records, OS);
665+ emitDXILOpAttributes (Records, DXILOps, OS);
654666 emitDXILProperties (Records, OS);
655667 emitDXILOpFunctionTypes (DXILOps, OS);
656668 emitDXILIntrinsicArgSelectTypes (Records, OS);
0 commit comments