Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/pure-cfg/src/compiler/mid-il/mid-opt.sml
ViewVC logotype

Annotation of /branches/pure-cfg/src/compiler/mid-il/mid-opt.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

1 : jhr 1036 (* mid-opt.sml
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 1036 * All rights reserved.
7 :     *)
8 :    
9 :     structure MidOptimizer : sig
10 :    
11 : jhr 1202 val controls : (string * bool ref * string) list
12 : jhr 1160
13 : jhr 1036 val optimize : MidIL.program -> MidIL.program
14 :    
15 :     end = struct
16 :    
17 : jhr 1153 (* Value numbering for MidIL *)
18 :     structure VN = ValueNumberingFn (DomTreeFn(MidIL))
19 :    
20 : jhr 1556 val contractFlag = ref true (* controls contraction *)
21 : jhr 1160 val vnFlag = ref true (* controls value numbering *)
22 :     val debugFlag = ref true (* controls printing *)
23 :     val checkFlag = ref true (* controls IL checking *)
24 :    
25 :     val controls = [
26 : jhr 1556 ("mid-contract", contractFlag, "enable contraction for MidIL"),
27 : jhr 1202 ("mid-vn", vnFlag, "enable value-numbering for MidIL"),
28 :     ("mid-debug", debugFlag, "enable printing MidIL to log file [debug]"),
29 :     ("mid-check", checkFlag, "enable consistency checking for MidIL [debug]")
30 : jhr 1160 ]
31 :    
32 : jhr 1498 fun checkIL (phase, prog) =
33 :     if !checkFlag andalso CheckMidIL.check ("after " ^ phase, prog)
34 : jhr 1160 then (
35 :     TextIO.output(TextIO.stdErr, concat[
36 :     "***** Internal error after ", phase,
37 :     ": see log file for details\n"
38 :     ]);
39 : jhr 1504 MidPP.output (Log.logFile(), "MidIL after " ^ phase, prog);
40 : jhr 1160 OS.Process.exit OS.Process.failure)
41 : jhr 1498 else if !debugFlag
42 :     then (
43 :     MidPP.output (Log.logFile(), "MidIL after " ^ phase, prog);
44 :     prog)
45 :     else prog
46 : jhr 1160
47 :     fun transform (ctl, phase, transform, prog) =
48 :     if !ctl
49 : jhr 1546 then checkIL (phase, transform prog)
50 : jhr 1160 else prog
51 :    
52 : jhr 1153 fun optimize prog = let
53 : jhr 1160 val prog = transform (vnFlag, "value numbering", VN.transform, prog)
54 : jhr 1556 val prog = transform (contractFlag, "contraction", MidContract.transform, prog)
55 : jhr 1153 in
56 :     prog
57 :     end
58 : jhr 1036
59 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0