- Added support for parsing HWDiv features using Target Parser.
[oota-llvm.git] / include / llvm / Support / TargetParser.h
1 //===-- TargetParser - Parser for target features ---------------*- 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 implements a target parser to recognise hardware features such as
11 // FPU/CPU/ARCH names as well as specific support such as HDIV, etc.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_SUPPORT_TARGETPARSER_H
16 #define LLVM_SUPPORT_TARGETPARSER_H
17
18 // FIXME: vector is used because that's what clang uses for subtarget feature
19 // lists, but SmallVector would probably be better
20 #include <vector>
21
22 namespace llvm {
23   class StringRef;
24
25 // Target specific information into their own namespaces. These should be
26 // generated from TableGen because the information is already there, and there
27 // is where new information about targets will be added.
28 // FIXME: To TableGen this we need to make some table generated files available
29 // even if the back-end is not compiled with LLVM, plus we need to create a new
30 // back-end to TableGen to create these clean tables.
31 namespace ARM {
32   // FPU names.
33   enum FPUKind {
34     FK_INVALID = 0,
35     FK_NONE,
36     FK_VFP,
37     FK_VFPV2,
38     FK_VFPV3,
39     FK_VFPV3_FP16,
40     FK_VFPV3_D16,
41     FK_VFPV3_D16_FP16,
42     FK_VFPV3XD,
43     FK_VFPV3XD_FP16,
44     FK_VFPV4,
45     FK_VFPV4_D16,
46     FK_FPV4_SP_D16,
47     FK_FPV5_D16,
48     FK_FPV5_SP_D16,
49     FK_FP_ARMV8,
50     FK_NEON,
51     FK_NEON_FP16,
52     FK_NEON_VFPV4,
53     FK_NEON_FP_ARMV8,
54     FK_CRYPTO_NEON_FP_ARMV8,
55     FK_SOFTVFP,
56     FK_LAST
57   };
58
59   // FPU Version
60   enum FPUVersion {
61     FV_NONE = 0,
62     FV_VFPV2,
63     FV_VFPV3,
64     FV_VFPV3_FP16,
65     FV_VFPV4,
66     FV_VFPV5
67   };
68
69   // An FPU name implies one of three levels of Neon support:
70   enum NeonSupportLevel {
71     NS_None = 0, ///< No Neon
72     NS_Neon,     ///< Neon
73     NS_Crypto    ///< Neon with Crypto
74   };
75
76   // An FPU name restricts the FPU in one of three ways:
77   enum FPURestriction {
78     FR_None = 0, ///< No restriction
79     FR_D16,      ///< Only 16 D registers
80     FR_SP_D16    ///< Only single-precision instructions, with 16 D registers
81   };
82
83   // Arch names.
84   enum ArchKind {
85     AK_INVALID = 0,
86     AK_ARMV2,
87     AK_ARMV2A,
88     AK_ARMV3,
89     AK_ARMV3M,
90     AK_ARMV4,
91     AK_ARMV4T,
92     AK_ARMV5T,
93     AK_ARMV5TE,
94     AK_ARMV5TEJ,
95     AK_ARMV6,
96     AK_ARMV6K,
97     AK_ARMV6T2,
98     AK_ARMV6Z,
99     AK_ARMV6ZK,
100     AK_ARMV6M,
101     AK_ARMV6SM,
102     AK_ARMV7A,
103     AK_ARMV7R,
104     AK_ARMV7M,
105     AK_ARMV7EM,
106     AK_ARMV8A,
107     AK_ARMV8_1A,
108     // Non-standard Arch names.
109     AK_IWMMXT,
110     AK_IWMMXT2,
111     AK_XSCALE,
112     AK_ARMV5,
113     AK_ARMV5E,
114     AK_ARMV6J,
115     AK_ARMV6HL,
116     AK_ARMV7,
117     AK_ARMV7L,
118     AK_ARMV7HL,
119     AK_ARMV7S,
120     AK_LAST
121   };
122
123   // Arch extension modifiers for CPUs.
124   enum ArchExtKind {
125     AEK_INVALID  = 0x0,
126     AEK_NONE     = 0x1,
127     AEK_CRC      = 0x2,
128     AEK_CRYPTO   = 0x4,
129     AEK_FP       = 0x8,
130     AEK_HWDIV    = 0x10,
131     AEK_HWDIVARM = 0x20,
132     AEK_MP       = 0x40,
133     AEK_SIMD     = 0x80,
134     AEK_SEC      = 0x100,
135     AEK_VIRT     = 0x200,
136     // Unsupported extensions.
137     AEK_OS       = 0x8000000,
138     AEK_IWMMXT   = 0x10000000,
139     AEK_IWMMXT2  = 0x20000000,
140     AEK_MAVERICK = 0x40000000,
141     AEK_XSCALE   = 0x80000000,
142   };
143
144   // ISA kinds.
145   enum ISAKind {
146     IK_INVALID = 0,
147     IK_ARM,
148     IK_THUMB,
149     IK_AARCH64
150   };
151
152   // Endianness
153   // FIXME: BE8 vs. BE32?
154   enum EndianKind {
155     EK_INVALID = 0,
156     EK_LITTLE,
157     EK_BIG
158   };
159
160   // v6/v7/v8 Profile
161   enum ProfileKind {
162     PK_INVALID = 0,
163     PK_A,
164     PK_R,
165     PK_M
166   };
167 } // namespace ARM
168
169 // Target Parsers, one per architecture.
170 class ARMTargetParser {
171   static StringRef getHWDivSynonym(StringRef HWDiv);
172   static StringRef getFPUSynonym(StringRef FPU);
173   static StringRef getArchSynonym(StringRef Arch);
174
175 public:
176   static StringRef getCanonicalArchName(StringRef Arch);
177
178   // Information by ID
179   static const char * getFPUName(unsigned FPUKind);
180   static     unsigned getFPUVersion(unsigned FPUKind);
181   static     unsigned getFPUNeonSupportLevel(unsigned FPUKind);
182   static     unsigned getFPURestriction(unsigned FPUKind);
183   static     unsigned getDefaultFPU(StringRef CPU);
184   // FIXME: This should be moved to TargetTuple once it exists
185   static       bool   getFPUFeatures(unsigned FPUKind,
186                                      std::vector<const char*> &Features);
187   static       bool   getHWDivFeatures(unsigned HWDivKind,
188                                        std::vector<const char*> &Features);
189   static const char * getArchName(unsigned ArchKind);
190   static   unsigned   getArchAttr(unsigned ArchKind);
191   static const char * getCPUAttr(unsigned ArchKind);
192   static const char * getSubArch(unsigned ArchKind);
193   static const char * getArchExtName(unsigned ArchExtKind);
194   static const char * getHWDivName(unsigned HWDivKind);
195   static const char * getDefaultCPU(StringRef Arch);
196
197   // Parser
198   static unsigned parseHWDiv(StringRef HWDiv);
199   static unsigned parseFPU(StringRef FPU);
200   static unsigned parseArch(StringRef Arch);
201   static unsigned parseArchExt(StringRef ArchExt);
202   static unsigned parseCPUArch(StringRef CPU);
203   static unsigned parseArchISA(StringRef Arch);
204   static unsigned parseArchEndian(StringRef Arch);
205   static unsigned parseArchProfile(StringRef Arch);
206   static unsigned parseArchVersion(StringRef Arch);
207
208 };
209
210 } // namespace llvm
211
212 #endif