Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9c430d3

Browse files
committed
Remove trait CoverageInfoMethods, since non-LLVM backends don't need it
These methods are only ever called from within `rustc_codegen_llvm`, so they can just be declared there as well.
1 parent 4169d0f commit 9c430d3

File tree

5 files changed

+13
-60
lines changed

5 files changed

+13
-60
lines changed
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,11 @@
1-
use gccjit::RValue;
2-
use rustc_codegen_ssa::traits::{CoverageInfoBuilderMethods, CoverageInfoMethods};
3-
use rustc_hir::def_id::DefId;
1+
use rustc_codegen_ssa::traits::CoverageInfoBuilderMethods;
42
use rustc_middle::mir::Coverage;
53
use rustc_middle::ty::Instance;
64

75
use crate::builder::Builder;
8-
use crate::context::CodegenCx;
96

107
impl<'a, 'gcc, 'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
118
fn add_coverage(&mut self, _instance: Instance<'tcx>, _coverage: &Coverage) {
129
// TODO(antoyo)
1310
}
1411
}
15-
16-
impl<'gcc, 'tcx> CoverageInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
17-
fn coverageinfo_finalize(&self) {
18-
// TODO(antoyo)
19-
}
20-
21-
fn get_pgo_func_name_var(&self, _instance: Instance<'tcx>) -> RValue<'gcc> {
22-
unimplemented!();
23-
}
24-
25-
/// Functions with MIR-based coverage are normally codegenned _only_ if
26-
/// called. LLVM coverage tools typically expect every function to be
27-
/// defined (even if unused), with at least one call to LLVM intrinsic
28-
/// `instrprof.increment`.
29-
///
30-
/// Codegen a small function that will never be called, with one counter
31-
/// that will never be incremented.
32-
///
33-
/// For used/called functions, the coverageinfo was already added to the
34-
/// `function_coverage_map` (keyed by function `Instance`) during codegen.
35-
/// But in this case, since the unused function was _not_ previously
36-
/// codegenned, collect the coverage `CodeRegion`s from the MIR and add
37-
/// them. The first `CodeRegion` is used to add a single counter, with the
38-
/// same counter ID used in the injected `instrprof.increment` intrinsic
39-
/// call. Since the function is never called, all other `CodeRegion`s can be
40-
/// added as `unreachable_region`s.
41-
fn define_unused_fn(&self, _def_id: DefId) {
42-
unimplemented!();
43-
}
44-
}

‎compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::llvm;
44

55
use llvm::coverageinfo::CounterMappingRegion;
66
use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression};
7-
use rustc_codegen_ssa::traits::{ConstMethods,CoverageInfoMethods};
7+
use rustc_codegen_ssa::traits::ConstMethods;
88
use rustc_data_structures::fx::FxIndexSet;
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::def_id::DefId;

‎compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use libc::c_uint;
88
use llvm::coverageinfo::CounterMappingRegion;
99
use rustc_codegen_ssa::coverageinfo::map::{CounterExpression, FunctionCoverage};
1010
use rustc_codegen_ssa::traits::{
11-
BaseTypeMethods, BuilderMethods, ConstMethods, CoverageInfoBuilderMethods, CoverageInfoMethods,
12-
MiscMethods,StaticMethods,
11+
BaseTypeMethods, BuilderMethods, ConstMethods, CoverageInfoBuilderMethods, MiscMethods,
12+
StaticMethods,
1313
};
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_hir as hir;
@@ -54,11 +54,17 @@ impl<'ll, 'tcx> CrateCoverageContext<'ll, 'tcx> {
5454
}
5555
}
5656

57-
impl<'ll, 'tcx> CoverageInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
58-
fn coverageinfo_finalize(&self) {
57+
// These methods used to be part of trait `CoverageInfoMethods`, which no longer
58+
// exists after most coverage code was moved out of SSA.
59+
impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
60+
pub(crate) fn coverageinfo_finalize(&self) {
5961
mapgen::finalize(self)
6062
}
6163

64+
/// For LLVM codegen, returns a function-specific `Value` for a global
65+
/// string, to hold the function name passed to LLVM intrinsic
66+
/// `instrprof.increment()`. The `Value` is only created once per instance.
67+
/// Multiple invocations with the same instance return the same `Value`.
6268
fn get_pgo_func_name_var(&self, instance: Instance<'tcx>) -> &'ll llvm::Value {
6369
if let Some(coverage_context) = self.coverage_context() {
6470
debug!("getting pgo_func_name_var for instance={:?}", instance);

‎compiler/rustc_codegen_ssa/src/traits/coverageinfo.rs‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
use super::BackendTypes;
2-
use rustc_hir::def_id::DefId;
32
use rustc_middle::mir::Coverage;
43
use rustc_middle::ty::Instance;
54

6-
pub trait CoverageInfoMethods<'tcx>: BackendTypes {
7-
fn coverageinfo_finalize(&self);
8-
9-
/// Codegen a small function that will never be called, with one counter
10-
/// that will never be incremented, that gives LLVM coverage tools a
11-
/// function definition it needs in order to resolve coverage map references
12-
/// to unused functions. This is necessary so unused functions will appear
13-
/// as uncovered (coverage execution count `0`) in LLVM coverage reports.
14-
fn define_unused_fn(&self, def_id: DefId);
15-
16-
/// For LLVM codegen, returns a function-specific `Value` for a global
17-
/// string, to hold the function name passed to LLVM intrinsic
18-
/// `instrprof.increment()`. The `Value` is only created once per instance.
19-
/// Multiple invocations with the same instance return the same `Value`.
20-
fn get_pgo_func_name_var(&self, instance: Instance<'tcx>) -> Self::Value;
21-
}
22-
235
pub trait CoverageInfoBuilderMethods<'tcx>: BackendTypes {
246
/// Handle the MIR coverage info in a backend-specific way.
257
///

‎compiler/rustc_codegen_ssa/src/traits/mod.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub use self::asm::{AsmBuilderMethods, AsmMethods, GlobalAsmOperandRef, InlineAs
3333
pub use self::backend::{Backend, BackendTypes, CodegenBackend, ExtraBackendMethods};
3434
pub use self::builder::{BuilderMethods, OverflowOp};
3535
pub use self::consts::ConstMethods;
36-
pub use self::coverageinfo::{CoverageInfoBuilderMethods,CoverageInfoMethods};
36+
pub use self::coverageinfo::CoverageInfoBuilderMethods;
3737
pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
3838
pub use self::declare::PreDefineMethods;
3939
pub use self::intrinsic::IntrinsicCallMethods;
@@ -59,7 +59,6 @@ pub trait CodegenMethods<'tcx>:
5959
+ MiscMethods<'tcx>
6060
+ ConstMethods<'tcx>
6161
+ StaticMethods
62-
+ CoverageInfoMethods<'tcx>
6362
+ DebugInfoMethods<'tcx>
6463
+ AsmMethods<'tcx>
6564
+ PreDefineMethods<'tcx>
@@ -75,7 +74,6 @@ impl<'tcx, T> CodegenMethods<'tcx> for T where
7574
+ MiscMethods<'tcx>
7675
+ ConstMethods<'tcx>
7776
+ StaticMethods
78-
+ CoverageInfoMethods<'tcx>
7977
+ DebugInfoMethods<'tcx>
8078
+ AsmMethods<'tcx>
8179
+ PreDefineMethods<'tcx>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /