Skip to content

Commit 88a31a1

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 7.3.0 and later. The new auto option is therefore also the default in clang, so this change aligns clang with gcc.
1 parent a955426 commit 88a31a1

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ arm::ReadTPMode arm::getReadTPMode(const Driver &D, const ArgList &Args,
223223
.Case("tpidruro", ReadTPMode::TPIDRURO)
224224
.Case("tpidrprw", ReadTPMode::TPIDRPRW)
225225
.Case("soft", ReadTPMode::Soft)
226+
.Case("auto", ReadTPMode::Auto)
226227
.Default(ReadTPMode::Invalid);
227228
if ((ThreadPointer == ReadTPMode::TPIDRURW ||
228229
ThreadPointer == 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 ReadTPMode::Auto;
243244
}
244245

245246
void arm::setArchNameInTriple(const Driver &D, const ArgList &Args,
@@ -580,6 +581,9 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D,
580581
Features.push_back("+read-tp-tpidruro");
581582
if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRPRW)
582583
Features.push_back("+read-tp-tpidrprw");
584+
if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::Auto &&
585+
isHardTPSupported(Triple) && !ForAS)
586+
Features.push_back("+read-tp-tpidruro");
583587

584588
const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ);
585589
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)