Author: arsenm Date: Wed Sep 7 02:08:02 2016 New Revision: 280787 URL: http://llvm.org/viewvc/llvm-project?rev=280787&view=rev Log: OpenCL: Defining __ENDIAN_LITTLE__ and fix target endianness
OpenCL requires __ENDIAN_LITTLE__ be set for little endian targets. The default for targets was also apparently big endian, so AMDGPU was incorrectly reported as big endian. Set this from the triple so targets don't have another place to set the endianness. Modified: cfe/trunk/include/clang/Basic/TargetInfo.h cfe/trunk/lib/Basic/TargetInfo.cpp cfe/trunk/lib/Basic/Targets.cpp cfe/trunk/lib/Frontend/InitPreprocessor.cpp cfe/trunk/test/Preprocessor/init.c Modified: cfe/trunk/include/clang/Basic/TargetInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=280787&r1=280786&r2=280787&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/TargetInfo.h (original) +++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Sep 7 02:08:02 2016 @@ -939,6 +939,7 @@ public: VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; } bool isBigEndian() const { return BigEndian; } + bool isLittleEndian() const { return !BigEndian; } enum CallingConvMethodType { CCMT_Unknown, Modified: cfe/trunk/lib/Basic/TargetInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=280787&r1=280786&r2=280787&view=diff ============================================================================== --- cfe/trunk/lib/Basic/TargetInfo.cpp (original) +++ cfe/trunk/lib/Basic/TargetInfo.cpp Wed Sep 7 02:08:02 2016 @@ -27,7 +27,7 @@ static const LangAS::Map DefaultAddrSpac TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) { // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or // SPARC. These should be overridden by concrete targets as needed. - BigEndian = true; + BigEndian = !T.isLittleEndian(); TLSSupported = true; NoAsmVariants = false; HasFloat128 = false; Modified: cfe/trunk/lib/Basic/Targets.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=280787&r1=280786&r2=280787&view=diff ============================================================================== --- cfe/trunk/lib/Basic/Targets.cpp (original) +++ cfe/trunk/lib/Basic/Targets.cpp Wed Sep 7 02:08:02 2016 @@ -879,7 +879,6 @@ public: : TargetInfo(Triple), HasVSX(false), HasP8Vector(false), HasP8Crypto(false), HasDirectMove(false), HasQPX(false), HasHTM(false), HasBPERMD(false), HasExtDiv(false) { - BigEndian = (Triple.getArch() != llvm::Triple::ppc64le); SimdDefaultAlign = 128; LongDoubleWidth = LongDoubleAlign = 128; LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble; @@ -1712,7 +1711,6 @@ class NVPTXTargetInfo : public TargetInf public: NVPTXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : TargetInfo(Triple) { - BigEndian = false; TLSSupported = false; LongWidth = LongAlign = 64; AddrSpaceMap = &NVPTXAddrSpaceMap; @@ -2663,7 +2661,6 @@ class X86TargetInfo : public TargetInfo public: X86TargetInfo(const llvm::Triple &Triple, const TargetOptions &) : TargetInfo(Triple) { - BigEndian = false; LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; } unsigned getFloatEvalMethod() const override { @@ -4878,11 +4875,9 @@ class ARMTargetInfo : public TargetInfo } public: - ARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts, - bool IsBigEndian) + ARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : TargetInfo(Triple), FPMath(FP_Default), IsAAPCS(true), LDREX(0), HW_FP(0) { - BigEndian = IsBigEndian; switch (getTriple().getOS()) { case llvm::Triple::NetBSD: @@ -5522,7 +5517,7 @@ const Builtin::Info ARMTargetInfo::Built class ARMleTargetInfo : public ARMTargetInfo { public: ARMleTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : ARMTargetInfo(Triple, Opts, /*BigEndian=*/false) {} + : ARMTargetInfo(Triple, Opts) {} void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override { Builder.defineMacro("__ARMEL__"); @@ -5533,7 +5528,7 @@ public: class ARMbeTargetInfo : public ARMTargetInfo { public: ARMbeTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : ARMTargetInfo(Triple, Opts, /*BigEndian=*/true) {} + : ARMTargetInfo(Triple, Opts) {} void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override { Builder.defineMacro("__ARMEB__"); @@ -6044,7 +6039,6 @@ class AArch64leTargetInfo : public AArch public: AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : AArch64TargetInfo(Triple, Opts) { - BigEndian = false; } void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override { @@ -6116,7 +6110,6 @@ class HexagonTargetInfo : public TargetI public: HexagonTargetInfo(const llvm::Triple &Triple, const TargetOptions &) : TargetInfo(Triple) { - BigEndian = false; // Specify the vector alignment explicitly. For v512x1, the calculated // alignment would be 512*alignment(i1), which is 512 bytes, instead of // the required minimum of 64 bytes. @@ -6746,7 +6739,6 @@ class SparcV8elTargetInfo : public Sparc SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : SparcV8TargetInfo(Triple, Opts) { resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32-S64"); - BigEndian = false; } }; @@ -6981,7 +6973,6 @@ class MSP430TargetInfo : public TargetIn public: MSP430TargetInfo(const llvm::Triple &Triple, const TargetOptions &) : TargetInfo(Triple) { - BigEndian = false; TLSSupported = false; IntWidth = 16; IntAlign = 16; @@ -7131,10 +7122,8 @@ public: Int64Type = SignedLong; RegParmMax = 5; if (Triple.getArch() == llvm::Triple::bpfeb) { - BigEndian = true; resetDataLayout("E-m:e-p:64:64-i64:64-n32:64-S128"); } else { - BigEndian = false; resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128"); } MaxAtomicPromoteWidth = 64; @@ -7213,8 +7202,6 @@ public: IsNan2008(false), IsSingleFloat(false), FloatABI(HardFloat), DspRev(NoDSP), HasMSA(false), HasFP64(false) { TheCXXABI.set(TargetCXXABI::GenericMIPS); - BigEndian = getTriple().getArch() == llvm::Triple::mips || - getTriple().getArch() == llvm::Triple::mips64; setABI((getTriple().getArch() == llvm::Triple::mips || getTriple().getArch() == llvm::Triple::mipsel) @@ -7717,7 +7704,6 @@ class PNaClTargetInfo : public TargetInf public: PNaClTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : TargetInfo(Triple) { - BigEndian = false; this->LongAlign = 32; this->LongWidth = 32; this->PointerAlign = 32; @@ -7785,7 +7771,6 @@ class Le64TargetInfo : public TargetInfo public: Le64TargetInfo(const llvm::Triple &Triple, const TargetOptions &) : TargetInfo(Triple) { - BigEndian = false; NoAsmVariants = true; LongWidth = LongAlign = PointerWidth = PointerAlign = 64; MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; @@ -7831,7 +7816,6 @@ class WebAssemblyTargetInfo : public Tar public: explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &) : TargetInfo(T), SIMDLevel(NoSIMD) { - BigEndian = false; NoAsmVariants = true; SuitableAlign = 128; LargeArrayMinWidth = 128; @@ -7998,7 +7982,6 @@ public: "SPIR target must use unknown OS"); assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment && "SPIR target must use unknown environment type"); - BigEndian = false; TLSSupported = false; LongWidth = LongAlign = 64; AddrSpaceMap = &SPIRAddrSpaceMap; @@ -8082,7 +8065,6 @@ class XCoreTargetInfo : public TargetInf public: XCoreTargetInfo(const llvm::Triple &Triple, const TargetOptions &) : TargetInfo(Triple) { - BigEndian = false; NoAsmVariants = true; LongLongAlign = 32; SuitableAlign = 32; Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=280787&r1=280786&r2=280787&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original) +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Wed Sep 7 02:08:02 2016 @@ -435,6 +435,9 @@ static void InitializeStandardPredefined Builder.defineMacro("CL_VERSION_1_2", "120"); Builder.defineMacro("CL_VERSION_2_0", "200"); + if (TI.isLittleEndian()) + Builder.defineMacro("__ENDIAN_LITTLE__"); + if (LangOpts.FastRelaxedMath) Builder.defineMacro("__FAST_RELAXED_MATH__"); } Modified: cfe/trunk/test/Preprocessor/init.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=280787&r1=280786&r2=280787&view=diff ============================================================================== --- cfe/trunk/test/Preprocessor/init.c (original) +++ cfe/trunk/test/Preprocessor/init.c Wed Sep 7 02:08:02 2016 @@ -6653,6 +6653,7 @@ // RUN: %clang_cc1 -x cl -E -dM -ffreestanding -triple=amdgcn < /dev/null | FileCheck -match-full-lines -check-prefix AMDGCN --check-prefix AMDGPU %s // RUN: %clang_cc1 -x cl -E -dM -ffreestanding -triple=r600 -target-cpu caicos < /dev/null | FileCheck -match-full-lines --check-prefix AMDGPU %s // +// AMDGPU:#define __ENDIAN_LITTLE__ 1 // AMDGPU:#define cl_khr_byte_addressable_store 1 // AMDGCN:#define cl_khr_fp64 1 // AMDGPU:#define cl_khr_global_int32_base_atomics 1 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits