blob: 9c47d8e0d544f8428aaaa959601965c48b235f0f [file] [log] [blame]
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001//===- MipsInstrInfo.h - Mips Instruction Information -----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
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"
Torok Edwinc25e7582009-07-11 20:10:48 +000018#include "llvm/Support/ErrorHandling.h"
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000019#include "llvm/Target/TargetInstrInfo.h"
20#include "MipsRegisterInfo.h"
21
22namespace llvm {
23
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000024namespace Mips {
25
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +000026 // Mips Branch Codes
27 enum FPBranchCode {
28 BRANCH_F,
29 BRANCH_T,
30 BRANCH_FL,
31 BRANCH_TL,
32 BRANCH_INVALID
33 };
34
Bruno Cardoso Lopesdc0c04c2007-08-28 05:06:17 +000035 // Mips Condition Codes
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000036 enum CondCode {
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000037 // To be used with float branch True
38 FCOND_F,
39 FCOND_UN,
40 FCOND_EQ,
41 FCOND_UEQ,
42 FCOND_OLT,
43 FCOND_ULT,
44 FCOND_OLE,
45 FCOND_ULE,
46 FCOND_SF,
47 FCOND_NGLE,
48 FCOND_SEQ,
49 FCOND_NGL,
50 FCOND_LT,
51 FCOND_NGE,
52 FCOND_LE,
53 FCOND_NGT,
54
55 // To be used with float branch False
56 // This conditions have the same mnemonic as the
57 // above ones, but are used with a branch False;
58 FCOND_T,
59 FCOND_OR,
60 FCOND_NEQ,
61 FCOND_OGL,
62 FCOND_UGE,
63 FCOND_OGE,
64 FCOND_UGT,
65 FCOND_OGT,
66 FCOND_ST,
67 FCOND_GLE,
68 FCOND_SNE,
69 FCOND_GL,
70 FCOND_NLT,
71 FCOND_GE,
72 FCOND_NLE,
73 FCOND_GT,
74
75 // Only integer conditions
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000076 COND_E,
77 COND_GZ,
78 COND_GEZ,
79 COND_LZ,
80 COND_LEZ,
81 COND_NE,
82 COND_INVALID
83 };
84
85 // Turn condition code into conditional branch opcode.
86 unsigned GetCondBranchFromCond(CondCode CC);
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +000087
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000088 /// GetOppositeBranchCondition - Return the inverse of the specified cond,
89 /// e.g. turning COND_E to COND_NE.
90 CondCode GetOppositeBranchCondition(Mips::CondCode CC);
91
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000092 /// MipsCCToString - Map each FP condition code to its string
93 inline static const char *MipsFCCToString(Mips::CondCode CC)
94 {
95 switch (CC) {
Torok Edwinc25e7582009-07-11 20:10:48 +000096 default: LLVM_UNREACHABLE("Unknown condition code");
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000097 case FCOND_F:
98 case FCOND_T: return "f";
99 case FCOND_UN:
100 case FCOND_OR: return "un";
101 case FCOND_EQ:
102 case FCOND_NEQ: return "eq";
103 case FCOND_UEQ:
104 case FCOND_OGL: return "ueq";
105 case FCOND_OLT:
106 case FCOND_UGE: return "olt";
107 case FCOND_ULT:
108 case FCOND_OGE: return "ult";
109 case FCOND_OLE:
110 case FCOND_UGT: return "ole";
111 case FCOND_ULE:
112 case FCOND_OGT: return "ule";
113 case FCOND_SF:
114 case FCOND_ST: return "sf";
115 case FCOND_NGLE:
116 case FCOND_GLE: return "ngle";
117 case FCOND_SEQ:
118 case FCOND_SNE: return "seq";
119 case FCOND_NGL:
120 case FCOND_GL: return "ngl";
121 case FCOND_LT:
122 case FCOND_NLT: return "lt";
123 case FCOND_NGE:
124 case FCOND_GE: return "ge";
125 case FCOND_LE:
126 case FCOND_NLE: return "nle";
127 case FCOND_NGT:
128 case FCOND_GT: return "gt";
129 }
130 }
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000131}
132
Chris Lattner64105522008-01-01 01:03:04 +0000133class MipsInstrInfo : public TargetInstrInfoImpl {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000134 MipsTargetMachine &TM;
135 const MipsRegisterInfo RI;
136public:
Dan Gohman950a4c42008-03-25 22:06:05 +0000137 explicit MipsInstrInfo(MipsTargetMachine &TM);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000138
139 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
140 /// such, whenever a client has an instance of instruction info, it should
141 /// always be able to get register info as well (through this method).
142 ///
Dan Gohmanc9f5f3f2008-05-14 01:58:56 +0000143 virtual const MipsRegisterInfo &getRegisterInfo() const { return RI; }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000144
Evan Cheng04ee5a12009-01-20 19:12:24 +0000145 /// Return true if the instruction is a register to register move and return
146 /// the source and dest operands and their sub-register indices by reference.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000147 virtual bool isMoveInstr(const MachineInstr &MI,
Evan Cheng04ee5a12009-01-20 19:12:24 +0000148 unsigned &SrcReg, unsigned &DstReg,
149 unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000150
151 /// isLoadFromStackSlot - If the specified machine instruction is a direct
152 /// load from a stack slot, return the virtual or physical register number of
153 /// the destination along with the FrameIndex of the loaded stack slot. If
154 /// not, return 0. This predicate must return 0 if the instruction has
155 /// any side effects other than loading from the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +0000156 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
157 int &FrameIndex) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000158
159 /// isStoreToStackSlot - If the specified machine instruction is a direct
160 /// store to a stack slot, return the virtual or physical register number of
161 /// the source reg along with the FrameIndex of the loaded stack slot. If
162 /// not, return 0. This predicate must return 0 if the instruction has
163 /// any side effects other than storing to the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +0000164 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
165 int &FrameIndex) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000166
167 /// Branch Analysis
168 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
169 MachineBasicBlock *&FBB,
Evan Chengdc54d312009-02-09 07:14:22 +0000170 SmallVectorImpl<MachineOperand> &Cond,
171 bool AllowModify) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000172 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000173 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000174 MachineBasicBlock *FBB,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000175 const SmallVectorImpl<MachineOperand> &Cond) const;
Owen Anderson940f83e2008-08-26 18:03:31 +0000176 virtual bool copyRegToReg(MachineBasicBlock &MBB,
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000177 MachineBasicBlock::iterator I,
Owen Andersond10fd972007-12-31 06:32:00 +0000178 unsigned DestReg, unsigned SrcReg,
179 const TargetRegisterClass *DestRC,
180 const TargetRegisterClass *SrcRC) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000181 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
182 MachineBasicBlock::iterator MBBI,
183 unsigned SrcReg, bool isKill, int FrameIndex,
184 const TargetRegisterClass *RC) const;
185
186 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
187 SmallVectorImpl<MachineOperand> &Addr,
188 const TargetRegisterClass *RC,
189 SmallVectorImpl<MachineInstr*> &NewMIs) const;
190
191 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
192 MachineBasicBlock::iterator MBBI,
193 unsigned DestReg, int FrameIndex,
194 const TargetRegisterClass *RC) const;
195
196 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
197 SmallVectorImpl<MachineOperand> &Addr,
198 const TargetRegisterClass *RC,
199 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Owen Anderson43dbe052008-01-07 01:35:02 +0000200
Dan Gohmanc54baa22008-12-03 18:43:12 +0000201 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
202 MachineInstr* MI,
203 const SmallVectorImpl<unsigned> &Ops,
204 int FrameIndex) const;
Owen Anderson43dbe052008-01-07 01:35:02 +0000205
Dan Gohmanc54baa22008-12-03 18:43:12 +0000206 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
207 MachineInstr* MI,
208 const SmallVectorImpl<unsigned> &Ops,
209 MachineInstr* LoadMI) const {
Owen Anderson43dbe052008-01-07 01:35:02 +0000210 return 0;
211 }
212
Dan Gohman8e8b8a22008-10-16 01:49:15 +0000213 virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
Owen Anderson44eb65c2008-08-14 22:49:33 +0000214 virtual
215 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000216
217 /// Insert nop instruction when hazard condition is found
218 virtual void insertNoop(MachineBasicBlock &MBB,
219 MachineBasicBlock::iterator MI) const;
Dan Gohman99114052009-06-03 20:30:14 +0000220
221 /// getGlobalBaseReg - Return a virtual register initialized with the
222 /// the global base register value. Output instructions required to
223 /// initialize the register in the function entry block, if necessary.
224 ///
225 unsigned getGlobalBaseReg(MachineFunction *MF) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000226};
227
228}
229
230#endif