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