use of com.jopdesign.common.code.ControlFlowGraph.CFGEdge in project jop by jop-devel.
the class IPETUtils method infeasibleEdgeConstraints.
/**
* Compute flow constraints: Infeasible edge constraints
*
* @param g the flow graph
* @param ctx the invocation context
* @return A list of flow constraints
*/
public static <C extends CallStringProvider> List<LinearConstraint<ExecutionEdge>> infeasibleEdgeConstraints(ControlFlowGraph g, IPETBuilder<C> ctx) {
List<LinearConstraint<ExecutionEdge>> constraints = new ArrayList<LinearConstraint<ExecutionEdge>>();
// -- edge = 0
for (CFGEdge edge : ctx.getWCETTool().getInfeasibleEdges(g, ctx.getCallString())) {
LinearConstraint<ExecutionEdge> infeasibleConstraint = new LinearConstraint<ExecutionEdge>(ConstraintType.Equal);
infeasibleConstraint.addLHS(ctx.newEdge(edge));
infeasibleConstraint.addRHS(0);
constraints.add(infeasibleConstraint);
}
return constraints;
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGEdge in project jop by jop-devel.
the class Segment method synchronizedSegment.
/**
* Create an interprocedural segment for a synchronized block. Currently we do
* not split basic blocks here, so either you are happy with basic block granularity,
* or you split the basic block while loading.
* @param targetBlock The block containing the monitorenter instruction
* @param monitorEnter The monitor enter instruction
* @param callString The context for the method
* @param cfgProvider A control flow graph provider
* @param callStringLength Length of the callstrings
* @param infeasibles Information about infeasible edges (null if no information available)
*
* @return a segment representing executions of the synchronized block
*/
public static Segment synchronizedSegment(ContextCFG ccfg, CFGNode entryNode, InstructionHandle monitorEnter, CFGProvider cfgProvider, int callStringLength, InfeasibleEdgeProvider infeasibles) {
if (infeasibles == null) {
infeasibles = InfeasibleEdgeProvider.NO_INFEASIBLES;
}
ControlFlowGraph cfg = ccfg.getCfg();
SuperGraph superGraph = new SuperGraph(cfgProvider, cfg, ccfg.getCallString(), callStringLength, infeasibles);
ContextCFG rootMethod = superGraph.getRootNode();
/* lift entry edges */
Set<SuperGraphEdge> entryEdges = Iterators.addAll(new HashSet<SuperGraphEdge>(), superGraph.liftCFGEdges(rootMethod, cfg.incomingEdgesOf(entryNode)));
/* find exit blocks (might also be in the same block) */
/* monitorenter followed bei monitorexit in same block => segment only contains this block */
Set<CFGEdge> monitorExitEdges = new HashSet<CFGEdge>();
CFGNode currentNode = entryNode;
int currentNestingLevel = 1;
Iterator<InstructionHandle> insIter = currentNode.getBasicBlock().getInstructions().iterator();
while (insIter.hasNext()) {
if (insIter.next() == monitorEnter)
break;
}
Stack<Pair<CFGNode, Integer>> todo = new Stack<Pair<CFGNode, Integer>>();
Set<CFGNode> visited = new HashSet<CFGNode>();
do {
boolean isExit = false;
while (insIter.hasNext()) {
InstructionHandle ih = insIter.next();
if (ih.getInstruction() instanceof MONITOREXIT) {
/* blocks outgoing edges terminate segment */
currentNestingLevel--;
if (currentNestingLevel == 0) {
isExit = true;
// If monitorexit is not implemented in Java, the outgoing edges of the
// basic block that contains monitorexit end the synchronized block.
// In order to avoid imprecision, it is advisable that monitorexit is the
// last statement in the basic block.
// We also handle the case when monitorexit is implemented in Java. In this case,
// currentNode will be a SpecialInvokeNode, urrentNode's only
// successor will be the corresponding ReturnNode, and the outgoing edges of
// the ReturnNode are the exit edges for the synchronized segment.
CFGNode onlySuccessor = Iterators.fromSingleton(cfg.getSuccessors(currentNode));
if (onlySuccessor != null && onlySuccessor instanceof ControlFlowGraph.ReturnNode) {
Iterators.addAll(monitorExitEdges, cfg.outgoingEdgesOf(onlySuccessor));
} else {
Iterators.addAll(monitorExitEdges, cfg.outgoingEdgesOf(currentNode));
}
break;
}
} else if (ih.getInstruction() instanceof MONITORENTER) {
currentNestingLevel++;
}
}
if (!isExit) {
for (CFGNode node : cfg.getSuccessors(currentNode)) {
todo.add(new Pair<CFGNode, Integer>(node, currentNestingLevel));
}
}
currentNode = null;
while (!todo.isEmpty()) {
Pair<CFGNode, Integer> nextPair = todo.pop();
CFGNode nextNode = nextPair.first();
if (!visited.contains(nextNode)) {
visited.add(nextNode);
if (cfg.outgoingEdgesOf(nextNode).isEmpty()) {
throw new AssertionError("Found monitor-exit free path from monitorenter to the end of a function. In: " + cfg);
} else if (nextNode.getBasicBlock() == null) {
for (CFGNode node : cfg.getSuccessors(nextNode)) {
todo.add(new Pair<CFGNode, Integer>(node, nextPair.second()));
}
} else {
currentNode = nextNode;
currentNestingLevel = nextPair.second();
insIter = currentNode.getBasicBlock().getInstructions().iterator();
break;
}
}
}
} while (currentNode != null);
Set<SuperGraphEdge> exitEdges = Iterators.addAll(new HashSet<SuperGraphEdge>(), superGraph.liftCFGEdges(rootMethod, monitorExitEdges));
return new Segment(superGraph, entryEdges, exitEdges);
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGEdge in project jop by jop-devel.
the class ExecFrequencyAnalysis method getExecFrequency.
public long getExecFrequency(ExecutionContext context, InstructionHandle ih) {
MethodInfo method = context.getMethodInfo();
// By loading the CFG, loopbounds are attached to the blocks if the WCA tool is loaded
ControlFlowGraph cfg = method.getCode().getControlFlowGraph(false);
LoopColoring<CFGNode, CFGEdge> lc = cfg.getLoopColoring();
BasicBlockNode node = cfg.getHandleNode(ih, true);
if (node == null) {
// THIS IS UNSAFE! but what can you do ...
return 1;
}
long ef = 1;
for (CFGNode hol : lc.getLoopColor(node)) {
LoopBound lb = hol.getLoopBound();
if (lb != null) {
if (lb.isDefaultBound() && !analyses.isWCAMethod(method)) {
ef *= DEFAULT_ACET_LOOP_BOUND;
} else {
ef *= lb.getUpperBound(context);
}
} else {
ef *= DEFAULT_ACET_LOOP_BOUND;
}
}
return ef;
}
use of com.jopdesign.common.code.ControlFlowGraph.CFGEdge 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.CFGEdge in project jop by jop-devel.
the class WCETTool method getInfeasibleEdges.
/**
* Get infeasible edges for certain call string
*
* @param cfg the controlflowgraph of the method
* @param cs the callstring of the method
* @return The infeasible edges
*/
public List<CFGEdge> getInfeasibleEdges(ControlFlowGraph cfg, CallString cs) {
List<CFGEdge> edges = new ArrayList<CFGEdge>();
for (BasicBlock b : cfg.getBlocks()) {
List<CFGEdge> edge = dfaInfeasibleEdge(cfg, b, cs);
edges.addAll(edge);
}
return edges;
}
Aggregations