Added Subtarget support into RegisterInfo
[oota-llvm.git] / lib / Target / Mips / MipsInstrInfo.td
1 //===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
11 // Instruction format superclass
12 //===----------------------------------------------------------------------===//
13
14 include "MipsInstrFormats.td"
15
16 //===----------------------------------------------------------------------===//
17 // Mips profiles and nodes
18 //===----------------------------------------------------------------------===//
19
20 def SDT_MipsRet          : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
21 def SDT_MipsJmpLink      : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
22 def SDT_MipsSelectCC     : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, 
23                                          SDTCisSameAs<1, 2>, SDTCisInt<3>]>;
24 def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
25 def SDT_MipsCallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
26
27 // Call
28 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, [SDNPHasChain,
29                          SDNPOutFlag]>;
30
31 // Hi and Lo nodes are used to handle global addresses. Used on 
32 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol 
33 // static model. (nothing to do with Mips Registers Hi and Lo)
34 //def MipsHi  : SDNode<"MipsISD::Hi", SDTIntUnaryOp, [SDNPOutFlag]>;
35 def MipsHi  : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
36 def MipsLo  : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
37
38 // Return
39 def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain, 
40                      SDNPOptInFlag]>;
41
42 // These are target-independent nodes, but have target-specific formats.
43 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
44                            [SDNPHasChain, SDNPOutFlag]>;
45 def callseq_end   : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
46                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
47
48 // Select Condition Code
49 def MipsSelectCC  : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
50
51 //===----------------------------------------------------------------------===//
52 // Mips Instruction Predicate Definitions.
53 //===----------------------------------------------------------------------===//
54 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
55
56 //===----------------------------------------------------------------------===//
57 // Mips Operand, Complex Patterns and Transformations Definitions.
58 //===----------------------------------------------------------------------===//
59
60 // Instruction operand types
61 def brtarget    : Operand<OtherVT>;
62 def calltarget  : Operand<i32>;
63 def uimm16      : Operand<i32>;
64 def simm16      : Operand<i32>;
65 def shamt       : Operand<i32>;
66
67 // Address operand
68 def mem : Operand<i32> {
69   let PrintMethod = "printMemOperand";
70   let MIOperandInfo = (ops simm16, CPURegs);
71 }
72
73 // Transformation Function - get the lower 16 bits.
74 def LO16 : SDNodeXForm<imm, [{
75   return getI32Imm((unsigned)N->getValue() & 0xFFFF);
76 }]>;
77
78 // Transformation Function - get the higher 16 bits.
79 def HI16 : SDNodeXForm<imm, [{
80   return getI32Imm((unsigned)N->getValue() >> 16);
81 }]>;
82
83 // Node immediate fits as 16-bit sign extended on target immediate.
84 // e.g. addi, andi
85 def immSExt16  : PatLeaf<(imm), [{
86   if (N->getValueType(0) == MVT::i32)
87     return (int32_t)N->getValue() == (short)N->getValue();
88   else
89     return (int64_t)N->getValue() == (short)N->getValue();
90 }]>;
91
92 // Node immediate fits as 16-bit zero extended on target immediate.
93 // The LO16 param means that only the lower 16 bits of the node
94 // immediate are caught.
95 // e.g. addiu, sltiu
96 def immZExt16  : PatLeaf<(imm), [{
97   if (N->getValueType(0) == MVT::i32)
98     return (uint32_t)N->getValue() == (unsigned short)N->getValue();
99   else
100     return (uint64_t)N->getValue() == (unsigned short)N->getValue();
101 }], LO16>;
102
103 // Node immediate fits as 32-bit zero extended on target immediate.
104 //def immZExt32  : PatLeaf<(imm), [{
105 //  return (uint64_t)N->getValue() == (uint32_t)N->getValue();
106 //}], LO16>;
107
108 // shamt field must fit in 5 bits.
109 def immZExt5 : PatLeaf<(imm), [{
110   return N->getValue() == ((N->getValue()) & 0x1f) ;
111 }]>;
112
113 // Mips Address Mode! SDNode frameindex could possibily be a match
114 // since load and store instructions from stack used it.
115 def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>;
116
117 //===----------------------------------------------------------------------===//
118 // Instructions specific format
119 //===----------------------------------------------------------------------===//
120
121 // Arithmetic 3 register operands
122 let isCommutable = 1 in
123 class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
124              InstrItinClass itin>:
125   FR< op,
126       func,
127       (outs CPURegs:$dst),
128       (ins CPURegs:$b, CPURegs:$c),
129       !strconcat(instr_asm, "\t$dst, $b, $c"),
130       [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
131
132 let isCommutable = 1 in
133 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
134   FR< op,
135       func,
136       (outs CPURegs:$dst),
137       (ins CPURegs:$b, CPURegs:$c),
138       !strconcat(instr_asm, "\t$dst, $b, $c"),
139       [], IIAlu>;
140
141 // Arithmetic 2 register operands
142 class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
143              Operand Od, PatLeaf imm_type> :
144   FI< op,
145       (outs CPURegs:$dst),
146       (ins CPURegs:$b, Od:$c),
147       !strconcat(instr_asm, "\t$dst, $b, $c"),
148       [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
149
150 // Arithmetic Multiply ADD/SUB
151 let rd=0 in
152 class MArithR<bits<6> func, string instr_asm> :
153   FR< 0x1c,
154       func,
155       (outs CPURegs:$rs),
156       (ins CPURegs:$rt),
157       !strconcat(instr_asm, "\t$rs, $rt"),
158       [], IIImul>;
159
160 //  Logical
161 class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
162   FR< 0x00,
163       func,
164       (outs CPURegs:$dst),
165       (ins CPURegs:$b, CPURegs:$c),
166       !strconcat(instr_asm, "\t$dst, $b, $c"),
167       [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
168
169 class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
170   FI< op,
171       (outs CPURegs:$dst),
172       (ins CPURegs:$b, uimm16:$c),
173       !strconcat(instr_asm, "\t$dst, $b, $c"),
174       [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
175
176 class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
177   FR< op,
178       func,
179       (outs CPURegs:$dst),
180       (ins CPURegs:$b, CPURegs:$c),
181       !strconcat(instr_asm, "\t$dst, $b, $c"),
182       [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
183
184 // Shifts
185 let rt = 0 in
186 class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
187   FR< 0x00,
188       func,
189       (outs CPURegs:$dst),
190       (ins CPURegs:$b, shamt:$c),
191       !strconcat(instr_asm, "\t$dst, $b, $c"),
192       [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
193
194 class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
195   FR< 0x00,
196       func,
197       (outs CPURegs:$dst),
198       (ins CPURegs:$b, CPURegs:$c),
199       !strconcat(instr_asm, "\t$dst, $b, $c"),
200       [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
201
202 // Load Upper Imediate
203 class LoadUpper<bits<6> op, string instr_asm>:
204   FI< op,
205       (outs CPURegs:$dst),
206       (ins uimm16:$imm),
207       !strconcat(instr_asm, "\t$dst, $imm"),
208       [], IIAlu>;
209
210 // Memory Load/Store
211 let isSimpleLoad = 1, hasDelaySlot = 1 in
212 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
213   FI< op,
214       (outs CPURegs:$dst),
215       (ins mem:$addr),
216       !strconcat(instr_asm, "\t$dst, $addr"),
217       [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
218
219 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
220   FI< op,
221       (outs),
222       (ins CPURegs:$dst, mem:$addr),
223       !strconcat(instr_asm, "\t$dst, $addr"),
224       [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
225
226 // Conditional Branch
227 let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
228 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
229   FI< op,
230       (outs),
231       (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
232       !strconcat(instr_asm, "\t$a, $b, $offset"),
233       [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
234       IIBranch>;
235
236
237 class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
238   FI< op,
239       (outs),
240       (ins CPURegs:$src, brtarget:$offset),
241       !strconcat(instr_asm, "\t$src, $offset"),
242       [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
243       IIBranch>;
244 }
245
246 // SetCC
247 class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
248       PatFrag cond_op>:
249   FR< op,
250       func,
251       (outs CPURegs:$dst),
252       (ins CPURegs:$b, CPURegs:$c),
253       !strconcat(instr_asm, "\t$dst, $b, $c"),
254       [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
255       IIAlu>;
256
257 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
258       Operand Od, PatLeaf imm_type>:
259   FI< op,
260       (outs CPURegs:$dst),
261       (ins CPURegs:$b, Od:$c),
262       !strconcat(instr_asm, "\t$dst, $b, $c"),
263       [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
264       IIAlu>;
265
266 // Unconditional branch
267 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
268 class JumpFJ<bits<6> op, string instr_asm>:
269   FJ< op,
270       (outs),
271       (ins brtarget:$target),
272       !strconcat(instr_asm, "\t$target"),
273       [(br bb:$target)], IIBranch>;
274
275 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
276 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
277   FR< op,
278       func,
279       (outs),
280       (ins CPURegs:$target),
281       !strconcat(instr_asm, "\t$target"),
282       [(brind CPURegs:$target)], IIBranch>;
283
284 // Jump and Link (Call)
285 let isCall=1, hasDelaySlot=1,
286   // All calls clobber the non-callee saved registers...
287   Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2,
288           T3, T4, T5, T6, T7, T8, T9, K0, K1], Uses = [GP] in {
289   class JumpLink<bits<6> op, string instr_asm>:
290     FJ< op,
291         (outs),
292         (ins calltarget:$target),
293         !strconcat(instr_asm, "\t$target"),
294         [(MipsJmpLink imm:$target)], IIBranch>;
295
296   let rd=31 in
297   class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
298     FR< op,
299         func,
300         (outs),
301         (ins CPURegs:$rs),
302         !strconcat(instr_asm, "\t$rs"),
303         [(MipsJmpLink CPURegs:$rs)], IIBranch>;
304
305   class BranchLink<string instr_asm>:
306     FI< 0x1,
307         (outs),
308         (ins CPURegs:$rs, brtarget:$target),
309         !strconcat(instr_asm, "\t$rs, $target"),
310         [], IIBranch>;
311 }
312
313 // Mul, Div
314 class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
315   FR< 0x00,
316       func,
317       (outs),
318       (ins CPURegs:$a, CPURegs:$b),
319       !strconcat(instr_asm, "\t$a, $b"),
320       [], itin>;
321
322 // Move from Hi/Lo
323 class MoveFromTo<bits<6> func, string instr_asm>:
324   FR< 0x00,
325       func,
326       (outs CPURegs:$dst),
327       (ins),
328       !strconcat(instr_asm, "\t$dst"),
329       [], IIHiLo>;
330
331 // Count Leading Ones/Zeros in Word
332 class CountLeading<bits<6> func, string instr_asm>:
333   FR< 0x1c,
334       func,
335       (outs CPURegs:$dst),
336       (ins CPURegs:$src),
337       !strconcat(instr_asm, "\t$dst, $src"),
338       [], IIAlu>;
339
340 class EffectiveAddress<string instr_asm> :
341   FI<0x09,
342      (outs CPURegs:$dst),
343      (ins mem:$addr),
344      instr_asm,
345      [(set CPURegs:$dst, addr:$addr)], IIAlu>;
346
347 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
348   FR< 0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
349       !strconcat(instr_asm, "\t$dst, $src"),
350       [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
351
352
353 //===----------------------------------------------------------------------===//
354 // Pseudo instructions
355 //===----------------------------------------------------------------------===//
356
357 // As stack alignment is always done with addiu, we need a 16-bit immediate
358 let Defs = [SP], Uses = [SP] in {
359 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
360                                   "!ADJCALLSTACKDOWN $amt",
361                                   [(callseq_start imm:$amt)]>;
362 def ADJCALLSTACKUP   : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
363                                   "!ADJCALLSTACKUP $amt1",
364                                   [(callseq_end imm:$amt1, imm:$amt2)]>;
365 }
366
367 // Some assembly macros need to avoid pseudoinstructions and assembler
368 // automatic reodering, we should reorder ourselves.
369 def MACRO     : MipsPseudo<(outs), (ins), ".set\tmacro",     []>;
370 def REORDER   : MipsPseudo<(outs), (ins), ".set\treorder",   []>;
371 def NOMACRO   : MipsPseudo<(outs), (ins), ".set\tnomacro",   []>;
372 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
373
374 // When handling PIC code the assembler needs .cpload and .cprestore
375 // directives. If the real instructions corresponding these directives
376 // are used, we have the same behavior, but get also a bunch of warnings
377 // from the assembler.
378 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
379 def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
380
381 // The supported Mips ISAs dont have any instruction close to the SELECT_CC 
382 // operation. The solution is to create a Mips pseudo SELECT_CC instruction
383 // (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally 
384 // replace it for real supported nodes into EmitInstrWithCustomInserter
385 let usesCustomDAGSchedInserter = 1 in {
386   def Select_CC : MipsPseudo<(outs CPURegs:$dst), 
387     (ins CPURegs:$CmpRes, CPURegs:$T, CPURegs:$F), "# MipsSelect_CC", 
388     [(set CPURegs:$dst, (MipsSelectCC CPURegs:$CmpRes, 
389                                       CPURegs:$T, CPURegs:$F))]>;
390 }
391
392 //===----------------------------------------------------------------------===//
393 // Instruction definition
394 //===----------------------------------------------------------------------===//
395
396 //===----------------------------------------------------------------------===//
397 // MipsI Instructions
398 //===----------------------------------------------------------------------===//
399
400 // Arithmetic
401
402 // ADDiu just accept 16-bit immediates but we handle this on Pat's.
403 // immZExt32 is used here so it can match GlobalAddress immediates.
404 // MUL is a assembly macro in the current used ISAs.
405 def ADDiu   : ArithI<0x09, "addiu", add, uimm16, immZExt16>;
406 def ADDi    : ArithI<0x08, "addi",  add, simm16, immSExt16>;
407 //def MUL     : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
408 def ADDu    : ArithR<0x00, 0x21, "addu", add, IIAlu>;
409 def SUBu    : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
410 def ADD     : ArithOverflowR<0x00, 0x20, "add">;
411 def SUB     : ArithOverflowR<0x00, 0x22, "sub">;
412
413 // Logical
414 def AND     : LogicR<0x24, "and", and>;
415 def OR      : LogicR<0x25, "or",  or>;
416 def XOR     : LogicR<0x26, "xor", xor>;
417 def ANDi    : LogicI<0x0c, "andi", and>;
418 def ORi     : LogicI<0x0d, "ori",  or>;
419 def XORi    : LogicI<0x0e, "xori",  xor>;
420 def NOR     : LogicNOR<0x00, 0x27, "nor">;
421
422 // Shifts
423 def SLL     : LogicR_shift_imm<0x00, "sll", shl>;
424 def SRL     : LogicR_shift_imm<0x02, "srl", srl>;
425 def SRA     : LogicR_shift_imm<0x03, "sra", sra>;
426 def SLLV    : LogicR_shift_reg<0x04, "sllv", shl>;
427 def SRLV    : LogicR_shift_reg<0x06, "srlv", srl>;
428 def SRAV    : LogicR_shift_reg<0x07, "srav", sra>;
429
430 // Load Upper Immediate
431 def LUi     : LoadUpper<0x0f, "lui">;
432
433 // Load/Store
434 def LB      : LoadM<0x20, "lb",  sextloadi8>;
435 def LBu     : LoadM<0x24, "lbu", zextloadi8>;
436 def LH      : LoadM<0x21, "lh",  sextloadi16>;
437 def LHu     : LoadM<0x25, "lhu", zextloadi16>;
438 def LW      : LoadM<0x23, "lw",  load>;
439 def SB      : StoreM<0x28, "sb", truncstorei8>;
440 def SH      : StoreM<0x29, "sh", truncstorei16>;
441 def SW      : StoreM<0x2b, "sw", store>;
442
443 // Conditional Branch
444 def BEQ     : CBranch<0x04, "beq", seteq>;
445 def BNE     : CBranch<0x05, "bne", setne>;
446
447 let rt=1 in
448 def BGEZ    : CBranchZero<0x01, "bgez", setge>;
449
450 let rt=0 in {
451 def BGTZ    : CBranchZero<0x07, "bgtz", setgt>;
452 def BLEZ    : CBranchZero<0x07, "blez", setle>;
453 def BLTZ    : CBranchZero<0x01, "bltz", setlt>;
454 }
455
456 // Set Condition Code
457 def SLT     : SetCC_R<0x00, 0x2a, "slt", setlt>;
458 def SLTu    : SetCC_R<0x00, 0x2b, "sltu", setult>;
459 def SLTi    : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
460 def SLTiu   : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
461
462 // Unconditional jump
463 def J       : JumpFJ<0x02, "j">;
464 def JR      : JumpFR<0x00, 0x08, "jr">;
465
466 // Jump and Link (Call)
467 def JAL     : JumpLink<0x03, "jal">;
468 def JALR    : JumpLinkReg<0x00, 0x09, "jalr">;
469 def BGEZAL  : BranchLink<"bgezal">;
470 def BLTZAL  : BranchLink<"bltzal">;
471
472 // MulDiv and Move From Hi/Lo operations, have
473 // their correpondent SDNodes created on ISelDAG.
474 // Special Mul, Div operations
475 def MULT    : MulDiv<0x18, "mult", IIImul>;
476 def MULTu   : MulDiv<0x19, "multu", IIImul>;
477 def DIV     : MulDiv<0x1a, "div", IIIdiv>;
478 def DIVu    : MulDiv<0x1b, "divu", IIIdiv>;
479
480 // Move From Hi/Lo
481 def MFHI    : MoveFromTo<0x10, "mfhi">;
482 def MFLO    : MoveFromTo<0x12, "mflo">;
483 def MTHI    : MoveFromTo<0x11, "mthi">;
484 def MTLO    : MoveFromTo<0x13, "mtlo">;
485
486 // No operation
487 let addr=0 in
488 def NOP     : FJ<0, (outs), (ins), "nop", [], IIAlu>;
489
490 // Ret instruction - as mips does not have "ret" a
491 // jr $ra must be generated.
492 let isReturn=1, isTerminator=1, hasDelaySlot=1,
493     isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
494 {
495   def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
496                 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
497 }
498
499 // FrameIndexes are legalized when they are operands from load/store
500 // instructions. The same not happens for stack address copies, so an
501 // add op with mem ComplexPattern is used and the stack address copy
502 // can be matched. It's similar to Sparc LEA_ADDRi
503 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
504
505 // Count Leading
506 // CLO/CLZ are part of the newer MIPS32(tm) instruction
507 // set and not older Mips I keep this for future use
508 // though. 
509 //def CLO     : CountLeading<0x21, "clo">;
510 //def CLZ     : CountLeading<0x20, "clz">;
511
512 // MADD*/MSUB* are not part of MipsI either.
513 //def MADD    : MArithR<0x00, "madd">;
514 //def MADDU   : MArithR<0x01, "maddu">;
515 //def MSUB    : MArithR<0x04, "msub">;
516 //def MSUBU   : MArithR<0x05, "msubu">;
517
518 let Predicates = [HasSEInReg] in {
519   let shamt = 0x10, rs = 0 in 
520     def SEB : SignExtInReg<0x21, "seb", i8>;
521
522   let shamt = 0x18, rs = 0 in 
523     def SEH : SignExtInReg<0x20, "seh", i16>;
524 }
525
526 //===----------------------------------------------------------------------===//
527 //  Arbitrary patterns that map to one or more instructions
528 //===----------------------------------------------------------------------===//
529
530 // Small immediates
531 def : Pat<(i32 immSExt16:$in),
532           (ADDiu ZERO, imm:$in)>;
533 def : Pat<(i32 immZExt16:$in),
534           (ORi ZERO, imm:$in)>;
535
536 // Arbitrary immediates
537 def : Pat<(i32 imm:$imm),
538           (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
539
540 // Carry patterns
541 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
542           (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
543 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
544           (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
545 def : Pat<(addc  CPURegs:$src, imm:$imm),
546           (ADDiu CPURegs:$src, imm:$imm)>;
547
548 // Call
549 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
550           (JAL tglobaladdr:$dst)>;
551 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
552           (JAL texternalsym:$dst)>;
553 def : Pat<(MipsJmpLink CPURegs:$dst),
554           (JALR CPURegs:$dst)>;
555
556 // GlobalAddress, Constant Pool, ExternalSymbol, and JumpTable
557 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
558 def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
559 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
560           (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
561 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
562 def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
563 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
564           (ADDiu CPURegs:$hi, tjumptable:$lo)>;
565
566 // Mips does not have "not", so we expand our way
567 def : Pat<(not CPURegs:$in),
568           (NOR CPURegs:$in, ZERO)>;
569
570 // extended load and stores
571 def : Pat<(i32 (extloadi1  addr:$src)), (LBu addr:$src)>;
572 def : Pat<(i32 (extloadi8  addr:$src)), (LBu addr:$src)>;
573 def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
574
575 // peepholes
576 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
577
578 // brcond patterns
579 // direct match equal/notequal zero branches
580 def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
581           (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
582 def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
583           (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
584
585 def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
586           (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
587 def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
588           (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
589
590 def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
591           (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
592 def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
593           (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
594
595 def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
596           (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
597 def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
598           (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
599
600 def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
601           (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
602 def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
603           (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
604 def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
605           (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
606 def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
607           (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
608
609 def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
610           (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
611 def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
612           (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
613
614 // generic brcond pattern
615 def : Pat<(brcond CPURegs:$cond, bb:$dst),
616           (BNE CPURegs:$cond, ZERO, bb:$dst)>;
617
618 /// setcc patterns, only matched when there
619 /// is no brcond following a setcc operation
620 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
621           (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
622 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
623           (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
624
625 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
626           (SLT CPURegs:$rhs, CPURegs:$lhs)>;
627 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
628           (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
629
630 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
631           (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
632 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
633           (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
634
635 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
636           (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
637               (SLT CPURegs:$rhs, CPURegs:$lhs))>;
638
639 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
640           (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
641                     (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
642
643 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
644           (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
645 def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
646           (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;
647
648 //===----------------------------------------------------------------------===//
649 // Floating Point Support
650 //===----------------------------------------------------------------------===//
651
652 include "MipsInstrFPU.td"
653