blob: 320c5b883483198d10c2f55d5b293115467cd83e [file] [log] [blame]
Chris Lattner03a159c2010-08-17 16:20:04 +00001//===- MipsInstrInfo.td - Mips Register defs ---------------*- tablegen -*-===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
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>]>;
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +000022def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>,
23 SDTCisSameAs<2, 3>, SDTCisInt<1>]>;
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +000024def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
25 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>,
26 SDTCisInt<4>]>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000027def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
28def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
29
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030// Call
Bruno Cardoso Lopes03ae5de2010-01-19 17:00:43 +000031def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner9c190262010-03-19 05:33:51 +000032 [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag,
33 SDNPVariadic]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +000035// Hi and Lo nodes are used to handle global addresses. Used on
36// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
37// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes12355a82008-07-21 18:52:34 +000038def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
39def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
40def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000041
Eric Christopher7300ac12007-10-26 04:00:13 +000042// Return
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000043def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
44 SDNPOptInFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045
46// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000047def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
48 [SDNPHasChain, SDNPOutFlag]>;
49def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
50 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Bill Wendling22f8deb2007-11-13 00:44:25 +000051
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000052// Select Condition Code
53def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +000054
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +000055// Conditional Move
56def MipsCMov : SDNode<"MipsISD::CMov", SDT_MipsCMov>;
57
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000058//===----------------------------------------------------------------------===//
59// Mips Instruction Predicate Definitions.
60//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +000061def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
62def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +000063def HasSwap : Predicate<"Subtarget.hasSwap()">;
64def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000065
66//===----------------------------------------------------------------------===//
67// Mips Operand, Complex Patterns and Transformations Definitions.
68//===----------------------------------------------------------------------===//
69
Dan Gohmanf17a25c2007-07-18 16:29:46 +000070// Instruction operand types
71def brtarget : Operand<OtherVT>;
72def calltarget : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073def simm16 : Operand<i32>;
Eric Christopher7300ac12007-10-26 04:00:13 +000074def shamt : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000075
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +000076// Unsigned Operand
77def uimm16 : Operand<i32> {
78 let PrintMethod = "printUnsignedImm";
79}
80
Dan Gohmanf17a25c2007-07-18 16:29:46 +000081// Address operand
82def mem : Operand<i32> {
83 let PrintMethod = "printMemOperand";
84 let MIOperandInfo = (ops simm16, CPURegs);
85}
86
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087// Transformation Function - get the lower 16 bits.
88def LO16 : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000089 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090}]>;
91
92// Transformation Function - get the higher 16 bits.
93def HI16 : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000094 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095}]>;
96
97// Node immediate fits as 16-bit sign extended on target immediate.
98// e.g. addi, andi
Jakob Stoklund Olesen39588a02010-08-18 23:56:46 +000099def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000100
101// Node immediate fits as 16-bit zero extended on target immediate.
102// The LO16 param means that only the lower 16 bits of the node
103// immediate are caught.
104// e.g. addiu, sltiu
105def immZExt16 : PatLeaf<(imm), [{
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000106 if (N->getValueType(0) == MVT::i32)
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000107 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher7300ac12007-10-26 04:00:13 +0000108 else
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000109 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000110}], LO16>;
111
112// shamt field must fit in 5 bits.
113def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000114 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000115}]>;
116
Eric Christopher7300ac12007-10-26 04:00:13 +0000117// Mips Address Mode! SDNode frameindex could possibily be a match
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000118// since load and store instructions from stack used it.
Chris Lattner14118ed2010-02-14 21:53:19 +0000119def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000120
121//===----------------------------------------------------------------------===//
122// Instructions specific format
123//===----------------------------------------------------------------------===//
124
125// Arithmetic 3 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000126let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000127class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher7300ac12007-10-26 04:00:13 +0000128 InstrItinClass itin>:
129 FR< op,
130 func,
131 (outs CPURegs:$dst),
132 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000133 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000134 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000135
Eric Christopher7300ac12007-10-26 04:00:13 +0000136let isCommutable = 1 in
137class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
138 FR< op,
139 func,
140 (outs CPURegs:$dst),
141 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000142 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000143 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000144
145// Arithmetic 2 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000146class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
147 Operand Od, PatLeaf imm_type> :
148 FI< op,
149 (outs CPURegs:$dst),
150 (ins CPURegs:$b, Od:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000151 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000152 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000153
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000154class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
155 Operand Od, PatLeaf imm_type> :
156 FI< op,
157 (outs CPURegs:$dst),
158 (ins CPURegs:$b, Od:$c),
159 !strconcat(instr_asm, "\t$dst, $b, $c"),
160 [], IIAlu>;
161
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000162// Arithmetic Multiply ADD/SUB
163let rd=0 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000164class MArithR<bits<6> func, string instr_asm> :
165 FR< 0x1c,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000166 func,
Eric Christopher7300ac12007-10-26 04:00:13 +0000167 (outs CPURegs:$rs),
168 (ins CPURegs:$rt),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000169 !strconcat(instr_asm, "\t$rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000170 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171
172// Logical
173class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000174 FR< 0x00,
175 func,
176 (outs CPURegs:$dst),
177 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000178 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000179 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000180
181class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
182 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000183 (outs CPURegs:$dst),
184 (ins CPURegs:$b, uimm16:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000185 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopesf2377552008-06-06 06:37:31 +0000186 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187
188class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000189 FR< op,
190 func,
191 (outs CPURegs:$dst),
192 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000193 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000194 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000195
196// Shifts
197let rt = 0 in
198class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000199 FR< 0x00,
200 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000201 (outs CPURegs:$dst),
202 (ins CPURegs:$b, shamt:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000203 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000204 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000205
206class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000207 FR< 0x00,
208 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000209 (outs CPURegs:$dst),
210 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000211 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000212 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213
214// Load Upper Imediate
215class LoadUpper<bits<6> op, string instr_asm>:
216 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000217 (outs CPURegs:$dst),
218 (ins uimm16:$imm),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000219 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000220 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000221
Eric Christopher7300ac12007-10-26 04:00:13 +0000222// Memory Load/Store
Dan Gohman5574cc72008-12-03 18:15:48 +0000223let canFoldAsLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
225 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000226 (outs CPURegs:$dst),
227 (ins mem:$addr),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000228 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000229 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000230
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000231class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
232 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000233 (outs),
234 (ins CPURegs:$dst, mem:$addr),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000235 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000236 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000237
238// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000239let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000240class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
241 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000242 (outs),
243 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000244 !strconcat(instr_asm, "\t$a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000245 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
246 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000248
249class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
250 FI< op,
251 (outs),
252 (ins CPURegs:$src, brtarget:$offset),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000253 !strconcat(instr_asm, "\t$src, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000254 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
255 IIBranch>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000256}
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000257
Eric Christopher7300ac12007-10-26 04:00:13 +0000258// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
260 PatFrag cond_op>:
261 FR< op,
262 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000263 (outs CPURegs:$dst),
264 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000265 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000266 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
267 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268
269class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
270 Operand Od, PatLeaf imm_type>:
271 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000272 (outs CPURegs:$dst),
273 (ins CPURegs:$b, Od:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000274 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000275 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
276 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000277
278// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000279let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280class JumpFJ<bits<6> op, string instr_asm>:
281 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000282 (outs),
283 (ins brtarget:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000284 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000285 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000287let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
289 FR< op,
290 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000291 (outs),
292 (ins CPURegs:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000293 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000294 [(brind CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000295
296// Jump and Link (Call)
Eric Christopher7300ac12007-10-26 04:00:13 +0000297let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000298 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesen770821b2010-02-17 20:18:50 +0000299 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
300 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher7300ac12007-10-26 04:00:13 +0000301 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000302 FJ< op,
303 (outs),
Bruno Cardoso Lopes03ae5de2010-01-19 17:00:43 +0000304 (ins calltarget:$target, variable_ops),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000305 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000306 [(MipsJmpLink imm:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000308 let rd=31 in
309 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
310 FR< op,
311 func,
312 (outs),
Bruno Cardoso Lopes03ae5de2010-01-19 17:00:43 +0000313 (ins CPURegs:$rs, variable_ops),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000314 !strconcat(instr_asm, "\t$rs"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000315 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
316
317 class BranchLink<string instr_asm>:
318 FI< 0x1,
319 (outs),
Bruno Cardoso Lopes03ae5de2010-01-19 17:00:43 +0000320 (ins CPURegs:$rs, brtarget:$target, variable_ops),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000321 !strconcat(instr_asm, "\t$rs, $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000322 [], IIBranch>;
323}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000324
Eric Christopher7300ac12007-10-26 04:00:13 +0000325// Mul, Div
326class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
327 FR< 0x00,
328 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000329 (outs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000330 (ins CPURegs:$a, CPURegs:$b),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000331 !strconcat(instr_asm, "\t$a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000332 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000333
Eric Christopher7300ac12007-10-26 04:00:13 +0000334// Move from Hi/Lo
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000335class MoveFromLOHI<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000336 FR< 0x00,
337 func,
338 (outs CPURegs:$dst),
Evan Chengb783fa32007-07-19 01:14:50 +0000339 (ins),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000340 !strconcat(instr_asm, "\t$dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000341 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000343class MoveToLOHI<bits<6> func, string instr_asm>:
344 FR< 0x00,
345 func,
346 (outs),
347 (ins CPURegs:$src),
348 !strconcat(instr_asm, "\t$src"),
349 [], IIHiLo>;
350
Eric Christopher7300ac12007-10-26 04:00:13 +0000351class EffectiveAddress<string instr_asm> :
352 FI<0x09,
353 (outs CPURegs:$dst),
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000354 (ins mem:$addr),
355 instr_asm,
356 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +0000358// Count Leading Ones/Zeros in Word
359class CountLeading<bits<6> func, string instr_asm, SDNode CountOp>:
360 FR< 0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
361 !strconcat(instr_asm, "\t$dst, $src"),
362 [(set CPURegs:$dst, (CountOp CPURegs:$src))], IIAlu>;
363
364// Sign Extend in Register.
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000365class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
366 FR< 0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000367 !strconcat(instr_asm, "\t$dst, $src"),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000368 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
369
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000370// Byte Swap
371class ByteSwap<bits<6> func, string instr_asm>:
372 FR< 0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
373 !strconcat(instr_asm, "\t$dst, $src"),
374 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
375
376// Conditional Move
377class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
378 FR< 0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
379 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
380 [(set CPURegs:$dst, (MipsCMov CPURegs:$F, CPURegs:$T,
381 CPURegs:$cond, MovCode))], NoItinerary>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000382
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000383//===----------------------------------------------------------------------===//
384// Pseudo instructions
385//===----------------------------------------------------------------------===//
386
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000387// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000388let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000389def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000390 "!ADJCALLSTACKDOWN $amt",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000391 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000392def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000393 "!ADJCALLSTACKUP $amt1",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000394 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000395}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000396
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000397// Some assembly macros need to avoid pseudoinstructions and assembler
398// automatic reodering, we should reorder ourselves.
399def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
400def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
401def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
402def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
403
Eric Christopher7300ac12007-10-26 04:00:13 +0000404// When handling PIC code the assembler needs .cpload and .cprestore
405// directives. If the real instructions corresponding these directives
406// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000407// from the assembler.
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000408def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
409def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000410
411// The supported Mips ISAs dont have any instruction close to the SELECT_CC
412// operation. The solution is to create a Mips pseudo SELECT_CC instruction
413// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
414// replace it for real supported nodes into EmitInstrWithCustomInserter
Dan Gohman30afe012009-10-29 18:10:34 +0000415let usesCustomInserter = 1 in {
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +0000416 class PseudoSelCC<RegisterClass RC, string asmstr>:
417 MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr,
418 [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000419}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +0000421def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
422
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000423//===----------------------------------------------------------------------===//
424// Instruction definition
425//===----------------------------------------------------------------------===//
426
427//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000428// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429//===----------------------------------------------------------------------===//
430
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000431/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000432def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
433def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000434def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000435def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000436def ANDi : LogicI<0x0c, "andi", and>;
437def ORi : LogicI<0x0d, "ori", or>;
438def XORi : LogicI<0x0e, "xori", xor>;
439def LUi : LoadUpper<0x0f, "lui">;
440
441/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000442def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
443def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444def ADD : ArithOverflowR<0x00, 0x20, "add">;
445def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000446def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
447def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448def AND : LogicR<0x24, "and", and>;
449def OR : LogicR<0x25, "or", or>;
450def XOR : LogicR<0x26, "xor", xor>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451def NOR : LogicNOR<0x00, 0x27, "nor">;
452
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000453/// Shift Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000454def SLL : LogicR_shift_imm<0x00, "sll", shl>;
455def SRL : LogicR_shift_imm<0x02, "srl", srl>;
456def SRA : LogicR_shift_imm<0x03, "sra", sra>;
457def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
458def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
459def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
460
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000461/// Load and Store Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000462def LB : LoadM<0x20, "lb", sextloadi8>;
463def LBu : LoadM<0x24, "lbu", zextloadi8>;
464def LH : LoadM<0x21, "lh", sextloadi16>;
465def LHu : LoadM<0x25, "lhu", zextloadi16>;
466def LW : LoadM<0x23, "lw", load>;
467def SB : StoreM<0x28, "sb", truncstorei8>;
468def SH : StoreM<0x29, "sh", truncstorei16>;
469def SW : StoreM<0x2b, "sw", store>;
470
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000471/// Jump and Branch Instructions
472def J : JumpFJ<0x02, "j">;
473def JR : JumpFR<0x00, 0x08, "jr">;
474def JAL : JumpLink<0x03, "jal">;
475def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476def BEQ : CBranch<0x04, "beq", seteq>;
477def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000478
Eric Christopher7300ac12007-10-26 04:00:13 +0000479let rt=1 in
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000480 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000481
482let rt=0 in {
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000483 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
484 def BLEZ : CBranchZero<0x07, "blez", setle>;
485 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000486}
487
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000488def BGEZAL : BranchLink<"bgezal">;
489def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000491let isReturn=1, isTerminator=1, hasDelaySlot=1,
492 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
493 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
494 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
495
496/// Multiply and Divide Instructions.
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000497let Defs = [HI, LO] in {
498 def MULT : MulDiv<0x18, "mult", IIImul>;
499 def MULTu : MulDiv<0x19, "multu", IIImul>;
500 def DIV : MulDiv<0x1a, "div", IIIdiv>;
501 def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
502}
503
504let Defs = [HI] in
505 def MTHI : MoveToLOHI<0x11, "mthi">;
506let Defs = [LO] in
507 def MTLO : MoveToLOHI<0x13, "mtlo">;
508
509let Uses = [HI] in
510 def MFHI : MoveFromLOHI<0x10, "mfhi">;
511let Uses = [LO] in
512 def MFLO : MoveFromLOHI<0x12, "mflo">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000514/// Sign Ext In Register Instructions.
515let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopes643c0402009-05-27 17:23:44 +0000516 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000517 def SEB : SignExtInReg<0x21, "seb", i8>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518
Bruno Cardoso Lopes643c0402009-05-27 17:23:44 +0000519 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000520 def SEH : SignExtInReg<0x20, "seh", i16>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521}
522
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +0000523/// Count Leading
524let Predicates = [HasBitCount] in {
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000525 let rt = 0 in
526 def CLZ : CountLeading<0b010110, "clz", ctlz>;
527}
528
529/// Byte Swap
530let Predicates = [HasSwap] in {
531 let shamt = 0x3, rs = 0 in
532 def WSBW : ByteSwap<0x20, "wsbw">;
533}
534
535/// Conditional Move
536def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
537def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
538
Eric Christopher040ab5f2010-06-21 20:19:21 +0000539let Predicates = [HasCondMov], Constraints = "$F = $dst" in {
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000540 def MOVN : CondMov<0x0a, "movn", MIPS_CMOV_NZERO>;
541 def MOVZ : CondMov<0x0b, "movz", MIPS_CMOV_ZERO>;
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +0000542}
543
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000544/// No operation
545let addr=0 in
546 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
547
Eric Christopher7300ac12007-10-26 04:00:13 +0000548// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000549// instructions. The same not happens for stack address copies, so an
550// add op with mem ComplexPattern is used and the stack address copy
551// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000552def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000553
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000554// MADD*/MSUB* are not part of MipsI either.
555//def MADD : MArithR<0x00, "madd">;
556//def MADDU : MArithR<0x01, "maddu">;
557//def MSUB : MArithR<0x04, "msub">;
558//def MSUBU : MArithR<0x05, "msubu">;
559
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000560// MUL is a assembly macro in the current used ISAs. In recent ISA's
561// it is a real instruction.
562//def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000563
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564//===----------------------------------------------------------------------===//
565// Arbitrary patterns that map to one or more instructions
566//===----------------------------------------------------------------------===//
567
568// Small immediates
Eric Christopher7300ac12007-10-26 04:00:13 +0000569def : Pat<(i32 immSExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570 (ADDiu ZERO, imm:$in)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000571def : Pat<(i32 immZExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572 (ORi ZERO, imm:$in)>;
573
574// Arbitrary immediates
575def : Pat<(i32 imm:$imm),
576 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
577
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000578// Carry patterns
579def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
580 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
581def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
582 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
583def : Pat<(addc CPURegs:$src, imm:$imm),
584 (ADDiu CPURegs:$src, imm:$imm)>;
585
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586// Call
587def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
588 (JAL tglobaladdr:$dst)>;
589def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
590 (JAL texternalsym:$dst)>;
Chris Lattnerb76fe972010-02-28 07:23:21 +0000591//def : Pat<(MipsJmpLink CPURegs:$dst),
592// (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000593
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000594// hi/lo relocs
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000595def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000596def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000597 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000598
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000599def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000600def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
601 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000602
603def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
604def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
605 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
606
607// gp_rel relocs
Bruno Cardoso Lopes12355a82008-07-21 18:52:34 +0000608def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
609 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000610def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
611 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000613// Mips does not have "not", so we expand our way
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000615 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000616
Eric Christopher7300ac12007-10-26 04:00:13 +0000617// extended load and stores
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000618def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
619def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
620def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000621
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000622// peepholes
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000623def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
624
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000625// brcond patterns
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000626def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000628def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
629 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000630
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000631def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000632 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000633def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000634 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
635def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
636 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
637def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
638 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000639
640def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000641 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000642def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000643 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000644
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000645def : Pat<(brcond CPURegs:$cond, bb:$dst),
646 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
647
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000648// select patterns
649def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
650 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$lhs, CPURegs:$rhs))>;
651def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
652 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs))>;
653def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), CPURegs:$T, CPURegs:$F),
654 (MOVZ CPURegs:$F, CPURegs:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs))>;
655def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), CPURegs:$T, CPURegs:$F),
656 (MOVZ CPURegs:$F, CPURegs:$T, (SLTiu CPURegs:$lh, immSExt16:$rh))>;
657
658def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
659 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$rhs, CPURegs:$lhs))>;
660def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
661 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs))>;
662
663def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
664 (MOVZ CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
665def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
666 (MOVN CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
667
668def : Pat<(select CPURegs:$cond, CPURegs:$T, CPURegs:$F),
669 (MOVN CPURegs:$F, CPURegs:$T, CPURegs:$cond)>;
670
671// setcc patterns
672def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
673 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
674def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
675 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
676
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000677def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
678 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
679def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
680 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
681
682def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
683 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
684def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
685 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
686
687def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
688 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
689def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
690 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
691
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000692def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
693 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000694def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
695 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000696
697//===----------------------------------------------------------------------===//
698// Floating Point Support
699//===----------------------------------------------------------------------===//
700
701include "MipsInstrFPU.td"
702