Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 11 additions & 17 deletions cranelift/codegen/src/egraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use crate::alias_analysis::{AliasAnalysis, LastStores};
use crate::ctxhash::{CtxEq, CtxHash, CtxHashMap};
use crate::cursor::{Cursor, CursorPosition, FuncCursor};
use crate::dominator_tree::DominatorTree;
use crate::egraph::domtree::DomTreeWithChildren;
use crate::dominator_tree::{DominatorTree, DominatorTreePreorder};
use crate::egraph::elaborate::Elaborator;
use crate::fx::FxHashSet;
use crate::inst_predicates::{is_mergeable_for_egraph, is_pure_for_egraph};
Expand All @@ -22,7 +21,6 @@ use smallvec::SmallVec;
use std::hash::Hasher;

mod cost;
mod domtree;
mod elaborate;

/// Pass over a Function that does the whole aegraph thing.
Expand All @@ -46,14 +44,12 @@ mod elaborate;
pub struct EgraphPass<'a> {
/// The function we're operating on.
func: &'a mut Function,
/// Dominator tree, used for elaboration pass.
domtree: &'a DominatorTree,
/// Dominator tree for the CFG, used to visit blocks in pre-order
/// so we see value definitions before their uses, and also used for
/// O(1) dominance checks.
domtree: DominatorTreePreorder,
/// Alias analysis, used during optimization.
alias_analysis: &'a mut AliasAnalysis<'a>,
/// "Domtree with children": like `domtree`, but with an explicit
/// list of children, complementing the parent pointers stored
/// in `domtree`.
domtree_children: DomTreeWithChildren,
/// Loop analysis results, used for built-in LICM during
/// elaboration.
loop_analysis: &'a LoopAnalysis,
Expand Down Expand Up @@ -401,16 +397,16 @@ impl<'a> EgraphPass<'a> {
/// Create a new EgraphPass.
pub fn new(
func: &'a mut Function,
domtree: &'a DominatorTree,
raw_domtree: &'a DominatorTree,
loop_analysis: &'a LoopAnalysis,
alias_analysis: &'a mut AliasAnalysis<'a>,
) -> Self {
let num_values = func.dfg.num_values();
let domtree_children = DomTreeWithChildren::new(func, domtree);
let mut domtree = DominatorTreePreorder::new();
domtree.compute(raw_domtree, &func.layout);
Self {
func,
domtree,
domtree_children,
loop_analysis,
alias_analysis,
stats: Stats::default(),
Expand Down Expand Up @@ -497,7 +493,7 @@ impl<'a> EgraphPass<'a> {

// In domtree preorder, visit blocks. (TODO: factor out an
// iterator from this and elaborator.)
let root = self.domtree_children.root();
let root = cursor.layout().entry_block().unwrap();
enum StackEntry {
Visit(Block),
Pop,
Expand All @@ -509,8 +505,7 @@ impl<'a> EgraphPass<'a> {
// We popped this block; push children
// immediately, then process this block.
block_stack.push(StackEntry::Pop);
block_stack
.extend(self.domtree_children.children(block).map(StackEntry::Visit));
block_stack.extend(self.domtree.children(block).map(StackEntry::Visit));
effectful_gvn_map.increment_depth();

trace!("Processing block {}", block);
Expand Down Expand Up @@ -615,8 +610,7 @@ impl<'a> EgraphPass<'a> {
fn elaborate(&mut self) {
let mut elaborator = Elaborator::new(
self.func,
self.domtree,
&self.domtree_children,
&self.domtree,
self.loop_analysis,
&mut self.remat_values,
&mut self.stats,
Expand Down
74 changes: 0 additions & 74 deletions cranelift/codegen/src/egraph/domtree.rs

This file was deleted.

23 changes: 7 additions & 16 deletions cranelift/codegen/src/egraph/elaborate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
//! in CFG nodes.

use super::cost::Cost;
use super::domtree::DomTreeWithChildren;
use super::Stats;
use crate::dominator_tree::DominatorTree;
use crate::dominator_tree::DominatorTreePreorder;
use crate::fx::{FxHashMap, FxHashSet};
use crate::hash_map::Entry as HashEntry;
use crate::inst_predicates::is_pure_for_egraph;
Expand All @@ -18,8 +17,7 @@ use smallvec::{smallvec, SmallVec};

pub(crate) struct Elaborator<'a> {
func: &'a mut Function,
domtree: &'a DominatorTree,
domtree_children: &'a DomTreeWithChildren,
domtree: &'a DominatorTreePreorder,
loop_analysis: &'a LoopAnalysis,
/// Map from Value that is produced by a pure Inst (and was thus
/// not in the side-effecting skeleton) to the value produced by
Expand Down Expand Up @@ -137,8 +135,7 @@ enum BlockStackEntry {
impl<'a> Elaborator<'a> {
pub(crate) fn new(
func: &'a mut Function,
domtree: &'a DominatorTree,
domtree_children: &'a DomTreeWithChildren,
domtree: &'a DominatorTreePreorder,
loop_analysis: &'a LoopAnalysis,
remat_values: &'a FxHashSet<Value>,
stats: &'a mut Stats,
Expand All @@ -150,7 +147,6 @@ impl<'a> Elaborator<'a> {
Self {
func,
domtree,
domtree_children,
loop_analysis,
value_to_elaborated_value: ScopedHashMap::with_capacity(num_values),
value_to_best_value,
Expand Down Expand Up @@ -557,11 +553,7 @@ impl<'a> Elaborator<'a> {
let data = &self.loop_stack[loop_hoist_level];
// `data.hoist_block` should dominate `before`'s block.
let before_block = self.func.layout.inst_block(before).unwrap();
debug_assert!(self.domtree.dominates(
data.hoist_block,
before_block,
&self.func.layout
));
debug_assert!(self.domtree.dominates(data.hoist_block, before_block));
// Determine the instruction at which we
// insert in `data.hoist_block`.
let before = self.func.layout.last_inst(data.hoist_block).unwrap();
Expand Down Expand Up @@ -762,10 +754,9 @@ impl<'a> Elaborator<'a> {
}
}

fn elaborate_domtree(&mut self, domtree: &DomTreeWithChildren) {
let root = domtree.root();
fn elaborate_domtree(&mut self, domtree: &DominatorTreePreorder) {
self.block_stack.push(BlockStackEntry::Elaborate {
block: root,
block: self.func.layout.entry_block().unwrap(),
idom: None,
});

Expand Down Expand Up @@ -808,7 +799,7 @@ impl<'a> Elaborator<'a> {
self.stats.elaborate_func += 1;
self.stats.elaborate_func_pre_insts += self.func.dfg.num_insts() as u64;
self.compute_best_values();
self.elaborate_domtree(&self.domtree_children);
self.elaborate_domtree(&self.domtree);
self.stats.elaborate_func_post_insts += self.func.dfg.num_insts() as u64;
}
}