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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/mid-to-low/mk-low-ir.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/mid-to-low/mk-low-ir.sml

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

revision 3648, Tue Feb 2 15:25:34 2016 UTC revision 3653, Tue Feb 2 22:50:44 2016 UTC
# Line 10  Line 10 
10    
11  structure MkLowIR : sig  structure MkLowIR : sig
12    
13      (* an environment that maps De Bruijn indices to their iteration-index value *)
14        type index_env = int IntRedBlackMap.map
15    
16    (* make "x := <int-literal>" *)    (* make "x := <int-literal>" *)
17      val intLit : AvailRHS.t * IntLit.t -> LowIR.var      val intLit : AvailRHS.t * IntLit.t -> LowIR.var
18    (* make "x := <real-literal>" *)    (* make "x := <real-literal>" *)
# Line 18  Line 21 
21      val intToRealLit : AvailRHS.t * int -> LowIR.var      val intToRealLit : AvailRHS.t * int -> LowIR.var
22    (* make "x := [args]" *)    (* make "x := [args]" *)
23      val cons : AvailRHS.t * int list * LowIR.var list -> LowIR.var      val cons : AvailRHS.t * int list * LowIR.var list -> LowIR.var
24      (* code for δ_{i,j} *)
25        val delta : AvailRHS.t * index_env * Ein.mu * Ein.mu -> LowIR.var
26      (* code for ε_{i,j} *)
27        val epsilon2 : AvailRHS.t * index_env * Ein.index_id * Ein.index_id -> LowIR.var
28      (* code for ε_{i,j,k} *)
29        val epsilon3 : AvailRHS.t * index_env * Ein.index_id * Ein.index_id * Ein.index_id -> LowIR.var
30    
31      (* evaluate δ_{i,j} *)
32        val evalDelta : index_env * Ein.mu * Ein.mu -> int
33    
34    end = struct    end = struct
35    
# Line 25  Line 37 
37      structure V = IR.Var      structure V = IR.Var
38      structure Ty = LowTypes      structure Ty = LowTypes
39      structure Op = LowOps      structure Op = LowOps
40        structure E = Ein
41        structure IMap = IntRedBlackMap
42    
43      (* an environment that maps De Bruijn indices to their iteration-index value *)
44        type index_env = int IMap.map
45    
46      fun mk (avail, name, ty, rhs) = let      fun mk (avail, name, ty, rhs) = let
47            val lhs = V.new (name, ty)            val lhs = V.new (name, ty)
# Line 37  Line 54 
54      fun intToRealLit (avail, n) = realLit (avail, RealLit.fromInt(IntInf.fromInt n))      fun intToRealLit (avail, n) = realLit (avail, RealLit.fromInt(IntInf.fromInt n))
55      fun cons (avail, shp, args) = mk (avail, "tensor", Ty.TensorTy shp, IR.CONS(args, Ty.TensorTy shp))      fun cons (avail, shp, args) = mk (avail, "tensor", Ty.TensorTy shp, IR.CONS(args, Ty.TensorTy shp))
56    
57        local
58          fun lookupMu (mapp, E.V id) = (case IMap.find (mapp, id)
59                 of SOME n => n
60                  | NONE => raise Fail(concat["lookupMu(_, V ", Int.toString id, "): out of bounds"])
61                (* end case *))
62            | lookupMu (_, E.C i) = i
63          fun lookupIdx (mapp, id) = (case IMap.find(mapp, id)
64                 of SOME x => x
65                  | NONE => raise Fail(concat["lookupIdx(_, V ", Int.toString id, "): out of bounds"])
66                (* end case *))
67        in
68        fun evalDelta (mapp, i, j) = let
69              val i' = lookupMu (mapp, i)
70              val j' = lookupMu (mapp, j)
71              in
72                if (i' = j') then 1 else 0
73              end
74    
75        fun delta (avail, mapp, i, j) = intToRealLit (avail, evalDelta (mapp, i, j))
76    
77        fun epsilon2 (avail, mapp, i, j) = let
78              val i' = lookupIdx (mapp, i)
79              val j' = lookupIdx (mapp, j)
80              in
81                if (i' = j')
82                  then intToRealLit (avail, 0)
83                else if (j' > i')
84                  then intToRealLit (avail, 1)
85                  else intToRealLit (avail, ~1)
86              end
87    
88        fun epsilon3 (avail, mapp, i, j, k) = let
89              val i' = lookupIdx (mapp, i)
90              val j' = lookupIdx (mapp, j)
91              val k' = lookupIdx (mapp, k)
92              in
93                if (i' = j' orelse j' = k' orelse i' = k')
94                  then intToRealLit (avail, 0)
95                else if (j' > i')
96                  then if (j' > k' andalso k' > i')
97                    then intToRealLit (avail, ~1)
98                    else intToRealLit (avail, 1)
99                else if (i' > k' andalso k' > j')
100                  then intToRealLit (avail, 1)
101                  else intToRealLit (avail, ~1)
102              end
103    
104        end (* local *)
105    
106    end    end

Legend:
Removed from v.3648  
changed lines
  Added in v.3653

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