use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.
the class GlobalAnalysis method getLoopBounds.
/**
* <p>Get all loop bounds for the given segment.</p>
* <p>For each loop bound B for loop H relative to marker M:</p>
* <p>sum(M) * B <= sum(continue-edges-of(H))</p>
*
* @param segment
* @return
* @throws InvalidFlowFactException
*/
private static Iterable<LinearConstraint<SuperGraphEdge>> getLoopBounds(WCETTool wcetTool, Segment segment) throws InvalidFlowFactException {
List<LinearConstraint<SuperGraphEdge>> constraints = new ArrayList<LinearConstraint<SuperGraphEdge>>();
// For all CFG instances
for (ContextCFG ccfg : segment.getCallGraphNodes()) {
ControlFlowGraph cfg = ccfg.getCfg();
// for all loops in the method
LoopColoring<CFGNode, ControlFlowGraph.CFGEdge> loops = cfg.getLoopColoring();
for (CFGNode hol : loops.getHeadOfLoops()) {
LoopBound loopBound = wcetTool.getLoopBound(hol, ccfg.getContext().getCallString());
if (loopBound == null) {
throw new AppInfoError("No loop bound record for head of loop: " + hol + " : " + cfg.buildLoopBoundMap());
}
addLoopConstraints(constraints, segment, ccfg, hol, loops, loopBound);
}
}
return constraints;
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.
the class IPETUtils method loopBoundConstraints.
/**
* Compute flow constraints: Loop Bound constraints (Control Flow Graph only)
*
* @param g the flow graph
* @param ctx the invocation context
* @return A list of flow constraints
*/
public static <C extends CallStringProvider> List<LinearConstraint<IPETBuilder.ExecutionEdge>> loopBoundConstraints(ControlFlowGraph g, IPETBuilder<C> ctx) {
List<LinearConstraint<IPETBuilder.ExecutionEdge>> constraints = new ArrayList<LinearConstraint<IPETBuilder.ExecutionEdge>>();
// - for each loop with bound B
// -- sum(exit_loop_edges) * B <= sum(continue_loop_edges)
LoopColoring<CFGNode, ControlFlowGraph.CFGEdge> loops = g.getLoopColoring();
for (CFGNode hol : loops.getHeadOfLoops()) {
//LoopBound loopBound = g.getLoopBound(hol, ctx.getCallString());
LoopBound loopBound = ctx.getWCETTool().getLoopBound(hol, ctx.getCallString());
if (loopBound == null) {
throw new AppInfoError("No loop bound record for head of loop: " + hol + " : " + g.buildLoopBoundMap());
}
for (LinearConstraint<IPETBuilder.ExecutionEdge> loopConstraint : constraintsForLoop(loops, hol, loopBound, ctx)) {
constraints.add(loopConstraint);
}
}
return constraints;
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.
the class IPETUtils method constraintsForLoop.
/**
* Generate Loop Constraints
*/
public static <C extends CallStringProvider> List<LinearConstraint<IPETBuilder.ExecutionEdge>> constraintsForLoop(LoopColoring<CFGNode, ControlFlowGraph.CFGEdge> loops, CFGNode hol, LoopBound loopBound, IPETBuilder<C> ctx) {
ExecutionContext eCtx = new ExecutionContext(hol.getControlFlowGraph().getMethodInfo(), ctx.getCallString());
List<LinearConstraint<IPETBuilder.ExecutionEdge>> loopConstraints = new ArrayList<LinearConstraint<IPETBuilder.ExecutionEdge>>();
/* marker loop constraints */
for (Entry<SymbolicMarker, LoopBoundExpr> markerBound : loopBound.getLoopBounds()) {
/* loop constraint */
LinearConstraint<IPETBuilder.ExecutionEdge> loopConstraint = new LinearConstraint<IPETBuilder.ExecutionEdge>(ConstraintType.GreaterEqual);
for (ControlFlowGraph.CFGEdge continueEdge : loops.getBackEdgesTo(hol)) {
loopConstraint.addRHS(ctx.newEdge(continueEdge));
}
/* Multiplicities */
long lhsMultiplicity = markerBound.getValue().upperBound(eCtx);
SymbolicMarker marker = markerBound.getKey();
if (marker.getMarkerType() == SymbolicMarkerType.OUTER_LOOP_MARKER) {
CFGNode outerLoopHol;
outerLoopHol = loops.getLoopAncestor(hol, marker.getOuterLoopDistance());
if (outerLoopHol == null) {
// FIXME: [annotations] This is a user error, not an assertion error
throw new AssertionError("Invalid Loop Nest Level");
}
for (ControlFlowGraph.CFGEdge exitEdge : loops.getExitEdgesOf(outerLoopHol)) {
loopConstraint.addLHS(ctx.newEdge(exitEdge), lhsMultiplicity);
}
} else {
assert (marker.getMarkerType() == SymbolicMarkerType.METHOD_MARKER);
throw new AssertionError("ILPModelBuilder: method markers not yet supported, sorry");
}
loopConstraints.add(loopConstraint);
}
return loopConstraints;
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.
the class IPETUtils method buildLocalILPModel.
/**
* Create a max-cost maxflow problem for the given flow graph graph, based on a
* given node to cost mapping.
*
* @param wcetTool A reference to the WCETTool
* @param problemName a unique identifier for the problem (for reporting)
* @param cs context of the method invocation
* @param cfg the graph
* @param nodeWCET cost of nodes
* @return The max-cost maxflow problem
*/
public static IPETSolver buildLocalILPModel(WCETTool wcetTool, String problemName, CallString cs, ControlFlowGraph cfg, CostProvider<CFGNode> nodeWCET, IPETConfig ipetConfig) {
IPETSolver ipetSolver = new IPETSolver(problemName, ipetConfig);
IPETBuilder<CallString> builder = new IPETBuilder<CallString>(wcetTool, cs);
ipetSolver.addConstraints(IPETUtils.structuralFlowConstraintsRoot(cfg.getGraph(), builder));
ipetSolver.addConstraints(IPETUtils.loopBoundConstraints(cfg, builder));
ipetSolver.addConstraints(IPETUtils.infeasibleEdgeConstraints(cfg, builder));
for (CFGNode n : cfg.vertexSet()) {
long nodeCost = nodeWCET.getCost(n);
for (ControlFlowGraph.CFGEdge e : cfg.outgoingEdgesOf(n)) {
ipetSolver.addEdgeCost(builder.newEdge(e), nodeCost);
}
}
return ipetSolver;
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGNode 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);
}
Aggregations