74#define DEBUG_TYPE "objc-arc-opts"
78 cl::desc(
"Maximum number of ptr states the optimizer keeps track of"),
89 if (isa<ConstantData>(Arg))
93 if (
const BitCastInst *BC = dyn_cast<BitCastInst>(Arg))
96 if (
GEP->hasAllZeroIndices())
100 cast<CallInst>(Arg)->getArgOperand(0));
162STATISTIC(NumNoops,
"Number of no-op objc calls eliminated");
163STATISTIC(NumPartialNoops,
"Number of partially no-op objc calls eliminated");
164STATISTIC(NumAutoreleases,
"Number of autoreleases converted to releases");
166 "retain+autoreleases eliminated");
167STATISTIC(NumRRs,
"Number of retain+release paths eliminated");
168STATISTIC(NumPeeps,
"Number of calls peephole-optimized");
171 "Number of retains before optimization");
173 "Number of releases before optimization");
175 "Number of retains after optimization");
177 "Number of releases after optimization");
186 unsigned TopDownPathCount = 0;
189 unsigned BottomUpPathCount = 0;
212 using top_down_ptr_iterator =
decltype(PerPtrTopDown)::iterator;
213 using const_top_down_ptr_iterator =
decltype(PerPtrTopDown)
::const_iterator;
215 top_down_ptr_iterator top_down_ptr_begin() {
return PerPtrTopDown.
begin(); }
216 top_down_ptr_iterator top_down_ptr_end() {
return PerPtrTopDown.
end(); }
217 const_top_down_ptr_iterator top_down_ptr_begin()
const {
218 return PerPtrTopDown.
begin();
220 const_top_down_ptr_iterator top_down_ptr_end()
const {
221 return PerPtrTopDown.
end();
223 bool hasTopDownPtrs()
const {
224 return !PerPtrTopDown.
empty();
227 unsigned top_down_ptr_list_size()
const {
228 return std::distance(top_down_ptr_begin(), top_down_ptr_end());
231 using bottom_up_ptr_iterator =
decltype(PerPtrBottomUp)::iterator;
232 using const_bottom_up_ptr_iterator =
235 bottom_up_ptr_iterator bottom_up_ptr_begin() {
236 return PerPtrBottomUp.
begin();
238 bottom_up_ptr_iterator bottom_up_ptr_end() {
return PerPtrBottomUp.
end(); }
239 const_bottom_up_ptr_iterator bottom_up_ptr_begin()
const {
240 return PerPtrBottomUp.
begin();
242 const_bottom_up_ptr_iterator bottom_up_ptr_end()
const {
243 return PerPtrBottomUp.
end();
245 bool hasBottomUpPtrs()
const {
246 return !PerPtrBottomUp.
empty();
249 unsigned bottom_up_ptr_list_size()
const {
250 return std::distance(bottom_up_ptr_begin(), bottom_up_ptr_end());
255 void SetAsEntry() { TopDownPathCount = 1; }
259 void SetAsExit() { BottomUpPathCount = 1; }
265 return PerPtrTopDown[Arg];
272 return PerPtrBottomUp[Arg];
277 bottom_up_ptr_iterator findPtrBottomUpState(
const Value *Arg) {
278 return PerPtrBottomUp.
find(Arg);
281 void clearBottomUpPointers() {
282 PerPtrBottomUp.
clear();
285 void clearTopDownPointers() {
286 PerPtrTopDown.
clear();
289 void InitFromPred(
const BBState &
Other);
290 void InitFromSucc(
const BBState &
Other);
291 void MergePred(
const BBState &
Other);
292 void MergeSucc(
const BBState &
Other);
300 bool GetAllPathCountWithOverflow(
unsigned &PathCount)
const {
304 unsigned long long Product =
305 (
unsigned long long)TopDownPathCount*BottomUpPathCount;
308 return (Product >> 32) ||
316 edge_iterator
pred_end()
const {
return Preds.
end(); }
318 edge_iterator
succ_end()
const {
return Succs.
end(); }
323 bool isExit()
const {
return Succs.
empty(); }
337void BBState::InitFromPred(
const BBState &
Other) {
338 PerPtrTopDown =
Other.PerPtrTopDown;
339 TopDownPathCount =
Other.TopDownPathCount;
342void BBState::InitFromSucc(
const BBState &
Other) {
343 PerPtrBottomUp =
Other.PerPtrBottomUp;
344 BottomUpPathCount =
Other.BottomUpPathCount;
349void BBState::MergePred(
const BBState &
Other) {
350 if (TopDownPathCount == OverflowOccurredValue)
355 TopDownPathCount +=
Other.TopDownPathCount;
360 if (TopDownPathCount == OverflowOccurredValue) {
361 clearTopDownPointers();
367 if (TopDownPathCount <
Other.TopDownPathCount) {
368 TopDownPathCount = OverflowOccurredValue;
369 clearTopDownPointers();
376 for (
auto MI =
Other.top_down_ptr_begin(), ME =
Other.top_down_ptr_end();
378 auto Pair = PerPtrTopDown.
insert(*
MI);
385 for (
auto MI = top_down_ptr_begin(), ME = top_down_ptr_end();
MI != ME; ++
MI)
386 if (
Other.PerPtrTopDown.find(
MI->first) ==
Other.PerPtrTopDown.end())
392void BBState::MergeSucc(
const BBState &
Other) {
393 if (BottomUpPathCount == OverflowOccurredValue)
398 BottomUpPathCount +=
Other.BottomUpPathCount;
403 if (BottomUpPathCount == OverflowOccurredValue) {
404 clearBottomUpPointers();
410 if (BottomUpPathCount <
Other.BottomUpPathCount) {
411 BottomUpPathCount = OverflowOccurredValue;
412 clearBottomUpPointers();
419 for (
auto MI =
Other.bottom_up_ptr_begin(), ME =
Other.bottom_up_ptr_end();
421 auto Pair = PerPtrBottomUp.
insert(*
MI);
428 for (
auto MI = bottom_up_ptr_begin(), ME = bottom_up_ptr_end();
MI != ME;
430 if (
Other.PerPtrBottomUp.find(
MI->first) ==
Other.PerPtrBottomUp.end())
436 OS <<
" TopDown State:\n";
437 if (!BBInfo.hasTopDownPtrs()) {
440 for (
auto I = BBInfo.top_down_ptr_begin(), E = BBInfo.top_down_ptr_end();
443 OS <<
" Ptr: " << *
I->first
444 <<
"\n KnownSafe: " << (
P.IsKnownSafe()?
"true":
"false")
445 <<
"\n ImpreciseRelease: "
446 << (
P.IsTrackingImpreciseReleases()?
"true":
"false") <<
"\n"
447 <<
" HasCFGHazards: "
448 << (
P.IsCFGHazardAfflicted()?
"true":
"false") <<
"\n"
449 <<
" KnownPositive: "
450 << (
P.HasKnownPositiveRefCount()?
"true":
"false") <<
"\n"
452 <<
P.GetSeq() <<
"\n";
456 OS <<
" BottomUp State:\n";
457 if (!BBInfo.hasBottomUpPtrs()) {
460 for (
auto I = BBInfo.bottom_up_ptr_begin(), E = BBInfo.bottom_up_ptr_end();
463 OS <<
" Ptr: " << *
I->first
464 <<
"\n KnownSafe: " << (
P.IsKnownSafe()?
"true":
"false")
465 <<
"\n ImpreciseRelease: "
466 << (
P.IsTrackingImpreciseReleases()?
"true":
"false") <<
"\n"
467 <<
" HasCFGHazards: "
468 << (
P.IsCFGHazardAfflicted()?
"true":
"false") <<
"\n"
469 <<
" KnownPositive: "
470 << (
P.HasKnownPositiveRefCount()?
"true":
"false") <<
"\n"
472 <<
P.GetSeq() <<
"\n";
483 bool Changed =
false;
484 bool CFGChanged =
false;
498 bool DisableRetainReleasePairing =
false;
502 unsigned UsedInThisFunction;
509 void OptimizeIndividualCalls(
Function &
F);
522 const Value *&AutoreleaseRVArg);
526 BBState &MyStates)
const;
533 bool VisitInstructionTopDown(
536 &ReleaseInsertPtToRCIdentityRoots);
541 &ReleaseInsertPtToRCIdentityRoots);
557 Value *Arg,
bool KnownSafe,
558 bool &AnyPairsCompletelyEliminated);
570 template <
typename PredicateT>
571 static void cloneOpBundlesIf(
CallBase *CI,
583 if (!BlockEHColors.
empty()) {
587 if (
auto *EHPad = dyn_cast<FuncletPadInst>(EHPadBB->getFirstNonPHI())) {
595 void GatherStatistics(
Function &
F,
bool AfterOptimization =
false);
601 bool hasCFGChanged()
const {
return CFGChanged; }
621 if (
II->getNormalDest() == RetainRVParent) {
632 "a bundled retainRV's argument should be a call");
638 LLVM_DEBUG(
dbgs() <<
"Transforming objc_retainAutoreleasedReturnValue => "
639 "objc_retain since the operand is not a return value.\n"
643 Function *NewDecl = EP.
get(ARCRuntimeEntryPointKind::Retain);
644 cast<CallInst>(
RetainRV)->setCalledFunction(NewDecl);
651bool ObjCARCOpt::OptimizeInlinedAutoreleaseRVCall(
663 if (Arg != AutoreleaseRVArg) {
665 const PHINode *PN = dyn_cast<PHINode>(Arg);
677 LLVM_DEBUG(
dbgs() <<
"Found inlined objc_autoreleaseReturnValue '"
685 if (Class == ARCInstKind::RetainRV) {
694 assert(Class == ARCInstKind::UnsafeClaimRV);
695 Value *
CallArg = cast<CallInst>(Inst)->getArgOperand(0);
700 "Expected UnsafeClaimRV to be safe to tail call");
706 OptimizeIndividualCallImpl(
F,
Release, ARCInstKind::Release, Arg);
712void ObjCARCOpt::OptimizeAutoreleaseRVCall(
Function &
F,
720 if (isa<ConstantData>(
Ptr))
727 if (
const PHINode *PN = dyn_cast<PHINode>(
Ptr))
732 for (
const User *U :
Ptr->users()) {
735 if (isa<BitCastInst>(U))
738 }
while (!
Users.empty());
744 dbgs() <<
"Transforming objc_autoreleaseReturnValue => "
745 "objc_autorelease since its operand is not used as a return "
751 Function *NewDecl = EP.
get(ARCRuntimeEntryPointKind::Autorelease);
754 Class = ARCInstKind::Autorelease;
761void ObjCARCOpt::OptimizeIndividualCalls(
Function &
F) {
762 LLVM_DEBUG(
dbgs() <<
"\n== ObjCARCOpt::OptimizeIndividualCalls ==\n");
764 UsedInThisFunction = 0;
769 const Value *DelayedAutoreleaseRVArg =
nullptr;
773 DelayedAutoreleaseRVArg =
nullptr;
775 auto optimizeDelayedAutoreleaseRV = [&]() {
776 if (!DelayedAutoreleaseRV)
778 OptimizeIndividualCallImpl(
F, DelayedAutoreleaseRV,
779 ARCInstKind::AutoreleaseRV,
780 DelayedAutoreleaseRVArg);
781 setDelayedAutoreleaseRV(
nullptr);
783 auto shouldDelayAutoreleaseRV = [&](
Instruction *NonARCInst) {
785 if (!DelayedAutoreleaseRV)
790 if (NonARCInst->isTerminator())
800 auto *CB = dyn_cast<CallBase>(NonARCInst);
810 if (
auto *CI = dyn_cast<CallInst>(Inst))
819 const Value *Arg =
nullptr;
822 optimizeDelayedAutoreleaseRV();
824 case ARCInstKind::CallOrUser:
825 case ARCInstKind::User:
826 case ARCInstKind::None:
830 if (!shouldDelayAutoreleaseRV(Inst))
831 optimizeDelayedAutoreleaseRV();
833 case ARCInstKind::AutoreleaseRV:
834 optimizeDelayedAutoreleaseRV();
835 setDelayedAutoreleaseRV(Inst);
837 case ARCInstKind::RetainRV:
838 case ARCInstKind::UnsafeClaimRV:
839 if (DelayedAutoreleaseRV) {
841 if (OptimizeInlinedAutoreleaseRVCall(
F, Inst, Arg, Class,
842 DelayedAutoreleaseRV,
843 DelayedAutoreleaseRVArg)) {
844 setDelayedAutoreleaseRV(
nullptr);
847 optimizeDelayedAutoreleaseRV();
852 OptimizeIndividualCallImpl(
F, Inst, Class, Arg);
856 optimizeDelayedAutoreleaseRV();
862 V = V->stripPointerCasts();
868 if (
auto *GV = dyn_cast<GlobalVariable>(V))
869 if (GV->hasAttribute(
"objc_arc_inert"))
872 if (
auto PN = dyn_cast<PHINode>(V)) {
874 if (!VisitedPhis.
insert(PN).second)
889 LLVM_DEBUG(
dbgs() <<
"Visiting: Class: " << Class <<
"; " << *Inst <<
"\n");
895 UsedInThisFunction |= 1 <<
unsigned(Class);
920 case ARCInstKind::NoopCast:
928 case ARCInstKind::StoreWeak:
929 case ARCInstKind::LoadWeak:
930 case ARCInstKind::LoadWeakRetained:
931 case ARCInstKind::InitWeak:
932 case ARCInstKind::DestroyWeak: {
933 CallInst *CI = cast<CallInst>(Inst);
941 dbgs() <<
"A null pointer-to-weak-pointer is undefined behavior."
943 << *CI <<
"\nNew = " << *NewValue <<
"\n");
950 case ARCInstKind::CopyWeak:
951 case ARCInstKind::MoveWeak: {
952 CallInst *CI = cast<CallInst>(Inst);
962 dbgs() <<
"A null pointer-to-weak-pointer is undefined behavior."
964 << *CI <<
"\nNew = " << *NewValue <<
"\n");
972 case ARCInstKind::RetainRV:
973 if (OptimizeRetainRVCall(
F, Inst))
976 case ARCInstKind::AutoreleaseRV:
977 OptimizeAutoreleaseRVCall(
F, Inst, Class);
984 const Value *Arg =
Call->getArgOperand(0);
993 Function *Decl = EP.
get(ARCRuntimeEntryPointKind::Release);
995 Call->getIterator());
996 NewCall->
setMetadata(MDKindCache.
get(ARCMDKindID::ImpreciseRelease),
999 LLVM_DEBUG(
dbgs() <<
"Replacing autorelease{,RV}(x) with objc_release(x) "
1000 "since x is otherwise unused.\nOld: "
1001 << *
Call <<
"\nNew: " << *NewCall <<
"\n");
1005 Class = ARCInstKind::Release;
1011 if (
IsAlwaysTail(Class) && !cast<CallInst>(Inst)->isNoTailCall()) {
1014 dbgs() <<
"Adding tail keyword to function since it can never be "
1015 "passed stack args: "
1017 cast<CallInst>(Inst)->setTailCall();
1024 LLVM_DEBUG(
dbgs() <<
"Removing tail keyword from function: " << *Inst
1026 cast<CallInst>(Inst)->setTailCall(
false);
1032 LLVM_DEBUG(
dbgs() <<
"Found no throw class. Setting nounwind on: " << *Inst
1034 cast<CallInst>(Inst)->setDoesNotThrow();
1039 UsedInThisFunction |= 1 <<
unsigned(Class);
1051 LLVM_DEBUG(
dbgs() <<
"ARC calls with null are no-ops. Erasing: " << *Inst
1059 UsedInThisFunction |= 1 <<
unsigned(Class);
1067 if (Class == ARCInstKind::Release &&
1068 !Inst->
getMetadata(MDKindCache.
get(ARCMDKindID::ImpreciseRelease)))
1072 Worklist.
push_back(std::make_pair(Inst, Arg));
1074 std::pair<Instruction *, const Value *> Pair = Worklist.
pop_back_val();
1078 const PHINode *PN = dyn_cast<PHINode>(Arg);
1084 bool HasNull =
false;
1085 bool HasCriticalEdges =
false;
1092 HasCriticalEdges =
true;
1097 if (HasCriticalEdges)
1107 case ARCInstKind::Retain:
1108 case ARCInstKind::RetainBlock:
1111 case ARCInstKind::Release:
1117 case ARCInstKind::Autorelease:
1122 case ARCInstKind::UnsafeClaimRV:
1123 case ARCInstKind::RetainRV:
1124 case ARCInstKind::AutoreleaseRV:
1140 CallInst *CInst = cast<CallInst>(Inst);
1153 addOpBundleForFunclet(InsertPos->getParent(), OpBundles);
1155 if (
Op->getType() != ParamTy)
1158 Clone->
insertBefore(*InsertPos->getParent(), InsertPos);
1161 "And inserting clone at "
1162 << *InsertPos <<
"\n");
1168 }
while (!Worklist.
empty());
1174 const bool SuccSRRIKnownSafe,
1176 bool &SomeSuccHasSame,
1177 bool &AllSuccsHaveSame,
1178 bool &NotAllSeqEqualButKnownSafe,
1179 bool &ShouldContinue) {
1187 ShouldContinue =
true;
1191 SomeSuccHasSame =
true;
1196 AllSuccsHaveSame =
false;
1198 NotAllSeqEqualButKnownSafe =
true;
1211 const bool SuccSRRIKnownSafe,
1213 bool &SomeSuccHasSame,
1214 bool &AllSuccsHaveSame,
1215 bool &NotAllSeqEqualButKnownSafe) {
1218 SomeSuccHasSame =
true;
1224 AllSuccsHaveSame =
false;
1226 NotAllSeqEqualButKnownSafe =
true;
1239ObjCARCOpt::CheckForCFGHazards(
const BasicBlock *BB,
1241 BBState &MyStates)
const {
1244 for (
auto I = MyStates.top_down_ptr_begin(), E = MyStates.top_down_ptr_end();
1247 const Sequence Seq =
I->second.GetSeq();
1256 "Unknown top down sequence state.");
1258 const Value *Arg =
I->first;
1259 bool SomeSuccHasSame =
false;
1260 bool AllSuccsHaveSame =
true;
1261 bool NotAllSeqEqualButKnownSafe =
false;
1267 BBStates.
find(Succ);
1277 if (SuccSSeq ==
S_None) {
1284 const bool SuccSRRIKnownSafe = SuccS.
IsKnownSafe();
1290 bool ShouldContinue =
false;
1292 AllSuccsHaveSame, NotAllSeqEqualButKnownSafe,
1300 SomeSuccHasSame, AllSuccsHaveSame,
1301 NotAllSeqEqualButKnownSafe);
1314 if (SomeSuccHasSame && !AllSuccsHaveSame) {
1316 }
else if (NotAllSeqEqualButKnownSafe) {
1326bool ObjCARCOpt::VisitInstructionBottomUp(
1328 BBState &MyStates) {
1329 bool NestingDetected =
false;
1331 const Value *Arg =
nullptr;
1336 case ARCInstKind::Release: {
1343 case ARCInstKind::RetainBlock:
1348 case ARCInstKind::Retain:
1349 case ARCInstKind::RetainRV: {
1355 if (Class != ARCInstKind::RetainRV) {
1364 case ARCInstKind::AutoreleasepoolPop:
1366 MyStates.clearBottomUpPointers();
1367 return NestingDetected;
1368 case ARCInstKind::AutoreleasepoolPush:
1369 case ARCInstKind::None:
1371 return NestingDetected;
1378 for (
auto MI = MyStates.bottom_up_ptr_begin(),
1379 ME = MyStates.bottom_up_ptr_end();
1392 return NestingDetected;
1395bool ObjCARCOpt::VisitBottomUp(
BasicBlock *BB,
1400 bool NestingDetected =
false;
1401 BBState &MyStates = BBStates[BB];
1405 BBState::edge_iterator
SI(MyStates.succ_begin()),
1406 SE(MyStates.succ_end());
1411 MyStates.InitFromSucc(
I->second);
1413 for (;
SI != SE; ++
SI) {
1415 I = BBStates.
find(Succ);
1417 MyStates.MergeSucc(
I->second);
1422 << BBStates[BB] <<
"\n"
1423 <<
"Performing Dataflow:\n");
1430 if (isa<InvokeInst>(Inst))
1435 NestingDetected |= VisitInstructionBottomUp(Inst, BB, Retains, MyStates);
1439 if (MyStates.bottom_up_ptr_list_size() >
MaxPtrStates) {
1440 DisableRetainReleasePairing =
true;
1448 for (BBState::edge_iterator PI(MyStates.pred_begin()),
1449 PE(MyStates.pred_end()); PI != PE; ++PI) {
1452 NestingDetected |= VisitInstructionBottomUp(
II, BB, Retains, MyStates);
1455 LLVM_DEBUG(
dbgs() <<
"\nFinal State:\n" << BBStates[BB] <<
"\n");
1457 return NestingDetected;
1466 &ReleaseInsertPtToRCIdentityRoots) {
1467 for (
const auto &
P : Retains) {
1474 for (
const Instruction *InsertPt :
P.second.ReverseInsertPts)
1475 ReleaseInsertPtToRCIdentityRoots[InsertPt].insert(Root);
1485 &ReleaseInsertPtToRCIdentityRoots) {
1486 auto I = ReleaseInsertPtToRCIdentityRoots.find(InsertPt);
1487 if (
I == ReleaseInsertPtToRCIdentityRoots.end())
1492bool ObjCARCOpt::VisitInstructionTopDown(
1495 &ReleaseInsertPtToRCIdentityRoots) {
1496 bool NestingDetected =
false;
1498 const Value *Arg =
nullptr;
1504 Inst, ReleaseInsertPtToRCIdentityRoots))
1505 for (
const auto *Root : *Roots) {
1519 case ARCInstKind::RetainBlock:
1525 case ARCInstKind::Retain:
1526 case ARCInstKind::RetainRV: {
1534 case ARCInstKind::Release: {
1548 case ARCInstKind::AutoreleasepoolPop:
1550 MyStates.clearTopDownPointers();
1552 case ARCInstKind::AutoreleasepoolPush:
1553 case ARCInstKind::None:
1562 for (
auto MI = MyStates.top_down_ptr_begin(),
1563 ME = MyStates.top_down_ptr_end();
1575 return NestingDetected;
1578bool ObjCARCOpt::VisitTopDown(
1582 &ReleaseInsertPtToRCIdentityRoots) {
1584 bool NestingDetected =
false;
1585 BBState &MyStates = BBStates[BB];
1589 BBState::edge_iterator PI(MyStates.pred_begin()),
1590 PE(MyStates.pred_end());
1595 MyStates.InitFromPred(
I->second);
1597 for (; PI != PE; ++PI) {
1599 I = BBStates.
find(Pred);
1601 MyStates.MergePred(
I->second);
1609 for (
auto I = MyStates.top_down_ptr_begin(),
1610 E = MyStates.top_down_ptr_end();
1612 I->second.SetCFGHazardAfflicted(
true);
1615 << BBStates[BB] <<
"\n"
1616 <<
"Performing Dataflow:\n");
1622 NestingDetected |= VisitInstructionTopDown(
1623 &Inst, Releases, MyStates, ReleaseInsertPtToRCIdentityRoots);
1627 if (MyStates.top_down_ptr_list_size() >
MaxPtrStates) {
1628 DisableRetainReleasePairing =
true;
1633 LLVM_DEBUG(
dbgs() <<
"\nState Before Checking for CFG Hazards:\n"
1634 << BBStates[BB] <<
"\n\n");
1635 CheckForCFGHazards(BB, BBStates, MyStates);
1637 return NestingDetected;
1644 unsigned NoObjCARCExceptionsMDKind,
1656 BBState &MyStates = BBStates[EntryBB];
1657 MyStates.SetAsEntry();
1667 while (SuccStack.
back().second != SE) {
1669 if (Visited.
insert(SuccBB).second) {
1672 BBStates[CurrBB].addSucc(SuccBB);
1673 BBState &SuccStates = BBStates[SuccBB];
1674 SuccStates.addPred(CurrBB);
1679 if (!OnStack.
count(SuccBB)) {
1680 BBStates[CurrBB].addSucc(SuccBB);
1681 BBStates[SuccBB].addPred(CurrBB);
1684 OnStack.
erase(CurrBB);
1687 }
while (!SuccStack.
empty());
1696 BBState &MyStates = BBStates[&ExitBB];
1697 if (!MyStates.isExit())
1700 MyStates.SetAsExit();
1702 PredStack.
push_back(std::make_pair(&ExitBB, MyStates.pred_begin()));
1704 while (!PredStack.
empty()) {
1705 reverse_dfs_next_succ:
1706 BBState::edge_iterator PE = BBStates[PredStack.
back().first].pred_end();
1707 while (PredStack.
back().second != PE) {
1709 if (Visited.
insert(BB).second) {
1711 goto reverse_dfs_next_succ;
1732 MDKindCache.
get(ARCMDKindID::NoObjCARCExceptions),
1736 bool BottomUpNestingDetected =
false;
1738 BottomUpNestingDetected |= VisitBottomUp(BB, BBStates, Retains);
1739 if (DisableRetainReleasePairing)
1744 ReleaseInsertPtToRCIdentityRoots;
1748 bool TopDownNestingDetected =
false;
1750 TopDownNestingDetected |=
1751 VisitTopDown(BB, BBStates, Releases, ReleaseInsertPtToRCIdentityRoots);
1752 if (DisableRetainReleasePairing)
1756 return TopDownNestingDetected && BottomUpNestingDetected;
1760void ObjCARCOpt::MoveCalls(
Value *Arg,
RRInfo &RetainsToMove,
1773 Value *MyArg = ArgTy == ParamTy ? Arg
1776 Function *Decl = EP.
get(ARCRuntimeEntryPointKind::Retain);
1778 addOpBundleForFunclet(InsertPt->
getParent(), BundleList);
1781 Call->setDoesNotThrow();
1782 Call->setTailCall();
1786 "At insertion point: "
1787 << *InsertPt <<
"\n");
1790 Value *MyArg = ArgTy == ParamTy ? Arg
1793 Function *Decl = EP.
get(ARCRuntimeEntryPointKind::Release);
1795 addOpBundleForFunclet(InsertPt->
getParent(), BundleList);
1800 Call->setMetadata(MDKindCache.
get(ARCMDKindID::ImpreciseRelease), M);
1801 Call->setDoesNotThrow();
1803 Call->setTailCall();
1807 "At insertion point: "
1808 << *InsertPt <<
"\n");
1813 Retains.
blot(OrigRetain);
1815 LLVM_DEBUG(
dbgs() <<
"Deleting retain: " << *OrigRetain <<
"\n");
1818 Releases.
erase(OrigRelease);
1820 LLVM_DEBUG(
dbgs() <<
"Deleting release: " << *OrigRelease <<
"\n");
1824bool ObjCARCOpt::PairUpRetainsAndReleases(
1830 RRInfo &ReleasesToMove,
Value *Arg,
bool KnownSafe,
1831 bool &AnyPairsCompletelyEliminated) {
1835 bool KnownSafeTD =
true, KnownSafeBU =
true;
1836 bool CFGHazardAfflicted =
false;
1842 unsigned OldDelta = 0;
1843 unsigned NewDelta = 0;
1844 unsigned OldCount = 0;
1845 unsigned NewCount = 0;
1846 bool FirstRelease =
true;
1850 auto It = Retains.
find(NewRetain);
1852 const RRInfo &NewRetainRRI = It->second;
1856 auto Jt = Releases.
find(NewRetainRelease);
1857 if (Jt == Releases.
end())
1859 const RRInfo &NewRetainReleaseRRI = Jt->second;
1866 if (!NewRetainReleaseRRI.
Calls.count(NewRetain))
1869 if (ReleasesToMove.
Calls.insert(NewRetainRelease).second) {
1872 const BBState &NRRBBState = BBStates[NewRetainRelease->
getParent()];
1874 if (NRRBBState.GetAllPathCountWithOverflow(PathCount))
1877 "PathCount at this point can not be "
1878 "OverflowOccurredValue.");
1879 OldDelta -= PathCount;
1887 FirstRelease =
false;
1903 const BBState &RIPBBState = BBStates[RIP->
getParent()];
1905 if (RIPBBState.GetAllPathCountWithOverflow(PathCount))
1908 "PathCount at this point can not be "
1909 "OverflowOccurredValue.");
1910 NewDelta -= PathCount;
1913 NewReleases.
push_back(NewRetainRelease);
1918 if (NewReleases.
empty())
break;
1922 auto It = Releases.
find(NewRelease);
1924 const RRInfo &NewReleaseRRI = It->second;
1928 auto Jt = Retains.
find(NewReleaseRetain);
1929 if (Jt == Retains.
end())
1931 const RRInfo &NewReleaseRetainRRI = Jt->second;
1938 if (!NewReleaseRetainRRI.
Calls.count(NewRelease))
1941 if (RetainsToMove.
Calls.insert(NewReleaseRetain).second) {
1944 const BBState &NRRBBState = BBStates[NewReleaseRetain->
getParent()];
1946 if (NRRBBState.GetAllPathCountWithOverflow(PathCount))
1949 "PathCount at this point can not be "
1950 "OverflowOccurredValue.");
1951 OldDelta += PathCount;
1952 OldCount += PathCount;
1960 const BBState &RIPBBState = BBStates[RIP->
getParent()];
1963 if (RIPBBState.GetAllPathCountWithOverflow(PathCount))
1966 "PathCount at this point can not be "
1967 "OverflowOccurredValue.");
1968 NewDelta += PathCount;
1969 NewCount += PathCount;
1972 NewRetains.push_back(NewReleaseRetain);
1976 if (NewRetains.empty())
break;
1980 bool UnconditionallySafe = KnownSafeTD && KnownSafeBU;
1981 if (UnconditionallySafe) {
1996 const bool WillPerformCodeMotion =
1999 if (CFGHazardAfflicted && WillPerformCodeMotion)
2012 assert(OldCount != 0 &&
"Unreachable code?");
2013 NumRRs += OldCount - NewCount;
2015 AnyPairsCompletelyEliminated = NewCount == 0;
2023bool ObjCARCOpt::PerformCodePlacement(
2027 LLVM_DEBUG(
dbgs() <<
"\n== ObjCARCOpt::PerformCodePlacement ==\n");
2029 bool AnyPairsCompletelyEliminated =
false;
2048 bool KnownSafe = isa<Constant>(Arg) || isa<AllocaInst>(Arg);
2052 if (
const LoadInst *LI = dyn_cast<LoadInst>(Arg))
2054 dyn_cast<GlobalVariable>(
2056 if (GV->isConstant())
2061 RRInfo RetainsToMove, ReleasesToMove;
2063 bool PerformMoveCalls = PairUpRetainsAndReleases(
2064 BBStates, Retains, Releases, M,
Retain, DeadInsts,
2065 RetainsToMove, ReleasesToMove, Arg, KnownSafe,
2066 AnyPairsCompletelyEliminated);
2068 if (PerformMoveCalls) {
2071 MoveCalls(Arg, RetainsToMove, ReleasesToMove,
2072 Retains, Releases, DeadInsts, M);
2078 while (!DeadInsts.
empty())
2081 return AnyPairsCompletelyEliminated;
2085void ObjCARCOpt::OptimizeWeakCalls(
Function &
F) {
2097 if (Class != ARCInstKind::LoadWeak &&
2098 Class != ARCInstKind::LoadWeakRetained)
2102 if (Class == ARCInstKind::LoadWeak && Inst->
use_empty()) {
2119 switch (EarlierClass) {
2120 case ARCInstKind::LoadWeak:
2121 case ARCInstKind::LoadWeakRetained: {
2125 CallInst *EarlierCall = cast<CallInst>(EarlierInst);
2128 switch (PA.
getAA()->
alias(Arg, EarlierArg)) {
2132 if (Class == ARCInstKind::LoadWeakRetained) {
2133 Function *Decl = EP.
get(ARCRuntimeEntryPointKind::Retain);
2139 Call->replaceAllUsesWith(EarlierCall);
2140 Call->eraseFromParent();
2150 case ARCInstKind::StoreWeak:
2151 case ARCInstKind::InitWeak: {
2155 CallInst *EarlierCall = cast<CallInst>(EarlierInst);
2158 switch (PA.
getAA()->
alias(Arg, EarlierArg)) {
2162 if (Class == ARCInstKind::LoadWeakRetained) {
2163 Function *Decl = EP.
get(ARCRuntimeEntryPointKind::Retain);
2170 Call->eraseFromParent();
2180 case ARCInstKind::MoveWeak:
2181 case ARCInstKind::CopyWeak:
2184 case ARCInstKind::AutoreleasepoolPush:
2185 case ARCInstKind::None:
2186 case ARCInstKind::IntrinsicUser:
2187 case ARCInstKind::User:
2203 if (Class != ARCInstKind::DestroyWeak)
2208 if (
AllocaInst *Alloca = dyn_cast<AllocaInst>(Arg)) {
2210 const Instruction *UserInst = cast<Instruction>(U);
2212 case ARCInstKind::InitWeak:
2213 case ARCInstKind::StoreWeak:
2214 case ARCInstKind::DestroyWeak:
2222 CallInst *UserInst = cast<CallInst>(U);
2224 case ARCInstKind::InitWeak:
2225 case ARCInstKind::StoreWeak:
2229 case ARCInstKind::DestroyWeak:
2237 Alloca->eraseFromParent();
2245bool ObjCARCOpt::OptimizeSequences(
Function &
F) {
2258 bool NestingDetected = Visit(
F, BBStates, Retains, Releases);
2260 if (DisableRetainReleasePairing)
2264 bool AnyPairsCompletelyEliminated = PerformCodePlacement(BBStates, Retains,
2268 return AnyPairsCompletelyEliminated && NestingDetected;
2286 return Class == ARCInstKind::CallOrUser || Class == ARCInstKind::Call
2298 auto *
Retain = dyn_cast_or_null<CallInst>(
2340void ObjCARCOpt::OptimizeReturns(
Function &
F) {
2341 if (!
F.getReturnType()->isPointerTy())
2376 (!
Call->isTailCall() &&
2393ObjCARCOpt::GatherStatistics(
Function &
F,
bool AfterOptimization) {
2395 AfterOptimization ? NumRetainsAfterOpt : NumRetainsBeforeOpt;
2397 AfterOptimization ? NumReleasesAfterOpt : NumReleasesBeforeOpt;
2404 case ARCInstKind::Retain:
2407 case ARCInstKind::Release:
2422 MDKindCache.
init(
F.getParent());
2425 EP.
init(
F.getParent());
2428 if (
F.hasPersonalityFn() &&
2437 Changed = CFGChanged =
false;
2439 BundledInsts = &BRV;
2441 LLVM_DEBUG(
dbgs() <<
"<<< ObjCARCOpt: Visiting Function: " <<
F.getName()
2447 CFGChanged |=
R.second;
2453 GatherStatistics(
F,
false);
2462 OptimizeIndividualCalls(
F);
2465 if (UsedInThisFunction & ((1 <<
unsigned(ARCInstKind::LoadWeak)) |
2466 (1 <<
unsigned(ARCInstKind::LoadWeakRetained)) |
2467 (1 <<
unsigned(ARCInstKind::StoreWeak)) |
2468 (1 <<
unsigned(ARCInstKind::InitWeak)) |
2469 (1 <<
unsigned(ARCInstKind::CopyWeak)) |
2470 (1 <<
unsigned(ARCInstKind::MoveWeak)) |
2471 (1 <<
unsigned(ARCInstKind::DestroyWeak))))
2472 OptimizeWeakCalls(
F);
2475 if (UsedInThisFunction & ((1 <<
unsigned(ARCInstKind::Retain)) |
2476 (1 <<
unsigned(ARCInstKind::RetainRV)) |
2477 (1 <<
unsigned(ARCInstKind::RetainBlock))))
2478 if (UsedInThisFunction & (1 <<
unsigned(ARCInstKind::Release)))
2481 while (OptimizeSequences(
F)) {}
2484 if (UsedInThisFunction & ((1 <<
unsigned(ARCInstKind::Autorelease)) |
2485 (1 <<
unsigned(ARCInstKind::AutoreleaseRV))))
2491 GatherStatistics(
F,
true);
2509 bool CFGChanged = OCAO.hasCFGChanged();
This file contains a class ARCRuntimeEntryPoints for use in creating/managing references to entry poi...
Expand Atomic instructions
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ATTRIBUTE_UNUSED
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file declares special dependency analysis routines used in Objective C ARC Optimizations.
std::optional< std::vector< StOtherPiece > > Other
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
iv Induction Variable Users
uint64_t IntrinsicInst * II
This file declares a simple ARC-aware AliasAnalysis using special knowledge of Objective C to enhance...
This file defines common analysis utilities used by the ObjC ARC Optimizer.
static cl::opt< unsigned > MaxPtrStates("arc-opt-max-ptr-states", cl::Hidden, cl::desc("Maximum number of ptr states the optimizer keeps track of"), cl::init(4095))
This file defines ARC utility functions which are used by various parts of the compiler.
This file declares a special form of Alias Analysis called Provenance Analysis''.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A manager for alias analyses.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
@ MayAlias
The two locations may or may not alias.
@ NoAlias
The two locations do not alias at all.
@ PartialAlias
The two locations alias, but only due to a partial overlap.
@ MustAlias
The two locations precisely alias each other.
an instruction to allocate memory on the stack
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
InstListType::const_iterator const_iterator
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
const Instruction & back() const
This class represents a no-op cast from one type to another.
An associative container with fast insertion-order (deterministic) iteration over its elements.
void blot(const KeyT &Key)
This is similar to erase, but instead of removing the element from the vector, it just zeros out the ...
iterator find(const KeyT &Key)
typename VectorTy::const_iterator const_iterator
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &InsertPair)
Represents analyses that only rely on functions' control flow.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
Value * getArgOperand(unsigned i) const
void setArgOperand(unsigned i, Value *v)
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
void setTailCall(bool IsTc=true)
static ConstantInt * getTrue(LLVMContext &Context)
This class represents an Operation in the Expression.
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
BIty & getInstructionIterator()
BBIty & getBasicBlockIterator()
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
A Module instance is used to store all the information related to an LLVM module.
op_range incoming_values()
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void preserveSet()
Mark an analysis set as preserved.
Return a value (possibly void), from a function.
bool erase(PtrType Ptr)
Remove pointer from the set.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
typename SuperClass::const_iterator const_iterator
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt8Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
LLVMContext & getContext() const
All values hold a context through their type.
const ParentTy * getParent() const
self_iterator getIterator()
A cache of MDKinds used by various ARC optimizations.
unsigned get(ARCMDKindID ID)
Declarations for ObjC runtime functions and constants.
Function * get(ARCRuntimeEntryPointKind kind)
bool contains(const Instruction *I) const
See if an instruction is a bundled retainRV/claimRV call.
std::pair< bool, bool > insertAfterInvokes(Function &F, DominatorTree *DT)
Insert a retainRV/claimRV call to the normal destination blocks of invokes with operand bundle "clang...
CallInst * insertRVCall(BasicBlock::iterator InsertPt, CallBase *AnnotatedCall)
Insert a retainRV/claimRV call.
void eraseInst(CallInst *CI)
Remove a retainRV/claimRV call entirely.
This is similar to BasicAliasAnalysis, and it uses many of the same techniques, except it uses specia...
AAResults * getAA() const
void setAA(AAResults *aa)
This class summarizes several per-pointer runtime properties which are propagated through the flow gr...
void SetCFGHazardAfflicted(const bool NewValue)
const RRInfo & GetRRInfo() const
void ClearSequenceProgress()
This class implements an extremely fast bulk output stream that can only output to a stream.
static void CheckForUseCFGHazard(const Sequence SuccSSeq, const bool SuccSRRIKnownSafe, TopDownPtrState &S, bool &SomeSuccHasSame, bool &AllSuccsHaveSame, bool &NotAllSeqEqualButKnownSafe, bool &ShouldContinue)
If we have a top down pointer in the S_Use state, make sure that there are no CFG hazards by checking...
static void CheckForCanReleaseCFGHazard(const Sequence SuccSSeq, const bool SuccSRRIKnownSafe, TopDownPtrState &S, bool &SomeSuccHasSame, bool &AllSuccsHaveSame, bool &NotAllSeqEqualButKnownSafe)
If we have a Top Down pointer in the S_CanRelease state, make sure that there are no CFG hazards by c...
static bool isInertARCValue(Value *V, SmallPtrSet< Value *, 1 > &VisitedPhis)
This function returns true if the value is inert.
static CallInst * FindPredecessorAutoreleaseWithSafePath(const Value *Arg, BasicBlock *BB, ReturnInst *Ret, ProvenanceAnalysis &PA)
Look for an `‘autorelease’' instruction dependent on Arg such that there are no instructions dependen...
static void collectReleaseInsertPts(const BlotMapVector< Value *, RRInfo > &Retains, DenseMap< const Instruction *, SmallPtrSet< const Value *, 2 > > &ReleaseInsertPtToRCIdentityRoots)
static void ComputePostOrders(Function &F, SmallVectorImpl< BasicBlock * > &PostOrder, SmallVectorImpl< BasicBlock * > &ReverseCFGPostOrder, unsigned NoObjCARCExceptionsMDKind, DenseMap< const BasicBlock *, BBState > &BBStates)
static CallInst * FindPredecessorRetainWithSafePath(const Value *Arg, BasicBlock *BB, Instruction *Autorelease, ProvenanceAnalysis &PA)
Find a dependent retain that precedes the given autorelease for which there is nothing in between the...
static const SmallPtrSet< const Value *, 2 > * getRCIdentityRootsFromReleaseInsertPt(const Instruction *InsertPt, const DenseMap< const Instruction *, SmallPtrSet< const Value *, 2 > > &ReleaseInsertPtToRCIdentityRoots)
static const unsigned OverflowOccurredValue
static CallInst * HasSafePathToPredecessorCall(const Value *Arg, Instruction *Retain, ProvenanceAnalysis &PA)
Check if there is a dependent call earlier that does not have anything in between the Retain and the ...
static const Value * FindSingleUseIdentifiedObject(const Value *Arg)
This is similar to GetRCIdentityRoot but it stops as soon as it finds a value with multiple uses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
bool IsRetain(ARCInstKind Class)
Test if the given class is objc_retain or equivalent.
@ AutoreleasePoolBoundary
@ NeedsPositiveRetainCount
bool IsNeverTail(ARCInstKind Class)
Test if the given class represents instructions which are never safe to mark with the "tail" keyword.
bool IsAlwaysTail(ARCInstKind Class)
Test if the given class represents instructions which are always safe to mark with the "tail" keyword...
bool IsNullOrUndef(const Value *V)
bool IsAutorelease(ARCInstKind Class)
Test if the given class is objc_autorelease or equivalent.
ARCInstKind
Equivalence classes of instructions in the ARC Model.
@ Autorelease
objc_autorelease
@ RetainRV
objc_retainAutoreleasedReturnValue
@ AutoreleaseRV
objc_autoreleaseReturnValue
@ Call
could call objc_release
bool IsObjCIdentifiedObject(const Value *V)
Return true if this value refers to a distinct and identifiable object.
bool EnableARCOpts
A handy option to enable/disable all ARC Optimizations.
void getEquivalentPHIs(PHINodeTy &PN, VectorTy &PHIList)
Return the list of PHI nodes that are equivalent to PN.
bool IsForwarding(ARCInstKind Class)
Test if the given class represents instructions which return their argument verbatim.
bool IsNoopInstruction(const Instruction *I)
llvm::Instruction * findSingleDependency(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, ProvenanceAnalysis &PA)
Find dependent instructions.
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
@ S_CanRelease
foo(x) – x could possibly see a ref count decrement.
@ S_Retain
objc_retain(x).
@ S_Stop
code motion is stopped.
@ S_MovableRelease
objc_release(x), !clang.imprecise_release.
ARCInstKind GetBasicARCInstKind(const Value *V)
Determine which objc runtime call instruction class V belongs to.
ARCInstKind GetARCInstKind(const Value *V)
Map V to its ARCInstKind equivalence class.
Value * GetArgRCIdentityRoot(Value *Inst)
Assuming the given instruction is one of the special calls such as objc_retain or objc_release,...
bool IsNoThrow(ARCInstKind Class)
Test if the given class represents instructions which are always safe to mark with the nounwind attri...
const Value * GetRCIdentityRoot(const Value *V)
The RCIdentity root of a value V is a dominating value U for which retaining or releasing U is equiva...
bool IsNoopOnGlobal(ARCInstKind Class)
Test if the given class represents instructions which do nothing if passed a global variable.
bool IsNoopOnNull(ARCInstKind Class)
Test if the given class represents instructions which do nothing if passed a null pointer.
bool hasAttachedCallOpBundle(const CallBase *CB)
static void EraseInstruction(Instruction *CI)
Erase the given instruction.
This is an optimization pass for GlobalISel generic memory operations.
pred_iterator pred_end(BasicBlock *BB)
auto successors(const MachineBasicBlock *BB)
DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
inst_iterator inst_begin(Function *F)
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
pred_iterator pred_begin(BasicBlock *BB)
auto reverse(ContainerTy &&C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
SuccIterator< Instruction, BasicBlock > succ_iterator
bool AreStatisticsEnabled()
Check if statistics are enabled.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
inst_iterator inst_end(Function *F)
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Incoming for lane maks phi as machine instruction, incoming register Reg and incoming block Block are...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
A lightweight accessor for an operand bundle meant to be passed around by value.
bool HandlePotentialAlterRefCount(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
bool InitBottomUp(ARCMDKindCache &Cache, Instruction *I)
(Re-)Initialize this bottom up pointer returning true if we detected a pointer with nested releases.
bool MatchWithRetain()
Return true if this set of releases can be paired with a release.
void HandlePotentialUse(BasicBlock *BB, Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
Unidirectional information about either a retain-decrement-use-release sequence or release-use-decrem...
bool KnownSafe
After an objc_retain, the reference count of the referenced object is known to be positive.
SmallPtrSet< Instruction *, 2 > Calls
For a top-down sequence, the set of objc_retains or objc_retainBlocks.
MDNode * ReleaseMetadata
If the Calls are objc_release calls and they all have a clang.imprecise_release tag,...
bool CFGHazardAfflicted
If this is true, we cannot perform code motion but can still remove retain/release pairs.
bool IsTailCallRelease
True of the objc_release calls are all marked with the "tail" keyword.
SmallPtrSet< Instruction *, 2 > ReverseInsertPts
The set of optimal insert positions for moving calls in the opposite sequence.
bool MatchWithRelease(ARCMDKindCache &Cache, Instruction *Release)
Return true if this set of retains can be paired with the given release.
bool InitTopDown(ARCInstKind Kind, Instruction *I)
(Re-)Initialize this bottom up pointer returning true if we detected a pointer with nested releases.
bool HandlePotentialAlterRefCount(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class, const BundledRetainClaimRVs &BundledRVs)
void HandlePotentialUse(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)