2016-06-20 23:55:14 +03:00
|
|
|
//! An analysis to determine which locals require allocas and
|
2015-11-03 06:35:09 -05:00
|
|
|
//! which do not.
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
use super::FunctionCx;
|
|
|
|
use crate::traits::*;
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_data_structures::graph::dominators::Dominators;
|
|
|
|
use rustc_index::bit_set::BitSet;
|
2021-06-09 00:00:00 +00:00
|
|
|
use rustc_index::vec::IndexVec;
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::mir::traversal;
|
2021-06-02 00:00:00 +00:00
|
|
|
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::mir::{self, Location, TerminatorKind};
|
2021-08-30 17:38:27 +03:00
|
|
|
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
|
2015-11-03 06:35:09 -05:00
|
|
|
|
2019-10-26 01:41:17 -04:00
|
|
|
pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
2019-11-04 19:52:19 -05:00
|
|
|
fx: &FunctionCx<'a, 'tcx, Bx>,
|
2018-09-20 15:47:22 +02:00
|
|
|
) -> BitSet<mir::Local> {
|
2019-11-04 19:52:19 -05:00
|
|
|
let mir = fx.mir;
|
2022-07-05 00:00:00 +00:00
|
|
|
let dominators = mir.basic_blocks.dominators();
|
2021-06-09 00:00:00 +00:00
|
|
|
let locals = mir
|
|
|
|
.local_decls
|
|
|
|
.iter()
|
|
|
|
.map(|decl| {
|
|
|
|
let ty = fx.monomorphize(decl.ty);
|
|
|
|
let layout = fx.cx.spanned_layout_of(ty, decl.source_info.span);
|
|
|
|
if layout.is_zst() {
|
|
|
|
LocalKind::ZST
|
|
|
|
} else if fx.cx.is_backend_immediate(layout) || fx.cx.is_backend_scalar_pair(layout) {
|
|
|
|
LocalKind::Unused
|
|
|
|
} else {
|
|
|
|
LocalKind::Memory
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let mut analyzer = LocalAnalyzer { fx, dominators, locals };
|
|
|
|
|
|
|
|
// Arguments get assigned to by means of the function being called
|
|
|
|
for arg in mir.args_iter() {
|
|
|
|
analyzer.assign(arg, mir::START_BLOCK.start_location());
|
|
|
|
}
|
2015-11-03 06:35:09 -05:00
|
|
|
|
2021-05-27 00:00:00 +00:00
|
|
|
// If there exists a local definition that dominates all uses of that local,
|
2022-05-01 00:00:00 +00:00
|
|
|
// the definition should be visited first. Traverse blocks in an order that
|
2021-05-27 00:00:00 +00:00
|
|
|
// is a topological sort of dominance partial order.
|
2022-05-01 00:00:00 +00:00
|
|
|
for (bb, data) in traversal::reverse_postorder(&mir) {
|
2021-06-02 00:00:00 +00:00
|
|
|
analyzer.visit_basic_block_data(bb, data);
|
|
|
|
}
|
2015-11-03 06:35:09 -05:00
|
|
|
|
2021-06-09 00:00:00 +00:00
|
|
|
let mut non_ssa_locals = BitSet::new_empty(analyzer.locals.len());
|
|
|
|
for (local, kind) in analyzer.locals.iter_enumerated() {
|
|
|
|
if matches!(kind, LocalKind::Memory) {
|
|
|
|
non_ssa_locals.insert(local);
|
2015-11-03 06:35:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-09 00:00:00 +00:00
|
|
|
non_ssa_locals
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
|
|
|
enum LocalKind {
|
|
|
|
ZST,
|
|
|
|
/// A local that requires an alloca.
|
|
|
|
Memory,
|
|
|
|
/// A scalar or a scalar pair local that is neither defined nor used.
|
|
|
|
Unused,
|
|
|
|
/// A scalar or a scalar pair local with a single definition that dominates all uses.
|
|
|
|
SSA(mir::Location),
|
2015-11-03 06:35:09 -05:00
|
|
|
}
|
|
|
|
|
2019-10-26 01:41:17 -04:00
|
|
|
struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
|
|
|
|
fx: &'mir FunctionCx<'a, 'tcx, Bx>,
|
2018-02-17 17:46:15 +02:00
|
|
|
dominators: Dominators<mir::BasicBlock>,
|
2021-06-09 00:00:00 +00:00
|
|
|
locals: IndexVec<mir::Local, LocalKind>,
|
2015-11-03 06:35:09 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 21:52:35 -05:00
|
|
|
impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
|
2018-02-17 17:46:15 +02:00
|
|
|
fn assign(&mut self, local: mir::Local, location: Location) {
|
2021-06-09 00:00:00 +00:00
|
|
|
let kind = &mut self.locals[local];
|
|
|
|
match *kind {
|
|
|
|
LocalKind::ZST => {}
|
|
|
|
LocalKind::Memory => {}
|
|
|
|
LocalKind::Unused => {
|
|
|
|
*kind = LocalKind::SSA(location);
|
|
|
|
}
|
|
|
|
LocalKind::SSA(_) => {
|
|
|
|
*kind = LocalKind::Memory;
|
|
|
|
}
|
2016-01-21 18:57:43 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-01 23:30:38 +02:00
|
|
|
|
2019-08-04 12:23:05 -07:00
|
|
|
fn process_place(
|
|
|
|
&mut self,
|
2020-03-04 18:25:03 -03:00
|
|
|
place_ref: &mir::PlaceRef<'tcx>,
|
2019-08-04 12:23:05 -07:00
|
|
|
context: PlaceContext,
|
|
|
|
location: Location,
|
|
|
|
) {
|
2019-07-01 23:30:38 +02:00
|
|
|
let cx = self.fx.cx;
|
|
|
|
|
2021-01-02 19:31:37 +01:00
|
|
|
if let Some((place_base, elem)) = place_ref.last_projection() {
|
2018-05-16 18:58:54 +03:00
|
|
|
let mut base_context = if context.is_mutating_use() {
|
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Projection)
|
|
|
|
} else {
|
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
|
|
|
|
};
|
|
|
|
|
2019-07-01 23:30:38 +02:00
|
|
|
// Allow uses of projections that are ZSTs or from scalar fields.
|
2020-12-24 02:55:21 +01:00
|
|
|
let is_consume = matches!(
|
|
|
|
context,
|
2020-04-16 17:38:52 -07:00
|
|
|
PlaceContext::NonMutatingUse(
|
|
|
|
NonMutatingUseContext::Copy | NonMutatingUseContext::Move,
|
2020-12-24 02:55:21 +01:00
|
|
|
)
|
|
|
|
);
|
2019-07-01 23:30:38 +02:00
|
|
|
if is_consume {
|
2021-01-16 11:34:22 +01:00
|
|
|
let base_ty = place_base.ty(self.fx.mir, cx.tcx());
|
2020-10-24 02:21:18 +02:00
|
|
|
let base_ty = self.fx.monomorphize(base_ty);
|
2019-07-01 23:30:38 +02:00
|
|
|
|
|
|
|
// ZSTs don't require any actual memory access.
|
2020-10-24 02:21:18 +02:00
|
|
|
let elem_ty = base_ty.projection_ty(cx.tcx(), self.fx.monomorphize(elem)).ty;
|
2020-01-14 02:10:05 -03:00
|
|
|
let span = self.fx.mir.local_decls[place_ref.local].source_info.span;
|
2019-08-04 12:23:05 -07:00
|
|
|
if cx.spanned_layout_of(elem_ty, span).is_zst() {
|
2019-07-01 23:30:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-30 00:07:28 +02:00
|
|
|
if let mir::ProjectionElem::Field(..) = elem {
|
2019-08-04 12:23:05 -07:00
|
|
|
let layout = cx.spanned_layout_of(base_ty.ty, span);
|
2019-07-01 23:30:38 +02:00
|
|
|
if cx.is_backend_immediate(layout) || cx.is_backend_scalar_pair(layout) {
|
|
|
|
// Recurse with the same context, instead of `Projection`,
|
|
|
|
// potentially stopping at non-operand projections,
|
|
|
|
// which would trigger `not_ssa` on locals.
|
2018-05-16 18:58:54 +03:00
|
|
|
base_context = context;
|
2019-07-01 23:30:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 00:07:28 +02:00
|
|
|
if let mir::ProjectionElem::Deref = elem {
|
2018-05-16 18:58:54 +03:00
|
|
|
// Deref projections typically only read the pointer.
|
|
|
|
base_context = PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy);
|
|
|
|
}
|
|
|
|
|
2021-01-02 19:31:37 +01:00
|
|
|
self.process_place(&place_base, base_context, location);
|
2018-05-16 18:58:54 +03:00
|
|
|
// HACK(eddyb) this emulates the old `visit_projection_elem`, this
|
|
|
|
// entire `visit_place`-like `process_place` method should be rewritten,
|
|
|
|
// now that we have moved to the "slice of projections" representation.
|
|
|
|
if let mir::ProjectionElem::Index(local) = elem {
|
|
|
|
self.visit_local(
|
2022-07-01 16:21:21 +02:00
|
|
|
local,
|
2019-07-01 23:30:38 +02:00
|
|
|
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
|
2019-12-22 17:42:04 -05:00
|
|
|
location,
|
2019-07-01 23:30:38 +02:00
|
|
|
);
|
|
|
|
}
|
2018-05-16 18:58:54 +03:00
|
|
|
} else {
|
2022-07-01 16:21:21 +02:00
|
|
|
self.visit_local(place_ref.local, context, location);
|
2019-07-01 23:30:38 +02:00
|
|
|
}
|
|
|
|
}
|
2015-11-03 06:35:09 -05:00
|
|
|
}
|
|
|
|
|
2019-10-26 01:41:17 -04:00
|
|
|
impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
|
|
|
for LocalAnalyzer<'mir, 'a, 'tcx, Bx>
|
2019-06-16 12:41:24 +03:00
|
|
|
{
|
2019-12-22 17:42:04 -05:00
|
|
|
fn visit_assign(
|
|
|
|
&mut self,
|
|
|
|
place: &mir::Place<'tcx>,
|
|
|
|
rvalue: &mir::Rvalue<'tcx>,
|
|
|
|
location: Location,
|
|
|
|
) {
|
2019-04-22 21:07:14 +01:00
|
|
|
debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue);
|
2015-11-03 06:35:09 -05:00
|
|
|
|
2021-06-09 00:00:00 +00:00
|
|
|
if let Some(local) = place.as_local() {
|
|
|
|
self.assign(local, location);
|
|
|
|
if self.locals[local] != LocalKind::Memory {
|
|
|
|
let decl_span = self.fx.mir.local_decls[local].source_info.span;
|
|
|
|
if !self.fx.rvalue_creates_operand(rvalue, decl_span) {
|
|
|
|
self.locals[local] = LocalKind::Memory;
|
|
|
|
}
|
2015-11-03 06:35:09 -05:00
|
|
|
}
|
2016-06-20 23:55:14 +03:00
|
|
|
} else {
|
2019-12-22 17:42:04 -05:00
|
|
|
self.visit_place(place, PlaceContext::MutatingUse(MutatingUseContext::Store), location);
|
2015-11-03 06:35:09 -05:00
|
|
|
}
|
|
|
|
|
2016-08-08 18:46:06 -07:00
|
|
|
self.visit_rvalue(rvalue, location);
|
2015-11-03 06:35:09 -05:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
|
2017-12-01 14:39:51 +02:00
|
|
|
debug!("visit_place(place={:?}, context={:?})", place, context);
|
2019-07-21 22:38:30 +02:00
|
|
|
self.process_place(&place.as_ref(), context, location);
|
2017-09-03 19:14:31 +03:00
|
|
|
}
|
2016-08-14 06:34:14 +03:00
|
|
|
|
2022-07-01 16:21:21 +02:00
|
|
|
fn visit_local(&mut self, local: mir::Local, context: PlaceContext, location: Location) {
|
2017-09-03 19:14:31 +03:00
|
|
|
match context {
|
2020-04-02 10:54:24 -07:00
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Call)
|
|
|
|
| PlaceContext::MutatingUse(MutatingUseContext::Yield) => {
|
2018-02-17 17:46:15 +02:00
|
|
|
self.assign(local, location);
|
2017-09-03 19:14:31 +03:00
|
|
|
}
|
2016-08-14 06:34:14 +03:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
PlaceContext::NonUse(_) | PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
|
2018-02-17 17:46:15 +02:00
|
|
|
|
2020-04-16 17:38:52 -07:00
|
|
|
PlaceContext::NonMutatingUse(
|
|
|
|
NonMutatingUseContext::Copy | NonMutatingUseContext::Move,
|
2021-06-09 00:00:00 +00:00
|
|
|
) => match &mut self.locals[local] {
|
|
|
|
LocalKind::ZST => {}
|
|
|
|
LocalKind::Memory => {}
|
|
|
|
LocalKind::SSA(def) if def.dominates(location, &self.dominators) => {}
|
2018-11-27 02:59:49 +00:00
|
|
|
// Reads from uninitialized variables (e.g., in dead code, after
|
2018-02-17 17:46:15 +02:00
|
|
|
// optimizations) require locals to be in (uninitialized) memory.
|
2018-11-27 02:59:49 +00:00
|
|
|
// N.B., there can be uninitialized reads of a local visited after
|
2018-02-17 17:46:15 +02:00
|
|
|
// an assignment to that local, if they happen on disjoint paths.
|
2021-06-09 00:00:00 +00:00
|
|
|
kind @ (LocalKind::Unused | LocalKind::SSA(_)) => {
|
|
|
|
*kind = LocalKind::Memory;
|
2018-02-17 17:46:15 +02:00
|
|
|
}
|
2021-06-09 00:00:00 +00:00
|
|
|
},
|
2016-06-09 18:15:15 +03:00
|
|
|
|
2020-04-16 17:38:52 -07:00
|
|
|
PlaceContext::MutatingUse(
|
|
|
|
MutatingUseContext::Store
|
2022-04-11 06:04:53 -04:00
|
|
|
| MutatingUseContext::Deinit
|
|
|
|
| MutatingUseContext::SetDiscriminant
|
2020-04-16 17:38:52 -07:00
|
|
|
| MutatingUseContext::AsmOutput
|
|
|
|
| MutatingUseContext::Borrow
|
|
|
|
| MutatingUseContext::AddressOf
|
|
|
|
| MutatingUseContext::Projection,
|
|
|
|
)
|
|
|
|
| PlaceContext::NonMutatingUse(
|
|
|
|
NonMutatingUseContext::Inspect
|
|
|
|
| NonMutatingUseContext::SharedBorrow
|
|
|
|
| NonMutatingUseContext::UniqueBorrow
|
|
|
|
| NonMutatingUseContext::ShallowBorrow
|
|
|
|
| NonMutatingUseContext::AddressOf
|
|
|
|
| NonMutatingUseContext::Projection,
|
|
|
|
) => {
|
2021-06-09 00:00:00 +00:00
|
|
|
self.locals[local] = LocalKind::Memory;
|
2015-11-03 06:35:09 -05:00
|
|
|
}
|
|
|
|
|
2018-10-26 13:22:45 +02:00
|
|
|
PlaceContext::MutatingUse(MutatingUseContext::Drop) => {
|
2021-06-09 00:00:00 +00:00
|
|
|
let kind = &mut self.locals[local];
|
|
|
|
if *kind != LocalKind::Memory {
|
|
|
|
let ty = self.fx.mir.local_decls[local].ty;
|
|
|
|
let ty = self.fx.monomorphize(ty);
|
|
|
|
if self.fx.cx.type_needs_drop(ty) {
|
|
|
|
// Only need the place if we're actually dropping it.
|
|
|
|
*kind = LocalKind::Memory;
|
|
|
|
}
|
2017-09-03 19:14:31 +03:00
|
|
|
}
|
2016-06-09 18:14:47 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-03 06:35:09 -05:00
|
|
|
}
|
|
|
|
}
|
2016-05-29 22:01:06 +03:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub enum CleanupKind {
|
|
|
|
NotCleanup,
|
|
|
|
Funclet,
|
2019-12-22 17:42:04 -05:00
|
|
|
Internal { funclet: mir::BasicBlock },
|
2016-05-29 22:01:06 +03:00
|
|
|
}
|
|
|
|
|
2017-05-23 23:47:15 +03:00
|
|
|
impl CleanupKind {
|
|
|
|
pub fn funclet_bb(self, for_bb: mir::BasicBlock) -> Option<mir::BasicBlock> {
|
|
|
|
match self {
|
|
|
|
CleanupKind::NotCleanup => None,
|
|
|
|
CleanupKind::Funclet => Some(for_bb),
|
|
|
|
CleanupKind::Internal { funclet } => Some(funclet),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 23:49:03 +02:00
|
|
|
pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKind> {
|
2019-12-22 17:42:04 -05:00
|
|
|
fn discover_masters<'tcx>(
|
|
|
|
result: &mut IndexVec<mir::BasicBlock, CleanupKind>,
|
|
|
|
mir: &mir::Body<'tcx>,
|
|
|
|
) {
|
2016-06-07 21:20:50 +03:00
|
|
|
for (bb, data) in mir.basic_blocks().iter_enumerated() {
|
2016-05-29 22:01:06 +03:00
|
|
|
match data.terminator().kind {
|
2019-12-22 17:42:04 -05:00
|
|
|
TerminatorKind::Goto { .. }
|
|
|
|
| TerminatorKind::Resume
|
|
|
|
| TerminatorKind::Abort
|
|
|
|
| TerminatorKind::Return
|
|
|
|
| TerminatorKind::GeneratorDrop
|
|
|
|
| TerminatorKind::Unreachable
|
|
|
|
| TerminatorKind::SwitchInt { .. }
|
|
|
|
| TerminatorKind::Yield { .. }
|
2020-06-02 09:15:24 +02:00
|
|
|
| TerminatorKind::FalseEdge { .. }
|
2021-09-04 19:25:09 +02:00
|
|
|
| TerminatorKind::FalseUnwind { .. } => { /* nothing to do */ }
|
2019-12-22 17:42:04 -05:00
|
|
|
TerminatorKind::Call { cleanup: unwind, .. }
|
2021-09-04 19:25:09 +02:00
|
|
|
| TerminatorKind::InlineAsm { cleanup: unwind, .. }
|
2019-12-22 17:42:04 -05:00
|
|
|
| TerminatorKind::Assert { cleanup: unwind, .. }
|
|
|
|
| TerminatorKind::DropAndReplace { unwind, .. }
|
|
|
|
| TerminatorKind::Drop { unwind, .. } => {
|
2016-05-29 22:01:06 +03:00
|
|
|
if let Some(unwind) = unwind {
|
2019-12-22 17:42:04 -05:00
|
|
|
debug!(
|
|
|
|
"cleanup_kinds: {:?}/{:?} registering {:?} as funclet",
|
|
|
|
bb, data, unwind
|
|
|
|
);
|
2016-06-07 17:28:36 +03:00
|
|
|
result[unwind] = CleanupKind::Funclet;
|
2016-05-29 22:01:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
fn propagate<'tcx>(result: &mut IndexVec<mir::BasicBlock, CleanupKind>, mir: &mir::Body<'tcx>) {
|
2016-06-07 21:20:50 +03:00
|
|
|
let mut funclet_succs = IndexVec::from_elem(None, mir.basic_blocks());
|
2016-05-29 22:01:06 +03:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
let mut set_successor = |funclet: mir::BasicBlock, succ| match funclet_succs[funclet] {
|
|
|
|
ref mut s @ None => {
|
|
|
|
debug!("set_successor: updating successor of {:?} to {:?}", funclet, succ);
|
|
|
|
*s = Some(succ);
|
|
|
|
}
|
|
|
|
Some(s) => {
|
|
|
|
if s != succ {
|
|
|
|
span_bug!(
|
|
|
|
mir.span,
|
|
|
|
"funclet {:?} has 2 parents - {:?} and {:?}",
|
|
|
|
funclet,
|
|
|
|
s,
|
|
|
|
succ
|
|
|
|
);
|
2016-05-29 22:01:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (bb, data) in traversal::reverse_postorder(mir) {
|
2016-06-07 17:28:36 +03:00
|
|
|
let funclet = match result[bb] {
|
2016-05-29 22:01:06 +03:00
|
|
|
CleanupKind::NotCleanup => continue,
|
|
|
|
CleanupKind::Funclet => bb,
|
|
|
|
CleanupKind::Internal { funclet } => funclet,
|
|
|
|
};
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
debug!(
|
|
|
|
"cleanup_kinds: {:?}/{:?}/{:?} propagating funclet {:?}",
|
|
|
|
bb, data, result[bb], funclet
|
|
|
|
);
|
2016-05-29 22:01:06 +03:00
|
|
|
|
2022-05-17 08:41:01 +08:00
|
|
|
for succ in data.terminator().successors() {
|
2016-06-07 17:28:36 +03:00
|
|
|
let kind = result[succ];
|
2019-12-22 17:42:04 -05:00
|
|
|
debug!("cleanup_kinds: propagating {:?} to {:?}/{:?}", funclet, succ, kind);
|
2016-05-29 22:01:06 +03:00
|
|
|
match kind {
|
|
|
|
CleanupKind::NotCleanup => {
|
2018-11-06 15:05:44 -05:00
|
|
|
result[succ] = CleanupKind::Internal { funclet };
|
2016-05-29 22:01:06 +03:00
|
|
|
}
|
|
|
|
CleanupKind::Funclet => {
|
2017-05-18 23:58:39 +03:00
|
|
|
if funclet != succ {
|
|
|
|
set_successor(funclet, succ);
|
|
|
|
}
|
2016-05-29 22:01:06 +03:00
|
|
|
}
|
|
|
|
CleanupKind::Internal { funclet: succ_funclet } => {
|
|
|
|
if funclet != succ_funclet {
|
|
|
|
// `succ` has 2 different funclet going into it, so it must
|
|
|
|
// be a funclet by itself.
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
debug!(
|
|
|
|
"promoting {:?} to a funclet and updating {:?}",
|
|
|
|
succ, succ_funclet
|
|
|
|
);
|
2016-06-07 17:28:36 +03:00
|
|
|
result[succ] = CleanupKind::Funclet;
|
2016-05-29 22:01:06 +03:00
|
|
|
set_successor(succ_funclet, succ);
|
|
|
|
set_successor(funclet, succ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 21:20:50 +03:00
|
|
|
let mut result = IndexVec::from_elem(CleanupKind::NotCleanup, mir.basic_blocks());
|
2016-05-29 22:01:06 +03:00
|
|
|
|
|
|
|
discover_masters(&mut result, mir);
|
|
|
|
propagate(&mut result, mir);
|
|
|
|
debug!("cleanup_kinds: result={:?}", result);
|
|
|
|
result
|
|
|
|
}
|