Skip to content

Commit a937a58

Browse files
committed
llvm/ObjCARC: Use continue to reduce some nesting, NFC
1 parent b11386f commit a937a58

File tree

1 file changed

+66
-66
lines changed

1 file changed

+66
-66
lines changed

llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp

+66-66
Original file line numberDiff line numberDiff line change
@@ -990,75 +990,75 @@ void ObjCARCOpt::OptimizeIndividualCalls(Function &F) {
990990
}
991991
}
992992
// If we have null operands and no critical edges, optimize.
993-
if (!HasCriticalEdges && HasNull) {
994-
SmallPtrSet<Instruction *, 4> DependingInstructions;
995-
SmallPtrSet<const BasicBlock *, 4> Visited;
996-
997-
// Check that there is nothing that cares about the reference
998-
// count between the call and the phi.
999-
switch (Class) {
1000-
case ARCInstKind::Retain:
1001-
case ARCInstKind::RetainBlock:
1002-
// These can always be moved up.
1003-
break;
1004-
case ARCInstKind::Release:
1005-
// These can't be moved across things that care about the retain
1006-
// count.
1007-
FindDependencies(NeedsPositiveRetainCount, Arg,
1008-
Inst->getParent(), Inst,
1009-
DependingInstructions, Visited, PA);
1010-
break;
1011-
case ARCInstKind::Autorelease:
1012-
// These can't be moved across autorelease pool scope boundaries.
1013-
FindDependencies(AutoreleasePoolBoundary, Arg,
1014-
Inst->getParent(), Inst,
1015-
DependingInstructions, Visited, PA);
1016-
break;
1017-
case ARCInstKind::ClaimRV:
1018-
case ARCInstKind::RetainRV:
1019-
case ARCInstKind::AutoreleaseRV:
1020-
// Don't move these; the RV optimization depends on the autoreleaseRV
1021-
// being tail called, and the retainRV being immediately after a call
1022-
// (which might still happen if we get lucky with codegen layout, but
1023-
// it's not worth taking the chance).
1024-
continue;
1025-
default:
1026-
llvm_unreachable("Invalid dependence flavor");
1027-
}
993+
if (HasCriticalEdges)
994+
continue;
995+
if (!HasNull)
996+
continue;
1028997

1029-
if (DependingInstructions.size() == 1 &&
1030-
*DependingInstructions.begin() == PN) {
1031-
Changed = true;
1032-
++NumPartialNoops;
1033-
// Clone the call into each predecessor that has a non-null value.
1034-
CallInst *CInst = cast<CallInst>(Inst);
1035-
Type *ParamTy = CInst->getArgOperand(0)->getType();
1036-
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
1037-
Value *Incoming =
1038-
GetRCIdentityRoot(PN->getIncomingValue(i));
1039-
if (!IsNullOrUndef(Incoming)) {
1040-
Value *Op = PN->getIncomingValue(i);
1041-
Instruction *InsertPos = &PN->getIncomingBlock(i)->back();
1042-
CallInst *Clone = cast<CallInst>(CloneCallInstForBB(
1043-
*CInst, *InsertPos->getParent(), BlockColors));
1044-
if (Op->getType() != ParamTy)
1045-
Op = new BitCastInst(Op, ParamTy, "", InsertPos);
1046-
Clone->setArgOperand(0, Op);
1047-
Clone->insertBefore(InsertPos);
1048-
1049-
LLVM_DEBUG(dbgs() << "Cloning " << *CInst
1050-
<< "\n"
1051-
"And inserting clone at "
1052-
<< *InsertPos << "\n");
1053-
Worklist.push_back(std::make_pair(Clone, Incoming));
1054-
}
1055-
}
1056-
// Erase the original call.
1057-
LLVM_DEBUG(dbgs() << "Erasing: " << *CInst << "\n");
1058-
EraseInstruction(CInst);
998+
SmallPtrSet<Instruction *, 4> DependingInstructions;
999+
SmallPtrSet<const BasicBlock *, 4> Visited;
1000+
1001+
// Check that there is nothing that cares about the reference
1002+
// count between the call and the phi.
1003+
switch (Class) {
1004+
case ARCInstKind::Retain:
1005+
case ARCInstKind::RetainBlock:
1006+
// These can always be moved up.
1007+
break;
1008+
case ARCInstKind::Release:
1009+
// These can't be moved across things that care about the retain
1010+
// count.
1011+
FindDependencies(NeedsPositiveRetainCount, Arg, Inst->getParent(), Inst,
1012+
DependingInstructions, Visited, PA);
1013+
break;
1014+
case ARCInstKind::Autorelease:
1015+
// These can't be moved across autorelease pool scope boundaries.
1016+
FindDependencies(AutoreleasePoolBoundary, Arg, Inst->getParent(), Inst,
1017+
DependingInstructions, Visited, PA);
1018+
break;
1019+
case ARCInstKind::ClaimRV:
1020+
case ARCInstKind::RetainRV:
1021+
case ARCInstKind::AutoreleaseRV:
1022+
// Don't move these; the RV optimization depends on the autoreleaseRV
1023+
// being tail called, and the retainRV being immediately after a call
1024+
// (which might still happen if we get lucky with codegen layout, but
1025+
// it's not worth taking the chance).
1026+
continue;
1027+
default:
1028+
llvm_unreachable("Invalid dependence flavor");
1029+
}
1030+
1031+
if (DependingInstructions.size() != 1)
1032+
continue;
1033+
if (*DependingInstructions.begin() != PN)
1034+
continue;
1035+
1036+
Changed = true;
1037+
++NumPartialNoops;
1038+
// Clone the call into each predecessor that has a non-null value.
1039+
CallInst *CInst = cast<CallInst>(Inst);
1040+
Type *ParamTy = CInst->getArgOperand(0)->getType();
1041+
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
1042+
Value *Incoming = GetRCIdentityRoot(PN->getIncomingValue(i));
1043+
if (IsNullOrUndef(Incoming))
10591044
continue;
1060-
}
1045+
Value *Op = PN->getIncomingValue(i);
1046+
Instruction *InsertPos = &PN->getIncomingBlock(i)->back();
1047+
CallInst *Clone = cast<CallInst>(
1048+
CloneCallInstForBB(*CInst, *InsertPos->getParent(), BlockColors));
1049+
if (Op->getType() != ParamTy)
1050+
Op = new BitCastInst(Op, ParamTy, "", InsertPos);
1051+
Clone->setArgOperand(0, Op);
1052+
Clone->insertBefore(InsertPos);
1053+
1054+
LLVM_DEBUG(dbgs() << "Cloning " << *CInst << "\n"
1055+
"And inserting clone at "
1056+
<< *InsertPos << "\n");
1057+
Worklist.push_back(std::make_pair(Clone, Incoming));
10611058
}
1059+
// Erase the original call.
1060+
LLVM_DEBUG(dbgs() << "Erasing: " << *CInst << "\n");
1061+
EraseInstruction(CInst);
10621062
} while (!Worklist.empty());
10631063
}
10641064
}

0 commit comments

Comments
 (0)