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