Commits
Michael Gottesman committed 6593eec5330
[g-arc-opts] Implement release post-dominated by use optimization. Currently in the ARC optimizer, we perform the double release algorithm. The logic behind the double release algorithm is that given the following situation: retain(x) call(x) call(x) release(x) release(x) The fact that we have two releases in a row on x implies that before the first release, we know statically that the reference count of x must be >= 2 implying we can remove the retain, release pair safely. This optimization was tempered by the restriction that the two releases could not have a use in between them. While thinking about this algorithm, I realized that the key thing about this optimization is *NOT* that I have two releases in a row. The interesting part of the optimization is that I know the reference count of x must be >= 2 before the first release. To ascertain that, we do not care about having another release, all that we care about is that there is an operation after the first release that requires x to be alive. Since x must be alive after the first release, we know that that release can not be the last release. This yields a much stronger optimization since it implies that if we see a release that is post dominated by a second release, we always know that the first release is known safe. Thus the optimization sequence looks like the following: retain(x) call(x) call(x) release(x) ... use(x) The current implementation of this algorithm is very simple and just changes the optimizer by saying that two nested decrements causes the first decrement to be known safe as long as there is not a retain on the same pointer in between the two decrements. The reason why this is important is that if we remove the second release in the ARC optimizer then that decrement (since it is removed) can not be considered the local use that allows us to conclude that the first is known safe. <rdar://problem/17372698> ARC: Implement the stronger release algorithm Swift SVN r19033