use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class LRUVarBlockCacheBuilder method initCache.
protected StringBuilder initCache(String NUM_METHODS) {
List<Object> cacheElems = new ArrayList<Object>();
for (int i = 0; i < numBlocks(); i++) cacheElems.add(NUM_METHODS);
// FIXME check: this has been "blocksOf(0)", check if this is the same!!
MethodInfo method = project.getProjectConfig().getTargetMethodInfo();
cacheElems.set(blocksOf(method) - 1, 0);
return SystemBuilder.constArray(cacheElems);
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class SegmentTest method main.
public static void main(String[] args) {
TestFramework testFramework = new TestFramework();
AppSetup setup = testFramework.setupAppSetup("java/tools/test/test/cg1.zip", null);
AppInfo appInfo = testFramework.setupAppInfo("wcet.devel.CallGraph1.run", true);
SegmentTest testInst = new SegmentTest();
testInst.appInfo = appInfo;
MethodInfo mainMethod = appInfo.getMainMethod();
/* count total number of CFG nodes */
SuperGraph superGraph = new SuperGraph(testInst, testInst.getFlowGraph(mainMethod), 2);
Segment segment = Segment.methodSegment(mainMethod, CallString.EMPTY, testInst, 2, superGraph.getInfeasibleEdgeProvider());
int count = 0;
for (ContextCFG cgNode : superGraph.getCallGraphNodes()) {
try {
cgNode.getCfg().exportDOT(new File("/tmp/cfg-" + cgNode.getCfg().getMethodInfo().getClassName() + "_" + cgNode.getCfg().getMethodInfo().getShortName() + ".dot"));
} catch (IOException e) {
}
count += cgNode.getCfg().vertexSet().size();
}
checkEquals("[Segment 1] Expected node count", (count - 2), Iterators.size(segment.getNodes()));
try {
segment.exportDOT(new File("/tmp/cg1-segment.dot"));
} catch (IOException e) {
e.printStackTrace();
}
/* root */
ContextCFG root = superGraph.getRootNode();
/* Build a segment cuts all invokes in those methods invoked by run() */
Segment segment2;
/* root entries */
Set<SuperGraphEdge> entries = new HashSet<SuperGraphEdge>();
Iterators.addAll(entries, superGraph.liftCFGEdges(root, root.getCfg().outgoingEdgesOf(root.getCfg().getEntry())));
Set<SuperGraphEdge> exits = new HashSet<SuperGraphEdge>();
int cfgNodeCandidateCount = root.getCfg().vertexSet().size();
/* find callees */
for (SuperEdge superEdge : superGraph.getCallGraph().outgoingEdgesOf(root)) {
if (!(superEdge instanceof SuperInvokeEdge))
continue;
ContextCFG callee1 = superGraph.getCallGraph().getEdgeTarget(superEdge);
cfgNodeCandidateCount += callee1.getCfg().vertexSet().size();
/* find all edges from invoke nodes */
for (CFGNode cfgNode : callee1.getCfg().vertexSet()) {
if (cfgNode instanceof InvokeNode) {
Iterators.addAll(exits, superGraph.outgoingEdgesOf(new SuperGraphNode(callee1, cfgNode)));
}
}
}
segment2 = new Segment(superGraph, entries, exits);
exits = segment2.getExitEdges();
/* reachable exits */
try {
segment2.exportDOT(new File("/tmp/cg1-segment2.dot"));
} catch (IOException e) {
e.printStackTrace();
}
checkEquals("[Segment 2] Expected node count", 14, Iterators.size(segment2.getNodes()) + 2);
checkLessEqual("[Segment 2] Expected node count <= |root + directly invoked|", Iterators.size(segment2.getNodes()) + 2, cfgNodeCandidateCount);
/* Another segment, with entries the exits of the last segment, and exits all invokes in methods the entries */
Segment segment3;
entries = segment2.getExitEdges();
exits = new HashSet<SuperGraphEdge>();
cfgNodeCandidateCount = 0;
for (SuperGraphEdge superEdge : entries) {
SuperGraphNode node1 = superEdge.getTarget();
for (SuperEdge superEdge2 : superGraph.getCallGraph().outgoingEdgesOf(node1.getContextCFG())) {
if (!(superEdge2 instanceof SuperInvokeEdge))
continue;
ContextCFG callee2 = superGraph.getCallGraph().getEdgeTarget(superEdge2);
/* find all edges from invoke nodes */
for (CFGNode cfgNode : callee2.getCfg().vertexSet()) {
if (cfgNode instanceof InvokeNode) {
Iterators.addAll(exits, superGraph.outgoingEdgesOf(new SuperGraphNode(callee2, cfgNode)));
}
}
}
}
segment3 = new Segment(superGraph, entries, exits);
try {
segment3.exportDOT(new File("/tmp/cg1-segment3.dot"));
} catch (IOException e) {
e.printStackTrace();
}
checkEquals("[Segment 2] 3 exits", 3, segment2.getExitEdges().size());
checkEquals("[Segment 3] 3 entries", 3, segment3.getEntryEdges().size());
checkEquals("[Segment 3] 4 exits", 4, segment3.getExitEdges().size());
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class JavaOneProcessPerSupergraphTranslator method recordLoops.
// Global maximal nesting depth is given by the equation
// node.gmnd = node.method.gmnd + (node.loop ? node.loop.nestingDepth : 0)
// method.gmnd = max { cs.method.gmnd + cs.gmnd | cs <- method.callsites }
// Example:
// main() { for() for() X: f(); }
// f() { for() for(HOL) }
// nesting depth of HOL is 2
// gmnd of f is gmnd of X = 2 + gmnd of main = 2
// gmnd of HOL is 4
private void recordLoops(TemplateBuilder tBuilder) {
try {
computeMethodNestingDepths();
} catch (BadGraphException e) {
throw new BadGraphError(e);
}
for (MethodInfo m : methodInfos) {
ControlFlowGraph cfg = project.getFlowGraph(m);
for (Entry<CFGNode, LoopBound> entry : cfg.buildLoopBoundMap().entrySet()) {
CFGNode hol = entry.getKey();
LoopBound lb = entry.getValue();
int nesting = cfg.getLoopColoring().getLoopColor(hol).size();
int gmnd = nesting + methodMNDs.get(m);
tBuilder.addLoop(hol, gmnd, lb);
}
}
if (config.debug)
tBuilder.dumpLoops();
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class JavaOneProcessPerSupergraphTranslator method translate.
@Override
protected void translate() {
computeCallSiteIDs();
systemBuilder.addCallStack(root, callSiteIDs.size());
/* Create one template for root method */
TemplateBuilder tBuilder = new TemplateBuilder(config, "Process", 0, "t_local");
tBuilder.addClock("t_local");
SubAutomaton mRoot = tBuilder.getTemplateAutomaton();
addMethodAutomaton(root, mRoot);
recordLoops(tBuilder);
/* Create start and end nodes for other methods */
for (int i = 1; i < this.methodInfos.size(); i++) {
MethodInfo mi = methodInfos.get(i);
if (project.getCallGraph().isLeafMethod(mi) && config.collapseLeaves)
continue;
SubAutomaton mAuto = tBuilder.createSubAutomaton(MiscUtils.qEncode(mi.getFQMethodName()));
addMethodAutomaton(mi, mAuto);
}
int i = 0;
for (MethodInfo mi : methodInfos) {
if (project.getCallGraph().isLeafMethod(mi) && config.collapseLeaves)
continue;
translateMethod(tBuilder, getMethodAutomaton(mi), i++, mi, new InvokeViaCallStackBuilder(this, tBuilder));
}
tBuilder.getInitial().setCommited();
addProgessMeasure(tBuilder);
tBuilder.addPostEnd();
try {
systemBuilder.addTemplate(0, 0, tBuilder.getFinalTemplate());
} catch (DuplicateKeyException e) {
throw new AssertionError("Unexpected exception: " + e);
}
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class ConstantCache method build.
public ConstantCache build() {
List<MethodInfo> methods = project.getCallGraph().getReachableImplementations(project.getTargetMethod());
for (int i = methods.size() - 1; i >= 0; i--) {
MethodInfo mi = methods.get(i);
ControlFlowGraph cfg = project.getFlowGraph(mi);
for (CFGNode n : cfg.vertexSet()) {
BasicBlock bb = n.getBasicBlock();
if (bb == null)
continue;
for (InstructionHandle ii : bb.getInstructions()) {
extractConstantAddresses(cfg, ii);
}
}
}
return this;
}
Aggregations