Update Cranelift for basic blocks

This commit is contained in:
bjorn3 2020-02-14 18:23:29 +01:00
parent b5b2ffab6a
commit 430f738392
17 changed files with 154 additions and 154 deletions

102
Cargo.lock generated
View file

@ -32,22 +32,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cranelift-bforest"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
dependencies = [
"cranelift-entity 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-entity 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
]
[[package]]
name = "cranelift-codegen"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-bforest 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen-meta 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen-shared 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-entity 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-bforest 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen-meta 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen-shared 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-entity 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"gimli 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -57,29 +57,29 @@ dependencies = [
[[package]]
name = "cranelift-codegen-meta"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
dependencies = [
"cranelift-codegen-shared 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-entity 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen-shared 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-entity 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
]
[[package]]
name = "cranelift-codegen-shared"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
[[package]]
name = "cranelift-entity"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
[[package]]
name = "cranelift-frontend"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
dependencies = [
"cranelift-codegen 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -87,44 +87,44 @@ dependencies = [
[[package]]
name = "cranelift-module"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
dependencies = [
"cranelift-codegen 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-entity 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-entity 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cranelift-native"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
dependencies = [
"cranelift-codegen 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"raw-cpuid 7.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cranelift-object"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
dependencies = [
"cranelift-codegen 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-module 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-module 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"object 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cranelift-simplejit"
version = "0.56.0"
source = "git+https://github.com/bytecodealliance/cranelift/#c73c3e8441efcb6324f18a22679e43e4bbd174cc"
version = "0.58.0"
source = "git+https://github.com/bytecodealliance/cranelift/#280fd1e13b5cdad9d9d308b78bb94b0476f2d9f0"
dependencies = [
"cranelift-codegen 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-module 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-native 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-module 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-native 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"region 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -282,11 +282,11 @@ version = "0.1.0"
dependencies = [
"ar 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-codegen 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-frontend 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-module 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-object 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-simplejit 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-codegen 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-frontend 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-module 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-object 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"cranelift-simplejit 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)",
"gimli 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
"indexmap 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -407,16 +407,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum cranelift-bforest 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-codegen 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-codegen-meta 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-codegen-shared 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-entity 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-frontend 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-module 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-native 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-object 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-simplejit 0.56.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-bforest 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-codegen 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-codegen-meta 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-codegen-shared 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-entity 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-frontend 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-module 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-native 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-object 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum cranelift-simplejit 0.58.0 (git+https://github.com/bytecodealliance/cranelift/)" = "<none>"
"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
"checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e"
"checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067"

View file

@ -288,13 +288,13 @@ fn local_place<'tcx>(
fx.local_map[&local]
}
pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_ebb: Ebb) {
pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_block: Block) {
let ssa_analyzed = crate::analyze::analyze(fx);
#[cfg(debug_assertions)]
self::comments::add_args_header_comment(fx);
self::returning::codegen_return_param(fx, &ssa_analyzed, start_ebb);
self::returning::codegen_return_param(fx, &ssa_analyzed, start_block);
// None means pass_mode == NoPass
enum ArgKind<'tcx> {
@ -322,13 +322,13 @@ pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_ebb:
let mut params = Vec::new();
for (i, arg_ty) in tupled_arg_tys.types().enumerate() {
let param = cvalue_for_param(fx, start_ebb, Some(local), Some(i), arg_ty);
let param = cvalue_for_param(fx, start_block, Some(local), Some(i), arg_ty);
params.push(param);
}
(local, ArgKind::Spread(params), arg_ty)
} else {
let param = cvalue_for_param(fx, start_ebb, Some(local), None, arg_ty);
let param = cvalue_for_param(fx, start_block, Some(local), None, arg_ty);
(local, ArgKind::Normal(param), arg_ty)
}
})
@ -337,10 +337,10 @@ pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_ebb:
assert!(fx.caller_location.is_none());
if fx.instance.def.requires_caller_location(fx.tcx) {
// Store caller location for `#[track_caller]`.
fx.caller_location = Some(cvalue_for_param(fx, start_ebb, None, None, fx.tcx.caller_location_ty()).unwrap());
fx.caller_location = Some(cvalue_for_param(fx, start_block, None, None, fx.tcx.caller_location_ty()).unwrap());
}
fx.bcx.switch_to_block(start_ebb);
fx.bcx.switch_to_block(start_block);
fx.bcx.ins().nop();
#[cfg(debug_assertions)]
@ -416,7 +416,7 @@ pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_ebb:
fx.bcx
.ins()
.jump(*fx.ebb_map.get(START_BLOCK).unwrap(), &[]);
.jump(*fx.block_map.get(START_BLOCK).unwrap(), &[]);
}
pub fn codegen_terminator_call<'tcx>(
@ -458,8 +458,8 @@ pub fn codegen_terminator_call<'tcx>(
InstanceDef::DropGlue(_, None) => {
// empty drop glue - a nop.
let (_, dest) = destination.expect("Non terminating drop_in_place_real???");
let ret_ebb = fx.get_ebb(dest);
fx.bcx.ins().jump(ret_ebb, &[]);
let ret_block = fx.get_block(dest);
fx.bcx.ins().jump(ret_block, &[]);
return;
}
_ => {}
@ -498,8 +498,8 @@ pub fn codegen_terminator_call<'tcx>(
);
if let Some((_, dest)) = destination {
let ret_ebb = fx.get_ebb(dest);
fx.bcx.ins().jump(ret_ebb, &[]);
let ret_block = fx.get_block(dest);
fx.bcx.ins().jump(ret_block, &[]);
} else {
trap_unreachable(fx, "[corruption] Diverging function returned");
}
@ -513,7 +513,7 @@ fn codegen_call_inner<'tcx>(
args: Vec<CValue<'tcx>>,
ret_place: Option<CPlace<'tcx>>,
) {
// FIXME mark the current ebb as cold when calling a `#[cold]` function.
// FIXME mark the current block as cold when calling a `#[cold]` function.
let fn_sig = fx
.tcx
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));

View file

@ -129,7 +129,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
pub(super) fn cvalue_for_param<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
start_ebb: Ebb,
start_block: Block,
local: Option<mir::Local>,
local_field: Option<usize>,
arg_ty: Ty<'tcx>,
@ -142,7 +142,7 @@ pub(super) fn cvalue_for_param<'tcx>(
}
let clif_types = pass_mode.get_param_ty(fx.tcx);
let ebb_params = clif_types.map(|t| fx.bcx.append_ebb_param(start_ebb, t));
let block_params = clif_types.map(|t| fx.bcx.append_block_param(start_block, t));
#[cfg(debug_assertions)]
crate::abi::comments::add_arg_comment(
@ -150,21 +150,21 @@ pub(super) fn cvalue_for_param<'tcx>(
"arg",
local,
local_field,
ebb_params,
block_params,
pass_mode,
arg_ty,
);
match pass_mode {
PassMode::NoPass => unreachable!(),
PassMode::ByVal(_) => Some(CValue::by_val(ebb_params.assert_single(), layout)),
PassMode::ByVal(_) => Some(CValue::by_val(block_params.assert_single(), layout)),
PassMode::ByValPair(_, _) => {
let (a, b) = ebb_params.assert_pair();
let (a, b) = block_params.assert_pair();
Some(CValue::by_val_pair(a, b, layout))
}
PassMode::ByRef { sized: true } => Some(CValue::by_ref(Pointer::new(ebb_params.assert_single()), layout)),
PassMode::ByRef { sized: true } => Some(CValue::by_ref(Pointer::new(block_params.assert_single()), layout)),
PassMode::ByRef { sized: false } => {
let (ptr, meta) = ebb_params.assert_pair();
let (ptr, meta) = block_params.assert_pair();
Some(CValue::by_ref_unsized(Pointer::new(ptr), meta, layout))
}
}

View file

@ -16,7 +16,7 @@ pub fn can_return_to_ssa_var<'tcx>(tcx: TyCtxt<'tcx>, dest_layout: TyLayout<'tcx
pub(super) fn codegen_return_param(
fx: &mut FunctionCx<impl Backend>,
ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>,
start_ebb: Ebb,
start_block: Block,
) {
let ret_layout = return_layout(fx);
let ret_pass_mode = get_pass_mode(fx.tcx, ret_layout);
@ -34,7 +34,7 @@ pub(super) fn codegen_return_param(
Empty
}
PassMode::ByRef { sized: true } => {
let ret_param = fx.bcx.append_ebb_param(start_ebb, fx.pointer_type);
let ret_param = fx.bcx.append_block_param(start_block, fx.pointer_type);
fx.local_map
.insert(RETURN_PLACE, CPlace::for_ptr(Pointer::new(ret_param), ret_layout));

View file

@ -78,11 +78,11 @@ fn codegen_inner(module: &mut Module<impl Backend + 'static>, kind: AllocatorKin
let mut func_ctx = FunctionBuilderContext::new();
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
let ebb = bcx.create_ebb();
bcx.switch_to_block(ebb);
let block = bcx.create_block();
bcx.switch_to_block(block);
let args = arg_tys
.into_iter()
.map(|ty| bcx.append_ebb_param(ebb, ty))
.map(|ty| bcx.append_block_param(block, ty))
.collect::<Vec<Value>>();
let callee_func_ref = module.declare_func_in_func(callee_func_id, &mut bcx.func);

View file

@ -29,9 +29,9 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
let mut func_ctx = FunctionBuilderContext::new();
let mut bcx = FunctionBuilder::new(&mut context.func, &mut func_ctx);
// Predefine ebb's
let start_ebb = bcx.create_ebb();
let ebb_map: IndexVec<BasicBlock, Ebb> = (0..mir.basic_blocks().len()).map(|_| bcx.create_ebb()).collect();
// Predefine block's
let start_block = bcx.create_block();
let block_map: IndexVec<BasicBlock, Block> = (0..mir.basic_blocks().len()).map(|_| bcx.create_block()).collect();
// Make FunctionCx
let pointer_type = cx.module.target_config().pointer_type();
@ -46,10 +46,10 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
mir,
bcx,
ebb_map,
block_map,
local_map: HashMap::new(),
caller_location: None, // set by `codegen_fn_prelude`
cold_ebbs: EntitySet::new(),
cold_blocks: EntitySet::new(),
clif_comments,
constants_cx: &mut cx.constants_cx,
@ -58,13 +58,13 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
};
if fx.mir.args_iter().any(|arg| fx.layout_of(fx.monomorphize(&fx.mir.local_decls[arg].ty)).abi.is_uninhabited()) {
let entry_block = fx.bcx.create_ebb();
fx.bcx.append_ebb_params_for_function_params(entry_block);
let entry_block = fx.bcx.create_block();
fx.bcx.append_block_params_for_function_params(entry_block);
fx.bcx.switch_to_block(entry_block);
crate::trap::trap_unreachable(&mut fx, "function has uninhabited argument");
} else {
tcx.sess.time("codegen clif ir", || {
tcx.sess.time("codegen prelude", || crate::abi::codegen_fn_prelude(&mut fx, start_ebb));
tcx.sess.time("codegen prelude", || crate::abi::codegen_fn_prelude(&mut fx, start_block));
codegen_fn_content(&mut fx);
});
}
@ -74,7 +74,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
let mut clif_comments = fx.clif_comments;
let source_info_set = fx.source_info_set;
let local_map = fx.local_map;
let cold_ebbs = fx.cold_ebbs;
let cold_blocks = fx.cold_blocks;
#[cfg(debug_assertions)]
crate::pretty_clif::write_clif_file(cx.tcx, "unopt", instance, &context.func, &clif_comments, None);
@ -84,7 +84,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
// Perform rust specific optimizations
tcx.sess.time("optimize clif ir", || {
crate::optimize::optimize_function(tcx, instance, context, &cold_ebbs, &mut clif_comments);
crate::optimize::optimize_function(tcx, instance, context, &cold_blocks, &mut clif_comments);
});
// Define function
@ -142,22 +142,22 @@ 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);
let block = fx.get_block(bb);
fx.bcx.switch_to_block(block);
if bb_data.is_cleanup {
// Unwinding after panicking is not supported
continue;
// 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);
// // Unwinding is unlikely to happen, so mark cleanup block's as cold.
// fx.cold_blocks.insert(block);
}
fx.bcx.ins().nop();
for stmt in &bb_data.statements {
fx.set_debug_loc(stmt.source_info);
trans_stmt(fx, ebb, stmt);
trans_stmt(fx, block, stmt);
}
#[cfg(debug_assertions)]
@ -168,7 +168,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
.kind
.fmt_head(&mut terminator_head)
.unwrap();
let inst = fx.bcx.func.layout.last_inst(ebb).unwrap();
let inst = fx.bcx.func.layout.last_inst(block).unwrap();
fx.add_comment(inst, terminator_head);
}
@ -176,8 +176,8 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
match &bb_data.terminator().kind {
TerminatorKind::Goto { target } => {
let ebb = fx.get_ebb(*target);
fx.bcx.ins().jump(ebb, &[]);
let block = fx.get_block(*target);
fx.bcx.ins().jump(block, &[]);
}
TerminatorKind::Return => {
crate::abi::codegen_return(fx);
@ -191,16 +191,16 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
} => {
if !fx.tcx.sess.overflow_checks() {
if let mir::AssertKind::OverflowNeg = *msg {
let target = fx.get_ebb(*target);
let target = fx.get_block(*target);
fx.bcx.ins().jump(target, &[]);
continue;
}
}
let cond = trans_operand(fx, cond).load_scalar(fx);
let target = fx.get_ebb(*target);
let failure = fx.bcx.create_ebb();
fx.cold_ebbs.insert(failure);
let target = fx.get_block(*target);
let failure = fx.bcx.create_block();
fx.cold_blocks.insert(failure);
if *expected {
fx.bcx.ins().brz(cond, failure, &[]);
@ -229,11 +229,11 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
let discr = trans_operand(fx, discr).load_scalar(fx);
let mut switch = ::cranelift_frontend::Switch::new();
for (i, value) in values.iter().enumerate() {
let ebb = fx.get_ebb(targets[i]);
switch.set_entry(*value as u64, ebb);
let block = fx.get_block(targets[i]);
switch.set_entry(*value as u64, block);
}
let otherwise_ebb = fx.get_ebb(targets[targets.len() - 1]);
switch.emit(&mut fx.bcx, discr, otherwise_ebb);
let otherwise_block = fx.get_block(targets[targets.len() - 1]);
switch.emit(&mut fx.bcx, discr, otherwise_block);
}
TerminatorKind::Call {
func,
@ -271,8 +271,8 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
let drop_place = trans_place(fx, location);
crate::abi::codegen_drop(fx, bb_data.terminator().source_info.span, drop_place);
let target_ebb = fx.get_ebb(*target);
fx.bcx.ins().jump(target_ebb, &[]);
let target_block = fx.get_block(*target);
fx.bcx.ins().jump(target_block, &[]);
}
};
}
@ -283,7 +283,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
fn trans_stmt<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
cur_ebb: Ebb,
cur_block: Block,
stmt: &Statement<'tcx>,
) {
let _print_guard = PrintOnPanic(|| format!("stmt {:?}", stmt));
@ -294,7 +294,7 @@ fn trans_stmt<'tcx>(
match &stmt.kind {
StatementKind::StorageLive(..) | StatementKind::StorageDead(..) => {} // Those are not very useful
_ => {
let inst = fx.bcx.func.layout.last_inst(cur_ebb).unwrap();
let inst = fx.bcx.func.layout.last_inst(cur_block).unwrap();
fx.add_comment(inst, format!("{:?}", stmt));
}
}

View file

@ -264,14 +264,14 @@ pub struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
pub mir: &'tcx Body<'tcx>,
pub bcx: FunctionBuilder<'clif>,
pub ebb_map: IndexVec<BasicBlock, Ebb>,
pub block_map: IndexVec<BasicBlock, Block>,
pub local_map: HashMap<Local, CPlace<'tcx>>,
/// When `#[track_caller]` is used, the implicit caller location is stored in this variable.
pub caller_location: Option<CValue<'tcx>>,
/// See [crate::optimize::code_layout] for more information.
pub cold_ebbs: EntitySet<Ebb>,
pub cold_blocks: EntitySet<Block>,
pub clif_comments: crate::pretty_clif::CommentWriter,
pub constants_cx: &'clif mut crate::constant::ConstantCx,
@ -325,7 +325,7 @@ impl<'tcx, B: Backend + 'static> HasTargetSpec for FunctionCx<'_, 'tcx, B> {
impl<'tcx, B: Backend> BackendTypes for FunctionCx<'_, 'tcx, B> {
type Value = Value;
type Function = Value;
type BasicBlock = Ebb;
type BasicBlock = Block;
type Type = Type;
type Funclet = !;
type DIScope = !;
@ -348,8 +348,8 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
clif_type_from_ty(self.tcx, ty)
}
pub fn get_ebb(&self, bb: BasicBlock) -> Ebb {
*self.ebb_map.get(bb).unwrap()
pub fn get_block(&self, bb: BasicBlock) -> Block {
*self.block_map.get(bb).unwrap()
}
pub fn get_local_place(&mut self, local: Local) -> CPlace<'tcx> {

View file

@ -118,8 +118,8 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
let encinfo = isa.encoding_info();
let func = &context.func;
let mut ebbs = func.layout.ebbs().collect::<Vec<_>>();
ebbs.sort_by_key(|ebb| func.offsets[*ebb]); // Ensure inst offsets always increase
let mut blocks = func.layout.blocks().collect::<Vec<_>>();
blocks.sort_by_key(|block| func.offsets[*block]); // Ensure inst offsets always increase
let line_strings = &mut self.debug_context.dwarf.line_strings;
let mut last_file = None;
@ -147,8 +147,8 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
};
let mut end = 0;
for ebb in ebbs {
for (offset, inst, size) in func.inst_offsets(ebb, &encinfo) {
for block in blocks {
for (offset, inst, size) in func.inst_offsets(block, &encinfo) {
let srcloc = func.srclocs[inst];
line_program.row().address_offset = offset as u64;
if !srcloc.is_default() {

View file

@ -97,8 +97,8 @@ pub fn codegen_llvm_intrinsic_call<'tcx>(
}
if let Some((_, dest)) = destination {
let ret_ebb = fx.get_ebb(dest);
fx.bcx.ins().jump(ret_ebb, &[]);
let ret_block = fx.get_block(dest);
fx.bcx.ins().jump(ret_block, &[]);
} else {
trap_unreachable(fx, "[corruption] Diverging intrinsic returned.");
}

View file

@ -87,8 +87,8 @@ macro call_intrinsic_match {
$ret.write_cvalue($fx, res);
if let Some((_, dest)) = $destination {
let ret_ebb = $fx.get_ebb(dest);
$fx.bcx.ins().jump(ret_ebb, &[]);
let ret_block = $fx.get_block(dest);
$fx.bcx.ins().jump(ret_block, &[]);
return;
} else {
unreachable!();
@ -369,8 +369,8 @@ pub fn codegen_intrinsic_call<'tcx>(
if intrinsic.starts_with("simd_") {
self::simd::codegen_simd_intrinsic_call(fx, instance, args, ret, span);
let ret_ebb = fx.get_ebb(destination.expect("SIMD intrinsics don't diverge").1);
fx.bcx.ins().jump(ret_ebb, &[]);
let ret_block = fx.get_block(destination.expect("SIMD intrinsics don't diverge").1);
fx.bcx.ins().jump(ret_block, &[]);
return;
}
@ -992,8 +992,8 @@ pub fn codegen_intrinsic_call<'tcx>(
}
if let Some((_, dest)) = destination {
let ret_ebb = fx.get_ebb(dest);
fx.bcx.ins().jump(ret_ebb, &[]);
let ret_block = fx.get_block(dest);
fx.bcx.ins().jump(ret_block, &[]);
} else {
trap_unreachable(fx, "[corruption] Diverging intrinsic returned.");
}

View file

@ -98,7 +98,7 @@ mod prelude {
pub use cranelift_codegen::Context;
pub use cranelift_codegen::entity::EntitySet;
pub use cranelift_codegen::ir::{AbiParam, Ebb, ExternalName, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, StackSlot, StackSlotData, StackSlotKind, TrapCode, Type, Value};
pub use cranelift_codegen::ir::{AbiParam, Block, ExternalName, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, StackSlot, StackSlotData, StackSlotKind, TrapCode, Type, Value};
pub use cranelift_codegen::ir::condcodes::{FloatCC, IntCC};
pub use cranelift_codegen::ir::function::Function;
pub use cranelift_codegen::ir::immediates::{Ieee32, Ieee64};

View file

@ -62,10 +62,10 @@ pub fn maybe_create_entry_wrapper(tcx: TyCtxt<'_>, module: &mut Module<impl Back
let mut func_ctx = FunctionBuilderContext::new();
let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
let ebb = bcx.create_ebb();
bcx.switch_to_block(ebb);
let arg_argc = bcx.append_ebb_param(ebb, m.target_config().pointer_type());
let arg_argv = bcx.append_ebb_param(ebb, m.target_config().pointer_type());
let block = bcx.create_block();
bcx.switch_to_block(block);
let arg_argc = bcx.append_block_param(block, m.target_config().pointer_type());
let arg_argv = bcx.append_block_param(block, m.target_config().pointer_type());
crate::atomic_shim::init_global_lock(m, &mut bcx);

View file

@ -10,25 +10,25 @@
use crate::prelude::*;
pub(super) fn optimize_function(ctx: &mut Context, cold_ebbs: &EntitySet<Ebb>) {
// FIXME Move the ebb in place instead of remove and append once
pub(super) fn optimize_function(ctx: &mut Context, cold_blocks: &EntitySet<Block>) {
// FIXME Move the block in place instead of remove and append once
// bytecodealliance/cranelift#1339 is implemented.
let mut ebb_insts = HashMap::new();
for ebb in cold_ebbs.keys().filter(|&ebb| cold_ebbs.contains(ebb)) {
let insts = ctx.func.layout.ebb_insts(ebb).collect::<Vec<_>>();
let mut block_insts = HashMap::new();
for block in cold_blocks.keys().filter(|&block| cold_blocks.contains(block)) {
let insts = ctx.func.layout.block_insts(block).collect::<Vec<_>>();
for &inst in &insts {
ctx.func.layout.remove_inst(inst);
}
ebb_insts.insert(ebb, insts);
ctx.func.layout.remove_ebb(ebb);
block_insts.insert(block, insts);
ctx.func.layout.remove_block(block);
}
// And then append them at the back again.
for ebb in cold_ebbs.keys().filter(|&ebb| cold_ebbs.contains(ebb)) {
ctx.func.layout.append_ebb(ebb);
for inst in ebb_insts.remove(&ebb).unwrap() {
ctx.func.layout.append_inst(inst, ebb);
for block in cold_blocks.keys().filter(|&block| cold_blocks.contains(block)) {
ctx.func.layout.append_block(block);
for inst in block_insts.remove(&block).unwrap() {
ctx.func.layout.append_inst(inst, block);
}
}
}

View file

@ -7,11 +7,11 @@ pub fn optimize_function<'tcx>(
tcx: TyCtxt<'tcx>,
instance: Instance<'tcx>,
ctx: &mut Context,
cold_ebbs: &EntitySet<Ebb>,
cold_blocks: &EntitySet<Block>,
clif_comments: &mut crate::pretty_clif::CommentWriter,
) {
// The code_layout optimization is very cheap.
self::code_layout::optimize_function(ctx, cold_ebbs);
self::code_layout::optimize_function(ctx, cold_blocks);
if tcx.sess.opts.optimize == rustc_session::config::OptLevel::No {
return; // FIXME classify optimizations over opt levels

View file

@ -116,7 +116,7 @@ impl<'a> OptimizeContext<'a> {
let mut stack_slot_usage_map = BTreeMap::<OrdStackSlot, StackSlotUsage>::new();
let mut cursor = FuncCursor::new(&mut ctx.func);
while let Some(_ebb) = cursor.next_ebb() {
while let Some(_block) = cursor.next_block() {
while let Some(inst) = cursor.next_inst() {
match cursor.func.dfg[inst] {
InstructionData::StackLoad {
@ -249,7 +249,7 @@ pub(super) fn optimize_function<T: std::fmt::Debug>(
fn combine_stack_addr_with_load_store(func: &mut Function) {
// Turn load and store into stack_load and stack_store when possible.
let mut cursor = FuncCursor::new(func);
while let Some(_ebb) = cursor.next_ebb() {
while let Some(_block) = cursor.next_block() {
while let Some(inst) = cursor.next_inst() {
match cursor.func.dfg[inst] {
InstructionData::Load { opcode: Opcode::Load, arg: addr, flags: _, offset } => {
@ -284,7 +284,7 @@ fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext) {
let mut stack_addr_load_insts_users = HashMap::<Inst, HashSet<Inst>>::new();
let mut cursor = FuncCursor::new(&mut opt_ctx.ctx.func);
while let Some(_ebb) = cursor.next_ebb() {
while let Some(_block) = cursor.next_block() {
while let Some(inst) = cursor.next_inst() {
for &arg in cursor.func.dfg.inst_args(inst) {
if let ValueDef::Result(arg_origin, 0) = cursor.func.dfg.value_def(arg) {

View file

@ -38,14 +38,14 @@ use crate::prelude::*;
/// sig1 = (i64, i64, i64) system_v
/// fn0 = colocated u0:6 sig1 ; Instance { def: Item(DefId(0/0:31 ~ example[8787]::{{impl}}[1]::call_mut[0])), substs: [ReErased, ReErased] }
///
/// ebb0(v0: i64, v1: i64, v2: i64):
/// block0(v0: i64, v1: i64, v2: i64):
/// v3 = stack_addr.i64 ss0
/// v4 = stack_addr.i64 ss1
/// store v2, v4
/// v5 = stack_addr.i64 ss2
/// jump ebb1
/// jump block1
///
/// ebb1:
/// block1:
/// nop
/// ; _3 = &mut _1
/// ; _4 = _2
@ -55,9 +55,9 @@ use crate::prelude::*;
/// ; _0 = const mini_core::FnMut::call_mut(move _3, move _4)
/// v7 = load.i64 v5
/// call fn0(v0, v3, v7)
/// jump ebb2
/// jump block2
///
/// ebb2:
/// block2:
/// nop
/// ;
/// ; return
@ -136,15 +136,15 @@ impl FuncWriter for &'_ CommentWriter {
}
}
fn write_ebb_header(
fn write_block_header(
&mut self,
w: &mut dyn fmt::Write,
func: &Function,
isa: Option<&dyn isa::TargetIsa>,
ebb: Ebb,
block: Block,
indent: usize,
) -> fmt::Result {
PlainWriter.write_ebb_header(w, func, isa, ebb, indent)
PlainWriter.write_block_header(w, func, isa, block, indent)
}
fn write_instruction(

View file

@ -382,12 +382,12 @@ impl<'tcx> CPlace<'tcx> {
#[cfg(debug_assertions)]
{
use cranelift_codegen::cursor::{Cursor, CursorPosition};
let cur_ebb = match fx.bcx.cursor().position() {
CursorPosition::After(ebb) => ebb,
let cur_block = match fx.bcx.cursor().position() {
CursorPosition::After(block) => block,
_ => unreachable!(),
};
fx.add_comment(
fx.bcx.func.layout.last_inst(cur_ebb).unwrap(),
fx.bcx.func.layout.last_inst(cur_block).unwrap(),
format!("write_cvalue: {:?} <- {:?}",self, from),
);
}