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