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

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/high-il/normalize.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/high-il/normalize.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2502 - (view) (download)

1 : jhr 1232 (* normalize.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure Normalize : sig
8 :    
9 :     val transform : HighIL.program -> HighIL.program
10 :    
11 :     end = struct
12 :    
13 :     structure IL = HighIL
14 :     structure Op = HighOps
15 :     structure V = IL.Var
16 : jhr 2356 structure Ty = HighILTypes
17 : jhr 1232 structure ST = Stats
18 : cchiw 2400 structure NE = NormalizeEin
19 : cchiw 2499 structure P=Printer
20 : cchiw 2502 structure mk=mkOperators
21 : jhr 1232
22 : cchiw 2400 (********** Counters for statistics **********)
23 : jhr 2356 val cntInsideScale = ST.newCounter "high-opt:inside-scale"
24 :     val cntInsideOffset = ST.newCounter "high-opt:inside-offset"
25 :     val cntInsideNeg = ST.newCounter "high-opt:inside-meg"
26 :     val cntInsideCurl = ST.newCounter "high-opt:inside-curl"
27 :     val cntInsideDiff = ST.newCounter "high-opt:inside-diff"
28 :     val cntProbeAdd = ST.newCounter "high-opt:probe-add"
29 :     val cntProbeSub = ST.newCounter "high-opt:probe-sub"
30 :     val cntProbeScale = ST.newCounter "high-opt:probe-scale"
31 :     val cntProbeOffset = ST.newCounter "high-opt:probe-offset"
32 :     val cntProbeNeg = ST.newCounter "high-opt:probe-neg"
33 :     val cntProbeCurl = ST.newCounter "high-opt:probe-curl"
34 :     val cntDiffField = ST.newCounter "high-opt:diff-field"
35 :     val cntDiffAdd = ST.newCounter "high-opt:diff-add"
36 :     val cntDiffScale = ST.newCounter "high-opt:diff-scale"
37 :     val cntDiffOffset = ST.newCounter "high-opt:diff-offset"
38 :     val cntDiffNeg = ST.newCounter "high-opt:diff-neg"
39 :     val cntCurlScale = ST.newCounter "high-opt:curl-scale"
40 :     val cntCurlNeg = ST.newCounter "high-opt:curl-neg"
41 :     val cntUnused = ST.newCounter "high-opt:unused"
42 :     val firstCounter = cntInsideScale
43 : jhr 1232 val lastCounter = cntUnused
44 :    
45 :     structure UnusedElim = UnusedElimFn (
46 : jhr 2356 structure IL = IL
47 :     val cntUnused = cntUnused)
48 : jhr 1232
49 :     fun useCount (IL.V{useCnt, ...}) = !useCnt
50 :    
51 :     (* adjust a variable's use count *)
52 :     fun incUse (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1)
53 :     fun decUse (IL.V{useCnt, ...}) = (useCnt := !useCnt - 1)
54 : jhr 2356 fun use x = (incUse x; x)
55 : jhr 1232
56 :     fun getRHS x = (case V.binding x
57 : jhr 2356 of IL.VB_RHS(IL.OP arg) => SOME arg
58 :     | IL.VB_RHS(IL.VAR x') => getRHS x'
59 : cchiw 2502 (* | IL.VB_RHS(IL.EINAPP (e,arg))=> SOME (arg)*)
60 : jhr 2356 | _ => NONE
61 :     (* end case *))
62 : jhr 1232
63 : jhr 2356 (* get the binding of a kernel variable *)
64 :     fun getKernelRHS h = (case getRHS h
65 :     of SOME(Op.Kernel(kernel, k), []) => (kernel, k)
66 :     | _ => raise Fail(concat[
67 :     "bogus kernel binding ", V.toString h, " = ", IL.vbToString(V.binding h)
68 :     ])
69 :     (* end case *))
70 :    
71 : jhr 1232 (* optimize the rhs of an assignment, returning NONE if there is no change *)
72 : cchiw 2445
73 : cchiw 2502 (*args are vars, how do I find if an einapp applied to an einapp?*)
74 :     (*where to add type checker*)
75 :     fun doRHS (lhs, IL.EINAPP (ein, args))=let
76 :     val (n,change)=NE.normalize(ein)
77 :     in (case change
78 :     of 0 => NONE
79 :     | _ => let
80 :     val str=String.concat [P.printerE(ein), "=>",P.printerE(n)]
81 :     val p=print str
82 :     in SOME[(lhs, IL.EINAPP(n, args))]
83 :     end)
84 :     end
85 : cchiw 2400
86 : cchiw 2502 (*how do I tell if an arg here is an einAPP, then we we can rewrite einapps*)
87 :    
88 : cchiw 2496 (*
89 : cchiw 2445 | doRHS (lhs, IL.OP rhs) = (case rhs
90 : jhr 2356 of (Op.Inside dim, [pos, f]) => (case getRHS f
91 : cchiw 2445 of SOME(Op.Field _, _) => NONE (* direct inside test does not need rewrite
92 : jhr 2356 | SOME(Op.OffsetField, [f', _]) => (
93 :     ST.tick cntInsideOffset;
94 :     decUse f;
95 : cchiw 2445 SOME[(lhs, IL.OP(Op.Inside dim, [pos, use f']))])*)
96 : jhr 2356 | _ => raise Fail(concat[
97 :     "inside: bogus field binding ", V.toString f, " = ", IL.vbToString(V.binding f)
98 :     ])
99 : cchiw 2445 (* end case *))
100 : jhr 2356 | _ => NONE
101 :     (* end case *))
102 : jhr 1232
103 : cchiw 2400 *)
104 : cchiw 2496 | doRHS _ = NONE
105 : cchiw 2400
106 :    
107 : cchiw 2496
108 : jhr 2356 structure Rewrite = RewriteFn (
109 :     struct
110 :     structure IL = IL
111 :     val doAssign = doRHS
112 :     fun doMAssign _ = NONE
113 :     val elimUnusedVars = UnusedElim.reduce
114 :     end)
115 : jhr 1232
116 : jhr 2356 val transform = Rewrite.transform
117 : jhr 1232
118 :     end

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