Move the 'ins' method to DataFlowGraph.
This given us better symmetry between the replace and insert builder operations:
dfg.replace(inst).iadd(x, y)
dfg.ins(cursor).imul(x, y)
This commit is contained in:
@@ -184,16 +184,16 @@ mod tests {
|
||||
let jmp_ebb1_ebb2;
|
||||
|
||||
{
|
||||
let mut cur = Cursor::new(&mut func.layout);
|
||||
let dfg = &mut func.dfg;
|
||||
let cur = &mut Cursor::new(&mut func.layout);
|
||||
|
||||
cur.insert_ebb(ebb0);
|
||||
br_ebb0_ebb2 = cur.ins(dfg).brnz(cond, ebb2, VariableArgs::new());
|
||||
jmp_ebb0_ebb1 = cur.ins(dfg).jump(ebb1, VariableArgs::new());
|
||||
br_ebb0_ebb2 = dfg.ins(cur).brnz(cond, ebb2, VariableArgs::new());
|
||||
jmp_ebb0_ebb1 = dfg.ins(cur).jump(ebb1, VariableArgs::new());
|
||||
|
||||
cur.insert_ebb(ebb1);
|
||||
br_ebb1_ebb1 = cur.ins(dfg).brnz(cond, ebb1, VariableArgs::new());
|
||||
jmp_ebb1_ebb2 = cur.ins(dfg).jump(ebb2, VariableArgs::new());
|
||||
br_ebb1_ebb1 = dfg.ins(cur).brnz(cond, ebb1, VariableArgs::new());
|
||||
jmp_ebb1_ebb2 = dfg.ins(cur).jump(ebb2, VariableArgs::new());
|
||||
|
||||
cur.insert_ebb(ebb2);
|
||||
}
|
||||
|
||||
@@ -142,18 +142,18 @@ mod test {
|
||||
let jmp_ebb1_ebb2;
|
||||
|
||||
{
|
||||
let mut cur = Cursor::new(&mut func.layout);
|
||||
let dfg = &mut func.dfg;
|
||||
let cur = &mut Cursor::new(&mut func.layout);
|
||||
|
||||
cur.insert_ebb(ebb3);
|
||||
jmp_ebb3_ebb1 = cur.ins(dfg).jump(ebb1, VariableArgs::new());
|
||||
jmp_ebb3_ebb1 = dfg.ins(cur).jump(ebb1, VariableArgs::new());
|
||||
|
||||
cur.insert_ebb(ebb1);
|
||||
br_ebb1_ebb0 = cur.ins(dfg).brnz(cond, ebb0, VariableArgs::new());
|
||||
jmp_ebb1_ebb2 = cur.ins(dfg).jump(ebb2, VariableArgs::new());
|
||||
br_ebb1_ebb0 = dfg.ins(cur).brnz(cond, ebb0, VariableArgs::new());
|
||||
jmp_ebb1_ebb2 = dfg.ins(cur).jump(ebb2, VariableArgs::new());
|
||||
|
||||
cur.insert_ebb(ebb2);
|
||||
cur.ins(dfg).jump(ebb0, VariableArgs::new());
|
||||
dfg.ins(cur).jump(ebb0, VariableArgs::new());
|
||||
|
||||
cur.insert_ebb(ebb0);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ use ir::entities::{NO_VALUE, ExpandedValue};
|
||||
use ir::instructions::{InstructionData, CallInfo};
|
||||
use ir::extfunc::ExtFuncData;
|
||||
use entity_map::{EntityMap, PrimaryEntityData};
|
||||
use ir::builder::ReplaceBuilder;
|
||||
use ir::builder::{InsertBuilder, ReplaceBuilder};
|
||||
use ir::layout::Cursor;
|
||||
|
||||
use std::mem;
|
||||
use std::ops::{Index, IndexMut};
|
||||
@@ -271,6 +272,13 @@ impl DataFlowGraph {
|
||||
total_results
|
||||
}
|
||||
|
||||
/// Create an `InsertBuilder` that will insert an instruction at the cursor's current position.
|
||||
pub fn ins<'c, 'fc: 'c, 'fd>(&'fd mut self,
|
||||
at: &'c mut Cursor<'fc>)
|
||||
-> InsertBuilder<'c, 'fc, 'fd> {
|
||||
InsertBuilder::new(self, at)
|
||||
}
|
||||
|
||||
/// Create a `ReplaceBuilder` that will replace `inst` with a new instruction in place.
|
||||
pub fn replace(&mut self, inst: Inst) -> ReplaceBuilder {
|
||||
ReplaceBuilder::new(self, inst)
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
use std::iter::{Iterator, IntoIterator};
|
||||
use entity_map::{EntityMap, EntityRef};
|
||||
use ir::entities::{Ebb, NO_EBB, Inst, NO_INST};
|
||||
use ir::dfg::DataFlowGraph;
|
||||
use ir::builder::InsertBuilder;
|
||||
|
||||
/// The `Layout` struct determines the layout of EBBs and instructions in a function. It does not
|
||||
/// contain definitions of instructions or EBBs, but depends on `Inst` and `Ebb` entity references
|
||||
@@ -617,11 +615,6 @@ impl<'f> Cursor<'f> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a builder for inserting an instruction at the current position.
|
||||
pub fn ins<'c, 'fd>(&'c mut self, dfg: &'fd mut DataFlowGraph) -> InsertBuilder<'c, 'f, 'fd> {
|
||||
InsertBuilder::new(dfg, self)
|
||||
}
|
||||
|
||||
/// Insert an EBB at the current position and switch to it.
|
||||
///
|
||||
/// As far as possible, this method behaves as if the EBB header were an instruction inserted
|
||||
|
||||
Reference in New Issue
Block a user