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