mod const_indexed_aggregates;
mod constant_propagate;
mod misc;
mod reachability;
mod verify;
use std::cmp::Ordering;
use super::abstract_instruction_set::AbstractInstructionSet;
use crate::OptLevel;
use super::data_section::DataSection;
const MAX_OPT_ROUNDS: usize = 10;
fn log_nothing(_: &str) {}
impl AbstractInstructionSet {
pub(crate) fn optimize(
mut self,
data_section: &DataSection,
level: OptLevel,
) -> AbstractInstructionSet {
match level {
OptLevel::Opt0 => self
.const_indexing_aggregates_function(data_section)
.constant_propagate(log_nothing)
.dce()
.simplify_cfg()
.remove_sequential_jumps()
.remove_redundant_moves()
.remove_redundant_ops(),
OptLevel::Opt1 => {
for _ in 0..MAX_OPT_ROUNDS {
let old = self.clone();
self = self.optimize(data_section, OptLevel::Opt0);
self = self.optimize(data_section, OptLevel::Opt0);
match self.ops.len().cmp(&old.ops.len()) {
Ordering::Equal => break,
Ordering::Greater => return old,
Ordering::Less => {}
}
}
self
}
}
}
}