BasicBlock

public struct BasicBlock : IRValue

A BasicBlock represents a basic block in an LLVM IR program. A basic block contains a sequence of instructions, a pointer to its parent block and its follower block, and an optional label that gives the basic block an entry in the symbol table.

A basic block can be thought of as a sequence of instructions, and indeed its member instructions may be iterated over with a for-in loop.

The first basic block in a function is special in two ways: it is immediately executed on entrance to the function, and it is not allowed to have predecessor basic blocks (i.e. there can not be any branches to the entry block of a function). Because the block can have no predecessors, it also cannot have any PHI nodes.

  • Creates a BasicBlock from an LLVMBasicBlockRef object.

    Declaration

    Swift

    public init(llvm: LLVMBasicBlockRef)
  • Creates a new basic block without a parent function.

    The basic block should be inserted into a function or destroyed before the IR builder is finalized.

    Declaration

    Swift

    public init(context: Context = .global, name: String = "")
  • Given that this block and a given block share a parent function, move this block before the given block in that function’s basic block list.

    Declaration

    Swift

    public func move(before position: BasicBlock)

    Parameters

    position

    The basic block that acts as a position before which this block will be moved.

  • Given that this block and a given block share a parent function, move this block after the given block in that function’s basic block list.

    Declaration

    Swift

    public func move(after position: BasicBlock)

    Parameters

    position

    The basic block that acts as a position after which this block will be moved.

  • Retrieves the underlying LLVM value object.

    Declaration

    Swift

    public func asLLVM() -> LLVMValueRef
  • Retrieves the name of this basic block.

    Declaration

    Swift

    public var name: String { get }
  • Returns the first instruction in the basic block, if it exists.

    Declaration

    Swift

    public var firstInstruction: Instruction? { get }
  • Returns the first instruction in the basic block, if it exists.

    Declaration

    Swift

    public var lastInstruction: Instruction? { get }
  • Returns the terminator instruction if this basic block is well formed or nil if it is not well formed.

    Declaration

    Swift

    public var terminator: TerminatorInstruction? { get }
  • Returns the parent function of this basic block, if it exists.

    Declaration

    Swift

    public var parent: Function? { get }
  • Returns the basic block following this basic block, if it exists.

    Declaration

    Swift

    public func next() -> BasicBlock?
  • Returns the basic block before this basic block, if it exists.

    Declaration

    Swift

    public func previous() -> BasicBlock?
  • Returns a sequence of the Instructions that make up this basic block.

    Declaration

    Swift

    public var instructions: AnySequence<Instruction> { get }
  • Removes this basic block from a function but keeps it alive.

    Note

    To ensure correct removal of the block, you must invalidate any references to it and its child instructions. The block must also have no successor blocks that make reference to it.

    Declaration

    Swift

    public func removeFromParent()
  • Moves this basic block before the given basic block.

    Declaration

    Swift

    public func moveBefore(_ block: BasicBlock)
  • Moves this basic block after the given basic block.

    Declaration

    Swift

    public func moveAfter(_ block: BasicBlock)
  • An Address represents a function-relative address of a basic block for use with the indirectbr instruction.

    See more

    Declaration

    Swift

    public struct Address : IRValue
  • Declaration

    Swift

    public static func == (lhs: BasicBlock, rhs: BasicBlock) -> Bool