clang  19.0.0git
X86.cpp
Go to the documentation of this file.
1 //===--- X86.cpp - Implement X86 target feature support -------------------===//
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 X86 TargetInfo objects.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "X86.h"
14 #include "clang/Basic/Builtins.h"
15 #include "clang/Basic/Diagnostic.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/TargetParser/X86TargetParser.h"
21 #include <optional>
22 
23 namespace clang {
24 namespace targets {
25 
26 static constexpr Builtin::Info BuiltinInfoX86[] = {
27 #define BUILTIN(ID, TYPE, ATTRS) \
28  {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
29 #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
30  {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
31 #define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \
32  {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::HEADER, LANGS},
33 #include "clang/Basic/BuiltinsX86.def"
34 
35 #define BUILTIN(ID, TYPE, ATTRS) \
36  {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
37 #define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \
38  {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
39 #define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANGS, FEATURE) \
40  {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::HEADER, LANGS},
41 #include "clang/Basic/BuiltinsX86_64.def"
42 };
43 
44 static const char *const GCCRegNames[] = {
45  "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
46  "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
47  "argp", "flags", "fpcr", "fpsr", "dirflag", "frame", "xmm0", "xmm1",
48  "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", "mm0", "mm1",
49  "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", "r8", "r9",
50  "r10", "r11", "r12", "r13", "r14", "r15", "xmm8", "xmm9",
51  "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15", "ymm0", "ymm1",
52  "ymm2", "ymm3", "ymm4", "ymm5", "ymm6", "ymm7", "ymm8", "ymm9",
53  "ymm10", "ymm11", "ymm12", "ymm13", "ymm14", "ymm15", "xmm16", "xmm17",
54  "xmm18", "xmm19", "xmm20", "xmm21", "xmm22", "xmm23", "xmm24", "xmm25",
55  "xmm26", "xmm27", "xmm28", "xmm29", "xmm30", "xmm31", "ymm16", "ymm17",
56  "ymm18", "ymm19", "ymm20", "ymm21", "ymm22", "ymm23", "ymm24", "ymm25",
57  "ymm26", "ymm27", "ymm28", "ymm29", "ymm30", "ymm31", "zmm0", "zmm1",
58  "zmm2", "zmm3", "zmm4", "zmm5", "zmm6", "zmm7", "zmm8", "zmm9",
59  "zmm10", "zmm11", "zmm12", "zmm13", "zmm14", "zmm15", "zmm16", "zmm17",
60  "zmm18", "zmm19", "zmm20", "zmm21", "zmm22", "zmm23", "zmm24", "zmm25",
61  "zmm26", "zmm27", "zmm28", "zmm29", "zmm30", "zmm31", "k0", "k1",
62  "k2", "k3", "k4", "k5", "k6", "k7",
63  "cr0", "cr2", "cr3", "cr4", "cr8",
64  "dr0", "dr1", "dr2", "dr3", "dr6", "dr7",
65  "bnd0", "bnd1", "bnd2", "bnd3",
66  "tmm0", "tmm1", "tmm2", "tmm3", "tmm4", "tmm5", "tmm6", "tmm7",
67  "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
68  "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
69 };
70 
72  {{"al", "ah", "eax", "rax"}, 0},
73  {{"bl", "bh", "ebx", "rbx"}, 3},
74  {{"cl", "ch", "ecx", "rcx"}, 2},
75  {{"dl", "dh", "edx", "rdx"}, 1},
76  {{"esi", "rsi"}, 4},
77  {{"edi", "rdi"}, 5},
78  {{"esp", "rsp"}, 7},
79  {{"ebp", "rbp"}, 6},
80  {{"r8d", "r8w", "r8b"}, 38},
81  {{"r9d", "r9w", "r9b"}, 39},
82  {{"r10d", "r10w", "r10b"}, 40},
83  {{"r11d", "r11w", "r11b"}, 41},
84  {{"r12d", "r12w", "r12b"}, 42},
85  {{"r13d", "r13w", "r13b"}, 43},
86  {{"r14d", "r14w", "r14b"}, 44},
87  {{"r15d", "r15w", "r15b"}, 45},
88  {{"r16d", "r16w", "r16b"}, 165},
89  {{"r17d", "r17w", "r17b"}, 166},
90  {{"r18d", "r18w", "r18b"}, 167},
91  {{"r19d", "r19w", "r19b"}, 168},
92  {{"r20d", "r20w", "r20b"}, 169},
93  {{"r21d", "r21w", "r21b"}, 170},
94  {{"r22d", "r22w", "r22b"}, 171},
95  {{"r23d", "r23w", "r23b"}, 172},
96  {{"r24d", "r24w", "r24b"}, 173},
97  {{"r25d", "r25w", "r25b"}, 174},
98  {{"r26d", "r26w", "r26b"}, 175},
99  {{"r27d", "r27w", "r27b"}, 176},
100  {{"r28d", "r28w", "r28b"}, 177},
101  {{"r29d", "r29w", "r29b"}, 178},
102  {{"r30d", "r30w", "r30b"}, 179},
103  {{"r31d", "r31w", "r31b"}, 180},
104 };
105 } // namespace targets
106 } // namespace clang
107 
108 using namespace clang;
109 using namespace clang::targets;
110 
111 bool X86TargetInfo::setFPMath(StringRef Name) {
112  if (Name == "387") {
113  FPMath = FP_387;
114  return true;
115  }
116  if (Name == "sse") {
117  FPMath = FP_SSE;
118  return true;
119  }
120  return false;
121 }
122 
124  llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
125  const std::vector<std::string> &FeaturesVec) const {
126  // FIXME: This *really* should not be here.
127  // X86_64 always has SSE2.
128  if (getTriple().getArch() == llvm::Triple::x86_64)
129  setFeatureEnabled(Features, "sse2", true);
130 
131  using namespace llvm::X86;
132 
133  SmallVector<StringRef, 16> CPUFeatures;
134  getFeaturesForCPU(CPU, CPUFeatures);
135  for (auto &F : CPUFeatures)
136  setFeatureEnabled(Features, F, true);
137 
138  std::vector<std::string> UpdatedFeaturesVec;
139  std::vector<std::string> UpdatedAVX10FeaturesVec;
140  enum { FE_NOSET = -1, FE_FALSE, FE_TRUE };
141  int HasEVEX512 = FE_NOSET;
142  bool HasAVX512F = Features.lookup("avx512f");
143  bool HasAVX10 = Features.lookup("avx10.1-256");
144  bool HasAVX10_512 = Features.lookup("avx10.1-512");
145  std::string LastAVX10;
146  std::string LastAVX512;
147  for (const auto &Feature : FeaturesVec) {
148  // Expand general-regs-only to -x86, -mmx and -sse
149  if (Feature == "+general-regs-only") {
150  UpdatedFeaturesVec.push_back("-x87");
151  UpdatedFeaturesVec.push_back("-mmx");
152  UpdatedFeaturesVec.push_back("-sse");
153  continue;
154  }
155 
156  if (Feature.substr(1, 6) == "avx10.") {
157  if (Feature[0] == '+') {
158  HasAVX10 = true;
159  if (StringRef(Feature).ends_with("512"))
160  HasAVX10_512 = true;
161  LastAVX10 = Feature;
162  } else if (HasAVX10 && Feature == "-avx10.1-256") {
163  HasAVX10 = false;
164  HasAVX10_512 = false;
165  } else if (HasAVX10_512 && Feature == "-avx10.1-512") {
166  HasAVX10_512 = false;
167  }
168  // Postpone AVX10 features handling after AVX512 settled.
169  UpdatedAVX10FeaturesVec.push_back(Feature);
170  continue;
171  } else if (!HasAVX512F && StringRef(Feature).starts_with("+avx512")) {
172  HasAVX512F = true;
173  LastAVX512 = Feature;
174  } else if (HasAVX512F && Feature == "-avx512f") {
175  HasAVX512F = false;
176  } else if (HasEVEX512 != FE_TRUE && Feature == "+evex512") {
177  HasEVEX512 = FE_TRUE;
178  continue;
179  } else if (HasEVEX512 != FE_FALSE && Feature == "-evex512") {
180  HasEVEX512 = FE_FALSE;
181  continue;
182  }
183 
184  UpdatedFeaturesVec.push_back(Feature);
185  }
186  llvm::append_range(UpdatedFeaturesVec, UpdatedAVX10FeaturesVec);
187  // HasEVEX512 is a three-states flag. We need to turn it into [+-]evex512
188  // according to other features.
189  if (HasAVX512F) {
190  UpdatedFeaturesVec.push_back(HasEVEX512 == FE_FALSE ? "-evex512"
191  : "+evex512");
192  if (HasAVX10 && !HasAVX10_512 && HasEVEX512 != FE_FALSE)
193  Diags.Report(diag::warn_invalid_feature_combination)
194  << LastAVX512 + " " + LastAVX10 + "; will be promoted to avx10.1-512";
195  } else if (HasAVX10) {
196  if (HasEVEX512 != FE_NOSET)
197  Diags.Report(diag::warn_invalid_feature_combination)
198  << LastAVX10 + (HasEVEX512 == FE_TRUE ? " +evex512" : " -evex512");
199  UpdatedFeaturesVec.push_back(HasAVX10_512 ? "+evex512" : "-evex512");
200  }
201 
202  if (!TargetInfo::initFeatureMap(Features, Diags, CPU, UpdatedFeaturesVec))
203  return false;
204 
205  // Can't do this earlier because we need to be able to explicitly enable
206  // or disable these features and the things that they depend upon.
207 
208  // Enable popcnt if sse4.2 is enabled and popcnt is not explicitly disabled.
209  auto I = Features.find("sse4.2");
210  if (I != Features.end() && I->getValue() &&
211  !llvm::is_contained(UpdatedFeaturesVec, "-popcnt"))
212  Features["popcnt"] = true;
213 
214  // Additionally, if SSE is enabled and mmx is not explicitly disabled,
215  // then enable MMX.
216  I = Features.find("sse");
217  if (I != Features.end() && I->getValue() &&
218  !llvm::is_contained(UpdatedFeaturesVec, "-mmx"))
219  Features["mmx"] = true;
220 
221  // Enable xsave if avx is enabled and xsave is not explicitly disabled.
222  I = Features.find("avx");
223  if (I != Features.end() && I->getValue() &&
224  !llvm::is_contained(UpdatedFeaturesVec, "-xsave"))
225  Features["xsave"] = true;
226 
227  // Enable CRC32 if SSE4.2 is enabled and CRC32 is not explicitly disabled.
228  I = Features.find("sse4.2");
229  if (I != Features.end() && I->getValue() &&
230  !llvm::is_contained(UpdatedFeaturesVec, "-crc32"))
231  Features["crc32"] = true;
232 
233  return true;
234 }
235 
236 void X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
237  StringRef Name, bool Enabled) const {
238  if (Name == "sse4") {
239  // We can get here via the __target__ attribute since that's not controlled
240  // via the -msse4/-mno-sse4 command line alias. Handle this the same way
241  // here - turn on the sse4.2 if enabled, turn off the sse4.1 level if
242  // disabled.
243  if (Enabled)
244  Name = "sse4.2";
245  else
246  Name = "sse4.1";
247  }
248 
249  Features[Name] = Enabled;
250  llvm::X86::updateImpliedFeatures(Name, Enabled, Features);
251 }
252 
253 /// handleTargetFeatures - Perform initialization based on the user
254 /// configured set of features.
255 bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
256  DiagnosticsEngine &Diags) {
257  for (const auto &Feature : Features) {
258  if (Feature[0] != '+')
259  continue;
260 
261  if (Feature == "+aes") {
262  HasAES = true;
263  } else if (Feature == "+vaes") {
264  HasVAES = true;
265  } else if (Feature == "+pclmul") {
266  HasPCLMUL = true;
267  } else if (Feature == "+vpclmulqdq") {
268  HasVPCLMULQDQ = true;
269  } else if (Feature == "+lzcnt") {
270  HasLZCNT = true;
271  } else if (Feature == "+rdrnd") {
272  HasRDRND = true;
273  } else if (Feature == "+fsgsbase") {
274  HasFSGSBASE = true;
275  } else if (Feature == "+bmi") {
276  HasBMI = true;
277  } else if (Feature == "+bmi2") {
278  HasBMI2 = true;
279  } else if (Feature == "+popcnt") {
280  HasPOPCNT = true;
281  } else if (Feature == "+rtm") {
282  HasRTM = true;
283  } else if (Feature == "+prfchw") {
284  HasPRFCHW = true;
285  } else if (Feature == "+rdseed") {
286  HasRDSEED = true;
287  } else if (Feature == "+adx") {
288  HasADX = true;
289  } else if (Feature == "+tbm") {
290  HasTBM = true;
291  } else if (Feature == "+lwp") {
292  HasLWP = true;
293  } else if (Feature == "+fma") {
294  HasFMA = true;
295  } else if (Feature == "+f16c") {
296  HasF16C = true;
297  } else if (Feature == "+gfni") {
298  HasGFNI = true;
299  } else if (Feature == "+evex512") {
300  HasEVEX512 = true;
301  } else if (Feature == "+avx10.1-256") {
302  HasAVX10_1 = true;
303  } else if (Feature == "+avx10.1-512") {
304  HasAVX10_1_512 = true;
305  } else if (Feature == "+avx512cd") {
306  HasAVX512CD = true;
307  } else if (Feature == "+avx512vpopcntdq") {
308  HasAVX512VPOPCNTDQ = true;
309  } else if (Feature == "+avx512vnni") {
310  HasAVX512VNNI = true;
311  } else if (Feature == "+avx512bf16") {
312  HasAVX512BF16 = true;
313  } else if (Feature == "+avx512fp16") {
314  HasAVX512FP16 = true;
315  HasLegalHalfType = true;
316  } else if (Feature == "+avx512dq") {
317  HasAVX512DQ = true;
318  } else if (Feature == "+avx512bitalg") {
319  HasAVX512BITALG = true;
320  } else if (Feature == "+avx512bw") {
321  HasAVX512BW = true;
322  } else if (Feature == "+avx512vl") {
323  HasAVX512VL = true;
324  } else if (Feature == "+avx512vbmi") {
325  HasAVX512VBMI = true;
326  } else if (Feature == "+avx512vbmi2") {
327  HasAVX512VBMI2 = true;
328  } else if (Feature == "+avx512ifma") {
329  HasAVX512IFMA = true;
330  } else if (Feature == "+avx512vp2intersect") {
331  HasAVX512VP2INTERSECT = true;
332  } else if (Feature == "+sha") {
333  HasSHA = true;
334  } else if (Feature == "+sha512") {
335  HasSHA512 = true;
336  } else if (Feature == "+shstk") {
337  HasSHSTK = true;
338  } else if (Feature == "+sm3") {
339  HasSM3 = true;
340  } else if (Feature == "+sm4") {
341  HasSM4 = true;
342  } else if (Feature == "+movbe") {
343  HasMOVBE = true;
344  } else if (Feature == "+sgx") {
345  HasSGX = true;
346  } else if (Feature == "+cx8") {
347  HasCX8 = true;
348  } else if (Feature == "+cx16") {
349  HasCX16 = true;
350  } else if (Feature == "+fxsr") {
351  HasFXSR = true;
352  } else if (Feature == "+xsave") {
353  HasXSAVE = true;
354  } else if (Feature == "+xsaveopt") {
355  HasXSAVEOPT = true;
356  } else if (Feature == "+xsavec") {
357  HasXSAVEC = true;
358  } else if (Feature == "+xsaves") {
359  HasXSAVES = true;
360  } else if (Feature == "+mwaitx") {
361  HasMWAITX = true;
362  } else if (Feature == "+pku") {
363  HasPKU = true;
364  } else if (Feature == "+clflushopt") {
365  HasCLFLUSHOPT = true;
366  } else if (Feature == "+clwb") {
367  HasCLWB = true;
368  } else if (Feature == "+wbnoinvd") {
369  HasWBNOINVD = true;
370  } else if (Feature == "+prefetchi") {
371  HasPREFETCHI = true;
372  } else if (Feature == "+clzero") {
373  HasCLZERO = true;
374  } else if (Feature == "+cldemote") {
375  HasCLDEMOTE = true;
376  } else if (Feature == "+rdpid") {
377  HasRDPID = true;
378  } else if (Feature == "+rdpru") {
379  HasRDPRU = true;
380  } else if (Feature == "+kl") {
381  HasKL = true;
382  } else if (Feature == "+widekl") {
383  HasWIDEKL = true;
384  } else if (Feature == "+retpoline-external-thunk") {
385  HasRetpolineExternalThunk = true;
386  } else if (Feature == "+sahf") {
387  HasLAHFSAHF = true;
388  } else if (Feature == "+waitpkg") {
389  HasWAITPKG = true;
390  } else if (Feature == "+movdiri") {
391  HasMOVDIRI = true;
392  } else if (Feature == "+movdir64b") {
393  HasMOVDIR64B = true;
394  } else if (Feature == "+pconfig") {
395  HasPCONFIG = true;
396  } else if (Feature == "+ptwrite") {
397  HasPTWRITE = true;
398  } else if (Feature == "+invpcid") {
399  HasINVPCID = true;
400  } else if (Feature == "+enqcmd") {
401  HasENQCMD = true;
402  } else if (Feature == "+hreset") {
403  HasHRESET = true;
404  } else if (Feature == "+amx-bf16") {
405  HasAMXBF16 = true;
406  } else if (Feature == "+amx-fp16") {
407  HasAMXFP16 = true;
408  } else if (Feature == "+amx-int8") {
409  HasAMXINT8 = true;
410  } else if (Feature == "+amx-tile") {
411  HasAMXTILE = true;
412  } else if (Feature == "+amx-complex") {
413  HasAMXCOMPLEX = true;
414  } else if (Feature == "+cmpccxadd") {
415  HasCMPCCXADD = true;
416  } else if (Feature == "+raoint") {
417  HasRAOINT = true;
418  } else if (Feature == "+avxifma") {
419  HasAVXIFMA = true;
420  } else if (Feature == "+avxneconvert") {
421  HasAVXNECONVERT= true;
422  } else if (Feature == "+avxvnni") {
423  HasAVXVNNI = true;
424  } else if (Feature == "+avxvnniint16") {
425  HasAVXVNNIINT16 = true;
426  } else if (Feature == "+avxvnniint8") {
427  HasAVXVNNIINT8 = true;
428  } else if (Feature == "+serialize") {
429  HasSERIALIZE = true;
430  } else if (Feature == "+tsxldtrk") {
431  HasTSXLDTRK = true;
432  } else if (Feature == "+uintr") {
433  HasUINTR = true;
434  } else if (Feature == "+usermsr") {
435  HasUSERMSR = true;
436  } else if (Feature == "+crc32") {
437  HasCRC32 = true;
438  } else if (Feature == "+x87") {
439  HasX87 = true;
440  } else if (Feature == "+fullbf16") {
441  HasFullBFloat16 = true;
442  } else if (Feature == "+egpr") {
443  HasEGPR = true;
444  } else if (Feature == "+push2pop2") {
445  HasPush2Pop2 = true;
446  } else if (Feature == "+ppx") {
447  HasPPX = true;
448  } else if (Feature == "+ndd") {
449  HasNDD = true;
450  } else if (Feature == "+ccmp") {
451  HasCCMP = true;
452  } else if (Feature == "+nf") {
453  HasNF = true;
454  } else if (Feature == "+cf") {
455  HasCF = true;
456  }
457 
458  X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
459  .Case("+avx512f", AVX512F)
460  .Case("+avx2", AVX2)
461  .Case("+avx", AVX)
462  .Case("+sse4.2", SSE42)
463  .Case("+sse4.1", SSE41)
464  .Case("+ssse3", SSSE3)
465  .Case("+sse3", SSE3)
466  .Case("+sse2", SSE2)
467  .Case("+sse", SSE1)
468  .Default(NoSSE);
469  SSELevel = std::max(SSELevel, Level);
470 
471  HasFloat16 = SSELevel >= SSE2;
472 
473  // X86 target has bfloat16 emulation support in the backend, where
474  // bfloat16 is treated as a 32-bit float, arithmetic operations are
475  // performed in 32-bit, and the result is converted back to bfloat16.
476  // Truncation and extension between bfloat16 and 32-bit float are supported
477  // by the compiler-rt library. However, native bfloat16 support is currently
478  // not available in the X86 target. Hence, HasFullBFloat16 will be false
479  // until native bfloat16 support is available. HasFullBFloat16 is used to
480  // determine whether to automatically use excess floating point precision
481  // for bfloat16 arithmetic operations in the front-end.
482  HasBFloat16 = SSELevel >= SSE2;
483 
484  MMX3DNowEnum ThreeDNowLevel = llvm::StringSwitch<MMX3DNowEnum>(Feature)
485  .Case("+3dnowa", AMD3DNowAthlon)
486  .Case("+3dnow", AMD3DNow)
487  .Case("+mmx", MMX)
488  .Default(NoMMX3DNow);
489  MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel);
490 
491  XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(Feature)
492  .Case("+xop", XOP)
493  .Case("+fma4", FMA4)
494  .Case("+sse4a", SSE4A)
495  .Default(NoXOP);
496  XOPLevel = std::max(XOPLevel, XLevel);
497  }
498 
499  // LLVM doesn't have a separate switch for fpmath, so only accept it if it
500  // matches the selected sse level.
501  if ((FPMath == FP_SSE && SSELevel < SSE1) ||
502  (FPMath == FP_387 && SSELevel >= SSE1)) {
503  Diags.Report(diag::err_target_unsupported_fpmath)
504  << (FPMath == FP_SSE ? "sse" : "387");
505  return false;
506  }
507 
508  // FIXME: We should allow long double type on 32-bits to match with GCC.
509  // This requires backend to be able to lower f80 without x87 first.
510  if (!HasX87 && LongDoubleFormat == &llvm::APFloat::x87DoubleExtended())
511  HasLongDouble = false;
512 
513  return true;
514 }
515 
516 /// X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro
517 /// definitions for this particular subtarget.
519  MacroBuilder &Builder) const {
520  // Inline assembly supports X86 flag outputs.
521  Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
522 
523  std::string CodeModel = getTargetOpts().CodeModel;
524  if (CodeModel == "default")
525  CodeModel = "small";
526  Builder.defineMacro("__code_model_" + CodeModel + "__");
527 
528  // Target identification.
529  if (getTriple().getArch() == llvm::Triple::x86_64) {
530  Builder.defineMacro("__amd64__");
531  Builder.defineMacro("__amd64");
532  Builder.defineMacro("__x86_64");
533  Builder.defineMacro("__x86_64__");
534  if (getTriple().getArchName() == "x86_64h") {
535  Builder.defineMacro("__x86_64h");
536  Builder.defineMacro("__x86_64h__");
537  }
538  } else {
539  DefineStd(Builder, "i386", Opts);
540  }
541 
542  Builder.defineMacro("__SEG_GS");
543  Builder.defineMacro("__SEG_FS");
544  Builder.defineMacro("__seg_gs", "__attribute__((address_space(256)))");
545  Builder.defineMacro("__seg_fs", "__attribute__((address_space(257)))");
546 
547  // Subtarget options.
548  // FIXME: We are hard-coding the tune parameters based on the CPU, but they
549  // truly should be based on -mtune options.
550  using namespace llvm::X86;
551  switch (CPU) {
552  case CK_None:
553  break;
554  case CK_i386:
555  // The rest are coming from the i386 define above.
556  Builder.defineMacro("__tune_i386__");
557  break;
558  case CK_i486:
559  case CK_WinChipC6:
560  case CK_WinChip2:
561  case CK_C3:
562  defineCPUMacros(Builder, "i486");
563  break;
564  case CK_PentiumMMX:
565  Builder.defineMacro("__pentium_mmx__");
566  Builder.defineMacro("__tune_pentium_mmx__");
567  [[fallthrough]];
568  case CK_i586:
569  case CK_Pentium:
570  defineCPUMacros(Builder, "i586");
571  defineCPUMacros(Builder, "pentium");
572  break;
573  case CK_Pentium3:
574  case CK_PentiumM:
575  Builder.defineMacro("__tune_pentium3__");
576  [[fallthrough]];
577  case CK_Pentium2:
578  case CK_C3_2:
579  Builder.defineMacro("__tune_pentium2__");
580  [[fallthrough]];
581  case CK_PentiumPro:
582  case CK_i686:
583  defineCPUMacros(Builder, "i686");
584  defineCPUMacros(Builder, "pentiumpro");
585  break;
586  case CK_Pentium4:
587  defineCPUMacros(Builder, "pentium4");
588  break;
589  case CK_Yonah:
590  case CK_Prescott:
591  case CK_Nocona:
592  defineCPUMacros(Builder, "nocona");
593  break;
594  case CK_Core2:
595  case CK_Penryn:
596  defineCPUMacros(Builder, "core2");
597  break;
598  case CK_Bonnell:
599  defineCPUMacros(Builder, "atom");
600  break;
601  case CK_Silvermont:
602  defineCPUMacros(Builder, "slm");
603  break;
604  case CK_Goldmont:
605  defineCPUMacros(Builder, "goldmont");
606  break;
607  case CK_GoldmontPlus:
608  defineCPUMacros(Builder, "goldmont_plus");
609  break;
610  case CK_Tremont:
611  defineCPUMacros(Builder, "tremont");
612  break;
613  // Gracemont and later atom-cores use P-core cpu macros.
614  case CK_Gracemont:
615  case CK_Nehalem:
616  case CK_Westmere:
617  case CK_SandyBridge:
618  case CK_IvyBridge:
619  case CK_Haswell:
620  case CK_Broadwell:
621  case CK_SkylakeClient:
622  case CK_SkylakeServer:
623  case CK_Cascadelake:
624  case CK_Cooperlake:
625  case CK_Cannonlake:
626  case CK_IcelakeClient:
627  case CK_Rocketlake:
628  case CK_IcelakeServer:
629  case CK_Tigerlake:
630  case CK_SapphireRapids:
631  case CK_Alderlake:
632  case CK_Raptorlake:
633  case CK_Meteorlake:
634  case CK_Arrowlake:
635  case CK_ArrowlakeS:
636  case CK_Lunarlake:
637  case CK_Pantherlake:
638  case CK_Sierraforest:
639  case CK_Grandridge:
640  case CK_Graniterapids:
641  case CK_GraniterapidsD:
642  case CK_Emeraldrapids:
643  case CK_Clearwaterforest:
644  // FIXME: Historically, we defined this legacy name, it would be nice to
645  // remove it at some point. We've never exposed fine-grained names for
646  // recent primary x86 CPUs, and we should keep it that way.
647  defineCPUMacros(Builder, "corei7");
648  break;
649  case CK_KNL:
650  defineCPUMacros(Builder, "knl");
651  break;
652  case CK_KNM:
653  break;
654  case CK_Lakemont:
655  defineCPUMacros(Builder, "i586", /*Tuning*/false);
656  defineCPUMacros(Builder, "pentium", /*Tuning*/false);
657  Builder.defineMacro("__tune_lakemont__");
658  break;
659  case CK_K6_2:
660  Builder.defineMacro("__k6_2__");
661  Builder.defineMacro("__tune_k6_2__");
662  [[fallthrough]];
663  case CK_K6_3:
664  if (CPU != CK_K6_2) { // In case of fallthrough
665  // FIXME: GCC may be enabling these in cases where some other k6
666  // architecture is specified but -m3dnow is explicitly provided. The
667  // exact semantics need to be determined and emulated here.
668  Builder.defineMacro("__k6_3__");
669  Builder.defineMacro("__tune_k6_3__");
670  }
671  [[fallthrough]];
672  case CK_K6:
673  defineCPUMacros(Builder, "k6");
674  break;
675  case CK_Athlon:
676  case CK_AthlonXP:
677  defineCPUMacros(Builder, "athlon");
678  if (SSELevel != NoSSE) {
679  Builder.defineMacro("__athlon_sse__");
680  Builder.defineMacro("__tune_athlon_sse__");
681  }
682  break;
683  case CK_K8:
684  case CK_K8SSE3:
685  case CK_x86_64:
686  defineCPUMacros(Builder, "k8");
687  break;
688  case CK_x86_64_v2:
689  case CK_x86_64_v3:
690  case CK_x86_64_v4:
691  break;
692  case CK_AMDFAM10:
693  defineCPUMacros(Builder, "amdfam10");
694  break;
695  case CK_BTVER1:
696  defineCPUMacros(Builder, "btver1");
697  break;
698  case CK_BTVER2:
699  defineCPUMacros(Builder, "btver2");
700  break;
701  case CK_BDVER1:
702  defineCPUMacros(Builder, "bdver1");
703  break;
704  case CK_BDVER2:
705  defineCPUMacros(Builder, "bdver2");
706  break;
707  case CK_BDVER3:
708  defineCPUMacros(Builder, "bdver3");
709  break;
710  case CK_BDVER4:
711  defineCPUMacros(Builder, "bdver4");
712  break;
713  case CK_ZNVER1:
714  defineCPUMacros(Builder, "znver1");
715  break;
716  case CK_ZNVER2:
717  defineCPUMacros(Builder, "znver2");
718  break;
719  case CK_ZNVER3:
720  defineCPUMacros(Builder, "znver3");
721  break;
722  case CK_ZNVER4:
723  defineCPUMacros(Builder, "znver4");
724  break;
725  case CK_Geode:
726  defineCPUMacros(Builder, "geode");
727  break;
728  }
729 
730  // Target properties.
731  Builder.defineMacro("__REGISTER_PREFIX__", "");
732 
733  // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
734  // functions in glibc header files that use FP Stack inline asm which the
735  // backend can't deal with (PR879).
736  Builder.defineMacro("__NO_MATH_INLINES");
737 
738  if (HasAES)
739  Builder.defineMacro("__AES__");
740 
741  if (HasVAES)
742  Builder.defineMacro("__VAES__");
743 
744  if (HasPCLMUL)
745  Builder.defineMacro("__PCLMUL__");
746 
747  if (HasVPCLMULQDQ)
748  Builder.defineMacro("__VPCLMULQDQ__");
749 
750  // Note, in 32-bit mode, GCC does not define the macro if -mno-sahf. In LLVM,
751  // the feature flag only applies to 64-bit mode.
752  if (HasLAHFSAHF || getTriple().getArch() == llvm::Triple::x86)
753  Builder.defineMacro("__LAHF_SAHF__");
754 
755  if (HasLZCNT)
756  Builder.defineMacro("__LZCNT__");
757 
758  if (HasRDRND)
759  Builder.defineMacro("__RDRND__");
760 
761  if (HasFSGSBASE)
762  Builder.defineMacro("__FSGSBASE__");
763 
764  if (HasBMI)
765  Builder.defineMacro("__BMI__");
766 
767  if (HasBMI2)
768  Builder.defineMacro("__BMI2__");
769 
770  if (HasPOPCNT)
771  Builder.defineMacro("__POPCNT__");
772 
773  if (HasRTM)
774  Builder.defineMacro("__RTM__");
775 
776  if (HasPRFCHW)
777  Builder.defineMacro("__PRFCHW__");
778 
779  if (HasRDSEED)
780  Builder.defineMacro("__RDSEED__");
781 
782  if (HasADX)
783  Builder.defineMacro("__ADX__");
784 
785  if (HasTBM)
786  Builder.defineMacro("__TBM__");
787 
788  if (HasLWP)
789  Builder.defineMacro("__LWP__");
790 
791  if (HasMWAITX)
792  Builder.defineMacro("__MWAITX__");
793 
794  if (HasMOVBE)
795  Builder.defineMacro("__MOVBE__");
796 
797  switch (XOPLevel) {
798  case XOP:
799  Builder.defineMacro("__XOP__");
800  [[fallthrough]];
801  case FMA4:
802  Builder.defineMacro("__FMA4__");
803  [[fallthrough]];
804  case SSE4A:
805  Builder.defineMacro("__SSE4A__");
806  [[fallthrough]];
807  case NoXOP:
808  break;
809  }
810 
811  if (HasFMA)
812  Builder.defineMacro("__FMA__");
813 
814  if (HasF16C)
815  Builder.defineMacro("__F16C__");
816 
817  if (HasGFNI)
818  Builder.defineMacro("__GFNI__");
819 
820  if (HasEVEX512)
821  Builder.defineMacro("__EVEX512__");
822  if (HasAVX10_1)
823  Builder.defineMacro("__AVX10_1__");
824  if (HasAVX10_1_512)
825  Builder.defineMacro("__AVX10_1_512__");
826  if (HasAVX512CD)
827  Builder.defineMacro("__AVX512CD__");
828  if (HasAVX512VPOPCNTDQ)
829  Builder.defineMacro("__AVX512VPOPCNTDQ__");
830  if (HasAVX512VNNI)
831  Builder.defineMacro("__AVX512VNNI__");
832  if (HasAVX512BF16)
833  Builder.defineMacro("__AVX512BF16__");
834  if (HasAVX512FP16)
835  Builder.defineMacro("__AVX512FP16__");
836  if (HasAVX512DQ)
837  Builder.defineMacro("__AVX512DQ__");
838  if (HasAVX512BITALG)
839  Builder.defineMacro("__AVX512BITALG__");
840  if (HasAVX512BW)
841  Builder.defineMacro("__AVX512BW__");
842  if (HasAVX512VL) {
843  Builder.defineMacro("__AVX512VL__");
844  Builder.defineMacro("__EVEX256__");
845  }
846  if (HasAVX512VBMI)
847  Builder.defineMacro("__AVX512VBMI__");
848  if (HasAVX512VBMI2)
849  Builder.defineMacro("__AVX512VBMI2__");
850  if (HasAVX512IFMA)
851  Builder.defineMacro("__AVX512IFMA__");
852  if (HasAVX512VP2INTERSECT)
853  Builder.defineMacro("__AVX512VP2INTERSECT__");
854  if (HasSHA)
855  Builder.defineMacro("__SHA__");
856  if (HasSHA512)
857  Builder.defineMacro("__SHA512__");
858 
859  if (HasFXSR)
860  Builder.defineMacro("__FXSR__");
861  if (HasXSAVE)
862  Builder.defineMacro("__XSAVE__");
863  if (HasXSAVEOPT)
864  Builder.defineMacro("__XSAVEOPT__");
865  if (HasXSAVEC)
866  Builder.defineMacro("__XSAVEC__");
867  if (HasXSAVES)
868  Builder.defineMacro("__XSAVES__");
869  if (HasPKU)
870  Builder.defineMacro("__PKU__");
871  if (HasCLFLUSHOPT)
872  Builder.defineMacro("__CLFLUSHOPT__");
873  if (HasCLWB)
874  Builder.defineMacro("__CLWB__");
875  if (HasWBNOINVD)
876  Builder.defineMacro("__WBNOINVD__");
877  if (HasSHSTK)
878  Builder.defineMacro("__SHSTK__");
879  if (HasSGX)
880  Builder.defineMacro("__SGX__");
881  if (HasSM3)
882  Builder.defineMacro("__SM3__");
883  if (HasSM4)
884  Builder.defineMacro("__SM4__");
885  if (HasPREFETCHI)
886  Builder.defineMacro("__PREFETCHI__");
887  if (HasCLZERO)
888  Builder.defineMacro("__CLZERO__");
889  if (HasKL)
890  Builder.defineMacro("__KL__");
891  if (HasWIDEKL)
892  Builder.defineMacro("__WIDEKL__");
893  if (HasRDPID)
894  Builder.defineMacro("__RDPID__");
895  if (HasRDPRU)
896  Builder.defineMacro("__RDPRU__");
897  if (HasCLDEMOTE)
898  Builder.defineMacro("__CLDEMOTE__");
899  if (HasWAITPKG)
900  Builder.defineMacro("__WAITPKG__");
901  if (HasMOVDIRI)
902  Builder.defineMacro("__MOVDIRI__");
903  if (HasMOVDIR64B)
904  Builder.defineMacro("__MOVDIR64B__");
905  if (HasPCONFIG)
906  Builder.defineMacro("__PCONFIG__");
907  if (HasPTWRITE)
908  Builder.defineMacro("__PTWRITE__");
909  if (HasINVPCID)
910  Builder.defineMacro("__INVPCID__");
911  if (HasENQCMD)
912  Builder.defineMacro("__ENQCMD__");
913  if (HasHRESET)
914  Builder.defineMacro("__HRESET__");
915  if (HasAMXTILE)
916  Builder.defineMacro("__AMX_TILE__");
917  if (HasAMXINT8)
918  Builder.defineMacro("__AMX_INT8__");
919  if (HasAMXBF16)
920  Builder.defineMacro("__AMX_BF16__");
921  if (HasAMXFP16)
922  Builder.defineMacro("__AMX_FP16__");
923  if (HasAMXCOMPLEX)
924  Builder.defineMacro("__AMX_COMPLEX__");
925  if (HasCMPCCXADD)
926  Builder.defineMacro("__CMPCCXADD__");
927  if (HasRAOINT)
928  Builder.defineMacro("__RAOINT__");
929  if (HasAVXIFMA)
930  Builder.defineMacro("__AVXIFMA__");
931  if (HasAVXNECONVERT)
932  Builder.defineMacro("__AVXNECONVERT__");
933  if (HasAVXVNNI)
934  Builder.defineMacro("__AVXVNNI__");
935  if (HasAVXVNNIINT16)
936  Builder.defineMacro("__AVXVNNIINT16__");
937  if (HasAVXVNNIINT8)
938  Builder.defineMacro("__AVXVNNIINT8__");
939  if (HasSERIALIZE)
940  Builder.defineMacro("__SERIALIZE__");
941  if (HasTSXLDTRK)
942  Builder.defineMacro("__TSXLDTRK__");
943  if (HasUINTR)
944  Builder.defineMacro("__UINTR__");
945  if (HasUSERMSR)
946  Builder.defineMacro("__USERMSR__");
947  if (HasCRC32)
948  Builder.defineMacro("__CRC32__");
949  if (HasEGPR)
950  Builder.defineMacro("__EGPR__");
951  if (HasPush2Pop2)
952  Builder.defineMacro("__PUSH2POP2__");
953  if (HasPPX)
954  Builder.defineMacro("__PPX__");
955  if (HasNDD)
956  Builder.defineMacro("__NDD__");
957  if (HasCCMP)
958  Builder.defineMacro("__CCMP__");
959  if (HasNF)
960  Builder.defineMacro("__NF__");
961  if (HasCF)
962  Builder.defineMacro("__CF__");
963  // Condition here is aligned with the feature set of mapxf in Options.td
964  if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD)
965  Builder.defineMacro("__APX_F__");
966 
967  // Each case falls through to the previous one here.
968  switch (SSELevel) {
969  case AVX512F:
970  Builder.defineMacro("__AVX512F__");
971  [[fallthrough]];
972  case AVX2:
973  Builder.defineMacro("__AVX2__");
974  [[fallthrough]];
975  case AVX:
976  Builder.defineMacro("__AVX__");
977  [[fallthrough]];
978  case SSE42:
979  Builder.defineMacro("__SSE4_2__");
980  [[fallthrough]];
981  case SSE41:
982  Builder.defineMacro("__SSE4_1__");
983  [[fallthrough]];
984  case SSSE3:
985  Builder.defineMacro("__SSSE3__");
986  [[fallthrough]];
987  case SSE3:
988  Builder.defineMacro("__SSE3__");
989  [[fallthrough]];
990  case SSE2:
991  Builder.defineMacro("__SSE2__");
992  Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
993  [[fallthrough]];
994  case SSE1:
995  Builder.defineMacro("__SSE__");
996  Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
997  [[fallthrough]];
998  case NoSSE:
999  break;
1000  }
1001 
1002  if (Opts.MicrosoftExt && getTriple().getArch() == llvm::Triple::x86) {
1003  switch (SSELevel) {
1004  case AVX512F:
1005  case AVX2:
1006  case AVX:
1007  case SSE42:
1008  case SSE41:
1009  case SSSE3:
1010  case SSE3:
1011  case SSE2:
1012  Builder.defineMacro("_M_IX86_FP", Twine(2));
1013  break;
1014  case SSE1:
1015  Builder.defineMacro("_M_IX86_FP", Twine(1));
1016  break;
1017  default:
1018  Builder.defineMacro("_M_IX86_FP", Twine(0));
1019  break;
1020  }
1021  }
1022 
1023  // Each case falls through to the previous one here.
1024  switch (MMX3DNowLevel) {
1025  case AMD3DNowAthlon:
1026  Builder.defineMacro("__3dNOW_A__");
1027  [[fallthrough]];
1028  case AMD3DNow:
1029  Builder.defineMacro("__3dNOW__");
1030  [[fallthrough]];
1031  case MMX:
1032  Builder.defineMacro("__MMX__");
1033  [[fallthrough]];
1034  case NoMMX3DNow:
1035  break;
1036  }
1037 
1038  if (CPU >= CK_i486 || CPU == CK_None) {
1039  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
1040  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
1041  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
1042  }
1043  if (HasCX8)
1044  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
1045  if (HasCX16 && getTriple().getArch() == llvm::Triple::x86_64)
1046  Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
1047 
1048  if (HasFloat128)
1049  Builder.defineMacro("__SIZEOF_FLOAT128__", "16");
1050 }
1051 
1052 bool X86TargetInfo::isValidFeatureName(StringRef Name) const {
1053  return llvm::StringSwitch<bool>(Name)
1054  .Case("3dnow", true)
1055  .Case("3dnowa", true)
1056  .Case("adx", true)
1057  .Case("aes", true)
1058  .Case("amx-bf16", true)
1059  .Case("amx-complex", true)
1060  .Case("amx-fp16", true)
1061  .Case("amx-int8", true)
1062  .Case("amx-tile", true)
1063  .Case("avx", true)
1064  .Case("avx10.1-256", true)
1065  .Case("avx10.1-512", true)
1066  .Case("avx2", true)
1067  .Case("avx512f", true)
1068  .Case("avx512cd", true)
1069  .Case("avx512vpopcntdq", true)
1070  .Case("avx512vnni", true)
1071  .Case("avx512bf16", true)
1072  .Case("avx512fp16", true)
1073  .Case("avx512dq", true)
1074  .Case("avx512bitalg", true)
1075  .Case("avx512bw", true)
1076  .Case("avx512vl", true)
1077  .Case("avx512vbmi", true)
1078  .Case("avx512vbmi2", true)
1079  .Case("avx512ifma", true)
1080  .Case("avx512vp2intersect", true)
1081  .Case("avxifma", true)
1082  .Case("avxneconvert", true)
1083  .Case("avxvnni", true)
1084  .Case("avxvnniint16", true)
1085  .Case("avxvnniint8", true)
1086  .Case("bmi", true)
1087  .Case("bmi2", true)
1088  .Case("cldemote", true)
1089  .Case("clflushopt", true)
1090  .Case("clwb", true)
1091  .Case("clzero", true)
1092  .Case("cmpccxadd", true)
1093  .Case("crc32", true)
1094  .Case("cx16", true)
1095  .Case("enqcmd", true)
1096  .Case("evex512", true)
1097  .Case("f16c", true)
1098  .Case("fma", true)
1099  .Case("fma4", true)
1100  .Case("fsgsbase", true)
1101  .Case("fxsr", true)
1102  .Case("general-regs-only", true)
1103  .Case("gfni", true)
1104  .Case("hreset", true)
1105  .Case("invpcid", true)
1106  .Case("kl", true)
1107  .Case("widekl", true)
1108  .Case("lwp", true)
1109  .Case("lzcnt", true)
1110  .Case("mmx", true)
1111  .Case("movbe", true)
1112  .Case("movdiri", true)
1113  .Case("movdir64b", true)
1114  .Case("mwaitx", true)
1115  .Case("pclmul", true)
1116  .Case("pconfig", true)
1117  .Case("pku", true)
1118  .Case("popcnt", true)
1119  .Case("prefetchi", true)
1120  .Case("prfchw", true)
1121  .Case("ptwrite", true)
1122  .Case("raoint", true)
1123  .Case("rdpid", true)
1124  .Case("rdpru", true)
1125  .Case("rdrnd", true)
1126  .Case("rdseed", true)
1127  .Case("rtm", true)
1128  .Case("sahf", true)
1129  .Case("serialize", true)
1130  .Case("sgx", true)
1131  .Case("sha", true)
1132  .Case("sha512", true)
1133  .Case("shstk", true)
1134  .Case("sm3", true)
1135  .Case("sm4", true)
1136  .Case("sse", true)
1137  .Case("sse2", true)
1138  .Case("sse3", true)
1139  .Case("ssse3", true)
1140  .Case("sse4", true)
1141  .Case("sse4.1", true)
1142  .Case("sse4.2", true)
1143  .Case("sse4a", true)
1144  .Case("tbm", true)
1145  .Case("tsxldtrk", true)
1146  .Case("uintr", true)
1147  .Case("usermsr", true)
1148  .Case("vaes", true)
1149  .Case("vpclmulqdq", true)
1150  .Case("wbnoinvd", true)
1151  .Case("waitpkg", true)
1152  .Case("x87", true)
1153  .Case("xop", true)
1154  .Case("xsave", true)
1155  .Case("xsavec", true)
1156  .Case("xsaves", true)
1157  .Case("xsaveopt", true)
1158  .Case("egpr", true)
1159  .Case("push2pop2", true)
1160  .Case("ppx", true)
1161  .Case("ndd", true)
1162  .Case("ccmp", true)
1163  .Case("nf", true)
1164  .Case("cf", true)
1165  .Default(false);
1166 }
1167 
1168 bool X86TargetInfo::hasFeature(StringRef Feature) const {
1169  return llvm::StringSwitch<bool>(Feature)
1170  .Case("adx", HasADX)
1171  .Case("aes", HasAES)
1172  .Case("amx-bf16", HasAMXBF16)
1173  .Case("amx-complex", HasAMXCOMPLEX)
1174  .Case("amx-fp16", HasAMXFP16)
1175  .Case("amx-int8", HasAMXINT8)
1176  .Case("amx-tile", HasAMXTILE)
1177  .Case("avx", SSELevel >= AVX)
1178  .Case("avx10.1-256", HasAVX10_1)
1179  .Case("avx10.1-512", HasAVX10_1_512)
1180  .Case("avx2", SSELevel >= AVX2)
1181  .Case("avx512f", SSELevel >= AVX512F)
1182  .Case("avx512cd", HasAVX512CD)
1183  .Case("avx512vpopcntdq", HasAVX512VPOPCNTDQ)
1184  .Case("avx512vnni", HasAVX512VNNI)
1185  .Case("avx512bf16", HasAVX512BF16)
1186  .Case("avx512fp16", HasAVX512FP16)
1187  .Case("avx512dq", HasAVX512DQ)
1188  .Case("avx512bitalg", HasAVX512BITALG)
1189  .Case("avx512bw", HasAVX512BW)
1190  .Case("avx512vl", HasAVX512VL)
1191  .Case("avx512vbmi", HasAVX512VBMI)
1192  .Case("avx512vbmi2", HasAVX512VBMI2)
1193  .Case("avx512ifma", HasAVX512IFMA)
1194  .Case("avx512vp2intersect", HasAVX512VP2INTERSECT)
1195  .Case("avxifma", HasAVXIFMA)
1196  .Case("avxneconvert", HasAVXNECONVERT)
1197  .Case("avxvnni", HasAVXVNNI)
1198  .Case("avxvnniint16", HasAVXVNNIINT16)
1199  .Case("avxvnniint8", HasAVXVNNIINT8)
1200  .Case("bmi", HasBMI)
1201  .Case("bmi2", HasBMI2)
1202  .Case("cldemote", HasCLDEMOTE)
1203  .Case("clflushopt", HasCLFLUSHOPT)
1204  .Case("clwb", HasCLWB)
1205  .Case("clzero", HasCLZERO)
1206  .Case("cmpccxadd", HasCMPCCXADD)
1207  .Case("crc32", HasCRC32)
1208  .Case("cx8", HasCX8)
1209  .Case("cx16", HasCX16)
1210  .Case("enqcmd", HasENQCMD)
1211  .Case("evex512", HasEVEX512)
1212  .Case("f16c", HasF16C)
1213  .Case("fma", HasFMA)
1214  .Case("fma4", XOPLevel >= FMA4)
1215  .Case("fsgsbase", HasFSGSBASE)
1216  .Case("fxsr", HasFXSR)
1217  .Case("gfni", HasGFNI)
1218  .Case("hreset", HasHRESET)
1219  .Case("invpcid", HasINVPCID)
1220  .Case("kl", HasKL)
1221  .Case("widekl", HasWIDEKL)
1222  .Case("lwp", HasLWP)
1223  .Case("lzcnt", HasLZCNT)
1224  .Case("mm3dnow", MMX3DNowLevel >= AMD3DNow)
1225  .Case("mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon)
1226  .Case("mmx", MMX3DNowLevel >= MMX)
1227  .Case("movbe", HasMOVBE)
1228  .Case("movdiri", HasMOVDIRI)
1229  .Case("movdir64b", HasMOVDIR64B)
1230  .Case("mwaitx", HasMWAITX)
1231  .Case("pclmul", HasPCLMUL)
1232  .Case("pconfig", HasPCONFIG)
1233  .Case("pku", HasPKU)
1234  .Case("popcnt", HasPOPCNT)
1235  .Case("prefetchi", HasPREFETCHI)
1236  .Case("prfchw", HasPRFCHW)
1237  .Case("ptwrite", HasPTWRITE)
1238  .Case("raoint", HasRAOINT)
1239  .Case("rdpid", HasRDPID)
1240  .Case("rdpru", HasRDPRU)
1241  .Case("rdrnd", HasRDRND)
1242  .Case("rdseed", HasRDSEED)
1243  .Case("retpoline-external-thunk", HasRetpolineExternalThunk)
1244  .Case("rtm", HasRTM)
1245  .Case("sahf", HasLAHFSAHF)
1246  .Case("serialize", HasSERIALIZE)
1247  .Case("sgx", HasSGX)
1248  .Case("sha", HasSHA)
1249  .Case("sha512", HasSHA512)
1250  .Case("shstk", HasSHSTK)
1251  .Case("sm3", HasSM3)
1252  .Case("sm4", HasSM4)
1253  .Case("sse", SSELevel >= SSE1)
1254  .Case("sse2", SSELevel >= SSE2)
1255  .Case("sse3", SSELevel >= SSE3)
1256  .Case("ssse3", SSELevel >= SSSE3)
1257  .Case("sse4.1", SSELevel >= SSE41)
1258  .Case("sse4.2", SSELevel >= SSE42)
1259  .Case("sse4a", XOPLevel >= SSE4A)
1260  .Case("tbm", HasTBM)
1261  .Case("tsxldtrk", HasTSXLDTRK)
1262  .Case("uintr", HasUINTR)
1263  .Case("usermsr", HasUSERMSR)
1264  .Case("vaes", HasVAES)
1265  .Case("vpclmulqdq", HasVPCLMULQDQ)
1266  .Case("wbnoinvd", HasWBNOINVD)
1267  .Case("waitpkg", HasWAITPKG)
1268  .Case("x86", true)
1269  .Case("x86_32", getTriple().getArch() == llvm::Triple::x86)
1270  .Case("x86_64", getTriple().getArch() == llvm::Triple::x86_64)
1271  .Case("x87", HasX87)
1272  .Case("xop", XOPLevel >= XOP)
1273  .Case("xsave", HasXSAVE)
1274  .Case("xsavec", HasXSAVEC)
1275  .Case("xsaves", HasXSAVES)
1276  .Case("xsaveopt", HasXSAVEOPT)
1277  .Case("fullbf16", HasFullBFloat16)
1278  .Case("egpr", HasEGPR)
1279  .Case("push2pop2", HasPush2Pop2)
1280  .Case("ppx", HasPPX)
1281  .Case("ndd", HasNDD)
1282  .Case("ccmp", HasCCMP)
1283  .Case("nf", HasNF)
1284  .Case("cf", HasCF)
1285  .Default(false);
1286 }
1287 
1288 // We can't use a generic validation scheme for the features accepted here
1289 // versus subtarget features accepted in the target attribute because the
1290 // bitfield structure that's initialized in the runtime only supports the
1291 // below currently rather than the full range of subtarget features. (See
1292 // X86TargetInfo::hasFeature for a somewhat comprehensive list).
1293 bool X86TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
1294  return llvm::StringSwitch<bool>(FeatureStr)
1295 #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) .Case(STR, true)
1296 #define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY) .Case(STR, true)
1297 #include "llvm/TargetParser/X86TargetParser.def"
1298  .Default(false);
1299 }
1300 
1301 static llvm::X86::ProcessorFeatures getFeature(StringRef Name) {
1302  return llvm::StringSwitch<llvm::X86::ProcessorFeatures>(Name)
1303 #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \
1304  .Case(STR, llvm::X86::FEATURE_##ENUM)
1305 
1306 #include "llvm/TargetParser/X86TargetParser.def"
1307  ;
1308  // Note, this function should only be used after ensuring the value is
1309  // correct, so it asserts if the value is out of range.
1310 }
1311 
1312 unsigned X86TargetInfo::multiVersionSortPriority(StringRef Name) const {
1313  // Valid CPUs have a 'key feature' that compares just better than its key
1314  // feature.
1315  using namespace llvm::X86;
1316  CPUKind Kind = parseArchX86(Name);
1317  if (Kind != CK_None) {
1318  ProcessorFeatures KeyFeature = getKeyFeature(Kind);
1319  return (getFeaturePriority(KeyFeature) << 1) + 1;
1320  }
1321 
1322  // Now we know we have a feature, so get its priority and shift it a few so
1323  // that we have sufficient room for the CPUs (above).
1324  return getFeaturePriority(getFeature(Name)) << 1;
1325 }
1326 
1328  return llvm::X86::validateCPUSpecificCPUDispatch(Name);
1329 }
1330 
1332  return llvm::X86::getCPUDispatchMangling(Name);
1333 }
1334 
1336  StringRef Name, llvm::SmallVectorImpl<StringRef> &Features) const {
1337  SmallVector<StringRef, 32> TargetCPUFeatures;
1338  llvm::X86::getFeaturesForCPU(Name, TargetCPUFeatures, true);
1339  for (auto &F : TargetCPUFeatures)
1340  Features.push_back(F);
1341 }
1342 
1343 // We can't use a generic validation scheme for the cpus accepted here
1344 // versus subtarget cpus accepted in the target attribute because the
1345 // variables intitialized by the runtime only support the below currently
1346 // rather than the full range of cpus.
1347 bool X86TargetInfo::validateCpuIs(StringRef FeatureStr) const {
1348  return llvm::StringSwitch<bool>(FeatureStr)
1349 #define X86_VENDOR(ENUM, STRING) .Case(STRING, true)
1350 #define X86_CPU_TYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1351 #define X86_CPU_TYPE(ENUM, STR) .Case(STR, true)
1352 #define X86_CPU_SUBTYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1353 #define X86_CPU_SUBTYPE(ENUM, STR) .Case(STR, true)
1354 #include "llvm/TargetParser/X86TargetParser.def"
1355  .Default(false);
1356 }
1357 
1358 static unsigned matchAsmCCConstraint(const char *Name) {
1359  auto RV = llvm::StringSwitch<unsigned>(Name)
1360  .Case("@cca", 4)
1361  .Case("@ccae", 5)
1362  .Case("@ccb", 4)
1363  .Case("@ccbe", 5)
1364  .Case("@ccc", 4)
1365  .Case("@cce", 4)
1366  .Case("@ccz", 4)
1367  .Case("@ccg", 4)
1368  .Case("@ccge", 5)
1369  .Case("@ccl", 4)
1370  .Case("@ccle", 5)
1371  .Case("@ccna", 5)
1372  .Case("@ccnae", 6)
1373  .Case("@ccnb", 5)
1374  .Case("@ccnbe", 6)
1375  .Case("@ccnc", 5)
1376  .Case("@ccne", 5)
1377  .Case("@ccnz", 5)
1378  .Case("@ccng", 5)
1379  .Case("@ccnge", 6)
1380  .Case("@ccnl", 5)
1381  .Case("@ccnle", 6)
1382  .Case("@ccno", 5)
1383  .Case("@ccnp", 5)
1384  .Case("@ccns", 5)
1385  .Case("@cco", 4)
1386  .Case("@ccp", 4)
1387  .Case("@ccs", 4)
1388  .Default(0);
1389  return RV;
1390 }
1391 
1393  const char *&Name, TargetInfo::ConstraintInfo &Info) const {
1394  switch (*Name) {
1395  default:
1396  return false;
1397  // Constant constraints.
1398  case 'e': // 32-bit signed integer constant for use with sign-extending x86_64
1399  // instructions.
1400  case 'Z': // 32-bit unsigned integer constant for use with zero-extending
1401  // x86_64 instructions.
1402  case 's':
1403  Info.setRequiresImmediate();
1404  return true;
1405  case 'I':
1406  Info.setRequiresImmediate(0, 31);
1407  return true;
1408  case 'J':
1409  Info.setRequiresImmediate(0, 63);
1410  return true;
1411  case 'K':
1412  Info.setRequiresImmediate(-128, 127);
1413  return true;
1414  case 'L':
1415  Info.setRequiresImmediate({int(0xff), int(0xffff), int(0xffffffff)});
1416  return true;
1417  case 'M':
1418  Info.setRequiresImmediate(0, 3);
1419  return true;
1420  case 'N':
1421  Info.setRequiresImmediate(0, 255);
1422  return true;
1423  case 'O':
1424  Info.setRequiresImmediate(0, 127);
1425  return true;
1426  case 'W':
1427  switch (*++Name) {
1428  default:
1429  return false;
1430  case 's':
1431  Info.setAllowsRegister();
1432  return true;
1433  }
1434  // Register constraints.
1435  case 'Y': // 'Y' is the first character for several 2-character constraints.
1436  // Shift the pointer to the second character of the constraint.
1437  Name++;
1438  switch (*Name) {
1439  default:
1440  return false;
1441  case 'z': // First SSE register.
1442  case '2':
1443  case 't': // Any SSE register, when SSE2 is enabled.
1444  case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
1445  case 'm': // Any MMX register, when inter-unit moves enabled.
1446  case 'k': // AVX512 arch mask registers: k1-k7.
1447  Info.setAllowsRegister();
1448  return true;
1449  }
1450  case 'f': // Any x87 floating point stack register.
1451  // Constraint 'f' cannot be used for output operands.
1452  if (Info.ConstraintStr[0] == '=')
1453  return false;
1454  Info.setAllowsRegister();
1455  return true;
1456  case 'a': // eax.
1457  case 'b': // ebx.
1458  case 'c': // ecx.
1459  case 'd': // edx.
1460  case 'S': // esi.
1461  case 'D': // edi.
1462  case 'A': // edx:eax.
1463  case 't': // Top of floating point stack.
1464  case 'u': // Second from top of floating point stack.
1465  case 'q': // Any register accessible as [r]l: a, b, c, and d.
1466  case 'y': // Any MMX register.
1467  case 'v': // Any {X,Y,Z}MM register (Arch & context dependent)
1468  case 'x': // Any SSE register.
1469  case 'k': // Any AVX512 mask register (same as Yk, additionally allows k0
1470  // for intermideate k reg operations).
1471  case 'Q': // Any register accessible as [r]h: a, b, c, and d.
1472  case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
1473  case 'l': // "Index" registers: any general register that can be used as an
1474  // index in a base+index memory access.
1475  Info.setAllowsRegister();
1476  return true;
1477  // Floating point constant constraints.
1478  case 'C': // SSE floating point constant.
1479  case 'G': // x87 floating point constant.
1480  return true;
1481  case '@':
1482  // CC condition changes.
1483  if (auto Len = matchAsmCCConstraint(Name)) {
1484  Name += Len - 1;
1485  Info.setAllowsRegister();
1486  return true;
1487  }
1488  return false;
1489  }
1490 }
1491 
1492 // Below is based on the following information:
1493 // +------------------------------------+-------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
1494 // | Processor Name | Cache Line Size (Bytes) | Source |
1495 // +------------------------------------+-------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
1496 // | i386 | 64 | https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf |
1497 // | i486 | 16 | "four doublewords" (doubleword = 32 bits, 4 bits * 32 bits = 16 bytes) https://en.wikichip.org/w/images/d/d3/i486_MICROPROCESSOR_HARDWARE_REFERENCE_MANUAL_%281990%29.pdf and http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.126.4216&rep=rep1&type=pdf (page 29) |
1498 // | i586/Pentium MMX | 32 | https://www.7-cpu.com/cpu/P-MMX.html |
1499 // | i686/Pentium | 32 | https://www.7-cpu.com/cpu/P6.html |
1500 // | Netburst/Pentium4 | 64 | https://www.7-cpu.com/cpu/P4-180.html |
1501 // | Atom | 64 | https://www.7-cpu.com/cpu/Atom.html |
1502 // | Westmere | 64 | https://en.wikichip.org/wiki/intel/microarchitectures/sandy_bridge_(client) "Cache Architecture" |
1503 // | Sandy Bridge | 64 | https://en.wikipedia.org/wiki/Sandy_Bridge and https://www.7-cpu.com/cpu/SandyBridge.html |
1504 // | Ivy Bridge | 64 | https://blog.stuffedcow.net/2013/01/ivb-cache-replacement/ and https://www.7-cpu.com/cpu/IvyBridge.html |
1505 // | Haswell | 64 | https://www.7-cpu.com/cpu/Haswell.html |
1506 // | Broadwell | 64 | https://www.7-cpu.com/cpu/Broadwell.html |
1507 // | Skylake (including skylake-avx512) | 64 | https://www.nas.nasa.gov/hecc/support/kb/skylake-processors_550.html "Cache Hierarchy" |
1508 // | Cascade Lake | 64 | https://www.nas.nasa.gov/hecc/support/kb/cascade-lake-processors_579.html "Cache Hierarchy" |
1509 // | Skylake | 64 | https://en.wikichip.org/wiki/intel/microarchitectures/kaby_lake "Memory Hierarchy" |
1510 // | Ice Lake | 64 | https://www.7-cpu.com/cpu/Ice_Lake.html |
1511 // | Knights Landing | 64 | https://software.intel.com/en-us/articles/intel-xeon-phi-processor-7200-family-memory-management-optimizations "The Intel® Xeon Phiâ„¢ Processor Architecture" |
1512 // | Knights Mill | 64 | https://software.intel.com/sites/default/files/managed/9e/bc/64-ia-32-architectures-optimization-manual.pdf?countrylabel=Colombia "2.5.5.2 L1 DCache " |
1513 // +------------------------------------+-------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
1514 std::optional<unsigned> X86TargetInfo::getCPUCacheLineSize() const {
1515  using namespace llvm::X86;
1516  switch (CPU) {
1517  // i386
1518  case CK_i386:
1519  // i486
1520  case CK_i486:
1521  case CK_WinChipC6:
1522  case CK_WinChip2:
1523  case CK_C3:
1524  // Lakemont
1525  case CK_Lakemont:
1526  return 16;
1527 
1528  // i586
1529  case CK_i586:
1530  case CK_Pentium:
1531  case CK_PentiumMMX:
1532  // i686
1533  case CK_PentiumPro:
1534  case CK_i686:
1535  case CK_Pentium2:
1536  case CK_Pentium3:
1537  case CK_PentiumM:
1538  case CK_C3_2:
1539  // K6
1540  case CK_K6:
1541  case CK_K6_2:
1542  case CK_K6_3:
1543  // Geode
1544  case CK_Geode:
1545  return 32;
1546 
1547  // Netburst
1548  case CK_Pentium4:
1549  case CK_Prescott:
1550  case CK_Nocona:
1551  // Atom
1552  case CK_Bonnell:
1553  case CK_Silvermont:
1554  case CK_Goldmont:
1555  case CK_GoldmontPlus:
1556  case CK_Tremont:
1557  case CK_Gracemont:
1558 
1559  case CK_Westmere:
1560  case CK_SandyBridge:
1561  case CK_IvyBridge:
1562  case CK_Haswell:
1563  case CK_Broadwell:
1564  case CK_SkylakeClient:
1565  case CK_SkylakeServer:
1566  case CK_Cascadelake:
1567  case CK_Nehalem:
1568  case CK_Cooperlake:
1569  case CK_Cannonlake:
1570  case CK_Tigerlake:
1571  case CK_SapphireRapids:
1572  case CK_IcelakeClient:
1573  case CK_Rocketlake:
1574  case CK_IcelakeServer:
1575  case CK_Alderlake:
1576  case CK_Raptorlake:
1577  case CK_Meteorlake:
1578  case CK_Arrowlake:
1579  case CK_ArrowlakeS:
1580  case CK_Lunarlake:
1581  case CK_Pantherlake:
1582  case CK_Sierraforest:
1583  case CK_Grandridge:
1584  case CK_Graniterapids:
1585  case CK_GraniterapidsD:
1586  case CK_Emeraldrapids:
1587  case CK_Clearwaterforest:
1588  case CK_KNL:
1589  case CK_KNM:
1590  // K7
1591  case CK_Athlon:
1592  case CK_AthlonXP:
1593  // K8
1594  case CK_K8:
1595  case CK_K8SSE3:
1596  case CK_AMDFAM10:
1597  // Bobcat
1598  case CK_BTVER1:
1599  case CK_BTVER2:
1600  // Bulldozer
1601  case CK_BDVER1:
1602  case CK_BDVER2:
1603  case CK_BDVER3:
1604  case CK_BDVER4:
1605  // Zen
1606  case CK_ZNVER1:
1607  case CK_ZNVER2:
1608  case CK_ZNVER3:
1609  case CK_ZNVER4:
1610  // Deprecated
1611  case CK_x86_64:
1612  case CK_x86_64_v2:
1613  case CK_x86_64_v3:
1614  case CK_x86_64_v4:
1615  case CK_Yonah:
1616  case CK_Penryn:
1617  case CK_Core2:
1618  return 64;
1619 
1620  // The following currently have unknown cache line sizes (but they are probably all 64):
1621  // Core
1622  case CK_None:
1623  return std::nullopt;
1624  }
1625  llvm_unreachable("Unknown CPU kind");
1626 }
1627 
1628 bool X86TargetInfo::validateOutputSize(const llvm::StringMap<bool> &FeatureMap,
1629  StringRef Constraint,
1630  unsigned Size) const {
1631  // Strip off constraint modifiers.
1632  Constraint = Constraint.ltrim("=+&");
1633 
1634  return validateOperandSize(FeatureMap, Constraint, Size);
1635 }
1636 
1637 bool X86TargetInfo::validateInputSize(const llvm::StringMap<bool> &FeatureMap,
1638  StringRef Constraint,
1639  unsigned Size) const {
1640  return validateOperandSize(FeatureMap, Constraint, Size);
1641 }
1642 
1643 bool X86TargetInfo::validateOperandSize(const llvm::StringMap<bool> &FeatureMap,
1644  StringRef Constraint,
1645  unsigned Size) const {
1646  switch (Constraint[0]) {
1647  default:
1648  break;
1649  case 'k':
1650  // Registers k0-k7 (AVX512) size limit is 64 bit.
1651  case 'y':
1652  return Size <= 64;
1653  case 'f':
1654  case 't':
1655  case 'u':
1656  return Size <= 128;
1657  case 'Y':
1658  // 'Y' is the first character for several 2-character constraints.
1659  switch (Constraint[1]) {
1660  default:
1661  return false;
1662  case 'm':
1663  // 'Ym' is synonymous with 'y'.
1664  case 'k':
1665  return Size <= 64;
1666  case 'z':
1667  // XMM0/YMM/ZMM0
1668  if (hasFeatureEnabled(FeatureMap, "avx512f") &&
1669  hasFeatureEnabled(FeatureMap, "evex512"))
1670  // ZMM0 can be used if target supports AVX512F and EVEX512 is set.
1671  return Size <= 512U;
1672  else if (hasFeatureEnabled(FeatureMap, "avx"))
1673  // YMM0 can be used if target supports AVX.
1674  return Size <= 256U;
1675  else if (hasFeatureEnabled(FeatureMap, "sse"))
1676  return Size <= 128U;
1677  return false;
1678  case 'i':
1679  case 't':
1680  case '2':
1681  // 'Yi','Yt','Y2' are synonymous with 'x' when SSE2 is enabled.
1682  if (SSELevel < SSE2)
1683  return false;
1684  break;
1685  }
1686  break;
1687  case 'v':
1688  case 'x':
1689  if (hasFeatureEnabled(FeatureMap, "avx512f") &&
1690  hasFeatureEnabled(FeatureMap, "evex512"))
1691  // 512-bit zmm registers can be used if target supports AVX512F and
1692  // EVEX512 is set.
1693  return Size <= 512U;
1694  else if (hasFeatureEnabled(FeatureMap, "avx"))
1695  // 256-bit ymm registers can be used if target supports AVX.
1696  return Size <= 256U;
1697  return Size <= 128U;
1698 
1699  }
1700 
1701  return true;
1702 }
1703 
1704 std::string X86TargetInfo::convertConstraint(const char *&Constraint) const {
1705  switch (*Constraint) {
1706  case '@':
1707  if (auto Len = matchAsmCCConstraint(Constraint)) {
1708  std::string Converted = "{" + std::string(Constraint, Len) + "}";
1709  Constraint += Len - 1;
1710  return Converted;
1711  }
1712  return std::string(1, *Constraint);
1713  case 'a':
1714  return std::string("{ax}");
1715  case 'b':
1716  return std::string("{bx}");
1717  case 'c':
1718  return std::string("{cx}");
1719  case 'd':
1720  return std::string("{dx}");
1721  case 'S':
1722  return std::string("{si}");
1723  case 'D':
1724  return std::string("{di}");
1725  case 'p': // Keep 'p' constraint (address).
1726  return std::string("p");
1727  case 't': // top of floating point stack.
1728  return std::string("{st}");
1729  case 'u': // second from top of floating point stack.
1730  return std::string("{st(1)}"); // second from top of floating point stack.
1731  case 'W':
1732  assert(Constraint[1] == 's');
1733  return '^' + std::string(Constraint++, 2);
1734  case 'Y':
1735  switch (Constraint[1]) {
1736  default:
1737  // Break from inner switch and fall through (copy single char),
1738  // continue parsing after copying the current constraint into
1739  // the return string.
1740  break;
1741  case 'k':
1742  case 'm':
1743  case 'i':
1744  case 't':
1745  case 'z':
1746  case '2':
1747  // "^" hints llvm that this is a 2 letter constraint.
1748  // "Constraint++" is used to promote the string iterator
1749  // to the next constraint.
1750  return std::string("^") + std::string(Constraint++, 2);
1751  }
1752  [[fallthrough]];
1753  default:
1754  return std::string(1, *Constraint);
1755  }
1756 }
1757 
1759  bool Only64Bit = getTriple().getArch() != llvm::Triple::x86;
1760  llvm::X86::fillValidCPUArchList(Values, Only64Bit);
1761 }
1762 
1764  llvm::X86::fillValidTuneCPUList(Values);
1765 }
1766 
1768  return llvm::ArrayRef(GCCRegNames);
1769 }
1770 
1772  return llvm::ArrayRef(AddlRegNames);
1773 }
1774 
1778 }
1779 
1783 }
Defines the Diagnostic-related interfaces.
static unsigned matchAsmCCConstraint(const char *Name)
Definition: X86.cpp:1358
static llvm::X86::ProcessorFeatures getFeature(StringRef Name)
Definition: X86.cpp:1301
Defines enum values for all the target-independent builtin functions.
Enumerates target-specific builtins in their own namespaces within namespace clang.
__DEVICE__ int max(int __a, int __b)
__device__ int
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:193
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1553
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:482
virtual bool hasFeatureEnabled(const llvm::StringMap< bool > &Features, StringRef Name) const
Check if target has a given feature enabled.
Definition: TargetInfo.h:1379
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1256
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: TargetInfo.cpp:566
TargetOptions & getTargetOpts() const
Retrieve the target options.
Definition: TargetInfo.h:312
enum clang::targets::X86TargetInfo::FPMathKind FPMath
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
handleTargetFeatures - Perform initialization based on the user configured set of features.
Definition: X86.cpp:255
std::optional< unsigned > getCPUCacheLineSize() const override
Definition: X86.cpp:1514
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition: X86.cpp:1392
unsigned multiVersionSortPriority(StringRef Name) const override
Definition: X86.cpp:1312
bool setFPMath(StringRef Name) override
Use the specified unit for FP math.
Definition: X86.cpp:111
ArrayRef< const char * > getGCCRegNames() const override
Definition: X86.cpp:1767
char CPUSpecificManglingCharacter(StringRef Name) const override
Definition: X86.cpp:1331
std::string convertConstraint(const char *&Constraint) const override
Definition: X86.cpp:1704
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.cpp:518
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeaturesVec) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: X86.cpp:123
void getCPUSpecificCPUDispatchFeatures(StringRef Name, llvm::SmallVectorImpl< StringRef > &Features) const override
Definition: X86.cpp:1335
bool validateCpuIs(StringRef FeatureStr) const override
Definition: X86.cpp:1347
bool validateOutputSize(const llvm::StringMap< bool > &FeatureMap, StringRef Constraint, unsigned Size) const override
Definition: X86.cpp:1628
virtual bool validateOperandSize(const llvm::StringMap< bool > &FeatureMap, StringRef Constraint, unsigned Size) const
Definition: X86.cpp:1643
void fillValidTuneCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values for tuning CPU.
Definition: X86.cpp:1763
bool validateCPUSpecificCPUDispatch(StringRef Name) const override
Definition: X86.cpp:1327
bool validateCpuSupports(StringRef FeatureStr) const override
Definition: X86.cpp:1293
bool isValidFeatureName(StringRef Name) const override
Determine whether this TargetInfo supports the given feature.
Definition: X86.cpp:1052
bool hasFeature(StringRef Feature) const final
Determine whether the given target has the given feature.
Definition: X86.cpp:1168
void setFeatureEnabled(llvm::StringMap< bool > &Features, StringRef Name, bool Enabled) const final
Enable or disable a specific target feature; the feature name must be valid.
Definition: X86.cpp:236
llvm::X86::CPUKind CPU
Definition: X86.h:177
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition: X86.cpp:1758
ArrayRef< TargetInfo::AddlRegName > getGCCAddlRegNames() const override
Definition: X86.cpp:1771
bool validateInputSize(const llvm::StringMap< bool > &FeatureMap, StringRef Constraint, unsigned Size) const override
Definition: X86.cpp:1637
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: X86.cpp:1775
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: X86.cpp:1780
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
Definition: Targets.cpp:76
static constexpr Builtin::Info BuiltinInfoX86[]
Definition: X86.cpp:26
const TargetInfo::AddlRegName AddlRegNames[]
Definition: X86.cpp:71
static const char *const GCCRegNames[]
Definition: X86.cpp:44
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:60
The JSON file list parser is used to communicate input to InstallAPI.
void setRequiresImmediate(int Min, int Max)
Definition: TargetInfo.h:1153
const llvm::fltSemantics * LongDoubleFormat
Definition: TargetInfo.h:139