blob: b9dcd1da1d03f575faeddbf5a52bb954009766d1 [file] [log] [blame]
Eric Christopher49ac3d72011-05-09 18:16:46 +00001//===- MipsInstrInfo.td - Target Description for Mips Target -*- tablegen -*-=//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Eric Christopher49ac3d72011-05-09 18:16:46 +00009//
10// This file contains the Mips implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000013
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000014//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000015// Instruction format superclass
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000016//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000017
18include "MipsInstrFormats.td"
19
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000020//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000021// Mips profiles and nodes
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000022//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000023
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000024def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
25def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000026def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +000027 SDTCisSameAs<1, 2>,
28 SDTCisSameAs<3, 4>,
29 SDTCisInt<4>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000030def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
31def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000032def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000033 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000034 SDTCisSameAs<1, 2>,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000035 SDTCisSameAs<2, 3>]>;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000036def SDT_MipsDivRem : SDTypeProfile<0, 2,
Akira Hatanakadda4a072011-10-03 21:06:13 +000037 [SDTCisInt<0>,
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000038 SDTCisSameAs<0, 1>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000039
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000040def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
41
Akira Hatanaka21afc632011-06-21 00:40:49 +000042def SDT_MipsDynAlloc : SDTypeProfile<1, 1, [SDTCisVT<0, i32>,
43 SDTCisVT<1, iPTR>]>;
Akira Hatanakadb548262011-07-19 23:30:50 +000044def SDT_Sync : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
Akira Hatanaka21afc632011-06-21 00:40:49 +000045
Akira Hatanaka40eda462011-09-22 23:31:54 +000046def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
47 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
48def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
49 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
Akira Hatanakabb15e112011-08-17 02:05:42 +000050 SDTCisSameAs<0, 4>]>;
51
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000052// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000053def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000054 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000055 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000056
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000057// Hi and Lo nodes are used to handle global addresses. Used on
58// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000059// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000060def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
61def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
62def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000063
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +000064// TlsGd node is used to handle General Dynamic TLS
65def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
66
67// TprelHi and TprelLo nodes are used to handle Local Exec TLS
68def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
69def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
70
71// Thread pointer
72def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
73
Eric Christopher3c999a22007-10-26 04:00:13 +000074// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000075def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000076 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000077
78// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000079def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000080 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000081def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000082 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000083
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000084// MAdd*/MSub* nodes
85def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
86 [SDNPOptInGlue, SDNPOutGlue]>;
87def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
88 [SDNPOptInGlue, SDNPOutGlue]>;
89def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
90 [SDNPOptInGlue, SDNPOutGlue]>;
91def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
92 [SDNPOptInGlue, SDNPOutGlue]>;
93
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000094// DivRem(u) nodes
95def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
96 [SDNPOutGlue]>;
97def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
98 [SDNPOutGlue]>;
99
Akira Hatanaka6cd4b4e2011-06-07 18:00:14 +0000100// Target constant nodes that are not part of any isel patterns and remain
101// unchanged can cause instructions with illegal operands to be emitted.
102// Wrapper node patterns give the instruction selector a chance to replace
103// target constant nodes that would otherwise remain unchanged with ADDiu
104// nodes. Without these wrapper node patterns, the following conditional move
105// instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
106// compiled:
107// movn %got(d)($gp), %got(c)($gp), $4
108// This instruction is illegal since movn can take only register operands.
109
Akira Hatanaka342837d2011-05-28 01:07:07 +0000110def MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", SDTIntUnaryOp>;
111
Akira Hatanaka21afc632011-06-21 00:40:49 +0000112// Pointer to dynamically allocated stack area.
113def MipsDynAlloc : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
114 [SDNPHasChain, SDNPInGlue]>;
115
Akira Hatanakadb548262011-07-19 23:30:50 +0000116def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain]>;
117
Akira Hatanakabb15e112011-08-17 02:05:42 +0000118def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>;
119def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>;
120
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000121//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000122// Mips Instruction Predicate Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000123//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000124def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
125def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000126def HasSwap : Predicate<"Subtarget.hasSwap()">;
127def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Akira Hatanaka56633442011-09-20 23:53:09 +0000128def HasMips32 : Predicate<"Subtarget.hasMips32()">;
129def HasMips32r2 : Predicate<"Subtarget.hasMips32r2()">;
Akira Hatanaka1acb7df2011-10-11 01:12:52 +0000130def HasMips64 : Predicate<"Subtarget.hasMips64()">;
131def NotMips64 : Predicate<"!Subtarget.hasMips64()">;
132def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000133def IsN64 : Predicate<"Subtarget.isABI_N64()">;
134def NotN64 : Predicate<"!Subtarget.isABI_N64()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000135
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000136//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000137// Mips Operand, Complex Patterns and Transformations Definitions.
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000138//===----------------------------------------------------------------------===//
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000139
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000140// Instruction operand types
141def brtarget : Operand<OtherVT>;
142def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000143def simm16 : Operand<i32>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000144def simm16_64 : Operand<i64>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000145def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000146
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000147// Unsigned Operand
148def uimm16 : Operand<i32> {
149 let PrintMethod = "printUnsignedImm";
150}
151
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000152// Address operand
153def mem : Operand<i32> {
154 let PrintMethod = "printMemOperand";
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000155 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000156}
157
Akira Hatanakad55bb382011-10-11 00:11:12 +0000158def mem64 : Operand<i64> {
159 let PrintMethod = "printMemOperand";
160 let MIOperandInfo = (ops CPU64Regs, simm16_64);
161}
162
Akira Hatanaka03236be2011-07-07 20:54:20 +0000163def mem_ea : Operand<i32> {
164 let PrintMethod = "printMemOperandEA";
165 let MIOperandInfo = (ops CPURegs, simm16);
166}
167
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000168// Transformation Function - get the lower 16 bits.
169def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000170 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000171}]>;
172
173// Transformation Function - get the higher 16 bits.
174def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000175 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000176}]>;
177
178// Node immediate fits as 16-bit sign extended on target immediate.
179// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000180def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000181
182// Node immediate fits as 16-bit zero extended on target immediate.
183// The LO16 param means that only the lower 16 bits of the node
184// immediate are caught.
185// e.g. addiu, sltiu
186def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000187 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000188 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000189 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000190 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000191}], LO16>;
192
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000193// shamt field must fit in 5 bits.
194def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000195 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000196}]>;
197
Eric Christopher3c999a22007-10-26 04:00:13 +0000198// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000199// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000200def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000201
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000202//===----------------------------------------------------------------------===//
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000203// Pattern fragment for load/store
204//===----------------------------------------------------------------------===//
205class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
206 LoadSDNode *LD = cast<LoadSDNode>(N);
207 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
208}]>;
209
210class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
211 LoadSDNode *LD = cast<LoadSDNode>(N);
212 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
213}]>;
214
215class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
216 (Node node:$val, node:$ptr), [{
217 StoreSDNode *SD = cast<StoreSDNode>(N);
218 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
219}]>;
220
221class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
222 (Node node:$val, node:$ptr), [{
223 StoreSDNode *SD = cast<StoreSDNode>(N);
224 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
225}]>;
226
227// Load/Store PatFrags.
228def sextloadi16_a : AlignedLoad<sextloadi16>;
229def zextloadi16_a : AlignedLoad<zextloadi16>;
230def extloadi16_a : AlignedLoad<extloadi16>;
231def load_a : AlignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000232def sextloadi32_a : AlignedLoad<sextloadi32>;
233def zextloadi32_a : AlignedLoad<zextloadi32>;
234def extloadi32_a : AlignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000235def truncstorei16_a : AlignedStore<truncstorei16>;
236def store_a : AlignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000237def truncstorei32_a : AlignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000238def sextloadi16_u : UnalignedLoad<sextloadi16>;
239def zextloadi16_u : UnalignedLoad<zextloadi16>;
240def extloadi16_u : UnalignedLoad<extloadi16>;
241def load_u : UnalignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000242def sextloadi32_u : UnalignedLoad<sextloadi32>;
243def zextloadi32_u : UnalignedLoad<zextloadi32>;
244def extloadi32_u : UnalignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000245def truncstorei16_u : UnalignedStore<truncstorei16>;
246def store_u : UnalignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000247def truncstorei32_u : UnalignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000248
249//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000250// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000251//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000252
Akira Hatanaka76d9f1c2011-10-11 23:12:12 +0000253// Arithmetic and logical instructions with 3 register operands.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000254class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
255 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
256 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
257 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
258 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
259 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000260 let isCommutable = isComm;
261}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000262
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000263class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000264 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
265 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
266 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
267 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000268 let isCommutable = isComm;
269}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000270
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000271// Arithmetic and logical instructions with 2 register operands.
272class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
273 Operand Od, PatLeaf imm_type, RegisterClass RC> :
274 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$i),
275 !strconcat(instr_asm, "\t$rt, $rs, $i"),
276 [(set RC:$rt, (OpNode RC:$rs, imm_type:$i))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000277
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000278class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000279 Operand Od, PatLeaf imm_type, RegisterClass RC> :
280 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$i),
281 !strconcat(instr_asm, "\t$rt, $rs, $i"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000282
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000283// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000284let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000285class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000286 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000287 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000288 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000289 let rd = 0;
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
294// Logical
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000295class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000296 FR<op, func, (outs CPURegs:$rd), (ins CPURegs:$rs, CPURegs:$rt),
297 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
298 [(set CPURegs:$rd, (not (or CPURegs:$rs, CPURegs:$rt)))], IIAlu> {
299 let shamt = 0;
300 let isCommutable = 1;
301}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000302
303// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000304class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000305 SDNode OpNode>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000306 FR<0x00, func, (outs CPURegs:$rd), (ins CPURegs:$rt, shamt:$shamt),
307 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
308 [(set CPURegs:$rd, (OpNode CPURegs:$rt, (i32 immZExt5:$shamt)))], IIAlu> {
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000309 let rs = _rs;
310}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000311
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000312class LogicR_shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000313 SDNode OpNode>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000314 FR<0x00, func, (outs CPURegs:$rd), (ins CPURegs:$rs, CPURegs:$rt),
315 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
316 [(set CPURegs:$rd, (OpNode CPURegs:$rt, CPURegs:$rs))], IIAlu> {
317 let shamt = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000318}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000319
320// Load Upper Imediate
321class LoadUpper<bits<6> op, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000322 FI<op, (outs CPURegs:$rt), (ins uimm16:$imm),
323 !strconcat(instr_asm, "\t$rt, $imm"), [], IIAlu> {
324 let rs = 0;
325}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000326
Eric Christopher3c999a22007-10-26 04:00:13 +0000327// Memory Load/Store
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000328let canFoldAsLoad = 1 in
Akira Hatanakad55bb382011-10-11 00:11:12 +0000329class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
330 Operand MemOpnd, bit Pseudo>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000331 FI<op, (outs RC:$rt), (ins MemOpnd:$addr),
332 !strconcat(instr_asm, "\t$rt, $addr"),
333 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000334 let isPseudo = Pseudo;
335}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000336
Akira Hatanakad55bb382011-10-11 00:11:12 +0000337class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
338 Operand MemOpnd, bit Pseudo>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000339 FI<op, (outs), (ins RC:$rt, MemOpnd:$addr),
340 !strconcat(instr_asm, "\t$rt, $addr"),
341 [(OpNode RC:$rt, addr:$addr)], IIStore> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000342 let isPseudo = Pseudo;
343}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000344
Akira Hatanakad55bb382011-10-11 00:11:12 +0000345// 32-bit load.
346multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
347 bit Pseudo = 0> {
348 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
349 Requires<[NotN64]>;
350 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
351 Requires<[IsN64]>;
352}
353
354// 64-bit load.
355multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
356 bit Pseudo = 0> {
357 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
358 Requires<[NotN64]>;
359 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
360 Requires<[IsN64]>;
361}
362
363// 32-bit store.
364multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
365 bit Pseudo = 0> {
366 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
367 Requires<[NotN64]>;
368 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
369 Requires<[IsN64]>;
370}
371
372// 64-bit store.
373multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
374 bit Pseudo = 0> {
375 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
376 Requires<[NotN64]>;
377 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
378 Requires<[IsN64]>;
379}
380
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000381// Conditional Branch
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000382class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
383 CBranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$offset),
384 !strconcat(instr_asm, "\t$rs, $rt, $offset"),
385 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$offset)], IIBranch> {
386 let isBranch = 1;
387 let isTerminator = 1;
388 let hasDelaySlot = 1;
389}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000390
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000391class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
392 RegisterClass RC>:
393 CBranchBase<op, (outs), (ins RC:$rs, brtarget:$offset),
394 !strconcat(instr_asm, "\t$rs, $offset"),
395 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$offset)], IIBranch> {
396 let rt = _rt;
397 let isBranch = 1;
398 let isTerminator = 1;
399 let hasDelaySlot = 1;
Eric Christopher3c999a22007-10-26 04:00:13 +0000400}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000401
Eric Christopher3c999a22007-10-26 04:00:13 +0000402// SetCC
Akira Hatanaka8191f342011-10-11 18:53:46 +0000403class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
404 RegisterClass RC>:
405 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
406 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
407 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000408 IIAlu> {
409 let shamt = 0;
410}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000411
Akira Hatanaka8191f342011-10-11 18:53:46 +0000412class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
413 PatLeaf imm_type, RegisterClass RC>:
414 FI<op, (outs CPURegs:$rd), (ins RC:$rs, Od:$i),
415 !strconcat(instr_asm, "\t$rd, $rs, $i"),
416 [(set CPURegs:$rd, (cond_op RC:$rs, imm_type:$i))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000417 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000418
419// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000420let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000421class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000422 FJ<op, (outs), (ins brtarget:$target),
423 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000424
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000425let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000426class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000427 FR<op, func, (outs), (ins CPURegs:$rs),
428 !strconcat(instr_asm, "\t$rs"), [(brind CPURegs:$rs)], IIBranch> {
429 let rt = 0;
430 let rd = 0;
431 let shamt = 0;
432}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000433
434// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000435let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000436 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000437 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
438 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000439 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000440 FJ<op, (outs), (ins calltarget:$target, variable_ops),
441 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
442 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000443
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000444 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000445 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000446 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
447 let rt = 0;
448 let rd = 31;
449 let shamt = 0;
450 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000451
452 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000453 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000454 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch> {
455 let rt = 0;
456 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000457}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000458
Eric Christopher3c999a22007-10-26 04:00:13 +0000459// Mul, Div
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000460class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
461 FR<0x00, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
462 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
463 let rd = 0;
464 let shamt = 0;
465 let isCommutable = 1;
466 let Defs = [HI, LO];
467}
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000468
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000469class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
470 FR<0x00, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
471 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
472 [(op CPURegs:$rs, CPURegs:$rt)], itin> {
473 let rd = 0;
474 let shamt = 0;
475 let Defs = [HI, LO];
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000476}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000477
Eric Christopher3c999a22007-10-26 04:00:13 +0000478// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000479class MoveFromLOHI<bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000480 FR<0x00, func, (outs CPURegs:$rd), (ins),
481 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
482 let rs = 0;
483 let rt = 0;
484 let shamt = 0;
485}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000486
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000487class MoveToLOHI<bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000488 FR<0x00, func, (outs), (ins CPURegs:$rs),
489 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
490 let rt = 0;
491 let rd = 0;
492 let shamt = 0;
Akira Hatanaka36787932011-10-03 19:28:44 +0000493}
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000494
Eric Christopher3c999a22007-10-26 04:00:13 +0000495class EffectiveAddress<string instr_asm> :
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000496 FI<0x09, (outs CPURegs:$rt), (ins mem_ea:$addr),
497 instr_asm, [(set CPURegs:$rt, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000498
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000499// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000500class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000501 FR<0x1c, func, (outs CPURegs:$rd), (ins CPURegs:$rs),
502 !strconcat(instr_asm, "\t$rd, $rs"), pattern, IIAlu>,
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000503 Requires<[HasBitCount]> {
504 let shamt = 0;
505 let rt = rd;
506}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000507
508// Sign Extend in Register.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000509class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
510 FR<0x3f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
511 !strconcat(instr_asm, "\t$rd, $rt"),
512 [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
513 let rs = 0;
514 let shamt = sa;
515 let Predicates = [HasSEInReg];
516}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000517
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000518// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000519class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
520 FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
521 !strconcat(instr_asm, "\t$rd, $rt"),
522 [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
523 let rs = 0;
524 let shamt = sa;
525 let Predicates = [HasSwap];
526}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000527
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000528// Read Hardware
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000529class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$rt), (ins HWRegs:$rd),
530 "rdhwr\t$rt, $rd", [], IIAlu> {
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000531 let rs = 0;
532 let shamt = 0;
533}
534
Akira Hatanaka667645f2011-08-17 22:59:46 +0000535// Ext and Ins
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000536class ExtIns<bits<6> _funct, string instr_asm, dag outs, dag ins,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000537 list<dag> pattern, InstrItinClass itin>:
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000538 FR<0x1f, _funct, outs, ins, !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
Akira Hatanaka56633442011-09-20 23:53:09 +0000539 pattern, itin>, Requires<[HasMips32r2]> {
Akira Hatanaka667645f2011-08-17 22:59:46 +0000540 bits<5> pos;
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000541 bits<5> sz;
542 let rd = sz;
Akira Hatanaka667645f2011-08-17 22:59:46 +0000543 let shamt = pos;
544}
545
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000546// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
Akira Hatanakade9416e2011-07-20 00:53:09 +0000547class Atomic2Ops<PatFrag Op, string Opstr> :
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000548 MipsPseudo<(outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
549 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
550 [(set CPURegs:$dst,
551 (Op CPURegs:$ptr, CPURegs:$incr))]>;
552
553// Atomic Compare & Swap.
554class AtomicCmpSwap<PatFrag Op, string Width> :
555 MipsPseudo<(outs CPURegs:$dst),
556 (ins CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap),
557 !strconcat("atomic_cmp_swap_", Width,
558 "\t$dst, $ptr, $cmp, $swap"),
559 [(set CPURegs:$dst,
560 (Op CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap))]>;
561
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000562//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000563// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000564//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000565
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000566// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000567let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000568def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000569 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000570 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000571def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000572 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000573 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000574}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000575
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000576// Some assembly macros need to avoid pseudoinstructions and assembler
577// automatic reodering, we should reorder ourselves.
578def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
579def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
580def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
581def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
582
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000583// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000584// when using the AT register.
585def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
586def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
587
Eric Christopher3c999a22007-10-26 04:00:13 +0000588// When handling PIC code the assembler needs .cpload and .cprestore
589// directives. If the real instructions corresponding these directives
590// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000591// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000592def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanaka78d62b22011-07-07 22:06:18 +0000593def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000594
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000595let usesCustomInserter = 1 in {
Akira Hatanakade9416e2011-07-20 00:53:09 +0000596 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, "load_add_8">;
597 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, "load_add_16">;
598 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, "load_add_32">;
599 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, "load_sub_8">;
600 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, "load_sub_16">;
601 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, "load_sub_32">;
602 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, "load_and_8">;
603 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, "load_and_16">;
604 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, "load_and_32">;
605 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, "load_or_8">;
606 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, "load_or_16">;
607 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, "load_or_32">;
608 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, "load_xor_8">;
609 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, "load_xor_16">;
610 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, "load_xor_32">;
611 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, "load_nand_8">;
612 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, "load_nand_16">;
613 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, "load_nand_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000614
Akira Hatanakade9416e2011-07-20 00:53:09 +0000615 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, "swap_8">;
616 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, "swap_16">;
617 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, "swap_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000618
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000619 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, "8">;
620 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, "16">;
621 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, "32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000622}
623
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000624//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000625// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000626//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000627
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000628//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000629// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000630//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000631
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000632/// Arithmetic Instructions (ALU Immediate)
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000633def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
634def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000635def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
636def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000637def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
638def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
639def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000640def LUi : LoadUpper<0x0f, "lui">;
641
642/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000643def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
644def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000645def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
646def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000647def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
648def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000649def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
650def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
651def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000652def NOR : LogicNOR<0x00, 0x27, "nor">;
653
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000654/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000655def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
656def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
657def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
658def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
659def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
660def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
661
662// Rotate Instructions
Akira Hatanaka56633442011-09-20 23:53:09 +0000663let Predicates = [HasMips32r2] in {
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000664 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
665 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
666}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000667
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000668/// Load and Store Instructions
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000669/// aligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000670defm LB : LoadM32<0x20, "lb", sextloadi8>;
671defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
672defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
673defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
674defm LW : LoadM32<0x23, "lw", load_a>;
675defm SB : StoreM32<0x28, "sb", truncstorei8>;
676defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
677defm SW : StoreM32<0x2b, "sw", store_a>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000678
679/// unaligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000680defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
681defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
682defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
683defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
684defm USW : StoreM32<0x2b, "usw", store_u, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000685
Akira Hatanakadb548262011-07-19 23:30:50 +0000686let hasSideEffects = 1 in
687def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
688 [(MipsSync imm:$stype)], NoItinerary>
689{
690 let opcode = 0;
691 let Inst{25-11} = 0;
692 let Inst{5-0} = 15;
693}
694
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000695/// Load-linked, Store-conditional
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000696let mayLoad = 1 in
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000697 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
698 "ll\t$dst, $addr", [], IILoad>;
Akira Hatanaka0d7d0b52011-07-18 18:52:12 +0000699let mayStore = 1, Constraints = "$src = $dst" in
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000700 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
701 "sc\t$src, $addr", [], IIStore>;
702
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000703/// Jump and Branch Instructions
704def J : JumpFJ<0x02, "j">;
Akira Hatanaka1f8d8222011-08-11 21:05:37 +0000705let isIndirectBranch = 1 in
706 def JR : JumpFR<0x00, 0x08, "jr">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000707def JAL : JumpLink<0x03, "jal">;
708def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000709def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
710def BNE : CBranch<0x05, "bne", setne, CPURegs>;
711def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
712def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
713def BLEZ : CBranchZero<0x07, 0, "blez", setle, CPURegs>;
714def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000715
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000716def BGEZAL : BranchLink<"bgezal">;
717def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000718
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000719let isReturn=1, isTerminator=1, hasDelaySlot=1,
720 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
721 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
722 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
723
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000724/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000725def MULT : Mul<0x18, "mult", IIImul>;
726def MULTu : Mul<0x19, "multu", IIImul>;
727def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
728def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000729
730let Defs = [HI] in
731 def MTHI : MoveToLOHI<0x11, "mthi">;
732let Defs = [LO] in
733 def MTLO : MoveToLOHI<0x13, "mtlo">;
734
735let Uses = [HI] in
736 def MFHI : MoveFromLOHI<0x10, "mfhi">;
737let Uses = [LO] in
738 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000739
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000740/// Sign Ext In Register Instructions.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000741def SEB : SignExtInReg<0x10, "seb", i8>;
742def SEH : SignExtInReg<0x18, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000743
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000744/// Count Leading
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000745def CLZ : CountLeading<0x20, "clz",
746 [(set CPURegs:$rd, (ctlz CPURegs:$rs))]>;
747def CLO : CountLeading<0x21, "clo",
748 [(set CPURegs:$rd, (ctlz (not CPURegs:$rs)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000749
750/// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000751def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000752
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000753// Conditional moves:
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +0000754// These instructions are expanded in
755// MipsISelLowering::EmitInstrWithCustomInserter if target does not have
756// conditional move instructions.
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000757// flag:int, data:int
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000758class CondMovIntInt<bits<6> funct, string instr_asm> :
759 FR<0, funct, (outs CPURegs:$rd),
760 (ins CPURegs:$rs, CPURegs:$rt, CPURegs:$F),
761 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], NoItinerary> {
762 let shamt = 0;
763 let usesCustomInserter = 1;
764 let Constraints = "$F = $rd";
765}
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000766
767def MOVZ_I : CondMovIntInt<0x0a, "movz">;
768def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000769
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000770/// No operation
771let addr=0 in
772 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
773
Eric Christopher3c999a22007-10-26 04:00:13 +0000774// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000775// instructions. The same not happens for stack address copies, so an
776// add op with mem ComplexPattern is used and the stack address copy
777// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000778def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000779
Akira Hatanaka21afc632011-06-21 00:40:49 +0000780// DynAlloc node points to dynamically allocated stack space.
781// $sp is added to the list of implicitly used registers to prevent dead code
782// elimination from removing instructions that modify $sp.
783let Uses = [SP] in
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000784def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr">;
Akira Hatanaka21afc632011-06-21 00:40:49 +0000785
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000786// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000787def MADD : MArithR<0, "madd", MipsMAdd, 1>;
788def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000789def MSUB : MArithR<4, "msub", MipsMSub>;
790def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000791
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000792// MUL is a assembly macro in the current used ISAs. In recent ISA's
793// it is a real instruction.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000794def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
795 Requires<[HasMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000796
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000797def RDHWR : ReadHardware;
798
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000799def EXT : ExtIns<0, "ext", (outs CPURegs:$rt),
800 (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz),
801 [(set CPURegs:$rt,
802 (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$sz))],
Akira Hatanaka667645f2011-08-17 22:59:46 +0000803 NoItinerary>;
804
805let Constraints = "$src = $rt" in
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000806def INS : ExtIns<4, "ins", (outs CPURegs:$rt),
807 (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz, CPURegs:$src),
808 [(set CPURegs:$rt,
809 (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$sz,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000810 CPURegs:$src))],
811 NoItinerary>;
Akira Hatanakabb15e112011-08-17 02:05:42 +0000812
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000813//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000814// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000815//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000816
817// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000818def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000819 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000820def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000821 (ORi ZERO, imm:$in)>;
822
823// Arbitrary immediates
824def : Pat<(i32 imm:$imm),
825 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
826
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000827// Carry patterns
828def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
829 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
830def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
831 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000832def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000833 (ADDiu CPURegs:$src, imm:$imm)>;
834
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000835// Call
836def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
837 (JAL tglobaladdr:$dst)>;
838def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
839 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000840//def : Pat<(MipsJmpLink CPURegs:$dst),
841// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000842
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000843// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000844def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000845def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000846def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
847def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000848def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000849 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000850def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
851 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000852
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000853def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000854def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000855def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
856 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000857
858def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000859def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000860def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
861 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
862
863// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000864def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000865 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000866def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000867 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000868
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000869// tlsgd
870def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
871 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
872
873// tprel hi/lo
874def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000875def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000876def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
877 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
878
Akira Hatanaka342837d2011-05-28 01:07:07 +0000879// wrapper_pic
880class WrapperPICPat<SDNode node>:
881 Pat<(MipsWrapperPIC node:$in),
882 (ADDiu GP, node:$in)>;
883
884def : WrapperPICPat<tglobaladdr>;
885def : WrapperPICPat<tconstpool>;
886def : WrapperPICPat<texternalsym>;
887def : WrapperPICPat<tblockaddress>;
888def : WrapperPICPat<tjumptable>;
889
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000890// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000891def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000892 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000893
Eric Christopher3c999a22007-10-26 04:00:13 +0000894// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000895def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
896def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000897def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
898def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000899
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000900// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000901def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
902
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000903// brcond patterns
Akira Hatanaka06f82312011-10-11 19:09:09 +0000904multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
905 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
906 Instruction SLTiuOp, Register ZEROReg> {
907def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
908 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
909def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
910 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000911
Akira Hatanaka06f82312011-10-11 19:09:09 +0000912def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
913 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
914def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
915 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
916def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
917 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
918def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
919 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000920
Akira Hatanaka06f82312011-10-11 19:09:09 +0000921def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
922 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
923def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
924 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000925
Akira Hatanaka06f82312011-10-11 19:09:09 +0000926def : Pat<(brcond RC:$cond, bb:$dst),
927 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
928}
929
930defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000931
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000932// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000933multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
Akira Hatanaka40eda462011-09-22 23:31:54 +0000934 def : Pat<(select (i32 (setge CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000935 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000936 def : Pat<(select (i32 (setuge CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000937 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000938 def : Pat<(select (i32 (setge CPURegs:$lhs, immSExt16:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000939 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000940 def : Pat<(select (i32 (setuge CPURegs:$lh, immSExt16:$rh)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000941 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000942 def : Pat<(select (i32 (setle CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000943 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000944 def : Pat<(select (i32 (setule CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000945 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000946 def : Pat<(select (i32 (seteq CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000947 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000948 def : Pat<(select (i32 (seteq CPURegs:$lhs, 0)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000949 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
950}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000951
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000952multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
Akira Hatanaka40eda462011-09-22 23:31:54 +0000953 def : Pat<(select (i32 (setne CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000954 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
955 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
956 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000957 def : Pat<(select (i32 (setne CPURegs:$lhs, 0)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000958 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
959}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000960
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000961defm : MovzPats<CPURegs, MOVZ_I>;
962defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000963
964// setcc patterns
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000965multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
966 Instruction SLTuOp, Register ZEROReg> {
967 def : Pat<(seteq RC:$lhs, RC:$rhs),
968 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
969 def : Pat<(setne RC:$lhs, RC:$rhs),
970 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
971}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000972
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000973multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
974 def : Pat<(setle RC:$lhs, RC:$rhs),
975 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
976 def : Pat<(setule RC:$lhs, RC:$rhs),
977 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
978}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000979
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000980multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
981 def : Pat<(setgt RC:$lhs, RC:$rhs),
982 (SLTOp RC:$rhs, RC:$lhs)>;
983 def : Pat<(setugt RC:$lhs, RC:$rhs),
984 (SLTuOp RC:$rhs, RC:$lhs)>;
985}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000986
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000987multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
988 def : Pat<(setge RC:$lhs, RC:$rhs),
989 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
990 def : Pat<(setuge RC:$lhs, RC:$rhs),
991 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
992}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000993
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000994multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
995 Instruction SLTiuOp> {
996 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
997 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
998 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
999 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1000}
1001
1002defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
1003defm : SetlePats<CPURegs, SLT, SLTu>;
1004defm : SetgtPats<CPURegs, SLT, SLTu>;
1005defm : SetgePats<CPURegs, SLT, SLTu>;
1006defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001007
Akira Hatanaka21afc632011-06-21 00:40:49 +00001008// select MipsDynAlloc
1009def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1010
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001011//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001012// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001013//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001014
1015include "MipsInstrFPU.td"
Akira Hatanaka95934842011-09-24 01:34:44 +00001016include "Mips64InstrInfo.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001017