ARM64 backend, part 3 / 11: MachInst infrastructure.
This patch adds the MachInst, or Machine Instruction, infrastructure. This is the machine-independent portion of the new backend design. It contains the implementation of the "vcode" (virtual-registerized code) container, the top-level lowering algorithm and compilation pipeline, and the trait definitions that the machine backends will fill in. This backend infrastructure is included in the compilation of the `codegen` crate, but it is not yet tied into the public APIs; that patch will come last, after all the other pieces are filled in. This patch contains code written by Julian Seward <jseward@acm.org> and Benjamin Bouvier <public@benj.me>, originally developed on a side-branch before rebasing and condensing into this patch series. See the `arm64` branch at `https://github.com/cfallin/wasmtime` for original development history. Co-authored-by: Julian Seward <jseward@acm.org> Co-authored-by: Benjamin Bouvier <public@benj.me>
This commit is contained in:
123
cranelift/codegen/src/machinst/adapter.rs
Normal file
123
cranelift/codegen/src/machinst/adapter.rs
Normal file
@@ -0,0 +1,123 @@
|
||||
//! Adapter for a `MachBackend` to implement the `TargetIsa` trait.
|
||||
|
||||
use crate::binemit;
|
||||
use crate::ir;
|
||||
use crate::isa::{EncInfo, Encoding, Encodings, Legalize, RegClass, RegInfo, TargetIsa};
|
||||
use crate::machinst::*;
|
||||
use crate::regalloc::{RegDiversions, RegisterSet};
|
||||
use crate::settings::Flags;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use target_lexicon::Triple;
|
||||
|
||||
/// A wrapper around a `MachBackend` that provides a `TargetIsa` impl.
|
||||
pub struct TargetIsaAdapter {
|
||||
backend: Box<dyn MachBackend + Send + Sync + 'static>,
|
||||
triple: Triple,
|
||||
}
|
||||
|
||||
impl TargetIsaAdapter {
|
||||
/// Create a new `TargetIsa` wrapper around a `MachBackend`.
|
||||
pub fn new<B: MachBackend + Send + Sync + 'static>(backend: B) -> TargetIsaAdapter {
|
||||
let triple = backend.triple();
|
||||
TargetIsaAdapter {
|
||||
backend: Box::new(backend),
|
||||
triple,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for TargetIsaAdapter {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "MachBackend")
|
||||
}
|
||||
}
|
||||
|
||||
impl TargetIsa for TargetIsaAdapter {
|
||||
fn name(&self) -> &'static str {
|
||||
self.backend.name()
|
||||
}
|
||||
|
||||
fn triple(&self) -> &Triple {
|
||||
&self.triple
|
||||
}
|
||||
|
||||
fn flags(&self) -> &Flags {
|
||||
self.backend.flags()
|
||||
}
|
||||
|
||||
fn register_info(&self) -> RegInfo {
|
||||
// Called from function's Display impl, so we need a stub here.
|
||||
RegInfo {
|
||||
banks: &[],
|
||||
classes: &[],
|
||||
}
|
||||
}
|
||||
|
||||
fn legal_encodings<'a>(
|
||||
&'a self,
|
||||
_func: &'a ir::Function,
|
||||
_inst: &'a ir::InstructionData,
|
||||
_ctrl_typevar: ir::Type,
|
||||
) -> Encodings<'a> {
|
||||
panic!("Should not be called when new-style backend is available!")
|
||||
}
|
||||
|
||||
fn encode(
|
||||
&self,
|
||||
_func: &ir::Function,
|
||||
_inst: &ir::InstructionData,
|
||||
_ctrl_typevar: ir::Type,
|
||||
) -> Result<Encoding, Legalize> {
|
||||
panic!("Should not be called when new-style backend is available!")
|
||||
}
|
||||
|
||||
fn encoding_info(&self) -> EncInfo {
|
||||
panic!("Should not be called when new-style backend is available!")
|
||||
}
|
||||
|
||||
fn legalize_signature(&self, _sig: &mut Cow<ir::Signature>, _current: bool) {
|
||||
panic!("Should not be called when new-style backend is available!")
|
||||
}
|
||||
|
||||
fn regclass_for_abi_type(&self, _ty: ir::Type) -> RegClass {
|
||||
panic!("Should not be called when new-style backend is available!")
|
||||
}
|
||||
|
||||
fn allocatable_registers(&self, _func: &ir::Function) -> RegisterSet {
|
||||
panic!("Should not be called when new-style backend is available!")
|
||||
}
|
||||
|
||||
fn prologue_epilogue(&self, _func: &mut ir::Function) -> CodegenResult<()> {
|
||||
panic!("Should not be called when new-style backend is available!")
|
||||
}
|
||||
|
||||
#[cfg(feature = "testing_hooks")]
|
||||
fn emit_inst(
|
||||
&self,
|
||||
_func: &ir::Function,
|
||||
_inst: ir::Inst,
|
||||
_divert: &mut RegDiversions,
|
||||
_sink: &mut dyn binemit::CodeSink,
|
||||
) {
|
||||
panic!("Should not be called when new-style backend is available!")
|
||||
}
|
||||
|
||||
/// Emit a whole function into memory.
|
||||
fn emit_function_to_memory(&self, _func: &ir::Function, _sink: &mut binemit::MemoryCodeSink) {
|
||||
panic!("Should not be called when new-style backend is available!")
|
||||
}
|
||||
|
||||
fn get_mach_backend(&self) -> Option<&dyn MachBackend> {
|
||||
Some(&*self.backend)
|
||||
}
|
||||
|
||||
fn unsigned_add_overflow_condition(&self) -> ir::condcodes::IntCC {
|
||||
self.backend.unsigned_add_overflow_condition()
|
||||
}
|
||||
|
||||
fn unsigned_sub_overflow_condition(&self) -> ir::condcodes::IntCC {
|
||||
self.backend.unsigned_sub_overflow_condition()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user