diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2023-09-03 16:07:50 +1000 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2023-09-11 14:29:10 +1000 |
| commit | 99da8a83c295b26b2211c90c0d6e4566b39b2c10 (patch) | |
| tree | 4a631ca889ae21599064af3b8265f079e2ff0a89 /compiler/rustc_codegen_llvm/src | |
| parent | fbbb543ced054daf718e6442247778713bde7008 (diff) | |
| download | rust-99da8a83c295b26b2211c90c0d6e4566b39b2c10.tar.gz rust-99da8a83c295b26b2211c90c0d6e4566b39b2c10.zip | |
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.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index b9025eff82c..cbf245d054b 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -7,7 +7,6 @@ use rustc_codegen_ssa::traits::ConstMethods; use rustc_data_structures::fx::FxIndexSet; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; -use rustc_llvm::RustString; use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::coverage::CodeRegion; @@ -67,14 +66,8 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) { let (expressions, counter_regions) = function_coverage.get_expressions_and_counter_regions(); - let coverage_mapping_buffer = llvm::build_byte_buffer(|coverage_mapping_buffer| { - write_coverage_mapping( - &mut global_file_table, - expressions, - counter_regions, - coverage_mapping_buffer, - ); - }); + let coverage_mapping_buffer = + encode_mappings_for_function(&mut global_file_table, expressions, counter_regions); if coverage_mapping_buffer.is_empty() { if function_coverage.is_used() { @@ -155,19 +148,19 @@ impl GlobalFileTable { } } -/// Using the `expressions` and `counter_regions` collected for the current function, generate -/// the `mapping_regions` and `virtual_file_mapping`, and capture any new filenames. Then use -/// LLVM APIs to encode the `virtual_file_mapping`, `expressions`, and `mapping_regions` into -/// the given `coverage_mapping` byte buffer, compliant with the LLVM Coverage Mapping format. -fn write_coverage_mapping<'a>( +/// Using the expressions and counter regions collected for a single function, +/// generate the variable-sized payload of its corresponding `__llvm_covfun` +/// entry. The payload is returned as a vector of bytes. +/// +/// Newly-encountered filenames will be added to the global file table. +fn encode_mappings_for_function<'a>( global_file_table: &mut GlobalFileTable, expressions: Vec<CounterExpression>, counter_regions: impl Iterator<Item = (Counter, &'a CodeRegion)>, - coverage_mapping_buffer: &RustString, -) { +) -> Vec<u8> { let mut counter_regions = counter_regions.collect::<Vec<_>>(); if counter_regions.is_empty() { - return; + return Vec::new(); } let mut virtual_file_mapping = Vec::new(); @@ -206,15 +199,15 @@ fn write_coverage_mapping<'a>( } } - { - // Encode and append the current function's coverage mapping data + // Encode the function's coverage mappings into a buffer. + llvm::build_byte_buffer(|buffer| { coverageinfo::write_mapping_to_buffer( virtual_file_mapping, expressions, mapping_regions, - coverage_mapping_buffer, + buffer, ); - } + }) } /// Construct coverage map header and the array of function records, and combine them into the |
