From: Akira Hatanaka Date: Fri, 13 Nov 2020 17:56:12 +0000 (-0800) Subject: Move variable declarations to functions in which they are used. NFC X-Git-Tag: llvmorg-13-init~6109 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00d0974e6290d5ee4ae1b4c654176863936f1469;p=platform%2Fupstream%2Fllvm.git Move variable declarations to functions in which they are used. NFC --- diff --git a/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp b/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp index 287dac0..1d90c3f 100644 --- a/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp +++ b/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp @@ -213,10 +213,10 @@ llvm::objcarc::FindDependencies(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, SmallPtrSetImpl &DependingInsts, - SmallPtrSetImpl &Visited, ProvenanceAnalysis &PA) { BasicBlock::iterator StartPos = StartInst->getIterator(); + SmallPtrSet Visited; SmallVector, 4> Worklist; Worklist.push_back(std::make_pair(StartBB, StartPos)); do { diff --git a/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.h b/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.h index ed89c8c..25ac93f 100644 --- a/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.h +++ b/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.h @@ -54,7 +54,6 @@ void FindDependencies(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, SmallPtrSetImpl &DependingInstructions, - SmallPtrSetImpl &Visited, ProvenanceAnalysis &PA); bool diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp index 5becc50..a5367cd 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -82,14 +82,13 @@ class ObjCARCContract { /// Returns true if we eliminated Inst. bool tryToPeepholeInstruction( Function &F, Instruction *Inst, inst_iterator &Iter, - SmallPtrSetImpl &Visited, bool &TailOkForStoreStrong, + bool &TailOkForStoreStrong, const DenseMap &BlockColors); bool optimizeRetainCall(Function &F, Instruction *Retain); - bool - contractAutorelease(Function &F, Instruction *Autorelease, ARCInstKind Class, - SmallPtrSetImpl &Visited); + bool contractAutorelease(Function &F, Instruction *Autorelease, + ARCInstKind Class); void tryToContractReleaseIntoStoreStrong( Instruction *Release, inst_iterator &Iter, @@ -156,9 +155,8 @@ bool ObjCARCContract::optimizeRetainCall(Function &F, Instruction *Retain) { } /// Merge an autorelease with a retain into a fused call. -bool ObjCARCContract::contractAutorelease( - Function &F, Instruction *Autorelease, ARCInstKind Class, - SmallPtrSetImpl &Visited) { +bool ObjCARCContract::contractAutorelease(Function &F, Instruction *Autorelease, + ARCInstKind Class) { const Value *Arg = GetArgRCIdentityRoot(Autorelease); // Check that there are no instructions between the retain and the autorelease @@ -167,15 +165,12 @@ bool ObjCARCContract::contractAutorelease( SmallPtrSet DependingInstructions; if (Class == ARCInstKind::AutoreleaseRV) - FindDependencies(RetainAutoreleaseRVDep, Arg, - Autorelease->getParent(), Autorelease, - DependingInstructions, Visited, PA); + FindDependencies(RetainAutoreleaseRVDep, Arg, Autorelease->getParent(), + Autorelease, DependingInstructions, PA); else - FindDependencies(RetainAutoreleaseDep, Arg, - Autorelease->getParent(), Autorelease, - DependingInstructions, Visited, PA); + FindDependencies(RetainAutoreleaseDep, Arg, Autorelease->getParent(), + Autorelease, DependingInstructions, PA); - Visited.clear(); if (DependingInstructions.size() != 1) return false; @@ -447,7 +442,7 @@ void ObjCARCContract::tryToContractReleaseIntoStoreStrong( bool ObjCARCContract::tryToPeepholeInstruction( Function &F, Instruction *Inst, inst_iterator &Iter, - SmallPtrSetImpl &Visited, bool &TailOkForStoreStrongs, + bool &TailOkForStoreStrongs, const DenseMap &BlockColors) { // Only these library routines return their argument. In particular, // objc_retainBlock does not necessarily return its argument. @@ -458,7 +453,7 @@ bool ObjCARCContract::tryToPeepholeInstruction( return false; case ARCInstKind::Autorelease: case ARCInstKind::AutoreleaseRV: - return contractAutorelease(F, Inst, Class, Visited); + return contractAutorelease(F, Inst, Class); case ARCInstKind::Retain: // Attempt to convert retains to retainrvs if they are next to function // calls. @@ -592,8 +587,6 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) { // For ObjC library calls which return their argument, replace uses of the // argument with uses of the call return value, if it dominates the use. This // reduces register pressure. - SmallPtrSet Visited; - for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E;) { Instruction *Inst = &*I++; @@ -601,7 +594,7 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) { // First try to peephole Inst. If there is nothing further we can do in // terms of undoing objc-arc-expand, process the next inst. - if (tryToPeepholeInstruction(F, Inst, I, Visited, TailOkForStoreStrongs, + if (tryToPeepholeInstruction(F, Inst, I, TailOkForStoreStrongs, BlockColors)) continue; diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index 1cd7987..ae197e6 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -1126,7 +1126,6 @@ void ObjCARCOpt::OptimizeIndividualCallImpl( continue; SmallPtrSet DependingInstructions; - SmallPtrSet Visited; // Check that there is nothing that cares about the reference // count between the call and the phi. @@ -1139,12 +1138,12 @@ void ObjCARCOpt::OptimizeIndividualCallImpl( // These can't be moved across things that care about the retain // count. FindDependencies(NeedsPositiveRetainCount, Arg, Inst->getParent(), Inst, - DependingInstructions, Visited, PA); + DependingInstructions, PA); break; case ARCInstKind::Autorelease: // These can't be moved across autorelease pool scope boundaries. FindDependencies(AutoreleasePoolBoundary, Arg, Inst->getParent(), Inst, - DependingInstructions, Visited, PA); + DependingInstructions, PA); break; case ARCInstKind::ClaimRV: case ARCInstKind::RetainRV: @@ -2237,10 +2236,9 @@ bool ObjCARCOpt::OptimizeSequences(Function &F) { static bool HasSafePathToPredecessorCall(const Value *Arg, Instruction *Retain, SmallPtrSetImpl &DepInsts, - SmallPtrSetImpl &Visited, ProvenanceAnalysis &PA) { FindDependencies(CanChangeRetainCount, Arg, Retain->getParent(), Retain, - DepInsts, Visited, PA); + DepInsts, PA); if (DepInsts.size() != 1) return false; @@ -2261,11 +2259,9 @@ HasSafePathToPredecessorCall(const Value *Arg, Instruction *Retain, static CallInst * FindPredecessorRetainWithSafePath(const Value *Arg, BasicBlock *BB, Instruction *Autorelease, - SmallPtrSetImpl &Visited, ProvenanceAnalysis &PA) { SmallPtrSet DepInsts; - FindDependencies(CanChangeRetainCount, Arg, - BB, Autorelease, DepInsts, Visited, PA); + FindDependencies(CanChangeRetainCount, Arg, BB, Autorelease, DepInsts, PA); if (DepInsts.size() != 1) return nullptr; @@ -2286,11 +2282,9 @@ FindPredecessorRetainWithSafePath(const Value *Arg, BasicBlock *BB, static CallInst * FindPredecessorAutoreleaseWithSafePath(const Value *Arg, BasicBlock *BB, ReturnInst *Ret, - SmallPtrSetImpl &V, ProvenanceAnalysis &PA) { SmallPtrSet DepInsts; - FindDependencies(NeedsPositiveRetainCount, Arg, - BB, Ret, DepInsts, V, PA); + FindDependencies(NeedsPositiveRetainCount, Arg, BB, Ret, DepInsts, PA); if (DepInsts.size() != 1) return nullptr; @@ -2321,7 +2315,6 @@ void ObjCARCOpt::OptimizeReturns(Function &F) { LLVM_DEBUG(dbgs() << "\n== ObjCARCOpt::OptimizeReturns ==\n"); SmallPtrSet DependingInstructions; - SmallPtrSet Visited; for (BasicBlock &BB: F) { ReturnInst *Ret = dyn_cast(&BB.back()); if (!Ret) @@ -2335,24 +2328,21 @@ void ObjCARCOpt::OptimizeReturns(Function &F) { // dependent on Arg such that there are no instructions dependent on Arg // that need a positive ref count in between the autorelease and Ret. CallInst *Autorelease = - FindPredecessorAutoreleaseWithSafePath(Arg, &BB, Ret, Visited, PA); - Visited.clear(); + FindPredecessorAutoreleaseWithSafePath(Arg, &BB, Ret, PA); if (!Autorelease) continue; CallInst *Retain = FindPredecessorRetainWithSafePath( - Arg, Autorelease->getParent(), Autorelease, Visited, PA); - Visited.clear(); + Arg, Autorelease->getParent(), Autorelease, PA); if (!Retain) continue; // Check that there is nothing that can affect the reference count // between the retain and the call. Note that Retain need not be in BB. - bool HasSafePathToCall = HasSafePathToPredecessorCall(Arg, Retain, - DependingInstructions, - Visited, PA); + bool HasSafePathToCall = + HasSafePathToPredecessorCall(Arg, Retain, DependingInstructions, PA); // Don't remove retainRV/autoreleaseRV pairs if the call isn't a tail call. if (HasSafePathToCall && @@ -2360,12 +2350,10 @@ void ObjCARCOpt::OptimizeReturns(Function &F) { GetBasicARCInstKind(Autorelease) == ARCInstKind::AutoreleaseRV && !cast(*DependingInstructions.begin())->isTailCall()) { DependingInstructions.clear(); - Visited.clear(); continue; } DependingInstructions.clear(); - Visited.clear(); if (!HasSafePathToCall) continue;