[llvm-branch-commits] [llvm] CodeGen: Synthesize "float-abi" module flag from -float-abi (PR #215795)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Aug 12 06:47:56 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-nvptx
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
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
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"}
``````````
</details>
https://github.com/llvm/llvm-project/pull/215795
More information about the llvm-branch-commits
mailing list