blob: 0e0af5d45a1ef5732a68003cbde38ba21567e0cd [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
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000020def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
21def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
22def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
23 SDTCisSameAs<1, 2>, SDTCisInt<3>]>;
24def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
25def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
26
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027// Call
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000028def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, [SDNPHasChain,
29 SDNPOutFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +000031// Hi and Lo nodes are used to handle global addresses. Used on
32// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
33// static model. (nothing to do with Mips Registers Hi and Lo)
34def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp, [SDNPOutFlag]>;
35def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000036
Eric Christopher7300ac12007-10-26 04:00:13 +000037// Return
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000038def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
39 SDNPOptInFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040
41// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000042def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
43 [SDNPHasChain, SDNPOutFlag]>;
44def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
45 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Bill Wendling22f8deb2007-11-13 00:44:25 +000046
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000047// Select Condition Code
48def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +000049
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000050//===----------------------------------------------------------------------===//
51// Mips Instruction Predicate Definitions.
52//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesdfd657f2008-07-09 05:32:22 +000053def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000054
55//===----------------------------------------------------------------------===//
56// Mips Operand, Complex Patterns and Transformations Definitions.
57//===----------------------------------------------------------------------===//
58
Dan Gohmanf17a25c2007-07-18 16:29:46 +000059// Instruction operand types
60def brtarget : Operand<OtherVT>;
61def calltarget : Operand<i32>;
62def uimm16 : Operand<i32>;
63def simm16 : Operand<i32>;
Eric Christopher7300ac12007-10-26 04:00:13 +000064def shamt : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065
66// Address operand
67def mem : Operand<i32> {
68 let PrintMethod = "printMemOperand";
69 let MIOperandInfo = (ops simm16, CPURegs);
70}
71
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072// Transformation Function - get the lower 16 bits.
73def LO16 : SDNodeXForm<imm, [{
74 return getI32Imm((unsigned)N->getValue() & 0xFFFF);
75}]>;
76
77// Transformation Function - get the higher 16 bits.
78def HI16 : SDNodeXForm<imm, [{
79 return getI32Imm((unsigned)N->getValue() >> 16);
80}]>;
81
82// Node immediate fits as 16-bit sign extended on target immediate.
83// e.g. addi, andi
84def immSExt16 : PatLeaf<(imm), [{
85 if (N->getValueType(0) == MVT::i32)
86 return (int32_t)N->getValue() == (short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +000087 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +000088 return (int64_t)N->getValue() == (short)N->getValue();
89}]>;
90
91// Node immediate fits as 16-bit zero extended on target immediate.
92// The LO16 param means that only the lower 16 bits of the node
93// immediate are caught.
94// e.g. addiu, sltiu
95def immZExt16 : PatLeaf<(imm), [{
96 if (N->getValueType(0) == MVT::i32)
97 return (uint32_t)N->getValue() == (unsigned short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +000098 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +000099 return (uint64_t)N->getValue() == (unsigned short)N->getValue();
100}], LO16>;
101
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000102// Node immediate fits as 32-bit zero extended on target immediate.
103//def immZExt32 : PatLeaf<(imm), [{
104// return (uint64_t)N->getValue() == (uint32_t)N->getValue();
105//}], LO16>;
106
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000107// shamt field must fit in 5 bits.
108def immZExt5 : PatLeaf<(imm), [{
109 return N->getValue() == ((N->getValue()) & 0x1f) ;
110}]>;
111
Eric Christopher7300ac12007-10-26 04:00:13 +0000112// Mips Address Mode! SDNode frameindex could possibily be a match
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000113// since load and store instructions from stack used it.
114def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>;
115
116//===----------------------------------------------------------------------===//
117// Instructions specific format
118//===----------------------------------------------------------------------===//
119
120// Arithmetic 3 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000121let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000122class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher7300ac12007-10-26 04:00:13 +0000123 InstrItinClass itin>:
124 FR< op,
125 func,
126 (outs CPURegs:$dst),
127 (ins CPURegs:$b, CPURegs:$c),
128 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000129 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000130
Eric Christopher7300ac12007-10-26 04:00:13 +0000131let isCommutable = 1 in
132class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
133 FR< op,
134 func,
135 (outs CPURegs:$dst),
136 (ins CPURegs:$b, CPURegs:$c),
137 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000138 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000139
140// Arithmetic 2 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000141class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
142 Operand Od, PatLeaf imm_type> :
143 FI< op,
144 (outs CPURegs:$dst),
145 (ins CPURegs:$b, Od:$c),
146 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000147 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000148
149// Arithmetic Multiply ADD/SUB
150let rd=0 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000151class MArithR<bits<6> func, string instr_asm> :
152 FR< 0x1c,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000153 func,
Eric Christopher7300ac12007-10-26 04:00:13 +0000154 (outs CPURegs:$rs),
155 (ins CPURegs:$rt),
156 !strconcat(instr_asm, " $rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000157 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158
159// Logical
160class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000161 FR< 0x00,
162 func,
163 (outs CPURegs:$dst),
164 (ins CPURegs:$b, CPURegs:$c),
165 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000166 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000167
168class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
169 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000170 (outs CPURegs:$dst),
171 (ins CPURegs:$b, uimm16:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000172 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopesf2377552008-06-06 06:37:31 +0000173 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000174
175class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000176 FR< op,
177 func,
178 (outs CPURegs:$dst),
179 (ins CPURegs:$b, CPURegs:$c),
180 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000181 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000182
183// Shifts
184let rt = 0 in
185class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000186 FR< 0x00,
187 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000188 (outs CPURegs:$dst),
189 (ins CPURegs:$b, shamt:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000190 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000191 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192
193class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000194 FR< 0x00,
195 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000196 (outs CPURegs:$dst),
197 (ins CPURegs:$b, CPURegs:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000198 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000199 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000200
201// Load Upper Imediate
202class LoadUpper<bits<6> op, string instr_asm>:
203 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000204 (outs CPURegs:$dst),
205 (ins uimm16:$imm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206 !strconcat(instr_asm, " $dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000207 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000208
Eric Christopher7300ac12007-10-26 04:00:13 +0000209// Memory Load/Store
Chris Lattner1a1932c2008-01-06 23:38:27 +0000210let isSimpleLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000211class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
212 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000213 (outs CPURegs:$dst),
214 (ins mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000216 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
219 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000220 (outs),
221 (ins CPURegs:$dst, mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000222 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000223 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224
225// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000226let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000227class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
228 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000229 (outs),
230 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000231 !strconcat(instr_asm, " $a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000232 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
233 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000235
236class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
237 FI< op,
238 (outs),
239 (ins CPURegs:$src, brtarget:$offset),
240 !strconcat(instr_asm, " $src, $offset"),
241 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
242 IIBranch>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000243}
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000244
Eric Christopher7300ac12007-10-26 04:00:13 +0000245// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000246class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
247 PatFrag cond_op>:
248 FR< op,
249 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000250 (outs CPURegs:$dst),
251 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000252 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000253 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
254 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000255
256class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
257 Operand Od, PatLeaf imm_type>:
258 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000259 (outs CPURegs:$dst),
260 (ins CPURegs:$b, Od:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000262 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
263 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264
265// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000266let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000267class JumpFJ<bits<6> op, string instr_asm>:
268 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000269 (outs),
270 (ins brtarget:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000272 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000274let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
276 FR< op,
277 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000278 (outs),
279 (ins CPURegs:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000281 [(brind CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282
283// Jump and Link (Call)
Eric Christopher7300ac12007-10-26 04:00:13 +0000284let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000285 // All calls clobber the non-callee saved registers...
Eric Christopher7300ac12007-10-26 04:00:13 +0000286 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2,
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000287 T3, T4, T5, T6, T7, T8, T9, K0, K1], Uses = [GP] in {
Eric Christopher7300ac12007-10-26 04:00:13 +0000288 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000289 FJ< op,
290 (outs),
291 (ins calltarget:$target),
292 !strconcat(instr_asm, " $target"),
293 [(MipsJmpLink imm:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000295 let rd=31 in
296 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
297 FR< op,
298 func,
299 (outs),
300 (ins CPURegs:$rs),
301 !strconcat(instr_asm, " $rs"),
302 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
303
304 class BranchLink<string instr_asm>:
305 FI< 0x1,
306 (outs),
307 (ins CPURegs:$rs, brtarget:$target),
308 !strconcat(instr_asm, " $rs, $target"),
309 [], IIBranch>;
310}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311
Eric Christopher7300ac12007-10-26 04:00:13 +0000312// Mul, Div
313class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
314 FR< 0x00,
315 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000316 (outs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000317 (ins CPURegs:$a, CPURegs:$b),
318 !strconcat(instr_asm, " $a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000319 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000320
Eric Christopher7300ac12007-10-26 04:00:13 +0000321// Move from Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322class MoveFromTo<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000323 FR< 0x00,
324 func,
325 (outs CPURegs:$dst),
Evan Chengb783fa32007-07-19 01:14:50 +0000326 (ins),
Eric Christopher7300ac12007-10-26 04:00:13 +0000327 !strconcat(instr_asm, " $dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000328 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329
330// Count Leading Ones/Zeros in Word
331class CountLeading<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000332 FR< 0x1c,
333 func,
334 (outs CPURegs:$dst),
335 (ins CPURegs:$src),
336 !strconcat(instr_asm, " $dst, $src"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000337 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338
Eric Christopher7300ac12007-10-26 04:00:13 +0000339class EffectiveAddress<string instr_asm> :
340 FI<0x09,
341 (outs CPURegs:$dst),
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000342 (ins mem:$addr),
343 instr_asm,
344 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000346class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
347 FR< 0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
348 !strconcat(instr_asm, " $dst, $src"),
349 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
350
351
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352//===----------------------------------------------------------------------===//
353// Pseudo instructions
354//===----------------------------------------------------------------------===//
355
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000357let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000358def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000359 "!ADJCALLSTACKDOWN $amt",
360 [(callseq_start imm:$amt)]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000361def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000362 "!ADJCALLSTACKUP $amt1",
363 [(callseq_end imm:$amt1, imm:$amt2)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000364}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000365
Eric Christopher7300ac12007-10-26 04:00:13 +0000366// When handling PIC code the assembler needs .cpload and .cprestore
367// directives. If the real instructions corresponding these directives
368// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000369// from the assembler.
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000370def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$reg),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000371 ".set noreorder\n\t.cpload $reg\n\t.set reorder\n",
372 []>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000373def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000374 ".cprestore $loc\n", []>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000375
376// The supported Mips ISAs dont have any instruction close to the SELECT_CC
377// operation. The solution is to create a Mips pseudo SELECT_CC instruction
378// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
379// replace it for real supported nodes into EmitInstrWithCustomInserter
380let usesCustomDAGSchedInserter = 1 in {
381 def Select_CC : MipsPseudo<(outs CPURegs:$dst),
382 (ins CPURegs:$CmpRes, CPURegs:$T, CPURegs:$F), "# MipsSelect_CC",
383 [(set CPURegs:$dst, (MipsSelectCC CPURegs:$CmpRes,
384 CPURegs:$T, CPURegs:$F))]>;
385}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000386
387//===----------------------------------------------------------------------===//
388// Instruction definition
389//===----------------------------------------------------------------------===//
390
391//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000392// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393//===----------------------------------------------------------------------===//
394
395// Arithmetic
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000396
397// ADDiu just accept 16-bit immediates but we handle this on Pat's.
398// immZExt32 is used here so it can match GlobalAddress immediates.
Bruno Cardoso Lopesf2377552008-06-06 06:37:31 +0000399// MUL is a assembly macro in the current used ISAs.
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000400def ADDiu : ArithI<0x09, "addiu", add, uimm16, immZExt16>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000401def ADDi : ArithI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf2377552008-06-06 06:37:31 +0000402//def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000403def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
404def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405def ADD : ArithOverflowR<0x00, 0x20, "add">;
406def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000407
408// Logical
409def AND : LogicR<0x24, "and", and>;
410def OR : LogicR<0x25, "or", or>;
411def XOR : LogicR<0x26, "xor", xor>;
412def ANDi : LogicI<0x0c, "andi", and>;
413def ORi : LogicI<0x0d, "ori", or>;
414def XORi : LogicI<0x0e, "xori", xor>;
415def NOR : LogicNOR<0x00, 0x27, "nor">;
416
Eric Christopher7300ac12007-10-26 04:00:13 +0000417// Shifts
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000418def SLL : LogicR_shift_imm<0x00, "sll", shl>;
419def SRL : LogicR_shift_imm<0x02, "srl", srl>;
420def SRA : LogicR_shift_imm<0x03, "sra", sra>;
421def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
422def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
423def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
424
425// Load Upper Immediate
426def LUi : LoadUpper<0x0f, "lui">;
427
428// Load/Store
429def LB : LoadM<0x20, "lb", sextloadi8>;
430def LBu : LoadM<0x24, "lbu", zextloadi8>;
431def LH : LoadM<0x21, "lh", sextloadi16>;
432def LHu : LoadM<0x25, "lhu", zextloadi16>;
433def LW : LoadM<0x23, "lw", load>;
434def SB : StoreM<0x28, "sb", truncstorei8>;
435def SH : StoreM<0x29, "sh", truncstorei16>;
436def SW : StoreM<0x2b, "sw", store>;
437
438// Conditional Branch
439def BEQ : CBranch<0x04, "beq", seteq>;
440def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000441
Eric Christopher7300ac12007-10-26 04:00:13 +0000442let rt=1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000443def BGEZ : CBranchZero<0x01, "bgez", setge>;
444
445let rt=0 in {
446def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
447def BLEZ : CBranchZero<0x07, "blez", setle>;
448def BLTZ : CBranchZero<0x01, "bltz", setlt>;
449}
450
451// Set Condition Code
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
453def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
454def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
455def SLTiu : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
456
457// Unconditional jump
458def J : JumpFJ<0x02, "j">;
459def JR : JumpFR<0x00, 0x08, "jr">;
460
461// Jump and Link (Call)
462def JAL : JumpLink<0x03, "jal">;
463def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000464def BGEZAL : BranchLink<"bgezal">;
465def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000466
467// MulDiv and Move From Hi/Lo operations, have
468// their correpondent SDNodes created on ISelDAG.
469// Special Mul, Div operations
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000470def MULT : MulDiv<0x18, "mult", IIImul>;
471def MULTu : MulDiv<0x19, "multu", IIImul>;
472def DIV : MulDiv<0x1a, "div", IIIdiv>;
473def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474
Eric Christopher7300ac12007-10-26 04:00:13 +0000475// Move From Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476def MFHI : MoveFromTo<0x10, "mfhi">;
477def MFLO : MoveFromTo<0x12, "mflo">;
478def MTHI : MoveFromTo<0x11, "mthi">;
479def MTLO : MoveFromTo<0x13, "mtlo">;
480
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481// No operation
482let addr=0 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000483def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000484
Eric Christopher7300ac12007-10-26 04:00:13 +0000485// Ret instruction - as mips does not have "ret" a
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486// jr $ra must be generated.
Evan Cheng37e7c752007-07-21 00:34:19 +0000487let isReturn=1, isTerminator=1, hasDelaySlot=1,
Eric Christopher7300ac12007-10-26 04:00:13 +0000488 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489{
Evan Chengb783fa32007-07-19 01:14:50 +0000490 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000491 "jr $target", [(MipsRet CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492}
493
Eric Christopher7300ac12007-10-26 04:00:13 +0000494// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000495// instructions. The same not happens for stack address copies, so an
496// add op with mem ComplexPattern is used and the stack address copy
497// can be matched. It's similar to Sparc LEA_ADDRi
498def LEA_ADDiu : EffectiveAddress<"addiu $dst, ${addr:stackloc}">;
499
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000500// Count Leading
501// CLO/CLZ are part of the newer MIPS32(tm) instruction
502// set and not older Mips I keep this for future use
503// though.
504//def CLO : CountLeading<0x21, "clo">;
505//def CLZ : CountLeading<0x20, "clz">;
506
507// MADD*/MSUB* are not part of MipsI either.
508//def MADD : MArithR<0x00, "madd">;
509//def MADDU : MArithR<0x01, "maddu">;
510//def MSUB : MArithR<0x04, "msub">;
511//def MSUBU : MArithR<0x05, "msubu">;
512
Bruno Cardoso Lopesdfd657f2008-07-09 05:32:22 +0000513let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000514 let shamt = 0x10, rs = 0 in
515 def SEB : SignExtInReg<0x21, "seb", i8>;
516
517 let shamt = 0x18, rs = 0 in
518 def SEH : SignExtInReg<0x20, "seh", i16>;
519}
520
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521//===----------------------------------------------------------------------===//
522// Arbitrary patterns that map to one or more instructions
523//===----------------------------------------------------------------------===//
524
525// Small immediates
Eric Christopher7300ac12007-10-26 04:00:13 +0000526def : Pat<(i32 immSExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527 (ADDiu ZERO, imm:$in)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000528def : Pat<(i32 immZExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000529 (ORi ZERO, imm:$in)>;
530
531// Arbitrary immediates
532def : Pat<(i32 imm:$imm),
533 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
534
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000535// Carry patterns
536def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
537 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
538def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
539 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
540def : Pat<(addc CPURegs:$src, imm:$imm),
541 (ADDiu CPURegs:$src, imm:$imm)>;
542
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000543// Call
544def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
545 (JAL tglobaladdr:$dst)>;
546def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
547 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000548def : Pat<(MipsJmpLink CPURegs:$dst),
549 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000550
551// GlobalAddress, Constant Pool, ExternalSymbol, and JumpTable
552def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
553def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000554def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000555 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000556def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
557def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
558def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
559 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000560
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000561// Mips does not have "not", so we expand our way
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000563 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564
Eric Christopher7300ac12007-10-26 04:00:13 +0000565// extended load and stores
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000566def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000567def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
568def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000570// peepholes
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000571def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
572
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000573// brcond patterns
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000574// direct match equal/notequal zero branches
575def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000576 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000577def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
578 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000579
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000580def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000581 (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000583 (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000584
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000585def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
586 (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
587def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
588 (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
589
590def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
591 (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
592def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
593 (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
594
595def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000596 (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
598 (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000599def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
600 (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
601def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
602 (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
603
604def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
605 (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
606def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
607 (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
608
609// generic brcond pattern
610def : Pat<(brcond CPURegs:$cond, bb:$dst),
611 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
612
Eric Christopher7300ac12007-10-26 04:00:13 +0000613/// setcc patterns, only matched when there
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000614/// is no brcond following a setcc operation
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000615def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
616 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
617def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
618 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
619
620def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
621 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
622def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
623 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
624
625def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
626 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
627def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
628 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
629
630def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000631 (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000632 (SLT CPURegs:$rhs, CPURegs:$lhs))>;
633
634def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000635 (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000636 (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000637
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000638def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
639 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
640def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
641 (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000642
643//===----------------------------------------------------------------------===//
644// Floating Point Support
645//===----------------------------------------------------------------------===//
646
647include "MipsInstrFPU.td"
648