From 69f8174c03de322f7c39eb12cd778b1a18fa4453 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 12 Sep 2017 13:47:17 -0700 Subject: [PATCH] Move `ensure_domtree` out of Context and into DominatorTree. This also moves the calls to it out of Context and into the passes that actually need it, so that Context's functions don't have any logic of their own. --- lib/cretonne/src/context.rs | 11 +---------- lib/cretonne/src/dominator_tree.rs | 8 ++++++++ lib/cretonne/src/licm.rs | 1 + lib/cretonne/src/regalloc/context.rs | 5 ++++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/cretonne/src/context.rs b/lib/cretonne/src/context.rs index ece812a5de..45914d8069 100644 --- a/lib/cretonne/src/context.rs +++ b/lib/cretonne/src/context.rs @@ -115,13 +115,6 @@ impl Context { self.domtree.compute(&self.func, &self.cfg); } - /// Ensure that a valid domtree exists. - pub fn ensure_domtree(&mut self) { - if !self.domtree.is_valid() { - self.domtree.compute(&self.func, &self.cfg); - } - } - /// Perform simple GVN on the function. pub fn simple_gvn(&mut self) -> CtonResult { do_simple_gvn(&mut self.func, &mut self.cfg); @@ -132,7 +125,6 @@ impl Context { /// Perform LICM on the function. pub fn licm(&mut self) -> CtonResult { - self.ensure_domtree(); do_licm( &mut self.func, &mut self.cfg, @@ -144,12 +136,11 @@ impl Context { /// Run the register allocator. pub fn regalloc(&mut self, isa: &TargetIsa) -> CtonResult { - self.ensure_domtree(); self.regalloc.run( isa, &mut self.func, &self.cfg, - &self.domtree, + &mut self.domtree, ) } diff --git a/lib/cretonne/src/dominator_tree.rs b/lib/cretonne/src/dominator_tree.rs index 2e9a6dc38d..18fd9e91b2 100644 --- a/lib/cretonne/src/dominator_tree.rs +++ b/lib/cretonne/src/dominator_tree.rs @@ -237,6 +237,14 @@ impl DominatorTree { !self.nodes.is_empty() } + /// Conveneince function to call `compute` if `compute` hasn't been called + /// since the last `clear()`. + pub fn ensure(&mut self, func: &Function, cfg: &ControlFlowGraph) { + if !self.is_valid() { + self.compute(func, cfg) + } + } + /// Reset all internal data structures and compute a post-order for `cfg`. /// /// This leaves `rpo_number == 1` for all reachable EBBs, 0 for unreachable ones. diff --git a/lib/cretonne/src/licm.rs b/lib/cretonne/src/licm.rs index 20dfca9f5d..41aa498c5c 100644 --- a/lib/cretonne/src/licm.rs +++ b/lib/cretonne/src/licm.rs @@ -16,6 +16,7 @@ pub fn do_licm( domtree: &mut DominatorTree, loop_analysis: &mut LoopAnalysis, ) { + domtree.ensure(func, cfg); loop_analysis.compute(func, cfg, domtree); for lp in loop_analysis.loops() { // For each loop that we want to optimize we determine the set of loop-invariant diff --git a/lib/cretonne/src/regalloc/context.rs b/lib/cretonne/src/regalloc/context.rs index 2e11536596..92be408919 100644 --- a/lib/cretonne/src/regalloc/context.rs +++ b/lib/cretonne/src/regalloc/context.rs @@ -58,8 +58,11 @@ impl Context { isa: &TargetIsa, func: &mut Function, cfg: &ControlFlowGraph, - domtree: &DominatorTree, + domtree: &mut DominatorTree, ) -> CtonResult { + // Ensure that a valid domtree exists. + domtree.ensure(func, cfg); + // `Liveness` and `Coloring` are self-clearing. self.virtregs.clear();