Skip to content

Commit 5c21ce3

Browse files
committed
Move MaybeUninitializedLocals to the ssa module
1 parent e0def51 commit 5c21ce3

File tree

5 files changed

+78
-79
lines changed

5 files changed

+78
-79
lines changed

compiler/rustc_mir_dataflow/src/impls/initialized.rs

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -558,80 +558,6 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
558558
}
559559
}
560560

561-
/// A dataflow analysis that tracks locals that are maybe uninitialized.
562-
///
563-
/// This is a simpler analysis than `MaybeUninitializedPlaces`, because it does not track
564-
/// individual fields.
565-
pub struct MaybeUninitializedLocals;
566-
567-
impl MaybeUninitializedLocals {
568-
pub fn new() -> Self {
569-
Self {}
570-
}
571-
}
572-
573-
impl<'tcx> Analysis<'tcx> for MaybeUninitializedLocals {
574-
type Domain = DenseBitSet<mir::Local>;
575-
576-
const NAME: &'static str = "maybe_uninit_locals";
577-
578-
fn bottom_value(&self, body: &Body<'tcx>) -> Self::Domain {
579-
// bottom = all locals are initialized.
580-
DenseBitSet::new_empty(body.local_decls.len())
581-
}
582-
583-
fn initialize_start_block(&self, body: &Body<'tcx>, state: &mut Self::Domain) {
584-
// All locals start as uninitialized...
585-
state.insert_all();
586-
// ...except for arguments, which are definitely initialized.
587-
for arg in body.args_iter() {
588-
state.remove(arg);
589-
}
590-
}
591-
592-
fn apply_primary_statement_effect(
593-
&mut self,
594-
state: &mut Self::Domain,
595-
statement: &mir::Statement<'tcx>,
596-
_location: Location,
597-
) {
598-
match statement.kind {
599-
// An assignment makes a local initialized.
600-
mir::StatementKind::Assign(box (place, _)) => {
601-
if let Some(local) = place.as_local() {
602-
state.remove(local);
603-
}
604-
}
605-
// Deinit makes the local uninitialized.
606-
mir::StatementKind::Deinit(box place) => {
607-
// A deinit makes a local uninitialized.
608-
if let Some(local) = place.as_local() {
609-
state.insert(local);
610-
}
611-
}
612-
// Storage{Live,Dead} makes a local uninitialized.
613-
mir::StatementKind::StorageLive(local) | mir::StatementKind::StorageDead(local) => {
614-
state.insert(local);
615-
}
616-
_ => {}
617-
}
618-
}
619-
620-
fn apply_call_return_effect(
621-
&mut self,
622-
state: &mut Self::Domain,
623-
_block: mir::BasicBlock,
624-
return_places: CallReturnPlaces<'_, 'tcx>,
625-
) {
626-
// The return place of a call is initialized.
627-
return_places.for_each(|place| {
628-
if let Some(local) = place.as_local() {
629-
state.remove(local);
630-
}
631-
});
632-
}
633-
}
634-
635561
/// There can be many more `InitIndex` than there are locals in a MIR body.
636562
/// We use a mixed bitset to avoid paying too high a memory footprint.
637563
pub type EverInitializedPlacesDomain = MixedBitSet<InitIndex>;

compiler/rustc_mir_dataflow/src/impls/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod storage_liveness;
66
pub use self::borrowed_locals::{MaybeBorrowedLocals, borrowed_locals};
77
pub use self::initialized::{
88
EverInitializedPlaces, EverInitializedPlacesDomain, MaybeInitializedPlaces,
9-
MaybeUninitializedLocals, MaybeUninitializedPlaces, MaybeUninitializedPlacesDomain,
9+
MaybeUninitializedPlaces, MaybeUninitializedPlacesDomain,
1010
};
1111
pub use self::liveness::{
1212
MaybeLiveLocals, MaybeTransitiveLiveLocals, TransferFunction as LivenessTransferFunction,

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ use rustc_index::bit_set::DenseBitSet;
33
use rustc_middle::mir::visit::*;
44
use rustc_middle::mir::*;
55
use rustc_middle::ty::TyCtxt;
6-
use rustc_mir_dataflow::impls::MaybeUninitializedLocals;
76
use rustc_mir_dataflow::{Analysis, ResultsCursor};
87
use tracing::{debug, instrument};
98

10-
use crate::ssa::SsaLocals;
9+
use crate::ssa::{MaybeUninitializedLocals, SsaLocals};
1110

1211
/// Unify locals that copy each other.
1312
///

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,13 @@ use rustc_middle::mir::visit::*;
104104
use rustc_middle::mir::*;
105105
use rustc_middle::ty::layout::HasTypingEnv;
106106
use rustc_middle::ty::{self, Ty, TyCtxt};
107-
use rustc_mir_dataflow::impls::MaybeUninitializedLocals;
108107
use rustc_mir_dataflow::{Analysis, ResultsCursor};
109108
use rustc_span::DUMMY_SP;
110109
use rustc_span::def_id::DefId;
111110
use smallvec::SmallVec;
112111
use tracing::{debug, instrument, trace};
113112

114-
use crate::ssa::SsaLocals;
113+
use crate::ssa::{MaybeUninitializedLocals, SsaLocals};
115114

116115
pub(super) struct GVN;
117116

compiler/rustc_mir_transform/src/ssa.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_middle::middle::resolve_bound_vars::Set1;
1414
use rustc_middle::mir::visit::*;
1515
use rustc_middle::mir::*;
1616
use rustc_middle::ty::{self, TyCtxt};
17+
use rustc_mir_dataflow::Analysis;
1718
use tracing::{debug, instrument, trace};
1819

1920
pub(super) struct SsaLocals {
@@ -405,3 +406,77 @@ impl StorageLiveLocals {
405406
matches!(self.storage_live[local], Set1::One(_))
406407
}
407408
}
409+
410+
/// A dataflow analysis that tracks locals that are maybe uninitialized.
411+
///
412+
/// This is a simpler analysis than `MaybeUninitializedPlaces`, because it does not track
413+
/// individual fields.
414+
pub(crate) struct MaybeUninitializedLocals;
415+
416+
impl MaybeUninitializedLocals {
417+
pub(crate) fn new() -> Self {
418+
Self {}
419+
}
420+
}
421+
422+
impl<'tcx> Analysis<'tcx> for MaybeUninitializedLocals {
423+
type Domain = DenseBitSet<Local>;
424+
425+
const NAME: &'static str = "maybe_uninit_locals";
426+
427+
fn bottom_value(&self, body: &Body<'tcx>) -> Self::Domain {
428+
// bottom = all locals are initialized.
429+
DenseBitSet::new_empty(body.local_decls.len())
430+
}
431+
432+
fn initialize_start_block(&self, body: &Body<'tcx>, state: &mut Self::Domain) {
433+
// All locals start as uninitialized...
434+
state.insert_all();
435+
// ...except for arguments, which are definitely initialized.
436+
for arg in body.args_iter() {
437+
state.remove(arg);
438+
}
439+
}
440+
441+
fn apply_primary_statement_effect(
442+
&mut self,
443+
state: &mut Self::Domain,
444+
statement: &Statement<'tcx>,
445+
_location: Location,
446+
) {
447+
match statement.kind {
448+
// An assignment makes a local initialized.
449+
StatementKind::Assign(box (place, _)) => {
450+
if let Some(local) = place.as_local() {
451+
state.remove(local);
452+
}
453+
}
454+
// Deinit makes the local uninitialized.
455+
StatementKind::Deinit(box place) => {
456+
// A deinit makes a local uninitialized.
457+
if let Some(local) = place.as_local() {
458+
state.insert(local);
459+
}
460+
}
461+
// Storage{Live,Dead} makes a local uninitialized.
462+
StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => {
463+
state.insert(local);
464+
}
465+
_ => {}
466+
}
467+
}
468+
469+
fn apply_call_return_effect(
470+
&mut self,
471+
state: &mut Self::Domain,
472+
_block: BasicBlock,
473+
return_places: CallReturnPlaces<'_, 'tcx>,
474+
) {
475+
// The return place of a call is initialized.
476+
return_places.for_each(|place| {
477+
if let Some(local) = place.as_local() {
478+
state.remove(local);
479+
}
480+
});
481+
}
482+
}

0 commit comments

Comments
 (0)