PhiNode

public struct PhiNode : IRInstruction

A PhiNode object represents a PHI node.

Because all instructions in LLVM IR are in SSA (Single Static Assignment) form, a PHI node is necessary when the value of a variable assignment depends on the path the flow of control takes through the program. For example:

var a = 1
if c == 42 {
  a = 2
}
let b = a

The value of b in this program depends on the value of the condition involving the variable c. Because b must be assigned to once, a PHI node is created and the program effectively is transformed into the following:

let aNoCond = 1
if c == 42 {
  let aCondTrue = 2
}
let b = PHI(aNoCond, aCondTrue)

If the flow of control reaches aCondTrue, the value of b is 2, else it is 1 and SSA semantics are preserved.

  • Adds a list of incoming value and their associated basic blocks to the end of the list of incoming values for this PHI node.

    Declaration

    Swift

    public func addIncoming(_ valueMap: [(IRValue, BasicBlock)])

    Parameters

    valueMap

    A list of incoming values and their associated basic blocks.

  • Obtain the incoming values and their associated basic blocks for this PHI node.

    Declaration

    Swift

    public var incoming: [(IRValue, BasicBlock)] { get }
  • Retrieves the incoming value for the given index for this PHI node, if it exists.

    Declaration

    Swift

    public func incomingValue(at index: Int) -> IRValue?

    Parameters

    index

    The index of the incoming value to retrieve.

    Return Value

    A value representing the incoming value to this PHI node at the given index, if it exists.

  • Retrieves the incoming basic block for the given index for this PHI node, if it exists.

    Declaration

    Swift

    public func incomingBlock(at index: Int) -> BasicBlock?

    Parameters

    index

    The index of the incoming basic block to retrieve.

    Return Value

    A value representing the incoming basic block to this PHI node at the given index, if it exists.

  • Retrieves the underlying LLVM value object.

    Declaration

    Swift

    public func asLLVM() -> LLVMValueRef