diff --git a/include/llvm/Analysis/AliasAnalysis.h b/include/llvm/Analysis/AliasAnalysis.h index f79931c8402..41bb03cac07 100644 --- a/include/llvm/Analysis/AliasAnalysis.h +++ b/include/llvm/Analysis/AliasAnalysis.h @@ -38,25 +38,30 @@ #ifndef LLVM_ANALYSIS_ALIASANALYSIS_H #define LLVM_ANALYSIS_ALIASANALYSIS_H +#include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/MemoryLocation.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/IR/CallSite.h" -#include "llvm/IR/Metadata.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/PassManager.h" +#include "llvm/Pass.h" +#include +#include +#include +#include namespace llvm { -class BasicAAResult; -class LoadInst; -class StoreInst; -class VAArgInst; -class DataLayout; -class Pass; + class AnalysisUsage; -class MemTransferInst; -class MemIntrinsic; +class BasicAAResult; +class BasicBlock; class DominatorTree; class OrderedBasicBlock; +class Value; /// The possible results of an alias query. /// @@ -611,6 +616,7 @@ public: private: class Concept; + template class Model; template friend class AAResultBase; @@ -624,7 +630,7 @@ private: /// Temporary typedef for legacy code that uses a generic \c AliasAnalysis /// pointer or reference. -typedef AAResults AliasAnalysis; +using AliasAnalysis = AAResults; /// A private abstract base class describing the concept of an individual alias /// analysis implementation. @@ -705,7 +711,7 @@ public: explicit Model(AAResultT &Result, AAResults &AAR) : Result(Result) { Result.setAAResults(&AAR); } - ~Model() override {} + ~Model() override = default; void setAAResults(AAResults *NewAAR) override { Result.setAAResults(NewAAR); } @@ -815,7 +821,7 @@ protected: } }; - explicit AAResultBase() {} + explicit AAResultBase() = default; // Provide all the copy and move constructors so that derived types aren't // constrained. @@ -864,7 +870,6 @@ public: } }; - /// Return true if this pointer is returned by a noalias function. bool isNoAliasCall(const Value *V); @@ -901,7 +906,7 @@ bool isIdentifiedFunctionLocal(const Value *V); /// ensure the analysis itself is registered with its AnalysisManager. class AAManager : public AnalysisInfoMixin { public: - typedef AAResults Result; + using Result = AAResults; /// Register a specific AA result. template void registerFunctionAnalysis() { @@ -922,6 +927,7 @@ public: private: friend AnalysisInfoMixin; + static AnalysisKey Key; SmallVector +#include +#include +#include namespace llvm { + +struct AAMDNodes; +class APInt; class AssumptionCache; +class BasicBlock; +class DataLayout; class DominatorTree; +class Function; +class GEPOperator; class LoopInfo; +class PHINode; +class SelectInst; +class TargetLibraryInfo; +class Value; /// This is the AA result object for the basic, local, and stateless alias /// analysis. It implements the AA query interface in an entirely stateless @@ -86,7 +100,6 @@ private: // A linear transformation of a Value; this class represents ZExt(SExt(V, // SExtBits), ZExtBits) * Scale + Offset. struct VariableGEPIndex { - // An opaque Value - we can't decompose this further. const Value *V; @@ -124,8 +137,8 @@ private: }; /// Track alias queries to guard against recursion. - typedef std::pair LocPair; - typedef SmallDenseMap AliasCacheTy; + using LocPair = std::pair; + using AliasCacheTy = SmallDenseMap; AliasCacheTy AliasCache; /// Tracks phi nodes we have visited. @@ -201,10 +214,11 @@ private: /// Analysis pass providing a never-invalidated alias analysis result. class BasicAA : public AnalysisInfoMixin { friend AnalysisInfoMixin; + static AnalysisKey Key; public: - typedef BasicAAResult Result; + using Result = BasicAAResult; BasicAAResult run(Function &F, FunctionAnalysisManager &AM); }; @@ -251,6 +265,6 @@ public: } }; -} +} // end namespace llvm -#endif +#endif // LLVM_ANALYSIS_BASICALIASANALYSIS_H diff --git a/include/llvm/Analysis/CFLAndersAliasAnalysis.h b/include/llvm/Analysis/CFLAndersAliasAnalysis.h index 4146ad4d18a..6239d530958 100644 --- a/include/llvm/Analysis/CFLAndersAliasAnalysis.h +++ b/include/llvm/Analysis/CFLAndersAliasAnalysis.h @@ -1,4 +1,4 @@ -//=- CFLAndersAliasAnalysis.h - Unification-based Alias Analysis ---*- C++-*-=// +//==- CFLAndersAliasAnalysis.h - Unification-based Alias Analysis -*- C++-*-==// // // The LLVM Compiler Infrastructure // @@ -19,25 +19,31 @@ #include "llvm/ADT/Optional.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CFLAliasAnalysisUtils.h" -#include "llvm/IR/Function.h" +#include "llvm/IR/PassManager.h" #include "llvm/Pass.h" #include +#include namespace llvm { +class Function; +class MemoryLocation; class TargetLibraryInfo; namespace cflaa { + struct AliasSummary; -} + +} // end namespace cflaa class CFLAndersAAResult : public AAResultBase { friend AAResultBase; + class FunctionInfo; public: - explicit CFLAndersAAResult(const TargetLibraryInfo &); - CFLAndersAAResult(CFLAndersAAResult &&); + explicit CFLAndersAAResult(const TargetLibraryInfo &TLI); + CFLAndersAAResult(CFLAndersAAResult &&RHS); ~CFLAndersAAResult(); /// Handle invalidation events from the new pass manager. @@ -46,6 +52,7 @@ public: FunctionAnalysisManager::Invalidator &) { return false; } + /// Evict the given function from cache void evict(const Function *Fn); @@ -85,10 +92,11 @@ private: /// in particular to leverage invalidation to trigger re-computation. class CFLAndersAA : public AnalysisInfoMixin { friend AnalysisInfoMixin; + static AnalysisKey Key; public: - typedef CFLAndersAAResult Result; + using Result = CFLAndersAAResult; CFLAndersAAResult run(Function &F, FunctionAnalysisManager &AM); }; @@ -109,12 +117,10 @@ public: void getAnalysisUsage(AnalysisUsage &AU) const override; }; -//===--------------------------------------------------------------------===// -// // createCFLAndersAAWrapperPass - This pass implements a set-based approach to // alias analysis. -// ImmutablePass *createCFLAndersAAWrapperPass(); -} -#endif +} // end namespace llvm + +#endif // LLVM_ANALYSIS_CFLANDERSALIASANALYSIS_H diff --git a/include/llvm/Analysis/CFLSteensAliasAnalysis.h b/include/llvm/Analysis/CFLSteensAliasAnalysis.h index 03ce85aa97b..ee9e29046af 100644 --- a/include/llvm/Analysis/CFLSteensAliasAnalysis.h +++ b/include/llvm/Analysis/CFLSteensAliasAnalysis.h @@ -1,4 +1,4 @@ -//=- CFLSteensAliasAnalysis.h - Unification-based Alias Analysis ---*- C++-*-=// +//==- CFLSteensAliasAnalysis.h - Unification-based Alias Analysis -*- C++-*-==// // // The LLVM Compiler Infrastructure // @@ -16,30 +16,34 @@ #define LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CFLAliasAnalysisUtils.h" -#include "llvm/IR/Function.h" -#include "llvm/IR/Module.h" -#include "llvm/IR/ValueHandle.h" +#include "llvm/Analysis/MemoryLocation.h" +#include "llvm/IR/PassManager.h" #include "llvm/Pass.h" +#include "llvm/Support/Casting.h" #include +#include namespace llvm { +class Function; class TargetLibraryInfo; namespace cflaa { + struct AliasSummary; -} + +} // end namespace cflaa class CFLSteensAAResult : public AAResultBase { friend AAResultBase; + class FunctionInfo; public: - explicit CFLSteensAAResult(const TargetLibraryInfo &); + explicit CFLSteensAAResult(const TargetLibraryInfo &TLI); CFLSteensAAResult(CFLSteensAAResult &&Arg); ~CFLSteensAAResult(); @@ -105,10 +109,11 @@ private: /// in particular to leverage invalidation to trigger re-computation of sets. class CFLSteensAA : public AnalysisInfoMixin { friend AnalysisInfoMixin; + static AnalysisKey Key; public: - typedef CFLSteensAAResult Result; + using Result = CFLSteensAAResult; CFLSteensAAResult run(Function &F, FunctionAnalysisManager &AM); }; @@ -129,12 +134,10 @@ public: void getAnalysisUsage(AnalysisUsage &AU) const override; }; -//===--------------------------------------------------------------------===// -// // createCFLSteensAAWrapperPass - This pass implements a set-based approach to // alias analysis. -// ImmutablePass *createCFLSteensAAWrapperPass(); -} -#endif +} // end namespace llvm + +#endif // LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H diff --git a/include/llvm/Analysis/LazyCallGraph.h b/include/llvm/Analysis/LazyCallGraph.h index b129fd0f616..d1ec6a9dcc5 100644 --- a/include/llvm/Analysis/LazyCallGraph.h +++ b/include/llvm/Analysis/LazyCallGraph.h @@ -35,28 +35,33 @@ #ifndef LLVM_ANALYSIS_LAZYCALLGRAPH_H #define LLVM_ANALYSIS_LAZYCALLGRAPH_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/PointerUnion.h" -#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Analysis/TargetLibraryInfo.h" -#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" -#include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/raw_ostream.h" +#include #include +#include #include namespace llvm { -class PreservedAnalyses; -class raw_ostream; + +class Module; +class Value; /// A lazily constructed view of the call graph of a module. /// @@ -183,8 +188,8 @@ public: friend class LazyCallGraph::Node; friend class LazyCallGraph::RefSCC; - typedef SmallVector VectorT; - typedef SmallVectorImpl VectorImplT; + using VectorT = SmallVector; + using VectorImplT = SmallVectorImpl; public: /// An iterator used for the edges to both entry nodes and child nodes. @@ -204,7 +209,7 @@ public: } public: - iterator() {} + iterator() = default; using iterator_adaptor_base::operator++; iterator &operator++() { @@ -240,7 +245,7 @@ public: } public: - call_iterator() {} + call_iterator() = default; using iterator_adaptor_base::operator++; call_iterator &operator++() { @@ -260,6 +265,7 @@ public: assert(E && "Dead or null edge!"); return E; } + Edge *lookup(Node &N) { auto EI = EdgeIndexMap.find(&N); if (EI == EdgeIndexMap.end()) @@ -381,15 +387,14 @@ public: // We provide for the DFS numbering and Tarjan walk lowlink numbers to be // stored directly within the node. These are both '-1' when nodes are part // of an SCC (or RefSCC), or '0' when not yet reached in a DFS walk. - int DFSNumber; - int LowLink; + int DFSNumber = 0; + int LowLink = 0; Optional Edges; /// Basic constructor implements the scanning of F into Edges and /// EdgeIndexMap. - Node(LazyCallGraph &G, Function &F) - : G(&G), F(&F), DFSNumber(0), LowLink(0) {} + Node(LazyCallGraph &G, Function &F) : G(&G), F(&F) {} /// Implementation of the scan when populating. EdgeSequence &populateSlow(); @@ -478,7 +483,7 @@ public: #endif public: - typedef pointee_iterator::const_iterator> iterator; + using iterator = pointee_iterator::const_iterator>; iterator begin() const { return Nodes.begin(); } iterator end() const { return Nodes.end(); } @@ -606,10 +611,10 @@ public: void handleTrivialEdgeInsertion(Node &SourceN, Node &TargetN); public: - typedef pointee_iterator::const_iterator> iterator; - typedef iterator_range range; - typedef pointee_iterator::const_iterator> - parent_iterator; + using iterator = pointee_iterator::const_iterator>; + using range = iterator_range; + using parent_iterator = + pointee_iterator::const_iterator>; iterator begin() const { return SCCs.begin(); } iterator end() const { return SCCs.end(); } @@ -888,14 +893,13 @@ public: struct IsAtEndT {}; LazyCallGraph *G; - RefSCC *RC; + RefSCC *RC = nullptr; /// Build the begin iterator for a node. postorder_ref_scc_iterator(LazyCallGraph &G) : G(&G), RC(getRC(G, 0)) {} /// Build the end iterator for a node. This is selected purely by overload. - postorder_ref_scc_iterator(LazyCallGraph &G, IsAtEndT /*Nonce*/) - : G(&G), RC(nullptr) {} + postorder_ref_scc_iterator(LazyCallGraph &G, IsAtEndT /*Nonce*/) : G(&G) {} /// Get the post-order RefSCC at the given index of the postorder walk, /// populating it if necessary. @@ -1097,8 +1101,8 @@ public: ///@} private: - typedef SmallVectorImpl::reverse_iterator node_stack_iterator; - typedef iterator_range node_stack_range; + using node_stack_iterator = SmallVectorImpl::reverse_iterator; + using node_stack_range = iterator_range; /// Allocator that holds all the call graph nodes. SpecificBumpPtrAllocator BPA; @@ -1218,16 +1222,16 @@ inline Function &LazyCallGraph::Edge::getFunction() const { // Provide GraphTraits specializations for call graphs. template <> struct GraphTraits { - typedef LazyCallGraph::Node *NodeRef; - typedef LazyCallGraph::EdgeSequence::iterator ChildIteratorType; + using NodeRef = LazyCallGraph::Node *; + using ChildIteratorType = LazyCallGraph::EdgeSequence::iterator; static NodeRef getEntryNode(NodeRef N) { return N; } static ChildIteratorType child_begin(NodeRef N) { return (*N)->begin(); } static ChildIteratorType child_end(NodeRef N) { return (*N)->end(); } }; template <> struct GraphTraits { - typedef LazyCallGraph::Node *NodeRef; - typedef LazyCallGraph::EdgeSequence::iterator ChildIteratorType; + using NodeRef = LazyCallGraph::Node *; + using ChildIteratorType = LazyCallGraph::EdgeSequence::iterator; static NodeRef getEntryNode(NodeRef N) { return N; } static ChildIteratorType child_begin(NodeRef N) { return (*N)->begin(); } @@ -1237,11 +1241,12 @@ template <> struct GraphTraits { /// An analysis pass which computes the call graph for a module. class LazyCallGraphAnalysis : public AnalysisInfoMixin { friend AnalysisInfoMixin; + static AnalysisKey Key; public: /// Inform generic clients of the result type. - typedef LazyCallGraph Result; + using Result = LazyCallGraph; /// Compute the \c LazyCallGraph for the module \c M. /// @@ -1277,6 +1282,7 @@ public: PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); }; -} -#endif +} // end namespace llvm + +#endif // LLVM_ANALYSIS_LAZYCALLGRAPH_H diff --git a/lib/Analysis/AliasAnalysis.cpp b/lib/Analysis/AliasAnalysis.cpp index 4c29aeaa622..897f89d3114 100644 --- a/lib/Analysis/AliasAnalysis.cpp +++ b/lib/Analysis/AliasAnalysis.cpp @@ -1,4 +1,4 @@ -//===- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation -==// +//==- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation --==// // // The LLVM Compiler Infrastructure // @@ -26,26 +26,35 @@ #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/BasicAliasAnalysis.h" -#include "llvm/Analysis/CFG.h" #include "llvm/Analysis/CFLAndersAliasAnalysis.h" #include "llvm/Analysis/CFLSteensAliasAnalysis.h" #include "llvm/Analysis/CaptureTracking.h" #include "llvm/Analysis/GlobalsModRef.h" +#include "llvm/Analysis/MemoryLocation.h" #include "llvm/Analysis/ObjCARCAliasAnalysis.h" #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" #include "llvm/Analysis/ScopedNoAliasAA.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TypeBasedAliasAnalysis.h" #include "llvm/Analysis/ValueTracking.h" +#include "llvm/IR/Argument.h" +#include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" -#include "llvm/IR/DataLayout.h" -#include "llvm/IR/Dominators.h" -#include "llvm/IR/Function.h" +#include "llvm/IR/CallSite.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" -#include "llvm/IR/IntrinsicInst.h" -#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/IR/Type.h" +#include "llvm/IR/Value.h" #include "llvm/Pass.h" +#include "llvm/Support/AtomicOrdering.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include +#include +#include +#include + using namespace llvm; /// Allow disabling BasicAA from the AA results. This is particularly useful @@ -377,7 +386,6 @@ ModRefInfo AAResults::getModRefInfo(const FenceInst *S, const MemoryLocation &Lo ModRefInfo AAResults::getModRefInfo(const VAArgInst *V, const MemoryLocation &Loc) { - if (Loc.Ptr) { // If the va_arg address cannot alias the pointer in question, then the // specified memory cannot be accessed by the va_arg. @@ -471,10 +479,10 @@ ModRefInfo AAResults::callCapturesBefore(const Instruction *I, if (!CS.getInstruction() || CS.getInstruction() == Object) return MRI_ModRef; - if (llvm::PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true, - /* StoreCaptures */ true, I, DT, - /* include Object */ true, - /* OrderedBasicBlock */ OBB)) + if (PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true, + /* StoreCaptures */ true, I, DT, + /* include Object */ true, + /* OrderedBasicBlock */ OBB)) return MRI_ModRef; unsigned ArgNo = 0; @@ -536,16 +544,17 @@ bool AAResults::canInstructionRangeModRef(const Instruction &I1, } // Provide a definition for the root virtual destructor. -AAResults::Concept::~Concept() {} +AAResults::Concept::~Concept() = default; // Provide a definition for the static object used to identify passes. AnalysisKey AAManager::Key; namespace { + /// A wrapper pass for external alias analyses. This just squirrels away the /// callback used to run any analyses and register their results. struct ExternalAAWrapperPass : ImmutablePass { - typedef std::function CallbackT; + using CallbackT = std::function; CallbackT CB; @@ -554,6 +563,7 @@ struct ExternalAAWrapperPass : ImmutablePass { ExternalAAWrapperPass() : ImmutablePass(ID) { initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry()); } + explicit ExternalAAWrapperPass(CallbackT CB) : ImmutablePass(ID), CB(std::move(CB)) { initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry()); @@ -563,9 +573,11 @@ struct ExternalAAWrapperPass : ImmutablePass { AU.setPreservesAll(); } }; -} + +} // end anonymous namespace char ExternalAAWrapperPass::ID = 0; + INITIALIZE_PASS(ExternalAAWrapperPass, "external-aa", "External Alias Analysis", false, true) diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index 180e5f4a644..84eb7699a0f 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -14,6 +14,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/BasicAliasAnalysis.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" @@ -23,21 +25,40 @@ #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/MemoryBuiltins.h" +#include "llvm/Analysis/MemoryLocation.h" +#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" +#include "llvm/IR/Argument.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/CallSite.h" +#include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Dominators.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GetElementPtrTypeIterator.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" -#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Intrinsics.h" +#include "llvm/IR/Metadata.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" #include "llvm/Pass.h" -#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/KnownBits.h" -#include +#include +#include +#include +#include #define DEBUG_TYPE "basicaa" @@ -223,7 +244,6 @@ static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL, if (const BinaryOperator *BOp = dyn_cast(V)) { if (ConstantInt *RHSC = dyn_cast(BOp->getOperand(1))) { - // If we've been called recursively, then Offset and Scale will be wider // than the BOp operands. We'll always zext it here as we'll process sign // extensions below (see the isa / isa cases). @@ -574,7 +594,6 @@ bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc, // Otherwise be conservative. Visited.clear(); return AAResultBase::pointsToConstantMemory(Loc, OrLocal); - } while (!Worklist.empty() && --MaxLookup); Visited.clear(); @@ -662,7 +681,6 @@ static bool isWriteOnlyParam(ImmutableCallSite CS, unsigned ArgIdx, ModRefInfo BasicAAResult::getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx) { - // Checking for known builtin intrinsics and target library functions. if (isWriteOnlyParam(CS, ArgIdx, TLI)) return MRI_Mod; @@ -927,7 +945,6 @@ static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1, const GEPOperator *GEP2, uint64_t V2Size, const DataLayout &DL) { - assert(GEP1->getPointerOperand()->stripPointerCastsAndBarriers() == GEP2->getPointerOperand()->stripPointerCastsAndBarriers() && GEP1->getPointerOperandType() == GEP2->getPointerOperandType() && @@ -1814,6 +1831,7 @@ BasicAAWrapperPass::BasicAAWrapperPass() : FunctionPass(ID) { } char BasicAAWrapperPass::ID = 0; + void BasicAAWrapperPass::anchor() {} INITIALIZE_PASS_BEGIN(BasicAAWrapperPass, "basicaa", diff --git a/lib/Analysis/CFLAndersAliasAnalysis.cpp b/lib/Analysis/CFLAndersAliasAnalysis.cpp index 1a3998836cf..076a2b205d0 100644 --- a/lib/Analysis/CFLAndersAliasAnalysis.cpp +++ b/lib/Analysis/CFLAndersAliasAnalysis.cpp @@ -1,4 +1,4 @@ -//- CFLAndersAliasAnalysis.cpp - Unification-based Alias Analysis ---*- C++-*-// +//===- CFLAndersAliasAnalysis.cpp - Unification-based Alias Analysis ------===// // // The LLVM Compiler Infrastructure // @@ -54,9 +54,35 @@ // FunctionPasses to run concurrently. #include "llvm/Analysis/CFLAndersAliasAnalysis.h" +#include "AliasAnalysisSummary.h" #include "CFLGraph.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/MemoryLocation.h" +#include "llvm/IR/Argument.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/PassManager.h" +#include "llvm/IR/Type.h" #include "llvm/Pass.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include +#include +#include +#include +#include using namespace llvm; using namespace llvm::cflaa; @@ -66,7 +92,7 @@ using namespace llvm::cflaa; CFLAndersAAResult::CFLAndersAAResult(const TargetLibraryInfo &TLI) : TLI(TLI) {} CFLAndersAAResult::CFLAndersAAResult(CFLAndersAAResult &&RHS) : AAResultBase(std::move(RHS)), TLI(RHS.TLI) {} -CFLAndersAAResult::~CFLAndersAAResult() {} +CFLAndersAAResult::~CFLAndersAAResult() = default; namespace { @@ -95,7 +121,8 @@ enum class MatchState : uint8_t { FlowToMemAliasReadWrite, }; -typedef std::bitset<7> StateSet; +using StateSet = std::bitset<7>; + const unsigned ReadOnlyStateMask = (1U << static_cast(MatchState::FlowFromReadOnly)) | (1U << static_cast(MatchState::FlowFromMemAliasReadOnly)); @@ -130,13 +157,14 @@ bool operator==(OffsetInstantiatedValue LHS, OffsetInstantiatedValue RHS) { // We use ReachabilitySet to keep track of value aliases (The nonterminal "V" in // the paper) during the analysis. class ReachabilitySet { - typedef DenseMap ValueStateMap; - typedef DenseMap ValueReachMap; + using ValueStateMap = DenseMap; + using ValueReachMap = DenseMap; + ValueReachMap ReachMap; public: - typedef ValueStateMap::const_iterator const_valuestate_iterator; - typedef ValueReachMap::const_iterator const_value_iterator; + using const_valuestate_iterator = ValueStateMap::const_iterator; + using const_value_iterator = ValueReachMap::const_iterator; // Insert edge 'From->To' at state 'State' bool insert(InstantiatedValue From, InstantiatedValue To, MatchState State) { @@ -169,12 +197,13 @@ public: // We use AliasMemSet to keep track of all memory aliases (the nonterminal "M" // in the paper) during the analysis. class AliasMemSet { - typedef DenseSet MemSet; - typedef DenseMap MemMapType; + using MemSet = DenseSet; + using MemMapType = DenseMap; + MemMapType MemMap; public: - typedef MemSet::const_iterator const_mem_iterator; + using const_mem_iterator = MemSet::const_iterator; bool insert(InstantiatedValue LHS, InstantiatedValue RHS) { // Top-level values can never be memory aliases because one cannot take the @@ -193,11 +222,12 @@ public: // We use AliasAttrMap to keep track of the AliasAttr of each node. class AliasAttrMap { - typedef DenseMap MapType; + using MapType = DenseMap; + MapType AttrMap; public: - typedef MapType::const_iterator const_iterator; + using const_iterator = MapType::const_iterator; bool add(InstantiatedValue V, AliasAttrs Attr) { auto &OldAttr = AttrMap[V]; @@ -234,23 +264,28 @@ struct ValueSummary { }; SmallVector FromRecords, ToRecords; }; -} + +} // end anonymous namespace namespace llvm { + // Specialize DenseMapInfo for OffsetValue. template <> struct DenseMapInfo { static OffsetValue getEmptyKey() { return OffsetValue{DenseMapInfo::getEmptyKey(), DenseMapInfo::getEmptyKey()}; } + static OffsetValue getTombstoneKey() { return OffsetValue{DenseMapInfo::getTombstoneKey(), DenseMapInfo::getEmptyKey()}; } + static unsigned getHashValue(const OffsetValue &OVal) { return DenseMapInfo>::getHashValue( std::make_pair(OVal.Val, OVal.Offset)); } + static bool isEqual(const OffsetValue &LHS, const OffsetValue &RHS) { return LHS == RHS; } @@ -263,21 +298,25 @@ template <> struct DenseMapInfo { DenseMapInfo::getEmptyKey(), DenseMapInfo::getEmptyKey()}; } + static OffsetInstantiatedValue getTombstoneKey() { return OffsetInstantiatedValue{ DenseMapInfo::getTombstoneKey(), DenseMapInfo::getEmptyKey()}; } + static unsigned getHashValue(const OffsetInstantiatedValue &OVal) { return DenseMapInfo>::getHashValue( std::make_pair(OVal.IVal, OVal.Offset)); } + static bool isEqual(const OffsetInstantiatedValue &LHS, const OffsetInstantiatedValue &RHS) { return LHS == RHS; } }; -} + +} // end namespace llvm class CFLAndersAAResult::FunctionInfo { /// Map a value to other values that may alias it @@ -654,41 +693,40 @@ static void processWorkListItem(const WorkListItem &Item, const CFLGraph &Graph, }; switch (Item.State) { - case MatchState::FlowFromReadOnly: { + case MatchState::FlowFromReadOnly: NextRevAssignState(MatchState::FlowFromReadOnly); NextAssignState(MatchState::FlowToReadWrite); NextMemState(MatchState::FlowFromMemAliasReadOnly); break; - } - case MatchState::FlowFromMemAliasNoReadWrite: { + + case MatchState::FlowFromMemAliasNoReadWrite: NextRevAssignState(MatchState::FlowFromReadOnly); NextAssignState(MatchState::FlowToWriteOnly); break; - } - case MatchState::FlowFromMemAliasReadOnly: { + + case MatchState::FlowFromMemAliasReadOnly: NextRevAssignState(MatchState::FlowFromReadOnly); NextAssignState(MatchState::FlowToReadWrite); break; - } - case MatchState::FlowToWriteOnly: { + + case MatchState::FlowToWriteOnly: NextAssignState(MatchState::FlowToWriteOnly); NextMemState(MatchState::FlowToMemAliasWriteOnly); break; - } - case MatchState::FlowToReadWrite: { + + case MatchState::FlowToReadWrite: NextAssignState(MatchState::FlowToReadWrite); NextMemState(MatchState::FlowToMemAliasReadWrite); break; - } - case MatchState::FlowToMemAliasWriteOnly: { + + case MatchState::FlowToMemAliasWriteOnly: NextAssignState(MatchState::FlowToWriteOnly); break; - } - case MatchState::FlowToMemAliasReadWrite: { + + case MatchState::FlowToMemAliasReadWrite: NextAssignState(MatchState::FlowToReadWrite); break; } - } } static AliasAttrMap buildAttrMap(const CFLGraph &Graph, diff --git a/lib/Analysis/CFLGraph.h b/lib/Analysis/CFLGraph.h index 95874b88244..e4e92864061 100644 --- a/lib/Analysis/CFLGraph.h +++ b/lib/Analysis/CFLGraph.h @@ -1,4 +1,4 @@ -//======- CFLGraph.h - Abstract stratified sets implementation. --------======// +//===- CFLGraph.h - Abstract stratified sets implementation. -----*- C++-*-===// // // The LLVM Compiler Infrastructure // @@ -6,19 +6,42 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +// /// \file /// This file defines CFLGraph, an auxiliary data structure used by CFL-based /// alias analysis. -/// +// //===----------------------------------------------------------------------===// -#ifndef LLVM_ANALYSIS_CFLGRAPH_H -#define LLVM_ANALYSIS_CFLGRAPH_H +#ifndef LLVM_LIB_ANALYSIS_CFLGRAPH_H +#define LLVM_LIB_ANALYSIS_CFLGRAPH_H #include "AliasAnalysisSummary.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Analysis/MemoryBuiltins.h" +#include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/IR/Argument.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/CallSite.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalValue.h" #include "llvm/IR/InstVisitor.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/Operator.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Value.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include +#include +#include namespace llvm { namespace cflaa { @@ -35,14 +58,14 @@ namespace cflaa { /// I+1) and a reference edge to (X, I-1). class CFLGraph { public: - typedef InstantiatedValue Node; + using Node = InstantiatedValue; struct Edge { Node Other; int64_t Offset; }; - typedef std::vector EdgeList; + using EdgeList = std::vector; struct NodeInfo { EdgeList Edges, ReverseEdges; @@ -74,7 +97,8 @@ public: }; private: - typedef DenseMap ValueMap; + using ValueMap = DenseMap; + ValueMap ValueImpls; NodeInfo *getNode(Node N) { @@ -85,7 +109,7 @@ private: } public: - typedef ValueMap::const_iterator const_value_iterator; + using const_value_iterator = ValueMap::const_iterator; bool addNode(Node N, AliasAttrs Attr = AliasAttrs()) { assert(N.Val != nullptr); @@ -496,10 +520,10 @@ template class CFLGraphBuilder { addNode(Ptr, getAttrEscaped()); break; } - case Instruction::IntToPtr: { + case Instruction::IntToPtr: addNode(CE, getAttrUnknown()); break; - } + case Instruction::BitCast: case Instruction::AddrSpaceCast: case Instruction::Trunc: @@ -571,11 +595,11 @@ template class CFLGraphBuilder { case Instruction::LShr: case Instruction::AShr: case Instruction::ICmp: - case Instruction::FCmp: { + case Instruction::FCmp: addAssignEdge(CE->getOperand(0), CE); addAssignEdge(CE->getOperand(1), CE); break; - } + default: llvm_unreachable("Unknown instruction type encountered!"); } @@ -640,7 +664,8 @@ public: return ReturnedValues; } }; -} -} -#endif +} // end namespace cflaa +} // end namespace llvm + +#endif // LLVM_LIB_ANALYSIS_CFLGRAPH_H diff --git a/lib/Analysis/CFLSteensAliasAnalysis.cpp b/lib/Analysis/CFLSteensAliasAnalysis.cpp index adbdd82012a..eee6d26ba78 100644 --- a/lib/Analysis/CFLSteensAliasAnalysis.cpp +++ b/lib/Analysis/CFLSteensAliasAnalysis.cpp @@ -1,4 +1,4 @@ -//- CFLSteensAliasAnalysis.cpp - Unification-based Alias Analysis ---*- C++-*-// +//===- CFLSteensAliasAnalysis.cpp - Unification-based Alias Analysis ------===// // // The LLVM Compiler Infrastructure // @@ -36,23 +36,25 @@ // FunctionPasses to run concurrently. #include "llvm/Analysis/CFLSteensAliasAnalysis.h" +#include "AliasAnalysisSummary.h" #include "CFLGraph.h" #include "StratifiedSets.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Value.h" #include "llvm/Pass.h" -#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include #include +#include #include -#include +#include using namespace llvm; using namespace llvm::cflaa; @@ -63,7 +65,7 @@ CFLSteensAAResult::CFLSteensAAResult(const TargetLibraryInfo &TLI) : AAResultBase(), TLI(TLI) {} CFLSteensAAResult::CFLSteensAAResult(CFLSteensAAResult &&Arg) : AAResultBase(std::move(Arg)), TLI(Arg.TLI) {} -CFLSteensAAResult::~CFLSteensAAResult() {} +CFLSteensAAResult::~CFLSteensAAResult() = default; /// Information we have about a function and would like to keep around. class CFLSteensAAResult::FunctionInfo { @@ -77,6 +79,7 @@ public: const StratifiedSets &getStratifiedSets() const { return Sets; } + const AliasSummary &getAliasSummary() const { return Summary; } }; diff --git a/lib/Analysis/LazyCallGraph.cpp b/lib/Analysis/LazyCallGraph.cpp index 5aeea9ef1f7..54299d078be 100644 --- a/lib/Analysis/LazyCallGraph.cpp +++ b/lib/Analysis/LazyCallGraph.cpp @@ -8,15 +8,31 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/LazyCallGraph.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/Sequence.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/IR/CallSite.h" -#include "llvm/IR/InstVisitor.h" -#include "llvm/IR/Instructions.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/GraphWriter.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include +#include +#include #include using namespace llvm; @@ -1339,10 +1355,8 @@ void LazyCallGraph::RefSCC::handleTrivialEdgeInsertion(Node &SourceN, // after this edge insertion. assert(G->lookupRefSCC(SourceN) == this && "Source must be in this RefSCC."); RefSCC &TargetRC = *G->lookupRefSCC(TargetN); - if (&TargetRC == this) { - + if (&TargetRC == this) return; - } #ifdef EXPENSIVE_CHECKS assert(TargetRC.isDescendantOf(*this) && @@ -1544,7 +1558,7 @@ template ())) EdgeItT; + using EdgeItT = decltype(GetBegin(std::declval())); SmallVector, 16> DFSStack; SmallVector PendingSCCStack;