Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
68ce659
Promote powerpc64le-unknown-linux-musl to tier 2 with host tools
Gelbpunkt Nov 18, 2024
3e3ee4c
Fix markdown link
Gelbpunkt Dec 3, 2024
8bb0fd5
Update src/doc/rustc/src/platform-support/powerpc64le-unknown-linux-m…
Gelbpunkt Dec 3, 2024
286de9f
Move dist-powerpc64le-linux to job-linux-4c-largedisk
Gelbpunkt Dec 9, 2024
2fd4438
clean up `emit_access_facts`
lqd Dec 11, 2024
9d8f58a
clean up `emit_drop_facts`
lqd Dec 11, 2024
afbe101
clean up `translate_outlives_facts`
lqd Dec 11, 2024
5486857
use let else more consistently in fact generation
lqd Dec 11, 2024
1740a5f
simplify `emit_access_facts` and fact generation
lqd Dec 11, 2024
2024c5d
simplify `emit_outlives_facts`
lqd Dec 11, 2024
7ad1f5b
refactor `type_check` module slightly
lqd Dec 11, 2024
8562497
improve consistency within fact gen
lqd Dec 11, 2024
ab6ad1a
Add a range argument to vec.extract_if
the8472 Nov 20, 2024
03f1b73
remove bounds from vec and linkedlist ExtractIf
the8472 Nov 20, 2024
fe52150
update uses of extract_if in the compiler
the8472 Nov 20, 2024
44790c4
remove obsolete comment and pub(super) visibility
the8472 Nov 20, 2024
fe412af
coverage: Use `is_eligible_for_coverage` to filter unused functions
Zalathar Dec 14, 2024
154fae1
coverage: Build the global file table on the fly
Zalathar Dec 13, 2024
252276a
coverage: Pull expression conversion out of `map_data.rs`
Zalathar Dec 12, 2024
527f812
coverage: Pull region conversion out of `map_data.rs`
Zalathar Dec 12, 2024
d34c365
coverage: Pull function source hash out of `map_data.rs`
Zalathar Dec 14, 2024
541d4e8
coverage: Track used functions in a set instead of a map
Zalathar Dec 14, 2024
a7f61ca
Regression test for RPIT inheriting lifetime
rmehri01 Dec 17, 2024
13e8313
bootstrap: use specific-purpose ui test path
jieyouxu Dec 17, 2024
c482b31
Fix typo in uint_macros.rs
hkBst Dec 17, 2024
938742e
Rollup merge of #133265 - the8472:extract-if-ranges, r=cuviper
matthiaskrgr Dec 17, 2024
ca5dfa7
Rollup merge of #133801 - Gelbpunkt:powerpc64le-unknown-linux-musl-ti…
matthiaskrgr Dec 17, 2024
e696f5c
Rollup merge of #134323 - Zalathar:dismantle-map-data, r=jieyouxu
matthiaskrgr Dec 17, 2024
264566f
Rollup merge of #134378 - lqd:polonius-next-episode-2, r=jackh726
matthiaskrgr Dec 17, 2024
53635e5
Rollup merge of #134408 - rmehri01:rpit-inherits-lifetime, r=compiler…
matthiaskrgr Dec 17, 2024
4b905c8
Rollup merge of #134423 - jieyouxu:bootstrap-test-valid, r=onur-ozkan
matthiaskrgr Dec 17, 2024
3b0df8c
Rollup merge of #134426 - hkBst:patch-3, r=lqd
matthiaskrgr Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
coverage: Pull expression conversion out of map_data.rs
  • Loading branch information
Zalathar committed Dec 17, 2024
commit 252276a53d05f49523e6eac992b5f49e9815db0c
32 changes: 1 addition & 31 deletions compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use rustc_data_structures::captures::Captures;
use rustc_middle::mir::coverage::{
CovTerm, CoverageIdsInfo, Expression, FunctionCoverageInfo, Mapping, MappingKind, Op,
SourceRegion,
CovTerm, CoverageIdsInfo, FunctionCoverageInfo, Mapping, MappingKind, SourceRegion,
};

use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};

pub(crate) struct FunctionCoverage<'tcx> {
pub(crate) function_coverage_info: &'tcx FunctionCoverageInfo,
/// If `None`, the corresponding function is unused.
Expand Down Expand Up @@ -35,28 +31,6 @@ impl<'tcx> FunctionCoverage<'tcx> {
if self.is_used() { self.function_coverage_info.function_source_hash } else { 0 }
}

/// Convert this function's coverage expression data into a form that can be
/// passed through FFI to LLVM.
pub(crate) fn counter_expressions(
&self,
) -> impl Iterator<Item = CounterExpression> + ExactSizeIterator + Captures<'_> {
// We know that LLVM will optimize out any unused expressions before
// producing the final coverage map, so there's no need to do the same
// thing on the Rust side unless we're confident we can do much better.
// (See `CounterExpressionsMinimizer` in `CoverageMappingWriter.cpp`.)

self.function_coverage_info.expressions.iter().map(move |&Expression { lhs, op, rhs }| {
CounterExpression {
lhs: self.counter_for_term(lhs),
kind: match op {
Op::Add => ExprKind::Add,
Op::Subtract => ExprKind::Subtract,
},
rhs: self.counter_for_term(rhs),
}
})
}

/// Converts this function's coverage mappings into an intermediate form
/// that will be used by `mapgen` when preparing for FFI.
pub(crate) fn counter_regions(
Expand All @@ -70,10 +44,6 @@ impl<'tcx> FunctionCoverage<'tcx> {
})
}

fn counter_for_term(&self, term: CovTerm) -> Counter {
if self.is_zero_term(term) { Counter::ZERO } else { Counter::from_term(term) }
}

fn is_zero_term(&self, term: CovTerm) -> bool {
match self.ids_info {
Some(ids_info) => ids_info.is_zero_term(term),
Expand Down
45 changes: 43 additions & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use rustc_codegen_ssa::traits::{
BaseTypeCodegenMethods, ConstCodegenMethods, StaticCodegenMethods,
};
use rustc_middle::bug;
use rustc_middle::mir::coverage::MappingKind;
use rustc_middle::mir::coverage::{
CoverageIdsInfo, Expression, FunctionCoverageInfo, MappingKind, Op,
};
use rustc_middle::ty::{Instance, TyCtxt};
use rustc_target::spec::HasTargetSpec;
use tracing::debug;
Expand Down Expand Up @@ -49,12 +51,17 @@ pub(crate) fn prepare_covfun_record<'tcx>(
instance: Instance<'tcx>,
function_coverage: &FunctionCoverage<'tcx>,
) -> Option<CovfunRecord<'tcx>> {
let fn_cov_info = tcx.instance_mir(instance.def).function_coverage_info.as_deref()?;
let ids_info = tcx.coverage_ids_info(instance.def);

let expressions = prepare_expressions(fn_cov_info, ids_info, function_coverage.is_used());

let mut covfun = CovfunRecord {
mangled_function_name: tcx.symbol_name(instance).name,
source_hash: function_coverage.source_hash(),
is_used: function_coverage.is_used(),
virtual_file_mapping: VirtualFileMapping::default(),
expressions: function_coverage.counter_expressions().collect::<Vec<_>>(),
expressions,
regions: ffi::Regions::default(),
};

Expand All @@ -72,6 +79,40 @@ pub(crate) fn prepare_covfun_record<'tcx>(
Some(covfun)
}

/// Convert the function's coverage-counter expressions into a form suitable for FFI.
fn prepare_expressions(
fn_cov_info: &FunctionCoverageInfo,
ids_info: &CoverageIdsInfo,
is_used: bool,
) -> Vec<ffi::CounterExpression> {
// If any counters or expressions were removed by MIR opts, replace their
// terms with zero.
let counter_for_term = |term| {
if !is_used || ids_info.is_zero_term(term) {
ffi::Counter::ZERO
} else {
ffi::Counter::from_term(term)
}
};

// We know that LLVM will optimize out any unused expressions before
// producing the final coverage map, so there's no need to do the same
// thing on the Rust side unless we're confident we can do much better.
// (See `CounterExpressionsMinimizer` in `CoverageMappingWriter.cpp`.)
fn_cov_info
.expressions
.iter()
.map(move |&Expression { lhs, op, rhs }| ffi::CounterExpression {
lhs: counter_for_term(lhs),
kind: match op {
Op::Add => ffi::ExprKind::Add,
Op::Subtract => ffi::ExprKind::Subtract,
},
rhs: counter_for_term(rhs),
})
.collect::<Vec<_>>()
}

/// Populates the mapping region tables in the current function's covfun record.
fn fill_region_tables<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down