| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | package com.sun.fortress.compiler.phases; |
|---|
| 19 | |
|---|
| 20 | import java.util.*; |
|---|
| 21 | import com.sun.fortress.nodes.*; |
|---|
| 22 | import com.sun.fortress.nodes_util.*; |
|---|
| 23 | import com.sun.fortress.useful.Debug; |
|---|
| 24 | |
|---|
| 25 | import edu.rice.cs.plt.tuple.Option; |
|---|
| 26 | |
|---|
| 27 | public 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 | |
|---|
| 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 | |
|---|
| 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 | } |
|---|