@@ -76,26 +76,18 @@ static inline bool shouldRunBasicAA() {
76
76
77
77
#endif
78
78
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
-
84
79
// ===----------------------------------------------------------------------===//
85
80
// Utilities
86
81
// ===----------------------------------------------------------------------===//
87
82
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) {
90
86
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" ;
99
91
}
100
92
}
101
93
@@ -265,9 +257,8 @@ static bool aliasUnequalObjects(SILValue O1, SILValue O2) {
265
257
// / Uses a bunch of ad-hoc rules to disambiguate a GEP instruction against
266
258
// / another pointer. We know that V1 is a GEP, but we don't know anything about
267
259
// / 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) {
271
262
272
263
// If V2 is also a gep instruction with a must-alias or not-aliasing base
273
264
// pointer, figure out if the indices of the GEPs tell us anything about the
@@ -278,9 +269,9 @@ AliasAnalysis::aliasAddressProjection(SILValue V1, SILValue V2,
278
269
// must alias relation on O1. This ensures that given an alloc_stack and a
279
270
// gep from that alloc_stack, we say that they partially alias.
280
271
if (isSameValueOrGlobal (O1, V2.stripCasts ()))
281
- return AliasAnalysis:: AliasResult::PartialAlias;
272
+ return AliasResult::PartialAlias;
282
273
283
- return AliasAnalysis:: AliasResult::MayAlias;
274
+ return AliasResult::MayAlias;
284
275
}
285
276
286
277
assert (!Projection::isAddrProjection (O1) &&
@@ -289,12 +280,12 @@ AliasAnalysis::aliasAddressProjection(SILValue V1, SILValue V2,
289
280
" underlying object may not be a projection" );
290
281
291
282
// Do the base pointers alias?
292
- AliasAnalysis:: AliasResult BaseAlias = aliasInner (O1, O2);
283
+ AliasResult BaseAlias = aliasInner (O1, O2);
293
284
294
285
// If the underlying objects are not aliased, the projected values are also
295
286
// not aliased.
296
- if (BaseAlias == AliasAnalysis:: AliasResult::NoAlias)
297
- return AliasAnalysis:: AliasResult::NoAlias;
287
+ if (BaseAlias == AliasResult::NoAlias)
288
+ return AliasResult::NoAlias;
298
289
299
290
// Let's do alias checking based on projections.
300
291
auto V1Path = ProjectionPath::getAddrProjectionPath (O1, V1, true );
@@ -311,32 +302,32 @@ AliasAnalysis::aliasAddressProjection(SILValue V1, SILValue V2,
311
302
// horizon) or enable Projection to represent a cast as a special sort of
312
303
// projection.
313
304
if (!V1Path || !V2Path)
314
- return AliasAnalysis:: AliasResult::MayAlias;
305
+ return AliasResult::MayAlias;
315
306
316
307
auto R = V1Path->computeSubSeqRelation (*V2Path);
317
308
318
309
// If all of the projections are equal (and they have the same base pointer),
319
310
// the two GEPs must be the same.
320
- if (BaseAlias == AliasAnalysis:: AliasResult::MustAlias &&
311
+ if (BaseAlias == AliasResult::MustAlias &&
321
312
R == SubSeqRelation_t::Equal)
322
- return AliasAnalysis:: AliasResult::MustAlias;
313
+ return AliasResult::MustAlias;
323
314
324
315
// The two GEPs do not alias if they are accessing different fields, even if
325
316
// we don't know the base pointers. Different fields should not overlap.
326
317
//
327
318
// TODO: Replace this with a check on the computed subseq relation. See the
328
319
// TODO in computeSubSeqRelation.
329
320
if (V1Path->hasNonEmptySymmetricDifference (V2Path.getValue ()))
330
- return AliasAnalysis:: AliasResult::NoAlias;
321
+ return AliasResult::NoAlias;
331
322
332
323
// If one of the GEPs is a super path of the other then they partially
333
324
// alias. W
334
- if (BaseAlias == AliasAnalysis:: AliasResult::MustAlias &&
325
+ if (BaseAlias == AliasResult::MustAlias &&
335
326
isStrictSubSeqRelation (R))
336
- return AliasAnalysis:: AliasResult::PartialAlias;
327
+ return AliasResult::PartialAlias;
337
328
338
329
// We failed to prove anything. Be conservative and return MayAlias.
339
- return AliasAnalysis:: AliasResult::MayAlias;
330
+ return AliasResult::MayAlias;
340
331
}
341
332
342
333
@@ -606,19 +597,17 @@ static bool typesMayAlias(SILType T1, SILType T2, SILType TBAA1Ty,
606
597
607
598
// / The main AA entry point. Performs various analyses on V1, V2 in an attempt
608
599
// / 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);
615
604
}
616
605
617
606
// / The main AA entry point. Performs various analyses on V1, V2 in an attempt
618
607
// / 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) {
622
611
#ifndef NDEBUG
623
612
// If alias analysis is disabled, always return may alias.
624
613
if (!shouldRunAA ())
@@ -648,24 +637,6 @@ AliasAnalysis::AliasResult AliasAnalysis::aliasInner(SILValue V1, SILValue V2,
648
637
DEBUG (llvm::dbgs () << " After Cast Stripping V1:" << *V1.getDef ());
649
638
DEBUG (llvm::dbgs () << " After Cast Stripping V2:" << *V2.getDef ());
650
639
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
-
669
640
// Ok, we need to actually compute an Alias Analysis result for V1, V2. Begin
670
641
// by finding the "base" of V1, V2 by stripping off all casts and GEPs.
671
642
SILValue O1 = getUnderlyingObject (V1);
@@ -676,7 +647,7 @@ AliasAnalysis::AliasResult AliasAnalysis::aliasInner(SILValue V1, SILValue V2,
676
647
// If O1 and O2 do not equal, see if we can prove that they can not be the
677
648
// same object. If we can, return No Alias.
678
649
if (O1 != O2 && aliasUnequalObjects (O1, O2))
679
- return cacheValue (Key, AliasResult::NoAlias) ;
650
+ return AliasResult::NoAlias;
680
651
681
652
// Ok, either O1, O2 are the same or we could not prove anything based off of
682
653
// 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,
694
665
if (Projection::isAddrProjection (V1)) {
695
666
AliasResult Result = aliasAddressProjection (V1, V2, O1, O2);
696
667
if (Result != AliasResult::MayAlias)
697
- return cacheValue (Key, Result) ;
668
+ return Result;
698
669
}
699
670
700
-
701
671
// We could not prove anything. Be conservative and return that V1, V2 may
702
672
// alias.
703
673
return AliasResult::MayAlias;
704
674
}
705
675
706
- // / Check if this is the address of a "let" member.
707
- // / Nobody can write into let members.
708
676
bool 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"
710
678
// and everything along this path is a value-type (i.e. struct or tuple).
711
679
712
680
// Is this an address of a "let" class member?
@@ -733,14 +701,6 @@ bool swift::isLetPointer(SILValue V) {
733
701
return false ;
734
702
}
735
703
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
- }
744
704
745
705
void AliasAnalysis::initialize (SILPassManager *PM) {
746
706
SEA = PM->getAnalysis <SideEffectAnalysis>();
0 commit comments