Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage: Emit the filenames section before encoding per-function mappings #117042

Merged
merged 6 commits into from
Oct 23, 2023

Commits on Oct 22, 2023

  1. coverage: Split FunctionCoverage into distinct collector/finished p…

    …hases
    
    This gives us a clearly-defined place to run code after the instance's MIR has
    been traversed by codegen, but before we emit its `__llvm_covfun` record.
    Zalathar committed Oct 22, 2023
    Configuration menu
    Copy the full SHA
    371883a View commit details
    Browse the repository at this point in the history
  2. coverage: Fetch expressions and mappings separately

    The combined `get_expressions_and_counter_regions` method was an artifact of
    having to prepare the expressions and mappings at the same time, to avoid
    ownership/lifetime problems with temporary data used by both.
    
    Now that we have an explicit transition from `FunctionCoverageCollector` to the
    final `FunctionCoverage`, we can prepare any shared data during that step and
    store it in the final struct.
    Zalathar committed Oct 22, 2023
    Configuration menu
    Copy the full SHA
    86b55cc View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    e985ae5 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    88159ca View commit details
    Browse the repository at this point in the history
  5. coverage: Encode function mappings without re-sorting them

    The main change here is that `VirtualFileMapping` now uses an internal hashmap
    to de-duplicate incoming global file IDs. That removes the need for
    `encode_mappings_for_function` to re-sort its mappings by filename in order to
    de-duplicate them.
    
    (We still de-duplicate runs of identical filenames to save work, but this is
    not load-bearing for correctness, so a sort is not necessary.)
    Zalathar committed Oct 22, 2023
    Configuration menu
    Copy the full SHA
    de4cfbc View commit details
    Browse the repository at this point in the history
  6. coverage: Emit the filenames section before encoding per-function map…

    …pings
    
    Most coverage metadata is encoded into two sections in the final executable.
    The `__llvm_covmap` section mostly just contains a list of filenames, while the
    `__llvm_covfun` section contains encoded coverage maps for each instrumented
    function.
    
    The catch is that each per-function record also needs to contain a hash of the
    filenames list that it refers to. Historically this was handled by assembling
    most of the per-function data into a temporary list, then assembling the
    filenames buffer, then using the filenames hash to emit the per-function data,
    and then finally emitting the filenames table itself.
    
    However, now that we build the filenames table up-front (via a separate
    traversal of the per-function data), we can hash and emit that part first, and
    then emit each of the per-function records immediately after building. This
    removes the awkwardness of having to temporarily store nearly-complete
    per-function records.
    Zalathar committed Oct 22, 2023
    Configuration menu
    Copy the full SHA
    6af9fef View commit details
    Browse the repository at this point in the history