1use std::iter;
23use rustc_index::IndexVec;
4use rustc_index::bit_set::DenseBitSet;
5use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
6use rustc_middle::mir;
7use rustc_middle::mir::{Body, Local, UnwindTerminateReason, traversal};
8use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, TyAndLayout};
9use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
10use rustc_span::{ErrorGuaranteed, bug, span_bug};
11use rustc_target::callconv::{FnAbi, IndirectMode, PassMode};
12use tracing::{debug, instrument};
1314use crate::base;
15use crate::traits::*;
1617mod analyze;
18mod block;
19mod constant;
20mod coverageinfo;
21pub mod debuginfo;
22mod intrinsic;
23mod locals;
24pub mod naked_asm;
25pub mod operand;
26pub mod place;
27mod retag;
28mod rvalue;
29mod statement;
3031pub use self::block::store_cast;
32use self::debuginfo::{FunctionDebugContext, PerLocalVarDebugInfo};
33use self::operand::{OperandRef, OperandValue};
34use self::place::PlaceRef;
3536// Used for tracking the state of generated basic blocks.
37enum CachedLlbb<T> {
38/// Nothing created yet.
39None,
4041/// Has been created.
42Some(T),
4344/// Nothing created yet, and nothing should be.
45Skip,
46}
4748type PerLocalVarDebugInfoIndexVec<'tcx, V> =
49IndexVec<mir::Local, Vec<PerLocalVarDebugInfo<'tcx, V>>>;
5051/// Master context for codegenning from MIR.
52pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
53 instance: Instance<'tcx>,
5455 mir: &'tcx mir::Body<'tcx>,
5657 debug_context: Option<FunctionDebugContext<'tcx, Bx::DIScope, Bx::DILocation>>,
5859 llfn: Bx::Function,
6061 cx: &'a Bx::CodegenCx,
6263 fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
6465/// When unwinding is initiated, we have to store this personality
66 /// value somewhere so that we can load it and re-use it in the
67 /// resume instruction. The personality is (afaik) some kind of
68 /// value used for C++ unwinding, which must filter by type: we
69 /// don't really care about it very much. Anyway, this value
70 /// contains an alloca into which the personality is stored and
71 /// then later loaded when generating the DIVERGE_BLOCK.
72personality_slot: Option<PlaceRef<'tcx, Bx::Value>>,
7374/// A backend `BasicBlock` for each MIR `BasicBlock`, created lazily
75 /// as-needed (e.g. RPO reaching it or another block branching to it).
76// FIXME(eddyb) rename `llbbs` and other `ll`-prefixed things to use a
77 // more backend-agnostic prefix such as `cg` (i.e. this would be `cgbbs`).
78cached_llbbs: IndexVec<mir::BasicBlock, CachedLlbb<Bx::BasicBlock>>,
7980/// The funclet status of each basic block
81cleanup_kinds: Option<IndexVec<mir::BasicBlock, analyze::CleanupKind>>,
8283/// When targeting MSVC, this stores the cleanup info for each funclet BB.
84 /// This is initialized at the same time as the `landing_pads` entry for the
85 /// funclets' head block, i.e. when needed by an unwind / `cleanup_ret` edge.
86funclets: IndexVec<mir::BasicBlock, Option<Bx::Funclet>>,
8788/// This stores the cached landing/cleanup pad block for a given BB.
89// FIXME(eddyb) rename this to `eh_pads`.
90landing_pads: IndexVec<mir::BasicBlock, Option<Bx::BasicBlock>>,
9192/// Cached unreachable block
93unreachable_block: Option<Bx::BasicBlock>,
9495/// Cached terminate upon unwinding block and its reason. For non-wasm
96 /// targets, there is at most one such block per function, stored at index
97 /// `START_BLOCK`. For wasm targets, each funclet needs its own terminate
98 /// block, indexed by the cleanup block that is the funclet's head.
99terminate_blocks: IndexVec<mir::BasicBlock, Option<(Bx::BasicBlock, UnwindTerminateReason)>>,
100101/// A cold block is a block that is unlikely to be executed at runtime.
102cold_blocks: DenseBitSet<mir::BasicBlock>,
103104 nop_landing_pads: DenseBitSet<mir::BasicBlock>,
105106/// The location where each MIR arg/var/tmp/ret is stored. This is
107 /// usually an `PlaceRef` representing an alloca, but not always:
108 /// sometimes we can skip the alloca and just store the value
109 /// directly using an `OperandRef`, which makes for tighter LLVM
110 /// IR. The conditions for using an `OperandRef` are as follows:
111 ///
112 /// - the type of the local must be judged "immediate" by `is_llvm_immediate`
113 /// - the operand must never be referenced indirectly
114 /// - we should not take its address using the `&` operator
115 /// - nor should it appear in a place path like `tmp.a`
116 /// - the operand must be defined by an rvalue that can generate immediate
117 /// values
118 ///
119 /// Avoiding allocs can also be important for certain intrinsics,
120 /// notably `expect`.
121locals: locals::Locals<'tcx, Bx::Value>,
122123/// All `VarDebugInfo` from the MIR body, partitioned by `Local`.
124 /// This is `None` if no variable debuginfo/names are needed.
125per_local_var_debug_info: Option<PerLocalVarDebugInfoIndexVec<'tcx, Bx::DIVariable>>,
126127/// Caller location propagated if this function has `#[track_caller]`.
128caller_location: Option<OperandRef<'tcx, Bx::Value>>,
129}
130131impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
132pub fn monomorphize<T>(&self, value: T) -> T
133where
134T: Copy + TypeFoldable<TyCtxt<'tcx>>,
135 {
136{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs:136",
"rustc_codegen_ssa::mir", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs"),
::tracing_core::__macro_support::Option::Some(136u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("monomorphize: self.instance={0:?}",
self.instance) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("monomorphize: self.instance={:?}", self.instance);
137self.instance.instantiate_mir_and_normalize_erasing_regions(
138self.cx.tcx(),
139self.cx.typing_env(),
140 ty::EarlyBinder::bind(self.cx.tcx(), value),
141 )
142 }
143}
144145enum LocalRef<'tcx, V> {
146 Place(PlaceRef<'tcx, V>),
147/// `UnsizedPlace(p)`: `p` itself is a thin pointer (indirect place).
148 /// `*p` is the wide pointer that references the actual unsized place.
149 ///
150 /// MIR only supports unsized args, not dynamically-sized locals, so
151 /// new unsized temps don't exist and we must reuse the referred-to place.
152 ///
153 /// FIXME: Since the removal of unsized locals in <https://github.com/rust-lang/rust/pull/142911>,
154 /// can we maybe use `Place` here? Or refactor it in another way? There are quite a few
155 /// `UnsizedPlace => bug` branches now.
156UnsizedPlace(PlaceRef<'tcx, V>),
157/// The backend [`OperandValue`] has already been generated.
158Operand(OperandRef<'tcx, V>),
159/// Will be a `Self::Operand` once we get to its definition.
160PendingOperand,
161}
162163pub enum IntrinsicResult<'tcx, V> {
164/// This intrinsic created an operand without using the `result_place` argument.
165 ///
166 /// `codegen_call_terminator` will handle writing the result into the place,
167 /// if doing so is needed.
168 ///
169 /// The vast majority of intrinsics can do this, see MCP#970
170Operand(OperandValue<V>),
171172/// The intrinsic wrote its result into the `result_place` argument.
173 ///
174 /// Most things don't need to do this, but there are some: `volatile_load`
175 /// of a non-scalar type, for example, has to.
176WroteIntoPlace,
177178/// Another instance should be called instead. This is used to invoke intrinsic
179 /// default bodies in case an intrinsic is not implemented by the backend.
180Fallback(ty::Instance<'tcx>),
181182/// Arguably this shouldn't exist, per MCP#620, but a bunch do it.
183Err(ErrorGuaranteed),
184}
185186impl<'tcx, V: CodegenObject> LocalRef<'tcx, V> {
187fn new_operand(layout: TyAndLayout<'tcx>) -> LocalRef<'tcx, V> {
188if layout.is_zst() {
189// Zero-size temporaries aren't always initialized, which
190 // doesn't matter because they don't contain data, but
191 // we need something sufficiently aligned in the operand.
192LocalRef::Operand(OperandRef::zero_sized(layout))
193 } else {
194 LocalRef::PendingOperand195 }
196 }
197}
198199///////////////////////////////////////////////////////////////////////////
200201{}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("codegen_mir",
"rustc_codegen_ssa::mir", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs"),
::tracing_core::__macro_support::Option::Some(201u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("instance")
}> =
::tracing::__macro_support::FieldName::new("instance");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instance)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if !!instance.args.has_infer() {
::core::panicking::panic("assertion failed: !instance.args.has_infer()")
};
let tcx = cx.tcx();
let llfn = cx.get_fn(instance);
let mut mir = tcx.instance_mir(instance.def);
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs:217",
"rustc_codegen_ssa::mir", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs"),
::tracing_core::__macro_support::Option::Some(217u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("fn_abi: {0:?}",
fn_abi) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let nop_landing_pads =
tcx.find_noop_landing_pads_for_instance(mir, instance,
cx.typing_env());
if tcx.features().ergonomic_clones() {
let monomorphized_mir =
instance.instantiate_mir_and_normalize_erasing_regions(tcx,
cx.typing_env(), ty::EarlyBinder::bind(tcx, mir.clone()));
mir =
tcx.arena.alloc(optimize_use_clone::<Bx>(cx,
monomorphized_mir));
}
let start_llbb = Bx::append_block(cx, llfn, "start");
let mut start_bx = Bx::build(cx, start_llbb);
if mir::traversal::mono_reachable(&mir, tcx,
instance).any(|(bb, block)|
{
(block.is_cleanup && !nop_landing_pads.contains(bb)) ||
#[allow(non_exhaustive_omitted_patterns)] match block.terminator().unwind()
{
Some(mir::UnwindAction::Terminate(_)) => true,
_ => false,
}
}) {
start_bx.set_personality_fn(cx.eh_personality());
}
let cleanup_kinds =
base::wants_new_eh_instructions(&tcx.sess.target).then(||
analyze::cleanup_kinds(&mir, &nop_landing_pads));
let cached_llbbs:
IndexVec<mir::BasicBlock, CachedLlbb<Bx::BasicBlock>> =
mir.basic_blocks.indices().map(|bb|
{
if bb == mir::START_BLOCK {
CachedLlbb::Some(start_llbb)
} else { CachedLlbb::None }
}).collect();
let mut fx =
FunctionCx {
instance,
mir,
llfn,
fn_abi,
cx,
personality_slot: None,
cached_llbbs,
unreachable_block: None,
terminate_blocks: IndexVec::from_elem(None,
&mir.basic_blocks),
cleanup_kinds,
landing_pads: IndexVec::from_elem(None, &mir.basic_blocks),
funclets: IndexVec::from_fn_n(|_| None,
mir.basic_blocks.len()),
cold_blocks: find_cold_blocks(tcx, mir),
locals: locals::Locals::empty(),
debug_context: None,
per_local_var_debug_info: None,
caller_location: None,
nop_landing_pads,
};
fx.fill_function_debug_context(&mut start_bx);
let (per_local_var_debug_info, consts_debug_info) =
fx.compute_per_local_var_debug_info(&mut start_bx).unzip();
fx.per_local_var_debug_info = per_local_var_debug_info;
let mut traversal_order =
traversal::mono_reachable_reverse_postorder(mir, tcx,
instance);
{
let mut reachable =
DenseBitSet::new_empty(mir.basic_blocks.len());
let mut to_visit =
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[mir::START_BLOCK]));
while let Some(next) = to_visit.pop() {
if !reachable.insert(next) { continue; }
let block = &mir.basic_blocks[next];
let successors = block.mono_successors(tcx, instance);
if let Some(mir::UnwindAction::Cleanup(target)) =
block.terminator().unwind() &&
fx.nop_landing_pads.contains(*target) {
to_visit.extend(successors.filter(|s| s != target));
} else { to_visit.extend(successors); }
}
traversal_order.retain(|bb| reachable.contains(*bb));
}
let memory_locals =
analyze::non_ssa_locals(&fx, &traversal_order);
let local_values =
{
let args =
arg_local_refs(&mut start_bx, &mut fx, &memory_locals);
let mut allocate_local =
|local: Local|
{
let decl = &mir.local_decls[local];
let layout = start_bx.layout_of(fx.monomorphize(decl.ty));
if !!layout.ty.has_erasable_regions() {
::core::panicking::panic("assertion failed: !layout.ty.has_erasable_regions()")
};
if local == mir::RETURN_PLACE {
match fx.fn_abi.ret.mode {
PassMode::Indirect { .. } => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs:329",
"rustc_codegen_ssa::mir", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs"),
::tracing_core::__macro_support::Option::Some(329u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("alloc: {0:?} (return place) -> place",
local) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let llretptr = start_bx.get_param(0);
return LocalRef::Place(PlaceRef::new_sized(llretptr,
layout));
}
PassMode::Cast { ref cast, .. } => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs:334",
"rustc_codegen_ssa::mir", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs"),
::tracing_core::__macro_support::Option::Some(334u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("alloc: {0:?} (return place) -> place",
local) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let size = cast.size(&start_bx).max(layout.size);
return LocalRef::Place(PlaceRef::alloca_size(&mut start_bx,
size, layout));
}
PassMode::IndirectUnsized { .. } =>
::rustc_span::macros::bug_impl(None,
format_args!("unsized returns are not supported"),
Location::caller()),
_ => {}
};
}
if memory_locals.contains(local) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs:344",
"rustc_codegen_ssa::mir", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs"),
::tracing_core::__macro_support::Option::Some(344u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("alloc: {0:?} -> place",
local) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if layout.is_unsized() {
LocalRef::UnsizedPlace(PlaceRef::alloca_unsized_indirect(&mut start_bx,
layout))
} else {
LocalRef::Place(PlaceRef::alloca(&mut start_bx, layout))
}
} else {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs:351",
"rustc_codegen_ssa::mir", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/249c1e4e31111b54ad2483cfd4cea06c7020c653/compiler/rustc_codegen_ssa/src/mir/mod.rs"),
::tracing_core::__macro_support::Option::Some(351u32),
::tracing_core::__macro_support::Option::Some("rustc_codegen_ssa::mir"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("alloc: {0:?} -> operand",
local) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
LocalRef::new_operand(layout)
}
};
let retptr = allocate_local(mir::RETURN_PLACE);
iter::once(retptr).chain(args.into_iter()).chain(mir.vars_and_temps_iter().map(allocate_local)).collect()
};
fx.initialize_locals(local_values);
fx.debug_introduce_locals(&mut start_bx,
consts_debug_info.unwrap_or_default());
drop(start_bx);
let mut unreached_blocks =
DenseBitSet::new_filled(mir.basic_blocks.len());
for bb in traversal_order {
fx.codegen_block(bb);
unreached_blocks.remove(bb);
}
for bb in unreached_blocks.iter() {
fx.codegen_block_as_unreachable(bb);
}
}
}
}#[instrument(level = "debug", skip(cx))]202pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
203 cx: &'a Bx::CodegenCx,
204 instance: Instance<'tcx>,
205) {
206assert!(!instance.args.has_infer());
207208let tcx = cx.tcx();
209let llfn = cx.get_fn(instance);
210211let mut mir = tcx.instance_mir(instance.def);
212// Note that the ABI logic has deduced facts about the functions' parameters based on the MIR we
213 // got here (`deduce_param_attrs`). That means we can *not* apply arbitrary further MIR
214 // transforms as that may invalidate those deduced facts!
215216let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
217debug!("fn_abi: {:?}", fn_abi);
218219let nop_landing_pads = tcx.find_noop_landing_pads_for_instance(mir, instance, cx.typing_env());
220221if tcx.features().ergonomic_clones() {
222let monomorphized_mir = instance.instantiate_mir_and_normalize_erasing_regions(
223 tcx,
224 cx.typing_env(),
225 ty::EarlyBinder::bind(tcx, mir.clone()),
226 );
227 mir = tcx.arena.alloc(optimize_use_clone::<Bx>(cx, monomorphized_mir));
228 }
229230let start_llbb = Bx::append_block(cx, llfn, "start");
231let mut start_bx = Bx::build(cx, start_llbb);
232233if mir::traversal::mono_reachable(&mir, tcx, instance).any(|(bb, block)| {
234 (block.is_cleanup && !nop_landing_pads.contains(bb))
235 || matches!(block.terminator().unwind(), Some(mir::UnwindAction::Terminate(_)))
236 }) {
237 start_bx.set_personality_fn(cx.eh_personality());
238 }
239240let cleanup_kinds = base::wants_new_eh_instructions(&tcx.sess.target)
241 .then(|| analyze::cleanup_kinds(&mir, &nop_landing_pads));
242243let cached_llbbs: IndexVec<mir::BasicBlock, CachedLlbb<Bx::BasicBlock>> =
244 mir.basic_blocks
245 .indices()
246 .map(|bb| {
247if bb == mir::START_BLOCK { CachedLlbb::Some(start_llbb) } else { CachedLlbb::None }
248 })
249 .collect();
250251let mut fx = FunctionCx {
252 instance,
253 mir,
254 llfn,
255 fn_abi,
256 cx,
257 personality_slot: None,
258 cached_llbbs,
259 unreachable_block: None,
260 terminate_blocks: IndexVec::from_elem(None, &mir.basic_blocks),
261 cleanup_kinds,
262 landing_pads: IndexVec::from_elem(None, &mir.basic_blocks),
263 funclets: IndexVec::from_fn_n(|_| None, mir.basic_blocks.len()),
264 cold_blocks: find_cold_blocks(tcx, mir),
265 locals: locals::Locals::empty(),
266 debug_context: None,
267 per_local_var_debug_info: None,
268 caller_location: None,
269 nop_landing_pads,
270 };
271272// It may seem like we should iterate over `required_consts` to ensure they all successfully
273 // evaluate; however, the `MirUsedCollector` already did that during the collection phase of
274 // monomorphization, and if there is an error during collection then codegen never starts -- so
275 // we don't have to do it again.
276277fx.fill_function_debug_context(&mut start_bx);
278279let (per_local_var_debug_info, consts_debug_info) =
280 fx.compute_per_local_var_debug_info(&mut start_bx).unzip();
281 fx.per_local_var_debug_info = per_local_var_debug_info;
282283let mut traversal_order = traversal::mono_reachable_reverse_postorder(mir, tcx, instance);
284285// Filter out blocks that won't be codegen'd because of nop_landing_pads optimization.
286 // FIXME: We might want to integrate the nop_landing_pads analysis into mono reachability.
287{
288let mut reachable = DenseBitSet::new_empty(mir.basic_blocks.len());
289let mut to_visit = vec![mir::START_BLOCK];
290while let Some(next) = to_visit.pop() {
291if !reachable.insert(next) {
292continue;
293 }
294295let block = &mir.basic_blocks[next];
296let successors = block.mono_successors(tcx, instance);
297298if let Some(mir::UnwindAction::Cleanup(target)) = block.terminator().unwind()
299 && fx.nop_landing_pads.contains(*target)
300 {
301// This edge will not be followed when we actually codegen, so skip generating it here.
302 //
303 // It's guaranteed that the cleanup block (`target`) occurs only in
304 // UnwindAction::Cleanup(...) -- i.e., we can't incorrectly filter too much here --
305 // because cleanup transitions must happen via UnwindAction::Cleanup.
306to_visit.extend(successors.filter(|s| s != target));
307 } else {
308 to_visit.extend(successors);
309 }
310 }
311312 traversal_order.retain(|bb| reachable.contains(*bb));
313 }
314315let memory_locals = analyze::non_ssa_locals(&fx, &traversal_order);
316317// Allocate variable and temp allocas
318let local_values = {
319let args = arg_local_refs(&mut start_bx, &mut fx, &memory_locals);
320321let mut allocate_local = |local: Local| {
322let decl = &mir.local_decls[local];
323let layout = start_bx.layout_of(fx.monomorphize(decl.ty));
324assert!(!layout.ty.has_erasable_regions());
325326if local == mir::RETURN_PLACE {
327match fx.fn_abi.ret.mode {
328 PassMode::Indirect { .. } => {
329debug!("alloc: {:?} (return place) -> place", local);
330let llretptr = start_bx.get_param(0);
331return LocalRef::Place(PlaceRef::new_sized(llretptr, layout));
332 }
333 PassMode::Cast { ref cast, .. } => {
334debug!("alloc: {:?} (return place) -> place", local);
335let size = cast.size(&start_bx).max(layout.size);
336return LocalRef::Place(PlaceRef::alloca_size(&mut start_bx, size, layout));
337 }
338 PassMode::IndirectUnsized { .. } => bug!("unsized returns are not supported"),
339_ => {}
340 };
341 }
342343if memory_locals.contains(local) {
344debug!("alloc: {:?} -> place", local);
345if layout.is_unsized() {
346 LocalRef::UnsizedPlace(PlaceRef::alloca_unsized_indirect(&mut start_bx, layout))
347 } else {
348 LocalRef::Place(PlaceRef::alloca(&mut start_bx, layout))
349 }
350 } else {
351debug!("alloc: {:?} -> operand", local);
352 LocalRef::new_operand(layout)
353 }
354 };
355356let retptr = allocate_local(mir::RETURN_PLACE);
357 iter::once(retptr)
358 .chain(args.into_iter())
359 .chain(mir.vars_and_temps_iter().map(allocate_local))
360 .collect()
361 };
362 fx.initialize_locals(local_values);
363364// Apply debuginfo to the newly allocated locals.
365fx.debug_introduce_locals(&mut start_bx, consts_debug_info.unwrap_or_default());
366367// The builders will be created separately for each basic block at `codegen_block`.
368 // So drop the builder of `start_llbb` to avoid having two at the same time.
369drop(start_bx);
370371let mut unreached_blocks = DenseBitSet::new_filled(mir.basic_blocks.len());
372// Codegen the body of each reachable block using our reverse postorder list.
373for bb in traversal_order {
374 fx.codegen_block(bb);
375 unreached_blocks.remove(bb);
376 }
377378// FIXME: These empty unreachable blocks are *mostly* a waste. They are occasionally
379 // targets for a SwitchInt terminator, but the reimplementation of the mono-reachable
380 // simplification in SwitchInt lowering sometimes misses cases that
381 // mono_reachable_reverse_postorder manages to figure out.
382 // The solution is to do something like post-mono GVN. But for now we have this hack.
383for bb in unreached_blocks.iter() {
384 fx.codegen_block_as_unreachable(bb);
385 }
386}
387388/// Replace `clone` calls that come from `use` statements with direct copies if possible.
389// FIXME: Move this function to mir::transform when post-mono MIR passes land.
390fn optimize_use_clone<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
391 cx: &'a Bx::CodegenCx,
392mut mir: Body<'tcx>,
393) -> Body<'tcx> {
394let tcx = cx.tcx();
395396if tcx.features().ergonomic_clones() {
397for bb in mir.basic_blocks.as_mut() {
398let mir::TerminatorKind::Call {
399 args,
400 destination,
401 target,
402 call_source: mir::CallSource::Use,
403 ..
404 } = &bb.terminator().kind
405else {
406continue;
407 };
408409// CallSource::Use calls always use 1 argument.
410{
match (&args.len(), &1) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(args.len(), 1);
411let arg = &args[0];
412413// These types are easily available from locals, so check that before
414 // doing DefId lookups to figure out what we're actually calling.
415let arg_ty = arg.node.ty(&mir.local_decls, tcx);
416417let ty::Ref(_region, inner_ty, mir::Mutability::Not) = *arg_ty.kind() else { continue };
418419if !tcx.type_is_copy_modulo_regions(cx.typing_env(), inner_ty) {
420continue;
421 }
422423let Some(arg_place) = arg.node.place() else { continue };
424425let destination_block = target.unwrap();
426427 bb.statements.push(mir::Statement::new(
428 bb.terminator().source_info,
429 mir::StatementKind::Assign(Box::new((
430*destination,
431 mir::Rvalue::Use(
432 mir::Operand::Copy(
433 arg_place.project_deeper(&[mir::ProjectionElem::Deref], tcx),
434 ),
435 mir::WithRetag::Yes,
436 ),
437 ))),
438 ));
439440 bb.terminator_mut().kind = mir::TerminatorKind::goto(destination_block);
441 }
442 }
443444mir445}
446447/// Produces, for each argument, a `Value` pointing at the
448/// argument's value. As arguments are places, these are always
449/// indirect.
450fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
451 bx: &mut Bx,
452 fx: &mut FunctionCx<'a, 'tcx, Bx>,
453 memory_locals: &DenseBitSet<mir::Local>,
454) -> Vec<LocalRef<'tcx, Bx::Value>> {
455let mir = fx.mir;
456let mut idx = 0;
457let mut llarg_idx = fx.fn_abi.ret.is_indirect() as usize;
458459let mut num_untupled = None;
460461let codegen_fn_attrs = bx.tcx().codegen_instance_attrs(fx.instance.def);
462if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
463return ::alloc::vec::Vec::new()vec![];
464 }
465466let mut args = mir467 .args_iter()
468 .enumerate()
469 .map(|(arg_index, local)| {
470let arg_decl = &mir.local_decls[local];
471let arg_ty = fx.monomorphize(arg_decl.ty);
472473// FIXME(splat): re-tuple splatted arguments that were un-tupled in the ABI
474if Some(local) == mir.spread_arg {
475// This argument (e.g., the last argument in the "rust-call" ABI)
476 // is a tuple that was spread at the ABI level and now we have
477 // to reconstruct it into a tuple local variable, from multiple
478 // individual LLVM function arguments.
479let ty::Tuple(tupled_arg_tys) = arg_ty.kind() else {
480::rustc_span::macros::bug_impl(None,
format_args!("spread argument isn\'t a tuple?!"), Location::caller());bug!("spread argument isn't a tuple?!");
481 };
482483let layout = bx.layout_of(arg_ty);
484485// FIXME: support unsized params in "rust-call" ABI
486if layout.is_unsized() {
487::rustc_span::macros::bug_impl(Some(arg_decl.source_info.span),
format_args!("\"rust-call\" ABI does not support unsized params"),
Location::caller());span_bug!(
488 arg_decl.source_info.span,
489"\"rust-call\" ABI does not support unsized params",
490 );
491 }
492493let place = PlaceRef::alloca(bx, layout);
494for i in 0..tupled_arg_tys.len() {
495let arg = &fx.fn_abi.args[idx];
496 idx += 1;
497if let PassMode::Cast { pad_i32_count, .. } = arg.mode {
498 llarg_idx += usize::from(pad_i32_count);
499 }
500let pr_field = place.project_field(bx, i);
501 bx.store_fn_arg(arg, &mut llarg_idx, pr_field);
502 }
503{
match (&None, &num_untupled.replace(tupled_arg_tys.len())) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("Replaced existing num_untupled")));
}
}
}
};assert_eq!(
504None,
505 num_untupled.replace(tupled_arg_tys.len()),
506"Replaced existing num_untupled"
507);
508509return LocalRef::Place(place);
510 }
511512if fx.fn_abi.c_variadic && arg_index == fx.fn_abi.args.len() {
513let va_list = PlaceRef::alloca(bx, bx.layout_of(arg_ty));
514515// Explicitly start the lifetime of the `va_list`, improves LLVM codegen.
516bx.lifetime_start(va_list.val.llval, va_list.layout.size);
517518bx.va_start(va_list.val.llval);
519520return LocalRef::Place(va_list);
521 }
522523let arg = &fx.fn_abi.args[idx];
524idx += 1;
525if let PassMode::Cast { pad_i32_count, .. } = arg.mode {
526llarg_idx += usize::from(pad_i32_count);
527 }
528529if !memory_locals.contains(local) {
530// We don't have to cast or keep the argument in the alloca.
531 // FIXME(eddyb): We should figure out how to use llvm.dbg.value instead
532 // of putting everything in allocas just so we can use llvm.dbg.declare.
533let local = |op| LocalRef::Operand(op);
534match arg.mode {
535 PassMode::Ignore => {
536return local(OperandRef::zero_sized(arg.layout));
537 }
538 PassMode::Direct(_) => {
539let llarg = bx.get_param(llarg_idx);
540llarg_idx += 1;
541if true {
if !arg.layout.backend_repr.is_scalar_or_simd() {
::core::panicking::panic("assertion failed: arg.layout.backend_repr.is_scalar_or_simd()")
};
};debug_assert!(arg.layout.backend_repr.is_scalar_or_simd());
542return local(OperandRef {
543 val: OperandValue::Immediate(llarg),
544 layout: arg.layout,
545 move_annotation: None,
546 });
547 }
548 PassMode::Pair(..) => {
549let (a, b) = (bx.get_param(llarg_idx), bx.get_param(llarg_idx + 1));
550llarg_idx += 2;
551552return local(OperandRef {
553 val: OperandValue::Pair(a, b),
554 layout: arg.layout,
555 move_annotation: None,
556 });
557 }
558_ => {}
559 }
560 }
561562match arg.mode {
563// Sized indirect arguments
564PassMode::Indirect { attrs, address_space: _, mode } => {
565// Don't copy an indirect argument to an alloca, the caller already put it
566 // in a temporary alloca and gave it up.
567 // AmdgpuKernelArg/byref arguments must not be modified, so always create a
568 // local alloca for them.
569 // If the argument is underaligned, then we need to copy it to a higher-aligned
570 // alloca.
571 // FIXME: lifetimes
572let mut needs_alloca = mode == IndirectMode::AmdgpuKernelArg;
573if let Some(pointee_align) = attrs.pointee_align
574 && pointee_align < arg.layout.align
575 {
576needs_alloca = true;
577 }
578if needs_alloca {
579let tmp = PlaceRef::alloca(bx, arg.layout);
580bx.store_fn_arg(arg, &mut llarg_idx, tmp);
581 LocalRef::Place(tmp)
582 } else {
583let llarg = bx.get_param(llarg_idx);
584llarg_idx += 1;
585 LocalRef::Place(PlaceRef::new_sized(llarg, arg.layout))
586 }
587 }
588// Unsized indirect arguments
589PassMode::IndirectUnsized { attrs: _, meta_attrs: _ } => {
590// As the storage for the indirect argument lives during
591 // the whole function call, we just copy the wide pointer.
592let llarg = bx.get_param(llarg_idx);
593llarg_idx += 1;
594let llextra = bx.get_param(llarg_idx);
595llarg_idx += 1;
596let indirect_operand = OperandValue::Pair(llarg, llextra);
597598let tmp = PlaceRef::alloca_unsized_indirect(bx, arg.layout);
599indirect_operand.store(bx, tmp);
600 LocalRef::UnsizedPlace(tmp)
601 }
602_ => {
603let tmp = PlaceRef::alloca(bx, arg.layout);
604bx.store_fn_arg(arg, &mut llarg_idx, tmp);
605 LocalRef::Place(tmp)
606 }
607 }
608 })
609 .collect::<Vec<_>>();
610if bx.tcx().sess.opts.unstable_opts.codegen_emit_retag.is_some() {
611args = args612 .iter()
613 .map(|arg| match arg {
614&LocalRef::Place(place_ref) => {
615fx.codegen_retag_place(bx, place_ref, true);
616 LocalRef::Place(place_ref)
617 }
618&LocalRef::UnsizedPlace(place_ref) => {
619let operand = bx.load_operand(place_ref);
620let retagged = fx.codegen_retag_operand(bx, operand, true);
621if !#[allow(non_exhaustive_omitted_patterns)] match retagged.val {
OperandValue::Pair(_, _) => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(retagged.val, OperandValue::Pair(_, _))")
};assert!(matches!(retagged.val, OperandValue::Pair(_, _)));
622retagged.val.store(bx, place_ref);
623 LocalRef::UnsizedPlace(place_ref)
624 }
625&LocalRef::Operand(operand_ref) => {
626let retagged = fx.codegen_retag_operand(bx, operand_ref, true);
627 LocalRef::Operand(retagged)
628 }
629 LocalRef::PendingOperand => LocalRef::PendingOperand,
630 })
631 .collect::<Vec<_>>();
632// If we branched during retagging, then we need to update the
633 // start block to the new location.
634fx.cached_llbbs[mir::START_BLOCK] = CachedLlbb::Some(bx.llbb());
635 }
636637if fx.instance.def.requires_caller_location(bx.tcx()) {
638let mir_args = if let Some(num_untupled) = num_untupled {
639// Subtract off the tupled argument that gets 'expanded'
640args.len() - 1 + num_untupled641 } else {
642args.len()
643 };
644{
match (&fx.fn_abi.args.len(), &(mir_args + 1)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("#[track_caller] instance {0:?} must have 1 more argument in their ABI than in their MIR",
fx.instance)));
}
}
}
};assert_eq!(
645 fx.fn_abi.args.len(),
646 mir_args + 1,
647"#[track_caller] instance {:?} must have 1 more argument in their ABI than in their MIR",
648 fx.instance
649 );
650651let arg = fx.fn_abi.args.last().unwrap();
652match arg.mode {
653 PassMode::Direct(_) => (),
654_ => ::rustc_span::macros::bug_impl(None,
format_args!("caller location must be PassMode::Direct, found {0:?}",
arg.mode), Location::caller())bug!("caller location must be PassMode::Direct, found {:?}", arg.mode),
655 }
656657fx.caller_location = Some(OperandRef {
658 val: OperandValue::Immediate(bx.get_param(llarg_idx)),
659 layout: arg.layout,
660 move_annotation: None,
661 });
662 }
663664args665}
666667fn find_cold_blocks<'tcx>(
668 tcx: TyCtxt<'tcx>,
669 mir: &mir::Body<'tcx>,
670) -> DenseBitSet<mir::BasicBlock> {
671let local_decls = &mir.local_decls;
672673let mut cold_blocks: DenseBitSet<mir::BasicBlock> =
674DenseBitSet::new_empty(mir.basic_blocks.len());
675676// Traverse all basic blocks from end of the function to the start.
677for (bb, bb_data) in traversal::postorder(mir) {
678let terminator = bb_data.terminator();
679680match terminator.kind {
681// If a BB ends with a call to a cold function, mark it as cold.
682mir::TerminatorKind::Call { ref func, .. }
683 | mir::TerminatorKind::TailCall { ref func, .. }
684if let ty::FnDef(def_id, ..) = *func.ty(local_decls, tcx).kind()
685 && let attrs = tcx.codegen_fn_attrs(def_id)
686 && attrs.flags.contains(CodegenFnAttrFlags::COLD) =>
687 {
688 cold_blocks.insert(bb);
689continue;
690 }
691692// If a BB ends with an `unreachable`, also mark it as cold.
693mir::TerminatorKind::Unreachable => {
694 cold_blocks.insert(bb);
695continue;
696 }
697698_ => {}
699 }
700701// If all successors of a BB are cold and there's at least one of them, mark this BB as cold
702let mut succ = terminator.successors();
703if let Some(first) = succ.next()
704 && cold_blocks.contains(first)
705 && succ.all(|s| cold_blocks.contains(s))
706 {
707 cold_blocks.insert(bb);
708 }
709 }
710711cold_blocks712}