SCM Repository
Annotation of /branches/vis15/src/compiler/simplify/simplify-vars.sml
Parent Directory
|
Revision Log
Revision 3457 - (view) (download)
1 : | jhr | 3457 | (* simplify-vars.sml |
2 : | * | ||
3 : | * This module analyses the use of variables in the Simple AST and rationalizes | ||
4 : | * their use in the following ways: | ||
5 : | * | ||
6 : | * -- for any strand parameter that is used in a method, we create a shadow state | ||
7 : | * variable | ||
8 : | * | ||
9 : | * -- unused constant and global variables are elminated | ||
10 : | * | ||
11 : | * -- unused strand state variables are eliminated | ||
12 : | * | ||
13 : | * -- unused local variables are eliminated | ||
14 : | * | ||
15 : | * -- strand-invariant state variables (except outputs) and expressions are | ||
16 : | * lifted to global scope | ||
17 : | * | ||
18 : | * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) | ||
19 : | * | ||
20 : | * COPYRIGHT (c) 2015 The University of Chicago | ||
21 : | * All rights reserved. | ||
22 : | *) | ||
23 : | |||
24 : | structure SimplifyVars : sig | ||
25 : | |||
26 : | val transform : Simple.program -> Simple.program | ||
27 : | |||
28 : | end = struct | ||
29 : | |||
30 : | structure S = Simple | ||
31 : | |||
32 : | (* analyze an expression using the `doVar` and `doFld` | ||
33 : | * functions to analyze variable uses. | ||
34 : | *) | ||
35 : | fun analyzeExp doVar doFld = let | ||
36 : | fun anal (env, e) = (case e | ||
37 : | of S.E_Var x => doVar(x, env) | ||
38 : | | S.E_Lit _ => env | ||
39 : | | S.E_Select(x, fld) => doFld (fld, doVar(x, env)) | ||
40 : | | S.E_Apply(f, xs, _) => List.foldl doVar env (f::xs) | ||
41 : | | S.E_Prim(_, _, xs, _) => List.foldl doVar env xs | ||
42 : | | S.E_Tensor(xs, _) => List.foldl doVar env xs | ||
43 : | | S.E_Seq(xs, _) => List.foldl doVar env xs | ||
44 : | | S.E_Slice(x, indices, _) => let | ||
45 : | fun doIndex (NONE, env) = env | ||
46 : | | doIndex (SOME ix, env) => doVar(ix, env) | ||
47 : | in | ||
48 : | doVar (x, List.foldl doIndex env indices) | ||
49 : | end | ||
50 : | | S.E_Coerce{x, ...} => doVar(x, env) | ||
51 : | | S.E_LoadSeq _ => () | ||
52 : | | S.E_LoadImage _ => () | ||
53 : | (* end case *)) | ||
54 : | in | ||
55 : | anal | ||
56 : | end | ||
57 : | |||
58 : | fun transform prog = prog | ||
59 : | |||
60 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |