diff --git a/hercules_opt/src/inline.rs b/hercules_opt/src/inline.rs index 895f1f73b10aef8b1809b9b4cb6ad83b7062015f..38ed1b22d2d81be971aa867857fd01e3752ecc0a 100644 --- a/hercules_opt/src/inline.rs +++ b/hercules_opt/src/inline.rs @@ -255,16 +255,6 @@ impl ParameterLattice { } } - fn try_const_dc(self, dcs: Ref<'_, Vec<DynamicConstant>>) -> Option<usize> { - if let ParameterLattice::DynamicConstant(id, _) = self - && let DynamicConstant::Constant(val) = &dcs[id.idx()] - { - Some(*val) - } else { - None - } - } - fn meet(&mut self, b: Self, cons: Ref<'_, Vec<Constant>>, dcs: Ref<'_, Vec<DynamicConstant>>) { use ParameterLattice::*; *self = match (*self, b) { @@ -312,8 +302,7 @@ impl ParameterLattice { * * 1. Not marked as entry. * 2. At every call site, a particular parameter is always a specific constant - * or dynamic constant OR a particular dynamic constant parameter is always a - * specific constant. + * or dynamic constant. * * These functions can have that constant "inlined" - the parameter is removed * and all uses of the parameter becomes uses of the constant directly. @@ -327,16 +316,14 @@ pub fn const_inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) { continue; } - // Figure out what we know about the parameters (both normal and dynamic - // constant) to this function. + // Figure out what we know about the parameters to this function. let mut param_lattice = vec![ParameterLattice::Top; func.param_types.len()]; - let mut dc_param_lattice = vec![ParameterLattice::Top; func.num_dynamic_constants as usize]; let mut callers = vec![]; for caller in callgraph.get_callers(func_id) { let editor = &editors[caller.idx()]; let nodes = &editor.func().nodes; for id in editor.node_ids() { - if let Some((_, callee, dc_args, args)) = nodes[id.idx()].try_call() + if let Some((_, callee, _, args)) = nodes[id.idx()].try_call() && callee == func_id { if editor.is_mutable(id) { @@ -348,31 +335,16 @@ pub fn const_inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) { editor.get_dynamic_constants(), ); } - - for (idx, id) in dc_args.into_iter().enumerate() { - let lattice = ParameterLattice::DynamicConstant(*id, func_id); - dc_param_lattice[idx].meet( - lattice, - editor.get_constants(), - editor.get_dynamic_constants(), - ); - } } else { // If we can't modify the call node in the caller, then // we can't perform the inlining. param_lattice = vec![ParameterLattice::Bottom; func.param_types.len()]; - dc_param_lattice = - vec![ParameterLattice::Bottom; func.num_dynamic_constants as usize]; } callers.push((caller, id)); } } } - if param_lattice.iter().all(|v| *v == ParameterLattice::Bottom) - && dc_param_lattice - .iter() - .all(|v| *v == ParameterLattice::Bottom) - { + if param_lattice.iter().all(|v| *v == ParameterLattice::Bottom) { continue; } @@ -392,6 +364,17 @@ pub fn const_inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) { if let Some(node) = match param_lattice[idx] { ParameterLattice::Top => Some(Node::Undef { ty: param_tys[idx] }), ParameterLattice::Constant(id) => Some(Node::Constant { id }), + ParameterLattice::DynamicConstant(id, _) => { + // Rust moment. + let maybe_cons = edit.get_dynamic_constant(id).try_constant(); + if let Some(val) = maybe_cons { + Some(Node::DynamicConstant { + id: edit.add_dynamic_constant(DynamicConstant::Constant(val)), + }) + } else { + None + } + } _ => None, } && let Some(ids) = param_idx_to_ids.get(&idx) { diff --git a/juno_samples/rodinia/bfs/src/bfs.jn b/juno_samples/rodinia/bfs/src/bfs.jn index 2e61f1a083155b12268be1d9b63555a6eee4b1b8..51dcd945429dfde02cb2313afa404e81f8722c84 100644 --- a/juno_samples/rodinia/bfs/src/bfs.jn +++ b/juno_samples/rodinia/bfs/src/bfs.jn @@ -13,7 +13,7 @@ fn bfs<n, m: usize>(graph_nodes: Node[n], source: u32, edges: u32[m]) -> i32[n] let visited: bool[n]; visited[source as u64] = true; - @cost let cost: i32[n]; + @cost @cost_init let cost: i32[n]; @cost_init for i in 0..n { cost[i] = -1; }