xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/X86.h (revision 480093f4440d54b30b3025afeac24b48f2ba7a2e)
10b57cec5SDimitry Andric //===--- X86.h - Declare X86 target feature support -------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file declares X86 TargetInfo objects.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
140b57cec5SDimitry Andric #define LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "OSTargets.h"
170b57cec5SDimitry Andric #include "clang/Basic/TargetInfo.h"
180b57cec5SDimitry Andric #include "clang/Basic/TargetOptions.h"
190b57cec5SDimitry Andric #include "llvm/ADT/Triple.h"
200b57cec5SDimitry Andric #include "llvm/Support/Compiler.h"
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric namespace clang {
230b57cec5SDimitry Andric namespace targets {
240b57cec5SDimitry Andric 
25*480093f4SDimitry Andric static const unsigned X86AddrSpaceMap[] = {
26*480093f4SDimitry Andric     0,   // Default
27*480093f4SDimitry Andric     0,   // opencl_global
28*480093f4SDimitry Andric     0,   // opencl_local
29*480093f4SDimitry Andric     0,   // opencl_constant
30*480093f4SDimitry Andric     0,   // opencl_private
31*480093f4SDimitry Andric     0,   // opencl_generic
32*480093f4SDimitry Andric     0,   // cuda_device
33*480093f4SDimitry Andric     0,   // cuda_constant
34*480093f4SDimitry Andric     0,   // cuda_shared
35*480093f4SDimitry Andric     270, // ptr32_sptr
36*480093f4SDimitry Andric     271, // ptr32_uptr
37*480093f4SDimitry Andric     272  // ptr64
38*480093f4SDimitry Andric };
39*480093f4SDimitry Andric 
400b57cec5SDimitry Andric // X86 target abstract base class; x86-32 and x86-64 are very close, so
410b57cec5SDimitry Andric // most of the implementation can be shared.
420b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric   enum X86SSEEnum {
450b57cec5SDimitry Andric     NoSSE,
460b57cec5SDimitry Andric     SSE1,
470b57cec5SDimitry Andric     SSE2,
480b57cec5SDimitry Andric     SSE3,
490b57cec5SDimitry Andric     SSSE3,
500b57cec5SDimitry Andric     SSE41,
510b57cec5SDimitry Andric     SSE42,
520b57cec5SDimitry Andric     AVX,
530b57cec5SDimitry Andric     AVX2,
540b57cec5SDimitry Andric     AVX512F
550b57cec5SDimitry Andric   } SSELevel = NoSSE;
560b57cec5SDimitry Andric   enum MMX3DNowEnum {
570b57cec5SDimitry Andric     NoMMX3DNow,
580b57cec5SDimitry Andric     MMX,
590b57cec5SDimitry Andric     AMD3DNow,
600b57cec5SDimitry Andric     AMD3DNowAthlon
610b57cec5SDimitry Andric   } MMX3DNowLevel = NoMMX3DNow;
620b57cec5SDimitry Andric   enum XOPEnum { NoXOP, SSE4A, FMA4, XOP } XOPLevel = NoXOP;
63*480093f4SDimitry Andric   enum AddrSpace { ptr32_sptr = 270, ptr32_uptr = 271, ptr64 = 272 };
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric   bool HasAES = false;
660b57cec5SDimitry Andric   bool HasVAES = false;
670b57cec5SDimitry Andric   bool HasPCLMUL = false;
680b57cec5SDimitry Andric   bool HasVPCLMULQDQ = false;
690b57cec5SDimitry Andric   bool HasGFNI = false;
700b57cec5SDimitry Andric   bool HasLZCNT = false;
710b57cec5SDimitry Andric   bool HasRDRND = false;
720b57cec5SDimitry Andric   bool HasFSGSBASE = false;
730b57cec5SDimitry Andric   bool HasBMI = false;
740b57cec5SDimitry Andric   bool HasBMI2 = false;
750b57cec5SDimitry Andric   bool HasPOPCNT = false;
760b57cec5SDimitry Andric   bool HasRTM = false;
770b57cec5SDimitry Andric   bool HasPRFCHW = false;
780b57cec5SDimitry Andric   bool HasRDSEED = false;
790b57cec5SDimitry Andric   bool HasADX = false;
800b57cec5SDimitry Andric   bool HasTBM = false;
810b57cec5SDimitry Andric   bool HasLWP = false;
820b57cec5SDimitry Andric   bool HasFMA = false;
830b57cec5SDimitry Andric   bool HasF16C = false;
840b57cec5SDimitry Andric   bool HasAVX512CD = false;
850b57cec5SDimitry Andric   bool HasAVX512VPOPCNTDQ = false;
860b57cec5SDimitry Andric   bool HasAVX512VNNI = false;
870b57cec5SDimitry Andric   bool HasAVX512BF16 = false;
880b57cec5SDimitry Andric   bool HasAVX512ER = false;
890b57cec5SDimitry Andric   bool HasAVX512PF = false;
900b57cec5SDimitry Andric   bool HasAVX512DQ = false;
910b57cec5SDimitry Andric   bool HasAVX512BITALG = false;
920b57cec5SDimitry Andric   bool HasAVX512BW = false;
930b57cec5SDimitry Andric   bool HasAVX512VL = false;
940b57cec5SDimitry Andric   bool HasAVX512VBMI = false;
950b57cec5SDimitry Andric   bool HasAVX512VBMI2 = false;
960b57cec5SDimitry Andric   bool HasAVX512IFMA = false;
970b57cec5SDimitry Andric   bool HasAVX512VP2INTERSECT = false;
980b57cec5SDimitry Andric   bool HasSHA = false;
990b57cec5SDimitry Andric   bool HasSHSTK = false;
1000b57cec5SDimitry Andric   bool HasSGX = false;
1010b57cec5SDimitry Andric   bool HasCX8 = false;
1020b57cec5SDimitry Andric   bool HasCX16 = false;
1030b57cec5SDimitry Andric   bool HasFXSR = false;
1040b57cec5SDimitry Andric   bool HasXSAVE = false;
1050b57cec5SDimitry Andric   bool HasXSAVEOPT = false;
1060b57cec5SDimitry Andric   bool HasXSAVEC = false;
1070b57cec5SDimitry Andric   bool HasXSAVES = false;
1080b57cec5SDimitry Andric   bool HasMWAITX = false;
1090b57cec5SDimitry Andric   bool HasCLZERO = false;
1100b57cec5SDimitry Andric   bool HasCLDEMOTE = false;
1110b57cec5SDimitry Andric   bool HasPCONFIG = false;
1120b57cec5SDimitry Andric   bool HasPKU = false;
1130b57cec5SDimitry Andric   bool HasCLFLUSHOPT = false;
1140b57cec5SDimitry Andric   bool HasCLWB = false;
1150b57cec5SDimitry Andric   bool HasMOVBE = false;
1160b57cec5SDimitry Andric   bool HasPREFETCHWT1 = false;
1170b57cec5SDimitry Andric   bool HasRDPID = false;
1180b57cec5SDimitry Andric   bool HasRetpolineExternalThunk = false;
1190b57cec5SDimitry Andric   bool HasLAHFSAHF = false;
1200b57cec5SDimitry Andric   bool HasWBNOINVD = false;
1210b57cec5SDimitry Andric   bool HasWAITPKG = false;
1220b57cec5SDimitry Andric   bool HasMOVDIRI = false;
1230b57cec5SDimitry Andric   bool HasMOVDIR64B = false;
1240b57cec5SDimitry Andric   bool HasPTWRITE = false;
1250b57cec5SDimitry Andric   bool HasINVPCID = false;
1260b57cec5SDimitry Andric   bool HasENQCMD = false;
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric protected:
1290b57cec5SDimitry Andric   /// Enumeration of all of the X86 CPUs supported by Clang.
1300b57cec5SDimitry Andric   ///
1310b57cec5SDimitry Andric   /// Each enumeration represents a particular CPU supported by Clang. These
1320b57cec5SDimitry Andric   /// loosely correspond to the options passed to '-march' or '-mtune' flags.
1330b57cec5SDimitry Andric   enum CPUKind {
1340b57cec5SDimitry Andric     CK_Generic,
1350b57cec5SDimitry Andric #define PROC(ENUM, STRING, IS64BIT) CK_##ENUM,
1360b57cec5SDimitry Andric #include "clang/Basic/X86Target.def"
1370b57cec5SDimitry Andric   } CPU = CK_Generic;
1380b57cec5SDimitry Andric 
1390b57cec5SDimitry Andric   bool checkCPUKind(CPUKind Kind) const;
1400b57cec5SDimitry Andric 
1410b57cec5SDimitry Andric   CPUKind getCPUKind(StringRef CPU) const;
1420b57cec5SDimitry Andric 
1430b57cec5SDimitry Andric   enum FPMathKind { FP_Default, FP_SSE, FP_387 } FPMath = FP_Default;
1440b57cec5SDimitry Andric 
1450b57cec5SDimitry Andric public:
1460b57cec5SDimitry Andric   X86TargetInfo(const llvm::Triple &Triple, const TargetOptions &)
1470b57cec5SDimitry Andric       : TargetInfo(Triple) {
1480b57cec5SDimitry Andric     LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
149*480093f4SDimitry Andric     AddrSpaceMap = &X86AddrSpaceMap;
1500b57cec5SDimitry Andric   }
1510b57cec5SDimitry Andric 
1520b57cec5SDimitry Andric   const char *getLongDoubleMangling() const override {
1530b57cec5SDimitry Andric     return LongDoubleFormat == &llvm::APFloat::IEEEquad() ? "g" : "e";
1540b57cec5SDimitry Andric   }
1550b57cec5SDimitry Andric 
1560b57cec5SDimitry Andric   unsigned getFloatEvalMethod() const override {
1570b57cec5SDimitry Andric     // X87 evaluates with 80 bits "long double" precision.
1580b57cec5SDimitry Andric     return SSELevel == NoSSE ? 2 : 0;
1590b57cec5SDimitry Andric   }
1600b57cec5SDimitry Andric 
1610b57cec5SDimitry Andric   ArrayRef<const char *> getGCCRegNames() const override;
1620b57cec5SDimitry Andric 
1630b57cec5SDimitry Andric   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
1640b57cec5SDimitry Andric     return None;
1650b57cec5SDimitry Andric   }
1660b57cec5SDimitry Andric 
1670b57cec5SDimitry Andric   ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
1680b57cec5SDimitry Andric 
1690b57cec5SDimitry Andric   bool validateCpuSupports(StringRef Name) const override;
1700b57cec5SDimitry Andric 
1710b57cec5SDimitry Andric   bool validateCpuIs(StringRef Name) const override;
1720b57cec5SDimitry Andric 
1730b57cec5SDimitry Andric   bool validateCPUSpecificCPUDispatch(StringRef Name) const override;
1740b57cec5SDimitry Andric 
1750b57cec5SDimitry Andric   char CPUSpecificManglingCharacter(StringRef Name) const override;
1760b57cec5SDimitry Andric 
1770b57cec5SDimitry Andric   void getCPUSpecificCPUDispatchFeatures(
1780b57cec5SDimitry Andric       StringRef Name,
1790b57cec5SDimitry Andric       llvm::SmallVectorImpl<StringRef> &Features) const override;
1800b57cec5SDimitry Andric 
1810b57cec5SDimitry Andric   bool validateAsmConstraint(const char *&Name,
1820b57cec5SDimitry Andric                              TargetInfo::ConstraintInfo &info) const override;
1830b57cec5SDimitry Andric 
1840b57cec5SDimitry Andric   bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
1850b57cec5SDimitry Andric                                       bool &HasSizeMismatch) const override {
1860b57cec5SDimitry Andric     // esp and ebp are the only 32-bit registers the x86 backend can currently
1870b57cec5SDimitry Andric     // handle.
1880b57cec5SDimitry Andric     if (RegName.equals("esp") || RegName.equals("ebp")) {
1890b57cec5SDimitry Andric       // Check that the register size is 32-bit.
1900b57cec5SDimitry Andric       HasSizeMismatch = RegSize != 32;
1910b57cec5SDimitry Andric       return true;
1920b57cec5SDimitry Andric     }
1930b57cec5SDimitry Andric 
1940b57cec5SDimitry Andric     return false;
1950b57cec5SDimitry Andric   }
1960b57cec5SDimitry Andric 
197*480093f4SDimitry Andric   bool validateOutputSize(const llvm::StringMap<bool> &FeatureMap,
198*480093f4SDimitry Andric                           StringRef Constraint, unsigned Size) const override;
1990b57cec5SDimitry Andric 
200*480093f4SDimitry Andric   bool validateInputSize(const llvm::StringMap<bool> &FeatureMap,
201*480093f4SDimitry Andric                          StringRef Constraint, unsigned Size) const override;
2020b57cec5SDimitry Andric 
2030b57cec5SDimitry Andric   virtual bool
2040b57cec5SDimitry Andric   checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
2050b57cec5SDimitry Andric     return true;
2060b57cec5SDimitry Andric   };
2070b57cec5SDimitry Andric 
2080b57cec5SDimitry Andric   virtual bool
2090b57cec5SDimitry Andric   checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
2100b57cec5SDimitry Andric     return true;
2110b57cec5SDimitry Andric   };
2120b57cec5SDimitry Andric 
213*480093f4SDimitry Andric   virtual bool validateOperandSize(const llvm::StringMap<bool> &FeatureMap,
214*480093f4SDimitry Andric                                    StringRef Constraint, unsigned Size) const;
2150b57cec5SDimitry Andric 
2160b57cec5SDimitry Andric   std::string convertConstraint(const char *&Constraint) const override;
2170b57cec5SDimitry Andric   const char *getClobbers() const override {
2180b57cec5SDimitry Andric     return "~{dirflag},~{fpsr},~{flags}";
2190b57cec5SDimitry Andric   }
2200b57cec5SDimitry Andric 
2210b57cec5SDimitry Andric   StringRef getConstraintRegister(StringRef Constraint,
2220b57cec5SDimitry Andric                                   StringRef Expression) const override {
2230b57cec5SDimitry Andric     StringRef::iterator I, E;
2240b57cec5SDimitry Andric     for (I = Constraint.begin(), E = Constraint.end(); I != E; ++I) {
2250b57cec5SDimitry Andric       if (isalpha(*I) || *I == '@')
2260b57cec5SDimitry Andric         break;
2270b57cec5SDimitry Andric     }
2280b57cec5SDimitry Andric     if (I == E)
2290b57cec5SDimitry Andric       return "";
2300b57cec5SDimitry Andric     switch (*I) {
2310b57cec5SDimitry Andric     // For the register constraints, return the matching register name
2320b57cec5SDimitry Andric     case 'a':
2330b57cec5SDimitry Andric       return "ax";
2340b57cec5SDimitry Andric     case 'b':
2350b57cec5SDimitry Andric       return "bx";
2360b57cec5SDimitry Andric     case 'c':
2370b57cec5SDimitry Andric       return "cx";
2380b57cec5SDimitry Andric     case 'd':
2390b57cec5SDimitry Andric       return "dx";
2400b57cec5SDimitry Andric     case 'S':
2410b57cec5SDimitry Andric       return "si";
2420b57cec5SDimitry Andric     case 'D':
2430b57cec5SDimitry Andric       return "di";
2440b57cec5SDimitry Andric     // In case the constraint is 'r' we need to return Expression
2450b57cec5SDimitry Andric     case 'r':
2460b57cec5SDimitry Andric       return Expression;
2470b57cec5SDimitry Andric     // Double letters Y<x> constraints
2480b57cec5SDimitry Andric     case 'Y':
2490b57cec5SDimitry Andric       if ((++I != E) && ((*I == '0') || (*I == 'z')))
2500b57cec5SDimitry Andric         return "xmm0";
2510b57cec5SDimitry Andric       break;
2520b57cec5SDimitry Andric     default:
2530b57cec5SDimitry Andric       break;
2540b57cec5SDimitry Andric     }
2550b57cec5SDimitry Andric     return "";
2560b57cec5SDimitry Andric   }
2570b57cec5SDimitry Andric 
2580b57cec5SDimitry Andric   bool useFP16ConversionIntrinsics() const override {
2590b57cec5SDimitry Andric     return false;
2600b57cec5SDimitry Andric   }
2610b57cec5SDimitry Andric 
2620b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
2630b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
2640b57cec5SDimitry Andric 
2650b57cec5SDimitry Andric   static void setSSELevel(llvm::StringMap<bool> &Features, X86SSEEnum Level,
2660b57cec5SDimitry Andric                           bool Enabled);
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric   static void setMMXLevel(llvm::StringMap<bool> &Features, MMX3DNowEnum Level,
2690b57cec5SDimitry Andric                           bool Enabled);
2700b57cec5SDimitry Andric 
2710b57cec5SDimitry Andric   static void setXOPLevel(llvm::StringMap<bool> &Features, XOPEnum Level,
2720b57cec5SDimitry Andric                           bool Enabled);
2730b57cec5SDimitry Andric 
2740b57cec5SDimitry Andric   void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
2750b57cec5SDimitry Andric                          bool Enabled) const override {
2760b57cec5SDimitry Andric     setFeatureEnabledImpl(Features, Name, Enabled);
2770b57cec5SDimitry Andric   }
2780b57cec5SDimitry Andric 
2790b57cec5SDimitry Andric   // This exists purely to cut down on the number of virtual calls in
2800b57cec5SDimitry Andric   // initFeatureMap which calls this repeatedly.
2810b57cec5SDimitry Andric   static void setFeatureEnabledImpl(llvm::StringMap<bool> &Features,
2820b57cec5SDimitry Andric                                     StringRef Name, bool Enabled);
2830b57cec5SDimitry Andric 
2840b57cec5SDimitry Andric   bool
2850b57cec5SDimitry Andric   initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
2860b57cec5SDimitry Andric                  StringRef CPU,
2870b57cec5SDimitry Andric                  const std::vector<std::string> &FeaturesVec) const override;
2880b57cec5SDimitry Andric 
2890b57cec5SDimitry Andric   bool isValidFeatureName(StringRef Name) const override;
2900b57cec5SDimitry Andric 
2910b57cec5SDimitry Andric   bool hasFeature(StringRef Feature) const override;
2920b57cec5SDimitry Andric 
2930b57cec5SDimitry Andric   bool handleTargetFeatures(std::vector<std::string> &Features,
2940b57cec5SDimitry Andric                             DiagnosticsEngine &Diags) override;
2950b57cec5SDimitry Andric 
2960b57cec5SDimitry Andric   StringRef getABI() const override {
2970b57cec5SDimitry Andric     if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX512F)
2980b57cec5SDimitry Andric       return "avx512";
2990b57cec5SDimitry Andric     if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX)
3000b57cec5SDimitry Andric       return "avx";
3010b57cec5SDimitry Andric     if (getTriple().getArch() == llvm::Triple::x86 &&
3020b57cec5SDimitry Andric         MMX3DNowLevel == NoMMX3DNow)
3030b57cec5SDimitry Andric       return "no-mmx";
3040b57cec5SDimitry Andric     return "";
3050b57cec5SDimitry Andric   }
3060b57cec5SDimitry Andric 
3070b57cec5SDimitry Andric   bool isValidCPUName(StringRef Name) const override {
3080b57cec5SDimitry Andric     return checkCPUKind(getCPUKind(Name));
3090b57cec5SDimitry Andric   }
3100b57cec5SDimitry Andric 
3110b57cec5SDimitry Andric   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
3120b57cec5SDimitry Andric 
3130b57cec5SDimitry Andric   bool setCPU(const std::string &Name) override {
3140b57cec5SDimitry Andric     return checkCPUKind(CPU = getCPUKind(Name));
3150b57cec5SDimitry Andric   }
3160b57cec5SDimitry Andric 
3170b57cec5SDimitry Andric   unsigned multiVersionSortPriority(StringRef Name) const override;
3180b57cec5SDimitry Andric 
3190b57cec5SDimitry Andric   bool setFPMath(StringRef Name) override;
3200b57cec5SDimitry Andric 
3210b57cec5SDimitry Andric   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
3220b57cec5SDimitry Andric     // Most of the non-ARM calling conventions are i386 conventions.
3230b57cec5SDimitry Andric     switch (CC) {
3240b57cec5SDimitry Andric     case CC_X86ThisCall:
3250b57cec5SDimitry Andric     case CC_X86FastCall:
3260b57cec5SDimitry Andric     case CC_X86StdCall:
3270b57cec5SDimitry Andric     case CC_X86VectorCall:
3280b57cec5SDimitry Andric     case CC_X86RegCall:
3290b57cec5SDimitry Andric     case CC_C:
3300b57cec5SDimitry Andric     case CC_PreserveMost:
3310b57cec5SDimitry Andric     case CC_Swift:
3320b57cec5SDimitry Andric     case CC_X86Pascal:
3330b57cec5SDimitry Andric     case CC_IntelOclBicc:
3340b57cec5SDimitry Andric     case CC_OpenCLKernel:
3350b57cec5SDimitry Andric       return CCCR_OK;
3360b57cec5SDimitry Andric     default:
3370b57cec5SDimitry Andric       return CCCR_Warning;
3380b57cec5SDimitry Andric     }
3390b57cec5SDimitry Andric   }
3400b57cec5SDimitry Andric 
3410b57cec5SDimitry Andric   CallingConv getDefaultCallingConv() const override {
3420b57cec5SDimitry Andric     return CC_C;
3430b57cec5SDimitry Andric   }
3440b57cec5SDimitry Andric 
3450b57cec5SDimitry Andric   bool hasSjLjLowering() const override { return true; }
3460b57cec5SDimitry Andric 
3470b57cec5SDimitry Andric   void setSupportedOpenCLOpts() override {
3480b57cec5SDimitry Andric     getSupportedOpenCLOpts().supportAll();
3490b57cec5SDimitry Andric   }
350*480093f4SDimitry Andric 
351*480093f4SDimitry Andric   uint64_t getPointerWidthV(unsigned AddrSpace) const override {
352*480093f4SDimitry Andric     if (AddrSpace == ptr32_sptr || AddrSpace == ptr32_uptr)
353*480093f4SDimitry Andric       return 32;
354*480093f4SDimitry Andric     if (AddrSpace == ptr64)
355*480093f4SDimitry Andric       return 64;
356*480093f4SDimitry Andric     return PointerWidth;
357*480093f4SDimitry Andric   }
358*480093f4SDimitry Andric 
359*480093f4SDimitry Andric   uint64_t getPointerAlignV(unsigned AddrSpace) const override {
360*480093f4SDimitry Andric     return getPointerWidthV(AddrSpace);
361*480093f4SDimitry Andric   }
3620b57cec5SDimitry Andric };
3630b57cec5SDimitry Andric 
3640b57cec5SDimitry Andric // X86-32 generic target
3650b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY X86_32TargetInfo : public X86TargetInfo {
3660b57cec5SDimitry Andric public:
3670b57cec5SDimitry Andric   X86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
3680b57cec5SDimitry Andric       : X86TargetInfo(Triple, Opts) {
3690b57cec5SDimitry Andric     DoubleAlign = LongLongAlign = 32;
3700b57cec5SDimitry Andric     LongDoubleWidth = 96;
3710b57cec5SDimitry Andric     LongDoubleAlign = 32;
3720b57cec5SDimitry Andric     SuitableAlign = 128;
373a7dea167SDimitry Andric     resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
374a7dea167SDimitry Andric                     "f80:32-n8:16:32-S128");
3750b57cec5SDimitry Andric     SizeType = UnsignedInt;
3760b57cec5SDimitry Andric     PtrDiffType = SignedInt;
3770b57cec5SDimitry Andric     IntPtrType = SignedInt;
3780b57cec5SDimitry Andric     RegParmMax = 3;
3790b57cec5SDimitry Andric 
3800b57cec5SDimitry Andric     // Use fpret for all types.
3810b57cec5SDimitry Andric     RealTypeUsesObjCFPRet =
3820b57cec5SDimitry Andric         ((1 << TargetInfo::Float) | (1 << TargetInfo::Double) |
3830b57cec5SDimitry Andric          (1 << TargetInfo::LongDouble));
3840b57cec5SDimitry Andric 
3850b57cec5SDimitry Andric     // x86-32 has atomics up to 8 bytes
3860b57cec5SDimitry Andric     MaxAtomicPromoteWidth = 64;
3870b57cec5SDimitry Andric     MaxAtomicInlineWidth = 32;
3880b57cec5SDimitry Andric   }
3890b57cec5SDimitry Andric 
3900b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override {
3910b57cec5SDimitry Andric     return TargetInfo::CharPtrBuiltinVaList;
3920b57cec5SDimitry Andric   }
3930b57cec5SDimitry Andric 
3940b57cec5SDimitry Andric   int getEHDataRegisterNumber(unsigned RegNo) const override {
3950b57cec5SDimitry Andric     if (RegNo == 0)
3960b57cec5SDimitry Andric       return 0;
3970b57cec5SDimitry Andric     if (RegNo == 1)
3980b57cec5SDimitry Andric       return 2;
3990b57cec5SDimitry Andric     return -1;
4000b57cec5SDimitry Andric   }
4010b57cec5SDimitry Andric 
402*480093f4SDimitry Andric   bool validateOperandSize(const llvm::StringMap<bool> &FeatureMap,
403*480093f4SDimitry Andric                            StringRef Constraint, unsigned Size) const override {
4040b57cec5SDimitry Andric     switch (Constraint[0]) {
4050b57cec5SDimitry Andric     default:
4060b57cec5SDimitry Andric       break;
4070b57cec5SDimitry Andric     case 'R':
4080b57cec5SDimitry Andric     case 'q':
4090b57cec5SDimitry Andric     case 'Q':
4100b57cec5SDimitry Andric     case 'a':
4110b57cec5SDimitry Andric     case 'b':
4120b57cec5SDimitry Andric     case 'c':
4130b57cec5SDimitry Andric     case 'd':
4140b57cec5SDimitry Andric     case 'S':
4150b57cec5SDimitry Andric     case 'D':
4160b57cec5SDimitry Andric       return Size <= 32;
4170b57cec5SDimitry Andric     case 'A':
4180b57cec5SDimitry Andric       return Size <= 64;
4190b57cec5SDimitry Andric     }
4200b57cec5SDimitry Andric 
421*480093f4SDimitry Andric     return X86TargetInfo::validateOperandSize(FeatureMap, Constraint, Size);
4220b57cec5SDimitry Andric   }
4230b57cec5SDimitry Andric 
4240b57cec5SDimitry Andric   void setMaxAtomicWidth() override {
4250b57cec5SDimitry Andric     if (hasFeature("cx8"))
4260b57cec5SDimitry Andric       MaxAtomicInlineWidth = 64;
4270b57cec5SDimitry Andric   }
4280b57cec5SDimitry Andric 
4290b57cec5SDimitry Andric   ArrayRef<Builtin::Info> getTargetBuiltins() const override;
4300b57cec5SDimitry Andric };
4310b57cec5SDimitry Andric 
4320b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY NetBSDI386TargetInfo
4330b57cec5SDimitry Andric     : public NetBSDTargetInfo<X86_32TargetInfo> {
4340b57cec5SDimitry Andric public:
4350b57cec5SDimitry Andric   NetBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
4360b57cec5SDimitry Andric       : NetBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) {}
4370b57cec5SDimitry Andric 
4380b57cec5SDimitry Andric   unsigned getFloatEvalMethod() const override {
4390b57cec5SDimitry Andric     unsigned Major, Minor, Micro;
4400b57cec5SDimitry Andric     getTriple().getOSVersion(Major, Minor, Micro);
4410b57cec5SDimitry Andric     // New NetBSD uses the default rounding mode.
4420b57cec5SDimitry Andric     if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 26) || Major == 0)
4430b57cec5SDimitry Andric       return X86_32TargetInfo::getFloatEvalMethod();
4440b57cec5SDimitry Andric     // NetBSD before 6.99.26 defaults to "double" rounding.
4450b57cec5SDimitry Andric     return 1;
4460b57cec5SDimitry Andric   }
4470b57cec5SDimitry Andric };
4480b57cec5SDimitry Andric 
4490b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY OpenBSDI386TargetInfo
4500b57cec5SDimitry Andric     : public OpenBSDTargetInfo<X86_32TargetInfo> {
4510b57cec5SDimitry Andric public:
4520b57cec5SDimitry Andric   OpenBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
4530b57cec5SDimitry Andric       : OpenBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) {
4540b57cec5SDimitry Andric     SizeType = UnsignedLong;
4550b57cec5SDimitry Andric     IntPtrType = SignedLong;
4560b57cec5SDimitry Andric     PtrDiffType = SignedLong;
4570b57cec5SDimitry Andric   }
4580b57cec5SDimitry Andric };
4590b57cec5SDimitry Andric 
4600b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY DarwinI386TargetInfo
4610b57cec5SDimitry Andric     : public DarwinTargetInfo<X86_32TargetInfo> {
4620b57cec5SDimitry Andric public:
4630b57cec5SDimitry Andric   DarwinI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
4640b57cec5SDimitry Andric       : DarwinTargetInfo<X86_32TargetInfo>(Triple, Opts) {
4650b57cec5SDimitry Andric     LongDoubleWidth = 128;
4660b57cec5SDimitry Andric     LongDoubleAlign = 128;
4670b57cec5SDimitry Andric     SuitableAlign = 128;
4680b57cec5SDimitry Andric     MaxVectorAlign = 256;
4690b57cec5SDimitry Andric     // The watchOS simulator uses the builtin bool type for Objective-C.
4700b57cec5SDimitry Andric     llvm::Triple T = llvm::Triple(Triple);
4710b57cec5SDimitry Andric     if (T.isWatchOS())
4720b57cec5SDimitry Andric       UseSignedCharForObjCBool = false;
4730b57cec5SDimitry Andric     SizeType = UnsignedLong;
4740b57cec5SDimitry Andric     IntPtrType = SignedLong;
475a7dea167SDimitry Andric     resetDataLayout("e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
476a7dea167SDimitry Andric                     "f80:128-n8:16:32-S128");
4770b57cec5SDimitry Andric     HasAlignMac68kSupport = true;
4780b57cec5SDimitry Andric   }
4790b57cec5SDimitry Andric 
4800b57cec5SDimitry Andric   bool handleTargetFeatures(std::vector<std::string> &Features,
4810b57cec5SDimitry Andric                             DiagnosticsEngine &Diags) override {
4820b57cec5SDimitry Andric     if (!DarwinTargetInfo<X86_32TargetInfo>::handleTargetFeatures(Features,
4830b57cec5SDimitry Andric                                                                   Diags))
4840b57cec5SDimitry Andric       return false;
4850b57cec5SDimitry Andric     // We now know the features we have: we can decide how to align vectors.
4860b57cec5SDimitry Andric     MaxVectorAlign =
4870b57cec5SDimitry Andric         hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128;
4880b57cec5SDimitry Andric     return true;
4890b57cec5SDimitry Andric   }
4900b57cec5SDimitry Andric };
4910b57cec5SDimitry Andric 
4920b57cec5SDimitry Andric // x86-32 Windows target
4930b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY WindowsX86_32TargetInfo
4940b57cec5SDimitry Andric     : public WindowsTargetInfo<X86_32TargetInfo> {
4950b57cec5SDimitry Andric public:
4960b57cec5SDimitry Andric   WindowsX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
4970b57cec5SDimitry Andric       : WindowsTargetInfo<X86_32TargetInfo>(Triple, Opts) {
4980b57cec5SDimitry Andric     DoubleAlign = LongLongAlign = 64;
4990b57cec5SDimitry Andric     bool IsWinCOFF =
5000b57cec5SDimitry Andric         getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
501a7dea167SDimitry Andric     resetDataLayout(IsWinCOFF ? "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:"
502a7dea167SDimitry Andric                                 "64-i64:64-f80:32-n8:16:32-a:0:32-S32"
503a7dea167SDimitry Andric                               : "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:"
504a7dea167SDimitry Andric                                 "64-i64:64-f80:32-n8:16:32-a:0:32-S32");
5050b57cec5SDimitry Andric   }
5060b57cec5SDimitry Andric };
5070b57cec5SDimitry Andric 
5080b57cec5SDimitry Andric // x86-32 Windows Visual Studio target
5090b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MicrosoftX86_32TargetInfo
5100b57cec5SDimitry Andric     : public WindowsX86_32TargetInfo {
5110b57cec5SDimitry Andric public:
5120b57cec5SDimitry Andric   MicrosoftX86_32TargetInfo(const llvm::Triple &Triple,
5130b57cec5SDimitry Andric                             const TargetOptions &Opts)
5140b57cec5SDimitry Andric       : WindowsX86_32TargetInfo(Triple, Opts) {
5150b57cec5SDimitry Andric     LongDoubleWidth = LongDoubleAlign = 64;
5160b57cec5SDimitry Andric     LongDoubleFormat = &llvm::APFloat::IEEEdouble();
5170b57cec5SDimitry Andric   }
5180b57cec5SDimitry Andric 
5190b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
5200b57cec5SDimitry Andric                         MacroBuilder &Builder) const override {
5210b57cec5SDimitry Andric     WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
5220b57cec5SDimitry Andric     // The value of the following reflects processor type.
5230b57cec5SDimitry Andric     // 300=386, 400=486, 500=Pentium, 600=Blend (default)
5240b57cec5SDimitry Andric     // We lost the original triple, so we use the default.
5250b57cec5SDimitry Andric     Builder.defineMacro("_M_IX86", "600");
5260b57cec5SDimitry Andric   }
5270b57cec5SDimitry Andric };
5280b57cec5SDimitry Andric 
5290b57cec5SDimitry Andric // x86-32 MinGW target
5300b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MinGWX86_32TargetInfo
5310b57cec5SDimitry Andric     : public WindowsX86_32TargetInfo {
5320b57cec5SDimitry Andric public:
5330b57cec5SDimitry Andric   MinGWX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
5340b57cec5SDimitry Andric       : WindowsX86_32TargetInfo(Triple, Opts) {
5350b57cec5SDimitry Andric     HasFloat128 = true;
5360b57cec5SDimitry Andric   }
5370b57cec5SDimitry Andric 
5380b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
5390b57cec5SDimitry Andric                         MacroBuilder &Builder) const override {
5400b57cec5SDimitry Andric     WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
5410b57cec5SDimitry Andric     Builder.defineMacro("_X86_");
5420b57cec5SDimitry Andric   }
5430b57cec5SDimitry Andric };
5440b57cec5SDimitry Andric 
5450b57cec5SDimitry Andric // x86-32 Cygwin target
5460b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : public X86_32TargetInfo {
5470b57cec5SDimitry Andric public:
5480b57cec5SDimitry Andric   CygwinX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
5490b57cec5SDimitry Andric       : X86_32TargetInfo(Triple, Opts) {
5500b57cec5SDimitry Andric     this->WCharType = TargetInfo::UnsignedShort;
5510b57cec5SDimitry Andric     DoubleAlign = LongLongAlign = 64;
552a7dea167SDimitry Andric     resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:"
553a7dea167SDimitry Andric                     "32-n8:16:32-a:0:32-S32");
5540b57cec5SDimitry Andric   }
5550b57cec5SDimitry Andric 
5560b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
5570b57cec5SDimitry Andric                         MacroBuilder &Builder) const override {
5580b57cec5SDimitry Andric     X86_32TargetInfo::getTargetDefines(Opts, Builder);
5590b57cec5SDimitry Andric     Builder.defineMacro("_X86_");
5600b57cec5SDimitry Andric     Builder.defineMacro("__CYGWIN__");
5610b57cec5SDimitry Andric     Builder.defineMacro("__CYGWIN32__");
5620b57cec5SDimitry Andric     addCygMingDefines(Opts, Builder);
5630b57cec5SDimitry Andric     DefineStd(Builder, "unix", Opts);
5640b57cec5SDimitry Andric     if (Opts.CPlusPlus)
5650b57cec5SDimitry Andric       Builder.defineMacro("_GNU_SOURCE");
5660b57cec5SDimitry Andric   }
5670b57cec5SDimitry Andric };
5680b57cec5SDimitry Andric 
5690b57cec5SDimitry Andric // x86-32 Haiku target
5700b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY HaikuX86_32TargetInfo
5710b57cec5SDimitry Andric     : public HaikuTargetInfo<X86_32TargetInfo> {
5720b57cec5SDimitry Andric public:
5730b57cec5SDimitry Andric   HaikuX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
5740b57cec5SDimitry Andric       : HaikuTargetInfo<X86_32TargetInfo>(Triple, Opts) {}
5750b57cec5SDimitry Andric 
5760b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
5770b57cec5SDimitry Andric                         MacroBuilder &Builder) const override {
5780b57cec5SDimitry Andric     HaikuTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
5790b57cec5SDimitry Andric     Builder.defineMacro("__INTEL__");
5800b57cec5SDimitry Andric   }
5810b57cec5SDimitry Andric };
5820b57cec5SDimitry Andric 
5830b57cec5SDimitry Andric // X86-32 MCU target
5840b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MCUX86_32TargetInfo : public X86_32TargetInfo {
5850b57cec5SDimitry Andric public:
5860b57cec5SDimitry Andric   MCUX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
5870b57cec5SDimitry Andric       : X86_32TargetInfo(Triple, Opts) {
5880b57cec5SDimitry Andric     LongDoubleWidth = 64;
5890b57cec5SDimitry Andric     LongDoubleFormat = &llvm::APFloat::IEEEdouble();
590a7dea167SDimitry Andric     resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-f64:"
591a7dea167SDimitry Andric                     "32-f128:32-n8:16:32-a:0:32-S32");
5920b57cec5SDimitry Andric     WIntType = UnsignedInt;
5930b57cec5SDimitry Andric   }
5940b57cec5SDimitry Andric 
5950b57cec5SDimitry Andric   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
5960b57cec5SDimitry Andric     // On MCU we support only C calling convention.
5970b57cec5SDimitry Andric     return CC == CC_C ? CCCR_OK : CCCR_Warning;
5980b57cec5SDimitry Andric   }
5990b57cec5SDimitry Andric 
6000b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
6010b57cec5SDimitry Andric                         MacroBuilder &Builder) const override {
6020b57cec5SDimitry Andric     X86_32TargetInfo::getTargetDefines(Opts, Builder);
6030b57cec5SDimitry Andric     Builder.defineMacro("__iamcu");
6040b57cec5SDimitry Andric     Builder.defineMacro("__iamcu__");
6050b57cec5SDimitry Andric   }
6060b57cec5SDimitry Andric 
6070b57cec5SDimitry Andric   bool allowsLargerPreferedTypeAlignment() const override { return false; }
6080b57cec5SDimitry Andric };
6090b57cec5SDimitry Andric 
6100b57cec5SDimitry Andric // x86-32 RTEMS target
6110b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY RTEMSX86_32TargetInfo : public X86_32TargetInfo {
6120b57cec5SDimitry Andric public:
6130b57cec5SDimitry Andric   RTEMSX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
6140b57cec5SDimitry Andric       : X86_32TargetInfo(Triple, Opts) {
6150b57cec5SDimitry Andric     SizeType = UnsignedLong;
6160b57cec5SDimitry Andric     IntPtrType = SignedLong;
6170b57cec5SDimitry Andric     PtrDiffType = SignedLong;
6180b57cec5SDimitry Andric   }
6190b57cec5SDimitry Andric 
6200b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
6210b57cec5SDimitry Andric                         MacroBuilder &Builder) const override {
6220b57cec5SDimitry Andric     X86_32TargetInfo::getTargetDefines(Opts, Builder);
6230b57cec5SDimitry Andric     Builder.defineMacro("__INTEL__");
6240b57cec5SDimitry Andric     Builder.defineMacro("__rtems__");
6250b57cec5SDimitry Andric   }
6260b57cec5SDimitry Andric };
6270b57cec5SDimitry Andric 
6280b57cec5SDimitry Andric // x86-64 generic target
6290b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo {
6300b57cec5SDimitry Andric public:
6310b57cec5SDimitry Andric   X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
6320b57cec5SDimitry Andric       : X86TargetInfo(Triple, Opts) {
6330b57cec5SDimitry Andric     const bool IsX32 = getTriple().getEnvironment() == llvm::Triple::GNUX32;
6340b57cec5SDimitry Andric     bool IsWinCOFF =
6350b57cec5SDimitry Andric         getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
6360b57cec5SDimitry Andric     LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64;
6370b57cec5SDimitry Andric     LongDoubleWidth = 128;
6380b57cec5SDimitry Andric     LongDoubleAlign = 128;
6390b57cec5SDimitry Andric     LargeArrayMinWidth = 128;
6400b57cec5SDimitry Andric     LargeArrayAlign = 128;
6410b57cec5SDimitry Andric     SuitableAlign = 128;
6420b57cec5SDimitry Andric     SizeType = IsX32 ? UnsignedInt : UnsignedLong;
6430b57cec5SDimitry Andric     PtrDiffType = IsX32 ? SignedInt : SignedLong;
6440b57cec5SDimitry Andric     IntPtrType = IsX32 ? SignedInt : SignedLong;
6450b57cec5SDimitry Andric     IntMaxType = IsX32 ? SignedLongLong : SignedLong;
6460b57cec5SDimitry Andric     Int64Type = IsX32 ? SignedLongLong : SignedLong;
6470b57cec5SDimitry Andric     RegParmMax = 6;
6480b57cec5SDimitry Andric 
6490b57cec5SDimitry Andric     // Pointers are 32-bit in x32.
650a7dea167SDimitry Andric     resetDataLayout(IsX32 ? "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
651a7dea167SDimitry Andric                             "i64:64-f80:128-n8:16:32:64-S128"
652a7dea167SDimitry Andric                           : IsWinCOFF ? "e-m:w-p270:32:32-p271:32:32-p272:64:"
653a7dea167SDimitry Andric                                         "64-i64:64-f80:128-n8:16:32:64-S128"
654a7dea167SDimitry Andric                                       : "e-m:e-p270:32:32-p271:32:32-p272:64:"
655a7dea167SDimitry Andric                                         "64-i64:64-f80:128-n8:16:32:64-S128");
6560b57cec5SDimitry Andric 
6570b57cec5SDimitry Andric     // Use fpret only for long double.
6580b57cec5SDimitry Andric     RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
6590b57cec5SDimitry Andric 
6600b57cec5SDimitry Andric     // Use fp2ret for _Complex long double.
6610b57cec5SDimitry Andric     ComplexLongDoubleUsesFP2Ret = true;
6620b57cec5SDimitry Andric 
6630b57cec5SDimitry Andric     // Make __builtin_ms_va_list available.
6640b57cec5SDimitry Andric     HasBuiltinMSVaList = true;
6650b57cec5SDimitry Andric 
6660b57cec5SDimitry Andric     // x86-64 has atomics up to 16 bytes.
6670b57cec5SDimitry Andric     MaxAtomicPromoteWidth = 128;
6680b57cec5SDimitry Andric     MaxAtomicInlineWidth = 64;
6690b57cec5SDimitry Andric   }
6700b57cec5SDimitry Andric 
6710b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override {
6720b57cec5SDimitry Andric     return TargetInfo::X86_64ABIBuiltinVaList;
6730b57cec5SDimitry Andric   }
6740b57cec5SDimitry Andric 
6750b57cec5SDimitry Andric   int getEHDataRegisterNumber(unsigned RegNo) const override {
6760b57cec5SDimitry Andric     if (RegNo == 0)
6770b57cec5SDimitry Andric       return 0;
6780b57cec5SDimitry Andric     if (RegNo == 1)
6790b57cec5SDimitry Andric       return 1;
6800b57cec5SDimitry Andric     return -1;
6810b57cec5SDimitry Andric   }
6820b57cec5SDimitry Andric 
6830b57cec5SDimitry Andric   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
6840b57cec5SDimitry Andric     switch (CC) {
6850b57cec5SDimitry Andric     case CC_C:
6860b57cec5SDimitry Andric     case CC_Swift:
6870b57cec5SDimitry Andric     case CC_X86VectorCall:
6880b57cec5SDimitry Andric     case CC_IntelOclBicc:
6890b57cec5SDimitry Andric     case CC_Win64:
6900b57cec5SDimitry Andric     case CC_PreserveMost:
6910b57cec5SDimitry Andric     case CC_PreserveAll:
6920b57cec5SDimitry Andric     case CC_X86RegCall:
6930b57cec5SDimitry Andric     case CC_OpenCLKernel:
6940b57cec5SDimitry Andric       return CCCR_OK;
6950b57cec5SDimitry Andric     default:
6960b57cec5SDimitry Andric       return CCCR_Warning;
6970b57cec5SDimitry Andric     }
6980b57cec5SDimitry Andric   }
6990b57cec5SDimitry Andric 
7000b57cec5SDimitry Andric   CallingConv getDefaultCallingConv() const override {
7010b57cec5SDimitry Andric     return CC_C;
7020b57cec5SDimitry Andric   }
7030b57cec5SDimitry Andric 
7040b57cec5SDimitry Andric   // for x32 we need it here explicitly
7050b57cec5SDimitry Andric   bool hasInt128Type() const override { return true; }
7060b57cec5SDimitry Andric 
7070b57cec5SDimitry Andric   unsigned getUnwindWordWidth() const override { return 64; }
7080b57cec5SDimitry Andric 
7090b57cec5SDimitry Andric   unsigned getRegisterWidth() const override { return 64; }
7100b57cec5SDimitry Andric 
7110b57cec5SDimitry Andric   bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
7120b57cec5SDimitry Andric                                       bool &HasSizeMismatch) const override {
7130b57cec5SDimitry Andric     // rsp and rbp are the only 64-bit registers the x86 backend can currently
7140b57cec5SDimitry Andric     // handle.
7150b57cec5SDimitry Andric     if (RegName.equals("rsp") || RegName.equals("rbp")) {
7160b57cec5SDimitry Andric       // Check that the register size is 64-bit.
7170b57cec5SDimitry Andric       HasSizeMismatch = RegSize != 64;
7180b57cec5SDimitry Andric       return true;
7190b57cec5SDimitry Andric     }
7200b57cec5SDimitry Andric 
7210b57cec5SDimitry Andric     // Check if the register is a 32-bit register the backend can handle.
7220b57cec5SDimitry Andric     return X86TargetInfo::validateGlobalRegisterVariable(RegName, RegSize,
7230b57cec5SDimitry Andric                                                          HasSizeMismatch);
7240b57cec5SDimitry Andric   }
7250b57cec5SDimitry Andric 
7260b57cec5SDimitry Andric   void setMaxAtomicWidth() override {
7270b57cec5SDimitry Andric     if (hasFeature("cx16"))
7280b57cec5SDimitry Andric       MaxAtomicInlineWidth = 128;
7290b57cec5SDimitry Andric   }
7300b57cec5SDimitry Andric 
7310b57cec5SDimitry Andric   ArrayRef<Builtin::Info> getTargetBuiltins() const override;
7320b57cec5SDimitry Andric };
7330b57cec5SDimitry Andric 
7340b57cec5SDimitry Andric // x86-64 Windows target
7350b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
7360b57cec5SDimitry Andric     : public WindowsTargetInfo<X86_64TargetInfo> {
7370b57cec5SDimitry Andric public:
7380b57cec5SDimitry Andric   WindowsX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
7390b57cec5SDimitry Andric       : WindowsTargetInfo<X86_64TargetInfo>(Triple, Opts) {
7400b57cec5SDimitry Andric     LongWidth = LongAlign = 32;
7410b57cec5SDimitry Andric     DoubleAlign = LongLongAlign = 64;
7420b57cec5SDimitry Andric     IntMaxType = SignedLongLong;
7430b57cec5SDimitry Andric     Int64Type = SignedLongLong;
7440b57cec5SDimitry Andric     SizeType = UnsignedLongLong;
7450b57cec5SDimitry Andric     PtrDiffType = SignedLongLong;
7460b57cec5SDimitry Andric     IntPtrType = SignedLongLong;
7470b57cec5SDimitry Andric   }
7480b57cec5SDimitry Andric 
7490b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override {
7500b57cec5SDimitry Andric     return TargetInfo::CharPtrBuiltinVaList;
7510b57cec5SDimitry Andric   }
7520b57cec5SDimitry Andric 
7530b57cec5SDimitry Andric   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
7540b57cec5SDimitry Andric     switch (CC) {
7550b57cec5SDimitry Andric     case CC_X86StdCall:
7560b57cec5SDimitry Andric     case CC_X86ThisCall:
7570b57cec5SDimitry Andric     case CC_X86FastCall:
7580b57cec5SDimitry Andric       return CCCR_Ignore;
7590b57cec5SDimitry Andric     case CC_C:
7600b57cec5SDimitry Andric     case CC_X86VectorCall:
7610b57cec5SDimitry Andric     case CC_IntelOclBicc:
7620b57cec5SDimitry Andric     case CC_PreserveMost:
7630b57cec5SDimitry Andric     case CC_PreserveAll:
7640b57cec5SDimitry Andric     case CC_X86_64SysV:
7650b57cec5SDimitry Andric     case CC_Swift:
7660b57cec5SDimitry Andric     case CC_X86RegCall:
7670b57cec5SDimitry Andric     case CC_OpenCLKernel:
7680b57cec5SDimitry Andric       return CCCR_OK;
7690b57cec5SDimitry Andric     default:
7700b57cec5SDimitry Andric       return CCCR_Warning;
7710b57cec5SDimitry Andric     }
7720b57cec5SDimitry Andric   }
7730b57cec5SDimitry Andric };
7740b57cec5SDimitry Andric 
7750b57cec5SDimitry Andric // x86-64 Windows Visual Studio target
7760b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64TargetInfo
7770b57cec5SDimitry Andric     : public WindowsX86_64TargetInfo {
7780b57cec5SDimitry Andric public:
7790b57cec5SDimitry Andric   MicrosoftX86_64TargetInfo(const llvm::Triple &Triple,
7800b57cec5SDimitry Andric                             const TargetOptions &Opts)
7810b57cec5SDimitry Andric       : WindowsX86_64TargetInfo(Triple, Opts) {
7820b57cec5SDimitry Andric     LongDoubleWidth = LongDoubleAlign = 64;
7830b57cec5SDimitry Andric     LongDoubleFormat = &llvm::APFloat::IEEEdouble();
7840b57cec5SDimitry Andric   }
7850b57cec5SDimitry Andric 
7860b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
7870b57cec5SDimitry Andric                         MacroBuilder &Builder) const override {
7880b57cec5SDimitry Andric     WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
7890b57cec5SDimitry Andric     Builder.defineMacro("_M_X64", "100");
7900b57cec5SDimitry Andric     Builder.defineMacro("_M_AMD64", "100");
7910b57cec5SDimitry Andric   }
7920b57cec5SDimitry Andric 
7930b57cec5SDimitry Andric   TargetInfo::CallingConvKind
7940b57cec5SDimitry Andric   getCallingConvKind(bool ClangABICompat4) const override {
7950b57cec5SDimitry Andric     return CCK_MicrosoftWin64;
7960b57cec5SDimitry Andric   }
7970b57cec5SDimitry Andric };
7980b57cec5SDimitry Andric 
7990b57cec5SDimitry Andric // x86-64 MinGW target
8000b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MinGWX86_64TargetInfo
8010b57cec5SDimitry Andric     : public WindowsX86_64TargetInfo {
8020b57cec5SDimitry Andric public:
8030b57cec5SDimitry Andric   MinGWX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
8040b57cec5SDimitry Andric       : WindowsX86_64TargetInfo(Triple, Opts) {
8050b57cec5SDimitry Andric     // Mingw64 rounds long double size and alignment up to 16 bytes, but sticks
8060b57cec5SDimitry Andric     // with x86 FP ops. Weird.
8070b57cec5SDimitry Andric     LongDoubleWidth = LongDoubleAlign = 128;
8080b57cec5SDimitry Andric     LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
8090b57cec5SDimitry Andric     HasFloat128 = true;
8100b57cec5SDimitry Andric   }
8110b57cec5SDimitry Andric };
8120b57cec5SDimitry Andric 
8130b57cec5SDimitry Andric // x86-64 Cygwin target
8140b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
8150b57cec5SDimitry Andric public:
8160b57cec5SDimitry Andric   CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
8170b57cec5SDimitry Andric       : X86_64TargetInfo(Triple, Opts) {
8180b57cec5SDimitry Andric     this->WCharType = TargetInfo::UnsignedShort;
8190b57cec5SDimitry Andric     TLSSupported = false;
8200b57cec5SDimitry Andric   }
8210b57cec5SDimitry Andric 
8220b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
8230b57cec5SDimitry Andric                         MacroBuilder &Builder) const override {
8240b57cec5SDimitry Andric     X86_64TargetInfo::getTargetDefines(Opts, Builder);
8250b57cec5SDimitry Andric     Builder.defineMacro("__x86_64__");
8260b57cec5SDimitry Andric     Builder.defineMacro("__CYGWIN__");
8270b57cec5SDimitry Andric     Builder.defineMacro("__CYGWIN64__");
8280b57cec5SDimitry Andric     addCygMingDefines(Opts, Builder);
8290b57cec5SDimitry Andric     DefineStd(Builder, "unix", Opts);
8300b57cec5SDimitry Andric     if (Opts.CPlusPlus)
8310b57cec5SDimitry Andric       Builder.defineMacro("_GNU_SOURCE");
8320b57cec5SDimitry Andric   }
8330b57cec5SDimitry Andric };
8340b57cec5SDimitry Andric 
8350b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY DarwinX86_64TargetInfo
8360b57cec5SDimitry Andric     : public DarwinTargetInfo<X86_64TargetInfo> {
8370b57cec5SDimitry Andric public:
8380b57cec5SDimitry Andric   DarwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
8390b57cec5SDimitry Andric       : DarwinTargetInfo<X86_64TargetInfo>(Triple, Opts) {
8400b57cec5SDimitry Andric     Int64Type = SignedLongLong;
8410b57cec5SDimitry Andric     // The 64-bit iOS simulator uses the builtin bool type for Objective-C.
8420b57cec5SDimitry Andric     llvm::Triple T = llvm::Triple(Triple);
8430b57cec5SDimitry Andric     if (T.isiOS())
8440b57cec5SDimitry Andric       UseSignedCharForObjCBool = false;
845a7dea167SDimitry Andric     resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:"
846a7dea167SDimitry Andric                     "16:32:64-S128");
8470b57cec5SDimitry Andric   }
8480b57cec5SDimitry Andric 
8490b57cec5SDimitry Andric   bool handleTargetFeatures(std::vector<std::string> &Features,
8500b57cec5SDimitry Andric                             DiagnosticsEngine &Diags) override {
8510b57cec5SDimitry Andric     if (!DarwinTargetInfo<X86_64TargetInfo>::handleTargetFeatures(Features,
8520b57cec5SDimitry Andric                                                                   Diags))
8530b57cec5SDimitry Andric       return false;
8540b57cec5SDimitry Andric     // We now know the features we have: we can decide how to align vectors.
8550b57cec5SDimitry Andric     MaxVectorAlign =
8560b57cec5SDimitry Andric         hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128;
8570b57cec5SDimitry Andric     return true;
8580b57cec5SDimitry Andric   }
8590b57cec5SDimitry Andric };
8600b57cec5SDimitry Andric 
8610b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY OpenBSDX86_64TargetInfo
8620b57cec5SDimitry Andric     : public OpenBSDTargetInfo<X86_64TargetInfo> {
8630b57cec5SDimitry Andric public:
8640b57cec5SDimitry Andric   OpenBSDX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
8650b57cec5SDimitry Andric       : OpenBSDTargetInfo<X86_64TargetInfo>(Triple, Opts) {
8660b57cec5SDimitry Andric     IntMaxType = SignedLongLong;
8670b57cec5SDimitry Andric     Int64Type = SignedLongLong;
8680b57cec5SDimitry Andric   }
8690b57cec5SDimitry Andric };
8700b57cec5SDimitry Andric 
8710b57cec5SDimitry Andric // x86_32 Android target
8720b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY AndroidX86_32TargetInfo
8730b57cec5SDimitry Andric     : public LinuxTargetInfo<X86_32TargetInfo> {
8740b57cec5SDimitry Andric public:
8750b57cec5SDimitry Andric   AndroidX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
8760b57cec5SDimitry Andric       : LinuxTargetInfo<X86_32TargetInfo>(Triple, Opts) {
8770b57cec5SDimitry Andric     SuitableAlign = 32;
8780b57cec5SDimitry Andric     LongDoubleWidth = 64;
8790b57cec5SDimitry Andric     LongDoubleFormat = &llvm::APFloat::IEEEdouble();
8800b57cec5SDimitry Andric   }
8810b57cec5SDimitry Andric };
8820b57cec5SDimitry Andric 
8830b57cec5SDimitry Andric // x86_64 Android target
8840b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY AndroidX86_64TargetInfo
8850b57cec5SDimitry Andric     : public LinuxTargetInfo<X86_64TargetInfo> {
8860b57cec5SDimitry Andric public:
8870b57cec5SDimitry Andric   AndroidX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
8880b57cec5SDimitry Andric       : LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts) {
8890b57cec5SDimitry Andric     LongDoubleFormat = &llvm::APFloat::IEEEquad();
8900b57cec5SDimitry Andric   }
8910b57cec5SDimitry Andric };
8920b57cec5SDimitry Andric } // namespace targets
8930b57cec5SDimitry Andric } // namespace clang
8940b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
895