use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.
the class SuperGraph method outgoingEdgesOf.
/**
* The outgoing edges are generated as follows:
* <ul>
* <li/>invoke node: superedge invoking the callee
* <li/>exit node: superedge returning to the caller
* <li/>other: intraprocedural CFG edge
* </ul>
* @param node
* @return
*/
public Iterable<SuperGraphEdge> outgoingEdgesOf(SuperGraphNode node) {
CFGNode cfgNode = node.getCFGNode();
if (cfgNode instanceof InvokeNode) {
/* invoke node: outgoing SuperInvoke edges */
final InvokeNode invNode = (InvokeNode) cfgNode;
Set<SuperEdge> outgoingInvokeEdges = superGraph.outgoingEdgesOf(node.getContextCFG());
return new Filter<SuperGraphEdge>() {
@Override
protected boolean include(SuperGraphEdge e) {
if (!(e instanceof SuperInvokeEdge))
return false;
SuperInvokeEdge invoke = (SuperInvokeEdge) e;
return invoke.getInvokeNode().equals(invNode);
}
}.<SuperGraphEdge>filter(outgoingInvokeEdges);
} else if (cfgNode instanceof VirtualNode && ((VirtualNode) cfgNode).getKind() == VirtualNodeKind.EXIT) {
/* exit node: outgoing SuperReturn edges */
Set<SuperEdge> outgoingReturnEdges = superGraph.outgoingEdgesOf(node.getContextCFG());
return new Filter<SuperGraphEdge>() {
@Override
protected boolean include(SuperGraphEdge e) {
return (e instanceof SuperReturnEdge);
}
}.<SuperGraphEdge>filter(outgoingReturnEdges);
} else {
/* standard edges: outgoing edges of cfg node */
Set<CFGEdge> outgoingCFGEdges = node.getContextCFG().getCfg().outgoingEdgesOf(cfgNode);
return liftCFGEdges(node.getContextCFG(), outgoingCFGEdges);
}
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.
the class TreeAnalysis method extractUBs.
private Map<CFGNode, Long> extractUBs(Map<CFGNode, LoopBound> loopBounds) {
Map<CFGNode, Long> ubMap = new HashMap<CFGNode, Long>();
for (Entry<CFGNode, LoopBound> entry : loopBounds.entrySet()) {
MethodInfo mi = entry.getKey().getControlFlowGraph().getMethodInfo();
ExecutionContext eCtx = new ExecutionContext(mi);
ubMap.put(entry.getKey(), entry.getValue().getUpperBound(eCtx));
}
return ubMap;
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.
the class TreeAnalysis method computeProgress.
/* FIXME: filter leaf methods is really a ugly hack,
* but needs some work to play nice with uppaal eliminate-leaf-methods optimizations
*/
public void computeProgress(MethodInfo targetMethod, CallString cs) {
List<MethodInfo> reachable = project.getCallGraph().getReachableImplementations(targetMethod, cs);
Collections.reverse(reachable);
for (MethodInfo mi : reachable) {
ControlFlowGraph cfg = project.getFlowGraph(mi);
Map<CFGNode, Long> localProgress = new HashMap<CFGNode, Long>();
ProgressVisitor progressVisitor = new ProgressVisitor(maxProgress);
for (CFGNode n : cfg.vertexSet()) {
localProgress.put(n, progressVisitor.getProgress(n));
}
ProgressMeasure<CFGNode, CFGEdge> pm = new ProgressMeasure<CFGNode, ControlFlowGraph.CFGEdge>(cfg.getGraph(), cfg.getLoopColoring(), extractUBs(cfg.buildLoopBoundMap()), localProgress);
long progress = pm.getMaxProgress().get(cfg.getExit());
/* FIXME: _UGLY_ hack */
if (filterLeafMethods && cfg.isLeafMethod()) {
maxProgress.put(mi, 0L);
} else {
maxProgress.put(mi, progress);
}
relativeProgress.put(mi, pm.computeRelativeProgress());
}
System.out.println("Progress Measure (max): " + maxProgress.get(targetMethod));
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.
the class ExecuteOnceAnalysis method analyze.
private void analyze() {
inLoopSet = new HashMap<ExecutionContext, Set<MethodInfo>>();
/* Top Down the Scope Graph */
TopologicalOrderIterator<ExecutionContext, ContextEdge> iter = project.getCallGraph().topDownIterator();
while (iter.hasNext()) {
ExecutionContext scope = iter.next();
scope = new ExecutionContext(scope.getMethodInfo());
/* Remove call string */
ControlFlowGraph cfg = project.getFlowGraph(scope.getMethodInfo());
Set<MethodInfo> inLoop = new HashSet<MethodInfo>();
for (CFGNode node : cfg.vertexSet()) {
if (!(node instanceof ControlFlowGraph.InvokeNode))
continue;
ControlFlowGraph.InvokeNode iNode = (ControlFlowGraph.InvokeNode) node;
if (!cfg.getLoopColoring().getLoopColor(node).isEmpty()) {
for (MethodInfo impl : iNode.getImplementingMethods()) {
inLoop.add(impl);
inLoop.addAll(project.getCallGraph().getReachableImplementationsSet(impl));
}
}
}
inLoopSet.put(scope, inLoop);
}
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.
the class GlobalAnalysis method addLoopConstraints.
/**
* Add loop contraints
* @param constraints the new constraints are added to this collection
* @param segment
* @param ccfg
* @param headOfLoop
* @param loops
* @param loopBound
* @throws InvalidFlowFactException
*/
private static void addLoopConstraints(List<LinearConstraint<SuperGraphEdge>> constraints, Segment segment, ContextCFG ccfg, CFGNode headOfLoop, LoopColoring<CFGNode, CFGEdge> loops, LoopBound loopBound) throws InvalidFlowFactException {
/* marker loop constraints */
for (Entry<SymbolicMarker, LoopBoundExpr> markerBound : loopBound.getLoopBounds()) {
/* loop constraint */
LinearConstraint<SuperGraphEdge> loopConstraint = new LinearConstraint<SuperGraphEdge>(ConstraintType.GreaterEqual);
/* rhs = sum(continue-edges(loop)) */
Iterable<SuperGraphEdge> continueEdges = segment.liftCFGEdges(ccfg, loops.getBackEdgesTo(headOfLoop));
loopConstraint.addRHS(continueEdges);
/* Multiplicities */
ExecutionContext executionContext = new ExecutionContext(ccfg.getCfg().getMethodInfo(), ccfg.getCallString());
long lhsMultiplicity = markerBound.getValue().upperBound(executionContext);
SymbolicMarker marker = markerBound.getKey();
if (marker.getMarkerType() == SymbolicMarkerType.OUTER_LOOP_MARKER) {
CFGNode outerLoopHol;
outerLoopHol = loops.getLoopAncestor(headOfLoop, marker.getOuterLoopDistance());
if (outerLoopHol == null) {
throw new InvalidFlowFactException("Bad outer loop annotation");
}
Iterable<SuperGraphEdge> exitEdges = segment.liftCFGEdges(ccfg, loops.getExitEdgesOf(outerLoopHol));
for (SuperGraphEdge exitEdge : exitEdges) {
loopConstraint.addLHS(exitEdge, lhsMultiplicity);
}
} else {
assert (marker.getMarkerType() == SymbolicMarkerType.METHOD_MARKER);
throw new AssertionError("ILPModelBuilder: method markers not yet supported, sorry");
}
constraints.add(loopConstraint);
}
}
Aggregations