Hide the call to InitMCInstrInfo into tblgen generated ctor.
[oota-llvm.git] / lib / Target / Mips / MipsInstrInfo.h
1 //===- MipsInstrInfo.h - Mips Instruction Information -----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the Mips implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef MIPSINSTRUCTIONINFO_H
15 #define MIPSINSTRUCTIONINFO_H
16
17 #include "Mips.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Target/TargetInstrInfo.h"
20 #include "MipsRegisterInfo.h"
21
22 #define GET_INSTRINFO_HEADER
23 #include "MipsGenInstrInfo.inc"
24
25 namespace llvm {
26
27 namespace Mips {
28
29   // Mips Branch Codes
30   enum FPBranchCode {
31     BRANCH_F,
32     BRANCH_T,
33     BRANCH_FL,
34     BRANCH_TL,
35     BRANCH_INVALID
36   };
37
38   // Mips Condition Codes
39   enum CondCode {
40     // To be used with float branch True
41     FCOND_F,
42     FCOND_UN,
43     FCOND_OEQ,
44     FCOND_UEQ,
45     FCOND_OLT,
46     FCOND_ULT,
47     FCOND_OLE,
48     FCOND_ULE,
49     FCOND_SF,
50     FCOND_NGLE,
51     FCOND_SEQ,
52     FCOND_NGL,
53     FCOND_LT,
54     FCOND_NGE,
55     FCOND_LE,
56     FCOND_NGT,
57
58     // To be used with float branch False
59     // This conditions have the same mnemonic as the
60     // above ones, but are used with a branch False;
61     FCOND_T,
62     FCOND_OR,
63     FCOND_UNE,
64     FCOND_ONE,
65     FCOND_UGE,
66     FCOND_OGE,
67     FCOND_UGT,
68     FCOND_OGT,
69     FCOND_ST,
70     FCOND_GLE,
71     FCOND_SNE,
72     FCOND_GL,
73     FCOND_NLT,
74     FCOND_GE,
75     FCOND_NLE,
76     FCOND_GT
77   };
78
79   /// GetOppositeBranchOpc - Return the inverse of the specified
80   /// opcode, e.g. turning BEQ to BNE.
81   unsigned GetOppositeBranchOpc(unsigned Opc);
82
83   /// MipsCCToString - Map each FP condition code to its string
84   inline static const char *MipsFCCToString(Mips::CondCode CC)
85   {
86     switch (CC) {
87       default: llvm_unreachable("Unknown condition code");
88       case FCOND_F:
89       case FCOND_T:   return "f";
90       case FCOND_UN:
91       case FCOND_OR:  return "un";
92       case FCOND_OEQ:
93       case FCOND_UNE: return "eq";
94       case FCOND_UEQ:
95       case FCOND_ONE: return "ueq";
96       case FCOND_OLT:
97       case FCOND_UGE: return "olt";
98       case FCOND_ULT:
99       case FCOND_OGE: return "ult";
100       case FCOND_OLE:
101       case FCOND_UGT: return "ole";
102       case FCOND_ULE:
103       case FCOND_OGT: return "ule";
104       case FCOND_SF:
105       case FCOND_ST:  return "sf";
106       case FCOND_NGLE:
107       case FCOND_GLE: return "ngle";
108       case FCOND_SEQ:
109       case FCOND_SNE: return "seq";
110       case FCOND_NGL:
111       case FCOND_GL:  return "ngl";
112       case FCOND_LT:
113       case FCOND_NLT: return "lt";
114       case FCOND_NGE:
115       case FCOND_GE:  return "nge";
116       case FCOND_LE:
117       case FCOND_NLE: return "le";
118       case FCOND_NGT:
119       case FCOND_GT:  return "ngt";
120     }
121   }
122 }
123
124 /// MipsII - This namespace holds all of the target specific flags that
125 /// instruction info tracks.
126 ///
127 namespace MipsII {
128   /// Target Operand Flag enum.
129   enum TOF {
130     //===------------------------------------------------------------------===//
131     // Mips Specific MachineOperand flags.
132
133     MO_NO_FLAG,
134
135     /// MO_GOT - Represents the offset into the global offset table at which
136     /// the address the relocation entry symbol resides during execution.
137     MO_GOT,
138
139     /// MO_GOT_CALL - Represents the offset into the global offset table at
140     /// which the address of a call site relocation entry symbol resides
141     /// during execution. This is different from the above since this flag
142     /// can only be present in call instructions.
143     MO_GOT_CALL,
144
145     /// MO_GPREL - Represents the offset from the current gp value to be used
146     /// for the relocatable object file being produced.
147     MO_GPREL,
148
149     /// MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol
150     /// address.
151     MO_ABS_HI,
152     MO_ABS_LO,
153
154     /// MO_TLSGD - Represents the offset into the global offset table at which
155     // the module ID and TSL block offset reside during execution (General
156     // Dynamic TLS).
157     MO_TLSGD,
158
159     /// MO_GOTTPREL - Represents the offset from the thread pointer (Initial
160     // Exec TLS).
161     MO_GOTTPREL,
162
163     /// MO_TPREL_HI/LO - Represents the hi and low part of the offset from
164     // the thread pointer (Local Exec TLS).
165     MO_TPREL_HI,
166     MO_TPREL_LO
167   };
168 }
169
170 class MipsInstrInfo : public MipsGenInstrInfo {
171   MipsTargetMachine &TM;
172   const MipsRegisterInfo RI;
173 public:
174   explicit MipsInstrInfo(MipsTargetMachine &TM);
175
176   /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
177   /// such, whenever a client has an instance of instruction info, it should
178   /// always be able to get register info as well (through this method).
179   ///
180   virtual const MipsRegisterInfo &getRegisterInfo() const { return RI; }
181
182   /// isLoadFromStackSlot - If the specified machine instruction is a direct
183   /// load from a stack slot, return the virtual or physical register number of
184   /// the destination along with the FrameIndex of the loaded stack slot.  If
185   /// not, return 0.  This predicate must return 0 if the instruction has
186   /// any side effects other than loading from the stack slot.
187   virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
188                                        int &FrameIndex) const;
189
190   /// isStoreToStackSlot - If the specified machine instruction is a direct
191   /// store to a stack slot, return the virtual or physical register number of
192   /// the source reg along with the FrameIndex of the loaded stack slot.  If
193   /// not, return 0.  This predicate must return 0 if the instruction has
194   /// any side effects other than storing to the stack slot.
195   virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
196                                       int &FrameIndex) const;
197
198   /// Branch Analysis
199   virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
200                              MachineBasicBlock *&FBB,
201                              SmallVectorImpl<MachineOperand> &Cond,
202                              bool AllowModify) const;
203   virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
204
205 private:
206   void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
207                    const SmallVectorImpl<MachineOperand>& Cond) const;
208
209 public:
210   virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
211                                 MachineBasicBlock *FBB,
212                                 const SmallVectorImpl<MachineOperand> &Cond,
213                                 DebugLoc DL) const;
214   virtual void copyPhysReg(MachineBasicBlock &MBB,
215                            MachineBasicBlock::iterator MI, DebugLoc DL,
216                            unsigned DestReg, unsigned SrcReg,
217                            bool KillSrc) const;
218   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
219                                    MachineBasicBlock::iterator MBBI,
220                                    unsigned SrcReg, bool isKill, int FrameIndex,
221                                    const TargetRegisterClass *RC,
222                                    const TargetRegisterInfo *TRI) const;
223
224   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
225                                     MachineBasicBlock::iterator MBBI,
226                                     unsigned DestReg, int FrameIndex,
227                                     const TargetRegisterClass *RC,
228                                     const TargetRegisterInfo *TRI) const;
229
230   virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
231                                                  int FrameIx, uint64_t Offset,
232                                                  const MDNode *MDPtr,
233                                                  DebugLoc DL) const;
234
235   virtual
236   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
237
238   /// Insert nop instruction when hazard condition is found
239   virtual void insertNoop(MachineBasicBlock &MBB,
240                           MachineBasicBlock::iterator MI) const;
241
242   /// getGlobalBaseReg - Return a virtual register initialized with the
243   /// the global base register value. Output instructions required to
244   /// initialize the register in the function entry block, if necessary.
245   ///
246   unsigned getGlobalBaseReg(MachineFunction *MF) const;
247 };
248
249 }
250
251 #endif