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