Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7870b29

Browse files
committed
Remove a couple of duplicate layout_of and monomorphize calls
1 parent bdb0665 commit 7870b29

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

src/abi/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
275275
self::comments::add_locals_header_comment(fx);
276276

277277
for (local, arg_kind, ty) in func_params {
278-
let layout = fx.layout_of(ty);
279-
280-
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
281-
282278
// While this is normally an optimization to prevent an unnecessary copy when an argument is
283279
// not mutated by the current function, this is necessary to support unsized arguments.
284280
if let ArgKind::Normal(Some(val)) = arg_kind {
@@ -300,6 +296,8 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
300296
}
301297
}
302298

299+
let layout = fx.layout_of(ty);
300+
let is_ssa = ssa_analyzed[local].is_ssa(fx, ty);
303301
let place = make_local_place(fx, local, layout, is_ssa);
304302
assert_eq!(fx.local_map.push(place), local);
305303

@@ -323,7 +321,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
323321
let ty = fx.monomorphize(fx.mir.local_decls[local].ty);
324322
let layout = fx.layout_of(ty);
325323

326-
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
324+
let is_ssa = ssa_analyzed[local].is_ssa(fx, ty);
327325

328326
let place = make_local_place(fx, local, layout, is_ssa);
329327
assert_eq!(fx.local_map.push(place), local);

src/abi/returning.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ pub(super) fn codegen_return_param<'tcx>(
1414
) -> CPlace<'tcx> {
1515
let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode {
1616
PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(..) => {
17-
let is_ssa = ssa_analyzed[RETURN_PLACE] == crate::analyze::SsaKind::Ssa;
17+
let is_ssa =
18+
ssa_analyzed[RETURN_PLACE].is_ssa(fx, fx.fn_abi.as_ref().unwrap().ret.layout.ty);
1819
(
1920
super::make_local_place(
2021
fx,

src/analyze.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,30 @@ use crate::prelude::*;
44

55
use rustc_index::vec::IndexVec;
66
use rustc_middle::mir::StatementKind::*;
7+
use rustc_middle::ty::Ty;
78

89
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
910
pub(crate) enum SsaKind {
1011
NotSsa,
11-
Ssa,
12+
MaybeSsa,
13+
}
14+
15+
impl SsaKind {
16+
pub(crate) fn is_ssa<'tcx>(self, fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
17+
self == SsaKind::MaybeSsa && (fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some())
18+
}
1219
}
1320

1421
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
15-
let mut flag_map = fx
16-
.mir
17-
.local_decls
18-
.iter()
19-
.map(|local_decl| {
20-
let ty = fx.monomorphize(local_decl.ty);
21-
if fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some() {
22-
SsaKind::Ssa
23-
} else {
24-
SsaKind::NotSsa
25-
}
26-
})
27-
.collect::<IndexVec<Local, SsaKind>>();
22+
let mut flag_map =
23+
fx.mir.local_decls.iter().map(|_| SsaKind::MaybeSsa).collect::<IndexVec<Local, SsaKind>>();
2824

2925
for bb in fx.mir.basic_blocks.iter() {
3026
for stmt in bb.statements.iter() {
3127
match &stmt.kind {
3228
Assign(place_and_rval) => match &place_and_rval.1 {
3329
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
34-
not_ssa(&mut flag_map, place.local)
30+
flag_map[place.local] = SsaKind::NotSsa;
3531
}
3632
_ => {}
3733
},
@@ -42,7 +38,3 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
4238

4339
flag_map
4440
}
45-
46-
fn not_ssa(flag_map: &mut IndexVec<Local, SsaKind>, local: Local) {
47-
flag_map[local] = SsaKind::NotSsa;
48-
}

0 commit comments

Comments
 (0)