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