mod fix_irreducible;
mod memory_to_register;
mod remove_load_directly_after_store;
mod remove_only_once_store;
mod remove_unused_register;
mod topological_sort;
use crate::ir::editor::Editor;
use enum_dispatch::enum_dispatch;
pub use fix_irreducible::FixIrreducible;
use memory_to_register::MemoryToRegister;
use remove_load_directly_after_store::RemoveLoadDirectlyAfterStore;
use remove_only_once_store::RemoveOnlyOnceStore;
use remove_unused_register::RemoveUnusedRegister;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
pub use topological_sort::TopologicalSort;
#[enum_dispatch]
pub trait IsPass {
fn run(&self, editor: &mut Editor);
fn need(&self) -> Vec<Pass>;
fn invalidate(&self) -> Vec<Pass>;
}
#[enum_dispatch(IsPass)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, Deserialize, Serialize)]
pub enum Pass {
RemoveUnusedRegister,
RemoveOnlyOnceStore,
RemoveLoadDirectlyAfterStore,
MemoryToRegister,
FixIrreducible,
TopologicalSort,
}
impl FromStr for Pass {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"RemoveUnusedRegister" => Ok(Self::RemoveUnusedRegister(RemoveUnusedRegister)),
"RemoveOnlyOnceStore" => Ok(Self::RemoveOnlyOnceStore(RemoveOnlyOnceStore)),
"RemoveLoadDirectlyAfterStore" => Ok(Self::RemoveLoadDirectlyAfterStore(
RemoveLoadDirectlyAfterStore,
)),
"MemoryToRegister" => Ok(Self::MemoryToRegister(MemoryToRegister)),
"FixIrreducible" => Ok(Self::FixIrreducible(FixIrreducible)),
"TopologicalSort" => Ok(Self::TopologicalSort(TopologicalSort)),
_ => Err(()),
}
}
}
impl From<&str> for Pass {
fn from(s: &str) -> Self {
Self::from_str(s).unwrap()
}
}