diff options
author | Paweł Dybiec <pdybiec@stud.cs.uni.wroc.pl> | 2019-01-27 23:47:42 +0100 |
---|---|---|
committer | Paweł Dybiec <pdybiec@stud.cs.uni.wroc.pl> | 2019-01-27 23:47:42 +0100 |
commit | 03e2e248f0583aba17bc7508ed163bf3515e4c10 (patch) | |
tree | 89822e02d6c1eaa17dd3e89181c939fef09c2167 /source/mod_student/constant_folding.ml | |
parent | Constant folding analysis (diff) |
Folding instructions
Diffstat (limited to 'source/mod_student/constant_folding.ml')
-rw-r--r-- | source/mod_student/constant_folding.ml | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/source/mod_student/constant_folding.ml b/source/mod_student/constant_folding.ml index 3bebcfa..bad5f80 100644 --- a/source/mod_student/constant_folding.ml +++ b/source/mod_student/constant_folding.ml @@ -1,5 +1,7 @@ open Xi_lib open Ir +open Ir_utils + module Make(T:Iface.COMPILER_TOOLBOX) = struct @@ -9,15 +11,32 @@ module Make(T:Iface.COMPILER_TOOLBOX) = struct end) = struct open M + open Analysis let cfa = T.ConstantFoldingAnalysis.analyse proc + let rewrite_instr (knwl,instr)= + let knwl = Knowledge.pre knwl in + let knwl = Ir.RegMap.fold (fun key v m -> + match v with + |None -> m + |Some v -> Ir.RegMap.add key (E_Int v) m) knwl Ir.RegMap.empty in + subst_expr_instr knwl instr + let rewrite_label l = + if l = (ControlFlowGraph.entry_label cfg) || l = (ControlFlowGraph.exit_label cfg) then () + else + match Hashtbl.find cfa l with + |Simple _ -> () + |Complex {body;_} -> ControlFlowGraph.set_block cfg l (List.map rewrite_instr body) + + let rewrite () = Logger.extra_debug begin fun () -> Logger.dump_constant_folding "before-optimization" cfg cfa; - end; - failwith "not yet implemeneted" - + end; + let labels = ControlFlowGraph.labels cfg in + List.iter rewrite_label labels + end @@ -28,4 +47,4 @@ module Make(T:Iface.COMPILER_TOOLBOX) = struct end) in Instance.rewrite () -end \ No newline at end of file +end |