Skip to content

Commit 1407846

Browse files
committed
docs: update SIL-Utilities.md
And move it out of the "proposals" folder, directly into "docs". It's now more a documentation of what we have and useful as a programming guide.
1 parent a12e33e commit 1407846

File tree

1 file changed

+88
-57
lines changed

1 file changed

+88
-57
lines changed

docs/proposals/SIL-Utilities.md renamed to docs/SIL-Utilities.md

Lines changed: 88 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,121 @@
11
# Utilities for SIL optimizer passes
22
This document lists a set of SIL utilities to be used by the Swift implementation of the SIL optimizer.
33

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**).
55

6+
### Goals for utilities
67
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.
78

89
## Basic Data-Structures
10+
911
#### `Stack`
1012

1113
An allocation-free, array like data structure. To be used instead of `Swift.Array` wherever random-access is not needed.
1214

1315
**Related C++ utilities:** `llvm::SmallVector`, `Stack`
14-
**Status:** done
16+
**Status:** done
1517

1618
#### `BasicBlockSet`
1719
An extremely efficient implementation of a set of basic blocks.
1820

1921
**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
2135

2236
#### `BasicBlockWorklist`
2337
To be used for all kind of basic-block work-list algorithms.
2438

2539
**Uses:** `Stack`, `BasicBlockSet`
2640
**Related C++ utilities:** `BasicBlockWorklist`
27-
**Status:** done
41+
**Status:** done
2842

2943
## Building SIL
3044

3145
#### `static Builder.insert(after:, insertFunc: (Builder) -> ())`
3246
Useful to insert instructions after a (potential) terminator instruction.
3347

3448
**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
36119

37120
## Instruction classifications
38121
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
78161
**Conforming instructions:** `BeginBorrowInst`, `Argument` with guaranteed ownership (however will do that), `LoadBorrowInst`
79162
**Status:** to-do
80163

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

Comments
 (0)