blob: fd26d9fd7d1aba435c78bd43838564d609bf9d4e [file] [log] [blame]
Chris Lattner128aff42002-12-28 20:32:54 +00001//===- X86RegisterInfo.h - X86 Register Information Impl --------*- C++ -*-===//
Misha Brukman0e0a7a452005-04-21 23:38:14 +00002//
John Criswell856ba762003-10-21 15:17:13 +00003// 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 Brukman0e0a7a452005-04-21 23:38:14 +00007//
John Criswell856ba762003-10-21 15:17:13 +00008//===----------------------------------------------------------------------===//
Chris Lattner72614082002-10-25 22:55:53 +00009//
10// This file contains the X86 implementation of the MRegisterInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef X86REGISTERINFO_H
15#define X86REGISTERINFO_H
16
Evan Chengf4c3a592007-08-30 05:54:07 +000017#include "llvm/ADT/SmallVector.h"
Chris Lattner72614082002-10-25 22:55:53 +000018#include "llvm/Target/MRegisterInfo.h"
Chris Lattner7ad3e062003-08-03 15:48:14 +000019#include "X86GenRegisterInfo.h.inc"
20
Brian Gaeked0fde302003-11-11 22:41:34 +000021namespace llvm {
Chris Lattner29268692006-09-05 02:12:02 +000022 class Type;
23 class TargetInstrInfo;
Evan Cheng25ab6902006-09-08 06:48:29 +000024 class X86TargetMachine;
Brian Gaeked0fde302003-11-11 22:41:34 +000025
Duncan Sandsee465742007-08-29 19:01:20 +000026/// N86 namespace - Native X86 register numbers
27///
28namespace N86 {
29 enum {
30 EAX = 0, ECX = 1, EDX = 2, EBX = 3, ESP = 4, EBP = 5, ESI = 6, EDI = 7
31 };
32}
33
Jeff Cohend41b30d2006-11-05 19:31:28 +000034class X86RegisterInfo : public X86GenRegisterInfo {
35public:
Evan Cheng25ab6902006-09-08 06:48:29 +000036 X86TargetMachine &TM;
Chris Lattner29268692006-09-05 02:12:02 +000037 const TargetInstrInfo &TII;
Jeff Cohend41b30d2006-11-05 19:31:28 +000038
Evan Cheng25ab6902006-09-08 06:48:29 +000039private:
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
52public:
53 X86RegisterInfo(X86TargetMachine &tm, const TargetInstrInfo &tii);
Chris Lattner128aff42002-12-28 20:32:54 +000054
Duncan Sandsee465742007-08-29 19:01:20 +000055 /// getX86RegNum - Returns the native X86 register number for the given LLVM
56 /// register identifier.
57 unsigned getX86RegNum(unsigned RegNo);
58
Chris Lattner128aff42002-12-28 20:32:54 +000059 /// Code Generation virtual methods...
Evan Cheng89d16592007-07-17 07:59:08 +000060 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 Lattner01d0efb2004-08-15 22:15:11 +000068 void storeRegToStackSlot(MachineBasicBlock &MBB,
Alkis Evlogimenos024126e2004-02-12 08:11:04 +000069 MachineBasicBlock::iterator MI,
Chris Lattner97d5e642005-09-30 01:29:42 +000070 unsigned SrcReg, int FrameIndex,
71 const TargetRegisterClass *RC) const;
Chris Lattner01d0efb2004-08-15 22:15:11 +000072
73 void loadRegFromStackSlot(MachineBasicBlock &MBB,
74 MachineBasicBlock::iterator MI,
Chris Lattner97d5e642005-09-30 01:29:42 +000075 unsigned DestReg, int FrameIndex,
76 const TargetRegisterClass *RC) const;
Misha Brukman0e0a7a452005-04-21 23:38:14 +000077
Chris Lattner01d0efb2004-08-15 22:15:11 +000078 void copyRegToReg(MachineBasicBlock &MBB,
79 MachineBasicBlock::iterator MI,
80 unsigned DestReg, unsigned SrcReg,
Evan Cheng9efce632007-09-26 06:25:56 +000081 const TargetRegisterClass *DestRC,
82 const TargetRegisterClass *SrcRC) const;
Evan Chengbf2c8b32007-03-20 08:09:38 +000083
Evan Chengff110262007-09-26 21:31:07 +000084 const TargetRegisterClass *
85 getCrossCopyRegClass(const TargetRegisterClass *RC) const;
86
Evan Chengbf2c8b32007-03-20 08:09:38 +000087 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
88 unsigned DestReg, const MachineInstr *Orig) const;
Chris Lattner128aff42002-12-28 20:32:54 +000089
Chris Lattner5a051f62004-02-17 05:54:57 +000090 /// 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 Cheng0f3ac8d2006-05-18 00:12:58 +000096 MachineInstr* foldMemoryOperand(MachineInstr* MI,
97 unsigned OpNum,
98 int FrameIndex) const;
Alkis Evlogimenosb4998662004-02-17 04:33:18 +000099
Evan Chengf4c3a592007-08-30 05:54:07 +0000100 /// 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 Chengc2b861d2007-01-02 21:33:40 +0000107 /// getCalleeSavedRegs - Return a null-terminated list of all of the
Evan Cheng0f3ac8d2006-05-18 00:12:58 +0000108 /// callee-save registers on this target.
Anton Korobeynikov2365f512007-07-14 14:06:15 +0000109 const unsigned *getCalleeSavedRegs(const MachineFunction* MF = 0) const;
Evan Cheng0f3ac8d2006-05-18 00:12:58 +0000110
Evan Chengc2b861d2007-01-02 21:33:40 +0000111 /// getCalleeSavedRegClasses - Return a null-terminated list of the preferred
Evan Cheng0f3ac8d2006-05-18 00:12:58 +0000112 /// register classes to spill each callee-saved register with. The order and
Evan Chengc2b861d2007-01-02 21:33:40 +0000113 /// length of this list match the getCalleeSavedRegs() list.
Evan Cheng64d80e32007-07-19 01:14:50 +0000114 const TargetRegisterClass* const*
115 getCalleeSavedRegClasses(const MachineFunction *MF = 0) const;
Alkis Evlogimenosb4998662004-02-17 04:33:18 +0000116
Evan Chengb371f452007-02-19 21:49:54 +0000117 /// 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 Chengdc775402007-01-23 00:57:47 +0000123 bool hasFP(const MachineFunction &MF) const;
124
Evan Cheng7e7bbf82007-07-19 00:42:05 +0000125 bool hasReservedCallFrame(MachineFunction &MF) const;
126
Chris Lattnerbb07ef92004-02-14 19:49:54 +0000127 void eliminateCallFramePseudoInstr(MachineFunction &MF,
128 MachineBasicBlock &MBB,
129 MachineBasicBlock::iterator MI) const;
Chris Lattner128aff42002-12-28 20:32:54 +0000130
Evan Cheng5e6df462007-02-28 00:21:17 +0000131 void eliminateFrameIndex(MachineBasicBlock::iterator MI,
Evan Cheng97de9132007-05-01 09:13:03 +0000132 int SPAdj, RegScavenger *RS = NULL) const;
Chris Lattner128aff42002-12-28 20:32:54 +0000133
Chris Lattnerbb07ef92004-02-14 19:49:54 +0000134 void processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
Chris Lattner128aff42002-12-28 20:32:54 +0000135
Chris Lattnerbb07ef92004-02-14 19:49:54 +0000136 void emitPrologue(MachineFunction &MF) const;
137 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
Jim Laskeyf1d78e82006-03-23 18:12:57 +0000138
Jim Laskeya9979182006-03-28 13:48:33 +0000139 // Debug information queries.
Jim Laskey41886992006-04-07 16:34:46 +0000140 unsigned getRARegister() const;
Jim Laskeya9979182006-03-28 13:48:33 +0000141 unsigned getFrameRegister(MachineFunction &MF) const;
Jim Laskey0e410942007-01-24 19:15:24 +0000142 void getInitialFrameState(std::vector<MachineMove> &Moves) const;
Jim Laskey62819f32007-02-21 22:54:50 +0000143
144 // Exception handling queries.
145 unsigned getEHExceptionRegister() const;
146 unsigned getEHHandlerRegister() const;
Evan Chengf4c3a592007-08-30 05:54:07 +0000147
148private:
149 MachineInstr* foldMemoryOperand(MachineInstr* MI,
150 unsigned OpNum,
151 SmallVector<MachineOperand,4> &MOs) const;
Chris Lattner72614082002-10-25 22:55:53 +0000152};
153
Evan Cheng8f7f7122006-05-05 05:40:20 +0000154// 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
157unsigned getX86SubSuperRegister(unsigned, MVT::ValueType, bool High=false);
158
Brian Gaeked0fde302003-11-11 22:41:34 +0000159} // End llvm namespace
160
Chris Lattner72614082002-10-25 22:55:53 +0000161#endif