Function
public struct Function : Sendable
A collection of basic blocks representing a lowered function.
-
A collection of blocks with stable identities.
Declaration
Swift
public typealias Blocks = DoublyLinkedList<Block> -
A collection of instructions with stable identities.
Declaration
Swift
public typealias Instructions = DoublyLinkedList<Instruction> -
trueiff the function implements a subscript.Declaration
Swift
public let isSubscript: Bool -
The site in the source code to which the function corresponds..
Declaration
Swift
public let site: SourceRange -
The linkage of the function.
Declaration
Swift
public let linkage: Linkage -
The generic (a.k.a., compile-time) parameters of the function.
Declaration
Swift
public let genericParameters: [GenericParameterDecl.ID] -
The run-time parameters of the function.
Declaration
Swift
public let inputs: [Parameter] -
The type of the function’s output.
Declaration
Swift
public let output: AnyType -
The basic blocks of the control flow graph.
Declaration
Swift
public var blocks: Blocks -
The instructions in the function.
Declaration
Swift
public var instructions: Instructions -
The block associated with each instruction.
Declaration
Swift
internal var blockForInstruction: [InstructionID : Block.ID] -
The def-use chains of the values in this module.
-
Accesses the basic block at
address.Requires
addressmust be a valid address inself. -
Accesses the block identified by
b. -
Accesses the instruction identified by
i.Declaration
Swift
public subscript(i: InstructionID) -> Instruction { get set } -
Accesses the instruction denoted by
oif it is.register; returnsnilotherwise.Declaration
Swift
public subscript(register o: Operand) -> Instruction? { get } -
The entry of the function.
-
trueiff the function takes generic parameters.Declaration
Swift
public var isGeneric: Bool { get } -
Returns the identity of the return value.
Declaration
Swift
public var returnValue: Operand? { get } -
The IDs of all basic blocks in the CFG, beginning with the entry point block.
The first element of the returned collection is the function’s entry; other elements are in no particular order.
-
The IDs of all instructions.
Declaration
Swift
public var instructionIdentities: some Collection<InstructionID> { get } -
Returns the control flow graph of
self.Declaration
Swift
func cfg() -> ControlFlowGraph -
Appends a basic block in
scope, returning its address.The first block appended becomes the entry point block. The first block takes the parameters of the function; other blocks take no parameters.
Declaration
-
Removes
blockand updates def-use chains.Requires
No instruction inblockis used by an instruction outside ofblock. -
Replaces
oldwithnew.The def-use chains are updated so that the uses formerly made by
oldare replaced by the uses made bynewand all former uses ofoldrefer tonew. After the call,self[old] == new.Requires
newproduces results with the same types asold.Declaration
Swift
mutating func replace<I>(_ old: InstructionID, with new: I) where I : Instruction -
Replaces all uses of
oldwithnewand updates the def-use chains.The def-use chains are updated so that the uses formerly made by
oldare replaced by the uses made bynewand all former uses ofoldrefer tonew.Requires
newas the same type asold. -
Inserts
newInstructionatboundaryand returns its identity.Declaration
Swift
@discardableResult mutating func insert( _ newInstruction: Instruction, at boundary: InsertionPoint ) -> InstructionID -
Adds
newInstructionat the start ofblockand returns its identity.Declaration
Swift
@discardableResult private mutating func prepend(_ newInstruction: Instruction, to block: Block.ID) -> InstructionID -
Adds
newInstructionat the end ofblockand returns its identity.Declaration
Swift
@discardableResult private mutating func append(_ newInstruction: Instruction, to block: Block.ID) -> InstructionID -
Inserts
newInstructionbeforesuccessorand returns its identity.Declaration
Swift
@discardableResult private mutating func insert( _ newInstruction: Instruction, before successor: InstructionID ) -> InstructionID -
Inserts
newInstructionafterpredecessorand returns its identity.Declaration
Swift
@discardableResult private mutating func insert( _ newInstruction: Instruction, after predecessor: InstructionID ) -> InstructionID -
Removes instruction
iand updates def-use chains.Requires
The result ofihave no users.Declaration
Swift
mutating func remove(_ i: InstructionID) -
Removes
ifrom its corresponding block.Declaration
Swift
private mutating func removeFromBlock(_ i: InstructionID) -
Removes all instructions after
iin its containing block and updates def-use chains.Requires
LetSbe the set of removed instructions, all users of a result ofjinSare also inS.Declaration
Swift
mutating func removeAllInstructions(after i: InstructionID) -
Keep track of uses for
instructionidentified byid.Declaration
Swift
private mutating func addUses(for instruction: Instruction, with id: InstructionID) -
Removes
ifrom the def-use chains of its operands.Declaration
Swift
private mutating func removeUsesMadeBy(_ i: InstructionID) -
Returns the IDs of the instructions in
b, in order.Declaration
Swift
public func instructions( in b: Block.ID ) -> some Sequence<InstructionID> -
Returns the ID of the first instruction in
b, if any.Declaration
Swift
public func firstInstruction(in b: Block.ID) -> InstructionID? -
Returns the ID the instruction before
i.Note: this may cross block boundaries.
Declaration
Swift
func instruction(before i: InstructionID) -> InstructionID? -
Returns the ID the instruction before
i.Declaration
Swift
func instruction(before i: InstructionID, in b: Block.ID) -> InstructionID? -
Returns the ID the instruction after
i.Note: this may cross block boundaries.
Declaration
Swift
func instruction(after i: InstructionID) -> InstructionID? -
Returns the ID the instruction after
i, in blockb.Declaration
Swift
public func instruction(after i: InstructionID, in b: Block.ID) -> InstructionID? -
Returns the block corresponding to
i.Declaration
Swift
public func block(of i: InstructionID) -> Block.ID -
Returns the block corresponding to
p.Declaration
Swift
internal func block(of p: InsertionPoint) -> Block.ID? -
Returns the scope in which
iis used.Declaration
Swift
public func scope(containing i: InstructionID) -> AnyScopeID -
Returns
trueifflhsis sequenced beforerhsin the block oflhs. Returnsfalseif the two instructions are not in the same block.Declaration
Swift
public func precedes(_ lhs: InstructionID, _ rhs: InstructionID) -> Bool -
Returns
trueifflhsis sequenced beforerhson all paths leading torhs.Declaration
Swift
func dominates(_ lhs: InstructionID, _ rhs: InstructionID) -> Bool -
Returns the global identity of
block‘s terminator, if it exists.Declaration
Swift
func terminator(of block: Block.ID) -> InstructionID? -
Returns the register assigned by
i, if any.Declaration
Swift
func result(of i: InstructionID) -> Operand? -
Returns the type of
operand.Declaration
Swift
public func type(of operand: Operand) -> IR.Type -
Returns
trueiffpcannot be used to modify or update a value.Declaration
Swift
public func isBoundImmutably(_ p: Operand) -> Bool -
Returns
trueiff the result oficannot be used to modify or update a value.Declaration
Swift
public func isBoundImmutably(register i: InstructionID) -> Bool -
If
pis a function parameter, returns its passing convention. Otherwise, returnsnil.Declaration
Swift
public func passingConvention(of p: Operand) -> AccessEffect? -
Returns the passing convention of the
i-th parameter ofself.Declaration
Swift
public func passingConvention(parameter i: Int) -> AccessEffect -
Returns the uses of all the registers assigned by
i.Declaration
Swift
func allUses(of i: InstructionID) -> [Use] -
Returns the operands from which the address denoted by
aderives.The (static) provenances of an address denote the original operands from which it derives. They form a set because an address computed by a projection depends on that projection’s arguments and because an address defined as a parameter of a basic block with multiple predecessors depends on that bock’s arguments.
-
Returns
trueifocan be sunken.Declaration
Swift
func isSink(_ o: Operand) -> Bool -
Returns
trueiffois anaccess [set]instruction.Declaration
Swift
func isBorrowSet(_ o: Operand) -> Bool -
Check if projection
selfis well-formed, raising diagnostics tologas needed, and returns the relevant information for expanding projections.Declaration
Swift
fileprivate func checkYieldCoherence( reportingDiagnosticsTo log: inout DiagnosticSet ) throws -> ProjectionSkeleton -
Returns the block containing a yield that has
bas a slide block, if any.Complexity
O(n) in the number of blocks in the CFG.Declaration
-
Returns the first yield instruction in block
b.Declaration
Swift
private func yieldForBlock(_ b: Block.ID) -> InstructionID? -
The global identity of an IR function.
See moreDeclaration
View on GitHub