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 projec 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 regclass_iterator RegClassBegin, RegClassEnd; // List of regclasses
227 TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
228 regclass_iterator RegClassBegin,
229 regclass_iterator RegClassEnd,
230 const char *const *subregindexnames);
231 virtual ~TargetRegisterInfo();
234 // Register numbers can represent physical registers, virtual registers, and
235 // sometimes stack slots. The unsigned values are divided into these ranges:
237 // 0 Not a register, can be used as a sentinel.
238 // [1;2^30) Physical registers assigned by TableGen.
239 // [2^30;2^31) Stack slots. (Rarely used.)
240 // [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
242 // Further sentinels can be allocated from the small negative integers.
243 // DenseMapInfo<unsigned> uses -1u and -2u.
245 /// isStackSlot - Sometimes it is useful the be able to store a non-negative
246 /// frame index in a variable that normally holds a register. isStackSlot()
247 /// returns true if Reg is in the range used for stack slots.
249 /// Note that isVirtualRegister() and isPhysicalRegister() cannot handle stack
250 /// slots, so if a variable may contains a stack slot, always check
251 /// isStackSlot() first.
253 static bool isStackSlot(unsigned Reg) {
254 return int(Reg) >= (1 << 30);
257 /// stackSlot2Index - Compute the frame index from a register value
258 /// representing a stack slot.
259 static int stackSlot2Index(unsigned Reg) {
260 assert(isStackSlot(Reg) && "Not a stack slot");
261 return int(Reg - (1u << 30));
264 /// index2StackSlot - Convert a non-negative frame index to a stack slot
266 static unsigned index2StackSlot(int FI) {
267 assert(FI >= 0 && "Cannot hold a negative frame index.");
268 return FI + (1u << 30);
271 /// isPhysicalRegister - Return true if the specified register number is in
272 /// the physical register namespace.
273 static bool isPhysicalRegister(unsigned Reg) {
274 assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
278 /// isVirtualRegister - Return true if the specified register number is in
279 /// the virtual register namespace.
280 static bool isVirtualRegister(unsigned Reg) {
281 assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
285 /// virtReg2Index - Convert a virtual register number to a 0-based index.
286 /// The first virtual register in a function will get the index 0.
287 static unsigned virtReg2Index(unsigned Reg) {
288 assert(isVirtualRegister(Reg) && "Not a virtual register");
289 return Reg & ~(1u << 31);
292 /// index2VirtReg - Convert a 0-based index to a virtual register number.
293 /// This is the inverse operation of VirtReg2IndexFunctor below.
294 static unsigned index2VirtReg(unsigned Index) {
295 return Index | (1u << 31);
298 /// getMinimalPhysRegClass - Returns the Register Class of a physical
299 /// register of the given type, picking the most sub register class of
300 /// the right type that contains this physreg.
301 const TargetRegisterClass *
302 getMinimalPhysRegClass(unsigned Reg, EVT VT = MVT::Other) const;
304 /// getAllocatableClass - Return the maximal subclass of the given register
305 /// class that is alloctable, or NULL.
306 const TargetRegisterClass *
307 getAllocatableClass(const TargetRegisterClass *RC) const;
309 /// getAllocatableSet - Returns a bitset indexed by register number
310 /// indicating if a register is allocatable or not. If a register class is
311 /// specified, returns the subset for the class.
312 BitVector getAllocatableSet(const MachineFunction &MF,
313 const TargetRegisterClass *RC = NULL) const;
315 /// getCostPerUse - Return the additional cost of using this register instead
316 /// of other registers in its class.
317 unsigned getCostPerUse(unsigned RegNo) const {
318 return InfoDesc[RegNo].CostPerUse;
321 /// isInAllocatableClass - Return true if the register is in the allocation
322 /// of any register class.
323 bool isInAllocatableClass(unsigned RegNo) const {
324 return InfoDesc[RegNo].inAllocatableClass;
327 /// getSubRegIndexName - Return the human-readable symbolic target-specific
328 /// name for the specified SubRegIndex.
329 const char *getSubRegIndexName(unsigned SubIdx) const {
330 assert(SubIdx && "This is not a subregister index");
331 return SubRegIndexNames[SubIdx-1];
334 /// regsOverlap - Returns true if the two registers are equal or alias each
335 /// other. The registers may be virtual register.
336 bool regsOverlap(unsigned regA, unsigned regB) const {
337 if (regA == regB) return true;
338 if (isVirtualRegister(regA) || isVirtualRegister(regB))
340 for (const uint16_t *regList = getOverlaps(regA)+1; *regList; ++regList) {
341 if (*regList == regB) return true;
346 /// isSubRegister - Returns true if regB is a sub-register of regA.
348 bool isSubRegister(unsigned regA, unsigned regB) const {
349 return isSuperRegister(regB, regA);
352 /// isSuperRegister - Returns true if regB is a super-register of regA.
354 bool isSuperRegister(unsigned regA, unsigned regB) const {
355 for (const uint16_t *regList = getSuperRegisters(regA); *regList;++regList){
356 if (*regList == regB) return true;
361 /// getCalleeSavedRegs - Return a null-terminated list of all of the
362 /// callee saved registers on this target. The register should be in the
363 /// order of desired callee-save stack frame offset. The first register is
364 /// closest to the incoming stack pointer if stack grows down, and vice versa.
366 virtual const uint16_t* getCalleeSavedRegs(const MachineFunction *MF = 0)
369 /// getCallPreservedMask - Return a mask of call-preserved registers for the
370 /// given calling convention on the current sub-target. The mask should
371 /// include all call-preserved aliases. This is used by the register
372 /// allocator to determine which registers can be live across a call.
374 /// The mask is an array containing (TRI::getNumRegs()+31)/32 entries.
375 /// A set bit indicates that all bits of the corresponding register are
376 /// preserved across the function call. The bit mask is expected to be
377 /// sub-register complete, i.e. if A is preserved, so are all its
380 /// Bits are numbered from the LSB, so the bit for physical register Reg can
381 /// be found as (Mask[Reg / 32] >> Reg % 32) & 1.
383 /// A NULL pointer means that no register mask will be used, and call
384 /// instructions should use implicit-def operands to indicate call clobbered
387 virtual const uint32_t *getCallPreservedMask(CallingConv::ID) const {
388 // The default mask clobbers everything. All targets should override.
392 /// getReservedRegs - Returns a bitset indexed by physical register number
393 /// indicating if a register is a special register that has particular uses
394 /// and should be considered unavailable at all times, e.g. SP, RA. This is
395 /// used by register scavenger to determine what registers are free.
396 virtual BitVector getReservedRegs(const MachineFunction &MF) const = 0;
398 /// getMatchingSuperReg - Return a super-register of the specified register
399 /// Reg so its sub-register of index SubIdx is Reg.
400 unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
401 const TargetRegisterClass *RC) const {
402 return MCRegisterInfo::getMatchingSuperReg(Reg, SubIdx, RC->MC);
405 /// canCombineSubRegIndices - Given a register class and a list of
406 /// subregister indices, return true if it's possible to combine the
407 /// subregister indices into one that corresponds to a larger
408 /// subregister. Return the new subregister index by reference. Note the
409 /// new index may be zero if the given subregisters can be combined to
410 /// form the whole register.
411 virtual bool canCombineSubRegIndices(const TargetRegisterClass *RC,
412 SmallVectorImpl<unsigned> &SubIndices,
413 unsigned &NewSubIdx) const {
417 /// getMatchingSuperRegClass - Return a subclass of the specified register
418 /// class A so that each register in it has a sub-register of the
419 /// specified sub-register index which is in the specified register class B.
421 /// TableGen will synthesize missing A sub-classes.
422 virtual const TargetRegisterClass *
423 getMatchingSuperRegClass(const TargetRegisterClass *A,
424 const TargetRegisterClass *B, unsigned Idx) const;
426 /// getSubClassWithSubReg - Returns the largest legal sub-class of RC that
427 /// supports the sub-register index Idx.
428 /// If no such sub-class exists, return NULL.
429 /// If all registers in RC already have an Idx sub-register, return RC.
431 /// TableGen generates a version of this function that is good enough in most
432 /// cases. Targets can override if they have constraints that TableGen
433 /// doesn't understand. For example, the x86 sub_8bit sub-register index is
434 /// supported by the full GR32 register class in 64-bit mode, but only by the
435 /// GR32_ABCD regiister class in 32-bit mode.
437 /// TableGen will synthesize missing RC sub-classes.
438 virtual const TargetRegisterClass *
439 getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const {
440 assert(Idx == 0 && "Target has no sub-registers");
444 /// composeSubRegIndices - Return the subregister index you get from composing
445 /// two subregister indices.
447 /// If R:a:b is the same register as R:c, then composeSubRegIndices(a, b)
448 /// returns c. Note that composeSubRegIndices does not tell you about illegal
449 /// compositions. If R does not have a subreg a, or R:a does not have a subreg
450 /// b, composeSubRegIndices doesn't tell you.
452 /// The ARM register Q0 has two D subregs dsub_0:D0 and dsub_1:D1. It also has
453 /// ssub_0:S0 - ssub_3:S3 subregs.
454 /// If you compose subreg indices dsub_1, ssub_0 you get ssub_2.
456 virtual unsigned composeSubRegIndices(unsigned a, unsigned b) const {
457 // This default implementation is correct for most targets.
461 /// getCommonSuperRegClass - Find a common super-register class if it exists.
463 /// Find a register class, SuperRC and two sub-register indices, PreA and
466 /// 1. PreA + SubA == PreB + SubB (using composeSubRegIndices()), and
468 /// 2. For all Reg in SuperRC: Reg:PreA in RCA and Reg:PreB in RCB, and
470 /// 3. SuperRC->getSize() >= max(RCA->getSize(), RCB->getSize()).
472 /// SuperRC will be chosen such that no super-class of SuperRC satisfies the
473 /// requirements, and there is no register class with a smaller spill size
474 /// that satisfies the requirements.
476 /// SubA and SubB must not be 0. Use getMatchingSuperRegClass() instead.
478 /// Either of the PreA and PreB sub-register indices may be returned as 0. In
479 /// that case, the returned register class will be a sub-class of the
480 /// corresponding argument register class.
482 /// The function returns NULL if no register class can be found.
484 const TargetRegisterClass*
485 getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
486 const TargetRegisterClass *RCB, unsigned SubB,
487 unsigned &PreA, unsigned &PreB) const;
489 //===--------------------------------------------------------------------===//
490 // Register Class Information
493 /// Register class iterators
495 regclass_iterator regclass_begin() const { return RegClassBegin; }
496 regclass_iterator regclass_end() const { return RegClassEnd; }
498 unsigned getNumRegClasses() const {
499 return (unsigned)(regclass_end()-regclass_begin());
502 /// getRegClass - Returns the register class associated with the enumeration
503 /// value. See class MCOperandInfo.
504 const TargetRegisterClass *getRegClass(unsigned i) const {
505 assert(i < getNumRegClasses() && "Register Class ID out of range");
506 return RegClassBegin[i];
509 /// getCommonSubClass - find the largest common subclass of A and B. Return
510 /// NULL if there is no common subclass.
511 const TargetRegisterClass *
512 getCommonSubClass(const TargetRegisterClass *A,
513 const TargetRegisterClass *B) const;
515 /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
516 /// values. If a target supports multiple different pointer register classes,
517 /// kind specifies which one is indicated.
518 virtual const TargetRegisterClass *getPointerRegClass(unsigned Kind=0) const {
519 llvm_unreachable("Target didn't implement getPointerRegClass!");
522 /// getCrossCopyRegClass - Returns a legal register class to copy a register
523 /// in the specified class to or from. If it is possible to copy the register
524 /// directly without using a cross register class copy, return the specified
525 /// RC. Returns NULL if it is not possible to copy between a two registers of
526 /// the specified class.
527 virtual const TargetRegisterClass *
528 getCrossCopyRegClass(const TargetRegisterClass *RC) const {
532 /// getLargestLegalSuperClass - Returns the largest super class of RC that is
533 /// legal to use in the current sub-target and has the same spill size.
534 /// The returned register class can be used to create virtual registers which
535 /// means that all its registers can be copied and spilled.
536 virtual const TargetRegisterClass*
537 getLargestLegalSuperClass(const TargetRegisterClass *RC) const {
538 /// The default implementation is very conservative and doesn't allow the
539 /// register allocator to inflate register classes.
543 /// getRegPressureLimit - Return the register pressure "high water mark" for
544 /// the specific register class. The scheduler is in high register pressure
545 /// mode (for the specific register class) if it goes over the limit.
547 /// Note: this is the old register pressure model that relies on a manually
548 /// specified representative register class per value type.
549 virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC,
550 MachineFunction &MF) const {
554 // Get the weight in units of pressure for this register class.
555 virtual const RegClassWeight &getRegClassWeight(
556 const TargetRegisterClass *RC) const = 0;
558 /// Get the number of dimensions of register pressure.
559 virtual unsigned getNumRegPressureSets() const = 0;
561 /// Get the name of this register unit pressure set.
562 virtual const char *getRegPressureSetName(unsigned Idx) const = 0;
564 /// Get the register unit pressure limit for this dimension.
565 /// This limit must be adjusted dynamically for reserved registers.
566 virtual unsigned getRegPressureSetLimit(unsigned Idx) const = 0;
568 /// Get the dimensions of register pressure impacted by this register class.
569 /// Returns a -1 terminated array of pressure set IDs.
570 virtual const int *getRegClassPressureSets(
571 const TargetRegisterClass *RC) const = 0;
573 /// getRawAllocationOrder - Returns the register allocation order for a
574 /// specified register class with a target-dependent hint. The returned list
575 /// may contain reserved registers that cannot be allocated.
577 /// Register allocators need only call this function to resolve
578 /// target-dependent hints, but it should work without hinting as well.
579 virtual ArrayRef<uint16_t>
580 getRawAllocationOrder(const TargetRegisterClass *RC,
581 unsigned HintType, unsigned HintReg,
582 const MachineFunction &MF) const {
583 return RC->getRawAllocationOrder(MF);
586 /// ResolveRegAllocHint - Resolves the specified register allocation hint
587 /// to a physical register. Returns the physical register if it is successful.
588 virtual unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg,
589 const MachineFunction &MF) const {
590 if (Type == 0 && Reg && isPhysicalRegister(Reg))
595 /// avoidWriteAfterWrite - Return true if the register allocator should avoid
596 /// writing a register from RC in two consecutive instructions.
597 /// This can avoid pipeline stalls on certain architectures.
598 /// It does cause increased register pressure, though.
599 virtual bool avoidWriteAfterWrite(const TargetRegisterClass *RC) const {
603 /// UpdateRegAllocHint - A callback to allow target a chance to update
604 /// register allocation hints when a register is "changed" (e.g. coalesced)
605 /// to another register. e.g. On ARM, some virtual registers should target
606 /// register pairs, if one of pair is coalesced to another register, the
607 /// allocation hint of the other half of the pair should be changed to point
608 /// to the new register.
609 virtual void UpdateRegAllocHint(unsigned Reg, unsigned NewReg,
610 MachineFunction &MF) const {
614 /// requiresRegisterScavenging - returns true if the target requires (and can
615 /// make use of) the register scavenger.
616 virtual bool requiresRegisterScavenging(const MachineFunction &MF) const {
620 /// useFPForScavengingIndex - returns true if the target wants to use
621 /// frame pointer based accesses to spill to the scavenger emergency spill
623 virtual bool useFPForScavengingIndex(const MachineFunction &MF) const {
627 /// requiresFrameIndexScavenging - returns true if the target requires post
628 /// PEI scavenging of registers for materializing frame index constants.
629 virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const {
633 /// requiresVirtualBaseRegisters - Returns true if the target wants the
634 /// LocalStackAllocation pass to be run and virtual base registers
635 /// used for more efficient stack access.
636 virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const {
640 /// hasReservedSpillSlot - Return true if target has reserved a spill slot in
641 /// the stack frame of the given function for the specified register. e.g. On
642 /// x86, if the frame register is required, the first fixed stack object is
643 /// reserved as its spill slot. This tells PEI not to create a new stack frame
644 /// object for the given register. It should be called only after
645 /// processFunctionBeforeCalleeSavedScan().
646 virtual bool hasReservedSpillSlot(const MachineFunction &MF, unsigned Reg,
647 int &FrameIdx) const {
651 /// trackLivenessAfterRegAlloc - returns true if the live-ins should be tracked
652 /// after register allocation.
653 virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
657 /// needsStackRealignment - true if storage within the function requires the
658 /// stack pointer to be aligned more than the normal calling convention calls
660 virtual bool needsStackRealignment(const MachineFunction &MF) const {
664 /// getFrameIndexInstrOffset - Get the offset from the referenced frame
665 /// index in the instruction, if there is one.
666 virtual int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
671 /// needsFrameBaseReg - Returns true if the instruction's frame index
672 /// reference would be better served by a base register other than FP
673 /// or SP. Used by LocalStackFrameAllocation to determine which frame index
674 /// references it should create new base registers for.
675 virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
679 /// materializeFrameBaseRegister - Insert defining instruction(s) for
680 /// BaseReg to be a pointer to FrameIdx before insertion point I.
681 virtual void materializeFrameBaseRegister(MachineBasicBlock *MBB,
682 unsigned BaseReg, int FrameIdx,
683 int64_t Offset) const {
684 llvm_unreachable("materializeFrameBaseRegister does not exist on this "
688 /// resolveFrameIndex - Resolve a frame index operand of an instruction
689 /// to reference the indicated base register plus offset instead.
690 virtual void resolveFrameIndex(MachineBasicBlock::iterator I,
691 unsigned BaseReg, int64_t Offset) const {
692 llvm_unreachable("resolveFrameIndex does not exist on this target");
695 /// isFrameOffsetLegal - Determine whether a given offset immediate is
696 /// encodable to resolve a frame index.
697 virtual bool isFrameOffsetLegal(const MachineInstr *MI,
698 int64_t Offset) const {
699 llvm_unreachable("isFrameOffsetLegal does not exist on this target");
702 /// eliminateCallFramePseudoInstr - This method is called during prolog/epilog
703 /// code insertion to eliminate call frame setup and destroy pseudo
704 /// instructions (but only if the Target is using them). It is responsible
705 /// for eliminating these instructions, replacing them with concrete
706 /// instructions. This method need only be implemented if using call frame
707 /// setup/destroy pseudo instructions.
710 eliminateCallFramePseudoInstr(MachineFunction &MF,
711 MachineBasicBlock &MBB,
712 MachineBasicBlock::iterator MI) const {
713 llvm_unreachable("Call Frame Pseudo Instructions do not exist on this "
718 /// saveScavengerRegister - Spill the register so it can be used by the
719 /// register scavenger. Return true if the register was spilled, false
720 /// otherwise. If this function does not spill the register, the scavenger
721 /// will instead spill it to the emergency spill slot.
723 virtual bool saveScavengerRegister(MachineBasicBlock &MBB,
724 MachineBasicBlock::iterator I,
725 MachineBasicBlock::iterator &UseMI,
726 const TargetRegisterClass *RC,
727 unsigned Reg) const {
731 /// eliminateFrameIndex - This method must be overriden to eliminate abstract
732 /// frame indices from instructions which may use them. The instruction
733 /// referenced by the iterator contains an MO_FrameIndex operand which must be
734 /// eliminated by this method. This method may modify or replace the
735 /// specified instruction, as long as it keeps the iterator pointing at the
736 /// finished product. SPAdj is the SP adjustment due to call frame setup
738 virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI,
739 int SPAdj, RegScavenger *RS=NULL) const = 0;
741 //===--------------------------------------------------------------------===//
742 /// Debug information queries.
744 /// getFrameRegister - This method should return the register used as a base
745 /// for values allocated in the current stack frame.
746 virtual unsigned getFrameRegister(const MachineFunction &MF) const = 0;
748 /// getCompactUnwindRegNum - This function maps the register to the number for
749 /// compact unwind encoding. Return -1 if the register isn't valid.
750 virtual int getCompactUnwindRegNum(unsigned, bool) const {
756 //===----------------------------------------------------------------------===//
757 // SuperRegClassIterator
758 //===----------------------------------------------------------------------===//
760 // Iterate over the possible super-registers for a given register class. The
761 // iterator will visit a list of pairs (Idx, Mask) corresponding to the
762 // possible classes of super-registers.
764 // Each bit mask will have at least one set bit, and each set bit in Mask
765 // corresponds to a SuperRC such that:
767 // For all Reg in SuperRC: Reg:Idx is in RC.
769 // The iterator can include (O, RC->getSubClassMask()) as the first entry which
770 // also satisfies the above requirement, assuming Reg:0 == Reg.
772 class SuperRegClassIterator {
773 const unsigned RCMaskWords;
776 const uint32_t *Mask;
779 /// Create a SuperRegClassIterator that visits all the super-register classes
780 /// of RC. When IncludeSelf is set, also include the (0, sub-classes) entry.
781 SuperRegClassIterator(const TargetRegisterClass *RC,
782 const TargetRegisterInfo *TRI,
783 bool IncludeSelf = false)
784 : RCMaskWords((TRI->getNumRegClasses() + 31) / 32),
786 Idx(RC->getSuperRegIndices()),
787 Mask(RC->getSubClassMask()) {
792 /// Returns true if this iterator is still pointing at a valid entry.
793 bool isValid() const { return Idx; }
795 /// Returns the current sub-register index.
796 unsigned getSubReg() const { return SubReg; }
798 /// Returns the bit mask if register classes that getSubReg() projects into
800 const uint32_t *getMask() const { return Mask; }
802 /// Advance iterator to the next entry.
804 assert(isValid() && "Cannot move iterator past end.");
812 // This is useful when building IndexedMaps keyed on virtual registers
813 struct VirtReg2IndexFunctor : public std::unary_function<unsigned, unsigned> {
814 unsigned operator()(unsigned Reg) const {
815 return TargetRegisterInfo::virtReg2Index(Reg);
819 /// PrintReg - Helper class for printing registers on a raw_ostream.
820 /// Prints virtual and physical registers with or without a TRI instance.
823 /// %noreg - NoRegister
824 /// %vreg5 - a virtual register.
825 /// %vreg5:sub_8bit - a virtual register with sub-register index (with TRI).
826 /// %EAX - a physical register
827 /// %physreg17 - a physical register when no TRI instance given.
829 /// Usage: OS << PrintReg(Reg, TRI) << '\n';
832 const TargetRegisterInfo *TRI;
836 PrintReg(unsigned reg, const TargetRegisterInfo *tri = 0, unsigned subidx = 0)
837 : TRI(tri), Reg(reg), SubIdx(subidx) {}
838 void print(raw_ostream&) const;
841 static inline raw_ostream &operator<<(raw_ostream &OS, const PrintReg &PR) {
846 } // End llvm namespace