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 2400 - (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 : jhr 1232
20 : cchiw 2400 (********** Counters for statistics **********)
21 : jhr 2356 val cntInsideScale = ST.newCounter "high-opt:inside-scale"
22 :     val cntInsideOffset = ST.newCounter "high-opt:inside-offset"
23 :     val cntInsideNeg = ST.newCounter "high-opt:inside-meg"
24 :     val cntInsideCurl = ST.newCounter "high-opt:inside-curl"
25 :     val cntInsideDiff = ST.newCounter "high-opt:inside-diff"
26 :     val cntProbeAdd = ST.newCounter "high-opt:probe-add"
27 :     val cntProbeSub = ST.newCounter "high-opt:probe-sub"
28 :     val cntProbeScale = ST.newCounter "high-opt:probe-scale"
29 :     val cntProbeOffset = ST.newCounter "high-opt:probe-offset"
30 :     val cntProbeNeg = ST.newCounter "high-opt:probe-neg"
31 :     val cntProbeCurl = ST.newCounter "high-opt:probe-curl"
32 :     val cntDiffField = ST.newCounter "high-opt:diff-field"
33 :     val cntDiffAdd = ST.newCounter "high-opt:diff-add"
34 :     val cntDiffScale = ST.newCounter "high-opt:diff-scale"
35 :     val cntDiffOffset = ST.newCounter "high-opt:diff-offset"
36 :     val cntDiffNeg = ST.newCounter "high-opt:diff-neg"
37 :     val cntCurlScale = ST.newCounter "high-opt:curl-scale"
38 :     val cntCurlNeg = ST.newCounter "high-opt:curl-neg"
39 :     val cntUnused = ST.newCounter "high-opt:unused"
40 :     val firstCounter = cntInsideScale
41 : jhr 1232 val lastCounter = cntUnused
42 :    
43 :     structure UnusedElim = UnusedElimFn (
44 : jhr 2356 structure IL = IL
45 :     val cntUnused = cntUnused)
46 : jhr 1232
47 :     fun useCount (IL.V{useCnt, ...}) = !useCnt
48 :    
49 :     (* adjust a variable's use count *)
50 :     fun incUse (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1)
51 :     fun decUse (IL.V{useCnt, ...}) = (useCnt := !useCnt - 1)
52 : jhr 2356 fun use x = (incUse x; x)
53 : jhr 1232
54 :     fun getRHS x = (case V.binding x
55 : jhr 2356 of IL.VB_RHS(IL.OP arg) => SOME arg
56 :     | IL.VB_RHS(IL.VAR x') => getRHS x'
57 : cchiw 2400 | IL.VB_RHS(IL.EINAPP arg)=> SOME arg
58 : jhr 2356 | _ => NONE
59 :     (* end case *))
60 : jhr 1232
61 : jhr 2356 (* get the binding of a kernel variable *)
62 :     fun getKernelRHS h = (case getRHS h
63 :     of SOME(Op.Kernel(kernel, k), []) => (kernel, k)
64 :     | _ => raise Fail(concat[
65 :     "bogus kernel binding ", V.toString h, " = ", IL.vbToString(V.binding h)
66 :     ])
67 :     (* end case *))
68 :    
69 : jhr 1232 (* optimize the rhs of an assignment, returning NONE if there is no change *)
70 : cchiw 2400 fun doRHS (lhs, IL.EINAPP (ein, args))=
71 :     SOME[(lhs, IL.EINAPP(NE.normalize(ein), args))]
72 :    
73 :     | doRHS (lhs, IL.OP rhs) = (case rhs
74 : jhr 2356 of (Op.Inside dim, [pos, f]) => (case getRHS f
75 :     of SOME(Op.Field _, _) => NONE (* direct inside test does not need rewrite *)
76 :     | SOME(Op.OffsetField, [f', _]) => (
77 :     ST.tick cntInsideOffset;
78 :     decUse f;
79 :     SOME[(lhs, IL.OP(Op.Inside dim, [pos, use f']))])
80 :     | _ => raise Fail(concat[
81 :     "inside: bogus field binding ", V.toString f, " = ", IL.vbToString(V.binding f)
82 :     ])
83 :     (* end case *))
84 :     | _ => NONE
85 :     (* end case *))
86 :     | doRHS _ = NONE
87 : jhr 1232
88 : cchiw 2400
89 :     (* (*deleted addfield, subfield, scalefield, negfield, curlfield, and difffield*)
90 :     -deleted probe field of Field, addfield, subfield, scalefield OffsetField, negfield, curl, diffield
91 :     -deleted diffield of field, addfield, subfield, scalefield, offsetfield
92 :     negfield
93 :     -deleted curlfield, ...
94 :     *)
95 :    
96 :    
97 : jhr 2356 structure Rewrite = RewriteFn (
98 :     struct
99 :     structure IL = IL
100 :     val doAssign = doRHS
101 :     fun doMAssign _ = NONE
102 :     val elimUnusedVars = UnusedElim.reduce
103 :     end)
104 : jhr 1232
105 : jhr 2356 val transform = Rewrite.transform
106 : jhr 1232
107 :     end

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