blob: 07be0ac6976388c3ec102fe89bfe1242f3a7f832 [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 Lopes972f5892007-06-06 07:42:06 +000040// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000041def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000042 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000043 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000044
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000045// Hi and Lo nodes are used to handle global addresses. Used on
46// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000047// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000048def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
49def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
50def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000051
Eric Christopher3c999a22007-10-26 04:00:13 +000052// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000053def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000054 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000055
56// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000057def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000058 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000059def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000060 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000061
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000062// MAdd*/MSub* nodes
63def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
64 [SDNPOptInGlue, SDNPOutGlue]>;
65def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
66 [SDNPOptInGlue, SDNPOutGlue]>;
67def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
68 [SDNPOptInGlue, SDNPOutGlue]>;
69def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
70 [SDNPOptInGlue, SDNPOutGlue]>;
71
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000072// DivRem(u) nodes
73def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
74 [SDNPOutGlue]>;
75def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
76 [SDNPOutGlue]>;
77
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000078//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000079// Mips Instruction Predicate Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000080//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +000081def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
82def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000083def HasSwap : Predicate<"Subtarget.hasSwap()">;
84def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +000085def IsMips32 : Predicate<"Subtarget.isMips32()">;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +000086def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000087
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000088//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000089// Mips Operand, Complex Patterns and Transformations Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000090//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000091
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000092// Instruction operand types
93def brtarget : Operand<OtherVT>;
94def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000095def simm16 : Operand<i32>;
Eric Christopher3c999a22007-10-26 04:00:13 +000096def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000097
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000098// Unsigned Operand
99def uimm16 : Operand<i32> {
100 let PrintMethod = "printUnsignedImm";
101}
102
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000103// Address operand
104def mem : Operand<i32> {
105 let PrintMethod = "printMemOperand";
106 let MIOperandInfo = (ops simm16, CPURegs);
107}
108
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000109// Transformation Function - get the lower 16 bits.
110def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000111 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000112}]>;
113
114// Transformation Function - get the higher 16 bits.
115def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000116 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000117}]>;
118
119// Node immediate fits as 16-bit sign extended on target immediate.
120// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000121def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000122
123// Node immediate fits as 16-bit zero extended on target immediate.
124// The LO16 param means that only the lower 16 bits of the node
125// immediate are caught.
126// e.g. addiu, sltiu
127def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000128 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000129 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000130 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000131 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000132}], LO16>;
133
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000134// shamt field must fit in 5 bits.
135def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000136 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000137}]>;
138
Eric Christopher3c999a22007-10-26 04:00:13 +0000139// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000140// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000141def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000142
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000143//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000144// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000145//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000146
147// Arithmetic 3 register operands
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000148class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000149 InstrItinClass itin, bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000150 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
151 !strconcat(instr_asm, "\t$dst, $b, $c"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000152 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
153 let isCommutable = isComm;
154}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000155
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000156class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm, bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000157 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000158 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
159 let isCommutable = isComm;
160}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000161
162// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000163class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
164 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000165 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
166 !strconcat(instr_asm, "\t$dst, $b, $c"),
167 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000168
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000169class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
170 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000171 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
172 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000173
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000174// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000175let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000176class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000177 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000178 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000179 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
180 let isCommutable = isComm;
181}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000182
183// Logical
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000184let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000185class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000186 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
187 !strconcat(instr_asm, "\t$dst, $b, $c"),
188 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000189
190class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000191 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
192 !strconcat(instr_asm, "\t$dst, $b, $c"),
193 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000194
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000195let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000196class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000197 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
198 !strconcat(instr_asm, "\t$dst, $b, $c"),
199 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000200
201// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000202class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000203 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000204 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
205 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000206 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
207 let rs = _rs;
208}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000209
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000210class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000211 SDNode OpNode>:
212 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000213 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000214 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
215 let shamt = _shamt;
216}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000217
218// Load Upper Imediate
219class LoadUpper<bits<6> op, string instr_asm>:
220 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000221 (outs CPURegs:$dst),
222 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000223 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000224 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000225
Eric Christopher3c999a22007-10-26 04:00:13 +0000226// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000227let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000228class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000229 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
230 !strconcat(instr_asm, "\t$dst, $addr"),
231 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000232
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000233class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000234 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
235 !strconcat(instr_asm, "\t$dst, $addr"),
236 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000237
238// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000239let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000240class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000241 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
242 !strconcat(instr_asm, "\t$a, $b, $offset"),
243 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
244 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000245
246class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000247 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
248 !strconcat(instr_asm, "\t$src, $offset"),
249 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
250 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000251}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000252
Eric Christopher3c999a22007-10-26 04:00:13 +0000253// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000254class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
255 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000256 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
257 !strconcat(instr_asm, "\t$dst, $b, $c"),
258 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
259 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000260
261class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
262 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000263 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
264 !strconcat(instr_asm, "\t$dst, $b, $c"),
265 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
266 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000267
268// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000269let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000270class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000271 FJ<op, (outs), (ins brtarget:$target),
272 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000273
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000274let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000275class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000276 FR<op, func, (outs), (ins CPURegs:$target),
277 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000278
279// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000280let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000281 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000282 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
283 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000284 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000285 FJ<op, (outs), (ins calltarget:$target, variable_ops),
286 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
287 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000288
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000289 let rd=31 in
290 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000291 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
292 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000293
294 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000295 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
296 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000297}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000298
Eric Christopher3c999a22007-10-26 04:00:13 +0000299// Mul, Div
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000300let Defs = [HI, LO] in {
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000301 let isCommutable = 1 in
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000302 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
303 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
304 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
305
306 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
307 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
308 !strconcat(instr_asm, "\t$$zero, $a, $b"),
309 [(op CPURegs:$a, CPURegs:$b)], itin>;
310}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000311
Eric Christopher3c999a22007-10-26 04:00:13 +0000312// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000313class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000314 FR<0x00, func, (outs CPURegs:$dst), (ins),
315 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000316
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000317class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000318 FR<0x00, func, (outs), (ins CPURegs:$src),
319 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000320
Eric Christopher3c999a22007-10-26 04:00:13 +0000321class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000322 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
323 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000324
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000325// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000326class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000327 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000328 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
329 Requires<[HasBitCount]> {
330 let shamt = 0;
331 let rt = rd;
332}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000333
334// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000335class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000336 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
337 !strconcat(instr_asm, "\t$dst, $src"),
338 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000339
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000340// Byte Swap
341class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000342 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
343 !strconcat(instr_asm, "\t$dst, $src"),
344 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000345
346// Conditional Move
347class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000348 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
349 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000350 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000351
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000352//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000353// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000354//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000355
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000356// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000357let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000358def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000359 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000360 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000361def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000362 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000363 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000364}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000365
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000366// Some assembly macros need to avoid pseudoinstructions and assembler
367// automatic reodering, we should reorder ourselves.
368def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
369def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
370def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
371def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
372
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000373// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000374// when using the AT register.
375def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
376def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
377
Eric Christopher3c999a22007-10-26 04:00:13 +0000378// When handling PIC code the assembler needs .cpload and .cprestore
379// directives. If the real instructions corresponding these directives
380// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000381// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000382def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000383def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000384
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000385//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000386// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000387//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000388
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000389//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000390// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000391//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000392
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000393/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000394def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
395def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000396def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000397def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000398def ANDi : LogicI<0x0c, "andi", and>;
399def ORi : LogicI<0x0d, "ori", or>;
400def XORi : LogicI<0x0e, "xori", xor>;
401def LUi : LoadUpper<0x0f, "lui">;
402
403/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000404def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000405def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000406def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000407def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000408def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
409def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000410def AND : LogicR<0x24, "and", and>;
411def OR : LogicR<0x25, "or", or>;
412def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000413def NOR : LogicNOR<0x00, 0x27, "nor">;
414
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000415/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000416def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
417def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
418def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
419def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
420def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
421def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
422
423// Rotate Instructions
424let Predicates = [IsMips32r2] in {
425 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
426 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
427}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000428
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000429/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000430def LB : LoadM<0x20, "lb", sextloadi8>;
431def LBu : LoadM<0x24, "lbu", zextloadi8>;
432def LH : LoadM<0x21, "lh", sextloadi16>;
433def LHu : LoadM<0x25, "lhu", zextloadi16>;
434def LW : LoadM<0x23, "lw", load>;
435def SB : StoreM<0x28, "sb", truncstorei8>;
436def SH : StoreM<0x29, "sh", truncstorei16>;
437def SW : StoreM<0x2b, "sw", store>;
438
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000439/// Jump and Branch Instructions
440def J : JumpFJ<0x02, "j">;
441def JR : JumpFR<0x00, 0x08, "jr">;
442def JAL : JumpLink<0x03, "jal">;
443def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000444def BEQ : CBranch<0x04, "beq", seteq>;
445def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000446
Eric Christopher3c999a22007-10-26 04:00:13 +0000447let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000448 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000449
450let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000451 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
452 def BLEZ : CBranchZero<0x07, "blez", setle>;
453 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000454}
455
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000456def BGEZAL : BranchLink<"bgezal">;
457def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000458
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000459let isReturn=1, isTerminator=1, hasDelaySlot=1,
460 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
461 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
462 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
463
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000464/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000465def MULT : Mul<0x18, "mult", IIImul>;
466def MULTu : Mul<0x19, "multu", IIImul>;
467def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
468def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000469
470let Defs = [HI] in
471 def MTHI : MoveToLOHI<0x11, "mthi">;
472let Defs = [LO] in
473 def MTLO : MoveToLOHI<0x13, "mtlo">;
474
475let Uses = [HI] in
476 def MFHI : MoveFromLOHI<0x10, "mfhi">;
477let Uses = [LO] in
478 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000479
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000480/// Sign Ext In Register Instructions.
481let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000482 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000483 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000484
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000485 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000486 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000487}
488
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000489/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000490def CLZ : CountLeading<0b100000, "clz",
491 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
492def CLO : CountLeading<0b100001, "clo",
493 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000494
495/// Byte Swap
496let Predicates = [HasSwap] in {
497 let shamt = 0x3, rs = 0 in
498 def WSBW : ByteSwap<0x20, "wsbw">;
499}
500
501/// Conditional Move
502def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
503def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
504
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000505// Conditional moves:
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +0000506// These instructions are expanded in
507// MipsISelLowering::EmitInstrWithCustomInserter if target does not have
508// conditional move instructions.
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000509// flag:int, data:int
510let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
511 class CondMovIntInt<bits<6> funct, string instr_asm> :
512 FR<0, funct, (outs CPURegs:$dst),
513 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
514 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
515
516def MOVZ_I : CondMovIntInt<0x0a, "movz">;
517def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000518
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000519/// No operation
520let addr=0 in
521 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
522
Eric Christopher3c999a22007-10-26 04:00:13 +0000523// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000524// instructions. The same not happens for stack address copies, so an
525// add op with mem ComplexPattern is used and the stack address copy
526// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000527def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000528
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000529// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000530def MADD : MArithR<0, "madd", MipsMAdd, 1>;
531def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000532def MSUB : MArithR<4, "msub", MipsMSub>;
533def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000534
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000535// MUL is a assembly macro in the current used ISAs. In recent ISA's
536// it is a real instruction.
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000537def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000538
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000539//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000540// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000541//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000542
543// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000544def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000545 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000546def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000547 (ORi ZERO, imm:$in)>;
548
549// Arbitrary immediates
550def : Pat<(i32 imm:$imm),
551 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
552
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000553// Carry patterns
554def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
555 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
556def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
557 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000558def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000559 (ADDiu CPURegs:$src, imm:$imm)>;
560
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000561// Call
562def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
563 (JAL tglobaladdr:$dst)>;
564def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
565 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000566//def : Pat<(MipsJmpLink CPURegs:$dst),
567// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000568
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000569// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000570def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000571def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000572def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000573 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000574def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
575 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000576
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000577def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000578def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
579 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000580
581def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
582def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
583 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
584
585// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000586def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000587 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000588def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000589 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000590
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000591// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000592def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000593 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000594
Eric Christopher3c999a22007-10-26 04:00:13 +0000595// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000596def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
597def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
598def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000599
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000600// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000601def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
602
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000603// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000604def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000605 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000606def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
607 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000608
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000609def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000610 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000611def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000612 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
613def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
614 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
615def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
616 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000617
618def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000619 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000620def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000621 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000622
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000623def : Pat<(brcond CPURegs:$cond, bb:$dst),
624 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
625
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000626// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000627multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
628 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
629 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
630 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
631 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
632 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
633 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
634 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
635 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
636 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
637 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
638 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
639 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
640 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
641 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
642 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
643 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
644}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000645
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000646multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
647 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
648 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
649 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
650 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
651 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
652 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
653}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000654
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000655defm : MovzPats<CPURegs, MOVZ_I>;
656defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000657
Bruno Cardoso Lopesab8d53a2010-12-07 19:00:20 +0000658// select patterns with got access
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000659let AddedComplexity = 10 in
660 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs),
661 (i32 tglobaladdr:$T), CPURegs:$F),
662 (MOVN_I CPURegs:$F, (ADDiu GP, tglobaladdr:$T),
663 (XOR CPURegs:$lhs, CPURegs:$rhs))>;
Bruno Cardoso Lopesab8d53a2010-12-07 19:00:20 +0000664
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000665// setcc patterns
666def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
667 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
668def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
669 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
670
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000671def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
672 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
673def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
674 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
675
676def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
677 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
678def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
679 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
680
681def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
682 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
683def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
684 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
685
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000686def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
687 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000688def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
689 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000690
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000691//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000692// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000693//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000694
695include "MipsInstrFPU.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000696