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 "llvm/ADT/StringExtras.h"
46 #include "llvm/TargetParser/Triple.h"
48 using namespace clang
;
52 //===----------------------------------------------------------------------===//
53 // Common code shared among targets.
54 //===----------------------------------------------------------------------===//
56 /// DefineStd - Define a macro name and standard variants. For example if
57 /// MacroName is "unix", then this will define "__unix", "__unix__", and "unix"
59 void DefineStd(MacroBuilder
&Builder
, StringRef MacroName
,
60 const LangOptions
&Opts
) {
61 assert(MacroName
[0] != '_' && "Identifier should be in the user's namespace");
63 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier
64 // in the user's namespace.
66 Builder
.defineMacro(MacroName
);
69 Builder
.defineMacro("__" + MacroName
);
72 Builder
.defineMacro("__" + MacroName
+ "__");
75 void defineCPUMacros(MacroBuilder
&Builder
, StringRef CPUName
, bool Tuning
) {
76 Builder
.defineMacro("__" + CPUName
);
77 Builder
.defineMacro("__" + CPUName
+ "__");
79 Builder
.defineMacro("__tune_" + CPUName
+ "__");
82 void addCygMingDefines(const LangOptions
&Opts
, MacroBuilder
&Builder
) {
83 // Mingw and cygwin define __declspec(a) to __attribute__((a)). Clang
84 // supports __declspec natively under -fdeclspec (also enabled with
85 // -fms-extensions), but we define a no-op __declspec macro anyway for
86 // pre-processor compatibility.
87 if (Opts
.DeclSpecKeyword
)
88 Builder
.defineMacro("__declspec", "__declspec");
90 Builder
.defineMacro("__declspec(a)", "__attribute__((a))");
92 if (!Opts
.MicrosoftExt
) {
93 // Provide macros for all the calling convention keywords. Provide both
94 // single and double underscore prefixed variants. These are available on
95 // x64 as well as x86, even though they have no effect.
96 const char *CCs
[] = {"cdecl", "stdcall", "fastcall", "thiscall", "pascal"};
97 for (const char *CC
: CCs
) {
98 std::string GCCSpelling
= "__attribute__((__";
100 GCCSpelling
+= "__))";
101 Builder
.defineMacro(Twine("_") + CC
, GCCSpelling
);
102 Builder
.defineMacro(Twine("__") + CC
, GCCSpelling
);
107 //===----------------------------------------------------------------------===//
109 //===----------------------------------------------------------------------===//
111 std::unique_ptr
<TargetInfo
> AllocateTarget(const llvm::Triple
&Triple
,
112 const TargetOptions
&Opts
) {
113 llvm::Triple::OSType os
= Triple
.getOS();
115 switch (Triple
.getArch()) {
119 case llvm::Triple::arc
:
120 return std::make_unique
<ARCTargetInfo
>(Triple
, Opts
);
122 case llvm::Triple::xcore
:
123 return std::make_unique
<XCoreTargetInfo
>(Triple
, Opts
);
125 case llvm::Triple::hexagon
:
126 if (os
== llvm::Triple::Linux
&&
127 Triple
.getEnvironment() == llvm::Triple::Musl
)
128 return std::make_unique
<LinuxTargetInfo
<HexagonTargetInfo
>>(Triple
, Opts
);
129 return std::make_unique
<HexagonTargetInfo
>(Triple
, Opts
);
131 case llvm::Triple::lanai
:
132 return std::make_unique
<LanaiTargetInfo
>(Triple
, Opts
);
134 case llvm::Triple::aarch64_32
:
135 if (Triple
.isOSDarwin())
136 return std::make_unique
<DarwinAArch64TargetInfo
>(Triple
, Opts
);
139 case llvm::Triple::aarch64
:
140 if (Triple
.isOSDarwin())
141 return std::make_unique
<DarwinAArch64TargetInfo
>(Triple
, Opts
);
144 case llvm::Triple::CloudABI
:
145 return std::make_unique
<CloudABITargetInfo
<AArch64leTargetInfo
>>(Triple
,
147 case llvm::Triple::FreeBSD
:
148 return std::make_unique
<FreeBSDTargetInfo
<AArch64leTargetInfo
>>(Triple
,
150 case llvm::Triple::Fuchsia
:
151 return std::make_unique
<FuchsiaTargetInfo
<AArch64leTargetInfo
>>(Triple
,
153 case llvm::Triple::Linux
:
154 switch (Triple
.getEnvironment()) {
156 return std::make_unique
<LinuxTargetInfo
<AArch64leTargetInfo
>>(Triple
,
158 case llvm::Triple::OpenHOS
:
159 return std::make_unique
<OHOSTargetInfo
<AArch64leTargetInfo
>>(Triple
,
162 case llvm::Triple::NetBSD
:
163 return std::make_unique
<NetBSDTargetInfo
<AArch64leTargetInfo
>>(Triple
,
165 case llvm::Triple::OpenBSD
:
166 return std::make_unique
<OpenBSDTargetInfo
<AArch64leTargetInfo
>>(Triple
,
168 case llvm::Triple::Win32
:
169 switch (Triple
.getEnvironment()) {
170 case llvm::Triple::GNU
:
171 return std::make_unique
<MinGWARM64TargetInfo
>(Triple
, Opts
);
172 case llvm::Triple::MSVC
:
173 default: // Assume MSVC for unknown environments
174 return std::make_unique
<MicrosoftARM64TargetInfo
>(Triple
, Opts
);
177 return std::make_unique
<AArch64leTargetInfo
>(Triple
, Opts
);
180 case llvm::Triple::aarch64_be
:
182 case llvm::Triple::FreeBSD
:
183 return std::make_unique
<FreeBSDTargetInfo
<AArch64beTargetInfo
>>(Triple
,
185 case llvm::Triple::Fuchsia
:
186 return std::make_unique
<FuchsiaTargetInfo
<AArch64beTargetInfo
>>(Triple
,
188 case llvm::Triple::Linux
:
189 return std::make_unique
<LinuxTargetInfo
<AArch64beTargetInfo
>>(Triple
,
191 case llvm::Triple::NetBSD
:
192 return std::make_unique
<NetBSDTargetInfo
<AArch64beTargetInfo
>>(Triple
,
195 return std::make_unique
<AArch64beTargetInfo
>(Triple
, Opts
);
198 case llvm::Triple::arm
:
199 case llvm::Triple::thumb
:
200 if (Triple
.isOSBinFormatMachO())
201 return std::make_unique
<DarwinARMTargetInfo
>(Triple
, Opts
);
204 case llvm::Triple::CloudABI
:
205 return std::make_unique
<CloudABITargetInfo
<ARMleTargetInfo
>>(Triple
,
207 case llvm::Triple::Linux
:
208 switch (Triple
.getEnvironment()) {
210 return std::make_unique
<LinuxTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
211 case llvm::Triple::OpenHOS
:
212 return std::make_unique
<OHOSTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
214 case llvm::Triple::LiteOS
:
215 return std::make_unique
<OHOSTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
216 case llvm::Triple::FreeBSD
:
217 return std::make_unique
<FreeBSDTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
218 case llvm::Triple::NetBSD
:
219 return std::make_unique
<NetBSDTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
220 case llvm::Triple::OpenBSD
:
221 return std::make_unique
<OpenBSDTargetInfo
<ARMleTargetInfo
>>(Triple
, Opts
);
222 case llvm::Triple::RTEMS
:
223 return std::make_unique
<RTEMSTargetInfo
<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::FreeBSD
:
251 return std::make_unique
<FreeBSDTargetInfo
<ARMbeTargetInfo
>>(Triple
, Opts
);
252 case llvm::Triple::NetBSD
:
253 return std::make_unique
<NetBSDTargetInfo
<ARMbeTargetInfo
>>(Triple
, Opts
);
254 case llvm::Triple::OpenBSD
:
255 return std::make_unique
<OpenBSDTargetInfo
<ARMbeTargetInfo
>>(Triple
, Opts
);
256 case llvm::Triple::RTEMS
:
257 return std::make_unique
<RTEMSTargetInfo
<ARMbeTargetInfo
>>(Triple
, Opts
);
258 case llvm::Triple::NaCl
:
259 return std::make_unique
<NaClTargetInfo
<ARMbeTargetInfo
>>(Triple
, Opts
);
261 return std::make_unique
<ARMbeTargetInfo
>(Triple
, Opts
);
264 case llvm::Triple::avr
:
265 return std::make_unique
<AVRTargetInfo
>(Triple
, Opts
);
266 case llvm::Triple::bpfeb
:
267 case llvm::Triple::bpfel
:
268 return std::make_unique
<BPFTargetInfo
>(Triple
, Opts
);
270 case llvm::Triple::msp430
:
271 return std::make_unique
<MSP430TargetInfo
>(Triple
, Opts
);
273 case llvm::Triple::mips
:
275 case llvm::Triple::Linux
:
276 return std::make_unique
<LinuxTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
277 case llvm::Triple::RTEMS
:
278 return std::make_unique
<RTEMSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
279 case llvm::Triple::FreeBSD
:
280 return std::make_unique
<FreeBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
281 case llvm::Triple::NetBSD
:
282 return std::make_unique
<NetBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
284 return std::make_unique
<MipsTargetInfo
>(Triple
, Opts
);
287 case llvm::Triple::mipsel
:
289 case llvm::Triple::Linux
:
290 switch (Triple
.getEnvironment()) {
292 return std::make_unique
<LinuxTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
293 case llvm::Triple::OpenHOS
:
294 return std::make_unique
<OHOSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
296 case llvm::Triple::RTEMS
:
297 return std::make_unique
<RTEMSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
298 case llvm::Triple::FreeBSD
:
299 return std::make_unique
<FreeBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
300 case llvm::Triple::NetBSD
:
301 return std::make_unique
<NetBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
302 case llvm::Triple::NaCl
:
303 return std::make_unique
<NaClTargetInfo
<NaClMips32TargetInfo
>>(Triple
,
306 return std::make_unique
<MipsTargetInfo
>(Triple
, Opts
);
309 case llvm::Triple::mips64
:
311 case llvm::Triple::Linux
:
312 return std::make_unique
<LinuxTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
313 case llvm::Triple::RTEMS
:
314 return std::make_unique
<RTEMSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
315 case llvm::Triple::FreeBSD
:
316 return std::make_unique
<FreeBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
317 case llvm::Triple::NetBSD
:
318 return std::make_unique
<NetBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
319 case llvm::Triple::OpenBSD
:
320 return std::make_unique
<OpenBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
322 return std::make_unique
<MipsTargetInfo
>(Triple
, Opts
);
325 case llvm::Triple::mips64el
:
327 case llvm::Triple::Linux
:
328 return std::make_unique
<LinuxTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
329 case llvm::Triple::RTEMS
:
330 return std::make_unique
<RTEMSTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
331 case llvm::Triple::FreeBSD
:
332 return std::make_unique
<FreeBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
333 case llvm::Triple::NetBSD
:
334 return std::make_unique
<NetBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
335 case llvm::Triple::OpenBSD
:
336 return std::make_unique
<OpenBSDTargetInfo
<MipsTargetInfo
>>(Triple
, Opts
);
338 return std::make_unique
<MipsTargetInfo
>(Triple
, Opts
);
341 case llvm::Triple::m68k
:
343 case llvm::Triple::Linux
:
344 return std::make_unique
<LinuxTargetInfo
<M68kTargetInfo
>>(Triple
, Opts
);
345 case llvm::Triple::NetBSD
:
346 return std::make_unique
<NetBSDTargetInfo
<M68kTargetInfo
>>(Triple
, Opts
);
348 return std::make_unique
<M68kTargetInfo
>(Triple
, Opts
);
351 case llvm::Triple::le32
:
353 case llvm::Triple::NaCl
:
354 return std::make_unique
<NaClTargetInfo
<PNaClTargetInfo
>>(Triple
, Opts
);
359 case llvm::Triple::le64
:
360 return std::make_unique
<Le64TargetInfo
>(Triple
, Opts
);
362 case llvm::Triple::ppc
:
364 case llvm::Triple::Linux
:
365 return std::make_unique
<LinuxTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
366 case llvm::Triple::FreeBSD
:
367 return std::make_unique
<FreeBSDTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
368 case llvm::Triple::NetBSD
:
369 return std::make_unique
<NetBSDTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
370 case llvm::Triple::OpenBSD
:
371 return std::make_unique
<OpenBSDTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
372 case llvm::Triple::RTEMS
:
373 return std::make_unique
<RTEMSTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
374 case llvm::Triple::AIX
:
375 return std::make_unique
<AIXPPC32TargetInfo
>(Triple
, Opts
);
377 return std::make_unique
<PPC32TargetInfo
>(Triple
, Opts
);
380 case llvm::Triple::ppcle
:
382 case llvm::Triple::Linux
:
383 return std::make_unique
<LinuxTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
384 case llvm::Triple::FreeBSD
:
385 return std::make_unique
<FreeBSDTargetInfo
<PPC32TargetInfo
>>(Triple
, Opts
);
387 return std::make_unique
<PPC32TargetInfo
>(Triple
, Opts
);
390 case llvm::Triple::ppc64
:
392 case llvm::Triple::Linux
:
393 return std::make_unique
<LinuxTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
394 case llvm::Triple::Lv2
:
395 return std::make_unique
<PS3PPUTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
396 case llvm::Triple::FreeBSD
:
397 return std::make_unique
<FreeBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
398 case llvm::Triple::NetBSD
:
399 return std::make_unique
<NetBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
400 case llvm::Triple::OpenBSD
:
401 return std::make_unique
<OpenBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
402 case llvm::Triple::AIX
:
403 return std::make_unique
<AIXPPC64TargetInfo
>(Triple
, Opts
);
405 return std::make_unique
<PPC64TargetInfo
>(Triple
, Opts
);
408 case llvm::Triple::ppc64le
:
410 case llvm::Triple::Linux
:
411 return std::make_unique
<LinuxTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
412 case llvm::Triple::FreeBSD
:
413 return std::make_unique
<FreeBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
414 case llvm::Triple::NetBSD
:
415 return std::make_unique
<NetBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
416 case llvm::Triple::OpenBSD
:
417 return std::make_unique
<OpenBSDTargetInfo
<PPC64TargetInfo
>>(Triple
, Opts
);
419 return std::make_unique
<PPC64TargetInfo
>(Triple
, Opts
);
422 case llvm::Triple::nvptx
:
423 return std::make_unique
<NVPTXTargetInfo
>(Triple
, Opts
,
424 /*TargetPointerWidth=*/32);
425 case llvm::Triple::nvptx64
:
426 return std::make_unique
<NVPTXTargetInfo
>(Triple
, Opts
,
427 /*TargetPointerWidth=*/64);
429 case llvm::Triple::amdgcn
:
430 case llvm::Triple::r600
:
431 return std::make_unique
<AMDGPUTargetInfo
>(Triple
, Opts
);
433 case llvm::Triple::riscv32
:
434 // TODO: add cases for NetBSD, RTEMS once tested.
436 case llvm::Triple::FreeBSD
:
437 return std::make_unique
<FreeBSDTargetInfo
<RISCV32TargetInfo
>>(Triple
,
439 case llvm::Triple::Linux
:
440 return std::make_unique
<LinuxTargetInfo
<RISCV32TargetInfo
>>(Triple
, Opts
);
442 return std::make_unique
<RISCV32TargetInfo
>(Triple
, Opts
);
445 case llvm::Triple::riscv64
:
446 // TODO: add cases for NetBSD, RTEMS once tested.
448 case llvm::Triple::FreeBSD
:
449 return std::make_unique
<FreeBSDTargetInfo
<RISCV64TargetInfo
>>(Triple
,
451 case llvm::Triple::OpenBSD
:
452 return std::make_unique
<OpenBSDTargetInfo
<RISCV64TargetInfo
>>(Triple
,
454 case llvm::Triple::Fuchsia
:
455 return std::make_unique
<FuchsiaTargetInfo
<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 // The 'sparcel' architecture copies all the above cases except for Solaris.
487 case llvm::Triple::sparcel
:
489 case llvm::Triple::Linux
:
490 return std::make_unique
<LinuxTargetInfo
<SparcV8elTargetInfo
>>(Triple
,
492 case llvm::Triple::NetBSD
:
493 return std::make_unique
<NetBSDTargetInfo
<SparcV8elTargetInfo
>>(Triple
,
495 case llvm::Triple::RTEMS
:
496 return std::make_unique
<RTEMSTargetInfo
<SparcV8elTargetInfo
>>(Triple
,
499 return std::make_unique
<SparcV8elTargetInfo
>(Triple
, Opts
);
502 case llvm::Triple::sparcv9
:
504 case llvm::Triple::Linux
:
505 return std::make_unique
<LinuxTargetInfo
<SparcV9TargetInfo
>>(Triple
, Opts
);
506 case llvm::Triple::Solaris
:
507 return std::make_unique
<SolarisTargetInfo
<SparcV9TargetInfo
>>(Triple
,
509 case llvm::Triple::NetBSD
:
510 return std::make_unique
<NetBSDTargetInfo
<SparcV9TargetInfo
>>(Triple
,
512 case llvm::Triple::OpenBSD
:
513 return std::make_unique
<OpenBSDTargetInfo
<SparcV9TargetInfo
>>(Triple
,
515 case llvm::Triple::FreeBSD
:
516 return std::make_unique
<FreeBSDTargetInfo
<SparcV9TargetInfo
>>(Triple
,
519 return std::make_unique
<SparcV9TargetInfo
>(Triple
, Opts
);
522 case llvm::Triple::systemz
:
524 case llvm::Triple::Linux
:
525 return std::make_unique
<LinuxTargetInfo
<SystemZTargetInfo
>>(Triple
, Opts
);
526 case llvm::Triple::ZOS
:
527 return std::make_unique
<ZOSTargetInfo
<SystemZTargetInfo
>>(Triple
, Opts
);
529 return std::make_unique
<SystemZTargetInfo
>(Triple
, Opts
);
532 case llvm::Triple::tce
:
533 return std::make_unique
<TCETargetInfo
>(Triple
, Opts
);
535 case llvm::Triple::tcele
:
536 return std::make_unique
<TCELETargetInfo
>(Triple
, Opts
);
538 case llvm::Triple::x86
:
539 if (Triple
.isOSDarwin())
540 return std::make_unique
<DarwinI386TargetInfo
>(Triple
, Opts
);
543 case llvm::Triple::Ananas
:
544 return std::make_unique
<AnanasTargetInfo
<X86_32TargetInfo
>>(Triple
, Opts
);
545 case llvm::Triple::CloudABI
:
546 return std::make_unique
<CloudABITargetInfo
<X86_32TargetInfo
>>(Triple
,
548 case llvm::Triple::Linux
: {
549 switch (Triple
.getEnvironment()) {
551 return std::make_unique
<LinuxTargetInfo
<X86_32TargetInfo
>>(Triple
,
553 case llvm::Triple::Android
:
554 return std::make_unique
<AndroidX86_32TargetInfo
>(Triple
, Opts
);
557 case llvm::Triple::DragonFly
:
558 return std::make_unique
<DragonFlyBSDTargetInfo
<X86_32TargetInfo
>>(Triple
,
560 case llvm::Triple::NetBSD
:
561 return std::make_unique
<NetBSDI386TargetInfo
>(Triple
, Opts
);
562 case llvm::Triple::OpenBSD
:
563 return std::make_unique
<OpenBSDI386TargetInfo
>(Triple
, Opts
);
564 case llvm::Triple::FreeBSD
:
565 return std::make_unique
<FreeBSDTargetInfo
<X86_32TargetInfo
>>(Triple
,
567 case llvm::Triple::Fuchsia
:
568 return std::make_unique
<FuchsiaTargetInfo
<X86_32TargetInfo
>>(Triple
,
570 case llvm::Triple::KFreeBSD
:
571 return std::make_unique
<KFreeBSDTargetInfo
<X86_32TargetInfo
>>(Triple
,
573 case llvm::Triple::Minix
:
574 return std::make_unique
<MinixTargetInfo
<X86_32TargetInfo
>>(Triple
, Opts
);
575 case llvm::Triple::Solaris
:
576 return std::make_unique
<SolarisTargetInfo
<X86_32TargetInfo
>>(Triple
,
578 case llvm::Triple::Win32
: {
579 switch (Triple
.getEnvironment()) {
580 case llvm::Triple::Cygnus
:
581 return std::make_unique
<CygwinX86_32TargetInfo
>(Triple
, Opts
);
582 case llvm::Triple::GNU
:
583 return std::make_unique
<MinGWX86_32TargetInfo
>(Triple
, Opts
);
584 case llvm::Triple::Itanium
:
585 case llvm::Triple::MSVC
:
586 default: // Assume MSVC for unknown environments
587 return std::make_unique
<MicrosoftX86_32TargetInfo
>(Triple
, Opts
);
590 case llvm::Triple::Haiku
:
591 return std::make_unique
<HaikuX86_32TargetInfo
>(Triple
, Opts
);
592 case llvm::Triple::RTEMS
:
593 return std::make_unique
<RTEMSX86_32TargetInfo
>(Triple
, Opts
);
594 case llvm::Triple::NaCl
:
595 return std::make_unique
<NaClTargetInfo
<X86_32TargetInfo
>>(Triple
, Opts
);
596 case llvm::Triple::ELFIAMCU
:
597 return std::make_unique
<MCUX86_32TargetInfo
>(Triple
, Opts
);
598 case llvm::Triple::Hurd
:
599 return std::make_unique
<HurdTargetInfo
<X86_32TargetInfo
>>(Triple
, Opts
);
601 return std::make_unique
<X86_32TargetInfo
>(Triple
, Opts
);
604 case llvm::Triple::x86_64
:
605 if (Triple
.isOSDarwin() || Triple
.isOSBinFormatMachO())
606 return std::make_unique
<DarwinX86_64TargetInfo
>(Triple
, Opts
);
609 case llvm::Triple::Ananas
:
610 return std::make_unique
<AnanasTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
611 case llvm::Triple::CloudABI
:
612 return std::make_unique
<CloudABITargetInfo
<X86_64TargetInfo
>>(Triple
,
614 case llvm::Triple::Linux
: {
615 switch (Triple
.getEnvironment()) {
617 return std::make_unique
<LinuxTargetInfo
<X86_64TargetInfo
>>(Triple
,
619 case llvm::Triple::Android
:
620 return std::make_unique
<AndroidX86_64TargetInfo
>(Triple
, Opts
);
621 case llvm::Triple::OpenHOS
:
622 return std::make_unique
<OHOSX86_64TargetInfo
>(Triple
, Opts
);
625 case llvm::Triple::DragonFly
:
626 return std::make_unique
<DragonFlyBSDTargetInfo
<X86_64TargetInfo
>>(Triple
,
628 case llvm::Triple::NetBSD
:
629 return std::make_unique
<NetBSDTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
630 case llvm::Triple::OpenBSD
:
631 return std::make_unique
<OpenBSDX86_64TargetInfo
>(Triple
, Opts
);
632 case llvm::Triple::FreeBSD
:
633 return std::make_unique
<FreeBSDTargetInfo
<X86_64TargetInfo
>>(Triple
,
635 case llvm::Triple::Fuchsia
:
636 return std::make_unique
<FuchsiaTargetInfo
<X86_64TargetInfo
>>(Triple
,
638 case llvm::Triple::KFreeBSD
:
639 return std::make_unique
<KFreeBSDTargetInfo
<X86_64TargetInfo
>>(Triple
,
641 case llvm::Triple::Solaris
:
642 return std::make_unique
<SolarisTargetInfo
<X86_64TargetInfo
>>(Triple
,
644 case llvm::Triple::Win32
: {
645 switch (Triple
.getEnvironment()) {
646 case llvm::Triple::Cygnus
:
647 return std::make_unique
<CygwinX86_64TargetInfo
>(Triple
, Opts
);
648 case llvm::Triple::GNU
:
649 return std::make_unique
<MinGWX86_64TargetInfo
>(Triple
, Opts
);
650 case llvm::Triple::MSVC
:
651 default: // Assume MSVC for unknown environments
652 return std::make_unique
<MicrosoftX86_64TargetInfo
>(Triple
, Opts
);
655 case llvm::Triple::Haiku
:
656 return std::make_unique
<HaikuTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
657 case llvm::Triple::NaCl
:
658 return std::make_unique
<NaClTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
659 case llvm::Triple::PS4
:
660 return std::make_unique
<PS4OSTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
661 case llvm::Triple::PS5
:
662 return std::make_unique
<PS5OSTargetInfo
<X86_64TargetInfo
>>(Triple
, Opts
);
664 return std::make_unique
<X86_64TargetInfo
>(Triple
, Opts
);
667 case llvm::Triple::spir
: {
668 if (os
!= llvm::Triple::UnknownOS
||
669 Triple
.getEnvironment() != llvm::Triple::UnknownEnvironment
)
671 return std::make_unique
<SPIR32TargetInfo
>(Triple
, Opts
);
673 case llvm::Triple::spir64
: {
674 if (os
!= llvm::Triple::UnknownOS
||
675 Triple
.getEnvironment() != llvm::Triple::UnknownEnvironment
)
677 return std::make_unique
<SPIR64TargetInfo
>(Triple
, Opts
);
679 case llvm::Triple::spirv32
: {
680 if (os
!= llvm::Triple::UnknownOS
||
681 Triple
.getEnvironment() != llvm::Triple::UnknownEnvironment
)
683 return std::make_unique
<SPIRV32TargetInfo
>(Triple
, Opts
);
685 case llvm::Triple::spirv64
: {
686 if (os
!= llvm::Triple::UnknownOS
||
687 Triple
.getEnvironment() != llvm::Triple::UnknownEnvironment
)
689 return std::make_unique
<SPIRV64TargetInfo
>(Triple
, Opts
);
691 case llvm::Triple::wasm32
:
692 if (Triple
.getSubArch() != llvm::Triple::NoSubArch
||
693 Triple
.getVendor() != llvm::Triple::UnknownVendor
||
694 !Triple
.isOSBinFormatWasm())
697 case llvm::Triple::WASI
:
698 return std::make_unique
<WASITargetInfo
<WebAssembly32TargetInfo
>>(Triple
,
700 case llvm::Triple::Emscripten
:
701 return std::make_unique
<EmscriptenTargetInfo
<WebAssembly32TargetInfo
>>(
703 case llvm::Triple::UnknownOS
:
704 return std::make_unique
<WebAssemblyOSTargetInfo
<WebAssembly32TargetInfo
>>(
709 case llvm::Triple::wasm64
:
710 if (Triple
.getSubArch() != llvm::Triple::NoSubArch
||
711 Triple
.getVendor() != llvm::Triple::UnknownVendor
||
712 !Triple
.isOSBinFormatWasm())
715 case llvm::Triple::WASI
:
716 return std::make_unique
<WASITargetInfo
<WebAssembly64TargetInfo
>>(Triple
,
718 case llvm::Triple::Emscripten
:
719 return std::make_unique
<EmscriptenTargetInfo
<WebAssembly64TargetInfo
>>(
721 case llvm::Triple::UnknownOS
:
722 return std::make_unique
<WebAssemblyOSTargetInfo
<WebAssembly64TargetInfo
>>(
728 case llvm::Triple::dxil
:
729 return std::make_unique
<DirectXTargetInfo
>(Triple
, Opts
);
730 case llvm::Triple::renderscript32
:
731 return std::make_unique
<LinuxTargetInfo
<RenderScript32TargetInfo
>>(Triple
,
733 case llvm::Triple::renderscript64
:
734 return std::make_unique
<LinuxTargetInfo
<RenderScript64TargetInfo
>>(Triple
,
737 case llvm::Triple::ve
:
738 return std::make_unique
<LinuxTargetInfo
<VETargetInfo
>>(Triple
, Opts
);
740 case llvm::Triple::csky
:
742 case llvm::Triple::Linux
:
743 return std::make_unique
<LinuxTargetInfo
<CSKYTargetInfo
>>(Triple
, Opts
);
745 return std::make_unique
<CSKYTargetInfo
>(Triple
, Opts
);
747 case llvm::Triple::loongarch32
:
749 case llvm::Triple::Linux
:
750 return std::make_unique
<LinuxTargetInfo
<LoongArch32TargetInfo
>>(Triple
,
753 return std::make_unique
<LoongArch32TargetInfo
>(Triple
, Opts
);
755 case llvm::Triple::loongarch64
:
757 case llvm::Triple::Linux
:
758 return std::make_unique
<LinuxTargetInfo
<LoongArch64TargetInfo
>>(Triple
,
761 return std::make_unique
<LoongArch64TargetInfo
>(Triple
, Opts
);
765 } // namespace targets
768 using namespace clang::targets
;
769 /// CreateTargetInfo - Return the target info object for the specified target
772 TargetInfo::CreateTargetInfo(DiagnosticsEngine
&Diags
,
773 const std::shared_ptr
<TargetOptions
> &Opts
) {
774 llvm::Triple
Triple(Opts
->Triple
);
776 // Construct the target
777 std::unique_ptr
<TargetInfo
> Target
= AllocateTarget(Triple
, *Opts
);
779 Diags
.Report(diag::err_target_unknown_triple
) << Triple
.str();
782 Target
->TargetOpts
= Opts
;
784 // Set the target CPU if specified.
785 if (!Opts
->CPU
.empty() && !Target
->setCPU(Opts
->CPU
)) {
786 Diags
.Report(diag::err_target_unknown_cpu
) << Opts
->CPU
;
787 SmallVector
<StringRef
, 32> ValidList
;
788 Target
->fillValidCPUList(ValidList
);
789 if (!ValidList
.empty())
790 Diags
.Report(diag::note_valid_options
) << llvm::join(ValidList
, ", ");
794 // Check the TuneCPU name if specified.
795 if (!Opts
->TuneCPU
.empty() &&
796 !Target
->isValidTuneCPUName(Opts
->TuneCPU
)) {
797 Diags
.Report(diag::err_target_unknown_cpu
) << Opts
->TuneCPU
;
798 SmallVector
<StringRef
, 32> ValidList
;
799 Target
->fillValidTuneCPUList(ValidList
);
800 if (!ValidList
.empty())
801 Diags
.Report(diag::note_valid_options
) << llvm::join(ValidList
, ", ");
805 // Set the target ABI if specified.
806 if (!Opts
->ABI
.empty() && !Target
->setABI(Opts
->ABI
)) {
807 Diags
.Report(diag::err_target_unknown_abi
) << Opts
->ABI
;
811 // Set the fp math unit.
812 if (!Opts
->FPMath
.empty() && !Target
->setFPMath(Opts
->FPMath
)) {
813 Diags
.Report(diag::err_target_unknown_fpmath
) << Opts
->FPMath
;
817 // Compute the default target features, we need the target to handle this
818 // because features may have dependencies on one another.
819 if (!Target
->initFeatureMap(Opts
->FeatureMap
, Diags
, Opts
->CPU
,
820 Opts
->FeaturesAsWritten
))
823 // Add the features to the compile options.
824 Opts
->Features
.clear();
825 for (const auto &F
: Opts
->FeatureMap
)
826 Opts
->Features
.push_back((F
.getValue() ? "+" : "-") + F
.getKey().str());
827 // Sort here, so we handle the features in a predictable order. (This matters
828 // when we're dealing with features that overlap.)
829 llvm::sort(Opts
->Features
);
831 if (!Target
->handleTargetFeatures(Opts
->Features
, Diags
))
834 Target
->setSupportedOpenCLOpts();
835 Target
->setCommandLineOpenCLOpts();
836 Target
->setMaxAtomicWidth();
838 if (!Opts
->DarwinTargetVariantTriple
.empty())
839 Target
->DarwinTargetVariantTriple
=
840 llvm::Triple(Opts
->DarwinTargetVariantTriple
);
842 if (!Target
->validateTarget(Diags
))
845 Target
->CheckFixedPointBits();
847 return Target
.release();
849 /// validateOpenCLTarget - Check that OpenCL target has valid
850 /// options setting based on OpenCL version.
851 bool TargetInfo::validateOpenCLTarget(const LangOptions
&Opts
,
852 DiagnosticsEngine
&Diags
) const {
853 const llvm::StringMap
<bool> &OpenCLFeaturesMap
= getSupportedOpenCLOpts();
855 auto diagnoseNotSupportedCore
= [&](llvm::StringRef Name
, auto... OptArgs
) {
856 if (OpenCLOptions::isOpenCLOptionCoreIn(Opts
, OptArgs
...) &&
857 !hasFeatureEnabled(OpenCLFeaturesMap
, Name
))
858 Diags
.Report(diag::warn_opencl_unsupported_core_feature
)
859 << Name
<< Opts
.OpenCLCPlusPlus
860 << Opts
.getOpenCLVersionTuple().getAsString();
862 #define OPENCL_GENERIC_EXTENSION(Ext, ...) \
863 diagnoseNotSupportedCore(#Ext, __VA_ARGS__);
864 #include "clang/Basic/OpenCLExtensions.def"
866 // Validate that feature macros are set properly for OpenCL C 3.0.
867 // In other cases assume that target is always valid.
868 if (Opts
.getOpenCLCompatibleVersion() < 300)
871 return OpenCLOptions::diagnoseUnsupportedFeatureDependencies(*this, Diags
) &&
872 OpenCLOptions::diagnoseFeatureExtensionDifferences(*this, Diags
);