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.

View File

@@ -72,12 +72,8 @@ pub fn legalize_function(func: &mut ir::Function, cfg: &mut ControlFlowGraph, is
split::simplify_branch_arguments(&mut pos.func.dfg, inst);
}
match isa.encode(
&pos.func.dfg,
&pos.func.dfg[inst],
pos.func.dfg.ctrl_typevar(inst),
) {
Ok(encoding) => pos.func.encodings[inst] = encoding,
match pos.func.update_encoding(inst, isa) {
Ok(()) => {}
Err(action) => {
// We should transform the instruction into legal equivalents.
let changed = action(inst, pos.func, cfg, isa);

View File

@@ -1058,11 +1058,7 @@ impl<'a> Verifier<'a> {
if let Some(text) = needs_enc {
// This instruction needs an encoding, so generate an error.
// Provide the ISA default encoding as a hint.
match isa.encode(
&self.func.dfg,
&self.func.dfg[inst],
self.func.dfg.ctrl_typevar(inst),
) {
match self.func.dfg.encode(inst, isa) {
Ok(enc) => {
return err!(
inst,