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:
Jakob Stoklund Olesen
2017-02-17 12:16:48 -08:00
parent f3fa0fb4e9
commit 77a7ad88f4
6 changed files with 39 additions and 19 deletions

View File

@@ -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(),
}
}
}