Class IRBlock


  • public class IRBlock
    extends Object
    A basic block in the SSA CFG, holding phi instructions ahead of its regular instructions.
    • Constructor Detail

      • IRBlock

        public IRBlock()
        Creates a new basic block with an auto-generated name.
      • IRBlock

        public IRBlock​(String name)
        Creates a new basic block with the given name.
        Parameters:
        name - the block name
    • Method Detail

      • getId

        public int getId()
        Returns:
        the id
      • getName

        public String getName()
        Returns:
        the name
      • setName

        public void setName​(String name)
        Parameters:
        name - the block name
      • getMethod

        public IRMethod getMethod()
        Returns:
        the method
      • setMethod

        public void setMethod​(IRMethod method)
        Parameters:
        method - the method this block belongs to
      • getPhiInstructions

        public List<PhiInstruction> getPhiInstructions()
        Returns:
        the phi instructions
      • getInstructions

        public List<IRInstruction> getInstructions()
        Returns:
        the instructions
      • getPredecessors

        public Set<IRBlock> getPredecessors()
        Returns:
        the predecessors
      • getSuccessors

        public Set<IRBlock> getSuccessors()
        Returns:
        the successors
      • getSuccessorEdgeTypes

        public Map<IRBlock,​EdgeType> getSuccessorEdgeTypes()
        Returns:
        the successor edge types
      • getExceptionHandlers

        public List<ExceptionHandler> getExceptionHandlers()
        Returns:
        the exception handlers
      • getBytecodeOffset

        public int getBytecodeOffset()
        Returns:
        the bytecode offset
      • setBytecodeOffset

        public void setBytecodeOffset​(int bytecodeOffset)
        Parameters:
        bytecodeOffset - the original bytecode offset of the block start, or -1 if unknown
      • addPhi

        public void addPhi​(PhiInstruction phi)
        Adds a phi instruction to this block.
        Parameters:
        phi - the phi instruction to add
      • addPhiInstruction

        public void addPhiInstruction​(PhiInstruction phi)
        Alias for addPhi to match common naming convention.
        Parameters:
        phi - the phi instruction to add
      • removePhi

        public void removePhi​(PhiInstruction phi)
        Removes a phi instruction from this block.
        Parameters:
        phi - the phi instruction to remove
      • addInstruction

        public void addInstruction​(IRInstruction instruction)
        Adds an instruction to the end of this block.
        Parameters:
        instruction - the instruction to add
      • insertInstruction

        public void insertInstruction​(int index,
                                      IRInstruction instruction)
        Inserts an instruction at the specified index.
        Parameters:
        index - the position to insert at
        instruction - the instruction to insert
      • removeInstruction

        public void removeInstruction​(IRInstruction instruction)
        Removes an instruction from this block.
        Parameters:
        instruction - the instruction to remove
      • addSuccessor

        public void addSuccessor​(IRBlock successor)
        Adds a successor block with a normal edge.
        Parameters:
        successor - the successor block
      • addSuccessor

        public void addSuccessor​(IRBlock successor,
                                 EdgeType edgeType)
        Adds a successor block with the specified edge type.
        Parameters:
        successor - the successor block
        edgeType - the type of edge
      • removeSuccessor

        public void removeSuccessor​(IRBlock successor)
        Removes a successor block and updates predecessor relationships.
        Parameters:
        successor - the successor block to remove
      • getEdgeType

        public EdgeType getEdgeType​(IRBlock successor)
        Gets the edge type to a successor block.
        Parameters:
        successor - the successor block
        Returns:
        the edge type
      • addExceptionHandler

        public void addExceptionHandler​(ExceptionHandler handler)
        Adds an exception handler to this block.
        Parameters:
        handler - the exception handler
      • getTerminator

        public IRInstruction getTerminator()
        Gets the terminator instruction of this block.
        Returns:
        the terminator instruction, or null if none
      • setTerminator

        public void setTerminator​(IRInstruction terminator)
        Sets the terminator instruction for this block.
        Parameters:
        terminator - the terminator instruction to set
      • addPredecessor

        public void addPredecessor​(IRBlock pred)
        Adds a predecessor block directly (for use in block duplication).
        Parameters:
        pred - the predecessor block
      • removePredecessor

        public void removePredecessor​(IRBlock pred)
        Removes a predecessor block directly.
        Parameters:
        pred - the predecessor block to remove
      • hasTerminator

        public boolean hasTerminator()
        Checks if this block has a terminator instruction.
        Returns:
        true if block has a terminator, false otherwise
      • getAllInstructions

        public List<IRInstruction> getAllInstructions()
        Gets all instructions including phi instructions.
        Returns:
        combined list of phi and regular instructions
      • isEmpty

        public boolean isEmpty()
        Checks if this block is empty.
        Returns:
        true if no instructions, false otherwise
      • isEntry

        public boolean isEntry()
        Checks if this is the entry block.
        Returns:
        true if this is the method's entry block, false otherwise
      • isExit

        public boolean isExit()
        Checks if this is an exit block.
        Returns:
        true if block has no successors, false otherwise
      • resetIdCounter

        public static void resetIdCounter()
        Resets the ID counter for basic blocks.
      • equals

        public boolean equals​(Object o)
        Identity by id.
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object