Skip to content

Commit

Permalink
remove dependcy on OpCodeProperty for helper function
Browse files Browse the repository at this point in the history
- before this change, we would be required to define OpCodeProperty and
all used structs to use hasProperty, which for all uses outside of
DXILOpBuilder is not usable.
  • Loading branch information
inbelic committed Nov 29, 2024
1 parent b157913 commit a3f579f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions llvm/utils/TableGen/DXILEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,22 @@ static void emitDXILProperties(const RecordKeeper &Records, raw_ostream &OS) {
OS << "#endif\n\n";
}

static void emitDXILPropertyHelper(raw_ostream &OS) {
static void emitDXILPropertyHelper(ArrayRef<DXILOperationDesc> Ops,
raw_ostream &OS) {
// Generate helper function to query all the functions
OS << "[[maybe_unused]]\n";
OS << "static llvm::SmallVector<dxil::Property> getProperties(dxil::OpCode "
"Op) {\n";
OS << " switch (Op) {\n";
for (const auto &Op : Ops) {
OS << " case dxil::OpCode::" << Op.OpName << ": return "
<< getPropertyListString(Op.PropRecs) << ";\n";
}
OS << " }\n";
OS << " return {};\n";
OS << "}\n\n";
OS << "static bool hasProperty(dxil::OpCode Op, dxil::Property Prop) {\n";
OS << " auto *OpCodeProp = getOpCodeProperty(Op);\n";
OS << " for (auto CurProp : OpCodeProp->Properties)\n";
OS << " auto Properties = getProperties(Op);\n";
OS << " for (auto CurProp : Properties)\n";
OS << " if (CurProp == Prop)\n";
OS << " return true;\n";
OS << " return false;\n";
Expand Down Expand Up @@ -591,9 +601,12 @@ static void emitDxilOperation(const RecordKeeper &Records, raw_ostream &OS) {
OS << "#ifdef DXIL_OP_OPERATION_TABLE\n\n";
emitDXILOperationTableDataStructs(Records, OS);
emitDXILOperationTable(DXILOps, OS);
emitDXILPropertyHelper(OS);
OS << "#undef DXIL_OP_OPERATION_TABLE\n";
OS << "#endif\n\n";
OS << "#ifdef DXIL_OP_PROPERTY_HELPER\n";
emitDXILPropertyHelper(DXILOps, OS);
OS << "#undef DXIL_OP_PROPERTY_HELPER\n";
OS << "#endif\n\n";
}

static TableGen::Emitter::Opt X("gen-dxil-operation", emitDxilOperation,
Expand Down

0 comments on commit a3f579f

Please sign in to comment.