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. //! Data flow graph tracking Instructions, Values, and EBBs.
use entity::{PrimaryMap, EntityMap}; use entity::{PrimaryMap, EntityMap};
use isa::TargetIsa; use isa::{TargetIsa, Encoding, Legalize};
use ir; use ir;
use ir::builder::ReplaceBuilder; use ir::builder::ReplaceBuilder;
use ir::extfunc::ExtFuncData; use ir::extfunc::ExtFuncData;
@@ -645,6 +645,12 @@ impl DataFlowGraph {
self.value_type(self.first_result(inst)) 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. /// 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::{InstEncodings, ValueLocations, JumpTables, StackSlots, EbbOffsets, SourceLocs};
use ir::{Ebb, JumpTableData, JumpTable, StackSlotData, StackSlot, SigRef, ExtFuncData, FuncRef, use ir::{Ebb, JumpTableData, JumpTable, StackSlotData, StackSlot, SigRef, ExtFuncData, FuncRef,
GlobalVarData, GlobalVar, HeapData, Heap}; GlobalVarData, GlobalVar, HeapData, Heap};
use isa::{TargetIsa, EncInfo}; use isa::{TargetIsa, EncInfo, Legalize};
use std::fmt; use std::fmt;
use write::write_function; use write::write_function;
@@ -176,6 +176,13 @@ impl Function {
iter: self.layout.ebb_insts(ebb), 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. /// 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); split::simplify_branch_arguments(&mut pos.func.dfg, inst);
} }
match isa.encode( match pos.func.update_encoding(inst, isa) {
&pos.func.dfg, Ok(()) => {}
&pos.func.dfg[inst],
pos.func.dfg.ctrl_typevar(inst),
) {
Ok(encoding) => pos.func.encodings[inst] = encoding,
Err(action) => { Err(action) => {
// We should transform the instruction into legal equivalents. // We should transform the instruction into legal equivalents.
let changed = action(inst, pos.func, cfg, isa); let changed = action(inst, pos.func, cfg, isa);

View File

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