[llvm] CSKY: Consume "float-abi" module flag (PR #212975)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 31 08:07:23 PDT 2026


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/212975

>From 064559e0b112186dd4c56b5aeee5abb595fe6fe6 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 20 Jul 2026 18:35:38 +0200
Subject: [PATCH 1/3] CSKY: Consume "float-abi" module flag

Start respecting float-abi, and fall back on the TargetOptions
field if not present.

Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
---
 llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp       |  4 +-
 llvm/lib/Target/CSKY/CSKYAsmPrinter.h         |  2 +-
 llvm/lib/Target/CSKY/CSKYSubtarget.cpp        | 12 +++--
 llvm/lib/Target/CSKY/CSKYSubtarget.h          |  7 ++-
 llvm/lib/Target/CSKY/CSKYTargetMachine.cpp    |  9 +++-
 .../CodeGen/CSKY/float-abi-module-flag.ll     | 45 +++++++++++++++++++
 6 files changed, 67 insertions(+), 12 deletions(-)
 create mode 100644 llvm/test/CodeGen/CSKY/float-abi-module-flag.ll

diff --git a/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp b/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
index aa0276123e240..7c8e8dd950e68 100644
--- a/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
+++ b/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
@@ -129,7 +129,7 @@ void CSKYAsmPrinter::emitFunctionBodyEnd() {
 
 void CSKYAsmPrinter::emitStartOfAsmFile(Module &M) {
   if (TM.getTargetTriple().isOSBinFormatELF())
-    emitAttributes();
+    emitAttributes(M);
 }
 
 void CSKYAsmPrinter::emitEndOfAsmFile(Module &M) {
@@ -245,7 +245,7 @@ void CSKYAsmPrinter::emitMachineConstantPoolValue(
   OutStreamer->emitValue(Expr, Size);
 }
 
-void CSKYAsmPrinter::emitAttributes() {
+void CSKYAsmPrinter::emitAttributes(Module &M) {
   CSKYTargetStreamer &CTS =
       static_cast<CSKYTargetStreamer &>(*OutStreamer->getTargetStreamer());
 
diff --git a/llvm/lib/Target/CSKY/CSKYAsmPrinter.h b/llvm/lib/Target/CSKY/CSKYAsmPrinter.h
index da47b650f1e19..fafc2ef000a9e 100644
--- a/llvm/lib/Target/CSKY/CSKYAsmPrinter.h
+++ b/llvm/lib/Target/CSKY/CSKYAsmPrinter.h
@@ -29,7 +29,7 @@ class LLVM_LIBRARY_VISIBILITY CSKYAsmPrinter : public AsmPrinter {
 
   void expandTLSLA(const MachineInstr *MI);
   void emitCustomConstantPool(const MachineInstr *MI);
-  void emitAttributes();
+  void emitAttributes(Module &M);
 
 public:
   explicit CSKYAsmPrinter(TargetMachine &TM,
diff --git a/llvm/lib/Target/CSKY/CSKYSubtarget.cpp b/llvm/lib/Target/CSKY/CSKYSubtarget.cpp
index 94e412ec81725..01d0cd2bc8084 100644
--- a/llvm/lib/Target/CSKY/CSKYSubtarget.cpp
+++ b/llvm/lib/Target/CSKY/CSKYSubtarget.cpp
@@ -89,10 +89,11 @@ CSKYSubtarget &CSKYSubtarget::initializeSubtargetDependencies(
 }
 
 CSKYSubtarget::CSKYSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
-                             StringRef FS, const TargetMachine &TM)
+                             StringRef FS, FloatABI::ABIType FloatABI,
+                             const TargetMachine &TM)
     : CSKYGenSubtargetInfo(TT, CPU, TuneCPU, FS),
       FrameLowering(initializeSubtargetDependencies(TT, CPU, TuneCPU, FS)),
-      InstrInfo(*this, RegInfo), TLInfo(TM, *this) {
+      InstrInfo(*this, RegInfo), TLInfo(TM, *this), FloatABIType(FloatABI) {
   TSInfo = std::make_unique<CSKYSelectionDAGInfo>();
 }
 
@@ -103,10 +104,7 @@ const SelectionDAGTargetInfo *CSKYSubtarget::getSelectionDAGInfo() const {
 }
 
 bool CSKYSubtarget::useHardFloatABI() const {
-  auto FloatABI = getTargetLowering()->getTargetMachine().Options.FloatABIType;
-
-  if (FloatABI == FloatABI::Default)
+  if (FloatABIType == FloatABI::Default)
     return UseHardFloatABI;
-  else
-    return FloatABI == FloatABI::Hard;
+  return FloatABIType == FloatABI::Hard;
 }
diff --git a/llvm/lib/Target/CSKY/CSKYSubtarget.h b/llvm/lib/Target/CSKY/CSKYSubtarget.h
index f5ad26a20d8a5..e0e93aa65caed 100644
--- a/llvm/lib/Target/CSKY/CSKYSubtarget.h
+++ b/llvm/lib/Target/CSKY/CSKYSubtarget.h
@@ -56,6 +56,10 @@ class CSKYSubtarget : public CSKYGenSubtargetInfo {
 
   bool UseHardFloat;
   bool UseHardFloatABI;
+
+  /// The floating-point ABI in effect for this subtarget, resolved from the
+  /// "float-abi" module flag or the target options.
+  FloatABI::ABIType FloatABIType;
   bool HasFPUv2SingleFloat;
   bool HasFPUv2DoubleFloat;
   bool HasFPUv3HalfWord;
@@ -109,7 +113,8 @@ class CSKYSubtarget : public CSKYGenSubtargetInfo {
 
 public:
   CSKYSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
-                StringRef FS, const TargetMachine &TM);
+                StringRef FS, FloatABI::ABIType FloatABI,
+                const TargetMachine &TM);
 
   ~CSKYSubtarget() override;
 
diff --git a/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp b/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
index 326dedfa08328..b4c8f0e709856 100644
--- a/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
+++ b/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
@@ -20,6 +20,7 @@
 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/IR/Module.h"
 #include "llvm/MC/TargetRegistry.h"
 #include <optional>
 
@@ -59,10 +60,16 @@ CSKYTargetMachine::getSubtargetImpl(const Function &F) const {
   std::string FS =
       FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
 
+  FloatABI::ABIType FloatABI = F.getParent()->getFloatABI();
+  if (FloatABI == FloatABI::Default)
+    FloatABI = Options.FloatABIType;
+
   std::string Key = CPU + TuneCPU + FS;
+  Key += FloatABI == FloatABI::Soft ? "+soft-float-abi" : "+hard-float-abi";
   auto &I = SubtargetMap[Key];
   if (!I) {
-    I = std::make_unique<CSKYSubtarget>(TargetTriple, CPU, TuneCPU, FS, *this);
+    I = std::make_unique<CSKYSubtarget>(TargetTriple, CPU, TuneCPU, FS,
+                                        FloatABI, *this);
     if (I->useHardFloat() && !I->hasAnyFloatExt())
       errs() << "Hard-float can't be used with current CPU,"
                 " set to Soft-float\n";
diff --git a/llvm/test/CodeGen/CSKY/float-abi-module-flag.ll b/llvm/test/CodeGen/CSKY/float-abi-module-flag.ll
new file mode 100644
index 0000000000000..78cffe05ade2f
--- /dev/null
+++ b/llvm/test/CodeGen/CSKY/float-abi-module-flag.ll
@@ -0,0 +1,45 @@
+; The "float-abi" module flag selects the floating-point calling convention.
+; RUN: split-file %s %t
+
+; Soft float ABI (the target default): FP arguments are passed in GPRs and moved
+; into VFP registers with fmtvrl.
+; RUN: llc -csky-no-aliases -mtriple=csky -mattr=+2e3,+fpuv2_sf,+fpuv2_df,+hard-float < %t/none.ll | FileCheck %s --check-prefix=SOFT
+
+; Hard float ABI module flag: FP arguments arrive directly in VFP registers, so
+; no fmtvrl moves are needed.
+; RUN: llc -csky-no-aliases -mtriple=csky -mattr=+2e3,+fpuv2_sf,+fpuv2_df,+hard-float < %t/hard.ll | FileCheck %s --check-prefix=HARD
+
+; Soft float ABI module flag matches the default.
+; RUN: llc -csky-no-aliases -mtriple=csky -mattr=+2e3,+fpuv2_sf,+fpuv2_df,+hard-float < %t/soft.ll | FileCheck %s --check-prefix=SOFT
+
+; The legacy -float-abi target option still selects the ABI when the module has
+; no "float-abi" flag.
+; RUN: llc -csky-no-aliases -mtriple=csky -mattr=+2e3,+fpuv2_sf,+fpuv2_df,+hard-float -float-abi=hard < %t/none.ll | FileCheck %s --check-prefix=HARD
+
+; An explicit module flag takes precedence over the legacy -float-abi option.
+; RUN: llc -csky-no-aliases -mtriple=csky -mattr=+2e3,+fpuv2_sf,+fpuv2_df,+hard-float -float-abi=hard < %t/soft.ll | FileCheck %s --check-prefix=SOFT
+
+;--- none.ll
+define float @f(float %x, float %y) {
+  %r = fadd float %x, %y
+  ret float %r
+}
+
+;--- hard.ll
+define float @f(float %x, float %y) {
+  %r = fadd float %x, %y
+  ret float %r
+}
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"float-abi", !"hard"}
+
+;--- soft.ll
+define float @f(float %x, float %y) {
+  %r = fadd float %x, %y
+  ret float %r
+}
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"float-abi", !"soft"}
+
+; SOFT: fmtvrl
+; HARD-NOT: fmtvrl

>From 7b44647082b4e2d541d58caa060f1bfff86bb064 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 31 Jul 2026 16:03:02 +0200
Subject: [PATCH 2/3] swap-default

---
 llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp    | 4 ++--
 llvm/lib/Target/CSKY/CSKYAsmPrinter.h      | 2 +-
 llvm/lib/Target/CSKY/CSKYTargetMachine.cpp | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp b/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
index 7c8e8dd950e68..aa0276123e240 100644
--- a/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
+++ b/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
@@ -129,7 +129,7 @@ void CSKYAsmPrinter::emitFunctionBodyEnd() {
 
 void CSKYAsmPrinter::emitStartOfAsmFile(Module &M) {
   if (TM.getTargetTriple().isOSBinFormatELF())
-    emitAttributes(M);
+    emitAttributes();
 }
 
 void CSKYAsmPrinter::emitEndOfAsmFile(Module &M) {
@@ -245,7 +245,7 @@ void CSKYAsmPrinter::emitMachineConstantPoolValue(
   OutStreamer->emitValue(Expr, Size);
 }
 
-void CSKYAsmPrinter::emitAttributes(Module &M) {
+void CSKYAsmPrinter::emitAttributes() {
   CSKYTargetStreamer &CTS =
       static_cast<CSKYTargetStreamer &>(*OutStreamer->getTargetStreamer());
 
diff --git a/llvm/lib/Target/CSKY/CSKYAsmPrinter.h b/llvm/lib/Target/CSKY/CSKYAsmPrinter.h
index fafc2ef000a9e..da47b650f1e19 100644
--- a/llvm/lib/Target/CSKY/CSKYAsmPrinter.h
+++ b/llvm/lib/Target/CSKY/CSKYAsmPrinter.h
@@ -29,7 +29,7 @@ class LLVM_LIBRARY_VISIBILITY CSKYAsmPrinter : public AsmPrinter {
 
   void expandTLSLA(const MachineInstr *MI);
   void emitCustomConstantPool(const MachineInstr *MI);
-  void emitAttributes(Module &M);
+  void emitAttributes();
 
 public:
   explicit CSKYAsmPrinter(TargetMachine &TM,
diff --git a/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp b/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
index b4c8f0e709856..2e1309391c338 100644
--- a/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
+++ b/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp
@@ -65,7 +65,7 @@ CSKYTargetMachine::getSubtargetImpl(const Function &F) const {
     FloatABI = Options.FloatABIType;
 
   std::string Key = CPU + TuneCPU + FS;
-  Key += FloatABI == FloatABI::Soft ? "+soft-float-abi" : "+hard-float-abi";
+  Key += FloatABI == FloatABI::Hard ? "+hard-float-abi" : "+soft-float-abi";
   auto &I = SubtargetMap[Key];
   if (!I) {
     I = std::make_unique<CSKYSubtarget>(TargetTriple, CPU, TuneCPU, FS,

>From 47e589afc05acf7e1c963d009eaf09bf3af52794 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 31 Jul 2026 16:20:55 +0200
Subject: [PATCH 3/3] Use UseHardFloatABI field

---
 llvm/lib/Target/CSKY/CSKYSubtarget.cpp | 9 ++-------
 llvm/lib/Target/CSKY/CSKYSubtarget.h   | 7 ++-----
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/llvm/lib/Target/CSKY/CSKYSubtarget.cpp b/llvm/lib/Target/CSKY/CSKYSubtarget.cpp
index 01d0cd2bc8084..1dc1153460a02 100644
--- a/llvm/lib/Target/CSKY/CSKYSubtarget.cpp
+++ b/llvm/lib/Target/CSKY/CSKYSubtarget.cpp
@@ -93,7 +93,8 @@ CSKYSubtarget::CSKYSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
                              const TargetMachine &TM)
     : CSKYGenSubtargetInfo(TT, CPU, TuneCPU, FS),
       FrameLowering(initializeSubtargetDependencies(TT, CPU, TuneCPU, FS)),
-      InstrInfo(*this, RegInfo), TLInfo(TM, *this), FloatABIType(FloatABI) {
+      InstrInfo(*this, RegInfo), TLInfo(TM, *this),
+      UseHardFloatABI(FloatABI == FloatABI::Hard) {
   TSInfo = std::make_unique<CSKYSelectionDAGInfo>();
 }
 
@@ -102,9 +103,3 @@ CSKYSubtarget::~CSKYSubtarget() = default;
 const SelectionDAGTargetInfo *CSKYSubtarget::getSelectionDAGInfo() const {
   return TSInfo.get();
 }
-
-bool CSKYSubtarget::useHardFloatABI() const {
-  if (FloatABIType == FloatABI::Default)
-    return UseHardFloatABI;
-  return FloatABIType == FloatABI::Hard;
-}
diff --git a/llvm/lib/Target/CSKY/CSKYSubtarget.h b/llvm/lib/Target/CSKY/CSKYSubtarget.h
index e0e93aa65caed..c5002bf214a7b 100644
--- a/llvm/lib/Target/CSKY/CSKYSubtarget.h
+++ b/llvm/lib/Target/CSKY/CSKYSubtarget.h
@@ -56,10 +56,6 @@ class CSKYSubtarget : public CSKYGenSubtargetInfo {
 
   bool UseHardFloat;
   bool UseHardFloatABI;
-
-  /// The floating-point ABI in effect for this subtarget, resolved from the
-  /// "float-abi" module flag or the target options.
-  FloatABI::ABIType FloatABIType;
   bool HasFPUv2SingleFloat;
   bool HasFPUv2DoubleFloat;
   bool HasFPUv3HalfWord;
@@ -139,7 +135,8 @@ class CSKYSubtarget : public CSKYGenSubtargetInfo {
   // Generated by inc file
   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
 
-  bool useHardFloatABI() const;
+  bool useHardFloatABI() const { return UseHardFloatABI; }
+
   bool useHardFloat() const { return UseHardFloat; }
   bool hasFPUv2SingleFloat() const { return HasFPUv2SingleFloat; }
   bool hasFPUv2DoubleFloat() const { return HasFPUv2DoubleFloat; }



More information about the llvm-commits mailing list