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

Add LLVM attributes in batches instead of individually #94221

Merged
merged 4 commits into from
Feb 27, 2022

Conversation

erikdesjardins
Copy link
Contributor

@erikdesjardins erikdesjardins commented Feb 21, 2022

This should improve performance.

r? @ghost (blocked on #94127)

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Feb 21, 2022
@erikdesjardins
Copy link
Contributor Author

erikdesjardins commented Feb 26, 2022

@rustbot ready
@rustbot label: -S-blocked

r? @nikic

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 26, 2022
@rustbot rustbot removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Feb 26, 2022
@rust-log-analyzer

This comment has been minimized.

@nikic
Copy link
Contributor

nikic commented Feb 26, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 26, 2022
@bors
Copy link
Contributor

bors commented Feb 26, 2022

⌛ Trying commit 30d3ce0 with merge 39292fbc75cdc462390b8b3c63d59cb5a6b00539...

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

Looks great. As the CI failure indicates, AttributeMask is new in LLVM 14, previously AttrBuilder was used.

fn get_attrs<'ll>(
this: &ArgAttributes,
cx: &CodegenCx<'ll, '_>,
) -> SmallVec<impl smallvec::Array<Item = &'ll Attribute>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

First time I'm seeing this SmallVec pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This avoids exposing the size in the signature. But it looks like we aren't concerned about that elsewhere, and it is compiler-internal anyways, so removed this

}
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &{ func_attrs });
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need braces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessary, but causes the SmallVec to be moved, which makes func_attrs.push() after this point an error.

@bors
Copy link
Contributor

bors commented Feb 26, 2022

☀️ Try build successful - checks-actions
Build commit: 39292fbc75cdc462390b8b3c63d59cb5a6b00539 (39292fbc75cdc462390b8b3c63d59cb5a6b00539)

@rust-timer
Copy link
Collaborator

Queued 39292fbc75cdc462390b8b3c63d59cb5a6b00539 with parent 6f681a8, future comparison URL.

@rust-log-analyzer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (39292fbc75cdc462390b8b3c63d59cb5a6b00539): comparison url.

Summary: This benchmark run did not return any relevant results. 7 results were found to be statistically significant but too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking 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 led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 26, 2022
@nikic
Copy link
Contributor

nikic commented Feb 27, 2022

Doesn't seem to do much for performance, but I think this still makes sense in terms of general design, by separating attribute creation and addition. For example, this allows reusing the same code when applying function and callsite attributes.

@bors r+

@bors
Copy link
Contributor

bors commented Feb 27, 2022

📌 Commit 0d0cc4f has been approved by nikic

@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 Feb 27, 2022
@bors
Copy link
Contributor

bors commented Feb 27, 2022

⌛ Testing commit 0d0cc4f with merge 2bd9656...

@bors
Copy link
Contributor

bors commented Feb 27, 2022

☀️ Test successful - checks-actions
Approved by: nikic
Pushing 2bd9656 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 27, 2022
@bors bors merged commit 2bd9656 into rust-lang:master Feb 27, 2022
@rustbot rustbot added this to the 1.61.0 milestone Feb 27, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2bd9656): comparison url.

Summary: This benchmark run did not return any relevant results. 19 results were found to be statistically significant but too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@erikdesjardins erikdesjardins deleted the addattr branch February 27, 2022 16:59
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 2, 2022
Remove LLVM attribute removal

This was necessary before, because `declare_raw_fn` would always apply
the default optimization attributes to every declared function.
Then `attributes::from_fn_attrs` would have to remove the default
attributes in the case of, e.g. `#[optimize(speed)]` in a `-Os` build.
(see [`src/test/codegen/optimize-attr-1.rs`](https://github.com/rust-lang/rust/blob/03a8cc7df1d65554a4d40825b0490c93ac0f0236/src/test/codegen/optimize-attr-1.rs#L33))

However, every relevant callsite of `declare_raw_fn` (i.e. where we
actually generate code for the function, and not e.g. a call to an
intrinsic, where optimization attributes don't [?] matter)
calls `from_fn_attrs`, so we can remove the attribute setting
from `declare_raw_fn`, and rely on `from_fn_attrs` to apply the correct
attributes all at once.

r? `@ghost` (blocked on rust-lang#94221)
`@rustbot` label S-blocked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

6 participants