Skip to content

Commit ff95e7e

Browse files
committed
Update SIL-Utilities.md for new ownership utils.
1 parent b6b45f0 commit ff95e7e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

docs/SIL-Utilities.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ A projected value is defined by the original value and a projection path.
5454
**Related C++ utilities:** `AccessPath`
5555
**Status:** done
5656

57+
### `SingleInlineArray`
58+
59+
An array with the first element stored inline. Useful for analyses that produces results that are typically a 1-to-1 map, but rarely a 1-to-N map.
60+
5761
## Building SIL
5862

5963
#### `static Builder.insert(after:, insertFunc: (Builder) -> ())`
@@ -66,6 +70,7 @@ Useful to insert instructions after a (potential) terminator instruction.
6670

6771
#### Walk Utils
6872
This consists of four protocols, which can be implemented to walk up or down the SSA graph:
73+
6974
* `ValueDefUseWalker`
7075
* `AddressDefUseWalker`
7176
* `ValueUseDefWalker`
@@ -78,6 +83,7 @@ This consists of four protocols, which can be implemented to walk up or down the
7883
#### Escape Utilities
7984
Escape analysis, which is used e.g. in stack promotion or alias analysis.
8085
Escape analysis is usable through the following methods of `ProjectedValue` and `Value`:
86+
8187
* `isEscaping()`
8288
* `isAddressEscaping()`
8389
* `visit()`
@@ -89,6 +95,7 @@ Escape analysis is usable through the following methods of `ProjectedValue` and
8995

9096
#### Access Utils
9197
A set of utilities for analyzing memory accesses. It defines the following concepts:
98+
9299
* `AccessBase`: represents the base address of a memory access.
93100
* `AccessPath`: a pair of an `AccessBase` and `SmallProjectionPath` with the path describing the specific address (in terms of projections) of the access.
94101
* Access storage path (which is of type `ProjectedValue`): identifies the reference - or a value which contains a reference - an address originates from.
@@ -97,6 +104,34 @@ A set of utilities for analyzing memory accesses. It defines the following conce
97104
**Related C++ utilities:** `AccessPath` and other access utilities.
98105
**Status:** done
99106

107+
### Ownership Utils
108+
109+
#### BorrowUtils.swift has utilities for traversing borrow scopes:
110+
111+
* `BorrowingInstruction`: find borrow scopes during def-use walks
112+
* `BeginBorrowValue`: find borrow scopes during use-def walks
113+
* `gatherBorrowIntroducers`: use-def walk finds the current scopes
114+
* `gatherEnclosingValues`: use-def walk finds the outer lifetimes that enclose the current scope
115+
116+
#### OwnershipUtils.swift has utilities for traversing OSSA lifetimes:
117+
118+
* `computeLinearLiveness`: compute an InstructionRange from the immediate lifetime ending uses.
119+
* `computeInteriorLiveness`: complete def-use walk to compute an InstructionRange from all transitive use points that must be within an OSSA lifetime.
120+
* `InteriorUseWalker`: def-use walker for all transitive use points that must be within an OSSA lifetime.
121+
* `AddressLifetimeDefUseWalker`: def-use address walker to categorize all legal address uses by ownership effect.
122+
* `OwnershipUseVistor`: categorize all uses of an owned or guaranteed use by ownership effect. Use this within a recursive def-use walker to decide how to follow each use.
123+
124+
`AddressLifetimeDefUseWalker` currently differs from `AddressDefUseWalker`. It visits all uses regardless of whether they are projections, has callbacks for handling inner scopes, and automatically handles the lifetime effect of inner scopes and dependent values.
125+
126+
TODO: Define address projections in a single place rather than in both `AddressDefUseWalker` and `AddressUseVisitor`. This can be done with a simple `AddressProjection` protocol.
127+
128+
#### ForwardingUtils.swift has utilities for traversing forward-extended lifetimes:
129+
130+
Forward-extended lifetimes may include multiple OSSA lifetimes, joined by ForwardingInstructions. Querying certin information about OSSA lifetimes, such as whether it has a lexical lifetime or a pointer escape, requires finding the introducer of the forward-extended lfietime. Forwarding walkers traverse the SSA graph of ForwardingInstructions:
131+
132+
* `ForwardingUseDefWalker`: Find the introducer of a forward-extended lifetime
133+
* `ForwardingDefUseWalker`: Find all OSSA lifetimes within a forward-extended lifetime.
134+
100135
## Control- and Dataflow
101136

102137
#### `DeadEndBlocks`

0 commit comments

Comments
 (0)