org.jikesrvm.compilers.opt.ir
Class BasicBlock

java.lang.Object
  extended by org.jikesrvm.compilers.opt.util.SpaceEffGraphNode
      extended by org.jikesrvm.compilers.opt.util.SortedGraphNode
          extended by org.jikesrvm.compilers.opt.ir.BasicBlock
All Implemented Interfaces:
GraphElement, GraphNode
Direct Known Subclasses:
ExceptionHandlerBasicBlock

public class BasicBlock
extends SortedGraphNode

A basic block in the Factored Control Flow Graph (FCFG).

Just like in a standard control flow graph (CFG), a FCFG basic block contains a linear sequence of instructions. However, in the FCFG, a Potentially Excepting Instruction (PEI) does not necessarily end its basic block. Therefore, although instructions within a FCFG basic block have the expected dominance relationships, they do not have the same post-dominance relationships as they would under the traditional basic block formulation used in a CFG. We chose to use an FCFG because doing so significantly reduces the number of basic blocks and control flow graph edges, thus reducing the time and space costs of representing the FCFG and also increasing the effectiveness of local (within a single basic block) analysis. However, using an FCFG does complicate flow-sensitive global analaysis. Many analyses can be easily extended to work on the FCFG. For those analyses that cannot, we provide utilities (IR.unfactor(), unfactor(IR)) to effectively convert the FCFG into a CFG. For a more detailed description of the FCFG and its implications for program analysis see the PASTE'99 paper by Choi et al. Efficient and Precise Modeling of Exceptions for the Analysis of Java Programs

The instructions in a basic block have the following structure

CALL instructions do not end their basic block. ATHROW instructions do end their basic block. Conventionally, we refer to the real instructions of the block as those that are between the LABEL and the BBEND. We say that the block is empty if it contains no real instructions.

See Also:
IR, Instruction, ControlFlowGraph

Nested Class Summary
(package private) static class BasicBlock.BBEnum
           
(package private) static class BasicBlock.ComputedBBEnum
           
(package private) static class BasicBlock.ExceptionOutEdgeEnum
           
(package private) static class BasicBlock.InEdgeEnum
           
(package private)  class BasicBlock.NormalOutEdgeEnum
           
(package private) static class BasicBlock.OutEdgeEnum
           
 
Nested classes/interfaces inherited from class org.jikesrvm.compilers.opt.util.SpaceEffGraphNode
SpaceEffGraphNode.GraphEdgeEnumeration<T extends GraphEdge>, SpaceEffGraphNode.OutEdgeEnumeration
 
Field Summary
(package private) static short CAN_THROW_EXCEPTIONS
          Bitfield used in flag encoding
(package private)  Instruction end
          Last instruction of the basic block (BBEND).
(package private) static short EXCEPTION_HANDLER
          Bitfield used in flag encoding
(package private) static short EXCEPTION_HANDLER_WITH_NORMAL_IN
          Bitfield used in flag encoding
 ExceptionHandlerBasicBlockBag exceptionHandlers
          Encodes exception handler info for this block.
protected  short flags
          Used to encode various properties of the block.
protected  float freq
          Relative execution frequency of this basic block.
(package private) static short IMPLICIT_EXIT_EDGE
          Bitfield used in flag encoding
(package private) static short INFREQUENT
          Bitfield used in flag encoding
(package private) static short LANDING_PAD
          Bitfield used in flag encoding
(package private) static short REACHABLE_FROM_EXCEPTION_HANDLER
          Bitfield used in flag encoding
(package private) static short SCRATCH
          Bitfield used in flag encoding
(package private)  Instruction start
          First instruction of the basic block (LABEL).
(package private) static short UNSAFE_TO_SCHEDULE
          Bitfield used in flag encoding
 
Fields inherited from class org.jikesrvm.compilers.opt.util.SortedGraphNode
backwardSortNumber, forwardSortNumber, sortedNext, sortedPrev
 
Fields inherited from class org.jikesrvm.compilers.opt.util.SpaceEffGraphNode
_inEdgeEnd, _inEdgeStart, _outEdgeEnd, _outEdgeStart, info, next, nextSorted, prev, scratch, scratchObject
 
Constructor Summary
private BasicBlock()
          This constructor is only used for creating an EXIT node
  BasicBlock(int i, InlineSequence position, ControlFlowGraph cfg)
          Creates a new basic block at the specified location.
protected BasicBlock(int i, InlineSequence position, int num)
          Creates a new basic block at the specified location with the given basic block number.
 
Method Summary
private  void addTargets(BasicBlock.ComputedBBEnum e, TypeReference thrownException)
           
 void appendInstruction(Instruction i)
          Append instruction to this basic block by inserting it right before the BBEND instruction in the instruction list.
 void appendInstructionRespectingTerminalBranch(Instruction i)
          Append instruction to this basic block by inserting it right before the BBEND instruction in the instruction list.
 void appendInstructionRespectingTerminalBranchOrPEI(Instruction i)
          Append instruction to this basic block by inserting it right before the BBEND instruction in the instruction list.
 void augmentExecutionFrequency(float f)
          Augment the estimated relative execution frequency of this block.
 boolean canThrowExceptions()
          Can this block possibly throw an exception?
 void clearCanThrowExceptions()
          Clear the may raise an exception property of the block
 void clearExceptionHandlerBasicBlock()
          Clear the block is the first one in an exception handler property of the block.
 void clearInfrequent()
          Clear the infrequently executed property of the block
 void clearLandingPad()
          Clear the landing pad property of the block
 void clearMayThrowUncaughtException()
          Clear the may raise uncaught exception property of the block
 void clearReachableFromExceptionHandler()
          Clear the block is reachable from an exception handler property of the block.
 void clearScratchFlag()
          Clear the scratch flag.
 void clearUnsafeToSchedule()
          Clear the unsafe to schedule property of the block
 BasicBlock copyWithoutLinks(IR ir)
          Copies a basic block.
 BasicBlock createSubBlock(int bc, IR ir)
           
 BasicBlock createSubBlock(int bc, IR ir, float wf)
          Creates a new basic block that inherits its exception handling, etc from 'this'.
private  void deleteExceptionalOut()
           
 void deleteNormalOut()
          Delete all the non-exceptional out edges.
 void discardInstructions()
           
 Enumeration<Instruction> enumerateBranchInstructions()
          Return an enumeration of the branch instructions in this basic block.
 LiveIntervalEnumeration enumerateLiveIntervals()
           
 Instruction firstBranchInstruction()
          Return the first branch instruction in the block.
 Instruction firstInstruction()
           
 Instruction firstRealInstruction()
           
 Enumeration<Instruction> forwardInstrEnumerator()
          Forward enumeration of all the instruction in the block.
 Enumeration<Instruction> forwardRealInstrEnumerator()
          Forward enumeration of all the real instruction in the block.
 Enumeration<BasicBlock> getApplicableExceptionalOut(Instruction instr)
          An enumeration of the subset of exceptional out edges that are applicable to the given instruction (assumed to be in instruction in 'this')
 Enumeration<BasicBlock> getExceptionalOut()
          An enumeration of the 'exceptional' (reached via exceptional control flow) out nodes of the block.
 Enumeration<BasicBlock> getExceptionHandlers()
          An enumeration of the in scope exception handlers for this basic block.
 float getExecutionFrequency()
          Return the estimated relative execution frequency of the block
 BasicBlock getFallThroughBlock()
          If there is a fallthrough FCFG successor of this node return it.
 LiveIntervalElement getFirstLiveIntervalElement()
          Returns NULL or an LiveIntervalElement (GCMaps/RegAlloc).
 Enumeration<BasicBlock> getIn()
          An enumeration of the FCFG in nodes.
 boolean getInfrequent()
          Has the block been marked as being infrequently executed?
 Enumeration<BasicBlock> getInNodes()
          An enumeration of the FCFG in nodes.
 boolean getLandingPad()
          Has the block been marked as landing pad?
 Enumeration<BasicBlock> getNormalOut()
          An enumeration of the 'normal' (not reached via exceptional control flow) out nodes of the block.
 BasicBlock getNotTakenNextBlock()
           
 int getNumberOfExceptionalOut()
          Get the number of out nodes that are to exception handler basic blocks
 int getNumberOfNormalOut()
          Get the number of out nodes that are to "normal" basic blocks
 int getNumberOfRealInstructions()
          How many real instructions does the block contain?
 BasicBlock.OutEdgeEnum getOut()
          An enumeration of the FCFG out nodes.
 BasicBlock.OutEdgeEnum getOutNodes()
          An enumeration of the FCFG out nodes.
 Enumeration<BasicBlock> getReachableExceptionHandlers()
          Returns an Enumeration of the in scope exception handlers that are actually reachable from this basic block in the order that they are applicable (which is semantically meaningful).
 boolean getScratchFlag()
          Is the scratch flag set on the block?
 boolean hasApplicableExceptionalOut(Instruction instr)
          Are there any exceptional out edges that are applicable to the given instruction (assumed to be in instruction in 'this')
 boolean hasAthrowInst()
          Does this basic block contain an explicit athrow instruction?
 boolean hasExceptionHandlers()
          Is this block in the scope of at least exception handler?
 boolean hasGoto()
          Does this basic block end in a GOTO instruction?
 boolean hasNonReturningCall()
          Does this basic block end in a call that never returns?
 boolean hasNonReturningOsr()
           
 boolean hasReachableExceptionHandlers()
          Are there exceptinal handlers that are reachable via exceptional control flow from this basic block?
 boolean hasReturn()
          Does this basic block end in a RETURN instruction?
 boolean hasSwitch()
          Does this basic block end in a SWITCH instruction?
 boolean hasTrap()
          Does this basic block end in an explicit trap?
 void initializeLiveRange()
          Clear the scratch object from previous uses (rename scratchObject manipulations for GCMaps/RegAlloc).
(package private)  void initInOutSets()
           
 boolean isEmpty()
          Returns true if the block contains no real instructions
 boolean isExceptionalOut(BasicBlock bb)
          Is there an 'exceptional' out edge to the given basic block?
 boolean isExceptionHandlerBasicBlock()
          Is this block the first basic block in an exception handler?
 boolean isExceptionHandlerEquivalent(BasicBlock other)
          Compare the in scope exception handlers of two blocks.
 boolean isExceptionHandlerWithNormalIn()
           
 boolean isExit()
          Is this block the exit basic block?
 boolean isIn(BasicBlock bb)
          Is there an in edge from the given basic block?
 boolean isNormalOut(BasicBlock bb)
          Is there a 'normal' out edge to the given basic block?
 boolean isOut(BasicBlock bb)
          Is there an out edge to the given basic block?
 boolean isReachableFromExceptionHandler()
          Has the block been marked as being reachable from an exception handler?
 boolean isUnsafeToSchedule()
          Has the block been marked as being unsafe to schedule (due to the presence of Magic)?
 void killFallThrough()
          Replace fall through in this block by an explicit goto
 Instruction lastInstruction()
           
 Instruction lastRealInstruction()
           
(package private) static BasicBlock makeExit()
          Make an EXIT node.
 Instruction makeGOTO()
          Make a GOTO instruction, branching to the first instruction of this basic block.
 BranchOperand makeJumpTarget()
          Make a branch operand with the label instruction of this block.
 boolean mayThrowUncaughtException()
          Can a PEI in this block possibly raise an uncaught exception?
 boolean mergeFallThrough(IR ir)
          If this block has a single non-Exception successor in the CFG then we may be able to merge the two blocks together.
 void moveBehind(BasicBlock pred, IR ir)
          Move me behind `pred'.
 BasicBlock nextBasicBlockInCodeOrder()
          Return the next basic block in with respect to the current code linearization order.
 void prependInstruction(Instruction i)
          Prepend instruction to this basic block by inserting it right after the LABEL instruction in the instruction list.
 void prependInstructionRespectingPrologue(Instruction i)
          Prepend instruction to this basic block but respect the prologue instruction, which must come first.
 void prependLiveIntervalElement(LiveIntervalElement li)
          Prepend a live interval element to the list being maintained in scratchObject (GCMaps/RegAlloc).
 BasicBlock prevBasicBlockInCodeOrder()
          Return the previous basic block in with respect to the current code linearization order.
 void printExtended()
          Print a detailed dump of the block to the sysWrite stream
(package private)  void pruneExceptionalOut(IR ir)
          Prune away exceptional out edges that are not reachable given this block's instructions.
 void recomputeNormalOut(IR ir)
          Recompute the normal out edges of 'this' based on the semantics of the branch instructions in the block.
 void redirectOuts(BasicBlock b, BasicBlock bCopy, IR ir)
          Change all branches from this to b to branches that go to bCopy instead.
 void replicateNormalOut(IR ir)
          For each basic block b which is a "normal" successor of this, make a copy of b, and set up the CFG so that this block has normal out edges to the copies.
 BasicBlock replicateThisOut(IR ir, BasicBlock b)
          For basic block b which has to be a "normal" successor of this, make a copy of b, and set up the CFG so that this block has normal out edges to the copy.
 BasicBlock replicateThisOut(IR ir, BasicBlock b, BasicBlock pred)
          For basic block b which has to be a "normal" successor of this, make a copy of b, and set up the CFG so that this block has normal out edges to the copy.
 Enumeration<Instruction> reverseInstrEnumerator()
          Reverse enumeration of all the instruction in the block.
 Enumeration<Instruction> reverseRealInstrEnumerator()
          Reverse enumeration of all the real instruction in the block.
 void scaleExecutionFrequency(float f)
          Scale the estimated relative execution frequency of this block.
 BasicBlock segregateInstruction(Instruction target, IR ir)
          Ensure that the target instruction is the only real instruction in its basic block and that it has exactly one successor and one predecessor basic blocks that are linked to it by fall through edges.
 void setCanThrowExceptions()
          Mark the block as possibly raising an exception.
private  void setCanThrowExceptions(boolean v)
           
 void setExceptionHandlerBasicBlock()
          Mark the block as the first block in an exception handler.
 void setExceptionHandlerWithNormalIn()
           
 void setExecutionFrequency(float f)
          Set the estimated relative execution frequency of this block.
 void setInfrequent()
          Mark the block as being infrequently executed.
(package private)  void setInfrequent(boolean v)
           
private  void setIsExceptionHandlerBasicBlock(boolean v)
           
 void setLandingPad()
          Mark the block as a landing pad for loop invariant code motion.
 void setMayThrowUncaughtException()
          Mark the block as possibly raising an uncaught exception.
private  void setMayThrowUncaughtException(boolean v)
           
 void setReachableFromExceptionHandler()
          Mark the block as being reachable from an exception handler.
 void setScratchFlag()
          Set the scratch flag
 void setUnsafeToSchedule()
          Mark the block as being unsafe to schedule.
private  void setUnsafeToSchedule(boolean v)
           
 BasicBlock splitNodeAt(Instruction last_instr_BB1, IR ir)
          Splits a node at an instruction point.
 BasicBlock splitNodeWithLinksAt(Instruction last_instr_BB1, IR ir)
          Splits a node at an instruction point.
 String toString()
          Returns the string representation of this basic block.
(package private)  void unfactor(IR ir)
          Convert a block in the FCFG into the equivalent set of CFG blocks by splitting the original block into sub-blocks at each PEI that reaches at least one exception handelr.
 
Methods inherited from class org.jikesrvm.compilers.opt.util.SortedGraphNode
getBackwardSortedNext, getBackwardSortNumber, getForwardSortedNext, getForwardSortNumber, getNewSortMarker, getSortedNext, getSortMarker, getSortNumber, isSortMarkedWith, setBackwardSortNumber, setForwardSortNumber, setSortedNext, setSortMarker, setSortNumber, setSortNumber
 
Methods inherited from class org.jikesrvm.compilers.opt.util.SpaceEffGraphNode
_sortDFS, _sortRevTop, _sortTop, append, appendInEdge, appendOutEdge, clearDfsVisited, clearFlags, clearInFlags, clearLoopHeader, clearOnStack, clearOutFlags, clearTopVisited, deleteIn, deleteOut, deleteOut, deleteOut, dfsVisited, findOutEdgeTo, firstInEdge, firstInNode, firstOutEdge, firstOutNode, flagsOn, getIndex, getNext, getNumber, getNumberOfIn, getNumberOfOut, getPrev, getScratch, hasIn, hasOneIn, hasOneIn, hasOneOut, hasOneOut, hasOut, hasZeroIn, hasZeroOut, inEdges, inNodes, insertOut, insertOut, isLoopHeader, markDFN, markSCC, onStack, outEdges, outNodes, pointsIn, pointsOut, printInEdges, printInNodes, printOutEdges, printOutNodes, remove, removeIn, removeIn, removeOut, removeOut, replaceInEdge, replaceOut, setDfsVisited, setDfsVisitedOnStack, setIndex, setLoopHeader, setNumber, setOnStack, setScratch, setTopVisited, sortDFS, sortRevTop, sortTop, topVisited
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CAN_THROW_EXCEPTIONS

static final short CAN_THROW_EXCEPTIONS
Bitfield used in flag encoding

See Also:
Constant Field Values

IMPLICIT_EXIT_EDGE

static final short IMPLICIT_EXIT_EDGE
Bitfield used in flag encoding

See Also:
Constant Field Values

EXCEPTION_HANDLER

static final short EXCEPTION_HANDLER
Bitfield used in flag encoding

See Also:
Constant Field Values

REACHABLE_FROM_EXCEPTION_HANDLER

static final short REACHABLE_FROM_EXCEPTION_HANDLER
Bitfield used in flag encoding

See Also:
Constant Field Values

UNSAFE_TO_SCHEDULE

static final short UNSAFE_TO_SCHEDULE
Bitfield used in flag encoding

See Also:
Constant Field Values

INFREQUENT

static final short INFREQUENT
Bitfield used in flag encoding

See Also:
Constant Field Values

SCRATCH

static final short SCRATCH
Bitfield used in flag encoding

See Also:
Constant Field Values

LANDING_PAD

static final short LANDING_PAD
Bitfield used in flag encoding

See Also:
Constant Field Values

EXCEPTION_HANDLER_WITH_NORMAL_IN

static final short EXCEPTION_HANDLER_WITH_NORMAL_IN
Bitfield used in flag encoding

See Also:
Constant Field Values

flags

protected short flags
Used to encode various properties of the block.


exceptionHandlers

public ExceptionHandlerBasicBlockBag exceptionHandlers
Encodes exception handler info for this block. May be shared if multiple blocks have exactly the same chain of exception handlers.


start

final Instruction start
First instruction of the basic block (LABEL).


end

final Instruction end
Last instruction of the basic block (BBEND).


freq

protected float freq
Relative execution frequency of this basic block. The entry block to a CFG has weight 1.0;

Constructor Detail

BasicBlock

public BasicBlock(int i,
                  InlineSequence position,
                  ControlFlowGraph cfg)
Creates a new basic block at the specified location. It initially contains a single label instruction pointed to by start and a BBEND instruction pointed to by end.

Parameters:
i - bytecode index to create basic block at
position - the inline context for this basic block
cfg - the FCFG that will contain the basic block

BasicBlock

protected BasicBlock(int i,
                     InlineSequence position,
                     int num)
Creates a new basic block at the specified location with the given basic block number. It initially contains a single label instruction pointed to by start and a BBEND instruction pointed to by end. WARNING: Don't call this constructor directly if the created basic block is going to be in some control flow graph, since it may not get assigned a unique number.

Parameters:
i - bytecode index to create basic block at
position - the inline context for this basic block
num - the number to assign the basic block

BasicBlock

private BasicBlock()
This constructor is only used for creating an EXIT node

Method Detail

initInOutSets

final void initInOutSets()

makeExit

static BasicBlock makeExit()
Make an EXIT node.


toString

public String toString()
Returns the string representation of this basic block.

Overrides:
toString in class Object
Returns:
a String that is the name of the block.

printExtended

public final void printExtended()
Print a detailed dump of the block to the sysWrite stream

Overrides:
printExtended in class SpaceEffGraphNode

initializeLiveRange

public final void initializeLiveRange()
Clear the scratch object from previous uses (rename scratchObject manipulations for GCMaps/RegAlloc).


enumerateLiveIntervals

public final LiveIntervalEnumeration enumerateLiveIntervals()
Returns:
an enumeration of the live interval elements for this basic block.

getFirstLiveIntervalElement

public final LiveIntervalElement getFirstLiveIntervalElement()
Returns NULL or an LiveIntervalElement (GCMaps/RegAlloc).

Returns:
scratchObject cast as an LiveIntevalElement

prependLiveIntervalElement

public final void prependLiveIntervalElement(LiveIntervalElement li)
Prepend a live interval element to the list being maintained in scratchObject (GCMaps/RegAlloc).

Parameters:
li - the live interval element to add

canThrowExceptions

public final boolean canThrowExceptions()
Can this block possibly throw an exception? May conservatively return true even if the block does not contain a PEI.

Returns:
true if the block might raise an exception or false if it cannot

mayThrowUncaughtException

public final boolean mayThrowUncaughtException()
Can a PEI in this block possibly raise an uncaught exception? May conservatively return true even if the block does not contain a PEI. When this is true it implies that there is an implicit edge from this node to the exit node in the FCFG.

NOTE: This method says nothing about the presence/absence of an explicit throw of an uncaught exception, and thus does not rule out the block having an explicit edge to the exit node caused by a throw of an uncaught exception.

Returns:
true if the block might raise an exception uncaught or false if it cannot

isExceptionHandlerBasicBlock

public final boolean isExceptionHandlerBasicBlock()
Is this block the first basic block in an exception handler? NOTE: This doesn't seem particularly useful to me anymore, since it is the same as asking if the block is an instanceof and ExceptionHandlerBasicBlock. Perhaps we should phase this out?

Returns:
true if the block is the first block in an exception hander or false if it is not

isReachableFromExceptionHandler

public final boolean isReachableFromExceptionHandler()
Has the block been marked as being reachable from an exception handler?

Returns:
true if the block is reachable from an exception hander or false if it is not

isExceptionHandlerEquivalent

public final boolean isExceptionHandlerEquivalent(BasicBlock other)
Compare the in scope exception handlers of two blocks.

Parameters:
other - block to be compared to this.
Returns:
true if this and other have equivalent in scope exception handlers.

isUnsafeToSchedule

public final boolean isUnsafeToSchedule()
Has the block been marked as being unsafe to schedule (due to the presence of Magic)?

Returns:
true if the block is marked as unsafe to schedule or false if it is not

getInfrequent

public final boolean getInfrequent()
Has the block been marked as being infrequently executed? NOTE: Only blocks that are truly icy cold should be marked as infrequent.

Returns:
true if the block is marked as infrequently executed or false if it is not

getScratchFlag

public final boolean getScratchFlag()
Is the scratch flag set on the block?

Returns:
true if the block scratch flag is set or false if it is not

getLandingPad

public final boolean getLandingPad()
Has the block been marked as landing pad?

Returns:
true if the block is marked as landing pad or false if it is not

setCanThrowExceptions

public final void setCanThrowExceptions()
Mark the block as possibly raising an exception.


setMayThrowUncaughtException

public final void setMayThrowUncaughtException()
Mark the block as possibly raising an uncaught exception.


setExceptionHandlerBasicBlock

public final void setExceptionHandlerBasicBlock()
Mark the block as the first block in an exception handler.


setReachableFromExceptionHandler

public final void setReachableFromExceptionHandler()
Mark the block as being reachable from an exception handler.


setUnsafeToSchedule

public final void setUnsafeToSchedule()
Mark the block as being unsafe to schedule.


setInfrequent

public final void setInfrequent()
Mark the block as being infrequently executed.


setScratchFlag

public final void setScratchFlag()
Set the scratch flag


setLandingPad

public final void setLandingPad()
Mark the block as a landing pad for loop invariant code motion.


clearCanThrowExceptions

public final void clearCanThrowExceptions()
Clear the may raise an exception property of the block


clearMayThrowUncaughtException

public final void clearMayThrowUncaughtException()
Clear the may raise uncaught exception property of the block


clearExceptionHandlerBasicBlock

public final void clearExceptionHandlerBasicBlock()
Clear the block is the first one in an exception handler property of the block.


clearReachableFromExceptionHandler

public final void clearReachableFromExceptionHandler()
Clear the block is reachable from an exception handler property of the block.


clearUnsafeToSchedule

public final void clearUnsafeToSchedule()
Clear the unsafe to schedule property of the block


clearInfrequent

public final void clearInfrequent()
Clear the infrequently executed property of the block


clearScratchFlag

public final void clearScratchFlag()
Clear the scratch flag.


clearLandingPad

public final void clearLandingPad()
Clear the landing pad property of the block


setCanThrowExceptions

private void setCanThrowExceptions(boolean v)

setMayThrowUncaughtException

private void setMayThrowUncaughtException(boolean v)

setIsExceptionHandlerBasicBlock

private void setIsExceptionHandlerBasicBlock(boolean v)

setUnsafeToSchedule

private void setUnsafeToSchedule(boolean v)

setInfrequent

final void setInfrequent(boolean v)

setExceptionHandlerWithNormalIn

public final void setExceptionHandlerWithNormalIn()

isExceptionHandlerWithNormalIn

public final boolean isExceptionHandlerWithNormalIn()

makeJumpTarget

public final BranchOperand makeJumpTarget()
Make a branch operand with the label instruction of this block.

Returns:
an BranchOperand holding this blocks label

makeGOTO

public final Instruction makeGOTO()
Make a GOTO instruction, branching to the first instruction of this basic block.

Returns:
a GOTO instruction that jumps to this block

firstInstruction

public final Instruction firstInstruction()
Returns:
the first instruciton of the basic block (the label)

firstRealInstruction

public final Instruction firstRealInstruction()
Returns:
the first 'real' instruction of the basic block; null if the block is empty

lastInstruction

public final Instruction lastInstruction()
Returns:
the last instruction of the basic block (the BBEND)

lastRealInstruction

public final Instruction lastRealInstruction()
Returns:
the last 'real' instruction of the basic block; null if the block is empty

getExecutionFrequency

public final float getExecutionFrequency()
Return the estimated relative execution frequency of the block


setExecutionFrequency

public final void setExecutionFrequency(float f)
Set the estimated relative execution frequency of this block.


scaleExecutionFrequency

public final void scaleExecutionFrequency(float f)
Scale the estimated relative execution frequency of this block.


augmentExecutionFrequency

public final void augmentExecutionFrequency(float f)
Augment the estimated relative execution frequency of this block.


isExit

public final boolean isExit()
Is this block the exit basic block?

Returns:
true if this block is the EXIT or false if it is not

forwardInstrEnumerator

public final Enumeration<Instruction> forwardInstrEnumerator()
Forward enumeration of all the instruction in the block.

Returns:
a forward enumeration of the block's instructons.

reverseInstrEnumerator

public final Enumeration<Instruction> reverseInstrEnumerator()
Reverse enumeration of all the instruction in the block.

Returns:
a reverse enumeration of the block's instructons.

forwardRealInstrEnumerator

public final Enumeration<Instruction> forwardRealInstrEnumerator()
Forward enumeration of all the real instruction in the block.

Returns:
a forward enumeration of the block's real instructons.

reverseRealInstrEnumerator

public final Enumeration<Instruction> reverseRealInstrEnumerator()
Reverse enumeration of all the real instruction in the block.

Returns:
a reverse enumeration of the block's real instructons.

getNumberOfRealInstructions

public int getNumberOfRealInstructions()
How many real instructions does the block contain? WARNING: This method actually counts the instructions, thus it has a linear time complexity!

Returns:
the number of "real" instructions in this basic block.

hasGoto

public final boolean hasGoto()
Does this basic block end in a GOTO instruction?

Returns:
true if the block ends in a GOTO or false if it does not

hasReturn

public final boolean hasReturn()
Does this basic block end in a RETURN instruction?

Returns:
true if the block ends in a RETURN or false if it does not

hasSwitch

public final boolean hasSwitch()
Does this basic block end in a SWITCH instruction?

Returns:
true if the block ends in a SWITCH or false if it does not

hasAthrowInst

public final boolean hasAthrowInst()
Does this basic block contain an explicit athrow instruction?

Returns:
true if the block ends in an explicit Athrow instruction or false if it does not

hasTrap

public final boolean hasTrap()
Does this basic block end in an explicit trap?

Returns:
true if the block ends in a an explicit trap or false if it does not

hasNonReturningCall

public final boolean hasNonReturningCall()
Does this basic block end in a call that never returns? (For example, a call to athrow())

Returns:
true if the block ends in a call that never returns or false if it does not

hasNonReturningOsr

public final boolean hasNonReturningOsr()

getFallThroughBlock

public final BasicBlock getFallThroughBlock()
If there is a fallthrough FCFG successor of this node return it.

Returns:
the fall-through successor of this node or null if none exists

getNotTakenNextBlock

public final BasicBlock getNotTakenNextBlock()
Returns:
the FCFG successor if all conditional branches in this are not taken

killFallThrough

public void killFallThrough()
Replace fall through in this block by an explicit goto


prependInstruction

public final void prependInstruction(Instruction i)
Prepend instruction to this basic block by inserting it right after the LABEL instruction in the instruction list.

Parameters:
i - instruction to append

prependInstructionRespectingPrologue

public final void prependInstructionRespectingPrologue(Instruction i)
Prepend instruction to this basic block but respect the prologue instruction, which must come first.

Parameters:
i - instruction to append

appendInstruction

public final void appendInstruction(Instruction i)
Append instruction to this basic block by inserting it right before the BBEND instruction in the instruction list.

Parameters:
i - instruction to append

appendInstructionRespectingTerminalBranch

public final void appendInstructionRespectingTerminalBranch(Instruction i)
Append instruction to this basic block by inserting it right before the BBEND instruction in the instruction list. However, if the basic block ends in a sequence of branch instructions, insert the instruction before the first branch instruction.

Parameters:
i - instruction to append

appendInstructionRespectingTerminalBranchOrPEI

public final void appendInstructionRespectingTerminalBranchOrPEI(Instruction i)
Append instruction to this basic block by inserting it right before the BBEND instruction in the instruction list. However, if the basic block ends in a sequence of branch instructions, insert the instruction before the first branch instruction. If the block ends in a PEI, insert the instruction before the PEI. This function is meant to be used when the block has been unfactored and thus is in CFG form.

Parameters:
i - instruction to append

enumerateBranchInstructions

public final Enumeration<Instruction> enumerateBranchInstructions()
Return an enumeration of the branch instructions in this basic block.

Returns:
an forward enumeration of this blocks branch instruction

firstBranchInstruction

public final Instruction firstBranchInstruction()
Return the first branch instruction in the block.

Returns:
the first branch instruction in the block or null if there are none.

nextBasicBlockInCodeOrder

public final BasicBlock nextBasicBlockInCodeOrder()
Return the next basic block in with respect to the current code linearization order.

Returns:
the next basic block in the code order or null if no such block exists

prevBasicBlockInCodeOrder

public final BasicBlock prevBasicBlockInCodeOrder()
Return the previous basic block in with respect to the current code linearization order.

Returns:
the previous basic block in the code order or null if no such block exists

isEmpty

public final boolean isEmpty()
Returns true if the block contains no real instructions

Returns:
true if the block contains no real instructions or false if it does.

hasApplicableExceptionalOut

public final boolean hasApplicableExceptionalOut(Instruction instr)
Are there any exceptional out edges that are applicable to the given instruction (assumed to be in instruction in 'this')

Parameters:
instr - the instruction in question
Returns:
true or false;

getApplicableExceptionalOut

public final Enumeration<BasicBlock> getApplicableExceptionalOut(Instruction instr)
An enumeration of the subset of exceptional out edges that are applicable to the given instruction (assumed to be in instruction in 'this')

Parameters:
instr - the instruction in question
Returns:
an enumeration of the exceptional out edges applicable to instr

addTargets

private void addTargets(BasicBlock.ComputedBBEnum e,
                        TypeReference thrownException)

getExceptionHandlers

public final Enumeration<BasicBlock> getExceptionHandlers()
An enumeration of the in scope exception handlers for this basic block. Note that this may be a superset of the exception handlers actually included in the out set of this basic block.

Returns:
an enumeration of all inscope exception handlers

hasExceptionHandlers

public final boolean hasExceptionHandlers()
Is this block in the scope of at least exception handler?

Returns:
true if there is at least one in scope exception handler, false otherwise

getReachableExceptionHandlers

public final Enumeration<BasicBlock> getReachableExceptionHandlers()
Returns an Enumeration of the in scope exception handlers that are actually reachable from this basic block in the order that they are applicable (which is semantically meaningful). IE, this is those blocks in getExceptionalOut ordered as in getExceptionHandlers.

Returns:
an enumeration of the reachable exception handlers

deleteNormalOut

public final void deleteNormalOut()
Delete all the non-exceptional out edges. A useful primitive routine for some CFG manipulations.


recomputeNormalOut

public final void recomputeNormalOut(IR ir)
Recompute the normal out edges of 'this' based on the semantics of the branch instructions in the block.

WARNING: Use this method with caution. It does not update the CFG edges correctly if the method contains certain instructions such as throws and returns. Incorrect liveness info and GC maps result, causing crashes during GC.

TODO check if warning is still current and if there's info on CMVC Defect 171189 anywhere


segregateInstruction

public final BasicBlock segregateInstruction(Instruction target,
                                             IR ir)
Ensure that the target instruction is the only real instruction in its basic block and that it has exactly one successor and one predecessor basic blocks that are linked to it by fall through edges.

Parameters:
target - the Instruction that must be placed in its own BB
ir - the containing IR object
Returns:
the BasicBlock containing target

splitNodeAt

public final BasicBlock splitNodeAt(Instruction last_instr_BB1,
                                    IR ir)
Splits a node at an instruction point. All the instructions up to and including the argument instruction remain in the original basic block. All instructions in this basic block but after s in the instruction list are moved to the new basic block.

Parameters:
last_instr_BB1 - the instr that is to become the last instruction in this basic block
ir - the containing IR object
Returns:
the newly created basic block which is the successor to this

splitNodeWithLinksAt

public final BasicBlock splitNodeWithLinksAt(Instruction last_instr_BB1,
                                             IR ir)
Splits a node at an instruction point. All the instructions up to and including the argument instruction remain in the original basic block all instructions in this basic block but after s in the instruction list are moved to the new basic block. The blocks are linked together in the FCFG and the code order. The key difference between this function and splitNodeAt(Instruction,IR) is that it does establish the FCFG edges and code order such that B1 falls into B2.

Parameters:
last_instr_BB1 - the instr that is to become the last instruction in this basic block
ir - the containing IR object
Returns:
the newly created basic block which is the successor to this

copyWithoutLinks

public final BasicBlock copyWithoutLinks(IR ir)
Copies a basic block. The copy differs from the original as follows: The copy

replicateNormalOut

public final void replicateNormalOut(IR ir)
For each basic block b which is a "normal" successor of this, make a copy of b, and set up the CFG so that this block has normal out edges to the copies.

WARNING: Use this method with caution. See comment on BasicBlock.recomputeNormalOut()

Parameters:
ir - the containing IR

replicateThisOut

public final BasicBlock replicateThisOut(IR ir,
                                         BasicBlock b)
For basic block b which has to be a "normal" successor of this, make a copy of b, and set up the CFG so that this block has normal out edges to the copy.

WARNING: Use this method with caution. See comment on BasicBlock.recomputeNormalOut()

Parameters:
ir - the governing IR
b - the block to replicate

replicateThisOut

public final BasicBlock replicateThisOut(IR ir,
                                         BasicBlock b,
                                         BasicBlock pred)
For basic block b which has to be a "normal" successor of this, make a copy of b, and set up the CFG so that this block has normal out edges to the copy.

WARNING: Use this method with caution. See comment on BasicBlock.recomputeNormalOut()

Parameters:
ir - the governing IR
b - the block to replicate
pred - code order predecessor for new block

moveBehind

public void moveBehind(BasicBlock pred,
                       IR ir)
Move me behind `pred'.

Parameters:
pred - my desired code order predecessor
ir - the governing IR

redirectOuts

public final void redirectOuts(BasicBlock b,
                               BasicBlock bCopy,
                               IR ir)
Change all branches from this to b to branches that go to bCopy instead. This method also handles this.fallThrough, so `this' should still be in the code order when this method is called.

WARNING: Use this method with caution. See comment on BasicBlock.recomputeNormalOut()

Parameters:
b - the original target
bCopy - the future target

createSubBlock

public final BasicBlock createSubBlock(int bc,
                                       IR ir)

createSubBlock

public final BasicBlock createSubBlock(int bc,
                                       IR ir,
                                       float wf)
Creates a new basic block that inherits its exception handling, etc from 'this'. This method is intended to be used in conjunction with splitNodeAt when splitting instructions in one original block into a sequence of sublocks

Parameters:
bc - the bytecode index to start the block
ir - the containing IR
wf - the fraction of this's execution frequency that should be inherited by the new block. In the range [0.0, 1.0]
Returns:
the new empty BBlock

mergeFallThrough

public final boolean mergeFallThrough(IR ir)
If this block has a single non-Exception successor in the CFG then we may be able to merge the two blocks together. In order for this to be legal, it must be the case that:
  1. The successor block has no other in edges than the one from this.
  2. Both blocks have the same exception handlers.
Merging the blocks is always desirable when
  1. the successor block is the next block in code order
  2. the successor block is not the next block in the code order, but ends in an unconditional branch (ie it doesn't have a fallthrough successor in the code order that we could be screwing up).

Parameters:
ir - the IR object containing the basic block to be merged
Returns:
true if the block was merged or false otherwise

unfactor

final void unfactor(IR ir)
Convert a block in the FCFG into the equivalent set of CFG blocks by splitting the original block into sub-blocks at each PEI that reaches at least one exception handelr. NOTE: This is sufficient for intraprocedural analysis, since the only program point at which the "wrong" answers will be computed is the exit node, but is not good enough for interprocedural analyses. To do an interprocedural analysis, either the analysis needs to deal with the FCFG or all nodes that modify globally visible state must be unfactored.

Parameters:
ir - the containing IR object
See Also:
IR.unfactor()

pruneExceptionalOut

final void pruneExceptionalOut(IR ir)
Prune away exceptional out edges that are not reachable given this block's instructions.


deleteExceptionalOut

private void deleteExceptionalOut()

getIn

public final Enumeration<BasicBlock> getIn()
An enumeration of the FCFG in nodes.

Returns:
an enumeration of the in nodes

getInNodes

public final Enumeration<BasicBlock> getInNodes()
An enumeration of the FCFG in nodes.

Specified by:
getInNodes in class SortedGraphNode
Returns:
an enumeration of the in nodes

isIn

public final boolean isIn(BasicBlock bb)
Is there an in edge from the given basic block?

Parameters:
bb - basic block in question
Returns:
true if an in edge exists from bb false otherwise

getOut

public final BasicBlock.OutEdgeEnum getOut()
An enumeration of the FCFG out nodes.

Returns:
an enumeration of the out nodes

getOutNodes

public final BasicBlock.OutEdgeEnum getOutNodes()
An enumeration of the FCFG out nodes.

Specified by:
getOutNodes in class SortedGraphNode
Returns:
an enumeration of the out nodes

isOut

public final boolean isOut(BasicBlock bb)
Is there an out edge to the given basic block?

Parameters:
bb - basic block in question
Returns:
true if an out edge exists to bb false otherwise

getNormalOut

public final Enumeration<BasicBlock> getNormalOut()
An enumeration of the 'normal' (not reached via exceptional control flow) out nodes of the block.

Returns:
an enumeration of the out nodes that are not reachable via as a result of exceptional control flow

isNormalOut

public final boolean isNormalOut(BasicBlock bb)
Is there a 'normal' out edge to the given basic block?

Parameters:
bb - basic block in question
Returns:
true if a normal out edge exists to bb false otherwise

getExceptionalOut

public final Enumeration<BasicBlock> getExceptionalOut()
An enumeration of the 'exceptional' (reached via exceptional control flow) out nodes of the block.

Returns:
an enumeration of the out nodes that are reachable via as a result of exceptional control flow

isExceptionalOut

public final boolean isExceptionalOut(BasicBlock bb)
Is there an 'exceptional' out edge to the given basic block?

Parameters:
bb - basic block in question
Returns:
true if an exceptional out edge exists to bb false otherwise

getNumberOfNormalOut

public final int getNumberOfNormalOut()
Get the number of out nodes that are to "normal" basic blocks

Returns:
the number of out nodes that are not the start of exception handlers

getNumberOfExceptionalOut

public final int getNumberOfExceptionalOut()
Get the number of out nodes that are to exception handler basic blocks

Returns:
the number of out nodes that are exception handlers

hasReachableExceptionHandlers

public final boolean hasReachableExceptionHandlers()
Are there exceptinal handlers that are reachable via exceptional control flow from this basic block?

Returns:
true if an exceptional handler is reachable from this block or false otherwise.

discardInstructions

public void discardInstructions()