Class SsaBasicBlock
java.lang.Object
com.android.dx.ssa.SsaBasicBlock
An SSA representation of a basic block.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classLabel comparator.static interfaceVisitor interface for basic blocks. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<SsaBasicBlock> non-null;comparator for instances of this class that just compares block labels -
Constructor Summary
ConstructorsConstructorDescriptionSsaBasicBlock(int basicBlockIndex, int ropLabel, SsaMethod parent) Creates a new empty basic block. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDomChild(SsaBasicBlock child) Adds a basic block as a dom child for this block.voidaddInsnToHead(Insn insn) Adds an insn to the head of this basic block, just after any phi insns.voidaddLiveIn(int regV) AddsregVto the live-in list for this block.voidaddLiveOut(int regV) AddsregVto the live-out list for this block.voidaddMoveToBeginning(RegisterSpec result, RegisterSpec source) Adds a move instruction after the phi insn block.voidaddMoveToEnd(RegisterSpec result, RegisterSpec source) Adds a move instruction to the end of this basic block, just before the last instruction.voidaddPhiInsnForReg(int reg) Adds a phi insn to the beginning of this block.voidaddPhiInsnForReg(RegisterSpec resultSpec) Adds a phi insn to the beginning of this block.voidexitBlockFixup(SsaBasicBlock exitBlock) Attaches block to an exit block if necessary.voidforEachInsn(SsaInsn.Visitor visitor) Visits all insns in this block.voidVisits each phi insn.Gets the dom children for this node.intgetIndex()getInsns()Returns the set of live-in registers.Returns the set of live-out registers.intintintInserts a new empty GOTO block as a predecessor to this block.insertNewSuccessor(SsaBasicBlock other) Constructs and inserts a new empty GOTO blockZbetween this block (A) and a current successor block (B).booleanstatic SsaBasicBlocknewFromRop(RopMethod rmeth, int basicBlockIndex, SsaMethod parent) Creates a new SSA basic block from a ROP form basic block.voidDeletes all phi insns.voidremoveSuccessor(int oldIndex) Removes a successor from this block's successor list.voidreplaceLastInsn(Insn insn) Replaces the last insn in this block.voidreplaceSuccessor(int oldIndex, int newIndex) Replaces an old successor with a new successor.voidSorts move instructions added viaaddMoveToEndduring phi removal so that results don't overwrite sources that are used.toString()
-
Field Details
-
LABEL_COMPARATOR
non-null;comparator for instances of this class that just compares block labels
-
-
Constructor Details
-
SsaBasicBlock
Creates a new empty basic block.- Parameters:
basicBlockIndex- index this block will haveropLabel- original rop-form labelparent- method of this block
-
-
Method Details
-
newFromRop
Creates a new SSA basic block from a ROP form basic block.- Parameters:
rmeth- original methodbasicBlockIndex- index this block will haveparent- method of this block predecessor set will be updated- Returns:
- new instance
-
addDomChild
Adds a basic block as a dom child for this block. Used when constructing the dom tree.- Parameters:
child-non-null;new dom child
-
getDomChildren
Gets the dom children for this node. Don't modify this list.- Returns:
non-null;list of dom children
-
addPhiInsnForReg
public void addPhiInsnForReg(int reg) Adds a phi insn to the beginning of this block. The result type of the phi will be set to void, to indicate that it's currently unknown.- Parameters:
reg->=0;result reg
-
addPhiInsnForReg
Adds a phi insn to the beginning of this block. This is to be used when the result type or local-association can be determined at phi insert time.- Parameters:
resultSpec-non-null;reg
-
addInsnToHead
Adds an insn to the head of this basic block, just after any phi insns.- Parameters:
insn-non-null;rop-form insn to add
-
replaceLastInsn
Replaces the last insn in this block. The provided insn must have some branchingness.- Parameters:
insn-non-null;rop-form insn to add, which must branch.
-
forEachPhiInsn
Visits each phi insn.- Parameters:
v-non-null;the callback
-
removeAllPhiInsns
public void removeAllPhiInsns()Deletes all phi insns. Do this after adding appropriate move insns. -
getInsns
-
getPhiInsns
-
getIndex
public int getIndex()- Returns:
- the block index of this block
-
getRopLabel
public int getRopLabel()- Returns:
- the label of this block in rop form
-
getRopLabelString
- Returns:
- the label of this block in rop form as a hex string
-
getPredecessors
- Returns:
non-null;predecessors set, indexed by block index
-
getSuccessors
- Returns:
non-null;successors set, indexed by block index
-
getSuccessorList
- Returns:
non-null;ordered successor list, containing block indicies
-
getPrimarySuccessorIndex
public int getPrimarySuccessorIndex()- Returns:
>= -1;block index of primary successor or-1if no primary successor
-
getPrimarySuccessorRopLabel
public int getPrimarySuccessorRopLabel()- Returns:
- rop label of primary successor
-
getPrimarySuccessor
- Returns:
null-ok;the primary successor block ornullif there is none
-
getRopLabelSuccessorList
- Returns:
- successor list of rop labels
-
getParent
- Returns:
non-null;method that contains this block
-
insertNewPredecessor
Inserts a new empty GOTO block as a predecessor to this block. All previous predecessors will be predecessors to the new block.- Returns:
non-null;an appropriately-constructed instance
-
insertNewSuccessor
Constructs and inserts a new empty GOTO blockZbetween this block (A) and a current successor block (B). The new block will replace B as A's successor and A as B's predecessor. A and B will no longer be directly connected. If B is listed as a successor multiple times, all references are replaced.- Parameters:
other- current successor (B)- Returns:
non-null;an appropriately-constructed instance
-
replaceSuccessor
public void replaceSuccessor(int oldIndex, int newIndex) Replaces an old successor with a new successor. This will throw RuntimeException ifoldIndexwas not a successor.- Parameters:
oldIndex- index of old successor blocknewIndex- index of new successor block
-
removeSuccessor
public void removeSuccessor(int oldIndex) Removes a successor from this block's successor list.- Parameters:
oldIndex- index of successor block to remove
-
exitBlockFixup
Attaches block to an exit block if necessary. If this block is not an exit predecessor or is the exit block, this block does nothing. For use bySsaMethod.makeExitBlock()- Parameters:
exitBlock-non-null;exit block
-
addMoveToEnd
Adds a move instruction to the end of this basic block, just before the last instruction. If the result of the final instruction is the source in question, then the move is placed at the beginning of the primary successor block. This is for unversioned registers.- Parameters:
result- move destinationsource- move source
-
addMoveToBeginning
Adds a move instruction after the phi insn block.- Parameters:
result- move destinationsource- move source
-
addLiveOut
public void addLiveOut(int regV) AddsregVto the live-out list for this block. This is called by the liveness analyzer.- Parameters:
regV- register that is live-out for this block.
-
addLiveIn
public void addLiveIn(int regV) AddsregVto the live-in list for this block. This is called by the liveness analyzer.- Parameters:
regV- register that is live-in for this block.
-
getLiveInRegs
Returns the set of live-in registers. Valid after register interference graph has been generated, otherwise empty.- Returns:
non-null;live-in register set.
-
getLiveOutRegs
Returns the set of live-out registers. Valid after register interference graph has been generated, otherwise empty.- Returns:
non-null;live-out register set
-
isExitBlock
public boolean isExitBlock()- Returns:
- true if this is the one-and-only exit block for this method
-
scheduleMovesFromPhis
public void scheduleMovesFromPhis()Sorts move instructions added viaaddMoveToEndduring phi removal so that results don't overwrite sources that are used. For use after all phis have been removed and all calls to addMoveToEnd() have been made.This is necessary because copy-propogation may have left us in a state where the same basic block has the same register as a phi operand and a result. In this case, the register in the phi operand always refers value before any other phis have executed.
-
forEachInsn
Visits all insns in this block.- Parameters:
visitor-non-null;callback interface
-
toString
-