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,
89 // Unsupported extensions.
91 AEK_IWMMXT = 0x10000000,
92 AEK_IWMMXT2 = 0x20000000,
93 AEK_MAVERICK = 0x40000000,
94 AEK_XSCALE = 0x80000000,
98 enum class ISAKind { INVALID = 0, ARM, THUMB, AARCH64 };
101 // FIXME: BE8 vs. BE32?
102 enum class EndianKind { INVALID = 0, LITTLE, BIG };
105 enum class ProfileKind { INVALID = 0, A, R, M };
107 StringRef getCanonicalArchName(StringRef Arch);
110 StringRef getFPUName(unsigned FPUKind);
111 FPUVersion getFPUVersion(unsigned FPUKind);
112 NeonSupportLevel getFPUNeonSupportLevel(unsigned FPUKind);
113 FPURestriction getFPURestriction(unsigned FPUKind);
115 // FIXME: These should be moved to TargetTuple once it exists
116 bool getFPUFeatures(unsigned FPUKind, std::vector<StringRef> &Features);
117 bool getHWDivFeatures(unsigned HWDivKind, std::vector<StringRef> &Features);
118 bool getExtensionFeatures(unsigned Extensions,
119 std::vector<StringRef> &Features);
121 StringRef getArchName(ArchKind AK);
122 unsigned getArchAttr(ArchKind AK);
123 StringRef getCPUAttr(ArchKind AK);
124 StringRef getSubArch(ArchKind AK);
125 StringRef getArchExtName(unsigned ArchExtKind);
126 StringRef getArchExtFeature(StringRef ArchExt);
127 StringRef getHWDivName(unsigned HWDivKind);
129 // Information by Name
130 unsigned getDefaultFPU(StringRef CPU, ArchKind AK);
131 unsigned getDefaultExtensions(StringRef CPU, ArchKind AK);
132 StringRef getDefaultCPU(StringRef Arch);
135 unsigned parseHWDiv(StringRef HWDiv);
136 unsigned parseFPU(StringRef FPU);
137 ArchKind parseArch(StringRef Arch);
138 unsigned parseArchExt(StringRef ArchExt);
139 ArchKind parseCPUArch(StringRef CPU);
140 ISAKind parseArchISA(StringRef Arch);
141 EndianKind parseArchEndian(StringRef Arch);
142 ProfileKind parseArchProfile(StringRef Arch);
143 unsigned parseArchVersion(StringRef Arch);
145 StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);
149 // FIXME:This should be made into class design,to avoid dupplication.
153 enum class ArchKind {
154 #define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) ID,
155 #include "AArch64TargetParser.def"
158 // Arch extension modifiers for CPUs.
159 enum ArchExtKind : unsigned {
167 AEK_PROFILE = 1 << 6,
171 AEK_DOTPROD = 1 << 10,
176 StringRef getCanonicalArchName(StringRef Arch);
179 StringRef getFPUName(unsigned FPUKind);
180 ARM::FPUVersion getFPUVersion(unsigned FPUKind);
181 ARM::NeonSupportLevel getFPUNeonSupportLevel(unsigned FPUKind);
182 ARM::FPURestriction getFPURestriction(unsigned FPUKind);
184 // FIXME: These should be moved to TargetTuple once it exists
185 bool getFPUFeatures(unsigned FPUKind, std::vector<StringRef> &Features);
186 bool getExtensionFeatures(unsigned Extensions,
187 std::vector<StringRef> &Features);
188 bool getArchFeatures(ArchKind AK, std::vector<StringRef> &Features);
190 StringRef getArchName(ArchKind AK);
191 unsigned getArchAttr(ArchKind AK);
192 StringRef getCPUAttr(ArchKind AK);
193 StringRef getSubArch(ArchKind AK);
194 StringRef getArchExtName(unsigned ArchExtKind);
195 StringRef getArchExtFeature(StringRef ArchExt);
196 unsigned checkArchVersion(StringRef Arch);
198 // Information by Name
199 unsigned getDefaultFPU(StringRef CPU, ArchKind AK);
200 unsigned getDefaultExtensions(StringRef CPU, ArchKind AK);
201 StringRef getDefaultCPU(StringRef Arch);
204 unsigned parseFPU(StringRef FPU);
205 AArch64::ArchKind parseArch(StringRef Arch);
206 unsigned parseArchExt(StringRef ArchExt);
207 ArchKind parseCPUArch(StringRef CPU);
208 ARM::ISAKind parseArchISA(StringRef Arch);
209 ARM::EndianKind parseArchEndian(StringRef Arch);
210 ARM::ProfileKind parseArchProfile(StringRef Arch);
211 unsigned parseArchVersion(StringRef Arch);
213 } // namespace AArch64
217 // This should be kept in sync with libcc/compiler-rt as its included by clang
218 // as a proxy for what's in libgcc/compiler-rt.
219 enum ProcessorVendors : unsigned {
221 #define X86_VENDOR(ENUM, STRING) \
223 #include "llvm/Support/X86TargetParser.def"
227 // This should be kept in sync with libcc/compiler-rt as its included by clang
228 // as a proxy for what's in libgcc/compiler-rt.
229 enum ProcessorTypes : unsigned {
231 #define X86_CPU_TYPE(ARCHNAME, ENUM) \
233 #include "llvm/Support/X86TargetParser.def"
237 // This should be kept in sync with libcc/compiler-rt as its included by clang
238 // as a proxy for what's in libgcc/compiler-rt.
239 enum ProcessorSubtypes : unsigned {
241 #define X86_CPU_SUBTYPE(ARCHNAME, ENUM) \
243 #include "llvm/Support/X86TargetParser.def"
247 // This should be kept in sync with libcc/compiler-rt as it should be used
248 // by clang as a proxy for what's in libgcc/compiler-rt.
249 enum ProcessorFeatures {
250 #define X86_FEATURE(VAL, ENUM) \
252 #include "llvm/Support/X86TargetParser.def"