clang  6.0.0
X86.h
Go to the documentation of this file.
1 //===--- X86.h - Declare X86 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 X86 TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
15 #define LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
16 
17 #include "OSTargets.h"
18 #include "clang/Basic/TargetInfo.h"
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/Support/Compiler.h"
22 
23 namespace clang {
24 namespace targets {
25 
26 // X86 target abstract base class; x86-32 and x86-64 are very close, so
27 // most of the implementation can be shared.
28 class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
29 
30  enum X86SSEEnum {
31  NoSSE,
32  SSE1,
33  SSE2,
34  SSE3,
35  SSSE3,
36  SSE41,
37  SSE42,
38  AVX,
39  AVX2,
40  AVX512F
41  } SSELevel = NoSSE;
42  enum MMX3DNowEnum {
43  NoMMX3DNow,
44  MMX,
45  AMD3DNow,
46  AMD3DNowAthlon
47  } MMX3DNowLevel = NoMMX3DNow;
48  enum XOPEnum { NoXOP, SSE4A, FMA4, XOP } XOPLevel = NoXOP;
49 
50  bool HasAES = false;
51  bool HasVAES = false;
52  bool HasPCLMUL = false;
53  bool HasVPCLMULQDQ = false;
54  bool HasGFNI = false;
55  bool HasLZCNT = false;
56  bool HasRDRND = false;
57  bool HasFSGSBASE = false;
58  bool HasBMI = false;
59  bool HasBMI2 = false;
60  bool HasPOPCNT = false;
61  bool HasRTM = false;
62  bool HasPRFCHW = false;
63  bool HasRDSEED = false;
64  bool HasADX = false;
65  bool HasTBM = false;
66  bool HasLWP = false;
67  bool HasFMA = false;
68  bool HasF16C = false;
69  bool HasAVX512CD = false;
70  bool HasAVX512VPOPCNTDQ = false;
71  bool HasAVX512VNNI = false;
72  bool HasAVX512ER = false;
73  bool HasAVX512PF = false;
74  bool HasAVX512DQ = false;
75  bool HasAVX512BITALG = false;
76  bool HasAVX512BW = false;
77  bool HasAVX512VL = false;
78  bool HasAVX512VBMI = false;
79  bool HasAVX512VBMI2 = false;
80  bool HasAVX512IFMA = false;
81  bool HasSHA = false;
82  bool HasMPX = false;
83  bool HasSHSTK = false;
84  bool HasIBT = false;
85  bool HasSGX = false;
86  bool HasCX16 = false;
87  bool HasFXSR = false;
88  bool HasXSAVE = false;
89  bool HasXSAVEOPT = false;
90  bool HasXSAVEC = false;
91  bool HasXSAVES = false;
92  bool HasMWAITX = false;
93  bool HasCLZERO = false;
94  bool HasPKU = false;
95  bool HasCLFLUSHOPT = false;
96  bool HasCLWB = false;
97  bool HasMOVBE = false;
98  bool HasPREFETCHWT1 = false;
99  bool HasRetpoline = false;
100  bool HasRetpolineExternalThunk = false;
101 
102  /// \brief Enumeration of all of the X86 CPUs supported by Clang.
103  ///
104  /// Each enumeration represents a particular CPU supported by Clang. These
105  /// loosely correspond to the options passed to '-march' or '-mtune' flags.
106  enum CPUKind {
107  CK_Generic,
108 #define PROC(ENUM, STRING, IS64BIT) CK_##ENUM,
109 #include "clang/Basic/X86Target.def"
110  } CPU = CK_Generic;
111 
112  bool checkCPUKind(CPUKind Kind) const;
113 
114  CPUKind getCPUKind(StringRef CPU) const;
115 
116  enum FPMathKind { FP_Default, FP_SSE, FP_387 } FPMath = FP_Default;
117 
118 public:
119  X86TargetInfo(const llvm::Triple &Triple, const TargetOptions &)
120  : TargetInfo(Triple) {
121  LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
122  }
123 
124  unsigned getFloatEvalMethod() const override {
125  // X87 evaluates with 80 bits "long double" precision.
126  return SSELevel == NoSSE ? 2 : 0;
127  }
128 
129  ArrayRef<const char *> getGCCRegNames() const override;
130 
132  return None;
133  }
134 
135  ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
136 
137  bool validateCpuSupports(StringRef Name) const override;
138 
139  bool validateCpuIs(StringRef Name) const override;
140 
141  bool validateAsmConstraint(const char *&Name,
142  TargetInfo::ConstraintInfo &info) const override;
143 
144  bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
145  bool &HasSizeMismatch) const override {
146  // esp and ebp are the only 32-bit registers the x86 backend can currently
147  // handle.
148  if (RegName.equals("esp") || RegName.equals("ebp")) {
149  // Check that the register size is 32-bit.
150  HasSizeMismatch = RegSize != 32;
151  return true;
152  }
153 
154  return false;
155  }
156 
157  bool validateOutputSize(StringRef Constraint, unsigned Size) const override;
158 
159  bool validateInputSize(StringRef Constraint, unsigned Size) const override;
160 
161  virtual bool validateOperandSize(StringRef Constraint, unsigned Size) const;
162 
163  std::string convertConstraint(const char *&Constraint) const override;
164  const char *getClobbers() const override {
165  return "~{dirflag},~{fpsr},~{flags}";
166  }
167 
168  StringRef getConstraintRegister(const StringRef &Constraint,
169  const StringRef &Expression) const override {
170  StringRef::iterator I, E;
171  for (I = Constraint.begin(), E = Constraint.end(); I != E; ++I) {
172  if (isalpha(*I))
173  break;
174  }
175  if (I == E)
176  return "";
177  switch (*I) {
178  // For the register constraints, return the matching register name
179  case 'a':
180  return "ax";
181  case 'b':
182  return "bx";
183  case 'c':
184  return "cx";
185  case 'd':
186  return "dx";
187  case 'S':
188  return "si";
189  case 'D':
190  return "di";
191  // In case the constraint is 'r' we need to return Expression
192  case 'r':
193  return Expression;
194  // Double letters Y<x> constraints
195  case 'Y':
196  if ((++I != E) && ((*I == '0') || (*I == 'z')))
197  return "xmm0";
198  default:
199  break;
200  }
201  return "";
202  }
203 
204  bool useFP16ConversionIntrinsics() const override {
205  return false;
206  }
207 
208  void getTargetDefines(const LangOptions &Opts,
209  MacroBuilder &Builder) const override;
210 
211  static void setSSELevel(llvm::StringMap<bool> &Features, X86SSEEnum Level,
212  bool Enabled);
213 
214  static void setMMXLevel(llvm::StringMap<bool> &Features, MMX3DNowEnum Level,
215  bool Enabled);
216 
217  static void setXOPLevel(llvm::StringMap<bool> &Features, XOPEnum Level,
218  bool Enabled);
219 
220  void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
221  bool Enabled) const override {
222  setFeatureEnabledImpl(Features, Name, Enabled);
223  }
224 
225  // This exists purely to cut down on the number of virtual calls in
226  // initFeatureMap which calls this repeatedly.
227  static void setFeatureEnabledImpl(llvm::StringMap<bool> &Features,
228  StringRef Name, bool Enabled);
229 
230  bool
231  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
232  StringRef CPU,
233  const std::vector<std::string> &FeaturesVec) const override;
234 
235  bool isValidFeatureName(StringRef Name) const override;
236 
237  bool hasFeature(StringRef Feature) const override;
238 
239  bool handleTargetFeatures(std::vector<std::string> &Features,
240  DiagnosticsEngine &Diags) override;
241 
242  StringRef getABI() const override {
243  if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX512F)
244  return "avx512";
245  if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX)
246  return "avx";
247  if (getTriple().getArch() == llvm::Triple::x86 &&
248  MMX3DNowLevel == NoMMX3DNow)
249  return "no-mmx";
250  return "";
251  }
252 
253  bool isValidCPUName(StringRef Name) const override {
254  return checkCPUKind(getCPUKind(Name));
255  }
256 
257  bool setCPU(const std::string &Name) override {
258  return checkCPUKind(CPU = getCPUKind(Name));
259  }
260 
261  bool setFPMath(StringRef Name) override;
262 
264  // Most of the non-ARM calling conventions are i386 conventions.
265  switch (CC) {
266  case CC_X86ThisCall:
267  case CC_X86FastCall:
268  case CC_X86StdCall:
269  case CC_X86VectorCall:
270  case CC_X86RegCall:
271  case CC_C:
272  case CC_Swift:
273  case CC_X86Pascal:
274  case CC_IntelOclBicc:
275  case CC_OpenCLKernel:
276  return CCCR_OK;
277  default:
278  return CCCR_Warning;
279  }
280  }
281 
283  return MT == CCMT_Member ? CC_X86ThisCall : CC_C;
284  }
285 
286  bool hasSjLjLowering() const override { return true; }
287 
288  void setSupportedOpenCLOpts() override {
289  getSupportedOpenCLOpts().supportAll();
290  }
291 };
292 
293 // X86-32 generic target
294 class LLVM_LIBRARY_VISIBILITY X86_32TargetInfo : public X86TargetInfo {
295 public:
296  X86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
297  : X86TargetInfo(Triple, Opts) {
298  DoubleAlign = LongLongAlign = 32;
299  LongDoubleWidth = 96;
300  LongDoubleAlign = 32;
301  SuitableAlign = 128;
302  resetDataLayout("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128");
303  SizeType = UnsignedInt;
304  PtrDiffType = SignedInt;
305  IntPtrType = SignedInt;
306  RegParmMax = 3;
307 
308  // Use fpret for all types.
309  RealTypeUsesObjCFPRet =
310  ((1 << TargetInfo::Float) | (1 << TargetInfo::Double) |
311  (1 << TargetInfo::LongDouble));
312 
313  // x86-32 has atomics up to 8 bytes
314  // FIXME: Check that we actually have cmpxchg8b before setting
315  // MaxAtomicInlineWidth. (cmpxchg8b is an i586 instruction.)
316  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
317  }
318 
321  }
322 
323  int getEHDataRegisterNumber(unsigned RegNo) const override {
324  if (RegNo == 0)
325  return 0;
326  if (RegNo == 1)
327  return 2;
328  return -1;
329  }
330 
331  bool validateOperandSize(StringRef Constraint, unsigned Size) const override {
332  switch (Constraint[0]) {
333  default:
334  break;
335  case 'R':
336  case 'q':
337  case 'Q':
338  case 'a':
339  case 'b':
340  case 'c':
341  case 'd':
342  case 'S':
343  case 'D':
344  return Size <= 32;
345  case 'A':
346  return Size <= 64;
347  }
348 
349  return X86TargetInfo::validateOperandSize(Constraint, Size);
350  }
351 
352  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
353 };
354 
355 class LLVM_LIBRARY_VISIBILITY NetBSDI386TargetInfo
356  : public NetBSDTargetInfo<X86_32TargetInfo> {
357 public:
358  NetBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
359  : NetBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) {}
360 
361  unsigned getFloatEvalMethod() const override {
362  unsigned Major, Minor, Micro;
363  getTriple().getOSVersion(Major, Minor, Micro);
364  // New NetBSD uses the default rounding mode.
365  if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 26) || Major == 0)
367  // NetBSD before 6.99.26 defaults to "double" rounding.
368  return 1;
369  }
370 };
371 
372 class LLVM_LIBRARY_VISIBILITY OpenBSDI386TargetInfo
373  : public OpenBSDTargetInfo<X86_32TargetInfo> {
374 public:
375  OpenBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
376  : OpenBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) {
377  SizeType = UnsignedLong;
378  IntPtrType = SignedLong;
379  PtrDiffType = SignedLong;
380  }
381 };
382 
383 class LLVM_LIBRARY_VISIBILITY DarwinI386TargetInfo
384  : public DarwinTargetInfo<X86_32TargetInfo> {
385 public:
386  DarwinI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
387  : DarwinTargetInfo<X86_32TargetInfo>(Triple, Opts) {
388  LongDoubleWidth = 128;
389  LongDoubleAlign = 128;
390  SuitableAlign = 128;
391  MaxVectorAlign = 256;
392  // The watchOS simulator uses the builtin bool type for Objective-C.
393  llvm::Triple T = llvm::Triple(Triple);
394  if (T.isWatchOS())
395  UseSignedCharForObjCBool = false;
396  SizeType = UnsignedLong;
397  IntPtrType = SignedLong;
398  resetDataLayout("e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128");
399  HasAlignMac68kSupport = true;
400  }
401 
402  bool handleTargetFeatures(std::vector<std::string> &Features,
403  DiagnosticsEngine &Diags) override {
405  Diags))
406  return false;
407  // We now know the features we have: we can decide how to align vectors.
408  MaxVectorAlign =
409  hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128;
410  return true;
411  }
412 };
413 
414 // x86-32 Windows target
415 class LLVM_LIBRARY_VISIBILITY WindowsX86_32TargetInfo
416  : public WindowsTargetInfo<X86_32TargetInfo> {
417 public:
418  WindowsX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
419  : WindowsTargetInfo<X86_32TargetInfo>(Triple, Opts) {
420  DoubleAlign = LongLongAlign = 64;
421  bool IsWinCOFF =
422  getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
423  resetDataLayout(IsWinCOFF
424  ? "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
425  : "e-m:e-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32");
426  }
427 };
428 
429 // x86-32 Windows Visual Studio target
430 class LLVM_LIBRARY_VISIBILITY MicrosoftX86_32TargetInfo
431  : public WindowsX86_32TargetInfo {
432 public:
433  MicrosoftX86_32TargetInfo(const llvm::Triple &Triple,
434  const TargetOptions &Opts)
435  : WindowsX86_32TargetInfo(Triple, Opts) {
436  LongDoubleWidth = LongDoubleAlign = 64;
437  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
438  }
439 
440  void getTargetDefines(const LangOptions &Opts,
441  MacroBuilder &Builder) const override {
444  // The value of the following reflects processor type.
445  // 300=386, 400=486, 500=Pentium, 600=Blend (default)
446  // We lost the original triple, so we use the default.
447  Builder.defineMacro("_M_IX86", "600");
448  }
449 };
450 
451 // x86-32 MinGW target
452 class LLVM_LIBRARY_VISIBILITY MinGWX86_32TargetInfo
453  : public WindowsX86_32TargetInfo {
454 public:
455  MinGWX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
456  : WindowsX86_32TargetInfo(Triple, Opts) {
457  HasFloat128 = true;
458  }
459 
460  void getTargetDefines(const LangOptions &Opts,
461  MacroBuilder &Builder) const override {
463  Builder.defineMacro("_X86_");
464  }
465 };
466 
467 // x86-32 Cygwin target
468 class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : public X86_32TargetInfo {
469 public:
470  CygwinX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
471  : X86_32TargetInfo(Triple, Opts) {
472  this->WCharType = TargetInfo::UnsignedShort;
473  DoubleAlign = LongLongAlign = 64;
474  resetDataLayout("e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32");
475  }
476 
477  void getTargetDefines(const LangOptions &Opts,
478  MacroBuilder &Builder) const override {
479  X86_32TargetInfo::getTargetDefines(Opts, Builder);
480  Builder.defineMacro("_X86_");
481  Builder.defineMacro("__CYGWIN__");
482  Builder.defineMacro("__CYGWIN32__");
483  addCygMingDefines(Opts, Builder);
484  DefineStd(Builder, "unix", Opts);
485  if (Opts.CPlusPlus)
486  Builder.defineMacro("_GNU_SOURCE");
487  }
488 };
489 
490 // x86-32 Haiku target
491 class LLVM_LIBRARY_VISIBILITY HaikuX86_32TargetInfo
492  : public HaikuTargetInfo<X86_32TargetInfo> {
493 public:
494  HaikuX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
495  : HaikuTargetInfo<X86_32TargetInfo>(Triple, Opts) {}
496 
497  void getTargetDefines(const LangOptions &Opts,
498  MacroBuilder &Builder) const override {
500  Builder.defineMacro("__INTEL__");
501  }
502 };
503 
504 // X86-32 MCU target
505 class LLVM_LIBRARY_VISIBILITY MCUX86_32TargetInfo : public X86_32TargetInfo {
506 public:
507  MCUX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
508  : X86_32TargetInfo(Triple, Opts) {
509  LongDoubleWidth = 64;
510  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
511  resetDataLayout("e-m:e-p:32:32-i64:32-f64:32-f128:32-n8:16:32-a:0:32-S32");
512  WIntType = UnsignedInt;
513  }
514 
516  // On MCU we support only C calling convention.
517  return CC == CC_C ? CCCR_OK : CCCR_Warning;
518  }
519 
520  void getTargetDefines(const LangOptions &Opts,
521  MacroBuilder &Builder) const override {
522  X86_32TargetInfo::getTargetDefines(Opts, Builder);
523  Builder.defineMacro("__iamcu");
524  Builder.defineMacro("__iamcu__");
525  }
526 
527  bool allowsLargerPreferedTypeAlignment() const override { return false; }
528 };
529 
530 // x86-32 RTEMS target
531 class LLVM_LIBRARY_VISIBILITY RTEMSX86_32TargetInfo : public X86_32TargetInfo {
532 public:
533  RTEMSX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
534  : X86_32TargetInfo(Triple, Opts) {
535  SizeType = UnsignedLong;
536  IntPtrType = SignedLong;
537  PtrDiffType = SignedLong;
538  }
539 
540  void getTargetDefines(const LangOptions &Opts,
541  MacroBuilder &Builder) const override {
542  X86_32TargetInfo::getTargetDefines(Opts, Builder);
543  Builder.defineMacro("__INTEL__");
544  Builder.defineMacro("__rtems__");
545  }
546 };
547 
548 // x86-64 generic target
549 class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo {
550 public:
551  X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
552  : X86TargetInfo(Triple, Opts) {
553  const bool IsX32 = getTriple().getEnvironment() == llvm::Triple::GNUX32;
554  bool IsWinCOFF =
555  getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
556  LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64;
557  LongDoubleWidth = 128;
558  LongDoubleAlign = 128;
559  LargeArrayMinWidth = 128;
560  LargeArrayAlign = 128;
561  SuitableAlign = 128;
562  SizeType = IsX32 ? UnsignedInt : UnsignedLong;
563  PtrDiffType = IsX32 ? SignedInt : SignedLong;
564  IntPtrType = IsX32 ? SignedInt : SignedLong;
565  IntMaxType = IsX32 ? SignedLongLong : SignedLong;
566  Int64Type = IsX32 ? SignedLongLong : SignedLong;
567  RegParmMax = 6;
568 
569  // Pointers are 32-bit in x32.
570  resetDataLayout(IsX32
571  ? "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128"
572  : IsWinCOFF ? "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
573  : "e-m:e-i64:64-f80:128-n8:16:32:64-S128");
574 
575  // Use fpret only for long double.
576  RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
577 
578  // Use fp2ret for _Complex long double.
579  ComplexLongDoubleUsesFP2Ret = true;
580 
581  // Make __builtin_ms_va_list available.
582  HasBuiltinMSVaList = true;
583 
584  // x86-64 has atomics up to 16 bytes.
585  MaxAtomicPromoteWidth = 128;
586  MaxAtomicInlineWidth = 64;
587  }
588 
591  }
592 
593  int getEHDataRegisterNumber(unsigned RegNo) const override {
594  if (RegNo == 0)
595  return 0;
596  if (RegNo == 1)
597  return 1;
598  return -1;
599  }
600 
602  switch (CC) {
603  case CC_C:
604  case CC_Swift:
605  case CC_X86VectorCall:
606  case CC_IntelOclBicc:
607  case CC_Win64:
608  case CC_PreserveMost:
609  case CC_PreserveAll:
610  case CC_X86RegCall:
611  case CC_OpenCLKernel:
612  return CCCR_OK;
613  default:
614  return CCCR_Warning;
615  }
616  }
617 
619  return CC_C;
620  }
621 
622  // for x32 we need it here explicitly
623  bool hasInt128Type() const override { return true; }
624 
625  unsigned getUnwindWordWidth() const override { return 64; }
626 
627  unsigned getRegisterWidth() const override { return 64; }
628 
629  bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
630  bool &HasSizeMismatch) const override {
631  // rsp and rbp are the only 64-bit registers the x86 backend can currently
632  // handle.
633  if (RegName.equals("rsp") || RegName.equals("rbp")) {
634  // Check that the register size is 64-bit.
635  HasSizeMismatch = RegSize != 64;
636  return true;
637  }
638 
639  // Check if the register is a 32-bit register the backend can handle.
640  return X86TargetInfo::validateGlobalRegisterVariable(RegName, RegSize,
641  HasSizeMismatch);
642  }
643 
644  void setMaxAtomicWidth() override {
645  if (hasFeature("cx16"))
646  MaxAtomicInlineWidth = 128;
647  }
648 
649  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
650 };
651 
652 // x86-64 Windows target
653 class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
654  : public WindowsTargetInfo<X86_64TargetInfo> {
655 public:
656  WindowsX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
657  : WindowsTargetInfo<X86_64TargetInfo>(Triple, Opts) {
658  LongWidth = LongAlign = 32;
659  DoubleAlign = LongLongAlign = 64;
660  IntMaxType = SignedLongLong;
661  Int64Type = SignedLongLong;
662  SizeType = UnsignedLongLong;
663  PtrDiffType = SignedLongLong;
664  IntPtrType = SignedLongLong;
665  }
666 
669  }
670 
672  switch (CC) {
673  case CC_X86StdCall:
674  case CC_X86ThisCall:
675  case CC_X86FastCall:
676  return CCCR_Ignore;
677  case CC_C:
678  case CC_X86VectorCall:
679  case CC_IntelOclBicc:
680  case CC_PreserveMost:
681  case CC_PreserveAll:
682  case CC_X86_64SysV:
683  case CC_Swift:
684  case CC_X86RegCall:
685  case CC_OpenCLKernel:
686  return CCCR_OK;
687  default:
688  return CCCR_Warning;
689  }
690  }
691 };
692 
693 // x86-64 Windows Visual Studio target
694 class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64TargetInfo
695  : public WindowsX86_64TargetInfo {
696 public:
697  MicrosoftX86_64TargetInfo(const llvm::Triple &Triple,
698  const TargetOptions &Opts)
699  : WindowsX86_64TargetInfo(Triple, Opts) {
700  LongDoubleWidth = LongDoubleAlign = 64;
701  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
702  }
703 
704  void getTargetDefines(const LangOptions &Opts,
705  MacroBuilder &Builder) const override {
708  Builder.defineMacro("_M_X64", "100");
709  Builder.defineMacro("_M_AMD64", "100");
710  }
711 };
712 
713 // x86-64 MinGW target
714 class LLVM_LIBRARY_VISIBILITY MinGWX86_64TargetInfo
715  : public WindowsX86_64TargetInfo {
716 public:
717  MinGWX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
718  : WindowsX86_64TargetInfo(Triple, Opts) {
719  // Mingw64 rounds long double size and alignment up to 16 bytes, but sticks
720  // with x86 FP ops. Weird.
721  LongDoubleWidth = LongDoubleAlign = 128;
722  LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
723  HasFloat128 = true;
724  }
725 };
726 
727 // x86-64 Cygwin target
728 class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
729 public:
730  CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
731  : X86_64TargetInfo(Triple, Opts) {
732  this->WCharType = TargetInfo::UnsignedShort;
733  TLSSupported = false;
734  }
735 
736  void getTargetDefines(const LangOptions &Opts,
737  MacroBuilder &Builder) const override {
738  X86_64TargetInfo::getTargetDefines(Opts, Builder);
739  Builder.defineMacro("__x86_64__");
740  Builder.defineMacro("__CYGWIN__");
741  Builder.defineMacro("__CYGWIN64__");
742  addCygMingDefines(Opts, Builder);
743  DefineStd(Builder, "unix", Opts);
744  if (Opts.CPlusPlus)
745  Builder.defineMacro("_GNU_SOURCE");
746  }
747 };
748 
749 class LLVM_LIBRARY_VISIBILITY DarwinX86_64TargetInfo
750  : public DarwinTargetInfo<X86_64TargetInfo> {
751 public:
752  DarwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
753  : DarwinTargetInfo<X86_64TargetInfo>(Triple, Opts) {
754  Int64Type = SignedLongLong;
755  // The 64-bit iOS simulator uses the builtin bool type for Objective-C.
756  llvm::Triple T = llvm::Triple(Triple);
757  if (T.isiOS())
758  UseSignedCharForObjCBool = false;
759  resetDataLayout("e-m:o-i64:64-f80:128-n8:16:32:64-S128");
760  }
761 
762  bool handleTargetFeatures(std::vector<std::string> &Features,
763  DiagnosticsEngine &Diags) override {
765  Diags))
766  return false;
767  // We now know the features we have: we can decide how to align vectors.
768  MaxVectorAlign =
769  hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128;
770  return true;
771  }
772 };
773 
774 class LLVM_LIBRARY_VISIBILITY OpenBSDX86_64TargetInfo
775  : public OpenBSDTargetInfo<X86_64TargetInfo> {
776 public:
777  OpenBSDX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
778  : OpenBSDTargetInfo<X86_64TargetInfo>(Triple, Opts) {
779  IntMaxType = SignedLongLong;
780  Int64Type = SignedLongLong;
781  }
782 };
783 
784 // x86_32 Android target
785 class LLVM_LIBRARY_VISIBILITY AndroidX86_32TargetInfo
786  : public LinuxTargetInfo<X86_32TargetInfo> {
787 public:
788  AndroidX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
789  : LinuxTargetInfo<X86_32TargetInfo>(Triple, Opts) {
790  SuitableAlign = 32;
791  LongDoubleWidth = 64;
792  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
793  }
794 };
795 
796 // x86_64 Android target
797 class LLVM_LIBRARY_VISIBILITY AndroidX86_64TargetInfo
798  : public LinuxTargetInfo<X86_64TargetInfo> {
799 public:
800  AndroidX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
801  : LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts) {
802  LongDoubleFormat = &llvm::APFloat::IEEEquad();
803  }
804 
805  bool useFloat128ManglingForLongDouble() const override { return true; }
806 };
807 } // namespace targets
808 } // namespace clang
809 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: X86.h:164
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition: X86.h:644
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:53
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.h:440
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.h:497
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: X86.h:601
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature...
Definition: Module.cpp:73
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: X86.h:253
unsigned getUnwindWordWidth() const override
Definition: X86.h:625
__builtin_va_list as defined by the x86-64 ABI: http://refspecs.linuxbase.org/elf/x86_64-abi-0.21.pdf
Definition: TargetInfo.h:174
X86TargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: X86.h:119
Options for controlling the target.
Definition: TargetOptions.h:26
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.h:736
virtual bool validateOperandSize(StringRef Constraint, unsigned Size) const
Definition: X86.cpp:1466
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.h:540
bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const override
Validate register name used for global register variables.
Definition: X86.h:629
WindowsX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:656
AndroidX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:788
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument...
Definition: X86.h:323
bool useFloat128ManglingForLongDouble() const override
Return true if the &#39;long double&#39; type should be mangled like __float128.
Definition: X86.h:805
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
unsigned getFloatEvalMethod() const override
Return the value for the C99 FLT_EVAL_METHOD macro.
Definition: X86.h:361
MicrosoftX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:697
CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:730
X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:551
DarwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:752
CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override
Gets the default calling convention for the given target and declaration context. ...
Definition: X86.h:618
StringRef getConstraintRegister(const StringRef &Constraint, const StringRef &Expression) const override
Definition: X86.h:168
MicrosoftX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:433
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
unsigned getRegisterWidth() const override
Return the "preferred" register width on this target.
Definition: X86.h:627
bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const override
Validate register name used for global register variables.
Definition: X86.h:144
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: X86.h:671
bool allowsLargerPreferedTypeAlignment() const override
Whether target allows to overalign ABI-specified preferred alignment.
Definition: X86.h:527
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.h:477
Exposes information about the current target.
Definition: TargetInfo.h:54
AndroidX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:800
const FunctionProtoType * T
void getVisualStudioDefines(const LangOptions &Opts, MacroBuilder &Builder) const
Definition: OSTargets.h:570
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: OSTargets.h:32
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: X86.h:319
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:233
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: X86.h:515
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: X86.h:263
HaikuX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:494
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: X86.h:131
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: X86.h:257
Kind
StringRef getABI() const override
Get the ABI currently in use.
Definition: X86.h:242
void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:76
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.h:520
NetBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:358
Defines the clang::TargetOptions class.
CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override
Gets the default calling convention for the given target and declaration context. ...
Definition: X86.h:282
RTEMSX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:533
bool useFP16ConversionIntrinsics() const override
Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used to convert to and from __fp...
Definition: X86.h:204
OpenBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:375
Dataflow Directional Tag Classes.
typedef char* __builtin_va_list;
Definition: TargetInfo.h:154
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: X86.h:667
bool validateOperandSize(StringRef Constraint, unsigned Size) const override
Definition: X86.h:331
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: X86.h:589
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.cpp:817
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument...
Definition: X86.h:593
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
handleTargetFeatures - Perform initialization based on the user configured set of features...
Definition: X86.h:762
bool hasSjLjLowering() const override
Controls if __builtin_longjmp / __builtin_setjmp can be lowered to llvm.eh.sjlj.longjmp / llvm...
Definition: X86.h:286
unsigned getFloatEvalMethod() const override
Return the value for the C99 FLT_EVAL_METHOD macro.
Definition: X86.h:124
MCUX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:507
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:152
WindowsX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:418
bool hasInt128Type() const override
Determine whether the __int128 type is supported on this target.
Definition: X86.h:623
void setSupportedOpenCLOpts() override
Set supported OpenCL extensions and optional core features.
Definition: X86.h:288
MinGWX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:717
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.h:460
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro definitions for this parti...
Definition: X86.h:704
Defines the clang::TargetInfo interface.
void setFeatureEnabled(llvm::StringMap< bool > &Features, StringRef Name, bool Enabled) const override
Enable or disable a specific target feature; the feature name must be valid.
Definition: X86.h:220
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
handleTargetFeatures - Perform initialization based on the user configured set of features...
Definition: X86.h:402
CygwinX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:470
OpenBSDX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:777
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
MinGWX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:455
X86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:296
DarwinI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: X86.h:386