Add an isa/encoding module.

Define data types for the level 1 and level 2 hash tables. These data types are
generic over the offset integer type so they can be twice as compact for
typically small ISAs.

Use these new types when generating encoding hash tables.

Emit both level 1 and level 2 hash tables.

Define generic functions that perform lookups in the encoding tables.

Implement the TargetIsa::encode() method for RISC-V using these building
blocks.
This commit is contained in:
Jakob Stoklund Olesen
2016-08-29 14:00:26 -07:00
parent cdbea59269
commit 38e2436074
5 changed files with 259 additions and 16 deletions

View File

@@ -0,0 +1,14 @@
//! Encoding tables for RISC-V.
use ir::{Opcode, InstructionData};
use ir::instructions::InstructionFormat;
use ir::types;
use predicates;
use isa::encoding::{Level1Entry, Level2Entry};
// Include the generated encoding tables:
// - `LEVEL1_RV32`
// - `LEVEL1_RV64`
// - `LEVEL2`
// - `ENCLIST`
include!(concat!(env!("OUT_DIR"), "/encoding-riscv.rs"));

View File

@@ -1,16 +1,19 @@
//! RISC-V Instruction Set Architecture.
pub mod settings;
mod encoding;
use super::super::settings as shared_settings;
use isa::encoding as shared_encoding;
use super::Builder as IsaBuilder;
use super::{TargetIsa, Encoding};
use ir::{Inst, DataFlowGraph};
use ir::{InstructionData, DataFlowGraph};
#[allow(dead_code)]
struct Isa {
shared_flags: shared_settings::Flags,
isa_flags: settings::Flags,
cpumode: &'static [shared_encoding::Level1Entry<u16>],
}
pub fn isa_builder() -> IsaBuilder {
@@ -23,14 +26,30 @@ pub fn isa_builder() -> IsaBuilder {
fn isa_constructor(shared_flags: shared_settings::Flags,
builder: shared_settings::Builder)
-> Box<TargetIsa> {
let level1 = if shared_flags.is_64bit() {
&encoding::LEVEL1_RV64[..]
} else {
&encoding::LEVEL1_RV32[..]
};
Box::new(Isa {
isa_flags: settings::Flags::new(&shared_flags, builder),
shared_flags: shared_flags,
cpumode: level1,
})
}
impl TargetIsa for Isa {
fn encode(&self, _: &DataFlowGraph, _: &Inst) -> Option<Encoding> {
unimplemented!()
fn encode(&self, _: &DataFlowGraph, inst: &InstructionData) -> Option<Encoding> {
shared_encoding::lookup_enclist(inst.first_type(),
inst.opcode(),
self.cpumode,
&encoding::LEVEL2[..])
.and_then(|enclist_offset| {
shared_encoding::general_encoding(enclist_offset,
&encoding::ENCLISTS[..],
|instp| encoding::check_instp(inst, instp),
// TODO: Implement ISA predicates properly.
|isap| isap != 17)
})
}
}