Package iota

Class NControlFlowGraph

java.lang.Object
iota.NControlFlowGraph

class NControlFlowGraph extends Object
Representation of a control flow graph (cfg) for a method.
  • Field Details

    • cp

      public CLConstantPool cp
      Constant pool of the class containing the method.
    • m

      public CLMethodInfo m
      Contains information about the method.
    • name

      public String name
      Name of the method.
    • desc

      public String desc
      Descriptor of the method.
    • basicBlocks

      public ArrayList<NBasicBlock> basicBlocks
      List of basic blocks forming this cfg.
    • numLocals

      public int numLocals
      Number of local variables (including parameters) in the method.
    • hirId

      public static int hirId
      HIR instruction identifier.
    • hirMap

      Maps HIR instruction ids in this cfg to HIR instructions.
    • lirId

      public static int lirId
      LIR instruction identifier.
    • regId

      public static int regId
      Virtual register identifier.
    • intervals

      public ArrayList<NInterval> intervals
      Liveness intervals of this cfg.
    • registers

      public ArrayList<NRegister> registers
      Virtual and physical registers used in this cfg.
    • pRegisters

      public ArrayList<NPhysicalRegister> pRegisters
      Physical registers used in this cfg.
  • Constructor Details

    • NControlFlowGraph

      public NControlFlowGraph(CLConstantPool cp, CLMethodInfo m, String name, String desc)
      Constructs a ControlFlowGraph object for a method.
      Parameters:
      cp - constant pool of the class containing the method.
      m - contains information about the method.
      name - method name.
      desc - method descriptor.
  • Method Details

    • detectLoops

      public void detectLoops(NBasicBlock block, NBasicBlock pred)
      Recursively identifies loop header and loop tail blocks starting from the given block.
      Parameters:
      block - a block.
      pred - block's predecessor or null.
    • removeUnreachableBlocks

      public void removeUnreachableBlocks()
      Removes basic blocks that cannot be reached from B0.
    • tuplesToHir

      public void tuplesToHir()
      Converts tuples in each block to their high-level (HIR) representations.
    • hirToLir

      public void hirToLir()
      Converts the HIR instructions in this cfg to LIR instructions.
    • cleanupPhiFunctions

      public void cleanupPhiFunctions()
      Replaces redundant phi functions of the form x = phi(y, x, x, ..., x) with y.
    • resolvePhiFunctions

      public void resolvePhiFunctions()
      Resolve Phi functions by inserting appropriate "copy" instructions at the end of the predecessor blocks. If the last instruction in the predecessor is a jump instruction, then the "copy" instructions are inserted right before the jump instruction.
    • renumberLir

      public void renumberLir()
      Assigns new ids (0, 5, 10, and so on) to the LIR instructions in this cfg. The gaps allow us to insert spill/restore instructions if needed during register allocation.
    • lirToMarvin

      public void lirToMarvin()
      Converts the LIR instructions in this cfg to Marvin instructions.
    • prepareMethodEntryAndExit

      public void prepareMethodEntryAndExit()
      Generate Marvin code for creating a stack frame upon method entry and destroying the frame upon exit.
    • resolveJumps

      public void resolveJumps()
      Resolve jumps within this method. This does not include method calls, which are handled by the resolveCalls() method.
    • resolveCalls

      public void resolveCalls()
      Resolves the jump locations in the "calln" instructions.
    • computeLivenessIntervals

      public void computeLivenessIntervals()
      Computes the liveness intervals for the registers (virtual and physical) used by this cfg.
    • writeTuplesToStdOut

      public void writeTuplesToStdOut(PrettyPrinter p)
      Writes the tuples in this cfg to standard output.
      Parameters:
      p - for pretty printing with indentation.
    • writeHirToStdOut

      public void writeHirToStdOut(PrettyPrinter p)
      Writes the hir instructions in this cfg to standard output.
      Parameters:
      p - for pretty printing with indentation.
    • writeLirToStdOut

      public void writeLirToStdOut(PrettyPrinter p)
      Writes the lir instructions in this cfg to standard output.
      Parameters:
      p - for pretty printing with indentation.
    • writeLivenessSetsToStdOut

      public void writeLivenessSetsToStdOut(PrettyPrinter p)
      Writes the local and global liveness sets in this cfg to standard output.
      Parameters:
      p - for pretty printing with indentation.
    • writeLivenessIntervalsToStdOut

      public void writeLivenessIntervalsToStdOut(PrettyPrinter p)
      Writes the liveness intervals in this cfg to standard output.
      Parameters:
      p - for pretty printing with indentation.
    • write

      public void write(PrintWriter out)
      Writes the Marvin instructions in this cfg to the give output stream.
      Parameters:
      out - output stream.