mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
e6376631cc
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
//! SSA analysis
|
|
|
|
use rustc_index::IndexVec;
|
|
use rustc_middle::mir::StatementKind::*;
|
|
|
|
use crate::prelude::*;
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
|
pub(crate) enum SsaKind {
|
|
NotSsa,
|
|
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(|_| 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) => {
|
|
flag_map[place.local] = SsaKind::NotSsa;
|
|
}
|
|
_ => {}
|
|
},
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
|
|
flag_map
|
|
}
|