1 //==- CodeGen/TargetRegisterInfo.h - Target Register Information -*- C++ -*-==//
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 // This file describes an abstract interface used to get information about a
10 // target machines register file.  This information is used for a variety of
11 // purposed, especially register allocation.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_TARGETREGISTERINFO_H
16 #define LLVM_CODEGEN_TARGETREGISTERINFO_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/iterator_range.h"
22 #include "llvm/CodeGen/MachineBasicBlock.h"
23 #include "llvm/IR/CallingConv.h"
24 #include "llvm/MC/LaneBitmask.h"
25 #include "llvm/MC/MCRegisterInfo.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/MachineValueType.h"
28 #include "llvm/Support/MathExtras.h"
29 #include "llvm/Support/Printable.h"
30 #include <cassert>
31 #include <cstdint>
32 #include <functional>
33 
34 namespace llvm {
35 
36 class BitVector;
37 class LiveRegMatrix;
38 class MachineFunction;
39 class MachineInstr;
40 class RegScavenger;
41 class VirtRegMap;
42 class LiveIntervals;
43 class LiveInterval;
44 
45 class TargetRegisterClass {
46 public:
47   using iterator = const MCPhysReg *;
48   using const_iterator = const MCPhysReg *;
49   using sc_iterator = const TargetRegisterClass* const *;
50 
51   // Instance variables filled by tablegen, do not use!
52   const MCRegisterClass *MC;
53   const uint32_t *SubClassMask;
54   const uint16_t *SuperRegIndices;
55   const LaneBitmask LaneMask;
56   /// Classes with a higher priority value are assigned first by register
57   /// allocators using a greedy heuristic. The value is in the range [0,63].
58   const uint8_t AllocationPriority;
59   /// Whether the class supports two (or more) disjunct subregister indices.
60   const bool HasDisjunctSubRegs;
61   /// Whether a combination of subregisters can cover every register in the
62   /// class. See also the CoveredBySubRegs description in Target.td.
63   const bool CoveredBySubRegs;
64   const sc_iterator SuperClasses;
65   ArrayRef<MCPhysReg> (*OrderFunc)(const MachineFunction&);
66 
67   /// Return the register class ID number.
68   unsigned getID() const { return MC->getID(); }
69 
70   /// begin/end - Return all of the registers in this class.
71   ///
72   iterator       begin() const { return MC->begin(); }
73   iterator         end() const { return MC->end(); }
74 
75   /// Return the number of registers in this class.
76   unsigned getNumRegs() const { return MC->getNumRegs(); }
77 
78   iterator_range<SmallVectorImpl<MCPhysReg>::const_iterator>
79   getRegisters() const {
80     return make_range(MC->begin(), MC->end());
81   }
82 
83   /// Return the specified register in the class.
84   MCRegister getRegister(unsigned i) const {
85     return MC->getRegister(i);
86   }
87 
88   /// Return true if the specified register is included in this register class.
89   /// This does not include virtual registers.
90   bool contains(unsigned Reg) const {
91     /// FIXME: Historically this function has returned false when given vregs
92     ///        but it should probably only receive physical registers
93     if (!Register::isPhysicalRegister(Reg))
94       return false;
95     return MC->contains(Reg);
96   }
97 
98   /// Return true if both registers are in this class.
99   bool contains(unsigned Reg1, unsigned Reg2) const {
100     /// FIXME: Historically this function has returned false when given a vregs
101     ///        but it should probably only receive physical registers
102     if (!Register::isPhysicalRegister(Reg1) ||
103         !Register::isPhysicalRegister(Reg2))
104       return false;
105     return MC->contains(Reg1, Reg2);
106   }
107 
108   /// Return the cost of copying a value between two registers in this class.
109   /// A negative number means the register class is very expensive
110   /// to copy e.g. status flag register classes.
111   int getCopyCost() const { return MC->getCopyCost(); }
112 
113   /// Return true if this register class may be used to create virtual
114   /// registers.
115   bool isAllocatable() const { return MC->isAllocatable(); }
116 
117   /// Return true if the specified TargetRegisterClass
118   /// is a proper sub-class of this TargetRegisterClass.
119   bool hasSubClass(const TargetRegisterClass *RC) const {
120     return RC != this && hasSubClassEq(RC);
121   }
122 
123   /// Returns true if RC is a sub-class of or equal to this class.
124   bool hasSubClassEq(const TargetRegisterClass *RC) const {
125     unsigned ID = RC->getID();
126     return (SubClassMask[ID / 32] >> (ID % 32)) & 1;
127   }
128 
129   /// Return true if the specified TargetRegisterClass is a
130   /// proper super-class of this TargetRegisterClass.
131   bool hasSuperClass(const TargetRegisterClass *RC) const {
132     return RC->hasSubClass(this);
133   }
134 
135   /// Returns true if RC is a super-class of or equal to this class.
136   bool hasSuperClassEq(const TargetRegisterClass *RC) const {
137     return RC->hasSubClassEq(this);
138   }
139 
140   /// Returns a bit vector of subclasses, including this one.
141   /// The vector is indexed by class IDs.
142   ///
143   /// To use it, consider the returned array as a chunk of memory that
144   /// contains an array of bits of size NumRegClasses. Each 32-bit chunk
145   /// contains a bitset of the ID of the subclasses in big-endian style.
146 
147   /// I.e., the representation of the memory from left to right at the
148   /// bit level looks like:
149   /// [31 30 ... 1 0] [ 63 62 ... 33 32] ...
150   ///                     [ XXX NumRegClasses NumRegClasses - 1 ... ]
151   /// Where the number represents the class ID and XXX bits that
152   /// should be ignored.
153   ///
154   /// See the implementation of hasSubClassEq for an example of how it
155   /// can be used.
156   const uint32_t *getSubClassMask() const {
157     return SubClassMask;
158   }
159 
160   /// Returns a 0-terminated list of sub-register indices that project some
161   /// super-register class into this register class. The list has an entry for
162   /// each Idx such that:
163   ///
164   ///   There exists SuperRC where:
165   ///     For all Reg in SuperRC:
166   ///       this->contains(Reg:Idx)
167   const uint16_t *getSuperRegIndices() const {
168     return SuperRegIndices;
169   }
170 
171   /// Returns a NULL-terminated list of super-classes.  The
172   /// classes are ordered by ID which is also a topological ordering from large
173   /// to small classes.  The list does NOT include the current class.
174   sc_iterator getSuperClasses() const {
175     return SuperClasses;
176   }
177 
178   /// Return true if this TargetRegisterClass is a subset
179   /// class of at least one other TargetRegisterClass.
180   bool isASubClass() const {
181     return SuperClasses[0] != nullptr;
182   }
183 
184   /// Returns the preferred order for allocating registers from this register
185   /// class in MF. The raw order comes directly from the .td file and may
186   /// include reserved registers that are not allocatable.
187   /// Register allocators should also make sure to allocate
188   /// callee-saved registers only after all the volatiles are used. The
189   /// RegisterClassInfo class provides filtered allocation orders with
190   /// callee-saved registers moved to the end.
191   ///
192   /// The MachineFunction argument can be used to tune the allocatable
193   /// registers based on the characteristics of the function, subtarget, or
194   /// other criteria.
195   ///
196   /// By default, this method returns all registers in the class.
197   ArrayRef<MCPhysReg> getRawAllocationOrder(const MachineFunction &MF) const {
198     return OrderFunc ? OrderFunc(MF) : makeArrayRef(begin(), getNumRegs());
199   }
200 
201   /// Returns the combination of all lane masks of register in this class.
202   /// The lane masks of the registers are the combination of all lane masks
203   /// of their subregisters. Returns 1 if there are no subregisters.
204   LaneBitmask getLaneMask() const {
205     return LaneMask;
206   }
207 };
208 
209 /// Extra information, not in MCRegisterDesc, about registers.
210 /// These are used by codegen, not by MC.
211 struct TargetRegisterInfoDesc {
212   unsigned CostPerUse;          // Extra cost of instructions using register.
213   bool inAllocatableClass;      // Register belongs to an allocatable regclass.
214 };
215 
216 /// Each TargetRegisterClass has a per register weight, and weight
217 /// limit which must be less than the limits of its pressure sets.
218 struct RegClassWeight {
219   unsigned RegWeight;
220   unsigned WeightLimit;
221 };
222 
223 /// TargetRegisterInfo base class - We assume that the target defines a static
224 /// array of TargetRegisterDesc objects that represent all of the machine
225 /// registers that the target has.  As such, we simply have to track a pointer
226 /// to this array so that we can turn register number into a register
227 /// descriptor.
228 ///
229 class TargetRegisterInfo : public MCRegisterInfo {
230 public:
231   using regclass_iterator = const TargetRegisterClass * const *;
232   using vt_iterator = const MVT::SimpleValueType *;
233   struct RegClassInfo {
234     unsigned RegSize, SpillSize, SpillAlignment;
235     vt_iterator VTList;
236   };
237 private:
238   const TargetRegisterInfoDesc *InfoDesc;     // Extra desc array for codegen
239   const char *const *SubRegIndexNames;        // Names of subreg indexes.
240   // Pointer to array of lane masks, one per sub-reg index.
241   const LaneBitmask *SubRegIndexLaneMasks;
242 
243   regclass_iterator RegClassBegin, RegClassEnd;   // List of regclasses
244   LaneBitmask CoveringLanes;
245   const RegClassInfo *const RCInfos;
246   unsigned HwMode;
247 
248 protected:
249   TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
250                      regclass_iterator RCB,
251                      regclass_iterator RCE,
252                      const char *const *SRINames,
253                      const LaneBitmask *SRILaneMasks,
254                      LaneBitmask CoveringLanes,
255                      const RegClassInfo *const RCIs,
256                      unsigned Mode = 0);
257   virtual ~TargetRegisterInfo();
258 
259 public:
260   // Register numbers can represent physical registers, virtual registers, and
261   // sometimes stack slots. The unsigned values are divided into these ranges:
262   //
263   //   0           Not a register, can be used as a sentinel.
264   //   [1;2^30)    Physical registers assigned by TableGen.
265   //   [2^30;2^31) Stack slots. (Rarely used.)
266   //   [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
267   //
268   // Further sentinels can be allocated from the small negative integers.
269   // DenseMapInfo<unsigned> uses -1u and -2u.
270 
271   /// Return the size in bits of a register from class RC.
272   unsigned getRegSizeInBits(const TargetRegisterClass &RC) const {
273     return getRegClassInfo(RC).RegSize;
274   }
275 
276   /// Return the size in bytes of the stack slot allocated to hold a spilled
277   /// copy of a register from class RC.
278   unsigned getSpillSize(const TargetRegisterClass &RC) const {
279     return getRegClassInfo(RC).SpillSize / 8;
280   }
281 
282   /// Return the minimum required alignment in bytes for a spill slot for
283   /// a register of this class.
284   unsigned getSpillAlignment(const TargetRegisterClass &RC) const {
285     return getRegClassInfo(RC).SpillAlignment / 8;
286   }
287 
288   /// Return the minimum required alignment in bytes for a spill slot for
289   /// a register of this class.
290   Align getSpillAlign(const TargetRegisterClass &RC) const {
291     return Align(getRegClassInfo(RC).SpillAlignment / 8);
292   }
293 
294   /// Return true if the given TargetRegisterClass has the ValueType T.
295   bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const {
296     for (auto I = legalclasstypes_begin(RC); *I != MVT::Other; ++I)
297       if (MVT(*I) == T)
298         return true;
299     return false;
300   }
301 
302   /// Loop over all of the value types that can be represented by values
303   /// in the given register class.
304   vt_iterator legalclasstypes_begin(const TargetRegisterClass &RC) const {
305     return getRegClassInfo(RC).VTList;
306   }
307 
308   vt_iterator legalclasstypes_end(const TargetRegisterClass &RC) const {
309     vt_iterator I = legalclasstypes_begin(RC);
310     while (*I != MVT::Other)
311       ++I;
312     return I;
313   }
314 
315   /// Returns the Register Class of a physical register of the given type,
316   /// picking the most sub register class of the right type that contains this
317   /// physreg.
318   const TargetRegisterClass *getMinimalPhysRegClass(MCRegister Reg,
319                                                     MVT VT = MVT::Other) const;
320 
321   /// Return the maximal subclass of the given register class that is
322   /// allocatable or NULL.
323   const TargetRegisterClass *
324     getAllocatableClass(const TargetRegisterClass *RC) const;
325 
326   /// Returns a bitset indexed by register number indicating if a register is
327   /// allocatable or not. If a register class is specified, returns the subset
328   /// for the class.
329   BitVector getAllocatableSet(const MachineFunction &MF,
330                               const TargetRegisterClass *RC = nullptr) const;
331 
332   /// Return the additional cost of using this register instead
333   /// of other registers in its class.
334   unsigned getCostPerUse(MCRegister RegNo) const {
335     return InfoDesc[RegNo].CostPerUse;
336   }
337 
338   /// Return true if the register is in the allocation of any register class.
339   bool isInAllocatableClass(MCRegister RegNo) const {
340     return InfoDesc[RegNo].inAllocatableClass;
341   }
342 
343   /// Return the human-readable symbolic target-specific
344   /// name for the specified SubRegIndex.
345   const char *getSubRegIndexName(unsigned SubIdx) const {
346     assert(SubIdx && SubIdx < getNumSubRegIndices() &&
347            "This is not a subregister index");
348     return SubRegIndexNames[SubIdx-1];
349   }
350 
351   /// Return a bitmask representing the parts of a register that are covered by
352   /// SubIdx \see LaneBitmask.
353   ///
354   /// SubIdx == 0 is allowed, it has the lane mask ~0u.
355   LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const {
356     assert(SubIdx < getNumSubRegIndices() && "This is not a subregister index");
357     return SubRegIndexLaneMasks[SubIdx];
358   }
359 
360   /// The lane masks returned by getSubRegIndexLaneMask() above can only be
361   /// used to determine if sub-registers overlap - they can't be used to
362   /// determine if a set of sub-registers completely cover another
363   /// sub-register.
364   ///
365   /// The X86 general purpose registers have two lanes corresponding to the
366   /// sub_8bit and sub_8bit_hi sub-registers. Both sub_32bit and sub_16bit have
367   /// lane masks '3', but the sub_16bit sub-register doesn't fully cover the
368   /// sub_32bit sub-register.
369   ///
370   /// On the other hand, the ARM NEON lanes fully cover their registers: The
371   /// dsub_0 sub-register is completely covered by the ssub_0 and ssub_1 lanes.
372   /// This is related to the CoveredBySubRegs property on register definitions.
373   ///
374   /// This function returns a bit mask of lanes that completely cover their
375   /// sub-registers. More precisely, given:
376   ///
377   ///   Covering = getCoveringLanes();
378   ///   MaskA = getSubRegIndexLaneMask(SubA);
379   ///   MaskB = getSubRegIndexLaneMask(SubB);
380   ///
381   /// If (MaskA & ~(MaskB & Covering)) == 0, then SubA is completely covered by
382   /// SubB.
383   LaneBitmask getCoveringLanes() const { return CoveringLanes; }
384 
385   /// Returns true if the two registers are equal or alias each other.
386   /// The registers may be virtual registers.
387   bool regsOverlap(Register regA, Register regB) const {
388     if (regA == regB) return true;
389     if (regA.isVirtual() || regB.isVirtual())
390       return false;
391 
392     // Regunits are numerically ordered. Find a common unit.
393     MCRegUnitIterator RUA(regA, this);
394     MCRegUnitIterator RUB(regB, this);
395     do {
396       if (*RUA == *RUB) return true;
397       if (*RUA < *RUB) ++RUA;
398       else             ++RUB;
399     } while (RUA.isValid() && RUB.isValid());
400     return false;
401   }
402 
403   /// Returns true if Reg contains RegUnit.
404   bool hasRegUnit(MCRegister Reg, unsigned RegUnit) const {
405     for (MCRegUnitIterator Units(Reg, this); Units.isValid(); ++Units)
406       if (*Units == RegUnit)
407         return true;
408     return false;
409   }
410 
411   /// Returns the original SrcReg unless it is the target of a copy-like
412   /// operation, in which case we chain backwards through all such operations
413   /// to the ultimate source register.  If a physical register is encountered,
414   /// we stop the search.
415   virtual Register lookThruCopyLike(Register SrcReg,
416                                     const MachineRegisterInfo *MRI) const;
417 
418   /// Return a null-terminated list of all of the callee-saved registers on
419   /// this target. The register should be in the order of desired callee-save
420   /// stack frame offset. The first register is closest to the incoming stack
421   /// pointer if stack grows down, and vice versa.
422   /// Notice: This function does not take into account disabled CSRs.
423   ///         In most cases you will want to use instead the function
424   ///         getCalleeSavedRegs that is implemented in MachineRegisterInfo.
425   virtual const MCPhysReg*
426   getCalleeSavedRegs(const MachineFunction *MF) const = 0;
427 
428   /// Return a mask of call-preserved registers for the given calling convention
429   /// on the current function. The mask should include all call-preserved
430   /// aliases. This is used by the register allocator to determine which
431   /// registers can be live across a call.
432   ///
433   /// The mask is an array containing (TRI::getNumRegs()+31)/32 entries.
434   /// A set bit indicates that all bits of the corresponding register are
435   /// preserved across the function call.  The bit mask is expected to be
436   /// sub-register complete, i.e. if A is preserved, so are all its
437   /// sub-registers.
438   ///
439   /// Bits are numbered from the LSB, so the bit for physical register Reg can
440   /// be found as (Mask[Reg / 32] >> Reg % 32) & 1.
441   ///
442   /// A NULL pointer means that no register mask will be used, and call
443   /// instructions should use implicit-def operands to indicate call clobbered
444   /// registers.
445   ///
446   virtual const uint32_t *getCallPreservedMask(const MachineFunction &MF,
447                                                CallingConv::ID) const {
448     // The default mask clobbers everything.  All targets should override.
449     return nullptr;
450   }
451 
452   /// Return a register mask that clobbers everything.
453   virtual const uint32_t *getNoPreservedMask() const {
454     llvm_unreachable("target does not provide no preserved mask");
455   }
456 
457   /// Return a list of all of the registers which are clobbered "inside" a call
458   /// to the given function. For example, these might be needed for PLT
459   /// sequences of long-branch veneers.
460   virtual ArrayRef<MCPhysReg>
461   getIntraCallClobberedRegs(const MachineFunction *MF) const {
462     return {};
463   }
464 
465   /// Return true if all bits that are set in mask \p mask0 are also set in
466   /// \p mask1.
467   bool regmaskSubsetEqual(const uint32_t *mask0, const uint32_t *mask1) const;
468 
469   /// Return all the call-preserved register masks defined for this target.
470   virtual ArrayRef<const uint32_t *> getRegMasks() const = 0;
471   virtual ArrayRef<const char *> getRegMaskNames() const = 0;
472 
473   /// Returns a bitset indexed by physical register number indicating if a
474   /// register is a special register that has particular uses and should be
475   /// considered unavailable at all times, e.g. stack pointer, return address.
476   /// A reserved register:
477   /// - is not allocatable
478   /// - is considered always live
479   /// - is ignored by liveness tracking
480   /// It is often necessary to reserve the super registers of a reserved
481   /// register as well, to avoid them getting allocated indirectly. You may use
482   /// markSuperRegs() and checkAllSuperRegsMarked() in this case.
483   virtual BitVector getReservedRegs(const MachineFunction &MF) const = 0;
484 
485   /// Returns false if we can't guarantee that Physreg, specified as an IR asm
486   /// clobber constraint, will be preserved across the statement.
487   virtual bool isAsmClobberable(const MachineFunction &MF,
488                                 MCRegister PhysReg) const {
489     return true;
490   }
491 
492   /// Returns true if PhysReg cannot be written to in inline asm statements.
493   virtual bool isInlineAsmReadOnlyReg(const MachineFunction &MF,
494                                       unsigned PhysReg) const {
495     return false;
496   }
497 
498   /// Returns true if PhysReg is unallocatable and constant throughout the
499   /// function.  Used by MachineRegisterInfo::isConstantPhysReg().
500   virtual bool isConstantPhysReg(MCRegister PhysReg) const { return false; }
501 
502   /// Returns true if the register class is considered divergent.
503   virtual bool isDivergentRegClass(const TargetRegisterClass *RC) const {
504     return false;
505   }
506 
507   /// Physical registers that may be modified within a function but are
508   /// guaranteed to be restored before any uses. This is useful for targets that
509   /// have call sequences where a GOT register may be updated by the caller
510   /// prior to a call and is guaranteed to be restored (also by the caller)
511   /// after the call.
512   virtual bool isCallerPreservedPhysReg(MCRegister PhysReg,
513                                         const MachineFunction &MF) const {
514     return false;
515   }
516 
517   /// This is a wrapper around getCallPreservedMask().
518   /// Return true if the register is preserved after the call.
519   virtual bool isCalleeSavedPhysReg(MCRegister PhysReg,
520                                     const MachineFunction &MF) const;
521 
522   /// Prior to adding the live-out mask to a stackmap or patchpoint
523   /// instruction, provide the target the opportunity to adjust it (mainly to
524   /// remove pseudo-registers that should be ignored).
525   virtual void adjustStackMapLiveOutMask(uint32_t *Mask) const {}
526 
527   /// Return a super-register of the specified register
528   /// Reg so its sub-register of index SubIdx is Reg.
529   MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx,
530                                  const TargetRegisterClass *RC) const {
531     return MCRegisterInfo::getMatchingSuperReg(Reg, SubIdx, RC->MC);
532   }
533 
534   /// Return a subclass of the specified register
535   /// class A so that each register in it has a sub-register of the
536   /// specified sub-register index which is in the specified register class B.
537   ///
538   /// TableGen will synthesize missing A sub-classes.
539   virtual const TargetRegisterClass *
540   getMatchingSuperRegClass(const TargetRegisterClass *A,
541                            const TargetRegisterClass *B, unsigned Idx) const;
542 
543   // For a copy-like instruction that defines a register of class DefRC with
544   // subreg index DefSubReg, reading from another source with class SrcRC and
545   // subregister SrcSubReg return true if this is a preferable copy
546   // instruction or an earlier use should be used.
547   virtual bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
548                                     unsigned DefSubReg,
549                                     const TargetRegisterClass *SrcRC,
550                                     unsigned SrcSubReg) const;
551 
552   /// Returns the largest legal sub-class of RC that
553   /// supports the sub-register index Idx.
554   /// If no such sub-class exists, return NULL.
555   /// If all registers in RC already have an Idx sub-register, return RC.
556   ///
557   /// TableGen generates a version of this function that is good enough in most
558   /// cases.  Targets can override if they have constraints that TableGen
559   /// doesn't understand.  For example, the x86 sub_8bit sub-register index is
560   /// supported by the full GR32 register class in 64-bit mode, but only by the
561   /// GR32_ABCD regiister class in 32-bit mode.
562   ///
563   /// TableGen will synthesize missing RC sub-classes.
564   virtual const TargetRegisterClass *
565   getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const {
566     assert(Idx == 0 && "Target has no sub-registers");
567     return RC;
568   }
569 
570   /// Return the subregister index you get from composing
571   /// two subregister indices.
572   ///
573   /// The special null sub-register index composes as the identity.
574   ///
575   /// If R:a:b is the same register as R:c, then composeSubRegIndices(a, b)
576   /// returns c. Note that composeSubRegIndices does not tell you about illegal
577   /// compositions. If R does not have a subreg a, or R:a does not have a subreg
578   /// b, composeSubRegIndices doesn't tell you.
579   ///
580   /// The ARM register Q0 has two D subregs dsub_0:D0 and dsub_1:D1. It also has
581   /// ssub_0:S0 - ssub_3:S3 subregs.
582   /// If you compose subreg indices dsub_1, ssub_0 you get ssub_2.
583   unsigned composeSubRegIndices(unsigned a, unsigned b) const {
584     if (!a) return b;
585     if (!b) return a;
586     return composeSubRegIndicesImpl(a, b);
587   }
588 
589   /// Transforms a LaneMask computed for one subregister to the lanemask that
590   /// would have been computed when composing the subsubregisters with IdxA
591   /// first. @sa composeSubRegIndices()
592   LaneBitmask composeSubRegIndexLaneMask(unsigned IdxA,
593                                          LaneBitmask Mask) const {
594     if (!IdxA)
595       return Mask;
596     return composeSubRegIndexLaneMaskImpl(IdxA, Mask);
597   }
598 
599   /// Transform a lanemask given for a virtual register to the corresponding
600   /// lanemask before using subregister with index \p IdxA.
601   /// This is the reverse of composeSubRegIndexLaneMask(), assuming Mask is a
602   /// valie lane mask (no invalid bits set) the following holds:
603   /// X0 = composeSubRegIndexLaneMask(Idx, Mask)
604   /// X1 = reverseComposeSubRegIndexLaneMask(Idx, X0)
605   /// => X1 == Mask
606   LaneBitmask reverseComposeSubRegIndexLaneMask(unsigned IdxA,
607                                                 LaneBitmask LaneMask) const {
608     if (!IdxA)
609       return LaneMask;
610     return reverseComposeSubRegIndexLaneMaskImpl(IdxA, LaneMask);
611   }
612 
613   /// Debugging helper: dump register in human readable form to dbgs() stream.
614   static void dumpReg(Register Reg, unsigned SubRegIndex = 0,
615                       const TargetRegisterInfo *TRI = nullptr);
616 
617 protected:
618   /// Overridden by TableGen in targets that have sub-registers.
619   virtual unsigned composeSubRegIndicesImpl(unsigned, unsigned) const {
620     llvm_unreachable("Target has no sub-registers");
621   }
622 
623   /// Overridden by TableGen in targets that have sub-registers.
624   virtual LaneBitmask
625   composeSubRegIndexLaneMaskImpl(unsigned, LaneBitmask) const {
626     llvm_unreachable("Target has no sub-registers");
627   }
628 
629   virtual LaneBitmask reverseComposeSubRegIndexLaneMaskImpl(unsigned,
630                                                             LaneBitmask) const {
631     llvm_unreachable("Target has no sub-registers");
632   }
633 
634 public:
635   /// Find a common super-register class if it exists.
636   ///
637   /// Find a register class, SuperRC and two sub-register indices, PreA and
638   /// PreB, such that:
639   ///
640   ///   1. PreA + SubA == PreB + SubB  (using composeSubRegIndices()), and
641   ///
642   ///   2. For all Reg in SuperRC: Reg:PreA in RCA and Reg:PreB in RCB, and
643   ///
644   ///   3. SuperRC->getSize() >= max(RCA->getSize(), RCB->getSize()).
645   ///
646   /// SuperRC will be chosen such that no super-class of SuperRC satisfies the
647   /// requirements, and there is no register class with a smaller spill size
648   /// that satisfies the requirements.
649   ///
650   /// SubA and SubB must not be 0. Use getMatchingSuperRegClass() instead.
651   ///
652   /// Either of the PreA and PreB sub-register indices may be returned as 0. In
653   /// that case, the returned register class will be a sub-class of the
654   /// corresponding argument register class.
655   ///
656   /// The function returns NULL if no register class can be found.
657   const TargetRegisterClass*
658   getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
659                          const TargetRegisterClass *RCB, unsigned SubB,
660                          unsigned &PreA, unsigned &PreB) const;
661 
662   //===--------------------------------------------------------------------===//
663   // Register Class Information
664   //
665 protected:
666   const RegClassInfo &getRegClassInfo(const TargetRegisterClass &RC) const {
667     return RCInfos[getNumRegClasses() * HwMode + RC.getID()];
668   }
669 
670 public:
671   /// Register class iterators
672   regclass_iterator regclass_begin() const { return RegClassBegin; }
673   regclass_iterator regclass_end() const { return RegClassEnd; }
674   iterator_range<regclass_iterator> regclasses() const {
675     return make_range(regclass_begin(), regclass_end());
676   }
677 
678   unsigned getNumRegClasses() const {
679     return (unsigned)(regclass_end()-regclass_begin());
680   }
681 
682   /// Returns the register class associated with the enumeration value.
683   /// See class MCOperandInfo.
684   const TargetRegisterClass *getRegClass(unsigned i) const {
685     assert(i < getNumRegClasses() && "Register Class ID out of range");
686     return RegClassBegin[i];
687   }
688 
689   /// Returns the name of the register class.
690   const char *getRegClassName(const TargetRegisterClass *Class) const {
691     return MCRegisterInfo::getRegClassName(Class->MC);
692   }
693 
694   /// Find the largest common subclass of A and B.
695   /// Return NULL if there is no common subclass.
696   const TargetRegisterClass *
697   getCommonSubClass(const TargetRegisterClass *A,
698                     const TargetRegisterClass *B) const;
699 
700   /// Returns a TargetRegisterClass used for pointer values.
701   /// If a target supports multiple different pointer register classes,
702   /// kind specifies which one is indicated.
703   virtual const TargetRegisterClass *
704   getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const {
705     llvm_unreachable("Target didn't implement getPointerRegClass!");
706   }
707 
708   /// Returns a legal register class to copy a register in the specified class
709   /// to or from. If it is possible to copy the register directly without using
710   /// a cross register class copy, return the specified RC. Returns NULL if it
711   /// is not possible to copy between two registers of the specified class.
712   virtual const TargetRegisterClass *
713   getCrossCopyRegClass(const TargetRegisterClass *RC) const {
714     return RC;
715   }
716 
717   /// Returns the largest super class of RC that is legal to use in the current
718   /// sub-target and has the same spill size.
719   /// The returned register class can be used to create virtual registers which
720   /// means that all its registers can be copied and spilled.
721   virtual const TargetRegisterClass *
722   getLargestLegalSuperClass(const TargetRegisterClass *RC,
723                             const MachineFunction &) const {
724     /// The default implementation is very conservative and doesn't allow the
725     /// register allocator to inflate register classes.
726     return RC;
727   }
728 
729   /// Return the register pressure "high water mark" for the specific register
730   /// class. The scheduler is in high register pressure mode (for the specific
731   /// register class) if it goes over the limit.
732   ///
733   /// Note: this is the old register pressure model that relies on a manually
734   /// specified representative register class per value type.
735   virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC,
736                                        MachineFunction &MF) const {
737     return 0;
738   }
739 
740   /// Return a heuristic for the machine scheduler to compare the profitability
741   /// of increasing one register pressure set versus another.  The scheduler
742   /// will prefer increasing the register pressure of the set which returns
743   /// the largest value for this function.
744   virtual unsigned getRegPressureSetScore(const MachineFunction &MF,
745                                           unsigned PSetID) const {
746     return PSetID;
747   }
748 
749   /// Get the weight in units of pressure for this register class.
750   virtual const RegClassWeight &getRegClassWeight(
751     const TargetRegisterClass *RC) const = 0;
752 
753   /// Returns size in bits of a phys/virtual/generic register.
754   unsigned getRegSizeInBits(Register Reg, const MachineRegisterInfo &MRI) const;
755 
756   /// Get the weight in units of pressure for this register unit.
757   virtual unsigned getRegUnitWeight(unsigned RegUnit) const = 0;
758 
759   /// Get the number of dimensions of register pressure.
760   virtual unsigned getNumRegPressureSets() const = 0;
761 
762   /// Get the name of this register unit pressure set.
763   virtual const char *getRegPressureSetName(unsigned Idx) const = 0;
764 
765   /// Get the register unit pressure limit for this dimension.
766   /// This limit must be adjusted dynamically for reserved registers.
767   virtual unsigned getRegPressureSetLimit(const MachineFunction &MF,
768                                           unsigned Idx) const = 0;
769 
770   /// Get the dimensions of register pressure impacted by this register class.
771   /// Returns a -1 terminated array of pressure set IDs.
772   virtual const int *getRegClassPressureSets(
773     const TargetRegisterClass *RC) const = 0;
774 
775   /// Get the dimensions of register pressure impacted by this register unit.
776   /// Returns a -1 terminated array of pressure set IDs.
777   virtual const int *getRegUnitPressureSets(unsigned RegUnit) const = 0;
778 
779   /// Get a list of 'hint' registers that the register allocator should try
780   /// first when allocating a physical register for the virtual register
781   /// VirtReg. These registers are effectively moved to the front of the
782   /// allocation order. If true is returned, regalloc will try to only use
783   /// hints to the greatest extent possible even if it means spilling.
784   ///
785   /// The Order argument is the allocation order for VirtReg's register class
786   /// as returned from RegisterClassInfo::getOrder(). The hint registers must
787   /// come from Order, and they must not be reserved.
788   ///
789   /// The default implementation of this function will only add target
790   /// independent register allocation hints. Targets that override this
791   /// function should typically call this default implementation as well and
792   /// expect to see generic copy hints added.
793   virtual bool
794   getRegAllocationHints(Register VirtReg, ArrayRef<MCPhysReg> Order,
795                         SmallVectorImpl<MCPhysReg> &Hints,
796                         const MachineFunction &MF,
797                         const VirtRegMap *VRM = nullptr,
798                         const LiveRegMatrix *Matrix = nullptr) const;
799 
800   /// A callback to allow target a chance to update register allocation hints
801   /// when a register is "changed" (e.g. coalesced) to another register.
802   /// e.g. On ARM, some virtual registers should target register pairs,
803   /// if one of pair is coalesced to another register, the allocation hint of
804   /// the other half of the pair should be changed to point to the new register.
805   virtual void updateRegAllocHint(Register Reg, Register NewReg,
806                                   MachineFunction &MF) const {
807     // Do nothing.
808   }
809 
810   /// Allow the target to reverse allocation order of local live ranges. This
811   /// will generally allocate shorter local live ranges first. For targets with
812   /// many registers, this could reduce regalloc compile time by a large
813   /// factor. It is disabled by default for three reasons:
814   /// (1) Top-down allocation is simpler and easier to debug for targets that
815   /// don't benefit from reversing the order.
816   /// (2) Bottom-up allocation could result in poor evicition decisions on some
817   /// targets affecting the performance of compiled code.
818   /// (3) Bottom-up allocation is no longer guaranteed to optimally color.
819   virtual bool reverseLocalAssignment() const { return false; }
820 
821   /// Allow the target to override the cost of using a callee-saved register for
822   /// the first time. Default value of 0 means we will use a callee-saved
823   /// register if it is available.
824   virtual unsigned getCSRFirstUseCost() const { return 0; }
825 
826   /// Returns true if the target requires (and can make use of) the register
827   /// scavenger.
828   virtual bool requiresRegisterScavenging(const MachineFunction &MF) const {
829     return false;
830   }
831 
832   /// Returns true if the target wants to use frame pointer based accesses to
833   /// spill to the scavenger emergency spill slot.
834   virtual bool useFPForScavengingIndex(const MachineFunction &MF) const {
835     return true;
836   }
837 
838   /// Returns true if the target requires post PEI scavenging of registers for
839   /// materializing frame index constants.
840   virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const {
841     return false;
842   }
843 
844   /// Returns true if the target requires using the RegScavenger directly for
845   /// frame elimination despite using requiresFrameIndexScavenging.
846   virtual bool requiresFrameIndexReplacementScavenging(
847       const MachineFunction &MF) const {
848     return false;
849   }
850 
851   /// Returns true if the target wants the LocalStackAllocation pass to be run
852   /// and virtual base registers used for more efficient stack access.
853   virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const {
854     return false;
855   }
856 
857   /// Return true if target has reserved a spill slot in the stack frame of
858   /// the given function for the specified register. e.g. On x86, if the frame
859   /// register is required, the first fixed stack object is reserved as its
860   /// spill slot. This tells PEI not to create a new stack frame
861   /// object for the given register. It should be called only after
862   /// determineCalleeSaves().
863   virtual bool hasReservedSpillSlot(const MachineFunction &MF, Register Reg,
864                                     int &FrameIdx) const {
865     return false;
866   }
867 
868   /// Returns true if the live-ins should be tracked after register allocation.
869   virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
870     return true;
871   }
872 
873   /// True if the stack can be realigned for the target.
874   virtual bool canRealignStack(const MachineFunction &MF) const;
875 
876   /// True if storage within the function requires the stack pointer to be
877   /// aligned more than the normal calling convention calls for.
878   /// This cannot be overriden by the target, but canRealignStack can be
879   /// overridden.
880   bool needsStackRealignment(const MachineFunction &MF) const;
881 
882   /// Get the offset from the referenced frame index in the instruction,
883   /// if there is one.
884   virtual int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
885                                            int Idx) const {
886     return 0;
887   }
888 
889   /// Returns true if the instruction's frame index reference would be better
890   /// served by a base register other than FP or SP.
891   /// Used by LocalStackFrameAllocation to determine which frame index
892   /// references it should create new base registers for.
893   virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
894     return false;
895   }
896 
897   /// Insert defining instruction(s) for BaseReg to be a pointer to FrameIdx
898   /// before insertion point I.
899   virtual void materializeFrameBaseRegister(MachineBasicBlock *MBB,
900                                             Register BaseReg, int FrameIdx,
901                                             int64_t Offset) const {
902     llvm_unreachable("materializeFrameBaseRegister does not exist on this "
903                      "target");
904   }
905 
906   /// Resolve a frame index operand of an instruction
907   /// to reference the indicated base register plus offset instead.
908   virtual void resolveFrameIndex(MachineInstr &MI, Register BaseReg,
909                                  int64_t Offset) const {
910     llvm_unreachable("resolveFrameIndex does not exist on this target");
911   }
912 
913   /// Determine whether a given base register plus offset immediate is
914   /// encodable to resolve a frame index.
915   virtual bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg,
916                                   int64_t Offset) const {
917     llvm_unreachable("isFrameOffsetLegal does not exist on this target");
918   }
919 
920   /// Spill the register so it can be used by the register scavenger.
921   /// Return true if the register was spilled, false otherwise.
922   /// If this function does not spill the register, the scavenger
923   /// will instead spill it to the emergency spill slot.
924   virtual bool saveScavengerRegister(MachineBasicBlock &MBB,
925                                      MachineBasicBlock::iterator I,
926                                      MachineBasicBlock::iterator &UseMI,
927                                      const TargetRegisterClass *RC,
928                                      Register Reg) const {
929     return false;
930   }
931 
932   /// This method must be overriden to eliminate abstract frame indices from
933   /// instructions which may use them. The instruction referenced by the
934   /// iterator contains an MO_FrameIndex operand which must be eliminated by
935   /// this method. This method may modify or replace the specified instruction,
936   /// as long as it keeps the iterator pointing at the finished product.
937   /// SPAdj is the SP adjustment due to call frame setup instruction.
938   /// FIOperandNum is the FI operand number.
939   virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI,
940                                    int SPAdj, unsigned FIOperandNum,
941                                    RegScavenger *RS = nullptr) const = 0;
942 
943   /// Return the assembly name for \p Reg.
944   virtual StringRef getRegAsmName(MCRegister Reg) const {
945     // FIXME: We are assuming that the assembly name is equal to the TableGen
946     // name converted to lower case
947     //
948     // The TableGen name is the name of the definition for this register in the
949     // target's tablegen files.  For example, the TableGen name of
950     // def EAX : Register <...>; is "EAX"
951     return StringRef(getName(Reg));
952   }
953 
954   //===--------------------------------------------------------------------===//
955   /// Subtarget Hooks
956 
957   /// SrcRC and DstRC will be morphed into NewRC if this returns true.
958   virtual bool shouldCoalesce(MachineInstr *MI,
959                               const TargetRegisterClass *SrcRC,
960                               unsigned SubReg,
961                               const TargetRegisterClass *DstRC,
962                               unsigned DstSubReg,
963                               const TargetRegisterClass *NewRC,
964                               LiveIntervals &LIS) const
965   { return true; }
966 
967   /// Region split has a high compile time cost especially for large live range.
968   /// This method is used to decide whether or not \p VirtReg should
969   /// go through this expensive splitting heuristic.
970   virtual bool shouldRegionSplitForVirtReg(const MachineFunction &MF,
971                                            const LiveInterval &VirtReg) const;
972 
973   //===--------------------------------------------------------------------===//
974   /// Debug information queries.
975 
976   /// getFrameRegister - This method should return the register used as a base
977   /// for values allocated in the current stack frame.
978   virtual Register getFrameRegister(const MachineFunction &MF) const = 0;
979 
980   /// Mark a register and all its aliases as reserved in the given set.
981   void markSuperRegs(BitVector &RegisterSet, MCRegister Reg) const;
982 
983   /// Returns true if for every register in the set all super registers are part
984   /// of the set as well.
985   bool checkAllSuperRegsMarked(const BitVector &RegisterSet,
986       ArrayRef<MCPhysReg> Exceptions = ArrayRef<MCPhysReg>()) const;
987 
988   virtual const TargetRegisterClass *
989   getConstrainedRegClassForOperand(const MachineOperand &MO,
990                                    const MachineRegisterInfo &MRI) const {
991     return nullptr;
992   }
993 
994   /// Returns the physical register number of sub-register "Index"
995   /// for physical register RegNo. Return zero if the sub-register does not
996   /// exist.
997   inline Register getSubReg(MCRegister Reg, unsigned Idx) const {
998     return static_cast<const MCRegisterInfo *>(this)->getSubReg(Reg, Idx);
999   }
1000 };
1001 
1002 //===----------------------------------------------------------------------===//
1003 //                           SuperRegClassIterator
1004 //===----------------------------------------------------------------------===//
1005 //
1006 // Iterate over the possible super-registers for a given register class. The
1007 // iterator will visit a list of pairs (Idx, Mask) corresponding to the
1008 // possible classes of super-registers.
1009 //
1010 // Each bit mask will have at least one set bit, and each set bit in Mask
1011 // corresponds to a SuperRC such that:
1012 //
1013 //   For all Reg in SuperRC: Reg:Idx is in RC.
1014 //
1015 // The iterator can include (O, RC->getSubClassMask()) as the first entry which
1016 // also satisfies the above requirement, assuming Reg:0 == Reg.
1017 //
1018 class SuperRegClassIterator {
1019   const unsigned RCMaskWords;
1020   unsigned SubReg = 0;
1021   const uint16_t *Idx;
1022   const uint32_t *Mask;
1023 
1024 public:
1025   /// Create a SuperRegClassIterator that visits all the super-register classes
1026   /// of RC. When IncludeSelf is set, also include the (0, sub-classes) entry.
1027   SuperRegClassIterator(const TargetRegisterClass *RC,
1028                         const TargetRegisterInfo *TRI,
1029                         bool IncludeSelf = false)
1030     : RCMaskWords((TRI->getNumRegClasses() + 31) / 32),
1031       Idx(RC->getSuperRegIndices()), Mask(RC->getSubClassMask()) {
1032     if (!IncludeSelf)
1033       ++*this;
1034   }
1035 
1036   /// Returns true if this iterator is still pointing at a valid entry.
1037   bool isValid() const { return Idx; }
1038 
1039   /// Returns the current sub-register index.
1040   unsigned getSubReg() const { return SubReg; }
1041 
1042   /// Returns the bit mask of register classes that getSubReg() projects into
1043   /// RC.
1044   /// See TargetRegisterClass::getSubClassMask() for how to use it.
1045   const uint32_t *getMask() const { return Mask; }
1046 
1047   /// Advance iterator to the next entry.
1048   void operator++() {
1049     assert(isValid() && "Cannot move iterator past end.");
1050     Mask += RCMaskWords;
1051     SubReg = *Idx++;
1052     if (!SubReg)
1053       Idx = nullptr;
1054   }
1055 };
1056 
1057 //===----------------------------------------------------------------------===//
1058 //                           BitMaskClassIterator
1059 //===----------------------------------------------------------------------===//
1060 /// This class encapuslates the logic to iterate over bitmask returned by
1061 /// the various RegClass related APIs.
1062 /// E.g., this class can be used to iterate over the subclasses provided by
1063 /// TargetRegisterClass::getSubClassMask or SuperRegClassIterator::getMask.
1064 class BitMaskClassIterator {
1065   /// Total number of register classes.
1066   const unsigned NumRegClasses;
1067   /// Base index of CurrentChunk.
1068   /// In other words, the number of bit we read to get at the
1069   /// beginning of that chunck.
1070   unsigned Base = 0;
1071   /// Adjust base index of CurrentChunk.
1072   /// Base index + how many bit we read within CurrentChunk.
1073   unsigned Idx = 0;
1074   /// Current register class ID.
1075   unsigned ID = 0;
1076   /// Mask we are iterating over.
1077   const uint32_t *Mask;
1078   /// Current chunk of the Mask we are traversing.
1079   uint32_t CurrentChunk;
1080 
1081   /// Move ID to the next set bit.
1082   void moveToNextID() {
1083     // If the current chunk of memory is empty, move to the next one,
1084     // while making sure we do not go pass the number of register
1085     // classes.
1086     while (!CurrentChunk) {
1087       // Move to the next chunk.
1088       Base += 32;
1089       if (Base >= NumRegClasses) {
1090         ID = NumRegClasses;
1091         return;
1092       }
1093       CurrentChunk = *++Mask;
1094       Idx = Base;
1095     }
1096     // Otherwise look for the first bit set from the right
1097     // (representation of the class ID is big endian).
1098     // See getSubClassMask for more details on the representation.
1099     unsigned Offset = countTrailingZeros(CurrentChunk);
1100     // Add the Offset to the adjusted base number of this chunk: Idx.
1101     // This is the ID of the register class.
1102     ID = Idx + Offset;
1103 
1104     // Consume the zeros, if any, and the bit we just read
1105     // so that we are at the right spot for the next call.
1106     // Do not do Offset + 1 because Offset may be 31 and 32
1107     // will be UB for the shift, though in that case we could
1108     // have make the chunk being equal to 0, but that would
1109     // have introduced a if statement.
1110     moveNBits(Offset);
1111     moveNBits(1);
1112   }
1113 
1114   /// Move \p NumBits Bits forward in CurrentChunk.
1115   void moveNBits(unsigned NumBits) {
1116     assert(NumBits < 32 && "Undefined behavior spotted!");
1117     // Consume the bit we read for the next call.
1118     CurrentChunk >>= NumBits;
1119     // Adjust the base for the chunk.
1120     Idx += NumBits;
1121   }
1122 
1123 public:
1124   /// Create a BitMaskClassIterator that visits all the register classes
1125   /// represented by \p Mask.
1126   ///
1127   /// \pre \p Mask != nullptr
1128   BitMaskClassIterator(const uint32_t *Mask, const TargetRegisterInfo &TRI)
1129       : NumRegClasses(TRI.getNumRegClasses()), Mask(Mask), CurrentChunk(*Mask) {
1130     // Move to the first ID.
1131     moveToNextID();
1132   }
1133 
1134   /// Returns true if this iterator is still pointing at a valid entry.
1135   bool isValid() const { return getID() != NumRegClasses; }
1136 
1137   /// Returns the current register class ID.
1138   unsigned getID() const { return ID; }
1139 
1140   /// Advance iterator to the next entry.
1141   void operator++() {
1142     assert(isValid() && "Cannot move iterator past end.");
1143     moveToNextID();
1144   }
1145 };
1146 
1147 // This is useful when building IndexedMaps keyed on virtual registers
1148 struct VirtReg2IndexFunctor {
1149   using argument_type = unsigned;
1150   unsigned operator()(unsigned Reg) const {
1151     return Register::virtReg2Index(Reg);
1152   }
1153 };
1154 
1155 /// Prints virtual and physical registers with or without a TRI instance.
1156 ///
1157 /// The format is:
1158 ///   %noreg          - NoRegister
1159 ///   %5              - a virtual register.
1160 ///   %5:sub_8bit     - a virtual register with sub-register index (with TRI).
1161 ///   %eax            - a physical register
1162 ///   %physreg17      - a physical register when no TRI instance given.
1163 ///
1164 /// Usage: OS << printReg(Reg, TRI, SubRegIdx) << '\n';
1165 Printable printReg(Register Reg, const TargetRegisterInfo *TRI = nullptr,
1166                    unsigned SubIdx = 0,
1167                    const MachineRegisterInfo *MRI = nullptr);
1168 
1169 /// Create Printable object to print register units on a \ref raw_ostream.
1170 ///
1171 /// Register units are named after their root registers:
1172 ///
1173 ///   al      - Single root.
1174 ///   fp0~st7 - Dual roots.
1175 ///
1176 /// Usage: OS << printRegUnit(Unit, TRI) << '\n';
1177 Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI);
1178 
1179 /// Create Printable object to print virtual registers and physical
1180 /// registers on a \ref raw_ostream.
1181 Printable printVRegOrUnit(unsigned VRegOrUnit, const TargetRegisterInfo *TRI);
1182 
1183 /// Create Printable object to print register classes or register banks
1184 /// on a \ref raw_ostream.
1185 Printable printRegClassOrBank(Register Reg, const MachineRegisterInfo &RegInfo,
1186                               const TargetRegisterInfo *TRI);
1187 
1188 } // end namespace llvm
1189 
1190 #endif // LLVM_CODEGEN_TARGETREGISTERINFO_H
1191