Optionally show annotations in final allocation/program dump based on RegallocOptions flag
This commit is contained in:
@@ -35,6 +35,11 @@ macro_rules! define_index {
|
||||
assert!(self.is_valid());
|
||||
Self(self.0 - 1)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn raw_u32(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::index::ContainerIndex for $ix {}
|
||||
|
||||
@@ -365,6 +365,7 @@ struct Env<'a, F: Function> {
|
||||
// For debug output only: a list of textual annotations at every
|
||||
// ProgPoint to insert into the final allocated program listing.
|
||||
debug_annotations: std::collections::HashMap<ProgPoint, Vec<String>>,
|
||||
annotations_enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -700,7 +701,12 @@ impl<'a> std::iter::Iterator for RegTraversalIter<'a> {
|
||||
}
|
||||
|
||||
impl<'a, F: Function> Env<'a, F> {
|
||||
pub(crate) fn new(func: &'a F, env: &'a MachineEnv, cfginfo: CFGInfo) -> Self {
|
||||
pub(crate) fn new(
|
||||
func: &'a F,
|
||||
env: &'a MachineEnv,
|
||||
cfginfo: CFGInfo,
|
||||
annotations_enabled: bool,
|
||||
) -> Self {
|
||||
let n = func.insts();
|
||||
Self {
|
||||
func,
|
||||
@@ -742,6 +748,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
stats: Stats::default(),
|
||||
|
||||
debug_annotations: std::collections::HashMap::new(),
|
||||
annotations_enabled,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1141,9 +1148,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
OperandPos::Before,
|
||||
);
|
||||
|
||||
#[cfg(debug)]
|
||||
{
|
||||
if log::log_enabled!(log::Level::Debug) {
|
||||
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||
self.annotate(
|
||||
ProgPoint::after(inst),
|
||||
format!(
|
||||
@@ -1155,7 +1160,6 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// N.B.: in order to integrate with the move
|
||||
// resolution that joins LRs in general, we
|
||||
@@ -1725,9 +1729,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
for entry in &list {
|
||||
self.ranges[entry.index.index()].bundle = to;
|
||||
|
||||
#[cfg(debug)]
|
||||
{
|
||||
if log::log_enabled!(log::Level::Debug) {
|
||||
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||
self.annotate(
|
||||
entry.range.from,
|
||||
format!(
|
||||
@@ -1740,7 +1742,6 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.bundles[to.index()].ranges = list;
|
||||
|
||||
return true;
|
||||
@@ -1780,10 +1781,8 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
}
|
||||
last_range = Some(entry.range);
|
||||
|
||||
#[cfg(debug)]
|
||||
{
|
||||
if self.ranges[entry.index.index()].bundle == from {
|
||||
if log::log_enabled!(log::Level::Debug) {
|
||||
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||
self.annotate(
|
||||
entry.range.from,
|
||||
format!(
|
||||
@@ -1796,7 +1795,6 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log::debug!(
|
||||
" -> merged result for bundle{}: range{}",
|
||||
@@ -2765,8 +2763,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
cur_uses.next();
|
||||
}
|
||||
|
||||
#[cfg(debug)]
|
||||
{
|
||||
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||
self.annotate(
|
||||
existing_range.to,
|
||||
format!(
|
||||
@@ -3396,9 +3393,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
);
|
||||
debug_assert!(alloc != Allocation::none());
|
||||
|
||||
#[cfg(debug)]
|
||||
{
|
||||
if log::log_enabled!(log::Level::Debug) {
|
||||
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||
self.annotate(
|
||||
range.from,
|
||||
format!(
|
||||
@@ -3406,7 +3401,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
vreg.index(),
|
||||
alloc,
|
||||
entry.index.index(),
|
||||
self.ranges[entry.index.index()].bundle.index(),
|
||||
self.ranges[entry.index.index()].bundle.raw_u32(),
|
||||
),
|
||||
);
|
||||
self.annotate(
|
||||
@@ -3416,11 +3411,10 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
vreg.index(),
|
||||
alloc,
|
||||
entry.index.index(),
|
||||
self.ranges[entry.index.index()].bundle.index(),
|
||||
self.ranges[entry.index.index()].bundle.raw_u32(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Does this range follow immediately after a prior
|
||||
// range in the same block? If so, insert a move (if
|
||||
@@ -3541,9 +3535,9 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
),
|
||||
alloc,
|
||||
});
|
||||
#[cfg(debug)]
|
||||
|
||||
if self.annotations_enabled && log::log_enabled!(log::Level::Debug)
|
||||
{
|
||||
if log::log_enabled!(log::Level::Debug) {
|
||||
self.annotate(
|
||||
self.cfginfo.block_exit[block.index()],
|
||||
format!(
|
||||
@@ -3557,7 +3551,7 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
blockparam_out_idx += 1;
|
||||
}
|
||||
|
||||
@@ -4341,10 +4335,14 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run<F: Function>(func: &F, mach_env: &MachineEnv) -> Result<Output, RegAllocError> {
|
||||
pub fn run<F: Function>(
|
||||
func: &F,
|
||||
mach_env: &MachineEnv,
|
||||
enable_annotations: bool,
|
||||
) -> Result<Output, RegAllocError> {
|
||||
let cfginfo = CFGInfo::new(func)?;
|
||||
|
||||
let mut env = Env::new(func, mach_env, cfginfo);
|
||||
let mut env = Env::new(func, mach_env, cfginfo, enable_annotations);
|
||||
env.init()?;
|
||||
|
||||
env.run()?;
|
||||
|
||||
15
src/lib.rs
15
src/lib.rs
@@ -1010,6 +1010,17 @@ impl std::fmt::Display for RegAllocError {
|
||||
|
||||
impl std::error::Error for RegAllocError {}
|
||||
|
||||
pub fn run<F: Function>(func: &F, env: &MachineEnv) -> Result<Output, RegAllocError> {
|
||||
ion::run(func, env)
|
||||
pub fn run<F: Function>(
|
||||
func: &F,
|
||||
env: &MachineEnv,
|
||||
options: &RegallocOptions,
|
||||
) -> Result<Output, RegAllocError> {
|
||||
ion::run(func, env, options.verbose_log)
|
||||
}
|
||||
|
||||
/// Options for allocation.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct RegallocOptions {
|
||||
/// Add extra verbosity to debug logs.
|
||||
pub verbose_log: bool,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user