Loop analysis of the IL
* Implemented in two passes * First pass discovers the loops headers (they dominate one of their predecessors) * Second pass traverses the blocks of each loop * Discovers the loop tree structure * Offers a new LoopAnalysis data structure queried from outside the module
This commit is contained in:
committed by
Jakob Stoklund Olesen
parent
cb35869803
commit
7d6113e479
@@ -71,7 +71,7 @@ impl<K, V> EntityMap<K, V>
|
||||
pub fn keys(&self) -> Keys<K> {
|
||||
Keys {
|
||||
pos: 0,
|
||||
len: self.elems.len(),
|
||||
rev_pos: self.elems.len(),
|
||||
unused: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ pub struct Keys<K>
|
||||
where K: EntityRef
|
||||
{
|
||||
pos: usize,
|
||||
len: usize,
|
||||
rev_pos: usize,
|
||||
unused: PhantomData<K>,
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ impl<K> Iterator for Keys<K>
|
||||
type Item = K;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.pos < self.len {
|
||||
if self.pos < self.rev_pos {
|
||||
let k = K::new(self.pos);
|
||||
self.pos += 1;
|
||||
Some(k)
|
||||
@@ -203,6 +203,20 @@ impl<K> Iterator for Keys<K>
|
||||
}
|
||||
}
|
||||
|
||||
impl<K> DoubleEndedIterator for Keys<K>
|
||||
where K: EntityRef
|
||||
{
|
||||
fn next_back(&mut self) -> Option<Self::Item> {
|
||||
if self.rev_pos > self.pos {
|
||||
let k = K::new(self.rev_pos - 1);
|
||||
self.rev_pos -= 1;
|
||||
Some(k)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user