|
1 | 1 | # Utilities for SIL optimizer passes
|
2 | 2 | This document lists a set of SIL utilities to be used by the Swift implementation of the SIL optimizer.
|
3 | 3 |
|
4 |
| -The purpose of this proposal is to do a better planning of what utilities we need in SIL optimizer passes. |
| 4 | +Some of the utilities presented in this document are still in the design phase and are not implemented yet (see **Status**). |
5 | 5 |
|
| 6 | +### Goals for utilities |
6 | 7 | We want to avoid a situation like we have in the C++ SIL optimizer, where a huge amount of (partly) redundant utilities exist. Many of those utilities have overlapping functionality, are difficult to discover and are poorly designed. We want to do better in the Swift SIL optimizer.
|
7 | 8 |
|
8 | 9 | ## Basic Data-Structures
|
| 10 | + |
9 | 11 | #### `Stack`
|
10 | 12 |
|
11 | 13 | An allocation-free, array like data structure. To be used instead of `Swift.Array` wherever random-access is not needed.
|
12 | 14 |
|
13 | 15 | **Related C++ utilities:** `llvm::SmallVector`, `Stack`
|
14 |
| -**Status:** done |
| 16 | +**Status:** done |
15 | 17 |
|
16 | 18 | #### `BasicBlockSet`
|
17 | 19 | An extremely efficient implementation of a set of basic blocks.
|
18 | 20 |
|
19 | 21 | **Related C++ utilities:** `BasicBlockSet`
|
20 |
| -**Status:** done |
| 22 | +**Status:** done |
| 23 | + |
| 24 | +#### `ValueSet` |
| 25 | +An extremely efficient implementation of a set of values. |
| 26 | + |
| 27 | +**Related C++ utilities:** `ValueSet` |
| 28 | +**Status:** done |
| 29 | + |
| 30 | +#### `InstructionSet` |
| 31 | +An extremely efficient implementation of a set of instructions. |
| 32 | + |
| 33 | +**Related C++ utilities:** `InstructionSet ` |
| 34 | +**Status:** done |
21 | 35 |
|
22 | 36 | #### `BasicBlockWorklist`
|
23 | 37 | To be used for all kind of basic-block work-list algorithms.
|
24 | 38 |
|
25 | 39 | **Uses:** `Stack`, `BasicBlockSet`
|
26 | 40 | **Related C++ utilities:** `BasicBlockWorklist`
|
27 |
| -**Status:** done |
| 41 | +**Status:** done |
28 | 42 |
|
29 | 43 | ## Building SIL
|
30 | 44 |
|
31 | 45 | #### `static Builder.insert(after:, insertFunc: (Builder) -> ())`
|
32 | 46 | Useful to insert instructions after a (potential) terminator instruction.
|
33 | 47 |
|
34 | 48 | **Related C++ utilities:** `SILBuilderWithScope::insertAfter()`
|
35 |
| -**Status:** done |
| 49 | +**Status:** done |
| 50 | + |
| 51 | +## SSA Traversal Utilities |
| 52 | + |
| 53 | +#### Walk Utils |
| 54 | +This consists of four protocols, which can be implemented to walk up or down the SSA graph: |
| 55 | +* `ValueDefUseWalker` |
| 56 | +* `AddressDefUseWalker` |
| 57 | +* `ValueUseDefWalker` |
| 58 | +* `AddressUseDefWalker` |
| 59 | + |
| 60 | +**Uses:** instruction classifications |
| 61 | +**Related C++ utilities:** `AccessPath`, `RCIdentityAnalysis`, various def-use/use-def walkers in optimization passes. |
| 62 | +**Status:** done |
| 63 | + |
| 64 | +#### `SmallProjectionPath` |
| 65 | +Describes a path of projections. |
| 66 | + |
| 67 | +**Related C++ utilities:** `AccessPath`, `ProjectionPath` |
| 68 | +**Status:** done |
| 69 | + |
| 70 | +#### `EscapeInfo` |
| 71 | +Escape analysis, which is used e.g. in stack promotion or alias analysis. |
| 72 | + |
| 73 | +**Uses:** Walk Utils, `SmallProjectionPath` |
| 74 | +**Related C++ utilities:** `EscapeAnalysis`, various def-use walkers in optimization passes. |
| 75 | +**Status:** done |
| 76 | + |
| 77 | +#### Access Utils |
| 78 | +A set of utilities for analyzing memory accesses. It defines the following concepts: |
| 79 | +* `AccessBase`: represents the base address of a memory access. |
| 80 | +* `AccessPath`: a pair of an `AccessBase` and `SmallProjectionPath` with the path describing the specific address (in terms of projections) of the access. |
| 81 | +* `AccessStoragePath`: identifies the reference (or a value which contains a reference) an address originates from. |
| 82 | + |
| 83 | +**Uses:** Walk utils |
| 84 | +**Related C++ utilities:** `AccessPath` and other access utilities. |
| 85 | +**Status:** done |
| 86 | + |
| 87 | +## Control- and Dataflow |
| 88 | + |
| 89 | +#### `BasicBlockRange` |
| 90 | +Defines a range from a dominating "begin" block to one or more "end" blocks. To be used for all kind of backward block reachability analysis. |
| 91 | + |
| 92 | +**Uses:** `Stack`, `BasicBlockSet`, `BasicBlockWorklist` |
| 93 | +**Related C++ utilities:** `PrunedLiveBlocks`, `findJointPostDominatingSet()` |
| 94 | +**Status:** done |
| 95 | + |
| 96 | +#### `InstructionRange` |
| 97 | +Like `BasicBlockRange`, but at the granularity of instructions. |
| 98 | + |
| 99 | +**Uses:** `BasicBlockRange` |
| 100 | +**Related C++ utilities:** `PrunedLiveness`, `ValueLifetimeAnalysis` |
| 101 | +**Status:** done |
| 102 | + |
| 103 | +## Utilities for Inter-procedural Analysis |
| 104 | + |
| 105 | +### `FunctionUses` |
| 106 | +Provides a list of instructions, which reference a function. This utility performs an analysis of all functions in the module and collects instructions which reference other functions. It can be used to do inter-procedural caller-analysis. |
| 107 | + |
| 108 | +**Related C++ utilities:** `CallerAnalysis` |
| 109 | +**Status:** done |
| 110 | + |
| 111 | +## OSSA Utilities |
| 112 | + |
| 113 | +#### `Value.makeAvailable()` and `Value.copy(at:)` |
| 114 | +To be used where a value is copied in one block and used in another block. |
| 115 | + |
| 116 | +**Uses:** `BasicBlockRange` |
| 117 | +**Related C++ utilities:** `makeValueAvailable()`, `OwnershipLifetimeExtender` |
| 118 | +**Status:** done |
36 | 119 |
|
37 | 120 | ## Instruction classifications
|
38 | 121 | We want to classify certain instructions into common groups so that passes can deal deal with the group instead of individual instruction opcodes. Optimization passes then don't need to be updated if new instructions are added to a group.
|
@@ -78,55 +161,3 @@ Maybe it's better to not do this as a protocol but just add an extension functio
|
78 | 161 | **Conforming instructions:** `BeginBorrowInst`, `Argument` with guaranteed ownership (however will do that), `LoadBorrowInst`
|
79 | 162 | **Status:** to-do
|
80 | 163 |
|
81 |
| -## SSA Traversal Utilities |
82 |
| - |
83 |
| -#### Basic Walkers |
84 |
| -This is currently in progress. We'll probably have an up-walkers and down-walkers for both, addresses and non-address values. |
85 |
| - |
86 |
| -**Uses:** instruction classifications |
87 |
| -**Related C++ utilities:** `AccessPath`, `RCIdentityAnalysis`, various def-use/use-def walkers in optimization passes. |
88 |
| -**Status:** in progress |
89 |
| - |
90 |
| -#### `SmallProjectionPath` |
91 |
| -Describes a path of projections. |
92 |
| - |
93 |
| -**Related C++ utilities:** `AccessPath`, `ProjectionPath` |
94 |
| -**Status:** done |
95 |
| - |
96 |
| -#### `EscapeInfo` |
97 |
| -Escape analysis, which is used e.g. in stack promotion or alias analysis. |
98 |
| - |
99 |
| -**Uses:** basic walkers, `SmallProjectionPath` |
100 |
| -**Related C++ utilities:** `EscapeAnalysis`, various def-use walkers in optimization passes. |
101 |
| -**Status:** done, but factoring out the walkers is in progress |
102 |
| - |
103 |
| -#### `AccessPath` |
104 |
| -Details need to be decided. |
105 |
| - |
106 |
| -**Uses:** basic walkers |
107 |
| -**Related C++ utilities:** `AccessPath` |
108 |
| -**Status:** to-do |
109 |
| - |
110 |
| -## Control- and Dataflow |
111 |
| - |
112 |
| -#### `BasicBlockRange` |
113 |
| -Defines a range from a dominating "begin" block to one or more "end" blocks. To be used for all kind of backward block reachability analysis. |
114 |
| - |
115 |
| -**Uses:** `Stack`, `BasicBlockSet`, `BasicBlockWorklist` |
116 |
| -**Related C++ utilities:** `PrunedLiveBlocks`, `findJointPostDominatingSet()` |
117 |
| -**Status:** done |
118 |
| - |
119 |
| -#### `InstructionRange` |
120 |
| -Like `BasicBlockRange`, but at the granularity of instructions. |
121 |
| - |
122 |
| -**Uses:** `BasicBlockRange` |
123 |
| -**Related C++ utilities:** `PrunedLiveness`, `ValueLifetimeAnalysis` |
124 |
| -**Status:** done |
125 |
| - |
126 |
| -## OSSA Utilities |
127 |
| -#### `Value.makeAvailable()` and `Value.copy(at:)` |
128 |
| -To be used where a value is copied in one block and used in another block. |
129 |
| - |
130 |
| -**Uses:** `BasicBlockRange` |
131 |
| -**Related C++ utilities:** `makeValueAvailable()`, `OwnershipLifetimeExtender` |
132 |
| -**Status:** done |
|
0 commit comments