blob: b4dc7aae80d5a6454727da792d2ea3f99c05fd7c [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 Hatanakac742e4f2011-11-11 04:06:38 +000042def SDT_MipsDynAlloc : SDTypeProfile<1, 1, [SDTCisVT<0, iPTR>,
43 SDTCisSameAs<0, 1>]>;
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>;
Akira Hatanaka642b1092011-11-11 04:03:54 +0000143def calltarget64: Operand<i64>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000144def simm16 : Operand<i32>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000145def simm16_64 : Operand<i64>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000146def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000147
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000148// Unsigned Operand
149def uimm16 : Operand<i32> {
150 let PrintMethod = "printUnsignedImm";
151}
152
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000153// Address operand
154def mem : Operand<i32> {
155 let PrintMethod = "printMemOperand";
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000156 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000157 let EncoderMethod = "getMemEncoding";
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000158}
159
Akira Hatanakad55bb382011-10-11 00:11:12 +0000160def mem64 : Operand<i64> {
161 let PrintMethod = "printMemOperand";
162 let MIOperandInfo = (ops CPU64Regs, simm16_64);
163}
164
Akira Hatanaka03236be2011-07-07 20:54:20 +0000165def mem_ea : Operand<i32> {
166 let PrintMethod = "printMemOperandEA";
167 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000168 let EncoderMethod = "getMemEncoding";
169}
170
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000171def mem_ea_64 : Operand<i64> {
172 let PrintMethod = "printMemOperandEA";
173 let MIOperandInfo = (ops CPU64Regs, simm16_64);
174 let EncoderMethod = "getMemEncoding";
175}
176
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000177// size operand of ext instruction
178def size_ext : Operand<i32> {
179 let EncoderMethod = "getSizeExtEncoding";
180}
181
182// size operand of ins instruction
183def size_ins : Operand<i32> {
184 let EncoderMethod = "getSizeInsEncoding";
Akira Hatanaka03236be2011-07-07 20:54:20 +0000185}
186
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000187// Transformation Function - get the lower 16 bits.
188def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000189 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000190}]>;
191
192// Transformation Function - get the higher 16 bits.
193def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000194 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000195}]>;
196
197// Node immediate fits as 16-bit sign extended on target immediate.
198// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000199def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000200
201// Node immediate fits as 16-bit zero extended on target immediate.
202// The LO16 param means that only the lower 16 bits of the node
203// immediate are caught.
204// e.g. addiu, sltiu
205def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000206 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000207 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000208 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000209 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000210}], LO16>;
211
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000212// shamt field must fit in 5 bits.
Akira Hatanakaa01820a2011-10-17 18:01:00 +0000213def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000214
Eric Christopher3c999a22007-10-26 04:00:13 +0000215// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000216// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000217def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000218
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000219//===----------------------------------------------------------------------===//
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000220// Pattern fragment for load/store
221//===----------------------------------------------------------------------===//
222class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
223 LoadSDNode *LD = cast<LoadSDNode>(N);
224 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
225}]>;
226
227class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
228 LoadSDNode *LD = cast<LoadSDNode>(N);
229 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
230}]>;
231
232class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
233 (Node node:$val, node:$ptr), [{
234 StoreSDNode *SD = cast<StoreSDNode>(N);
235 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
236}]>;
237
238class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
239 (Node node:$val, node:$ptr), [{
240 StoreSDNode *SD = cast<StoreSDNode>(N);
241 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
242}]>;
243
244// Load/Store PatFrags.
245def sextloadi16_a : AlignedLoad<sextloadi16>;
246def zextloadi16_a : AlignedLoad<zextloadi16>;
247def extloadi16_a : AlignedLoad<extloadi16>;
248def load_a : AlignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000249def sextloadi32_a : AlignedLoad<sextloadi32>;
250def zextloadi32_a : AlignedLoad<zextloadi32>;
251def extloadi32_a : AlignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000252def truncstorei16_a : AlignedStore<truncstorei16>;
253def store_a : AlignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000254def truncstorei32_a : AlignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000255def sextloadi16_u : UnalignedLoad<sextloadi16>;
256def zextloadi16_u : UnalignedLoad<zextloadi16>;
257def extloadi16_u : UnalignedLoad<extloadi16>;
258def load_u : UnalignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000259def sextloadi32_u : UnalignedLoad<sextloadi32>;
260def zextloadi32_u : UnalignedLoad<zextloadi32>;
261def extloadi32_u : UnalignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000262def truncstorei16_u : UnalignedStore<truncstorei16>;
263def store_u : UnalignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000264def truncstorei32_u : UnalignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000265
266//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000267// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000268//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000269
Akira Hatanaka76d9f1c2011-10-11 23:12:12 +0000270// Arithmetic and logical instructions with 3 register operands.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000271class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
272 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
273 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
274 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
275 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
276 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000277 let isCommutable = isComm;
278}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000279
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000280class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000281 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
282 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
283 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
284 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000285 let isCommutable = isComm;
286}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000287
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000288// Arithmetic and logical instructions with 2 register operands.
289class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
290 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000291 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
292 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
293 [(set RC:$rt, (OpNode RC:$rs, imm_type:$imm16))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000294
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000295class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000296 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000297 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
298 !strconcat(instr_asm, "\t$rt, $rs, $imm16"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000299
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000300// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000301let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000302class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000303 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000304 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000305 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000306 let rd = 0;
307 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000308 let isCommutable = isComm;
309}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000310
311// Logical
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000312class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
313 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000314 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000315 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000316 let shamt = 0;
317 let isCommutable = 1;
318}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000319
320// Shifts
Akira Hatanaka36393462011-10-17 18:06:56 +0000321class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
322 SDNode OpNode, PatFrag PF, Operand ImmOpnd,
323 RegisterClass RC>:
324 FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000325 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
Akira Hatanaka36393462011-10-17 18:06:56 +0000326 [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
327 let rs = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000328}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000329
Akira Hatanaka36393462011-10-17 18:06:56 +0000330// 32-bit shift instructions.
331class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
332 SDNode OpNode>:
333 shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
334
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000335class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
336 SDNode OpNode, RegisterClass RC>:
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000337 FR<0x00, func, (outs RC:$rd), (ins CPURegs:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000338 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000339 [(set RC:$rd, (OpNode RC:$rt, CPURegs:$rs))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000340 let shamt = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000341}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000342
343// Load Upper Imediate
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000344class LoadUpper<bits<6> op, string instr_asm, RegisterClass RC, Operand Imm>:
345 FI<op, (outs RC:$rt), (ins Imm:$imm16),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000346 !strconcat(instr_asm, "\t$rt, $imm16"), [], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000347 let rs = 0;
348}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000349
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000350class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
351 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> {
352 bits<21> addr;
353 let Inst{25-21} = addr{20-16};
354 let Inst{15-0} = addr{15-0};
355}
356
Eric Christopher3c999a22007-10-26 04:00:13 +0000357// Memory Load/Store
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000358let canFoldAsLoad = 1 in
Akira Hatanakad55bb382011-10-11 00:11:12 +0000359class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
360 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000361 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000362 !strconcat(instr_asm, "\t$rt, $addr"),
363 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000364 let isPseudo = Pseudo;
365}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000366
Akira Hatanakad55bb382011-10-11 00:11:12 +0000367class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
368 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000369 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000370 !strconcat(instr_asm, "\t$rt, $addr"),
371 [(OpNode RC:$rt, addr:$addr)], IIStore> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000372 let isPseudo = Pseudo;
373}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000374
Akira Hatanakad55bb382011-10-11 00:11:12 +0000375// 32-bit load.
376multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
377 bit Pseudo = 0> {
378 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
379 Requires<[NotN64]>;
380 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
381 Requires<[IsN64]>;
382}
383
384// 64-bit load.
385multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
386 bit Pseudo = 0> {
387 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
388 Requires<[NotN64]>;
389 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
390 Requires<[IsN64]>;
391}
392
393// 32-bit store.
394multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
395 bit Pseudo = 0> {
396 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
397 Requires<[NotN64]>;
398 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
399 Requires<[IsN64]>;
400}
401
402// 64-bit store.
403multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
404 bit Pseudo = 0> {
405 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
406 Requires<[NotN64]>;
407 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
408 Requires<[IsN64]>;
409}
410
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000411// Conditional Branch
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000412class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000413 CBranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$imm16),
414 !strconcat(instr_asm, "\t$rs, $rt, $imm16"),
415 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000416 let isBranch = 1;
417 let isTerminator = 1;
418 let hasDelaySlot = 1;
419}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000420
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000421class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
422 RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000423 CBranchBase<op, (outs), (ins RC:$rs, brtarget:$imm16),
424 !strconcat(instr_asm, "\t$rs, $imm16"),
425 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000426 let rt = _rt;
427 let isBranch = 1;
428 let isTerminator = 1;
429 let hasDelaySlot = 1;
Eric Christopher3c999a22007-10-26 04:00:13 +0000430}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000431
Eric Christopher3c999a22007-10-26 04:00:13 +0000432// SetCC
Akira Hatanaka8191f342011-10-11 18:53:46 +0000433class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
434 RegisterClass RC>:
435 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
436 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
437 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000438 IIAlu> {
439 let shamt = 0;
440}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000441
Akira Hatanaka8191f342011-10-11 18:53:46 +0000442class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
443 PatLeaf imm_type, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000444 FI<op, (outs CPURegs:$rt), (ins RC:$rs, Od:$imm16),
445 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
446 [(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000447 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000448
449// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000450let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000451class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000452 FJ<op, (outs), (ins brtarget:$target),
453 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000454
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000455let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000456class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000457 FR<op, func, (outs), (ins CPURegs:$rs),
458 !strconcat(instr_asm, "\t$rs"), [(brind CPURegs:$rs)], IIBranch> {
459 let rt = 0;
460 let rd = 0;
461 let shamt = 0;
462}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000463
464// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000465let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000466 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000467 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
468 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000469 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000470 FJ<op, (outs), (ins calltarget:$target, variable_ops),
471 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
472 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000473
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000474 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000475 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000476 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
477 let rt = 0;
478 let rd = 31;
479 let shamt = 0;
480 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000481
482 class BranchLink<string instr_asm>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000483 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$imm16, variable_ops),
484 !strconcat(instr_asm, "\t$rs, $imm16"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000485}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000486
Eric Christopher3c999a22007-10-26 04:00:13 +0000487// Mul, Div
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000488class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
489 RegisterClass RC, list<Register> DefRegs>:
490 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000491 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
492 let rd = 0;
493 let shamt = 0;
494 let isCommutable = 1;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000495 let Defs = DefRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000496}
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000497
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000498class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
499 Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
500
501class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
502 RegisterClass RC, list<Register> DefRegs>:
503 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
504 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
505 [(op RC:$rs, RC:$rt)], itin> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000506 let rd = 0;
507 let shamt = 0;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000508 let Defs = DefRegs;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000509}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000510
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000511class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
512 Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
513
Eric Christopher3c999a22007-10-26 04:00:13 +0000514// Move from Hi/Lo
Akira Hatanaka89d30662011-10-17 18:24:15 +0000515class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
516 list<Register> UseRegs>:
517 FR<0x00, func, (outs RC:$rd), (ins),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000518 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
519 let rs = 0;
520 let rt = 0;
521 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000522 let Uses = UseRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000523}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000524
Akira Hatanaka89d30662011-10-17 18:24:15 +0000525class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
526 list<Register> DefRegs>:
527 FR<0x00, func, (outs), (ins RC:$rs),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000528 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
529 let rt = 0;
530 let rd = 0;
531 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000532 let Defs = DefRegs;
Akira Hatanaka36787932011-10-03 19:28:44 +0000533}
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000534
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000535class EffectiveAddress<string instr_asm, RegisterClass RC, Operand Mem> :
536 FMem<0x09, (outs RC:$rt), (ins Mem:$addr),
537 instr_asm, [(set RC:$rt, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000538
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000539// Count Leading Ones/Zeros in Word
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000540class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
541 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
542 !strconcat(instr_asm, "\t$rd, $rs"),
543 [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
544 Requires<[HasBitCount]> {
545 let shamt = 0;
546 let rt = rd;
547}
548
549class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
550 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
551 !strconcat(instr_asm, "\t$rd, $rs"),
552 [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000553 Requires<[HasBitCount]> {
554 let shamt = 0;
555 let rt = rd;
556}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000557
558// Sign Extend in Register.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000559class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000560 FR<0x1f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000561 !strconcat(instr_asm, "\t$rd, $rt"),
562 [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
563 let rs = 0;
564 let shamt = sa;
565 let Predicates = [HasSEInReg];
566}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000567
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000568// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000569class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
570 FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
571 !strconcat(instr_asm, "\t$rd, $rt"),
572 [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
573 let rs = 0;
574 let shamt = sa;
575 let Predicates = [HasSwap];
576}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000577
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000578// Read Hardware
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000579class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$rt), (ins HWRegs:$rd),
580 "rdhwr\t$rt, $rd", [], IIAlu> {
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000581 let rs = 0;
582 let shamt = 0;
583}
584
Akira Hatanaka667645f2011-08-17 22:59:46 +0000585// Ext and Ins
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000586class ExtIns<bits<6> _funct, string instr_asm, dag outs, dag ins,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000587 list<dag> pattern, InstrItinClass itin>:
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000588 FR<0x1f, _funct, outs, ins, !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
Akira Hatanaka56633442011-09-20 23:53:09 +0000589 pattern, itin>, Requires<[HasMips32r2]> {
Akira Hatanaka667645f2011-08-17 22:59:46 +0000590 bits<5> pos;
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000591 bits<5> sz;
592 let rd = sz;
Akira Hatanaka667645f2011-08-17 22:59:46 +0000593 let shamt = pos;
594}
595
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000596// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
Akira Hatanakade9416e2011-07-20 00:53:09 +0000597class Atomic2Ops<PatFrag Op, string Opstr> :
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000598 MipsPseudo<(outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
599 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
600 [(set CPURegs:$dst,
601 (Op CPURegs:$ptr, CPURegs:$incr))]>;
602
603// Atomic Compare & Swap.
604class AtomicCmpSwap<PatFrag Op, string Width> :
605 MipsPseudo<(outs CPURegs:$dst),
606 (ins CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap),
607 !strconcat("atomic_cmp_swap_", Width,
608 "\t$dst, $ptr, $cmp, $swap"),
609 [(set CPURegs:$dst,
610 (Op CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap))]>;
611
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000612//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000613// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000614//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000615
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000616// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000617let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000618def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000619 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000620 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000621def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000622 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000623 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000624}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000625
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000626// Some assembly macros need to avoid pseudoinstructions and assembler
627// automatic reodering, we should reorder ourselves.
628def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
629def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
630def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
631def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
632
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000633// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000634// when using the AT register.
635def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
636def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
637
Eric Christopher3c999a22007-10-26 04:00:13 +0000638// When handling PIC code the assembler needs .cpload and .cprestore
639// directives. If the real instructions corresponding these directives
640// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000641// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000642def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanaka78d62b22011-07-07 22:06:18 +0000643def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000644
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000645let usesCustomInserter = 1 in {
Akira Hatanakade9416e2011-07-20 00:53:09 +0000646 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, "load_add_8">;
647 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, "load_add_16">;
648 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, "load_add_32">;
649 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, "load_sub_8">;
650 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, "load_sub_16">;
651 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, "load_sub_32">;
652 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, "load_and_8">;
653 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, "load_and_16">;
654 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, "load_and_32">;
655 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, "load_or_8">;
656 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, "load_or_16">;
657 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, "load_or_32">;
658 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, "load_xor_8">;
659 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, "load_xor_16">;
660 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, "load_xor_32">;
661 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, "load_nand_8">;
662 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, "load_nand_16">;
663 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, "load_nand_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000664
Akira Hatanakade9416e2011-07-20 00:53:09 +0000665 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, "swap_8">;
666 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, "swap_16">;
667 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, "swap_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000668
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000669 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, "8">;
670 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, "16">;
671 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, "32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000672}
673
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000674//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000675// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000676//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000677
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000678//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000679// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000680//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000681
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000682/// Arithmetic Instructions (ALU Immediate)
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000683def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
684def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000685def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
686def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000687def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
688def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
689def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000690def LUi : LoadUpper<0x0f, "lui", CPURegs, uimm16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000691
692/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000693def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
694def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000695def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
696def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000697def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
698def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000699def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
700def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
701def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000702def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000703
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000704/// Shift Instructions
Akira Hatanaka36393462011-10-17 18:06:56 +0000705def SLL : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
706def SRL : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
707def SRA : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000708def SLLV : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
709def SRLV : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
710def SRAV : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000711
712// Rotate Instructions
Akira Hatanaka56633442011-09-20 23:53:09 +0000713let Predicates = [HasMips32r2] in {
Akira Hatanaka36393462011-10-17 18:06:56 +0000714 def ROTR : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000715 def ROTRV : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000716}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000717
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000718/// Load and Store Instructions
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000719/// aligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000720defm LB : LoadM32<0x20, "lb", sextloadi8>;
721defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
722defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
723defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
724defm LW : LoadM32<0x23, "lw", load_a>;
725defm SB : StoreM32<0x28, "sb", truncstorei8>;
726defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
727defm SW : StoreM32<0x2b, "sw", store_a>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000728
729/// unaligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000730defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
731defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
732defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
733defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
734defm USW : StoreM32<0x2b, "usw", store_u, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000735
Akira Hatanakadb548262011-07-19 23:30:50 +0000736let hasSideEffects = 1 in
737def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000738 [(MipsSync imm:$stype)], NoItinerary, FrmOther>
Akira Hatanakadb548262011-07-19 23:30:50 +0000739{
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000740 bits<5> stype;
741 let Opcode = 0;
Akira Hatanakadb548262011-07-19 23:30:50 +0000742 let Inst{25-11} = 0;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000743 let Inst{10-6} = stype;
Akira Hatanakadb548262011-07-19 23:30:50 +0000744 let Inst{5-0} = 15;
745}
746
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000747/// Load-linked, Store-conditional
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000748let mayLoad = 1 in
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000749 def LL : FMem<0x30, (outs CPURegs:$rt), (ins mem:$addr),
750 "ll\t$rt, $addr", [], IILoad>;
751let mayStore = 1, Constraints = "$rt = $dst" in
752 def SC : FMem<0x38, (outs CPURegs:$dst), (ins CPURegs:$rt, mem:$addr),
753 "sc\t$rt, $addr", [], IIStore>;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000754
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000755/// Jump and Branch Instructions
756def J : JumpFJ<0x02, "j">;
Akira Hatanaka1f8d8222011-08-11 21:05:37 +0000757let isIndirectBranch = 1 in
758 def JR : JumpFR<0x00, 0x08, "jr">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000759def JAL : JumpLink<0x03, "jal">;
760def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000761def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
762def BNE : CBranch<0x05, "bne", setne, CPURegs>;
763def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
764def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000765def BLEZ : CBranchZero<0x06, 0, "blez", setle, CPURegs>;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000766def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000767
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000768let rt=0x11 in
769 def BGEZAL : BranchLink<"bgezal">;
770let rt=0x10 in
771 def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000772
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000773let isReturn=1, isTerminator=1, hasDelaySlot=1,
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000774 isBarrier=1, hasCtrlDep=1, rd=0, rt=0, shamt=0 in
775 def RET : FR <0x00, 0x08, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000776 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
777
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000778/// Multiply and Divide Instructions.
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000779def MULT : Mult32<0x18, "mult", IIImul>;
780def MULTu : Mult32<0x19, "multu", IIImul>;
781def SDIV : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
782def UDIV : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000783
Akira Hatanaka89d30662011-10-17 18:24:15 +0000784def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
785def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
786def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
787def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000788
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000789/// Sign Ext In Register Instructions.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000790def SEB : SignExtInReg<0x10, "seb", i8>;
791def SEH : SignExtInReg<0x18, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000792
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000793/// Count Leading
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000794def CLZ : CountLeading0<0x20, "clz", CPURegs>;
795def CLO : CountLeading1<0x21, "clo", CPURegs>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000796
797/// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000798def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000799
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000800/// No operation
801let addr=0 in
802 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
803
Eric Christopher3c999a22007-10-26 04:00:13 +0000804// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000805// instructions. The same not happens for stack address copies, so an
806// add op with mem ComplexPattern is used and the stack address copy
807// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000808def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000809
Akira Hatanaka21afc632011-06-21 00:40:49 +0000810// DynAlloc node points to dynamically allocated stack space.
811// $sp is added to the list of implicitly used registers to prevent dead code
812// elimination from removing instructions that modify $sp.
813let Uses = [SP] in
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000814def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
Akira Hatanaka21afc632011-06-21 00:40:49 +0000815
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000816// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000817def MADD : MArithR<0, "madd", MipsMAdd, 1>;
818def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000819def MSUB : MArithR<4, "msub", MipsMSub>;
820def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000821
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000822// MUL is a assembly macro in the current used ISAs. In recent ISA's
823// it is a real instruction.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000824def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
825 Requires<[HasMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000826
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000827def RDHWR : ReadHardware;
828
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000829def EXT : ExtIns<0, "ext", (outs CPURegs:$rt),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000830 (ins CPURegs:$rs, uimm16:$pos, size_ext:$sz),
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000831 [(set CPURegs:$rt,
832 (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$sz))],
Akira Hatanaka667645f2011-08-17 22:59:46 +0000833 NoItinerary>;
834
835let Constraints = "$src = $rt" in
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000836def INS : ExtIns<4, "ins", (outs CPURegs:$rt),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000837 (ins CPURegs:$rs, uimm16:$pos, size_ins:$sz, CPURegs:$src),
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000838 [(set CPURegs:$rt,
839 (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$sz,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000840 CPURegs:$src))],
841 NoItinerary>;
Akira Hatanakabb15e112011-08-17 02:05:42 +0000842
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000843//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000844// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000845//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000846
847// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000848def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000849 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000850def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000851 (ORi ZERO, imm:$in)>;
852
853// Arbitrary immediates
854def : Pat<(i32 imm:$imm),
855 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
856
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000857// Carry patterns
858def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
859 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
860def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
861 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000862def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000863 (ADDiu CPURegs:$src, imm:$imm)>;
864
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000865// Call
866def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
867 (JAL tglobaladdr:$dst)>;
868def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
869 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000870//def : Pat<(MipsJmpLink CPURegs:$dst),
871// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000872
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000873// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000874def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000875def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000876def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
877def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000878def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000879 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000880def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
881 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000882
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000883def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000884def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000885def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
886 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000887
888def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000889def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000890def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
891 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
892
893// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000894def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000895 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000896def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000897 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000898
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000899// tlsgd
900def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
901 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
902
903// tprel hi/lo
904def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000905def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000906def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
907 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
908
Akira Hatanaka342837d2011-05-28 01:07:07 +0000909// wrapper_pic
910class WrapperPICPat<SDNode node>:
911 Pat<(MipsWrapperPIC node:$in),
912 (ADDiu GP, node:$in)>;
913
914def : WrapperPICPat<tglobaladdr>;
915def : WrapperPICPat<tconstpool>;
916def : WrapperPICPat<texternalsym>;
917def : WrapperPICPat<tblockaddress>;
918def : WrapperPICPat<tjumptable>;
919
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000920// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000921def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000922 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000923
Eric Christopher3c999a22007-10-26 04:00:13 +0000924// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000925def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
926def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000927def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
928def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000929
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000930// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000931def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
932
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000933// brcond patterns
Akira Hatanaka06f82312011-10-11 19:09:09 +0000934multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
935 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
936 Instruction SLTiuOp, Register ZEROReg> {
937def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
938 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
939def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
940 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000941
Akira Hatanaka06f82312011-10-11 19:09:09 +0000942def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
943 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
944def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
945 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
946def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
947 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
948def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
949 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000950
Akira Hatanaka06f82312011-10-11 19:09:09 +0000951def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
952 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
953def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
954 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000955
Akira Hatanaka06f82312011-10-11 19:09:09 +0000956def : Pat<(brcond RC:$cond, bb:$dst),
957 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
958}
959
960defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000961
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000962// 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 Hatanaka8ae330a2011-10-17 18:53:29 +00001015include "MipsCondMov.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001016