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

Resurrect: rustc_llvm: Add a -Z print-codegen-stats option to expose LLVM statistics. #113723

Merged
merged 4 commits into from
Jul 21, 2023

Conversation

khei4
Copy link
Contributor

@khei4 khei4 commented Jul 15, 2023

This resurrects PR #104000, which has sat idle for a while. And I want to see the effect of stack-move optimizations on LLVM (like https://reviews.llvm.org/D153453) :).

I have applied the changes requested by @oli-obk and @nagisa #104000 (comment) and #104000 (comment) in the latest commits.

r? @oli-obk


LLVM has a neat statistics feature that tracks how often optimizations kick in. It's very handy for optimization work. Since we expose the LLVM pass timings, I thought it made sense to expose the LLVM statistics too.


(Edit: fix broken link
(Edit2: fix segmentation fault and use malloc

If rustc is built with

[llvm]
assertions = true

Then you can see like

rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
         3 aa                           - Number of MayAlias results
       193 aa                           - Number of MustAlias results
       531 aa                           - Number of NoAlias results
...

And the current default build emits only

$ rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
$ 

This might be better to emit the message to tell assertion flag necessity, but now I can't find how to do that...

@rustbot
Copy link
Collaborator

rustbot commented Jul 15, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added 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. labels Jul 15, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jul 15, 2023

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo

@rust-log-analyzer

This comment has been minimized.

@khei4 khei4 changed the title Resurrect: rustc_llvm: Add a -Z print-llvm-stats option to expose LLVM statistics. [WIP] Resurrect: rustc_llvm: Add a -Z print-codegen-stats option to expose LLVM statistics. Jul 16, 2023
@khei4 khei4 marked this pull request as draft July 16, 2023 06:30
@khei4 khei4 force-pushed the khei4/llvm-stats branch from b5dee46 to d1c0de0 Compare July 16, 2023 12:07
@rust-log-analyzer

This comment has been minimized.

@khei4 khei4 force-pushed the khei4/llvm-stats branch from d1c0de0 to e0d8c74 Compare July 16, 2023 12:23
@khei4 khei4 changed the title [WIP] Resurrect: rustc_llvm: Add a -Z print-codegen-stats option to expose LLVM statistics. Resurrect: rustc_llvm: Add a -Z print-codegen-stats option to expose LLVM statistics. Jul 16, 2023
@rust-log-analyzer

This comment has been minimized.

@khei4 khei4 force-pushed the khei4/llvm-stats branch from e0d8c74 to ef451d8 Compare July 16, 2023 12:30
@rust-log-analyzer

This comment has been minimized.

@khei4 khei4 force-pushed the khei4/llvm-stats branch from ef451d8 to a462bab Compare July 16, 2023 12:43
@rust-log-analyzer

This comment has been minimized.

pcwalton added 2 commits July 16, 2023 22:56
…ics.

LLVM has a neat [statistics] feature that tracks how often optimizations kick
in. It's very handy for optimization work. Since we expose the LLVM pass
timings, I thought it made sense to expose the LLVM statistics too.

[statistics]: https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option
@khei4 khei4 force-pushed the khei4/llvm-stats branch from a462bab to c0d58fd Compare July 16, 2023 13:56
@rust-log-analyzer

This comment has been minimized.

@khei4 khei4 force-pushed the khei4/llvm-stats branch from c0d58fd to 4d307c4 Compare July 16, 2023 15:38
@khei4 khei4 marked this pull request as ready for review July 16, 2023 15:43
@@ -1868,7 +1868,10 @@ extern "C" {
pub fn LLVMRustGetLastError() -> *const c_char;

/// Print the pass timings since static dtors aren't picking them up.
pub fn LLVMRustPrintPassTimings();
pub fn LLVMRustPrintPassTimings(size: *const usize) -> *const c_char;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing else in this file uses usize, please use size_t to make sure we don't rely on funny Rust<->C differences

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks! I should have seen around.

compiler/rustc_codegen_llvm/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_codegen_llvm/src/lib.rs Outdated Show resolved Hide resolved
@oli-obk oli-obk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 19, 2023
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 20, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Jul 20, 2023

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 20, 2023
…rust/pull/113723/files

use slice memcpy rather than strcpy and write it on stdout

use println on failure

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
@khei4 khei4 force-pushed the khei4/llvm-stats branch from 13f664b to c7bf20d Compare July 20, 2023 07:54
@khei4
Copy link
Contributor Author

khei4 commented Jul 20, 2023

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 20, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Jul 20, 2023

@bors r=oli-obk,nikic

@bors
Copy link
Contributor

bors commented Jul 20, 2023

📌 Commit c7bf20d has been approved by oli-obk,nikic

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 20, 2023
@bors
Copy link
Contributor

bors commented Jul 20, 2023

⌛ Testing commit c7bf20d with merge cd454abe290b5438354e833ebfeca69b11ecfbf2...

@bors
Copy link
Contributor

bors commented Jul 20, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 20, 2023
@rust-log-analyzer
Copy link
Collaborator

The job dist-i586-gnu-i586-i686-musl failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@lqd
Copy link
Member

lqd commented Jul 20, 2023

@bors retry rust-lang/crates.io#6850

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 20, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 21, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#113380 (style-guide: clean up "must"/"should"/"may")
 - rust-lang#113723 (Resurrect: rustc_llvm: Add a -Z `print-codegen-stats` option to expose LLVM statistics.)
 - rust-lang#113780 (Support `--print KIND=PATH` command line syntax)
 - rust-lang#113810 (Make {Rc,Arc}::allocator associated functions)
 - rust-lang#113907 (Minor improvements to Windows TLS dtors)

Failed merges:

 - rust-lang#113392 (style-guide: Some cleanups from the fmt-rfcs repo history)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2734b5a into rust-lang:master Jul 21, 2023
@rustbot rustbot added this to the 1.73.0 milestone Jul 21, 2023
antoyo pushed a commit to antoyo/rust that referenced this pull request Oct 9, 2023
…nikic

Resurrect: rustc_llvm: Add a -Z `print-codegen-stats` option to expose LLVM statistics.

This resurrects PR rust-lang#104000, which has sat idle for a while. And I want to see the effect of stack-move optimizations on LLVM (like https://reviews.llvm.org/D153453) :).

I have applied the changes requested by `@oli-obk` and `@nagisa`  rust-lang#104000 (comment) and rust-lang#104000 (comment) in the latest commits.

r? `@oli-obk`

-----

LLVM has a neat [statistics](https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option) feature that tracks how often optimizations kick in. It's very handy for optimization work. Since we expose the LLVM pass timings, I thought it made sense to expose the LLVM statistics too.

-----
(Edit: fix broken link
(Edit2: fix segmentation fault and use malloc

If `rustc` is built with
```toml
[llvm]
assertions = true
```
Then you can see like
```
rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
         3 aa                           - Number of MayAlias results
       193 aa                           - Number of MustAlias results
       531 aa                           - Number of NoAlias results
...
```

And the current default build emits only
```
$ rustc +stage1 -Z print-codegen-stats -C opt-level=3  tmp.rs
===-------------------------------------------------------------------------===
                          ... Statistics Collected ...
===-------------------------------------------------------------------------===
$
```
This might be better to emit the message to tell assertion flag necessity, but now I can't find how to do that...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants