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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations