Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[experiments] making better example for gvn

  • Loading branch information...
commit f50c2c36fcb8bebfcf0179bf617877d6ff5e47be 1 parent 6c17655
Raphaël Proust authored
6 .gitignore
View
@@ -24,3 +24,9 @@ tests/*.cps
tests/*.ssa
tests/*.bc
tests/*.hi
+experiments/*/*.hi
+experiments/*/*.ll
+experiments/*/*.cps
+experiments/*/*.ssa
+experiments/*/*.bc
+experiments/*/*.hi
63 experiments/gvn/Makefile
View
@@ -0,0 +1,63 @@
+
+CS= \
+ bar.c \
+ bar2.c \
+ calls_if.c \
+ calls_simpl.c \
+ calls_simpl_nested.c \
+ constflow.c \
+ dead.c \
+ dead2.c \
+ fibonacci.c \
+ foo_after.c \
+ foo_before.c \
+ foo_both.c \
+ forloop.c \
+ ifif.c \
+ ifs.c \
+ smallish.c
+
+HSS= \
+ fibonacci_pat.hs \
+ fibonacci_zip.hs \
+ fun0.hs \
+ funif.hs \
+ mutual.hs \
+ mutual_infinite.hs \
+ y.hs \
+
+LLS=$(CS:.c=.ll) $(HSS:.hs=.ll)
+SSAS=$(CS:.c=.ssa) $(HSS:.hs=.ssa)
+CPSS=$(CS:.c=.cps) $(HSS:.hs=.cps)
+
+OPTS= gvn
+
+all: run
+
+run: lls
+ ../../src/run.native $(LLS) -- $(OPTS)
+
+bcs: $(BCS)
+
+lls: $(LLS)
+
+ssas: $(SSAS)
+
+cpss: $(CPSS)
+
+clean:
+ rm -f $(BCS) *.ssa *.cps *.ll *.hi *.o
+
+%.pre.ll: %.c
+ clang $< -O0 -emit-llvm -S -o $@
+
+%.ll: %.hs
+ ghc -keep-llvm-file -O1 -c $<
+ opt -S -mem2reg $@ > $@.pre
+ mv $@.pre $@
+
+%.ll: %.pre.ll
+ opt -S -mem2reg $< > $@
+
+%.cps %.ssa: %.ll
+ ../src/run.native $<
7 experiments/gvn/bar.c
View
@@ -0,0 +1,7 @@
+int entry (int foo) {
+ int i;
+ for(i=0; i<100; i++){
+ foo++;
+ }
+ return foo;
+}
7 experiments/gvn/bar2.c
View
@@ -0,0 +1,7 @@
+int entry (int foo, int bar) {
+ int i;
+ for(i=0; i<100; i++){
+ foo += bar;
+ }
+ return foo;
+}
31 experiments/gvn/calls_if.c
View
@@ -0,0 +1,31 @@
+int baz(int a) {
+ return (a+a);
+}
+
+int bar(int a) {
+ int res = a;
+ res += baz(a);
+ return res;
+}
+
+int foo(int a) {
+ int res = 0;
+ res = bar(a);
+ res += baz(a);
+ return res;
+}
+
+int entry (int b, int x, int y){
+ int res = 0;
+ if (!b) {
+ b++;
+ res = foo(x);
+ } else {
+ res = foo(x);
+ }
+ if (b) {
+ res += bar(y);
+ }
+ return res;
+}
+
15 experiments/gvn/calls_simpl.c
View
@@ -0,0 +1,15 @@
+int baz(int a) {
+ return (a + a);
+}
+
+int foo(int a) {
+ return 0;
+}
+
+int entry (int b, int n){
+ int res = 0;
+ res += foo(n);
+ res += baz(n);
+ return res;
+}
+
16 experiments/gvn/calls_simpl_nested.c
View
@@ -0,0 +1,16 @@
+int baz(int a) {
+ return (a + a);
+}
+
+int foo(int a) {
+ int res = baz(a + a);
+ return res;
+}
+
+int entry (int b, int n){
+ int res = 0;
+ res += foo(n);
+ res += baz(n);
+ return res;
+}
+
40 experiments/gvn/constflow.c
View
@@ -0,0 +1,40 @@
+int entry (int flag0, int flag1){
+
+ const int n0 = 223;
+ const int n1 = 2;
+
+ int tmp0, tmp1;
+ int bar0, bar1;
+
+ if (flag1) {
+
+ tmp0 = n0+n1;
+ tmp1 = n0-n1;
+
+ const int foo0 = tmp0-tmp1;
+ const int foo1 = tmp0+tmp1;
+
+ bar0 = foo0*foo1;
+ bar1 = foo0*foo1;
+
+ }
+
+ if (flag1) {
+
+ tmp0 = n0+n1;
+ tmp1 = n0+n1;
+
+ const int fu0 = tmp0-tmp1;
+ const int fu1 = tmp0*tmp1;
+
+ bar0 = fu0*fu1;
+ bar1 = fu0+fu1;
+
+ }
+
+ const int res0 = bar0+bar1;
+ const int res1 = tmp0-bar0;
+ const int res = res0+res1;
+
+ return res;
+}
26 experiments/gvn/dead.c
View
@@ -0,0 +1,26 @@
+int complicated(int input){
+ int output = input;
+ output *= input;
+
+ int i;
+ for(i=0; i<100; i++){
+ output+=input;
+ }
+
+ return output;
+
+}
+
+int entry(){
+ int foo = 0;
+ int blah = 0;
+ foo += blah;
+
+ if(foo){
+ blah=4;
+ blah=complicated(blah);
+ }
+
+ return blah;
+
+}
36 experiments/gvn/dead2.c
View
@@ -0,0 +1,36 @@
+int complicated(int input){
+ int output = input;
+ output *= input;
+
+ int i;
+ for(i=0; i<100; i++){
+ output+=input;
+ }
+
+ return output;
+
+}
+
+int entry(){
+ const int foo = 0;
+ const int bar = 1;
+ int blah = 0;
+
+ if(foo){
+ blah=4;
+ blah=complicated(blah);
+ } else {
+ if(foo) {
+ blah=5;
+ blah=complicated(blah);
+ } else {
+ if(!bar) {
+ blah=6;
+ blah=complicated(blah);
+ }
+ }
+ }
+
+ return blah;
+
+}
13 experiments/gvn/fibonacci.c
View
@@ -0,0 +1,13 @@
+int entry (int n) {
+ int i = 0;
+ int num1 = 0;
+ int num2 = 1;
+ int temp;
+ for(i = 0; i < n; i++){
+ temp = num1+num2;
+ num1 = num2;
+ num2 = temp;
+ }
+ return temp;
+}
+
6 experiments/gvn/fibonacci_pat.hs
View
@@ -0,0 +1,6 @@
+module FPat where
+
+fibonacci :: Integer -> Integer
+fibonacci 0 = 0
+fibonacci 1 = 1
+fibonacci n = fibonacci (n-1) + fibonacci (n-2)
5 experiments/gvn/fibonacci_zip.hs
View
@@ -0,0 +1,5 @@
+module FZip where
+
+fibonacci :: Int -> Int
+fibonacci n = fibs !! n
+ where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
12 experiments/gvn/foo_after.c
View
@@ -0,0 +1,12 @@
+int entry (int b, int n, int m){
+ int res = 0;
+ if(b) {
+ res -= m;
+ res++;
+ } else {
+ res += m;
+ res++;
+ }
+ return res;
+}
+
12 experiments/gvn/foo_before.c
View
@@ -0,0 +1,12 @@
+int entry (int b, int n, int m){
+ int res = 0;
+ if(b) {
+ res += n;
+ res -= m;
+ } else {
+ res += n;
+ res += m;
+ }
+ return res;
+}
+
14 experiments/gvn/foo_both.c
View
@@ -0,0 +1,14 @@
+int entry (int b, int n, int m){
+ int res = 0;
+ if(b) {
+ res += n;
+ res -= m;
+ res++;
+ } else {
+ res += n;
+ res -= m;
+ res++;
+ }
+ return res;
+}
+
8 experiments/gvn/forloop.c
View
@@ -0,0 +1,8 @@
+int entry (int n){
+ int i = 0;
+ int res = 0;
+ for(i=0; i<n; i++){
+ res++;
+ }
+ return res;
+}
4 experiments/gvn/fun0.hs
View
@@ -0,0 +1,4 @@
+module Fun where
+
+zero :: a -> Integer
+zero _ = 0
5 experiments/gvn/funif.hs
View
@@ -0,0 +1,5 @@
+module If where
+
+if' :: Bool -> a -> a -> a
+if' True x _ = x
+if' False _ y = y
13 experiments/gvn/ifif.c
View
@@ -0,0 +1,13 @@
+int entry (int n1, int n2){
+ int res = 0;
+ if (n1==0) {
+ res = 0;
+ } else {
+ res--;
+ }
+ if (n2==0) {
+ } else {
+ res--;
+ }
+ return res;
+}
14 experiments/gvn/ifs.c
View
@@ -0,0 +1,14 @@
+int entry (int b, int x, int y){
+ int res = 0;
+ if (!b) {
+ b++;
+ res = 42;
+ } else {
+ res = 43;
+ }
+ if (b) {
+ res += b;
+ }
+ return res;
+}
+
9 experiments/gvn/mutual.hs
View
@@ -0,0 +1,9 @@
+module Mutual where
+
+even' :: Integer -> Bool
+even' 0 = True
+even' n = odd' (n - 1)
+
+odd' :: Integer -> Bool
+odd' 0 = False
+odd' n = even' (n - 1)
9 experiments/gvn/mutual_infinite.hs
View
@@ -0,0 +1,9 @@
+module MutualInf where
+
+f :: Integer -> Bool
+f 0 = True
+f n = g n
+
+g :: Integer -> Bool
+g 0 = False
+g n = f n
10 experiments/gvn/smallish.c
View
@@ -0,0 +1,10 @@
+int entry(int n){
+ int blah = 0;
+ const int step = 422;
+
+ for(int i = 10; i>0; i--){
+ blah += step;
+ }
+
+ return blah;
+}
4 experiments/gvn/y.hs
View
@@ -0,0 +1,4 @@
+module Y where
+
+f :: Integer -> Integer -> Integer -> Integer
+f x y z = x + y + z
Please sign in to comment.
Something went wrong with that request. Please try again.