@@ -22,16 +22,30 @@ use crate::coverageinfo::mapgen::{GlobalFileTable, VirtualFileMapping, span_file
2222use crate :: coverageinfo:: { ffi, llvm_cov} ;
2323use crate :: llvm;
2424
25- pub ( crate ) fn prepare_and_generate_covfun_record < ' ll , ' tcx > (
26- cx : & CodegenCx < ' ll , ' tcx > ,
25+ /// Intermediate coverage metadata for a single function, used to help build
26+ /// the final record that will be embedded in the `__llvm_covfun` section.
27+ #[ derive( Debug ) ]
28+ pub ( crate ) struct CovfunRecord < ' tcx > {
29+ mangled_function_name : & ' tcx str ,
30+ source_hash : u64 ,
31+ is_used : bool ,
32+ coverage_mapping_buffer : Vec < u8 > ,
33+ }
34+
35+ impl < ' tcx > CovfunRecord < ' tcx > {
36+ /// FIXME(Zalathar): Make this the responsibility of the code that determines
37+ /// which functions are unused.
38+ pub ( crate ) fn mangled_function_name_if_unused ( & self ) -> Option < & ' tcx str > {
39+ ( !self . is_used ) . then_some ( self . mangled_function_name )
40+ }
41+ }
42+
43+ pub ( crate ) fn prepare_covfun_record < ' tcx > (
44+ tcx : TyCtxt < ' tcx > ,
2745 global_file_table : & GlobalFileTable ,
28- filenames_ref : u64 ,
29- unused_function_names : & mut Vec < & ' tcx str > ,
3046 instance : Instance < ' tcx > ,
3147 function_coverage : & FunctionCoverage < ' tcx > ,
32- ) {
33- let tcx = cx. tcx ;
34-
48+ ) -> Option < CovfunRecord < ' tcx > > {
3549 let mangled_function_name = tcx. symbol_name ( instance) . name ;
3650 let source_hash = function_coverage. source_hash ( ) ;
3751 let is_used = function_coverage. is_used ( ) ;
@@ -47,22 +61,11 @@ pub(crate) fn prepare_and_generate_covfun_record<'ll, 'tcx>(
4761 ) ;
4862 } else {
4963 debug ! ( "unused function had no coverage mapping data: {}" , mangled_function_name) ;
50- return ;
64+ return None ;
5165 }
5266 }
5367
54- if !is_used {
55- unused_function_names. push ( mangled_function_name) ;
56- }
57-
58- generate_covfun_record (
59- cx,
60- mangled_function_name,
61- source_hash,
62- filenames_ref,
63- coverage_mapping_buffer,
64- is_used,
65- ) ;
68+ Some ( CovfunRecord { mangled_function_name, source_hash, is_used, coverage_mapping_buffer } )
6669}
6770
6871/// Using the expressions and counter regions collected for a single function,
@@ -145,14 +148,18 @@ fn encode_mappings_for_function(
145148/// Generates the contents of the covfun record for this function, which
146149/// contains the function's coverage mapping data. The record is then stored
147150/// as a global variable in the `__llvm_covfun` section.
148- fn generate_covfun_record (
149- cx : & CodegenCx < ' _ , ' _ > ,
150- mangled_function_name : & str ,
151- source_hash : u64 ,
151+ pub ( crate ) fn generate_covfun_record < ' tcx > (
152+ cx : & CodegenCx < ' _ , ' tcx > ,
152153 filenames_ref : u64 ,
153- coverage_mapping_buffer : Vec < u8 > ,
154- is_used : bool ,
154+ covfun : & CovfunRecord < ' tcx > ,
155155) {
156+ let & CovfunRecord {
157+ mangled_function_name,
158+ source_hash,
159+ is_used,
160+ ref coverage_mapping_buffer, // Previously-encoded coverage mappings
161+ } = covfun;
162+
156163 // Concatenate the encoded coverage mappings
157164 let coverage_mapping_size = coverage_mapping_buffer. len ( ) ;
158165 let coverage_mapping_val = cx. const_bytes ( & coverage_mapping_buffer) ;
0 commit comments