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 //===----------------------------------------------------------------------===//
14 def uimm5 : Operand<i8> {
15 let DecoderMethod= "DecodeSimm16";
19 // RRR-type instruction format
22 class FRRR16_ins<bits<2> _f, string asmstr, InstrItinClass itin> :
23 FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
24 !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
27 // I8_MOV32R instruction format (used only by MOV32R instruction)
29 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
30 FI8_MOV32R16<(outs CPURegs:$r32), (ins CPU16Regs:$rz),
31 !strconcat(asmstr, "\t$r32, $rz"), [], itin>;
34 // EXT-RI instruction format
37 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
39 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
40 !strconcat(asmstr, asmstr2), [], itin>;
42 class FEXT_RI16_ins<bits<5> _op, string asmstr,
44 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
46 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
47 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
50 // RR-type instruction format
53 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
54 string asmstr, InstrItinClass itin>:
55 FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
59 // EXT-RRI instruction format
62 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
64 FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
65 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
68 // EXT-SHIFT instruction format
70 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
71 FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, uimm5:$sa),
72 !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
76 def mem16 : Operand<i32> {
77 let PrintMethod = "printMemOperand";
78 let MIOperandInfo = (ops CPU16Regs, simm16);
79 let EncoderMethod = "getMemEncoding";
83 // Format: ADDIU rx, pc, immediate MIPS16e
84 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
85 // To add a constant to the program counter.
87 class AddiuRxPcImmX16_base : FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
88 def AddiuRxPcImmX16 : AddiuRxPcImmX16_base;
90 // Format: ADDU rz, rx, ry MIPS16e
91 // Purpose: Add Unsigned Word (3-Operand)
92 // To add 32-bit integers.
95 class AdduRxRyRz16_base: FRRR16_ins<01, "addu", IIAlu>;
96 def AdduRxRyRz16: AdduRxRyRz16_base;
99 // Format: JR ra MIPS16e
100 // Purpose: Jump Register Through Register ra
101 // To execute a branch to the instruction address in the return
105 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu>;
108 // Format: LI rx, immediate MIPS16e
109 // Purpose: Load Immediate (Extended)
110 // To load a constant into a GPR.
112 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
115 // Format: LW ry, offset(rx) MIPS16e
116 // Purpose: Load Word (Extended)
117 // To load a word from memory as a signed value.
119 class LwRxRyOffMemX16_base: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IIAlu>;
120 def LwRxRyOffMemX16: LwRxRyOffMemX16_base;
123 // Format: MOVE r32, rz MIPS16e
125 // To move the contents of a GPR to a GPR.
127 def Mov32R16: FI8_MOV32R16_ins<"move", IIAlu>;
129 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
130 // (All args are optional) MIPS16e
131 // Purpose: Restore Registers and Deallocate Stack Frame
132 // To deallocate a stack frame before exit from a subroutine,
133 // restoring return address and static registers, and adjusting
137 // fixed form for restoring RA and the frame
138 // for direct object emitter, encoding needs to be adjusted for the
141 let ra=1, s=0,s0=0,s1=0 in
143 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
144 "restore \t$$ra, $frame_size", [], IILoad >;
147 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
149 // Purpose: Save Registers and Set Up Stack Frame
150 // To set up a stack frame on entry to a subroutine,
151 // saving return address and static registers, and adjusting stack
153 let ra=1, s=1,s0=0,s1=0 in
155 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
156 "save \t$$ra, $frame_size", [], IILoad >;
159 // Format: SLL rx, ry, sa MIPS16e
160 // Purpose: Shift Word Left Logical (Extended)
161 // To execute a left-shift of a word by a fixed number of bits—0 to 31 bits.
163 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
166 // Format: SW ry, offset(rx) MIPS16e
167 // Purpose: Store Word (Extended)
168 // To store a word to memory.
170 class SwRxRyOffMemX16_base: FEXT_RRI16_mem_ins<0b11011, "sw", mem16, IIAlu>;
171 def SwRxRyOffMemX16: SwRxRyOffMemX16_base;
173 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
174 let Predicates = [InMips16Mode];
177 class ArithLogicR16Defs<SDNode OpNode, bit isComm = 0> {
178 dag OutOperandList = (outs CPU16Regs:$rz);
179 dag InOperandList = (ins CPU16Regs:$rx, CPU16Regs:$ry);
180 list<dag> Pattern = [(set CPU16Regs:$rz,
181 (OpNode CPU16Regs:$rx, CPU16Regs:$ry))];
184 multiclass ArithLogicR16_base {
185 def _add: AdduRxRyRz16_base, ArithLogicR16Defs<add, 1>;
188 defm ArithLogicR16_patt : ArithLogicR16_base;
190 class LoadM16Defs<PatFrag OpNode, Operand _MemOpnd, bit Pseudo=0> {
191 bit isPseudo = Pseudo;
192 Operand MemOpnd = _MemOpnd;
193 dag OutOperandList = (outs CPU16Regs:$ry);
194 dag InOperandList = (ins MemOpnd:$addr);
195 list<dag> Pattern = [(set CPU16Regs:$ry, (OpNode addr:$addr))];
198 multiclass LoadM16_base {
199 def _LwRxRyOffMemX16: LwRxRyOffMemX16_base, LoadM16Defs<load_a, mem16>;
202 defm LoadM16: LoadM16_base;
204 class StoreM16Defs<PatFrag OpNode, Operand _MemOpnd, bit Pseudo=0> {
205 bit isPseudo = Pseudo;
206 Operand MemOpnd = _MemOpnd;
207 dag OutOperandList = (outs );
208 dag InOperandList = (ins CPU16Regs:$ry, MemOpnd:$addr);
209 list<dag> Pattern = [(OpNode CPU16Regs:$ry, addr:$addr)];
212 multiclass StoreM16_base {
213 def _SwRxRyOffMemX16: SwRxRyOffMemX16_base, StoreM16Defs<store_a, mem16>;
216 defm StoreM16: StoreM16_base;
218 // Jump and Link (Call)
219 let isCall=1, hasDelaySlot=1 in
221 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
222 "jalr \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
225 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
226 hasExtraSrcRegAllocReq = 1 in
227 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
229 // As stack alignment is always done with addiu, we need a 16-bit immediate
230 // This is basically deprecated code but needs to be there for things
232 let Defs = [SP], Uses = [SP] in {
233 def ADJCALLSTACKDOWN16 : MipsPseudo16<(outs), (ins uimm16:$amt),
235 [(callseq_start timm:$amt)]>;
236 def ADJCALLSTACKUP16 : MipsPseudo16<(outs), (ins uimm16:$amt1, uimm16:$amt2),
238 [(callseq_end timm:$amt1, timm:$amt2)]>;
242 def : Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
243 def : Mips16Pat<(MipsLo tglobaladdr:$in), (LiRxImmX16 tglobaladdr:$in)>;