From 33e73091f8d4299e7f281a7d5da5184bf055c895 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 1 Feb 2020 16:47:35 +0100 Subject: [PATCH] Don't mark unwind ebbs as cold This fixes the code_layout optimization, as it would previously try to move non-existing ebbs. Fixes #877 --- src/base.rs | 18 ++++++++---------- src/optimize/code_layout.rs | 2 -- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/base.rs b/src/base.rs index 6af9ddd8894..5860e3121b4 100644 --- a/src/base.rs +++ b/src/base.rs @@ -32,12 +32,6 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( // Predefine ebb's let start_ebb = bcx.create_ebb(); let ebb_map: IndexVec = (0..mir.basic_blocks().len()).map(|_| bcx.create_ebb()).collect(); - let mut cold_ebbs = EntitySet::new(); - for (bb, &ebb) in ebb_map.iter_enumerated() { - if mir.basic_blocks()[bb].is_cleanup { - cold_ebbs.insert(ebb); - } - } // Make FunctionCx let pointer_type = cx.module.target_config().pointer_type(); @@ -55,7 +49,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( ebb_map, local_map: HashMap::new(), caller_location: None, // set by `codegen_fn_prelude` - cold_ebbs, + cold_ebbs: EntitySet::new(), clif_comments, constants_cx: &mut cx.constants_cx, @@ -148,13 +142,17 @@ pub fn verify_func(tcx: TyCtxt, writer: &crate::pretty_clif::CommentWriter, func fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) { for (bb, bb_data) in fx.mir.basic_blocks().iter_enumerated() { + let ebb = fx.get_ebb(bb); + fx.bcx.switch_to_block(ebb); + if bb_data.is_cleanup { // Unwinding after panicking is not supported continue; - } - let ebb = fx.get_ebb(bb); - fx.bcx.switch_to_block(ebb); + // FIXME once unwinding is supported uncomment next lines + // // Unwinding is unlikely to happen, so mark cleanup ebb's as cold. + // fx.cold_ebbs.insert(ebb); + } fx.bcx.ins().nop(); for stmt in &bb_data.statements { diff --git a/src/optimize/code_layout.rs b/src/optimize/code_layout.rs index 9ceca814150..4d2301c6f6c 100644 --- a/src/optimize/code_layout.rs +++ b/src/optimize/code_layout.rs @@ -11,8 +11,6 @@ use crate::prelude::*; pub(super) fn optimize_function(ctx: &mut Context, cold_ebbs: &EntitySet) { - return; // FIXME add ebb arguments back - // FIXME Move the ebb in place instead of remove and append once // bytecodealliance/cranelift#1339 is implemented.