blob: fd99b1312621443c19813aad1ddb224acb973ec3 [file] [log] [blame]
Eric Christopher49ac3d72011-05-09 18:16:46 +00001//===- MipsInstrInfo.td - Target Description for Mips Target -*- tablegen -*-=//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Eric Christopher49ac3d72011-05-09 18:16:46 +00009//
10// This file contains the Mips implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000013
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000014//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000015// Instruction format superclass
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000016//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000017
18include "MipsInstrFormats.td"
19
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000020//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000021// Mips profiles and nodes
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000022//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000023
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000024def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
25def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000026def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +000027 SDTCisSameAs<1, 2>,
28 SDTCisSameAs<3, 4>,
29 SDTCisInt<4>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000030def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
31def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000032def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000033 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000034 SDTCisSameAs<1, 2>,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000035 SDTCisSameAs<2, 3>]>;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000036def SDT_MipsDivRem : SDTypeProfile<0, 2,
Akira Hatanakadda4a072011-10-03 21:06:13 +000037 [SDTCisInt<0>,
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000038 SDTCisSameAs<0, 1>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000039
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000040def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
41
Akira Hatanaka21afc632011-06-21 00:40:49 +000042def SDT_MipsDynAlloc : SDTypeProfile<1, 1, [SDTCisVT<0, i32>,
43 SDTCisVT<1, iPTR>]>;
Akira Hatanakadb548262011-07-19 23:30:50 +000044def SDT_Sync : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
Akira Hatanaka21afc632011-06-21 00:40:49 +000045
Akira Hatanaka40eda462011-09-22 23:31:54 +000046def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
47 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
48def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
49 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
Akira Hatanakabb15e112011-08-17 02:05:42 +000050 SDTCisSameAs<0, 4>]>;
51
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000052// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000053def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000054 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000055 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000056
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000057// Hi and Lo nodes are used to handle global addresses. Used on
58// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000059// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000060def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
61def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
62def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000063
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000064// TlsGd node is used to handle General Dynamic TLS
65def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
66
67// TprelHi and TprelLo nodes are used to handle Local Exec TLS
68def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
69def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
70
71// Thread pointer
72def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
73
Eric Christopher3c999a22007-10-26 04:00:13 +000074// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000075def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000076 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000077
78// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000079def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000080 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000081def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000082 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000083
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000084// MAdd*/MSub* nodes
85def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
86 [SDNPOptInGlue, SDNPOutGlue]>;
87def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
88 [SDNPOptInGlue, SDNPOutGlue]>;
89def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
90 [SDNPOptInGlue, SDNPOutGlue]>;
91def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
92 [SDNPOptInGlue, SDNPOutGlue]>;
93
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000094// DivRem(u) nodes
95def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
96 [SDNPOutGlue]>;
97def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
98 [SDNPOutGlue]>;
99
Akira Hatanaka6cd4b4e2011-06-07 18:00:14 +0000100// Target constant nodes that are not part of any isel patterns and remain
101// unchanged can cause instructions with illegal operands to be emitted.
102// Wrapper node patterns give the instruction selector a chance to replace
103// target constant nodes that would otherwise remain unchanged with ADDiu
104// nodes. Without these wrapper node patterns, the following conditional move
105// instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
106// compiled:
107// movn %got(d)($gp), %got(c)($gp), $4
108// This instruction is illegal since movn can take only register operands.
109
Akira Hatanaka342837d2011-05-28 01:07:07 +0000110def MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", SDTIntUnaryOp>;
111
Akira Hatanaka21afc632011-06-21 00:40:49 +0000112// Pointer to dynamically allocated stack area.
113def MipsDynAlloc : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
114 [SDNPHasChain, SDNPInGlue]>;
115
Akira Hatanakadb548262011-07-19 23:30:50 +0000116def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain]>;
117
Akira Hatanakabb15e112011-08-17 02:05:42 +0000118def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>;
119def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>;
120
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000121//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000122// Mips Instruction Predicate Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000123//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000124def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
125def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000126def HasSwap : Predicate<"Subtarget.hasSwap()">;
127def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Akira Hatanaka56633442011-09-20 23:53:09 +0000128def HasMips32 : Predicate<"Subtarget.hasMips32()">;
129def HasMips32r2 : Predicate<"Subtarget.hasMips32r2()">;
Akira Hatanaka1acb7df2011-10-11 01:12:52 +0000130def HasMips64 : Predicate<"Subtarget.hasMips64()">;
131def NotMips64 : Predicate<"!Subtarget.hasMips64()">;
132def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000133def IsN64 : Predicate<"Subtarget.isABI_N64()">;
134def NotN64 : Predicate<"!Subtarget.isABI_N64()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000135
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000136//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000137// Mips Operand, Complex Patterns and Transformations Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000138//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000139
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000140// Instruction operand types
141def brtarget : Operand<OtherVT>;
142def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000143def simm16 : Operand<i32>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000144def simm16_64 : Operand<i64>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000145def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000146
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000147// Unsigned Operand
148def uimm16 : Operand<i32> {
149 let PrintMethod = "printUnsignedImm";
150}
151
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000152// Address operand
153def mem : Operand<i32> {
154 let PrintMethod = "printMemOperand";
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000155 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000156 let EncoderMethod = "getMemEncoding";
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000157}
158
Akira Hatanakad55bb382011-10-11 00:11:12 +0000159def mem64 : Operand<i64> {
160 let PrintMethod = "printMemOperand";
161 let MIOperandInfo = (ops CPU64Regs, simm16_64);
162}
163
Akira Hatanaka03236be2011-07-07 20:54:20 +0000164def mem_ea : Operand<i32> {
165 let PrintMethod = "printMemOperandEA";
166 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000167 let EncoderMethod = "getMemEncoding";
168}
169
170// size operand of ext instruction
171def size_ext : Operand<i32> {
172 let EncoderMethod = "getSizeExtEncoding";
173}
174
175// size operand of ins instruction
176def size_ins : Operand<i32> {
177 let EncoderMethod = "getSizeInsEncoding";
Akira Hatanaka03236be2011-07-07 20:54:20 +0000178}
179
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000180// Transformation Function - get the lower 16 bits.
181def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000182 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000183}]>;
184
185// Transformation Function - get the higher 16 bits.
186def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000187 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000188}]>;
189
190// Node immediate fits as 16-bit sign extended on target immediate.
191// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000192def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000193
194// Node immediate fits as 16-bit zero extended on target immediate.
195// The LO16 param means that only the lower 16 bits of the node
196// immediate are caught.
197// e.g. addiu, sltiu
198def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000199 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000200 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000201 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000202 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000203}], LO16>;
204
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000205// shamt field must fit in 5 bits.
Akira Hatanakaa01820a2011-10-17 18:01:00 +0000206def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000207
Eric Christopher3c999a22007-10-26 04:00:13 +0000208// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000209// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000210def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000211
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000212//===----------------------------------------------------------------------===//
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000213// Pattern fragment for load/store
214//===----------------------------------------------------------------------===//
215class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
216 LoadSDNode *LD = cast<LoadSDNode>(N);
217 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
218}]>;
219
220class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
221 LoadSDNode *LD = cast<LoadSDNode>(N);
222 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
223}]>;
224
225class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
226 (Node node:$val, node:$ptr), [{
227 StoreSDNode *SD = cast<StoreSDNode>(N);
228 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
229}]>;
230
231class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
232 (Node node:$val, node:$ptr), [{
233 StoreSDNode *SD = cast<StoreSDNode>(N);
234 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
235}]>;
236
237// Load/Store PatFrags.
238def sextloadi16_a : AlignedLoad<sextloadi16>;
239def zextloadi16_a : AlignedLoad<zextloadi16>;
240def extloadi16_a : AlignedLoad<extloadi16>;
241def load_a : AlignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000242def sextloadi32_a : AlignedLoad<sextloadi32>;
243def zextloadi32_a : AlignedLoad<zextloadi32>;
244def extloadi32_a : AlignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000245def truncstorei16_a : AlignedStore<truncstorei16>;
246def store_a : AlignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000247def truncstorei32_a : AlignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000248def sextloadi16_u : UnalignedLoad<sextloadi16>;
249def zextloadi16_u : UnalignedLoad<zextloadi16>;
250def extloadi16_u : UnalignedLoad<extloadi16>;
251def load_u : UnalignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000252def sextloadi32_u : UnalignedLoad<sextloadi32>;
253def zextloadi32_u : UnalignedLoad<zextloadi32>;
254def extloadi32_u : UnalignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000255def truncstorei16_u : UnalignedStore<truncstorei16>;
256def store_u : UnalignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000257def truncstorei32_u : UnalignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000258
259//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000260// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000261//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000262
Akira Hatanaka76d9f1c2011-10-11 23:12:12 +0000263// Arithmetic and logical instructions with 3 register operands.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000264class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
265 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
266 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
267 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
268 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
269 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000270 let isCommutable = isComm;
271}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000272
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000273class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000274 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
275 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
276 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
277 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000278 let isCommutable = isComm;
279}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000280
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000281// Arithmetic and logical instructions with 2 register operands.
282class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
283 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000284 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
285 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
286 [(set RC:$rt, (OpNode RC:$rs, imm_type:$imm16))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000287
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000288class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000289 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000290 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
291 !strconcat(instr_asm, "\t$rt, $rs, $imm16"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000292
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000293// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000294let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000295class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000296 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000297 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000298 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000299 let rd = 0;
300 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000301 let isCommutable = isComm;
302}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000303
304// Logical
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000305class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
306 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000307 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000308 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000309 let shamt = 0;
310 let isCommutable = 1;
311}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000312
313// Shifts
Akira Hatanaka36393462011-10-17 18:06:56 +0000314class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
315 SDNode OpNode, PatFrag PF, Operand ImmOpnd,
316 RegisterClass RC>:
317 FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000318 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
Akira Hatanaka36393462011-10-17 18:06:56 +0000319 [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
320 let rs = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000321}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000322
Akira Hatanaka36393462011-10-17 18:06:56 +0000323// 32-bit shift instructions.
324class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
325 SDNode OpNode>:
326 shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
327
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000328class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
329 SDNode OpNode, RegisterClass RC>:
330 FR<0x00, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000331 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000332 [(set RC:$rd, (OpNode RC:$rt, RC:$rs))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000333 let shamt = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000334}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000335
336// Load Upper Imediate
337class LoadUpper<bits<6> op, string instr_asm>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000338 FI<op, (outs CPURegs:$rt), (ins uimm16:$imm16),
339 !strconcat(instr_asm, "\t$rt, $imm16"), [], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000340 let rs = 0;
341}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000342
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000343class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
344 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> {
345 bits<21> addr;
346 let Inst{25-21} = addr{20-16};
347 let Inst{15-0} = addr{15-0};
348}
349
Eric Christopher3c999a22007-10-26 04:00:13 +0000350// Memory Load/Store
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000351let canFoldAsLoad = 1 in
Akira Hatanakad55bb382011-10-11 00:11:12 +0000352class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
353 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000354 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000355 !strconcat(instr_asm, "\t$rt, $addr"),
356 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000357 let isPseudo = Pseudo;
358}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000359
Akira Hatanakad55bb382011-10-11 00:11:12 +0000360class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
361 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000362 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000363 !strconcat(instr_asm, "\t$rt, $addr"),
364 [(OpNode RC:$rt, addr:$addr)], IIStore> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000365 let isPseudo = Pseudo;
366}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000367
Akira Hatanakad55bb382011-10-11 00:11:12 +0000368// 32-bit load.
369multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
370 bit Pseudo = 0> {
371 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
372 Requires<[NotN64]>;
373 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
374 Requires<[IsN64]>;
375}
376
377// 64-bit load.
378multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
379 bit Pseudo = 0> {
380 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
381 Requires<[NotN64]>;
382 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
383 Requires<[IsN64]>;
384}
385
386// 32-bit store.
387multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
388 bit Pseudo = 0> {
389 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
390 Requires<[NotN64]>;
391 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
392 Requires<[IsN64]>;
393}
394
395// 64-bit store.
396multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
397 bit Pseudo = 0> {
398 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
399 Requires<[NotN64]>;
400 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
401 Requires<[IsN64]>;
402}
403
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000404// Conditional Branch
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000405class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000406 CBranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$imm16),
407 !strconcat(instr_asm, "\t$rs, $rt, $imm16"),
408 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000409 let isBranch = 1;
410 let isTerminator = 1;
411 let hasDelaySlot = 1;
412}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000413
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000414class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
415 RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000416 CBranchBase<op, (outs), (ins RC:$rs, brtarget:$imm16),
417 !strconcat(instr_asm, "\t$rs, $imm16"),
418 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000419 let rt = _rt;
420 let isBranch = 1;
421 let isTerminator = 1;
422 let hasDelaySlot = 1;
Eric Christopher3c999a22007-10-26 04:00:13 +0000423}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000424
Eric Christopher3c999a22007-10-26 04:00:13 +0000425// SetCC
Akira Hatanaka8191f342011-10-11 18:53:46 +0000426class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
427 RegisterClass RC>:
428 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
429 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
430 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000431 IIAlu> {
432 let shamt = 0;
433}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000434
Akira Hatanaka8191f342011-10-11 18:53:46 +0000435class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
436 PatLeaf imm_type, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000437 FI<op, (outs CPURegs:$rt), (ins RC:$rs, Od:$imm16),
438 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
439 [(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000440 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000441
442// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000443let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000444class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000445 FJ<op, (outs), (ins brtarget:$target),
446 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000447
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000448let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000449class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000450 FR<op, func, (outs), (ins CPURegs:$rs),
451 !strconcat(instr_asm, "\t$rs"), [(brind CPURegs:$rs)], IIBranch> {
452 let rt = 0;
453 let rd = 0;
454 let shamt = 0;
455}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000456
457// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000458let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000459 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000460 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
461 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000462 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000463 FJ<op, (outs), (ins calltarget:$target, variable_ops),
464 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
465 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000466
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000467 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000468 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000469 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
470 let rt = 0;
471 let rd = 31;
472 let shamt = 0;
473 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000474
475 class BranchLink<string instr_asm>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000476 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$imm16, variable_ops),
477 !strconcat(instr_asm, "\t$rs, $imm16"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000478}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000479
Eric Christopher3c999a22007-10-26 04:00:13 +0000480// Mul, Div
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000481class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
482 RegisterClass RC, list<Register> DefRegs>:
483 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000484 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
485 let rd = 0;
486 let shamt = 0;
487 let isCommutable = 1;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000488 let Defs = DefRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000489}
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000490
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000491class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
492 Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
493
494class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
495 RegisterClass RC, list<Register> DefRegs>:
496 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
497 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
498 [(op RC:$rs, RC:$rt)], itin> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000499 let rd = 0;
500 let shamt = 0;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000501 let Defs = DefRegs;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000502}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000503
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000504class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
505 Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
506
Eric Christopher3c999a22007-10-26 04:00:13 +0000507// Move from Hi/Lo
Akira Hatanaka89d30662011-10-17 18:24:15 +0000508class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
509 list<Register> UseRegs>:
510 FR<0x00, func, (outs RC:$rd), (ins),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000511 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
512 let rs = 0;
513 let rt = 0;
514 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000515 let Uses = UseRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000516}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000517
Akira Hatanaka89d30662011-10-17 18:24:15 +0000518class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
519 list<Register> DefRegs>:
520 FR<0x00, func, (outs), (ins RC:$rs),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000521 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
522 let rt = 0;
523 let rd = 0;
524 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000525 let Defs = DefRegs;
Akira Hatanaka36787932011-10-03 19:28:44 +0000526}
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000527
Eric Christopher3c999a22007-10-26 04:00:13 +0000528class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000529 FMem<0x09, (outs CPURegs:$rt), (ins mem_ea:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000530 instr_asm, [(set CPURegs:$rt, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000531
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000532// Count Leading Ones/Zeros in Word
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000533class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
534 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
535 !strconcat(instr_asm, "\t$rd, $rs"),
536 [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
537 Requires<[HasBitCount]> {
538 let shamt = 0;
539 let rt = rd;
540}
541
542class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
543 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
544 !strconcat(instr_asm, "\t$rd, $rs"),
545 [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000546 Requires<[HasBitCount]> {
547 let shamt = 0;
548 let rt = rd;
549}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000550
551// Sign Extend in Register.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000552class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000553 FR<0x1f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000554 !strconcat(instr_asm, "\t$rd, $rt"),
555 [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
556 let rs = 0;
557 let shamt = sa;
558 let Predicates = [HasSEInReg];
559}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000560
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000561// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000562class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
563 FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
564 !strconcat(instr_asm, "\t$rd, $rt"),
565 [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
566 let rs = 0;
567 let shamt = sa;
568 let Predicates = [HasSwap];
569}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000570
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000571// Read Hardware
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000572class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$rt), (ins HWRegs:$rd),
573 "rdhwr\t$rt, $rd", [], IIAlu> {
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000574 let rs = 0;
575 let shamt = 0;
576}
577
Akira Hatanaka667645f2011-08-17 22:59:46 +0000578// Ext and Ins
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000579class ExtIns<bits<6> _funct, string instr_asm, dag outs, dag ins,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000580 list<dag> pattern, InstrItinClass itin>:
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000581 FR<0x1f, _funct, outs, ins, !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
Akira Hatanaka56633442011-09-20 23:53:09 +0000582 pattern, itin>, Requires<[HasMips32r2]> {
Akira Hatanaka667645f2011-08-17 22:59:46 +0000583 bits<5> pos;
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000584 bits<5> sz;
585 let rd = sz;
Akira Hatanaka667645f2011-08-17 22:59:46 +0000586 let shamt = pos;
587}
588
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000589// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
Akira Hatanakade9416e2011-07-20 00:53:09 +0000590class Atomic2Ops<PatFrag Op, string Opstr> :
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000591 MipsPseudo<(outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
592 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
593 [(set CPURegs:$dst,
594 (Op CPURegs:$ptr, CPURegs:$incr))]>;
595
596// Atomic Compare & Swap.
597class AtomicCmpSwap<PatFrag Op, string Width> :
598 MipsPseudo<(outs CPURegs:$dst),
599 (ins CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap),
600 !strconcat("atomic_cmp_swap_", Width,
601 "\t$dst, $ptr, $cmp, $swap"),
602 [(set CPURegs:$dst,
603 (Op CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap))]>;
604
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000605//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000606// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000607//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000608
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000609// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000610let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000611def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000612 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000613 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000614def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000615 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000616 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000617}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000618
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000619// Some assembly macros need to avoid pseudoinstructions and assembler
620// automatic reodering, we should reorder ourselves.
621def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
622def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
623def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
624def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
625
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000626// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000627// when using the AT register.
628def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
629def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
630
Eric Christopher3c999a22007-10-26 04:00:13 +0000631// When handling PIC code the assembler needs .cpload and .cprestore
632// directives. If the real instructions corresponding these directives
633// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000634// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000635def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanaka78d62b22011-07-07 22:06:18 +0000636def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000637
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000638let usesCustomInserter = 1 in {
Akira Hatanakade9416e2011-07-20 00:53:09 +0000639 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, "load_add_8">;
640 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, "load_add_16">;
641 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, "load_add_32">;
642 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, "load_sub_8">;
643 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, "load_sub_16">;
644 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, "load_sub_32">;
645 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, "load_and_8">;
646 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, "load_and_16">;
647 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, "load_and_32">;
648 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, "load_or_8">;
649 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, "load_or_16">;
650 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, "load_or_32">;
651 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, "load_xor_8">;
652 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, "load_xor_16">;
653 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, "load_xor_32">;
654 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, "load_nand_8">;
655 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, "load_nand_16">;
656 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, "load_nand_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000657
Akira Hatanakade9416e2011-07-20 00:53:09 +0000658 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, "swap_8">;
659 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, "swap_16">;
660 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, "swap_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000661
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000662 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, "8">;
663 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, "16">;
664 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, "32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000665}
666
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000667//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000668// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000669//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000670
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000671//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000672// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000673//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000674
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000675/// Arithmetic Instructions (ALU Immediate)
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000676def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
677def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000678def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
679def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000680def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
681def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
682def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000683def LUi : LoadUpper<0x0f, "lui">;
684
685/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000686def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
687def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000688def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
689def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000690def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
691def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000692def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
693def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
694def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000695def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000696
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000697/// Shift Instructions
Akira Hatanaka36393462011-10-17 18:06:56 +0000698def SLL : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
699def SRL : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
700def SRA : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000701def SLLV : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
702def SRLV : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
703def SRAV : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000704
705// Rotate Instructions
Akira Hatanaka56633442011-09-20 23:53:09 +0000706let Predicates = [HasMips32r2] in {
Akira Hatanaka36393462011-10-17 18:06:56 +0000707 def ROTR : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000708 def ROTRV : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000709}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000710
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000711/// Load and Store Instructions
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000712/// aligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000713defm LB : LoadM32<0x20, "lb", sextloadi8>;
714defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
715defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
716defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
717defm LW : LoadM32<0x23, "lw", load_a>;
718defm SB : StoreM32<0x28, "sb", truncstorei8>;
719defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
720defm SW : StoreM32<0x2b, "sw", store_a>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000721
722/// unaligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000723defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
724defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
725defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
726defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
727defm USW : StoreM32<0x2b, "usw", store_u, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000728
Akira Hatanakadb548262011-07-19 23:30:50 +0000729let hasSideEffects = 1 in
730def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000731 [(MipsSync imm:$stype)], NoItinerary, FrmOther>
Akira Hatanakadb548262011-07-19 23:30:50 +0000732{
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000733 bits<5> stype;
734 let Opcode = 0;
Akira Hatanakadb548262011-07-19 23:30:50 +0000735 let Inst{25-11} = 0;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000736 let Inst{10-6} = stype;
Akira Hatanakadb548262011-07-19 23:30:50 +0000737 let Inst{5-0} = 15;
738}
739
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000740/// Load-linked, Store-conditional
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000741let mayLoad = 1 in
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000742 def LL : FMem<0x30, (outs CPURegs:$rt), (ins mem:$addr),
743 "ll\t$rt, $addr", [], IILoad>;
744let mayStore = 1, Constraints = "$rt = $dst" in
745 def SC : FMem<0x38, (outs CPURegs:$dst), (ins CPURegs:$rt, mem:$addr),
746 "sc\t$rt, $addr", [], IIStore>;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000747
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000748/// Jump and Branch Instructions
749def J : JumpFJ<0x02, "j">;
Akira Hatanaka1f8d8222011-08-11 21:05:37 +0000750let isIndirectBranch = 1 in
751 def JR : JumpFR<0x00, 0x08, "jr">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000752def JAL : JumpLink<0x03, "jal">;
753def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000754def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
755def BNE : CBranch<0x05, "bne", setne, CPURegs>;
756def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
757def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000758def BLEZ : CBranchZero<0x06, 0, "blez", setle, CPURegs>;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000759def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000760
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000761let rt=0x11 in
762 def BGEZAL : BranchLink<"bgezal">;
763let rt=0x10 in
764 def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000765
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000766let isReturn=1, isTerminator=1, hasDelaySlot=1,
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000767 isBarrier=1, hasCtrlDep=1, rd=0, rt=0, shamt=0 in
768 def RET : FR <0x00, 0x08, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000769 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
770
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000771/// Multiply and Divide Instructions.
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000772def MULT : Mult32<0x18, "mult", IIImul>;
773def MULTu : Mult32<0x19, "multu", IIImul>;
774def SDIV : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
775def UDIV : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000776
Akira Hatanaka89d30662011-10-17 18:24:15 +0000777def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
778def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
779def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
780def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000781
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000782/// Sign Ext In Register Instructions.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000783def SEB : SignExtInReg<0x10, "seb", i8>;
784def SEH : SignExtInReg<0x18, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000785
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000786/// Count Leading
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000787def CLZ : CountLeading0<0x20, "clz", CPURegs>;
788def CLO : CountLeading1<0x21, "clo", CPURegs>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000789
790/// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000791def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000792
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000793/// No operation
794let addr=0 in
795 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
796
Eric Christopher3c999a22007-10-26 04:00:13 +0000797// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000798// instructions. The same not happens for stack address copies, so an
799// add op with mem ComplexPattern is used and the stack address copy
800// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000801def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000802
Akira Hatanaka21afc632011-06-21 00:40:49 +0000803// DynAlloc node points to dynamically allocated stack space.
804// $sp is added to the list of implicitly used registers to prevent dead code
805// elimination from removing instructions that modify $sp.
806let Uses = [SP] in
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000807def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr">;
Akira Hatanaka21afc632011-06-21 00:40:49 +0000808
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000809// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000810def MADD : MArithR<0, "madd", MipsMAdd, 1>;
811def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000812def MSUB : MArithR<4, "msub", MipsMSub>;
813def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000814
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000815// MUL is a assembly macro in the current used ISAs. In recent ISA's
816// it is a real instruction.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000817def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
818 Requires<[HasMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000819
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000820def RDHWR : ReadHardware;
821
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000822def EXT : ExtIns<0, "ext", (outs CPURegs:$rt),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000823 (ins CPURegs:$rs, uimm16:$pos, size_ext:$sz),
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000824 [(set CPURegs:$rt,
825 (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$sz))],
Akira Hatanaka667645f2011-08-17 22:59:46 +0000826 NoItinerary>;
827
828let Constraints = "$src = $rt" in
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000829def INS : ExtIns<4, "ins", (outs CPURegs:$rt),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000830 (ins CPURegs:$rs, uimm16:$pos, size_ins:$sz, CPURegs:$src),
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000831 [(set CPURegs:$rt,
832 (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$sz,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000833 CPURegs:$src))],
834 NoItinerary>;
Akira Hatanakabb15e112011-08-17 02:05:42 +0000835
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000836//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000837// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000838//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000839
840// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000841def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000842 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000843def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000844 (ORi ZERO, imm:$in)>;
845
846// Arbitrary immediates
847def : Pat<(i32 imm:$imm),
848 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
849
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000850// Carry patterns
851def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
852 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
853def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
854 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000855def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000856 (ADDiu CPURegs:$src, imm:$imm)>;
857
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000858// Call
859def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
860 (JAL tglobaladdr:$dst)>;
861def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
862 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000863//def : Pat<(MipsJmpLink CPURegs:$dst),
864// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000865
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000866// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000867def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000868def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000869def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
870def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000871def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000872 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000873def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
874 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000875
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000876def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000877def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000878def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
879 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000880
881def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000882def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000883def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
884 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
885
886// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000887def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000888 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000889def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000890 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000891
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000892// tlsgd
893def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
894 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
895
896// tprel hi/lo
897def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000898def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000899def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
900 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
901
Akira Hatanaka342837d2011-05-28 01:07:07 +0000902// wrapper_pic
903class WrapperPICPat<SDNode node>:
904 Pat<(MipsWrapperPIC node:$in),
905 (ADDiu GP, node:$in)>;
906
907def : WrapperPICPat<tglobaladdr>;
908def : WrapperPICPat<tconstpool>;
909def : WrapperPICPat<texternalsym>;
910def : WrapperPICPat<tblockaddress>;
911def : WrapperPICPat<tjumptable>;
912
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000913// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000914def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000915 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000916
Eric Christopher3c999a22007-10-26 04:00:13 +0000917// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000918def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
919def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000920def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
921def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000922
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000923// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000924def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
925
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000926// brcond patterns
Akira Hatanaka06f82312011-10-11 19:09:09 +0000927multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
928 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
929 Instruction SLTiuOp, Register ZEROReg> {
930def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
931 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
932def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
933 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000934
Akira Hatanaka06f82312011-10-11 19:09:09 +0000935def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
936 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
937def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
938 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
939def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
940 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
941def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
942 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000943
Akira Hatanaka06f82312011-10-11 19:09:09 +0000944def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
945 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
946def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
947 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000948
Akira Hatanaka06f82312011-10-11 19:09:09 +0000949def : Pat<(brcond RC:$cond, bb:$dst),
950 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
951}
952
953defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000954
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000955// setcc patterns
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000956multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
957 Instruction SLTuOp, Register ZEROReg> {
958 def : Pat<(seteq RC:$lhs, RC:$rhs),
959 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
960 def : Pat<(setne RC:$lhs, RC:$rhs),
961 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
962}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000963
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000964multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
965 def : Pat<(setle RC:$lhs, RC:$rhs),
966 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
967 def : Pat<(setule RC:$lhs, RC:$rhs),
968 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
969}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000970
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000971multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
972 def : Pat<(setgt RC:$lhs, RC:$rhs),
973 (SLTOp RC:$rhs, RC:$lhs)>;
974 def : Pat<(setugt RC:$lhs, RC:$rhs),
975 (SLTuOp RC:$rhs, RC:$lhs)>;
976}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000977
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000978multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
979 def : Pat<(setge RC:$lhs, RC:$rhs),
980 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
981 def : Pat<(setuge RC:$lhs, RC:$rhs),
982 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
983}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000984
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000985multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
986 Instruction SLTiuOp> {
987 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
988 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
989 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
990 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
991}
992
993defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
994defm : SetlePats<CPURegs, SLT, SLTu>;
995defm : SetgtPats<CPURegs, SLT, SLTu>;
996defm : SetgePats<CPURegs, SLT, SLTu>;
997defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000998
Akira Hatanaka21afc632011-06-21 00:40:49 +0000999// select MipsDynAlloc
1000def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1001
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001002//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001003// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001004//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001005
1006include "MipsInstrFPU.td"
Akira Hatanaka95934842011-09-24 01:34:44 +00001007include "Mips64InstrInfo.td"
Akira Hatanaka8ae330a2011-10-17 18:53:29 +00001008include "MipsCondMov.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001009