From cf0aa991df9692a9f5959013b0c0210edf41c027 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Sat, 25 Feb 2017 00:53:38 +0000 Subject: [PATCH] Clean up ObjCARCOpts.cpp. NFC. I removed unused functions and variables and moved variables closer to their uses. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296218 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 88 ++------------------------ 1 file changed, 7 insertions(+), 81 deletions(-) diff --git a/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index 136d54a6cb7..23851be3d78 100644 --- a/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -85,41 +85,6 @@ static const Value *FindSingleUseIdentifiedObject(const Value *Arg) { return nullptr; } -/// This is a wrapper around getUnderlyingObjCPtr along the lines of -/// GetUnderlyingObjects except that it returns early when it sees the first -/// alloca. -static inline bool AreAnyUnderlyingObjectsAnAlloca(const Value *V, - const DataLayout &DL) { - SmallPtrSet Visited; - SmallVector Worklist; - Worklist.push_back(V); - do { - const Value *P = Worklist.pop_back_val(); - P = GetUnderlyingObjCPtr(P, DL); - - if (isa(P)) - return true; - - if (!Visited.insert(P).second) - continue; - - if (const SelectInst *SI = dyn_cast(P)) { - Worklist.push_back(SI->getTrueValue()); - Worklist.push_back(SI->getFalseValue()); - continue; - } - - if (const PHINode *PN = dyn_cast(P)) { - for (Value *IncValue : PN->incoming_values()) - Worklist.push_back(IncValue); - continue; - } - } while (!Worklist.empty()); - - return false; -} - - /// @} /// /// \defgroup ARCOpt ARC Optimization. @@ -481,9 +446,6 @@ namespace { /// MDKind identifiers. ARCMDKindCache MDKindCache; - // This is used to track if a pointer is stored into an alloca. - DenseSet MultiOwnersSet; - /// A flag indicating whether this optimization pass should run. bool Run; @@ -524,8 +486,7 @@ namespace { PairUpRetainsAndReleases(DenseMap &BBStates, BlotMapVector &Retains, DenseMap &Releases, Module *M, - SmallVectorImpl &NewRetains, - SmallVectorImpl &NewReleases, + Instruction * Retain, SmallVectorImpl &DeadInsts, RRInfo &RetainsToMove, RRInfo &ReleasesToMove, Value *Arg, bool KnownSafe, @@ -1155,29 +1116,6 @@ bool ObjCARCOpt::VisitInstructionBottomUp( case ARCInstKind::None: // These are irrelevant. return NestingDetected; - case ARCInstKind::User: - // If we have a store into an alloca of a pointer we are tracking, the - // pointer has multiple owners implying that we must be more conservative. - // - // This comes up in the context of a pointer being ``KnownSafe''. In the - // presence 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, 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 presence of allocas we only unconditionally remove pointers if - // both our retain and our release are KnownSafe. - if (StoreInst *SI = dyn_cast(Inst)) { - const DataLayout &DL = BB->getModule()->getDataLayout(); - if (AreAnyUnderlyingObjectsAnAlloca(SI->getPointerOperand(), DL)) { - auto I = MyStates.findPtrBottomUpState( - GetRCIdentityRoot(SI->getValueOperand())); - if (I != MyStates.bottom_up_ptr_end()) - MultiOwnersSet.insert(I->first); - } - } - break; default: break; } @@ -1540,8 +1478,7 @@ bool ObjCARCOpt::PairUpRetainsAndReleases( DenseMap &BBStates, BlotMapVector &Retains, DenseMap &Releases, Module *M, - SmallVectorImpl &NewRetains, - SmallVectorImpl &NewReleases, + Instruction *Retain, SmallVectorImpl &DeadInsts, RRInfo &RetainsToMove, RRInfo &ReleasesToMove, Value *Arg, bool KnownSafe, bool &AnyPairsCompletelyEliminated) { @@ -1549,7 +1486,6 @@ bool ObjCARCOpt::PairUpRetainsAndReleases( // is already incremented, we can similarly ignore possible decrements unless // we are dealing with a retainable object with multiple provenance sources. bool KnownSafeTD = true, KnownSafeBU = true; - bool MultipleOwners = false; bool CFGHazardAfflicted = false; // Connect the dots between the top-down-collected RetainsToMove and @@ -1561,14 +1497,13 @@ bool ObjCARCOpt::PairUpRetainsAndReleases( unsigned OldCount = 0; unsigned NewCount = 0; bool FirstRelease = true; - for (;;) { + for (SmallVector NewRetains{Retain};;) { + SmallVector NewReleases; for (Instruction *NewRetain : NewRetains) { auto It = Retains.find(NewRetain); assert(It != Retains.end()); const RRInfo &NewRetainRRI = It->second; KnownSafeTD &= NewRetainRRI.KnownSafe; - MultipleOwners = - MultipleOwners || MultiOwnersSet.count(GetArgRCIdentityRoot(NewRetain)); for (Instruction *NewRetainRelease : NewRetainRRI.Calls) { auto Jt = Releases.find(NewRetainRelease); if (Jt == Releases.end()) @@ -1691,7 +1626,6 @@ bool ObjCARCOpt::PairUpRetainsAndReleases( } } } - NewReleases.clear(); if (NewRetains.empty()) break; } @@ -1745,10 +1679,6 @@ bool ObjCARCOpt::PerformCodePlacement( DEBUG(dbgs() << "\n== ObjCARCOpt::PerformCodePlacement ==\n"); bool AnyPairsCompletelyEliminated = false; - RRInfo RetainsToMove; - RRInfo ReleasesToMove; - SmallVector NewRetains; - SmallVector NewReleases; SmallVector DeadInsts; // Visit each retain. @@ -1780,9 +1710,10 @@ bool ObjCARCOpt::PerformCodePlacement( // Connect the dots between the top-down-collected RetainsToMove and // bottom-up-collected ReleasesToMove to form sets of related calls. - NewRetains.push_back(Retain); + RRInfo RetainsToMove, ReleasesToMove; + bool PerformMoveCalls = PairUpRetainsAndReleases( - BBStates, Retains, Releases, M, NewRetains, NewReleases, DeadInsts, + BBStates, Retains, Releases, M, Retain, DeadInsts, RetainsToMove, ReleasesToMove, Arg, KnownSafe, AnyPairsCompletelyEliminated); @@ -1794,8 +1725,6 @@ bool ObjCARCOpt::PerformCodePlacement( } // Clean up state for next retain. - NewReleases.clear(); - NewRetains.clear(); RetainsToMove.clear(); ReleasesToMove.clear(); } @@ -1987,9 +1916,6 @@ bool ObjCARCOpt::OptimizeSequences(Function &F) { Releases, F.getParent()); - // Cleanup. - MultiOwnersSet.clear(); - return AnyPairsCompletelyEliminated && NestingDetected; }