Factor out check whether an unwind action generates invoke
This commit is contained in:
parent
5c1733e4f4
commit
02d7fc167f
1 changed files with 10 additions and 7 deletions
|
@ -57,10 +57,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
|
||||||
kind: TerminatorKind::Call { target: Some(ref mut destination), unwind, .. },
|
kind: TerminatorKind::Call { target: Some(ref mut destination), unwind, .. },
|
||||||
source_info,
|
source_info,
|
||||||
}) if pred_count[*destination] > 1
|
}) if pred_count[*destination] > 1
|
||||||
&& (matches!(
|
&& (generates_invoke(unwind) || self == &AllCallEdges) =>
|
||||||
unwind,
|
|
||||||
UnwindAction::Cleanup(_) | UnwindAction::Terminate(_)
|
|
||||||
) || self == &AllCallEdges) =>
|
|
||||||
{
|
{
|
||||||
// It's a critical edge, break it
|
// It's a critical edge, break it
|
||||||
*destination = new_block(source_info, block.is_cleanup, *destination);
|
*destination = new_block(source_info, block.is_cleanup, *destination);
|
||||||
|
@ -81,9 +78,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
|
||||||
});
|
});
|
||||||
let has_labels =
|
let has_labels =
|
||||||
operands.iter().any(|op| matches!(op, InlineAsmOperand::Label { .. }));
|
operands.iter().any(|op| matches!(op, InlineAsmOperand::Label { .. }));
|
||||||
let invoke =
|
if has_outputs && (has_labels || generates_invoke(unwind)) {
|
||||||
matches!(unwind, UnwindAction::Cleanup(_) | UnwindAction::Terminate(_));
|
|
||||||
if has_outputs && (has_labels || invoke) {
|
|
||||||
for target in targets.iter_mut() {
|
for target in targets.iter_mut() {
|
||||||
if pred_count[*target] > 1 {
|
if pred_count[*target] > 1 {
|
||||||
*target = new_block(source_info, block.is_cleanup, *target);
|
*target = new_block(source_info, block.is_cleanup, *target);
|
||||||
|
@ -104,3 +99,11 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if this unwind action is code generated as an invoke as opposed to a call.
|
||||||
|
fn generates_invoke(unwind: UnwindAction) -> bool {
|
||||||
|
match unwind {
|
||||||
|
UnwindAction::Continue | UnwindAction::Unreachable => false,
|
||||||
|
UnwindAction::Cleanup(_) | UnwindAction::Terminate(_) => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue