Skip to content

Commit

Permalink
Move variable declarations to functions in which they are used. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
ahatanaka committed Nov 11, 2020
1 parent fc8c1ea commit 5e85d00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
18 changes: 6 additions & 12 deletions llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
Expand Up @@ -82,15 +82,13 @@ class ObjCARCContract {
/// Returns true if we eliminated Inst.
bool tryToPeepholeInstruction(
Function &F, Instruction *Inst, inst_iterator &Iter,
SmallPtrSetImpl<Instruction *> &DepInsts,
SmallPtrSetImpl<const BasicBlock *> &Visited, bool &TailOkForStoreStrong,
const DenseMap<BasicBlock *, ColorVector> &BlockColors);

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

bool
contractAutorelease(Function &F, Instruction *Autorelease, ARCInstKind Class,
SmallPtrSetImpl<Instruction *> &DependingInstructions,
SmallPtrSetImpl<const BasicBlock *> &Visited);

void tryToContractReleaseIntoStoreStrong(
Expand Down Expand Up @@ -160,13 +158,14 @@ 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<Instruction *> &DependingInstructions,
SmallPtrSetImpl<const BasicBlock *> &Visited) {
const Value *Arg = GetArgRCIdentityRoot(Autorelease);

// Check that there are no instructions between the retain and the autorelease
// (such as an autorelease_pop) which may change the count.
CallInst *Retain = nullptr;
SmallPtrSet<Instruction *, 4> DependingInstructions;

if (Class == ARCInstKind::AutoreleaseRV)
FindDependencies(RetainAutoreleaseRVDep, Arg,
Autorelease->getParent(), Autorelease,
Expand All @@ -177,13 +176,10 @@ bool ObjCARCContract::contractAutorelease(
DependingInstructions, Visited, PA);

Visited.clear();
if (DependingInstructions.size() != 1) {
DependingInstructions.clear();
if (DependingInstructions.size() != 1)
return false;
}

Retain = dyn_cast_or_null<CallInst>(*DependingInstructions.begin());
DependingInstructions.clear();

if (!Retain || GetBasicARCInstKind(Retain) != ARCInstKind::Retain ||
GetArgRCIdentityRoot(Retain) != Arg)
Expand Down Expand Up @@ -451,7 +447,6 @@ void ObjCARCContract::tryToContractReleaseIntoStoreStrong(

bool ObjCARCContract::tryToPeepholeInstruction(
Function &F, Instruction *Inst, inst_iterator &Iter,
SmallPtrSetImpl<Instruction *> &DependingInsts,
SmallPtrSetImpl<const BasicBlock *> &Visited, bool &TailOkForStoreStrongs,
const DenseMap<BasicBlock *, ColorVector> &BlockColors) {
// Only these library routines return their argument. In particular,
Expand All @@ -463,7 +458,7 @@ bool ObjCARCContract::tryToPeepholeInstruction(
return false;
case ARCInstKind::Autorelease:
case ARCInstKind::AutoreleaseRV:
return contractAutorelease(F, Inst, Class, DependingInsts, Visited);
return contractAutorelease(F, Inst, Class, Visited);
case ARCInstKind::Retain:
// Attempt to convert retains to retainrvs if they are next to function
// calls.
Expand Down Expand Up @@ -597,7 +592,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<Instruction *, 4> DependingInstructions;
SmallPtrSet<const BasicBlock *, 4> Visited;

for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E;) {
Expand All @@ -607,8 +601,8 @@ 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, DependingInstructions, Visited,
TailOkForStoreStrongs, BlockColors))
if (tryToPeepholeInstruction(F, Inst, I, Visited, TailOkForStoreStrongs,
BlockColors))
continue;

// Otherwise, try to undo objc-arc-expand.
Expand Down
13 changes: 5 additions & 8 deletions llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
Expand Up @@ -2261,9 +2261,9 @@ HasSafePathToPredecessorCall(const Value *Arg, Instruction *Retain,
static CallInst *
FindPredecessorRetainWithSafePath(const Value *Arg, BasicBlock *BB,
Instruction *Autorelease,
SmallPtrSetImpl<Instruction *> &DepInsts,
SmallPtrSetImpl<const BasicBlock *> &Visited,
ProvenanceAnalysis &PA) {
SmallPtrSet<Instruction *, 4> DepInsts;
FindDependencies(CanChangeRetainCount, Arg,
BB, Autorelease, DepInsts, Visited, PA);
if (DepInsts.size() != 1)
Expand All @@ -2286,9 +2286,9 @@ FindPredecessorRetainWithSafePath(const Value *Arg, BasicBlock *BB,
static CallInst *
FindPredecessorAutoreleaseWithSafePath(const Value *Arg, BasicBlock *BB,
ReturnInst *Ret,
SmallPtrSetImpl<Instruction *> &DepInsts,
SmallPtrSetImpl<const BasicBlock *> &V,
ProvenanceAnalysis &PA) {
SmallPtrSet<Instruction *, 4> DepInsts;
FindDependencies(NeedsPositiveRetainCount, Arg,
BB, Ret, DepInsts, V, PA);
if (DepInsts.size() != 1)
Expand Down Expand Up @@ -2334,18 +2334,15 @@ void ObjCARCOpt::OptimizeReturns(Function &F) {
// Look for an ``autorelease'' instruction that is a predecessor of Ret and
// 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, DependingInstructions, Visited, PA);
DependingInstructions.clear();
CallInst *Autorelease =
FindPredecessorAutoreleaseWithSafePath(Arg, &BB, Ret, Visited, PA);
Visited.clear();

if (!Autorelease)
continue;

CallInst *Retain = FindPredecessorRetainWithSafePath(
Arg, Autorelease->getParent(), Autorelease, DependingInstructions,
Visited, PA);
DependingInstructions.clear();
Arg, Autorelease->getParent(), Autorelease, Visited, PA);
Visited.clear();

if (!Retain)
Expand Down

0 comments on commit 5e85d00

Please sign in to comment.