Make the ControlFlowGraph reusable.
Move the flow graph computation into a compute method which can be called with multiple functions. This allows us to reuse the ControlFlowGraph memory and keep an instance in the Context.
This commit is contained in:
@@ -4,12 +4,16 @@
|
||||
//! deallocating the data structures needed for compilation. The `Context` struct is used to hold
|
||||
//! on to memory allocations between function compilations.
|
||||
|
||||
use cfg::ControlFlowGraph;
|
||||
use ir::Function;
|
||||
|
||||
/// Persistent data structures and compilation pipeline.
|
||||
pub struct Context {
|
||||
/// The function we're compiling.
|
||||
pub func: Function,
|
||||
|
||||
/// The control flow graph of `func`.
|
||||
pub cfg: ControlFlowGraph,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
@@ -18,6 +22,9 @@ impl Context {
|
||||
/// The returned instance should be reused for compiling multiple functions in order to avoid
|
||||
/// needless allocator thrashing.
|
||||
pub fn new() -> Context {
|
||||
Context { func: Function::new() }
|
||||
Context {
|
||||
func: Function::new(),
|
||||
cfg: ControlFlowGraph::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user