From bf6026c51c7f2dcfccddb3a1b7234b5ca38a7597 Mon Sep 17 00:00:00 2001 From: Aaron Councilman <aaronjc4@illinois.edu> Date: Fri, 6 Dec 2024 09:43:25 -0600 Subject: [PATCH] CCP improvements --- hercules_opt/src/ccp.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/hercules_opt/src/ccp.rs b/hercules_opt/src/ccp.rs index cf3a0919..b8eb57ca 100644 --- a/hercules_opt/src/ccp.rs +++ b/hercules_opt/src/ccp.rs @@ -383,8 +383,14 @@ fn ccp_flow_function( }), // If node has only one output, if doesn't directly handle crossover of // reachability and constant propagation. Read handles that. - Node::If { control, cond: _ } => inputs[control.idx()].clone(), - Node::Match { control, sum: _ } => inputs[control.idx()].clone(), + Node::If { control, cond } => { + assert!(!inputs[control.idx()].is_reachable() || inputs[cond.idx()].is_reachable()); + inputs[control.idx()].clone() + } + Node::Match { control, sum } => { + assert!(!inputs[control.idx()].is_reachable() || inputs[sum.idx()].is_reachable()); + inputs[control.idx()].clone() + } Node::Fork { control, factors: _, @@ -426,9 +432,21 @@ fn ccp_flow_function( // TODO: At least for now, reduce nodes always produce unknown values. Node::Reduce { control, - init: _, - reduct: _, - } => inputs[control.idx()].clone(), + init, + reduct, + } => { + let reachability = inputs[control.idx()].reachability.clone(); + if reachability == ReachabilityLattice::Reachable { + assert!(inputs[init.idx()].is_reachable()); + let mut constant = inputs[init.idx()].constant.clone(); + if inputs[reduct.idx()].is_reachable() { + constant = ConstantLattice::meet(&constant, &inputs[reduct.idx()].constant); + } + CCPLattice { reachability, constant } + } else { + CCPLattice { reachability, constant: ConstantLattice::top() } + } + }, Node::Return { control, data } => inputs[control.idx()].clone(), Node::Parameter { index: _ } => CCPLattice::bottom(), // A constant node is the "source" of concrete constant lattice values. -- GitLab