1 //===-- TargetParser - Parser for target features ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_TARGETPARSER_H
16 #define LLVM_SUPPORT_TARGETPARSER_H
18 // FIXME: vector is used because that's what clang uses for subtarget feature
19 // lists, but SmallVector would probably be better
20 #include "llvm/ADT/Triple.h"
26 // Target specific information into their own namespaces. These should be
27 // generated from TableGen because the information is already there, and there
28 // is where new information about targets will be added.
29 // FIXME: To TableGen this we need to make some table generated files available
30 // even if the back-end is not compiled with LLVM, plus we need to create a new
31 // back-end to TableGen to create these clean tables.
35 enum class FPUVersion {
44 // An FPU name restricts the FPU in one of three ways:
45 enum class FPURestriction {
46 None = 0, ///< No restriction
47 D16, ///< Only 16 D registers
48 SP_D16 ///< Only single-precision instructions, with 16 D registers
51 // An FPU name implies one of three levels of Neon support:
52 enum class NeonSupportLevel {
53 None = 0, ///< No Neon
55 Crypto ///< Neon with Crypto
60 #define ARM_FPU(NAME, KIND, VERSION, NEON_SUPPORT, RESTRICTION) KIND,
61 #include "ARMTargetParser.def"
67 #define ARM_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) ID,
68 #include "ARMTargetParser.def"
71 // Arch extension modifiers for CPUs.
72 enum ArchExtKind : unsigned {
78 AEK_HWDIVTHUMB = 1 << 4,
79 AEK_HWDIVARM = 1 << 5,
88 AEK_DOTPROD = 1 << 14,
91 // Unsupported extensions.
93 AEK_IWMMXT = 0x10000000,
94 AEK_IWMMXT2 = 0x20000000,
95 AEK_MAVERICK = 0x40000000,
96 AEK_XSCALE = 0x80000000,
100 enum class ISAKind { INVALID = 0, ARM, THUMB, AARCH64 };
103 // FIXME: BE8 vs. BE32?
104 enum class EndianKind { INVALID = 0, LITTLE, BIG };
107 enum class ProfileKind { INVALID = 0, A, R, M };
109 StringRef getCanonicalArchName(StringRef Arch);
112 StringRef getFPUName(unsigned FPUKind);
113 FPUVersion getFPUVersion(unsigned FPUKind);
114 NeonSupportLevel getFPUNeonSupportLevel(unsigned FPUKind);
115 FPURestriction getFPURestriction(unsigned FPUKind);
117 // FIXME: These should be moved to TargetTuple once it exists
118 bool getFPUFeatures(unsigned FPUKind, std::vector<StringRef> &Features);
119 bool getHWDivFeatures(unsigned HWDivKind, std::vector<StringRef> &Features);
120 bool getExtensionFeatures(unsigned Extensions,
121 std::vector<StringRef> &Features);
123 StringRef getArchName(ArchKind AK);
124 unsigned getArchAttr(ArchKind AK);
125 StringRef getCPUAttr(ArchKind AK);
126 StringRef getSubArch(ArchKind AK);
127 StringRef getArchExtName(unsigned ArchExtKind);
128 StringRef getArchExtFeature(StringRef ArchExt);
129 StringRef getHWDivName(unsigned HWDivKind);
131 // Information by Name
132 unsigned getDefaultFPU(StringRef CPU, ArchKind AK);
133 unsigned getDefaultExtensions(StringRef CPU, ArchKind AK);
134 StringRef getDefaultCPU(StringRef Arch);
137 unsigned parseHWDiv(StringRef HWDiv);
138 unsigned parseFPU(StringRef FPU);
139 ArchKind parseArch(StringRef Arch);
140 unsigned parseArchExt(StringRef ArchExt);
141 ArchKind parseCPUArch(StringRef CPU);
142 void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
143 ISAKind parseArchISA(StringRef Arch);
144 EndianKind parseArchEndian(StringRef Arch);
145 ProfileKind parseArchProfile(StringRef Arch);
146 unsigned parseArchVersion(StringRef Arch);
148 StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);
152 // FIXME:This should be made into class design,to avoid dupplication.
156 enum class ArchKind {
157 #define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) ID,
158 #include "AArch64TargetParser.def"
161 // Arch extension modifiers for CPUs.
162 enum ArchExtKind : unsigned {
170 AEK_PROFILE = 1 << 6,
174 AEK_DOTPROD = 1 << 10,
183 StringRef getCanonicalArchName(StringRef Arch);
186 StringRef getFPUName(unsigned FPUKind);
187 ARM::FPUVersion getFPUVersion(unsigned FPUKind);
188 ARM::NeonSupportLevel getFPUNeonSupportLevel(unsigned FPUKind);
189 ARM::FPURestriction getFPURestriction(unsigned FPUKind);
191 // FIXME: These should be moved to TargetTuple once it exists
192 bool getFPUFeatures(unsigned FPUKind, std::vector<StringRef> &Features);
193 bool getExtensionFeatures(unsigned Extensions,
194 std::vector<StringRef> &Features);
195 bool getArchFeatures(ArchKind AK, std::vector<StringRef> &Features);
197 StringRef getArchName(ArchKind AK);
198 unsigned getArchAttr(ArchKind AK);
199 StringRef getCPUAttr(ArchKind AK);
200 StringRef getSubArch(ArchKind AK);
201 StringRef getArchExtName(unsigned ArchExtKind);
202 StringRef getArchExtFeature(StringRef ArchExt);
203 unsigned checkArchVersion(StringRef Arch);
205 // Information by Name
206 unsigned getDefaultFPU(StringRef CPU, ArchKind AK);
207 unsigned getDefaultExtensions(StringRef CPU, ArchKind AK);
208 StringRef getDefaultCPU(StringRef Arch);
209 AArch64::ArchKind getCPUArchKind(StringRef CPU);
212 unsigned parseFPU(StringRef FPU);
213 AArch64::ArchKind parseArch(StringRef Arch);
214 ArchExtKind parseArchExt(StringRef ArchExt);
215 ArchKind parseCPUArch(StringRef CPU);
216 void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
217 ARM::ISAKind parseArchISA(StringRef Arch);
218 ARM::EndianKind parseArchEndian(StringRef Arch);
219 ARM::ProfileKind parseArchProfile(StringRef Arch);
220 unsigned parseArchVersion(StringRef Arch);
222 bool isX18ReservedByDefault(const Triple &TT);
224 } // namespace AArch64
228 // This should be kept in sync with libcc/compiler-rt as its included by clang
229 // as a proxy for what's in libgcc/compiler-rt.
230 enum ProcessorVendors : unsigned {
232 #define X86_VENDOR(ENUM, STRING) \
234 #include "llvm/Support/X86TargetParser.def"
238 // This should be kept in sync with libcc/compiler-rt as its included by clang
239 // as a proxy for what's in libgcc/compiler-rt.
240 enum ProcessorTypes : unsigned {
242 #define X86_CPU_TYPE(ARCHNAME, ENUM) \
244 #include "llvm/Support/X86TargetParser.def"
248 // This should be kept in sync with libcc/compiler-rt as its included by clang
249 // as a proxy for what's in libgcc/compiler-rt.
250 enum ProcessorSubtypes : unsigned {
252 #define X86_CPU_SUBTYPE(ARCHNAME, ENUM) \
254 #include "llvm/Support/X86TargetParser.def"
258 // This should be kept in sync with libcc/compiler-rt as it should be used
259 // by clang as a proxy for what's in libgcc/compiler-rt.
260 enum ProcessorFeatures {
261 #define X86_FEATURE(VAL, ENUM) \
263 #include "llvm/Support/X86TargetParser.def"