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

SCM Repository

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

Annotation of /branches/pure-cfg/src/compiler/codegen/classify-state.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

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

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