blob: 73de312f7f946c73735fe284a8ec81f6c78e9db1 [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}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000148def calltarget : Operand<i32>;
Akira Hatanaka642b1092011-11-11 04:03:54 +0000149def calltarget64: Operand<i64>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000150def simm16 : Operand<i32>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000151def simm16_64 : Operand<i64>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000152def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000153
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000154// Unsigned Operand
155def uimm16 : Operand<i32> {
156 let PrintMethod = "printUnsignedImm";
157}
158
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000159// Address operand
160def mem : Operand<i32> {
161 let PrintMethod = "printMemOperand";
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000162 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000163 let EncoderMethod = "getMemEncoding";
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000164}
165
Akira Hatanakad55bb382011-10-11 00:11:12 +0000166def mem64 : Operand<i64> {
167 let PrintMethod = "printMemOperand";
168 let MIOperandInfo = (ops CPU64Regs, simm16_64);
169}
170
Akira Hatanaka03236be2011-07-07 20:54:20 +0000171def mem_ea : Operand<i32> {
172 let PrintMethod = "printMemOperandEA";
173 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000174 let EncoderMethod = "getMemEncoding";
175}
176
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000177def mem_ea_64 : Operand<i64> {
178 let PrintMethod = "printMemOperandEA";
179 let MIOperandInfo = (ops CPU64Regs, simm16_64);
180 let EncoderMethod = "getMemEncoding";
181}
182
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000183// size operand of ext instruction
184def size_ext : Operand<i32> {
185 let EncoderMethod = "getSizeExtEncoding";
186}
187
188// size operand of ins instruction
189def size_ins : Operand<i32> {
190 let EncoderMethod = "getSizeInsEncoding";
Akira Hatanaka03236be2011-07-07 20:54:20 +0000191}
192
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000193// Transformation Function - get the lower 16 bits.
194def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000195 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000196}]>;
197
198// Transformation Function - get the higher 16 bits.
199def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000200 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000201}]>;
202
203// Node immediate fits as 16-bit sign extended on target immediate.
204// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000205def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000206
207// Node immediate fits as 16-bit zero extended on target immediate.
208// The LO16 param means that only the lower 16 bits of the node
209// immediate are caught.
210// e.g. addiu, sltiu
211def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000212 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000213 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000214 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000215 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000216}], LO16>;
217
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000218// shamt field must fit in 5 bits.
Akira Hatanakaa01820a2011-10-17 18:01:00 +0000219def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000220
Eric Christopher3c999a22007-10-26 04:00:13 +0000221// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000222// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000223def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000224
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000225//===----------------------------------------------------------------------===//
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000226// Pattern fragment for load/store
227//===----------------------------------------------------------------------===//
228class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
229 LoadSDNode *LD = cast<LoadSDNode>(N);
230 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
231}]>;
232
233class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
234 LoadSDNode *LD = cast<LoadSDNode>(N);
235 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
236}]>;
237
238class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
239 (Node node:$val, node:$ptr), [{
240 StoreSDNode *SD = cast<StoreSDNode>(N);
241 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
242}]>;
243
244class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
245 (Node node:$val, node:$ptr), [{
246 StoreSDNode *SD = cast<StoreSDNode>(N);
247 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
248}]>;
249
250// Load/Store PatFrags.
251def sextloadi16_a : AlignedLoad<sextloadi16>;
252def zextloadi16_a : AlignedLoad<zextloadi16>;
253def extloadi16_a : AlignedLoad<extloadi16>;
254def load_a : AlignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000255def sextloadi32_a : AlignedLoad<sextloadi32>;
256def zextloadi32_a : AlignedLoad<zextloadi32>;
257def extloadi32_a : AlignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000258def truncstorei16_a : AlignedStore<truncstorei16>;
259def store_a : AlignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000260def truncstorei32_a : AlignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000261def sextloadi16_u : UnalignedLoad<sextloadi16>;
262def zextloadi16_u : UnalignedLoad<zextloadi16>;
263def extloadi16_u : UnalignedLoad<extloadi16>;
264def load_u : UnalignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000265def sextloadi32_u : UnalignedLoad<sextloadi32>;
266def zextloadi32_u : UnalignedLoad<zextloadi32>;
267def extloadi32_u : UnalignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000268def truncstorei16_u : UnalignedStore<truncstorei16>;
269def store_u : UnalignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000270def truncstorei32_u : UnalignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000271
272//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000273// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000274//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000275
Akira Hatanaka76d9f1c2011-10-11 23:12:12 +0000276// Arithmetic and logical instructions with 3 register operands.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000277class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
278 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
279 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
280 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
281 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
282 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000283 let isCommutable = isComm;
284}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000285
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000286class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000287 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
288 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
289 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
290 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000291 let isCommutable = isComm;
292}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000293
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000294// Arithmetic and logical instructions with 2 register operands.
295class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
296 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000297 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
298 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
299 [(set RC:$rt, (OpNode RC:$rs, imm_type:$imm16))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000300
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000301class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000302 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000303 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
304 !strconcat(instr_asm, "\t$rt, $rs, $imm16"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000305
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000306// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000307let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000308class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000309 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000310 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000311 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000312 let rd = 0;
313 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000314 let isCommutable = isComm;
315}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000316
317// Logical
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000318class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
319 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000320 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000321 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000322 let shamt = 0;
323 let isCommutable = 1;
324}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000325
326// Shifts
Akira Hatanaka36393462011-10-17 18:06:56 +0000327class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
328 SDNode OpNode, PatFrag PF, Operand ImmOpnd,
329 RegisterClass RC>:
330 FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000331 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
Akira Hatanaka36393462011-10-17 18:06:56 +0000332 [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
333 let rs = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000334}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000335
Akira Hatanaka36393462011-10-17 18:06:56 +0000336// 32-bit shift instructions.
337class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
338 SDNode OpNode>:
339 shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
340
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000341class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
342 SDNode OpNode, RegisterClass RC>:
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000343 FR<0x00, func, (outs RC:$rd), (ins CPURegs:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000344 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000345 [(set RC:$rd, (OpNode RC:$rt, CPURegs:$rs))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000346 let shamt = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000347}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000348
349// Load Upper Imediate
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000350class LoadUpper<bits<6> op, string instr_asm, RegisterClass RC, Operand Imm>:
351 FI<op, (outs RC:$rt), (ins Imm:$imm16),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000352 !strconcat(instr_asm, "\t$rt, $imm16"), [], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000353 let rs = 0;
354}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000355
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000356class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
357 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> {
358 bits<21> addr;
359 let Inst{25-21} = addr{20-16};
360 let Inst{15-0} = addr{15-0};
361}
362
Eric Christopher3c999a22007-10-26 04:00:13 +0000363// Memory Load/Store
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000364let canFoldAsLoad = 1 in
Akira Hatanakad55bb382011-10-11 00:11:12 +0000365class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
366 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000367 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000368 !strconcat(instr_asm, "\t$rt, $addr"),
369 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000370 let isPseudo = Pseudo;
371}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000372
Akira Hatanakad55bb382011-10-11 00:11:12 +0000373class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
374 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000375 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000376 !strconcat(instr_asm, "\t$rt, $addr"),
377 [(OpNode RC:$rt, addr:$addr)], IIStore> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000378 let isPseudo = Pseudo;
379}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000380
Akira Hatanakad55bb382011-10-11 00:11:12 +0000381// 32-bit load.
382multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
383 bit Pseudo = 0> {
384 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
385 Requires<[NotN64]>;
386 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
387 Requires<[IsN64]>;
388}
389
390// 64-bit load.
391multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
392 bit Pseudo = 0> {
393 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
394 Requires<[NotN64]>;
395 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
396 Requires<[IsN64]>;
397}
398
399// 32-bit store.
400multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
401 bit Pseudo = 0> {
402 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
403 Requires<[NotN64]>;
404 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
405 Requires<[IsN64]>;
406}
407
408// 64-bit store.
409multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
410 bit Pseudo = 0> {
411 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
412 Requires<[NotN64]>;
413 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
414 Requires<[IsN64]>;
415}
416
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000417// Conditional Branch
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000418class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000419 CBranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$imm16),
420 !strconcat(instr_asm, "\t$rs, $rt, $imm16"),
421 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000422 let isBranch = 1;
423 let isTerminator = 1;
424 let hasDelaySlot = 1;
425}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000426
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000427class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
428 RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000429 CBranchBase<op, (outs), (ins RC:$rs, brtarget:$imm16),
430 !strconcat(instr_asm, "\t$rs, $imm16"),
431 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000432 let rt = _rt;
433 let isBranch = 1;
434 let isTerminator = 1;
435 let hasDelaySlot = 1;
Eric Christopher3c999a22007-10-26 04:00:13 +0000436}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000437
Eric Christopher3c999a22007-10-26 04:00:13 +0000438// SetCC
Akira Hatanaka8191f342011-10-11 18:53:46 +0000439class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
440 RegisterClass RC>:
441 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
442 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
443 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000444 IIAlu> {
445 let shamt = 0;
446}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000447
Akira Hatanaka8191f342011-10-11 18:53:46 +0000448class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
449 PatLeaf imm_type, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000450 FI<op, (outs CPURegs:$rt), (ins RC:$rs, Od:$imm16),
451 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
452 [(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000453 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000454
455// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000456let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000457class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000458 FJ<op, (outs), (ins jmptarget:$target),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000459 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000460
Akira Hatanaka4fd40b32011-11-16 22:36:01 +0000461let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1,
462 isIndirectBranch = 1 in
463class JumpFR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
464 FR<op, func, (outs), (ins RC:$rs),
465 !strconcat(instr_asm, "\t$rs"), [(brind RC:$rs)], IIBranch> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000466 let rt = 0;
467 let rd = 0;
468 let shamt = 0;
469}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000470
471// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000472let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000473 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000474 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
475 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000476 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000477 FJ<op, (outs), (ins calltarget:$target, variable_ops),
478 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
479 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000480
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000481 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000482 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000483 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
484 let rt = 0;
485 let rd = 31;
486 let shamt = 0;
487 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000488
489 class BranchLink<string instr_asm>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000490 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$imm16, variable_ops),
491 !strconcat(instr_asm, "\t$rs, $imm16"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000492}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000493
Eric Christopher3c999a22007-10-26 04:00:13 +0000494// Mul, Div
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000495class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
496 RegisterClass RC, list<Register> DefRegs>:
497 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000498 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
499 let rd = 0;
500 let shamt = 0;
501 let isCommutable = 1;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000502 let Defs = DefRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000503}
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000504
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000505class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
506 Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
507
508class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
509 RegisterClass RC, list<Register> DefRegs>:
510 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
511 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
512 [(op RC:$rs, RC:$rt)], itin> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000513 let rd = 0;
514 let shamt = 0;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000515 let Defs = DefRegs;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000516}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000517
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000518class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
519 Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
520
Eric Christopher3c999a22007-10-26 04:00:13 +0000521// Move from Hi/Lo
Akira Hatanaka89d30662011-10-17 18:24:15 +0000522class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
523 list<Register> UseRegs>:
524 FR<0x00, func, (outs RC:$rd), (ins),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000525 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
526 let rs = 0;
527 let rt = 0;
528 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000529 let Uses = UseRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000530}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000531
Akira Hatanaka89d30662011-10-17 18:24:15 +0000532class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
533 list<Register> DefRegs>:
534 FR<0x00, func, (outs), (ins RC:$rs),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000535 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
536 let rt = 0;
537 let rd = 0;
538 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000539 let Defs = DefRegs;
Akira Hatanaka36787932011-10-03 19:28:44 +0000540}
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000541
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000542class EffectiveAddress<string instr_asm, RegisterClass RC, Operand Mem> :
543 FMem<0x09, (outs RC:$rt), (ins Mem:$addr),
544 instr_asm, [(set RC:$rt, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000545
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000546// Count Leading Ones/Zeros in Word
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000547class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
548 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
549 !strconcat(instr_asm, "\t$rd, $rs"),
550 [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
551 Requires<[HasBitCount]> {
552 let shamt = 0;
553 let rt = rd;
554}
555
556class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
557 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
558 !strconcat(instr_asm, "\t$rd, $rs"),
559 [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000560 Requires<[HasBitCount]> {
561 let shamt = 0;
562 let rt = rd;
563}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000564
565// Sign Extend in Register.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000566class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000567 FR<0x1f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000568 !strconcat(instr_asm, "\t$rd, $rt"),
569 [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
570 let rs = 0;
571 let shamt = sa;
572 let Predicates = [HasSEInReg];
573}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000574
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000575// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000576class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
577 FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
578 !strconcat(instr_asm, "\t$rd, $rt"),
579 [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
580 let rs = 0;
581 let shamt = sa;
582 let Predicates = [HasSwap];
583}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000584
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000585// Read Hardware
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000586class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$rt), (ins HWRegs:$rd),
587 "rdhwr\t$rt, $rd", [], IIAlu> {
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000588 let rs = 0;
589 let shamt = 0;
590}
591
Akira Hatanaka667645f2011-08-17 22:59:46 +0000592// Ext and Ins
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000593class ExtIns<bits<6> _funct, string instr_asm, dag outs, dag ins,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000594 list<dag> pattern, InstrItinClass itin>:
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000595 FR<0x1f, _funct, outs, ins, !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
Akira Hatanaka56633442011-09-20 23:53:09 +0000596 pattern, itin>, Requires<[HasMips32r2]> {
Akira Hatanaka667645f2011-08-17 22:59:46 +0000597 bits<5> pos;
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000598 bits<5> sz;
599 let rd = sz;
Akira Hatanaka667645f2011-08-17 22:59:46 +0000600 let shamt = pos;
601}
602
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000603// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
Akira Hatanaka59068062011-11-11 04:14:30 +0000604class Atomic2Ops<PatFrag Op, string Opstr, RegisterClass DRC,
605 RegisterClass PRC> :
606 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$incr),
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000607 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
Akira Hatanaka59068062011-11-11 04:14:30 +0000608 [(set DRC:$dst, (Op PRC:$ptr, DRC:$incr))]>;
609
610multiclass Atomic2Ops32<PatFrag Op, string Opstr> {
611 def #NAME# : Atomic2Ops<Op, Opstr, CPURegs, CPURegs>, Requires<[NotN64]>;
612 def _P8 : Atomic2Ops<Op, Opstr, CPURegs, CPU64Regs>, Requires<[IsN64]>;
613}
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000614
615// Atomic Compare & Swap.
Akira Hatanaka59068062011-11-11 04:14:30 +0000616class AtomicCmpSwap<PatFrag Op, string Width, RegisterClass DRC,
617 RegisterClass PRC> :
618 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$cmp, DRC:$swap),
619 !strconcat("atomic_cmp_swap_", Width, "\t$dst, $ptr, $cmp, $swap"),
620 [(set DRC:$dst, (Op PRC:$ptr, DRC:$cmp, DRC:$swap))]>;
621
622multiclass AtomicCmpSwap32<PatFrag Op, string Width> {
623 def #NAME# : AtomicCmpSwap<Op, Width, CPURegs, CPURegs>, Requires<[NotN64]>;
624 def _P8 : AtomicCmpSwap<Op, Width, CPURegs, CPU64Regs>, Requires<[IsN64]>;
625}
626
627class LLBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
628 FMem<Opc, (outs RC:$rt), (ins Mem:$addr),
629 !strconcat(opstring, "\t$rt, $addr"), [], IILoad> {
630 let mayLoad = 1;
631}
632
633class SCBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
634 FMem<Opc, (outs RC:$dst), (ins RC:$rt, Mem:$addr),
635 !strconcat(opstring, "\t$rt, $addr"), [], IIStore> {
636 let mayStore = 1;
637 let Constraints = "$rt = $dst";
638}
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000639
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000640//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000641// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000642//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000643
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000644// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000645let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000646def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000647 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000648 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000649def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000650 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000651 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000652}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000653
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000654// Some assembly macros need to avoid pseudoinstructions and assembler
655// automatic reodering, we should reorder ourselves.
656def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
657def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
658def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
659def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
660
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000661// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000662// when using the AT register.
663def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
664def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
665
Eric Christopher3c999a22007-10-26 04:00:13 +0000666// When handling PIC code the assembler needs .cpload and .cprestore
667// directives. If the real instructions corresponding these directives
668// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000669// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000670def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanaka78d62b22011-07-07 22:06:18 +0000671def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000672
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000673let usesCustomInserter = 1 in {
Akira Hatanaka59068062011-11-11 04:14:30 +0000674 defm ATOMIC_LOAD_ADD_I8 : Atomic2Ops32<atomic_load_add_8, "load_add_8">;
675 defm ATOMIC_LOAD_ADD_I16 : Atomic2Ops32<atomic_load_add_16, "load_add_16">;
676 defm ATOMIC_LOAD_ADD_I32 : Atomic2Ops32<atomic_load_add_32, "load_add_32">;
677 defm ATOMIC_LOAD_SUB_I8 : Atomic2Ops32<atomic_load_sub_8, "load_sub_8">;
678 defm ATOMIC_LOAD_SUB_I16 : Atomic2Ops32<atomic_load_sub_16, "load_sub_16">;
679 defm ATOMIC_LOAD_SUB_I32 : Atomic2Ops32<atomic_load_sub_32, "load_sub_32">;
680 defm ATOMIC_LOAD_AND_I8 : Atomic2Ops32<atomic_load_and_8, "load_and_8">;
681 defm ATOMIC_LOAD_AND_I16 : Atomic2Ops32<atomic_load_and_16, "load_and_16">;
682 defm ATOMIC_LOAD_AND_I32 : Atomic2Ops32<atomic_load_and_32, "load_and_32">;
683 defm ATOMIC_LOAD_OR_I8 : Atomic2Ops32<atomic_load_or_8, "load_or_8">;
684 defm ATOMIC_LOAD_OR_I16 : Atomic2Ops32<atomic_load_or_16, "load_or_16">;
685 defm ATOMIC_LOAD_OR_I32 : Atomic2Ops32<atomic_load_or_32, "load_or_32">;
686 defm ATOMIC_LOAD_XOR_I8 : Atomic2Ops32<atomic_load_xor_8, "load_xor_8">;
687 defm ATOMIC_LOAD_XOR_I16 : Atomic2Ops32<atomic_load_xor_16, "load_xor_16">;
688 defm ATOMIC_LOAD_XOR_I32 : Atomic2Ops32<atomic_load_xor_32, "load_xor_32">;
689 defm ATOMIC_LOAD_NAND_I8 : Atomic2Ops32<atomic_load_nand_8, "load_nand_8">;
690 defm ATOMIC_LOAD_NAND_I16 : Atomic2Ops32<atomic_load_nand_16, "load_nand_16">;
691 defm ATOMIC_LOAD_NAND_I32 : Atomic2Ops32<atomic_load_nand_32, "load_nand_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000692
Akira Hatanaka59068062011-11-11 04:14:30 +0000693 defm ATOMIC_SWAP_I8 : Atomic2Ops32<atomic_swap_8, "swap_8">;
694 defm ATOMIC_SWAP_I16 : Atomic2Ops32<atomic_swap_16, "swap_16">;
695 defm ATOMIC_SWAP_I32 : Atomic2Ops32<atomic_swap_32, "swap_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000696
Akira Hatanaka59068062011-11-11 04:14:30 +0000697 defm ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap32<atomic_cmp_swap_8, "8">;
698 defm ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap32<atomic_cmp_swap_16, "16">;
699 defm ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap32<atomic_cmp_swap_32, "32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000700}
701
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000702//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000703// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000704//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000705
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000706//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000707// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000708//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000709
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000710/// Arithmetic Instructions (ALU Immediate)
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000711def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
712def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000713def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
714def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000715def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
716def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
717def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000718def LUi : LoadUpper<0x0f, "lui", CPURegs, uimm16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000719
720/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000721def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
722def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000723def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
724def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000725def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
726def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000727def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
728def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
729def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000730def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000731
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000732/// Shift Instructions
Akira Hatanaka36393462011-10-17 18:06:56 +0000733def SLL : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
734def SRL : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
735def SRA : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000736def SLLV : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
737def SRLV : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
738def SRAV : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000739
740// Rotate Instructions
Akira Hatanaka56633442011-09-20 23:53:09 +0000741let Predicates = [HasMips32r2] in {
Akira Hatanaka36393462011-10-17 18:06:56 +0000742 def ROTR : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000743 def ROTRV : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000744}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000745
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000746/// Load and Store Instructions
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000747/// aligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000748defm LB : LoadM32<0x20, "lb", sextloadi8>;
749defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
750defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
751defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
752defm LW : LoadM32<0x23, "lw", load_a>;
753defm SB : StoreM32<0x28, "sb", truncstorei8>;
754defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
755defm SW : StoreM32<0x2b, "sw", store_a>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000756
757/// unaligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000758defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
759defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
760defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
761defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
762defm USW : StoreM32<0x2b, "usw", store_u, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000763
Akira Hatanakadb548262011-07-19 23:30:50 +0000764let hasSideEffects = 1 in
765def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000766 [(MipsSync imm:$stype)], NoItinerary, FrmOther>
Akira Hatanakadb548262011-07-19 23:30:50 +0000767{
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000768 bits<5> stype;
769 let Opcode = 0;
Akira Hatanakadb548262011-07-19 23:30:50 +0000770 let Inst{25-11} = 0;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000771 let Inst{10-6} = stype;
Akira Hatanakadb548262011-07-19 23:30:50 +0000772 let Inst{5-0} = 15;
773}
774
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000775/// Load-linked, Store-conditional
Akira Hatanaka59068062011-11-11 04:14:30 +0000776def LL : LLBase<0x30, "ll", CPURegs, mem>, Requires<[NotN64]>;
777def LL_P8 : LLBase<0x30, "ll", CPURegs, mem64>, Requires<[IsN64]>;
778def SC : SCBase<0x38, "sc", CPURegs, mem>, Requires<[NotN64]>;
779def SC_P8 : SCBase<0x38, "sc", CPURegs, mem64>, Requires<[IsN64]>;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000780
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000781/// Jump and Branch Instructions
782def J : JumpFJ<0x02, "j">;
Akira Hatanaka4fd40b32011-11-16 22:36:01 +0000783def JR : JumpFR<0x00, 0x08, "jr", CPURegs>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000784def JAL : JumpLink<0x03, "jal">;
785def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000786def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
787def BNE : CBranch<0x05, "bne", setne, CPURegs>;
788def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
789def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000790def BLEZ : CBranchZero<0x06, 0, "blez", setle, CPURegs>;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000791def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000792
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000793let rt=0x11 in
794 def BGEZAL : BranchLink<"bgezal">;
795let rt=0x10 in
796 def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000797
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000798let isReturn=1, isTerminator=1, hasDelaySlot=1,
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000799 isBarrier=1, hasCtrlDep=1, rd=0, rt=0, shamt=0 in
800 def RET : FR <0x00, 0x08, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000801 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
802
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000803/// Multiply and Divide Instructions.
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000804def MULT : Mult32<0x18, "mult", IIImul>;
805def MULTu : Mult32<0x19, "multu", IIImul>;
806def SDIV : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
807def UDIV : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000808
Akira Hatanaka89d30662011-10-17 18:24:15 +0000809def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
810def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
811def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
812def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000813
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000814/// Sign Ext In Register Instructions.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000815def SEB : SignExtInReg<0x10, "seb", i8>;
816def SEH : SignExtInReg<0x18, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000817
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000818/// Count Leading
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000819def CLZ : CountLeading0<0x20, "clz", CPURegs>;
820def CLO : CountLeading1<0x21, "clo", CPURegs>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000821
822/// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000823def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000824
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000825/// No operation
826let addr=0 in
827 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
828
Eric Christopher3c999a22007-10-26 04:00:13 +0000829// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000830// instructions. The same not happens for stack address copies, so an
831// add op with mem ComplexPattern is used and the stack address copy
832// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000833def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000834
Akira Hatanaka21afc632011-06-21 00:40:49 +0000835// DynAlloc node points to dynamically allocated stack space.
836// $sp is added to the list of implicitly used registers to prevent dead code
837// elimination from removing instructions that modify $sp.
838let Uses = [SP] in
Akira Hatanakac742e4f2011-11-11 04:06:38 +0000839def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
Akira Hatanaka21afc632011-06-21 00:40:49 +0000840
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000841// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000842def MADD : MArithR<0, "madd", MipsMAdd, 1>;
843def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000844def MSUB : MArithR<4, "msub", MipsMSub>;
845def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000846
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000847// MUL is a assembly macro in the current used ISAs. In recent ISA's
848// it is a real instruction.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000849def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
850 Requires<[HasMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000851
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000852def RDHWR : ReadHardware;
853
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000854def EXT : ExtIns<0, "ext", (outs CPURegs:$rt),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000855 (ins CPURegs:$rs, uimm16:$pos, size_ext:$sz),
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000856 [(set CPURegs:$rt,
857 (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$sz))],
Akira Hatanaka667645f2011-08-17 22:59:46 +0000858 NoItinerary>;
859
860let Constraints = "$src = $rt" in
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000861def INS : ExtIns<4, "ins", (outs CPURegs:$rt),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000862 (ins CPURegs:$rs, uimm16:$pos, size_ins:$sz, CPURegs:$src),
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000863 [(set CPURegs:$rt,
864 (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$sz,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000865 CPURegs:$src))],
866 NoItinerary>;
Akira Hatanakabb15e112011-08-17 02:05:42 +0000867
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000868//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000869// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000870//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000871
872// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000873def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000874 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000875def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000876 (ORi ZERO, imm:$in)>;
877
878// Arbitrary immediates
879def : Pat<(i32 imm:$imm),
880 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
881
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000882// Carry patterns
883def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
884 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
885def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
886 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000887def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000888 (ADDiu CPURegs:$src, imm:$imm)>;
889
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000890// Call
891def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
892 (JAL tglobaladdr:$dst)>;
893def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
894 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000895//def : Pat<(MipsJmpLink CPURegs:$dst),
896// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000897
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000898// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000899def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000900def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Akira Hatanaka74c76342011-11-16 22:39:56 +0000901def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
902def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
903
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000904def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
905def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
Akira Hatanaka74c76342011-11-16 22:39:56 +0000906def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
907def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
908
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000909def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000910 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000911def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
912 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000913def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
914 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000915def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
916 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
917
918// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000919def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000920 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000921def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000922 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000923
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000924// tlsgd
925def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
926 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
927
928// tprel hi/lo
929def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000930def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000931def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
932 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
933
Akira Hatanaka342837d2011-05-28 01:07:07 +0000934// wrapper_pic
935class WrapperPICPat<SDNode node>:
936 Pat<(MipsWrapperPIC node:$in),
937 (ADDiu GP, node:$in)>;
938
939def : WrapperPICPat<tglobaladdr>;
940def : WrapperPICPat<tconstpool>;
941def : WrapperPICPat<texternalsym>;
942def : WrapperPICPat<tblockaddress>;
943def : WrapperPICPat<tjumptable>;
944
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000945// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000946def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000947 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000948
Eric Christopher3c999a22007-10-26 04:00:13 +0000949// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000950def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
951def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000952def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
953def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000954
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000955// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000956def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
957
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000958// brcond patterns
Akira Hatanaka06f82312011-10-11 19:09:09 +0000959multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
960 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
961 Instruction SLTiuOp, Register ZEROReg> {
962def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
963 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
964def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
965 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000966
Akira Hatanaka06f82312011-10-11 19:09:09 +0000967def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
968 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
969def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
970 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
971def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
972 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
973def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
974 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000975
Akira Hatanaka06f82312011-10-11 19:09:09 +0000976def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
977 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
978def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
979 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000980
Akira Hatanaka06f82312011-10-11 19:09:09 +0000981def : Pat<(brcond RC:$cond, bb:$dst),
982 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
983}
984
985defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000986
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000987// setcc patterns
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000988multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
989 Instruction SLTuOp, Register ZEROReg> {
990 def : Pat<(seteq RC:$lhs, RC:$rhs),
991 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
992 def : Pat<(setne RC:$lhs, RC:$rhs),
993 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
994}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000995
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000996multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
997 def : Pat<(setle RC:$lhs, RC:$rhs),
998 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
999 def : Pat<(setule RC:$lhs, RC:$rhs),
1000 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
1001}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001002
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001003multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1004 def : Pat<(setgt RC:$lhs, RC:$rhs),
1005 (SLTOp RC:$rhs, RC:$lhs)>;
1006 def : Pat<(setugt RC:$lhs, RC:$rhs),
1007 (SLTuOp RC:$rhs, RC:$lhs)>;
1008}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001009
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001010multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1011 def : Pat<(setge RC:$lhs, RC:$rhs),
1012 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
1013 def : Pat<(setuge RC:$lhs, RC:$rhs),
1014 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
1015}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +00001016
Akira Hatanaka395d76c2011-10-11 21:40:01 +00001017multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
1018 Instruction SLTiuOp> {
1019 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
1020 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
1021 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
1022 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1023}
1024
1025defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
1026defm : SetlePats<CPURegs, SLT, SLTu>;
1027defm : SetgtPats<CPURegs, SLT, SLTu>;
1028defm : SetgePats<CPURegs, SLT, SLTu>;
1029defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001030
Akira Hatanaka21afc632011-06-21 00:40:49 +00001031// select MipsDynAlloc
1032def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1033
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001034//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001035// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001036//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001037
1038include "MipsInstrFPU.td"
Akira Hatanaka95934842011-09-24 01:34:44 +00001039include "Mips64InstrInfo.td"
Akira Hatanaka8ae330a2011-10-17 18:53:29 +00001040include "MipsCondMov.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001041