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