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