Cranelift: remove unused EncCursor
This commit is contained in:
@@ -347,7 +347,6 @@ impl Context {
|
|||||||
/// Perform LICM on the function.
|
/// Perform LICM on the function.
|
||||||
pub fn licm(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()> {
|
pub fn licm(&mut self, isa: &dyn TargetIsa) -> CodegenResult<()> {
|
||||||
do_licm(
|
do_licm(
|
||||||
isa,
|
|
||||||
&mut self.func,
|
&mut self.func,
|
||||||
&mut self.cfg,
|
&mut self.cfg,
|
||||||
&mut self.domtree,
|
&mut self.domtree,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
//! This module defines cursor data types that can be used for inserting instructions.
|
//! This module defines cursor data types that can be used for inserting instructions.
|
||||||
|
|
||||||
use crate::ir;
|
use crate::ir;
|
||||||
use crate::isa::TargetIsa;
|
|
||||||
|
|
||||||
/// The possible positions of a cursor.
|
/// The possible positions of a cursor.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
@@ -664,134 +663,3 @@ impl<'c, 'f> ir::InstInserterBase<'c> for &'c mut FuncCursor<'f> {
|
|||||||
&mut self.func.dfg
|
&mut self.func.dfg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encoding cursor.
|
|
||||||
///
|
|
||||||
/// An `EncCursor` can be used to insert instructions that are immediately assigned an encoding.
|
|
||||||
/// The cursor holds a mutable reference to the whole function which can be re-borrowed from the
|
|
||||||
/// public `pos.func` member.
|
|
||||||
pub struct EncCursor<'f> {
|
|
||||||
pos: CursorPosition,
|
|
||||||
srcloc: ir::SourceLoc,
|
|
||||||
built_inst: Option<ir::Inst>,
|
|
||||||
|
|
||||||
/// The referenced function.
|
|
||||||
pub func: &'f mut ir::Function,
|
|
||||||
|
|
||||||
/// The target ISA that will be used to encode instructions.
|
|
||||||
pub isa: &'f dyn TargetIsa,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'f> EncCursor<'f> {
|
|
||||||
/// Create a new `EncCursor` pointing nowhere.
|
|
||||||
pub fn new(func: &'f mut ir::Function, isa: &'f dyn TargetIsa) -> Self {
|
|
||||||
Self {
|
|
||||||
pos: CursorPosition::Nowhere,
|
|
||||||
srcloc: Default::default(),
|
|
||||||
built_inst: None,
|
|
||||||
func,
|
|
||||||
isa,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Use the source location of `inst` for future instructions.
|
|
||||||
pub fn use_srcloc(&mut self, inst: ir::Inst) {
|
|
||||||
self.srcloc = self.func.srclocs[inst];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create an instruction builder that will insert an encoded instruction at the current
|
|
||||||
/// position.
|
|
||||||
///
|
|
||||||
/// The builder will panic if it is used to insert an instruction that can't be encoded for
|
|
||||||
/// `self.isa`.
|
|
||||||
pub fn ins(&mut self) -> ir::InsertBuilder<&mut EncCursor<'f>> {
|
|
||||||
ir::InsertBuilder::new(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the last built instruction.
|
|
||||||
///
|
|
||||||
/// This returns the last instruction that was built using the `ins()` method on this cursor.
|
|
||||||
/// Panics if no instruction was built.
|
|
||||||
pub fn built_inst(&self) -> ir::Inst {
|
|
||||||
self.built_inst.expect("No instruction was inserted")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return an object that can display `inst`.
|
|
||||||
///
|
|
||||||
/// This is a convenience wrapper for the DFG equivalent.
|
|
||||||
pub fn display_inst(&self, inst: ir::Inst) -> ir::dfg::DisplayInst {
|
|
||||||
self.func.dfg.display_inst(inst)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'f> Cursor for EncCursor<'f> {
|
|
||||||
fn position(&self) -> CursorPosition {
|
|
||||||
self.pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_position(&mut self, pos: CursorPosition) {
|
|
||||||
self.pos = pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn srcloc(&self) -> ir::SourceLoc {
|
|
||||||
self.srcloc
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_srcloc(&mut self, srcloc: ir::SourceLoc) {
|
|
||||||
self.srcloc = srcloc;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn layout(&self) -> &ir::Layout {
|
|
||||||
&self.func.layout
|
|
||||||
}
|
|
||||||
|
|
||||||
fn layout_mut(&mut self) -> &mut ir::Layout {
|
|
||||||
&mut self.func.layout
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'c, 'f> ir::InstInserterBase<'c> for &'c mut EncCursor<'f> {
|
|
||||||
fn data_flow_graph(&self) -> &ir::DataFlowGraph {
|
|
||||||
&self.func.dfg
|
|
||||||
}
|
|
||||||
|
|
||||||
fn data_flow_graph_mut(&mut self) -> &mut ir::DataFlowGraph {
|
|
||||||
&mut self.func.dfg
|
|
||||||
}
|
|
||||||
|
|
||||||
fn insert_built_inst(self, inst: ir::Inst) -> &'c mut ir::DataFlowGraph {
|
|
||||||
// TODO: Remove this assertion once #796 is fixed.
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
if let CursorPosition::At(_) = self.position() {
|
|
||||||
if let Some(curr) = self.current_inst() {
|
|
||||||
if let Some(prev) = self.layout().prev_inst(curr) {
|
|
||||||
let prev_op = self.data_flow_graph()[prev].opcode();
|
|
||||||
let inst_op = self.data_flow_graph()[inst].opcode();
|
|
||||||
if prev_op.is_branch()
|
|
||||||
&& !prev_op.is_terminator()
|
|
||||||
&& !inst_op.is_terminator()
|
|
||||||
{
|
|
||||||
panic!(
|
|
||||||
"Inserting instruction {} after {} and before {}",
|
|
||||||
self.display_inst(inst),
|
|
||||||
self.display_inst(prev),
|
|
||||||
self.display_inst(curr)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert the instruction and remember the reference.
|
|
||||||
self.insert_inst(inst);
|
|
||||||
self.built_inst = Some(inst);
|
|
||||||
|
|
||||||
if !self.srcloc.is_default() {
|
|
||||||
self.func.srclocs[inst] = self.srcloc;
|
|
||||||
}
|
|
||||||
|
|
||||||
&mut self.func.dfg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! A Loop Invariant Code Motion optimization pass
|
//! A Loop Invariant Code Motion optimization pass
|
||||||
|
|
||||||
use crate::cursor::{Cursor, EncCursor, FuncCursor};
|
use crate::cursor::{Cursor, FuncCursor};
|
||||||
use crate::dominator_tree::DominatorTree;
|
use crate::dominator_tree::DominatorTree;
|
||||||
use crate::entity::{EntityList, ListPool};
|
use crate::entity::{EntityList, ListPool};
|
||||||
use crate::flowgraph::{BlockPredecessor, ControlFlowGraph};
|
use crate::flowgraph::{BlockPredecessor, ControlFlowGraph};
|
||||||
@@ -8,7 +8,6 @@ use crate::fx::FxHashSet;
|
|||||||
use crate::ir::{
|
use crate::ir::{
|
||||||
Block, DataFlowGraph, Function, Inst, InstBuilder, InstructionData, Layout, Opcode, Type, Value,
|
Block, DataFlowGraph, Function, Inst, InstBuilder, InstructionData, Layout, Opcode, Type, Value,
|
||||||
};
|
};
|
||||||
use crate::isa::TargetIsa;
|
|
||||||
use crate::loop_analysis::{Loop, LoopAnalysis};
|
use crate::loop_analysis::{Loop, LoopAnalysis};
|
||||||
use crate::timing;
|
use crate::timing;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
@@ -17,7 +16,6 @@ use alloc::vec::Vec;
|
|||||||
/// loop-invariant instructions out of them.
|
/// loop-invariant instructions out of them.
|
||||||
/// Changes the CFG and domtree in-place during the operation.
|
/// Changes the CFG and domtree in-place during the operation.
|
||||||
pub fn do_licm(
|
pub fn do_licm(
|
||||||
isa: &dyn TargetIsa,
|
|
||||||
func: &mut Function,
|
func: &mut Function,
|
||||||
cfg: &mut ControlFlowGraph,
|
cfg: &mut ControlFlowGraph,
|
||||||
domtree: &mut DominatorTree,
|
domtree: &mut DominatorTree,
|
||||||
@@ -40,7 +38,7 @@ pub fn do_licm(
|
|||||||
match has_pre_header(&func.layout, cfg, domtree, loop_analysis.loop_header(lp)) {
|
match has_pre_header(&func.layout, cfg, domtree, loop_analysis.loop_header(lp)) {
|
||||||
None => {
|
None => {
|
||||||
let pre_header =
|
let pre_header =
|
||||||
create_pre_header(isa, loop_analysis.loop_header(lp), func, cfg, domtree);
|
create_pre_header(loop_analysis.loop_header(lp), func, cfg, domtree);
|
||||||
pos = FuncCursor::new(func).at_last_inst(pre_header);
|
pos = FuncCursor::new(func).at_last_inst(pre_header);
|
||||||
}
|
}
|
||||||
// If there is a natural pre-header we insert new instructions just before the
|
// If there is a natural pre-header we insert new instructions just before the
|
||||||
@@ -64,7 +62,6 @@ pub fn do_licm(
|
|||||||
/// Insert a pre-header before the header, modifying the function layout and CFG to reflect it.
|
/// Insert a pre-header before the header, modifying the function layout and CFG to reflect it.
|
||||||
/// A jump instruction to the header is placed at the end of the pre-header.
|
/// A jump instruction to the header is placed at the end of the pre-header.
|
||||||
fn create_pre_header(
|
fn create_pre_header(
|
||||||
isa: &dyn TargetIsa,
|
|
||||||
header: Block,
|
header: Block,
|
||||||
func: &mut Function,
|
func: &mut Function,
|
||||||
cfg: &mut ControlFlowGraph,
|
cfg: &mut ControlFlowGraph,
|
||||||
@@ -93,7 +90,7 @@ fn create_pre_header(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inserts the pre-header at the right place in the layout.
|
// Inserts the pre-header at the right place in the layout.
|
||||||
let mut pos = EncCursor::new(func, isa).at_top(header);
|
let mut pos = FuncCursor::new(func).at_top(header);
|
||||||
pos.insert_block(pre_header);
|
pos.insert_block(pre_header);
|
||||||
pos.next_inst();
|
pos.next_inst();
|
||||||
pos.ins().jump(header, pre_header_args_value.as_slice(pool));
|
pos.ins().jump(header, pre_header_args_value.as_slice(pool));
|
||||||
|
|||||||
Reference in New Issue
Block a user