Search in sources :

Example 1 with SuperGraphNode

use of com.jopdesign.common.code.SuperGraph.SuperGraphNode in project jop by jop-devel.

the class Segment method buildSegment.

/**
	 * Collect all supergraph edges which are part of the segment.
	 * As segments are allowed to be interprocedural, we require that
	 * control flow graphs have return edges, and that return edges
	 * are in the exit set if they are not part of the segment.
	 */
private Set<SuperGraphEdge> buildSegment() {
    nodes = new HashMap<SuperGraph.ContextCFG, List<SuperGraphNode>>();
    edges = new HashSet<SuperGraphEdge>();
    otherEntries = new HashSet<SuperGraphEdge>();
    HashSet<SuperGraphEdge> actualExits = new HashSet<SuperGraphEdge>();
    Stack<SuperGraphEdge> worklist = new Stack<SuperGraphEdge>();
    /* push all targets of entry edges on the worklist */
    worklist.addAll(entries);
    while (!worklist.isEmpty()) {
        SuperGraphEdge current = worklist.pop();
        if (edges.contains(current))
            continue;
        /* continue if marked black */
        edges.add(current);
        /* If this is an exit egde, remember that it has been visited, and continue */
        if (exits.contains(current)) {
            actualExits.add(current);
            continue;
        }
        /* Otherwise add the target node and push all successors on the worklist */
        SuperGraphNode target = current.getTarget();
        MiscUtils.addToList(nodes, target.getContextCFG(), target);
        Iterators.addAll(worklist, sg.getSuccessorEdges(current));
    }
    exits = actualExits;
    for (SuperGraphNode node : getNodes()) {
        for (SuperGraphEdge edge : sg.incomingEdgesOf(node)) {
            if (!edges.contains(edge)) {
                otherEntries.add(edge);
            }
        }
    }
    /* for all nodes find entries which are not part of the segment; this are "otherEntries" */
    return edges;
}
Also used : ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Stack(java.util.Stack)

Example 2 with SuperGraphNode

use of com.jopdesign.common.code.SuperGraph.SuperGraphNode in project jop by jop-devel.

the class Segment method exportDOT.

/**
	 * Export to DOT file
	 * @param dotFile
	 * @throws IOException
	 */
public void exportDOT(File dotFile) throws IOException {
    FileWriter dotWriter = new FileWriter(dotFile);
    AdvancedDOTExporter.DOTNodeLabeller<SuperGraphNode> nodeLabeller = new AdvancedDOTExporter.DefaultNodeLabeller<SuperGraphNode>() {

        @Override
        public String getLabel(SuperGraphNode node) {
            StringBuilder sb = new StringBuilder();
            /* for entry nodes: method + call string */
            if (node.getCFGNode().getId() == 0) {
                sb.append(node.getContextCFG().getCfg().getMethodInfo().getFQMethodName() + "\n");
                int i = 1;
                for (InvokeSite is : node.getContextCFG().getCallString()) {
                    sb.append(" #" + i + " " + is.getInvoker().getFQMethodName() + " / " + is.getInstructionHandle().getPosition() + "\n");
                    i += 1;
                }
            } else /* for other nodes: basic block export */
            {
                sb.append(node.getCFGNode().toString());
            }
            return sb.toString();
        }
    };
    DOTLabeller<SuperGraphEdge> edgeLabeller = new AdvancedDOTExporter.DefaultDOTLabeller<SuperGraphEdge>() {

        @Override
        public String getLabel(SuperGraphEdge edge) {
            return "";
        }

        @Override
        public boolean setAttributes(SuperGraphEdge edge, Map<String, String> ht) {
            super.setAttributes(edge, ht);
            if (edge instanceof SuperReturnEdge) {
                ht.put("style", "dotted");
                ht.put("arrowhead", "empty");
            } else if (edge instanceof SuperInvokeEdge) {
                ht.put("style", "dotted");
            }
            return true;
        }
    };
    AdvancedDOTExporter<SuperGraphNode, SuperGraphEdge> de = new AdvancedDOTExporter<SuperGraphNode, SuperGraphEdge>(nodeLabeller, edgeLabeller);
    de.exportDOTDiGraph(dotWriter, this.getNodes(), this.getEdges(), new AdvancedDOTExporter.GraphAdapter<SuperGraphNode, SuperGraphEdge>() {

        @Override
        public SuperGraphNode getEdgeSource(SuperGraphEdge e) {
            return e.getSource();
        }

        @Override
        public SuperGraphNode getEdgeTarget(SuperGraphEdge e) {
            return e.getTarget();
        }
    });
    dotWriter.close();
}
Also used : FileWriter(java.io.FileWriter) SuperReturnEdge(com.jopdesign.common.code.SuperGraph.SuperReturnEdge) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge) AdvancedDOTExporter(com.jopdesign.common.graphutils.AdvancedDOTExporter) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with SuperGraphNode

use of com.jopdesign.common.code.SuperGraph.SuperGraphNode in project jop by jop-devel.

the class ObjectCacheAnalysis method getSaturatedTypes.

/** Traverse vertex set. Collect those types where we could not resolve
	 * the symbolic object names. (Not too useful in the analysis, but useful
	 * for debugging)
	 */
public HashSet<String> getSaturatedTypes(Segment segment, LocalPointsToResult usedRefs) {
    HashSet<String> topTypes = new HashSet<String>();
    for (SuperGraphNode n : segment.getNodes()) {
        BasicBlock bb = n.getCFGNode().getBasicBlock();
        if (bb == null)
            continue;
        CallString cs = n.getContextCFG().getCallString();
        for (InstructionHandle ih : bb.getInstructions()) {
            BoundedSet<SymbolicAddress> refs;
            if (usedRefs.containsKey(ih)) {
                refs = usedRefs.get(ih, cs);
                String handleType = getHandleType(project, n.getCfg(), ih);
                if (handleType == null)
                    continue;
                if (refs.isSaturated()) {
                    topTypes.add(handleType);
                }
            }
        }
    }
    return topTypes;
}
Also used : BasicBlock(com.jopdesign.common.code.BasicBlock) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) CallString(com.jopdesign.common.code.CallString) SymbolicAddress(com.jopdesign.dfa.analyses.SymbolicAddress) InstructionHandle(org.apache.bcel.generic.InstructionHandle) HashSet(java.util.HashSet) CallString(com.jopdesign.common.code.CallString)

Example 4 with SuperGraphNode

use of com.jopdesign.common.code.SuperGraph.SuperGraphNode in project jop by jop-devel.

the class GlobalAnalysis method buildIpetProblem.

/**
     * Create an interprocedural max-cost max-flow problem for the given segment<br/>
     * Notes:<ul>
     * <li/> super graph edges always have the callstring of the invoking method
     * </ul>
     *
     * @param wcetTool    A reference to the WCETTool
     * @param problemName A unique identifier for the problem (for reporting)
     * @param segment     The segment to build the ILP for
     * @param ipetConfig  Cost of nodes (or {@code null} if no cost is associated with nodes)
     * @return The max-cost maxflow problem
     * @throws InvalidFlowFactException 
     */
public static IPETSolver<SuperGraphEdge> buildIpetProblem(WCETTool wcetTool, String problemName, Segment segment, IPETConfig ipetConfig) throws InvalidFlowFactException {
    IPETSolver<SuperGraphEdge> ipetSolver = new IPETSolver<SuperGraphEdge>(problemName, ipetConfig);
    /* DEBUGGING: Render segment */
    //        try {
    //			segment.exportDOT(wcetTool.getProjectConfig().getOutFile(problemName+".dot"));
    //		} catch (IOException e) {
    //			e.printStackTrace();
    //		}
    /* In- and Outflow */
    ipetSolver.addConstraint(IPETUtils.constantFlow(segment.getEntryEdges(), 1));
    ipetSolver.addConstraint(IPETUtils.constantFlow(segment.getExitEdges(), 1));
    /* Structural flow constraints */
    for (SuperGraphNode node : segment.getNodes()) {
        ipetSolver.addConstraint(IPETUtils.flowPreservation(segment.incomingEdgesOf(node), segment.outgoingEdgesOf(node)));
    }
    /* Supergraph constraints */
    for (Pair<SuperInvokeEdge, SuperReturnEdge> superEdgePair : segment.getCallSites()) {
        Iterable<SuperGraphEdge> es1 = Iterators.<SuperGraphEdge>singleton(superEdgePair.first());
        Iterable<SuperGraphEdge> es2 = Iterators.<SuperGraphEdge>singleton(superEdgePair.second());
        ipetSolver.addConstraint(IPETUtils.flowPreservation(es1, es2));
    }
    /* Program Flow Constraints */
    for (LinearConstraint<SuperGraphEdge> flowFact : getFlowFacts(wcetTool, segment)) {
        ipetSolver.addConstraint(flowFact);
    }
    return ipetSolver;
}
Also used : IPETSolver(com.jopdesign.wcet.ipet.IPETSolver) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperReturnEdge(com.jopdesign.common.code.SuperGraph.SuperReturnEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)

Example 5 with SuperGraphNode

use of com.jopdesign.common.code.SuperGraph.SuperGraphNode in project jop by jop-devel.

the class GlobalAnalysis method setExecutionCost.

/**
     * Compute the execution time of each edge in in the supergraph
     * 
     * @param segment       the supergraph, whose vertices are considered
     * @param ipetInst      the IPET instance
     * @return the cost map
     */
private Map<SuperGraphEdge, WcetCost> setExecutionCost(Segment segment, IPETSolver<SuperGraphEdge> ipetInstance) {
    HashMap<SuperGraphEdge, WcetCost> edgeCost = new HashMap<SuperGraphEdge, WcetCost>();
    /* Attribute edge cost to edge source */
    for (SuperGraphEdge e : segment.getEdges()) {
        /* ignore exit edges, because their target is per definitionem not part of the segment */
        if (segment.isExitEdge(e))
            continue;
        SuperGraphNode sg = e.getTarget();
        WcetCost cost = calculateCost(sg);
        edgeCost.put(e, cost);
        ipetInstance.addEdgeCost(e, cost.getCost());
    }
    return edgeCost;
}
Also used : HashMap(java.util.HashMap) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode)

Aggregations

SuperGraphNode (com.jopdesign.common.code.SuperGraph.SuperGraphNode)11 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)8 HashSet (java.util.HashSet)5 CallString (com.jopdesign.common.code.CallString)4 SuperInvokeEdge (com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)4 SymbolicAddress (com.jopdesign.dfa.analyses.SymbolicAddress)4 InstructionHandle (org.apache.bcel.generic.InstructionHandle)4 BasicBlock (com.jopdesign.common.code.BasicBlock)3 SuperReturnEdge (com.jopdesign.common.code.SuperGraph.SuperReturnEdge)3 AccessCostInfo (com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis.AccessCostInfo)3 Segment (com.jopdesign.common.code.Segment)2 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)2 ObjectCacheCost (com.jopdesign.wcet.jop.ObjectCache.ObjectCacheCost)2 HashMap (java.util.HashMap)2 AppInfo (com.jopdesign.common.AppInfo)1 AppSetup (com.jopdesign.common.AppSetup)1 MethodInfo (com.jopdesign.common.MethodInfo)1 TestFramework (com.jopdesign.common.TestFramework)1 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)1 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)1