ARMBaseRegisterInfo.h revision 65482b1bb873dd820f54a24a2f34bd65f2669e5c
12cfd52c507bd5790457a171eb9bcb39019cc6860Chris Lattner//===- 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" 19c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#include "ARMGenRegisterInfo.h.inc" 20c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 21c140c4803dc3e10e08138670829bc0494986abe9David Goodwinnamespace llvm { 22c140c4803dc3e10e08138670829bc0494986abe9David Goodwin class ARMSubtarget; 23db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin class ARMBaseInstrInfo; 24c140c4803dc3e10e08138670829bc0494986abe9David Goodwin class Type; 25c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 26c140c4803dc3e10e08138670829bc0494986abe9David Goodwin/// Register allocation hints. 27c140c4803dc3e10e08138670829bc0494986abe9David Goodwinnamespace ARMRI { 28c140c4803dc3e10e08138670829bc0494986abe9David Goodwin enum { 29c140c4803dc3e10e08138670829bc0494986abe9David Goodwin RegPairOdd = 1, 30c140c4803dc3e10e08138670829bc0494986abe9David Goodwin RegPairEven = 2 31c140c4803dc3e10e08138670829bc0494986abe9David Goodwin }; 32c140c4803dc3e10e08138670829bc0494986abe9David Goodwin} 33c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 34c140c4803dc3e10e08138670829bc0494986abe9David Goodwin/// isARMLowRegister - Returns true if the register is low register r0-r7. 35c140c4803dc3e10e08138670829bc0494986abe9David Goodwin/// 36c140c4803dc3e10e08138670829bc0494986abe9David Goodwinstatic inline bool isARMLowRegister(unsigned Reg) { 37c140c4803dc3e10e08138670829bc0494986abe9David Goodwin using namespace ARM; 38c140c4803dc3e10e08138670829bc0494986abe9David Goodwin switch (Reg) { 39c140c4803dc3e10e08138670829bc0494986abe9David Goodwin case R0: case R1: case R2: case R3: 40c140c4803dc3e10e08138670829bc0494986abe9David Goodwin case R4: case R5: case R6: case R7: 41c140c4803dc3e10e08138670829bc0494986abe9David Goodwin return true; 42c140c4803dc3e10e08138670829bc0494986abe9David Goodwin default: 43c140c4803dc3e10e08138670829bc0494986abe9David Goodwin return false; 44c140c4803dc3e10e08138670829bc0494986abe9David Goodwin } 45c140c4803dc3e10e08138670829bc0494986abe9David Goodwin} 46c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 474dbbe3433f7339ed277af55037ff6847f484e5abChris Lattnerclass ARMBaseRegisterInfo : public ARMGenRegisterInfo { 48c140c4803dc3e10e08138670829bc0494986abe9David Goodwinprotected: 49db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin const ARMBaseInstrInfo &TII; 50c140c4803dc3e10e08138670829bc0494986abe9David Goodwin const ARMSubtarget &STI; 51c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 52c140c4803dc3e10e08138670829bc0494986abe9David Goodwin /// FramePtr - ARM physical register used as frame ptr. 53c140c4803dc3e10e08138670829bc0494986abe9David Goodwin unsigned FramePtr; 54c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 5565482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach /// BasePtr - ARM physical register used as a base ptr in complex stack 5665482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach /// frames. I.e., when we need a 3rd base, not just SP and FP, due to 5765482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach /// variable size stack objects. 5865482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach unsigned BasePtr; 5965482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach 60db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin // Can be only subclassed. 61b5619f42f4fdf347380d28357549df09b9ca3946Evan Cheng explicit ARMBaseRegisterInfo(const ARMBaseInstrInfo &tii, 62b5619f42f4fdf347380d28357549df09b9ca3946Evan Cheng const ARMSubtarget &STI); 63db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 6477521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin // Return the opcode that implements 'Op', or 0 if no opcode 6577521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin unsigned getOpcode(int Op) const; 6677521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin 67db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwinpublic: 68c140c4803dc3e10e08138670829bc0494986abe9David Goodwin /// getRegisterNumbering - Given the enum value for some register, e.g. 698295d99bff6f8e3dfdfdaf1871cb72adab423f20Evan Cheng /// ARM::LR, return the number that it corresponds to (e.g. 14). It 708295d99bff6f8e3dfdfdaf1871cb72adab423f20Evan Cheng /// also returns true in isSPVFP if the register is a single precision 718295d99bff6f8e3dfdfdaf1871cb72adab423f20Evan Cheng /// VFP register. 728295d99bff6f8e3dfdfdaf1871cb72adab423f20Evan Cheng static unsigned getRegisterNumbering(unsigned RegEnum, bool *isSPVFP = 0); 73c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 74c140c4803dc3e10e08138670829bc0494986abe9David Goodwin /// Code Generation virtual methods... 75c140c4803dc3e10e08138670829bc0494986abe9David Goodwin const unsigned *getCalleeSavedRegs(const MachineFunction *MF = 0) const; 76c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 77c140c4803dc3e10e08138670829bc0494986abe9David Goodwin BitVector getReservedRegs(const MachineFunction &MF) const; 78c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 794f54c1293af174a8002db20faf7b4f82ba4e8514Evan Cheng /// getMatchingSuperRegClass - Return a subclass of the specified register 804f54c1293af174a8002db20faf7b4f82ba4e8514Evan Cheng /// class A so that each register in it has a sub-register of the 814f54c1293af174a8002db20faf7b4f82ba4e8514Evan Cheng /// specified sub-register index which is in the specified register class B. 824f54c1293af174a8002db20faf7b4f82ba4e8514Evan Cheng virtual const TargetRegisterClass * 834f54c1293af174a8002db20faf7b4f82ba4e8514Evan Cheng getMatchingSuperRegClass(const TargetRegisterClass *A, 844f54c1293af174a8002db20faf7b4f82ba4e8514Evan Cheng const TargetRegisterClass *B, unsigned Idx) const; 854f54c1293af174a8002db20faf7b4f82ba4e8514Evan Cheng 8691a74da036d3a9442953ae1de3e797a50da4ccf0Bob Wilson /// canCombineSubRegIndices - Given a register class and a list of 8791a74da036d3a9442953ae1de3e797a50da4ccf0Bob Wilson /// subregister indices, return true if it's possible to combine the 8891a74da036d3a9442953ae1de3e797a50da4ccf0Bob Wilson /// subregister indices into one that corresponds to a larger 8991a74da036d3a9442953ae1de3e797a50da4ccf0Bob Wilson /// subregister. Return the new subregister index by reference. Note the 9091a74da036d3a9442953ae1de3e797a50da4ccf0Bob Wilson /// new index may be zero if the given subregisters can be combined to 9191a74da036d3a9442953ae1de3e797a50da4ccf0Bob Wilson /// form the whole register. 9291a74da036d3a9442953ae1de3e797a50da4ccf0Bob Wilson virtual bool canCombineSubRegIndices(const TargetRegisterClass *RC, 9391a74da036d3a9442953ae1de3e797a50da4ccf0Bob Wilson SmallVectorImpl<unsigned> &SubIndices, 9491a74da036d3a9442953ae1de3e797a50da4ccf0Bob Wilson unsigned &NewSubIdx) const; 95b990a2f249196ad3e0cc451d40a45fc2f9278eafEvan Cheng 962cfd52c507bd5790457a171eb9bcb39019cc6860Chris Lattner const TargetRegisterClass *getPointerRegClass(unsigned Kind = 0) const; 97c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 98c140c4803dc3e10e08138670829bc0494986abe9David Goodwin std::pair<TargetRegisterClass::iterator,TargetRegisterClass::iterator> 99c140c4803dc3e10e08138670829bc0494986abe9David Goodwin getAllocationOrder(const TargetRegisterClass *RC, 100c140c4803dc3e10e08138670829bc0494986abe9David Goodwin unsigned HintType, unsigned HintReg, 101c140c4803dc3e10e08138670829bc0494986abe9David Goodwin const MachineFunction &MF) const; 102c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 103c140c4803dc3e10e08138670829bc0494986abe9David Goodwin unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg, 104c140c4803dc3e10e08138670829bc0494986abe9David Goodwin const MachineFunction &MF) const; 105c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 106c140c4803dc3e10e08138670829bc0494986abe9David Goodwin void UpdateRegAllocHint(unsigned Reg, unsigned NewReg, 107c140c4803dc3e10e08138670829bc0494986abe9David Goodwin MachineFunction &MF) const; 108c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 109c140c4803dc3e10e08138670829bc0494986abe9David Goodwin bool hasFP(const MachineFunction &MF) const; 11065482b1bb873dd820f54a24a2f34bd65f2669e5cJim Grosbach bool hasBasePointer(const MachineFunction &MF) const; 11198a0104014e9bb6ed89c2572f615351fd526674aEvan Cheng 112e45ab8a0a90e4f3a59d8c38038ae3e495ee1fef3Jim Grosbach bool canRealignStack(const MachineFunction &MF) const; 1133dab2778571b5bb00b35a0adcb7011dc85158bebJim Grosbach bool needsStackRealignment(const MachineFunction &MF) const; 1141ab3f16f06698596716593a30545799688acccd7Jim Grosbach int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const; 1153197380143cdc18837722129ac888528b9fbfc2bJim Grosbach bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const; 116dc140c6e7b8350ca51aa1d408c10e25a27826e2cJim Grosbach void materializeFrameBaseRegister(MachineBasicBlock::iterator I, 117e2f556933e1a19cddf6d4f370e2770c0f763b025Jim Grosbach unsigned BaseReg, int FrameIdx, 118e2f556933e1a19cddf6d4f370e2770c0f763b025Jim Grosbach int64_t Offset) const; 119dc140c6e7b8350ca51aa1d408c10e25a27826e2cJim Grosbach void resolveFrameIndex(MachineBasicBlock::iterator I, 120dc140c6e7b8350ca51aa1d408c10e25a27826e2cJim Grosbach unsigned BaseReg, int64_t Offset) const; 121e2f556933e1a19cddf6d4f370e2770c0f763b025Jim Grosbach bool isFrameOffsetLegal(const MachineInstr *MI, int64_t Offset) const; 1223dab2778571b5bb00b35a0adcb7011dc85158bebJim Grosbach 123010b1b9e7b11bced0b277a4d808226ba2af3044aEvan Cheng bool cannotEliminateFrame(const MachineFunction &MF) const; 124c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 125c140c4803dc3e10e08138670829bc0494986abe9David Goodwin void processFunctionBeforeCalleeSavedScan(MachineFunction &MF, 126c140c4803dc3e10e08138670829bc0494986abe9David Goodwin RegScavenger *RS = NULL) const; 127c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 128c140c4803dc3e10e08138670829bc0494986abe9David Goodwin // Debug information queries. 129c140c4803dc3e10e08138670829bc0494986abe9David Goodwin unsigned getRARegister() const; 130b9c2fd964ee7dd7823ac71db8443055e4d0f1c15David Greene unsigned getFrameRegister(const MachineFunction &MF) const; 13130c6b75ac2eef548c18110a38c9798ea5314cabaChris Lattner int getFrameIndexReference(const MachineFunction &MF, int FI, 13250f8516d2dd87e6c02a46fa349b75101f9db8619Jim Grosbach unsigned &FrameReg) const; 133e3ede5e2e4de6d028956c0b75c6bfa17ec50cc09Jim Grosbach int ResolveFrameIndexReference(const MachineFunction &MF, int FI, 134e3ede5e2e4de6d028956c0b75c6bfa17ec50cc09Jim Grosbach unsigned &FrameReg, int SPAdj) const; 13530c6b75ac2eef548c18110a38c9798ea5314cabaChris Lattner int getFrameIndexOffset(const MachineFunction &MF, int FI) const; 136c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 137c140c4803dc3e10e08138670829bc0494986abe9David Goodwin // Exception handling queries. 138c140c4803dc3e10e08138670829bc0494986abe9David Goodwin unsigned getEHExceptionRegister() const; 139c140c4803dc3e10e08138670829bc0494986abe9David Goodwin unsigned getEHHandlerRegister() const; 140c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 141c140c4803dc3e10e08138670829bc0494986abe9David Goodwin int getDwarfRegNum(unsigned RegNum, bool isEH) const; 142c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 143c140c4803dc3e10e08138670829bc0494986abe9David Goodwin bool isLowRegister(unsigned Reg) const; 144c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 145db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 146db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin /// emitLoadConstPool - Emits a load from constpool to materialize the 147db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin /// specified immediate. 148db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin virtual void emitLoadConstPool(MachineBasicBlock &MBB, 149db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin MachineBasicBlock::iterator &MBBI, 15077521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin DebugLoc dl, 151378445303b10b092a898a75131141a8259cff50bEvan Cheng unsigned DestReg, unsigned SubIdx, 152378445303b10b092a898a75131141a8259cff50bEvan Cheng int Val, 153db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin ARMCC::CondCodes Pred = ARMCC::AL, 154db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin unsigned PredReg = 0) const; 155db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 156db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin /// Code Generation virtual methods... 157db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin virtual bool isReservedReg(const MachineFunction &MF, unsigned Reg) const; 158db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 159db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin virtual bool requiresRegisterScavenging(const MachineFunction &MF) const; 160db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 1617e831db1d4f5dc51ca6526739cf41e59895c5c20Jim Grosbach virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const; 162a273442891ae20fd8192526132e3819ea9e5eda9Jim Grosbach 163a273442891ae20fd8192526132e3819ea9e5eda9Jim Grosbach virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const; 1647e831db1d4f5dc51ca6526739cf41e59895c5c20Jim Grosbach 16572852a8cfb605056d87b644d2e36b1346051413dEric Christopher virtual bool hasReservedCallFrame(const MachineFunction &MF) const; 16672852a8cfb605056d87b644d2e36b1346051413dEric Christopher virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const; 167db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 168db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin virtual void eliminateCallFramePseudoInstr(MachineFunction &MF, 16918f30e6f5e80787808fe1455742452a5210afe07Jim Grosbach MachineBasicBlock &MBB, 17018f30e6f5e80787808fe1455742452a5210afe07Jim Grosbach MachineBasicBlock::iterator I) const; 171db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 172fcb4a8ead3cd8d9540d5eaa448af5d14a0ee341aJim Grosbach virtual void eliminateFrameIndex(MachineBasicBlock::iterator II, 173fcb4a8ead3cd8d9540d5eaa448af5d14a0ee341aJim Grosbach int SPAdj, RegScavenger *RS = NULL) const; 174db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 175db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin virtual void emitPrologue(MachineFunction &MF) const; 176db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const; 177db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin 178c140c4803dc3e10e08138670829bc0494986abe9David Goodwinprivate: 179ee42fd309ee6a8febfafb97c2f3b6f2069758c5eEvan Cheng unsigned estimateRSStackSizeLimit(MachineFunction &MF) const; 180ee42fd309ee6a8febfafb97c2f3b6f2069758c5eEvan Cheng 181c140c4803dc3e10e08138670829bc0494986abe9David Goodwin unsigned getRegisterPairEven(unsigned Reg, const MachineFunction &MF) const; 182c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 183c140c4803dc3e10e08138670829bc0494986abe9David Goodwin unsigned getRegisterPairOdd(unsigned Reg, const MachineFunction &MF) const; 184c140c4803dc3e10e08138670829bc0494986abe9David Goodwin}; 185c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 186c140c4803dc3e10e08138670829bc0494986abe9David Goodwin} // end namespace llvm 187c140c4803dc3e10e08138670829bc0494986abe9David Goodwin 188c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#endif 189