@@ -372,16 +372,31 @@ static void emitDXILAttributes(const RecordKeeper &Records, raw_ostream &OS) {
372
372
OS << " #endif\n\n " ;
373
373
}
374
374
375
- // Helper function to determine if the given Attr is defined in the vector
376
- // Attrs, by comparing the names
377
- static bool attrIsDefined (std::vector<const Record *> Attrs,
378
- const Record *Attr) {
379
- for (auto CurAttr : Attrs)
380
- if (CurAttr->getName () == Attr->getName ())
375
+ // Helper function to determine if Recs contains Rec
376
+ static bool containsRec (ArrayRef<const Record *> Recs, const Record *Rec) {
377
+ for (auto CurRec : Recs)
378
+ if (CurRec->getName () == Rec->getName ())
381
379
return true ;
382
380
return false ;
383
381
}
384
382
383
+ // Iterate through AllRecords and output 'true' if there is a Rec with the same name in
384
+ // CurRecords, output all others as 'false' to create a boolean table.
385
+ // Eg)
386
+ // In:
387
+ // CurRecords->getName() = {"Cat"}
388
+ // DefinedRecords->getName() = {"Dog", "Cat", "Cow"}
389
+ // Out:
390
+ // false, true, false
391
+ static void emitBoolTable (ArrayRef<const Record *> CurRecords, ArrayRef<const Record *> AllRecords, raw_ostream &OS) {
392
+ for (const Record *Rec : AllRecords) {
393
+ std::string HasRec = " , false" ;
394
+ if (containsRec (CurRecords, Rec))
395
+ HasRec = " , true" ;
396
+ OS << HasRec;
397
+ }
398
+ }
399
+
385
400
// / Emit a table of bools denoting a DXIL op's function attributes
386
401
static void emitDXILOpAttributes (const RecordKeeper &Records,
387
402
ArrayRef<DXILOperationDesc> Ops,
@@ -393,6 +408,7 @@ static void emitDXILOpAttributes(const RecordKeeper &Records,
393
408
//
394
409
// OpName, VersionMajor, VersionMinor, FnAttr1, FnAttr2, ...
395
410
// Eg) Abs, 1, 0, true, false, ...
411
+ auto DefinedAttrs = Records.getAllDerivedDefinitions (" DXILAttribute" );
396
412
OS << " #ifdef DXIL_OP_ATTRIBUTES\n " ;
397
413
for (const auto &Op : Ops) {
398
414
for (const auto *Rec : Op.AttrRecs ) {
@@ -402,18 +418,9 @@ static void emitDXILOpAttributes(const RecordKeeper &Records,
402
418
Rec->getValueAsDef (" dxil_version" )->getValueAsInt (" Minor" );
403
419
OS << " DXIL_OP_ATTRIBUTES(dxil::OpCode::" << Op.OpName << " , " ;
404
420
OS << std::to_string (Major) << " , " << std::to_string (Minor);
405
- // These Attrs are the ones set for above DXIL version
406
- auto Attrs = Rec->getValueAsListOfDefs (" fn_attrs" );
407
- // We will then iteratre through all possible attributes and mark the
408
- // present ones as 'true' and all the others as 'false' to create the
409
- // boolean table, eg) true, false, false, false
410
- for (const Record *Attr :
411
- Records.getAllDerivedDefinitions (" DXILAttribute" )) {
412
- std::string HasAttr = " , false" ;
413
- if (attrIsDefined (Attrs, Attr))
414
- HasAttr = " , true" ;
415
- OS << HasAttr;
416
- }
421
+ // These Attrs are the ones set for on an op with the above DXIL version
422
+ auto OpAttrs = Rec->getValueAsListOfDefs (" fn_attrs" );
423
+ emitBoolTable (OpAttrs, DefinedAttrs, OS);
417
424
OS << " )\n " ;
418
425
}
419
426
}
0 commit comments