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

fix getting dc params, add graphs for paper

parent 694dacca
No related branches found
No related tags found
1 merge request!161Fix DC param ID identfication
/target
*.dot
!paper_resources/*.dot
*.bc
*.out
*.ll
......
......@@ -24,21 +24,19 @@ pub fn inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) {
.map(|editor| collapse_returns(editor))
.collect();
// Step 3: verify that each possible dynamic constant parameter index has a
// single unique dynamic constant ID. If this isn't true, dynamic constant
// substitution won't work, and this should be true anyway!
let mut found_idxs = HashMap::new();
for id in editors[0].dynamic_constant_ids() {
let dc = editors[0].get_dynamic_constant(id);
if let DynamicConstant::Parameter(idx) = *dc {
assert!(!found_idxs.contains_key(&idx));
found_idxs.insert(idx, id);
}
}
let mut dc_param_idx_to_dc_id = vec![];
for idx in 0..found_idxs.len() {
dc_param_idx_to_dc_id.push(found_idxs[&idx]);
}
// Step 3: get dynamic constant IDs for parameters.
let max_num_dc_params = editors
.iter()
.map(|editor| editor.func().num_dynamic_constants)
.max()
.unwrap();
let mut dc_args = vec![];
editors[0].edit(|mut edit| {
dc_args = (0..max_num_dc_params as usize)
.map(|i| edit.add_dynamic_constant(DynamicConstant::Parameter(i)))
.collect();
Ok(edit)
});
// Step 4: run inlining on each function individually. Iterate the functions
// in topological order.
......@@ -49,12 +47,7 @@ pub fn inline(editors: &mut [FunctionEditor], callgraph: &CallGraph) {
// 2. Shared references to all of the functions called by that function.
let callees = callgraph.get_callees(to_inline_id);
let editor_refs = get_mut_and_immuts(editors, to_inline_id, callees);
inline_func(
editor_refs.0,
editor_refs.1,
&single_return_nodes,
&dc_param_idx_to_dc_id,
);
inline_func(editor_refs.0, editor_refs.1, &single_return_nodes, &dc_args);
}
}
......
......@@ -235,18 +235,18 @@ fn compress_return_products(editors: &mut Vec<FunctionEditor>, all_callsites_edi
// dc_param_idx_to_dc_id to get the id of the dynamic constants in the function,
// and then replace dc_param_idx_to_dc_id[i] with call.dynamic_constants[i],
// for all i.
let mut found_idxs = HashMap::new();
for id in editors[0].dynamic_constant_ids() {
let dc = editors[0].get_dynamic_constant(id);
if let DynamicConstant::Parameter(idx) = *dc {
assert!(!found_idxs.contains_key(&idx));
found_idxs.insert(idx, id);
}
}
let mut dc_param_idx_to_dc_id = vec![];
for idx in 0..found_idxs.len() {
dc_param_idx_to_dc_id.push(found_idxs[&idx]);
}
let max_num_dc_params = editors
.iter()
.map(|editor| editor.func().num_dynamic_constants)
.max()
.unwrap();
let mut dc_args = vec![];
editors[0].edit(|mut edit| {
dc_args = (0..max_num_dc_params as usize)
.map(|i| edit.add_dynamic_constant(DynamicConstant::Parameter(i)))
.collect();
Ok(edit)
});
// Step 2. Modify the return type of all editors corresponding to a function
// for which we can edit every callsite, and the return type is a product.
......@@ -314,7 +314,7 @@ fn compress_return_products(editors: &mut Vec<FunctionEditor>, all_callsites_edi
// a better abstraction around bulk replacement.
let new_dcs = (*dynamic_constants).to_vec();
let old_dcs = dc_param_idx_to_dc_id[..new_dcs.len()].to_vec();
let old_dcs = dc_args[..new_dcs.len()].to_vec();
assert_eq!(old_dcs.len(), new_dcs.len());
let substs = old_dcs
.into_iter()
......
......@@ -64,6 +64,7 @@ pub fn default_schedule() -> ScheduleStmt {
DCE,
GVN,
DCE,
Xdot,
LiftDCMath,
DCE,
GVN,
......
digraph "Module" {
margin=0;
subgraph sum {
label="sum<1>"
style=invis
cluster=true
ranksep=1;
nodesep=1;
start_0_0 [xlabel=0, label=<Start<BR /><FONT POINT-SIZE="8">Control</FONT>>, color=darkred];
parameter_0_1 [xlabel=1, label=<Parameter (#0)<BR /><FONT POINT-SIZE="8">Array(Float32, #0)</FONT>>, color=darkblue];
dynamic_constant_0_2 [xlabel=2, label=<DynamicConstant (#0)<BR /><FONT POINT-SIZE="8">UnsignedInteger64</FONT>>, color=darkblue];
projection_0_3 [xlabel=3, label=<Projection<BR /><FONT POINT-SIZE="8">Control</FONT>>, color=darkred];
add_0_4 [xlabel=4, label=<Add<BR /><FONT POINT-SIZE="8">UnsignedInteger64</FONT>>, color=darkblue];
add_0_5 [xlabel=5, label=<Add<BR /><FONT POINT-SIZE="8">Float32</FONT>>, color=darkblue];
read_0_6 [xlabel=6, label=<Read<BR /><FONT POINT-SIZE="8">Float32</FONT>>, color=darkblue];
lt_0_7 [xlabel=7, label=<LT<BR /><FONT POINT-SIZE="8">Boolean</FONT>>, color=darkblue];
if_0_8 [xlabel=8, label=<If<BR /><FONT POINT-SIZE="8">Control</FONT>>, color=darkred];
projection_0_9 [xlabel=9, label=<Projection<BR /><FONT POINT-SIZE="8">Control</FONT>>, color=darkred];
return_0_10 [xlabel=10, label=<Return>, color=darkred];
constant_0_11 [xlabel=11, label=<Constant (0)<BR /><FONT POINT-SIZE="8">UnsignedInteger64</FONT>>, color=darkblue];
constant_0_12 [xlabel=12, label=<Constant (1)<BR /><FONT POINT-SIZE="8">UnsignedInteger64</FONT>>, color=darkblue];
constant_0_13 [xlabel=13, label=<Constant (0)<BR /><FONT POINT-SIZE="8">Float32</FONT>>, color=darkblue];
phi_0_14 [xlabel=14, label=<Phi<BR /><FONT POINT-SIZE="8">UnsignedInteger64</FONT>>, color=darkblue];
phi_0_15 [xlabel=15, label=<Phi<BR /><FONT POINT-SIZE="8">Float32</FONT>>, color=darkblue];
region_0_16 [xlabel=16, label=<Region<BR /><FONT POINT-SIZE="8">Control</FONT>>, color=darkred];
if_0_8 -> projection_0_3 [color=black, style="dashed"];
phi_0_14 -> add_0_4 [color=black, style=""];
constant_0_12 -> add_0_4 [color=black, style=""];
phi_0_15 -> add_0_5 [color=black, style=""];
read_0_6 -> add_0_5 [color=black, style=""];
parameter_0_1 -> read_0_6 [color=black, style=""];
phi_0_14 -> read_0_6 [color=black, style=""];
add_0_4 -> lt_0_7 [color=black, style=""];
dynamic_constant_0_2 -> lt_0_7 [color=black, style=""];
if_0_8 -> region_0_16 [dir=back, color=black, style="dashed"];
lt_0_7 -> if_0_8 [color=black, style="dotted"];
if_0_8 -> projection_0_9 [color=black, style="dashed"];
projection_0_9 -> return_0_10 [color=black, style="dashed"];
add_0_5 -> return_0_10 [color=black, style="dotted"];
constant_0_11 -> phi_0_14 [color=black, style=""];
phi_0_14 -> add_0_4 [dir=back, color=black, style=""];
region_0_16 -> phi_0_14 [color=black, style="dotted"];
constant_0_13 -> phi_0_15 [color=black, style=""];
add_0_5 -> phi_0_15 [color=black, style=""];
region_0_16 -> phi_0_15 [color=black, style="dotted"];
start_0_0 -> region_0_16 [color=black, style="dashed"];
projection_0_3 -> region_0_16 [color=black, style="dashed"];
}
}
File added
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