Add AArch64 as an experimental target.
[oota-llvm.git] / lib / Target / AArch64 / MCTargetDesc / AArch64BaseInfo.h
1 //===-- AArch64BaseInfo.h - Top level definitions for AArch64- --*- C++ -*-===//
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 // This file contains small standalone helper functions and enum definitions for
11 // the AArch64 target useful for the compiler back-end and the MC libraries.
12 // As such, it deliberately does not include references to LLVM core
13 // code gen types, passes, etc..
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_AARCH64_BASEINFO_H
18 #define LLVM_AARCH64_BASEINFO_H
19
20 #include "AArch64MCTargetDesc.h"
21 #include "llvm/ADT/StringSwitch.h"
22 #include "llvm/ADT/STLExtras.h"
23 #include "llvm/Support/ErrorHandling.h"
24
25 namespace llvm {
26
27 // // Enums corresponding to AArch64 condition codes
28 namespace A64CC {
29   // The CondCodes constants map directly to the 4-bit encoding of the
30   // condition field for predicated instructions.
31   enum CondCodes {   // Meaning (integer)          Meaning (floating-point)
32     EQ = 0,        // Equal                      Equal
33     NE,            // Not equal                  Not equal, or unordered
34     HS,            // Unsigned higher or same    >, ==, or unordered
35     LO,            // Unsigned lower or same     Less than
36     MI,            // Minus, negative            Less than
37     PL,            // Plus, positive or zero     >, ==, or unordered
38     VS,            // Overflow                   Unordered
39     VC,            // No overflow                Ordered
40     HI,            // Unsigned higher            Greater than, or unordered
41     LS,            // Unsigned lower or same     Less than or equal
42     GE,            // Greater than or equal      Greater than or equal
43     LT,            // Less than                  Less than, or unordered
44     GT,            // Signed greater than        Greater than
45     LE,            // Signed less than or equal  <, ==, or unordered
46     AL,            // Always (unconditional)     Always (unconditional)
47     NV,             // Always (unconditional)     Always (unconditional)
48     // Note the NV exists purely to disassemble 0b1111. Execution
49     // is "always".
50     Invalid
51   };
52
53 } // namespace A64CC
54
55 inline static const char *A64CondCodeToString(A64CC::CondCodes CC) {
56   switch (CC) {
57   default: llvm_unreachable("Unknown condition code");
58   case A64CC::EQ:  return "eq";
59   case A64CC::NE:  return "ne";
60   case A64CC::HS:  return "hs";
61   case A64CC::LO:  return "lo";
62   case A64CC::MI:  return "mi";
63   case A64CC::PL:  return "pl";
64   case A64CC::VS:  return "vs";
65   case A64CC::VC:  return "vc";
66   case A64CC::HI:  return "hi";
67   case A64CC::LS:  return "ls";
68   case A64CC::GE:  return "ge";
69   case A64CC::LT:  return "lt";
70   case A64CC::GT:  return "gt";
71   case A64CC::LE:  return "le";
72   case A64CC::AL:  return "al";
73   case A64CC::NV:  return "nv";
74   }
75 }
76
77 inline static A64CC::CondCodes A64StringToCondCode(StringRef CondStr) {
78   return StringSwitch<A64CC::CondCodes>(CondStr.lower())
79              .Case("eq", A64CC::EQ)
80              .Case("ne", A64CC::NE)
81              .Case("ne", A64CC::NE)
82              .Case("hs", A64CC::HS)
83              .Case("cs", A64CC::HS)
84              .Case("lo", A64CC::LO)
85              .Case("cc", A64CC::LO)
86              .Case("mi", A64CC::MI)
87              .Case("pl", A64CC::PL)
88              .Case("vs", A64CC::VS)
89              .Case("vc", A64CC::VC)
90              .Case("hi", A64CC::HI)
91              .Case("ls", A64CC::LS)
92              .Case("ge", A64CC::GE)
93              .Case("lt", A64CC::LT)
94              .Case("gt", A64CC::GT)
95              .Case("le", A64CC::LE)
96              .Case("al", A64CC::AL)
97              .Case("nv", A64CC::NV)
98              .Default(A64CC::Invalid);
99 }
100
101 inline static A64CC::CondCodes A64InvertCondCode(A64CC::CondCodes CC) {
102   // It turns out that the condition codes have been designed so that in order
103   // to reverse the intent of the condition you only have to invert the low bit:
104
105   return static_cast<A64CC::CondCodes>(static_cast<unsigned>(CC) ^ 0x1);
106 }
107
108 /// Instances of this class can perform bidirectional mapping from random
109 /// identifier strings to operand encodings. For example "MSR" takes a named
110 /// system-register which must be encoded somehow and decoded for printing. This
111 /// central location means that the information for those transformations is not
112 /// duplicated and remains in sync.
113 ///
114 /// FIXME: currently the algorithm is a completely unoptimised linear
115 /// search. Obviously this could be improved, but we would probably want to work
116 /// out just how often these instructions are emitted before working on it. It
117 /// might even be optimal to just reorder the tables for the common instructions
118 /// rather than changing the algorithm.
119 struct NamedImmMapper {
120   struct Mapping {
121     const char *Name;
122     uint32_t Value;
123   };
124
125   template<int N>
126   NamedImmMapper(const Mapping (&Pairs)[N], uint32_t TooBigImm)
127     : Pairs(&Pairs[0]), NumPairs(N), TooBigImm(TooBigImm) {}
128
129   StringRef toString(uint32_t Value, bool &Valid) const;
130   uint32_t fromString(StringRef Name, bool &Valid) const;
131
132   /// Many of the instructions allow an alternative assembly form consisting of
133   /// a simple immediate. Currently the only valid forms are ranges [0, N) where
134   /// N being 0 indicates no immediate syntax-form is allowed.
135   bool validImm(uint32_t Value) const;
136 protected:
137   const Mapping *Pairs;
138   size_t NumPairs;
139   uint32_t TooBigImm;
140 };
141
142 namespace A64AT {
143   enum ATValues {
144     Invalid = -1,    // Op0 Op1  CRn   CRm   Op2
145     S1E1R = 0x43c0,  // 01  000  0111  1000  000
146     S1E2R = 0x63c0,  // 01  100  0111  1000  000
147     S1E3R = 0x73c0,  // 01  110  0111  1000  000
148     S1E1W = 0x43c1,  // 01  000  0111  1000  001
149     S1E2W = 0x63c1,  // 01  100  0111  1000  001
150     S1E3W = 0x73c1,  // 01  110  0111  1000  001
151     S1E0R = 0x43c2,  // 01  000  0111  1000  010
152     S1E0W = 0x43c3,  // 01  000  0111  1000  011
153     S12E1R = 0x63c4, // 01  100  0111  1000  100
154     S12E1W = 0x63c5, // 01  100  0111  1000  101
155     S12E0R = 0x63c6, // 01  100  0111  1000  110
156     S12E0W = 0x63c7  // 01  100  0111  1000  111
157   };
158
159   struct ATMapper : NamedImmMapper {
160     const static Mapping ATPairs[];
161
162     ATMapper();
163   };
164
165 }
166 namespace A64DB {
167   enum DBValues {
168     Invalid = -1,
169     OSHLD = 0x1,
170     OSHST = 0x2,
171     OSH =   0x3,
172     NSHLD = 0x5,
173     NSHST = 0x6,
174     NSH =   0x7,
175     ISHLD = 0x9,
176     ISHST = 0xa,
177     ISH =   0xb,
178     LD =    0xd,
179     ST =    0xe,
180     SY =    0xf
181   };
182
183   struct DBarrierMapper : NamedImmMapper {
184     const static Mapping DBarrierPairs[];
185
186     DBarrierMapper();
187   };
188 }
189
190 namespace  A64DC {
191   enum DCValues {
192     Invalid = -1,   // Op1  CRn   CRm   Op2
193     ZVA   = 0x5ba1, // 01  011  0111  0100  001
194     IVAC  = 0x43b1, // 01  000  0111  0110  001
195     ISW   = 0x43b2, // 01  000  0111  0110  010
196     CVAC  = 0x5bd1, // 01  011  0111  1010  001
197     CSW   = 0x43d2, // 01  000  0111  1010  010
198     CVAU  = 0x5bd9, // 01  011  0111  1011  001
199     CIVAC = 0x5bf1, // 01  011  0111  1110  001
200     CISW  = 0x43f2  // 01  000  0111  1110  010
201   };
202
203   struct DCMapper : NamedImmMapper {
204     const static Mapping DCPairs[];
205
206     DCMapper();
207   };
208
209 }
210
211 namespace  A64IC {
212   enum ICValues {
213     Invalid = -1,     // Op1  CRn   CRm   Op2
214     IALLUIS = 0x0388, // 000  0111  0001  000
215     IALLU = 0x03a8,   // 000  0111  0101  000
216     IVAU = 0x1ba9     // 011  0111  0101  001
217   };
218
219
220   struct ICMapper : NamedImmMapper {
221     const static Mapping ICPairs[];
222
223     ICMapper();
224   };
225
226   static inline bool NeedsRegister(ICValues Val) {
227     return Val == IVAU;
228   }
229 }
230
231 namespace  A64ISB {
232   enum ISBValues {
233     Invalid = -1,
234     SY = 0xf
235   };
236   struct ISBMapper : NamedImmMapper {
237     const static Mapping ISBPairs[];
238
239     ISBMapper();
240   };
241 }
242
243 namespace A64PRFM {
244   enum PRFMValues {
245     Invalid = -1,
246     PLDL1KEEP = 0x00,
247     PLDL1STRM = 0x01,
248     PLDL2KEEP = 0x02,
249     PLDL2STRM = 0x03,
250     PLDL3KEEP = 0x04,
251     PLDL3STRM = 0x05,
252     PSTL1KEEP = 0x10,
253     PSTL1STRM = 0x11,
254     PSTL2KEEP = 0x12,
255     PSTL2STRM = 0x13,
256     PSTL3KEEP = 0x14,
257     PSTL3STRM = 0x15
258   };
259
260   struct PRFMMapper : NamedImmMapper {
261     const static Mapping PRFMPairs[];
262
263     PRFMMapper();
264   };
265 }
266
267 namespace A64PState {
268   enum PStateValues {
269     Invalid = -1,
270     SPSel = 0x05,
271     DAIFSet = 0x1e,
272     DAIFClr = 0x1f
273   };
274
275   struct PStateMapper : NamedImmMapper {
276     const static Mapping PStatePairs[];
277
278     PStateMapper();
279   };
280
281 }
282
283 namespace A64SE {
284     enum ShiftExtSpecifiers {
285         Invalid = -1,
286         LSL,
287         LSR,
288         ASR,
289         ROR,
290
291         UXTB,
292         UXTH,
293         UXTW,
294         UXTX,
295
296         SXTB,
297         SXTH,
298         SXTW,
299         SXTX
300     };
301 }
302
303 namespace A64SysReg {
304   enum SysRegROValues {
305     MDCCSR_EL0        = 0x9808, // 10  011  0000  0001  000
306     DBGDTRRX_EL0      = 0x9828, // 10  011  0000  0101  000
307     MDRAR_EL1         = 0x8080, // 10  000  0001  0000  000
308     OSLSR_EL1         = 0x808c, // 10  000  0001  0001  100
309     DBGAUTHSTATUS_EL1 = 0x83f6, // 10  000  0111  1110  110
310     PMCEID0_EL0       = 0xdce6, // 11  011  1001  1100  110
311     PMCEID1_EL0       = 0xdce7, // 11  011  1001  1100  111
312     MIDR_EL1          = 0xc000, // 11  000  0000  0000  000
313     CCSIDR_EL1        = 0xc800, // 11  001  0000  0000  000
314     CLIDR_EL1         = 0xc801, // 11  001  0000  0000  001
315     CTR_EL0           = 0xd801, // 11  011  0000  0000  001
316     MPIDR_EL1         = 0xc005, // 11  000  0000  0000  101
317     REVIDR_EL1        = 0xc006, // 11  000  0000  0000  110
318     AIDR_EL1          = 0xc807, // 11  001  0000  0000  111
319     DCZID_EL0         = 0xd807, // 11  011  0000  0000  111
320     ID_PFR0_EL1       = 0xc008, // 11  000  0000  0001  000
321     ID_PFR1_EL1       = 0xc009, // 11  000  0000  0001  001
322     ID_DFR0_EL1       = 0xc00a, // 11  000  0000  0001  010
323     ID_AFR0_EL1       = 0xc00b, // 11  000  0000  0001  011
324     ID_MMFR0_EL1      = 0xc00c, // 11  000  0000  0001  100
325     ID_MMFR1_EL1      = 0xc00d, // 11  000  0000  0001  101
326     ID_MMFR2_EL1      = 0xc00e, // 11  000  0000  0001  110
327     ID_MMFR3_EL1      = 0xc00f, // 11  000  0000  0001  111
328     ID_ISAR0_EL1      = 0xc010, // 11  000  0000  0010  000
329     ID_ISAR1_EL1      = 0xc011, // 11  000  0000  0010  001
330     ID_ISAR2_EL1      = 0xc012, // 11  000  0000  0010  010
331     ID_ISAR3_EL1      = 0xc013, // 11  000  0000  0010  011
332     ID_ISAR4_EL1      = 0xc014, // 11  000  0000  0010  100
333     ID_ISAR5_EL1      = 0xc015, // 11  000  0000  0010  101
334     ID_AA64PFR0_EL1   = 0xc020, // 11  000  0000  0100  000
335     ID_AA64PFR1_EL1   = 0xc021, // 11  000  0000  0100  001
336     ID_AA64DFR0_EL1   = 0xc028, // 11  000  0000  0101  000
337     ID_AA64DFR1_EL1   = 0xc029, // 11  000  0000  0101  001
338     ID_AA64AFR0_EL1   = 0xc02c, // 11  000  0000  0101  100
339     ID_AA64AFR1_EL1   = 0xc02d, // 11  000  0000  0101  101
340     ID_AA64ISAR0_EL1  = 0xc030, // 11  000  0000  0110  000
341     ID_AA64ISAR1_EL1  = 0xc031, // 11  000  0000  0110  001
342     ID_AA64MMFR0_EL1  = 0xc038, // 11  000  0000  0111  000
343     ID_AA64MMFR1_EL1  = 0xc039, // 11  000  0000  0111  001
344     MVFR0_EL1         = 0xc018, // 11  000  0000  0011  000
345     MVFR1_EL1         = 0xc019, // 11  000  0000  0011  001
346     MVFR2_EL1         = 0xc01a, // 11  000  0000  0011  010
347     RVBAR_EL1         = 0xc601, // 11  000  1100  0000  001
348     RVBAR_EL2         = 0xe601, // 11  100  1100  0000  001
349     RVBAR_EL3         = 0xf601, // 11  110  1100  0000  001
350     ISR_EL1           = 0xc608, // 11  000  1100  0001  000
351     CNTPCT_EL0        = 0xdf01, // 11  011  1110  0000  001
352     CNTVCT_EL0        = 0xdf02  // 11  011  1110  0000  010
353   };
354
355   enum SysRegWOValues {
356     DBGDTRTX_EL0      = 0x9828, // 10  011  0000  0101  000
357     OSLAR_EL1         = 0x8084, // 10  000  0001  0000  100
358     PMSWINC_EL0       = 0xdce4  // 11  011  1001  1100  100
359   };
360
361   enum SysRegValues {
362     Invalid = -1,               // Op0 Op1  CRn   CRm   Op2
363     OSDTRRX_EL1       = 0x8002, // 10  000  0000  0000  010
364     OSDTRTX_EL1       = 0x801a, // 10  000  0000  0011  010
365     TEECR32_EL1       = 0x9000, // 10  010  0000  0000  000
366     MDCCINT_EL1       = 0x8010, // 10  000  0000  0010  000
367     MDSCR_EL1         = 0x8012, // 10  000  0000  0010  010
368     DBGDTR_EL0        = 0x9820, // 10  011  0000  0100  000
369     OSECCR_EL1        = 0x8032, // 10  000  0000  0110  010
370     DBGVCR32_EL2      = 0xa038, // 10  100  0000  0111  000
371     DBGBVR0_EL1       = 0x8004, // 10  000  0000  0000  100
372     DBGBVR1_EL1       = 0x800c, // 10  000  0000  0001  100
373     DBGBVR2_EL1       = 0x8014, // 10  000  0000  0010  100
374     DBGBVR3_EL1       = 0x801c, // 10  000  0000  0011  100
375     DBGBVR4_EL1       = 0x8024, // 10  000  0000  0100  100
376     DBGBVR5_EL1       = 0x802c, // 10  000  0000  0101  100
377     DBGBVR6_EL1       = 0x8034, // 10  000  0000  0110  100
378     DBGBVR7_EL1       = 0x803c, // 10  000  0000  0111  100
379     DBGBVR8_EL1       = 0x8044, // 10  000  0000  1000  100
380     DBGBVR9_EL1       = 0x804c, // 10  000  0000  1001  100
381     DBGBVR10_EL1      = 0x8054, // 10  000  0000  1010  100
382     DBGBVR11_EL1      = 0x805c, // 10  000  0000  1011  100
383     DBGBVR12_EL1      = 0x8064, // 10  000  0000  1100  100
384     DBGBVR13_EL1      = 0x806c, // 10  000  0000  1101  100
385     DBGBVR14_EL1      = 0x8074, // 10  000  0000  1110  100
386     DBGBVR15_EL1      = 0x807c, // 10  000  0000  1111  100
387     DBGBCR0_EL1       = 0x8005, // 10  000  0000  0000  101
388     DBGBCR1_EL1       = 0x800d, // 10  000  0000  0001  101
389     DBGBCR2_EL1       = 0x8015, // 10  000  0000  0010  101
390     DBGBCR3_EL1       = 0x801d, // 10  000  0000  0011  101
391     DBGBCR4_EL1       = 0x8025, // 10  000  0000  0100  101
392     DBGBCR5_EL1       = 0x802d, // 10  000  0000  0101  101
393     DBGBCR6_EL1       = 0x8035, // 10  000  0000  0110  101
394     DBGBCR7_EL1       = 0x803d, // 10  000  0000  0111  101
395     DBGBCR8_EL1       = 0x8045, // 10  000  0000  1000  101
396     DBGBCR9_EL1       = 0x804d, // 10  000  0000  1001  101
397     DBGBCR10_EL1      = 0x8055, // 10  000  0000  1010  101
398     DBGBCR11_EL1      = 0x805d, // 10  000  0000  1011  101
399     DBGBCR12_EL1      = 0x8065, // 10  000  0000  1100  101
400     DBGBCR13_EL1      = 0x806d, // 10  000  0000  1101  101
401     DBGBCR14_EL1      = 0x8075, // 10  000  0000  1110  101
402     DBGBCR15_EL1      = 0x807d, // 10  000  0000  1111  101
403     DBGWVR0_EL1       = 0x8006, // 10  000  0000  0000  110
404     DBGWVR1_EL1       = 0x800e, // 10  000  0000  0001  110
405     DBGWVR2_EL1       = 0x8016, // 10  000  0000  0010  110
406     DBGWVR3_EL1       = 0x801e, // 10  000  0000  0011  110
407     DBGWVR4_EL1       = 0x8026, // 10  000  0000  0100  110
408     DBGWVR5_EL1       = 0x802e, // 10  000  0000  0101  110
409     DBGWVR6_EL1       = 0x8036, // 10  000  0000  0110  110
410     DBGWVR7_EL1       = 0x803e, // 10  000  0000  0111  110
411     DBGWVR8_EL1       = 0x8046, // 10  000  0000  1000  110
412     DBGWVR9_EL1       = 0x804e, // 10  000  0000  1001  110
413     DBGWVR10_EL1      = 0x8056, // 10  000  0000  1010  110
414     DBGWVR11_EL1      = 0x805e, // 10  000  0000  1011  110
415     DBGWVR12_EL1      = 0x8066, // 10  000  0000  1100  110
416     DBGWVR13_EL1      = 0x806e, // 10  000  0000  1101  110
417     DBGWVR14_EL1      = 0x8076, // 10  000  0000  1110  110
418     DBGWVR15_EL1      = 0x807e, // 10  000  0000  1111  110
419     DBGWCR0_EL1       = 0x8007, // 10  000  0000  0000  111
420     DBGWCR1_EL1       = 0x800f, // 10  000  0000  0001  111
421     DBGWCR2_EL1       = 0x8017, // 10  000  0000  0010  111
422     DBGWCR3_EL1       = 0x801f, // 10  000  0000  0011  111
423     DBGWCR4_EL1       = 0x8027, // 10  000  0000  0100  111
424     DBGWCR5_EL1       = 0x802f, // 10  000  0000  0101  111
425     DBGWCR6_EL1       = 0x8037, // 10  000  0000  0110  111
426     DBGWCR7_EL1       = 0x803f, // 10  000  0000  0111  111
427     DBGWCR8_EL1       = 0x8047, // 10  000  0000  1000  111
428     DBGWCR9_EL1       = 0x804f, // 10  000  0000  1001  111
429     DBGWCR10_EL1      = 0x8057, // 10  000  0000  1010  111
430     DBGWCR11_EL1      = 0x805f, // 10  000  0000  1011  111
431     DBGWCR12_EL1      = 0x8067, // 10  000  0000  1100  111
432     DBGWCR13_EL1      = 0x806f, // 10  000  0000  1101  111
433     DBGWCR14_EL1      = 0x8077, // 10  000  0000  1110  111
434     DBGWCR15_EL1      = 0x807f, // 10  000  0000  1111  111
435     TEEHBR32_EL1      = 0x9080, // 10  010  0001  0000  000
436     OSDLR_EL1         = 0x809c, // 10  000  0001  0011  100
437     DBGPRCR_EL1       = 0x80a4, // 10  000  0001  0100  100
438     DBGCLAIMSET_EL1   = 0x83c6, // 10  000  0111  1000  110
439     DBGCLAIMCLR_EL1   = 0x83ce, // 10  000  0111  1001  110
440     CSSELR_EL1        = 0xd000, // 11  010  0000  0000  000
441     VPIDR_EL2         = 0xe000, // 11  100  0000  0000  000
442     VMPIDR_EL2        = 0xe005, // 11  100  0000  0000  101
443     CPACR_EL1         = 0xc082, // 11  000  0001  0000  010
444     SCTLR_EL1         = 0xc080, // 11  000  0001  0000  000
445     SCTLR_EL2         = 0xe080, // 11  100  0001  0000  000
446     SCTLR_EL3         = 0xf080, // 11  110  0001  0000  000
447     ACTLR_EL1         = 0xc081, // 11  000  0001  0000  001
448     ACTLR_EL2         = 0xe081, // 11  100  0001  0000  001
449     ACTLR_EL3         = 0xf081, // 11  110  0001  0000  001
450     HCR_EL2           = 0xe088, // 11  100  0001  0001  000
451     SCR_EL3           = 0xf088, // 11  110  0001  0001  000
452     MDCR_EL2          = 0xe089, // 11  100  0001  0001  001
453     SDER32_EL3        = 0xf089, // 11  110  0001  0001  001
454     CPTR_EL2          = 0xe08a, // 11  100  0001  0001  010
455     CPTR_EL3          = 0xf08a, // 11  110  0001  0001  010
456     HSTR_EL2          = 0xe08b, // 11  100  0001  0001  011
457     HACR_EL2          = 0xe08f, // 11  100  0001  0001  111
458     MDCR_EL3          = 0xf099, // 11  110  0001  0011  001
459     TTBR0_EL1         = 0xc100, // 11  000  0010  0000  000
460     TTBR0_EL2         = 0xe100, // 11  100  0010  0000  000
461     TTBR0_EL3         = 0xf100, // 11  110  0010  0000  000
462     TTBR1_EL1         = 0xc101, // 11  000  0010  0000  001
463     TCR_EL1           = 0xc102, // 11  000  0010  0000  010
464     TCR_EL2           = 0xe102, // 11  100  0010  0000  010
465     TCR_EL3           = 0xf102, // 11  110  0010  0000  010
466     VTTBR_EL2         = 0xe108, // 11  100  0010  0001  000
467     VTCR_EL2          = 0xe10a, // 11  100  0010  0001  010
468     DACR32_EL2        = 0xe180, // 11  100  0011  0000  000
469     SPSR_EL1          = 0xc200, // 11  000  0100  0000  000
470     SPSR_EL2          = 0xe200, // 11  100  0100  0000  000
471     SPSR_EL3          = 0xf200, // 11  110  0100  0000  000
472     ELR_EL1           = 0xc201, // 11  000  0100  0000  001
473     ELR_EL2           = 0xe201, // 11  100  0100  0000  001
474     ELR_EL3           = 0xf201, // 11  110  0100  0000  001
475     SP_EL0            = 0xc208, // 11  000  0100  0001  000
476     SP_EL1            = 0xe208, // 11  100  0100  0001  000
477     SP_EL2            = 0xf208, // 11  110  0100  0001  000
478     SPSel             = 0xc210, // 11  000  0100  0010  000
479     NZCV              = 0xda10, // 11  011  0100  0010  000
480     DAIF              = 0xda11, // 11  011  0100  0010  001
481     CurrentEL         = 0xc212, // 11  000  0100  0010  010
482     SPSR_irq          = 0xe218, // 11  100  0100  0011  000
483     SPSR_abt          = 0xe219, // 11  100  0100  0011  001
484     SPSR_und          = 0xe21a, // 11  100  0100  0011  010
485     SPSR_fiq          = 0xe21b, // 11  100  0100  0011  011
486     FPCR              = 0xda20, // 11  011  0100  0100  000
487     FPSR              = 0xda21, // 11  011  0100  0100  001
488     DSPSR_EL0         = 0xda28, // 11  011  0100  0101  000
489     DLR_EL0           = 0xda29, // 11  011  0100  0101  001
490     IFSR32_EL2        = 0xe281, // 11  100  0101  0000  001
491     AFSR0_EL1         = 0xc288, // 11  000  0101  0001  000
492     AFSR0_EL2         = 0xe288, // 11  100  0101  0001  000
493     AFSR0_EL3         = 0xf288, // 11  110  0101  0001  000
494     AFSR1_EL1         = 0xc289, // 11  000  0101  0001  001
495     AFSR1_EL2         = 0xe289, // 11  100  0101  0001  001
496     AFSR1_EL3         = 0xf289, // 11  110  0101  0001  001
497     ESR_EL1           = 0xc290, // 11  000  0101  0010  000
498     ESR_EL2           = 0xe290, // 11  100  0101  0010  000
499     ESR_EL3           = 0xf290, // 11  110  0101  0010  000
500     FPEXC32_EL2       = 0xe298, // 11  100  0101  0011  000
501     FAR_EL1           = 0xc300, // 11  000  0110  0000  000
502     FAR_EL2           = 0xe300, // 11  100  0110  0000  000
503     FAR_EL3           = 0xf300, // 11  110  0110  0000  000
504     HPFAR_EL2         = 0xe304, // 11  100  0110  0000  100
505     PAR_EL1           = 0xc3a0, // 11  000  0111  0100  000
506     PMCR_EL0          = 0xdce0, // 11  011  1001  1100  000
507     PMCNTENSET_EL0    = 0xdce1, // 11  011  1001  1100  001
508     PMCNTENCLR_EL0    = 0xdce2, // 11  011  1001  1100  010
509     PMOVSCLR_EL0      = 0xdce3, // 11  011  1001  1100  011
510     PMSELR_EL0        = 0xdce5, // 11  011  1001  1100  101
511     PMCCNTR_EL0       = 0xdce8, // 11  011  1001  1101  000
512     PMXEVTYPER_EL0    = 0xdce9, // 11  011  1001  1101  001
513     PMXEVCNTR_EL0     = 0xdcea, // 11  011  1001  1101  010
514     PMUSERENR_EL0     = 0xdcf0, // 11  011  1001  1110  000
515     PMINTENSET_EL1    = 0xc4f1, // 11  000  1001  1110  001
516     PMINTENCLR_EL1    = 0xc4f2, // 11  000  1001  1110  010
517     PMOVSSET_EL0      = 0xdcf3, // 11  011  1001  1110  011
518     MAIR_EL1          = 0xc510, // 11  000  1010  0010  000
519     MAIR_EL2          = 0xe510, // 11  100  1010  0010  000
520     MAIR_EL3          = 0xf510, // 11  110  1010  0010  000
521     AMAIR_EL1         = 0xc518, // 11  000  1010  0011  000
522     AMAIR_EL2         = 0xe518, // 11  100  1010  0011  000
523     AMAIR_EL3         = 0xf518, // 11  110  1010  0011  000
524     VBAR_EL1          = 0xc600, // 11  000  1100  0000  000
525     VBAR_EL2          = 0xe600, // 11  100  1100  0000  000
526     VBAR_EL3          = 0xf600, // 11  110  1100  0000  000
527     RMR_EL1           = 0xc602, // 11  000  1100  0000  010
528     RMR_EL2           = 0xe602, // 11  100  1100  0000  010
529     RMR_EL3           = 0xf602, // 11  110  1100  0000  010
530     CONTEXTIDR_EL1    = 0xc681, // 11  000  1101  0000  001
531     TPIDR_EL0         = 0xde82, // 11  011  1101  0000  010
532     TPIDR_EL2         = 0xe682, // 11  100  1101  0000  010
533     TPIDR_EL3         = 0xf682, // 11  110  1101  0000  010
534     TPIDRRO_EL0       = 0xde83, // 11  011  1101  0000  011
535     TPIDR_EL1         = 0xc684, // 11  000  1101  0000  100
536     CNTFRQ_EL0        = 0xdf00, // 11  011  1110  0000  000
537     CNTVOFF_EL2       = 0xe703, // 11  100  1110  0000  011
538     CNTKCTL_EL1       = 0xc708, // 11  000  1110  0001  000
539     CNTHCTL_EL2       = 0xe708, // 11  100  1110  0001  000
540     CNTP_TVAL_EL0     = 0xdf10, // 11  011  1110  0010  000
541     CNTHP_TVAL_EL2    = 0xe710, // 11  100  1110  0010  000
542     CNTPS_TVAL_EL1    = 0xff10, // 11  111  1110  0010  000
543     CNTP_CTL_EL0      = 0xdf11, // 11  011  1110  0010  001
544     CNTHP_CTL_EL2     = 0xe711, // 11  100  1110  0010  001
545     CNTPS_CTL_EL1     = 0xff11, // 11  111  1110  0010  001
546     CNTP_CVAL_EL0     = 0xdf12, // 11  011  1110  0010  010
547     CNTHP_CVAL_EL2    = 0xe712, // 11  100  1110  0010  010
548     CNTPS_CVAL_EL1    = 0xff12, // 11  111  1110  0010  010
549     CNTV_TVAL_EL0     = 0xdf18, // 11  011  1110  0011  000
550     CNTV_CTL_EL0      = 0xdf19, // 11  011  1110  0011  001
551     CNTV_CVAL_EL0     = 0xdf1a, // 11  011  1110  0011  010
552     PMEVCNTR0_EL0     = 0xdf40, // 11  011  1110  1000  000
553     PMEVCNTR1_EL0     = 0xdf41, // 11  011  1110  1000  001
554     PMEVCNTR2_EL0     = 0xdf42, // 11  011  1110  1000  010
555     PMEVCNTR3_EL0     = 0xdf43, // 11  011  1110  1000  011
556     PMEVCNTR4_EL0     = 0xdf44, // 11  011  1110  1000  100
557     PMEVCNTR5_EL0     = 0xdf45, // 11  011  1110  1000  101
558     PMEVCNTR6_EL0     = 0xdf46, // 11  011  1110  1000  110
559     PMEVCNTR7_EL0     = 0xdf47, // 11  011  1110  1000  111
560     PMEVCNTR8_EL0     = 0xdf48, // 11  011  1110  1001  000
561     PMEVCNTR9_EL0     = 0xdf49, // 11  011  1110  1001  001
562     PMEVCNTR10_EL0    = 0xdf4a, // 11  011  1110  1001  010
563     PMEVCNTR11_EL0    = 0xdf4b, // 11  011  1110  1001  011
564     PMEVCNTR12_EL0    = 0xdf4c, // 11  011  1110  1001  100
565     PMEVCNTR13_EL0    = 0xdf4d, // 11  011  1110  1001  101
566     PMEVCNTR14_EL0    = 0xdf4e, // 11  011  1110  1001  110
567     PMEVCNTR15_EL0    = 0xdf4f, // 11  011  1110  1001  111
568     PMEVCNTR16_EL0    = 0xdf50, // 11  011  1110  1010  000
569     PMEVCNTR17_EL0    = 0xdf51, // 11  011  1110  1010  001
570     PMEVCNTR18_EL0    = 0xdf52, // 11  011  1110  1010  010
571     PMEVCNTR19_EL0    = 0xdf53, // 11  011  1110  1010  011
572     PMEVCNTR20_EL0    = 0xdf54, // 11  011  1110  1010  100
573     PMEVCNTR21_EL0    = 0xdf55, // 11  011  1110  1010  101
574     PMEVCNTR22_EL0    = 0xdf56, // 11  011  1110  1010  110
575     PMEVCNTR23_EL0    = 0xdf57, // 11  011  1110  1010  111
576     PMEVCNTR24_EL0    = 0xdf58, // 11  011  1110  1011  000
577     PMEVCNTR25_EL0    = 0xdf59, // 11  011  1110  1011  001
578     PMEVCNTR26_EL0    = 0xdf5a, // 11  011  1110  1011  010
579     PMEVCNTR27_EL0    = 0xdf5b, // 11  011  1110  1011  011
580     PMEVCNTR28_EL0    = 0xdf5c, // 11  011  1110  1011  100
581     PMEVCNTR29_EL0    = 0xdf5d, // 11  011  1110  1011  101
582     PMEVCNTR30_EL0    = 0xdf5e, // 11  011  1110  1011  110
583     PMCCFILTR_EL0     = 0xdf7f, // 11  011  1110  1111  111
584     PMEVTYPER0_EL0    = 0xdf60, // 11  011  1110  1100  000
585     PMEVTYPER1_EL0    = 0xdf61, // 11  011  1110  1100  001
586     PMEVTYPER2_EL0    = 0xdf62, // 11  011  1110  1100  010
587     PMEVTYPER3_EL0    = 0xdf63, // 11  011  1110  1100  011
588     PMEVTYPER4_EL0    = 0xdf64, // 11  011  1110  1100  100
589     PMEVTYPER5_EL0    = 0xdf65, // 11  011  1110  1100  101
590     PMEVTYPER6_EL0    = 0xdf66, // 11  011  1110  1100  110
591     PMEVTYPER7_EL0    = 0xdf67, // 11  011  1110  1100  111
592     PMEVTYPER8_EL0    = 0xdf68, // 11  011  1110  1101  000
593     PMEVTYPER9_EL0    = 0xdf69, // 11  011  1110  1101  001
594     PMEVTYPER10_EL0   = 0xdf6a, // 11  011  1110  1101  010
595     PMEVTYPER11_EL0   = 0xdf6b, // 11  011  1110  1101  011
596     PMEVTYPER12_EL0   = 0xdf6c, // 11  011  1110  1101  100
597     PMEVTYPER13_EL0   = 0xdf6d, // 11  011  1110  1101  101
598     PMEVTYPER14_EL0   = 0xdf6e, // 11  011  1110  1101  110
599     PMEVTYPER15_EL0   = 0xdf6f, // 11  011  1110  1101  111
600     PMEVTYPER16_EL0   = 0xdf70, // 11  011  1110  1110  000
601     PMEVTYPER17_EL0   = 0xdf71, // 11  011  1110  1110  001
602     PMEVTYPER18_EL0   = 0xdf72, // 11  011  1110  1110  010
603     PMEVTYPER19_EL0   = 0xdf73, // 11  011  1110  1110  011
604     PMEVTYPER20_EL0   = 0xdf74, // 11  011  1110  1110  100
605     PMEVTYPER21_EL0   = 0xdf75, // 11  011  1110  1110  101
606     PMEVTYPER22_EL0   = 0xdf76, // 11  011  1110  1110  110
607     PMEVTYPER23_EL0   = 0xdf77, // 11  011  1110  1110  111
608     PMEVTYPER24_EL0   = 0xdf78, // 11  011  1110  1111  000
609     PMEVTYPER25_EL0   = 0xdf79, // 11  011  1110  1111  001
610     PMEVTYPER26_EL0   = 0xdf7a, // 11  011  1110  1111  010
611     PMEVTYPER27_EL0   = 0xdf7b, // 11  011  1110  1111  011
612     PMEVTYPER28_EL0   = 0xdf7c, // 11  011  1110  1111  100
613     PMEVTYPER29_EL0   = 0xdf7d, // 11  011  1110  1111  101
614     PMEVTYPER30_EL0   = 0xdf7e  // 11  011  1110  1111  110
615   };
616
617   // Note that these do not inherit from NamedImmMapper. This class is
618   // sufficiently different in its behaviour that I don't believe it's worth
619   // burdening the common NamedImmMapper with abstractions only needed in
620   // this one case.
621   struct SysRegMapper {
622     static const NamedImmMapper::Mapping SysRegPairs[];
623
624     const NamedImmMapper::Mapping *InstPairs;
625     size_t NumInstPairs;
626
627     SysRegMapper() {}
628     uint32_t fromString(StringRef Name, bool &Valid) const;
629     std::string toString(uint32_t Bits, bool &Valid) const;
630   };
631
632   struct MSRMapper : SysRegMapper {
633     static const NamedImmMapper::Mapping MSRPairs[];
634     MSRMapper();
635   };
636
637   struct MRSMapper : SysRegMapper {
638     static const NamedImmMapper::Mapping MRSPairs[];
639     MRSMapper();
640   };
641
642   uint32_t ParseGenericRegister(StringRef Name, bool &Valid);
643 }
644
645 namespace A64TLBI {
646   enum TLBIValues {
647     Invalid = -1,          // Op0 Op1  CRn   CRm   Op2
648     IPAS2E1IS    = 0x6401, // 01  100  1000  0000  001
649     IPAS2LE1IS   = 0x6405, // 01  100  1000  0000  101
650     VMALLE1IS    = 0x4418, // 01  000  1000  0011  000
651     ALLE2IS      = 0x6418, // 01  100  1000  0011  000
652     ALLE3IS      = 0x7418, // 01  110  1000  0011  000
653     VAE1IS       = 0x4419, // 01  000  1000  0011  001
654     VAE2IS       = 0x6419, // 01  100  1000  0011  001
655     VAE3IS       = 0x7419, // 01  110  1000  0011  001
656     ASIDE1IS     = 0x441a, // 01  000  1000  0011  010
657     VAAE1IS      = 0x441b, // 01  000  1000  0011  011
658     ALLE1IS      = 0x641c, // 01  100  1000  0011  100
659     VALE1IS      = 0x441d, // 01  000  1000  0011  101
660     VALE2IS      = 0x641d, // 01  100  1000  0011  101
661     VALE3IS      = 0x741d, // 01  110  1000  0011  101
662     VMALLS12E1IS = 0x641e, // 01  100  1000  0011  110
663     VAALE1IS     = 0x441f, // 01  000  1000  0011  111
664     IPAS2E1      = 0x6421, // 01  100  1000  0100  001
665     IPAS2LE1     = 0x6425, // 01  100  1000  0100  101
666     VMALLE1      = 0x4438, // 01  000  1000  0111  000
667     ALLE2        = 0x6438, // 01  100  1000  0111  000
668     ALLE3        = 0x7438, // 01  110  1000  0111  000
669     VAE1         = 0x4439, // 01  000  1000  0111  001
670     VAE2         = 0x6439, // 01  100  1000  0111  001
671     VAE3         = 0x7439, // 01  110  1000  0111  001
672     ASIDE1       = 0x443a, // 01  000  1000  0111  010
673     VAAE1        = 0x443b, // 01  000  1000  0111  011
674     ALLE1        = 0x643c, // 01  100  1000  0111  100
675     VALE1        = 0x443d, // 01  000  1000  0111  101
676     VALE2        = 0x643d, // 01  100  1000  0111  101
677     VALE3        = 0x743d, // 01  110  1000  0111  101
678     VMALLS12E1   = 0x643e, // 01  100  1000  0111  110
679     VAALE1       = 0x443f  // 01  000  1000  0111  111
680   };
681
682   struct TLBIMapper : NamedImmMapper {
683     const static Mapping TLBIPairs[];
684
685     TLBIMapper();
686   };
687
688   static inline bool NeedsRegister(TLBIValues Val) {
689     switch (Val) {
690     case VMALLE1IS:
691     case ALLE2IS:
692     case ALLE3IS:
693     case ALLE1IS:
694     case VMALLS12E1IS:
695     case VMALLE1:
696     case ALLE2:
697     case ALLE3:
698     case ALLE1:
699     case VMALLS12E1:
700       return false;
701     default:
702       return true;
703     }
704   }
705 }
706
707 namespace AArch64II {
708
709   enum TOF {
710     //===--------------------------------------------------------------===//
711     // AArch64 Specific MachineOperand flags.
712
713     MO_NO_FLAG,
714
715     // MO_GOT - Represents a relocation referring to the GOT entry of a given
716     // symbol. Used in adrp.
717     MO_GOT,
718
719     // MO_GOT_LO12 - Represents a relocation referring to the low 12 bits of the
720     // GOT entry of a given symbol. Used in ldr only.
721     MO_GOT_LO12,
722
723     // MO_DTPREL_* - Represents a relocation referring to the offset from a
724     // module's dynamic thread pointer. Used in the local-dynamic TLS access
725     // model.
726     MO_DTPREL_G1,
727     MO_DTPREL_G0_NC,
728
729     // MO_GOTTPREL_* - Represents a relocation referring to a GOT entry
730     // providing the offset of a variable from the thread-pointer. Used in
731     // initial-exec TLS model where this offset is assigned in the static thread
732     // block and thus known by the dynamic linker.
733     MO_GOTTPREL,
734     MO_GOTTPREL_LO12,
735
736     // MO_TLSDESC_* - Represents a relocation referring to a GOT entry providing
737     // a TLS descriptor chosen by the dynamic linker. Used for the
738     // general-dynamic and local-dynamic TLS access models where very littls is
739     // known at link-time.
740     MO_TLSDESC,
741     MO_TLSDESC_LO12,
742
743     // MO_TPREL_* - Represents a relocation referring to the offset of a
744     // variable from the thread pointer itself. Used in the local-exec TLS
745     // access model.
746     MO_TPREL_G1,
747     MO_TPREL_G0_NC,
748
749     // MO_LO12 - On a symbol operand, this represents a relocation containing
750     // lower 12 bits of the address. Used in add/sub/ldr/str.
751     MO_LO12
752   };
753 }
754
755 class APFloat;
756
757 namespace A64Imms {
758   bool isFPImm(const APFloat &Val, uint32_t &Imm8Bits);
759
760   inline bool isFPImm(const APFloat &Val) {
761     uint32_t Imm8;
762     return isFPImm(Val, Imm8);
763   }
764
765   bool isLogicalImm(unsigned RegWidth, uint64_t Imm, uint32_t &Bits);
766   bool isLogicalImmBits(unsigned RegWidth, uint32_t Bits, uint64_t &Imm);
767
768   bool isMOVZImm(int RegWidth, uint64_t Value, int &UImm16, int &Shift);
769   bool isMOVNImm(int RegWidth, uint64_t Value, int &UImm16, int &Shift);
770
771   // We sometimes want to know whether the immediate is representable with a
772   // MOVN but *not* with a MOVZ (because that would take priority).
773   bool isOnlyMOVNImm(int RegWidth, uint64_t Value, int &UImm16, int &Shift);
774
775 }
776
777 } // end namespace llvm;
778
779 #endif