Chaos mode MVP: Skip branch optimization in MachBuffer (#6039)
* fuzz: Add chaos mode control plane Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * fuzz: Skip branch optimization with chaos mode Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * fuzz: Rename chaos engine -> control plane Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * chaos mode: refactoring ControlPlane to be passed through the call stack by reference Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Remo Senekowitsch <contact@remsle.dev> * fuzz: annotate chaos todos Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * fuzz: cleanup control plane Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * fuzz: remove control plane from compiler context Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * fuzz: move control plane into emit state Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * fuzz: fix remaining compiler errors Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * fix tests * refactor emission state ctrl plane accessors Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * centralize conditional compilation of chaos mode Also cleanup a few straggling dependencies on cranelift-control that aren't needed anymore. Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * add cranelift-control to published crates prtest:full Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> * add cranelift-control to public crates Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> --------- Co-authored-by: Falk Zwimpfer <24669719+FalkZ@users.noreply.github.com> Co-authored-by: Moritz Waser <mzrw.dev@pm.me> Co-authored-by: Remo Senekowitsch <contact@remsle.dev>
This commit is contained in:
committed by
GitHub
parent
064968b01d
commit
7eb8914090
@@ -7,6 +7,7 @@ use cranelift_codegen::ir::{
|
||||
};
|
||||
use cranelift_codegen::isa::{OwnedTargetIsa, TargetIsa};
|
||||
use cranelift_codegen::{ir, settings, CodegenError, Context};
|
||||
use cranelift_control::ControlPlane;
|
||||
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
|
||||
use cranelift_jit::{JITBuilder, JITModule};
|
||||
use cranelift_module::{FuncId, Linkage, Module, ModuleError};
|
||||
@@ -49,6 +50,7 @@ struct DefinedFunction {
|
||||
/// "outside-of-function" functionality, see `cranelift_jit::backend::JITBackend`.
|
||||
///
|
||||
/// ```
|
||||
/// # let ctrl_plane = &mut Default::default();
|
||||
/// use cranelift_filetests::TestFileCompiler;
|
||||
/// use cranelift_reader::parse_functions;
|
||||
/// use cranelift_codegen::data_value::DataValue;
|
||||
@@ -57,8 +59,8 @@ struct DefinedFunction {
|
||||
/// let func = parse_functions(code).unwrap().into_iter().nth(0).unwrap();
|
||||
/// let mut compiler = TestFileCompiler::with_default_host_isa().unwrap();
|
||||
/// compiler.declare_function(&func).unwrap();
|
||||
/// compiler.define_function(func.clone()).unwrap();
|
||||
/// compiler.create_trampoline_for_function(&func).unwrap();
|
||||
/// compiler.define_function(func.clone(), ctrl_plane).unwrap();
|
||||
/// compiler.create_trampoline_for_function(&func, ctrl_plane).unwrap();
|
||||
/// let compiled = compiler.compile().unwrap();
|
||||
/// let trampoline = compiled.get_trampoline(&func).unwrap();
|
||||
///
|
||||
@@ -116,16 +118,24 @@ impl TestFileCompiler {
|
||||
|
||||
/// Declares and compiles all functions in `functions`. Additionally creates a trampoline for
|
||||
/// each one of them.
|
||||
pub fn add_functions(&mut self, functions: &[Function]) -> Result<()> {
|
||||
pub fn add_functions(
|
||||
&mut self,
|
||||
functions: &[Function],
|
||||
ctrl_planes: Vec<ControlPlane>,
|
||||
) -> Result<()> {
|
||||
// Declare all functions in the file, so that they may refer to each other.
|
||||
for func in functions {
|
||||
self.declare_function(func)?;
|
||||
}
|
||||
|
||||
let ctrl_planes = ctrl_planes
|
||||
.into_iter()
|
||||
.chain(std::iter::repeat(ControlPlane::default()));
|
||||
|
||||
// Define all functions and trampolines
|
||||
for func in functions {
|
||||
self.define_function(func.clone())?;
|
||||
self.create_trampoline_for_function(func)?;
|
||||
for (func, ref mut ctrl_plane) in functions.iter().zip(ctrl_planes) {
|
||||
self.define_function(func.clone(), ctrl_plane)?;
|
||||
self.create_trampoline_for_function(func, ctrl_plane)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -141,7 +151,7 @@ impl TestFileCompiler {
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
self.add_functions(&functions[..])?;
|
||||
self.add_functions(&functions[..], Vec::new())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -217,7 +227,7 @@ impl TestFileCompiler {
|
||||
}
|
||||
|
||||
/// Defines the body of a function
|
||||
pub fn define_function(&mut self, func: Function) -> Result<()> {
|
||||
pub fn define_function(&mut self, func: Function, ctrl_plane: &mut ControlPlane) -> Result<()> {
|
||||
let defined_func = self
|
||||
.defined_functions
|
||||
.get(&func.name)
|
||||
@@ -225,13 +235,17 @@ impl TestFileCompiler {
|
||||
|
||||
self.ctx.func = self.apply_func_rename(func, defined_func)?;
|
||||
self.module
|
||||
.define_function(defined_func.func_id, &mut self.ctx)?;
|
||||
.define_function(defined_func.func_id, &mut self.ctx, ctrl_plane)?;
|
||||
self.module.clear_context(&mut self.ctx);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Creates and registers a trampoline for a function if none exists.
|
||||
pub fn create_trampoline_for_function(&mut self, func: &Function) -> Result<()> {
|
||||
pub fn create_trampoline_for_function(
|
||||
&mut self,
|
||||
func: &Function,
|
||||
ctrl_plane: &mut ControlPlane,
|
||||
) -> Result<()> {
|
||||
if !self.defined_functions.contains_key(&func.name) {
|
||||
anyhow::bail!("Undeclared function {} found!", &func.name);
|
||||
}
|
||||
@@ -246,7 +260,7 @@ impl TestFileCompiler {
|
||||
let trampoline = make_trampoline(name.clone(), &func.signature, self.module.isa());
|
||||
|
||||
self.declare_function(&trampoline)?;
|
||||
self.define_function(trampoline)?;
|
||||
self.define_function(trampoline, ctrl_plane)?;
|
||||
|
||||
self.trampolines.insert(func.signature.clone(), name);
|
||||
|
||||
@@ -504,6 +518,7 @@ mod test {
|
||||
return v1
|
||||
}",
|
||||
);
|
||||
let ctrl_plane = &mut ControlPlane::default();
|
||||
|
||||
// extract function
|
||||
let test_file = parse_test(code.as_str(), ParseOptions::default()).unwrap();
|
||||
@@ -513,8 +528,12 @@ mod test {
|
||||
// execute function
|
||||
let mut compiler = TestFileCompiler::with_default_host_isa().unwrap();
|
||||
compiler.declare_function(&function).unwrap();
|
||||
compiler.define_function(function.clone()).unwrap();
|
||||
compiler.create_trampoline_for_function(&function).unwrap();
|
||||
compiler
|
||||
.define_function(function.clone(), ctrl_plane)
|
||||
.unwrap();
|
||||
compiler
|
||||
.create_trampoline_for_function(&function, ctrl_plane)
|
||||
.unwrap();
|
||||
let compiled = compiler.compile().unwrap();
|
||||
let trampoline = compiled.get_trampoline(&function).unwrap();
|
||||
let returned = trampoline.call(&[]);
|
||||
|
||||
Reference in New Issue
Block a user