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