Mass rename Ebb and relatives to Block (#1365)
* Manually rename BasicBlock to BlockPredecessor BasicBlock is a pair of (Ebb, Inst) that is used to represent the basic block subcomponent of an Ebb that is a predecessor to an Ebb. Eventually we will be able to remove this struct, but for now it makes sense to give it a non-conflicting name so that we can start to transition Ebb to represent a basic block. I have not updated any comments that refer to BasicBlock, as eventually we will remove BlockPredecessor and replace with Block, which is a basic block, so the comments will become correct. * Manually rename SSABuilder block types to avoid conflict SSABuilder has its own Block and BlockData types. These along with associated identifier will cause conflicts in a later commit, so they are renamed to be more verbose here. * Automatically rename 'Ebb' to 'Block' in *.rs * Automatically rename 'EBB' to 'block' in *.rs * Automatically rename 'ebb' to 'block' in *.rs * Automatically rename 'extended basic block' to 'basic block' in *.rs * Automatically rename 'an basic block' to 'a basic block' in *.rs * Manually update comment for `Block` `Block`'s wikipedia article required an update. * Automatically rename 'an `Block`' to 'a `Block`' in *.rs * Automatically rename 'extended_basic_block' to 'basic_block' in *.rs * Automatically rename 'ebb' to 'block' in *.clif * Manually rename clif constant that contains 'ebb' as substring to avoid conflict * Automatically rename filecheck uses of 'EBB' to 'BB' 'regex: EBB' -> 'regex: BB' '$EBB' -> '$BB' * Automatically rename 'EBB' 'Ebb' to 'block' in *.clif * Automatically rename 'an block' to 'a block' in *.clif * Fix broken testcase when function name length increases Test function names are limited to 16 characters. This causes the new longer name to be truncated and fail a filecheck test. An outdated comment was also fixed.
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
//! Topological order of EBBs, according to the dominator tree.
|
||||
//! Topological order of blocks, according to the dominator tree.
|
||||
|
||||
use crate::dominator_tree::DominatorTree;
|
||||
use crate::entity::EntitySet;
|
||||
use crate::ir::{Ebb, Layout};
|
||||
use crate::ir::{Block, Layout};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
/// Present EBBs in a topological order such that all dominating EBBs are guaranteed to be visited
|
||||
/// before the current EBB.
|
||||
/// Present blocks in a topological order such that all dominating blocks are guaranteed to be visited
|
||||
/// before the current block.
|
||||
///
|
||||
/// There are many topological orders of the EBBs in a function, so it is possible to provide a
|
||||
/// preferred order, and the `TopoOrder` will present EBBs in an order that is as close as possible
|
||||
/// There are many topological orders of the blocks in a function, so it is possible to provide a
|
||||
/// preferred order, and the `TopoOrder` will present blocks in an order that is as close as possible
|
||||
/// to the preferred order.
|
||||
pub struct TopoOrder {
|
||||
/// Preferred order of EBBs to visit.
|
||||
preferred: Vec<Ebb>,
|
||||
/// Preferred order of blocks to visit.
|
||||
preferred: Vec<Block>,
|
||||
|
||||
/// Next entry to get from `preferred`.
|
||||
next: usize,
|
||||
|
||||
/// Set of visited EBBs.
|
||||
visited: EntitySet<Ebb>,
|
||||
/// Set of visited blocks.
|
||||
visited: EntitySet<Block>,
|
||||
|
||||
/// Stack of EBBs to be visited next, already in `visited`.
|
||||
stack: Vec<Ebb>,
|
||||
/// Stack of blocks to be visited next, already in `visited`.
|
||||
stack: Vec<Block>,
|
||||
}
|
||||
|
||||
impl TopoOrder {
|
||||
@@ -44,11 +44,11 @@ impl TopoOrder {
|
||||
self.stack.clear();
|
||||
}
|
||||
|
||||
/// Reset and initialize with a preferred sequence of EBBs. The resulting topological order is
|
||||
/// guaranteed to contain all of the EBBs in `preferred` as well as any dominators.
|
||||
pub fn reset<Ebbs>(&mut self, preferred: Ebbs)
|
||||
/// Reset and initialize with a preferred sequence of blocks. The resulting topological order is
|
||||
/// guaranteed to contain all of the blocks in `preferred` as well as any dominators.
|
||||
pub fn reset<Blocks>(&mut self, preferred: Blocks)
|
||||
where
|
||||
Ebbs: IntoIterator<Item = Ebb>,
|
||||
Blocks: IntoIterator<Item = Block>,
|
||||
{
|
||||
self.preferred.clear();
|
||||
self.preferred.extend(preferred);
|
||||
@@ -57,27 +57,29 @@ impl TopoOrder {
|
||||
self.stack.clear();
|
||||
}
|
||||
|
||||
/// Get the next EBB in the topological order.
|
||||
/// Get the next block in the topological order.
|
||||
///
|
||||
/// Two things are guaranteed about the EBBs returned by this function:
|
||||
/// Two things are guaranteed about the blocks returned by this function:
|
||||
///
|
||||
/// - All EBBs in the `preferred` iterator given to `reset` will be returned.
|
||||
/// - All dominators are visited before the EBB returned.
|
||||
pub fn next(&mut self, layout: &Layout, domtree: &DominatorTree) -> Option<Ebb> {
|
||||
self.visited.resize(layout.ebb_capacity());
|
||||
/// - All blocks in the `preferred` iterator given to `reset` will be returned.
|
||||
/// - All dominators are visited before the block returned.
|
||||
pub fn next(&mut self, layout: &Layout, domtree: &DominatorTree) -> Option<Block> {
|
||||
self.visited.resize(layout.block_capacity());
|
||||
// Any entries in `stack` should be returned immediately. They have already been added to
|
||||
// `visited`.
|
||||
while self.stack.is_empty() {
|
||||
match self.preferred.get(self.next).cloned() {
|
||||
None => return None,
|
||||
Some(mut ebb) => {
|
||||
// We have the next EBB in the preferred order.
|
||||
Some(mut block) => {
|
||||
// We have the next block in the preferred order.
|
||||
self.next += 1;
|
||||
// Push it along with any non-visited dominators.
|
||||
while self.visited.insert(ebb) {
|
||||
self.stack.push(ebb);
|
||||
match domtree.idom(ebb) {
|
||||
Some(idom) => ebb = layout.inst_ebb(idom).expect("idom not in layout"),
|
||||
while self.visited.insert(block) {
|
||||
self.stack.push(block);
|
||||
match domtree.idom(block) {
|
||||
Some(idom) => {
|
||||
block = layout.inst_block(idom).expect("idom not in layout")
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
@@ -105,32 +107,32 @@ mod tests {
|
||||
let mut topo = TopoOrder::new();
|
||||
|
||||
assert_eq!(topo.next(&func.layout, &domtree), None);
|
||||
topo.reset(func.layout.ebbs());
|
||||
topo.reset(func.layout.blocks());
|
||||
assert_eq!(topo.next(&func.layout, &domtree), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
let mut func = Function::new();
|
||||
let ebb0 = func.dfg.make_ebb();
|
||||
let ebb1 = func.dfg.make_ebb();
|
||||
let block0 = func.dfg.make_block();
|
||||
let block1 = func.dfg.make_block();
|
||||
|
||||
{
|
||||
let mut cur = FuncCursor::new(&mut func);
|
||||
|
||||
cur.insert_ebb(ebb0);
|
||||
cur.ins().jump(ebb1, &[]);
|
||||
cur.insert_ebb(ebb1);
|
||||
cur.ins().jump(ebb1, &[]);
|
||||
cur.insert_block(block0);
|
||||
cur.ins().jump(block1, &[]);
|
||||
cur.insert_block(block1);
|
||||
cur.ins().jump(block1, &[]);
|
||||
}
|
||||
|
||||
let cfg = ControlFlowGraph::with_function(&func);
|
||||
let domtree = DominatorTree::with_function(&func, &cfg);
|
||||
let mut topo = TopoOrder::new();
|
||||
|
||||
topo.reset(iter::once(ebb1));
|
||||
assert_eq!(topo.next(&func.layout, &domtree), Some(ebb0));
|
||||
assert_eq!(topo.next(&func.layout, &domtree), Some(ebb1));
|
||||
topo.reset(iter::once(block1));
|
||||
assert_eq!(topo.next(&func.layout, &domtree), Some(block0));
|
||||
assert_eq!(topo.next(&func.layout, &domtree), Some(block1));
|
||||
assert_eq!(topo.next(&func.layout, &domtree), None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user