Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1143: Set backend_id to static str r=MarkMcCaskey a=syrusakbary

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description

As per feedback in wasmerio#1099, set backend_id to static str.

<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [ ] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Syrus <[email protected]>
Co-authored-by: Mark McCaskey <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2020
2 parents 606ed7a + 75d7f10 commit 12f1f2d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
6 changes: 4 additions & 2 deletions lib/clif-backend/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use wasmer_runtime_core::{
};
use wasmparser::Type as WpType;

static BACKEND_ID: &str = "cranelift";

pub struct CraneliftModuleCodeGenerator {
isa: Box<dyn isa::TargetIsa>,
signatures: Option<Arc<Map<SigIndex, FuncSig>>>,
Expand All @@ -58,8 +60,8 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
unimplemented!("cross compilation is not available for clif backend")
}

fn backend_id() -> String {
"cranelift".to_string()
fn backend_id() -> &'static str {
BACKEND_ID
}

fn check_precondition(&mut self, _module_info: &ModuleInfo) -> Result<(), CodegenError> {
Expand Down
6 changes: 4 additions & 2 deletions lib/llvm-backend/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ use wasmer_runtime_core::{
};
use wasmparser::{BinaryReaderError, MemoryImmediate, Operator, Type as WpType};

static BACKEND_ID: &str = "llvm";

fn func_sig_to_llvm<'ctx>(
context: &'ctx Context,
intrinsics: &Intrinsics<'ctx>,
Expand Down Expand Up @@ -8721,8 +8723,8 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
}
}

fn backend_id() -> String {
"llvm".to_string()
fn backend_id() -> &'static str {
BACKEND_ID
}

fn check_precondition(&mut self, _module_info: &ModuleInfo) -> Result<(), CodegenError> {
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime-core/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator<E>, RM: RunnableModule,
) -> Self;

/// Returns the backend id associated with this MCG.
fn backend_id() -> String;
fn backend_id() -> &'static str;

/// It sets if the current compiler requires validation before compilation
fn requires_pre_validation() -> bool {
Expand Down Expand Up @@ -231,7 +231,7 @@ impl<
validate_with_features(wasm, &compiler_config.features)?;
}

let mut mcg = match MCG::backend_id().as_ref() {
let mut mcg = match MCG::backend_id() {
"llvm" => MCG::new_with_target(
compiler_config.triple.clone(),
compiler_config.cpu_name.clone(),
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn read_module<

func_assoc: Map::new(),
signatures: Map::new(),
backend: MCG::backend_id(),
backend: MCG::backend_id().to_string(),

namespace_table: StringTable::new(),
name_table: StringTable::new(),
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub struct CodeVersion {
pub base: usize,

/// The backend used to compile this module.
pub backend: String,
pub backend: &'static str,

/// `RunnableModule` for this code version.
pub runnable_module: Arc<Box<dyn RunnableModule>>,
Expand Down
10 changes: 5 additions & 5 deletions lib/runtime-core/src/tiering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct OptimizationState {
}

struct OptimizationOutcome {
backend_id: String,
backend_id: &'static str,
module: Module,
}

Expand All @@ -54,7 +54,7 @@ unsafe impl Sync for CtxWrapper {}

unsafe fn do_optimize(
binary: &[u8],
backend_id: String,
backend_id: &'static str,
compiler: Box<dyn Compiler>,
ctx: &Mutex<CtxWrapper>,
state: &OptimizationState,
Expand Down Expand Up @@ -87,8 +87,8 @@ pub unsafe fn run_tiering<F: Fn(InteractiveShellContext) -> ShellExitOperation>(
import_object: &ImportObject,
start_raw: extern "C" fn(&mut Ctx),
baseline: &mut Instance,
baseline_backend: String,
optimized_backends: Vec<(String, Box<dyn Fn() -> Box<dyn Compiler> + Send>)>,
baseline_backend: &'static str,
optimized_backends: Vec<(&'static str, Box<dyn Fn() -> Box<dyn Compiler> + Send>)>,
interactive_shell: F,
) -> Result<(), String> {
ensure_sighandler();
Expand Down Expand Up @@ -140,7 +140,7 @@ pub unsafe fn run_tiering<F: Fn(InteractiveShellContext) -> ShellExitOperation>(
}));

loop {
let new_optimized: Option<(String, &mut Instance)> = {
let new_optimized: Option<(&'static str, &mut Instance)> = {
let mut outcome = opt_state.outcome.lock().unwrap();
if let Some(x) = outcome.take() {
let instance = x
Expand Down
6 changes: 4 additions & 2 deletions lib/singlepass-backend/src/codegen_x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub const INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS: usize = 7;
/// Inline breakpoint size for aarch64.
pub const INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS: usize = 12;

static BACKEND_ID: &str = "singlepass";

#[cfg(target_arch = "x86_64")]
lazy_static! {
/// Performs a System V call to `target` with [stack_top..stack_base] as the argument list, from right to left.
Expand Down Expand Up @@ -651,8 +653,8 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
false
}

fn backend_id() -> String {
"singlepass".to_string()
fn backend_id() -> &'static str {
BACKEND_ID
}

fn new_with_target(_: Option<String>, _: Option<String>, _: Option<String>) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,15 @@ fn execute_wasi(
&import_object,
start_raw,
&mut instance,
options.backend,
options.backend.to_string(),
options
.optimized_backends
.iter()
.map(
|&backend| -> (Backend, Box<dyn Fn() -> Box<dyn Compiler> + Send>) {
let options = options.clone();
(
backend,
backend.to_string(),
Box::new(move || {
get_compiler_by_backend(backend, &options).unwrap()
}),
Expand Down Expand Up @@ -492,7 +492,7 @@ fn execute_wasi(
baseline: true,
msm: msm,
base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize,
backend: options.backend.to_string().to_owned(),
backend: options.backend.to_string(),
runnable_module: instance.module.runnable_module.clone(),
});
true
Expand Down

0 comments on commit 12f1f2d

Please sign in to comment.