CodeGen: Synthesize "float-abi" module flag from -float-abi - #215795
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@llvm/pr-subscribers-backend-arm @llvm/pr-subscribers-backend-nvptx Author: Matt Arsenault (arsenm) ChangesAvoid annoying test updates when the corresponding TargetOptions 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:
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"}
|
05a4564 to
2fac20d
Compare
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
00fb3f7 to
6d7e249
Compare
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>
6d7e249 to
c24ac2f
Compare

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