summaryrefslogtreecommitdiff
path: root/lib/Transforms/ObjCARC
Commit message (Collapse)AuthorAge
* [objc-arc] Ensure that the cfg path count does not overflow when we multiply ↵Michael Gottesman2013-06-07
| | | | | | | | TopDownPathCount/BottomUpPathCount. rdar://12480535 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183489 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] KnownSafe does not imply that it is safe to perform code motion ↵Michael Gottesman2013-05-24
| | | | | | | | across CFG edges since even if it is safe to remove RR pairs, we may still be able to move a retain/release into a loop. rdar://13949644 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182670 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Make sure that multiple owners is propogated correctly through ↵Michael Gottesman2013-05-24
| | | | | | | | the pass via the usage of a global data structure. rdar://13750319 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182669 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Fixed number of prefixing slashes in some comments in a function ↵Michael Gottesman2013-05-23
| | | | | | from 3 to 2 to match the rest of ObjCARCOpts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182557 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Fixed a spelling error and made the statistic descriptions be ↵Michael Gottesman2013-05-15
| | | | | | consistent about their usage of periods. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181901 91177308-0d34-0410-b5e6-96231b3b80d8
* Removed trailing whitespace.Michael Gottesman2013-05-14
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181760 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc-opts] Added debug statements when we set and unset whether a ↵Michael Gottesman2013-05-14
| | | | | | pointer is known positive. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181745 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc-opts] In the presense of an alloca unconditionally remove RR pairs ↵Michael Gottesman2013-05-13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | if and only if we are both KnownSafeBU/KnownSafeTD rather than just either or. In the presense of a block being initialized, the frontend will emit the objc_retain on the original pointer and the release on the pointer loaded from the alloca. The optimizer will through the provenance analysis realize that the two are related (albiet different), but since we only require KnownSafe in one direction, will match the inner retain on the original pointer with the guard release on the original pointer. This is fixed by ensuring that in the presense of allocas we only unconditionally remove pointers if both our retain and our release are KnownSafe (i.e. we are KnownSafe in both directions) since we must deal with the possibility that the frontend will emit what (to the optimizer) appears to be unbalanced retain/releases. An example of the miscompile is: %A = alloca retain(%x) retain(%x) <--- Inner Retain store %x, %A %y = load %A ... DO STUFF ... release(%y) call void @use(%x) release(%x) <--- Guarding Release getting optimized to: %A = alloca retain(%x) store %x, %A %y = load %A ... DO STUFF ... release(%y) call void @use(%x) rdar://13750319 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181743 91177308-0d34-0410-b5e6-96231b3b80d8
* Move a couple more statistics inside '#ifndef NDEBUG'.Matt Beaumont-Gay2013-05-13
| | | | | | Suppresses an unused-variable warning in -Asserts builds. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181733 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc-opts] Add comment to BBState making it clear that ↵Michael Gottesman2013-05-13
| | | | | | get{TopDown,BottomUp}PtrState will create a new PtrState object if it does not find a PtrState for Arg. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181726 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Move the before optimization statistics gathering phase out of ↵Michael Gottesman2013-05-13
| | | | | | | | | | | OptimizeIndividualCalls. This makes the statistics gathering completely independent of the actual optimization occuring, preventing any sort of bleeding over from occuring. Additionally, it simplifies a switch statement in the non-statistic gathering case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181719 91177308-0d34-0410-b5e6-96231b3b80d8
* Add ArrayRef constructor from None, and do the cleanups that this ↵Dmitri Gribenko2013-05-05
| | | | | | | | | constructor enables Patch by Robert Wilhelm. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181138 91177308-0d34-0410-b5e6-96231b3b80d8
* This patch breaks up Wrap.h so that it does not have to include all of Filip Pizlo2013-05-01
| | | | | | | | | | | | | | | | | | | | | | | | | | the things, and renames it to CBindingWrapping.h. I also moved CBindingWrapping.h into Support/. This new file just contains the macros for defining different wrap/unwrap methods. The calls to those macros, as well as any custom wrap/unwrap definitions (like for array of Values for example), are put into corresponding C++ headers. Doing this required some #include surgery, since some .cpp files relied on the fact that including Wrap.h implicitly caused the inclusion of a bunch of other things. This also now means that the C++ headers will include their corresponding C API headers; for example Value.h must include llvm-c/Core.h. I think this is harmless, since the C API headers contain just external function declarations and some C types, so I don't believe there should be any nasty dependency issues here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180881 91177308-0d34-0410-b5e6-96231b3b80d8
* Add in some conditional compilation in order to silence an unused variable ↵Michael Gottesman2013-04-29
| | | | | | warning. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180700 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Apply the RV optimization to retains next to calls in ↵Michael Gottesman2013-04-29
| | | | | | | | | | | | | | | ObjCARCContract instead of ObjCARCOpts. Turning retains into retainRV calls disrupts the data flow analysis in ObjCARCOpts. Thus we move it as late as we can by moving it into ObjCARCContract. We leave in the conversion from retainRV -> retain in ObjCARCOpt since it enables the dataflow analysis. rdar://10813093 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180698 91177308-0d34-0410-b5e6-96231b3b80d8
* Added statistics to count the number of retains/releases before/after ↵Michael Gottesman2013-04-29
| | | | | | optimization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180697 91177308-0d34-0410-b5e6-96231b3b80d8
* Removed trailing whitespace.Michael Gottesman2013-04-29
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180696 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix for r180693. = /.Michael Gottesman2013-04-29
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180694 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc-annotations] Moved the disabling of call movement to ↵Michael Gottesman2013-04-29
| | | | | | ConnectTDBUTraversals so that I can prevent Changed = true from being set. This prevents an infinite loop. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180693 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "[objc-arc] Added ImpreciseAutoreleaseSet to track autorelease calls ↵Michael Gottesman2013-04-26
| | | | | | | | | | | | | | that were once autoreleaseRV instructions." This reverts commit r180222. I think this might tie in with a different problem which will require a different approach potentially. I am reverting this in the case I need to go down that second path. My apologies for the noise. = /. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180590 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Added ImpreciseAutoreleaseSet to track autorelease calls that ↵Michael Gottesman2013-04-24
| | | | | | | | | | | | | | | | | | | | | | | | | | were once autoreleaseRV instructions. Due to the semantics of ARC, we must be extremely conservative with autorelease calls inserted by the frontend since ARC gaurantees that said object will be in the autorelease pool after that point, an optimization invariant that the optimizer must respect. On the other hand, we are allowed significantly more flexibility with autoreleaseRV instructions. Often times though this flexibility is disrupted by early transformations which transform objc_autoreleaseRV => objc_autorelease if said instruction is no longer being used as part of an RV pair (generally due to inlining). Since we can not tell the difference in between an autorelease put into place by the frontend and one created through said ``strength reduction'' we can not perform these optimizations. The addition of this set gets around said issues by allowing us to differentiate in between said two cases. rdar://problem/13697741. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180222 91177308-0d34-0410-b5e6-96231b3b80d8
* Fixed comment typo.Michael Gottesman2013-04-24
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180221 91177308-0d34-0410-b5e6-96231b3b80d8
* Move C++ code out of the C headers and into either C++ headersEric Christopher2013-04-22
| | | | | | | or the C++ files themselves. This enables people to use just a C compiler to interoperate with LLVM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180063 91177308-0d34-0410-b5e6-96231b3b80d8
* When we strength reduce an objc_retainBlock call to objc_retain, increment ↵Michael Gottesman2013-04-21
| | | | | | NumPeeps and make sure that Changed is set to true. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179968 91177308-0d34-0410-b5e6-96231b3b80d8
* Fixed comment typo.Michael Gottesman2013-04-21
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179967 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Fixed typo in debug message.Michael Gottesman2013-04-21
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179966 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Fixed comment typo.Michael Gottesman2013-04-21
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179965 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Refactored OptimizeReturns so that it uses continue instead of a ↵Michael Gottesman2013-04-21
| | | | | | large multi-level nested if statement. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179964 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Added debug statement saying when we are resetting a sequence's ↵Michael Gottesman2013-04-20
| | | | | | | | | | progress. This will make it clearer when we are actually resetting a sequence's progress vs just changing state. This is an important distinction because the former case clears any pointers that we are tracking while the later does not. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179963 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Do not mismatch up retains inside a for loop with releases ↵Michael Gottesman2013-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | outside said for loop in the presense of differing provenance caused by escaping blocks. This occurs due to an alloca representing a separate ownership from the original pointer. Thus consider the following pseudo-IR: objc_retain(%a) for (...) { objc_retain(%a) %block <- %a F(%block) objc_release(%block) } objc_release(%a) From the perspective of the optimizer, the %block is a separate provenance from the original %a. Thus the optimizer pairs up the inner retain for %a and the outer release from %a, resulting in segfaults. This is fixed by noting that the signature of a mismatch of retain/releases inside the for loop is a Use/CanRelease top down with an None bottom up (since bottom up the Retain-CanRelease-Use-Release sequence is completed by the inner objc_retain, but top down due to the differing provenance from the objc_release said sequence is not completed). In said case in CheckForCFGHazards, we now clear the state of %a implying that no pairing will occur. Additionally a test case is included. rdar://12969722 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179747 91177308-0d34-0410-b5e6-96231b3b80d8
* Removed trailing whitespace.Michael Gottesman2013-04-18
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179746 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Added annotation option to only emit annotations for a specific ↵Michael Gottesman2013-04-17
| | | | | | ssa identifier. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179729 91177308-0d34-0410-b5e6-96231b3b80d8
* Fixed typo.Michael Gottesman2013-04-17
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179721 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Added descriptions for EnableARCAnnotations, ↵Michael Gottesman2013-04-17
| | | | | | EnableCheckForCFGHazards, EnableARCOptimizations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179718 91177308-0d34-0410-b5e6-96231b3b80d8
* [objc-arc] Added an option to arc-annotations for turning off CheckForCFGHazard.Michael Gottesman2013-04-17
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179717 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix some comment typos.Bob Wilson2013-04-09
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179132 91177308-0d34-0410-b5e6-96231b3b80d8
* Removed trailing whitespace.Michael Gottesman2013-04-05
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178932 91177308-0d34-0410-b5e6-96231b3b80d8
* An objc_retain can serve as a use for a different pointer.Michael Gottesman2013-04-05
| | | | | | | This is the counterpart to commit r160637, except it performs the action in the bottomup portion of the data flow analysis. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178922 91177308-0d34-0410-b5e6-96231b3b80d8
* Properly model precise lifetime when given an incomplete dataflow sequence.Michael Gottesman2013-04-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The normal dataflow sequence in the ARC optimizer consists of the following states: Retain -> CanRelease -> Use -> Release The optimizer before this patch stored the uses that determine the lifetime of the retainable object pointer when it bottom up hits a retain or when top down it hits a release. This is correct for an imprecise lifetime scenario since what we are trying to do is remove retains/releases while making sure that no ``CanRelease'' (which is usually a call) deallocates the given pointer before we get to the ``Use'' (since that would cause a segfault). If we are considering the precise lifetime scenario though, this is not correct. In such a situation, we *DO* care about the previous sequence, but additionally, we wish to track the uses resulting from the following incomplete sequences: Retain -> CanRelease -> Release (TopDown) Retain <- Use <- Release (BottomUp) *NOTE* This patch looks large but the most of it consists of updating test cases. Additionally this fix exposed an additional bug. I removed the test case that expressed said bug and will recommit it with the fix in a little bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178921 91177308-0d34-0410-b5e6-96231b3b80d8
* Added two debug logging messages to VisitInstructionsTopDown to match ↵Michael Gottesman2013-04-05
| | | | | | VisitInstructionsBottomUp. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178895 91177308-0d34-0410-b5e6-96231b3b80d8
* Cleaned up whitespace and made debug logging less verbose.Michael Gottesman2013-04-05
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178893 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactored out the helper method FindPredecessorAutoreleaseWithSafePath from ↵Michael Gottesman2013-04-03
| | | | | | | | ObjCARCOpt::OptimizeReturns. Now ObjCARCOpt::OptimizeReturns is easy to read and reason about. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178715 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactored out the helper function FindPredecessorRetainWithSafePath from ↵Michael Gottesman2013-04-03
| | | | | | ObjCARCOpt::OptimizeReturns. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178714 91177308-0d34-0410-b5e6-96231b3b80d8
* Small cleanups.Michael Gottesman2013-04-03
| | | | | | | | Cleaned up trailing whitespace and added extra slashes in front of a function level comment so that it follow the convention of having 3 slashes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178712 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactored out a part of ObjCARCOpt::OptimizeReturns into its own method ↵Michael Gottesman2013-04-03
| | | | | | HasSafePathToPredecessorCall. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178710 91177308-0d34-0410-b5e6-96231b3b80d8
* Removed an old comment.Michael Gottesman2013-04-03
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178709 91177308-0d34-0410-b5e6-96231b3b80d8
* Clean up arc annotations by moving the top/bottom BB annotations into ↵Michael Gottesman2013-04-03
| | | | | | | | conditional macros that no-op in Release mode instead of #ifdef sections of the code. This is to follow the example of the DEBUG macro. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178705 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove an optimization where we were changing an objc_autorelease into an ↵Michael Gottesman2013-04-03
| | | | | | | | | | | | | | | | | | | | | objc_autoreleaseReturnValue. The semantics of ARC implies that a pointer passed into an objc_autorelease must live until some point (potentially down the stack) where an autorelease pool is popped. On the other hand, an objc_autoreleaseReturnValue just signifies that the object must live until the end of the given function at least. Thus objc_autorelease is stronger than objc_autoreleaseReturnValue in terms of the semantics of ARC* implying that performing the given strength reduction without any knowledge of how this relates to the autorelease pool pop that is further up the stack violates the semantics of ARC. *Even though objc_autoreleaseReturnValue if you know that no RV optimization will occur is more computationally expensive. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178612 91177308-0d34-0410-b5e6-96231b3b80d8
* Improved comment. No functionality change.Michael Gottesman2013-04-03
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178605 91177308-0d34-0410-b5e6-96231b3b80d8
* Add clang.arc.used to ModuleHasARC so ARC always runs if said call is ↵Michael Gottesman2013-03-29
| | | | | | | | | | present in a module. clang.arc.used is an interesting call for ARC since ObjCARCContract needs to run to remove said intrinsic to avoid a linker error (since the call does not exist). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178369 91177308-0d34-0410-b5e6-96231b3b80d8