blob: b1f975482aaa93b9f35089b285c3ac8f2f110b4a [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Bruno Cardoso Lopes and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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
25// Hi and Lo nodes are created to let easy manipulation of 16-bit when
26// handling 32-bit immediates. They are used on MipsISelLowering to
27// lower stuff like GlobalAddress, ExternalSymbol, ...
28// This two nodes have nothing to do with Mips Registers Hi and Lo.
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +000029def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp, [SDNPOutFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
31
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +000032// Necessary to generate glued instructions when loading GlobalAddress
33// into registers.
34def MipsAdd : SDNode<"MipsISD::Add", SDTIntBinOp, [SDNPCommutative,
35 SDNPAssociative, SDNPOptInFlag]>;
36
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037// Return
38def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
39def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
40 SDNPOptInFlag]>;
41
42// These are target-independent nodes, but have target-specific formats.
43def SDT_MipsCallSeq : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
44def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeq,
45 [SDNPHasChain, SDNPOutFlag]>;
46def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeq,
47 [SDNPHasChain, SDNPOutFlag]>;
48
49// Instruction operand types
50def brtarget : Operand<OtherVT>;
51def calltarget : Operand<i32>;
52def uimm16 : Operand<i32>;
53def simm16 : Operand<i32>;
54def shamt : Operand<i32>;
55
56// Address operand
57def mem : Operand<i32> {
58 let PrintMethod = "printMemOperand";
59 let MIOperandInfo = (ops simm16, CPURegs);
60}
61
62//===----------------------------------------------------------------------===//
63// Mips Patterns and Transformations
64//===----------------------------------------------------------------------===//
65
66// Transformation Function - get the lower 16 bits.
67def LO16 : SDNodeXForm<imm, [{
68 return getI32Imm((unsigned)N->getValue() & 0xFFFF);
69}]>;
70
71// Transformation Function - get the higher 16 bits.
72def HI16 : SDNodeXForm<imm, [{
73 return getI32Imm((unsigned)N->getValue() >> 16);
74}]>;
75
76// Node immediate fits as 16-bit sign extended on target immediate.
77// e.g. addi, andi
78def immSExt16 : PatLeaf<(imm), [{
79 if (N->getValueType(0) == MVT::i32)
80 return (int32_t)N->getValue() == (short)N->getValue();
81 else
82 return (int64_t)N->getValue() == (short)N->getValue();
83}]>;
84
85// Node immediate fits as 16-bit zero extended on target immediate.
86// The LO16 param means that only the lower 16 bits of the node
87// immediate are caught.
88// e.g. addiu, sltiu
89def immZExt16 : PatLeaf<(imm), [{
90 if (N->getValueType(0) == MVT::i32)
91 return (uint32_t)N->getValue() == (unsigned short)N->getValue();
92 else
93 return (uint64_t)N->getValue() == (unsigned short)N->getValue();
94}], LO16>;
95
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +000096// Node immediate fits as 32-bit zero extended on target immediate.
97//def immZExt32 : PatLeaf<(imm), [{
98// return (uint64_t)N->getValue() == (uint32_t)N->getValue();
99//}], LO16>;
100
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000101// shamt field must fit in 5 bits.
102def immZExt5 : PatLeaf<(imm), [{
103 return N->getValue() == ((N->getValue()) & 0x1f) ;
104}]>;
105
106// Mips Address Mode! SDNode frameindex could possibily be a match
107// since load and store instructions from stack used it.
108def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>;
109
110//===----------------------------------------------------------------------===//
111// Instructions specific format
112//===----------------------------------------------------------------------===//
113
114// Arithmetic 3 register operands
115let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000116class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
117 InstrItinClass itin>:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000118 FR< op,
119 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000120 (outs CPURegs:$dst),
121 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000123 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124
125let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000126class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127 FR< op,
128 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000129 (outs CPURegs:$dst),
130 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000131 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000132 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000133
134// Arithmetic 2 register operands
135let isCommutable = 1 in
136class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
137 Operand Od, PatLeaf imm_type> :
138 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000139 (outs CPURegs:$dst),
140 (ins CPURegs:$b, Od:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000141 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000142 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000143
144// Arithmetic Multiply ADD/SUB
145let rd=0 in
146class MArithR<bits<6> func, string instr_asm> :
147 FR< 0x1c,
148 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000149 (outs CPURegs:$rs),
150 (ins CPURegs:$rt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000151 !strconcat(instr_asm, " $rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000152 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000153
154// Logical
155class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
156 FR< 0x00,
157 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000158 (outs CPURegs:$dst),
159 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000161 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000162
163class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
164 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000165 (outs CPURegs:$dst),
166 (ins CPURegs:$b, uimm16:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000167 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000168 [(set CPURegs:$dst, (OpNode CPURegs:$b, immSExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169
170class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
171 FR< op,
172 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000173 (outs CPURegs:$dst),
174 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000175 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000176 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000177
178// Shifts
179let rt = 0 in
180class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
181 FR< 0x00,
182 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000183 (outs CPURegs:$dst),
184 (ins CPURegs:$b, shamt:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000186 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187
188class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
189 FR< 0x00,
190 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000191 (outs CPURegs:$dst),
192 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000193 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000194 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000195
196// Load Upper Imediate
197class LoadUpper<bits<6> op, string instr_asm>:
198 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000199 (outs CPURegs:$dst),
200 (ins uimm16:$imm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201 !strconcat(instr_asm, " $dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000202 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203
204// Memory Load/Store
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000205let isLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
207 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000208 (outs CPURegs:$dst),
209 (ins mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000211 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000212
213let isStore = 1 in
214class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
215 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000216 (outs),
217 (ins CPURegs:$dst, mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000219 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220
221// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000222let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000223class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
224 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000225 (outs),
226 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000227 !strconcat(instr_asm, " $a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000228 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
229 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000230
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000231
232class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
233 FI< op,
234 (outs),
235 (ins CPURegs:$src, brtarget:$offset),
236 !strconcat(instr_asm, " $src, $offset"),
237 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
238 IIBranch>;
239}
240
241// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
243 PatFrag cond_op>:
244 FR< op,
245 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000246 (outs CPURegs:$dst),
247 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000249 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
250 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251
252class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
253 Operand Od, PatLeaf imm_type>:
254 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000255 (outs CPURegs:$dst),
256 (ins CPURegs:$b, Od:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000258 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
259 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260
261// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000262let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263class JumpFJ<bits<6> op, string instr_asm>:
264 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000265 (outs),
266 (ins brtarget:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000267 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000268 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000270let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
272 FR< op,
273 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000274 (outs),
275 (ins CPURegs:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000277 [], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278
279// Jump and Link (Call)
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000280let isCall=1, hasDelaySlot=1,
281 // All calls clobber the non-callee saved registers...
282 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2,
283 T3, T4, T5, T6, T7, T8, T9, K0, K1, GP] in {
284 class JumpLink<bits<6> op, string instr_asm>:
285 FJ< op,
286 (outs),
287 (ins calltarget:$target),
288 !strconcat(instr_asm, " $target"),
289 [(MipsJmpLink imm:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000290
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000291 let rd=31 in
292 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
293 FR< op,
294 func,
295 (outs),
296 (ins CPURegs:$rs),
297 !strconcat(instr_asm, " $rs"),
298 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
299
300 class BranchLink<string instr_asm>:
301 FI< 0x1,
302 (outs),
303 (ins CPURegs:$rs, brtarget:$target),
304 !strconcat(instr_asm, " $rs, $target"),
305 [], IIBranch>;
306}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307
308// Mul, Div
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000309class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000310 FR< 0x00,
311 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000312 (outs),
313 (ins CPURegs:$a, CPURegs:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000314 !strconcat(instr_asm, " $a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000315 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316
317// Move from Hi/Lo
318class MoveFromTo<bits<6> func, string instr_asm>:
319 FR< 0x00,
320 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000321 (outs CPURegs:$dst),
322 (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323 !strconcat(instr_asm, " $dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000324 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000325
326// Count Leading Ones/Zeros in Word
327class CountLeading<bits<6> func, string instr_asm>:
328 FR< 0x1c,
329 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000330 (outs CPURegs:$dst),
331 (ins CPURegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332 !strconcat(instr_asm, " $dst, $src"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000333 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334
335
336//===----------------------------------------------------------------------===//
337// Pseudo instructions
338//===----------------------------------------------------------------------===//
339
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000340class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>:
341 MipsInst<outs, ins, asmstr, pattern, IIPseudo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342
343// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000344let Defs = [SP], Uses = [SP] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000345def ADJCALLSTACKDOWN : Pseudo<(outs), (ins uimm16:$amt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000346 "!ADJCALLSTACKDOWN $amt",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000347 [(callseq_start imm:$amt)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000348def ADJCALLSTACKUP : Pseudo<(outs), (ins uimm16:$amt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349 "!ADJCALLSTACKUP $amt",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000350 [(callseq_end imm:$amt)]>;
351}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352
Evan Chengb783fa32007-07-19 01:14:50 +0000353def IMPLICIT_DEF_CPURegs : Pseudo<(outs CPURegs:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354 "!IMPLICIT_DEF $dst",
355 [(set CPURegs:$dst, (undef))]>;
356
357//===----------------------------------------------------------------------===//
358// Instruction definition
359//===----------------------------------------------------------------------===//
360
361//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000362// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363//===----------------------------------------------------------------------===//
364
365// Arithmetic
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000366
367// ADDiu just accept 16-bit immediates but we handle this on Pat's.
368// immZExt32 is used here so it can match GlobalAddress immediates.
369def ADDiu : ArithI<0x09, "addiu", MipsAdd, uimm16, immZExt16>;
370def ADDi : ArithI<0x08, "addi", add, simm16, immSExt16>;
371def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
372def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
373def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000374def ADD : ArithOverflowR<0x00, 0x20, "add">;
375def SUB : ArithOverflowR<0x00, 0x22, "sub">;
376def MADD : MArithR<0x00, "madd">;
377def MADDU : MArithR<0x01, "maddu">;
378def MSUB : MArithR<0x04, "msub">;
379def MSUBU : MArithR<0x05, "msubu">;
380
381// Logical
382def AND : LogicR<0x24, "and", and>;
383def OR : LogicR<0x25, "or", or>;
384def XOR : LogicR<0x26, "xor", xor>;
385def ANDi : LogicI<0x0c, "andi", and>;
386def ORi : LogicI<0x0d, "ori", or>;
387def XORi : LogicI<0x0e, "xori", xor>;
388def NOR : LogicNOR<0x00, 0x27, "nor">;
389
390// Shifts
391def SLL : LogicR_shift_imm<0x00, "sll", shl>;
392def SRL : LogicR_shift_imm<0x02, "srl", srl>;
393def SRA : LogicR_shift_imm<0x03, "sra", sra>;
394def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
395def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
396def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
397
398// Load Upper Immediate
399def LUi : LoadUpper<0x0f, "lui">;
400
401// Load/Store
402def LB : LoadM<0x20, "lb", sextloadi8>;
403def LBu : LoadM<0x24, "lbu", zextloadi8>;
404def LH : LoadM<0x21, "lh", sextloadi16>;
405def LHu : LoadM<0x25, "lhu", zextloadi16>;
406def LW : LoadM<0x23, "lw", load>;
407def SB : StoreM<0x28, "sb", truncstorei8>;
408def SH : StoreM<0x29, "sh", truncstorei16>;
409def SW : StoreM<0x2b, "sw", store>;
410
411// Conditional Branch
412def BEQ : CBranch<0x04, "beq", seteq>;
413def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000414
415let rt=1 in
416def BGEZ : CBranchZero<0x01, "bgez", setge>;
417
418let rt=0 in {
419def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
420def BLEZ : CBranchZero<0x07, "blez", setle>;
421def BLTZ : CBranchZero<0x01, "bltz", setlt>;
422}
423
424// Set Condition Code
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000425def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
426def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
427def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
428def SLTiu : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
429
430// Unconditional jump
431def J : JumpFJ<0x02, "j">;
432def JR : JumpFR<0x00, 0x08, "jr">;
433
434// Jump and Link (Call)
435def JAL : JumpLink<0x03, "jal">;
436def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000437def BGEZAL : BranchLink<"bgezal">;
438def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439
440// MulDiv and Move From Hi/Lo operations, have
441// their correpondent SDNodes created on ISelDAG.
442// Special Mul, Div operations
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000443def MULT : MulDiv<0x18, "mult", IIImul>;
444def MULTu : MulDiv<0x19, "multu", IIImul>;
445def DIV : MulDiv<0x1a, "div", IIIdiv>;
446def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447
448// Move From Hi/Lo
449def MFHI : MoveFromTo<0x10, "mfhi">;
450def MFLO : MoveFromTo<0x12, "mflo">;
451def MTHI : MoveFromTo<0x11, "mthi">;
452def MTLO : MoveFromTo<0x13, "mtlo">;
453
454// Count Leading
455def CLO : CountLeading<0x21, "clo">;
456def CLZ : CountLeading<0x20, "clz">;
457
458// No operation
459let addr=0 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000460def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461
462// Ret instruction - as mips does not have "ret" a
463// jr $ra must be generated.
Evan Cheng37e7c752007-07-21 00:34:19 +0000464let isReturn=1, isTerminator=1, hasDelaySlot=1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000465 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
466{
Evan Chengb783fa32007-07-19 01:14:50 +0000467 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000468 "jr $target", [(MipsRet CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469}
470
471//===----------------------------------------------------------------------===//
472// Arbitrary patterns that map to one or more instructions
473//===----------------------------------------------------------------------===//
474
475// Small immediates
476def : Pat<(i32 immSExt16:$in),
477 (ADDiu ZERO, imm:$in)>;
478def : Pat<(i32 immZExt16:$in),
479 (ORi ZERO, imm:$in)>;
480
481// Arbitrary immediates
482def : Pat<(i32 imm:$imm),
483 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
484
485// Call
486def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
487 (JAL tglobaladdr:$dst)>;
488def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
489 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000490def : Pat<(MipsJmpLink CPURegs:$dst),
491 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492
493// GlobalAddress, Constant Pool, ExternalSymbol, and JumpTable
494def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
495def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000496def : Pat<(MipsAdd CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
497 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498
499// Mips does not have not, so we increase the operation
500def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000501 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000502
503// extended load and stores
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000504def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000505def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
506def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
507def : Pat<(truncstorei1 CPURegs:$src, addr:$addr),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000508 (SB CPURegs:$src, addr:$addr)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000510///
511/// brcond patterns
512///
513
514// direct match equal/notequal zero branches
515def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000516 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000517def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
518 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000521 (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000523 (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000525def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
526 (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
527def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
528 (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
529
530def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
531 (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
532def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
533 (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
534
535def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000536 (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
538 (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000539def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
540 (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
541def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
542 (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
543
544def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
545 (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
546def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
547 (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
548
549// generic brcond pattern
550def : Pat<(brcond CPURegs:$cond, bb:$dst),
551 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
552
553///
554/// setcc patterns, only matched when there
555/// is no brcond following a setcc operation
556///
557
558// setcc 2 register operands
559def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
560 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
561def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
562 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
563
564def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
565 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
566def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
567 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
568
569def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
570 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
571def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
572 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
573
574def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
575 (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
576 (SLT CPURegs:$rhs, CPURegs:$lhs))>;
577
578def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
579 (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
580 (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
581
582// setcc reg/imm operands
583def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
584 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
585def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
586 (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;
587