Make the dfg.insts table private again.

- Add a dfg.is_inst_valid() method for the verifier.
- Use the inst_args_mut() method when rewriting values in the parser.
- Add a new branch_destination_mut() to use when rewriting EBBs.

This also gets rid of one of the large instruction format switches in
the parser.
This commit is contained in:
Jakob Stoklund Olesen
2017-04-11 15:03:43 -07:00
parent 5209778ae2
commit fe0d986110
4 changed files with 24 additions and 67 deletions

View File

@@ -26,7 +26,7 @@ pub struct DataFlowGraph {
/// Data about all of the instructions in the function, including opcodes and operands.
/// The instructions in this map are not in program order. That is tracked by `Layout`, along
/// with the EBB containing each instruction.
pub insts: EntityMap<Inst, InstructionData>,
insts: EntityMap<Inst, InstructionData>,
/// Memory pool of value lists referenced by instructions in `insts`.
pub value_lists: ValueListPool,
@@ -77,6 +77,11 @@ impl DataFlowGraph {
self.insts.len()
}
/// Returns `true` if the given instruction reference is valid.
pub fn inst_is_valid(&self, inst: Inst) -> bool {
self.insts.is_valid(inst)
}
/// Get the total number of extended basic blocks created in this function, whether they are
/// currently inserted in the layout or not.
///

View File

@@ -376,6 +376,19 @@ impl InstructionData {
}
}
/// Get a mutable reference to the single destination of this branch instruction, if it is a
/// single destination branch or jump.
///
/// Multi-destination branches like `br_table` return `None`.
pub fn branch_destination_mut(&mut self) -> Option<&mut Ebb> {
match *self {
InstructionData::Jump { ref mut destination, .. } => Some(destination),
InstructionData::Branch { ref mut destination, .. } => Some(destination),
InstructionData::BranchIcmp { ref mut destination, .. } => Some(destination),
_ => None,
}
}
/// Return information about a call instruction.
///
/// Any instruction that can call another function reveals its call signature here.

View File

@@ -337,7 +337,7 @@ impl<'a> Verifier<'a> {
match dfg.value_def(v) {
ValueDef::Res(def_inst, _) => {
// Value is defined by an instruction that exists.
if !dfg.insts.is_valid(def_inst) {
if !dfg.inst_is_valid(def_inst) {
return err!(loc_inst,
"{} is defined by invalid instruction {}",
v,