mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-16 07:28:52 +00:00
Update homework 1 and 2
This commit is contained in:
48
src/opt/simplify_cfg.rs
Normal file
48
src/opt/simplify_cfg.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use crate::ir::*;
|
||||
use crate::*;
|
||||
|
||||
pub type SimplifyCfg = Repeat<(SimplifyCfgConstProp, (SimplifyCfgReach, SimplifyCfgMerge))>;
|
||||
|
||||
impl Optimize<TranslationUnit> for SimplifyCfg {
|
||||
fn optimize(&mut self, code: &mut TranslationUnit) -> bool {
|
||||
code.decls.iter_mut().any(|(_, decl)| self.optimize(decl))
|
||||
}
|
||||
}
|
||||
|
||||
impl Optimize<Declaration> for SimplifyCfg {
|
||||
fn optimize(&mut self, code: &mut Declaration) -> bool {
|
||||
let (_fsig, fdef) = some_or!(code.get_function_mut(), return false);
|
||||
let fdef = some_or!(fdef, return false);
|
||||
self.optimize(fdef)
|
||||
}
|
||||
}
|
||||
|
||||
/// Simplifies block exits by propagating constants.
|
||||
#[derive(Default)]
|
||||
pub struct SimplifyCfgConstProp {}
|
||||
|
||||
/// Retains only those blocks that are reachable from the init.
|
||||
#[derive(Default)]
|
||||
pub struct SimplifyCfgReach {}
|
||||
|
||||
/// Merges two blocks if a block is pointed to only by another
|
||||
#[derive(Default)]
|
||||
pub struct SimplifyCfgMerge {}
|
||||
|
||||
impl Optimize<FunctionDefinition> for SimplifyCfgConstProp {
|
||||
fn optimize(&mut self, _code: &mut FunctionDefinition) -> bool {
|
||||
todo!("homework 3")
|
||||
}
|
||||
}
|
||||
|
||||
impl Optimize<FunctionDefinition> for SimplifyCfgReach {
|
||||
fn optimize(&mut self, _code: &mut FunctionDefinition) -> bool {
|
||||
todo!("homework 3")
|
||||
}
|
||||
}
|
||||
|
||||
impl Optimize<FunctionDefinition> for SimplifyCfgMerge {
|
||||
fn optimize(&mut self, _code: &mut FunctionDefinition) -> bool {
|
||||
todo!("homework 3")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user