root/trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/ParallelismAnalyzer.java @ 3852

Revision 3852, 5.6 KB (checked in by chf, 5 months ago)

alphabetize codegen, ParallelismAnallyzer? isn't working yet.

Line 
1/*******************************************************************************
2    Copyright 2009 Sun Microsystems, Inc.,
3    4150 Network Circle, Santa Clara, California 95054, U.S.A.
4    All rights reserved.
5
6    U.S. Government Rights - Commercial software.
7    Government users are subject to the Sun Microsystems, Inc. standard
8    license agreement and applicable provisions of the FAR and its supplements.
9
10    Use is subject to license terms.
11
12    This distribution may include materials developed by third parties.
13
14    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15    trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16******************************************************************************/
17
18package com.sun.fortress.compiler.phases;
19
20import java.util.*;
21import com.sun.fortress.nodes.*;
22import com.sun.fortress.nodes_util.*;
23import com.sun.fortress.useful.Debug;
24
25import edu.rice.cs.plt.tuple.Option;
26
27public class ParallelismAnalyzer extends NodeAbstractVisitor<Boolean> {
28    private final HashMap<ASTNode, Boolean> worthy;
29
30    private final static Boolean f = new Boolean(false);
31    private final static Boolean t = new Boolean(true);
32
33    ParallelismAnalyzer() {
34        worthy = new HashMap<ASTNode, Boolean>();
35    }
36
37    private void debug(ASTNode x) {
38        Debug.debug(Debug.Type.CODEGEN,1, "ParallelismAnalyzer: node =" + x);       
39    }
40
41    private void debug(ASTNode x, String message){
42        Debug.debug(Debug.Type.CODEGEN,1, "ParallelismAnalyzer: node =" + x + "::" + message);
43    }
44
45    private void debug(String message) {
46        Debug.debug(Debug.Type.CODEGEN,1, "ParallelismAnalyzer: " + "::" + message);       
47    }
48
49    public Boolean defaultCase(ASTNode x) {
50        debug(x,"defaultCase");
51        worthy.put(x, f);
52        return f;
53    }
54
55    public Boolean forComponent(Component x) {
56        debug(x, "forComponent");
57
58        for (Decl d : x.getDecls()) {
59            d.accept(this);
60        }
61        worthy.put(x,f);
62        return f;
63    }
64
65    public Boolean forFnDecl(FnDecl x) {
66        debug(x,"forFnDecl");
67        boolean result = false;
68        List<Param> params = x.getHeader().getParams();
69        boolean paramsWorthy[] = new boolean[params.size()];
70        int i = 0;
71       
72        for (Param p : params)
73            paramsWorthy[i++] = p.accept(this);
74       
75       
76        debug(x,"ZZZZZZ" + x.getBody().unwrap());
77        x.getBody().unwrap().accept(this);
78        return f;
79    }
80
81    // The FnRef is not parallel, but as an argument it is worth parallelizing.
82    public Boolean forFnRef(FnRef x) {
83        debug(x,"forFnRef");
84        worthy.put(x, f);
85        return t;
86    }
87
88    public Boolean forIf(If x) {
89        debug(x,"forIf");
90        for (IfClause clause : x.getClauses()) clause.accept(this);
91        Option<Block> maybe_else = x.getElseClause();
92        if (maybe_else.isSome()) {
93            maybe_else.unwrap().accept(this);
94        }       
95        worthy.put(x,f);
96        return f;
97    }
98
99    public Boolean forOpExpr(OpExpr x) {
100        debug(x,"forOpExpr");
101        List<Expr> args = x.getArgs();
102        boolean argsWorthy[] = new boolean[args.size()];
103        int i = 0;
104        int count = 0;
105
106        for (Expr e : args) {
107            Boolean temp = e.accept(this);
108            argsWorthy[i++] = temp;
109            if (temp) {
110                count++;
111            }
112        }
113        worthy.put(x, f);
114        return f;
115    }
116
117    public Boolean forTraitDecl(TraitDecl x) {
118        debug(x,"forTraitDecl");
119        for (Decl d : x.getHeader().getDecls()) d.accept(this);
120        worthy.put(x,f);
121        return f;
122    }
123
124
125    public Boolean for_RewriteFnApp(_RewriteFnApp x) {
126        debug(x,"for_RewriteFnApp");
127
128        Expr arg = x.getArgument();
129        if (arg instanceof VoidLiteralExpr) {
130           
131        } else if (arg instanceof TupleExpr) {
132            TupleExpr targ = (TupleExpr) arg;
133            List<Expr> exprs = targ.getExprs();
134               
135            for (Expr expr : exprs) {
136                expr.accept(this);
137            }
138        } else {
139            arg.accept(this);
140        }
141        x.getFunction().accept(this);
142        worthy.put(x, f);
143        return f;
144    }
145
146    // Why doesn't the defaultCase handle these?
147
148    public Boolean forBlock(Block x) {debug(x,"forBlock"); return f;}
149    public Boolean forChainExpr(ChainExpr x) {debug(x,"forChainExpr"); return f;}
150    public Boolean forDecl(Decl x) {debug(x,"forDecl"); return f;}
151    public Boolean forDo(Do x) {debug(x,"forDo"); return f;}
152    public Boolean forIfClause(IfClause x) {debug(x,"forIfClause"); return f;}
153    public Boolean forImportNames(ImportNames x) {debug(x,"forImportNames"); return f;}
154    public Boolean forIntLiteralExpr(IntLiteralExpr x) {debug(x,"forIntLiteralExpr"); return f;}
155    public Boolean forObjectDecl(ObjectDecl x) {debug(x,"forObjectDecl"); return f;}
156    public Boolean forOpRef(OpRef x) {debug(x,"forOpRef"); return f;}
157    public Boolean forParam(Param x) {debug(x,"forParam"); return f;}
158    public Boolean forStringLiteralExpr(StringLiteralExpr x) {debug(x,"forStringLiteralExpr"); return f;}
159    public Boolean forSubscriptExpr(SubscriptExpr x) {debug(x,"forSubscriptExpr"); return f;}
160    public Boolean forVarRef(VarRef x) {debug(x,"forVarRef"); return f;}
161    public Boolean forVoidLiteralExpr(VoidLiteralExpr x) {debug(x,"forVoidLiteralExpr"); return f;}
162    public Boolean for_RewriteFnOverloadDecl(_RewriteFnOverloadDecl x) {debug(x,"for"); return f;}
163
164
165    public void printTable() {
166        Set<ASTNode> keys = worthy.keySet();
167        for (ASTNode key : keys)
168            debug("Parallelizable table entry " + key  + " has value " + worthy.get(key));
169    }
170}
Note: See TracBrowser for help on using the browser.