mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-25 06:31:32 +00:00
Enable nan canonicalization for cranelift backend.
This commit is contained in:
@ -19,7 +19,7 @@ use std::mem;
|
|||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use wasmer_runtime_core::error::CompileError;
|
use wasmer_runtime_core::error::CompileError;
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
backend::{CacheGen, Token},
|
backend::{CacheGen, CompilerConfig, Token},
|
||||||
cache::{Artifact, Error as CacheError},
|
cache::{Artifact, Error as CacheError},
|
||||||
codegen::*,
|
codegen::*,
|
||||||
memory::MemoryType,
|
memory::MemoryType,
|
||||||
@ -36,7 +36,7 @@ use wasmparser::Type as WpType;
|
|||||||
static BACKEND_ID: &str = "cranelift";
|
static BACKEND_ID: &str = "cranelift";
|
||||||
|
|
||||||
pub struct CraneliftModuleCodeGenerator {
|
pub struct CraneliftModuleCodeGenerator {
|
||||||
isa: Box<dyn isa::TargetIsa>,
|
isa: Option<Box<dyn isa::TargetIsa>>,
|
||||||
signatures: Option<Arc<Map<SigIndex, FuncSig>>>,
|
signatures: Option<Arc<Map<SigIndex, FuncSig>>>,
|
||||||
pub clif_signatures: Map<SigIndex, ir::Signature>,
|
pub clif_signatures: Map<SigIndex, ir::Signature>,
|
||||||
function_signatures: Option<Arc<Map<FuncIndex, SigIndex>>>,
|
function_signatures: Option<Arc<Map<FuncIndex, SigIndex>>>,
|
||||||
@ -47,9 +47,8 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
|
|||||||
for CraneliftModuleCodeGenerator
|
for CraneliftModuleCodeGenerator
|
||||||
{
|
{
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let isa = get_isa();
|
|
||||||
CraneliftModuleCodeGenerator {
|
CraneliftModuleCodeGenerator {
|
||||||
isa,
|
isa: None,
|
||||||
clif_signatures: Map::new(),
|
clif_signatures: Map::new(),
|
||||||
functions: vec![],
|
functions: vec![],
|
||||||
function_signatures: None,
|
function_signatures: None,
|
||||||
@ -100,7 +99,7 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
|
|||||||
position: Position::default(),
|
position: Position::default(),
|
||||||
func_env: FunctionEnvironment {
|
func_env: FunctionEnvironment {
|
||||||
module_info: Arc::clone(&module_info),
|
module_info: Arc::clone(&module_info),
|
||||||
target_config: self.isa.frontend_config().clone(),
|
target_config: self.isa.as_ref().unwrap().frontend_config().clone(),
|
||||||
clif_signatures: self.clif_signatures.clone(),
|
clif_signatures: self.clif_signatures.clone(),
|
||||||
},
|
},
|
||||||
loc,
|
loc,
|
||||||
@ -162,9 +161,9 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
|
|||||||
}
|
}
|
||||||
|
|
||||||
let (func_resolver_builder, debug_metadata, handler_data) =
|
let (func_resolver_builder, debug_metadata, handler_data) =
|
||||||
FuncResolverBuilder::new(&*self.isa, func_bodies, module_info)?;
|
FuncResolverBuilder::new(&**self.isa.as_ref().unwrap(), func_bodies, module_info)?;
|
||||||
|
|
||||||
let trampolines = Arc::new(Trampolines::new(&*self.isa, module_info));
|
let trampolines = Arc::new(Trampolines::new(&**self.isa.as_ref().unwrap(), module_info));
|
||||||
|
|
||||||
let signatures_empty = Map::new();
|
let signatures_empty = Map::new();
|
||||||
let signatures = if self.signatures.is_some() {
|
let signatures = if self.signatures.is_some() {
|
||||||
@ -191,9 +190,19 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn feed_compiler_config(&mut self, config: &CompilerConfig) -> Result<(), CodegenError> {
|
||||||
|
self.isa = Some(get_isa(Some(config)));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn feed_signatures(&mut self, signatures: Map<SigIndex, FuncSig>) -> Result<(), CodegenError> {
|
fn feed_signatures(&mut self, signatures: Map<SigIndex, FuncSig>) -> Result<(), CodegenError> {
|
||||||
self.signatures = Some(Arc::new(signatures));
|
self.signatures = Some(Arc::new(signatures));
|
||||||
let call_conv = self.isa.frontend_config().default_call_conv;
|
let call_conv = self
|
||||||
|
.isa
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.frontend_config()
|
||||||
|
.default_call_conv;
|
||||||
for (_sig_idx, func_sig) in self.signatures.as_ref().unwrap().iter() {
|
for (_sig_idx, func_sig) in self.signatures.as_ref().unwrap().iter() {
|
||||||
self.clif_signatures
|
self.clif_signatures
|
||||||
.push(convert_func_sig(func_sig, call_conv));
|
.push(convert_func_sig(func_sig, call_conv));
|
||||||
@ -1302,7 +1311,10 @@ fn generate_signature(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn pointer_type(mcg: &CraneliftModuleCodeGenerator) -> ir::Type {
|
fn pointer_type(mcg: &CraneliftModuleCodeGenerator) -> ir::Type {
|
||||||
ir::Type::int(u16::from(mcg.isa.frontend_config().pointer_bits())).unwrap()
|
ir::Type::int(u16::from(
|
||||||
|
mcg.isa.as_ref().unwrap().frontend_config().pointer_bits(),
|
||||||
|
))
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Declare local variables for the signature parameters that correspond to WebAssembly locals.
|
/// Declare local variables for the signature parameters that correspond to WebAssembly locals.
|
||||||
|
@ -29,6 +29,7 @@ use cranelift_codegen::{
|
|||||||
settings::{self, Configurable},
|
settings::{self, Configurable},
|
||||||
};
|
};
|
||||||
use target_lexicon::Triple;
|
use target_lexicon::Triple;
|
||||||
|
use wasmer_runtime_core::{backend::CompilerConfig, codegen::SimpleStreamingCompilerGen};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
@ -36,7 +37,7 @@ extern crate serde_derive;
|
|||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
fn get_isa() -> Box<dyn isa::TargetIsa> {
|
fn get_isa(config: Option<&CompilerConfig>) -> Box<dyn isa::TargetIsa> {
|
||||||
let flags = {
|
let flags = {
|
||||||
let mut builder = settings::builder();
|
let mut builder = settings::builder();
|
||||||
builder.set("opt_level", "speed_and_size").unwrap();
|
builder.set("opt_level", "speed_and_size").unwrap();
|
||||||
@ -48,6 +49,12 @@ fn get_isa() -> Box<dyn isa::TargetIsa> {
|
|||||||
builder.set("enable_verifier", "false").unwrap();
|
builder.set("enable_verifier", "false").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(config) = config {
|
||||||
|
if config.nan_canonicalization {
|
||||||
|
builder.set("enable_nan_canonicalization", "true").unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let flags = settings::Flags::new(builder);
|
let flags = settings::Flags::new(builder);
|
||||||
debug_assert_eq!(flags.opt_level(), settings::OptLevel::SpeedAndSize);
|
debug_assert_eq!(flags.opt_level(), settings::OptLevel::SpeedAndSize);
|
||||||
flags
|
flags
|
||||||
@ -58,8 +65,6 @@ fn get_isa() -> Box<dyn isa::TargetIsa> {
|
|||||||
/// The current version of this crate
|
/// The current version of this crate
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
use wasmer_runtime_core::codegen::SimpleStreamingCompilerGen;
|
|
||||||
|
|
||||||
/// Streaming compiler implementation for the Cranelift backed. Compiles web assembly binary into
|
/// Streaming compiler implementation for the Cranelift backed. Compiles web assembly binary into
|
||||||
/// machine code.
|
/// machine code.
|
||||||
pub type CraneliftCompiler = SimpleStreamingCompilerGen<
|
pub type CraneliftCompiler = SimpleStreamingCompilerGen<
|
||||||
|
@ -212,8 +212,7 @@ fn wasm_ty_to_clif(ty: Type) -> ir::types::Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_trampoline_signature() -> ir::Signature {
|
fn generate_trampoline_signature() -> ir::Signature {
|
||||||
let isa = super::get_isa();
|
let call_convention = super::get_isa(None).default_call_conv();
|
||||||
let call_convention = isa.default_call_conv();
|
|
||||||
let mut sig = ir::Signature::new(call_convention);
|
let mut sig = ir::Signature::new(call_convention);
|
||||||
|
|
||||||
let ptr_param = ir::AbiParam {
|
let ptr_param = ir::AbiParam {
|
||||||
@ -229,8 +228,7 @@ fn generate_trampoline_signature() -> ir::Signature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_export_signature(func_sig: &FuncSig) -> ir::Signature {
|
fn generate_export_signature(func_sig: &FuncSig) -> ir::Signature {
|
||||||
let isa = super::get_isa();
|
let call_convention = super::get_isa(None).default_call_conv();
|
||||||
let call_convention = isa.default_call_conv();
|
|
||||||
let mut export_clif_sig = ir::Signature::new(call_convention);
|
let mut export_clif_sig = ir::Signature::new(call_convention);
|
||||||
|
|
||||||
let func_sig_iter = func_sig.params().iter().map(|wasm_ty| ir::AbiParam {
|
let func_sig_iter = func_sig.params().iter().map(|wasm_ty| ir::AbiParam {
|
||||||
|
Reference in New Issue
Block a user