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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/high-opt/reorder.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/high-opt/reorder.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3520 - (view) (download)

1 : jhr 3515 (* reorder.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 :     * All rights reserved.
7 :     *)
8 :    
9 :     structure Reorder : sig
10 :    
11 :     (* Reorders the subexpressions in an Ein Function after substitution *)
12 :     val transform : Ein.ein -> Ein.ein
13 :    
14 :     end = struct
15 :    
16 :     structure E = Ein
17 :    
18 :     (* rewriteProd : ein_exp list ->ein_exp*)
19 :     fun rewriteProd [e] = e
20 :     | rewriteProd exps = E.Opn(E.Prod, exps)
21 :    
22 :     (* rewriteProd : ein_exp * ein_exp list ->ein_exp*)
23 :     fun rewriteApply (c, p) = E.Apply(c, rewriteProd p)
24 :    
25 :     (* pushApply:ein_exp * ein_exp list ->int* ein_exp
26 :     * Moves non-field expression outside of apply
27 :     *)
28 : jhr 3520 fun pushApply (del, p) = (case EinFilter.partitionField p
29 : jhr 3515 of ([], []) => raise Fail "No Field in Apply expression"
30 :     | ([], post) => (false, rewriteApply(del, post))
31 :     | (pre, post) => (true, rewriteProd(pre@[rewriteApply(del, post)]))
32 :     (* end case *))
33 :    
34 :     (* Does some simple ordering
35 :     Scalars*Epsilons*deltas*else
36 :     *)
37 :     fun transform (Ein.EIN{params, index, body}) = let
38 :     val changed = ref false
39 :     fun order b = (case b
40 :     of E.Lift e => E.Lift(order e)
41 :     | E.Apply(e1, E.Opn(E.Prod, e2)) => let
42 :     val (change, e') = pushApply(e1, e2)
43 :     in
44 :     if change then changed := true else ();
45 :     e'
46 :     end
47 :     | E.Probe(e1, e2) => E.Probe(order e1, order e2)
48 :     | E.Sum(c1,E.Sum(c2, e)) => (changed:=true;E.Sum(c1@c2,order e))
49 :     | E.Sum(c, e1) => E.Sum(c, order e1)
50 :     | E.Op1(op1, e1) => E.Op1(op1,order e1)
51 :     | E.Op2(op2, e1,e2) => E.Op2(op2,order e1,order e2)
52 :     | E.Opn(E.Prod, es) => let
53 : jhr 3520 val (s, eps, dels, p) = EinFilter.partitionGreek es
54 : jhr 3515 val p' = List.map order p
55 :     in
56 :     E.Opn(E.Prod, s@eps@dels@p')
57 :     end
58 :     | E.Opn(opn, es) => E.Opn(opn, List.map order es)
59 :     | _ => b
60 :     (* end case *))
61 :     (* iterate to a fixed point *)
62 :     fun loop body = let
63 :     val body' = order body
64 :     in
65 :     if !changed
66 :     then (changed := false; loop body')
67 :     else body'
68 :     end
69 :     val b = loop body
70 :     (* QUESTION: I don't think that the following does anything, since we are at a fixed point!
71 :     val b' = order b
72 :     *)
73 :     in
74 : jhr 3516 Ein.EIN{params=params, index=index, body=b}
75 : jhr 3515 end
76 :    
77 :     end

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