LLVM API Documentation
00001 //===-- ARMBaseRegisterInfo.h - ARM Register Information Impl ---*- 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 contains the base ARM implementation of TargetRegisterInfo class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_LIB_TARGET_ARM_ARMBASEREGISTERINFO_H 00015 #define LLVM_LIB_TARGET_ARM_ARMBASEREGISTERINFO_H 00016 00017 #include "MCTargetDesc/ARMBaseInfo.h" 00018 #include "llvm/Target/TargetRegisterInfo.h" 00019 00020 #define GET_REGINFO_HEADER 00021 #include "ARMGenRegisterInfo.inc" 00022 00023 namespace llvm { 00024 class ARMSubtarget; 00025 class ARMBaseInstrInfo; 00026 class Type; 00027 00028 /// Register allocation hints. 00029 namespace ARMRI { 00030 enum { 00031 RegPairOdd = 1, 00032 RegPairEven = 2 00033 }; 00034 } 00035 00036 /// isARMArea1Register - Returns true if the register is a low register (r0-r7) 00037 /// or a stack/pc register that we should push/pop. 00038 static inline bool isARMArea1Register(unsigned Reg, bool isIOS) { 00039 using namespace ARM; 00040 switch (Reg) { 00041 case R0: case R1: case R2: case R3: 00042 case R4: case R5: case R6: case R7: 00043 case LR: case SP: case PC: 00044 return true; 00045 case R8: case R9: case R10: case R11: case R12: 00046 // For iOS we want r7 and lr to be next to each other. 00047 return !isIOS; 00048 default: 00049 return false; 00050 } 00051 } 00052 00053 static inline bool isARMArea2Register(unsigned Reg, bool isIOS) { 00054 using namespace ARM; 00055 switch (Reg) { 00056 case R8: case R9: case R10: case R11: case R12: 00057 // iOS has this second area. 00058 return isIOS; 00059 default: 00060 return false; 00061 } 00062 } 00063 00064 static inline bool isARMArea3Register(unsigned Reg, bool isIOS) { 00065 using namespace ARM; 00066 switch (Reg) { 00067 case D15: case D14: case D13: case D12: 00068 case D11: case D10: case D9: case D8: 00069 return true; 00070 default: 00071 return false; 00072 } 00073 } 00074 00075 static inline bool isCalleeSavedRegister(unsigned Reg, 00076 const MCPhysReg *CSRegs) { 00077 for (unsigned i = 0; CSRegs[i]; ++i) 00078 if (Reg == CSRegs[i]) 00079 return true; 00080 return false; 00081 } 00082 00083 class ARMBaseRegisterInfo : public ARMGenRegisterInfo { 00084 protected: 00085 const ARMSubtarget &STI; 00086 00087 /// FramePtr - ARM physical register used as frame ptr. 00088 unsigned FramePtr; 00089 00090 /// BasePtr - ARM physical register used as a base ptr in complex stack 00091 /// frames. I.e., when we need a 3rd base, not just SP and FP, due to 00092 /// variable size stack objects. 00093 unsigned BasePtr; 00094 00095 // Can be only subclassed. 00096 explicit ARMBaseRegisterInfo(const ARMSubtarget &STI); 00097 00098 // Return the opcode that implements 'Op', or 0 if no opcode 00099 unsigned getOpcode(int Op) const; 00100 00101 public: 00102 /// Code Generation virtual methods... 00103 const MCPhysReg * 00104 getCalleeSavedRegs(const MachineFunction *MF = nullptr) const override; 00105 const uint32_t *getCallPreservedMask(CallingConv::ID) const override; 00106 const uint32_t *getNoPreservedMask() const; 00107 00108 /// getThisReturnPreservedMask - Returns a call preserved mask specific to the 00109 /// case that 'returned' is on an i32 first argument if the calling convention 00110 /// is one that can (partially) model this attribute with a preserved mask 00111 /// (i.e. it is a calling convention that uses the same register for the first 00112 /// i32 argument and an i32 return value) 00113 /// 00114 /// Should return NULL in the case that the calling convention does not have 00115 /// this property 00116 const uint32_t *getThisReturnPreservedMask(CallingConv::ID) const; 00117 00118 BitVector getReservedRegs(const MachineFunction &MF) const override; 00119 00120 const TargetRegisterClass * 00121 getPointerRegClass(const MachineFunction &MF, 00122 unsigned Kind = 0) const override; 00123 const TargetRegisterClass * 00124 getCrossCopyRegClass(const TargetRegisterClass *RC) const override; 00125 00126 const TargetRegisterClass * 00127 getLargestLegalSuperClass(const TargetRegisterClass *RC) const override; 00128 00129 unsigned getRegPressureLimit(const TargetRegisterClass *RC, 00130 MachineFunction &MF) const override; 00131 00132 void getRegAllocationHints(unsigned VirtReg, 00133 ArrayRef<MCPhysReg> Order, 00134 SmallVectorImpl<MCPhysReg> &Hints, 00135 const MachineFunction &MF, 00136 const VirtRegMap *VRM) const override; 00137 00138 void UpdateRegAllocHint(unsigned Reg, unsigned NewReg, 00139 MachineFunction &MF) const override; 00140 00141 bool avoidWriteAfterWrite(const TargetRegisterClass *RC) const override; 00142 00143 bool hasBasePointer(const MachineFunction &MF) const; 00144 00145 bool canRealignStack(const MachineFunction &MF) const; 00146 bool needsStackRealignment(const MachineFunction &MF) const override; 00147 int64_t getFrameIndexInstrOffset(const MachineInstr *MI, 00148 int Idx) const override; 00149 bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override; 00150 void materializeFrameBaseRegister(MachineBasicBlock *MBB, 00151 unsigned BaseReg, int FrameIdx, 00152 int64_t Offset) const override; 00153 void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg, 00154 int64_t Offset) const override; 00155 bool isFrameOffsetLegal(const MachineInstr *MI, 00156 int64_t Offset) const override; 00157 00158 bool cannotEliminateFrame(const MachineFunction &MF) const; 00159 00160 // Debug information queries. 00161 unsigned getFrameRegister(const MachineFunction &MF) const override; 00162 unsigned getBaseRegister() const { return BasePtr; } 00163 00164 bool isLowRegister(unsigned Reg) const; 00165 00166 00167 /// emitLoadConstPool - Emits a load from constpool to materialize the 00168 /// specified immediate. 00169 virtual void emitLoadConstPool(MachineBasicBlock &MBB, 00170 MachineBasicBlock::iterator &MBBI, 00171 DebugLoc dl, unsigned DestReg, unsigned SubIdx, 00172 int Val, ARMCC::CondCodes Pred = ARMCC::AL, 00173 unsigned PredReg = 0, 00174 unsigned MIFlags = MachineInstr::NoFlags)const; 00175 00176 /// Code Generation virtual methods... 00177 bool mayOverrideLocalAssignment() const override; 00178 00179 bool requiresRegisterScavenging(const MachineFunction &MF) const override; 00180 00181 bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override; 00182 00183 bool requiresFrameIndexScavenging(const MachineFunction &MF) const override; 00184 00185 bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override; 00186 00187 void eliminateFrameIndex(MachineBasicBlock::iterator II, 00188 int SPAdj, unsigned FIOperandNum, 00189 RegScavenger *RS = nullptr) const override; 00190 00191 /// \brief SrcRC and DstRC will be morphed into NewRC if this returns true 00192 bool shouldCoalesce(MachineInstr *MI, 00193 const TargetRegisterClass *SrcRC, 00194 unsigned SubReg, 00195 const TargetRegisterClass *DstRC, 00196 unsigned DstSubReg, 00197 const TargetRegisterClass *NewRC) const override; 00198 }; 00199 00200 } // end namespace llvm 00201 00202 #endif