Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit acbfa06

Browse files
authored
Mark blocks that call cold funs as cold (rust-lang#1021)
1 parent bb4cc18 commit acbfa06

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/abi/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod pass_mode;
44
mod returning;
55

66
use rustc_target::spec::abi::Abi;
7+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
78

89
use cranelift_codegen::ir::AbiParam;
910

@@ -431,6 +432,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
431432
pub(crate) fn codegen_terminator_call<'tcx>(
432433
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
433434
span: Span,
435+
current_block: Block,
434436
func: &Operand<'tcx>,
435437
args: &[Operand<'tcx>],
436438
destination: Option<(Place<'tcx>, BasicBlock)>,
@@ -440,8 +442,6 @@ pub(crate) fn codegen_terminator_call<'tcx>(
440442
.tcx
441443
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
442444

443-
// FIXME mark the current block as cold when calling a `#[cold]` function.
444-
445445
let destination = destination.map(|(place, bb)| (trans_place(fx, place), bb));
446446

447447
// Handle special calls like instrinsics and empty drop glue.
@@ -479,6 +479,15 @@ pub(crate) fn codegen_terminator_call<'tcx>(
479479
None
480480
};
481481

482+
let is_cold =
483+
instance.map(|inst|
484+
fx.tcx.codegen_fn_attrs(inst.def_id())
485+
.flags.contains(CodegenFnAttrFlags::COLD))
486+
.unwrap_or(false);
487+
if is_cold {
488+
fx.cold_blocks.insert(current_block);
489+
}
490+
482491
// Unpack arguments tuple for closures
483492
let args = if fn_sig.abi == Abi::RustCall {
484493
assert_eq!(args.len(), 2, "rust-call abi requires two arguments");

src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
300300
fx.tcx.sess.time("codegen call", || crate::abi::codegen_terminator_call(
301301
fx,
302302
bb_data.terminator().source_info.span,
303+
block,
303304
func,
304305
args,
305306
*destination,

0 commit comments

Comments
 (0)