scale.score.chords
Class LoopExitChord

java.lang.Object
  extended by scale.common.Root
      extended by scale.score.Note
          extended by scale.score.chords.Chord
              extended by scale.score.chords.SequentialChord
                  extended by scale.score.chords.LoopExitChord
All Implemented Interfaces:
AnnotationInterface, DisplayNode

public class LoopExitChord
extends SequentialChord

This class is used to mark the exit point of loops.

$Id: LoopExitChord.java,v 1.32 2006-02-28 16:37:08 burrill Exp $

Copyright 2005 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

This class represents a non-action. No code is generated for this node. Not all loops have LoopExitChord nodes. Some may have more than one.

 int sumfor2(int n)
 {
   int sum, i;
   sum = 0;
   for (i = 0; i < n; i++) {
     sum += i;
     if (sum > 100)
       return -1;
   }
   return sum;
 }
 
 

Loop with Two Exits

See Also:
LoopHeaderChord, LoopPreHeaderChord, LoopHeaderChord, LoopTailChord, LoopInitChord

Field Summary
 
Fields inherited from class scale.score.chords.Chord
lineNumber
 
Constructor Summary
LoopExitChord(LoopHeaderChord header)
           
LoopExitChord(LoopHeaderChord header, Chord next)
           
 
Method Summary
 Chord copy()
          Make a copy of this CFG node with the same out-going CFG edges.
 LoopExitChord findLoopExit(LoopHeaderChord header)
          Return the LoopExitChord, for the specified loop, that is reachable from this Chord.
 DColor getDisplayColorHint()
          Return a String specifying the color to use for coloring this node in a graphical display.
 LoopHeaderChord getLoopHeader()
          Return the LoopHeaderChord associated with this loop exit.
 boolean isLoopExit()
          Return true if this chord is a LoopExitChord.
 boolean isSpecial()
          Return true if this is chord was added for the convenience of the compiler and does not correspond to actual source code in the user program.
 void setLoopHeader(LoopHeaderChord header)
          Specify the loop header of this loop.
 java.lang.String toStringSpecial()
          Return a String containing additional information about this Chord.
 void unlinkChord()
          Break any un-needed links from a Chord that is being deleted.
 void validate()
          Check this node for validity.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.score.chords.SequentialChord
changeOutCfgEdge, clearEdge, clearEdgeMarkers, deleteInDataEdges, deleteOutCfgEdges, edgeMarked, executionCostEstimate, getDeclList, getExprList, getLoadExprList, getNextChord, getOutCfgEdge, getOutCfgEdgeArray, getTarget, indexOfOutCfgEdge, isLastInBasicBlock, isSequential, linkSubgraph, linkTo, markEdge, numOutCfgEdges, pushAllOutCfgEdges, pushOutCfgEdges, pushOutCfgEdges, pushSortedOutCfgEdges, pushSortedOutCfgEdges, removeUseDef, replaceDecl, replaceOutCfgEdge, setTarget, setTargetUnsafe
 
Methods inherited from class scale.score.chords.Chord
addInCfgEdge, changeInDataEdge, changeParentOutCfgEdge, copySourceLine, deadCFGNodes, deletedCFGNodes, deleteInCfgEdge, executionOrder, expungeFromCfg, extractFromCfg, findPhiChords, firstInBasicBlock, getCall, getDefExpr, getDisplayLabel, getDisplayShapeHint, getFirstInCfgEdge, getInCfgEdge, getInCfgEdge, getInCfgEdgeArray, getInDataEdge, getInDataEdgeArray, getLabel, getLoopHeader, getLoopNumber, getSourceLineNumber, gotoCFGNodes, inBasicBlock, indexOfInCfgEdge, insertAfterOutCfg, insertBeforeInCfg, isAssignChord, isBranch, isExprChord, isFirstInBasicBlock, isLoopHeader, isLoopPreHeader, isLoopTail, isMarker, isPhiExpr, lastInBasicBlock, loopClean, nextVisit, nthIndexOfInCfgEdge, nullCFGNodes, numInCfgEdges, numInDataEdges, numOfInCfgEdge, parentsFinished, parentsVisited, pushAllInCfgEdges, pushChordWhenReady, pushChordWhenReady, pushInCfgEdges, pushInCfgEdges, pushInDataEdges, recordRefs, removeDeadCode, removeDualExprs, removeFromCfg, removeRefs, reorderInCfgEdgesOfCopy, replaceInCfgEdge, setLabel, setSourceLineNumber, setVisited, visited
 
Methods inherited from class scale.score.Note
getChord, getEssentialUse, setAnnotationLevel, setReportLevel, toString
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, hashCode, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, trace, trace, trace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LoopExitChord

public LoopExitChord(LoopHeaderChord header,
                     Chord next)

LoopExitChord

public LoopExitChord(LoopHeaderChord header)
Method Detail

getLoopHeader

public LoopHeaderChord getLoopHeader()
Return the LoopHeaderChord associated with this loop exit.

Overrides:
getLoopHeader in class Chord

setLoopHeader

public void setLoopHeader(LoopHeaderChord header)
Specify the loop header of this loop.

Parameters:
header - is the loop header of this loop

copy

public Chord copy()
Description copied from class: Chord
Make a copy of this CFG node with the same out-going CFG edges. The validity of the CFG graph is maintained.

Specified by:
copy in class Chord
Returns:
a copy of this node

unlinkChord

public void unlinkChord()
Break any un-needed links from a Chord that is being deleted.

Overrides:
unlinkChord in class Chord

isSpecial

public boolean isSpecial()
Return true if this is chord was added for the convenience of the compiler and does not correspond to actual source code in the user program.

Overrides:
isSpecial in class Chord

isLoopExit

public final boolean isLoopExit()
Return true if this chord is a LoopExitChord.

Overrides:
isLoopExit in class Chord

visit

public void visit(Predicate p)
Description copied from class: Note
Process a node by calling its associated routine. See the "visitor" design pattern in Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma, et al, Addison Wesley, ISBN 0-201-63361-2.

Each class has a visit(Predicate p) method. For example, in class ABC:

   public void visit(Predicate p)
   {
     p.visitABC(this);
   }
 
and the class that implements Predicate has a method
   public void visitABC(Note n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements Predicate can call
   n.visit(this);
 
where n is a Note sub-class without determining which specific sub-class n is. The visit pattern basically avoids implementing a large switch statement or defining different methods in each class for some purpose.

Specified by:
visit in class Note
See Also:
Predicate

toStringSpecial

public java.lang.String toStringSpecial()
Return a String containing additional information about this Chord.

Overrides:
toStringSpecial in class Chord

findLoopExit

public final LoopExitChord findLoopExit(LoopHeaderChord header)
Return the LoopExitChord, for the specified loop, that is reachable from this Chord. Return null if none is found.

Overrides:
findLoopExit in class Chord

getDisplayColorHint

public DColor getDisplayColorHint()
Return a String specifying the color to use for coloring this node in a graphical display.

Specified by:
getDisplayColorHint in interface DisplayNode
Overrides:
getDisplayColorHint in class Chord
See Also:
DColor

validate

public void validate()
Check this node for validity. This method throws an exception if the node is not linked properly.

Overrides:
validate in class Note