Fix SSA analysis for value types with PassMode::ByRef
This commit is contained in:
parent
ca93bcba5d
commit
2920cc48e6
3 changed files with 21 additions and 1 deletions
|
@ -10,7 +10,7 @@ use cranelift_codegen::ir::AbiParam;
|
||||||
use self::pass_mode::*;
|
use self::pass_mode::*;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub use self::returning::codegen_return;
|
pub use self::returning::{can_return_to_ssa_var, codegen_return};
|
||||||
|
|
||||||
// Copied from https://github.com/rust-lang/rust/blob/c2f4c57296f0d929618baed0b0d6eb594abf01eb/src/librustc/ty/layout.rs#L2349
|
// Copied from https://github.com/rust-lang/rust/blob/c2f4c57296f0d929618baed0b0d6eb594abf01eb/src/librustc/ty/layout.rs#L2349
|
||||||
pub fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> {
|
pub fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> {
|
||||||
|
|
|
@ -5,6 +5,14 @@ fn return_layout<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> TyLay
|
||||||
fx.layout_of(fx.monomorphize(&fx.mir.local_decls[RETURN_PLACE].ty))
|
fx.layout_of(fx.monomorphize(&fx.mir.local_decls[RETURN_PLACE].ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn can_return_to_ssa_var<'tcx>(tcx: TyCtxt<'tcx>, dest_layout: TyLayout<'tcx>) -> bool {
|
||||||
|
match get_pass_mode(tcx, dest_layout) {
|
||||||
|
PassMode::NoPass | PassMode::ByVal(_) => true,
|
||||||
|
// FIXME Make it possible to return ByValPair and ByRef to an ssa var.
|
||||||
|
PassMode::ByValPair(_, _) | PassMode::ByRef => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn codegen_return_param(
|
pub fn codegen_return_param(
|
||||||
fx: &mut FunctionCx<impl Backend>,
|
fx: &mut FunctionCx<impl Backend>,
|
||||||
ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>,
|
ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>,
|
||||||
|
|
|
@ -30,6 +30,18 @@ pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match &bb.terminator().kind {
|
||||||
|
TerminatorKind::Call { destination, .. } => {
|
||||||
|
if let Some((dest_place, _dest_bb)) = destination {
|
||||||
|
let dest_layout = fx.layout_of(fx.monomorphize(&dest_place.ty(&fx.mir.local_decls, fx.tcx).ty));
|
||||||
|
if !crate::abi::can_return_to_ssa_var(fx.tcx, dest_layout) {
|
||||||
|
analyze_non_ssa_place(&mut flag_map, dest_place);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flag_map
|
flag_map
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue