Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ps 2 compile #73

Merged
merged 39 commits into from
Oct 3, 2011
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a3fb524
Changed definition of operand
awatanabe Sep 29, 2011
e282848
Partial implementation of compile_exp_r
awatanabe Sep 29, 2011
dd04af0
Preliminary implementation of compile_exp
awatanabe Sep 29, 2011
75ae0c1
Preliminary implementation of compile_exp
awatanabe Sep 29, 2011
b8c3656
Added comments to compile_exp
awatanabe Sep 30, 2011
e317019
Updated implementation of revapp to make it more logical
awatanabe Sep 30, 2011
9a64585
Implemented compilation of if statements
awatanabe Sep 30, 2011
337fceb
Added compilation for for loop and while loop
awatanabe Sep 30, 2011
1681d9c
Added a few comments
awatanabe Sep 30, 2011
5f6e407
Minor changes to the build system and a nice stub for the test system…
spartango Oct 2, 2011
eb312ed
pulled in stuff from compile to be able to adequately test it
spartango Oct 2, 2011
e2a1c09
added a nice script to compile the canned tests
spartango Oct 2, 2011
f8ec6df
got a working way to compile tests and hijack them with prints
spartango Oct 2, 2011
cf4ce9f
added some glue to run tests as a batch
spartango Oct 2, 2011
7001f26
made outputs nicer
spartango Oct 2, 2011
5d9a8a8
pretty\!
spartango Oct 2, 2011
31e2a41
starting some simple variable collection tests
spartango Oct 2, 2011
2bb37ca
fixed a bug in nested assignment
spartango Oct 2, 2011
d5dfd70
added a hack that patches the fail that is the inability for SPIM to …
spartango Oct 2, 2011
13a4759
cleanliness included in the hack
spartango Oct 2, 2011
191f705
Minor changes as i hunt down the flipped sw/la bug
spartango Oct 2, 2011
2b7776d
CAUTIOUS COMMIT: passes tests with the bug fix, but i'm still not con…
spartango Oct 2, 2011
9f86b33
Merge pull request #68 from spartango/ps_2_tests
spartango Oct 2, 2011
24cc9b6
added a file for optimizations
spartango Oct 2, 2011
25fa78d
minor changes
spartango Oct 2, 2011
52d622e
preliminary implementation of jump threading
spartango Oct 2, 2011
1b61aee
jump threading appears to work, although its vulnerable to crazy loop…
spartango Oct 2, 2011
0299fcb
nice things in .gitignore
spartango Oct 2, 2011
975b033
starting constantfolding, added folder and expression stub
spartango Oct 3, 2011
0f40e29
all cases by and/or in place
spartango Oct 3, 2011
5faea13
constant folder compiles, moving to test
spartango Oct 3, 2011
92dbb2d
added a simple constant folding fish file
spartango Oct 3, 2011
934e4af
added a simple constant folding test
spartango Oct 3, 2011
c5d34ef
Merge pull request #70 from spartango/ps_2_jump_thread
spartango Oct 3, 2011
0a81a8f
minor change to not folding
spartango Oct 3, 2011
bce120f
added a nice benchmark script
spartango Oct 3, 2011
0e786a5
better display
spartango Oct 3, 2011
8341f1f
used a fold in good place
spartango Oct 3, 2011
b2bacce
Merge pull request #72 from spartango/ps_2_conditional_opt
spartango Oct 3, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
starting constantfolding, added folder and expression stub
  • Loading branch information
spartango committed Oct 3, 2011
commit 975b03363c1ed3f6831cfdb2ef8a6be57809665a
31 changes: 31 additions & 0 deletions ps2/optimize.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,34 @@ let thread_jumps (insts : inst list) : inst list =
thread_jumps_r [] insts
;;

(* Constant folding: cutting constant-constant ops out of the AST *)
let rec constant_fold (statment : Ast.stmt) : Ast.stmt =

(* Handle expressions *)
let rec constant_fold_e (expression : Ast.exp) : Ast.exp =
let (rexpr, position) = expression in
let folded_expr =
match rexpr with
| Int
| Var
| Binop
| Not
| And
| Or
| Assign
in
(folded_expr, position)
in

(* Break statements down *)
let (rstatement, position) = statement in
let folded_statement =
match rstatement with
| Seq(s1, s2) -> Seq((constant_fold s1), (constant_fold s2))
| Exp(expr) -> Exp(constant_fold_e expr)
| Return(expr) -> Return(constant_fold_e expr)
| If(expr, then_s, else_s) -> If((constant_fold_e expr), (constant_fold then_s), (constant_fold else_s))
| While(expr, do_s) -> While((constant_fold_e expr), (constant_fold do_s))
| For(expr1, expr2, expr3, do_s) -> For((constant_fold_e expr1), (constant_fold_e expr2), (constant_fold_e expr3), (constant_fold do_s))
in
(folded_statement, position)