-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify SwitchInt
handling
#133328
Simplify SwitchInt
handling
#133328
Conversation
Details in the individual commits. Let me know if I am sending you too many reviews, I can reassign if necessary. It's worth noting my motivation for this change. I wanted to try making |
☔ The latest upstream changes (presumably #133505) made this pull request unmergeable. Please resolve the merge conflicts. |
4cc04f3
to
6e4ad2c
Compare
I rebased. |
@cjgillot: two week review ping |
6e4ad2c
to
8e59df9
Compare
This shouldn't affect perf, but let's check that: @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…ing, r=<try> Simplify `SwitchInt` handling Dataflow handling of `SwitchInt` is currently complicated. This PR simplifies it. r? `@cjgillot`
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (79ce057): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 1.5%, secondary 2.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary 3.2%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 769.915s -> 767.459s (-0.32%) |
☔ The latest upstream changes (presumably #134269) made this pull request unmergeable. Please resolve the merge conflicts. |
I tried reordering this method to more closely match `MaybeUninitializedPlaces::apply_terminator_effect`, but doing so breaks tests.
Current `SwitchInt` handling has complicated control flow. - The dataflow engine calls `Analysis::apply_switch_int_edge_effects`, passing in an "applier" that impls `SwitchIntEdgeEffects`. - `apply_switch_int_edge_effects` possibly calls `apply` on the applier, passing it a closure. - The `apply` method calls the closure on each `SwitchInt` edge. - The closure operates on the edge. I.e. control flow goes from the engine, to the analysis, to the applier (which came from the engine), to the closure (which came from the analysis). It took me a while to work this out. This commit changes to a simpler structure that maintains the important characteristics. - The dataflow engine calls `Analysis::get_switch_int_data`. - `get_switch_int_data` returns an `Option<Self::SwitchIntData>` value. - If that returned value was `Some`, the dataflow engine calls `Analysis::apply_switch_int_edge_effect` on each edge, passing the `Self::SwitchIntData` value. - `Analysis::apply_switch_int_edge_effect` operates on the edge. I.e. control flow goes from the engine, to the analysis, to the engine, to the analysis. Added: - The `Analysis::SwitchIntData` assoc type and the `Analysis::get_switch_int_data` method. Both only need to be defined by analyses that look at `SwitchInt` terminators. - The `MaybePlacesSwitchIntData` struct, which has three fields. Changes: - `Analysis::apply_switch_int_edge_effects` becomes `Analysis::apply_switch_int_edge_effect`, which is a little simpler because it's dealing with a single edge instead of all edges. Removed: - The `SwitchIntEdgeEffects` trait, and its two impls: `BackwardSwitchIntEdgeEffectsApplier` (which has six fields) and `ForwardSwitchIntEdgeEffectsApplier` structs (which has four fields). - The closure. The new structure is more concise and simpler.
Switches to the idiom used elsewhere of calling `Analysis::bottom_value` to initialize a `state` value outside a loop, and then using `clone_from` to update it within the loop. This is simpler and has no impact on performance.
It is possible to avoid the clone as suggested in the comment. It would require introducing an enum with two variants `CloneBeforeModifying(&Domain)` and `Modifiable(&mut Domain)`. But it's not worth the effort, because this code path just isn't very hot. E.g. when compiling a large benchmark like `cargo-0.60.0` it's only hit a few thousand times.
9da7871
to
5f40942
Compare
Let's try a different reviewer: r? @tmiasko Best reviewed one commit at a time. See this comment for the specific motivation beyond "it makes thing simpler". |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (c434b4b): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 4.1%, secondary 3.5%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary -2.3%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 771.62s -> 770.535s (-0.14%) |
Dataflow handling of
SwitchInt
is currently complicated. This PR simplifies it.r? @cjgillot