Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix slow compilation by using dynasm VecAssembler #71

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/compiler-singlepass/src/codegen_x64.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::address_map::get_function_address_map;
use crate::config::{Intrinsic, IntrinsicKind};
use crate::{common_decl::*, config::Singlepass, emitter_x64::*, machine::Machine, x64_decl::*};
use dynasmrt::{x64::Assembler, DynamicLabel};
use dynasmrt::{x64::X64Relocation, DynamicLabel, VecAssembler};
use memoffset::offset_of;
use smallvec::{smallvec, SmallVec};
use std::collections::HashMap;
Expand All @@ -24,6 +24,8 @@ use wasmer_types::{
};
use wasmer_vm::{TableStyle, TrapCode, VMBuiltinFunctionIndex, VMOffsets};

type Assembler = VecAssembler<X64Relocation>;

/// The singlepass per-function code generator.
pub struct FuncGen<'a> {
// Immutable properties assigned at creation time.
Expand Down Expand Up @@ -1995,7 +1997,7 @@ impl<'a> FuncGen<'a> {
.collect(),
);

let mut assembler = Assembler::new().unwrap();
let mut assembler = Assembler::new(0);
ailisp marked this conversation as resolved.
Show resolved Hide resolved
let special_labels = SpecialLabelSet {
integer_division_by_zero: assembler.get_label(),
integer_overflow: assembler.get_label(),
Expand Down Expand Up @@ -8860,7 +8862,7 @@ fn sort_call_movs(movs: &mut [(Location, GPR)]) {

// Standard entry trampoline.
pub fn gen_std_trampoline(sig: &FunctionType) -> FunctionBody {
let mut a = Assembler::new().unwrap();
let mut a = Assembler::new(0);

// Calculate stack offset.
let mut stack_offset: u32 = 0;
Expand Down Expand Up @@ -8962,7 +8964,7 @@ pub fn gen_std_dynamic_import_trampoline(
vmoffsets: &VMOffsets,
sig: &FunctionType,
) -> FunctionBody {
let mut a = Assembler::new().unwrap();
let mut a = Assembler::new(0);

// Allocate argument array.
let stack_offset: usize = 16 * std::cmp::max(sig.params().len(), sig.results().len()) + 8; // 16 bytes each + 8 bytes sysv call padding
Expand Down Expand Up @@ -9056,7 +9058,7 @@ pub fn gen_import_call_trampoline(
index: FunctionIndex,
sig: &FunctionType,
) -> CustomSection {
let mut a = Assembler::new().unwrap();
let mut a = Assembler::new(0);

// TODO: ARM entry trampoline is not emitted.

Expand Down
6 changes: 5 additions & 1 deletion lib/compiler-singlepass/src/emitter_x64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
pub use crate::x64_decl::{GPR, XMM};
use dynasm::dynasm;
use dynasmrt::{x64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi};
use dynasmrt::{
x64::X64Relocation, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi, VecAssembler,
};

type Assembler = VecAssembler<X64Relocation>;

/// Dynasm proc-macro checks for an `.arch` expression in a source file to
/// determine the architecture it should use.
Expand Down
6 changes: 4 additions & 2 deletions lib/compiler-singlepass/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,14 @@ impl Machine {
#[cfg(test)]
mod test {
use super::*;
use dynasmrt::x64::Assembler;
use dynasmrt::x64::X64Relocation;
use dynasmrt::VecAssembler;
type Assembler = VecAssembler<X64Relocation>;

#[test]
fn test_release_locations_keep_state_nopanic() {
let mut machine = Machine::new();
let mut assembler = Assembler::new().unwrap();
let mut assembler = Assembler::new(0);
let locs = machine.acquire_locations(
&mut assembler,
&(0..10)
Expand Down