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:
Jakob Stoklund Olesen
2016-10-21 09:44:24 -07:00
parent 0acabc80d0
commit 1305283ed8
4 changed files with 19 additions and 18 deletions

View File

@@ -184,16 +184,16 @@ mod tests {
let jmp_ebb1_ebb2; let jmp_ebb1_ebb2;
{ {
let mut cur = Cursor::new(&mut func.layout);
let dfg = &mut func.dfg; let dfg = &mut func.dfg;
let cur = &mut Cursor::new(&mut func.layout);
cur.insert_ebb(ebb0); cur.insert_ebb(ebb0);
br_ebb0_ebb2 = cur.ins(dfg).brnz(cond, ebb2, VariableArgs::new()); br_ebb0_ebb2 = dfg.ins(cur).brnz(cond, ebb2, VariableArgs::new());
jmp_ebb0_ebb1 = cur.ins(dfg).jump(ebb1, VariableArgs::new()); jmp_ebb0_ebb1 = dfg.ins(cur).jump(ebb1, VariableArgs::new());
cur.insert_ebb(ebb1); cur.insert_ebb(ebb1);
br_ebb1_ebb1 = cur.ins(dfg).brnz(cond, ebb1, VariableArgs::new()); br_ebb1_ebb1 = dfg.ins(cur).brnz(cond, ebb1, VariableArgs::new());
jmp_ebb1_ebb2 = cur.ins(dfg).jump(ebb2, VariableArgs::new()); jmp_ebb1_ebb2 = dfg.ins(cur).jump(ebb2, VariableArgs::new());
cur.insert_ebb(ebb2); cur.insert_ebb(ebb2);
} }

View File

@@ -142,18 +142,18 @@ mod test {
let jmp_ebb1_ebb2; let jmp_ebb1_ebb2;
{ {
let mut cur = Cursor::new(&mut func.layout);
let dfg = &mut func.dfg; let dfg = &mut func.dfg;
let cur = &mut Cursor::new(&mut func.layout);
cur.insert_ebb(ebb3); 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); cur.insert_ebb(ebb1);
br_ebb1_ebb0 = cur.ins(dfg).brnz(cond, ebb0, VariableArgs::new()); br_ebb1_ebb0 = dfg.ins(cur).brnz(cond, ebb0, VariableArgs::new());
jmp_ebb1_ebb2 = cur.ins(dfg).jump(ebb2, VariableArgs::new()); jmp_ebb1_ebb2 = dfg.ins(cur).jump(ebb2, VariableArgs::new());
cur.insert_ebb(ebb2); cur.insert_ebb(ebb2);
cur.ins(dfg).jump(ebb0, VariableArgs::new()); dfg.ins(cur).jump(ebb0, VariableArgs::new());
cur.insert_ebb(ebb0); cur.insert_ebb(ebb0);
} }

View File

@@ -5,7 +5,8 @@ use ir::entities::{NO_VALUE, ExpandedValue};
use ir::instructions::{InstructionData, CallInfo}; use ir::instructions::{InstructionData, CallInfo};
use ir::extfunc::ExtFuncData; use ir::extfunc::ExtFuncData;
use entity_map::{EntityMap, PrimaryEntityData}; use entity_map::{EntityMap, PrimaryEntityData};
use ir::builder::ReplaceBuilder; use ir::builder::{InsertBuilder, ReplaceBuilder};
use ir::layout::Cursor;
use std::mem; use std::mem;
use std::ops::{Index, IndexMut}; use std::ops::{Index, IndexMut};
@@ -271,6 +272,13 @@ impl DataFlowGraph {
total_results 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. /// Create a `ReplaceBuilder` that will replace `inst` with a new instruction in place.
pub fn replace(&mut self, inst: Inst) -> ReplaceBuilder { pub fn replace(&mut self, inst: Inst) -> ReplaceBuilder {
ReplaceBuilder::new(self, inst) ReplaceBuilder::new(self, inst)

View File

@@ -6,8 +6,6 @@
use std::iter::{Iterator, IntoIterator}; use std::iter::{Iterator, IntoIterator};
use entity_map::{EntityMap, EntityRef}; use entity_map::{EntityMap, EntityRef};
use ir::entities::{Ebb, NO_EBB, Inst, NO_INST}; 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 /// 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 /// 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. /// 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 /// As far as possible, this method behaves as if the EBB header were an instruction inserted