Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c564f81
rustdoc: align stability badge to baseline instead of bottom
notriddle Dec 13, 2022
193fec6
Preparing for merge from rustc
Oct 22, 2023
1f09dd2
Merge from rustc
Oct 22, 2023
8cbac82
clippy
RalfJung Oct 22, 2023
f6be93f
Auto merge of #3133 - rust-lang:rustup-2023-10-22, r=RalfJung
bors Oct 22, 2023
b53c34f
avoid AtomicU64 when a Cell is enough
RalfJung Oct 22, 2023
f35c36a
Auto merge of #3135 - RalfJung:nonatomic-clock, r=RalfJung
bors Oct 22, 2023
371883a
coverage: Split `FunctionCoverage` into distinct collector/finished p…
Zalathar Oct 6, 2023
86b55cc
coverage: Fetch expressions and mappings separately
Zalathar Oct 6, 2023
e985ae5
coverage: Build the global file table ahead of time
Zalathar Oct 3, 2023
88159ca
coverage: Encapsulate local-to-global file mappings
Zalathar Sep 28, 2023
de4cfbc
coverage: Encode function mappings without re-sorting them
Zalathar Sep 28, 2023
6af9fef
coverage: Emit the filenames section before encoding per-function map…
Zalathar Oct 6, 2023
dc00d03
add target csky-unknown-linux-gnuabiv2hf
Dirreke Oct 22, 2023
5454797
tidy docs
Dirreke Oct 22, 2023
bb67e0f
fix broken link: update incremental compilation url
gvozdvmozgu Oct 22, 2023
1f9f041
x.ps1: remove the check for Python from Windows Store
xobs Oct 23, 2023
e86f9b6
Rollup merge of #105666 - notriddle:notriddle/stab-baseline, r=Guilla…
matthiaskrgr Oct 23, 2023
dde77f7
Rollup merge of #117042 - Zalathar:file-table, r=cjgillot
matthiaskrgr Oct 23, 2023
fe4fde2
Rollup merge of #117044 - RalfJung:miri, r=RalfJung
matthiaskrgr Oct 23, 2023
9acb775
Rollup merge of #117049 - Dirreke:csky-unknown-linux-gunabiv2, r=bjorn3
matthiaskrgr Oct 23, 2023
2636745
Rollup merge of #117051 - gvozdvmozgu:fix-incremental-compilation-lin…
matthiaskrgr Oct 23, 2023
cec7d4a
Rollup merge of #117069 - xobs:x.ps1-remove-windows-store-check, r=al…
matthiaskrgr Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
Zalathar committed Oct 22, 2023
commit 6af9fef08590fd499370a2f6cbbae9ceacf15336
36 changes: 15 additions & 21 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,22 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
function_coverage_entries.iter().flat_map(|(_, fn_cov)| fn_cov.all_file_names());
let global_file_table = GlobalFileTable::new(all_file_names);

// Encode all filenames referenced by coverage mappings in this CGU.
let filenames_buffer = global_file_table.make_filenames_buffer(tcx);

let filenames_size = filenames_buffer.len();
let filenames_val = cx.const_bytes(&filenames_buffer);
let filenames_ref = coverageinfo::hash_bytes(&filenames_buffer);

// Generate the coverage map header, which contains the filenames used by
// this CGU's coverage mappings, and store it in a well-known global.
let cov_data_val = generate_coverage_map(cx, version, filenames_size, filenames_val);
coverageinfo::save_cov_data_to_mod(cx, cov_data_val);

let mut unused_function_names = Vec::new();
let covfun_section_name = coverageinfo::covfun_section_name(cx);

// Encode coverage mappings and generate function records
let mut function_data = Vec::new();
for (instance, function_coverage) in function_coverage_entries {
debug!("Generate function coverage for {}, {:?}", cx.codegen_unit.name(), instance);

Expand All @@ -91,23 +105,6 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
}
}

function_data.push((mangled_function_name, source_hash, is_used, coverage_mapping_buffer));
}

// Encode all filenames referenced by counters/expressions in this module
let filenames_buffer = global_file_table.make_filenames_buffer(tcx);

let filenames_size = filenames_buffer.len();
let filenames_val = cx.const_bytes(&filenames_buffer);
let filenames_ref = coverageinfo::hash_bytes(&filenames_buffer);

// Generate the LLVM IR representation of the coverage map and store it in a well-known global
let cov_data_val = generate_coverage_map(cx, version, filenames_size, filenames_val);

let mut unused_function_names = Vec::new();

let covfun_section_name = coverageinfo::covfun_section_name(cx);
for (mangled_function_name, source_hash, is_used, coverage_mapping_buffer) in function_data {
if !is_used {
unused_function_names.push(mangled_function_name);
}
Expand Down Expand Up @@ -141,9 +138,6 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
llvm::set_linkage(array, llvm::Linkage::InternalLinkage);
llvm::set_initializer(array, initializer);
}

// Save the coverage data value to LLVM IR
coverageinfo::save_cov_data_to_mod(cx, cov_data_val);
}

/// Maps "global" (per-CGU) file ID numbers to their underlying filenames.
Expand Down
6 changes: 3 additions & 3 deletions tests/run-make/coverage-llvmir/filecheck.testprog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

WINDOWS: $__llvm_profile_runtime_user = comdat any

CHECK: @__covrec_{{[A-F0-9]+}}u = linkonce_odr hidden constant
CHECK-SAME: section "[[INSTR_PROF_COVFUN]]"[[COMDAT_IF_SUPPORTED]], align 8

CHECK: @__llvm_coverage_mapping = private constant
CHECK-SAME: section "[[INSTR_PROF_COVMAP]]", align 8

CHECK: @__covrec_{{[A-F0-9]+}}u = linkonce_odr hidden constant
CHECK-SAME: section "[[INSTR_PROF_COVFUN]]"[[COMDAT_IF_SUPPORTED]], align 8

WINDOWS: @__llvm_profile_runtime = external{{.*}}global i32

CHECK: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called = {{private|internal}} global
Expand Down