Skip to content

Commit 191eb30

Browse files
committed
perf: there is no need to add entries for vars and temps
If we need them, they will be added in the visitor that goes through assigns
1 parent 20e1973 commit 191eb30

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

compiler/rustc_mir/src/dataflow/impls/available_locals.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ impl<'a, 'tcx> AvailableLocals {
6262

6363
/// Returns whether the given local is available at the given state
6464
pub fn is_available(&self, local: Local, state: &'a State) -> bool {
65-
self.local_with_location_map.local_with_locations(local).any(
66-
|place_taken_ref_local_with_location| {
65+
let locations_opt = self.local_with_location_map.local_with_locations(local);
66+
if let Some(mut locations) = locations_opt {
67+
locations.any(|place_taken_ref_local_with_location| {
6768
state.0.contains(place_taken_ref_local_with_location)
68-
},
69-
)
69+
})
70+
} else {
71+
false
72+
}
7073
}
7174

7275
fn transfer_function<T>(&'a self, available: &'a mut T) -> TransferFunction<'a, T>
@@ -160,7 +163,7 @@ impl LocalWithLocationMap {
160163
.or_insert(SmallVec::with_capacity(2))
161164
.push((0usize.into(), None));
162165

163-
for arg in body.args_iter().chain(body.vars_and_temps_iter()) {
166+
for arg in body.args_iter() {
164167
map.entry(arg).or_insert(SmallVec::with_capacity(2)).push((0usize.into(), None));
165168
}
166169

@@ -196,10 +199,10 @@ impl LocalWithLocationMap {
196199
fn local_with_locations(
197200
&self,
198201
local: Local,
199-
) -> impl Iterator<Item = LocalWithLocationIndex> + '_ {
202+
) -> Option<impl Iterator<Item = LocalWithLocationIndex> + '_> {
200203
debug!("Looking for {:?} in {:?}", local, self.0);
201-
let locations = self.0.get(&local).unwrap();
202-
return locations.iter().map(move |(location_idx, _)| *location_idx);
204+
let locations = self.0.get(&local)?;
205+
return Some(locations.iter().map(move |(location_idx, _)| *location_idx));
203206
}
204207

205208
fn len(&self) -> usize {
@@ -261,9 +264,13 @@ where
261264
T: GenKill<LocalWithLocationIndex>,
262265
{
263266
fn invalidate_local(&mut self, local_invalidated: Local, _location: Location) {
264-
for x in self.local_with_location_map.local_with_locations(local_invalidated) {
265-
debug!("Invalidating {:?} which corresponds to {:?}", x, local_invalidated);
266-
self.available.kill(x);
267+
if let Some(locations) =
268+
self.local_with_location_map.local_with_locations(local_invalidated)
269+
{
270+
for x in locations {
271+
debug!("Invalidating {:?} which corresponds to {:?}", x, local_invalidated);
272+
self.available.kill(x);
273+
}
267274
}
268275
}
269276

@@ -278,9 +285,15 @@ where
278285

279286
let all_participating_alive =
280287
rvalue.participating_locals(location).all(|participating_local| {
281-
self.local_with_location_map
282-
.local_with_locations(participating_local)
283-
.any(|participating_local_idx| self.available.is_alive(participating_local_idx))
288+
let location_opt =
289+
self.local_with_location_map.local_with_locations(participating_local);
290+
if let Some(mut locations) = location_opt {
291+
locations.any(|participating_local_idx| {
292+
self.available.is_alive(participating_local_idx)
293+
})
294+
} else {
295+
false
296+
}
284297
});
285298
if all_participating_alive {
286299
let index =

0 commit comments

Comments
 (0)