Class RegisterAllocator

java.lang.Object
com.android.dx.ssa.back.RegisterAllocator
Direct Known Subclasses:
FirstFitAllocator, FirstFitLocalCombiningAllocator, NullRegisterAllocator

public abstract class RegisterAllocator extends Object
Base class of all register allocators.
  • Field Details

    • ssaMeth

      protected final SsaMethod ssaMeth
      method being processed
    • interference

      protected final InterferenceGraph interference
      interference graph, indexed by register in both dimensions
  • Constructor Details

    • RegisterAllocator

      public RegisterAllocator(SsaMethod ssaMeth, InterferenceGraph interference)
      Creates an instance. Call allocateRegisters to run.
      Parameters:
      ssaMeth - method to process.
      interference - Interference graph, indexed by register in both dimensions.
  • Method Details

    • wantsParamsMovedHigh

      public abstract boolean wantsParamsMovedHigh()
      Indicates whether the method params were allocated at the bottom of the namespace, and thus should be moved up to the top of the namespace after phi removal.
      Returns:
      true if params should be moved from low to high
    • allocateRegisters

      public abstract RegisterMapper allocateRegisters()
      Runs the algorithm.
      Returns:
      a register mapper to apply to the SsaMethod
    • getCategoryForSsaReg

      protected final int getCategoryForSsaReg(int reg)
      Returns the category (width) of the definition site of the register. Returns 1 for undefined registers.
      Parameters:
      reg - register
      Returns:
      1..2
    • getDefinitionSpecForSsaReg

      protected final RegisterSpec getDefinitionSpecForSsaReg(int reg)
      Returns the RegisterSpec of the definition of the register.
      Parameters:
      reg - >= 0; SSA register
      Returns:
      definition spec of the register or null if it is never defined (for the case of "version 0" SSA registers)
    • isDefinitionMoveParam

      protected boolean isDefinitionMoveParam(int reg)
      Returns true if the definition site of this register is a move-param (ie, this is a method parameter).
      Parameters:
      reg - register in question
      Returns:
      true if this is a method parameter
    • insertMoveBefore

      protected final RegisterSpec insertMoveBefore(SsaInsn insn, RegisterSpec reg)
      Inserts a move instruction for a specified SSA register before a specified instruction, creating a new SSA register and adjusting the interference graph in the process. The insn currently must be the last insn in a block.
      Parameters:
      insn - non-null; insn to insert move before, must be last insn in block
      reg - non-null; SSA register to duplicate
      Returns:
      non-null; spec of new SSA register created by move