Skip to content

Commit 3d35b03

Browse files
committed
[AliasAnalysis] Document and cleanup referenceTypeTBAAMayAlias.
1 parent 89a8103 commit 3d35b03

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

Diff for: lib/SILAnalysis/AliasAnalysis.cpp

+24-19
Original file line numberDiff line numberDiff line change
@@ -442,29 +442,34 @@ static bool typedAccessTBAABuiltinTypesMayAlias(SILType LTy, SILType RTy,
442442
return false;
443443
}
444444

445-
/// Return true if LTyRef and RTyRef have a parent-child relationship, i.e.
446-
/// the objects with the given types mayalias.
447-
static bool referenceTypeTBAAMayAlias(SILType LTy, SILType RTy) {
448-
// Walk the type hiearchy to see whether LTy and RTy have a parent-child
449-
// relationship.
450-
SILType C = SILType();
451-
// Walk from LTy to RTy.
452-
C = LTy;
445+
/// Return true if the type \p Parent is a parent of \p Child in the
446+
/// class hierarchy.
447+
static bool isParentClass(SILType Parent, SILType Child) {
448+
SILType T = SILType();
449+
450+
// Walk the class hiearchy to see whether Parent and Child have a
451+
// parent-child relationship.
452+
T = Child;
453453
do {
454454
// There is a parent-child relationship.
455-
if (C == RTy)
455+
if (T == Parent)
456456
return true;
457-
C = C.getSuperclass(nullptr);
458-
} while(C);
459457

460-
// Walk from RTy to LTy.
461-
C = RTy;
462-
do {
463-
// There is a parent-child relationship.
464-
if (C == LTy)
465-
return true;
466-
C = C.getSuperclass(nullptr);
467-
} while(C);
458+
T = T.getSuperclass(nullptr);
459+
} while(T);
460+
461+
return false;
462+
}
463+
464+
/// Returns true if the reference types \p LTy and \pRTy may alias.
465+
static bool referenceTypeTBAAMayAlias(SILType LTy, SILType RTy) {
466+
467+
// Walk the type hiearchy to see whether LTy and RTy have a parent-child
468+
// relationship.
469+
if (isParentClass(LTy, RTy) ||
470+
isParentClass(RTy, LTy)) {
471+
return true;
472+
}
468473

469474
return false;
470475
}

0 commit comments

Comments
 (0)