1 //===- MSP430InstrFormats.td - MSP430 Instruction Formats-----*- tblgen -*-===//
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 //===----------------------------------------------------------------------===//
11 // Describe MSP430 instructions format here
14 // Format specifies the encoding used by the instruction. This is part of the
15 // ad-hoc solution used to emit machine instruction encodings by our machine
17 class Format<bits<2> val> {
21 def PseudoFrm : Format<0>;
22 def SingleOpFrm : Format<1>;
23 def DoubleOpFrm : Format<2>;
24 def CondJumpFrm : Format<3>;
26 class SourceMode<bits<2> val> {
30 def SrcReg : SourceMode<0>;
31 def SrcMem : SourceMode<1>;
32 def SrcIndReg : SourceMode<2>;
33 def SrcPostInc : SourceMode<3>;
34 def SrcImm : SourceMode<3>;
36 class DestMode<bit val> {
40 def DstReg : DestMode<0>;
41 def DstMem : DestMode<1>;
43 class SizeVal<bits<3> val> {
47 def SizeUnknown : SizeVal<0>; // Unknown / unset size
48 def SizeSpecial : SizeVal<1>; // Special instruction, e.g. pseudo
49 def Size2Bytes : SizeVal<2>;
50 def Size4Bytes : SizeVal<3>;
51 def Size6Bytes : SizeVal<4>;
53 // Generic MSP430 Format
54 class MSP430Inst<dag outs, dag ins, SizeVal sz, Format f,
55 string asmstr> : Instruction {
58 let Namespace = "MSP430";
60 dag OutOperandList = outs;
61 dag InOperandList = ins;
66 // Define how we want to layout our TargetSpecific information field... This
67 // should be kept up-to-date with the fields in the MSP430InstrInfo.h file.
68 let TSFlags{1-0} = Form.Value;
69 let TSFlags{4-2} = Sz.Value;
71 let AsmString = asmstr;
74 // FIXME: Create different classes for different addressing modes.
76 // MSP430 Double Operand (Format I) Instructions
77 class IForm<bits<4> opcode, DestMode dest, bit bw, SourceMode src, SizeVal sz,
78 dag outs, dag ins, string asmstr, list<dag> pattern>
79 : MSP430Inst<outs, ins, sz, DoubleOpFrm, asmstr> {
80 let Pattern = pattern;
85 let Inst{12-15} = opcode;
86 let Inst{7} = ad.Value;
88 let Inst{4-5} = as.Value;
91 // 8 bit IForm instructions
92 class IForm8<bits<4> opcode, DestMode dest, SourceMode src, SizeVal sz,
93 dag outs, dag ins, string asmstr, list<dag> pattern>
94 : IForm<opcode, dest, 1, src, sz, outs, ins, asmstr, pattern>;
96 class I8rr<bits<4> opcode,
97 dag outs, dag ins, string asmstr, list<dag> pattern>
98 : IForm8<opcode, DstReg, SrcReg, Size2Bytes, outs, ins, asmstr, pattern>;
100 class I8ri<bits<4> opcode,
101 dag outs, dag ins, string asmstr, list<dag> pattern>
102 : IForm8<opcode, DstReg, SrcImm, Size4Bytes, outs, ins, asmstr, pattern>;
104 class I8rm<bits<4> opcode,
105 dag outs, dag ins, string asmstr, list<dag> pattern>
106 : IForm8<opcode, DstReg, SrcMem, Size4Bytes, outs, ins, asmstr, pattern>;
108 class I8mr<bits<4> opcode,
109 dag outs, dag ins, string asmstr, list<dag> pattern>
110 : IForm8<opcode, DstMem, SrcReg, Size4Bytes, outs, ins, asmstr, pattern>;
112 class I8mi<bits<4> opcode,
113 dag outs, dag ins, string asmstr, list<dag> pattern>
114 : IForm8<opcode, DstMem, SrcImm, Size6Bytes, outs, ins, asmstr, pattern>;
116 class I8mm<bits<4> opcode,
117 dag outs, dag ins, string asmstr, list<dag> pattern>
118 : IForm8<opcode, DstMem, SrcMem, Size6Bytes, outs, ins, asmstr, pattern>;
120 // 16 bit IForm instructions
121 class IForm16<bits<4> opcode, DestMode dest, SourceMode src, SizeVal sz,
122 dag outs, dag ins, string asmstr, list<dag> pattern>
123 : IForm<opcode, dest, 0, src, sz, outs, ins, asmstr, pattern>;
125 class I16rr<bits<4> opcode,
126 dag outs, dag ins, string asmstr, list<dag> pattern>
127 : IForm16<opcode, DstReg, SrcReg, Size2Bytes, outs, ins, asmstr, pattern>;
129 class I16ri<bits<4> opcode,
130 dag outs, dag ins, string asmstr, list<dag> pattern>
131 : IForm16<opcode, DstReg, SrcImm, Size4Bytes, outs, ins, asmstr, pattern>;
133 class I16rm<bits<4> opcode,
134 dag outs, dag ins, string asmstr, list<dag> pattern>
135 : IForm16<opcode, DstReg, SrcMem, Size4Bytes, outs, ins, asmstr, pattern>;
137 class I16mr<bits<4> opcode,
138 dag outs, dag ins, string asmstr, list<dag> pattern>
139 : IForm16<opcode, DstMem, SrcReg, Size4Bytes, outs, ins, asmstr, pattern>;
141 class I16mi<bits<4> opcode,
142 dag outs, dag ins, string asmstr, list<dag> pattern>
143 : IForm16<opcode, DstMem, SrcImm, Size6Bytes, outs, ins, asmstr, pattern>;
145 class I16mm<bits<4> opcode,
146 dag outs, dag ins, string asmstr, list<dag> pattern>
147 : IForm16<opcode, DstMem, SrcMem, Size6Bytes, outs, ins, asmstr, pattern>;
149 // MSP430 Single Operand (Format II) Instructions
150 class IIForm<bits<9> opcode, bit bw, SourceMode src, SizeVal sz,
151 dag outs, dag ins, string asmstr, list<dag> pattern>
152 : MSP430Inst<outs, ins, sz, SingleOpFrm, asmstr> {
153 let Pattern = pattern;
157 let Inst{7-15} = opcode;
159 let Inst{4-5} = as.Value;
162 // 8 bit IIForm instructions
163 class IIForm8<bits<9> opcode, SourceMode src, SizeVal sz,
164 dag outs, dag ins, string asmstr, list<dag> pattern>
165 : IIForm<opcode, 1, src, sz, outs, ins, asmstr, pattern>;
167 class II8r<bits<9> opcode,
168 dag outs, dag ins, string asmstr, list<dag> pattern>
169 : IIForm8<opcode, SrcReg, Size2Bytes, outs, ins, asmstr, pattern>;
171 class II8m<bits<9> opcode,
172 dag outs, dag ins, string asmstr, list<dag> pattern>
173 : IIForm8<opcode, SrcMem, Size4Bytes, outs, ins, asmstr, pattern>;
175 class II8i<bits<9> opcode,
176 dag outs, dag ins, string asmstr, list<dag> pattern>
177 : IIForm8<opcode, SrcImm, Size4Bytes, outs, ins, asmstr, pattern>;
179 // 16 bit IIForm instructions
180 class IIForm16<bits<9> opcode, SourceMode src, SizeVal sz,
181 dag outs, dag ins, string asmstr, list<dag> pattern>
182 : IIForm<opcode, 0, src, sz, outs, ins, asmstr, pattern>;
184 class II16r<bits<9> opcode,
185 dag outs, dag ins, string asmstr, list<dag> pattern>
186 : IIForm16<opcode, SrcReg, Size2Bytes, outs, ins, asmstr, pattern>;
188 class II16m<bits<9> opcode,
189 dag outs, dag ins, string asmstr, list<dag> pattern>
190 : IIForm16<opcode, SrcMem, Size4Bytes, outs, ins, asmstr, pattern>;
192 class II16i<bits<9> opcode,
193 dag outs, dag ins, string asmstr, list<dag> pattern>
194 : IIForm16<opcode, SrcImm, Size4Bytes, outs, ins, asmstr, pattern>;
196 // MSP430 Conditional Jumps Instructions
197 class CJForm<bits<3> opcode, bits<3> cond,
198 dag outs, dag ins, string asmstr, list<dag> pattern>
199 : MSP430Inst<outs, ins, Size2Bytes, CondJumpFrm, asmstr> {
200 let Pattern = pattern;
202 let Inst{13-15} = opcode;
203 let Inst{10-12} = cond;
206 // Pseudo instructions
207 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
208 : MSP430Inst<outs, ins, SizeSpecial, PseudoFrm, asmstr> {
209 let Pattern = pattern;