Add deadcode examples

This commit is contained in:
Jeehoon Kang
2020-05-03 06:01:46 +00:00
parent f4dc5e426c
commit 9a2dd840d2
6 changed files with 86 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
fun unit @sink {
init:
bid: b0
allocations:
block b0:
%b0:p0:unit
ret unit:unit
}
fun i32 @deadcode {
init:
bid: b0
allocations:
%l0:i32:x
%l1:i32:y
block b0:
%b0:i0:i32 = add 100:i32 200:i32
%b0:i1:i32 = add %b0:i0:i32 300:i32
%b0:i2:i32 = add %b0:i1:i32 400:i32
%b0:i3:unit = store %l1:i32 %b0:i0:i32
br undef:i1 b1() b2()
block b1:
%b1:i0:unit = nop
%b1:i1:unit = call @sink(%b1:i0:unit)
j b3()
block b2:
%b2:i0:unit = store %l1:i32 42:i32
j b3()
block b3:
ret 0:i32
}

View File

@@ -0,0 +1,35 @@
fun unit @sink {
init:
bid: b0
allocations:
block b0:
%b0:p0:unit
ret unit:unit
}
fun i32 @deadcode {
init:
bid: b0
allocations:
%l0:i32:y
block b0:
%b0:i0:i32 = add 100:i32 200:i32
%b0:i1:unit = store %l0:i32 %b0:i0:i32
br undef:i1 b1() b2()
block b1:
%b1:i0:unit = call @sink(unit:unit)
j b3()
block b2:
%b2:i0:unit = store %l0:i32 42:i32
j b3()
block b3:
ret 0:i32
}

View File

@@ -238,7 +238,7 @@ peg::parser! {
} }
/ /
"unit" { "unit" {
Constant::undef(Dtype::unit()) // TODO Constant::unit()
} }
/ /
"<constant>" { "<constant>" {

View File

@@ -2,7 +2,7 @@ use crate::ir::*;
use crate::opt::FunctionPass; use crate::opt::FunctionPass;
use crate::*; use crate::*;
pub type Deadcode = FunctionPass<DeadcodeInner>; pub type Deadcode = FunctionPass<Repeat<DeadcodeInner>>;
#[derive(Default)] #[derive(Default)]
pub struct DeadcodeInner {} pub struct DeadcodeInner {}

View File

@@ -20,7 +20,7 @@ pub trait Optimize<T> {
} }
pub type O0 = Null; pub type O0 = Null;
pub type O1 = Repeat<(SimplifyCfg, (Mem2reg, (Deadcode, Gvn)))>; pub type O1 = Repeat<(SimplifyCfg, (Mem2reg, (Gvn, Deadcode)))>;
#[derive(Default)] #[derive(Default)]
pub struct Null {} pub struct Null {}

View File

@@ -92,3 +92,12 @@ fn test_examples_gvn() {
&mut Gvn::default(), &mut Gvn::default(),
); );
} }
#[test]
fn test_examples_deadcode() {
test_opt(
&Path::new("examples/deadcode/deadcode.input.ir"),
&Path::new("examples/deadcode/deadcode.output.ir"),
&mut Deadcode::default(),
);
}