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

SCM Repository

[diderot] Annotation of /trunk/src/compiler/codegen/classify-state.sml
ViewVC logotype

Annotation of /trunk/src/compiler/codegen/classify-state.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1115 - (view) (download)

1 : jhr 1115 (* classify-state.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Classify strand state variables into three categories:
7 :     *
8 :     * UNIFORM -- these have the same value for all strands
9 :     * INVARIANT -- does not change over the life of the strand
10 :     * VARYING -- varies from step to step
11 :     *
12 :     * UNIFORM variables can be lifted into the global name space, while INVARIANT variables
13 :     * can be lifted into the non-varying state.
14 :     *)
15 :    
16 :     structure ClassifyState : sig
17 :    
18 :     datatype state_var_class = UNIFORM | INVARIANT | VARYING
19 :    
20 :     (* get the classification of a state variable *)
21 :     val varClass : LowIL.var -> state_var_class
22 :    
23 :     end = struct
24 :    
25 :     structure IL = LowIL
26 :     structure V = IL.Var
27 :    
28 :     datatype state_var_class = UNIFORM | INVARIANT | VARYING
29 :    
30 :     (* property for state variable classification *)
31 :     val {getFn = varClass : V.var -> state_var_class, setFn = setClass, ...} =
32 :     V.newProp (fn x => raise Fail(V.toString x ^ " not a state variable"))
33 :    
34 :     fun join (UNIFORM, cls) = cls
35 :     | join (cls, UNIFORM) = cls
36 :     | join (INVARIANT, cls) = cls
37 :     | join (cls, INVARIANT) = cls
38 :     | join (VARYING, VARYING) = VARYING
39 :    
40 :     fun analyseCFG () = let
41 :     val anyChange = ref false
42 :     fun mark (x, cls) = (case (varClass x, cls)
43 :     of (UNIFORM, cls) => (setClass(x, cls); anyChange := true)
44 :     | (INVARIANT, VARYING) => (setClass(x, cls); anyChange := true)
45 :     | _ => () (* no change *)
46 :     (* end case *))
47 :     fun loopToFixPt () = (
48 :     anyChange := false;
49 :     analyse();
50 :     if (! anyChange)
51 :     then loopToFixPt ()
52 :     else ())
53 :     in
54 :     loopToFixPt ()
55 :     end
56 :    
57 :     (* analyse a strand *)
58 :     fun analyseStrand (IL.Strand{name, params, state, stateInit, methods}) = let
59 :     in
60 :     (* initially, we mark all state variables as UNIFORM and parameters as INVARIANT *)
61 :     List.app (fn x => setClass(x, UNIFORM)) state;
62 :     List.app (fn x => setClass(x, INVARIANT)) params;
63 :     end
64 :    
65 :     end

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