Return a Result from the TargetIsa::encode() method.
When an instruction can't be encoded, provide a viable legalization action in the form of a Legalize enum.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//! This module contains types and functions for working with the encoding tables generated by
|
||||
//! `lib/cretonne/meta/gen_encoding.py`.
|
||||
use ir::{Type, Opcode};
|
||||
use isa::Encoding;
|
||||
use isa::{Encoding, Legalize};
|
||||
use constant_hash::{Table, probe};
|
||||
|
||||
/// Level 1 hash table entry.
|
||||
@@ -83,16 +83,21 @@ pub fn lookup_enclist<OffT1, OffT2>(ctrl_typevar: Type,
|
||||
opcode: Opcode,
|
||||
level1_table: &[Level1Entry<OffT1>],
|
||||
level2_table: &[Level2Entry<OffT2>])
|
||||
-> Option<usize>
|
||||
-> Result<usize, Legalize>
|
||||
where OffT1: Into<u32> + Copy,
|
||||
OffT2: Into<u32> + Copy
|
||||
{
|
||||
probe(level1_table, ctrl_typevar, ctrl_typevar.index()).and_then(|l1idx| {
|
||||
let l1ent = &level1_table[l1idx];
|
||||
let l2off = l1ent.offset.into() as usize;
|
||||
let l2tab = &level2_table[l2off..l2off + (1 << l1ent.log2len)];
|
||||
probe(l2tab, opcode, opcode as usize).map(|l2idx| l2tab[l2idx].offset.into() as usize)
|
||||
})
|
||||
// TODO: The choice of legalization actions here is naive. This needs to be configurable.
|
||||
probe(level1_table, ctrl_typevar, ctrl_typevar.index())
|
||||
.ok_or(Legalize::Narrow)
|
||||
.and_then(|l1idx| {
|
||||
let l1ent = &level1_table[l1idx];
|
||||
let l2off = l1ent.offset.into() as usize;
|
||||
let l2tab = &level2_table[l2off..l2off + (1 << l1ent.log2len)];
|
||||
probe(l2tab, opcode, opcode as usize)
|
||||
.map(|l2idx| l2tab[l2idx].offset.into() as usize)
|
||||
.ok_or(Legalize::Expand)
|
||||
})
|
||||
}
|
||||
|
||||
/// Encoding list entry.
|
||||
|
||||
Reference in New Issue
Block a user