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