ARMBaseRegisterInfo.h revision 1b26fdbf1f01e90b803cc035b6b932cd95c76830
131d157ae1ac2cd9c787dc3c1d28e64c682803844Jia Liu//===-- ARMBaseRegisterInfo.h - ARM Register Information Impl ---*- C++ -*-===// 2c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// 3c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// The LLVM Compiler Infrastructure 4c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// 5c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// This file is distributed under the University of Illinois Open Source 6c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// License. See LICENSE.TXT for details. 7c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// 8c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//===----------------------------------------------------------------------===// 9c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// 10c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// This file contains the base ARM implementation of TargetRegisterInfo class. 11c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// 12c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//===----------------------------------------------------------------------===// 13c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 14c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#ifndef ARMBASEREGISTERINFO_H 15c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#define ARMBASEREGISTERINFO_H 16c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 17c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#include "ARM.h" 18c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#include "llvm/Target/TargetRegisterInfo.h" 1973f50d9bc3bd46cc0abeba9bb0d46977ba1aea42Evan Cheng 2073f50d9bc3bd46cc0abeba9bb0d46977ba1aea42Evan Cheng#define GET_REGINFO_HEADER 2173f50d9bc3bd46cc0abeba9bb0d46977ba1aea42Evan Cheng#include "ARMGenRegisterInfo.inc" 22c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 23c140c4803dc3e10e08138670829bc0494986abe9David Goodwinnamespace llvm { 24c140c4803dc3e10e08138670829bc0494986abe9David Goodwin class ARMSubtarget; 25db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin class ARMBaseInstrInfo; 26c140c4803dc3e10e08138670829bc0494986abe9David Goodwin class Type; 27c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 28c140c4803dc3e10e08138670829bc0494986abe9David Goodwin/// Register allocation hints. 29c140c4803dc3e10e08138670829bc0494986abe9David Goodwinnamespace ARMRI { 30c140c4803dc3e10e08138670829bc0494986abe9David Goodwin enum { 31c140c4803dc3e10e08138670829bc0494986abe9David Goodwin RegPairOdd = 1, 32c140c4803dc3e10e08138670829bc0494986abe9David Goodwin RegPairEven = 2 33c140c4803dc3e10e08138670829bc0494986abe9David Goodwin }; 34c140c4803dc3e10e08138670829bc0494986abe9David Goodwin} 35c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 368b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher/// isARMArea1Register - Returns true if the register is a low register (r0-r7) 378b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher/// or a stack/pc register that we should push/pop. 38afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Chengstatic inline bool isARMArea1Register(unsigned Reg, bool isIOS) { 398b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher using namespace ARM; 408b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher switch (Reg) { 418b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case R0: case R1: case R2: case R3: 428b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case R4: case R5: case R6: case R7: 438b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case LR: case SP: case PC: 448b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return true; 458b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case R8: case R9: case R10: case R11: 46afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Cheng // For iOS we want r7 and lr to be next to each other. 47afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Cheng return !isIOS; 488b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher default: 498b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return false; 508b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher } 518b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher} 528b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher 53afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Chengstatic inline bool isARMArea2Register(unsigned Reg, bool isIOS) { 548b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher using namespace ARM; 558b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher switch (Reg) { 568b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case R8: case R9: case R10: case R11: 57afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Cheng // iOS has this second area. 58afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Cheng return isIOS; 598b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher default: 608b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return false; 618b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher } 628b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher} 638b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher 64afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Chengstatic inline bool isARMArea3Register(unsigned Reg, bool isIOS) { 658b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher using namespace ARM; 668b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher switch (Reg) { 678b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case D15: case D14: case D13: case D12: 688b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case D11: case D10: case D9: case D8: 698b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return true; 708b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher default: 718b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return false; 728b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher } 738b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher} 748b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher 751b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendlingstatic inline bool isCalleeSavedRegister(unsigned Reg, 761b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling const MCPhysReg *CSRegs) { 771b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling for (unsigned i = 0; CSRegs[i]; ++i) 781b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling if (Reg == CSRegs[i]) 791b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling return true; 801b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling return false; 811b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling} 821b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling 834dbbe3433f7339ed277af55037ff6847f484e5abChris Lattnerclass ARMBaseRegisterInfo : public ARMGenRegisterInfo { 84c140c4803dc3e10e08138670829bc0494986abe9David Goodwinprotected: 85c140c4803dc3e10e08138670829bc0494986abe9David Goodwin const ARMSubtarget &STI; 86c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 87c140c4803dc3e10e08138670829bc0494986abe9David Goodwin /// FramePtr - ARM physical register used as frame ptr. 88c140c4803dc3e10e08138670829bc0494986abe9David Goodwin unsigned FramePtr; 89c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 9065482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach /// BasePtr - ARM physical register used as a base ptr in complex stack 9165482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach /// frames. I.e., when we need a 3rd base, not just SP and FP, due to 9265482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach /// variable size stack objects. 9365482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach unsigned BasePtr; 9465482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach 95db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin // Can be only subclassed. 9657148c166ab232191098492633c924fad9c44ef3Bill Wendling explicit ARMBaseRegisterInfo(const ARMSubtarget &STI); 97db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 9877521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin // Return the opcode that implements 'Op', or 0 if no opcode 9977521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin unsigned getOpcode(int Op) const; 10077521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin 101db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwinpublic: 102c140c4803dc3e10e08138670829bc0494986abe9David Goodwin /// Code Generation virtual methods... 103015f228861ef9b337366f92f637d4e8d624bb006Craig Topper const uint16_t *getCalleeSavedRegs(const MachineFunction *MF = 0) const; 1043ee7d15284f188672e9e429e9e5cf7b870698677Jakob Stoklund Olesen const uint32_t *getCallPreservedMask(CallingConv::ID) const; 105e7bd51980a1341fb60322e5922cfcc0c9b92b165Chad Rosier const uint32_t *getNoPreservedMask() const; 106c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 107165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// getThisReturnPreservedMask - Returns a call preserved mask specific to the 108165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// case that 'returned' is on an i32 first argument if the calling convention 109165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// is one that can (partially) model this attribute with a preserved mask 110165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// (i.e. it is a calling convention that uses the same register for the first 111165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// i32 argument and an i32 return value) 112165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// 113165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// Should return NULL in the case that the calling convention does not have 114165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// this property 1156b97ebe9a32342207b24a5f73ebbf3070ec8d189Stephen Lin const uint32_t *getThisReturnPreservedMask(CallingConv::ID) const; 1166b97ebe9a32342207b24a5f73ebbf3070ec8d189Stephen Lin 117c140c4803dc3e10e08138670829bc0494986abe9David Goodwin BitVector getReservedRegs(const MachineFunction &MF) const; 118c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 119397fc4874efe9c17e737d4c5c50bd19dc3bf27f5Jakob Stoklund Olesen const TargetRegisterClass* 120397fc4874efe9c17e737d4c5c50bd19dc3bf27f5Jakob Stoklund Olesen getPointerRegClass(const MachineFunction &MF, unsigned Kind = 0) const; 121342e3161d9dd4fa485b47788aa0266f9c91c3832Evan Cheng const TargetRegisterClass* 122342e3161d9dd4fa485b47788aa0266f9c91c3832Evan Cheng getCrossCopyRegClass(const TargetRegisterClass *RC) const; 123c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 124c9e5015dece0a1a73bec358e11bc87594831279dJakob Stoklund Olesen const TargetRegisterClass* 125c9e5015dece0a1a73bec358e11bc87594831279dJakob Stoklund Olesen getLargestLegalSuperClass(const TargetRegisterClass *RC) const; 126c9e5015dece0a1a73bec358e11bc87594831279dJakob Stoklund Olesen 127be2119e8e2bc7006cfd638a24367acbfda625d16Cameron Zwarich unsigned getRegPressureLimit(const TargetRegisterClass *RC, 128be2119e8e2bc7006cfd638a24367acbfda625d16Cameron Zwarich MachineFunction &MF) const; 129be2119e8e2bc7006cfd638a24367acbfda625d16Cameron Zwarich 130303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen void getRegAllocationHints(unsigned VirtReg, 131303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen ArrayRef<MCPhysReg> Order, 132303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen SmallVectorImpl<MCPhysReg> &Hints, 133303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen const MachineFunction &MF, 134303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen const VirtRegMap *VRM) const; 135303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen 136c140c4803dc3e10e08138670829bc0494986abe9David Goodwin void UpdateRegAllocHint(unsigned Reg, unsigned NewReg, 137c140c4803dc3e10e08138670829bc0494986abe9David Goodwin MachineFunction &MF) const; 138c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 139f6a4d3c2f3e1029af252a0f6999edfa3c2f326eeBob Wilson virtual bool avoidWriteAfterWrite(const TargetRegisterClass *RC) const; 140f6a4d3c2f3e1029af252a0f6999edfa3c2f326eeBob Wilson 14165482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach bool hasBasePointer(const MachineFunction &MF) const; 14298a0104014e9bb6ed89c2572f615351fd526674aEvan Cheng 143e45ab8a0a90e4f3a59d8c38038ae3e495ee1fef3Jim Grosbach bool canRealignStack(const MachineFunction &MF) const; 1443dab2778571b5bb00b35a0adcb7011dc85158bebJim Grosbach bool needsStackRealignment(const MachineFunction &MF) const; 1451ab3f16f06698596716593a30545799688acccd7Jim Grosbach int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const; 1463197380143cdc18837722129ac888528b9fbfc2bJim Grosbach bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const; 147976ef86689ed065361a748f81c44ca3510af2202Bill Wendling void materializeFrameBaseRegister(MachineBasicBlock *MBB, 148e2f556933e1a19cddf6d4f370e2770c0f763b025Jim Grosbach unsigned BaseReg, int FrameIdx, 149e2f556933e1a19cddf6d4f370e2770c0f763b025Jim Grosbach int64_t Offset) const; 150dc140c6e7b8350ca51aa1d408c10e25a27826e2cJim Grosbach void resolveFrameIndex(MachineBasicBlock::iterator I, 151dc140c6e7b8350ca51aa1d408c10e25a27826e2cJim Grosbach unsigned BaseReg, int64_t Offset) const; 152e2f556933e1a19cddf6d4f370e2770c0f763b025Jim Grosbach bool isFrameOffsetLegal(const MachineInstr *MI, int64_t Offset) const; 1533dab2778571b5bb00b35a0adcb7011dc85158bebJim Grosbach 154010b1b9e7b11bced0b277a4d808226ba2af3044aEvan Cheng bool cannotEliminateFrame(const MachineFunction &MF) const; 155c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 156c140c4803dc3e10e08138670829bc0494986abe9David Goodwin // Debug information queries. 157b9c2fd964ee7dd7823ac71db8443055e4d0f1c15David Greene unsigned getFrameRegister(const MachineFunction &MF) const; 15865a0adb5978d44c791d047cb44792785abf71e4bChris Lattner unsigned getBaseRegister() const { return BasePtr; } 159c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 160c140c4803dc3e10e08138670829bc0494986abe9David Goodwin bool isLowRegister(unsigned Reg) const; 161c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 162db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 163db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin /// emitLoadConstPool - Emits a load from constpool to materialize the 164db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin /// specified immediate. 165db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin virtual void emitLoadConstPool(MachineBasicBlock &MBB, 166db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin MachineBasicBlock::iterator &MBBI, 16777521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin DebugLoc dl, 168378445303b10b092a898a75131141a8259cff50bEvan Cheng unsigned DestReg, unsigned SubIdx, 169378445303b10b092a898a75131141a8259cff50bEvan Cheng int Val, 170db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin ARMCC::CondCodes Pred = ARMCC::AL, 1713daccd82d3151fa3629de430b55698a81084fc9eAnton Korobeynikov unsigned PredReg = 0, 1723daccd82d3151fa3629de430b55698a81084fc9eAnton Korobeynikov unsigned MIFlags = MachineInstr::NoFlags)const; 173db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 174db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin /// Code Generation virtual methods... 175db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin virtual bool requiresRegisterScavenging(const MachineFunction &MF) const; 176db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 1776a8c7bf8e72338e55f0f9583e1828f62da165d4aPreston Gurd virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const; 1786a8c7bf8e72338e55f0f9583e1828f62da165d4aPreston Gurd 1797e831db1d4f5dc51ca6526739cf41e59895c5c20Jim Grosbach virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const; 180a273442891ae20fd8192526132e3819ea9e5eda9Jim Grosbach 181a273442891ae20fd8192526132e3819ea9e5eda9Jim Grosbach virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const; 1827e831db1d4f5dc51ca6526739cf41e59895c5c20Jim Grosbach 183fcb4a8ead3cd8d9540d5eaa448af5d14a0ee341aJim Grosbach virtual void eliminateFrameIndex(MachineBasicBlock::iterator II, 184108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier int SPAdj, unsigned FIOperandNum, 185108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier RegScavenger *RS = NULL) const; 186c140c4803dc3e10e08138670829bc0494986abe9David Goodwin}; 187c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 188c140c4803dc3e10e08138670829bc0494986abe9David Goodwin} // end namespace llvm 189c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 190c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#endif 191