blob: ceaf75f70a936cd203b7cd6c0652971440d810f4 [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 Lopes81092dc2011-03-04 17:51:39 +000029def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000030 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000031 SDTCisSameAs<1, 2>,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000032 SDTCisSameAs<2, 3>]>;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000033def SDT_MipsDivRem : SDTypeProfile<0, 2,
34 [SDTCisVT<0, i32>,
35 SDTCisSameAs<0, 1>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000036
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000037// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000038def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000039 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000040 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000041
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000042// Hi and Lo nodes are used to handle global addresses. Used on
43// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000044// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000045def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
46def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
47def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000048
Eric Christopher3c999a22007-10-26 04:00:13 +000049// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000050def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000051 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000052
53// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000054def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000055 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000056def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000057 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000058
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000059// Select Condition Code
60def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +000061
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000062// MAdd*/MSub* nodes
63def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
64 [SDNPOptInGlue, SDNPOutGlue]>;
65def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
66 [SDNPOptInGlue, SDNPOutGlue]>;
67def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
68 [SDNPOptInGlue, SDNPOutGlue]>;
69def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
70 [SDNPOptInGlue, SDNPOutGlue]>;
71
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000072// DivRem(u) nodes
73def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
74 [SDNPOutGlue]>;
75def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
76 [SDNPOutGlue]>;
77
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000078//===----------------------------------------------------------------------===//
79// Mips Instruction Predicate Definitions.
80//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +000081def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
82def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000083def HasSwap : Predicate<"Subtarget.hasSwap()">;
84def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +000085def IsMips32 : Predicate<"Subtarget.isMips32()">;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +000086def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000087
88//===----------------------------------------------------------------------===//
89// Mips Operand, Complex Patterns and Transformations Definitions.
90//===----------------------------------------------------------------------===//
91
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000092// Instruction operand types
93def brtarget : Operand<OtherVT>;
94def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000095def simm16 : Operand<i32>;
Eric Christopher3c999a22007-10-26 04:00:13 +000096def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000097
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000098// Unsigned Operand
99def uimm16 : Operand<i32> {
100 let PrintMethod = "printUnsignedImm";
101}
102
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000103// Address operand
104def mem : Operand<i32> {
105 let PrintMethod = "printMemOperand";
106 let MIOperandInfo = (ops simm16, CPURegs);
107}
108
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000109// Transformation Function - get the lower 16 bits.
110def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000111 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000112}]>;
113
114// Transformation Function - get the higher 16 bits.
115def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000116 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000117}]>;
118
119// Node immediate fits as 16-bit sign extended on target immediate.
120// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000121def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000122
123// Node immediate fits as 16-bit zero extended on target immediate.
124// The LO16 param means that only the lower 16 bits of the node
125// immediate are caught.
126// e.g. addiu, sltiu
127def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000128 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000129 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000130 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000131 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000132}], LO16>;
133
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000134// shamt field must fit in 5 bits.
135def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000136 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000137}]>;
138
Eric Christopher3c999a22007-10-26 04:00:13 +0000139// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000140// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000141def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000142
143//===----------------------------------------------------------------------===//
144// Instructions specific format
145//===----------------------------------------------------------------------===//
146
147// Arithmetic 3 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000148let isCommutable = 1 in
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000149class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher3c999a22007-10-26 04:00:13 +0000150 InstrItinClass itin>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000151 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
152 !strconcat(instr_asm, "\t$dst, $b, $c"),
153 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000154
Eric Christopher3c999a22007-10-26 04:00:13 +0000155let isCommutable = 1 in
156class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000157 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
158 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000159
160// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000161class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
162 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000163 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
164 !strconcat(instr_asm, "\t$dst, $b, $c"),
165 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000166
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000167class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
168 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000169 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
170 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000171
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000172// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000173let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
174class MArithR<bits<6> func, string instr_asm, SDNode op> :
175 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000176 !strconcat(instr_asm, "\t$rs, $rt"),
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000177 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000178
179// Logical
180class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000181 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
182 !strconcat(instr_asm, "\t$dst, $b, $c"),
183 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000184
185class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000186 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
187 !strconcat(instr_asm, "\t$dst, $b, $c"),
188 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000189
190class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000191 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
192 !strconcat(instr_asm, "\t$dst, $b, $c"),
193 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000194
195// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000196class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000197 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000198 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
199 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000200 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
201 let rs = _rs;
202}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000203
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000204class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000205 SDNode OpNode>:
206 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000207 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000208 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
209 let shamt = _shamt;
210}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000211
212// Load Upper Imediate
213class LoadUpper<bits<6> op, string instr_asm>:
214 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000215 (outs CPURegs:$dst),
216 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000217 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000218 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000219
Eric Christopher3c999a22007-10-26 04:00:13 +0000220// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000221let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000222class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000223 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
224 !strconcat(instr_asm, "\t$dst, $addr"),
225 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000226
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000227class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000228 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
229 !strconcat(instr_asm, "\t$dst, $addr"),
230 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000231
232// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000233let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000234class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000235 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
236 !strconcat(instr_asm, "\t$a, $b, $offset"),
237 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
238 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000239
240class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000241 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
242 !strconcat(instr_asm, "\t$src, $offset"),
243 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
244 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000245}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000246
Eric Christopher3c999a22007-10-26 04:00:13 +0000247// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000248class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
249 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000250 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
251 !strconcat(instr_asm, "\t$dst, $b, $c"),
252 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
253 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000254
255class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
256 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000257 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
258 !strconcat(instr_asm, "\t$dst, $b, $c"),
259 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
260 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000261
262// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000263let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000264class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000265 FJ<op, (outs), (ins brtarget:$target),
266 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000267
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000268let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000269class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000270 FR<op, func, (outs), (ins CPURegs:$target),
271 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000272
273// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000274let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000275 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000276 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
277 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000278 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000279 FJ<op, (outs), (ins calltarget:$target, variable_ops),
280 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
281 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000282
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000283 let rd=31 in
284 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000285 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
286 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000287
288 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000289 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
290 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000291}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000292
Eric Christopher3c999a22007-10-26 04:00:13 +0000293// Mul, Div
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000294let Defs = [HI, LO] in {
295 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
296 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
297 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
298
299 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
300 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
301 !strconcat(instr_asm, "\t$$zero, $a, $b"),
302 [(op CPURegs:$a, CPURegs:$b)], itin>;
303}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000304
Eric Christopher3c999a22007-10-26 04:00:13 +0000305// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000306class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000307 FR<0x00, func, (outs CPURegs:$dst), (ins),
308 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000309
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000310class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000311 FR<0x00, func, (outs), (ins CPURegs:$src),
312 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000313
Eric Christopher3c999a22007-10-26 04:00:13 +0000314class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000315 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
316 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000317
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000318// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000319class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000320 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000321 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
322 Requires<[HasBitCount]> {
323 let shamt = 0;
324 let rt = rd;
325}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000326
327// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000328class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000329 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
330 !strconcat(instr_asm, "\t$dst, $src"),
331 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000332
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000333// Byte Swap
334class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000335 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
336 !strconcat(instr_asm, "\t$dst, $src"),
337 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000338
339// Conditional Move
340class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000341 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
342 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000343 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000344
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000345//===----------------------------------------------------------------------===//
346// Pseudo instructions
347//===----------------------------------------------------------------------===//
348
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000349// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000350let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000351def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000352 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000353 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000354def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000355 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000356 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000357}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000358
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000359// Some assembly macros need to avoid pseudoinstructions and assembler
360// automatic reodering, we should reorder ourselves.
361def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
362def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
363def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
364def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
365
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000366// These macros are inserted to prevent GAS from complaining
367// when using the AT register.
368def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
369def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
370
Eric Christopher3c999a22007-10-26 04:00:13 +0000371// When handling PIC code the assembler needs .cpload and .cprestore
372// directives. If the real instructions corresponding these directives
373// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000374// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000375def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
376def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000377
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000378// The supported Mips ISAs dont have any instruction close to the SELECT_CC
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000379// operation. The solution is to create a Mips pseudo SELECT_CC instruction
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000380// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000381// replace it for real supported nodes into EmitInstrWithCustomInserter
Dan Gohman533297b2009-10-29 18:10:34 +0000382let usesCustomInserter = 1 in {
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000383 class PseudoSelCC<RegisterClass RC, string asmstr>:
384 MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr,
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000385 [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000386}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000387
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000388def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
389
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000390//===----------------------------------------------------------------------===//
391// Instruction definition
392//===----------------------------------------------------------------------===//
393
394//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000395// MipsI Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000396//===----------------------------------------------------------------------===//
397
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000398/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000399def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
400def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000401def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000402def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000403def ANDi : LogicI<0x0c, "andi", and>;
404def ORi : LogicI<0x0d, "ori", or>;
405def XORi : LogicI<0x0e, "xori", xor>;
406def LUi : LoadUpper<0x0f, "lui">;
407
408/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000409def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
410def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000411def ADD : ArithOverflowR<0x00, 0x20, "add">;
412def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000413def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
414def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000415def AND : LogicR<0x24, "and", and>;
416def OR : LogicR<0x25, "or", or>;
417def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000418def NOR : LogicNOR<0x00, 0x27, "nor">;
419
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000420/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000421def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
422def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
423def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
424def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
425def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
426def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
427
428// Rotate Instructions
429let Predicates = [IsMips32r2] in {
430 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
431 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
432}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000433
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000434/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +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 Lopesf7d66f72008-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">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000449def BEQ : CBranch<0x04, "beq", seteq>;
450def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000451
Eric Christopher3c999a22007-10-26 04:00:13 +0000452let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000453 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000454
455let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-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 Lopes97105362007-08-18 02:37:46 +0000459}
460
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000461def BGEZAL : BranchLink<"bgezal">;
462def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000463
Bruno Cardoso Lopesf7d66f72008-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
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000469/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000470def MULT : Mul<0x18, "mult", IIImul>;
471def MULTu : Mul<0x19, "multu", IIImul>;
472def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
473def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000474
475let Defs = [HI] in
476 def MTHI : MoveToLOHI<0x11, "mthi">;
477let Defs = [LO] in
478 def MTLO : MoveToLOHI<0x13, "mtlo">;
479
480let Uses = [HI] in
481 def MFHI : MoveFromLOHI<0x10, "mfhi">;
482let Uses = [LO] in
483 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000484
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000485/// Sign Ext In Register Instructions.
486let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000487 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000488 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000489
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000490 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000491 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000492}
493
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000494/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000495def CLZ : CountLeading<0b100000, "clz",
496 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
497def CLO : CountLeading<0b100001, "clo",
498 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000499
500/// Byte Swap
501let Predicates = [HasSwap] in {
502 let shamt = 0x3, rs = 0 in
503 def WSBW : ByteSwap<0x20, "wsbw">;
504}
505
506/// Conditional Move
507def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
508def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
509
Eric Christopherc452d792010-06-21 20:19:21 +0000510let Predicates = [HasCondMov], Constraints = "$F = $dst" in {
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000511 def MOVN : CondMov<0x0a, "movn", MIPS_CMOV_NZERO>;
512 def MOVZ : CondMov<0x0b, "movz", MIPS_CMOV_ZERO>;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000513}
514
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000515/// No operation
516let addr=0 in
517 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
518
Eric Christopher3c999a22007-10-26 04:00:13 +0000519// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000520// instructions. The same not happens for stack address copies, so an
521// add op with mem ComplexPattern is used and the stack address copy
522// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000523def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000524
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000525// MADD*/MSUB*
526def MADD : MArithR<0, "madd", MipsMAdd>;
527def MADDU : MArithR<1, "maddu", MipsMAddu>;
528def MSUB : MArithR<4, "msub", MipsMSub>;
529def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000530
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000531// MUL is a assembly macro in the current used ISAs. In recent ISA's
532// it is a real instruction.
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +0000533def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000534
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000535//===----------------------------------------------------------------------===//
536// Arbitrary patterns that map to one or more instructions
537//===----------------------------------------------------------------------===//
538
539// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000540def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000541 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000542def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000543 (ORi ZERO, imm:$in)>;
544
545// Arbitrary immediates
546def : Pat<(i32 imm:$imm),
547 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
548
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000549// Carry patterns
550def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
551 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
552def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
553 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000554def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000555 (ADDiu CPURegs:$src, imm:$imm)>;
556
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000557// Call
558def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
559 (JAL tglobaladdr:$dst)>;
560def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
561 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000562//def : Pat<(MipsJmpLink CPURegs:$dst),
563// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000564
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000565// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000566def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000567def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000568 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000569def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
570 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000571
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000572def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000573def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
574 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000575
576def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
577def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
578 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
579
580// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000581def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000582 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000583def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000584 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000585
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000586// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000587def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000588 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000589
Eric Christopher3c999a22007-10-26 04:00:13 +0000590// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000591def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
592def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
593def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000594
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000595// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000596def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
597
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000598// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000599def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000600 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000601def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
602 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000603
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000604def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000605 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000606def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000607 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
608def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
609 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
610def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
611 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000612
613def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000614 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000615def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000616 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000617
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000618def : Pat<(brcond CPURegs:$cond, bb:$dst),
619 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
620
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000621// select patterns
622def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
623 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$lhs, CPURegs:$rhs))>;
624def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
625 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs))>;
626def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), CPURegs:$T, CPURegs:$F),
627 (MOVZ CPURegs:$F, CPURegs:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs))>;
628def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), CPURegs:$T, CPURegs:$F),
629 (MOVZ CPURegs:$F, CPURegs:$T, (SLTiu CPURegs:$lh, immSExt16:$rh))>;
630
631def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
632 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$rhs, CPURegs:$lhs))>;
633def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
634 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs))>;
635
636def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
637 (MOVZ CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
638def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
639 (MOVN CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
640
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000641def : Pat<(select CPURegs:$cond, CPURegs:$T, CPURegs:$F),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000642 (MOVN CPURegs:$F, CPURegs:$T, CPURegs:$cond)>;
643
Bruno Cardoso Lopesab8d53a2010-12-07 19:00:20 +0000644// select patterns with got access
645def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs),
646 (i32 tglobaladdr:$T), CPURegs:$F),
647 (MOVN CPURegs:$F, (ADDiu GP, tglobaladdr:$T),
648 (XOR CPURegs:$lhs, CPURegs:$rhs))>;
649
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000650// setcc patterns
651def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
652 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
653def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
654 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
655
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000656def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
657 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
658def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
659 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
660
661def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
662 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
663def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
664 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
665
666def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
667 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
668def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
669 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
670
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000671def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
672 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000673def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
674 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000675
676//===----------------------------------------------------------------------===//
677// Floating Point Support
678//===----------------------------------------------------------------------===//
679
680include "MipsInstrFPU.td"
681