coverage: Push down creation of the mappings payload buffer
Instead of writing coverage mappings into a supplied `&RustString`, this function can just create the buffer itself and return the resulting vector of bytes.
This commit is contained in:
parent
fbbb543ced
commit
99da8a83c2
1 changed files with 14 additions and 21 deletions
|
@ -7,7 +7,6 @@ use rustc_codegen_ssa::traits::ConstMethods;
|
||||||
use rustc_data_structures::fx::FxIndexSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_llvm::RustString;
|
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||||
use rustc_middle::mir::coverage::CodeRegion;
|
use rustc_middle::mir::coverage::CodeRegion;
|
||||||
|
@ -67,14 +66,8 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
|
||||||
let (expressions, counter_regions) =
|
let (expressions, counter_regions) =
|
||||||
function_coverage.get_expressions_and_counter_regions();
|
function_coverage.get_expressions_and_counter_regions();
|
||||||
|
|
||||||
let coverage_mapping_buffer = llvm::build_byte_buffer(|coverage_mapping_buffer| {
|
let coverage_mapping_buffer =
|
||||||
write_coverage_mapping(
|
encode_mappings_for_function(&mut global_file_table, expressions, counter_regions);
|
||||||
&mut global_file_table,
|
|
||||||
expressions,
|
|
||||||
counter_regions,
|
|
||||||
coverage_mapping_buffer,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
if coverage_mapping_buffer.is_empty() {
|
if coverage_mapping_buffer.is_empty() {
|
||||||
if function_coverage.is_used() {
|
if function_coverage.is_used() {
|
||||||
|
@ -155,19 +148,19 @@ impl GlobalFileTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Using the `expressions` and `counter_regions` collected for the current function, generate
|
/// Using the expressions and counter regions collected for a single function,
|
||||||
/// the `mapping_regions` and `virtual_file_mapping`, and capture any new filenames. Then use
|
/// generate the variable-sized payload of its corresponding `__llvm_covfun`
|
||||||
/// LLVM APIs to encode the `virtual_file_mapping`, `expressions`, and `mapping_regions` into
|
/// entry. The payload is returned as a vector of bytes.
|
||||||
/// the given `coverage_mapping` byte buffer, compliant with the LLVM Coverage Mapping format.
|
///
|
||||||
fn write_coverage_mapping<'a>(
|
/// Newly-encountered filenames will be added to the global file table.
|
||||||
|
fn encode_mappings_for_function<'a>(
|
||||||
global_file_table: &mut GlobalFileTable,
|
global_file_table: &mut GlobalFileTable,
|
||||||
expressions: Vec<CounterExpression>,
|
expressions: Vec<CounterExpression>,
|
||||||
counter_regions: impl Iterator<Item = (Counter, &'a CodeRegion)>,
|
counter_regions: impl Iterator<Item = (Counter, &'a CodeRegion)>,
|
||||||
coverage_mapping_buffer: &RustString,
|
) -> Vec<u8> {
|
||||||
) {
|
|
||||||
let mut counter_regions = counter_regions.collect::<Vec<_>>();
|
let mut counter_regions = counter_regions.collect::<Vec<_>>();
|
||||||
if counter_regions.is_empty() {
|
if counter_regions.is_empty() {
|
||||||
return;
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut virtual_file_mapping = Vec::new();
|
let mut virtual_file_mapping = Vec::new();
|
||||||
|
@ -206,15 +199,15 @@ fn write_coverage_mapping<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// Encode the function's coverage mappings into a buffer.
|
||||||
// Encode and append the current function's coverage mapping data
|
llvm::build_byte_buffer(|buffer| {
|
||||||
coverageinfo::write_mapping_to_buffer(
|
coverageinfo::write_mapping_to_buffer(
|
||||||
virtual_file_mapping,
|
virtual_file_mapping,
|
||||||
expressions,
|
expressions,
|
||||||
mapping_regions,
|
mapping_regions,
|
||||||
coverage_mapping_buffer,
|
buffer,
|
||||||
);
|
);
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct coverage map header and the array of function records, and combine them into the
|
/// Construct coverage map header and the array of function records, and combine them into the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue