diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-08-25 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2022-08-25 10:38:00 +0200 |
| commit | 58eabb291d4e4e307e00869f5a253c5061482141 (patch) | |
| tree | 1eae3771cf2557c10fad42d9abcc4494a6c0f059 /compiler/rustc_mir_dataflow/src | |
| parent | 4462b4af52e753e79de737857ff620fd267fb58f (diff) | |
| download | rust-58eabb291d4e4e307e00869f5a253c5061482141.tar.gz rust-58eabb291d4e4e307e00869f5a253c5061482141.zip | |
Add method that applies DefUse effect
Diffstat (limited to 'compiler/rustc_mir_dataflow/src')
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/impls/liveness.rs | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/compiler/rustc_mir_dataflow/src/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs index 8f81b71e3e2..483c1e274aa 100644 --- a/compiler/rustc_mir_dataflow/src/impls/liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs @@ -122,11 +122,7 @@ where } fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) { - match DefUse::for_place(local.into(), context) { - Some(DefUse::Def) => self.0.kill(local), - Some(DefUse::Use) => self.0.gen(local), - None => {} - } + DefUse::apply(self.0, local.into(), context); } } @@ -137,20 +133,12 @@ where T: GenKill<Local>, { fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) { - match DefUse::for_place(*place, context) { - Some(DefUse::Def) => self.0.kill(place.local), - Some(DefUse::Use) => self.0.gen(place.local), - None => {} - } + DefUse::apply(self.0, *place, context); self.visit_projection(place.as_ref(), context, location); } fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) { - match DefUse::for_place(local.into(), context) { - Some(DefUse::Def) => self.0.kill(local), - Some(DefUse::Use) => self.0.gen(local), - None => {} - } + DefUse::apply(self.0, local.into(), context); } } @@ -161,6 +149,14 @@ enum DefUse { } impl DefUse { + fn apply<'tcx>(trans: &mut impl GenKill<Local>, place: Place<'tcx>, context: PlaceContext) { + match DefUse::for_place(place, context) { + Some(DefUse::Def) => trans.kill(place.local), + Some(DefUse::Use) => trans.gen(place.local), + None => {} + } + } + fn for_place<'tcx>(place: Place<'tcx>, context: PlaceContext) -> Option<DefUse> { match context { PlaceContext::NonUse(_) => None, |
