[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / lib / Basic / Targets / OSTargets.h
blob445718ea66b6896d195baf2095668b25b1734906
1 //===--- OSTargets.h - Declare OS target feature support --------*- C++ -*-===//
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 declares OS specific TargetInfo types.
10 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
13 #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
15 #include "Targets.h"
17 namespace clang {
18 namespace targets {
20 template <typename TgtInfo>
21 class LLVM_LIBRARY_VISIBILITY OSTargetInfo : public TgtInfo {
22 protected:
23 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
24 MacroBuilder &Builder) const = 0;
26 public:
27 OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
28 : TgtInfo(Triple, Opts) {}
30 void getTargetDefines(const LangOptions &Opts,
31 MacroBuilder &Builder) const override {
32 TgtInfo::getTargetDefines(Opts, Builder);
33 getOSDefines(Opts, TgtInfo::getTriple(), Builder);
37 // CloudABI Target
38 template <typename Target>
39 class LLVM_LIBRARY_VISIBILITY CloudABITargetInfo : public OSTargetInfo<Target> {
40 protected:
41 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
42 MacroBuilder &Builder) const override {
43 Builder.defineMacro("__CloudABI__");
45 // CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
46 Builder.defineMacro("__STDC_ISO_10646__", "201206L");
49 public:
50 using OSTargetInfo<Target>::OSTargetInfo;
53 // Ananas target
54 template <typename Target>
55 class LLVM_LIBRARY_VISIBILITY AnanasTargetInfo : public OSTargetInfo<Target> {
56 protected:
57 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
58 MacroBuilder &Builder) const override {
59 // Ananas defines
60 Builder.defineMacro("__Ananas__");
63 public:
64 using OSTargetInfo<Target>::OSTargetInfo;
67 void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
68 const llvm::Triple &Triple, StringRef &PlatformName,
69 VersionTuple &PlatformMinVersion);
71 template <typename Target>
72 class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public OSTargetInfo<Target> {
73 protected:
74 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
75 MacroBuilder &Builder) const override {
76 getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
77 this->PlatformMinVersion);
80 public:
81 DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
82 : OSTargetInfo<Target>(Triple, Opts) {
83 // By default, no TLS, and we list permitted architecture/OS
84 // combinations.
85 this->TLSSupported = false;
87 if (Triple.isMacOSX())
88 this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7);
89 else if (Triple.isiOS()) {
90 // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
91 // 32-bit simulator from 10 onwards.
92 if (Triple.isArch64Bit())
93 this->TLSSupported = !Triple.isOSVersionLT(8);
94 else if (Triple.isArch32Bit()) {
95 if (!Triple.isSimulatorEnvironment())
96 this->TLSSupported = !Triple.isOSVersionLT(9);
97 else
98 this->TLSSupported = !Triple.isOSVersionLT(10);
100 } else if (Triple.isWatchOS()) {
101 if (!Triple.isSimulatorEnvironment())
102 this->TLSSupported = !Triple.isOSVersionLT(2);
103 else
104 this->TLSSupported = !Triple.isOSVersionLT(3);
105 } else if (Triple.isDriverKit()) {
106 // No TLS on DriverKit.
109 this->MCountName = "\01mcount";
112 const char *getStaticInitSectionSpecifier() const override {
113 // FIXME: We should return 0 when building kexts.
114 return "__TEXT,__StaticInit,regular,pure_instructions";
117 /// Darwin does not support protected visibility. Darwin's "default"
118 /// is very similar to ELF's "protected"; Darwin requires a "weak"
119 /// attribute on declarations that can be dynamically replaced.
120 bool hasProtectedVisibility() const override { return false; }
122 unsigned getExnObjectAlignment() const override {
123 // Older versions of libc++abi guarantee an alignment of only 8-bytes for
124 // exception objects because of a bug in __cxa_exception that was
125 // eventually fixed in r319123.
126 llvm::VersionTuple MinVersion;
127 const llvm::Triple &T = this->getTriple();
129 // Compute the earliest OS versions that have the fix to libc++abi.
130 switch (T.getOS()) {
131 case llvm::Triple::Darwin:
132 case llvm::Triple::MacOSX: // Earliest supporting version is 10.14.
133 MinVersion = llvm::VersionTuple(10U, 14U);
134 break;
135 case llvm::Triple::IOS:
136 case llvm::Triple::TvOS: // Earliest supporting version is 12.0.0.
137 MinVersion = llvm::VersionTuple(12U);
138 break;
139 case llvm::Triple::WatchOS: // Earliest supporting version is 5.0.0.
140 MinVersion = llvm::VersionTuple(5U);
141 break;
142 default:
143 // Conservatively return 8 bytes if OS is unknown.
144 return 64;
147 if (T.getOSVersion() < MinVersion)
148 return 64;
149 return OSTargetInfo<Target>::getExnObjectAlignment();
152 TargetInfo::IntType getLeastIntTypeByWidth(unsigned BitWidth,
153 bool IsSigned) const final {
154 // Darwin uses `long long` for `int_least64_t` and `int_fast64_t`.
155 return BitWidth == 64
156 ? (IsSigned ? TargetInfo::SignedLongLong
157 : TargetInfo::UnsignedLongLong)
158 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
161 bool areDefaultedSMFStillPOD(const LangOptions &) const override {
162 return false;
166 // DragonFlyBSD Target
167 template <typename Target>
168 class LLVM_LIBRARY_VISIBILITY DragonFlyBSDTargetInfo
169 : public OSTargetInfo<Target> {
170 protected:
171 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
172 MacroBuilder &Builder) const override {
173 // DragonFly defines; list based off of gcc output
174 Builder.defineMacro("__DragonFly__");
175 Builder.defineMacro("__DragonFly_cc_version", "100001");
176 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
177 Builder.defineMacro("__tune_i386__");
178 DefineStd(Builder, "unix", Opts);
179 if (this->HasFloat128)
180 Builder.defineMacro("__FLOAT128__");
183 public:
184 DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
185 : OSTargetInfo<Target>(Triple, Opts) {
186 switch (Triple.getArch()) {
187 default:
188 case llvm::Triple::x86:
189 case llvm::Triple::x86_64:
190 this->HasFloat128 = true;
191 this->MCountName = ".mcount";
192 break;
197 #ifndef FREEBSD_CC_VERSION
198 #define FREEBSD_CC_VERSION 0U
199 #endif
201 // FreeBSD Target
202 template <typename Target>
203 class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo<Target> {
204 protected:
205 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
206 MacroBuilder &Builder) const override {
207 // FreeBSD defines; list based off of gcc output
209 unsigned Release = Triple.getOSMajorVersion();
210 if (Release == 0U)
211 Release = 8U;
212 unsigned CCVersion = FREEBSD_CC_VERSION;
213 if (CCVersion == 0U)
214 CCVersion = Release * 100000U + 1U;
216 Builder.defineMacro("__FreeBSD__", Twine(Release));
217 Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
218 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
219 DefineStd(Builder, "unix", Opts);
221 // On FreeBSD, wchar_t contains the number of the code point as
222 // used by the character set of the locale. These character sets are
223 // not necessarily a superset of ASCII.
225 // FIXME: This is wrong; the macro refers to the numerical values
226 // of wchar_t *literals*, which are not locale-dependent. However,
227 // FreeBSD systems apparently depend on us getting this wrong, and
228 // setting this to 1 is conforming even if all the basic source
229 // character literals have the same encoding as char and wchar_t.
230 Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
233 public:
234 FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
235 : OSTargetInfo<Target>(Triple, Opts) {
236 switch (Triple.getArch()) {
237 default:
238 case llvm::Triple::x86:
239 case llvm::Triple::x86_64:
240 this->MCountName = ".mcount";
241 break;
242 case llvm::Triple::mips:
243 case llvm::Triple::mipsel:
244 case llvm::Triple::ppc:
245 case llvm::Triple::ppcle:
246 case llvm::Triple::ppc64:
247 case llvm::Triple::ppc64le:
248 this->MCountName = "_mcount";
249 break;
250 case llvm::Triple::arm:
251 this->MCountName = "__mcount";
252 break;
253 case llvm::Triple::riscv32:
254 case llvm::Triple::riscv64:
255 break;
260 // GNU/kFreeBSD Target
261 template <typename Target>
262 class LLVM_LIBRARY_VISIBILITY KFreeBSDTargetInfo : public OSTargetInfo<Target> {
263 protected:
264 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
265 MacroBuilder &Builder) const override {
266 // GNU/kFreeBSD defines; list based off of gcc output
268 DefineStd(Builder, "unix", Opts);
269 Builder.defineMacro("__FreeBSD_kernel__");
270 Builder.defineMacro("__GLIBC__");
271 if (Opts.POSIXThreads)
272 Builder.defineMacro("_REENTRANT");
273 if (Opts.CPlusPlus)
274 Builder.defineMacro("_GNU_SOURCE");
277 public:
278 using OSTargetInfo<Target>::OSTargetInfo;
281 // Haiku Target
282 template <typename Target>
283 class LLVM_LIBRARY_VISIBILITY HaikuTargetInfo : public OSTargetInfo<Target> {
284 protected:
285 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
286 MacroBuilder &Builder) const override {
287 // Haiku defines; list based off of gcc output
288 Builder.defineMacro("__HAIKU__");
289 DefineStd(Builder, "unix", Opts);
290 if (this->HasFloat128)
291 Builder.defineMacro("__FLOAT128__");
294 public:
295 HaikuTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
296 : OSTargetInfo<Target>(Triple, Opts) {
297 this->SizeType = TargetInfo::UnsignedLong;
298 this->IntPtrType = TargetInfo::SignedLong;
299 this->PtrDiffType = TargetInfo::SignedLong;
300 this->ProcessIDType = TargetInfo::SignedLong;
301 this->TLSSupported = false;
302 switch (Triple.getArch()) {
303 default:
304 break;
305 case llvm::Triple::x86:
306 case llvm::Triple::x86_64:
307 this->HasFloat128 = true;
308 break;
313 // Hurd target
314 template <typename Target>
315 class LLVM_LIBRARY_VISIBILITY HurdTargetInfo : public OSTargetInfo<Target> {
316 protected:
317 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
318 MacroBuilder &Builder) const override {
319 // Hurd defines; list based off of gcc output.
320 DefineStd(Builder, "unix", Opts);
321 Builder.defineMacro("__GNU__");
322 Builder.defineMacro("__gnu_hurd__");
323 Builder.defineMacro("__MACH__");
324 Builder.defineMacro("__GLIBC__");
325 if (Opts.POSIXThreads)
326 Builder.defineMacro("_REENTRANT");
327 if (Opts.CPlusPlus)
328 Builder.defineMacro("_GNU_SOURCE");
330 public:
331 using OSTargetInfo<Target>::OSTargetInfo;
334 // Minix Target
335 template <typename Target>
336 class LLVM_LIBRARY_VISIBILITY MinixTargetInfo : public OSTargetInfo<Target> {
337 protected:
338 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
339 MacroBuilder &Builder) const override {
340 // Minix defines
342 Builder.defineMacro("__minix", "3");
343 Builder.defineMacro("_EM_WSIZE", "4");
344 Builder.defineMacro("_EM_PSIZE", "4");
345 Builder.defineMacro("_EM_SSIZE", "2");
346 Builder.defineMacro("_EM_LSIZE", "4");
347 Builder.defineMacro("_EM_FSIZE", "4");
348 Builder.defineMacro("_EM_DSIZE", "8");
349 DefineStd(Builder, "unix", Opts);
352 public:
353 using OSTargetInfo<Target>::OSTargetInfo;
356 // Linux target
357 template <typename Target>
358 class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public OSTargetInfo<Target> {
359 protected:
360 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
361 MacroBuilder &Builder) const override {
362 // Linux defines; list based off of gcc output
363 DefineStd(Builder, "unix", Opts);
364 DefineStd(Builder, "linux", Opts);
365 if (Triple.isAndroid()) {
366 Builder.defineMacro("__ANDROID__", "1");
367 this->PlatformName = "android";
368 this->PlatformMinVersion = Triple.getEnvironmentVersion();
369 const unsigned Maj = this->PlatformMinVersion.getMajor();
370 if (Maj) {
371 Builder.defineMacro("__ANDROID_MIN_SDK_VERSION__", Twine(Maj));
372 // This historical but ambiguous name for the minSdkVersion macro. Keep
373 // defined for compatibility.
374 Builder.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
376 } else {
377 Builder.defineMacro("__gnu_linux__");
379 if (Opts.POSIXThreads)
380 Builder.defineMacro("_REENTRANT");
381 if (Opts.CPlusPlus)
382 Builder.defineMacro("_GNU_SOURCE");
383 if (this->HasFloat128)
384 Builder.defineMacro("__FLOAT128__");
387 public:
388 LinuxTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
389 : OSTargetInfo<Target>(Triple, Opts) {
390 this->WIntType = TargetInfo::UnsignedInt;
392 switch (Triple.getArch()) {
393 default:
394 break;
395 case llvm::Triple::mips:
396 case llvm::Triple::mipsel:
397 case llvm::Triple::mips64:
398 case llvm::Triple::mips64el:
399 case llvm::Triple::ppc:
400 case llvm::Triple::ppcle:
401 case llvm::Triple::ppc64:
402 case llvm::Triple::ppc64le:
403 this->MCountName = "_mcount";
404 break;
405 case llvm::Triple::x86:
406 case llvm::Triple::x86_64:
407 this->HasFloat128 = true;
408 break;
412 const char *getStaticInitSectionSpecifier() const override {
413 return ".text.startup";
417 // NetBSD Target
418 template <typename Target>
419 class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public OSTargetInfo<Target> {
420 protected:
421 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
422 MacroBuilder &Builder) const override {
423 // NetBSD defines; list based off of gcc output
424 Builder.defineMacro("__NetBSD__");
425 Builder.defineMacro("__unix__");
426 if (Opts.POSIXThreads)
427 Builder.defineMacro("_REENTRANT");
430 public:
431 NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
432 : OSTargetInfo<Target>(Triple, Opts) {
433 this->MCountName = "__mcount";
437 // OpenBSD Target
438 template <typename Target>
439 class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
440 protected:
441 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
442 MacroBuilder &Builder) const override {
443 // OpenBSD defines; list based off of gcc output
445 Builder.defineMacro("__OpenBSD__");
446 DefineStd(Builder, "unix", Opts);
447 if (Opts.POSIXThreads)
448 Builder.defineMacro("_REENTRANT");
449 if (this->HasFloat128)
450 Builder.defineMacro("__FLOAT128__");
452 if (Opts.C11)
453 Builder.defineMacro("__STDC_NO_THREADS__");
456 public:
457 OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
458 : OSTargetInfo<Target>(Triple, Opts) {
459 this->WCharType = this->WIntType = this->SignedInt;
460 this->IntMaxType = TargetInfo::SignedLongLong;
461 this->Int64Type = TargetInfo::SignedLongLong;
462 switch (Triple.getArch()) {
463 case llvm::Triple::x86:
464 case llvm::Triple::x86_64:
465 this->HasFloat128 = true;
466 [[fallthrough]];
467 default:
468 this->MCountName = "__mcount";
469 break;
470 case llvm::Triple::mips64:
471 case llvm::Triple::mips64el:
472 case llvm::Triple::ppc:
473 case llvm::Triple::ppc64:
474 case llvm::Triple::ppc64le:
475 case llvm::Triple::sparcv9:
476 this->MCountName = "_mcount";
477 break;
478 case llvm::Triple::riscv32:
479 case llvm::Triple::riscv64:
480 break;
485 // PS3 PPU Target
486 template <typename Target>
487 class LLVM_LIBRARY_VISIBILITY PS3PPUTargetInfo : public OSTargetInfo<Target> {
488 protected:
489 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
490 MacroBuilder &Builder) const override {
491 // PS3 PPU defines.
492 Builder.defineMacro("__PPU__");
493 Builder.defineMacro("__CELLOS_LV2__");
494 Builder.defineMacro("__LP32__");
495 Builder.defineMacro("_ARCH_PPC64");
496 Builder.defineMacro("__powerpc64__");
499 public:
500 PS3PPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
501 : OSTargetInfo<Target>(Triple, Opts) {
502 this->LongWidth = this->LongAlign = 32;
503 this->PointerWidth = this->PointerAlign = 32;
504 this->IntMaxType = TargetInfo::SignedLongLong;
505 this->Int64Type = TargetInfo::SignedLongLong;
506 this->SizeType = TargetInfo::UnsignedInt;
507 this->resetDataLayout("E-m:e-p:32:32-Fi64-i64:64-n32:64");
511 // Common base class for PS4/PS5 targets.
512 template <typename Target>
513 class LLVM_LIBRARY_VISIBILITY PSOSTargetInfo : public OSTargetInfo<Target> {
514 protected:
515 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
516 MacroBuilder &Builder) const override {
517 Builder.defineMacro("__FreeBSD__", "9");
518 Builder.defineMacro("__FreeBSD_cc_version", "900001");
519 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
520 DefineStd(Builder, "unix", Opts);
521 Builder.defineMacro("__SCE__");
522 Builder.defineMacro("__STDC_NO_COMPLEX__");
523 Builder.defineMacro("__STDC_NO_THREADS__");
526 public:
527 PSOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
528 : OSTargetInfo<Target>(Triple, Opts) {
529 this->WCharType = TargetInfo::UnsignedShort;
531 // On PS4/PS5, TLS variable cannot be aligned to more than 32 bytes (256
532 // bits).
533 this->MaxTLSAlign = 256;
535 // On PS4/PS5, do not honor explicit bit field alignment,
536 // as in "__attribute__((aligned(2))) int b : 1;".
537 this->UseExplicitBitFieldAlignment = false;
539 this->MCountName = ".mcount";
540 this->NewAlign = 256;
541 this->SuitableAlign = 256;
544 TargetInfo::CallingConvCheckResult
545 checkCallingConvention(CallingConv CC) const override {
546 return (CC == CC_C) ? TargetInfo::CCCR_OK : TargetInfo::CCCR_Error;
549 bool areDefaultedSMFStillPOD(const LangOptions &) const override {
550 return false;
554 // PS4 Target
555 template <typename Target>
556 class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public PSOSTargetInfo<Target> {
557 protected:
558 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
559 MacroBuilder &Builder) const override {
560 // Start with base class defines.
561 PSOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
563 Builder.defineMacro("__ORBIS__");
566 public:
567 using PSOSTargetInfo<Target>::PSOSTargetInfo;
570 // PS5 Target
571 template <typename Target>
572 class LLVM_LIBRARY_VISIBILITY PS5OSTargetInfo : public PSOSTargetInfo<Target> {
573 protected:
574 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
575 MacroBuilder &Builder) const override {
576 // Start with base class defines.
577 PSOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
579 Builder.defineMacro("__PROSPERO__");
582 public:
583 using PSOSTargetInfo<Target>::PSOSTargetInfo;
586 // RTEMS Target
587 template <typename Target>
588 class LLVM_LIBRARY_VISIBILITY RTEMSTargetInfo : public OSTargetInfo<Target> {
589 protected:
590 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
591 MacroBuilder &Builder) const override {
592 // RTEMS defines; list based off of gcc output
594 Builder.defineMacro("__rtems__");
595 if (Opts.CPlusPlus)
596 Builder.defineMacro("_GNU_SOURCE");
599 public:
600 RTEMSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
601 : OSTargetInfo<Target>(Triple, Opts) {
602 switch (Triple.getArch()) {
603 default:
604 case llvm::Triple::x86:
605 // this->MCountName = ".mcount";
606 break;
607 case llvm::Triple::mips:
608 case llvm::Triple::mipsel:
609 case llvm::Triple::ppc:
610 case llvm::Triple::ppc64:
611 case llvm::Triple::ppc64le:
612 // this->MCountName = "_mcount";
613 break;
614 case llvm::Triple::arm:
615 // this->MCountName = "__mcount";
616 break;
621 // Solaris target
622 template <typename Target>
623 class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo : public OSTargetInfo<Target> {
624 protected:
625 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
626 MacroBuilder &Builder) const override {
627 DefineStd(Builder, "sun", Opts);
628 DefineStd(Builder, "unix", Opts);
629 Builder.defineMacro("__svr4__");
630 Builder.defineMacro("__SVR4");
631 // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
632 // newer, but to 500 for everything else. feature_test.h has a check to
633 // ensure that you are not using C99 with an old version of X/Open or C89
634 // with a new version.
635 if (Opts.C99)
636 Builder.defineMacro("_XOPEN_SOURCE", "600");
637 else
638 Builder.defineMacro("_XOPEN_SOURCE", "500");
639 if (Opts.CPlusPlus) {
640 Builder.defineMacro("__C99FEATURES__");
641 Builder.defineMacro("_FILE_OFFSET_BITS", "64");
643 // GCC restricts the next two to C++.
644 Builder.defineMacro("_LARGEFILE_SOURCE");
645 Builder.defineMacro("_LARGEFILE64_SOURCE");
646 Builder.defineMacro("__EXTENSIONS__");
647 if (Opts.POSIXThreads)
648 Builder.defineMacro("_REENTRANT");
649 if (this->HasFloat128)
650 Builder.defineMacro("__FLOAT128__");
653 public:
654 SolarisTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
655 : OSTargetInfo<Target>(Triple, Opts) {
656 if (this->PointerWidth == 64) {
657 this->WCharType = this->WIntType = this->SignedInt;
658 } else {
659 this->WCharType = this->WIntType = this->SignedLong;
661 switch (Triple.getArch()) {
662 default:
663 break;
664 case llvm::Triple::x86:
665 case llvm::Triple::x86_64:
666 this->HasFloat128 = true;
667 break;
672 // AIX Target
673 template <typename Target>
674 class AIXTargetInfo : public OSTargetInfo<Target> {
675 protected:
676 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
677 MacroBuilder &Builder) const override {
678 DefineStd(Builder, "unix", Opts);
679 Builder.defineMacro("_IBMR2");
680 Builder.defineMacro("_POWER");
681 Builder.defineMacro("__THW_BIG_ENDIAN__");
683 Builder.defineMacro("_AIX");
684 Builder.defineMacro("__TOS_AIX__");
685 Builder.defineMacro("__HOS_AIX__");
687 if (Opts.C11) {
688 Builder.defineMacro("__STDC_NO_ATOMICS__");
689 Builder.defineMacro("__STDC_NO_THREADS__");
692 if (Opts.EnableAIXExtendedAltivecABI)
693 Builder.defineMacro("__EXTABI__");
695 VersionTuple OsVersion = Triple.getOSVersion();
697 // Define AIX OS-Version Macros.
698 // Includes logic for legacy versions of AIX; no specific intent to support.
699 if (OsVersion >= VersionTuple(3, 2))
700 Builder.defineMacro("_AIX32");
701 if (OsVersion >= VersionTuple(4, 1))
702 Builder.defineMacro("_AIX41");
703 if (OsVersion >= VersionTuple(4, 3))
704 Builder.defineMacro("_AIX43");
705 if (OsVersion >= VersionTuple(5, 0))
706 Builder.defineMacro("_AIX50");
707 if (OsVersion >= VersionTuple(5, 1))
708 Builder.defineMacro("_AIX51");
709 if (OsVersion >= VersionTuple(5, 2))
710 Builder.defineMacro("_AIX52");
711 if (OsVersion >= VersionTuple(5, 3))
712 Builder.defineMacro("_AIX53");
713 if (OsVersion >= VersionTuple(6, 1))
714 Builder.defineMacro("_AIX61");
715 if (OsVersion >= VersionTuple(7, 1))
716 Builder.defineMacro("_AIX71");
717 if (OsVersion >= VersionTuple(7, 2))
718 Builder.defineMacro("_AIX72");
719 if (OsVersion >= VersionTuple(7, 3))
720 Builder.defineMacro("_AIX73");
722 // FIXME: Do not define _LONG_LONG when -fno-long-long is specified.
723 Builder.defineMacro("_LONG_LONG");
725 if (Opts.POSIXThreads) {
726 Builder.defineMacro("_THREAD_SAFE");
729 if (this->PointerWidth == 64) {
730 Builder.defineMacro("__64BIT__");
733 // Define _WCHAR_T when it is a fundamental type
734 // (i.e., for C++ without -fno-wchar).
735 if (Opts.CPlusPlus && Opts.WChar) {
736 Builder.defineMacro("_WCHAR_T");
740 public:
741 AIXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
742 : OSTargetInfo<Target>(Triple, Opts) {
743 this->MCountName = "__mcount";
744 this->TheCXXABI.set(TargetCXXABI::XL);
746 if (this->PointerWidth == 64) {
747 this->WCharType = this->UnsignedInt;
748 } else {
749 this->WCharType = this->UnsignedShort;
751 this->UseZeroLengthBitfieldAlignment = true;
754 // AIX sets FLT_EVAL_METHOD to be 1.
755 LangOptions::FPEvalMethodKind getFPEvalMethod() const override {
756 return LangOptions::FPEvalMethodKind::FEM_Double;
759 bool defaultsToAIXPowerAlignment() const override { return true; }
761 bool areDefaultedSMFStillPOD(const LangOptions &) const override {
762 return false;
766 // z/OS target
767 template <typename Target>
768 class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo<Target> {
769 protected:
770 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
771 MacroBuilder &Builder) const override {
772 // FIXME: _LONG_LONG should not be defined under -std=c89.
773 Builder.defineMacro("_LONG_LONG");
774 Builder.defineMacro("_OPEN_DEFAULT");
775 // _UNIX03_WITHDRAWN is required to build libcxx.
776 Builder.defineMacro("_UNIX03_WITHDRAWN");
777 Builder.defineMacro("__370__");
778 Builder.defineMacro("__BFP__");
779 // FIXME: __BOOL__ should not be defined under -std=c89.
780 Builder.defineMacro("__BOOL__");
781 Builder.defineMacro("__LONGNAME__");
782 Builder.defineMacro("__MVS__");
783 Builder.defineMacro("__THW_370__");
784 Builder.defineMacro("__THW_BIG_ENDIAN__");
785 Builder.defineMacro("__TOS_390__");
786 Builder.defineMacro("__TOS_MVS__");
787 Builder.defineMacro("__XPLINK__");
789 if (this->PointerWidth == 64)
790 Builder.defineMacro("__64BIT__");
792 if (Opts.CPlusPlus) {
793 Builder.defineMacro("__DLL__");
794 // _XOPEN_SOURCE=600 is required to build libcxx.
795 Builder.defineMacro("_XOPEN_SOURCE", "600");
798 if (Opts.GNUMode) {
799 Builder.defineMacro("_MI_BUILTIN");
800 Builder.defineMacro("_EXT");
803 if (Opts.CPlusPlus && Opts.WChar) {
804 // Macro __wchar_t is defined so that the wchar_t data
805 // type is not declared as a typedef in system headers.
806 Builder.defineMacro("__wchar_t");
809 this->PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
812 public:
813 ZOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
814 : OSTargetInfo<Target>(Triple, Opts) {
815 this->WCharType = TargetInfo::UnsignedInt;
816 this->MaxAlignedAttribute = 128;
817 this->UseBitFieldTypeAlignment = false;
818 this->UseZeroLengthBitfieldAlignment = true;
819 this->UseLeadingZeroLengthBitfield = false;
820 this->ZeroLengthBitfieldBoundary = 32;
823 bool areDefaultedSMFStillPOD(const LangOptions &) const override {
824 return false;
828 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
829 MacroBuilder &Builder);
831 // Windows target
832 template <typename Target>
833 class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
834 protected:
835 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
836 MacroBuilder &Builder) const override {
837 addWindowsDefines(Triple, Opts, Builder);
840 public:
841 WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
842 : OSTargetInfo<Target>(Triple, Opts) {
843 this->WCharType = TargetInfo::UnsignedShort;
844 this->WIntType = TargetInfo::UnsignedShort;
848 template <typename Target>
849 class LLVM_LIBRARY_VISIBILITY NaClTargetInfo : public OSTargetInfo<Target> {
850 protected:
851 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
852 MacroBuilder &Builder) const override {
853 if (Opts.POSIXThreads)
854 Builder.defineMacro("_REENTRANT");
855 if (Opts.CPlusPlus)
856 Builder.defineMacro("_GNU_SOURCE");
858 DefineStd(Builder, "unix", Opts);
859 Builder.defineMacro("__native_client__");
862 public:
863 NaClTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
864 : OSTargetInfo<Target>(Triple, Opts) {
865 this->LongAlign = 32;
866 this->LongWidth = 32;
867 this->PointerAlign = 32;
868 this->PointerWidth = 32;
869 this->IntMaxType = TargetInfo::SignedLongLong;
870 this->Int64Type = TargetInfo::SignedLongLong;
871 this->DoubleAlign = 64;
872 this->LongDoubleWidth = 64;
873 this->LongDoubleAlign = 64;
874 this->LongLongWidth = 64;
875 this->LongLongAlign = 64;
876 this->SizeType = TargetInfo::UnsignedInt;
877 this->PtrDiffType = TargetInfo::SignedInt;
878 this->IntPtrType = TargetInfo::SignedInt;
879 // RegParmMax is inherited from the underlying architecture.
880 this->LongDoubleFormat = &llvm::APFloat::IEEEdouble();
881 if (Triple.getArch() == llvm::Triple::arm) {
882 // Handled in ARM's setABI().
883 } else if (Triple.getArch() == llvm::Triple::x86) {
884 this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
885 "i64:64-n8:16:32-S128");
886 } else if (Triple.getArch() == llvm::Triple::x86_64) {
887 this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
888 "i64:64-n8:16:32:64-S128");
889 } else if (Triple.getArch() == llvm::Triple::mipsel) {
890 // Handled on mips' setDataLayout.
891 } else {
892 assert(Triple.getArch() == llvm::Triple::le32);
893 this->resetDataLayout("e-p:32:32-i64:64");
898 // Fuchsia Target
899 template <typename Target>
900 class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo : public OSTargetInfo<Target> {
901 protected:
902 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
903 MacroBuilder &Builder) const override {
904 Builder.defineMacro("__Fuchsia__");
905 if (Opts.POSIXThreads)
906 Builder.defineMacro("_REENTRANT");
907 // Required by the libc++ locale support.
908 if (Opts.CPlusPlus)
909 Builder.defineMacro("_GNU_SOURCE");
910 Builder.defineMacro("__Fuchsia_API_level__", Twine(Opts.FuchsiaAPILevel));
911 this->PlatformName = "fuchsia";
912 this->PlatformMinVersion = VersionTuple(Opts.FuchsiaAPILevel);
915 public:
916 FuchsiaTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
917 : OSTargetInfo<Target>(Triple, Opts) {
918 this->MCountName = "__mcount";
919 this->TheCXXABI.set(TargetCXXABI::Fuchsia);
923 // WebAssembly target
924 template <typename Target>
925 class LLVM_LIBRARY_VISIBILITY WebAssemblyOSTargetInfo
926 : public OSTargetInfo<Target> {
927 protected:
928 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
929 MacroBuilder &Builder) const override {
930 // A common platform macro.
931 if (Opts.POSIXThreads)
932 Builder.defineMacro("_REENTRANT");
933 // Follow g++ convention and predefine _GNU_SOURCE for C++.
934 if (Opts.CPlusPlus)
935 Builder.defineMacro("_GNU_SOURCE");
936 // Indicate that we have __float128.
937 Builder.defineMacro("__FLOAT128__");
940 public:
941 explicit WebAssemblyOSTargetInfo(const llvm::Triple &Triple,
942 const TargetOptions &Opts)
943 : OSTargetInfo<Target>(Triple, Opts) {
944 this->MCountName = "__mcount";
945 this->TheCXXABI.set(TargetCXXABI::WebAssembly);
946 this->HasFloat128 = true;
950 // WASI target
951 template <typename Target>
952 class LLVM_LIBRARY_VISIBILITY WASITargetInfo
953 : public WebAssemblyOSTargetInfo<Target> {
954 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
955 MacroBuilder &Builder) const final {
956 WebAssemblyOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
957 Builder.defineMacro("__wasi__");
960 public:
961 using WebAssemblyOSTargetInfo<Target>::WebAssemblyOSTargetInfo;
964 // Emscripten target
965 template <typename Target>
966 class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
967 : public WebAssemblyOSTargetInfo<Target> {
968 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
969 MacroBuilder &Builder) const final {
970 WebAssemblyOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
971 DefineStd(Builder, "unix", Opts);
972 Builder.defineMacro("__EMSCRIPTEN__");
973 if (Opts.POSIXThreads)
974 Builder.defineMacro("__EMSCRIPTEN_PTHREADS__");
977 public:
978 explicit EmscriptenTargetInfo(const llvm::Triple &Triple,
979 const TargetOptions &Opts)
980 : WebAssemblyOSTargetInfo<Target>(Triple, Opts) {
981 // Keeping the alignment of long double to 8 bytes even though its size is
982 // 16 bytes allows emscripten to have an 8-byte-aligned max_align_t which
983 // in turn gives is a 8-byte aligned malloc.
984 // Emscripten's ABI is unstable and we may change this back to 128 to match
985 // the WebAssembly default in the future.
986 this->LongDoubleAlign = 64;
990 // OHOS target
991 template <typename Target>
992 class LLVM_LIBRARY_VISIBILITY OHOSTargetInfo : public OSTargetInfo<Target> {
993 protected:
994 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
995 MacroBuilder &Builder) const override {
996 // Linux defines; list based off of gcc output
997 DefineStd(Builder, "unix", Opts);
999 // Generic OHOS target defines
1000 if (Triple.isOHOSFamily()) {
1001 Builder.defineMacro("__OHOS_FAMILY__", "1");
1003 auto Version = Triple.getEnvironmentVersion();
1004 this->PlatformName = "ohos";
1005 this->PlatformMinVersion = Version;
1006 Builder.defineMacro("__OHOS_Major__", Twine(Version.getMajor()));
1007 if (auto Minor = Version.getMinor())
1008 Builder.defineMacro("__OHOS_Minor__", Twine(*Minor));
1009 if (auto Subminor = Version.getSubminor())
1010 Builder.defineMacro("__OHOS_Micro__", Twine(*Subminor));
1013 if (Triple.isOpenHOS())
1014 Builder.defineMacro("__OHOS__");
1016 if (Triple.isOSLinux()) {
1017 DefineStd(Builder, "linux", Opts);
1018 } else if (Triple.isOSLiteOS()) {
1019 Builder.defineMacro("__LITEOS__");
1022 if (Opts.POSIXThreads)
1023 Builder.defineMacro("_REENTRANT");
1024 if (Opts.CPlusPlus)
1025 Builder.defineMacro("_GNU_SOURCE");
1026 if (this->HasFloat128)
1027 Builder.defineMacro("__FLOAT128__");
1030 public:
1031 OHOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
1032 : OSTargetInfo<Target>(Triple, Opts) {
1033 this->WIntType = TargetInfo::UnsignedInt;
1035 switch (Triple.getArch()) {
1036 default:
1037 break;
1038 case llvm::Triple::x86:
1039 case llvm::Triple::x86_64:
1040 this->HasFloat128 = true;
1041 break;
1045 const char *getStaticInitSectionSpecifier() const override {
1046 return ".text.startup";
1050 } // namespace targets
1051 } // namespace clang
1052 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H