@@ -22,6 +22,10 @@ namespace swift {
2222
2323// / This class is a simple wrapper around an alias analysis cache. This is
2424// / 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.
2529class AliasAnalysis {
2630public:
2731
@@ -159,14 +163,24 @@ class AliasAnalysis {
159163 return alias (V1, V2, TBAAType1, TBAAType2) == AliasResult::MayAlias;
160164 }
161165
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.
164182 MemoryBehavior computeMemoryBehavior (SILInstruction *Inst, SILValue V);
165183
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-
170184 // / Returns true if \p Inst may read from memory at address \p V.
171185 // /
172186 // / For details see MemoryBehavior::MayRead.
@@ -203,20 +217,37 @@ class AliasAnalysis {
203217 // / Returns true if \p Ptr may be released by the builtin \p BI.
204218 bool canBuiltinDecrementRefCount (BuiltinInst *BI, SILValue Ptr);
205219
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);
208221
209222 // / 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.
210226 bool isObjectReleasedByInst (SILValue obj, SILInstruction *toInst);
211227
212228 // / Is the `addr` within all reachable objects/addresses, when start walking
213229 // / from `obj`?
230+ // /
231+ // / Special entry point into BridgedAliasAnalysis (escape analysis) for use in
232+ // / ARC analysis.
214233 bool isAddrVisibleFromObject (SILValue addr, SILValue obj);
215234
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+
216249 // / Returns true if `lhs` can reference the same field as `rhs`.
217250 bool canReferenceSameField (SILValue lhs, SILValue rhs);
218-
219- int getEstimatedFunctionSize (SILValue valueInFunction);
220251};
221252
222253
0 commit comments