Skip to content
Snippets Groups Projects
Commit 84dfd900 authored by Russel Arbore's avatar Russel Arbore
Browse files

Inline dynamic constants

parent 4572a7ec
No related branches found
No related tags found
1 merge request!202Round 1 of rodinia schedule optimization
Pipeline #201898 passed
...@@ -255,16 +255,6 @@ impl ParameterLattice { ...@@ -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>>) { fn meet(&mut self, b: Self, cons: Ref<'_, Vec<Constant>>, dcs: Ref<'_, Vec<DynamicConstant>>) {
use ParameterLattice::*; use ParameterLattice::*;
*self = match (*self, b) { *self = match (*self, b) {
...@@ -312,8 +302,7 @@ impl ParameterLattice { ...@@ -312,8 +302,7 @@ impl ParameterLattice {
* *
* 1. Not marked as entry. * 1. Not marked as entry.
* 2. At every call site, a particular parameter is always a specific constant * 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 * or dynamic constant.
* specific constant.
* *
* These functions can have that constant "inlined" - the parameter is removed * These functions can have that constant "inlined" - the parameter is removed
* and all uses of the parameter becomes uses of the constant directly. * 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) { ...@@ -327,16 +316,14 @@ pub fn const_inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) {
continue; continue;
} }
// Figure out what we know about the parameters (both normal and dynamic // Figure out what we know about the parameters to this function.
// constant) to this function.
let mut param_lattice = vec![ParameterLattice::Top; func.param_types.len()]; 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![]; let mut callers = vec![];
for caller in callgraph.get_callers(func_id) { for caller in callgraph.get_callers(func_id) {
let editor = &editors[caller.idx()]; let editor = &editors[caller.idx()];
let nodes = &editor.func().nodes; let nodes = &editor.func().nodes;
for id in editor.node_ids() { 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 && callee == func_id
{ {
if editor.is_mutable(id) { if editor.is_mutable(id) {
...@@ -348,31 +335,16 @@ pub fn const_inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) { ...@@ -348,31 +335,16 @@ pub fn const_inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) {
editor.get_dynamic_constants(), 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 { } else {
// If we can't modify the call node in the caller, then // If we can't modify the call node in the caller, then
// we can't perform the inlining. // we can't perform the inlining.
param_lattice = vec![ParameterLattice::Bottom; func.param_types.len()]; 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)); callers.push((caller, id));
} }
} }
} }
if param_lattice.iter().all(|v| *v == ParameterLattice::Bottom) if param_lattice.iter().all(|v| *v == ParameterLattice::Bottom) {
&& dc_param_lattice
.iter()
.all(|v| *v == ParameterLattice::Bottom)
{
continue; continue;
} }
...@@ -392,6 +364,17 @@ pub fn const_inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) { ...@@ -392,6 +364,17 @@ pub fn const_inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) {
if let Some(node) = match param_lattice[idx] { if let Some(node) = match param_lattice[idx] {
ParameterLattice::Top => Some(Node::Undef { ty: param_tys[idx] }), ParameterLattice::Top => Some(Node::Undef { ty: param_tys[idx] }),
ParameterLattice::Constant(id) => Some(Node::Constant { id }), 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, _ => None,
} && let Some(ids) = param_idx_to_ids.get(&idx) } && let Some(ids) = param_idx_to_ids.get(&idx)
{ {
......
...@@ -13,7 +13,7 @@ fn bfs<n, m: usize>(graph_nodes: Node[n], source: u32, edges: u32[m]) -> i32[n] ...@@ -13,7 +13,7 @@ fn bfs<n, m: usize>(graph_nodes: Node[n], source: u32, edges: u32[m]) -> i32[n]
let visited: bool[n]; let visited: bool[n];
visited[source as u64] = true; 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_init for i in 0..n {
cost[i] = -1; cost[i] = -1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment