Generalize rpo_cmp to handle all program points.

When comparing instructions in the same EBB, behave like the RPO visits
instructions in program order.

- Add a Layout::pp_ebb() method for convenience. It gets the EBB
  containing any program point.
- Add a conversion from ValueDef to ExpandedProgramPoint so it can be
  used with the rpo_cmp method.
This commit is contained in:
Jakob Stoklund Olesen
2017-06-12 13:53:12 -07:00
parent 706eef23d3
commit 4f9ff548bd
3 changed files with 48 additions and 5 deletions

View File

@@ -412,6 +412,18 @@ impl Layout {
}
}
/// Get the EBB containing the program point `pp`. Panic if `pp` is not in the layout.
pub fn pp_ebb<PP>(&self, pp: PP) -> Ebb
where PP: Into<ExpandedProgramPoint>
{
match pp.into() {
ExpandedProgramPoint::Ebb(ebb) => ebb,
ExpandedProgramPoint::Inst(inst) => {
self.inst_ebb(inst).expect("Program point not in layout")
}
}
}
/// Append `inst` to the end of `ebb`.
pub fn append_inst(&mut self, inst: Inst, ebb: Ebb) {
assert_eq!(self.inst_ebb(inst), None);

View File

@@ -63,6 +63,15 @@ impl From<Ebb> for ExpandedProgramPoint {
}
}
impl From<ValueDef> for ExpandedProgramPoint {
fn from(def: ValueDef) -> ExpandedProgramPoint {
match def {
ValueDef::Res(inst, _) => inst.into(),
ValueDef::Arg(ebb, _) => ebb.into(),
}
}
}
impl From<ProgramPoint> for ExpandedProgramPoint {
fn from(pp: ProgramPoint) -> ExpandedProgramPoint {
if pp.0 & 1 == 0 {