Skip to content
Snippets Groups Projects
Commit 72932feb authored by Aaron Councilman's avatar Aaron Councilman
Browse files

Merge branch 'sroa' into 'main'

Intraprocedural SROA

Closes #8

See merge request !57
parents 73012260 cc1726f2
No related branches found
No related tags found
1 merge request!57Intraprocedural SROA
Pipeline #200342 passed
......@@ -728,6 +728,14 @@ impl Type {
None
}
}
pub fn try_product(&self) -> Option<&[TypeID]> {
if let Type::Product(ts) = self {
Some(ts)
} else {
None
}
}
}
impl Constant {
......
......@@ -555,7 +555,11 @@ pub fn repair_plan(plan: &mut Plan, new_function: &Function, edits: &[Edit]) {
// Step 2: drop schedules for deleted nodes and create empty schedule lists
// for added nodes.
for deleted in total_edit.0.iter() {
plan.schedules[deleted.idx()] = vec![];
// Nodes that were created and deleted using the same editor don't have
// an existing schedule, so ignore them
if deleted.idx() < plan.schedules.len() {
plan.schedules[deleted.idx()] = vec![];
}
}
if !total_edit.1.is_empty() {
assert_eq!(
......
......@@ -543,16 +543,33 @@ impl PassManager {
let reverse_postorders = self.reverse_postorders.as_ref().unwrap();
let typing = self.typing.as_ref().unwrap();
for idx in 0..self.module.functions.len() {
sroa(
let constants_ref =
RefCell::new(std::mem::take(&mut self.module.constants));
let dynamic_constants_ref =
RefCell::new(std::mem::take(&mut self.module.dynamic_constants));
let types_ref = RefCell::new(std::mem::take(&mut self.module.types));
let mut editor = FunctionEditor::new(
&mut self.module.functions[idx],
&constants_ref,
&dynamic_constants_ref,
&types_ref,
&def_uses[idx],
&reverse_postorders[idx],
&typing[idx],
&self.module.types,
&mut self.module.constants,
);
sroa(&mut editor, &reverse_postorders[idx], &typing[idx]);
self.module.constants = constants_ref.take();
self.module.dynamic_constants = dynamic_constants_ref.take();
self.module.types = types_ref.take();
let edits = &editor.edits();
if let Some(plans) = self.plans.as_mut() {
repair_plan(&mut plans[idx], &self.module.functions[idx], edits);
}
let grave_mapping = self.module.functions[idx].delete_gravestones();
if let Some(plans) = self.plans.as_mut() {
plans[idx].fix_gravestones(&grave_mapping);
}
}
self.legacy_repair_plan();
self.clear_analyses();
}
Pass::Inline => {
......
This diff is collapsed.
......@@ -69,11 +69,11 @@ impl fmt::Display for ErrorMessage {
match self {
ErrorMessage::SemanticError(errs) => {
for err in errs {
write!(f, "{}", err)?;
write!(f, "{}\n", err)?;
}
}
ErrorMessage::SchedulingError(msg) => {
write!(f, "{}", msg)?;
write!(f, "{}\n", msg)?;
}
}
Ok(())
......@@ -152,11 +152,20 @@ pub fn compile_ir(
pm.add_pass(hercules_opt::pass::Pass::Xdot(true));
}
add_pass!(pm, verify, Inline);
// Run SROA pretty early (though after inlining which can make SROA more effective) so that
// CCP, GVN, etc. can work on the result of SROA
add_pass!(pm, verify, InterproceduralSROA);
add_pass!(pm, verify, SROA);
// We run phi-elim again because SROA can introduce new phis that might be able to be
// simplified
add_verified_pass!(pm, verify, PhiElim);
if x_dot {
pm.add_pass(hercules_opt::pass::Pass::Xdot(true));
}
add_pass!(pm, verify, CCP);
add_pass!(pm, verify, DCE);
add_pass!(pm, verify, GVN);
add_pass!(pm, verify, DCE);
add_pass!(pm, verify, InterproceduralSROA);
if x_dot {
pm.add_pass(hercules_opt::pass::Pass::Xdot(true));
}
......
fn test_call(x : i32, y : f32) -> (i32, f32) {
let res = (x, y);
for i = 0 to 10 {
res.0 += 1;
}
return res;
}
fn test(x : i32, y : f32) -> (f32, i32) {
let res = test_call(x, y);
return (res.1, res.0);
}
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