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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/mid-to-low/ein-to-scalar.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/mid-to-low/ein-to-scalar.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3666 - (view) (download)

1 : jhr 3646 (* ein-to-scalar.sml
2 :     *
3 :     * Generate LowIR scalar computations that implement Ein expressions.
4 :     *
5 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
6 :     *
7 :     * COPYRIGHT (c) 2016 The University of Chicago
8 :     * All rights reserved.
9 :     *)
10 :    
11 :     structure EinToScalar : sig
12 :    
13 : jhr 3648 val expand :
14 : jhr 3653 AvailRHS.t * int IntRedBlackMap.map * (Ein.param_kind list * Ein.ein_exp * LowIR.var list)
15 :     -> LowIR.var
16 : jhr 3646
17 :     end = struct
18 :    
19 :     structure IR = LowIR
20 :     structure Ty = LowTypes
21 :     structure Op = LowOps
22 :     structure Var = LowIR.Var
23 :     structure E = Ein
24 : jhr 3648 structure Mk = MkLowIR
25 : jhr 3646 structure IMap = IntRedBlackMap
26 :    
27 : jhr 3653 fun mapIndex (mapp, id) = (case IMap.find(mapp, id)
28 : jhr 3649 of SOME x => x
29 :     | NONE => raise Fail(concat["mapIndex(_, V ", Int.toString id, "): out of bounds"])
30 :     (* end case *))
31 :    
32 : jhr 3666 (* FIXME: we probably do not need the params (depending on how we implement FieldToLow.expand *)
33 : jhr 3648 fun expand (avail, mapp, (params, body, args)) = let
34 : jhr 3653 fun gen (mapp, body) = let
35 :     (*********sumexpression ********)
36 :     fun tb n = List.tabulate (n, fn e => e)
37 :     fun sumCheck (mapp, (E.V v, lb, ub) :: sumx, e) = let
38 :     fun sumloop mapp = gen (mapp, e)
39 :     fun sumI1 (left, (v, [i], lb1), [], rest) = let
40 :     val mapp = IMap.insert (mapp, v, lb1+i)
41 :     val vD = gen (mapp, e)
42 :     in
43 :     rest@[vD]
44 :     end
45 :     | sumI1 (left, (v, i::es, lb1), [], rest) = let
46 :     val mapp = IMap.insert (left, v, i+lb1)
47 :     val vD = gen (mapp, e)
48 :     in
49 :     sumI1 (mapp, (v, es, lb1), [], rest@[vD])
50 :     end
51 :     | sumI1 (left, (v, [i], lb1), (E.V a, lb2, ub2) ::sx, rest) =
52 :     sumI1 (IMap.insert (left, v, lb1+i), (a, tb (ub2-lb2+1), lb2), sx, rest)
53 :     | sumI1 (left, (v, s::es, lb1), (E.V a, lb2, ub2) ::sx, rest) = let
54 :     val mapp = IMap.insert (left, v, s+lb1)
55 :     val xx = tb (ub2-lb2+1)
56 :     val rest' = sumI1 (mapp, (a, xx, lb2), sx, rest)
57 :     in
58 :     sumI1 (mapp, (v, es, lb1), (E.V a, lb2, ub2) ::sx, rest')
59 :     end
60 :     | sumI1 _ = raise Fail "None Variable-index in summation"
61 :     in
62 :     sumI1 (mapp, (v, tb (ub-lb+1), lb), sumx, [])
63 :     end
64 :     in
65 :     case body
66 :     of E.Value v => Mk.intToRealLit (avail, mapIndex (mapp, v))
67 :     | E.Const c => Mk.intToRealLit (avail, c)
68 :     | E.Delta(i, j) => Mk.delta (avail, mapp, i, j)
69 :     | E.Epsilon(i, j, k) => Mk.epsilon3 (avail, mapp, i, j, k)
70 :     | E.Eps2(i, j) => Mk.epsilon2 (avail, mapp, i, j)
71 : jhr 3665 | E.Tensor(id, ix) => Mk.tensorIndex (avail, mapp, List.nth(args, id), ix)
72 :     | E.Op1(op1, e1) => let
73 :     val arg = gen (mapp, e1)
74 :     in
75 :     case op1
76 :     of E.Neg => Mk.realNeg (avail, arg)
77 :     | _ => raise Fail "FIXME: unimplemented"
78 :     (*
79 :     | E.Exp
80 :     | E.Sqrt
81 :     | E.Cosine
82 :     | E.ArcCosine
83 :     | E.Sine
84 :     | E.ArcSine
85 :     | E.Tangent
86 :     | E.ArcTangent
87 :     | E.PowInt of int
88 :     | E.PowReal of Rational.t
89 :     | E.PowEmb of sumrange list * int
90 :     *)
91 :     (* end case *)
92 :     end
93 : jhr 3661 | E.Op2(E.Sub, e1, e2) => Mk.realSub (avail, gen (mapp, e1), gen (mapp, e2))
94 :     | E.Opn(E.Add, es) =>
95 :     Mk.reduce (avail, Mk.realAdd, List.map (fn e => gen(mapp, e)) es)
96 :     | E.Opn(E.Prod, es) =>
97 :     Mk.reduce (avail, Mk.realMul, List.map (fn e => gen(mapp, e)) es)
98 : jhr 3653 | E.Op2(E.Div, e1 as E.Tensor (_, [_]), e2 as E.Tensor (_, [])) =>
99 :     gen (mapp, E.Opn(E.Prod, [E.Op2 (E.Div, E.Const 1, e2), e1]))
100 : jhr 3661 | E.Op2(E.Div, e1, e2) => Mk.realDiv (avail, gen (mapp, e1), gen (mapp, e2))
101 : jhr 3665 | E.Sum(x, E.Opn (E.Prod, (E.Img (Vid, _, _) :: E.Krn (Hid, _, _) ::_))) =>
102 :     (*
103 : jhr 3653 FieldToLow.expand (avail, mapp, params, body, args)
104 : jhr 3665 *)
105 :     raise Fail "FIXME: unimplemented"
106 : jhr 3661 | E.Sum(sumx, e) =>
107 :     Mk.reduce (avail, Mk.realAdd, sumCheck (mapp, sumx, e))
108 : jhr 3653 | _ => raise Fail("unsupported ein-exp: " ^ EinPP.expToString body)
109 :     (*end case*)
110 :     end
111 :     in
112 :     gen (mapp, body)
113 :     end
114 : jhr 3646
115 :     end

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