Consistently use dominates instead of is_dominated_by

There is a number of APIs that answer dominance queries. Previously they
were named either "dominates" or "is_dominated_by". Consistently use the
"dominates" form.

No functional changes.
This commit is contained in:
Tomasz Miąsko 2023-01-20 00:00:00 +00:00
parent b22aa57fd5
commit 955e7fbb16
5 changed files with 18 additions and 18 deletions

View File

@ -289,7 +289,7 @@ impl<Node: Idx> Dominators<Node> {
Iter { dominators: self, node: Some(node) } Iter { dominators: self, node: Some(node) }
} }
pub fn is_dominated_by(&self, node: Node, dom: Node) -> bool { pub fn dominates(&self, dom: Node, node: Node) -> bool {
// FIXME -- could be optimized by using post-order-rank // FIXME -- could be optimized by using post-order-rank
self.dominators(node).any(|n| n == dom) self.dominators(node).any(|n| n == dom)
} }

View File

@ -3049,7 +3049,7 @@ impl Location {
if self.block == other.block { if self.block == other.block {
self.statement_index <= other.statement_index self.statement_index <= other.statement_index
} else { } else {
dominators.is_dominated_by(other.block, self.block) dominators.dominates(self.block, other.block)
} }
} }
} }

View File

@ -520,7 +520,7 @@ impl<'a> BcbCounters<'a> {
let mut found_loop_exit = false; let mut found_loop_exit = false;
for &branch in branches.iter() { for &branch in branches.iter() {
if backedge_from_bcbs.iter().any(|&backedge_from_bcb| { if backedge_from_bcbs.iter().any(|&backedge_from_bcb| {
self.bcb_is_dominated_by(backedge_from_bcb, branch.target_bcb) self.bcb_dominates(branch.target_bcb, backedge_from_bcb)
}) { }) {
if let Some(reloop_branch) = some_reloop_branch { if let Some(reloop_branch) = some_reloop_branch {
if reloop_branch.counter(&self.basic_coverage_blocks).is_none() { if reloop_branch.counter(&self.basic_coverage_blocks).is_none() {
@ -603,8 +603,8 @@ impl<'a> BcbCounters<'a> {
} }
#[inline] #[inline]
fn bcb_is_dominated_by(&self, node: BasicCoverageBlock, dom: BasicCoverageBlock) -> bool { fn bcb_dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool {
self.basic_coverage_blocks.is_dominated_by(node, dom) self.basic_coverage_blocks.dominates(dom, node)
} }
#[inline] #[inline]

View File

@ -209,8 +209,8 @@ impl CoverageGraph {
} }
#[inline(always)] #[inline(always)]
pub fn is_dominated_by(&self, node: BasicCoverageBlock, dom: BasicCoverageBlock) -> bool { pub fn dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool {
self.dominators.as_ref().unwrap().is_dominated_by(node, dom) self.dominators.as_ref().unwrap().dominates(dom, node)
} }
#[inline(always)] #[inline(always)]
@ -312,7 +312,7 @@ rustc_index::newtype_index! {
/// to the BCB's primary counter or expression). /// to the BCB's primary counter or expression).
/// ///
/// The BCB CFG is critical to simplifying the coverage analysis by ensuring graph path-based /// The BCB CFG is critical to simplifying the coverage analysis by ensuring graph path-based
/// queries (`is_dominated_by()`, `predecessors`, `successors`, etc.) have branch (control flow) /// queries (`dominates()`, `predecessors`, `successors`, etc.) have branch (control flow)
/// significance. /// significance.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(super) struct BasicCoverageBlockData { pub(super) struct BasicCoverageBlockData {
@ -594,7 +594,7 @@ impl TraverseCoverageGraphWithLoops {
// branching block would have given an `Expression` (or vice versa). // branching block would have given an `Expression` (or vice versa).
let (some_successor_to_add, some_loop_header) = let (some_successor_to_add, some_loop_header) =
if let Some((_, loop_header)) = context.loop_backedges { if let Some((_, loop_header)) = context.loop_backedges {
if basic_coverage_blocks.is_dominated_by(successor, loop_header) { if basic_coverage_blocks.dominates(loop_header, successor) {
(Some(successor), Some(loop_header)) (Some(successor), Some(loop_header))
} else { } else {
(None, None) (None, None)
@ -666,15 +666,15 @@ pub(super) fn find_loop_backedges(
// //
// The overall complexity appears to be comparable to many other MIR transform algorithms, and I // The overall complexity appears to be comparable to many other MIR transform algorithms, and I
// don't expect that this function is creating a performance hot spot, but if this becomes an // don't expect that this function is creating a performance hot spot, but if this becomes an
// issue, there may be ways to optimize the `is_dominated_by` algorithm (as indicated by an // issue, there may be ways to optimize the `dominates` algorithm (as indicated by an
// existing `FIXME` comment in that code), or possibly ways to optimize it's usage here, perhaps // existing `FIXME` comment in that code), or possibly ways to optimize it's usage here, perhaps
// by keeping track of results for visited `BasicCoverageBlock`s if they can be used to short // by keeping track of results for visited `BasicCoverageBlock`s if they can be used to short
// circuit downstream `is_dominated_by` checks. // circuit downstream `dominates` checks.
// //
// For now, that kind of optimization seems unnecessarily complicated. // For now, that kind of optimization seems unnecessarily complicated.
for (bcb, _) in basic_coverage_blocks.iter_enumerated() { for (bcb, _) in basic_coverage_blocks.iter_enumerated() {
for &successor in &basic_coverage_blocks.successors[bcb] { for &successor in &basic_coverage_blocks.successors[bcb] {
if basic_coverage_blocks.is_dominated_by(bcb, successor) { if basic_coverage_blocks.dominates(successor, bcb) {
let loop_header = successor; let loop_header = successor;
let backedge_from_bcb = bcb; let backedge_from_bcb = bcb;
debug!( debug!(

View File

@ -63,7 +63,7 @@ impl CoverageStatement {
/// Note: A `CoverageStatement` merged into another CoverageSpan may come from a `BasicBlock` that /// Note: A `CoverageStatement` merged into another CoverageSpan may come from a `BasicBlock` that
/// is not part of the `CoverageSpan` bcb if the statement was included because it's `Span` matches /// is not part of the `CoverageSpan` bcb if the statement was included because it's `Span` matches
/// or is subsumed by the `Span` associated with this `CoverageSpan`, and it's `BasicBlock` /// or is subsumed by the `Span` associated with this `CoverageSpan`, and it's `BasicBlock`
/// `is_dominated_by()` the `BasicBlock`s in this `CoverageSpan`. /// `dominates()` the `BasicBlock`s in this `CoverageSpan`.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(super) struct CoverageSpan { pub(super) struct CoverageSpan {
pub span: Span, pub span: Span,
@ -705,12 +705,12 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
fn hold_pending_dups_unless_dominated(&mut self) { fn hold_pending_dups_unless_dominated(&mut self) {
// Equal coverage spans are ordered by dominators before dominated (if any), so it should be // Equal coverage spans are ordered by dominators before dominated (if any), so it should be
// impossible for `curr` to dominate any previous `CoverageSpan`. // impossible for `curr` to dominate any previous `CoverageSpan`.
debug_assert!(!self.span_bcb_is_dominated_by(self.prev(), self.curr())); debug_assert!(!self.span_bcb_dominates(self.curr(), self.prev()));
let initial_pending_count = self.pending_dups.len(); let initial_pending_count = self.pending_dups.len();
if initial_pending_count > 0 { if initial_pending_count > 0 {
let mut pending_dups = self.pending_dups.split_off(0); let mut pending_dups = self.pending_dups.split_off(0);
pending_dups.retain(|dup| !self.span_bcb_is_dominated_by(self.curr(), dup)); pending_dups.retain(|dup| !self.span_bcb_dominates(dup, self.curr()));
self.pending_dups.append(&mut pending_dups); self.pending_dups.append(&mut pending_dups);
if self.pending_dups.len() < initial_pending_count { if self.pending_dups.len() < initial_pending_count {
debug!( debug!(
@ -721,7 +721,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
} }
} }
if self.span_bcb_is_dominated_by(self.curr(), self.prev()) { if self.span_bcb_dominates(self.prev(), self.curr()) {
debug!( debug!(
" different bcbs but SAME spans, and prev dominates curr. Discard prev={:?}", " different bcbs but SAME spans, and prev dominates curr. Discard prev={:?}",
self.prev() self.prev()
@ -787,8 +787,8 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
} }
} }
fn span_bcb_is_dominated_by(&self, covspan: &CoverageSpan, dom_covspan: &CoverageSpan) -> bool { fn span_bcb_dominates(&self, dom_covspan: &CoverageSpan, covspan: &CoverageSpan) -> bool {
self.basic_coverage_blocks.is_dominated_by(covspan.bcb, dom_covspan.bcb) self.basic_coverage_blocks.dominates(dom_covspan.bcb, covspan.bcb)
} }
} }