llvm.org GIT mirror llvm / b923d2f
TableGen: Generate an enum for all named Operand types in tblgen'd InstrInfo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194978 91177308-0d34-0410-b5e6-96231b3b80d8 Ahmed Bougacha 7 years ago
2 changed file(s) with 75 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
953953 namespace XXX {
954954 int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIndex);
955955 } // End namespace XXX
956
957 Instruction Operand Types
958 ^^^^^^^^^^^^^^^^^^^^^^^^^
959
960 TableGen will also generate an enumeration consisting of all named Operand
961 types defined in the backend, in the llvm::XXX::OpTypes namespace.
962 Some common immediate Operand types (for instance i8, i32, i64, f32, f64)
963 are defined for all targets in ``include/llvm/Target/Target.td``, and are
964 available in each Target's OpTypes enum. Also, only named Operand types appear
965 in the enumeration: anonymous types are ignored.
966 For example, the X86 backend defines ``brtarget`` and ``brtarget8``, both
967 instances of the TableGen ``Operand`` class, which represent branch target
968 operands:
969
970 .. code-block:: llvm
971
972 def brtarget : Operand;
973 def brtarget8 : Operand;
974
975 This results in:
976
977 .. code-block:: c++
978 namespace X86 {
979 namespace OpTypes {
980 enum OperandType {
981 ...
982 brtarget,
983 brtarget8,
984 ...
985 i32imm,
986 i64imm,
987 ...
988 OPERAND_TYPE_LIST_END
989 } // End namespace OpTypes
990 } // End namespace X86
991
992 In typical TableGen fashion, to use the enum, you will need to define a
993 preprocessor macro:
994
995 .. code-block:: c++
996
997 #define GET_INSTRINFO_OPERAND_TYPES_ENUM // For OpTypes enum
998 #include "XXXGenInstrInfo.inc"
999
9561000
9571001 Instruction Scheduling
9581002 ----------------------
5656 std::map, unsigned> &EL,
5757 const OperandInfoMapTy &OpInfo,
5858 raw_ostream &OS);
59 void emitOperandTypesEnum(raw_ostream &OS, const CodeGenTarget &Target);
5960 void initOperandMapData(
6061 const std::vector NumberedInstructions,
6162 const std::string &Namespace,
310311
311312 }
312313
314 /// Generate an enum for all the operand types for this target, under the
315 /// llvm::TargetNamespace::OpTypes namespace.
316 /// Operand types are all definitions derived of the Operand Target.td class.
317 void InstrInfoEmitter::emitOperandTypesEnum(raw_ostream &OS,
318 const CodeGenTarget &Target) {
319
320 const std::string &Namespace = Target.getInstNamespace();
321 std::vector Operands = Records.getAllDerivedDefinitions("Operand");
322
323 OS << "\n#ifdef GET_INSTRINFO_OPERAND_TYPES_ENUM\n";
324 OS << "#undef GET_INSTRINFO_OPERAND_TYPES_ENUM\n";
325 OS << "namespace llvm {";
326 OS << "namespace " << Namespace << " {\n";
327 OS << "namespace OpTypes { \n";
328 OS << "enum OperandType {\n";
329
330 for (unsigned oi = 0, oe = Operands.size(); oi != oe; ++oi) {
331 if (!Operands[oi]->isAnonymous())
332 OS << " " << Operands[oi]->getName() << " = " << oi << ",\n";
333 }
334
335 OS << " OPERAND_TYPE_LIST_END" << "\n};\n";
336 OS << "} // End namespace OpTypes\n";
337 OS << "} // End namespace " << Namespace << "\n";
338 OS << "} // End namespace llvm\n";
339 OS << "#endif // GET_INSTRINFO_OPERAND_TYPES_ENUM\n";
340 }
341
313342 //===----------------------------------------------------------------------===//
314343 // Main Output.
315344 //===----------------------------------------------------------------------===//
431460 OS << "#endif // GET_INSTRINFO_CTOR_DTOR\n\n";
432461
433462 emitOperandNameMappings(OS, Target, NumberedInstructions);
463
464 emitOperandTypesEnum(OS, Target);
434465 }
435466
436467 void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,