Return a function pointer from TargetIsa::encode().

Replace the isa::Legalize enumeration with a function pointer. This
allows an ISA to define its own specific legalization actions instead of
relying on the default two.

Generate a LEGALIZE_ACTIONS table for each ISA which contains
legalization function pointers indexed by the legalization codes that
are already in the encoding tables. Include this table in
isa/*/enc_tables.rs.

Give the `Encodings` iterator a reference to the action table and change
its `legalize()` method to return a function pointer instead of an
ISA-specific code.

The Result<> returned from TargetIsa::encode() no longer implements
Debug, so eliminate uses of unwrap and expect on that type.
This commit is contained in:
Jakob Stoklund Olesen
2017-07-27 14:46:56 -07:00
parent d1353bba05
commit 2aca35a9aa
19 changed files with 140 additions and 102 deletions

View File

@@ -15,9 +15,9 @@
use dominator_tree::DominatorTree;
use flowgraph::ControlFlowGraph;
use ir::{Function, Cursor, DataFlowGraph, InstructionData, Opcode, InstBuilder};
use ir::{self, Function, Cursor};
use ir::condcodes::IntCC;
use isa::{TargetIsa, Legalize};
use isa::TargetIsa;
use bitset::BitSet;
use ir::instructions::ValueTypeSet;
@@ -73,22 +73,7 @@ pub fn legalize_function(func: &mut Function,
Ok(encoding) => *func.encodings.ensure(inst) = encoding,
Err(action) => {
// We should transform the instruction into legal equivalents.
// Possible strategies are:
// 1. Legalize::Expand: Expand instruction into sequence of legal instructions.
// Possibly iteratively. ()
// 2. Legalize::Narrow: Split the controlling type variable into high and low
// parts. This applies both to SIMD vector types which can be halved and to
// integer types such as `i64` used on a 32-bit ISA. ().
// 3. TODO: Promote the controlling type variable to a larger type. This
// typically means expressing `i8` and `i16` arithmetic in terms if `i32`
// operations on RISC targets. (It may or may not be beneficial to promote
// small vector types versus splitting them.)
// 4. TODO: Convert to library calls. For example, floating point operations on
// an ISA with no IEEE 754 support.
let changed = match action {
Legalize::Expand => expand(&mut func.dfg, cfg, &mut pos),
Legalize::Narrow => narrow(&mut func.dfg, cfg, &mut pos),
};
let changed = action(&mut func.dfg, cfg, &mut pos);
// If the current instruction was replaced, we need to double back and revisit
// the expanded sequence. This is both to assign encodings and possible to
// expand further.