Remove a couple of duplicate layout_of and monomorphize calls
This commit is contained in:
parent
bdb0665479
commit
7870b296e4
@ -275,10 +275,6 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
|
||||
self::comments::add_locals_header_comment(fx);
|
||||
|
||||
for (local, arg_kind, ty) in func_params {
|
||||
let layout = fx.layout_of(ty);
|
||||
|
||||
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
|
||||
|
||||
// While this is normally an optimization to prevent an unnecessary copy when an argument is
|
||||
// not mutated by the current function, this is necessary to support unsized arguments.
|
||||
if let ArgKind::Normal(Some(val)) = arg_kind {
|
||||
@ -300,6 +296,8 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
|
||||
}
|
||||
}
|
||||
|
||||
let layout = fx.layout_of(ty);
|
||||
let is_ssa = ssa_analyzed[local].is_ssa(fx, ty);
|
||||
let place = make_local_place(fx, local, layout, is_ssa);
|
||||
assert_eq!(fx.local_map.push(place), local);
|
||||
|
||||
@ -323,7 +321,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
|
||||
let ty = fx.monomorphize(fx.mir.local_decls[local].ty);
|
||||
let layout = fx.layout_of(ty);
|
||||
|
||||
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
|
||||
let is_ssa = ssa_analyzed[local].is_ssa(fx, ty);
|
||||
|
||||
let place = make_local_place(fx, local, layout, is_ssa);
|
||||
assert_eq!(fx.local_map.push(place), local);
|
||||
|
@ -14,7 +14,8 @@ pub(super) fn codegen_return_param<'tcx>(
|
||||
) -> CPlace<'tcx> {
|
||||
let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode {
|
||||
PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(..) => {
|
||||
let is_ssa = ssa_analyzed[RETURN_PLACE] == crate::analyze::SsaKind::Ssa;
|
||||
let is_ssa =
|
||||
ssa_analyzed[RETURN_PLACE].is_ssa(fx, fx.fn_abi.as_ref().unwrap().ret.layout.ty);
|
||||
(
|
||||
super::make_local_place(
|
||||
fx,
|
||||
|
@ -4,34 +4,30 @@ use crate::prelude::*;
|
||||
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::mir::StatementKind::*;
|
||||
use rustc_middle::ty::Ty;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum SsaKind {
|
||||
NotSsa,
|
||||
Ssa,
|
||||
MaybeSsa,
|
||||
}
|
||||
|
||||
impl SsaKind {
|
||||
pub(crate) fn is_ssa<'tcx>(self, fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
self == SsaKind::MaybeSsa && (fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
|
||||
let mut flag_map = fx
|
||||
.mir
|
||||
.local_decls
|
||||
.iter()
|
||||
.map(|local_decl| {
|
||||
let ty = fx.monomorphize(local_decl.ty);
|
||||
if fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some() {
|
||||
SsaKind::Ssa
|
||||
} else {
|
||||
SsaKind::NotSsa
|
||||
}
|
||||
})
|
||||
.collect::<IndexVec<Local, SsaKind>>();
|
||||
let mut flag_map =
|
||||
fx.mir.local_decls.iter().map(|_| SsaKind::MaybeSsa).collect::<IndexVec<Local, SsaKind>>();
|
||||
|
||||
for bb in fx.mir.basic_blocks.iter() {
|
||||
for stmt in bb.statements.iter() {
|
||||
match &stmt.kind {
|
||||
Assign(place_and_rval) => match &place_and_rval.1 {
|
||||
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
|
||||
not_ssa(&mut flag_map, place.local)
|
||||
flag_map[place.local] = SsaKind::NotSsa;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
@ -42,7 +38,3 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
|
||||
|
||||
flag_map
|
||||
}
|
||||
|
||||
fn not_ssa(flag_map: &mut IndexVec<Local, SsaKind>, local: Local) {
|
||||
flag_map[local] = SsaKind::NotSsa;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user