blob: 702b37683461cd5139f5608c3961fc668fcf878b [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
253// Arithmetic 3 register operands
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000254class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000255 InstrItinClass itin, bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000256 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
257 !strconcat(instr_asm, "\t$dst, $b, $c"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000258 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
259 let isCommutable = isComm;
260}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000261
Akira Hatanakaedacba82011-05-25 17:32:06 +0000262class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
263 bit isComm = 0>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000264 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000265 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
266 let isCommutable = isComm;
267}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000268
269// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000270class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
271 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000272 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
273 !strconcat(instr_asm, "\t$dst, $b, $c"),
274 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000275
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000276class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
277 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000278 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
279 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000280
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000281// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000282let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000283class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000284 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000285 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000286 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
287 let isCommutable = isComm;
288}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000289
290// Logical
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000291let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000292class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000293 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
294 !strconcat(instr_asm, "\t$dst, $b, $c"),
295 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000296
297class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000298 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
299 !strconcat(instr_asm, "\t$dst, $b, $c"),
300 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000301
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000302let isCommutable = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000303class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000304 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
305 !strconcat(instr_asm, "\t$dst, $b, $c"),
306 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000307
308// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000309class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000310 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000311 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
312 !strconcat(instr_asm, "\t$dst, $b, $c"),
Akira Hatanaka40eda462011-09-22 23:31:54 +0000313 [(set CPURegs:$dst, (OpNode CPURegs:$b, (i32 immZExt5:$c)))], IIAlu> {
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000314 let rs = _rs;
315}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000316
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000317class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000318 SDNode OpNode>:
319 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000320 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000321 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
322 let shamt = _shamt;
323}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000324
325// Load Upper Imediate
326class LoadUpper<bits<6> op, string instr_asm>:
327 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000328 (outs CPURegs:$dst),
329 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000330 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000331 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000332
Eric Christopher3c999a22007-10-26 04:00:13 +0000333// Memory Load/Store
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000334let canFoldAsLoad = 1 in
Akira Hatanakad55bb382011-10-11 00:11:12 +0000335class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
336 Operand MemOpnd, bit Pseudo>:
337 FI<op, (outs RC:$dst), (ins MemOpnd:$addr),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000338 !strconcat(instr_asm, "\t$dst, $addr"),
Akira Hatanakad55bb382011-10-11 00:11:12 +0000339 [(set RC:$dst, (OpNode addr:$addr))], IILoad> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000340 let isPseudo = Pseudo;
341}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000342
Akira Hatanakad55bb382011-10-11 00:11:12 +0000343class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
344 Operand MemOpnd, bit Pseudo>:
345 FI<op, (outs), (ins RC:$dst, MemOpnd:$addr),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000346 !strconcat(instr_asm, "\t$dst, $addr"),
Akira Hatanakad55bb382011-10-11 00:11:12 +0000347 [(OpNode RC:$dst, addr:$addr)], IIStore> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000348 let isPseudo = Pseudo;
349}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000350
Akira Hatanakad55bb382011-10-11 00:11:12 +0000351// 32-bit load.
352multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
353 bit Pseudo = 0> {
354 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
355 Requires<[NotN64]>;
356 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
357 Requires<[IsN64]>;
358}
359
360// 64-bit load.
361multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
362 bit Pseudo = 0> {
363 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
364 Requires<[NotN64]>;
365 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
366 Requires<[IsN64]>;
367}
368
369// 32-bit store.
370multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
371 bit Pseudo = 0> {
372 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
373 Requires<[NotN64]>;
374 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
375 Requires<[IsN64]>;
376}
377
378// 64-bit store.
379multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
380 bit Pseudo = 0> {
381 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
382 Requires<[NotN64]>;
383 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
384 Requires<[IsN64]>;
385}
386
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000387// Conditional Branch
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000388class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
389 CBranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$offset),
390 !strconcat(instr_asm, "\t$rs, $rt, $offset"),
391 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$offset)], IIBranch> {
392 let isBranch = 1;
393 let isTerminator = 1;
394 let hasDelaySlot = 1;
395}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000396
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000397class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
398 RegisterClass RC>:
399 CBranchBase<op, (outs), (ins RC:$rs, brtarget:$offset),
400 !strconcat(instr_asm, "\t$rs, $offset"),
401 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$offset)], IIBranch> {
402 let rt = _rt;
403 let isBranch = 1;
404 let isTerminator = 1;
405 let hasDelaySlot = 1;
Eric Christopher3c999a22007-10-26 04:00:13 +0000406}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000407
Eric Christopher3c999a22007-10-26 04:00:13 +0000408// SetCC
Akira Hatanaka8191f342011-10-11 18:53:46 +0000409class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
410 RegisterClass RC>:
411 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
412 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
413 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000414 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000415
Akira Hatanaka8191f342011-10-11 18:53:46 +0000416class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
417 PatLeaf imm_type, RegisterClass RC>:
418 FI<op, (outs CPURegs:$rd), (ins RC:$rs, Od:$i),
419 !strconcat(instr_asm, "\t$rd, $rs, $i"),
420 [(set CPURegs:$rd, (cond_op RC:$rs, imm_type:$i))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000421 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000422
423// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000424let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000425class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000426 FJ<op, (outs), (ins brtarget:$target),
427 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000428
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000429let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000430class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000431 FR<op, func, (outs), (ins CPURegs:$target),
432 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
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 let rd=31 in
445 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000446 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
447 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000448
449 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000450 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
451 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000452}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000453
Eric Christopher3c999a22007-10-26 04:00:13 +0000454// Mul, Div
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000455let Defs = [HI, LO] in {
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000456 let isCommutable = 1 in
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000457 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
458 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
459 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
460
461 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
462 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
463 !strconcat(instr_asm, "\t$$zero, $a, $b"),
464 [(op CPURegs:$a, CPURegs:$b)], itin>;
465}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000466
Eric Christopher3c999a22007-10-26 04:00:13 +0000467// Move from Hi/Lo
Akira Hatanaka36787932011-10-03 19:28:44 +0000468let shamt = 0 in {
469let rs = 0, rt = 0 in
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000470class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000471 FR<0x00, func, (outs CPURegs:$dst), (ins),
472 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000473
Akira Hatanaka36787932011-10-03 19:28:44 +0000474let rt = 0, rd = 0 in
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000475class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000476 FR<0x00, func, (outs), (ins CPURegs:$src),
477 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Akira Hatanaka36787932011-10-03 19:28:44 +0000478}
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000479
Eric Christopher3c999a22007-10-26 04:00:13 +0000480class EffectiveAddress<string instr_asm> :
Akira Hatanaka03236be2011-07-07 20:54:20 +0000481 FI<0x09, (outs CPURegs:$dst), (ins mem_ea:$addr),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000482 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000483
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000484// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000485class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000486 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000487 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
488 Requires<[HasBitCount]> {
489 let shamt = 0;
490 let rt = rd;
491}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000492
493// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000494class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000495 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
496 !strconcat(instr_asm, "\t$dst, $src"),
497 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000498
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000499// Byte Swap
500class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000501 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
502 !strconcat(instr_asm, "\t$dst, $src"),
503 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000504
505// Conditional Move
506class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000507 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
508 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000509 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000510
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000511// Read Hardware
512class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
513 "rdhwr\t$dst, $src", [], IIAlu> {
514 let rs = 0;
515 let shamt = 0;
516}
517
Akira Hatanaka667645f2011-08-17 22:59:46 +0000518// Ext and Ins
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000519class ExtIns<bits<6> _funct, string instr_asm, dag outs, dag ins,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000520 list<dag> pattern, InstrItinClass itin>:
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000521 FR<0x1f, _funct, outs, ins, !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
Akira Hatanaka56633442011-09-20 23:53:09 +0000522 pattern, itin>, Requires<[HasMips32r2]> {
Akira Hatanaka667645f2011-08-17 22:59:46 +0000523 bits<5> pos;
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000524 bits<5> sz;
525 let rd = sz;
Akira Hatanaka667645f2011-08-17 22:59:46 +0000526 let shamt = pos;
527}
528
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000529// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
Akira Hatanakade9416e2011-07-20 00:53:09 +0000530class Atomic2Ops<PatFrag Op, string Opstr> :
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000531 MipsPseudo<(outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
532 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
533 [(set CPURegs:$dst,
534 (Op CPURegs:$ptr, CPURegs:$incr))]>;
535
536// Atomic Compare & Swap.
537class AtomicCmpSwap<PatFrag Op, string Width> :
538 MipsPseudo<(outs CPURegs:$dst),
539 (ins CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap),
540 !strconcat("atomic_cmp_swap_", Width,
541 "\t$dst, $ptr, $cmp, $swap"),
542 [(set CPURegs:$dst,
543 (Op CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap))]>;
544
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000545//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000546// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000547//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000548
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000549// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000550let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000551def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000552 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000553 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000554def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000555 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000556 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000557}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000558
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000559// Some assembly macros need to avoid pseudoinstructions and assembler
560// automatic reodering, we should reorder ourselves.
561def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
562def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
563def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
564def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
565
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000566// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000567// when using the AT register.
568def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
569def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
570
Eric Christopher3c999a22007-10-26 04:00:13 +0000571// When handling PIC code the assembler needs .cpload and .cprestore
572// directives. If the real instructions corresponding these directives
573// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000574// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000575def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanaka78d62b22011-07-07 22:06:18 +0000576def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000577
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000578let usesCustomInserter = 1 in {
Akira Hatanakade9416e2011-07-20 00:53:09 +0000579 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, "load_add_8">;
580 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, "load_add_16">;
581 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, "load_add_32">;
582 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, "load_sub_8">;
583 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, "load_sub_16">;
584 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, "load_sub_32">;
585 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, "load_and_8">;
586 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, "load_and_16">;
587 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, "load_and_32">;
588 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, "load_or_8">;
589 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, "load_or_16">;
590 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, "load_or_32">;
591 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, "load_xor_8">;
592 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, "load_xor_16">;
593 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, "load_xor_32">;
594 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, "load_nand_8">;
595 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, "load_nand_16">;
596 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, "load_nand_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000597
Akira Hatanakade9416e2011-07-20 00:53:09 +0000598 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, "swap_8">;
599 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, "swap_16">;
600 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, "swap_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000601
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000602 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, "8">;
603 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, "16">;
604 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, "32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000605}
606
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000607//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000608// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000609//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000610
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000611//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000612// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000613//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000614
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000615/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000616def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
617def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000618def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
619def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000620def ANDi : LogicI<0x0c, "andi", and>;
621def ORi : LogicI<0x0d, "ori", or>;
622def XORi : LogicI<0x0e, "xori", xor>;
623def LUi : LoadUpper<0x0f, "lui">;
624
625/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000626def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000627def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000628def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000629def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000630def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
631def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000632def AND : LogicR<0x24, "and", and>;
633def OR : LogicR<0x25, "or", or>;
634def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000635def NOR : LogicNOR<0x00, 0x27, "nor">;
636
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000637/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000638def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
639def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
640def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
641def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
642def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
643def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
644
645// Rotate Instructions
Akira Hatanaka56633442011-09-20 23:53:09 +0000646let Predicates = [HasMips32r2] in {
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000647 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
648 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
649}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000650
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000651/// Load and Store Instructions
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000652/// aligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000653defm LB : LoadM32<0x20, "lb", sextloadi8>;
654defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
655defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
656defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
657defm LW : LoadM32<0x23, "lw", load_a>;
658defm SB : StoreM32<0x28, "sb", truncstorei8>;
659defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
660defm SW : StoreM32<0x2b, "sw", store_a>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000661
662/// unaligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000663defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
664defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
665defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
666defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
667defm USW : StoreM32<0x2b, "usw", store_u, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000668
Akira Hatanakadb548262011-07-19 23:30:50 +0000669let hasSideEffects = 1 in
670def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
671 [(MipsSync imm:$stype)], NoItinerary>
672{
673 let opcode = 0;
674 let Inst{25-11} = 0;
675 let Inst{5-0} = 15;
676}
677
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000678/// Load-linked, Store-conditional
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000679let mayLoad = 1 in
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000680 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
681 "ll\t$dst, $addr", [], IILoad>;
Akira Hatanaka0d7d0b52011-07-18 18:52:12 +0000682let mayStore = 1, Constraints = "$src = $dst" in
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000683 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
684 "sc\t$src, $addr", [], IIStore>;
685
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000686/// Jump and Branch Instructions
687def J : JumpFJ<0x02, "j">;
Akira Hatanaka1f8d8222011-08-11 21:05:37 +0000688let isIndirectBranch = 1 in
689 def JR : JumpFR<0x00, 0x08, "jr">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000690def JAL : JumpLink<0x03, "jal">;
691def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000692def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
693def BNE : CBranch<0x05, "bne", setne, CPURegs>;
694def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
695def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
696def BLEZ : CBranchZero<0x07, 0, "blez", setle, CPURegs>;
697def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000698
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000699def BGEZAL : BranchLink<"bgezal">;
700def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000701
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000702let isReturn=1, isTerminator=1, hasDelaySlot=1,
703 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
704 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
705 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
706
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000707/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000708def MULT : Mul<0x18, "mult", IIImul>;
709def MULTu : Mul<0x19, "multu", IIImul>;
710def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
711def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000712
713let Defs = [HI] in
714 def MTHI : MoveToLOHI<0x11, "mthi">;
715let Defs = [LO] in
716 def MTLO : MoveToLOHI<0x13, "mtlo">;
717
718let Uses = [HI] in
719 def MFHI : MoveFromLOHI<0x10, "mfhi">;
720let Uses = [LO] in
721 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000722
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000723/// Sign Ext In Register Instructions.
724let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000725 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000726 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000727
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000728 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000729 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000730}
731
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000732/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000733def CLZ : CountLeading<0b100000, "clz",
734 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
735def CLO : CountLeading<0b100001, "clo",
736 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000737
738/// Byte Swap
739let Predicates = [HasSwap] in {
740 let shamt = 0x3, rs = 0 in
741 def WSBW : ByteSwap<0x20, "wsbw">;
742}
743
744/// Conditional Move
745def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
746def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
747
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000748// Conditional moves:
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +0000749// These instructions are expanded in
750// MipsISelLowering::EmitInstrWithCustomInserter if target does not have
751// conditional move instructions.
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000752// flag:int, data:int
753let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
754 class CondMovIntInt<bits<6> funct, string instr_asm> :
755 FR<0, funct, (outs CPURegs:$dst),
756 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
757 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
758
759def MOVZ_I : CondMovIntInt<0x0a, "movz">;
760def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000761
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000762/// No operation
763let addr=0 in
764 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
765
Eric Christopher3c999a22007-10-26 04:00:13 +0000766// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000767// instructions. The same not happens for stack address copies, so an
768// add op with mem ComplexPattern is used and the stack address copy
769// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanaka03236be2011-07-07 20:54:20 +0000770def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, $addr">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000771
Akira Hatanaka21afc632011-06-21 00:40:49 +0000772// DynAlloc node points to dynamically allocated stack space.
773// $sp is added to the list of implicitly used registers to prevent dead code
774// elimination from removing instructions that modify $sp.
775let Uses = [SP] in
Akira Hatanaka03236be2011-07-07 20:54:20 +0000776def DynAlloc : EffectiveAddress<"addiu\t$dst, $addr">;
Akira Hatanaka21afc632011-06-21 00:40:49 +0000777
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000778// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000779def MADD : MArithR<0, "madd", MipsMAdd, 1>;
780def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000781def MSUB : MArithR<4, "msub", MipsMSub>;
782def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000783
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000784// MUL is a assembly macro in the current used ISAs. In recent ISA's
785// it is a real instruction.
Akira Hatanaka56633442011-09-20 23:53:09 +0000786def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[HasMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000787
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000788def RDHWR : ReadHardware;
789
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000790def EXT : ExtIns<0, "ext", (outs CPURegs:$rt),
791 (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz),
792 [(set CPURegs:$rt,
793 (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$sz))],
Akira Hatanaka667645f2011-08-17 22:59:46 +0000794 NoItinerary>;
795
796let Constraints = "$src = $rt" in
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000797def INS : ExtIns<4, "ins", (outs CPURegs:$rt),
798 (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz, CPURegs:$src),
799 [(set CPURegs:$rt,
800 (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$sz,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000801 CPURegs:$src))],
802 NoItinerary>;
Akira Hatanakabb15e112011-08-17 02:05:42 +0000803
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000804//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000805// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000806//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000807
808// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000809def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000810 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000811def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000812 (ORi ZERO, imm:$in)>;
813
814// Arbitrary immediates
815def : Pat<(i32 imm:$imm),
816 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
817
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000818// Carry patterns
819def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
820 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
821def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
822 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000823def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000824 (ADDiu CPURegs:$src, imm:$imm)>;
825
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000826// Call
827def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
828 (JAL tglobaladdr:$dst)>;
829def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
830 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000831//def : Pat<(MipsJmpLink CPURegs:$dst),
832// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000833
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000834// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000835def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000836def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000837def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
838def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000839def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000840 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000841def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
842 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000843
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000844def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000845def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000846def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
847 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000848
849def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000850def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000851def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
852 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
853
854// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000855def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000856 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000857def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000858 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000859
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000860// tlsgd
861def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
862 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
863
864// tprel hi/lo
865def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000866def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000867def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
868 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
869
Akira Hatanaka342837d2011-05-28 01:07:07 +0000870// wrapper_pic
871class WrapperPICPat<SDNode node>:
872 Pat<(MipsWrapperPIC node:$in),
873 (ADDiu GP, node:$in)>;
874
875def : WrapperPICPat<tglobaladdr>;
876def : WrapperPICPat<tconstpool>;
877def : WrapperPICPat<texternalsym>;
878def : WrapperPICPat<tblockaddress>;
879def : WrapperPICPat<tjumptable>;
880
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000881// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000882def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000883 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000884
Eric Christopher3c999a22007-10-26 04:00:13 +0000885// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000886def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
887def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000888def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
889def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000890
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000891// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000892def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
893
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000894// brcond patterns
Akira Hatanaka06f82312011-10-11 19:09:09 +0000895multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
896 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
897 Instruction SLTiuOp, Register ZEROReg> {
898def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
899 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
900def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
901 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000902
Akira Hatanaka06f82312011-10-11 19:09:09 +0000903def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
904 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
905def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
906 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
907def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
908 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
909def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
910 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000911
Akira Hatanaka06f82312011-10-11 19:09:09 +0000912def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
913 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
914def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
915 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000916
Akira Hatanaka06f82312011-10-11 19:09:09 +0000917def : Pat<(brcond RC:$cond, bb:$dst),
918 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
919}
920
921defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000922
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000923// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000924multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
Akira Hatanaka40eda462011-09-22 23:31:54 +0000925 def : Pat<(select (i32 (setge CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000926 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000927 def : Pat<(select (i32 (setuge CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000928 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000929 def : Pat<(select (i32 (setge CPURegs:$lhs, immSExt16:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000930 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000931 def : Pat<(select (i32 (setuge CPURegs:$lh, immSExt16:$rh)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000932 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000933 def : Pat<(select (i32 (setle CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000934 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000935 def : Pat<(select (i32 (setule CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000936 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000937 def : Pat<(select (i32 (seteq CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000938 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000939 def : Pat<(select (i32 (seteq CPURegs:$lhs, 0)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000940 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
941}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000942
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000943multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
Akira Hatanaka40eda462011-09-22 23:31:54 +0000944 def : Pat<(select (i32 (setne CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000945 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
946 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
947 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
Akira Hatanaka40eda462011-09-22 23:31:54 +0000948 def : Pat<(select (i32 (setne CPURegs:$lhs, 0)), RC:$T, RC:$F),
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000949 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
950}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000951
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000952defm : MovzPats<CPURegs, MOVZ_I>;
953defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000954
955// setcc patterns
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000956multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
957 Instruction SLTuOp, Register ZEROReg> {
958 def : Pat<(seteq RC:$lhs, RC:$rhs),
959 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
960 def : Pat<(setne RC:$lhs, RC:$rhs),
961 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
962}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000963
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000964multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
965 def : Pat<(setle RC:$lhs, RC:$rhs),
966 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
967 def : Pat<(setule RC:$lhs, RC:$rhs),
968 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
969}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000970
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000971multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
972 def : Pat<(setgt RC:$lhs, RC:$rhs),
973 (SLTOp RC:$rhs, RC:$lhs)>;
974 def : Pat<(setugt RC:$lhs, RC:$rhs),
975 (SLTuOp RC:$rhs, RC:$lhs)>;
976}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000977
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000978multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
979 def : Pat<(setge RC:$lhs, RC:$rhs),
980 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
981 def : Pat<(setuge RC:$lhs, RC:$rhs),
982 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
983}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000984
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000985multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
986 Instruction SLTiuOp> {
987 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
988 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
989 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
990 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
991}
992
993defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
994defm : SetlePats<CPURegs, SLT, SLTu>;
995defm : SetgtPats<CPURegs, SLT, SLTu>;
996defm : SetgePats<CPURegs, SLT, SLTu>;
997defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000998
Akira Hatanaka21afc632011-06-21 00:40:49 +0000999// select MipsDynAlloc
1000def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1001
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001002//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001003// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001004//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001005
1006include "MipsInstrFPU.td"
Akira Hatanaka95934842011-09-24 01:34:44 +00001007include "Mips64InstrInfo.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001008