SCM Repository
Annotation of /branches/vis15/src/compiler/high-opt/reorder.sml
Parent Directory
|
Revision Log
Revision 5241 - (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 : | jhr | 4317 | (* end case *)) |
33 : | jhr | 3515 | |
34 : | (* Does some simple ordering | ||
35 : | Scalars*Epsilons*deltas*else | ||
36 : | *) | ||
37 : | fun transform (Ein.EIN{params, index, body}) = let | ||
38 : | jhr | 4317 | 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 : | cchiw | 5241 | | E.Op3(op3, e1, e2, e3) => E.Op3(op3, order e1, order e2, order e3) |
53 : | jhr | 4317 | | E.Opn(E.Prod, es) => let |
54 : | val (s, eps, dels, p) = EinFilter.partitionGreek es | ||
55 : | val p' = List.map order p | ||
56 : | in | ||
57 : | E.Opn(E.Prod, s@eps@dels@p') | ||
58 : | end | ||
59 : | | E.Opn(opn, es) => E.Opn(opn, List.map order es) | ||
60 : | | _ => b | ||
61 : | (* end case *)) | ||
62 : | jhr | 3515 | (* iterate to a fixed point *) |
63 : | fun loop body = let | ||
64 : | jhr | 4317 | val body' = order body |
65 : | in | ||
66 : | jhr | 3515 | if !changed |
67 : | jhr | 4317 | then (changed := false; loop body') |
68 : | else body' | ||
69 : | end | ||
70 : | jhr | 3515 | val b = loop body |
71 : | (* QUESTION: I don't think that the following does anything, since we are at a fixed point! | ||
72 : | val b' = order b | ||
73 : | *) | ||
74 : | jhr | 4317 | in |
75 : | Ein.EIN{params=params, index=index, body=b} | ||
76 : | end | ||
77 : | jhr | 3515 | |
78 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |