1 //===- Mips16InstrInfo.td - Target Description for Mips16 -*- tablegen -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes Mips16 instructions.
12 //===----------------------------------------------------------------------===//
17 def addr16 : ComplexPattern<iPTR, 2, "selectAddr16", [frameindex]>;
18 def addr16sp : ComplexPattern<iPTR, 2, "selectAddr16SP", [frameindex]>;
22 def mem16 : Operand<i32> {
23 let PrintMethod = "printMemOperand";
24 let MIOperandInfo = (ops CPU16Regs, simm16);
25 let EncoderMethod = "getMemEncoding";
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";
40 def mem16_ea : Operand<i32> {
41 let PrintMethod = "printMemOperandEA";
42 let MIOperandInfo = (ops CPU16RegsPlusSP, simm16);
43 let EncoderMethod = "getMemEncoding";
46 def pcrel16 : Operand<i32>;
49 // I-type instruction format
51 // this is only used by bimm. the actual assembly value is a 12 bit signed
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>;
60 // I8 instruction format
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),
68 class FI816_ins<bits<3> _func, string asmstr,
70 FI816_ins_base<_func, asmstr, "\t$imm # 16 bit inst", itin>;
72 class FI816_SP_ins<bits<3> _func, string asmstr,
74 FI816_ins_base<_func, asmstr, "\t$$sp, $imm # 16 bit inst", itin>;
77 // RI instruction format
81 class FRI16_ins_base<bits<5> op, string asmstr, string asmstr2,
83 FRI16<op, (outs CPU16Regs:$rx), (ins simm16:$imm),
84 !strconcat(asmstr, asmstr2), [], itin>;
86 class FRI16_ins<bits<5> op, string asmstr,
88 FRI16_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
90 class FRI16_TCP_ins<bits<5> _op, string asmstr,
92 FRI16<_op, (outs CPU16Regs:$rx), (ins pcrel16:$imm, i32imm:$size),
93 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin>;
95 class FRI16R_ins_base<bits<5> op, string asmstr, string asmstr2,
97 FRI16<op, (outs), (ins CPU16Regs:$rx, simm16:$imm),
98 !strconcat(asmstr, asmstr2), [], itin>;
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>;
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";
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>;
116 // Compare a register and immediate and place result in CC
117 // Implicit use of T8
119 // EXT-CCRR Instruction format
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"), []> {
125 let usesCustomInserter = 1;
128 // JAL and JALX instruction format
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"),[],
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"),[],
149 // EXT-I instruction format
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>;
156 // EXT-I8 instruction format
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),
164 class FEXT_I816_ins<bits<3> _func, string asmstr,
165 InstrItinClass itin>:
166 FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
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>;
173 // Assembler formats in alphabetical order.
174 // Natural and pseudos are mixed together.
176 // Compare two registers and place result in CC
177 // Implicit use of T8
179 // CC-RR Instruction format
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"), []> {
185 let usesCustomInserter = 1;
189 // EXT-RI instruction format
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>;
197 class FEXT_RI16_ins<bits<5> _op, string asmstr,
198 InstrItinClass itin>:
199 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
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>;
206 class FEXT_RI16R_ins<bits<5> _op, string asmstr,
207 InstrItinClass itin>:
208 FEXT_RI16R_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
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>;
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>;
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>;
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";
231 // EXT-RRI instruction format
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>;
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>;
246 // EXT-RRI-A instruction format
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>;
255 // EXT-SHIFT instruction format
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>;
264 class FEXT_T8I816_ins<string asmstr, string asmstr2>:
266 (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
267 !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
268 !strconcat(asmstr, "\t$imm"))),[]> {
270 let usesCustomInserter = 1;
276 class FEXT_T8I8I16_ins<string asmstr, string asmstr2>:
278 (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
279 !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
280 !strconcat(asmstr, "\t$targ"))), []> {
282 let usesCustomInserter = 1;
288 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
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>;
295 // I8_MOV32R instruction format (used only by MOV32R instruction)
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>;
303 // This are pseudo formats for multiply
304 // This first one can be changed to non-pseudo now.
308 class FMULT16_ins<string asmstr, InstrItinClass itin> :
309 MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
310 !strconcat(asmstr, "\t$rx, $ry"), []>;
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"), []> {
322 // RR-type instruction format
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> {
330 class FRRBreakNull16_ins<string asmstr, InstrItinClass itin> :
331 FRRBreak16<(outs), (ins), asmstr, [], itin> {
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> {
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"), []> ;
345 // maybe refactor but need a $zero as a dummy first parameter
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> ;
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> ;
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>;
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"),
366 let Constraints = "$rx = $rz";
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"),
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> ;
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"),
387 let Constraints = "$rx_ = $rx";
390 // RRR-type instruction format
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>;
398 // These Sel patterns support the generation of conditional move
399 // pseudo instructions.
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.
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.
412 // if $op == beqz or bnez:
417 // if $op == beqz, then if $rt != 0, then the conditional assignment
418 // $rd = $rs is done.
420 // if $op == bnez, then if $rt == 0, then the conditional assignment
421 // $rd = $rs is done.
423 // So this pseudo class only has one operand, i.e. op
425 class Sel<string op>:
426 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
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;
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
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
444 // $op2 $t, $imm ;test register t and branch conditionally
445 // $op1 .+4 ;op1 is a conditional branch
449 class SeliT<string op1, string op2>:
450 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
451 CPU16Regs:$rl, simm16:$imm),
453 !strconcat("\t$rl, $imm\n\t",
454 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
456 let Constraints = "$rd = $rd_";
457 let usesCustomInserter = 1;
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
467 // $op2 $rl, $rr ;test registers rl,rr
468 // $op1 .+4 ;op2 is a conditional branch
472 class SelT<string op1, string op2>:
473 MipsPseudo16<(outs CPU16Regs:$rd_),
474 (ins CPU16Regs:$rd, CPU16Regs:$rs,
475 CPU16Regs:$rl, CPU16Regs:$rr),
477 !strconcat("\t$rl, $rr\n\t",
478 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
480 let Constraints = "$rd = $rd_";
481 let usesCustomInserter = 1;
488 MipsPseudo16<(outs), (ins simm32:$imm), "\t.word $imm", []>;
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:", []>;
496 // Some general instruction class info
500 class ArithLogic16Defs<bit isCom=0> {
502 bit isCommutable = isCom;
503 bit isReMaterializable = 1;
504 bit hasSideEffects = 0;
509 bit isTerminator = 1;
515 bit isTerminator = 1;
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.
532 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIM16Alu>;
534 def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIM16Alu>,
535 ArithLogic16Defs<0> {
536 let AddedComplexity = 5;
538 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIM16Alu>,
539 ArithLogic16Defs<0> {
540 let isCodeGenOnly = 1;
543 def AddiuRxRyOffMemX16:
544 FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIM16Alu>;
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.
552 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIM16Alu>;
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.
560 : FI816_SP_ins<0b011, "addiu", IIM16Alu> {
563 let AddedComplexity = 5;
567 : FEXT_I816_SP_ins<0b011, "addiu", IIM16Alu> {
573 // Format: ADDU rz, rx, ry MIPS16e
574 // Purpose: Add Unsigned Word (3-Operand)
575 // To add 32-bit integers.
578 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIM16Alu>, ArithLogic16Defs<1>;
581 // Format: AND rx, ry MIPS16e
583 // To do a bitwise logical AND.
585 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIM16Alu>, ArithLogic16Defs<1>;
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.
593 def BeqzRxImm16: FRI16_B_ins<0b00100, "beqz", IIM16Alu>, cbranch16;
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.
601 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIM16Alu>, cbranch16;
604 // Format: B offset MIPS16e
605 // Purpose: Unconditional Branch (Extended)
606 // To do an unconditional PC-relative branch.
609 def Bimm16: FI16_ins<0b00010, "b", IIM16Alu>, branch16;
611 // Format: B offset MIPS16e
612 // Purpose: Unconditional Branch
613 // To do an unconditional PC-relative branch.
615 def BimmX16: FEXT_I16_ins<0b00010, "b", IIM16Alu>, branch16;
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.
622 def BnezRxImm16: FRI16_B_ins<0b00101, "bnez", IIM16Alu>, cbranch16;
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.
629 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIM16Alu>, cbranch16;
633 //Format: BREAK immediate
634 // Purpose: Breakpoint
635 // To cause a Breakpoint exception.
637 def Break16: FRRBreakNull16_ins<"break 0", IIM16Alu>;
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.
643 def Bteqz16: FI816_ins<0b000, "bteqz", IIM16Alu>, cbranch16 {
647 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIM16Alu>, cbranch16 {
651 def BteqzT8CmpX16: FEXT_T8I816_ins<"bteqz", "cmp">, cbranch16;
653 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<"bteqz", "cmpi">,
656 def BteqzT8SltX16: FEXT_T8I816_ins<"bteqz", "slt">, cbranch16;
658 def BteqzT8SltuX16: FEXT_T8I816_ins<"bteqz", "sltu">, cbranch16;
660 def BteqzT8SltiX16: FEXT_T8I8I16_ins<"bteqz", "slti">, cbranch16;
662 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<"bteqz", "sltiu">,
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.
671 def Btnez16: FI816_ins<0b001, "btnez", IIM16Alu>, cbranch16 {
675 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIM16Alu> ,cbranch16 {
679 def BtnezT8CmpX16: FEXT_T8I816_ins<"btnez", "cmp">, cbranch16;
681 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<"btnez", "cmpi">, cbranch16;
683 def BtnezT8SltX16: FEXT_T8I816_ins<"btnez", "slt">, cbranch16;
685 def BtnezT8SltuX16: FEXT_T8I816_ins<"btnez", "sltu">, cbranch16;
687 def BtnezT8SltiX16: FEXT_T8I8I16_ins<"btnez", "slti">, cbranch16;
689 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<"btnez", "sltiu">,
693 // Format: CMP rx, ry MIPS16e
695 // To compare the contents of two GPRs.
697 def CmpRxRy16: FRR16R_ins<0b01010, "cmp", IIM16Alu> {
702 // Format: CMPI rx, immediate MIPS16e
703 // Purpose: Compare Immediate
704 // To compare a constant with the contents of a GPR.
706 def CmpiRxImm16: FRI16R_ins<0b01110, "cmpi", IIM16Alu> {
711 // Format: CMPI rx, immediate MIPS16e
712 // Purpose: Compare Immediate (Extended)
713 // To compare a constant with the contents of a GPR.
715 def CmpiRxImmX16: FEXT_RI16R_ins<0b01110, "cmpi", IIM16Alu> {
721 // Format: DIV rx, ry MIPS16e
722 // Purpose: Divide Word
723 // To divide 32-bit signed integers.
725 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIM16Alu> {
726 let Defs = [HI0, LO0];
730 // Format: DIVU rx, ry MIPS16e
731 // Purpose: Divide Unsigned Word
732 // To divide 32-bit unsigned integers.
734 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIM16Alu> {
735 let Defs = [HI0, LO0];
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.
744 def Jal16 : FJAL16_ins<0b0, "jal", IIM16Alu> {
745 let hasDelaySlot = 0; // not true, but we add the nop for now
750 def JalB16 : FJALB16_ins<0b0, "jal", IIM16Alu>, branch16 {
751 let hasDelaySlot = 0; // not true, but we add the nop for now
757 // Format: JR ra MIPS16e
758 // Purpose: Jump Register Through Register ra
759 // To execute a branch to the instruction address in the return
763 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIM16Alu> {
765 let isIndirectBranch = 1;
766 let hasDelaySlot = 1;
772 def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIM16Alu> {
774 let isIndirectBranch = 1;
780 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIM16Alu> {
782 let isIndirectBranch = 1;
787 // Format: LB ry, offset(rx) MIPS16e
788 // Purpose: Load Byte (Extended)
789 // To load a byte from memory as a signed value.
791 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, II_LB>, MayLoad{
792 let isCodeGenOnly = 1;
796 // Format: LBU ry, offset(rx) MIPS16e
797 // Purpose: Load Byte Unsigned (Extended)
798 // To load a byte from memory as a unsigned value.
800 def LbuRxRyOffMemX16:
801 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, II_LBU>, MayLoad {
802 let isCodeGenOnly = 1;
806 // Format: LH ry, offset(rx) MIPS16e
807 // Purpose: Load Halfword signed (Extended)
808 // To load a halfword from memory as a signed value.
810 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, II_LH>, MayLoad{
811 let isCodeGenOnly = 1;
815 // Format: LHU ry, offset(rx) MIPS16e
816 // Purpose: Load Halfword unsigned (Extended)
817 // To load a halfword from memory as an unsigned value.
819 def LhuRxRyOffMemX16:
820 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, II_LHU>, MayLoad {
821 let isCodeGenOnly = 1;
825 // Format: LI rx, immediate MIPS16e
826 // Purpose: Load Immediate
827 // To load a constant into a GPR.
829 def LiRxImm16: FRI16_ins<0b01101, "li", IIM16Alu>;
832 // Format: LI rx, immediate MIPS16e
833 // Purpose: Load Immediate (Extended)
834 // To load a constant into a GPR.
836 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIM16Alu>;
838 def LiRxImmAlignX16: FEXT_RI16_ins<0b01101, ".align 2\n\tli", IIM16Alu> {
839 let isCodeGenOnly = 1;
843 // Format: LW ry, offset(rx) MIPS16e
844 // Purpose: Load Word (Extended)
845 // To load a word from memory as a signed value.
847 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, II_LW>, MayLoad{
848 let isCodeGenOnly = 1;
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.
855 def LwRxSpImmX16: FEXT_RRI16_mem_ins<0b10010, "lw", mem16sp, II_LW>, MayLoad;
857 def LwRxPcTcp16: FRI16_TCP_ins<0b10110, "lw", II_LW>, MayLoad;
859 def LwRxPcTcpX16: FEXT_RI16_TCP_ins<0b10110, "lw", II_LW>, MayLoad;
861 // Format: MOVE r32, rz MIPS16e
863 // To move the contents of a GPR to a GPR.
865 def Move32R16: FI8_MOV32R16_ins<"move", IIM16Alu>;
868 // Format: MOVE ry, r32 MIPS16e
870 // To move the contents of a GPR to a GPR.
872 def MoveR3216: FI8_MOVR3216_ins<"move", IIM16Alu> {
877 // Format: MFHI rx MIPS16e
878 // Purpose: Move From HI Register
879 // To copy the special purpose HI register to a GPR.
881 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIM16Alu> {
883 let hasSideEffects = 0;
888 // Format: MFLO rx MIPS16e
889 // Purpose: Move From LO Register
890 // To copy the special purpose LO register to a GPR.
892 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIM16Alu> {
894 let hasSideEffects = 0;
899 // Pseudo Instruction for mult
901 def MultRxRy16: FMULT16_ins<"mult", IIM16Alu> {
902 let isCommutable = 1;
903 let hasSideEffects = 0;
904 let Defs = [HI0, LO0];
907 def MultuRxRy16: FMULT16_ins<"multu", IIM16Alu> {
908 let isCommutable = 1;
909 let hasSideEffects = 0;
910 let Defs = [HI0, LO0];
914 // Format: MULT rx, ry MIPS16e
915 // Purpose: Multiply Word
916 // To multiply 32-bit signed integers.
918 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIM16Alu> {
919 let isCommutable = 1;
920 let hasSideEffects = 0;
921 let Defs = [HI0, LO0];
925 // Format: MULTU rx, ry MIPS16e
926 // Purpose: Multiply Unsigned Word
927 // To multiply 32-bit unsigned integers.
929 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIM16Alu> {
930 let isCommutable = 1;
931 let hasSideEffects = 0;
932 let Defs = [HI0, LO0];
936 // Format: NEG rx, ry MIPS16e
938 // To negate an integer value.
940 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIM16Alu>;
943 // Format: NOT rx, ry MIPS16e
945 // To complement an integer value
947 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIM16Alu>;
950 // Format: OR rx, ry MIPS16e
952 // To do a bitwise logical OR.
954 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIM16Alu>, ArithLogic16Defs<1>;
957 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
958 // (All args are optional) MIPS16e
959 // Purpose: Restore Registers and Deallocate Stack Frame
960 // To deallocate a stack frame before exit from a subroutine,
961 // restoring return address and static registers, and adjusting
966 FI8_SVRS16<0b1, (outs), (ins variable_ops),
967 "", [], II_RESTORE >, MayLoad {
968 let isCodeGenOnly = 1;
975 FI8_SVRS16<0b1, (outs), (ins variable_ops),
976 "", [], II_RESTORE >, MayLoad {
977 let isCodeGenOnly = 1;
983 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
985 // Purpose: Save Registers and Set Up Stack Frame
986 // To set up a stack frame on entry to a subroutine,
987 // saving return address and static registers, and adjusting stack
990 FI8_SVRS16<0b1, (outs), (ins variable_ops),
991 "", [], II_SAVE >, MayStore {
992 let isCodeGenOnly = 1;
998 FI8_SVRS16<0b1, (outs), (ins variable_ops),
999 "", [], II_SAVE >, MayStore {
1000 let isCodeGenOnly = 1;
1005 // Format: SB ry, offset(rx) MIPS16e
1006 // Purpose: Store Byte (Extended)
1007 // To store a byte to memory.
1009 def SbRxRyOffMemX16:
1010 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, II_SB>, MayStore;
1013 // Format: SEB rx MIPS16e
1014 // Purpose: Sign-Extend Byte
1015 // Sign-extend least significant byte in register rx.
1018 : FRR_SF16_ins<0b10001, 0b100, "seb", IIM16Alu>;
1021 // Format: SEH rx MIPS16e
1022 // Purpose: Sign-Extend Halfword
1023 // Sign-extend least significant word in register rx.
1026 : FRR_SF16_ins<0b10001, 0b101, "seh", IIM16Alu>;
1029 // The Sel(T) instructions are pseudos
1030 // T means that they use T8 implicitly.
1033 // Format: SelBeqZ rd, rs, rt
1034 // Purpose: if rt==0, do nothing
1037 def SelBeqZ: Sel<"beqz">;
1040 // Format: SelTBteqZCmp rd, rs, rl, rr
1041 // Purpose: b = Cmp rl, rr.
1042 // If b==0 then do nothing.
1043 // if b!=0 then rd = rs
1045 def SelTBteqZCmp: SelT<"bteqz", "cmp">;
1048 // Format: SelTBteqZCmpi rd, rs, rl, rr
1049 // Purpose: b = Cmpi rl, imm.
1050 // If b==0 then do nothing.
1051 // if b!=0 then rd = rs
1053 def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
1056 // Format: SelTBteqZSlt rd, rs, rl, rr
1057 // Purpose: b = Slt rl, rr.
1058 // If b==0 then do nothing.
1059 // if b!=0 then rd = rs
1061 def SelTBteqZSlt: SelT<"bteqz", "slt">;
1064 // Format: SelTBteqZSlti rd, rs, rl, rr
1065 // Purpose: b = Slti rl, imm.
1066 // If b==0 then do nothing.
1067 // if b!=0 then rd = rs
1069 def SelTBteqZSlti: SeliT<"bteqz", "slti">;
1072 // Format: SelTBteqZSltu rd, rs, rl, rr
1073 // Purpose: b = Sltu rl, rr.
1074 // If b==0 then do nothing.
1075 // if b!=0 then rd = rs
1077 def SelTBteqZSltu: SelT<"bteqz", "sltu">;
1080 // Format: SelTBteqZSltiu rd, rs, rl, rr
1081 // Purpose: b = Sltiu rl, imm.
1082 // If b==0 then do nothing.
1083 // if b!=0 then rd = rs
1085 def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
1088 // Format: SelBnez rd, rs, rt
1089 // Purpose: if rt!=0, do nothing
1092 def SelBneZ: Sel<"bnez">;
1095 // Format: SelTBtneZCmp rd, rs, rl, rr
1096 // Purpose: b = Cmp rl, rr.
1097 // If b!=0 then do nothing.
1098 // if b0=0 then rd = rs
1100 def SelTBtneZCmp: SelT<"btnez", "cmp">;
1103 // Format: SelTBtnezCmpi rd, rs, rl, rr
1104 // Purpose: b = Cmpi rl, imm.
1105 // If b!=0 then do nothing.
1106 // if b==0 then rd = rs
1108 def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
1111 // Format: SelTBtneZSlt rd, rs, rl, rr
1112 // Purpose: b = Slt rl, rr.
1113 // If b!=0 then do nothing.
1114 // if b==0 then rd = rs
1116 def SelTBtneZSlt: SelT<"btnez", "slt">;
1119 // Format: SelTBtneZSlti rd, rs, rl, rr
1120 // Purpose: b = Slti rl, imm.
1121 // If b!=0 then do nothing.
1122 // if b==0 then rd = rs
1124 def SelTBtneZSlti: SeliT<"btnez", "slti">;
1127 // Format: SelTBtneZSltu rd, rs, rl, rr
1128 // Purpose: b = Sltu rl, rr.
1129 // If b!=0 then do nothing.
1130 // if b==0 then rd = rs
1132 def SelTBtneZSltu: SelT<"btnez", "sltu">;
1135 // Format: SelTBtneZSltiu rd, rs, rl, rr
1136 // Purpose: b = Slti rl, imm.
1137 // If b!=0 then do nothing.
1138 // if b==0 then rd = rs
1140 def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
1143 // Format: SH ry, offset(rx) MIPS16e
1144 // Purpose: Store Halfword (Extended)
1145 // To store a halfword to memory.
1147 def ShRxRyOffMemX16:
1148 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, II_SH>, MayStore;
1151 // Format: SLL rx, ry, sa MIPS16e
1152 // Purpose: Shift Word Left Logical (Extended)
1153 // To execute a left-shift of a word by a fixed number of bits-0 to 31 bits.
1155 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIM16Alu>;
1158 // Format: SLLV ry, rx MIPS16e
1159 // Purpose: Shift Word Left Logical Variable
1160 // To execute a left-shift of a word by a variable number of bits.
1162 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIM16Alu>;
1164 // Format: SLTI rx, immediate MIPS16e
1165 // Purpose: Set on Less Than Immediate
1166 // To record the result of a less-than comparison with a constant.
1169 def SltiRxImm16: FRI16R_ins<0b01010, "slti", IIM16Alu> {
1174 // Format: SLTI rx, immediate MIPS16e
1175 // Purpose: Set on Less Than Immediate (Extended)
1176 // To record the result of a less-than comparison with a constant.
1179 def SltiRxImmX16: FEXT_RI16R_ins<0b01010, "slti", IIM16Alu> {
1183 def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
1185 // Format: SLTIU rx, immediate MIPS16e
1186 // Purpose: Set on Less Than Immediate Unsigned
1187 // To record the result of a less-than comparison with a constant.
1190 def SltiuRxImm16: FRI16R_ins<0b01011, "sltiu", IIM16Alu> {
1195 // Format: SLTI rx, immediate MIPS16e
1196 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1197 // To record the result of a less-than comparison with a constant.
1200 def SltiuRxImmX16: FEXT_RI16R_ins<0b01011, "sltiu", IIM16Alu> {
1204 // Format: SLTIU rx, immediate MIPS16e
1205 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1206 // To record the result of a less-than comparison with a constant.
1208 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
1211 // Format: SLT rx, ry MIPS16e
1212 // Purpose: Set on Less Than
1213 // To record the result of a less-than comparison.
1215 def SltRxRy16: FRR16R_ins<0b00010, "slt", IIM16Alu>{
1219 def SltCCRxRy16: FCCRR16_ins<"slt">;
1221 // Format: SLTU rx, ry MIPS16e
1222 // Purpose: Set on Less Than Unsigned
1223 // To record the result of an unsigned less-than comparison.
1225 def SltuRxRy16: FRR16R_ins<0b00011, "sltu", IIM16Alu>{
1229 def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
1230 let isCodeGenOnly=1;
1235 def SltuCCRxRy16: FCCRR16_ins<"sltu">;
1237 // Format: SRAV ry, rx MIPS16e
1238 // Purpose: Shift Word Right Arithmetic Variable
1239 // To execute an arithmetic right-shift of a word by a variable
1242 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIM16Alu>;
1246 // Format: SRA rx, ry, sa MIPS16e
1247 // Purpose: Shift Word Right Arithmetic (Extended)
1248 // To execute an arithmetic right-shift of a word by a fixed
1249 // number of bits-1 to 8 bits.
1251 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIM16Alu>;
1255 // Format: SRLV ry, rx MIPS16e
1256 // Purpose: Shift Word Right Logical Variable
1257 // To execute a logical right-shift of a word by a variable
1260 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIM16Alu>;
1264 // Format: SRL rx, ry, sa MIPS16e
1265 // Purpose: Shift Word Right Logical (Extended)
1266 // To execute a logical right-shift of a word by a fixed
1267 // number of bits-1 to 31 bits.
1269 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIM16Alu>;
1272 // Format: SUBU rz, rx, ry MIPS16e
1273 // Purpose: Subtract Unsigned Word
1274 // To subtract 32-bit integers
1276 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIM16Alu>, ArithLogic16Defs<0>;
1279 // Format: SW ry, offset(rx) MIPS16e
1280 // Purpose: Store Word (Extended)
1281 // To store a word to memory.
1283 def SwRxRyOffMemX16: FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, II_SW>, MayStore;
1286 // Format: SW rx, offset(sp) MIPS16e
1287 // Purpose: Store Word rx (SP-Relative)
1288 // To store an SP-relative word to memory.
1290 def SwRxSpImmX16: FEXT_RRI16_mem2_ins<0b11010, "sw", mem16sp, II_SW>, MayStore;
1294 // Format: XOR rx, ry MIPS16e
1296 // To do a bitwise logical XOR.
1298 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIM16Alu>, ArithLogic16Defs<1>;
1300 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1301 let Predicates = [InMips16Mode];
1304 // Unary Arith/Logic
1306 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1307 Mips16Pat<(OpNode CPU16Regs:$r),
1310 def: ArithLogicU_pat<not, NotRxRy16>;
1311 def: ArithLogicU_pat<ineg, NegRxRy16>;
1313 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1314 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1315 (I CPU16Regs:$l, CPU16Regs:$r)>;
1317 def: ArithLogic16_pat<add, AdduRxRyRz16>;
1318 def: ArithLogic16_pat<and, AndRxRxRy16>;
1319 def: ArithLogic16_pat<mul, MultRxRyRz16>;
1320 def: ArithLogic16_pat<or, OrRxRxRy16>;
1321 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1322 def: ArithLogic16_pat<xor, XorRxRxRy16>;
1324 // Arithmetic and logical instructions with 2 register operands.
1326 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1327 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1328 (I CPU16Regs:$in, imm_type:$imm)>;
1330 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
1331 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1332 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1333 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1334 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
1336 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1337 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1338 (I CPU16Regs:$r, CPU16Regs:$ra)>;
1340 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1341 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1342 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1344 class LoadM16_pat<PatFrag OpNode, Instruction I, ComplexPattern Addr> :
1345 Mips16Pat<(OpNode Addr:$addr), (I Addr:$addr)>;
1347 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16, addr16>;
1348 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16, addr16>;
1349 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16, addr16>;
1350 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16, addr16>;
1351 def: LoadM16_pat<load, LwRxSpImmX16, addr16sp>;
1353 class StoreM16_pat<PatFrag OpNode, Instruction I, ComplexPattern Addr> :
1354 Mips16Pat<(OpNode CPU16Regs:$r, Addr:$addr), (I CPU16Regs:$r, Addr:$addr)>;
1356 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16, addr16>;
1357 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16, addr16>;
1358 def: StoreM16_pat<store, SwRxSpImmX16, addr16sp>;
1360 // Unconditional branch
1361 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1362 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
1363 let Predicates = [InMips16Mode];
1366 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1367 (Jal16 tglobaladdr:$dst)>;
1369 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1370 (Jal16 texternalsym:$dst)>;
1373 def: Mips16Pat<(brind CPU16Regs:$rs), (JrcRx16 CPU16Regs:$rs)> {
1374 // Ensure that the addition of MIPS32r6/MIPS64r6 support does not change
1375 // MIPS16's behaviour.
1376 let AddedComplexity = 1;
1379 // Jump and Link (Call)
1380 let isCall=1, hasDelaySlot=0 in
1382 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
1383 "jalrc\t$rs", [(MipsJmpLink CPU16Regs:$rs)], II_JALRC> {
1388 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1389 hasExtraSrcRegAllocReq = 1 in
1390 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1395 class SetCC_R16<PatFrag cond_op, Instruction I>:
1396 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1397 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1399 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1400 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1401 (I CPU16Regs:$rx, imm_type:$imm16)>;
1404 def: Mips16Pat<(i32 addr16sp:$addr), (AddiuRxRyOffMemX16 addr16sp:$addr)>;
1407 // Large (>16 bit) immediate loads
1408 def : Mips16Pat<(i32 imm:$imm), (LwConstant32 imm:$imm, -1)>;
1411 // Some branch conditional patterns are not generated by llvm at this time.
1412 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1413 // comparison they are used and for unsigned a different pattern is used.
1414 // I am pushing upstream from the full mips16 port and it seemed that I needed
1415 // these earlier and the mips32 port has these but now I cannot create test
1416 // cases that use these patterns. While I sort this all out I will leave these
1417 // extra patterns commented out and if I can be sure they are really not used,
1418 // I will delete the code. I don't want to check the code in uncommented without
1419 // a valid test case. In some cases, the compiler is generating patterns with
1420 // setcc instead and earlier I had implemented setcc first so may have masked
1421 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1422 // figure out how to enable the brcond patterns or else possibly new
1423 // combinations of brcond and setcc.
1429 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1430 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1435 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1436 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1440 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1441 (BeqzRxImm16 CPU16Regs:$rx, bb:$targ16)
1445 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1448 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1449 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1456 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1457 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1461 // never called because compiler transforms a >= k to a > (k-1)
1463 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1464 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1471 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1472 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1476 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1477 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1484 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1485 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1492 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1493 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1497 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1498 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1502 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1503 (BnezRxImm16 CPU16Regs:$rx, bb:$targ16)
1507 // This needs to be there but I forget which code will generate it
1510 <(brcond CPU16Regs:$rx, bb:$targ16),
1511 (BnezRxImm16 CPU16Regs:$rx, bb:$targ16)
1520 // <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1521 // (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1528 // <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1529 // (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1537 // <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1538 // (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1541 def: UncondBranch16_pat<br, Bimm16>;
1544 def: Mips16Pat<(i32 immSExt16:$in),
1545 (AddiuRxRxImmX16 (MoveR3216 ZERO), immSExt16:$in)>;
1547 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1553 <(MipsDivRem16 CPU16Regs:$rx, CPU16Regs:$ry),
1554 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1560 <(MipsDivRemU16 CPU16Regs:$rx, CPU16Regs:$ry),
1561 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1566 // if !(a < b) x = y
1568 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1569 CPU16Regs:$x, CPU16Regs:$y),
1570 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1571 CPU16Regs:$a, CPU16Regs:$b)>;
1578 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1579 CPU16Regs:$x, CPU16Regs:$y),
1580 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1581 CPU16Regs:$b, CPU16Regs:$a)>;
1586 // if !(a < b) x = y;
1589 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1590 CPU16Regs:$x, CPU16Regs:$y),
1591 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1592 CPU16Regs:$a, CPU16Regs:$b)>;
1599 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1600 CPU16Regs:$x, CPU16Regs:$y),
1601 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1602 CPU16Regs:$b, CPU16Regs:$a)>;
1606 // due to an llvm optimization, i don't think that this will ever
1607 // be used. This is transformed into x = (a > k-1)?x:y
1612 // (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1613 // CPU16Regs:$T, CPU16Regs:$F),
1614 // (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1615 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1618 // (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1619 // CPU16Regs:$T, CPU16Regs:$F),
1620 // (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1621 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1626 // if !(a < k) x = y;
1629 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1630 CPU16Regs:$x, CPU16Regs:$y),
1631 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1632 CPU16Regs:$a, immSExt16:$b)>;
1638 // x = (a <= b)? x : y
1642 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1643 CPU16Regs:$x, CPU16Regs:$y),
1644 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1645 CPU16Regs:$b, CPU16Regs:$a)>;
1649 // x = (a <= b)? x : y
1653 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1654 CPU16Regs:$x, CPU16Regs:$y),
1655 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1656 CPU16Regs:$b, CPU16Regs:$a)>;
1660 // x = (a == b)? x : y
1662 // if (a != b) x = y
1664 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1665 CPU16Regs:$x, CPU16Regs:$y),
1666 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1667 CPU16Regs:$b, CPU16Regs:$a)>;
1671 // x = (a == 0)? x : y
1673 // if (a != 0) x = y
1675 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1676 CPU16Regs:$x, CPU16Regs:$y),
1677 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1683 // x = (a == k)? x : y
1685 // if (a != k) x = y
1687 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1688 CPU16Regs:$x, CPU16Regs:$y),
1689 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1690 CPU16Regs:$a, immZExt16:$k)>;
1695 // x = (a != b)? x : y
1697 // if (a == b) x = y
1700 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1701 CPU16Regs:$x, CPU16Regs:$y),
1702 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1703 CPU16Regs:$b, CPU16Regs:$a)>;
1707 // x = (a != 0)? x : y
1709 // if (a == 0) x = y
1711 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1712 CPU16Regs:$x, CPU16Regs:$y),
1713 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1721 def : Mips16Pat<(select CPU16Regs:$a,
1722 CPU16Regs:$x, CPU16Regs:$y),
1723 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1729 // x = (a != k)? x : y
1731 // if (a == k) x = y
1733 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1734 CPU16Regs:$x, CPU16Regs:$y),
1735 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1736 CPU16Regs:$a, immZExt16:$k)>;
1739 // When writing C code to test setxx these patterns,
1740 // some will be transformed into
1741 // other things. So we test using C code but using -O3 and -O0
1746 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1747 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1750 <(seteq CPU16Regs:$lhs, 0),
1751 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1759 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1760 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1764 // For constants, llvm transforms this to:
1765 // x > (k - 1) and then reverses the operands to use setlt. So this pattern
1766 // is not used now by the compiler. (Presumably checking that k-1 does not
1767 // overflow). The compiler never uses this at the current time, due to
1768 // other optimizations.
1771 // <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1772 // (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1773 // (LiRxImmX16 1))>;
1775 // This catches the x >= -32768 case by transforming it to x > -32769
1778 <(setgt CPU16Regs:$lhs, -32769),
1779 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1788 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1789 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1795 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1796 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImm16 1))>;
1801 def: SetCC_R16<setlt, SltCCRxRy16>;
1803 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1809 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1810 (SltuCCRxRy16 (LiRxImmX16 0),
1811 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1818 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1819 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1822 // this pattern will never be used because the compiler will transform
1823 // x >= k to x > (k - 1) and then use SLT
1826 // <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1827 // (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1828 // (LiRxImmX16 1))>;
1834 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1835 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1841 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1842 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1847 def: SetCC_R16<setult, SltuCCRxRy16>;
1849 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1851 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1852 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1855 def : Mips16Pat<(MipsHi tblockaddress:$in),
1856 (SllX16 (LiRxImmX16 tblockaddress:$in), 16)>;
1857 def : Mips16Pat<(MipsHi tglobaladdr:$in),
1858 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
1859 def : Mips16Pat<(MipsHi tjumptable:$in),
1860 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
1862 def : Mips16Pat<(MipsLo tblockaddress:$in), (LiRxImmX16 tblockaddress:$in)>;
1864 def : Mips16Pat<(MipsTlsHi tglobaltlsaddr:$in),
1865 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1868 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1869 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1870 (ADDiuOp RC:$gp, node:$in)>;
1873 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1874 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1876 def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1877 (LbuRxRyOffMemX16 addr16:$src)>;
1878 def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
1879 (LhuRxRyOffMemX16 addr16:$src)>;
1881 def: Mips16Pat<(trap), (Break16)>;
1883 def : Mips16Pat<(sext_inreg CPU16Regs:$val, i8),
1884 (SebRx16 CPU16Regs:$val)>;
1886 def : Mips16Pat<(sext_inreg CPU16Regs:$val, i16),
1887 (SehRx16 CPU16Regs:$val)>;
1891 (outs CPU16Regs:$rh, CPU16Regs:$rl),
1892 (ins simm16:$immHi, simm16:$immLo),
1893 "li\t$rh, $immHi\n\taddiu\t$rl, $$pc, $immLo\n ",[]> ;
1895 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
1896 def cpinst_operand : Operand<i32> {
1897 // let PrintMethod = "printCPInstOperand";
1900 // CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
1901 // the function. The first operand is the ID# for this instruction, the second
1902 // is the index into the MachineConstantPool that this is, the third is the
1903 // size in bytes of this constant pool entry.
1905 let hasSideEffects = 0, isNotDuplicable = 1 in
1906 def CONSTPOOL_ENTRY :
1907 MipsPseudo16<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
1908 i32imm:$size), "foo", []>;
1910 // Instruction Aliases
1912 let EncodingPredicates = [InMips16Mode] in
1913 def : MipsInstAlias<"nop", (Move32R16 ZERO, S0)>;