Skip to content

Commit c5e7e64

Browse files
committed
[AArch64][Clang][Linux] Enable out-of-line atomics by default.
Generate outline atomics if compiling for armv8-a non-LSE AArch64 Linux (including Android) targets to use LSE instructions, if they are available, at runtime. Library support is checked by clang driver which doesn't enable outline atomics if no proper libraries (libgcc >= 9.3.1 or compiler-rt) found. Differential Revision: https://reviews.llvm.org/D93585
1 parent 010b176 commit c5e7e64

File tree

13 files changed

+82
-0
lines changed

13 files changed

+82
-0
lines changed

clang/include/clang/Driver/ToolChain.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,12 @@ class ToolChain {
456456
/// by default.
457457
virtual bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const;
458458

459+
/// Test whether this toolchain supports outline atomics by default.
460+
virtual bool
461+
IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const {
462+
return false;
463+
}
464+
459465
/// Test whether this toolchain defaults to PIC.
460466
virtual bool isPICDefault() const = 0;
461467

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6500,6 +6500,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
65006500
CmdArgs.push_back("-target-feature");
65016501
CmdArgs.push_back("-outline-atomics");
65026502
}
6503+
} else if (Triple.isAArch64() &&
6504+
getToolChain().IsAArch64OutlineAtomicsDefault(Args)) {
6505+
CmdArgs.push_back("-target-feature");
6506+
CmdArgs.push_back("+outline-atomics");
65036507
}
65046508

65056509
if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,19 @@ bool Linux::isPIEDefault() const {
836836
getTriple().isMusl() || getSanitizerArgs().requiresPIE();
837837
}
838838

839+
bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const {
840+
// Outline atomics for AArch64 are supported by compiler-rt
841+
// and libgcc since 9.3.1
842+
assert(getTriple().isAArch64() && "expected AArch64 target!");
843+
ToolChain::RuntimeLibType RtLib = GetRuntimeLibType(Args);
844+
if (RtLib == ToolChain::RLT_CompilerRT)
845+
return true;
846+
assert(RtLib == ToolChain::RLT_Libgcc && "unexpected runtime library type!");
847+
if (GCCInstallation.getVersion().isOlderThan(9, 3, 1))
848+
return false;
849+
return true;
850+
}
851+
839852
bool Linux::isNoExecStackDefault() const {
840853
return getTriple().isAndroid();
841854
}

clang/lib/Driver/ToolChains/Linux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
3636
void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
3737
llvm::opt::ArgStringList &CC1Args) const override;
3838
CXXStdlibType GetDefaultCXXStdlibType() const override;
39+
bool
40+
IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const override;
3941
bool isPIEDefault() const override;
4042
bool isNoExecStackDefault() const override;
4143
bool IsMathErrnoDefault() const override;

clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-10/lib/gcc/aarch64-unknown-linux-gnu/10/crtbegin.o

Whitespace-only changes.

clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-10/lib/gcc/aarch64-unknown-linux-gnu/10/libgcc.a

Whitespace-only changes.

clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-7.5.0/lib/gcc/aarch64-unknown-linux-gnu/7.5.0/crtbegin.o

Whitespace-only changes.

clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-7.5.0/lib/gcc/aarch64-unknown-linux-gnu/7.5.0/libgcc.a

Whitespace-only changes.

clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-9.3.0/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/crtbegin.o

Whitespace-only changes.

clang/test/Driver/Inputs/aarch64-linux-gnu-tree/gcc-9.3.0/lib/gcc/aarch64-unknown-linux-gnu/9.3.0/libgcc.a

Whitespace-only changes.

0 commit comments

Comments
 (0)