blob: b469167824c64e04f6d8e38c3cc74861cad24129 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9
10//===----------------------------------------------------------------------===//
11// Instruction format superclass
12//===----------------------------------------------------------------------===//
13
14include "MipsInstrFormats.td"
15
16//===----------------------------------------------------------------------===//
17// Mips profiles and nodes
18//===----------------------------------------------------------------------===//
19
20// Call
21def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
22def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, [SDNPHasChain,
23 SDNPOutFlag]>;
24
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +000025// Hi and Lo nodes are used to handle global addresses. Used on
26// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
27// static model. (nothing to do with Mips Registers Hi and Lo)
28def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp, [SDNPOutFlag]>;
29def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000030
Eric Christopher7300ac12007-10-26 04:00:13 +000031// Return
32def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
33def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034 SDNPOptInFlag]>;
35
36// These are target-independent nodes, but have target-specific formats.
Bill Wendling7173da52007-11-13 09:19:02 +000037def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
38def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>,
39 SDTCisVT<1, i32>]>;
Bill Wendling22f8deb2007-11-13 00:44:25 +000040
Bill Wendling7173da52007-11-13 09:19:02 +000041def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042 [SDNPHasChain, SDNPOutFlag]>;
Bill Wendling7173da52007-11-13 09:19:02 +000043def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Bill Wendling22f8deb2007-11-13 00:44:25 +000044 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +000046// Select CC
47def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
48 SDTCisSameAs<1, 2>, SDTCisInt<3>]>;
49def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
50
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000051//===----------------------------------------------------------------------===//
52// Mips Instruction Predicate Definitions.
53//===----------------------------------------------------------------------===//
54def IsStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">;
55
56//===----------------------------------------------------------------------===//
57// Mips Operand, Complex Patterns and Transformations Definitions.
58//===----------------------------------------------------------------------===//
59
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060// Instruction operand types
61def brtarget : Operand<OtherVT>;
62def calltarget : Operand<i32>;
63def uimm16 : Operand<i32>;
64def simm16 : Operand<i32>;
Eric Christopher7300ac12007-10-26 04:00:13 +000065def shamt : Operand<i32>;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000066def addrlabel : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000067
68// Address operand
69def mem : Operand<i32> {
70 let PrintMethod = "printMemOperand";
71 let MIOperandInfo = (ops simm16, CPURegs);
72}
73
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074// Transformation Function - get the lower 16 bits.
75def LO16 : SDNodeXForm<imm, [{
76 return getI32Imm((unsigned)N->getValue() & 0xFFFF);
77}]>;
78
79// Transformation Function - get the higher 16 bits.
80def HI16 : SDNodeXForm<imm, [{
81 return getI32Imm((unsigned)N->getValue() >> 16);
82}]>;
83
84// Node immediate fits as 16-bit sign extended on target immediate.
85// e.g. addi, andi
86def immSExt16 : PatLeaf<(imm), [{
87 if (N->getValueType(0) == MVT::i32)
88 return (int32_t)N->getValue() == (short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +000089 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090 return (int64_t)N->getValue() == (short)N->getValue();
91}]>;
92
93// Node immediate fits as 16-bit zero extended on target immediate.
94// The LO16 param means that only the lower 16 bits of the node
95// immediate are caught.
96// e.g. addiu, sltiu
97def immZExt16 : PatLeaf<(imm), [{
98 if (N->getValueType(0) == MVT::i32)
99 return (uint32_t)N->getValue() == (unsigned short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +0000100 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000101 return (uint64_t)N->getValue() == (unsigned short)N->getValue();
102}], LO16>;
103
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000104// Node immediate fits as 32-bit zero extended on target immediate.
105//def immZExt32 : PatLeaf<(imm), [{
106// return (uint64_t)N->getValue() == (uint32_t)N->getValue();
107//}], LO16>;
108
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000109// shamt field must fit in 5 bits.
110def immZExt5 : PatLeaf<(imm), [{
111 return N->getValue() == ((N->getValue()) & 0x1f) ;
112}]>;
113
Eric Christopher7300ac12007-10-26 04:00:13 +0000114// Mips Address Mode! SDNode frameindex could possibily be a match
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000115// since load and store instructions from stack used it.
116def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>;
117
118//===----------------------------------------------------------------------===//
119// Instructions specific format
120//===----------------------------------------------------------------------===//
121
122// Arithmetic 3 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000123let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000124class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher7300ac12007-10-26 04:00:13 +0000125 InstrItinClass itin>:
126 FR< op,
127 func,
128 (outs CPURegs:$dst),
129 (ins CPURegs:$b, CPURegs:$c),
130 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000131 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000132
Eric Christopher7300ac12007-10-26 04:00:13 +0000133let isCommutable = 1 in
134class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
135 FR< op,
136 func,
137 (outs CPURegs:$dst),
138 (ins CPURegs:$b, CPURegs:$c),
139 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000140 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000141
142// Arithmetic 2 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000143class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
144 Operand Od, PatLeaf imm_type> :
145 FI< op,
146 (outs CPURegs:$dst),
147 (ins CPURegs:$b, Od:$c),
148 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000149 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000150
151// Arithmetic Multiply ADD/SUB
152let rd=0 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000153class MArithR<bits<6> func, string instr_asm> :
154 FR< 0x1c,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155 func,
Eric Christopher7300ac12007-10-26 04:00:13 +0000156 (outs CPURegs:$rs),
157 (ins CPURegs:$rt),
158 !strconcat(instr_asm, " $rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000159 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160
161// Logical
162class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000163 FR< 0x00,
164 func,
165 (outs CPURegs:$dst),
166 (ins CPURegs:$b, CPURegs:$c),
167 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000168 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169
170class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
171 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000172 (outs CPURegs:$dst),
173 (ins CPURegs:$b, uimm16:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000174 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000175 [(set CPURegs:$dst, (OpNode CPURegs:$b, immSExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176
177class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000178 FR< op,
179 func,
180 (outs CPURegs:$dst),
181 (ins CPURegs:$b, CPURegs:$c),
182 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000183 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184
185// Shifts
186let rt = 0 in
187class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000188 FR< 0x00,
189 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000190 (outs CPURegs:$dst),
191 (ins CPURegs:$b, shamt:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000192 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000193 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194
195class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000196 FR< 0x00,
197 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000198 (outs CPURegs:$dst),
199 (ins CPURegs:$b, CPURegs:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000200 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000201 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000202
203// Load Upper Imediate
204class LoadUpper<bits<6> op, string instr_asm>:
205 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000206 (outs CPURegs:$dst),
207 (ins uimm16:$imm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000208 !strconcat(instr_asm, " $dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000209 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210
Eric Christopher7300ac12007-10-26 04:00:13 +0000211// Memory Load/Store
Chris Lattner1a1932c2008-01-06 23:38:27 +0000212let isSimpleLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
214 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000215 (outs CPURegs:$dst),
216 (ins mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000218 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
221 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000222 (outs),
223 (ins CPURegs:$dst, mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000225 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000226
227// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000228let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
230 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000231 (outs),
232 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000233 !strconcat(instr_asm, " $a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000234 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
235 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000236
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000237
238class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
239 FI< op,
240 (outs),
241 (ins CPURegs:$src, brtarget:$offset),
242 !strconcat(instr_asm, " $src, $offset"),
243 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
244 IIBranch>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000245}
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000246
Eric Christopher7300ac12007-10-26 04:00:13 +0000247// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
249 PatFrag cond_op>:
250 FR< op,
251 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000252 (outs CPURegs:$dst),
253 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000255 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
256 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257
258class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
259 Operand Od, PatLeaf imm_type>:
260 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000261 (outs CPURegs:$dst),
262 (ins CPURegs:$b, Od:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000264 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
265 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266
267// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000268let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269class JumpFJ<bits<6> op, string instr_asm>:
270 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000271 (outs),
272 (ins brtarget:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000274 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000276let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000277class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
278 FR< op,
279 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000280 (outs),
281 (ins CPURegs:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000283 [(brind CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284
285// Jump and Link (Call)
Eric Christopher7300ac12007-10-26 04:00:13 +0000286let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000287 // All calls clobber the non-callee saved registers...
Eric Christopher7300ac12007-10-26 04:00:13 +0000288 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2,
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000289 T3, T4, T5, T6, T7, T8, T9, K0, K1], Uses = [GP] in {
Eric Christopher7300ac12007-10-26 04:00:13 +0000290 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000291 FJ< op,
292 (outs),
293 (ins calltarget:$target),
294 !strconcat(instr_asm, " $target"),
295 [(MipsJmpLink imm:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000297 let rd=31 in
298 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
299 FR< op,
300 func,
301 (outs),
302 (ins CPURegs:$rs),
303 !strconcat(instr_asm, " $rs"),
304 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
305
306 class BranchLink<string instr_asm>:
307 FI< 0x1,
308 (outs),
309 (ins CPURegs:$rs, brtarget:$target),
310 !strconcat(instr_asm, " $rs, $target"),
311 [], IIBranch>;
312}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000313
Eric Christopher7300ac12007-10-26 04:00:13 +0000314// Mul, Div
315class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
316 FR< 0x00,
317 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000318 (outs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000319 (ins CPURegs:$a, CPURegs:$b),
320 !strconcat(instr_asm, " $a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000321 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322
Eric Christopher7300ac12007-10-26 04:00:13 +0000323// Move from Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000324class MoveFromTo<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000325 FR< 0x00,
326 func,
327 (outs CPURegs:$dst),
Evan Chengb783fa32007-07-19 01:14:50 +0000328 (ins),
Eric Christopher7300ac12007-10-26 04:00:13 +0000329 !strconcat(instr_asm, " $dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000330 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000331
332// Count Leading Ones/Zeros in Word
333class CountLeading<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000334 FR< 0x1c,
335 func,
336 (outs CPURegs:$dst),
337 (ins CPURegs:$src),
338 !strconcat(instr_asm, " $dst, $src"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000339 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340
Eric Christopher7300ac12007-10-26 04:00:13 +0000341class EffectiveAddress<string instr_asm> :
342 FI<0x09,
343 (outs CPURegs:$dst),
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000344 (ins mem:$addr),
345 instr_asm,
346 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000347
348//===----------------------------------------------------------------------===//
349// Pseudo instructions
350//===----------------------------------------------------------------------===//
351
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000353let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000354def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000355 "!ADJCALLSTACKDOWN $amt",
356 [(callseq_start imm:$amt)]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000357def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bill Wendling22f8deb2007-11-13 00:44:25 +0000358 "!ADJCALLSTACKUP $amt1",
359 [(callseq_end imm:$amt1, imm:$amt2)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000360}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361
Eric Christopher7300ac12007-10-26 04:00:13 +0000362// When handling PIC code the assembler needs .cpload and .cprestore
363// directives. If the real instructions corresponding these directives
364// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000365// from the assembler.
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000366def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$reg),
367 ".set noreorder\n\t.cpload $reg\n\t.set reorder\n",
368 []>;
369def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc),
370 ".cprestore $loc\n", []>;
371
372// The supported Mips ISAs dont have any instruction close to the SELECT_CC
373// operation. The solution is to create a Mips pseudo SELECT_CC instruction
374// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
375// replace it for real supported nodes into EmitInstrWithCustomInserter
376let usesCustomDAGSchedInserter = 1 in {
377 def Select_CC : MipsPseudo<(outs CPURegs:$dst),
378 (ins CPURegs:$CmpRes, CPURegs:$T, CPURegs:$F), "# MipsSelect_CC",
379 [(set CPURegs:$dst, (MipsSelectCC CPURegs:$CmpRes,
380 CPURegs:$T, CPURegs:$F))]>;
381}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382
383//===----------------------------------------------------------------------===//
384// Instruction definition
385//===----------------------------------------------------------------------===//
386
387//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000388// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389//===----------------------------------------------------------------------===//
390
391// Arithmetic
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000392
393// ADDiu just accept 16-bit immediates but we handle this on Pat's.
394// immZExt32 is used here so it can match GlobalAddress immediates.
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000395def ADDiu : ArithI<0x09, "addiu", add, uimm16, immZExt16>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000396def ADDi : ArithI<0x08, "addi", add, simm16, immSExt16>;
397def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
398def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
399def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400def ADD : ArithOverflowR<0x00, 0x20, "add">;
401def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000402
403// Logical
404def AND : LogicR<0x24, "and", and>;
405def OR : LogicR<0x25, "or", or>;
406def XOR : LogicR<0x26, "xor", xor>;
407def ANDi : LogicI<0x0c, "andi", and>;
408def ORi : LogicI<0x0d, "ori", or>;
409def XORi : LogicI<0x0e, "xori", xor>;
410def NOR : LogicNOR<0x00, 0x27, "nor">;
411
Eric Christopher7300ac12007-10-26 04:00:13 +0000412// Shifts
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000413def SLL : LogicR_shift_imm<0x00, "sll", shl>;
414def SRL : LogicR_shift_imm<0x02, "srl", srl>;
415def SRA : LogicR_shift_imm<0x03, "sra", sra>;
416def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
417def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
418def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
419
420// Load Upper Immediate
421def LUi : LoadUpper<0x0f, "lui">;
422
423// Load/Store
424def LB : LoadM<0x20, "lb", sextloadi8>;
425def LBu : LoadM<0x24, "lbu", zextloadi8>;
426def LH : LoadM<0x21, "lh", sextloadi16>;
427def LHu : LoadM<0x25, "lhu", zextloadi16>;
428def LW : LoadM<0x23, "lw", load>;
429def SB : StoreM<0x28, "sb", truncstorei8>;
430def SH : StoreM<0x29, "sh", truncstorei16>;
431def SW : StoreM<0x2b, "sw", store>;
432
433// Conditional Branch
434def BEQ : CBranch<0x04, "beq", seteq>;
435def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000436
Eric Christopher7300ac12007-10-26 04:00:13 +0000437let rt=1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000438def BGEZ : CBranchZero<0x01, "bgez", setge>;
439
440let rt=0 in {
441def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
442def BLEZ : CBranchZero<0x07, "blez", setle>;
443def BLTZ : CBranchZero<0x01, "bltz", setlt>;
444}
445
446// Set Condition Code
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
448def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
449def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
450def SLTiu : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
451
452// Unconditional jump
453def J : JumpFJ<0x02, "j">;
454def JR : JumpFR<0x00, 0x08, "jr">;
455
456// Jump and Link (Call)
457def JAL : JumpLink<0x03, "jal">;
458def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000459def BGEZAL : BranchLink<"bgezal">;
460def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461
462// MulDiv and Move From Hi/Lo operations, have
463// their correpondent SDNodes created on ISelDAG.
464// Special Mul, Div operations
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000465def MULT : MulDiv<0x18, "mult", IIImul>;
466def MULTu : MulDiv<0x19, "multu", IIImul>;
467def DIV : MulDiv<0x1a, "div", IIIdiv>;
468def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469
Eric Christopher7300ac12007-10-26 04:00:13 +0000470// Move From Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000471def MFHI : MoveFromTo<0x10, "mfhi">;
472def MFLO : MoveFromTo<0x12, "mflo">;
473def MTHI : MoveFromTo<0x11, "mthi">;
474def MTLO : MoveFromTo<0x13, "mtlo">;
475
476// Count Leading
Eric Christopher7300ac12007-10-26 04:00:13 +0000477// CLO/CLZ are part of the newer MIPS32(tm) instruction
478// set and not older Mips I keep this for future use
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000479// though.
Eric Christopher7300ac12007-10-26 04:00:13 +0000480//def CLO : CountLeading<0x21, "clo">;
481//def CLZ : CountLeading<0x20, "clz">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000482
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000483// MADD*/MSUB* are not part of MipsI either.
484//def MADD : MArithR<0x00, "madd">;
485//def MADDU : MArithR<0x01, "maddu">;
486//def MSUB : MArithR<0x04, "msub">;
487//def MSUBU : MArithR<0x05, "msubu">;
488
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489// No operation
490let addr=0 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000491def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492
Eric Christopher7300ac12007-10-26 04:00:13 +0000493// Ret instruction - as mips does not have "ret" a
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494// jr $ra must be generated.
Evan Cheng37e7c752007-07-21 00:34:19 +0000495let isReturn=1, isTerminator=1, hasDelaySlot=1,
Eric Christopher7300ac12007-10-26 04:00:13 +0000496 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497{
Evan Chengb783fa32007-07-19 01:14:50 +0000498 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000499 "jr $target", [(MipsRet CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000500}
501
Eric Christopher7300ac12007-10-26 04:00:13 +0000502// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000503// instructions. The same not happens for stack address copies, so an
504// add op with mem ComplexPattern is used and the stack address copy
505// can be matched. It's similar to Sparc LEA_ADDRi
506def LEA_ADDiu : EffectiveAddress<"addiu $dst, ${addr:stackloc}">;
507
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508//===----------------------------------------------------------------------===//
509// Arbitrary patterns that map to one or more instructions
510//===----------------------------------------------------------------------===//
511
512// Small immediates
Eric Christopher7300ac12007-10-26 04:00:13 +0000513def : Pat<(i32 immSExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000514 (ADDiu ZERO, imm:$in)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000515def : Pat<(i32 immZExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000516 (ORi ZERO, imm:$in)>;
517
518// Arbitrary immediates
519def : Pat<(i32 imm:$imm),
520 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
521
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000522// Carry patterns
523def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
524 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
525def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
526 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
527def : Pat<(addc CPURegs:$src, imm:$imm),
528 (ADDiu CPURegs:$src, imm:$imm)>;
529
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530// Call
531def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
532 (JAL tglobaladdr:$dst)>;
533def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
534 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000535def : Pat<(MipsJmpLink CPURegs:$dst),
536 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537
538// GlobalAddress, Constant Pool, ExternalSymbol, and JumpTable
539def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
540def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000541def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000542 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000543def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
544def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
545def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
546 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547
Eric Christopher7300ac12007-10-26 04:00:13 +0000548// Mips does not have not, so we increase the operation
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000549def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000550 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000551
Eric Christopher7300ac12007-10-26 04:00:13 +0000552// extended load and stores
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000553def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
555def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000557// peepholes
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000558def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
559
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000560///
561/// brcond patterns
562///
563
564// direct match equal/notequal zero branches
565def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000566 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000567def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
568 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000571 (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000573 (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000574
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000575def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
576 (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
577def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
578 (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
579
580def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
581 (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
582def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
583 (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
584
585def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586 (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000587def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
588 (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000589def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
590 (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
591def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
592 (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
593
594def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
595 (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
596def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
597 (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
598
599// generic brcond pattern
600def : Pat<(brcond CPURegs:$cond, bb:$dst),
601 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
602
603///
Eric Christopher7300ac12007-10-26 04:00:13 +0000604/// setcc patterns, only matched when there
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000605/// is no brcond following a setcc operation
606///
607
608// setcc 2 register operands
609def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
610 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
611def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
612 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
613
614def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
615 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
616def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
617 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
618
619def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
620 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
621def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
622 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
623
624def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000625 (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000626 (SLT CPURegs:$rhs, CPURegs:$lhs))>;
627
628def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000629 (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000630 (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000631
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000632// setcc reg/imm operands
633def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
634 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
635def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
636 (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;