use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.
the class ObjectCacheAnalysis method contextForSegment.
/**
* XXX: temporary helper to bridge gap between two representations (segment and scope)
* @param segment
* @return the corresponding execution context
* @throws RuntimeException if the conversion is impossible
*/
private ExecutionContext contextForSegment(Segment segment) {
ContextCFG entry;
Set<ContextCFG> entries = segment.getEntryCFGs();
if (entries.size() != 1) {
throw new RuntimeException("contextForSegment(): Currently we only support a single entry method");
}
entry = entries.iterator().next();
return new ExecutionContext(entry.getCfg().getMethodInfo(), entry.getCallString());
}
use of com.jopdesign.common.code.ExecutionContext 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);
}
}
use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.
the class WCETTool method computeCyclomaticComplexity.
// public File getOutFile(String file) {
// return new File(projectConfig.getOutDir(), file);
// }
/* FIXME: Slow, caching is missing */
public int computeCyclomaticComplexity(MethodInfo m) {
ControlFlowGraph g = getFlowGraph(m);
int nLocal = g.vertexSet().size();
int eLocal = g.edgeSet().size();
int pLocal = g.buildLoopBoundMap().size();
int ccLocal = eLocal - nLocal + 2 * pLocal;
int ccGlobal = 0;
for (ExecutionContext n : this.getCallGraph().getReferencedMethods(m)) {
MethodInfo impl = n.getMethodInfo();
ccGlobal += 2 + computeCyclomaticComplexity(impl);
}
return ccLocal + ccGlobal;
}
use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.
the class WCETTool method getLoopBound.
// TODO move somewhere else?
public LoopBound getLoopBound(CFGNode node, CallString cs) {
LoopBound globalBound = node.getLoopBound();
ExecutionContext eCtx = new ExecutionContext(node.getControlFlowGraph().getMethodInfo(), cs);
if (node.getBasicBlock() != null) {
return this.getEventHandler().dfaLoopBound(node.getBasicBlock(), eCtx, globalBound);
} else {
return globalBound;
}
}
use of com.jopdesign.common.code.ExecutionContext 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;
}
Aggregations