1 //==------------------------------------------------------------------------==// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_CODEGEN_SDNODEINFO_H 10 #define LLVM_CODEGEN_SDNODEINFO_H 11 12 #include "llvm/ADT/ArrayRef.h" 13 #include "llvm/ADT/StringTable.h" 14 #include "llvm/CodeGen/ISDOpcodes.h" 15 #include "llvm/CodeGenTypes/MachineValueType.h" 16 17 namespace llvm { 18 19 class SDNode; 20 class SelectionDAG; 21 22 enum SDNP { 23 SDNPHasChain, 24 SDNPOutGlue, 25 SDNPInGlue, 26 SDNPOptInGlue, 27 SDNPMemOperand, 28 SDNPVariadic, 29 }; 30 31 enum SDTC : uint8_t { 32 SDTCisVT, 33 SDTCisPtrTy, 34 SDTCisInt, 35 SDTCisFP, 36 SDTCisVec, 37 SDTCisSameAs, 38 SDTCisVTSmallerThanOp, 39 SDTCisOpSmallerThanOp, 40 SDTCisEltOfVec, 41 SDTCisSubVecOfVec, 42 SDTCVecEltisVT, 43 SDTCisSameNumEltsAs, 44 SDTCisSameSizeAs, 45 }; 46 47 enum SDNF { 48 SDNFIsStrictFP, 49 }; 50 51 struct SDTypeConstraint { 52 SDTC Kind; 53 uint8_t OpNo; 54 uint8_t OtherOpNo; 55 MVT::SimpleValueType VT; 56 }; 57 58 using SDNodeTSFlags = uint32_t; 59 60 struct SDNodeDesc { 61 uint16_t NumResults; 62 int16_t NumOperands; 63 uint32_t Properties; 64 uint32_t Flags; 65 SDNodeTSFlags TSFlags; 66 unsigned NameOffset; 67 unsigned ConstraintOffset; 68 unsigned ConstraintCount; 69 hasPropertySDNodeDesc70 bool hasProperty(SDNP Property) const { return Properties & (1 << Property); } 71 hasFlagSDNodeDesc72 bool hasFlag(SDNF Flag) const { return Flags & (1 << Flag); } 73 }; 74 75 class SDNodeInfo final { 76 unsigned NumOpcodes; 77 const SDNodeDesc *Descs; 78 StringTable Names; 79 const SDTypeConstraint *Constraints; 80 81 public: SDNodeInfo(unsigned NumOpcodes,const SDNodeDesc * Descs,StringTable Names,const SDTypeConstraint * Constraints)82 constexpr SDNodeInfo(unsigned NumOpcodes, const SDNodeDesc *Descs, 83 StringTable Names, const SDTypeConstraint *Constraints) 84 : NumOpcodes(NumOpcodes), Descs(Descs), Names(Names), 85 Constraints(Constraints) {} 86 87 /// Returns true if there is a generated description for a node with the given 88 /// target-specific opcode. hasDesc(unsigned Opcode)89 bool hasDesc(unsigned Opcode) const { 90 assert(Opcode >= ISD::BUILTIN_OP_END && "Expected target-specific opcode"); 91 return Opcode < ISD::BUILTIN_OP_END + NumOpcodes; 92 } 93 94 /// Returns the description of a node with the given opcode. getDesc(unsigned Opcode)95 const SDNodeDesc &getDesc(unsigned Opcode) const { 96 assert(hasDesc(Opcode)); 97 return Descs[Opcode - ISD::BUILTIN_OP_END]; 98 } 99 100 /// Returns operand constraints for a node with the given opcode. getConstraints(unsigned Opcode)101 ArrayRef<SDTypeConstraint> getConstraints(unsigned Opcode) const { 102 const SDNodeDesc &Desc = getDesc(Opcode); 103 return ArrayRef(&Constraints[Desc.ConstraintOffset], Desc.ConstraintCount); 104 } 105 106 /// Returns the name of the given target-specific opcode, suitable for 107 /// debug printing. getName(unsigned Opcode)108 StringRef getName(unsigned Opcode) const { 109 return Names[getDesc(Opcode).NameOffset]; 110 } 111 112 void verifyNode(const SelectionDAG &DAG, const SDNode *N) const; 113 }; 114 115 } // namespace llvm 116 117 #endif // LLVM_CODEGEN_SDNODEINFO_H 118