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:
@@ -13,12 +13,12 @@ pub enum CursorPosition {
|
||||
/// Cursor is pointing at an existing instruction.
|
||||
/// New instructions will be inserted *before* the current instruction.
|
||||
At(ir::Inst),
|
||||
/// Cursor is before the beginning of an EBB. No instructions can be inserted. Calling
|
||||
/// `next_inst()` will move to the first instruction in the EBB.
|
||||
Before(ir::Ebb),
|
||||
/// Cursor is pointing after the end of an EBB.
|
||||
/// New instructions will be appended to the EBB.
|
||||
After(ir::Ebb),
|
||||
/// Cursor is before the beginning of an block. No instructions can be inserted. Calling
|
||||
/// `next_inst()` will move to the first instruction in the block.
|
||||
Before(ir::Block),
|
||||
/// Cursor is pointing after the end of an block.
|
||||
/// New instructions will be appended to the block.
|
||||
After(ir::Block),
|
||||
}
|
||||
|
||||
/// All cursor types implement the `Cursor` which provides common navigation operations.
|
||||
@@ -46,7 +46,7 @@ pub trait Cursor {
|
||||
/// This is intended to be used as a builder method:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb, SourceLoc};
|
||||
/// # use cranelift_codegen::ir::{Function, Block, SourceLoc};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function, srcloc: SourceLoc) {
|
||||
/// let mut pos = FuncCursor::new(func).with_srcloc(srcloc);
|
||||
@@ -76,7 +76,7 @@ pub trait Cursor {
|
||||
/// This is intended to be used as a builder method:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb, Inst};
|
||||
/// # use cranelift_codegen::ir::{Function, Block, Inst};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function, inst: Inst) {
|
||||
/// let mut pos = FuncCursor::new(func).at_inst(inst);
|
||||
@@ -92,68 +92,68 @@ pub trait Cursor {
|
||||
self
|
||||
}
|
||||
|
||||
/// Rebuild this cursor positioned at the first insertion point for `ebb`.
|
||||
/// Rebuild this cursor positioned at the first insertion point for `block`.
|
||||
/// This differs from `at_first_inst` in that it doesn't assume that any
|
||||
/// instructions have been inserted into `ebb` yet.
|
||||
/// instructions have been inserted into `block` yet.
|
||||
///
|
||||
/// This is intended to be used as a builder method:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb, Inst};
|
||||
/// # use cranelift_codegen::ir::{Function, Block, Inst};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function, ebb: Ebb) {
|
||||
/// let mut pos = FuncCursor::new(func).at_first_insertion_point(ebb);
|
||||
/// fn edit_func(func: &mut Function, block: Block) {
|
||||
/// let mut pos = FuncCursor::new(func).at_first_insertion_point(block);
|
||||
///
|
||||
/// // Use `pos`...
|
||||
/// }
|
||||
/// ```
|
||||
fn at_first_insertion_point(mut self, ebb: ir::Ebb) -> Self
|
||||
fn at_first_insertion_point(mut self, block: ir::Block) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.goto_first_insertion_point(ebb);
|
||||
self.goto_first_insertion_point(block);
|
||||
self
|
||||
}
|
||||
|
||||
/// Rebuild this cursor positioned at the first instruction in `ebb`.
|
||||
/// Rebuild this cursor positioned at the first instruction in `block`.
|
||||
///
|
||||
/// This is intended to be used as a builder method:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb, Inst};
|
||||
/// # use cranelift_codegen::ir::{Function, Block, Inst};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function, ebb: Ebb) {
|
||||
/// let mut pos = FuncCursor::new(func).at_first_inst(ebb);
|
||||
/// fn edit_func(func: &mut Function, block: Block) {
|
||||
/// let mut pos = FuncCursor::new(func).at_first_inst(block);
|
||||
///
|
||||
/// // Use `pos`...
|
||||
/// }
|
||||
/// ```
|
||||
fn at_first_inst(mut self, ebb: ir::Ebb) -> Self
|
||||
fn at_first_inst(mut self, block: ir::Block) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.goto_first_inst(ebb);
|
||||
self.goto_first_inst(block);
|
||||
self
|
||||
}
|
||||
|
||||
/// Rebuild this cursor positioned at the last instruction in `ebb`.
|
||||
/// Rebuild this cursor positioned at the last instruction in `block`.
|
||||
///
|
||||
/// This is intended to be used as a builder method:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb, Inst};
|
||||
/// # use cranelift_codegen::ir::{Function, Block, Inst};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function, ebb: Ebb) {
|
||||
/// let mut pos = FuncCursor::new(func).at_last_inst(ebb);
|
||||
/// fn edit_func(func: &mut Function, block: Block) {
|
||||
/// let mut pos = FuncCursor::new(func).at_last_inst(block);
|
||||
///
|
||||
/// // Use `pos`...
|
||||
/// }
|
||||
/// ```
|
||||
fn at_last_inst(mut self, ebb: ir::Ebb) -> Self
|
||||
fn at_last_inst(mut self, block: ir::Block) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.goto_last_inst(ebb);
|
||||
self.goto_last_inst(block);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ pub trait Cursor {
|
||||
/// This is intended to be used as a builder method:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb, Inst};
|
||||
/// # use cranelift_codegen::ir::{Function, Block, Inst};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function, inst: Inst) {
|
||||
/// let mut pos = FuncCursor::new(func).after_inst(inst);
|
||||
@@ -178,55 +178,55 @@ pub trait Cursor {
|
||||
self
|
||||
}
|
||||
|
||||
/// Rebuild this cursor positioned at the top of `ebb`.
|
||||
/// Rebuild this cursor positioned at the top of `block`.
|
||||
///
|
||||
/// This is intended to be used as a builder method:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb, Inst};
|
||||
/// # use cranelift_codegen::ir::{Function, Block, Inst};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function, ebb: Ebb) {
|
||||
/// let mut pos = FuncCursor::new(func).at_top(ebb);
|
||||
/// fn edit_func(func: &mut Function, block: Block) {
|
||||
/// let mut pos = FuncCursor::new(func).at_top(block);
|
||||
///
|
||||
/// // Use `pos`...
|
||||
/// }
|
||||
/// ```
|
||||
fn at_top(mut self, ebb: ir::Ebb) -> Self
|
||||
fn at_top(mut self, block: ir::Block) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.goto_top(ebb);
|
||||
self.goto_top(block);
|
||||
self
|
||||
}
|
||||
|
||||
/// Rebuild this cursor positioned at the bottom of `ebb`.
|
||||
/// Rebuild this cursor positioned at the bottom of `block`.
|
||||
///
|
||||
/// This is intended to be used as a builder method:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb, Inst};
|
||||
/// # use cranelift_codegen::ir::{Function, Block, Inst};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function, ebb: Ebb) {
|
||||
/// let mut pos = FuncCursor::new(func).at_bottom(ebb);
|
||||
/// fn edit_func(func: &mut Function, block: Block) {
|
||||
/// let mut pos = FuncCursor::new(func).at_bottom(block);
|
||||
///
|
||||
/// // Use `pos`...
|
||||
/// }
|
||||
/// ```
|
||||
fn at_bottom(mut self, ebb: ir::Ebb) -> Self
|
||||
fn at_bottom(mut self, block: ir::Block) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.goto_bottom(ebb);
|
||||
self.goto_bottom(block);
|
||||
self
|
||||
}
|
||||
|
||||
/// Get the EBB corresponding to the current position.
|
||||
fn current_ebb(&self) -> Option<ir::Ebb> {
|
||||
/// Get the block corresponding to the current position.
|
||||
fn current_block(&self) -> Option<ir::Block> {
|
||||
use self::CursorPosition::*;
|
||||
match self.position() {
|
||||
Nowhere => None,
|
||||
At(inst) => self.layout().inst_ebb(inst),
|
||||
Before(ebb) | After(ebb) => Some(ebb),
|
||||
At(inst) => self.layout().inst_block(inst),
|
||||
Before(block) | After(block) => Some(block),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,13 +242,13 @@ pub trait Cursor {
|
||||
/// Go to the position after a specific instruction, which must be inserted
|
||||
/// in the layout. New instructions will be inserted after `inst`.
|
||||
fn goto_after_inst(&mut self, inst: ir::Inst) {
|
||||
debug_assert!(self.layout().inst_ebb(inst).is_some());
|
||||
debug_assert!(self.layout().inst_block(inst).is_some());
|
||||
let new_pos = if let Some(next) = self.layout().next_inst(inst) {
|
||||
CursorPosition::At(next)
|
||||
} else {
|
||||
CursorPosition::After(
|
||||
self.layout()
|
||||
.inst_ebb(inst)
|
||||
.inst_block(inst)
|
||||
.expect("current instruction removed?"),
|
||||
)
|
||||
};
|
||||
@@ -258,133 +258,133 @@ pub trait Cursor {
|
||||
/// Go to a specific instruction which must be inserted in the layout.
|
||||
/// New instructions will be inserted before `inst`.
|
||||
fn goto_inst(&mut self, inst: ir::Inst) {
|
||||
debug_assert!(self.layout().inst_ebb(inst).is_some());
|
||||
debug_assert!(self.layout().inst_block(inst).is_some());
|
||||
self.set_position(CursorPosition::At(inst));
|
||||
}
|
||||
|
||||
/// Go to the position for inserting instructions at the beginning of `ebb`,
|
||||
/// Go to the position for inserting instructions at the beginning of `block`,
|
||||
/// which unlike `goto_first_inst` doesn't assume that any instructions have
|
||||
/// been inserted into `ebb` yet.
|
||||
fn goto_first_insertion_point(&mut self, ebb: ir::Ebb) {
|
||||
if let Some(inst) = self.layout().first_inst(ebb) {
|
||||
/// been inserted into `block` yet.
|
||||
fn goto_first_insertion_point(&mut self, block: ir::Block) {
|
||||
if let Some(inst) = self.layout().first_inst(block) {
|
||||
self.goto_inst(inst);
|
||||
} else {
|
||||
self.goto_bottom(ebb);
|
||||
self.goto_bottom(block);
|
||||
}
|
||||
}
|
||||
|
||||
/// Go to the first instruction in `ebb`.
|
||||
fn goto_first_inst(&mut self, ebb: ir::Ebb) {
|
||||
let inst = self.layout().first_inst(ebb).expect("Empty EBB");
|
||||
/// Go to the first instruction in `block`.
|
||||
fn goto_first_inst(&mut self, block: ir::Block) {
|
||||
let inst = self.layout().first_inst(block).expect("Empty block");
|
||||
self.goto_inst(inst);
|
||||
}
|
||||
|
||||
/// Go to the last instruction in `ebb`.
|
||||
fn goto_last_inst(&mut self, ebb: ir::Ebb) {
|
||||
let inst = self.layout().last_inst(ebb).expect("Empty EBB");
|
||||
/// Go to the last instruction in `block`.
|
||||
fn goto_last_inst(&mut self, block: ir::Block) {
|
||||
let inst = self.layout().last_inst(block).expect("Empty block");
|
||||
self.goto_inst(inst);
|
||||
}
|
||||
|
||||
/// Go to the top of `ebb` which must be inserted into the layout.
|
||||
/// Go to the top of `block` which must be inserted into the layout.
|
||||
/// At this position, instructions cannot be inserted, but `next_inst()` will move to the first
|
||||
/// instruction in `ebb`.
|
||||
fn goto_top(&mut self, ebb: ir::Ebb) {
|
||||
debug_assert!(self.layout().is_ebb_inserted(ebb));
|
||||
self.set_position(CursorPosition::Before(ebb));
|
||||
/// instruction in `block`.
|
||||
fn goto_top(&mut self, block: ir::Block) {
|
||||
debug_assert!(self.layout().is_block_inserted(block));
|
||||
self.set_position(CursorPosition::Before(block));
|
||||
}
|
||||
|
||||
/// Go to the bottom of `ebb` which must be inserted into the layout.
|
||||
/// At this position, inserted instructions will be appended to `ebb`.
|
||||
fn goto_bottom(&mut self, ebb: ir::Ebb) {
|
||||
debug_assert!(self.layout().is_ebb_inserted(ebb));
|
||||
self.set_position(CursorPosition::After(ebb));
|
||||
/// Go to the bottom of `block` which must be inserted into the layout.
|
||||
/// At this position, inserted instructions will be appended to `block`.
|
||||
fn goto_bottom(&mut self, block: ir::Block) {
|
||||
debug_assert!(self.layout().is_block_inserted(block));
|
||||
self.set_position(CursorPosition::After(block));
|
||||
}
|
||||
|
||||
/// Go to the top of the next EBB in layout order and return it.
|
||||
/// Go to the top of the next block in layout order and return it.
|
||||
///
|
||||
/// - If the cursor wasn't pointing at anything, go to the top of the first EBB in the
|
||||
/// - If the cursor wasn't pointing at anything, go to the top of the first block in the
|
||||
/// function.
|
||||
/// - If there are no more EBBs, leave the cursor pointing at nothing and return `None`.
|
||||
/// - If there are no more blocks, leave the cursor pointing at nothing and return `None`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// The `next_ebb()` method is intended for iterating over the EBBs in layout order:
|
||||
/// The `next_block()` method is intended for iterating over the blocks in layout order:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb};
|
||||
/// # use cranelift_codegen::ir::{Function, Block};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function) {
|
||||
/// let mut cursor = FuncCursor::new(func);
|
||||
/// while let Some(ebb) = cursor.next_ebb() {
|
||||
/// // Edit ebb.
|
||||
/// while let Some(block) = cursor.next_block() {
|
||||
/// // Edit block.
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
fn next_ebb(&mut self) -> Option<ir::Ebb> {
|
||||
let next = if let Some(ebb) = self.current_ebb() {
|
||||
self.layout().next_ebb(ebb)
|
||||
fn next_block(&mut self) -> Option<ir::Block> {
|
||||
let next = if let Some(block) = self.current_block() {
|
||||
self.layout().next_block(block)
|
||||
} else {
|
||||
self.layout().entry_block()
|
||||
};
|
||||
self.set_position(match next {
|
||||
Some(ebb) => CursorPosition::Before(ebb),
|
||||
Some(block) => CursorPosition::Before(block),
|
||||
None => CursorPosition::Nowhere,
|
||||
});
|
||||
next
|
||||
}
|
||||
|
||||
/// Go to the bottom of the previous EBB in layout order and return it.
|
||||
/// Go to the bottom of the previous block in layout order and return it.
|
||||
///
|
||||
/// - If the cursor wasn't pointing at anything, go to the bottom of the last EBB in the
|
||||
/// - If the cursor wasn't pointing at anything, go to the bottom of the last block in the
|
||||
/// function.
|
||||
/// - If there are no more EBBs, leave the cursor pointing at nothing and return `None`.
|
||||
/// - If there are no more blocks, leave the cursor pointing at nothing and return `None`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// The `prev_ebb()` method is intended for iterating over the EBBs in backwards layout order:
|
||||
/// The `prev_block()` method is intended for iterating over the blocks in backwards layout order:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb};
|
||||
/// # use cranelift_codegen::ir::{Function, Block};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function) {
|
||||
/// let mut cursor = FuncCursor::new(func);
|
||||
/// while let Some(ebb) = cursor.prev_ebb() {
|
||||
/// // Edit ebb.
|
||||
/// while let Some(block) = cursor.prev_block() {
|
||||
/// // Edit block.
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
fn prev_ebb(&mut self) -> Option<ir::Ebb> {
|
||||
let prev = if let Some(ebb) = self.current_ebb() {
|
||||
self.layout().prev_ebb(ebb)
|
||||
fn prev_block(&mut self) -> Option<ir::Block> {
|
||||
let prev = if let Some(block) = self.current_block() {
|
||||
self.layout().prev_block(block)
|
||||
} else {
|
||||
self.layout().last_ebb()
|
||||
self.layout().last_block()
|
||||
};
|
||||
self.set_position(match prev {
|
||||
Some(ebb) => CursorPosition::After(ebb),
|
||||
Some(block) => CursorPosition::After(block),
|
||||
None => CursorPosition::Nowhere,
|
||||
});
|
||||
prev
|
||||
}
|
||||
|
||||
/// Move to the next instruction in the same EBB and return it.
|
||||
/// Move to the next instruction in the same block and return it.
|
||||
///
|
||||
/// - If the cursor was positioned before an EBB, go to the first instruction in that EBB.
|
||||
/// - If there are no more instructions in the EBB, go to the `After(ebb)` position and return
|
||||
/// - If the cursor was positioned before an block, go to the first instruction in that block.
|
||||
/// - If there are no more instructions in the block, go to the `After(block)` position and return
|
||||
/// `None`.
|
||||
/// - If the cursor wasn't pointing anywhere, keep doing that.
|
||||
///
|
||||
/// This method will never move the cursor to a different EBB.
|
||||
/// This method will never move the cursor to a different block.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// The `next_inst()` method is intended for iterating over the instructions in an EBB like
|
||||
/// The `next_inst()` method is intended for iterating over the instructions in an block like
|
||||
/// this:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb};
|
||||
/// # use cranelift_codegen::ir::{Function, Block};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_ebb(func: &mut Function, ebb: Ebb) {
|
||||
/// let mut cursor = FuncCursor::new(func).at_top(ebb);
|
||||
/// fn edit_block(func: &mut Function, block: Block) {
|
||||
/// let mut cursor = FuncCursor::new(func).at_top(block);
|
||||
/// while let Some(inst) = cursor.next_inst() {
|
||||
/// // Edit instructions...
|
||||
/// }
|
||||
@@ -395,11 +395,11 @@ pub trait Cursor {
|
||||
/// Iterating over all the instructions in a function looks like this:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb};
|
||||
/// # use cranelift_codegen::ir::{Function, Block};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_func(func: &mut Function) {
|
||||
/// let mut cursor = FuncCursor::new(func);
|
||||
/// while let Some(ebb) = cursor.next_ebb() {
|
||||
/// while let Some(block) = cursor.next_block() {
|
||||
/// while let Some(inst) = cursor.next_inst() {
|
||||
/// // Edit instructions...
|
||||
/// }
|
||||
@@ -417,44 +417,44 @@ pub trait Cursor {
|
||||
} else {
|
||||
let pos = After(
|
||||
self.layout()
|
||||
.inst_ebb(inst)
|
||||
.inst_block(inst)
|
||||
.expect("current instruction removed?"),
|
||||
);
|
||||
self.set_position(pos);
|
||||
None
|
||||
}
|
||||
}
|
||||
Before(ebb) => {
|
||||
if let Some(next) = self.layout().first_inst(ebb) {
|
||||
Before(block) => {
|
||||
if let Some(next) = self.layout().first_inst(block) {
|
||||
self.set_position(At(next));
|
||||
Some(next)
|
||||
} else {
|
||||
self.set_position(After(ebb));
|
||||
self.set_position(After(block));
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Move to the previous instruction in the same EBB and return it.
|
||||
/// Move to the previous instruction in the same block and return it.
|
||||
///
|
||||
/// - If the cursor was positioned after an EBB, go to the last instruction in that EBB.
|
||||
/// - If there are no more instructions in the EBB, go to the `Before(ebb)` position and return
|
||||
/// - If the cursor was positioned after an block, go to the last instruction in that block.
|
||||
/// - If there are no more instructions in the block, go to the `Before(block)` position and return
|
||||
/// `None`.
|
||||
/// - If the cursor wasn't pointing anywhere, keep doing that.
|
||||
///
|
||||
/// This method will never move the cursor to a different EBB.
|
||||
/// This method will never move the cursor to a different block.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// The `prev_inst()` method is intended for iterating backwards over the instructions in an
|
||||
/// EBB like this:
|
||||
/// block like this:
|
||||
///
|
||||
/// ```
|
||||
/// # use cranelift_codegen::ir::{Function, Ebb};
|
||||
/// # use cranelift_codegen::ir::{Function, Block};
|
||||
/// # use cranelift_codegen::cursor::{Cursor, FuncCursor};
|
||||
/// fn edit_ebb(func: &mut Function, ebb: Ebb) {
|
||||
/// let mut cursor = FuncCursor::new(func).at_bottom(ebb);
|
||||
/// fn edit_block(func: &mut Function, block: Block) {
|
||||
/// let mut cursor = FuncCursor::new(func).at_bottom(block);
|
||||
/// while let Some(inst) = cursor.prev_inst() {
|
||||
/// // Edit instructions...
|
||||
/// }
|
||||
@@ -471,19 +471,19 @@ pub trait Cursor {
|
||||
} else {
|
||||
let pos = Before(
|
||||
self.layout()
|
||||
.inst_ebb(inst)
|
||||
.inst_block(inst)
|
||||
.expect("current instruction removed?"),
|
||||
);
|
||||
self.set_position(pos);
|
||||
None
|
||||
}
|
||||
}
|
||||
After(ebb) => {
|
||||
if let Some(prev) = self.layout().last_inst(ebb) {
|
||||
After(block) => {
|
||||
if let Some(prev) = self.layout().last_inst(block) {
|
||||
self.set_position(At(prev));
|
||||
Some(prev)
|
||||
} else {
|
||||
self.set_position(Before(ebb));
|
||||
self.set_position(Before(block));
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -494,17 +494,17 @@ pub trait Cursor {
|
||||
///
|
||||
/// - If pointing at an instruction, the new instruction is inserted before the current
|
||||
/// instruction.
|
||||
/// - If pointing at the bottom of an EBB, the new instruction is appended to the EBB.
|
||||
/// - If pointing at the bottom of an block, the new instruction is appended to the block.
|
||||
/// - Otherwise panic.
|
||||
///
|
||||
/// In either case, the cursor is not moved, such that repeated calls to `insert_inst()` causes
|
||||
/// instructions to appear in insertion order in the EBB.
|
||||
/// instructions to appear in insertion order in the block.
|
||||
fn insert_inst(&mut self, inst: ir::Inst) {
|
||||
use self::CursorPosition::*;
|
||||
match self.position() {
|
||||
Nowhere | Before(..) => panic!("Invalid insert_inst position"),
|
||||
At(cur) => self.layout_mut().insert_inst(inst, cur),
|
||||
After(ebb) => self.layout_mut().append_inst(inst, ebb),
|
||||
After(block) => self.layout_mut().append_inst(inst, block),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,34 +532,34 @@ pub trait Cursor {
|
||||
inst
|
||||
}
|
||||
|
||||
/// Insert an EBB at the current position and switch to it.
|
||||
/// Insert an block at the current position and switch to it.
|
||||
///
|
||||
/// As far as possible, this method behaves as if the EBB header were an instruction inserted
|
||||
/// As far as possible, this method behaves as if the block header were an instruction inserted
|
||||
/// at the current position.
|
||||
///
|
||||
/// - If the cursor is pointing at an existing instruction, *the current EBB is split in two*
|
||||
/// and the current instruction becomes the first instruction in the inserted EBB.
|
||||
/// - If the cursor points at the bottom of an EBB, the new EBB is inserted after the current
|
||||
/// one, and moved to the bottom of the new EBB where instructions can be appended.
|
||||
/// - If the cursor points to the top of an EBB, the new EBB is inserted above the current one.
|
||||
/// - If the cursor is not pointing at anything, the new EBB is placed last in the layout.
|
||||
/// - If the cursor is pointing at an existing instruction, *the current block is split in two*
|
||||
/// and the current instruction becomes the first instruction in the inserted block.
|
||||
/// - If the cursor points at the bottom of an block, the new block is inserted after the current
|
||||
/// one, and moved to the bottom of the new block where instructions can be appended.
|
||||
/// - If the cursor points to the top of an block, the new block is inserted above the current one.
|
||||
/// - If the cursor is not pointing at anything, the new block is placed last in the layout.
|
||||
///
|
||||
/// This means that it is always valid to call this method, and it always leaves the cursor in
|
||||
/// a state that will insert instructions into the new EBB.
|
||||
fn insert_ebb(&mut self, new_ebb: ir::Ebb) {
|
||||
/// a state that will insert instructions into the new block.
|
||||
fn insert_block(&mut self, new_block: ir::Block) {
|
||||
use self::CursorPosition::*;
|
||||
match self.position() {
|
||||
At(inst) => {
|
||||
self.layout_mut().split_ebb(new_ebb, inst);
|
||||
// All other cases move to `After(ebb)`, but in this case we'll stay `At(inst)`.
|
||||
self.layout_mut().split_block(new_block, inst);
|
||||
// All other cases move to `After(block)`, but in this case we'll stay `At(inst)`.
|
||||
return;
|
||||
}
|
||||
Nowhere => self.layout_mut().append_ebb(new_ebb),
|
||||
Before(ebb) => self.layout_mut().insert_ebb(new_ebb, ebb),
|
||||
After(ebb) => self.layout_mut().insert_ebb_after(new_ebb, ebb),
|
||||
Nowhere => self.layout_mut().append_block(new_block),
|
||||
Before(block) => self.layout_mut().insert_block(new_block, block),
|
||||
After(block) => self.layout_mut().insert_block_after(new_block, block),
|
||||
}
|
||||
// For everything but `At(inst)` we end up appending to the new EBB.
|
||||
self.set_position(After(new_ebb));
|
||||
// For everything but `At(inst)` we end up appending to the new block.
|
||||
self.set_position(After(new_block));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user