blob: 5fdbf1f230a0af5339910d84cd360d37cadd7e04 [file] [log] [blame]
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001//===- MipsInstrInfo.h - Mips Instruction Information -----------*- C++ -*-===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
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//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00009//
10// This file contains the Mips implementation of the TargetInstrInfo class.
11//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000013
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,
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +000040 FCOND_OEQ,
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000041 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,
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +000060 FCOND_UNE,
61 FCOND_ONE,
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000062 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,
Akira Hatanaka20ada982011-04-01 17:39:08 +000073 FCOND_GT
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000074 };
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000075
Akira Hatanaka20ada982011-04-01 17:39:08 +000076 /// GetOppositeBranchOpc - Return the inverse of the specified
77 /// opcode, e.g. turning BEQ to BNE.
78 unsigned GetOppositeBranchOpc(unsigned Opc);
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000079
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000080 /// MipsCCToString - Map each FP condition code to its string
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000081 inline static const char *MipsFCCToString(Mips::CondCode CC)
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000082 {
83 switch (CC) {
Torok Edwinc23197a2009-07-14 16:55:14 +000084 default: llvm_unreachable("Unknown condition code");
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000085 case FCOND_F:
86 case FCOND_T: return "f";
87 case FCOND_UN:
88 case FCOND_OR: return "un";
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +000089 case FCOND_OEQ:
90 case FCOND_UNE: return "eq";
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000091 case FCOND_UEQ:
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +000092 case FCOND_ONE: return "ueq";
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000093 case FCOND_OLT:
94 case FCOND_UGE: return "olt";
95 case FCOND_ULT:
96 case FCOND_OGE: return "ult";
97 case FCOND_OLE:
98 case FCOND_UGT: return "ole";
99 case FCOND_ULE:
100 case FCOND_OGT: return "ule";
101 case FCOND_SF:
102 case FCOND_ST: return "sf";
103 case FCOND_NGLE:
104 case FCOND_GLE: return "ngle";
105 case FCOND_SEQ:
106 case FCOND_SNE: return "seq";
107 case FCOND_NGL:
108 case FCOND_GL: return "ngl";
109 case FCOND_LT:
110 case FCOND_NLT: return "lt";
111 case FCOND_NGE:
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000112 case FCOND_GE: return "nge";
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000113 case FCOND_LE:
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000114 case FCOND_NLE: return "le";
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000115 case FCOND_NGT:
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000116 case FCOND_GT: return "ngt";
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000117 }
118 }
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000119}
120
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000121/// MipsII - This namespace holds all of the target specific flags that
122/// instruction info tracks.
123///
124namespace MipsII {
125 /// Target Operand Flag enum.
126 enum TOF {
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000127 //===------------------------------------------------------------------===//
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000128 // Mips Specific MachineOperand flags.
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000129
Dan Gohman01a76ce2009-10-05 15:52:08 +0000130 MO_NO_FLAG,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000131
132 /// MO_GOT - Represents the offset into the global offset table at which
133 /// the address the relocation entry symbol resides during execution.
Dan Gohman01a76ce2009-10-05 15:52:08 +0000134 MO_GOT,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000135
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000136 /// MO_GOT_CALL - Represents the offset into the global offset table at
137 /// which the address of a call site relocation entry symbol resides
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000138 /// during execution. This is different from the above since this flag
139 /// can only be present in call instructions.
Dan Gohman01a76ce2009-10-05 15:52:08 +0000140 MO_GOT_CALL,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000141
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000142 /// MO_GPREL - Represents the offset from the current gp value to be used
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000143 /// for the relocatable object file being produced.
Dan Gohman01a76ce2009-10-05 15:52:08 +0000144 MO_GPREL,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000145
Akira Hatanakae2e436a2011-04-01 21:41:06 +0000146 /// MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000147 /// address.
Akira Hatanakae2e436a2011-04-01 21:41:06 +0000148 MO_ABS_HI,
149 MO_ABS_LO
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000150 };
151}
152
Chris Lattner64105522008-01-01 01:03:04 +0000153class MipsInstrInfo : public TargetInstrInfoImpl {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000154 MipsTargetMachine &TM;
155 const MipsRegisterInfo RI;
156public:
Dan Gohman950a4c42008-03-25 22:06:05 +0000157 explicit MipsInstrInfo(MipsTargetMachine &TM);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000158
159 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
160 /// such, whenever a client has an instance of instruction info, it should
161 /// always be able to get register info as well (through this method).
162 ///
Dan Gohmanc9f5f3f2008-05-14 01:58:56 +0000163 virtual const MipsRegisterInfo &getRegisterInfo() const { return RI; }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000164
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000165 /// isLoadFromStackSlot - If the specified machine instruction is a direct
166 /// load from a stack slot, return the virtual or physical register number of
167 /// the destination along with the FrameIndex of the loaded stack slot. If
168 /// not, return 0. This predicate must return 0 if the instruction has
169 /// any side effects other than loading from the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +0000170 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
171 int &FrameIndex) const;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000172
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000173 /// isStoreToStackSlot - If the specified machine instruction is a direct
174 /// store to a stack slot, return the virtual or physical register number of
175 /// the source reg along with the FrameIndex of the loaded stack slot. If
176 /// not, return 0. This predicate must return 0 if the instruction has
177 /// any side effects other than storing to the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +0000178 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
179 int &FrameIndex) const;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000180
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000181 /// Branch Analysis
182 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
183 MachineBasicBlock *&FBB,
Evan Chengdc54d312009-02-09 07:14:22 +0000184 SmallVectorImpl<MachineOperand> &Cond,
185 bool AllowModify) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000186 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
Akira Hatanaka20ada982011-04-01 17:39:08 +0000187
188private:
189 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
190 const SmallVectorImpl<MachineOperand>& Cond) const;
191
192public:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000193 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000194 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +0000195 const SmallVectorImpl<MachineOperand> &Cond,
196 DebugLoc DL) const;
Jakob Stoklund Olesen273c14f2010-07-11 01:08:31 +0000197 virtual void copyPhysReg(MachineBasicBlock &MBB,
198 MachineBasicBlock::iterator MI, DebugLoc DL,
199 unsigned DestReg, unsigned SrcReg,
200 bool KillSrc) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000201 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
202 MachineBasicBlock::iterator MBBI,
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000203 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000204 const TargetRegisterClass *RC,
205 const TargetRegisterInfo *TRI) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000206
Owen Andersonf6372aa2008-01-01 21:11:32 +0000207 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
208 MachineBasicBlock::iterator MBBI,
209 unsigned DestReg, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000210 const TargetRegisterClass *RC,
211 const TargetRegisterInfo *TRI) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000212
Owen Anderson44eb65c2008-08-14 22:49:33 +0000213 virtual
214 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000215
216 /// Insert nop instruction when hazard condition is found
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000217 virtual void insertNoop(MachineBasicBlock &MBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000218 MachineBasicBlock::iterator MI) const;
Dan Gohman99114052009-06-03 20:30:14 +0000219
220 /// getGlobalBaseReg - Return a virtual register initialized with the
221 /// the global base register value. Output instructions required to
222 /// initialize the register in the function entry block, if necessary.
223 ///
224 unsigned getGlobalBaseReg(MachineFunction *MF) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000225};
226
227}
228
229#endif