diff --git a/src/abi/comments.rs b/src/abi/comments.rs new file mode 100644 index 00000000000..674449cf06d --- /dev/null +++ b/src/abi/comments.rs @@ -0,0 +1,94 @@ +use std::borrow::Cow; + +use rustc::mir; + +use crate::prelude::*; +use crate::abi::pass_mode::*; + +pub fn add_local_header_comment(fx: &mut FunctionCx) { + fx.add_global_comment(format!( + "msg loc.idx param pass mode ssa flags ty" + )); +} + +pub fn add_arg_comment<'tcx>( + fx: &mut FunctionCx<'_, 'tcx, impl Backend>, + msg: &str, + local: mir::Local, + local_field: Option, + params: EmptySinglePair, + pass_mode: PassMode, + ssa: crate::analyze::Flags, + ty: Ty<'tcx>, +) { + let local_field = if let Some(local_field) = local_field { + Cow::Owned(format!(".{}", local_field)) + } else { + Cow::Borrowed("") + }; + let params = match params { + Empty => Cow::Borrowed("-"), + Single(param) => Cow::Owned(format!("= {:?}", param)), + Pair(param_a, param_b) => Cow::Owned(format!("= {:?}, {:?}", param_a, param_b)), + }; + let pass_mode = format!("{:?}", pass_mode); + fx.add_global_comment(format!( + "{msg:5}{local:>3}{local_field:<5} {params:10} {pass_mode:36} {ssa:10} {ty:?}", + msg = msg, + local = format!("{:?}", local), + local_field = local_field, + params = params, + pass_mode = pass_mode, + ssa = format!("{:?}", ssa), + ty = ty, + )); +} + +pub fn add_local_place_comments<'tcx>( + fx: &mut FunctionCx<'_, 'tcx, impl Backend>, + place: CPlace<'tcx>, + local: Local, +) { + let TyLayout { ty, details } = place.layout(); + let ty::layout::LayoutDetails { + size, + align, + abi: _, + variants: _, + fields: _, + largest_niche: _, + } = details; + match *place.inner() { + CPlaceInner::Var(var) => { + assert_eq!(local, var); + fx.add_global_comment(format!( + "ssa {:?}: {:?} size={} align={}, {}", + local, + ty, + size.bytes(), + align.abi.bytes(), + align.pref.bytes(), + )); + } + CPlaceInner::Stack(stack_slot) => fx.add_entity_comment( + stack_slot, + format!( + "{:?}: {:?} size={} align={},{}", + local, + ty, + size.bytes(), + align.abi.bytes(), + align.pref.bytes(), + ), + ), + CPlaceInner::NoPlace => fx.add_global_comment(format!( + "zst {:?}: {:?} size={} align={}, {}", + local, + ty, + size.bytes(), + align.abi.bytes(), + align.pref.bytes(), + )), + CPlaceInner::Addr(_, _) => unreachable!(), + } +} diff --git a/src/abi/mod.rs b/src/abi/mod.rs index dc6bac0e426..512b1b68ad9 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -1,8 +1,8 @@ +#[cfg(debug_assertions)] +mod comments; mod returning; mod pass_mode; -use std::borrow::Cow; - use rustc_target::spec::abi::Abi; use crate::prelude::*; @@ -193,47 +193,6 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { } } -#[cfg(debug_assertions)] -fn add_arg_comment<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Backend>, - msg: &str, - local: mir::Local, - local_field: Option, - params: EmptySinglePair, - pass_mode: PassMode, - ssa: crate::analyze::Flags, - ty: Ty<'tcx>, -) { - let local_field = if let Some(local_field) = local_field { - Cow::Owned(format!(".{}", local_field)) - } else { - Cow::Borrowed("") - }; - let params = match params { - Empty => Cow::Borrowed("-"), - Single(param) => Cow::Owned(format!("= {:?}", param)), - Pair(param_a, param_b) => Cow::Owned(format!("= {:?}, {:?}", param_a, param_b)), - }; - let pass_mode = format!("{:?}", pass_mode); - fx.add_global_comment(format!( - "{msg:5} {local:>3}{local_field:<5} {params:10} {pass_mode:36} {ssa:10} {ty:?}", - msg = msg, - local = format!("{:?}", local), - local_field = local_field, - params = params, - pass_mode = pass_mode, - ssa = format!("{:?}", ssa), - ty = ty, - )); -} - -#[cfg(debug_assertions)] -fn add_local_header_comment(fx: &mut FunctionCx) { - fx.add_global_comment(format!( - "msg loc.idx param pass mode ssa flags ty" - )); -} - fn local_place<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, local: Local, @@ -243,46 +202,12 @@ fn local_place<'tcx>( let place = if is_ssa { CPlace::new_var(fx, local, layout) } else { - let place = CPlace::new_stack_slot(fx, layout.ty); - - #[cfg(debug_assertions)] - { - let TyLayout { ty, details } = layout; - let ty::layout::LayoutDetails { - size, - align, - abi: _, - variants: _, - fields: _, - largest_niche: _, - } = details; - match *place.inner() { - CPlaceInner::Stack(stack_slot) => fx.add_entity_comment( - stack_slot, - format!( - "{:?}: {:?} size={} align={},{}", - local, - ty, - size.bytes(), - align.abi.bytes(), - align.pref.bytes(), - ), - ), - CPlaceInner::NoPlace => fx.add_global_comment(format!( - "zst {:?}: {:?} size={} align={}, {}", - local, - ty, - size.bytes(), - align.abi.bytes(), - align.pref.bytes(), - )), - _ => unreachable!(), - } - } - - place + CPlace::new_stack_slot(fx, layout.ty) }; + #[cfg(debug_assertions)] + self::comments::add_local_place_comments(fx, place, local); + let prev_place = fx.local_map.insert(local, place); debug_assert!(prev_place.is_none()); fx.local_map[&local] @@ -295,10 +220,7 @@ pub fn codegen_fn_prelude( let ssa_analyzed = crate::analyze::analyze(fx); #[cfg(debug_assertions)] - { - fx.add_global_comment(format!("ssa {:?}", ssa_analyzed)); - add_local_header_comment(fx); - } + self::comments::add_local_header_comment(fx); self::returning::codegen_return_param(fx, &ssa_analyzed, start_ebb); diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index 4608562e993..f5c91338842 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -145,7 +145,7 @@ pub fn cvalue_for_param<'tcx>( let ebb_params = clif_types.map(|t| fx.bcx.append_ebb_param(start_ebb, t)); #[cfg(debug_assertions)] - super::add_arg_comment( + crate::abi::comments::add_arg_comment( fx, "arg", local, diff --git a/src/abi/returning.rs b/src/abi/returning.rs index 45ba48d7c4f..465127e9b71 100644 --- a/src/abi/returning.rs +++ b/src/abi/returning.rs @@ -37,18 +37,16 @@ pub fn codegen_return_param( }; #[cfg(debug_assertions)] - { - super::add_arg_comment( - fx, - "ret", - RETURN_PLACE, - None, - ret_param, - output_pass_mode, - ssa_analyzed[&RETURN_PLACE], - ret_layout.ty, - ); - } + crate::abi::comments::add_arg_comment( + fx, + "ret", + RETURN_PLACE, + None, + ret_param, + output_pass_mode, + ssa_analyzed[&RETURN_PLACE], + ret_layout.ty, + ); } pub fn codegen_with_call_return_arg<'tcx, B: Backend, T>(