Skip to content

Commit 3a14fa3

Browse files
authored
refactor(cranelift): merge DominatorTreePreorder into DominatorTree (#11596)
* refactor(cranelift): merge DominatorTreePreorder into DominatorTree Integrate preorder functionality directly into DominatorTree to eliminate duplicate computation and improve performance. This eliminates the need for a separate DominatorTreePreorder data structure, reducing memory usage and providing O(1) block dominance checks by default. Block dominance checks throughout the compiler now benefit from constant-time performance instead of O(depth) tree traversal. * refactor(cranelift): implement the new unified DominatorTree Remove separate DominatorTreePreorder computation and use unified API: - Context: Remove domtree_preorder field, simplify compute_domtree() - AliasAnalysis: Switch from DominatorTreePreorder to DominatorTree - Update dominance checks to use general dominates() method All dominance checks in alias analysis now automatically benefit from O(1) block dominance performance when instructions are in different blocks. * refactor(cranelift): update optimization passes for DominatorTree * refactor(cranelift): update verifier and tests for new DominatorTree SSA dominance validation in the verifier now benefits from O(1) block-to-block dominance checks, improving compilation performance during debug builds with verification enabled.
1 parent e017b7f commit 3a14fa3

File tree

8 files changed

+129
-247
lines changed

8 files changed

+129
-247
lines changed

cranelift/codegen/src/alias_analysis.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
6464
use crate::{
6565
cursor::{Cursor, FuncCursor},
66-
dominator_tree::DominatorTreePreorder,
66+
dominator_tree::DominatorTree,
6767
inst_predicates::{
6868
has_memory_fence_semantics, inst_addr_offset_type, inst_store_data, visit_block_succs,
6969
},
@@ -176,7 +176,7 @@ struct MemoryLoc {
176176
/// An alias-analysis pass.
177177
pub struct AliasAnalysis<'a> {
178178
/// The domtree for the function.
179-
domtree: &'a DominatorTreePreorder,
179+
domtree: &'a DominatorTree,
180180

181181
/// Input state to a basic block.
182182
block_input: FxHashMap<Block, LastStores>,
@@ -191,7 +191,7 @@ pub struct AliasAnalysis<'a> {
191191

192192
impl<'a> AliasAnalysis<'a> {
193193
/// Perform an alias analysis pass.
194-
pub fn new(func: &Function, domtree: &'a DominatorTreePreorder) -> AliasAnalysis<'a> {
194+
pub fn new(func: &Function, domtree: &'a DominatorTree) -> AliasAnalysis<'a> {
195195
trace!("alias analysis: input is:\n{:?}", func);
196196
let mut analysis = AliasAnalysis {
197197
domtree,
@@ -333,7 +333,7 @@ impl<'a> AliasAnalysis<'a> {
333333
value.index(),
334334
def_inst.index()
335335
);
336-
if self.domtree.dominates_inst(def_inst, inst, &func.layout) {
336+
if self.domtree.dominates(def_inst, inst, &func.layout) {
337337
trace!(
338338
" -> dominates; value equiv from v{} to v{} inserted",
339339
load_result.index(),

cranelift/codegen/src/context.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1212
use crate::alias_analysis::AliasAnalysis;
1313
use crate::dominator_tree::DominatorTree;
14-
use crate::dominator_tree::DominatorTreePreorder;
1514
use crate::egraph::EgraphPass;
1615
use crate::flowgraph::ControlFlowGraph;
1716
use crate::inline::{Inline, do_inlining};
@@ -48,9 +47,6 @@ pub struct Context {
4847
/// Dominator tree for `func`.
4948
pub domtree: DominatorTree,
5049

51-
/// Dominator tree with dominance stored implicitly via visit-order indices for `func`
52-
domtree_preorder: DominatorTreePreorder,
53-
5450
/// Loop analysis of `func`.
5551
pub loop_analysis: LoopAnalysis,
5652

@@ -79,7 +75,6 @@ impl Context {
7975
func,
8076
cfg: ControlFlowGraph::new(),
8177
domtree: DominatorTree::new(),
82-
domtree_preorder: DominatorTreePreorder::new(),
8378
loop_analysis: LoopAnalysis::new(),
8479
compiled_code: None,
8580
want_disasm: false,
@@ -319,7 +314,6 @@ impl Context {
319314
/// Compute dominator tree.
320315
pub fn compute_domtree(&mut self) {
321316
self.domtree.compute(&self.func, &self.cfg);
322-
self.domtree_preorder.compute(&self.domtree);
323317
}
324318

325319
/// Compute the loop analysis.
@@ -349,7 +343,7 @@ impl Context {
349343
/// by a store instruction to the same instruction (so-called
350344
/// "store-to-load forwarding").
351345
pub fn replace_redundant_loads(&mut self) -> CodegenResult<()> {
352-
let mut analysis = AliasAnalysis::new(&self.func, &self.domtree_preorder);
346+
let mut analysis = AliasAnalysis::new(&self.func, &self.domtree);
353347
analysis.compute_and_update_aliases(&mut self.func);
354348
Ok(())
355349
}
@@ -381,7 +375,7 @@ impl Context {
381375
);
382376
let fisa = fisa.into();
383377
self.compute_loop_analysis();
384-
let mut alias_analysis = AliasAnalysis::new(&self.func, &self.domtree_preorder);
378+
let mut alias_analysis = AliasAnalysis::new(&self.func, &self.domtree);
385379
let mut pass = EgraphPass::new(
386380
&mut self.func,
387381
&self.domtree,

0 commit comments

Comments
 (0)