winch: Use aarch64 backend for code emission. (#5652)
This patch introduces basic aarch64 code generation by using `cranelift-codegen`'s backend. This commit *does not*: * Change the semantics of the code generation * Adds support for other Wasm instructions The most notable change in this patch is how addressing modes are handled at the MacroAssembler layer: instead of having a canonical address representation, this patch introduces the addressing mode as an associated type in the MacroAssembler trait. This approach has the advantage that gives each ISA enough flexiblity to describe the addressing modes and their constraints in isolation without having to worry on how a particular addressing mode is going to affect other ISAs. In the case of Aarch64 this becomes useful to describe indexed addressing modes (particularly from the stack pointer). This patch uses the concept of a shadow stack pointer (x28) as a workaround to Aarch64's stack pointer 16-byte alignment. This constraint is enforced by: * Introducing specialized addressing modes when using the real stack pointer; this enables auditing when the real stack pointer is used. As of this change, the real stack pointer is only used in the function's prologue and epilogue. * Asserting that the real stack pointer is not used as a base for addressing modes. * Ensuring that at any point during the code generation process where the stack pointer changes (e.g. when stack space is allocated / deallocated) the value of the real stack pointer is copied into the shadow stack pointer.
This commit is contained in:
@@ -1,12 +1,25 @@
|
||||
use crate::isa::{Builder, TargetIsa};
|
||||
use self::regs::{scratch, ALL_GPR};
|
||||
use crate::{
|
||||
abi::ABI,
|
||||
codegen::{CodeGen, CodeGenContext},
|
||||
frame::Frame,
|
||||
isa::{Builder, TargetIsa},
|
||||
masm::MacroAssembler,
|
||||
regalloc::RegAlloc,
|
||||
regset::RegSet,
|
||||
stack::Stack,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use cranelift_codegen::{
|
||||
isa::aarch64::settings as aarch64_settings, settings::Flags, Final, MachBufferFinalized,
|
||||
};
|
||||
use masm::MacroAssembler as Aarch64Masm;
|
||||
use target_lexicon::Triple;
|
||||
use wasmparser::{FuncType, FuncValidator, FunctionBody, ValidatorResources};
|
||||
|
||||
mod abi;
|
||||
mod address;
|
||||
mod asm;
|
||||
mod masm;
|
||||
mod regs;
|
||||
|
||||
@@ -36,7 +49,7 @@ pub(crate) struct Aarch64 {
|
||||
}
|
||||
|
||||
impl Aarch64 {
|
||||
/// Create a Aarch64 ISA.
|
||||
/// Create an Aarch64 ISA.
|
||||
pub fn new(triple: Triple, shared_flags: Flags, isa_flags: aarch64_settings::Flags) -> Self {
|
||||
Self {
|
||||
isa_flags,
|
||||
@@ -57,10 +70,22 @@ impl TargetIsa for Aarch64 {
|
||||
|
||||
fn compile_function(
|
||||
&self,
|
||||
_sig: &FuncType,
|
||||
_body: &FunctionBody,
|
||||
mut _validator: FuncValidator<ValidatorResources>,
|
||||
sig: &FuncType,
|
||||
body: &FunctionBody,
|
||||
mut validator: FuncValidator<ValidatorResources>,
|
||||
) -> Result<MachBufferFinalized<Final>> {
|
||||
todo!()
|
||||
let mut body = body.get_binary_reader();
|
||||
let mut masm = Aarch64Masm::new(self.shared_flags.clone());
|
||||
let stack = Stack::new();
|
||||
let abi = abi::Aarch64ABI::default();
|
||||
let abi_sig = abi.sig(sig);
|
||||
let frame = Frame::new(&abi_sig, &mut body, &mut validator, &abi)?;
|
||||
// TODO: Add floating point bitmask
|
||||
let regalloc = RegAlloc::new(RegSet::new(ALL_GPR, 0), scratch());
|
||||
let codegen_context = CodeGenContext::new(&mut masm, stack, &frame);
|
||||
let mut codegen = CodeGen::new::<abi::Aarch64ABI>(codegen_context, abi_sig, regalloc);
|
||||
|
||||
codegen.emit(&mut body, validator)?;
|
||||
Ok(masm.finalize())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user