[Analysis] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes (NFC).

llvm-svn: 310766
This commit is contained in:
Eugene Zelenko
2017-08-11 21:30:02 +00:00
parent 0499212ebf
commit 530851c2bc
11 changed files with 306 additions and 161 deletions

View File

@@ -38,25 +38,30 @@
#ifndef LLVM_ANALYSIS_ALIASANALYSIS_H #ifndef LLVM_ANALYSIS_ALIASANALYSIS_H
#define LLVM_ANALYSIS_ALIASANALYSIS_H #define LLVM_ANALYSIS_ALIASANALYSIS_H
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h" #include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/MemoryLocation.h" #include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/CallSite.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/IR/PassManager.h"
#include "llvm/Pass.h"
#include <cstdint>
#include <functional>
#include <memory>
#include <vector>
namespace llvm { namespace llvm {
class BasicAAResult;
class LoadInst;
class StoreInst;
class VAArgInst;
class DataLayout;
class Pass;
class AnalysisUsage; class AnalysisUsage;
class MemTransferInst; class BasicAAResult;
class MemIntrinsic; class BasicBlock;
class DominatorTree; class DominatorTree;
class OrderedBasicBlock; class OrderedBasicBlock;
class Value;
/// The possible results of an alias query. /// The possible results of an alias query.
/// ///
@@ -611,6 +616,7 @@ public:
private: private:
class Concept; class Concept;
template <typename T> class Model; template <typename T> class Model;
template <typename T> friend class AAResultBase; template <typename T> friend class AAResultBase;
@@ -624,7 +630,7 @@ private:
/// Temporary typedef for legacy code that uses a generic \c AliasAnalysis /// Temporary typedef for legacy code that uses a generic \c AliasAnalysis
/// pointer or reference. /// pointer or reference.
typedef AAResults AliasAnalysis; using AliasAnalysis = AAResults;
/// A private abstract base class describing the concept of an individual alias /// A private abstract base class describing the concept of an individual alias
/// analysis implementation. /// analysis implementation.
@@ -705,7 +711,7 @@ public:
explicit Model(AAResultT &Result, AAResults &AAR) : Result(Result) { explicit Model(AAResultT &Result, AAResults &AAR) : Result(Result) {
Result.setAAResults(&AAR); Result.setAAResults(&AAR);
} }
~Model() override {} ~Model() override = default;
void setAAResults(AAResults *NewAAR) override { Result.setAAResults(NewAAR); } 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 // Provide all the copy and move constructors so that derived types aren't
// constrained. // constrained.
@@ -864,7 +870,6 @@ public:
} }
}; };
/// Return true if this pointer is returned by a noalias function. /// Return true if this pointer is returned by a noalias function.
bool isNoAliasCall(const Value *V); bool isNoAliasCall(const Value *V);
@@ -901,7 +906,7 @@ bool isIdentifiedFunctionLocal(const Value *V);
/// ensure the analysis itself is registered with its AnalysisManager. /// ensure the analysis itself is registered with its AnalysisManager.
class AAManager : public AnalysisInfoMixin<AAManager> { class AAManager : public AnalysisInfoMixin<AAManager> {
public: public:
typedef AAResults Result; using Result = AAResults;
/// Register a specific AA result. /// Register a specific AA result.
template <typename AnalysisT> void registerFunctionAnalysis() { template <typename AnalysisT> void registerFunctionAnalysis() {
@@ -922,6 +927,7 @@ public:
private: private:
friend AnalysisInfoMixin<AAManager>; friend AnalysisInfoMixin<AAManager>;
static AnalysisKey Key; static AnalysisKey Key;
SmallVector<void (*)(Function &F, FunctionAnalysisManager &AM, SmallVector<void (*)(Function &F, FunctionAnalysisManager &AM,
@@ -992,6 +998,6 @@ AAResults createLegacyPMAAResults(Pass &P, Function &F, BasicAAResult &BAR);
/// sure the analyses required by \p createLegacyPMAAResults are available. /// sure the analyses required by \p createLegacyPMAAResults are available.
void getAAResultsAnalysisUsage(AnalysisUsage &AU); void getAAResultsAnalysisUsage(AnalysisUsage &AU);
} // End llvm namespace } // end namespace llvm
#endif #endif // LLVM_ANALYSIS_ALIASANALYSIS_H

View File

@@ -14,22 +14,36 @@
#ifndef LLVM_ANALYSIS_BASICALIASANALYSIS_H #ifndef LLVM_ANALYSIS_BASICALIASANALYSIS_H
#define LLVM_ANALYSIS_BASICALIASANALYSIS_H #define LLVM_ANALYSIS_BASICALIASANALYSIS_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/MemoryLocation.h"
#include "llvm/IR/Function.h" #include "llvm/IR/CallSite.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h" #include "llvm/IR/PassManager.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Pass.h"
#include <algorithm>
#include <cstdint>
#include <memory>
#include <utility>
namespace llvm { namespace llvm {
struct AAMDNodes;
class APInt;
class AssumptionCache; class AssumptionCache;
class BasicBlock;
class DataLayout;
class DominatorTree; class DominatorTree;
class Function;
class GEPOperator;
class LoopInfo; class LoopInfo;
class PHINode;
class SelectInst;
class TargetLibraryInfo;
class Value;
/// This is the AA result object for the basic, local, and stateless alias /// This is the AA result object for the basic, local, and stateless alias
/// analysis. It implements the AA query interface in an entirely stateless /// 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, // A linear transformation of a Value; this class represents ZExt(SExt(V,
// SExtBits), ZExtBits) * Scale + Offset. // SExtBits), ZExtBits) * Scale + Offset.
struct VariableGEPIndex { struct VariableGEPIndex {
// An opaque Value - we can't decompose this further. // An opaque Value - we can't decompose this further.
const Value *V; const Value *V;
@@ -124,8 +137,8 @@ private:
}; };
/// Track alias queries to guard against recursion. /// Track alias queries to guard against recursion.
typedef std::pair<MemoryLocation, MemoryLocation> LocPair; using LocPair = std::pair<MemoryLocation, MemoryLocation>;
typedef SmallDenseMap<LocPair, AliasResult, 8> AliasCacheTy; using AliasCacheTy = SmallDenseMap<LocPair, AliasResult, 8>;
AliasCacheTy AliasCache; AliasCacheTy AliasCache;
/// Tracks phi nodes we have visited. /// Tracks phi nodes we have visited.
@@ -201,10 +214,11 @@ private:
/// Analysis pass providing a never-invalidated alias analysis result. /// Analysis pass providing a never-invalidated alias analysis result.
class BasicAA : public AnalysisInfoMixin<BasicAA> { class BasicAA : public AnalysisInfoMixin<BasicAA> {
friend AnalysisInfoMixin<BasicAA>; friend AnalysisInfoMixin<BasicAA>;
static AnalysisKey Key; static AnalysisKey Key;
public: public:
typedef BasicAAResult Result; using Result = BasicAAResult;
BasicAAResult run(Function &F, FunctionAnalysisManager &AM); BasicAAResult run(Function &F, FunctionAnalysisManager &AM);
}; };
@@ -251,6 +265,6 @@ public:
} }
}; };
} } // end namespace llvm
#endif #endif // LLVM_ANALYSIS_BASICALIASANALYSIS_H

View File

@@ -1,4 +1,4 @@
//=- CFLAndersAliasAnalysis.h - Unification-based Alias Analysis ---*- C++-*-=// //==- CFLAndersAliasAnalysis.h - Unification-based Alias Analysis -*- C++-*-==//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@@ -19,25 +19,31 @@
#include "llvm/ADT/Optional.h" #include "llvm/ADT/Optional.h"
#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/CFLAliasAnalysisUtils.h" #include "llvm/Analysis/CFLAliasAnalysisUtils.h"
#include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include <forward_list> #include <forward_list>
#include <memory>
namespace llvm { namespace llvm {
class Function;
class MemoryLocation;
class TargetLibraryInfo; class TargetLibraryInfo;
namespace cflaa { namespace cflaa {
struct AliasSummary; struct AliasSummary;
}
} // end namespace cflaa
class CFLAndersAAResult : public AAResultBase<CFLAndersAAResult> { class CFLAndersAAResult : public AAResultBase<CFLAndersAAResult> {
friend AAResultBase<CFLAndersAAResult>; friend AAResultBase<CFLAndersAAResult>;
class FunctionInfo; class FunctionInfo;
public: public:
explicit CFLAndersAAResult(const TargetLibraryInfo &); explicit CFLAndersAAResult(const TargetLibraryInfo &TLI);
CFLAndersAAResult(CFLAndersAAResult &&); CFLAndersAAResult(CFLAndersAAResult &&RHS);
~CFLAndersAAResult(); ~CFLAndersAAResult();
/// Handle invalidation events from the new pass manager. /// Handle invalidation events from the new pass manager.
@@ -46,6 +52,7 @@ public:
FunctionAnalysisManager::Invalidator &) { FunctionAnalysisManager::Invalidator &) {
return false; return false;
} }
/// Evict the given function from cache /// Evict the given function from cache
void evict(const Function *Fn); void evict(const Function *Fn);
@@ -85,10 +92,11 @@ private:
/// in particular to leverage invalidation to trigger re-computation. /// in particular to leverage invalidation to trigger re-computation.
class CFLAndersAA : public AnalysisInfoMixin<CFLAndersAA> { class CFLAndersAA : public AnalysisInfoMixin<CFLAndersAA> {
friend AnalysisInfoMixin<CFLAndersAA>; friend AnalysisInfoMixin<CFLAndersAA>;
static AnalysisKey Key; static AnalysisKey Key;
public: public:
typedef CFLAndersAAResult Result; using Result = CFLAndersAAResult;
CFLAndersAAResult run(Function &F, FunctionAnalysisManager &AM); CFLAndersAAResult run(Function &F, FunctionAnalysisManager &AM);
}; };
@@ -109,12 +117,10 @@ public:
void getAnalysisUsage(AnalysisUsage &AU) const override; void getAnalysisUsage(AnalysisUsage &AU) const override;
}; };
//===--------------------------------------------------------------------===//
//
// createCFLAndersAAWrapperPass - This pass implements a set-based approach to // createCFLAndersAAWrapperPass - This pass implements a set-based approach to
// alias analysis. // alias analysis.
//
ImmutablePass *createCFLAndersAAWrapperPass(); ImmutablePass *createCFLAndersAAWrapperPass();
}
#endif } // end namespace llvm
#endif // LLVM_ANALYSIS_CFLANDERSALIASANALYSIS_H

View File

@@ -1,4 +1,4 @@
//=- CFLSteensAliasAnalysis.h - Unification-based Alias Analysis ---*- C++-*-=// //==- CFLSteensAliasAnalysis.h - Unification-based Alias Analysis -*- C++-*-==//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@@ -16,30 +16,34 @@
#define LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H #define LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h" #include "llvm/ADT/Optional.h"
#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/CFLAliasAnalysisUtils.h" #include "llvm/Analysis/CFLAliasAnalysisUtils.h"
#include "llvm/IR/Function.h" #include "llvm/Analysis/MemoryLocation.h"
#include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include <forward_list> #include <forward_list>
#include <memory>
namespace llvm { namespace llvm {
class Function;
class TargetLibraryInfo; class TargetLibraryInfo;
namespace cflaa { namespace cflaa {
struct AliasSummary; struct AliasSummary;
}
} // end namespace cflaa
class CFLSteensAAResult : public AAResultBase<CFLSteensAAResult> { class CFLSteensAAResult : public AAResultBase<CFLSteensAAResult> {
friend AAResultBase<CFLSteensAAResult>; friend AAResultBase<CFLSteensAAResult>;
class FunctionInfo; class FunctionInfo;
public: public:
explicit CFLSteensAAResult(const TargetLibraryInfo &); explicit CFLSteensAAResult(const TargetLibraryInfo &TLI);
CFLSteensAAResult(CFLSteensAAResult &&Arg); CFLSteensAAResult(CFLSteensAAResult &&Arg);
~CFLSteensAAResult(); ~CFLSteensAAResult();
@@ -105,10 +109,11 @@ private:
/// in particular to leverage invalidation to trigger re-computation of sets. /// in particular to leverage invalidation to trigger re-computation of sets.
class CFLSteensAA : public AnalysisInfoMixin<CFLSteensAA> { class CFLSteensAA : public AnalysisInfoMixin<CFLSteensAA> {
friend AnalysisInfoMixin<CFLSteensAA>; friend AnalysisInfoMixin<CFLSteensAA>;
static AnalysisKey Key; static AnalysisKey Key;
public: public:
typedef CFLSteensAAResult Result; using Result = CFLSteensAAResult;
CFLSteensAAResult run(Function &F, FunctionAnalysisManager &AM); CFLSteensAAResult run(Function &F, FunctionAnalysisManager &AM);
}; };
@@ -129,12 +134,10 @@ public:
void getAnalysisUsage(AnalysisUsage &AU) const override; void getAnalysisUsage(AnalysisUsage &AU) const override;
}; };
//===--------------------------------------------------------------------===//
//
// createCFLSteensAAWrapperPass - This pass implements a set-based approach to // createCFLSteensAAWrapperPass - This pass implements a set-based approach to
// alias analysis. // alias analysis.
//
ImmutablePass *createCFLSteensAAWrapperPass(); ImmutablePass *createCFLSteensAAWrapperPass();
}
#endif } // end namespace llvm
#endif // LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H

View File

@@ -35,28 +35,33 @@
#ifndef LLVM_ANALYSIS_LAZYCALLGRAPH_H #ifndef LLVM_ANALYSIS_LAZYCALLGRAPH_H
#define LLVM_ANALYSIS_LAZYCALLGRAPH_H #define LLVM_ANALYSIS_LAZYCALLGRAPH_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator.h" #include "llvm/ADT/iterator.h"
#include "llvm/ADT/iterator_range.h" #include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h" #include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h" #include "llvm/IR/PassManager.h"
#include "llvm/Support/Allocator.h" #include "llvm/Support/Allocator.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <iterator> #include <iterator>
#include <string>
#include <utility> #include <utility>
namespace llvm { namespace llvm {
class PreservedAnalyses;
class raw_ostream; class Module;
class Value;
/// A lazily constructed view of the call graph of a module. /// A lazily constructed view of the call graph of a module.
/// ///
@@ -183,8 +188,8 @@ public:
friend class LazyCallGraph::Node; friend class LazyCallGraph::Node;
friend class LazyCallGraph::RefSCC; friend class LazyCallGraph::RefSCC;
typedef SmallVector<Edge, 4> VectorT; using VectorT = SmallVector<Edge, 4>;
typedef SmallVectorImpl<Edge> VectorImplT; using VectorImplT = SmallVectorImpl<Edge>;
public: public:
/// An iterator used for the edges to both entry nodes and child nodes. /// An iterator used for the edges to both entry nodes and child nodes.
@@ -204,7 +209,7 @@ public:
} }
public: public:
iterator() {} iterator() = default;
using iterator_adaptor_base::operator++; using iterator_adaptor_base::operator++;
iterator &operator++() { iterator &operator++() {
@@ -240,7 +245,7 @@ public:
} }
public: public:
call_iterator() {} call_iterator() = default;
using iterator_adaptor_base::operator++; using iterator_adaptor_base::operator++;
call_iterator &operator++() { call_iterator &operator++() {
@@ -260,6 +265,7 @@ public:
assert(E && "Dead or null edge!"); assert(E && "Dead or null edge!");
return E; return E;
} }
Edge *lookup(Node &N) { Edge *lookup(Node &N) {
auto EI = EdgeIndexMap.find(&N); auto EI = EdgeIndexMap.find(&N);
if (EI == EdgeIndexMap.end()) if (EI == EdgeIndexMap.end())
@@ -381,15 +387,14 @@ public:
// We provide for the DFS numbering and Tarjan walk lowlink numbers to be // 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 // 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. // of an SCC (or RefSCC), or '0' when not yet reached in a DFS walk.
int DFSNumber; int DFSNumber = 0;
int LowLink; int LowLink = 0;
Optional<EdgeSequence> Edges; Optional<EdgeSequence> Edges;
/// Basic constructor implements the scanning of F into Edges and /// Basic constructor implements the scanning of F into Edges and
/// EdgeIndexMap. /// EdgeIndexMap.
Node(LazyCallGraph &G, Function &F) Node(LazyCallGraph &G, Function &F) : G(&G), F(&F) {}
: G(&G), F(&F), DFSNumber(0), LowLink(0) {}
/// Implementation of the scan when populating. /// Implementation of the scan when populating.
EdgeSequence &populateSlow(); EdgeSequence &populateSlow();
@@ -478,7 +483,7 @@ public:
#endif #endif
public: public:
typedef pointee_iterator<SmallVectorImpl<Node *>::const_iterator> iterator; using iterator = pointee_iterator<SmallVectorImpl<Node *>::const_iterator>;
iterator begin() const { return Nodes.begin(); } iterator begin() const { return Nodes.begin(); }
iterator end() const { return Nodes.end(); } iterator end() const { return Nodes.end(); }
@@ -606,10 +611,10 @@ public:
void handleTrivialEdgeInsertion(Node &SourceN, Node &TargetN); void handleTrivialEdgeInsertion(Node &SourceN, Node &TargetN);
public: public:
typedef pointee_iterator<SmallVectorImpl<SCC *>::const_iterator> iterator; using iterator = pointee_iterator<SmallVectorImpl<SCC *>::const_iterator>;
typedef iterator_range<iterator> range; using range = iterator_range<iterator>;
typedef pointee_iterator<SmallPtrSetImpl<RefSCC *>::const_iterator> using parent_iterator =
parent_iterator; pointee_iterator<SmallPtrSetImpl<RefSCC *>::const_iterator>;
iterator begin() const { return SCCs.begin(); } iterator begin() const { return SCCs.begin(); }
iterator end() const { return SCCs.end(); } iterator end() const { return SCCs.end(); }
@@ -888,14 +893,13 @@ public:
struct IsAtEndT {}; struct IsAtEndT {};
LazyCallGraph *G; LazyCallGraph *G;
RefSCC *RC; RefSCC *RC = nullptr;
/// Build the begin iterator for a node. /// Build the begin iterator for a node.
postorder_ref_scc_iterator(LazyCallGraph &G) : G(&G), RC(getRC(G, 0)) {} 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. /// Build the end iterator for a node. This is selected purely by overload.
postorder_ref_scc_iterator(LazyCallGraph &G, IsAtEndT /*Nonce*/) postorder_ref_scc_iterator(LazyCallGraph &G, IsAtEndT /*Nonce*/) : G(&G) {}
: G(&G), RC(nullptr) {}
/// Get the post-order RefSCC at the given index of the postorder walk, /// Get the post-order RefSCC at the given index of the postorder walk,
/// populating it if necessary. /// populating it if necessary.
@@ -1097,8 +1101,8 @@ public:
///@} ///@}
private: private:
typedef SmallVectorImpl<Node *>::reverse_iterator node_stack_iterator; using node_stack_iterator = SmallVectorImpl<Node *>::reverse_iterator;
typedef iterator_range<node_stack_iterator> node_stack_range; using node_stack_range = iterator_range<node_stack_iterator>;
/// Allocator that holds all the call graph nodes. /// Allocator that holds all the call graph nodes.
SpecificBumpPtrAllocator<Node> BPA; SpecificBumpPtrAllocator<Node> BPA;
@@ -1218,16 +1222,16 @@ inline Function &LazyCallGraph::Edge::getFunction() const {
// Provide GraphTraits specializations for call graphs. // Provide GraphTraits specializations for call graphs.
template <> struct GraphTraits<LazyCallGraph::Node *> { template <> struct GraphTraits<LazyCallGraph::Node *> {
typedef LazyCallGraph::Node *NodeRef; using NodeRef = LazyCallGraph::Node *;
typedef LazyCallGraph::EdgeSequence::iterator ChildIteratorType; using ChildIteratorType = LazyCallGraph::EdgeSequence::iterator;
static NodeRef getEntryNode(NodeRef N) { return N; } static NodeRef getEntryNode(NodeRef N) { return N; }
static ChildIteratorType child_begin(NodeRef N) { return (*N)->begin(); } static ChildIteratorType child_begin(NodeRef N) { return (*N)->begin(); }
static ChildIteratorType child_end(NodeRef N) { return (*N)->end(); } static ChildIteratorType child_end(NodeRef N) { return (*N)->end(); }
}; };
template <> struct GraphTraits<LazyCallGraph *> { template <> struct GraphTraits<LazyCallGraph *> {
typedef LazyCallGraph::Node *NodeRef; using NodeRef = LazyCallGraph::Node *;
typedef LazyCallGraph::EdgeSequence::iterator ChildIteratorType; using ChildIteratorType = LazyCallGraph::EdgeSequence::iterator;
static NodeRef getEntryNode(NodeRef N) { return N; } static NodeRef getEntryNode(NodeRef N) { return N; }
static ChildIteratorType child_begin(NodeRef N) { return (*N)->begin(); } static ChildIteratorType child_begin(NodeRef N) { return (*N)->begin(); }
@@ -1237,11 +1241,12 @@ template <> struct GraphTraits<LazyCallGraph *> {
/// An analysis pass which computes the call graph for a module. /// An analysis pass which computes the call graph for a module.
class LazyCallGraphAnalysis : public AnalysisInfoMixin<LazyCallGraphAnalysis> { class LazyCallGraphAnalysis : public AnalysisInfoMixin<LazyCallGraphAnalysis> {
friend AnalysisInfoMixin<LazyCallGraphAnalysis>; friend AnalysisInfoMixin<LazyCallGraphAnalysis>;
static AnalysisKey Key; static AnalysisKey Key;
public: public:
/// Inform generic clients of the result type. /// Inform generic clients of the result type.
typedef LazyCallGraph Result; using Result = LazyCallGraph;
/// Compute the \c LazyCallGraph for the module \c M. /// Compute the \c LazyCallGraph for the module \c M.
/// ///
@@ -1277,6 +1282,7 @@ public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
}; };
}
#endif } // end namespace llvm
#endif // LLVM_ANALYSIS_LAZYCALLGRAPH_H

View File

@@ -1,4 +1,4 @@
//===- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation -==// //==- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation --==//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@@ -26,26 +26,35 @@
#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/BasicAliasAnalysis.h" #include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/CFLAndersAliasAnalysis.h" #include "llvm/Analysis/CFLAndersAliasAnalysis.h"
#include "llvm/Analysis/CFLSteensAliasAnalysis.h" #include "llvm/Analysis/CFLSteensAliasAnalysis.h"
#include "llvm/Analysis/CaptureTracking.h" #include "llvm/Analysis/CaptureTracking.h"
#include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/ObjCARCAliasAnalysis.h" #include "llvm/Analysis/ObjCARCAliasAnalysis.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/ScopedNoAliasAA.h" #include "llvm/Analysis/ScopedNoAliasAA.h"
#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TypeBasedAliasAnalysis.h" #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
#include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h" #include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DataLayout.h" #include "llvm/IR/CallSite.h"
#include "llvm/IR/Dominators.h" #include "llvm/IR/Instruction.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h" #include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Type.h" #include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include <algorithm>
#include <cassert>
#include <functional>
#include <iterator>
using namespace llvm; using namespace llvm;
/// Allow disabling BasicAA from the AA results. This is particularly useful /// 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, ModRefInfo AAResults::getModRefInfo(const VAArgInst *V,
const MemoryLocation &Loc) { const MemoryLocation &Loc) {
if (Loc.Ptr) { if (Loc.Ptr) {
// If the va_arg address cannot alias the pointer in question, then the // If the va_arg address cannot alias the pointer in question, then the
// specified memory cannot be accessed by the va_arg. // 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) if (!CS.getInstruction() || CS.getInstruction() == Object)
return MRI_ModRef; return MRI_ModRef;
if (llvm::PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true, if (PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true,
/* StoreCaptures */ true, I, DT, /* StoreCaptures */ true, I, DT,
/* include Object */ true, /* include Object */ true,
/* OrderedBasicBlock */ OBB)) /* OrderedBasicBlock */ OBB))
return MRI_ModRef; return MRI_ModRef;
unsigned ArgNo = 0; unsigned ArgNo = 0;
@@ -536,16 +544,17 @@ bool AAResults::canInstructionRangeModRef(const Instruction &I1,
} }
// Provide a definition for the root virtual destructor. // 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. // Provide a definition for the static object used to identify passes.
AnalysisKey AAManager::Key; AnalysisKey AAManager::Key;
namespace { namespace {
/// A wrapper pass for external alias analyses. This just squirrels away the /// A wrapper pass for external alias analyses. This just squirrels away the
/// callback used to run any analyses and register their results. /// callback used to run any analyses and register their results.
struct ExternalAAWrapperPass : ImmutablePass { struct ExternalAAWrapperPass : ImmutablePass {
typedef std::function<void(Pass &, Function &, AAResults &)> CallbackT; using CallbackT = std::function<void(Pass &, Function &, AAResults &)>;
CallbackT CB; CallbackT CB;
@@ -554,6 +563,7 @@ struct ExternalAAWrapperPass : ImmutablePass {
ExternalAAWrapperPass() : ImmutablePass(ID) { ExternalAAWrapperPass() : ImmutablePass(ID) {
initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry()); initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
} }
explicit ExternalAAWrapperPass(CallbackT CB) explicit ExternalAAWrapperPass(CallbackT CB)
: ImmutablePass(ID), CB(std::move(CB)) { : ImmutablePass(ID), CB(std::move(CB)) {
initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry()); initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
@@ -563,9 +573,11 @@ struct ExternalAAWrapperPass : ImmutablePass {
AU.setPreservesAll(); AU.setPreservesAll();
} }
}; };
}
} // end anonymous namespace
char ExternalAAWrapperPass::ID = 0; char ExternalAAWrapperPass::ID = 0;
INITIALIZE_PASS(ExternalAAWrapperPass, "external-aa", "External Alias Analysis", INITIALIZE_PASS(ExternalAAWrapperPass, "external-aa", "External Alias Analysis",
false, true) false, true)

View File

@@ -14,6 +14,8 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Analysis/BasicAliasAnalysis.h" #include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h" #include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AliasAnalysis.h"
@@ -23,21 +25,40 @@
#include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueTracking.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/Constants.h"
#include "llvm/IR/DataLayout.h" #include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h" #include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalVariable.h" #include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h" #include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.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/Operator.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.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 "llvm/Support/KnownBits.h"
#include <algorithm> #include <cassert>
#include <cstdint>
#include <cstdlib>
#include <utility>
#define DEBUG_TYPE "basicaa" #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<BinaryOperator>(V)) { if (const BinaryOperator *BOp = dyn_cast<BinaryOperator>(V)) {
if (ConstantInt *RHSC = dyn_cast<ConstantInt>(BOp->getOperand(1))) { if (ConstantInt *RHSC = dyn_cast<ConstantInt>(BOp->getOperand(1))) {
// If we've been called recursively, then Offset and Scale will be wider // 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 // than the BOp operands. We'll always zext it here as we'll process sign
// extensions below (see the isa<SExtInst> / isa<ZExtInst> cases). // extensions below (see the isa<SExtInst> / isa<ZExtInst> cases).
@@ -574,7 +594,6 @@ bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc,
// Otherwise be conservative. // Otherwise be conservative.
Visited.clear(); Visited.clear();
return AAResultBase::pointsToConstantMemory(Loc, OrLocal); return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
} while (!Worklist.empty() && --MaxLookup); } while (!Worklist.empty() && --MaxLookup);
Visited.clear(); Visited.clear();
@@ -662,7 +681,6 @@ static bool isWriteOnlyParam(ImmutableCallSite CS, unsigned ArgIdx,
ModRefInfo BasicAAResult::getArgModRefInfo(ImmutableCallSite CS, ModRefInfo BasicAAResult::getArgModRefInfo(ImmutableCallSite CS,
unsigned ArgIdx) { unsigned ArgIdx) {
// Checking for known builtin intrinsics and target library functions. // Checking for known builtin intrinsics and target library functions.
if (isWriteOnlyParam(CS, ArgIdx, TLI)) if (isWriteOnlyParam(CS, ArgIdx, TLI))
return MRI_Mod; return MRI_Mod;
@@ -927,7 +945,6 @@ static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1,
const GEPOperator *GEP2, const GEPOperator *GEP2,
uint64_t V2Size, uint64_t V2Size,
const DataLayout &DL) { const DataLayout &DL) {
assert(GEP1->getPointerOperand()->stripPointerCastsAndBarriers() == assert(GEP1->getPointerOperand()->stripPointerCastsAndBarriers() ==
GEP2->getPointerOperand()->stripPointerCastsAndBarriers() && GEP2->getPointerOperand()->stripPointerCastsAndBarriers() &&
GEP1->getPointerOperandType() == GEP2->getPointerOperandType() && GEP1->getPointerOperandType() == GEP2->getPointerOperandType() &&
@@ -1814,6 +1831,7 @@ BasicAAWrapperPass::BasicAAWrapperPass() : FunctionPass(ID) {
} }
char BasicAAWrapperPass::ID = 0; char BasicAAWrapperPass::ID = 0;
void BasicAAWrapperPass::anchor() {} void BasicAAWrapperPass::anchor() {}
INITIALIZE_PASS_BEGIN(BasicAAWrapperPass, "basicaa", INITIALIZE_PASS_BEGIN(BasicAAWrapperPass, "basicaa",

View File

@@ -1,4 +1,4 @@
//- CFLAndersAliasAnalysis.cpp - Unification-based Alias Analysis ---*- C++-*-// //===- CFLAndersAliasAnalysis.cpp - Unification-based Alias Analysis ------===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@@ -54,9 +54,35 @@
// FunctionPasses to run concurrently. // FunctionPasses to run concurrently.
#include "llvm/Analysis/CFLAndersAliasAnalysis.h" #include "llvm/Analysis/CFLAndersAliasAnalysis.h"
#include "AliasAnalysisSummary.h"
#include "CFLGraph.h" #include "CFLGraph.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/DenseSet.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/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <utility>
#include <vector>
using namespace llvm; using namespace llvm;
using namespace llvm::cflaa; using namespace llvm::cflaa;
@@ -66,7 +92,7 @@ using namespace llvm::cflaa;
CFLAndersAAResult::CFLAndersAAResult(const TargetLibraryInfo &TLI) : TLI(TLI) {} CFLAndersAAResult::CFLAndersAAResult(const TargetLibraryInfo &TLI) : TLI(TLI) {}
CFLAndersAAResult::CFLAndersAAResult(CFLAndersAAResult &&RHS) CFLAndersAAResult::CFLAndersAAResult(CFLAndersAAResult &&RHS)
: AAResultBase(std::move(RHS)), TLI(RHS.TLI) {} : AAResultBase(std::move(RHS)), TLI(RHS.TLI) {}
CFLAndersAAResult::~CFLAndersAAResult() {} CFLAndersAAResult::~CFLAndersAAResult() = default;
namespace { namespace {
@@ -95,7 +121,8 @@ enum class MatchState : uint8_t {
FlowToMemAliasReadWrite, FlowToMemAliasReadWrite,
}; };
typedef std::bitset<7> StateSet; using StateSet = std::bitset<7>;
const unsigned ReadOnlyStateMask = const unsigned ReadOnlyStateMask =
(1U << static_cast<uint8_t>(MatchState::FlowFromReadOnly)) | (1U << static_cast<uint8_t>(MatchState::FlowFromReadOnly)) |
(1U << static_cast<uint8_t>(MatchState::FlowFromMemAliasReadOnly)); (1U << static_cast<uint8_t>(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 // We use ReachabilitySet to keep track of value aliases (The nonterminal "V" in
// the paper) during the analysis. // the paper) during the analysis.
class ReachabilitySet { class ReachabilitySet {
typedef DenseMap<InstantiatedValue, StateSet> ValueStateMap; using ValueStateMap = DenseMap<InstantiatedValue, StateSet>;
typedef DenseMap<InstantiatedValue, ValueStateMap> ValueReachMap; using ValueReachMap = DenseMap<InstantiatedValue, ValueStateMap>;
ValueReachMap ReachMap; ValueReachMap ReachMap;
public: public:
typedef ValueStateMap::const_iterator const_valuestate_iterator; using const_valuestate_iterator = ValueStateMap::const_iterator;
typedef ValueReachMap::const_iterator const_value_iterator; using const_value_iterator = ValueReachMap::const_iterator;
// Insert edge 'From->To' at state 'State' // Insert edge 'From->To' at state 'State'
bool insert(InstantiatedValue From, InstantiatedValue To, MatchState 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" // We use AliasMemSet to keep track of all memory aliases (the nonterminal "M"
// in the paper) during the analysis. // in the paper) during the analysis.
class AliasMemSet { class AliasMemSet {
typedef DenseSet<InstantiatedValue> MemSet; using MemSet = DenseSet<InstantiatedValue>;
typedef DenseMap<InstantiatedValue, MemSet> MemMapType; using MemMapType = DenseMap<InstantiatedValue, MemSet>;
MemMapType MemMap; MemMapType MemMap;
public: public:
typedef MemSet::const_iterator const_mem_iterator; using const_mem_iterator = MemSet::const_iterator;
bool insert(InstantiatedValue LHS, InstantiatedValue RHS) { bool insert(InstantiatedValue LHS, InstantiatedValue RHS) {
// Top-level values can never be memory aliases because one cannot take the // 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. // We use AliasAttrMap to keep track of the AliasAttr of each node.
class AliasAttrMap { class AliasAttrMap {
typedef DenseMap<InstantiatedValue, AliasAttrs> MapType; using MapType = DenseMap<InstantiatedValue, AliasAttrs>;
MapType AttrMap; MapType AttrMap;
public: public:
typedef MapType::const_iterator const_iterator; using const_iterator = MapType::const_iterator;
bool add(InstantiatedValue V, AliasAttrs Attr) { bool add(InstantiatedValue V, AliasAttrs Attr) {
auto &OldAttr = AttrMap[V]; auto &OldAttr = AttrMap[V];
@@ -234,23 +264,28 @@ struct ValueSummary {
}; };
SmallVector<Record, 4> FromRecords, ToRecords; SmallVector<Record, 4> FromRecords, ToRecords;
}; };
}
} // end anonymous namespace
namespace llvm { namespace llvm {
// Specialize DenseMapInfo for OffsetValue. // Specialize DenseMapInfo for OffsetValue.
template <> struct DenseMapInfo<OffsetValue> { template <> struct DenseMapInfo<OffsetValue> {
static OffsetValue getEmptyKey() { static OffsetValue getEmptyKey() {
return OffsetValue{DenseMapInfo<const Value *>::getEmptyKey(), return OffsetValue{DenseMapInfo<const Value *>::getEmptyKey(),
DenseMapInfo<int64_t>::getEmptyKey()}; DenseMapInfo<int64_t>::getEmptyKey()};
} }
static OffsetValue getTombstoneKey() { static OffsetValue getTombstoneKey() {
return OffsetValue{DenseMapInfo<const Value *>::getTombstoneKey(), return OffsetValue{DenseMapInfo<const Value *>::getTombstoneKey(),
DenseMapInfo<int64_t>::getEmptyKey()}; DenseMapInfo<int64_t>::getEmptyKey()};
} }
static unsigned getHashValue(const OffsetValue &OVal) { static unsigned getHashValue(const OffsetValue &OVal) {
return DenseMapInfo<std::pair<const Value *, int64_t>>::getHashValue( return DenseMapInfo<std::pair<const Value *, int64_t>>::getHashValue(
std::make_pair(OVal.Val, OVal.Offset)); std::make_pair(OVal.Val, OVal.Offset));
} }
static bool isEqual(const OffsetValue &LHS, const OffsetValue &RHS) { static bool isEqual(const OffsetValue &LHS, const OffsetValue &RHS) {
return LHS == RHS; return LHS == RHS;
} }
@@ -263,21 +298,25 @@ template <> struct DenseMapInfo<OffsetInstantiatedValue> {
DenseMapInfo<InstantiatedValue>::getEmptyKey(), DenseMapInfo<InstantiatedValue>::getEmptyKey(),
DenseMapInfo<int64_t>::getEmptyKey()}; DenseMapInfo<int64_t>::getEmptyKey()};
} }
static OffsetInstantiatedValue getTombstoneKey() { static OffsetInstantiatedValue getTombstoneKey() {
return OffsetInstantiatedValue{ return OffsetInstantiatedValue{
DenseMapInfo<InstantiatedValue>::getTombstoneKey(), DenseMapInfo<InstantiatedValue>::getTombstoneKey(),
DenseMapInfo<int64_t>::getEmptyKey()}; DenseMapInfo<int64_t>::getEmptyKey()};
} }
static unsigned getHashValue(const OffsetInstantiatedValue &OVal) { static unsigned getHashValue(const OffsetInstantiatedValue &OVal) {
return DenseMapInfo<std::pair<InstantiatedValue, int64_t>>::getHashValue( return DenseMapInfo<std::pair<InstantiatedValue, int64_t>>::getHashValue(
std::make_pair(OVal.IVal, OVal.Offset)); std::make_pair(OVal.IVal, OVal.Offset));
} }
static bool isEqual(const OffsetInstantiatedValue &LHS, static bool isEqual(const OffsetInstantiatedValue &LHS,
const OffsetInstantiatedValue &RHS) { const OffsetInstantiatedValue &RHS) {
return LHS == RHS; return LHS == RHS;
} }
}; };
}
} // end namespace llvm
class CFLAndersAAResult::FunctionInfo { class CFLAndersAAResult::FunctionInfo {
/// Map a value to other values that may alias it /// 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) { switch (Item.State) {
case MatchState::FlowFromReadOnly: { case MatchState::FlowFromReadOnly:
NextRevAssignState(MatchState::FlowFromReadOnly); NextRevAssignState(MatchState::FlowFromReadOnly);
NextAssignState(MatchState::FlowToReadWrite); NextAssignState(MatchState::FlowToReadWrite);
NextMemState(MatchState::FlowFromMemAliasReadOnly); NextMemState(MatchState::FlowFromMemAliasReadOnly);
break; break;
}
case MatchState::FlowFromMemAliasNoReadWrite: { case MatchState::FlowFromMemAliasNoReadWrite:
NextRevAssignState(MatchState::FlowFromReadOnly); NextRevAssignState(MatchState::FlowFromReadOnly);
NextAssignState(MatchState::FlowToWriteOnly); NextAssignState(MatchState::FlowToWriteOnly);
break; break;
}
case MatchState::FlowFromMemAliasReadOnly: { case MatchState::FlowFromMemAliasReadOnly:
NextRevAssignState(MatchState::FlowFromReadOnly); NextRevAssignState(MatchState::FlowFromReadOnly);
NextAssignState(MatchState::FlowToReadWrite); NextAssignState(MatchState::FlowToReadWrite);
break; break;
}
case MatchState::FlowToWriteOnly: { case MatchState::FlowToWriteOnly:
NextAssignState(MatchState::FlowToWriteOnly); NextAssignState(MatchState::FlowToWriteOnly);
NextMemState(MatchState::FlowToMemAliasWriteOnly); NextMemState(MatchState::FlowToMemAliasWriteOnly);
break; break;
}
case MatchState::FlowToReadWrite: { case MatchState::FlowToReadWrite:
NextAssignState(MatchState::FlowToReadWrite); NextAssignState(MatchState::FlowToReadWrite);
NextMemState(MatchState::FlowToMemAliasReadWrite); NextMemState(MatchState::FlowToMemAliasReadWrite);
break; break;
}
case MatchState::FlowToMemAliasWriteOnly: { case MatchState::FlowToMemAliasWriteOnly:
NextAssignState(MatchState::FlowToWriteOnly); NextAssignState(MatchState::FlowToWriteOnly);
break; break;
}
case MatchState::FlowToMemAliasReadWrite: { case MatchState::FlowToMemAliasReadWrite:
NextAssignState(MatchState::FlowToReadWrite); NextAssignState(MatchState::FlowToReadWrite);
break; break;
} }
}
} }
static AliasAttrMap buildAttrMap(const CFLGraph &Graph, static AliasAttrMap buildAttrMap(const CFLGraph &Graph,

View File

@@ -1,4 +1,4 @@
//======- CFLGraph.h - Abstract stratified sets implementation. --------======// //===- CFLGraph.h - Abstract stratified sets implementation. -----*- C++-*-===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@@ -6,19 +6,42 @@
// License. See LICENSE.TXT for details. // License. See LICENSE.TXT for details.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
//
/// \file /// \file
/// This file defines CFLGraph, an auxiliary data structure used by CFL-based /// This file defines CFLGraph, an auxiliary data structure used by CFL-based
/// alias analysis. /// alias analysis.
/// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_CFLGRAPH_H #ifndef LLVM_LIB_ANALYSIS_CFLGRAPH_H
#define LLVM_ANALYSIS_CFLGRAPH_H #define LLVM_LIB_ANALYSIS_CFLGRAPH_H
#include "AliasAnalysisSummary.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/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/InstVisitor.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.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 <cassert>
#include <cstdint>
#include <vector>
namespace llvm { namespace llvm {
namespace cflaa { namespace cflaa {
@@ -35,14 +58,14 @@ namespace cflaa {
/// I+1) and a reference edge to (X, I-1). /// I+1) and a reference edge to (X, I-1).
class CFLGraph { class CFLGraph {
public: public:
typedef InstantiatedValue Node; using Node = InstantiatedValue;
struct Edge { struct Edge {
Node Other; Node Other;
int64_t Offset; int64_t Offset;
}; };
typedef std::vector<Edge> EdgeList; using EdgeList = std::vector<Edge>;
struct NodeInfo { struct NodeInfo {
EdgeList Edges, ReverseEdges; EdgeList Edges, ReverseEdges;
@@ -74,7 +97,8 @@ public:
}; };
private: private:
typedef DenseMap<Value *, ValueInfo> ValueMap; using ValueMap = DenseMap<Value *, ValueInfo>;
ValueMap ValueImpls; ValueMap ValueImpls;
NodeInfo *getNode(Node N) { NodeInfo *getNode(Node N) {
@@ -85,7 +109,7 @@ private:
} }
public: public:
typedef ValueMap::const_iterator const_value_iterator; using const_value_iterator = ValueMap::const_iterator;
bool addNode(Node N, AliasAttrs Attr = AliasAttrs()) { bool addNode(Node N, AliasAttrs Attr = AliasAttrs()) {
assert(N.Val != nullptr); assert(N.Val != nullptr);
@@ -496,10 +520,10 @@ template <typename CFLAA> class CFLGraphBuilder {
addNode(Ptr, getAttrEscaped()); addNode(Ptr, getAttrEscaped());
break; break;
} }
case Instruction::IntToPtr: { case Instruction::IntToPtr:
addNode(CE, getAttrUnknown()); addNode(CE, getAttrUnknown());
break; break;
}
case Instruction::BitCast: case Instruction::BitCast:
case Instruction::AddrSpaceCast: case Instruction::AddrSpaceCast:
case Instruction::Trunc: case Instruction::Trunc:
@@ -571,11 +595,11 @@ template <typename CFLAA> class CFLGraphBuilder {
case Instruction::LShr: case Instruction::LShr:
case Instruction::AShr: case Instruction::AShr:
case Instruction::ICmp: case Instruction::ICmp:
case Instruction::FCmp: { case Instruction::FCmp:
addAssignEdge(CE->getOperand(0), CE); addAssignEdge(CE->getOperand(0), CE);
addAssignEdge(CE->getOperand(1), CE); addAssignEdge(CE->getOperand(1), CE);
break; break;
}
default: default:
llvm_unreachable("Unknown instruction type encountered!"); llvm_unreachable("Unknown instruction type encountered!");
} }
@@ -640,7 +664,8 @@ public:
return ReturnedValues; return ReturnedValues;
} }
}; };
}
}
#endif } // end namespace cflaa
} // end namespace llvm
#endif // LLVM_LIB_ANALYSIS_CFLGRAPH_H

View File

@@ -1,4 +1,4 @@
//- CFLSteensAliasAnalysis.cpp - Unification-based Alias Analysis ---*- C++-*-// //===- CFLSteensAliasAnalysis.cpp - Unification-based Alias Analysis ------===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@@ -36,23 +36,25 @@
// FunctionPasses to run concurrently. // FunctionPasses to run concurrently.
#include "llvm/Analysis/CFLSteensAliasAnalysis.h" #include "llvm/Analysis/CFLSteensAliasAnalysis.h"
#include "AliasAnalysisSummary.h"
#include "CFLGraph.h" #include "CFLGraph.h"
#include "StratifiedSets.h" #include "StratifiedSets.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h" #include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/Constants.h" #include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <limits>
#include <memory> #include <memory>
#include <tuple> #include <utility>
using namespace llvm; using namespace llvm;
using namespace llvm::cflaa; using namespace llvm::cflaa;
@@ -63,7 +65,7 @@ CFLSteensAAResult::CFLSteensAAResult(const TargetLibraryInfo &TLI)
: AAResultBase(), TLI(TLI) {} : AAResultBase(), TLI(TLI) {}
CFLSteensAAResult::CFLSteensAAResult(CFLSteensAAResult &&Arg) CFLSteensAAResult::CFLSteensAAResult(CFLSteensAAResult &&Arg)
: AAResultBase(std::move(Arg)), TLI(Arg.TLI) {} : AAResultBase(std::move(Arg)), TLI(Arg.TLI) {}
CFLSteensAAResult::~CFLSteensAAResult() {} CFLSteensAAResult::~CFLSteensAAResult() = default;
/// Information we have about a function and would like to keep around. /// Information we have about a function and would like to keep around.
class CFLSteensAAResult::FunctionInfo { class CFLSteensAAResult::FunctionInfo {
@@ -77,6 +79,7 @@ public:
const StratifiedSets<InstantiatedValue> &getStratifiedSets() const { const StratifiedSets<InstantiatedValue> &getStratifiedSets() const {
return Sets; return Sets;
} }
const AliasSummary &getAliasSummary() const { return Summary; } const AliasSummary &getAliasSummary() const { return Summary; }
}; };

View File

@@ -8,15 +8,31 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Analysis/LazyCallGraph.h" #include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/Sequence.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/CallSite.h"
#include "llvm/IR/InstVisitor.h" #include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h" #include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h" #include "llvm/IR/PassManager.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/GraphWriter.h" #include "llvm/Support/GraphWriter.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iterator>
#include <string>
#include <tuple>
#include <utility> #include <utility>
using namespace llvm; using namespace llvm;
@@ -1339,10 +1355,8 @@ void LazyCallGraph::RefSCC::handleTrivialEdgeInsertion(Node &SourceN,
// after this edge insertion. // after this edge insertion.
assert(G->lookupRefSCC(SourceN) == this && "Source must be in this RefSCC."); assert(G->lookupRefSCC(SourceN) == this && "Source must be in this RefSCC.");
RefSCC &TargetRC = *G->lookupRefSCC(TargetN); RefSCC &TargetRC = *G->lookupRefSCC(TargetN);
if (&TargetRC == this) { if (&TargetRC == this)
return; return;
}
#ifdef EXPENSIVE_CHECKS #ifdef EXPENSIVE_CHECKS
assert(TargetRC.isDescendantOf(*this) && assert(TargetRC.isDescendantOf(*this) &&
@@ -1544,7 +1558,7 @@ template <typename RootsT, typename GetBeginT, typename GetEndT,
void LazyCallGraph::buildGenericSCCs(RootsT &&Roots, GetBeginT &&GetBegin, void LazyCallGraph::buildGenericSCCs(RootsT &&Roots, GetBeginT &&GetBegin,
GetEndT &&GetEnd, GetNodeT &&GetNode, GetEndT &&GetEnd, GetNodeT &&GetNode,
FormSCCCallbackT &&FormSCC) { FormSCCCallbackT &&FormSCC) {
typedef decltype(GetBegin(std::declval<Node &>())) EdgeItT; using EdgeItT = decltype(GetBegin(std::declval<Node &>()));
SmallVector<std::pair<Node *, EdgeItT>, 16> DFSStack; SmallVector<std::pair<Node *, EdgeItT>, 16> DFSStack;
SmallVector<Node *, 16> PendingSCCStack; SmallVector<Node *, 16> PendingSCCStack;