Add definitions of conditional moves with 64-bit operands. Comment out code for
[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 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
17
18 include "MipsInstrFormats.td"
19
20 //===----------------------------------------------------------------------===//
21 // Mips profiles and nodes
22 //===----------------------------------------------------------------------===//
23
24 def SDT_MipsRet          : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
25 def SDT_MipsJmpLink      : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
26 def SDT_MipsCMov         : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
27                                                 SDTCisSameAs<1, 2>,
28                                                 SDTCisSameAs<3, 4>,
29                                                 SDTCisInt<4>]>;
30 def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
31 def SDT_MipsCallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
32 def SDT_MipsMAddMSub     : SDTypeProfile<0, 4,
33                                          [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
34                                           SDTCisSameAs<1, 2>,
35                                           SDTCisSameAs<2, 3>]>;
36 def SDT_MipsDivRem       : SDTypeProfile<0, 2,
37                                          [SDTCisInt<0>,
38                                           SDTCisSameAs<0, 1>]>;
39
40 def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
41
42 def SDT_MipsDynAlloc    : SDTypeProfile<1, 1, [SDTCisVT<0, i32>,
43                                                SDTCisVT<1, iPTR>]>;
44 def SDT_Sync             : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
45
46 def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
47                                    SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
48 def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
49                                    SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
50                                    SDTCisSameAs<0, 4>]>;
51
52 // Call
53 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
54                          [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
55                           SDNPVariadic]>;
56
57 // Hi and Lo nodes are used to handle global addresses. Used on
58 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
59 // static model. (nothing to do with Mips Registers Hi and Lo)
60 def MipsHi    : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
61 def MipsLo    : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
62 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
63
64 // TlsGd node is used to handle General Dynamic TLS
65 def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
66
67 // TprelHi and TprelLo nodes are used to handle Local Exec TLS
68 def MipsTprelHi    : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
69 def MipsTprelLo    : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
70
71 // Thread pointer
72 def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
73
74 // Return
75 def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
76                      SDNPOptInGlue]>;
77
78 // These are target-independent nodes, but have target-specific formats.
79 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
80                            [SDNPHasChain, SDNPOutGlue]>;
81 def callseq_end   : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
82                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
83
84 // MAdd*/MSub* nodes
85 def MipsMAdd      : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
86                            [SDNPOptInGlue, SDNPOutGlue]>;
87 def MipsMAddu     : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
88                            [SDNPOptInGlue, SDNPOutGlue]>;
89 def MipsMSub      : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
90                            [SDNPOptInGlue, SDNPOutGlue]>;
91 def MipsMSubu     : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
92                            [SDNPOptInGlue, SDNPOutGlue]>;
93
94 // DivRem(u) nodes
95 def MipsDivRem    : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
96                            [SDNPOutGlue]>;
97 def MipsDivRemU   : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
98                            [SDNPOutGlue]>;
99
100 // Target constant nodes that are not part of any isel patterns and remain
101 // unchanged can cause instructions with illegal operands to be emitted.
102 // Wrapper node patterns give the instruction selector a chance to replace
103 // target constant nodes that would otherwise remain unchanged with ADDiu
104 // nodes. Without these wrapper node patterns, the following conditional move
105 // instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
106 // compiled: 
107 //  movn  %got(d)($gp), %got(c)($gp), $4
108 // This instruction is illegal since movn can take only register operands.
109
110 def MipsWrapperPIC    : SDNode<"MipsISD::WrapperPIC",  SDTIntUnaryOp>;
111
112 // Pointer to dynamically allocated stack area.
113 def MipsDynAlloc  : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
114                            [SDNPHasChain, SDNPInGlue]>;
115
116 def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain]>;
117
118 def MipsExt :  SDNode<"MipsISD::Ext", SDT_Ext>;
119 def MipsIns :  SDNode<"MipsISD::Ins", SDT_Ins>;
120
121 //===----------------------------------------------------------------------===//
122 // Mips Instruction Predicate Definitions.
123 //===----------------------------------------------------------------------===//
124 def HasSEInReg  : Predicate<"Subtarget.hasSEInReg()">;
125 def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
126 def HasSwap     : Predicate<"Subtarget.hasSwap()">;
127 def HasCondMov  : Predicate<"Subtarget.hasCondMov()">;
128 def HasMips32    : Predicate<"Subtarget.hasMips32()">;
129 def HasMips32r2  : Predicate<"Subtarget.hasMips32r2()">;
130 def HasMips64    : Predicate<"Subtarget.hasMips64()">;
131 def NotMips64    : Predicate<"!Subtarget.hasMips64()">;
132 def HasMips64r2  : Predicate<"Subtarget.hasMips64r2()">;
133 def IsN64       : Predicate<"Subtarget.isABI_N64()">;
134 def NotN64      : Predicate<"!Subtarget.isABI_N64()">;
135
136 //===----------------------------------------------------------------------===//
137 // Mips Operand, Complex Patterns and Transformations Definitions.
138 //===----------------------------------------------------------------------===//
139
140 // Instruction operand types
141 def brtarget    : Operand<OtherVT>;
142 def calltarget  : Operand<i32>;
143 def simm16      : Operand<i32>;
144 def simm16_64   : Operand<i64>;
145 def shamt       : Operand<i32>;
146
147 // Unsigned Operand
148 def uimm16      : Operand<i32> {
149   let PrintMethod = "printUnsignedImm";
150 }
151
152 // Address operand
153 def mem : Operand<i32> {
154   let PrintMethod = "printMemOperand";
155   let MIOperandInfo = (ops CPURegs, simm16);
156 }
157
158 def mem64 : Operand<i64> {
159   let PrintMethod = "printMemOperand";
160   let MIOperandInfo = (ops CPU64Regs, simm16_64);
161 }
162
163 def mem_ea : Operand<i32> {
164   let PrintMethod = "printMemOperandEA";
165   let MIOperandInfo = (ops CPURegs, simm16);
166 }
167
168 // Transformation Function - get the lower 16 bits.
169 def LO16 : SDNodeXForm<imm, [{
170   return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
171 }]>;
172
173 // Transformation Function - get the higher 16 bits.
174 def HI16 : SDNodeXForm<imm, [{
175   return getI32Imm((unsigned)N->getZExtValue() >> 16);
176 }]>;
177
178 // Node immediate fits as 16-bit sign extended on target immediate.
179 // e.g. addi, andi
180 def immSExt16  : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
181
182 // Node immediate fits as 16-bit zero extended on target immediate.
183 // The LO16 param means that only the lower 16 bits of the node
184 // immediate are caught.
185 // e.g. addiu, sltiu
186 def immZExt16  : PatLeaf<(imm), [{
187   if (N->getValueType(0) == MVT::i32)
188     return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
189   else
190     return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
191 }], LO16>;
192
193 // shamt field must fit in 5 bits.
194 def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
195
196 // Mips Address Mode! SDNode frameindex could possibily be a match
197 // since load and store instructions from stack used it.
198 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
199
200 //===----------------------------------------------------------------------===//
201 // Pattern fragment for load/store
202 //===----------------------------------------------------------------------===//
203 class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
204   LoadSDNode *LD = cast<LoadSDNode>(N);
205   return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
206 }]>;
207
208 class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
209   LoadSDNode *LD = cast<LoadSDNode>(N);
210   return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
211 }]>;
212
213 class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
214                                              (Node node:$val, node:$ptr), [{
215   StoreSDNode *SD = cast<StoreSDNode>(N);
216   return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
217 }]>;
218
219 class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
220                                            (Node node:$val, node:$ptr), [{
221   StoreSDNode *SD = cast<StoreSDNode>(N);
222   return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
223 }]>;
224
225 // Load/Store PatFrags.
226 def sextloadi16_a   : AlignedLoad<sextloadi16>;
227 def zextloadi16_a   : AlignedLoad<zextloadi16>;
228 def extloadi16_a    : AlignedLoad<extloadi16>;
229 def load_a          : AlignedLoad<load>;
230 def sextloadi32_a   : AlignedLoad<sextloadi32>;
231 def zextloadi32_a   : AlignedLoad<zextloadi32>;
232 def extloadi32_a    : AlignedLoad<extloadi32>;
233 def truncstorei16_a : AlignedStore<truncstorei16>;
234 def store_a         : AlignedStore<store>;
235 def truncstorei32_a : AlignedStore<truncstorei32>;
236 def sextloadi16_u   : UnalignedLoad<sextloadi16>;
237 def zextloadi16_u   : UnalignedLoad<zextloadi16>;
238 def extloadi16_u    : UnalignedLoad<extloadi16>;
239 def load_u          : UnalignedLoad<load>;
240 def sextloadi32_u   : UnalignedLoad<sextloadi32>;
241 def zextloadi32_u   : UnalignedLoad<zextloadi32>;
242 def extloadi32_u    : UnalignedLoad<extloadi32>;
243 def truncstorei16_u : UnalignedStore<truncstorei16>;
244 def store_u         : UnalignedStore<store>;
245 def truncstorei32_u : UnalignedStore<truncstorei32>;
246
247 //===----------------------------------------------------------------------===//
248 // Instructions specific format
249 //===----------------------------------------------------------------------===//
250
251 // Arithmetic and logical instructions with 3 register operands.
252 class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
253                   InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
254   FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
255      !strconcat(instr_asm, "\t$rd, $rs, $rt"),
256      [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
257   let shamt = 0;
258   let isCommutable = isComm;
259 }
260
261 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
262                     InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
263   FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
264      !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
265   let shamt = 0;
266   let isCommutable = isComm;
267 }
268
269 // Arithmetic and logical instructions with 2 register operands.
270 class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
271                   Operand Od, PatLeaf imm_type, RegisterClass RC> :
272   FI<op, (outs RC:$rt), (ins RC:$rs, Od:$i),
273      !strconcat(instr_asm, "\t$rt, $rs, $i"),
274      [(set RC:$rt, (OpNode RC:$rs, imm_type:$i))], IIAlu>;
275
276 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
277                      Operand Od, PatLeaf imm_type, RegisterClass RC> :
278   FI<op, (outs RC:$rt), (ins RC:$rs, Od:$i),
279      !strconcat(instr_asm, "\t$rt, $rs, $i"), [], IIAlu>;
280
281 // Arithmetic Multiply ADD/SUB
282 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
283 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
284   FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
285      !strconcat(instr_asm, "\t$rs, $rt"),
286      [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
287   let rd = 0;
288   let shamt = 0;
289   let isCommutable = isComm;
290 }
291
292 //  Logical
293 class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
294   FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
295      !strconcat(instr_asm, "\t$rd, $rs, $rt"),
296      [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
297   let shamt = 0;
298   let isCommutable = 1;
299 }
300
301 // Shifts
302 class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
303                        SDNode OpNode, PatFrag PF, Operand ImmOpnd,
304                        RegisterClass RC>:
305   FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
306      !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
307      [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
308   let rs = isRotate;
309 }
310
311 // 32-bit shift instructions.
312 class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
313                          SDNode OpNode>:
314   shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
315
316 class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
317                        SDNode OpNode, RegisterClass RC>:
318   FR<0x00, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
319      !strconcat(instr_asm, "\t$rd, $rt, $rs"),
320      [(set RC:$rd, (OpNode RC:$rt, RC:$rs))], IIAlu> {
321   let shamt = isRotate;
322 }
323
324 // Load Upper Imediate
325 class LoadUpper<bits<6> op, string instr_asm>:
326   FI<op, (outs CPURegs:$rt), (ins uimm16:$imm),
327      !strconcat(instr_asm, "\t$rt, $imm"), [], IIAlu> {
328   let rs = 0;
329 }
330
331 // Memory Load/Store
332 let canFoldAsLoad = 1 in
333 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
334             Operand MemOpnd, bit Pseudo>:
335   FI<op, (outs RC:$rt), (ins MemOpnd:$addr),
336      !strconcat(instr_asm, "\t$rt, $addr"),
337      [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
338   let isPseudo = Pseudo;
339 }
340
341 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
342              Operand MemOpnd, bit Pseudo>:
343   FI<op, (outs), (ins RC:$rt, MemOpnd:$addr),
344      !strconcat(instr_asm, "\t$rt, $addr"),
345      [(OpNode RC:$rt, addr:$addr)], IIStore> {
346   let isPseudo = Pseudo;
347 }
348
349 // 32-bit load.
350 multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
351                    bit Pseudo = 0> {
352   def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
353                Requires<[NotN64]>;
354   def _P8    : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
355                Requires<[IsN64]>;
356
357
358 // 64-bit load.
359 multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
360                    bit Pseudo = 0> {
361   def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
362                Requires<[NotN64]>;
363   def _P8    : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
364                Requires<[IsN64]>;
365
366
367 // 32-bit store.
368 multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
369                     bit Pseudo = 0> {
370   def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
371                Requires<[NotN64]>;
372   def _P8    : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
373                Requires<[IsN64]>;
374 }
375
376 // 64-bit store.
377 multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
378                     bit Pseudo = 0> {
379   def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
380                Requires<[NotN64]>;
381   def _P8    : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
382                Requires<[IsN64]>;
383 }
384
385 // Conditional Branch
386 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
387   CBranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$offset),
388               !strconcat(instr_asm, "\t$rs, $rt, $offset"),
389               [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$offset)], IIBranch> {
390   let isBranch = 1;
391   let isTerminator = 1;
392   let hasDelaySlot = 1;
393 }
394
395 class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
396                   RegisterClass RC>:
397   CBranchBase<op, (outs), (ins RC:$rs, brtarget:$offset),
398               !strconcat(instr_asm, "\t$rs, $offset"),
399               [(brcond (i32 (cond_op RC:$rs, 0)), bb:$offset)], IIBranch> {
400   let rt = _rt;
401   let isBranch = 1;
402   let isTerminator = 1;
403   let hasDelaySlot = 1;
404 }
405
406 // SetCC
407 class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
408               RegisterClass RC>:
409   FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
410      !strconcat(instr_asm, "\t$rd, $rs, $rt"),
411      [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
412      IIAlu> {
413   let shamt = 0;
414 }
415
416 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
417               PatLeaf imm_type, RegisterClass RC>:
418   FI<op, (outs CPURegs:$rd), (ins RC:$rs, Od:$i),
419      !strconcat(instr_asm, "\t$rd, $rs, $i"),
420      [(set CPURegs:$rd, (cond_op RC:$rs, imm_type:$i))],
421      IIAlu>;
422
423 // Unconditional branch
424 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
425 class JumpFJ<bits<6> op, string instr_asm>:
426   FJ<op, (outs), (ins brtarget:$target),
427      !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
428
429 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
430 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
431   FR<op, func, (outs), (ins CPURegs:$rs),
432      !strconcat(instr_asm, "\t$rs"), [(brind CPURegs:$rs)], IIBranch> {
433   let rt = 0;
434   let rd = 0;
435   let shamt = 0;
436 }
437
438 // Jump and Link (Call)
439 let isCall=1, hasDelaySlot=1,
440   // All calls clobber the non-callee saved registers...
441   Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
442           K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
443   class JumpLink<bits<6> op, string instr_asm>:
444     FJ<op, (outs), (ins calltarget:$target, variable_ops),
445        !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
446        IIBranch>;
447
448   class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
449     FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
450        !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
451     let rt = 0;
452     let rd = 31;
453     let shamt = 0;
454   }
455
456   class BranchLink<string instr_asm>:
457     FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
458        !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch> {
459     let rt = 0;
460   }
461 }
462
463 // Mul, Div
464 class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
465            RegisterClass RC, list<Register> DefRegs>:
466   FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
467      !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
468   let rd = 0;
469   let shamt = 0;
470   let isCommutable = 1;
471   let Defs = DefRegs;
472 }
473
474 class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
475   Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
476
477 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
478           RegisterClass RC, list<Register> DefRegs>:
479   FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
480      !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
481      [(op RC:$rs, RC:$rt)], itin> {
482   let rd = 0;
483   let shamt = 0;
484   let Defs = DefRegs;
485 }
486
487 class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
488   Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
489
490 // Move from Hi/Lo
491 class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
492                    list<Register> UseRegs>:
493   FR<0x00, func, (outs RC:$rd), (ins),
494      !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
495   let rs = 0;
496   let rt = 0;
497   let shamt = 0;
498   let Uses = UseRegs;
499 }
500
501 class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
502                  list<Register> DefRegs>:
503   FR<0x00, func, (outs), (ins RC:$rs),
504      !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
505   let rt = 0;
506   let rd = 0;
507   let shamt = 0;
508   let Defs = DefRegs;
509 }
510
511 class EffectiveAddress<string instr_asm> :
512   FI<0x09, (outs CPURegs:$rt), (ins mem_ea:$addr),
513      instr_asm, [(set CPURegs:$rt, addr:$addr)], IIAlu>;
514
515 // Count Leading Ones/Zeros in Word
516 class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
517   FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
518      !strconcat(instr_asm, "\t$rd, $rs"),
519      [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
520      Requires<[HasBitCount]> {
521   let shamt = 0;
522   let rt = rd;
523 }
524
525 class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
526   FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
527      !strconcat(instr_asm, "\t$rd, $rs"),
528      [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
529      Requires<[HasBitCount]> {
530   let shamt = 0;
531   let rt = rd;
532 }
533
534 // Sign Extend in Register.
535 class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
536   FR<0x3f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
537      !strconcat(instr_asm, "\t$rd, $rt"),
538      [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
539   let rs = 0;
540   let shamt = sa;
541   let Predicates = [HasSEInReg];
542 }
543
544 // Byte Swap
545 class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
546   FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
547      !strconcat(instr_asm, "\t$rd, $rt"),
548      [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
549   let rs = 0;
550   let shamt = sa;
551   let Predicates = [HasSwap];
552 }
553
554 // Read Hardware
555 class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$rt), (ins HWRegs:$rd),
556     "rdhwr\t$rt, $rd", [], IIAlu> {
557   let rs = 0;
558   let shamt = 0;
559 }
560
561 // Ext and Ins
562 class ExtIns<bits<6> _funct, string instr_asm, dag outs, dag ins,
563              list<dag> pattern, InstrItinClass itin>:
564   FR<0x1f, _funct, outs, ins, !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
565      pattern, itin>, Requires<[HasMips32r2]> {
566   bits<5> pos;
567   bits<5> sz;
568   let rd = sz;
569   let shamt = pos;
570 }
571
572 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
573 class Atomic2Ops<PatFrag Op, string Opstr> :
574   MipsPseudo<(outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
575              !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
576              [(set CPURegs:$dst,
577               (Op CPURegs:$ptr, CPURegs:$incr))]>;
578
579 // Atomic Compare & Swap.
580 class AtomicCmpSwap<PatFrag Op, string Width> :
581   MipsPseudo<(outs CPURegs:$dst), 
582              (ins CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap),
583              !strconcat("atomic_cmp_swap_", Width, 
584                         "\t$dst, $ptr, $cmp, $swap"),
585              [(set CPURegs:$dst,
586               (Op CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap))]>;
587
588 //===----------------------------------------------------------------------===//
589 // Pseudo instructions
590 //===----------------------------------------------------------------------===//
591
592 // As stack alignment is always done with addiu, we need a 16-bit immediate
593 let Defs = [SP], Uses = [SP] in {
594 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
595                                   "!ADJCALLSTACKDOWN $amt",
596                                   [(callseq_start timm:$amt)]>;
597 def ADJCALLSTACKUP   : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
598                                   "!ADJCALLSTACKUP $amt1",
599                                   [(callseq_end timm:$amt1, timm:$amt2)]>;
600 }
601
602 // Some assembly macros need to avoid pseudoinstructions and assembler
603 // automatic reodering, we should reorder ourselves.
604 def MACRO     : MipsPseudo<(outs), (ins), ".set\tmacro",     []>;
605 def REORDER   : MipsPseudo<(outs), (ins), ".set\treorder",   []>;
606 def NOMACRO   : MipsPseudo<(outs), (ins), ".set\tnomacro",   []>;
607 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
608
609 // These macros are inserted to prevent GAS from complaining
610 // when using the AT register.
611 def NOAT      : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
612 def ATMACRO   : MipsPseudo<(outs), (ins), ".set\tat", []>;
613
614 // When handling PIC code the assembler needs .cpload and .cprestore
615 // directives. If the real instructions corresponding these directives
616 // are used, we have the same behavior, but get also a bunch of warnings
617 // from the assembler.
618 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
619 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
620
621 let usesCustomInserter = 1 in {
622   def ATOMIC_LOAD_ADD_I8   : Atomic2Ops<atomic_load_add_8, "load_add_8">;
623   def ATOMIC_LOAD_ADD_I16  : Atomic2Ops<atomic_load_add_16, "load_add_16">;
624   def ATOMIC_LOAD_ADD_I32  : Atomic2Ops<atomic_load_add_32, "load_add_32">;
625   def ATOMIC_LOAD_SUB_I8   : Atomic2Ops<atomic_load_sub_8, "load_sub_8">;
626   def ATOMIC_LOAD_SUB_I16  : Atomic2Ops<atomic_load_sub_16, "load_sub_16">;
627   def ATOMIC_LOAD_SUB_I32  : Atomic2Ops<atomic_load_sub_32, "load_sub_32">;
628   def ATOMIC_LOAD_AND_I8   : Atomic2Ops<atomic_load_and_8, "load_and_8">;
629   def ATOMIC_LOAD_AND_I16  : Atomic2Ops<atomic_load_and_16, "load_and_16">;
630   def ATOMIC_LOAD_AND_I32  : Atomic2Ops<atomic_load_and_32, "load_and_32">;
631   def ATOMIC_LOAD_OR_I8    : Atomic2Ops<atomic_load_or_8, "load_or_8">;
632   def ATOMIC_LOAD_OR_I16   : Atomic2Ops<atomic_load_or_16, "load_or_16">;
633   def ATOMIC_LOAD_OR_I32   : Atomic2Ops<atomic_load_or_32, "load_or_32">;
634   def ATOMIC_LOAD_XOR_I8   : Atomic2Ops<atomic_load_xor_8, "load_xor_8">;
635   def ATOMIC_LOAD_XOR_I16  : Atomic2Ops<atomic_load_xor_16, "load_xor_16">;
636   def ATOMIC_LOAD_XOR_I32  : Atomic2Ops<atomic_load_xor_32, "load_xor_32">;
637   def ATOMIC_LOAD_NAND_I8  : Atomic2Ops<atomic_load_nand_8, "load_nand_8">;
638   def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, "load_nand_16">;
639   def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, "load_nand_32">;
640
641   def ATOMIC_SWAP_I8       : Atomic2Ops<atomic_swap_8, "swap_8">;
642   def ATOMIC_SWAP_I16      : Atomic2Ops<atomic_swap_16, "swap_16">;
643   def ATOMIC_SWAP_I32      : Atomic2Ops<atomic_swap_32, "swap_32">;
644
645   def ATOMIC_CMP_SWAP_I8   : AtomicCmpSwap<atomic_cmp_swap_8, "8">;
646   def ATOMIC_CMP_SWAP_I16  : AtomicCmpSwap<atomic_cmp_swap_16, "16">;
647   def ATOMIC_CMP_SWAP_I32  : AtomicCmpSwap<atomic_cmp_swap_32, "32">;
648 }
649
650 //===----------------------------------------------------------------------===//
651 // Instruction definition
652 //===----------------------------------------------------------------------===//
653
654 //===----------------------------------------------------------------------===//
655 // MipsI Instructions
656 //===----------------------------------------------------------------------===//
657
658 /// Arithmetic Instructions (ALU Immediate)
659 def ADDiu   : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
660 def ADDi    : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
661 def SLTi    : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
662 def SLTiu   : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
663 def ANDi    : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
664 def ORi     : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
665 def XORi    : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
666 def LUi     : LoadUpper<0x0f, "lui">;
667
668 /// Arithmetic Instructions (3-Operand, R-Type)
669 def ADDu    : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
670 def SUBu    : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
671 def ADD     : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
672 def SUB     : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
673 def SLT     : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
674 def SLTu    : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
675 def AND     : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
676 def OR      : ArithLogicR<0x00, 0x25, "or",  or, IIAlu, CPURegs, 1>;
677 def XOR     : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
678 def NOR     : LogicNOR<0x00, 0x27, "nor", CPURegs>;
679
680 /// Shift Instructions
681 def SLL     : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
682 def SRL     : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
683 def SRA     : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
684 def SLLV    : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
685 def SRLV    : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
686 def SRAV    : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
687
688 // Rotate Instructions
689 let Predicates = [HasMips32r2] in {
690     def ROTR    : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
691     def ROTRV   : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
692 }
693
694 /// Load and Store Instructions
695 ///  aligned
696 defm LB      : LoadM32<0x20, "lb",  sextloadi8>;
697 defm LBu     : LoadM32<0x24, "lbu", zextloadi8>;
698 defm LH      : LoadM32<0x21, "lh",  sextloadi16_a>;
699 defm LHu     : LoadM32<0x25, "lhu", zextloadi16_a>;
700 defm LW      : LoadM32<0x23, "lw",  load_a>;
701 defm SB      : StoreM32<0x28, "sb", truncstorei8>;
702 defm SH      : StoreM32<0x29, "sh", truncstorei16_a>;
703 defm SW      : StoreM32<0x2b, "sw", store_a>;
704
705 ///  unaligned
706 defm ULH     : LoadM32<0x21, "ulh",  sextloadi16_u, 1>;
707 defm ULHu    : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
708 defm ULW     : LoadM32<0x23, "ulw",  load_u, 1>;
709 defm USH     : StoreM32<0x29, "ush", truncstorei16_u, 1>;
710 defm USW     : StoreM32<0x2b, "usw", store_u, 1>;
711
712 let hasSideEffects = 1 in
713 def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
714                     [(MipsSync imm:$stype)], NoItinerary>
715 {
716   let opcode = 0;
717   let Inst{25-11} = 0;
718   let Inst{5-0} = 15;
719 }
720
721 /// Load-linked, Store-conditional
722 let mayLoad = 1 in
723   def LL    : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
724               "ll\t$dst, $addr", [], IILoad>;
725 let mayStore = 1, Constraints = "$src = $dst" in
726   def SC    : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
727               "sc\t$src, $addr", [], IIStore>;
728
729 /// Jump and Branch Instructions
730 def J       : JumpFJ<0x02, "j">;
731 let isIndirectBranch = 1 in
732   def JR      : JumpFR<0x00, 0x08, "jr">;
733 def JAL     : JumpLink<0x03, "jal">;
734 def JALR    : JumpLinkReg<0x00, 0x09, "jalr">;
735 def BEQ     : CBranch<0x04, "beq", seteq, CPURegs>;
736 def BNE     : CBranch<0x05, "bne", setne, CPURegs>;
737 def BGEZ    : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
738 def BGTZ    : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
739 def BLEZ    : CBranchZero<0x07, 0, "blez", setle, CPURegs>;
740 def BLTZ    : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
741
742 def BGEZAL  : BranchLink<"bgezal">;
743 def BLTZAL  : BranchLink<"bltzal">;
744
745 let isReturn=1, isTerminator=1, hasDelaySlot=1,
746     isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
747   def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
748                 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
749
750 /// Multiply and Divide Instructions.
751 def MULT    : Mult32<0x18, "mult", IIImul>;
752 def MULTu   : Mult32<0x19, "multu", IIImul>;
753 def SDIV    : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
754 def UDIV    : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
755
756 def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
757 def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
758 def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
759 def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
760
761 /// Sign Ext In Register Instructions.
762 def SEB : SignExtInReg<0x10, "seb", i8>;
763 def SEH : SignExtInReg<0x18, "seh", i16>;
764
765 /// Count Leading
766 def CLZ : CountLeading0<0x20, "clz", CPURegs>;
767 def CLO : CountLeading1<0x21, "clo", CPURegs>;
768
769 /// Byte Swap
770 def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
771
772 /// No operation
773 let addr=0 in
774   def NOP   : FJ<0, (outs), (ins), "nop", [], IIAlu>;
775
776 // FrameIndexes are legalized when they are operands from load/store
777 // instructions. The same not happens for stack address copies, so an
778 // add op with mem ComplexPattern is used and the stack address copy
779 // can be matched. It's similar to Sparc LEA_ADDRi
780 def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr">;
781
782 // DynAlloc node points to dynamically allocated stack space.
783 // $sp is added to the list of implicitly used registers to prevent dead code
784 // elimination from removing instructions that modify $sp.
785 let Uses = [SP] in
786 def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr">;
787
788 // MADD*/MSUB*
789 def MADD  : MArithR<0, "madd", MipsMAdd, 1>;
790 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
791 def MSUB  : MArithR<4, "msub", MipsMSub>;
792 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
793
794 // MUL is a assembly macro in the current used ISAs. In recent ISA's
795 // it is a real instruction.
796 def MUL   : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
797             Requires<[HasMips32]>;
798
799 def RDHWR : ReadHardware;
800
801 def EXT : ExtIns<0, "ext", (outs CPURegs:$rt),
802                  (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz),
803                  [(set CPURegs:$rt,
804                    (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$sz))],
805                  NoItinerary>;
806
807 let Constraints = "$src = $rt" in
808 def INS : ExtIns<4, "ins", (outs CPURegs:$rt),
809                  (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz, CPURegs:$src),
810                  [(set CPURegs:$rt,
811                    (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$sz,
812                     CPURegs:$src))],
813                  NoItinerary>;
814
815 //===----------------------------------------------------------------------===//
816 //  Arbitrary patterns that map to one or more instructions
817 //===----------------------------------------------------------------------===//
818
819 // Small immediates
820 def : Pat<(i32 immSExt16:$in),
821           (ADDiu ZERO, imm:$in)>;
822 def : Pat<(i32 immZExt16:$in),
823           (ORi ZERO, imm:$in)>;
824
825 // Arbitrary immediates
826 def : Pat<(i32 imm:$imm),
827           (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
828
829 // Carry patterns
830 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
831           (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
832 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
833           (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
834 def : Pat<(addc  CPURegs:$src, immSExt16:$imm),
835           (ADDiu CPURegs:$src, imm:$imm)>;
836
837 // Call
838 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
839           (JAL tglobaladdr:$dst)>;
840 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
841           (JAL texternalsym:$dst)>;
842 //def : Pat<(MipsJmpLink CPURegs:$dst),
843 //          (JALR CPURegs:$dst)>;
844
845 // hi/lo relocs
846 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
847 def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
848 def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
849 def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
850 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
851           (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
852 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
853           (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
854
855 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
856 def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
857 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
858           (ADDiu CPURegs:$hi, tjumptable:$lo)>;
859
860 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
861 def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
862 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
863           (ADDiu CPURegs:$hi, tconstpool:$lo)>;
864
865 // gp_rel relocs
866 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
867           (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
868 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
869           (ADDiu CPURegs:$gp, tconstpool:$in)>;
870
871 // tlsgd
872 def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
873           (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
874
875 // tprel hi/lo
876 def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
877 def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
878 def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
879           (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
880
881 // wrapper_pic
882 class WrapperPICPat<SDNode node>:
883       Pat<(MipsWrapperPIC node:$in),
884           (ADDiu GP, node:$in)>;
885
886 def : WrapperPICPat<tglobaladdr>;
887 def : WrapperPICPat<tconstpool>;
888 def : WrapperPICPat<texternalsym>;
889 def : WrapperPICPat<tblockaddress>;
890 def : WrapperPICPat<tjumptable>;
891
892 // Mips does not have "not", so we expand our way
893 def : Pat<(not CPURegs:$in),
894           (NOR CPURegs:$in, ZERO)>;
895
896 // extended load and stores
897 def : Pat<(extloadi1  addr:$src), (LBu addr:$src)>;
898 def : Pat<(extloadi8  addr:$src), (LBu addr:$src)>;
899 def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
900 def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
901
902 // peepholes
903 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
904
905 // brcond patterns
906 multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
907                       Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
908                       Instruction SLTiuOp, Register ZEROReg> {
909 def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
910           (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
911 def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
912           (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
913
914 def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
915           (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
916 def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
917           (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
918 def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
919           (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
920 def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
921           (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
922
923 def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
924           (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
925 def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
926           (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
927
928 def : Pat<(brcond RC:$cond, bb:$dst),
929           (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
930 }
931
932 defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
933
934 // setcc patterns
935 multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
936                      Instruction SLTuOp, Register ZEROReg> {
937   def : Pat<(seteq RC:$lhs, RC:$rhs),
938             (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
939   def : Pat<(setne RC:$lhs, RC:$rhs),
940             (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
941 }
942
943 multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
944   def : Pat<(setle RC:$lhs, RC:$rhs),
945             (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
946   def : Pat<(setule RC:$lhs, RC:$rhs),
947             (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
948 }
949
950 multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
951   def : Pat<(setgt RC:$lhs, RC:$rhs),
952             (SLTOp RC:$rhs, RC:$lhs)>;
953   def : Pat<(setugt RC:$lhs, RC:$rhs),
954             (SLTuOp RC:$rhs, RC:$lhs)>;
955 }
956
957 multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
958   def : Pat<(setge RC:$lhs, RC:$rhs),
959             (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
960   def : Pat<(setuge RC:$lhs, RC:$rhs),
961             (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
962 }
963
964 multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
965                         Instruction SLTiuOp> {
966   def : Pat<(setge RC:$lhs, immSExt16:$rhs),
967             (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
968   def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
969             (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
970 }
971
972 defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
973 defm : SetlePats<CPURegs, SLT, SLTu>;
974 defm : SetgtPats<CPURegs, SLT, SLTu>;
975 defm : SetgePats<CPURegs, SLT, SLTu>;
976 defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
977
978 // select MipsDynAlloc
979 def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
980
981 //===----------------------------------------------------------------------===//
982 // Floating Point Support
983 //===----------------------------------------------------------------------===//
984
985 include "MipsInstrFPU.td"
986 include "Mips64InstrInfo.td"
987 include "MipsCondMov.td"
988