Skip to content

Commit 23bc1ae

Browse files
authored
Rollup merge of #161317 - TimNN:float-abi-flag, r=khyperia
LLVM 24: configure float-abi via module flag `TargetOptions::FloatABIType` was removed in llvm/llvm-project#215796 See llvm/llvm-project#212985 for the corresponding clang change. The `ModuleFlagMergeBehavior::Error` was copied from the clang implementation. This currently relies on the string representation of Rust's [`FloatAbi` "target_spec_enum"](https://github.com/rust-lang/rust/blob/e71c0f1e3395b10a8c331317be1a5c107bdf7b2e/compiler/rustc_target/src/spec/mod.rs#L978-L986) matching LLVM. This seemed reasonable to me since the representation is quite straightforward ("soft" and "hard"), but let me know if you'd like an explicit `to_llvm_float_abi_str`, either defined in Rust or forwarding to `llvm::FloatABI::getABITypeName`. Contrary to the clang implementation which only sets the module flag if it differs from the target default, we set it whenever the Rust target has an explicit float ABI set. See also discussion in [#t-compiler/llvm > float-abi module flag behavior](https://rust-lang.zulipchat.com/#narrow/channel/187780-t-compiler.2Fllvm/topic/float-abi.20module.20flag.20behavior/with/617279073). The added test won't actually run on Rust's own CI until that updates to LLVM 24. @rustbot label llvm-main
2 parents f7e9665 + 4c28ae2 commit 23bc1ae

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,17 @@ pub(crate) unsafe fn create_module<'ll>(
564564
);
565565
}
566566

567+
if llvm_version >= (24, 0, 0)
568+
&& let Some(floatabi) = sess.target.llvm_floatabi
569+
{
570+
llvm::add_module_flag_str(
571+
llmod,
572+
llvm::ModuleFlagMergeBehavior::Error,
573+
"float-abi",
574+
floatabi.desc(),
575+
);
576+
}
577+
567578
// Add module flags specified via -Z llvm_module_flag
568579
for (key, value, merge_behavior) in &sess.opts.unstable_opts.llvm_module_flag {
569580
let merge_behavior = match merge_behavior.as_str() {

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
365365

366366
TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Trip);
367367

368+
#if LLVM_VERSION_LT(24, 0)
368369
Options.FloatABIType = FloatABIType;
370+
#endif
369371
Options.DataSections = DataSections;
370372
Options.FunctionSections = FunctionSections;
371373
Options.UniqueSectionNames = UniqueSectionNames;
@@ -439,7 +441,11 @@ extern "C" void LLVMRustAddLibraryInfo(LLVMTargetMachineRef T,
439441
if (DisableSimplifyLibCalls)
440442
TLII.disableAllFunctions();
441443
unwrap(PMR)->add(new TargetLibraryInfoWrapperPass(TLII));
442-
#if LLVM_VERSION_GE(22, 0)
444+
#if LLVM_VERSION_GE(24, 0)
445+
unwrap(PMR)->add(new RuntimeLibraryInfoWrapper(
446+
Options->ExceptionModel, Options->EABIVersion, Options->MCOptions.ABIName,
447+
Options->VecLib));
448+
#elif LLVM_VERSION_GE(22, 0)
443449
unwrap(PMR)->add(new RuntimeLibraryInfoWrapper(
444450
TargetTriple, Options->ExceptionModel, Options->FloatABIType,
445451
Options->EABIVersion, Options->MCOptions.ABIName, Options->VecLib));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ add-minicore
2+
//@ min-llvm-version: 24
3+
//@ revisions: armhf armsf aarch64sf
4+
5+
//@ [armhf] needs-llvm-components: arm
6+
//@ [armhf] compile-flags: --target=armv7-unknown-linux-gnueabihf
7+
8+
//@ [armsf] needs-llvm-components: arm
9+
//@ [armsf] compile-flags: --target=armv7-unknown-linux-gnueabi
10+
11+
//@ [aarch64sf] needs-llvm-components: aarch64
12+
//@ [aarch64sf] compile-flags: --target=aarch64-unknown-none-softfloat
13+
14+
#![crate_type = "lib"]
15+
#![feature(no_core)]
16+
#![no_core]
17+
18+
// rustc sets the module flag only for targets with an explicit `llvm_floatabi`,
19+
// which is (currently) only the case on ARM.
20+
21+
// armhf: !{i32 1, !"float-abi", !"hard"}
22+
// armsf: !{i32 1, !"float-abi", !"soft"}
23+
// aarch64sf-NOT: !"float-abi"

0 commit comments

Comments
 (0)