Skip to content

Commit 0db9830

Browse files
committed
[ARM] Introduce -mtp=auto and make it the default
This adds a new value auto to the possible values of the existing -mtp= clang option which controls how the thread pointer is found. auto means the same as soft if the target architecture doesn't support a hardware thread pointer at all; otherwise it means the same as cp15. This behavior is the default in gcc version 4.1.0 and later. The new auto option is therefore also the default in clang, so this change aligns clang with gcc. Fixes #123864.
1 parent a955426 commit 0db9830

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ Deprecated Compiler Flags
122122
Modified Compiler Flags
123123
-----------------------
124124

125+
- The ARM AArch32 ``-mtp`` option accepts and defaults to ``auto``, a value of ``auto`` uses the best available method of providing the frame pointer supported by the hardware. This matches
126+
the behavior of ``-mtp`` in gcc. This changes the default behavior for ARM targets that provide the ``TPIDRURO`` register as this will be used instead of a call to the ``__aeabi_read_tp``.
127+
Programs that use ``__aeabi_read_tp`` but do not use the ``TPIDRURO`` register must use ``-mtp=soft``. Fixes #123864
128+
125129
Removed Compiler Flags
126130
-------------------------
127131

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4711,7 +4711,7 @@ def mexecute_only : Flag<["-"], "mexecute-only">, Group<m_arm_Features_Group>,
47114711
def mno_execute_only : Flag<["-"], "mno-execute-only">, Group<m_arm_Features_Group>,
47124712
HelpText<"Allow generation of data access to code sections (ARM only)">;
47134713
let Flags = [TargetSpecific] in {
4714-
def mtp_mode_EQ : Joined<["-"], "mtp=">, Group<m_arm_Features_Group>, Values<"soft,cp15,tpidrurw,tpidruro,tpidrprw,el0,el1,el2,el3,tpidr_el0,tpidr_el1,tpidr_el2,tpidr_el3,tpidrro_el0">,
4714+
def mtp_mode_EQ : Joined<["-"], "mtp=">, Group<m_arm_Features_Group>, Values<"soft,cp15,tpidrurw,tpidruro,tpidrprw,el0,el1,el2,el3,tpidr_el0,tpidr_el1,tpidr_el2,tpidr_el3,tpidrro_el0,auto">,
47154715
HelpText<"Thread pointer access method. "
47164716
"For AArch32: 'soft' uses a function call, or 'tpidrurw', 'tpidruro' or 'tpidrprw' use the three CP15 registers. 'cp15' is an alias for 'tpidruro'. "
47174717
"For AArch64: 'tpidr_el0', 'tpidr_el1', 'tpidr_el2', 'tpidr_el3' or 'tpidrro_el0' use the five system registers. 'elN' is an alias for 'tpidr_elN'.">;

clang/lib/Driver/ToolChains/Arch/ARM.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ bool arm::isHardTPSupported(const llvm::Triple &Triple) {
215215
// Select mode for reading thread pointer (-mtp=soft/cp15).
216216
arm::ReadTPMode arm::getReadTPMode(const Driver &D, const ArgList &Args,
217217
const llvm::Triple &Triple, bool ForAS) {
218-
if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
218+
Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ);
219+
if (A && A->getValue() != StringRef("auto")) {
219220
arm::ReadTPMode ThreadPointer =
220221
llvm::StringSwitch<arm::ReadTPMode>(A->getValue())
221222
.Case("cp15", ReadTPMode::TPIDRURO)
@@ -239,7 +240,7 @@ arm::ReadTPMode arm::getReadTPMode(const Driver &D, const ArgList &Args,
239240
D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
240241
return ReadTPMode::Invalid;
241242
}
242-
return ReadTPMode::Soft;
243+
return (isHardTPSupported(Triple) ? ReadTPMode::TPIDRURO : ReadTPMode::Soft);
243244
}
244245

245246
void arm::setArchNameInTriple(const Driver &D, const ArgList &Args,
@@ -574,12 +575,14 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D,
574575
A->ignoreTargetSpecific();
575576
}
576577

577-
if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRURW)
578+
arm::ReadTPMode TPMode = getReadTPMode(D, Args, Triple, ForAS);
579+
580+
if (TPMode == ReadTPMode::TPIDRURW)
578581
Features.push_back("+read-tp-tpidrurw");
579-
if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRURO)
580-
Features.push_back("+read-tp-tpidruro");
581-
if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRPRW)
582+
else if (TPMode == ReadTPMode::TPIDRPRW)
582583
Features.push_back("+read-tp-tpidrprw");
584+
else if (TPMode == ReadTPMode::TPIDRURO)
585+
Features.push_back("+read-tp-tpidruro");
583586

584587
const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ);
585588
const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ);

clang/lib/Driver/ToolChains/Arch/ARM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum class ReadTPMode {
4141
TPIDRURW,
4242
TPIDRURO,
4343
TPIDRPRW,
44+
Auto,
4445
};
4546

4647
enum class FloatABI {

clang/test/Driver/arm-thread-pointer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@
4242

4343
// RUN: %clang --target=armv7-linux -### -S %s 2>&1 | \
4444
// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_NON %s
45-
// ARMv7_THREAD_POINTER_NON-NOT: "-target-feature" "+read-tp-tpidruro"
45+
// ARMv7_THREAD_POINTER_NON: "-target-feature" "+read-tp-tpidruro"
46+
47+
// RUN: %clang --target=armv7-linux -mtp=auto -### -S %s 2>&1 | \
48+
// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_Auto %s
49+
// ARMv7_THREAD_POINTER_Auto: "-target-feature" "+read-tp-tpidruro"

0 commit comments

Comments
 (0)