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" 215ffd83dbSDimitry Andric #include "llvm/Support/X86TargetParser.h" 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric namespace clang { 240b57cec5SDimitry Andric namespace targets { 250b57cec5SDimitry Andric 26480093f4SDimitry Andric static const unsigned X86AddrSpaceMap[] = { 27480093f4SDimitry Andric 0, // Default 28480093f4SDimitry Andric 0, // opencl_global 29480093f4SDimitry Andric 0, // opencl_local 30480093f4SDimitry Andric 0, // opencl_constant 31480093f4SDimitry Andric 0, // opencl_private 32480093f4SDimitry Andric 0, // opencl_generic 33*e8d8bef9SDimitry Andric 0, // opencl_global_device 34*e8d8bef9SDimitry Andric 0, // opencl_global_host 35480093f4SDimitry Andric 0, // cuda_device 36480093f4SDimitry Andric 0, // cuda_constant 37480093f4SDimitry Andric 0, // cuda_shared 38480093f4SDimitry Andric 270, // ptr32_sptr 39480093f4SDimitry Andric 271, // ptr32_uptr 40480093f4SDimitry Andric 272 // ptr64 41480093f4SDimitry Andric }; 42480093f4SDimitry Andric 430b57cec5SDimitry Andric // X86 target abstract base class; x86-32 and x86-64 are very close, so 440b57cec5SDimitry Andric // most of the implementation can be shared. 450b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo { 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric enum X86SSEEnum { 480b57cec5SDimitry Andric NoSSE, 490b57cec5SDimitry Andric SSE1, 500b57cec5SDimitry Andric SSE2, 510b57cec5SDimitry Andric SSE3, 520b57cec5SDimitry Andric SSSE3, 530b57cec5SDimitry Andric SSE41, 540b57cec5SDimitry Andric SSE42, 550b57cec5SDimitry Andric AVX, 560b57cec5SDimitry Andric AVX2, 570b57cec5SDimitry Andric AVX512F 580b57cec5SDimitry Andric } SSELevel = NoSSE; 590b57cec5SDimitry Andric enum MMX3DNowEnum { 600b57cec5SDimitry Andric NoMMX3DNow, 610b57cec5SDimitry Andric MMX, 620b57cec5SDimitry Andric AMD3DNow, 630b57cec5SDimitry Andric AMD3DNowAthlon 640b57cec5SDimitry Andric } MMX3DNowLevel = NoMMX3DNow; 650b57cec5SDimitry Andric enum XOPEnum { NoXOP, SSE4A, FMA4, XOP } XOPLevel = NoXOP; 66480093f4SDimitry Andric enum AddrSpace { ptr32_sptr = 270, ptr32_uptr = 271, ptr64 = 272 }; 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric bool HasAES = false; 690b57cec5SDimitry Andric bool HasVAES = false; 700b57cec5SDimitry Andric bool HasPCLMUL = false; 710b57cec5SDimitry Andric bool HasVPCLMULQDQ = false; 720b57cec5SDimitry Andric bool HasGFNI = false; 730b57cec5SDimitry Andric bool HasLZCNT = false; 740b57cec5SDimitry Andric bool HasRDRND = false; 750b57cec5SDimitry Andric bool HasFSGSBASE = false; 760b57cec5SDimitry Andric bool HasBMI = false; 770b57cec5SDimitry Andric bool HasBMI2 = false; 780b57cec5SDimitry Andric bool HasPOPCNT = false; 790b57cec5SDimitry Andric bool HasRTM = false; 800b57cec5SDimitry Andric bool HasPRFCHW = false; 810b57cec5SDimitry Andric bool HasRDSEED = false; 820b57cec5SDimitry Andric bool HasADX = false; 830b57cec5SDimitry Andric bool HasTBM = false; 840b57cec5SDimitry Andric bool HasLWP = false; 850b57cec5SDimitry Andric bool HasFMA = false; 860b57cec5SDimitry Andric bool HasF16C = false; 870b57cec5SDimitry Andric bool HasAVX512CD = false; 880b57cec5SDimitry Andric bool HasAVX512VPOPCNTDQ = false; 890b57cec5SDimitry Andric bool HasAVX512VNNI = false; 900b57cec5SDimitry Andric bool HasAVX512BF16 = false; 910b57cec5SDimitry Andric bool HasAVX512ER = false; 920b57cec5SDimitry Andric bool HasAVX512PF = false; 930b57cec5SDimitry Andric bool HasAVX512DQ = false; 940b57cec5SDimitry Andric bool HasAVX512BITALG = false; 950b57cec5SDimitry Andric bool HasAVX512BW = false; 960b57cec5SDimitry Andric bool HasAVX512VL = false; 970b57cec5SDimitry Andric bool HasAVX512VBMI = false; 980b57cec5SDimitry Andric bool HasAVX512VBMI2 = false; 990b57cec5SDimitry Andric bool HasAVX512IFMA = false; 1000b57cec5SDimitry Andric bool HasAVX512VP2INTERSECT = false; 1010b57cec5SDimitry Andric bool HasSHA = false; 1020b57cec5SDimitry Andric bool HasSHSTK = false; 1030b57cec5SDimitry Andric bool HasSGX = false; 1040b57cec5SDimitry Andric bool HasCX8 = false; 1050b57cec5SDimitry Andric bool HasCX16 = false; 1060b57cec5SDimitry Andric bool HasFXSR = false; 1070b57cec5SDimitry Andric bool HasXSAVE = false; 1080b57cec5SDimitry Andric bool HasXSAVEOPT = false; 1090b57cec5SDimitry Andric bool HasXSAVEC = false; 1100b57cec5SDimitry Andric bool HasXSAVES = false; 1110b57cec5SDimitry Andric bool HasMWAITX = false; 1120b57cec5SDimitry Andric bool HasCLZERO = false; 1130b57cec5SDimitry Andric bool HasCLDEMOTE = false; 1140b57cec5SDimitry Andric bool HasPCONFIG = false; 1150b57cec5SDimitry Andric bool HasPKU = false; 1160b57cec5SDimitry Andric bool HasCLFLUSHOPT = false; 1170b57cec5SDimitry Andric bool HasCLWB = false; 1180b57cec5SDimitry Andric bool HasMOVBE = false; 1190b57cec5SDimitry Andric bool HasPREFETCHWT1 = false; 1200b57cec5SDimitry Andric bool HasRDPID = false; 1210b57cec5SDimitry Andric bool HasRetpolineExternalThunk = false; 1220b57cec5SDimitry Andric bool HasLAHFSAHF = false; 1230b57cec5SDimitry Andric bool HasWBNOINVD = false; 1240b57cec5SDimitry Andric bool HasWAITPKG = false; 1250b57cec5SDimitry Andric bool HasMOVDIRI = false; 1260b57cec5SDimitry Andric bool HasMOVDIR64B = false; 1270b57cec5SDimitry Andric bool HasPTWRITE = false; 1280b57cec5SDimitry Andric bool HasINVPCID = false; 1290b57cec5SDimitry Andric bool HasENQCMD = false; 130*e8d8bef9SDimitry Andric bool HasKL = false; // For key locker 131*e8d8bef9SDimitry Andric bool HasWIDEKL = false; // For wide key locker 132*e8d8bef9SDimitry Andric bool HasHRESET = false; 133*e8d8bef9SDimitry Andric bool HasAVXVNNI = false; 1345ffd83dbSDimitry Andric bool HasAMXTILE = false; 1355ffd83dbSDimitry Andric bool HasAMXINT8 = false; 1365ffd83dbSDimitry Andric bool HasAMXBF16 = false; 1375ffd83dbSDimitry Andric bool HasSERIALIZE = false; 1385ffd83dbSDimitry Andric bool HasTSXLDTRK = false; 139*e8d8bef9SDimitry Andric bool HasUINTR = false; 1400b57cec5SDimitry Andric 1410b57cec5SDimitry Andric protected: 1425ffd83dbSDimitry Andric llvm::X86::CPUKind CPU = llvm::X86::CK_None; 1430b57cec5SDimitry Andric 1440b57cec5SDimitry Andric enum FPMathKind { FP_Default, FP_SSE, FP_387 } FPMath = FP_Default; 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andric public: 1470b57cec5SDimitry Andric X86TargetInfo(const llvm::Triple &Triple, const TargetOptions &) 1480b57cec5SDimitry Andric : TargetInfo(Triple) { 1490b57cec5SDimitry Andric LongDoubleFormat = &llvm::APFloat::x87DoubleExtended(); 150480093f4SDimitry Andric AddrSpaceMap = &X86AddrSpaceMap; 1515ffd83dbSDimitry Andric HasStrictFP = true; 152*e8d8bef9SDimitry Andric 153*e8d8bef9SDimitry Andric bool IsWinCOFF = 154*e8d8bef9SDimitry Andric getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); 155*e8d8bef9SDimitry Andric if (IsWinCOFF) 156*e8d8bef9SDimitry Andric MaxVectorAlign = MaxTLSAlign = 8192u * getCharWidth(); 1570b57cec5SDimitry Andric } 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andric const char *getLongDoubleMangling() const override { 1600b57cec5SDimitry Andric return LongDoubleFormat == &llvm::APFloat::IEEEquad() ? "g" : "e"; 1610b57cec5SDimitry Andric } 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric unsigned getFloatEvalMethod() const override { 1640b57cec5SDimitry Andric // X87 evaluates with 80 bits "long double" precision. 1650b57cec5SDimitry Andric return SSELevel == NoSSE ? 2 : 0; 1660b57cec5SDimitry Andric } 1670b57cec5SDimitry Andric 1680b57cec5SDimitry Andric ArrayRef<const char *> getGCCRegNames() const override; 1690b57cec5SDimitry Andric 1700b57cec5SDimitry Andric ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override { 1710b57cec5SDimitry Andric return None; 1720b57cec5SDimitry Andric } 1730b57cec5SDimitry Andric 1740b57cec5SDimitry Andric ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override; 1750b57cec5SDimitry Andric 1765ffd83dbSDimitry Andric bool isSPRegName(StringRef RegName) const override { 1775ffd83dbSDimitry Andric return RegName.equals("esp") || RegName.equals("rsp"); 1785ffd83dbSDimitry Andric } 1795ffd83dbSDimitry Andric 1800b57cec5SDimitry Andric bool validateCpuSupports(StringRef Name) const override; 1810b57cec5SDimitry Andric 1820b57cec5SDimitry Andric bool validateCpuIs(StringRef Name) const override; 1830b57cec5SDimitry Andric 1840b57cec5SDimitry Andric bool validateCPUSpecificCPUDispatch(StringRef Name) const override; 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andric char CPUSpecificManglingCharacter(StringRef Name) const override; 1870b57cec5SDimitry Andric 1880b57cec5SDimitry Andric void getCPUSpecificCPUDispatchFeatures( 1890b57cec5SDimitry Andric StringRef Name, 1900b57cec5SDimitry Andric llvm::SmallVectorImpl<StringRef> &Features) const override; 1910b57cec5SDimitry Andric 1925ffd83dbSDimitry Andric Optional<unsigned> getCPUCacheLineSize() const override; 1935ffd83dbSDimitry Andric 1940b57cec5SDimitry Andric bool validateAsmConstraint(const char *&Name, 1950b57cec5SDimitry Andric TargetInfo::ConstraintInfo &info) const override; 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, 1980b57cec5SDimitry Andric bool &HasSizeMismatch) const override { 1990b57cec5SDimitry Andric // esp and ebp are the only 32-bit registers the x86 backend can currently 2000b57cec5SDimitry Andric // handle. 2010b57cec5SDimitry Andric if (RegName.equals("esp") || RegName.equals("ebp")) { 2020b57cec5SDimitry Andric // Check that the register size is 32-bit. 2030b57cec5SDimitry Andric HasSizeMismatch = RegSize != 32; 2040b57cec5SDimitry Andric return true; 2050b57cec5SDimitry Andric } 2060b57cec5SDimitry Andric 2070b57cec5SDimitry Andric return false; 2080b57cec5SDimitry Andric } 2090b57cec5SDimitry Andric 210480093f4SDimitry Andric bool validateOutputSize(const llvm::StringMap<bool> &FeatureMap, 211480093f4SDimitry Andric StringRef Constraint, unsigned Size) const override; 2120b57cec5SDimitry Andric 213480093f4SDimitry Andric bool validateInputSize(const llvm::StringMap<bool> &FeatureMap, 214480093f4SDimitry Andric StringRef Constraint, unsigned Size) const override; 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andric virtual bool 2170b57cec5SDimitry Andric checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { 2180b57cec5SDimitry Andric return true; 2190b57cec5SDimitry Andric }; 2200b57cec5SDimitry Andric 2210b57cec5SDimitry Andric virtual bool 2220b57cec5SDimitry Andric checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override { 2230b57cec5SDimitry Andric return true; 2240b57cec5SDimitry Andric }; 2250b57cec5SDimitry Andric 226480093f4SDimitry Andric virtual bool validateOperandSize(const llvm::StringMap<bool> &FeatureMap, 227480093f4SDimitry Andric StringRef Constraint, unsigned Size) const; 2280b57cec5SDimitry Andric 2290b57cec5SDimitry Andric std::string convertConstraint(const char *&Constraint) const override; 2300b57cec5SDimitry Andric const char *getClobbers() const override { 2310b57cec5SDimitry Andric return "~{dirflag},~{fpsr},~{flags}"; 2320b57cec5SDimitry Andric } 2330b57cec5SDimitry Andric 2340b57cec5SDimitry Andric StringRef getConstraintRegister(StringRef Constraint, 2350b57cec5SDimitry Andric StringRef Expression) const override { 2360b57cec5SDimitry Andric StringRef::iterator I, E; 2370b57cec5SDimitry Andric for (I = Constraint.begin(), E = Constraint.end(); I != E; ++I) { 2380b57cec5SDimitry Andric if (isalpha(*I) || *I == '@') 2390b57cec5SDimitry Andric break; 2400b57cec5SDimitry Andric } 2410b57cec5SDimitry Andric if (I == E) 2420b57cec5SDimitry Andric return ""; 2430b57cec5SDimitry Andric switch (*I) { 2440b57cec5SDimitry Andric // For the register constraints, return the matching register name 2450b57cec5SDimitry Andric case 'a': 2460b57cec5SDimitry Andric return "ax"; 2470b57cec5SDimitry Andric case 'b': 2480b57cec5SDimitry Andric return "bx"; 2490b57cec5SDimitry Andric case 'c': 2500b57cec5SDimitry Andric return "cx"; 2510b57cec5SDimitry Andric case 'd': 2520b57cec5SDimitry Andric return "dx"; 2530b57cec5SDimitry Andric case 'S': 2540b57cec5SDimitry Andric return "si"; 2550b57cec5SDimitry Andric case 'D': 2560b57cec5SDimitry Andric return "di"; 2570b57cec5SDimitry Andric // In case the constraint is 'r' we need to return Expression 2580b57cec5SDimitry Andric case 'r': 2590b57cec5SDimitry Andric return Expression; 2600b57cec5SDimitry Andric // Double letters Y<x> constraints 2610b57cec5SDimitry Andric case 'Y': 2620b57cec5SDimitry Andric if ((++I != E) && ((*I == '0') || (*I == 'z'))) 2630b57cec5SDimitry Andric return "xmm0"; 2640b57cec5SDimitry Andric break; 2650b57cec5SDimitry Andric default: 2660b57cec5SDimitry Andric break; 2670b57cec5SDimitry Andric } 2680b57cec5SDimitry Andric return ""; 2690b57cec5SDimitry Andric } 2700b57cec5SDimitry Andric 2710b57cec5SDimitry Andric bool useFP16ConversionIntrinsics() const override { 2720b57cec5SDimitry Andric return false; 2730b57cec5SDimitry Andric } 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 2760b57cec5SDimitry Andric MacroBuilder &Builder) const override; 2770b57cec5SDimitry Andric 2780b57cec5SDimitry Andric void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name, 2795ffd83dbSDimitry Andric bool Enabled) const final; 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andric bool 2820b57cec5SDimitry Andric initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, 2830b57cec5SDimitry Andric StringRef CPU, 2840b57cec5SDimitry Andric const std::vector<std::string> &FeaturesVec) const override; 2850b57cec5SDimitry Andric 2860b57cec5SDimitry Andric bool isValidFeatureName(StringRef Name) const override; 2870b57cec5SDimitry Andric 2885ffd83dbSDimitry Andric bool hasFeature(StringRef Feature) const final; 2890b57cec5SDimitry Andric 2900b57cec5SDimitry Andric bool handleTargetFeatures(std::vector<std::string> &Features, 2910b57cec5SDimitry Andric DiagnosticsEngine &Diags) override; 2920b57cec5SDimitry Andric 2930b57cec5SDimitry Andric StringRef getABI() const override { 2940b57cec5SDimitry Andric if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX512F) 2950b57cec5SDimitry Andric return "avx512"; 2960b57cec5SDimitry Andric if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX) 2970b57cec5SDimitry Andric return "avx"; 2980b57cec5SDimitry Andric if (getTriple().getArch() == llvm::Triple::x86 && 2990b57cec5SDimitry Andric MMX3DNowLevel == NoMMX3DNow) 3000b57cec5SDimitry Andric return "no-mmx"; 3010b57cec5SDimitry Andric return ""; 3020b57cec5SDimitry Andric } 3030b57cec5SDimitry Andric 304*e8d8bef9SDimitry Andric bool supportsTargetAttributeTune() const override { 305*e8d8bef9SDimitry Andric return true; 306*e8d8bef9SDimitry Andric } 307*e8d8bef9SDimitry Andric 3080b57cec5SDimitry Andric bool isValidCPUName(StringRef Name) const override { 3095ffd83dbSDimitry Andric bool Only64Bit = getTriple().getArch() != llvm::Triple::x86; 3105ffd83dbSDimitry Andric return llvm::X86::parseArchX86(Name, Only64Bit) != llvm::X86::CK_None; 3110b57cec5SDimitry Andric } 3120b57cec5SDimitry Andric 313*e8d8bef9SDimitry Andric bool isValidTuneCPUName(StringRef Name) const override { 314*e8d8bef9SDimitry Andric if (Name == "generic") 315*e8d8bef9SDimitry Andric return true; 316*e8d8bef9SDimitry Andric 317*e8d8bef9SDimitry Andric // Allow 32-bit only CPUs regardless of 64-bit mode unlike isValidCPUName. 318*e8d8bef9SDimitry Andric // NOTE: gcc rejects 32-bit mtune CPUs in 64-bit mode. But being lenient 319*e8d8bef9SDimitry Andric // since mtune was ignored by clang for so long. 320*e8d8bef9SDimitry Andric return llvm::X86::parseTuneCPU(Name) != llvm::X86::CK_None; 321*e8d8bef9SDimitry Andric } 322*e8d8bef9SDimitry Andric 3230b57cec5SDimitry Andric void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; 324*e8d8bef9SDimitry Andric void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override; 3250b57cec5SDimitry Andric 3260b57cec5SDimitry Andric bool setCPU(const std::string &Name) override { 3275ffd83dbSDimitry Andric bool Only64Bit = getTriple().getArch() != llvm::Triple::x86; 3285ffd83dbSDimitry Andric CPU = llvm::X86::parseArchX86(Name, Only64Bit); 3295ffd83dbSDimitry Andric return CPU != llvm::X86::CK_None; 3300b57cec5SDimitry Andric } 3310b57cec5SDimitry Andric 3320b57cec5SDimitry Andric unsigned multiVersionSortPriority(StringRef Name) const override; 3330b57cec5SDimitry Andric 3340b57cec5SDimitry Andric bool setFPMath(StringRef Name) override; 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andric CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { 3370b57cec5SDimitry Andric // Most of the non-ARM calling conventions are i386 conventions. 3380b57cec5SDimitry Andric switch (CC) { 3390b57cec5SDimitry Andric case CC_X86ThisCall: 3400b57cec5SDimitry Andric case CC_X86FastCall: 3410b57cec5SDimitry Andric case CC_X86StdCall: 3420b57cec5SDimitry Andric case CC_X86VectorCall: 3430b57cec5SDimitry Andric case CC_X86RegCall: 3440b57cec5SDimitry Andric case CC_C: 3450b57cec5SDimitry Andric case CC_PreserveMost: 3460b57cec5SDimitry Andric case CC_Swift: 3470b57cec5SDimitry Andric case CC_X86Pascal: 3480b57cec5SDimitry Andric case CC_IntelOclBicc: 3490b57cec5SDimitry Andric case CC_OpenCLKernel: 3500b57cec5SDimitry Andric return CCCR_OK; 3510b57cec5SDimitry Andric default: 3520b57cec5SDimitry Andric return CCCR_Warning; 3530b57cec5SDimitry Andric } 3540b57cec5SDimitry Andric } 3550b57cec5SDimitry Andric 3560b57cec5SDimitry Andric CallingConv getDefaultCallingConv() const override { 3570b57cec5SDimitry Andric return CC_C; 3580b57cec5SDimitry Andric } 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andric bool hasSjLjLowering() const override { return true; } 3610b57cec5SDimitry Andric 362*e8d8bef9SDimitry Andric void setSupportedOpenCLOpts() override { supportAllOpenCLOpts(); } 363480093f4SDimitry Andric 364480093f4SDimitry Andric uint64_t getPointerWidthV(unsigned AddrSpace) const override { 365480093f4SDimitry Andric if (AddrSpace == ptr32_sptr || AddrSpace == ptr32_uptr) 366480093f4SDimitry Andric return 32; 367480093f4SDimitry Andric if (AddrSpace == ptr64) 368480093f4SDimitry Andric return 64; 369480093f4SDimitry Andric return PointerWidth; 370480093f4SDimitry Andric } 371480093f4SDimitry Andric 372480093f4SDimitry Andric uint64_t getPointerAlignV(unsigned AddrSpace) const override { 373480093f4SDimitry Andric return getPointerWidthV(AddrSpace); 374480093f4SDimitry Andric } 3750b57cec5SDimitry Andric }; 3760b57cec5SDimitry Andric 3770b57cec5SDimitry Andric // X86-32 generic target 3780b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY X86_32TargetInfo : public X86TargetInfo { 3790b57cec5SDimitry Andric public: 3800b57cec5SDimitry Andric X86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 3810b57cec5SDimitry Andric : X86TargetInfo(Triple, Opts) { 3820b57cec5SDimitry Andric DoubleAlign = LongLongAlign = 32; 3830b57cec5SDimitry Andric LongDoubleWidth = 96; 3840b57cec5SDimitry Andric LongDoubleAlign = 32; 3850b57cec5SDimitry Andric SuitableAlign = 128; 386*e8d8bef9SDimitry Andric resetDataLayout(Triple.isOSBinFormatMachO() ? 387*e8d8bef9SDimitry Andric "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-" 388*e8d8bef9SDimitry Andric "f80:32-n8:16:32-S128" : 389*e8d8bef9SDimitry Andric "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-" 390a7dea167SDimitry Andric "f80:32-n8:16:32-S128"); 3910b57cec5SDimitry Andric SizeType = UnsignedInt; 3920b57cec5SDimitry Andric PtrDiffType = SignedInt; 3930b57cec5SDimitry Andric IntPtrType = SignedInt; 3940b57cec5SDimitry Andric RegParmMax = 3; 3950b57cec5SDimitry Andric 3960b57cec5SDimitry Andric // Use fpret for all types. 3970b57cec5SDimitry Andric RealTypeUsesObjCFPRet = 3980b57cec5SDimitry Andric ((1 << TargetInfo::Float) | (1 << TargetInfo::Double) | 3990b57cec5SDimitry Andric (1 << TargetInfo::LongDouble)); 4000b57cec5SDimitry Andric 4010b57cec5SDimitry Andric // x86-32 has atomics up to 8 bytes 4020b57cec5SDimitry Andric MaxAtomicPromoteWidth = 64; 4030b57cec5SDimitry Andric MaxAtomicInlineWidth = 32; 4040b57cec5SDimitry Andric } 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andric BuiltinVaListKind getBuiltinVaListKind() const override { 4070b57cec5SDimitry Andric return TargetInfo::CharPtrBuiltinVaList; 4080b57cec5SDimitry Andric } 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andric int getEHDataRegisterNumber(unsigned RegNo) const override { 4110b57cec5SDimitry Andric if (RegNo == 0) 4120b57cec5SDimitry Andric return 0; 4130b57cec5SDimitry Andric if (RegNo == 1) 4140b57cec5SDimitry Andric return 2; 4150b57cec5SDimitry Andric return -1; 4160b57cec5SDimitry Andric } 4170b57cec5SDimitry Andric 418480093f4SDimitry Andric bool validateOperandSize(const llvm::StringMap<bool> &FeatureMap, 419480093f4SDimitry Andric StringRef Constraint, unsigned Size) const override { 4200b57cec5SDimitry Andric switch (Constraint[0]) { 4210b57cec5SDimitry Andric default: 4220b57cec5SDimitry Andric break; 4230b57cec5SDimitry Andric case 'R': 4240b57cec5SDimitry Andric case 'q': 4250b57cec5SDimitry Andric case 'Q': 4260b57cec5SDimitry Andric case 'a': 4270b57cec5SDimitry Andric case 'b': 4280b57cec5SDimitry Andric case 'c': 4290b57cec5SDimitry Andric case 'd': 4300b57cec5SDimitry Andric case 'S': 4310b57cec5SDimitry Andric case 'D': 4320b57cec5SDimitry Andric return Size <= 32; 4330b57cec5SDimitry Andric case 'A': 4340b57cec5SDimitry Andric return Size <= 64; 4350b57cec5SDimitry Andric } 4360b57cec5SDimitry Andric 437480093f4SDimitry Andric return X86TargetInfo::validateOperandSize(FeatureMap, Constraint, Size); 4380b57cec5SDimitry Andric } 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andric void setMaxAtomicWidth() override { 4410b57cec5SDimitry Andric if (hasFeature("cx8")) 4420b57cec5SDimitry Andric MaxAtomicInlineWidth = 64; 4430b57cec5SDimitry Andric } 4440b57cec5SDimitry Andric 4450b57cec5SDimitry Andric ArrayRef<Builtin::Info> getTargetBuiltins() const override; 4465ffd83dbSDimitry Andric 4475ffd83dbSDimitry Andric bool hasExtIntType() const override { return true; } 4480b57cec5SDimitry Andric }; 4490b57cec5SDimitry Andric 4500b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY NetBSDI386TargetInfo 4510b57cec5SDimitry Andric : public NetBSDTargetInfo<X86_32TargetInfo> { 4520b57cec5SDimitry Andric public: 4530b57cec5SDimitry Andric NetBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 4540b57cec5SDimitry Andric : NetBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) {} 4550b57cec5SDimitry Andric 4560b57cec5SDimitry Andric unsigned getFloatEvalMethod() const override { 4570b57cec5SDimitry Andric unsigned Major, Minor, Micro; 4580b57cec5SDimitry Andric getTriple().getOSVersion(Major, Minor, Micro); 4590b57cec5SDimitry Andric // New NetBSD uses the default rounding mode. 4600b57cec5SDimitry Andric if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 26) || Major == 0) 4610b57cec5SDimitry Andric return X86_32TargetInfo::getFloatEvalMethod(); 4620b57cec5SDimitry Andric // NetBSD before 6.99.26 defaults to "double" rounding. 4630b57cec5SDimitry Andric return 1; 4640b57cec5SDimitry Andric } 4650b57cec5SDimitry Andric }; 4660b57cec5SDimitry Andric 4670b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY OpenBSDI386TargetInfo 4680b57cec5SDimitry Andric : public OpenBSDTargetInfo<X86_32TargetInfo> { 4690b57cec5SDimitry Andric public: 4700b57cec5SDimitry Andric OpenBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 4710b57cec5SDimitry Andric : OpenBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) { 4720b57cec5SDimitry Andric SizeType = UnsignedLong; 4730b57cec5SDimitry Andric IntPtrType = SignedLong; 4740b57cec5SDimitry Andric PtrDiffType = SignedLong; 4750b57cec5SDimitry Andric } 4760b57cec5SDimitry Andric }; 4770b57cec5SDimitry Andric 4780b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY DarwinI386TargetInfo 4790b57cec5SDimitry Andric : public DarwinTargetInfo<X86_32TargetInfo> { 4800b57cec5SDimitry Andric public: 4810b57cec5SDimitry Andric DarwinI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 4820b57cec5SDimitry Andric : DarwinTargetInfo<X86_32TargetInfo>(Triple, Opts) { 4830b57cec5SDimitry Andric LongDoubleWidth = 128; 4840b57cec5SDimitry Andric LongDoubleAlign = 128; 4850b57cec5SDimitry Andric SuitableAlign = 128; 4860b57cec5SDimitry Andric MaxVectorAlign = 256; 4870b57cec5SDimitry Andric // The watchOS simulator uses the builtin bool type for Objective-C. 4880b57cec5SDimitry Andric llvm::Triple T = llvm::Triple(Triple); 4890b57cec5SDimitry Andric if (T.isWatchOS()) 4900b57cec5SDimitry Andric UseSignedCharForObjCBool = false; 4910b57cec5SDimitry Andric SizeType = UnsignedLong; 4920b57cec5SDimitry Andric IntPtrType = SignedLong; 493a7dea167SDimitry Andric resetDataLayout("e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-" 494a7dea167SDimitry Andric "f80:128-n8:16:32-S128"); 4950b57cec5SDimitry Andric HasAlignMac68kSupport = true; 4960b57cec5SDimitry Andric } 4970b57cec5SDimitry Andric 4980b57cec5SDimitry Andric bool handleTargetFeatures(std::vector<std::string> &Features, 4990b57cec5SDimitry Andric DiagnosticsEngine &Diags) override { 5000b57cec5SDimitry Andric if (!DarwinTargetInfo<X86_32TargetInfo>::handleTargetFeatures(Features, 5010b57cec5SDimitry Andric Diags)) 5020b57cec5SDimitry Andric return false; 5030b57cec5SDimitry Andric // We now know the features we have: we can decide how to align vectors. 5040b57cec5SDimitry Andric MaxVectorAlign = 5050b57cec5SDimitry Andric hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128; 5060b57cec5SDimitry Andric return true; 5070b57cec5SDimitry Andric } 5080b57cec5SDimitry Andric }; 5090b57cec5SDimitry Andric 5100b57cec5SDimitry Andric // x86-32 Windows target 5110b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY WindowsX86_32TargetInfo 5120b57cec5SDimitry Andric : public WindowsTargetInfo<X86_32TargetInfo> { 5130b57cec5SDimitry Andric public: 5140b57cec5SDimitry Andric WindowsX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 5150b57cec5SDimitry Andric : WindowsTargetInfo<X86_32TargetInfo>(Triple, Opts) { 5160b57cec5SDimitry Andric DoubleAlign = LongLongAlign = 64; 5170b57cec5SDimitry Andric bool IsWinCOFF = 5180b57cec5SDimitry Andric getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); 519a7dea167SDimitry Andric resetDataLayout(IsWinCOFF ? "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:" 520a7dea167SDimitry Andric "64-i64:64-f80:32-n8:16:32-a:0:32-S32" 521a7dea167SDimitry Andric : "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:" 522a7dea167SDimitry Andric "64-i64:64-f80:32-n8:16:32-a:0:32-S32"); 5230b57cec5SDimitry Andric } 5240b57cec5SDimitry Andric }; 5250b57cec5SDimitry Andric 5260b57cec5SDimitry Andric // x86-32 Windows Visual Studio target 5270b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MicrosoftX86_32TargetInfo 5280b57cec5SDimitry Andric : public WindowsX86_32TargetInfo { 5290b57cec5SDimitry Andric public: 5300b57cec5SDimitry Andric MicrosoftX86_32TargetInfo(const llvm::Triple &Triple, 5310b57cec5SDimitry Andric const TargetOptions &Opts) 5320b57cec5SDimitry Andric : WindowsX86_32TargetInfo(Triple, Opts) { 5330b57cec5SDimitry Andric LongDoubleWidth = LongDoubleAlign = 64; 5340b57cec5SDimitry Andric LongDoubleFormat = &llvm::APFloat::IEEEdouble(); 5350b57cec5SDimitry Andric } 5360b57cec5SDimitry Andric 5370b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 5380b57cec5SDimitry Andric MacroBuilder &Builder) const override { 5390b57cec5SDimitry Andric WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); 5400b57cec5SDimitry Andric // The value of the following reflects processor type. 5410b57cec5SDimitry Andric // 300=386, 400=486, 500=Pentium, 600=Blend (default) 5420b57cec5SDimitry Andric // We lost the original triple, so we use the default. 5430b57cec5SDimitry Andric Builder.defineMacro("_M_IX86", "600"); 5440b57cec5SDimitry Andric } 5450b57cec5SDimitry Andric }; 5460b57cec5SDimitry Andric 5470b57cec5SDimitry Andric // x86-32 MinGW target 5480b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MinGWX86_32TargetInfo 5490b57cec5SDimitry Andric : public WindowsX86_32TargetInfo { 5500b57cec5SDimitry Andric public: 5510b57cec5SDimitry Andric MinGWX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 5520b57cec5SDimitry Andric : WindowsX86_32TargetInfo(Triple, Opts) { 5530b57cec5SDimitry Andric HasFloat128 = true; 5540b57cec5SDimitry Andric } 5550b57cec5SDimitry Andric 5560b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 5570b57cec5SDimitry Andric MacroBuilder &Builder) const override { 5580b57cec5SDimitry Andric WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); 5590b57cec5SDimitry Andric Builder.defineMacro("_X86_"); 5600b57cec5SDimitry Andric } 5610b57cec5SDimitry Andric }; 5620b57cec5SDimitry Andric 5630b57cec5SDimitry Andric // x86-32 Cygwin target 5640b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : public X86_32TargetInfo { 5650b57cec5SDimitry Andric public: 5660b57cec5SDimitry Andric CygwinX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 5670b57cec5SDimitry Andric : X86_32TargetInfo(Triple, Opts) { 5680b57cec5SDimitry Andric this->WCharType = TargetInfo::UnsignedShort; 5690b57cec5SDimitry Andric DoubleAlign = LongLongAlign = 64; 570a7dea167SDimitry Andric resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:" 571a7dea167SDimitry Andric "32-n8:16:32-a:0:32-S32"); 5720b57cec5SDimitry Andric } 5730b57cec5SDimitry Andric 5740b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 5750b57cec5SDimitry Andric MacroBuilder &Builder) const override { 5760b57cec5SDimitry Andric X86_32TargetInfo::getTargetDefines(Opts, Builder); 5770b57cec5SDimitry Andric Builder.defineMacro("_X86_"); 5780b57cec5SDimitry Andric Builder.defineMacro("__CYGWIN__"); 5790b57cec5SDimitry Andric Builder.defineMacro("__CYGWIN32__"); 5800b57cec5SDimitry Andric addCygMingDefines(Opts, Builder); 5810b57cec5SDimitry Andric DefineStd(Builder, "unix", Opts); 5820b57cec5SDimitry Andric if (Opts.CPlusPlus) 5830b57cec5SDimitry Andric Builder.defineMacro("_GNU_SOURCE"); 5840b57cec5SDimitry Andric } 5850b57cec5SDimitry Andric }; 5860b57cec5SDimitry Andric 5870b57cec5SDimitry Andric // x86-32 Haiku target 5880b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY HaikuX86_32TargetInfo 5890b57cec5SDimitry Andric : public HaikuTargetInfo<X86_32TargetInfo> { 5900b57cec5SDimitry Andric public: 5910b57cec5SDimitry Andric HaikuX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 5920b57cec5SDimitry Andric : HaikuTargetInfo<X86_32TargetInfo>(Triple, Opts) {} 5930b57cec5SDimitry Andric 5940b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 5950b57cec5SDimitry Andric MacroBuilder &Builder) const override { 5960b57cec5SDimitry Andric HaikuTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder); 5970b57cec5SDimitry Andric Builder.defineMacro("__INTEL__"); 5980b57cec5SDimitry Andric } 5990b57cec5SDimitry Andric }; 6000b57cec5SDimitry Andric 6010b57cec5SDimitry Andric // X86-32 MCU target 6020b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MCUX86_32TargetInfo : public X86_32TargetInfo { 6030b57cec5SDimitry Andric public: 6040b57cec5SDimitry Andric MCUX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 6050b57cec5SDimitry Andric : X86_32TargetInfo(Triple, Opts) { 6060b57cec5SDimitry Andric LongDoubleWidth = 64; 6070b57cec5SDimitry Andric LongDoubleFormat = &llvm::APFloat::IEEEdouble(); 608a7dea167SDimitry Andric resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-f64:" 609a7dea167SDimitry Andric "32-f128:32-n8:16:32-a:0:32-S32"); 6100b57cec5SDimitry Andric WIntType = UnsignedInt; 6110b57cec5SDimitry Andric } 6120b57cec5SDimitry Andric 6130b57cec5SDimitry Andric CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { 6140b57cec5SDimitry Andric // On MCU we support only C calling convention. 6150b57cec5SDimitry Andric return CC == CC_C ? CCCR_OK : CCCR_Warning; 6160b57cec5SDimitry Andric } 6170b57cec5SDimitry Andric 6180b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 6190b57cec5SDimitry Andric MacroBuilder &Builder) const override { 6200b57cec5SDimitry Andric X86_32TargetInfo::getTargetDefines(Opts, Builder); 6210b57cec5SDimitry Andric Builder.defineMacro("__iamcu"); 6220b57cec5SDimitry Andric Builder.defineMacro("__iamcu__"); 6230b57cec5SDimitry Andric } 6240b57cec5SDimitry Andric 6250b57cec5SDimitry Andric bool allowsLargerPreferedTypeAlignment() const override { return false; } 6260b57cec5SDimitry Andric }; 6270b57cec5SDimitry Andric 6280b57cec5SDimitry Andric // x86-32 RTEMS target 6290b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY RTEMSX86_32TargetInfo : public X86_32TargetInfo { 6300b57cec5SDimitry Andric public: 6310b57cec5SDimitry Andric RTEMSX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 6320b57cec5SDimitry Andric : X86_32TargetInfo(Triple, Opts) { 6330b57cec5SDimitry Andric SizeType = UnsignedLong; 6340b57cec5SDimitry Andric IntPtrType = SignedLong; 6350b57cec5SDimitry Andric PtrDiffType = SignedLong; 6360b57cec5SDimitry Andric } 6370b57cec5SDimitry Andric 6380b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 6390b57cec5SDimitry Andric MacroBuilder &Builder) const override { 6400b57cec5SDimitry Andric X86_32TargetInfo::getTargetDefines(Opts, Builder); 6410b57cec5SDimitry Andric Builder.defineMacro("__INTEL__"); 6420b57cec5SDimitry Andric Builder.defineMacro("__rtems__"); 6430b57cec5SDimitry Andric } 6440b57cec5SDimitry Andric }; 6450b57cec5SDimitry Andric 6460b57cec5SDimitry Andric // x86-64 generic target 6470b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { 6480b57cec5SDimitry Andric public: 6490b57cec5SDimitry Andric X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 6500b57cec5SDimitry Andric : X86TargetInfo(Triple, Opts) { 6510b57cec5SDimitry Andric const bool IsX32 = getTriple().getEnvironment() == llvm::Triple::GNUX32; 6520b57cec5SDimitry Andric bool IsWinCOFF = 6530b57cec5SDimitry Andric getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); 6540b57cec5SDimitry Andric LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; 6550b57cec5SDimitry Andric LongDoubleWidth = 128; 6560b57cec5SDimitry Andric LongDoubleAlign = 128; 6570b57cec5SDimitry Andric LargeArrayMinWidth = 128; 6580b57cec5SDimitry Andric LargeArrayAlign = 128; 6590b57cec5SDimitry Andric SuitableAlign = 128; 6600b57cec5SDimitry Andric SizeType = IsX32 ? UnsignedInt : UnsignedLong; 6610b57cec5SDimitry Andric PtrDiffType = IsX32 ? SignedInt : SignedLong; 6620b57cec5SDimitry Andric IntPtrType = IsX32 ? SignedInt : SignedLong; 6630b57cec5SDimitry Andric IntMaxType = IsX32 ? SignedLongLong : SignedLong; 6640b57cec5SDimitry Andric Int64Type = IsX32 ? SignedLongLong : SignedLong; 6650b57cec5SDimitry Andric RegParmMax = 6; 6660b57cec5SDimitry Andric 6670b57cec5SDimitry Andric // Pointers are 32-bit in x32. 668a7dea167SDimitry Andric resetDataLayout(IsX32 ? "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-" 669a7dea167SDimitry Andric "i64:64-f80:128-n8:16:32:64-S128" 670a7dea167SDimitry Andric : IsWinCOFF ? "e-m:w-p270:32:32-p271:32:32-p272:64:" 671a7dea167SDimitry Andric "64-i64:64-f80:128-n8:16:32:64-S128" 672a7dea167SDimitry Andric : "e-m:e-p270:32:32-p271:32:32-p272:64:" 673a7dea167SDimitry Andric "64-i64:64-f80:128-n8:16:32:64-S128"); 6740b57cec5SDimitry Andric 6750b57cec5SDimitry Andric // Use fpret only for long double. 6760b57cec5SDimitry Andric RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble); 6770b57cec5SDimitry Andric 6780b57cec5SDimitry Andric // Use fp2ret for _Complex long double. 6790b57cec5SDimitry Andric ComplexLongDoubleUsesFP2Ret = true; 6800b57cec5SDimitry Andric 6810b57cec5SDimitry Andric // Make __builtin_ms_va_list available. 6820b57cec5SDimitry Andric HasBuiltinMSVaList = true; 6830b57cec5SDimitry Andric 6840b57cec5SDimitry Andric // x86-64 has atomics up to 16 bytes. 6850b57cec5SDimitry Andric MaxAtomicPromoteWidth = 128; 6860b57cec5SDimitry Andric MaxAtomicInlineWidth = 64; 6870b57cec5SDimitry Andric } 6880b57cec5SDimitry Andric 6890b57cec5SDimitry Andric BuiltinVaListKind getBuiltinVaListKind() const override { 6900b57cec5SDimitry Andric return TargetInfo::X86_64ABIBuiltinVaList; 6910b57cec5SDimitry Andric } 6920b57cec5SDimitry Andric 6930b57cec5SDimitry Andric int getEHDataRegisterNumber(unsigned RegNo) const override { 6940b57cec5SDimitry Andric if (RegNo == 0) 6950b57cec5SDimitry Andric return 0; 6960b57cec5SDimitry Andric if (RegNo == 1) 6970b57cec5SDimitry Andric return 1; 6980b57cec5SDimitry Andric return -1; 6990b57cec5SDimitry Andric } 7000b57cec5SDimitry Andric 7010b57cec5SDimitry Andric CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { 7020b57cec5SDimitry Andric switch (CC) { 7030b57cec5SDimitry Andric case CC_C: 7040b57cec5SDimitry Andric case CC_Swift: 7050b57cec5SDimitry Andric case CC_X86VectorCall: 7060b57cec5SDimitry Andric case CC_IntelOclBicc: 7070b57cec5SDimitry Andric case CC_Win64: 7080b57cec5SDimitry Andric case CC_PreserveMost: 7090b57cec5SDimitry Andric case CC_PreserveAll: 7100b57cec5SDimitry Andric case CC_X86RegCall: 7110b57cec5SDimitry Andric case CC_OpenCLKernel: 7120b57cec5SDimitry Andric return CCCR_OK; 7130b57cec5SDimitry Andric default: 7140b57cec5SDimitry Andric return CCCR_Warning; 7150b57cec5SDimitry Andric } 7160b57cec5SDimitry Andric } 7170b57cec5SDimitry Andric 7180b57cec5SDimitry Andric CallingConv getDefaultCallingConv() const override { 7190b57cec5SDimitry Andric return CC_C; 7200b57cec5SDimitry Andric } 7210b57cec5SDimitry Andric 7220b57cec5SDimitry Andric // for x32 we need it here explicitly 7230b57cec5SDimitry Andric bool hasInt128Type() const override { return true; } 7240b57cec5SDimitry Andric 7250b57cec5SDimitry Andric unsigned getUnwindWordWidth() const override { return 64; } 7260b57cec5SDimitry Andric 7270b57cec5SDimitry Andric unsigned getRegisterWidth() const override { return 64; } 7280b57cec5SDimitry Andric 7290b57cec5SDimitry Andric bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, 7300b57cec5SDimitry Andric bool &HasSizeMismatch) const override { 7310b57cec5SDimitry Andric // rsp and rbp are the only 64-bit registers the x86 backend can currently 7320b57cec5SDimitry Andric // handle. 7330b57cec5SDimitry Andric if (RegName.equals("rsp") || RegName.equals("rbp")) { 7340b57cec5SDimitry Andric // Check that the register size is 64-bit. 7350b57cec5SDimitry Andric HasSizeMismatch = RegSize != 64; 7360b57cec5SDimitry Andric return true; 7370b57cec5SDimitry Andric } 7380b57cec5SDimitry Andric 7390b57cec5SDimitry Andric // Check if the register is a 32-bit register the backend can handle. 7400b57cec5SDimitry Andric return X86TargetInfo::validateGlobalRegisterVariable(RegName, RegSize, 7410b57cec5SDimitry Andric HasSizeMismatch); 7420b57cec5SDimitry Andric } 7430b57cec5SDimitry Andric 7440b57cec5SDimitry Andric void setMaxAtomicWidth() override { 7450b57cec5SDimitry Andric if (hasFeature("cx16")) 7460b57cec5SDimitry Andric MaxAtomicInlineWidth = 128; 7470b57cec5SDimitry Andric } 7480b57cec5SDimitry Andric 7490b57cec5SDimitry Andric ArrayRef<Builtin::Info> getTargetBuiltins() const override; 7505ffd83dbSDimitry Andric 7515ffd83dbSDimitry Andric bool hasExtIntType() const override { return true; } 7520b57cec5SDimitry Andric }; 7530b57cec5SDimitry Andric 7540b57cec5SDimitry Andric // x86-64 Windows target 7550b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo 7560b57cec5SDimitry Andric : public WindowsTargetInfo<X86_64TargetInfo> { 7570b57cec5SDimitry Andric public: 7580b57cec5SDimitry Andric WindowsX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 7590b57cec5SDimitry Andric : WindowsTargetInfo<X86_64TargetInfo>(Triple, Opts) { 7600b57cec5SDimitry Andric LongWidth = LongAlign = 32; 7610b57cec5SDimitry Andric DoubleAlign = LongLongAlign = 64; 7620b57cec5SDimitry Andric IntMaxType = SignedLongLong; 7630b57cec5SDimitry Andric Int64Type = SignedLongLong; 7640b57cec5SDimitry Andric SizeType = UnsignedLongLong; 7650b57cec5SDimitry Andric PtrDiffType = SignedLongLong; 7660b57cec5SDimitry Andric IntPtrType = SignedLongLong; 7670b57cec5SDimitry Andric } 7680b57cec5SDimitry Andric 7690b57cec5SDimitry Andric BuiltinVaListKind getBuiltinVaListKind() const override { 7700b57cec5SDimitry Andric return TargetInfo::CharPtrBuiltinVaList; 7710b57cec5SDimitry Andric } 7720b57cec5SDimitry Andric 7730b57cec5SDimitry Andric CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { 7740b57cec5SDimitry Andric switch (CC) { 7750b57cec5SDimitry Andric case CC_X86StdCall: 7760b57cec5SDimitry Andric case CC_X86ThisCall: 7770b57cec5SDimitry Andric case CC_X86FastCall: 7780b57cec5SDimitry Andric return CCCR_Ignore; 7790b57cec5SDimitry Andric case CC_C: 7800b57cec5SDimitry Andric case CC_X86VectorCall: 7810b57cec5SDimitry Andric case CC_IntelOclBicc: 7820b57cec5SDimitry Andric case CC_PreserveMost: 7830b57cec5SDimitry Andric case CC_PreserveAll: 7840b57cec5SDimitry Andric case CC_X86_64SysV: 7850b57cec5SDimitry Andric case CC_Swift: 7860b57cec5SDimitry Andric case CC_X86RegCall: 7870b57cec5SDimitry Andric case CC_OpenCLKernel: 7880b57cec5SDimitry Andric return CCCR_OK; 7890b57cec5SDimitry Andric default: 7900b57cec5SDimitry Andric return CCCR_Warning; 7910b57cec5SDimitry Andric } 7920b57cec5SDimitry Andric } 7930b57cec5SDimitry Andric }; 7940b57cec5SDimitry Andric 7950b57cec5SDimitry Andric // x86-64 Windows Visual Studio target 7960b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64TargetInfo 7970b57cec5SDimitry Andric : public WindowsX86_64TargetInfo { 7980b57cec5SDimitry Andric public: 7990b57cec5SDimitry Andric MicrosoftX86_64TargetInfo(const llvm::Triple &Triple, 8000b57cec5SDimitry Andric const TargetOptions &Opts) 8010b57cec5SDimitry Andric : WindowsX86_64TargetInfo(Triple, Opts) { 8020b57cec5SDimitry Andric LongDoubleWidth = LongDoubleAlign = 64; 8030b57cec5SDimitry Andric LongDoubleFormat = &llvm::APFloat::IEEEdouble(); 8040b57cec5SDimitry Andric } 8050b57cec5SDimitry Andric 8060b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 8070b57cec5SDimitry Andric MacroBuilder &Builder) const override { 8080b57cec5SDimitry Andric WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); 8090b57cec5SDimitry Andric Builder.defineMacro("_M_X64", "100"); 8100b57cec5SDimitry Andric Builder.defineMacro("_M_AMD64", "100"); 8110b57cec5SDimitry Andric } 8120b57cec5SDimitry Andric 8130b57cec5SDimitry Andric TargetInfo::CallingConvKind 8140b57cec5SDimitry Andric getCallingConvKind(bool ClangABICompat4) const override { 8150b57cec5SDimitry Andric return CCK_MicrosoftWin64; 8160b57cec5SDimitry Andric } 8170b57cec5SDimitry Andric }; 8180b57cec5SDimitry Andric 8190b57cec5SDimitry Andric // x86-64 MinGW target 8200b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MinGWX86_64TargetInfo 8210b57cec5SDimitry Andric : public WindowsX86_64TargetInfo { 8220b57cec5SDimitry Andric public: 8230b57cec5SDimitry Andric MinGWX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 8240b57cec5SDimitry Andric : WindowsX86_64TargetInfo(Triple, Opts) { 8250b57cec5SDimitry Andric // Mingw64 rounds long double size and alignment up to 16 bytes, but sticks 8260b57cec5SDimitry Andric // with x86 FP ops. Weird. 8270b57cec5SDimitry Andric LongDoubleWidth = LongDoubleAlign = 128; 8280b57cec5SDimitry Andric LongDoubleFormat = &llvm::APFloat::x87DoubleExtended(); 8290b57cec5SDimitry Andric HasFloat128 = true; 8300b57cec5SDimitry Andric } 8310b57cec5SDimitry Andric }; 8320b57cec5SDimitry Andric 8330b57cec5SDimitry Andric // x86-64 Cygwin target 8340b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo { 8350b57cec5SDimitry Andric public: 8360b57cec5SDimitry Andric CygwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 8370b57cec5SDimitry Andric : X86_64TargetInfo(Triple, Opts) { 8380b57cec5SDimitry Andric this->WCharType = TargetInfo::UnsignedShort; 8390b57cec5SDimitry Andric TLSSupported = false; 8400b57cec5SDimitry Andric } 8410b57cec5SDimitry Andric 8420b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 8430b57cec5SDimitry Andric MacroBuilder &Builder) const override { 8440b57cec5SDimitry Andric X86_64TargetInfo::getTargetDefines(Opts, Builder); 8450b57cec5SDimitry Andric Builder.defineMacro("__x86_64__"); 8460b57cec5SDimitry Andric Builder.defineMacro("__CYGWIN__"); 8470b57cec5SDimitry Andric Builder.defineMacro("__CYGWIN64__"); 8480b57cec5SDimitry Andric addCygMingDefines(Opts, Builder); 8490b57cec5SDimitry Andric DefineStd(Builder, "unix", Opts); 8500b57cec5SDimitry Andric if (Opts.CPlusPlus) 8510b57cec5SDimitry Andric Builder.defineMacro("_GNU_SOURCE"); 8520b57cec5SDimitry Andric } 8530b57cec5SDimitry Andric }; 8540b57cec5SDimitry Andric 8550b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY DarwinX86_64TargetInfo 8560b57cec5SDimitry Andric : public DarwinTargetInfo<X86_64TargetInfo> { 8570b57cec5SDimitry Andric public: 8580b57cec5SDimitry Andric DarwinX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 8590b57cec5SDimitry Andric : DarwinTargetInfo<X86_64TargetInfo>(Triple, Opts) { 8600b57cec5SDimitry Andric Int64Type = SignedLongLong; 8610b57cec5SDimitry Andric // The 64-bit iOS simulator uses the builtin bool type for Objective-C. 8620b57cec5SDimitry Andric llvm::Triple T = llvm::Triple(Triple); 8630b57cec5SDimitry Andric if (T.isiOS()) 8640b57cec5SDimitry Andric UseSignedCharForObjCBool = false; 865a7dea167SDimitry Andric resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:" 866a7dea167SDimitry Andric "16:32:64-S128"); 8670b57cec5SDimitry Andric } 8680b57cec5SDimitry Andric 8690b57cec5SDimitry Andric bool handleTargetFeatures(std::vector<std::string> &Features, 8700b57cec5SDimitry Andric DiagnosticsEngine &Diags) override { 8710b57cec5SDimitry Andric if (!DarwinTargetInfo<X86_64TargetInfo>::handleTargetFeatures(Features, 8720b57cec5SDimitry Andric Diags)) 8730b57cec5SDimitry Andric return false; 8740b57cec5SDimitry Andric // We now know the features we have: we can decide how to align vectors. 8750b57cec5SDimitry Andric MaxVectorAlign = 8760b57cec5SDimitry Andric hasFeature("avx512f") ? 512 : hasFeature("avx") ? 256 : 128; 8770b57cec5SDimitry Andric return true; 8780b57cec5SDimitry Andric } 8790b57cec5SDimitry Andric }; 8800b57cec5SDimitry Andric 8810b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY OpenBSDX86_64TargetInfo 8820b57cec5SDimitry Andric : public OpenBSDTargetInfo<X86_64TargetInfo> { 8830b57cec5SDimitry Andric public: 8840b57cec5SDimitry Andric OpenBSDX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 8850b57cec5SDimitry Andric : OpenBSDTargetInfo<X86_64TargetInfo>(Triple, Opts) { 8860b57cec5SDimitry Andric IntMaxType = SignedLongLong; 8870b57cec5SDimitry Andric Int64Type = SignedLongLong; 8880b57cec5SDimitry Andric } 8890b57cec5SDimitry Andric }; 8900b57cec5SDimitry Andric 8910b57cec5SDimitry Andric // x86_32 Android target 8920b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY AndroidX86_32TargetInfo 8930b57cec5SDimitry Andric : public LinuxTargetInfo<X86_32TargetInfo> { 8940b57cec5SDimitry Andric public: 8950b57cec5SDimitry Andric AndroidX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 8960b57cec5SDimitry Andric : LinuxTargetInfo<X86_32TargetInfo>(Triple, Opts) { 8970b57cec5SDimitry Andric SuitableAlign = 32; 8980b57cec5SDimitry Andric LongDoubleWidth = 64; 8990b57cec5SDimitry Andric LongDoubleFormat = &llvm::APFloat::IEEEdouble(); 9000b57cec5SDimitry Andric } 9010b57cec5SDimitry Andric }; 9020b57cec5SDimitry Andric 9030b57cec5SDimitry Andric // x86_64 Android target 9040b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY AndroidX86_64TargetInfo 9050b57cec5SDimitry Andric : public LinuxTargetInfo<X86_64TargetInfo> { 9060b57cec5SDimitry Andric public: 9070b57cec5SDimitry Andric AndroidX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 9080b57cec5SDimitry Andric : LinuxTargetInfo<X86_64TargetInfo>(Triple, Opts) { 9090b57cec5SDimitry Andric LongDoubleFormat = &llvm::APFloat::IEEEquad(); 9100b57cec5SDimitry Andric } 9110b57cec5SDimitry Andric }; 9120b57cec5SDimitry Andric } // namespace targets 9130b57cec5SDimitry Andric } // namespace clang 9140b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_BASIC_TARGETS_X86_H 915