summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2009-01-14 20:38:14 +0100
committerGuillaume Seguin <guillaume@segu.in>2009-01-14 20:38:14 +0100
commit9d878f3e39a2bd46e652d2b0cac4f82046728b52 (patch)
tree8d41f1eb02fae1893a1ecbe03a84bb81d6217dfc
parentf44f0b34894ed330c7291b0952291b4a5acc25cd (diff)
downloadpetitcaml-9d878f3e39a2bd46e652d2b0cac4f82046728b52.tar.gz
petitcaml-9d878f3e39a2bd46e652d2b0cac4f82046728b52.tar.bz2
[petitcaml] optimize.ml : comment & add some rough optimizations
-rw-r--r--optimize.ml12
1 files changed, 11 insertions, 1 deletions
diff --git a/optimize.ml b/optimize.ml
index 5f88ec2..a0bee21 100644
--- a/optimize.ml
+++ b/optimize.ml
@@ -1,7 +1,12 @@
+(****************************************
+ optimize.ml - optimisations de code
+ ****************************************)
+
open Ast
open Utils
open Mips
+(* Réduit les opérations constantes précalculables de l'ast *)
let optimize_binop e1 o e2 =
match e1.e, o, e2.e with
| (Econst (Cint c1), OAdd, Econst (Cint c2)) ->
@@ -96,9 +101,14 @@ let rec optimize_ast expr =
in
raw_expr new_e
+(* Réduction des opérations assembleur consécutives *)
+(* TODO : optimiser plus *)
let optimize_program p =
let rec optimize_instrs = function
| [] -> []
- | i::l -> i::(optimize_instrs l) (* TODO *)
+ | (Addi (rdest1, rsrc1, i1))::(Addi (rdest2, rsrc2, i2))::l
+ when rdest1 = rdest2 && rsrc1 = rsrc2 ->
+ optimize_instrs ((Addi (rdest1, rsrc1, i1 + i2))::l)
+ | i::l -> i::(optimize_instrs l)
in
{p with text = optimize_instrs p.text}