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

SCM Repository

[diderot] Annotation of /trunk/src/compiler/high-il/high-opt.sml
ViewVC logotype

Annotation of /trunk/src/compiler/high-il/high-opt.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 287 - (view) (download)

1 : jhr 287 (* high-opt.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Optimization of the HighIL representation of Diderot terms. The main
7 :     * task of this phase is to statically resolve field definitions.
8 :     *)
9 :    
10 :     structure HighOptimizer : sig
11 :    
12 :     val optimize : HighIL.program -> HighIL.program
13 :    
14 :     end = struct
15 :    
16 :     structure IL = HighIL
17 :     structure Op = IL.Op
18 :     structure V = IL.Var
19 :    
20 :     datatype binding
21 :     = Unknown
22 :     | OP of Op.rator * IL.var list
23 :    
24 :     (* decrement a variable's use count *)
25 :     fun decUse (IL.V{useCnt, ...}) = (useCnt := !useCnt - 1)
26 :    
27 :     val {getFn=getBinding, setFn=setBinding, clrFn=clrBinding, ...}
28 :     = V.newProp (fn _ => Unknown)
29 :    
30 :     (* optimize the rhs of an assignment, returning NONE if there is no change *)
31 :     fun doAssignment rhs = (case rhs
32 :     of IL.OP(Op.Convolve, [v, h]) => (case (getBinding v, getBinding h)
33 :     of ((Op.LoadImage v', []), (Op.Kernel h', [])) => (
34 :     decUse v; decUse h;
35 :     SOME(IL.Op(Op.Field(F.convolve(v', h')), [])))
36 :     | _ => raise Fail "non-constant Convolve"
37 :     (* end case *))
38 :     | IL.OP(Op.AddField, [f, g]) => (case (getBinding f, getBinding g)
39 :     of ((Op.Field f', []), (Op.Field g', [])) => (
40 :     decUse f; decUse g;
41 :     SOME(IL.Op(Op.Field(F.SUM(f, g)), [])))
42 :     | _ => NONE
43 :     (* end case *))
44 :     | IL.OP(Op.NegField, [f]) => (case (getBinding f)
45 :     of (Op.Field f', []) => (
46 :     decUse f';
47 :     SOME(IL.Op(Op.Field(F.neg f'), [])))
48 :     | _ => NONE
49 :     (* end case *))
50 :     | IL.OP(Op.DiffField, [f]) => (case (getBinding f)
51 :     of (Op.Field f', []) => (
52 :     decUse f';
53 :     SOME(IL.Op(Op.Field(F.diff f'), [])))
54 :     | _ => raise Fail "non-constant DiffField"
55 :     (* end case *))
56 :     | _ => NONE
57 :     (* end case *))
58 :    
59 :     end

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