2 use rustc_codegen_ssa::traits::{CoverageInfoBuilderMethods, CoverageInfoMethods};
3 use rustc_hir::def_id::DefId;
4 use rustc_middle::mir::coverage::{
11 use rustc_middle::ty::Instance;
13 use crate::builder::Builder;
14 use crate::context::CodegenCx;
16 impl<'a, 'gcc, 'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
17 fn set_function_source_hash(
19 _instance: Instance<'tcx>,
20 _function_source_hash: u64,
25 fn add_coverage_counter(&mut self, _instance: Instance<'tcx>, _id: CounterValueReference, _region: CodeRegion) -> bool {
30 fn add_coverage_counter_expression(&mut self, _instance: Instance<'tcx>, _id: InjectedExpressionId, _lhs: ExpressionOperandId, _op: Op, _rhs: ExpressionOperandId, _region: Option<CodeRegion>) -> bool {
35 fn add_coverage_unreachable(&mut self, _instance: Instance<'tcx>, _region: CodeRegion) -> bool {
41 impl<'gcc, 'tcx> CoverageInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
42 fn coverageinfo_finalize(&self) {
46 fn get_pgo_func_name_var(&self, _instance: Instance<'tcx>) -> RValue<'gcc> {
50 /// Functions with MIR-based coverage are normally codegenned _only_ if
51 /// called. LLVM coverage tools typically expect every function to be
52 /// defined (even if unused), with at least one call to LLVM intrinsic
53 /// `instrprof.increment`.
55 /// Codegen a small function that will never be called, with one counter
56 /// that will never be incremented.
58 /// For used/called functions, the coverageinfo was already added to the
59 /// `function_coverage_map` (keyed by function `Instance`) during codegen.
60 /// But in this case, since the unused function was _not_ previously
61 /// codegenned, collect the coverage `CodeRegion`s from the MIR and add
62 /// them. The first `CodeRegion` is used to add a single counter, with the
63 /// same counter ID used in the injected `instrprof.increment` intrinsic
64 /// call. Since the function is never called, all other `CodeRegion`s can be
65 /// added as `unreachable_region`s.
66 fn define_unused_fn(&self, _def_id: DefId) {