Added support to fold X86 load / store instructions. This allow rematerialized loads...
[oota-llvm.git] / lib / Target / X86 / X86RegisterInfo.h
1 //===- X86RegisterInfo.h - X86 Register Information Impl --------*- C++ -*-===//
2 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the X86 implementation of the MRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef X86REGISTERINFO_H
15 #define X86REGISTERINFO_H
16
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Target/MRegisterInfo.h"
19 #include "X86GenRegisterInfo.h.inc"
20
21 namespace llvm {
22   class Type;
23   class TargetInstrInfo;
24   class X86TargetMachine;
25
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
34 class X86RegisterInfo : public X86GenRegisterInfo {
35 public:
36   X86TargetMachine &TM;
37   const TargetInstrInfo &TII;
38
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);
54
55   /// getX86RegNum - Returns the native X86 register number for the given LLVM
56   /// register identifier.
57   unsigned getX86RegNum(unsigned RegNo);
58
59   /// Code Generation virtual methods...
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
68   void storeRegToStackSlot(MachineBasicBlock &MBB,
69                            MachineBasicBlock::iterator MI,
70                            unsigned SrcReg, int FrameIndex,
71                            const TargetRegisterClass *RC) const;
72
73   void loadRegFromStackSlot(MachineBasicBlock &MBB,
74                             MachineBasicBlock::iterator MI,
75                             unsigned DestReg, int FrameIndex,
76                             const TargetRegisterClass *RC) const;
77
78   void copyRegToReg(MachineBasicBlock &MBB,
79                     MachineBasicBlock::iterator MI,
80                     unsigned DestReg, unsigned SrcReg,
81                     const TargetRegisterClass *RC) const;
82  
83   void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
84                      unsigned DestReg, const MachineInstr *Orig) const;
85
86   /// foldMemoryOperand - If this target supports it, fold a load or store of
87   /// the specified stack slot into the specified machine instruction for the
88   /// specified operand.  If this is possible, the target should perform the
89   /// folding and return true, otherwise it should return false.  If it folds
90   /// the instruction, it is likely that the MachineInstruction the iterator
91   /// references has been changed.
92   MachineInstr* foldMemoryOperand(MachineInstr* MI,
93                                   unsigned OpNum,
94                                   int FrameIndex) const;
95
96   /// foldMemoryOperand - Same as the previous version except it allows folding
97   /// of any load and store from / to any address, not just from a specific
98   /// stack slot.
99   MachineInstr* foldMemoryOperand(MachineInstr* MI,
100                                   unsigned OpNum,
101                                   MachineInstr* LoadMI) const;
102
103   /// getCalleeSavedRegs - Return a null-terminated list of all of the
104   /// callee-save registers on this target.
105   const unsigned *getCalleeSavedRegs(const MachineFunction* MF = 0) const;
106
107   /// getCalleeSavedRegClasses - Return a null-terminated list of the preferred
108   /// register classes to spill each callee-saved register with.  The order and
109   /// length of this list match the getCalleeSavedRegs() list.
110   const TargetRegisterClass* const*
111   getCalleeSavedRegClasses(const MachineFunction *MF = 0) const;
112
113   /// getReservedRegs - Returns a bitset indexed by physical register number
114   /// indicating if a register is a special register that has particular uses and
115   /// should be considered unavailable at all times, e.g. SP, RA. This is used by
116   /// register scavenger to determine what registers are free.
117   BitVector getReservedRegs(const MachineFunction &MF) const;
118
119   bool hasFP(const MachineFunction &MF) const;
120
121   bool hasReservedCallFrame(MachineFunction &MF) const;
122
123   void eliminateCallFramePseudoInstr(MachineFunction &MF,
124                                      MachineBasicBlock &MBB,
125                                      MachineBasicBlock::iterator MI) const;
126
127   void eliminateFrameIndex(MachineBasicBlock::iterator MI,
128                            int SPAdj, RegScavenger *RS = NULL) const;
129
130   void processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
131
132   void emitPrologue(MachineFunction &MF) const;
133   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
134
135   // Debug information queries.
136   unsigned getRARegister() const;
137   unsigned getFrameRegister(MachineFunction &MF) const;
138   void getInitialFrameState(std::vector<MachineMove> &Moves) const;
139
140   // Exception handling queries.
141   unsigned getEHExceptionRegister() const;
142   unsigned getEHHandlerRegister() const;
143
144 private:
145   MachineInstr* foldMemoryOperand(MachineInstr* MI,
146                                   unsigned OpNum,
147                                   SmallVector<MachineOperand,4> &MOs) const;
148 };
149
150 // getX86SubSuperRegister - X86 utility function. It returns the sub or super
151 // register of a specific X86 register.
152 // e.g. getX86SubSuperRegister(X86::EAX, MVT::i16) return X86:AX
153 unsigned getX86SubSuperRegister(unsigned, MVT::ValueType, bool High=false);
154
155 } // End llvm namespace
156
157 #endif