Add next_inst and prev_inst helper functions to Layout.

This commit is contained in:
Dan Gohman
2017-09-20 12:38:13 -07:00
parent 42af6d59bf
commit 6710216e96

View File

@@ -482,6 +482,16 @@ impl Layout {
self.ebbs[ebb].last_inst.into() self.ebbs[ebb].last_inst.into()
} }
/// Fetch the instruction following `inst`.
pub fn next_inst(&self, inst: Inst) -> Option<Inst> {
self.insts[inst].next.expand()
}
/// Fetch the instruction preceding `inst`.
pub fn prev_inst(&self, inst: Inst) -> Option<Inst> {
self.insts[inst].prev.expand()
}
/// Insert `inst` before the instruction `before` in the same EBB. /// Insert `inst` before the instruction `before` in the same EBB.
pub fn insert_inst(&mut self, inst: Inst, before: Inst) { pub fn insert_inst(&mut self, inst: Inst, before: Inst) {
assert_eq!(self.inst_ebb(inst), None); assert_eq!(self.inst_ebb(inst), None);