Commit Graph

137 Commits

Author SHA1 Message Date
Manuel Drehwald
1f30517d40 upstream rustc_codegen_ssa/rustc_middle changes for enzyme/autodiff 2025-01-29 21:31:13 -05:00
Oli Scherer
b24f674520 Change collect_and_partition_mono_items tuple return type to a struct 2025-01-27 09:38:12 +00:00
Zalathar
837a25dd41 coverage: Identify source files by ID, not by interned filename 2024-12-19 18:09:09 +11:00
Zalathar
34ed51cb83 coverage: Store coverage source regions as Span until codegen 2024-12-19 18:09:09 +11:00
Zalathar
541d4e85d9 coverage: Track used functions in a set instead of a map
This patch dismantles what was left of `FunctionCoverage` in `map_data.rs`,
replaces `function_coverage_map` with a set, and overhauls how we prepare
covfun records for unused functions.
2024-12-17 14:14:19 +11:00
Zalathar
d34c365eb0 coverage: Pull function source hash out of map_data.rs 2024-12-17 13:55:20 +11:00
Zalathar
154fae1e8d coverage: Build the global file table on the fly 2024-12-17 13:55:19 +11:00
Zalathar
fe412af4fc coverage: Use is_eligible_for_coverage to filter unused functions
The checks in `is_eligible_for_coverage` include `is_fn_like`, but will also
exclude various function-like things that cannot possibly have coverage
instrumentation.
2024-12-17 13:30:11 +11:00
Zalathar
5f5745beb0 coverage: Tidy up creation of covfun records 2024-12-12 22:13:07 +11:00
Zalathar
de53fe245d coverage: Tidy up creation of covmap records 2024-12-12 22:10:42 +11:00
Zalathar
3f3a9bf7f5 coverage: Store intermediate region tables in CovfunRecord
This defers the call to `llvm_cov::write_function_mappings_to_buffer` until
just before its enclosing global variable is created.
2024-12-11 21:35:45 +11:00
Zalathar
512f3fdebe coverage: Only generate a CGU's covmap record if it has covfun records 2024-12-11 21:35:44 +11:00
Zalathar
6a8c016266 coverage: Reify CovfunRecord as an intermediate step 2024-12-11 18:25:10 +11:00
Zalathar
7c4ac71ad1 coverage: Extract function metadata handling to a covfun submodule 2024-12-11 17:49:44 +11:00
Zalathar
3a35fb6938 coverage: Unused functions don't need to store CoverageIdsInfo 2024-12-08 21:00:53 +11:00
Zalathar
4d2bfece41 coverage: Remove FunctionCoverageCollector
The information that was being collected by this builder type is now collected
by the `coverage_ids_info` query instead.
2024-12-08 20:53:57 +11:00
Zalathar
6fc0fe76e8 coverage: Use a query to identify which counter/expression IDs are used 2024-11-30 00:58:48 +11:00
Zalathar
121a17ccc3 coverage: All counter terms in an unused function are zero
This is currently handled automatically by the fact that codegen doesn't visit
coverage statements in unused functions, but that will no longer be the case
when unused IDs are identified by a separate query instead.
2024-11-30 00:54:53 +11:00
Zalathar
9461f4296f Revert "Rollup merge of #133418 - Zalathar:spans, r=jieyouxu"
This reverts commit adf9b5fcd1, reversing
changes made to af1ca153d4.

Reverting due to <https://github.com/rust-lang/rust/issues/133606>.
2024-11-29 14:57:01 +11:00
Zalathar
2748009aad coverage: Identify source files by ID, not by interned filename 2024-11-24 23:46:41 +11:00
Zalathar
b9fb1a69d2 coverage: Store coverage source regions as Span until codegen 2024-11-24 23:46:39 +11:00
Zalathar
87fe7def12 coverage: Rename some FFI fields from span to cov_span
This will avoid confusion with actual `Span` spans.
2024-11-24 23:29:02 +11:00
Zalathar
619a272612 coverage: Ignore functions that end up having no mappings
A used function with no mappings has historically indicated a bug, but that
will no longer be the case after moving some fallible span-processing steps
into codegen.
2024-11-24 23:28:02 +11:00
Matthias Krüger
b95232dabb
Rollup merge of #132675 - Zalathar:empty-spans, r=jieyouxu
coverage: Restrict empty-span expansion to only cover `{` and `}`

Coverage instrumentation has some tricky code for converting a coverage-relevant `Span` into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata.

A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well.

This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is `{`, or the character before the empty span is `}`.

(As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.)

Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.
2024-11-10 17:43:07 +01:00
Zalathar
925dfc8608 coverage: Pass a LocalFileId to CoverageSpan::from_source_region 2024-11-10 11:58:44 +11:00
Zalathar
996bdabc2a coverage: Remove unhelpful code for handling multiple files per function
Functions currently can't have mappings in multiple files, and if that ever
changes (e.g. to properly support expansion regions), this code will need to be
completely overhauled anyway.
2024-11-08 20:43:08 +11:00
Zalathar
3f9c54caf0 coverage: Add GlobalFileId for stricter type-checking of file IDs
We already had a dedicated `LocalFileId` index type, but previously we used a
raw `u32` for global file IDs, because index types were harder to pass through
FFI.
2024-11-08 20:43:08 +11:00
Zalathar
b790e4473c coverage: Extract safe FFI wrapper functions to llvm_cov 2024-11-05 15:32:34 +11:00
Zalathar
8dddd1ae60 coverage: Avoid ICE when coverage_cx is unexpectedly unavailable 2024-10-31 21:25:43 +11:00
Zalathar
0d653a5866 coverage: Add links to LLVM docs for the coverage mapping format 2024-10-26 17:37:04 +11:00
Zalathar
0356908cf5 coverage: Store covfun_section_name in the codegen context
Adding an extra `OnceCell` to `CrateCoverageContext` is much nicer than trying
to thread this string through multiple layers of function calls that already
have access to the context.
2024-10-25 12:42:42 +11:00
Zalathar
0a96176533 coverage: Make obtaining the codegen coverage context infallible
In all the situations where this context is needed, it should always be
available.
2024-10-25 12:42:42 +11:00
Zalathar
9f8a6be221 coverage: Consolidate creation of covmap/covfun records
There is no need for this code to be split across multiple functions in
multiple files.
2024-10-25 12:42:23 +11:00
Stuart Cook
8f354fc94a
Rollup merge of #131956 - Zalathar:llvm-counters, r=compiler-errors,Swatinem
coverage: Pass coverage mappings to LLVM as separate structs

Instead of trying to cram *N* different kinds of coverage mapping data into a single list for FFI, pass *N* different lists of simpler structs.

This avoids the need to fill unused fields with dummy values, and avoids the need to tag structs with their underlying kind. It also lets us call the dedicated LLVM constructors for each different mapping type, instead of having to go through the complex general-purpose constructor.

Even though this adds multiple new structs to the FFI surface area, the resulting C++ code is simpler and shorter.

---

I've structured this mostly as a single atomic patch, rather than a series of incremental changes, because that avoids the need to make fiddly fixes to code that is about to be deleted anyway.
2024-10-24 14:19:57 +11:00
Zalathar
3310419d35 Make llvm::set_section take a &CStr 2024-10-20 17:08:05 +11:00
Zalathar
d1bf77eb34 Pass coverage mappings to LLVM as separate structs 2024-10-20 13:29:34 +11:00
Jubilee Young
888efe74a3 cg_llvm: Switch llvm::add_global to &CStr 2024-10-18 17:46:33 -07:00
Zalathar
9357277de7 coverage: Remove code related to LLVM 17 2024-10-11 21:44:36 +11:00
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Nicholas Nethercote
a8d22eb39e Rename supertraits of CodegenMethods.
Supertraits of `BuilderMethods` are all called `XyzBuilderMethods`.
Supertraits of `CodegenMethods` are all called `XyzMethods`. This commit
changes the latter to `XyzCodegenMethods`, for consistency.
2024-09-17 10:24:43 +10:00
Alexander Cyon
ac69544a17
chore: Fix typos in 'compiler' (batch 1) 2024-09-02 07:42:38 +02:00
Nicholas Nethercote
61627438eb Add warn(unreachable_pub) to rustc_codegen_llvm. 2024-08-16 08:46:57 +10:00
Nicholas Nethercote
84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Nicholas Nethercote
8e94226e61 Remove #[macro_use] extern crate tracing from rustc_codegen_llvm. 2024-05-23 18:02:40 +10:00
Zalathar
8289dadfbc coverage: Correctly report and check LLVM's coverage mapping version 2024-04-03 09:53:49 +11:00
Urgau
106146fd95 Replace RemapFileNameExt::for_codegen with explicit calls 2024-03-28 18:47:26 +01:00
Zalathar
54116c8cae coverage: Detect functions that have lost all their coverage statements
If a function was instrumented for coverage, but all of its coverage statements
have been removed by later MIR transforms, it should be treated as "unused"
even if the compiler generates an unreachable stub for it.
2024-03-26 11:46:04 +11:00
Zalathar
e3f66b2493 coverage: Overhaul the search for unused functions 2024-03-26 11:46:04 +11:00
Zalathar
5ddc4f24cc coverage: Inline creating a dummy instance for unused functions 2024-03-26 11:29:38 +11:00
Zalathar
1f544ce305 coverage: Remove all unstable values of -Cinstrument-coverage 2024-03-13 11:14:09 +11:00