blob: 239542309984e3e0f3550c3e5121d961035d9f4e [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 Lopes2cacce92007-10-09 02:55:31 +000046//===----------------------------------------------------------------------===//
47// Mips Instruction Predicate Definitions.
48//===----------------------------------------------------------------------===//
49def IsStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">;
50
51//===----------------------------------------------------------------------===//
52// Mips Operand, Complex Patterns and Transformations Definitions.
53//===----------------------------------------------------------------------===//
54
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055// Instruction operand types
56def brtarget : Operand<OtherVT>;
57def calltarget : Operand<i32>;
58def uimm16 : Operand<i32>;
59def simm16 : Operand<i32>;
Eric Christopher7300ac12007-10-26 04:00:13 +000060def shamt : Operand<i32>;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000061def addrlabel : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062
63// Address operand
64def mem : Operand<i32> {
65 let PrintMethod = "printMemOperand";
66 let MIOperandInfo = (ops simm16, CPURegs);
67}
68
Dan Gohmanf17a25c2007-07-18 16:29:46 +000069// Transformation Function - get the lower 16 bits.
70def LO16 : SDNodeXForm<imm, [{
71 return getI32Imm((unsigned)N->getValue() & 0xFFFF);
72}]>;
73
74// Transformation Function - get the higher 16 bits.
75def HI16 : SDNodeXForm<imm, [{
76 return getI32Imm((unsigned)N->getValue() >> 16);
77}]>;
78
79// Node immediate fits as 16-bit sign extended on target immediate.
80// e.g. addi, andi
81def immSExt16 : PatLeaf<(imm), [{
82 if (N->getValueType(0) == MVT::i32)
83 return (int32_t)N->getValue() == (short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +000084 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +000085 return (int64_t)N->getValue() == (short)N->getValue();
86}]>;
87
88// Node immediate fits as 16-bit zero extended on target immediate.
89// The LO16 param means that only the lower 16 bits of the node
90// immediate are caught.
91// e.g. addiu, sltiu
92def immZExt16 : PatLeaf<(imm), [{
93 if (N->getValueType(0) == MVT::i32)
94 return (uint32_t)N->getValue() == (unsigned short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +000095 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +000096 return (uint64_t)N->getValue() == (unsigned short)N->getValue();
97}], LO16>;
98
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +000099// Node immediate fits as 32-bit zero extended on target immediate.
100//def immZExt32 : PatLeaf<(imm), [{
101// return (uint64_t)N->getValue() == (uint32_t)N->getValue();
102//}], LO16>;
103
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000104// shamt field must fit in 5 bits.
105def immZExt5 : PatLeaf<(imm), [{
106 return N->getValue() == ((N->getValue()) & 0x1f) ;
107}]>;
108
Eric Christopher7300ac12007-10-26 04:00:13 +0000109// Mips Address Mode! SDNode frameindex could possibily be a match
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000110// since load and store instructions from stack used it.
111def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>;
112
113//===----------------------------------------------------------------------===//
114// Instructions specific format
115//===----------------------------------------------------------------------===//
116
117// Arithmetic 3 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000118let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000119class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher7300ac12007-10-26 04:00:13 +0000120 InstrItinClass itin>:
121 FR< op,
122 func,
123 (outs CPURegs:$dst),
124 (ins CPURegs:$b, CPURegs:$c),
125 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000126 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127
Eric Christopher7300ac12007-10-26 04:00:13 +0000128let isCommutable = 1 in
129class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
130 FR< op,
131 func,
132 (outs CPURegs:$dst),
133 (ins CPURegs:$b, CPURegs:$c),
134 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000135 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000136
137// Arithmetic 2 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000138class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
139 Operand Od, PatLeaf imm_type> :
140 FI< op,
141 (outs CPURegs:$dst),
142 (ins CPURegs:$b, Od:$c),
143 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000144 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000145
146// Arithmetic Multiply ADD/SUB
147let rd=0 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000148class MArithR<bits<6> func, string instr_asm> :
149 FR< 0x1c,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000150 func,
Eric Christopher7300ac12007-10-26 04:00:13 +0000151 (outs CPURegs:$rs),
152 (ins CPURegs:$rt),
153 !strconcat(instr_asm, " $rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000154 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155
156// Logical
157class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000158 FR< 0x00,
159 func,
160 (outs CPURegs:$dst),
161 (ins CPURegs:$b, CPURegs:$c),
162 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000163 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164
165class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
166 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000167 (outs CPURegs:$dst),
168 (ins CPURegs:$b, uimm16:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000170 [(set CPURegs:$dst, (OpNode CPURegs:$b, immSExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171
172class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000173 FR< op,
174 func,
175 (outs CPURegs:$dst),
176 (ins CPURegs:$b, CPURegs:$c),
177 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000178 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179
180// Shifts
181let rt = 0 in
182class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000183 FR< 0x00,
184 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000185 (outs CPURegs:$dst),
186 (ins CPURegs:$b, shamt:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000187 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000188 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189
190class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000191 FR< 0x00,
192 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000193 (outs CPURegs:$dst),
194 (ins CPURegs:$b, CPURegs:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000195 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000196 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000197
198// Load Upper Imediate
199class LoadUpper<bits<6> op, string instr_asm>:
200 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000201 (outs CPURegs:$dst),
202 (ins uimm16:$imm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203 !strconcat(instr_asm, " $dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000204 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000205
Eric Christopher7300ac12007-10-26 04:00:13 +0000206// Memory Load/Store
Chris Lattner1a1932c2008-01-06 23:38:27 +0000207let isSimpleLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000208class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
209 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000210 (outs CPURegs:$dst),
211 (ins mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000212 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000213 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
216 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000217 (outs),
218 (ins CPURegs:$dst, mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000220 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000221
222// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000223let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
225 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000226 (outs),
227 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000228 !strconcat(instr_asm, " $a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000229 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
230 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000231
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000232
233class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
234 FI< op,
235 (outs),
236 (ins CPURegs:$src, brtarget:$offset),
237 !strconcat(instr_asm, " $src, $offset"),
238 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
239 IIBranch>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000240}
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000241
Eric Christopher7300ac12007-10-26 04:00:13 +0000242// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
244 PatFrag cond_op>:
245 FR< op,
246 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000247 (outs CPURegs:$dst),
248 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000249 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000250 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
251 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000252
253class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
254 Operand Od, PatLeaf imm_type>:
255 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000256 (outs CPURegs:$dst),
257 (ins CPURegs:$b, Od:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000258 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000259 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
260 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261
262// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000263let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264class JumpFJ<bits<6> op, string instr_asm>:
265 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000266 (outs),
267 (ins brtarget:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000269 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000270
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000271let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
273 FR< op,
274 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000275 (outs),
276 (ins CPURegs:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000277 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000278 [(brind CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279
280// Jump and Link (Call)
Eric Christopher7300ac12007-10-26 04:00:13 +0000281let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000282 // All calls clobber the non-callee saved registers...
Eric Christopher7300ac12007-10-26 04:00:13 +0000283 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2,
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000284 T3, T4, T5, T6, T7, T8, T9, K0, K1], Uses = [GP] in {
Eric Christopher7300ac12007-10-26 04:00:13 +0000285 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000286 FJ< op,
287 (outs),
288 (ins calltarget:$target),
289 !strconcat(instr_asm, " $target"),
290 [(MipsJmpLink imm:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000292 let rd=31 in
293 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
294 FR< op,
295 func,
296 (outs),
297 (ins CPURegs:$rs),
298 !strconcat(instr_asm, " $rs"),
299 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
300
301 class BranchLink<string instr_asm>:
302 FI< 0x1,
303 (outs),
304 (ins CPURegs:$rs, brtarget:$target),
305 !strconcat(instr_asm, " $rs, $target"),
306 [], IIBranch>;
307}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000308
Eric Christopher7300ac12007-10-26 04:00:13 +0000309// Mul, Div
310class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
311 FR< 0x00,
312 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000313 (outs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000314 (ins CPURegs:$a, CPURegs:$b),
315 !strconcat(instr_asm, " $a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000316 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317
Eric Christopher7300ac12007-10-26 04:00:13 +0000318// Move from Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000319class MoveFromTo<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000320 FR< 0x00,
321 func,
322 (outs CPURegs:$dst),
Evan Chengb783fa32007-07-19 01:14:50 +0000323 (ins),
Eric Christopher7300ac12007-10-26 04:00:13 +0000324 !strconcat(instr_asm, " $dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000325 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326
327// Count Leading Ones/Zeros in Word
328class CountLeading<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000329 FR< 0x1c,
330 func,
331 (outs CPURegs:$dst),
332 (ins CPURegs:$src),
333 !strconcat(instr_asm, " $dst, $src"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000334 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335
Eric Christopher7300ac12007-10-26 04:00:13 +0000336class EffectiveAddress<string instr_asm> :
337 FI<0x09,
338 (outs CPURegs:$dst),
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000339 (ins mem:$addr),
340 instr_asm,
341 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342
343//===----------------------------------------------------------------------===//
344// Pseudo instructions
345//===----------------------------------------------------------------------===//
346
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000347// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000348let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000349def ADJCALLSTACKDOWN : PseudoInstMips<(outs), (ins uimm16:$amt),
350 "!ADJCALLSTACKDOWN $amt",
351 [(callseq_start imm:$amt)]>;
Bill Wendling22f8deb2007-11-13 00:44:25 +0000352def ADJCALLSTACKUP : PseudoInstMips<(outs), (ins uimm16:$amt1, uimm16:$amt2),
353 "!ADJCALLSTACKUP $amt1",
354 [(callseq_end imm:$amt1, imm:$amt2)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000355}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356
Eric Christopher7300ac12007-10-26 04:00:13 +0000357// When handling PIC code the assembler needs .cpload and .cprestore
358// directives. If the real instructions corresponding these directives
359// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000360// from the assembler.
Eric Christopher7300ac12007-10-26 04:00:13 +0000361def CPLOAD: PseudoInstMips<(outs), (ins CPURegs:$reg),
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000362 ".set noreorder\n\t.cpload $reg\n\t.set reorder\n", []>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000363def CPRESTORE: PseudoInstMips<(outs), (ins uimm16:$loc),
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000364 ".cprestore $loc\n", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000365
366//===----------------------------------------------------------------------===//
367// Instruction definition
368//===----------------------------------------------------------------------===//
369
370//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000371// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000372//===----------------------------------------------------------------------===//
373
374// Arithmetic
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000375
376// ADDiu just accept 16-bit immediates but we handle this on Pat's.
377// immZExt32 is used here so it can match GlobalAddress immediates.
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000378def ADDiu : ArithI<0x09, "addiu", add, uimm16, immZExt16>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000379def ADDi : ArithI<0x08, "addi", add, simm16, immSExt16>;
380def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
381def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
382def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000383def ADD : ArithOverflowR<0x00, 0x20, "add">;
384def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385
386// Logical
387def AND : LogicR<0x24, "and", and>;
388def OR : LogicR<0x25, "or", or>;
389def XOR : LogicR<0x26, "xor", xor>;
390def ANDi : LogicI<0x0c, "andi", and>;
391def ORi : LogicI<0x0d, "ori", or>;
392def XORi : LogicI<0x0e, "xori", xor>;
393def NOR : LogicNOR<0x00, 0x27, "nor">;
394
Eric Christopher7300ac12007-10-26 04:00:13 +0000395// Shifts
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000396def SLL : LogicR_shift_imm<0x00, "sll", shl>;
397def SRL : LogicR_shift_imm<0x02, "srl", srl>;
398def SRA : LogicR_shift_imm<0x03, "sra", sra>;
399def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
400def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
401def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
402
403// Load Upper Immediate
404def LUi : LoadUpper<0x0f, "lui">;
405
406// Load/Store
407def LB : LoadM<0x20, "lb", sextloadi8>;
408def LBu : LoadM<0x24, "lbu", zextloadi8>;
409def LH : LoadM<0x21, "lh", sextloadi16>;
410def LHu : LoadM<0x25, "lhu", zextloadi16>;
411def LW : LoadM<0x23, "lw", load>;
412def SB : StoreM<0x28, "sb", truncstorei8>;
413def SH : StoreM<0x29, "sh", truncstorei16>;
414def SW : StoreM<0x2b, "sw", store>;
415
416// Conditional Branch
417def BEQ : CBranch<0x04, "beq", seteq>;
418def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000419
Eric Christopher7300ac12007-10-26 04:00:13 +0000420let rt=1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000421def BGEZ : CBranchZero<0x01, "bgez", setge>;
422
423let rt=0 in {
424def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
425def BLEZ : CBranchZero<0x07, "blez", setle>;
426def BLTZ : CBranchZero<0x01, "bltz", setlt>;
427}
428
429// Set Condition Code
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000430def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
431def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
432def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
433def SLTiu : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
434
435// Unconditional jump
436def J : JumpFJ<0x02, "j">;
437def JR : JumpFR<0x00, 0x08, "jr">;
438
439// Jump and Link (Call)
440def JAL : JumpLink<0x03, "jal">;
441def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000442def BGEZAL : BranchLink<"bgezal">;
443def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444
445// MulDiv and Move From Hi/Lo operations, have
446// their correpondent SDNodes created on ISelDAG.
447// Special Mul, Div operations
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000448def MULT : MulDiv<0x18, "mult", IIImul>;
449def MULTu : MulDiv<0x19, "multu", IIImul>;
450def DIV : MulDiv<0x1a, "div", IIIdiv>;
451def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452
Eric Christopher7300ac12007-10-26 04:00:13 +0000453// Move From Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000454def MFHI : MoveFromTo<0x10, "mfhi">;
455def MFLO : MoveFromTo<0x12, "mflo">;
456def MTHI : MoveFromTo<0x11, "mthi">;
457def MTLO : MoveFromTo<0x13, "mtlo">;
458
459// Count Leading
Eric Christopher7300ac12007-10-26 04:00:13 +0000460// CLO/CLZ are part of the newer MIPS32(tm) instruction
461// set and not older Mips I keep this for future use
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000462// though.
Eric Christopher7300ac12007-10-26 04:00:13 +0000463//def CLO : CountLeading<0x21, "clo">;
464//def CLZ : CountLeading<0x20, "clz">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000465
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000466// MADD*/MSUB* are not part of MipsI either.
467//def MADD : MArithR<0x00, "madd">;
468//def MADDU : MArithR<0x01, "maddu">;
469//def MSUB : MArithR<0x04, "msub">;
470//def MSUBU : MArithR<0x05, "msubu">;
471
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472// No operation
473let addr=0 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000474def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475
Eric Christopher7300ac12007-10-26 04:00:13 +0000476// Ret instruction - as mips does not have "ret" a
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477// jr $ra must be generated.
Evan Cheng37e7c752007-07-21 00:34:19 +0000478let isReturn=1, isTerminator=1, hasDelaySlot=1,
Eric Christopher7300ac12007-10-26 04:00:13 +0000479 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480{
Evan Chengb783fa32007-07-19 01:14:50 +0000481 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000482 "jr $target", [(MipsRet CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483}
484
Eric Christopher7300ac12007-10-26 04:00:13 +0000485// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000486// instructions. The same not happens for stack address copies, so an
487// add op with mem ComplexPattern is used and the stack address copy
488// can be matched. It's similar to Sparc LEA_ADDRi
489def LEA_ADDiu : EffectiveAddress<"addiu $dst, ${addr:stackloc}">;
490
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000491//===----------------------------------------------------------------------===//
492// Arbitrary patterns that map to one or more instructions
493//===----------------------------------------------------------------------===//
494
495// Small immediates
Eric Christopher7300ac12007-10-26 04:00:13 +0000496def : Pat<(i32 immSExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497 (ADDiu ZERO, imm:$in)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000498def : Pat<(i32 immZExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499 (ORi ZERO, imm:$in)>;
500
501// Arbitrary immediates
502def : Pat<(i32 imm:$imm),
503 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
504
505// Call
506def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
507 (JAL tglobaladdr:$dst)>;
508def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
509 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000510def : Pat<(MipsJmpLink CPURegs:$dst),
511 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512
513// GlobalAddress, Constant Pool, ExternalSymbol, and JumpTable
514def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
515def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000516def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000517 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000518def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
519def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
520def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
521 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522
Eric Christopher7300ac12007-10-26 04:00:13 +0000523// Mips does not have not, so we increase the operation
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000525 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526
Eric Christopher7300ac12007-10-26 04:00:13 +0000527// extended load and stores
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000528def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000529def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
530def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000531
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000532// some peepholes
533def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
534
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000535///
536/// brcond patterns
537///
538
539// direct match equal/notequal zero branches
540def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000542def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
543 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000546 (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000548 (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000549
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000550def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
551 (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
552def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
553 (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
554
555def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
556 (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
557def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
558 (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
559
560def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561 (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
563 (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000564def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
565 (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
566def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
567 (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
568
569def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
570 (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
571def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
572 (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
573
574// generic brcond pattern
575def : Pat<(brcond CPURegs:$cond, bb:$dst),
576 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
577
578///
Eric Christopher7300ac12007-10-26 04:00:13 +0000579/// setcc patterns, only matched when there
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000580/// is no brcond following a setcc operation
581///
582
583// setcc 2 register operands
584def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
585 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
586def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
587 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
588
589def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
590 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
591def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
592 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
593
594def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
595 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
596def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
597 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
598
599def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000600 (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000601 (SLT CPURegs:$rhs, CPURegs:$lhs))>;
602
603def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000604 (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000605 (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000606
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000607// setcc reg/imm operands
608def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
609 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
610def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
611 (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;