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.
This commit is contained in:
@@ -115,13 +115,6 @@ impl Context {
|
|||||||
self.domtree.compute(&self.func, &self.cfg);
|
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.
|
/// Perform simple GVN on the function.
|
||||||
pub fn simple_gvn(&mut self) -> CtonResult {
|
pub fn simple_gvn(&mut self) -> CtonResult {
|
||||||
do_simple_gvn(&mut self.func, &mut self.cfg);
|
do_simple_gvn(&mut self.func, &mut self.cfg);
|
||||||
@@ -132,7 +125,6 @@ impl Context {
|
|||||||
|
|
||||||
/// Perform LICM on the function.
|
/// Perform LICM on the function.
|
||||||
pub fn licm(&mut self) -> CtonResult {
|
pub fn licm(&mut self) -> CtonResult {
|
||||||
self.ensure_domtree();
|
|
||||||
do_licm(
|
do_licm(
|
||||||
&mut self.func,
|
&mut self.func,
|
||||||
&mut self.cfg,
|
&mut self.cfg,
|
||||||
@@ -144,12 +136,11 @@ impl Context {
|
|||||||
|
|
||||||
/// Run the register allocator.
|
/// Run the register allocator.
|
||||||
pub fn regalloc(&mut self, isa: &TargetIsa) -> CtonResult {
|
pub fn regalloc(&mut self, isa: &TargetIsa) -> CtonResult {
|
||||||
self.ensure_domtree();
|
|
||||||
self.regalloc.run(
|
self.regalloc.run(
|
||||||
isa,
|
isa,
|
||||||
&mut self.func,
|
&mut self.func,
|
||||||
&self.cfg,
|
&self.cfg,
|
||||||
&self.domtree,
|
&mut self.domtree,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -237,6 +237,14 @@ impl DominatorTree {
|
|||||||
!self.nodes.is_empty()
|
!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`.
|
/// 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.
|
/// This leaves `rpo_number == 1` for all reachable EBBs, 0 for unreachable ones.
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub fn do_licm(
|
|||||||
domtree: &mut DominatorTree,
|
domtree: &mut DominatorTree,
|
||||||
loop_analysis: &mut LoopAnalysis,
|
loop_analysis: &mut LoopAnalysis,
|
||||||
) {
|
) {
|
||||||
|
domtree.ensure(func, cfg);
|
||||||
loop_analysis.compute(func, cfg, domtree);
|
loop_analysis.compute(func, cfg, domtree);
|
||||||
for lp in loop_analysis.loops() {
|
for lp in loop_analysis.loops() {
|
||||||
// For each loop that we want to optimize we determine the set of loop-invariant
|
// For each loop that we want to optimize we determine the set of loop-invariant
|
||||||
|
|||||||
@@ -58,8 +58,11 @@ impl Context {
|
|||||||
isa: &TargetIsa,
|
isa: &TargetIsa,
|
||||||
func: &mut Function,
|
func: &mut Function,
|
||||||
cfg: &ControlFlowGraph,
|
cfg: &ControlFlowGraph,
|
||||||
domtree: &DominatorTree,
|
domtree: &mut DominatorTree,
|
||||||
) -> CtonResult {
|
) -> CtonResult {
|
||||||
|
// Ensure that a valid domtree exists.
|
||||||
|
domtree.ensure(func, cfg);
|
||||||
|
|
||||||
// `Liveness` and `Coloring` are self-clearing.
|
// `Liveness` and `Coloring` are self-clearing.
|
||||||
self.virtregs.clear();
|
self.virtregs.clear();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user