mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-04 11:01:32 +00:00
Add the ability to pass backend specific options through CompilerConfig.
Use this to replace wasmer_llvm_backend::GLOBAL_OPTIONS.
This commit is contained in:
@ -5,6 +5,7 @@ use crate::{
|
||||
stackmap::{StackmapEntry, StackmapEntryKind, StackmapRegistry, ValueSemantic},
|
||||
state::{ControlFrame, ExtraInfo, IfElseState, State},
|
||||
trampolines::generate_trampolines,
|
||||
LLVMBackendConfig, LLVMCallbacks,
|
||||
};
|
||||
use inkwell::{
|
||||
builder::Builder,
|
||||
@ -877,6 +878,7 @@ pub struct LLVMModuleCodeGenerator<'ctx> {
|
||||
stackmaps: Rc<RefCell<StackmapRegistry>>,
|
||||
track_state: bool,
|
||||
target_machine: TargetMachine,
|
||||
llvm_callbacks: Option<Rc<RefCell<dyn LLVMCallbacks>>>,
|
||||
}
|
||||
|
||||
pub struct LLVMFunctionCodeGenerator<'ctx> {
|
||||
@ -8513,6 +8515,7 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
||||
stackmaps: Rc::new(RefCell::new(StackmapRegistry::default())),
|
||||
track_state: false,
|
||||
target_machine,
|
||||
llvm_callbacks: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -8654,8 +8657,10 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
||||
message: format!("trampolines generation error: {:?}", e),
|
||||
})?;
|
||||
|
||||
if let Some(path) = unsafe { &crate::GLOBAL_OPTIONS.pre_opt_ir } {
|
||||
self.module.borrow_mut().print_to_file(path).unwrap();
|
||||
if let Some(ref mut callbacks) = self.llvm_callbacks {
|
||||
callbacks
|
||||
.borrow_mut()
|
||||
.preopt_ir_callback(&*self.module.borrow_mut());
|
||||
}
|
||||
|
||||
let pass_manager = PassManager::create(());
|
||||
@ -8695,8 +8700,10 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
||||
pass_manager.add_early_cse_pass();
|
||||
|
||||
pass_manager.run_on(&*self.module.borrow_mut());
|
||||
if let Some(path) = unsafe { &crate::GLOBAL_OPTIONS.post_opt_ir } {
|
||||
self.module.borrow_mut().print_to_file(path).unwrap();
|
||||
if let Some(ref mut callbacks) = self.llvm_callbacks {
|
||||
callbacks
|
||||
.borrow_mut()
|
||||
.postopt_ir_callback(&*self.module.borrow_mut());
|
||||
}
|
||||
|
||||
let stackmaps = self.stackmaps.borrow();
|
||||
@ -8707,12 +8714,18 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
|
||||
&*stackmaps,
|
||||
module_info,
|
||||
&self.target_machine,
|
||||
&mut self.llvm_callbacks,
|
||||
);
|
||||
Ok((backend, Box::new(cache_gen)))
|
||||
}
|
||||
|
||||
fn feed_compiler_config(&mut self, config: &CompilerConfig) -> Result<(), CodegenError> {
|
||||
self.track_state = config.track_state;
|
||||
if let Some(backend_compiler_config) = &config.backend_specific_config {
|
||||
if let Some(llvm_config) = backend_compiler_config.get_specific::<LLVMBackendConfig>() {
|
||||
self.llvm_callbacks = llvm_config.callbacks.clone();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user