blob: 43313e21061c052ff2265fee8d3bff20f96ac8f4 [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
138let isCommutable = 1 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000139class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
140 Operand Od, PatLeaf imm_type> :
141 FI< op,
142 (outs CPURegs:$dst),
143 (ins CPURegs:$b, Od:$c),
144 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000145 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000146
147// Arithmetic Multiply ADD/SUB
148let rd=0 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000149class MArithR<bits<6> func, string instr_asm> :
150 FR< 0x1c,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000151 func,
Eric Christopher7300ac12007-10-26 04:00:13 +0000152 (outs CPURegs:$rs),
153 (ins CPURegs:$rt),
154 !strconcat(instr_asm, " $rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000155 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000156
157// Logical
158class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000159 FR< 0x00,
160 func,
161 (outs CPURegs:$dst),
162 (ins CPURegs:$b, CPURegs:$c),
163 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000164 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000165
166class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
167 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000168 (outs CPURegs:$dst),
169 (ins CPURegs:$b, uimm16:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000171 [(set CPURegs:$dst, (OpNode CPURegs:$b, immSExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000172
173class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000174 FR< op,
175 func,
176 (outs CPURegs:$dst),
177 (ins CPURegs:$b, CPURegs:$c),
178 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000179 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000180
181// Shifts
182let rt = 0 in
183class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000184 FR< 0x00,
185 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000186 (outs CPURegs:$dst),
187 (ins CPURegs:$b, shamt:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000188 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000189 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000190
191class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000192 FR< 0x00,
193 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000194 (outs CPURegs:$dst),
195 (ins CPURegs:$b, CPURegs:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000196 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000197 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000198
199// Load Upper Imediate
200class LoadUpper<bits<6> op, string instr_asm>:
201 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000202 (outs CPURegs:$dst),
203 (ins uimm16:$imm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000204 !strconcat(instr_asm, " $dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000205 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206
Eric Christopher7300ac12007-10-26 04:00:13 +0000207// Memory Load/Store
Chris Lattner1a1932c2008-01-06 23:38:27 +0000208let isSimpleLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
210 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000211 (outs CPURegs:$dst),
212 (ins mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000214 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
217 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000218 (outs),
219 (ins CPURegs:$dst, mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000221 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000222
223// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000224let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000225class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
226 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000227 (outs),
228 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229 !strconcat(instr_asm, " $a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000230 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
231 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000233
234class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
235 FI< op,
236 (outs),
237 (ins CPURegs:$src, brtarget:$offset),
238 !strconcat(instr_asm, " $src, $offset"),
239 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
240 IIBranch>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000241}
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000242
Eric Christopher7300ac12007-10-26 04:00:13 +0000243// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
245 PatFrag cond_op>:
246 FR< op,
247 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000248 (outs CPURegs:$dst),
249 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000250 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000251 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
252 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000253
254class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
255 Operand Od, PatLeaf imm_type>:
256 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000257 (outs CPURegs:$dst),
258 (ins CPURegs:$b, Od:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000260 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
261 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000262
263// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000264let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000265class JumpFJ<bits<6> op, string instr_asm>:
266 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000267 (outs),
268 (ins brtarget:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000270 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000272let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
274 FR< op,
275 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000276 (outs),
277 (ins CPURegs:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000279 [(brind CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280
281// Jump and Link (Call)
Eric Christopher7300ac12007-10-26 04:00:13 +0000282let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000283 // All calls clobber the non-callee saved registers...
Eric Christopher7300ac12007-10-26 04:00:13 +0000284 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2,
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000285 T3, T4, T5, T6, T7, T8, T9, K0, K1], Uses = [GP] in {
Eric Christopher7300ac12007-10-26 04:00:13 +0000286 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000287 FJ< op,
288 (outs),
289 (ins calltarget:$target),
290 !strconcat(instr_asm, " $target"),
291 [(MipsJmpLink imm:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000293 let rd=31 in
294 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
295 FR< op,
296 func,
297 (outs),
298 (ins CPURegs:$rs),
299 !strconcat(instr_asm, " $rs"),
300 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
301
302 class BranchLink<string instr_asm>:
303 FI< 0x1,
304 (outs),
305 (ins CPURegs:$rs, brtarget:$target),
306 !strconcat(instr_asm, " $rs, $target"),
307 [], IIBranch>;
308}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309
Eric Christopher7300ac12007-10-26 04:00:13 +0000310// Mul, Div
311class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
312 FR< 0x00,
313 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000314 (outs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000315 (ins CPURegs:$a, CPURegs:$b),
316 !strconcat(instr_asm, " $a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000317 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000318
Eric Christopher7300ac12007-10-26 04:00:13 +0000319// Move from Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000320class MoveFromTo<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000321 FR< 0x00,
322 func,
323 (outs CPURegs:$dst),
Evan Chengb783fa32007-07-19 01:14:50 +0000324 (ins),
Eric Christopher7300ac12007-10-26 04:00:13 +0000325 !strconcat(instr_asm, " $dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000326 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000327
328// Count Leading Ones/Zeros in Word
329class CountLeading<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000330 FR< 0x1c,
331 func,
332 (outs CPURegs:$dst),
333 (ins CPURegs:$src),
334 !strconcat(instr_asm, " $dst, $src"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000335 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000336
Eric Christopher7300ac12007-10-26 04:00:13 +0000337class EffectiveAddress<string instr_asm> :
338 FI<0x09,
339 (outs CPURegs:$dst),
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000340 (ins mem:$addr),
341 instr_asm,
342 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343
344//===----------------------------------------------------------------------===//
345// Pseudo instructions
346//===----------------------------------------------------------------------===//
347
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000349let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000350def ADJCALLSTACKDOWN : PseudoInstMips<(outs), (ins uimm16:$amt),
351 "!ADJCALLSTACKDOWN $amt",
352 [(callseq_start imm:$amt)]>;
Bill Wendling22f8deb2007-11-13 00:44:25 +0000353def ADJCALLSTACKUP : PseudoInstMips<(outs), (ins uimm16:$amt1, uimm16:$amt2),
354 "!ADJCALLSTACKUP $amt1",
355 [(callseq_end imm:$amt1, imm:$amt2)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000356}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357
Evan Chenge399fbb2007-12-12 23:12:09 +0000358let isImplicitDef = 1 in
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000359def IMPLICIT_DEF_CPURegs : PseudoInstMips<(outs CPURegs:$dst), (ins),
360 "!IMPLICIT_DEF $dst",
361 [(set CPURegs:$dst, (undef))]>;
362
Eric Christopher7300ac12007-10-26 04:00:13 +0000363// When handling PIC code the assembler needs .cpload and .cprestore
364// directives. If the real instructions corresponding these directives
365// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000366// from the assembler.
Eric Christopher7300ac12007-10-26 04:00:13 +0000367def CPLOAD: PseudoInstMips<(outs), (ins CPURegs:$reg),
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000368 ".set noreorder\n\t.cpload $reg\n\t.set reorder\n", []>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000369def CPRESTORE: PseudoInstMips<(outs), (ins uimm16:$loc),
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000370 ".cprestore $loc\n", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000371
372//===----------------------------------------------------------------------===//
373// Instruction definition
374//===----------------------------------------------------------------------===//
375
376//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000377// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000378//===----------------------------------------------------------------------===//
379
380// Arithmetic
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000381
382// ADDiu just accept 16-bit immediates but we handle this on Pat's.
383// immZExt32 is used here so it can match GlobalAddress immediates.
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000384def ADDiu : ArithI<0x09, "addiu", add, uimm16, immZExt16>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000385def ADDi : ArithI<0x08, "addi", add, simm16, immSExt16>;
386def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
387def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
388def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389def ADD : ArithOverflowR<0x00, 0x20, "add">;
390def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391
392// Logical
393def AND : LogicR<0x24, "and", and>;
394def OR : LogicR<0x25, "or", or>;
395def XOR : LogicR<0x26, "xor", xor>;
396def ANDi : LogicI<0x0c, "andi", and>;
397def ORi : LogicI<0x0d, "ori", or>;
398def XORi : LogicI<0x0e, "xori", xor>;
399def NOR : LogicNOR<0x00, 0x27, "nor">;
400
Eric Christopher7300ac12007-10-26 04:00:13 +0000401// Shifts
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000402def SLL : LogicR_shift_imm<0x00, "sll", shl>;
403def SRL : LogicR_shift_imm<0x02, "srl", srl>;
404def SRA : LogicR_shift_imm<0x03, "sra", sra>;
405def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
406def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
407def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
408
409// Load Upper Immediate
410def LUi : LoadUpper<0x0f, "lui">;
411
412// Load/Store
413def LB : LoadM<0x20, "lb", sextloadi8>;
414def LBu : LoadM<0x24, "lbu", zextloadi8>;
415def LH : LoadM<0x21, "lh", sextloadi16>;
416def LHu : LoadM<0x25, "lhu", zextloadi16>;
417def LW : LoadM<0x23, "lw", load>;
418def SB : StoreM<0x28, "sb", truncstorei8>;
419def SH : StoreM<0x29, "sh", truncstorei16>;
420def SW : StoreM<0x2b, "sw", store>;
421
422// Conditional Branch
423def BEQ : CBranch<0x04, "beq", seteq>;
424def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000425
Eric Christopher7300ac12007-10-26 04:00:13 +0000426let rt=1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000427def BGEZ : CBranchZero<0x01, "bgez", setge>;
428
429let rt=0 in {
430def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
431def BLEZ : CBranchZero<0x07, "blez", setle>;
432def BLTZ : CBranchZero<0x01, "bltz", setlt>;
433}
434
435// Set Condition Code
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000436def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
437def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
438def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
439def SLTiu : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
440
441// Unconditional jump
442def J : JumpFJ<0x02, "j">;
443def JR : JumpFR<0x00, 0x08, "jr">;
444
445// Jump and Link (Call)
446def JAL : JumpLink<0x03, "jal">;
447def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000448def BGEZAL : BranchLink<"bgezal">;
449def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450
451// MulDiv and Move From Hi/Lo operations, have
452// their correpondent SDNodes created on ISelDAG.
453// Special Mul, Div operations
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000454def MULT : MulDiv<0x18, "mult", IIImul>;
455def MULTu : MulDiv<0x19, "multu", IIImul>;
456def DIV : MulDiv<0x1a, "div", IIIdiv>;
457def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458
Eric Christopher7300ac12007-10-26 04:00:13 +0000459// Move From Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000460def MFHI : MoveFromTo<0x10, "mfhi">;
461def MFLO : MoveFromTo<0x12, "mflo">;
462def MTHI : MoveFromTo<0x11, "mthi">;
463def MTLO : MoveFromTo<0x13, "mtlo">;
464
465// Count Leading
Eric Christopher7300ac12007-10-26 04:00:13 +0000466// CLO/CLZ are part of the newer MIPS32(tm) instruction
467// set and not older Mips I keep this for future use
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000468// though.
Eric Christopher7300ac12007-10-26 04:00:13 +0000469//def CLO : CountLeading<0x21, "clo">;
470//def CLZ : CountLeading<0x20, "clz">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000471
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000472// MADD*/MSUB* are not part of MipsI either.
473//def MADD : MArithR<0x00, "madd">;
474//def MADDU : MArithR<0x01, "maddu">;
475//def MSUB : MArithR<0x04, "msub">;
476//def MSUBU : MArithR<0x05, "msubu">;
477
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478// No operation
479let addr=0 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000480def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481
Eric Christopher7300ac12007-10-26 04:00:13 +0000482// Ret instruction - as mips does not have "ret" a
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483// jr $ra must be generated.
Evan Cheng37e7c752007-07-21 00:34:19 +0000484let isReturn=1, isTerminator=1, hasDelaySlot=1,
Eric Christopher7300ac12007-10-26 04:00:13 +0000485 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486{
Evan Chengb783fa32007-07-19 01:14:50 +0000487 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000488 "jr $target", [(MipsRet CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489}
490
Eric Christopher7300ac12007-10-26 04:00:13 +0000491// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000492// instructions. The same not happens for stack address copies, so an
493// add op with mem ComplexPattern is used and the stack address copy
494// can be matched. It's similar to Sparc LEA_ADDRi
495def LEA_ADDiu : EffectiveAddress<"addiu $dst, ${addr:stackloc}">;
496
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497//===----------------------------------------------------------------------===//
498// Arbitrary patterns that map to one or more instructions
499//===----------------------------------------------------------------------===//
500
501// Small immediates
Eric Christopher7300ac12007-10-26 04:00:13 +0000502def : Pat<(i32 immSExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000503 (ADDiu ZERO, imm:$in)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000504def : Pat<(i32 immZExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000505 (ORi ZERO, imm:$in)>;
506
507// Arbitrary immediates
508def : Pat<(i32 imm:$imm),
509 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
510
511// Call
512def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
513 (JAL tglobaladdr:$dst)>;
514def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
515 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000516def : Pat<(MipsJmpLink CPURegs:$dst),
517 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518
519// GlobalAddress, Constant Pool, ExternalSymbol, and JumpTable
520def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
521def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000522def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000523 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000524def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
525def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
526def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
527 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528
Eric Christopher7300ac12007-10-26 04:00:13 +0000529// Mips does not have not, so we increase the operation
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000531 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532
Eric Christopher7300ac12007-10-26 04:00:13 +0000533// extended load and stores
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000534def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
536def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000537def : Pat<(truncstorei1 CPURegs:$src, addr:$addr),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000538 (SB CPURegs:$src, addr:$addr)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000540// some peepholes
541def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
542
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000543///
544/// brcond patterns
545///
546
547// direct match equal/notequal zero branches
548def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000549 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000550def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
551 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000552
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000554 (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000556 (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000558def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
559 (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
560def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
561 (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
562
563def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
564 (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
565def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
566 (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
567
568def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569 (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
571 (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000572def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
573 (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
574def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
575 (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
576
577def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
578 (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
579def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
580 (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
581
582// generic brcond pattern
583def : Pat<(brcond CPURegs:$cond, bb:$dst),
584 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
585
586///
Eric Christopher7300ac12007-10-26 04:00:13 +0000587/// setcc patterns, only matched when there
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000588/// is no brcond following a setcc operation
589///
590
591// setcc 2 register operands
592def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
593 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
594def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
595 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
596
597def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
598 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
599def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
600 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
601
602def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
603 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
604def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
605 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
606
607def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000608 (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000609 (SLT CPURegs:$rhs, CPURegs:$lhs))>;
610
611def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000612 (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000613 (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000614
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000615// setcc reg/imm operands
616def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
617 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
618def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
619 (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;