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