From 518d30b3793b57182a01afeca65879709da832ea Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 17 Feb 2017 11:57:32 -0800 Subject: [PATCH] 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. --- lib/cretonne/src/context.rs | 23 +++++++++++++++++++++++ lib/cretonne/src/lib.rs | 24 +++++++++++++----------- 2 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 lib/cretonne/src/context.rs diff --git a/lib/cretonne/src/context.rs b/lib/cretonne/src/context.rs new file mode 100644 index 0000000000..2360302ea2 --- /dev/null +++ b/lib/cretonne/src/context.rs @@ -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() } + } +} diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index bfd986949a..47339a39ca 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -2,28 +2,30 @@ #![deny(missing_docs)] +pub use context::Context; +pub use legalizer::legalize_function; pub use verifier::verify_function; pub use write::write_function; -pub use legalizer::legalize_function; /// Version number of the cretonne crate. pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); -pub mod ir; -pub mod isa; pub mod cfg; pub mod dominator_tree; -pub mod entity_map; pub mod entity_list; -pub mod sparse_map; -pub mod settings; -pub mod verifier; +pub mod entity_map; +pub mod ir; +pub mod isa; pub mod regalloc; +pub mod settings; +pub mod sparse_map; +pub mod verifier; -mod write; mod constant_hash; -mod predicates; +mod context; mod legalizer; -mod ref_slice; -mod partition_slice; mod packed_option; +mod partition_slice; +mod predicates; +mod ref_slice; +mod write;