blob: d02fdc1b37ae758aee5fea4526ba74c581a727c4 [file] [log] [blame]
Akira Hatanakae2489122011-04-15 21:51:11 +00001//===- MipsInstrInfo.h - Mips Instruction Information -----------*- C++ -*-===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Lopes35e43c42007-06-06 07:42:06 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00009//
10// This file contains the Mips implementation of the TargetInstrInfo class.
11//
Akira Hatanakae2489122011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000013
14#ifndef MIPSINSTRUCTIONINFO_H
15#define MIPSINSTRUCTIONINFO_H
16
17#include "Mips.h"
Torok Edwin56d06592009-07-11 20:10:48 +000018#include "llvm/Support/ErrorHandling.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000019#include "llvm/Target/TargetInstrInfo.h"
20#include "MipsRegisterInfo.h"
21
Evan Cheng703a0fb2011-07-01 17:57:27 +000022#define GET_INSTRINFO_HEADER
23#include "MipsGenInstrInfo.inc"
24
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000025namespace llvm {
26
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000027namespace Mips {
28
Bruno Cardoso Lopesbcaf6e52008-07-28 19:11:24 +000029 // Mips Branch Codes
30 enum FPBranchCode {
31 BRANCH_F,
32 BRANCH_T,
33 BRANCH_FL,
34 BRANCH_TL,
35 BRANCH_INVALID
36 };
37
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +000038 // Mips Condition Codes
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000039 enum CondCode {
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000040 // To be used with float branch True
41 FCOND_F,
42 FCOND_UN,
Akira Hatanakaa5352702011-03-31 18:26:17 +000043 FCOND_OEQ,
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000044 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,
Akira Hatanakaa5352702011-03-31 18:26:17 +000063 FCOND_UNE,
64 FCOND_ONE,
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000065 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,
Akira Hatanaka93f898f2011-04-01 17:39:08 +000076 FCOND_GT
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000077 };
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000078
Akira Hatanaka93f898f2011-04-01 17:39:08 +000079 /// GetOppositeBranchOpc - Return the inverse of the specified
80 /// opcode, e.g. turning BEQ to BNE.
81 unsigned GetOppositeBranchOpc(unsigned Opc);
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +000082
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000083 /// MipsCCToString - Map each FP condition code to its string
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +000084 inline static const char *MipsFCCToString(Mips::CondCode CC)
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000085 {
86 switch (CC) {
Torok Edwinfbcc6632009-07-14 16:55:14 +000087 default: llvm_unreachable("Unknown condition code");
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000088 case FCOND_F:
89 case FCOND_T: return "f";
90 case FCOND_UN:
91 case FCOND_OR: return "un";
Akira Hatanakaa5352702011-03-31 18:26:17 +000092 case FCOND_OEQ:
93 case FCOND_UNE: return "eq";
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000094 case FCOND_UEQ:
Akira Hatanakaa5352702011-03-31 18:26:17 +000095 case FCOND_ONE: return "ueq";
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000096 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:
Akira Hatanakaa5352702011-03-31 18:26:17 +0000115 case FCOND_GE: return "nge";
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000116 case FCOND_LE:
Akira Hatanakaa5352702011-03-31 18:26:17 +0000117 case FCOND_NLE: return "le";
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000118 case FCOND_NGT:
Akira Hatanakaa5352702011-03-31 18:26:17 +0000119 case FCOND_GT: return "ngt";
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000120 }
121 }
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000122}
123
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000124/// MipsII - This namespace holds all of the target specific flags that
125/// instruction info tracks.
126///
127namespace MipsII {
128 /// Target Operand Flag enum.
129 enum TOF {
Akira Hatanakae2489122011-04-15 21:51:11 +0000130 //===------------------------------------------------------------------===//
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000131 // Mips Specific MachineOperand flags.
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000132
Dan Gohman27285692009-10-05 15:52:08 +0000133 MO_NO_FLAG,
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000134
135 /// MO_GOT - Represents the offset into the global offset table at which
136 /// the address the relocation entry symbol resides during execution.
Dan Gohman27285692009-10-05 15:52:08 +0000137 MO_GOT,
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000138
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000139 /// MO_GOT_CALL - Represents the offset into the global offset table at
140 /// which the address of a call site relocation entry symbol resides
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000141 /// during execution. This is different from the above since this flag
142 /// can only be present in call instructions.
Dan Gohman27285692009-10-05 15:52:08 +0000143 MO_GOT_CALL,
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000144
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000145 /// MO_GPREL - Represents the offset from the current gp value to be used
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000146 /// for the relocatable object file being produced.
Dan Gohman27285692009-10-05 15:52:08 +0000147 MO_GPREL,
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000148
Akira Hatanaka56d9ef52011-04-01 21:41:06 +0000149 /// MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000150 /// address.
Akira Hatanaka56d9ef52011-04-01 21:41:06 +0000151 MO_ABS_HI,
Bruno Cardoso Lopesbf3c1252011-05-31 02:53:58 +0000152 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
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000167 };
168}
169
Evan Cheng703a0fb2011-07-01 17:57:27 +0000170class MipsInstrInfo : public MipsGenInstrInfo {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000171 MipsTargetMachine &TM;
172 const MipsRegisterInfo RI;
173public:
Dan Gohmanc60c67f2008-03-25 22:06:05 +0000174 explicit MipsInstrInfo(MipsTargetMachine &TM);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000175
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 ///
Dan Gohmaneabd6472008-05-14 01:58:56 +0000180 virtual const MipsRegisterInfo &getRegisterInfo() const { return RI; }
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000181
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000182 /// 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.
Dan Gohman0b273252008-11-18 19:49:32 +0000187 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
188 int &FrameIndex) const;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000189
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000190 /// 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.
Dan Gohman0b273252008-11-18 19:49:32 +0000195 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
196 int &FrameIndex) const;
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000197
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000198 /// Branch Analysis
199 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
200 MachineBasicBlock *&FBB,
Evan Cheng64dfcac2009-02-09 07:14:22 +0000201 SmallVectorImpl<MachineOperand> &Cond,
202 bool AllowModify) const;
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000203 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
Akira Hatanaka93f898f2011-04-01 17:39:08 +0000204
205private:
206 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
207 const SmallVectorImpl<MachineOperand>& Cond) const;
208
209public:
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000210 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000211 MachineBasicBlock *FBB,
Stuart Hastings0125b642010-06-17 22:43:56 +0000212 const SmallVectorImpl<MachineOperand> &Cond,
213 DebugLoc DL) const;
Jakob Stoklund Olesen7002c312010-07-11 01:08:31 +0000214 virtual void copyPhysReg(MachineBasicBlock &MBB,
215 MachineBasicBlock::iterator MI, DebugLoc DL,
216 unsigned DestReg, unsigned SrcReg,
217 bool KillSrc) const;
Owen Andersoneee14602008-01-01 21:11:32 +0000218 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
219 MachineBasicBlock::iterator MBBI,
Akira Hatanakae2489122011-04-15 21:51:11 +0000220 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Chengefb126a2010-05-06 19:06:44 +0000221 const TargetRegisterClass *RC,
222 const TargetRegisterInfo *TRI) const;
Owen Andersoneee14602008-01-01 21:11:32 +0000223
Owen Andersoneee14602008-01-01 21:11:32 +0000224 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
225 MachineBasicBlock::iterator MBBI,
226 unsigned DestReg, int FrameIndex,
Evan Chengefb126a2010-05-06 19:06:44 +0000227 const TargetRegisterClass *RC,
228 const TargetRegisterInfo *TRI) const;
Owen Andersoneee14602008-01-01 21:11:32 +0000229
Akira Hatanakaf2bcad92011-07-01 01:04:43 +0000230 virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
231 int FrameIx, uint64_t Offset,
232 const MDNode *MDPtr,
233 DebugLoc DL) const;
234
Owen Anderson4f6bf042008-08-14 22:49:33 +0000235 virtual
236 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000237
238 /// Insert nop instruction when hazard condition is found
Bruno Cardoso Lopesed874ef2011-03-04 17:51:39 +0000239 virtual void insertNoop(MachineBasicBlock &MBB,
Bruno Cardoso Lopes0c530632007-08-18 01:59:45 +0000240 MachineBasicBlock::iterator MI) const;
Dan Gohmand5ca70642009-06-03 20:30:14 +0000241
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;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000247};
248
249}
250
251#endif