Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions compiler/optimizer/src/analysis/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,42 @@ impl LivenessAnalysis {

// Iterative dataflow solver
let mut changed = true;
let mut new_in = HashSet::new();
let mut new_out = HashSet::new();

while changed {
changed = false;
for block in &func.blocks {
let block_id = block.id;

// LiveOut = union of LiveIn(succs)
let mut new_out = HashSet::new();
new_out.clear();
for &succ in &block.successors {
if let Some(succ_in) = live_in.get(&succ) {
new_out.extend(succ_in);
}
}

// LiveIn = Use union (LiveOut diff Def)
let mut new_in = uses[&block_id].clone();
new_in.clear();
new_in.extend(uses[&block_id].iter().copied());
let def = &defs[&block_id];
for &val in &new_out {
if !def.contains(&val) {
new_in.insert(val);
for val in &new_out {
if !def.contains(val) {
new_in.insert(*val);
}
}

if let Some(old_in) = live_in.get_mut(&block_id) {
if *old_in != new_in {
*old_in = new_in;
if old_in.len() != new_in.len() {
*old_in = new_in.clone();
changed = true;
}
}

if let Some(old_out) = live_out.get_mut(&block_id) {
if *old_out != new_out {
*old_out = new_out;
if old_out.len() != new_out.len() {
*old_out = new_out.clone();
changed = true;
}
}
Expand Down
Binary file added test_perf
Binary file not shown.
Loading