use of com.jopdesign.common.code.ControlFlowGraph.CFGEdge in project jop by jop-devel.
the class SuperGraph method addEdge.
private void addEdge(ControlFlowGraph.InvokeNode invokeNode, ContextCFG invoker, ContextCFG invoked) {
SuperInvokeEdge iEdge = new SuperInvokeEdge(invokeNode, invoker, invoked);
superGraph.addEdge(invoker, invoked, iEdge);
CFGEdge returnEdge;
Set<CFGEdge> outEdges = invoker.getCfg().outgoingEdgesOf(invokeNode);
if (outEdges.size() != 1) {
throw new AssertionError("SuperGraph: Outdegree of invoker node != 1 (Missing return node?)");
} else {
returnEdge = outEdges.iterator().next();
}
CFGNode returnNode = invoker.getCfg().getEdgeTarget(returnEdge);
if (invoker.getCfg().incomingEdgesOf(returnNode).size() != 1) {
throw new AssertionError("SuperGraph: Indegree of return node != 1 (Missing return node?)");
}
SuperReturnEdge rEdge = new SuperReturnEdge(invokeNode, returnNode, invoker, invoked);
superGraph.addEdge(invoked, invoker, rEdge);
superEdgePairs.put(iEdge, rEdge);
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGEdge in project jop by jop-devel.
the class SuperGraph method createSuperGraph.
private void createSuperGraph() {
Stack<ContextCFG> todo = new Stack<ContextCFG>();
todo.push(rootNode);
superGraph.addVertex(rootNode);
while (!todo.empty()) {
ContextCFG current = todo.pop();
if (!current.getCfg().areVirtualInvokesResolved()) {
throw new AssertionError("Virtual dispatch nodes not yet supported for supergraph (file a bug)");
}
ControlFlowGraph currentCFG = current.getCfg();
CallString currentCS = current.getCallString();
Collection<CFGEdge> infeasibleEdges = infeasibleEdgeProvider.getInfeasibleEdges(currentCFG, currentCS);
for (CFGNode node : current.getCfg().vertexSet()) {
if (node instanceof ControlFlowGraph.InvokeNode) {
/* skip node if all incoming edges are infeasible in the current call context */
boolean infeasible = true;
for (CFGEdge e : current.getCfg().incomingEdgesOf(node)) {
if (!infeasibleEdges.contains(e)) {
infeasible = false;
}
}
if (infeasible)
continue;
ControlFlowGraph.InvokeNode iNode = (ControlFlowGraph.InvokeNode) node;
Set<MethodInfo> impls = iNode.getImplementingMethods();
if (impls.size() == 0) {
throw new AssertionError("No implementations for iNode available");
} else if (impls.size() != 1) {
throw new AssertionError("Unresolved virtual Dispatch for " + iNode + ": " + impls);
}
for (MethodInfo impl : impls) {
ControlFlowGraph invokedCFG = cfgProvider.getFlowGraph(impl);
CallString invokedCS = currentCS.push(iNode, callstringLength);
/* skip node if receiver is infeasible in current call context */
if (infeasibleEdgeProvider.isInfeasibleReceiver(impl, invokedCS)) {
Logger.getLogger(this.getClass()).info("createSuperGraph(): infeasible receiver " + impl);
continue;
}
ContextCFG invoked = new ContextCFG(invokedCFG, invokedCS);
if (!superGraph.containsVertex(invoked)) {
superGraph.addVertex(invoked);
todo.push(invoked);
}
addEdge(iNode, current, invoked);
}
}
}
}
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGEdge in project jop by jop-devel.
the class WCETTool method dfaInfeasibleEdge.
/**
* Get infeasible edges for certain basic block call string
* @param cfg the CFG containing the block
* @param block get infeasible outgoing edges for the block
* @param cs the callstring
* @return The infeasible edges for this basic block
*/
private List<CFGEdge> dfaInfeasibleEdge(ControlFlowGraph cfg, BasicBlock block, CallString cs) {
List<CFGEdge> retval = new LinkedList<CFGEdge>();
if (getDfaLoopBounds() != null) {
LoopBounds lbs = getDfaLoopBounds();
Set<FlowEdge> edges = lbs.getInfeasibleEdges(block.getLastInstruction(), cs);
for (FlowEdge e : edges) {
BasicBlockNode head = cfg.getHandleNode(e.getHead());
BasicBlockNode tail = cfg.getHandleNode(e.getTail());
CFGEdge edge = cfg.getEdge(tail, head);
if (edge != null) {
retval.add(edge);
} else {
// edge does was removed from the CFG
// logger.warn("The infeasible edge between "+head+" and "+tail+" does not exist");
}
}
}
return retval;
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGEdge in project jop by jop-devel.
the class GlobalAnalysis method getInfeasibleEdgeConstraints.
/**
* For each infeasible edge, assert that the edge has flow 0
* @param wcetTool
* @param segment
* @return
*/
private static Iterable<LinearConstraint<SuperGraphEdge>> getInfeasibleEdgeConstraints(WCETTool wcetTool, Segment segment) {
List<LinearConstraint<SuperGraphEdge>> constraints = new ArrayList<LinearConstraint<SuperGraphEdge>>();
// -- edge = 0
for (ContextCFG ccfg : segment.getCallGraphNodes()) {
for (CFGEdge edge : wcetTool.getInfeasibleEdges(ccfg.getCfg(), ccfg.getCallString())) {
LinearConstraint<SuperGraphEdge> infeasibleConstraint = new LinearConstraint<SuperGraphEdge>(ConstraintType.Equal);
infeasibleConstraint.addLHS(segment.liftCFGEdges(ccfg, Iterators.singleton(edge)));
infeasibleConstraint.addRHS(0);
constraints.add(infeasibleConstraint);
}
}
return constraints;
}
Aggregations