mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Remove target from CompilerConfig
This commit is contained in:
@@ -54,7 +54,7 @@ impl Default for Store {
|
||||
fn get_engine(
|
||||
config: Box<dyn CompilerConfig + Send + Sync>,
|
||||
) -> Arc<dyn Engine + Send + Sync> {
|
||||
let tunables = Tunables::for_target(config.target().triple());
|
||||
let tunables = Tunables::default();
|
||||
|
||||
#[cfg(feature = "jit")]
|
||||
return Arc::new(wasmer_engine_jit::JITEngine::new(
|
||||
|
||||
@@ -5,6 +5,7 @@ use more_asserts::assert_ge;
|
||||
use std::cmp::min;
|
||||
use std::sync::Arc;
|
||||
use target_lexicon::{OperatingSystem, PointerWidth, Triple, HOST};
|
||||
use wasmer_compiler::Target;
|
||||
use wasmer_engine::Tunables as BaseTunables;
|
||||
use wasmer_runtime::MemoryError;
|
||||
use wasmer_runtime::{Memory, MemoryPlan, MemoryStyle, Table, TablePlan, TableStyle};
|
||||
@@ -12,6 +13,8 @@ use wasmer_runtime::{Memory, MemoryPlan, MemoryStyle, Table, TablePlan, TableSty
|
||||
/// Tunable parameters for WebAssembly compilation.
|
||||
#[derive(Clone)]
|
||||
pub struct Tunables {
|
||||
pub target: Target,
|
||||
|
||||
/// For static heaps, the size in wasm pages of the heap protected by bounds checking.
|
||||
pub static_memory_bound: Pages,
|
||||
|
||||
@@ -24,7 +27,8 @@ pub struct Tunables {
|
||||
|
||||
impl Tunables {
|
||||
/// Get the `Tunables` for a specific Target
|
||||
pub fn for_target(triple: &Triple) -> Self {
|
||||
pub fn for_target(target: Target) -> Self {
|
||||
let triple = target.triple();
|
||||
let pointer_width: PointerWidth = triple.pointer_width().unwrap();
|
||||
let (mut static_memory_bound, mut static_memory_offset_guard_size): (Pages, u64) =
|
||||
match pointer_width {
|
||||
@@ -54,11 +58,17 @@ impl Tunables {
|
||||
static_memory_bound,
|
||||
static_memory_offset_guard_size,
|
||||
dynamic_memory_offset_guard_size,
|
||||
target,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BaseTunables for Tunables {
|
||||
/// Get the target for this Tunables
|
||||
fn target(&self) -> &Target {
|
||||
&self.target
|
||||
}
|
||||
|
||||
/// Get a `MemoryPlan` for the provided `MemoryType`
|
||||
fn memory_plan(&self, memory: MemoryType) -> MemoryPlan {
|
||||
// A heap with a maximum that doesn't exceed the static memory bound specified by the
|
||||
@@ -105,6 +115,6 @@ impl BaseTunables for Tunables {
|
||||
|
||||
impl Default for Tunables {
|
||||
fn default() -> Self {
|
||||
Self::for_target(&HOST)
|
||||
Self::for_target(Target::default())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,25 +33,17 @@ use wasmer_compiler::{
|
||||
/// A compiler that compiles a WebAssembly module with Cranelift, translating the Wasm to Cranelift IR,
|
||||
/// optimizing it and then translating to assembly.
|
||||
pub struct CraneliftCompiler {
|
||||
isa: Box<dyn isa::TargetIsa>,
|
||||
config: CraneliftConfig,
|
||||
}
|
||||
|
||||
impl CraneliftCompiler {
|
||||
/// Creates a new Cranelift compiler
|
||||
pub fn new(config: &CraneliftConfig) -> Self {
|
||||
let isa = config.isa();
|
||||
Self {
|
||||
isa,
|
||||
config: config.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves the starget ISA
|
||||
fn isa(&self) -> &dyn isa::TargetIsa {
|
||||
&*self.isa
|
||||
}
|
||||
|
||||
/// Gets the WebAssembly features for this Compiler
|
||||
pub fn config(&self) -> &CraneliftConfig {
|
||||
&self.config
|
||||
@@ -59,20 +51,16 @@ impl CraneliftCompiler {
|
||||
}
|
||||
|
||||
impl Compiler for CraneliftCompiler {
|
||||
/// Gets the target associated to the Cranelift ISA.
|
||||
fn target(&self) -> &Target {
|
||||
self.config.target()
|
||||
}
|
||||
|
||||
/// Compile the module using Cranelift, producing a compilation result with
|
||||
/// associated relocations.
|
||||
fn compile_module(
|
||||
&self,
|
||||
target: &Target,
|
||||
compile_info: &CompileModuleInfo,
|
||||
module_translation: &ModuleTranslationState,
|
||||
function_body_inputs: PrimaryMap<LocalFunctionIndex, FunctionBodyData<'_>>,
|
||||
) -> Result<Compilation, CompileError> {
|
||||
let isa = self.isa();
|
||||
let isa = self.config().isa(target);
|
||||
let frontend_config = isa.frontend_config();
|
||||
let memory_plans = &compile_info.memory_plans;
|
||||
let table_plans = &compile_info.table_plans;
|
||||
@@ -87,7 +75,7 @@ impl Compiler for CraneliftCompiler {
|
||||
#[cfg(feature = "unwind")]
|
||||
let dwarf_frametable = {
|
||||
use std::sync::{Arc, Mutex};
|
||||
match self.target().triple().default_calling_convention() {
|
||||
match target.triple().default_calling_convention() {
|
||||
Ok(CallingConvention::SystemV) => {
|
||||
match isa.create_systemv_cie() {
|
||||
Some(cie) => {
|
||||
@@ -139,17 +127,17 @@ impl Compiler for CraneliftCompiler {
|
||||
let mut stackmap_sink = binemit::NullStackmapSink {};
|
||||
context
|
||||
.compile_and_emit(
|
||||
isa,
|
||||
&*isa,
|
||||
&mut code_buf,
|
||||
&mut reloc_sink,
|
||||
&mut trap_sink,
|
||||
&mut stackmap_sink,
|
||||
)
|
||||
.map_err(|error| {
|
||||
CompileError::Codegen(pretty_error(&context.func, Some(isa), error))
|
||||
CompileError::Codegen(pretty_error(&context.func, Some(&*isa), error))
|
||||
})?;
|
||||
|
||||
let unwind_info = match compiled_function_unwind_info(isa, &context)? {
|
||||
let unwind_info = match compiled_function_unwind_info(&*isa, &context)? {
|
||||
#[cfg(feature = "unwind")]
|
||||
CraneliftUnwindInfo::FDE(fde) => {
|
||||
if let Some((dwarf_frametable, cie_id)) = &dwarf_frametable {
|
||||
@@ -176,7 +164,7 @@ impl Compiler for CraneliftCompiler {
|
||||
other => other.maybe_into_to_windows_unwind(),
|
||||
};
|
||||
|
||||
let address_map = get_function_address_map(&context, input, code_buf.len(), isa);
|
||||
let address_map = get_function_address_map(&context, input, code_buf.len(), &*isa);
|
||||
|
||||
// We transform the Cranelift JumpTable's into compiler JumpTables
|
||||
let func_jt_offsets = transform_jump_table(context.func.jt_offsets);
|
||||
@@ -202,9 +190,7 @@ impl Compiler for CraneliftCompiler {
|
||||
let (custom_sections, dwarf) = {
|
||||
let mut custom_sections = PrimaryMap::new();
|
||||
let dwarf = if let Some((dwarf_frametable, _cie_id)) = dwarf_frametable {
|
||||
let mut eh_frame = EhFrame(WriterRelocate::new(
|
||||
self.target().triple().endianness().ok(),
|
||||
));
|
||||
let mut eh_frame = EhFrame(WriterRelocate::new(target.triple().endianness().ok()));
|
||||
dwarf_frametable
|
||||
.lock()
|
||||
.unwrap()
|
||||
@@ -229,7 +215,7 @@ impl Compiler for CraneliftCompiler {
|
||||
.collect::<Vec<_>>()
|
||||
.par_iter()
|
||||
.map_init(FunctionBuilderContext::new, |mut cx, sig| {
|
||||
make_trampoline_function_call(&*self.isa, &mut cx, sig)
|
||||
make_trampoline_function_call(&*isa, &mut cx, sig)
|
||||
})
|
||||
.collect::<Result<Vec<FunctionBody>, CompileError>>()?
|
||||
.into_iter()
|
||||
@@ -243,7 +229,7 @@ impl Compiler for CraneliftCompiler {
|
||||
.collect::<Vec<_>>()
|
||||
.par_iter()
|
||||
.map_init(FunctionBuilderContext::new, |mut cx, func_type| {
|
||||
make_trampoline_dynamic_function(&*self.isa, &offsets, &mut cx, &func_type)
|
||||
make_trampoline_dynamic_function(&*isa, &offsets, &mut cx, &func_type)
|
||||
})
|
||||
.collect::<Result<Vec<_>, CompileError>>()?
|
||||
.into_iter()
|
||||
|
||||
@@ -49,8 +49,6 @@ pub struct CraneliftConfig {
|
||||
/// The optimization levels when optimizing the IR.
|
||||
pub opt_level: OptLevel,
|
||||
|
||||
target: Target,
|
||||
|
||||
/// The middleware chain.
|
||||
pub(crate) middlewares: Vec<Arc<dyn FunctionMiddlewareGenerator>>,
|
||||
}
|
||||
@@ -58,21 +56,19 @@ pub struct CraneliftConfig {
|
||||
impl CraneliftConfig {
|
||||
/// Creates a new configuration object with the default configuration
|
||||
/// specified.
|
||||
pub fn new(target: Target) -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
enable_nan_canonicalization: false,
|
||||
enable_verifier: false,
|
||||
opt_level: OptLevel::Speed,
|
||||
enable_pic: false,
|
||||
enable_simd: false,
|
||||
target,
|
||||
middlewares: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates the ISA for the current target
|
||||
pub fn isa(&self) -> Box<dyn TargetIsa> {
|
||||
let target = self.target();
|
||||
/// Generates the ISA for the provided target
|
||||
pub fn isa(&self, target: &Target) -> Box<dyn TargetIsa> {
|
||||
let mut builder =
|
||||
lookup(target.triple().clone()).expect("construct Cranelift ISA for triple");
|
||||
// Cpu Features
|
||||
@@ -126,7 +122,7 @@ impl CraneliftConfig {
|
||||
builder.finish(self.flags())
|
||||
}
|
||||
|
||||
/// Generates the flags for the current target
|
||||
/// Generates the flags for the compiler
|
||||
pub fn flags(&self) -> settings::Flags {
|
||||
let mut flags = settings::builder();
|
||||
|
||||
@@ -187,12 +183,6 @@ impl CompilerConfig for CraneliftConfig {
|
||||
self.enable_pic = true;
|
||||
}
|
||||
|
||||
/// Gets the target that we will use for compiling
|
||||
/// the WebAssembly module
|
||||
fn target(&self) -> &Target {
|
||||
&self.target
|
||||
}
|
||||
|
||||
/// Transform it into the compiler
|
||||
fn compiler(&self) -> Box<dyn Compiler + Send> {
|
||||
Box::new(CraneliftCompiler::new(&self))
|
||||
@@ -206,6 +196,6 @@ impl CompilerConfig for CraneliftConfig {
|
||||
|
||||
impl Default for CraneliftConfig {
|
||||
fn default() -> Self {
|
||||
Self::new(Default::default())
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
|
||||
use wasm_common::LocalFunctionIndex;
|
||||
use wasmer_compiler::{
|
||||
Compilation, CompileError, CompileModuleInfo, Compiler, CompilerConfig, FunctionBodyData,
|
||||
Compilation, CompileError, CompileModuleInfo, Compiler, FunctionBodyData,
|
||||
ModuleTranslationState, RelocationTarget, SectionIndex, Target,
|
||||
};
|
||||
|
||||
@@ -32,15 +32,11 @@ impl LLVMCompiler {
|
||||
}
|
||||
|
||||
impl Compiler for LLVMCompiler {
|
||||
/// Gets the target associated to this Compiler.
|
||||
fn target(&self) -> &Target {
|
||||
self.config.target()
|
||||
}
|
||||
|
||||
/// Compile the module using LLVM, producing a compilation result with
|
||||
/// associated relocations.
|
||||
fn compile_module<'data, 'module>(
|
||||
&self,
|
||||
target: &Target,
|
||||
compile_info: &'module CompileModuleInfo,
|
||||
module_translation: &ModuleTranslationState,
|
||||
function_body_inputs: PrimaryMap<LocalFunctionIndex, FunctionBodyData<'data>>,
|
||||
@@ -65,20 +61,26 @@ impl Compiler for LLVMCompiler {
|
||||
.into_iter()
|
||||
.collect::<Vec<(LocalFunctionIndex, &FunctionBodyData<'_>)>>()
|
||||
.par_iter()
|
||||
.map_init(FuncTranslator::new, |func_translator, (i, input)| {
|
||||
// TODO: remove (to serialize)
|
||||
//let mut data = data.lock().unwrap();
|
||||
func_translator.translate(
|
||||
&module,
|
||||
module_translation,
|
||||
i,
|
||||
input,
|
||||
self.config(),
|
||||
&memory_plans,
|
||||
&table_plans,
|
||||
&func_names,
|
||||
)
|
||||
})
|
||||
.map_init(
|
||||
|| {
|
||||
let target_machine = self.config().target_machine(target);
|
||||
FuncTranslator::new(target_machine)
|
||||
},
|
||||
|func_translator, (i, input)| {
|
||||
// TODO: remove (to serialize)
|
||||
//let mut data = data.lock().unwrap();
|
||||
func_translator.translate(
|
||||
&module,
|
||||
module_translation,
|
||||
i,
|
||||
input,
|
||||
self.config(),
|
||||
&memory_plans,
|
||||
&table_plans,
|
||||
&func_names,
|
||||
)
|
||||
},
|
||||
)
|
||||
.collect::<Result<Vec<_>, CompileError>>()?
|
||||
.into_iter()
|
||||
.map(|(mut compiled_function, function_custom_sections)| {
|
||||
@@ -111,9 +113,13 @@ impl Compiler for LLVMCompiler {
|
||||
.values()
|
||||
.collect::<Vec<_>>()
|
||||
.par_iter()
|
||||
.map_init(FuncTrampoline::new, |func_trampoline, sig| {
|
||||
func_trampoline.trampoline(sig, self.config())
|
||||
})
|
||||
.map_init(
|
||||
|| {
|
||||
let target_machine = self.config().target_machine(target);
|
||||
FuncTrampoline::new(target_machine)
|
||||
},
|
||||
|func_trampoline, sig| func_trampoline.trampoline(sig, self.config()),
|
||||
)
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.collect::<Result<PrimaryMap<_, _>, CompileError>>()?;
|
||||
@@ -122,9 +128,15 @@ impl Compiler for LLVMCompiler {
|
||||
.imported_function_types()
|
||||
.collect::<Vec<_>>()
|
||||
.par_iter()
|
||||
.map_init(FuncTrampoline::new, |func_trampoline, func_type| {
|
||||
func_trampoline.dynamic_trampoline(&func_type, self.config())
|
||||
})
|
||||
.map_init(
|
||||
|| {
|
||||
let target_machine = self.config().target_machine(target);
|
||||
FuncTrampoline::new(target_machine)
|
||||
},
|
||||
|func_trampoline, func_type| {
|
||||
func_trampoline.dynamic_trampoline(&func_type, self.config())
|
||||
},
|
||||
)
|
||||
.collect::<Result<Vec<_>, CompileError>>()?
|
||||
.into_iter()
|
||||
.collect::<PrimaryMap<_, _>>();
|
||||
|
||||
@@ -63,20 +63,17 @@ pub struct LLVMConfig {
|
||||
|
||||
/// The middleware chain.
|
||||
pub(crate) middlewares: Vec<Arc<dyn FunctionMiddlewareGenerator>>,
|
||||
|
||||
target: Target,
|
||||
}
|
||||
|
||||
impl LLVMConfig {
|
||||
/// Creates a new configuration object with the default configuration
|
||||
/// specified.
|
||||
pub fn new(target: Target) -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
enable_nan_canonicalization: true,
|
||||
enable_verifier: false,
|
||||
opt_level: OptimizationLevel::Aggressive,
|
||||
is_pic: false,
|
||||
target,
|
||||
callbacks: None,
|
||||
middlewares: vec![],
|
||||
}
|
||||
@@ -94,8 +91,7 @@ impl LLVMConfig {
|
||||
CodeModel::Large
|
||||
}
|
||||
|
||||
pub fn target_triple(&self) -> TargetTriple {
|
||||
let target = self.target();
|
||||
fn target_triple(&self, target: &Target) -> TargetTriple {
|
||||
let operating_system =
|
||||
if target.triple().operating_system == wasmer_compiler::OperatingSystem::Darwin {
|
||||
// LLVM detects static relocation + darwin + 64-bit and
|
||||
@@ -119,8 +115,7 @@ impl LLVMConfig {
|
||||
}
|
||||
|
||||
/// Generates the target machine for the current target
|
||||
pub fn target_machine(&self) -> TargetMachine {
|
||||
let target = self.target();
|
||||
pub fn target_machine(&self, target: &Target) -> TargetMachine {
|
||||
let triple = target.triple();
|
||||
let cpu_features = &target.cpu_features();
|
||||
|
||||
@@ -152,7 +147,7 @@ impl LLVMConfig {
|
||||
.map(|feature| format!("+{}", feature.to_string()))
|
||||
.join(",");
|
||||
|
||||
let target_triple = self.target_triple();
|
||||
let target_triple = self.target_triple(&target);
|
||||
let llvm_target = InkwellTarget::from_triple(&target_triple).unwrap();
|
||||
llvm_target
|
||||
.create_target_machine(
|
||||
@@ -175,12 +170,6 @@ impl CompilerConfig for LLVMConfig {
|
||||
self.is_pic = true;
|
||||
}
|
||||
|
||||
/// Gets the target that we will use for compiling.
|
||||
/// the WebAssembly module
|
||||
fn target(&self) -> &Target {
|
||||
&self.target
|
||||
}
|
||||
|
||||
/// Transform it into the compiler.
|
||||
fn compiler(&self) -> Box<dyn Compiler + Send> {
|
||||
Box::new(LLVMCompiler::new(&self))
|
||||
@@ -194,6 +183,6 @@ impl CompilerConfig for LLVMConfig {
|
||||
|
||||
impl Default for LLVMConfig {
|
||||
fn default() -> LLVMConfig {
|
||||
Self::new(Default::default())
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use inkwell::{
|
||||
context::Context,
|
||||
module::Linkage,
|
||||
passes::PassManager,
|
||||
targets::FileType,
|
||||
targets::{FileType, TargetMachine},
|
||||
types::BasicType,
|
||||
values::{BasicValue, FunctionValue},
|
||||
AddressSpace,
|
||||
@@ -22,14 +22,16 @@ use wasmer_compiler::{CompileError, FunctionBody};
|
||||
|
||||
pub struct FuncTrampoline {
|
||||
ctx: Context,
|
||||
target_machine: TargetMachine,
|
||||
}
|
||||
|
||||
const FUNCTION_SECTION: &str = ".wasmer_trampoline";
|
||||
|
||||
impl FuncTrampoline {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(target_machine: TargetMachine) -> Self {
|
||||
Self {
|
||||
ctx: Context::create(),
|
||||
target_machine,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +43,8 @@ impl FuncTrampoline {
|
||||
// The function type, used for the callbacks.
|
||||
let function = CompiledFunctionKind::FunctionCallTrampoline(ty.clone());
|
||||
let module = self.ctx.create_module("");
|
||||
let target_triple = config.target_triple();
|
||||
let target_machine = config.target_machine();
|
||||
let target_machine = &self.target_machine;
|
||||
let target_triple = target_machine.get_triple();
|
||||
module.set_triple(&target_triple);
|
||||
module.set_data_layout(&target_machine.get_target_data().get_data_layout());
|
||||
let intrinsics = Intrinsics::declare(&module, &self.ctx);
|
||||
@@ -130,8 +132,8 @@ impl FuncTrampoline {
|
||||
// The function type, used for the callbacks
|
||||
let function = CompiledFunctionKind::DynamicFunctionTrampoline(ty.clone());
|
||||
let module = self.ctx.create_module("");
|
||||
let target_triple = config.target_triple();
|
||||
let target_machine = config.target_machine();
|
||||
let target_machine = &self.target_machine;
|
||||
let target_triple = target_machine.get_triple();
|
||||
module.set_triple(&target_triple);
|
||||
module.set_data_layout(&target_machine.get_target_data().get_data_layout());
|
||||
let intrinsics = Intrinsics::declare(&module, &self.ctx);
|
||||
|
||||
@@ -12,7 +12,7 @@ use inkwell::{
|
||||
context::Context,
|
||||
module::{Linkage, Module},
|
||||
passes::PassManager,
|
||||
targets::FileType,
|
||||
targets::{FileType, TargetMachine},
|
||||
types::{BasicType, BasicTypeEnum, FloatMathType, IntType, PointerType, VectorType},
|
||||
values::{
|
||||
BasicValue, BasicValueEnum, FloatValue, FunctionValue, InstructionOpcode, InstructionValue,
|
||||
@@ -55,12 +55,14 @@ fn const_zero(ty: BasicTypeEnum) -> BasicValueEnum {
|
||||
|
||||
pub struct FuncTranslator {
|
||||
ctx: Context,
|
||||
target_machine: TargetMachine,
|
||||
}
|
||||
|
||||
impl FuncTranslator {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(target_machine: TargetMachine) -> Self {
|
||||
Self {
|
||||
ctx: Context::create(),
|
||||
target_machine,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,8 +87,8 @@ impl FuncTranslator {
|
||||
};
|
||||
let module = self.ctx.create_module(module_name.as_str());
|
||||
|
||||
let target_triple = config.target_triple();
|
||||
let target_machine = config.target_machine();
|
||||
let target_machine = &self.target_machine;
|
||||
let target_triple = target_machine.get_triple();
|
||||
module.set_triple(&target_triple);
|
||||
module.set_data_layout(&target_machine.get_target_data().get_data_layout());
|
||||
let wasm_fn_type = wasm_module
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
|
||||
use crate::compiler::SinglepassCompiler;
|
||||
use std::sync::Arc;
|
||||
use wasmer_compiler::{
|
||||
Compiler, CompilerConfig, CpuFeature, FunctionMiddlewareGenerator, Target,
|
||||
};
|
||||
use wasmer_compiler::{Compiler, CompilerConfig, CpuFeature, FunctionMiddlewareGenerator, Target};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SinglepassConfig {
|
||||
|
||||
@@ -17,9 +17,6 @@ use wasmer_runtime::{MemoryPlan, TablePlan};
|
||||
use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig};
|
||||
|
||||
/// The compiler configuration options.
|
||||
///
|
||||
/// This options must have WebAssembly `Features` and a specific
|
||||
/// `Target` to compile to.
|
||||
pub trait CompilerConfig {
|
||||
/// Should Position Independent Code (PIC) be enabled.
|
||||
///
|
||||
@@ -28,10 +25,6 @@ pub trait CompilerConfig {
|
||||
/// supported in the JIT linking phase.
|
||||
fn enable_pic(&mut self);
|
||||
|
||||
/// Gets the target that we will use for compiling
|
||||
/// the WebAssembly module
|
||||
fn target(&self) -> &Target;
|
||||
|
||||
/// Gets the custom compiler config
|
||||
fn compiler(&self) -> Box<dyn Compiler + Send>;
|
||||
|
||||
@@ -41,9 +34,6 @@ pub trait CompilerConfig {
|
||||
|
||||
/// An implementation of a Compiler from parsed WebAssembly module to Compiled native code.
|
||||
pub trait Compiler {
|
||||
/// Gets the target associated with this compiler
|
||||
fn target(&self) -> &Target;
|
||||
|
||||
/// Validates a module.
|
||||
///
|
||||
/// It returns the a succesful Result in case is valid, `CompileError` in case is not.
|
||||
@@ -70,6 +60,7 @@ pub trait Compiler {
|
||||
/// It returns the [`Compilation`] or a [`CompileError`].
|
||||
fn compile_module<'data, 'module>(
|
||||
&self,
|
||||
target: &Target,
|
||||
module: &'module CompileModuleInfo,
|
||||
module_translation: &ModuleTranslationState,
|
||||
// The list of function bodies
|
||||
|
||||
@@ -75,6 +75,7 @@ impl JITArtifact {
|
||||
|
||||
// Compile the Module
|
||||
let compilation = compiler.compile_module(
|
||||
&tunables.target(),
|
||||
&compile_info,
|
||||
translation.module_translation.as_ref().unwrap(),
|
||||
translation.function_body_inputs,
|
||||
|
||||
@@ -123,8 +123,11 @@ impl NativeArtifact {
|
||||
};
|
||||
|
||||
let compiler = engine_inner.compiler()?;
|
||||
let target = tunables.target();
|
||||
|
||||
// Compile the Module
|
||||
let compilation = compiler.compile_module(
|
||||
&target,
|
||||
&compile_info,
|
||||
translation.module_translation.as_ref().unwrap(),
|
||||
translation.function_body_inputs,
|
||||
@@ -139,7 +142,6 @@ impl NativeArtifact {
|
||||
.collect::<Vec<_>>()
|
||||
.into_boxed_slice();
|
||||
|
||||
let target = compiler.target();
|
||||
let target_triple = target.triple().clone();
|
||||
|
||||
let obj_binary_format = match target_triple.binary_format {
|
||||
|
||||
@@ -5,16 +5,20 @@ use wasm_common::{
|
||||
LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryIndex, MemoryType, TableIndex,
|
||||
TableType,
|
||||
};
|
||||
use wasmer_compiler::Target;
|
||||
use wasmer_runtime::MemoryError;
|
||||
use wasmer_runtime::{Memory, ModuleInfo, Table, VMGlobalDefinition};
|
||||
use wasmer_runtime::{MemoryPlan, TablePlan};
|
||||
|
||||
/// Tunables for an engine
|
||||
pub trait Tunables {
|
||||
/// Get a `MemoryPlan` for the provided `MemoryType`
|
||||
/// Get the target for this Tunables
|
||||
fn target(&self) -> &Target;
|
||||
|
||||
/// Construct a `MemoryPlan` for the provided `MemoryType`
|
||||
fn memory_plan(&self, memory: MemoryType) -> MemoryPlan;
|
||||
|
||||
/// Get a `TablePlan` for the provided `TableType`
|
||||
/// Construct a `TablePlan` for the provided `TableType`
|
||||
fn table_plan(&self, table: TableType) -> TablePlan;
|
||||
|
||||
/// Create a memory given a memory type
|
||||
|
||||
20
src/store.rs
20
src/store.rs
@@ -174,21 +174,18 @@ impl StoreOptions {
|
||||
|
||||
/// Get the Compiler Config for the current options
|
||||
#[allow(unused_variables)]
|
||||
fn get_compiler_config(
|
||||
&self,
|
||||
target: Target,
|
||||
) -> Result<(Box<dyn CompilerConfig>, CompilerType)> {
|
||||
fn get_compiler_config(&self) -> Result<(Box<dyn CompilerConfig>, CompilerType)> {
|
||||
let compiler = self.get_compiler()?;
|
||||
let compiler_config: Box<dyn CompilerConfig> = match compiler {
|
||||
CompilerType::Headless => bail!("The headless engine can't be chosen"),
|
||||
#[cfg(feature = "singlepass")]
|
||||
CompilerType::Singlepass => {
|
||||
let config = wasmer_compiler_singlepass::SinglepassConfig::new(target);
|
||||
let config = wasmer_compiler_singlepass::SinglepassConfig::new();
|
||||
Box::new(config)
|
||||
}
|
||||
#[cfg(feature = "cranelift")]
|
||||
CompilerType::Cranelift => {
|
||||
let config = wasmer_compiler_cranelift::CraneliftConfig::new(target);
|
||||
let config = wasmer_compiler_cranelift::CraneliftConfig::new();
|
||||
Box::new(config)
|
||||
}
|
||||
#[cfg(feature = "llvm")]
|
||||
@@ -200,7 +197,7 @@ impl StoreOptions {
|
||||
CompiledFunctionKind, InkwellMemoryBuffer, InkwellModule, LLVMCallbacks,
|
||||
LLVMConfig,
|
||||
};
|
||||
let mut config = LLVMConfig::new(target);
|
||||
let mut config = LLVMConfig::new();
|
||||
struct Callbacks {
|
||||
debug_dir: PathBuf,
|
||||
}
|
||||
@@ -290,11 +287,6 @@ impl StoreOptions {
|
||||
Ok((compiler_config, compiler))
|
||||
}
|
||||
|
||||
/// Gets the tunables for the compiler target
|
||||
pub fn get_tunables(&self, compiler_config: &dyn CompilerConfig) -> Tunables {
|
||||
Tunables::for_target(compiler_config.target().triple())
|
||||
}
|
||||
|
||||
/// Gets the store for the host target, with the engine name and compiler name selected
|
||||
pub fn get_store(&self) -> Result<(Store, EngineType, CompilerType)> {
|
||||
let target = Target::default();
|
||||
@@ -306,8 +298,8 @@ impl StoreOptions {
|
||||
&self,
|
||||
target: Target,
|
||||
) -> Result<(Store, EngineType, CompilerType)> {
|
||||
let (compiler_config, compiler_type) = self.get_compiler_config(target)?;
|
||||
let tunables = self.get_tunables(&*compiler_config);
|
||||
let (compiler_config, compiler_type) = self.get_compiler_config()?;
|
||||
let tunables = Tunables::for_target(target);
|
||||
let (engine, engine_type) = self.get_engine_with_compiler(tunables, compiler_config)?;
|
||||
let store = Store::new(engine);
|
||||
Ok((store, engine_type, compiler_type))
|
||||
|
||||
@@ -27,7 +27,7 @@ pub fn get_store() -> Store {
|
||||
let try_nan_canonicalization = false;
|
||||
let compiler_config =
|
||||
get_compiler_config_from_str(get_compiler_str(), try_nan_canonicalization);
|
||||
let tunables = Tunables::for_target(compiler_config.target().triple());
|
||||
let tunables = Tunables::default();
|
||||
let store = Store::new(Arc::new(JITEngine::new(
|
||||
compiler_config,
|
||||
tunables,
|
||||
@@ -46,7 +46,7 @@ pub fn get_store_with_middlewares<I: Iterator<Item = Arc<dyn FunctionMiddlewareG
|
||||
for x in middlewares {
|
||||
compiler_config.push_middleware(x);
|
||||
}
|
||||
let tunables = Tunables::for_target(compiler_config.target().triple());
|
||||
let tunables = Tunables::default();
|
||||
let store = Store::new(Arc::new(JITEngine::new(
|
||||
compiler_config,
|
||||
tunables,
|
||||
@@ -56,7 +56,7 @@ pub fn get_store_with_middlewares<I: Iterator<Item = Arc<dyn FunctionMiddlewareG
|
||||
}
|
||||
|
||||
pub fn get_headless_store() -> Store {
|
||||
let tunables = Tunables::for_target(&Triple::host());
|
||||
let tunables = Tunables::default();
|
||||
let store = Store::new(Arc::new(JITEngine::headless(tunables)));
|
||||
store
|
||||
}
|
||||
|
||||
@@ -9,26 +9,23 @@ pub fn get_compiler_config_from_str(
|
||||
compiler_name: &str,
|
||||
try_nan_canonicalization: bool,
|
||||
) -> Box<dyn CompilerConfig> {
|
||||
// We use the current host target for testing locally
|
||||
let target = Target::default();
|
||||
|
||||
match compiler_name {
|
||||
#[cfg(feature = "singlepass")]
|
||||
"singlepass" => {
|
||||
// Singlepass.canonicalize_nans(true).compiler()
|
||||
let mut singlepass_config = wasmer_compiler_singlepass::SinglepassConfig::new(target);
|
||||
let mut singlepass_config = wasmer_compiler_singlepass::SinglepassConfig::new();
|
||||
singlepass_config.enable_nan_canonicalization = try_nan_canonicalization;
|
||||
Box::new(singlepass_config)
|
||||
}
|
||||
#[cfg(feature = "cranelift")]
|
||||
"cranelift" => {
|
||||
let mut cranelift_config = wasmer_compiler_cranelift::CraneliftConfig::new(target);
|
||||
let mut cranelift_config = wasmer_compiler_cranelift::CraneliftConfig::new();
|
||||
cranelift_config.enable_nan_canonicalization = try_nan_canonicalization;
|
||||
Box::new(cranelift_config)
|
||||
}
|
||||
#[cfg(feature = "llvm")]
|
||||
"llvm" => {
|
||||
let mut llvm_config = wasmer_compiler_llvm::LLVMConfig::new(target);
|
||||
let mut llvm_config = wasmer_compiler_llvm::LLVMConfig::new();
|
||||
llvm_config.enable_nan_canonicalization = try_nan_canonicalization;
|
||||
Box::new(llvm_config)
|
||||
}
|
||||
@@ -38,8 +35,9 @@ pub fn get_compiler_config_from_str(
|
||||
|
||||
/// for when you need a store but you don't care about the details
|
||||
pub fn get_default_store() -> Store {
|
||||
let target = Target::default();
|
||||
let compiler_config = get_compiler_config_from_str("cranelift", false);
|
||||
let tunables = Tunables::for_target(compiler_config.target().triple());
|
||||
let tunables = Tunables::for_target(target);
|
||||
Store::new(Arc::new(JITEngine::new(
|
||||
compiler_config,
|
||||
tunables,
|
||||
@@ -49,8 +47,9 @@ pub fn get_default_store() -> Store {
|
||||
|
||||
#[cfg(feature = "llvm")]
|
||||
pub fn get_default_llvm_store() -> Store {
|
||||
let target = Target::default();
|
||||
let compiler_config = get_compiler_config_from_str("llvm", false);
|
||||
let tunables = Tunables::for_target(compiler_config.target().triple());
|
||||
let tunables = Tunables::for_target(target);
|
||||
Store::new(Arc::new(JITEngine::new(
|
||||
compiler_config,
|
||||
tunables,
|
||||
@@ -60,8 +59,9 @@ pub fn get_default_llvm_store() -> Store {
|
||||
|
||||
#[cfg(feature = "cranelift")]
|
||||
pub fn get_default_cranelift_store() -> Store {
|
||||
let target = Target::default();
|
||||
let compiler_config = get_compiler_config_from_str("cranelift", false);
|
||||
let tunables = Tunables::for_target(compiler_config.target().triple());
|
||||
let tunables = Tunables::for_target(target);
|
||||
Store::new(Arc::new(JITEngine::new(
|
||||
compiler_config,
|
||||
tunables,
|
||||
@@ -71,8 +71,9 @@ pub fn get_default_cranelift_store() -> Store {
|
||||
|
||||
#[cfg(feature = "singlepass")]
|
||||
pub fn get_default_singlepass_store() -> Store {
|
||||
let target = Target::default();
|
||||
let compiler_config = get_compiler_config_from_str("singlepass", false);
|
||||
let tunables = Tunables::for_target(compiler_config.target().triple());
|
||||
let tunables = Tunables::for_target(target);
|
||||
Store::new(Arc::new(JITEngine::new(
|
||||
compiler_config,
|
||||
tunables,
|
||||
|
||||
@@ -40,7 +40,7 @@ fn run_wast(wast_path: &str, compiler: &str) -> anyhow::Result<()> {
|
||||
features.bulk_memory(true);
|
||||
}
|
||||
let compiler_config = get_compiler_config_from_str(compiler, try_nan_canonicalization);
|
||||
let tunables = Tunables::for_target(compiler_config.target().triple());
|
||||
let tunables = Tunables::default();
|
||||
let store = Store::new(Arc::new(JITEngine::new(
|
||||
compiler_config,
|
||||
tunables,
|
||||
|
||||
Reference in New Issue
Block a user