Cretonne IL frontend: ILBuilder (#97)

* API and data structures proposal for the SSA construction module

* Polished API and implemented trivial functions

* API more explicit, Variable now struct parameter

* Sample test written to see how the API could be used

* Implemented local value numbering for SSABuilder

* Implemented SSA within a single Ebb

* Unfinished unoptimized implementation for recursive use and seal

* Working global value numbering
The SSABuilder now create ebb args and modifies jump instructions accordingly

* Updated doc and improved branch argument modifying.
Removed instructions::branch_arguments and instructions::branch_argument_mut

* SSA building: bugfix, asserts and new test case
Missing a key optimization to remove cycles of Phi

* SSA Building: small changes after code review
Created helper function for seal_block (which now contains sanity checks)

* Optimization: removed useless phis (ebb arguments)
Using pessimistic assumption that when using a non-def variable in an unsealed block we create an ebb argument which is removed when sealing if we detect it as useless
Using aliases to avoid rewriting variables

* Changed the semantics of remove_ebb_arg and turned it into a proper API method

* Adapted ssa branch to changes in the DFG API

* Abandonned SparseMaps for EntityMaps, added named structure for headr block data.

* Created skeletton for a Cretonne IL builder frontend

* Frontend IL builder: first draft of implementation with example of instruction methods

* Working basic implementation of the frontend
Missing handling of function arguments and return values

* Interaction with function signature, sample test, more checks

* Test with function verifier, seal and fill sanity check

* Implemented python script to generate ILBuilder methods

* Added support for jump tables and stack slot

* Major API overhaul
* No longer generating rust through Python but implements InstBuilder
* No longer parametrized by user's blocks but use regular `Ebb`
* Reuse of allocated memory via distinction between ILBuilder and FunctionBuilder

* Integrate changes from StackSlot

* Improved error message

* Added support for jump arguments supplied by the user

* Added an ebb_args proxy method needed

* Adapted to Entity_ref splitted into a new module

* Better error messages and fixed tests

* Added method to change jump destination

* We whould be able to add unreachable code

* Added inst_result proxy to frontend

* Import support

* Added optimization for SSA construction:
If multiple predecessors but agree on value don't create EBB argument

* Move unsafe and not write-only funcs apart, improved doc

* Added proxy function for append_ebb_arg

* Support for unreachable code and better layout of the Ebbs

* Fixed a bug yielding an infinite loop in SSA construction

* SSA predecessors lookup code refactoring

* Fixed bug in unreachable definition

* New sanity check and display debug function

* Fixed bug in verifier and added is_pristine ;ethod for frontend

* Extended set of characters printable in function names
To be able to print names of functions in test suite

* Fixes and improvements of SSA construction after code review

* Bugfixes for frontend code simplification

* On-the-fly critical edge splitting in case of br_table with jump arguments

* No more dangling undefined values, now attached as EBB args

* Bugfix: only split corresponding edges on demand, not all br_table edges

* Added signature retrieval method

* Bugfix for critical edge splitting not sealing the ebbs it created

* Proper handling of SSA side effects by the frontend

* Code refactoring: moving frontend and SSA to new crate

* Frontend: small changes and bugfixes after code review
This commit is contained in:
Denis Merigoux
2017-07-11 15:08:57 -07:00
committed by Jakob Stoklund Olesen
parent 6ae4eb82f8
commit de5501bc47
10 changed files with 2162 additions and 2 deletions

View File

@@ -23,6 +23,8 @@ pub trait InstBuilderBase<'f>: Sized {
/// Get an immutable reference to the data flow graph that will hold the constructed
/// instructions.
fn data_flow_graph(&self) -> &DataFlowGraph;
/// Get a mutable reference to the data flow graph that will hold the constructed
/// instructions.
fn data_flow_graph_mut(&mut self) -> &mut DataFlowGraph;
/// Insert an instruction and return a reference to it, consuming the builder.

View File

@@ -728,6 +728,37 @@ impl DataFlowGraph {
num as usize
}
/// Removes `val` from `ebb`'s arguments by a standard linear time list removal which preserves
/// ordering. Also updates the values' data.
pub fn remove_ebb_arg(&mut self, val: Value) {
let (ebb, num) = if let ValueData::Arg { num, ebb, .. } = self.values[val] {
(ebb, num)
} else {
panic!("{} must be an EBB argument", val);
};
self.ebbs[ebb]
.args
.remove(num as usize, &mut self.value_lists);
for index in num..(self.ebb_args(ebb).len() as u16) {
match self.values[self.ebbs[ebb]
.args
.get(index as usize, &self.value_lists)
.unwrap()] {
ValueData::Arg { ref mut num, .. } => {
*num -= 1;
}
_ => {
panic!("{} must be an EBB argument",
self.ebbs[ebb]
.args
.get(index as usize, &self.value_lists)
.unwrap())
}
}
}
}
/// Append an existing argument value to `ebb`.
///
/// The appended value can't already be attached to something else.

View File

@@ -31,6 +31,7 @@ pub use ir::function::Function;
pub use ir::builder::InstBuilder;
pub use ir::progpoint::{ProgramPoint, ProgramOrder, ExpandedProgramPoint};
pub use ir::memflags::MemFlags;
pub use ir::builder::InstBuilderBase;
use binemit;
use entity_map::EntityMap;

View File

@@ -24,6 +24,7 @@ pub mod flowgraph;
pub mod ir;
pub mod isa;
pub mod loop_analysis;
pub mod packed_option;
pub mod regalloc;
pub mod result;
pub mod settings;
@@ -36,7 +37,6 @@ mod context;
mod iterators;
mod legalizer;
mod licm;
mod packed_option;
mod partition_slice;
mod predicates;
mod ref_slice;