1 //===-- MSP430InstrFormats.td - MSP430 Instruction Formats -*- 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 //===----------------------------------------------------------------------===// 11 // Describe MSP430 instructions format here 12 // 13 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 16 // code emitter. 17 class Format<bits<2> val> { 18 bits<2> Value = val; 19 } 20 21 def PseudoFrm : Format<0>; 22 def SingleOpFrm : Format<1>; 23 def DoubleOpFrm : Format<2>; 24 def CondJumpFrm : Format<3>; 25 26 class SourceMode<bits<2> val> { 27 bits<2> Value = val; 28 } 29 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>; 35 36 class DestMode<bit val> { 37 bit Value = val; 38 } 39 40 def DstReg : DestMode<0>; 41 def DstMem : DestMode<1>; 42 43 class SizeVal<bits<3> val> { 44 bits<3> Value = val; 45 } 46 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>; 52 53 // Generic MSP430 Format 54 class MSP430Inst<dag outs, dag ins, SizeVal sz, Format f, 55 string asmstr> : Instruction { 56 field bits<16> Inst; 57 58 let Namespace = "MSP430"; 59 60 dag OutOperandList = outs; 61 dag InOperandList = ins; 62 63 Format Form = f; 64 SizeVal Sz = sz; 65 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; 70 71 let AsmString = asmstr; 72 } 73 74 // FIXME: Create different classes for different addressing modes. 75 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; 81 82 DestMode ad = dest; 83 SourceMode as = src; 84 85 let Inst{12-15} = opcode; 86 let Inst{7} = ad.Value; 87 let Inst{6} = bw; 88 let Inst{4-5} = as.Value; 89 } 90 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>; 95 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>; 99 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>; 103 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>; 107 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>; 111 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>; 115 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>; 119 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>; 124 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>; 128 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>; 132 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>; 136 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>; 140 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>; 144 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>; 148 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; 154 155 SourceMode as = src; 156 157 let Inst{7-15} = opcode; 158 let Inst{6} = bw; 159 let Inst{4-5} = as.Value; 160 } 161 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>; 166 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>; 170 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>; 174 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>; 178 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>; 183 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>; 187 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>; 191 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>; 195 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; 201 202 let Inst{13-15} = opcode; 203 let Inst{10-12} = cond; 204 } 205 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; 210 let Inst{15-0} = 0; 211 } 212