about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/coverageinfo
AgeCommit message (Collapse)AuthorLines
2023-10-18coverage: Store all of a function's mappings in function coverage infoZalathar-69/+39
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: Make expression simplification non-destructiveZalathar-22/+58
Instead of modifying the accumulated expressions in-place, we now build a set of expressions that are known to be zero, and then consult that set on the fly when converting the expression data for FFI. This will be necessary when moving mappings and expression data into function coverage info, which can't be mutated during codegen.
2023-10-18coverage: Collect a function's coverage mappings into a single listZalathar-75/+51
This is an intermediate step towards being able to store all of a function's mappings in function coverage info.
2023-10-18coverage: Rename `Operand` to `CovTerm`Zalathar-22/+22
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-15/+22
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-49/+48
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-03coverage: Let each coverage statement hold a vector of code regionsZalathar-61/+65
This makes it possible for a `StatementKind::Coverage` to hold more than one code region, but that capability is not yet used.
2023-10-03coverage: Mappings for unused functions can all be zeroZalathar-11/+3
There is no need to include a dummy counter reference in the coverage mappings for an unused function.
2023-09-21coverage: Don't bother renumbering expressions on the Rust sideZalathar-156/+64
The LLVM API that we use to encode coverage mappings already has its own code for removing unused coverage expressions and renumbering the rest. This lets us get rid of our own complex renumbering code, making it easier to change our coverage code in other ways.
2023-09-21coverage: Explicitly simplify coverage expressions in codegenZalathar-1/+57
After coverage instrumentation and MIR transformations, we can sometimes end up with coverage expressions that always have a value of zero. Any expression operand that refers to an always-zero expression can be replaced with a literal `Operand::Zero`, making the emitted coverage mapping data smaller and simpler. This simplification step is mostly redundant with the simplifications performed inline in `expressions_with_regions`, except that it does a slightly more thorough job in some cases (because it checks for always-zero expressions *after* other simplifications). However, adding this simplification step will then let us greatly simplify that code, without affecting the quality of the emitted coverage maps.
2023-09-21coverage: Make the zero counter a constantZalathar-15/+12
2023-09-14Auto merge of #114656 - bossmc:rework-no-coverage-attr, r=oli-obkbors-2/+2
Rework `no_coverage` to `coverage(off)` As discussed at the tail of https://github.com/rust-lang/rust/issues/84605 this replaces the `no_coverage` attribute with a `coverage` attribute that takes sub-parameters (currently `off` and `on`) to control the coverage instrumentation. Allows future-proofing for things like `coverage(off, reason="Tested live", issue="#12345")` or similar.
2023-09-11coverage: Simplify grouping of mappings by fileZalathar-25/+25
This removes an ad-hoc implementation of `group_by`.
2023-09-11coverage: Push down the call to `get_expressions_and_counter_regions`Zalathar-7/+7
These expressions and counter regions are only needed by the function that encodes a function's coverage mappings payload.
2023-09-11coverage: Push down creation of the mappings payload bufferZalathar-21/+14
Instead of writing coverage mappings into a supplied `&RustString`, this function can just create the buffer itself and return the resulting vector of bytes.
2023-09-11coverage: Reserve capacity for all of a function's mapping regionsZalathar-1/+1
We already know in advance how many entries will be pushed onto this vector.
2023-09-11coverage: Use a stable sort when grouping mapped regions by fileZalathar-1/+1
If two or more mappings cover exactly the same region, their relative order will now be preserved from `get_expressions_and_counter_regions`, rather than being disturbed by implementation details of an unstable sort. The current order is: counter mappings, expression mappings, zero mappings. (LLVM will also perform its own stable sort on these mappings, but that sort only compares file ID, start location, and `RegionKind`.)
2023-09-11coverage: Convert `CoverageMapGenerator` to `GlobalFileTable`Zalathar-76/+96
This struct was only being used to hold the global file table, and one of its methods didn't even use the table. Changing its methods to ordinary functions makes it easier to see where the table is mutated.
2023-09-08Rework no_coverage to coverage(off)Andy Caldwell-2/+2
2023-08-22Inline functions called from `add_coverage`Arpad Borsos-123/+46
This removes quite a bit of indirection and duplicated code related to getting the `FunctionCoverage`.
2023-08-04coverage: Don't convert symbol names to `CString` for FFIZalathar-4/+8
2023-08-04coverage: Don't convert filenames to `CString` for FFIZalathar-17/+22
2023-08-02coverage: Consolidate FFI types into one moduleZalathar-6/+199
Coverage FFI types were historically split across two modules, because some of them were needed by code in `rustc_codegen_ssa`. Now that all of the coverage codegen code has been moved into `rustc_codegen_llvm` (#113355), it's possible to move all of the FFI types into a single module, making it easier to see all of them at once.
2023-08-01Make coverage counter IDs count up from 0, not 1Zalathar-27/+12
Operand types are now tracked explicitly, so there is no need to reserve ID 0 for the special always-zero counter. As part of the renumbering, this change fixes an off-by-one error in the way counters were counted by the `coverageinfo` query. As a result, functions should now have exactly the number of counters they actually need, instead of always having an extra counter that is never used.
2023-08-01Make coverage expression IDs count up from 0, not down from `u32::MAX`Zalathar-37/+16
Operand types are now tracked explicitly, so there is no need for expression IDs to avoid counter IDs by descending from `u32::MAX`. Instead they can just count up from 0, and can be used directly as indices when necessary.
2023-08-01Replace `ExpressionOperandId` with enum `Operand`Zalathar-27/+22
Because the three kinds of operand are now distinguished explicitly, we no longer need fiddly code to disambiguate counter IDs and expression IDs based on the total number of counters/expressions in a function. This does increase the size of operands from 4 bytes to 8 bytes, but that shouldn't be a big deal since they are mostly stored inside boxed structures, and the current coverage code is not particularly size-optimized anyway.
2023-07-24coverage: Obtain the `__llvm_covfun` section name outside a per-function loopZalathar-8/+31
This section name is always constant for a given target, but obtaining it from LLVM requires a few intermediate allocations. There's no need to do so repeatedly from inside a per-function loop.
2023-07-16Auto merge of #113430 - Zalathar:hash, r=b-naberbors-10/+5
Remove `LLVMRustCoverageHashCString` Coverage has two FFI functions for computing the hash of a byte string. One takes a ptr/len pair (`LLVMRustCoverageHashByteArray`), and the other takes a NUL-terminated C string (`LLVMRustCoverageHashCString`). But on closer inspection, the C string version is unnecessary. The calling-side code converts a Rust `&str` into a `CString`, and the C++ code then immediately turns it back into a ptr/len string before actually hashing it. So we can just call the ptr/len version directly instead. --- This PR also fixes a bug in the C++ declaration of `LLVMRustCoverageHashByteArray`. It should be `size_t`, since that's what is declared and passed on the Rust side, and it's what `StrRef`'s constructor expects to receive on the callee side.
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-2/+2
2023-07-13Remove `LLVMRustCoverageHashCString`Zalathar-6/+1
Coverage has two FFI functions for computing the hash of a byte string. One takes a ptr/len pair, and the other takes a NUL-terminated C string. But on closer inspection, the C string version is unnecessary. The calling-side code converts a Rust `&str` into a C string, and the C++ code then immediately turns it back into a ptr/len string before actually hashing it.
2023-07-13Pass a byte slice to `coverageinfo::hash_bytes` instead of an owned vectorZalathar-2/+2
The function body immediately treats it as a slice anyway, so this just makes it possible to call the hash function with arbitrary read-only byte slices.
2023-07-13Don't clone symbol names for coverage hashingZalathar-3/+3
A symbol already contains a `&str`, and in this context there's no need to make an owned copy, so we can just use the original string reference.
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-2/+3
2023-07-05Move `coverageinfo::ffi` and `coverageinfo::map` out of SSAZalathar-2/+441
2023-07-05Remove trait `CoverageInfoMethods`, since non-LLVM backends don't need itZalathar-5/+11
These methods are only ever called from within `rustc_codegen_llvm`, so they can just be declared there as well.
2023-07-05Narrow trait `CoverageInfoBuilderMethods` down to just one methodZalathar-2/+57
This effectively inlines most of `FunctionCx::codegen_coverage` into the LLVM implementation of `CoverageInfoBuilderMethods`.
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-1/+1
2023-05-09CFI: Fix SIGILL reached via trait objectsRamon de C Valle-0/+1
Fix #106547 by transforming the concrete self into a reference to a trait object before emitting type metadata identifiers for trait methods.
2023-02-17Use `IntoIterator` for `mk_fn_sig`.Nicholas Nethercote-3/+1
This makes a lot of call sites nicer.
2023-01-27reduce rightward-driftTshepang Mbambo-3/+2
2023-01-26Rollup merge of #106625 - Swatinem:ref/cov6, r=nagisaMatthias Krüger-28/+17
Remove backwards compat for LLVM 12 coverage format The minimum external LLVM was updated to 13 recently in https://github.com/rust-lang/rust/pull/100611, so this PR removes backwards compat with older coverage formats. I kept the version check and error message there, in accordance with this comment: https://github.com/rust-lang/rust/pull/91207#issuecomment-981121867
2023-01-19Use UnordSet instead of FxHashSet in define_id_collections!().Michael Woerister-3/+5
2023-01-09Remove backwards compat for LLVM 12 coverage formatArpad Borsos-28/+17
2022-12-20rustc: Remove needless lifetimesJeremy Stucki-2/+2
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-1/+1
2022-11-16Use `as_deref` in compiler (but only where it makes sense)Maybe Waffle-1/+1
2022-11-09Port Instrument coverage requires llvm 12 to the new structSLASHLogin-1/+2
2022-10-14more dupe word typosRageking8-1/+1
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-3/+0
by module
2022-03-08add `#[rustc_pass_by_value]` to more typeslcnr-4/+4