Skip to content

Commit 751237a

Browse files
committed
explicitly track SPE ABI for PowerPC
1 parent ba1d939 commit 751237a

5 files changed

Lines changed: 44 additions & 21 deletions

File tree

‎compiler/rustc_target/src/spec/mod.rs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,8 @@ crate::target_spec_enum! {
10061006
pubenumRustcAbi{
10071007
/// On x86-32 only: make use of SSE and SSE2 for ABI purposes.
10081008
X86Sse2 = "x86-sse2",
1009+
/// On PowerPC only: build for SPE.
1010+
PowerPcSpe = "powerpc-spe",
10091011
/// On x86-32/64, aarch64, and S390x: do not use any FPU or SIMD registers for the ABI.
10101012
Softfloat = "softfloat","x86-softfloat",
10111013
}
@@ -3445,13 +3447,15 @@ impl Target {
34453447
"`llvm_abiname` is unused on PowerPC"
34463448
);
34473449
check!(self.llvm_floatabi.is_none(),"`llvm_floatabi` is unused on PowerPC");
3448-
check!(self.rustc_abi.is_none(),"`rustc_abi` is unused on PowerPC");
3449-
// FIXME: Check that `target_abi` matches the actually configured ABI (with or
3450-
// without SPE).
34513450
check_matches!(
3451+
(&self.rustc_abi,&self.cfg_abi),
3452+
(Some(RustcAbi::PowerPcSpe),CfgAbi::Spe)
3453+
| (None,CfgAbi::Unspecified | CfgAbi::Other(_)),
3454+
"invalid PowerPC Rust-specific ABI and `cfg(target_abi)` combination:\n\
3455+
Rust-specific ABI: {:?}\n\
3456+
cfg(target_abi): {}",
3457+
self.rustc_abi,
34523458
self.cfg_abi,
3453-
CfgAbi::Spe | CfgAbi::Unspecified | CfgAbi::Other(_),
3454-
"invalid `target_abi` for PowerPC"
34553459
);
34563460
}
34573461
Arch::PowerPC64 => {

‎compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_gnuspe.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_abi::Endian;
22

33
usecrate::spec::{
4-
Arch,Cc,CfgAbi,LinkerFlavor,Lld,StackProbeType,Target,TargetMetadata,TargetOptions,
5-
base,
4+
Arch,Cc,CfgAbi,LinkerFlavor,Lld,RustcAbi,StackProbeType,Target,TargetMetadata,
5+
TargetOptions,base,
66
};
77

88
pub(crate)fntarget() -> Target{
@@ -24,6 +24,7 @@ pub(crate) fn target() -> Target {
2424
arch:Arch::PowerPC,
2525
options:TargetOptions{
2626
cfg_abi:CfgAbi::Spe,
27+
rustc_abi:Some(RustcAbi::PowerPcSpe),
2728
endian:Endian::Big,
2829
features:"+secure-plt,+msync,+spe".into(),
2930
mcount:"_mcount".into(),

‎compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_abi::Endian;
22

33
usecrate::spec::{
4-
Arch,Cc,CfgAbi,LinkerFlavor,Lld,StackProbeType,Target,TargetMetadata,TargetOptions,
5-
base,
4+
Arch,Cc,CfgAbi,LinkerFlavor,Lld,RustcAbi,StackProbeType,Target,TargetMetadata,
5+
TargetOptions,base,
66
};
77

88
pub(crate)fntarget() -> Target{
@@ -24,6 +24,7 @@ pub(crate) fn target() -> Target {
2424
arch:Arch::PowerPC,
2525
options:TargetOptions{
2626
cfg_abi:CfgAbi::Spe,
27+
rustc_abi:Some(RustcAbi::PowerPcSpe),
2728
endian:Endian::Big,
2829
features:"+msync,+spe".into(),
2930
mcount:"_mcount".into(),

‎compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks_spe.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_abi::Endian;
22

33
usecrate::spec::{
4-
Arch,Cc,CfgAbi,LinkerFlavor,Lld,StackProbeType,Target,TargetMetadata,TargetOptions,
5-
base,
4+
Arch,Cc,CfgAbi,LinkerFlavor,Lld,RustcAbi,StackProbeType,Target,TargetMetadata,
5+
TargetOptions,base,
66
};
77

88
pub(crate)fntarget() -> Target{
@@ -24,6 +24,7 @@ pub(crate) fn target() -> Target {
2424
arch:Arch::PowerPC,
2525
options:TargetOptions{
2626
cfg_abi:CfgAbi::Spe,
27+
rustc_abi:Some(RustcAbi::PowerPcSpe),
2728
endian:Endian::Big,
2829
// feature msync would disable instruction 'fsync' which is not supported by fsl_p1p2
2930
features:"+secure-plt,+msync,+spe".into(),

‎compiler/rustc_target/src/target_features.rs‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ impl Target {
11781178
// LLVM handles the rest.
11791179
FeatureConstraints{required:&["soft-float"],incompatible:&[]}
11801180
}
1181+
_ => unreachable!(),
11811182
}
11821183
}
11831184
Arch::X86_64 => {
@@ -1198,7 +1199,7 @@ impl Target {
11981199
// LLVM handles the rest.
11991200
FeatureConstraints{required:&["soft-float"],incompatible:&[]}
12001201
}
1201-
Some(r) => panic!("invalid Rust ABI for x86_64: {r:?}"),
1202+
_ => unreachable!(),
12021203
}
12031204
}
12041205
Arch::Arm => {
@@ -1235,7 +1236,7 @@ impl Target {
12351236
// `FeatureConstraints` uses Rust feature names, hence only "neon" shows up.
12361237
FeatureConstraints{required:&["neon"],incompatible:&[]}
12371238
}
1238-
Some(r) => panic!("invalid Rust ABI for aarch64: {r:?}"),
1239+
_ => unreachable!(),
12391240
}
12401241
}
12411242
Arch::RiscV32 | Arch::RiscV64 => {
@@ -1312,17 +1313,32 @@ impl Target {
13121313
// llvm will switch to soft-float ABI just based on this feature.
13131314
FeatureConstraints{required:&["soft-float"],incompatible:&["vector"]}
13141315
}
1315-
Some(r) => {
1316-
panic!("invalid Rust ABI for s390x: {r:?}");
1316+
_ => unreachable!(),
1317+
}
1318+
}
1319+
Arch::PowerPC => {
1320+
// The main ABI-relevant target features are "hard-float" and "spe". We use our own
1321+
// ABI indicator here.
1322+
matchself.rustc_abi{
1323+
None => {
1324+
// Default hardfloat ABI.
1325+
FeatureConstraints{required:&["hard-float"],incompatible:&["spe"]}
1326+
}
1327+
Some(RustcAbi::PowerPcSpe) => {
1328+
// We reject "efpu2" since that seems to *disable* the f64 registers in
1329+
// LLVM, which seems likely to affect the ABI.
1330+
FeatureConstraints{
1331+
required:&["hard-float","spe"],
1332+
incompatible:&["efpu2"],
1333+
}
13171334
}
1335+
_ => unreachable!(),
13181336
}
13191337
}
1320-
Arch::PowerPC | Arch::PowerPC64 => {
1321-
// The main ABI-relevant target features are "hard-float" and "spe". There is also
1322-
// "efpu2" but that seems only relevant when "spe" is enabled. If we ever add a
1323-
// soft-float variant, it looks like we have to mark "altivec" as incompatible --
1324-
// unlike other targets, it looks like enabling "altivec" will have LLVM use
1325-
// different registers for float types even if "hard-float" is off.
1338+
Arch::PowerPC64 => {
1339+
// There's no SPE for PowerPC64, and we currently don't support any soft-float
1340+
// targets. (If we ever add one, we need to match on `RustcAbi::Softfloat` similar
1341+
// to other targets above.)
13261342
FeatureConstraints{required:&["hard-float"],incompatible:&["spe"]}
13271343
}
13281344
Arch::Avr => {

0 commit comments

Comments
 (0)