forked from OSchip/llvm-project
[clang][Sparc] Default to -mcpu=v9 for Sparc V8 on Solaris
As reported in Bug 42535, `clang` doesn't inline atomic ops on 32-bit Sparc, unlike `gcc` on Solaris. In a 1-stage build with `gcc`, only two testcases are affected (currently `XFAIL`ed), while in a 2-stage build more than 100 tests `FAIL` due to this issue. The reason for this `gcc`/`clang` difference is that `gcc` on 32-bit Solaris/SPARC defaults to `-mpcu=v9` where atomic ops are supported, unlike with `clang`'s default of `-mcpu=v8`. This patch changes `clang` to use `-mcpu=v9` on 32-bit Solaris/SPARC, too. Doing so uncovered two bugs: `clang -m32 -mcpu=v9` chokes with any Solaris system headers included: /usr/include/sys/isa_defs.h:461:2: error: "Both _ILP32 and _LP64 are defined" #error "Both _ILP32 and _LP64 are defined" While `clang` currently defines `__sparcv9` in a 32-bit `-mcpu=v9` compilation, neither `gcc` nor Studio `cc` do. In fact, the Studio 12.6 `cc(1)` man page clearly states: These predefinitions are valid in all modes: [...] __sparcv8 (SPARC) __sparcv9 (SPARC -m64) At the same time, the patch defines `__GCC_HAVE_SYNC_COMPARE_AND_SWAP_[1248]` for a 32-bit Sparc compilation with any V9 cpu. I've also changed `MaxAtomicInlineWidth` for V9, matching what `gcc` does and the Oracle Developer Studio 12.6: C User's Guide documents (Ch. 3, Support for Atomic Types, 3.1 Size and Alignment of Atomic C Types). The two testcases that had been `XFAIL`ed for Bug 42535 are un-`XFAIL`ed again. Tested on `sparcv9-sun-solaris2.11` and `amd64-pc-solaris2.11`. Differential Revision: https://reviews.llvm.org/D86621
This commit is contained in:
parent
d380b582f7
commit
76e85ae268
|
@ -147,19 +147,20 @@ void SparcTargetInfo::getTargetDefines(const LangOptions &Opts,
|
|||
void SparcV8TargetInfo::getTargetDefines(const LangOptions &Opts,
|
||||
MacroBuilder &Builder) const {
|
||||
SparcTargetInfo::getTargetDefines(Opts, Builder);
|
||||
switch (getCPUGeneration(CPU)) {
|
||||
case CG_V8:
|
||||
if (getTriple().getOS() == llvm::Triple::Solaris)
|
||||
Builder.defineMacro("__sparcv8");
|
||||
if (getTriple().getOS() != llvm::Triple::Solaris)
|
||||
else {
|
||||
switch (getCPUGeneration(CPU)) {
|
||||
case CG_V8:
|
||||
Builder.defineMacro("__sparcv8");
|
||||
Builder.defineMacro("__sparcv8__");
|
||||
break;
|
||||
case CG_V9:
|
||||
Builder.defineMacro("__sparcv9");
|
||||
if (getTriple().getOS() != llvm::Triple::Solaris) {
|
||||
break;
|
||||
case CG_V9:
|
||||
Builder.defineMacro("__sparcv9");
|
||||
Builder.defineMacro("__sparcv9__");
|
||||
Builder.defineMacro("__sparc_v9__");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (getTriple().getVendor() == llvm::Triple::Myriad) {
|
||||
std::string MyriadArchValue, Myriad2Value;
|
||||
|
@ -227,6 +228,12 @@ void SparcV8TargetInfo::getTargetDefines(const LangOptions &Opts,
|
|||
Builder.defineMacro("__myriad2__", Myriad2Value);
|
||||
Builder.defineMacro("__myriad2", Myriad2Value);
|
||||
}
|
||||
if (getCPUGeneration(CPU) == CG_V9) {
|
||||
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
|
||||
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
|
||||
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
|
||||
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
|
||||
}
|
||||
}
|
||||
|
||||
void SparcV9TargetInfo::getTargetDefines(const LangOptions &Opts,
|
||||
|
|
|
@ -166,10 +166,15 @@ public:
|
|||
PtrDiffType = SignedLong;
|
||||
break;
|
||||
}
|
||||
// Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
|
||||
// on up to 64 bits.
|
||||
// Up to 32 bits (V8) or 64 bits (V9) are lock-free atomic, but we're
|
||||
// willing to do atomic ops on up to 64 bits.
|
||||
MaxAtomicPromoteWidth = 64;
|
||||
MaxAtomicInlineWidth = 32;
|
||||
if (getCPUGeneration(CPU) == CG_V9)
|
||||
MaxAtomicInlineWidth = 64;
|
||||
else
|
||||
// FIXME: This isn't correct for plain V8 which lacks CAS,
|
||||
// only for LEON 3+ and Myriad.
|
||||
MaxAtomicInlineWidth = 32;
|
||||
}
|
||||
|
||||
void getTargetDefines(const LangOptions &Opts,
|
||||
|
|
|
@ -347,6 +347,8 @@ std::string tools::getCPUName(const ArgList &Args, const llvm::Triple &T,
|
|||
case llvm::Triple::sparcv9:
|
||||
if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
|
||||
return A->getValue();
|
||||
if (T.getArch() == llvm::Triple::sparc && T.isOSSolaris())
|
||||
return "v9";
|
||||
return "";
|
||||
|
||||
case llvm::Triple::x86:
|
||||
|
|
|
@ -3235,9 +3235,26 @@
|
|||
// RUN: -target sparc-unknown-linux \
|
||||
// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC-V9
|
||||
// CHECK_SPARC-V9-NOT: #define __sparcv8 1
|
||||
// CHECK_SPARC-V9-NOT: #define __sparcv8__ 1
|
||||
// CHECK_SPARC-V9: #define __sparc_v9__ 1
|
||||
// CHECK_SPARC-V9: #define __sparcv9 1
|
||||
// CHECK_SPARC-V9-NOT: #define __sparcv8 1
|
||||
// CHECK_SPARC-V9: #define __sparcv9__ 1
|
||||
|
||||
// RUN: %clang -E -dM %s -o - 2>&1 \
|
||||
// RUN: -target sparc-sun-solaris \
|
||||
// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC_SOLARIS_GCC_ATOMICS
|
||||
// CHECK_SPARC_SOLARIS_GCC_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
|
||||
// CHECK_SPARC_SOLARIS_GCC_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
|
||||
// CHECK_SPARC_SOLARIS_GCC_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
|
||||
// CHECK_SPARC_SOLARIS_GCC_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
|
||||
|
||||
// RUN: %clang -mcpu=v8 -E -dM %s -o - 2>&1 \
|
||||
// RUN: -target sparc-sun-solaris \
|
||||
// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8
|
||||
// CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
|
||||
// CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
|
||||
// CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
|
||||
// CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
|
||||
|
||||
// RUN: %clang -E -dM %s -o - 2>&1 \
|
||||
// RUN: -target sparcel-unknown-linux \
|
||||
|
|
|
@ -10,9 +10,6 @@ RUN: %run %t.driver %t.target
|
|||
RUN: llvm-cov gcov instrprof-gcov-parallel.target.gcda
|
||||
RUN: FileCheck --input-file instrprof-gcov-parallel.target.c.gcov %s
|
||||
|
||||
# Bug 42535
|
||||
# XFAIL: sparc-target-arch
|
||||
|
||||
# Test if the .gcda file is correctly created from one of child processes
|
||||
# and counters of all processes are recorded correctly.
|
||||
# 707 = CHILDREN * COUNT
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
// FIXME: not %run %t 8 2>&1 | FileCheck %s --check-prefix=CHECK-8
|
||||
// RUN: not %run %t 9 2>&1 | FileCheck %s --check-prefix=CHECK-9
|
||||
|
||||
// Bug 42535
|
||||
// XFAIL: sparc-target-arch
|
||||
|
||||
// This test assumes float and double are IEEE-754 single- and double-precision.
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
|
Loading…
Reference in New Issue