1f4a2713aSLionel Sambuc //===- CodeGenRegisters.h - Register and RegisterClass Info -----*- C++ -*-===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10f4a2713aSLionel Sambuc // This file defines structures to encapsulate information gleaned from the 11f4a2713aSLionel Sambuc // target register and register class definitions. 12f4a2713aSLionel Sambuc // 13f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 14f4a2713aSLionel Sambuc 15*0a6a1f1dSLionel Sambuc #ifndef LLVM_UTILS_TABLEGEN_CODEGENREGISTERS_H 16*0a6a1f1dSLionel Sambuc #define LLVM_UTILS_TABLEGEN_CODEGENREGISTERS_H 17f4a2713aSLionel Sambuc 18f4a2713aSLionel Sambuc #include "llvm/ADT/ArrayRef.h" 19f4a2713aSLionel Sambuc #include "llvm/ADT/BitVector.h" 20f4a2713aSLionel Sambuc #include "llvm/ADT/DenseMap.h" 21f4a2713aSLionel Sambuc #include "llvm/ADT/SetVector.h" 22*0a6a1f1dSLionel Sambuc #include "llvm/CodeGen/MachineValueType.h" 23f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h" 24f4a2713aSLionel Sambuc #include "llvm/TableGen/Record.h" 25*0a6a1f1dSLionel Sambuc #include "llvm/TableGen/SetTheory.h" 26f4a2713aSLionel Sambuc #include <cstdlib> 27*0a6a1f1dSLionel Sambuc #include <list> 28f4a2713aSLionel Sambuc #include <map> 29f4a2713aSLionel Sambuc #include <set> 30f4a2713aSLionel Sambuc #include <string> 31f4a2713aSLionel Sambuc #include <vector> 32*0a6a1f1dSLionel Sambuc #include <deque> 33f4a2713aSLionel Sambuc 34f4a2713aSLionel Sambuc namespace llvm { 35f4a2713aSLionel Sambuc class CodeGenRegBank; 36f4a2713aSLionel Sambuc 37*0a6a1f1dSLionel Sambuc /// Used to encode a step in a register lane mask transformation. 38*0a6a1f1dSLionel Sambuc /// Mask the bits specified in Mask, then rotate them Rol bits to the left 39*0a6a1f1dSLionel Sambuc /// assuming a wraparound at 32bits. 40*0a6a1f1dSLionel Sambuc struct MaskRolPair { 41*0a6a1f1dSLionel Sambuc unsigned Mask; 42*0a6a1f1dSLionel Sambuc uint8_t RotateLeft; 43*0a6a1f1dSLionel Sambuc bool operator==(const MaskRolPair Other) { 44*0a6a1f1dSLionel Sambuc return Mask == Other.Mask && RotateLeft == Other.RotateLeft; 45*0a6a1f1dSLionel Sambuc } 46*0a6a1f1dSLionel Sambuc bool operator!=(const MaskRolPair Other) { 47*0a6a1f1dSLionel Sambuc return Mask != Other.Mask || RotateLeft != Other.RotateLeft; 48*0a6a1f1dSLionel Sambuc } 49*0a6a1f1dSLionel Sambuc }; 50*0a6a1f1dSLionel Sambuc 51f4a2713aSLionel Sambuc /// CodeGenSubRegIndex - Represents a sub-register index. 52f4a2713aSLionel Sambuc class CodeGenSubRegIndex { 53f4a2713aSLionel Sambuc Record *const TheDef; 54f4a2713aSLionel Sambuc std::string Name; 55f4a2713aSLionel Sambuc std::string Namespace; 56f4a2713aSLionel Sambuc 57f4a2713aSLionel Sambuc public: 58f4a2713aSLionel Sambuc uint16_t Size; 59f4a2713aSLionel Sambuc uint16_t Offset; 60f4a2713aSLionel Sambuc const unsigned EnumValue; 61*0a6a1f1dSLionel Sambuc mutable unsigned LaneMask; 62*0a6a1f1dSLionel Sambuc mutable SmallVector<MaskRolPair,1> CompositionLaneMaskTransform; 63f4a2713aSLionel Sambuc 64f4a2713aSLionel Sambuc // Are all super-registers containing this SubRegIndex covered by their 65f4a2713aSLionel Sambuc // sub-registers? 66f4a2713aSLionel Sambuc bool AllSuperRegsCovered; 67f4a2713aSLionel Sambuc 68f4a2713aSLionel Sambuc CodeGenSubRegIndex(Record *R, unsigned Enum); 69f4a2713aSLionel Sambuc CodeGenSubRegIndex(StringRef N, StringRef Nspace, unsigned Enum); 70f4a2713aSLionel Sambuc getName()71f4a2713aSLionel Sambuc const std::string &getName() const { return Name; } getNamespace()72f4a2713aSLionel Sambuc const std::string &getNamespace() const { return Namespace; } 73f4a2713aSLionel Sambuc std::string getQualifiedName() const; 74f4a2713aSLionel Sambuc 75f4a2713aSLionel Sambuc // Order CodeGenSubRegIndex pointers by EnumValue. 76f4a2713aSLionel Sambuc struct Less { operatorLess77f4a2713aSLionel Sambuc bool operator()(const CodeGenSubRegIndex *A, 78f4a2713aSLionel Sambuc const CodeGenSubRegIndex *B) const { 79f4a2713aSLionel Sambuc assert(A && B); 80f4a2713aSLionel Sambuc return A->EnumValue < B->EnumValue; 81f4a2713aSLionel Sambuc } 82f4a2713aSLionel Sambuc }; 83f4a2713aSLionel Sambuc 84f4a2713aSLionel Sambuc // Map of composite subreg indices. 85f4a2713aSLionel Sambuc typedef std::map<CodeGenSubRegIndex*, CodeGenSubRegIndex*, Less> CompMap; 86f4a2713aSLionel Sambuc 87f4a2713aSLionel Sambuc // Returns the subreg index that results from composing this with Idx. 88f4a2713aSLionel Sambuc // Returns NULL if this and Idx don't compose. compose(CodeGenSubRegIndex * Idx)89f4a2713aSLionel Sambuc CodeGenSubRegIndex *compose(CodeGenSubRegIndex *Idx) const { 90f4a2713aSLionel Sambuc CompMap::const_iterator I = Composed.find(Idx); 91*0a6a1f1dSLionel Sambuc return I == Composed.end() ? nullptr : I->second; 92f4a2713aSLionel Sambuc } 93f4a2713aSLionel Sambuc 94f4a2713aSLionel Sambuc // Add a composite subreg index: this+A = B. 95f4a2713aSLionel Sambuc // Return a conflicting composite, or NULL addComposite(CodeGenSubRegIndex * A,CodeGenSubRegIndex * B)96f4a2713aSLionel Sambuc CodeGenSubRegIndex *addComposite(CodeGenSubRegIndex *A, 97f4a2713aSLionel Sambuc CodeGenSubRegIndex *B) { 98f4a2713aSLionel Sambuc assert(A && B); 99f4a2713aSLionel Sambuc std::pair<CompMap::iterator, bool> Ins = 100f4a2713aSLionel Sambuc Composed.insert(std::make_pair(A, B)); 101f4a2713aSLionel Sambuc // Synthetic subreg indices that aren't contiguous (for instance ARM 102f4a2713aSLionel Sambuc // register tuples) don't have a bit range, so it's OK to let 103f4a2713aSLionel Sambuc // B->Offset == -1. For the other cases, accumulate the offset and set 104f4a2713aSLionel Sambuc // the size here. Only do so if there is no offset yet though. 105f4a2713aSLionel Sambuc if ((Offset != (uint16_t)-1 && A->Offset != (uint16_t)-1) && 106f4a2713aSLionel Sambuc (B->Offset == (uint16_t)-1)) { 107f4a2713aSLionel Sambuc B->Offset = Offset + A->Offset; 108f4a2713aSLionel Sambuc B->Size = A->Size; 109f4a2713aSLionel Sambuc } 110*0a6a1f1dSLionel Sambuc return (Ins.second || Ins.first->second == B) ? nullptr 111*0a6a1f1dSLionel Sambuc : Ins.first->second; 112f4a2713aSLionel Sambuc } 113f4a2713aSLionel Sambuc 114f4a2713aSLionel Sambuc // Update the composite maps of components specified in 'ComposedOf'. 115f4a2713aSLionel Sambuc void updateComponents(CodeGenRegBank&); 116f4a2713aSLionel Sambuc 117f4a2713aSLionel Sambuc // Return the map of composites. getComposites()118f4a2713aSLionel Sambuc const CompMap &getComposites() const { return Composed; } 119f4a2713aSLionel Sambuc 120f4a2713aSLionel Sambuc // Compute LaneMask from Composed. Return LaneMask. 121*0a6a1f1dSLionel Sambuc unsigned computeLaneMask() const; 122f4a2713aSLionel Sambuc 123f4a2713aSLionel Sambuc private: 124f4a2713aSLionel Sambuc CompMap Composed; 125f4a2713aSLionel Sambuc }; 126f4a2713aSLionel Sambuc 127f4a2713aSLionel Sambuc /// CodeGenRegister - Represents a register definition. 128f4a2713aSLionel Sambuc struct CodeGenRegister { 129f4a2713aSLionel Sambuc Record *TheDef; 130f4a2713aSLionel Sambuc unsigned EnumValue; 131f4a2713aSLionel Sambuc unsigned CostPerUse; 132f4a2713aSLionel Sambuc bool CoveredBySubRegs; 133f4a2713aSLionel Sambuc 134f4a2713aSLionel Sambuc // Map SubRegIndex -> Register. 135f4a2713aSLionel Sambuc typedef std::map<CodeGenSubRegIndex*, CodeGenRegister*, 136f4a2713aSLionel Sambuc CodeGenSubRegIndex::Less> SubRegMap; 137f4a2713aSLionel Sambuc 138f4a2713aSLionel Sambuc CodeGenRegister(Record *R, unsigned Enum); 139f4a2713aSLionel Sambuc 140f4a2713aSLionel Sambuc const std::string &getName() const; 141f4a2713aSLionel Sambuc 142f4a2713aSLionel Sambuc // Extract more information from TheDef. This is used to build an object 143f4a2713aSLionel Sambuc // graph after all CodeGenRegister objects have been created. 144f4a2713aSLionel Sambuc void buildObjectGraph(CodeGenRegBank&); 145f4a2713aSLionel Sambuc 146f4a2713aSLionel Sambuc // Lazily compute a map of all sub-registers. 147f4a2713aSLionel Sambuc // This includes unique entries for all sub-sub-registers. 148f4a2713aSLionel Sambuc const SubRegMap &computeSubRegs(CodeGenRegBank&); 149f4a2713aSLionel Sambuc 150f4a2713aSLionel Sambuc // Compute extra sub-registers by combining the existing sub-registers. 151f4a2713aSLionel Sambuc void computeSecondarySubRegs(CodeGenRegBank&); 152f4a2713aSLionel Sambuc 153f4a2713aSLionel Sambuc // Add this as a super-register to all sub-registers after the sub-register 154f4a2713aSLionel Sambuc // graph has been built. 155f4a2713aSLionel Sambuc void computeSuperRegs(CodeGenRegBank&); 156f4a2713aSLionel Sambuc getSubRegsCodeGenRegister157f4a2713aSLionel Sambuc const SubRegMap &getSubRegs() const { 158f4a2713aSLionel Sambuc assert(SubRegsComplete && "Must precompute sub-registers"); 159f4a2713aSLionel Sambuc return SubRegs; 160f4a2713aSLionel Sambuc } 161f4a2713aSLionel Sambuc 162f4a2713aSLionel Sambuc // Add sub-registers to OSet following a pre-order defined by the .td file. 163f4a2713aSLionel Sambuc void addSubRegsPreOrder(SetVector<const CodeGenRegister*> &OSet, 164f4a2713aSLionel Sambuc CodeGenRegBank&) const; 165f4a2713aSLionel Sambuc 166f4a2713aSLionel Sambuc // Return the sub-register index naming Reg as a sub-register of this 167f4a2713aSLionel Sambuc // register. Returns NULL if Reg is not a sub-register. getSubRegIndexCodeGenRegister168f4a2713aSLionel Sambuc CodeGenSubRegIndex *getSubRegIndex(const CodeGenRegister *Reg) const { 169f4a2713aSLionel Sambuc return SubReg2Idx.lookup(Reg); 170f4a2713aSLionel Sambuc } 171f4a2713aSLionel Sambuc 172f4a2713aSLionel Sambuc typedef std::vector<const CodeGenRegister*> SuperRegList; 173f4a2713aSLionel Sambuc 174f4a2713aSLionel Sambuc // Get the list of super-registers in topological order, small to large. 175f4a2713aSLionel Sambuc // This is valid after computeSubRegs visits all registers during RegBank 176f4a2713aSLionel Sambuc // construction. getSuperRegsCodeGenRegister177f4a2713aSLionel Sambuc const SuperRegList &getSuperRegs() const { 178f4a2713aSLionel Sambuc assert(SubRegsComplete && "Must precompute sub-registers"); 179f4a2713aSLionel Sambuc return SuperRegs; 180f4a2713aSLionel Sambuc } 181f4a2713aSLionel Sambuc 182f4a2713aSLionel Sambuc // Get the list of ad hoc aliases. The graph is symmetric, so the list 183f4a2713aSLionel Sambuc // contains all registers in 'Aliases', and all registers that mention this 184f4a2713aSLionel Sambuc // register in 'Aliases'. getExplicitAliasesCodeGenRegister185f4a2713aSLionel Sambuc ArrayRef<CodeGenRegister*> getExplicitAliases() const { 186f4a2713aSLionel Sambuc return ExplicitAliases; 187f4a2713aSLionel Sambuc } 188f4a2713aSLionel Sambuc 189f4a2713aSLionel Sambuc // Get the topological signature of this register. This is a small integer 190f4a2713aSLionel Sambuc // less than RegBank.getNumTopoSigs(). Registers with the same TopoSig have 191f4a2713aSLionel Sambuc // identical sub-register structure. That is, they support the same set of 192f4a2713aSLionel Sambuc // sub-register indices mapping to the same kind of sub-registers 193f4a2713aSLionel Sambuc // (TopoSig-wise). getTopoSigCodeGenRegister194f4a2713aSLionel Sambuc unsigned getTopoSig() const { 195f4a2713aSLionel Sambuc assert(SuperRegsComplete && "TopoSigs haven't been computed yet."); 196f4a2713aSLionel Sambuc return TopoSig; 197f4a2713aSLionel Sambuc } 198f4a2713aSLionel Sambuc 199f4a2713aSLionel Sambuc // List of register units in ascending order. 200f4a2713aSLionel Sambuc typedef SmallVector<unsigned, 16> RegUnitList; 201*0a6a1f1dSLionel Sambuc typedef SmallVector<unsigned, 16> RegUnitLaneMaskList; 202f4a2713aSLionel Sambuc 203f4a2713aSLionel Sambuc // How many entries in RegUnitList are native? 204f4a2713aSLionel Sambuc unsigned NumNativeRegUnits; 205f4a2713aSLionel Sambuc 206f4a2713aSLionel Sambuc // Get the list of register units. 207f4a2713aSLionel Sambuc // This is only valid after computeSubRegs() completes. getRegUnitsCodeGenRegister208f4a2713aSLionel Sambuc const RegUnitList &getRegUnits() const { return RegUnits; } 209f4a2713aSLionel Sambuc getRegUnitLaneMasksCodeGenRegister210*0a6a1f1dSLionel Sambuc ArrayRef<unsigned> getRegUnitLaneMasks() const { 211*0a6a1f1dSLionel Sambuc return makeArrayRef(RegUnitLaneMasks).slice(0, NumNativeRegUnits); 212*0a6a1f1dSLionel Sambuc } 213*0a6a1f1dSLionel Sambuc 214f4a2713aSLionel Sambuc // Get the native register units. This is a prefix of getRegUnits(). getNativeRegUnitsCodeGenRegister215f4a2713aSLionel Sambuc ArrayRef<unsigned> getNativeRegUnits() const { 216f4a2713aSLionel Sambuc return makeArrayRef(RegUnits).slice(0, NumNativeRegUnits); 217f4a2713aSLionel Sambuc } 218f4a2713aSLionel Sambuc setRegUnitLaneMasksCodeGenRegister219*0a6a1f1dSLionel Sambuc void setRegUnitLaneMasks(const RegUnitLaneMaskList &LaneMasks) { 220*0a6a1f1dSLionel Sambuc RegUnitLaneMasks = LaneMasks; 221*0a6a1f1dSLionel Sambuc } 222*0a6a1f1dSLionel Sambuc 223f4a2713aSLionel Sambuc // Inherit register units from subregisters. 224f4a2713aSLionel Sambuc // Return true if the RegUnits changed. 225f4a2713aSLionel Sambuc bool inheritRegUnits(CodeGenRegBank &RegBank); 226f4a2713aSLionel Sambuc 227f4a2713aSLionel Sambuc // Adopt a register unit for pressure tracking. 228f4a2713aSLionel Sambuc // A unit is adopted iff its unit number is >= NumNativeRegUnits. adoptRegUnitCodeGenRegister229f4a2713aSLionel Sambuc void adoptRegUnit(unsigned RUID) { RegUnits.push_back(RUID); } 230f4a2713aSLionel Sambuc 231f4a2713aSLionel Sambuc // Get the sum of this register's register unit weights. 232f4a2713aSLionel Sambuc unsigned getWeight(const CodeGenRegBank &RegBank) const; 233f4a2713aSLionel Sambuc 234f4a2713aSLionel Sambuc // Order CodeGenRegister pointers by EnumValue. 235f4a2713aSLionel Sambuc struct Less { operatorCodeGenRegister::Less236f4a2713aSLionel Sambuc bool operator()(const CodeGenRegister *A, 237f4a2713aSLionel Sambuc const CodeGenRegister *B) const { 238f4a2713aSLionel Sambuc assert(A && B); 239f4a2713aSLionel Sambuc return A->EnumValue < B->EnumValue; 240f4a2713aSLionel Sambuc } 241f4a2713aSLionel Sambuc }; 242f4a2713aSLionel Sambuc 243f4a2713aSLionel Sambuc // Canonically ordered set. 244f4a2713aSLionel Sambuc typedef std::set<const CodeGenRegister*, Less> Set; 245f4a2713aSLionel Sambuc 246f4a2713aSLionel Sambuc private: 247f4a2713aSLionel Sambuc bool SubRegsComplete; 248f4a2713aSLionel Sambuc bool SuperRegsComplete; 249f4a2713aSLionel Sambuc unsigned TopoSig; 250f4a2713aSLionel Sambuc 251f4a2713aSLionel Sambuc // The sub-registers explicit in the .td file form a tree. 252f4a2713aSLionel Sambuc SmallVector<CodeGenSubRegIndex*, 8> ExplicitSubRegIndices; 253f4a2713aSLionel Sambuc SmallVector<CodeGenRegister*, 8> ExplicitSubRegs; 254f4a2713aSLionel Sambuc 255f4a2713aSLionel Sambuc // Explicit ad hoc aliases, symmetrized to form an undirected graph. 256f4a2713aSLionel Sambuc SmallVector<CodeGenRegister*, 8> ExplicitAliases; 257f4a2713aSLionel Sambuc 258f4a2713aSLionel Sambuc // Super-registers where this is the first explicit sub-register. 259f4a2713aSLionel Sambuc SuperRegList LeadingSuperRegs; 260f4a2713aSLionel Sambuc 261f4a2713aSLionel Sambuc SubRegMap SubRegs; 262f4a2713aSLionel Sambuc SuperRegList SuperRegs; 263f4a2713aSLionel Sambuc DenseMap<const CodeGenRegister*, CodeGenSubRegIndex*> SubReg2Idx; 264f4a2713aSLionel Sambuc RegUnitList RegUnits; 265*0a6a1f1dSLionel Sambuc RegUnitLaneMaskList RegUnitLaneMasks; 266f4a2713aSLionel Sambuc }; 267f4a2713aSLionel Sambuc 268f4a2713aSLionel Sambuc 269f4a2713aSLionel Sambuc class CodeGenRegisterClass { 270f4a2713aSLionel Sambuc CodeGenRegister::Set Members; 271f4a2713aSLionel Sambuc // Allocation orders. Order[0] always contains all registers in Members. 272f4a2713aSLionel Sambuc std::vector<SmallVector<Record*, 16> > Orders; 273f4a2713aSLionel Sambuc // Bit mask of sub-classes including this, indexed by their EnumValue. 274f4a2713aSLionel Sambuc BitVector SubClasses; 275f4a2713aSLionel Sambuc // List of super-classes, topologocally ordered to have the larger classes 276f4a2713aSLionel Sambuc // first. This is the same as sorting by EnumValue. 277f4a2713aSLionel Sambuc SmallVector<CodeGenRegisterClass*, 4> SuperClasses; 278f4a2713aSLionel Sambuc Record *TheDef; 279f4a2713aSLionel Sambuc std::string Name; 280f4a2713aSLionel Sambuc 281f4a2713aSLionel Sambuc // For a synthesized class, inherit missing properties from the nearest 282f4a2713aSLionel Sambuc // super-class. 283f4a2713aSLionel Sambuc void inheritProperties(CodeGenRegBank&); 284f4a2713aSLionel Sambuc 285f4a2713aSLionel Sambuc // Map SubRegIndex -> sub-class. This is the largest sub-class where all 286f4a2713aSLionel Sambuc // registers have a SubRegIndex sub-register. 287*0a6a1f1dSLionel Sambuc DenseMap<const CodeGenSubRegIndex *, CodeGenRegisterClass *> 288*0a6a1f1dSLionel Sambuc SubClassWithSubReg; 289f4a2713aSLionel Sambuc 290f4a2713aSLionel Sambuc // Map SubRegIndex -> set of super-reg classes. This is all register 291f4a2713aSLionel Sambuc // classes SuperRC such that: 292f4a2713aSLionel Sambuc // 293f4a2713aSLionel Sambuc // R:SubRegIndex in this RC for all R in SuperRC. 294f4a2713aSLionel Sambuc // 295*0a6a1f1dSLionel Sambuc DenseMap<const CodeGenSubRegIndex *, SmallPtrSet<CodeGenRegisterClass *, 8>> 296*0a6a1f1dSLionel Sambuc SuperRegClasses; 297f4a2713aSLionel Sambuc 298f4a2713aSLionel Sambuc // Bit vector of TopoSigs for the registers in this class. This will be 299f4a2713aSLionel Sambuc // very sparse on regular architectures. 300f4a2713aSLionel Sambuc BitVector TopoSigs; 301f4a2713aSLionel Sambuc 302f4a2713aSLionel Sambuc public: 303f4a2713aSLionel Sambuc unsigned EnumValue; 304f4a2713aSLionel Sambuc std::string Namespace; 305f4a2713aSLionel Sambuc SmallVector<MVT::SimpleValueType, 4> VTs; 306f4a2713aSLionel Sambuc unsigned SpillSize; 307f4a2713aSLionel Sambuc unsigned SpillAlignment; 308f4a2713aSLionel Sambuc int CopyCost; 309f4a2713aSLionel Sambuc bool Allocatable; 310f4a2713aSLionel Sambuc std::string AltOrderSelect; 311*0a6a1f1dSLionel Sambuc /// Contains the combination of the lane masks of all subregisters. 312*0a6a1f1dSLionel Sambuc unsigned LaneMask; 313f4a2713aSLionel Sambuc 314f4a2713aSLionel Sambuc // Return the Record that defined this class, or NULL if the class was 315f4a2713aSLionel Sambuc // created by TableGen. getDef()316f4a2713aSLionel Sambuc Record *getDef() const { return TheDef; } 317f4a2713aSLionel Sambuc getName()318f4a2713aSLionel Sambuc const std::string &getName() const { return Name; } 319f4a2713aSLionel Sambuc std::string getQualifiedName() const; getValueTypes()320f4a2713aSLionel Sambuc ArrayRef<MVT::SimpleValueType> getValueTypes() const {return VTs;} getNumValueTypes()321f4a2713aSLionel Sambuc unsigned getNumValueTypes() const { return VTs.size(); } 322f4a2713aSLionel Sambuc getValueTypeNum(unsigned VTNum)323f4a2713aSLionel Sambuc MVT::SimpleValueType getValueTypeNum(unsigned VTNum) const { 324f4a2713aSLionel Sambuc if (VTNum < VTs.size()) 325f4a2713aSLionel Sambuc return VTs[VTNum]; 326f4a2713aSLionel Sambuc llvm_unreachable("VTNum greater than number of ValueTypes in RegClass!"); 327f4a2713aSLionel Sambuc } 328f4a2713aSLionel Sambuc 329f4a2713aSLionel Sambuc // Return true if this this class contains the register. 330f4a2713aSLionel Sambuc bool contains(const CodeGenRegister*) const; 331f4a2713aSLionel Sambuc 332f4a2713aSLionel Sambuc // Returns true if RC is a subclass. 333f4a2713aSLionel Sambuc // RC is a sub-class of this class if it is a valid replacement for any 334f4a2713aSLionel Sambuc // instruction operand where a register of this classis required. It must 335f4a2713aSLionel Sambuc // satisfy these conditions: 336f4a2713aSLionel Sambuc // 337f4a2713aSLionel Sambuc // 1. All RC registers are also in this. 338f4a2713aSLionel Sambuc // 2. The RC spill size must not be smaller than our spill size. 339f4a2713aSLionel Sambuc // 3. RC spill alignment must be compatible with ours. 340f4a2713aSLionel Sambuc // hasSubClass(const CodeGenRegisterClass * RC)341f4a2713aSLionel Sambuc bool hasSubClass(const CodeGenRegisterClass *RC) const { 342f4a2713aSLionel Sambuc return SubClasses.test(RC->EnumValue); 343f4a2713aSLionel Sambuc } 344f4a2713aSLionel Sambuc 345f4a2713aSLionel Sambuc // getSubClassWithSubReg - Returns the largest sub-class where all 346f4a2713aSLionel Sambuc // registers have a SubIdx sub-register. 347f4a2713aSLionel Sambuc CodeGenRegisterClass * getSubClassWithSubReg(const CodeGenSubRegIndex * SubIdx)348*0a6a1f1dSLionel Sambuc getSubClassWithSubReg(const CodeGenSubRegIndex *SubIdx) const { 349f4a2713aSLionel Sambuc return SubClassWithSubReg.lookup(SubIdx); 350f4a2713aSLionel Sambuc } 351f4a2713aSLionel Sambuc setSubClassWithSubReg(const CodeGenSubRegIndex * SubIdx,CodeGenRegisterClass * SubRC)352*0a6a1f1dSLionel Sambuc void setSubClassWithSubReg(const CodeGenSubRegIndex *SubIdx, 353f4a2713aSLionel Sambuc CodeGenRegisterClass *SubRC) { 354f4a2713aSLionel Sambuc SubClassWithSubReg[SubIdx] = SubRC; 355f4a2713aSLionel Sambuc } 356f4a2713aSLionel Sambuc 357f4a2713aSLionel Sambuc // getSuperRegClasses - Returns a bit vector of all register classes 358f4a2713aSLionel Sambuc // containing only SubIdx super-registers of this class. 359*0a6a1f1dSLionel Sambuc void getSuperRegClasses(const CodeGenSubRegIndex *SubIdx, 360*0a6a1f1dSLionel Sambuc BitVector &Out) const; 361f4a2713aSLionel Sambuc 362f4a2713aSLionel Sambuc // addSuperRegClass - Add a class containing only SudIdx super-registers. addSuperRegClass(CodeGenSubRegIndex * SubIdx,CodeGenRegisterClass * SuperRC)363f4a2713aSLionel Sambuc void addSuperRegClass(CodeGenSubRegIndex *SubIdx, 364f4a2713aSLionel Sambuc CodeGenRegisterClass *SuperRC) { 365f4a2713aSLionel Sambuc SuperRegClasses[SubIdx].insert(SuperRC); 366f4a2713aSLionel Sambuc } 367f4a2713aSLionel Sambuc 368f4a2713aSLionel Sambuc // getSubClasses - Returns a constant BitVector of subclasses indexed by 369f4a2713aSLionel Sambuc // EnumValue. 370*0a6a1f1dSLionel Sambuc // The SubClasses vector includes an entry for this class. getSubClasses()371f4a2713aSLionel Sambuc const BitVector &getSubClasses() const { return SubClasses; } 372f4a2713aSLionel Sambuc 373f4a2713aSLionel Sambuc // getSuperClasses - Returns a list of super classes ordered by EnumValue. 374f4a2713aSLionel Sambuc // The array does not include an entry for this class. getSuperClasses()375f4a2713aSLionel Sambuc ArrayRef<CodeGenRegisterClass*> getSuperClasses() const { 376f4a2713aSLionel Sambuc return SuperClasses; 377f4a2713aSLionel Sambuc } 378f4a2713aSLionel Sambuc 379f4a2713aSLionel Sambuc // Returns an ordered list of class members. 380f4a2713aSLionel Sambuc // The order of registers is the same as in the .td file. 381f4a2713aSLionel Sambuc // No = 0 is the default allocation order, No = 1 is the first alternative. 382f4a2713aSLionel Sambuc ArrayRef<Record*> getOrder(unsigned No = 0) const { 383f4a2713aSLionel Sambuc return Orders[No]; 384f4a2713aSLionel Sambuc } 385f4a2713aSLionel Sambuc 386f4a2713aSLionel Sambuc // Return the total number of allocation orders available. getNumOrders()387f4a2713aSLionel Sambuc unsigned getNumOrders() const { return Orders.size(); } 388f4a2713aSLionel Sambuc 389f4a2713aSLionel Sambuc // Get the set of registers. This set contains the same registers as 390f4a2713aSLionel Sambuc // getOrder(0). getMembers()391f4a2713aSLionel Sambuc const CodeGenRegister::Set &getMembers() const { return Members; } 392f4a2713aSLionel Sambuc 393f4a2713aSLionel Sambuc // Get a bit vector of TopoSigs present in this register class. getTopoSigs()394f4a2713aSLionel Sambuc const BitVector &getTopoSigs() const { return TopoSigs; } 395f4a2713aSLionel Sambuc 396f4a2713aSLionel Sambuc // Populate a unique sorted list of units from a register set. 397f4a2713aSLionel Sambuc void buildRegUnitSet(std::vector<unsigned> &RegUnits) const; 398f4a2713aSLionel Sambuc 399f4a2713aSLionel Sambuc CodeGenRegisterClass(CodeGenRegBank&, Record *R); 400f4a2713aSLionel Sambuc 401f4a2713aSLionel Sambuc // A key representing the parts of a register class used for forming 402f4a2713aSLionel Sambuc // sub-classes. Note the ordering provided by this key is not the same as 403f4a2713aSLionel Sambuc // the topological order used for the EnumValues. 404f4a2713aSLionel Sambuc struct Key { 405f4a2713aSLionel Sambuc const CodeGenRegister::Set *Members; 406f4a2713aSLionel Sambuc unsigned SpillSize; 407f4a2713aSLionel Sambuc unsigned SpillAlignment; 408f4a2713aSLionel Sambuc 409f4a2713aSLionel Sambuc Key(const CodeGenRegister::Set *M, unsigned S = 0, unsigned A = 0) MembersKey410f4a2713aSLionel Sambuc : Members(M), SpillSize(S), SpillAlignment(A) {} 411f4a2713aSLionel Sambuc KeyKey412f4a2713aSLionel Sambuc Key(const CodeGenRegisterClass &RC) 413f4a2713aSLionel Sambuc : Members(&RC.getMembers()), 414f4a2713aSLionel Sambuc SpillSize(RC.SpillSize), 415f4a2713aSLionel Sambuc SpillAlignment(RC.SpillAlignment) {} 416f4a2713aSLionel Sambuc 417f4a2713aSLionel Sambuc // Lexicographical order of (Members, SpillSize, SpillAlignment). 418f4a2713aSLionel Sambuc bool operator<(const Key&) const; 419f4a2713aSLionel Sambuc }; 420f4a2713aSLionel Sambuc 421f4a2713aSLionel Sambuc // Create a non-user defined register class. 422f4a2713aSLionel Sambuc CodeGenRegisterClass(CodeGenRegBank&, StringRef Name, Key Props); 423f4a2713aSLionel Sambuc 424f4a2713aSLionel Sambuc // Called by CodeGenRegBank::CodeGenRegBank(). 425f4a2713aSLionel Sambuc static void computeSubClasses(CodeGenRegBank&); 426f4a2713aSLionel Sambuc }; 427f4a2713aSLionel Sambuc 428f4a2713aSLionel Sambuc // Register units are used to model interference and register pressure. 429f4a2713aSLionel Sambuc // Every register is assigned one or more register units such that two 430f4a2713aSLionel Sambuc // registers overlap if and only if they have a register unit in common. 431f4a2713aSLionel Sambuc // 432f4a2713aSLionel Sambuc // Normally, one register unit is created per leaf register. Non-leaf 433f4a2713aSLionel Sambuc // registers inherit the units of their sub-registers. 434f4a2713aSLionel Sambuc struct RegUnit { 435f4a2713aSLionel Sambuc // Weight assigned to this RegUnit for estimating register pressure. 436f4a2713aSLionel Sambuc // This is useful when equalizing weights in register classes with mixed 437f4a2713aSLionel Sambuc // register topologies. 438f4a2713aSLionel Sambuc unsigned Weight; 439f4a2713aSLionel Sambuc 440f4a2713aSLionel Sambuc // Each native RegUnit corresponds to one or two root registers. The full 441f4a2713aSLionel Sambuc // set of registers containing this unit can be computed as the union of 442f4a2713aSLionel Sambuc // these two registers and their super-registers. 443f4a2713aSLionel Sambuc const CodeGenRegister *Roots[2]; 444f4a2713aSLionel Sambuc 445f4a2713aSLionel Sambuc // Index into RegClassUnitSets where we can find the list of UnitSets that 446f4a2713aSLionel Sambuc // contain this unit. 447f4a2713aSLionel Sambuc unsigned RegClassUnitSetsIdx; 448f4a2713aSLionel Sambuc RegUnitRegUnit449*0a6a1f1dSLionel Sambuc RegUnit() : Weight(0), RegClassUnitSetsIdx(0) { 450*0a6a1f1dSLionel Sambuc Roots[0] = Roots[1] = nullptr; 451*0a6a1f1dSLionel Sambuc } 452f4a2713aSLionel Sambuc getRootsRegUnit453f4a2713aSLionel Sambuc ArrayRef<const CodeGenRegister*> getRoots() const { 454f4a2713aSLionel Sambuc assert(!(Roots[1] && !Roots[0]) && "Invalid roots array"); 455f4a2713aSLionel Sambuc return makeArrayRef(Roots, !!Roots[0] + !!Roots[1]); 456f4a2713aSLionel Sambuc } 457f4a2713aSLionel Sambuc }; 458f4a2713aSLionel Sambuc 459f4a2713aSLionel Sambuc // Each RegUnitSet is a sorted vector with a name. 460f4a2713aSLionel Sambuc struct RegUnitSet { 461f4a2713aSLionel Sambuc typedef std::vector<unsigned>::const_iterator iterator; 462f4a2713aSLionel Sambuc 463f4a2713aSLionel Sambuc std::string Name; 464f4a2713aSLionel Sambuc std::vector<unsigned> Units; 465f4a2713aSLionel Sambuc unsigned Weight; // Cache the sum of all unit weights. 466f4a2713aSLionel Sambuc unsigned Order; // Cache the sort key. 467f4a2713aSLionel Sambuc RegUnitSetRegUnitSet468f4a2713aSLionel Sambuc RegUnitSet() : Weight(0), Order(0) {} 469f4a2713aSLionel Sambuc }; 470f4a2713aSLionel Sambuc 471f4a2713aSLionel Sambuc // Base vector for identifying TopoSigs. The contents uniquely identify a 472f4a2713aSLionel Sambuc // TopoSig, only computeSuperRegs needs to know how. 473f4a2713aSLionel Sambuc typedef SmallVector<unsigned, 16> TopoSigId; 474f4a2713aSLionel Sambuc 475f4a2713aSLionel Sambuc // CodeGenRegBank - Represent a target's registers and the relations between 476f4a2713aSLionel Sambuc // them. 477f4a2713aSLionel Sambuc class CodeGenRegBank { 478f4a2713aSLionel Sambuc SetTheory Sets; 479f4a2713aSLionel Sambuc 480*0a6a1f1dSLionel Sambuc std::deque<CodeGenSubRegIndex> SubRegIndices; 481f4a2713aSLionel Sambuc DenseMap<Record*, CodeGenSubRegIndex*> Def2SubRegIdx; 482f4a2713aSLionel Sambuc 483f4a2713aSLionel Sambuc CodeGenSubRegIndex *createSubRegIndex(StringRef Name, StringRef NameSpace); 484f4a2713aSLionel Sambuc 485f4a2713aSLionel Sambuc typedef std::map<SmallVector<CodeGenSubRegIndex*, 8>, 486f4a2713aSLionel Sambuc CodeGenSubRegIndex*> ConcatIdxMap; 487f4a2713aSLionel Sambuc ConcatIdxMap ConcatIdx; 488f4a2713aSLionel Sambuc 489f4a2713aSLionel Sambuc // Registers. 490*0a6a1f1dSLionel Sambuc std::deque<CodeGenRegister> Registers; 491f4a2713aSLionel Sambuc StringMap<CodeGenRegister*> RegistersByName; 492f4a2713aSLionel Sambuc DenseMap<Record*, CodeGenRegister*> Def2Reg; 493f4a2713aSLionel Sambuc unsigned NumNativeRegUnits; 494f4a2713aSLionel Sambuc 495f4a2713aSLionel Sambuc std::map<TopoSigId, unsigned> TopoSigs; 496f4a2713aSLionel Sambuc 497f4a2713aSLionel Sambuc // Includes native (0..NumNativeRegUnits-1) and adopted register units. 498f4a2713aSLionel Sambuc SmallVector<RegUnit, 8> RegUnits; 499f4a2713aSLionel Sambuc 500f4a2713aSLionel Sambuc // Register classes. 501*0a6a1f1dSLionel Sambuc std::list<CodeGenRegisterClass> RegClasses; 502f4a2713aSLionel Sambuc DenseMap<Record*, CodeGenRegisterClass*> Def2RC; 503f4a2713aSLionel Sambuc typedef std::map<CodeGenRegisterClass::Key, CodeGenRegisterClass*> RCKeyMap; 504f4a2713aSLionel Sambuc RCKeyMap Key2RC; 505f4a2713aSLionel Sambuc 506f4a2713aSLionel Sambuc // Remember each unique set of register units. Initially, this contains a 507f4a2713aSLionel Sambuc // unique set for each register class. Simliar sets are coalesced with 508f4a2713aSLionel Sambuc // pruneUnitSets and new supersets are inferred during computeRegUnitSets. 509f4a2713aSLionel Sambuc std::vector<RegUnitSet> RegUnitSets; 510f4a2713aSLionel Sambuc 511f4a2713aSLionel Sambuc // Map RegisterClass index to the index of the RegUnitSet that contains the 512f4a2713aSLionel Sambuc // class's units and any inferred RegUnit supersets. 513f4a2713aSLionel Sambuc // 514f4a2713aSLionel Sambuc // NOTE: This could grow beyond the number of register classes when we map 515f4a2713aSLionel Sambuc // register units to lists of unit sets. If the list of unit sets does not 516f4a2713aSLionel Sambuc // already exist for a register class, we create a new entry in this vector. 517f4a2713aSLionel Sambuc std::vector<std::vector<unsigned> > RegClassUnitSets; 518f4a2713aSLionel Sambuc 519f4a2713aSLionel Sambuc // Give each register unit set an order based on sorting criteria. 520f4a2713aSLionel Sambuc std::vector<unsigned> RegUnitSetOrder; 521f4a2713aSLionel Sambuc 522f4a2713aSLionel Sambuc // Add RC to *2RC maps. 523f4a2713aSLionel Sambuc void addToMaps(CodeGenRegisterClass*); 524f4a2713aSLionel Sambuc 525f4a2713aSLionel Sambuc // Create a synthetic sub-class if it is missing. 526f4a2713aSLionel Sambuc CodeGenRegisterClass *getOrCreateSubClass(const CodeGenRegisterClass *RC, 527f4a2713aSLionel Sambuc const CodeGenRegister::Set *Membs, 528f4a2713aSLionel Sambuc StringRef Name); 529f4a2713aSLionel Sambuc 530f4a2713aSLionel Sambuc // Infer missing register classes. 531f4a2713aSLionel Sambuc void computeInferredRegisterClasses(); 532f4a2713aSLionel Sambuc void inferCommonSubClass(CodeGenRegisterClass *RC); 533f4a2713aSLionel Sambuc void inferSubClassWithSubReg(CodeGenRegisterClass *RC); inferMatchingSuperRegClass(CodeGenRegisterClass * RC)534*0a6a1f1dSLionel Sambuc void inferMatchingSuperRegClass(CodeGenRegisterClass *RC) { 535*0a6a1f1dSLionel Sambuc inferMatchingSuperRegClass(RC, RegClasses.begin()); 536*0a6a1f1dSLionel Sambuc } 537*0a6a1f1dSLionel Sambuc 538*0a6a1f1dSLionel Sambuc void inferMatchingSuperRegClass( 539*0a6a1f1dSLionel Sambuc CodeGenRegisterClass *RC, 540*0a6a1f1dSLionel Sambuc std::list<CodeGenRegisterClass>::iterator FirstSubRegRC); 541f4a2713aSLionel Sambuc 542f4a2713aSLionel Sambuc // Iteratively prune unit sets. 543f4a2713aSLionel Sambuc void pruneUnitSets(); 544f4a2713aSLionel Sambuc 545f4a2713aSLionel Sambuc // Compute a weight for each register unit created during getSubRegs. 546f4a2713aSLionel Sambuc void computeRegUnitWeights(); 547f4a2713aSLionel Sambuc 548f4a2713aSLionel Sambuc // Create a RegUnitSet for each RegClass and infer superclasses. 549f4a2713aSLionel Sambuc void computeRegUnitSets(); 550f4a2713aSLionel Sambuc 551f4a2713aSLionel Sambuc // Populate the Composite map from sub-register relationships. 552f4a2713aSLionel Sambuc void computeComposites(); 553f4a2713aSLionel Sambuc 554f4a2713aSLionel Sambuc // Compute a lane mask for each sub-register index. 555*0a6a1f1dSLionel Sambuc void computeSubRegLaneMasks(); 556*0a6a1f1dSLionel Sambuc 557*0a6a1f1dSLionel Sambuc /// Computes a lane mask for each register unit enumerated by a physical 558*0a6a1f1dSLionel Sambuc /// register. 559*0a6a1f1dSLionel Sambuc void computeRegUnitLaneMasks(); 560f4a2713aSLionel Sambuc 561f4a2713aSLionel Sambuc public: 562f4a2713aSLionel Sambuc CodeGenRegBank(RecordKeeper&); 563f4a2713aSLionel Sambuc getSets()564f4a2713aSLionel Sambuc SetTheory &getSets() { return Sets; } 565f4a2713aSLionel Sambuc 566f4a2713aSLionel Sambuc // Sub-register indices. The first NumNamedIndices are defined by the user 567f4a2713aSLionel Sambuc // in the .td files. The rest are synthesized such that all sub-registers 568f4a2713aSLionel Sambuc // have a unique name. getSubRegIndices()569*0a6a1f1dSLionel Sambuc const std::deque<CodeGenSubRegIndex> &getSubRegIndices() const { 570*0a6a1f1dSLionel Sambuc return SubRegIndices; 571*0a6a1f1dSLionel Sambuc } 572f4a2713aSLionel Sambuc 573f4a2713aSLionel Sambuc // Find a SubRegIndex form its Record def. 574f4a2713aSLionel Sambuc CodeGenSubRegIndex *getSubRegIdx(Record*); 575f4a2713aSLionel Sambuc 576f4a2713aSLionel Sambuc // Find or create a sub-register index representing the A+B composition. 577f4a2713aSLionel Sambuc CodeGenSubRegIndex *getCompositeSubRegIndex(CodeGenSubRegIndex *A, 578f4a2713aSLionel Sambuc CodeGenSubRegIndex *B); 579f4a2713aSLionel Sambuc 580f4a2713aSLionel Sambuc // Find or create a sub-register index representing the concatenation of 581f4a2713aSLionel Sambuc // non-overlapping sibling indices. 582f4a2713aSLionel Sambuc CodeGenSubRegIndex * 583f4a2713aSLionel Sambuc getConcatSubRegIndex(const SmallVector<CodeGenSubRegIndex *, 8>&); 584f4a2713aSLionel Sambuc 585f4a2713aSLionel Sambuc void addConcatSubRegIndex(const SmallVector<CodeGenSubRegIndex *,8> & Parts,CodeGenSubRegIndex * Idx)586f4a2713aSLionel Sambuc addConcatSubRegIndex(const SmallVector<CodeGenSubRegIndex *, 8> &Parts, 587f4a2713aSLionel Sambuc CodeGenSubRegIndex *Idx) { 588f4a2713aSLionel Sambuc ConcatIdx.insert(std::make_pair(Parts, Idx)); 589f4a2713aSLionel Sambuc } 590f4a2713aSLionel Sambuc getRegisters()591*0a6a1f1dSLionel Sambuc const std::deque<CodeGenRegister> &getRegisters() { return Registers; } getRegistersByName()592f4a2713aSLionel Sambuc const StringMap<CodeGenRegister*> &getRegistersByName() { 593f4a2713aSLionel Sambuc return RegistersByName; 594f4a2713aSLionel Sambuc } 595f4a2713aSLionel Sambuc 596f4a2713aSLionel Sambuc // Find a register from its Record def. 597f4a2713aSLionel Sambuc CodeGenRegister *getReg(Record*); 598f4a2713aSLionel Sambuc 599f4a2713aSLionel Sambuc // Get a Register's index into the Registers array. getRegIndex(const CodeGenRegister * Reg)600f4a2713aSLionel Sambuc unsigned getRegIndex(const CodeGenRegister *Reg) const { 601f4a2713aSLionel Sambuc return Reg->EnumValue - 1; 602f4a2713aSLionel Sambuc } 603f4a2713aSLionel Sambuc 604f4a2713aSLionel Sambuc // Return the number of allocated TopoSigs. The first TopoSig representing 605f4a2713aSLionel Sambuc // leaf registers is allocated number 0. getNumTopoSigs()606f4a2713aSLionel Sambuc unsigned getNumTopoSigs() const { 607f4a2713aSLionel Sambuc return TopoSigs.size(); 608f4a2713aSLionel Sambuc } 609f4a2713aSLionel Sambuc 610f4a2713aSLionel Sambuc // Find or create a TopoSig for the given TopoSigId. 611f4a2713aSLionel Sambuc // This function is only for use by CodeGenRegister::computeSuperRegs(). 612f4a2713aSLionel Sambuc // Others should simply use Reg->getTopoSig(). getTopoSig(const TopoSigId & Id)613f4a2713aSLionel Sambuc unsigned getTopoSig(const TopoSigId &Id) { 614f4a2713aSLionel Sambuc return TopoSigs.insert(std::make_pair(Id, TopoSigs.size())).first->second; 615f4a2713aSLionel Sambuc } 616f4a2713aSLionel Sambuc 617f4a2713aSLionel Sambuc // Create a native register unit that is associated with one or two root 618f4a2713aSLionel Sambuc // registers. 619*0a6a1f1dSLionel Sambuc unsigned newRegUnit(CodeGenRegister *R0, CodeGenRegister *R1 = nullptr) { 620f4a2713aSLionel Sambuc RegUnits.resize(RegUnits.size() + 1); 621f4a2713aSLionel Sambuc RegUnits.back().Roots[0] = R0; 622f4a2713aSLionel Sambuc RegUnits.back().Roots[1] = R1; 623f4a2713aSLionel Sambuc return RegUnits.size() - 1; 624f4a2713aSLionel Sambuc } 625f4a2713aSLionel Sambuc 626f4a2713aSLionel Sambuc // Create a new non-native register unit that can be adopted by a register 627f4a2713aSLionel Sambuc // to increase its pressure. Note that NumNativeRegUnits is not increased. newRegUnit(unsigned Weight)628f4a2713aSLionel Sambuc unsigned newRegUnit(unsigned Weight) { 629f4a2713aSLionel Sambuc RegUnits.resize(RegUnits.size() + 1); 630f4a2713aSLionel Sambuc RegUnits.back().Weight = Weight; 631f4a2713aSLionel Sambuc return RegUnits.size() - 1; 632f4a2713aSLionel Sambuc } 633f4a2713aSLionel Sambuc 634f4a2713aSLionel Sambuc // Native units are the singular unit of a leaf register. Register aliasing 635f4a2713aSLionel Sambuc // is completely characterized by native units. Adopted units exist to give 636f4a2713aSLionel Sambuc // register additional weight but don't affect aliasing. isNativeUnit(unsigned RUID)637f4a2713aSLionel Sambuc bool isNativeUnit(unsigned RUID) { 638f4a2713aSLionel Sambuc return RUID < NumNativeRegUnits; 639f4a2713aSLionel Sambuc } 640f4a2713aSLionel Sambuc getNumNativeRegUnits()641f4a2713aSLionel Sambuc unsigned getNumNativeRegUnits() const { 642f4a2713aSLionel Sambuc return NumNativeRegUnits; 643f4a2713aSLionel Sambuc } 644f4a2713aSLionel Sambuc getRegUnit(unsigned RUID)645f4a2713aSLionel Sambuc RegUnit &getRegUnit(unsigned RUID) { return RegUnits[RUID]; } getRegUnit(unsigned RUID)646f4a2713aSLionel Sambuc const RegUnit &getRegUnit(unsigned RUID) const { return RegUnits[RUID]; } 647f4a2713aSLionel Sambuc getRegClasses()648*0a6a1f1dSLionel Sambuc std::list<CodeGenRegisterClass> &getRegClasses() { return RegClasses; } 649*0a6a1f1dSLionel Sambuc getRegClasses()650*0a6a1f1dSLionel Sambuc const std::list<CodeGenRegisterClass> &getRegClasses() const { 651f4a2713aSLionel Sambuc return RegClasses; 652f4a2713aSLionel Sambuc } 653f4a2713aSLionel Sambuc 654f4a2713aSLionel Sambuc // Find a register class from its def. 655f4a2713aSLionel Sambuc CodeGenRegisterClass *getRegClass(Record*); 656f4a2713aSLionel Sambuc 657f4a2713aSLionel Sambuc /// getRegisterClassForRegister - Find the register class that contains the 658f4a2713aSLionel Sambuc /// specified physical register. If the register is not in a register 659f4a2713aSLionel Sambuc /// class, return null. If the register is in multiple classes, and the 660f4a2713aSLionel Sambuc /// classes have a superset-subset relationship and the same set of types, 661f4a2713aSLionel Sambuc /// return the superclass. Otherwise return null. 662f4a2713aSLionel Sambuc const CodeGenRegisterClass* getRegClassForRegister(Record *R); 663f4a2713aSLionel Sambuc 664f4a2713aSLionel Sambuc // Get the sum of unit weights. getRegUnitSetWeight(const std::vector<unsigned> & Units)665f4a2713aSLionel Sambuc unsigned getRegUnitSetWeight(const std::vector<unsigned> &Units) const { 666f4a2713aSLionel Sambuc unsigned Weight = 0; 667f4a2713aSLionel Sambuc for (std::vector<unsigned>::const_iterator 668f4a2713aSLionel Sambuc I = Units.begin(), E = Units.end(); I != E; ++I) 669f4a2713aSLionel Sambuc Weight += getRegUnit(*I).Weight; 670f4a2713aSLionel Sambuc return Weight; 671f4a2713aSLionel Sambuc } 672f4a2713aSLionel Sambuc getRegSetIDAt(unsigned Order)673f4a2713aSLionel Sambuc unsigned getRegSetIDAt(unsigned Order) const { 674f4a2713aSLionel Sambuc return RegUnitSetOrder[Order]; 675f4a2713aSLionel Sambuc } getRegSetAt(unsigned Order)676f4a2713aSLionel Sambuc const RegUnitSet &getRegSetAt(unsigned Order) const { 677f4a2713aSLionel Sambuc return RegUnitSets[RegUnitSetOrder[Order]]; 678f4a2713aSLionel Sambuc } 679f4a2713aSLionel Sambuc 680f4a2713aSLionel Sambuc // Increase a RegUnitWeight. increaseRegUnitWeight(unsigned RUID,unsigned Inc)681f4a2713aSLionel Sambuc void increaseRegUnitWeight(unsigned RUID, unsigned Inc) { 682f4a2713aSLionel Sambuc getRegUnit(RUID).Weight += Inc; 683f4a2713aSLionel Sambuc } 684f4a2713aSLionel Sambuc 685f4a2713aSLionel Sambuc // Get the number of register pressure dimensions. getNumRegPressureSets()686f4a2713aSLionel Sambuc unsigned getNumRegPressureSets() const { return RegUnitSets.size(); } 687f4a2713aSLionel Sambuc 688f4a2713aSLionel Sambuc // Get a set of register unit IDs for a given dimension of pressure. getRegPressureSet(unsigned Idx)689f4a2713aSLionel Sambuc const RegUnitSet &getRegPressureSet(unsigned Idx) const { 690f4a2713aSLionel Sambuc return RegUnitSets[Idx]; 691f4a2713aSLionel Sambuc } 692f4a2713aSLionel Sambuc 693f4a2713aSLionel Sambuc // The number of pressure set lists may be larget than the number of 694f4a2713aSLionel Sambuc // register classes if some register units appeared in a list of sets that 695f4a2713aSLionel Sambuc // did not correspond to an existing register class. getNumRegClassPressureSetLists()696f4a2713aSLionel Sambuc unsigned getNumRegClassPressureSetLists() const { 697f4a2713aSLionel Sambuc return RegClassUnitSets.size(); 698f4a2713aSLionel Sambuc } 699f4a2713aSLionel Sambuc 700f4a2713aSLionel Sambuc // Get a list of pressure set IDs for a register class. Liveness of a 701f4a2713aSLionel Sambuc // register in this class impacts each pressure set in this list by the 702f4a2713aSLionel Sambuc // weight of the register. An exact solution requires all registers in a 703f4a2713aSLionel Sambuc // class to have the same class, but it is not strictly guaranteed. getRCPressureSetIDs(unsigned RCIdx)704f4a2713aSLionel Sambuc ArrayRef<unsigned> getRCPressureSetIDs(unsigned RCIdx) const { 705f4a2713aSLionel Sambuc return RegClassUnitSets[RCIdx]; 706f4a2713aSLionel Sambuc } 707f4a2713aSLionel Sambuc 708f4a2713aSLionel Sambuc // Computed derived records such as missing sub-register indices. 709f4a2713aSLionel Sambuc void computeDerivedInfo(); 710f4a2713aSLionel Sambuc 711f4a2713aSLionel Sambuc // Compute the set of registers completely covered by the registers in Regs. 712f4a2713aSLionel Sambuc // The returned BitVector will have a bit set for each register in Regs, 713f4a2713aSLionel Sambuc // all sub-registers, and all super-registers that are covered by the 714f4a2713aSLionel Sambuc // registers in Regs. 715f4a2713aSLionel Sambuc // 716f4a2713aSLionel Sambuc // This is used to compute the mask of call-preserved registers from a list 717f4a2713aSLionel Sambuc // of callee-saves. 718f4a2713aSLionel Sambuc BitVector computeCoveredRegisters(ArrayRef<Record*> Regs); 719f4a2713aSLionel Sambuc 720f4a2713aSLionel Sambuc // Bit mask of lanes that cover their registers. A sub-register index whose 721f4a2713aSLionel Sambuc // LaneMask is contained in CoveringLanes will be completely covered by 722f4a2713aSLionel Sambuc // another sub-register with the same or larger lane mask. 723f4a2713aSLionel Sambuc unsigned CoveringLanes; 724f4a2713aSLionel Sambuc }; 725f4a2713aSLionel Sambuc } 726f4a2713aSLionel Sambuc 727f4a2713aSLionel Sambuc #endif 728