LICM pass: small changes after code review (#94)
This commit is contained in:
committed by
Dan Gohman
parent
6563270c63
commit
81284dbd93
@@ -46,7 +46,7 @@ pub fn do_licm(func: &mut Function,
|
|||||||
};
|
};
|
||||||
// The last instruction of the pre-header is the termination instruction (usually
|
// The last instruction of the pre-header is the termination instruction (usually
|
||||||
// a jump) so we need to insert just before this.
|
// a jump) so we need to insert just before this.
|
||||||
for inst in invariant_inst.iter() {
|
for inst in invariant_inst {
|
||||||
pos.insert_inst(inst.clone());
|
pos.insert_inst(inst.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,11 +64,7 @@ fn create_pre_header(header: Ebb,
|
|||||||
domtree: &DominatorTree)
|
domtree: &DominatorTree)
|
||||||
-> Ebb {
|
-> Ebb {
|
||||||
let pool = &mut ListPool::<Value>::new();
|
let pool = &mut ListPool::<Value>::new();
|
||||||
let header_args_values: Vec<Value> = func.dfg
|
let header_args_values: Vec<Value> = func.dfg.ebb_args(header).into_iter().cloned().collect();
|
||||||
.ebb_args(header)
|
|
||||||
.into_iter()
|
|
||||||
.map(|val| *val)
|
|
||||||
.collect();
|
|
||||||
let header_args_types: Vec<Type> = header_args_values
|
let header_args_types: Vec<Type> = header_args_values
|
||||||
.clone()
|
.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -135,8 +131,8 @@ fn change_branch_jump_destination(inst: Inst, new_ebb: Ebb, func: &mut Function)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traverses a loop in reverse post-order from a header EBB and identify lopp-invariant
|
// Traverses a loop in reverse post-order from a header EBB and identify loop-invariant
|
||||||
// instructions. Theseloop-invariant instructions are then removed from the code and returned
|
// instructions. These loop-invariant instructions are then removed from the code and returned
|
||||||
// (in reverse post-order) for later use.
|
// (in reverse post-order) for later use.
|
||||||
fn remove_loop_invariant_instructions(lp: Loop,
|
fn remove_loop_invariant_instructions(lp: Loop,
|
||||||
func: &mut Function,
|
func: &mut Function,
|
||||||
@@ -163,8 +159,7 @@ fn remove_loop_invariant_instructions(lp: Loop,
|
|||||||
// then this instruction is loop-invariant
|
// then this instruction is loop-invariant
|
||||||
invariant_inst.push(inst);
|
invariant_inst.push(inst);
|
||||||
// We remove it from the loop
|
// We remove it from the loop
|
||||||
pos.remove_inst();
|
pos.remove_inst_and_step_back();
|
||||||
pos.prev_inst();
|
|
||||||
} else {
|
} else {
|
||||||
// If the instruction is not loop-invariant we push its results in the set of
|
// If the instruction is not loop-invariant we push its results in the set of
|
||||||
// loop values
|
// loop values
|
||||||
@@ -178,10 +173,7 @@ fn remove_loop_invariant_instructions(lp: Loop,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return ebbs from a loop in post-order, starting from an entry point in the block.
|
/// Return ebbs from a loop in post-order, starting from an entry point in the block.
|
||||||
pub fn postorder_ebbs_loop(loop_analysis: &LoopAnalysis,
|
fn postorder_ebbs_loop(loop_analysis: &LoopAnalysis, cfg: &ControlFlowGraph, lp: Loop) -> Vec<Ebb> {
|
||||||
cfg: &ControlFlowGraph,
|
|
||||||
lp: Loop)
|
|
||||||
-> Vec<Ebb> {
|
|
||||||
let mut grey = HashSet::new();
|
let mut grey = HashSet::new();
|
||||||
let mut black = HashSet::new();
|
let mut black = HashSet::new();
|
||||||
let mut stack = vec![loop_analysis.loop_header(lp).clone()];
|
let mut stack = vec![loop_analysis.loop_header(lp).clone()];
|
||||||
|
|||||||
Reference in New Issue
Block a user