Chris Lattner | 128aff4 | 2002-12-28 20:32:54 +0000 | [diff] [blame] | 1 | //===- X86RegisterInfo.h - X86 Register Information Impl --------*- C++ -*-===// |
Misha Brukman | 0e0a7a45 | 2005-04-21 23:38:14 +0000 | [diff] [blame] | 2 | // |
John Criswell | 856ba76 | 2003-10-21 15:17:13 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 0e0a7a45 | 2005-04-21 23:38:14 +0000 | [diff] [blame] | 7 | // |
John Criswell | 856ba76 | 2003-10-21 15:17:13 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file contains the X86 implementation of the MRegisterInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef X86REGISTERINFO_H |
| 15 | #define X86REGISTERINFO_H |
| 16 | |
Evan Cheng | f4c3a59 | 2007-08-30 05:54:07 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 18 | #include "llvm/Target/MRegisterInfo.h" |
Chris Lattner | 7ad3e06 | 2003-08-03 15:48:14 +0000 | [diff] [blame] | 19 | #include "X86GenRegisterInfo.h.inc" |
| 20 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 21 | namespace llvm { |
Chris Lattner | 2926869 | 2006-09-05 02:12:02 +0000 | [diff] [blame] | 22 | class Type; |
| 23 | class TargetInstrInfo; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 24 | class X86TargetMachine; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 25 | |
Duncan Sands | ee46574 | 2007-08-29 19:01:20 +0000 | [diff] [blame] | 26 | /// N86 namespace - Native X86 register numbers |
| 27 | /// |
| 28 | namespace N86 { |
| 29 | enum { |
| 30 | EAX = 0, ECX = 1, EDX = 2, EBX = 3, ESP = 4, EBP = 5, ESI = 6, EDI = 7 |
| 31 | }; |
| 32 | } |
| 33 | |
Jeff Cohen | d41b30d | 2006-11-05 19:31:28 +0000 | [diff] [blame] | 34 | class X86RegisterInfo : public X86GenRegisterInfo { |
| 35 | public: |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 36 | X86TargetMachine &TM; |
Chris Lattner | 2926869 | 2006-09-05 02:12:02 +0000 | [diff] [blame] | 37 | const TargetInstrInfo &TII; |
Jeff Cohen | d41b30d | 2006-11-05 19:31:28 +0000 | [diff] [blame] | 38 | |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 39 | private: |
| 40 | /// Is64Bit - Is the target 64-bits. |
| 41 | bool Is64Bit; |
| 42 | |
| 43 | /// SlotSize - Stack slot size in bytes. |
| 44 | unsigned SlotSize; |
| 45 | |
| 46 | /// StackPtr - X86 physical register used as stack ptr. |
| 47 | unsigned StackPtr; |
| 48 | |
| 49 | /// FramePtr - X86 physical register used as frame ptr. |
| 50 | unsigned FramePtr; |
| 51 | |
| 52 | public: |
| 53 | X86RegisterInfo(X86TargetMachine &tm, const TargetInstrInfo &tii); |
Chris Lattner | 128aff4 | 2002-12-28 20:32:54 +0000 | [diff] [blame] | 54 | |
Duncan Sands | ee46574 | 2007-08-29 19:01:20 +0000 | [diff] [blame] | 55 | /// getX86RegNum - Returns the native X86 register number for the given LLVM |
| 56 | /// register identifier. |
| 57 | unsigned getX86RegNum(unsigned RegNo); |
| 58 | |
Chris Lattner | 128aff4 | 2002-12-28 20:32:54 +0000 | [diff] [blame] | 59 | /// Code Generation virtual methods... |
Evan Cheng | 89d1659 | 2007-07-17 07:59:08 +0000 | [diff] [blame] | 60 | bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 61 | MachineBasicBlock::iterator MI, |
| 62 | const std::vector<CalleeSavedInfo> &CSI) const; |
| 63 | |
| 64 | bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 65 | MachineBasicBlock::iterator MI, |
| 66 | const std::vector<CalleeSavedInfo> &CSI) const; |
| 67 | |
Chris Lattner | 01d0efb | 2004-08-15 22:15:11 +0000 | [diff] [blame] | 68 | void storeRegToStackSlot(MachineBasicBlock &MBB, |
Alkis Evlogimenos | 024126e | 2004-02-12 08:11:04 +0000 | [diff] [blame] | 69 | MachineBasicBlock::iterator MI, |
Chris Lattner | 97d5e64 | 2005-09-30 01:29:42 +0000 | [diff] [blame] | 70 | unsigned SrcReg, int FrameIndex, |
| 71 | const TargetRegisterClass *RC) const; |
Chris Lattner | 01d0efb | 2004-08-15 22:15:11 +0000 | [diff] [blame] | 72 | |
| 73 | void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 74 | MachineBasicBlock::iterator MI, |
Chris Lattner | 97d5e64 | 2005-09-30 01:29:42 +0000 | [diff] [blame] | 75 | unsigned DestReg, int FrameIndex, |
| 76 | const TargetRegisterClass *RC) const; |
Misha Brukman | 0e0a7a45 | 2005-04-21 23:38:14 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 01d0efb | 2004-08-15 22:15:11 +0000 | [diff] [blame] | 78 | void copyRegToReg(MachineBasicBlock &MBB, |
| 79 | MachineBasicBlock::iterator MI, |
| 80 | unsigned DestReg, unsigned SrcReg, |
Evan Cheng | 9efce63 | 2007-09-26 06:25:56 +0000 | [diff] [blame] | 81 | const TargetRegisterClass *DestRC, |
| 82 | const TargetRegisterClass *SrcRC) const; |
Evan Cheng | bf2c8b3 | 2007-03-20 08:09:38 +0000 | [diff] [blame] | 83 | |
Evan Cheng | ff11026 | 2007-09-26 21:31:07 +0000 | [diff] [blame^] | 84 | const TargetRegisterClass * |
| 85 | getCrossCopyRegClass(const TargetRegisterClass *RC) const; |
| 86 | |
Evan Cheng | bf2c8b3 | 2007-03-20 08:09:38 +0000 | [diff] [blame] | 87 | void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, |
| 88 | unsigned DestReg, const MachineInstr *Orig) const; |
Chris Lattner | 128aff4 | 2002-12-28 20:32:54 +0000 | [diff] [blame] | 89 | |
Chris Lattner | 5a051f6 | 2004-02-17 05:54:57 +0000 | [diff] [blame] | 90 | /// foldMemoryOperand - If this target supports it, fold a load or store of |
| 91 | /// the specified stack slot into the specified machine instruction for the |
| 92 | /// specified operand. If this is possible, the target should perform the |
| 93 | /// folding and return true, otherwise it should return false. If it folds |
| 94 | /// the instruction, it is likely that the MachineInstruction the iterator |
| 95 | /// references has been changed. |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 96 | MachineInstr* foldMemoryOperand(MachineInstr* MI, |
| 97 | unsigned OpNum, |
| 98 | int FrameIndex) const; |
Alkis Evlogimenos | b499866 | 2004-02-17 04:33:18 +0000 | [diff] [blame] | 99 | |
Evan Cheng | f4c3a59 | 2007-08-30 05:54:07 +0000 | [diff] [blame] | 100 | /// foldMemoryOperand - Same as the previous version except it allows folding |
| 101 | /// of any load and store from / to any address, not just from a specific |
| 102 | /// stack slot. |
| 103 | MachineInstr* foldMemoryOperand(MachineInstr* MI, |
| 104 | unsigned OpNum, |
| 105 | MachineInstr* LoadMI) const; |
| 106 | |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame] | 107 | /// getCalleeSavedRegs - Return a null-terminated list of all of the |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 108 | /// callee-save registers on this target. |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 109 | const unsigned *getCalleeSavedRegs(const MachineFunction* MF = 0) const; |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 110 | |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame] | 111 | /// getCalleeSavedRegClasses - Return a null-terminated list of the preferred |
Evan Cheng | 0f3ac8d | 2006-05-18 00:12:58 +0000 | [diff] [blame] | 112 | /// register classes to spill each callee-saved register with. The order and |
Evan Cheng | c2b861d | 2007-01-02 21:33:40 +0000 | [diff] [blame] | 113 | /// length of this list match the getCalleeSavedRegs() list. |
Evan Cheng | 64d80e3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 114 | const TargetRegisterClass* const* |
| 115 | getCalleeSavedRegClasses(const MachineFunction *MF = 0) const; |
Alkis Evlogimenos | b499866 | 2004-02-17 04:33:18 +0000 | [diff] [blame] | 116 | |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 117 | /// getReservedRegs - Returns a bitset indexed by physical register number |
| 118 | /// indicating if a register is a special register that has particular uses and |
| 119 | /// should be considered unavailable at all times, e.g. SP, RA. This is used by |
| 120 | /// register scavenger to determine what registers are free. |
| 121 | BitVector getReservedRegs(const MachineFunction &MF) const; |
| 122 | |
Evan Cheng | dc77540 | 2007-01-23 00:57:47 +0000 | [diff] [blame] | 123 | bool hasFP(const MachineFunction &MF) const; |
| 124 | |
Evan Cheng | 7e7bbf8 | 2007-07-19 00:42:05 +0000 | [diff] [blame] | 125 | bool hasReservedCallFrame(MachineFunction &MF) const; |
| 126 | |
Chris Lattner | bb07ef9 | 2004-02-14 19:49:54 +0000 | [diff] [blame] | 127 | void eliminateCallFramePseudoInstr(MachineFunction &MF, |
| 128 | MachineBasicBlock &MBB, |
| 129 | MachineBasicBlock::iterator MI) const; |
Chris Lattner | 128aff4 | 2002-12-28 20:32:54 +0000 | [diff] [blame] | 130 | |
Evan Cheng | 5e6df46 | 2007-02-28 00:21:17 +0000 | [diff] [blame] | 131 | void eliminateFrameIndex(MachineBasicBlock::iterator MI, |
Evan Cheng | 97de913 | 2007-05-01 09:13:03 +0000 | [diff] [blame] | 132 | int SPAdj, RegScavenger *RS = NULL) const; |
Chris Lattner | 128aff4 | 2002-12-28 20:32:54 +0000 | [diff] [blame] | 133 | |
Chris Lattner | bb07ef9 | 2004-02-14 19:49:54 +0000 | [diff] [blame] | 134 | void processFunctionBeforeFrameFinalized(MachineFunction &MF) const; |
Chris Lattner | 128aff4 | 2002-12-28 20:32:54 +0000 | [diff] [blame] | 135 | |
Chris Lattner | bb07ef9 | 2004-02-14 19:49:54 +0000 | [diff] [blame] | 136 | void emitPrologue(MachineFunction &MF) const; |
| 137 | void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const; |
Jim Laskey | f1d78e8 | 2006-03-23 18:12:57 +0000 | [diff] [blame] | 138 | |
Jim Laskey | a997918 | 2006-03-28 13:48:33 +0000 | [diff] [blame] | 139 | // Debug information queries. |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 140 | unsigned getRARegister() const; |
Jim Laskey | a997918 | 2006-03-28 13:48:33 +0000 | [diff] [blame] | 141 | unsigned getFrameRegister(MachineFunction &MF) const; |
Jim Laskey | 0e41094 | 2007-01-24 19:15:24 +0000 | [diff] [blame] | 142 | void getInitialFrameState(std::vector<MachineMove> &Moves) const; |
Jim Laskey | 62819f3 | 2007-02-21 22:54:50 +0000 | [diff] [blame] | 143 | |
| 144 | // Exception handling queries. |
| 145 | unsigned getEHExceptionRegister() const; |
| 146 | unsigned getEHHandlerRegister() const; |
Evan Cheng | f4c3a59 | 2007-08-30 05:54:07 +0000 | [diff] [blame] | 147 | |
| 148 | private: |
| 149 | MachineInstr* foldMemoryOperand(MachineInstr* MI, |
| 150 | unsigned OpNum, |
| 151 | SmallVector<MachineOperand,4> &MOs) const; |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
Evan Cheng | 8f7f712 | 2006-05-05 05:40:20 +0000 | [diff] [blame] | 154 | // getX86SubSuperRegister - X86 utility function. It returns the sub or super |
| 155 | // register of a specific X86 register. |
| 156 | // e.g. getX86SubSuperRegister(X86::EAX, MVT::i16) return X86:AX |
| 157 | unsigned getX86SubSuperRegister(unsigned, MVT::ValueType, bool High=false); |
| 158 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 159 | } // End llvm namespace |
| 160 | |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 161 | #endif |