Remove TargetELFWriterInfo.
[oota-llvm.git] / lib / Target / Mips / Mips16InstrInfo.td
1 //===- Mips16InstrInfo.td - Target Description for Mips16  -*- 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 describes Mips16 instructions.
11 //
12 //===----------------------------------------------------------------------===//
13 //
14 //
15 // Mips Address
16 //
17 def addr16 :
18   ComplexPattern<iPTR, 3, "SelectAddr16", [frameindex], [SDNPWantParent]>;
19
20 //
21 // Address operand
22 def mem16 : Operand<i32> {
23   let PrintMethod = "printMemOperand";
24   let MIOperandInfo = (ops CPU16Regs, simm16, CPU16Regs);
25   let EncoderMethod = "getMemEncoding";
26 }
27
28 def mem16_ea : Operand<i32> {
29   let PrintMethod = "printMemOperandEA";
30   let MIOperandInfo = (ops CPU16Regs, simm16);
31   let EncoderMethod = "getMemEncoding";
32 }
33
34 //
35 // Compare a register and immediate and place result in CC
36 // Implicit use of T8
37 //
38 // EXT-CCRR Instruction format
39 //
40 class FEXT_CCRXI16_ins<bits<5> _op, string asmstr,
41                        InstrItinClass itin>:
42   FEXT_RI16<_op, (outs CPU16Regs:$cc), (ins CPU16Regs:$rx, simm16:$imm),
43             !strconcat(asmstr, "\t$rx, $imm\n\tmove\t$cc, $$t8"), [], itin> {
44   let isCodeGenOnly=1;
45 }
46
47 //
48 // EXT-I instruction format
49 //
50 class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
51   FEXT_I16<eop, (outs), (ins brtarget:$imm16),
52            !strconcat(asmstr, "\t$imm16"),[], itin>;
53
54 //
55 // EXT-I8 instruction format
56 //
57
58 class FEXT_I816_ins_base<bits<3> _func, string asmstr,
59                          string asmstr2, InstrItinClass itin>:
60   FEXT_I816<_func, (outs), (ins uimm16:$imm), !strconcat(asmstr, asmstr2),
61             [], itin>;
62
63 class FEXT_I816_ins<bits<3> _func, string asmstr,
64                     InstrItinClass itin>:
65   FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
66
67 //
68 // Assembler formats in alphabetical order.
69 // Natural and pseudos are mixed together.
70 //
71 // Compare two registers and place result in CC
72 // Implicit use of T8
73 //
74 // CC-RR Instruction format
75 //
76 class FCCRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
77   FRR16<f, (outs CPU16Regs:$cc), (ins CPU16Regs:$rx, CPU16Regs:$ry),
78         !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$cc, $$t8"), [], itin> {
79   let isCodeGenOnly=1;
80 }
81
82 //
83 // EXT-RI instruction format
84 //
85
86 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
87                          InstrItinClass itin>:
88   FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
89                   !strconcat(asmstr, asmstr2), [], itin>;
90
91 class FEXT_RI16_ins<bits<5> _op, string asmstr,
92                     InstrItinClass itin>:
93   FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
94
95 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
96   FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
97
98 class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
99                       InstrItinClass itin>:
100   FEXT_RI16<_op, (outs), (ins  CPU16Regs:$rx, brtarget:$imm),
101             !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
102
103 class FEXT_2RI16_ins<bits<5> _op, string asmstr,
104                      InstrItinClass itin>:
105   FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
106             !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
107   let Constraints = "$rx_ = $rx";
108 }
109
110
111 // this has an explicit sp argument that we ignore to work around a problem
112 // in the compiler
113 class FEXT_RI16_SP_explicit_ins<bits<5> _op, string asmstr,
114                                 InstrItinClass itin>:
115   FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPUSPReg:$ry, simm16:$imm),
116             !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
117
118 //
119 // EXT-RRI instruction format
120 //
121
122 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
123                          InstrItinClass itin>:
124   FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins  MemOpnd:$addr),
125              !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
126
127 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
128                           InstrItinClass itin>:
129   FEXT_RRI16<op, (outs ), (ins  CPU16Regs:$ry, MemOpnd:$addr),
130              !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
131
132 //
133 //
134 // EXT-RRI-A instruction format
135 //
136
137 class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
138                            InstrItinClass itin>:
139   FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins  MemOpnd:$addr),
140                !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
141
142 //
143 // EXT-SHIFT instruction format
144 //
145 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
146   FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, shamt:$sa),
147                !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
148
149 //
150 // EXT-T8I8
151 //
152 class FEXT_T8I816_ins<bits<3> _func, string asmstr, string asmstr2,
153                       InstrItinClass itin>:
154   FEXT_I816<_func, (outs),
155             (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
156             !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
157             !strconcat(asmstr, "\t$imm"))),[], itin> {
158   let isCodeGenOnly=1;
159 }
160
161 //
162 // EXT-T8I8I
163 //
164 class FEXT_T8I8I16_ins<bits<3> _func, string asmstr, string asmstr2,
165                        InstrItinClass itin>:
166   FEXT_I816<_func, (outs),
167             (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
168             !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
169             !strconcat(asmstr, "\t$targ"))), [], itin> {
170   let isCodeGenOnly=1;
171 }
172 //
173
174
175 //
176 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
177 //
178 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
179        FI8_MOVR3216<(outs CPU16Regs:$rz), (ins CPURegs:$r32),
180        !strconcat(asmstr,  "\t$rz, $r32"), [], itin>;
181
182 //
183 // I8_MOV32R instruction format (used only by MOV32R instruction)
184 //
185
186 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
187   FI8_MOV32R16<(outs CPURegs:$r32), (ins CPU16Regs:$rz),
188                !strconcat(asmstr,  "\t$r32, $rz"), [], itin>;
189
190 //
191 // This are pseudo formats for multiply
192 // This first one can be changed to non pseudo now.
193 //
194 // MULT
195 //
196 class FMULT16_ins<string asmstr, InstrItinClass itin> :
197   MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
198                !strconcat(asmstr, "\t$rx, $ry"), []>;
199
200 //
201 // MULT-LO
202 //
203 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
204   MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
205                !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
206   let isCodeGenOnly=1;
207 }
208
209 //
210 // RR-type instruction format
211 //
212
213 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
214   FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
215         !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
216 }
217
218 class FRRTR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
219   FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
220         !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), [], itin> ;
221
222 //
223 // maybe refactor but need a $zero as a dummy first parameter
224 //
225 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
226   FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
227         !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
228
229 class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
230   FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
231         !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
232
233
234 class FRR16_M_ins<bits<5> f, string asmstr,
235                   InstrItinClass itin> :
236   FRR16<f, (outs CPU16Regs:$rx), (ins),
237         !strconcat(asmstr, "\t$rx"), [], itin>;
238
239 class FRxRxRy16_ins<bits<5> f, string asmstr,
240                     InstrItinClass itin> :
241   FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
242             !strconcat(asmstr, "\t$rz, $ry"),
243             [], itin> {
244   let Constraints = "$rx = $rz";
245 }
246
247 let rx=0 in
248 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
249                               string asmstr, InstrItinClass itin>:
250   FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
251               [], itin> ;
252
253 //
254 // RRR-type instruction format
255 //
256
257 class FRRR16_ins<bits<2> _f, string asmstr,  InstrItinClass itin> :
258   FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
259          !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
260
261 //
262 // These Sel patterns support the generation of conditional move
263 // pseudo instructions.
264 //
265 // The nomenclature uses the components making up the pseudo and may
266 // be a bit counter intuitive when compared with the end result we seek.
267 // For example using a bqez in the example directly below results in the
268 // conditional move being done if the tested register is not zero.
269 // I considered in easier to check by keeping the pseudo consistent with
270 // it's components but it could have been done differently.
271 //
272 // The simplest case is when can test and operand directly and do the
273 // conditional move based on a simple mips16 conditional
274 //  branch instruction.
275 // for example:
276 // if $op == beqz or bnez:
277 //
278 // $op1 $rt, .+4
279 // move $rd, $rs
280 //
281 // if $op == beqz, then if $rt != 0, then the conditional assignment
282 // $rd = $rs is done.
283
284 // if $op == bnez, then if $rt == 0, then the conditional assignment
285 // $rd = $rs is done.
286 //
287 // So this pseudo class only has one operand, i.e. op
288 //
289 class Sel<bits<5> f1, string op, InstrItinClass itin>:
290   MipsInst16_32<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
291                 CPU16Regs:$rt),
292                 !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), [], itin,
293                 Pseudo16> {
294   let isCodeGenOnly=1;
295   let Constraints = "$rd = $rd_";
296 }
297
298 //
299 // The next two instruction classes allow for an operand which tests
300 // two operands and returns a value in register T8 and
301 //then does a conditional branch based on the value of T8
302 //
303
304 // op2 can be cmpi or slti/sltiu
305 // op1 can bteqz or btnez
306 // the operands for op2 are a register and a signed constant
307 //
308 // $op2 $t, $imm  ;test register t and branch conditionally
309 // $op1 .+4       ;op1 is a conditional branch
310 // move $rd, $rs
311 //
312 //
313 class SeliT<bits<5> f1, string op1, bits<5> f2, string op2,
314                  InstrItinClass itin>:
315   MipsInst16_32<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
316                                         CPU16Regs:$rl, simm16:$imm),
317                  !strconcat(op2,
318                  !strconcat("\t$rl, $imm\n\t",
319                  !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), [], itin,
320                  Pseudo16> {
321   let isCodeGenOnly=1;
322   let Constraints = "$rd = $rd_";
323 }
324
325 //
326 // op2 can be cmp or slt/sltu
327 // op1 can be bteqz or btnez
328 // the operands for op2 are two registers
329 // op1 is a conditional branch
330 //
331 //
332 // $op2 $rl, $rr  ;test registers rl,rr
333 // $op1 .+4       ;op2 is a conditional branch
334 // move $rd, $rs
335 //
336 //
337 class SelT<bits<5> f1, string op1, bits<5> f2, string op2,
338            InstrItinClass itin>:
339   MipsInst16_32<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
340                 CPU16Regs:$rl, CPU16Regs:$rr),
341                 !strconcat(op2,
342                 !strconcat("\t$rl, $rr\n\t",
343                 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), [], itin,
344                 Pseudo16> {
345   let isCodeGenOnly=1;
346   let Constraints = "$rd = $rd_";
347 }
348
349
350 //
351 // Some general instruction class info
352 //
353 //
354
355 class ArithLogic16Defs<bit isCom=0> {
356   bits<5> shamt = 0;
357   bit isCommutable = isCom;
358   bit isReMaterializable = 1;
359   bit neverHasSideEffects = 1;
360 }
361
362 class branch16 {
363   bit isBranch = 1;
364   bit isTerminator = 1;
365   bit isBarrier = 1;
366 }
367
368 class cbranch16 {
369   bit isBranch = 1;
370   bit isTerminator = 1;
371 }
372
373 class MayLoad {
374   bit mayLoad = 1;
375 }
376
377 class MayStore {
378   bit mayStore = 1;
379 }
380 //
381
382 // Format: ADDIU rx, immediate MIPS16e
383 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
384 // To add a constant to a 32-bit integer.
385 //
386 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
387
388 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
389   ArithLogic16Defs<0>;
390
391 def AddiuRxRyOffMemX16:
392   FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIAlu>;
393
394 //
395
396 // Format: ADDIU rx, pc, immediate MIPS16e
397 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
398 // To add a constant to the program counter.
399 //
400 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
401 //
402 // Format: ADDU rz, rx, ry MIPS16e
403 // Purpose: Add Unsigned Word (3-Operand)
404 // To add 32-bit integers.
405 //
406
407 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
408
409 //
410 // Format: AND rx, ry MIPS16e
411 // Purpose: AND
412 // To do a bitwise logical AND.
413
414 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
415
416
417 //
418 // Format: BEQZ rx, offset MIPS16e
419 // Purpose: Branch on Equal to Zero (Extended)
420 // To test a GPR then do a PC-relative conditional branch.
421 //
422 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
423
424 // Format: B offset MIPS16e
425 // Purpose: Unconditional Branch
426 // To do an unconditional PC-relative branch.
427 //
428 def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
429
430 //
431 // Format: BNEZ rx, offset MIPS16e
432 // Purpose: Branch on Not Equal to Zero (Extended)
433 // To test a GPR then do a PC-relative conditional branch.
434 //
435 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
436
437 //
438 // Format: BTEQZ offset MIPS16e
439 // Purpose: Branch on T Equal to Zero (Extended)
440 // To test special register T then do a PC-relative conditional branch.
441 //
442 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16;
443
444 def BteqzT8CmpX16: FEXT_T8I816_ins<0b000, "bteqz", "cmp", IIAlu>, cbranch16;
445
446 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<0b000, "bteqz", "cmpi", IIAlu>,
447   cbranch16;
448
449 def BteqzT8SltX16: FEXT_T8I816_ins<0b000, "bteqz", "slt", IIAlu>, cbranch16;
450
451 def BteqzT8SltuX16: FEXT_T8I816_ins<0b000, "bteqz", "sltu", IIAlu>, cbranch16;
452
453 def BteqzT8SltiX16: FEXT_T8I8I16_ins<0b000, "bteqz", "slti", IIAlu>, cbranch16;
454
455 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<0b000, "bteqz", "sltiu", IIAlu>,
456   cbranch16;
457
458 //
459 // Format: BTNEZ offset MIPS16e
460 // Purpose: Branch on T Not Equal to Zero (Extended)
461 // To test special register T then do a PC-relative conditional branch.
462 //
463 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16;
464
465 def BtnezT8CmpX16: FEXT_T8I816_ins<0b000, "btnez", "cmp", IIAlu>, cbranch16;
466
467 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<0b000, "btnez", "cmpi", IIAlu>, cbranch16;
468
469 def BtnezT8SltX16: FEXT_T8I816_ins<0b000, "btnez", "slt", IIAlu>, cbranch16;
470
471 def BtnezT8SltuX16: FEXT_T8I816_ins<0b000, "btnez", "sltu", IIAlu>, cbranch16;
472
473 def BtnezT8SltiX16: FEXT_T8I8I16_ins<0b000, "btnez", "slti", IIAlu>, cbranch16;
474
475 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<0b000, "btnez", "sltiu", IIAlu>,
476   cbranch16;
477
478 //
479 // Format: DIV rx, ry MIPS16e
480 // Purpose: Divide Word
481 // To divide 32-bit signed integers.
482 //
483 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
484   let Defs = [HI, LO];
485 }
486
487 //
488 // Format: DIVU rx, ry MIPS16e
489 // Purpose: Divide Unsigned Word
490 // To divide 32-bit unsigned integers.
491 //
492 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
493   let Defs = [HI, LO];
494 }
495
496
497 //
498 // Format: JR ra MIPS16e
499 // Purpose: Jump Register Through Register ra
500 // To execute a branch to the instruction address in the return
501 // address register.
502 //
503
504 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
505   let isBranch = 1;
506   let isIndirectBranch = 1;
507   let hasDelaySlot = 1;
508   let isTerminator=1;
509   let isBarrier=1;
510 }
511 //
512 // Format: LB ry, offset(rx) MIPS16e
513 // Purpose: Load Byte (Extended)
514 // To load a byte from memory as a signed value.
515 //
516 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad;
517
518 //
519 // Format: LBU ry, offset(rx) MIPS16e
520 // Purpose: Load Byte Unsigned (Extended)
521 // To load a byte from memory as a unsigned value.
522 //
523 def LbuRxRyOffMemX16:
524   FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad;
525
526 //
527 // Format: LH ry, offset(rx) MIPS16e
528 // Purpose: Load Halfword signed (Extended)
529 // To load a halfword from memory as a signed value.
530 //
531 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad;
532
533 //
534 // Format: LHU ry, offset(rx) MIPS16e
535 // Purpose: Load Halfword unsigned (Extended)
536 // To load a halfword from memory as an unsigned value.
537 //
538 def LhuRxRyOffMemX16:
539   FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad;
540
541 //
542 // Format: LI rx, immediate MIPS16e
543 // Purpose: Load Immediate (Extended)
544 // To load a constant into a GPR.
545 //
546 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
547
548 //
549 // Format: LW ry, offset(rx) MIPS16e
550 // Purpose: Load Word (Extended)
551 // To load a word from memory as a signed value.
552 //
553 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad;
554
555 // Format: LW rx, offset(sp) MIPS16e
556 // Purpose: Load Word (SP-Relative, Extended)
557 // To load an SP-relative word from memory as a signed value.
558 //
559 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10110, "lw", IILoad>, MayLoad;
560
561 //
562 // Format: MOVE r32, rz MIPS16e
563 // Purpose: Move
564 // To move the contents of a GPR to a GPR.
565 //
566 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
567
568 //
569 // Format: MOVE ry, r32 MIPS16e
570 //Purpose: Move
571 // To move the contents of a GPR to a GPR.
572 //
573 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
574
575 //
576 // Format: MFHI rx MIPS16e
577 // Purpose: Move From HI Register
578 // To copy the special purpose HI register to a GPR.
579 //
580 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
581   let Uses = [HI];
582   let neverHasSideEffects = 1;
583 }
584
585 //
586 // Format: MFLO rx MIPS16e
587 // Purpose: Move From LO Register
588 // To copy the special purpose LO register to a GPR.
589 //
590 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
591   let Uses = [LO];
592   let neverHasSideEffects = 1;
593 }
594
595 //
596 // Pseudo Instruction for mult
597 //
598 def MultRxRy16:  FMULT16_ins<"mult",  IIAlu> {
599   let isCommutable = 1;
600   let neverHasSideEffects = 1;
601   let Defs = [HI, LO];
602 }
603
604 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
605   let isCommutable = 1;
606   let neverHasSideEffects = 1;
607   let Defs = [HI, LO];
608 }
609
610 //
611 // Format: MULT rx, ry MIPS16e
612 // Purpose: Multiply Word
613 // To multiply 32-bit signed integers.
614 //
615 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
616   let isCommutable = 1;
617   let neverHasSideEffects = 1;
618   let Defs = [HI, LO];
619 }
620
621 //
622 // Format: MULTU rx, ry MIPS16e
623 // Purpose: Multiply Unsigned Word
624 // To multiply 32-bit unsigned integers.
625 //
626 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
627   let isCommutable = 1;
628   let neverHasSideEffects = 1;
629   let Defs = [HI, LO];
630 }
631
632 //
633 // Format: NEG rx, ry MIPS16e
634 // Purpose: Negate
635 // To negate an integer value.
636 //
637 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
638
639 //
640 // Format: NOT rx, ry MIPS16e
641 // Purpose: Not
642 // To complement an integer value
643 //
644 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
645
646 //
647 // Format: OR rx, ry MIPS16e
648 // Purpose: Or
649 // To do a bitwise logical OR.
650 //
651 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
652
653 //
654 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
655 // (All args are optional) MIPS16e
656 // Purpose: Restore Registers and Deallocate Stack Frame
657 // To deallocate a stack frame before exit from a subroutine,
658 // restoring return address and static registers, and adjusting
659 // stack
660 //
661
662 // fixed form for restoring RA and the frame
663 // for direct object emitter, encoding needs to be adjusted for the
664 // frame size
665 //
666 let ra=1, s=0,s0=1,s1=1 in
667 def RestoreRaF16:
668   FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
669              "restore \t$$ra,  $$s0, $$s1, $frame_size", [], IILoad >, MayLoad {
670   let isCodeGenOnly = 1;
671 }
672
673 //
674 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
675 // MIPS16e
676 // Purpose: Save Registers and Set Up Stack Frame
677 // To set up a stack frame on entry to a subroutine,
678 // saving return address and static registers, and adjusting stack
679 //
680 let ra=1, s=1,s0=1,s1=1 in
681 def SaveRaF16:
682   FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
683              "save \t$$ra, $$s0, $$s1, $frame_size", [], IIStore >, MayStore {
684   let isCodeGenOnly = 1;
685 }
686 //
687 // Format: SB ry, offset(rx) MIPS16e
688 // Purpose: Store Byte (Extended)
689 // To store a byte to memory.
690 //
691 def SbRxRyOffMemX16:
692   FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
693
694 //
695 // The Sel(T) instructions are pseudos
696 // T means that they use T8 implicitly.
697 //
698 //
699 // Format: SelBeqZ rd, rs, rt
700 // Purpose: if rt==0, do nothing
701 //          else rs = rt
702 //
703 def SelBeqZ: Sel<0b00100, "beqz", IIAlu>;
704
705 //
706 // Format:  SelTBteqZCmp rd, rs, rl, rr
707 // Purpose: b = Cmp rl, rr.
708 //          If b==0 then do nothing.
709 //          if b!=0 then rd = rs
710 //
711 def SelTBteqZCmp: SelT<0b000, "bteqz", 0b01010, "cmp", IIAlu>;
712
713 //
714 // Format:  SelTBteqZCmpi rd, rs, rl, rr
715 // Purpose: b = Cmpi rl, imm.
716 //          If b==0 then do nothing.
717 //          if b!=0 then rd = rs
718 //
719 def SelTBteqZCmpi: SeliT<0b000, "bteqz", 0b01110, "cmpi", IIAlu>;
720
721 //
722 // Format:  SelTBteqZSlt rd, rs, rl, rr
723 // Purpose: b = Slt rl, rr.
724 //          If b==0 then do nothing.
725 //          if b!=0 then rd = rs
726 //
727 def SelTBteqZSlt: SelT<0b000, "bteqz", 0b00010, "slt", IIAlu>;
728
729 //
730 // Format:  SelTBteqZSlti rd, rs, rl, rr
731 // Purpose: b = Slti rl, imm.
732 //          If b==0 then do nothing.
733 //          if b!=0 then rd = rs
734 //
735 def SelTBteqZSlti: SeliT<0b000, "bteqz", 0b01010, "slti", IIAlu>;
736
737 //
738 // Format:  SelTBteqZSltu rd, rs, rl, rr
739 // Purpose: b = Sltu rl, rr.
740 //          If b==0 then do nothing.
741 //          if b!=0 then rd = rs
742 //
743 def SelTBteqZSltu: SelT<0b000, "bteqz", 0b00011, "sltu", IIAlu>;
744
745 //
746 // Format:  SelTBteqZSltiu rd, rs, rl, rr
747 // Purpose: b = Sltiu rl, imm.
748 //          If b==0 then do nothing.
749 //          if b!=0 then rd = rs
750 //
751 def SelTBteqZSltiu: SeliT<0b000, "bteqz", 0b01011, "sltiu", IIAlu>;
752
753 //
754 // Format: SelBnez rd, rs, rt
755 // Purpose: if rt!=0, do nothing
756 //          else rs = rt
757 //
758 def SelBneZ: Sel<0b00101, "bnez", IIAlu>;
759
760 //
761 // Format:  SelTBtneZCmp rd, rs, rl, rr
762 // Purpose: b = Cmp rl, rr.
763 //          If b!=0 then do nothing.
764 //          if b0=0 then rd = rs
765 //
766 def SelTBtneZCmp: SelT<0b001, "btnez", 0b01010, "cmp", IIAlu>;
767
768 //
769 // Format:  SelTBtnezCmpi rd, rs, rl, rr
770 // Purpose: b = Cmpi rl, imm.
771 //          If b!=0 then do nothing.
772 //          if b==0 then rd = rs
773 //
774 def SelTBtneZCmpi: SeliT<0b000, "btnez", 0b01110, "cmpi", IIAlu>;
775
776 //
777 // Format:  SelTBtneZSlt rd, rs, rl, rr
778 // Purpose: b = Slt rl, rr.
779 //          If b!=0 then do nothing.
780 //          if b==0 then rd = rs
781 //
782 def SelTBtneZSlt: SelT<0b001, "btnez", 0b00010, "slt", IIAlu>;
783
784 //
785 // Format:  SelTBtneZSlti rd, rs, rl, rr
786 // Purpose: b = Slti rl, imm.
787 //          If b!=0 then do nothing.
788 //          if b==0 then rd = rs
789 //
790 def SelTBtneZSlti: SeliT<0b001, "btnez", 0b01010, "slti", IIAlu>;
791
792 //
793 // Format:  SelTBtneZSltu rd, rs, rl, rr
794 // Purpose: b = Sltu rl, rr.
795 //          If b!=0 then do nothing.
796 //          if b==0 then rd = rs
797 //
798 def SelTBtneZSltu: SelT<0b001, "btnez", 0b00011, "sltu", IIAlu>;
799
800 //
801 // Format:  SelTBtneZSltiu rd, rs, rl, rr
802 // Purpose: b = Slti rl, imm.
803 //          If b!=0 then do nothing.
804 //          if b==0 then rd = rs
805 //
806 def SelTBtneZSltiu: SeliT<0b001, "btnez", 0b01011, "sltiu", IIAlu>;
807 //
808 //
809 // Format: SH ry, offset(rx) MIPS16e
810 // Purpose: Store Halfword (Extended)
811 // To store a halfword to memory.
812 //
813 def ShRxRyOffMemX16:
814   FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
815
816 //
817 // Format: SLL rx, ry, sa MIPS16e
818 // Purpose: Shift Word Left Logical (Extended)
819 // To execute a left-shift of a word by a fixed number of bits—0 to 31 bits.
820 //
821 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
822
823 //
824 // Format: SLLV ry, rx MIPS16e
825 // Purpose: Shift Word Left Logical Variable
826 // To execute a left-shift of a word by a variable number of bits.
827 //
828 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
829
830 //
831 // Format: SLTI rx, immediate MIPS16e
832 // Purpose: Set on Less Than Immediate (Extended)
833 // To record the result of a less-than comparison with a constant.
834 //
835 def SltiCCRxImmX16: FEXT_CCRXI16_ins<0b01010, "slti", IIAlu>;
836
837 //
838 // Format: SLTIU rx, immediate MIPS16e
839 // Purpose: Set on Less Than Immediate Unsigned (Extended)
840 // To record the result of a less-than comparison with a constant.
841 //
842 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<0b01011, "sltiu", IIAlu>;
843
844 //
845 // Format: SLT rx, ry MIPS16e
846 // Purpose: Set on Less Than
847 // To record the result of a less-than comparison.
848 //
849 def SltRxRy16: FRR16_ins<0b00010, "slt", IIAlu>;
850
851 def SltCCRxRy16: FCCRR16_ins<0b00010, "slt", IIAlu>;
852
853 // Format: SLTU rx, ry MIPS16e
854 // Purpose: Set on Less Than Unsigned
855 // To record the result of an unsigned less-than comparison.
856 //
857 def SltuRxRyRz16: FRRTR16_ins<0b00011, "sltu", IIAlu> {
858   let isCodeGenOnly=1;
859 }
860
861
862 def SltuCCRxRy16: FCCRR16_ins<0b00011, "sltu", IIAlu>;
863 //
864 // Format: SRAV ry, rx MIPS16e
865 // Purpose: Shift Word Right Arithmetic Variable
866 // To execute an arithmetic right-shift of a word by a variable
867 // number of bits.
868 //
869 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
870
871
872 //
873 // Format: SRA rx, ry, sa MIPS16e
874 // Purpose: Shift Word Right Arithmetic (Extended)
875 // To execute an arithmetic right-shift of a word by a fixed
876 // number of bits—1 to 8 bits.
877 //
878 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
879
880
881 //
882 // Format: SRLV ry, rx MIPS16e
883 // Purpose: Shift Word Right Logical Variable
884 // To execute a logical right-shift of a word by a variable
885 // number of bits.
886 //
887 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
888
889
890 //
891 // Format: SRL rx, ry, sa MIPS16e
892 // Purpose: Shift Word Right Logical (Extended)
893 // To execute a logical right-shift of a word by a fixed
894 // number of bits—1 to 31 bits.
895 //
896 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
897
898 //
899 // Format: SUBU rz, rx, ry MIPS16e
900 // Purpose: Subtract Unsigned Word
901 // To subtract 32-bit integers
902 //
903 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
904
905 //
906 // Format: SW ry, offset(rx) MIPS16e
907 // Purpose: Store Word (Extended)
908 // To store a word to memory.
909 //
910 def SwRxRyOffMemX16:
911   FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
912
913 //
914 // Format: SW rx, offset(sp) MIPS16e
915 // Purpose: Store Word rx (SP-Relative)
916 // To store an SP-relative word to memory.
917 //
918 def SwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b11010, "sw", IIStore>, MayStore;
919
920 //
921 //
922 // Format: XOR rx, ry MIPS16e
923 // Purpose: Xor
924 // To do a bitwise logical XOR.
925 //
926 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
927
928 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
929   let Predicates = [InMips16Mode];
930 }
931
932 // Unary Arith/Logic
933 //
934 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
935   Mips16Pat<(OpNode CPU16Regs:$r),
936             (I CPU16Regs:$r)>;
937
938 def: ArithLogicU_pat<not, NotRxRy16>;
939 def: ArithLogicU_pat<ineg, NegRxRy16>;
940
941 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
942   Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
943             (I CPU16Regs:$l, CPU16Regs:$r)>;
944
945 def: ArithLogic16_pat<add, AdduRxRyRz16>;
946 def: ArithLogic16_pat<and, AndRxRxRy16>;
947 def: ArithLogic16_pat<mul, MultRxRyRz16>;
948 def: ArithLogic16_pat<or, OrRxRxRy16>;
949 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
950 def: ArithLogic16_pat<xor, XorRxRxRy16>;
951
952 // Arithmetic and logical instructions with 2 register operands.
953
954 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
955   Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
956             (I CPU16Regs:$in, imm_type:$imm)>;
957
958 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
959 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
960 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
961 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
962
963 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
964   Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
965             (I CPU16Regs:$r, CPU16Regs:$ra)>;
966
967 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
968 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
969 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
970
971 class LoadM16_pat<PatFrag OpNode, Instruction I> :
972   Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
973
974 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
975 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
976 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
977 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
978 def: LoadM16_pat<load, LwRxRyOffMemX16>;
979
980 class StoreM16_pat<PatFrag OpNode, Instruction I> :
981   Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
982             (I CPU16Regs:$r, addr16:$addr)>;
983
984 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
985 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
986 def: StoreM16_pat<store, SwRxRyOffMemX16>;
987
988 // Unconditional branch
989 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
990   Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
991     let Predicates = [RelocPIC, InMips16Mode];
992   }
993
994 // Jump and Link (Call)
995 let isCall=1, hasDelaySlot=1 in
996 def JumpLinkReg16:
997   FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
998               "jalr \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
999
1000 // Mips16 pseudos
1001 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1002   hasExtraSrcRegAllocReq = 1 in
1003 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1004
1005
1006 // setcc patterns
1007
1008 class SetCC_R16<PatFrag cond_op, Instruction I>:
1009   Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1010             (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1011
1012 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1013   Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1014             (I CPU16Regs:$rx, imm_type:$imm16)>;
1015
1016
1017 def: Mips16Pat<(i32  addr16:$addr),
1018                (AddiuRxRyOffMemX16  addr16:$addr)>;
1019
1020
1021 // Large (>16 bit) immediate loads
1022 def : Mips16Pat<(i32 imm:$imm),
1023                 (OrRxRxRy16 (SllX16 (LiRxImmX16 (HI16 imm:$imm)), 16),
1024                 (LiRxImmX16 (LO16 imm:$imm)))>;
1025
1026 // Carry MipsPatterns
1027 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1028                 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1029 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1030                 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1031 def : Mips16Pat<(addc  CPU16Regs:$src, immSExt16:$imm),
1032                 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1033
1034 //
1035 // Some branch conditional patterns are not generated by llvm at this time.
1036 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1037 // comparison they are used and for unsigned a different pattern is used.
1038 // I am pushing upstream from the full mips16 port and it seemed that I needed
1039 // these earlier and the mips32 port has these but now I cannot create test
1040 // cases that use these patterns. While I sort this all out I will leave these
1041 // extra patterns commented out and if I can be sure they are really not used,
1042 // I will delete the code. I don't want to check the code in uncommented without
1043 // a valid test case. In some cases, the compiler is generating patterns with
1044 // setcc instead and earlier I had implemented setcc first so may have masked
1045 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1046 // figure out how to enable the brcond patterns or else possibly new
1047 // combinations of of brcond and setcc.
1048 //
1049 //
1050 // bcond-seteq
1051 //
1052 def: Mips16Pat
1053   <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1054    (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
1055   >;
1056
1057
1058 def: Mips16Pat
1059   <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1060    (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$targ16)
1061   >;
1062
1063 def: Mips16Pat
1064   <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1065    (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
1066   >;
1067
1068 //
1069 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1070 //
1071 def: Mips16Pat
1072   <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1073    (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx,  bb:$imm16)
1074   >;
1075
1076 //
1077 // bcond-setge
1078 //
1079 def: Mips16Pat
1080   <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1081    (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
1082   >;
1083
1084 //
1085 // never called because compiler transforms a >= k to a > (k-1)
1086 def: Mips16Pat
1087   <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1088    (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$imm16)
1089   >;
1090
1091 //
1092 // bcond-setlt
1093 //
1094 def: Mips16Pat
1095   <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1096    (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
1097   >;
1098
1099 def: Mips16Pat
1100   <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1101    (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$imm16)
1102   >;
1103
1104 //
1105 // bcond-setle
1106 //
1107 def: Mips16Pat
1108   <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1109    (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx,  bb:$imm16)
1110   >;
1111
1112 //
1113 // bcond-setne
1114 //
1115 def: Mips16Pat
1116   <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1117    (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
1118   >;
1119
1120 def: Mips16Pat
1121   <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1122    (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$targ16)
1123   >;
1124
1125 def: Mips16Pat
1126   <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1127    (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1128   >;
1129
1130 //
1131 // This needs to be there but I forget which code will generate it
1132 //
1133 def: Mips16Pat
1134   <(brcond CPU16Regs:$rx, bb:$targ16),
1135    (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1136   >;
1137
1138 //
1139
1140 //
1141 // bcond-setugt
1142 //
1143 //def: Mips16Pat
1144 //  <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1145 //   (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx,  bb:$imm16)
1146 //  >;
1147
1148 //
1149 // bcond-setuge
1150 //
1151 //def: Mips16Pat
1152 //  <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1153 //   (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
1154 //  >;
1155
1156
1157 //
1158 // bcond-setult
1159 //
1160 //def: Mips16Pat
1161 //  <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1162 //   (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
1163 //  >;
1164
1165 def: UncondBranch16_pat<br, BimmX16>;
1166
1167 // Small immediates
1168 def: Mips16Pat<(i32 immSExt16:$in),
1169                (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
1170
1171 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1172
1173 //
1174 // MipsDivRem
1175 //
1176 def: Mips16Pat
1177   <(MipsDivRem CPU16Regs:$rx, CPU16Regs:$ry),
1178    (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1179
1180 //
1181 // MipsDivRemU
1182 //
1183 def: Mips16Pat
1184   <(MipsDivRemU CPU16Regs:$rx, CPU16Regs:$ry),
1185    (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1186
1187 //  signed a,b
1188 //  x = (a>=b)?x:y
1189 //
1190 //  if !(a < b) x = y
1191 //
1192 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1193                  CPU16Regs:$x, CPU16Regs:$y),
1194                 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1195                  CPU16Regs:$a, CPU16Regs:$b)>;
1196
1197 //  signed a,b
1198 //  x = (a>b)?x:y
1199 //
1200 //  if  (b < a) x = y
1201 //
1202 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1203                  CPU16Regs:$x, CPU16Regs:$y),
1204                 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1205                  CPU16Regs:$b, CPU16Regs:$a)>;
1206
1207 // unsigned a,b
1208 // x = (a>=b)?x:y
1209 //
1210 // if !(a < b) x = y;
1211 //
1212 def : Mips16Pat<
1213   (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1214    CPU16Regs:$x, CPU16Regs:$y),
1215   (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1216    CPU16Regs:$a, CPU16Regs:$b)>;
1217
1218 //  unsigned a,b
1219 //  x = (a>b)?x:y
1220 //
1221 //  if (b < a) x = y
1222 //
1223 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1224                  CPU16Regs:$x, CPU16Regs:$y),
1225                 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1226                  CPU16Regs:$b, CPU16Regs:$a)>;
1227
1228 // signed
1229 // x = (a >= k)?x:y
1230 // due to an llvm optimization, i don't think that this will ever
1231 // be used. This is transformed into x = (a > k-1)?x:y
1232 //
1233 //
1234
1235 //def : Mips16Pat<
1236 //  (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1237 //   CPU16Regs:$T, CPU16Regs:$F),
1238 //  (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1239 //   CPU16Regs:$lhs, immSExt16:$rhs)>;
1240
1241 //def : Mips16Pat<
1242 //  (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1243 //   CPU16Regs:$T, CPU16Regs:$F),
1244 //  (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1245 //   CPU16Regs:$lhs, immSExt16:$rhs)>;
1246
1247 // signed
1248 // x = (a < k)?x:y
1249 //
1250 // if !(a < k) x = y;
1251 //
1252 def : Mips16Pat<
1253   (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1254    CPU16Regs:$x, CPU16Regs:$y),
1255   (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1256    CPU16Regs:$a, immSExt16:$b)>;
1257
1258
1259 //
1260 //
1261 // signed
1262 // x = (a <= b)? x : y
1263 //
1264 // if  (b < a) x = y
1265 //
1266 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1267                  CPU16Regs:$x, CPU16Regs:$y),
1268                 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1269                  CPU16Regs:$b, CPU16Regs:$a)>;
1270
1271 //
1272 // unnsigned
1273 // x = (a <= b)? x : y
1274 //
1275 // if  (b < a) x = y
1276 //
1277 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1278                  CPU16Regs:$x, CPU16Regs:$y),
1279                 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1280                  CPU16Regs:$b, CPU16Regs:$a)>;
1281
1282 //
1283 // signed/unsigned
1284 // x = (a == b)? x : y
1285 //
1286 // if (a != b) x = y
1287 //
1288 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1289                  CPU16Regs:$x, CPU16Regs:$y),
1290                 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1291                  CPU16Regs:$b, CPU16Regs:$a)>;
1292
1293 //
1294 // signed/unsigned
1295 // x = (a == 0)? x : y
1296 //
1297 // if (a != 0) x = y
1298 //
1299 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1300                  CPU16Regs:$x, CPU16Regs:$y),
1301                 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1302                  CPU16Regs:$a)>;
1303
1304
1305 //
1306 // signed/unsigned
1307 // x = (a == k)? x : y
1308 //
1309 // if (a != k) x = y
1310 //
1311 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1312                  CPU16Regs:$x, CPU16Regs:$y),
1313                 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1314                  CPU16Regs:$a, immZExt16:$k)>;
1315
1316
1317 //
1318 // signed/unsigned
1319 // x = (a != b)? x : y
1320 //
1321 // if (a == b) x = y
1322 //
1323 //
1324 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1325                  CPU16Regs:$x, CPU16Regs:$y),
1326                 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1327                  CPU16Regs:$b, CPU16Regs:$a)>;
1328
1329 //
1330 // signed/unsigned
1331 // x = (a != 0)? x : y
1332 //
1333 // if (a == 0) x = y
1334 //
1335 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1336                  CPU16Regs:$x, CPU16Regs:$y),
1337                 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1338                  CPU16Regs:$a)>;
1339
1340 // signed/unsigned
1341 // x = (a)? x : y
1342 //
1343 // if (!a) x = y
1344 //
1345 def : Mips16Pat<(select  CPU16Regs:$a,
1346                  CPU16Regs:$x, CPU16Regs:$y),
1347       (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1348        CPU16Regs:$a)>;
1349
1350
1351 //
1352 // signed/unsigned
1353 // x = (a != k)? x : y
1354 //
1355 // if (a == k) x = y
1356 //
1357 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1358                  CPU16Regs:$x, CPU16Regs:$y),
1359                 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1360                  CPU16Regs:$a, immZExt16:$k)>;
1361
1362 //
1363 // When writing C code to test setxx these patterns,
1364 // some will be transformed into
1365 // other things. So we test using C code but using -O3 and -O0
1366 //
1367 // seteq
1368 //
1369 def : Mips16Pat
1370   <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1371    (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1372
1373 def : Mips16Pat
1374   <(seteq CPU16Regs:$lhs, 0),
1375    (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1376
1377
1378 //
1379 // setge
1380 //
1381
1382 def: Mips16Pat
1383   <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1384    (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1385    (LiRxImmX16 1))>;
1386
1387 //
1388 // For constants, llvm transforms this to:
1389 // x > (k -1) and then reverses the operands to use setlt. So this pattern
1390 // is not used now by the compiler. (Presumably checking that k-1 does not
1391 // overflow). The compiler never uses this at a the current time, due to
1392 // other optimizations.
1393 //
1394 //def: Mips16Pat
1395 //  <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1396 //   (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1397 //   (LiRxImmX16 1))>;
1398
1399 // This catches the x >= -32768 case by transforming it to  x > -32769
1400 //
1401 def: Mips16Pat
1402   <(setgt CPU16Regs:$lhs, -32769),
1403    (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1404    (LiRxImmX16 1))>;
1405
1406 //
1407 // setgt
1408 //
1409 //
1410
1411 def: Mips16Pat
1412   <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1413    (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1414
1415 //
1416 // setle
1417 //
1418 def: Mips16Pat
1419   <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1420    (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1421
1422 //
1423 // setlt
1424 //
1425 def: SetCC_R16<setlt, SltCCRxRy16>;
1426
1427 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1428
1429 //
1430 // setne
1431 //
1432 def : Mips16Pat
1433   <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1434    (SltuCCRxRy16 (LiRxImmX16 0),
1435    (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1436
1437
1438 //
1439 // setuge
1440 //
1441 def: Mips16Pat
1442   <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1443    (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1444    (LiRxImmX16 1))>;
1445
1446 // this pattern will never be used because the compiler will transform
1447 // x >= k to x > (k - 1) and then use SLT
1448 //
1449 //def: Mips16Pat
1450 //  <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1451 //   (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1452 //   (LiRxImmX16 1))>;
1453
1454 //
1455 // setugt
1456 //
1457 def: Mips16Pat
1458   <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1459    (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1460
1461 //
1462 // setule
1463 //
1464 def: Mips16Pat
1465   <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1466    (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1467
1468 //
1469 // setult
1470 //
1471 def: SetCC_R16<setult, SltuCCRxRy16>;
1472
1473 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1474
1475 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1476                (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1477
1478 // hi/lo relocs
1479
1480 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in), 
1481                 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1482
1483 // wrapper_pic
1484 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1485   Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1486             (ADDiuOp RC:$gp, node:$in)>;
1487
1488
1489 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1490 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1491