From 85bb1039f8d5f32c12f4b1a24baea8866ea6d3e2 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 7 Dec 2020 18:12:33 +0100 Subject: [PATCH 1/3] Expose wasmer::CraneliftOptLevel This is required to do something like ```rust use wasmer::{Cranelift, CraneliftOptLevel}; let mut compiler = Cranelift::default(); compiler.opt_level(CraneliftOptLevel::None); let engine = JIT::new(compiler).engine(); // ... ``` --- lib/api/src/lib.rs | 2 +- lib/compiler-cranelift/src/config.rs | 14 +++++++------- lib/compiler-cranelift/src/lib.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index eefb25bb937..beb2eb78820 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -355,7 +355,7 @@ let store = Store::new(&engine); pub use wasmer_compiler_singlepass::Singlepass; #[cfg(feature = "cranelift")] -pub use wasmer_compiler_cranelift::Cranelift; +pub use wasmer_compiler_cranelift::{Cranelift, CraneliftOptLevel}; #[cfg(feature = "llvm")] pub use wasmer_compiler_llvm::LLVM; diff --git a/lib/compiler-cranelift/src/config.rs b/lib/compiler-cranelift/src/config.rs index c4f8bdf65c7..efa4fa6c110 100644 --- a/lib/compiler-cranelift/src/config.rs +++ b/lib/compiler-cranelift/src/config.rs @@ -11,7 +11,7 @@ use wasmer_compiler::{ /// Possible optimization levels for the Cranelift codegen backend. #[non_exhaustive] #[derive(Clone, Debug)] -pub enum OptLevel { +pub enum CraneliftOptLevel { /// No optimizations performed, minimizes compilation time by disabling most /// optimizations. None, @@ -33,7 +33,7 @@ pub struct Cranelift { enable_verifier: bool, enable_simd: bool, enable_pic: bool, - opt_level: OptLevel, + opt_level: CraneliftOptLevel, /// The middleware chain. pub(crate) middlewares: Vec>, } @@ -45,7 +45,7 @@ impl Cranelift { Self { enable_nan_canonicalization: false, enable_verifier: false, - opt_level: OptLevel::Speed, + opt_level: CraneliftOptLevel::Speed, enable_pic: false, enable_simd: true, middlewares: vec![], @@ -68,7 +68,7 @@ impl Cranelift { } /// The optimization levels when optimizing the IR. - pub fn opt_level(&mut self, opt_level: OptLevel) -> &mut Self { + pub fn opt_level(&mut self, opt_level: CraneliftOptLevel) -> &mut Self { self.opt_level = opt_level; self } @@ -156,9 +156,9 @@ impl Cranelift { "none" } else { match self.opt_level { - OptLevel::None => "none", - OptLevel::Speed => "speed", - OptLevel::SpeedAndSize => "speed_and_size", + CraneliftOptLevel::None => "none", + CraneliftOptLevel::Speed => "speed", + CraneliftOptLevel::SpeedAndSize => "speed_and_size", } }; diff --git a/lib/compiler-cranelift/src/lib.rs b/lib/compiler-cranelift/src/lib.rs index 6f0df0afb10..b047edca507 100644 --- a/lib/compiler-cranelift/src/lib.rs +++ b/lib/compiler-cranelift/src/lib.rs @@ -56,7 +56,7 @@ mod trampoline; mod translator; pub use crate::compiler::CraneliftCompiler; -pub use crate::config::Cranelift; +pub use crate::config::{Cranelift, CraneliftOptLevel}; pub use crate::debug::{ModuleInfoMemoryOffset, ModuleInfoVmctxInfo, ValueLabelsRanges}; pub use crate::trampoline::make_trampoline_function_call; From 9d6fc4a4badc1a6092e227c4e900fd848a2d951d Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sun, 13 Dec 2020 10:11:02 +0100 Subject: [PATCH 2/3] Expose wasmer::LLVMOptLevel --- lib/api/src/lib.rs | 2 +- lib/compiler-llvm/src/config.rs | 8 ++++---- lib/compiler-llvm/src/lib.rs | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index beb2eb78820..8adef3b737f 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -358,7 +358,7 @@ pub use wasmer_compiler_singlepass::Singlepass; pub use wasmer_compiler_cranelift::{Cranelift, CraneliftOptLevel}; #[cfg(feature = "llvm")] -pub use wasmer_compiler_llvm::LLVM; +pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM}; #[cfg(feature = "jit")] pub use wasmer_engine_jit::{JITArtifact, JITEngine, JIT}; diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index 1d1d5224dec..6ae8085aaf1 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -3,7 +3,7 @@ use inkwell::targets::{ CodeModel, InitializationConfig, RelocMode, Target as InkwellTarget, TargetMachine, TargetTriple, }; -use inkwell::OptimizationLevel; +pub use inkwell::OptimizationLevel as LLVMOptLevel; use itertools::Itertools; use std::fmt::Debug; use std::sync::Arc; @@ -41,7 +41,7 @@ pub trait LLVMCallbacks: Debug + Send + Sync { pub struct LLVM { pub(crate) enable_nan_canonicalization: bool, pub(crate) enable_verifier: bool, - pub(crate) opt_level: OptimizationLevel, + pub(crate) opt_level: LLVMOptLevel, is_pic: bool, pub(crate) callbacks: Option>, /// The middleware chain. @@ -55,7 +55,7 @@ impl LLVM { Self { enable_nan_canonicalization: false, enable_verifier: false, - opt_level: OptimizationLevel::Aggressive, + opt_level: LLVMOptLevel::Aggressive, is_pic: false, callbacks: None, middlewares: vec![], @@ -72,7 +72,7 @@ impl LLVM { } /// The optimization levels when optimizing the IR. - pub fn opt_level(&mut self, opt_level: OptimizationLevel) -> &mut Self { + pub fn opt_level(&mut self, opt_level: LLVMOptLevel) -> &mut Self { self.opt_level = opt_level; self } diff --git a/lib/compiler-llvm/src/lib.rs b/lib/compiler-llvm/src/lib.rs index a640d360577..db2503e9c9b 100644 --- a/lib/compiler-llvm/src/lib.rs +++ b/lib/compiler-llvm/src/lib.rs @@ -22,4 +22,6 @@ mod trampoline; mod translator; pub use crate::compiler::LLVMCompiler; -pub use crate::config::{CompiledKind, InkwellMemoryBuffer, InkwellModule, LLVMCallbacks, LLVM}; +pub use crate::config::{ + CompiledKind, InkwellMemoryBuffer, InkwellModule, LLVMCallbacks, LLVMOptLevel, LLVM, +}; From 50f0339c5c591e44e662bdd391b79ef4c586f9d1 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sun, 13 Dec 2020 10:18:08 +0100 Subject: [PATCH 3/3] Add CHANGELOG entry --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f49eeed4cb..fda945847cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ ## **[Unreleased]** +### Added + +* [#1894](https://github.com/wasmerio/wasmer/pull/1894) Added exports `wasmer::{CraneliftOptLevel, LLVMOptLevel}` to allow using `Cranelift::opt_level` and `LLVM::opt_level` directly via the `wasmer` crate + +### Changed + +### Fixed + ## 1.0.0-beta2 - 2020-12-16 ### Added