@@ -715,7 +715,8 @@ MemoryBehavior AliasAnalysis::getMemoryEffectOnEscapedAddress(
715
715
SILValue addr, SILInstruction *toInst) {
716
716
if (getMemEffectsFunction) {
717
717
return (MemoryBehavior)getMemEffectsFunction ({PM->getSwiftPassInvocation ()}, {addr},
718
- {toInst->asSILNode ()});
718
+ {toInst->asSILNode ()},
719
+ getComplexityBudget (addr));
719
720
}
720
721
return MemoryBehavior::MayHaveSideEffects;
721
722
}
@@ -729,16 +730,8 @@ bool AliasAnalysis::isObjectReleasedByInst(SILValue obj, SILInstruction *inst) {
729
730
730
731
bool AliasAnalysis::isAddrVisibleFromObject (SILValue addr, SILValue obj) {
731
732
if (isAddrVisibleFromObjFunction) {
732
- // This function is called a lot from ARCSequenceOpt and ReleaseHoisting.
733
- // To avoid quadratic complexity for large functions, we limit the amount
734
- // of work what the EscapeUtils are allowed to to.
735
- // This keeps the complexity linear.
736
- //
737
- // This arbitrary limit is good enough for almost all functions. It lets
738
- // the EscapeUtils do several hundred up/down walks which is much more than
739
- // needed in most cases.
740
- SwiftInt complexityLimit = 1000000 / getEstimatedFunctionSize (addr);
741
- return isAddrVisibleFromObjFunction ({PM->getSwiftPassInvocation ()}, {addr}, {obj}, complexityLimit) != 0 ;
733
+ return isAddrVisibleFromObjFunction ({PM->getSwiftPassInvocation ()}, {addr}, {obj},
734
+ getComplexityBudget (addr)) != 0 ;
742
735
}
743
736
return true ;
744
737
}
@@ -750,7 +743,14 @@ bool AliasAnalysis::canReferenceSameField(SILValue lhs, SILValue rhs) {
750
743
return true ;
751
744
}
752
745
753
- int AliasAnalysis::getEstimatedFunctionSize (SILValue valueInFunction) {
746
+ // To avoid quadratic complexity for large functions, we limit the amount
747
+ // of work what the EscapeUtils are allowed to to.
748
+ // This keeps the complexity linear.
749
+ //
750
+ // This arbitrary limit is good enough for almost all functions. It lets
751
+ // the EscapeUtils do several hundred up/down walks which is much more than
752
+ // needed in most cases.
753
+ int AliasAnalysis::getComplexityBudget (SILValue valueInFunction) {
754
754
if (estimatedFunctionSize < 0 ) {
755
755
int numInsts = 0 ;
756
756
SILFunction *f = valueInFunction->getFunction ();
@@ -759,5 +759,5 @@ int AliasAnalysis::getEstimatedFunctionSize(SILValue valueInFunction) {
759
759
}
760
760
estimatedFunctionSize = numInsts;
761
761
}
762
- return estimatedFunctionSize;
762
+ return 1000000 / estimatedFunctionSize;
763
763
}
0 commit comments