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