Class IR

java.lang.Object
com.ibm.wala.ssa.IR
All Implemented Interfaces:
IRView
Direct Known Subclasses:
AstIRFactory.AstIR, SyntheticIR

public abstract class IR extends Object implements IRView
An SSA IR.

The IR (Intermediate Representation) is the central data structure that represents the instructions of a particular method. The IR represents a method's instructions in a language close to JVM bytecode, but in an SSA-based register transfer language which eliminates the stack abstraction, relying instead on a set of symbolic registers. The IR organizes instructions in a control-flow graph of basic blocks, as typical in compiler textbooks.

See more details on the IR API.

  • Constructor Details Link icon

  • Method Details Link icon

    • getLocalMap Link icon

      protected abstract IR.SSA2LocalMap getLocalMap()
      subclasses must provide a source name mapping, if they want one (or null otherwise)
    • getIndirectionData Link icon

      protected abstract <T extends SSAIndirectionData.Name> SSAIndirectionData<T> getIndirectionData()
      subclasses must provide information about indirect use of values, if appropriate, and otherwise null
    • setupLocationMap Link icon

      protected void setupLocationMap()
      create mappings from call sites, new sites, and PEIs to instruction index
    • instructionPosition Link icon

      protected abstract String instructionPosition(int instructionIndex)
      Returns:
      a String which is a readable representation of the instruction position corresponding to an instruction index
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object
    • getInstructions Link icon

      public SSAInstruction[] getInstructions()
      Returns the normal instructions. Does not include SSAPhiInstruction, SSAPiInstruction, or SSAGetCaughtExceptionInstructions, which are currently managed by SSACFG.BasicBlock. Entries in the returned array might be null.

      This may go away someday.

      Specified by:
      getInstructions in interface IRView
    • getSymbolTable Link icon

      public SymbolTable getSymbolTable()
      Specified by:
      getSymbolTable in interface IRView
      Returns:
      the SymbolTable managing attributes for values in this method
    • getControlFlowGraph Link icon

      public SSACFG getControlFlowGraph()
      Specified by:
      getControlFlowGraph in interface IRView
      Returns:
      the underlying ControlFlowGraph which defines this IR.
    • getBlocks Link icon

      public Iterator<ISSABasicBlock> getBlocks()
      Specified by:
      getBlocks in interface IRView
    • iteratePhis Link icon

      public Iterator<? extends SSAInstruction> iteratePhis()
      Return an Iterator of all SSAPhiInstructions for this IR.
    • iteratePis Link icon

      public Iterator<? extends SSAInstruction> iteratePis()
      Return an Iterator of all SSAPiInstructions for this IR.
    • getParameterValueNumbers Link icon

      public int[] getParameterValueNumbers()
      Returns:
      array of value numbers representing parameters to this method
    • getParameter Link icon

      public int getParameter(int i)
      Returns:
      the value number of the ith parameter
    • getParameterType Link icon

      public TypeReference getParameterType(int i)
      Get the TypeReference that describes the ith parameter to this method. By convention, for a non-static method, the 0th parameter is "this".
    • getNumberOfParameters Link icon

      public int getNumberOfParameters()
      Returns:
      number of parameters to this method, including "this"
    • getMethod Link icon

      public IMethod getMethod()
      Specified by:
      getMethod in interface IRView
      Returns:
      the method this IR represents
    • iterateCatchInstructions Link icon

      public Iterator<SSAInstruction> iterateCatchInstructions()
      Returns:
      iterator of the catch instructions in this IR
    • visitNormalInstructions Link icon

      public void visitNormalInstructions(SSAInstruction.IVisitor v)
      visit each normal (non-phi, non-pi, non-catch) instruction in this IR
    • visitAllInstructions Link icon

      public void visitAllInstructions(SSAInstruction.IVisitor v)
      visit each instruction in this IR
    • iterateNormalInstructions Link icon

      public Iterator<SSAInstruction> iterateNormalInstructions()
      Returns:
      an Iterator of all "normal" instructions on this IR
    • iterateAllInstructions Link icon

      public Iterator<SSAInstruction> iterateAllInstructions()
      Returns:
      an Iterator of all instructions (Normal, Phi, and Catch)
    • getExitBlock Link icon

      public SSACFG.BasicBlock getExitBlock()
      Specified by:
      getExitBlock in interface IRView
      Returns:
      the exit basic block
    • getCalls Link icon

      Return the invoke instructions corresponding to a call site

      Note that Shrike may inline JSRS. This can lead to multiple copies of a single bytecode instruction in a particular IR. So we may have more than one instruction index for a particular call site from bytecode.

    • getCallInstructionIndices Link icon

      public IntSet getCallInstructionIndices(CallSiteReference site)
      Return the instruction indices corresponding to a call site.

      Note that Shrike may inline JSRS. This can lead to multiple copies of a single bytecode instruction in a particular IR. So we may have more than one instruction index for a particular call site from bytecode.

    • getNew Link icon

      public SSANewInstruction getNew(NewSiteReference site)
      Return the new instruction corresponding to an allocation site
    • getNewInstructionIndex Link icon

      public int getNewInstructionIndex(NewSiteReference site)
      Return the instruction index corresponding to an allocation site
    • getPEI Link icon

      public SSAInstruction getPEI(ProgramCounter pc)
      Specified by:
      getPEI in interface IRView
      Parameters:
      pc - a program counter
      Returns:
      the instruction (a PEI) at this program counter
    • iterateNewSites Link icon

      public Iterator<NewSiteReference> iterateNewSites()
      Specified by:
      iterateNewSites in interface IRView
      Returns:
      an Iterator of all the allocation sites ( NewSiteReferences ) in this IR
    • iterateCallSites Link icon

      public Iterator<CallSiteReference> iterateCallSites()
      Specified by:
      iterateCallSites in interface IRView
      Returns:
      an Iterator of all the call sites ( CallSiteReferences ) in this IR
    • getBasicBlocksForCall Link icon

      public ISSABasicBlock[] getBasicBlocksForCall(CallSiteReference site)
      Specified by:
      getBasicBlocksForCall in interface IRView
      Parameters:
      site - a call site in this method
      Returns:
      the basic block corresponding to this instruction
      Throws:
      IllegalArgumentException - if site is null
    • getBasicBlockForInstruction Link icon

      public ISSABasicBlock getBasicBlockForInstruction(SSAInstruction s)
      This is space-inefficient. Use with care.

      Be very careful; note the strange identity semantics of SSAInstruction, using ==. You can't mix SSAInstructions and IRs freely.

    • isEmptyIR Link icon

      public boolean isEmptyIR()
      TODO: why do we need this? We should enforce instructions == null if necessary, I think.
      Returns:
      true iff every instruction is null
    • getLocalNames Link icon

      public String[] getLocalNames(int index, int vn)
      Specified by:
      getLocalNames in interface IRView
      Parameters:
      index - an index into the IR instruction array
      vn - a value number
      Returns:
      if we know that immediately after the given program counter, v_vn corresponds to one or more locals and local variable names are available, the name of the locals which v_vn represents. Otherwise, null.
    • getBasicBlockForCatch Link icon

      public ISSABasicBlock getBasicBlockForCatch(SSAGetCaughtExceptionInstruction instruction)
      Return the ISSABasicBlock corresponding to a particular catch instruction
    • getOptions Link icon

      public SSAOptions getOptions()
      Returns:
      the SSAOptions which controlled how this IR was built