Search in sources :

Example 1 with SuperInvokeEdge

use of com.jopdesign.common.code.SuperGraph.SuperInvokeEdge 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 2 with SuperInvokeEdge

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

the class MethodCacheAnalysis method findPersistenceSegmentCover.

/** Find a segment cover (i.e., a set of segments covering all execution paths)
	 *  where each segment in the set is persistent (a cache persistence region (CPR))
	 *  
	 *  <h2>The simplest algorithm for a segment S (for acyclic callgraphs)</h2>
	 *   <ul><li/>Check whether S itself is CPR; if so, return S
	 *       <li/>Otherwise, create subsegments S' for each invoked method,
	 *       <li/>and single node segments for each access
	 *   </ul>
	 * @param segment the parent segment
	 * @param checks the strategy to use to determine whether a segment is a persistence region
	 * @param avoidOverlap whether overlapping segments should be avoided
	 * @param extraCostOut additional cost for edges which are considered as always-miss or not-cached
	 * @return
	 */
protected Collection<Segment> findPersistenceSegmentCover(Segment segment, EnumSet<PersistenceCheck> checks, boolean avoidOverlap, Map<SuperGraphEdge, Long> extraCostOut) {
    List<Segment> cover = new ArrayList<Segment>();
    /* We currently only support entries to one CFG */
    Set<ContextCFG> entryMethods = new HashSet<ContextCFG>();
    for (SuperGraphEdge entryEdge : segment.getEntryEdges()) {
        entryMethods.add(entryEdge.getTarget().getContextCFG());
    }
    if (entryMethods.size() != 1) {
        throw new AssertionError("findPersistenceSegmentCover: only supporting segments with unique entry method");
    }
    if (this.isPersistenceRegion(segment, checks)) {
        // System.err.println("Adding cover segment for: "+entryMethods);
        cover.add(segment);
    } else {
        for (Pair<SuperInvokeEdge, SuperReturnEdge> invocation : segment.getCallSitesFrom(entryMethods.iterator().next())) {
            ContextCFG callee = invocation.first().getCallee();
            // System.err.println("Recursively analyzing: "+callee);
            Segment subSegment = Segment.methodSegment(callee, segment.getSuperGraph());
            Collection<Segment> subRegions = findPersistenceSegmentCover(subSegment, checks, avoidOverlap, extraCostOut);
            cover.addAll(subRegions);
            SuperReturnEdge rEdge = invocation.second();
            MiscUtils.incrementBy(extraCostOut, rEdge, getMissCost(rEdge), 0);
        }
    }
    return cover;
}
Also used : ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) ArrayList(java.util.ArrayList) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperReturnEdge(com.jopdesign.common.code.SuperGraph.SuperReturnEdge) Segment(com.jopdesign.common.code.Segment) HashSet(java.util.HashSet) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)

Example 3 with SuperInvokeEdge

use of com.jopdesign.common.code.SuperGraph.SuperInvokeEdge 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 4 with SuperInvokeEdge

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

the class MethodCacheAnalysis method getMissCost.

/**
	 * Get miss cost for an edge accessing the method cache
	 * @param accessEdge either a SuperInvoke or SuperReturn edge, or an entry edge of the segment analyzed
	 * @return maximum miss penalty (in cycles)
	 */
private long getMissCost(SuperGraphEdge accessEdge) {
    SuperGraphNode accessed = accessEdge.getTarget();
    ControlFlowGraph cfg = accessed.getCfg();
    if (accessEdge instanceof SuperReturnEdge) {
        /* return edge: return cost */
        Type returnType = accessEdge.getSource().getCfg().getMethodInfo().getType();
        return methodCache.getMissPenaltyOnReturn(cfg.getNumberOfWords(), returnType);
    } else if (accessEdge instanceof SuperInvokeEdge) {
        InstructionHandle invokeIns = ((SuperInvokeEdge) accessEdge).getInvokeNode().getInvokeSite().getInstructionHandle();
        return methodCache.getMissPenaltyOnInvoke(cfg.getNumberOfWords(), invokeIns.getInstruction());
    } else {
        /* entry edge of the segment: can be invoke or return cost */
        return methodCache.getMissPenalty(cfg.getNumberOfWords(), false);
    }
}
Also used : Type(org.apache.bcel.generic.Type) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) SuperReturnEdge(com.jopdesign.common.code.SuperGraph.SuperReturnEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) InstructionHandle(org.apache.bcel.generic.InstructionHandle) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)

Example 5 with SuperInvokeEdge

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

the class ObjectCacheAnalysis method findPersistenceSegmentCover.

/** Find a segment cover (i.e., a set of segments covering all execution paths)
	 *  where each segment in the set is persistent (a cache persistence region (CPR))
	 *  
	 *  <h2>The simplest algorithm for a segment S (for acyclic callgraphs)</h2>
	 *   <ul><li/>Check whether S itself is CPR; if so, return S
	 *       <li/>Otherwise, create subsegments S' for each invoked method,
	 *       <li/>and single node segments for each access
	 *   </ul>
	 * @param segment the parent segment
	 * @param checks the strategy to use to determine whether a segment is a persistence region
	 * @param avoidOverlap whether overlapping segments should be avoided
	 * @param alwaysMissNodes additional node set considered to be always miss
	 * @return
	 * @throws LpSolveException 
	 * @throws InvalidFlowFactException 
	 */
protected Collection<Segment> findPersistenceSegmentCover(Segment segment, EnumSet<PersistenceCheck> checks, boolean avoidOverlap, Set<SuperGraphNode> alwaysMissNodes) throws InvalidFlowFactException, LpSolveException {
    List<Segment> cover = new ArrayList<Segment>();
    /* We currently only support entries to one CFG */
    Set<ContextCFG> entryMethods = new HashSet<ContextCFG>();
    for (SuperGraphEdge entryEdge : segment.getEntryEdges()) {
        entryMethods.add(entryEdge.getTarget().getContextCFG());
    }
    ContextCFG entryMethod;
    if (entryMethods.size() != 1) {
        throw new AssertionError("findPersistenceSegmentCover: only supporting segments with unique entry method");
    } else {
        entryMethod = entryMethods.iterator().next();
    }
    if (this.isPersistenceRegion(segment, checks)) {
        cover.add(segment);
    } else {
        /* method sub segments */
        for (Pair<SuperInvokeEdge, SuperReturnEdge> invocation : segment.getCallSitesFrom(entryMethod)) {
            ContextCFG callee = invocation.first().getCallee();
            // System.err.println("Recursively analyzing: "+callee);
            Segment subSegment = Segment.methodSegment(callee, segment.getSuperGraph());
            cover.addAll(findPersistenceSegmentCover(subSegment, checks, avoidOverlap, alwaysMissNodes));
        }
        /* always miss nodes (not covered) */
        alwaysMissNodes.addAll(segment.getNodes(entryMethod));
    }
    return cover;
}
Also used : ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) ArrayList(java.util.ArrayList) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperReturnEdge(com.jopdesign.common.code.SuperGraph.SuperReturnEdge) Segment(com.jopdesign.common.code.Segment) HashSet(java.util.HashSet) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)

Aggregations

SuperInvokeEdge (com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)6 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)5 SuperReturnEdge (com.jopdesign.common.code.SuperGraph.SuperReturnEdge)5 SuperGraphNode (com.jopdesign.common.code.SuperGraph.SuperGraphNode)4 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)3 HashSet (java.util.HashSet)3 Segment (com.jopdesign.common.code.Segment)2 ArrayList (java.util.ArrayList)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 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)1 SuperEdge (com.jopdesign.common.code.SuperGraph.SuperEdge)1 AdvancedDOTExporter (com.jopdesign.common.graphutils.AdvancedDOTExporter)1 IPETSolver (com.jopdesign.wcet.ipet.IPETSolver)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1