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