Generates the opcode enum definition from TableGen records.
| 156 | |
| 157 | /// Generates the opcode enum definition from TableGen records. |
| 158 | static void generateOpcodeEnumDefinition(const RecordKeeper &records, |
| 159 | raw_ostream &os) { |
| 160 | emitSourceFileHeader("Generated Opcode Enum Definition", os); |
| 161 | |
| 162 | // Get all BytecodeOpcode records. |
| 163 | auto opcodeRecords = records.getAllDerivedDefinitions("BytecodeOpcode"); |
| 164 | |
| 165 | // Validate all opcode assignments before generating code. |
| 166 | validateAllOpcodeAssignments(records, opcodeRecords); |
| 167 | |
| 168 | os << "namespace mlir {\n" |
| 169 | << "namespace cuda_tile {\n" |
| 170 | << "namespace Bytecode {\n\n" |
| 171 | << "/// FROZEN at current assignments for backward compatibility.\n" |
| 172 | << "/// WARNING: NEVER CHANGE THESE VALUES - they must remain stable for " |
| 173 | "backward\n" |
| 174 | << "/// compatibility.\n" |
| 175 | << "enum class Opcode {\n" |
| 176 | << " // === PUBLIC OPERATIONS ===\n" |
| 177 | << " // These are available in all builds and must never be " |
| 178 | "renumbered.\n"; |
| 179 | |
| 180 | // Generate public opcodes. |
| 181 | for (const Record *record : opcodeRecords) { |
| 182 | if (record->isSubClassOf("PublicOpcode")) { |
| 183 | const Record *opRecord = record->getValueAsDef("operation"); |
| 184 | unsigned opcodeValue = record->getValueAsInt("opcodeValue"); |
| 185 | Operator op(opRecord); |
| 186 | os << " " << op.getCppClassName() << " = 0x" |
| 187 | << llvm::format("%X", opcodeValue) << ",\n"; |
| 188 | } |
| 189 | } |
| 190 | os << "\n// Reserved range for future PUBLIC operations.\n\n"; |
| 191 | os << "};\n\n" |
| 192 | << "} // namespace Bytecode\n" |
| 193 | << "} // namespace cuda_tile\n" |
| 194 | << "} // namespace mlir\n"; |
| 195 | } |
| 196 | |
| 197 | /// Generates the opcode map implementation from TableGen records |
| 198 | static void generateOpcodeMap(const RecordKeeper &records, raw_ostream &os) { |
no test coverage detected