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