Skip to content

Commit c40e2ac

Browse files
committed
Auto merge of rust-lang#55024 - alexcrichton:wasm-simd-by-val, r=estebank
rustc: Allow targets to specify SIMD args are by-val The upcoming SIMD support in the wasm target is unique from the other platforms where it's either unconditionally available or not available, there's no halfway where a subsection of the program can use it but no other parts of the program can use it. In this world it's valid for wasm SIMD args to always be passed by value and there's no need to pass them by reference. This commit adds a new custom target specification option `simd_types_indirect` which defaults to `true`, but the wasm backend disables this and sets it to `false`.
2 parents f02768b + 9562b69 commit c40e2ac

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/librustc_codegen_llvm/abi.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,10 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
536536
// Note that the platform intrinsic ABI is exempt here as
537537
// that's how we connect up to LLVM and it's unstable
538538
// anyway, we control all calls to it in libstd.
539-
layout::Abi::Vector { .. } if abi != Abi::PlatformIntrinsic => {
539+
layout::Abi::Vector { .. }
540+
if abi != Abi::PlatformIntrinsic &&
541+
cx.sess().target.target.options.simd_types_indirect =>
542+
{
540543
arg.make_indirect();
541544
return
542545
}

src/librustc_target/spec/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,12 @@ pub struct TargetOptions {
680680
/// typically because the platform needs to unwind for things like stack
681681
/// unwinders.
682682
pub requires_uwtable: bool,
683+
684+
/// Whether or not SIMD types are passed by reference in the Rust ABI,
685+
/// typically required if a target can be compiled with a mixed set of
686+
/// target features. This is `true` by default, and `false` for targets like
687+
/// wasm32 where the whole program either has simd or not.
688+
pub simd_types_indirect: bool,
683689
}
684690

685691
impl Default for TargetOptions {
@@ -760,6 +766,7 @@ impl Default for TargetOptions {
760766
embed_bitcode: false,
761767
emit_debug_gdb_scripts: true,
762768
requires_uwtable: false,
769+
simd_types_indirect: true,
763770
}
764771
}
765772
}
@@ -1041,6 +1048,7 @@ impl Target {
10411048
key!(embed_bitcode, bool);
10421049
key!(emit_debug_gdb_scripts, bool);
10431050
key!(requires_uwtable, bool);
1051+
key!(simd_types_indirect, bool);
10441052

10451053
if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
10461054
for name in array.iter().filter_map(|abi| abi.as_string()) {
@@ -1250,6 +1258,7 @@ impl ToJson for Target {
12501258
target_option_val!(embed_bitcode);
12511259
target_option_val!(emit_debug_gdb_scripts);
12521260
target_option_val!(requires_uwtable);
1261+
target_option_val!(simd_types_indirect);
12531262

12541263
if default.abi_blacklist != self.options.abi_blacklist {
12551264
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()

src/librustc_target/spec/wasm32_unknown_unknown.rs

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ pub fn target() -> Result<Target, String> {
5454
linker: Some("rust-lld".to_owned()),
5555
lld_flavor: LldFlavor::Wasm,
5656

57+
// No need for indirection here, simd types can always be passed by
58+
// value as the whole module either has simd or not, which is different
59+
// from x86 (for example) where programs can have functions that don't
60+
// enable simd features.
61+
simd_types_indirect: false,
62+
5763
.. Default::default()
5864
};
5965
Ok(Target {

0 commit comments

Comments
 (0)