Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chaos mode: refactoring ControlPlane to be passed through the call st…
…ack by reference

Co-authored-by: Falk Zwimpfer <[email protected]>
Co-authored-by: Remo Senekowitsch <[email protected]>
  • Loading branch information
3 people authored and senekor committed Apr 3, 2023
commit dfa059426d617946e9bc698e39e821958084f902
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 30 additions & 8 deletions cranelift/codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,50 @@ pub struct Context {
/// Flag: do we want a disassembly with the CompiledCode?
pub want_disasm: bool,

/// Only used during fuzz-testing. Otherwise, this is a zero-sized struct
/// and compiled away. See [cranelift_control].
control_plane: ControlPlane,
/// TODO chaos: is this the right location to hold ownership?
pub ctrl_plane: ControlPlane,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably better to pass in the control-plane state with each call to compile; the CompilerContext is otherwise not that semantically meaningful (meant to enable reuse).

}

impl Context {
/// Allocate a new compilation context.
///
/// The returned instance should be reused for compiling multiple functions in order to avoid
/// needless allocator thrashing.
pub fn new(control_plane: ControlPlane) -> Self {
Self::for_function(Function::new(), control_plane)
pub fn new() -> Self {
Self::for_function(Function::new())
}

/// TODO:
pub fn new_with_ctrl_plane(ctrl_plane: ControlPlane) -> Self {
Self::for_function_with_ctrl_plane(Function::new(), ctrl_plane)
}

/// Allocate a new compilation context with an existing Function.
///
/// The returned instance should be reused for compiling multiple functions in order to avoid
/// needless allocator thrashing.
pub fn for_function(func: Function, control_plane: ControlPlane) -> Self {
pub fn for_function(func: Function) -> Self {
Self {
func,
cfg: ControlFlowGraph::new(),
domtree: DominatorTree::new(),
loop_analysis: LoopAnalysis::new(),
compiled_code: None,
want_disasm: false,
control_plane,
ctrl_plane: ControlPlane::default(),
}
}

/// TODO:
pub fn for_function_with_ctrl_plane(func: Function, ctrl_plane: ControlPlane) -> Self {
Self {
func,
cfg: ControlFlowGraph::new(),
domtree: DominatorTree::new(),
loop_analysis: LoopAnalysis::new(),
compiled_code: None,
want_disasm: false,
ctrl_plane,
}
}

Expand Down Expand Up @@ -146,7 +163,12 @@ impl Context {

self.optimize(isa)?;

isa.compile_function(&self.func, &self.domtree, self.want_disasm)
isa.compile_function(
&self.func,
&self.domtree,
self.want_disasm,
&mut self.ctrl_plane,
)
}

/// Optimize the function, performing all compilation steps up to
Expand Down
Loading