clang  9.0.0svn
OSTargets.h
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
11 
12 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
13 #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
14 
15 #include "Targets.h"
16 #include "llvm/MC/MCSectionMachO.h"
17 
18 namespace clang {
19 namespace targets {
20 
21 template <typename TgtInfo>
22 class LLVM_LIBRARY_VISIBILITY OSTargetInfo : public TgtInfo {
23 protected:
24  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
25  MacroBuilder &Builder) const = 0;
26 
27 public:
28  OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
29  : TgtInfo(Triple, Opts) {}
30 
31  void getTargetDefines(const LangOptions &Opts,
32  MacroBuilder &Builder) const override {
33  TgtInfo::getTargetDefines(Opts, Builder);
34  getOSDefines(Opts, TgtInfo::getTriple(), Builder);
35  }
36 };
37 
38 // CloudABI Target
39 template <typename Target>
40 class LLVM_LIBRARY_VISIBILITY CloudABITargetInfo : public OSTargetInfo<Target> {
41 protected:
42  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
43  MacroBuilder &Builder) const override {
44  Builder.defineMacro("__CloudABI__");
45  Builder.defineMacro("__ELF__");
46 
47  // CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
48  Builder.defineMacro("__STDC_ISO_10646__", "201206L");
49  Builder.defineMacro("__STDC_UTF_16__");
50  Builder.defineMacro("__STDC_UTF_32__");
51  }
52 
53 public:
54  CloudABITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
55  : OSTargetInfo<Target>(Triple, Opts) {}
56 };
57 
58 // Ananas target
59 template <typename Target>
60 class LLVM_LIBRARY_VISIBILITY AnanasTargetInfo : public OSTargetInfo<Target> {
61 protected:
62  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
63  MacroBuilder &Builder) const override {
64  // Ananas defines
65  Builder.defineMacro("__Ananas__");
66  Builder.defineMacro("__ELF__");
67  }
68 
69 public:
70  AnanasTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
71  : OSTargetInfo<Target>(Triple, Opts) {}
72 };
73 
74 void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
75  const llvm::Triple &Triple, StringRef &PlatformName,
76  VersionTuple &PlatformMinVersion);
77 
78 template <typename Target>
79 class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public OSTargetInfo<Target> {
80 protected:
81  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
82  MacroBuilder &Builder) const override {
83  getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
84  this->PlatformMinVersion);
85  }
86 
87 public:
88  DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
89  : OSTargetInfo<Target>(Triple, Opts) {
90  // By default, no TLS, and we whitelist permitted architecture/OS
91  // combinations.
92  this->TLSSupported = false;
93 
94  if (Triple.isMacOSX())
95  this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7);
96  else if (Triple.isiOS()) {
97  // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
98  // 32-bit simulator from 10 onwards.
99  if (Triple.isArch64Bit())
100  this->TLSSupported = !Triple.isOSVersionLT(8);
101  else if (Triple.isArch32Bit()) {
102  if (!Triple.isSimulatorEnvironment())
103  this->TLSSupported = !Triple.isOSVersionLT(9);
104  else
105  this->TLSSupported = !Triple.isOSVersionLT(10);
106  }
107  } else if (Triple.isWatchOS()) {
108  if (!Triple.isSimulatorEnvironment())
109  this->TLSSupported = !Triple.isOSVersionLT(2);
110  else
111  this->TLSSupported = !Triple.isOSVersionLT(3);
112  }
113 
114  this->MCountName = "\01mcount";
115  }
116 
117  std::string isValidSectionSpecifier(StringRef SR) const override {
118  // Let MCSectionMachO validate this.
119  StringRef Segment, Section;
120  unsigned TAA, StubSize;
121  bool HasTAA;
122  return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
123  TAA, HasTAA, StubSize);
124  }
125 
126  const char *getStaticInitSectionSpecifier() const override {
127  // FIXME: We should return 0 when building kexts.
128  return "__TEXT,__StaticInit,regular,pure_instructions";
129  }
130 
131  /// Darwin does not support protected visibility. Darwin's "default"
132  /// is very similar to ELF's "protected"; Darwin requires a "weak"
133  /// attribute on declarations that can be dynamically replaced.
134  bool hasProtectedVisibility() const override { return false; }
135 
137  bool IsSigned) const final {
138  // Darwin uses `long long` for `int_least64_t` and `int_fast64_t`.
139  return BitWidth == 64
140  ? (IsSigned ? TargetInfo::SignedLongLong
142  : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
143  }
144 };
145 
146 // DragonFlyBSD Target
147 template <typename Target>
148 class LLVM_LIBRARY_VISIBILITY DragonFlyBSDTargetInfo
149  : public OSTargetInfo<Target> {
150 protected:
151  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
152  MacroBuilder &Builder) const override {
153  // DragonFly defines; list based off of gcc output
154  Builder.defineMacro("__DragonFly__");
155  Builder.defineMacro("__DragonFly_cc_version", "100001");
156  Builder.defineMacro("__ELF__");
157  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
158  Builder.defineMacro("__tune_i386__");
159  DefineStd(Builder, "unix", Opts);
160  }
161 
162 public:
163  DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
164  : OSTargetInfo<Target>(Triple, Opts) {
165  switch (Triple.getArch()) {
166  default:
167  case llvm::Triple::x86:
168  case llvm::Triple::x86_64:
169  this->MCountName = ".mcount";
170  break;
171  }
172  }
173 };
174 
175 #ifndef FREEBSD_CC_VERSION
176 #define FREEBSD_CC_VERSION 0U
177 #endif
178 
179 // FreeBSD Target
180 template <typename Target>
181 class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo<Target> {
182 protected:
183  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
184  MacroBuilder &Builder) const override {
185  // FreeBSD defines; list based off of gcc output
186 
187  unsigned Release = Triple.getOSMajorVersion();
188  if (Release == 0U)
189  Release = 8U;
190  unsigned CCVersion = FREEBSD_CC_VERSION;
191  if (CCVersion == 0U)
192  CCVersion = Release * 100000U + 1U;
193 
194  Builder.defineMacro("__FreeBSD__", Twine(Release));
195  Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
196  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
197  DefineStd(Builder, "unix", Opts);
198  Builder.defineMacro("__ELF__");
199 
200  // On FreeBSD, wchar_t contains the number of the code point as
201  // used by the character set of the locale. These character sets are
202  // not necessarily a superset of ASCII.
203  //
204  // FIXME: This is wrong; the macro refers to the numerical values
205  // of wchar_t *literals*, which are not locale-dependent. However,
206  // FreeBSD systems apparently depend on us getting this wrong, and
207  // setting this to 1 is conforming even if all the basic source
208  // character literals have the same encoding as char and wchar_t.
209  Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
210  }
211 
212 public:
213  FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
214  : OSTargetInfo<Target>(Triple, Opts) {
215  switch (Triple.getArch()) {
216  default:
217  case llvm::Triple::x86:
218  case llvm::Triple::x86_64:
219  this->MCountName = ".mcount";
220  break;
221  case llvm::Triple::mips:
222  case llvm::Triple::mipsel:
223  case llvm::Triple::ppc:
224  case llvm::Triple::ppc64:
225  case llvm::Triple::ppc64le:
226  this->MCountName = "_mcount";
227  break;
228  case llvm::Triple::arm:
229  this->MCountName = "__mcount";
230  break;
231  }
232  }
233 };
234 
235 // GNU/kFreeBSD Target
236 template <typename Target>
237 class LLVM_LIBRARY_VISIBILITY KFreeBSDTargetInfo : public OSTargetInfo<Target> {
238 protected:
239  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
240  MacroBuilder &Builder) const override {
241  // GNU/kFreeBSD defines; list based off of gcc output
242 
243  DefineStd(Builder, "unix", Opts);
244  Builder.defineMacro("__FreeBSD_kernel__");
245  Builder.defineMacro("__GLIBC__");
246  Builder.defineMacro("__ELF__");
247  if (Opts.POSIXThreads)
248  Builder.defineMacro("_REENTRANT");
249  if (Opts.CPlusPlus)
250  Builder.defineMacro("_GNU_SOURCE");
251  }
252 
253 public:
254  KFreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
255  : OSTargetInfo<Target>(Triple, Opts) {}
256 };
257 
258 // Haiku Target
259 template <typename Target>
260 class LLVM_LIBRARY_VISIBILITY HaikuTargetInfo : public OSTargetInfo<Target> {
261 protected:
262  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
263  MacroBuilder &Builder) const override {
264  // Haiku defines; list based off of gcc output
265  Builder.defineMacro("__HAIKU__");
266  Builder.defineMacro("__ELF__");
267  DefineStd(Builder, "unix", Opts);
268  if (this->HasFloat128)
269  Builder.defineMacro("__FLOAT128__");
270  }
271 
272 public:
273  HaikuTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
274  : OSTargetInfo<Target>(Triple, Opts) {
275  this->SizeType = TargetInfo::UnsignedLong;
276  this->IntPtrType = TargetInfo::SignedLong;
277  this->PtrDiffType = TargetInfo::SignedLong;
278  this->ProcessIDType = TargetInfo::SignedLong;
279  this->TLSSupported = false;
280  switch (Triple.getArch()) {
281  default:
282  break;
283  case llvm::Triple::x86:
284  case llvm::Triple::x86_64:
285  this->HasFloat128 = true;
286  break;
287  }
288  }
289 };
290 
291 // Hurd target
292 template <typename Target>
293 class LLVM_LIBRARY_VISIBILITY HurdTargetInfo : public OSTargetInfo<Target> {
294 protected:
295  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
296  MacroBuilder &Builder) const override {
297  // Hurd defines; list based off of gcc output.
298  DefineStd(Builder, "unix", Opts);
299  Builder.defineMacro("__GNU__");
300  Builder.defineMacro("__gnu_hurd__");
301  Builder.defineMacro("__MACH__");
302  Builder.defineMacro("__GLIBC__");
303  Builder.defineMacro("__ELF__");
304  if (Opts.POSIXThreads)
305  Builder.defineMacro("_REENTRANT");
306  if (Opts.CPlusPlus)
307  Builder.defineMacro("_GNU_SOURCE");
308  }
309 public:
310  HurdTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
311  : OSTargetInfo<Target>(Triple, Opts) {}
312 };
313 
314 // Minix Target
315 template <typename Target>
316 class LLVM_LIBRARY_VISIBILITY MinixTargetInfo : public OSTargetInfo<Target> {
317 protected:
318  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
319  MacroBuilder &Builder) const override {
320  // Minix defines
321 
322  Builder.defineMacro("__minix", "3");
323  Builder.defineMacro("_EM_WSIZE", "4");
324  Builder.defineMacro("_EM_PSIZE", "4");
325  Builder.defineMacro("_EM_SSIZE", "2");
326  Builder.defineMacro("_EM_LSIZE", "4");
327  Builder.defineMacro("_EM_FSIZE", "4");
328  Builder.defineMacro("_EM_DSIZE", "8");
329  Builder.defineMacro("__ELF__");
330  DefineStd(Builder, "unix", Opts);
331  }
332 
333 public:
334  MinixTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
335  : OSTargetInfo<Target>(Triple, Opts) {}
336 };
337 
338 // Linux target
339 template <typename Target>
340 class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public OSTargetInfo<Target> {
341 protected:
342  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
343  MacroBuilder &Builder) const override {
344  // Linux defines; list based off of gcc output
345  DefineStd(Builder, "unix", Opts);
346  DefineStd(Builder, "linux", Opts);
347  Builder.defineMacro("__ELF__");
348  if (Triple.isAndroid()) {
349  Builder.defineMacro("__ANDROID__", "1");
350  unsigned Maj, Min, Rev;
351  Triple.getEnvironmentVersion(Maj, Min, Rev);
352  this->PlatformName = "android";
353  this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
354  if (Maj)
355  Builder.defineMacro("__ANDROID_API__", Twine(Maj));
356  } else {
357  Builder.defineMacro("__gnu_linux__");
358  }
359  if (Opts.POSIXThreads)
360  Builder.defineMacro("_REENTRANT");
361  if (Opts.CPlusPlus)
362  Builder.defineMacro("_GNU_SOURCE");
363  if (this->HasFloat128)
364  Builder.defineMacro("__FLOAT128__");
365  }
366 
367 public:
368  LinuxTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
369  : OSTargetInfo<Target>(Triple, Opts) {
370  this->WIntType = TargetInfo::UnsignedInt;
371 
372  switch (Triple.getArch()) {
373  default:
374  break;
375  case llvm::Triple::mips:
376  case llvm::Triple::mipsel:
377  case llvm::Triple::mips64:
378  case llvm::Triple::mips64el:
379  case llvm::Triple::ppc:
380  case llvm::Triple::ppc64:
381  case llvm::Triple::ppc64le:
382  this->MCountName = "_mcount";
383  break;
384  case llvm::Triple::x86:
385  case llvm::Triple::x86_64:
386  this->HasFloat128 = true;
387  break;
388  }
389  }
390 
391  const char *getStaticInitSectionSpecifier() const override {
392  return ".text.startup";
393  }
394 };
395 
396 // NetBSD Target
397 template <typename Target>
398 class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public OSTargetInfo<Target> {
399 protected:
400  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
401  MacroBuilder &Builder) const override {
402  // NetBSD defines; list based off of gcc output
403  Builder.defineMacro("__NetBSD__");
404  Builder.defineMacro("__unix__");
405  Builder.defineMacro("__ELF__");
406  if (Opts.POSIXThreads)
407  Builder.defineMacro("_REENTRANT");
408  }
409 
410 public:
411  NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
412  : OSTargetInfo<Target>(Triple, Opts) {
413  this->MCountName = "__mcount";
414  }
415 };
416 
417 // OpenBSD Target
418 template <typename Target>
419 class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
420 protected:
421  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
422  MacroBuilder &Builder) const override {
423  // OpenBSD defines; list based off of gcc output
424 
425  Builder.defineMacro("__OpenBSD__");
426  DefineStd(Builder, "unix", Opts);
427  Builder.defineMacro("__ELF__");
428  if (Opts.POSIXThreads)
429  Builder.defineMacro("_REENTRANT");
430  if (this->HasFloat128)
431  Builder.defineMacro("__FLOAT128__");
432  }
433 
434 public:
435  OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
436  : OSTargetInfo<Target>(Triple, Opts) {
437  switch (Triple.getArch()) {
438  case llvm::Triple::x86:
439  case llvm::Triple::x86_64:
440  this->HasFloat128 = true;
441  LLVM_FALLTHROUGH;
442  default:
443  this->MCountName = "__mcount";
444  break;
445  case llvm::Triple::mips64:
446  case llvm::Triple::mips64el:
447  case llvm::Triple::ppc:
448  case llvm::Triple::sparcv9:
449  this->MCountName = "_mcount";
450  break;
451  }
452  }
453 };
454 
455 // PSP Target
456 template <typename Target>
457 class LLVM_LIBRARY_VISIBILITY PSPTargetInfo : public OSTargetInfo<Target> {
458 protected:
459  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
460  MacroBuilder &Builder) const override {
461  // PSP defines; list based on the output of the pspdev gcc toolchain.
462  Builder.defineMacro("PSP");
463  Builder.defineMacro("_PSP");
464  Builder.defineMacro("__psp__");
465  Builder.defineMacro("__ELF__");
466  }
467 
468 public:
469  PSPTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {}
470 };
471 
472 // PS3 PPU Target
473 template <typename Target>
474 class LLVM_LIBRARY_VISIBILITY PS3PPUTargetInfo : public OSTargetInfo<Target> {
475 protected:
476  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
477  MacroBuilder &Builder) const override {
478  // PS3 PPU defines.
479  Builder.defineMacro("__PPC__");
480  Builder.defineMacro("__PPU__");
481  Builder.defineMacro("__CELLOS_LV2__");
482  Builder.defineMacro("__ELF__");
483  Builder.defineMacro("__LP32__");
484  Builder.defineMacro("_ARCH_PPC64");
485  Builder.defineMacro("__powerpc64__");
486  }
487 
488 public:
489  PS3PPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
490  : OSTargetInfo<Target>(Triple, Opts) {
491  this->LongWidth = this->LongAlign = 32;
492  this->PointerWidth = this->PointerAlign = 32;
493  this->IntMaxType = TargetInfo::SignedLongLong;
494  this->Int64Type = TargetInfo::SignedLongLong;
495  this->SizeType = TargetInfo::UnsignedInt;
496  this->resetDataLayout("E-m:e-p:32:32-i64:64-n32:64");
497  }
498 };
499 
500 template <typename Target>
501 class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public OSTargetInfo<Target> {
502 protected:
503  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
504  MacroBuilder &Builder) const override {
505  Builder.defineMacro("__FreeBSD__", "9");
506  Builder.defineMacro("__FreeBSD_cc_version", "900001");
507  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
508  DefineStd(Builder, "unix", Opts);
509  Builder.defineMacro("__ELF__");
510  Builder.defineMacro("__ORBIS__");
511  }
512 
513 public:
514  PS4OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
515  : OSTargetInfo<Target>(Triple, Opts) {
516  this->WCharType = TargetInfo::UnsignedShort;
517 
518  // On PS4, TLS variable cannot be aligned to more than 32 bytes (256 bits).
519  this->MaxTLSAlign = 256;
520 
521  // On PS4, do not honor explicit bit field alignment,
522  // as in "__attribute__((aligned(2))) int b : 1;".
523  this->UseExplicitBitFieldAlignment = false;
524 
525  switch (Triple.getArch()) {
526  default:
527  case llvm::Triple::x86_64:
528  this->MCountName = ".mcount";
529  this->NewAlign = 256;
530  break;
531  }
532  }
533 };
534 
535 // RTEMS Target
536 template <typename Target>
537 class LLVM_LIBRARY_VISIBILITY RTEMSTargetInfo : public OSTargetInfo<Target> {
538 protected:
539  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
540  MacroBuilder &Builder) const override {
541  // RTEMS defines; list based off of gcc output
542 
543  Builder.defineMacro("__rtems__");
544  Builder.defineMacro("__ELF__");
545  if (Opts.CPlusPlus)
546  Builder.defineMacro("_GNU_SOURCE");
547  }
548 
549 public:
550  RTEMSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
551  : OSTargetInfo<Target>(Triple, Opts) {
552  switch (Triple.getArch()) {
553  default:
554  case llvm::Triple::x86:
555  // this->MCountName = ".mcount";
556  break;
557  case llvm::Triple::mips:
558  case llvm::Triple::mipsel:
559  case llvm::Triple::ppc:
560  case llvm::Triple::ppc64:
561  case llvm::Triple::ppc64le:
562  // this->MCountName = "_mcount";
563  break;
564  case llvm::Triple::arm:
565  // this->MCountName = "__mcount";
566  break;
567  }
568  }
569 };
570 
571 // Solaris target
572 template <typename Target>
573 class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo : public OSTargetInfo<Target> {
574 protected:
575  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
576  MacroBuilder &Builder) const override {
577  DefineStd(Builder, "sun", Opts);
578  DefineStd(Builder, "unix", Opts);
579  Builder.defineMacro("__ELF__");
580  Builder.defineMacro("__svr4__");
581  Builder.defineMacro("__SVR4");
582  // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
583  // newer, but to 500 for everything else. feature_test.h has a check to
584  // ensure that you are not using C99 with an old version of X/Open or C89
585  // with a new version.
586  if (Opts.C99)
587  Builder.defineMacro("_XOPEN_SOURCE", "600");
588  else
589  Builder.defineMacro("_XOPEN_SOURCE", "500");
590  if (Opts.CPlusPlus)
591  Builder.defineMacro("__C99FEATURES__");
592  Builder.defineMacro("_LARGEFILE_SOURCE");
593  Builder.defineMacro("_LARGEFILE64_SOURCE");
594  Builder.defineMacro("__EXTENSIONS__");
595  if (Opts.POSIXThreads)
596  Builder.defineMacro("_REENTRANT");
597  if (this->HasFloat128)
598  Builder.defineMacro("__FLOAT128__");
599  }
600 
601 public:
602  SolarisTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
603  : OSTargetInfo<Target>(Triple, Opts) {
604  // FIXME: WIntType should be SignedLong
605  switch (Triple.getArch()) {
606  default:
607  break;
608  case llvm::Triple::x86:
609  case llvm::Triple::x86_64:
610  this->HasFloat128 = true;
611  break;
612  }
613  }
614 };
615 
616 // Windows target
617 template <typename Target>
618 class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
619 protected:
620  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
621  MacroBuilder &Builder) const override {
622  Builder.defineMacro("_WIN32");
623  if (Triple.isArch64Bit())
624  Builder.defineMacro("_WIN64");
625  if (Triple.isWindowsGNUEnvironment())
626  addMinGWDefines(Triple, Opts, Builder);
627 
628  }
630  MacroBuilder &Builder) const {
631  if (Opts.CPlusPlus) {
632  if (Opts.RTTIData)
633  Builder.defineMacro("_CPPRTTI");
634 
635  if (Opts.CXXExceptions)
636  Builder.defineMacro("_CPPUNWIND");
637  }
638 
639  if (Opts.Bool)
640  Builder.defineMacro("__BOOL_DEFINED");
641 
642  if (!Opts.CharIsSigned)
643  Builder.defineMacro("_CHAR_UNSIGNED");
644 
645  // FIXME: POSIXThreads isn't exactly the option this should be defined for,
646  // but it works for now.
647  if (Opts.POSIXThreads)
648  Builder.defineMacro("_MT");
649 
650  if (Opts.MSCompatibilityVersion) {
651  Builder.defineMacro("_MSC_VER",
652  Twine(Opts.MSCompatibilityVersion / 100000));
653  Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
654  // FIXME We cannot encode the revision information into 32-bits
655  Builder.defineMacro("_MSC_BUILD", Twine(1));
656 
657  if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
658  Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
659 
661  if (Opts.CPlusPlus2a)
662  Builder.defineMacro("_MSVC_LANG", "201704L");
663  else if (Opts.CPlusPlus17)
664  Builder.defineMacro("_MSVC_LANG", "201703L");
665  else if (Opts.CPlusPlus14)
666  Builder.defineMacro("_MSVC_LANG", "201402L");
667  }
668  }
669 
670  if (Opts.MicrosoftExt) {
671  Builder.defineMacro("_MSC_EXTENSIONS");
672 
673  if (Opts.CPlusPlus11) {
674  Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
675  Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
676  Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
677  }
678  }
679 
680  Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
681  }
682 
683 public:
684  WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
685  : OSTargetInfo<Target>(Triple, Opts) {
686  this->WCharType = TargetInfo::UnsignedShort;
687  this->WIntType = TargetInfo::UnsignedShort;
688  }
689 };
690 
691 template <typename Target>
692 class LLVM_LIBRARY_VISIBILITY NaClTargetInfo : public OSTargetInfo<Target> {
693 protected:
694  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
695  MacroBuilder &Builder) const override {
696  if (Opts.POSIXThreads)
697  Builder.defineMacro("_REENTRANT");
698  if (Opts.CPlusPlus)
699  Builder.defineMacro("_GNU_SOURCE");
700 
701  DefineStd(Builder, "unix", Opts);
702  Builder.defineMacro("__ELF__");
703  Builder.defineMacro("__native_client__");
704  }
705 
706 public:
707  NaClTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
708  : OSTargetInfo<Target>(Triple, Opts) {
709  this->LongAlign = 32;
710  this->LongWidth = 32;
711  this->PointerAlign = 32;
712  this->PointerWidth = 32;
713  this->IntMaxType = TargetInfo::SignedLongLong;
714  this->Int64Type = TargetInfo::SignedLongLong;
715  this->DoubleAlign = 64;
716  this->LongDoubleWidth = 64;
717  this->LongDoubleAlign = 64;
718  this->LongLongWidth = 64;
719  this->LongLongAlign = 64;
720  this->SizeType = TargetInfo::UnsignedInt;
721  this->PtrDiffType = TargetInfo::SignedInt;
722  this->IntPtrType = TargetInfo::SignedInt;
723  // RegParmMax is inherited from the underlying architecture.
724  this->LongDoubleFormat = &llvm::APFloat::IEEEdouble();
725  if (Triple.getArch() == llvm::Triple::arm) {
726  // Handled in ARM's setABI().
727  } else if (Triple.getArch() == llvm::Triple::x86) {
728  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32-S128");
729  } else if (Triple.getArch() == llvm::Triple::x86_64) {
730  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32:64-S128");
731  } else if (Triple.getArch() == llvm::Triple::mipsel) {
732  // Handled on mips' setDataLayout.
733  } else {
734  assert(Triple.getArch() == llvm::Triple::le32);
735  this->resetDataLayout("e-p:32:32-i64:64");
736  }
737  }
738 };
739 
740 // Fuchsia Target
741 template <typename Target>
742 class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo : public OSTargetInfo<Target> {
743 protected:
744  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
745  MacroBuilder &Builder) const override {
746  Builder.defineMacro("__Fuchsia__");
747  Builder.defineMacro("__ELF__");
748  if (Opts.POSIXThreads)
749  Builder.defineMacro("_REENTRANT");
750  // Required by the libc++ locale support.
751  if (Opts.CPlusPlus)
752  Builder.defineMacro("_GNU_SOURCE");
753  }
754 
755 public:
756  FuchsiaTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
757  : OSTargetInfo<Target>(Triple, Opts) {
758  this->MCountName = "__mcount";
759  }
760 };
761 
762 // WebAssembly target
763 template <typename Target>
764 class LLVM_LIBRARY_VISIBILITY WebAssemblyOSTargetInfo
765  : public OSTargetInfo<Target> {
766 protected:
767  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
768  MacroBuilder &Builder) const {
769  // A common platform macro.
770  if (Opts.POSIXThreads)
771  Builder.defineMacro("_REENTRANT");
772  // Follow g++ convention and predefine _GNU_SOURCE for C++.
773  if (Opts.CPlusPlus)
774  Builder.defineMacro("_GNU_SOURCE");
775  // Indicate that we have __float128.
776  Builder.defineMacro("__FLOAT128__");
777  }
778 
779 public:
780  explicit WebAssemblyOSTargetInfo(const llvm::Triple &Triple,
781  const TargetOptions &Opts)
782  : OSTargetInfo<Target>(Triple, Opts) {
783  this->MCountName = "__mcount";
784  this->TheCXXABI.set(TargetCXXABI::WebAssembly);
785  this->HasFloat128 = true;
786  }
787 };
788 
789 // WASI target
790 template <typename Target>
791 class LLVM_LIBRARY_VISIBILITY WASITargetInfo
792  : public WebAssemblyOSTargetInfo<Target> {
793  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
794  MacroBuilder &Builder) const final {
795  WebAssemblyOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
796  Builder.defineMacro("__wasi__");
797  }
798 
799 public:
800  explicit WASITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
801  : WebAssemblyOSTargetInfo<Target>(Triple, Opts) {}
802 };
803 
804 } // namespace targets
805 } // namespace clang
806 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
PSPTargetInfo(const llvm::Triple &Triple)
Definition: OSTargets.h:469
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:42
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:54
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:262
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:280
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:744
WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:684
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
Definition: TargetInfo.cpp:244
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:81
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:295
const char * getStaticInitSectionSpecifier() const override
Definition: OSTargets.h:126
Options for controlling the target.
Definition: TargetOptions.h:26
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:476
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:620
WebAssemblyOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:780
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:183
LinuxTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:368
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const
Definition: OSTargets.h:767
bool hasProtectedVisibility() const override
Darwin does not support protected visibility.
Definition: OSTargets.h:134
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
RTEMSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:550
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:62
AnanasTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:70
NaClTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:707
const char * getStaticInitSectionSpecifier() const override
Definition: OSTargets.h:391
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:342
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:239
void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:101
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:151
std::string isValidSectionSpecifier(StringRef SR) const override
Definition: OSTargets.h:117
KFreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:254
SolarisTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:602
void getVisualStudioDefines(const LangOptions &Opts, MacroBuilder &Builder) const
Definition: OSTargets.h:629
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
Definition: OSTargets.h:31
DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:88
HaikuTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:273
DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:163
FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:213
void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple, StringRef &PlatformName, VersionTuple &PlatformMinVersion)
Definition: OSTargets.cpp:22
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:503
#define FREEBSD_CC_VERSION
Definition: OSTargets.h:176
FuchsiaTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:756
CloudABITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:54
The WebAssembly ABI is a modified version of the Itanium ABI.
Definition: TargetCXXABI.h:104
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition: TargetInfo.h:104
Dataflow Directional Tag Classes.
PS4OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:514
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:539
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:318
HurdTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:310
NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:411
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:400
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:694
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:459
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:575
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:421
MinixTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:334
OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:28
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
Definition: MacroBuilder.h:29
OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:435
WASITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:800
PS3PPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:489
TargetInfo::IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final
Definition: OSTargets.h:136