swift
f4c7d461 - Change the algorithm for the AccessEnforcementDom pass.

Commit
6 years ago
Change the algorithm for the AccessEnforcementDom pass. This adds a mostly flow-insensitive analysis that runs before the dominator-based transformations. The analysis is simple and efficient because it only needs to track data flow of currently in-scope accesses. The original dominator tree walk remains simple, but it now checks the flow insensitive analysis information to determine general correctness. This is now correct in the presence of all kinds of nested static and dynamic nested accesses, call sites, coroutines, etc. This is a better compromise than: (a) disabling the pass and taking a major performance loss. (b) converting the pass itself to full-fledged data flow driven optimization, which would be more optimal because it could remove accesses when nesting is involved, but would be much more expensive and complicated, and there's no indication that it's useful. The new approach is also simpler than adding more complexity to independently handle to each of many issues: - Nested reads followed by a modify without a false conflict. - Reads nested within a function call without a false conflict. - Conflicts nested within a function call without dropping enforcement. - Accesses within a generalized accessor. - Conservative treatment of invalid storage locations. - Conservative treatment of unknown apply callee. - General analysis invalidation. Some of these issues also needed to be considered in the LoopDominatingAccess sub-pass. Rather than fix that sub-pass, I just integrated it into the main pass. This is a simplification, is more efficient, and also handles nested loops without creating more redundant accesses. It is also generalized to: - hoist non-uniquely identified accesses. - Avoid unnecessarily promoting accesses inside the loop. With this approach we can remove the scary warnings and caveats in the comments. While doing this I also took the opportunity to eliminate quadratic behavior, make the domtree walk non-recursive, and eliminate cutoff thresholds. Note that simple nested dynamic reads to identical storage could very easily be removed via separate logic, but it does not fit with the dominator-based algorithm. For example, during the analysis phase, we could simply mark the "fully nested" read scopes, then convert them to [static] right after the analysis, removing them from the result map. I didn't do this because I don't know if it happens in practice.
Author
Committer
Parents
Loading