Skip to content

Commit

Permalink
Set cranelift simd config based on Wasm Features
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Mar 31, 2021
1 parent 62a8d07 commit 1231cb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 5 additions & 3 deletions lib/compiler-cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ impl Compiler for CraneliftCompiler {
module_translation_state: &ModuleTranslationState,
function_body_inputs: PrimaryMap<LocalFunctionIndex, FunctionBodyData<'_>>,
) -> Result<Compilation, CompileError> {
let isa = self.config().isa(target);
let config = self.config();
let flags = self.config().flags(compile_info.features.simd);
let isa = config.isa(target, flags);
let frontend_config = isa.frontend_config();
let memory_styles = &compile_info.memory_styles;
let table_styles = &compile_info.table_styles;
let mut module = (*compile_info.module).clone();
self.config.middlewares.apply_on_module_info(&mut module);
config.middlewares.apply_on_module_info(&mut module);
compile_info.module = Arc::new(module);
let module = &compile_info.module;
let signatures = module
Expand Down Expand Up @@ -126,7 +128,7 @@ impl Compiler for CraneliftCompiler {
&mut context.func,
&mut func_env,
*i,
&self.config,
&config,
)?;

let mut code_buf: Vec<u8> = Vec::new();
Expand Down
10 changes: 4 additions & 6 deletions lib/compiler-cranelift/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub enum CraneliftOptLevel {
pub struct Cranelift {
enable_nan_canonicalization: bool,
enable_verifier: bool,
enable_simd: bool,
enable_pic: bool,
opt_level: CraneliftOptLevel,
/// The middleware chain.
Expand All @@ -48,7 +47,6 @@ impl Cranelift {
enable_verifier: false,
opt_level: CraneliftOptLevel::Speed,
enable_pic: false,
enable_simd: true,
middlewares: vec![],
}
}
Expand All @@ -69,7 +67,7 @@ impl Cranelift {
}

/// Generates the ISA for the provided target
pub fn isa(&self, target: &Target) -> Box<dyn TargetIsa> {
pub fn isa(&self, target: &Target, flags: settings::Flags) -> Box<dyn TargetIsa> {
let mut builder =
lookup(target.triple().clone()).expect("construct Cranelift ISA for triple");
// Cpu Features
Expand Down Expand Up @@ -120,11 +118,11 @@ impl Cranelift {
builder.enable("has_lzcnt").expect("should be valid flag");
}

builder.finish(self.flags())
builder.finish(flags)
}

/// Generates the flags for the compiler
pub fn flags(&self) -> settings::Flags {
pub fn flags(&self, enable_simd: bool) -> settings::Flags {
let mut flags = settings::builder();

// There are two possible traps for division, and this way
Expand Down Expand Up @@ -158,7 +156,7 @@ impl Cranelift {
)
.expect("should be valid flag");

let enable_simd = if self.enable_simd { "true" } else { "false" };
let enable_simd = if enable_simd { "true" } else { "false" };
flags
.set("enable_simd", enable_simd)
.expect("should be valid flag");
Expand Down

0 comments on commit 1231cb2

Please sign in to comment.