Add logging to frame operations

This commit is contained in:
Andrew Brown
2020-05-25 20:25:13 -07:00
committed by Benjamin Bouvier
parent c92917de15
commit d73cb48c29

View File

@@ -2,6 +2,7 @@
use cranelift_codegen::ir::{Function, Value as ValueRef}; use cranelift_codegen::ir::{Function, Value as ValueRef};
use cranelift_reader::DataValue; use cranelift_reader::DataValue;
use log::trace;
use std::collections::HashMap; use std::collections::HashMap;
/// Holds the mutable elements of an interpretation. At some point I thought about using /// Holds the mutable elements of an interpretation. At some point I thought about using
@@ -22,6 +23,7 @@ impl<'a> Frame<'a> {
/// `Value` (renamed to `ValueRef` here) which should mean that no additional allocations are /// `Value` (renamed to `ValueRef` here) which should mean that no additional allocations are
/// needed while interpreting the frame. /// needed while interpreting the frame.
pub fn new(function: &'a Function) -> Self { pub fn new(function: &'a Function) -> Self {
trace!("Create new frame for function: {}", function.signature);
Self { Self {
function, function,
registers: HashMap::with_capacity(function.dfg.num_values()), registers: HashMap::with_capacity(function.dfg.num_values()),
@@ -41,6 +43,7 @@ impl<'a> Frame<'a> {
/// Retrieve the actual value associated with an SSA reference. /// Retrieve the actual value associated with an SSA reference.
#[inline] #[inline]
pub fn get(&self, name: &ValueRef) -> &DataValue { pub fn get(&self, name: &ValueRef) -> &DataValue {
trace!("Get {}", name);
self.registers self.registers
.get(name) .get(name)
.unwrap_or_else(|| panic!("unknown value: {}", name)) .unwrap_or_else(|| panic!("unknown value: {}", name))
@@ -54,6 +57,7 @@ impl<'a> Frame<'a> {
/// Assign `value` to the SSA reference `name`. /// Assign `value` to the SSA reference `name`.
#[inline] #[inline]
pub fn set(&mut self, name: ValueRef, value: DataValue) -> Option<DataValue> { pub fn set(&mut self, name: ValueRef, value: DataValue) -> Option<DataValue> {
trace!("Set {} -> {}", name, value);
self.registers.insert(name, value) self.registers.insert(name, value)
} }
@@ -70,6 +74,7 @@ impl<'a> Frame<'a> {
/// could be removed if we copied the values in the right order (i.e. when modifying in place, /// could be removed if we copied the values in the right order (i.e. when modifying in place,
/// we need to avoid changing a value before it is referenced). /// we need to avoid changing a value before it is referenced).
pub fn rename(&mut self, old_names: &[ValueRef], new_names: &[ValueRef]) { pub fn rename(&mut self, old_names: &[ValueRef], new_names: &[ValueRef]) {
trace!("Renaming {:?} -> {:?}", old_names, new_names);
assert_eq!(old_names.len(), new_names.len()); assert_eq!(old_names.len(), new_names.len());
let mut registers = HashMap::with_capacity(self.registers.len()); let mut registers = HashMap::with_capacity(self.registers.len());
for (on, nn) in old_names.iter().zip(new_names) { for (on, nn) in old_names.iter().zip(new_names) {