blob: b70266ac3e80a65a16a39925d6c2018ea305e415 [file] [log] [blame]
Chris Lattner23e70eb2010-08-17 16:20:04 +00001//===- MipsInstrInfo.td - Mips Register defs ---------------*- tablegen -*-===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
8//===----------------------------------------------------------------------===//
9
10//===----------------------------------------------------------------------===//
11// Instruction format superclass
12//===----------------------------------------------------------------------===//
13
14include "MipsInstrFormats.td"
15
16//===----------------------------------------------------------------------===//
17// Mips profiles and nodes
18//===----------------------------------------------------------------------===//
19
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000020def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
21def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000022def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>,
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +000023 SDTCisSameAs<2, 3>, SDTCisInt<1>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000024def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000025 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>,
26 SDTCisInt<4>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000027def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
28def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000029def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
30 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
31 SDTCisSameAs<1, 2>,
32 SDTCisSameAs<2, 3>]>;
33
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000034
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000035// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000036def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000037 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000038 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000039
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000040// Hi and Lo nodes are used to handle global addresses. Used on
41// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000042// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000043def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
44def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
45def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000046
Eric Christopher3c999a22007-10-26 04:00:13 +000047// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000048def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000049 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000050
51// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000052def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000053 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000054def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000055 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000056
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000057// Select Condition Code
58def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +000059
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000060// MAdd*/MSub* nodes
61def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
62 [SDNPOptInGlue, SDNPOutGlue]>;
63def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
64 [SDNPOptInGlue, SDNPOutGlue]>;
65def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
66 [SDNPOptInGlue, SDNPOutGlue]>;
67def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
68 [SDNPOptInGlue, SDNPOutGlue]>;
69
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000070//===----------------------------------------------------------------------===//
71// Mips Instruction Predicate Definitions.
72//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +000073def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
74def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000075def HasSwap : Predicate<"Subtarget.hasSwap()">;
76def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +000077def IsMips32 : Predicate<"Subtarget.isMips32()">;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +000078def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000079
80//===----------------------------------------------------------------------===//
81// Mips Operand, Complex Patterns and Transformations Definitions.
82//===----------------------------------------------------------------------===//
83
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000084// Instruction operand types
85def brtarget : Operand<OtherVT>;
86def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000087def simm16 : Operand<i32>;
Eric Christopher3c999a22007-10-26 04:00:13 +000088def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000089
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000090// Unsigned Operand
91def uimm16 : Operand<i32> {
92 let PrintMethod = "printUnsignedImm";
93}
94
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000095// Address operand
96def mem : Operand<i32> {
97 let PrintMethod = "printMemOperand";
98 let MIOperandInfo = (ops simm16, CPURegs);
99}
100
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000101// Transformation Function - get the lower 16 bits.
102def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000103 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000104}]>;
105
106// Transformation Function - get the higher 16 bits.
107def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000108 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000109}]>;
110
111// Node immediate fits as 16-bit sign extended on target immediate.
112// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000113def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000114
115// Node immediate fits as 16-bit zero extended on target immediate.
116// The LO16 param means that only the lower 16 bits of the node
117// immediate are caught.
118// e.g. addiu, sltiu
119def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000120 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000121 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000122 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000123 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000124}], LO16>;
125
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000126// shamt field must fit in 5 bits.
127def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000128 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000129}]>;
130
Eric Christopher3c999a22007-10-26 04:00:13 +0000131// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000132// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000133def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000134
135//===----------------------------------------------------------------------===//
136// Instructions specific format
137//===----------------------------------------------------------------------===//
138
139// Arithmetic 3 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000140let isCommutable = 1 in
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000141class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher3c999a22007-10-26 04:00:13 +0000142 InstrItinClass itin>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000143 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
144 !strconcat(instr_asm, "\t$dst, $b, $c"),
145 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000146
Eric Christopher3c999a22007-10-26 04:00:13 +0000147let isCommutable = 1 in
148class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000149 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
150 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000151
152// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000153class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
154 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000155 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
156 !strconcat(instr_asm, "\t$dst, $b, $c"),
157 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000158
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000159class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
160 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000161 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
162 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000163
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000164// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000165let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
166class MArithR<bits<6> func, string instr_asm, SDNode op> :
167 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
168 !strconcat(instr_asm, "\t$rs, $rt"),
169 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000170
171// Logical
172class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000173 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
174 !strconcat(instr_asm, "\t$dst, $b, $c"),
175 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000176
177class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000178 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
179 !strconcat(instr_asm, "\t$dst, $b, $c"),
180 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000181
182class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000183 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
184 !strconcat(instr_asm, "\t$dst, $b, $c"),
185 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000186
187// Shifts
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000188class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
189 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000190 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
191 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000192 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
193 let rs = _rs;
194}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000195
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000196class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
197 SDNode OpNode>:
198 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000199 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000200 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
201 let shamt = _shamt;
202}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000203
204// Load Upper Imediate
205class LoadUpper<bits<6> op, string instr_asm>:
206 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000207 (outs CPURegs:$dst),
208 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000209 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000210 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000211
Eric Christopher3c999a22007-10-26 04:00:13 +0000212// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000213let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000214class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000215 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
216 !strconcat(instr_asm, "\t$dst, $addr"),
217 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000218
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000219class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000220 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
221 !strconcat(instr_asm, "\t$dst, $addr"),
222 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000223
224// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000225let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000226class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000227 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
228 !strconcat(instr_asm, "\t$a, $b, $offset"),
229 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
230 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000231
232class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000233 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
234 !strconcat(instr_asm, "\t$src, $offset"),
235 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
236 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000237}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000238
Eric Christopher3c999a22007-10-26 04:00:13 +0000239// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000240class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
241 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000242 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
243 !strconcat(instr_asm, "\t$dst, $b, $c"),
244 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
245 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000246
247class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
248 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000249 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
250 !strconcat(instr_asm, "\t$dst, $b, $c"),
251 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
252 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000253
254// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000255let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000256class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000257 FJ<op, (outs), (ins brtarget:$target),
258 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000259
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000260let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000261class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000262 FR<op, func, (outs), (ins CPURegs:$target),
263 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000264
265// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000266let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000267 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000268 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
269 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000270 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000271 FJ<op, (outs), (ins calltarget:$target, variable_ops),
272 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
273 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000274
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000275 let rd=31 in
276 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000277 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
278 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000279
280 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000281 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
282 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000283}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000284
Eric Christopher3c999a22007-10-26 04:00:13 +0000285// Mul, Div
286class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000287 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
288 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000289
Eric Christopher3c999a22007-10-26 04:00:13 +0000290// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000291class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000292 FR<0x00, func, (outs CPURegs:$dst), (ins),
293 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000294
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000295class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000296 FR<0x00, func, (outs), (ins CPURegs:$src),
297 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000298
Eric Christopher3c999a22007-10-26 04:00:13 +0000299class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000300 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
301 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000302
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000303// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000304class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000305 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000306 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
307 Requires<[HasBitCount]> {
308 let shamt = 0;
309 let rt = rd;
310}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000311
312// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000313class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000314 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
315 !strconcat(instr_asm, "\t$dst, $src"),
316 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000317
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000318// Byte Swap
319class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000320 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
321 !strconcat(instr_asm, "\t$dst, $src"),
322 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000323
324// Conditional Move
325class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000326 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
327 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000328 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000329
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000330//===----------------------------------------------------------------------===//
331// Pseudo instructions
332//===----------------------------------------------------------------------===//
333
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000334// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000335let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000336def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000337 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000338 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000339def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000340 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000341 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000342}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000343
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000344// Some assembly macros need to avoid pseudoinstructions and assembler
345// automatic reodering, we should reorder ourselves.
346def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
347def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
348def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
349def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
350
Eric Christopher3c999a22007-10-26 04:00:13 +0000351// When handling PIC code the assembler needs .cpload and .cprestore
352// directives. If the real instructions corresponding these directives
353// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000354// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000355def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
356def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000357
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000358// The supported Mips ISAs dont have any instruction close to the SELECT_CC
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000359// operation. The solution is to create a Mips pseudo SELECT_CC instruction
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000360// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000361// replace it for real supported nodes into EmitInstrWithCustomInserter
Dan Gohman533297b2009-10-29 18:10:34 +0000362let usesCustomInserter = 1 in {
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000363 class PseudoSelCC<RegisterClass RC, string asmstr>:
364 MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr,
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000365 [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000366}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000367
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000368def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
369
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000370//===----------------------------------------------------------------------===//
371// Instruction definition
372//===----------------------------------------------------------------------===//
373
374//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000375// MipsI Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000376//===----------------------------------------------------------------------===//
377
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000378/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000379def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
380def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000381def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000382def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000383def ANDi : LogicI<0x0c, "andi", and>;
384def ORi : LogicI<0x0d, "ori", or>;
385def XORi : LogicI<0x0e, "xori", xor>;
386def LUi : LoadUpper<0x0f, "lui">;
387
388/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000389def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
390def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000391def ADD : ArithOverflowR<0x00, 0x20, "add">;
392def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000393def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
394def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000395def AND : LogicR<0x24, "and", and>;
396def OR : LogicR<0x25, "or", or>;
397def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000398def NOR : LogicNOR<0x00, 0x27, "nor">;
399
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000400/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000401def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
402def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
403def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
404def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
405def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
406def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
407
408// Rotate Instructions
409let Predicates = [IsMips32r2] in {
410 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
411 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
412}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000413
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000414/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000415def LB : LoadM<0x20, "lb", sextloadi8>;
416def LBu : LoadM<0x24, "lbu", zextloadi8>;
417def LH : LoadM<0x21, "lh", sextloadi16>;
418def LHu : LoadM<0x25, "lhu", zextloadi16>;
419def LW : LoadM<0x23, "lw", load>;
420def SB : StoreM<0x28, "sb", truncstorei8>;
421def SH : StoreM<0x29, "sh", truncstorei16>;
422def SW : StoreM<0x2b, "sw", store>;
423
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000424/// Jump and Branch Instructions
425def J : JumpFJ<0x02, "j">;
426def JR : JumpFR<0x00, 0x08, "jr">;
427def JAL : JumpLink<0x03, "jal">;
428def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000429def BEQ : CBranch<0x04, "beq", seteq>;
430def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000431
Eric Christopher3c999a22007-10-26 04:00:13 +0000432let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000433 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000434
435let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000436 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
437 def BLEZ : CBranchZero<0x07, "blez", setle>;
438 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000439}
440
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000441def BGEZAL : BranchLink<"bgezal">;
442def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000443
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000444let isReturn=1, isTerminator=1, hasDelaySlot=1,
445 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
446 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
447 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
448
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000449/// Multiply and Divide Instructions.
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000450let Defs = [HI, LO] in {
451 def MULT : MulDiv<0x18, "mult", IIImul>;
452 def MULTu : MulDiv<0x19, "multu", IIImul>;
453 def DIV : MulDiv<0x1a, "div", IIIdiv>;
454 def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
455}
456
457let Defs = [HI] in
458 def MTHI : MoveToLOHI<0x11, "mthi">;
459let Defs = [LO] in
460 def MTLO : MoveToLOHI<0x13, "mtlo">;
461
462let Uses = [HI] in
463 def MFHI : MoveFromLOHI<0x10, "mfhi">;
464let Uses = [LO] in
465 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000466
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000467/// Sign Ext In Register Instructions.
468let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000469 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000470 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000471
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000472 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000473 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000474}
475
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000476/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000477def CLZ : CountLeading<0b100000, "clz",
478 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
479def CLO : CountLeading<0b100001, "clo",
480 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000481
482/// Byte Swap
483let Predicates = [HasSwap] in {
484 let shamt = 0x3, rs = 0 in
485 def WSBW : ByteSwap<0x20, "wsbw">;
486}
487
488/// Conditional Move
489def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
490def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
491
Eric Christopherc452d792010-06-21 20:19:21 +0000492let Predicates = [HasCondMov], Constraints = "$F = $dst" in {
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000493 def MOVN : CondMov<0x0a, "movn", MIPS_CMOV_NZERO>;
494 def MOVZ : CondMov<0x0b, "movz", MIPS_CMOV_ZERO>;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000495}
496
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000497/// No operation
498let addr=0 in
499 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
500
Eric Christopher3c999a22007-10-26 04:00:13 +0000501// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000502// instructions. The same not happens for stack address copies, so an
503// add op with mem ComplexPattern is used and the stack address copy
504// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000505def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000506
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000507// MADD*/MSUB*
508def MADD : MArithR<0, "madd", MipsMAdd>;
509def MADDU : MArithR<1, "maddu", MipsMAddu>;
510def MSUB : MArithR<4, "msub", MipsMSub>;
511def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000512
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000513// MUL is a assembly macro in the current used ISAs. In recent ISA's
514// it is a real instruction.
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +0000515def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000516
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000517//===----------------------------------------------------------------------===//
518// Arbitrary patterns that map to one or more instructions
519//===----------------------------------------------------------------------===//
520
521// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000522def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000523 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000524def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000525 (ORi ZERO, imm:$in)>;
526
527// Arbitrary immediates
528def : Pat<(i32 imm:$imm),
529 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
530
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000531// Carry patterns
532def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
533 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
534def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
535 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
536def : Pat<(addc CPURegs:$src, imm:$imm),
537 (ADDiu CPURegs:$src, imm:$imm)>;
538
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000539// Call
540def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
541 (JAL tglobaladdr:$dst)>;
542def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
543 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000544//def : Pat<(MipsJmpLink CPURegs:$dst),
545// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000546
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000547// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000548def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000549def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000550 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000551
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000552def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000553def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
554 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000555
556def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
557def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
558 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
559
560// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000561def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000562 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000563def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000564 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000565
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000566// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000567def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000568 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000569
Eric Christopher3c999a22007-10-26 04:00:13 +0000570// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000571def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
572def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
573def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000574
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000575// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000576def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
577
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000578// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000579def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000580 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000581def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
582 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000583
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000584def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000585 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000586def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000587 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
588def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
589 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
590def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
591 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000592
593def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000594 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000595def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000596 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000597
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000598def : Pat<(brcond CPURegs:$cond, bb:$dst),
599 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
600
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000601// select patterns
602def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
603 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$lhs, CPURegs:$rhs))>;
604def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
605 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs))>;
606def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), CPURegs:$T, CPURegs:$F),
607 (MOVZ CPURegs:$F, CPURegs:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs))>;
608def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), CPURegs:$T, CPURegs:$F),
609 (MOVZ CPURegs:$F, CPURegs:$T, (SLTiu CPURegs:$lh, immSExt16:$rh))>;
610
611def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
612 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$rhs, CPURegs:$lhs))>;
613def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
614 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs))>;
615
616def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
617 (MOVZ CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
618def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
619 (MOVN CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
620
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000621def : Pat<(select CPURegs:$cond, CPURegs:$T, CPURegs:$F),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000622 (MOVN CPURegs:$F, CPURegs:$T, CPURegs:$cond)>;
623
Bruno Cardoso Lopesab8d53a2010-12-07 19:00:20 +0000624// select patterns with got access
625def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs),
626 (i32 tglobaladdr:$T), CPURegs:$F),
627 (MOVN CPURegs:$F, (ADDiu GP, tglobaladdr:$T),
628 (XOR CPURegs:$lhs, CPURegs:$rhs))>;
629
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000630// setcc patterns
631def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
632 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
633def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
634 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
635
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000636def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
637 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
638def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
639 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
640
641def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
642 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
643def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
644 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
645
646def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
647 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
648def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
649 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
650
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000651def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
652 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000653def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
654 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000655
656//===----------------------------------------------------------------------===//
657// Floating Point Support
658//===----------------------------------------------------------------------===//
659
660include "MipsInstrFPU.td"
661