Break critical edges in inline asm before code generation
An inline asm terminator defines outputs along its target edges -- a fallthrough target and labeled targets. Code generation implements this by inserting code directly into the target blocks. This approach works only if the target blocks don't have other predecessors. Establish required invariant by extending existing code that breaks critical edges before code generation.
This commit is contained in:
parent
c5b7a9c4b5
commit
5c1733e4f4
2 changed files with 63 additions and 0 deletions
|
@ -65,6 +65,32 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
|
|||
// It's a critical edge, break it
|
||||
*destination = new_block(source_info, block.is_cleanup, *destination);
|
||||
}
|
||||
Some(Terminator {
|
||||
kind:
|
||||
TerminatorKind::InlineAsm {
|
||||
asm_macro: InlineAsmMacro::Asm,
|
||||
ref mut targets,
|
||||
ref operands,
|
||||
unwind,
|
||||
..
|
||||
},
|
||||
source_info,
|
||||
}) if self == &CriticalCallEdges => {
|
||||
let has_outputs = operands.iter().any(|op| {
|
||||
matches!(op, InlineAsmOperand::InOut { .. } | InlineAsmOperand::Out { .. })
|
||||
});
|
||||
let has_labels =
|
||||
operands.iter().any(|op| matches!(op, InlineAsmOperand::Label { .. }));
|
||||
let invoke =
|
||||
matches!(unwind, UnwindAction::Cleanup(_) | UnwindAction::Terminate(_));
|
||||
if has_outputs && (has_labels || invoke) {
|
||||
for target in targets.iter_mut() {
|
||||
if pred_count[*target] > 1 {
|
||||
*target = new_block(source_info, block.is_cleanup, *target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue