Skip to content

CodeGen: Synthesize "float-abi" module flag from -float-abi - #215795

Merged
arsenm merged 3 commits into
mainfrom
users/arsenm/float-abi-synthesize-from-cl-opt
Aug 18, 2026
Merged

CodeGen: Synthesize "float-abi" module flag from -float-abi#215795
arsenm merged 3 commits into
mainfrom
users/arsenm/float-abi-synthesize-from-cl-opt

Conversation

@arsenm

@arsenm arsenm commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Avoid annoying test updates when the corresponding TargetOptions
field is removed. Make the -float-abi llc/opt option a lit test
convenience that records the floating-point ABI in the IR,
mirroring how -mcpu/-mattr are recorded as function attributes.

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

arsenm commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@llvmorg-github-actions

llvmorg-github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-arm
@llvm/pr-subscribers-backend-msp430
@llvm/pr-subscribers-llvm-selectiondag
@llvm/pr-subscribers-backend-hexagon

@llvm/pr-subscribers-backend-nvptx

Author: Matt Arsenault (arsenm)

Changes

Avoid annoying test updates when the corresponding TargetOptions
field is removed. Make the -float-abi llc/opt option a lit test
convenience that records the floating-point ABI in the IR,
mirroring how -mcpu/-mattr are recorded as function attributes.

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


Full diff: https://github.com/llvm/llvm-project/pull/215795.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/CommandFlags.cpp (+11-1)
  • (added) llvm/test/CodeGen/ARM/float-abi-synthesize-flag.ll (+32)
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index 306c0ff7c704b..88987d0bc5558 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -270,7 +270,9 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
   CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
 
   static cl::opt<FloatABI::ABIType> FloatABIForCalls(
-      "float-abi", cl::desc("Choose float ABI type"),
+      "float-abi",
+      cl::desc(
+          "Choose float ABI type (writes the \"float-abi\" IR module flag)"),
       cl::init(FloatABI::Default),
       cl::values(clEnumValN(FloatABI::Default, "default",
                             "Target default float ABI type"),
@@ -774,6 +776,14 @@ void codegen::setFunctionAttributes(Function &F, StringRef CPU,
 
 void codegen::setFunctionAttributes(Module &M, StringRef CPU,
                                     StringRef Features, StringRef TuneCPU) {
+  // Synthesize the "float-abi" module flag from the -float-abi option,
+  FloatABI::ABIType ABI = getFloatABIForCalls();
+  if (ABI != FloatABI::Default && !M.getModuleFlag("float-abi")) {
+    M.addModuleFlag(
+        Module::Error, "float-abi",
+        MDString::get(M.getContext(), FloatABI::getABITypeName(ABI)));
+  }
+
   for (Function &F : M)
     setFunctionAttributes(F, CPU, Features, TuneCPU);
 }
diff --git a/llvm/test/CodeGen/ARM/float-abi-synthesize-flag.ll b/llvm/test/CodeGen/ARM/float-abi-synthesize-flag.ll
new file mode 100644
index 0000000000000..ce4d47d18010f
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/float-abi-synthesize-flag.ll
@@ -0,0 +1,32 @@
+; Check behavior of the -float-abi command-line option; it should
+; synthesize the "float-abi" module flag, unless one is already
+; present
+
+; RUN: split-file %s %t
+
+; -float-abi=hard writes the module flag.
+; RUN: llc -mtriple=armv7-none-eabi -float-abi=hard -stop-after=finalize-isel %t/none.ll -o - | FileCheck %s --check-prefix=HARD
+
+; -float-abi=soft writes the module flag.
+; RUN: llc -mtriple=armv7-none-eabi -float-abi=soft -stop-after=finalize-isel %t/none.ll -o - | FileCheck %s --check-prefix=SOFT
+
+; Without -float-abi, no flag is synthesized.
+; RUN: llc -mtriple=armv7-none-eabi -stop-after=finalize-isel %t/none.ll -o - | FileCheck %s --check-prefix=NONE
+
+; An explicit in-IR flag is not overridden by -float-abi.
+; RUN: llc -mtriple=armv7-none-eabi -float-abi=soft -stop-after=finalize-isel %t/hard.ll -o - | FileCheck %s --check-prefix=HARD
+
+;--- none.ll
+define void @f() {
+  ret void
+}
+; HARD: !{i32 1, !"float-abi", !"hard"}
+; SOFT: !{i32 1, !"float-abi", !"soft"}
+; NONE-NOT: !"float-abi"
+
+;--- hard.ll
+define void @f() {
+  ret void
+}
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"float-abi", !"hard"}

Comment thread llvm/lib/CodeGen/CommandFlags.cpp Outdated
Comment thread llvm/lib/CodeGen/CommandFlags.cpp Outdated
Base automatically changed from users/arsenm/codegen/relocate-generic-fp-libcall-tests to main August 12, 2026 20:15
@arsenm
arsenm force-pushed the users/arsenm/float-abi-synthesize-from-cl-opt branch from 05a4564 to 2fac20d Compare August 13, 2026 09:52
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 202138 tests passed
  • 5590 tests skipped

✅ The build succeeded and all tests passed.

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 139869 tests passed
  • 3706 tests skipped

✅ The build succeeded and all tests passed.

@arsenm
arsenm force-pushed the users/arsenm/float-abi-synthesize-from-cl-opt branch 2 times, most recently from 00fb3f7 to 6d7e249 Compare August 14, 2026 13:40
Avoid annoying test updates when the corresponding TargetOptions
field is removed. Make the -float-abi llc/opt option a lit test
convenience that records the floating-point ABI in the IR,
mirroring how -mcpu/-mattr are recorded as function attributes.

Co-authored-by: Claude (Claude-Opus-4.8) <noreply@anthropic.com>
@arsenm
arsenm force-pushed the users/arsenm/float-abi-synthesize-from-cl-opt branch from 6d7e249 to c24ac2f Compare August 17, 2026 06:47

@ilovepi ilovepi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@arsenm
arsenm merged commit 77adee2 into main Aug 18, 2026
12 checks passed
@arsenm
arsenm deleted the users/arsenm/float-abi-synthesize-from-cl-opt branch August 18, 2026 15:33
ronlieb pushed a commit to ROCm/llvm-project that referenced this pull request Aug 18, 2026
kieroxide pushed a commit to kieroxide/llvm-project that referenced this pull request Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants