https://github.com/Zhenhang1213 updated 
https://github.com/llvm/llvm-project/pull/128901

>From 4bb02c6f8a81a4060fe99ca57602b65a507905d0 Mon Sep 17 00:00:00 2001
From: Austin <zhenhangw...@huawei.com>
Date: Thu, 27 Feb 2025 00:11:56 +0800
Subject: [PATCH] [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.
---
 clang/lib/Driver/ToolChains/Arch/ARM.cpp | 10 +++++-----
 clang/test/Driver/arm-thread-pointer.c   |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 3aee540d501be..42f92eb94657a 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -239,7 +239,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 (isHardTPSupported(Triple) ? ReadTPMode::TPIDRURO : ReadTPMode::Soft);
 }
 
 void arm::setArchNameInTriple(const Driver &D, const ArgList &Args,
@@ -574,12 +574,12 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
       A->ignoreTargetSpecific();
   }
 
-  if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRURW)
+  arm::ReadTPMode TPMode = getReadTPMode(D, Args, Triple, ForAS);
+
+  if (TPMode == ReadTPMode::TPIDRURW)
     Features.push_back("+read-tp-tpidrurw");
-  if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRURO)
+  else if (TPMode == ReadTPMode::TPIDRURO)
     Features.push_back("+read-tp-tpidruro");
-  if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRPRW)
-    Features.push_back("+read-tp-tpidrprw");
 
   const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ);
   const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ);
diff --git a/clang/test/Driver/arm-thread-pointer.c 
b/clang/test/Driver/arm-thread-pointer.c
index 5521e1865b276..e4bce724be74a 100644
--- a/clang/test/Driver/arm-thread-pointer.c
+++ b/clang/test/Driver/arm-thread-pointer.c
@@ -42,4 +42,4 @@
 
 // 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"

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to