From: Derek Schuff Date: Thu, 11 Oct 2012 15:52:22 +0000 (+0000) Subject: Make X86_64ABIInfo clean for ABIs with 32 bit pointers, such as X32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=babaf31d401310464db93627ef6b195a7ffb1029;p=clang Make X86_64ABIInfo clean for ABIs with 32 bit pointers, such as X32 and Native Client git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165715 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index bc32d75d79..4948ba45b6 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -1551,9 +1551,10 @@ public: virtual bool hasFeature(StringRef Feature) const; virtual void HandleTargetFeatures(std::vector &Features); virtual const char* getABI() const { - if (PointerWidth == 64 && SSELevel >= AVX) + if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX) return "avx"; - else if (PointerWidth == 32 && MMX3DNowLevel == NoMMX3DNow) + else if (getTriple().getArch() == llvm::Triple::x86 && + MMX3DNowLevel == NoMMX3DNow) return "no-mmx"; return ""; } @@ -1647,7 +1648,7 @@ public: case CK_AthlonMP: case CK_Geode: // Only accept certain architectures when compiling in 32-bit mode. - if (PointerWidth != 32) + if (getTriple().getArch() != llvm::Triple::x86) return false; // Fallthrough @@ -1719,7 +1720,7 @@ void X86TargetInfo::getDefaultFeatures(llvm::StringMap &Features) const { // FIXME: This *really* should not be here. // X86_64 always has SSE2. - if (PointerWidth == 64) + if (getTriple().getArch() == llvm::Triple::x86_64) Features["sse2"] = Features["sse"] = Features["mmx"] = true; switch (CPU) { @@ -2101,7 +2102,7 @@ void X86TargetInfo::HandleTargetFeatures(std::vector &Features) { void X86TargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { // Target identification. - if (PointerWidth == 64) { + if (getTriple().getArch() == llvm::Triple::x86_64) { Builder.defineMacro("__amd64__"); Builder.defineMacro("__amd64"); Builder.defineMacro("__x86_64"); @@ -2300,7 +2301,7 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, break; } - if (Opts.MicrosoftExt && PointerWidth == 32) { + if (Opts.MicrosoftExt && getTriple().getArch() == llvm::Triple::x86) { switch (SSELevel) { case AVX2: case AVX: @@ -2356,8 +2357,8 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const { .Case("sse42", SSELevel >= SSE42) .Case("sse4a", HasSSE4a) .Case("x86", true) - .Case("x86_32", PointerWidth == 32) - .Case("x86_64", PointerWidth == 64) + .Case("x86_32", getTriple().getArch() == llvm::Triple::x86) + .Case("x86_64", getTriple().getArch() == llvm::Triple::x86_64) .Case("xop", HasXOP) .Case("f16c", HasF16C) .Default(false); diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 8aa8b90f96..3136245a9a 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -1115,10 +1115,15 @@ class X86_64ABIInfo : public ABIInfo { } bool HasAVX; + // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on + // 64-bit hardware. + bool Has64BitPointers; public: X86_64ABIInfo(CodeGen::CodeGenTypes &CGT, bool hasavx) : - ABIInfo(CGT), HasAVX(hasavx) {} + ABIInfo(CGT), HasAVX(hasavx), + Has64BitPointers(CGT.getDataLayout().getPointerSize() == 8) { + } bool isPassedUsingAVXType(QualType type) const { unsigned neededInt, neededSSE; @@ -1155,7 +1160,7 @@ public: class X86_64TargetCodeGenInfo : public TargetCodeGenInfo { public: X86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, bool HasAVX) - : TargetCodeGenInfo(new X86_64ABIInfo(CGT, HasAVX)) {} + : TargetCodeGenInfo(new X86_64ABIInfo(CGT, HasAVX)) {} const X86_64ABIInfo &getABIInfo() const { return static_cast(TargetCodeGenInfo::getABIInfo()); @@ -1351,7 +1356,7 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, } if (Ty->isMemberPointerType()) { - if (Ty->isMemberFunctionPointerType()) + if (Ty->isMemberFunctionPointerType() && Has64BitPointers) Lo = Hi = Integer; else Current = Integer; @@ -1862,7 +1867,8 @@ GetINTEGERTypeAtOffset(llvm::Type *IRType, unsigned IROffset, // returning an 8-byte unit starting with it. See if we can safely use it. if (IROffset == 0) { // Pointers and int64's always fill the 8-byte unit. - if (isa(IRType) || IRType->isIntegerTy(64)) + if ((isa(IRType) && Has64BitPointers) || + IRType->isIntegerTy(64)) return IRType; // If we have a 1/2/4-byte integer, we can use it only if the rest of the @@ -1872,8 +1878,10 @@ GetINTEGERTypeAtOffset(llvm::Type *IRType, unsigned IROffset, // have to do this analysis on the source type because we can't depend on // unions being lowered a specific way etc. if (IRType->isIntegerTy(8) || IRType->isIntegerTy(16) || - IRType->isIntegerTy(32)) { - unsigned BitWidth = cast(IRType)->getBitWidth(); + IRType->isIntegerTy(32) || + (isa(IRType) && !Has64BitPointers)) { + unsigned BitWidth = isa(IRType) ? 32 : + cast(IRType)->getBitWidth(); if (BitsContainNoUserData(SourceTy, SourceOffset*8+BitWidth, SourceOffset*8+64, getContext()))