Skip to content

Commit 8cf7eff

Browse files
committed
mcdc-coverage(codegen): Add MCDCCondBitmap(Reset|Update) Handling in LLVM codegen
1 parent e6a398a commit 8cf7eff

File tree

1 file changed

+48
-2
lines changed
  • compiler/rustc_codegen_llvm/src/coverageinfo

1 file changed

+48
-2
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+48-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,54 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
173173
.borrow_mut()
174174
.insert(instance, cond_bitmap_addr);
175175
}
176-
CoverageKind::MCDCCondBitmapReset => todo!(),
177-
CoverageKind::MCDCCondBitmapUpdate { condition_id: _, bool_value: _ } => todo!(),
176+
CoverageKind::MCDCCondBitmapReset => {
177+
// Drop unused coverage_map, which prevents us to use bx.
178+
drop(coverage_map);
179+
180+
let cond_bitmap_addr = match coverage_context
181+
.mcdc_condbitmap_map
182+
.borrow()
183+
.get(&instance)
184+
{
185+
Some(addr) => *addr,
186+
None => bug!(
187+
"Condition bitmap reset instruction was encountered without a condition bitmap being declared."
188+
),
189+
};
190+
191+
bx.store(
192+
bx.const_i32(0),
193+
cond_bitmap_addr,
194+
Align::from_bytes(4).expect("4 bytes alignement failed"),
195+
);
196+
}
197+
CoverageKind::MCDCCondBitmapUpdate { condition_id, bool_value } => {
198+
// Drop unused coverage_map, which prevents us to use bx.
199+
drop(coverage_map);
200+
201+
let fn_name = bx.get_pgo_func_name_var(instance);
202+
let hash = bx.const_u64(function_coverage_info.function_source_hash);
203+
let cond_id = bx.const_u32(condition_id);
204+
let cond_bitmap_addr = match coverage_context
205+
.mcdc_condbitmap_map
206+
.borrow()
207+
.get(&instance)
208+
{
209+
Some(addr) => *addr,
210+
None => bug!(
211+
"Condition bitmap reset instruction was encountered without a condition bitmap being declared."
212+
),
213+
};
214+
let cond_result = bx.const_bool(bool_value);
215+
216+
bx.instrprof_mcdc_condbitmap_update(
217+
fn_name,
218+
hash,
219+
cond_id,
220+
cond_bitmap_addr,
221+
cond_result,
222+
)
223+
}
178224
CoverageKind::MCDCTestBitmapUpdate { needed_bytes: _, decision_index: _ } => todo!(),
179225
}
180226
}

0 commit comments

Comments
 (0)