1 //=== Target/TargetRegisterInfo.h - Target Register Information -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes an abstract interface used to get information about a
11 // target machines register file. This information is used for a variety of
12 // purposed, especially register allocation.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TARGET_TARGETREGISTERINFO_H
17 #define LLVM_TARGET_TARGETREGISTERINFO_H
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/CodeGen/MachineBasicBlock.h"
21 #include "llvm/CodeGen/ValueTypes.h"
22 #include "llvm/ADT/ArrayRef.h"
23 #include "llvm/CallingConv.h"
30 class MachineFunction;
32 template<class T> class SmallVectorImpl;
35 class TargetRegisterClass {
37 typedef const uint16_t* iterator;
38 typedef const uint16_t* const_iterator;
39 typedef const MVT::SimpleValueType* vt_iterator;
40 typedef const TargetRegisterClass* const * sc_iterator;
42 // Instance variables filled by tablegen, do not use!
43 const MCRegisterClass *MC;
44 const vt_iterator VTs;
45 const uint32_t *SubClassMask;
46 const uint16_t *SuperRegIndices;
47 const sc_iterator SuperClasses;
48 ArrayRef<uint16_t> (*OrderFunc)(const MachineFunction&);
50 /// getID() - Return the register class ID number.
52 unsigned getID() const { return MC->getID(); }
54 /// getName() - Return the register class name for debugging.
56 const char *getName() const { return MC->getName(); }
58 /// begin/end - Return all of the registers in this class.
60 iterator begin() const { return MC->begin(); }
61 iterator end() const { return MC->end(); }
63 /// getNumRegs - Return the number of registers in this class.
65 unsigned getNumRegs() const { return MC->getNumRegs(); }
67 /// getRegister - Return the specified register in the class.
69 unsigned getRegister(unsigned i) const {
70 return MC->getRegister(i);
73 /// contains - Return true if the specified register is included in this
74 /// register class. This does not include virtual registers.
75 bool contains(unsigned Reg) const {
76 return MC->contains(Reg);
79 /// contains - Return true if both registers are in this class.
80 bool contains(unsigned Reg1, unsigned Reg2) const {
81 return MC->contains(Reg1, Reg2);
84 /// getSize - Return the size of the register in bytes, which is also the size
85 /// of a stack slot allocated to hold a spilled copy of this register.
86 unsigned getSize() const { return MC->getSize(); }
88 /// getAlignment - Return the minimum required alignment for a register of
90 unsigned getAlignment() const { return MC->getAlignment(); }
92 /// getCopyCost - Return the cost of copying a value between two registers in
93 /// this class. A negative number means the register class is very expensive
94 /// to copy e.g. status flag register classes.
95 int getCopyCost() const { return MC->getCopyCost(); }
97 /// isAllocatable - Return true if this register class may be used to create
98 /// virtual registers.
99 bool isAllocatable() const { return MC->isAllocatable(); }
101 /// hasType - return true if this TargetRegisterClass has the ValueType vt.
103 bool hasType(EVT vt) const {
104 for(int i = 0; VTs[i] != MVT::Other; ++i)
105 if (EVT(VTs[i]) == vt)
110 /// vt_begin / vt_end - Loop over all of the value types that can be
111 /// represented by values in this register class.
112 vt_iterator vt_begin() const {
116 vt_iterator vt_end() const {
118 while (*I != MVT::Other) ++I;
122 /// hasSubClass - return true if the specified TargetRegisterClass
123 /// is a proper sub-class of this TargetRegisterClass.
124 bool hasSubClass(const TargetRegisterClass *RC) const {
125 return RC != this && hasSubClassEq(RC);
128 /// hasSubClassEq - Returns true if RC is a sub-class of or equal to this
130 bool hasSubClassEq(const TargetRegisterClass *RC) const {
131 unsigned ID = RC->getID();
132 return (SubClassMask[ID / 32] >> (ID % 32)) & 1;
135 /// hasSuperClass - return true if the specified TargetRegisterClass is a
136 /// proper super-class of this TargetRegisterClass.
137 bool hasSuperClass(const TargetRegisterClass *RC) const {
138 return RC->hasSubClass(this);
141 /// hasSuperClassEq - Returns true if RC is a super-class of or equal to this
143 bool hasSuperClassEq(const TargetRegisterClass *RC) const {
144 return RC->hasSubClassEq(this);
147 /// getSubClassMask - Returns a bit vector of subclasses, including this one.
148 /// The vector is indexed by class IDs, see hasSubClassEq() above for how to
150 const uint32_t *getSubClassMask() const {
154 /// getSuperRegIndices - Returns a 0-terminated list of sub-register indices
155 /// that project some super-register class into this register class. The list
156 /// has an entry for each Idx such that:
158 /// There exists SuperRC where:
159 /// For all Reg in SuperRC:
160 /// this->contains(Reg:Idx)
162 const uint16_t *getSuperRegIndices() const {
163 return SuperRegIndices;
166 /// getSuperClasses - Returns a NULL terminated list of super-classes. The
167 /// classes are ordered by ID which is also a topological ordering from large
168 /// to small classes. The list does NOT include the current class.
169 sc_iterator getSuperClasses() const {
173 /// isASubClass - return true if this TargetRegisterClass is a subset
174 /// class of at least one other TargetRegisterClass.
175 bool isASubClass() const {
176 return SuperClasses[0] != 0;
179 /// getRawAllocationOrder - Returns the preferred order for allocating
180 /// registers from this register class in MF. The raw order comes directly
181 /// from the .td file and may include reserved registers that are not
182 /// allocatable. Register allocators should also make sure to allocate
183 /// callee-saved registers only after all the volatiles are used. The
184 /// RegisterClassInfo class provides filtered allocation orders with
185 /// callee-saved registers moved to the end.
187 /// The MachineFunction argument can be used to tune the allocatable
188 /// registers based on the characteristics of the function, subtarget, or
191 /// By default, this method returns all registers in the class.
193 ArrayRef<uint16_t> getRawAllocationOrder(const MachineFunction &MF) const {
194 return OrderFunc ? OrderFunc(MF) : makeArrayRef(begin(), getNumRegs());
198 /// TargetRegisterInfoDesc - Extra information, not in MCRegisterDesc, about
199 /// registers. These are used by codegen, not by MC.
200 struct TargetRegisterInfoDesc {
201 unsigned CostPerUse; // Extra cost of instructions using register.
202 bool inAllocatableClass; // Register belongs to an allocatable regclass.
205 /// Each TargetRegisterClass has a per register weight, and weight
206 /// limit which must be less than the limits of its pressure sets.
207 struct RegClassWeight {
209 unsigned WeightLimit;
212 /// TargetRegisterInfo base class - We assume that the target defines a static
213 /// array of TargetRegisterDesc objects that represent all of the machine
214 /// registers that the target has. As such, we simply have to track a pointer
215 /// to this array so that we can turn register number into a register
218 class TargetRegisterInfo : public MCRegisterInfo {
220 typedef const TargetRegisterClass * const * regclass_iterator;
222 const TargetRegisterInfoDesc *InfoDesc; // Extra desc array for codegen
223 const char *const *SubRegIndexNames; // Names of subreg indexes.
224 // Pointer to array of lane masks, one per sub-reg index.
225 const unsigned *SubRegIndexLaneMasks;
227 regclass_iterator RegClassBegin, RegClassEnd; // List of regclasses
230 TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
231 regclass_iterator RegClassBegin,
232 regclass_iterator RegClassEnd,
233 const char *const *SRINames,
234 const unsigned *SRILaneMasks);
235 virtual ~TargetRegisterInfo();
238 // Register numbers can represent physical registers, virtual registers, and
239 // sometimes stack slots. The unsigned values are divided into these ranges:
241 // 0 Not a register, can be used as a sentinel.
242 // [1;2^30) Physical registers assigned by TableGen.
243 // [2^30;2^31) Stack slots. (Rarely used.)
244 // [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
246 // Further sentinels can be allocated from the small negative integers.
247 // DenseMapInfo<unsigned> uses -1u and -2u.
249 /// isStackSlot - Sometimes it is useful the be able to store a non-negative
250 /// frame index in a variable that normally holds a register. isStackSlot()
251 /// returns true if Reg is in the range used for stack slots.
253 /// Note that isVirtualRegister() and isPhysicalRegister() cannot handle stack
254 /// slots, so if a variable may contains a stack slot, always check
255 /// isStackSlot() first.
257 static bool isStackSlot(unsigned Reg) {
258 return int(Reg) >= (1 << 30);
261 /// stackSlot2Index - Compute the frame index from a register value
262 /// representing a stack slot.
263 static int stackSlot2Index(unsigned Reg) {
264 assert(isStackSlot(Reg) && "Not a stack slot");
265 return int(Reg - (1u << 30));
268 /// index2StackSlot - Convert a non-negative frame index to a stack slot
270 static unsigned index2StackSlot(int FI) {
271 assert(FI >= 0 && "Cannot hold a negative frame index.");
272 return FI + (1u << 30);
275 /// isPhysicalRegister - Return true if the specified register number is in
276 /// the physical register namespace.
277 static bool isPhysicalRegister(unsigned Reg) {
278 assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
282 /// isVirtualRegister - Return true if the specified register number is in
283 /// the virtual register namespace.
284 static bool isVirtualRegister(unsigned Reg) {
285 assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
289 /// virtReg2Index - Convert a virtual register number to a 0-based index.
290 /// The first virtual register in a function will get the index 0.
291 static unsigned virtReg2Index(unsigned Reg) {
292 assert(isVirtualRegister(Reg) && "Not a virtual register");
293 return Reg & ~(1u << 31);
296 /// index2VirtReg - Convert a 0-based index to a virtual register number.
297 /// This is the inverse operation of VirtReg2IndexFunctor below.
298 static unsigned index2VirtReg(unsigned Index) {
299 return Index | (1u << 31);
302 /// getMinimalPhysRegClass - Returns the Register Class of a physical
303 /// register of the given type, picking the most sub register class of
304 /// the right type that contains this physreg.
305 const TargetRegisterClass *
306 getMinimalPhysRegClass(unsigned Reg, EVT VT = MVT::Other) const;
308 /// getAllocatableClass - Return the maximal subclass of the given register
309 /// class that is alloctable, or NULL.
310 const TargetRegisterClass *
311 getAllocatableClass(const TargetRegisterClass *RC) const;
313 /// getAllocatableSet - Returns a bitset indexed by register number
314 /// indicating if a register is allocatable or not. If a register class is
315 /// specified, returns the subset for the class.
316 BitVector getAllocatableSet(const MachineFunction &MF,
317 const TargetRegisterClass *RC = NULL) const;
319 /// getCostPerUse - Return the additional cost of using this register instead
320 /// of other registers in its class.
321 unsigned getCostPerUse(unsigned RegNo) const {
322 return InfoDesc[RegNo].CostPerUse;
325 /// isInAllocatableClass - Return true if the register is in the allocation
326 /// of any register class.
327 bool isInAllocatableClass(unsigned RegNo) const {
328 return InfoDesc[RegNo].inAllocatableClass;
331 /// getSubRegIndexName - Return the human-readable symbolic target-specific
332 /// name for the specified SubRegIndex.
333 const char *getSubRegIndexName(unsigned SubIdx) const {
334 assert(SubIdx && SubIdx < getNumSubRegIndices() &&
335 "This is not a subregister index");
336 return SubRegIndexNames[SubIdx-1];
339 /// getSubRegIndexLaneMask - Return a bitmask representing the parts of a
340 /// register that are covered by SubIdx.
342 /// Lane masks for sub-register indices are similar to register units for
343 /// physical registers. The individual bits in a lane mask can't be assigned
344 /// any specific meaning. They can be used to check if two sub-register
347 /// If the target has a register such that:
349 /// getSubReg(Reg, A) overlaps getSubReg(Reg, B)
353 /// getSubRegIndexLaneMask(A) & getSubRegIndexLaneMask(B) != 0
355 /// The converse is not necessarily true. If two lane masks have a common
356 /// bit, the corresponding sub-registers may not overlap, but it can be
357 /// assumed that they usually will.
358 unsigned getSubRegIndexLaneMask(unsigned SubIdx) const {
359 // SubIdx == 0 is allowed, it has the lane mask ~0u.
360 assert(SubIdx < getNumSubRegIndices() && "This is not a subregister index");
361 return SubRegIndexLaneMasks[SubIdx];
364 /// regsOverlap - Returns true if the two registers are equal or alias each
365 /// other. The registers may be virtual register.
366 bool regsOverlap(unsigned regA, unsigned regB) const {
367 if (regA == regB) return true;
368 if (isVirtualRegister(regA) || isVirtualRegister(regB))
371 // Regunits are numerically ordered. Find a common unit.
372 MCRegUnitIterator RUA(regA, this);
373 MCRegUnitIterator RUB(regB, this);
375 if (*RUA == *RUB) return true;
376 if (*RUA < *RUB) ++RUA;
378 } while (RUA.isValid() && RUB.isValid());
382 /// hasRegUnit - Returns true if Reg contains RegUnit.
383 bool hasRegUnit(unsigned Reg, unsigned RegUnit) const {
384 for (MCRegUnitIterator Units(Reg, this); Units.isValid(); ++Units)
385 if (*Units == RegUnit)
390 /// isSubRegister - Returns true if regB is a sub-register of regA.
392 bool isSubRegister(unsigned regA, unsigned regB) const {
393 return isSuperRegister(regB, regA);
396 /// isSuperRegister - Returns true if regB is a super-register of regA.
398 bool isSuperRegister(unsigned RegA, unsigned RegB) const {
399 for (MCSuperRegIterator I(RegA, this); I.isValid(); ++I)
405 /// getCalleeSavedRegs - Return a null-terminated list of all of the
406 /// callee saved registers on this target. The register should be in the
407 /// order of desired callee-save stack frame offset. The first register is
408 /// closest to the incoming stack pointer if stack grows down, and vice versa.
410 virtual const uint16_t* getCalleeSavedRegs(const MachineFunction *MF = 0)
413 /// getCallPreservedMask - Return a mask of call-preserved registers for the
414 /// given calling convention on the current sub-target. The mask should
415 /// include all call-preserved aliases. This is used by the register
416 /// allocator to determine which registers can be live across a call.
418 /// The mask is an array containing (TRI::getNumRegs()+31)/32 entries.
419 /// A set bit indicates that all bits of the corresponding register are
420 /// preserved across the function call. The bit mask is expected to be
421 /// sub-register complete, i.e. if A is preserved, so are all its
424 /// Bits are numbered from the LSB, so the bit for physical register Reg can
425 /// be found as (Mask[Reg / 32] >> Reg % 32) & 1.
427 /// A NULL pointer means that no register mask will be used, and call
428 /// instructions should use implicit-def operands to indicate call clobbered
431 virtual const uint32_t *getCallPreservedMask(CallingConv::ID) const {
432 // The default mask clobbers everything. All targets should override.
436 /// getReservedRegs - Returns a bitset indexed by physical register number
437 /// indicating if a register is a special register that has particular uses
438 /// and should be considered unavailable at all times, e.g. SP, RA. This is
439 /// used by register scavenger to determine what registers are free.
440 virtual BitVector getReservedRegs(const MachineFunction &MF) const = 0;
442 /// getMatchingSuperReg - Return a super-register of the specified register
443 /// Reg so its sub-register of index SubIdx is Reg.
444 unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
445 const TargetRegisterClass *RC) const {
446 return MCRegisterInfo::getMatchingSuperReg(Reg, SubIdx, RC->MC);
449 /// canCombineSubRegIndices - Given a register class and a list of
450 /// subregister indices, return true if it's possible to combine the
451 /// subregister indices into one that corresponds to a larger
452 /// subregister. Return the new subregister index by reference. Note the
453 /// new index may be zero if the given subregisters can be combined to
454 /// form the whole register.
455 virtual bool canCombineSubRegIndices(const TargetRegisterClass *RC,
456 SmallVectorImpl<unsigned> &SubIndices,
457 unsigned &NewSubIdx) const {
461 /// getMatchingSuperRegClass - Return a subclass of the specified register
462 /// class A so that each register in it has a sub-register of the
463 /// specified sub-register index which is in the specified register class B.
465 /// TableGen will synthesize missing A sub-classes.
466 virtual const TargetRegisterClass *
467 getMatchingSuperRegClass(const TargetRegisterClass *A,
468 const TargetRegisterClass *B, unsigned Idx) const;
470 /// getSubClassWithSubReg - Returns the largest legal sub-class of RC that
471 /// supports the sub-register index Idx.
472 /// If no such sub-class exists, return NULL.
473 /// If all registers in RC already have an Idx sub-register, return RC.
475 /// TableGen generates a version of this function that is good enough in most
476 /// cases. Targets can override if they have constraints that TableGen
477 /// doesn't understand. For example, the x86 sub_8bit sub-register index is
478 /// supported by the full GR32 register class in 64-bit mode, but only by the
479 /// GR32_ABCD regiister class in 32-bit mode.
481 /// TableGen will synthesize missing RC sub-classes.
482 virtual const TargetRegisterClass *
483 getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const {
484 assert(Idx == 0 && "Target has no sub-registers");
488 /// composeSubRegIndices - Return the subregister index you get from composing
489 /// two subregister indices.
491 /// If R:a:b is the same register as R:c, then composeSubRegIndices(a, b)
492 /// returns c. Note that composeSubRegIndices does not tell you about illegal
493 /// compositions. If R does not have a subreg a, or R:a does not have a subreg
494 /// b, composeSubRegIndices doesn't tell you.
496 /// The ARM register Q0 has two D subregs dsub_0:D0 and dsub_1:D1. It also has
497 /// ssub_0:S0 - ssub_3:S3 subregs.
498 /// If you compose subreg indices dsub_1, ssub_0 you get ssub_2.
500 virtual unsigned composeSubRegIndices(unsigned a, unsigned b) const {
501 // This default implementation is correct for most targets.
505 /// getCommonSuperRegClass - Find a common super-register class if it exists.
507 /// Find a register class, SuperRC and two sub-register indices, PreA and
510 /// 1. PreA + SubA == PreB + SubB (using composeSubRegIndices()), and
512 /// 2. For all Reg in SuperRC: Reg:PreA in RCA and Reg:PreB in RCB, and
514 /// 3. SuperRC->getSize() >= max(RCA->getSize(), RCB->getSize()).
516 /// SuperRC will be chosen such that no super-class of SuperRC satisfies the
517 /// requirements, and there is no register class with a smaller spill size
518 /// that satisfies the requirements.
520 /// SubA and SubB must not be 0. Use getMatchingSuperRegClass() instead.
522 /// Either of the PreA and PreB sub-register indices may be returned as 0. In
523 /// that case, the returned register class will be a sub-class of the
524 /// corresponding argument register class.
526 /// The function returns NULL if no register class can be found.
528 const TargetRegisterClass*
529 getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
530 const TargetRegisterClass *RCB, unsigned SubB,
531 unsigned &PreA, unsigned &PreB) const;
533 //===--------------------------------------------------------------------===//
534 // Register Class Information
537 /// Register class iterators
539 regclass_iterator regclass_begin() const { return RegClassBegin; }
540 regclass_iterator regclass_end() const { return RegClassEnd; }
542 unsigned getNumRegClasses() const {
543 return (unsigned)(regclass_end()-regclass_begin());
546 /// getRegClass - Returns the register class associated with the enumeration
547 /// value. See class MCOperandInfo.
548 const TargetRegisterClass *getRegClass(unsigned i) const {
549 assert(i < getNumRegClasses() && "Register Class ID out of range");
550 return RegClassBegin[i];
553 /// getCommonSubClass - find the largest common subclass of A and B. Return
554 /// NULL if there is no common subclass.
555 const TargetRegisterClass *
556 getCommonSubClass(const TargetRegisterClass *A,
557 const TargetRegisterClass *B) const;
559 /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
560 /// values. If a target supports multiple different pointer register classes,
561 /// kind specifies which one is indicated.
562 virtual const TargetRegisterClass *
563 getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const {
564 llvm_unreachable("Target didn't implement getPointerRegClass!");
567 /// getCrossCopyRegClass - Returns a legal register class to copy a register
568 /// in the specified class to or from. If it is possible to copy the register
569 /// directly without using a cross register class copy, return the specified
570 /// RC. Returns NULL if it is not possible to copy between a two registers of
571 /// the specified class.
572 virtual const TargetRegisterClass *
573 getCrossCopyRegClass(const TargetRegisterClass *RC) const {
577 /// getLargestLegalSuperClass - Returns the largest super class of RC that is
578 /// legal to use in the current sub-target and has the same spill size.
579 /// The returned register class can be used to create virtual registers which
580 /// means that all its registers can be copied and spilled.
581 virtual const TargetRegisterClass*
582 getLargestLegalSuperClass(const TargetRegisterClass *RC) const {
583 /// The default implementation is very conservative and doesn't allow the
584 /// register allocator to inflate register classes.
588 /// getRegPressureLimit - Return the register pressure "high water mark" for
589 /// the specific register class. The scheduler is in high register pressure
590 /// mode (for the specific register class) if it goes over the limit.
592 /// Note: this is the old register pressure model that relies on a manually
593 /// specified representative register class per value type.
594 virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC,
595 MachineFunction &MF) const {
599 // Get the weight in units of pressure for this register class.
600 virtual const RegClassWeight &getRegClassWeight(
601 const TargetRegisterClass *RC) const = 0;
603 /// Get the number of dimensions of register pressure.
604 virtual unsigned getNumRegPressureSets() const = 0;
606 /// Get the name of this register unit pressure set.
607 virtual const char *getRegPressureSetName(unsigned Idx) const = 0;
609 /// Get the register unit pressure limit for this dimension.
610 /// This limit must be adjusted dynamically for reserved registers.
611 virtual unsigned getRegPressureSetLimit(unsigned Idx) const = 0;
613 /// Get the dimensions of register pressure impacted by this register class.
614 /// Returns a -1 terminated array of pressure set IDs.
615 virtual const int *getRegClassPressureSets(
616 const TargetRegisterClass *RC) const = 0;
618 /// getRawAllocationOrder - Returns the register allocation order for a
619 /// specified register class with a target-dependent hint. The returned list
620 /// may contain reserved registers that cannot be allocated.
622 /// Register allocators need only call this function to resolve
623 /// target-dependent hints, but it should work without hinting as well.
624 virtual ArrayRef<uint16_t>
625 getRawAllocationOrder(const TargetRegisterClass *RC,
626 unsigned HintType, unsigned HintReg,
627 const MachineFunction &MF) const {
628 return RC->getRawAllocationOrder(MF);
631 /// ResolveRegAllocHint - Resolves the specified register allocation hint
632 /// to a physical register. Returns the physical register if it is successful.
633 virtual unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg,
634 const MachineFunction &MF) const {
635 if (Type == 0 && Reg && isPhysicalRegister(Reg))
640 /// avoidWriteAfterWrite - Return true if the register allocator should avoid
641 /// writing a register from RC in two consecutive instructions.
642 /// This can avoid pipeline stalls on certain architectures.
643 /// It does cause increased register pressure, though.
644 virtual bool avoidWriteAfterWrite(const TargetRegisterClass *RC) const {
648 /// UpdateRegAllocHint - A callback to allow target a chance to update
649 /// register allocation hints when a register is "changed" (e.g. coalesced)
650 /// to another register. e.g. On ARM, some virtual registers should target
651 /// register pairs, if one of pair is coalesced to another register, the
652 /// allocation hint of the other half of the pair should be changed to point
653 /// to the new register.
654 virtual void UpdateRegAllocHint(unsigned Reg, unsigned NewReg,
655 MachineFunction &MF) const {
659 /// requiresRegisterScavenging - returns true if the target requires (and can
660 /// make use of) the register scavenger.
661 virtual bool requiresRegisterScavenging(const MachineFunction &MF) const {
665 /// useFPForScavengingIndex - returns true if the target wants to use
666 /// frame pointer based accesses to spill to the scavenger emergency spill
668 virtual bool useFPForScavengingIndex(const MachineFunction &MF) const {
672 /// requiresFrameIndexScavenging - returns true if the target requires post
673 /// PEI scavenging of registers for materializing frame index constants.
674 virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const {
678 /// requiresVirtualBaseRegisters - Returns true if the target wants the
679 /// LocalStackAllocation pass to be run and virtual base registers
680 /// used for more efficient stack access.
681 virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const {
685 /// hasReservedSpillSlot - Return true if target has reserved a spill slot in
686 /// the stack frame of the given function for the specified register. e.g. On
687 /// x86, if the frame register is required, the first fixed stack object is
688 /// reserved as its spill slot. This tells PEI not to create a new stack frame
689 /// object for the given register. It should be called only after
690 /// processFunctionBeforeCalleeSavedScan().
691 virtual bool hasReservedSpillSlot(const MachineFunction &MF, unsigned Reg,
692 int &FrameIdx) const {
696 /// trackLivenessAfterRegAlloc - returns true if the live-ins should be tracked
697 /// after register allocation.
698 virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
702 /// needsStackRealignment - true if storage within the function requires the
703 /// stack pointer to be aligned more than the normal calling convention calls
705 virtual bool needsStackRealignment(const MachineFunction &MF) const {
709 /// getFrameIndexInstrOffset - Get the offset from the referenced frame
710 /// index in the instruction, if there is one.
711 virtual int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
716 /// needsFrameBaseReg - Returns true if the instruction's frame index
717 /// reference would be better served by a base register other than FP
718 /// or SP. Used by LocalStackFrameAllocation to determine which frame index
719 /// references it should create new base registers for.
720 virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
724 /// materializeFrameBaseRegister - Insert defining instruction(s) for
725 /// BaseReg to be a pointer to FrameIdx before insertion point I.
726 virtual void materializeFrameBaseRegister(MachineBasicBlock *MBB,
727 unsigned BaseReg, int FrameIdx,
728 int64_t Offset) const {
729 llvm_unreachable("materializeFrameBaseRegister does not exist on this "
733 /// resolveFrameIndex - Resolve a frame index operand of an instruction
734 /// to reference the indicated base register plus offset instead.
735 virtual void resolveFrameIndex(MachineBasicBlock::iterator I,
736 unsigned BaseReg, int64_t Offset) const {
737 llvm_unreachable("resolveFrameIndex does not exist on this target");
740 /// isFrameOffsetLegal - Determine whether a given offset immediate is
741 /// encodable to resolve a frame index.
742 virtual bool isFrameOffsetLegal(const MachineInstr *MI,
743 int64_t Offset) const {
744 llvm_unreachable("isFrameOffsetLegal does not exist on this target");
747 /// eliminateCallFramePseudoInstr - This method is called during prolog/epilog
748 /// code insertion to eliminate call frame setup and destroy pseudo
749 /// instructions (but only if the Target is using them). It is responsible
750 /// for eliminating these instructions, replacing them with concrete
751 /// instructions. This method need only be implemented if using call frame
752 /// setup/destroy pseudo instructions.
755 eliminateCallFramePseudoInstr(MachineFunction &MF,
756 MachineBasicBlock &MBB,
757 MachineBasicBlock::iterator MI) const {
758 llvm_unreachable("Call Frame Pseudo Instructions do not exist on this "
763 /// saveScavengerRegister - Spill the register so it can be used by the
764 /// register scavenger. Return true if the register was spilled, false
765 /// otherwise. If this function does not spill the register, the scavenger
766 /// will instead spill it to the emergency spill slot.
768 virtual bool saveScavengerRegister(MachineBasicBlock &MBB,
769 MachineBasicBlock::iterator I,
770 MachineBasicBlock::iterator &UseMI,
771 const TargetRegisterClass *RC,
772 unsigned Reg) const {
776 /// eliminateFrameIndex - This method must be overriden to eliminate abstract
777 /// frame indices from instructions which may use them. The instruction
778 /// referenced by the iterator contains an MO_FrameIndex operand which must be
779 /// eliminated by this method. This method may modify or replace the
780 /// specified instruction, as long as it keeps the iterator pointing at the
781 /// finished product. SPAdj is the SP adjustment due to call frame setup
783 virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI,
784 int SPAdj, RegScavenger *RS=NULL) const = 0;
786 //===--------------------------------------------------------------------===//
787 /// Debug information queries.
789 /// getFrameRegister - This method should return the register used as a base
790 /// for values allocated in the current stack frame.
791 virtual unsigned getFrameRegister(const MachineFunction &MF) const = 0;
793 /// getCompactUnwindRegNum - This function maps the register to the number for
794 /// compact unwind encoding. Return -1 if the register isn't valid.
795 virtual int getCompactUnwindRegNum(unsigned, bool) const {
801 //===----------------------------------------------------------------------===//
802 // SuperRegClassIterator
803 //===----------------------------------------------------------------------===//
805 // Iterate over the possible super-registers for a given register class. The
806 // iterator will visit a list of pairs (Idx, Mask) corresponding to the
807 // possible classes of super-registers.
809 // Each bit mask will have at least one set bit, and each set bit in Mask
810 // corresponds to a SuperRC such that:
812 // For all Reg in SuperRC: Reg:Idx is in RC.
814 // The iterator can include (O, RC->getSubClassMask()) as the first entry which
815 // also satisfies the above requirement, assuming Reg:0 == Reg.
817 class SuperRegClassIterator {
818 const unsigned RCMaskWords;
821 const uint32_t *Mask;
824 /// Create a SuperRegClassIterator that visits all the super-register classes
825 /// of RC. When IncludeSelf is set, also include the (0, sub-classes) entry.
826 SuperRegClassIterator(const TargetRegisterClass *RC,
827 const TargetRegisterInfo *TRI,
828 bool IncludeSelf = false)
829 : RCMaskWords((TRI->getNumRegClasses() + 31) / 32),
831 Idx(RC->getSuperRegIndices()),
832 Mask(RC->getSubClassMask()) {
837 /// Returns true if this iterator is still pointing at a valid entry.
838 bool isValid() const { return Idx; }
840 /// Returns the current sub-register index.
841 unsigned getSubReg() const { return SubReg; }
843 /// Returns the bit mask if register classes that getSubReg() projects into
845 const uint32_t *getMask() const { return Mask; }
847 /// Advance iterator to the next entry.
849 assert(isValid() && "Cannot move iterator past end.");
857 // This is useful when building IndexedMaps keyed on virtual registers
858 struct VirtReg2IndexFunctor : public std::unary_function<unsigned, unsigned> {
859 unsigned operator()(unsigned Reg) const {
860 return TargetRegisterInfo::virtReg2Index(Reg);
864 /// PrintReg - Helper class for printing registers on a raw_ostream.
865 /// Prints virtual and physical registers with or without a TRI instance.
868 /// %noreg - NoRegister
869 /// %vreg5 - a virtual register.
870 /// %vreg5:sub_8bit - a virtual register with sub-register index (with TRI).
871 /// %EAX - a physical register
872 /// %physreg17 - a physical register when no TRI instance given.
874 /// Usage: OS << PrintReg(Reg, TRI) << '\n';
877 const TargetRegisterInfo *TRI;
881 PrintReg(unsigned reg, const TargetRegisterInfo *tri = 0, unsigned subidx = 0)
882 : TRI(tri), Reg(reg), SubIdx(subidx) {}
883 void print(raw_ostream&) const;
886 static inline raw_ostream &operator<<(raw_ostream &OS, const PrintReg &PR) {
891 /// PrintRegUnit - Helper class for printing register units on a raw_ostream.
893 /// Register units are named after their root registers:
895 /// AL - Single root.
896 /// FP0~ST7 - Dual roots.
898 /// Usage: OS << PrintRegUnit(Unit, TRI) << '\n';
901 const TargetRegisterInfo *TRI;
904 PrintRegUnit(unsigned unit, const TargetRegisterInfo *tri)
905 : TRI(tri), Unit(unit) {}
906 void print(raw_ostream&) const;
909 static inline raw_ostream &operator<<(raw_ostream &OS, const PrintRegUnit &PR) {
914 } // End llvm namespace