Commit Graph

72 Commits

Author SHA1 Message Date
bors 97d328012b Auto merge of #111673 - cjgillot:dominator-preprocess, r=cjgillot,tmiasko
Preprocess and cache dominator tree

Preprocessing dominators has a very strong effect for https://github.com/rust-lang/rust/pull/111344.
That pass checks that assignments dominate their uses repeatedly. Using the unprocessed dominator tree caused a quadratic runtime (number of bbs x depth of the dominator tree).

This PR also caches the dominator tree and the pre-processed dominators in the MIR cfg cache.

Rebase of https://github.com/rust-lang/rust/pull/107157
cc `@tmiasko`
2023-05-24 16:18:21 +00:00
Camille GILLOT 7c8f29f02c Revert spurious changes. 2023-05-18 14:36:13 +00:00
Camille GILLOT fa8598cb50 Merge DominatorTree and Dominators. 2023-05-17 10:37:29 +00:00
Camille GILLOT 4bbdb64016 Typo. 2023-05-17 10:29:12 +00:00
Camille GILLOT ae318e3444 Remove outdated comment. 2023-05-17 10:26:04 +00:00
Tomasz Miąsko aa1267f630 Preprocess dominator tree to answer queries in O(1) 2023-05-17 09:36:12 +00:00
Camille GILLOT 84339a6f05 Process current bucket instead of parent's bucket when starting loop for dominators. 2023-05-15 16:16:34 +00:00
Tomasz Miąsko f16d2b1629 Start node has no immediate dominator
Change the immediate_dominator return type to Option, and use None to
indicate that node has no immediate dominator.

Also fix the issue where the start node would be returned as its own
immediate dominator.
2023-05-14 16:09:58 +02:00
Maybe Waffle e496fbec92 Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
Nilstrieb 81c320ea77 Fix some clippy::complexity 2023-04-09 23:22:14 +02:00
Scott McMurray a2ee7592d6 Use &IndexSlice instead of &IndexVec where possible
All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
2023-04-02 17:35:37 -07:00
John Kåre Alsaker f60d2eb6c1 Add -Z time-passes-format to allow specifying a JSON output for -Z time-passes 2023-03-21 18:18:25 +01:00
b-naber 8252a6eddf address review 2023-02-21 21:54:53 +00:00
b-naber e2bf960fe1 sccs info 2023-02-19 22:12:12 +00:00
Bryan Garza 1bbd655888 Improve efficiency of has_back_edge(...) 2023-01-24 00:01:37 +00:00
Bryan Garza f9982ea24a Add comment on cause of panic in dominators algorithm 2023-01-23 23:56:22 +00:00
Yuki Okushi eae7f947b5 Rollup merge of #107153 - tmiasko:dominates, r=oli-obk
Consistently use dominates instead of is_dominated_by

There is a number of APIs that answer dominance queries. Previously they were named either "dominates" or "is_dominated_by". Consistently use the "dominates" form.

No functional changes.
2023-01-23 19:30:02 +09:00
Tomasz Miąsko 955e7fbb16 Consistently use dominates instead of is_dominated_by
There is a number of APIs that answer dominance queries. Previously they
were named either "dominates" or "is_dominated_by". Consistently use the
"dominates" form.

No functional changes.
2023-01-21 12:15:02 +01:00
bors 21f6839352 Auto merge of #106976 - tmiasko:borrowck-lazy-dominators, r=cjgillot
Lazy dominator tree construction in borrowck

Motivated by the observation that sometimes constructed dominator tree was never queried.
2023-01-21 11:02:29 +00:00
bors 56ee85274e Auto merge of #106090 - WaffleLapkin:dereffffffffff, r=Nilstrieb
Remove some `ref` patterns from the compiler

Previous PR: https://github.com/rust-lang/rust/pull/105368

r? `@Nilstrieb`
2023-01-20 04:52:28 +00:00
Guillaume Gomez dee88e0fa2 Rollup merge of #107037 - tmiasko:rank, r=oli-obk
Fix Dominators::rank_partial_cmp to match documentation

The only use site is also updated accordingly and there is no change in end-to-end behaviour.
2023-01-19 11:19:36 +01:00
Tomasz Miąsko b8c5821ad8 Fix Dominators::rank_partial_cmp to match documentation
The only use site is also updated accordingly and there is no change in
end-to-end behaviour.
2023-01-18 17:11:43 +01:00
Scott McMurray 925dc37313 Stop using BREAK & CONTINUE in compiler
Switching them to `Break(())` and `Continue(())` instead.

libs-api would like to remove these constants, so stop using them in compiler to make the removal PR later smaller.
2023-01-17 23:17:51 -08:00
Tomasz Miąsko 7fe68571fa Lazy dominator tree construction in borrowck
Motivated by the observation that sometimes constructed dominator tree
was never queried.
2023-01-17 22:00:41 +01:00
Matthias Krüger 68f12338af Rollup merge of #104505 - WaffleLapkin:no-double-spaces-in-comments, r=jackh726
Remove double spaces after dots in comments

Most of the comments do not have double spaces, so I assume these are typos.
2023-01-17 20:21:25 +01:00
Maybe Waffle 6a28fb42a8 Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
Maybe Waffle fc6cda8603 rustc_data_structures: remove ref patterns and other artifacts of the past 2023-01-17 07:48:19 +00:00
Jakob Degen f49126e3d6 Document wf constraints on control flow in cleanup blocks
Also fixes a bug in dominator computation
2023-01-16 14:51:33 -08:00
nils fd7a159710 Fix uninlined_format_args for some compiler crates
Convert all the crates that have had their diagnostic migration
completed (except save_analysis because that will be deleted soon and
apfloat because of the licensing problem).
2023-01-05 19:01:12 +01:00
Nilstrieb 8bfd6450c7 A few small cleanups for newtype_index
Remove the `..` from the body, only a few invocations used it and it's
inconsistent with rust syntax.

Use `;` instead of `,` between consts. As the Rust syntax gods inteded.
2022-12-18 21:47:28 +01:00
KaDiWa 9bc69925cb compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
Rageking8 7122abaddf more dupe word typos 2022-10-14 12:57:56 +08:00
Nilstrieb fc8b13cb96 Adapt rustc_data_structures tests to run in strict miri
Some tests took too long and owning_ref is fundamentally flawed,
so don't run these tests or run them with a shorter N. This makes
miri with `-Zmiri-strict-provenance` usable to find UB.
2022-06-04 17:46:29 +02:00
Mark Rousskov 4d89292785 Avoid exhausting stack space in dominator compression 2022-02-23 16:07:56 -05:00
pierwill e6ff0bac1e rustc VecGraph: require the index type to implement Ord 2021-12-22 10:50:57 -06:00
pierwill 8df9248591 Remove PartialOrd and Ord from LocalDefId
Implement `Ord`, `PartialOrd` for SpanData
2021-12-22 10:50:57 -06:00
Mark Rousskov 15483ccf9d Annotate comments onto the LT algorithm 2021-12-06 20:30:15 -05:00
Mark Rousskov 3187480070 Avoid using Option where values are always Some 2021-12-06 15:05:22 -05:00
Mark Rousskov 2b63059772 Create newtype around the pre order index 2021-12-06 15:05:22 -05:00
Mark Rousskov cc63ec32fb Use variables rather than lengths directly 2021-12-06 15:05:22 -05:00
Mark Rousskov 345ada0e1b Optimize: reuse the real-to-preorder mapping as the visited set 2021-12-06 15:05:22 -05:00
Mark Rousskov 8991002644 Remove separate RPO traversal
This integrates the preorder and postorder traversals into one.
2021-12-06 15:05:22 -05:00
Mark Rousskov 7d12767dc5 Use preorder indices for data structures
This largely avoids remapping from and to the 'real' indices, with the exception
of predecessor lookup and the final merge back, and is conceptually better.
2021-12-06 15:05:22 -05:00
Mark Rousskov 92186cb5c9 Avoid inserting into buckets if not necessary 2021-12-06 15:05:22 -05:00
Mark Rousskov 7379d24ebc Optimization: process buckets only once 2021-12-06 15:05:22 -05:00
Mark Rousskov c82fe0efb4 Optimization: Merge parent and ancestor arrays
As the paper indicates, the unprocessed vertices in the DFS tree and processed
vertices are disjoint, and we can use them in the same space, tracking only the index
of the split.
2021-12-06 15:05:22 -05:00
Mark Rousskov e8d7248093 Implement the simple Lengauer-Tarjan algorithm
This replaces the previous implementation with the simple variant of
Lengauer-Tarjan, which performs better in the general case. Performance on the
keccak benchmark is about equivalent between the two, but we don't see
regressions (and indeed see improvements) on other benchmarks, even on a
partially optimized implementation.

The implementation here follows that of the pseudocode in "Linear-Time
Algorithms for Dominators and Related Problems" thesis by Loukas Georgiadis. The
next few commits will optimize the implementation as suggested in the thesis.
Several related works are cited in the comments within the implementation, as
well.

Implement the simple Lengauer-Tarjan algorithm

This replaces the previous implementation (from #34169), which has not been
optimized since, with the simple variant of Lengauer-Tarjan which performs
better in the general case. A previous attempt -- not kept in commit history --
attempted a replacement with a bitset-based implementation, but this led to
regressions on perf.rust-lang.org benchmarks and equivalent wins for the keccak
benchmark, so was rejected.

The implementation here follows that of the pseudocode in "Linear-Time
Algorithms for Dominators and Related Problems" thesis by Loukas Georgiadis. The
next few commits will optimize the implementation as suggested in the thesis.
Several related works are cited in the comments within the implementation, as
well.

On the keccak benchmark, we were previously spending 15% of our cycles computing
the NCA / intersect function; this function is quite expensive, especially on
modern CPUs, as it chases pointers on every iteration in a tight loop. With this
commit, we spend ~0.05% of our time in dominator computation.
2021-12-06 15:03:09 -05:00
Scott McMurray 308fd59f42 Stop enabling in_band_lifetimes in rustc_data_structures
There's a conversation in the tracking issue about possibly unaccepting `in_band_lifetimes`, but it's used heavily in the compiler, and thus there'd need to be a bunch of PRs like this if that were to happen.

So here's one to see how much of an impact it has.

(Oh, and I removed `nll` while I was here too, since it didn't seem needed.  Let me know if I should put that back.)
2021-12-05 20:17:35 -08:00
Matthias Krüger 4457014398 Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov"
The PR had some unforseen perf regressions that are not as easy to find.
Revert the PR for now.

This reverts commit 6ae8912a3e, reversing
changes made to 86d6d2b738.
2021-10-15 11:28:23 +02:00
Clemens Wasser 71dd0b928b Apply clippy suggestions 2021-10-10 15:38:19 +02:00