diff options
author | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-10-27 01:09:08 +0000 |
---|---|---|
committer | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-10-27 01:09:08 +0000 |
commit | 57bd5a0274d63a7ab53d8064ff916fc89a80a5df (patch) | |
tree | 8a7f4560d3ca9a3cdf98a6d28e0ca7f3373ebb63 /llvm/lib/Transforms/ObjCARC | |
parent | 636ed47428c1cf9304c4131d631f3c0b72f020ad (diff) | |
download | bcm5719-llvm-57bd5a0274d63a7ab53d8064ff916fc89a80a5df.tar.gz bcm5719-llvm-57bd5a0274d63a7ab53d8064ff916fc89a80a5df.zip |
[Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 316724
Diffstat (limited to 'llvm/lib/Transforms/ObjCARC')
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h | 64 | ||||
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/BlotMapVector.h | 34 | ||||
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 121 | ||||
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h | 32 | ||||
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/PtrState.cpp | 14 | ||||
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/PtrState.h | 39 |
7 files changed, 197 insertions, 122 deletions
diff --git a/llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h b/llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h index cb3b5757f8d..ba4924c9cb2 100644 --- a/llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h +++ b/llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h @@ -1,4 +1,4 @@ -//===- ARCRuntimeEntryPoints.h - ObjC ARC Optimization --*- C++ -*---------===// +//===- ARCRuntimeEntryPoints.h - ObjC ARC Optimization ----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -6,6 +6,7 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// /// \file /// This file contains a class ARCRuntimeEntryPoints for use in /// creating/managing references to entry points to the arc objective c runtime. @@ -16,15 +17,25 @@ /// WARNING: This file knows about how certain Objective-C library functions are /// used. Naive LLVM IR transformations which would otherwise be /// behavior-preserving may break these assumptions. -/// +// //===----------------------------------------------------------------------===// #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H #define LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H -#include "ObjCARC.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" +#include "llvm/Support/ErrorHandling.h" +#include <cassert> namespace llvm { + +class Constant; +class LLVMContext; + namespace objcarc { enum class ARCRuntimeEntryPointKind { @@ -43,16 +54,7 @@ enum class ARCRuntimeEntryPointKind { /// lazily to avoid cluttering up the Module with unused declarations. class ARCRuntimeEntryPoints { public: - ARCRuntimeEntryPoints() : TheModule(nullptr), - AutoreleaseRV(nullptr), - Release(nullptr), - Retain(nullptr), - RetainBlock(nullptr), - Autorelease(nullptr), - StoreStrong(nullptr), - RetainRV(nullptr), - RetainAutorelease(nullptr), - RetainAutoreleaseRV(nullptr) { } + ARCRuntimeEntryPoints() = default; void init(Module *M) { TheModule = M; @@ -100,26 +102,34 @@ public: private: /// Cached reference to the module which we will insert declarations into. - Module *TheModule; + Module *TheModule = nullptr; /// Declaration for ObjC runtime function objc_autoreleaseReturnValue. - Constant *AutoreleaseRV; + Constant *AutoreleaseRV = nullptr; + /// Declaration for ObjC runtime function objc_release. - Constant *Release; + Constant *Release = nullptr; + /// Declaration for ObjC runtime function objc_retain. - Constant *Retain; + Constant *Retain = nullptr; + /// Declaration for ObjC runtime function objc_retainBlock. - Constant *RetainBlock; + Constant *RetainBlock = nullptr; + /// Declaration for ObjC runtime function objc_autorelease. - Constant *Autorelease; + Constant *Autorelease = nullptr; + /// Declaration for objc_storeStrong(). - Constant *StoreStrong; + Constant *StoreStrong = nullptr; + /// Declaration for objc_retainAutoreleasedReturnValue(). - Constant *RetainRV; + Constant *RetainRV = nullptr; + /// Declaration for objc_retainAutorelease(). - Constant *RetainAutorelease; + Constant *RetainAutorelease = nullptr; + /// Declaration for objc_retainAutoreleaseReturnValue(). - Constant *RetainAutoreleaseRV; + Constant *RetainAutoreleaseRV = nullptr; Constant *getVoidRetI8XEntryPoint(Constant *&Decl, StringRef Name) { if (Decl) @@ -170,10 +180,10 @@ private: return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr); } +}; -}; // class ARCRuntimeEntryPoints +} // end namespace objcarc -} // namespace objcarc -} // namespace llvm +} // end namespace llvm -#endif +#endif // LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H diff --git a/llvm/lib/Transforms/ObjCARC/BlotMapVector.h b/llvm/lib/Transforms/ObjCARC/BlotMapVector.h index 9c5cf6f5f5a..5518b49c409 100644 --- a/llvm/lib/Transforms/ObjCARC/BlotMapVector.h +++ b/llvm/lib/Transforms/ObjCARC/BlotMapVector.h @@ -1,4 +1,4 @@ -//===- BlotMapVector.h - A MapVector with the blot operation -*- C++ -*----===// +//===- BlotMapVector.h - A MapVector with the blot operation ----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -7,30 +7,29 @@ // //===----------------------------------------------------------------------===// +#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_BLOTMAPVECTOR_H +#define LLVM_LIB_TRANSFORMS_OBJCARC_BLOTMAPVECTOR_H + #include "llvm/ADT/DenseMap.h" -#include <algorithm> +#include <cassert> +#include <cstddef> +#include <utility> #include <vector> namespace llvm { + /// \brief An associative container with fast insertion-order (deterministic) /// iteration over its elements. Plus the special blot operation. template <class KeyT, class ValueT> class BlotMapVector { /// Map keys to indices in Vector. - typedef DenseMap<KeyT, size_t> MapTy; + using MapTy = DenseMap<KeyT, size_t>; MapTy Map; - typedef std::vector<std::pair<KeyT, ValueT>> VectorTy; /// Keys and values. + using VectorTy = std::vector<std::pair<KeyT, ValueT>>; VectorTy Vector; public: - typedef typename VectorTy::iterator iterator; - typedef typename VectorTy::const_iterator const_iterator; - iterator begin() { return Vector.begin(); } - iterator end() { return Vector.end(); } - const_iterator begin() const { return Vector.begin(); } - const_iterator end() const { return Vector.end(); } - #ifdef EXPENSIVE_CHECKS ~BlotMapVector() { assert(Vector.size() >= Map.size()); // May differ due to blotting. @@ -46,6 +45,14 @@ public: } #endif + using iterator = typename VectorTy::iterator; + using const_iterator = typename VectorTy::const_iterator; + + iterator begin() { return Vector.begin(); } + iterator end() { return Vector.end(); } + const_iterator begin() const { return Vector.begin(); } + const_iterator end() const { return Vector.end(); } + ValueT &operator[](const KeyT &Arg) { std::pair<typename MapTy::iterator, bool> Pair = Map.insert(std::make_pair(Arg, size_t(0))); @@ -105,4 +112,7 @@ public: return Map.empty(); } }; -} // + +} // end namespace llvm + +#endif // LLVM_LIB_TRANSFORMS_OBJCARC_BLOTMAPVECTOR_H diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index 6692d950da2..99ed6863c22 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -6,6 +6,7 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// /// \file /// This file defines ObjC ARC optimizations. ARC stands for Automatic /// Reference Counting and is a system for managing reference counts for objects @@ -21,7 +22,7 @@ /// WARNING: This file knows about how certain Objective-C library functions are /// used. Naive LLVM IR transformations which would otherwise be /// behavior-preserving may break these assumptions. -/// +// //===----------------------------------------------------------------------===// #include "ARCRuntimeEntryPoints.h" @@ -31,16 +32,41 @@ #include "ProvenanceAnalysis.h" #include "PtrState.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" +#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/ObjCARCAliasAnalysis.h" +#include "llvm/Analysis/ObjCARCAnalysisUtils.h" +#include "llvm/Analysis/ObjCARCInstKind.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" -#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/CallSite.h" +#include "llvm/IR/Constant.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Metadata.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" +#include "llvm/Pass.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" +#include <cassert> +#include <iterator> +#include <utility> using namespace llvm; using namespace llvm::objcarc; @@ -147,14 +173,15 @@ STATISTIC(NumReleasesAfterOpt, #endif namespace { + /// \brief Per-BasicBlock state. class BBState { /// The number of unique control paths from the entry which can reach this /// block. - unsigned TopDownPathCount; + unsigned TopDownPathCount = 0; /// The number of unique control paths to exits from this block. - unsigned BottomUpPathCount; + unsigned BottomUpPathCount = 0; /// The top-down traversal uses this to record information known about a /// pointer at the bottom of each block. @@ -175,10 +202,10 @@ namespace { public: static const unsigned OverflowOccurredValue; - BBState() : TopDownPathCount(0), BottomUpPathCount(0) { } + BBState() = default; - typedef decltype(PerPtrTopDown)::iterator top_down_ptr_iterator; - typedef decltype(PerPtrTopDown)::const_iterator const_top_down_ptr_iterator; + using top_down_ptr_iterator = decltype(PerPtrTopDown)::iterator; + using const_top_down_ptr_iterator = decltype(PerPtrTopDown)::const_iterator; top_down_ptr_iterator top_down_ptr_begin() { return PerPtrTopDown.begin(); } top_down_ptr_iterator top_down_ptr_end() { return PerPtrTopDown.end(); } @@ -192,9 +219,9 @@ namespace { return !PerPtrTopDown.empty(); } - typedef decltype(PerPtrBottomUp)::iterator bottom_up_ptr_iterator; - typedef decltype( - PerPtrBottomUp)::const_iterator const_bottom_up_ptr_iterator; + using bottom_up_ptr_iterator = decltype(PerPtrBottomUp)::iterator; + using const_bottom_up_ptr_iterator = + decltype(PerPtrBottomUp)::const_iterator; bottom_up_ptr_iterator bottom_up_ptr_begin() { return PerPtrBottomUp.begin(); @@ -270,7 +297,8 @@ namespace { } // Specialized CFG utilities. - typedef SmallVectorImpl<BasicBlock *>::const_iterator edge_iterator; + using edge_iterator = SmallVectorImpl<BasicBlock *>::const_iterator; + edge_iterator pred_begin() const { return Preds.begin(); } edge_iterator pred_end() const { return Preds.end(); } edge_iterator succ_begin() const { return Succs.begin(); } @@ -282,13 +310,16 @@ namespace { bool isExit() const { return Succs.empty(); } }; - const unsigned BBState::OverflowOccurredValue = 0xffffffff; -} +} // end anonymous namespace + +const unsigned BBState::OverflowOccurredValue = 0xffffffff; namespace llvm { + raw_ostream &operator<<(raw_ostream &OS, BBState &BBState) LLVM_ATTRIBUTE_UNUSED; -} + +} // end namespace llvm void BBState::InitFromPred(const BBState &Other) { PerPtrTopDown = Other.PerPtrTopDown; @@ -391,7 +422,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, BBState &BBInfo) { // Dump the pointers we are tracking. OS << " TopDown State:\n"; if (!BBInfo.hasTopDownPtrs()) { - DEBUG(llvm::dbgs() << " NONE!\n"); + DEBUG(dbgs() << " NONE!\n"); } else { for (auto I = BBInfo.top_down_ptr_begin(), E = BBInfo.top_down_ptr_end(); I != E; ++I) { @@ -411,7 +442,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, BBState &BBInfo) { OS << " BottomUp State:\n"; if (!BBInfo.hasBottomUpPtrs()) { - DEBUG(llvm::dbgs() << " NONE!\n"); + DEBUG(dbgs() << " NONE!\n"); } else { for (auto I = BBInfo.bottom_up_ptr_begin(), E = BBInfo.bottom_up_ptr_end(); I != E; ++I) { @@ -513,13 +544,16 @@ namespace { public: static char ID; + ObjCARCOpt() : FunctionPass(ID) { initializeObjCARCOptPass(*PassRegistry::getPassRegistry()); } }; -} + +} // end anonymous namespace char ObjCARCOpt::ID = 0; + INITIALIZE_PASS_BEGIN(ObjCARCOpt, "objc-arc", "ObjC ARC optimization", false, false) INITIALIZE_PASS_DEPENDENCY(ObjCARCAAWrapperPass) @@ -643,7 +677,6 @@ void ObjCARCOpt::OptimizeAutoreleaseRVCall(Function &F, Class = ARCInstKind::Autorelease; DEBUG(dbgs() << "New: " << *AutoreleaseRV << "\n"); - } /// Visit each call, one at a time, and make simplifications without doing any @@ -692,7 +725,7 @@ void ObjCARCOpt::OptimizeIndividualCalls(Function &F) { new StoreInst(UndefValue::get(cast<PointerType>(Ty)->getElementType()), Constant::getNullValue(Ty), CI); - llvm::Value *NewValue = UndefValue::get(CI->getType()); + Value *NewValue = UndefValue::get(CI->getType()); DEBUG(dbgs() << "A null pointer-to-weak-pointer is undefined behavior." "\nOld = " << *CI << "\nNew = " << *NewValue << "\n"); CI->replaceAllUsesWith(NewValue); @@ -712,7 +745,7 @@ void ObjCARCOpt::OptimizeIndividualCalls(Function &F) { Constant::getNullValue(Ty), CI); - llvm::Value *NewValue = UndefValue::get(CI->getType()); + Value *NewValue = UndefValue::get(CI->getType()); DEBUG(dbgs() << "A null pointer-to-weak-pointer is undefined behavior." "\nOld = " << *CI << "\nNew = " << *NewValue << "\n"); @@ -1045,12 +1078,11 @@ ObjCARCOpt::CheckForCFGHazards(const BasicBlock *BB, continue; break; } - case S_CanRelease: { + case S_CanRelease: CheckForCanReleaseCFGHazard(SuccSSeq, SuccSRRIKnownSafe, S, SomeSuccHasSame, AllSuccsHaveSame, NotAllSeqEqualButKnownSafe); break; - } case S_Retain: case S_None: case S_Stop: @@ -1105,7 +1137,7 @@ bool ObjCARCOpt::VisitInstructionBottomUp( // Don't do retain+release tracking for ARCInstKind::RetainRV, because // it's better to let it remain as the first instruction after a call. if (Class != ARCInstKind::RetainRV) { - DEBUG(llvm::dbgs() << " Matching with: " << *Inst << "\n"); + DEBUG(dbgs() << " Matching with: " << *Inst << "\n"); Retains[Inst] = S.GetRRInfo(); } S.ClearSequenceProgress(); @@ -1147,7 +1179,6 @@ bool ObjCARCOpt::VisitInstructionBottomUp( bool ObjCARCOpt::VisitBottomUp(BasicBlock *BB, DenseMap<const BasicBlock *, BBState> &BBStates, BlotMapVector<Value *, RRInfo> &Retains) { - DEBUG(dbgs() << "\n== ObjCARCOpt::VisitBottomUp ==\n"); bool NestingDetected = false; @@ -1171,8 +1202,8 @@ bool ObjCARCOpt::VisitBottomUp(BasicBlock *BB, } } - DEBUG(llvm::dbgs() << "Before:\n" << BBStates[BB] << "\n" - << "Performing Dataflow:\n"); + DEBUG(dbgs() << "Before:\n" << BBStates[BB] << "\n" + << "Performing Dataflow:\n"); // Visit all the instructions, bottom-up. for (BasicBlock::iterator I = BB->end(), E = BB->begin(); I != E; --I) { @@ -1197,7 +1228,7 @@ bool ObjCARCOpt::VisitBottomUp(BasicBlock *BB, NestingDetected |= VisitInstructionBottomUp(II, BB, Retains, MyStates); } - DEBUG(llvm::dbgs() << "\nFinal State:\n" << BBStates[BB] << "\n"); + DEBUG(dbgs() << "\nFinal State:\n" << BBStates[BB] << "\n"); return NestingDetected; } @@ -1210,7 +1241,7 @@ ObjCARCOpt::VisitInstructionTopDown(Instruction *Inst, ARCInstKind Class = GetARCInstKind(Inst); const Value *Arg = nullptr; - DEBUG(llvm::dbgs() << " Class: " << Class << "\n"); + DEBUG(dbgs() << " Class: " << Class << "\n"); switch (Class) { case ARCInstKind::RetainBlock: @@ -1236,7 +1267,7 @@ ObjCARCOpt::VisitInstructionTopDown(Instruction *Inst, if (S.MatchWithRelease(MDKindCache, Inst)) { // If we succeed, copy S's RRInfo into the Release -> {Retain Set // Map}. Then we clear S. - DEBUG(llvm::dbgs() << " Matching with: " << *Inst << "\n"); + DEBUG(dbgs() << " Matching with: " << *Inst << "\n"); Releases[Inst] = S.GetRRInfo(); S.ClearSequenceProgress(); } @@ -1298,8 +1329,8 @@ ObjCARCOpt::VisitTopDown(BasicBlock *BB, } } - DEBUG(llvm::dbgs() << "Before:\n" << BBStates[BB] << "\n" - << "Performing Dataflow:\n"); + DEBUG(dbgs() << "Before:\n" << BBStates[BB] << "\n" + << "Performing Dataflow:\n"); // Visit all the instructions, top-down. for (Instruction &Inst : *BB) { @@ -1308,10 +1339,10 @@ ObjCARCOpt::VisitTopDown(BasicBlock *BB, NestingDetected |= VisitInstructionTopDown(&Inst, Releases, MyStates); } - DEBUG(llvm::dbgs() << "\nState Before Checking for CFG Hazards:\n" - << BBStates[BB] << "\n\n"); + DEBUG(dbgs() << "\nState Before Checking for CFG Hazards:\n" + << BBStates[BB] << "\n\n"); CheckForCFGHazards(BB, BBStates, MyStates); - DEBUG(llvm::dbgs() << "Final State:\n" << BBStates[BB] << "\n"); + DEBUG(dbgs() << "Final State:\n" << BBStates[BB] << "\n"); return NestingDetected; } @@ -1400,7 +1431,6 @@ bool ObjCARCOpt::Visit(Function &F, DenseMap<const BasicBlock *, BBState> &BBStates, BlotMapVector<Value *, RRInfo> &Retains, DenseMap<Value *, RRInfo> &Releases) { - // Use reverse-postorder traversals, because we magically know that loops // will be well behaved, i.e. they won't repeatedly call retain on a single // pointer without doing a release. We can't use the ReversePostOrderTraversal @@ -1414,12 +1444,12 @@ bool ObjCARCOpt::Visit(Function &F, // Use reverse-postorder on the reverse CFG for bottom-up. bool BottomUpNestingDetected = false; - for (BasicBlock *BB : reverse(ReverseCFGPostOrder)) + for (BasicBlock *BB : llvm::reverse(ReverseCFGPostOrder)) BottomUpNestingDetected |= VisitBottomUp(BB, BBStates, Retains); // Use reverse-postorder for top-down. bool TopDownNestingDetected = false; - for (BasicBlock *BB : reverse(PostOrder)) + for (BasicBlock *BB : llvm::reverse(PostOrder)) TopDownNestingDetected |= VisitTopDown(BB, BBStates, Releases); return TopDownNestingDetected && BottomUpNestingDetected; @@ -1476,7 +1506,6 @@ void ObjCARCOpt::MoveCalls(Value *Arg, RRInfo &RetainsToMove, DeadInsts.push_back(OrigRelease); DEBUG(dbgs() << "Deleting release: " << *OrigRelease << "\n"); } - } bool ObjCARCOpt::PairUpRetainsAndReleases( @@ -1524,7 +1553,6 @@ bool ObjCARCOpt::PairUpRetainsAndReleases( return false; if (ReleasesToMove.Calls.insert(NewRetainRelease).second) { - // If we overflow when we compute the path count, don't remove/move // anything. const BBState &NRRBBState = BBStates[NewRetainRelease->getParent()]; @@ -1651,8 +1679,9 @@ bool ObjCARCOpt::PairUpRetainsAndReleases( // At this point, we are not going to remove any RR pairs, but we still are // able to move RR pairs. If one of our pointers is afflicted with // CFGHazards, we cannot perform such code motion so exit early. - const bool WillPerformCodeMotion = RetainsToMove.ReverseInsertPts.size() || - ReleasesToMove.ReverseInsertPts.size(); + const bool WillPerformCodeMotion = + !RetainsToMove.ReverseInsertPts.empty() || + !ReleasesToMove.ReverseInsertPts.empty(); if (CFGHazardAfflicted && WillPerformCodeMotion) return false; } @@ -2064,10 +2093,10 @@ void ObjCARCOpt::OptimizeReturns(Function &F) { #ifndef NDEBUG void ObjCARCOpt::GatherStatistics(Function &F, bool AfterOptimization) { - llvm::Statistic &NumRetains = - AfterOptimization? NumRetainsAfterOpt : NumRetainsBeforeOpt; - llvm::Statistic &NumReleases = - AfterOptimization? NumReleasesAfterOpt : NumReleasesBeforeOpt; + Statistic &NumRetains = + AfterOptimization ? NumRetainsAfterOpt : NumRetainsBeforeOpt; + Statistic &NumReleases = + AfterOptimization ? NumReleasesAfterOpt : NumReleasesBeforeOpt; for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ) { Instruction *Inst = &*I++; diff --git a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp index 62fc52f6d09..f89fc8eb62a 100644 --- a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp +++ b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp @@ -6,6 +6,7 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// /// \file /// /// This file defines a special form of Alias Analysis called ``Provenance @@ -19,13 +20,21 @@ /// WARNING: This file knows about how certain Objective-C library functions are /// used. Naive LLVM IR transformations which would otherwise be /// behavior-preserving may break these assumptions. -/// +// //===----------------------------------------------------------------------===// #include "ProvenanceAnalysis.h" -#include "ObjCARC.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/ObjCARCAnalysisUtils.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/Use.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include <utility> using namespace llvm; using namespace llvm::objcarc; diff --git a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h index 1a12b659e5a..5e676167a6a 100644 --- a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h +++ b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.h @@ -1,4 +1,4 @@ -//===- ProvenanceAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===// +//===- ProvenanceAnalysis.h - ObjC ARC Optimization -------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -6,6 +6,7 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// /// \file /// /// This file declares a special form of Alias Analysis called ``Provenance @@ -19,7 +20,7 @@ /// WARNING: This file knows about how certain Objective-C library functions are /// used. Naive LLVM IR transformations which would otherwise be /// behavior-preserving may break these assumptions. -/// +// //===----------------------------------------------------------------------===// #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H @@ -27,15 +28,15 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/Analysis/AliasAnalysis.h" +#include <utility> namespace llvm { - class Value; - class DataLayout; - class PHINode; - class SelectInst; -} -namespace llvm { +class DataLayout; +class PHINode; +class SelectInst; +class Value; + namespace objcarc { /// \brief This is similar to BasicAliasAnalysis, and it uses many of the same @@ -50,19 +51,19 @@ namespace objcarc { class ProvenanceAnalysis { AliasAnalysis *AA; - typedef std::pair<const Value *, const Value *> ValuePairTy; - typedef DenseMap<ValuePairTy, bool> CachedResultsTy; + using ValuePairTy = std::pair<const Value *, const Value *>; + using CachedResultsTy = DenseMap<ValuePairTy, bool>; + CachedResultsTy CachedResults; bool relatedCheck(const Value *A, const Value *B, const DataLayout &DL); bool relatedSelect(const SelectInst *A, const Value *B); bool relatedPHI(const PHINode *A, const Value *B); - void operator=(const ProvenanceAnalysis &) = delete; - ProvenanceAnalysis(const ProvenanceAnalysis &) = delete; - public: - ProvenanceAnalysis() {} + ProvenanceAnalysis() = default; + ProvenanceAnalysis(const ProvenanceAnalysis &) = delete; + ProvenanceAnalysis &operator=(const ProvenanceAnalysis &) = delete; void setAA(AliasAnalysis *aa) { AA = aa; } @@ -76,6 +77,7 @@ public: }; } // end namespace objcarc + } // end namespace llvm -#endif +#endif // LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H diff --git a/llvm/lib/Transforms/ObjCARC/PtrState.cpp b/llvm/lib/Transforms/ObjCARC/PtrState.cpp index c512ff584a1..e1774b88fd3 100644 --- a/llvm/lib/Transforms/ObjCARC/PtrState.cpp +++ b/llvm/lib/Transforms/ObjCARC/PtrState.cpp @@ -1,4 +1,4 @@ -//===--- PtrState.cpp -----------------------------------------------------===// +//===- PtrState.cpp -------------------------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -10,8 +10,20 @@ #include "PtrState.h" #include "DependencyAnalysis.h" #include "ObjCARC.h" +#include "llvm/Analysis/ObjCARCAnalysisUtils.h" +#include "llvm/Analysis/ObjCARCInstKind.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" +#include <cassert> +#include <iterator> +#include <utility> using namespace llvm; using namespace llvm::objcarc; diff --git a/llvm/lib/Transforms/ObjCARC/PtrState.h b/llvm/lib/Transforms/ObjCARC/PtrState.h index 87298fa59bf..e1e95afcf76 100644 --- a/llvm/lib/Transforms/ObjCARC/PtrState.h +++ b/llvm/lib/Transforms/ObjCARC/PtrState.h @@ -1,4 +1,4 @@ -//===--- PtrState.h - ARC State for a Ptr -------------------*- C++ -*-----===// +//===- PtrState.h - ARC State for a Ptr -------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -19,12 +19,16 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Analysis/ObjCARCInstKind.h" -#include "llvm/IR/Instruction.h" -#include "llvm/IR/Value.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Compiler.h" namespace llvm { + +class BasicBlock; +class Instruction; +class MDNode; +class raw_ostream; +class Value; + namespace objcarc { class ARCMDKindCache; @@ -63,14 +67,14 @@ struct RRInfo { /// of any intervening side effects. /// /// KnownSafe is true when either of these conditions is satisfied. - bool KnownSafe; + bool KnownSafe = false; /// True of the objc_release calls are all marked with the "tail" keyword. - bool IsTailCallRelease; + bool IsTailCallRelease = false; /// If the Calls are objc_release calls and they all have a /// clang.imprecise_release tag, this is the metadata tag. - MDNode *ReleaseMetadata; + MDNode *ReleaseMetadata = nullptr; /// For a top-down sequence, the set of objc_retains or /// objc_retainBlocks. For bottom-up, the set of objc_releases. @@ -82,11 +86,9 @@ struct RRInfo { /// If this is true, we cannot perform code motion but can still remove /// retain/release pairs. - bool CFGHazardAfflicted; + bool CFGHazardAfflicted = false; - RRInfo() - : KnownSafe(false), IsTailCallRelease(false), ReleaseMetadata(nullptr), - CFGHazardAfflicted(false) {} + RRInfo() = default; void clear(); @@ -100,11 +102,11 @@ struct RRInfo { class PtrState { protected: /// True if the reference count is known to be incremented. - bool KnownPositiveRefCount; + bool KnownPositiveRefCount = false; /// True if we've seen an opportunity for partial RR elimination, such as /// pushing calls into a CFG triangle or into one side of a CFG diamond. - bool Partial; + bool Partial = false; /// The current position in the sequence. unsigned char Seq : 8; @@ -112,7 +114,7 @@ protected: /// Unidirectional information about the current sequence. RRInfo RRI; - PtrState() : KnownPositiveRefCount(false), Partial(false), Seq(S_None) {} + PtrState() : Seq(S_None) {} public: bool IsKnownSafe() const { return RRI.KnownSafe; } @@ -165,7 +167,7 @@ public: }; struct BottomUpPtrState : PtrState { - BottomUpPtrState() : PtrState() {} + BottomUpPtrState() = default; /// (Re-)Initialize this bottom up pointer returning true if we detected a /// pointer with nested releases. @@ -186,7 +188,7 @@ struct BottomUpPtrState : PtrState { }; struct TopDownPtrState : PtrState { - TopDownPtrState() : PtrState() {} + TopDownPtrState() = default; /// (Re-)Initialize this bottom up pointer returning true if we detected a /// pointer with nested releases. @@ -205,6 +207,7 @@ struct TopDownPtrState : PtrState { }; } // end namespace objcarc + } // end namespace llvm -#endif +#endif // LLVM_LIB_TRANSFORMS_OBJCARC_PTRSTATE_H |