diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-02-10 00:47:48 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-02-23 10:18:49 +1100 |
| commit | 36b495f3cf23a1f235482ce7f81f0f4be614bb85 (patch) | |
| tree | bb651118e987cbe7467f088e84811ae93a676954 /compiler/rustc_mir_dataflow/src/impls | |
| parent | 523a1b1d388bfe82a5d0540b876d9428b6dccc9c (diff) | |
| download | rust-36b495f3cf23a1f235482ce7f81f0f4be614bb85.tar.gz rust-36b495f3cf23a1f235482ce7f81f0f4be614bb85.zip | |
Introduce `ChunkedBitSet` and use it for some dataflow analyses.
This reduces peak memory usage significantly for some programs with very large functions, such as: - `keccak`, `unicode_normalization`, and `match-stress-enum`, from the `rustc-perf` benchmark suite; - `http-0.2.6` from crates.io. The new type is used in the analyses where the bitsets can get huge (e.g. 10s of thousands of bits): `MaybeInitializedPlaces`, `MaybeUninitializedPlaces`, and `EverInitializedPlaces`. Some refactoring was required in `rustc_mir_dataflow`. All existing analysis domains are either `BitSet` or a trivial wrapper around `BitSet`, and access in a few places is done via `Borrow<BitSet>` or `BorrowMut<BitSet>`. Now that some of these domains are `ClusterBitSet`, that no longer works. So this commit replaces the `Borrow`/`BorrowMut` usage with a new trait `BitSetExt` containing the needed bitset operations. The impls just forward these to the underlying bitset type. This required fiddling with trait bounds in a few places. The commit also: - Moves `static_assert_size` from `rustc_data_structures` to `rustc_index` so it can be used in the latter; the former now re-exports it so existing users are unaffected. - Factors out some common "clear excess bits in the final word" functionality in `bit_set.rs`. - Uses `fill` in a few places instead of loops.
Diffstat (limited to 'compiler/rustc_mir_dataflow/src/impls')
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/impls/mod.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/compiler/rustc_mir_dataflow/src/impls/mod.rs b/compiler/rustc_mir_dataflow/src/impls/mod.rs index 63d935db8ca..9502c5d57d6 100644 --- a/compiler/rustc_mir_dataflow/src/impls/mod.rs +++ b/compiler/rustc_mir_dataflow/src/impls/mod.rs @@ -2,7 +2,7 @@ //! bitvectors attached to each basic block, represented via a //! zero-sized structure. -use rustc_index::bit_set::BitSet; +use rustc_index::bit_set::{BitSet, ChunkedBitSet}; use rustc_index::vec::Idx; use rustc_middle::mir::visit::{MirVisitable, Visitor}; use rustc_middle::mir::{self, Body, Location}; @@ -286,12 +286,12 @@ impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> { } impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { - type Domain = BitSet<MovePathIndex>; + type Domain = ChunkedBitSet<MovePathIndex>; const NAME: &'static str = "maybe_init"; fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain { // bottom = uninitialized - BitSet::new_empty(self.move_data().move_paths.len()) + ChunkedBitSet::new_empty(self.move_data().move_paths.len()) } fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) { @@ -417,13 +417,13 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { } impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { - type Domain = BitSet<MovePathIndex>; + type Domain = ChunkedBitSet<MovePathIndex>; const NAME: &'static str = "maybe_uninit"; fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain { // bottom = initialized (start_block_effect counters this at outset) - BitSet::new_empty(self.move_data().move_paths.len()) + ChunkedBitSet::new_empty(self.move_data().move_paths.len()) } // sets on_entry bits for Arg places @@ -606,13 +606,13 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> { } impl<'tcx> AnalysisDomain<'tcx> for EverInitializedPlaces<'_, 'tcx> { - type Domain = BitSet<InitIndex>; + type Domain = ChunkedBitSet<InitIndex>; const NAME: &'static str = "ever_init"; fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain { // bottom = no initialized variables by default - BitSet::new_empty(self.move_data().inits.len()) + ChunkedBitSet::new_empty(self.move_data().inits.len()) } fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain) { |
