[llvm-branch-commits] [clang] [flang] [llvm] CodeGen: Remove TargetOptions::FloatABIType (PR #215796)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Aug 12 07:35:01 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-selectiondag

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>

This is now fully replaced with the "float-abi" module flag.
If the module flag is not present, the default is computed
from the triple. Consumers are updated to read the module flag.

RuntimeLibraryAnalysis now defers analysis until run() on a Module,
instead of during the pass constructor as before. This requires copying
all of the remaining relevant TargetOptions so they are available
when the module is seen.

Unfortunately, ARM still depends on TargetOptions for determining
the float-abi. -target-abi=aapcs16 still changes the default float-abi,
but an explicit module flag wins.

Co-authored-by: Claude (Claude-Opus-4.8) <noreply@<!-- -->anthropic.com>

---

Patch is 30.83 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/215796.diff


29 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+3-14) 
- (modified) flang/lib/Frontend/FrontendActions.cpp (+4-4) 
- (modified) llvm/docs/ReleaseNotes.md (+3) 
- (modified) llvm/include/llvm/Analysis/RuntimeLibcallInfo.h (+19-17) 
- (modified) llvm/include/llvm/IR/Module.h (+1-1) 
- (modified) llvm/include/llvm/IR/RuntimeLibcalls.h (+10-1) 
- (modified) llvm/include/llvm/Target/TargetOptions.h (-8) 
- (modified) llvm/lib/Analysis/RuntimeLibcallInfo.cpp (+5-18) 
- (modified) llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/CommandFlags.cpp (-2) 
- (modified) llvm/lib/CodeGen/TargetLoweringBase.cpp (+2-1) 
- (modified) llvm/lib/IR/Module.cpp (+4-2) 
- (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+6-4) 
- (modified) llvm/lib/LTO/LTOBackend.cpp (+1-2) 
- (modified) llvm/lib/Target/ARM/ARMAsmPrinter.cpp (+1-5) 
- (modified) llvm/lib/Target/ARM/ARMTargetMachine.cpp (+15-20) 
- (modified) llvm/lib/Target/ARM/ARMTargetMachine.h (+5) 
- (modified) llvm/lib/Target/CSKY/CSKYTargetMachine.cpp (-2) 
- (modified) llvm/test/CodeGen/Hexagon/autohvx/xqf-assertion1.ll (+2-2) 
- (modified) llvm/test/CodeGen/Hexagon/autohvx/xqf-handle-conv.ll (+2-2) 
- (modified) llvm/test/CodeGen/Hexagon/fmaximum.ll (+1-1) 
- (modified) llvm/test/CodeGen/Hexagon/fminimum.ll (+1-1) 
- (added) llvm/test/LTO/ARM/float-abi-module-flag.ll (+45) 
- (added) llvm/test/Transforms/Util/DeclareRuntimeLibcalls/float-abi-module-flag.ll (+28) 
- (modified) llvm/tools/llc/NewPMDriver.cpp (+2-4) 
- (modified) llvm/tools/llc/llc.cpp (+2-6) 
- (modified) llvm/tools/lli/lli.cpp (+6-2) 
- (modified) llvm/tools/opt/NewPMDriver.cpp (+1-2) 
- (modified) llvm/tools/opt/optdriver.cpp (+2-2) 


``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index e95552b7e9e06..16fb29d75be70 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -392,17 +392,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
     break;
   }
 
-  // Set float ABI type.
-  assert((CodeGenOpts.FloatABI == "soft" || CodeGenOpts.FloatABI == "softfp" ||
-          CodeGenOpts.FloatABI == "hard" || CodeGenOpts.FloatABI.empty()) &&
-         "Invalid Floating Point ABI!");
-  Options.FloatABIType =
-      llvm::StringSwitch<llvm::FloatABI::ABIType>(CodeGenOpts.FloatABI)
-          .Case("soft", llvm::FloatABI::Soft)
-          .Case("softfp", llvm::FloatABI::Soft)
-          .Case("hard", llvm::FloatABI::Hard)
-          .Default(llvm::FloatABI::Default);
-
   // Set FP fusion mode.
   switch (LangOpts.getDefaultFPContractMode()) {
   case LangOptions::FPM_Off:
@@ -1275,9 +1264,9 @@ void EmitAssemblyHelper::RunCodegenPipelineLegacy(
   CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
 
   const llvm::TargetOptions &Options = TM->Options;
-  CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
-      TargetTriple, Options.ExceptionModel, Options.FloatABIType,
-      Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
+  CodeGenPasses.add(
+      new RuntimeLibraryInfoWrapper(Options.ExceptionModel, Options.EABIVersion,
+                                    Options.MCOptions.ABIName, Options.VecLib));
 
   if (TM->addPassesToEmitFile(CodeGenPasses, *OS,
                               DwoOS ? &DwoOS->os() : nullptr, CGFT,
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index e21590cc9fa7f..7ecda651027e2 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -920,8 +920,8 @@ static void generateMachineCodeOrAssemblyImpl(
       llvm::driver::createTLII(triple, codeGenOpts.getVecLib());
   codeGenPasses.add(new llvm::TargetLibraryInfoWrapperPass(*tlii));
   codeGenPasses.add(new llvm::RuntimeLibraryInfoWrapper(
-      triple, tm.Options.ExceptionModel, tm.Options.FloatABIType,
-      tm.Options.EABIVersion, tm.Options.MCOptions.ABIName, tm.Options.VecLib));
+      tm.Options.ExceptionModel, tm.Options.EABIVersion,
+      tm.Options.MCOptions.ABIName, tm.Options.VecLib));
 
   std::unique_ptr<llvm::ToolOutputFile> dwoOS;
   if (!codeGenOpts.SplitDwarfOutput.empty()) {
@@ -1040,8 +1040,8 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
   fam.registerPass([&] { return llvm::TargetLibraryAnalysis(*tlii); });
   mam.registerPass([&] {
     return llvm::RuntimeLibraryAnalysis(
-        triple, targetMachine->Options.ExceptionModel,
-        targetMachine->Options.FloatABIType, targetMachine->Options.EABIVersion,
+        targetMachine->Options.ExceptionModel,
+        targetMachine->Options.EABIVersion,
         targetMachine->Options.MCOptions.ABIName,
         targetMachine->Options.VecLib);
   });
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 40e0303f77e86..ee128b416463d 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -54,6 +54,9 @@ Makes programs 10x faster by doing Special New Thing.
 
 ### Changes to LLVM infrastructure
 
+* Removed `TargetOptions::FloatABIType`. The soft float ABI should be
+  controlled by setting the `"float-abi"` module flag.
+
 ### Changes to building LLVM
 
 ### Changes to TableGen
diff --git a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
index 3054177bc6cce..f4d81b2f1e057 100644
--- a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
+++ b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
@@ -11,6 +11,8 @@
 
 #include "llvm/IR/RuntimeLibcalls.h"
 #include "llvm/Pass.h"
+#include <optional>
+#include <string>
 
 namespace llvm {
 
@@ -20,24 +22,26 @@ class LLVM_ABI RuntimeLibraryAnalysis
   using Result = RTLIB::RuntimeLibcallsInfo;
 
   RuntimeLibraryAnalysis() = default;
-  RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&BaselineInfoImpl)
-      : LibcallsInfo(std::move(BaselineInfoImpl)) {}
-  RuntimeLibraryAnalysis(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  RuntimeLibraryAnalysis(ExceptionHandling ExceptionModel,
+                         EABI EABIVersion = EABI::Default,
+                         StringRef ABIName = "",
+                         VectorLibrary VecLib = VectorLibrary::NoLibrary)
+      : ExceptionModel(ExceptionModel), EABIVersion(EABIVersion),
+        ABIName(ABIName.str()), VecLib(VecLib) {}
 
   RTLIB::RuntimeLibcallsInfo run(const Module &M, ModuleAnalysisManager &);
 
-  operator bool() const { return LibcallsInfo.has_value(); }
-
 private:
   friend AnalysisInfoMixin<RuntimeLibraryAnalysis>;
   static AnalysisKey Key;
 
-  std::optional<RTLIB::RuntimeLibcallsInfo> LibcallsInfo;
+  // FIXME: These are TargetOptions values that are not yet represented in the
+  // IR, copied here so run() can forward them to the RuntimeLibcallsInfo Module
+  // constructor. Delete each one as they are migrated to module flags.
+  ExceptionHandling ExceptionModel = ExceptionHandling::None;
+  EABI EABIVersion = EABI::Default;
+  std::string ABIName;
+  VectorLibrary VecLib = VectorLibrary::NoLibrary;
 };
 
 class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
@@ -47,12 +51,10 @@ class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
 public:
   static char ID;
   RuntimeLibraryInfoWrapper();
-  RuntimeLibraryInfoWrapper(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  RuntimeLibraryInfoWrapper(ExceptionHandling ExceptionModel,
+                            EABI EABIVersion = EABI::Default,
+                            StringRef ABIName = "",
+                            VectorLibrary VecLib = VectorLibrary::NoLibrary);
 
   const RTLIB::RuntimeLibcallsInfo &getRTLCI(const Module &M) {
     if (!RTLCI) {
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 53927e96a232e..6090644f7a12f 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -1066,7 +1066,7 @@ class LLVM_ABI Module {
   /// @{
 
   /// Returns the floating-point ABI recorded by the "float-abi" module flag, or
-  /// FloatABI::Default when the flag is absent (meaning the target default).
+  /// the ABI implied by the target triple when the flag is absent.
   FloatABI::ABIType getFloatABI() const;
   /// @}
 
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 78b75f3e81c3b..8519100f9f80a 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -87,7 +87,16 @@ struct RuntimeLibcallsInfo {
       EABI EABIVersion = EABI::Default, StringRef ABIName = "",
       VectorLibrary VecLib = VectorLibrary::NoLibrary);
 
-  LLVM_ABI explicit RuntimeLibcallsInfo(const Module &M);
+  // FIXME: The floating-point ABI is read from the "float-abi" module flag, but
+  // the ExceptionModel/EABIVersion/ABIName/VecLib parameters are still
+  // TargetOptions values that are not yet represented in the IR. Delete these
+  // parameters (and build everything from the Module) once those fields are
+  // migrated to module flags.
+  LLVM_ABI explicit RuntimeLibcallsInfo(
+      const Module &M,
+      ExceptionHandling ExceptionModel = ExceptionHandling::None,
+      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
+      VectorLibrary VecLib = VectorLibrary::NoLibrary);
 
   LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
                            ModuleAnalysisManager::Invalidator &);
diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h
index dc8b2ebceee46..f6c862e99b98f 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -358,14 +358,6 @@ class TargetOptions {
   /// If greater than 0, override TargetLoweringBase::PrefLoopAlignment.
   unsigned LoopAlignment = 0;
 
-  /// FloatABIType - This setting is set by -float-abi=xxx option is specfied
-  /// on the command line. This setting may either be Default, Soft, or Hard.
-  /// Default selects the target's default behavior. Soft selects the ABI for
-  /// software floating point, but does not indicate that FP hardware may not
-  /// be used. Such a combination is unfortunately popular (e.g.
-  /// arm-apple-darwin). Hard presumes that the normal FP ABI is used.
-  FloatABI::ABIType FloatABIType = FloatABI::Default;
-
   /// AllowFPOpFusion - This flag is set by the -fp-contract=xxx option.
   /// This controls the creation of fused FP ops that store intermediate
   /// results in higher precision than IEEE allows (E.g. FMAs).
diff --git a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
index 1c5a1cc75b7bd..23dca93c4d884 100644
--- a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
+++ b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
@@ -13,34 +13,21 @@ using namespace llvm;
 
 AnalysisKey RuntimeLibraryAnalysis::Key;
 
-RuntimeLibraryAnalysis::RuntimeLibraryAnalysis(const Triple &TT,
-                                               ExceptionHandling ExceptionModel,
-                                               FloatABI::ABIType FloatABI,
-                                               EABI EABIVersion,
-                                               StringRef ABIName,
-                                               VectorLibrary VecLib)
-    : LibcallsInfo(std::in_place, TT, ExceptionModel, FloatABI, EABIVersion,
-                   ABIName, VecLib) {}
-
 RTLIB::RuntimeLibcallsInfo
 RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) {
-  if (!LibcallsInfo)
-    LibcallsInfo = RTLIB::RuntimeLibcallsInfo(M);
-  return *LibcallsInfo;
+  return RTLIB::RuntimeLibcallsInfo(M, ExceptionModel, EABIVersion, ABIName,
+                                    VecLib);
 }
 
 INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
                 "Runtime Library Function Analysis", false, true)
 
-RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper()
-    : ImmutablePass(ID), RTLA(RTLIB::RuntimeLibcallsInfo(Triple())) {}
+RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper() : ImmutablePass(ID) {}
 
 RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper(
-    const Triple &TT, ExceptionHandling ExceptionModel,
-    FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName,
+    ExceptionHandling ExceptionModel, EABI EABIVersion, StringRef ABIName,
     VectorLibrary VecLib)
-    : ImmutablePass(ID), RTLCI(std::in_place, TT, ExceptionModel, FloatABI,
-                               EABIVersion, ABIName, VecLib) {}
+    : ImmutablePass(ID), RTLA(ExceptionModel, EABIVersion, ABIName, VecLib) {}
 
 char RuntimeLibraryInfoWrapper::ID = 0;
 
diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
index b66e1027e64c2..d869c123c2046 100644
--- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
+++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
@@ -129,9 +129,9 @@ addPassesToGenerateCode(CodeGenTargetMachineImpl &TM, PassManagerBase &PM,
   const TargetOptions &Options = TM.Options;
   TargetLibraryInfoImpl TLII(TM.getTargetTriple(), Options.VecLib);
   PM.add(new TargetLibraryInfoWrapperPass(TLII));
-  PM.add(new RuntimeLibraryInfoWrapper(
-      TM.getTargetTriple(), Options.ExceptionModel, Options.FloatABIType,
-      Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
+  PM.add(
+      new RuntimeLibraryInfoWrapper(Options.ExceptionModel, Options.EABIVersion,
+                                    Options.MCOptions.ABIName, Options.VecLib));
 
   invokeGlobalTargetPassConfigCallbacks(TM, PM, PassConfig);
 
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index 88987d0bc5558..24d46c6dcfe94 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -590,8 +590,6 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
 
   Options.HonorSignDependentRoundingFPMathOption =
       getEnableHonorSignDependentRoundingFPMath();
-  if (getFloatABIForCalls() != FloatABI::Default)
-    Options.FloatABIType = getFloatABIForCalls();
   Options.EnableAIXExtendedAltivecABI = getEnableAIXExtendedAltivecABI();
   Options.NoZerosInBSS = getDontPlaceZerosInBSS();
   Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 71eda1048bc11..3213788b71dc8 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -944,7 +944,8 @@ TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm,
                                        const TargetSubtargetInfo &STI)
     : TM(tm),
       RuntimeLibcallInfo(TM.getTargetTriple(), TM.Options.ExceptionModel,
-                         TM.Options.FloatABIType, TM.Options.EABIVersion,
+                         TM.getTargetTriple().getDefaultFloatABI(),
+                         TM.Options.EABIVersion,
                          TM.Options.MCOptions.getABIName(), TM.Options.VecLib),
       Libcalls(RuntimeLibcallInfo, STI) {
   initActions();
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 2ae76b80ccd57..510d33c0ad295 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -700,8 +700,10 @@ void Module::setLongDoubleFormat(LongDoubleFormat Format) {
 
 FloatABI::ABIType Module::getFloatABI() const {
   if (auto *Val = dyn_cast_or_null<MDString>(getModuleFlag("float-abi")))
-    return FloatABI::parseABIType(Val->getString()).value_or(FloatABI::Default);
-  return FloatABI::Default;
+    return *FloatABI::parseABIType(Val->getString());
+  // Without an explicit flag, fall back to the ABI implied by the target
+  // triple.
+  return getTargetTriple().getDefaultFloatABI();
 }
 
 std::optional<uint64_t> Module::getLargeDataThreshold() const {
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index ad7d3320f8928..d8069e207d3ef 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -101,10 +101,12 @@ RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
   }
 }
 
-RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M)
-    : RuntimeLibcallsInfo(M.getTargetTriple()) {
-  // TODO: Consider module flags
-}
+RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M,
+                                         ExceptionHandling ExceptionModel,
+                                         EABI EABIVersion, StringRef ABIName,
+                                         VectorLibrary VecLib)
+    : RuntimeLibcallsInfo(M.getTargetTriple(), ExceptionModel, M.getFloatABI(),
+                          EABIVersion, ABIName, VecLib) {}
 
 /// Set default libcall names. If a target wants to opt-out of a libcall it
 /// should be placed here.
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 73697a9d0d446..69bc3fdae6c57 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -485,8 +485,7 @@ static void codegen(const Config &Conf, TargetMachine *TM,
     TargetLibraryInfoImpl TLII(Mod.getTargetTriple(), TM->Options.VecLib);
     CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
     CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
-        Mod.getTargetTriple(), TM->Options.ExceptionModel,
-        TM->Options.FloatABIType, TM->Options.EABIVersion,
+        TM->Options.ExceptionModel, TM->Options.EABIVersion,
         TM->Options.MCOptions.ABIName, TM->Options.VecLib));
 
     // No need to make index available if the module is empty.
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 59ad547dc26d7..11f7929cb6dbe 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -698,11 +698,7 @@ void ARMAsmPrinter::emitAttributes() {
   }
   const ARMBaseTargetMachine &ATM =
       static_cast<const ARMBaseTargetMachine &>(TM);
-  // The float ABI comes from the "float-abi" module flag if present, otherwise
-  // from the legacy -float-abi target option.
-  FloatABI::ABIType FloatABI = MMI->getModule()->getFloatABI();
-  if (FloatABI == FloatABI::Default)
-    FloatABI = ATM.Options.FloatABIType;
+  FloatABI::ABIType FloatABI = ATM.getFloatABI(*MMI->getModule());
   const ARMSubtarget STI(TT, std::string(CPU), ArchFS, ATM,
                          ATM.isLittleEndian(), FloatABI);
 
diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
index 3d388a7db6687..a1ced45a83e63 100644
--- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
@@ -156,16 +156,6 @@ ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, const Triple &TT,
       TargetABI(ARM::computeTargetABI(TT, Options.MCOptions.ABIName)),
       TLOF(createTLOF(getTargetTriple())), isLittle(TT.isLittleEndian()) {
 
-  // Default to triple-appropriate float ABI. -target-abi=aapcs16 forces hard
-  // float regardless of the triple default.
-  if (Options.FloatABIType == FloatABI::Default) {
-    if (TargetABI == ARM::ARM_ABI_AAPCS16 ||
-        TT.getDefaultFloatABI() == FloatABI::Hard)
-      this->Options.FloatABIType = FloatABI::Hard;
-    else
-      this->Options.FloatABIType = FloatABI::Soft;
-  }
-
   // Default to triple-appropriate EABI
   if (Options.EABIVersion == EABI::Default ||
       Options.EABIVersion == EABI::Unknown) {
@@ -207,6 +197,20 @@ MachineFunctionInfo *ARMBaseTargetMachine::createMachineFunctionInfo(
       Allocator, F, static_cast<const ARMSubtarget *>(STI));
 }
 
+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 (TargetABI == ARM::ARM_ABI_AAPCS16)
+    return FloatABI::Hard;
+  // Otherwise fall back to the ABI implied by the target triple.
+  return M.getTargetTriple().getDefaultFloatABI();
+}
+
 const ARMSubtarget *
 ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
   Attribute CPUAttr = F.getFnAttribute("target-cpu");
@@ -238,16 +242,7 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) const {
   if (DM != DenormalMode::getIEEE())
     Key += "denormal-fp-math=" + DM.str();
 
-  // The float ABI comes from the "float-abi" module flag if present, otherwise
-  // from the legacy -float-abi target option (which the constructor seeded from
-  // the target triple).
-  FloatABI::ABIType FloatABI = F.getParent()->getFloatABI();
-  if (FloatABI == FloatABI::Default) {
-    FloatABI = Options.FloatABIType;
-    assert(FloatABI != FloatABI::Default &&
-           "expected TargetMachine constructor to overwrite default float abi");
-  }
-
+  FloatABI::ABIType FloatABI = getFloatABI(*F.getParent());
   // It is legal to have FloatABI::Hard with +soft-float for targets with SIMD
   // registers, but no floating-point hardware (mve+nofp)
   Key += FloatABI == FloatABI::Hard ? "+hard-float-abi" : "+soft-float-abi";
diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.h b/llvm/lib/Target/ARM/ARMTargetMachine.h
index 1d373e65978f9..81dc7a5965f6f 100644
--- a/llvm/lib/Target/ARM/ARMTargetMachine.h
+++ b/llvm/lib/Target/ARM/ARMTargetMachine.h
@@ -52,6 +52,11 @@ class ARMBaseTargetMachine : public CodeGenTargetMachineImpl {
   const ARMSubtarget *getSubtargetImpl() const = delete;
   bool isLittleEndian() const { return isLittle; }
 
+  /// Returns the floating-point ABI ...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/215796


More information about the llvm-branch-commits mailing list