about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2023-10-18Only check in a single place if a pass is enabled.Camille GILLOT-13/+22
2023-10-18coverage: Store expression data in function coverage infoZalathar-72/+19
Even though expression details are now stored in the info structure, we still need to inject `ExpressionUsed` statements into MIR, because if one is missing during codegen then we know that it was optimized out and we can remap all of its associated code regions to zero.
2023-10-18Remove unused `TyCtxt` from `remove_dead_blocks`Zalathar-9/+9
This context was only needed by code for processing coverage statements, which has been removed.
2023-10-18coverage: Store all of a function's mappings in function coverage infoZalathar-142/+17
Previously, mappings were attached to individual coverage statements in MIR. That necessitated special handling in MIR optimizations to avoid deleting those statements, since otherwise codegen would be unable to reassemble the original list of mappings. With this change, a function's list of mappings is now attached to its MIR body, and survives intact even if individual statements are deleted by optimizations.
2023-10-18coverage: Rename `Operand` to `CovTerm`Zalathar-20/+20
Later patches in this PR will use `CovTerm` to represent things that are not expression operands.
2023-10-18coverage: Store the number of counters/expressions in function coverage infoZalathar-74/+25
Coverage codegen can now allocate arrays based on the number of counters/expressions originally used by the instrumentor. The existing query that inspects coverage statements is still used for determining the number of counters passed to `llvm.instrprof.increment`. If some high-numbered counters were removed by MIR optimizations, the instrumented binary can potentially use less memory and disk space at runtime.
2023-10-18coverage: Attach an optional `FunctionCoverageInfo` to `mir::Body`Zalathar-3/+5
This allows coverage information to be attached to the function as a whole when appropriate, instead of being smuggled through coverage statements in the function's basic blocks. As an example, this patch moves the `function_source_hash` value out of individual `CoverageKind::Counter` statements and into the per-function info. When synthesizing unused functions for coverage purposes, the absence of this info is taken to indicate that a function was not eligible for coverage and should not be synthesized.
2023-10-17Automatically enable cross-crate inlining for small functionsBen Kimock-5/+130
2023-10-17[RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopesUrgau-1/+4
2023-10-16debug Span::ctxt() call detectionArthur Lafrance-1/+1
2023-10-16coverage: Explain why we temporarily steal `pending_dups`Zalathar-6/+20
2023-10-16coverage: Inline `span_bcb_dominates`Zalathar-14/+11
Interacting with `basic_coverage_blocks` directly makes it easier to satisfy the borrow checker when mutating `pending_dups` while reading other fields.
2023-10-16coverage: Inline `prev_starts_after_next`Zalathar-10/+5
2023-10-16coverage: Move `take_curr` and note what its callers are doingZalathar-9/+9
2023-10-16coverage: Call `prev`/`curr` less in other placesZalathar-11/+17
This reduces clutter, and makes it easier to notice regions where mutations definitely don't occur.
2023-10-16coverage: Call `prev`/`curr` less in `to_refined_spans`Zalathar-22/+20
This makes it easier to see that the non-initial cases assume that `prev` and `curr` are set, and all operate on the same prev/curr references.
2023-10-16coverage: Remove redundant field `prev_expn_span`Zalathar-7/+2
This span can always be retrieved from `prev`, so there is no need to store it separately.
2023-10-16coverage: Flatten guard logic in `maybe_flush_pending_dups`Zalathar-15/+16
2023-10-16coverage: Flatten guard logic in `maybe_push_macro_name_span`Zalathar-20/+17
2023-10-16coverage: Simplify `push_refined_span`Zalathar-12/+8
It turns out that all of the `len` manipulation here was just reimplementing `last_mut`.
2023-10-16coverage: Use `DUMMY_SP` instead of creating a dummy span manuallyZalathar-4/+4
This patch also sorts the constructor fields into declaration order.
2023-10-16coverage: Rename `hold_pending_dups_unless_dominated` to `update_pending_dups`Zalathar-2/+2
2023-10-16coverage: Rename `check_pending_dups` to `maybe_flush_pending_dups`Zalathar-2/+2
This method's main responsibility is to flush the pending dups into refined spans, if appropriate.
2023-10-16coverage: Rename `check_invoked_macro_name_span` to `maybe_push_macro_name_span`Zalathar-5/+7
2023-10-15Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstriebbors-78/+139
Format all the let-chains in compiler crates Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped). This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else. I will also add this commit to the ignore list after it has landed. The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree. ``` ~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates ~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif ``` cc `@rust-lang/rustfmt` r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :> cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-14Auto merge of #115524 - RalfJung:misalign, r=wesleywiserbors-32/+6
const-eval: make misalignment a hard error It's been a future-incompat error (showing up in cargo's reports) since https://github.com/rust-lang/rust/pull/104616, Rust 1.68, released in March. That should be long enough. The question for the lang team is simply -- should we move ahead with this, making const-eval alignment failures a hard error? (It turns out some of them accidentally already were hard errors since #104616. But not all so this is still a breaking change. Crater found no regression.)
2023-10-13Format all the let chains in compilerMichael Goulet-78/+139
2023-10-12coverage: Simplify adding BCB successors to the traversal worklistsZalathar-38/+39
2023-10-12coverage: Don't store loop backedges in the traversal contextZalathar-7/+10
As long as we store the loop header BCB, we can look up its incoming loop backedges as needed.
2023-10-12coverage: Store a graph reference in the graph traversal structZalathar-17/+16
Having to keep passing in a graph reference was a holdover from when the graph was partly mutated during traversal. As of #114354 that is no longer necessary, so we can simplify the traversal code by storing a graph reference as a field in `TraverseCoverageGraphWithLoops`.
2023-10-12coverage: Use a `VecDeque` for loop traversal worklistsZalathar-31/+18
The previous code was storing the worklist in a vector, and then selectively adding items to the start or end of the vector. That's a perfect use-case for a double-ended queue. This change also reveals that the existing code was a bit confused about which end of the worklist is the front or back. For now, items are always removed from the front of the queue (instead of the back), and code that adds items to the queue has been flipped, to preserve the existing behaviour.
2023-10-12coverage: Rename `next_bcb` to just `bcb`Zalathar-9/+10
This is the only BCB that `TraverseCoverageGraphWithLoops::next` works with, so calling it `next_bcb` just makes the code less clear.
2023-10-12coverage: Simplify the detection of reloop edges to be given expressionsZalathar-82/+57
2023-10-11Rollup merge of #116315 - cjgillot:cpl-clean, r=petrochenkovMatthias Krüger-50/+11
Do not check for impossible predicates in const-prop lint. The enclosing query already checks for them, and replaces the body with a single `unreachable` if they are indeed impossible.
2023-10-10Auto merge of #113915 - cjgillot:ssa-call, r=tmiaskobors-43/+71
Also consider call and yield as MIR SSA. The SSA analysis on MIR only considered `Assign` statements as defining a SSA local. This PR adds assignments as part of a `Call` or `Yield` terminator in that category. This mainly allows to perform CopyProp on a call return place. The only subtlety is in the dominance property: the assignment is only complete at the beginning of the target block.
2023-10-10Rollup merge of #116595 - RalfJung:mir-enable-passes, r=oli-obkMatthias Krüger-1/+5
-Zmir-enable-passes: document that this may enable unsound passes also add some comments explaining why MIR opts are marked as unsound
2023-10-10Rollup merge of #116589 - Zalathar:successors, r=oli-obkMatthias Krüger-80/+38
coverage: Unbox and simplify `bcb_filtered_successors` This is a small cleanup in the coverage instrumentor's graph-building code. --- This function already has access to the MIR body, so instead of taking a reference to a terminator, it's simpler and easier to pass in a basic block index. There is no need to box the returned iterator if we instead add appropriate lifetime captures, and make `short_circuit_preorder` generic over the type of iterator it expects. We can also greatly simplify the function's implementation by observing that the only difference between its two cases is whether we take all of a BB's successors, or just the first one. --- `@rustbot` label +A-code-coverage
2023-10-10add some comments explaining why MIR opts are marked as unsoundRalf Jung-1/+5
2023-10-10coverage: Unbox and simplify `bcb_filtered_successors`Zalathar-28/+24
This function already has access to the MIR body, so instead of taking a reference to a terminator, it's simpler and easier to pass in a basic block index. There is no need to box the returned iterator if we instead add appropriate lifetime captures, since `short_circuit_preorder` is now generic over the type of iterator it expects. We can also greatly simplify the function's implementation by observing that the only difference between its two cases is whether we take all of a BB's successors, or just the first one.
2023-10-10coverage: Replace `ShortCircuitPreorder` with a single functionZalathar-55/+17
Instead of defining a named struct, we can use `std::iter::from_fn` and store intermediate state in a closure.
2023-10-10coverage: Remove enum `CoverageStatement`Zalathar-46/+17
This enum was mainly needed to track the precise origin of a span in MIR, for debug printing purposes. Since the old debug code was removed in #115962, we can replace it with just the span itself.
2023-10-10coverage: Disconnect span extraction from `CoverageSpansGenerator`Zalathar-87/+85
By performal initial span extraction in a separate free function, we can remove some accidental complexity from the main generator code.
2023-10-10coverage: Move initial MIR span extraction into a submoduleZalathar-185/+194
2023-10-09Rollup merge of #116549 - DaniPopes:miropts-let-chains, r=oli-obkMatthias Krüger-86/+43
Simplify some mir passes by using let chains
2023-10-09Auto merge of #116533 - cjgillot:skip-trivial-mir, r=oli-obkbors-0/+9
Do not run optimizations on trivial MIR. Fixes https://github.com/rust-lang/rust/issues/116513 The bug was introduced in https://github.com/rust-lang/rust/pull/110728, which put the check too early in the query chain. cc `@oli-obk` `@ouz-a`
2023-10-09Simplify some mir passes by using let chainsDaniPopes-86/+43
2023-10-08Also consider call and yield as MIR SSA.Camille GILLOT-43/+71
2023-10-08Auto merge of #116454 - tmiasko:small-dominators, r=cjgillotbors-64/+30
Generalize small dominators optimization * Use small dominators optimization from 640ede7b0a1840415cb6ec881c2210302bfeba18 more generally. * Merge `DefLocation` and `LocationExtended` since they serve the same purpose.
2023-10-08Do not run optimizations on trivial MIR.Camille GILLOT-0/+9
2023-10-06Preserve DebugInfo in DeadStoreElimination.Camille GILLOT-7/+15