blob: d2a4387209ff8da8a82a25bc1a416b075e59ba42 [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
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000014
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000015//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000016// Mips profiles and nodes
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000017//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000018
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000019def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
20def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000021def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +000022 SDTCisSameAs<1, 2>,
23 SDTCisSameAs<3, 4>,
24 SDTCisInt<4>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000025def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
26def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000027def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000028 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000029 SDTCisSameAs<1, 2>,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000030 SDTCisSameAs<2, 3>]>;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000031def SDT_MipsDivRem : SDTypeProfile<0, 2,
Akira Hatanakadda4a072011-10-03 21:06:13 +000032 [SDTCisInt<0>,
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000033 SDTCisSameAs<0, 1>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000034
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000035def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
36
Akira Hatanakac742e4f2011-11-11 04:06:38 +000037def SDT_MipsDynAlloc : SDTypeProfile<1, 1, [SDTCisVT<0, iPTR>,
38 SDTCisSameAs<0, 1>]>;
Akira Hatanakadb548262011-07-19 23:30:50 +000039def SDT_Sync : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
Akira Hatanaka21afc632011-06-21 00:40:49 +000040
Akira Hatanaka40eda462011-09-22 23:31:54 +000041def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
42 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
43def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
44 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
Akira Hatanakabb15e112011-08-17 02:05:42 +000045 SDTCisSameAs<0, 4>]>;
46
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000047// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000048def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000049 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000050 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000051
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000052// Hi and Lo nodes are used to handle global addresses. Used on
53// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000054// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000055def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
56def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
57def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000058
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000059// TlsGd node is used to handle General Dynamic TLS
60def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
61
62// TprelHi and TprelLo nodes are used to handle Local Exec TLS
63def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
64def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
65
66// Thread pointer
67def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
68
Eric Christopher3c999a22007-10-26 04:00:13 +000069// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000070def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000071 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000072
73// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000074def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000075 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000076def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000077 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000078
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000079// MAdd*/MSub* nodes
80def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
81 [SDNPOptInGlue, SDNPOutGlue]>;
82def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
83 [SDNPOptInGlue, SDNPOutGlue]>;
84def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
85 [SDNPOptInGlue, SDNPOutGlue]>;
86def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
87 [SDNPOptInGlue, SDNPOutGlue]>;
88
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000089// DivRem(u) nodes
90def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
91 [SDNPOutGlue]>;
92def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
93 [SDNPOutGlue]>;
94
Akira Hatanaka6cd4b4e2011-06-07 18:00:14 +000095// Target constant nodes that are not part of any isel patterns and remain
96// unchanged can cause instructions with illegal operands to be emitted.
97// Wrapper node patterns give the instruction selector a chance to replace
98// target constant nodes that would otherwise remain unchanged with ADDiu
99// nodes. Without these wrapper node patterns, the following conditional move
100// instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
Jia Liubb481f82012-02-28 07:46:26 +0000101// compiled:
Akira Hatanaka6cd4b4e2011-06-07 18:00:14 +0000102// movn %got(d)($gp), %got(c)($gp), $4
103// This instruction is illegal since movn can take only register operands.
104
Akira Hatanaka648f00c2012-02-24 22:34:47 +0000105def MipsWrapper : SDNode<"MipsISD::Wrapper", SDTIntBinOp>;
Akira Hatanaka342837d2011-05-28 01:07:07 +0000106
Akira Hatanaka21afc632011-06-21 00:40:49 +0000107// Pointer to dynamically allocated stack area.
108def MipsDynAlloc : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
109 [SDNPHasChain, SDNPInGlue]>;
110
Akira Hatanakadb548262011-07-19 23:30:50 +0000111def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain]>;
112
Akira Hatanakabb15e112011-08-17 02:05:42 +0000113def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>;
114def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>;
115
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000116//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000117// Mips Instruction Predicate Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000118//===----------------------------------------------------------------------===//
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000119def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">,
120 AssemblerPredicate<"FeatureSEInReg">;
121def HasBitCount : Predicate<"Subtarget.hasBitCount()">,
122 AssemblerPredicate<"FeatureBitCount">;
123def HasSwap : Predicate<"Subtarget.hasSwap()">,
124 AssemblerPredicate<"FeatureSwap">;
125def HasCondMov : Predicate<"Subtarget.hasCondMov()">,
126 AssemblerPredicate<"FeatureCondMov">;
127def HasMips32 : Predicate<"Subtarget.hasMips32()">,
128 AssemblerPredicate<"FeatureMips32">;
129def HasMips32r2 : Predicate<"Subtarget.hasMips32r2()">,
130 AssemblerPredicate<"FeatureMips32r2">;
131def HasMips64 : Predicate<"Subtarget.hasMips64()">,
132 AssemblerPredicate<"FeatureMips64">;
133def HasMips32r2Or64 : Predicate<"Subtarget.hasMips32r2Or64()">,
134 AssemblerPredicate<"FeatureMips32r2,FeatureMips64">;
135def NotMips64 : Predicate<"!Subtarget.hasMips64()">,
136 AssemblerPredicate<"!FeatureMips64">;
137def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">,
138 AssemblerPredicate<"FeatureMips64r2">;
139def IsN64 : Predicate<"Subtarget.isABI_N64()">,
140 AssemblerPredicate<"FeatureN64">;
141def NotN64 : Predicate<"!Subtarget.isABI_N64()">,
142 AssemblerPredicate<"!FeatureN64">;
Akira Hatanaka4a5a8942012-05-24 18:32:33 +0000143def InMips16Mode : Predicate<"Subtarget.inMips16Mode()">,
144 AssemblerPredicate<"FeatureMips16">;
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000145def RelocStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">,
146 AssemblerPredicate<"FeatureMips32">;
147def RelocPIC : Predicate<"TM.getRelocationModel() == Reloc::PIC_">,
148 AssemblerPredicate<"FeatureMips32">;
149def NoNaNsFPMath : Predicate<"TM.Options.NoNaNsFPMath">,
150 AssemblerPredicate<"FeatureMips32">;
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000151def HasStandardEncoding:
Akira Hatanaka4a5a8942012-05-24 18:32:33 +0000152 Predicate<"Subtarget.hasStandardEncoding()">,
153 AssemblerPredicate<"FeatureMips32,FeatureMips32r2,FeatureMips64"> ;
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000154
155//===----------------------------------------------------------------------===//
156// Instruction format superclass
157//===----------------------------------------------------------------------===//
158
159include "MipsInstrFormats.td"
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000160
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000161//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000162// Mips Operand, Complex Patterns and Transformations Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000163//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000164
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000165// Instruction operand types
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000166def jmptarget : Operand<OtherVT> {
167 let EncoderMethod = "getJumpTargetOpValue";
168}
169def brtarget : Operand<OtherVT> {
170 let EncoderMethod = "getBranchTargetOpValue";
171 let OperandType = "OPERAND_PCREL";
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000172 let DecoderMethod = "DecodeBranchTarget";
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000173}
Akira Hatanaka421455f2011-11-23 22:19:28 +0000174def calltarget : Operand<iPTR> {
175 let EncoderMethod = "getJumpTargetOpValue";
176}
Akira Hatanaka642b1092011-11-11 04:03:54 +0000177def calltarget64: Operand<i64>;
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000178def simm16 : Operand<i32> {
179 let DecoderMethod= "DecodeSimm16";
180}
Akira Hatanakad55bb382011-10-11 00:11:12 +0000181def simm16_64 : Operand<i64>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000182def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000183
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000184// Unsigned Operand
185def uimm16 : Operand<i32> {
186 let PrintMethod = "printUnsignedImm";
187}
188
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000189// Address operand
190def mem : Operand<i32> {
191 let PrintMethod = "printMemOperand";
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000192 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000193 let EncoderMethod = "getMemEncoding";
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000194}
195
Akira Hatanakad55bb382011-10-11 00:11:12 +0000196def mem64 : Operand<i64> {
197 let PrintMethod = "printMemOperand";
198 let MIOperandInfo = (ops CPU64Regs, simm16_64);
199}
200
Akira Hatanaka03236be2011-07-07 20:54:20 +0000201def mem_ea : Operand<i32> {
202 let PrintMethod = "printMemOperandEA";
203 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000204 let EncoderMethod = "getMemEncoding";
205}
206
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000207def mem_ea_64 : Operand<i64> {
208 let PrintMethod = "printMemOperandEA";
209 let MIOperandInfo = (ops CPU64Regs, simm16_64);
210 let EncoderMethod = "getMemEncoding";
211}
212
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000213// size operand of ext instruction
214def size_ext : Operand<i32> {
215 let EncoderMethod = "getSizeExtEncoding";
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000216 let DecoderMethod = "DecodeExtSize";
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000217}
218
219// size operand of ins instruction
220def size_ins : Operand<i32> {
221 let EncoderMethod = "getSizeInsEncoding";
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000222 let DecoderMethod = "DecodeInsSize";
Akira Hatanaka03236be2011-07-07 20:54:20 +0000223}
224
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000225// Transformation Function - get the lower 16 bits.
226def LO16 : SDNodeXForm<imm, [{
Akira Hatanaka4d0eb632011-12-07 20:10:24 +0000227 return getImm(N, N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000228}]>;
229
230// Transformation Function - get the higher 16 bits.
231def HI16 : SDNodeXForm<imm, [{
Akira Hatanaka4d0eb632011-12-07 20:10:24 +0000232 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000233}]>;
234
235// Node immediate fits as 16-bit sign extended on target immediate.
236// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000237def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000238
239// Node immediate fits as 16-bit zero extended on target immediate.
240// The LO16 param means that only the lower 16 bits of the node
241// immediate are caught.
242// e.g. addiu, sltiu
243def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000244 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000245 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000246 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000247 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000248}], LO16>;
249
Akira Hatanakaf06cb2b2011-12-19 20:21:18 +0000250// Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared).
Akira Hatanaka20103252012-01-04 03:09:26 +0000251def immLow16Zero : PatLeaf<(imm), [{
Akira Hatanakaf06cb2b2011-12-19 20:21:18 +0000252 int64_t Val = N->getSExtValue();
253 return isInt<32>(Val) && !(Val & 0xffff);
254}]>;
255
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000256// shamt field must fit in 5 bits.
Akira Hatanakaa01820a2011-10-17 18:01:00 +0000257def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000258
Eric Christopher3c999a22007-10-26 04:00:13 +0000259// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000260// since load and store instructions from stack used it.
Akira Hatanaka4a5a8942012-05-24 18:32:33 +0000261def addr :
262 ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], [SDNPWantParent]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000263
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000264//===----------------------------------------------------------------------===//
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000265// Pattern fragment for load/store
266//===----------------------------------------------------------------------===//
Akira Hatanaka82099682011-12-19 19:52:25 +0000267class UnalignedLoad<PatFrag Node> :
268 PatFrag<(ops node:$ptr), (Node node:$ptr), [{
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000269 LoadSDNode *LD = cast<LoadSDNode>(N);
270 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
271}]>;
272
Akira Hatanaka82099682011-12-19 19:52:25 +0000273class AlignedLoad<PatFrag Node> :
274 PatFrag<(ops node:$ptr), (Node node:$ptr), [{
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000275 LoadSDNode *LD = cast<LoadSDNode>(N);
276 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
277}]>;
278
Akira Hatanaka82099682011-12-19 19:52:25 +0000279class UnalignedStore<PatFrag Node> :
280 PatFrag<(ops node:$val, node:$ptr), (Node node:$val, node:$ptr), [{
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000281 StoreSDNode *SD = cast<StoreSDNode>(N);
282 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
283}]>;
284
Akira Hatanaka82099682011-12-19 19:52:25 +0000285class AlignedStore<PatFrag Node> :
286 PatFrag<(ops node:$val, node:$ptr), (Node node:$val, node:$ptr), [{
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000287 StoreSDNode *SD = cast<StoreSDNode>(N);
288 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
289}]>;
290
291// Load/Store PatFrags.
292def sextloadi16_a : AlignedLoad<sextloadi16>;
293def zextloadi16_a : AlignedLoad<zextloadi16>;
294def extloadi16_a : AlignedLoad<extloadi16>;
295def load_a : AlignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000296def sextloadi32_a : AlignedLoad<sextloadi32>;
297def zextloadi32_a : AlignedLoad<zextloadi32>;
298def extloadi32_a : AlignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000299def truncstorei16_a : AlignedStore<truncstorei16>;
300def store_a : AlignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000301def truncstorei32_a : AlignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000302def sextloadi16_u : UnalignedLoad<sextloadi16>;
303def zextloadi16_u : UnalignedLoad<zextloadi16>;
304def extloadi16_u : UnalignedLoad<extloadi16>;
305def load_u : UnalignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000306def sextloadi32_u : UnalignedLoad<sextloadi32>;
307def zextloadi32_u : UnalignedLoad<zextloadi32>;
308def extloadi32_u : UnalignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000309def truncstorei16_u : UnalignedStore<truncstorei16>;
310def store_u : UnalignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000311def truncstorei32_u : UnalignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000312
313//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000314// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000315//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000316
Akira Hatanaka76d9f1c2011-10-11 23:12:12 +0000317// Arithmetic and logical instructions with 3 register operands.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000318class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
319 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
320 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
321 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
322 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
323 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000324 let isCommutable = isComm;
Akira Hatanakaa6953492012-04-18 18:52:10 +0000325 let isReMaterializable = 1;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000326}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000327
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000328class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000329 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
330 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
331 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
332 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000333 let isCommutable = isComm;
334}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000335
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000336// Arithmetic and logical instructions with 2 register operands.
337class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
338 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000339 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
340 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
Akira Hatanakaa6953492012-04-18 18:52:10 +0000341 [(set RC:$rt, (OpNode RC:$rs, imm_type:$imm16))], IIAlu> {
342 let isReMaterializable = 1;
343}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000344
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000345class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000346 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000347 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
348 !strconcat(instr_asm, "\t$rt, $rs, $imm16"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000349
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000350// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000351let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000352class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000353 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000354 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000355 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000356 let rd = 0;
357 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000358 let isCommutable = isComm;
359}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000360
361// Logical
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000362class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
363 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000364 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000365 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000366 let shamt = 0;
367 let isCommutable = 1;
368}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000369
370// Shifts
Akira Hatanaka36393462011-10-17 18:06:56 +0000371class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
372 SDNode OpNode, PatFrag PF, Operand ImmOpnd,
373 RegisterClass RC>:
374 FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000375 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
Akira Hatanaka36393462011-10-17 18:06:56 +0000376 [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
377 let rs = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000378}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000379
Akira Hatanaka36393462011-10-17 18:06:56 +0000380// 32-bit shift instructions.
381class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
382 SDNode OpNode>:
383 shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
384
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000385class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
386 SDNode OpNode, RegisterClass RC>:
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000387 FR<0x00, func, (outs RC:$rd), (ins CPURegs:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000388 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000389 [(set RC:$rd, (OpNode RC:$rt, CPURegs:$rs))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000390 let shamt = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000391}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000392
393// Load Upper Imediate
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000394class LoadUpper<bits<6> op, string instr_asm, RegisterClass RC, Operand Imm>:
395 FI<op, (outs RC:$rt), (ins Imm:$imm16),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000396 !strconcat(instr_asm, "\t$rt, $imm16"), [], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000397 let rs = 0;
Akira Hatanaka02365942012-04-03 02:51:09 +0000398 let neverHasSideEffects = 1;
Akira Hatanakaa6953492012-04-18 18:52:10 +0000399 let isReMaterializable = 1;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000400}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000401
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000402class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
403 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> {
404 bits<21> addr;
405 let Inst{25-21} = addr{20-16};
406 let Inst{15-0} = addr{15-0};
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000407 let DecoderMethod = "DecodeMem";
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000408}
409
Eric Christopher3c999a22007-10-26 04:00:13 +0000410// Memory Load/Store
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000411let canFoldAsLoad = 1 in
Akira Hatanakad55bb382011-10-11 00:11:12 +0000412class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
413 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000414 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000415 !strconcat(instr_asm, "\t$rt, $addr"),
416 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000417 let isPseudo = Pseudo;
418}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000419
Akira Hatanakad55bb382011-10-11 00:11:12 +0000420class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
421 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000422 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000423 !strconcat(instr_asm, "\t$rt, $addr"),
424 [(OpNode RC:$rt, addr:$addr)], IIStore> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000425 let isPseudo = Pseudo;
426}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000427
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000428// Unaligned Memory Load/Store
Akira Hatanaka421455f2011-11-23 22:19:28 +0000429let canFoldAsLoad = 1 in
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000430class LoadUnAlign<bits<6> op, RegisterClass RC, Operand MemOpnd>:
431 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr), "", [], IILoad> {}
Akira Hatanaka421455f2011-11-23 22:19:28 +0000432
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000433class StoreUnAlign<bits<6> op, RegisterClass RC, Operand MemOpnd>:
434 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr), "", [], IIStore> {}
Akira Hatanaka421455f2011-11-23 22:19:28 +0000435
Akira Hatanakad55bb382011-10-11 00:11:12 +0000436// 32-bit load.
437multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
438 bit Pseudo = 0> {
439 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000440 Requires<[NotN64, HasStandardEncoding]>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000441 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000442 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000443 let DecoderNamespace = "Mips64";
444 let isCodeGenOnly = 1;
445 }
Jia Liubb481f82012-02-28 07:46:26 +0000446}
Akira Hatanakad55bb382011-10-11 00:11:12 +0000447
448// 64-bit load.
449multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
450 bit Pseudo = 0> {
451 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000452 Requires<[NotN64, HasStandardEncoding]>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000453 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000454 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000455 let DecoderNamespace = "Mips64";
456 let isCodeGenOnly = 1;
457 }
Jia Liubb481f82012-02-28 07:46:26 +0000458}
Akira Hatanakad55bb382011-10-11 00:11:12 +0000459
Akira Hatanaka421455f2011-11-23 22:19:28 +0000460// 32-bit load.
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000461multiclass LoadUnAlign32<bits<6> op> {
462 def #NAME# : LoadUnAlign<op, CPURegs, mem>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000463 Requires<[NotN64, HasStandardEncoding]>;
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000464 def _P8 : LoadUnAlign<op, CPURegs, mem64>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000465 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000466 let DecoderNamespace = "Mips64";
467 let isCodeGenOnly = 1;
468 }
Akira Hatanaka421455f2011-11-23 22:19:28 +0000469}
Akira Hatanakad55bb382011-10-11 00:11:12 +0000470// 32-bit store.
471multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
472 bit Pseudo = 0> {
473 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000474 Requires<[NotN64, HasStandardEncoding]>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000475 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000476 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000477 let DecoderNamespace = "Mips64";
478 let isCodeGenOnly = 1;
479 }
Akira Hatanakad55bb382011-10-11 00:11:12 +0000480}
481
482// 64-bit store.
483multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
484 bit Pseudo = 0> {
485 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000486 Requires<[NotN64, HasStandardEncoding]>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000487 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000488 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000489 let DecoderNamespace = "Mips64";
490 let isCodeGenOnly = 1;
491 }
Akira Hatanakad55bb382011-10-11 00:11:12 +0000492}
493
Akira Hatanaka421455f2011-11-23 22:19:28 +0000494// 32-bit store.
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000495multiclass StoreUnAlign32<bits<6> op> {
496 def #NAME# : StoreUnAlign<op, CPURegs, mem>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000497 Requires<[NotN64, HasStandardEncoding]>;
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000498 def _P8 : StoreUnAlign<op, CPURegs, mem64>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000499 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000500 let DecoderNamespace = "Mips64";
501 let isCodeGenOnly = 1;
502 }
Akira Hatanaka421455f2011-11-23 22:19:28 +0000503}
504
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000505// Conditional Branch
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000506class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000507 BranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$imm16),
508 !strconcat(instr_asm, "\t$rs, $rt, $imm16"),
509 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000510 let isBranch = 1;
511 let isTerminator = 1;
512 let hasDelaySlot = 1;
513}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000514
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000515class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
516 RegisterClass RC>:
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000517 BranchBase<op, (outs), (ins RC:$rs, brtarget:$imm16),
518 !strconcat(instr_asm, "\t$rs, $imm16"),
519 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000520 let rt = _rt;
521 let isBranch = 1;
522 let isTerminator = 1;
523 let hasDelaySlot = 1;
Eric Christopher3c999a22007-10-26 04:00:13 +0000524}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000525
Eric Christopher3c999a22007-10-26 04:00:13 +0000526// SetCC
Akira Hatanaka8191f342011-10-11 18:53:46 +0000527class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
528 RegisterClass RC>:
529 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
530 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
531 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000532 IIAlu> {
533 let shamt = 0;
534}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000535
Akira Hatanaka8191f342011-10-11 18:53:46 +0000536class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
537 PatLeaf imm_type, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000538 FI<op, (outs CPURegs:$rt), (ins RC:$rs, Od:$imm16),
539 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
540 [(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000541 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000542
Akira Hatanaka6e55ff52011-12-12 22:39:35 +0000543// Jump
544class JumpFJ<bits<6> op, string instr_asm>:
545 FJ<op, (outs), (ins jmptarget:$target),
546 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch> {
547 let isBranch=1;
548 let isTerminator=1;
549 let isBarrier=1;
550 let hasDelaySlot = 1;
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000551 let Predicates = [RelocStatic, HasStandardEncoding];
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000552 let DecoderMethod = "DecodeJumpTarget";
Akira Hatanaka6e55ff52011-12-12 22:39:35 +0000553}
554
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000555// Unconditional branch
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000556class UncondBranch<bits<6> op, string instr_asm>:
557 BranchBase<op, (outs), (ins brtarget:$imm16),
558 !strconcat(instr_asm, "\t$imm16"), [(br bb:$imm16)], IIBranch> {
559 let rs = 0;
560 let rt = 0;
561 let isBranch = 1;
562 let isTerminator = 1;
563 let isBarrier = 1;
564 let hasDelaySlot = 1;
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000565 let Predicates = [RelocPIC, HasStandardEncoding];
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000566}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000567
Akira Hatanaka4fd40b32011-11-16 22:36:01 +0000568let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1,
569 isIndirectBranch = 1 in
570class JumpFR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
571 FR<op, func, (outs), (ins RC:$rs),
572 !strconcat(instr_asm, "\t$rs"), [(brind RC:$rs)], IIBranch> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000573 let rt = 0;
574 let rd = 0;
575 let shamt = 0;
576}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000577
578// Jump and Link (Call)
Akira Hatanakaf12e7022012-01-04 03:02:47 +0000579let isCall=1, hasDelaySlot=1 in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000580 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000581 FJ<op, (outs), (ins calltarget:$target, variable_ops),
582 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000583 IIBranch> {
584 let DecoderMethod = "DecodeJumpTarget";
585 }
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000586
Akira Hatanakaf12e7022012-01-04 03:02:47 +0000587 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm,
588 RegisterClass RC>:
589 FR<op, func, (outs), (ins RC:$rs, variable_ops),
590 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink RC:$rs)], IIBranch> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000591 let rt = 0;
592 let rd = 31;
593 let shamt = 0;
594 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000595
Akira Hatanakaf12e7022012-01-04 03:02:47 +0000596 class BranchLink<string instr_asm, bits<5> _rt, RegisterClass RC>:
597 FI<0x1, (outs), (ins RC:$rs, brtarget:$imm16, variable_ops),
598 !strconcat(instr_asm, "\t$rs, $imm16"), [], IIBranch> {
599 let rt = _rt;
600 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000601}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000602
Eric Christopher3c999a22007-10-26 04:00:13 +0000603// Mul, Div
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000604class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
605 RegisterClass RC, list<Register> DefRegs>:
606 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000607 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
608 let rd = 0;
609 let shamt = 0;
610 let isCommutable = 1;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000611 let Defs = DefRegs;
Akira Hatanaka02365942012-04-03 02:51:09 +0000612 let neverHasSideEffects = 1;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000613}
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000614
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000615class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
616 Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
617
618class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
619 RegisterClass RC, list<Register> DefRegs>:
620 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
621 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
622 [(op RC:$rs, RC:$rt)], itin> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000623 let rd = 0;
624 let shamt = 0;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000625 let Defs = DefRegs;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000626}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000627
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000628class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
629 Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
630
Eric Christopher3c999a22007-10-26 04:00:13 +0000631// Move from Hi/Lo
Akira Hatanaka89d30662011-10-17 18:24:15 +0000632class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
633 list<Register> UseRegs>:
634 FR<0x00, func, (outs RC:$rd), (ins),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000635 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
636 let rs = 0;
637 let rt = 0;
638 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000639 let Uses = UseRegs;
Akira Hatanaka02365942012-04-03 02:51:09 +0000640 let neverHasSideEffects = 1;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000641}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000642
Akira Hatanaka89d30662011-10-17 18:24:15 +0000643class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
644 list<Register> DefRegs>:
645 FR<0x00, func, (outs), (ins RC:$rs),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000646 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
647 let rt = 0;
648 let rd = 0;
649 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000650 let Defs = DefRegs;
Akira Hatanaka02365942012-04-03 02:51:09 +0000651 let neverHasSideEffects = 1;
Akira Hatanaka36787932011-10-03 19:28:44 +0000652}
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000653
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000654class EffectiveAddress<string instr_asm, RegisterClass RC, Operand Mem> :
655 FMem<0x09, (outs RC:$rt), (ins Mem:$addr),
656 instr_asm, [(set RC:$rt, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000657
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000658// Count Leading Ones/Zeros in Word
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000659class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
660 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
661 !strconcat(instr_asm, "\t$rd, $rs"),
662 [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000663 Requires<[HasBitCount, HasStandardEncoding]> {
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000664 let shamt = 0;
665 let rt = rd;
666}
667
668class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
669 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
670 !strconcat(instr_asm, "\t$rd, $rs"),
671 [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000672 Requires<[HasBitCount, HasStandardEncoding]> {
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000673 let shamt = 0;
674 let rt = rd;
675}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000676
677// Sign Extend in Register.
Akira Hatanaka5387f2e2012-01-24 21:41:09 +0000678class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt,
679 RegisterClass RC>:
680 FR<0x1f, 0x20, (outs RC:$rd), (ins RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000681 !strconcat(instr_asm, "\t$rd, $rt"),
Akira Hatanaka5387f2e2012-01-24 21:41:09 +0000682 [(set RC:$rd, (sext_inreg RC:$rt, vt))], NoItinerary> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000683 let rs = 0;
684 let shamt = sa;
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000685 let Predicates = [HasSEInReg, HasStandardEncoding];
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000686}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000687
Akira Hatanaka4d2b0f32011-12-20 23:47:44 +0000688// Subword Swap
689class SubwordSwap<bits<6> func, bits<5> sa, string instr_asm, RegisterClass RC>:
690 FR<0x1f, func, (outs RC:$rd), (ins RC:$rt),
691 !strconcat(instr_asm, "\t$rd, $rt"), [], NoItinerary> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000692 let rs = 0;
693 let shamt = sa;
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000694 let Predicates = [HasSwap, HasStandardEncoding];
Akira Hatanaka02365942012-04-03 02:51:09 +0000695 let neverHasSideEffects = 1;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000696}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000697
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000698// Read Hardware
Akira Hatanaka08a7d922011-12-07 23:31:26 +0000699class ReadHardware<RegisterClass CPURegClass, RegisterClass HWRegClass>
700 : FR<0x1f, 0x3b, (outs CPURegClass:$rt), (ins HWRegClass:$rd),
701 "rdhwr\t$rt, $rd", [], IIAlu> {
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000702 let rs = 0;
703 let shamt = 0;
704}
705
Akira Hatanaka667645f2011-08-17 22:59:46 +0000706// Ext and Ins
Akira Hatanakacee46ab2011-12-05 21:14:28 +0000707class ExtBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
Jia Liubb481f82012-02-28 07:46:26 +0000708 FR<0x1f, _funct, (outs RC:$rt), (ins RC:$rs, uimm16:$pos, size_ext:$sz),
Akira Hatanakacee46ab2011-12-05 21:14:28 +0000709 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
710 [(set RC:$rt, (MipsExt RC:$rs, imm:$pos, imm:$sz))], NoItinerary> {
Akira Hatanaka667645f2011-08-17 22:59:46 +0000711 bits<5> pos;
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000712 bits<5> sz;
713 let rd = sz;
Akira Hatanaka667645f2011-08-17 22:59:46 +0000714 let shamt = pos;
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000715 let Predicates = [HasMips32r2, HasStandardEncoding];
Akira Hatanakacee46ab2011-12-05 21:14:28 +0000716}
717
718class InsBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
719 FR<0x1f, _funct, (outs RC:$rt),
720 (ins RC:$rs, uimm16:$pos, size_ins:$sz, RC:$src),
721 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
722 [(set RC:$rt, (MipsIns RC:$rs, imm:$pos, imm:$sz, RC:$src))],
723 NoItinerary> {
724 bits<5> pos;
725 bits<5> sz;
726 let rd = sz;
727 let shamt = pos;
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000728 let Predicates = [HasMips32r2, HasStandardEncoding];
Akira Hatanakacee46ab2011-12-05 21:14:28 +0000729 let Constraints = "$src = $rt";
Akira Hatanaka667645f2011-08-17 22:59:46 +0000730}
731
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000732// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
Akira Hatanaka59068062011-11-11 04:14:30 +0000733class Atomic2Ops<PatFrag Op, string Opstr, RegisterClass DRC,
734 RegisterClass PRC> :
735 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$incr),
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000736 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
Akira Hatanaka59068062011-11-11 04:14:30 +0000737 [(set DRC:$dst, (Op PRC:$ptr, DRC:$incr))]>;
738
739multiclass Atomic2Ops32<PatFrag Op, string Opstr> {
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000740 def #NAME# : Atomic2Ops<Op, Opstr, CPURegs, CPURegs>,
741 Requires<[NotN64, HasStandardEncoding]>;
742 def _P8 : Atomic2Ops<Op, Opstr, CPURegs, CPU64Regs>,
743 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000744 let DecoderNamespace = "Mips64";
745 }
Akira Hatanaka59068062011-11-11 04:14:30 +0000746}
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000747
748// Atomic Compare & Swap.
Akira Hatanaka59068062011-11-11 04:14:30 +0000749class AtomicCmpSwap<PatFrag Op, string Width, RegisterClass DRC,
750 RegisterClass PRC> :
751 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$cmp, DRC:$swap),
752 !strconcat("atomic_cmp_swap_", Width, "\t$dst, $ptr, $cmp, $swap"),
753 [(set DRC:$dst, (Op PRC:$ptr, DRC:$cmp, DRC:$swap))]>;
754
755multiclass AtomicCmpSwap32<PatFrag Op, string Width> {
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000756 def #NAME# : AtomicCmpSwap<Op, Width, CPURegs, CPURegs>,
757 Requires<[NotN64, HasStandardEncoding]>;
758 def _P8 : AtomicCmpSwap<Op, Width, CPURegs, CPU64Regs>,
759 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000760 let DecoderNamespace = "Mips64";
761 }
Akira Hatanaka59068062011-11-11 04:14:30 +0000762}
763
764class LLBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
765 FMem<Opc, (outs RC:$rt), (ins Mem:$addr),
766 !strconcat(opstring, "\t$rt, $addr"), [], IILoad> {
767 let mayLoad = 1;
768}
769
770class SCBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
771 FMem<Opc, (outs RC:$dst), (ins RC:$rt, Mem:$addr),
772 !strconcat(opstring, "\t$rt, $addr"), [], IIStore> {
773 let mayStore = 1;
774 let Constraints = "$rt = $dst";
775}
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000776
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000777//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000778// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000779//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000780
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000781// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000782let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000783def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000784 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000785 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000786def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000787 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000788 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000789}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000790
Eric Christopher3c999a22007-10-26 04:00:13 +0000791// When handling PIC code the assembler needs .cpload and .cprestore
792// directives. If the real instructions corresponding these directives
793// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000794// from the assembler.
Akira Hatanaka02365942012-04-03 02:51:09 +0000795let neverHasSideEffects = 1 in
796def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc, CPURegs:$gp),
797 ".cprestore\t$loc", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000798
Akira Hatanaka648f00c2012-02-24 22:34:47 +0000799// For O32 ABI & PIC & non-fixed global base register, the following instruction
800// seqeunce is emitted to set the global base register:
801//
802// 0. lui $2, %hi(_gp_disp)
803// 1. addiu $2, $2, %lo(_gp_disp)
804// 2. addu $globalbasereg, $2, $t9
805//
806// SETGP01 is emitted during Prologue/Epilogue insertion and then converted to
807// instructions 0 and 1 in the sequence above during MC lowering.
808// SETGP2 is emitted just before register allocation and converted to
809// instruction 2 just prior to post-RA scheduling.
Akira Hatanaka980a9992012-02-28 03:18:43 +0000810//
811// These pseudo instructions are needed to ensure no instructions are inserted
812// before or between instructions 0 and 1, which is a limitation imposed by
813// GNU linker.
Akira Hatanaka648f00c2012-02-24 22:34:47 +0000814
Akira Hatanaka02365942012-04-03 02:51:09 +0000815let isTerminator = 1, isBarrier = 1 in
Akira Hatanaka648f00c2012-02-24 22:34:47 +0000816def SETGP01 : MipsPseudo<(outs CPURegs:$dst), (ins), "", []>;
Akira Hatanaka02365942012-04-03 02:51:09 +0000817
818let neverHasSideEffects = 1 in
Akira Hatanaka648f00c2012-02-24 22:34:47 +0000819def SETGP2 : MipsPseudo<(outs CPURegs:$globalreg), (ins CPURegs:$picreg), "",
820 []>;
821
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000822let usesCustomInserter = 1 in {
Akira Hatanaka59068062011-11-11 04:14:30 +0000823 defm ATOMIC_LOAD_ADD_I8 : Atomic2Ops32<atomic_load_add_8, "load_add_8">;
824 defm ATOMIC_LOAD_ADD_I16 : Atomic2Ops32<atomic_load_add_16, "load_add_16">;
825 defm ATOMIC_LOAD_ADD_I32 : Atomic2Ops32<atomic_load_add_32, "load_add_32">;
826 defm ATOMIC_LOAD_SUB_I8 : Atomic2Ops32<atomic_load_sub_8, "load_sub_8">;
827 defm ATOMIC_LOAD_SUB_I16 : Atomic2Ops32<atomic_load_sub_16, "load_sub_16">;
828 defm ATOMIC_LOAD_SUB_I32 : Atomic2Ops32<atomic_load_sub_32, "load_sub_32">;
829 defm ATOMIC_LOAD_AND_I8 : Atomic2Ops32<atomic_load_and_8, "load_and_8">;
830 defm ATOMIC_LOAD_AND_I16 : Atomic2Ops32<atomic_load_and_16, "load_and_16">;
831 defm ATOMIC_LOAD_AND_I32 : Atomic2Ops32<atomic_load_and_32, "load_and_32">;
832 defm ATOMIC_LOAD_OR_I8 : Atomic2Ops32<atomic_load_or_8, "load_or_8">;
833 defm ATOMIC_LOAD_OR_I16 : Atomic2Ops32<atomic_load_or_16, "load_or_16">;
834 defm ATOMIC_LOAD_OR_I32 : Atomic2Ops32<atomic_load_or_32, "load_or_32">;
835 defm ATOMIC_LOAD_XOR_I8 : Atomic2Ops32<atomic_load_xor_8, "load_xor_8">;
836 defm ATOMIC_LOAD_XOR_I16 : Atomic2Ops32<atomic_load_xor_16, "load_xor_16">;
837 defm ATOMIC_LOAD_XOR_I32 : Atomic2Ops32<atomic_load_xor_32, "load_xor_32">;
838 defm ATOMIC_LOAD_NAND_I8 : Atomic2Ops32<atomic_load_nand_8, "load_nand_8">;
839 defm ATOMIC_LOAD_NAND_I16 : Atomic2Ops32<atomic_load_nand_16, "load_nand_16">;
840 defm ATOMIC_LOAD_NAND_I32 : Atomic2Ops32<atomic_load_nand_32, "load_nand_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000841
Akira Hatanaka59068062011-11-11 04:14:30 +0000842 defm ATOMIC_SWAP_I8 : Atomic2Ops32<atomic_swap_8, "swap_8">;
843 defm ATOMIC_SWAP_I16 : Atomic2Ops32<atomic_swap_16, "swap_16">;
844 defm ATOMIC_SWAP_I32 : Atomic2Ops32<atomic_swap_32, "swap_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000845
Akira Hatanaka59068062011-11-11 04:14:30 +0000846 defm ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap32<atomic_cmp_swap_8, "8">;
847 defm ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap32<atomic_cmp_swap_16, "16">;
848 defm ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap32<atomic_cmp_swap_32, "32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000849}
850
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000851//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000852// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000853//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000854
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000855//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000856// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000857//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000858
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000859/// Arithmetic Instructions (ALU Immediate)
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000860def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
861def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000862def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
863def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000864def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
865def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
866def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000867def LUi : LoadUpper<0x0f, "lui", CPURegs, uimm16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000868
869/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000870def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
871def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000872def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
873def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000874def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
875def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000876def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
877def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
878def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000879def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000880
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000881/// Shift Instructions
Akira Hatanaka36393462011-10-17 18:06:56 +0000882def SLL : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
883def SRL : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
884def SRA : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000885def SLLV : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
886def SRLV : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
887def SRAV : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000888
889// Rotate Instructions
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000890let Predicates = [HasMips32r2, HasStandardEncoding] in {
Akira Hatanaka36393462011-10-17 18:06:56 +0000891 def ROTR : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000892 def ROTRV : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000893}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000894
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000895/// Load and Store Instructions
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000896/// aligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000897defm LB : LoadM32<0x20, "lb", sextloadi8>;
898defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
899defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
900defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
901defm LW : LoadM32<0x23, "lw", load_a>;
902defm SB : StoreM32<0x28, "sb", truncstorei8>;
903defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
904defm SW : StoreM32<0x2b, "sw", store_a>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000905
906/// unaligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000907defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
908defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
909defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
910defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
911defm USW : StoreM32<0x2b, "usw", store_u, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000912
Akira Hatanaka421455f2011-11-23 22:19:28 +0000913/// Primitives for unaligned
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000914defm LWL : LoadUnAlign32<0x22>;
915defm LWR : LoadUnAlign32<0x26>;
916defm SWL : StoreUnAlign32<0x2A>;
917defm SWR : StoreUnAlign32<0x2E>;
Akira Hatanaka421455f2011-11-23 22:19:28 +0000918
Akira Hatanakadb548262011-07-19 23:30:50 +0000919let hasSideEffects = 1 in
920def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000921 [(MipsSync imm:$stype)], NoItinerary, FrmOther>
Akira Hatanakadb548262011-07-19 23:30:50 +0000922{
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000923 bits<5> stype;
924 let Opcode = 0;
Akira Hatanakadb548262011-07-19 23:30:50 +0000925 let Inst{25-11} = 0;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000926 let Inst{10-6} = stype;
Akira Hatanakadb548262011-07-19 23:30:50 +0000927 let Inst{5-0} = 15;
928}
929
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000930/// Load-linked, Store-conditional
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000931def LL : LLBase<0x30, "ll", CPURegs, mem>,
932 Requires<[NotN64, HasStandardEncoding]>;
933def LL_P8 : LLBase<0x30, "ll", CPURegs, mem64>,
934 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000935 let DecoderNamespace = "Mips64";
936}
937
Akira Hatanaka18f3c782012-05-22 03:10:09 +0000938def SC : SCBase<0x38, "sc", CPURegs, mem>,
939 Requires<[NotN64, HasStandardEncoding]>;
940def SC_P8 : SCBase<0x38, "sc", CPURegs, mem64>,
941 Requires<[IsN64, HasStandardEncoding]> {
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000942 let DecoderNamespace = "Mips64";
943}
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000944
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000945/// Jump and Branch Instructions
Akira Hatanaka6e55ff52011-12-12 22:39:35 +0000946def J : JumpFJ<0x02, "j">;
Akira Hatanaka4fd40b32011-11-16 22:36:01 +0000947def JR : JumpFR<0x00, 0x08, "jr", CPURegs>;
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000948def B : UncondBranch<0x04, "b">;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000949def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
950def BNE : CBranch<0x05, "bne", setne, CPURegs>;
951def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
952def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000953def BLEZ : CBranchZero<0x06, 0, "blez", setle, CPURegs>;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000954def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000955
Akira Hatanakab2930b92012-03-01 22:27:29 +0000956def JAL : JumpLink<0x03, "jal">;
957def JALR : JumpLinkReg<0x00, 0x09, "jalr", CPURegs>;
958def BGEZAL : BranchLink<"bgezal", 0x11, CPURegs>;
959def BLTZAL : BranchLink<"bltzal", 0x10, CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000960
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000961let isReturn=1, isTerminator=1, hasDelaySlot=1, isCodeGenOnly=1,
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000962 isBarrier=1, hasCtrlDep=1, rd=0, rt=0, shamt=0 in
963 def RET : FR <0x00, 0x08, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000964 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
965
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000966/// Multiply and Divide Instructions.
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000967def MULT : Mult32<0x18, "mult", IIImul>;
968def MULTu : Mult32<0x19, "multu", IIImul>;
969def SDIV : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
970def UDIV : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000971
Akira Hatanaka89d30662011-10-17 18:24:15 +0000972def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
973def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
974def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
975def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000976
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000977/// Sign Ext In Register Instructions.
Akira Hatanaka5387f2e2012-01-24 21:41:09 +0000978def SEB : SignExtInReg<0x10, "seb", i8, CPURegs>;
979def SEH : SignExtInReg<0x18, "seh", i16, CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000980
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000981/// Count Leading
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000982def CLZ : CountLeading0<0x20, "clz", CPURegs>;
983def CLO : CountLeading1<0x21, "clo", CPURegs>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000984
Akira Hatanaka4d2b0f32011-12-20 23:47:44 +0000985/// Word Swap Bytes Within Halfwords
986def WSBH : SubwordSwap<0x20, 0x2, "wsbh", CPURegs>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000987
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000988/// No operation
989let addr=0 in
990 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
991
Eric Christopher3c999a22007-10-26 04:00:13 +0000992// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000993// instructions. The same not happens for stack address copies, so an
994// add op with mem ComplexPattern is used and the stack address copy
995// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanakaecdc9d52012-04-17 18:03:21 +0000996def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea> {
997 let isCodeGenOnly = 1;
998}
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000999
Akira Hatanaka21afc632011-06-21 00:40:49 +00001000// DynAlloc node points to dynamically allocated stack space.
1001// $sp is added to the list of implicitly used registers to prevent dead code
1002// elimination from removing instructions that modify $sp.
1003let Uses = [SP] in
Akira Hatanakaecdc9d52012-04-17 18:03:21 +00001004def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea> {
1005 let isCodeGenOnly = 1;
1006}
Akira Hatanaka21afc632011-06-21 00:40:49 +00001007
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +00001008// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +00001009def MADD : MArithR<0, "madd", MipsMAdd, 1>;
1010def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +00001011def MSUB : MArithR<4, "msub", MipsMSub>;
1012def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001013
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +00001014// MUL is a assembly macro in the current used ISAs. In recent ISA's
1015// it is a real instruction.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +00001016def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
Akira Hatanaka18f3c782012-05-22 03:10:09 +00001017 Requires<[HasMips32, HasStandardEncoding]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001018
Akira Hatanaka08a7d922011-12-07 23:31:26 +00001019def RDHWR : ReadHardware<CPURegs, HWRegs>;
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +00001020
Akira Hatanakacee46ab2011-12-05 21:14:28 +00001021def EXT : ExtBase<0, "ext", CPURegs>;
1022def INS : InsBase<4, "ins", CPURegs>;
Akira Hatanakabb15e112011-08-17 02:05:42 +00001023
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001024//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001025// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001026//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001027
1028// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +00001029def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +00001030 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +00001031def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001032 (ORi ZERO, imm:$in)>;
Akira Hatanaka20103252012-01-04 03:09:26 +00001033def : Pat<(i32 immLow16Zero:$in),
Akira Hatanakaf06cb2b2011-12-19 20:21:18 +00001034 (LUi (HI16 imm:$in))>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001035
1036// Arbitrary immediates
1037def : Pat<(i32 imm:$imm),
1038 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
1039
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +00001040// Carry patterns
1041def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
1042 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
1043def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
1044 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +00001045def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +00001046 (ADDiu CPURegs:$src, imm:$imm)>;
1047
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001048// Call
1049def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1050 (JAL tglobaladdr:$dst)>;
1051def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1052 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +00001053//def : Pat<(MipsJmpLink CPURegs:$dst),
1054// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001055
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +00001056// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001057def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +00001058def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Akira Hatanaka74c76342011-11-16 22:39:56 +00001059def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
1060def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
Akira Hatanakaca074792011-12-08 20:34:32 +00001061def : Pat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
Akira Hatanaka74c76342011-11-16 22:39:56 +00001062
Akira Hatanakaa4b97f32011-09-13 20:13:58 +00001063def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
1064def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
Akira Hatanaka74c76342011-11-16 22:39:56 +00001065def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
1066def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
Akira Hatanakaca074792011-12-08 20:34:32 +00001067def : Pat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
Akira Hatanaka74c76342011-11-16 22:39:56 +00001068
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001069def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001070 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +00001071def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
1072 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +00001073def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
1074 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +00001075def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
1076 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
Akira Hatanakaca074792011-12-08 20:34:32 +00001077def : Pat<(add CPURegs:$hi, (MipsLo tglobaltlsaddr:$lo)),
1078 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +00001079
1080// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +00001081def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +00001082 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +00001083def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +00001084 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001085
Akira Hatanaka342837d2011-05-28 01:07:07 +00001086// wrapper_pic
Akira Hatanaka648f00c2012-02-24 22:34:47 +00001087class WrapperPat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1088 Pat<(MipsWrapper RC:$gp, node:$in),
1089 (ADDiuOp RC:$gp, node:$in)>;
Akira Hatanaka342837d2011-05-28 01:07:07 +00001090
Akira Hatanaka648f00c2012-02-24 22:34:47 +00001091def : WrapperPat<tglobaladdr, ADDiu, CPURegs>;
1092def : WrapperPat<tconstpool, ADDiu, CPURegs>;
1093def : WrapperPat<texternalsym, ADDiu, CPURegs>;
1094def : WrapperPat<tblockaddress, ADDiu, CPURegs>;
1095def : WrapperPat<tjumptable, ADDiu, CPURegs>;
1096def : WrapperPat<tglobaltlsaddr, ADDiu, CPURegs>;
Akira Hatanaka342837d2011-05-28 01:07:07 +00001097
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001098// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001099def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001100 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001101
Akira Hatanakaab05b6c2011-12-20 22:33:53 +00001102// extended loads
Akira Hatanaka18f3c782012-05-22 03:10:09 +00001103let Predicates = [NotN64, HasStandardEncoding] in {
Akira Hatanakaab05b6c2011-12-20 22:33:53 +00001104 def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
1105 def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
1106 def : Pat<(i32 (extloadi16_a addr:$src)), (LHu addr:$src)>;
1107 def : Pat<(i32 (extloadi16_u addr:$src)), (ULHu addr:$src)>;
1108}
Akira Hatanaka18f3c782012-05-22 03:10:09 +00001109let Predicates = [IsN64, HasStandardEncoding] in {
Akira Hatanakaab05b6c2011-12-20 22:33:53 +00001110 def : Pat<(i32 (extloadi1 addr:$src)), (LBu_P8 addr:$src)>;
1111 def : Pat<(i32 (extloadi8 addr:$src)), (LBu_P8 addr:$src)>;
1112 def : Pat<(i32 (extloadi16_a addr:$src)), (LHu_P8 addr:$src)>;
1113 def : Pat<(i32 (extloadi16_u addr:$src)), (ULHu_P8 addr:$src)>;
1114}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001115
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +00001116// peepholes
Akira Hatanaka18f3c782012-05-22 03:10:09 +00001117let Predicates = [NotN64, HasStandardEncoding] in {
Akira Hatanakac7541c42011-12-21 00:31:10 +00001118 def : Pat<(store_a (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
1119 def : Pat<(store_u (i32 0), addr:$dst), (USW ZERO, addr:$dst)>;
1120}
Akira Hatanaka18f3c782012-05-22 03:10:09 +00001121let Predicates = [IsN64, HasStandardEncoding] in {
Akira Hatanakac7541c42011-12-21 00:31:10 +00001122 def : Pat<(store_a (i32 0), addr:$dst), (SW_P8 ZERO, addr:$dst)>;
1123 def : Pat<(store_u (i32 0), addr:$dst), (USW_P8 ZERO, addr:$dst)>;
1124}
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +00001125
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001126// brcond patterns
Akira Hatanaka06f82312011-10-11 19:09:09 +00001127multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
1128 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
1129 Instruction SLTiuOp, Register ZEROReg> {
1130def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
1131 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
1132def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
1133 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +00001134
Akira Hatanaka06f82312011-10-11 19:09:09 +00001135def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
1136 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1137def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
1138 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1139def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1140 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1141def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1142 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001143
Akira Hatanaka06f82312011-10-11 19:09:09 +00001144def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
1145 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1146def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
1147 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001148
Akira Hatanaka06f82312011-10-11 19:09:09 +00001149def : Pat<(brcond RC:$cond, bb:$dst),
1150 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
1151}
1152
1153defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001154
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +00001155// setcc patterns
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001156multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
1157 Instruction SLTuOp, Register ZEROReg> {
1158 def : Pat<(seteq RC:$lhs, RC:$rhs),
1159 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
1160 def : Pat<(setne RC:$lhs, RC:$rhs),
1161 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
1162}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +00001163
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001164multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1165 def : Pat<(setle RC:$lhs, RC:$rhs),
1166 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
1167 def : Pat<(setule RC:$lhs, RC:$rhs),
1168 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
1169}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001170
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001171multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1172 def : Pat<(setgt RC:$lhs, RC:$rhs),
1173 (SLTOp RC:$rhs, RC:$lhs)>;
1174 def : Pat<(setugt RC:$lhs, RC:$rhs),
1175 (SLTuOp RC:$rhs, RC:$lhs)>;
1176}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001177
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001178multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1179 def : Pat<(setge RC:$lhs, RC:$rhs),
1180 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
1181 def : Pat<(setuge RC:$lhs, RC:$rhs),
1182 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
1183}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001184
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001185multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
1186 Instruction SLTiuOp> {
1187 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
1188 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
1189 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
1190 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1191}
1192
1193defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
1194defm : SetlePats<CPURegs, SLT, SLTu>;
1195defm : SetgtPats<CPURegs, SLT, SLTu>;
1196defm : SetgePats<CPURegs, SLT, SLTu>;
1197defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001198
Akira Hatanaka21afc632011-06-21 00:40:49 +00001199// select MipsDynAlloc
1200def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1201
Akira Hatanaka4d2b0f32011-12-20 23:47:44 +00001202// bswap pattern
Jia Liubb481f82012-02-28 07:46:26 +00001203def : Pat<(bswap CPURegs:$rt), (ROTR (WSBH CPURegs:$rt), 16)>;
Akira Hatanaka4d2b0f32011-12-20 23:47:44 +00001204
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001205//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001206// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001207//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001208
1209include "MipsInstrFPU.td"
Akira Hatanaka95934842011-09-24 01:34:44 +00001210include "Mips64InstrInfo.td"
Akira Hatanaka8ae330a2011-10-17 18:53:29 +00001211include "MipsCondMov.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001212
Akira Hatanakae10d9722012-05-08 19:08:58 +00001213//
1214// Mips16
1215
1216include "Mips16InstrFormats.td"
Akira Hatanaka4a5a8942012-05-24 18:32:33 +00001217include "Mips16InstrInfo.td"