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 singlepass slow compilation of many function wasm by using dynasm VecAssembler #2681

Merged
merged 5 commits into from
Nov 17, 2021
Merged
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,6 +1,6 @@
use crate::address_map::get_function_address_map;
use crate::{common_decl::*, config::Singlepass, emitter_x64::*, machine::Machine, x64_decl::*};
use dynasmrt::{x64::Assembler, DynamicLabel};
use dynasmrt::{x64::X64Relocation, DynamicLabel, VecAssembler};
use smallvec::{smallvec, SmallVec};
use std::collections::BTreeMap;
use std::iter;
Expand All @@ -22,6 +22,8 @@ use wasmer_types::{
};
use wasmer_vm::{MemoryStyle, 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 @@ -1844,7 +1846,7 @@ impl<'a> FuncGen<'a> {
.collect(),
);

let mut assembler = Assembler::new().unwrap();
let mut assembler = Assembler::new(0);
let special_labels = SpecialLabelSet {
integer_division_by_zero: assembler.get_label(),
heap_access_oob: assembler.get_label(),
Expand Down Expand Up @@ -8811,7 +8813,7 @@ pub fn gen_std_trampoline(
sig: &FunctionType,
calling_convention: CallingConvention,
) -> 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 @@ -8921,7 +8923,7 @@ pub fn gen_std_dynamic_import_trampoline(
sig: &FunctionType,
calling_convention: CallingConvention,
) -> 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 @@ -9043,7 +9045,7 @@ pub fn gen_import_call_trampoline(
sig: &FunctionType,
calling_convention: CallingConvention,
) -> 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>;

/// Force `dynasm!` to use the correct arch (x64) when cross-compiling.
/// `dynasm!` proc-macro tries to auto-detect it by default by looking at the
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 @@ -586,12 +586,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