clang  8.0.0svn
OSTargets.h
Go to the documentation of this file.
1 //===--- OSTargets.h - Declare OS target feature support --------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares OS specific TargetInfo types.
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
15 
16 #include "Targets.h"
17 #include "llvm/MC/MCSectionMachO.h"
18 
19 namespace clang {
20 namespace targets {
21 
22 template <typename TgtInfo>
23 class LLVM_LIBRARY_VISIBILITY OSTargetInfo : public TgtInfo {
24 protected:
25  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
26  MacroBuilder &Builder) const = 0;
27 
28 public:
29  OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
30  : TgtInfo(Triple, Opts) {}
31 
32  void getTargetDefines(const LangOptions &Opts,
33  MacroBuilder &Builder) const override {
34  TgtInfo::getTargetDefines(Opts, Builder);
35  getOSDefines(Opts, TgtInfo::getTriple(), Builder);
36  }
37 };
38 
39 // CloudABI Target
40 template <typename Target>
41 class LLVM_LIBRARY_VISIBILITY CloudABITargetInfo : public OSTargetInfo<Target> {
42 protected:
43  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
44  MacroBuilder &Builder) const override {
45  Builder.defineMacro("__CloudABI__");
46  Builder.defineMacro("__ELF__");
47 
48  // CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
49  Builder.defineMacro("__STDC_ISO_10646__", "201206L");
50  Builder.defineMacro("__STDC_UTF_16__");
51  Builder.defineMacro("__STDC_UTF_32__");
52  }
53 
54 public:
55  CloudABITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
56  : OSTargetInfo<Target>(Triple, Opts) {}
57 };
58 
59 // Ananas target
60 template <typename Target>
61 class LLVM_LIBRARY_VISIBILITY AnanasTargetInfo : public OSTargetInfo<Target> {
62 protected:
63  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
64  MacroBuilder &Builder) const override {
65  // Ananas defines
66  Builder.defineMacro("__Ananas__");
67  Builder.defineMacro("__ELF__");
68  }
69 
70 public:
71  AnanasTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
72  : OSTargetInfo<Target>(Triple, Opts) {}
73 };
74 
75 void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
76  const llvm::Triple &Triple, StringRef &PlatformName,
77  VersionTuple &PlatformMinVersion);
78 
79 template <typename Target>
80 class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public OSTargetInfo<Target> {
81 protected:
82  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
83  MacroBuilder &Builder) const override {
84  getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
85  this->PlatformMinVersion);
86  }
87 
88 public:
89  DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
90  : OSTargetInfo<Target>(Triple, Opts) {
91  // By default, no TLS, and we whitelist permitted architecture/OS
92  // combinations.
93  this->TLSSupported = false;
94 
95  if (Triple.isMacOSX())
96  this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7);
97  else if (Triple.isiOS()) {
98  // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
99  // 32-bit simulator from 10 onwards.
100  if (Triple.isArch64Bit())
101  this->TLSSupported = !Triple.isOSVersionLT(8);
102  else if (Triple.isArch32Bit()) {
103  if (!Triple.isSimulatorEnvironment())
104  this->TLSSupported = !Triple.isOSVersionLT(9);
105  else
106  this->TLSSupported = !Triple.isOSVersionLT(10);
107  }
108  } else if (Triple.isWatchOS()) {
109  if (!Triple.isSimulatorEnvironment())
110  this->TLSSupported = !Triple.isOSVersionLT(2);
111  else
112  this->TLSSupported = !Triple.isOSVersionLT(3);
113  }
114 
115  this->MCountName = "\01mcount";
116  }
117 
118  std::string isValidSectionSpecifier(StringRef SR) const override {
119  // Let MCSectionMachO validate this.
120  StringRef Segment, Section;
121  unsigned TAA, StubSize;
122  bool HasTAA;
123  return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
124  TAA, HasTAA, StubSize);
125  }
126 
127  const char *getStaticInitSectionSpecifier() const override {
128  // FIXME: We should return 0 when building kexts.
129  return "__TEXT,__StaticInit,regular,pure_instructions";
130  }
131 
132  /// Darwin does not support protected visibility. Darwin's "default"
133  /// is very similar to ELF's "protected"; Darwin requires a "weak"
134  /// attribute on declarations that can be dynamically replaced.
135  bool hasProtectedVisibility() const override { return false; }
136 
138  bool IsSigned) const final {
139  // Darwin uses `long long` for `int_least64_t` and `int_fast64_t`.
140  return BitWidth == 64
141  ? (IsSigned ? TargetInfo::SignedLongLong
143  : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
144  }
145 };
146 
147 // DragonFlyBSD Target
148 template <typename Target>
149 class LLVM_LIBRARY_VISIBILITY DragonFlyBSDTargetInfo
150  : public OSTargetInfo<Target> {
151 protected:
152  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
153  MacroBuilder &Builder) const override {
154  // DragonFly defines; list based off of gcc output
155  Builder.defineMacro("__DragonFly__");
156  Builder.defineMacro("__DragonFly_cc_version", "100001");
157  Builder.defineMacro("__ELF__");
158  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
159  Builder.defineMacro("__tune_i386__");
160  DefineStd(Builder, "unix", Opts);
161  }
162 
163 public:
164  DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
165  : OSTargetInfo<Target>(Triple, Opts) {
166  switch (Triple.getArch()) {
167  default:
168  case llvm::Triple::x86:
169  case llvm::Triple::x86_64:
170  this->MCountName = ".mcount";
171  break;
172  }
173  }
174 };
175 
176 #ifndef FREEBSD_CC_VERSION
177 #define FREEBSD_CC_VERSION 0U
178 #endif
179 
180 // FreeBSD Target
181 template <typename Target>
182 class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo<Target> {
183 protected:
184  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
185  MacroBuilder &Builder) const override {
186  // FreeBSD defines; list based off of gcc output
187 
188  unsigned Release = Triple.getOSMajorVersion();
189  if (Release == 0U)
190  Release = 8U;
191  unsigned CCVersion = FREEBSD_CC_VERSION;
192  if (CCVersion == 0U)
193  CCVersion = Release * 100000U + 1U;
194 
195  Builder.defineMacro("__FreeBSD__", Twine(Release));
196  Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
197  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
198  DefineStd(Builder, "unix", Opts);
199  Builder.defineMacro("__ELF__");
200 
201  // On FreeBSD, wchar_t contains the number of the code point as
202  // used by the character set of the locale. These character sets are
203  // not necessarily a superset of ASCII.
204  //
205  // FIXME: This is wrong; the macro refers to the numerical values
206  // of wchar_t *literals*, which are not locale-dependent. However,
207  // FreeBSD systems apparently depend on us getting this wrong, and
208  // setting this to 1 is conforming even if all the basic source
209  // character literals have the same encoding as char and wchar_t.
210  Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
211  }
212 
213 public:
214  FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
215  : OSTargetInfo<Target>(Triple, Opts) {
216  switch (Triple.getArch()) {
217  default:
218  case llvm::Triple::x86:
219  case llvm::Triple::x86_64:
220  this->MCountName = ".mcount";
221  break;
222  case llvm::Triple::mips:
223  case llvm::Triple::mipsel:
224  case llvm::Triple::ppc:
225  case llvm::Triple::ppc64:
226  case llvm::Triple::ppc64le:
227  this->MCountName = "_mcount";
228  break;
229  case llvm::Triple::arm:
230  this->MCountName = "__mcount";
231  break;
232  }
233  }
234 };
235 
236 // GNU/kFreeBSD Target
237 template <typename Target>
238 class LLVM_LIBRARY_VISIBILITY KFreeBSDTargetInfo : public OSTargetInfo<Target> {
239 protected:
240  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
241  MacroBuilder &Builder) const override {
242  // GNU/kFreeBSD defines; list based off of gcc output
243 
244  DefineStd(Builder, "unix", Opts);
245  Builder.defineMacro("__FreeBSD_kernel__");
246  Builder.defineMacro("__GLIBC__");
247  Builder.defineMacro("__ELF__");
248  if (Opts.POSIXThreads)
249  Builder.defineMacro("_REENTRANT");
250  if (Opts.CPlusPlus)
251  Builder.defineMacro("_GNU_SOURCE");
252  }
253 
254 public:
255  KFreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
256  : OSTargetInfo<Target>(Triple, Opts) {}
257 };
258 
259 // Haiku Target
260 template <typename Target>
261 class LLVM_LIBRARY_VISIBILITY HaikuTargetInfo : public OSTargetInfo<Target> {
262 protected:
263  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
264  MacroBuilder &Builder) const override {
265  // Haiku defines; list based off of gcc output
266  Builder.defineMacro("__HAIKU__");
267  Builder.defineMacro("__ELF__");
268  DefineStd(Builder, "unix", Opts);
269  if (this->HasFloat128)
270  Builder.defineMacro("__FLOAT128__");
271  }
272 
273 public:
274  HaikuTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
275  : OSTargetInfo<Target>(Triple, Opts) {
276  this->SizeType = TargetInfo::UnsignedLong;
277  this->IntPtrType = TargetInfo::SignedLong;
278  this->PtrDiffType = TargetInfo::SignedLong;
279  this->ProcessIDType = TargetInfo::SignedLong;
280  this->TLSSupported = false;
281  switch (Triple.getArch()) {
282  default:
283  break;
284  case llvm::Triple::x86:
285  case llvm::Triple::x86_64:
286  this->HasFloat128 = true;
287  break;
288  }
289  }
290 };
291 
292 // Hurd target
293 template <typename Target>
294 class LLVM_LIBRARY_VISIBILITY HurdTargetInfo : public OSTargetInfo<Target> {
295 protected:
296  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
297  MacroBuilder &Builder) const override {
298  // Hurd defines; list based off of gcc output.
299  DefineStd(Builder, "unix", Opts);
300  Builder.defineMacro("__GNU__");
301  Builder.defineMacro("__gnu_hurd__");
302  Builder.defineMacro("__MACH__");
303  Builder.defineMacro("__GLIBC__");
304  Builder.defineMacro("__ELF__");
305  if (Opts.POSIXThreads)
306  Builder.defineMacro("_REENTRANT");
307  if (Opts.CPlusPlus)
308  Builder.defineMacro("_GNU_SOURCE");
309  }
310 public:
311  HurdTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
312  : OSTargetInfo<Target>(Triple, Opts) {}
313 };
314 
315 // Minix Target
316 template <typename Target>
317 class LLVM_LIBRARY_VISIBILITY MinixTargetInfo : public OSTargetInfo<Target> {
318 protected:
319  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
320  MacroBuilder &Builder) const override {
321  // Minix defines
322 
323  Builder.defineMacro("__minix", "3");
324  Builder.defineMacro("_EM_WSIZE", "4");
325  Builder.defineMacro("_EM_PSIZE", "4");
326  Builder.defineMacro("_EM_SSIZE", "2");
327  Builder.defineMacro("_EM_LSIZE", "4");
328  Builder.defineMacro("_EM_FSIZE", "4");
329  Builder.defineMacro("_EM_DSIZE", "8");
330  Builder.defineMacro("__ELF__");
331  DefineStd(Builder, "unix", Opts);
332  }
333 
334 public:
335  MinixTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
336  : OSTargetInfo<Target>(Triple, Opts) {}
337 };
338 
339 // Linux target
340 template <typename Target>
341 class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public OSTargetInfo<Target> {
342 protected:
343  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
344  MacroBuilder &Builder) const override {
345  // Linux defines; list based off of gcc output
346  DefineStd(Builder, "unix", Opts);
347  DefineStd(Builder, "linux", Opts);
348  Builder.defineMacro("__gnu_linux__");
349  Builder.defineMacro("__ELF__");
350  if (Triple.isAndroid()) {
351  Builder.defineMacro("__ANDROID__", "1");
352  unsigned Maj, Min, Rev;
353  Triple.getEnvironmentVersion(Maj, Min, Rev);
354  this->PlatformName = "android";
355  this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
356  if (Maj)
357  Builder.defineMacro("__ANDROID_API__", Twine(Maj));
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  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
767  MacroBuilder &Builder) const final {
768  // A common platform macro.
769  if (Opts.POSIXThreads)
770  Builder.defineMacro("_REENTRANT");
771  // Follow g++ convention and predefine _GNU_SOURCE for C++.
772  if (Opts.CPlusPlus)
773  Builder.defineMacro("_GNU_SOURCE");
774  }
775 
776 public:
777  explicit WebAssemblyOSTargetInfo(const llvm::Triple &Triple,
778  const TargetOptions &Opts)
779  : OSTargetInfo<Target>(Triple, Opts) {
780  this->MCountName = "__mcount";
781  this->TheCXXABI.set(TargetCXXABI::WebAssembly);
782  }
783 };
784 
785 } // namespace targets
786 } // namespace clang
787 #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:43
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:56
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:263
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:273
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:82
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:296
const char * getStaticInitSectionSpecifier() const override
Definition: OSTargets.h:127
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:777
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:184
LinuxTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:368
bool hasProtectedVisibility() const override
Darwin does not support protected visibility.
Definition: OSTargets.h:135
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
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:63
AnanasTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:71
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:343
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:240
void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:103
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:152
std::string isValidSectionSpecifier(StringRef SR) const override
Definition: OSTargets.h:118
KFreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:255
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:32
DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:89
HaikuTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:274
DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:164
FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:214
void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple, StringRef &PlatformName, VersionTuple &PlatformMinVersion)
Definition: OSTargets.cpp:23
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:503
#define FREEBSD_CC_VERSION
Definition: OSTargets.h:177
FuchsiaTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:756
CloudABITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:55
The WebAssembly ABI is a modified version of the Itanium ABI.
Definition: TargetCXXABI.h:105
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition: TargetInfo.h:157
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:319
HurdTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:311
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:335
OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:29
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:30
OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:435
PS3PPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:489
TargetInfo::IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final
Definition: OSTargets.h:137