Add a compilation context struct.

This will provide main entry points for compiling functions, and it
serves as a place for keeping data structures that should be preserved
between function compilations to reduce allocator thrashing.

So far, Context is just basic scaffolding. More to be added.
This commit is contained in:
Jakob Stoklund Olesen
2017-02-17 11:57:32 -08:00
parent 3072728d37
commit 518d30b379
2 changed files with 36 additions and 11 deletions

View File

@@ -0,0 +1,23 @@
//! Cretonne compilation context and main entry point.
//!
//! When compiling many small functions, it is important to avoid repeatedly allocating and
//! deallocating the data structures needed for compilation. The `Context` struct is used to hold
//! on to memory allocations between function compilations.
use ir::Function;
/// Persistent data structures and compilation pipeline.
pub struct Context {
/// The function we're compiling.
pub func: Function,
}
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() -> Context {
Context { func: Function::new() }
}
}

View File

@@ -2,28 +2,30 @@
#![deny(missing_docs)] #![deny(missing_docs)]
pub use context::Context;
pub use legalizer::legalize_function;
pub use verifier::verify_function; pub use verifier::verify_function;
pub use write::write_function; pub use write::write_function;
pub use legalizer::legalize_function;
/// Version number of the cretonne crate. /// Version number of the cretonne crate.
pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
pub mod ir;
pub mod isa;
pub mod cfg; pub mod cfg;
pub mod dominator_tree; pub mod dominator_tree;
pub mod entity_map;
pub mod entity_list; pub mod entity_list;
pub mod sparse_map; pub mod entity_map;
pub mod settings; pub mod ir;
pub mod verifier; pub mod isa;
pub mod regalloc; pub mod regalloc;
pub mod settings;
pub mod sparse_map;
pub mod verifier;
mod write;
mod constant_hash; mod constant_hash;
mod predicates; mod context;
mod legalizer; mod legalizer;
mod ref_slice;
mod partition_slice;
mod packed_option; mod packed_option;
mod partition_slice;
mod predicates;
mod ref_slice;
mod write;