From: yeom Date: Fri, 19 Aug 2011 02:30:46 +0000 (+0000) Subject: changes on the loop termination analysis: associate a labeled statement with a corres... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=commitdiff_plain;h=e23c316baea2eaf8fed44a761cecaefbcb9a7a36 changes on the loop termination analysis: associate a labeled statement with a corresponding LoopNode rather than attaching it to a BlockNode. this is interim implementation until we have branching statements. --- diff --git a/Robust/src/Analysis/Loops/LoopTerminate.java b/Robust/src/Analysis/Loops/LoopTerminate.java index 3cfbb3d0..f0111eb0 100644 --- a/Robust/src/Analysis/Loops/LoopTerminate.java +++ b/Robust/src/Analysis/Loops/LoopTerminate.java @@ -5,7 +5,9 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import Analysis.SSJava.SSJavaAnalysis; import IR.Operation; +import IR.State; import IR.Flat.FKind; import IR.Flat.FlatCondBranch; import IR.Flat.FlatMethod; @@ -28,10 +30,15 @@ public class LoopTerminate { Set computed; + State state; + SSJavaAnalysis ssjava; + /** * Constructor for Loop Termination Analysis */ - public LoopTerminate() { + public LoopTerminate(SSJavaAnalysis ssjava, State state) { + this.ssjava = ssjava; + this.state = state; this.inductionSet = new HashSet(); this.inductionVar2DefNode = new HashMap(); this.derivedVar2basicInduction = new HashMap(); @@ -93,10 +100,14 @@ public class LoopTerminate { assert loopEntrances.size() == 1; FlatNode loopEntrance = (FlatNode) loopEntrances.iterator().next(); - init(); - detectBasicInductionVar(loopElements); - detectDerivedInductionVar(loopElements); - checkConditionBranch(loopEntrance, loopElements); + String loopLabel = (String) state.fn2labelMap.get(loopEntrance); + + if (loopLabel == null || !loopLabel.startsWith(ssjava.TERMINATE)) { + init(); + detectBasicInductionVar(loopElements); + detectDerivedInductionVar(loopElements); + checkConditionBranch(loopEntrance, loopElements); + } } diff --git a/Robust/src/Analysis/SSJava/MethodAnnotationCheck.java b/Robust/src/Analysis/SSJava/MethodAnnotationCheck.java index bd585c07..5dbcc8ad 100644 --- a/Robust/src/Analysis/SSJava/MethodAnnotationCheck.java +++ b/Robust/src/Analysis/SSJava/MethodAnnotationCheck.java @@ -203,20 +203,10 @@ public class MethodAnnotationCheck { private void checkBlockNode(MethodDescriptor md, SymbolTable nametable, BlockNode bn, boolean flag) { bn.getVarTable().setParent(nametable); - String label = bn.getLabel(); - boolean isSSJavaLoop = flag; - if (label != null && label.equals(ssjava.SSJAVA)) { - if (isSSJavaLoop) { - throw new Error("Only outermost loop can be the self-stabilizing loop."); - } else { - annotatedMDSet.add(md); - isSSJavaLoop = true; - } - } for (int i = 0; i < bn.size(); i++) { BlockStatementNode bsn = bn.get(i); - checkBlockStatementNode(md, bn.getVarTable(), bsn, isSSJavaLoop); + checkBlockStatementNode(md, bn.getVarTable(), bsn, flag); } } @@ -285,9 +275,21 @@ public class MethodAnnotationCheck { } private void checkLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln, boolean flag) { + + String label = ln.getLabel(); + boolean isSSJavaLoop = flag; + if (label != null && label.equals(ssjava.SSJAVA)) { + if (isSSJavaLoop) { + throw new Error("Only outermost loop can be the self-stabilizing loop."); + } else { + annotatedMDSet.add(md); + isSSJavaLoop = true; + } + } + if (ln.getType() == LoopNode.WHILELOOP || ln.getType() == LoopNode.DOWHILELOOP) { - checkExpressionNode(md, nametable, ln.getCondition(), flag); - checkBlockNode(md, nametable, ln.getBody(), flag); + checkExpressionNode(md, nametable, ln.getCondition(), isSSJavaLoop); + checkBlockNode(md, nametable, ln.getBody(), isSSJavaLoop); } else { // For loop case /* Link in the initializer naming environment */ @@ -295,12 +297,12 @@ public class MethodAnnotationCheck { bn.getVarTable().setParent(nametable); for (int i = 0; i < bn.size(); i++) { BlockStatementNode bsn = bn.get(i); - checkBlockStatementNode(md, bn.getVarTable(), bsn, flag); + checkBlockStatementNode(md, bn.getVarTable(), bsn, isSSJavaLoop); } // check the condition - checkExpressionNode(md, bn.getVarTable(), ln.getCondition(), flag); - checkBlockNode(md, bn.getVarTable(), ln.getBody(), flag); - checkBlockNode(md, bn.getVarTable(), ln.getUpdate(), flag); + checkExpressionNode(md, bn.getVarTable(), ln.getCondition(), isSSJavaLoop); + checkBlockNode(md, bn.getVarTable(), ln.getBody(), isSSJavaLoop); + checkBlockNode(md, bn.getVarTable(), ln.getUpdate(), isSSJavaLoop); } } diff --git a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java index d294a192..a9f2e858 100644 --- a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java +++ b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java @@ -92,15 +92,15 @@ public class SSJavaAnalysis { } public void doCheck() { - doMethodAnnotationCheck(); - computeLinearTypeCheckMethodSet(); - doLinearTypeCheck(); - if (state.SSJAVADEBUG) { - debugPrint(); - } - parseLocationAnnotation(); - doFlowDownCheck(); - doDefinitelyWrittenCheck(); + doMethodAnnotationCheck(); + // computeLinearTypeCheckMethodSet(); + // doLinearTypeCheck(); + // if (state.SSJAVADEBUG) { + // debugPrint(); + // } + // parseLocationAnnotation(); + // doFlowDownCheck(); + // doDefinitelyWrittenCheck(); } public void addTrustMethod(MethodDescriptor md) { @@ -409,24 +409,12 @@ public class SSJavaAnalysis { } public void doLoopTerminationCheck(LoopOptimize lo, FlatMethod fm) { - LoopTerminate lt = new LoopTerminate(); + LoopTerminate lt = new LoopTerminate(this,state); if (needTobeAnnotated(fm.getMethod())) { lt.terminateAnalysis(fm, lo.getLoopInvariant(fm)); } } - public void doLoopTerminationCheck(LoopOptimize lo) { - LoopTerminate lt = new LoopTerminate(); - for (Iterator iterator = annotationRequireSet.iterator(); iterator.hasNext();) { - MethodDescriptor md = (MethodDescriptor) iterator.next(); - if (!skipLoopTerminate.containsKey(md)) { - FlatMethod fm = state.getMethodFlat(md); - lt.terminateAnalysis(fm, lo.getLoopInvariant(fm)); - } - } - - } - public CallGraph getCallGraph() { return callgraph; } diff --git a/Robust/src/IR/Flat/BuildFlat.java b/Robust/src/IR/Flat/BuildFlat.java index dab3af93..a600b71a 100644 --- a/Robust/src/IR/Flat/BuildFlat.java +++ b/Robust/src/IR/Flat/BuildFlat.java @@ -309,10 +309,6 @@ public class BuildFlat { NodePair np=flattenBlockStatementNode(bn.get(i)); FlatNode np_begin=np.getBegin(); FlatNode np_end=np.getEnd(); - if(bn.getLabel()!=null) { - // interim implementation to have the labeled statement - state.fn2labelMap.put(np_begin, bn.getLabel()); - } if (begin==null) { begin=np_begin; } @@ -1342,6 +1338,7 @@ public class BuildFlat { } private NodePair flattenLoopNode(LoopNode ln) { + HashSet oldbs=breakset; HashSet oldcs=continueset; breakset=new HashSet(); @@ -1383,6 +1380,9 @@ public class BuildFlat { } breakset=oldbs; continueset=oldcs; + if(ln.getLabel()!=null){ + state.fn2labelMap.put(condition.getBegin(), ln.getLabel()); + } return new NodePair(begin,nopend); } else if (ln.getType()==LoopNode.WHILELOOP) { TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN)); @@ -1416,6 +1416,9 @@ public class BuildFlat { } breakset=oldbs; continueset=oldcs; + if(ln.getLabel()!=null){ + state.fn2labelMap.put(begin, ln.getLabel()); + } return new NodePair(begin,nopend); } else if (ln.getType()==LoopNode.DOWHILELOOP) { TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN)); @@ -1448,6 +1451,9 @@ public class BuildFlat { } breakset=oldbs; continueset=oldcs; + if(ln.getLabel()!=null){ + state.fn2labelMap.put(condition.getBegin(), ln.getLabel()); + } return new NodePair(begin,nopend); } else throw new Error(); } diff --git a/Robust/src/IR/Tree/BlockNode.java b/Robust/src/IR/Tree/BlockNode.java index 992928fb..e44e42de 100644 --- a/Robust/src/IR/Tree/BlockNode.java +++ b/Robust/src/IR/Tree/BlockNode.java @@ -11,8 +11,6 @@ public class BlockNode extends TreeNode { public final static int NOBRACES=1; public final static int EXPRLIST=2; - String label=null; - public BlockNode() { blockstatements=new Vector(); table=new SymbolTable(); @@ -88,12 +86,4 @@ public class BlockNode extends TreeNode { return Kind.BlockNode; } - public void setLabel(String l) { - label=l; - } - - public String getLabel() { - return label; - } - } diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index f81d8bb9..cc3845eb 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1341,15 +1341,19 @@ public class BuildIR { return bn; } - public BlockNode parseSingleBlock(ParseNode pn) { + public BlockNode parseSingleBlock(ParseNode pn, String label){ BlockNode bn=new BlockNode(); - Vector bsv=parseBlockStatement(pn); + Vector bsv=parseBlockStatement(pn,label); for(int j=0; j