blob: 4405760cd05bb1aecc0071899ca692d4266c3a3e [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
Evan Cheng4db3cff2011-07-01 17:57:27 +000022#define GET_INSTRINFO_HEADER
23#include "MipsGenInstrInfo.inc"
24
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000025namespace llvm {
26
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000027namespace Mips {
Akira Hatanaka20ada982011-04-01 17:39:08 +000028 /// GetOppositeBranchOpc - Return the inverse of the specified
29 /// opcode, e.g. turning BEQ to BNE.
30 unsigned GetOppositeBranchOpc(unsigned Opc);
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +000031}
32
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +000033/// MipsII - This namespace holds all of the target specific flags that
34/// instruction info tracks.
35///
36namespace MipsII {
37 /// Target Operand Flag enum.
38 enum TOF {
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000039 //===------------------------------------------------------------------===//
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +000040 // Mips Specific MachineOperand flags.
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000041
Dan Gohman01a76ce2009-10-05 15:52:08 +000042 MO_NO_FLAG,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +000043
44 /// MO_GOT - Represents the offset into the global offset table at which
45 /// the address the relocation entry symbol resides during execution.
Dan Gohman01a76ce2009-10-05 15:52:08 +000046 MO_GOT,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +000047
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000048 /// MO_GOT_CALL - Represents the offset into the global offset table at
49 /// which the address of a call site relocation entry symbol resides
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +000050 /// during execution. This is different from the above since this flag
51 /// can only be present in call instructions.
Dan Gohman01a76ce2009-10-05 15:52:08 +000052 MO_GOT_CALL,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +000053
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000054 /// MO_GPREL - Represents the offset from the current gp value to be used
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +000055 /// for the relocatable object file being produced.
Dan Gohman01a76ce2009-10-05 15:52:08 +000056 MO_GPREL,
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +000057
Akira Hatanakae2e436a2011-04-01 21:41:06 +000058 /// MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000059 /// address.
Akira Hatanakae2e436a2011-04-01 21:41:06 +000060 MO_ABS_HI,
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000061 MO_ABS_LO,
62
63 /// MO_TLSGD - Represents the offset into the global offset table at which
64 // the module ID and TSL block offset reside during execution (General
65 // Dynamic TLS).
66 MO_TLSGD,
67
68 /// MO_GOTTPREL - Represents the offset from the thread pointer (Initial
69 // Exec TLS).
70 MO_GOTTPREL,
71
72 /// MO_TPREL_HI/LO - Represents the hi and low part of the offset from
73 // the thread pointer (Local Exec TLS).
74 MO_TPREL_HI,
Akira Hatanakae33ca9c2011-09-22 03:09:07 +000075 MO_TPREL_LO,
76
77 // N32/64 Flags.
78 MO_GPOFF_HI,
79 MO_GPOFF_LO,
80 MO_GOT_DISP,
81 MO_GOT_PAGE,
82 MO_GOT_OFST
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +000083 };
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +000084
85 enum {
86 //===------------------------------------------------------------------===//
87 // Instruction encodings. These are the standard/most common forms for
88 // Mips instructions.
89 //
90
91 // Pseudo - This represents an instruction that is a pseudo instruction
92 // or one that has not been implemented yet. It is illegal to code generate
93 // it, but tolerated for intermediate implementation stages.
94 Pseudo = 0,
95
96 /// FrmR - This form is for instructions of the format R.
97 FrmR = 1,
98 /// FrmI - This form is for instructions of the format I.
99 FrmI = 2,
100 /// FrmJ - This form is for instructions of the format J.
101 FrmJ = 3,
102 /// FrmFR - This form is for instructions of the format FR.
103 FrmFR = 4,
104 /// FrmFI - This form is for instructions of the format FI.
105 FrmFI = 5,
106 /// FrmOther - This form is for instructions that have no specific format.
107 FrmOther = 6,
108
109 FormMask = 15
110 };
Bruno Cardoso Lopesc517cb02009-09-01 17:27:58 +0000111}
112
Evan Cheng4db3cff2011-07-01 17:57:27 +0000113class MipsInstrInfo : public MipsGenInstrInfo {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000114 MipsTargetMachine &TM;
115 const MipsRegisterInfo RI;
116public:
Dan Gohman950a4c42008-03-25 22:06:05 +0000117 explicit MipsInstrInfo(MipsTargetMachine &TM);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000118
119 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
120 /// such, whenever a client has an instance of instruction info, it should
121 /// always be able to get register info as well (through this method).
122 ///
Akira Hatanaka794bf172011-07-07 23:56:50 +0000123 virtual const MipsRegisterInfo &getRegisterInfo() const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000124
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000125 /// isLoadFromStackSlot - If the specified machine instruction is a direct
126 /// load from a stack slot, return the virtual or physical register number of
127 /// the destination along with the FrameIndex of the loaded stack slot. If
128 /// not, return 0. This predicate must return 0 if the instruction has
129 /// any side effects other than loading from the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +0000130 virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
131 int &FrameIndex) const;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000132
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000133 /// isStoreToStackSlot - If the specified machine instruction is a direct
134 /// store to a stack slot, return the virtual or physical register number of
135 /// the source reg along with the FrameIndex of the loaded stack slot. If
136 /// not, return 0. This predicate must return 0 if the instruction has
137 /// any side effects other than storing to the stack slot.
Dan Gohmancbad42c2008-11-18 19:49:32 +0000138 virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
139 int &FrameIndex) const;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000140
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000141 /// Branch Analysis
142 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
143 MachineBasicBlock *&FBB,
Evan Chengdc54d312009-02-09 07:14:22 +0000144 SmallVectorImpl<MachineOperand> &Cond,
145 bool AllowModify) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000146 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
Akira Hatanaka20ada982011-04-01 17:39:08 +0000147
148private:
149 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
150 const SmallVectorImpl<MachineOperand>& Cond) const;
151
152public:
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000153 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000154 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +0000155 const SmallVectorImpl<MachineOperand> &Cond,
156 DebugLoc DL) const;
Jakob Stoklund Olesen273c14f2010-07-11 01:08:31 +0000157 virtual void copyPhysReg(MachineBasicBlock &MBB,
158 MachineBasicBlock::iterator MI, DebugLoc DL,
159 unsigned DestReg, unsigned SrcReg,
160 bool KillSrc) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000161 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
162 MachineBasicBlock::iterator MBBI,
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000163 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000164 const TargetRegisterClass *RC,
165 const TargetRegisterInfo *TRI) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000166
Owen Andersonf6372aa2008-01-01 21:11:32 +0000167 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
168 MachineBasicBlock::iterator MBBI,
169 unsigned DestReg, int FrameIndex,
Evan Cheng746ad692010-05-06 19:06:44 +0000170 const TargetRegisterClass *RC,
171 const TargetRegisterInfo *TRI) const;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000172
Akira Hatanakac4f24eb2011-07-01 01:04:43 +0000173 virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
174 int FrameIx, uint64_t Offset,
175 const MDNode *MDPtr,
176 DebugLoc DL) const;
177
Owen Anderson44eb65c2008-08-14 22:49:33 +0000178 virtual
179 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000180
181 /// Insert nop instruction when hazard condition is found
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000182 virtual void insertNoop(MachineBasicBlock &MBB,
Bruno Cardoso Lopes0b2cd892007-08-18 01:59:45 +0000183 MachineBasicBlock::iterator MI) const;
Dan Gohman99114052009-06-03 20:30:14 +0000184
185 /// getGlobalBaseReg - Return a virtual register initialized with the
186 /// the global base register value. Output instructions required to
187 /// initialize the register in the function entry block, if necessary.
188 ///
189 unsigned getGlobalBaseReg(MachineFunction *MF) const;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000190};
191
192}
193
194#endif