blob: b32ae6faf865df6c06ed0a189d1854ab6ade04bf [file] [log] [blame]
Eric Christopher49ac3d72011-05-09 18:16:46 +00001//===- MipsInstrInfo.td - Target Description for Mips Target -*- 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//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Eric Christopher49ac3d72011-05-09 18:16:46 +00009//
10// This file contains the Mips implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000013
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000014//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000015// Instruction format superclass
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000016//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000017
18include "MipsInstrFormats.td"
19
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000020//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000021// Mips profiles and nodes
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000022//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000023
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000024def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
25def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000026def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +000027 SDTCisSameAs<1, 2>,
28 SDTCisSameAs<3, 4>,
29 SDTCisInt<4>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000030def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
31def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000032def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000033 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000034 SDTCisSameAs<1, 2>,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000035 SDTCisSameAs<2, 3>]>;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000036def SDT_MipsDivRem : SDTypeProfile<0, 2,
37 [SDTCisVT<0, i32>,
38 SDTCisSameAs<0, 1>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000039
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000040def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
41
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000042// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000043def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000044 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000045 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000046
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000047// Hi and Lo nodes are used to handle global addresses. Used on
48// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000049// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000050def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
51def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
52def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000053
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000054// TlsGd node is used to handle General Dynamic TLS
55def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
56
57// TprelHi and TprelLo nodes are used to handle Local Exec TLS
58def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
59def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
60
61// Thread pointer
62def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
63
Eric Christopher3c999a22007-10-26 04:00:13 +000064// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000065def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000066 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000067
68// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000069def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000070 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000071def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000072 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000073
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000074// MAdd*/MSub* nodes
75def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
76 [SDNPOptInGlue, SDNPOutGlue]>;
77def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
78 [SDNPOptInGlue, SDNPOutGlue]>;
79def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
80 [SDNPOptInGlue, SDNPOutGlue]>;
81def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
82 [SDNPOptInGlue, SDNPOutGlue]>;
83
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000084// DivRem(u) nodes
85def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
86 [SDNPOutGlue]>;
87def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
88 [SDNPOutGlue]>;
89
Akira Hatanaka342837d2011-05-28 01:07:07 +000090// wrapper node
91def MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", SDTIntUnaryOp>;
92
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000093//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000094// Mips Instruction Predicate Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000095//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +000096def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
97def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000098def HasSwap : Predicate<"Subtarget.hasSwap()">;
99def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +0000100def IsMips32 : Predicate<"Subtarget.isMips32()">;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000101def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000102
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000103//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000104// Mips Operand, Complex Patterns and Transformations Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000105//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000106
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000107// Instruction operand types
108def brtarget : Operand<OtherVT>;
109def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000110def simm16 : Operand<i32>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000111def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000112
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000113// Unsigned Operand
114def uimm16 : Operand<i32> {
115 let PrintMethod = "printUnsignedImm";
116}
117
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000118// Address operand
119def mem : Operand<i32> {
120 let PrintMethod = "printMemOperand";
121 let MIOperandInfo = (ops simm16, CPURegs);
122}
123
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000124// Transformation Function - get the lower 16 bits.
125def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000126 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000127}]>;
128
129// Transformation Function - get the higher 16 bits.
130def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000131 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000132}]>;
133
134// Node immediate fits as 16-bit sign extended on target immediate.
135// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000136def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000137
138// Node immediate fits as 16-bit zero extended on target immediate.
139// The LO16 param means that only the lower 16 bits of the node
140// immediate are caught.
141// e.g. addiu, sltiu
142def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000143 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000144 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000145 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000146 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000147}], LO16>;
148
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000149// shamt field must fit in 5 bits.
150def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000151 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000152}]>;
153
Eric Christopher3c999a22007-10-26 04:00:13 +0000154// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000155// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000156def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000157
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000158//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000159// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000160//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000161
162// Arithmetic 3 register operands
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000163class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000164 InstrItinClass itin, bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000165 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
166 !strconcat(instr_asm, "\t$dst, $b, $c"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000167 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
168 let isCommutable = isComm;
169}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000170
Akira Hatanakaedacba82011-05-25 17:32:06 +0000171class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
172 bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000173 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000174 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
175 let isCommutable = isComm;
176}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000177
178// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000179class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
180 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000181 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
182 !strconcat(instr_asm, "\t$dst, $b, $c"),
183 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000184
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000185class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
186 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000187 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
188 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000189
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000190// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000191let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000192class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000193 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000194 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000195 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
196 let isCommutable = isComm;
197}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000198
199// Logical
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000200let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000201class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000202 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
203 !strconcat(instr_asm, "\t$dst, $b, $c"),
204 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000205
206class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000207 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
208 !strconcat(instr_asm, "\t$dst, $b, $c"),
209 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000210
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000211let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000212class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000213 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
214 !strconcat(instr_asm, "\t$dst, $b, $c"),
215 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000216
217// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000218class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000219 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000220 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
221 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000222 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
223 let rs = _rs;
224}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000225
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000226class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000227 SDNode OpNode>:
228 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000229 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000230 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
231 let shamt = _shamt;
232}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000233
234// Load Upper Imediate
235class LoadUpper<bits<6> op, string instr_asm>:
236 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000237 (outs CPURegs:$dst),
238 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000239 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000240 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000241
Eric Christopher3c999a22007-10-26 04:00:13 +0000242// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000243let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000244class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000245 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
246 !strconcat(instr_asm, "\t$dst, $addr"),
247 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000248
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000249class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000250 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
251 !strconcat(instr_asm, "\t$dst, $addr"),
252 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000253
254// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000255let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000256class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000257 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
258 !strconcat(instr_asm, "\t$a, $b, $offset"),
259 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
260 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000261
262class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000263 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
264 !strconcat(instr_asm, "\t$src, $offset"),
265 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
266 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000267}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000268
Eric Christopher3c999a22007-10-26 04:00:13 +0000269// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000270class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
271 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000272 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
273 !strconcat(instr_asm, "\t$dst, $b, $c"),
274 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
275 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000276
277class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
278 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000279 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
280 !strconcat(instr_asm, "\t$dst, $b, $c"),
281 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
282 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000283
284// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000285let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000286class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000287 FJ<op, (outs), (ins brtarget:$target),
288 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000289
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000290let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000291class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000292 FR<op, func, (outs), (ins CPURegs:$target),
293 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000294
295// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000296let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000297 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000298 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
299 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000300 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000301 FJ<op, (outs), (ins calltarget:$target, variable_ops),
302 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
303 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000304
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000305 let rd=31 in
306 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000307 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
308 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000309
310 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000311 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
312 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000313}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000314
Eric Christopher3c999a22007-10-26 04:00:13 +0000315// Mul, Div
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000316let Defs = [HI, LO] in {
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000317 let isCommutable = 1 in
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000318 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
319 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
320 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
321
322 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
323 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
324 !strconcat(instr_asm, "\t$$zero, $a, $b"),
325 [(op CPURegs:$a, CPURegs:$b)], itin>;
326}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000327
Eric Christopher3c999a22007-10-26 04:00:13 +0000328// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000329class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000330 FR<0x00, func, (outs CPURegs:$dst), (ins),
331 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000332
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000333class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000334 FR<0x00, func, (outs), (ins CPURegs:$src),
335 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000336
Eric Christopher3c999a22007-10-26 04:00:13 +0000337class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000338 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
339 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000340
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000341// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000342class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000343 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000344 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
345 Requires<[HasBitCount]> {
346 let shamt = 0;
347 let rt = rd;
348}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000349
350// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000351class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000352 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
353 !strconcat(instr_asm, "\t$dst, $src"),
354 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000355
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000356// Byte Swap
357class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000358 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
359 !strconcat(instr_asm, "\t$dst, $src"),
360 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000361
362// Conditional Move
363class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000364 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
365 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000366 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000367
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000368// Read Hardware
369class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
370 "rdhwr\t$dst, $src", [], IIAlu> {
371 let rs = 0;
372 let shamt = 0;
373}
374
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000375//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000376// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000377//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000378
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000379// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000380let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000381def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000382 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000383 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000384def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000385 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000386 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000387}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000388
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000389// Some assembly macros need to avoid pseudoinstructions and assembler
390// automatic reodering, we should reorder ourselves.
391def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
392def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
393def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
394def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
395
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000396// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000397// when using the AT register.
398def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
399def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
400
Eric Christopher3c999a22007-10-26 04:00:13 +0000401// When handling PIC code the assembler needs .cpload and .cprestore
402// directives. If the real instructions corresponding these directives
403// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000404// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000405def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanakace98deb2011-05-24 21:22:21 +0000406def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000407
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000408let usesCustomInserter = 1 in {
409 def ATOMIC_LOAD_ADD_I8 : MipsPseudo<
410 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
411 "atomic_load_add_8\t$dst, $ptr, $incr",
412 [(set CPURegs:$dst, (atomic_load_add_8 CPURegs:$ptr, CPURegs:$incr))]>;
413 def ATOMIC_LOAD_ADD_I16 : MipsPseudo<
414 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
415 "atomic_load_add_16\t$dst, $ptr, $incr",
416 [(set CPURegs:$dst, (atomic_load_add_16 CPURegs:$ptr, CPURegs:$incr))]>;
417 def ATOMIC_LOAD_ADD_I32 : MipsPseudo<
418 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
419 "atomic_load_add_32\t$dst, $ptr, $incr",
420 [(set CPURegs:$dst, (atomic_load_add_32 CPURegs:$ptr, CPURegs:$incr))]>;
421
422 def ATOMIC_LOAD_SUB_I8 : MipsPseudo<
423 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
424 "atomic_load_sub_8\t$dst, $ptr, $incr",
425 [(set CPURegs:$dst, (atomic_load_sub_8 CPURegs:$ptr, CPURegs:$incr))]>;
426 def ATOMIC_LOAD_SUB_I16 : MipsPseudo<
427 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
428 "atomic_load_sub_16\t$dst, $ptr, $incr",
429 [(set CPURegs:$dst, (atomic_load_sub_16 CPURegs:$ptr, CPURegs:$incr))]>;
430 def ATOMIC_LOAD_SUB_I32 : MipsPseudo<
431 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
432 "atomic_load_sub_32\t$dst, $ptr, $incr",
433 [(set CPURegs:$dst, (atomic_load_sub_32 CPURegs:$ptr, CPURegs:$incr))]>;
434
435 def ATOMIC_LOAD_AND_I8 : MipsPseudo<
436 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
437 "atomic_load_and_8\t$dst, $ptr, $incr",
438 [(set CPURegs:$dst, (atomic_load_and_8 CPURegs:$ptr, CPURegs:$incr))]>;
439 def ATOMIC_LOAD_AND_I16 : MipsPseudo<
440 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
441 "atomic_load_and_16\t$dst, $ptr, $incr",
442 [(set CPURegs:$dst, (atomic_load_and_16 CPURegs:$ptr, CPURegs:$incr))]>;
443 def ATOMIC_LOAD_AND_I32 : MipsPseudo<
444 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
445 "atomic_load_and_32\t$dst, $ptr, $incr",
446 [(set CPURegs:$dst, (atomic_load_and_32 CPURegs:$ptr, CPURegs:$incr))]>;
447
448 def ATOMIC_LOAD_OR_I8 : MipsPseudo<
449 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
450 "atomic_load_or_8\t$dst, $ptr, $incr",
451 [(set CPURegs:$dst, (atomic_load_or_8 CPURegs:$ptr, CPURegs:$incr))]>;
452 def ATOMIC_LOAD_OR_I16 : MipsPseudo<
453 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
454 "atomic_load_or_16\t$dst, $ptr, $incr",
455 [(set CPURegs:$dst, (atomic_load_or_16 CPURegs:$ptr, CPURegs:$incr))]>;
456 def ATOMIC_LOAD_OR_I32 : MipsPseudo<
457 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
458 "atomic_load_or_32\t$dst, $ptr, $incr",
459 [(set CPURegs:$dst, (atomic_load_or_32 CPURegs:$ptr, CPURegs:$incr))]>;
460
461 def ATOMIC_LOAD_XOR_I8 : MipsPseudo<
462 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
463 "atomic_load_xor_8\t$dst, $ptr, $incr",
464 [(set CPURegs:$dst, (atomic_load_xor_8 CPURegs:$ptr, CPURegs:$incr))]>;
465 def ATOMIC_LOAD_XOR_I16 : MipsPseudo<
466 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
467 "atomic_load_xor_16\t$dst, $ptr, $incr",
468 [(set CPURegs:$dst, (atomic_load_xor_16 CPURegs:$ptr, CPURegs:$incr))]>;
469 def ATOMIC_LOAD_XOR_I32 : MipsPseudo<
470 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
471 "atomic_load_xor_32\t$dst, $ptr, $incr",
472 [(set CPURegs:$dst, (atomic_load_xor_32 CPURegs:$ptr, CPURegs:$incr))]>;
473
474 def ATOMIC_LOAD_NAND_I8 : MipsPseudo<
475 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
476 "atomic_load_nand_8\t$dst, $ptr, $incr",
477 [(set CPURegs:$dst, (atomic_load_nand_8 CPURegs:$ptr, CPURegs:$incr))]>;
478 def ATOMIC_LOAD_NAND_I16 : MipsPseudo<
479 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
480 "atomic_load_nand_16\t$dst, $ptr, $incr",
481 [(set CPURegs:$dst, (atomic_load_nand_16 CPURegs:$ptr, CPURegs:$incr))]>;
482 def ATOMIC_LOAD_NAND_I32 : MipsPseudo<
483 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
484 "atomic_load_nand_32\t$dst, $ptr, $incr",
485 [(set CPURegs:$dst, (atomic_load_nand_32 CPURegs:$ptr, CPURegs:$incr))]>;
486
487 def ATOMIC_SWAP_I8 : MipsPseudo<
488 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
489 "atomic_swap_8\t$dst, $ptr, $val",
490 [(set CPURegs:$dst, (atomic_swap_8 CPURegs:$ptr, CPURegs:$val))]>;
491 def ATOMIC_SWAP_I16 : MipsPseudo<
492 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
493 "atomic_swap_16\t$dst, $ptr, $val",
494 [(set CPURegs:$dst, (atomic_swap_16 CPURegs:$ptr, CPURegs:$val))]>;
495 def ATOMIC_SWAP_I32 : MipsPseudo<
496 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
497 "atomic_swap_32\t$dst, $ptr, $val",
498 [(set CPURegs:$dst, (atomic_swap_32 CPURegs:$ptr, CPURegs:$val))]>;
499
500 def ATOMIC_CMP_SWAP_I8 : MipsPseudo<
501 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
502 "atomic_cmp_swap_8\t$dst, $ptr, $oldval, $newval",
503 [(set CPURegs:$dst,
504 (atomic_cmp_swap_8 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
505 def ATOMIC_CMP_SWAP_I16 : MipsPseudo<
506 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
507 "atomic_cmp_swap_16\t$dst, $ptr, $oldval, $newval",
508 [(set CPURegs:$dst,
509 (atomic_cmp_swap_16 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
510 def ATOMIC_CMP_SWAP_I32 : MipsPseudo<
511 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
512 "atomic_cmp_swap_32\t$dst, $ptr, $oldval, $newval",
513 [(set CPURegs:$dst,
514 (atomic_cmp_swap_32 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
515}
516
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000517//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000518// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000519//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000520
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000521//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000522// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000523//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000524
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000525/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000526def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
527def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000528def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000529def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000530def ANDi : LogicI<0x0c, "andi", and>;
531def ORi : LogicI<0x0d, "ori", or>;
532def XORi : LogicI<0x0e, "xori", xor>;
533def LUi : LoadUpper<0x0f, "lui">;
534
535/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000536def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000537def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000538def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000539def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000540def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
541def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000542def AND : LogicR<0x24, "and", and>;
543def OR : LogicR<0x25, "or", or>;
544def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000545def NOR : LogicNOR<0x00, 0x27, "nor">;
546
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000547/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000548def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
549def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
550def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
551def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
552def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
553def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
554
555// Rotate Instructions
556let Predicates = [IsMips32r2] in {
557 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
558 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
559}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000560
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000561/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000562def LB : LoadM<0x20, "lb", sextloadi8>;
563def LBu : LoadM<0x24, "lbu", zextloadi8>;
564def LH : LoadM<0x21, "lh", sextloadi16>;
565def LHu : LoadM<0x25, "lhu", zextloadi16>;
566def LW : LoadM<0x23, "lw", load>;
567def SB : StoreM<0x28, "sb", truncstorei8>;
568def SH : StoreM<0x29, "sh", truncstorei16>;
569def SW : StoreM<0x2b, "sw", store>;
570
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000571/// Load-linked, Store-conditional
572let hasDelaySlot = 1 in
573 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
574 "ll\t$dst, $addr", [], IILoad>;
575let Constraints = "$src = $dst" in
576 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
577 "sc\t$src, $addr", [], IIStore>;
578
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000579/// Jump and Branch Instructions
580def J : JumpFJ<0x02, "j">;
581def JR : JumpFR<0x00, 0x08, "jr">;
582def JAL : JumpLink<0x03, "jal">;
583def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000584def BEQ : CBranch<0x04, "beq", seteq>;
585def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000586
Eric Christopher3c999a22007-10-26 04:00:13 +0000587let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000588 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000589
590let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000591 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
592 def BLEZ : CBranchZero<0x07, "blez", setle>;
593 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000594}
595
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000596def BGEZAL : BranchLink<"bgezal">;
597def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000598
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000599let isReturn=1, isTerminator=1, hasDelaySlot=1,
600 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
601 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
602 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
603
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000604/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000605def MULT : Mul<0x18, "mult", IIImul>;
606def MULTu : Mul<0x19, "multu", IIImul>;
607def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
608def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000609
610let Defs = [HI] in
611 def MTHI : MoveToLOHI<0x11, "mthi">;
612let Defs = [LO] in
613 def MTLO : MoveToLOHI<0x13, "mtlo">;
614
615let Uses = [HI] in
616 def MFHI : MoveFromLOHI<0x10, "mfhi">;
617let Uses = [LO] in
618 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000619
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000620/// Sign Ext In Register Instructions.
621let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000622 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000623 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000624
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000625 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000626 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000627}
628
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000629/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000630def CLZ : CountLeading<0b100000, "clz",
631 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
632def CLO : CountLeading<0b100001, "clo",
633 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000634
635/// Byte Swap
636let Predicates = [HasSwap] in {
637 let shamt = 0x3, rs = 0 in
638 def WSBW : ByteSwap<0x20, "wsbw">;
639}
640
641/// Conditional Move
642def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
643def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
644
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000645// Conditional moves:
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +0000646// These instructions are expanded in
647// MipsISelLowering::EmitInstrWithCustomInserter if target does not have
648// conditional move instructions.
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000649// flag:int, data:int
650let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
651 class CondMovIntInt<bits<6> funct, string instr_asm> :
652 FR<0, funct, (outs CPURegs:$dst),
653 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
654 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
655
656def MOVZ_I : CondMovIntInt<0x0a, "movz">;
657def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000658
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000659/// No operation
660let addr=0 in
661 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
662
Eric Christopher3c999a22007-10-26 04:00:13 +0000663// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000664// instructions. The same not happens for stack address copies, so an
665// add op with mem ComplexPattern is used and the stack address copy
666// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000667def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000668
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000669// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000670def MADD : MArithR<0, "madd", MipsMAdd, 1>;
671def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000672def MSUB : MArithR<4, "msub", MipsMSub>;
673def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000674
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000675// MUL is a assembly macro in the current used ISAs. In recent ISA's
676// it is a real instruction.
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000677def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000678
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000679def RDHWR : ReadHardware;
680
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000681//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000682// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000683//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000684
685// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000686def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000687 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000688def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000689 (ORi ZERO, imm:$in)>;
690
691// Arbitrary immediates
692def : Pat<(i32 imm:$imm),
693 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
694
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000695// Carry patterns
696def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
697 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
698def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
699 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000700def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000701 (ADDiu CPURegs:$src, imm:$imm)>;
702
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000703// Call
704def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
705 (JAL tglobaladdr:$dst)>;
706def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
707 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000708//def : Pat<(MipsJmpLink CPURegs:$dst),
709// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000710
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000711// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000712def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000713def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000714def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000715 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000716def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
717 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000718
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000719def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000720def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
721 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000722
723def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
724def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
725 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
726
727// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000728def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000729 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000730def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000731 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000732
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000733// tlsgd
734def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
735 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
736
737// tprel hi/lo
738def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
739def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
740 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
741
Akira Hatanaka342837d2011-05-28 01:07:07 +0000742// wrapper_pic
743class WrapperPICPat<SDNode node>:
744 Pat<(MipsWrapperPIC node:$in),
745 (ADDiu GP, node:$in)>;
746
747def : WrapperPICPat<tglobaladdr>;
748def : WrapperPICPat<tconstpool>;
749def : WrapperPICPat<texternalsym>;
750def : WrapperPICPat<tblockaddress>;
751def : WrapperPICPat<tjumptable>;
752
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000753// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000754def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000755 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000756
Eric Christopher3c999a22007-10-26 04:00:13 +0000757// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000758def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
759def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
760def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000761
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000762// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000763def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
764
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000765// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000766def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000767 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000768def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
769 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000770
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000771def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000772 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000773def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000774 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
775def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
776 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
777def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
778 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000779
780def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000781 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000782def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000783 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000784
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000785def : Pat<(brcond CPURegs:$cond, bb:$dst),
786 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
787
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000788// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000789multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
790 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
791 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
792 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
793 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
794 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
795 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
796 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
797 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
798 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
799 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
800 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
801 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
802 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
803 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
804 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
805 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
806}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000807
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000808multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
809 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
810 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
811 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
812 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
813 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
814 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
815}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000816
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000817defm : MovzPats<CPURegs, MOVZ_I>;
818defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000819
820// setcc patterns
821def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
822 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
823def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
824 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
825
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000826def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
827 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
828def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
829 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
830
831def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
832 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
833def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
834 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
835
836def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
837 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
838def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
839 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
840
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000841def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
842 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000843def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
844 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000845
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000846//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000847// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000848//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000849
850include "MipsInstrFPU.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000851