blob: 4cddd6b7fb9874c52d3df0daceb17eda7faed0d8 [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
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000141def jmptarget : Operand<OtherVT> {
142 let EncoderMethod = "getJumpTargetOpValue";
143}
144def brtarget : Operand<OtherVT> {
145 let EncoderMethod = "getBranchTargetOpValue";
146 let OperandType = "OPERAND_PCREL";
147}
Akira Hatanaka421455f2011-11-23 22:19:28 +0000148def calltarget : Operand<iPTR> {
149 let EncoderMethod = "getJumpTargetOpValue";
150}
Akira Hatanaka642b1092011-11-11 04:03:54 +0000151def calltarget64: Operand<i64>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000152def simm16 : Operand<i32>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000153def simm16_64 : Operand<i64>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000154def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000155
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000156// Unsigned Operand
157def uimm16 : Operand<i32> {
158 let PrintMethod = "printUnsignedImm";
159}
160
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000161// Address operand
162def mem : Operand<i32> {
163 let PrintMethod = "printMemOperand";
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000164 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000165 let EncoderMethod = "getMemEncoding";
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000166}
167
Akira Hatanakad55bb382011-10-11 00:11:12 +0000168def mem64 : Operand<i64> {
169 let PrintMethod = "printMemOperand";
170 let MIOperandInfo = (ops CPU64Regs, simm16_64);
171}
172
Akira Hatanaka03236be2011-07-07 20:54:20 +0000173def mem_ea : Operand<i32> {
174 let PrintMethod = "printMemOperandEA";
175 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000176 let EncoderMethod = "getMemEncoding";
177}
178
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000179def mem_ea_64 : Operand<i64> {
180 let PrintMethod = "printMemOperandEA";
181 let MIOperandInfo = (ops CPU64Regs, simm16_64);
182 let EncoderMethod = "getMemEncoding";
183}
184
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000185// size operand of ext instruction
186def size_ext : Operand<i32> {
187 let EncoderMethod = "getSizeExtEncoding";
188}
189
190// size operand of ins instruction
191def size_ins : Operand<i32> {
192 let EncoderMethod = "getSizeInsEncoding";
Akira Hatanaka03236be2011-07-07 20:54:20 +0000193}
194
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000195// Transformation Function - get the lower 16 bits.
196def LO16 : SDNodeXForm<imm, [{
Akira Hatanaka4d0eb632011-12-07 20:10:24 +0000197 return getImm(N, N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000198}]>;
199
200// Transformation Function - get the higher 16 bits.
201def HI16 : SDNodeXForm<imm, [{
Akira Hatanaka4d0eb632011-12-07 20:10:24 +0000202 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000203}]>;
204
205// Node immediate fits as 16-bit sign extended on target immediate.
206// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000207def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000208
209// Node immediate fits as 16-bit zero extended on target immediate.
210// The LO16 param means that only the lower 16 bits of the node
211// immediate are caught.
212// e.g. addiu, sltiu
213def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000214 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000215 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000216 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000217 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000218}], LO16>;
219
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000220// shamt field must fit in 5 bits.
Akira Hatanakaa01820a2011-10-17 18:01:00 +0000221def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000222
Eric Christopher3c999a22007-10-26 04:00:13 +0000223// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000224// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000225def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000226
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000227//===----------------------------------------------------------------------===//
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000228// Pattern fragment for load/store
229//===----------------------------------------------------------------------===//
230class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
231 LoadSDNode *LD = cast<LoadSDNode>(N);
232 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
233}]>;
234
235class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
236 LoadSDNode *LD = cast<LoadSDNode>(N);
237 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
238}]>;
239
240class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
241 (Node node:$val, node:$ptr), [{
242 StoreSDNode *SD = cast<StoreSDNode>(N);
243 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
244}]>;
245
246class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
247 (Node node:$val, node:$ptr), [{
248 StoreSDNode *SD = cast<StoreSDNode>(N);
249 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
250}]>;
251
252// Load/Store PatFrags.
253def sextloadi16_a : AlignedLoad<sextloadi16>;
254def zextloadi16_a : AlignedLoad<zextloadi16>;
255def extloadi16_a : AlignedLoad<extloadi16>;
256def load_a : AlignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000257def sextloadi32_a : AlignedLoad<sextloadi32>;
258def zextloadi32_a : AlignedLoad<zextloadi32>;
259def extloadi32_a : AlignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000260def truncstorei16_a : AlignedStore<truncstorei16>;
261def store_a : AlignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000262def truncstorei32_a : AlignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000263def sextloadi16_u : UnalignedLoad<sextloadi16>;
264def zextloadi16_u : UnalignedLoad<zextloadi16>;
265def extloadi16_u : UnalignedLoad<extloadi16>;
266def load_u : UnalignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000267def sextloadi32_u : UnalignedLoad<sextloadi32>;
268def zextloadi32_u : UnalignedLoad<zextloadi32>;
269def extloadi32_u : UnalignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000270def truncstorei16_u : UnalignedStore<truncstorei16>;
271def store_u : UnalignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000272def truncstorei32_u : UnalignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000273
274//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000275// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000276//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000277
Akira Hatanaka76d9f1c2011-10-11 23:12:12 +0000278// Arithmetic and logical instructions with 3 register operands.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000279class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
280 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
281 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
282 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
283 [(set RC:$rd, (OpNode RC:$rs, RC:$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 Hatanaka80eb9942011-10-11 23:43:48 +0000288class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000289 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
290 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
291 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
292 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000293 let isCommutable = isComm;
294}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000295
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000296// Arithmetic and logical instructions with 2 register operands.
297class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
298 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000299 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
300 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
301 [(set RC:$rt, (OpNode RC:$rs, imm_type:$imm16))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000302
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000303class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000304 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000305 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
306 !strconcat(instr_asm, "\t$rt, $rs, $imm16"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000307
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000308// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000309let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000310class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000311 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000312 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000313 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000314 let rd = 0;
315 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000316 let isCommutable = isComm;
317}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000318
319// Logical
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000320class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
321 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000322 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000323 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000324 let shamt = 0;
325 let isCommutable = 1;
326}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000327
328// Shifts
Akira Hatanaka36393462011-10-17 18:06:56 +0000329class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
330 SDNode OpNode, PatFrag PF, Operand ImmOpnd,
331 RegisterClass RC>:
332 FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000333 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
Akira Hatanaka36393462011-10-17 18:06:56 +0000334 [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
335 let rs = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000336}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000337
Akira Hatanaka36393462011-10-17 18:06:56 +0000338// 32-bit shift instructions.
339class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
340 SDNode OpNode>:
341 shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
342
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000343class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
344 SDNode OpNode, RegisterClass RC>:
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000345 FR<0x00, func, (outs RC:$rd), (ins CPURegs:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000346 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000347 [(set RC:$rd, (OpNode RC:$rt, CPURegs:$rs))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000348 let shamt = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000349}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000350
351// Load Upper Imediate
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000352class LoadUpper<bits<6> op, string instr_asm, RegisterClass RC, Operand Imm>:
353 FI<op, (outs RC:$rt), (ins Imm:$imm16),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000354 !strconcat(instr_asm, "\t$rt, $imm16"), [], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000355 let rs = 0;
356}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000357
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000358class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
359 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> {
360 bits<21> addr;
361 let Inst{25-21} = addr{20-16};
362 let Inst{15-0} = addr{15-0};
363}
364
Eric Christopher3c999a22007-10-26 04:00:13 +0000365// Memory Load/Store
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000366let canFoldAsLoad = 1 in
Akira Hatanakad55bb382011-10-11 00:11:12 +0000367class LoadM<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 RC:$rt), (ins MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000370 !strconcat(instr_asm, "\t$rt, $addr"),
371 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
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 +0000375class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
376 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000377 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000378 !strconcat(instr_asm, "\t$rt, $addr"),
379 [(OpNode RC:$rt, addr:$addr)], IIStore> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000380 let isPseudo = Pseudo;
381}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000382
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000383// Unaligned Memory Load/Store
Akira Hatanaka421455f2011-11-23 22:19:28 +0000384let canFoldAsLoad = 1 in
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000385class LoadUnAlign<bits<6> op, RegisterClass RC, Operand MemOpnd>:
386 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr), "", [], IILoad> {}
Akira Hatanaka421455f2011-11-23 22:19:28 +0000387
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000388class StoreUnAlign<bits<6> op, RegisterClass RC, Operand MemOpnd>:
389 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr), "", [], IIStore> {}
Akira Hatanaka421455f2011-11-23 22:19:28 +0000390
Akira Hatanakad55bb382011-10-11 00:11:12 +0000391// 32-bit load.
392multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
393 bit Pseudo = 0> {
394 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
395 Requires<[NotN64]>;
396 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
397 Requires<[IsN64]>;
398}
399
400// 64-bit load.
401multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
402 bit Pseudo = 0> {
403 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
404 Requires<[NotN64]>;
405 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
406 Requires<[IsN64]>;
407}
408
Akira Hatanaka421455f2011-11-23 22:19:28 +0000409// 32-bit load.
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000410multiclass LoadUnAlign32<bits<6> op> {
411 def #NAME# : LoadUnAlign<op, CPURegs, mem>,
Akira Hatanaka421455f2011-11-23 22:19:28 +0000412 Requires<[NotN64]>;
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000413 def _P8 : LoadUnAlign<op, CPURegs, mem64>,
Akira Hatanaka421455f2011-11-23 22:19:28 +0000414 Requires<[IsN64]>;
415}
Akira Hatanakad55bb382011-10-11 00:11:12 +0000416// 32-bit store.
417multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
418 bit Pseudo = 0> {
419 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
420 Requires<[NotN64]>;
421 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
422 Requires<[IsN64]>;
423}
424
425// 64-bit store.
426multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
427 bit Pseudo = 0> {
428 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
429 Requires<[NotN64]>;
430 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
431 Requires<[IsN64]>;
432}
433
Akira Hatanaka421455f2011-11-23 22:19:28 +0000434// 32-bit store.
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000435multiclass StoreUnAlign32<bits<6> op> {
436 def #NAME# : StoreUnAlign<op, CPURegs, mem>,
Akira Hatanaka421455f2011-11-23 22:19:28 +0000437 Requires<[NotN64]>;
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000438 def _P8 : StoreUnAlign<op, CPURegs, mem64>,
Akira Hatanaka421455f2011-11-23 22:19:28 +0000439 Requires<[IsN64]>;
440}
441
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000442// Conditional Branch
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000443class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000444 BranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$imm16),
445 !strconcat(instr_asm, "\t$rs, $rt, $imm16"),
446 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000447 let isBranch = 1;
448 let isTerminator = 1;
449 let hasDelaySlot = 1;
450}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000451
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000452class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
453 RegisterClass RC>:
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000454 BranchBase<op, (outs), (ins RC:$rs, brtarget:$imm16),
455 !strconcat(instr_asm, "\t$rs, $imm16"),
456 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000457 let rt = _rt;
458 let isBranch = 1;
459 let isTerminator = 1;
460 let hasDelaySlot = 1;
Eric Christopher3c999a22007-10-26 04:00:13 +0000461}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000462
Eric Christopher3c999a22007-10-26 04:00:13 +0000463// SetCC
Akira Hatanaka8191f342011-10-11 18:53:46 +0000464class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
465 RegisterClass RC>:
466 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
467 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
468 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000469 IIAlu> {
470 let shamt = 0;
471}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000472
Akira Hatanaka8191f342011-10-11 18:53:46 +0000473class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
474 PatLeaf imm_type, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000475 FI<op, (outs CPURegs:$rt), (ins RC:$rs, Od:$imm16),
476 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
477 [(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000478 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000479
480// Unconditional branch
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000481class UncondBranch<bits<6> op, string instr_asm>:
482 BranchBase<op, (outs), (ins brtarget:$imm16),
483 !strconcat(instr_asm, "\t$imm16"), [(br bb:$imm16)], IIBranch> {
484 let rs = 0;
485 let rt = 0;
486 let isBranch = 1;
487 let isTerminator = 1;
488 let isBarrier = 1;
489 let hasDelaySlot = 1;
490}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000491
Akira Hatanaka4fd40b32011-11-16 22:36:01 +0000492let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1,
493 isIndirectBranch = 1 in
494class JumpFR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
495 FR<op, func, (outs), (ins RC:$rs),
496 !strconcat(instr_asm, "\t$rs"), [(brind RC:$rs)], IIBranch> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000497 let rt = 0;
498 let rd = 0;
499 let shamt = 0;
500}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000501
502// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000503let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000504 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000505 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
506 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000507 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000508 FJ<op, (outs), (ins calltarget:$target, variable_ops),
509 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
510 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000511
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000512 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000513 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000514 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
515 let rt = 0;
516 let rd = 31;
517 let shamt = 0;
518 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000519
520 class BranchLink<string instr_asm>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000521 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$imm16, variable_ops),
522 !strconcat(instr_asm, "\t$rs, $imm16"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000523}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000524
Eric Christopher3c999a22007-10-26 04:00:13 +0000525// Mul, Div
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000526class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
527 RegisterClass RC, list<Register> DefRegs>:
528 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000529 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
530 let rd = 0;
531 let shamt = 0;
532 let isCommutable = 1;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000533 let Defs = DefRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000534}
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000535
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000536class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
537 Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
538
539class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
540 RegisterClass RC, list<Register> DefRegs>:
541 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
542 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
543 [(op RC:$rs, RC:$rt)], itin> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000544 let rd = 0;
545 let shamt = 0;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000546 let Defs = DefRegs;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000547}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000548
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000549class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
550 Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
551
Eric Christopher3c999a22007-10-26 04:00:13 +0000552// Move from Hi/Lo
Akira Hatanaka89d30662011-10-17 18:24:15 +0000553class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
554 list<Register> UseRegs>:
555 FR<0x00, func, (outs RC:$rd), (ins),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000556 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
557 let rs = 0;
558 let rt = 0;
559 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000560 let Uses = UseRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000561}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000562
Akira Hatanaka89d30662011-10-17 18:24:15 +0000563class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
564 list<Register> DefRegs>:
565 FR<0x00, func, (outs), (ins RC:$rs),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000566 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
567 let rt = 0;
568 let rd = 0;
569 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000570 let Defs = DefRegs;
Akira Hatanaka36787932011-10-03 19:28:44 +0000571}
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000572
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000573class EffectiveAddress<string instr_asm, RegisterClass RC, Operand Mem> :
574 FMem<0x09, (outs RC:$rt), (ins Mem:$addr),
575 instr_asm, [(set RC:$rt, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000576
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000577// Count Leading Ones/Zeros in Word
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000578class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
579 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
580 !strconcat(instr_asm, "\t$rd, $rs"),
581 [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
582 Requires<[HasBitCount]> {
583 let shamt = 0;
584 let rt = rd;
585}
586
587class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
588 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
589 !strconcat(instr_asm, "\t$rd, $rs"),
590 [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000591 Requires<[HasBitCount]> {
592 let shamt = 0;
593 let rt = rd;
594}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000595
596// Sign Extend in Register.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000597class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000598 FR<0x1f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000599 !strconcat(instr_asm, "\t$rd, $rt"),
600 [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
601 let rs = 0;
602 let shamt = sa;
603 let Predicates = [HasSEInReg];
604}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000605
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000606// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000607class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
608 FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
609 !strconcat(instr_asm, "\t$rd, $rt"),
610 [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
611 let rs = 0;
612 let shamt = sa;
613 let Predicates = [HasSwap];
614}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000615
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000616// Read Hardware
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000617class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$rt), (ins HWRegs:$rd),
618 "rdhwr\t$rt, $rd", [], IIAlu> {
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000619 let rs = 0;
620 let shamt = 0;
621}
622
Akira Hatanaka667645f2011-08-17 22:59:46 +0000623// Ext and Ins
Akira Hatanakacee46ab2011-12-05 21:14:28 +0000624class ExtBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
625 FR<0x1f, _funct, (outs RC:$rt), (ins RC:$rs, uimm16:$pos, size_ext:$sz),
626 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
627 [(set RC:$rt, (MipsExt RC:$rs, imm:$pos, imm:$sz))], NoItinerary> {
Akira Hatanaka667645f2011-08-17 22:59:46 +0000628 bits<5> pos;
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000629 bits<5> sz;
630 let rd = sz;
Akira Hatanaka667645f2011-08-17 22:59:46 +0000631 let shamt = pos;
Akira Hatanakacee46ab2011-12-05 21:14:28 +0000632 let Predicates = [HasMips32r2];
633}
634
635class InsBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
636 FR<0x1f, _funct, (outs RC:$rt),
637 (ins RC:$rs, uimm16:$pos, size_ins:$sz, RC:$src),
638 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
639 [(set RC:$rt, (MipsIns RC:$rs, imm:$pos, imm:$sz, RC:$src))],
640 NoItinerary> {
641 bits<5> pos;
642 bits<5> sz;
643 let rd = sz;
644 let shamt = pos;
645 let Predicates = [HasMips32r2];
646 let Constraints = "$src = $rt";
Akira Hatanaka667645f2011-08-17 22:59:46 +0000647}
648
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000649// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
Akira Hatanaka59068062011-11-11 04:14:30 +0000650class Atomic2Ops<PatFrag Op, string Opstr, RegisterClass DRC,
651 RegisterClass PRC> :
652 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$incr),
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000653 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
Akira Hatanaka59068062011-11-11 04:14:30 +0000654 [(set DRC:$dst, (Op PRC:$ptr, DRC:$incr))]>;
655
656multiclass Atomic2Ops32<PatFrag Op, string Opstr> {
657 def #NAME# : Atomic2Ops<Op, Opstr, CPURegs, CPURegs>, Requires<[NotN64]>;
658 def _P8 : Atomic2Ops<Op, Opstr, CPURegs, CPU64Regs>, Requires<[IsN64]>;
659}
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000660
661// Atomic Compare & Swap.
Akira Hatanaka59068062011-11-11 04:14:30 +0000662class AtomicCmpSwap<PatFrag Op, string Width, RegisterClass DRC,
663 RegisterClass PRC> :
664 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$cmp, DRC:$swap),
665 !strconcat("atomic_cmp_swap_", Width, "\t$dst, $ptr, $cmp, $swap"),
666 [(set DRC:$dst, (Op PRC:$ptr, DRC:$cmp, DRC:$swap))]>;
667
668multiclass AtomicCmpSwap32<PatFrag Op, string Width> {
669 def #NAME# : AtomicCmpSwap<Op, Width, CPURegs, CPURegs>, Requires<[NotN64]>;
670 def _P8 : AtomicCmpSwap<Op, Width, CPURegs, CPU64Regs>, Requires<[IsN64]>;
671}
672
673class LLBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
674 FMem<Opc, (outs RC:$rt), (ins Mem:$addr),
675 !strconcat(opstring, "\t$rt, $addr"), [], IILoad> {
676 let mayLoad = 1;
677}
678
679class SCBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
680 FMem<Opc, (outs RC:$dst), (ins RC:$rt, Mem:$addr),
681 !strconcat(opstring, "\t$rt, $addr"), [], IIStore> {
682 let mayStore = 1;
683 let Constraints = "$rt = $dst";
684}
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000685
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000686//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000687// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000688//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000689
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000690// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000691let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000692def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000693 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000694 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000695def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000696 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000697 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000698}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000699
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000700// Some assembly macros need to avoid pseudoinstructions and assembler
701// automatic reodering, we should reorder ourselves.
702def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
703def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
704def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
705def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
706
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000707// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000708// when using the AT register.
709def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
710def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
711
Eric Christopher3c999a22007-10-26 04:00:13 +0000712// When handling PIC code the assembler needs .cpload and .cprestore
713// directives. If the real instructions corresponding these directives
714// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000715// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000716def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanaka78d62b22011-07-07 22:06:18 +0000717def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000718
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000719let usesCustomInserter = 1 in {
Akira Hatanaka59068062011-11-11 04:14:30 +0000720 defm ATOMIC_LOAD_ADD_I8 : Atomic2Ops32<atomic_load_add_8, "load_add_8">;
721 defm ATOMIC_LOAD_ADD_I16 : Atomic2Ops32<atomic_load_add_16, "load_add_16">;
722 defm ATOMIC_LOAD_ADD_I32 : Atomic2Ops32<atomic_load_add_32, "load_add_32">;
723 defm ATOMIC_LOAD_SUB_I8 : Atomic2Ops32<atomic_load_sub_8, "load_sub_8">;
724 defm ATOMIC_LOAD_SUB_I16 : Atomic2Ops32<atomic_load_sub_16, "load_sub_16">;
725 defm ATOMIC_LOAD_SUB_I32 : Atomic2Ops32<atomic_load_sub_32, "load_sub_32">;
726 defm ATOMIC_LOAD_AND_I8 : Atomic2Ops32<atomic_load_and_8, "load_and_8">;
727 defm ATOMIC_LOAD_AND_I16 : Atomic2Ops32<atomic_load_and_16, "load_and_16">;
728 defm ATOMIC_LOAD_AND_I32 : Atomic2Ops32<atomic_load_and_32, "load_and_32">;
729 defm ATOMIC_LOAD_OR_I8 : Atomic2Ops32<atomic_load_or_8, "load_or_8">;
730 defm ATOMIC_LOAD_OR_I16 : Atomic2Ops32<atomic_load_or_16, "load_or_16">;
731 defm ATOMIC_LOAD_OR_I32 : Atomic2Ops32<atomic_load_or_32, "load_or_32">;
732 defm ATOMIC_LOAD_XOR_I8 : Atomic2Ops32<atomic_load_xor_8, "load_xor_8">;
733 defm ATOMIC_LOAD_XOR_I16 : Atomic2Ops32<atomic_load_xor_16, "load_xor_16">;
734 defm ATOMIC_LOAD_XOR_I32 : Atomic2Ops32<atomic_load_xor_32, "load_xor_32">;
735 defm ATOMIC_LOAD_NAND_I8 : Atomic2Ops32<atomic_load_nand_8, "load_nand_8">;
736 defm ATOMIC_LOAD_NAND_I16 : Atomic2Ops32<atomic_load_nand_16, "load_nand_16">;
737 defm ATOMIC_LOAD_NAND_I32 : Atomic2Ops32<atomic_load_nand_32, "load_nand_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000738
Akira Hatanaka59068062011-11-11 04:14:30 +0000739 defm ATOMIC_SWAP_I8 : Atomic2Ops32<atomic_swap_8, "swap_8">;
740 defm ATOMIC_SWAP_I16 : Atomic2Ops32<atomic_swap_16, "swap_16">;
741 defm ATOMIC_SWAP_I32 : Atomic2Ops32<atomic_swap_32, "swap_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000742
Akira Hatanaka59068062011-11-11 04:14:30 +0000743 defm ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap32<atomic_cmp_swap_8, "8">;
744 defm ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap32<atomic_cmp_swap_16, "16">;
745 defm ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap32<atomic_cmp_swap_32, "32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000746}
747
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000748//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000749// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000750//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000751
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000752//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000753// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000754//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000755
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000756/// Arithmetic Instructions (ALU Immediate)
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000757def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
758def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000759def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
760def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000761def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
762def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
763def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000764def LUi : LoadUpper<0x0f, "lui", CPURegs, uimm16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000765
766/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000767def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
768def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000769def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
770def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000771def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
772def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000773def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
774def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
775def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000776def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000777
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000778/// Shift Instructions
Akira Hatanaka36393462011-10-17 18:06:56 +0000779def SLL : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
780def SRL : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
781def SRA : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000782def SLLV : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
783def SRLV : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
784def SRAV : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000785
786// Rotate Instructions
Akira Hatanaka56633442011-09-20 23:53:09 +0000787let Predicates = [HasMips32r2] in {
Akira Hatanaka36393462011-10-17 18:06:56 +0000788 def ROTR : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000789 def ROTRV : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000790}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000791
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000792/// Load and Store Instructions
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000793/// aligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000794defm LB : LoadM32<0x20, "lb", sextloadi8>;
795defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
796defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
797defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
798defm LW : LoadM32<0x23, "lw", load_a>;
799defm SB : StoreM32<0x28, "sb", truncstorei8>;
800defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
801defm SW : StoreM32<0x2b, "sw", store_a>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000802
803/// unaligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000804defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
805defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
806defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
807defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
808defm USW : StoreM32<0x2b, "usw", store_u, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000809
Akira Hatanaka421455f2011-11-23 22:19:28 +0000810/// Primitives for unaligned
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000811defm LWL : LoadUnAlign32<0x22>;
812defm LWR : LoadUnAlign32<0x26>;
813defm SWL : StoreUnAlign32<0x2A>;
814defm SWR : StoreUnAlign32<0x2E>;
Akira Hatanaka421455f2011-11-23 22:19:28 +0000815
Akira Hatanakadb548262011-07-19 23:30:50 +0000816let hasSideEffects = 1 in
817def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000818 [(MipsSync imm:$stype)], NoItinerary, FrmOther>
Akira Hatanakadb548262011-07-19 23:30:50 +0000819{
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000820 bits<5> stype;
821 let Opcode = 0;
Akira Hatanakadb548262011-07-19 23:30:50 +0000822 let Inst{25-11} = 0;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000823 let Inst{10-6} = stype;
Akira Hatanakadb548262011-07-19 23:30:50 +0000824 let Inst{5-0} = 15;
825}
826
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000827/// Load-linked, Store-conditional
Akira Hatanaka59068062011-11-11 04:14:30 +0000828def LL : LLBase<0x30, "ll", CPURegs, mem>, Requires<[NotN64]>;
829def LL_P8 : LLBase<0x30, "ll", CPURegs, mem64>, Requires<[IsN64]>;
830def SC : SCBase<0x38, "sc", CPURegs, mem>, Requires<[NotN64]>;
831def SC_P8 : SCBase<0x38, "sc", CPURegs, mem64>, Requires<[IsN64]>;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000832
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000833/// Jump and Branch Instructions
Akira Hatanaka4fd40b32011-11-16 22:36:01 +0000834def JR : JumpFR<0x00, 0x08, "jr", CPURegs>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000835def JAL : JumpLink<0x03, "jal">;
836def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopesff452f52011-12-06 03:34:48 +0000837def B : UncondBranch<0x04, "b">;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000838def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
839def BNE : CBranch<0x05, "bne", setne, CPURegs>;
840def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
841def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000842def BLEZ : CBranchZero<0x06, 0, "blez", setle, CPURegs>;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000843def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000844
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000845let rt=0x11 in
846 def BGEZAL : BranchLink<"bgezal">;
847let rt=0x10 in
848 def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000849
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000850let isReturn=1, isTerminator=1, hasDelaySlot=1,
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000851 isBarrier=1, hasCtrlDep=1, rd=0, rt=0, shamt=0 in
852 def RET : FR <0x00, 0x08, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000853 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
854
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000855/// Multiply and Divide Instructions.
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000856def MULT : Mult32<0x18, "mult", IIImul>;
857def MULTu : Mult32<0x19, "multu", IIImul>;
858def SDIV : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
859def UDIV : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000860
Akira Hatanaka89d30662011-10-17 18:24:15 +0000861def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
862def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
863def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
864def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000865
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000866/// Sign Ext In Register Instructions.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000867def SEB : SignExtInReg<0x10, "seb", i8>;
868def SEH : SignExtInReg<0x18, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000869
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000870/// Count Leading
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000871def CLZ : CountLeading0<0x20, "clz", CPURegs>;
872def CLO : CountLeading1<0x21, "clo", CPURegs>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000873
874/// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000875def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000876
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000877/// No operation
878let addr=0 in
879 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
880
Eric Christopher3c999a22007-10-26 04:00:13 +0000881// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000882// instructions. The same not happens for stack address copies, so an
883// add op with mem ComplexPattern is used and the stack address copy
884// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000885def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000886
Akira Hatanaka21afc632011-06-21 00:40:49 +0000887// DynAlloc node points to dynamically allocated stack space.
888// $sp is added to the list of implicitly used registers to prevent dead code
889// elimination from removing instructions that modify $sp.
890let Uses = [SP] in
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000891def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
Akira Hatanaka21afc632011-06-21 00:40:49 +0000892
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000893// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000894def MADD : MArithR<0, "madd", MipsMAdd, 1>;
895def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000896def MSUB : MArithR<4, "msub", MipsMSub>;
897def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000898
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000899// MUL is a assembly macro in the current used ISAs. In recent ISA's
900// it is a real instruction.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000901def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
902 Requires<[HasMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000903
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000904def RDHWR : ReadHardware;
905
Akira Hatanakacee46ab2011-12-05 21:14:28 +0000906def EXT : ExtBase<0, "ext", CPURegs>;
907def INS : InsBase<4, "ins", CPURegs>;
Akira Hatanakabb15e112011-08-17 02:05:42 +0000908
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000909//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000910// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000911//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000912
913// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000914def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000915 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000916def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000917 (ORi ZERO, imm:$in)>;
918
919// Arbitrary immediates
920def : Pat<(i32 imm:$imm),
921 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
922
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000923// Carry patterns
924def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
925 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
926def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
927 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000928def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000929 (ADDiu CPURegs:$src, imm:$imm)>;
930
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000931// Call
932def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
933 (JAL tglobaladdr:$dst)>;
934def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
935 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000936//def : Pat<(MipsJmpLink CPURegs:$dst),
937// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000938
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000939// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000940def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000941def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Akira Hatanaka74c76342011-11-16 22:39:56 +0000942def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
943def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
944
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000945def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
946def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
Akira Hatanaka74c76342011-11-16 22:39:56 +0000947def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
948def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
949
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000950def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000951 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000952def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
953 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000954def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
955 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000956def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
957 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
958
959// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000960def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000961 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000962def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000963 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000964
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000965// tlsgd
966def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
967 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
968
969// tprel hi/lo
970def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000971def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000972def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
973 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
974
Akira Hatanaka342837d2011-05-28 01:07:07 +0000975// wrapper_pic
976class WrapperPICPat<SDNode node>:
977 Pat<(MipsWrapperPIC node:$in),
978 (ADDiu GP, node:$in)>;
979
980def : WrapperPICPat<tglobaladdr>;
981def : WrapperPICPat<tconstpool>;
982def : WrapperPICPat<texternalsym>;
983def : WrapperPICPat<tblockaddress>;
984def : WrapperPICPat<tjumptable>;
985
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000986// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000987def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000988 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000989
Eric Christopher3c999a22007-10-26 04:00:13 +0000990// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000991def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
992def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000993def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
994def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000995
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000996// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000997def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
998
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000999// brcond patterns
Akira Hatanaka06f82312011-10-11 19:09:09 +00001000multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
1001 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
1002 Instruction SLTiuOp, Register ZEROReg> {
1003def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
1004 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
1005def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
1006 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +00001007
Akira Hatanaka06f82312011-10-11 19:09:09 +00001008def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
1009 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1010def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
1011 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1012def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1013 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1014def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1015 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001016
Akira Hatanaka06f82312011-10-11 19:09:09 +00001017def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
1018 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1019def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
1020 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001021
Akira Hatanaka06f82312011-10-11 19:09:09 +00001022def : Pat<(brcond RC:$cond, bb:$dst),
1023 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
1024}
1025
1026defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001027
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +00001028// setcc patterns
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001029multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
1030 Instruction SLTuOp, Register ZEROReg> {
1031 def : Pat<(seteq RC:$lhs, RC:$rhs),
1032 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
1033 def : Pat<(setne RC:$lhs, RC:$rhs),
1034 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
1035}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +00001036
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001037multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1038 def : Pat<(setle RC:$lhs, RC:$rhs),
1039 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
1040 def : Pat<(setule RC:$lhs, RC:$rhs),
1041 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
1042}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001043
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001044multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1045 def : Pat<(setgt RC:$lhs, RC:$rhs),
1046 (SLTOp RC:$rhs, RC:$lhs)>;
1047 def : Pat<(setugt RC:$lhs, RC:$rhs),
1048 (SLTuOp RC:$rhs, RC:$lhs)>;
1049}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001050
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001051multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1052 def : Pat<(setge RC:$lhs, RC:$rhs),
1053 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
1054 def : Pat<(setuge RC:$lhs, RC:$rhs),
1055 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
1056}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001057
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001058multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
1059 Instruction SLTiuOp> {
1060 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
1061 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
1062 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
1063 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1064}
1065
1066defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
1067defm : SetlePats<CPURegs, SLT, SLTu>;
1068defm : SetgtPats<CPURegs, SLT, SLTu>;
1069defm : SetgePats<CPURegs, SLT, SLTu>;
1070defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001071
Akira Hatanaka21afc632011-06-21 00:40:49 +00001072// select MipsDynAlloc
1073def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1074
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001075//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001076// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001077//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001078
1079include "MipsInstrFPU.td"
Akira Hatanaka95934842011-09-24 01:34:44 +00001080include "Mips64InstrInfo.td"
Akira Hatanaka8ae330a2011-10-17 18:53:29 +00001081include "MipsCondMov.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001082