Skip to content

Commit 00d0974

Browse files
committed
Move variable declarations to functions in which they are used. NFC
1 parent d6a88e7 commit 00d0974

File tree

4 files changed

+22
-42
lines changed

4 files changed

+22
-42
lines changed

llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ llvm::objcarc::FindDependencies(DependenceKind Flavor,
213213
const Value *Arg,
214214
BasicBlock *StartBB, Instruction *StartInst,
215215
SmallPtrSetImpl<Instruction *> &DependingInsts,
216-
SmallPtrSetImpl<const BasicBlock *> &Visited,
217216
ProvenanceAnalysis &PA) {
218217
BasicBlock::iterator StartPos = StartInst->getIterator();
219218

219+
SmallPtrSet<const BasicBlock *, 4> Visited;
220220
SmallVector<std::pair<BasicBlock *, BasicBlock::iterator>, 4> Worklist;
221221
Worklist.push_back(std::make_pair(StartBB, StartPos));
222222
do {

llvm/lib/Transforms/ObjCARC/DependencyAnalysis.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void FindDependencies(DependenceKind Flavor,
5454
const Value *Arg,
5555
BasicBlock *StartBB, Instruction *StartInst,
5656
SmallPtrSetImpl<Instruction *> &DependingInstructions,
57-
SmallPtrSetImpl<const BasicBlock *> &Visited,
5857
ProvenanceAnalysis &PA);
5958

6059
bool

llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,13 @@ class ObjCARCContract {
8282
/// Returns true if we eliminated Inst.
8383
bool tryToPeepholeInstruction(
8484
Function &F, Instruction *Inst, inst_iterator &Iter,
85-
SmallPtrSetImpl<const BasicBlock *> &Visited, bool &TailOkForStoreStrong,
85+
bool &TailOkForStoreStrong,
8686
const DenseMap<BasicBlock *, ColorVector> &BlockColors);
8787

8888
bool optimizeRetainCall(Function &F, Instruction *Retain);
8989

90-
bool
91-
contractAutorelease(Function &F, Instruction *Autorelease, ARCInstKind Class,
92-
SmallPtrSetImpl<const BasicBlock *> &Visited);
90+
bool contractAutorelease(Function &F, Instruction *Autorelease,
91+
ARCInstKind Class);
9392

9493
void tryToContractReleaseIntoStoreStrong(
9594
Instruction *Release, inst_iterator &Iter,
@@ -156,9 +155,8 @@ bool ObjCARCContract::optimizeRetainCall(Function &F, Instruction *Retain) {
156155
}
157156

158157
/// Merge an autorelease with a retain into a fused call.
159-
bool ObjCARCContract::contractAutorelease(
160-
Function &F, Instruction *Autorelease, ARCInstKind Class,
161-
SmallPtrSetImpl<const BasicBlock *> &Visited) {
158+
bool ObjCARCContract::contractAutorelease(Function &F, Instruction *Autorelease,
159+
ARCInstKind Class) {
162160
const Value *Arg = GetArgRCIdentityRoot(Autorelease);
163161

164162
// Check that there are no instructions between the retain and the autorelease
@@ -167,15 +165,12 @@ bool ObjCARCContract::contractAutorelease(
167165
SmallPtrSet<Instruction *, 4> DependingInstructions;
168166

169167
if (Class == ARCInstKind::AutoreleaseRV)
170-
FindDependencies(RetainAutoreleaseRVDep, Arg,
171-
Autorelease->getParent(), Autorelease,
172-
DependingInstructions, Visited, PA);
168+
FindDependencies(RetainAutoreleaseRVDep, Arg, Autorelease->getParent(),
169+
Autorelease, DependingInstructions, PA);
173170
else
174-
FindDependencies(RetainAutoreleaseDep, Arg,
175-
Autorelease->getParent(), Autorelease,
176-
DependingInstructions, Visited, PA);
171+
FindDependencies(RetainAutoreleaseDep, Arg, Autorelease->getParent(),
172+
Autorelease, DependingInstructions, PA);
177173

178-
Visited.clear();
179174
if (DependingInstructions.size() != 1)
180175
return false;
181176

@@ -447,7 +442,7 @@ void ObjCARCContract::tryToContractReleaseIntoStoreStrong(
447442

448443
bool ObjCARCContract::tryToPeepholeInstruction(
449444
Function &F, Instruction *Inst, inst_iterator &Iter,
450-
SmallPtrSetImpl<const BasicBlock *> &Visited, bool &TailOkForStoreStrongs,
445+
bool &TailOkForStoreStrongs,
451446
const DenseMap<BasicBlock *, ColorVector> &BlockColors) {
452447
// Only these library routines return their argument. In particular,
453448
// objc_retainBlock does not necessarily return its argument.
@@ -458,7 +453,7 @@ bool ObjCARCContract::tryToPeepholeInstruction(
458453
return false;
459454
case ARCInstKind::Autorelease:
460455
case ARCInstKind::AutoreleaseRV:
461-
return contractAutorelease(F, Inst, Class, Visited);
456+
return contractAutorelease(F, Inst, Class);
462457
case ARCInstKind::Retain:
463458
// Attempt to convert retains to retainrvs if they are next to function
464459
// calls.
@@ -592,16 +587,14 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) {
592587
// For ObjC library calls which return their argument, replace uses of the
593588
// argument with uses of the call return value, if it dominates the use. This
594589
// reduces register pressure.
595-
SmallPtrSet<const BasicBlock *, 4> Visited;
596-
597590
for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E;) {
598591
Instruction *Inst = &*I++;
599592

600593
LLVM_DEBUG(dbgs() << "Visiting: " << *Inst << "\n");
601594

602595
// First try to peephole Inst. If there is nothing further we can do in
603596
// terms of undoing objc-arc-expand, process the next inst.
604-
if (tryToPeepholeInstruction(F, Inst, I, Visited, TailOkForStoreStrongs,
597+
if (tryToPeepholeInstruction(F, Inst, I, TailOkForStoreStrongs,
605598
BlockColors))
606599
continue;
607600

llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,6 @@ void ObjCARCOpt::OptimizeIndividualCallImpl(
11261126
continue;
11271127

11281128
SmallPtrSet<Instruction *, 4> DependingInstructions;
1129-
SmallPtrSet<const BasicBlock *, 4> Visited;
11301129

11311130
// Check that there is nothing that cares about the reference
11321131
// count between the call and the phi.
@@ -1139,12 +1138,12 @@ void ObjCARCOpt::OptimizeIndividualCallImpl(
11391138
// These can't be moved across things that care about the retain
11401139
// count.
11411140
FindDependencies(NeedsPositiveRetainCount, Arg, Inst->getParent(), Inst,
1142-
DependingInstructions, Visited, PA);
1141+
DependingInstructions, PA);
11431142
break;
11441143
case ARCInstKind::Autorelease:
11451144
// These can't be moved across autorelease pool scope boundaries.
11461145
FindDependencies(AutoreleasePoolBoundary, Arg, Inst->getParent(), Inst,
1147-
DependingInstructions, Visited, PA);
1146+
DependingInstructions, PA);
11481147
break;
11491148
case ARCInstKind::ClaimRV:
11501149
case ARCInstKind::RetainRV:
@@ -2237,10 +2236,9 @@ bool ObjCARCOpt::OptimizeSequences(Function &F) {
22372236
static bool
22382237
HasSafePathToPredecessorCall(const Value *Arg, Instruction *Retain,
22392238
SmallPtrSetImpl<Instruction *> &DepInsts,
2240-
SmallPtrSetImpl<const BasicBlock *> &Visited,
22412239
ProvenanceAnalysis &PA) {
22422240
FindDependencies(CanChangeRetainCount, Arg, Retain->getParent(), Retain,
2243-
DepInsts, Visited, PA);
2241+
DepInsts, PA);
22442242
if (DepInsts.size() != 1)
22452243
return false;
22462244

@@ -2261,11 +2259,9 @@ HasSafePathToPredecessorCall(const Value *Arg, Instruction *Retain,
22612259
static CallInst *
22622260
FindPredecessorRetainWithSafePath(const Value *Arg, BasicBlock *BB,
22632261
Instruction *Autorelease,
2264-
SmallPtrSetImpl<const BasicBlock *> &Visited,
22652262
ProvenanceAnalysis &PA) {
22662263
SmallPtrSet<Instruction *, 4> DepInsts;
2267-
FindDependencies(CanChangeRetainCount, Arg,
2268-
BB, Autorelease, DepInsts, Visited, PA);
2264+
FindDependencies(CanChangeRetainCount, Arg, BB, Autorelease, DepInsts, PA);
22692265
if (DepInsts.size() != 1)
22702266
return nullptr;
22712267

@@ -2286,11 +2282,9 @@ FindPredecessorRetainWithSafePath(const Value *Arg, BasicBlock *BB,
22862282
static CallInst *
22872283
FindPredecessorAutoreleaseWithSafePath(const Value *Arg, BasicBlock *BB,
22882284
ReturnInst *Ret,
2289-
SmallPtrSetImpl<const BasicBlock *> &V,
22902285
ProvenanceAnalysis &PA) {
22912286
SmallPtrSet<Instruction *, 4> DepInsts;
2292-
FindDependencies(NeedsPositiveRetainCount, Arg,
2293-
BB, Ret, DepInsts, V, PA);
2287+
FindDependencies(NeedsPositiveRetainCount, Arg, BB, Ret, DepInsts, PA);
22942288
if (DepInsts.size() != 1)
22952289
return nullptr;
22962290

@@ -2321,7 +2315,6 @@ void ObjCARCOpt::OptimizeReturns(Function &F) {
23212315
LLVM_DEBUG(dbgs() << "\n== ObjCARCOpt::OptimizeReturns ==\n");
23222316

23232317
SmallPtrSet<Instruction *, 4> DependingInstructions;
2324-
SmallPtrSet<const BasicBlock *, 4> Visited;
23252318
for (BasicBlock &BB: F) {
23262319
ReturnInst *Ret = dyn_cast<ReturnInst>(&BB.back());
23272320
if (!Ret)
@@ -2335,37 +2328,32 @@ void ObjCARCOpt::OptimizeReturns(Function &F) {
23352328
// dependent on Arg such that there are no instructions dependent on Arg
23362329
// that need a positive ref count in between the autorelease and Ret.
23372330
CallInst *Autorelease =
2338-
FindPredecessorAutoreleaseWithSafePath(Arg, &BB, Ret, Visited, PA);
2339-
Visited.clear();
2331+
FindPredecessorAutoreleaseWithSafePath(Arg, &BB, Ret, PA);
23402332

23412333
if (!Autorelease)
23422334
continue;
23432335

23442336
CallInst *Retain = FindPredecessorRetainWithSafePath(
2345-
Arg, Autorelease->getParent(), Autorelease, Visited, PA);
2346-
Visited.clear();
2337+
Arg, Autorelease->getParent(), Autorelease, PA);
23472338

23482339
if (!Retain)
23492340
continue;
23502341

23512342
// Check that there is nothing that can affect the reference count
23522343
// between the retain and the call. Note that Retain need not be in BB.
2353-
bool HasSafePathToCall = HasSafePathToPredecessorCall(Arg, Retain,
2354-
DependingInstructions,
2355-
Visited, PA);
2344+
bool HasSafePathToCall =
2345+
HasSafePathToPredecessorCall(Arg, Retain, DependingInstructions, PA);
23562346

23572347
// Don't remove retainRV/autoreleaseRV pairs if the call isn't a tail call.
23582348
if (HasSafePathToCall &&
23592349
GetBasicARCInstKind(Retain) == ARCInstKind::RetainRV &&
23602350
GetBasicARCInstKind(Autorelease) == ARCInstKind::AutoreleaseRV &&
23612351
!cast<CallInst>(*DependingInstructions.begin())->isTailCall()) {
23622352
DependingInstructions.clear();
2363-
Visited.clear();
23642353
continue;
23652354
}
23662355

23672356
DependingInstructions.clear();
2368-
Visited.clear();
23692357

23702358
if (!HasSafePathToCall)
23712359
continue;

0 commit comments

Comments
 (0)