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());
|
assert!(self.is_valid());
|
||||||
Self(self.0 - 1)
|
Self(self.0 - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn raw_u32(self) -> u32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::index::ContainerIndex for $ix {}
|
impl crate::index::ContainerIndex for $ix {}
|
||||||
|
|||||||
156
src/ion/mod.rs
156
src/ion/mod.rs
@@ -365,6 +365,7 @@ struct Env<'a, F: Function> {
|
|||||||
// For debug output only: a list of textual annotations at every
|
// For debug output only: a list of textual annotations at every
|
||||||
// ProgPoint to insert into the final allocated program listing.
|
// ProgPoint to insert into the final allocated program listing.
|
||||||
debug_annotations: std::collections::HashMap<ProgPoint, Vec<String>>,
|
debug_annotations: std::collections::HashMap<ProgPoint, Vec<String>>,
|
||||||
|
annotations_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -700,7 +701,12 @@ impl<'a> std::iter::Iterator for RegTraversalIter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, F: Function> Env<'a, F> {
|
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();
|
let n = func.insts();
|
||||||
Self {
|
Self {
|
||||||
func,
|
func,
|
||||||
@@ -742,6 +748,7 @@ impl<'a, F: Function> Env<'a, F> {
|
|||||||
stats: Stats::default(),
|
stats: Stats::default(),
|
||||||
|
|
||||||
debug_annotations: std::collections::HashMap::new(),
|
debug_annotations: std::collections::HashMap::new(),
|
||||||
|
annotations_enabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1141,20 +1148,17 @@ impl<'a, F: Function> Env<'a, F> {
|
|||||||
OperandPos::Before,
|
OperandPos::Before,
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(debug)]
|
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||||
{
|
self.annotate(
|
||||||
if log::log_enabled!(log::Level::Debug) {
|
ProgPoint::after(inst),
|
||||||
self.annotate(
|
format!(
|
||||||
ProgPoint::after(inst),
|
" prog-move v{} ({:?}) -> v{} ({:?})",
|
||||||
format!(
|
src.vreg().vreg(),
|
||||||
" prog-move v{} ({:?}) -> v{} ({:?})",
|
src_policy,
|
||||||
src.vreg().vreg(),
|
dst.vreg().vreg(),
|
||||||
src_policy,
|
dst_policy,
|
||||||
dst.vreg().vreg(),
|
),
|
||||||
dst_policy,
|
);
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// N.B.: in order to integrate with the move
|
// N.B.: in order to integrate with the move
|
||||||
@@ -1725,20 +1729,17 @@ impl<'a, F: Function> Env<'a, F> {
|
|||||||
for entry in &list {
|
for entry in &list {
|
||||||
self.ranges[entry.index.index()].bundle = to;
|
self.ranges[entry.index.index()].bundle = to;
|
||||||
|
|
||||||
#[cfg(debug)]
|
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||||
{
|
self.annotate(
|
||||||
if log::log_enabled!(log::Level::Debug) {
|
entry.range.from,
|
||||||
self.annotate(
|
format!(
|
||||||
entry.range.from,
|
" MERGE range{} v{} from bundle{} to bundle{}",
|
||||||
format!(
|
entry.index.index(),
|
||||||
" MERGE range{} v{} from bundle{} to bundle{}",
|
self.ranges[entry.index.index()].vreg.index(),
|
||||||
entry.index.index(),
|
from.index(),
|
||||||
self.ranges[entry.index.index()].vreg.index(),
|
to.index(),
|
||||||
from.index(),
|
),
|
||||||
to.index(),
|
);
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.bundles[to.index()].ranges = list;
|
self.bundles[to.index()].ranges = list;
|
||||||
@@ -1780,21 +1781,18 @@ impl<'a, F: Function> Env<'a, F> {
|
|||||||
}
|
}
|
||||||
last_range = Some(entry.range);
|
last_range = Some(entry.range);
|
||||||
|
|
||||||
#[cfg(debug)]
|
if self.ranges[entry.index.index()].bundle == from {
|
||||||
{
|
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||||
if self.ranges[entry.index.index()].bundle == from {
|
self.annotate(
|
||||||
if log::log_enabled!(log::Level::Debug) {
|
entry.range.from,
|
||||||
self.annotate(
|
format!(
|
||||||
entry.range.from,
|
" MERGE range{} v{} from bundle{} to bundle{}",
|
||||||
format!(
|
entry.index.index(),
|
||||||
" MERGE range{} v{} from bundle{} to bundle{}",
|
self.ranges[entry.index.index()].vreg.index(),
|
||||||
entry.index.index(),
|
from.index(),
|
||||||
self.ranges[entry.index.index()].vreg.index(),
|
to.index(),
|
||||||
from.index(),
|
),
|
||||||
to.index(),
|
);
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2765,8 +2763,7 @@ impl<'a, F: Function> Env<'a, F> {
|
|||||||
cur_uses.next();
|
cur_uses.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug)]
|
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||||
{
|
|
||||||
self.annotate(
|
self.annotate(
|
||||||
existing_range.to,
|
existing_range.to,
|
||||||
format!(
|
format!(
|
||||||
@@ -3396,30 +3393,27 @@ impl<'a, F: Function> Env<'a, F> {
|
|||||||
);
|
);
|
||||||
debug_assert!(alloc != Allocation::none());
|
debug_assert!(alloc != Allocation::none());
|
||||||
|
|
||||||
#[cfg(debug)]
|
if self.annotations_enabled && log::log_enabled!(log::Level::Debug) {
|
||||||
{
|
self.annotate(
|
||||||
if log::log_enabled!(log::Level::Debug) {
|
range.from,
|
||||||
self.annotate(
|
format!(
|
||||||
range.from,
|
" <<< start v{} in {} (range{}) (bundle{})",
|
||||||
format!(
|
vreg.index(),
|
||||||
" <<< start v{} in {} (range{}) (bundle{})",
|
alloc,
|
||||||
vreg.index(),
|
entry.index.index(),
|
||||||
alloc,
|
self.ranges[entry.index.index()].bundle.raw_u32(),
|
||||||
entry.index.index(),
|
),
|
||||||
self.ranges[entry.index.index()].bundle.index(),
|
);
|
||||||
),
|
self.annotate(
|
||||||
);
|
range.to,
|
||||||
self.annotate(
|
format!(
|
||||||
range.to,
|
" end v{} in {} (range{}) (bundle{}) >>>",
|
||||||
format!(
|
vreg.index(),
|
||||||
" end v{} in {} (range{}) (bundle{}) >>>",
|
alloc,
|
||||||
vreg.index(),
|
entry.index.index(),
|
||||||
alloc,
|
self.ranges[entry.index.index()].bundle.raw_u32(),
|
||||||
entry.index.index(),
|
),
|
||||||
self.ranges[entry.index.index()].bundle.index(),
|
);
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Does this range follow immediately after a prior
|
// Does this range follow immediately after a prior
|
||||||
@@ -3541,12 +3535,12 @@ impl<'a, F: Function> Env<'a, F> {
|
|||||||
),
|
),
|
||||||
alloc,
|
alloc,
|
||||||
});
|
});
|
||||||
#[cfg(debug)]
|
|
||||||
|
if self.annotations_enabled && log::log_enabled!(log::Level::Debug)
|
||||||
{
|
{
|
||||||
if log::log_enabled!(log::Level::Debug) {
|
self.annotate(
|
||||||
self.annotate(
|
self.cfginfo.block_exit[block.index()],
|
||||||
self.cfginfo.block_exit[block.index()],
|
format!(
|
||||||
format!(
|
|
||||||
"blockparam-out: block{} to block{}: v{} to v{} in {}",
|
"blockparam-out: block{} to block{}: v{} to v{} in {}",
|
||||||
from_block.index(),
|
from_block.index(),
|
||||||
to_block.index(),
|
to_block.index(),
|
||||||
@@ -3554,10 +3548,10 @@ impl<'a, F: Function> Env<'a, F> {
|
|||||||
to_vreg.index(),
|
to_vreg.index(),
|
||||||
alloc
|
alloc
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blockparam_out_idx += 1;
|
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 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.init()?;
|
||||||
|
|
||||||
env.run()?;
|
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 {}
|
impl std::error::Error for RegAllocError {}
|
||||||
|
|
||||||
pub fn run<F: Function>(func: &F, env: &MachineEnv) -> Result<Output, RegAllocError> {
|
pub fn run<F: Function>(
|
||||||
ion::run(func, env)
|
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