Skip to content
Snippets Groups Projects

Bug fixes for CCP

Merged Aaron Councilman requested to merge ccp-bugfix into main
8 files
+ 117
14
Compare changes
  • Side-by-side
  • Inline
Files
8
+ 26
14
@@ -53,6 +53,19 @@ impl CCPLattice {
@@ -53,6 +53,19 @@ impl CCPLattice {
}
}
}
}
 
impl ReachabilityLattice {
 
// We define join for the reachability lattice as for data nodes we join the reachability of
 
// its uses since it is unreachable if any of its uses are unreachable
 
fn join(a: &Self, b: &Self) -> Self {
 
match (a, b) {
 
(ReachabilityLattice::Reachable, ReachabilityLattice::Reachable) => {
 
ReachabilityLattice::Reachable
 
}
 
_ => ReachabilityLattice::Unreachable,
 
}
 
}
 
}
 
impl ConstantLattice {
impl ConstantLattice {
fn is_top(&self) -> bool {
fn is_top(&self) -> bool {
*self == ConstantLattice::Top
*self == ConstantLattice::Top
@@ -274,11 +287,10 @@ pub fn ccp(editor: &mut FunctionEditor, reverse_postorder: &Vec<NodeID>) {
@@ -274,11 +287,10 @@ pub fn ccp(editor: &mut FunctionEditor, reverse_postorder: &Vec<NodeID>) {
// Replace all uses of the single reachable user with the node preceeding the
// Replace all uses of the single reachable user with the node preceeding the
// branch node
// branch node
edit = edit.replace_all_uses(the_reachable_user, control)?;
edit = edit.replace_all_uses(the_reachable_user, control)?;
// Delete all users and the branch node
// Mark the reachable user and the branch as unreachable so they'll be deleted
for user in users {
unreachable.insert(the_reachable_user);
edit = edit.delete_node(user)?;
unreachable.insert(branch_id);
}
Ok(edit)
edit.delete_node(branch_id)
});
});
}
}
}
}
@@ -629,7 +641,7 @@ fn ccp_flow_function(
@@ -629,7 +641,7 @@ fn ccp_flow_function(
};
};
CCPLattice {
CCPLattice {
reachability: ReachabilityLattice::meet(left_reachability, right_reachability),
reachability: ReachabilityLattice::join(left_reachability, right_reachability),
constant: new_constant,
constant: new_constant,
}
}
}
}
@@ -682,9 +694,9 @@ fn ccp_flow_function(
@@ -682,9 +694,9 @@ fn ccp_flow_function(
};
};
CCPLattice {
CCPLattice {
reachability: ReachabilityLattice::meet(
reachability: ReachabilityLattice::join(
first_reachability,
first_reachability,
&ReachabilityLattice::meet(second_reachability, third_reachability),
&ReachabilityLattice::join(second_reachability, third_reachability),
),
),
constant: new_constant,
constant: new_constant,
}
}
@@ -696,13 +708,13 @@ fn ccp_flow_function(
@@ -696,13 +708,13 @@ fn ccp_flow_function(
dynamic_constants: _,
dynamic_constants: _,
args,
args,
} => CCPLattice {
} => CCPLattice {
reachability: args.iter().fold(ReachabilityLattice::top(), |val, id| {
reachability: args.iter().fold(ReachabilityLattice::bottom(), |val, id| {
ReachabilityLattice::meet(&val, &inputs[id.idx()].reachability)
ReachabilityLattice::join(&val, &inputs[id.idx()].reachability)
}),
}),
constant: ConstantLattice::bottom(),
constant: ConstantLattice::bottom(),
},
},
Node::IntrinsicCall { intrinsic, args } => {
Node::IntrinsicCall { intrinsic, args } => {
let mut new_reachability = ReachabilityLattice::top();
let mut new_reachability = ReachabilityLattice::bottom();
let mut new_constant = ConstantLattice::top();
let mut new_constant = ConstantLattice::top();
let mut constants = vec![];
let mut constants = vec![];
let mut all_constants = true;
let mut all_constants = true;
@@ -713,7 +725,7 @@ fn ccp_flow_function(
@@ -713,7 +725,7 @@ fn ccp_flow_function(
ref constant,
ref constant,
} = inputs[arg.idx()];
} = inputs[arg.idx()];
new_reachability = ReachabilityLattice::meet(&new_reachability, reachability);
new_reachability = ReachabilityLattice::join(&new_reachability, reachability);
new_constant = ConstantLattice::meet(&new_constant, constant);
new_constant = ConstantLattice::meet(&new_constant, constant);
if let ConstantLattice::Constant(constant) = constant {
if let ConstantLattice::Constant(constant) = constant {
@@ -908,14 +920,14 @@ fn ccp_flow_function(
@@ -908,14 +920,14 @@ fn ccp_flow_function(
data,
data,
indices,
indices,
} => {
} => {
let mut reachability = ReachabilityLattice::meet(
let mut reachability = ReachabilityLattice::join(
&inputs[collect.idx()].reachability,
&inputs[collect.idx()].reachability,
&inputs[data.idx()].reachability,
&inputs[data.idx()].reachability,
);
);
for index in indices.iter() {
for index in indices.iter() {
if let Index::Position(positions) = index {
if let Index::Position(positions) = index {
for position in positions.iter() {
for position in positions.iter() {
reachability = ReachabilityLattice::meet(
reachability = ReachabilityLattice::join(
&reachability,
&reachability,
&inputs[position.idx()].reachability,
&inputs[position.idx()].reachability,
);
);
Loading