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 5dac6b3

Browse files
committed
Auto merge of #113370 - compiler-errors:rollup-8gvyy8e, r=compiler-errors
Rollup of 8 pull requests Successful merges: - #113010 (rust-installer & rls: remove exclusion from rustfmt & tidy ) - #113317 ( -Ztrait-solver=next: stop depending on old solver) - #113319 (`TypeParameterDefinition` always require a `DefId`) - #113320 (Add some extra information to opaque type cycle errors) - #113321 (Move `ty::ConstKind` to `rustc_type_ir`) - #113337 (Winnow specialized impls during selection in new solver) - #113355 (Move most coverage code out of `rustc_codegen_ssa`) - #113356 (Add support for NetBSD/riscv64 aka. riscv64gc-unknown-netbsd.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e4cd161 + 560136f commit 5dac6b3

File tree

84 files changed

+2035
-1459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2035
-1459
lines changed

‎compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,6 @@ fn codegen_stmt<'tcx>(
706706
let times = fx
707707
.monomorphize(times)
708708
.eval(fx.tcx, ParamEnv::reveal_all())
709-
.kind()
710709
.try_to_bits(fx.tcx.data_layout.pointer_size)
711710
.unwrap();
712711
if operand.layout().size.bytes() == 0 {
Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,11 @@
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-
};
1+
use rustc_codegen_ssa::traits::CoverageInfoBuilderMethods;
2+
use rustc_middle::mir::Coverage;
113
use rustc_middle::ty::Instance;
124

135
use crate::builder::Builder;
14-
use crate::context::CodegenCx;
156

167
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 {
8+
fn add_coverage(&mut self, _instance: Instance<'tcx>, _coverage: &Coverage) {
369
// 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!();
6810
}
6911
}
File renamed without changes.

‎compiler/rustc_codegen_ssa/src/coverageinfo/map.rs renamed to ‎compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub use super::ffi::*;
22

33
use rustc_index::{IndexSlice, IndexVec};
4+
use rustc_middle::bug;
45
use rustc_middle::mir::coverage::{
56
CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId,
67
InjectedExpressionIndex, MappedExpressionIndex, Op,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::common::CodegenCx;
22
use crate::coverageinfo;
3+
use crate::coverageinfo::map_data::{Counter, CounterExpression};
34
use crate::llvm;
45

56
use llvm::coverageinfo::CounterMappingRegion;
6-
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: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,33 @@ use crate::llvm;
33
use crate::abi::Abi;
44
use crate::builder::Builder;
55
use crate::common::CodegenCx;
6+
use crate::coverageinfo::map_data::{CounterExpression, FunctionCoverage};
67

78
use libc::c_uint;
89
use llvm::coverageinfo::CounterMappingRegion;
9-
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;
1616
use rustc_hir::def_id::DefId;
1717
use rustc_llvm::RustString;
1818
use rustc_middle::bug;
1919
use rustc_middle::mir::coverage::{
20-
CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId, Op,
20+
CodeRegion, CounterValueReference, CoverageKind,ExpressionOperandId, InjectedExpressionId, Op,
2121
};
22+
use rustc_middle::mir::Coverage;
2223
use rustc_middle::ty;
23-
use rustc_middle::ty::layout::FnAbiOf;
24+
use rustc_middle::ty::layout::{FnAbiOf,HasTyCtxt};
2425
use rustc_middle::ty::subst::InternalSubsts;
2526
use rustc_middle::ty::Instance;
2627

2728
use std::cell::RefCell;
2829
use std::ffi::CString;
2930

31+
mod ffi;
32+
pub(crate) mod map_data;
3033
pub mod mapgen;
3134

3235
const UNUSED_FUNCTION_COUNTER_ID: CounterValueReference = CounterValueReference::START;
@@ -53,11 +56,17 @@ impl<'ll, 'tcx> CrateCoverageContext<'ll, 'tcx> {
5356
}
5457
}
5558

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

66+
/// For LLVM codegen, returns a function-specific `Value` for a global
67+
/// string, to hold the function name passed to LLVM intrinsic
68+
/// `instrprof.increment()`. The `Value` is only created once per instance.
69+
/// Multiple invocations with the same instance return the same `Value`.
6170
fn get_pgo_func_name_var(&self, instance: Instance<'tcx>) -> &'ll llvm::Value {
6271
if let Some(coverage_context) = self.coverage_context() {
6372
debug!("getting pgo_func_name_var for instance={:?}", instance);
@@ -94,6 +103,54 @@ impl<'ll, 'tcx> CoverageInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
94103
}
95104

96105
impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
106+
fn add_coverage(&mut self, instance: Instance<'tcx>, coverage: &Coverage) {
107+
let bx = self;
108+
109+
let Coverage { kind, code_region } = coverage.clone();
110+
match kind {
111+
CoverageKind::Counter { function_source_hash, id } => {
112+
if bx.set_function_source_hash(instance, function_source_hash) {
113+
// If `set_function_source_hash()` returned true, the coverage map is enabled,
114+
// so continue adding the counter.
115+
if let Some(code_region) = code_region {
116+
// Note: Some counters do not have code regions, but may still be referenced
117+
// from expressions. In that case, don't add the counter to the coverage map,
118+
// but do inject the counter intrinsic.
119+
bx.add_coverage_counter(instance, id, code_region);
120+
}
121+
122+
let coverageinfo = bx.tcx().coverageinfo(instance.def);
123+
124+
let fn_name = bx.get_pgo_func_name_var(instance);
125+
let hash = bx.const_u64(function_source_hash);
126+
let num_counters = bx.const_u32(coverageinfo.num_counters);
127+
let index = bx.const_u32(id.zero_based_index());
128+
debug!(
129+
"codegen intrinsic instrprof.increment(fn_name={:?}, hash={:?}, num_counters={:?}, index={:?})",
130+
fn_name, hash, num_counters, index,
131+
);
132+
bx.instrprof_increment(fn_name, hash, num_counters, index);
133+
}
134+
}
135+
CoverageKind::Expression { id, lhs, op, rhs } => {
136+
bx.add_coverage_counter_expression(instance, id, lhs, op, rhs, code_region);
137+
}
138+
CoverageKind::Unreachable => {
139+
bx.add_coverage_unreachable(
140+
instance,
141+
code_region.expect("unreachable regions always have code regions"),
142+
);
143+
}
144+
}
145+
}
146+
}
147+
148+
// These methods used to be part of trait `CoverageInfoBuilderMethods`, but
149+
// after moving most coverage code out of SSA they are now just ordinary methods.
150+
impl<'tcx> Builder<'_, '_, 'tcx> {
151+
/// Returns true if the function source hash was added to the coverage map (even if it had
152+
/// already been added, for this instance). Returns false *only* if `-C instrument-coverage` is
153+
/// not enabled (a coverage map is not being generated).
97154
fn set_function_source_hash(
98155
&mut self,
99156
instance: Instance<'tcx>,
@@ -115,6 +172,8 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
115172
}
116173
}
117174

175+
/// Returns true if the counter was added to the coverage map; false if `-C instrument-coverage`
176+
/// is not enabled (a coverage map is not being generated).
118177
fn add_coverage_counter(
119178
&mut self,
120179
instance: Instance<'tcx>,
@@ -137,6 +196,8 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
137196
}
138197
}
139198

199+
/// Returns true if the expression was added to the coverage map; false if
200+
/// `-C instrument-coverage` is not enabled (a coverage map is not being generated).
140201
fn add_coverage_counter_expression(
141202
&mut self,
142203
instance: Instance<'tcx>,
@@ -163,6 +224,8 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
163224
}
164225
}
165226

227+
/// Returns true if the region was added to the coverage map; false if `-C instrument-coverage`
228+
/// is not enabled (a coverage map is not being generated).
166229
fn add_coverage_unreachable(&mut self, instance: Instance<'tcx>, region: CodeRegion) -> bool {
167230
if let Some(coverage_context) = self.coverage_context() {
168231
debug!(

‎compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(non_camel_case_types)]
22
#![allow(non_upper_case_globals)]
33

4-
use rustc_codegen_ssa::coverageinfo::map as coverage_map;
4+
use crate::coverageinfo::map_data as coverage_map;
55

66
use super::debuginfo::{
77
DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,

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

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub mod back;
4848
pub mod base;
4949
pub mod codegen_attrs;
5050
pub mod common;
51-
pub mod coverageinfo;
5251
pub mod debuginfo;
5352
pub mod errors;
5453
pub mod glue;
Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,20 @@
11
use crate::traits::*;
22

3-
use rustc_middle::mir::coverage::*;
43
use rustc_middle::mir::Coverage;
54
use rustc_middle::mir::SourceScope;
65

76
use super::FunctionCx;
87

98
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10-
pub fn codegen_coverage(&self, bx: &mut Bx, coverage: Coverage, scope: SourceScope) {
9+
pub fn codegen_coverage(&self, bx: &mut Bx, coverage: &Coverage, scope: SourceScope) {
1110
// Determine the instance that coverage data was originally generated for.
1211
let instance = if let Some(inlined) = scope.inlined_instance(&self.mir.source_scopes) {
1312
self.monomorphize(inlined)
1413
} else {
1514
self.instance
1615
};
1716

18-
let Coverage { kind, code_region } = coverage;
19-
match kind {
20-
CoverageKind::Counter { function_source_hash, id } => {
21-
if bx.set_function_source_hash(instance, function_source_hash) {
22-
// If `set_function_source_hash()` returned true, the coverage map is enabled,
23-
// so continue adding the counter.
24-
if let Some(code_region) = code_region {
25-
// Note: Some counters do not have code regions, but may still be referenced
26-
// from expressions. In that case, don't add the counter to the coverage map,
27-
// but do inject the counter intrinsic.
28-
bx.add_coverage_counter(instance, id, code_region);
29-
}
30-
31-
let coverageinfo = bx.tcx().coverageinfo(instance.def);
32-
33-
let fn_name = bx.get_pgo_func_name_var(instance);
34-
let hash = bx.const_u64(function_source_hash);
35-
let num_counters = bx.const_u32(coverageinfo.num_counters);
36-
let index = bx.const_u32(id.zero_based_index());
37-
debug!(
38-
"codegen intrinsic instrprof.increment(fn_name={:?}, hash={:?}, num_counters={:?}, index={:?})",
39-
fn_name, hash, num_counters, index,
40-
);
41-
bx.instrprof_increment(fn_name, hash, num_counters, index);
42-
}
43-
}
44-
CoverageKind::Expression { id, lhs, op, rhs } => {
45-
bx.add_coverage_counter_expression(instance, id, lhs, op, rhs, code_region);
46-
}
47-
CoverageKind::Unreachable => {
48-
bx.add_coverage_unreachable(
49-
instance,
50-
code_region.expect("unreachable regions always have code regions"),
51-
);
52-
}
53-
}
17+
// Handle the coverage info in a backend-specific way.
18+
bx.add_coverage(instance, coverage);
5419
}
5520
}

0 commit comments

Comments
(0)

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