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