Class SsaBasicBlock

java.lang.Object
com.android.dx.ssa.SsaBasicBlock

public final class SsaBasicBlock extends Object
An SSA representation of a basic block.
  • Field Details

    • LABEL_COMPARATOR

      public static final Comparator<SsaBasicBlock> LABEL_COMPARATOR
      non-null; comparator for instances of this class that just compares block labels
  • Constructor Details

    • SsaBasicBlock

      public SsaBasicBlock(int basicBlockIndex, int ropLabel, SsaMethod parent)
      Creates a new empty basic block.
      Parameters:
      basicBlockIndex - index this block will have
      ropLabel - original rop-form label
      parent - method of this block
  • Method Details

    • newFromRop

      public static SsaBasicBlock newFromRop(RopMethod rmeth, int basicBlockIndex, SsaMethod parent)
      Creates a new SSA basic block from a ROP form basic block.
      Parameters:
      rmeth - original method
      basicBlockIndex - index this block will have
      parent - method of this block predecessor set will be updated
      Returns:
      new instance
    • addDomChild

      public void addDomChild(SsaBasicBlock child)
      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

      public ArrayList<SsaBasicBlock> 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

      public void addPhiInsnForReg(RegisterSpec resultSpec)
      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

      public void addInsnToHead(Insn insn)
      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

      public void replaceLastInsn(Insn insn)
      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

      public void forEachPhiInsn(PhiInsn.Visitor v)
      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

      public ArrayList<SsaInsn> getInsns()
      Returns:
      non-null; the (mutable) instruction list for this block, with phi insns at the beginning
    • getPhiInsns

      public List<SsaInsn> getPhiInsns()
      Returns:
      non-null; the (mutable) list of phi insns for this block
    • 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

      public String getRopLabelString()
      Returns:
      the label of this block in rop form as a hex string
    • getPredecessors

      public BitSet getPredecessors()
      Returns:
      non-null; predecessors set, indexed by block index
    • getSuccessors

      public BitSet getSuccessors()
      Returns:
      non-null; successors set, indexed by block index
    • getSuccessorList

      public IntList getSuccessorList()
      Returns:
      non-null; ordered successor list, containing block indicies
    • getPrimarySuccessorIndex

      public int getPrimarySuccessorIndex()
      Returns:
      >= -1; block index of primary successor or -1 if no primary successor
    • getPrimarySuccessorRopLabel

      public int getPrimarySuccessorRopLabel()
      Returns:
      rop label of primary successor
    • getPrimarySuccessor

      public SsaBasicBlock getPrimarySuccessor()
      Returns:
      null-ok; the primary successor block or null if there is none
    • getRopLabelSuccessorList

      public IntList getRopLabelSuccessorList()
      Returns:
      successor list of rop labels
    • getParent

      public SsaMethod getParent()
      Returns:
      non-null; method that contains this block
    • insertNewPredecessor

      public SsaBasicBlock 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

      public SsaBasicBlock insertNewSuccessor(SsaBasicBlock other)
      Constructs and inserts a new empty GOTO block Z between 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 if oldIndex was not a successor.
      Parameters:
      oldIndex - index of old successor block
      newIndex - 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

      public void exitBlockFixup(SsaBasicBlock exitBlock)
      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 by SsaMethod.makeExitBlock()
      Parameters:
      exitBlock - non-null; exit block
    • addMoveToEnd

      public void addMoveToEnd(RegisterSpec result, RegisterSpec source)
      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 destination
      source - move source
    • addMoveToBeginning

      public void addMoveToBeginning(RegisterSpec result, RegisterSpec source)
      Adds a move instruction after the phi insn block.
      Parameters:
      result - move destination
      source - move source
    • addLiveOut

      public void addLiveOut(int regV)
      Adds regV to 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)
      Adds regV to 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

      public IntSet 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

      public IntSet 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 via addMoveToEnd during 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

      public void forEachInsn(SsaInsn.Visitor visitor)
      Visits all insns in this block.
      Parameters:
      visitor - non-null; callback interface
    • toString

      public String toString()
      Overrides:
      toString in class Object