Commit Graph

1361 Commits

Author SHA1 Message Date
bors 10143e781b Auto merge of #117166 - oli-obk:mir_const_qualif_perf, r=petrochenkov
Only call `mir_const_qualif` if absolutely necessary

Pull the perf change out of https://github.com/rust-lang/rust/pull/113617

This should not have any impact on behaviour (if it does, we'll see an ICE)
2023-10-27 16:06:02 +00:00
Matthias Krüger a1ab16792b Rollup merge of #117141 - tmiasko:inline-target-features, r=oli-obk
Require target features to match exactly during inlining

In general it is not correct to inline a callee with a target features
that are subset of the callee. Require target features to match exactly
during inlining.

The exact match could be potentially relaxed, but this would require
identifying specific feature that are allowed to differ, those that need
to match, and those that can be present in caller but not in callee.

This resolves MIR part of #116573. For other concerns with respect to
the previous implementation also see areInlineCompatible in LLVM.
2023-10-25 19:51:14 +02:00
Oli Scherer 57d6a6f588 Only call mir_const_qualif if absolutely necessary 2023-10-25 14:32:14 +00:00
bors df871fbf05 Auto merge of #115796 - cjgillot:const-prop-rvalue, r=oli-obk
Generate aggregate constants in DataflowConstProp.
2023-10-24 21:47:53 +00:00
Tomasz Miąsko 011b260cc8 Require target features to match exactly during inlining
In general it is not correct to inline a callee with a target features
that are subset of the callee. Require target features to match exactly
during inlining.

The exact match could be potentially relaxed, but this would require
identifying specific feature that are allowed to differ, those that need
to match, and those that can be present in caller but not in callee.

This resolves MIR part of #116573. For other concerns with respect to
the previous implementation also see areInlineCompatible in LLVM.
2023-10-24 22:49:15 +02:00
bors cd674d6179 Auto merge of #116300 - cjgillot:split-move, r=petrochenkov
Separate move path tracking between borrowck and drop elaboration.

The primary goal of this PR is to skip creating a `MovePathIndex` for path that do not need dropping in drop elaboration.

The 2 first commits are cleanups.

The next 2 commits displace `move` errors from move-path builder to borrowck. Move-path builder keeps the same logic, but does not carry error information any more.

The remaining commits allow to filter `MovePathIndex` creation according to types. This is used in drop elaboration, to avoid computing dataflow for paths that do not need dropping.
2023-10-24 00:25:32 +00:00
bors 1322f92634 Auto merge of #107009 - cjgillot:jump-threading, r=pnkfelix
Implement jump threading MIR opt

This pass is an attempt to generalize `ConstGoto` and `SeparateConstSwitch` passes into a more complete jump threading pass.

This pass is rather heavy, as it performs a truncated backwards DFS on MIR starting from each `SwitchInt` terminator. This backwards DFS remains very limited, as it only walks through `Goto` terminators.

It is build to support constants and discriminants, and a propagating through a very limited set of operations.

The pass successfully manages to disentangle the `Some(x?)` use case and the DFA use case. It still needs a few tests before being ready.
2023-10-23 18:05:44 +00:00
Camille GILLOT 8c1b039d48 Use a ConstValue instead. 2023-10-21 16:26:05 +00:00
Camille GILLOT 31d101093c Generate ValTrees in DataflowConstProp. 2023-10-21 16:20:46 +00:00
Camille GILLOT c8f33ec35f Typo. 2023-10-21 12:14:17 +00:00
Camille GILLOT 547af00019 Remove on_all_drop_children_bits.
As drop elaboration only tracks places that need dropping, is has become
equivalent to `on_all_children_bits`.
2023-10-21 10:33:37 +00:00
Camille GILLOT c9c0c0cbca Do not create move paths that do not need dropping. 2023-10-21 10:32:59 +00:00
Camille GILLOT f038882fc0 Give collect_drop_flags and elaborate_drops closer structure. 2023-10-21 10:32:21 +00:00
Camille GILLOT 252c64722f Parametrize gather_moves by filter. 2023-10-21 10:31:39 +00:00
Camille GILLOT 8d535070a2 Do not report errors from move path builder. 2023-10-21 10:29:40 +00:00
Matthias Krüger e9df0b6b40 Rollup merge of #116974 - Zalathar:signature-spans, r=oli-obk,cjgillot
coverage: Fix inconsistent handling of function signature spans

While doing some more cleanup of `spans`, I noticed a strange inconsistency in how function signatures are handled. Normally the function signature span is treated as though it were executable as part of the start of the function, but in some cases the signature span disappears entirely from coverage, for no obvious reason.

This is caused by the fact that spans created by `CoverageSpan::for_fn_sig` don't add the span to their `merged_spans` field (unlike normal statement/terminator spans). In cases where the span-processing code looks at those merged spans, it thinks the signature span is no longer visible and deletes it.

Adding the signature span to `merged_spans` resolves the inconsistency.

(Prior to #116409 this wouldn't have been possible, because there was no case in the old `CoverageStatement` enum representing a signature. Now that `merged_spans` is just a list of spans, that's no longer an obstacle.)
2023-10-21 10:08:17 +02:00
Camille GILLOT dd08dd42e5 Expand comment on disappearing edge. 2023-10-21 07:08:53 +00:00
Camille GILLOT 8fb99afb02 Correct loop_headers logic. 2023-10-21 07:08:53 +00:00
Camille GILLOT 54b61d6e1a Reword TO application comments. 2023-10-21 07:08:53 +00:00
Camille GILLOT 66ec098ea7 Simplify static if handling. 2023-10-21 07:08:53 +00:00
Camille GILLOT d5b21ef96b Explicit notation. 2023-10-21 07:08:53 +00:00
Camille GILLOT 98b86fa9e5 Document Condition. 2023-10-21 07:03:23 +00:00
Camille GILLOT 47056248e5 Make polarity an enum. 2023-10-21 07:02:45 +00:00
Camille GILLOT b5aa1ef9b4 Document mutated_statement. 2023-10-21 07:02:06 +00:00
Camille GILLOT 4abea83663 Improve naming and comments. 2023-10-21 07:01:25 +00:00
Camille GILLOT df9e5ee038 Handle more terminators. 2023-10-21 07:01:24 +00:00
Camille GILLOT 0d0a536777 Do not thread through loop headers. 2023-10-21 06:59:37 +00:00
Camille GILLOT 751a079413 Implement JumpThreading pass. 2023-10-21 06:58:38 +00:00
Camille GILLOT 3cb0c2e385 Make instance an option in CostChecker. 2023-10-21 06:58:00 +00:00
Camille GILLOT 8252ad02c4 Extract cost checker from inliner. 2023-10-21 06:57:49 +00:00
Zalathar ff02d9200c coverage: Simplify the injection of coverage statements 2023-10-21 12:33:33 +11:00
Zalathar 319693a927 coverage: Simplify initial creation of coverage spans 2023-10-21 11:56:15 +11:00
Zalathar e16494469e coverage: Don't create an intermediate vec for each BCB's initial spans 2023-10-21 11:53:27 +11:00
Zalathar a17ff82aae coverage: Handle fn signature spans more consistently near ? 2023-10-21 11:53:27 +11:00
Oli Scherer e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer 60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
bors 94c4e5c411 Auto merge of #115214 - Urgau:rfc-3127-trim-paths, r=compiler-errors
Implement rustc part of RFC 3127 trim-paths

This PR implements (or at least tries to) [RFC 3127 trim-paths](https://github.com/rust-lang/rust/issues/111540), the rustc part. That is `-Zremap-path-scope` with all of it's components/scopes.

`@rustbot` label: +F-trim-paths
2023-10-19 19:09:29 +00:00
Matthias Krüger 096943a534 Rollup merge of #116896 - cjgillot:single-inline, r=oli-obk
Only check in a single place if a pass is enabled.

Fixes https://github.com/rust-lang/rust/issues/116294
2023-10-19 14:38:26 +02:00
Camille GILLOT c1c5a1d69a Only check in a single place if a pass is enabled. 2023-10-18 16:59:23 +00:00
Zalathar 13b2d604ec coverage: Store expression data in function coverage info
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-18 23:44:34 +11:00
Zalathar 7d38f4a611 Remove unused TyCtxt from remove_dead_blocks
This context was only needed by code for processing coverage statements, which
has been removed.
2023-10-18 23:42:45 +11:00
Zalathar 6da319f635 coverage: Store all of a function's mappings in function coverage info
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-18 23:42:39 +11:00
Zalathar 79f935b96c coverage: Rename Operand to CovTerm
Later patches in this PR will use `CovTerm` to represent things that are not
expression operands.
2023-10-18 21:23:58 +11:00
Zalathar a18c5f3b75 coverage: Store the number of counters/expressions in function coverage info
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-18 21:22:40 +11:00
Zalathar c479bc7f3b coverage: Attach an optional FunctionCoverageInfo to mir::Body
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-18 21:20:29 +11:00
Ben Kimock 33b0e4be06 Automatically enable cross-crate inlining for small functions 2023-10-17 19:53:51 -04:00
Urgau eccc9e6628 [RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopes 2023-10-17 10:11:30 +02:00
Arthur Lafrance 5895102c4d debug Span::ctxt() call detection 2023-10-16 19:50:29 -07:00
Zalathar 7aa1b8390b coverage: Explain why we temporarily steal pending_dups 2023-10-16 21:05:46 +11:00
Zalathar 5e5a8e7769 coverage: Inline span_bcb_dominates
Interacting with `basic_coverage_blocks` directly makes it easier to satisfy
the borrow checker when mutating `pending_dups` while reading other fields.
2023-10-16 21:05:46 +11:00