com.android.dx.ssa
Class PhiInsn

java.lang.Object
  extended by com.android.dx.ssa.SsaInsn
      extended by com.android.dx.ssa.PhiInsn
All Implemented Interfaces:
ToHuman, Cloneable

public final class PhiInsn
extends SsaInsn

A Phi instruction (magical post-control-flow-merge) instruction in SSA form. Will be converted to moves in predecessor blocks before conversion back to ROP form.


Nested Class Summary
static interface PhiInsn.Visitor
          Visitor interface for instances of this (outer) class.
 
Constructor Summary
PhiInsn(int resultReg, SsaBasicBlock block)
          Makes a phi insn with a void result type.
PhiInsn(RegisterSpec resultReg, SsaBasicBlock block)
          Constructs a new phi insn with no operands.
 
Method Summary
 void accept(SsaInsn.Visitor v)
          Accepts a visitor.
 void addPhiOperand(RegisterSpec registerSpec, SsaBasicBlock predBlock)
          Adds an operand to this phi instruction.
 boolean areAllOperandsEqual()
           
 boolean canThrow()
           Always returns false for PhiInsns.
 void changeResultType(TypeBearer type, LocalItem local)
          Changes the result type.
 PhiInsn clone()
          
 Rop getOpcode()
          Returns the Rop opcode for this insn, or null if this is a phi insn.
 Insn getOriginalRopInsn()
          Returns the original Rop insn for this insn, or null if this is a phi insn.
 int getRopResultReg()
          Gets the original rop-form result reg.
 RegisterSpecList getSources()
          Gets sources.
 boolean hasSideEffect()
          Returns true if this insn is considered to have a side effect beyond that of assigning to the result reg.
 boolean isPhiOrMove()
          
 boolean isRegASource(int reg)
          Indicates whether the specified register is amongst the registers used as sources for this instruction.
 void mapSourceRegisters(RegisterMapper mapper)
          Maps only source registers.
 int predBlockIndexForSourcesIndex(int sourcesIndex)
          Gets the index of the pred block associated with the RegisterSpec at the particular getSources() index.
 List<SsaBasicBlock> predBlocksForReg(int reg, SsaMethod ssaMeth)
          Returns the list of predecessor blocks associated with all operands that have reg as an operand register.
 void removePhiRegister(RegisterSpec registerSpec)
          Removes all operand uses of a register from this phi instruction.
 String toHuman()
          Return the "human" string form of this instance.
protected  String toHumanWithInline(String extra)
          Returns human-readable string for listing dumps.
 Insn toRopInsn()
          Always throws an exeption, since a phi insn may not be converted back to rop form.
 void updateSourcesToDefinitions(SsaMethod ssaMeth)
          Updates the TypeBearers of all the sources (phi operands) to be the current TypeBearer of the register-defining instruction's result.
 
Methods inherited from class com.android.dx.ssa.SsaInsn
changeResultReg, getBlock, getLocalAssignment, getResult, isMoveException, isNormalMoveInsn, isResultReg, makeFromRop, mapRegisters, setResult, setResultLocal
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhiInsn

public PhiInsn(RegisterSpec resultReg,
               SsaBasicBlock block)
Constructs a new phi insn with no operands.

Parameters:
resultReg - the result reg for this phi insn
block - block containing this insn.

PhiInsn

public PhiInsn(int resultReg,
               SsaBasicBlock block)
Makes a phi insn with a void result type.

Parameters:
resultReg - the result register for this phi insn.
block - block containing this insn.
Method Detail

clone

public PhiInsn clone()

Overrides:
clone in class SsaInsn

updateSourcesToDefinitions

public void updateSourcesToDefinitions(SsaMethod ssaMeth)
Updates the TypeBearers of all the sources (phi operands) to be the current TypeBearer of the register-defining instruction's result. This is used during phi-type resolution.

Note that local association of operands are preserved in this step.

Parameters:
ssaMeth - method that contains this insn

changeResultType

public void changeResultType(TypeBearer type,
                             LocalItem local)
Changes the result type. Used during phi type resolution

Parameters:
type - non-null; new TypeBearer
local - null-ok; new local info, if available

getRopResultReg

public int getRopResultReg()
Gets the original rop-form result reg. This is useful during renaming.

Returns:
the original rop-form result reg

addPhiOperand

public void addPhiOperand(RegisterSpec registerSpec,
                          SsaBasicBlock predBlock)
Adds an operand to this phi instruction.

Parameters:
registerSpec - register spec, including type and reg of operand
predBlock - predecessor block to be associated with this operand

removePhiRegister

public void removePhiRegister(RegisterSpec registerSpec)
Removes all operand uses of a register from this phi instruction.

Parameters:
registerSpec - register spec, including type and reg of operand

predBlockIndexForSourcesIndex

public int predBlockIndexForSourcesIndex(int sourcesIndex)
Gets the index of the pred block associated with the RegisterSpec at the particular getSources() index.

Parameters:
sourcesIndex - index of source in getSources()
Returns:
block index

getOpcode

public Rop getOpcode()
Returns the Rop opcode for this insn, or null if this is a phi insn. TODO: Move this up into NormalSsaInsn. Always returns null for PhiInsns.

Specified by:
getOpcode in class SsaInsn
Returns:
null-ok; Rop opcode if there is one.

getOriginalRopInsn

public Insn getOriginalRopInsn()
Returns the original Rop insn for this insn, or null if this is a phi insn. TODO: Move this up into NormalSsaInsn. Always returns null for PhiInsns.

Specified by:
getOriginalRopInsn in class SsaInsn
Returns:
null-ok; Rop insn if there is one.

canThrow

public boolean canThrow()
Always returns false for PhiInsns.

Specified by:
canThrow in class SsaInsn
Returns:
true if this instruction can throw.

getSources

public RegisterSpecList getSources()
Gets sources. Constructed lazily from phi operand data structures and then cached.

Specified by:
getSources in class SsaInsn
Returns:
non-null; sources list

isRegASource

public boolean isRegASource(int reg)
Indicates whether the specified register is amongst the registers used as sources for this instruction.

Overrides:
isRegASource in class SsaInsn
Parameters:
reg - the register in question
Returns:
true if the reg is a source

areAllOperandsEqual

public boolean areAllOperandsEqual()
Returns:
true if all operands use the same register

mapSourceRegisters

public final void mapSourceRegisters(RegisterMapper mapper)
Maps only source registers.

Specified by:
mapSourceRegisters in class SsaInsn
Parameters:
mapper - new mapping

toRopInsn

public Insn toRopInsn()
Always throws an exeption, since a phi insn may not be converted back to rop form.

Specified by:
toRopInsn in class SsaInsn
Returns:
always throws exception

predBlocksForReg

public List<SsaBasicBlock> predBlocksForReg(int reg,
                                            SsaMethod ssaMeth)
Returns the list of predecessor blocks associated with all operands that have reg as an operand register.

Parameters:
reg - register to look up
ssaMeth - method we're operating on
Returns:
list of predecessor blocks, empty if none

isPhiOrMove

public boolean isPhiOrMove()

Specified by:
isPhiOrMove in class SsaInsn
Returns:
true if this is a PhiInsn or a normal move insn

hasSideEffect

public boolean hasSideEffect()
Returns true if this insn is considered to have a side effect beyond that of assigning to the result reg.

Specified by:
hasSideEffect in class SsaInsn
Returns:
true if this insn is considered to have a side effect beyond that of assigning to the result reg.

accept

public void accept(SsaInsn.Visitor v)
Accepts a visitor.

Specified by:
accept in class SsaInsn
Parameters:
v - non-null the visitor

toHuman

public String toHuman()
Return the "human" string form of this instance. This is generally less "debuggy" than toString().

Returns:
non-null; the human string form

toHumanWithInline

protected final String toHumanWithInline(String extra)
Returns human-readable string for listing dumps. This method allows sub-classes to specify extra text.

Parameters:
extra - null-ok; the argument to print after the opcode
Returns:
human-readable string for listing dumps


Copyright © 2015. All rights reserved.