Skip to content
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

Collect statistics about MIR optimizations #76769

Closed
wants to merge 1 commit into from

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Sep 15, 2020

For example -Zmir-opt-level=3 -Zmir-opt-stats:

 141639 const_prop                   Number of const propagations
     54 const_prop                   Number of validation errors during const propagation
 530284 dest_prop                    Number of destination propagations
    389 dest_prop                    Number of functions with too many blocks to optimize
    184 dest_prop                    Number of functions with too many locals to optimize
 237034 inline                       Number of functions inlined
   1542 instcombine                  Number of array length operations simplified
  16396 instcombine                  Number of derer-refs operations simplified
  15932 instcombine                  Number of equality comparisons with a const bool simplified
 364113 instcombine                  Number of ref-derefs operations simplified
  16452 match_branches               Number of similar basic blocks merged together
  51978 multiple_return_terminators  Number of goto terminators replaced with a return
    860 nrvo                         Number of functions eligible for named return value optimization
   2137 remove_noop_landing_pads     Number of no-op jumps folded
 482515 remove_noop_landing_pads     Number of no-op landing pads removed
  10732 remove_unneeded_drops        Number of unnecessary drop terminators removed
      9 simplify                     Maximum number of iterations of control-flow-graph simplifier
      4 simplify                     Maximum number of iterations of locals simplifier
 792860 simplify                     Number of basic blocks merged with their only predecessor
2066039 simplify                     Number of dead basic blocks removed
  39601 simplify                     Number of switch int terminators with identical successors replaced with a goto
 961242 simplify                     Number of unused locals removed
 156604 simplify_branches            Number of false edges simplified to a goto
   5397 simplify_branches            Number of false unwinds simplified to a goto
   2111 simplify_branches            Number of true assertions simplified to a goto
   3864 simplify_comparison_integral Number of switches on a result of integer comparison simplified to switches on integers
     60 simplify_try                 Number of switches with equivalent targets replaced with a goto to the first target
  26785 unreachable_prop             Number of blocks with some of targets removed

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2020
@jyn514 jyn514 added A-mir-opt Area: MIR optimizations T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 16, 2020
use std::io::{self, Write as _};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

static COLLECTOR: Collector = Collector::new();
Copy link
Member

@bjorn3 bjorn3 Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of Session or TyCtxt. There may be multiple rustc sessions running in a single process. (for example when using RLS)

Copy link
Contributor Author

@tmiasko tmiasko Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented with different implementation approaches:

  1. Statistics definitions are in the context together with their values.
  2. Statistics definitions are in MIR passes, their values are stored in the context.
  3. Statistics definitions and values are stored together with MIR passes.

I strongly prefer variants that put statistics definitions together with MIR passes that uses them. In that approach, adding and removing counters is trivial, additionally any unused counters are detected as such during compilation.

Values can be stored in the context if we want to support multiple rustc sessions in a single process, although it requires passing context to all those places where counters are used. But is there any real use-case? Why would you use rustc with debug-assertions and MIR optimizations counters inside the RLS?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @bjorn3. We've tried pretty hard to move these sorts of things into Session and TyCtxt to allow running multiple sessions in the same process (both for RLS and eventually for one rustc process compiling multiple crates simultaneously).

Since this is essentially unstable, diagnostic data and doesn't effect the compilation artifacts, it may be worth bending that rule because, as you point out, having the counters defined in their MIR passes is quite nice. I don't personally feel comfortable approving that since this is a cross-cutting concern for the compiler as a whole and there may be others on the compiler team that have strong opinions about breaking that rule.

@petrochenkov
Copy link
Contributor

r? @wesleywiser

@tmiasko tmiasko force-pushed the mir-opt-stats branch 2 times, most recently from b0a81f4 to 9996642 Compare September 21, 2020 05:13
@bors
Copy link
Contributor

bors commented Sep 23, 2020

☔ The latest upstream changes (presumably #76659) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@tmiasko tmiasko force-pushed the mir-opt-stats branch 2 times, most recently from 63abbc7 to 511d534 Compare September 24, 2020 15:20
@bors
Copy link
Contributor

bors commented Oct 4, 2020

☔ The latest upstream changes (presumably #77430) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@tmiasko
Copy link
Contributor Author

tmiasko commented Oct 8, 2020

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@tmiasko tmiasko force-pushed the mir-opt-stats branch 2 times, most recently from b5d9534 to a2293bf Compare October 11, 2020 23:10
@bors
Copy link
Contributor

bors commented Oct 13, 2020

☔ The latest upstream changes (presumably #77796) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@bors
Copy link
Contributor

bors commented Oct 17, 2020

☔ The latest upstream changes (presumably #77373) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@tmiasko tmiasko closed this Nov 4, 2020
@tmiasko tmiasko deleted the mir-opt-stats branch November 4, 2020 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants