Review feedback.

This commit is contained in:
Chris Fallin
2021-08-12 14:08:10 -07:00
parent b76b7747d0
commit 2f856435f4
4 changed files with 21 additions and 18 deletions

View File

@@ -265,13 +265,14 @@ pub struct SetBitsIter(u64);
impl Iterator for SetBitsIter { impl Iterator for SetBitsIter {
type Item = usize; type Item = usize;
fn next(&mut self) -> Option<usize> { fn next(&mut self) -> Option<usize> {
if self.0 == 0 { // Build an `Option<NonZeroU64>` so that on the nonzero path,
None // the compiler can optimize the trailing-zeroes operator
} else { // using that knowledge.
let bitidx = self.0.trailing_zeros(); std::num::NonZeroU64::new(self.0).map(|nz| {
self.0 &= !(1 << bitidx); let bitidx = nz.trailing_zeros();
Some(bitidx as usize) self.0 &= self.0 - 1; // clear highest set bit
} bitidx as usize
})
} }
} }

View File

@@ -96,7 +96,7 @@ impl<'a, F: Function> Env<'a, F> {
self.compute_liveness()?; self.compute_liveness()?;
self.merge_vreg_bundles(); self.merge_vreg_bundles();
self.queue_bundles(); self.queue_bundles();
if log::log_enabled!(log::Level::Debug) { if log::log_enabled!(log::Level::Trace) {
self.dump_state(); self.dump_state();
} }
Ok(()) Ok(())

View File

@@ -411,9 +411,9 @@ impl<'a, F: Function> Env<'a, F> {
from_block.index(), from_block.index(),
alloc, alloc,
); );
#[cfg(debug)] #[cfg(debug_assertions)]
{ {
if log::log_enabled!(log::Level::Debug) { if log::log_enabled!(log::Level::Trace) {
self.annotate( self.annotate(
self.cfginfo.block_entry[block.index()], self.cfginfo.block_entry[block.index()],
format!( format!(
@@ -772,9 +772,9 @@ impl<'a, F: Function> Env<'a, F> {
input_alloc input_alloc
); );
if input_alloc != output_alloc { if input_alloc != output_alloc {
#[cfg(debug)] #[cfg(debug_assertions)]
{ {
if log::log_enabled!(log::Level::Debug) { if log::log_enabled!(log::Level::Trace) {
self.annotate( self.annotate(
ProgPoint::before(inst), ProgPoint::before(inst),
format!( format!(

View File

@@ -47,15 +47,16 @@ impl PReg {
/// Create a new PReg. The `hw_enc` range is 6 bits. /// Create a new PReg. The `hw_enc` range is 6 bits.
#[inline(always)] #[inline(always)]
pub fn new(hw_enc: usize, class: RegClass) -> Self { pub const fn new(hw_enc: usize, class: RegClass) -> Self {
assert!(hw_enc <= Self::MAX);
PReg(hw_enc as u8, class) PReg(hw_enc as u8, class)
} }
/// The physical register number, as encoded by the ISA for the particular register class. /// The physical register number, as encoded by the ISA for the particular register class.
#[inline(always)] #[inline(always)]
pub fn hw_enc(self) -> usize { pub fn hw_enc(self) -> usize {
self.0 as usize let hw_enc = self.0 as usize;
debug_assert!(hw_enc <= Self::MAX);
hw_enc
} }
/// The register class. /// The register class.
@@ -121,14 +122,15 @@ impl VReg {
pub const MAX: usize = (1 << Self::MAX_BITS) - 1; pub const MAX: usize = (1 << Self::MAX_BITS) - 1;
#[inline(always)] #[inline(always)]
pub fn new(virt_reg: usize, class: RegClass) -> Self { pub const fn new(virt_reg: usize, class: RegClass) -> Self {
assert!(virt_reg <= Self::MAX);
VReg(((virt_reg as u32) << 1) | (class as u8 as u32)) VReg(((virt_reg as u32) << 1) | (class as u8 as u32))
} }
#[inline(always)] #[inline(always)]
pub fn vreg(self) -> usize { pub fn vreg(self) -> usize {
(self.0 >> 1) as usize let vreg = (self.0 >> 1) as usize;
debug_assert!(vreg <= Self::MAX);
vreg
} }
#[inline(always)] #[inline(always)]