1 //===--- Targets.cpp - Implement target feature support -------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements construction of a TargetInfo object from a
12 //===----------------------------------------------------------------------===//
16 #include "Targets/AArch64.h"
17 #include "Targets/AMDGPU.h"
18 #include "Targets/ARC.h"
19 #include "Targets/ARM.h"
20 #include "Targets/AVR.h"
21 #include "Targets/BPF.h"
22 #include "Targets/CSKY.h"
23 #include "Targets/DirectX.h"
24 #include "Targets/Hexagon.h"
25 #include "Targets/Lanai.h"
26 #include "Targets/Le64.h"
27 #include "Targets/LoongArch.h"
28 #include "Targets/M68k.h"
29 #include "Targets/MSP430.h"
30 #include "Targets/Mips.h"
31 #include "Targets/NVPTX.h"
32 #include "Targets/OSTargets.h"
33 #include "Targets/PNaCl.h"
34 #include "Targets/PPC.h"
35 #include "Targets/RISCV.h"
36 #include "Targets/SPIR.h"
37 #include "Targets/Sparc.h"
38 #include "Targets/SystemZ.h"
39 #include "Targets/TCE.h"
40 #include "Targets/VE.h"
41 #include "Targets/WebAssembly.h"
42 #include "Targets/X86.h"
43 #include "Targets/XCore.h"
44 #include "clang/Basic/Diagnostic.h"
45 #include "clang/Basic/DiagnosticFrontend.h"
46 #include "llvm/ADT/StringExtras.h"
47 #include "llvm/TargetParser/Triple.h"
49 using namespace clang
;
53 //===----------------------------------------------------------------------===//
54 // Common code shared among targets.
55 //===----------------------------------------------------------------------===//
57 /// DefineStd - Define a macro name and standard variants. For example if
58 /// MacroName is "unix", then this will define "__unix", "__unix__", and "unix"
60 void DefineStd(MacroBuilder
&Builder
, StringRef MacroName
,
61 const LangOptions
&Opts
) {
62 assert(MacroName
[0] != '_' && "Identifier should be in the user's namespace");
64 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier
65 // in the user's namespace.
67 Builder
.defineMacro(MacroName
);
70 Builder
.defineMacro("__" + MacroName
);
73 Builder
.defineMacro("__" + MacroName
+ "__");
76 void defineCPUMacros(MacroBuilder
&Builder
, StringRef CPUName
, bool Tuning
) {
77 Builder
.defineMacro("__" + CPUName
);
78 Builder
.defineMacro("__" + CPUName
+ "__");
80 Builder
.defineMacro("__tune_" + CPUName
+ "__");
83 void addCygMingDefines(const LangOptions
&Opts
, MacroBuilder
&Builder
) {
84 // Mingw and cygwin define __declspec(a) to __attribute__((a)). Clang
85 // supports __declspec natively under -fdeclspec (also enabled with
86 // -fms-extensions), but we define a no-op __declspec macro anyway for
87 // pre-processor compatibility.
88 if (Opts
.DeclSpecKeyword
)
89 Builder
.defineMacro("__declspec", "__declspec");
91 Builder
.defineMacro("__declspec(a)", "__attribute__((a))");
93 if (!Opts
.MicrosoftExt
) {
94 // Provide macros for all the calling convention keywords. Provide both
95 // single and double underscore prefixed variants. These are available on
96 // x64 as well as x86, even though they have no effect.
97 const char *CCs
[] = {"cdecl", "stdcall", "fastcall", "thiscall", "pascal"};
98 for (const char *CC
: CCs
) {
99 std::string GCCSpelling
= "__attribute__((__";
101 GCCSpelling
+= "__))";
102 Builder
.defineMacro(Twine("_") + CC
, GCCSpelling
);
103 Builder
.defineMacro(Twine("__") + CC
, GCCSpelling
);
108 //===----------------------------------------------------------------------===//
110 //===----------------------------------------------------------------------===//
112 std::unique_ptr
<TargetInfo
> AllocateTarget(const llvm::Triple
&Triple
,
113 const TargetOptions
&Opts
) {
114 llvm::Triple::OSType os
= Triple
.getOS();
116 switch (Triple
.getArch()) {
120 case llvm::Triple::arc
:
121 return std::make_unique
<ARCTargetInfo
>(Triple
, Opts
);
123 case llvm::Triple::xcore
:
124 return std::make_unique
<XCoreTargetInfo
>(Triple
, Opts
);
126 case llvm::Triple::hexagon
:
127 if (os
== llvm::Triple::Linux
&&
128 Triple
.getEnvironment() == llvm::Triple::Musl
)
129 return std::make_unique
<LinuxTargetInfo
<HexagonTargetInfo
>>(Triple
, Opts
);
130 return std::make_unique
<HexagonTargetInfo
>(Triple
, Opts
);
132 case llvm::Triple::lanai
:
133 return std::make_unique
<LanaiTargetInfo
>(Triple
, Opts
);
135 case llvm::Triple::aarch64_32
:
136 if (Triple
.isOSDarwin())
137 return std::make_unique
<DarwinAArch64TargetInfo
>(Triple
, Opts
);
140 case llvm::Triple::aarch64
:
141 if (Triple
.isOSDarwin())
142 return std::make_unique
<DarwinAArch64TargetInfo
>(Triple
, Opts
);
145 case llvm::Triple::FreeBSD
:
146 return std::make_unique
<FreeBSDTargetInfo
<AArch64leTargetInfo
>>(Triple
,
148 case llvm::Triple::Fuchsia
:
149 return std::make_unique
<FuchsiaTargetInfo
<AArch64leTargetInfo
>>(Triple
,
151 case llvm::Triple::Haiku
:
152 return std::make_unique
<HaikuTargetInfo
<AArch64leTargetInfo
>>(Triple
,
154 case llvm::Triple::Linux
:
155 switch (Triple
.getEnvironment()) {
157 return std::make_unique
<LinuxTargetInfo
<AArch64leTargetInfo
>>(Triple
,
159 case llvm::Triple::OpenHOS
:
160 return std::make_unique
<OHOSTargetInfo
<AArch64leTargetInfo
>>(Triple
,
163 case llvm::Triple::NetBSD
:
164 return std::make_unique
<NetBSDTargetInfo
<AArch64leTargetInfo
>>(Triple
,
166 case llvm::Triple::OpenBSD
:
167 return std::make_unique
<OpenBSDTargetInfo
<AArch64leTargetInfo
>>(Triple
,
169 case llvm::Triple::Win32
:
170 switch (Triple
.getEnvironment()) {
171 case llvm::Triple::GNU
:
172 return std::make_unique
<MinGWARM64TargetInfo
>(Triple
, Opts
);
173 case llvm::Triple::MSVC
:
174 default: // Assume MSVC for unknown environments
175 return std::make_unique
<MicrosoftARM64TargetInfo
>(Triple
, Opts
);
178 return std::make_unique
<AArch64leTargetInfo
>(Triple
, Opts
);
181 case llvm::Triple::aarch64_be
:
183 case llvm::Triple::FreeBSD
:
184 return std::make_unique
<FreeBSDTargetInfo
<AArch64beTargetInfo
>>(Triple
,
186 case llvm::Triple::Fuchsia
:
187 return std::make_unique
<FuchsiaTargetInfo
<AArch64beTargetInfo
>>(Triple
,
189 case llvm::Triple::Linux
:
190 return std::make_unique
<LinuxTargetInfo
<AArch64beTargetInfo
>>(Triple
,
192 case llvm::Triple::NetBSD
:
193 return std::make_unique
<NetBSDTargetInfo
<AArch64beTargetInfo
>>(Triple
,
196 return std::make_unique
<AArch64beTargetInfo
>(Triple
, Opts
);
199 case llvm::Triple::arm
:
200 case llvm::Triple::thumb
:
201 if (Triple
.isOSBinFormatMachO())
202 return std::make_unique
<DarwinARMTargetInfo
>(Triple
, Opts
);
205 case llvm::Triple::Linux
:
206 switch (Triple
.getEnvironment()) {
208 return std::make_unique
<LinuxTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
209 case llvm::Triple::OpenHOS
:
210 return std::make_unique
<OHOSTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
212 case llvm::Triple::LiteOS
:
213 return std::make_unique
<OHOSTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
214 case llvm::Triple::FreeBSD
:
215 return std::make_unique
<FreeBSDTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
216 case llvm::Triple::NetBSD
:
217 return std::make_unique
<NetBSDTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
218 case llvm::Triple::OpenBSD
:
219 return std::make_unique
<OpenBSDTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
220 case llvm::Triple::RTEMS
:
221 return std::make_unique
<RTEMSTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
222 case llvm::Triple::Haiku
:
223 return std::make_unique
<HaikuTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
224 case llvm::Triple::NaCl
:
225 return std::make_unique
<NaClTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
226 case llvm::Triple::Win32
:
227 switch (Triple
.getEnvironment()) {
228 case llvm::Triple::Cygnus
:
229 return std::make_unique
<CygwinARMTargetInfo
>(Triple
, Opts
);
230 case llvm::Triple::GNU
:
231 return std::make_unique
<MinGWARMTargetInfo
>(Triple
, Opts
);
232 case llvm::Triple::Itanium
:
233 return std::make_unique
<ItaniumWindowsARMleTargetInfo
>(Triple
, Opts
);
234 case llvm::Triple::MSVC
:
235 default: // Assume MSVC for unknown environments
236 return std::make_unique
<MicrosoftARMleTargetInfo
>(Triple
, Opts
);
239 return std::make_unique
<ARMleTargetInfo
>(Triple
, Opts
);
242 case llvm::Triple::armeb
:
243 case llvm::Triple::thumbeb
:
244 if (Triple
.isOSDarwin())
245 return std::make_unique
<DarwinARMTargetInfo
>(Triple
, Opts
);
248 case llvm::Triple::Linux
:
249 return std::make_unique
<LinuxTargetInfo
<ARMbeTargetInfo
>>(Triple
, Opts
);
250 case llvm::Triple::NetBSD
:
251 return std::make_unique
<NetBSDTargetInfo
<ARMbeTargetInfo
>>(Triple
, Opts
);
252 case llvm::Triple::RTEMS
:
253 return std::make_unique
<RTEMSTargetInfo
<ARMbeTargetInfo
>>(Triple
, Opts
);
254 case llvm::Triple::NaCl
:
255 return std::make_unique
<NaClTargetInfo
<ARMbeTargetInfo
>>(Triple
, Opts
);
257 return std::make_unique
<ARMbeTargetInfo
>(Triple
, Opts
);
260 case llvm::Triple::avr
:
261 return std::make_unique
<AVRTargetInfo
>(Triple
, Opts
);
262 case llvm::Triple::bpfeb
:
263 case llvm::Triple::bpfel
:
264 return std::make_unique
<BPFTargetInfo
>(Triple
, Opts
);
266 case llvm::Triple::msp430
:
267 return std::make_unique
<MSP430TargetInfo
>(Triple
, Opts
);
269 case llvm::Triple::mips
:
271 case llvm::Triple::Linux
:
272 return std::make_unique
<LinuxTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
273 case llvm::Triple::RTEMS
:
274 return std::make_unique
<RTEMSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
275 case llvm::Triple::FreeBSD
:
276 return std::make_unique
<FreeBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
277 case llvm::Triple::NetBSD
:
278 return std::make_unique
<NetBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
280 return std::make_unique
<MipsTargetInfo
>(Triple
, Opts
);
283 case llvm::Triple::mipsel
:
285 case llvm::Triple::Linux
:
286 switch (Triple
.getEnvironment()) {
288 return std::make_unique
<LinuxTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
289 case llvm::Triple::OpenHOS
:
290 return std::make_unique
<OHOSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
292 case llvm::Triple::RTEMS
:
293 return std::make_unique
<RTEMSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
294 case llvm::Triple::FreeBSD
:
295 return std::make_unique
<FreeBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
296 case llvm::Triple::NetBSD
:
297 return std::make_unique
<NetBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
298 case llvm::Triple::NaCl
:
299 return std::make_unique
<NaClTargetInfo
<NaClMips32TargetInfo
>>(Triple
,
302 return std::make_unique
<MipsTargetInfo
>(Triple
, Opts
);
305 case llvm::Triple::mips64
:
307 case llvm::Triple::Linux
:
308 return std::make_unique
<LinuxTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
309 case llvm::Triple::RTEMS
:
310 return std::make_unique
<RTEMSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
311 case llvm::Triple::FreeBSD
:
312 return std::make_unique
<FreeBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
313 case llvm::Triple::NetBSD
:
314 return std::make_unique
<NetBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
315 case llvm::Triple::OpenBSD
:
316 return std::make_unique
<OpenBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
318 return std::make_unique
<MipsTargetInfo
>(Triple
, Opts
);
321 case llvm::Triple::mips64el
:
323 case llvm::Triple::Linux
:
324 return std::make_unique
<LinuxTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
325 case llvm::Triple::RTEMS
:
326 return std::make_unique
<RTEMSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
327 case llvm::Triple::FreeBSD
:
328 return std::make_unique
<FreeBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
329 case llvm::Triple::NetBSD
:
330 return std::make_unique
<NetBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
331 case llvm::Triple::OpenBSD
:
332 return std::make_unique
<OpenBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
334 return std::make_unique
<MipsTargetInfo
>(Triple
, Opts
);
337 case llvm::Triple::m68k
:
339 case llvm::Triple::Linux
:
340 return std::make_unique
<LinuxTargetInfo
<M68kTargetInfo
>>(Triple
, Opts
);
341 case llvm::Triple::NetBSD
:
342 return std::make_unique
<NetBSDTargetInfo
<M68kTargetInfo
>>(Triple
, Opts
);
344 return std::make_unique
<M68kTargetInfo
>(Triple
, Opts
);
347 case llvm::Triple::le32
:
349 case llvm::Triple::NaCl
:
350 return std::make_unique
<NaClTargetInfo
<PNaClTargetInfo
>>(Triple
, Opts
);
355 case llvm::Triple::le64
:
356 return std::make_unique
<Le64TargetInfo
>(Triple
, Opts
);
358 case llvm::Triple::ppc
:
360 case llvm::Triple::Linux
:
361 return std::make_unique
<LinuxTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
362 case llvm::Triple::FreeBSD
:
363 return std::make_unique
<FreeBSDTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
364 case llvm::Triple::NetBSD
:
365 return std::make_unique
<NetBSDTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
366 case llvm::Triple::OpenBSD
:
367 return std::make_unique
<OpenBSDTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
368 case llvm::Triple::RTEMS
:
369 return std::make_unique
<RTEMSTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
370 case llvm::Triple::AIX
:
371 return std::make_unique
<AIXPPC32TargetInfo
>(Triple
, Opts
);
373 return std::make_unique
<PPC32TargetInfo
>(Triple
, Opts
);
376 case llvm::Triple::ppcle
:
378 case llvm::Triple::Linux
:
379 return std::make_unique
<LinuxTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
380 case llvm::Triple::FreeBSD
:
381 return std::make_unique
<FreeBSDTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
383 return std::make_unique
<PPC32TargetInfo
>(Triple
, Opts
);
386 case llvm::Triple::ppc64
:
388 case llvm::Triple::Linux
:
389 return std::make_unique
<LinuxTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
390 case llvm::Triple::Lv2
:
391 return std::make_unique
<PS3PPUTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
392 case llvm::Triple::FreeBSD
:
393 return std::make_unique
<FreeBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
394 case llvm::Triple::NetBSD
:
395 return std::make_unique
<NetBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
396 case llvm::Triple::OpenBSD
:
397 return std::make_unique
<OpenBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
398 case llvm::Triple::AIX
:
399 return std::make_unique
<AIXPPC64TargetInfo
>(Triple
, Opts
);
401 return std::make_unique
<PPC64TargetInfo
>(Triple
, Opts
);
404 case llvm::Triple::ppc64le
:
406 case llvm::Triple::Linux
:
407 return std::make_unique
<LinuxTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
408 case llvm::Triple::FreeBSD
:
409 return std::make_unique
<FreeBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
410 case llvm::Triple::NetBSD
:
411 return std::make_unique
<NetBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
412 case llvm::Triple::OpenBSD
:
413 return std::make_unique
<OpenBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
415 return std::make_unique
<PPC64TargetInfo
>(Triple
, Opts
);
418 case llvm::Triple::nvptx
:
419 return std::make_unique
<NVPTXTargetInfo
>(Triple
, Opts
,
420 /*TargetPointerWidth=*/32);
421 case llvm::Triple::nvptx64
:
422 return std::make_unique
<NVPTXTargetInfo
>(Triple
, Opts
,
423 /*TargetPointerWidth=*/64);
425 case llvm::Triple::amdgcn
:
426 case llvm::Triple::r600
:
427 return std::make_unique
<AMDGPUTargetInfo
>(Triple
, Opts
);
429 case llvm::Triple::riscv32
:
431 case llvm::Triple::NetBSD
:
432 return std::make_unique
<NetBSDTargetInfo
<RISCV32TargetInfo
>>(Triple
,
434 case llvm::Triple::Linux
:
435 return std::make_unique
<LinuxTargetInfo
<RISCV32TargetInfo
>>(Triple
, Opts
);
437 return std::make_unique
<RISCV32TargetInfo
>(Triple
, Opts
);
440 case llvm::Triple::riscv64
:
442 case llvm::Triple::FreeBSD
:
443 return std::make_unique
<FreeBSDTargetInfo
<RISCV64TargetInfo
>>(Triple
,
445 case llvm::Triple::NetBSD
:
446 return std::make_unique
<NetBSDTargetInfo
<RISCV64TargetInfo
>>(Triple
,
448 case llvm::Triple::OpenBSD
:
449 return std::make_unique
<OpenBSDTargetInfo
<RISCV64TargetInfo
>>(Triple
,
451 case llvm::Triple::Fuchsia
:
452 return std::make_unique
<FuchsiaTargetInfo
<RISCV64TargetInfo
>>(Triple
,
454 case llvm::Triple::Haiku
:
455 return std::make_unique
<HaikuTargetInfo
<RISCV64TargetInfo
>>(Triple
,
457 case llvm::Triple::Linux
:
458 switch (Triple
.getEnvironment()) {
460 return std::make_unique
<LinuxTargetInfo
<RISCV64TargetInfo
>>(Triple
,
462 case llvm::Triple::OpenHOS
:
463 return std::make_unique
<OHOSTargetInfo
<RISCV64TargetInfo
>>(Triple
,
467 return std::make_unique
<RISCV64TargetInfo
>(Triple
, Opts
);
470 case llvm::Triple::sparc
:
472 case llvm::Triple::Linux
:
473 return std::make_unique
<LinuxTargetInfo
<SparcV8TargetInfo
>>(Triple
, Opts
);
474 case llvm::Triple::Solaris
:
475 return std::make_unique
<SolarisTargetInfo
<SparcV8TargetInfo
>>(Triple
,
477 case llvm::Triple::NetBSD
:
478 return std::make_unique
<NetBSDTargetInfo
<SparcV8TargetInfo
>>(Triple
,
480 case llvm::Triple::RTEMS
:
481 return std::make_unique
<RTEMSTargetInfo
<SparcV8TargetInfo
>>(Triple
, Opts
);
483 return std::make_unique
<SparcV8TargetInfo
>(Triple
, Opts
);
486 case llvm::Triple::sparcel
:
488 case llvm::Triple::Linux
:
489 return std::make_unique
<LinuxTargetInfo
<SparcV8elTargetInfo
>>(Triple
,
491 case llvm::Triple::RTEMS
:
492 return std::make_unique
<RTEMSTargetInfo
<SparcV8elTargetInfo
>>(Triple
,
495 return std::make_unique
<SparcV8elTargetInfo
>(Triple
, Opts
);
498 case llvm::Triple::sparcv9
:
500 case llvm::Triple::Linux
:
501 return std::make_unique
<LinuxTargetInfo
<SparcV9TargetInfo
>>(Triple
, Opts
);
502 case llvm::Triple::Solaris
:
503 return std::make_unique
<SolarisTargetInfo
<SparcV9TargetInfo
>>(Triple
,
505 case llvm::Triple::NetBSD
:
506 return std::make_unique
<NetBSDTargetInfo
<SparcV9TargetInfo
>>(Triple
,
508 case llvm::Triple::OpenBSD
:
509 return std::make_unique
<OpenBSDTargetInfo
<SparcV9TargetInfo
>>(Triple
,
511 case llvm::Triple::FreeBSD
:
512 return std::make_unique
<FreeBSDTargetInfo
<SparcV9TargetInfo
>>(Triple
,
515 return std::make_unique
<SparcV9TargetInfo
>(Triple
, Opts
);
518 case llvm::Triple::systemz
:
520 case llvm::Triple::Linux
:
521 return std::make_unique
<LinuxTargetInfo
<SystemZTargetInfo
>>(Triple
, Opts
);
522 case llvm::Triple::ZOS
:
523 return std::make_unique
<ZOSTargetInfo
<SystemZTargetInfo
>>(Triple
, Opts
);
525 return std::make_unique
<SystemZTargetInfo
>(Triple
, Opts
);
528 case llvm::Triple::tce
:
529 return std::make_unique
<TCETargetInfo
>(Triple
, Opts
);
531 case llvm::Triple::tcele
:
532 return std::make_unique
<TCELETargetInfo
>(Triple
, Opts
);
534 case llvm::Triple::x86
:
535 if (Triple
.isOSDarwin())
536 return std::make_unique
<DarwinI386TargetInfo
>(Triple
, Opts
);
539 case llvm::Triple::Linux
: {
540 switch (Triple
.getEnvironment()) {
542 return std::make_unique
<LinuxTargetInfo
<X86_32TargetInfo
>>(Triple
,
544 case llvm::Triple::Android
:
545 return std::make_unique
<AndroidX86_32TargetInfo
>(Triple
, Opts
);
548 case llvm::Triple::DragonFly
:
549 return std::make_unique
<DragonFlyBSDTargetInfo
<X86_32TargetInfo
>>(Triple
,
551 case llvm::Triple::NetBSD
:
552 return std::make_unique
<NetBSDI386TargetInfo
>(Triple
, Opts
);
553 case llvm::Triple::OpenBSD
:
554 return std::make_unique
<OpenBSDI386TargetInfo
>(Triple
, Opts
);
555 case llvm::Triple::FreeBSD
:
556 return std::make_unique
<FreeBSDTargetInfo
<X86_32TargetInfo
>>(Triple
,
558 case llvm::Triple::Fuchsia
:
559 return std::make_unique
<FuchsiaTargetInfo
<X86_32TargetInfo
>>(Triple
,
561 case llvm::Triple::KFreeBSD
:
562 return std::make_unique
<KFreeBSDTargetInfo
<X86_32TargetInfo
>>(Triple
,
564 case llvm::Triple::Solaris
:
565 return std::make_unique
<SolarisTargetInfo
<X86_32TargetInfo
>>(Triple
,
567 case llvm::Triple::Win32
: {
568 switch (Triple
.getEnvironment()) {
569 case llvm::Triple::Cygnus
:
570 return std::make_unique
<CygwinX86_32TargetInfo
>(Triple
, Opts
);
571 case llvm::Triple::GNU
:
572 return std::make_unique
<MinGWX86_32TargetInfo
>(Triple
, Opts
);
573 case llvm::Triple::Itanium
:
574 case llvm::Triple::MSVC
:
575 default: // Assume MSVC for unknown environments
576 return std::make_unique
<MicrosoftX86_32TargetInfo
>(Triple
, Opts
);
579 case llvm::Triple::Haiku
:
580 return std::make_unique
<HaikuX86_32TargetInfo
>(Triple
, Opts
);
581 case llvm::Triple::RTEMS
:
582 return std::make_unique
<RTEMSX86_32TargetInfo
>(Triple
, Opts
);
583 case llvm::Triple::NaCl
:
584 return std::make_unique
<NaClTargetInfo
<X86_32TargetInfo
>>(Triple
, Opts
);
585 case llvm::Triple::ELFIAMCU
:
586 return std::make_unique
<MCUX86_32TargetInfo
>(Triple
, Opts
);
587 case llvm::Triple::Hurd
:
588 return std::make_unique
<HurdTargetInfo
<X86_32TargetInfo
>>(Triple
, Opts
);
590 return std::make_unique
<X86_32TargetInfo
>(Triple
, Opts
);
593 case llvm::Triple::x86_64
:
594 if (Triple
.isOSDarwin() || Triple
.isOSBinFormatMachO())
595 return std::make_unique
<DarwinX86_64TargetInfo
>(Triple
, Opts
);
598 case llvm::Triple::Linux
: {
599 switch (Triple
.getEnvironment()) {
601 return std::make_unique
<LinuxTargetInfo
<X86_64TargetInfo
>>(Triple
,
603 case llvm::Triple::Android
:
604 return std::make_unique
<AndroidX86_64TargetInfo
>(Triple
, Opts
);
605 case llvm::Triple::OpenHOS
:
606 return std::make_unique
<OHOSX86_64TargetInfo
>(Triple
, Opts
);
609 case llvm::Triple::DragonFly
:
610 return std::make_unique
<DragonFlyBSDTargetInfo
<X86_64TargetInfo
>>(Triple
,
612 case llvm::Triple::NetBSD
:
613 return std::make_unique
<NetBSDTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
614 case llvm::Triple::OpenBSD
:
615 return std::make_unique
<OpenBSDX86_64TargetInfo
>(Triple
, Opts
);
616 case llvm::Triple::FreeBSD
:
617 return std::make_unique
<FreeBSDTargetInfo
<X86_64TargetInfo
>>(Triple
,
619 case llvm::Triple::Fuchsia
:
620 return std::make_unique
<FuchsiaTargetInfo
<X86_64TargetInfo
>>(Triple
,
622 case llvm::Triple::KFreeBSD
:
623 return std::make_unique
<KFreeBSDTargetInfo
<X86_64TargetInfo
>>(Triple
,
625 case llvm::Triple::Solaris
:
626 return std::make_unique
<SolarisTargetInfo
<X86_64TargetInfo
>>(Triple
,
628 case llvm::Triple::Win32
: {
629 switch (Triple
.getEnvironment()) {
630 case llvm::Triple::Cygnus
:
631 return std::make_unique
<CygwinX86_64TargetInfo
>(Triple
, Opts
);
632 case llvm::Triple::GNU
:
633 return std::make_unique
<MinGWX86_64TargetInfo
>(Triple
, Opts
);
634 case llvm::Triple::MSVC
:
635 default: // Assume MSVC for unknown environments
636 return std::make_unique
<MicrosoftX86_64TargetInfo
>(Triple
, Opts
);
639 case llvm::Triple::Haiku
:
640 return std::make_unique
<HaikuTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
641 case llvm::Triple::NaCl
:
642 return std::make_unique
<NaClTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
643 case llvm::Triple::PS4
:
644 return std::make_unique
<PS4OSTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
645 case llvm::Triple::PS5
:
646 return std::make_unique
<PS5OSTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
647 case llvm::Triple::Hurd
:
648 return std::make_unique
<HurdTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
650 return std::make_unique
<X86_64TargetInfo
>(Triple
, Opts
);
653 case llvm::Triple::spir
: {
654 if (os
!= llvm::Triple::UnknownOS
||
655 Triple
.getEnvironment() != llvm::Triple::UnknownEnvironment
)
657 return std::make_unique
<SPIR32TargetInfo
>(Triple
, Opts
);
659 case llvm::Triple::spir64
: {
660 if (os
!= llvm::Triple::UnknownOS
||
661 Triple
.getEnvironment() != llvm::Triple::UnknownEnvironment
)
663 return std::make_unique
<SPIR64TargetInfo
>(Triple
, Opts
);
665 case llvm::Triple::spirv
: {
666 return std::make_unique
<SPIRVTargetInfo
>(Triple
, Opts
);
668 case llvm::Triple::spirv32
: {
669 if (os
!= llvm::Triple::UnknownOS
||
670 Triple
.getEnvironment() != llvm::Triple::UnknownEnvironment
)
672 return std::make_unique
<SPIRV32TargetInfo
>(Triple
, Opts
);
674 case llvm::Triple::spirv64
: {
675 if (os
!= llvm::Triple::UnknownOS
||
676 Triple
.getEnvironment() != llvm::Triple::UnknownEnvironment
)
678 return std::make_unique
<SPIRV64TargetInfo
>(Triple
, Opts
);
680 case llvm::Triple::wasm32
:
681 if (Triple
.getSubArch() != llvm::Triple::NoSubArch
||
682 Triple
.getVendor() != llvm::Triple::UnknownVendor
||
683 !Triple
.isOSBinFormatWasm())
686 case llvm::Triple::WASI
:
687 return std::make_unique
<WASITargetInfo
<WebAssembly32TargetInfo
>>(Triple
,
689 case llvm::Triple::Emscripten
:
690 return std::make_unique
<EmscriptenTargetInfo
<WebAssembly32TargetInfo
>>(
692 case llvm::Triple::UnknownOS
:
693 return std::make_unique
<WebAssemblyOSTargetInfo
<WebAssembly32TargetInfo
>>(
698 case llvm::Triple::wasm64
:
699 if (Triple
.getSubArch() != llvm::Triple::NoSubArch
||
700 Triple
.getVendor() != llvm::Triple::UnknownVendor
||
701 !Triple
.isOSBinFormatWasm())
704 case llvm::Triple::WASI
:
705 return std::make_unique
<WASITargetInfo
<WebAssembly64TargetInfo
>>(Triple
,
707 case llvm::Triple::Emscripten
:
708 return std::make_unique
<EmscriptenTargetInfo
<WebAssembly64TargetInfo
>>(
710 case llvm::Triple::UnknownOS
:
711 return std::make_unique
<WebAssemblyOSTargetInfo
<WebAssembly64TargetInfo
>>(
717 case llvm::Triple::dxil
:
718 return std::make_unique
<DirectXTargetInfo
>(Triple
, Opts
);
719 case llvm::Triple::renderscript32
:
720 return std::make_unique
<LinuxTargetInfo
<RenderScript32TargetInfo
>>(Triple
,
722 case llvm::Triple::renderscript64
:
723 return std::make_unique
<LinuxTargetInfo
<RenderScript64TargetInfo
>>(Triple
,
726 case llvm::Triple::ve
:
727 return std::make_unique
<LinuxTargetInfo
<VETargetInfo
>>(Triple
, Opts
);
729 case llvm::Triple::csky
:
731 case llvm::Triple::Linux
:
732 return std::make_unique
<LinuxTargetInfo
<CSKYTargetInfo
>>(Triple
, Opts
);
734 return std::make_unique
<CSKYTargetInfo
>(Triple
, Opts
);
736 case llvm::Triple::loongarch32
:
738 case llvm::Triple::Linux
:
739 return std::make_unique
<LinuxTargetInfo
<LoongArch32TargetInfo
>>(Triple
,
742 return std::make_unique
<LoongArch32TargetInfo
>(Triple
, Opts
);
744 case llvm::Triple::loongarch64
:
746 case llvm::Triple::Linux
:
747 return std::make_unique
<LinuxTargetInfo
<LoongArch64TargetInfo
>>(Triple
,
750 return std::make_unique
<LoongArch64TargetInfo
>(Triple
, Opts
);
754 } // namespace targets
757 using namespace clang::targets
;
758 /// CreateTargetInfo - Return the target info object for the specified target
761 TargetInfo::CreateTargetInfo(DiagnosticsEngine
&Diags
,
762 const std::shared_ptr
<TargetOptions
> &Opts
) {
763 llvm::Triple
Triple(Opts
->Triple
);
765 // Construct the target
766 std::unique_ptr
<TargetInfo
> Target
= AllocateTarget(Triple
, *Opts
);
768 Diags
.Report(diag::err_target_unknown_triple
) << Triple
.str();
771 Target
->TargetOpts
= Opts
;
773 // Set the target CPU if specified.
774 if (!Opts
->CPU
.empty() && !Target
->setCPU(Opts
->CPU
)) {
775 Diags
.Report(diag::err_target_unknown_cpu
) << Opts
->CPU
;
776 SmallVector
<StringRef
, 32> ValidList
;
777 Target
->fillValidCPUList(ValidList
);
778 if (!ValidList
.empty())
779 Diags
.Report(diag::note_valid_options
) << llvm::join(ValidList
, ", ");
783 // Check the TuneCPU name if specified.
784 if (!Opts
->TuneCPU
.empty() &&
785 !Target
->isValidTuneCPUName(Opts
->TuneCPU
)) {
786 Diags
.Report(diag::err_target_unknown_cpu
) << Opts
->TuneCPU
;
787 SmallVector
<StringRef
, 32> ValidList
;
788 Target
->fillValidTuneCPUList(ValidList
);
789 if (!ValidList
.empty())
790 Diags
.Report(diag::note_valid_options
) << llvm::join(ValidList
, ", ");
794 // Set the target ABI if specified.
795 if (!Opts
->ABI
.empty() && !Target
->setABI(Opts
->ABI
)) {
796 Diags
.Report(diag::err_target_unknown_abi
) << Opts
->ABI
;
800 // Set the fp math unit.
801 if (!Opts
->FPMath
.empty() && !Target
->setFPMath(Opts
->FPMath
)) {
802 Diags
.Report(diag::err_target_unknown_fpmath
) << Opts
->FPMath
;
806 // Compute the default target features, we need the target to handle this
807 // because features may have dependencies on one another.
808 llvm::erase_if(Opts
->FeaturesAsWritten
, [&](StringRef Name
) {
809 if (Target
->isReadOnlyFeature(Name
.substr(1))) {
810 Diags
.Report(diag::warn_fe_backend_readonly_feature_flag
) << Name
;
815 if (!Target
->initFeatureMap(Opts
->FeatureMap
, Diags
, Opts
->CPU
,
816 Opts
->FeaturesAsWritten
))
819 // Add the features to the compile options.
820 Opts
->Features
.clear();
821 for (const auto &F
: Opts
->FeatureMap
)
822 Opts
->Features
.push_back((F
.getValue() ? "+" : "-") + F
.getKey().str());
823 // Sort here, so we handle the features in a predictable order. (This matters
824 // when we're dealing with features that overlap.)
825 llvm::sort(Opts
->Features
);
827 if (!Target
->handleTargetFeatures(Opts
->Features
, Diags
))
830 Target
->setSupportedOpenCLOpts();
831 Target
->setCommandLineOpenCLOpts();
832 Target
->setMaxAtomicWidth();
834 if (!Opts
->DarwinTargetVariantTriple
.empty())
835 Target
->DarwinTargetVariantTriple
=
836 llvm::Triple(Opts
->DarwinTargetVariantTriple
);
838 if (!Target
->validateTarget(Diags
))
841 Target
->CheckFixedPointBits();
843 return Target
.release();
845 /// validateOpenCLTarget - Check that OpenCL target has valid
846 /// options setting based on OpenCL version.
847 bool TargetInfo::validateOpenCLTarget(const LangOptions
&Opts
,
848 DiagnosticsEngine
&Diags
) const {
849 const llvm::StringMap
<bool> &OpenCLFeaturesMap
= getSupportedOpenCLOpts();
851 auto diagnoseNotSupportedCore
= [&](llvm::StringRef Name
, auto... OptArgs
) {
852 if (OpenCLOptions::isOpenCLOptionCoreIn(Opts
, OptArgs
...) &&
853 !hasFeatureEnabled(OpenCLFeaturesMap
, Name
))
854 Diags
.Report(diag::warn_opencl_unsupported_core_feature
)
855 << Name
<< Opts
.OpenCLCPlusPlus
856 << Opts
.getOpenCLVersionTuple().getAsString();
858 #define OPENCL_GENERIC_EXTENSION(Ext, ...) \
859 diagnoseNotSupportedCore(#Ext, __VA_ARGS__);
860 #include "clang/Basic/OpenCLExtensions.def"
862 // Validate that feature macros are set properly for OpenCL C 3.0.
863 // In other cases assume that target is always valid.
864 if (Opts
.getOpenCLCompatibleVersion() < 300)
867 return OpenCLOptions::diagnoseUnsupportedFeatureDependencies(*this, Diags
) &&
868 OpenCLOptions::diagnoseFeatureExtensionDifferences(*this, Diags
);