blob: 61e6bf3fc8c80cd54867db39342f3b735252e095 [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>;
Akira Hatanaka642b1092011-11-11 04:03:54 +0000143def calltarget64: Operand<i64>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000144def simm16 : Operand<i32>;
Akira Hatanakad55bb382011-10-11 00:11:12 +0000145def simm16_64 : Operand<i64>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000146def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000147
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000148// Unsigned Operand
149def uimm16 : Operand<i32> {
150 let PrintMethod = "printUnsignedImm";
151}
152
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000153// Address operand
154def mem : Operand<i32> {
155 let PrintMethod = "printMemOperand";
Akira Hatanakad3ac47f2011-07-07 18:57:00 +0000156 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000157 let EncoderMethod = "getMemEncoding";
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000158}
159
Akira Hatanakad55bb382011-10-11 00:11:12 +0000160def mem64 : Operand<i64> {
161 let PrintMethod = "printMemOperand";
162 let MIOperandInfo = (ops CPU64Regs, simm16_64);
163}
164
Akira Hatanaka03236be2011-07-07 20:54:20 +0000165def mem_ea : Operand<i32> {
166 let PrintMethod = "printMemOperandEA";
167 let MIOperandInfo = (ops CPURegs, simm16);
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000168 let EncoderMethod = "getMemEncoding";
169}
170
171// size operand of ext instruction
172def size_ext : Operand<i32> {
173 let EncoderMethod = "getSizeExtEncoding";
174}
175
176// size operand of ins instruction
177def size_ins : Operand<i32> {
178 let EncoderMethod = "getSizeInsEncoding";
Akira Hatanaka03236be2011-07-07 20:54:20 +0000179}
180
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000181// Transformation Function - get the lower 16 bits.
182def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000183 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000184}]>;
185
186// Transformation Function - get the higher 16 bits.
187def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000188 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000189}]>;
190
191// Node immediate fits as 16-bit sign extended on target immediate.
192// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000193def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000194
195// Node immediate fits as 16-bit zero extended on target immediate.
196// The LO16 param means that only the lower 16 bits of the node
197// immediate are caught.
198// e.g. addiu, sltiu
199def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000200 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000201 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000202 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000203 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000204}], LO16>;
205
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000206// shamt field must fit in 5 bits.
Akira Hatanakaa01820a2011-10-17 18:01:00 +0000207def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000208
Eric Christopher3c999a22007-10-26 04:00:13 +0000209// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000210// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000211def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000212
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000213//===----------------------------------------------------------------------===//
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000214// Pattern fragment for load/store
215//===----------------------------------------------------------------------===//
216class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
217 LoadSDNode *LD = cast<LoadSDNode>(N);
218 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
219}]>;
220
221class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
222 LoadSDNode *LD = cast<LoadSDNode>(N);
223 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
224}]>;
225
226class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
227 (Node node:$val, node:$ptr), [{
228 StoreSDNode *SD = cast<StoreSDNode>(N);
229 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
230}]>;
231
232class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
233 (Node node:$val, node:$ptr), [{
234 StoreSDNode *SD = cast<StoreSDNode>(N);
235 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
236}]>;
237
238// Load/Store PatFrags.
239def sextloadi16_a : AlignedLoad<sextloadi16>;
240def zextloadi16_a : AlignedLoad<zextloadi16>;
241def extloadi16_a : AlignedLoad<extloadi16>;
242def load_a : AlignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000243def sextloadi32_a : AlignedLoad<sextloadi32>;
244def zextloadi32_a : AlignedLoad<zextloadi32>;
245def extloadi32_a : AlignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000246def truncstorei16_a : AlignedStore<truncstorei16>;
247def store_a : AlignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000248def truncstorei32_a : AlignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000249def sextloadi16_u : UnalignedLoad<sextloadi16>;
250def zextloadi16_u : UnalignedLoad<zextloadi16>;
251def extloadi16_u : UnalignedLoad<extloadi16>;
252def load_u : UnalignedLoad<load>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000253def sextloadi32_u : UnalignedLoad<sextloadi32>;
254def zextloadi32_u : UnalignedLoad<zextloadi32>;
255def extloadi32_u : UnalignedLoad<extloadi32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000256def truncstorei16_u : UnalignedStore<truncstorei16>;
257def store_u : UnalignedStore<store>;
Akira Hatanaka7bd19bd2011-10-11 00:27:28 +0000258def truncstorei32_u : UnalignedStore<truncstorei32>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000259
260//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000261// Instructions specific format
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000262//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000263
Akira Hatanaka76d9f1c2011-10-11 23:12:12 +0000264// Arithmetic and logical instructions with 3 register operands.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000265class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
266 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
267 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
268 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
269 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
270 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000271 let isCommutable = isComm;
272}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000273
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000274class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000275 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
276 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
277 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
278 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000279 let isCommutable = isComm;
280}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000281
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000282// Arithmetic and logical instructions with 2 register operands.
283class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
284 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000285 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
286 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
287 [(set RC:$rt, (OpNode RC:$rs, imm_type:$imm16))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000288
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000289class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000290 Operand Od, PatLeaf imm_type, RegisterClass RC> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000291 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
292 !strconcat(instr_asm, "\t$rt, $rs, $imm16"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000293
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000294// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000295let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000296class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000297 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000298 !strconcat(instr_asm, "\t$rs, $rt"),
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000299 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000300 let rd = 0;
301 let shamt = 0;
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000302 let isCommutable = isComm;
303}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000304
305// Logical
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000306class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
307 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000308 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000309 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000310 let shamt = 0;
311 let isCommutable = 1;
312}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000313
314// Shifts
Akira Hatanaka36393462011-10-17 18:06:56 +0000315class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
316 SDNode OpNode, PatFrag PF, Operand ImmOpnd,
317 RegisterClass RC>:
318 FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000319 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
Akira Hatanaka36393462011-10-17 18:06:56 +0000320 [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
321 let rs = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000322}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000323
Akira Hatanaka36393462011-10-17 18:06:56 +0000324// 32-bit shift instructions.
325class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
326 SDNode OpNode>:
327 shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
328
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000329class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
330 SDNode OpNode, RegisterClass RC>:
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000331 FR<0x00, func, (outs RC:$rd), (ins CPURegs:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000332 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
Akira Hatanaka68698cc2011-11-07 18:59:49 +0000333 [(set RC:$rd, (OpNode RC:$rt, CPURegs:$rs))], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000334 let shamt = isRotate;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000335}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000336
337// Load Upper Imediate
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000338class LoadUpper<bits<6> op, string instr_asm, RegisterClass RC, Operand Imm>:
339 FI<op, (outs RC:$rt), (ins Imm:$imm16),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000340 !strconcat(instr_asm, "\t$rt, $imm16"), [], IIAlu> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000341 let rs = 0;
342}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000343
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000344class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
345 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> {
346 bits<21> addr;
347 let Inst{25-21} = addr{20-16};
348 let Inst{15-0} = addr{15-0};
349}
350
Eric Christopher3c999a22007-10-26 04:00:13 +0000351// Memory Load/Store
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000352let canFoldAsLoad = 1 in
Akira Hatanakad55bb382011-10-11 00:11:12 +0000353class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
354 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000355 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000356 !strconcat(instr_asm, "\t$rt, $addr"),
357 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000358 let isPseudo = Pseudo;
359}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000360
Akira Hatanakad55bb382011-10-11 00:11:12 +0000361class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
362 Operand MemOpnd, bit Pseudo>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000363 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000364 !strconcat(instr_asm, "\t$rt, $addr"),
365 [(OpNode RC:$rt, addr:$addr)], IIStore> {
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000366 let isPseudo = Pseudo;
367}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000368
Akira Hatanakad55bb382011-10-11 00:11:12 +0000369// 32-bit load.
370multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
371 bit Pseudo = 0> {
372 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
373 Requires<[NotN64]>;
374 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
375 Requires<[IsN64]>;
376}
377
378// 64-bit load.
379multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
380 bit Pseudo = 0> {
381 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
382 Requires<[NotN64]>;
383 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
384 Requires<[IsN64]>;
385}
386
387// 32-bit store.
388multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
389 bit Pseudo = 0> {
390 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
391 Requires<[NotN64]>;
392 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
393 Requires<[IsN64]>;
394}
395
396// 64-bit store.
397multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
398 bit Pseudo = 0> {
399 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
400 Requires<[NotN64]>;
401 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
402 Requires<[IsN64]>;
403}
404
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000405// Conditional Branch
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000406class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000407 CBranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$imm16),
408 !strconcat(instr_asm, "\t$rs, $rt, $imm16"),
409 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000410 let isBranch = 1;
411 let isTerminator = 1;
412 let hasDelaySlot = 1;
413}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000414
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000415class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
416 RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000417 CBranchBase<op, (outs), (ins RC:$rs, brtarget:$imm16),
418 !strconcat(instr_asm, "\t$rs, $imm16"),
419 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$imm16)], IIBranch> {
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000420 let rt = _rt;
421 let isBranch = 1;
422 let isTerminator = 1;
423 let hasDelaySlot = 1;
Eric Christopher3c999a22007-10-26 04:00:13 +0000424}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000425
Eric Christopher3c999a22007-10-26 04:00:13 +0000426// SetCC
Akira Hatanaka8191f342011-10-11 18:53:46 +0000427class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
428 RegisterClass RC>:
429 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
430 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
431 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000432 IIAlu> {
433 let shamt = 0;
434}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000435
Akira Hatanaka8191f342011-10-11 18:53:46 +0000436class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
437 PatLeaf imm_type, RegisterClass RC>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000438 FI<op, (outs CPURegs:$rt), (ins RC:$rs, Od:$imm16),
439 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
440 [(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000441 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000442
443// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000444let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000445class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000446 FJ<op, (outs), (ins brtarget:$target),
447 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000448
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000449let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000450class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000451 FR<op, func, (outs), (ins CPURegs:$rs),
452 !strconcat(instr_asm, "\t$rs"), [(brind CPURegs:$rs)], IIBranch> {
453 let rt = 0;
454 let rd = 0;
455 let shamt = 0;
456}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000457
458// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000459let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000460 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000461 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
462 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000463 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000464 FJ<op, (outs), (ins calltarget:$target, variable_ops),
465 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
466 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000467
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000468 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000469 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000470 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
471 let rt = 0;
472 let rd = 31;
473 let shamt = 0;
474 }
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000475
476 class BranchLink<string instr_asm>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000477 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$imm16, variable_ops),
478 !strconcat(instr_asm, "\t$rs, $imm16"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000479}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000480
Eric Christopher3c999a22007-10-26 04:00:13 +0000481// Mul, Div
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000482class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
483 RegisterClass RC, list<Register> DefRegs>:
484 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000485 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
486 let rd = 0;
487 let shamt = 0;
488 let isCommutable = 1;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000489 let Defs = DefRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000490}
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000491
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000492class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
493 Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
494
495class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
496 RegisterClass RC, list<Register> DefRegs>:
497 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
498 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
499 [(op RC:$rs, RC:$rt)], itin> {
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000500 let rd = 0;
501 let shamt = 0;
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000502 let Defs = DefRegs;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000503}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000504
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000505class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
506 Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
507
Eric Christopher3c999a22007-10-26 04:00:13 +0000508// Move from Hi/Lo
Akira Hatanaka89d30662011-10-17 18:24:15 +0000509class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
510 list<Register> UseRegs>:
511 FR<0x00, func, (outs RC:$rd), (ins),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000512 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
513 let rs = 0;
514 let rt = 0;
515 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000516 let Uses = UseRegs;
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000517}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000518
Akira Hatanaka89d30662011-10-17 18:24:15 +0000519class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
520 list<Register> DefRegs>:
521 FR<0x00, func, (outs), (ins RC:$rs),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000522 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
523 let rt = 0;
524 let rd = 0;
525 let shamt = 0;
Akira Hatanaka89d30662011-10-17 18:24:15 +0000526 let Defs = DefRegs;
Akira Hatanaka36787932011-10-03 19:28:44 +0000527}
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000528
Eric Christopher3c999a22007-10-26 04:00:13 +0000529class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000530 FMem<0x09, (outs CPURegs:$rt), (ins mem_ea:$addr),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000531 instr_asm, [(set CPURegs:$rt, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000532
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000533// Count Leading Ones/Zeros in Word
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000534class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
535 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
536 !strconcat(instr_asm, "\t$rd, $rs"),
537 [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
538 Requires<[HasBitCount]> {
539 let shamt = 0;
540 let rt = rd;
541}
542
543class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
544 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
545 !strconcat(instr_asm, "\t$rd, $rs"),
546 [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000547 Requires<[HasBitCount]> {
548 let shamt = 0;
549 let rt = rd;
550}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000551
552// Sign Extend in Register.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000553class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000554 FR<0x1f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000555 !strconcat(instr_asm, "\t$rd, $rt"),
556 [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
557 let rs = 0;
558 let shamt = sa;
559 let Predicates = [HasSEInReg];
560}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000561
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000562// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000563class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
564 FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
565 !strconcat(instr_asm, "\t$rd, $rt"),
566 [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
567 let rs = 0;
568 let shamt = sa;
569 let Predicates = [HasSwap];
570}
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000571
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000572// Read Hardware
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000573class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$rt), (ins HWRegs:$rd),
574 "rdhwr\t$rt, $rd", [], IIAlu> {
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000575 let rs = 0;
576 let shamt = 0;
577}
578
Akira Hatanaka667645f2011-08-17 22:59:46 +0000579// Ext and Ins
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000580class ExtIns<bits<6> _funct, string instr_asm, dag outs, dag ins,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000581 list<dag> pattern, InstrItinClass itin>:
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000582 FR<0x1f, _funct, outs, ins, !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
Akira Hatanaka56633442011-09-20 23:53:09 +0000583 pattern, itin>, Requires<[HasMips32r2]> {
Akira Hatanaka667645f2011-08-17 22:59:46 +0000584 bits<5> pos;
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000585 bits<5> sz;
586 let rd = sz;
Akira Hatanaka667645f2011-08-17 22:59:46 +0000587 let shamt = pos;
588}
589
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000590// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
Akira Hatanakade9416e2011-07-20 00:53:09 +0000591class Atomic2Ops<PatFrag Op, string Opstr> :
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000592 MipsPseudo<(outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
593 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
594 [(set CPURegs:$dst,
595 (Op CPURegs:$ptr, CPURegs:$incr))]>;
596
597// Atomic Compare & Swap.
598class AtomicCmpSwap<PatFrag Op, string Width> :
599 MipsPseudo<(outs CPURegs:$dst),
600 (ins CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap),
601 !strconcat("atomic_cmp_swap_", Width,
602 "\t$dst, $ptr, $cmp, $swap"),
603 [(set CPURegs:$dst,
604 (Op CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap))]>;
605
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000606//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000607// Pseudo instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000608//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000609
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000610// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000611let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000612def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000613 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000614 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000615def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000616 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000617 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000618}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000619
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000620// Some assembly macros need to avoid pseudoinstructions and assembler
621// automatic reodering, we should reorder ourselves.
622def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
623def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
624def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
625def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
626
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000627// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000628// when using the AT register.
629def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
630def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
631
Eric Christopher3c999a22007-10-26 04:00:13 +0000632// When handling PIC code the assembler needs .cpload and .cprestore
633// directives. If the real instructions corresponding these directives
634// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000635// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000636def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
Akira Hatanaka78d62b22011-07-07 22:06:18 +0000637def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000638
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000639let usesCustomInserter = 1 in {
Akira Hatanakade9416e2011-07-20 00:53:09 +0000640 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, "load_add_8">;
641 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, "load_add_16">;
642 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, "load_add_32">;
643 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, "load_sub_8">;
644 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, "load_sub_16">;
645 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, "load_sub_32">;
646 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, "load_and_8">;
647 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, "load_and_16">;
648 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, "load_and_32">;
649 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, "load_or_8">;
650 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, "load_or_16">;
651 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, "load_or_32">;
652 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, "load_xor_8">;
653 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, "load_xor_16">;
654 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, "load_xor_32">;
655 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, "load_nand_8">;
656 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, "load_nand_16">;
657 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, "load_nand_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000658
Akira Hatanakade9416e2011-07-20 00:53:09 +0000659 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, "swap_8">;
660 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, "swap_16">;
661 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, "swap_32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000662
Akira Hatanaka32b7ebb2011-07-20 00:23:01 +0000663 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, "8">;
664 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, "16">;
665 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, "32">;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000666}
667
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000668//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000669// Instruction definition
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000670//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000671
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000672//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000673// MipsI Instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000674//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000675
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000676/// Arithmetic Instructions (ALU Immediate)
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000677def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
678def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000679def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
680def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
Akira Hatanaka2dfd3a92011-10-11 23:38:52 +0000681def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
682def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
683def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
Akira Hatanakad83d98d2011-11-07 19:10:49 +0000684def LUi : LoadUpper<0x0f, "lui", CPURegs, uimm16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000685
686/// Arithmetic Instructions (3-Operand, R-Type)
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000687def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
688def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
Akira Hatanaka80eb9942011-10-11 23:43:48 +0000689def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
690def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
Akira Hatanaka8191f342011-10-11 18:53:46 +0000691def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
692def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000693def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
694def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
695def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
Akira Hatanaka41f9a432011-10-12 01:05:13 +0000696def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000697
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000698/// Shift Instructions
Akira Hatanaka36393462011-10-17 18:06:56 +0000699def SLL : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
700def SRL : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
701def SRA : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000702def SLLV : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
703def SRLV : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
704def SRAV : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000705
706// Rotate Instructions
Akira Hatanaka56633442011-09-20 23:53:09 +0000707let Predicates = [HasMips32r2] in {
Akira Hatanaka36393462011-10-17 18:06:56 +0000708 def ROTR : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
Akira Hatanaka2d0a61d2011-10-17 18:17:58 +0000709 def ROTRV : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000710}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000711
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000712/// Load and Store Instructions
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000713/// aligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000714defm LB : LoadM32<0x20, "lb", sextloadi8>;
715defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
716defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
717defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
718defm LW : LoadM32<0x23, "lw", load_a>;
719defm SB : StoreM32<0x28, "sb", truncstorei8>;
720defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
721defm SW : StoreM32<0x2b, "sw", store_a>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000722
723/// unaligned
Akira Hatanakad55bb382011-10-11 00:11:12 +0000724defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
725defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
726defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
727defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
728defm USW : StoreM32<0x2b, "usw", store_u, 1>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000729
Akira Hatanakadb548262011-07-19 23:30:50 +0000730let hasSideEffects = 1 in
731def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000732 [(MipsSync imm:$stype)], NoItinerary, FrmOther>
Akira Hatanakadb548262011-07-19 23:30:50 +0000733{
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000734 bits<5> stype;
735 let Opcode = 0;
Akira Hatanakadb548262011-07-19 23:30:50 +0000736 let Inst{25-11} = 0;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000737 let Inst{10-6} = stype;
Akira Hatanakadb548262011-07-19 23:30:50 +0000738 let Inst{5-0} = 15;
739}
740
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000741/// Load-linked, Store-conditional
Akira Hatanaka8ddf6532011-09-09 20:45:50 +0000742let mayLoad = 1 in
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000743 def LL : FMem<0x30, (outs CPURegs:$rt), (ins mem:$addr),
744 "ll\t$rt, $addr", [], IILoad>;
745let mayStore = 1, Constraints = "$rt = $dst" in
746 def SC : FMem<0x38, (outs CPURegs:$dst), (ins CPURegs:$rt, mem:$addr),
747 "sc\t$rt, $addr", [], IIStore>;
Bruno Cardoso Lopes4e694c92011-05-31 02:54:07 +0000748
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000749/// Jump and Branch Instructions
750def J : JumpFJ<0x02, "j">;
Akira Hatanaka1f8d8222011-08-11 21:05:37 +0000751let isIndirectBranch = 1 in
752 def JR : JumpFR<0x00, 0x08, "jr">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000753def JAL : JumpLink<0x03, "jal">;
754def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000755def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
756def BNE : CBranch<0x05, "bne", setne, CPURegs>;
757def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
758def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000759def BLEZ : CBranchZero<0x06, 0, "blez", setle, CPURegs>;
Akira Hatanaka3e3427a2011-10-11 18:49:17 +0000760def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000761
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000762let rt=0x11 in
763 def BGEZAL : BranchLink<"bgezal">;
764let rt=0x10 in
765 def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000766
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000767let isReturn=1, isTerminator=1, hasDelaySlot=1,
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000768 isBarrier=1, hasCtrlDep=1, rd=0, rt=0, shamt=0 in
769 def RET : FR <0x00, 0x08, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000770 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
771
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000772/// Multiply and Divide Instructions.
Akira Hatanakaf1fddcd2011-10-17 18:21:24 +0000773def MULT : Mult32<0x18, "mult", IIImul>;
774def MULTu : Mult32<0x19, "multu", IIImul>;
775def SDIV : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
776def UDIV : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000777
Akira Hatanaka89d30662011-10-17 18:24:15 +0000778def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
779def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
780def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
781def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000782
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000783/// Sign Ext In Register Instructions.
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000784def SEB : SignExtInReg<0x10, "seb", i8>;
785def SEH : SignExtInReg<0x18, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000786
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000787/// Count Leading
Akira Hatanakabdfd98a2011-10-17 18:26:37 +0000788def CLZ : CountLeading0<0x20, "clz", CPURegs>;
789def CLO : CountLeading1<0x21, "clo", CPURegs>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000790
791/// Byte Swap
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000792def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000793
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000794/// No operation
795let addr=0 in
796 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
797
Eric Christopher3c999a22007-10-26 04:00:13 +0000798// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000799// instructions. The same not happens for stack address copies, so an
800// add op with mem ComplexPattern is used and the stack address copy
801// can be matched. It's similar to Sparc LEA_ADDRi
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000802def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000803
Akira Hatanaka21afc632011-06-21 00:40:49 +0000804// DynAlloc node points to dynamically allocated stack space.
805// $sp is added to the list of implicitly used registers to prevent dead code
806// elimination from removing instructions that modify $sp.
807let Uses = [SP] in
Akira Hatanaka6baabc12011-10-12 00:56:06 +0000808def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr">;
Akira Hatanaka21afc632011-06-21 00:40:49 +0000809
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000810// MADD*/MSUB*
Akira Hatanaka01765eb2011-05-12 17:42:08 +0000811def MADD : MArithR<0, "madd", MipsMAdd, 1>;
812def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000813def MSUB : MArithR<4, "msub", MipsMSub>;
814def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000815
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000816// MUL is a assembly macro in the current used ISAs. In recent ISA's
817// it is a real instruction.
Akira Hatanakac2f3ac92011-10-11 23:05:46 +0000818def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
819 Requires<[HasMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000820
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000821def RDHWR : ReadHardware;
822
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000823def EXT : ExtIns<0, "ext", (outs CPURegs:$rt),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000824 (ins CPURegs:$rs, uimm16:$pos, size_ext:$sz),
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000825 [(set CPURegs:$rt,
826 (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$sz))],
Akira Hatanaka667645f2011-08-17 22:59:46 +0000827 NoItinerary>;
828
829let Constraints = "$src = $rt" in
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000830def INS : ExtIns<4, "ins", (outs CPURegs:$rt),
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000831 (ins CPURegs:$rs, uimm16:$pos, size_ins:$sz, CPURegs:$src),
Bruno Cardoso Lopes44d12eb2011-08-18 16:30:49 +0000832 [(set CPURegs:$rt,
833 (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$sz,
Akira Hatanaka667645f2011-08-17 22:59:46 +0000834 CPURegs:$src))],
835 NoItinerary>;
Akira Hatanakabb15e112011-08-17 02:05:42 +0000836
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000837//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000838// Arbitrary patterns that map to one or more instructions
Akira Hatanaka4552c9a2011-04-15 21:51:11 +0000839//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000840
841// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000842def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000843 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000844def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000845 (ORi ZERO, imm:$in)>;
846
847// Arbitrary immediates
848def : Pat<(i32 imm:$imm),
849 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
850
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000851// Carry patterns
852def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
853 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
854def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
855 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000856def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000857 (ADDiu CPURegs:$src, imm:$imm)>;
858
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000859// Call
860def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
861 (JAL tglobaladdr:$dst)>;
862def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
863 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000864//def : Pat<(MipsJmpLink CPURegs:$dst),
865// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000866
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000867// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000868def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Akira Hatanakaf48eb532011-04-25 17:10:45 +0000869def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000870def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
871def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000872def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000873 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000874def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
875 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000876
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000877def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000878def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000879def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
880 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000881
882def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000883def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000884def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
885 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
886
887// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000888def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000889 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000890def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000891 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000892
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000893// tlsgd
894def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
895 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
896
897// tprel hi/lo
898def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
Akira Hatanakaa4b97f32011-09-13 20:13:58 +0000899def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
Bruno Cardoso Lopesd9796862011-05-31 02:53:58 +0000900def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
901 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
902
Akira Hatanaka342837d2011-05-28 01:07:07 +0000903// wrapper_pic
904class WrapperPICPat<SDNode node>:
905 Pat<(MipsWrapperPIC node:$in),
906 (ADDiu GP, node:$in)>;
907
908def : WrapperPICPat<tglobaladdr>;
909def : WrapperPICPat<tconstpool>;
910def : WrapperPICPat<texternalsym>;
911def : WrapperPICPat<tblockaddress>;
912def : WrapperPICPat<tjumptable>;
913
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000914// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000915def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000916 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000917
Eric Christopher3c999a22007-10-26 04:00:13 +0000918// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000919def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
920def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
Akira Hatanakacb518ee2011-10-08 02:24:10 +0000921def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
922def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000923
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000924// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000925def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
926
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000927// brcond patterns
Akira Hatanaka06f82312011-10-11 19:09:09 +0000928multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
929 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
930 Instruction SLTiuOp, Register ZEROReg> {
931def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
932 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
933def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
934 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000935
Akira Hatanaka06f82312011-10-11 19:09:09 +0000936def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
937 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
938def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
939 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
940def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
941 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
942def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
943 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000944
Akira Hatanaka06f82312011-10-11 19:09:09 +0000945def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
946 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
947def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
948 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000949
Akira Hatanaka06f82312011-10-11 19:09:09 +0000950def : Pat<(brcond RC:$cond, bb:$dst),
951 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
952}
953
954defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000955
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000956// setcc patterns
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000957multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
958 Instruction SLTuOp, Register ZEROReg> {
959 def : Pat<(seteq RC:$lhs, RC:$rhs),
960 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
961 def : Pat<(setne RC:$lhs, RC:$rhs),
962 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
963}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000964
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000965multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
966 def : Pat<(setle RC:$lhs, RC:$rhs),
967 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
968 def : Pat<(setule RC:$lhs, RC:$rhs),
969 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
970}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000971
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000972multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
973 def : Pat<(setgt RC:$lhs, RC:$rhs),
974 (SLTOp RC:$rhs, RC:$lhs)>;
975 def : Pat<(setugt RC:$lhs, RC:$rhs),
976 (SLTuOp RC:$rhs, RC:$lhs)>;
977}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000978
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000979multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
980 def : Pat<(setge RC:$lhs, RC:$rhs),
981 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
982 def : Pat<(setuge RC:$lhs, RC:$rhs),
983 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
984}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000985
Akira Hatanaka395d76c2011-10-11 21:40:01 +0000986multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
987 Instruction SLTiuOp> {
988 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
989 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
990 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
991 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
992}
993
994defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
995defm : SetlePats<CPURegs, SLT, SLTu>;
996defm : SetgtPats<CPURegs, SLT, SLTu>;
997defm : SetgePats<CPURegs, SLT, SLTu>;
998defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000999
Akira Hatanaka21afc632011-06-21 00:40:49 +00001000// select MipsDynAlloc
1001def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1002
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001003//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001004// Floating Point Support
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001005//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001006
1007include "MipsInstrFPU.td"
Akira Hatanaka95934842011-09-24 01:34:44 +00001008include "Mips64InstrInfo.td"
Akira Hatanaka8ae330a2011-10-17 18:53:29 +00001009include "MipsCondMov.td"
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00001010