Add early-stage optimization crate (#556)

* Add simple constant folding and folding tests
This commit is contained in:
Lachlan Sneff
2018-11-07 18:59:29 -05:00
committed by Dan Gohman
parent bdcc06eb15
commit 3409af7c07
22 changed files with 745 additions and 21 deletions

View File

@@ -22,11 +22,11 @@ use licm::do_licm;
use loop_analysis::LoopAnalysis;
use nan_canonicalization::do_nan_canonicalization;
use postopt::do_postopt;
use preopt::do_preopt;
use regalloc;
use result::CodegenResult;
use settings::{FlagsOrIsa, OptLevel};
use simple_gvn::do_simple_gvn;
use simple_preopt::do_preopt;
use std::vec::Vec;
use timing;
use unreachable_code::eliminate_unreachable_code;

View File

@@ -104,12 +104,12 @@ mod nan_canonicalization;
mod partition_slice;
mod postopt;
mod predicates;
mod preopt;
mod ref_slice;
mod regalloc;
mod result;
mod scoped_hash_map;
mod simple_gvn;
mod simple_preopt;
mod stack_layout;
mod topo_order;
mod unreachable_code;

View File

@@ -124,7 +124,7 @@ mod details {
}
/// Accumulated timing information for a single pass.
#[derive(Default)]
#[derive(Default, Copy, Clone)]
struct PassTime {
/// Total time spent running this pass including children.
total: Duration,
@@ -134,17 +134,24 @@ mod details {
}
/// Accumulated timing for all passes.
#[derive(Default)]
pub struct PassTimes {
pass: [PassTime; NUM_PASSES],
}
impl Default for PassTimes {
fn default() -> Self {
PassTimes {
pass: [Default::default(); NUM_PASSES],
}
}
}
impl fmt::Display for PassTimes {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "======== ======== ==================================")?;
writeln!(f, " Total Self Pass")?;
writeln!(f, "-------- -------- ----------------------------------")?;
for (time, desc) in self.pass.iter().zip(&DESCRIPTIONS) {
for (time, desc) in self.pass.iter().zip(&DESCRIPTIONS[..]) {
// Omit passes that haven't run.
if time.total == Duration::default() {
continue;
@@ -212,7 +219,7 @@ mod details {
/// Add `timings` to the accumulated timings for the current thread.
pub fn add_to_current(times: &PassTimes) {
PASS_TIME.with(|rc| {
for (a, b) in rc.borrow_mut().pass.iter_mut().zip(&times.pass) {
for (a, b) in rc.borrow_mut().pass.iter_mut().zip(&times.pass[..]) {
a.total += b.total;
a.child += b.child;
}