[llvm-cov] Look up expansion regions by FileID with binary search (#246474)
The following problem was encountered while computing coverage for the
LLVM codebase. `llvm-cov export` on an instrumented `opt` took ~20min
for a profile from the AMDGPU lit suite (~7k tests). After these changes
it took 10s. The output was byte identical in both instances.
`llvm-cov` repeatedly look up entries by key in a container that is
already sorted by that key. Each lookup is conceptually selecting a
contiguous subrange. The old code scanned the whole container every
time. The PR replaces that with a binary search over the subrange. The
containers are already sorted; the PR only introduces assertions to
validate it.
The logical changes are introduced in
`CoverageMapping::getCoverageForExpansion` (easier to start reading from
there). The linear scan is replaced by an equivalent binary search over
the subrange.
My goal here is to provide a local optimization for this bottleneck
because at the moment it is not possible to compute coverage for LLVM in
a reasonable amount of time. `llvm-cov` may take more time than running
the test suite itself.
Reproducer: instrumented `opt` (all targets, statically linked,
RelWithDebInfo, assertions off), coverage profiled with the AMDGPU lit
suite (~7k tests), then: `llvm-cov export -format=lcov -j 32
-instr-profile=… bin/opt`