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