Use CursorBase utility functions to reduce repositioning clutter.

This commit is contained in:
Dan Gohman
2017-09-20 06:58:45 -07:00
parent 144d39a53d
commit b888894fbb
5 changed files with 22 additions and 9 deletions

View File

@@ -788,10 +788,27 @@ pub trait CursorBase {
self.set_position(CursorPosition::At(inst)); self.set_position(CursorPosition::At(inst));
} }
/// Go to the position for inserting instructions at the beginning of `ebb`,
/// which unlike `goto_first_inst` doesn't assume that any instructions have
/// been inserted into `ebb` yet.
fn goto_first_insertion_point(&mut self, ebb: Ebb) {
if let Some(inst) = self.layout().ebbs[ebb].first_inst.expand() {
self.goto_inst(inst);
} else {
self.goto_bottom(ebb);
}
}
/// Go to the first instruction in `ebb`. /// Go to the first instruction in `ebb`.
fn goto_first_inst(&mut self, ebb: Ebb) { fn goto_first_inst(&mut self, ebb: Ebb) {
let inst = self.layout().ebbs[ebb].first_inst.expect("Empty EBB"); let inst = self.layout().ebbs[ebb].first_inst.expect("Empty EBB");
self.set_position(CursorPosition::At(inst)); self.goto_inst(inst);
}
/// Go to the last instruction in `ebb`.
fn goto_last_inst(&mut self, ebb: Ebb) {
let inst = self.layout().ebbs[ebb].last_inst.expect("Empty EBB");
self.goto_inst(inst);
} }
/// Go to the top of `ebb` which must be inserted into the layout. /// Go to the top of `ebb` which must be inserted into the layout.

View File

@@ -63,8 +63,7 @@ fn legalize_entry_arguments(func: &mut Function, entry: Ebb) {
// We want to insert instructions before the first instruction in the entry block. // We want to insert instructions before the first instruction in the entry block.
// If the entry block is empty, append instructions to it instead. // If the entry block is empty, append instructions to it instead.
let mut pos = Cursor::new(&mut func.layout); let mut pos = Cursor::new(&mut func.layout);
pos.goto_top(entry); pos.goto_first_inst(entry);
pos.next_inst();
// Keep track of the argument types in the ABI-legalized signature. // Keep track of the argument types in the ABI-legalized signature.
let abi_types = &func.signature.argument_types; let abi_types = &func.signature.argument_types;

View File

@@ -235,8 +235,7 @@ fn split_value(
// //
// Note that it is safe to move `pos` here since `reuse` was set above, so we don't // Note that it is safe to move `pos` here since `reuse` was set above, so we don't
// need to insert a split instruction before returning. // need to insert a split instruction before returning.
pos.goto_top(ebb); pos.goto_first_inst(ebb);
pos.next_inst();
dfg.ins(pos).with_result(value).Binary( dfg.ins(pos).with_result(value).Binary(
concat, concat,
split_type, split_type,

View File

@@ -34,8 +34,7 @@ pub fn do_licm(
let pre_header = let pre_header =
create_pre_header(loop_analysis.loop_header(lp), func, cfg, domtree); create_pre_header(loop_analysis.loop_header(lp), func, cfg, domtree);
pos = Cursor::new(&mut func.layout); pos = Cursor::new(&mut func.layout);
pos.goto_bottom(pre_header); pos.goto_last_inst(pre_header);
pos.prev_inst();
} }
// If there is a natural pre-header we insert new instructions just before the // If there is a natural pre-header we insert new instructions just before the
// related jumping instruction (which is not necessarily at the end). // related jumping instruction (which is not necessarily at the end).

View File

@@ -445,8 +445,7 @@ where
layout.append_ebb(dest_ebb) layout.append_ebb(dest_ebb)
}; };
let mut cur = Cursor::new(layout); let mut cur = Cursor::new(layout);
cur.goto_top(dest_ebb); cur.goto_first_insertion_point(dest_ebb);
cur.next_inst();
let ty = dfg.value_type(temp_arg_val); let ty = dfg.value_type(temp_arg_val);
let val = if ty.is_int() { let val = if ty.is_int() {
dfg.ins(&mut cur).iconst(ty, 0) dfg.ins(&mut cur).iconst(ty, 0)