blob: 89e8ee26ea12aabad5e0c2b154560678cc0ac223 [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>]>;
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 Lopes4fb1f542008-07-05 19:05:21 +000024def 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)
Bruno Cardoso Lopes12355a82008-07-21 18:52:34 +000034def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
35def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
36def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000037
Eric Christopher7300ac12007-10-26 04:00:13 +000038// Return
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000039def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
40 SDNPOptInFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041
42// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000043def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
44 [SDNPHasChain, SDNPOutFlag]>;
45def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
46 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Bill Wendling22f8deb2007-11-13 00:44:25 +000047
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000048// Select Condition Code
49def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +000050
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000051//===----------------------------------------------------------------------===//
52// Mips Instruction Predicate Definitions.
53//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +000054def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
55def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000056
57//===----------------------------------------------------------------------===//
58// Mips Operand, Complex Patterns and Transformations Definitions.
59//===----------------------------------------------------------------------===//
60
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061// Instruction operand types
62def brtarget : Operand<OtherVT>;
63def calltarget : Operand<i32>;
64def uimm16 : Operand<i32>;
65def simm16 : Operand<i32>;
Eric Christopher7300ac12007-10-26 04:00:13 +000066def shamt : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000067
68// Address operand
69def mem : Operand<i32> {
70 let PrintMethod = "printMemOperand";
71 let MIOperandInfo = (ops simm16, CPURegs);
72}
73
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074// Transformation Function - get the lower 16 bits.
75def LO16 : SDNodeXForm<imm, [{
76 return getI32Imm((unsigned)N->getValue() & 0xFFFF);
77}]>;
78
79// Transformation Function - get the higher 16 bits.
80def HI16 : SDNodeXForm<imm, [{
81 return getI32Imm((unsigned)N->getValue() >> 16);
82}]>;
83
84// Node immediate fits as 16-bit sign extended on target immediate.
85// e.g. addi, andi
86def immSExt16 : PatLeaf<(imm), [{
87 if (N->getValueType(0) == MVT::i32)
88 return (int32_t)N->getValue() == (short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +000089 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090 return (int64_t)N->getValue() == (short)N->getValue();
91}]>;
92
93// Node immediate fits as 16-bit zero extended on target immediate.
94// The LO16 param means that only the lower 16 bits of the node
95// immediate are caught.
96// e.g. addiu, sltiu
97def immZExt16 : PatLeaf<(imm), [{
98 if (N->getValueType(0) == MVT::i32)
99 return (uint32_t)N->getValue() == (unsigned short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +0000100 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000101 return (uint64_t)N->getValue() == (unsigned short)N->getValue();
102}], LO16>;
103
104// 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),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000125 !strconcat(instr_asm, "\t$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),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000134 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000135 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000136
137// Arithmetic 2 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000138class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
139 Operand Od, PatLeaf imm_type> :
140 FI< op,
141 (outs CPURegs:$dst),
142 (ins CPURegs:$b, Od:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000143 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000144 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000145
146// Arithmetic Multiply ADD/SUB
147let rd=0 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000148class MArithR<bits<6> func, string instr_asm> :
149 FR< 0x1c,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000150 func,
Eric Christopher7300ac12007-10-26 04:00:13 +0000151 (outs CPURegs:$rs),
152 (ins CPURegs:$rt),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000153 !strconcat(instr_asm, "\t$rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000154 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155
156// Logical
157class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000158 FR< 0x00,
159 func,
160 (outs CPURegs:$dst),
161 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000162 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000163 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164
165class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
166 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000167 (outs CPURegs:$dst),
168 (ins CPURegs:$b, uimm16:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000169 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopesf2377552008-06-06 06:37:31 +0000170 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171
172class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000173 FR< op,
174 func,
175 (outs CPURegs:$dst),
176 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000177 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000178 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179
180// Shifts
181let rt = 0 in
182class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000183 FR< 0x00,
184 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000185 (outs CPURegs:$dst),
186 (ins CPURegs:$b, shamt:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000187 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000188 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189
190class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000191 FR< 0x00,
192 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000193 (outs CPURegs:$dst),
194 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000195 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000196 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000197
198// Load Upper Imediate
199class LoadUpper<bits<6> op, string instr_asm>:
200 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000201 (outs CPURegs:$dst),
202 (ins uimm16:$imm),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000203 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000204 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000205
Eric Christopher7300ac12007-10-26 04:00:13 +0000206// Memory Load/Store
Chris Lattner1a1932c2008-01-06 23:38:27 +0000207let isSimpleLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000208class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
209 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000210 (outs CPURegs:$dst),
211 (ins mem:$addr),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000212 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000213 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
216 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000217 (outs),
218 (ins CPURegs:$dst, mem:$addr),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000219 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000220 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000221
222// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000223let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
225 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000226 (outs),
227 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000228 !strconcat(instr_asm, "\t$a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000229 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
230 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000231
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000232
233class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
234 FI< op,
235 (outs),
236 (ins CPURegs:$src, brtarget:$offset),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000237 !strconcat(instr_asm, "\t$src, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000238 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
239 IIBranch>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000240}
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000241
Eric Christopher7300ac12007-10-26 04:00:13 +0000242// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
244 PatFrag cond_op>:
245 FR< op,
246 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000247 (outs CPURegs:$dst),
248 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000249 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000250 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
251 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000252
253class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
254 Operand Od, PatLeaf imm_type>:
255 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000256 (outs CPURegs:$dst),
257 (ins CPURegs:$b, Od:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000258 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000259 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
260 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261
262// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000263let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264class JumpFJ<bits<6> op, string instr_asm>:
265 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000266 (outs),
267 (ins brtarget:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000268 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000269 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000270
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000271let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
273 FR< op,
274 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000275 (outs),
276 (ins CPURegs:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000277 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000278 [(brind CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279
280// Jump and Link (Call)
Eric Christopher7300ac12007-10-26 04:00:13 +0000281let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000282 // All calls clobber the non-callee saved registers...
Bruno Cardoso Lopesf046f872008-08-06 06:14:43 +0000283 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
284 K0, K1, F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
285 F14, F15, F16, F17, F18, F19], 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),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000290 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000291 [(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),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000299 !strconcat(instr_asm, "\t$rs"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000300 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
301
302 class BranchLink<string instr_asm>:
303 FI< 0x1,
304 (outs),
305 (ins CPURegs:$rs, brtarget:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000306 !strconcat(instr_asm, "\t$rs, $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000307 [], 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),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000316 !strconcat(instr_asm, "\t$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
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000320class MoveFromLOHI<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),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000325 !strconcat(instr_asm, "\t$dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000326 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000327
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000328class MoveToLOHI<bits<6> func, string instr_asm>:
329 FR< 0x00,
330 func,
331 (outs),
332 (ins CPURegs:$src),
333 !strconcat(instr_asm, "\t$src"),
334 [], IIHiLo>;
335
Eric Christopher7300ac12007-10-26 04:00:13 +0000336class EffectiveAddress<string instr_asm> :
337 FI<0x09,
338 (outs CPURegs:$dst),
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000339 (ins mem:$addr),
340 instr_asm,
341 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +0000343// Count Leading Ones/Zeros in Word
344class CountLeading<bits<6> func, string instr_asm, SDNode CountOp>:
345 FR< 0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
346 !strconcat(instr_asm, "\t$dst, $src"),
347 [(set CPURegs:$dst, (CountOp CPURegs:$src))], IIAlu>;
348
349// Sign Extend in Register.
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000350class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
351 FR< 0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000352 !strconcat(instr_asm, "\t$dst, $src"),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000353 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
354
355
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356//===----------------------------------------------------------------------===//
357// Pseudo instructions
358//===----------------------------------------------------------------------===//
359
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000361let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000362def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000363 "!ADJCALLSTACKDOWN $amt",
364 [(callseq_start imm:$amt)]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000365def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000366 "!ADJCALLSTACKUP $amt1",
367 [(callseq_end imm:$amt1, imm:$amt2)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000368}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000370// Some assembly macros need to avoid pseudoinstructions and assembler
371// automatic reodering, we should reorder ourselves.
372def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
373def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
374def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
375def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
376
Eric Christopher7300ac12007-10-26 04:00:13 +0000377// When handling PIC code the assembler needs .cpload and .cprestore
378// directives. If the real instructions corresponding these directives
379// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000380// from the assembler.
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000381def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
382def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000383
384// The supported Mips ISAs dont have any instruction close to the SELECT_CC
385// operation. The solution is to create a Mips pseudo SELECT_CC instruction
386// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
387// replace it for real supported nodes into EmitInstrWithCustomInserter
388let usesCustomDAGSchedInserter = 1 in {
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +0000389 class PseudoSelCC<RegisterClass RC, string asmstr>:
390 MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr,
391 [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000392}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +0000394def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
395
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000396//===----------------------------------------------------------------------===//
397// Instruction definition
398//===----------------------------------------------------------------------===//
399
400//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000401// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000402//===----------------------------------------------------------------------===//
403
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000404/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000405def ADDiu : ArithI<0x09, "addiu", add, uimm16, immZExt16>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000406def ADDi : ArithI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000407def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
408def SLTiu : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
409def ANDi : LogicI<0x0c, "andi", and>;
410def ORi : LogicI<0x0d, "ori", or>;
411def XORi : LogicI<0x0e, "xori", xor>;
412def LUi : LoadUpper<0x0f, "lui">;
413
414/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000415def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
416def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000417def ADD : ArithOverflowR<0x00, 0x20, "add">;
418def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000419def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
420def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421def AND : LogicR<0x24, "and", and>;
422def OR : LogicR<0x25, "or", or>;
423def XOR : LogicR<0x26, "xor", xor>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000424def NOR : LogicNOR<0x00, 0x27, "nor">;
425
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000426/// Shift Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000427def SLL : LogicR_shift_imm<0x00, "sll", shl>;
428def SRL : LogicR_shift_imm<0x02, "srl", srl>;
429def SRA : LogicR_shift_imm<0x03, "sra", sra>;
430def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
431def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
432def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
433
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000434/// Load and Store Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435def LB : LoadM<0x20, "lb", sextloadi8>;
436def LBu : LoadM<0x24, "lbu", zextloadi8>;
437def LH : LoadM<0x21, "lh", sextloadi16>;
438def LHu : LoadM<0x25, "lhu", zextloadi16>;
439def LW : LoadM<0x23, "lw", load>;
440def SB : StoreM<0x28, "sb", truncstorei8>;
441def SH : StoreM<0x29, "sh", truncstorei16>;
442def SW : StoreM<0x2b, "sw", store>;
443
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000444/// Jump and Branch Instructions
445def J : JumpFJ<0x02, "j">;
446def JR : JumpFR<0x00, 0x08, "jr">;
447def JAL : JumpLink<0x03, "jal">;
448def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000449def BEQ : CBranch<0x04, "beq", seteq>;
450def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000451
Eric Christopher7300ac12007-10-26 04:00:13 +0000452let rt=1 in
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000453 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000454
455let rt=0 in {
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000456 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
457 def BLEZ : CBranchZero<0x07, "blez", setle>;
458 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000459}
460
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000461def BGEZAL : BranchLink<"bgezal">;
462def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000463
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000464let isReturn=1, isTerminator=1, hasDelaySlot=1,
465 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
466 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
467 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
468
469/// Multiply and Divide Instructions.
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000470let Defs = [HI, LO] in {
471 def MULT : MulDiv<0x18, "mult", IIImul>;
472 def MULTu : MulDiv<0x19, "multu", IIImul>;
473 def DIV : MulDiv<0x1a, "div", IIIdiv>;
474 def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
475}
476
477let Defs = [HI] in
478 def MTHI : MoveToLOHI<0x11, "mthi">;
479let Defs = [LO] in
480 def MTLO : MoveToLOHI<0x13, "mtlo">;
481
482let Uses = [HI] in
483 def MFHI : MoveFromLOHI<0x10, "mfhi">;
484let Uses = [LO] in
485 def MFLO : MoveFromLOHI<0x12, "mflo">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000487/// Sign Ext In Register Instructions.
488let Predicates = [HasSEInReg] in {
489 let shamt = 0x10, rs = 0 in
490 def SEB : SignExtInReg<0x21, "seb", i8>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000491
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000492 let shamt = 0x18, rs = 0 in
493 def SEH : SignExtInReg<0x20, "seh", i16>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494}
495
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +0000496/// Count Leading
497let Predicates = [HasBitCount] in {
498 def CLZ : CountLeading<0b010110, "clz", ctlz>;
499//def CLO : CountLeading<0b010110, "clo">;
500}
501
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000502/// No operation
503let addr=0 in
504 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
505
Eric Christopher7300ac12007-10-26 04:00:13 +0000506// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000507// instructions. The same not happens for stack address copies, so an
508// add op with mem ComplexPattern is used and the stack address copy
509// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000510def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000511
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000512// MADD*/MSUB* are not part of MipsI either.
513//def MADD : MArithR<0x00, "madd">;
514//def MADDU : MArithR<0x01, "maddu">;
515//def MSUB : MArithR<0x04, "msub">;
516//def MSUBU : MArithR<0x05, "msubu">;
517
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000518// MUL is a assembly macro in the current used ISAs. In recent ISA's
519// it is a real instruction.
520//def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000521
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522//===----------------------------------------------------------------------===//
523// Arbitrary patterns that map to one or more instructions
524//===----------------------------------------------------------------------===//
525
526// Small immediates
Eric Christopher7300ac12007-10-26 04:00:13 +0000527def : Pat<(i32 immSExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528 (ADDiu ZERO, imm:$in)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000529def : Pat<(i32 immZExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530 (ORi ZERO, imm:$in)>;
531
532// Arbitrary immediates
533def : Pat<(i32 imm:$imm),
534 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
535
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000536// Carry patterns
537def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
538 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
539def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
540 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
541def : Pat<(addc CPURegs:$src, imm:$imm),
542 (ADDiu CPURegs:$src, imm:$imm)>;
543
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544// Call
545def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
546 (JAL tglobaladdr:$dst)>;
547def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
548 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000549def : Pat<(MipsJmpLink CPURegs:$dst),
550 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000551
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000552// hi/lo relocs
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553def : Pat<(MipsHi tglobaladdr:$in), (LUi 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 Lopes69ca2ca2008-07-23 16:01:50 +0000556
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000557def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000558def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
559 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000560
561def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
562def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
563 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
564
565// gp_rel relocs
Bruno Cardoso Lopes12355a82008-07-21 18:52:34 +0000566def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
567 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000568def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
569 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000571// Mips does not have "not", so we expand our way
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000573 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000574
Eric Christopher7300ac12007-10-26 04:00:13 +0000575// extended load and stores
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000576def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
578def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000579
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000580// peepholes
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000581def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
582
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000583// brcond patterns
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000584// direct match equal/notequal zero branches
585def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000587def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
588 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000590def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000591 (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000593 (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000594
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000595def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
596 (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
597def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
598 (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
599
600def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
601 (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
602def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
603 (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
604
605def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000606 (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
608 (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000609def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
610 (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
611def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
612 (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
613
614def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
615 (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
616def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
617 (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
618
619// generic brcond pattern
620def : Pat<(brcond CPURegs:$cond, bb:$dst),
621 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
622
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000623// setcc patterns, only matched when there
624// is no brcond following a setcc operation
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000625def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
626 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
627def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
628 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
629
630def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
631 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
632def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
633 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
634
635def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
636 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
637def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
638 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
639
640def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000641 (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000642 (SLT CPURegs:$rhs, CPURegs:$lhs))>;
643
644def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000645 (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000646 (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000647
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000648def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
649 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
650def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
651 (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000652
653//===----------------------------------------------------------------------===//
654// Floating Point Support
655//===----------------------------------------------------------------------===//
656
657include "MipsInstrFPU.td"
658