Teach tblgen to emit MCRegisterClasses.
[oota-llvm.git] / include / llvm / Target / TargetRegisterInfo.h
1 //=== Target/TargetRegisterInfo.h - Target Register Information -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file 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.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TARGET_TARGETREGISTERINFO_H
17 #define LLVM_TARGET_TARGETREGISTERINFO_H
18
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/ADT/DenseSet.h"
24 #include <cassert>
25 #include <functional>
26
27 namespace llvm {
28
29 class BitVector;
30 class MachineFunction;
31 class RegScavenger;
32 template<class T> class SmallVectorImpl;
33 class raw_ostream;
34
35 class TargetRegisterClass : public MCRegisterClass {
36 public:
37   typedef const EVT* vt_iterator;
38   typedef const TargetRegisterClass* const * sc_iterator;
39 private:
40   const vt_iterator VTs;
41   const sc_iterator SubClasses;
42   const sc_iterator SuperClasses;
43   const sc_iterator SubRegClasses;
44   const sc_iterator SuperRegClasses;
45 public:
46   TargetRegisterClass(unsigned id, const char *name, const EVT *vts,
47                       const TargetRegisterClass * const *subcs,
48                       const TargetRegisterClass * const *supcs,
49                       const TargetRegisterClass * const *subregcs,
50                       const TargetRegisterClass * const *superregcs,
51                       unsigned RS, unsigned Al, int CC, bool Allocable,
52                       iterator RB, iterator RE)
53     : MCRegisterClass(id, name, RS, Al, CC, Allocable, RB, RE),
54       VTs(vts), SubClasses(subcs), SuperClasses(supcs), SubRegClasses(subregcs),
55       SuperRegClasses(superregcs) {
56     initMCRegisterClass();
57   }
58
59   virtual ~TargetRegisterClass() {}     // Allow subclasses
60
61   /// hasType - return true if this TargetRegisterClass has the ValueType vt.
62   ///
63   bool hasType(EVT vt) const {
64     for(int i = 0; VTs[i] != MVT::Other; ++i)
65       if (VTs[i] == vt)
66         return true;
67     return false;
68   }
69
70   /// vt_begin / vt_end - Loop over all of the value types that can be
71   /// represented by values in this register class.
72   vt_iterator vt_begin() const {
73     return VTs;
74   }
75
76   vt_iterator vt_end() const {
77     vt_iterator I = VTs;
78     while (*I != MVT::Other) ++I;
79     return I;
80   }
81
82   /// subregclasses_begin / subregclasses_end - Loop over all of
83   /// the subreg register classes of this register class.
84   sc_iterator subregclasses_begin() const {
85     return SubRegClasses;
86   }
87
88   sc_iterator subregclasses_end() const {
89     sc_iterator I = SubRegClasses;
90     while (*I != NULL) ++I;
91     return I;
92   }
93
94   /// getSubRegisterRegClass - Return the register class of subregisters with
95   /// index SubIdx, or NULL if no such class exists.
96   const TargetRegisterClass* getSubRegisterRegClass(unsigned SubIdx) const {
97     assert(SubIdx>0 && "Invalid subregister index");
98     return SubRegClasses[SubIdx-1];
99   }
100
101   /// superregclasses_begin / superregclasses_end - Loop over all of
102   /// the superreg register classes of this register class.
103   sc_iterator superregclasses_begin() const {
104     return SuperRegClasses;
105   }
106
107   sc_iterator superregclasses_end() const {
108     sc_iterator I = SuperRegClasses;
109     while (*I != NULL) ++I;
110     return I;
111   }
112
113   /// hasSubClass - return true if the specified TargetRegisterClass
114   /// is a proper subset of this TargetRegisterClass.
115   bool hasSubClass(const TargetRegisterClass *cs) const {
116     for (int i = 0; SubClasses[i] != NULL; ++i)
117       if (SubClasses[i] == cs)
118         return true;
119     return false;
120   }
121
122   /// hasSubClassEq - Returns true if RC is a subclass of or equal to this
123   /// class.
124   bool hasSubClassEq(const TargetRegisterClass *RC) const {
125     return RC == this || hasSubClass(RC);
126   }
127
128   /// subclasses_begin / subclasses_end - Loop over all of the classes
129   /// that are proper subsets of this register class.
130   sc_iterator subclasses_begin() const {
131     return SubClasses;
132   }
133
134   sc_iterator subclasses_end() const {
135     sc_iterator I = SubClasses;
136     while (*I != NULL) ++I;
137     return I;
138   }
139
140   /// hasSuperClass - return true if the specified TargetRegisterClass is a
141   /// proper superset of this TargetRegisterClass.
142   bool hasSuperClass(const TargetRegisterClass *cs) const {
143     for (int i = 0; SuperClasses[i] != NULL; ++i)
144       if (SuperClasses[i] == cs)
145         return true;
146     return false;
147   }
148
149   /// hasSuperClassEq - Returns true if RC is a superclass of or equal to this
150   /// class.
151   bool hasSuperClassEq(const TargetRegisterClass *RC) const {
152     return RC == this || hasSuperClass(RC);
153   }
154
155   /// superclasses_begin / superclasses_end - Loop over all of the classes
156   /// that are proper supersets of this register class.
157   sc_iterator superclasses_begin() const {
158     return SuperClasses;
159   }
160
161   sc_iterator superclasses_end() const {
162     sc_iterator I = SuperClasses;
163     while (*I != NULL) ++I;
164     return I;
165   }
166
167   /// isASubClass - return true if this TargetRegisterClass is a subset
168   /// class of at least one other TargetRegisterClass.
169   bool isASubClass() const {
170     return SuperClasses[0] != 0;
171   }
172
173   /// getRawAllocationOrder - Returns the preferred order for allocating
174   /// registers from this register class in MF. The raw order comes directly
175   /// from the .td file and may include reserved registers that are not
176   /// allocatable. Register allocators should also make sure to allocate
177   /// callee-saved registers only after all the volatiles are used. The
178   /// RegisterClassInfo class provides filtered allocation orders with
179   /// callee-saved registers moved to the end.
180   ///
181   /// The MachineFunction argument can be used to tune the allocatable
182   /// registers based on the characteristics of the function, subtarget, or
183   /// other criteria.
184   ///
185   /// By default, this method returns all registers in the class.
186   ///
187   virtual
188   ArrayRef<unsigned> getRawAllocationOrder(const MachineFunction &MF) const {
189     return makeArrayRef(begin(), getNumRegs());
190   }
191 };
192
193 /// TargetRegisterInfoDesc - Extra information, not in MCRegisterDesc, about
194 /// registers. These are used by codegen, not by MC.
195 struct TargetRegisterInfoDesc {
196   unsigned CostPerUse;          // Extra cost of instructions using register.
197   bool inAllocatableClass;      // Register belongs to an allocatable regclass.
198 };
199
200 /// TargetRegisterInfo base class - We assume that the target defines a static
201 /// array of TargetRegisterDesc objects that represent all of the machine
202 /// registers that the target has.  As such, we simply have to track a pointer
203 /// to this array so that we can turn register number into a register
204 /// descriptor.
205 ///
206 class TargetRegisterInfo : public MCRegisterInfo {
207 public:
208   typedef const TargetRegisterClass * const * regclass_iterator;
209 private:
210   const TargetRegisterInfoDesc *InfoDesc;     // Extra desc array for codegen
211   const char *const *SubRegIndexNames;        // Names of subreg indexes.
212   regclass_iterator RegClassBegin, RegClassEnd;   // List of regclasses
213
214 protected:
215   TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
216                      regclass_iterator RegClassBegin,
217                      regclass_iterator RegClassEnd,
218                      const char *const *subregindexnames);
219   virtual ~TargetRegisterInfo();
220 public:
221
222   // Register numbers can represent physical registers, virtual registers, and
223   // sometimes stack slots. The unsigned values are divided into these ranges:
224   //
225   //   0           Not a register, can be used as a sentinel.
226   //   [1;2^30)    Physical registers assigned by TableGen.
227   //   [2^30;2^31) Stack slots. (Rarely used.)
228   //   [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
229   //
230   // Further sentinels can be allocated from the small negative integers.
231   // DenseMapInfo<unsigned> uses -1u and -2u.
232
233   /// isStackSlot - Sometimes it is useful the be able to store a non-negative
234   /// frame index in a variable that normally holds a register. isStackSlot()
235   /// returns true if Reg is in the range used for stack slots.
236   ///
237   /// Note that isVirtualRegister() and isPhysicalRegister() cannot handle stack
238   /// slots, so if a variable may contains a stack slot, always check
239   /// isStackSlot() first.
240   ///
241   static bool isStackSlot(unsigned Reg) {
242     return int(Reg) >= (1 << 30);
243   }
244
245   /// stackSlot2Index - Compute the frame index from a register value
246   /// representing a stack slot.
247   static int stackSlot2Index(unsigned Reg) {
248     assert(isStackSlot(Reg) && "Not a stack slot");
249     return int(Reg - (1u << 30));
250   }
251
252   /// index2StackSlot - Convert a non-negative frame index to a stack slot
253   /// register value.
254   static unsigned index2StackSlot(int FI) {
255     assert(FI >= 0 && "Cannot hold a negative frame index.");
256     return FI + (1u << 30);
257   }
258
259   /// isPhysicalRegister - Return true if the specified register number is in
260   /// the physical register namespace.
261   static bool isPhysicalRegister(unsigned Reg) {
262     assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
263     return int(Reg) > 0;
264   }
265
266   /// isVirtualRegister - Return true if the specified register number is in
267   /// the virtual register namespace.
268   static bool isVirtualRegister(unsigned Reg) {
269     assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
270     return int(Reg) < 0;
271   }
272
273   /// virtReg2Index - Convert a virtual register number to a 0-based index.
274   /// The first virtual register in a function will get the index 0.
275   static unsigned virtReg2Index(unsigned Reg) {
276     assert(isVirtualRegister(Reg) && "Not a virtual register");
277     return Reg & ~(1u << 31);
278   }
279
280   /// index2VirtReg - Convert a 0-based index to a virtual register number.
281   /// This is the inverse operation of VirtReg2IndexFunctor below.
282   static unsigned index2VirtReg(unsigned Index) {
283     return Index | (1u << 31);
284   }
285
286   /// getMinimalPhysRegClass - Returns the Register Class of a physical
287   /// register of the given type, picking the most sub register class of
288   /// the right type that contains this physreg.
289   const TargetRegisterClass *
290     getMinimalPhysRegClass(unsigned Reg, EVT VT = MVT::Other) const;
291
292   /// getAllocatableSet - Returns a bitset indexed by register number
293   /// indicating if a register is allocatable or not. If a register class is
294   /// specified, returns the subset for the class.
295   BitVector getAllocatableSet(const MachineFunction &MF,
296                               const TargetRegisterClass *RC = NULL) const;
297
298   /// getCostPerUse - Return the additional cost of using this register instead
299   /// of other registers in its class.
300   unsigned getCostPerUse(unsigned RegNo) const {
301     return InfoDesc[RegNo].CostPerUse;
302   }
303
304   /// isInAllocatableClass - Return true if the register is in the allocation
305   /// of any register class.
306   bool isInAllocatableClass(unsigned RegNo) const {
307     return InfoDesc[RegNo].inAllocatableClass;
308   }
309
310   /// getSubRegIndexName - Return the human-readable symbolic target-specific
311   /// name for the specified SubRegIndex.
312   const char *getSubRegIndexName(unsigned SubIdx) const {
313     assert(SubIdx && "This is not a subregister index");
314     return SubRegIndexNames[SubIdx-1];
315   }
316
317   /// regsOverlap - Returns true if the two registers are equal or alias each
318   /// other. The registers may be virtual register.
319   bool regsOverlap(unsigned regA, unsigned regB) const {
320     if (regA == regB) return true;
321     if (isVirtualRegister(regA) || isVirtualRegister(regB))
322       return false;
323     for (const unsigned *regList = getOverlaps(regA)+1; *regList; ++regList) {
324       if (*regList == regB) return true;
325     }
326     return false;
327   }
328
329   /// isSubRegister - Returns true if regB is a sub-register of regA.
330   ///
331   bool isSubRegister(unsigned regA, unsigned regB) const {
332     return isSuperRegister(regB, regA);
333   }
334
335   /// isSuperRegister - Returns true if regB is a super-register of regA.
336   ///
337   bool isSuperRegister(unsigned regA, unsigned regB) const {
338     for (const unsigned *regList = getSuperRegisters(regA); *regList;++regList){
339       if (*regList == regB) return true;
340     }
341     return false;
342   }
343
344   /// getCalleeSavedRegs - Return a null-terminated list of all of the
345   /// callee saved registers on this target. The register should be in the
346   /// order of desired callee-save stack frame offset. The first register is
347   /// closed to the incoming stack pointer if stack grows down, and vice versa.
348   virtual const unsigned* getCalleeSavedRegs(const MachineFunction *MF = 0)
349                                                                       const = 0;
350
351
352   /// getReservedRegs - Returns a bitset indexed by physical register number
353   /// indicating if a register is a special register that has particular uses
354   /// and should be considered unavailable at all times, e.g. SP, RA. This is
355   /// used by register scavenger to determine what registers are free.
356   virtual BitVector getReservedRegs(const MachineFunction &MF) const = 0;
357
358   /// getSubReg - Returns the physical register number of sub-register "Index"
359   /// for physical register RegNo. Return zero if the sub-register does not
360   /// exist.
361   virtual unsigned getSubReg(unsigned RegNo, unsigned Index) const = 0;
362
363   /// getSubRegIndex - For a given register pair, return the sub-register index
364   /// if the second register is a sub-register of the first. Return zero
365   /// otherwise.
366   virtual unsigned getSubRegIndex(unsigned RegNo, unsigned SubRegNo) const = 0;
367
368   /// getMatchingSuperReg - Return a super-register of the specified register
369   /// Reg so its sub-register of index SubIdx is Reg.
370   unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
371                                const TargetRegisterClass *RC) const {
372     for (const unsigned *SRs = getSuperRegisters(Reg); unsigned SR = *SRs;++SRs)
373       if (Reg == getSubReg(SR, SubIdx) && RC->contains(SR))
374         return SR;
375     return 0;
376   }
377
378   /// canCombineSubRegIndices - Given a register class and a list of
379   /// subregister indices, return true if it's possible to combine the
380   /// subregister indices into one that corresponds to a larger
381   /// subregister. Return the new subregister index by reference. Note the
382   /// new index may be zero if the given subregisters can be combined to
383   /// form the whole register.
384   virtual bool canCombineSubRegIndices(const TargetRegisterClass *RC,
385                                        SmallVectorImpl<unsigned> &SubIndices,
386                                        unsigned &NewSubIdx) const {
387     return 0;
388   }
389
390   /// getMatchingSuperRegClass - Return a subclass of the specified register
391   /// class A so that each register in it has a sub-register of the
392   /// specified sub-register index which is in the specified register class B.
393   virtual const TargetRegisterClass *
394   getMatchingSuperRegClass(const TargetRegisterClass *A,
395                            const TargetRegisterClass *B, unsigned Idx) const {
396     return 0;
397   }
398
399   /// composeSubRegIndices - Return the subregister index you get from composing
400   /// two subregister indices.
401   ///
402   /// If R:a:b is the same register as R:c, then composeSubRegIndices(a, b)
403   /// returns c. Note that composeSubRegIndices does not tell you about illegal
404   /// compositions. If R does not have a subreg a, or R:a does not have a subreg
405   /// b, composeSubRegIndices doesn't tell you.
406   ///
407   /// The ARM register Q0 has two D subregs dsub_0:D0 and dsub_1:D1. It also has
408   /// ssub_0:S0 - ssub_3:S3 subregs.
409   /// If you compose subreg indices dsub_1, ssub_0 you get ssub_2.
410   ///
411   virtual unsigned composeSubRegIndices(unsigned a, unsigned b) const {
412     // This default implementation is correct for most targets.
413     return b;
414   }
415
416   //===--------------------------------------------------------------------===//
417   // Register Class Information
418   //
419
420   /// Register class iterators
421   ///
422   regclass_iterator regclass_begin() const { return RegClassBegin; }
423   regclass_iterator regclass_end() const { return RegClassEnd; }
424
425   unsigned getNumRegClasses() const {
426     return (unsigned)(regclass_end()-regclass_begin());
427   }
428
429   /// getRegClass - Returns the register class associated with the enumeration
430   /// value.  See class MCOperandInfo.
431   const TargetRegisterClass *getRegClass(unsigned i) const {
432     assert(i < getNumRegClasses() && "Register Class ID out of range");
433     return RegClassBegin[i];
434   }
435
436   /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
437   /// values.  If a target supports multiple different pointer register classes,
438   /// kind specifies which one is indicated.
439   virtual const TargetRegisterClass *getPointerRegClass(unsigned Kind=0) const {
440     assert(0 && "Target didn't implement getPointerRegClass!");
441     return 0; // Must return a value in order to compile with VS 2005
442   }
443
444   /// getCrossCopyRegClass - Returns a legal register class to copy a register
445   /// in the specified class to or from. If it is possible to copy the register
446   /// directly without using a cross register class copy, return the specified
447   /// RC. Returns NULL if it is not possible to copy between a two registers of
448   /// the specified class.
449   virtual const TargetRegisterClass *
450   getCrossCopyRegClass(const TargetRegisterClass *RC) const {
451     return RC;
452   }
453
454   /// getLargestLegalSuperClass - Returns the largest super class of RC that is
455   /// legal to use in the current sub-target and has the same spill size.
456   /// The returned register class can be used to create virtual registers which
457   /// means that all its registers can be copied and spilled.
458   virtual const TargetRegisterClass*
459   getLargestLegalSuperClass(const TargetRegisterClass *RC) const {
460     /// The default implementation is very conservative and doesn't allow the
461     /// register allocator to inflate register classes.
462     return RC;
463   }
464
465   /// getRegPressureLimit - Return the register pressure "high water mark" for
466   /// the specific register class. The scheduler is in high register pressure
467   /// mode (for the specific register class) if it goes over the limit.
468   virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC,
469                                        MachineFunction &MF) const {
470     return 0;
471   }
472
473   /// getRawAllocationOrder - Returns the register allocation order for a
474   /// specified register class with a target-dependent hint. The returned list
475   /// may contain reserved registers that cannot be allocated.
476   ///
477   /// Register allocators need only call this function to resolve
478   /// target-dependent hints, but it should work without hinting as well.
479   virtual ArrayRef<unsigned>
480   getRawAllocationOrder(const TargetRegisterClass *RC,
481                         unsigned HintType, unsigned HintReg,
482                         const MachineFunction &MF) const {
483     return RC->getRawAllocationOrder(MF);
484   }
485
486   /// ResolveRegAllocHint - Resolves the specified register allocation hint
487   /// to a physical register. Returns the physical register if it is successful.
488   virtual unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg,
489                                        const MachineFunction &MF) const {
490     if (Type == 0 && Reg && isPhysicalRegister(Reg))
491       return Reg;
492     return 0;
493   }
494
495   /// avoidWriteAfterWrite - Return true if the register allocator should avoid
496   /// writing a register from RC in two consecutive instructions.
497   /// This can avoid pipeline stalls on certain architectures.
498   /// It does cause increased register pressure, though.
499   virtual bool avoidWriteAfterWrite(const TargetRegisterClass *RC) const {
500     return false;
501   }
502
503   /// UpdateRegAllocHint - A callback to allow target a chance to update
504   /// register allocation hints when a register is "changed" (e.g. coalesced)
505   /// to another register. e.g. On ARM, some virtual registers should target
506   /// register pairs, if one of pair is coalesced to another register, the
507   /// allocation hint of the other half of the pair should be changed to point
508   /// to the new register.
509   virtual void UpdateRegAllocHint(unsigned Reg, unsigned NewReg,
510                                   MachineFunction &MF) const {
511     // Do nothing.
512   }
513
514   /// requiresRegisterScavenging - returns true if the target requires (and can
515   /// make use of) the register scavenger.
516   virtual bool requiresRegisterScavenging(const MachineFunction &MF) const {
517     return false;
518   }
519
520   /// useFPForScavengingIndex - returns true if the target wants to use
521   /// frame pointer based accesses to spill to the scavenger emergency spill
522   /// slot.
523   virtual bool useFPForScavengingIndex(const MachineFunction &MF) const {
524     return true;
525   }
526
527   /// requiresFrameIndexScavenging - returns true if the target requires post
528   /// PEI scavenging of registers for materializing frame index constants.
529   virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const {
530     return false;
531   }
532
533   /// requiresVirtualBaseRegisters - Returns true if the target wants the
534   /// LocalStackAllocation pass to be run and virtual base registers
535   /// used for more efficient stack access.
536   virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const {
537     return false;
538   }
539
540   /// hasReservedSpillSlot - Return true if target has reserved a spill slot in
541   /// the stack frame of the given function for the specified register. e.g. On
542   /// x86, if the frame register is required, the first fixed stack object is
543   /// reserved as its spill slot. This tells PEI not to create a new stack frame
544   /// object for the given register. It should be called only after
545   /// processFunctionBeforeCalleeSavedScan().
546   virtual bool hasReservedSpillSlot(const MachineFunction &MF, unsigned Reg,
547                                     int &FrameIdx) const {
548     return false;
549   }
550
551   /// needsStackRealignment - true if storage within the function requires the
552   /// stack pointer to be aligned more than the normal calling convention calls
553   /// for.
554   virtual bool needsStackRealignment(const MachineFunction &MF) const {
555     return false;
556   }
557
558   /// getFrameIndexInstrOffset - Get the offset from the referenced frame
559   /// index in the instruction, if there is one.
560   virtual int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
561                                            int Idx) const {
562     return 0;
563   }
564
565   /// needsFrameBaseReg - Returns true if the instruction's frame index
566   /// reference would be better served by a base register other than FP
567   /// or SP. Used by LocalStackFrameAllocation to determine which frame index
568   /// references it should create new base registers for.
569   virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
570     return false;
571   }
572
573   /// materializeFrameBaseRegister - Insert defining instruction(s) for
574   /// BaseReg to be a pointer to FrameIdx before insertion point I.
575   virtual void materializeFrameBaseRegister(MachineBasicBlock *MBB,
576                                             unsigned BaseReg, int FrameIdx,
577                                             int64_t Offset) const {
578     assert(0 && "materializeFrameBaseRegister does not exist on this target");
579   }
580
581   /// resolveFrameIndex - Resolve a frame index operand of an instruction
582   /// to reference the indicated base register plus offset instead.
583   virtual void resolveFrameIndex(MachineBasicBlock::iterator I,
584                                  unsigned BaseReg, int64_t Offset) const {
585     assert(0 && "resolveFrameIndex does not exist on this target");
586   }
587
588   /// isFrameOffsetLegal - Determine whether a given offset immediate is
589   /// encodable to resolve a frame index.
590   virtual bool isFrameOffsetLegal(const MachineInstr *MI,
591                                   int64_t Offset) const {
592     assert(0 && "isFrameOffsetLegal does not exist on this target");
593     return false; // Must return a value in order to compile with VS 2005
594   }
595
596   /// eliminateCallFramePseudoInstr - This method is called during prolog/epilog
597   /// code insertion to eliminate call frame setup and destroy pseudo
598   /// instructions (but only if the Target is using them).  It is responsible
599   /// for eliminating these instructions, replacing them with concrete
600   /// instructions.  This method need only be implemented if using call frame
601   /// setup/destroy pseudo instructions.
602   ///
603   virtual void
604   eliminateCallFramePseudoInstr(MachineFunction &MF,
605                                 MachineBasicBlock &MBB,
606                                 MachineBasicBlock::iterator MI) const {
607     assert(0 && "Call Frame Pseudo Instructions do not exist on this target!");
608   }
609
610
611   /// saveScavengerRegister - Spill the register so it can be used by the
612   /// register scavenger. Return true if the register was spilled, false
613   /// otherwise. If this function does not spill the register, the scavenger
614   /// will instead spill it to the emergency spill slot.
615   ///
616   virtual bool saveScavengerRegister(MachineBasicBlock &MBB,
617                                      MachineBasicBlock::iterator I,
618                                      MachineBasicBlock::iterator &UseMI,
619                                      const TargetRegisterClass *RC,
620                                      unsigned Reg) const {
621     return false;
622   }
623
624   /// eliminateFrameIndex - This method must be overriden to eliminate abstract
625   /// frame indices from instructions which may use them.  The instruction
626   /// referenced by the iterator contains an MO_FrameIndex operand which must be
627   /// eliminated by this method.  This method may modify or replace the
628   /// specified instruction, as long as it keeps the iterator pointing at the
629   /// finished product. SPAdj is the SP adjustment due to call frame setup
630   /// instruction.
631   virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI,
632                                    int SPAdj, RegScavenger *RS=NULL) const = 0;
633
634   //===--------------------------------------------------------------------===//
635   /// Debug information queries.
636
637   /// getFrameRegister - This method should return the register used as a base
638   /// for values allocated in the current stack frame.
639   virtual unsigned getFrameRegister(const MachineFunction &MF) const = 0;
640
641   /// getCompactUnwindRegNum - This function maps the register to the number for
642   /// compact unwind encoding. Return -1 if the register isn't valid.
643   virtual int getCompactUnwindRegNum(unsigned, bool) const {
644     return -1;
645   }
646 };
647
648
649 // This is useful when building IndexedMaps keyed on virtual registers
650 struct VirtReg2IndexFunctor : public std::unary_function<unsigned, unsigned> {
651   unsigned operator()(unsigned Reg) const {
652     return TargetRegisterInfo::virtReg2Index(Reg);
653   }
654 };
655
656 /// getCommonSubClass - find the largest common subclass of A and B. Return NULL
657 /// if there is no common subclass.
658 const TargetRegisterClass *getCommonSubClass(const TargetRegisterClass *A,
659                                              const TargetRegisterClass *B);
660
661 /// PrintReg - Helper class for printing registers on a raw_ostream.
662 /// Prints virtual and physical registers with or without a TRI instance.
663 ///
664 /// The format is:
665 ///   %noreg          - NoRegister
666 ///   %vreg5          - a virtual register.
667 ///   %vreg5:sub_8bit - a virtual register with sub-register index (with TRI).
668 ///   %EAX            - a physical register
669 ///   %physreg17      - a physical register when no TRI instance given.
670 ///
671 /// Usage: OS << PrintReg(Reg, TRI) << '\n';
672 ///
673 class PrintReg {
674   const TargetRegisterInfo *TRI;
675   unsigned Reg;
676   unsigned SubIdx;
677 public:
678   PrintReg(unsigned reg, const TargetRegisterInfo *tri = 0, unsigned subidx = 0)
679     : TRI(tri), Reg(reg), SubIdx(subidx) {}
680   void print(raw_ostream&) const;
681 };
682
683 static inline raw_ostream &operator<<(raw_ostream &OS, const PrintReg &PR) {
684   PR.print(OS);
685   return OS;
686 }
687
688 } // End llvm namespace
689
690 #endif