Add a preorder pre_cmp_def() function.
This provides a total ordering of values according to when their
definition appears in the dominator tree pre-order.
use entity::EntityMap;
use flowgraph::{ControlFlowGraph, BasicBlock};
-use ir::{Ebb, Inst, Function, Layout, ProgramOrder, ExpandedProgramPoint};
+use ir::{Ebb, Inst, Value, Function, Layout, ProgramOrder, ExpandedProgramPoint};
use ir::instructions::BranchInfo;
use packed_option::PackedOption;
use std::cmp;
@@ -649,6 +649,20 @@ impl DominatorTreePreorder {
layout.cmp(a, b),
)
}
+
+ /// Compare two value defs according to the dominator tree pre-order.
+ ///
+ /// Two values defined at the same program point are compared according to their parameter or
+ /// result order.
+ ///
+ /// This is a total ordering of the values in the function.
+ pub fn pre_cmp_def(&self, a: Value, b: Value, func: &Function) -> Ordering {
+ let da = func.dfg.value_def(a);
+ let db = func.dfg.value_def(b);
+ self.pre_cmp(da, db, &func.layout).then_with(
+ || da.num().cmp(&db.num()),
+ )
+ }
}
#[cfg(test)]
