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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/translate/analyze-simple.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/translate/analyze-simple.sml

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

revision 3840, Mon May 9 20:42:08 2016 UTC revision 4228, Mon Jul 18 22:07:47 2016 UTC
# Line 28  Line 28 
28    (* a property set on state variables that are read by other strands *)    (* a property set on state variables that are read by other strands *)
29      val sharedStateVar : SimpleVar.t -> bool      val sharedStateVar : SimpleVar.t -> bool
30    
31      (* a property set on top-level blocks that tracks the globals that are read in the block *)
32        val globalsOfBlock : Simple.block -> SimpleVar.Set.set
33    
34    end = struct    end = struct
35    
36      structure S = Simple      structure S = Simple
# Line 36  Line 39 
39      structure VSet = SV.Set      structure VSet = SV.Set
40    
41      datatype context      datatype context
42        = ConstInit | GlobalInit | StateInit        = ConstInit | UserFunc | GlobalInit | StateInit
43        | InitMeth | UpdateMeth | StabilizeMeth        | InitMeth | UpdateMeth | StabilizeMeth
44        | Create | GlobalUpdate        | Create | GlobalUpdate
45    
46      (* for debugging *)
47        fun cxtToString cxt = (case cxt
48               of ConstInit => "ConstInit"
49                | UserFunc => "UserFunc"
50                | GlobalInit => "GlobalInit"
51                | StateInit => "StateInit"
52                | InitMeth => "InitMeth"
53                | UpdateMeth => "UpdateMeth"
54                | StabilizeMeth => "StabilizeMeth"
55                | Create => "Create"
56                | GlobalUpdate => "GlobalUpdate"
57              (* end case *))
58    
59      local      local
60        val {getFn, setFn, ...} = S.newProp (fn _ => VSet.empty)        val {getFn, setFn, ...} = S.newProp (fn _ => VSet.empty)
61      in      in
# Line 89  Line 105 
105            (* end case *))            (* end case *))
106      end (* local *)      end (* local *)
107    
108        local
109          val {getFn, setFn, ...} =
110                PropList.newProp (fn (S.Block{props, ...}) => props, fn _ => VSet.empty)
111        in
112        val globalsOfBlock = getFn
113        val setGlobalsOfBlock = setFn
114        end (* local *)
115    
116      fun markUpdate (cxt, x) = (case (cxt, SV.kindOf x)      fun markUpdate (cxt, x) = (case (cxt, SV.kindOf x)
117             of (ConstInit, SV.ConstVar) => ()             of (ConstInit, SV.ConstVar) => ()
118              | (_, SV.ConstVar) => raise Fail "update of ConstVar"              | (_, SV.ConstVar) => raise Fail "update of ConstVar"
# Line 110  Line 134 
134              | _ => false              | _ => false
135            (* end case *))            (* end case *))
136    
137      fun addVar (x, vs) = if isLocal x then VSet.add(vs, x) else vs  (* FIXME: need to use context to filter out globals in some situations *)
138        fun analyzeBlock cxt blk = let
139              val globals = ref VSet.empty
140              fun addGlobal x = (globals := VSet.add(!globals, x))
141              fun addVar (x, vs) =
142                    if isLocal x then VSet.add(vs, x)
143                    else (case (SV.kindOf x, cxt)
144                       of (SV.ConstVar, ConstInit) => ()
145                        | (SV.ConstVar, _) => addGlobal x
146                        | (SV.InputVar, ConstInit) => ()
147                        | (SV.InputVar, _) => addGlobal x
148                        | (SV.GlobalVar, ConstInit) => ()
149                        | (SV.GlobalVar, GlobalInit) => ()
150                        | (SV.GlobalVar, _) => addGlobal x
151                        | _ => ()
152                      (* end case *);
153                      vs)
154      fun addList (xs, vs) = List.foldl addVar vs xs      fun addList (xs, vs) = List.foldl addVar vs xs
155            (* compute the used local and global variables of a Simple AST expression *)
   (* compute the used local variables of a Simple AST expression *)  
156      fun addUses (e, vs) = let      fun addUses (e, vs) = let
157            val u = (case e            val u = (case e
158                   of S.E_Var x => [x]                   of S.E_Var x => [x]
159                    | S.E_Lit _ => []                    | S.E_Lit _ => []
160                            | S.E_Kernel _ => []
161                    | S.E_Select _ => raise Fail "unexpected E_Select" (* should be handled by doStm *)                    | S.E_Select _ => raise Fail "unexpected E_Select" (* should be handled by doStm *)
162                    | S.E_Apply _ => raise Fail "unexpected E_Apply"                          | S.E_Apply(_, xs) => xs
163                    | S.E_Prim(_, _, xs, _) => xs                    | S.E_Prim(_, _, xs, _) => xs
164                    | S.E_Tensor(xs, _) => xs                    | S.E_Tensor(xs, _) => xs
165                    | S.E_Seq(xs, _) => xs                    | S.E_Seq(xs, _) => xs
166                    | S.E_Slice(x, _, _) => [x]                    | S.E_Slice(x, _, _) => [x]
167                    | S.E_Coerce{x, ...} => [x]                    | S.E_Coerce{x, ...} => [x]
168                            | S.E_BorderCtl(BorderCtl.Default x, y) => [x, y]
169                            | S.E_BorderCtl(_, x) => [x]
170                    | S.E_LoadSeq _ => []                    | S.E_LoadSeq _ => []
171                    | S.E_LoadImage _ => []                    | S.E_LoadImage _ => []
172                            | S.E_InsideImage(pos, img, _) => [pos, img]
173                  (* end case *))                  (* end case *))
174            in            in
175              addList (u, vs)              addList (u, vs)
176            end            end
   
     fun analyzeBlock cxt blk = let  
177            fun doBlock (blk as S.Block{code, ...}, liveIn) = let            fun doBlock (blk as S.Block{code, ...}, liveIn) = let
178                  val result as (liveOut, assigns) = List.foldr doStm (liveIn, VSet.empty) code                  val result as (liveOut, assigns) = List.foldr doStm (liveIn, VSet.empty) code
179                  in                  in
# Line 161  Line 201 
201  (* QUESTION: do we want to modify the properties of b? *)  (* QUESTION: do we want to modify the properties of b? *)
202                    (liveOut, assigns)                    (liveOut, assigns)
203                  end                  end
204              | doStm (S.S_IfThenElse(_, b1, b2), (liveIn, assignsIn)) = let              | doStm (S.S_IfThenElse(x, b1, b2), (liveIn, assignsIn)) = let
205                    val liveIn = addVar(x, liveIn)
206                  val (live1, assigns1) = doBlock (b1, liveIn)                  val (live1, assigns1) = doBlock (b1, liveIn)
207                  val (live2, assigns2) = doBlock (b2, liveIn)                  val (live2, assigns2) = doBlock (b2, liveIn)
208                  val assigns = VSet.union(assignsIn, VSet.union(assigns1, assigns2))                  val assigns = VSet.union(assignsIn, VSet.union(assigns1, assigns2))
# Line 176  Line 217 
217              | doStm (_, acc) = acc              | doStm (_, acc) = acc
218            val (bnd, assigns) = doBlock (blk, VSet.empty)            val (bnd, assigns) = doBlock (blk, VSet.empty)
219            in            in
220              ()              setGlobalsOfBlock (blk, !globals)
221            end            end
222    
223      fun analyze (S.Program{constInit, init, strand, create, update, ...}) = let      fun analyze (S.Program{constInit, funcs, globInit, strand, create, init, update, ...}) = let
224            val S.Strand{stateInit, initM, updateM, stabilizeM, ...} = strand            val S.Strand{stateInit, initM, updateM, stabilizeM, ...} = strand
           val S.Create{code, ...} = create  
225            in            in
226              analyzeBlock ConstInit constInit;              analyzeBlock ConstInit constInit;
227              analyzeBlock GlobalInit init;              List.app (fn (S.Func{f, body, ...}) => analyzeBlock UserFunc body) funcs;
228                analyzeBlock GlobalInit globInit;
229              analyzeBlock StateInit stateInit;              analyzeBlock StateInit stateInit;
230              Option.app (analyzeBlock InitMeth) initM;              Option.app (analyzeBlock InitMeth) initM;
231              analyzeBlock UpdateMeth updateM;              analyzeBlock UpdateMeth updateM;
232              Option.app (analyzeBlock StabilizeMeth) stabilizeM;              Option.app (analyzeBlock StabilizeMeth) stabilizeM;
233              analyzeBlock Create code;              Create.app (analyzeBlock Create) create;
234                Option.app (analyzeBlock GlobalUpdate) init;
235              Option.app (analyzeBlock GlobalUpdate) update              Option.app (analyzeBlock GlobalUpdate) update
236            end            end
237    

Legend:
Removed from v.3840  
changed lines
  Added in v.4228

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