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 1437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#ifndef LLVM_LIB_TARGET_ARM_ARMBASEREGISTERINFO_H 1537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#define LLVM_LIB_TARGET_ARM_ARMBASEREGISTERINFO_H 16c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 1736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "MCTargetDesc/ARMBaseInfo.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/// Register allocation hints. 25c140c4803dc3e10e08138670829bc0494986abe9David Goodwinnamespace ARMRI { 26c140c4803dc3e10e08138670829bc0494986abe9David Goodwin enum { 27c140c4803dc3e10e08138670829bc0494986abe9David Goodwin RegPairOdd = 1, 28c140c4803dc3e10e08138670829bc0494986abe9David Goodwin RegPairEven = 2 29c140c4803dc3e10e08138670829bc0494986abe9David Goodwin }; 30c140c4803dc3e10e08138670829bc0494986abe9David Goodwin} 31c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 328b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher/// isARMArea1Register - Returns true if the register is a low register (r0-r7) 338b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher/// or a stack/pc register that we should push/pop. 34afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Chengstatic inline bool isARMArea1Register(unsigned Reg, bool isIOS) { 358b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher using namespace ARM; 368b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher switch (Reg) { 378b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case R0: case R1: case R2: case R3: 388b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case R4: case R5: case R6: case R7: 398b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case LR: case SP: case PC: 408b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return true; 4136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case R8: case R9: case R10: case R11: case R12: 42afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Cheng // For iOS we want r7 and lr to be next to each other. 43afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Cheng return !isIOS; 448b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher default: 458b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return false; 468b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher } 478b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher} 488b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher 49afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Chengstatic inline bool isARMArea2Register(unsigned Reg, bool isIOS) { 508b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher using namespace ARM; 518b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher switch (Reg) { 5236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case R8: case R9: case R10: case R11: case R12: 53afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Cheng // iOS has this second area. 54afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Cheng return isIOS; 558b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher default: 568b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return false; 578b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher } 588b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher} 598b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher 60afad0fe59a791cb4fd87fbd7ea2b1aba8d67a7afEvan Chengstatic inline bool isARMArea3Register(unsigned Reg, bool isIOS) { 618b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher using namespace ARM; 628b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher switch (Reg) { 638b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case D15: case D14: case D13: case D12: 648b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher case D11: case D10: case D9: case D8: 658b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return true; 668b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher default: 678b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher return false; 688b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher } 698b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher} 708b3ca6216d62bf3f729c2e122dcfeb7c4d7500dcEric Christopher 711b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendlingstatic inline bool isCalleeSavedRegister(unsigned Reg, 721b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling const MCPhysReg *CSRegs) { 731b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling for (unsigned i = 0; CSRegs[i]; ++i) 741b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling if (Reg == CSRegs[i]) 751b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling return true; 761b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling return false; 771b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling} 781b26fdbf1f01e90b803cc035b6b932cd95c76830Bill Wendling 794dbbe3433f7339ed277af55037ff6847f484e5abChris Lattnerclass ARMBaseRegisterInfo : public ARMGenRegisterInfo { 80c140c4803dc3e10e08138670829bc0494986abe9David Goodwinprotected: 8165482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach /// BasePtr - ARM physical register used as a base ptr in complex stack 8265482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach /// frames. I.e., when we need a 3rd base, not just SP and FP, due to 8365482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach /// variable size stack objects. 8465482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach unsigned BasePtr; 8565482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach 86db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin // Can be only subclassed. 874c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar explicit ARMBaseRegisterInfo(); 88db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 8977521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin // Return the opcode that implements 'Op', or 0 if no opcode 9077521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin unsigned getOpcode(int Op) const; 9177521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin 92db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwinpublic: 93c140c4803dc3e10e08138670829bc0494986abe9David Goodwin /// Code Generation virtual methods... 944c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override; 954c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar const uint32_t *getCallPreservedMask(const MachineFunction &MF, 964c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar CallingConv::ID) const override; 97cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar const uint32_t *getNoPreservedMask() const override; 98c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 99165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// getThisReturnPreservedMask - Returns a call preserved mask specific to the 100165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// case that 'returned' is on an i32 first argument if the calling convention 101165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// is one that can (partially) model this attribute with a preserved mask 102165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// (i.e. it is a calling convention that uses the same register for the first 103165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// i32 argument and an i32 return value) 104165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// 105165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// Should return NULL in the case that the calling convention does not have 106165a7a925d73286abfc826b3d6339843b02c09e0Stephen Lin /// this property 1074c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar const uint32_t *getThisReturnPreservedMask(const MachineFunction &MF, 1084c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar CallingConv::ID) const; 109c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 11036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines BitVector getReservedRegs(const MachineFunction &MF) const override; 111c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 11236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const TargetRegisterClass * 11336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines getPointerRegClass(const MachineFunction &MF, 11436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines unsigned Kind = 0) const override; 11536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const TargetRegisterClass * 11636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines getCrossCopyRegClass(const TargetRegisterClass *RC) const override; 11736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 11836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const TargetRegisterClass * 1194c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar getLargestLegalSuperClass(const TargetRegisterClass *RC, 1204c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar const MachineFunction &MF) const override; 121c9e5015dece0a1a73bec358e11bc87594831279dJakob Stoklund Olesen 122be2119e8e2bc7006cfd638a24367acbfda625d16Cameron Zwarich unsigned getRegPressureLimit(const TargetRegisterClass *RC, 12336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachineFunction &MF) const override; 124be2119e8e2bc7006cfd638a24367acbfda625d16Cameron Zwarich 125303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen void getRegAllocationHints(unsigned VirtReg, 126303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen ArrayRef<MCPhysReg> Order, 127303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen SmallVectorImpl<MCPhysReg> &Hints, 128303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen const MachineFunction &MF, 129cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar const VirtRegMap *VRM, 130cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar const LiveRegMatrix *Matrix) const override; 131303da1baf2a90d18a709f29f4f7cd0e1962be5f9Jakob Stoklund Olesen 132ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines void updateRegAllocHint(unsigned Reg, unsigned NewReg, 13336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachineFunction &MF) const override; 134c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 13565482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach bool hasBasePointer(const MachineFunction &MF) const; 13698a0104014e9bb6ed89c2572f615351fd526674aEvan Cheng 137cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar bool canRealignStack(const MachineFunction &MF) const override; 13836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int64_t getFrameIndexInstrOffset(const MachineInstr *MI, 13936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int Idx) const override; 14036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override; 141976ef86689ed065361a748f81c44ca3510af2202Bill Wendling void materializeFrameBaseRegister(MachineBasicBlock *MBB, 142e2f556933e1a19cddf6d4f370e2770c0f763b025Jim Grosbach unsigned BaseReg, int FrameIdx, 14336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int64_t Offset) const override; 14436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg, 14536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int64_t Offset) const override; 1464c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg, 14736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int64_t Offset) const override; 1483dab2778571b5bb00b35a0adcb7011dc85158bebJim Grosbach 149010b1b9e7b11bced0b277a4d808226ba2af3044aEvan Cheng bool cannotEliminateFrame(const MachineFunction &MF) const; 150c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 151c140c4803dc3e10e08138670829bc0494986abe9David Goodwin // Debug information queries. 15236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines unsigned getFrameRegister(const MachineFunction &MF) const override; 15365a0adb5978d44c791d047cb44792785abf71e4bChris Lattner unsigned getBaseRegister() const { return BasePtr; } 154c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 155c140c4803dc3e10e08138670829bc0494986abe9David Goodwin bool isLowRegister(unsigned Reg) const; 156c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 157db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 158db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin /// emitLoadConstPool - Emits a load from constpool to materialize the 159db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin /// specified immediate. 160db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin virtual void emitLoadConstPool(MachineBasicBlock &MBB, 161db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin MachineBasicBlock::iterator &MBBI, 16236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DebugLoc dl, unsigned DestReg, unsigned SubIdx, 16336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int Val, ARMCC::CondCodes Pred = ARMCC::AL, 1643daccd82d3151fa3629de430b55698a81084fc9eAnton Korobeynikov unsigned PredReg = 0, 1653daccd82d3151fa3629de430b55698a81084fc9eAnton Korobeynikov unsigned MIFlags = MachineInstr::NoFlags)const; 166db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 167db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin /// Code Generation virtual methods... 16836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool requiresRegisterScavenging(const MachineFunction &MF) const override; 169db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 17036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override; 1716a8c7bf8e72338e55f0f9583e1828f62da165d4aPreston Gurd 17236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool requiresFrameIndexScavenging(const MachineFunction &MF) const override; 173a273442891ae20fd8192526132e3819ea9e5eda9Jim Grosbach 17436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override; 1757e831db1d4f5dc51ca6526739cf41e59895c5c20Jim Grosbach 17636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void eliminateFrameIndex(MachineBasicBlock::iterator II, 17736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines int SPAdj, unsigned FIOperandNum, 178dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines RegScavenger *RS = nullptr) const override; 17937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines 18037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines /// \brief SrcRC and DstRC will be morphed into NewRC if this returns true 18137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines bool shouldCoalesce(MachineInstr *MI, 18237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines const TargetRegisterClass *SrcRC, 18337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines unsigned SubReg, 18437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines const TargetRegisterClass *DstRC, 18537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines unsigned DstSubReg, 18637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines const TargetRegisterClass *NewRC) const override; 187c140c4803dc3e10e08138670829bc0494986abe9David Goodwin}; 188c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 189c140c4803dc3e10e08138670829bc0494986abe9David Goodwin} // end namespace llvm 190c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 191c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#endif 192