Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARM] Introduce -mtp=auto and make it the default #128728

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4711,7 +4711,7 @@ def mexecute_only : Flag<["-"], "mexecute-only">, Group<m_arm_Features_Group>,
def mno_execute_only : Flag<["-"], "mno-execute-only">, Group<m_arm_Features_Group>,
HelpText<"Allow generation of data access to code sections (ARM only)">;
let Flags = [TargetSpecific] in {
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">,
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">,
HelpText<"Thread pointer access method. "
"For AArch32: 'soft' uses a function call, or 'tpidrurw', 'tpidruro' or 'tpidrprw' use the three CP15 registers. 'cp15' is an alias for 'tpidruro'. "
"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'.">;
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Driver/ToolChains/Arch/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ arm::ReadTPMode arm::getReadTPMode(const Driver &D, const ArgList &Args,
.Case("tpidruro", ReadTPMode::TPIDRURO)
.Case("tpidrprw", ReadTPMode::TPIDRPRW)
.Case("soft", ReadTPMode::Soft)
.Case("auto", ReadTPMode::Auto)
.Default(ReadTPMode::Invalid);
if ((ThreadPointer == ReadTPMode::TPIDRURW ||
ThreadPointer == ReadTPMode::TPIDRURO ||
Expand All @@ -239,7 +240,7 @@ arm::ReadTPMode arm::getReadTPMode(const Driver &D, const ArgList &Args,
D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
return ReadTPMode::Invalid;
}
return ReadTPMode::Soft;
return ReadTPMode::Auto;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way of rewriting this so that we don't have to return Auto from the function? I think the intention is that the logic of handling the mtp option is centralised here. Ideally we should translate Auto to either Soft or TPIDRURO. That would mean it wouldn't need to be handled in setArchNameInTriple

This may need some reorganisation to avoid duplication. Although it may just be simple enough to live with it.

  if (ThreadPointer == ReadTPMode::Auto)
    return (isHardTPSupported(Triple) ? ReadTPMode::TPIDRURO : ReadTPMode::Soft);

At the end we could replace return ReadTPMode::Auto with

return (isHardTPSupported(Triple) ? ReadTPMode::TPIDRURO : ReadTPMode::Soft);

}

void arm::setArchNameInTriple(const Driver &D, const ArgList &Args,
Expand Down Expand Up @@ -580,6 +581,9 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D,
Features.push_back("+read-tp-tpidruro");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're calling getReadTPMode 4 times now, with the same parameters. and I don't think it can return a different value each time. I think this could be simplified to

arm::ReadTPMode TPMode = getReadTPMode(D, Args, Triple, ForAS);
if (TPMode == ReadTPMode::TPIDRURW)
    Features.push_back("+read-tp-tpidrurw");
else if (TPMode == ReadTPMode::TPIDRURO)
    ...

if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRPRW)
Features.push_back("+read-tp-tpidrprw");
if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::Auto &&
isHardTPSupported(Triple) && !ForAS)
Features.push_back("+read-tp-tpidruro");

const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ);
const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains/Arch/ARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum class ReadTPMode {
TPIDRURW,
TPIDRURO,
TPIDRPRW,
Auto,
};

enum class FloatABI {
Expand Down
6 changes: 5 additions & 1 deletion clang/test/Driver/arm-thread-pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@

// RUN: %clang --target=armv7-linux -### -S %s 2>&1 | \
// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_NON %s
// ARMv7_THREAD_POINTER_NON-NOT: "-target-feature" "+read-tp-tpidruro"
// ARMv7_THREAD_POINTER_NON: "-target-feature" "+read-tp-tpidruro"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this test matches the change in getARMTargetFeatures. In that function, you respond to -mtp=auto by setting the feature +read-tp-tpidrprw. But here the test is expecting +read-tp-tpidruro, which isn't the same. Can you explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It‘s my fault, I want to set +read-tp-tpidruro by -mtp=auto


// RUN: %clang --target=armv7-linux -mtp=auto -### -S %s 2>&1 | \
// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_Auto %s
// ARMv7_THREAD_POINTER_Auto: "-target-feature" "+read-tp-tpidruro"
Loading