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

SCM Repository

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

Diff of /branches/vis15/src/compiler/high-opt/apply.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5569, Tue May 29 21:26:24 2018 UTC revision 5570, Wed May 30 22:09:45 2018 UTC
# Line 10  Line 10 
10    
11  structure Apply : sig  structure Apply : sig
12    
13      val apply : Ein.ein * int * Ein.ein -> Ein.ein option      val apply : Ein.ein * int * Ein.ein  * HighIR.var list * HighIR.var list -> Ein.ein option
14    
15    end = struct    end = struct
16    
# Line 35  Line 35 
35              | SOME j => j              | SOME j => j
36           (* end case *))           (* end case *))
37    
38      fun rewriteSubst (e, subId, mx, paramShift, sumShift) = let      fun rewriteSubst (e, subId, mx, paramShift, sumShift, newArgs, done) = let
39            fun insertIndex ([], _, dict, shift) = (dict, shift)            fun insertIndex ([], _, dict, shift) = (dict, shift)
40              | insertIndex (e::es, n, dict, _) = let              | insertIndex (e::es, n, dict, _) = let
41                  val shift = (case e of E.V ix => ix - n | E.C i => i - n)                  val shift = (case e of E.V ix => ix - n | E.C i => i - n)
# Line 56  Line 56 
56                    v                    v
57                  end                  end
58            fun mapSum l = List.map (fn (a, b, c) => (mapSingle a, b, c)) l            fun mapSum l = List.map (fn (a, b, c) => (mapSingle a, b, c)) l
59            fun mapParam id = mapId2(id, subId, 0)            fun mapParam id = let
60                    val vA = List.nth(newArgs, id)
61                    fun iter ([], _) = mapId2(id, subId, 0)
62                      | iter (e1::es, n) = if (HighIR.Var.same(e1, vA)) then n else iter(es, n+1)
63                    in
64                      iter (done@newArgs, 0)
65                    end
66            fun apply e = (case e            fun apply e = (case e
67                   of E.Const _ => e                   of E.Const _ => e
68                    | E.ConstR _ => e                    | E.ConstR _ => e
# Line 74  Line 80 
80                    | E.Value _ => raise Fail "expression before expand"                    | E.Value _ => raise Fail "expression before expand"
81                    | E.Img _ => raise Fail "expression before expand"                    | E.Img _ => raise Fail "expression before expand"
82                    | E.Krn _ => raise Fail "expression before expand"                    | E.Krn _ => raise Fail "expression before expand"
83                      | E.OField(E.CFExp es, e2,dx) => let
84                          val es =  List.map (fn (id, inputTy) => (mapParam id, inputTy)) es
85                          val e2 = apply e2
86                          val dx = apply dx
87                          in
88                            E.OField(E.CFExp es, e2,dx)
89                          end
90                    | E.Sum(c, esum) => E.Sum(mapSum c, apply esum)                    | E.Sum(c, esum) => E.Sum(mapSum c, apply esum)
91                    | E.Op1(op1, e1) => E.Op1(op1, apply e1)                    | E.Op1(op1, e1) => E.Op1(op1, apply e1)
92                    | E.Op2(op2, e1, e2) => E.Op2(op2, apply e1, apply e2)                    | E.Op2(op2, e1, e2) => E.Op2(op2, apply e1, apply e2)
# Line 103  Line 116 
116            end            end
117    
118    (* Looks for params id that match substitution *)    (* Looks for params id that match substitution *)
119      fun apply (e1 as E.EIN{params, index, body}, place, e2) = let      fun apply (e1 as E.EIN{params, index, body}, place, e2, newArgs, done) = let
120            val E.EIN{params=params2, index=index2, body=body2} = e2            val E.EIN{params=params2, index=index2, body=body2} = e2
121            val changed = ref false            val changed = ref false
122            val (params', origId, substId, paramShift) = rewriteParams(params, params2, place)            val (params', origId, substId, paramShift) = rewriteParams(params, params2, place)
# Line 115  Line 128 
128                      then if (length mx = length index2)                      then if (length mx = length index2)
129                        then (                        then (
130                          changed := true;                          changed := true;
131                          rewriteSubst (body2, substId, mx, paramShift, x))                          rewriteSubst (body2, substId, mx, paramShift, x, newArgs, done))
132                        else raise Fail "argument/parameter mismatch"                        else raise Fail "argument/parameter mismatch"
133                      else (case e                      else (case e
134                         of E.Tensor(id, mx) => E.Tensor(mapId(id, origId, 0), mx)                         of E.Tensor(id, mx) => E.Tensor(mapId(id, origId, 0), mx)
# Line 135  Line 148 
148                    | E.Value _ => raise Fail "expression before expand"                    | E.Value _ => raise Fail "expression before expand"
149                    | E.Img _ => raise Fail "expression before expand"                    | E.Img _ => raise Fail "expression before expand"
150                    | E.Krn _ => raise Fail "expression before expand"                    | E.Krn _ => raise Fail "expression before expand"
151                      | E.OField(E.CFExp es, e2, E.Partial alpha) => let
152                          val ps = List.map (fn (id, inputTy) => (mapId(id, origId, 0), inputTy)) es
153                          in
154                            E.OField(E.CFExp ps, apply e2, E.Partial alpha)
155                          end
156                      | E.Poly _ => raise Fail "expression before expand"
157                    | E.Sum(indices, esum) => let                    | E.Sum(indices, esum) => let
158                        val (ix, _, _) = List.last indices                        val (ix, _, _) = List.last indices
159                        in                        in

Legend:
Removed from v.5569  
changed lines
  Added in v.5570

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