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