Class BranchInstruction


  • public class BranchInstruction
    extends IRInstruction
    A conditional branch comparing one or two operands and selecting a true or false target block.
    • Constructor Detail

      • BranchInstruction

        public BranchInstruction​(CompareOp condition,
                                 Value left,
                                 Value right,
                                 IRBlock trueTarget,
                                 IRBlock falseTarget)
        Creates a two-operand comparison branch and registers uses of its SSA operands.
        Parameters:
        condition - the comparison to evaluate
        left - the left operand
        right - the right operand
        trueTarget - the block taken when the comparison holds
        falseTarget - the block taken otherwise
      • BranchInstruction

        public BranchInstruction​(CompareOp condition,
                                 Value operand,
                                 IRBlock trueTarget,
                                 IRBlock falseTarget)
        Creates a single-operand branch comparing against an implicit zero or null.
        Parameters:
        condition - the comparison to evaluate
        operand - the operand to test
        trueTarget - the block taken when the comparison holds
        falseTarget - the block taken otherwise
    • Method Detail

      • getCondition

        public CompareOp getCondition()
        Returns:
        the condition
      • getLeft

        public Value getLeft()
        Returns:
        the left
      • getRight

        public Value getRight()
        Returns:
        the right
      • getTrueTarget

        public IRBlock getTrueTarget()
        Returns:
        the true target
      • setTrueTarget

        public void setTrueTarget​(IRBlock trueTarget)
        Parameters:
        trueTarget - the block taken when the comparison holds
      • getFalseTarget

        public IRBlock getFalseTarget()
        Returns:
        the false target
      • setFalseTarget

        public void setFalseTarget​(IRBlock falseTarget)
        Parameters:
        falseTarget - the block taken when the comparison fails
      • replaceOperand

        public void replaceOperand​(Value oldValue,
                                   Value newValue)
        Description copied from class: IRInstruction
        Replaces an operand value with a new value.
        Specified by:
        replaceOperand in class IRInstruction
        Parameters:
        oldValue - the value to replace
        newValue - the replacement value
      • accept

        public <T> T accept​(IRVisitor<T> visitor)
        Description copied from class: IRInstruction
        Accepts a visitor for this instruction.
        Specified by:
        accept in class IRInstruction
        Type Parameters:
        T - the return type
        Parameters:
        visitor - the visitor to accept
        Returns:
        the visitor result
      • isTerminator

        public boolean isTerminator()
        Description copied from class: IRInstruction
        Checks if this instruction terminates a basic block.
        Overrides:
        isTerminator in class IRInstruction
        Returns:
        true if this is a terminator instruction
      • replaceTarget

        public void replaceTarget​(IRBlock oldTarget,
                                  IRBlock newTarget)
        Description copied from class: IRInstruction
        Replaces a target block in terminator instructions.
        Overrides:
        replaceTarget in class IRInstruction
        Parameters:
        oldTarget - the block to replace
        newTarget - the replacement block
      • copyWithNewOperands

        public IRInstruction copyWithNewOperands​(SSAValue newResult,
                                                 List<Value> newOperands)
        Description copied from class: IRInstruction
        Creates a copy of this instruction with new result and operands.
        Overrides:
        copyWithNewOperands in class IRInstruction
        Parameters:
        newResult - the new result value (may be null)
        newOperands - the new operand values
        Returns:
        a copy of this instruction, or null if copying not supported