1
Fork 0

Rollup merge of #133475 - nnethercote:MaybeStorage-improvements, r=lcnr

`MaybeStorage` improvements

Minor dataflow improvements.

r? `@tmiasko`
This commit is contained in:
Michael Goulet 2024-11-26 20:35:40 -05:00 committed by GitHub
commit 219b2a010d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 29 additions and 38 deletions

View file

@ -18,8 +18,7 @@ use rustc_middle::span_bug;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
use rustc_mir_dataflow::Analysis;
use rustc_mir_dataflow::impls::MaybeStorageLive;
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::impls::{MaybeStorageLive, always_storage_live_locals};
use rustc_span::{Span, Symbol, sym};
use rustc_trait_selection::traits::{
Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt,

View file

@ -10,7 +10,7 @@ use rustc_index::IndexVec;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::{bug, mir};
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::impls::always_storage_live_locals;
use rustc_span::Span;
use tracing::{info_span, instrument, trace};

View file

@ -14,4 +14,6 @@ pub use self::initialized::{
pub use self::liveness::{
MaybeLiveLocals, MaybeTransitiveLiveLocals, TransferFunction as LivenessTransferFunction,
};
pub use self::storage_liveness::{MaybeRequiresStorage, MaybeStorageDead, MaybeStorageLive};
pub use self::storage_liveness::{
MaybeRequiresStorage, MaybeStorageDead, MaybeStorageLive, always_storage_live_locals,
};

View file

@ -7,6 +7,23 @@ use rustc_middle::mir::*;
use super::MaybeBorrowedLocals;
use crate::{Analysis, GenKill, ResultsCursor};
/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
///
/// These locals have fixed storage for the duration of the body.
pub fn always_storage_live_locals(body: &Body<'_>) -> BitSet<Local> {
let mut always_live_locals = BitSet::new_filled(body.local_decls.len());
for block in &*body.basic_blocks {
for statement in &block.statements {
if let StatementKind::StorageLive(l) | StatementKind::StorageDead(l) = statement.kind {
always_live_locals.remove(l);
}
}
}
always_live_locals
}
pub struct MaybeStorageLive<'a> {
always_live_locals: Cow<'a, BitSet<Local>>,
}
@ -28,10 +45,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageLive<'a> {
}
fn initialize_start_block(&self, body: &Body<'tcx>, on_entry: &mut Self::Domain) {
assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size());
for local in self.always_live_locals.iter() {
on_entry.insert(local);
}
on_entry.union(&*self.always_live_locals);
for arg in body.args_iter() {
on_entry.insert(arg);

View file

@ -25,7 +25,7 @@ pub use self::framework::{
use self::move_paths::MoveData;
pub mod debuginfo;
pub mod drop_flag_effects;
mod drop_flag_effects;
pub mod elaborate_drops;
mod errors;
mod framework;
@ -33,8 +33,7 @@ pub mod impls;
pub mod move_paths;
pub mod points;
pub mod rustc_peek;
pub mod storage;
pub mod un_derefer;
mod un_derefer;
pub mod value_analysis;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

View file

@ -1,20 +0,0 @@
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::{self, Local};
/// The set of locals in a MIR body that do not have `StorageLive`/`StorageDead` annotations.
///
/// These locals have fixed storage for the duration of the body.
pub fn always_storage_live_locals(body: &mir::Body<'_>) -> BitSet<Local> {
let mut always_live_locals = BitSet::new_filled(body.local_decls.len());
for block in &*body.basic_blocks {
for statement in &block.statements {
use mir::StatementKind::{StorageDead, StorageLive};
if let StorageLive(l) | StorageDead(l) = statement.kind {
always_live_locals.remove(l);
}
}
}
always_live_locals
}

View file

@ -70,8 +70,8 @@ use rustc_middle::ty::{
use rustc_middle::{bug, span_bug};
use rustc_mir_dataflow::impls::{
MaybeBorrowedLocals, MaybeLiveLocals, MaybeRequiresStorage, MaybeStorageLive,
always_storage_live_locals,
};
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor};
use rustc_span::Span;
use rustc_span::def_id::{DefId, LocalDefId};
@ -696,8 +696,7 @@ fn locals_live_across_suspend_points<'tcx>(
let loc = Location { block, statement_index: data.statements.len() };
liveness.seek_to_block_end(block);
let mut live_locals: BitSet<_> = BitSet::new_empty(body.local_decls.len());
live_locals.union(liveness.get());
let mut live_locals = liveness.get().clone();
if !movable {
// The `liveness` variable contains the liveness of MIR locals ignoring borrows.

View file

@ -9,8 +9,7 @@ use rustc_index::bit_set::BitSet;
use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_mir_dataflow::impls::{MaybeStorageDead, MaybeStorageLive};
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::impls::{MaybeStorageDead, MaybeStorageLive, always_storage_live_locals};
use rustc_mir_dataflow::{Analysis, ResultsCursor};
pub(super) fn lint_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, when: String) {

View file

@ -8,8 +8,7 @@ use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_mir_dataflow::Analysis;
use rustc_mir_dataflow::impls::MaybeStorageDead;
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::impls::{MaybeStorageDead, always_storage_live_locals};
use tracing::{debug, instrument};
use crate::ssa::{SsaLocals, StorageLiveLocals};