Skip to content

Use runCodeGen Abstraction for new LLVM - #163672

Open
boomanaiden154 wants to merge 1 commit into
rust-lang:mainfrom
boomanaiden154:rustc-newpm-new-abstraction
Open

boomanaiden154 wants to merge 1 commit into
rust-lang:mainfrom
boomanaiden154:rustc-newpm-new-abstraction

Conversation

@boomanaiden154

@boomanaiden154 boomanaiden154 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

This is the abstraction that clang/flang both use. It simplifies the code by quite a bit (although not until we delete the old version). Mainly this enables the use of the NewPM for LLVM targets that opt-in (currently only Lanai and MSP430, but more soon).

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2026
@boomanaiden154
boomanaiden154 marked this pull request as ready for review October 2, 2026 18:19
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 2, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 2, 2026
@rustbot

rustbot commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

r? @cuviper

rustbot has assigned @cuviper.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @cuviper

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@boomanaiden154
boomanaiden154 force-pushed the rustc-newpm-new-abstraction branch from 92b27b6 to 86c9fc2 Compare October 4, 2026 19:14
@rustbot

This comment has been minimized.

@boomanaiden154

Copy link
Copy Markdown
Contributor Author

r? @nikic

@rustbot rustbot assigned nikic and unassigned cuviper Oct 22, 2026
// TargetMachine::addPassesToEmitFile stores pointers to the output streams
// in a couple of places inside of the object. Explicitly delete the PM after
// we call run() to avoid dangling references.
std::unique_ptr<llvm::ToolOutputFile> DOS;

@nikic nikic Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::unique_ptr<llvm::ToolOutputFile> DOS;
std::unique_ptr<llvm::ToolOutputFile> DwoOS;

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also not sure I understand the unique_ptr here. Can this be just std::optional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed.

It could be std::optional, but right now runCodeGenPipeline takes a reference to a std::unique_ptr, so we would need to repackage it at some point. That's mostly cargo-culting from clang. I can adjust it on the LLVM side first if you think that would be cleaner.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking at how it's used, I think it would probably make the most sense to accept a raw_pwrite_stream *?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, given that's what the underlying functions expect too.

llvm/llvm-project#235339 to update the LLVM side. I've kept the unique_ptr for the normal/buffered stream. For DwoOS I think we could use either, but using a unique_ptr for BDwoOS makes things a bit nicer given the LLVM APIs take raw pointers so we don't need to use a ternary to return nullptr if has_value() is false.

Comment thread compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp Outdated

@nikic nikic left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Can you please squash?

View changes since this review

if (DisableSimplifyLibCalls)
TLII.disableAllFunctions();
PM->add(new TargetLibraryInfoWrapperPass(TLII));
#if LLVM_VERSION_GE(22, 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should no longer be needed, LLVM 22 is the minimum version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@boomanaiden154
boomanaiden154 force-pushed the rustc-newpm-new-abstraction branch from 8208452 to 49810b3 Compare October 26, 2026 20:43
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred in src/tools/opt-dist

cc @Kobzol

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

rustc_error_messages was changed

cc @TaKO8Ki

Some changes occurred in src/tools/compiletest

cc @jieyouxu

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

This PR modifies bootstrap.example.toml.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

rustc_macros::diagnostics was changed

cc @TaKO8Ki, @JonathanBrouwer

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-clippy Relevant to the Clippy team. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Oct 26, 2026
@boomanaiden154
boomanaiden154 force-pushed the rustc-newpm-new-abstraction branch from 49810b3 to ceaa153 Compare October 26, 2026 20:44
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in engine.rs, potentially modifying the public API of ObligationCtxt.

cc @lcnr

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

changes to the core type system

cc @lcnr

rustfmt is developed in its own repository. If possible, consider making this change to rust-lang/rustfmt instead.

cc @rust-lang/rustfmt

rustc_errors::emitter was changed

cc @Muscraft

The rustc-dev-guide subtree was changed. If your future PRs only touch the subtree, consider submitting them directly to rust-lang/rustc-dev-guide, which is where the document is primarily maintained (and has faster CI).

cc @BoxyUwU, @tshepang

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in float parsing

cc @tgross35

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in compiler/rustc_attr_ir

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in src/etc/lldb_lookup.py

cc @Walnut356

Some changes occurred in src/etc/lldb_providers.py

cc @Walnut356

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CI Area: Our Github Actions CI A-rustc-dev-guide Area: rustc-dev-guide T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Oct 26, 2026
@boomanaiden154
boomanaiden154 force-pushed the rustc-newpm-new-abstraction branch from ceaa153 to c6865b7 Compare October 26, 2026 20:45
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@boomanaiden154

Copy link
Copy Markdown
Contributor Author

And of course I somehow end up rebasing a merge...

Sorry for all the pings.

This should be squashed now.

@ytmimi ytmimi removed the T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. label Oct 26, 2026
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/ToolOutputFile.h"

@nikic nikic Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This header should no longer be needed in the latest version, I think.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, removed.

This is the abstraction that clang/flang both use. It simplifies the
code by quite a bit (although not until we delete the old version).
Mainly this enables the use of the NewPM for LLVM targets that opt-in
(currently only Lanai and MSP430, but more soon).
@boomanaiden154
boomanaiden154 force-pushed the rustc-newpm-new-abstraction branch from c6865b7 to b5c68b6 Compare October 26, 2026 21:24
@nikic

nikic commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b5c68b6 has been approved by nikic

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Oct 27, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 27, 2026
…traction, r=nikic

Use runCodeGen Abstraction for new LLVM

This is the abstraction that clang/flang both use. It simplifies the code by quite a bit (although not until we delete the old version). Mainly this enables the use of the NewPM for LLVM targets that opt-in (currently only Lanai and MSP430, but more soon).
rust-bors Bot pushed a commit that referenced this pull request Oct 27, 2026
…uwer

Rollup of 22 pull requests

Successful merges:

 - #159580 (Reject cfg on expressions that cannot be safely removed)
 - #162597 (raise ambiguity error on attribute macro that could be tool attribute)
 - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs)
 - #163059 (Recover invalid return type until `{`, `}` or `;`)
 - #163672 (Use runCodeGen Abstraction for new LLVM)
 - #164028 (Add a future incompat warning for #[no_link])
 - #164188 (Suggest adding lifetime for `dyn Trait` in return type)
 - #164345 (fix: handle `false` in root contexts)
 - #164494 (drop ands which are a superset of other ands)
 - #164766 (Unstably introduce MVP edition migration lint `unmarked_unchecked_type_aliases` together with bikeshed attribute `#[rustc_unchecked_type_alias]`)
 - #164785 (delegation: emit error when there is no field for `Self` mapping)
 - #164799 (Don't use `IntoIterator` in parallel API)
 - #164871 (Refactor call argument codegen)
 - #164648 (parse inline and rustc_force_inline with same parser)
 - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration)
 - #164900 (make tool_attrs method to retrieve tool attributes.)
 - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit)
 - #164996 (miri: add missing alignment check in write_bytes)
 - #165012 (Remove Span::eq_ctxt())
 - #165013 ([tiny] Add missing backticks around lifetime name)
 - #165024 (rustdoc-search: rank re-export lower)
 - #165028 (Update enzyme to fix one bug related to higher-order derivatives)

> [!WARNING]
> This rollup conflicts with pending auto build #165042 and may need to be recreated if the pending build succeeds.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 27, 2026
…traction, r=nikic

Use runCodeGen Abstraction for new LLVM

This is the abstraction that clang/flang both use. It simplifies the code by quite a bit (although not until we delete the old version). Mainly this enables the use of the NewPM for LLVM targets that opt-in (currently only Lanai and MSP430, but more soon).
rust-bors Bot pushed a commit that referenced this pull request Oct 27, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #159580 (Reject cfg on expressions that cannot be safely removed)
 - #162597 (raise ambiguity error on attribute macro that could be tool attribute)
 - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs)
 - #163059 (Recover invalid return type until `{`, `}` or `;`)
 - #163672 (Use runCodeGen Abstraction for new LLVM)
 - #164028 (Add a future incompat warning for #[no_link])
 - #164188 (Suggest adding lifetime for `dyn Trait` in return type)
 - #164345 (fix: handle `false` in root contexts)
 - #164494 (drop ands which are a superset of other ands)
 - #164785 (delegation: emit error when there is no field for `Self` mapping)
 - #164799 (Don't use `IntoIterator` in parallel API)
 - #164871 (Refactor call argument codegen)
 - #164648 (parse inline and rustc_force_inline with same parser)
 - #164811 (fix: Prevent ICE when comparing EII impl against generic declaration)
 - #164900 (make tool_attrs method to retrieve tool attributes.)
 - #164993 (copy_nonoverlapping: dont skip ovelrap check when src is fully uninit)
 - #164996 (miri: add missing alignment check in write_bytes)
 - #165012 (Remove Span::eq_ctxt())
 - #165013 ([tiny] Add missing backticks around lifetime name)
 - #165024 (rustdoc-search: rank re-export lower)
 - #165028 (Update enzyme to fix one bug related to higher-order derivatives)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CI Area: Our Github Actions CI A-compiletest Area: The compiletest test runner A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-run-make Area: port run-make Makefiles to rmake.rs A-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants