[mips] Fold FeatureBitCount into FeatureMips32 and FeatureMips64
[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     :    Predicate<"Subtarget.hasMips3()">,
154                       AssemblerPredicate<"FeatureMips3">;
155 def HasMips4_32  :    Predicate<"Subtarget.hasMips4_32()">,
156                       AssemblerPredicate<"FeatureMips4_32">;
157 def HasMips4_32r2 :   Predicate<"Subtarget.hasMips4_32r2()">,
158                       AssemblerPredicate<"FeatureMips4_32r2">;
159 def HasMips32    :    Predicate<"Subtarget.hasMips32()">,
160                       AssemblerPredicate<"FeatureMips32">;
161 def HasMips32r2  :    Predicate<"Subtarget.hasMips32r2()">,
162                       AssemblerPredicate<"FeatureMips32r2">;
163 def IsGP64bit    :    Predicate<"Subtarget.isGP64bit()">,
164                       AssemblerPredicate<"FeatureGP64Bit">;
165 def IsGP32bit    :    Predicate<"!Subtarget.isGP64bit()">,
166                       AssemblerPredicate<"!FeatureGP64Bit">;
167 def HasMips64    :    Predicate<"Subtarget.hasMips64()">,
168                       AssemblerPredicate<"FeatureMips64">;
169 def IsGP32       :    Predicate<"!Subtarget.isGP64()">,
170                       AssemblerPredicate<"!FeatureGP64Bit">;
171 def IsGP64       :    Predicate<"Subtarget.isGP64()">,
172                       AssemblerPredicate<"FeatureGP64Bit">;
173 def HasMips64r2  :    Predicate<"Subtarget.hasMips64r2()">,
174                       AssemblerPredicate<"FeatureMips64r2">;
175 def IsN64       :     Predicate<"Subtarget.isABI_N64()">,
176                       AssemblerPredicate<"FeatureN64">;
177 def InMips16Mode :    Predicate<"Subtarget.inMips16Mode()">,
178                       AssemblerPredicate<"FeatureMips16">;
179 def HasCnMips    :    Predicate<"Subtarget.hasCnMips()">,
180                       AssemblerPredicate<"FeatureCnMips">;
181 def RelocStatic :     Predicate<"TM.getRelocationModel() == Reloc::Static">,
182                       AssemblerPredicate<"FeatureMips32">;
183 def RelocPIC    :     Predicate<"TM.getRelocationModel() == Reloc::PIC_">,
184                       AssemblerPredicate<"FeatureMips32">;
185 def NoNaNsFPMath :    Predicate<"TM.Options.NoNaNsFPMath">;
186 def HasStdEnc :       Predicate<"Subtarget.hasStandardEncoding()">,
187                       AssemblerPredicate<"!FeatureMips16">;
188 def NotDSP :          Predicate<"!Subtarget.hasDSP()">;
189 def InMicroMips    :  Predicate<"Subtarget.inMicroMipsMode()">,
190                       AssemblerPredicate<"FeatureMicroMips">;
191 def NotInMicroMips :  Predicate<"!Subtarget.inMicroMipsMode()">,
192                       AssemblerPredicate<"!FeatureMicroMips">;
193 def IsLE           :  Predicate<"Subtarget.isLittle()">;
194 def IsBE           :  Predicate<"!Subtarget.isLittle()">;
195 def IsNotNaCl    :    Predicate<"!Subtarget.isTargetNaCl()">;
196
197 //===----------------------------------------------------------------------===//
198 // Mips GPR size adjectives.
199 // They are mutually exclusive.
200 //===----------------------------------------------------------------------===//
201
202 class GPR_64 { list<Predicate> GPRPredicates = [IsGP64bit]; }
203
204 //===----------------------------------------------------------------------===//
205 // Mips ISA/ASE membership and instruction group membership adjectives.
206 // They are mutually exclusive.
207 //===----------------------------------------------------------------------===//
208
209 class ISA_MIPS2    { list<Predicate> InsnPredicates = [HasMips2]; }
210 class ISA_MIPS3    { list<Predicate> InsnPredicates = [HasMips3]; }
211 class ISA_MIPS32   { list<Predicate> InsnPredicates = [HasMips32]; }
212 class ISA_MIPS32R2 { list<Predicate> InsnPredicates = [HasMips32r2]; }
213 class ISA_MIPS64   { list<Predicate> InsnPredicates = [HasMips64]; }
214 class ISA_MIPS64R2 { list<Predicate> InsnPredicates = [HasMips64r2]; }
215
216 // The portions of MIPS-III that were also added to MIPS32
217 class INSN_MIPS3_32 { list<Predicate> InsnPredicates = [HasMips3_32]; }
218
219 // The portions of MIPS-IV that were also added to MIPS32
220 class INSN_MIPS4_32 { list<Predicate> InsnPredicates = [HasMips4_32]; }
221
222 // The portions of MIPS-IV that were also added to MIPS32R2
223 class INSN_MIPS4_32R2 { list<Predicate> InsnPredicates = [HasMips4_32r2]; }
224
225 //===----------------------------------------------------------------------===//
226
227 class MipsPat<dag pattern, dag result> : Pat<pattern, result>, PredicateControl {
228   let EncodingPredicates = [HasStdEnc];
229 }
230
231 class MipsInstAlias<string Asm, dag Result, bit Emit = 0b1> :
232   InstAlias<Asm, Result, Emit>, PredicateControl;
233
234 class IsCommutable {
235   bit isCommutable = 1;
236 }
237
238 class IsBranch {
239   bit isBranch = 1;
240 }
241
242 class IsReturn {
243   bit isReturn = 1;
244 }
245
246 class IsCall {
247   bit isCall = 1;
248 }
249
250 class IsTailCall {
251   bit isCall = 1;
252   bit isTerminator = 1;
253   bit isReturn = 1;
254   bit isBarrier = 1;
255   bit hasExtraSrcRegAllocReq = 1;
256   bit isCodeGenOnly = 1;
257 }
258
259 class IsAsCheapAsAMove {
260   bit isAsCheapAsAMove = 1;
261 }
262
263 class NeverHasSideEffects {
264   bit neverHasSideEffects = 1;
265 }
266
267 //===----------------------------------------------------------------------===//
268 // Instruction format superclass
269 //===----------------------------------------------------------------------===//
270
271 include "MipsInstrFormats.td"
272
273 //===----------------------------------------------------------------------===//
274 // Mips Operand, Complex Patterns and Transformations Definitions.
275 //===----------------------------------------------------------------------===//
276
277 def MipsJumpTargetAsmOperand : AsmOperandClass {
278   let Name = "JumpTarget";
279   let ParserMethod = "ParseJumpTarget";
280   let PredicateMethod = "isImm";
281   let RenderMethod = "addImmOperands";
282 }
283
284 // Instruction operand types
285 def jmptarget   : Operand<OtherVT> {
286   let EncoderMethod = "getJumpTargetOpValue";
287   let ParserMatchClass = MipsJumpTargetAsmOperand;
288 }
289 def brtarget    : Operand<OtherVT> {
290   let EncoderMethod = "getBranchTargetOpValue";
291   let OperandType = "OPERAND_PCREL";
292   let DecoderMethod = "DecodeBranchTarget";
293   let ParserMatchClass = MipsJumpTargetAsmOperand;
294 }
295 def calltarget  : Operand<iPTR> {
296   let EncoderMethod = "getJumpTargetOpValue";
297   let ParserMatchClass = MipsJumpTargetAsmOperand;
298 }
299
300 def simm10 : Operand<i32>;
301
302 def simm16      : Operand<i32> {
303   let DecoderMethod= "DecodeSimm16";
304 }
305
306 def simm20      : Operand<i32> {
307 }
308
309 def uimm20      : Operand<i32> {
310 }
311
312 def uimm10      : Operand<i32> {
313 }
314
315 def simm16_64   : Operand<i64> {
316   let DecoderMethod = "DecodeSimm16";
317 }
318
319 // Zero
320 def uimmz       : Operand<i32> {
321   let PrintMethod = "printUnsignedImm";
322 }
323
324 // Unsigned Operand
325 def uimm5       : Operand<i32> {
326   let PrintMethod = "printUnsignedImm";
327 }
328
329 def uimm6 : Operand<i32> {
330   let PrintMethod = "printUnsignedImm";
331 }
332
333 def uimm16      : Operand<i32> {
334   let PrintMethod = "printUnsignedImm";
335 }
336
337 def pcrel16      : Operand<i32> {
338 }
339
340 def MipsMemAsmOperand : AsmOperandClass {
341   let Name = "Mem";
342   let ParserMethod = "parseMemOperand";
343 }
344
345 def MipsInvertedImmoperand : AsmOperandClass {
346   let Name = "InvNum";
347   let RenderMethod = "addImmOperands";
348   let ParserMethod = "parseInvNum";
349 }
350
351 def InvertedImOperand : Operand<i32> {
352   let ParserMatchClass = MipsInvertedImmoperand;
353 }
354
355 def InvertedImOperand64 : Operand<i64> {
356   let ParserMatchClass = MipsInvertedImmoperand;
357 }
358
359 class mem_generic : Operand<iPTR> {
360   let PrintMethod = "printMemOperand";
361   let MIOperandInfo = (ops ptr_rc, simm16);
362   let EncoderMethod = "getMemEncoding";
363   let ParserMatchClass = MipsMemAsmOperand;
364   let OperandType = "OPERAND_MEMORY";
365 }
366
367 // Address operand
368 def mem : mem_generic;
369
370 // MSA specific address operand
371 def mem_msa : mem_generic {
372   let MIOperandInfo = (ops ptr_rc, simm10);
373   let EncoderMethod = "getMSAMemEncoding";
374 }
375
376 def mem_ea : Operand<iPTR> {
377   let PrintMethod = "printMemOperandEA";
378   let MIOperandInfo = (ops ptr_rc, simm16);
379   let EncoderMethod = "getMemEncoding";
380   let OperandType = "OPERAND_MEMORY";
381 }
382
383 def PtrRC : Operand<iPTR> {
384   let MIOperandInfo = (ops ptr_rc);
385   let DecoderMethod = "DecodePtrRegisterClass";
386   let ParserMatchClass = GPR32AsmOperand;
387 }
388
389 // size operand of ext instruction
390 def size_ext : Operand<i32> {
391   let EncoderMethod = "getSizeExtEncoding";
392   let DecoderMethod = "DecodeExtSize";
393 }
394
395 // size operand of ins instruction
396 def size_ins : Operand<i32> {
397   let EncoderMethod = "getSizeInsEncoding";
398   let DecoderMethod = "DecodeInsSize";
399 }
400
401 // Transformation Function - get the lower 16 bits.
402 def LO16 : SDNodeXForm<imm, [{
403   return getImm(N, N->getZExtValue() & 0xFFFF);
404 }]>;
405
406 // Transformation Function - get the higher 16 bits.
407 def HI16 : SDNodeXForm<imm, [{
408   return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
409 }]>;
410
411 // Plus 1.
412 def Plus1 : SDNodeXForm<imm, [{ return getImm(N, N->getSExtValue() + 1); }]>;
413
414 // Node immediate is zero (e.g. insve.d)
415 def immz : PatLeaf<(imm), [{ return N->getSExtValue() == 0; }]>;
416
417 // Node immediate fits as 16-bit sign extended on target immediate.
418 // e.g. addi, andi
419 def immSExt8  : PatLeaf<(imm), [{ return isInt<8>(N->getSExtValue()); }]>;
420
421 // Node immediate fits as 16-bit sign extended on target immediate.
422 // e.g. addi, andi
423 def immSExt16  : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
424
425 // Node immediate fits as 15-bit sign extended on target immediate.
426 // e.g. addi, andi
427 def immSExt15  : PatLeaf<(imm), [{ return isInt<15>(N->getSExtValue()); }]>;
428
429 // Node immediate fits as 16-bit zero extended on target immediate.
430 // The LO16 param means that only the lower 16 bits of the node
431 // immediate are caught.
432 // e.g. addiu, sltiu
433 def immZExt16  : PatLeaf<(imm), [{
434   if (N->getValueType(0) == MVT::i32)
435     return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
436   else
437     return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
438 }], LO16>;
439
440 // Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared).
441 def immLow16Zero : PatLeaf<(imm), [{
442   int64_t Val = N->getSExtValue();
443   return isInt<32>(Val) && !(Val & 0xffff);
444 }]>;
445
446 // shamt field must fit in 5 bits.
447 def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
448
449 // True if (N + 1) fits in 16-bit field.
450 def immSExt16Plus1 : PatLeaf<(imm), [{
451   return isInt<17>(N->getSExtValue()) && isInt<16>(N->getSExtValue() + 1);
452 }]>;
453
454 // Mips Address Mode! SDNode frameindex could possibily be a match
455 // since load and store instructions from stack used it.
456 def addr :
457   ComplexPattern<iPTR, 2, "selectIntAddr", [frameindex]>;
458
459 def addrRegImm :
460   ComplexPattern<iPTR, 2, "selectAddrRegImm", [frameindex]>;
461
462 def addrRegReg :
463   ComplexPattern<iPTR, 2, "selectAddrRegReg", [frameindex]>;
464
465 def addrDefault :
466   ComplexPattern<iPTR, 2, "selectAddrDefault", [frameindex]>;
467
468 def addrimm10 : ComplexPattern<iPTR, 2, "selectIntAddrMSA", [frameindex]>;
469
470 //===----------------------------------------------------------------------===//
471 // Instructions specific format
472 //===----------------------------------------------------------------------===//
473
474 // Arithmetic and logical instructions with 3 register operands.
475 class ArithLogicR<string opstr, RegisterOperand RO, bit isComm = 0,
476                   InstrItinClass Itin = NoItinerary,
477                   SDPatternOperator OpNode = null_frag>:
478   InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
479          !strconcat(opstr, "\t$rd, $rs, $rt"),
480          [(set RO:$rd, (OpNode RO:$rs, RO:$rt))], Itin, FrmR, opstr> {
481   let isCommutable = isComm;
482   let isReMaterializable = 1;
483   let TwoOperandAliasConstraint = "$rd = $rs";
484 }
485
486 // Arithmetic and logical instructions with 2 register operands.
487 class ArithLogicI<string opstr, Operand Od, RegisterOperand RO,
488                   InstrItinClass Itin = NoItinerary,
489                   SDPatternOperator imm_type = null_frag,
490                   SDPatternOperator OpNode = null_frag> :
491   InstSE<(outs RO:$rt), (ins RO:$rs, Od:$imm16),
492          !strconcat(opstr, "\t$rt, $rs, $imm16"),
493          [(set RO:$rt, (OpNode RO:$rs, imm_type:$imm16))],
494          Itin, FrmI, opstr> {
495   let isReMaterializable = 1;
496   let TwoOperandAliasConstraint = "$rs = $rt";
497 }
498
499 // Arithmetic Multiply ADD/SUB
500 class MArithR<string opstr, InstrItinClass itin, bit isComm = 0> :
501   InstSE<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
502          !strconcat(opstr, "\t$rs, $rt"), [], itin, FrmR, opstr> {
503   let Defs = [HI0, LO0];
504   let Uses = [HI0, LO0];
505   let isCommutable = isComm;
506 }
507
508 //  Logical
509 class LogicNOR<string opstr, RegisterOperand RO>:
510   InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
511          !strconcat(opstr, "\t$rd, $rs, $rt"),
512          [(set RO:$rd, (not (or RO:$rs, RO:$rt)))], II_NOR, FrmR, opstr> {
513   let isCommutable = 1;
514 }
515
516 // Shifts
517 class shift_rotate_imm<string opstr, Operand ImmOpnd,
518                        RegisterOperand RO, InstrItinClass itin,
519                        SDPatternOperator OpNode = null_frag,
520                        SDPatternOperator PF = null_frag> :
521   InstSE<(outs RO:$rd), (ins RO:$rt, ImmOpnd:$shamt),
522          !strconcat(opstr, "\t$rd, $rt, $shamt"),
523          [(set RO:$rd, (OpNode RO:$rt, PF:$shamt))], itin, FrmR, opstr> {
524   let TwoOperandAliasConstraint = "$rt = $rd";
525 }
526
527 class shift_rotate_reg<string opstr, RegisterOperand RO, InstrItinClass itin,
528                        SDPatternOperator OpNode = null_frag>:
529   InstSE<(outs RO:$rd), (ins RO:$rt, GPR32Opnd:$rs),
530          !strconcat(opstr, "\t$rd, $rt, $rs"),
531          [(set RO:$rd, (OpNode RO:$rt, GPR32Opnd:$rs))], itin, FrmR,
532          opstr>;
533
534 // Load Upper Imediate
535 class LoadUpper<string opstr, RegisterOperand RO, Operand Imm>:
536   InstSE<(outs RO:$rt), (ins Imm:$imm16), !strconcat(opstr, "\t$rt, $imm16"),
537          [], II_LUI, FrmI, opstr>, IsAsCheapAsAMove {
538   let neverHasSideEffects = 1;
539   let isReMaterializable = 1;
540 }
541
542 // Memory Load/Store
543 class Load<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
544            InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
545   InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
546          [(set RO:$rt, (OpNode Addr:$addr))], Itin, FrmI, opstr> {
547   let DecoderMethod = "DecodeMem";
548   let canFoldAsLoad = 1;
549   let mayLoad = 1;
550 }
551
552 class Store<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
553             InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
554   InstSE<(outs), (ins RO:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
555          [(OpNode RO:$rt, Addr:$addr)], Itin, FrmI, opstr> {
556   let DecoderMethod = "DecodeMem";
557   let mayStore = 1;
558 }
559
560 // Load/Store Left/Right
561 let canFoldAsLoad = 1 in
562 class LoadLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
563                     InstrItinClass Itin> :
564   InstSE<(outs RO:$rt), (ins mem:$addr, RO:$src),
565          !strconcat(opstr, "\t$rt, $addr"),
566          [(set RO:$rt, (OpNode addr:$addr, RO:$src))], Itin, FrmI> {
567   let DecoderMethod = "DecodeMem";
568   string Constraints = "$src = $rt";
569 }
570
571 class StoreLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
572                      InstrItinClass Itin> :
573   InstSE<(outs), (ins RO:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
574          [(OpNode RO:$rt, addr:$addr)], Itin, FrmI> {
575   let DecoderMethod = "DecodeMem";
576 }
577
578 // Conditional Branch
579 class CBranch<string opstr, DAGOperand opnd, PatFrag cond_op,
580               RegisterOperand RO> :
581   InstSE<(outs), (ins RO:$rs, RO:$rt, opnd:$offset),
582          !strconcat(opstr, "\t$rs, $rt, $offset"),
583          [(brcond (i32 (cond_op RO:$rs, RO:$rt)), bb:$offset)], IIBranch,
584          FrmI, opstr> {
585   let isBranch = 1;
586   let isTerminator = 1;
587   let hasDelaySlot = 1;
588   let Defs = [AT];
589 }
590
591 class CBranchZero<string opstr, DAGOperand opnd, PatFrag cond_op,
592                   RegisterOperand RO> :
593   InstSE<(outs), (ins RO:$rs, opnd:$offset),
594          !strconcat(opstr, "\t$rs, $offset"),
595          [(brcond (i32 (cond_op RO:$rs, 0)), bb:$offset)], IIBranch,
596          FrmI, opstr> {
597   let isBranch = 1;
598   let isTerminator = 1;
599   let hasDelaySlot = 1;
600   let Defs = [AT];
601 }
602
603 // SetCC
604 class SetCC_R<string opstr, PatFrag cond_op, RegisterOperand RO> :
605   InstSE<(outs GPR32Opnd:$rd), (ins RO:$rs, RO:$rt),
606          !strconcat(opstr, "\t$rd, $rs, $rt"),
607          [(set GPR32Opnd:$rd, (cond_op RO:$rs, RO:$rt))],
608          II_SLT_SLTU, FrmR, opstr>;
609
610 class SetCC_I<string opstr, PatFrag cond_op, Operand Od, PatLeaf imm_type,
611               RegisterOperand RO>:
612   InstSE<(outs GPR32Opnd:$rt), (ins RO:$rs, Od:$imm16),
613          !strconcat(opstr, "\t$rt, $rs, $imm16"),
614          [(set GPR32Opnd:$rt, (cond_op RO:$rs, imm_type:$imm16))],
615          II_SLTI_SLTIU, FrmI, opstr>;
616
617 // Jump
618 class JumpFJ<DAGOperand opnd, string opstr, SDPatternOperator operator,
619              SDPatternOperator targetoperator, string bopstr> :
620   InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
621          [(operator targetoperator:$target)], IIBranch, FrmJ, bopstr> {
622   let isTerminator=1;
623   let isBarrier=1;
624   let hasDelaySlot = 1;
625   let DecoderMethod = "DecodeJumpTarget";
626   let Defs = [AT];
627 }
628
629 // Unconditional branch
630 class UncondBranch<Instruction BEQInst> :
631   PseudoSE<(outs), (ins brtarget:$offset), [(br bb:$offset)], IIBranch>,
632   PseudoInstExpansion<(BEQInst ZERO, ZERO, brtarget:$offset)> {
633   let isBranch = 1;
634   let isTerminator = 1;
635   let isBarrier = 1;
636   let hasDelaySlot = 1;
637   let AdditionalPredicates = [RelocPIC];
638   let Defs = [AT];
639 }
640
641 // Base class for indirect branch and return instruction classes.
642 let isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
643 class JumpFR<string opstr, RegisterOperand RO,
644              SDPatternOperator operator = null_frag>:
645   InstSE<(outs), (ins RO:$rs), "jr\t$rs", [(operator RO:$rs)], IIBranch,
646          FrmR, opstr>;
647
648 // Indirect branch
649 class IndirectBranch<string opstr, RegisterOperand RO> :
650       JumpFR<opstr, RO, brind> {
651   let isBranch = 1;
652   let isIndirectBranch = 1;
653 }
654
655 // Return instruction
656 class RetBase<string opstr, RegisterOperand RO>: JumpFR<opstr, RO> {
657   let isReturn = 1;
658   let isCodeGenOnly = 1;
659   let hasCtrlDep = 1;
660   let hasExtraSrcRegAllocReq = 1;
661 }
662
663 // Jump and Link (Call)
664 let isCall=1, hasDelaySlot=1, Defs = [RA] in {
665   class JumpLink<string opstr, DAGOperand opnd> :
666     InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
667            [(MipsJmpLink imm:$target)], IIBranch, FrmJ, opstr> {
668     let DecoderMethod = "DecodeJumpTarget";
669   }
670
671   class JumpLinkRegPseudo<RegisterOperand RO, Instruction JALRInst,
672                           Register RetReg, RegisterOperand ResRO = RO>:
673     PseudoSE<(outs), (ins RO:$rs), [(MipsJmpLink RO:$rs)], IIBranch>,
674     PseudoInstExpansion<(JALRInst RetReg, ResRO:$rs)>;
675
676   class JumpLinkReg<string opstr, RegisterOperand RO>:
677     InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
678            [], IIBranch, FrmR>;
679
680   class BGEZAL_FT<string opstr, DAGOperand opnd, RegisterOperand RO> :
681     InstSE<(outs), (ins RO:$rs, opnd:$offset),
682            !strconcat(opstr, "\t$rs, $offset"), [], IIBranch, FrmI, opstr>;
683
684 }
685
686 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, hasDelaySlot = 1,
687     hasExtraSrcRegAllocReq = 1, Defs = [AT] in {
688   class TailCall<Instruction JumpInst> :
689     PseudoSE<(outs), (ins calltarget:$target), [], IIBranch>,
690     PseudoInstExpansion<(JumpInst jmptarget:$target)>;
691
692   class TailCallReg<RegisterOperand RO, Instruction JRInst,
693                     RegisterOperand ResRO = RO> :
694     PseudoSE<(outs), (ins RO:$rs), [(MipsTailCall RO:$rs)], IIBranch>,
695     PseudoInstExpansion<(JRInst ResRO:$rs)>;
696 }
697
698 class BAL_BR_Pseudo<Instruction RealInst> :
699   PseudoSE<(outs), (ins brtarget:$offset), [], IIBranch>,
700   PseudoInstExpansion<(RealInst ZERO, brtarget:$offset)> {
701   let isBranch = 1;
702   let isTerminator = 1;
703   let isBarrier = 1;
704   let hasDelaySlot = 1;
705   let Defs = [RA];
706 }
707
708 // Syscall
709 class SYS_FT<string opstr> :
710   InstSE<(outs), (ins uimm20:$code_),
711          !strconcat(opstr, "\t$code_"), [], NoItinerary, FrmI, opstr>;
712 // Break
713 class BRK_FT<string opstr> :
714   InstSE<(outs), (ins uimm10:$code_1, uimm10:$code_2),
715          !strconcat(opstr, "\t$code_1, $code_2"), [], NoItinerary,
716          FrmOther, opstr>;
717
718 // (D)Eret
719 class ER_FT<string opstr> :
720   InstSE<(outs), (ins),
721          opstr, [], NoItinerary, FrmOther, opstr>;
722
723 // Interrupts
724 class DEI_FT<string opstr, RegisterOperand RO> :
725   InstSE<(outs RO:$rt), (ins),
726          !strconcat(opstr, "\t$rt"), [], NoItinerary, FrmOther, opstr>;
727
728 // Wait
729 class WAIT_FT<string opstr> :
730   InstSE<(outs), (ins), opstr, [], NoItinerary, FrmOther, opstr>;
731
732 // Sync
733 let hasSideEffects = 1 in
734 class SYNC_FT<string opstr> :
735   InstSE<(outs), (ins i32imm:$stype), "sync $stype", [(MipsSync imm:$stype)],
736          NoItinerary, FrmOther, opstr>;
737
738 let hasSideEffects = 1 in
739 class TEQ_FT<string opstr, RegisterOperand RO> :
740   InstSE<(outs), (ins RO:$rs, RO:$rt, uimm16:$code_),
741          !strconcat(opstr, "\t$rs, $rt, $code_"), [], NoItinerary,
742          FrmI, opstr>;
743
744 class TEQI_FT<string opstr, RegisterOperand RO> :
745   InstSE<(outs), (ins RO:$rs, uimm16:$imm16),
746          !strconcat(opstr, "\t$rs, $imm16"), [], NoItinerary, FrmOther, opstr>;
747 // Mul, Div
748 class Mult<string opstr, InstrItinClass itin, RegisterOperand RO,
749            list<Register> DefRegs> :
750   InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$rs, $rt"), [],
751          itin, FrmR, opstr> {
752   let isCommutable = 1;
753   let Defs = DefRegs;
754   let neverHasSideEffects = 1;
755 }
756
757 // Pseudo multiply/divide instruction with explicit accumulator register
758 // operands.
759 class MultDivPseudo<Instruction RealInst, RegisterClass R0, RegisterOperand R1,
760                     SDPatternOperator OpNode, InstrItinClass Itin,
761                     bit IsComm = 1, bit HasSideEffects = 0,
762                     bit UsesCustomInserter = 0> :
763   PseudoSE<(outs R0:$ac), (ins R1:$rs, R1:$rt),
764            [(set R0:$ac, (OpNode R1:$rs, R1:$rt))], Itin>,
765   PseudoInstExpansion<(RealInst R1:$rs, R1:$rt)> {
766   let isCommutable = IsComm;
767   let hasSideEffects = HasSideEffects;
768   let usesCustomInserter = UsesCustomInserter;
769 }
770
771 // Pseudo multiply add/sub instruction with explicit accumulator register
772 // operands.
773 class MAddSubPseudo<Instruction RealInst, SDPatternOperator OpNode,
774                     InstrItinClass itin>
775   : PseudoSE<(outs ACC64:$ac),
776              (ins GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin),
777              [(set ACC64:$ac,
778               (OpNode GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin))],
779              itin>,
780     PseudoInstExpansion<(RealInst GPR32Opnd:$rs, GPR32Opnd:$rt)> {
781   string Constraints = "$acin = $ac";
782 }
783
784 class Div<string opstr, InstrItinClass itin, RegisterOperand RO,
785           list<Register> DefRegs> :
786   InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$$zero, $rs, $rt"),
787          [], itin, FrmR, opstr> {
788   let Defs = DefRegs;
789 }
790
791 // Move from Hi/Lo
792 class PseudoMFLOHI<RegisterClass DstRC, RegisterClass SrcRC, SDNode OpNode>
793   : PseudoSE<(outs DstRC:$rd), (ins SrcRC:$hilo),
794              [(set DstRC:$rd, (OpNode SrcRC:$hilo))], II_MFHI_MFLO>;
795
796 class MoveFromLOHI<string opstr, RegisterOperand RO, Register UseReg>:
797   InstSE<(outs RO:$rd), (ins), !strconcat(opstr, "\t$rd"), [], II_MFHI_MFLO,
798          FrmR, opstr> {
799   let Uses = [UseReg];
800   let neverHasSideEffects = 1;
801 }
802
803 class PseudoMTLOHI<RegisterClass DstRC, RegisterClass SrcRC>
804   : PseudoSE<(outs DstRC:$lohi), (ins SrcRC:$lo, SrcRC:$hi),
805              [(set DstRC:$lohi, (MipsMTLOHI SrcRC:$lo, SrcRC:$hi))],
806              II_MTHI_MTLO>;
807
808 class MoveToLOHI<string opstr, RegisterOperand RO, list<Register> DefRegs>:
809   InstSE<(outs), (ins RO:$rs), !strconcat(opstr, "\t$rs"), [], II_MTHI_MTLO,
810   FrmR, opstr> {
811   let Defs = DefRegs;
812   let neverHasSideEffects = 1;
813 }
814
815 class EffectiveAddress<string opstr, RegisterOperand RO> :
816   InstSE<(outs RO:$rt), (ins mem_ea:$addr), !strconcat(opstr, "\t$rt, $addr"),
817          [(set RO:$rt, addr:$addr)], NoItinerary, FrmI,
818          !strconcat(opstr, "_lea")> {
819   let isCodeGenOnly = 1;
820   let DecoderMethod = "DecodeMem";
821 }
822
823 // Count Leading Ones/Zeros in Word
824 class CountLeading0<string opstr, RegisterOperand RO>:
825   InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
826          [(set RO:$rd, (ctlz RO:$rs))], II_CLZ, FrmR, opstr>;
827
828 class CountLeading1<string opstr, RegisterOperand RO>:
829   InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
830          [(set RO:$rd, (ctlz (not RO:$rs)))], II_CLO, FrmR, opstr>;
831
832 // Sign Extend in Register.
833 class SignExtInReg<string opstr, ValueType vt, RegisterOperand RO,
834                    InstrItinClass itin> :
835   InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"),
836          [(set RO:$rd, (sext_inreg RO:$rt, vt))], itin, FrmR, opstr>;
837
838 // Subword Swap
839 class SubwordSwap<string opstr, RegisterOperand RO>:
840   InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"), [],
841          NoItinerary, FrmR, opstr> {
842   let neverHasSideEffects = 1;
843 }
844
845 // Read Hardware
846 class ReadHardware<RegisterOperand CPURegOperand, RegisterOperand RO> :
847   InstSE<(outs CPURegOperand:$rt), (ins RO:$rd), "rdhwr\t$rt, $rd", [],
848          II_RDHWR, FrmR>;
849
850 // Ext and Ins
851 class ExtBase<string opstr, RegisterOperand RO, Operand PosOpnd,
852               SDPatternOperator Op = null_frag>:
853   InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, size_ext:$size),
854          !strconcat(opstr, " $rt, $rs, $pos, $size"),
855          [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size))], NoItinerary,
856          FrmR, opstr>, ISA_MIPS32R2;
857
858 class InsBase<string opstr, RegisterOperand RO, Operand PosOpnd,
859               SDPatternOperator Op = null_frag>:
860   InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, size_ins:$size, RO:$src),
861          !strconcat(opstr, " $rt, $rs, $pos, $size"),
862          [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size, RO:$src))],
863          NoItinerary, FrmR, opstr>, ISA_MIPS32R2 {
864   let Constraints = "$src = $rt";
865 }
866
867 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
868 class Atomic2Ops<PatFrag Op, RegisterClass DRC> :
869   PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$incr),
870            [(set DRC:$dst, (Op iPTR:$ptr, DRC:$incr))]>;
871
872 // Atomic Compare & Swap.
873 class AtomicCmpSwap<PatFrag Op, RegisterClass DRC> :
874   PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$cmp, DRC:$swap),
875            [(set DRC:$dst, (Op iPTR:$ptr, DRC:$cmp, DRC:$swap))]>;
876
877 class LLBase<string opstr, RegisterOperand RO> :
878   InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
879          [], NoItinerary, FrmI> {
880   let DecoderMethod = "DecodeMem";
881   let mayLoad = 1;
882 }
883
884 class SCBase<string opstr, RegisterOperand RO> :
885   InstSE<(outs RO:$dst), (ins RO:$rt, mem:$addr),
886          !strconcat(opstr, "\t$rt, $addr"), [], NoItinerary, FrmI> {
887   let DecoderMethod = "DecodeMem";
888   let mayStore = 1;
889   let Constraints = "$rt = $dst";
890 }
891
892 class MFC3OP<string asmstr, RegisterOperand RO> :
893   InstSE<(outs RO:$rt, RO:$rd, uimm16:$sel), (ins),
894          !strconcat(asmstr, "\t$rt, $rd, $sel"), [], NoItinerary, FrmFR>;
895
896 class TrapBase<Instruction RealInst>
897   : PseudoSE<(outs), (ins), [(trap)], NoItinerary>,
898     PseudoInstExpansion<(RealInst 0, 0)> {
899   let isBarrier = 1;
900   let isTerminator = 1;
901   let isCodeGenOnly = 1;
902 }
903
904 //===----------------------------------------------------------------------===//
905 // Pseudo instructions
906 //===----------------------------------------------------------------------===//
907
908 // Return RA.
909 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1 in
910 def RetRA : PseudoSE<(outs), (ins), [(MipsRet)]>;
911
912 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
913 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins i32imm:$amt),
914                                   [(callseq_start timm:$amt)]>;
915 def ADJCALLSTACKUP   : MipsPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
916                                   [(callseq_end timm:$amt1, timm:$amt2)]>;
917 }
918
919 let usesCustomInserter = 1 in {
920   def ATOMIC_LOAD_ADD_I8   : Atomic2Ops<atomic_load_add_8, GPR32>;
921   def ATOMIC_LOAD_ADD_I16  : Atomic2Ops<atomic_load_add_16, GPR32>;
922   def ATOMIC_LOAD_ADD_I32  : Atomic2Ops<atomic_load_add_32, GPR32>;
923   def ATOMIC_LOAD_SUB_I8   : Atomic2Ops<atomic_load_sub_8, GPR32>;
924   def ATOMIC_LOAD_SUB_I16  : Atomic2Ops<atomic_load_sub_16, GPR32>;
925   def ATOMIC_LOAD_SUB_I32  : Atomic2Ops<atomic_load_sub_32, GPR32>;
926   def ATOMIC_LOAD_AND_I8   : Atomic2Ops<atomic_load_and_8, GPR32>;
927   def ATOMIC_LOAD_AND_I16  : Atomic2Ops<atomic_load_and_16, GPR32>;
928   def ATOMIC_LOAD_AND_I32  : Atomic2Ops<atomic_load_and_32, GPR32>;
929   def ATOMIC_LOAD_OR_I8    : Atomic2Ops<atomic_load_or_8, GPR32>;
930   def ATOMIC_LOAD_OR_I16   : Atomic2Ops<atomic_load_or_16, GPR32>;
931   def ATOMIC_LOAD_OR_I32   : Atomic2Ops<atomic_load_or_32, GPR32>;
932   def ATOMIC_LOAD_XOR_I8   : Atomic2Ops<atomic_load_xor_8, GPR32>;
933   def ATOMIC_LOAD_XOR_I16  : Atomic2Ops<atomic_load_xor_16, GPR32>;
934   def ATOMIC_LOAD_XOR_I32  : Atomic2Ops<atomic_load_xor_32, GPR32>;
935   def ATOMIC_LOAD_NAND_I8  : Atomic2Ops<atomic_load_nand_8, GPR32>;
936   def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, GPR32>;
937   def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, GPR32>;
938
939   def ATOMIC_SWAP_I8       : Atomic2Ops<atomic_swap_8, GPR32>;
940   def ATOMIC_SWAP_I16      : Atomic2Ops<atomic_swap_16, GPR32>;
941   def ATOMIC_SWAP_I32      : Atomic2Ops<atomic_swap_32, GPR32>;
942
943   def ATOMIC_CMP_SWAP_I8   : AtomicCmpSwap<atomic_cmp_swap_8, GPR32>;
944   def ATOMIC_CMP_SWAP_I16  : AtomicCmpSwap<atomic_cmp_swap_16, GPR32>;
945   def ATOMIC_CMP_SWAP_I32  : AtomicCmpSwap<atomic_cmp_swap_32, GPR32>;
946 }
947
948 /// Pseudo instructions for loading and storing accumulator registers.
949 let isPseudo = 1, isCodeGenOnly = 1 in {
950   def LOAD_ACC64  : Load<"", ACC64>;
951   def STORE_ACC64 : Store<"", ACC64>;
952 }
953
954 // We need these two pseudo instructions to avoid offset calculation for long
955 // branches.  See the comment in file MipsLongBranch.cpp for detailed
956 // explanation.
957
958 // Expands to: lui $dst, %hi($tgt - $baltgt)
959 def LONG_BRANCH_LUi : PseudoSE<(outs GPR32Opnd:$dst),
960   (ins brtarget:$tgt, brtarget:$baltgt), []>;
961
962 // Expands to: addiu $dst, $src, %lo($tgt - $baltgt)
963 def LONG_BRANCH_ADDiu : PseudoSE<(outs GPR32Opnd:$dst),
964   (ins GPR32Opnd:$src, brtarget:$tgt, brtarget:$baltgt), []>;
965
966 //===----------------------------------------------------------------------===//
967 // Instruction definition
968 //===----------------------------------------------------------------------===//
969 //===----------------------------------------------------------------------===//
970 // MipsI Instructions
971 //===----------------------------------------------------------------------===//
972
973 /// Arithmetic Instructions (ALU Immediate)
974 def ADDiu : MMRel, ArithLogicI<"addiu", simm16, GPR32Opnd, II_ADDIU, immSExt16,
975                                add>,
976             ADDI_FM<0x9>, IsAsCheapAsAMove;
977 def ADDi  : MMRel, ArithLogicI<"addi", simm16, GPR32Opnd>, ADDI_FM<0x8>;
978 def SLTi  : MMRel, SetCC_I<"slti", setlt, simm16, immSExt16, GPR32Opnd>,
979             SLTI_FM<0xa>;
980 def SLTiu : MMRel, SetCC_I<"sltiu", setult, simm16, immSExt16, GPR32Opnd>,
981             SLTI_FM<0xb>;
982 def ANDi  : MMRel, ArithLogicI<"andi", uimm16, GPR32Opnd, II_ANDI, immZExt16,
983                                and>,
984             ADDI_FM<0xc>;
985 def ORi   : MMRel, ArithLogicI<"ori", uimm16, GPR32Opnd, II_ORI, immZExt16,
986                                or>,
987             ADDI_FM<0xd>;
988 def XORi  : MMRel, ArithLogicI<"xori", uimm16, GPR32Opnd, II_XORI, immZExt16,
989                                xor>,
990             ADDI_FM<0xe>;
991 def LUi   : MMRel, LoadUpper<"lui", GPR32Opnd, uimm16>, LUI_FM;
992
993 /// Arithmetic Instructions (3-Operand, R-Type)
994 def ADDu  : MMRel, ArithLogicR<"addu", GPR32Opnd, 1, II_ADDU, add>,
995             ADD_FM<0, 0x21>;
996 def SUBu  : MMRel, ArithLogicR<"subu", GPR32Opnd, 0, II_SUBU, sub>,
997             ADD_FM<0, 0x23>;
998 let Defs = [HI0, LO0] in
999 def MUL   : MMRel, ArithLogicR<"mul", GPR32Opnd, 1, II_MUL, mul>,
1000             ADD_FM<0x1c, 2>;
1001 def ADD   : MMRel, ArithLogicR<"add", GPR32Opnd>, ADD_FM<0, 0x20>;
1002 def SUB   : MMRel, ArithLogicR<"sub", GPR32Opnd>, ADD_FM<0, 0x22>;
1003 def SLT   : MMRel, SetCC_R<"slt", setlt, GPR32Opnd>, ADD_FM<0, 0x2a>;
1004 def SLTu  : MMRel, SetCC_R<"sltu", setult, GPR32Opnd>, ADD_FM<0, 0x2b>;
1005 def AND   : MMRel, ArithLogicR<"and", GPR32Opnd, 1, II_AND, and>,
1006             ADD_FM<0, 0x24>;
1007 def OR    : MMRel, ArithLogicR<"or", GPR32Opnd, 1, II_OR, or>,
1008             ADD_FM<0, 0x25>;
1009 def XOR   : MMRel, ArithLogicR<"xor", GPR32Opnd, 1, II_XOR, xor>,
1010             ADD_FM<0, 0x26>;
1011 def NOR   : MMRel, LogicNOR<"nor", GPR32Opnd>, ADD_FM<0, 0x27>;
1012
1013 /// Shift Instructions
1014 def SLL  : MMRel, shift_rotate_imm<"sll", uimm5, GPR32Opnd, II_SLL, shl,
1015                                    immZExt5>, SRA_FM<0, 0>;
1016 def SRL  : MMRel, shift_rotate_imm<"srl", uimm5, GPR32Opnd, II_SRL, srl,
1017                                    immZExt5>, SRA_FM<2, 0>;
1018 def SRA  : MMRel, shift_rotate_imm<"sra", uimm5, GPR32Opnd, II_SRA, sra,
1019                                    immZExt5>, SRA_FM<3, 0>;
1020 def SLLV : MMRel, shift_rotate_reg<"sllv", GPR32Opnd, II_SLLV, shl>,
1021            SRLV_FM<4, 0>;
1022 def SRLV : MMRel, shift_rotate_reg<"srlv", GPR32Opnd, II_SRLV, srl>,
1023            SRLV_FM<6, 0>;
1024 def SRAV : MMRel, shift_rotate_reg<"srav", GPR32Opnd, II_SRAV, sra>,
1025            SRLV_FM<7, 0>;
1026
1027 // Rotate Instructions
1028 def ROTR  : MMRel, shift_rotate_imm<"rotr", uimm5, GPR32Opnd, II_ROTR, rotr,
1029                                     immZExt5>,
1030             SRA_FM<2, 1>, ISA_MIPS32R2;
1031 def ROTRV : MMRel, shift_rotate_reg<"rotrv", GPR32Opnd, II_ROTRV, rotr>,
1032             SRLV_FM<6, 1>, ISA_MIPS32R2;
1033
1034 /// Load and Store Instructions
1035 ///  aligned
1036 def LB  : Load<"lb", GPR32Opnd, sextloadi8, II_LB>, MMRel, LW_FM<0x20>;
1037 def LBu : Load<"lbu", GPR32Opnd, zextloadi8, II_LBU, addrDefault>, MMRel,
1038           LW_FM<0x24>;
1039 def LH  : Load<"lh", GPR32Opnd, sextloadi16, II_LH, addrDefault>, MMRel,
1040           LW_FM<0x21>;
1041 def LHu : Load<"lhu", GPR32Opnd, zextloadi16, II_LHU>, MMRel, LW_FM<0x25>;
1042 def LW  : Load<"lw", GPR32Opnd, load, II_LW, addrDefault>, MMRel,
1043           LW_FM<0x23>;
1044 def SB  : Store<"sb", GPR32Opnd, truncstorei8, II_SB>, MMRel, LW_FM<0x28>;
1045 def SH  : Store<"sh", GPR32Opnd, truncstorei16, II_SH>, MMRel, LW_FM<0x29>;
1046 def SW  : Store<"sw", GPR32Opnd, store, II_SW>, MMRel, LW_FM<0x2b>;
1047
1048 /// load/store left/right
1049 let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1050     AdditionalPredicates = [NotInMicroMips] in {
1051 def LWL : LoadLeftRight<"lwl", MipsLWL, GPR32Opnd, II_LWL>, LW_FM<0x22>;
1052 def LWR : LoadLeftRight<"lwr", MipsLWR, GPR32Opnd, II_LWR>, LW_FM<0x26>;
1053 def SWL : StoreLeftRight<"swl", MipsSWL, GPR32Opnd, II_SWL>, LW_FM<0x2a>;
1054 def SWR : StoreLeftRight<"swr", MipsSWR, GPR32Opnd, II_SWR>, LW_FM<0x2e>;
1055 }
1056
1057 def SYNC : MMRel, SYNC_FT<"sync">, SYNC_FM;
1058 def TEQ : MMRel, TEQ_FT<"teq", GPR32Opnd>, TEQ_FM<0x34>;
1059 def TGE : MMRel, TEQ_FT<"tge", GPR32Opnd>, TEQ_FM<0x30>;
1060 def TGEU : MMRel, TEQ_FT<"tgeu", GPR32Opnd>, TEQ_FM<0x31>;
1061 def TLT : MMRel, TEQ_FT<"tlt", GPR32Opnd>, TEQ_FM<0x32>;
1062 def TLTU : MMRel, TEQ_FT<"tltu", GPR32Opnd>, TEQ_FM<0x33>;
1063 def TNE : MMRel, TEQ_FT<"tne", GPR32Opnd>, TEQ_FM<0x36>;
1064
1065 def TEQI : MMRel, TEQI_FT<"teqi", GPR32Opnd>, TEQI_FM<0xc>, ISA_MIPS2;
1066 def TGEI : MMRel, TEQI_FT<"tgei", GPR32Opnd>, TEQI_FM<0x8>, ISA_MIPS2;
1067 def TGEIU : MMRel, TEQI_FT<"tgeiu", GPR32Opnd>, TEQI_FM<0x9>, ISA_MIPS2;
1068 def TLTI : MMRel, TEQI_FT<"tlti", GPR32Opnd>, TEQI_FM<0xa>, ISA_MIPS2;
1069 def TTLTIU : MMRel, TEQI_FT<"tltiu", GPR32Opnd>, TEQI_FM<0xb>, ISA_MIPS2;
1070 def TNEI : MMRel, TEQI_FT<"tnei", GPR32Opnd>, TEQI_FM<0xe>, ISA_MIPS2;
1071
1072 def BREAK : MMRel, BRK_FT<"break">, BRK_FM<0xd>;
1073 def SYSCALL : MMRel, SYS_FT<"syscall">, SYS_FM<0xc>;
1074 def TRAP : TrapBase<BREAK>;
1075
1076 def ERET : MMRel, ER_FT<"eret">, ER_FM<0x18>, INSN_MIPS3_32;
1077 def DERET : MMRel, ER_FT<"deret">, ER_FM<0x1f>;
1078
1079 def EI : MMRel, DEI_FT<"ei", GPR32Opnd>, EI_FM<1>;
1080 def DI : MMRel, DEI_FT<"di", GPR32Opnd>, EI_FM<0>;
1081
1082 let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1083     AdditionalPredicates = [NotInMicroMips] in {
1084 def WAIT : WAIT_FT<"wait">, WAIT_FM;
1085
1086 /// Load-linked, Store-conditional
1087 def LL : LLBase<"ll", GPR32Opnd>, LW_FM<0x30>, ISA_MIPS2;
1088 def SC : SCBase<"sc", GPR32Opnd>, LW_FM<0x38>, ISA_MIPS2;
1089 }
1090
1091 /// Jump and Branch Instructions
1092 def J       : MMRel, JumpFJ<jmptarget, "j", br, bb, "j">, FJ<2>,
1093               AdditionalRequires<[RelocStatic]>, IsBranch;
1094 def JR      : MMRel, IndirectBranch<"jr", GPR32Opnd>, MTLO_FM<8>;
1095 def BEQ     : MMRel, CBranch<"beq", brtarget, seteq, GPR32Opnd>, BEQ_FM<4>;
1096 def BNE     : MMRel, CBranch<"bne", brtarget, setne, GPR32Opnd>, BEQ_FM<5>;
1097 def BGEZ    : MMRel, CBranchZero<"bgez", brtarget, setge, GPR32Opnd>,
1098               BGEZ_FM<1, 1>;
1099 def BGTZ    : MMRel, CBranchZero<"bgtz", brtarget, setgt, GPR32Opnd>,
1100               BGEZ_FM<7, 0>;
1101 def BLEZ    : MMRel, CBranchZero<"blez", brtarget, setle, GPR32Opnd>,
1102               BGEZ_FM<6, 0>;
1103 def BLTZ    : MMRel, CBranchZero<"bltz", brtarget, setlt, GPR32Opnd>,
1104               BGEZ_FM<1, 0>;
1105 def B       : UncondBranch<BEQ>;
1106
1107 def JAL  : MMRel, JumpLink<"jal", calltarget>, FJ<3>;
1108 let AdditionalPredicates = [NotInMicroMips] in {
1109 def JALR : JumpLinkReg<"jalr", GPR32Opnd>, JALR_FM;
1110 def JALRPseudo : JumpLinkRegPseudo<GPR32Opnd, JALR, RA>;
1111 }
1112 def JALX  : JumpLink<"jalx", calltarget>, FJ<0x1D>;
1113 def BGEZAL : MMRel, BGEZAL_FT<"bgezal", brtarget, GPR32Opnd>, BGEZAL_FM<0x11>;
1114 def BLTZAL : MMRel, BGEZAL_FT<"bltzal", brtarget, GPR32Opnd>, BGEZAL_FM<0x10>;
1115 def BAL_BR : BAL_BR_Pseudo<BGEZAL>;
1116 def TAILCALL : TailCall<J>;
1117 def TAILCALL_R : TailCallReg<GPR32Opnd, JR>;
1118
1119 def RET : MMRel, RetBase<"ret", GPR32Opnd>, MTLO_FM<8>;
1120
1121 // Exception handling related node and instructions.
1122 // The conversion sequence is:
1123 // ISD::EH_RETURN -> MipsISD::EH_RETURN ->
1124 // MIPSeh_return -> (stack change + indirect branch)
1125 //
1126 // MIPSeh_return takes the place of regular return instruction
1127 // but takes two arguments (V1, V0) which are used for storing
1128 // the offset and return address respectively.
1129 def SDT_MipsEHRET : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisPtrTy<1>]>;
1130
1131 def MIPSehret : SDNode<"MipsISD::EH_RETURN", SDT_MipsEHRET,
1132                       [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
1133
1134 let Uses = [V0, V1], isTerminator = 1, isReturn = 1, isBarrier = 1 in {
1135   def MIPSeh_return32 : MipsPseudo<(outs), (ins GPR32:$spoff, GPR32:$dst),
1136                                 [(MIPSehret GPR32:$spoff, GPR32:$dst)]>;
1137   def MIPSeh_return64 : MipsPseudo<(outs), (ins GPR64:$spoff,
1138                                                 GPR64:$dst),
1139                                 [(MIPSehret GPR64:$spoff, GPR64:$dst)]>;
1140 }
1141
1142 /// Multiply and Divide Instructions.
1143 def MULT  : MMRel, Mult<"mult", II_MULT, GPR32Opnd, [HI0, LO0]>,
1144             MULT_FM<0, 0x18>;
1145 def MULTu : MMRel, Mult<"multu", II_MULTU, GPR32Opnd, [HI0, LO0]>,
1146             MULT_FM<0, 0x19>;
1147 def SDIV  : MMRel, Div<"div", II_DIV, GPR32Opnd, [HI0, LO0]>,
1148             MULT_FM<0, 0x1a>;
1149 def UDIV  : MMRel, Div<"divu", II_DIVU, GPR32Opnd, [HI0, LO0]>,
1150             MULT_FM<0, 0x1b>;
1151
1152 def MTHI : MMRel, MoveToLOHI<"mthi", GPR32Opnd, [HI0]>, MTLO_FM<0x11>;
1153 def MTLO : MMRel, MoveToLOHI<"mtlo", GPR32Opnd, [LO0]>, MTLO_FM<0x13>;
1154 let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1155     AdditionalPredicates = [NotInMicroMips] in {
1156 def MFHI : MMRel, MoveFromLOHI<"mfhi", GPR32Opnd, AC0>, MFLO_FM<0x10>;
1157 def MFLO : MMRel, MoveFromLOHI<"mflo", GPR32Opnd, AC0>, MFLO_FM<0x12>;
1158 }
1159
1160 /// Sign Ext In Register Instructions.
1161 def SEB : MMRel, SignExtInReg<"seb", i8, GPR32Opnd, II_SEB>,
1162           SEB_FM<0x10, 0x20>, ISA_MIPS32R2;
1163 def SEH : MMRel, SignExtInReg<"seh", i16, GPR32Opnd, II_SEH>,
1164           SEB_FM<0x18, 0x20>, ISA_MIPS32R2;
1165
1166 /// Count Leading
1167 def CLZ : MMRel, CountLeading0<"clz", GPR32Opnd>, CLO_FM<0x20>, ISA_MIPS32;
1168 def CLO : MMRel, CountLeading1<"clo", GPR32Opnd>, CLO_FM<0x21>, ISA_MIPS32;
1169
1170 /// Word Swap Bytes Within Halfwords
1171 def WSBH : MMRel, SubwordSwap<"wsbh", GPR32Opnd>, SEB_FM<2, 0x20>, ISA_MIPS32R2;
1172
1173 /// No operation.
1174 def NOP : PseudoSE<(outs), (ins), []>, PseudoInstExpansion<(SLL ZERO, ZERO, 0)>;
1175
1176 // FrameIndexes are legalized when they are operands from load/store
1177 // instructions. The same not happens for stack address copies, so an
1178 // add op with mem ComplexPattern is used and the stack address copy
1179 // can be matched. It's similar to Sparc LEA_ADDRi
1180 def LEA_ADDiu : MMRel, EffectiveAddress<"addiu", GPR32Opnd>, LW_FM<9>;
1181
1182 // MADD*/MSUB*
1183 def MADD  : MMRel, MArithR<"madd", II_MADD, 1>, MULT_FM<0x1c, 0>;
1184 def MADDU : MMRel, MArithR<"maddu", II_MADDU, 1>, MULT_FM<0x1c, 1>;
1185 def MSUB  : MMRel, MArithR<"msub", II_MSUB>, MULT_FM<0x1c, 4>;
1186 def MSUBU : MMRel, MArithR<"msubu", II_MSUBU>, MULT_FM<0x1c, 5>;
1187
1188 let AdditionalPredicates = [NotDSP] in {
1189 def PseudoMULT  : MultDivPseudo<MULT, ACC64, GPR32Opnd, MipsMult, II_MULT>;
1190 def PseudoMULTu : MultDivPseudo<MULTu, ACC64, GPR32Opnd, MipsMultu, II_MULTU>;
1191 def PseudoMFHI : PseudoMFLOHI<GPR32, ACC64, MipsMFHI>;
1192 def PseudoMFLO : PseudoMFLOHI<GPR32, ACC64, MipsMFLO>;
1193 def PseudoMTLOHI : PseudoMTLOHI<ACC64, GPR32>;
1194 def PseudoMADD  : MAddSubPseudo<MADD, MipsMAdd, II_MADD>;
1195 def PseudoMADDU : MAddSubPseudo<MADDU, MipsMAddu, II_MADDU>;
1196 def PseudoMSUB  : MAddSubPseudo<MSUB, MipsMSub, II_MSUB>;
1197 def PseudoMSUBU : MAddSubPseudo<MSUBU, MipsMSubu, II_MSUBU>;
1198 }
1199
1200 def PseudoSDIV : MultDivPseudo<SDIV, ACC64, GPR32Opnd, MipsDivRem, II_DIV,
1201                                0, 1, 1>;
1202 def PseudoUDIV : MultDivPseudo<UDIV, ACC64, GPR32Opnd, MipsDivRemU, II_DIVU,
1203                                0, 1, 1>;
1204
1205 def RDHWR : ReadHardware<GPR32Opnd, HWRegsOpnd>, RDHWR_FM;
1206
1207 def EXT : MMRel, ExtBase<"ext", GPR32Opnd, uimm5, MipsExt>, EXT_FM<0>;
1208 def INS : MMRel, InsBase<"ins", GPR32Opnd, uimm5, MipsIns>, EXT_FM<4>;
1209
1210 /// Move Control Registers From/To CPU Registers
1211 def MFC0 : MFC3OP<"mfc0", GPR32Opnd>, MFC3OP_FM<0x10, 0>;
1212 def MTC0 : MFC3OP<"mtc0", GPR32Opnd>, MFC3OP_FM<0x10, 4>;
1213 def MFC2 : MFC3OP<"mfc2", GPR32Opnd>, MFC3OP_FM<0x12, 0>;
1214 def MTC2 : MFC3OP<"mtc2", GPR32Opnd>, MFC3OP_FM<0x12, 4>;
1215
1216 class Barrier<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary,
1217                                       FrmOther>;
1218 def SSNOP : Barrier<"ssnop">, BARRIER_FM<1>;
1219 def EHB : Barrier<"ehb">, BARRIER_FM<3>;
1220 def PAUSE : Barrier<"pause">, BARRIER_FM<5>, ISA_MIPS32R2;
1221
1222 class TLB<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary,
1223                                       FrmOther>;
1224 def TLBP : TLB<"tlbp">, COP0_TLB_FM<0x08>;
1225 def TLBR : TLB<"tlbr">, COP0_TLB_FM<0x01>;
1226 def TLBWI : TLB<"tlbwi">, COP0_TLB_FM<0x02>;
1227 def TLBWR : TLB<"tlbwr">, COP0_TLB_FM<0x06>;
1228
1229 //===----------------------------------------------------------------------===//
1230 // Instruction aliases
1231 //===----------------------------------------------------------------------===//
1232 def : MipsInstAlias<"move $dst, $src",
1233                     (ADDu GPR32Opnd:$dst, GPR32Opnd:$src,ZERO), 1>,
1234       Requires<[IsGP32, NotInMicroMips]>;
1235 def : MipsInstAlias<"bal $offset", (BGEZAL ZERO, brtarget:$offset), 0>;
1236 def : MipsInstAlias<"addu $rs, $rt, $imm",
1237                     (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1238 def : MipsInstAlias<"add $rs, $rt, $imm",
1239                     (ADDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1240 def : MipsInstAlias<"and $rs, $rt, $imm",
1241                     (ANDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1242 def : MipsInstAlias<"j $rs", (JR GPR32Opnd:$rs), 0>;
1243 let Predicates = [NotInMicroMips] in {
1244 def : MipsInstAlias<"jalr $rs", (JALR RA, GPR32Opnd:$rs), 0>;
1245 }
1246 def : MipsInstAlias<"jal $rs", (JALR RA, GPR32Opnd:$rs), 0>;
1247 def : MipsInstAlias<"jal $rd,$rs", (JALR GPR32Opnd:$rd, GPR32Opnd:$rs), 0>;
1248 def : MipsInstAlias<"not $rt, $rs",
1249                     (NOR GPR32Opnd:$rt, GPR32Opnd:$rs, ZERO), 0>;
1250 def : MipsInstAlias<"neg $rt, $rs",
1251                     (SUB GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1252 def : MipsInstAlias<"negu $rt",
1253                     (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rt), 0>;
1254 def : MipsInstAlias<"negu $rt, $rs",
1255                     (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1256 def : MipsInstAlias<"slt $rs, $rt, $imm",
1257                     (SLTi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1258 def : MipsInstAlias<"sltu $rt, $rs, $imm",
1259                     (SLTiu GPR32Opnd:$rt, GPR32Opnd:$rs, simm16:$imm), 0>;
1260 def : MipsInstAlias<"xor $rs, $rt, $imm",
1261                     (XORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>;
1262 def : MipsInstAlias<"or $rs, $rt, $imm",
1263                     (ORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>;
1264 def : MipsInstAlias<"nop", (SLL ZERO, ZERO, 0), 1>;
1265 def : MipsInstAlias<"mfc0 $rt, $rd", (MFC0 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1266 def : MipsInstAlias<"mtc0 $rt, $rd", (MTC0 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1267 def : MipsInstAlias<"mfc2 $rt, $rd", (MFC2 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1268 def : MipsInstAlias<"mtc2 $rt, $rd", (MTC2 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1269 def : MipsInstAlias<"b $offset", (BEQ ZERO, ZERO, brtarget:$offset), 0>;
1270 def : MipsInstAlias<"bnez $rs,$offset",
1271                     (BNE GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1272 def : MipsInstAlias<"beqz $rs,$offset",
1273                     (BEQ GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1274 def : MipsInstAlias<"syscall", (SYSCALL 0), 1>;
1275     
1276 def : MipsInstAlias<"break $imm", (BREAK uimm10:$imm, 0), 1>;
1277 def : MipsInstAlias<"break", (BREAK 0, 0), 1>;
1278 def : MipsInstAlias<"ei", (EI ZERO), 1>;
1279 def : MipsInstAlias<"di", (DI ZERO), 1>;
1280
1281 def  : MipsInstAlias<"teq $rs, $rt", (TEQ GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1282 def  : MipsInstAlias<"tge $rs, $rt", (TGE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1283 def  : MipsInstAlias<"tgeu $rs, $rt", (TGEU GPR32Opnd:$rs, GPR32Opnd:$rt, 0),
1284                      1>;
1285 def  : MipsInstAlias<"tlt $rs, $rt", (TLT GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1286 def  : MipsInstAlias<"tltu $rs, $rt", (TLTU GPR32Opnd:$rs, GPR32Opnd:$rt, 0),
1287                      1>;
1288 def  : MipsInstAlias<"tne $rs, $rt", (TNE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1289 def  : MipsInstAlias<"sll $rd, $rt, $rs",
1290                      (SLLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1291 def : MipsInstAlias<"sub, $rd, $rs, $imm",
1292                     (ADDi GPR32Opnd:$rd, GPR32Opnd:$rs,
1293                           InvertedImOperand:$imm)>;
1294 def : MipsInstAlias<"sub $rs, $imm",
1295                     (ADDi GPR32Opnd:$rs, GPR32Opnd:$rs, InvertedImOperand:$imm),
1296                     0>;
1297 def : MipsInstAlias<"subu, $rd, $rs, $imm",
1298                     (ADDiu GPR32Opnd:$rd, GPR32Opnd:$rs,
1299                            InvertedImOperand:$imm)>;
1300 def : MipsInstAlias<"subu $rs, $imm", (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rs,
1301                                              InvertedImOperand:$imm), 0>;
1302 def : MipsInstAlias<"sra $rd, $rt, $rs",
1303                     (SRAV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1304 def : MipsInstAlias<"srl $rd, $rt, $rs",
1305                     (SRLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1306 //===----------------------------------------------------------------------===//
1307 // Assembler Pseudo Instructions
1308 //===----------------------------------------------------------------------===//
1309
1310 class LoadImm32< string instr_asm, Operand Od, RegisterOperand RO> :
1311   MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
1312                      !strconcat(instr_asm, "\t$rt, $imm32")> ;
1313 def LoadImm32Reg : LoadImm32<"li", uimm5, GPR32Opnd>;
1314
1315 class LoadAddress<string instr_asm, Operand MemOpnd, RegisterOperand RO> :
1316   MipsAsmPseudoInst<(outs RO:$rt), (ins MemOpnd:$addr),
1317                      !strconcat(instr_asm, "\t$rt, $addr")> ;
1318 def LoadAddr32Reg : LoadAddress<"la", mem, GPR32Opnd>;
1319
1320 class LoadAddressImm<string instr_asm, Operand Od, RegisterOperand RO> :
1321   MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
1322                      !strconcat(instr_asm, "\t$rt, $imm32")> ;
1323 def LoadAddr32Imm : LoadAddressImm<"la", uimm5, GPR32Opnd>;
1324
1325 //===----------------------------------------------------------------------===//
1326 //  Arbitrary patterns that map to one or more instructions
1327 //===----------------------------------------------------------------------===//
1328
1329 // Load/store pattern templates.
1330 class LoadRegImmPat<Instruction LoadInst, ValueType ValTy, PatFrag Node> :
1331   MipsPat<(ValTy (Node addrRegImm:$a)), (LoadInst addrRegImm:$a)>;
1332
1333 class StoreRegImmPat<Instruction StoreInst, ValueType ValTy> :
1334   MipsPat<(store ValTy:$v, addrRegImm:$a), (StoreInst ValTy:$v, addrRegImm:$a)>;
1335
1336 // Small immediates
1337 def : MipsPat<(i32 immSExt16:$in),
1338               (ADDiu ZERO, imm:$in)>;
1339 def : MipsPat<(i32 immZExt16:$in),
1340               (ORi ZERO, imm:$in)>;
1341 def : MipsPat<(i32 immLow16Zero:$in),
1342               (LUi (HI16 imm:$in))>;
1343
1344 // Arbitrary immediates
1345 def : MipsPat<(i32 imm:$imm),
1346           (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
1347
1348 // Carry MipsPatterns
1349 def : MipsPat<(subc GPR32:$lhs, GPR32:$rhs),
1350               (SUBu GPR32:$lhs, GPR32:$rhs)>;
1351 let AdditionalPredicates = [NotDSP] in {
1352   def : MipsPat<(addc GPR32:$lhs, GPR32:$rhs),
1353                 (ADDu GPR32:$lhs, GPR32:$rhs)>;
1354   def : MipsPat<(addc  GPR32:$src, immSExt16:$imm),
1355                 (ADDiu GPR32:$src, imm:$imm)>;
1356 }
1357
1358 // Call
1359 def : MipsPat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1360               (JAL tglobaladdr:$dst)>;
1361 def : MipsPat<(MipsJmpLink (i32 texternalsym:$dst)),
1362               (JAL texternalsym:$dst)>;
1363 //def : MipsPat<(MipsJmpLink GPR32:$dst),
1364 //              (JALR GPR32:$dst)>;
1365
1366 // Tail call
1367 def : MipsPat<(MipsTailCall (iPTR tglobaladdr:$dst)),
1368               (TAILCALL tglobaladdr:$dst)>;
1369 def : MipsPat<(MipsTailCall (iPTR texternalsym:$dst)),
1370               (TAILCALL texternalsym:$dst)>;
1371 // hi/lo relocs
1372 def : MipsPat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
1373 def : MipsPat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
1374 def : MipsPat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
1375 def : MipsPat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
1376 def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
1377 def : MipsPat<(MipsHi texternalsym:$in), (LUi texternalsym:$in)>;
1378
1379 def : MipsPat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
1380 def : MipsPat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
1381 def : MipsPat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
1382 def : MipsPat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
1383 def : MipsPat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
1384 def : MipsPat<(MipsLo texternalsym:$in), (ADDiu ZERO, texternalsym:$in)>;
1385
1386 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaladdr:$lo)),
1387               (ADDiu GPR32:$hi, tglobaladdr:$lo)>;
1388 def : MipsPat<(add GPR32:$hi, (MipsLo tblockaddress:$lo)),
1389               (ADDiu GPR32:$hi, tblockaddress:$lo)>;
1390 def : MipsPat<(add GPR32:$hi, (MipsLo tjumptable:$lo)),
1391               (ADDiu GPR32:$hi, tjumptable:$lo)>;
1392 def : MipsPat<(add GPR32:$hi, (MipsLo tconstpool:$lo)),
1393               (ADDiu GPR32:$hi, tconstpool:$lo)>;
1394 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaltlsaddr:$lo)),
1395               (ADDiu GPR32:$hi, tglobaltlsaddr:$lo)>;
1396
1397 // gp_rel relocs
1398 def : MipsPat<(add GPR32:$gp, (MipsGPRel tglobaladdr:$in)),
1399               (ADDiu GPR32:$gp, tglobaladdr:$in)>;
1400 def : MipsPat<(add GPR32:$gp, (MipsGPRel tconstpool:$in)),
1401               (ADDiu GPR32:$gp, tconstpool:$in)>;
1402
1403 // wrapper_pic
1404 class WrapperPat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1405       MipsPat<(MipsWrapper RC:$gp, node:$in),
1406               (ADDiuOp RC:$gp, node:$in)>;
1407
1408 def : WrapperPat<tglobaladdr, ADDiu, GPR32>;
1409 def : WrapperPat<tconstpool, ADDiu, GPR32>;
1410 def : WrapperPat<texternalsym, ADDiu, GPR32>;
1411 def : WrapperPat<tblockaddress, ADDiu, GPR32>;
1412 def : WrapperPat<tjumptable, ADDiu, GPR32>;
1413 def : WrapperPat<tglobaltlsaddr, ADDiu, GPR32>;
1414
1415 // Mips does not have "not", so we expand our way
1416 def : MipsPat<(not GPR32:$in),
1417               (NOR GPR32Opnd:$in, ZERO)>;
1418
1419 // extended loads
1420 def : MipsPat<(i32 (extloadi1  addr:$src)), (LBu addr:$src)>;
1421 def : MipsPat<(i32 (extloadi8  addr:$src)), (LBu addr:$src)>;
1422 def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
1423
1424 // peepholes
1425 def : MipsPat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
1426
1427 // brcond patterns
1428 multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
1429                       Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
1430                       Instruction SLTiuOp, Register ZEROReg> {
1431 def : MipsPat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
1432               (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
1433 def : MipsPat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
1434               (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
1435
1436 def : MipsPat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
1437               (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1438 def : MipsPat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
1439               (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1440 def : MipsPat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1441               (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1442 def : MipsPat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1443               (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1444 def : MipsPat<(brcond (i32 (setgt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
1445               (BEQ (SLTiOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
1446 def : MipsPat<(brcond (i32 (setugt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
1447               (BEQ (SLTiuOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
1448
1449 def : MipsPat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
1450               (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1451 def : MipsPat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
1452               (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1453
1454 def : MipsPat<(brcond RC:$cond, bb:$dst),
1455               (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
1456 }
1457
1458 defm : BrcondPats<GPR32, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
1459
1460 def : MipsPat<(brcond (i32 (setlt i32:$lhs, 1)), bb:$dst),
1461               (BLEZ i32:$lhs, bb:$dst)>;
1462 def : MipsPat<(brcond (i32 (setgt i32:$lhs, -1)), bb:$dst),
1463               (BGEZ i32:$lhs, bb:$dst)>;
1464
1465 // setcc patterns
1466 multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
1467                      Instruction SLTuOp, Register ZEROReg> {
1468   def : MipsPat<(seteq RC:$lhs, 0),
1469                 (SLTiuOp RC:$lhs, 1)>;
1470   def : MipsPat<(setne RC:$lhs, 0),
1471                 (SLTuOp ZEROReg, RC:$lhs)>;
1472   def : MipsPat<(seteq RC:$lhs, RC:$rhs),
1473                 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
1474   def : MipsPat<(setne RC:$lhs, RC:$rhs),
1475                 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
1476 }
1477
1478 multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1479   def : MipsPat<(setle RC:$lhs, RC:$rhs),
1480                 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
1481   def : MipsPat<(setule RC:$lhs, RC:$rhs),
1482                 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
1483 }
1484
1485 multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1486   def : MipsPat<(setgt RC:$lhs, RC:$rhs),
1487                 (SLTOp RC:$rhs, RC:$lhs)>;
1488   def : MipsPat<(setugt RC:$lhs, RC:$rhs),
1489                 (SLTuOp RC:$rhs, RC:$lhs)>;
1490 }
1491
1492 multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1493   def : MipsPat<(setge RC:$lhs, RC:$rhs),
1494                 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
1495   def : MipsPat<(setuge RC:$lhs, RC:$rhs),
1496                 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
1497 }
1498
1499 multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
1500                         Instruction SLTiuOp> {
1501   def : MipsPat<(setge RC:$lhs, immSExt16:$rhs),
1502                 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
1503   def : MipsPat<(setuge RC:$lhs, immSExt16:$rhs),
1504                 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1505 }
1506
1507 defm : SeteqPats<GPR32, SLTiu, XOR, SLTu, ZERO>;
1508 defm : SetlePats<GPR32, SLT, SLTu>;
1509 defm : SetgtPats<GPR32, SLT, SLTu>;
1510 defm : SetgePats<GPR32, SLT, SLTu>;
1511 defm : SetgeImmPats<GPR32, SLTi, SLTiu>;
1512
1513 // bswap pattern
1514 def : MipsPat<(bswap GPR32:$rt), (ROTR (WSBH GPR32:$rt), 16)>;
1515
1516 // Load halfword/word patterns.
1517 let AddedComplexity = 40 in {
1518   def : LoadRegImmPat<LBu, i32, zextloadi8>;
1519   def : LoadRegImmPat<LH, i32, sextloadi16>;
1520   def : LoadRegImmPat<LW, i32, load>;
1521 }
1522
1523 //===----------------------------------------------------------------------===//
1524 // Floating Point Support
1525 //===----------------------------------------------------------------------===//
1526
1527 include "MipsInstrFPU.td"
1528 include "Mips64InstrInfo.td"
1529 include "MipsCondMov.td"
1530
1531 include "Mips32r6InstrInfo.td"
1532 include "Mips64r6InstrInfo.td"
1533
1534 //
1535 // Mips16
1536
1537 include "Mips16InstrFormats.td"
1538 include "Mips16InstrInfo.td"
1539
1540 // DSP
1541 include "MipsDSPInstrFormats.td"
1542 include "MipsDSPInstrInfo.td"
1543
1544 // MSA
1545 include "MipsMSAInstrFormats.td"
1546 include "MipsMSAInstrInfo.td"
1547
1548 // Micromips
1549 include "MicroMipsInstrFormats.td"
1550 include "MicroMipsInstrInfo.td"
1551 include "MicroMipsInstrFPU.td"