Skip to content

[DirectX] Simplify tablegen'd OpCode and OpClass enums #101249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion llvm/lib/Target/DirectX/DXILConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@
namespace llvm {
namespace dxil {

#define DXIL_OP_ENUM
enum class OpCode : unsigned {
#define DXIL_OPCODE(Op, Name) Name = Op,
#include "DXILOperation.inc"
};

enum class OpCodeClass : unsigned {
#define DXIL_OPCLASS(Name) Name,
#include "DXILOperation.inc"
};

} // namespace dxil
} // namespace llvm
Expand Down
49 changes: 21 additions & 28 deletions llvm/utils/TableGen/DXILEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,34 +429,26 @@ static std::string getAttributeMaskString(const SmallVector<Record *> Recs) {
return MaskString;
}

/// Emit Enums of DXIL Ops
/// \param A vector of DXIL Ops
/// \param Output stream
static void emitDXILEnums(std::vector<DXILOperationDesc> &Ops,
raw_ostream &OS) {
OS << "#ifdef DXIL_OP_ENUM\n\n";
OS << "// Enumeration for operations specified by DXIL\n";
OS << "enum class OpCode : unsigned {\n";

for (auto &Op : Ops) {
// Name = ID, // Doc
OS << Op.OpName << " = " << Op.OpCode << ", // " << Op.Doc << "\n";
}

OS << "\n};\n\n";
/// Emit a mapping of DXIL opcode to opname
static void emitDXILOpCodes(std::vector<DXILOperationDesc> &Ops,
raw_ostream &OS) {
OS << "#ifdef DXIL_OPCODE\n";
for (const DXILOperationDesc &Op : Ops)
OS << "DXIL_OPCODE(" << Op.OpCode << ", " << Op.OpName << ")\n";
OS << "#undef DXIL_OPCODE\n";
OS << "\n";
OS << "#endif\n\n";
}

OS << "// Groups for DXIL operations with equivalent function templates\n";
OS << "enum class OpCodeClass : unsigned {\n";
// Build an OpClass set to print
SmallSet<StringRef, 2> OpClassSet;
for (auto &Op : Ops) {
OpClassSet.insert(Op.OpClass);
}
for (auto &C : OpClassSet) {
OS << C << ",\n";
}
OS << "\n};\n\n";
OS << "#undef DXIL_OP_ENUM\n";
/// Emit a list of DXIL op classes
static void emitDXILOpClasses(RecordKeeper &Records,
raw_ostream &OS) {
OS << "#ifdef DXIL_OPCLASS\n";
std::vector<Record *> OpClasses =
Records.getAllDerivedDefinitions("DXILOpClass");
for (Record *OpClass : OpClasses)
OS << "DXIL_OPCLASS(" << OpClass->getName() << ")\n";
OS << "#undef DXIL_OPCLASS\n";
OS << "#endif\n\n";
}

Expand Down Expand Up @@ -652,7 +644,8 @@ static void EmitDXILOperation(RecordKeeper &Records, raw_ostream &OS) {
PrevOp = Desc.OpCode;
}

emitDXILEnums(DXILOps, OS);
emitDXILOpCodes(DXILOps, OS);
emitDXILOpClasses(Records, OS);
emitDXILIntrinsicMap(DXILOps, OS);
OS << "#ifdef DXIL_OP_OPERATION_TABLE\n\n";
emitDXILOperationTableDataStructs(Records, OS);
Expand Down
Loading