remove unnecessary and ineffective caching
This commit is contained in:
parent
b6d5b728b3
commit
1205e82578
1 changed files with 9 additions and 22 deletions
|
@ -1,7 +1,6 @@
|
||||||
//! Removes assignments to ZST places.
|
//! Removes assignments to ZST places.
|
||||||
|
|
||||||
use crate::transform::MirPass;
|
use crate::transform::MirPass;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
|
||||||
use rustc_middle::mir::{Body, StatementKind};
|
use rustc_middle::mir::{Body, StatementKind};
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
|
||||||
|
@ -10,35 +9,23 @@ pub struct RemoveZsts;
|
||||||
impl<'tcx> MirPass<'tcx> for RemoveZsts {
|
impl<'tcx> MirPass<'tcx> for RemoveZsts {
|
||||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
let param_env = tcx.param_env(body.source.def_id());
|
let param_env = tcx.param_env(body.source.def_id());
|
||||||
|
|
||||||
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
|
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
|
||||||
|
|
||||||
let mut is_zst_cache = FxHashMap::default();
|
|
||||||
|
|
||||||
for block in basic_blocks.iter_mut() {
|
for block in basic_blocks.iter_mut() {
|
||||||
for statement in block.statements.iter_mut() {
|
for statement in block.statements.iter_mut() {
|
||||||
match statement.kind {
|
match statement.kind {
|
||||||
StatementKind::Assign(box (place, _)) => {
|
StatementKind::Assign(box (place, _)) => {
|
||||||
let place_ty = place.ty(local_decls, tcx).ty;
|
let place_ty = place.ty(local_decls, tcx).ty;
|
||||||
|
if let Ok(layout) = tcx.layout_of(param_env.and(place_ty)) {
|
||||||
let is_inhabited_zst = *is_zst_cache.entry(place_ty).or_insert_with(|| {
|
if layout.is_zst() && !layout.abi.is_uninhabited() {
|
||||||
if let Ok(layout) = tcx.layout_of(param_env.and(place_ty)) {
|
if tcx.consider_optimizing(|| {
|
||||||
if layout.is_zst() && !layout.abi.is_uninhabited() {
|
format!(
|
||||||
return true;
|
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
|
||||||
|
place, statement.source_info
|
||||||
|
)
|
||||||
|
}) {
|
||||||
|
statement.make_nop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
|
||||||
});
|
|
||||||
|
|
||||||
if is_inhabited_zst {
|
|
||||||
if tcx.consider_optimizing(|| {
|
|
||||||
format!(
|
|
||||||
"RemoveZsts - Place: {:?} SourceInfo: {:?}",
|
|
||||||
place, statement.source_info
|
|
||||||
)
|
|
||||||
}) {
|
|
||||||
statement.make_nop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue