1//===- MipsInstrInfo.td - Target Description for Mips Target -*- tablegen -*-=//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the Mips implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14
15//===----------------------------------------------------------------------===//
16// Mips profiles and nodes
17//===----------------------------------------------------------------------===//
18
19def SDT_MipsJmpLink      : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
20def SDT_MipsCMov         : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
21                                                SDTCisSameAs<1, 2>,
22                                                SDTCisSameAs<3, 4>,
23                                                SDTCisInt<4>]>;
24def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
25def SDT_MipsCallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
26def SDT_MFLOHI : SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisVT<1, untyped>]>;
27def SDT_MTLOHI : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>,
28                                      SDTCisInt<1>, SDTCisSameAs<1, 2>]>;
29def SDT_MipsMultDiv : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>, SDTCisInt<1>,
30                                    SDTCisSameAs<1, 2>]>;
31def SDT_MipsMAddMSub : SDTypeProfile<1, 3,
32                                     [SDTCisVT<0, untyped>, SDTCisSameAs<0, 3>,
33                                      SDTCisVT<1, i32>, SDTCisSameAs<1, 2>]>;
34def SDT_MipsDivRem16 : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisSameAs<0, 1>]>;
35
36def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
37
38def SDT_Sync             : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
39
40def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
41                                   SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
42def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
43                                   SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
44                                   SDTCisSameAs<0, 4>]>;
45
46def SDTMipsLoadLR  : SDTypeProfile<1, 2,
47                                   [SDTCisInt<0>, SDTCisPtrTy<1>,
48                                    SDTCisSameAs<0, 2>]>;
49
50// Call
51def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
52                         [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
53                          SDNPVariadic]>;
54
55// Tail call
56def MipsTailCall : SDNode<"MipsISD::TailCall", SDT_MipsJmpLink,
57                          [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
58
59// Hi and Lo nodes are used to handle global addresses. Used on
60// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
61// static model. (nothing to do with Mips Registers Hi and Lo)
62def MipsHi    : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
63def MipsLo    : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
64def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
65
66// TlsGd node is used to handle General Dynamic TLS
67def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
68
69// TprelHi and TprelLo nodes are used to handle Local Exec TLS
70def MipsTprelHi    : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
71def MipsTprelLo    : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
72
73// Thread pointer
74def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
75
76// Return
77def MipsRet : SDNode<"MipsISD::Ret", SDTNone,
78                     [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
79
80def MipsERet : SDNode<"MipsISD::ERet", SDTNone,
81                      [SDNPHasChain, SDNPOptInGlue, SDNPSideEffect]>;
82
83// These are target-independent nodes, but have target-specific formats.
84def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
85                           [SDNPHasChain, SDNPSideEffect, SDNPOutGlue]>;
86def callseq_end   : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
87                           [SDNPHasChain, SDNPSideEffect,
88                            SDNPOptInGlue, SDNPOutGlue]>;
89
90// Nodes used to extract LO/HI registers.
91def MipsMFHI : SDNode<"MipsISD::MFHI", SDT_MFLOHI>;
92def MipsMFLO : SDNode<"MipsISD::MFLO", SDT_MFLOHI>;
93
94// Node used to insert 32-bit integers to LOHI register pair.
95def MipsMTLOHI : SDNode<"MipsISD::MTLOHI", SDT_MTLOHI>;
96
97// Mult nodes.
98def MipsMult  : SDNode<"MipsISD::Mult", SDT_MipsMultDiv>;
99def MipsMultu : SDNode<"MipsISD::Multu", SDT_MipsMultDiv>;
100
101// MAdd*/MSub* nodes
102def MipsMAdd  : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub>;
103def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub>;
104def MipsMSub  : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub>;
105def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub>;
106
107// DivRem(u) nodes
108def MipsDivRem    : SDNode<"MipsISD::DivRem", SDT_MipsMultDiv>;
109def MipsDivRemU   : SDNode<"MipsISD::DivRemU", SDT_MipsMultDiv>;
110def MipsDivRem16  : SDNode<"MipsISD::DivRem16", SDT_MipsDivRem16,
111                           [SDNPOutGlue]>;
112def MipsDivRemU16 : SDNode<"MipsISD::DivRemU16", SDT_MipsDivRem16,
113                           [SDNPOutGlue]>;
114
115// Target constant nodes that are not part of any isel patterns and remain
116// unchanged can cause instructions with illegal operands to be emitted.
117// Wrapper node patterns give the instruction selector a chance to replace
118// target constant nodes that would otherwise remain unchanged with ADDiu
119// nodes. Without these wrapper node patterns, the following conditional move
120// instruction is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
121// compiled:
122//  movn  %got(d)($gp), %got(c)($gp), $4
123// This instruction is illegal since movn can take only register operands.
124
125def MipsWrapper    : SDNode<"MipsISD::Wrapper", SDTIntBinOp>;
126
127def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain,SDNPSideEffect]>;
128
129def MipsExt :  SDNode<"MipsISD::Ext", SDT_Ext>;
130def MipsIns :  SDNode<"MipsISD::Ins", SDT_Ins>;
131
132def MipsLWL : SDNode<"MipsISD::LWL", SDTMipsLoadLR,
133                     [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
134def MipsLWR : SDNode<"MipsISD::LWR", SDTMipsLoadLR,
135                     [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
136def MipsSWL : SDNode<"MipsISD::SWL", SDTStore,
137                     [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
138def MipsSWR : SDNode<"MipsISD::SWR", SDTStore,
139                     [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
140def MipsLDL : SDNode<"MipsISD::LDL", SDTMipsLoadLR,
141                     [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
142def MipsLDR : SDNode<"MipsISD::LDR", SDTMipsLoadLR,
143                     [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
144def MipsSDL : SDNode<"MipsISD::SDL", SDTStore,
145                     [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
146def MipsSDR : SDNode<"MipsISD::SDR", SDTStore,
147                     [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
148
149//===----------------------------------------------------------------------===//
150// Mips Instruction Predicate Definitions.
151//===----------------------------------------------------------------------===//
152def HasMips2     :    Predicate<"Subtarget->hasMips2()">,
153                      AssemblerPredicate<"FeatureMips2">;
154def HasMips3_32  :    Predicate<"Subtarget->hasMips3_32()">,
155                      AssemblerPredicate<"FeatureMips3_32">;
156def HasMips3_32r2 :   Predicate<"Subtarget->hasMips3_32r2()">,
157                      AssemblerPredicate<"FeatureMips3_32r2">;
158def HasMips3     :    Predicate<"Subtarget->hasMips3()">,
159                      AssemblerPredicate<"FeatureMips3">;
160def HasMips4_32  :    Predicate<"Subtarget->hasMips4_32()">,
161                      AssemblerPredicate<"FeatureMips4_32">;
162def NotMips4_32  :    Predicate<"!Subtarget->hasMips4_32()">,
163                      AssemblerPredicate<"!FeatureMips4_32">;
164def HasMips4_32r2 :   Predicate<"Subtarget->hasMips4_32r2()">,
165                      AssemblerPredicate<"FeatureMips4_32r2">;
166def HasMips5_32r2 :   Predicate<"Subtarget->hasMips5_32r2()">,
167                      AssemblerPredicate<"FeatureMips5_32r2">;
168def HasMips32    :    Predicate<"Subtarget->hasMips32()">,
169                      AssemblerPredicate<"FeatureMips32">;
170def HasMips32r2  :    Predicate<"Subtarget->hasMips32r2()">,
171                      AssemblerPredicate<"FeatureMips32r2">;
172def HasMips32r5  :    Predicate<"Subtarget->hasMips32r5()">,
173                      AssemblerPredicate<"FeatureMips32r5">;
174def HasMips32r6  :    Predicate<"Subtarget->hasMips32r6()">,
175                      AssemblerPredicate<"FeatureMips32r6">;
176def NotMips32r6  :    Predicate<"!Subtarget->hasMips32r6()">,
177                      AssemblerPredicate<"!FeatureMips32r6">;
178def IsGP64bit    :    Predicate<"Subtarget->isGP64bit()">,
179                      AssemblerPredicate<"FeatureGP64Bit">;
180def IsGP32bit    :    Predicate<"!Subtarget->isGP64bit()">,
181                      AssemblerPredicate<"!FeatureGP64Bit">;
182def HasMips64    :    Predicate<"Subtarget->hasMips64()">,
183                      AssemblerPredicate<"FeatureMips64">;
184def NotMips64    :    Predicate<"!Subtarget->hasMips64()">,
185                      AssemblerPredicate<"!FeatureMips64">;
186def HasMips64r2  :    Predicate<"Subtarget->hasMips64r2()">,
187                      AssemblerPredicate<"FeatureMips64r2">;
188def HasMips64r6  :    Predicate<"Subtarget->hasMips64r6()">,
189                      AssemblerPredicate<"FeatureMips64r6">;
190def NotMips64r6  :    Predicate<"!Subtarget->hasMips64r6()">,
191                      AssemblerPredicate<"!FeatureMips64r6">;
192def HasMicroMips32r6 : Predicate<"Subtarget->inMicroMips32r6Mode()">,
193                       AssemblerPredicate<"FeatureMicroMips,FeatureMips32r6">;
194def HasMicroMips64r6 : Predicate<"Subtarget->inMicroMips64r6Mode()">,
195                       AssemblerPredicate<"FeatureMicroMips,FeatureMips64r6">;
196def InMips16Mode :    Predicate<"Subtarget->inMips16Mode()">,
197                      AssemblerPredicate<"FeatureMips16">;
198def HasCnMips    :    Predicate<"Subtarget->hasCnMips()">,
199                      AssemblerPredicate<"FeatureCnMips">;
200def RelocStatic :     Predicate<"TM.getRelocationModel() == Reloc::Static">;
201def RelocPIC    :     Predicate<"TM.getRelocationModel() == Reloc::PIC_">;
202def NoNaNsFPMath :    Predicate<"TM.Options.NoNaNsFPMath">;
203def HasStdEnc :       Predicate<"Subtarget->hasStandardEncoding()">,
204                      AssemblerPredicate<"!FeatureMips16">;
205def NotDSP :          Predicate<"!Subtarget->hasDSP()">;
206def InMicroMips    :  Predicate<"Subtarget->inMicroMipsMode()">,
207                      AssemblerPredicate<"FeatureMicroMips">;
208def NotInMicroMips :  Predicate<"!Subtarget->inMicroMipsMode()">,
209                      AssemblerPredicate<"!FeatureMicroMips">;
210def IsLE           :  Predicate<"Subtarget->isLittle()">;
211def IsBE           :  Predicate<"!Subtarget->isLittle()">;
212def IsNotNaCl    :    Predicate<"!Subtarget->isTargetNaCl()">;
213def UseTCCInDIV    :  AssemblerPredicate<"FeatureUseTCCInDIV">;
214def HasEVA       :    Predicate<"Subtarget->hasEVA()">,
215                      AssemblerPredicate<"FeatureEVA,FeatureMips32r2">;
216def HasMSA : Predicate<"Subtarget->hasMSA()">,
217             AssemblerPredicate<"FeatureMSA">;
218
219
220//===----------------------------------------------------------------------===//
221// Mips GPR size adjectives.
222// They are mutually exclusive.
223//===----------------------------------------------------------------------===//
224
225class GPR_32 { list<Predicate> GPRPredicates = [IsGP32bit]; }
226class GPR_64 { list<Predicate> GPRPredicates = [IsGP64bit]; }
227
228//===----------------------------------------------------------------------===//
229// Mips ISA/ASE membership and instruction group membership adjectives.
230// They are mutually exclusive.
231//===----------------------------------------------------------------------===//
232
233// FIXME: I'd prefer to use additive predicates to build the instruction sets
234//        but we are short on assembler feature bits at the moment. Using a
235//        subtractive predicate will hopefully keep us under the 32 predicate
236//        limit long enough to develop an alternative way to handle P1||P2
237//        predicates.
238class ISA_MIPS1_NOT_4_32 {
239  list<Predicate> InsnPredicates = [NotMips4_32];
240}
241class ISA_MIPS1_NOT_32R6_64R6 {
242  list<Predicate> InsnPredicates = [NotMips32r6, NotMips64r6];
243}
244class ISA_MIPS2    { list<Predicate> InsnPredicates = [HasMips2]; }
245class ISA_MIPS2_NOT_32R6_64R6 {
246  list<Predicate> InsnPredicates = [HasMips2, NotMips32r6, NotMips64r6];
247}
248class ISA_MIPS3    { list<Predicate> InsnPredicates = [HasMips3]; }
249class ISA_MIPS3_NOT_32R6_64R6 {
250  list<Predicate> InsnPredicates = [HasMips3, NotMips32r6, NotMips64r6];
251}
252class ISA_MIPS32   { list<Predicate> InsnPredicates = [HasMips32]; }
253class ISA_MIPS32_NOT_32R6_64R6 {
254  list<Predicate> InsnPredicates = [HasMips32, NotMips32r6, NotMips64r6];
255}
256class ISA_MIPS32R2 { list<Predicate> InsnPredicates = [HasMips32r2]; }
257class ISA_MIPS32R2_NOT_32R6_64R6 {
258  list<Predicate> InsnPredicates = [HasMips32r2, NotMips32r6, NotMips64r6];
259}
260class ISA_MIPS32R5 { list<Predicate> InsnPredicates = [HasMips32r5]; }
261class ISA_MIPS64   { list<Predicate> InsnPredicates = [HasMips64]; }
262class ISA_MIPS64_NOT_64R6 {
263  list<Predicate> InsnPredicates = [HasMips64, NotMips64r6];
264}
265class ISA_MIPS64R2 { list<Predicate> InsnPredicates = [HasMips64r2]; }
266class ISA_MIPS32R6 { list<Predicate> InsnPredicates = [HasMips32r6]; }
267class ISA_MIPS64R6 { list<Predicate> InsnPredicates = [HasMips64r6]; }
268class ISA_MICROMIPS { list<Predicate> InsnPredicates = [InMicroMips]; }
269class ISA_MICROMIPS32R6 {
270  list<Predicate> InsnPredicates = [HasMicroMips32r6];
271}
272class ISA_MICROMIPS64R6 {
273  list<Predicate> InsnPredicates = [HasMicroMips64r6];
274}
275class ISA_MICROMIPS32_NOT_MIPS32R6 {
276  list<Predicate> InsnPredicates = [InMicroMips, NotMips32r6];
277}
278
279class INSN_EVA { list<Predicate> InsnPredicates = [HasEVA]; }
280class INSN_EVA_NOT_32R6_64R6 {
281  list<Predicate> InsnPredicates = [NotMips32r6, NotMips64r6, HasEVA];
282}
283
284// The portions of MIPS-III that were also added to MIPS32
285class INSN_MIPS3_32 { list<Predicate> InsnPredicates = [HasMips3_32]; }
286
287// The portions of MIPS-III that were also added to MIPS32 but were removed in
288// MIPS32r6 and MIPS64r6.
289class INSN_MIPS3_32_NOT_32R6_64R6 {
290  list<Predicate> InsnPredicates = [HasMips3_32, NotMips32r6, NotMips64r6];
291}
292
293// The portions of MIPS-III that were also added to MIPS32
294class INSN_MIPS3_32R2 { list<Predicate> InsnPredicates = [HasMips3_32r2]; }
295
296// The portions of MIPS-IV that were also added to MIPS32 but were removed in
297// MIPS32r6 and MIPS64r6.
298class INSN_MIPS4_32_NOT_32R6_64R6 {
299  list<Predicate> InsnPredicates = [HasMips4_32, NotMips32r6, NotMips64r6];
300}
301
302// The portions of MIPS-IV that were also added to MIPS32r2 but were removed in
303// MIPS32r6 and MIPS64r6.
304class INSN_MIPS4_32R2_NOT_32R6_64R6 {
305  list<Predicate> InsnPredicates = [HasMips4_32r2, NotMips32r6, NotMips64r6];
306}
307
308// The portions of MIPS-V that were also added to MIPS32r2 but were removed in
309// MIPS32r6 and MIPS64r6.
310class INSN_MIPS5_32R2_NOT_32R6_64R6 {
311  list<Predicate> InsnPredicates = [HasMips5_32r2, NotMips32r6, NotMips64r6];
312}
313
314class ASE_CNMIPS {
315  list<Predicate> InsnPredicates = [HasCnMips];
316}
317
318class ASE_MSA {
319  list<Predicate> InsnPredicates = [HasMSA];
320}
321
322class ASE_MSA_NOT_MSA64 {
323  list<Predicate> InsnPredicates = [HasMSA, NotMips64];
324}
325
326class ASE_MSA64 {
327  list<Predicate> InsnPredicates = [HasMSA, HasMips64];
328}
329
330// Class used for separating microMIPSr6 and microMIPS (r3) instruction.
331// It can be used only on instructions that doesn't inherit PredicateControl.
332class ISA_MICROMIPS_NOT_32R6_64R6 : PredicateControl {
333  let InsnPredicates = [InMicroMips, NotMips32r6, NotMips64r6];
334}
335
336//===----------------------------------------------------------------------===//
337
338class MipsPat<dag pattern, dag result> : Pat<pattern, result>, PredicateControl {
339  let EncodingPredicates = [HasStdEnc];
340}
341
342class MipsInstAlias<string Asm, dag Result, bit Emit = 0b1> :
343  InstAlias<Asm, Result, Emit>, PredicateControl;
344
345class IsCommutable {
346  bit isCommutable = 1;
347}
348
349class IsBranch {
350  bit isBranch = 1;
351}
352
353class IsReturn {
354  bit isReturn = 1;
355}
356
357class IsCall {
358  bit isCall = 1;
359}
360
361class IsTailCall {
362  bit isCall = 1;
363  bit isTerminator = 1;
364  bit isReturn = 1;
365  bit isBarrier = 1;
366  bit hasExtraSrcRegAllocReq = 1;
367  bit isCodeGenOnly = 1;
368}
369
370class IsAsCheapAsAMove {
371  bit isAsCheapAsAMove = 1;
372}
373
374class NeverHasSideEffects {
375  bit hasSideEffects = 0;
376}
377
378//===----------------------------------------------------------------------===//
379// Instruction format superclass
380//===----------------------------------------------------------------------===//
381
382include "MipsInstrFormats.td"
383
384//===----------------------------------------------------------------------===//
385// Mips Operand, Complex Patterns and Transformations Definitions.
386//===----------------------------------------------------------------------===//
387
388class ConstantSImmAsmOperandClass<int Bits, list<AsmOperandClass> Supers = []>
389    : AsmOperandClass {
390  let Name = "ConstantSImm" # Bits;
391  let RenderMethod = "addImmOperands";
392  let PredicateMethod = "isConstantSImm<" # Bits # ">";
393  let SuperClasses = Supers;
394  let DiagnosticType = "SImm" # Bits;
395}
396
397class ConstantUImmAsmOperandClass<int Bits, list<AsmOperandClass> Supers = [],
398                                  int Offset = 0> : AsmOperandClass {
399  let Name = "ConstantUImm" # Bits # "_" # Offset;
400  let RenderMethod = "addConstantUImmOperands<" # Bits # ", " # Offset # ">";
401  let PredicateMethod = "isConstantUImm<" # Bits # ", " # Offset # ">";
402  let SuperClasses = Supers;
403  let DiagnosticType = "UImm" # Bits # "_" # Offset;
404}
405
406class ConstantUImmRangeAsmOperandClass<int Bottom, int Top,
407                                       list<AsmOperandClass> Supers = []>
408    : AsmOperandClass {
409  let Name = "ConstantUImmRange" # Bottom # "_" # Top;
410  let RenderMethod = "addImmOperands";
411  let PredicateMethod = "isConstantUImmRange<" # Bottom # ", " # Top # ">";
412  let SuperClasses = Supers;
413  let DiagnosticType = "UImmRange" # Bottom # "_" # Top;
414}
415
416class UImmAsmOperandClass<int Bits, list<AsmOperandClass> Supers = []>
417    : AsmOperandClass {
418  let Name = "UImm" # Bits;
419  let RenderMethod = "addUImmOperands<" # Bits # ">";
420  let PredicateMethod = "isUImm<" # Bits # ">";
421  let SuperClasses = Supers;
422  let DiagnosticType = "UImm" # Bits;
423}
424
425def UImm16RelaxedAsmOperandClass
426    : UImmAsmOperandClass<16, []> {
427  let Name = "UImm16_Relaxed";
428  let PredicateMethod = "isAnyImm<16>";
429  let DiagnosticType = "UImm16_Relaxed";
430}
431def UImm16AsmOperandClass
432    : UImmAsmOperandClass<16, [UImm16RelaxedAsmOperandClass]>;
433def ConstantUImm10AsmOperandClass
434    : ConstantUImmAsmOperandClass<10, [UImm16AsmOperandClass]>;
435def ConstantUImm8AsmOperandClass
436    : ConstantUImmAsmOperandClass<8, [ConstantUImm10AsmOperandClass]>;
437def ConstantUImm7AsmOperandClass
438    : ConstantUImmAsmOperandClass<7, [ConstantUImm8AsmOperandClass]>;
439def ConstantUImm6AsmOperandClass
440    : ConstantUImmAsmOperandClass<6, [ConstantUImm7AsmOperandClass]>;
441def ConstantSImm6AsmOperandClass
442    : ConstantSImmAsmOperandClass<6, [ConstantUImm7AsmOperandClass]>;
443def ConstantUImm5Plus1AsmOperandClass
444    : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass], 1>;
445def ConstantUImm5_Range2_64AsmOperandClass
446    : ConstantUImmRangeAsmOperandClass<2, 64, [ConstantUImm6AsmOperandClass]>;
447def ConstantUImm5Plus32AsmOperandClass
448    : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass], 32>;
449def ConstantUImm5Plus33AsmOperandClass
450    : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass], 33>;
451def ConstantUImm5Plus32NormalizeAsmOperandClass
452    : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass], 32> {
453  let Name = "ConstantUImm5_32_Norm";
454  // We must also subtract 32 when we render the operand.
455  let RenderMethod = "addConstantUImmOperands<5, 32, -32>";
456}
457def ConstantUImm5Lsl2AsmOperandClass : AsmOperandClass {
458  let Name = "UImm5Lsl2";
459  let RenderMethod = "addImmOperands";
460  let PredicateMethod = "isScaledUImm<5, 2>";
461  let SuperClasses = [ConstantUImm6AsmOperandClass];
462  let DiagnosticType = "UImm5_Lsl2";
463}
464def ConstantUImm5ReportUImm6AsmOperandClass
465    : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass]> {
466  let Name = "ConstantUImm5_0_Report_UImm6";
467  let DiagnosticType = "UImm5_0_Report_UImm6";
468}
469def ConstantUImm5AsmOperandClass
470    : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass]>;
471def ConstantUImm4AsmOperandClass
472    : ConstantUImmAsmOperandClass<
473          4, [ConstantUImm5AsmOperandClass,
474              ConstantUImm5Plus32AsmOperandClass,
475              ConstantUImm5Plus32NormalizeAsmOperandClass]>;
476def ConstantUImm3AsmOperandClass
477    : ConstantUImmAsmOperandClass<3, [ConstantUImm4AsmOperandClass]>;
478def ConstantUImm2Plus1AsmOperandClass
479    : ConstantUImmAsmOperandClass<2, [ConstantUImm3AsmOperandClass], 1>;
480def ConstantUImm2AsmOperandClass
481    : ConstantUImmAsmOperandClass<2, [ConstantUImm3AsmOperandClass]>;
482def ConstantUImm1AsmOperandClass
483    : ConstantUImmAsmOperandClass<1, [ConstantUImm2AsmOperandClass]>;
484def ConstantImmzAsmOperandClass : AsmOperandClass {
485  let Name = "ConstantImmz";
486  let RenderMethod = "addConstantUImmOperands<1>";
487  let PredicateMethod = "isConstantImmz";
488  let SuperClasses = [ConstantUImm1AsmOperandClass];
489  let DiagnosticType = "Immz";
490}
491
492def MipsJumpTargetAsmOperand : AsmOperandClass {
493  let Name = "JumpTarget";
494  let ParserMethod = "parseJumpTarget";
495  let PredicateMethod = "isImm";
496  let RenderMethod = "addImmOperands";
497}
498
499// Instruction operand types
500def jmptarget   : Operand<OtherVT> {
501  let EncoderMethod = "getJumpTargetOpValue";
502  let ParserMatchClass = MipsJumpTargetAsmOperand;
503}
504def brtarget    : Operand<OtherVT> {
505  let EncoderMethod = "getBranchTargetOpValue";
506  let OperandType = "OPERAND_PCREL";
507  let DecoderMethod = "DecodeBranchTarget";
508  let ParserMatchClass = MipsJumpTargetAsmOperand;
509}
510def calltarget  : Operand<iPTR> {
511  let EncoderMethod = "getJumpTargetOpValue";
512  let ParserMatchClass = MipsJumpTargetAsmOperand;
513}
514
515def imm64: Operand<i64>;
516
517def simm6 : Operand<i32> {
518  let ParserMatchClass = ConstantSImm6AsmOperandClass;
519  let OperandType = "OPERAND_IMMEDIATE";
520}
521def simm9 : Operand<i32>;
522def simm10 : Operand<i32>;
523def simm11 : Operand<i32>;
524
525def simm16      : Operand<i32> {
526  let DecoderMethod= "DecodeSimm16";
527}
528
529def simm19_lsl2 : Operand<i32> {
530  let EncoderMethod = "getSimm19Lsl2Encoding";
531  let DecoderMethod = "DecodeSimm19Lsl2";
532  let ParserMatchClass = MipsJumpTargetAsmOperand;
533}
534
535def simm18_lsl3 : Operand<i32> {
536  let EncoderMethod = "getSimm18Lsl3Encoding";
537  let DecoderMethod = "DecodeSimm18Lsl3";
538  let ParserMatchClass = MipsJumpTargetAsmOperand;
539}
540
541def simm20      : Operand<i32>;
542def simm32      : Operand<i32>;
543
544def uimm20      : Operand<i32> {
545}
546
547def simm16_64   : Operand<i64> {
548  let DecoderMethod = "DecodeSimm16";
549}
550
551// Zero
552def uimmz       : Operand<i32> {
553  let PrintMethod = "printUnsignedImm";
554  let ParserMatchClass = ConstantImmzAsmOperandClass;
555}
556
557// size operand of ins instruction
558def uimm_range_2_64 : Operand<i32> {
559  let PrintMethod = "printUnsignedImm";
560  let EncoderMethod = "getSizeInsEncoding";
561  let DecoderMethod = "DecodeInsSize";
562  let ParserMatchClass = ConstantUImm5_Range2_64AsmOperandClass;
563}
564
565// Unsigned Operands
566foreach I = {1, 2, 3, 4, 5, 6, 7, 8, 10} in
567  def uimm # I : Operand<i32> {
568    let PrintMethod = "printUnsignedImm";
569    let ParserMatchClass =
570        !cast<AsmOperandClass>("ConstantUImm" # I # "AsmOperandClass");
571  }
572
573def uimm2_plus1 : Operand<i32> {
574  let PrintMethod = "printUnsignedImm";
575  let EncoderMethod = "getUImmWithOffsetEncoding<2, 1>";
576  let DecoderMethod = "DecodeUImmWithOffset<2, 1>";
577  let ParserMatchClass = ConstantUImm2Plus1AsmOperandClass;
578}
579
580def uimm5_plus1 : Operand<i32> {
581  let PrintMethod = "printUnsignedImm";
582  let EncoderMethod = "getUImmWithOffsetEncoding<5, 1>";
583  let DecoderMethod = "DecodeUImmWithOffset<5, 1>";
584  let ParserMatchClass = ConstantUImm5Plus1AsmOperandClass;
585}
586
587def uimm5_plus32 : Operand<i32> {
588  let PrintMethod = "printUnsignedImm";
589  let ParserMatchClass = ConstantUImm5Plus32AsmOperandClass;
590}
591
592def uimm5_plus33 : Operand<i32> {
593  let PrintMethod = "printUnsignedImm";
594  let EncoderMethod = "getUImmWithOffsetEncoding<5, 1>";
595  let DecoderMethod = "DecodeUImmWithOffset<5, 1>";
596  let ParserMatchClass = ConstantUImm5Plus33AsmOperandClass;
597}
598
599def uimm5_inssize_plus1 : Operand<i32> {
600  let PrintMethod = "printUnsignedImm";
601  let ParserMatchClass = ConstantUImm5Plus1AsmOperandClass;
602  let EncoderMethod = "getSizeInsEncoding";
603  let DecoderMethod = "DecodeInsSize";
604}
605
606def uimm5_plus32_normalize : Operand<i32> {
607  let PrintMethod = "printUnsignedImm";
608  let ParserMatchClass = ConstantUImm5Plus32NormalizeAsmOperandClass;
609}
610
611def uimm5_lsl2 : Operand<OtherVT> {
612  let EncoderMethod = "getUImm5Lsl2Encoding";
613  let DecoderMethod = "DecodeUImm5lsl2";
614  let ParserMatchClass = ConstantUImm5Lsl2AsmOperandClass;
615}
616
617def uimm5_plus32_normalize_64 : Operand<i64> {
618  let PrintMethod = "printUnsignedImm";
619  let ParserMatchClass = ConstantUImm5Plus32NormalizeAsmOperandClass;
620}
621
622foreach I = {16} in
623  def uimm # I : Operand<i32> {
624    let PrintMethod = "printUnsignedImm";
625    let ParserMatchClass =
626        !cast<AsmOperandClass>("UImm" # I # "AsmOperandClass");
627  }
628
629// Like uimm16_64 but coerces simm16 to uimm16.
630def uimm16_relaxed : Operand<i32> {
631  let PrintMethod = "printUnsignedImm";
632  let ParserMatchClass =
633      !cast<AsmOperandClass>("UImm16RelaxedAsmOperandClass");
634}
635
636foreach I = {5} in
637  def uimm # I # _64 : Operand<i64> {
638    let PrintMethod = "printUnsignedImm";
639    let ParserMatchClass =
640        !cast<AsmOperandClass>("ConstantUImm" # I # "AsmOperandClass");
641  }
642
643def uimm16_64 : Operand<i64> {
644  let PrintMethod = "printUnsignedImm";
645  let ParserMatchClass =
646      !cast<AsmOperandClass>("UImm16AsmOperandClass");
647}
648
649// Like uimm16_64 but coerces simm16 to uimm16.
650def uimm16_64_relaxed : Operand<i64> {
651  let PrintMethod = "printUnsignedImm";
652  let ParserMatchClass =
653      !cast<AsmOperandClass>("UImm16RelaxedAsmOperandClass");
654}
655
656// Like uimm5_64 but reports a less confusing error for 32-63 when
657// an instruction alias permits that.
658def uimm5_64_report_uimm6 : Operand<i64> {
659  let PrintMethod = "printUnsignedImm";
660  let ParserMatchClass = ConstantUImm5ReportUImm6AsmOperandClass;
661}
662
663def pcrel16      : Operand<i32> {
664}
665
666def MipsMemAsmOperand : AsmOperandClass {
667  let Name = "Mem";
668  let ParserMethod = "parseMemOperand";
669}
670
671def MipsMemSimm9AsmOperand : AsmOperandClass {
672  let Name = "MemOffsetSimm9";
673  let SuperClasses = [MipsMemAsmOperand];
674  let RenderMethod = "addMemOperands";
675  let ParserMethod = "parseMemOperand";
676  let PredicateMethod = "isMemWithSimmOffset<9>";
677}
678
679def MipsMemSimm9GPRAsmOperand : AsmOperandClass {
680  let Name = "MemOffsetSimm9GPR";
681  let SuperClasses = [MipsMemAsmOperand];
682  let RenderMethod = "addMemOperands";
683  let ParserMethod = "parseMemOperand";
684  let PredicateMethod = "isMemWithSimmOffsetGPR<9>";
685}
686
687def MipsMemSimm11AsmOperand : AsmOperandClass {
688  let Name = "MemOffsetSimm11";
689  let SuperClasses = [MipsMemAsmOperand];
690  let RenderMethod = "addMemOperands";
691  let ParserMethod = "parseMemOperand";
692  let PredicateMethod = "isMemWithSimmOffset<11>";
693}
694
695def MipsMemSimm16AsmOperand : AsmOperandClass {
696  let Name = "MemOffsetSimm16";
697  let SuperClasses = [MipsMemAsmOperand];
698  let RenderMethod = "addMemOperands";
699  let ParserMethod = "parseMemOperand";
700  let PredicateMethod = "isMemWithSimmOffset<16>";
701}
702
703def MipsInvertedImmoperand : AsmOperandClass {
704  let Name = "InvNum";
705  let RenderMethod = "addImmOperands";
706  let ParserMethod = "parseInvNum";
707}
708
709def InvertedImOperand : Operand<i32> {
710  let ParserMatchClass = MipsInvertedImmoperand;
711}
712
713def InvertedImOperand64 : Operand<i64> {
714  let ParserMatchClass = MipsInvertedImmoperand;
715}
716
717class mem_generic : Operand<iPTR> {
718  let PrintMethod = "printMemOperand";
719  let MIOperandInfo = (ops ptr_rc, simm16);
720  let EncoderMethod = "getMemEncoding";
721  let ParserMatchClass = MipsMemAsmOperand;
722  let OperandType = "OPERAND_MEMORY";
723}
724
725// Address operand
726def mem : mem_generic;
727
728// MSA specific address operand
729def mem_msa : mem_generic {
730  let MIOperandInfo = (ops ptr_rc, simm10);
731  let EncoderMethod = "getMSAMemEncoding";
732}
733
734def mem_simm9 : mem_generic {
735  let MIOperandInfo = (ops ptr_rc, simm9);
736  let EncoderMethod = "getMemEncoding";
737  let ParserMatchClass = MipsMemSimm9AsmOperand;
738}
739
740def mem_simm9gpr : mem_generic {
741  let MIOperandInfo = (ops ptr_rc, simm9);
742  let EncoderMethod = "getMemEncoding";
743  let ParserMatchClass = MipsMemSimm9GPRAsmOperand;
744}
745
746def mem_simm11 : mem_generic {
747  let MIOperandInfo = (ops ptr_rc, simm11);
748  let EncoderMethod = "getMemEncoding";
749  let ParserMatchClass = MipsMemSimm11AsmOperand;
750}
751
752def mem_simm16 : mem_generic {
753  let MIOperandInfo = (ops ptr_rc, simm16);
754  let EncoderMethod = "getMemEncoding";
755  let ParserMatchClass = MipsMemSimm16AsmOperand;
756}
757
758def mem_ea : Operand<iPTR> {
759  let PrintMethod = "printMemOperandEA";
760  let MIOperandInfo = (ops ptr_rc, simm16);
761  let EncoderMethod = "getMemEncoding";
762  let OperandType = "OPERAND_MEMORY";
763}
764
765def PtrRC : Operand<iPTR> {
766  let MIOperandInfo = (ops ptr_rc);
767  let DecoderMethod = "DecodePtrRegisterClass";
768  let ParserMatchClass = GPR32AsmOperand;
769}
770
771// size operand of ins instruction
772def size_ins : Operand<i32> {
773  let EncoderMethod = "getSizeInsEncoding";
774  let DecoderMethod = "DecodeInsSize";
775}
776
777// Transformation Function - get the lower 16 bits.
778def LO16 : SDNodeXForm<imm, [{
779  return getImm(N, N->getZExtValue() & 0xFFFF);
780}]>;
781
782// Transformation Function - get the higher 16 bits.
783def HI16 : SDNodeXForm<imm, [{
784  return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
785}]>;
786
787// Plus 1.
788def Plus1 : SDNodeXForm<imm, [{ return getImm(N, N->getSExtValue() + 1); }]>;
789
790// Node immediate is zero (e.g. insve.d)
791def immz : PatLeaf<(imm), [{ return N->getSExtValue() == 0; }]>;
792
793// Node immediate fits as 16-bit sign extended on target immediate.
794// e.g. addi, andi
795def immSExt8  : PatLeaf<(imm), [{ return isInt<8>(N->getSExtValue()); }]>;
796
797// Node immediate fits as 16-bit sign extended on target immediate.
798// e.g. addi, andi
799def immSExt16  : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
800
801// Node immediate fits as 15-bit sign extended on target immediate.
802// e.g. addi, andi
803def immSExt15  : PatLeaf<(imm), [{ return isInt<15>(N->getSExtValue()); }]>;
804
805// Node immediate fits as 7-bit zero extended on target immediate.
806def immZExt7 : PatLeaf<(imm), [{ return isUInt<7>(N->getZExtValue()); }]>;
807
808// Node immediate fits as 16-bit zero extended on target immediate.
809// The LO16 param means that only the lower 16 bits of the node
810// immediate are caught.
811// e.g. addiu, sltiu
812def immZExt16  : PatLeaf<(imm), [{
813  if (N->getValueType(0) == MVT::i32)
814    return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
815  else
816    return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
817}], LO16>;
818
819// Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared).
820def immLow16Zero : PatLeaf<(imm), [{
821  int64_t Val = N->getSExtValue();
822  return isInt<32>(Val) && !(Val & 0xffff);
823}]>;
824
825// shamt field must fit in 5 bits.
826def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
827
828// True if (N + 1) fits in 16-bit field.
829def immSExt16Plus1 : PatLeaf<(imm), [{
830  return isInt<17>(N->getSExtValue()) && isInt<16>(N->getSExtValue() + 1);
831}]>;
832
833// Mips Address Mode! SDNode frameindex could possibily be a match
834// since load and store instructions from stack used it.
835def addr :
836  ComplexPattern<iPTR, 2, "selectIntAddr", [frameindex]>;
837
838def addrRegImm :
839  ComplexPattern<iPTR, 2, "selectAddrRegImm", [frameindex]>;
840
841def addrRegReg :
842  ComplexPattern<iPTR, 2, "selectAddrRegReg", [frameindex]>;
843
844def addrDefault :
845  ComplexPattern<iPTR, 2, "selectAddrDefault", [frameindex]>;
846
847def addrimm10 : ComplexPattern<iPTR, 2, "selectIntAddrMSA", [frameindex]>;
848
849//===----------------------------------------------------------------------===//
850// Instructions specific format
851//===----------------------------------------------------------------------===//
852
853// Arithmetic and logical instructions with 3 register operands.
854class ArithLogicR<string opstr, RegisterOperand RO, bit isComm = 0,
855                  InstrItinClass Itin = NoItinerary,
856                  SDPatternOperator OpNode = null_frag>:
857  InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
858         !strconcat(opstr, "\t$rd, $rs, $rt"),
859         [(set RO:$rd, (OpNode RO:$rs, RO:$rt))], Itin, FrmR, opstr> {
860  let isCommutable = isComm;
861  let isReMaterializable = 1;
862  let TwoOperandAliasConstraint = "$rd = $rs";
863}
864
865// Arithmetic and logical instructions with 2 register operands.
866class ArithLogicI<string opstr, Operand Od, RegisterOperand RO,
867                  InstrItinClass Itin = NoItinerary,
868                  SDPatternOperator imm_type = null_frag,
869                  SDPatternOperator OpNode = null_frag> :
870  InstSE<(outs RO:$rt), (ins RO:$rs, Od:$imm16),
871         !strconcat(opstr, "\t$rt, $rs, $imm16"),
872         [(set RO:$rt, (OpNode RO:$rs, imm_type:$imm16))],
873         Itin, FrmI, opstr> {
874  let isReMaterializable = 1;
875  let TwoOperandAliasConstraint = "$rs = $rt";
876}
877
878// Arithmetic Multiply ADD/SUB
879class MArithR<string opstr, InstrItinClass itin, bit isComm = 0> :
880  InstSE<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
881         !strconcat(opstr, "\t$rs, $rt"), [], itin, FrmR, opstr> {
882  let Defs = [HI0, LO0];
883  let Uses = [HI0, LO0];
884  let isCommutable = isComm;
885}
886
887//  Logical
888class LogicNOR<string opstr, RegisterOperand RO>:
889  InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
890         !strconcat(opstr, "\t$rd, $rs, $rt"),
891         [(set RO:$rd, (not (or RO:$rs, RO:$rt)))], II_NOR, FrmR, opstr> {
892  let isCommutable = 1;
893}
894
895// Shifts
896class shift_rotate_imm<string opstr, Operand ImmOpnd,
897                       RegisterOperand RO, InstrItinClass itin,
898                       SDPatternOperator OpNode = null_frag,
899                       SDPatternOperator PF = null_frag> :
900  InstSE<(outs RO:$rd), (ins RO:$rt, ImmOpnd:$shamt),
901         !strconcat(opstr, "\t$rd, $rt, $shamt"),
902         [(set RO:$rd, (OpNode RO:$rt, PF:$shamt))], itin, FrmR, opstr> {
903  let TwoOperandAliasConstraint = "$rt = $rd";
904}
905
906class shift_rotate_reg<string opstr, RegisterOperand RO, InstrItinClass itin,
907                       SDPatternOperator OpNode = null_frag>:
908  InstSE<(outs RO:$rd), (ins RO:$rt, GPR32Opnd:$rs),
909         !strconcat(opstr, "\t$rd, $rt, $rs"),
910         [(set RO:$rd, (OpNode RO:$rt, GPR32Opnd:$rs))], itin, FrmR,
911         opstr>;
912
913// Load Upper Immediate
914class LoadUpper<string opstr, RegisterOperand RO, Operand Imm>:
915  InstSE<(outs RO:$rt), (ins Imm:$imm16), !strconcat(opstr, "\t$rt, $imm16"),
916         [], II_LUI, FrmI, opstr>, IsAsCheapAsAMove {
917  let hasSideEffects = 0;
918  let isReMaterializable = 1;
919}
920
921// Memory Load/Store
922class Load<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
923           InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
924  InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
925         [(set RO:$rt, (OpNode Addr:$addr))], Itin, FrmI, opstr> {
926  let DecoderMethod = "DecodeMem";
927  let canFoldAsLoad = 1;
928  let mayLoad = 1;
929}
930
931class StoreMemory<string opstr, DAGOperand RO, DAGOperand MO,
932            SDPatternOperator OpNode = null_frag,
933            InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
934  InstSE<(outs), (ins RO:$rt, MO:$addr), !strconcat(opstr, "\t$rt, $addr"),
935         [(OpNode RO:$rt, Addr:$addr)], Itin, FrmI, opstr> {
936  let DecoderMethod = "DecodeMem";
937  let mayStore = 1;
938}
939
940class Store<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
941            InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
942  StoreMemory<opstr, RO, mem, OpNode, Itin, Addr>;
943
944// Load/Store Left/Right
945let canFoldAsLoad = 1 in
946class LoadLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
947                    InstrItinClass Itin> :
948  InstSE<(outs RO:$rt), (ins mem:$addr, RO:$src),
949         !strconcat(opstr, "\t$rt, $addr"),
950         [(set RO:$rt, (OpNode addr:$addr, RO:$src))], Itin, FrmI> {
951  let DecoderMethod = "DecodeMem";
952  string Constraints = "$src = $rt";
953}
954
955class StoreLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
956                     InstrItinClass Itin> :
957  InstSE<(outs), (ins RO:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
958         [(OpNode RO:$rt, addr:$addr)], Itin, FrmI> {
959  let DecoderMethod = "DecodeMem";
960}
961
962// COP2 Load/Store
963class LW_FT2<string opstr, RegisterOperand RC, InstrItinClass Itin,
964             SDPatternOperator OpNode= null_frag> :
965  InstSE<(outs RC:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
966         [(set RC:$rt, (OpNode addrDefault:$addr))], Itin, FrmFI, opstr> {
967  let DecoderMethod = "DecodeFMem2";
968  let mayLoad = 1;
969}
970
971class SW_FT2<string opstr, RegisterOperand RC, InstrItinClass Itin,
972             SDPatternOperator OpNode= null_frag> :
973  InstSE<(outs), (ins RC:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
974         [(OpNode RC:$rt, addrDefault:$addr)], Itin, FrmFI, opstr> {
975  let DecoderMethod = "DecodeFMem2";
976  let mayStore = 1;
977}
978
979// COP3 Load/Store
980class LW_FT3<string opstr, RegisterOperand RC, InstrItinClass Itin,
981             SDPatternOperator OpNode= null_frag> :
982  InstSE<(outs RC:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
983         [(set RC:$rt, (OpNode addrDefault:$addr))], Itin, FrmFI, opstr> {
984  let DecoderMethod = "DecodeFMem3";
985  let mayLoad = 1;
986}
987
988class SW_FT3<string opstr, RegisterOperand RC, InstrItinClass Itin,
989             SDPatternOperator OpNode= null_frag> :
990  InstSE<(outs), (ins RC:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
991         [(OpNode RC:$rt, addrDefault:$addr)], Itin, FrmFI, opstr> {
992  let DecoderMethod = "DecodeFMem3";
993  let mayStore = 1;
994}
995
996// Conditional Branch
997class CBranch<string opstr, DAGOperand opnd, PatFrag cond_op,
998              RegisterOperand RO, bit DelaySlot = 1> :
999  InstSE<(outs), (ins RO:$rs, RO:$rt, opnd:$offset),
1000         !strconcat(opstr, "\t$rs, $rt, $offset"),
1001         [(brcond (i32 (cond_op RO:$rs, RO:$rt)), bb:$offset)], II_BCC,
1002         FrmI, opstr> {
1003  let isBranch = 1;
1004  let isTerminator = 1;
1005  let hasDelaySlot = DelaySlot;
1006  let Defs = [AT];
1007}
1008
1009class CBranchZero<string opstr, DAGOperand opnd, PatFrag cond_op,
1010                  RegisterOperand RO, bit DelaySlot = 1> :
1011  InstSE<(outs), (ins RO:$rs, opnd:$offset),
1012         !strconcat(opstr, "\t$rs, $offset"),
1013         [(brcond (i32 (cond_op RO:$rs, 0)), bb:$offset)], II_BCCZ,
1014         FrmI, opstr> {
1015  let isBranch = 1;
1016  let isTerminator = 1;
1017  let hasDelaySlot = DelaySlot;
1018  let Defs = [AT];
1019}
1020
1021// SetCC
1022class SetCC_R<string opstr, PatFrag cond_op, RegisterOperand RO> :
1023  InstSE<(outs GPR32Opnd:$rd), (ins RO:$rs, RO:$rt),
1024         !strconcat(opstr, "\t$rd, $rs, $rt"),
1025         [(set GPR32Opnd:$rd, (cond_op RO:$rs, RO:$rt))],
1026         II_SLT_SLTU, FrmR, opstr>;
1027
1028class SetCC_I<string opstr, PatFrag cond_op, Operand Od, PatLeaf imm_type,
1029              RegisterOperand RO>:
1030  InstSE<(outs GPR32Opnd:$rt), (ins RO:$rs, Od:$imm16),
1031         !strconcat(opstr, "\t$rt, $rs, $imm16"),
1032         [(set GPR32Opnd:$rt, (cond_op RO:$rs, imm_type:$imm16))],
1033         II_SLTI_SLTIU, FrmI, opstr>;
1034
1035// Jump
1036class JumpFJ<DAGOperand opnd, string opstr, SDPatternOperator operator,
1037             SDPatternOperator targetoperator, string bopstr> :
1038  InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
1039         [(operator targetoperator:$target)], II_J, FrmJ, bopstr> {
1040  let isTerminator=1;
1041  let isBarrier=1;
1042  let hasDelaySlot = 1;
1043  let DecoderMethod = "DecodeJumpTarget";
1044  let Defs = [AT];
1045}
1046
1047// Unconditional branch
1048class UncondBranch<Instruction BEQInst> :
1049  PseudoSE<(outs), (ins brtarget:$offset), [(br bb:$offset)], II_B>,
1050  PseudoInstExpansion<(BEQInst ZERO, ZERO, brtarget:$offset)> {
1051  let isBranch = 1;
1052  let isTerminator = 1;
1053  let isBarrier = 1;
1054  let hasDelaySlot = 1;
1055  let AdditionalPredicates = [RelocPIC];
1056  let Defs = [AT];
1057}
1058
1059// Base class for indirect branch and return instruction classes.
1060let isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
1061class JumpFR<string opstr, RegisterOperand RO,
1062             SDPatternOperator operator = null_frag>:
1063  InstSE<(outs), (ins RO:$rs), "jr\t$rs", [(operator RO:$rs)], II_JR,
1064         FrmR, opstr>;
1065
1066// Indirect branch
1067class IndirectBranch<string opstr, RegisterOperand RO> : JumpFR<opstr, RO> {
1068  let isBranch = 1;
1069  let isIndirectBranch = 1;
1070}
1071
1072// Jump and Link (Call)
1073let isCall=1, hasDelaySlot=1, Defs = [RA] in {
1074  class JumpLink<string opstr, DAGOperand opnd> :
1075    InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
1076           [(MipsJmpLink tglobaladdr:$target)], II_JAL, FrmJ, opstr> {
1077    let DecoderMethod = "DecodeJumpTarget";
1078  }
1079
1080  class JumpLinkRegPseudo<RegisterOperand RO, Instruction JALRInst,
1081                          Register RetReg, RegisterOperand ResRO = RO>:
1082    PseudoSE<(outs), (ins RO:$rs), [(MipsJmpLink RO:$rs)], II_JALR>,
1083    PseudoInstExpansion<(JALRInst RetReg, ResRO:$rs)>;
1084
1085  class JumpLinkReg<string opstr, RegisterOperand RO>:
1086    InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
1087           [], II_JALR, FrmR, opstr>;
1088
1089  class BGEZAL_FT<string opstr, DAGOperand opnd,
1090                  RegisterOperand RO, bit DelaySlot = 1> :
1091    InstSE<(outs), (ins RO:$rs, opnd:$offset),
1092           !strconcat(opstr, "\t$rs, $offset"), [], II_BCCZAL, FrmI, opstr> {
1093    let hasDelaySlot = DelaySlot;
1094  }
1095
1096}
1097
1098let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, hasDelaySlot = 1,
1099    hasExtraSrcRegAllocReq = 1, Defs = [AT] in {
1100  class TailCall<Instruction JumpInst> :
1101    PseudoSE<(outs), (ins calltarget:$target), [], II_J>,
1102    PseudoInstExpansion<(JumpInst jmptarget:$target)>;
1103
1104  class TailCallReg<RegisterOperand RO, Instruction JRInst,
1105                    RegisterOperand ResRO = RO> :
1106    PseudoSE<(outs), (ins RO:$rs), [(MipsTailCall RO:$rs)], II_JR>,
1107    PseudoInstExpansion<(JRInst ResRO:$rs)>;
1108}
1109
1110class BAL_BR_Pseudo<Instruction RealInst> :
1111  PseudoSE<(outs), (ins brtarget:$offset), [], II_BCCZAL>,
1112  PseudoInstExpansion<(RealInst ZERO, brtarget:$offset)> {
1113  let isBranch = 1;
1114  let isTerminator = 1;
1115  let isBarrier = 1;
1116  let hasDelaySlot = 1;
1117  let Defs = [RA];
1118}
1119
1120// Syscall
1121class SYS_FT<string opstr> :
1122  InstSE<(outs), (ins uimm20:$code_),
1123         !strconcat(opstr, "\t$code_"), [], NoItinerary, FrmI, opstr>;
1124// Break
1125class BRK_FT<string opstr> :
1126  InstSE<(outs), (ins uimm10:$code_1, uimm10:$code_2),
1127         !strconcat(opstr, "\t$code_1, $code_2"), [], NoItinerary,
1128         FrmOther, opstr>;
1129
1130// (D)Eret
1131class ER_FT<string opstr> :
1132  InstSE<(outs), (ins),
1133         opstr, [], NoItinerary, FrmOther, opstr>;
1134
1135// Interrupts
1136class DEI_FT<string opstr, RegisterOperand RO> :
1137  InstSE<(outs RO:$rt), (ins),
1138         !strconcat(opstr, "\t$rt"), [], NoItinerary, FrmOther, opstr>;
1139
1140// Wait
1141class WAIT_FT<string opstr> :
1142  InstSE<(outs), (ins), opstr, [], NoItinerary, FrmOther, opstr>;
1143
1144// Sync
1145let hasSideEffects = 1 in
1146class SYNC_FT<string opstr> :
1147  InstSE<(outs), (ins i32imm:$stype), "sync $stype", [(MipsSync imm:$stype)],
1148         NoItinerary, FrmOther, opstr>;
1149
1150class SYNCI_FT<string opstr> :
1151  InstSE<(outs), (ins mem_simm16:$addr), !strconcat(opstr, "\t$addr"), [],
1152         NoItinerary, FrmOther, opstr> {
1153  let hasSideEffects = 1;
1154  let DecoderMethod = "DecodeSyncI";
1155}
1156
1157class TEQ_FT<string opstr, RegisterOperand RO, Operand ImmOp> :
1158  InstSE<(outs), (ins RO:$rs, RO:$rt, ImmOp:$code_),
1159         !strconcat(opstr, "\t$rs, $rt, $code_"), [], NoItinerary,
1160         FrmI, opstr> {
1161  let hasSideEffects = 1;
1162}
1163
1164class TEQI_FT<string opstr, RegisterOperand RO> :
1165  InstSE<(outs), (ins RO:$rs, simm16:$imm16),
1166         !strconcat(opstr, "\t$rs, $imm16"), [], NoItinerary, FrmOther, opstr> {
1167  let hasSideEffects = 1;
1168}
1169
1170// Mul, Div
1171class Mult<string opstr, InstrItinClass itin, RegisterOperand RO,
1172           list<Register> DefRegs> :
1173  InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$rs, $rt"), [],
1174         itin, FrmR, opstr> {
1175  let isCommutable = 1;
1176  let Defs = DefRegs;
1177  let hasSideEffects = 0;
1178}
1179
1180// Pseudo multiply/divide instruction with explicit accumulator register
1181// operands.
1182class MultDivPseudo<Instruction RealInst, RegisterClass R0, RegisterOperand R1,
1183                    SDPatternOperator OpNode, InstrItinClass Itin,
1184                    bit IsComm = 1, bit HasSideEffects = 0,
1185                    bit UsesCustomInserter = 0> :
1186  PseudoSE<(outs R0:$ac), (ins R1:$rs, R1:$rt),
1187           [(set R0:$ac, (OpNode R1:$rs, R1:$rt))], Itin>,
1188  PseudoInstExpansion<(RealInst R1:$rs, R1:$rt)> {
1189  let isCommutable = IsComm;
1190  let hasSideEffects = HasSideEffects;
1191  let usesCustomInserter = UsesCustomInserter;
1192}
1193
1194// Pseudo multiply add/sub instruction with explicit accumulator register
1195// operands.
1196class MAddSubPseudo<Instruction RealInst, SDPatternOperator OpNode,
1197                    InstrItinClass itin>
1198  : PseudoSE<(outs ACC64:$ac),
1199             (ins GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin),
1200             [(set ACC64:$ac,
1201              (OpNode GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin))],
1202             itin>,
1203    PseudoInstExpansion<(RealInst GPR32Opnd:$rs, GPR32Opnd:$rt)> {
1204  string Constraints = "$acin = $ac";
1205}
1206
1207class Div<string opstr, InstrItinClass itin, RegisterOperand RO,
1208          list<Register> DefRegs> :
1209  InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$$zero, $rs, $rt"),
1210         [], itin, FrmR, opstr> {
1211  let Defs = DefRegs;
1212}
1213
1214// Move from Hi/Lo
1215class PseudoMFLOHI<RegisterClass DstRC, RegisterClass SrcRC, SDNode OpNode>
1216  : PseudoSE<(outs DstRC:$rd), (ins SrcRC:$hilo),
1217             [(set DstRC:$rd, (OpNode SrcRC:$hilo))], II_MFHI_MFLO>;
1218
1219class MoveFromLOHI<string opstr, RegisterOperand RO, Register UseReg>:
1220  InstSE<(outs RO:$rd), (ins), !strconcat(opstr, "\t$rd"), [], II_MFHI_MFLO,
1221         FrmR, opstr> {
1222  let Uses = [UseReg];
1223  let hasSideEffects = 0;
1224}
1225
1226class PseudoMTLOHI<RegisterClass DstRC, RegisterClass SrcRC>
1227  : PseudoSE<(outs DstRC:$lohi), (ins SrcRC:$lo, SrcRC:$hi),
1228             [(set DstRC:$lohi, (MipsMTLOHI SrcRC:$lo, SrcRC:$hi))],
1229             II_MTHI_MTLO>;
1230
1231class MoveToLOHI<string opstr, RegisterOperand RO, list<Register> DefRegs>:
1232  InstSE<(outs), (ins RO:$rs), !strconcat(opstr, "\t$rs"), [], II_MTHI_MTLO,
1233  FrmR, opstr> {
1234  let Defs = DefRegs;
1235  let hasSideEffects = 0;
1236}
1237
1238class EffectiveAddress<string opstr, RegisterOperand RO> :
1239  InstSE<(outs RO:$rt), (ins mem_ea:$addr), !strconcat(opstr, "\t$rt, $addr"),
1240         [(set RO:$rt, addr:$addr)], NoItinerary, FrmI,
1241         !strconcat(opstr, "_lea")> {
1242  let isCodeGenOnly = 1;
1243  let DecoderMethod = "DecodeMem";
1244}
1245
1246// Count Leading Ones/Zeros in Word
1247class CountLeading0<string opstr, RegisterOperand RO>:
1248  InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
1249         [(set RO:$rd, (ctlz RO:$rs))], II_CLZ, FrmR, opstr>;
1250
1251class CountLeading1<string opstr, RegisterOperand RO>:
1252  InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
1253         [(set RO:$rd, (ctlz (not RO:$rs)))], II_CLO, FrmR, opstr>;
1254
1255// Sign Extend in Register.
1256class SignExtInReg<string opstr, ValueType vt, RegisterOperand RO,
1257                   InstrItinClass itin> :
1258  InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"),
1259         [(set RO:$rd, (sext_inreg RO:$rt, vt))], itin, FrmR, opstr>;
1260
1261// Subword Swap
1262class SubwordSwap<string opstr, RegisterOperand RO,
1263                  InstrItinClass itin = NoItinerary>:
1264  InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"), [], itin,
1265         FrmR, opstr> {
1266  let hasSideEffects = 0;
1267}
1268
1269// Read Hardware
1270class ReadHardware<RegisterOperand CPURegOperand, RegisterOperand RO> :
1271  InstSE<(outs CPURegOperand:$rt), (ins RO:$rd), "rdhwr\t$rt, $rd", [],
1272         II_RDHWR, FrmR, "rdhwr">;
1273
1274// Ext and Ins
1275class ExtBase<string opstr, RegisterOperand RO, Operand PosOpnd,
1276              Operand SizeOpnd, SDPatternOperator Op = null_frag> :
1277  InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, SizeOpnd:$size),
1278         !strconcat(opstr, " $rt, $rs, $pos, $size"),
1279         [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size))], II_EXT,
1280         FrmR, opstr>, ISA_MIPS32R2;
1281
1282class InsBase<string opstr, RegisterOperand RO, Operand PosOpnd,
1283              Operand SizeOpnd, SDPatternOperator Op = null_frag>:
1284  InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, SizeOpnd:$size, RO:$src),
1285         !strconcat(opstr, " $rt, $rs, $pos, $size"),
1286         [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size, RO:$src))],
1287         II_INS, FrmR, opstr>, ISA_MIPS32R2 {
1288  let Constraints = "$src = $rt";
1289}
1290
1291// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
1292class Atomic2Ops<PatFrag Op, RegisterClass DRC> :
1293  PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$incr),
1294           [(set DRC:$dst, (Op iPTR:$ptr, DRC:$incr))]>;
1295
1296// Atomic Compare & Swap.
1297class AtomicCmpSwap<PatFrag Op, RegisterClass DRC> :
1298  PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$cmp, DRC:$swap),
1299           [(set DRC:$dst, (Op iPTR:$ptr, DRC:$cmp, DRC:$swap))]>;
1300
1301class LLBase<string opstr, RegisterOperand RO> :
1302  InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
1303         [], NoItinerary, FrmI> {
1304  let DecoderMethod = "DecodeMem";
1305  let mayLoad = 1;
1306}
1307
1308class SCBase<string opstr, RegisterOperand RO> :
1309  InstSE<(outs RO:$dst), (ins RO:$rt, mem:$addr),
1310         !strconcat(opstr, "\t$rt, $addr"), [], NoItinerary, FrmI> {
1311  let DecoderMethod = "DecodeMem";
1312  let mayStore = 1;
1313  let Constraints = "$rt = $dst";
1314}
1315
1316class MFC3OP<string asmstr, RegisterOperand RO, RegisterOperand RD> :
1317  InstSE<(outs RO:$rt), (ins RD:$rd, uimm16:$sel),
1318         !strconcat(asmstr, "\t$rt, $rd, $sel"), [], NoItinerary, FrmFR>;
1319
1320class MTC3OP<string asmstr, RegisterOperand RO, RegisterOperand RD> :
1321  InstSE<(outs RO:$rd), (ins RD:$rt, uimm16:$sel),
1322         !strconcat(asmstr, "\t$rt, $rd, $sel"), [], NoItinerary, FrmFR>;
1323
1324class TrapBase<Instruction RealInst>
1325  : PseudoSE<(outs), (ins), [(trap)], NoItinerary>,
1326    PseudoInstExpansion<(RealInst 0, 0)> {
1327  let isBarrier = 1;
1328  let isTerminator = 1;
1329  let isCodeGenOnly = 1;
1330}
1331
1332//===----------------------------------------------------------------------===//
1333// Pseudo instructions
1334//===----------------------------------------------------------------------===//
1335
1336// Return RA.
1337let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1 in
1338def RetRA : PseudoSE<(outs), (ins), [(MipsRet)]>;
1339
1340let isReturn=1, isTerminator=1, isBarrier=1, hasCtrlDep=1, hasSideEffects=1 in
1341def ERet : PseudoSE<(outs), (ins), [(MipsERet)]>;
1342
1343let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
1344def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins i32imm:$amt),
1345                                  [(callseq_start timm:$amt)]>;
1346def ADJCALLSTACKUP   : MipsPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
1347                                  [(callseq_end timm:$amt1, timm:$amt2)]>;
1348}
1349
1350let usesCustomInserter = 1 in {
1351  def ATOMIC_LOAD_ADD_I8   : Atomic2Ops<atomic_load_add_8, GPR32>;
1352  def ATOMIC_LOAD_ADD_I16  : Atomic2Ops<atomic_load_add_16, GPR32>;
1353  def ATOMIC_LOAD_ADD_I32  : Atomic2Ops<atomic_load_add_32, GPR32>;
1354  def ATOMIC_LOAD_SUB_I8   : Atomic2Ops<atomic_load_sub_8, GPR32>;
1355  def ATOMIC_LOAD_SUB_I16  : Atomic2Ops<atomic_load_sub_16, GPR32>;
1356  def ATOMIC_LOAD_SUB_I32  : Atomic2Ops<atomic_load_sub_32, GPR32>;
1357  def ATOMIC_LOAD_AND_I8   : Atomic2Ops<atomic_load_and_8, GPR32>;
1358  def ATOMIC_LOAD_AND_I16  : Atomic2Ops<atomic_load_and_16, GPR32>;
1359  def ATOMIC_LOAD_AND_I32  : Atomic2Ops<atomic_load_and_32, GPR32>;
1360  def ATOMIC_LOAD_OR_I8    : Atomic2Ops<atomic_load_or_8, GPR32>;
1361  def ATOMIC_LOAD_OR_I16   : Atomic2Ops<atomic_load_or_16, GPR32>;
1362  def ATOMIC_LOAD_OR_I32   : Atomic2Ops<atomic_load_or_32, GPR32>;
1363  def ATOMIC_LOAD_XOR_I8   : Atomic2Ops<atomic_load_xor_8, GPR32>;
1364  def ATOMIC_LOAD_XOR_I16  : Atomic2Ops<atomic_load_xor_16, GPR32>;
1365  def ATOMIC_LOAD_XOR_I32  : Atomic2Ops<atomic_load_xor_32, GPR32>;
1366  def ATOMIC_LOAD_NAND_I8  : Atomic2Ops<atomic_load_nand_8, GPR32>;
1367  def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, GPR32>;
1368  def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, GPR32>;
1369
1370  def ATOMIC_SWAP_I8       : Atomic2Ops<atomic_swap_8, GPR32>;
1371  def ATOMIC_SWAP_I16      : Atomic2Ops<atomic_swap_16, GPR32>;
1372  def ATOMIC_SWAP_I32      : Atomic2Ops<atomic_swap_32, GPR32>;
1373
1374  def ATOMIC_CMP_SWAP_I8   : AtomicCmpSwap<atomic_cmp_swap_8, GPR32>;
1375  def ATOMIC_CMP_SWAP_I16  : AtomicCmpSwap<atomic_cmp_swap_16, GPR32>;
1376  def ATOMIC_CMP_SWAP_I32  : AtomicCmpSwap<atomic_cmp_swap_32, GPR32>;
1377}
1378
1379/// Pseudo instructions for loading and storing accumulator registers.
1380let isPseudo = 1, isCodeGenOnly = 1 in {
1381  def LOAD_ACC64  : Load<"", ACC64>;
1382  def STORE_ACC64 : Store<"", ACC64>;
1383}
1384
1385// We need these two pseudo instructions to avoid offset calculation for long
1386// branches.  See the comment in file MipsLongBranch.cpp for detailed
1387// explanation.
1388
1389// Expands to: lui $dst, %hi($tgt - $baltgt)
1390def LONG_BRANCH_LUi : PseudoSE<(outs GPR32Opnd:$dst),
1391  (ins brtarget:$tgt, brtarget:$baltgt), []>;
1392
1393// Expands to: addiu $dst, $src, %lo($tgt - $baltgt)
1394def LONG_BRANCH_ADDiu : PseudoSE<(outs GPR32Opnd:$dst),
1395  (ins GPR32Opnd:$src, brtarget:$tgt, brtarget:$baltgt), []>;
1396
1397//===----------------------------------------------------------------------===//
1398// Instruction definition
1399//===----------------------------------------------------------------------===//
1400//===----------------------------------------------------------------------===//
1401// MipsI Instructions
1402//===----------------------------------------------------------------------===//
1403
1404/// Arithmetic Instructions (ALU Immediate)
1405let AdditionalPredicates = [NotInMicroMips] in {
1406def ADDiu : MMRel, StdMMR6Rel, ArithLogicI<"addiu", simm16, GPR32Opnd,
1407                                           II_ADDIU, immSExt16, add>,
1408            ADDI_FM<0x9>, IsAsCheapAsAMove;
1409}
1410def ADDi  : MMRel, ArithLogicI<"addi", simm16, GPR32Opnd>, ADDI_FM<0x8>,
1411            ISA_MIPS1_NOT_32R6_64R6;
1412def SLTi  : MMRel, SetCC_I<"slti", setlt, simm16, immSExt16, GPR32Opnd>,
1413            SLTI_FM<0xa>;
1414def SLTiu : MMRel, SetCC_I<"sltiu", setult, simm16, immSExt16, GPR32Opnd>,
1415            SLTI_FM<0xb>;
1416let AdditionalPredicates = [NotInMicroMips] in {
1417def ANDi  : MMRel, StdMMR6Rel,
1418            ArithLogicI<"andi", uimm16, GPR32Opnd, II_ANDI, immZExt16, and>,
1419            ADDI_FM<0xc>;
1420}
1421def ORi   : MMRel, StdMMR6Rel,
1422            ArithLogicI<"ori", uimm16, GPR32Opnd, II_ORI, immZExt16, or>,
1423            ADDI_FM<0xd>;
1424def XORi  : MMRel, StdMMR6Rel,
1425            ArithLogicI<"xori", uimm16, GPR32Opnd, II_XORI, immZExt16, xor>,
1426            ADDI_FM<0xe>;
1427def LUi   : MMRel, LoadUpper<"lui", GPR32Opnd, uimm16_relaxed>, LUI_FM;
1428let AdditionalPredicates = [NotInMicroMips] in {
1429/// Arithmetic Instructions (3-Operand, R-Type)
1430def ADDu  : MMRel, StdMMR6Rel, ArithLogicR<"addu", GPR32Opnd, 1, II_ADDU, add>,
1431            ADD_FM<0, 0x21>;
1432def SUBu  : MMRel, ArithLogicR<"subu", GPR32Opnd, 0, II_SUBU, sub>,
1433            ADD_FM<0, 0x23>;
1434}
1435let Defs = [HI0, LO0] in
1436def MUL   : MMRel, ArithLogicR<"mul", GPR32Opnd, 1, II_MUL, mul>,
1437            ADD_FM<0x1c, 2>, ISA_MIPS32_NOT_32R6_64R6;
1438def ADD   : MMRel, StdMMR6Rel, ArithLogicR<"add", GPR32Opnd>, ADD_FM<0, 0x20>;
1439def SUB   : MMRel, ArithLogicR<"sub", GPR32Opnd>, ADD_FM<0, 0x22>;
1440def SLT   : MMRel, SetCC_R<"slt", setlt, GPR32Opnd>, ADD_FM<0, 0x2a>;
1441def SLTu  : MMRel, SetCC_R<"sltu", setult, GPR32Opnd>, ADD_FM<0, 0x2b>;
1442let AdditionalPredicates = [NotInMicroMips] in {
1443def AND   : MMRel, StdMMR6Rel, ArithLogicR<"and", GPR32Opnd, 1, II_AND, and>,
1444            ADD_FM<0, 0x24>;
1445def OR    : MMRel, StdMMR6Rel, ArithLogicR<"or", GPR32Opnd, 1, II_OR, or>,
1446            ADD_FM<0, 0x25>;
1447def XOR   : MMRel, StdMMR6Rel, ArithLogicR<"xor", GPR32Opnd, 1, II_XOR, xor>,
1448            ADD_FM<0, 0x26>;
1449}
1450def NOR   : MMRel, StdMMR6Rel, LogicNOR<"nor", GPR32Opnd>, ADD_FM<0, 0x27>;
1451
1452/// Shift Instructions
1453let AdditionalPredicates = [NotInMicroMips] in {
1454def SLL  : MMRel, shift_rotate_imm<"sll", uimm5, GPR32Opnd, II_SLL, shl,
1455                                   immZExt5>, SRA_FM<0, 0>;
1456def SRL  : MMRel, shift_rotate_imm<"srl", uimm5, GPR32Opnd, II_SRL, srl,
1457                                   immZExt5>, SRA_FM<2, 0>;
1458}
1459def SRA  : MMRel, shift_rotate_imm<"sra", uimm5, GPR32Opnd, II_SRA, sra,
1460                                   immZExt5>, SRA_FM<3, 0>;
1461def SLLV : MMRel, shift_rotate_reg<"sllv", GPR32Opnd, II_SLLV, shl>,
1462           SRLV_FM<4, 0>;
1463def SRLV : MMRel, shift_rotate_reg<"srlv", GPR32Opnd, II_SRLV, srl>,
1464           SRLV_FM<6, 0>;
1465def SRAV : MMRel, shift_rotate_reg<"srav", GPR32Opnd, II_SRAV, sra>,
1466           SRLV_FM<7, 0>;
1467
1468// Rotate Instructions
1469def ROTR  : MMRel, shift_rotate_imm<"rotr", uimm5, GPR32Opnd, II_ROTR, rotr,
1470                                    immZExt5>,
1471            SRA_FM<2, 1>, ISA_MIPS32R2;
1472def ROTRV : MMRel, shift_rotate_reg<"rotrv", GPR32Opnd, II_ROTRV, rotr>,
1473            SRLV_FM<6, 1>, ISA_MIPS32R2;
1474
1475/// Load and Store Instructions
1476///  aligned
1477def LB  : Load<"lb", GPR32Opnd, sextloadi8, II_LB>, MMRel, LW_FM<0x20>;
1478def LBu : Load<"lbu", GPR32Opnd, zextloadi8, II_LBU, addrDefault>, MMRel,
1479          LW_FM<0x24>;
1480def LH  : Load<"lh", GPR32Opnd, sextloadi16, II_LH, addrDefault>, MMRel,
1481          LW_FM<0x21>;
1482def LHu : Load<"lhu", GPR32Opnd, zextloadi16, II_LHU>, MMRel, LW_FM<0x25>;
1483let AdditionalPredicates = [NotInMicroMips] in {
1484def LW  : StdMMR6Rel, Load<"lw", GPR32Opnd, load, II_LW, addrDefault>, MMRel,
1485          LW_FM<0x23>;
1486}
1487def SB  : StdMMR6Rel, Store<"sb", GPR32Opnd, truncstorei8, II_SB>, MMRel,
1488          LW_FM<0x28>;
1489def SH  : Store<"sh", GPR32Opnd, truncstorei16, II_SH>, MMRel, LW_FM<0x29>;
1490let AdditionalPredicates = [NotInMicroMips] in {
1491def SW  : Store<"sw", GPR32Opnd, store, II_SW>, MMRel, LW_FM<0x2b>;
1492}
1493
1494/// load/store left/right
1495let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1496    AdditionalPredicates = [NotInMicroMips] in {
1497def LWL : LoadLeftRight<"lwl", MipsLWL, GPR32Opnd, II_LWL>, LW_FM<0x22>,
1498          ISA_MIPS1_NOT_32R6_64R6;
1499def LWR : LoadLeftRight<"lwr", MipsLWR, GPR32Opnd, II_LWR>, LW_FM<0x26>,
1500          ISA_MIPS1_NOT_32R6_64R6;
1501def SWL : StoreLeftRight<"swl", MipsSWL, GPR32Opnd, II_SWL>, LW_FM<0x2a>,
1502          ISA_MIPS1_NOT_32R6_64R6;
1503def SWR : StoreLeftRight<"swr", MipsSWR, GPR32Opnd, II_SWR>, LW_FM<0x2e>,
1504          ISA_MIPS1_NOT_32R6_64R6;
1505}
1506
1507let AdditionalPredicates = [NotInMicroMips] in {
1508// COP2 Memory Instructions
1509def LWC2 : LW_FT2<"lwc2", COP2Opnd, NoItinerary, load>, LW_FM<0x32>,
1510           ISA_MIPS1_NOT_32R6_64R6;
1511def SWC2 : SW_FT2<"swc2", COP2Opnd, NoItinerary, store>, LW_FM<0x3a>,
1512           ISA_MIPS1_NOT_32R6_64R6;
1513def LDC2 : LW_FT2<"ldc2", COP2Opnd, NoItinerary, load>, LW_FM<0x36>,
1514           ISA_MIPS2_NOT_32R6_64R6;
1515def SDC2 : SW_FT2<"sdc2", COP2Opnd, NoItinerary, store>, LW_FM<0x3e>,
1516           ISA_MIPS2_NOT_32R6_64R6;
1517
1518// COP3 Memory Instructions
1519let DecoderNamespace = "COP3_" in {
1520  def LWC3 : LW_FT3<"lwc3", COP3Opnd, NoItinerary, load>, LW_FM<0x33>;
1521  def SWC3 : SW_FT3<"swc3", COP3Opnd, NoItinerary, store>, LW_FM<0x3b>;
1522  def LDC3 : LW_FT3<"ldc3", COP3Opnd, NoItinerary, load>, LW_FM<0x37>,
1523             ISA_MIPS2;
1524  def SDC3 : SW_FT3<"sdc3", COP3Opnd, NoItinerary, store>, LW_FM<0x3f>,
1525             ISA_MIPS2;
1526}
1527}
1528
1529def SYNC : MMRel, StdMMR6Rel, SYNC_FT<"sync">, SYNC_FM, ISA_MIPS32;
1530def SYNCI : MMRel, StdMMR6Rel, SYNCI_FT<"synci">, SYNCI_FM, ISA_MIPS32R2;
1531
1532let AdditionalPredicates = [NotInMicroMips] in {
1533  def TEQ : MMRel, TEQ_FT<"teq", GPR32Opnd, uimm10>, TEQ_FM<0x34>, ISA_MIPS2;
1534  def TGE : MMRel, TEQ_FT<"tge", GPR32Opnd, uimm10>, TEQ_FM<0x30>, ISA_MIPS2;
1535  def TGEU : MMRel, TEQ_FT<"tgeu", GPR32Opnd, uimm10>, TEQ_FM<0x31>, ISA_MIPS2;
1536  def TLT : MMRel, TEQ_FT<"tlt", GPR32Opnd, uimm10>, TEQ_FM<0x32>, ISA_MIPS2;
1537  def TLTU : MMRel, TEQ_FT<"tltu", GPR32Opnd, uimm10>, TEQ_FM<0x33>, ISA_MIPS2;
1538  def TNE : MMRel, TEQ_FT<"tne", GPR32Opnd, uimm10>, TEQ_FM<0x36>, ISA_MIPS2;
1539}
1540
1541def TEQI : MMRel, TEQI_FT<"teqi", GPR32Opnd>, TEQI_FM<0xc>,
1542           ISA_MIPS2_NOT_32R6_64R6;
1543def TGEI : MMRel, TEQI_FT<"tgei", GPR32Opnd>, TEQI_FM<0x8>,
1544           ISA_MIPS2_NOT_32R6_64R6;
1545def TGEIU : MMRel, TEQI_FT<"tgeiu", GPR32Opnd>, TEQI_FM<0x9>,
1546           ISA_MIPS2_NOT_32R6_64R6;
1547def TLTI : MMRel, TEQI_FT<"tlti", GPR32Opnd>, TEQI_FM<0xa>,
1548           ISA_MIPS2_NOT_32R6_64R6;
1549def TTLTIU : MMRel, TEQI_FT<"tltiu", GPR32Opnd>, TEQI_FM<0xb>,
1550           ISA_MIPS2_NOT_32R6_64R6;
1551def TNEI : MMRel, TEQI_FT<"tnei", GPR32Opnd>, TEQI_FM<0xe>,
1552           ISA_MIPS2_NOT_32R6_64R6;
1553
1554let AdditionalPredicates = [NotInMicroMips] in {
1555def BREAK : MMRel, StdMMR6Rel, BRK_FT<"break">, BRK_FM<0xd>;
1556}
1557def SYSCALL : MMRel, SYS_FT<"syscall">, SYS_FM<0xc>;
1558def TRAP : TrapBase<BREAK>;
1559def SDBBP : MMRel, SYS_FT<"sdbbp">, SDBBP_FM, ISA_MIPS32_NOT_32R6_64R6;
1560
1561let AdditionalPredicates = [NotInMicroMips] in {
1562  def ERET : MMRel, ER_FT<"eret">, ER_FM<0x18, 0x0>, INSN_MIPS3_32;
1563  def ERETNC : MMRel, ER_FT<"eretnc">, ER_FM<0x18, 0x1>, ISA_MIPS32R5;
1564  def DERET : MMRel, ER_FT<"deret">, ER_FM<0x1f, 0x0>, ISA_MIPS32;
1565}
1566
1567let AdditionalPredicates = [NotInMicroMips] in {
1568  def EI : MMRel, StdMMR6Rel, DEI_FT<"ei", GPR32Opnd>, EI_FM<1>, ISA_MIPS32R2;
1569  def DI : MMRel, StdMMR6Rel, DEI_FT<"di", GPR32Opnd>, EI_FM<0>, ISA_MIPS32R2;
1570}
1571
1572let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1573    AdditionalPredicates = [NotInMicroMips] in {
1574def WAIT : WAIT_FT<"wait">, WAIT_FM;
1575
1576/// Load-linked, Store-conditional
1577def LL : LLBase<"ll", GPR32Opnd>, LW_FM<0x30>, ISA_MIPS2_NOT_32R6_64R6;
1578def SC : SCBase<"sc", GPR32Opnd>, LW_FM<0x38>, ISA_MIPS2_NOT_32R6_64R6;
1579}
1580
1581/// Jump and Branch Instructions
1582def J       : MMRel, JumpFJ<jmptarget, "j", br, bb, "j">, FJ<2>,
1583              AdditionalRequires<[RelocStatic]>, IsBranch;
1584def JR      : MMRel, IndirectBranch<"jr", GPR32Opnd>, MTLO_FM<8>;
1585def BEQ     : MMRel, CBranch<"beq", brtarget, seteq, GPR32Opnd>, BEQ_FM<4>;
1586def BEQL    : MMRel, CBranch<"beql", brtarget, seteq, GPR32Opnd, 0>,
1587              BEQ_FM<20>, ISA_MIPS2_NOT_32R6_64R6;
1588def BNE     : MMRel, CBranch<"bne", brtarget, setne, GPR32Opnd>, BEQ_FM<5>;
1589def BNEL    : MMRel, CBranch<"bnel", brtarget, setne, GPR32Opnd, 0>,
1590              BEQ_FM<21>, ISA_MIPS2_NOT_32R6_64R6;
1591def BGEZ    : MMRel, CBranchZero<"bgez", brtarget, setge, GPR32Opnd>,
1592              BGEZ_FM<1, 1>;
1593def BGEZL   : MMRel, CBranchZero<"bgezl", brtarget, setge, GPR32Opnd, 0>,
1594              BGEZ_FM<1, 3>, ISA_MIPS2_NOT_32R6_64R6;
1595def BGTZ    : MMRel, CBranchZero<"bgtz", brtarget, setgt, GPR32Opnd>,
1596              BGEZ_FM<7, 0>;
1597def BGTZL   : MMRel, CBranchZero<"bgtzl", brtarget, setgt, GPR32Opnd, 0>,
1598              BGEZ_FM<23, 0>, ISA_MIPS2_NOT_32R6_64R6;
1599def BLEZ    : MMRel, CBranchZero<"blez", brtarget, setle, GPR32Opnd>,
1600              BGEZ_FM<6, 0>;
1601def BLEZL   : MMRel, CBranchZero<"blezl", brtarget, setle, GPR32Opnd, 0>,
1602              BGEZ_FM<22, 0>, ISA_MIPS2_NOT_32R6_64R6;
1603def BLTZ    : MMRel, CBranchZero<"bltz", brtarget, setlt, GPR32Opnd>,
1604              BGEZ_FM<1, 0>;
1605def BLTZL   : MMRel, CBranchZero<"bltzl", brtarget, setlt, GPR32Opnd, 0>,
1606              BGEZ_FM<1, 2>, ISA_MIPS2_NOT_32R6_64R6;
1607def B       : UncondBranch<BEQ>;
1608
1609def JAL  : MMRel, JumpLink<"jal", calltarget>, FJ<3>;
1610let AdditionalPredicates = [NotInMicroMips] in {
1611  def JALR : JumpLinkReg<"jalr", GPR32Opnd>, JALR_FM;
1612  def JALRPseudo : JumpLinkRegPseudo<GPR32Opnd, JALR, RA>;
1613}
1614
1615def JALX : MMRel, JumpLink<"jalx", calltarget>, FJ<0x1D>,
1616           ISA_MIPS32_NOT_32R6_64R6;
1617def BGEZAL : MMRel, BGEZAL_FT<"bgezal", brtarget, GPR32Opnd>, BGEZAL_FM<0x11>,
1618             ISA_MIPS1_NOT_32R6_64R6;
1619def BGEZALL : MMRel, BGEZAL_FT<"bgezall", brtarget, GPR32Opnd, 0>,
1620              BGEZAL_FM<0x13>, ISA_MIPS2_NOT_32R6_64R6;
1621def BLTZAL : MMRel, BGEZAL_FT<"bltzal", brtarget, GPR32Opnd>, BGEZAL_FM<0x10>,
1622             ISA_MIPS1_NOT_32R6_64R6;
1623def BLTZALL : MMRel, BGEZAL_FT<"bltzall", brtarget, GPR32Opnd, 0>,
1624              BGEZAL_FM<0x12>, ISA_MIPS2_NOT_32R6_64R6;
1625def BAL_BR : BAL_BR_Pseudo<BGEZAL>;
1626def TAILCALL : TailCall<J>;
1627def TAILCALL_R : TailCallReg<GPR32Opnd, JR>;
1628
1629// Indirect branches are matched as PseudoIndirectBranch/PseudoIndirectBranch64
1630// then are expanded to JR, JR64, JALR, or JALR64 depending on the ISA.
1631class PseudoIndirectBranchBase<RegisterOperand RO> :
1632    MipsPseudo<(outs), (ins RO:$rs), [(brind RO:$rs)],
1633               II_IndirectBranchPseudo> {
1634  let isTerminator=1;
1635  let isBarrier=1;
1636  let hasDelaySlot = 1;
1637  let isBranch = 1;
1638  let isIndirectBranch = 1;
1639}
1640
1641def PseudoIndirectBranch : PseudoIndirectBranchBase<GPR32Opnd>;
1642
1643// Return instructions are matched as a RetRA instruction, then are expanded
1644// into PseudoReturn/PseudoReturn64 after register allocation. Finally,
1645// MipsAsmPrinter expands this into JR, JR64, JALR, or JALR64 depending on the
1646// ISA.
1647class PseudoReturnBase<RegisterOperand RO> : MipsPseudo<(outs), (ins RO:$rs),
1648                                                        [], II_ReturnPseudo> {
1649  let isTerminator = 1;
1650  let isBarrier = 1;
1651  let hasDelaySlot = 1;
1652  let isReturn = 1;
1653  let isCodeGenOnly = 1;
1654  let hasCtrlDep = 1;
1655  let hasExtraSrcRegAllocReq = 1;
1656}
1657
1658def PseudoReturn : PseudoReturnBase<GPR32Opnd>;
1659
1660// Exception handling related node and instructions.
1661// The conversion sequence is:
1662// ISD::EH_RETURN -> MipsISD::EH_RETURN ->
1663// MIPSeh_return -> (stack change + indirect branch)
1664//
1665// MIPSeh_return takes the place of regular return instruction
1666// but takes two arguments (V1, V0) which are used for storing
1667// the offset and return address respectively.
1668def SDT_MipsEHRET : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisPtrTy<1>]>;
1669
1670def MIPSehret : SDNode<"MipsISD::EH_RETURN", SDT_MipsEHRET,
1671                      [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
1672
1673let Uses = [V0, V1], isTerminator = 1, isReturn = 1, isBarrier = 1 in {
1674  def MIPSeh_return32 : MipsPseudo<(outs), (ins GPR32:$spoff, GPR32:$dst),
1675                                [(MIPSehret GPR32:$spoff, GPR32:$dst)]>;
1676  def MIPSeh_return64 : MipsPseudo<(outs), (ins GPR64:$spoff,
1677                                                GPR64:$dst),
1678                                [(MIPSehret GPR64:$spoff, GPR64:$dst)]>;
1679}
1680
1681/// Multiply and Divide Instructions.
1682def MULT  : MMRel, Mult<"mult", II_MULT, GPR32Opnd, [HI0, LO0]>,
1683            MULT_FM<0, 0x18>, ISA_MIPS1_NOT_32R6_64R6;
1684def MULTu : MMRel, Mult<"multu", II_MULTU, GPR32Opnd, [HI0, LO0]>,
1685            MULT_FM<0, 0x19>, ISA_MIPS1_NOT_32R6_64R6;
1686def SDIV  : MMRel, Div<"div", II_DIV, GPR32Opnd, [HI0, LO0]>,
1687            MULT_FM<0, 0x1a>, ISA_MIPS1_NOT_32R6_64R6;
1688def UDIV  : MMRel, Div<"divu", II_DIVU, GPR32Opnd, [HI0, LO0]>,
1689            MULT_FM<0, 0x1b>, ISA_MIPS1_NOT_32R6_64R6;
1690
1691def MTHI : MMRel, MoveToLOHI<"mthi", GPR32Opnd, [HI0]>, MTLO_FM<0x11>,
1692           ISA_MIPS1_NOT_32R6_64R6;
1693def MTLO : MMRel, MoveToLOHI<"mtlo", GPR32Opnd, [LO0]>, MTLO_FM<0x13>,
1694           ISA_MIPS1_NOT_32R6_64R6;
1695let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1696    AdditionalPredicates = [NotInMicroMips] in {
1697def MFHI : MMRel, MoveFromLOHI<"mfhi", GPR32Opnd, AC0>, MFLO_FM<0x10>,
1698           ISA_MIPS1_NOT_32R6_64R6;
1699def MFLO : MMRel, MoveFromLOHI<"mflo", GPR32Opnd, AC0>, MFLO_FM<0x12>,
1700           ISA_MIPS1_NOT_32R6_64R6;
1701}
1702
1703/// Sign Ext In Register Instructions.
1704def SEB : MMRel, StdMMR6Rel, SignExtInReg<"seb", i8, GPR32Opnd, II_SEB>,
1705          SEB_FM<0x10, 0x20>, ISA_MIPS32R2;
1706def SEH : MMRel, StdMMR6Rel, SignExtInReg<"seh", i16, GPR32Opnd, II_SEH>,
1707          SEB_FM<0x18, 0x20>, ISA_MIPS32R2;
1708
1709/// Count Leading
1710def CLZ : MMRel, CountLeading0<"clz", GPR32Opnd>, CLO_FM<0x20>,
1711          ISA_MIPS32_NOT_32R6_64R6;
1712def CLO : MMRel, CountLeading1<"clo", GPR32Opnd>, CLO_FM<0x21>,
1713          ISA_MIPS32_NOT_32R6_64R6;
1714
1715let AdditionalPredicates = [NotInMicroMips] in {
1716  /// Word Swap Bytes Within Halfwords
1717  def WSBH : MMRel, SubwordSwap<"wsbh", GPR32Opnd, II_WSBH>, SEB_FM<2, 0x20>,
1718             ISA_MIPS32R2;
1719}
1720
1721/// No operation.
1722def NOP : PseudoSE<(outs), (ins), []>, PseudoInstExpansion<(SLL ZERO, ZERO, 0)>;
1723
1724// FrameIndexes are legalized when they are operands from load/store
1725// instructions. The same not happens for stack address copies, so an
1726// add op with mem ComplexPattern is used and the stack address copy
1727// can be matched. It's similar to Sparc LEA_ADDRi
1728def LEA_ADDiu : MMRel, EffectiveAddress<"addiu", GPR32Opnd>, LW_FM<9>;
1729
1730// MADD*/MSUB*
1731def MADD  : MMRel, MArithR<"madd", II_MADD, 1>, MULT_FM<0x1c, 0>,
1732            ISA_MIPS32_NOT_32R6_64R6;
1733def MADDU : MMRel, MArithR<"maddu", II_MADDU, 1>, MULT_FM<0x1c, 1>,
1734            ISA_MIPS32_NOT_32R6_64R6;
1735def MSUB  : MMRel, MArithR<"msub", II_MSUB>, MULT_FM<0x1c, 4>,
1736            ISA_MIPS32_NOT_32R6_64R6;
1737def MSUBU : MMRel, MArithR<"msubu", II_MSUBU>, MULT_FM<0x1c, 5>,
1738            ISA_MIPS32_NOT_32R6_64R6;
1739
1740let AdditionalPredicates = [NotDSP] in {
1741def PseudoMULT  : MultDivPseudo<MULT, ACC64, GPR32Opnd, MipsMult, II_MULT>,
1742                  ISA_MIPS1_NOT_32R6_64R6;
1743def PseudoMULTu : MultDivPseudo<MULTu, ACC64, GPR32Opnd, MipsMultu, II_MULTU>,
1744                  ISA_MIPS1_NOT_32R6_64R6;
1745def PseudoMFHI : PseudoMFLOHI<GPR32, ACC64, MipsMFHI>, ISA_MIPS1_NOT_32R6_64R6;
1746def PseudoMFLO : PseudoMFLOHI<GPR32, ACC64, MipsMFLO>, ISA_MIPS1_NOT_32R6_64R6;
1747def PseudoMTLOHI : PseudoMTLOHI<ACC64, GPR32>, ISA_MIPS1_NOT_32R6_64R6;
1748def PseudoMADD  : MAddSubPseudo<MADD, MipsMAdd, II_MADD>,
1749                  ISA_MIPS32_NOT_32R6_64R6;
1750def PseudoMADDU : MAddSubPseudo<MADDU, MipsMAddu, II_MADDU>,
1751                  ISA_MIPS32_NOT_32R6_64R6;
1752def PseudoMSUB  : MAddSubPseudo<MSUB, MipsMSub, II_MSUB>,
1753                  ISA_MIPS32_NOT_32R6_64R6;
1754def PseudoMSUBU : MAddSubPseudo<MSUBU, MipsMSubu, II_MSUBU>,
1755                  ISA_MIPS32_NOT_32R6_64R6;
1756}
1757
1758def PseudoSDIV : MultDivPseudo<SDIV, ACC64, GPR32Opnd, MipsDivRem, II_DIV,
1759                               0, 1, 1>, ISA_MIPS1_NOT_32R6_64R6;
1760def PseudoUDIV : MultDivPseudo<UDIV, ACC64, GPR32Opnd, MipsDivRemU, II_DIVU,
1761                               0, 1, 1>, ISA_MIPS1_NOT_32R6_64R6;
1762let AdditionalPredicates = [NotInMicroMips] in {
1763def RDHWR : MMRel, ReadHardware<GPR32Opnd, HWRegsOpnd>, RDHWR_FM;
1764}
1765// TODO: Add '0 < pos+size <= 32' constraint check to ext instruction
1766def EXT : MMRel, ExtBase<"ext", GPR32Opnd, uimm5, uimm5_plus1, MipsExt>,
1767          EXT_FM<0>;
1768def INS : MMRel, InsBase<"ins", GPR32Opnd, uimm5, uimm5_inssize_plus1, MipsIns>,
1769          EXT_FM<4>;
1770
1771/// Move Control Registers From/To CPU Registers
1772def MFC0 : MFC3OP<"mfc0", GPR32Opnd, COP0Opnd>, MFC3OP_FM<0x10, 0>, ISA_MIPS32;
1773def MTC0 : MTC3OP<"mtc0", COP0Opnd, GPR32Opnd>, MFC3OP_FM<0x10, 4>, ISA_MIPS32;
1774def MFC2 : MFC3OP<"mfc2", GPR32Opnd, COP2Opnd>, MFC3OP_FM<0x12, 0>;
1775def MTC2 : MTC3OP<"mtc2", COP2Opnd, GPR32Opnd>, MFC3OP_FM<0x12, 4>;
1776
1777class Barrier<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary,
1778                                      FrmOther, asmstr>;
1779def SSNOP : MMRel, StdMMR6Rel, Barrier<"ssnop">, BARRIER_FM<1>;
1780def EHB : MMRel, Barrier<"ehb">, BARRIER_FM<3>;
1781def PAUSE : MMRel, StdMMR6Rel, Barrier<"pause">, BARRIER_FM<5>, ISA_MIPS32R2;
1782
1783// JR_HB and JALR_HB are defined here using the new style naming
1784// scheme because some of this code is shared with Mips32r6InstrInfo.td
1785// and because of that it doesn't follow the naming convention of the
1786// rest of the file. To avoid a mixture of old vs new style, the new
1787// style was chosen.
1788class JR_HB_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {
1789  dag OutOperandList = (outs);
1790  dag InOperandList = (ins GPROpnd:$rs);
1791  string AsmString = !strconcat(instr_asm, "\t$rs");
1792  list<dag> Pattern = [];
1793}
1794
1795class JALR_HB_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {
1796  dag OutOperandList = (outs GPROpnd:$rd);
1797  dag InOperandList = (ins GPROpnd:$rs);
1798  string AsmString = !strconcat(instr_asm, "\t$rd, $rs");
1799  list<dag> Pattern = [];
1800}
1801
1802class JR_HB_DESC : InstSE<(outs), (ins), "", [], NoItinerary, FrmJ>,
1803                   JR_HB_DESC_BASE<"jr.hb", GPR32Opnd> {
1804  let isBranch=1;
1805  let isIndirectBranch=1;
1806  let hasDelaySlot=1;
1807  let isTerminator=1;
1808  let isBarrier=1;
1809}
1810
1811class JALR_HB_DESC : InstSE<(outs), (ins), "", [], NoItinerary, FrmJ>,
1812                     JALR_HB_DESC_BASE<"jalr.hb", GPR32Opnd> {
1813  let isIndirectBranch=1;
1814  let hasDelaySlot=1;
1815}
1816
1817class JR_HB_ENC : JR_HB_FM<8>;
1818class JALR_HB_ENC : JALR_HB_FM<9>;
1819
1820def JR_HB : JR_HB_DESC, JR_HB_ENC, ISA_MIPS32_NOT_32R6_64R6;
1821def JALR_HB : JALR_HB_DESC, JALR_HB_ENC, ISA_MIPS32;
1822
1823class TLB<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary,
1824                                      FrmOther, asmstr>;
1825def TLBP : MMRel, TLB<"tlbp">, COP0_TLB_FM<0x08>;
1826def TLBR : MMRel, TLB<"tlbr">, COP0_TLB_FM<0x01>;
1827def TLBWI : MMRel, TLB<"tlbwi">, COP0_TLB_FM<0x02>;
1828def TLBWR : MMRel, TLB<"tlbwr">, COP0_TLB_FM<0x06>;
1829
1830class CacheOp<string instr_asm, Operand MemOpnd> :
1831    InstSE<(outs), (ins  MemOpnd:$addr, uimm5:$hint),
1832           !strconcat(instr_asm, "\t$hint, $addr"), [], NoItinerary, FrmOther,
1833           instr_asm> {
1834  let DecoderMethod = "DecodeCacheOp";
1835}
1836
1837def CACHE : MMRel, CacheOp<"cache", mem>, CACHEOP_FM<0b101111>,
1838            INSN_MIPS3_32_NOT_32R6_64R6;
1839def PREF :  MMRel, CacheOp<"pref", mem>, CACHEOP_FM<0b110011>,
1840            INSN_MIPS3_32_NOT_32R6_64R6;
1841
1842def ROL : MipsAsmPseudoInst<(outs),
1843                            (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd),
1844                            "rol\t$rs, $rt, $rd">;
1845def ROLImm : MipsAsmPseudoInst<(outs),
1846                               (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
1847                               "rol\t$rs, $rt, $imm">;
1848def : MipsInstAlias<"rol $rd, $rs",
1849                    (ROL GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>;
1850def : MipsInstAlias<"rol $rd, $imm",
1851                    (ROLImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>;
1852
1853def ROR : MipsAsmPseudoInst<(outs),
1854                            (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd),
1855                            "ror\t$rs, $rt, $rd">;
1856def RORImm : MipsAsmPseudoInst<(outs),
1857                               (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
1858                               "ror\t$rs, $rt, $imm">;
1859def : MipsInstAlias<"ror $rd, $rs",
1860                    (ROR GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>;
1861def : MipsInstAlias<"ror $rd, $imm",
1862                    (RORImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>;
1863
1864def DROL : MipsAsmPseudoInst<(outs),
1865                             (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd),
1866                             "drol\t$rs, $rt, $rd">, ISA_MIPS64;
1867def DROLImm : MipsAsmPseudoInst<(outs),
1868                                (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
1869                                "drol\t$rs, $rt, $imm">, ISA_MIPS64;
1870def : MipsInstAlias<"drol $rd, $rs",
1871                    (DROL GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>, ISA_MIPS64;
1872def : MipsInstAlias<"drol $rd, $imm",
1873                    (DROLImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>, ISA_MIPS64;
1874
1875def DROR : MipsAsmPseudoInst<(outs),
1876                             (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd),
1877                             "dror\t$rs, $rt, $rd">, ISA_MIPS64;
1878def DRORImm : MipsAsmPseudoInst<(outs),
1879                                (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
1880                                "dror\t$rs, $rt, $imm">, ISA_MIPS64;
1881def : MipsInstAlias<"dror $rd, $rs",
1882                    (DROR GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>, ISA_MIPS64;
1883def : MipsInstAlias<"dror $rd, $imm",
1884                    (DRORImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>, ISA_MIPS64;
1885
1886def ABSMacro : MipsAsmPseudoInst<(outs GPR32Opnd:$rd), (ins GPR32Opnd:$rs),
1887                                 "abs\t$rd, $rs">;
1888
1889//===----------------------------------------------------------------------===//
1890// Instruction aliases
1891//===----------------------------------------------------------------------===//
1892def : MipsInstAlias<"move $dst, $src",
1893                    (OR GPR32Opnd:$dst, GPR32Opnd:$src, ZERO), 1>,
1894      GPR_32 {
1895  let AdditionalPredicates = [NotInMicroMips];
1896}
1897def : MipsInstAlias<"move $dst, $src",
1898                    (ADDu GPR32Opnd:$dst, GPR32Opnd:$src, ZERO), 1>,
1899      GPR_32 {
1900  let AdditionalPredicates = [NotInMicroMips];
1901}
1902def : MipsInstAlias<"bal $offset", (BGEZAL ZERO, brtarget:$offset), 0>,
1903      ISA_MIPS1_NOT_32R6_64R6;
1904def : MipsInstAlias<"addu $rs, $rt, $imm",
1905                    (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1906def : MipsInstAlias<"addu $rs, $imm",
1907                    (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rs, simm16:$imm), 0>;
1908def : MipsInstAlias<"add $rs, $rt, $imm",
1909                    (ADDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>,
1910                    ISA_MIPS1_NOT_32R6_64R6;
1911def : MipsInstAlias<"add $rs, $imm",
1912                    (ADDi GPR32Opnd:$rs, GPR32Opnd:$rs, simm16:$imm), 0>,
1913                    ISA_MIPS1_NOT_32R6_64R6;
1914def : MipsInstAlias<"and $rs, $rt, $imm",
1915                    (ANDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1916def : MipsInstAlias<"and $rs, $imm",
1917                    (ANDi GPR32Opnd:$rs, GPR32Opnd:$rs, simm16:$imm), 0>;
1918def : MipsInstAlias<"j $rs", (JR GPR32Opnd:$rs), 0>;
1919let Predicates = [NotInMicroMips] in {
1920def : MipsInstAlias<"jalr $rs", (JALR RA, GPR32Opnd:$rs), 0>;
1921}
1922def : MipsInstAlias<"jalr.hb $rs", (JALR_HB RA, GPR32Opnd:$rs), 1>, ISA_MIPS32;
1923def : MipsInstAlias<"not $rt, $rs",
1924                    (NOR GPR32Opnd:$rt, GPR32Opnd:$rs, ZERO), 0>;
1925def : MipsInstAlias<"neg $rt, $rs",
1926                    (SUB GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1927def : MipsInstAlias<"negu $rt",
1928                    (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rt), 0>;
1929def : MipsInstAlias<"negu $rt, $rs",
1930                    (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1931def : MipsInstAlias<"slt $rs, $rt, $imm",
1932                    (SLTi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1933def : MipsInstAlias<"sltu $rt, $rs, $imm",
1934                    (SLTiu GPR32Opnd:$rt, GPR32Opnd:$rs, simm16:$imm), 0>;
1935def : MipsInstAlias<"xor $rs, $rt, $imm",
1936                    (XORi GPR32Opnd:$rs, GPR32Opnd:$rt, simm32:$imm), 0>;
1937def : MipsInstAlias<"xor $rs, $imm",
1938                    (XORi GPR32Opnd:$rs, GPR32Opnd:$rs, simm32:$imm), 0>;
1939def : MipsInstAlias<"or $rs, $rt, $imm",
1940                    (ORi GPR32Opnd:$rs, GPR32Opnd:$rt, simm32:$imm), 0>;
1941def : MipsInstAlias<"or $rs, $imm",
1942                    (ORi GPR32Opnd:$rs, GPR32Opnd:$rs, simm32:$imm), 0>;
1943let AdditionalPredicates = [NotInMicroMips] in {
1944def : MipsInstAlias<"nop", (SLL ZERO, ZERO, 0), 1>;
1945}
1946def : MipsInstAlias<"mfc0 $rt, $rd", (MFC0 GPR32Opnd:$rt, COP0Opnd:$rd, 0), 0>;
1947def : MipsInstAlias<"mtc0 $rt, $rd", (MTC0 COP0Opnd:$rd, GPR32Opnd:$rt, 0), 0>;
1948def : MipsInstAlias<"mfc2 $rt, $rd", (MFC2 GPR32Opnd:$rt, COP2Opnd:$rd, 0), 0>;
1949def : MipsInstAlias<"mtc2 $rt, $rd", (MTC2 COP2Opnd:$rd, GPR32Opnd:$rt, 0), 0>;
1950let AdditionalPredicates = [NotInMicroMips] in {
1951def : MipsInstAlias<"b $offset", (BEQ ZERO, ZERO, brtarget:$offset), 0>;
1952}
1953def : MipsInstAlias<"bnez $rs,$offset",
1954                    (BNE GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1955def : MipsInstAlias<"bnezl $rs,$offset",
1956                    (BNEL GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1957def : MipsInstAlias<"beqz $rs,$offset",
1958                    (BEQ GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1959def : MipsInstAlias<"beqzl $rs,$offset",
1960                    (BEQL GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1961def : MipsInstAlias<"syscall", (SYSCALL 0), 1>;
1962
1963def : MipsInstAlias<"break", (BREAK 0, 0), 1>;
1964def : MipsInstAlias<"break $imm", (BREAK uimm10:$imm, 0), 1>;
1965let AdditionalPredicates = [NotInMicroMips] in {
1966  def : MipsInstAlias<"ei", (EI ZERO), 1>, ISA_MIPS32R2;
1967  def : MipsInstAlias<"di", (DI ZERO), 1>, ISA_MIPS32R2;
1968}
1969let AdditionalPredicates = [NotInMicroMips] in {
1970  def : MipsInstAlias<"teq $rs, $rt",
1971                      (TEQ GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1972  def : MipsInstAlias<"tge $rs, $rt",
1973                      (TGE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1974  def : MipsInstAlias<"tgeu $rs, $rt",
1975                      (TGEU GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1976  def : MipsInstAlias<"tlt $rs, $rt",
1977                      (TLT GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1978  def : MipsInstAlias<"tltu $rs, $rt",
1979                      (TLTU GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1980  def : MipsInstAlias<"tne $rs, $rt",
1981                      (TNE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1982}
1983def  : MipsInstAlias<"sll $rd, $rt, $rs",
1984                     (SLLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1985def : MipsInstAlias<"sub, $rd, $rs, $imm",
1986                    (ADDi GPR32Opnd:$rd, GPR32Opnd:$rs,
1987                          InvertedImOperand:$imm), 0>, ISA_MIPS1_NOT_32R6_64R6;
1988def : MipsInstAlias<"sub $rs, $imm",
1989                    (ADDi GPR32Opnd:$rs, GPR32Opnd:$rs, InvertedImOperand:$imm),
1990                    0>, ISA_MIPS1_NOT_32R6_64R6;
1991def : MipsInstAlias<"subu, $rd, $rs, $imm",
1992                    (ADDiu GPR32Opnd:$rd, GPR32Opnd:$rs,
1993                           InvertedImOperand:$imm), 0>;
1994def : MipsInstAlias<"subu $rs, $imm", (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rs,
1995                                             InvertedImOperand:$imm), 0>;
1996def : MipsInstAlias<"sra $rd, $rt, $rs",
1997                    (SRAV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1998def : MipsInstAlias<"srl $rd, $rt, $rs",
1999                    (SRLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
2000def : MipsInstAlias<"sdbbp", (SDBBP 0)>, ISA_MIPS32_NOT_32R6_64R6;
2001def : MipsInstAlias<"sync",
2002                    (SYNC 0), 1>, ISA_MIPS2;
2003//===----------------------------------------------------------------------===//
2004// Assembler Pseudo Instructions
2005//===----------------------------------------------------------------------===//
2006
2007class LoadImmediate32<string instr_asm, Operand Od, RegisterOperand RO> :
2008  MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
2009                     !strconcat(instr_asm, "\t$rt, $imm32")> ;
2010def LoadImm32 : LoadImmediate32<"li", simm32, GPR32Opnd>;
2011
2012class LoadAddressFromReg32<string instr_asm, Operand MemOpnd,
2013                           RegisterOperand RO> :
2014  MipsAsmPseudoInst<(outs RO:$rt), (ins MemOpnd:$addr),
2015                     !strconcat(instr_asm, "\t$rt, $addr")> ;
2016def LoadAddrReg32 : LoadAddressFromReg32<"la", mem, GPR32Opnd>;
2017
2018class LoadAddressFromImm32<string instr_asm, Operand Od, RegisterOperand RO> :
2019  MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
2020                     !strconcat(instr_asm, "\t$rt, $imm32")> ;
2021def LoadAddrImm32 : LoadAddressFromImm32<"la", simm32, GPR32Opnd>;
2022
2023def JalTwoReg : MipsAsmPseudoInst<(outs GPR32Opnd:$rd), (ins GPR32Opnd:$rs),
2024                      "jal\t$rd, $rs"> ;
2025def JalOneReg : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs),
2026                      "jal\t$rs"> ;
2027
2028def NORImm : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
2029                               "nor\t$rs, $rt, $imm"> ;
2030
2031let hasDelaySlot = 1 in {
2032def BneImm : MipsAsmPseudoInst<(outs GPR32Opnd:$rt),
2033                               (ins imm64:$imm64, brtarget:$offset),
2034                               "bne\t$rt, $imm64, $offset">;
2035def BeqImm : MipsAsmPseudoInst<(outs GPR32Opnd:$rt),
2036                               (ins imm64:$imm64, brtarget:$offset),
2037                               "beq\t$rt, $imm64, $offset">;
2038
2039class CondBranchPseudo<string instr_asm> :
2040  MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt,
2041                                 brtarget:$offset),
2042                    !strconcat(instr_asm, "\t$rs, $rt, $offset")>;
2043}
2044
2045def BLT : CondBranchPseudo<"blt">;
2046def BLE : CondBranchPseudo<"ble">;
2047def BGE : CondBranchPseudo<"bge">;
2048def BGT : CondBranchPseudo<"bgt">;
2049def BLTU : CondBranchPseudo<"bltu">;
2050def BLEU : CondBranchPseudo<"bleu">;
2051def BGEU : CondBranchPseudo<"bgeu">;
2052def BGTU : CondBranchPseudo<"bgtu">;
2053def BLTL : CondBranchPseudo<"bltl">, ISA_MIPS2_NOT_32R6_64R6;
2054def BLEL : CondBranchPseudo<"blel">, ISA_MIPS2_NOT_32R6_64R6;
2055def BGEL : CondBranchPseudo<"bgel">, ISA_MIPS2_NOT_32R6_64R6;
2056def BGTL : CondBranchPseudo<"bgtl">, ISA_MIPS2_NOT_32R6_64R6;
2057def BLTUL: CondBranchPseudo<"bltul">, ISA_MIPS2_NOT_32R6_64R6;
2058def BLEUL: CondBranchPseudo<"bleul">, ISA_MIPS2_NOT_32R6_64R6;
2059def BGEUL: CondBranchPseudo<"bgeul">, ISA_MIPS2_NOT_32R6_64R6;
2060def BGTUL: CondBranchPseudo<"bgtul">, ISA_MIPS2_NOT_32R6_64R6;
2061
2062class CondBranchImmPseudo<string instr_asm> :
2063  MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, imm64:$imm, brtarget:$offset),
2064                    !strconcat(instr_asm, "\t$rs, $imm, $offset")>;
2065
2066def BLTImmMacro  : CondBranchImmPseudo<"blt">;
2067def BLEImmMacro  : CondBranchImmPseudo<"ble">;
2068def BGEImmMacro  : CondBranchImmPseudo<"bge">;
2069def BGTImmMacro  : CondBranchImmPseudo<"bgt">;
2070def BLTUImmMacro : CondBranchImmPseudo<"bltu">;
2071def BLEUImmMacro : CondBranchImmPseudo<"bleu">;
2072def BGEUImmMacro : CondBranchImmPseudo<"bgeu">;
2073def BGTUImmMacro : CondBranchImmPseudo<"bgtu">;
2074def BLTLImmMacro : CondBranchImmPseudo<"bltl">, ISA_MIPS2_NOT_32R6_64R6;
2075def BLELImmMacro : CondBranchImmPseudo<"blel">, ISA_MIPS2_NOT_32R6_64R6;
2076def BGELImmMacro : CondBranchImmPseudo<"bgel">, ISA_MIPS2_NOT_32R6_64R6;
2077def BGTLImmMacro : CondBranchImmPseudo<"bgtl">, ISA_MIPS2_NOT_32R6_64R6;
2078def BLTULImmMacro : CondBranchImmPseudo<"bltul">, ISA_MIPS2_NOT_32R6_64R6;
2079def BLEULImmMacro : CondBranchImmPseudo<"bleul">, ISA_MIPS2_NOT_32R6_64R6;
2080def BGEULImmMacro : CondBranchImmPseudo<"bgeul">, ISA_MIPS2_NOT_32R6_64R6;
2081def BGTULImmMacro : CondBranchImmPseudo<"bgtul">, ISA_MIPS2_NOT_32R6_64R6;
2082
2083// FIXME: Predicates are removed because instructions are matched regardless of
2084// predicates, because PredicateControl was not in the hierarchy. This was
2085// done to emit more precise error message from expansion function.
2086// Once the tablegen-erated errors are made better, this needs to be fixed and
2087// predicates needs to be restored.
2088
2089def SDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
2090                                  "div\t$rs, $rt">; //, ISA_MIPS1_NOT_32R6_64R6;
2091
2092def UDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
2093                                  "divu\t$rs, $rt">; //, ISA_MIPS1_NOT_32R6_64R6;
2094
2095def DSDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
2096                                   "ddiv\t$rs, $rt">; //, ISA_MIPS64_NOT_64R6;
2097
2098def DUDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
2099                                   "ddivu\t$rs, $rt">; //, ISA_MIPS64_NOT_64R6;
2100
2101def Ulh : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr),
2102                            "ulh\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6;
2103
2104def Ulhu : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr),
2105                             "ulhu\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6;
2106
2107def Ulw : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr),
2108                            "ulw\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6;
2109
2110//===----------------------------------------------------------------------===//
2111//  Arbitrary patterns that map to one or more instructions
2112//===----------------------------------------------------------------------===//
2113
2114// Load/store pattern templates.
2115class LoadRegImmPat<Instruction LoadInst, ValueType ValTy, PatFrag Node> :
2116  MipsPat<(ValTy (Node addrRegImm:$a)), (LoadInst addrRegImm:$a)>;
2117
2118class StoreRegImmPat<Instruction StoreInst, ValueType ValTy> :
2119  MipsPat<(store ValTy:$v, addrRegImm:$a), (StoreInst ValTy:$v, addrRegImm:$a)>;
2120
2121// Small immediates
2122let AdditionalPredicates = [NotInMicroMips] in {
2123def : MipsPat<(i32 immSExt16:$in),
2124              (ADDiu ZERO, imm:$in)>;
2125def : MipsPat<(i32 immZExt16:$in),
2126              (ORi ZERO, imm:$in)>;
2127}
2128def : MipsPat<(i32 immLow16Zero:$in),
2129              (LUi (HI16 imm:$in))>;
2130
2131// Arbitrary immediates
2132def : MipsPat<(i32 imm:$imm),
2133          (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
2134
2135// Carry MipsPatterns
2136def : MipsPat<(subc GPR32:$lhs, GPR32:$rhs),
2137              (SUBu GPR32:$lhs, GPR32:$rhs)>;
2138let AdditionalPredicates = [NotDSP] in {
2139  def : MipsPat<(addc GPR32:$lhs, GPR32:$rhs),
2140                (ADDu GPR32:$lhs, GPR32:$rhs)>;
2141  def : MipsPat<(addc  GPR32:$src, immSExt16:$imm),
2142                (ADDiu GPR32:$src, imm:$imm)>;
2143}
2144
2145// Support multiplication for pre-Mips32 targets that don't have
2146// the MUL instruction.
2147def : MipsPat<(mul GPR32:$lhs, GPR32:$rhs),
2148              (PseudoMFLO (PseudoMULT GPR32:$lhs, GPR32:$rhs))>,
2149      ISA_MIPS1_NOT_32R6_64R6;
2150
2151// SYNC
2152def : MipsPat<(MipsSync (i32 immz)),
2153              (SYNC 0)>, ISA_MIPS2;
2154
2155// Call
2156def : MipsPat<(MipsJmpLink (i32 texternalsym:$dst)),
2157              (JAL texternalsym:$dst)>;
2158//def : MipsPat<(MipsJmpLink GPR32:$dst),
2159//              (JALR GPR32:$dst)>;
2160
2161// Tail call
2162def : MipsPat<(MipsTailCall (iPTR tglobaladdr:$dst)),
2163              (TAILCALL tglobaladdr:$dst)>;
2164def : MipsPat<(MipsTailCall (iPTR texternalsym:$dst)),
2165              (TAILCALL texternalsym:$dst)>;
2166// hi/lo relocs
2167def : MipsPat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
2168def : MipsPat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
2169def : MipsPat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
2170def : MipsPat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
2171def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
2172def : MipsPat<(MipsHi texternalsym:$in), (LUi texternalsym:$in)>;
2173
2174def : MipsPat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
2175def : MipsPat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
2176def : MipsPat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
2177def : MipsPat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
2178def : MipsPat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
2179def : MipsPat<(MipsLo texternalsym:$in), (ADDiu ZERO, texternalsym:$in)>;
2180
2181def : MipsPat<(add GPR32:$hi, (MipsLo tglobaladdr:$lo)),
2182              (ADDiu GPR32:$hi, tglobaladdr:$lo)>;
2183def : MipsPat<(add GPR32:$hi, (MipsLo tblockaddress:$lo)),
2184              (ADDiu GPR32:$hi, tblockaddress:$lo)>;
2185def : MipsPat<(add GPR32:$hi, (MipsLo tjumptable:$lo)),
2186              (ADDiu GPR32:$hi, tjumptable:$lo)>;
2187def : MipsPat<(add GPR32:$hi, (MipsLo tconstpool:$lo)),
2188              (ADDiu GPR32:$hi, tconstpool:$lo)>;
2189def : MipsPat<(add GPR32:$hi, (MipsLo tglobaltlsaddr:$lo)),
2190              (ADDiu GPR32:$hi, tglobaltlsaddr:$lo)>;
2191
2192// gp_rel relocs
2193def : MipsPat<(add GPR32:$gp, (MipsGPRel tglobaladdr:$in)),
2194              (ADDiu GPR32:$gp, tglobaladdr:$in)>;
2195def : MipsPat<(add GPR32:$gp, (MipsGPRel tconstpool:$in)),
2196              (ADDiu GPR32:$gp, tconstpool:$in)>;
2197
2198// wrapper_pic
2199class WrapperPat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
2200      MipsPat<(MipsWrapper RC:$gp, node:$in),
2201              (ADDiuOp RC:$gp, node:$in)>;
2202
2203def : WrapperPat<tglobaladdr, ADDiu, GPR32>;
2204def : WrapperPat<tconstpool, ADDiu, GPR32>;
2205def : WrapperPat<texternalsym, ADDiu, GPR32>;
2206def : WrapperPat<tblockaddress, ADDiu, GPR32>;
2207def : WrapperPat<tjumptable, ADDiu, GPR32>;
2208def : WrapperPat<tglobaltlsaddr, ADDiu, GPR32>;
2209
2210let AdditionalPredicates = [NotInMicroMips] in {
2211// Mips does not have "not", so we expand our way
2212def : MipsPat<(not GPR32:$in),
2213              (NOR GPR32Opnd:$in, ZERO)>;
2214}
2215
2216// extended loads
2217def : MipsPat<(i32 (extloadi1  addr:$src)), (LBu addr:$src)>;
2218def : MipsPat<(i32 (extloadi8  addr:$src)), (LBu addr:$src)>;
2219def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
2220
2221// peepholes
2222def : MipsPat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
2223
2224// brcond patterns
2225multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
2226                      Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
2227                      Instruction SLTiuOp, Register ZEROReg> {
2228def : MipsPat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
2229              (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
2230def : MipsPat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
2231              (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
2232
2233def : MipsPat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
2234              (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
2235def : MipsPat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
2236              (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
2237def : MipsPat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
2238              (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
2239def : MipsPat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
2240              (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
2241def : MipsPat<(brcond (i32 (setgt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
2242              (BEQ (SLTiOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
2243def : MipsPat<(brcond (i32 (setugt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
2244              (BEQ (SLTiuOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
2245
2246def : MipsPat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
2247              (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
2248def : MipsPat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
2249              (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
2250
2251def : MipsPat<(brcond RC:$cond, bb:$dst),
2252              (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
2253}
2254
2255defm : BrcondPats<GPR32, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
2256
2257def : MipsPat<(brcond (i32 (setlt i32:$lhs, 1)), bb:$dst),
2258              (BLEZ i32:$lhs, bb:$dst)>;
2259def : MipsPat<(brcond (i32 (setgt i32:$lhs, -1)), bb:$dst),
2260              (BGEZ i32:$lhs, bb:$dst)>;
2261
2262// setcc patterns
2263multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
2264                     Instruction SLTuOp, Register ZEROReg> {
2265  def : MipsPat<(seteq RC:$lhs, 0),
2266                (SLTiuOp RC:$lhs, 1)>;
2267  def : MipsPat<(setne RC:$lhs, 0),
2268                (SLTuOp ZEROReg, RC:$lhs)>;
2269  def : MipsPat<(seteq RC:$lhs, RC:$rhs),
2270                (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
2271  def : MipsPat<(setne RC:$lhs, RC:$rhs),
2272                (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
2273}
2274
2275multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
2276  def : MipsPat<(setle RC:$lhs, RC:$rhs),
2277                (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
2278  def : MipsPat<(setule RC:$lhs, RC:$rhs),
2279                (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
2280}
2281
2282multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
2283  def : MipsPat<(setgt RC:$lhs, RC:$rhs),
2284                (SLTOp RC:$rhs, RC:$lhs)>;
2285  def : MipsPat<(setugt RC:$lhs, RC:$rhs),
2286                (SLTuOp RC:$rhs, RC:$lhs)>;
2287}
2288
2289multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
2290  def : MipsPat<(setge RC:$lhs, RC:$rhs),
2291                (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
2292  def : MipsPat<(setuge RC:$lhs, RC:$rhs),
2293                (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
2294}
2295
2296multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
2297                        Instruction SLTiuOp> {
2298  def : MipsPat<(setge RC:$lhs, immSExt16:$rhs),
2299                (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
2300  def : MipsPat<(setuge RC:$lhs, immSExt16:$rhs),
2301                (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
2302}
2303
2304defm : SeteqPats<GPR32, SLTiu, XOR, SLTu, ZERO>;
2305defm : SetlePats<GPR32, SLT, SLTu>;
2306defm : SetgtPats<GPR32, SLT, SLTu>;
2307defm : SetgePats<GPR32, SLT, SLTu>;
2308defm : SetgeImmPats<GPR32, SLTi, SLTiu>;
2309
2310// bswap pattern
2311def : MipsPat<(bswap GPR32:$rt), (ROTR (WSBH GPR32:$rt), 16)>;
2312
2313// Load halfword/word patterns.
2314let AddedComplexity = 40 in {
2315  def : LoadRegImmPat<LBu, i32, zextloadi8>;
2316  def : LoadRegImmPat<LH, i32, sextloadi16>;
2317  let AdditionalPredicates = [NotInMicroMips] in {
2318  def : LoadRegImmPat<LW, i32, load>;
2319  }
2320}
2321
2322// Atomic load patterns.
2323def : MipsPat<(atomic_load_8 addr:$a), (LB addr:$a)>;
2324def : MipsPat<(atomic_load_16 addr:$a), (LH addr:$a)>;
2325def : MipsPat<(atomic_load_32 addr:$a), (LW addr:$a)>;
2326
2327// Atomic store patterns.
2328def : MipsPat<(atomic_store_8 addr:$a, GPR32:$v), (SB GPR32:$v, addr:$a)>;
2329def : MipsPat<(atomic_store_16 addr:$a, GPR32:$v), (SH GPR32:$v, addr:$a)>;
2330def : MipsPat<(atomic_store_32 addr:$a, GPR32:$v), (SW GPR32:$v, addr:$a)>;
2331
2332//===----------------------------------------------------------------------===//
2333// Floating Point Support
2334//===----------------------------------------------------------------------===//
2335
2336include "MipsInstrFPU.td"
2337include "Mips64InstrInfo.td"
2338include "MipsCondMov.td"
2339
2340include "Mips32r6InstrInfo.td"
2341include "Mips64r6InstrInfo.td"
2342
2343//
2344// Mips16
2345
2346include "Mips16InstrFormats.td"
2347include "Mips16InstrInfo.td"
2348
2349// DSP
2350include "MipsDSPInstrFormats.td"
2351include "MipsDSPInstrInfo.td"
2352
2353// MSA
2354include "MipsMSAInstrFormats.td"
2355include "MipsMSAInstrInfo.td"
2356
2357// EVA
2358include "MipsEVAInstrFormats.td"
2359include "MipsEVAInstrInfo.td"
2360
2361// Micromips
2362include "MicroMipsInstrFormats.td"
2363include "MicroMipsInstrInfo.td"
2364include "MicroMipsInstrFPU.td"
2365
2366// Micromips r6
2367include "MicroMips32r6InstrFormats.td"
2368include "MicroMips32r6InstrInfo.td"
2369
2370// Micromips64 r6
2371include "MicroMips64r6InstrFormats.td"
2372include "MicroMips64r6InstrInfo.td"
2373
2374// Micromips DSP
2375include "MicroMipsDSPInstrFormats.td"
2376include "MicroMipsDSPInstrInfo.td"
2377