Skip to content

Commit 4094098

Browse files
authored
[DirectX] Simplify tablegen'd OpCode and OpClass enums
Pull Request: #101249
1 parent 50cf413 commit 4094098

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

llvm/lib/Target/DirectX/DXILConstants.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
namespace llvm {
1616
namespace dxil {
1717

18-
#define DXIL_OP_ENUM
18+
enum class OpCode : unsigned {
19+
#define DXIL_OPCODE(Op, Name) Name = Op,
1920
#include "DXILOperation.inc"
21+
};
22+
23+
enum class OpCodeClass : unsigned {
24+
#define DXIL_OPCLASS(Name) Name,
25+
#include "DXILOperation.inc"
26+
};
2027

2128
} // namespace dxil
2229
} // namespace llvm

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -429,34 +429,26 @@ static std::string getAttributeMaskString(const SmallVector<Record *> Recs) {
429429
return MaskString;
430430
}
431431

432-
/// Emit Enums of DXIL Ops
433-
/// \param A vector of DXIL Ops
434-
/// \param Output stream
435-
static void emitDXILEnums(std::vector<DXILOperationDesc> &Ops,
436-
raw_ostream &OS) {
437-
OS << "#ifdef DXIL_OP_ENUM\n\n";
438-
OS << "// Enumeration for operations specified by DXIL\n";
439-
OS << "enum class OpCode : unsigned {\n";
440-
441-
for (auto &Op : Ops) {
442-
// Name = ID, // Doc
443-
OS << Op.OpName << " = " << Op.OpCode << ", // " << Op.Doc << "\n";
444-
}
445-
446-
OS << "\n};\n\n";
432+
/// Emit a mapping of DXIL opcode to opname
433+
static void emitDXILOpCodes(std::vector<DXILOperationDesc> &Ops,
434+
raw_ostream &OS) {
435+
OS << "#ifdef DXIL_OPCODE\n";
436+
for (const DXILOperationDesc &Op : Ops)
437+
OS << "DXIL_OPCODE(" << Op.OpCode << ", " << Op.OpName << ")\n";
438+
OS << "#undef DXIL_OPCODE\n";
439+
OS << "\n";
440+
OS << "#endif\n\n";
441+
}
447442

448-
OS << "// Groups for DXIL operations with equivalent function templates\n";
449-
OS << "enum class OpCodeClass : unsigned {\n";
450-
// Build an OpClass set to print
451-
SmallSet<StringRef, 2> OpClassSet;
452-
for (auto &Op : Ops) {
453-
OpClassSet.insert(Op.OpClass);
454-
}
455-
for (auto &C : OpClassSet) {
456-
OS << C << ",\n";
457-
}
458-
OS << "\n};\n\n";
459-
OS << "#undef DXIL_OP_ENUM\n";
443+
/// Emit a list of DXIL op classes
444+
static void emitDXILOpClasses(RecordKeeper &Records,
445+
raw_ostream &OS) {
446+
OS << "#ifdef DXIL_OPCLASS\n";
447+
std::vector<Record *> OpClasses =
448+
Records.getAllDerivedDefinitions("DXILOpClass");
449+
for (Record *OpClass : OpClasses)
450+
OS << "DXIL_OPCLASS(" << OpClass->getName() << ")\n";
451+
OS << "#undef DXIL_OPCLASS\n";
460452
OS << "#endif\n\n";
461453
}
462454

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

655-
emitDXILEnums(DXILOps, OS);
647+
emitDXILOpCodes(DXILOps, OS);
648+
emitDXILOpClasses(Records, OS);
656649
emitDXILIntrinsicMap(DXILOps, OS);
657650
OS << "#ifdef DXIL_OP_OPERATION_TABLE\n\n";
658651
emitDXILOperationTableDataStructs(Records, OS);

0 commit comments

Comments
 (0)