/** * Whenever a variable is defined, we want it to be also defined in the generated output. * * @param variableName The identifier of the variable. NOT the hashname given be NameTable. */ public void wasDefined(String variableName) { //String hashname = NameTable.getInstance().add(variableName); graph.addLocalVariable(new Variable(variableName)); } /**
@Override public void visit(StartNode node) { System.out.println("Replacer: Starting CSE Replacement"); this.cfg = node.getGraph(); for (OperationToken iterable_element : opstor.ReplaceAbleOpsSet.values()) { cfg.addLocalVariable(new Variable(iterable_element.getIdentifier())); } node.getSuccessor().accept(this); }
@Override public void visit(AssignmentNode node) { findUndeclaredVariables(node.getValue()); graph.addLocalVariable(node.getVariable()); node.getSuccessor().accept(this); }
/** * Updates the variable-sets in a graph * @param graph The graph */ public static void updateVariableSets(ControlFlowGraph graph) { UpdateLocalVariableSet visitor = new UpdateLocalVariableSet(); graph.accept(visitor); LinkedList<Variable> iVar = new LinkedList<Variable>(graph.getInputVariables()); LinkedList<Variable> lVar = new LinkedList<Variable>(graph.getLocalVariables()); //clear for (Variable inputVar: iVar) graph.removeInputVariable(inputVar); for (Variable defVar: lVar) graph.removeLocalVariable(defVar); //add for (String inputVar: visitor.inputVariables) graph.addInputVariable(new Variable(inputVar)); for (String defVar: visitor.defined) graph.addLocalVariable(new Variable(defVar)); }
@Override public void transform(ControlFlowGraph graph) throws OptimizationException { //insert visualizing commands, if needed LinkedList<ExpressionStatement> statements = ExpressionStatementCollector.collectAllStatements(graph); String prefix = "_V_"; //2d HashMap<String, Expression> renderingExpressions = graph.getRenderingExpressions(); int i = 0; for (ExpressionStatement s : statements) { String productName = prefix + "PRODUCT" + i; AssignmentNode renderNode = new AssignmentNode(graph, new Variable(productName), s.getExpression()); graph.addLocalVariable(new Variable(productName)); s.insertAfter(renderNode); StoreResultNode outputRenderNode = new StoreResultNode(graph, new Variable(productName)); graph.addLocalVariable(new Variable(productName)); renderNode.insertAfter(outputRenderNode); renderingExpressions.put(productName, s.getExpression()); i++; } } }
graph.addLocalVariable(new Variable(prefix + "POINT")); String productName = prefix + "PRODUCT" + i; AssignmentNode renderNode = new AssignmentNode(graph, new Variable(productName), new InnerProduct(s.getExpression(), visualizationPoint)); graph.addLocalVariable(new Variable(productName)); s.insertAfter(renderNode); graph.addLocalVariable(new Variable(productName)); renderNode.insertAfter(outputRenderNode); renderingExpressions.put(productName, s.getExpression());