Skip to content

Commit e00df5d

Browse files
committed
mcdc-coverage(codegen): Add MCDCTestVectorBitmapUpdate codegen implementation
1 parent 33de2bb commit e00df5d

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,33 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
221221
cond_result,
222222
)
223223
}
224-
CoverageKind::MCDCTestBitmapUpdate { needed_bytes: _, decision_index: _ } => todo!(),
224+
CoverageKind::MCDCTestVectorBitmapUpdate { needed_bytes, decision_index } => {
225+
// Drop unused coverage_map, which prevents us to use bx.
226+
drop(coverage_map);
227+
228+
let fn_name = bx.get_pgo_func_name_var(instance);
229+
let hash = bx.const_u64(function_coverage_info.function_source_hash);
230+
let needed_bytes = bx.const_u32(needed_bytes);
231+
let bitmap_idx = bx.const_u32(decision_index);
232+
let cond_bitmap_addr = match coverage_context
233+
.mcdc_condbitmap_map
234+
.borrow()
235+
.get(&instance)
236+
{
237+
Some(addr) => *addr,
238+
None => bug!(
239+
"Condition bitmap reset instruction was encountered without a condition bitmap being declared."
240+
),
241+
};
242+
243+
bx.instrprof_mcdc_tvbitmap_update(
244+
fn_name,
245+
hash,
246+
needed_bytes,
247+
bitmap_idx,
248+
cond_bitmap_addr,
249+
)
250+
}
225251
}
226252
}
227253
}

compiler/rustc_middle/src/mir/coverage.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub enum CoverageKind {
190190
MCDCCondBitmapUpdate { condition_id: u32, bool_value: bool },
191191

192192
/// Marks a point where a bit of the global Test Vector bitmap should be set to one.
193-
MCDCTestBitmapUpdate { needed_bytes: u32, decision_index: u32 },
193+
MCDCTestVectorBitmapUpdate { needed_bytes: u32, decision_index: u32 },
194194
}
195195

196196
impl Debug for CoverageKind {
@@ -228,7 +228,7 @@ impl Debug for CoverageKind {
228228
MCDCCondBitmapUpdate { condition_id, bool_value } => {
229229
write!(fmt, "MCDCCondBitmapUpdate({condition_id}, {bool_value})")
230230
}
231-
MCDCTestBitmapUpdate { needed_bytes, decision_index } => {
231+
MCDCTestVectorBitmapUpdate { needed_bytes, decision_index } => {
232232
write!(fmt, "MCDCTVBitmapUpdate({needed_bytes} bytes, {decision_index})")
233233
}
234234
}

compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
239239
| CoverageKind::MCDCBitmapRequire { .. }
240240
| CoverageKind::MCDCCondBitmapReset
241241
| CoverageKind::MCDCCondBitmapUpdate { .. }
242-
| CoverageKind::MCDCTestBitmapUpdate { .. }
242+
| CoverageKind::MCDCTestVectorBitmapUpdate { .. }
243243
) => bug!(
244244
"Unexpected coverage statement found during coverage instrumentation: {statement:?}"
245245
),

0 commit comments

Comments
 (0)