Improve local ir comments

This commit is contained in:
bjorn3 2019-12-22 15:27:25 +01:00
parent df641e1679
commit 15a310345d
2 changed files with 31 additions and 29 deletions

View File

@ -45,7 +45,7 @@ pub fn add_arg_comment<'tcx>(
pub fn add_locals_header_comment(fx: &mut FunctionCx<impl Backend>) {
fx.add_global_comment(String::new());
fx.add_global_comment(format!(
"kind local ty size align (abi,pref)"
"kind local ty size align (abi,pref)"
));
}
@ -63,35 +63,33 @@ pub fn add_local_place_comments<'tcx>(
fields: _,
largest_niche: _,
} = details;
match *place.inner() {
let (kind, extra) = match *place.inner() {
CPlaceInner::Var(var) => {
assert_eq!(local, var);
fx.add_global_comment(format!(
"ssa {:5} {:20} {:4}b {}, {}",
format!("{:?}", local),
format!("{:?}", ty),
size.bytes(),
align.abi.bytes(),
align.pref.bytes(),
));
("ssa", std::borrow::Cow::Borrowed(""))
}
CPlaceInner::NoPlace => fx.add_global_comment(format!(
"zst {:5} {:20} {:4}b {}, {}",
format!("{:?}", local),
format!("{:?}", ty),
size.bytes(),
align.abi.bytes(),
align.pref.bytes(),
)),
CPlaceInner::Addr(ptr, None) => fx.add_global_comment(format!(
"reuse {:5} {:20} {:4}b {}, {} storage={:?}",
format!("{:?}", local),
format!("{:?}", ty),
size.bytes(),
align.abi.bytes(),
align.pref.bytes(),
ptr,
)),
CPlaceInner::NoPlace => ("zst", "".into()),
CPlaceInner::Addr(ptr, None) => match ptr.base_and_offset() {
(crate::pointer::PointerBase::Addr(addr), offset) => {
("reuse", format!("storage={}{}", addr, offset).into())
}
(crate::pointer::PointerBase::Stack(stack_slot), offset) => {
("stack", format!("storage={}{}", stack_slot, offset).into())
}
},
CPlaceInner::Addr(_, Some(_)) => unreachable!(),
}
};
fx.add_global_comment(format!(
"{:<5} {:5} {:30} {:4}b {}, {}{}{}",
kind,
format!("{:?}", local),
format!("{:?}", ty),
size.bytes(),
align.abi.bytes(),
align.pref.bytes(),
if extra.is_empty() { "" } else { " " },
extra,
));
}

View File

@ -9,7 +9,7 @@ pub struct Pointer {
}
#[derive(Copy, Clone, Debug)]
enum PointerBase {
pub enum PointerBase {
Addr(Value),
Stack(StackSlot),
}
@ -37,6 +37,10 @@ pub fn const_addr<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>, addr: i
}
}
pub fn base_and_offset(self) -> (PointerBase, Offset32) {
(self.base, self.offset)
}
pub fn get_addr<'a, 'tcx>(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Value {
match self.base {
PointerBase::Addr(base_addr) => {