/** * Collect all nodes from a given ControlFlowGraph * @param graph The ControlFlowGraph * @return The collected nodes */ public static LinkedList<Node> collectNodes(ControlFlowGraph graph) { NodeCollector collector = new NodeCollector(); graph.accept(collector); return collector.nodes; }
private String generateFilename(ControlFlowGraph in) { String filename = "gaalop.clu"; if (in.getSource() != null) { filename = in.getSource().getName(); int lastDotIndex = filename.lastIndexOf('.'); if (lastDotIndex != -1) { filename = filename.substring(0, lastDotIndex); } filename += ".clu"; } return filename; }
private void printMultivector(String name, Multivector mv) { for (int bladeIndex = 0; bladeIndex < mv.entries.length; bladeIndex++) if (Math.abs(mv.entries[bladeIndex]) > EPSILON) System.out.println(name + "(" + bladeIndex + ") = "+mv.entries[bladeIndex]+" // "+graph.getAlgebraDefinitionFile().getBladeString(bladeIndex)); }
/** * Removes the DefVars statement from a given Control Flow Graph * @param graph The Control Flow Graph */ public static void removeDefVars(ControlFlowGraph graph) { RemoveDefVars visitor = new RemoveDefVars(); graph.accept(visitor); for (SequentialNode node: visitor.toRemove) graph.removeNode(node); }
/** * 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)); }
/** * Updates the LocalVariable-set in a graph * @param graph The graph */ public static void updateVariableSets(ControlFlowGraph graph) { VariablesCollector collector = new VariablesCollector(); graph.accept(collector); LinkedList<Variable> vars = new LinkedList<Variable>(graph.getLocalVariables()); for (Variable v: vars) if (!collector.getVariables().contains(v.getName())) graph.removeLocalVariable(v); }
protected void createVectorSet (FindStoreOutputNodes findOutput) { for (Variable var : graph.getInputVariables()) { FieldsUsedVisitor fieldVisitor = new FieldsUsedVisitor(var.getName()); graph.accept(fieldVisitor); vectorSet.add(fieldVisitor.getMultiVector()); } for (Variable var : graph.getLocalVariables()) { FieldsUsedVisitor fieldVisitor = new FieldsUsedVisitor(var.getName()); graph.accept(fieldVisitor); vectorSet.add(fieldVisitor.getMultiVector()); } for (StoreResultNode var : findOutput.getNodes()) { FieldsUsedVisitor fieldVisitor = new FieldsUsedVisitor(var.getValue().getName()); graph.accept(fieldVisitor); vectorSet.add(fieldVisitor.getMultiVector()); } }
graph.accept(outputNodes); if (outputNodes.getNodes().isEmpty()) { throw new OptimizationException("There are no lines marked for optimization ('?')", graph); try { AlgebraDefinitionFile alFile = graph.getAlgebraDefinitionFile(); alFile.setUsePrecalculatedTable(plugin.usePrecalulatedTables); alFile.setUseAsRessource(graph.asRessource); graph.removeNode(macro); definer.createFromAlBase(alFile.base); BaseVectorReplaceVisitor replacerB = new BaseVectorReplaceVisitor(definer); graph.accept(replacerB); mapIndices.put(bladeToString(alFile.blades[index]), new Integer(index)); Set<String> set = graph.getPragmaOutputVariables(); HashSet<String> copySet = new HashSet<String>(set); set.clear();
graph.getInputVariables().contains(inputsVectorVar) || graph.getScalarVariables().contains(inputsVectorVar) || graph.getLocalVariables().contains(inputsVectorVar) graph.accept(vCFG);
if (graph.getInputVariables().isEmpty()) return; LinkedList<Variable> toDo = new LinkedList<Variable>(graph.getInputVariables()); Variable curVar = toDo.removeFirst(); ReplaceVisitor replaceVisitor = new ReplaceVisitor(curVar, map.get(curVar)); graph.accept(replaceVisitor);
in.accept(collector); graphAssignmentNodes = collector.getAssignmentNodes(); renderingExpressions = in.getRenderingExpressions(); colors = ColorEvaluater.getColors(in); for (Variable inputVar: in.getInputVariables()) if (!isPositionVariable(inputVar.getName())) inputs.add(inputVar.getName());
@Override public void visit(StartNode node) { graph = node.getGraph(); int bladeCount = graph.getAlgebraDefinitionFile().getBladeCount(); List<Variable> localVariables = sortVariables(graph.getLocalVariables()); if (standalone) { code.append("void calculate("); List<Variable> inputParameters = sortVariables(graph.getInputVariables()); for (Variable var : inputParameters) { code.append(variableType).append(" "); // The assumption here is that they all are normal scalars if (graph.getLocalVariables().size() > 0) { code.setLength(code.length() - 2); if (graph.getScalarVariables().size() > 0) { appendIndentation(); code.append(variableType).append(" "); for (Variable tmp : graph.getScalarVariables()) { code.append(tmp.getName()); code.append(", "); if (!graph.getLocalVariables().isEmpty()) { code.append("\n");
graph.accept(v); LinkedList<Node> nodeList = v.getNodeList(); for (String output : graph.getPragmaOutputVariables()) { String[] parts = output.split("\\$"); LinkedList<Integer> list; graph.removeNode(node); graph.accept(collector); graph.removeNode(node);
/** * Declare local variables * but first local variables in a set, so we reduce redundancy */ protected void handleLocalVariables() { Set <String> varNames = new HashSet<String> (); for (Variable var : graph.getLocalVariables()) { varNames.add(var.getName()); } for (String var : varNames) { appendIndentation(); FieldsUsedVisitor fieldVisitor = new FieldsUsedVisitor(var); graph.accept(fieldVisitor); code.append(fieldVisitor.giveDefinition(variableType)); code.append("\n"); } if (!graph.getLocalVariables().isEmpty()) { code.append("\n"); } }
/** * Searches the expression for variable references. If an undeclared reference is found, it is added to the input variables of * the graph. * * @param expression The expression to search in. */ private void findUndeclaredVariables(Expression expression) { UsedVariablesVisitor visitor = new UsedVariablesVisitor(); expression.accept(visitor); for (Variable usedVariable : visitor.getVariables()) { if (!graph.getLocalVariables().contains(usedVariable)) { // in case we have pragmas giving ranges for the variable, add them if (graph.getPragmaMinValue().containsKey(usedVariable.getName())) { usedVariable.setMinValue(graph.getPragmaMinValue().get(usedVariable.getName())); } if (graph.getPragmaMaxValue().containsKey(usedVariable.getName())) { usedVariable.setMaxValue(graph.getPragmaMaxValue().get(usedVariable.getName())); } graph.addInputVariable(usedVariable); } } }
public VerilogDFG(ControlFlowGraph in) { this.setCfg(in); originalstart = in.getStartNode(); originalend = in.getEndNode(); this.startnode= new VerilogNode(this) ; this.endnode = new VerilogNode(this); irvisit = new VerilogIRConverterVisitorCookies(this); in.accept(irvisit); // TODO Auto-generated constructor stub }
usedAlgebra = new UseAlgebra(graph.getAlgebraDefinitionFile()); graph.accept(divisionRemover); graph.accept(collector); graph.accept(mathFunctionSeparator); CFGImporter builder = new CFGImporter(usedAlgebra, plugin.isScalarFunctions(), graph.getAlgebraDefinitionFile()); graph.accept(builder); graph.accept(new RoundingCFGVisitor(plugin.getNumberOfRoundingDigits()));
/** * Returns all output blades of a given graph * @param graph The graph * @param usedAlgebra The used algebra * @return The output blades */ public static HashSet<VariableComponent> getAllOutputBlades(ControlFlowGraph graph, UseAlgebra usedAlgebra) { HashSet<VariableComponent> result = new HashSet<VariableComponent>(); // mark output vars as tabu for (String output : graph.getPragmaOutputVariables()) { String[] parts = output.split("\\$"); result.add(new VariableComponent(parts[0], Integer.parseInt(parts[1]), null)); } FindStoreOutputNodes storeResultNodes = new FindStoreOutputNodes(); graph.accept(storeResultNodes); for (StoreResultNode curSRNode : storeResultNodes.getNodes()) { String name = curSRNode.getValue().getName(); int bladeCount = usedAlgebra.getBladeCount(); for (int blade = 0; blade < bladeCount; blade++) { result.add(new VariableComponent(name, blade, null)); } } return result; } }
in.accept(cpp); try { BufferedWriter w = new BufferedWriter(new FileWriter("original.cpp")); in.accept(cf); for(int i=0;i<20;++i) { in.accept(new ConstanKillCrawler()); in.accept(new ConstantFolding()); in.accept(new CSE_Collector()); in.accept(new CSE_Collector()); System.out.println(in.toString());
graph = node.getGraph(); List<Variable> localVariables = sortVariables(graph.getLocalVariables()); if (standalone) { code.append("void calculate("); List<Variable> inputParameters = sortVariables(graph.getInputVariables()); for (Variable var : inputParameters) { code.append(variableType).append(" "); // The assumption here is that they all are normal scalars if (graph.getLocalVariables().size() > 0) { code.setLength(code.length() - 2); if (graph.getScalarVariables().size() > 0) { appendIndentation(); code.append(variableType).append(" "); for (Variable tmp : graph.getScalarVariables()) { code.append(tmp.getName()); code.append(", "); if (!graph.getLocalVariables().isEmpty()) { code.append("\n");