LLVM API Documentation
00001 //=== Target/TargetRegisterInfo.h - Target Register Information -*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file describes an abstract interface used to get information about a 00011 // target machines register file. This information is used for a variety of 00012 // purposed, especially register allocation. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_TARGET_TARGETREGISTERINFO_H 00017 #define LLVM_TARGET_TARGETREGISTERINFO_H 00018 00019 #include "llvm/CodeGen/MachineBasicBlock.h" 00020 #include "llvm/CodeGen/ValueTypes.h" 00021 #include "llvm/ADT/DenseSet.h" 00022 #include <cassert> 00023 #include <functional> 00024 00025 namespace llvm { 00026 00027 class BitVector; 00028 class MachineFunction; 00029 class MachineMove; 00030 class RegScavenger; 00031 00032 /// TargetRegisterDesc - This record contains all of the information known about 00033 /// a particular register. The AliasSet field (if not null) contains a pointer 00034 /// to a Zero terminated array of registers that this register aliases. This is 00035 /// needed for architectures like X86 which have AL alias AX alias EAX. 00036 /// Registers that this does not apply to simply should set this to null. 00037 /// The SubRegs field is a zero terminated array of registers that are 00038 /// sub-registers of the specific register, e.g. AL, AH are sub-registers of AX. 00039 /// The SuperRegs field is a zero terminated array of registers that are 00040 /// super-registers of the specific register, e.g. RAX, EAX, are super-registers 00041 /// of AX. 00042 /// 00043 struct TargetRegisterDesc { 00044 const char *AsmName; // Assembly language name for the register 00045 const char *Name; // Printable name for the reg (for debugging) 00046 const unsigned *AliasSet; // Register Alias Set, described above 00047 const unsigned *SubRegs; // Sub-register set, described above 00048 const unsigned *SuperRegs; // Super-register set, described above 00049 }; 00050 00051 class TargetRegisterClass { 00052 public: 00053 typedef const unsigned* iterator; 00054 typedef const unsigned* const_iterator; 00055 00056 typedef const EVT* vt_iterator; 00057 typedef const TargetRegisterClass* const * sc_iterator; 00058 private: 00059 unsigned ID; 00060 const char *Name; 00061 const vt_iterator VTs; 00062 const sc_iterator SubClasses; 00063 const sc_iterator SuperClasses; 00064 const sc_iterator SubRegClasses; 00065 const sc_iterator SuperRegClasses; 00066 const unsigned RegSize, Alignment; // Size & Alignment of register in bytes 00067 const int CopyCost; 00068 const iterator RegsBegin, RegsEnd; 00069 DenseSet<unsigned> RegSet; 00070 public: 00071 TargetRegisterClass(unsigned id, 00072 const char *name, 00073 const EVT *vts, 00074 const TargetRegisterClass * const *subcs, 00075 const TargetRegisterClass * const *supcs, 00076 const TargetRegisterClass * const *subregcs, 00077 const TargetRegisterClass * const *superregcs, 00078 unsigned RS, unsigned Al, int CC, 00079 iterator RB, iterator RE) 00080 : ID(id), Name(name), VTs(vts), SubClasses(subcs), SuperClasses(supcs), 00081 SubRegClasses(subregcs), SuperRegClasses(superregcs), 00082 RegSize(RS), Alignment(Al), CopyCost(CC), RegsBegin(RB), RegsEnd(RE) { 00083 for (iterator I = RegsBegin, E = RegsEnd; I != E; ++I) 00084 RegSet.insert(*I); 00085 } 00086 virtual ~TargetRegisterClass() {} // Allow subclasses 00087 00088 /// getID() - Return the register class ID number. 00089 /// 00090 unsigned getID() const { return ID; } 00091 00092 /// getName() - Return the register class name for debugging. 00093 /// 00094 const char *getName() const { return Name; } 00095 00096 /// begin/end - Return all of the registers in this class. 00097 /// 00098 iterator begin() const { return RegsBegin; } 00099 iterator end() const { return RegsEnd; } 00100 00101 /// getNumRegs - Return the number of registers in this class. 00102 /// 00103 unsigned getNumRegs() const { return (unsigned)(RegsEnd-RegsBegin); } 00104 00105 /// getRegister - Return the specified register in the class. 00106 /// 00107 unsigned getRegister(unsigned i) const { 00108 assert(i < getNumRegs() && "Register number out of range!"); 00109 return RegsBegin[i]; 00110 } 00111 00112 /// contains - Return true if the specified register is included in this 00113 /// register class. 00114 bool contains(unsigned Reg) const { 00115 return RegSet.count(Reg); 00116 } 00117 00118 /// hasType - return true if this TargetRegisterClass has the ValueType vt. 00119 /// 00120 bool hasType(EVT vt) const { 00121 for(int i = 0; VTs[i].getSimpleVT().SimpleTy != MVT::Other; ++i) 00122 if (VTs[i] == vt) 00123 return true; 00124 return false; 00125 } 00126 00127 /// vt_begin / vt_end - Loop over all of the value types that can be 00128 /// represented by values in this register class. 00129 vt_iterator vt_begin() const { 00130 return VTs; 00131 } 00132 00133 vt_iterator vt_end() const { 00134 vt_iterator I = VTs; 00135 while (I->getSimpleVT().SimpleTy != MVT::Other) ++I; 00136 return I; 00137 } 00138 00139 /// subregclasses_begin / subregclasses_end - Loop over all of 00140 /// the subreg register classes of this register class. 00141 sc_iterator subregclasses_begin() const { 00142 return SubRegClasses; 00143 } 00144 00145 sc_iterator subregclasses_end() const { 00146 sc_iterator I = SubRegClasses; 00147 while (*I != NULL) ++I; 00148 return I; 00149 } 00150 00151 /// getSubRegisterRegClass - Return the register class of subregisters with 00152 /// index SubIdx, or NULL if no such class exists. 00153 const TargetRegisterClass* getSubRegisterRegClass(unsigned SubIdx) const { 00154 assert(SubIdx>0 && "Invalid subregister index"); 00155 for (unsigned s = 0; s != SubIdx-1; ++s) 00156 if (!SubRegClasses[s]) 00157 return NULL; 00158 return SubRegClasses[SubIdx-1]; 00159 } 00160 00161 /// superregclasses_begin / superregclasses_end - Loop over all of 00162 /// the superreg register classes of this register class. 00163 sc_iterator superregclasses_begin() const { 00164 return SuperRegClasses; 00165 } 00166 00167 sc_iterator superregclasses_end() const { 00168 sc_iterator I = SuperRegClasses; 00169 while (*I != NULL) ++I; 00170 return I; 00171 } 00172 00173 /// hasSubClass - return true if the the specified TargetRegisterClass 00174 /// is a proper subset of this TargetRegisterClass. 00175 bool hasSubClass(const TargetRegisterClass *cs) const { 00176 for (int i = 0; SubClasses[i] != NULL; ++i) 00177 if (SubClasses[i] == cs) 00178 return true; 00179 return false; 00180 } 00181 00182 /// subclasses_begin / subclasses_end - Loop over all of the classes 00183 /// that are proper subsets of this register class. 00184 sc_iterator subclasses_begin() const { 00185 return SubClasses; 00186 } 00187 00188 sc_iterator subclasses_end() const { 00189 sc_iterator I = SubClasses; 00190 while (*I != NULL) ++I; 00191 return I; 00192 } 00193 00194 /// hasSuperClass - return true if the specified TargetRegisterClass is a 00195 /// proper superset of this TargetRegisterClass. 00196 bool hasSuperClass(const TargetRegisterClass *cs) const { 00197 for (int i = 0; SuperClasses[i] != NULL; ++i) 00198 if (SuperClasses[i] == cs) 00199 return true; 00200 return false; 00201 } 00202 00203 /// superclasses_begin / superclasses_end - Loop over all of the classes 00204 /// that are proper supersets of this register class. 00205 sc_iterator superclasses_begin() const { 00206 return SuperClasses; 00207 } 00208 00209 sc_iterator superclasses_end() const { 00210 sc_iterator I = SuperClasses; 00211 while (*I != NULL) ++I; 00212 return I; 00213 } 00214 00215 /// isASubClass - return true if this TargetRegisterClass is a subset 00216 /// class of at least one other TargetRegisterClass. 00217 bool isASubClass() const { 00218 return SuperClasses[0] != 0; 00219 } 00220 00221 /// allocation_order_begin/end - These methods define a range of registers 00222 /// which specify the registers in this class that are valid to register 00223 /// allocate, and the preferred order to allocate them in. For example, 00224 /// callee saved registers should be at the end of the list, because it is 00225 /// cheaper to allocate caller saved registers. 00226 /// 00227 /// These methods take a MachineFunction argument, which can be used to tune 00228 /// the allocatable registers based on the characteristics of the function. 00229 /// One simple example is that the frame pointer register can be used if 00230 /// frame-pointer-elimination is performed. 00231 /// 00232 /// By default, these methods return all registers in the class. 00233 /// 00234 virtual iterator allocation_order_begin(const MachineFunction &MF) const { 00235 return begin(); 00236 } 00237 virtual iterator allocation_order_end(const MachineFunction &MF) const { 00238 return end(); 00239 } 00240 00241 /// getSize - Return the size of the register in bytes, which is also the size 00242 /// of a stack slot allocated to hold a spilled copy of this register. 00243 unsigned getSize() const { return RegSize; } 00244 00245 /// getAlignment - Return the minimum required alignment for a register of 00246 /// this class. 00247 unsigned getAlignment() const { return Alignment; } 00248 00249 /// getCopyCost - Return the cost of copying a value between two registers in 00250 /// this class. A negative number means the register class is very expensive 00251 /// to copy e.g. status flag register classes. 00252 int getCopyCost() const { return CopyCost; } 00253 }; 00254 00255 00256 /// TargetRegisterInfo base class - We assume that the target defines a static 00257 /// array of TargetRegisterDesc objects that represent all of the machine 00258 /// registers that the target has. As such, we simply have to track a pointer 00259 /// to this array so that we can turn register number into a register 00260 /// descriptor. 00261 /// 00262 class TargetRegisterInfo { 00263 protected: 00264 const unsigned* SubregHash; 00265 const unsigned SubregHashSize; 00266 const unsigned* SuperregHash; 00267 const unsigned SuperregHashSize; 00268 const unsigned* AliasesHash; 00269 const unsigned AliasesHashSize; 00270 public: 00271 typedef const TargetRegisterClass * const * regclass_iterator; 00272 private: 00273 const TargetRegisterDesc *Desc; // Pointer to the descriptor array 00274 unsigned NumRegs; // Number of entries in the array 00275 00276 regclass_iterator RegClassBegin, RegClassEnd; // List of regclasses 00277 00278 int CallFrameSetupOpcode, CallFrameDestroyOpcode; 00279 protected: 00280 TargetRegisterInfo(const TargetRegisterDesc *D, unsigned NR, 00281 regclass_iterator RegClassBegin, 00282 regclass_iterator RegClassEnd, 00283 int CallFrameSetupOpcode = -1, 00284 int CallFrameDestroyOpcode = -1, 00285 const unsigned* subregs = 0, 00286 const unsigned subregsize = 0, 00287 const unsigned* superregs = 0, 00288 const unsigned superregsize = 0, 00289 const unsigned* aliases = 0, 00290 const unsigned aliasessize = 0); 00291 virtual ~TargetRegisterInfo(); 00292 public: 00293 00294 enum { // Define some target independent constants 00295 /// NoRegister - This physical register is not a real target register. It 00296 /// is useful as a sentinal. 00297 NoRegister = 0, 00298 00299 /// FirstVirtualRegister - This is the first register number that is 00300 /// considered to be a 'virtual' register, which is part of the SSA 00301 /// namespace. This must be the same for all targets, which means that each 00302 /// target is limited to 1024 registers. 00303 FirstVirtualRegister = 1024 00304 }; 00305 00306 /// isPhysicalRegister - Return true if the specified register number is in 00307 /// the physical register namespace. 00308 static bool isPhysicalRegister(unsigned Reg) { 00309 assert(Reg && "this is not a register!"); 00310 return Reg < FirstVirtualRegister; 00311 } 00312 00313 /// isVirtualRegister - Return true if the specified register number is in 00314 /// the virtual register namespace. 00315 static bool isVirtualRegister(unsigned Reg) { 00316 assert(Reg && "this is not a register!"); 00317 return Reg >= FirstVirtualRegister; 00318 } 00319 00320 /// getPhysicalRegisterRegClass - Returns the Register Class of a physical 00321 /// register of the given type. If type is EVT::Other, then just return any 00322 /// register class the register belongs to. 00323 virtual const TargetRegisterClass * 00324 getPhysicalRegisterRegClass(unsigned Reg, EVT VT = MVT::Other) const; 00325 00326 /// getAllocatableSet - Returns a bitset indexed by register number 00327 /// indicating if a register is allocatable or not. If a register class is 00328 /// specified, returns the subset for the class. 00329 BitVector getAllocatableSet(MachineFunction &MF, 00330 const TargetRegisterClass *RC = NULL) const; 00331 00332 const TargetRegisterDesc &operator[](unsigned RegNo) const { 00333 assert(RegNo < NumRegs && 00334 "Attempting to access record for invalid register number!"); 00335 return Desc[RegNo]; 00336 } 00337 00338 /// Provide a get method, equivalent to [], but more useful if we have a 00339 /// pointer to this object. 00340 /// 00341 const TargetRegisterDesc &get(unsigned RegNo) const { 00342 return operator[](RegNo); 00343 } 00344 00345 /// getAliasSet - Return the set of registers aliased by the specified 00346 /// register, or a null list of there are none. The list returned is zero 00347 /// terminated. 00348 /// 00349 const unsigned *getAliasSet(unsigned RegNo) const { 00350 return get(RegNo).AliasSet; 00351 } 00352 00353 /// getSubRegisters - Return the list of registers that are sub-registers of 00354 /// the specified register, or a null list of there are none. The list 00355 /// returned is zero terminated and sorted according to super-sub register 00356 /// relations. e.g. X86::RAX's sub-register list is EAX, AX, AL, AH. 00357 /// 00358 const unsigned *getSubRegisters(unsigned RegNo) const { 00359 return get(RegNo).SubRegs; 00360 } 00361 00362 /// getSuperRegisters - Return the list of registers that are super-registers 00363 /// of the specified register, or a null list of there are none. The list 00364 /// returned is zero terminated and sorted according to super-sub register 00365 /// relations. e.g. X86::AL's super-register list is RAX, EAX, AX. 00366 /// 00367 const unsigned *getSuperRegisters(unsigned RegNo) const { 00368 return get(RegNo).SuperRegs; 00369 } 00370 00371 /// getAsmName - Return the symbolic target-specific name for the 00372 /// specified physical register. 00373 const char *getAsmName(unsigned RegNo) const { 00374 return get(RegNo).AsmName; 00375 } 00376 00377 /// getName - Return the human-readable symbolic target-specific name for the 00378 /// specified physical register. 00379 const char *getName(unsigned RegNo) const { 00380 return get(RegNo).Name; 00381 } 00382 00383 /// getNumRegs - Return the number of registers this target has (useful for 00384 /// sizing arrays holding per register information) 00385 unsigned getNumRegs() const { 00386 return NumRegs; 00387 } 00388 00389 /// regsOverlap - Returns true if the two registers are equal or alias each 00390 /// other. The registers may be virtual register. 00391 bool regsOverlap(unsigned regA, unsigned regB) const { 00392 if (regA == regB) 00393 return true; 00394 00395 if (isVirtualRegister(regA) || isVirtualRegister(regB)) 00396 return false; 00397 00398 // regA and regB are distinct physical registers. Do they alias? 00399 size_t index = (regA + regB * 37) & (AliasesHashSize-1); 00400 unsigned ProbeAmt = 0; 00401 while (AliasesHash[index*2] != 0 && 00402 AliasesHash[index*2+1] != 0) { 00403 if (AliasesHash[index*2] == regA && AliasesHash[index*2+1] == regB) 00404 return true; 00405 00406 index = (index + ProbeAmt) & (AliasesHashSize-1); 00407 ProbeAmt += 2; 00408 } 00409 00410 return false; 00411 } 00412 00413 /// isSubRegister - Returns true if regB is a sub-register of regA. 00414 /// 00415 bool isSubRegister(unsigned regA, unsigned regB) const { 00416 // SubregHash is a simple quadratically probed hash table. 00417 size_t index = (regA + regB * 37) & (SubregHashSize-1); 00418 unsigned ProbeAmt = 2; 00419 while (SubregHash[index*2] != 0 && 00420 SubregHash[index*2+1] != 0) { 00421 if (SubregHash[index*2] == regA && SubregHash[index*2+1] == regB) 00422 return true; 00423 00424 index = (index + ProbeAmt) & (SubregHashSize-1); 00425 ProbeAmt += 2; 00426 } 00427 00428 return false; 00429 } 00430 00431 /// isSuperRegister - Returns true if regB is a super-register of regA. 00432 /// 00433 bool isSuperRegister(unsigned regA, unsigned regB) const { 00434 // SuperregHash is a simple quadratically probed hash table. 00435 size_t index = (regA + regB * 37) & (SuperregHashSize-1); 00436 unsigned ProbeAmt = 2; 00437 while (SuperregHash[index*2] != 0 && 00438 SuperregHash[index*2+1] != 0) { 00439 if (SuperregHash[index*2] == regA && SuperregHash[index*2+1] == regB) 00440 return true; 00441 00442 index = (index + ProbeAmt) & (SuperregHashSize-1); 00443 ProbeAmt += 2; 00444 } 00445 00446 return false; 00447 } 00448 00449 /// getCalleeSavedRegs - Return a null-terminated list of all of the 00450 /// callee saved registers on this target. The register should be in the 00451 /// order of desired callee-save stack frame offset. The first register is 00452 /// closed to the incoming stack pointer if stack grows down, and vice versa. 00453 virtual const unsigned* getCalleeSavedRegs(const MachineFunction *MF = 0) 00454 const = 0; 00455 00456 /// getCalleeSavedRegClasses - Return a null-terminated list of the preferred 00457 /// register classes to spill each callee saved register with. The order and 00458 /// length of this list match the getCalleeSaveRegs() list. 00459 virtual const TargetRegisterClass* const *getCalleeSavedRegClasses( 00460 const MachineFunction *MF) const =0; 00461 00462 /// getReservedRegs - Returns a bitset indexed by physical register number 00463 /// indicating if a register is a special register that has particular uses 00464 /// and should be considered unavailable at all times, e.g. SP, RA. This is 00465 /// used by register scavenger to determine what registers are free. 00466 virtual BitVector getReservedRegs(const MachineFunction &MF) const = 0; 00467 00468 /// getSubReg - Returns the physical register number of sub-register "Index" 00469 /// for physical register RegNo. Return zero if the sub-register does not 00470 /// exist. 00471 virtual unsigned getSubReg(unsigned RegNo, unsigned Index) const = 0; 00472 00473 /// getMatchingSuperReg - Return a super-register of the specified register 00474 /// Reg so its sub-register of index SubIdx is Reg. 00475 unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx, 00476 const TargetRegisterClass *RC) const { 00477 for (const unsigned *SRs = getSuperRegisters(Reg); unsigned SR = *SRs;++SRs) 00478 if (Reg == getSubReg(SR, SubIdx) && RC->contains(SR)) 00479 return SR; 00480 return 0; 00481 } 00482 00483 /// getMatchingSuperRegClass - Return a subclass of the specified register 00484 /// class A so that each register in it has a sub-register of the 00485 /// specified sub-register index which is in the specified register class B. 00486 virtual const TargetRegisterClass * 00487 getMatchingSuperRegClass(const TargetRegisterClass *A, 00488 const TargetRegisterClass *B, unsigned Idx) const { 00489 return 0; 00490 } 00491 00492 //===--------------------------------------------------------------------===// 00493 // Register Class Information 00494 // 00495 00496 /// Register class iterators 00497 /// 00498 regclass_iterator regclass_begin() const { return RegClassBegin; } 00499 regclass_iterator regclass_end() const { return RegClassEnd; } 00500 00501 unsigned getNumRegClasses() const { 00502 return (unsigned)(regclass_end()-regclass_begin()); 00503 } 00504 00505 /// getRegClass - Returns the register class associated with the enumeration 00506 /// value. See class TargetOperandInfo. 00507 const TargetRegisterClass *getRegClass(unsigned i) const { 00508 assert(i <= getNumRegClasses() && "Register Class ID out of range"); 00509 return i ? RegClassBegin[i - 1] : NULL; 00510 } 00511 00512 /// getPointerRegClass - Returns a TargetRegisterClass used for pointer 00513 /// values. If a target supports multiple different pointer register classes, 00514 /// kind specifies which one is indicated. 00515 virtual const TargetRegisterClass *getPointerRegClass(unsigned Kind=0) const { 00516 assert(0 && "Target didn't implement getPointerRegClass!"); 00517 return 0; // Must return a value in order to compile with VS 2005 00518 } 00519 00520 /// getCrossCopyRegClass - Returns a legal register class to copy a register 00521 /// in the specified class to or from. Returns NULL if it is possible to copy 00522 /// between a two registers of the specified class. 00523 virtual const TargetRegisterClass * 00524 getCrossCopyRegClass(const TargetRegisterClass *RC) const { 00525 return NULL; 00526 } 00527 00528 /// getAllocationOrder - Returns the register allocation order for a specified 00529 /// register class in the form of a pair of TargetRegisterClass iterators. 00530 virtual std::pair<TargetRegisterClass::iterator,TargetRegisterClass::iterator> 00531 getAllocationOrder(const TargetRegisterClass *RC, 00532 unsigned HintType, unsigned HintReg, 00533 const MachineFunction &MF) const { 00534 return std::make_pair(RC->allocation_order_begin(MF), 00535 RC->allocation_order_end(MF)); 00536 } 00537 00538 /// ResolveRegAllocHint - Resolves the specified register allocation hint 00539 /// to a physical register. Returns the physical register if it is successful. 00540 virtual unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg, 00541 const MachineFunction &MF) const { 00542 if (Type == 0 && Reg && isPhysicalRegister(Reg)) 00543 return Reg; 00544 return 0; 00545 } 00546 00547 /// UpdateRegAllocHint - A callback to allow target a chance to update 00548 /// register allocation hints when a register is "changed" (e.g. coalesced) 00549 /// to another register. e.g. On ARM, some virtual registers should target 00550 /// register pairs, if one of pair is coalesced to another register, the 00551 /// allocation hint of the other half of the pair should be changed to point 00552 /// to the new register. 00553 virtual void UpdateRegAllocHint(unsigned Reg, unsigned NewReg, 00554 MachineFunction &MF) const { 00555 // Do nothing. 00556 } 00557 00558 /// targetHandlesStackFrameRounding - Returns true if the target is 00559 /// responsible for rounding up the stack frame (probably at emitPrologue 00560 /// time). 00561 virtual bool targetHandlesStackFrameRounding() const { 00562 return false; 00563 } 00564 00565 /// requiresRegisterScavenging - returns true if the target requires (and can 00566 /// make use of) the register scavenger. 00567 virtual bool requiresRegisterScavenging(const MachineFunction &MF) const { 00568 return false; 00569 } 00570 00571 /// hasFP - Return true if the specified function should have a dedicated 00572 /// frame pointer register. For most targets this is true only if the function 00573 /// has variable sized allocas or if frame pointer elimination is disabled. 00574 virtual bool hasFP(const MachineFunction &MF) const = 0; 00575 00576 /// hasReservedCallFrame - Under normal circumstances, when a frame pointer is 00577 /// not required, we reserve argument space for call sites in the function 00578 /// immediately on entry to the current function. This eliminates the need for 00579 /// add/sub sp brackets around call sites. Returns true if the call frame is 00580 /// included as part of the stack frame. 00581 virtual bool hasReservedCallFrame(MachineFunction &MF) const { 00582 return !hasFP(MF); 00583 } 00584 00585 /// hasReservedSpillSlot - Return true if target has reserved a spill slot in 00586 /// the stack frame of the given function for the specified register. e.g. On 00587 /// x86, if the frame register is required, the first fixed stack object is 00588 /// reserved as its spill slot. This tells PEI not to create a new stack frame 00589 /// object for the given register. It should be called only after 00590 /// processFunctionBeforeCalleeSavedScan(). 00591 virtual bool hasReservedSpillSlot(MachineFunction &MF, unsigned Reg, 00592 int &FrameIdx) const { 00593 return false; 00594 } 00595 00596 /// needsStackRealignment - true if storage within the function requires the 00597 /// stack pointer to be aligned more than the normal calling convention calls 00598 /// for. 00599 virtual bool needsStackRealignment(const MachineFunction &MF) const { 00600 return false; 00601 } 00602 00603 /// getCallFrameSetup/DestroyOpcode - These methods return the opcode of the 00604 /// frame setup/destroy instructions if they exist (-1 otherwise). Some 00605 /// targets use pseudo instructions in order to abstract away the difference 00606 /// between operating with a frame pointer and operating without, through the 00607 /// use of these two instructions. 00608 /// 00609 int getCallFrameSetupOpcode() const { return CallFrameSetupOpcode; } 00610 int getCallFrameDestroyOpcode() const { return CallFrameDestroyOpcode; } 00611 00612 /// eliminateCallFramePseudoInstr - This method is called during prolog/epilog 00613 /// code insertion to eliminate call frame setup and destroy pseudo 00614 /// instructions (but only if the Target is using them). It is responsible 00615 /// for eliminating these instructions, replacing them with concrete 00616 /// instructions. This method need only be implemented if using call frame 00617 /// setup/destroy pseudo instructions. 00618 /// 00619 virtual void 00620 eliminateCallFramePseudoInstr(MachineFunction &MF, 00621 MachineBasicBlock &MBB, 00622 MachineBasicBlock::iterator MI) const { 00623 assert(getCallFrameSetupOpcode()== -1 && getCallFrameDestroyOpcode()== -1 && 00624 "eliminateCallFramePseudoInstr must be implemented if using" 00625 " call frame setup/destroy pseudo instructions!"); 00626 assert(0 && "Call Frame Pseudo Instructions do not exist on this target!"); 00627 } 00628 00629 /// processFunctionBeforeCalleeSavedScan - This method is called immediately 00630 /// before PrologEpilogInserter scans the physical registers used to determine 00631 /// what callee saved registers should be spilled. This method is optional. 00632 virtual void processFunctionBeforeCalleeSavedScan(MachineFunction &MF, 00633 RegScavenger *RS = NULL) const { 00634 00635 } 00636 00637 /// processFunctionBeforeFrameFinalized - This method is called immediately 00638 /// before the specified functions frame layout (MF.getFrameInfo()) is 00639 /// finalized. Once the frame is finalized, MO_FrameIndex operands are 00640 /// replaced with direct constants. This method is optional. 00641 /// 00642 virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF) const { 00643 } 00644 00645 /// eliminateFrameIndex - This method must be overriden to eliminate abstract 00646 /// frame indices from instructions which may use them. The instruction 00647 /// referenced by the iterator contains an MO_FrameIndex operand which must be 00648 /// eliminated by this method. This method may modify or replace the 00649 /// specified instruction, as long as it keeps the iterator pointing the the 00650 /// finished product. SPAdj is the SP adjustment due to call frame setup 00651 /// instruction. 00652 virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI, 00653 int SPAdj, RegScavenger *RS=NULL) const = 0; 00654 00655 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into 00656 /// the function. 00657 virtual void emitPrologue(MachineFunction &MF) const = 0; 00658 virtual void emitEpilogue(MachineFunction &MF, 00659 MachineBasicBlock &MBB) const = 0; 00660 00661 //===--------------------------------------------------------------------===// 00662 /// Debug information queries. 00663 00664 /// getDwarfRegNum - Map a target register to an equivalent dwarf register 00665 /// number. Returns -1 if there is no equivalent value. The second 00666 /// parameter allows targets to use different numberings for EH info and 00667 /// debugging info. 00668 virtual int getDwarfRegNum(unsigned RegNum, bool isEH) const = 0; 00669 00670 /// getFrameRegister - This method should return the register used as a base 00671 /// for values allocated in the current stack frame. 00672 virtual unsigned getFrameRegister(MachineFunction &MF) const = 0; 00673 00674 /// getFrameIndexOffset - Returns the displacement from the frame register to 00675 /// the stack frame of the specified index. 00676 virtual int getFrameIndexOffset(MachineFunction &MF, int FI) const; 00677 00678 /// getRARegister - This method should return the register where the return 00679 /// address can be found. 00680 virtual unsigned getRARegister() const = 0; 00681 00682 /// getInitialFrameState - Returns a list of machine moves that are assumed 00683 /// on entry to all functions. Note that LabelID is ignored (assumed to be 00684 /// the beginning of the function.) 00685 virtual void getInitialFrameState(std::vector<MachineMove> &Moves) const; 00686 }; 00687 00688 00689 // This is useful when building IndexedMaps keyed on virtual registers 00690 struct VirtReg2IndexFunctor : std::unary_function<unsigned, unsigned> { 00691 unsigned operator()(unsigned Reg) const { 00692 return Reg - TargetRegisterInfo::FirstVirtualRegister; 00693 } 00694 }; 00695 00696 /// getCommonSubClass - find the largest common subclass of A and B. Return NULL 00697 /// if there is no common subclass. 00698 const TargetRegisterClass *getCommonSubClass(const TargetRegisterClass *A, 00699 const TargetRegisterClass *B); 00700 00701 } // End llvm namespace 00702 00703 #endif