Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic structurization #2

Merged
merged 11 commits into from
Sep 23, 2024
Prev Previous commit
Next Next commit
cfg: correctly support chains of rewritten phis.
eddyb authored and Firestar99 committed Sep 23, 2024
commit c91d90a1f916d923b9711ce0bd34e1b6273b1ad7
20 changes: 16 additions & 4 deletions src/cfg.rs
Original file line number Diff line number Diff line change
@@ -739,11 +739,23 @@ impl<'a> Structurizer<'a> {
}
}

self.func_def_body.inner_in_place_transform_with(&mut ReplaceValueWith(|v| match v {
Value::ControlRegionInput { region, input_idx } => {
Some(self.control_region_input_replacements.get(region)?[input_idx as usize])
self.func_def_body.inner_in_place_transform_with(&mut ReplaceValueWith(|v| {
// NOTE(eddyb) this needs to be able to apply multiple replacements,
// due to the input potentially having redundantly chained `OpPhi`s.
//
// FIXME(eddyb) union-find-style "path compression" could record the
// final value inside `self.control_region_input_replacements` while
// replacements are being made, to avoid going through a chain more
// than once (and some of these replacements could be applied early).
let mut new_v = v;
while let Value::ControlRegionInput { region, input_idx } = new_v {
if let Some(replacements) = self.control_region_input_replacements.get(region) {
new_v = replacements[input_idx as usize];
} else {
break;
}
}
_ => None,
(v != new_v).then_some(new_v)
}));
}