blob: 55a2249029780d078aeaadb40accf1739530fd89 [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"
18#include "llvm/Target/TargetInstrInfo.h"
19#include "MipsRegisterInfo.h"
20
21namespace llvm {
22
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000023namespace Mips {
24
Bruno Cardoso Lopesdc0c04c2007-08-28 05:06:17 +000025 // Mips Condition Codes
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000026 enum CondCode {
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000027 // To be used with float branch True
28 FCOND_F,
29 FCOND_UN,
30 FCOND_EQ,
31 FCOND_UEQ,
32 FCOND_OLT,
33 FCOND_ULT,
34 FCOND_OLE,
35 FCOND_ULE,
36 FCOND_SF,
37 FCOND_NGLE,
38 FCOND_SEQ,
39 FCOND_NGL,
40 FCOND_LT,
41 FCOND_NGE,
42 FCOND_LE,
43 FCOND_NGT,
44
45 // To be used with float branch False
46 // This conditions have the same mnemonic as the
47 // above ones, but are used with a branch False;
48 FCOND_T,
49 FCOND_OR,
50 FCOND_NEQ,
51 FCOND_OGL,
52 FCOND_UGE,
53 FCOND_OGE,
54 FCOND_UGT,
55 FCOND_OGT,
56 FCOND_ST,
57 FCOND_GLE,
58 FCOND_SNE,
59 FCOND_GL,
60 FCOND_NLT,
61 FCOND_GE,
62 FCOND_NLE,
63 FCOND_GT,
64
65 // Only integer conditions
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000066 COND_E,
67 COND_GZ,
68 COND_GEZ,
69 COND_LZ,
70 COND_LEZ,
71 COND_NE,
72 COND_INVALID
73 };
74
75 // Turn condition code into conditional branch opcode.
76 unsigned GetCondBranchFromCond(CondCode CC);
77
78 /// GetOppositeBranchCondition - Return the inverse of the specified cond,
79 /// e.g. turning COND_E to COND_NE.
80 CondCode GetOppositeBranchCondition(Mips::CondCode CC);
81
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000082 /// MipsCCToString - Map each FP condition code to its string
83 inline static const char *MipsFCCToString(Mips::CondCode CC)
84 {
85 switch (CC) {
86 default: assert(0 && "Unknown condition code");
87 case FCOND_F:
88 case FCOND_T: return "f";
89 case FCOND_UN:
90 case FCOND_OR: return "un";
91 case FCOND_EQ:
92 case FCOND_NEQ: return "eq";
93 case FCOND_UEQ:
94 case FCOND_OGL: return "ueq";
95 case FCOND_OLT:
96 case FCOND_UGE: return "olt";
97 case FCOND_ULT:
98 case FCOND_OGE: return "ult";
99 case FCOND_OLE:
100 case FCOND_UGT: return "ole";
101 case FCOND_ULE:
102 case FCOND_OGT: return "ule";
103 case FCOND_SF:
104 case FCOND_ST: return "sf";
105 case FCOND_NGLE:
106 case FCOND_GLE: return "ngle";
107 case FCOND_SEQ:
108 case FCOND_SNE: return "seq";
109 case FCOND_NGL:
110 case FCOND_GL: return "ngl";
111 case FCOND_LT:
112 case FCOND_NLT: return "lt";
113 case FCOND_NGE:
114 case FCOND_GE: return "ge";
115 case FCOND_LE:
116 case FCOND_NLE: return "nle";
117 case FCOND_NGT:
118 case FCOND_GT: return "gt";
119 }
120 }
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000121}
122
Chris Lattner64105522008-01-01 01:03:04 +0000123class MipsInstrInfo : public TargetInstrInfoImpl {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000124 MipsTargetMachine &TM;
125 const MipsRegisterInfo RI;
126public:
Dan Gohman950a4c42008-03-25 22:06:05 +0000127 explicit MipsInstrInfo(MipsTargetMachine &TM);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000128
129 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
130 /// such, whenever a client has an instance of instruction info, it should
131 /// always be able to get register info as well (through this method).
132 ///
Dan Gohmanc9f5f3f2008-05-14 01:58:56 +0000133 virtual const MipsRegisterInfo &getRegisterInfo() const { return RI; }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000134
135 /// Return true if the instruction is a register to register move and
136 /// leave the source and dest operands in the passed parameters.
137 ///
138 virtual bool isMoveInstr(const MachineInstr &MI,
139 unsigned &SrcReg, unsigned &DstReg) const;
140
141 /// isLoadFromStackSlot - If the specified machine instruction is a direct
142 /// load from a stack slot, return the virtual or physical register number of
143 /// the destination along with the FrameIndex of the loaded stack slot. If
144 /// not, return 0. This predicate must return 0 if the instruction has
145 /// any side effects other than loading from the stack slot.
146 virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
147
148 /// isStoreToStackSlot - If the specified machine instruction is a direct
149 /// store to a stack slot, return the virtual or physical register number of
150 /// the source reg along with the FrameIndex of the loaded stack slot. If
151 /// not, return 0. This predicate must return 0 if the instruction has
152 /// any side effects other than storing to the stack slot.
153 virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000154
155 /// Branch Analysis
156 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
157 MachineBasicBlock *&FBB,
158 std::vector<MachineOperand> &Cond) const;
159 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000160 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000161 MachineBasicBlock *FBB,
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000162 const std::vector<MachineOperand> &Cond) const;
Owen Andersond10fd972007-12-31 06:32:00 +0000163 virtual void copyRegToReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
164 unsigned DestReg, unsigned SrcReg,
165 const TargetRegisterClass *DestRC,
166 const TargetRegisterClass *SrcRC) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000167 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
168 MachineBasicBlock::iterator MBBI,
169 unsigned SrcReg, bool isKill, int FrameIndex,
170 const TargetRegisterClass *RC) const;
171
172 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
173 SmallVectorImpl<MachineOperand> &Addr,
174 const TargetRegisterClass *RC,
175 SmallVectorImpl<MachineInstr*> &NewMIs) const;
176
177 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
178 MachineBasicBlock::iterator MBBI,
179 unsigned DestReg, int FrameIndex,
180 const TargetRegisterClass *RC) const;
181
182 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
183 SmallVectorImpl<MachineOperand> &Addr,
184 const TargetRegisterClass *RC,
185 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Owen Anderson43dbe052008-01-07 01:35:02 +0000186
Evan Cheng5fd79d02008-02-08 21:20:40 +0000187 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
188 MachineInstr* MI,
Owen Anderson43dbe052008-01-07 01:35:02 +0000189 SmallVectorImpl<unsigned> &Ops,
190 int FrameIndex) const;
191
Evan Cheng5fd79d02008-02-08 21:20:40 +0000192 virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
193 MachineInstr* MI,
Owen Anderson43dbe052008-01-07 01:35:02 +0000194 SmallVectorImpl<unsigned> &Ops,
195 MachineInstr* LoadMI) const {
196 return 0;
197 }
198
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000199 virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const;
200 virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const;
201
202 /// Insert nop instruction when hazard condition is found
203 virtual void insertNoop(MachineBasicBlock &MBB,
204 MachineBasicBlock::iterator MI) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000205};
206
207}
208
209#endif