@@ -22,16 +22,30 @@ use crate::coverageinfo::mapgen::{GlobalFileTable, VirtualFileMapping, span_file
22
22
use crate :: coverageinfo:: { ffi, llvm_cov} ;
23
23
use crate :: llvm;
24
24
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 > ,
27
45
global_file_table : & GlobalFileTable ,
28
- filenames_ref : u64 ,
29
- unused_function_names : & mut Vec < & ' tcx str > ,
30
46
instance : Instance < ' tcx > ,
31
47
function_coverage : & FunctionCoverage < ' tcx > ,
32
- ) {
33
- let tcx = cx. tcx ;
34
-
48
+ ) -> Option < CovfunRecord < ' tcx > > {
35
49
let mangled_function_name = tcx. symbol_name ( instance) . name ;
36
50
let source_hash = function_coverage. source_hash ( ) ;
37
51
let is_used = function_coverage. is_used ( ) ;
@@ -47,22 +61,11 @@ pub(crate) fn prepare_and_generate_covfun_record<'ll, 'tcx>(
47
61
) ;
48
62
} else {
49
63
debug ! ( "unused function had no coverage mapping data: {}" , mangled_function_name) ;
50
- return ;
64
+ return None ;
51
65
}
52
66
}
53
67
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 } )
66
69
}
67
70
68
71
/// Using the expressions and counter regions collected for a single function,
@@ -145,14 +148,18 @@ fn encode_mappings_for_function(
145
148
/// Generates the contents of the covfun record for this function, which
146
149
/// contains the function's coverage mapping data. The record is then stored
147
150
/// 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 > ,
152
153
filenames_ref : u64 ,
153
- coverage_mapping_buffer : Vec < u8 > ,
154
- is_used : bool ,
154
+ covfun : & CovfunRecord < ' tcx > ,
155
155
) {
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
+
156
163
// Concatenate the encoded coverage mappings
157
164
let coverage_mapping_size = coverage_mapping_buffer. len ( ) ;
158
165
let coverage_mapping_val = cx. const_bytes ( & coverage_mapping_buffer) ;
0 commit comments