1 //! Inlining pass for MIR functions
3 use rustc_attr as attr;
4 use rustc_hir::def_id::DefId;
5 use rustc_index::bit_set::BitSet;
6 use rustc_index::vec::{Idx, IndexVec};
7 use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
8 use rustc_middle::mir::visit::*;
9 use rustc_middle::mir::*;
10 use rustc_middle::ty::subst::{Subst, SubstsRef};
11 use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
12 use rustc_target::spec::abi::Abi;
14 use super::simplify::{remove_dead_blocks, CfgSimplifier};
15 use crate::transform::MirPass;
16 use std::collections::VecDeque;
19 const DEFAULT_THRESHOLD: usize = 50;
20 const HINT_THRESHOLD: usize = 100;
22 const INSTR_COST: usize = 5;
23 const CALL_PENALTY: usize = 25;
24 const LANDINGPAD_PENALTY: usize = 50;
25 const RESUME_PENALTY: usize = 45;
27 const UNKNOWN_SIZE_COST: usize = 10;
31 #[derive(Copy, Clone, Debug)]
32 struct CallSite<'tcx> {
34 substs: SubstsRef<'tcx>,
39 impl<'tcx> MirPass<'tcx> for Inline {
40 fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
41 if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
42 if tcx.sess.opts.debugging_opts.instrument_coverage {
43 // The current implementation of source code coverage injects code region counters
44 // into the MIR, and assumes a 1-to-1 correspondence between MIR and source-code-
46 debug!("function inlining is disabled when compiling with `instrument_coverage`");
50 param_env: tcx.param_env_reveal_all_normalized(body.source.def_id()),
51 codegen_fn_attrs: tcx.codegen_fn_attrs(body.source.def_id()),
59 struct Inliner<'tcx> {
61 param_env: ParamEnv<'tcx>,
62 codegen_fn_attrs: &'tcx CodegenFnAttrs,
66 fn run_pass(&self, caller_body: &mut Body<'tcx>) {
67 // Keep a queue of callsites to try inlining on. We take
68 // advantage of the fact that queries detect cycles here to
69 // allow us to try and fetch the fully optimized MIR of a
70 // call; if it succeeds, we can inline it and we know that
71 // they do not call us. Otherwise, we just don't try to
74 // We use a queue so that we inline "broadly" before we inline
75 // in depth. It is unclear if this is the best heuristic,
76 // really, but that's true of all the heuristics in this
79 let mut callsites = VecDeque::new();
81 let def_id = caller_body.source.def_id();
83 // Only do inlining into fn bodies.
84 let self_hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
85 if self.tcx.hir().body_owner_kind(self_hir_id).is_fn_or_closure()
86 && caller_body.source.promoted.is_none()
88 for (bb, bb_data) in caller_body.basic_blocks().iter_enumerated() {
89 if let Some(callsite) = self.get_valid_function_call(bb, bb_data, caller_body) {
90 callsites.push_back(callsite);
98 let mut changed = false;
101 local_change = false;
102 while let Some(callsite) = callsites.pop_front() {
103 debug!("checking whether to inline callsite {:?}", callsite);
104 if !self.tcx.is_mir_available(callsite.callee) {
105 debug!("checking whether to inline callsite {:?} - MIR unavailable", callsite);
109 let callee_body = if let Some(callee_def_id) = callsite.callee.as_local() {
110 let callee_hir_id = self.tcx.hir().local_def_id_to_hir_id(callee_def_id);
111 // Avoid a cycle here by only using `optimized_mir` only if we have
112 // a lower `HirId` than the callee. This ensures that the callee will
113 // not inline us. This trick only works without incremental compilation.
114 // So don't do it if that is enabled. Also avoid inlining into generators,
115 // since their `optimized_mir` is used for layout computation, which can
116 // create a cycle, even when no attempt is made to inline the function
117 // in the other direction.
118 if !self.tcx.dep_graph.is_fully_enabled()
119 && self_hir_id < callee_hir_id
120 && caller_body.generator_kind.is_none()
122 self.tcx.optimized_mir(callsite.callee)
127 // This cannot result in a cycle since the callee MIR is from another crate
128 // and is already optimized.
129 self.tcx.optimized_mir(callsite.callee)
132 let callee_body = if self.consider_optimizing(callsite, callee_body) {
133 self.tcx.subst_and_normalize_erasing_regions(
142 // Copy only unevaluated constants from the callee_body into the caller_body.
143 // Although we are only pushing `ConstKind::Unevaluated` consts to
144 // `required_consts`, here we may not only have `ConstKind::Unevaluated`
145 // because we are calling `subst_and_normalize_erasing_regions`.
146 caller_body.required_consts.extend(
147 callee_body.required_consts.iter().copied().filter(|&constant| {
148 matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _))
152 let start = caller_body.basic_blocks().len();
153 debug!("attempting to inline callsite {:?} - body={:?}", callsite, callee_body);
154 if !self.inline_call(callsite, caller_body, callee_body) {
155 debug!("attempting to inline callsite {:?} - failure", callsite);
158 debug!("attempting to inline callsite {:?} - success", callsite);
160 // Add callsites from inlined function
161 for (bb, bb_data) in caller_body.basic_blocks().iter_enumerated().skip(start) {
162 if let Some(new_callsite) =
163 self.get_valid_function_call(bb, bb_data, caller_body)
165 // Don't inline the same function multiple times.
166 if callsite.callee != new_callsite.callee {
167 callsites.push_back(new_callsite);
181 // Simplify if we inlined anything.
183 debug!("running simplify cfg on {:?}", caller_body.source);
184 CfgSimplifier::new(caller_body).simplify();
185 remove_dead_blocks(caller_body);
189 fn get_valid_function_call(
192 bb_data: &BasicBlockData<'tcx>,
193 caller_body: &Body<'tcx>,
194 ) -> Option<CallSite<'tcx>> {
195 // Don't inline calls that are in cleanup blocks.
196 if bb_data.is_cleanup {
200 // Only consider direct calls to functions
201 let terminator = bb_data.terminator();
202 if let TerminatorKind::Call { func: ref op, .. } = terminator.kind {
203 if let ty::FnDef(callee_def_id, substs) = *op.ty(caller_body, self.tcx).kind() {
204 let instance = Instance::resolve(self.tcx, self.param_env, callee_def_id, substs)
208 if let InstanceDef::Virtual(..) = instance.def {
212 return Some(CallSite {
213 callee: instance.def_id(),
214 substs: instance.substs,
216 location: terminator.source_info,
224 fn consider_optimizing(&self, callsite: CallSite<'tcx>, callee_body: &Body<'tcx>) -> bool {
225 debug!("consider_optimizing({:?})", callsite);
226 self.should_inline(callsite, callee_body)
227 && self.tcx.consider_optimizing(|| {
228 format!("Inline {:?} into {:?}", callee_body.span, callsite)
232 fn should_inline(&self, callsite: CallSite<'tcx>, callee_body: &Body<'tcx>) -> bool {
233 debug!("should_inline({:?})", callsite);
236 // Cannot inline generators which haven't been transformed yet
237 if callee_body.yield_ty.is_some() {
238 debug!(" yield ty present - not inlining");
242 let codegen_fn_attrs = tcx.codegen_fn_attrs(callsite.callee);
244 if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::TRACK_CALLER) {
245 debug!("`#[track_caller]` present - not inlining");
249 let self_features = &self.codegen_fn_attrs.target_features;
250 let callee_features = &codegen_fn_attrs.target_features;
251 if callee_features.iter().any(|feature| !self_features.contains(feature)) {
252 debug!("`callee has extra target features - not inlining");
256 let self_no_sanitize =
257 self.codegen_fn_attrs.no_sanitize & self.tcx.sess.opts.debugging_opts.sanitizer;
258 let callee_no_sanitize =
259 codegen_fn_attrs.no_sanitize & self.tcx.sess.opts.debugging_opts.sanitizer;
260 if self_no_sanitize != callee_no_sanitize {
261 debug!("`callee has incompatible no_sanitize attribute - not inlining");
265 let hinted = match codegen_fn_attrs.inline {
266 // Just treat inline(always) as a hint for now,
267 // there are cases that prevent inlining that we
268 // need to check for first.
269 attr::InlineAttr::Always => true,
270 attr::InlineAttr::Never => {
271 debug!("`#[inline(never)]` present - not inlining");
274 attr::InlineAttr::Hint => true,
275 attr::InlineAttr::None => false,
278 // Only inline local functions if they would be eligible for cross-crate
279 // inlining. This is to ensure that the final crate doesn't have MIR that
280 // reference unexported symbols
281 if callsite.callee.is_local() {
282 if callsite.substs.non_erasable_generics().count() == 0 && !hinted {
283 debug!(" callee is an exported function - not inlining");
288 let mut threshold = if hinted { HINT_THRESHOLD } else { DEFAULT_THRESHOLD };
290 // Significantly lower the threshold for inlining cold functions
291 if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
295 // Give a bonus functions with a small number of blocks,
296 // We normally have two or three blocks for even
297 // very small functions.
298 if callee_body.basic_blocks().len() <= 3 {
299 threshold += threshold / 4;
301 debug!(" final inline threshold = {}", threshold);
303 // FIXME: Give a bonus to functions with only a single caller
304 let mut first_block = true;
307 // Traverse the MIR manually so we can account for the effects of
308 // inlining on the CFG.
309 let mut work_list = vec![START_BLOCK];
310 let mut visited = BitSet::new_empty(callee_body.basic_blocks().len());
311 while let Some(bb) = work_list.pop() {
312 if !visited.insert(bb.index()) {
315 let blk = &callee_body.basic_blocks()[bb];
317 for stmt in &blk.statements {
318 // Don't count StorageLive/StorageDead in the inlining cost.
320 StatementKind::StorageLive(_)
321 | StatementKind::StorageDead(_)
322 | StatementKind::Nop => {}
323 _ => cost += INSTR_COST,
326 let term = blk.terminator();
327 let mut is_drop = false;
329 TerminatorKind::Drop { ref place, target, unwind }
330 | TerminatorKind::DropAndReplace { ref place, target, unwind, .. } => {
332 work_list.push(target);
333 // If the place doesn't actually need dropping, treat it like
335 let ty = place.ty(callee_body, tcx).subst(tcx, callsite.substs).ty;
336 if ty.needs_drop(tcx, self.param_env) {
337 cost += CALL_PENALTY;
338 if let Some(unwind) = unwind {
339 cost += LANDINGPAD_PENALTY;
340 work_list.push(unwind);
347 TerminatorKind::Unreachable | TerminatorKind::Call { destination: None, .. }
350 // If the function always diverges, don't inline
351 // unless the cost is zero
355 TerminatorKind::Call { func: Operand::Constant(ref f), cleanup, .. } => {
356 if let ty::FnDef(def_id, _) = *f.literal.ty.kind() {
357 // Don't give intrinsics the extra penalty for calls
358 let f = tcx.fn_sig(def_id);
359 if f.abi() == Abi::RustIntrinsic || f.abi() == Abi::PlatformIntrinsic {
362 cost += CALL_PENALTY;
365 cost += CALL_PENALTY;
367 if cleanup.is_some() {
368 cost += LANDINGPAD_PENALTY;
371 TerminatorKind::Assert { cleanup, .. } => {
372 cost += CALL_PENALTY;
374 if cleanup.is_some() {
375 cost += LANDINGPAD_PENALTY;
378 TerminatorKind::Resume => cost += RESUME_PENALTY,
379 _ => cost += INSTR_COST,
383 for &succ in term.successors() {
384 work_list.push(succ);
391 // Count up the cost of local variables and temps, if we know the size
392 // use that, otherwise we use a moderately-large dummy cost.
394 let ptr_size = tcx.data_layout.pointer_size.bytes();
396 for v in callee_body.vars_and_temps_iter() {
397 let v = &callee_body.local_decls[v];
398 let ty = v.ty.subst(tcx, callsite.substs);
399 // Cost of the var is the size in machine-words, if we know
401 if let Some(size) = type_size_of(tcx, self.param_env, ty) {
402 cost += (size / ptr_size) as usize;
404 cost += UNKNOWN_SIZE_COST;
408 if let attr::InlineAttr::Always = codegen_fn_attrs.inline {
409 debug!("INLINING {:?} because inline(always) [cost={}]", callsite, cost);
412 if cost <= threshold {
413 debug!("INLINING {:?} [cost={} <= threshold={}]", callsite, cost, threshold);
416 debug!("NOT inlining {:?} [cost={} > threshold={}]", callsite, cost, threshold);
424 callsite: CallSite<'tcx>,
425 caller_body: &mut Body<'tcx>,
426 mut callee_body: Body<'tcx>,
428 let terminator = caller_body[callsite.bb].terminator.take().unwrap();
429 match terminator.kind {
430 // FIXME: Handle inlining of diverging calls
431 TerminatorKind::Call { args, destination: Some(destination), cleanup, .. } => {
432 debug!("inlined {:?} into {:?}", callsite.callee, caller_body.source);
434 let mut local_map = IndexVec::with_capacity(callee_body.local_decls.len());
435 let mut scope_map = IndexVec::with_capacity(callee_body.source_scopes.len());
437 for mut scope in callee_body.source_scopes.iter().cloned() {
438 if scope.parent_scope.is_none() {
439 scope.parent_scope = Some(callsite.location.scope);
440 // FIXME(eddyb) is this really needed?
441 // (also note that it's always overwritten below)
442 scope.span = callee_body.span;
445 // FIXME(eddyb) this doesn't seem right at all.
446 // The inlined source scopes should probably be annotated as
447 // such, but also contain all of the original information.
448 scope.span = callsite.location.span;
450 let idx = caller_body.source_scopes.push(scope);
454 for loc in callee_body.vars_and_temps_iter() {
455 let mut local = callee_body.local_decls[loc].clone();
457 local.source_info.scope = scope_map[local.source_info.scope];
458 local.source_info.span = callsite.location.span;
460 let idx = caller_body.local_decls.push(local);
464 // If the call is something like `a[*i] = f(i)`, where
465 // `i : &mut usize`, then just duplicating the `a[*i]`
466 // Place could result in two different locations if `f`
467 // writes to `i`. To prevent this we need to create a temporary
468 // borrow of the place and pass the destination as `*temp` instead.
469 fn dest_needs_borrow(place: Place<'_>) -> bool {
470 for elem in place.projection.iter() {
472 ProjectionElem::Deref | ProjectionElem::Index(_) => return true,
480 let dest = if dest_needs_borrow(destination.0) {
481 debug!("creating temp for return destination");
482 let dest = Rvalue::Ref(
483 self.tcx.lifetimes.re_erased,
484 BorrowKind::Mut { allow_two_phase_borrow: false },
488 let ty = dest.ty(caller_body, self.tcx);
490 let temp = LocalDecl::new(ty, callsite.location.span);
492 let tmp = caller_body.local_decls.push(temp);
493 let tmp = Place::from(tmp);
495 let stmt = Statement {
496 source_info: callsite.location,
497 kind: StatementKind::Assign(box (tmp, dest)),
499 caller_body[callsite.bb].statements.push(stmt);
500 self.tcx.mk_place_deref(tmp)
505 let return_block = destination.1;
507 // Copy the arguments if needed.
508 let args: Vec<_> = self.make_call_args(args, &callsite, caller_body, return_block);
510 let bb_len = caller_body.basic_blocks().len();
511 let mut integrator = Integrator {
518 cleanup_block: cleanup,
519 in_cleanup_block: false,
523 for mut var_debug_info in callee_body.var_debug_info.drain(..) {
524 integrator.visit_var_debug_info(&mut var_debug_info);
525 caller_body.var_debug_info.push(var_debug_info);
528 for (bb, mut block) in callee_body.basic_blocks_mut().drain_enumerated(..) {
529 integrator.visit_basic_block_data(bb, &mut block);
530 caller_body.basic_blocks_mut().push(block);
533 let terminator = Terminator {
534 source_info: callsite.location,
535 kind: TerminatorKind::Goto { target: BasicBlock::new(bb_len) },
538 caller_body[callsite.bb].terminator = Some(terminator);
543 caller_body[callsite.bb].terminator =
544 Some(Terminator { source_info: terminator.source_info, kind });
552 args: Vec<Operand<'tcx>>,
553 callsite: &CallSite<'tcx>,
554 caller_body: &mut Body<'tcx>,
555 return_block: BasicBlock,
559 // There is a bit of a mismatch between the *caller* of a closure and the *callee*.
560 // The caller provides the arguments wrapped up in a tuple:
562 // tuple_tmp = (a, b, c)
563 // Fn::call(closure_ref, tuple_tmp)
565 // meanwhile the closure body expects the arguments (here, `a`, `b`, and `c`)
566 // as distinct arguments. (This is the "rust-call" ABI hack.) Normally, codegen has
567 // the job of unpacking this tuple. But here, we are codegen. =) So we want to create
570 // [closure_ref, tuple_tmp.0, tuple_tmp.1, tuple_tmp.2]
572 // Except for one tiny wrinkle: we don't actually want `tuple_tmp.0`. It's more convenient
573 // if we "spill" that into *another* temporary, so that we can map the argument
574 // variable in the callee MIR directly to an argument variable on our side.
575 // So we introduce temporaries like:
577 // tmp0 = tuple_tmp.0
578 // tmp1 = tuple_tmp.1
579 // tmp2 = tuple_tmp.2
581 // and the vector is `[closure_ref, tmp0, tmp1, tmp2]`.
582 if tcx.is_closure(callsite.callee) {
583 let mut args = args.into_iter();
584 let self_ = self.create_temp_if_necessary(
585 args.next().unwrap(),
590 let tuple = self.create_temp_if_necessary(
591 args.next().unwrap(),
596 assert!(args.next().is_none());
598 let tuple = Place::from(tuple);
599 let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body, tcx).ty.kind() {
602 bug!("Closure arguments are not passed as a tuple");
605 // The `closure_ref` in our example above.
606 let closure_ref_arg = iter::once(self_);
608 // The `tmp0`, `tmp1`, and `tmp2` in our example abonve.
609 let tuple_tmp_args = tuple_tys.iter().enumerate().map(|(i, ty)| {
610 // This is e.g., `tuple_tmp.0` in our example above.
612 Operand::Move(tcx.mk_place_field(tuple, Field::new(i), ty.expect_ty()));
614 // Spill to a local to make e.g., `tmp0`.
615 self.create_temp_if_necessary(tuple_field, callsite, caller_body, return_block)
618 closure_ref_arg.chain(tuple_tmp_args).collect()
621 .map(|a| self.create_temp_if_necessary(a, callsite, caller_body, return_block))
626 /// If `arg` is already a temporary, returns it. Otherwise, introduces a fresh
627 /// temporary `T` and an instruction `T = arg`, and returns `T`.
628 fn create_temp_if_necessary(
631 callsite: &CallSite<'tcx>,
632 caller_body: &mut Body<'tcx>,
633 return_block: BasicBlock,
635 // FIXME: Analysis of the usage of the arguments to avoid
636 // unnecessary temporaries.
638 if let Operand::Move(place) = &arg {
639 if let Some(local) = place.as_local() {
640 if caller_body.local_kind(local) == LocalKind::Temp {
641 // Reuse the operand if it's a temporary already
647 debug!("creating temp for argument {:?}", arg);
648 // Otherwise, create a temporary for the arg
649 let arg = Rvalue::Use(arg);
651 let ty = arg.ty(caller_body, self.tcx);
653 let arg_tmp = LocalDecl::new(ty, callsite.location.span);
654 let arg_tmp = caller_body.local_decls.push(arg_tmp);
656 caller_body[callsite.bb].statements.push(Statement {
657 source_info: callsite.location,
658 kind: StatementKind::StorageLive(arg_tmp),
660 caller_body[callsite.bb].statements.push(Statement {
661 source_info: callsite.location,
662 kind: StatementKind::Assign(box (Place::from(arg_tmp), arg)),
664 caller_body[return_block].statements.insert(
666 Statement { source_info: callsite.location, kind: StatementKind::StorageDead(arg_tmp) },
673 fn type_size_of<'tcx>(
675 param_env: ty::ParamEnv<'tcx>,
678 tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes())
684 * Integrates blocks from the callee function into the calling function.
685 * Updates block indices, references to locals and other control flow
688 struct Integrator<'a, 'tcx> {
691 local_map: IndexVec<Local, Local>,
692 scope_map: IndexVec<SourceScope, SourceScope>,
693 destination: Place<'tcx>,
694 return_block: BasicBlock,
695 cleanup_block: Option<BasicBlock>,
696 in_cleanup_block: bool,
700 impl<'a, 'tcx> Integrator<'a, 'tcx> {
701 fn update_target(&self, tgt: BasicBlock) -> BasicBlock {
702 let new = BasicBlock::new(tgt.index() + self.block_idx);
703 debug!("updating target `{:?}`, new: `{:?}`", tgt, new);
707 fn make_integrate_local(&self, local: Local) -> Local {
708 if local == RETURN_PLACE {
709 return self.destination.local;
712 let idx = local.index() - 1;
713 if idx < self.args.len() {
714 return self.args[idx];
717 self.local_map[Local::new(idx - self.args.len())]
721 impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
722 fn tcx(&self) -> TyCtxt<'tcx> {
726 fn visit_local(&mut self, local: &mut Local, _ctxt: PlaceContext, _location: Location) {
727 *local = self.make_integrate_local(*local);
730 fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) {
731 // If this is the `RETURN_PLACE`, we need to rebase any projections onto it.
732 let dest_proj_len = self.destination.projection.len();
733 if place.local == RETURN_PLACE && dest_proj_len > 0 {
734 let mut projs = Vec::with_capacity(dest_proj_len + place.projection.len());
735 projs.extend(self.destination.projection);
736 projs.extend(place.projection);
738 place.projection = self.tcx.intern_place_elems(&*projs);
740 // Handles integrating any locals that occur in the base
742 self.super_place(place, context, location)
745 fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
746 self.in_cleanup_block = data.is_cleanup;
747 self.super_basic_block_data(block, data);
748 self.in_cleanup_block = false;
751 fn visit_retag(&mut self, kind: &mut RetagKind, place: &mut Place<'tcx>, loc: Location) {
752 self.super_retag(kind, place, loc);
754 // We have to patch all inlined retags to be aware that they are no longer
755 // happening on function entry.
756 if *kind == RetagKind::FnEntry {
757 *kind = RetagKind::Default;
761 fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, loc: Location) {
762 // Don't try to modify the implicit `_0` access on return (`return` terminators are
763 // replaced down below anyways).
764 if !matches!(terminator.kind, TerminatorKind::Return) {
765 self.super_terminator(terminator, loc);
768 match terminator.kind {
769 TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => bug!(),
770 TerminatorKind::Goto { ref mut target } => {
771 *target = self.update_target(*target);
773 TerminatorKind::SwitchInt { ref mut targets, .. } => {
775 *tgt = self.update_target(*tgt);
778 TerminatorKind::Drop { ref mut target, ref mut unwind, .. }
779 | TerminatorKind::DropAndReplace { ref mut target, ref mut unwind, .. } => {
780 *target = self.update_target(*target);
781 if let Some(tgt) = *unwind {
782 *unwind = Some(self.update_target(tgt));
783 } else if !self.in_cleanup_block {
784 // Unless this drop is in a cleanup block, add an unwind edge to
785 // the original call's cleanup block
786 *unwind = self.cleanup_block;
789 TerminatorKind::Call { ref mut destination, ref mut cleanup, .. } => {
790 if let Some((_, ref mut tgt)) = *destination {
791 *tgt = self.update_target(*tgt);
793 if let Some(tgt) = *cleanup {
794 *cleanup = Some(self.update_target(tgt));
795 } else if !self.in_cleanup_block {
796 // Unless this call is in a cleanup block, add an unwind edge to
797 // the original call's cleanup block
798 *cleanup = self.cleanup_block;
801 TerminatorKind::Assert { ref mut target, ref mut cleanup, .. } => {
802 *target = self.update_target(*target);
803 if let Some(tgt) = *cleanup {
804 *cleanup = Some(self.update_target(tgt));
805 } else if !self.in_cleanup_block {
806 // Unless this assert is in a cleanup block, add an unwind edge to
807 // the original call's cleanup block
808 *cleanup = self.cleanup_block;
811 TerminatorKind::Return => {
812 terminator.kind = TerminatorKind::Goto { target: self.return_block };
814 TerminatorKind::Resume => {
815 if let Some(tgt) = self.cleanup_block {
816 terminator.kind = TerminatorKind::Goto { target: tgt }
819 TerminatorKind::Abort => {}
820 TerminatorKind::Unreachable => {}
821 TerminatorKind::FalseEdge { ref mut real_target, ref mut imaginary_target } => {
822 *real_target = self.update_target(*real_target);
823 *imaginary_target = self.update_target(*imaginary_target);
825 TerminatorKind::FalseUnwind { real_target: _, unwind: _ } =>
826 // see the ordering of passes in the optimized_mir query.
828 bug!("False unwinds should have been removed before inlining")
830 TerminatorKind::InlineAsm { ref mut destination, .. } => {
831 if let Some(ref mut tgt) = *destination {
832 *tgt = self.update_target(*tgt);
838 fn visit_source_scope(&mut self, scope: &mut SourceScope) {
839 *scope = self.scope_map[*scope];