[llvm] ARM: Move abi name implied float abi to TargetParser (PR #226774)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 27 01:49:48 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/226774

ARMTargetMachine overrode the default float abi based on the abi name.
Move this logic to TargetParser so the ABI will be computable without
depending on codegen.

Co-Authored-By: Claude Sonnet 5 <noreply at anthropic.com>

>From e9072bd33e51060f3b2b2306001b63332f6aad1b Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sun, 27 Sep 2026 10:42:38 +0200
Subject: [PATCH] ARM: Move abi name implied float abi to TargetParser

ARMTargetMachine overrode the default float abi based on the abi name.
Move this logic to TargetParser so the ABI will be computable without
depending on codegen.

Co-Authored-By: Claude Sonnet 5 <noreply at anthropic.com>
---
 llvm/include/llvm/TargetParser/Triple.h  |  6 ++++--
 llvm/lib/Target/ARM/ARMTargetMachine.cpp |  9 +--------
 llvm/lib/TargetParser/Triple.cpp         | 10 ++++++----
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index b369b66960b1a..e161fd0f00eb9 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -1258,8 +1258,10 @@ class Triple {
   }
 
   /// Returns the default floating-point ABI for this target triple, i.e. the
-  /// ABI the code generator will resolve FloatABI::Default to
-  LLVM_ABI FloatABI::ABIType getDefaultFloatABI() const;
+  /// ABI the code generator will resolve FloatABI::Default to. \p ABIName, if
+  /// given, is the effective target ABI (e.g. "aapcs16" can force hard float on
+  /// ARM even when the ordinary default is soft).
+  LLVM_ABI FloatABI::ABIType getDefaultFloatABI(StringRef ABIName = "") const;
 
   /// Tests if the target's default floating-point ABI is hard float.
   bool isHardFloatABI() const { return getDefaultFloatABI() == FloatABI::Hard; }
diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
index e1153ed22ab91..6bc7cd019e0f5 100644
--- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
@@ -219,14 +219,7 @@ FloatABI::ABIType ARMBaseTargetMachine::getFloatABI(const Module &M) const {
   // An explicit "float-abi" module flag always wins, even for AAPCS16.
   if (auto *Val = dyn_cast_or_null<MDString>(M.getModuleFlag("float-abi")))
     return *FloatABI::parseABIType(Val->getString());
-
-  // With no explicit ABI, an explicit -target-abi=aapcs16 forces hard float
-  // even on triples whose default float ABI is soft (the triple default only
-  // detects AAPCS16 when it is the triple's own default ABI).
-  if (getEffectiveABI(M) == ARM::ARM_ABI_AAPCS16)
-    return FloatABI::Hard;
-  // Otherwise fall back to the ABI implied by the target triple.
-  return M.getTargetTriple().getDefaultFloatABI();
+  return M.getTargetTriple().getDefaultFloatABI(getTargetABIName(M));
 }
 
 ARM::ARMABI ARMBaseTargetMachine::getEffectiveABI(const Module &M) const {
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 6f2c867a318d2..ef480281700f4 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -2518,19 +2518,21 @@ ExceptionHandling Triple::getDefaultExceptionHandling() const {
   return ExceptionHandling::None;
 }
 
-static FloatABI::ABIType getARMDefaultFloatABI(const Triple &T) {
+static FloatABI::ABIType getARMDefaultFloatABI(const Triple &T,
+                                               StringRef ABIName) {
   Triple::EnvironmentType Env = T.getEnvironment();
   bool IsHard =
       Env == Triple::GNUEABIHF || Env == Triple::GNUEABIHFT64 ||
       Env == Triple::MuslEABIHF || Env == Triple::EABIHF ||
       (T.isOSBinFormatMachO() && T.getSubArch() == Triple::ARMSubArch_v7em) ||
-      T.isOSWindows() || ARM::computeTargetABI(T, "") == ARM::ARM_ABI_AAPCS16;
+      T.isOSWindows() ||
+      ARM::computeTargetABI(T, ABIName) == ARM::ARM_ABI_AAPCS16;
   return IsHard ? FloatABI::Hard : FloatABI::Soft;
 }
 
-FloatABI::ABIType Triple::getDefaultFloatABI() const {
+FloatABI::ABIType Triple::getDefaultFloatABI(StringRef ABIName) const {
   if (isARM() || isThumb())
-    return getARMDefaultFloatABI(*this);
+    return getARMDefaultFloatABI(*this, ABIName);
 
   // MIPS defaults to hard float, except on FreeBSD which uses soft float.
   if (isMIPS())



More information about the llvm-commits mailing list