@@ -22,6 +22,10 @@ namespace swift {
22
22
23
23
// / This class is a simple wrapper around an alias analysis cache. This is
24
24
// / needed since we do not have an "analysis" infrastructure.
25
+ // /
26
+ // / This wrapper sits above the SwiftCompilerSource implementation of
27
+ // / AliasAnalysis. The implementation calls into AliasAnalysis.swift via
28
+ // / BridgedAliasAnalysis whenever the result may depend on escape analysis.
25
29
class AliasAnalysis {
26
30
public:
27
31
@@ -159,14 +163,24 @@ class AliasAnalysis {
159
163
return alias (V1, V2, TBAAType1, TBAAType2) == AliasResult::MayAlias;
160
164
}
161
165
162
- // / Use the alias analysis to determine the memory behavior of Inst with
163
- // / respect to V.
166
+ // / Compute the effects of Inst's memory behavior on the memory pointed to by
167
+ // / the value V.
168
+ // /
169
+ // / This is the top-level API for memory behavior.
170
+ // /
171
+ // / 1. MemoryBehaviorVisitor overrides select instruction types. Types that
172
+ // / have no override default to SILInstruction::getMemoryBehavior(), which is
173
+ // / not specific to the memory pointed to by V.
174
+ // /
175
+ // / 2. For instruction types overridden by MemoryBehaviorVisitor, this uses
176
+ // / alias analysis to disambiguate the Inst's memory effects from the memory
177
+ // / pointed to by value V. 'mayAlias' is used for memory operations and
178
+ // / 'getMemoryEffectOnEscapedAddress' is used for calls and releases.
179
+ // /
180
+ // / 3. For calls, alias analysis uses callee analysis to retrieve function
181
+ // / side effects which provides the memory behavior of each argument.
164
182
MemoryBehavior computeMemoryBehavior (SILInstruction *Inst, SILValue V);
165
183
166
- // / Use the alias analysis to determine the memory behavior of Inst with
167
- // / respect to V.
168
- MemoryBehavior computeMemoryBehaviorInner (SILInstruction *Inst, SILValue V);
169
-
170
184
// / Returns true if \p Inst may read from memory at address \p V.
171
185
// /
172
186
// / For details see MemoryBehavior::MayRead.
@@ -203,20 +217,37 @@ class AliasAnalysis {
203
217
// / Returns true if \p Ptr may be released by the builtin \p BI.
204
218
bool canBuiltinDecrementRefCount (BuiltinInst *BI, SILValue Ptr);
205
219
206
- // / Returns true if the address(es of) `addr` can escape to `toInst`.
207
- MemoryBehavior getMemoryBehaviorOfInst (SILValue addr, SILInstruction *toInst);
220
+ int getEstimatedFunctionSize (SILValue valueInFunction);
208
221
209
222
// / Returns true if the object(s of) `obj` can escape to `toInst`.
223
+ // /
224
+ // / Special entry point into BridgedAliasAnalysis (escape analysis) for use in
225
+ // / ARC analysis.
210
226
bool isObjectReleasedByInst (SILValue obj, SILInstruction *toInst);
211
227
212
228
// / Is the `addr` within all reachable objects/addresses, when start walking
213
229
// / from `obj`?
230
+ // /
231
+ // / Special entry point into BridgedAliasAnalysis (escape analysis) for use in
232
+ // / ARC analysis.
214
233
bool isAddrVisibleFromObject (SILValue addr, SILValue obj);
215
234
235
+ // / MARK: implementation helpers for MemBehaviorVisitor.
236
+
237
+ // / If the address(es of) `addr` can escape to `toInst` (based on escape
238
+ // / analysis), return the memory effect of `toInst` on the escaped memory.
239
+ // /
240
+ // / This should not be called directly; it is an implementation helper for
241
+ // / querying escape analysis.
242
+ MemoryBehavior getMemoryEffectOnEscapedAddress (SILValue addr, SILInstruction *toInst);
243
+
244
+ protected:
245
+ // / Use the alias analysis to determine the memory behavior of Inst with
246
+ // / respect to V.
247
+ MemoryBehavior computeMemoryBehaviorInner (SILInstruction *Inst, SILValue V);
248
+
216
249
// / Returns true if `lhs` can reference the same field as `rhs`.
217
250
bool canReferenceSameField (SILValue lhs, SILValue rhs);
218
-
219
- int getEstimatedFunctionSize (SILValue valueInFunction);
220
251
};
221
252
222
253
0 commit comments