1 //===-- X86TargetParser - Parser for X86 features ---------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a target parser to recognise X86 hardware features.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_SUPPORT_X86TARGETPARSERCOMMON_H
14 #define LLVM_SUPPORT_X86TARGETPARSERCOMMON_H
15 
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringMap.h"
18 
19 namespace llvm {
20 class StringRef;
21 
22 namespace X86 {
23 
24 // This should be kept in sync with libcc/compiler-rt as its included by clang
25 // as a proxy for what's in libgcc/compiler-rt.
26 enum ProcessorVendors : unsigned {
27   VENDOR_DUMMY,
28 #define X86_VENDOR(ENUM, STRING) \
29   ENUM,
30 #include "llvm/Support/X86TargetParser.def"
31   VENDOR_OTHER
32 };
33 
34 // This should be kept in sync with libcc/compiler-rt as its included by clang
35 // as a proxy for what's in libgcc/compiler-rt.
36 enum ProcessorTypes : unsigned {
37   CPU_TYPE_DUMMY,
38 #define X86_CPU_TYPE(ENUM, STRING) \
39   ENUM,
40 #include "llvm/Support/X86TargetParser.def"
41   CPU_TYPE_MAX
42 };
43 
44 // This should be kept in sync with libcc/compiler-rt as its included by clang
45 // as a proxy for what's in libgcc/compiler-rt.
46 enum ProcessorSubtypes : unsigned {
47   CPU_SUBTYPE_DUMMY,
48 #define X86_CPU_SUBTYPE(ENUM, STRING) \
49   ENUM,
50 #include "llvm/Support/X86TargetParser.def"
51   CPU_SUBTYPE_MAX
52 };
53 
54 // This should be kept in sync with libcc/compiler-rt as it should be used
55 // by clang as a proxy for what's in libgcc/compiler-rt.
56 enum ProcessorFeatures {
57 #define X86_FEATURE(ENUM, STRING) FEATURE_##ENUM,
58 #include "llvm/Support/X86TargetParser.def"
59   CPU_FEATURE_MAX
60 };
61 
62 enum CPUKind {
63   CK_None,
64   CK_i386,
65   CK_i486,
66   CK_WinChipC6,
67   CK_WinChip2,
68   CK_C3,
69   CK_i586,
70   CK_Pentium,
71   CK_PentiumMMX,
72   CK_PentiumPro,
73   CK_i686,
74   CK_Pentium2,
75   CK_Pentium3,
76   CK_PentiumM,
77   CK_C3_2,
78   CK_Yonah,
79   CK_Pentium4,
80   CK_Prescott,
81   CK_Nocona,
82   CK_Core2,
83   CK_Penryn,
84   CK_Bonnell,
85   CK_Silvermont,
86   CK_Goldmont,
87   CK_GoldmontPlus,
88   CK_Tremont,
89   CK_Nehalem,
90   CK_Westmere,
91   CK_SandyBridge,
92   CK_IvyBridge,
93   CK_Haswell,
94   CK_Broadwell,
95   CK_SkylakeClient,
96   CK_SkylakeServer,
97   CK_Cascadelake,
98   CK_Cooperlake,
99   CK_Cannonlake,
100   CK_IcelakeClient,
101   CK_IcelakeServer,
102   CK_Tigerlake,
103   CK_SapphireRapids,
104   CK_Alderlake,
105   CK_KNL,
106   CK_KNM,
107   CK_Lakemont,
108   CK_K6,
109   CK_K6_2,
110   CK_K6_3,
111   CK_Athlon,
112   CK_AthlonXP,
113   CK_K8,
114   CK_K8SSE3,
115   CK_AMDFAM10,
116   CK_BTVER1,
117   CK_BTVER2,
118   CK_BDVER1,
119   CK_BDVER2,
120   CK_BDVER3,
121   CK_BDVER4,
122   CK_ZNVER1,
123   CK_ZNVER2,
124   CK_ZNVER3,
125   CK_x86_64,
126   CK_x86_64_v2,
127   CK_x86_64_v3,
128   CK_x86_64_v4,
129   CK_Geode,
130 };
131 
132 /// Parse \p CPU string into a CPUKind. Will only accept 64-bit capable CPUs if
133 /// \p Only64Bit is true.
134 CPUKind parseArchX86(StringRef CPU, bool Only64Bit = false);
135 CPUKind parseTuneCPU(StringRef CPU, bool Only64Bit = false);
136 
137 /// Provide a list of valid CPU names. If \p Only64Bit is true, the list will
138 /// only contain 64-bit capable CPUs.
139 void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values,
140                           bool Only64Bit = false);
141 /// Provide a list of valid -mtune names.
142 void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values,
143                           bool Only64Bit = false);
144 
145 /// Get the key feature prioritizing target multiversioning.
146 ProcessorFeatures getKeyFeature(CPUKind Kind);
147 
148 /// Fill in the features that \p CPU supports into \p Features.
149 void getFeaturesForCPU(StringRef CPU, SmallVectorImpl<StringRef> &Features);
150 
151 /// Set or clear entries in \p Features that are implied to be enabled/disabled
152 /// by the provided \p Feature.
153 void updateImpliedFeatures(StringRef Feature, bool Enabled,
154                            StringMap<bool> &Features);
155 
156 } // namespace X86
157 } // namespace llvm
158 
159 #endif
160