]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_gcc/src/coverageinfo.rs
Merge commit 'e228f0c16ea8c34794a6285bf57aab627c26b147' into libgccjit-codegen
[rust.git] / compiler / rustc_codegen_gcc / src / coverageinfo.rs
1 use gccjit::RValue;
2 use rustc_codegen_ssa::traits::{CoverageInfoBuilderMethods, CoverageInfoMethods};
3 use rustc_hir::def_id::DefId;
4 use rustc_middle::mir::coverage::{
5     CodeRegion,
6     CounterValueReference,
7     ExpressionOperandId,
8     InjectedExpressionId,
9     Op,
10 };
11 use rustc_middle::ty::Instance;
12
13 use crate::builder::Builder;
14 use crate::context::CodegenCx;
15
16 impl<'a, 'gcc, 'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
17     fn set_function_source_hash(
18         &mut self,
19         _instance: Instance<'tcx>,
20         _function_source_hash: u64,
21     ) -> bool {
22         unimplemented!();
23     }
24
25     fn add_coverage_counter(&mut self, _instance: Instance<'tcx>, _id: CounterValueReference, _region: CodeRegion) -> bool {
26         // TODO(antoyo)
27         false
28     }
29
30     fn add_coverage_counter_expression(&mut self, _instance: Instance<'tcx>, _id: InjectedExpressionId, _lhs: ExpressionOperandId, _op: Op, _rhs: ExpressionOperandId, _region: Option<CodeRegion>) -> bool {
31         // TODO(antoyo)
32         false
33     }
34
35     fn add_coverage_unreachable(&mut self, _instance: Instance<'tcx>, _region: CodeRegion) -> bool {
36         // TODO(antoyo)
37         false
38     }
39 }
40
41 impl<'gcc, 'tcx> CoverageInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
42     fn coverageinfo_finalize(&self) {
43         // TODO(antoyo)
44     }
45
46     fn get_pgo_func_name_var(&self, _instance: Instance<'tcx>) -> RValue<'gcc> {
47         unimplemented!();
48     }
49
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`.
54     ///
55     /// Codegen a small function that will never be called, with one counter
56     /// that will never be incremented.
57     ///
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) {
67         unimplemented!();
68     }
69 }