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