blob: ef26bb54791b71604c48c4bc61ee605f3c81cdbb [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
Akira Hatanaka03236be2011-07-07 20:54:20 +0000140def mem_ea : Operand<i32> {
141 let PrintMethod = "printMemOperandEA";
142 let MIOperandInfo = (ops CPURegs, simm16);
143}
144
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000145// Transformation Function - get the lower 16 bits.
146def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000147 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000148}]>;
149
150// Transformation Function - get the higher 16 bits.
151def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000152 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000153}]>;
154
155// Node immediate fits as 16-bit sign extended on target immediate.
156// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000157def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000158
159// Node immediate fits as 16-bit zero extended on target immediate.
160// The LO16 param means that only the lower 16 bits of the node
161// immediate are caught.
162// e.g. addiu, sltiu
163def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000164 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000165 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000166 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000167 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000168}], LO16>;
169
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000170// shamt field must fit in 5 bits.
171def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000172 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000173}]>;
174
Eric Christopher3c999a22007-10-26 04:00:13 +0000175// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000176// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000177def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000178
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000179//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000180// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000181//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000182
183// Arithmetic 3 register operands
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000184class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000185 InstrItinClass itin, bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000186 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
187 !strconcat(instr_asm, "\t$dst, $b, $c"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000188 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
189 let isCommutable = isComm;
190}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000191
Akira Hatanakaedacba82011-05-25 17:32:06 +0000192class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
193 bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000194 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000195 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
196 let isCommutable = isComm;
197}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000198
199// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000200class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
201 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000202 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
203 !strconcat(instr_asm, "\t$dst, $b, $c"),
204 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000205
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000206class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
207 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000208 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
209 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000210
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000211// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000212let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000213class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000214 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000215 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000216 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
217 let isCommutable = isComm;
218}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000219
220// Logical
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000221let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000222class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000223 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
224 !strconcat(instr_asm, "\t$dst, $b, $c"),
225 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000226
227class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000228 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
229 !strconcat(instr_asm, "\t$dst, $b, $c"),
230 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000231
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000232let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000233class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000234 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
235 !strconcat(instr_asm, "\t$dst, $b, $c"),
236 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000237
238// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000239class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000240 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000241 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
242 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000243 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
244 let rs = _rs;
245}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000246
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000247class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000248 SDNode OpNode>:
249 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000250 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000251 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
252 let shamt = _shamt;
253}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000254
255// Load Upper Imediate
256class LoadUpper<bits<6> op, string instr_asm>:
257 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000258 (outs CPURegs:$dst),
259 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000260 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000261 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000262
Eric Christopher3c999a22007-10-26 04:00:13 +0000263// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000264let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000265class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000266 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
267 !strconcat(instr_asm, "\t$dst, $addr"),
268 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000269
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000270class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000271 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
272 !strconcat(instr_asm, "\t$dst, $addr"),
273 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000274
275// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000276let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000277class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000278 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
279 !strconcat(instr_asm, "\t$a, $b, $offset"),
280 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
281 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000282
283class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000284 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
285 !strconcat(instr_asm, "\t$src, $offset"),
286 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
287 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000288}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000289
Eric Christopher3c999a22007-10-26 04:00:13 +0000290// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000291class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
292 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000293 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
294 !strconcat(instr_asm, "\t$dst, $b, $c"),
295 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
296 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000297
298class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
299 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000300 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
301 !strconcat(instr_asm, "\t$dst, $b, $c"),
302 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
303 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000304
305// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000306let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000307class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000308 FJ<op, (outs), (ins brtarget:$target),
309 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000310
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000311let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000312class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000313 FR<op, func, (outs), (ins CPURegs:$target),
314 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000315
316// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000317let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000318 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000319 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
320 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000321 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000322 FJ<op, (outs), (ins calltarget:$target, variable_ops),
323 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
324 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000325
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000326 let rd=31 in
327 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000328 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
329 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000330
331 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000332 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
333 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000334}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000335
Eric Christopher3c999a22007-10-26 04:00:13 +0000336// Mul, Div
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000337let Defs = [HI, LO] in {
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000338 let isCommutable = 1 in
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000339 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
340 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
341 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
342
343 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
344 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
345 !strconcat(instr_asm, "\t$$zero, $a, $b"),
346 [(op CPURegs:$a, CPURegs:$b)], itin>;
347}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000348
Eric Christopher3c999a22007-10-26 04:00:13 +0000349// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000350class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000351 FR<0x00, func, (outs CPURegs:$dst), (ins),
352 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000353
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000354class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000355 FR<0x00, func, (outs), (ins CPURegs:$src),
356 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000357
Eric Christopher3c999a22007-10-26 04:00:13 +0000358class EffectiveAddress<string instr_asm> :
Akira Hatanaka03236be2011-07-07 20:54:20 +0000359 FI<0x09, (outs CPURegs:$dst), (ins mem_ea:$addr),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000360 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000361
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000362// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000363class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000364 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000365 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
366 Requires<[HasBitCount]> {
367 let shamt = 0;
368 let rt = rd;
369}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000370
371// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000372class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000373 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
374 !strconcat(instr_asm, "\t$dst, $src"),
375 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000376
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000377// Byte Swap
378class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000379 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
380 !strconcat(instr_asm, "\t$dst, $src"),
381 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000382
383// Conditional Move
384class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000385 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
386 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000387 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000388
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000389// Read Hardware
390class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
391 "rdhwr\t$dst, $src", [], IIAlu> {
392 let rs = 0;
393 let shamt = 0;
394}
395
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000396//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000397// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000398//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000399
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000400// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000401let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000402def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000403 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000404 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000405def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000406 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000407 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000408}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000409
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000410// Some assembly macros need to avoid pseudoinstructions and assembler
411// automatic reodering, we should reorder ourselves.
412def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
413def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
414def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
415def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
416
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000417// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000418// when using the AT register.
419def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
420def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
421
Eric Christopher3c999a22007-10-26 04:00:13 +0000422// When handling PIC code the assembler needs .cpload and .cprestore
423// directives. If the real instructions corresponding these directives
424// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000425// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000426def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanakace98deb2011-05-24 21:22:21 +0000427def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000428
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000429let usesCustomInserter = 1 in {
430 def ATOMIC_LOAD_ADD_I8 : MipsPseudo<
431 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
432 "atomic_load_add_8\t$dst, $ptr, $incr",
433 [(set CPURegs:$dst, (atomic_load_add_8 CPURegs:$ptr, CPURegs:$incr))]>;
434 def ATOMIC_LOAD_ADD_I16 : MipsPseudo<
435 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
436 "atomic_load_add_16\t$dst, $ptr, $incr",
437 [(set CPURegs:$dst, (atomic_load_add_16 CPURegs:$ptr, CPURegs:$incr))]>;
438 def ATOMIC_LOAD_ADD_I32 : MipsPseudo<
439 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
440 "atomic_load_add_32\t$dst, $ptr, $incr",
441 [(set CPURegs:$dst, (atomic_load_add_32 CPURegs:$ptr, CPURegs:$incr))]>;
442
443 def ATOMIC_LOAD_SUB_I8 : MipsPseudo<
444 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
445 "atomic_load_sub_8\t$dst, $ptr, $incr",
446 [(set CPURegs:$dst, (atomic_load_sub_8 CPURegs:$ptr, CPURegs:$incr))]>;
447 def ATOMIC_LOAD_SUB_I16 : MipsPseudo<
448 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
449 "atomic_load_sub_16\t$dst, $ptr, $incr",
450 [(set CPURegs:$dst, (atomic_load_sub_16 CPURegs:$ptr, CPURegs:$incr))]>;
451 def ATOMIC_LOAD_SUB_I32 : MipsPseudo<
452 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
453 "atomic_load_sub_32\t$dst, $ptr, $incr",
454 [(set CPURegs:$dst, (atomic_load_sub_32 CPURegs:$ptr, CPURegs:$incr))]>;
455
456 def ATOMIC_LOAD_AND_I8 : MipsPseudo<
457 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
458 "atomic_load_and_8\t$dst, $ptr, $incr",
459 [(set CPURegs:$dst, (atomic_load_and_8 CPURegs:$ptr, CPURegs:$incr))]>;
460 def ATOMIC_LOAD_AND_I16 : MipsPseudo<
461 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
462 "atomic_load_and_16\t$dst, $ptr, $incr",
463 [(set CPURegs:$dst, (atomic_load_and_16 CPURegs:$ptr, CPURegs:$incr))]>;
464 def ATOMIC_LOAD_AND_I32 : MipsPseudo<
465 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
466 "atomic_load_and_32\t$dst, $ptr, $incr",
467 [(set CPURegs:$dst, (atomic_load_and_32 CPURegs:$ptr, CPURegs:$incr))]>;
468
469 def ATOMIC_LOAD_OR_I8 : MipsPseudo<
470 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
471 "atomic_load_or_8\t$dst, $ptr, $incr",
472 [(set CPURegs:$dst, (atomic_load_or_8 CPURegs:$ptr, CPURegs:$incr))]>;
473 def ATOMIC_LOAD_OR_I16 : MipsPseudo<
474 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
475 "atomic_load_or_16\t$dst, $ptr, $incr",
476 [(set CPURegs:$dst, (atomic_load_or_16 CPURegs:$ptr, CPURegs:$incr))]>;
477 def ATOMIC_LOAD_OR_I32 : MipsPseudo<
478 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
479 "atomic_load_or_32\t$dst, $ptr, $incr",
480 [(set CPURegs:$dst, (atomic_load_or_32 CPURegs:$ptr, CPURegs:$incr))]>;
481
482 def ATOMIC_LOAD_XOR_I8 : MipsPseudo<
483 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
484 "atomic_load_xor_8\t$dst, $ptr, $incr",
485 [(set CPURegs:$dst, (atomic_load_xor_8 CPURegs:$ptr, CPURegs:$incr))]>;
486 def ATOMIC_LOAD_XOR_I16 : MipsPseudo<
487 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
488 "atomic_load_xor_16\t$dst, $ptr, $incr",
489 [(set CPURegs:$dst, (atomic_load_xor_16 CPURegs:$ptr, CPURegs:$incr))]>;
490 def ATOMIC_LOAD_XOR_I32 : MipsPseudo<
491 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
492 "atomic_load_xor_32\t$dst, $ptr, $incr",
493 [(set CPURegs:$dst, (atomic_load_xor_32 CPURegs:$ptr, CPURegs:$incr))]>;
494
495 def ATOMIC_LOAD_NAND_I8 : MipsPseudo<
496 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
497 "atomic_load_nand_8\t$dst, $ptr, $incr",
498 [(set CPURegs:$dst, (atomic_load_nand_8 CPURegs:$ptr, CPURegs:$incr))]>;
499 def ATOMIC_LOAD_NAND_I16 : MipsPseudo<
500 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
501 "atomic_load_nand_16\t$dst, $ptr, $incr",
502 [(set CPURegs:$dst, (atomic_load_nand_16 CPURegs:$ptr, CPURegs:$incr))]>;
503 def ATOMIC_LOAD_NAND_I32 : MipsPseudo<
504 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
505 "atomic_load_nand_32\t$dst, $ptr, $incr",
506 [(set CPURegs:$dst, (atomic_load_nand_32 CPURegs:$ptr, CPURegs:$incr))]>;
507
508 def ATOMIC_SWAP_I8 : MipsPseudo<
509 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
510 "atomic_swap_8\t$dst, $ptr, $val",
511 [(set CPURegs:$dst, (atomic_swap_8 CPURegs:$ptr, CPURegs:$val))]>;
512 def ATOMIC_SWAP_I16 : MipsPseudo<
513 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
514 "atomic_swap_16\t$dst, $ptr, $val",
515 [(set CPURegs:$dst, (atomic_swap_16 CPURegs:$ptr, CPURegs:$val))]>;
516 def ATOMIC_SWAP_I32 : MipsPseudo<
517 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
518 "atomic_swap_32\t$dst, $ptr, $val",
519 [(set CPURegs:$dst, (atomic_swap_32 CPURegs:$ptr, CPURegs:$val))]>;
520
521 def ATOMIC_CMP_SWAP_I8 : MipsPseudo<
522 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
523 "atomic_cmp_swap_8\t$dst, $ptr, $oldval, $newval",
524 [(set CPURegs:$dst,
525 (atomic_cmp_swap_8 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
526 def ATOMIC_CMP_SWAP_I16 : MipsPseudo<
527 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
528 "atomic_cmp_swap_16\t$dst, $ptr, $oldval, $newval",
529 [(set CPURegs:$dst,
530 (atomic_cmp_swap_16 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
531 def ATOMIC_CMP_SWAP_I32 : MipsPseudo<
532 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
533 "atomic_cmp_swap_32\t$dst, $ptr, $oldval, $newval",
534 [(set CPURegs:$dst,
535 (atomic_cmp_swap_32 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
536}
537
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000538//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000539// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000540//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000541
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000542//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000543// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000544//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000545
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000546/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000547def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
548def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000549def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000550def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000551def ANDi : LogicI<0x0c, "andi", and>;
552def ORi : LogicI<0x0d, "ori", or>;
553def XORi : LogicI<0x0e, "xori", xor>;
554def LUi : LoadUpper<0x0f, "lui">;
555
556/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000557def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000558def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000559def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000560def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000561def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
562def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000563def AND : LogicR<0x24, "and", and>;
564def OR : LogicR<0x25, "or", or>;
565def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000566def NOR : LogicNOR<0x00, 0x27, "nor">;
567
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000568/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000569def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
570def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
571def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
572def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
573def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
574def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
575
576// Rotate Instructions
577let Predicates = [IsMips32r2] in {
578 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
579 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
580}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000581
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000582/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000583def LB : LoadM<0x20, "lb", sextloadi8>;
584def LBu : LoadM<0x24, "lbu", zextloadi8>;
585def LH : LoadM<0x21, "lh", sextloadi16>;
586def LHu : LoadM<0x25, "lhu", zextloadi16>;
587def LW : LoadM<0x23, "lw", load>;
588def SB : StoreM<0x28, "sb", truncstorei8>;
589def SH : StoreM<0x29, "sh", truncstorei16>;
590def SW : StoreM<0x2b, "sw", store>;
591
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000592/// Load-linked, Store-conditional
593let hasDelaySlot = 1 in
594 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
595 "ll\t$dst, $addr", [], IILoad>;
596let Constraints = "$src = $dst" in
597 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
598 "sc\t$src, $addr", [], IIStore>;
599
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000600/// Jump and Branch Instructions
601def J : JumpFJ<0x02, "j">;
602def JR : JumpFR<0x00, 0x08, "jr">;
603def JAL : JumpLink<0x03, "jal">;
604def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000605def BEQ : CBranch<0x04, "beq", seteq>;
606def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000607
Eric Christopher3c999a22007-10-26 04:00:13 +0000608let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000609 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000610
611let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000612 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
613 def BLEZ : CBranchZero<0x07, "blez", setle>;
614 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000615}
616
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000617def BGEZAL : BranchLink<"bgezal">;
618def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000619
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000620let isReturn=1, isTerminator=1, hasDelaySlot=1,
621 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
622 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
623 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
624
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000625/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000626def MULT : Mul<0x18, "mult", IIImul>;
627def MULTu : Mul<0x19, "multu", IIImul>;
628def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
629def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000630
631let Defs = [HI] in
632 def MTHI : MoveToLOHI<0x11, "mthi">;
633let Defs = [LO] in
634 def MTLO : MoveToLOHI<0x13, "mtlo">;
635
636let Uses = [HI] in
637 def MFHI : MoveFromLOHI<0x10, "mfhi">;
638let Uses = [LO] in
639 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000640
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000641/// Sign Ext In Register Instructions.
642let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000643 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000644 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000645
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000646 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000647 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000648}
649
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000650/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000651def CLZ : CountLeading<0b100000, "clz",
652 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
653def CLO : CountLeading<0b100001, "clo",
654 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000655
656/// Byte Swap
657let Predicates = [HasSwap] in {
658 let shamt = 0x3, rs = 0 in
659 def WSBW : ByteSwap<0x20, "wsbw">;
660}
661
662/// Conditional Move
663def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
664def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
665
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000666// Conditional moves:
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +0000667// These instructions are expanded in
668// MipsISelLowering::EmitInstrWithCustomInserter if target does not have
669// conditional move instructions.
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000670// flag:int, data:int
671let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
672 class CondMovIntInt<bits<6> funct, string instr_asm> :
673 FR<0, funct, (outs CPURegs:$dst),
674 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
675 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
676
677def MOVZ_I : CondMovIntInt<0x0a, "movz">;
678def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000679
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000680/// No operation
681let addr=0 in
682 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
683
Eric Christopher3c999a22007-10-26 04:00:13 +0000684// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000685// instructions. The same not happens for stack address copies, so an
686// add op with mem ComplexPattern is used and the stack address copy
687// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanaka03236be2011-07-07 20:54:20 +0000688def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, $addr">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000689
Akira Hatanaka21afc632011-06-21 00:40:49 +0000690// DynAlloc node points to dynamically allocated stack space.
691// $sp is added to the list of implicitly used registers to prevent dead code
692// elimination from removing instructions that modify $sp.
693let Uses = [SP] in
Akira Hatanaka03236be2011-07-07 20:54:20 +0000694def DynAlloc : EffectiveAddress<"addiu\t$dst, $addr">;
Akira Hatanaka21afc632011-06-21 00:40:49 +0000695
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000696// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000697def MADD : MArithR<0, "madd", MipsMAdd, 1>;
698def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000699def MSUB : MArithR<4, "msub", MipsMSub>;
700def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000701
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000702// MUL is a assembly macro in the current used ISAs. In recent ISA's
703// it is a real instruction.
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000704def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000705
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000706def RDHWR : ReadHardware;
707
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000708//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000709// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000710//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000711
712// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000713def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000714 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000715def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000716 (ORi ZERO, imm:$in)>;
717
718// Arbitrary immediates
719def : Pat<(i32 imm:$imm),
720 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
721
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000722// Carry patterns
723def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
724 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
725def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
726 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000727def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000728 (ADDiu CPURegs:$src, imm:$imm)>;
729
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000730// Call
731def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
732 (JAL tglobaladdr:$dst)>;
733def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
734 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000735//def : Pat<(MipsJmpLink CPURegs:$dst),
736// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000737
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000738// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000739def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000740def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000741def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000742 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000743def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
744 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000745
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000746def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000747def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
748 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000749
750def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
751def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
752 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
753
754// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000755def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000756 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000757def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000758 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000759
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000760// tlsgd
761def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
762 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
763
764// tprel hi/lo
765def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
766def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
767 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
768
Akira Hatanaka342837d2011-05-28 01:07:07 +0000769// wrapper_pic
770class WrapperPICPat<SDNode node>:
771 Pat<(MipsWrapperPIC node:$in),
772 (ADDiu GP, node:$in)>;
773
774def : WrapperPICPat<tglobaladdr>;
775def : WrapperPICPat<tconstpool>;
776def : WrapperPICPat<texternalsym>;
777def : WrapperPICPat<tblockaddress>;
778def : WrapperPICPat<tjumptable>;
779
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000780// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000781def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000782 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000783
Eric Christopher3c999a22007-10-26 04:00:13 +0000784// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000785def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
786def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
787def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000788
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000789// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000790def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
791
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000792// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000793def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000794 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000795def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
796 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000797
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000798def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000799 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000800def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000801 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
802def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
803 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
804def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
805 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000806
807def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000808 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000809def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000810 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000811
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000812def : Pat<(brcond CPURegs:$cond, bb:$dst),
813 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
814
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000815// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000816multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
817 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
818 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
819 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
820 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
821 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
822 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
823 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
824 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
825 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
826 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
827 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
828 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
829 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
830 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
831 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
832 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
833}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000834
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000835multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
836 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
837 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
838 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
839 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
840 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
841 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
842}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000843
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000844defm : MovzPats<CPURegs, MOVZ_I>;
845defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000846
847// setcc patterns
848def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
849 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
850def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
851 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
852
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000853def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
854 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
855def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
856 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
857
858def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
859 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
860def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
861 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
862
863def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
864 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
865def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
866 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
867
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000868def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
869 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000870def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
871 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000872
Akira Hatanaka21afc632011-06-21 00:40:49 +0000873// select MipsDynAlloc
874def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
875
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000876//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000877// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000878//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000879
880include "MipsInstrFPU.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000881