@@ -76,26 +76,18 @@ static inline bool shouldRunBasicAA() {
7676
7777#endif
7878
79- static llvm::cl::opt<bool >
80- CacheAAResults (" cache-aa-results" ,
81- llvm::cl::desc (" Should AA results be cached" ),
82- llvm::cl::init(true ));
83-
8479// ===----------------------------------------------------------------------===//
8580// Utilities
8681// ===----------------------------------------------------------------------===//
8782
88- llvm::raw_ostream &swift::operator <<(llvm::raw_ostream &OS,
89- AliasAnalysis::AliasResult R) {
83+ using AliasResult = AliasAnalysis::AliasResult;
84+
85+ llvm::raw_ostream &swift::operator <<(llvm::raw_ostream &OS, AliasResult R) {
9086 switch (R) {
91- case AliasAnalysis::AliasResult::NoAlias:
92- return OS << " NoAlias" ;
93- case AliasAnalysis::AliasResult::MayAlias:
94- return OS << " MayAlias" ;
95- case AliasAnalysis::AliasResult::PartialAlias:
96- return OS << " PartialAlias" ;
97- case AliasAnalysis::AliasResult::MustAlias:
98- return OS << " MustAlias" ;
87+ case AliasResult::NoAlias: return OS << " NoAlias" ;
88+ case AliasResult::MayAlias: return OS << " MayAlias" ;
89+ case AliasResult::PartialAlias: return OS << " PartialAlias" ;
90+ case AliasResult::MustAlias: return OS << " MustAlias" ;
9991 }
10092}
10193
@@ -265,9 +257,8 @@ static bool aliasUnequalObjects(SILValue O1, SILValue O2) {
265257// / Uses a bunch of ad-hoc rules to disambiguate a GEP instruction against
266258// / another pointer. We know that V1 is a GEP, but we don't know anything about
267259// / V2. O1, O2 are getUnderlyingObject of V1, V2 respectively.
268- AliasAnalysis::AliasResult
269- AliasAnalysis::aliasAddressProjection (SILValue V1, SILValue V2,
270- SILValue O1, SILValue O2) {
260+ AliasResult AliasAnalysis::aliasAddressProjection (SILValue V1, SILValue V2,
261+ SILValue O1, SILValue O2) {
271262
272263 // If V2 is also a gep instruction with a must-alias or not-aliasing base
273264 // pointer, figure out if the indices of the GEPs tell us anything about the
@@ -278,9 +269,9 @@ AliasAnalysis::aliasAddressProjection(SILValue V1, SILValue V2,
278269 // must alias relation on O1. This ensures that given an alloc_stack and a
279270 // gep from that alloc_stack, we say that they partially alias.
280271 if (isSameValueOrGlobal (O1, V2.stripCasts ()))
281- return AliasAnalysis:: AliasResult::PartialAlias;
272+ return AliasResult::PartialAlias;
282273
283- return AliasAnalysis:: AliasResult::MayAlias;
274+ return AliasResult::MayAlias;
284275 }
285276
286277 assert (!Projection::isAddrProjection (O1) &&
@@ -289,12 +280,12 @@ AliasAnalysis::aliasAddressProjection(SILValue V1, SILValue V2,
289280 " underlying object may not be a projection" );
290281
291282 // Do the base pointers alias?
292- AliasAnalysis:: AliasResult BaseAlias = aliasInner (O1, O2);
283+ AliasResult BaseAlias = aliasInner (O1, O2);
293284
294285 // If the underlying objects are not aliased, the projected values are also
295286 // not aliased.
296- if (BaseAlias == AliasAnalysis:: AliasResult::NoAlias)
297- return AliasAnalysis:: AliasResult::NoAlias;
287+ if (BaseAlias == AliasResult::NoAlias)
288+ return AliasResult::NoAlias;
298289
299290 // Let's do alias checking based on projections.
300291 auto V1Path = ProjectionPath::getAddrProjectionPath (O1, V1, true );
@@ -311,32 +302,32 @@ AliasAnalysis::aliasAddressProjection(SILValue V1, SILValue V2,
311302 // horizon) or enable Projection to represent a cast as a special sort of
312303 // projection.
313304 if (!V1Path || !V2Path)
314- return AliasAnalysis:: AliasResult::MayAlias;
305+ return AliasResult::MayAlias;
315306
316307 auto R = V1Path->computeSubSeqRelation (*V2Path);
317308
318309 // If all of the projections are equal (and they have the same base pointer),
319310 // the two GEPs must be the same.
320- if (BaseAlias == AliasAnalysis:: AliasResult::MustAlias &&
311+ if (BaseAlias == AliasResult::MustAlias &&
321312 R == SubSeqRelation_t::Equal)
322- return AliasAnalysis:: AliasResult::MustAlias;
313+ return AliasResult::MustAlias;
323314
324315 // The two GEPs do not alias if they are accessing different fields, even if
325316 // we don't know the base pointers. Different fields should not overlap.
326317 //
327318 // TODO: Replace this with a check on the computed subseq relation. See the
328319 // TODO in computeSubSeqRelation.
329320 if (V1Path->hasNonEmptySymmetricDifference (V2Path.getValue ()))
330- return AliasAnalysis:: AliasResult::NoAlias;
321+ return AliasResult::NoAlias;
331322
332323 // If one of the GEPs is a super path of the other then they partially
333324 // alias. W
334- if (BaseAlias == AliasAnalysis:: AliasResult::MustAlias &&
325+ if (BaseAlias == AliasResult::MustAlias &&
335326 isStrictSubSeqRelation (R))
336- return AliasAnalysis:: AliasResult::PartialAlias;
327+ return AliasResult::PartialAlias;
337328
338329 // We failed to prove anything. Be conservative and return MayAlias.
339- return AliasAnalysis:: AliasResult::MayAlias;
330+ return AliasResult::MayAlias;
340331}
341332
342333
@@ -606,19 +597,17 @@ static bool typesMayAlias(SILType T1, SILType T2, SILType TBAA1Ty,
606597
607598// / The main AA entry point. Performs various analyses on V1, V2 in an attempt
608599// / to disambiguate the two values.
609- AliasAnalysis::AliasResult AliasAnalysis::alias (SILValue V1, SILValue V2,
610- SILType TBAAType1,
611- SILType TBAAType2) {
612- auto Result = aliasInner (V1, V2, TBAAType1, TBAAType2);
613- AliasCache.clear ();
614- return Result;
600+ AliasResult AliasAnalysis::alias (SILValue V1, SILValue V2,
601+ SILType TBAAType1,
602+ SILType TBAAType2) {
603+ return aliasInner (V1, V2, TBAAType1, TBAAType2);
615604}
616605
617606// / The main AA entry point. Performs various analyses on V1, V2 in an attempt
618607// / to disambiguate the two values.
619- AliasAnalysis:: AliasResult AliasAnalysis::aliasInner (SILValue V1, SILValue V2,
620- SILType TBAAType1,
621- SILType TBAAType2) {
608+ AliasResult AliasAnalysis::aliasInner (SILValue V1, SILValue V2,
609+ SILType TBAAType1,
610+ SILType TBAAType2) {
622611#ifndef NDEBUG
623612 // If alias analysis is disabled, always return may alias.
624613 if (!shouldRunAA ())
@@ -648,24 +637,6 @@ AliasAnalysis::AliasResult AliasAnalysis::aliasInner(SILValue V1, SILValue V2,
648637 DEBUG (llvm::dbgs () << " After Cast Stripping V1:" << *V1.getDef ());
649638 DEBUG (llvm::dbgs () << " After Cast Stripping V2:" << *V2.getDef ());
650639
651- // Create a key to lookup if we have already computed an alias result for V1,
652- // V2. Canonicalize our cache keys so that the pointer with the lower address
653- // is always the first element of the pair. This ensures we do not pollute our
654- // cache with two entries with the same key, albeit with the key's fields
655- // swapped.
656- auto Key = V1 < V2? std::make_pair (V1, V2) : std::make_pair (V2, V1);
657-
658- // If we find our key in the cache, just return the alias result.
659- if (CacheAAResults) {
660- auto Pair = AliasCache.find (Key);
661- if (Pair != AliasCache.end ()) {
662- DEBUG (llvm::dbgs () << " Found value in the cache: " << Pair->second
663- << " \n " );
664-
665- return Pair->second ;
666- }
667- }
668-
669640 // Ok, we need to actually compute an Alias Analysis result for V1, V2. Begin
670641 // by finding the "base" of V1, V2 by stripping off all casts and GEPs.
671642 SILValue O1 = getUnderlyingObject (V1);
@@ -676,7 +647,7 @@ AliasAnalysis::AliasResult AliasAnalysis::aliasInner(SILValue V1, SILValue V2,
676647 // If O1 and O2 do not equal, see if we can prove that they can not be the
677648 // same object. If we can, return No Alias.
678649 if (O1 != O2 && aliasUnequalObjects (O1, O2))
679- return cacheValue (Key, AliasResult::NoAlias) ;
650+ return AliasResult::NoAlias;
680651
681652 // Ok, either O1, O2 are the same or we could not prove anything based off of
682653 // their inequality. Now we climb up use-def chains and attempt to do tricks
@@ -694,19 +665,16 @@ AliasAnalysis::AliasResult AliasAnalysis::aliasInner(SILValue V1, SILValue V2,
694665 if (Projection::isAddrProjection (V1)) {
695666 AliasResult Result = aliasAddressProjection (V1, V2, O1, O2);
696667 if (Result != AliasResult::MayAlias)
697- return cacheValue (Key, Result) ;
668+ return Result;
698669 }
699670
700-
701671 // We could not prove anything. Be conservative and return that V1, V2 may
702672 // alias.
703673 return AliasResult::MayAlias;
704674}
705675
706- // / Check if this is the address of a "let" member.
707- // / Nobody can write into let members.
708676bool swift::isLetPointer (SILValue V) {
709- // Traverse the "access" path for V and check that starts with "let"
677+ // Traverse the "access" path for V and check that it starts with "let"
710678 // and everything along this path is a value-type (i.e. struct or tuple).
711679
712680 // Is this an address of a "let" class member?
@@ -733,14 +701,6 @@ bool swift::isLetPointer(SILValue V) {
733701 return false ;
734702}
735703
736- AliasAnalysis::AliasResult AliasAnalysis::cacheValue (AliasCacheKey Key,
737- AliasResult Result) {
738- if (!CacheAAResults)
739- return Result;
740- DEBUG (llvm::dbgs () << " Caching Alias Result: " << Result << " \n " << Key.first
741- << Key.second << " \n " );
742- return AliasCache[Key] = Result;
743- }
744704
745705void AliasAnalysis::initialize (SILPassManager *PM) {
746706 SEA = PM->getAnalysis <SideEffectAnalysis>();
0 commit comments