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