Skip to content

Commit 2920cc4

Browse files
committed
Fix SSA analysis for value types with PassMode::ByRef
1 parent ca93bcb commit 2920cc4

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use cranelift_codegen::ir::AbiParam;
1010
use self::pass_mode::*;
1111
use crate::prelude::*;
1212

13-
pub use self::returning::codegen_return;
13+
pub use self::returning::{can_return_to_ssa_var, codegen_return};
1414

1515
// Copied from https://github.com/rust-lang/rust/blob/c2f4c57296f0d929618baed0b0d6eb594abf01eb/src/librustc/ty/layout.rs#L2349
1616
pub fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> {

src/abi/returning.rs

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ fn return_layout<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> TyLay
55
fx.layout_of(fx.monomorphize(&fx.mir.local_decls[RETURN_PLACE].ty))
66
}
77

8+
pub fn can_return_to_ssa_var<'tcx>(tcx: TyCtxt<'tcx>, dest_layout: TyLayout<'tcx>) -> bool {
9+
match get_pass_mode(tcx, dest_layout) {
10+
PassMode::NoPass | PassMode::ByVal(_) => true,
11+
// FIXME Make it possible to return ByValPair and ByRef to an ssa var.
12+
PassMode::ByValPair(_, _) | PassMode::ByRef => false
13+
}
14+
}
15+
816
pub fn codegen_return_param(
917
fx: &mut FunctionCx<impl Backend>,
1018
ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>,

src/analyze.rs

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind
3030
_ => {}
3131
}
3232
}
33+
34+
match &bb.terminator().kind {
35+
TerminatorKind::Call { destination, .. } => {
36+
if let Some((dest_place, _dest_bb)) = destination {
37+
let dest_layout = fx.layout_of(fx.monomorphize(&dest_place.ty(&fx.mir.local_decls, fx.tcx).ty));
38+
if !crate::abi::can_return_to_ssa_var(fx.tcx, dest_layout) {
39+
analyze_non_ssa_place(&mut flag_map, dest_place);
40+
}
41+
}
42+
}
43+
_ => {}
44+
}
3345
}
3446

3547
flag_map

0 commit comments

Comments
 (0)