clang 20.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"
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
23namespace clang {
24namespace targets {
25
26static 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
44static 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
108using namespace clang;
109using namespace clang::targets;
110
111bool 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
236void 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.
255bool 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 == "+mmx") {
262 HasMMX = true;
263 } else if (Feature == "+aes") {
264 HasAES = true;
265 } else if (Feature == "+vaes") {
266 HasVAES = true;
267 } else if (Feature == "+pclmul") {
268 HasPCLMUL = true;
269 } else if (Feature == "+vpclmulqdq") {
270 HasVPCLMULQDQ = true;
271 } else if (Feature == "+lzcnt") {
272 HasLZCNT = true;
273 } else if (Feature == "+rdrnd") {
274 HasRDRND = true;
275 } else if (Feature == "+fsgsbase") {
276 HasFSGSBASE = true;
277 } else if (Feature == "+bmi") {
278 HasBMI = true;
279 } else if (Feature == "+bmi2") {
280 HasBMI2 = true;
281 } else if (Feature == "+popcnt") {
282 HasPOPCNT = true;
283 } else if (Feature == "+rtm") {
284 HasRTM = true;
285 } else if (Feature == "+prfchw") {
286 HasPRFCHW = true;
287 } else if (Feature == "+rdseed") {
288 HasRDSEED = true;
289 } else if (Feature == "+adx") {
290 HasADX = true;
291 } else if (Feature == "+tbm") {
292 HasTBM = true;
293 } else if (Feature == "+lwp") {
294 HasLWP = true;
295 } else if (Feature == "+fma") {
296 HasFMA = true;
297 } else if (Feature == "+f16c") {
298 HasF16C = true;
299 } else if (Feature == "+gfni") {
300 HasGFNI = true;
301 } else if (Feature == "+evex512") {
302 HasEVEX512 = true;
303 } else if (Feature == "+avx10.1-256") {
304 HasAVX10_1 = true;
305 } else if (Feature == "+avx10.1-512") {
306 HasAVX10_1_512 = true;
307 } else if (Feature == "+avx512cd") {
308 HasAVX512CD = true;
309 } else if (Feature == "+avx512vpopcntdq") {
310 HasAVX512VPOPCNTDQ = true;
311 } else if (Feature == "+avx512vnni") {
312 HasAVX512VNNI = true;
313 } else if (Feature == "+avx512bf16") {
314 HasAVX512BF16 = true;
315 } else if (Feature == "+avx512fp16") {
316 HasAVX512FP16 = true;
317 HasLegalHalfType = true;
318 } else if (Feature == "+avx512dq") {
319 HasAVX512DQ = true;
320 } else if (Feature == "+avx512bitalg") {
321 HasAVX512BITALG = true;
322 } else if (Feature == "+avx512bw") {
323 HasAVX512BW = true;
324 } else if (Feature == "+avx512vl") {
325 HasAVX512VL = true;
326 } else if (Feature == "+avx512vbmi") {
327 HasAVX512VBMI = true;
328 } else if (Feature == "+avx512vbmi2") {
329 HasAVX512VBMI2 = true;
330 } else if (Feature == "+avx512ifma") {
331 HasAVX512IFMA = true;
332 } else if (Feature == "+avx512vp2intersect") {
333 HasAVX512VP2INTERSECT = true;
334 } else if (Feature == "+sha") {
335 HasSHA = true;
336 } else if (Feature == "+sha512") {
337 HasSHA512 = true;
338 } else if (Feature == "+shstk") {
339 HasSHSTK = true;
340 } else if (Feature == "+sm3") {
341 HasSM3 = true;
342 } else if (Feature == "+sm4") {
343 HasSM4 = true;
344 } else if (Feature == "+movbe") {
345 HasMOVBE = true;
346 } else if (Feature == "+sgx") {
347 HasSGX = true;
348 } else if (Feature == "+cx8") {
349 HasCX8 = true;
350 } else if (Feature == "+cx16") {
351 HasCX16 = true;
352 } else if (Feature == "+fxsr") {
353 HasFXSR = true;
354 } else if (Feature == "+xsave") {
355 HasXSAVE = true;
356 } else if (Feature == "+xsaveopt") {
357 HasXSAVEOPT = true;
358 } else if (Feature == "+xsavec") {
359 HasXSAVEC = true;
360 } else if (Feature == "+xsaves") {
361 HasXSAVES = true;
362 } else if (Feature == "+mwaitx") {
363 HasMWAITX = true;
364 } else if (Feature == "+pku") {
365 HasPKU = true;
366 } else if (Feature == "+clflushopt") {
367 HasCLFLUSHOPT = true;
368 } else if (Feature == "+clwb") {
369 HasCLWB = true;
370 } else if (Feature == "+wbnoinvd") {
371 HasWBNOINVD = true;
372 } else if (Feature == "+prefetchi") {
373 HasPREFETCHI = true;
374 } else if (Feature == "+clzero") {
375 HasCLZERO = true;
376 } else if (Feature == "+cldemote") {
377 HasCLDEMOTE = true;
378 } else if (Feature == "+rdpid") {
379 HasRDPID = true;
380 } else if (Feature == "+rdpru") {
381 HasRDPRU = true;
382 } else if (Feature == "+kl") {
383 HasKL = true;
384 } else if (Feature == "+widekl") {
385 HasWIDEKL = true;
386 } else if (Feature == "+retpoline-external-thunk") {
387 HasRetpolineExternalThunk = true;
388 } else if (Feature == "+sahf") {
389 HasLAHFSAHF = true;
390 } else if (Feature == "+waitpkg") {
391 HasWAITPKG = true;
392 } else if (Feature == "+movdiri") {
393 HasMOVDIRI = true;
394 } else if (Feature == "+movdir64b") {
395 HasMOVDIR64B = true;
396 } else if (Feature == "+pconfig") {
397 HasPCONFIG = true;
398 } else if (Feature == "+ptwrite") {
399 HasPTWRITE = true;
400 } else if (Feature == "+invpcid") {
401 HasINVPCID = true;
402 } else if (Feature == "+enqcmd") {
403 HasENQCMD = true;
404 } else if (Feature == "+hreset") {
405 HasHRESET = true;
406 } else if (Feature == "+amx-bf16") {
407 HasAMXBF16 = true;
408 } else if (Feature == "+amx-fp16") {
409 HasAMXFP16 = true;
410 } else if (Feature == "+amx-int8") {
411 HasAMXINT8 = true;
412 } else if (Feature == "+amx-tile") {
413 HasAMXTILE = true;
414 } else if (Feature == "+amx-complex") {
415 HasAMXCOMPLEX = true;
416 } else if (Feature == "+cmpccxadd") {
417 HasCMPCCXADD = true;
418 } else if (Feature == "+raoint") {
419 HasRAOINT = true;
420 } else if (Feature == "+avxifma") {
421 HasAVXIFMA = true;
422 } else if (Feature == "+avxneconvert") {
423 HasAVXNECONVERT= true;
424 } else if (Feature == "+avxvnni") {
425 HasAVXVNNI = true;
426 } else if (Feature == "+avxvnniint16") {
427 HasAVXVNNIINT16 = true;
428 } else if (Feature == "+avxvnniint8") {
429 HasAVXVNNIINT8 = true;
430 } else if (Feature == "+serialize") {
431 HasSERIALIZE = true;
432 } else if (Feature == "+tsxldtrk") {
433 HasTSXLDTRK = true;
434 } else if (Feature == "+uintr") {
435 HasUINTR = true;
436 } else if (Feature == "+usermsr") {
437 HasUSERMSR = true;
438 } else if (Feature == "+crc32") {
439 HasCRC32 = true;
440 } else if (Feature == "+x87") {
441 HasX87 = true;
442 } else if (Feature == "+fullbf16") {
443 HasFullBFloat16 = true;
444 } else if (Feature == "+egpr") {
445 HasEGPR = true;
446 } else if (Feature == "+inline-asm-use-gpr32") {
447 HasInlineAsmUseGPR32 = true;
448 } else if (Feature == "+push2pop2") {
449 HasPush2Pop2 = true;
450 } else if (Feature == "+ppx") {
451 HasPPX = true;
452 } else if (Feature == "+ndd") {
453 HasNDD = true;
454 } else if (Feature == "+ccmp") {
455 HasCCMP = true;
456 } else if (Feature == "+nf") {
457 HasNF = true;
458 } else if (Feature == "+cf") {
459 HasCF = true;
460 } else if (Feature == "+zu") {
461 HasZU = true;
462 } else if (Feature == "+branch-hint") {
463 HasBranchHint = true;
464 }
465
466 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
467 .Case("+avx512f", AVX512F)
468 .Case("+avx2", AVX2)
469 .Case("+avx", AVX)
470 .Case("+sse4.2", SSE42)
471 .Case("+sse4.1", SSE41)
472 .Case("+ssse3", SSSE3)
473 .Case("+sse3", SSE3)
474 .Case("+sse2", SSE2)
475 .Case("+sse", SSE1)
476 .Default(NoSSE);
477 SSELevel = std::max(SSELevel, Level);
478
479 HasFloat16 = SSELevel >= SSE2;
480
481 // X86 target has bfloat16 emulation support in the backend, where
482 // bfloat16 is treated as a 32-bit float, arithmetic operations are
483 // performed in 32-bit, and the result is converted back to bfloat16.
484 // Truncation and extension between bfloat16 and 32-bit float are supported
485 // by the compiler-rt library. However, native bfloat16 support is currently
486 // not available in the X86 target. Hence, HasFullBFloat16 will be false
487 // until native bfloat16 support is available. HasFullBFloat16 is used to
488 // determine whether to automatically use excess floating point precision
489 // for bfloat16 arithmetic operations in the front-end.
490 HasBFloat16 = SSELevel >= SSE2;
491
492 XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(Feature)
493 .Case("+xop", XOP)
494 .Case("+fma4", FMA4)
495 .Case("+sse4a", SSE4A)
496 .Default(NoXOP);
497 XOPLevel = std::max(XOPLevel, XLevel);
498 }
499
500 // LLVM doesn't have a separate switch for fpmath, so only accept it if it
501 // matches the selected sse level.
502 if ((FPMath == FP_SSE && SSELevel < SSE1) ||
503 (FPMath == FP_387 && SSELevel >= SSE1)) {
504 Diags.Report(diag::err_target_unsupported_fpmath)
505 << (FPMath == FP_SSE ? "sse" : "387");
506 return false;
507 }
508
509 // FIXME: We should allow long double type on 32-bits to match with GCC.
510 // This requires backend to be able to lower f80 without x87 first.
511 if (!HasX87 && LongDoubleFormat == &llvm::APFloat::x87DoubleExtended())
512 HasLongDouble = false;
513
514 return true;
515}
516
517/// X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro
518/// definitions for this particular subtarget.
520 MacroBuilder &Builder) const {
521 // Inline assembly supports X86 flag outputs.
522 Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
523
524 std::string CodeModel = getTargetOpts().CodeModel;
525 if (CodeModel == "default")
526 CodeModel = "small";
527 Builder.defineMacro("__code_model_" + CodeModel + "__");
528
529 // Target identification.
530 if (getTriple().getArch() == llvm::Triple::x86_64) {
531 Builder.defineMacro("__amd64__");
532 Builder.defineMacro("__amd64");
533 Builder.defineMacro("__x86_64");
534 Builder.defineMacro("__x86_64__");
535 if (getTriple().getArchName() == "x86_64h") {
536 Builder.defineMacro("__x86_64h");
537 Builder.defineMacro("__x86_64h__");
538 }
539 } else {
540 DefineStd(Builder, "i386", Opts);
541 }
542
543 Builder.defineMacro("__SEG_GS");
544 Builder.defineMacro("__SEG_FS");
545 Builder.defineMacro("__seg_gs", "__attribute__((address_space(256)))");
546 Builder.defineMacro("__seg_fs", "__attribute__((address_space(257)))");
547
548 // Subtarget options.
549 // FIXME: We are hard-coding the tune parameters based on the CPU, but they
550 // truly should be based on -mtune options.
551 using namespace llvm::X86;
552 switch (CPU) {
553 case CK_None:
554 break;
555 case CK_i386:
556 // The rest are coming from the i386 define above.
557 Builder.defineMacro("__tune_i386__");
558 break;
559 case CK_i486:
560 case CK_WinChipC6:
561 case CK_WinChip2:
562 case CK_C3:
563 defineCPUMacros(Builder, "i486");
564 break;
565 case CK_PentiumMMX:
566 Builder.defineMacro("__pentium_mmx__");
567 Builder.defineMacro("__tune_pentium_mmx__");
568 [[fallthrough]];
569 case CK_i586:
570 case CK_Pentium:
571 defineCPUMacros(Builder, "i586");
572 defineCPUMacros(Builder, "pentium");
573 break;
574 case CK_Pentium3:
575 case CK_PentiumM:
576 Builder.defineMacro("__tune_pentium3__");
577 [[fallthrough]];
578 case CK_Pentium2:
579 case CK_C3_2:
580 Builder.defineMacro("__tune_pentium2__");
581 [[fallthrough]];
582 case CK_PentiumPro:
583 case CK_i686:
584 defineCPUMacros(Builder, "i686");
585 defineCPUMacros(Builder, "pentiumpro");
586 break;
587 case CK_Pentium4:
588 defineCPUMacros(Builder, "pentium4");
589 break;
590 case CK_Yonah:
591 case CK_Prescott:
592 case CK_Nocona:
593 defineCPUMacros(Builder, "nocona");
594 break;
595 case CK_Core2:
596 case CK_Penryn:
597 defineCPUMacros(Builder, "core2");
598 break;
599 case CK_Bonnell:
600 defineCPUMacros(Builder, "atom");
601 break;
602 case CK_Silvermont:
603 defineCPUMacros(Builder, "slm");
604 break;
605 case CK_Goldmont:
606 defineCPUMacros(Builder, "goldmont");
607 break;
608 case CK_GoldmontPlus:
609 defineCPUMacros(Builder, "goldmont_plus");
610 break;
611 case CK_Tremont:
612 defineCPUMacros(Builder, "tremont");
613 break;
614 // Gracemont and later atom-cores use P-core cpu macros.
615 case CK_Gracemont:
616 case CK_Nehalem:
617 case CK_Westmere:
618 case CK_SandyBridge:
619 case CK_IvyBridge:
620 case CK_Haswell:
621 case CK_Broadwell:
622 case CK_SkylakeClient:
623 case CK_SkylakeServer:
624 case CK_Cascadelake:
625 case CK_Cooperlake:
626 case CK_Cannonlake:
627 case CK_IcelakeClient:
628 case CK_Rocketlake:
629 case CK_IcelakeServer:
630 case CK_Tigerlake:
631 case CK_SapphireRapids:
632 case CK_Alderlake:
633 case CK_Raptorlake:
634 case CK_Meteorlake:
635 case CK_Arrowlake:
636 case CK_ArrowlakeS:
637 case CK_Lunarlake:
638 case CK_Pantherlake:
639 case CK_Sierraforest:
640 case CK_Grandridge:
641 case CK_Graniterapids:
642 case CK_GraniterapidsD:
643 case CK_Emeraldrapids:
644 case CK_Clearwaterforest:
645 // FIXME: Historically, we defined this legacy name, it would be nice to
646 // remove it at some point. We've never exposed fine-grained names for
647 // recent primary x86 CPUs, and we should keep it that way.
648 defineCPUMacros(Builder, "corei7");
649 break;
650 case CK_KNL:
651 defineCPUMacros(Builder, "knl");
652 break;
653 case CK_KNM:
654 break;
655 case CK_Lakemont:
656 defineCPUMacros(Builder, "i586", /*Tuning*/false);
657 defineCPUMacros(Builder, "pentium", /*Tuning*/false);
658 Builder.defineMacro("__tune_lakemont__");
659 break;
660 case CK_K6_2:
661 Builder.defineMacro("__k6_2__");
662 Builder.defineMacro("__tune_k6_2__");
663 [[fallthrough]];
664 case CK_K6_3:
665 if (CPU != CK_K6_2) { // In case of fallthrough
666 // FIXME: GCC may be enabling these in cases where some other k6
667 // architecture is specified but -m3dnow is explicitly provided. The
668 // exact semantics need to be determined and emulated here.
669 Builder.defineMacro("__k6_3__");
670 Builder.defineMacro("__tune_k6_3__");
671 }
672 [[fallthrough]];
673 case CK_K6:
674 defineCPUMacros(Builder, "k6");
675 break;
676 case CK_Athlon:
677 case CK_AthlonXP:
678 defineCPUMacros(Builder, "athlon");
679 if (SSELevel != NoSSE) {
680 Builder.defineMacro("__athlon_sse__");
681 Builder.defineMacro("__tune_athlon_sse__");
682 }
683 break;
684 case CK_K8:
685 case CK_K8SSE3:
686 case CK_x86_64:
687 defineCPUMacros(Builder, "k8");
688 break;
689 case CK_x86_64_v2:
690 case CK_x86_64_v3:
691 case CK_x86_64_v4:
692 break;
693 case CK_AMDFAM10:
694 defineCPUMacros(Builder, "amdfam10");
695 break;
696 case CK_BTVER1:
697 defineCPUMacros(Builder, "btver1");
698 break;
699 case CK_BTVER2:
700 defineCPUMacros(Builder, "btver2");
701 break;
702 case CK_BDVER1:
703 defineCPUMacros(Builder, "bdver1");
704 break;
705 case CK_BDVER2:
706 defineCPUMacros(Builder, "bdver2");
707 break;
708 case CK_BDVER3:
709 defineCPUMacros(Builder, "bdver3");
710 break;
711 case CK_BDVER4:
712 defineCPUMacros(Builder, "bdver4");
713 break;
714 case CK_ZNVER1:
715 defineCPUMacros(Builder, "znver1");
716 break;
717 case CK_ZNVER2:
718 defineCPUMacros(Builder, "znver2");
719 break;
720 case CK_ZNVER3:
721 defineCPUMacros(Builder, "znver3");
722 break;
723 case CK_ZNVER4:
724 defineCPUMacros(Builder, "znver4");
725 break;
726 case CK_Geode:
727 defineCPUMacros(Builder, "geode");
728 break;
729 }
730
731 // Target properties.
732 Builder.defineMacro("__REGISTER_PREFIX__", "");
733
734 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
735 // functions in glibc header files that use FP Stack inline asm which the
736 // backend can't deal with (PR879).
737 Builder.defineMacro("__NO_MATH_INLINES");
738
739 if (HasAES)
740 Builder.defineMacro("__AES__");
741
742 if (HasVAES)
743 Builder.defineMacro("__VAES__");
744
745 if (HasPCLMUL)
746 Builder.defineMacro("__PCLMUL__");
747
748 if (HasVPCLMULQDQ)
749 Builder.defineMacro("__VPCLMULQDQ__");
750
751 // Note, in 32-bit mode, GCC does not define the macro if -mno-sahf. In LLVM,
752 // the feature flag only applies to 64-bit mode.
753 if (HasLAHFSAHF || getTriple().getArch() == llvm::Triple::x86)
754 Builder.defineMacro("__LAHF_SAHF__");
755
756 if (HasLZCNT)
757 Builder.defineMacro("__LZCNT__");
758
759 if (HasRDRND)
760 Builder.defineMacro("__RDRND__");
761
762 if (HasFSGSBASE)
763 Builder.defineMacro("__FSGSBASE__");
764
765 if (HasBMI)
766 Builder.defineMacro("__BMI__");
767
768 if (HasBMI2)
769 Builder.defineMacro("__BMI2__");
770
771 if (HasPOPCNT)
772 Builder.defineMacro("__POPCNT__");
773
774 if (HasRTM)
775 Builder.defineMacro("__RTM__");
776
777 if (HasPRFCHW)
778 Builder.defineMacro("__PRFCHW__");
779
780 if (HasRDSEED)
781 Builder.defineMacro("__RDSEED__");
782
783 if (HasADX)
784 Builder.defineMacro("__ADX__");
785
786 if (HasTBM)
787 Builder.defineMacro("__TBM__");
788
789 if (HasLWP)
790 Builder.defineMacro("__LWP__");
791
792 if (HasMWAITX)
793 Builder.defineMacro("__MWAITX__");
794
795 if (HasMOVBE)
796 Builder.defineMacro("__MOVBE__");
797
798 switch (XOPLevel) {
799 case XOP:
800 Builder.defineMacro("__XOP__");
801 [[fallthrough]];
802 case FMA4:
803 Builder.defineMacro("__FMA4__");
804 [[fallthrough]];
805 case SSE4A:
806 Builder.defineMacro("__SSE4A__");
807 [[fallthrough]];
808 case NoXOP:
809 break;
810 }
811
812 if (HasFMA)
813 Builder.defineMacro("__FMA__");
814
815 if (HasF16C)
816 Builder.defineMacro("__F16C__");
817
818 if (HasGFNI)
819 Builder.defineMacro("__GFNI__");
820
821 if (HasEVEX512)
822 Builder.defineMacro("__EVEX512__");
823 if (HasAVX10_1)
824 Builder.defineMacro("__AVX10_1__");
825 if (HasAVX10_1_512)
826 Builder.defineMacro("__AVX10_1_512__");
827 if (HasAVX512CD)
828 Builder.defineMacro("__AVX512CD__");
829 if (HasAVX512VPOPCNTDQ)
830 Builder.defineMacro("__AVX512VPOPCNTDQ__");
831 if (HasAVX512VNNI)
832 Builder.defineMacro("__AVX512VNNI__");
833 if (HasAVX512BF16)
834 Builder.defineMacro("__AVX512BF16__");
835 if (HasAVX512FP16)
836 Builder.defineMacro("__AVX512FP16__");
837 if (HasAVX512DQ)
838 Builder.defineMacro("__AVX512DQ__");
839 if (HasAVX512BITALG)
840 Builder.defineMacro("__AVX512BITALG__");
841 if (HasAVX512BW)
842 Builder.defineMacro("__AVX512BW__");
843 if (HasAVX512VL) {
844 Builder.defineMacro("__AVX512VL__");
845 Builder.defineMacro("__EVEX256__");
846 }
847 if (HasAVX512VBMI)
848 Builder.defineMacro("__AVX512VBMI__");
849 if (HasAVX512VBMI2)
850 Builder.defineMacro("__AVX512VBMI2__");
851 if (HasAVX512IFMA)
852 Builder.defineMacro("__AVX512IFMA__");
853 if (HasAVX512VP2INTERSECT)
854 Builder.defineMacro("__AVX512VP2INTERSECT__");
855 if (HasSHA)
856 Builder.defineMacro("__SHA__");
857 if (HasSHA512)
858 Builder.defineMacro("__SHA512__");
859
860 if (HasFXSR)
861 Builder.defineMacro("__FXSR__");
862 if (HasXSAVE)
863 Builder.defineMacro("__XSAVE__");
864 if (HasXSAVEOPT)
865 Builder.defineMacro("__XSAVEOPT__");
866 if (HasXSAVEC)
867 Builder.defineMacro("__XSAVEC__");
868 if (HasXSAVES)
869 Builder.defineMacro("__XSAVES__");
870 if (HasPKU)
871 Builder.defineMacro("__PKU__");
872 if (HasCLFLUSHOPT)
873 Builder.defineMacro("__CLFLUSHOPT__");
874 if (HasCLWB)
875 Builder.defineMacro("__CLWB__");
876 if (HasWBNOINVD)
877 Builder.defineMacro("__WBNOINVD__");
878 if (HasSHSTK)
879 Builder.defineMacro("__SHSTK__");
880 if (HasSGX)
881 Builder.defineMacro("__SGX__");
882 if (HasSM3)
883 Builder.defineMacro("__SM3__");
884 if (HasSM4)
885 Builder.defineMacro("__SM4__");
886 if (HasPREFETCHI)
887 Builder.defineMacro("__PREFETCHI__");
888 if (HasCLZERO)
889 Builder.defineMacro("__CLZERO__");
890 if (HasKL)
891 Builder.defineMacro("__KL__");
892 if (HasWIDEKL)
893 Builder.defineMacro("__WIDEKL__");
894 if (HasRDPID)
895 Builder.defineMacro("__RDPID__");
896 if (HasRDPRU)
897 Builder.defineMacro("__RDPRU__");
898 if (HasCLDEMOTE)
899 Builder.defineMacro("__CLDEMOTE__");
900 if (HasWAITPKG)
901 Builder.defineMacro("__WAITPKG__");
902 if (HasMOVDIRI)
903 Builder.defineMacro("__MOVDIRI__");
904 if (HasMOVDIR64B)
905 Builder.defineMacro("__MOVDIR64B__");
906 if (HasPCONFIG)
907 Builder.defineMacro("__PCONFIG__");
908 if (HasPTWRITE)
909 Builder.defineMacro("__PTWRITE__");
910 if (HasINVPCID)
911 Builder.defineMacro("__INVPCID__");
912 if (HasENQCMD)
913 Builder.defineMacro("__ENQCMD__");
914 if (HasHRESET)
915 Builder.defineMacro("__HRESET__");
916 if (HasAMXTILE)
917 Builder.defineMacro("__AMX_TILE__");
918 if (HasAMXINT8)
919 Builder.defineMacro("__AMX_INT8__");
920 if (HasAMXBF16)
921 Builder.defineMacro("__AMX_BF16__");
922 if (HasAMXFP16)
923 Builder.defineMacro("__AMX_FP16__");
924 if (HasAMXCOMPLEX)
925 Builder.defineMacro("__AMX_COMPLEX__");
926 if (HasCMPCCXADD)
927 Builder.defineMacro("__CMPCCXADD__");
928 if (HasRAOINT)
929 Builder.defineMacro("__RAOINT__");
930 if (HasAVXIFMA)
931 Builder.defineMacro("__AVXIFMA__");
932 if (HasAVXNECONVERT)
933 Builder.defineMacro("__AVXNECONVERT__");
934 if (HasAVXVNNI)
935 Builder.defineMacro("__AVXVNNI__");
936 if (HasAVXVNNIINT16)
937 Builder.defineMacro("__AVXVNNIINT16__");
938 if (HasAVXVNNIINT8)
939 Builder.defineMacro("__AVXVNNIINT8__");
940 if (HasSERIALIZE)
941 Builder.defineMacro("__SERIALIZE__");
942 if (HasTSXLDTRK)
943 Builder.defineMacro("__TSXLDTRK__");
944 if (HasUINTR)
945 Builder.defineMacro("__UINTR__");
946 if (HasUSERMSR)
947 Builder.defineMacro("__USERMSR__");
948 if (HasCRC32)
949 Builder.defineMacro("__CRC32__");
950 if (HasEGPR)
951 Builder.defineMacro("__EGPR__");
952 if (HasPush2Pop2)
953 Builder.defineMacro("__PUSH2POP2__");
954 if (HasPPX)
955 Builder.defineMacro("__PPX__");
956 if (HasNDD)
957 Builder.defineMacro("__NDD__");
958 if (HasCCMP)
959 Builder.defineMacro("__CCMP__");
960 if (HasNF)
961 Builder.defineMacro("__NF__");
962 if (HasCF)
963 Builder.defineMacro("__CF__");
964 if (HasZU)
965 Builder.defineMacro("__ZU__");
966 if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD && HasCCMP && HasNF &&
967 HasCF && HasZU)
968 Builder.defineMacro("__APX_F__");
969 if (HasEGPR && HasInlineAsmUseGPR32)
970 Builder.defineMacro("__APX_INLINE_ASM_USE_GPR32__");
971
972 // Each case falls through to the previous one here.
973 switch (SSELevel) {
974 case AVX512F:
975 Builder.defineMacro("__AVX512F__");
976 [[fallthrough]];
977 case AVX2:
978 Builder.defineMacro("__AVX2__");
979 [[fallthrough]];
980 case AVX:
981 Builder.defineMacro("__AVX__");
982 [[fallthrough]];
983 case SSE42:
984 Builder.defineMacro("__SSE4_2__");
985 [[fallthrough]];
986 case SSE41:
987 Builder.defineMacro("__SSE4_1__");
988 [[fallthrough]];
989 case SSSE3:
990 Builder.defineMacro("__SSSE3__");
991 [[fallthrough]];
992 case SSE3:
993 Builder.defineMacro("__SSE3__");
994 [[fallthrough]];
995 case SSE2:
996 Builder.defineMacro("__SSE2__");
997 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
998 [[fallthrough]];
999 case SSE1:
1000 Builder.defineMacro("__SSE__");
1001 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
1002 [[fallthrough]];
1003 case NoSSE:
1004 break;
1005 }
1006
1007 if (Opts.MicrosoftExt && getTriple().getArch() == llvm::Triple::x86) {
1008 switch (SSELevel) {
1009 case AVX512F:
1010 case AVX2:
1011 case AVX:
1012 case SSE42:
1013 case SSE41:
1014 case SSSE3:
1015 case SSE3:
1016 case SSE2:
1017 Builder.defineMacro("_M_IX86_FP", Twine(2));
1018 break;
1019 case SSE1:
1020 Builder.defineMacro("_M_IX86_FP", Twine(1));
1021 break;
1022 default:
1023 Builder.defineMacro("_M_IX86_FP", Twine(0));
1024 break;
1025 }
1026 }
1027
1028 // Each case falls through to the previous one here.
1029 if (HasMMX) {
1030 Builder.defineMacro("__MMX__");
1031 }
1032
1033 if (CPU >= CK_i486 || CPU == CK_None) {
1034 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
1035 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
1036 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
1037 }
1038 if (HasCX8)
1039 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
1040 if (HasCX16 && getTriple().getArch() == llvm::Triple::x86_64)
1041 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
1042
1043 if (HasFloat128)
1044 Builder.defineMacro("__SIZEOF_FLOAT128__", "16");
1045}
1046
1047bool X86TargetInfo::isValidFeatureName(StringRef Name) const {
1048 return llvm::StringSwitch<bool>(Name)
1049 .Case("adx", true)
1050 .Case("aes", true)
1051 .Case("amx-bf16", true)
1052 .Case("amx-complex", true)
1053 .Case("amx-fp16", true)
1054 .Case("amx-int8", true)
1055 .Case("amx-tile", true)
1056 .Case("avx", true)
1057 .Case("avx10.1-256", true)
1058 .Case("avx10.1-512", true)
1059 .Case("avx2", true)
1060 .Case("avx512f", true)
1061 .Case("avx512cd", true)
1062 .Case("avx512vpopcntdq", true)
1063 .Case("avx512vnni", true)
1064 .Case("avx512bf16", true)
1065 .Case("avx512fp16", true)
1066 .Case("avx512dq", true)
1067 .Case("avx512bitalg", true)
1068 .Case("avx512bw", true)
1069 .Case("avx512vl", true)
1070 .Case("avx512vbmi", true)
1071 .Case("avx512vbmi2", true)
1072 .Case("avx512ifma", true)
1073 .Case("avx512vp2intersect", true)
1074 .Case("avxifma", true)
1075 .Case("avxneconvert", true)
1076 .Case("avxvnni", true)
1077 .Case("avxvnniint16", true)
1078 .Case("avxvnniint8", true)
1079 .Case("bmi", true)
1080 .Case("bmi2", true)
1081 .Case("cldemote", true)
1082 .Case("clflushopt", true)
1083 .Case("clwb", true)
1084 .Case("clzero", true)
1085 .Case("cmpccxadd", true)
1086 .Case("crc32", true)
1087 .Case("cx16", true)
1088 .Case("enqcmd", true)
1089 .Case("evex512", true)
1090 .Case("f16c", true)
1091 .Case("fma", true)
1092 .Case("fma4", true)
1093 .Case("fsgsbase", true)
1094 .Case("fxsr", true)
1095 .Case("general-regs-only", true)
1096 .Case("gfni", true)
1097 .Case("hreset", true)
1098 .Case("invpcid", true)
1099 .Case("kl", true)
1100 .Case("widekl", true)
1101 .Case("lwp", true)
1102 .Case("lzcnt", true)
1103 .Case("mmx", true)
1104 .Case("movbe", true)
1105 .Case("movdiri", true)
1106 .Case("movdir64b", true)
1107 .Case("mwaitx", true)
1108 .Case("pclmul", true)
1109 .Case("pconfig", true)
1110 .Case("pku", true)
1111 .Case("popcnt", true)
1112 .Case("prefetchi", true)
1113 .Case("prfchw", true)
1114 .Case("ptwrite", true)
1115 .Case("raoint", true)
1116 .Case("rdpid", true)
1117 .Case("rdpru", true)
1118 .Case("rdrnd", true)
1119 .Case("rdseed", true)
1120 .Case("rtm", true)
1121 .Case("sahf", true)
1122 .Case("serialize", true)
1123 .Case("sgx", true)
1124 .Case("sha", true)
1125 .Case("sha512", true)
1126 .Case("shstk", true)
1127 .Case("sm3", true)
1128 .Case("sm4", true)
1129 .Case("sse", true)
1130 .Case("sse2", true)
1131 .Case("sse3", true)
1132 .Case("ssse3", true)
1133 .Case("sse4", true)
1134 .Case("sse4.1", true)
1135 .Case("sse4.2", true)
1136 .Case("sse4a", true)
1137 .Case("tbm", true)
1138 .Case("tsxldtrk", true)
1139 .Case("uintr", true)
1140 .Case("usermsr", true)
1141 .Case("vaes", true)
1142 .Case("vpclmulqdq", true)
1143 .Case("wbnoinvd", true)
1144 .Case("waitpkg", true)
1145 .Case("x87", true)
1146 .Case("xop", true)
1147 .Case("xsave", true)
1148 .Case("xsavec", true)
1149 .Case("xsaves", true)
1150 .Case("xsaveopt", true)
1151 .Case("egpr", true)
1152 .Case("push2pop2", true)
1153 .Case("ppx", true)
1154 .Case("ndd", true)
1155 .Case("ccmp", true)
1156 .Case("nf", true)
1157 .Case("cf", true)
1158 .Case("zu", true)
1159 .Default(false);
1160}
1161
1162bool X86TargetInfo::hasFeature(StringRef Feature) const {
1163 return llvm::StringSwitch<bool>(Feature)
1164 .Case("adx", HasADX)
1165 .Case("aes", HasAES)
1166 .Case("amx-bf16", HasAMXBF16)
1167 .Case("amx-complex", HasAMXCOMPLEX)
1168 .Case("amx-fp16", HasAMXFP16)
1169 .Case("amx-int8", HasAMXINT8)
1170 .Case("amx-tile", HasAMXTILE)
1171 .Case("avx", SSELevel >= AVX)
1172 .Case("avx10.1-256", HasAVX10_1)
1173 .Case("avx10.1-512", HasAVX10_1_512)
1174 .Case("avx2", SSELevel >= AVX2)
1175 .Case("avx512f", SSELevel >= AVX512F)
1176 .Case("avx512cd", HasAVX512CD)
1177 .Case("avx512vpopcntdq", HasAVX512VPOPCNTDQ)
1178 .Case("avx512vnni", HasAVX512VNNI)
1179 .Case("avx512bf16", HasAVX512BF16)
1180 .Case("avx512fp16", HasAVX512FP16)
1181 .Case("avx512dq", HasAVX512DQ)
1182 .Case("avx512bitalg", HasAVX512BITALG)
1183 .Case("avx512bw", HasAVX512BW)
1184 .Case("avx512vl", HasAVX512VL)
1185 .Case("avx512vbmi", HasAVX512VBMI)
1186 .Case("avx512vbmi2", HasAVX512VBMI2)
1187 .Case("avx512ifma", HasAVX512IFMA)
1188 .Case("avx512vp2intersect", HasAVX512VP2INTERSECT)
1189 .Case("avxifma", HasAVXIFMA)
1190 .Case("avxneconvert", HasAVXNECONVERT)
1191 .Case("avxvnni", HasAVXVNNI)
1192 .Case("avxvnniint16", HasAVXVNNIINT16)
1193 .Case("avxvnniint8", HasAVXVNNIINT8)
1194 .Case("bmi", HasBMI)
1195 .Case("bmi2", HasBMI2)
1196 .Case("cldemote", HasCLDEMOTE)
1197 .Case("clflushopt", HasCLFLUSHOPT)
1198 .Case("clwb", HasCLWB)
1199 .Case("clzero", HasCLZERO)
1200 .Case("cmpccxadd", HasCMPCCXADD)
1201 .Case("crc32", HasCRC32)
1202 .Case("cx8", HasCX8)
1203 .Case("cx16", HasCX16)
1204 .Case("enqcmd", HasENQCMD)
1205 .Case("evex512", HasEVEX512)
1206 .Case("f16c", HasF16C)
1207 .Case("fma", HasFMA)
1208 .Case("fma4", XOPLevel >= FMA4)
1209 .Case("fsgsbase", HasFSGSBASE)
1210 .Case("fxsr", HasFXSR)
1211 .Case("gfni", HasGFNI)
1212 .Case("hreset", HasHRESET)
1213 .Case("invpcid", HasINVPCID)
1214 .Case("kl", HasKL)
1215 .Case("widekl", HasWIDEKL)
1216 .Case("lwp", HasLWP)
1217 .Case("lzcnt", HasLZCNT)
1218 .Case("mmx", HasMMX)
1219 .Case("movbe", HasMOVBE)
1220 .Case("movdiri", HasMOVDIRI)
1221 .Case("movdir64b", HasMOVDIR64B)
1222 .Case("mwaitx", HasMWAITX)
1223 .Case("pclmul", HasPCLMUL)
1224 .Case("pconfig", HasPCONFIG)
1225 .Case("pku", HasPKU)
1226 .Case("popcnt", HasPOPCNT)
1227 .Case("prefetchi", HasPREFETCHI)
1228 .Case("prfchw", HasPRFCHW)
1229 .Case("ptwrite", HasPTWRITE)
1230 .Case("raoint", HasRAOINT)
1231 .Case("rdpid", HasRDPID)
1232 .Case("rdpru", HasRDPRU)
1233 .Case("rdrnd", HasRDRND)
1234 .Case("rdseed", HasRDSEED)
1235 .Case("retpoline-external-thunk", HasRetpolineExternalThunk)
1236 .Case("rtm", HasRTM)
1237 .Case("sahf", HasLAHFSAHF)
1238 .Case("serialize", HasSERIALIZE)
1239 .Case("sgx", HasSGX)
1240 .Case("sha", HasSHA)
1241 .Case("sha512", HasSHA512)
1242 .Case("shstk", HasSHSTK)
1243 .Case("sm3", HasSM3)
1244 .Case("sm4", HasSM4)
1245 .Case("sse", SSELevel >= SSE1)
1246 .Case("sse2", SSELevel >= SSE2)
1247 .Case("sse3", SSELevel >= SSE3)
1248 .Case("ssse3", SSELevel >= SSSE3)
1249 .Case("sse4.1", SSELevel >= SSE41)
1250 .Case("sse4.2", SSELevel >= SSE42)
1251 .Case("sse4a", XOPLevel >= SSE4A)
1252 .Case("tbm", HasTBM)
1253 .Case("tsxldtrk", HasTSXLDTRK)
1254 .Case("uintr", HasUINTR)
1255 .Case("usermsr", HasUSERMSR)
1256 .Case("vaes", HasVAES)
1257 .Case("vpclmulqdq", HasVPCLMULQDQ)
1258 .Case("wbnoinvd", HasWBNOINVD)
1259 .Case("waitpkg", HasWAITPKG)
1260 .Case("x86", true)
1261 .Case("x86_32", getTriple().getArch() == llvm::Triple::x86)
1262 .Case("x86_64", getTriple().getArch() == llvm::Triple::x86_64)
1263 .Case("x87", HasX87)
1264 .Case("xop", XOPLevel >= XOP)
1265 .Case("xsave", HasXSAVE)
1266 .Case("xsavec", HasXSAVEC)
1267 .Case("xsaves", HasXSAVES)
1268 .Case("xsaveopt", HasXSAVEOPT)
1269 .Case("fullbf16", HasFullBFloat16)
1270 .Case("egpr", HasEGPR)
1271 .Case("push2pop2", HasPush2Pop2)
1272 .Case("ppx", HasPPX)
1273 .Case("ndd", HasNDD)
1274 .Case("ccmp", HasCCMP)
1275 .Case("nf", HasNF)
1276 .Case("cf", HasCF)
1277 .Case("zu", HasZU)
1278 .Case("branch-hint", HasBranchHint)
1279 .Default(false);
1280}
1281
1282// We can't use a generic validation scheme for the features accepted here
1283// versus subtarget features accepted in the target attribute because the
1284// bitfield structure that's initialized in the runtime only supports the
1285// below currently rather than the full range of subtarget features. (See
1286// X86TargetInfo::hasFeature for a somewhat comprehensive list).
1287bool X86TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
1288 return llvm::StringSwitch<bool>(FeatureStr)
1289#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) .Case(STR, true)
1290#define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY) .Case(STR, true)
1291#include "llvm/TargetParser/X86TargetParser.def"
1292 .Default(false);
1293}
1294
1295static llvm::X86::ProcessorFeatures getFeature(StringRef Name) {
1296 return llvm::StringSwitch<llvm::X86::ProcessorFeatures>(Name)
1297#define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY) \
1298 .Case(STR, llvm::X86::FEATURE_##ENUM)
1299
1300#include "llvm/TargetParser/X86TargetParser.def"
1301 ;
1302 // Note, this function should only be used after ensuring the value is
1303 // correct, so it asserts if the value is out of range.
1304}
1305
1306unsigned X86TargetInfo::multiVersionSortPriority(StringRef Name) const {
1307 // Valid CPUs have a 'key feature' that compares just better than its key
1308 // feature.
1309 using namespace llvm::X86;
1310 CPUKind Kind = parseArchX86(Name);
1311 if (Kind != CK_None) {
1312 ProcessorFeatures KeyFeature = getKeyFeature(Kind);
1313 return (getFeaturePriority(KeyFeature) << 1) + 1;
1314 }
1315
1316 // Now we know we have a feature, so get its priority and shift it a few so
1317 // that we have sufficient room for the CPUs (above).
1318 return getFeaturePriority(getFeature(Name)) << 1;
1319}
1320
1322 return llvm::X86::validateCPUSpecificCPUDispatch(Name);
1323}
1324
1326 return llvm::X86::getCPUDispatchMangling(Name);
1327}
1328
1330 StringRef Name, llvm::SmallVectorImpl<StringRef> &Features) const {
1331 SmallVector<StringRef, 32> TargetCPUFeatures;
1332 llvm::X86::getFeaturesForCPU(Name, TargetCPUFeatures, true);
1333 for (auto &F : TargetCPUFeatures)
1334 Features.push_back(F);
1335}
1336
1337// We can't use a generic validation scheme for the cpus accepted here
1338// versus subtarget cpus accepted in the target attribute because the
1339// variables intitialized by the runtime only support the below currently
1340// rather than the full range of cpus.
1341bool X86TargetInfo::validateCpuIs(StringRef FeatureStr) const {
1342 return llvm::StringSwitch<bool>(FeatureStr)
1343#define X86_VENDOR(ENUM, STRING) .Case(STRING, true)
1344#define X86_CPU_TYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1345#define X86_CPU_TYPE(ENUM, STR) .Case(STR, true)
1346#define X86_CPU_SUBTYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true)
1347#define X86_CPU_SUBTYPE(ENUM, STR) .Case(STR, true)
1348#include "llvm/TargetParser/X86TargetParser.def"
1349 .Default(false);
1350}
1351
1352static unsigned matchAsmCCConstraint(const char *Name) {
1353 auto RV = llvm::StringSwitch<unsigned>(Name)
1354 .Case("@cca", 4)
1355 .Case("@ccae", 5)
1356 .Case("@ccb", 4)
1357 .Case("@ccbe", 5)
1358 .Case("@ccc", 4)
1359 .Case("@cce", 4)
1360 .Case("@ccz", 4)
1361 .Case("@ccg", 4)
1362 .Case("@ccge", 5)
1363 .Case("@ccl", 4)
1364 .Case("@ccle", 5)
1365 .Case("@ccna", 5)
1366 .Case("@ccnae", 6)
1367 .Case("@ccnb", 5)
1368 .Case("@ccnbe", 6)
1369 .Case("@ccnc", 5)
1370 .Case("@ccne", 5)
1371 .Case("@ccnz", 5)
1372 .Case("@ccng", 5)
1373 .Case("@ccnge", 6)
1374 .Case("@ccnl", 5)
1375 .Case("@ccnle", 6)
1376 .Case("@ccno", 5)
1377 .Case("@ccnp", 5)
1378 .Case("@ccns", 5)
1379 .Case("@cco", 4)
1380 .Case("@ccp", 4)
1381 .Case("@ccs", 4)
1382 .Default(0);
1383 return RV;
1384}
1385
1387 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
1388 switch (*Name) {
1389 default:
1390 return false;
1391 // Constant constraints.
1392 case 'e': // 32-bit signed integer constant for use with sign-extending x86_64
1393 // instructions.
1394 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
1395 // x86_64 instructions.
1396 case 's':
1397 Info.setRequiresImmediate();
1398 return true;
1399 case 'I':
1400 Info.setRequiresImmediate(0, 31);
1401 return true;
1402 case 'J':
1403 Info.setRequiresImmediate(0, 63);
1404 return true;
1405 case 'K':
1406 Info.setRequiresImmediate(-128, 127);
1407 return true;
1408 case 'L':
1409 Info.setRequiresImmediate({int(0xff), int(0xffff), int(0xffffffff)});
1410 return true;
1411 case 'M':
1412 Info.setRequiresImmediate(0, 3);
1413 return true;
1414 case 'N':
1415 Info.setRequiresImmediate(0, 255);
1416 return true;
1417 case 'O':
1418 Info.setRequiresImmediate(0, 127);
1419 return true;
1420 case 'W':
1421 switch (*++Name) {
1422 default:
1423 return false;
1424 case 's':
1425 Info.setAllowsRegister();
1426 return true;
1427 }
1428 // Register constraints.
1429 case 'Y': // 'Y' is the first character for several 2-character constraints.
1430 // Shift the pointer to the second character of the constraint.
1431 Name++;
1432 switch (*Name) {
1433 default:
1434 return false;
1435 case 'z': // First SSE register.
1436 case '2':
1437 case 't': // Any SSE register, when SSE2 is enabled.
1438 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
1439 case 'm': // Any MMX register, when inter-unit moves enabled.
1440 case 'k': // AVX512 arch mask registers: k1-k7.
1441 Info.setAllowsRegister();
1442 return true;
1443 }
1444 case 'f': // Any x87 floating point stack register.
1445 // Constraint 'f' cannot be used for output operands.
1446 if (Info.ConstraintStr[0] == '=')
1447 return false;
1448 Info.setAllowsRegister();
1449 return true;
1450 case 'a': // eax.
1451 case 'b': // ebx.
1452 case 'c': // ecx.
1453 case 'd': // edx.
1454 case 'S': // esi.
1455 case 'D': // edi.
1456 case 'A': // edx:eax.
1457 case 't': // Top of floating point stack.
1458 case 'u': // Second from top of floating point stack.
1459 case 'q': // Any register accessible as [r]l: a, b, c, and d.
1460 case 'y': // Any MMX register.
1461 case 'v': // Any {X,Y,Z}MM register (Arch & context dependent)
1462 case 'x': // Any SSE register.
1463 case 'k': // Any AVX512 mask register (same as Yk, additionally allows k0
1464 // for intermideate k reg operations).
1465 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
1466 case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
1467 case 'l': // "Index" registers: any general register that can be used as an
1468 // index in a base+index memory access.
1469 Info.setAllowsRegister();
1470 return true;
1471 // Floating point constant constraints.
1472 case 'C': // SSE floating point constant.
1473 case 'G': // x87 floating point constant.
1474 return true;
1475 case 'j':
1476 Name++;
1477 switch (*Name) {
1478 default:
1479 return false;
1480 case 'r':
1481 Info.setAllowsRegister();
1482 return true;
1483 case 'R':
1484 Info.setAllowsRegister();
1485 return true;
1486 }
1487 case '@':
1488 // CC condition changes.
1489 if (auto Len = matchAsmCCConstraint(Name)) {
1490 Name += Len - 1;
1491 Info.setAllowsRegister();
1492 return true;
1493 }
1494 return false;
1495 }
1496}
1497
1498// Below is based on the following information:
1499// +------------------------------------+-------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
1500// | Processor Name | Cache Line Size (Bytes) | Source |
1501// +------------------------------------+-------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
1502// | i386 | 64 | https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf |
1503// | 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) |
1504// | i586/Pentium MMX | 32 | https://www.7-cpu.com/cpu/P-MMX.html |
1505// | i686/Pentium | 32 | https://www.7-cpu.com/cpu/P6.html |
1506// | Netburst/Pentium4 | 64 | https://www.7-cpu.com/cpu/P4-180.html |
1507// | Atom | 64 | https://www.7-cpu.com/cpu/Atom.html |
1508// | Westmere | 64 | https://en.wikichip.org/wiki/intel/microarchitectures/sandy_bridge_(client) "Cache Architecture" |
1509// | Sandy Bridge | 64 | https://en.wikipedia.org/wiki/Sandy_Bridge and https://www.7-cpu.com/cpu/SandyBridge.html |
1510// | Ivy Bridge | 64 | https://blog.stuffedcow.net/2013/01/ivb-cache-replacement/ and https://www.7-cpu.com/cpu/IvyBridge.html |
1511// | Haswell | 64 | https://www.7-cpu.com/cpu/Haswell.html |
1512// | Broadwell | 64 | https://www.7-cpu.com/cpu/Broadwell.html |
1513// | Skylake (including skylake-avx512) | 64 | https://www.nas.nasa.gov/hecc/support/kb/skylake-processors_550.html "Cache Hierarchy" |
1514// | Cascade Lake | 64 | https://www.nas.nasa.gov/hecc/support/kb/cascade-lake-processors_579.html "Cache Hierarchy" |
1515// | Skylake | 64 | https://en.wikichip.org/wiki/intel/microarchitectures/kaby_lake "Memory Hierarchy" |
1516// | Ice Lake | 64 | https://www.7-cpu.com/cpu/Ice_Lake.html |
1517// | 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" |
1518// | 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 " |
1519// +------------------------------------+-------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
1520std::optional<unsigned> X86TargetInfo::getCPUCacheLineSize() const {
1521 using namespace llvm::X86;
1522 switch (CPU) {
1523 // i386
1524 case CK_i386:
1525 // i486
1526 case CK_i486:
1527 case CK_WinChipC6:
1528 case CK_WinChip2:
1529 case CK_C3:
1530 // Lakemont
1531 case CK_Lakemont:
1532 return 16;
1533
1534 // i586
1535 case CK_i586:
1536 case CK_Pentium:
1537 case CK_PentiumMMX:
1538 // i686
1539 case CK_PentiumPro:
1540 case CK_i686:
1541 case CK_Pentium2:
1542 case CK_Pentium3:
1543 case CK_PentiumM:
1544 case CK_C3_2:
1545 // K6
1546 case CK_K6:
1547 case CK_K6_2:
1548 case CK_K6_3:
1549 // Geode
1550 case CK_Geode:
1551 return 32;
1552
1553 // Netburst
1554 case CK_Pentium4:
1555 case CK_Prescott:
1556 case CK_Nocona:
1557 // Atom
1558 case CK_Bonnell:
1559 case CK_Silvermont:
1560 case CK_Goldmont:
1561 case CK_GoldmontPlus:
1562 case CK_Tremont:
1563 case CK_Gracemont:
1564
1565 case CK_Westmere:
1566 case CK_SandyBridge:
1567 case CK_IvyBridge:
1568 case CK_Haswell:
1569 case CK_Broadwell:
1570 case CK_SkylakeClient:
1571 case CK_SkylakeServer:
1572 case CK_Cascadelake:
1573 case CK_Nehalem:
1574 case CK_Cooperlake:
1575 case CK_Cannonlake:
1576 case CK_Tigerlake:
1577 case CK_SapphireRapids:
1578 case CK_IcelakeClient:
1579 case CK_Rocketlake:
1580 case CK_IcelakeServer:
1581 case CK_Alderlake:
1582 case CK_Raptorlake:
1583 case CK_Meteorlake:
1584 case CK_Arrowlake:
1585 case CK_ArrowlakeS:
1586 case CK_Lunarlake:
1587 case CK_Pantherlake:
1588 case CK_Sierraforest:
1589 case CK_Grandridge:
1590 case CK_Graniterapids:
1591 case CK_GraniterapidsD:
1592 case CK_Emeraldrapids:
1593 case CK_Clearwaterforest:
1594 case CK_KNL:
1595 case CK_KNM:
1596 // K7
1597 case CK_Athlon:
1598 case CK_AthlonXP:
1599 // K8
1600 case CK_K8:
1601 case CK_K8SSE3:
1602 case CK_AMDFAM10:
1603 // Bobcat
1604 case CK_BTVER1:
1605 case CK_BTVER2:
1606 // Bulldozer
1607 case CK_BDVER1:
1608 case CK_BDVER2:
1609 case CK_BDVER3:
1610 case CK_BDVER4:
1611 // Zen
1612 case CK_ZNVER1:
1613 case CK_ZNVER2:
1614 case CK_ZNVER3:
1615 case CK_ZNVER4:
1616 // Deprecated
1617 case CK_x86_64:
1618 case CK_x86_64_v2:
1619 case CK_x86_64_v3:
1620 case CK_x86_64_v4:
1621 case CK_Yonah:
1622 case CK_Penryn:
1623 case CK_Core2:
1624 return 64;
1625
1626 // The following currently have unknown cache line sizes (but they are probably all 64):
1627 // Core
1628 case CK_None:
1629 return std::nullopt;
1630 }
1631 llvm_unreachable("Unknown CPU kind");
1632}
1633
1634bool X86TargetInfo::validateOutputSize(const llvm::StringMap<bool> &FeatureMap,
1635 StringRef Constraint,
1636 unsigned Size) const {
1637 // Strip off constraint modifiers.
1638 Constraint = Constraint.ltrim("=+&");
1639
1640 return validateOperandSize(FeatureMap, Constraint, Size);
1641}
1642
1643bool X86TargetInfo::validateInputSize(const llvm::StringMap<bool> &FeatureMap,
1644 StringRef Constraint,
1645 unsigned Size) const {
1646 return validateOperandSize(FeatureMap, Constraint, Size);
1647}
1648
1649bool X86TargetInfo::validateOperandSize(const llvm::StringMap<bool> &FeatureMap,
1650 StringRef Constraint,
1651 unsigned Size) const {
1652 switch (Constraint[0]) {
1653 default:
1654 break;
1655 case 'k':
1656 // Registers k0-k7 (AVX512) size limit is 64 bit.
1657 case 'y':
1658 return Size <= 64;
1659 case 'f':
1660 case 't':
1661 case 'u':
1662 return Size <= 128;
1663 case 'Y':
1664 // 'Y' is the first character for several 2-character constraints.
1665 switch (Constraint[1]) {
1666 default:
1667 return false;
1668 case 'm':
1669 // 'Ym' is synonymous with 'y'.
1670 case 'k':
1671 return Size <= 64;
1672 case 'z':
1673 // XMM0/YMM/ZMM0
1674 if (hasFeatureEnabled(FeatureMap, "avx512f") &&
1675 hasFeatureEnabled(FeatureMap, "evex512"))
1676 // ZMM0 can be used if target supports AVX512F and EVEX512 is set.
1677 return Size <= 512U;
1678 else if (hasFeatureEnabled(FeatureMap, "avx"))
1679 // YMM0 can be used if target supports AVX.
1680 return Size <= 256U;
1681 else if (hasFeatureEnabled(FeatureMap, "sse"))
1682 return Size <= 128U;
1683 return false;
1684 case 'i':
1685 case 't':
1686 case '2':
1687 // 'Yi','Yt','Y2' are synonymous with 'x' when SSE2 is enabled.
1688 if (SSELevel < SSE2)
1689 return false;
1690 break;
1691 }
1692 break;
1693 case 'v':
1694 case 'x':
1695 if (hasFeatureEnabled(FeatureMap, "avx512f") &&
1696 hasFeatureEnabled(FeatureMap, "evex512"))
1697 // 512-bit zmm registers can be used if target supports AVX512F and
1698 // EVEX512 is set.
1699 return Size <= 512U;
1700 else if (hasFeatureEnabled(FeatureMap, "avx"))
1701 // 256-bit ymm registers can be used if target supports AVX.
1702 return Size <= 256U;
1703 return Size <= 128U;
1704
1705 }
1706
1707 return true;
1708}
1709
1710std::string X86TargetInfo::convertConstraint(const char *&Constraint) const {
1711 switch (*Constraint) {
1712 case '@':
1713 if (auto Len = matchAsmCCConstraint(Constraint)) {
1714 std::string Converted = "{" + std::string(Constraint, Len) + "}";
1715 Constraint += Len - 1;
1716 return Converted;
1717 }
1718 return std::string(1, *Constraint);
1719 case 'a':
1720 return std::string("{ax}");
1721 case 'b':
1722 return std::string("{bx}");
1723 case 'c':
1724 return std::string("{cx}");
1725 case 'd':
1726 return std::string("{dx}");
1727 case 'S':
1728 return std::string("{si}");
1729 case 'D':
1730 return std::string("{di}");
1731 case 'p': // Keep 'p' constraint (address).
1732 return std::string("p");
1733 case 't': // top of floating point stack.
1734 return std::string("{st}");
1735 case 'u': // second from top of floating point stack.
1736 return std::string("{st(1)}"); // second from top of floating point stack.
1737 case 'W':
1738 assert(Constraint[1] == 's');
1739 return '^' + std::string(Constraint++, 2);
1740 case 'Y':
1741 switch (Constraint[1]) {
1742 default:
1743 // Break from inner switch and fall through (copy single char),
1744 // continue parsing after copying the current constraint into
1745 // the return string.
1746 break;
1747 case 'k':
1748 case 'm':
1749 case 'i':
1750 case 't':
1751 case 'z':
1752 case '2':
1753 // "^" hints llvm that this is a 2 letter constraint.
1754 // "Constraint++" is used to promote the string iterator
1755 // to the next constraint.
1756 return std::string("^") + std::string(Constraint++, 2);
1757 }
1758 [[fallthrough]];
1759 case 'j':
1760 switch (Constraint[1]) {
1761 default:
1762 // Break from inner switch and fall through (copy single char),
1763 // continue parsing after copying the current constraint into
1764 // the return string.
1765 break;
1766 case 'r':
1767 case 'R':
1768 // "^" hints llvm that this is a 2 letter constraint.
1769 // "Constraint++" is used to promote the string iterator
1770 // to the next constraint.
1771 return std::string("^") + std::string(Constraint++, 2);
1772 }
1773 [[fallthrough]];
1774 default:
1775 return std::string(1, *Constraint);
1776 }
1777}
1778
1780 bool Only64Bit = getTriple().getArch() != llvm::Triple::x86;
1781 llvm::X86::fillValidCPUArchList(Values, Only64Bit);
1782}
1783
1785 llvm::X86::fillValidTuneCPUList(Values);
1786}
1787
1790}
1791
1794}
1795
1799}
1800
1804}
Defines the Diagnostic-related interfaces.
static unsigned matchAsmCCConstraint(const char *Name)
Definition: AArch64.cpp:1330
static llvm::X86::ProcessorFeatures getFeature(StringRef Name)
Definition: X86.cpp:1295
Defines enum values for all the target-independent builtin functions.
Enumerates target-specific builtins in their own namespaces within namespace clang.
__device__ int
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1547
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
TargetOptions & getTargetOpts() const
Retrieve the target options.
Definition: TargetInfo.h:312
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1256
virtual bool hasFeatureEnabled(const llvm::StringMap< bool > &Features, StringRef Name) const
Check if target has a given feature enabled.
Definition: TargetInfo.h:1379
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:532
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:1520
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition: X86.cpp:1386
unsigned multiVersionSortPriority(StringRef Name) const override
Definition: X86.cpp:1306
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:1788
char CPUSpecificManglingCharacter(StringRef Name) const override
Definition: X86.cpp:1325
std::string convertConstraint(const char *&Constraint) const override
Definition: X86.cpp:1710
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:519
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:1329
bool validateCpuIs(StringRef FeatureStr) const override
Definition: X86.cpp:1341
bool validateOutputSize(const llvm::StringMap< bool > &FeatureMap, StringRef Constraint, unsigned Size) const override
Definition: X86.cpp:1634
virtual bool validateOperandSize(const llvm::StringMap< bool > &FeatureMap, StringRef Constraint, unsigned Size) const
Definition: X86.cpp:1649
void fillValidTuneCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values for tuning CPU.
Definition: X86.cpp:1784
bool validateCPUSpecificCPUDispatch(StringRef Name) const override
Definition: X86.cpp:1321
bool validateCpuSupports(StringRef FeatureStr) const override
Definition: X86.cpp:1287
bool isValidFeatureName(StringRef Name) const override
Determine whether this TargetInfo supports the given feature.
Definition: X86.cpp:1047
bool hasFeature(StringRef Feature) const final
Determine whether the given target has the given feature.
Definition: X86.cpp:1162
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:175
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition: X86.cpp:1779
ArrayRef< TargetInfo::AddlRegName > getGCCAddlRegNames() const override
Definition: X86.cpp:1792
bool validateInputSize(const llvm::StringMap< bool > &FeatureMap, StringRef Constraint, unsigned Size) const override
Definition: X86.cpp:1643
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: X86.cpp:1796
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: X86.cpp:1801
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