Evan Cheng | 7b0249b | 2008-08-28 23:39:26 +0000 | [diff] [blame] | 1 | //===- ARMInstrFormats.td - ARM 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 | // |
| 12 | // ARM Instruction Format Definitions. |
| 13 | // |
| 14 | |
| 15 | // Format specifies the encoding used by the instruction. This is part of the |
| 16 | // ad-hoc solution used to emit machine instruction encodings by our machine |
| 17 | // code emitter. |
| 18 | class Format<bits<5> val> { |
| 19 | bits<5> Value = val; |
| 20 | } |
| 21 | |
| 22 | def Pseudo : Format<1>; |
| 23 | def MulFrm : Format<2>; |
| 24 | def MulSMLAW : Format<3>; |
| 25 | def MulSMULW : Format<4>; |
| 26 | def MulSMLA : Format<5>; |
| 27 | def MulSMUL : Format<6>; |
| 28 | def Branch : Format<7>; |
| 29 | def BranchMisc : Format<8>; |
| 30 | |
| 31 | def DPRdIm : Format<9>; |
| 32 | def DPRdReg : Format<10>; |
| 33 | def DPRdSoReg : Format<11>; |
| 34 | def DPRdMisc : Format<12>; |
| 35 | def DPRnIm : Format<13>; |
| 36 | def DPRnReg : Format<14>; |
| 37 | def DPRnSoReg : Format<15>; |
| 38 | def DPRIm : Format<16>; |
| 39 | def DPRReg : Format<17>; |
| 40 | def DPRSoReg : Format<18>; |
| 41 | def DPRImS : Format<19>; |
| 42 | def DPRRegS : Format<20>; |
| 43 | def DPRSoRegS : Format<21>; |
| 44 | |
| 45 | def LdFrm : Format<22>; |
| 46 | def StFrm : Format<23>; |
| 47 | |
| 48 | def ArithMisc : Format<24>; |
| 49 | def ThumbFrm : Format<25>; |
| 50 | def VFPFrm : Format<26>; |
| 51 | |
| 52 | |
| 53 | |
| 54 | //===----------------------------------------------------------------------===// |
| 55 | |
| 56 | // ARM Instruction templates. |
| 57 | // |
| 58 | |
| 59 | class InstARM<bits<4> opcod, AddrMode am, SizeFlagVal sz, IndexMode im, |
| 60 | Format f, string cstr> |
| 61 | : Instruction { |
| 62 | let Namespace = "ARM"; |
| 63 | |
| 64 | bits<4> Opcode = opcod; |
| 65 | AddrMode AM = am; |
| 66 | bits<4> AddrModeBits = AM.Value; |
| 67 | |
| 68 | SizeFlagVal SZ = sz; |
| 69 | bits<3> SizeFlag = SZ.Value; |
| 70 | |
| 71 | IndexMode IM = im; |
| 72 | bits<2> IndexModeBits = IM.Value; |
| 73 | |
| 74 | Format F = f; |
| 75 | bits<5> Form = F.Value; |
| 76 | |
| 77 | let Constraints = cstr; |
| 78 | } |
| 79 | |
| 80 | class PseudoInst<dag oops, dag iops, string asm, list<dag> pattern> |
| 81 | : InstARM<0, AddrModeNone, SizeSpecial, IndexModeNone, Pseudo, ""> { |
| 82 | let OutOperandList = oops; |
| 83 | let InOperandList = iops; |
| 84 | let AsmString = asm; |
| 85 | let Pattern = pattern; |
| 86 | } |
| 87 | |
| 88 | // Almost all ARM instructions are predicable. |
| 89 | class I<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz, |
| 90 | IndexMode im, Format f, string opc, string asm, string cstr, |
| 91 | list<dag> pattern> |
| 92 | : InstARM<opcod, am, sz, im, f, cstr> { |
| 93 | let OutOperandList = oops; |
| 94 | let InOperandList = !con(iops, (ops pred:$p)); |
| 95 | let AsmString = !strconcat(opc, !strconcat("${p}", asm)); |
| 96 | let Pattern = pattern; |
| 97 | list<Predicate> Predicates = [IsARM]; |
| 98 | } |
| 99 | |
| 100 | // Same as I except it can optionally modify CPSR. Note it's modeled as |
| 101 | // an input operand since by default it's a zero register. It will |
| 102 | // become an implicit def once it's "flipped". |
| 103 | class sI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz, |
| 104 | IndexMode im, Format f, string opc, string asm, string cstr, |
| 105 | list<dag> pattern> |
| 106 | : InstARM<opcod, am, sz, im, f, cstr> { |
| 107 | let OutOperandList = oops; |
| 108 | let InOperandList = !con(iops, (ops pred:$p, cc_out:$s)); |
| 109 | let AsmString = !strconcat(opc, !strconcat("${p}${s}", asm)); |
| 110 | let Pattern = pattern; |
| 111 | list<Predicate> Predicates = [IsARM]; |
| 112 | } |
| 113 | |
| 114 | class AI<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 115 | string asm, list<dag> pattern> |
| 116 | : I<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, opc, |
| 117 | asm,"",pattern>; |
| 118 | class AsI<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 119 | string asm, list<dag> pattern> |
| 120 | : sI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, opc, |
| 121 | asm,"",pattern>; |
| 122 | class AI1<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 123 | string asm, list<dag> pattern> |
| 124 | : I<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc, |
| 125 | asm, "", pattern>; |
| 126 | class AsI1<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 127 | string asm, list<dag> pattern> |
| 128 | : sI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc, |
| 129 | asm, "", pattern>; |
| 130 | class AI2<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 131 | string asm, list<dag> pattern> |
| 132 | : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, opc, |
| 133 | asm, "", pattern>; |
| 134 | class AI3<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 135 | string asm, list<dag> pattern> |
| 136 | : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, opc, |
| 137 | asm, "", pattern>; |
| 138 | class AI4<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 139 | string asm, list<dag> pattern> |
| 140 | : I<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, opc, |
| 141 | asm, "", pattern>; |
| 142 | class AI1x2<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 143 | string asm, list<dag> pattern> |
| 144 | : I<opcod, oops, iops, AddrMode1, Size8Bytes, IndexModeNone, f, opc, |
| 145 | asm, "", pattern>; |
| 146 | |
| 147 | // Pre-indexed ops |
| 148 | class AI2pr<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 149 | string asm, string cstr, list<dag> pattern> |
| 150 | : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc, |
| 151 | asm, cstr, pattern>; |
| 152 | class AI3pr<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 153 | string asm, string cstr, list<dag> pattern> |
| 154 | : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePre, f, opc, |
| 155 | asm, cstr, pattern>; |
| 156 | |
| 157 | // Post-indexed ops |
| 158 | class AI2po<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 159 | string asm, string cstr, list<dag> pattern> |
| 160 | : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc, |
| 161 | asm, cstr,pattern>; |
| 162 | class AI3po<bits<4> opcod, dag oops, dag iops, Format f, string opc, |
| 163 | string asm, string cstr, list<dag> pattern> |
| 164 | : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePost, f, opc, |
| 165 | asm, cstr,pattern>; |
| 166 | |
| 167 | |
| 168 | // Special cases. |
| 169 | class XI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz, |
| 170 | IndexMode im, Format f, string asm, string cstr, list<dag> pattern> |
| 171 | : InstARM<opcod, am, sz, im, f, cstr> { |
| 172 | let OutOperandList = oops; |
| 173 | let InOperandList = iops; |
| 174 | let AsmString = asm; |
| 175 | let Pattern = pattern; |
| 176 | list<Predicate> Predicates = [IsARM]; |
| 177 | } |
| 178 | |
| 179 | class AXI<bits<4> opcod, dag oops, dag iops, Format f, string asm, |
| 180 | list<dag> pattern> |
| 181 | : XI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, asm, |
| 182 | "", pattern>; |
| 183 | class AXI1<bits<4> opcod, dag oops, dag iops, Format f, string asm, |
| 184 | list<dag> pattern> |
| 185 | : XI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, asm, |
| 186 | "", pattern>; |
| 187 | class AXI2<bits<4> opcod, dag oops, dag iops, Format f, string asm, |
| 188 | list<dag> pattern> |
| 189 | : XI<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, asm, |
| 190 | "", pattern>; |
| 191 | class AXI3<bits<4> opcod, dag oops, dag iops, Format f, string asm, |
| 192 | list<dag> pattern> |
| 193 | : XI<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, asm, |
| 194 | "", pattern>; |
| 195 | class AXI4<bits<4> opcod, dag oops, dag iops, Format f, string asm, |
| 196 | list<dag> pattern> |
| 197 | : XI<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, asm, |
| 198 | "", pattern>; |
| 199 | |
| 200 | class AXIx2<bits<4> opcod, dag oops, dag iops, Format f, string asm, |
| 201 | list<dag> pattern> |
| 202 | : XI<opcod, oops, iops, AddrModeNone, Size8Bytes, IndexModeNone, f, asm, |
| 203 | "", pattern>; |
| 204 | |
| 205 | // BR_JT instructions |
| 206 | class JTI<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern> |
| 207 | : XI<opcod, oops, iops, AddrModeNone, SizeSpecial, IndexModeNone, BranchMisc, |
| 208 | asm, "", pattern>; |
| 209 | class JTI1<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern> |
| 210 | : XI<opcod, oops, iops, AddrMode1, SizeSpecial, IndexModeNone, BranchMisc, |
| 211 | asm, "", pattern>; |
| 212 | class JTI2<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern> |
| 213 | : XI<opcod, oops, iops, AddrMode2, SizeSpecial, IndexModeNone, BranchMisc, |
| 214 | asm, "", pattern>; |
| 215 | |
| 216 | |
| 217 | //===----------------------------------------------------------------------===// |
| 218 | |
| 219 | // ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode. |
| 220 | class ARMPat<dag pattern, dag result> : Pat<pattern, result> { |
| 221 | list<Predicate> Predicates = [IsARM]; |
| 222 | } |
| 223 | class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> { |
| 224 | list<Predicate> Predicates = [IsARM, HasV5TE]; |
| 225 | } |
| 226 | class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> { |
| 227 | list<Predicate> Predicates = [IsARM, HasV6]; |
| 228 | } |
Evan Cheng | 34a46e1 | 2008-08-29 06:41:12 +0000 | [diff] [blame] | 229 | |
| 230 | //===----------------------------------------------------------------------===// |
| 231 | // |
| 232 | // Thumb Instruction Format Definitions. |
| 233 | // |
| 234 | |
| 235 | |
| 236 | // TI - Thumb instruction. |
| 237 | |
| 238 | class ThumbI<dag outs, dag ins, AddrMode am, SizeFlagVal sz, |
| 239 | string asm, string cstr, list<dag> pattern> |
| 240 | // FIXME: Set all opcodes to 0 for now. |
| 241 | : InstARM<0, am, sz, IndexModeNone, ThumbFrm, cstr> { |
| 242 | let OutOperandList = outs; |
| 243 | let InOperandList = ins; |
| 244 | let AsmString = asm; |
| 245 | let Pattern = pattern; |
| 246 | list<Predicate> Predicates = [IsThumb]; |
| 247 | } |
| 248 | |
| 249 | class TI<dag outs, dag ins, string asm, list<dag> pattern> |
| 250 | : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "", pattern>; |
| 251 | class TI1<dag outs, dag ins, string asm, list<dag> pattern> |
| 252 | : ThumbI<outs, ins, AddrModeT1, Size2Bytes, asm, "", pattern>; |
| 253 | class TI2<dag outs, dag ins, string asm, list<dag> pattern> |
| 254 | : ThumbI<outs, ins, AddrModeT2, Size2Bytes, asm, "", pattern>; |
| 255 | class TI4<dag outs, dag ins, string asm, list<dag> pattern> |
| 256 | : ThumbI<outs, ins, AddrModeT4, Size2Bytes, asm, "", pattern>; |
| 257 | class TIs<dag outs, dag ins, string asm, list<dag> pattern> |
| 258 | : ThumbI<outs, ins, AddrModeTs, Size2Bytes, asm, "", pattern>; |
| 259 | |
| 260 | // Two-address instructions |
| 261 | class TIt<dag outs, dag ins, string asm, list<dag> pattern> |
| 262 | : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "$lhs = $dst", pattern>; |
| 263 | |
| 264 | // BL, BLX(1) are translated by assembler into two instructions |
| 265 | class TIx2<dag outs, dag ins, string asm, list<dag> pattern> |
| 266 | : ThumbI<outs, ins, AddrModeNone, Size4Bytes, asm, "", pattern>; |
| 267 | |
| 268 | // BR_JT instructions |
| 269 | class TJTI<dag outs, dag ins, string asm, list<dag> pattern> |
| 270 | : ThumbI<outs, ins, AddrModeNone, SizeSpecial, asm, "", pattern>; |
| 271 | |
| 272 | |
| 273 | //===----------------------------------------------------------------------===// |
| 274 | |
| 275 | |
| 276 | // ThumbPat - Same as Pat<>, but requires that the compiler be in Thumb mode. |
| 277 | class ThumbPat<dag pattern, dag result> : Pat<pattern, result> { |
| 278 | list<Predicate> Predicates = [IsThumb]; |
| 279 | } |
| 280 | |
| 281 | class ThumbV5Pat<dag pattern, dag result> : Pat<pattern, result> { |
| 282 | list<Predicate> Predicates = [IsThumb, HasV5T]; |
| 283 | } |