blob: 507010698c8f9f2b517cf5726320b6aecb36214c [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,
Akira Hatanakadda4a072011-10-03 21:06:13 +000037 [SDTCisInt<0>,
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000038 SDTCisSameAs<0, 1>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000039
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000040def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
41
Akira Hatanaka21afc632011-06-21 00:40:49 +000042def SDT_MipsDynAlloc : SDTypeProfile<1, 1, [SDTCisVT<0, i32>,
43 SDTCisVT<1, iPTR>]>;
Akira Hatanakadb548262011-07-19 23:30:50 +000044def SDT_Sync : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
Akira Hatanaka21afc632011-06-21 00:40:49 +000045
Akira Hatanaka40eda462011-09-22 23:31:54 +000046def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
47 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
48def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
49 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
Akira Hatanakabb15e112011-08-17 02:05:42 +000050 SDTCisSameAs<0, 4>]>;
51
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000052// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000053def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000054 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000055 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000056
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000057// Hi and Lo nodes are used to handle global addresses. Used on
58// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000059// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000060def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
61def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
62def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000063
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000064// TlsGd node is used to handle General Dynamic TLS
65def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
66
67// TprelHi and TprelLo nodes are used to handle Local Exec TLS
68def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
69def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
70
71// Thread pointer
72def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
73
Eric Christopher3c999a22007-10-26 04:00:13 +000074// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000075def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000076 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000077
78// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000079def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000080 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000081def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000082 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000083
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000084// MAdd*/MSub* nodes
85def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
86 [SDNPOptInGlue, SDNPOutGlue]>;
87def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
88 [SDNPOptInGlue, SDNPOutGlue]>;
89def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
90 [SDNPOptInGlue, SDNPOutGlue]>;
91def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
92 [SDNPOptInGlue, SDNPOutGlue]>;
93
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000094// DivRem(u) nodes
95def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
96 [SDNPOutGlue]>;
97def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
98 [SDNPOutGlue]>;
99
Akira Hatanaka6cd4b4e2011-06-07 18:00:14 +0000100// Target constant nodes that are not part of any isel patterns and remain
101// unchanged can cause instructions with illegal operands to be emitted.
102// Wrapper node patterns give the instruction selector a chance to replace
103// target constant nodes that would otherwise remain unchanged with ADDiu
104// nodes. Without these wrapper node patterns, the following conditional move
105// instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
106// compiled:
107// movn %got(d)($gp), %got(c)($gp), $4
108// This instruction is illegal since movn can take only register operands.
109
Akira Hatanaka342837d2011-05-28 01:07:07 +0000110def MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", SDTIntUnaryOp>;
111
Akira Hatanaka21afc632011-06-21 00:40:49 +0000112// Pointer to dynamically allocated stack area.
113def MipsDynAlloc : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
114 [SDNPHasChain, SDNPInGlue]>;
115
Akira Hatanakadb548262011-07-19 23:30:50 +0000116def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain]>;
117
Akira Hatanakabb15e112011-08-17 02:05:42 +0000118def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>;
119def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>;
120
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000121//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000122// Mips Instruction Predicate Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000123//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000124def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
125def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000126def HasSwap : Predicate<"Subtarget.hasSwap()">;
127def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Akira Hatanaka56633442011-09-20 23:53:09 +0000128def HasMips32 : Predicate<"Subtarget.hasMips32()">;
129def HasMips32r2 : Predicate<"Subtarget.hasMips32r2()">;
Akira Hatanaka1acb7df2011-10-11 01:12:52 +0000130def HasMips64 : Predicate<"Subtarget.hasMips64()">;
131def NotMips64 : Predicate<"!Subtarget.hasMips64()">;
132def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000133def IsN64 : Predicate<"Subtarget.isABI_N64()">;
134def NotN64 : Predicate<"!Subtarget.isABI_N64()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000135
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000136//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000137// Mips Operand, Complex Patterns and Transformations Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000138//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000139
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000140// Instruction operand types
141def brtarget : Operand<OtherVT>;
142def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000143def simm16 : Operand<i32>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000144def simm16_64 : Operand<i64>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000145def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000146
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000147// Unsigned Operand
148def uimm16 : Operand<i32> {
149 let PrintMethod = "printUnsignedImm";
150}
151
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000152// Address operand
153def mem : Operand<i32> {
154 let PrintMethod = "printMemOperand";
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000155 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000156}
157
Akira Hatanakad55bb382011-10-11 00:11:12 +0000158def mem64 : Operand<i64> {
159 let PrintMethod = "printMemOperand";
160 let MIOperandInfo = (ops CPU64Regs, simm16_64);
161}
162
Akira Hatanaka03236be2011-07-07 20:54:20 +0000163def mem_ea : Operand<i32> {
164 let PrintMethod = "printMemOperandEA";
165 let MIOperandInfo = (ops CPURegs, simm16);
166}
167
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000168// Transformation Function - get the lower 16 bits.
169def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000170 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000171}]>;
172
173// Transformation Function - get the higher 16 bits.
174def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000175 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000176}]>;
177
178// Node immediate fits as 16-bit sign extended on target immediate.
179// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000180def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000181
182// Node immediate fits as 16-bit zero extended on target immediate.
183// The LO16 param means that only the lower 16 bits of the node
184// immediate are caught.
185// e.g. addiu, sltiu
186def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000187 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000188 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000189 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000190 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000191}], LO16>;
192
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000193// shamt field must fit in 5 bits.
Akira Hatanakaa01820a2011-10-17 18:01:00 +0000194def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000195
Eric Christopher3c999a22007-10-26 04:00:13 +0000196// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000197// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000198def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000199
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000200//===----------------------------------------------------------------------===//
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000201// Pattern fragment for load/store
202//===----------------------------------------------------------------------===//
203class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
204 LoadSDNode *LD = cast<LoadSDNode>(N);
205 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
206}]>;
207
208class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
209 LoadSDNode *LD = cast<LoadSDNode>(N);
210 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
211}]>;
212
213class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
214 (Node node:$val, node:$ptr), [{
215 StoreSDNode *SD = cast<StoreSDNode>(N);
216 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
217}]>;
218
219class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
220 (Node node:$val, node:$ptr), [{
221 StoreSDNode *SD = cast<StoreSDNode>(N);
222 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
223}]>;
224
225// Load/Store PatFrags.
226def sextloadi16_a : AlignedLoad<sextloadi16>;
227def zextloadi16_a : AlignedLoad<zextloadi16>;
228def extloadi16_a : AlignedLoad<extloadi16>;
229def load_a : AlignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000230def sextloadi32_a : AlignedLoad<sextloadi32>;
231def zextloadi32_a : AlignedLoad<zextloadi32>;
232def extloadi32_a : AlignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000233def truncstorei16_a : AlignedStore<truncstorei16>;
234def store_a : AlignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000235def truncstorei32_a : AlignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000236def sextloadi16_u : UnalignedLoad<sextloadi16>;
237def zextloadi16_u : UnalignedLoad<zextloadi16>;
238def extloadi16_u : UnalignedLoad<extloadi16>;
239def load_u : UnalignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000240def sextloadi32_u : UnalignedLoad<sextloadi32>;
241def zextloadi32_u : UnalignedLoad<zextloadi32>;
242def extloadi32_u : UnalignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000243def truncstorei16_u : UnalignedStore<truncstorei16>;
244def store_u : UnalignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000245def truncstorei32_u : UnalignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000246
247//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000248// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000249//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000250
Akira Hatanaka76d9f1c2011-10-11 23:12:12 +0000251// Arithmetic and logical instructions with 3 register operands.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000252class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
253 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
254 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
255 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
256 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
257 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000258 let isCommutable = isComm;
259}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000260
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000261class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000262 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
263 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
264 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
265 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000266 let isCommutable = isComm;
267}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000268
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000269// Arithmetic and logical instructions with 2 register operands.
270class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
271 Operand Od, PatLeaf imm_type, RegisterClass RC> :
272 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$i),
273 !strconcat(instr_asm, "\t$rt, $rs, $i"),
274 [(set RC:$rt, (OpNode RC:$rs, imm_type:$i))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000275
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000276class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000277 Operand Od, PatLeaf imm_type, RegisterClass RC> :
278 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$i),
279 !strconcat(instr_asm, "\t$rt, $rs, $i"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000280
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000281// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000282let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000283class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000284 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000285 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000286 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000287 let rd = 0;
288 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000289 let isCommutable = isComm;
290}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000291
292// Logical
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000293class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
294 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000295 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000296 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000297 let shamt = 0;
298 let isCommutable = 1;
299}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000300
301// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000302class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000303 SDNode OpNode>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000304 FR<0x00, func, (outs CPURegs:$rd), (ins CPURegs:$rt, shamt:$shamt),
305 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
306 [(set CPURegs:$rd, (OpNode CPURegs:$rt, (i32 immZExt5:$shamt)))], IIAlu> {
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000307 let rs = _rs;
308}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000309
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000310class LogicR_shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000311 SDNode OpNode>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000312 FR<0x00, func, (outs CPURegs:$rd), (ins CPURegs:$rs, CPURegs:$rt),
313 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
314 [(set CPURegs:$rd, (OpNode CPURegs:$rt, CPURegs:$rs))], IIAlu> {
315 let shamt = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000316}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000317
318// Load Upper Imediate
319class LoadUpper<bits<6> op, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000320 FI<op, (outs CPURegs:$rt), (ins uimm16:$imm),
321 !strconcat(instr_asm, "\t$rt, $imm"), [], IIAlu> {
322 let rs = 0;
323}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000324
Eric Christopher3c999a22007-10-26 04:00:13 +0000325// Memory Load/Store
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000326let canFoldAsLoad = 1 in
Akira Hatanakad55bb382011-10-11 00:11:12 +0000327class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
328 Operand MemOpnd, bit Pseudo>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000329 FI<op, (outs RC:$rt), (ins MemOpnd:$addr),
330 !strconcat(instr_asm, "\t$rt, $addr"),
331 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000332 let isPseudo = Pseudo;
333}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000334
Akira Hatanakad55bb382011-10-11 00:11:12 +0000335class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
336 Operand MemOpnd, bit Pseudo>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000337 FI<op, (outs), (ins RC:$rt, MemOpnd:$addr),
338 !strconcat(instr_asm, "\t$rt, $addr"),
339 [(OpNode RC:$rt, addr:$addr)], IIStore> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000340 let isPseudo = Pseudo;
341}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000342
Akira Hatanakad55bb382011-10-11 00:11:12 +0000343// 32-bit load.
344multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
345 bit Pseudo = 0> {
346 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
347 Requires<[NotN64]>;
348 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
349 Requires<[IsN64]>;
350}
351
352// 64-bit load.
353multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
354 bit Pseudo = 0> {
355 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
356 Requires<[NotN64]>;
357 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
358 Requires<[IsN64]>;
359}
360
361// 32-bit store.
362multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
363 bit Pseudo = 0> {
364 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
365 Requires<[NotN64]>;
366 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
367 Requires<[IsN64]>;
368}
369
370// 64-bit store.
371multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
372 bit Pseudo = 0> {
373 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
374 Requires<[NotN64]>;
375 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
376 Requires<[IsN64]>;
377}
378
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000379// Conditional Branch
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000380class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
381 CBranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$offset),
382 !strconcat(instr_asm, "\t$rs, $rt, $offset"),
383 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$offset)], IIBranch> {
384 let isBranch = 1;
385 let isTerminator = 1;
386 let hasDelaySlot = 1;
387}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000388
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000389class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
390 RegisterClass RC>:
391 CBranchBase<op, (outs), (ins RC:$rs, brtarget:$offset),
392 !strconcat(instr_asm, "\t$rs, $offset"),
393 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$offset)], IIBranch> {
394 let rt = _rt;
395 let isBranch = 1;
396 let isTerminator = 1;
397 let hasDelaySlot = 1;
Eric Christopher3c999a22007-10-26 04:00:13 +0000398}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000399
Eric Christopher3c999a22007-10-26 04:00:13 +0000400// SetCC
Akira Hatanaka8191f342011-10-11 18:53:46 +0000401class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
402 RegisterClass RC>:
403 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
404 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
405 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000406 IIAlu> {
407 let shamt = 0;
408}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000409
Akira Hatanaka8191f342011-10-11 18:53:46 +0000410class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
411 PatLeaf imm_type, RegisterClass RC>:
412 FI<op, (outs CPURegs:$rd), (ins RC:$rs, Od:$i),
413 !strconcat(instr_asm, "\t$rd, $rs, $i"),
414 [(set CPURegs:$rd, (cond_op RC:$rs, imm_type:$i))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000415 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000416
417// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000418let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000419class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000420 FJ<op, (outs), (ins brtarget:$target),
421 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000422
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000423let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000424class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000425 FR<op, func, (outs), (ins CPURegs:$rs),
426 !strconcat(instr_asm, "\t$rs"), [(brind CPURegs:$rs)], IIBranch> {
427 let rt = 0;
428 let rd = 0;
429 let shamt = 0;
430}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000431
432// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000433let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000434 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000435 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
436 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000437 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000438 FJ<op, (outs), (ins calltarget:$target, variable_ops),
439 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
440 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000441
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000442 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000443 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000444 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
445 let rt = 0;
446 let rd = 31;
447 let shamt = 0;
448 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000449
450 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000451 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000452 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch> {
453 let rt = 0;
454 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000455}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000456
Eric Christopher3c999a22007-10-26 04:00:13 +0000457// Mul, Div
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000458class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
459 FR<0x00, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
460 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
461 let rd = 0;
462 let shamt = 0;
463 let isCommutable = 1;
464 let Defs = [HI, LO];
465}
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000466
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000467class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
468 FR<0x00, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
469 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
470 [(op CPURegs:$rs, CPURegs:$rt)], itin> {
471 let rd = 0;
472 let shamt = 0;
473 let Defs = [HI, LO];
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000474}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000475
Eric Christopher3c999a22007-10-26 04:00:13 +0000476// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000477class MoveFromLOHI<bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000478 FR<0x00, func, (outs CPURegs:$rd), (ins),
479 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
480 let rs = 0;
481 let rt = 0;
482 let shamt = 0;
483}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000484
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000485class MoveToLOHI<bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000486 FR<0x00, func, (outs), (ins CPURegs:$rs),
487 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
488 let rt = 0;
489 let rd = 0;
490 let shamt = 0;
Akira Hatanaka36787932011-10-03 19:28:44 +0000491}
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000492
Eric Christopher3c999a22007-10-26 04:00:13 +0000493class EffectiveAddress<string instr_asm> :
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000494 FI<0x09, (outs CPURegs:$rt), (ins mem_ea:$addr),
495 instr_asm, [(set CPURegs:$rt, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000496
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000497// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000498class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000499 FR<0x1c, func, (outs CPURegs:$rd), (ins CPURegs:$rs),
500 !strconcat(instr_asm, "\t$rd, $rs"), pattern, IIAlu>,
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000501 Requires<[HasBitCount]> {
502 let shamt = 0;
503 let rt = rd;
504}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000505
506// Sign Extend in Register.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000507class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
508 FR<0x3f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
509 !strconcat(instr_asm, "\t$rd, $rt"),
510 [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
511 let rs = 0;
512 let shamt = sa;
513 let Predicates = [HasSEInReg];
514}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000515
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000516// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000517class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
518 FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
519 !strconcat(instr_asm, "\t$rd, $rt"),
520 [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
521 let rs = 0;
522 let shamt = sa;
523 let Predicates = [HasSwap];
524}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000525
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000526// Read Hardware
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000527class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$rt), (ins HWRegs:$rd),
528 "rdhwr\t$rt, $rd", [], IIAlu> {
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000529 let rs = 0;
530 let shamt = 0;
531}
532
Akira Hatanaka667645f2011-08-17 22:59:46 +0000533// Ext and Ins
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000534class ExtIns<bits<6> _funct, string instr_asm, dag outs, dag ins,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000535 list<dag> pattern, InstrItinClass itin>:
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000536 FR<0x1f, _funct, outs, ins, !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
Akira Hatanaka56633442011-09-20 23:53:09 +0000537 pattern, itin>, Requires<[HasMips32r2]> {
Akira Hatanaka667645f2011-08-17 22:59:46 +0000538 bits<5> pos;
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000539 bits<5> sz;
540 let rd = sz;
Akira Hatanaka667645f2011-08-17 22:59:46 +0000541 let shamt = pos;
542}
543
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000544// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
Akira Hatanakade9416e2011-07-20 00:53:09 +0000545class Atomic2Ops<PatFrag Op, string Opstr> :
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000546 MipsPseudo<(outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
547 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
548 [(set CPURegs:$dst,
549 (Op CPURegs:$ptr, CPURegs:$incr))]>;
550
551// Atomic Compare & Swap.
552class AtomicCmpSwap<PatFrag Op, string Width> :
553 MipsPseudo<(outs CPURegs:$dst),
554 (ins CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap),
555 !strconcat("atomic_cmp_swap_", Width,
556 "\t$dst, $ptr, $cmp, $swap"),
557 [(set CPURegs:$dst,
558 (Op CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap))]>;
559
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000560//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000561// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000562//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000563
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000564// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000565let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000566def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000567 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000568 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000569def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000570 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000571 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000572}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000573
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000574// Some assembly macros need to avoid pseudoinstructions and assembler
575// automatic reodering, we should reorder ourselves.
576def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
577def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
578def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
579def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
580
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000581// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000582// when using the AT register.
583def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
584def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
585
Eric Christopher3c999a22007-10-26 04:00:13 +0000586// When handling PIC code the assembler needs .cpload and .cprestore
587// directives. If the real instructions corresponding these directives
588// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000589// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000590def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanaka78d62b22011-07-07 22:06:18 +0000591def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000592
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000593let usesCustomInserter = 1 in {
Akira Hatanakade9416e2011-07-20 00:53:09 +0000594 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, "load_add_8">;
595 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, "load_add_16">;
596 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, "load_add_32">;
597 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, "load_sub_8">;
598 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, "load_sub_16">;
599 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, "load_sub_32">;
600 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, "load_and_8">;
601 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, "load_and_16">;
602 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, "load_and_32">;
603 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, "load_or_8">;
604 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, "load_or_16">;
605 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, "load_or_32">;
606 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, "load_xor_8">;
607 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, "load_xor_16">;
608 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, "load_xor_32">;
609 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, "load_nand_8">;
610 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, "load_nand_16">;
611 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, "load_nand_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000612
Akira Hatanakade9416e2011-07-20 00:53:09 +0000613 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, "swap_8">;
614 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, "swap_16">;
615 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, "swap_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000616
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000617 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, "8">;
618 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, "16">;
619 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, "32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000620}
621
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000622//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000623// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000624//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000625
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000626//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000627// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000628//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000629
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000630/// Arithmetic Instructions (ALU Immediate)
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000631def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
632def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000633def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
634def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000635def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
636def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
637def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000638def LUi : LoadUpper<0x0f, "lui">;
639
640/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000641def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
642def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000643def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
644def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000645def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
646def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000647def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
648def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
649def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000650def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000651
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000652/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000653def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
654def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
655def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
656def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
657def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
658def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
659
660// Rotate Instructions
Akira Hatanaka56633442011-09-20 23:53:09 +0000661let Predicates = [HasMips32r2] in {
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000662 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
663 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
664}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000665
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000666/// Load and Store Instructions
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000667/// aligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000668defm LB : LoadM32<0x20, "lb", sextloadi8>;
669defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
670defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
671defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
672defm LW : LoadM32<0x23, "lw", load_a>;
673defm SB : StoreM32<0x28, "sb", truncstorei8>;
674defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
675defm SW : StoreM32<0x2b, "sw", store_a>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000676
677/// unaligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000678defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
679defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
680defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
681defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
682defm USW : StoreM32<0x2b, "usw", store_u, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000683
Akira Hatanakadb548262011-07-19 23:30:50 +0000684let hasSideEffects = 1 in
685def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
686 [(MipsSync imm:$stype)], NoItinerary>
687{
688 let opcode = 0;
689 let Inst{25-11} = 0;
690 let Inst{5-0} = 15;
691}
692
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000693/// Load-linked, Store-conditional
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000694let mayLoad = 1 in
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000695 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
696 "ll\t$dst, $addr", [], IILoad>;
Akira Hatanaka0d7d0b52011-07-18 18:52:12 +0000697let mayStore = 1, Constraints = "$src = $dst" in
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000698 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
699 "sc\t$src, $addr", [], IIStore>;
700
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000701/// Jump and Branch Instructions
702def J : JumpFJ<0x02, "j">;
Akira Hatanaka1f8d8222011-08-11 21:05:37 +0000703let isIndirectBranch = 1 in
704 def JR : JumpFR<0x00, 0x08, "jr">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000705def JAL : JumpLink<0x03, "jal">;
706def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000707def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
708def BNE : CBranch<0x05, "bne", setne, CPURegs>;
709def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
710def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
711def BLEZ : CBranchZero<0x07, 0, "blez", setle, CPURegs>;
712def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000713
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000714def BGEZAL : BranchLink<"bgezal">;
715def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000716
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000717let isReturn=1, isTerminator=1, hasDelaySlot=1,
718 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
719 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
720 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
721
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000722/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000723def MULT : Mul<0x18, "mult", IIImul>;
724def MULTu : Mul<0x19, "multu", IIImul>;
725def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
726def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000727
728let Defs = [HI] in
729 def MTHI : MoveToLOHI<0x11, "mthi">;
730let Defs = [LO] in
731 def MTLO : MoveToLOHI<0x13, "mtlo">;
732
733let Uses = [HI] in
734 def MFHI : MoveFromLOHI<0x10, "mfhi">;
735let Uses = [LO] in
736 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000737
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000738/// Sign Ext In Register Instructions.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000739def SEB : SignExtInReg<0x10, "seb", i8>;
740def SEH : SignExtInReg<0x18, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000741
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000742/// Count Leading
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000743def CLZ : CountLeading<0x20, "clz",
744 [(set CPURegs:$rd, (ctlz CPURegs:$rs))]>;
745def CLO : CountLeading<0x21, "clo",
746 [(set CPURegs:$rd, (ctlz (not CPURegs:$rs)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000747
748/// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000749def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000750
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000751// Conditional moves:
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +0000752// These instructions are expanded in
753// MipsISelLowering::EmitInstrWithCustomInserter if target does not have
754// conditional move instructions.
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000755// flag:int, data:int
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000756class CondMovIntInt<bits<6> funct, string instr_asm> :
757 FR<0, funct, (outs CPURegs:$rd),
758 (ins CPURegs:$rs, CPURegs:$rt, CPURegs:$F),
759 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], NoItinerary> {
760 let shamt = 0;
761 let usesCustomInserter = 1;
762 let Constraints = "$F = $rd";
763}
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000764
765def MOVZ_I : CondMovIntInt<0x0a, "movz">;
766def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000767
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000768/// No operation
769let addr=0 in
770 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
771
Eric Christopher3c999a22007-10-26 04:00:13 +0000772// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000773// instructions. The same not happens for stack address copies, so an
774// add op with mem ComplexPattern is used and the stack address copy
775// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000776def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000777
Akira Hatanaka21afc632011-06-21 00:40:49 +0000778// DynAlloc node points to dynamically allocated stack space.
779// $sp is added to the list of implicitly used registers to prevent dead code
780// elimination from removing instructions that modify $sp.
781let Uses = [SP] in
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000782def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr">;
Akira Hatanaka21afc632011-06-21 00:40:49 +0000783
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000784// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000785def MADD : MArithR<0, "madd", MipsMAdd, 1>;
786def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000787def MSUB : MArithR<4, "msub", MipsMSub>;
788def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000789
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000790// MUL is a assembly macro in the current used ISAs. In recent ISA's
791// it is a real instruction.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000792def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
793 Requires<[HasMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000794
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000795def RDHWR : ReadHardware;
796
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000797def EXT : ExtIns<0, "ext", (outs CPURegs:$rt),
798 (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz),
799 [(set CPURegs:$rt,
800 (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$sz))],
Akira Hatanaka667645f2011-08-17 22:59:46 +0000801 NoItinerary>;
802
803let Constraints = "$src = $rt" in
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000804def INS : ExtIns<4, "ins", (outs CPURegs:$rt),
805 (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz, CPURegs:$src),
806 [(set CPURegs:$rt,
807 (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$sz,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000808 CPURegs:$src))],
809 NoItinerary>;
Akira Hatanakabb15e112011-08-17 02:05:42 +0000810
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000811//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000812// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000813//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000814
815// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000816def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000817 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000818def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000819 (ORi ZERO, imm:$in)>;
820
821// Arbitrary immediates
822def : Pat<(i32 imm:$imm),
823 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
824
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000825// Carry patterns
826def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
827 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
828def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
829 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000830def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000831 (ADDiu CPURegs:$src, imm:$imm)>;
832
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000833// Call
834def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
835 (JAL tglobaladdr:$dst)>;
836def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
837 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000838//def : Pat<(MipsJmpLink CPURegs:$dst),
839// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000840
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000841// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000842def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000843def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000844def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
845def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000846def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000847 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000848def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
849 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000850
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000851def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000852def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000853def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
854 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000855
856def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000857def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000858def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
859 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
860
861// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000862def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000863 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000864def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000865 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000866
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000867// tlsgd
868def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
869 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
870
871// tprel hi/lo
872def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000873def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000874def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
875 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
876
Akira Hatanaka342837d2011-05-28 01:07:07 +0000877// wrapper_pic
878class WrapperPICPat<SDNode node>:
879 Pat<(MipsWrapperPIC node:$in),
880 (ADDiu GP, node:$in)>;
881
882def : WrapperPICPat<tglobaladdr>;
883def : WrapperPICPat<tconstpool>;
884def : WrapperPICPat<texternalsym>;
885def : WrapperPICPat<tblockaddress>;
886def : WrapperPICPat<tjumptable>;
887
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000888// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000889def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000890 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000891
Eric Christopher3c999a22007-10-26 04:00:13 +0000892// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000893def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
894def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000895def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
896def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000897
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000898// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000899def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
900
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000901// brcond patterns
Akira Hatanaka06f82312011-10-11 19:09:09 +0000902multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
903 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
904 Instruction SLTiuOp, Register ZEROReg> {
905def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
906 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
907def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
908 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000909
Akira Hatanaka06f82312011-10-11 19:09:09 +0000910def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
911 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
912def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
913 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
914def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
915 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
916def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
917 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000918
Akira Hatanaka06f82312011-10-11 19:09:09 +0000919def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
920 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
921def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
922 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000923
Akira Hatanaka06f82312011-10-11 19:09:09 +0000924def : Pat<(brcond RC:$cond, bb:$dst),
925 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
926}
927
928defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000929
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000930// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000931multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
Akira Hatanaka40eda462011-09-22 23:31:54 +0000932 def : Pat<(select (i32 (setge CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000933 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000934 def : Pat<(select (i32 (setuge CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000935 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000936 def : Pat<(select (i32 (setge CPURegs:$lhs, immSExt16:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000937 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000938 def : Pat<(select (i32 (setuge CPURegs:$lh, immSExt16:$rh)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000939 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000940 def : Pat<(select (i32 (setle CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000941 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000942 def : Pat<(select (i32 (setule CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000943 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000944 def : Pat<(select (i32 (seteq CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000945 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000946 def : Pat<(select (i32 (seteq CPURegs:$lhs, 0)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000947 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
948}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000949
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000950multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
Akira Hatanaka40eda462011-09-22 23:31:54 +0000951 def : Pat<(select (i32 (setne CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000952 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
953 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
954 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000955 def : Pat<(select (i32 (setne CPURegs:$lhs, 0)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000956 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
957}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000958
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000959defm : MovzPats<CPURegs, MOVZ_I>;
960defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000961
962// setcc patterns
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000963multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
964 Instruction SLTuOp, Register ZEROReg> {
965 def : Pat<(seteq RC:$lhs, RC:$rhs),
966 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
967 def : Pat<(setne RC:$lhs, RC:$rhs),
968 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
969}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000970
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000971multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
972 def : Pat<(setle RC:$lhs, RC:$rhs),
973 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
974 def : Pat<(setule RC:$lhs, RC:$rhs),
975 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
976}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000977
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000978multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
979 def : Pat<(setgt RC:$lhs, RC:$rhs),
980 (SLTOp RC:$rhs, RC:$lhs)>;
981 def : Pat<(setugt RC:$lhs, RC:$rhs),
982 (SLTuOp RC:$rhs, RC:$lhs)>;
983}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000984
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000985multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
986 def : Pat<(setge RC:$lhs, RC:$rhs),
987 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
988 def : Pat<(setuge RC:$lhs, RC:$rhs),
989 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
990}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000991
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000992multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
993 Instruction SLTiuOp> {
994 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
995 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
996 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
997 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
998}
999
1000defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
1001defm : SetlePats<CPURegs, SLT, SLTu>;
1002defm : SetgtPats<CPURegs, SLT, SLTu>;
1003defm : SetgePats<CPURegs, SLT, SLTu>;
1004defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001005
Akira Hatanaka21afc632011-06-21 00:40:49 +00001006// select MipsDynAlloc
1007def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1008
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001009//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001010// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001011//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001012
1013include "MipsInstrFPU.td"
Akira Hatanaka95934842011-09-24 01:34:44 +00001014include "Mips64InstrInfo.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001015