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 4164, Thu Jul 7 12:56:59 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 89  Line 92 
92            (* end case *))            (* end case *))
93      end (* local *)      end (* local *)
94    
95        local
96          val {getFn, setFn, ...} =
97                PropList.newProp (fn (S.Block{props, ...}) => props, fn _ => VSet.empty)
98        in
99        val globalsOfBlock = getFn
100        val setGlobalsOfBlock = setFn
101        end (* local *)
102    
103      fun markUpdate (cxt, x) = (case (cxt, SV.kindOf x)      fun markUpdate (cxt, x) = (case (cxt, SV.kindOf x)
104             of (ConstInit, SV.ConstVar) => ()             of (ConstInit, SV.ConstVar) => ()
105              | (_, SV.ConstVar) => raise Fail "update of ConstVar"              | (_, SV.ConstVar) => raise Fail "update of ConstVar"
# Line 114  Line 125 
125    
126      fun addList (xs, vs) = List.foldl addVar vs xs      fun addList (xs, vs) = List.foldl addVar vs xs
127    
128    (* compute the used local variables of a Simple AST expression *)  (* FIXME: need to use context to filter out globals in some situations *)
129        fun analyzeBlock cxt blk = let
130              val globals = ref VSet.empty
131            (* compute the used local and global variables of a Simple AST expression *)
132      fun addUses (e, vs) = let      fun addUses (e, vs) = let
133            val u = (case e            val u = (case e
134                   of S.E_Var x => [x]                   of S.E_Var x => [x]
135                    | S.E_Lit _ => []                    | S.E_Lit _ => []
136                            | S.E_Kernel _ => []
137                    | 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 *)
138                    | S.E_Apply _ => raise Fail "unexpected E_Apply"                          | S.E_Apply(_, xs) => xs
139                    | S.E_Prim(_, _, xs, _) => xs                    | S.E_Prim(_, _, xs, _) => xs
140                    | S.E_Tensor(xs, _) => xs                    | S.E_Tensor(xs, _) => xs
141                    | S.E_Seq(xs, _) => xs                    | S.E_Seq(xs, _) => xs
# Line 128  Line 143 
143                    | S.E_Coerce{x, ...} => [x]                    | S.E_Coerce{x, ...} => [x]
144                    | S.E_LoadSeq _ => []                    | S.E_LoadSeq _ => []
145                    | S.E_LoadImage _ => []                    | S.E_LoadImage _ => []
146                            | S.E_InsideImage(pos, img, _) => [pos, img]
147                  (* end case *))                  (* end case *))
148            in            in
149              addList (u, vs)                    case List.partition SV.isGlobal u
150                       of ([], []) => vs
151                        | (gvs, []) => (globals := addList (gvs, !globals); vs)
152                        | ([], u) => addList (u, vs)
153                        | (gvs, u) => (globals := addList (gvs, !globals); addList (u, vs))
154                      (* end case *)
155            end            end
   
     fun analyzeBlock cxt blk = let  
156            fun doBlock (blk as S.Block{code, ...}, liveIn) = let            fun doBlock (blk as S.Block{code, ...}, liveIn) = let
157                  val result as (liveOut, assigns) = List.foldr doStm (liveIn, VSet.empty) code                  val result as (liveOut, assigns) = List.foldr doStm (liveIn, VSet.empty) code
158                  in                  in
# Line 176  Line 195 
195              | doStm (_, acc) = acc              | doStm (_, acc) = acc
196            val (bnd, assigns) = doBlock (blk, VSet.empty)            val (bnd, assigns) = doBlock (blk, VSet.empty)
197            in            in
198              ()              setGlobalsOfBlock (blk, !globals)
199            end            end
200    
201      fun analyze (S.Program{constInit, init, strand, create, update, ...}) = let      fun analyze (S.Program{constInit, globInit, strand, create, init, update, ...}) = let
202            val S.Strand{stateInit, initM, updateM, stabilizeM, ...} = strand            val S.Strand{stateInit, initM, updateM, stabilizeM, ...} = strand
           val S.Create{code, ...} = create  
203            in            in
204              analyzeBlock ConstInit constInit;              analyzeBlock ConstInit constInit;
205              analyzeBlock GlobalInit init;              analyzeBlock GlobalInit globInit;
206              analyzeBlock StateInit stateInit;              analyzeBlock StateInit stateInit;
207              Option.app (analyzeBlock InitMeth) initM;              Option.app (analyzeBlock InitMeth) initM;
208              analyzeBlock UpdateMeth updateM;              analyzeBlock UpdateMeth updateM;
209              Option.app (analyzeBlock StabilizeMeth) stabilizeM;              Option.app (analyzeBlock StabilizeMeth) stabilizeM;
210              analyzeBlock Create code;              Create.app (analyzeBlock Create) create;
211                Option.app (analyzeBlock GlobalUpdate) init;
212              Option.app (analyzeBlock GlobalUpdate) update              Option.app (analyzeBlock GlobalUpdate) update
213            end            end
214    

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

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