blob: 0e20f986c7f84b4c69bf277b67ba61523d8ab001 [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 Hatanakaedacba82011-05-25 17:32:06 +0000156class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
157 bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000158 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000159 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
160 let isCommutable = isComm;
161}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000162
163// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000164class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
165 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000166 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
167 !strconcat(instr_asm, "\t$dst, $b, $c"),
168 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000169
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000170class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
171 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000172 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
173 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000174
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000175// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000176let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000177class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000178 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000179 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000180 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
181 let isCommutable = isComm;
182}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000183
184// Logical
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000185let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000186class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000187 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
188 !strconcat(instr_asm, "\t$dst, $b, $c"),
189 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000190
191class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000192 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
193 !strconcat(instr_asm, "\t$dst, $b, $c"),
194 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000195
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000196let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000197class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000198 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
199 !strconcat(instr_asm, "\t$dst, $b, $c"),
200 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000201
202// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000203class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000204 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000205 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
206 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000207 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
208 let rs = _rs;
209}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000210
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000211class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000212 SDNode OpNode>:
213 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000214 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000215 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
216 let shamt = _shamt;
217}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000218
219// Load Upper Imediate
220class LoadUpper<bits<6> op, string instr_asm>:
221 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000222 (outs CPURegs:$dst),
223 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000224 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000225 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000226
Eric Christopher3c999a22007-10-26 04:00:13 +0000227// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000228let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000229class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000230 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
231 !strconcat(instr_asm, "\t$dst, $addr"),
232 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000233
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000234class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000235 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
236 !strconcat(instr_asm, "\t$dst, $addr"),
237 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000238
239// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000240let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000241class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000242 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
243 !strconcat(instr_asm, "\t$a, $b, $offset"),
244 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
245 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000246
247class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000248 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
249 !strconcat(instr_asm, "\t$src, $offset"),
250 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
251 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000252}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000253
Eric Christopher3c999a22007-10-26 04:00:13 +0000254// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000255class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
256 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000257 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
258 !strconcat(instr_asm, "\t$dst, $b, $c"),
259 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
260 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000261
262class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
263 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000264 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
265 !strconcat(instr_asm, "\t$dst, $b, $c"),
266 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
267 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000268
269// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000270let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000271class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000272 FJ<op, (outs), (ins brtarget:$target),
273 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000274
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000275let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000276class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000277 FR<op, func, (outs), (ins CPURegs:$target),
278 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000279
280// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000281let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000282 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000283 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
284 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000285 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000286 FJ<op, (outs), (ins calltarget:$target, variable_ops),
287 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
288 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000289
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000290 let rd=31 in
291 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000292 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
293 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000294
295 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000296 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
297 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000298}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000299
Eric Christopher3c999a22007-10-26 04:00:13 +0000300// Mul, Div
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000301let Defs = [HI, LO] in {
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000302 let isCommutable = 1 in
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000303 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
304 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
305 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
306
307 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
308 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
309 !strconcat(instr_asm, "\t$$zero, $a, $b"),
310 [(op CPURegs:$a, CPURegs:$b)], itin>;
311}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000312
Eric Christopher3c999a22007-10-26 04:00:13 +0000313// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000314class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000315 FR<0x00, func, (outs CPURegs:$dst), (ins),
316 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000317
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000318class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000319 FR<0x00, func, (outs), (ins CPURegs:$src),
320 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000321
Eric Christopher3c999a22007-10-26 04:00:13 +0000322class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000323 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
324 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000325
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000326// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000327class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000328 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000329 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
330 Requires<[HasBitCount]> {
331 let shamt = 0;
332 let rt = rd;
333}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000334
335// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000336class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000337 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
338 !strconcat(instr_asm, "\t$dst, $src"),
339 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000340
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000341// Byte Swap
342class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000343 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
344 !strconcat(instr_asm, "\t$dst, $src"),
345 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000346
347// Conditional Move
348class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000349 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
350 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000351 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000352
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000353//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000354// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000355//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000356
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000357// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000358let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000359def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000360 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000361 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000362def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000363 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000364 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000365}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000366
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000367// Some assembly macros need to avoid pseudoinstructions and assembler
368// automatic reodering, we should reorder ourselves.
369def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
370def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
371def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
372def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
373
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000374// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000375// when using the AT register.
376def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
377def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
378
Eric Christopher3c999a22007-10-26 04:00:13 +0000379// When handling PIC code the assembler needs .cpload and .cprestore
380// directives. If the real instructions corresponding these directives
381// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000382// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000383def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanakace98deb2011-05-24 21:22:21 +0000384def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000385
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000386//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000387// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000388//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000389
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000390//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000391// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000392//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000393
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000394/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000395def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
396def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000397def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000398def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000399def ANDi : LogicI<0x0c, "andi", and>;
400def ORi : LogicI<0x0d, "ori", or>;
401def XORi : LogicI<0x0e, "xori", xor>;
402def LUi : LoadUpper<0x0f, "lui">;
403
404/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000405def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000406def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000407def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000408def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000409def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
410def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000411def AND : LogicR<0x24, "and", and>;
412def OR : LogicR<0x25, "or", or>;
413def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000414def NOR : LogicNOR<0x00, 0x27, "nor">;
415
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000416/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000417def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
418def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
419def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
420def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
421def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
422def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
423
424// Rotate Instructions
425let Predicates = [IsMips32r2] in {
426 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
427 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
428}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000429
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000430/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000431def LB : LoadM<0x20, "lb", sextloadi8>;
432def LBu : LoadM<0x24, "lbu", zextloadi8>;
433def LH : LoadM<0x21, "lh", sextloadi16>;
434def LHu : LoadM<0x25, "lhu", zextloadi16>;
435def LW : LoadM<0x23, "lw", load>;
436def SB : StoreM<0x28, "sb", truncstorei8>;
437def SH : StoreM<0x29, "sh", truncstorei16>;
438def SW : StoreM<0x2b, "sw", store>;
439
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000440/// Jump and Branch Instructions
441def J : JumpFJ<0x02, "j">;
442def JR : JumpFR<0x00, 0x08, "jr">;
443def JAL : JumpLink<0x03, "jal">;
444def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000445def BEQ : CBranch<0x04, "beq", seteq>;
446def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000447
Eric Christopher3c999a22007-10-26 04:00:13 +0000448let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000449 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000450
451let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000452 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
453 def BLEZ : CBranchZero<0x07, "blez", setle>;
454 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000455}
456
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000457def BGEZAL : BranchLink<"bgezal">;
458def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000459
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000460let isReturn=1, isTerminator=1, hasDelaySlot=1,
461 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
462 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
463 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
464
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000465/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000466def MULT : Mul<0x18, "mult", IIImul>;
467def MULTu : Mul<0x19, "multu", IIImul>;
468def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
469def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000470
471let Defs = [HI] in
472 def MTHI : MoveToLOHI<0x11, "mthi">;
473let Defs = [LO] in
474 def MTLO : MoveToLOHI<0x13, "mtlo">;
475
476let Uses = [HI] in
477 def MFHI : MoveFromLOHI<0x10, "mfhi">;
478let Uses = [LO] in
479 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000480
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000481/// Sign Ext In Register Instructions.
482let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000483 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000484 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000485
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000486 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000487 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000488}
489
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000490/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000491def CLZ : CountLeading<0b100000, "clz",
492 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
493def CLO : CountLeading<0b100001, "clo",
494 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000495
496/// Byte Swap
497let Predicates = [HasSwap] in {
498 let shamt = 0x3, rs = 0 in
499 def WSBW : ByteSwap<0x20, "wsbw">;
500}
501
502/// Conditional Move
503def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
504def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
505
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000506// Conditional moves:
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +0000507// These instructions are expanded in
508// MipsISelLowering::EmitInstrWithCustomInserter if target does not have
509// conditional move instructions.
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000510// flag:int, data:int
511let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
512 class CondMovIntInt<bits<6> funct, string instr_asm> :
513 FR<0, funct, (outs CPURegs:$dst),
514 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
515 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
516
517def MOVZ_I : CondMovIntInt<0x0a, "movz">;
518def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000519
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000520/// No operation
521let addr=0 in
522 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
523
Eric Christopher3c999a22007-10-26 04:00:13 +0000524// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000525// instructions. The same not happens for stack address copies, so an
526// add op with mem ComplexPattern is used and the stack address copy
527// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000528def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000529
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000530// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000531def MADD : MArithR<0, "madd", MipsMAdd, 1>;
532def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000533def MSUB : MArithR<4, "msub", MipsMSub>;
534def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000535
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000536// MUL is a assembly macro in the current used ISAs. In recent ISA's
537// it is a real instruction.
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000538def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000539
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000540//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000541// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000542//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000543
544// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000545def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000546 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000547def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000548 (ORi ZERO, imm:$in)>;
549
550// Arbitrary immediates
551def : Pat<(i32 imm:$imm),
552 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
553
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000554// Carry patterns
555def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
556 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
557def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
558 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000559def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000560 (ADDiu CPURegs:$src, imm:$imm)>;
561
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000562// Call
563def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
564 (JAL tglobaladdr:$dst)>;
565def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
566 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000567//def : Pat<(MipsJmpLink CPURegs:$dst),
568// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000569
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000570// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000571def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000572def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000573def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000574 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000575def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
576 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000577
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000578def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000579def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
580 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000581
582def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
583def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
584 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
585
586// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000587def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000588 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000589def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000590 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000591
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000592// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000593def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000594 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000595
Eric Christopher3c999a22007-10-26 04:00:13 +0000596// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000597def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
598def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
599def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000600
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000601// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000602def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
603
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000604// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000605def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000606 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000607def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
608 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000609
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000610def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000611 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000612def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000613 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
614def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
615 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
616def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
617 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000618
619def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000620 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000621def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000622 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000623
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000624def : Pat<(brcond CPURegs:$cond, bb:$dst),
625 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
626
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000627// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000628multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
629 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
630 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
631 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
632 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
633 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
634 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
635 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
636 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
637 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
638 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
639 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
640 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
641 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
642 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
643 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
644 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
645}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000646
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000647multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
648 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
649 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
650 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
651 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
652 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
653 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
654}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000655
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000656defm : MovzPats<CPURegs, MOVZ_I>;
657defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000658
Bruno Cardoso Lopesab8d53a2010-12-07 19:00:20 +0000659// select patterns with got access
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000660let AddedComplexity = 10 in
661 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs),
662 (i32 tglobaladdr:$T), CPURegs:$F),
663 (MOVN_I CPURegs:$F, (ADDiu GP, tglobaladdr:$T),
664 (XOR CPURegs:$lhs, CPURegs:$rhs))>;
Bruno Cardoso Lopesab8d53a2010-12-07 19:00:20 +0000665
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000666// setcc patterns
667def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
668 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
669def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
670 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
671
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000672def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
673 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
674def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
675 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
676
677def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
678 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
679def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
680 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
681
682def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
683 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
684def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
685 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
686
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000687def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
688 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000689def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
690 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000691
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000692//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000693// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000694//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000695
696include "MipsInstrFPU.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000697