Factor out common ways to call encode from a dfg or func.

This commit is contained in:
Dan Gohman
2018-03-26 21:54:36 -07:00
parent ffe89cdc0a
commit a661a8a9bb
4 changed files with 18 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
//! Data flow graph tracking Instructions, Values, and EBBs.
use entity::{PrimaryMap, EntityMap};
use isa::TargetIsa;
use isa::{TargetIsa, Encoding, Legalize};
use ir;
use ir::builder::ReplaceBuilder;
use ir::extfunc::ExtFuncData;
@@ -645,6 +645,12 @@ impl DataFlowGraph {
self.value_type(self.first_result(inst))
}
}
/// Wrapper around `TargetIsa::encode` for encoding an existing instruction
/// in the `DataFlowGraph`.
pub fn encode(&self, inst: Inst, isa: &TargetIsa) -> Result<Encoding, Legalize> {
isa.encode(&self, &self[inst], self.ctrl_typevar(inst))
}
}
/// Allow immutable access to instructions via indexing.

View File

@@ -10,7 +10,7 @@ use ir::{ExternalName, CallConv, Signature, DataFlowGraph, Layout};
use ir::{InstEncodings, ValueLocations, JumpTables, StackSlots, EbbOffsets, SourceLocs};
use ir::{Ebb, JumpTableData, JumpTable, StackSlotData, StackSlot, SigRef, ExtFuncData, FuncRef,
GlobalVarData, GlobalVar, HeapData, Heap};
use isa::{TargetIsa, EncInfo};
use isa::{TargetIsa, EncInfo, Legalize};
use std::fmt;
use write::write_function;
@@ -176,6 +176,13 @@ impl Function {
iter: self.layout.ebb_insts(ebb),
}
}
/// Wrapper around `DataFlowGraph::encode` which assigns `inst` the resulting encoding.
pub fn update_encoding(&mut self, inst: ir::Inst, isa: &TargetIsa) -> Result<(), Legalize> {
self.dfg.encode(inst, isa).map(
|e| { self.encodings[inst] = e; },
)
}
}
/// Wrapper type capable of displaying a `Function` with correct ISA annotations.