blob: 329a002667a0380201956395fd3bec21ab5bb604 [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 Hatanaka6cd4b4e2011-06-07 18:00:14 +000090// Target constant nodes that are not part of any isel patterns and remain
91// unchanged can cause instructions with illegal operands to be emitted.
92// Wrapper node patterns give the instruction selector a chance to replace
93// target constant nodes that would otherwise remain unchanged with ADDiu
94// nodes. Without these wrapper node patterns, the following conditional move
95// instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
96// compiled:
97// movn %got(d)($gp), %got(c)($gp), $4
98// This instruction is illegal since movn can take only register operands.
99
Akira Hatanaka342837d2011-05-28 01:07:07 +0000100def MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", SDTIntUnaryOp>;
101
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000102//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000103// Mips Instruction Predicate Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000104//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000105def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
106def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000107def HasSwap : Predicate<"Subtarget.hasSwap()">;
108def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +0000109def IsMips32 : Predicate<"Subtarget.isMips32()">;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000110def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000111
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000112//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000113// Mips Operand, Complex Patterns and Transformations Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000114//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000115
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000116// Instruction operand types
117def brtarget : Operand<OtherVT>;
118def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000119def simm16 : Operand<i32>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000120def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000121
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000122// Unsigned Operand
123def uimm16 : Operand<i32> {
124 let PrintMethod = "printUnsignedImm";
125}
126
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000127// Address operand
128def mem : Operand<i32> {
129 let PrintMethod = "printMemOperand";
130 let MIOperandInfo = (ops simm16, CPURegs);
131}
132
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000133// Transformation Function - get the lower 16 bits.
134def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000135 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000136}]>;
137
138// Transformation Function - get the higher 16 bits.
139def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000140 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000141}]>;
142
143// Node immediate fits as 16-bit sign extended on target immediate.
144// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000145def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000146
147// Node immediate fits as 16-bit zero extended on target immediate.
148// The LO16 param means that only the lower 16 bits of the node
149// immediate are caught.
150// e.g. addiu, sltiu
151def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000152 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000153 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000154 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000155 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000156}], LO16>;
157
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000158// shamt field must fit in 5 bits.
159def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000160 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000161}]>;
162
Eric Christopher3c999a22007-10-26 04:00:13 +0000163// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000164// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000165def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000166
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000167//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000168// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000169//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000170
171// Arithmetic 3 register operands
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000172class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000173 InstrItinClass itin, bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000174 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
175 !strconcat(instr_asm, "\t$dst, $b, $c"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000176 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
177 let isCommutable = isComm;
178}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000179
Akira Hatanakaedacba82011-05-25 17:32:06 +0000180class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
181 bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000182 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000183 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
184 let isCommutable = isComm;
185}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000186
187// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000188class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
189 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000190 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
191 !strconcat(instr_asm, "\t$dst, $b, $c"),
192 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000193
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000194class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
195 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000196 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
197 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000198
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000199// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000200let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000201class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000202 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000203 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000204 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
205 let isCommutable = isComm;
206}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000207
208// Logical
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000209let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000210class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000211 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
212 !strconcat(instr_asm, "\t$dst, $b, $c"),
213 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000214
215class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000216 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
217 !strconcat(instr_asm, "\t$dst, $b, $c"),
218 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000219
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000220let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000221class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000222 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
223 !strconcat(instr_asm, "\t$dst, $b, $c"),
224 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000225
226// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000227class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000228 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000229 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
230 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000231 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
232 let rs = _rs;
233}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000234
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000235class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000236 SDNode OpNode>:
237 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000238 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000239 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
240 let shamt = _shamt;
241}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000242
243// Load Upper Imediate
244class LoadUpper<bits<6> op, string instr_asm>:
245 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000246 (outs CPURegs:$dst),
247 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000248 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000249 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000250
Eric Christopher3c999a22007-10-26 04:00:13 +0000251// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000252let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000253class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000254 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
255 !strconcat(instr_asm, "\t$dst, $addr"),
256 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000257
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000258class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000259 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
260 !strconcat(instr_asm, "\t$dst, $addr"),
261 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000262
263// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000264let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000265class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000266 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
267 !strconcat(instr_asm, "\t$a, $b, $offset"),
268 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
269 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000270
271class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000272 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
273 !strconcat(instr_asm, "\t$src, $offset"),
274 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
275 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000276}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000277
Eric Christopher3c999a22007-10-26 04:00:13 +0000278// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000279class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
280 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000281 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
282 !strconcat(instr_asm, "\t$dst, $b, $c"),
283 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
284 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000285
286class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
287 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000288 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
289 !strconcat(instr_asm, "\t$dst, $b, $c"),
290 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
291 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000292
293// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000294let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000295class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000296 FJ<op, (outs), (ins brtarget:$target),
297 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000298
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000299let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000300class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000301 FR<op, func, (outs), (ins CPURegs:$target),
302 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000303
304// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000305let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000306 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000307 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
308 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000309 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000310 FJ<op, (outs), (ins calltarget:$target, variable_ops),
311 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
312 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000313
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000314 let rd=31 in
315 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000316 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
317 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000318
319 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000320 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
321 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000322}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000323
Eric Christopher3c999a22007-10-26 04:00:13 +0000324// Mul, Div
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000325let Defs = [HI, LO] in {
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000326 let isCommutable = 1 in
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000327 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
328 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
329 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
330
331 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
332 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
333 !strconcat(instr_asm, "\t$$zero, $a, $b"),
334 [(op CPURegs:$a, CPURegs:$b)], itin>;
335}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000336
Eric Christopher3c999a22007-10-26 04:00:13 +0000337// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000338class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000339 FR<0x00, func, (outs CPURegs:$dst), (ins),
340 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000341
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000342class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000343 FR<0x00, func, (outs), (ins CPURegs:$src),
344 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000345
Eric Christopher3c999a22007-10-26 04:00:13 +0000346class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000347 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
348 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000349
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000350// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000351class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000352 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000353 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
354 Requires<[HasBitCount]> {
355 let shamt = 0;
356 let rt = rd;
357}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000358
359// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000360class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000361 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
362 !strconcat(instr_asm, "\t$dst, $src"),
363 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000364
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000365// Byte Swap
366class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000367 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
368 !strconcat(instr_asm, "\t$dst, $src"),
369 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000370
371// Conditional Move
372class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000373 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
374 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000375 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000376
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000377// Read Hardware
378class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
379 "rdhwr\t$dst, $src", [], IIAlu> {
380 let rs = 0;
381 let shamt = 0;
382}
383
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000384//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000385// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000386//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000387
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000388// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000389let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000390def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000391 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000392 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000393def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000394 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000395 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000396}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000397
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000398// Some assembly macros need to avoid pseudoinstructions and assembler
399// automatic reodering, we should reorder ourselves.
400def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
401def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
402def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
403def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
404
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000405// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000406// when using the AT register.
407def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
408def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
409
Eric Christopher3c999a22007-10-26 04:00:13 +0000410// When handling PIC code the assembler needs .cpload and .cprestore
411// directives. If the real instructions corresponding these directives
412// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000413// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000414def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanakace98deb2011-05-24 21:22:21 +0000415def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000416
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000417let usesCustomInserter = 1 in {
418 def ATOMIC_LOAD_ADD_I8 : MipsPseudo<
419 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
420 "atomic_load_add_8\t$dst, $ptr, $incr",
421 [(set CPURegs:$dst, (atomic_load_add_8 CPURegs:$ptr, CPURegs:$incr))]>;
422 def ATOMIC_LOAD_ADD_I16 : MipsPseudo<
423 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
424 "atomic_load_add_16\t$dst, $ptr, $incr",
425 [(set CPURegs:$dst, (atomic_load_add_16 CPURegs:$ptr, CPURegs:$incr))]>;
426 def ATOMIC_LOAD_ADD_I32 : MipsPseudo<
427 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
428 "atomic_load_add_32\t$dst, $ptr, $incr",
429 [(set CPURegs:$dst, (atomic_load_add_32 CPURegs:$ptr, CPURegs:$incr))]>;
430
431 def ATOMIC_LOAD_SUB_I8 : MipsPseudo<
432 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
433 "atomic_load_sub_8\t$dst, $ptr, $incr",
434 [(set CPURegs:$dst, (atomic_load_sub_8 CPURegs:$ptr, CPURegs:$incr))]>;
435 def ATOMIC_LOAD_SUB_I16 : MipsPseudo<
436 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
437 "atomic_load_sub_16\t$dst, $ptr, $incr",
438 [(set CPURegs:$dst, (atomic_load_sub_16 CPURegs:$ptr, CPURegs:$incr))]>;
439 def ATOMIC_LOAD_SUB_I32 : MipsPseudo<
440 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
441 "atomic_load_sub_32\t$dst, $ptr, $incr",
442 [(set CPURegs:$dst, (atomic_load_sub_32 CPURegs:$ptr, CPURegs:$incr))]>;
443
444 def ATOMIC_LOAD_AND_I8 : MipsPseudo<
445 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
446 "atomic_load_and_8\t$dst, $ptr, $incr",
447 [(set CPURegs:$dst, (atomic_load_and_8 CPURegs:$ptr, CPURegs:$incr))]>;
448 def ATOMIC_LOAD_AND_I16 : MipsPseudo<
449 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
450 "atomic_load_and_16\t$dst, $ptr, $incr",
451 [(set CPURegs:$dst, (atomic_load_and_16 CPURegs:$ptr, CPURegs:$incr))]>;
452 def ATOMIC_LOAD_AND_I32 : MipsPseudo<
453 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
454 "atomic_load_and_32\t$dst, $ptr, $incr",
455 [(set CPURegs:$dst, (atomic_load_and_32 CPURegs:$ptr, CPURegs:$incr))]>;
456
457 def ATOMIC_LOAD_OR_I8 : MipsPseudo<
458 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
459 "atomic_load_or_8\t$dst, $ptr, $incr",
460 [(set CPURegs:$dst, (atomic_load_or_8 CPURegs:$ptr, CPURegs:$incr))]>;
461 def ATOMIC_LOAD_OR_I16 : MipsPseudo<
462 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
463 "atomic_load_or_16\t$dst, $ptr, $incr",
464 [(set CPURegs:$dst, (atomic_load_or_16 CPURegs:$ptr, CPURegs:$incr))]>;
465 def ATOMIC_LOAD_OR_I32 : MipsPseudo<
466 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
467 "atomic_load_or_32\t$dst, $ptr, $incr",
468 [(set CPURegs:$dst, (atomic_load_or_32 CPURegs:$ptr, CPURegs:$incr))]>;
469
470 def ATOMIC_LOAD_XOR_I8 : MipsPseudo<
471 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
472 "atomic_load_xor_8\t$dst, $ptr, $incr",
473 [(set CPURegs:$dst, (atomic_load_xor_8 CPURegs:$ptr, CPURegs:$incr))]>;
474 def ATOMIC_LOAD_XOR_I16 : MipsPseudo<
475 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
476 "atomic_load_xor_16\t$dst, $ptr, $incr",
477 [(set CPURegs:$dst, (atomic_load_xor_16 CPURegs:$ptr, CPURegs:$incr))]>;
478 def ATOMIC_LOAD_XOR_I32 : MipsPseudo<
479 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
480 "atomic_load_xor_32\t$dst, $ptr, $incr",
481 [(set CPURegs:$dst, (atomic_load_xor_32 CPURegs:$ptr, CPURegs:$incr))]>;
482
483 def ATOMIC_LOAD_NAND_I8 : MipsPseudo<
484 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
485 "atomic_load_nand_8\t$dst, $ptr, $incr",
486 [(set CPURegs:$dst, (atomic_load_nand_8 CPURegs:$ptr, CPURegs:$incr))]>;
487 def ATOMIC_LOAD_NAND_I16 : MipsPseudo<
488 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
489 "atomic_load_nand_16\t$dst, $ptr, $incr",
490 [(set CPURegs:$dst, (atomic_load_nand_16 CPURegs:$ptr, CPURegs:$incr))]>;
491 def ATOMIC_LOAD_NAND_I32 : MipsPseudo<
492 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
493 "atomic_load_nand_32\t$dst, $ptr, $incr",
494 [(set CPURegs:$dst, (atomic_load_nand_32 CPURegs:$ptr, CPURegs:$incr))]>;
495
496 def ATOMIC_SWAP_I8 : MipsPseudo<
497 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
498 "atomic_swap_8\t$dst, $ptr, $val",
499 [(set CPURegs:$dst, (atomic_swap_8 CPURegs:$ptr, CPURegs:$val))]>;
500 def ATOMIC_SWAP_I16 : MipsPseudo<
501 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
502 "atomic_swap_16\t$dst, $ptr, $val",
503 [(set CPURegs:$dst, (atomic_swap_16 CPURegs:$ptr, CPURegs:$val))]>;
504 def ATOMIC_SWAP_I32 : MipsPseudo<
505 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
506 "atomic_swap_32\t$dst, $ptr, $val",
507 [(set CPURegs:$dst, (atomic_swap_32 CPURegs:$ptr, CPURegs:$val))]>;
508
509 def ATOMIC_CMP_SWAP_I8 : MipsPseudo<
510 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
511 "atomic_cmp_swap_8\t$dst, $ptr, $oldval, $newval",
512 [(set CPURegs:$dst,
513 (atomic_cmp_swap_8 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
514 def ATOMIC_CMP_SWAP_I16 : MipsPseudo<
515 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
516 "atomic_cmp_swap_16\t$dst, $ptr, $oldval, $newval",
517 [(set CPURegs:$dst,
518 (atomic_cmp_swap_16 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
519 def ATOMIC_CMP_SWAP_I32 : MipsPseudo<
520 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
521 "atomic_cmp_swap_32\t$dst, $ptr, $oldval, $newval",
522 [(set CPURegs:$dst,
523 (atomic_cmp_swap_32 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
524}
525
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000526//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000527// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000528//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000529
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000530//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000531// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000532//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000533
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000534/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000535def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
536def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000537def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000538def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000539def ANDi : LogicI<0x0c, "andi", and>;
540def ORi : LogicI<0x0d, "ori", or>;
541def XORi : LogicI<0x0e, "xori", xor>;
542def LUi : LoadUpper<0x0f, "lui">;
543
544/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000545def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000546def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000547def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000548def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000549def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
550def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000551def AND : LogicR<0x24, "and", and>;
552def OR : LogicR<0x25, "or", or>;
553def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000554def NOR : LogicNOR<0x00, 0x27, "nor">;
555
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000556/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000557def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
558def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
559def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
560def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
561def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
562def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
563
564// Rotate Instructions
565let Predicates = [IsMips32r2] in {
566 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
567 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
568}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000569
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000570/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000571def LB : LoadM<0x20, "lb", sextloadi8>;
572def LBu : LoadM<0x24, "lbu", zextloadi8>;
573def LH : LoadM<0x21, "lh", sextloadi16>;
574def LHu : LoadM<0x25, "lhu", zextloadi16>;
575def LW : LoadM<0x23, "lw", load>;
576def SB : StoreM<0x28, "sb", truncstorei8>;
577def SH : StoreM<0x29, "sh", truncstorei16>;
578def SW : StoreM<0x2b, "sw", store>;
579
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000580/// Load-linked, Store-conditional
581let hasDelaySlot = 1 in
582 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
583 "ll\t$dst, $addr", [], IILoad>;
584let Constraints = "$src = $dst" in
585 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
586 "sc\t$src, $addr", [], IIStore>;
587
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000588/// Jump and Branch Instructions
589def J : JumpFJ<0x02, "j">;
590def JR : JumpFR<0x00, 0x08, "jr">;
591def JAL : JumpLink<0x03, "jal">;
592def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000593def BEQ : CBranch<0x04, "beq", seteq>;
594def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000595
Eric Christopher3c999a22007-10-26 04:00:13 +0000596let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000597 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000598
599let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000600 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
601 def BLEZ : CBranchZero<0x07, "blez", setle>;
602 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000603}
604
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000605def BGEZAL : BranchLink<"bgezal">;
606def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000607
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000608let isReturn=1, isTerminator=1, hasDelaySlot=1,
609 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
610 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
611 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
612
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000613/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000614def MULT : Mul<0x18, "mult", IIImul>;
615def MULTu : Mul<0x19, "multu", IIImul>;
616def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
617def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000618
619let Defs = [HI] in
620 def MTHI : MoveToLOHI<0x11, "mthi">;
621let Defs = [LO] in
622 def MTLO : MoveToLOHI<0x13, "mtlo">;
623
624let Uses = [HI] in
625 def MFHI : MoveFromLOHI<0x10, "mfhi">;
626let Uses = [LO] in
627 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000628
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000629/// Sign Ext In Register Instructions.
630let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000631 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000632 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000633
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000634 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000635 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000636}
637
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000638/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000639def CLZ : CountLeading<0b100000, "clz",
640 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
641def CLO : CountLeading<0b100001, "clo",
642 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000643
644/// Byte Swap
645let Predicates = [HasSwap] in {
646 let shamt = 0x3, rs = 0 in
647 def WSBW : ByteSwap<0x20, "wsbw">;
648}
649
650/// Conditional Move
651def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
652def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
653
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000654// Conditional moves:
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +0000655// These instructions are expanded in
656// MipsISelLowering::EmitInstrWithCustomInserter if target does not have
657// conditional move instructions.
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000658// flag:int, data:int
659let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
660 class CondMovIntInt<bits<6> funct, string instr_asm> :
661 FR<0, funct, (outs CPURegs:$dst),
662 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
663 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
664
665def MOVZ_I : CondMovIntInt<0x0a, "movz">;
666def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000667
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000668/// No operation
669let addr=0 in
670 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
671
Eric Christopher3c999a22007-10-26 04:00:13 +0000672// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000673// instructions. The same not happens for stack address copies, so an
674// add op with mem ComplexPattern is used and the stack address copy
675// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000676def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000677
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000678// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000679def MADD : MArithR<0, "madd", MipsMAdd, 1>;
680def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000681def MSUB : MArithR<4, "msub", MipsMSub>;
682def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000683
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000684// MUL is a assembly macro in the current used ISAs. In recent ISA's
685// it is a real instruction.
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000686def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000687
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000688def RDHWR : ReadHardware;
689
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000690//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000691// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000692//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000693
694// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000695def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000696 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000697def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000698 (ORi ZERO, imm:$in)>;
699
700// Arbitrary immediates
701def : Pat<(i32 imm:$imm),
702 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
703
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000704// Carry patterns
705def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
706 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
707def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
708 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000709def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000710 (ADDiu CPURegs:$src, imm:$imm)>;
711
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000712// Call
713def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
714 (JAL tglobaladdr:$dst)>;
715def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
716 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000717//def : Pat<(MipsJmpLink CPURegs:$dst),
718// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000719
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000720// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000721def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000722def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000723def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000724 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000725def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
726 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000727
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000728def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000729def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
730 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000731
732def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
733def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
734 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
735
736// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000737def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000738 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000739def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000740 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000741
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000742// tlsgd
743def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
744 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
745
746// tprel hi/lo
747def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
748def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
749 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
750
Akira Hatanaka342837d2011-05-28 01:07:07 +0000751// wrapper_pic
752class WrapperPICPat<SDNode node>:
753 Pat<(MipsWrapperPIC node:$in),
754 (ADDiu GP, node:$in)>;
755
756def : WrapperPICPat<tglobaladdr>;
757def : WrapperPICPat<tconstpool>;
758def : WrapperPICPat<texternalsym>;
759def : WrapperPICPat<tblockaddress>;
760def : WrapperPICPat<tjumptable>;
761
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000762// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000763def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000764 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000765
Eric Christopher3c999a22007-10-26 04:00:13 +0000766// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000767def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
768def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
769def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000770
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000771// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000772def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
773
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000774// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000775def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000776 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000777def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
778 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000779
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000780def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000781 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000782def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000783 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
784def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
785 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
786def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
787 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000788
789def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000790 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000791def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000792 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000793
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000794def : Pat<(brcond CPURegs:$cond, bb:$dst),
795 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
796
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000797// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000798multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
799 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
800 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
801 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
802 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
803 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
804 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
805 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
806 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
807 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
808 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
809 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
810 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
811 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
812 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
813 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
814 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
815}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000816
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000817multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
818 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
819 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
820 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
821 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
822 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
823 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
824}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000825
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000826defm : MovzPats<CPURegs, MOVZ_I>;
827defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000828
829// setcc patterns
830def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
831 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
832def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
833 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
834
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000835def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
836 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
837def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
838 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
839
840def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
841 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
842def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
843 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
844
845def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
846 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
847def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
848 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
849
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000850def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
851 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000852def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
853 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000854
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000855//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000856// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000857//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000858
859include "MipsInstrFPU.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000860