blob: d0d820c15dca96ed3de8a886089de891c9ad7a79 [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
Akira Hatanaka21afc632011-06-21 00:40:49 +000042def SDT_MipsDynAlloc : SDTypeProfile<1, 1, [SDTCisVT<0, i32>,
43 SDTCisVT<1, iPTR>]>;
44
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000045// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000046def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000047 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000048 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000049
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000050// Hi and Lo nodes are used to handle global addresses. Used on
51// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000052// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000053def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
54def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
55def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000056
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000057// TlsGd node is used to handle General Dynamic TLS
58def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
59
60// TprelHi and TprelLo nodes are used to handle Local Exec TLS
61def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
62def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
63
64// Thread pointer
65def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
66
Eric Christopher3c999a22007-10-26 04:00:13 +000067// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000068def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000069 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000070
71// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000072def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000073 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000074def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000075 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000076
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000077// MAdd*/MSub* nodes
78def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
79 [SDNPOptInGlue, SDNPOutGlue]>;
80def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
81 [SDNPOptInGlue, SDNPOutGlue]>;
82def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
83 [SDNPOptInGlue, SDNPOutGlue]>;
84def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
85 [SDNPOptInGlue, SDNPOutGlue]>;
86
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000087// DivRem(u) nodes
88def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
89 [SDNPOutGlue]>;
90def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
91 [SDNPOutGlue]>;
92
Akira Hatanaka6cd4b4e2011-06-07 18:00:14 +000093// Target constant nodes that are not part of any isel patterns and remain
94// unchanged can cause instructions with illegal operands to be emitted.
95// Wrapper node patterns give the instruction selector a chance to replace
96// target constant nodes that would otherwise remain unchanged with ADDiu
97// nodes. Without these wrapper node patterns, the following conditional move
98// instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
99// compiled:
100// movn %got(d)($gp), %got(c)($gp), $4
101// This instruction is illegal since movn can take only register operands.
102
Akira Hatanaka342837d2011-05-28 01:07:07 +0000103def MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", SDTIntUnaryOp>;
104
Akira Hatanaka21afc632011-06-21 00:40:49 +0000105// Pointer to dynamically allocated stack area.
106def MipsDynAlloc : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
107 [SDNPHasChain, SDNPInGlue]>;
108
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000109//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000110// Mips Instruction Predicate Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000111//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000112def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
113def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000114def HasSwap : Predicate<"Subtarget.hasSwap()">;
115def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +0000116def IsMips32 : Predicate<"Subtarget.isMips32()">;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000117def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000118
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000119//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000120// Mips Operand, Complex Patterns and Transformations Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000121//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000122
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000123// Instruction operand types
124def brtarget : Operand<OtherVT>;
125def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000126def simm16 : Operand<i32>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000127def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000128
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000129// Unsigned Operand
130def uimm16 : Operand<i32> {
131 let PrintMethod = "printUnsignedImm";
132}
133
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000134// Address operand
135def mem : Operand<i32> {
136 let PrintMethod = "printMemOperand";
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000137 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000138}
139
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000140// Transformation Function - get the lower 16 bits.
141def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000142 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000143}]>;
144
145// Transformation Function - get the higher 16 bits.
146def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000147 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000148}]>;
149
150// Node immediate fits as 16-bit sign extended on target immediate.
151// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000152def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000153
154// Node immediate fits as 16-bit zero extended on target immediate.
155// The LO16 param means that only the lower 16 bits of the node
156// immediate are caught.
157// e.g. addiu, sltiu
158def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000159 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000160 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000161 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000162 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000163}], LO16>;
164
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000165// shamt field must fit in 5 bits.
166def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000167 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000168}]>;
169
Eric Christopher3c999a22007-10-26 04:00:13 +0000170// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000171// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000172def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000173
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000174//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000175// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000176//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000177
178// Arithmetic 3 register operands
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000179class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000180 InstrItinClass itin, bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000181 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
182 !strconcat(instr_asm, "\t$dst, $b, $c"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000183 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
184 let isCommutable = isComm;
185}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000186
Akira Hatanakaedacba82011-05-25 17:32:06 +0000187class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
188 bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000189 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000190 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
191 let isCommutable = isComm;
192}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000193
194// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000195class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
196 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000197 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
198 !strconcat(instr_asm, "\t$dst, $b, $c"),
199 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000200
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000201class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
202 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000203 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
204 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000205
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000206// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000207let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000208class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000209 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000210 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000211 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
212 let isCommutable = isComm;
213}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000214
215// Logical
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000216let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000217class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000218 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
219 !strconcat(instr_asm, "\t$dst, $b, $c"),
220 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000221
222class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000223 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
224 !strconcat(instr_asm, "\t$dst, $b, $c"),
225 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000226
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000227let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000228class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000229 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
230 !strconcat(instr_asm, "\t$dst, $b, $c"),
231 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000232
233// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000234class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000235 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000236 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
237 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000238 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
239 let rs = _rs;
240}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000241
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000242class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000243 SDNode OpNode>:
244 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000245 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000246 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
247 let shamt = _shamt;
248}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000249
250// Load Upper Imediate
251class LoadUpper<bits<6> op, string instr_asm>:
252 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000253 (outs CPURegs:$dst),
254 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000255 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000256 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000257
Eric Christopher3c999a22007-10-26 04:00:13 +0000258// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000259let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000260class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000261 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
262 !strconcat(instr_asm, "\t$dst, $addr"),
263 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000264
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000265class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000266 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
267 !strconcat(instr_asm, "\t$dst, $addr"),
268 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000269
270// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000271let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000272class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000273 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
274 !strconcat(instr_asm, "\t$a, $b, $offset"),
275 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
276 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000277
278class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000279 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
280 !strconcat(instr_asm, "\t$src, $offset"),
281 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
282 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000283}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000284
Eric Christopher3c999a22007-10-26 04:00:13 +0000285// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000286class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
287 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000288 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
289 !strconcat(instr_asm, "\t$dst, $b, $c"),
290 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
291 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000292
293class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
294 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000295 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
296 !strconcat(instr_asm, "\t$dst, $b, $c"),
297 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
298 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000299
300// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000301let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000302class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000303 FJ<op, (outs), (ins brtarget:$target),
304 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000305
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000306let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000307class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000308 FR<op, func, (outs), (ins CPURegs:$target),
309 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000310
311// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000312let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000313 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000314 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
315 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000316 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000317 FJ<op, (outs), (ins calltarget:$target, variable_ops),
318 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
319 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000320
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000321 let rd=31 in
322 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000323 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
324 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000325
326 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000327 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
328 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000329}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000330
Eric Christopher3c999a22007-10-26 04:00:13 +0000331// Mul, Div
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000332let Defs = [HI, LO] in {
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000333 let isCommutable = 1 in
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000334 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
335 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
336 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
337
338 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
339 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
340 !strconcat(instr_asm, "\t$$zero, $a, $b"),
341 [(op CPURegs:$a, CPURegs:$b)], itin>;
342}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000343
Eric Christopher3c999a22007-10-26 04:00:13 +0000344// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000345class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000346 FR<0x00, func, (outs CPURegs:$dst), (ins),
347 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000348
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000349class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000350 FR<0x00, func, (outs), (ins CPURegs:$src),
351 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000352
Eric Christopher3c999a22007-10-26 04:00:13 +0000353class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000354 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
355 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000356
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000357// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000358class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000359 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000360 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
361 Requires<[HasBitCount]> {
362 let shamt = 0;
363 let rt = rd;
364}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000365
366// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000367class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000368 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
369 !strconcat(instr_asm, "\t$dst, $src"),
370 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000371
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000372// Byte Swap
373class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000374 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
375 !strconcat(instr_asm, "\t$dst, $src"),
376 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000377
378// Conditional Move
379class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000380 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
381 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000382 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000383
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000384// Read Hardware
385class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
386 "rdhwr\t$dst, $src", [], IIAlu> {
387 let rs = 0;
388 let shamt = 0;
389}
390
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000391//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000392// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000393//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000394
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000395// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000396let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000397def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000398 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000399 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000400def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000401 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000402 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000403}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000404
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000405// Some assembly macros need to avoid pseudoinstructions and assembler
406// automatic reodering, we should reorder ourselves.
407def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
408def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
409def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
410def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
411
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000412// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000413// when using the AT register.
414def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
415def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
416
Eric Christopher3c999a22007-10-26 04:00:13 +0000417// When handling PIC code the assembler needs .cpload and .cprestore
418// directives. If the real instructions corresponding these directives
419// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000420// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000421def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanakace98deb2011-05-24 21:22:21 +0000422def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000423
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000424let usesCustomInserter = 1 in {
425 def ATOMIC_LOAD_ADD_I8 : MipsPseudo<
426 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
427 "atomic_load_add_8\t$dst, $ptr, $incr",
428 [(set CPURegs:$dst, (atomic_load_add_8 CPURegs:$ptr, CPURegs:$incr))]>;
429 def ATOMIC_LOAD_ADD_I16 : MipsPseudo<
430 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
431 "atomic_load_add_16\t$dst, $ptr, $incr",
432 [(set CPURegs:$dst, (atomic_load_add_16 CPURegs:$ptr, CPURegs:$incr))]>;
433 def ATOMIC_LOAD_ADD_I32 : MipsPseudo<
434 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
435 "atomic_load_add_32\t$dst, $ptr, $incr",
436 [(set CPURegs:$dst, (atomic_load_add_32 CPURegs:$ptr, CPURegs:$incr))]>;
437
438 def ATOMIC_LOAD_SUB_I8 : MipsPseudo<
439 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
440 "atomic_load_sub_8\t$dst, $ptr, $incr",
441 [(set CPURegs:$dst, (atomic_load_sub_8 CPURegs:$ptr, CPURegs:$incr))]>;
442 def ATOMIC_LOAD_SUB_I16 : MipsPseudo<
443 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
444 "atomic_load_sub_16\t$dst, $ptr, $incr",
445 [(set CPURegs:$dst, (atomic_load_sub_16 CPURegs:$ptr, CPURegs:$incr))]>;
446 def ATOMIC_LOAD_SUB_I32 : MipsPseudo<
447 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
448 "atomic_load_sub_32\t$dst, $ptr, $incr",
449 [(set CPURegs:$dst, (atomic_load_sub_32 CPURegs:$ptr, CPURegs:$incr))]>;
450
451 def ATOMIC_LOAD_AND_I8 : MipsPseudo<
452 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
453 "atomic_load_and_8\t$dst, $ptr, $incr",
454 [(set CPURegs:$dst, (atomic_load_and_8 CPURegs:$ptr, CPURegs:$incr))]>;
455 def ATOMIC_LOAD_AND_I16 : MipsPseudo<
456 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
457 "atomic_load_and_16\t$dst, $ptr, $incr",
458 [(set CPURegs:$dst, (atomic_load_and_16 CPURegs:$ptr, CPURegs:$incr))]>;
459 def ATOMIC_LOAD_AND_I32 : MipsPseudo<
460 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
461 "atomic_load_and_32\t$dst, $ptr, $incr",
462 [(set CPURegs:$dst, (atomic_load_and_32 CPURegs:$ptr, CPURegs:$incr))]>;
463
464 def ATOMIC_LOAD_OR_I8 : MipsPseudo<
465 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
466 "atomic_load_or_8\t$dst, $ptr, $incr",
467 [(set CPURegs:$dst, (atomic_load_or_8 CPURegs:$ptr, CPURegs:$incr))]>;
468 def ATOMIC_LOAD_OR_I16 : MipsPseudo<
469 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
470 "atomic_load_or_16\t$dst, $ptr, $incr",
471 [(set CPURegs:$dst, (atomic_load_or_16 CPURegs:$ptr, CPURegs:$incr))]>;
472 def ATOMIC_LOAD_OR_I32 : MipsPseudo<
473 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
474 "atomic_load_or_32\t$dst, $ptr, $incr",
475 [(set CPURegs:$dst, (atomic_load_or_32 CPURegs:$ptr, CPURegs:$incr))]>;
476
477 def ATOMIC_LOAD_XOR_I8 : MipsPseudo<
478 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
479 "atomic_load_xor_8\t$dst, $ptr, $incr",
480 [(set CPURegs:$dst, (atomic_load_xor_8 CPURegs:$ptr, CPURegs:$incr))]>;
481 def ATOMIC_LOAD_XOR_I16 : MipsPseudo<
482 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
483 "atomic_load_xor_16\t$dst, $ptr, $incr",
484 [(set CPURegs:$dst, (atomic_load_xor_16 CPURegs:$ptr, CPURegs:$incr))]>;
485 def ATOMIC_LOAD_XOR_I32 : MipsPseudo<
486 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
487 "atomic_load_xor_32\t$dst, $ptr, $incr",
488 [(set CPURegs:$dst, (atomic_load_xor_32 CPURegs:$ptr, CPURegs:$incr))]>;
489
490 def ATOMIC_LOAD_NAND_I8 : MipsPseudo<
491 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
492 "atomic_load_nand_8\t$dst, $ptr, $incr",
493 [(set CPURegs:$dst, (atomic_load_nand_8 CPURegs:$ptr, CPURegs:$incr))]>;
494 def ATOMIC_LOAD_NAND_I16 : MipsPseudo<
495 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
496 "atomic_load_nand_16\t$dst, $ptr, $incr",
497 [(set CPURegs:$dst, (atomic_load_nand_16 CPURegs:$ptr, CPURegs:$incr))]>;
498 def ATOMIC_LOAD_NAND_I32 : MipsPseudo<
499 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
500 "atomic_load_nand_32\t$dst, $ptr, $incr",
501 [(set CPURegs:$dst, (atomic_load_nand_32 CPURegs:$ptr, CPURegs:$incr))]>;
502
503 def ATOMIC_SWAP_I8 : MipsPseudo<
504 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
505 "atomic_swap_8\t$dst, $ptr, $val",
506 [(set CPURegs:$dst, (atomic_swap_8 CPURegs:$ptr, CPURegs:$val))]>;
507 def ATOMIC_SWAP_I16 : MipsPseudo<
508 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
509 "atomic_swap_16\t$dst, $ptr, $val",
510 [(set CPURegs:$dst, (atomic_swap_16 CPURegs:$ptr, CPURegs:$val))]>;
511 def ATOMIC_SWAP_I32 : MipsPseudo<
512 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
513 "atomic_swap_32\t$dst, $ptr, $val",
514 [(set CPURegs:$dst, (atomic_swap_32 CPURegs:$ptr, CPURegs:$val))]>;
515
516 def ATOMIC_CMP_SWAP_I8 : MipsPseudo<
517 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
518 "atomic_cmp_swap_8\t$dst, $ptr, $oldval, $newval",
519 [(set CPURegs:$dst,
520 (atomic_cmp_swap_8 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
521 def ATOMIC_CMP_SWAP_I16 : MipsPseudo<
522 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
523 "atomic_cmp_swap_16\t$dst, $ptr, $oldval, $newval",
524 [(set CPURegs:$dst,
525 (atomic_cmp_swap_16 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
526 def ATOMIC_CMP_SWAP_I32 : MipsPseudo<
527 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
528 "atomic_cmp_swap_32\t$dst, $ptr, $oldval, $newval",
529 [(set CPURegs:$dst,
530 (atomic_cmp_swap_32 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
531}
532
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000533//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000534// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000535//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000536
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000537//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000538// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000539//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000540
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000541/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000542def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
543def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000544def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000545def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000546def ANDi : LogicI<0x0c, "andi", and>;
547def ORi : LogicI<0x0d, "ori", or>;
548def XORi : LogicI<0x0e, "xori", xor>;
549def LUi : LoadUpper<0x0f, "lui">;
550
551/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000552def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000553def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000554def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000555def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000556def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
557def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000558def AND : LogicR<0x24, "and", and>;
559def OR : LogicR<0x25, "or", or>;
560def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000561def NOR : LogicNOR<0x00, 0x27, "nor">;
562
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000563/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000564def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
565def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
566def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
567def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
568def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
569def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
570
571// Rotate Instructions
572let Predicates = [IsMips32r2] in {
573 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
574 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
575}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000576
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000577/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000578def LB : LoadM<0x20, "lb", sextloadi8>;
579def LBu : LoadM<0x24, "lbu", zextloadi8>;
580def LH : LoadM<0x21, "lh", sextloadi16>;
581def LHu : LoadM<0x25, "lhu", zextloadi16>;
582def LW : LoadM<0x23, "lw", load>;
583def SB : StoreM<0x28, "sb", truncstorei8>;
584def SH : StoreM<0x29, "sh", truncstorei16>;
585def SW : StoreM<0x2b, "sw", store>;
586
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000587/// Load-linked, Store-conditional
588let hasDelaySlot = 1 in
589 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
590 "ll\t$dst, $addr", [], IILoad>;
591let Constraints = "$src = $dst" in
592 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
593 "sc\t$src, $addr", [], IIStore>;
594
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000595/// Jump and Branch Instructions
596def J : JumpFJ<0x02, "j">;
597def JR : JumpFR<0x00, 0x08, "jr">;
598def JAL : JumpLink<0x03, "jal">;
599def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000600def BEQ : CBranch<0x04, "beq", seteq>;
601def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000602
Eric Christopher3c999a22007-10-26 04:00:13 +0000603let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000604 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000605
606let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000607 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
608 def BLEZ : CBranchZero<0x07, "blez", setle>;
609 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000610}
611
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000612def BGEZAL : BranchLink<"bgezal">;
613def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000614
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000615let isReturn=1, isTerminator=1, hasDelaySlot=1,
616 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
617 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
618 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
619
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000620/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000621def MULT : Mul<0x18, "mult", IIImul>;
622def MULTu : Mul<0x19, "multu", IIImul>;
623def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
624def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000625
626let Defs = [HI] in
627 def MTHI : MoveToLOHI<0x11, "mthi">;
628let Defs = [LO] in
629 def MTLO : MoveToLOHI<0x13, "mtlo">;
630
631let Uses = [HI] in
632 def MFHI : MoveFromLOHI<0x10, "mfhi">;
633let Uses = [LO] in
634 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000635
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000636/// Sign Ext In Register Instructions.
637let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000638 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000639 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000640
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000641 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000642 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000643}
644
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000645/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000646def CLZ : CountLeading<0b100000, "clz",
647 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
648def CLO : CountLeading<0b100001, "clo",
649 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000650
651/// Byte Swap
652let Predicates = [HasSwap] in {
653 let shamt = 0x3, rs = 0 in
654 def WSBW : ByteSwap<0x20, "wsbw">;
655}
656
657/// Conditional Move
658def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
659def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
660
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000661// Conditional moves:
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +0000662// These instructions are expanded in
663// MipsISelLowering::EmitInstrWithCustomInserter if target does not have
664// conditional move instructions.
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000665// flag:int, data:int
666let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
667 class CondMovIntInt<bits<6> funct, string instr_asm> :
668 FR<0, funct, (outs CPURegs:$dst),
669 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
670 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
671
672def MOVZ_I : CondMovIntInt<0x0a, "movz">;
673def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000674
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000675/// No operation
676let addr=0 in
677 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
678
Eric Christopher3c999a22007-10-26 04:00:13 +0000679// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000680// instructions. The same not happens for stack address copies, so an
681// add op with mem ComplexPattern is used and the stack address copy
682// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000683def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000684
Akira Hatanaka21afc632011-06-21 00:40:49 +0000685// DynAlloc node points to dynamically allocated stack space.
686// $sp is added to the list of implicitly used registers to prevent dead code
687// elimination from removing instructions that modify $sp.
688let Uses = [SP] in
689def DynAlloc : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
690
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000691// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000692def MADD : MArithR<0, "madd", MipsMAdd, 1>;
693def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000694def MSUB : MArithR<4, "msub", MipsMSub>;
695def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000696
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000697// MUL is a assembly macro in the current used ISAs. In recent ISA's
698// it is a real instruction.
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000699def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000700
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000701def RDHWR : ReadHardware;
702
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000703//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000704// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000705//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000706
707// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000708def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000709 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000710def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000711 (ORi ZERO, imm:$in)>;
712
713// Arbitrary immediates
714def : Pat<(i32 imm:$imm),
715 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
716
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000717// Carry patterns
718def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
719 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
720def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
721 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000722def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000723 (ADDiu CPURegs:$src, imm:$imm)>;
724
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000725// Call
726def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
727 (JAL tglobaladdr:$dst)>;
728def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
729 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000730//def : Pat<(MipsJmpLink CPURegs:$dst),
731// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000732
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000733// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000734def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000735def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000736def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000737 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000738def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
739 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000740
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000741def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000742def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
743 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000744
745def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
746def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
747 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
748
749// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000750def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000751 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000752def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000753 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000754
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000755// tlsgd
756def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
757 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
758
759// tprel hi/lo
760def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
761def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
762 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
763
Akira Hatanaka342837d2011-05-28 01:07:07 +0000764// wrapper_pic
765class WrapperPICPat<SDNode node>:
766 Pat<(MipsWrapperPIC node:$in),
767 (ADDiu GP, node:$in)>;
768
769def : WrapperPICPat<tglobaladdr>;
770def : WrapperPICPat<tconstpool>;
771def : WrapperPICPat<texternalsym>;
772def : WrapperPICPat<tblockaddress>;
773def : WrapperPICPat<tjumptable>;
774
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000775// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000776def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000777 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000778
Eric Christopher3c999a22007-10-26 04:00:13 +0000779// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000780def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
781def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
782def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000783
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000784// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000785def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
786
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000787// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000788def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000789 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000790def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
791 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000792
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000793def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000794 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000795def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000796 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
797def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
798 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
799def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
800 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000801
802def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000803 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000804def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000805 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000806
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000807def : Pat<(brcond CPURegs:$cond, bb:$dst),
808 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
809
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000810// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000811multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
812 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
813 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
814 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
815 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
816 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
817 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
818 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
819 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
820 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
821 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
822 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
823 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
824 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
825 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
826 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
827 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
828}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000829
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000830multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
831 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
832 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
833 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
834 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
835 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
836 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
837}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000838
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000839defm : MovzPats<CPURegs, MOVZ_I>;
840defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000841
842// setcc patterns
843def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
844 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
845def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
846 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
847
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000848def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
849 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
850def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
851 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
852
853def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
854 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
855def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
856 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
857
858def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
859 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
860def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
861 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
862
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000863def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
864 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000865def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
866 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000867
Akira Hatanaka21afc632011-06-21 00:40:49 +0000868// select MipsDynAlloc
869def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
870
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000871//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000872// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000873//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000874
875include "MipsInstrFPU.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000876