llvm.org GIT mirror llvm / c5e4ac8
[Analysis] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310766 91177308-0d34-0410-b5e6-96231b3b80d8 Eugene Zelenko 2 years ago
11 changed file(s) with 310 addition(s) and 165 deletion(s). Raw diff Collapse all Expand all
3737 #ifndef LLVM_ANALYSIS_ALIASANALYSIS_H
3838 #define LLVM_ANALYSIS_ALIASANALYSIS_H
3939
40 #include "llvm/ADT/None.h"
4041 #include "llvm/ADT/Optional.h"
42 #include "llvm/ADT/SmallVector.h"
4143 #include "llvm/Analysis/MemoryLocation.h"
4244 #include "llvm/Analysis/TargetLibraryInfo.h"
4345 #include "llvm/IR/CallSite.h"
44 #include "llvm/IR/Metadata.h"
46 #include "llvm/IR/Function.h"
47 #include "llvm/IR/Instruction.h"
48 #include "llvm/IR/Instructions.h"
4549 #include "llvm/IR/PassManager.h"
50 #include "llvm/Pass.h"
51 #include
52 #include
53 #include
54 #include
4655
4756 namespace llvm {
57
58 class AnalysisUsage;
4859 class BasicAAResult;
49 class LoadInst;
50 class StoreInst;
51 class VAArgInst;
52 class DataLayout;
53 class Pass;
54 class AnalysisUsage;
55 class MemTransferInst;
56 class MemIntrinsic;
60 class BasicBlock;
5761 class DominatorTree;
5862 class OrderedBasicBlock;
63 class Value;
5964
6065 /// The possible results of an alias query.
6166 ///
610615
611616 private:
612617 class Concept;
618
613619 template class Model;
614620
615621 template friend class AAResultBase;
623629
624630 /// Temporary typedef for legacy code that uses a generic \c AliasAnalysis
625631 /// pointer or reference.
626 typedef AAResults AliasAnalysis;
632 using AliasAnalysis = AAResults;
627633
628634 /// A private abstract base class describing the concept of an individual alias
629635 /// analysis implementation.
704710 explicit Model(AAResultT &Result, AAResults &AAR) : Result(Result) {
705711 Result.setAAResults(&AAR);
706712 }
707 ~Model() override {}
713 ~Model() override = default;
708714
709715 void setAAResults(AAResults *NewAAR) override { Result.setAAResults(NewAAR); }
710716
814820 }
815821 };
816822
817 explicit AAResultBase() {}
823 explicit AAResultBase() = default;
818824
819825 // Provide all the copy and move constructors so that derived types aren't
820826 // constrained.
862868 return MRI_ModRef;
863869 }
864870 };
865
866871
867872 /// Return true if this pointer is returned by a noalias function.
868873 bool isNoAliasCall(const Value *V);
900905 /// ensure the analysis itself is registered with its AnalysisManager.
901906 class AAManager : public AnalysisInfoMixin {
902907 public:
903 typedef AAResults Result;
908 using Result = AAResults;
904909
905910 /// Register a specific AA result.
906911 template void registerFunctionAnalysis() {
921926
922927 private:
923928 friend AnalysisInfoMixin;
929
924930 static AnalysisKey Key;
925931
926932 SmallVector
991997 /// sure the analyses required by \p createLegacyPMAAResults are available.
992998 void getAAResultsAnalysisUsage(AnalysisUsage &AU);
993999
994 } // End llvm namespace
995
996 #endif
1000 } // end namespace llvm
1001
1002 #endif // LLVM_ANALYSIS_ALIASANALYSIS_H
1313 #ifndef LLVM_ANALYSIS_BASICALIASANALYSIS_H
1414 #define LLVM_ANALYSIS_BASICALIASANALYSIS_H
1515
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/Optional.h"
1618 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/SmallVector.h"
1720 #include "llvm/Analysis/AliasAnalysis.h"
1821 #include "llvm/Analysis/AssumptionCache.h"
19 #include "llvm/Analysis/TargetLibraryInfo.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/GetElementPtrTypeIterator.h"
22 #include "llvm/IR/Instruction.h"
23 #include "llvm/IR/LLVMContext.h"
24 #include "llvm/IR/Module.h"
22 #include "llvm/Analysis/MemoryLocation.h"
23 #include "llvm/IR/CallSite.h"
2524 #include "llvm/IR/PassManager.h"
26 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Pass.h"
26 #include
27 #include
28 #include
29 #include
2730
2831 namespace llvm {
32
33 struct AAMDNodes;
34 class APInt;
2935 class AssumptionCache;
36 class BasicBlock;
37 class DataLayout;
3038 class DominatorTree;
39 class Function;
40 class GEPOperator;
3141 class LoopInfo;
42 class PHINode;
43 class SelectInst;
44 class TargetLibraryInfo;
45 class Value;
3246
3347 /// This is the AA result object for the basic, local, and stateless alias
3448 /// analysis. It implements the AA query interface in an entirely stateless
8599 // A linear transformation of a Value; this class represents ZExt(SExt(V,
86100 // SExtBits), ZExtBits) * Scale + Offset.
87101 struct VariableGEPIndex {
88
89102 // An opaque Value - we can't decompose this further.
90103 const Value *V;
91104
123136 };
124137
125138 /// Track alias queries to guard against recursion.
126 typedef std::pair LocPair;
127 typedef SmallDenseMap AliasCacheTy;
139 using LocPair = std::pair;
140 using AliasCacheTy = SmallDenseMap;
128141 AliasCacheTy AliasCache;
129142
130143 /// Tracks phi nodes we have visited.
200213 /// Analysis pass providing a never-invalidated alias analysis result.
201214 class BasicAA : public AnalysisInfoMixin {
202215 friend AnalysisInfoMixin;
216
203217 static AnalysisKey Key;
204218
205219 public:
206 typedef BasicAAResult Result;
220 using Result = BasicAAResult;
207221
208222 BasicAAResult run(Function &F, FunctionAnalysisManager &AM);
209223 };
250264 }
251265 };
252266
253 }
254
255 #endif
267 } // end namespace llvm
268
269 #endif // LLVM_ANALYSIS_BASICALIASANALYSIS_H
None //=- CFLAndersAliasAnalysis.h - Unification-based Alias Analysis ---*- C++-*-=//
0 //==- CFLAndersAliasAnalysis.h - Unification-based Alias Analysis -*- C++-*-==//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1818 #include "llvm/ADT/Optional.h"
1919 #include "llvm/Analysis/AliasAnalysis.h"
2020 #include "llvm/Analysis/CFLAliasAnalysisUtils.h"
21 #include "llvm/IR/Function.h"
21 #include "llvm/IR/PassManager.h"
2222 #include "llvm/Pass.h"
2323 #include
24 #include
2425
2526 namespace llvm {
2627
28 class Function;
29 class MemoryLocation;
2730 class TargetLibraryInfo;
2831
2932 namespace cflaa {
33
3034 struct AliasSummary;
31 }
35
36 } // end namespace cflaa
3237
3338 class CFLAndersAAResult : public AAResultBase {
3439 friend AAResultBase;
40
3541 class FunctionInfo;
3642
3743 public:
38 explicit CFLAndersAAResult(const TargetLibraryInfo &);
39 CFLAndersAAResult(CFLAndersAAResult &&);
44 explicit CFLAndersAAResult(const TargetLibraryInfo &TLI);
45 CFLAndersAAResult(CFLAndersAAResult &&RHS);
4046 ~CFLAndersAAResult();
4147
4248 /// Handle invalidation events from the new pass manager.
4551 FunctionAnalysisManager::Invalidator &) {
4652 return false;
4753 }
54
4855 /// Evict the given function from cache
4956 void evict(const Function *Fn);
5057
8491 /// in particular to leverage invalidation to trigger re-computation.
8592 class CFLAndersAA : public AnalysisInfoMixin {
8693 friend AnalysisInfoMixin;
94
8795 static AnalysisKey Key;
8896
8997 public:
90 typedef CFLAndersAAResult Result;
98 using Result = CFLAndersAAResult;
9199
92100 CFLAndersAAResult run(Function &F, FunctionAnalysisManager &AM);
93101 };
108116 void getAnalysisUsage(AnalysisUsage &AU) const override;
109117 };
110118
111 //===--------------------------------------------------------------------===//
112 //
113119 // createCFLAndersAAWrapperPass - This pass implements a set-based approach to
114120 // alias analysis.
115 //
116121 ImmutablePass *createCFLAndersAAWrapperPass();
117 }
118122
119 #endif
123 } // end namespace llvm
124
125 #endif // LLVM_ANALYSIS_CFLANDERSALIASANALYSIS_H
None //=- CFLSteensAliasAnalysis.h - Unification-based Alias Analysis ---*- C++-*-=//
0 //==- CFLSteensAliasAnalysis.h - Unification-based Alias Analysis -*- C++-*-==//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1515 #define LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H
1616
1717 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/None.h"
1918 #include "llvm/ADT/Optional.h"
2019 #include "llvm/Analysis/AliasAnalysis.h"
2120 #include "llvm/Analysis/CFLAliasAnalysisUtils.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/IR/Module.h"
24 #include "llvm/IR/ValueHandle.h"
21 #include "llvm/Analysis/MemoryLocation.h"
22 #include "llvm/IR/PassManager.h"
2523 #include "llvm/Pass.h"
24 #include "llvm/Support/Casting.h"
2625 #include
26 #include
2727
2828 namespace llvm {
2929
30 class Function;
3031 class TargetLibraryInfo;
3132
3233 namespace cflaa {
34
3335 struct AliasSummary;
34 }
36
37 } // end namespace cflaa
3538
3639 class CFLSteensAAResult : public AAResultBase {
3740 friend AAResultBase;
41
3842 class FunctionInfo;
3943
4044 public:
41 explicit CFLSteensAAResult(const TargetLibraryInfo &);
45 explicit CFLSteensAAResult(const TargetLibraryInfo &TLI);
4246 CFLSteensAAResult(CFLSteensAAResult &&Arg);
4347 ~CFLSteensAAResult();
4448
104108 /// in particular to leverage invalidation to trigger re-computation of sets.
105109 class CFLSteensAA : public AnalysisInfoMixin {
106110 friend AnalysisInfoMixin;
111
107112 static AnalysisKey Key;
108113
109114 public:
110 typedef CFLSteensAAResult Result;
115 using Result = CFLSteensAAResult;
111116
112117 CFLSteensAAResult run(Function &F, FunctionAnalysisManager &AM);
113118 };
128133 void getAnalysisUsage(AnalysisUsage &AU) const override;
129134 };
130135
131 //===--------------------------------------------------------------------===//
132 //
133136 // createCFLSteensAAWrapperPass - This pass implements a set-based approach to
134137 // alias analysis.
135 //
136138 ImmutablePass *createCFLSteensAAWrapperPass();
137 }
138139
139 #endif
140 } // end namespace llvm
141
142 #endif // LLVM_ANALYSIS_CFLSTEENSALIASANALYSIS_H
3434 #ifndef LLVM_ANALYSIS_LAZYCALLGRAPH_H
3535 #define LLVM_ANALYSIS_LAZYCALLGRAPH_H
3636
37 #include "llvm/ADT/ArrayRef.h"
3738 #include "llvm/ADT/DenseMap.h"
38 #include "llvm/ADT/PointerUnion.h"
39 #include "llvm/ADT/STLExtras.h"
39 #include "llvm/ADT/Optional.h"
40 #include "llvm/ADT/PointerIntPair.h"
4041 #include "llvm/ADT/SetVector.h"
4142 #include "llvm/ADT/SmallPtrSet.h"
4243 #include "llvm/ADT/SmallVector.h"
44 #include "llvm/ADT/StringRef.h"
4345 #include "llvm/ADT/iterator.h"
4446 #include "llvm/ADT/iterator_range.h"
4547 #include "llvm/Analysis/TargetLibraryInfo.h"
46 #include "llvm/IR/BasicBlock.h"
48 #include "llvm/IR/Constant.h"
4749 #include "llvm/IR/Constants.h"
4850 #include "llvm/IR/Function.h"
49 #include "llvm/IR/Module.h"
5051 #include "llvm/IR/PassManager.h"
5152 #include "llvm/Support/Allocator.h"
53 #include "llvm/Support/Casting.h"
5254 #include "llvm/Support/raw_ostream.h"
55 #include
5356 #include
57 #include
5458 #include
5559
5660 namespace llvm {
57 class PreservedAnalyses;
58 class raw_ostream;
61
62 class Module;
63 class Value;
5964
6065 /// A lazily constructed view of the call graph of a module.
6166 ///
182187 friend class LazyCallGraph::Node;
183188 friend class LazyCallGraph::RefSCC;
184189
185 typedef SmallVector VectorT;
186 typedef SmallVectorImpl VectorImplT;
190 using VectorT = SmallVector;
191 using VectorImplT = SmallVectorImpl;
187192
188193 public:
189194 /// An iterator used for the edges to both entry nodes and child nodes.
203208 }
204209
205210 public:
206 iterator() {}
211 iterator() = default;
207212
208213 using iterator_adaptor_base::operator++;
209214 iterator &operator++() {
239244 }
240245
241246 public:
242 call_iterator() {}
247 call_iterator() = default;
243248
244249 using iterator_adaptor_base::operator++;
245250 call_iterator &operator++() {
259264 assert(E && "Dead or null edge!");
260265 return E;
261266 }
267
262268 Edge *lookup(Node &N) {
263269 auto EI = EdgeIndexMap.find(&N);
264270 if (EI == EdgeIndexMap.end())
380386 // We provide for the DFS numbering and Tarjan walk lowlink numbers to be
381387 // stored directly within the node. These are both '-1' when nodes are part
382388 // of an SCC (or RefSCC), or '0' when not yet reached in a DFS walk.
383 int DFSNumber;
384 int LowLink;
389 int DFSNumber = 0;
390 int LowLink = 0;
385391
386392 Optional Edges;
387393
388394 /// Basic constructor implements the scanning of F into Edges and
389395 /// EdgeIndexMap.
390 Node(LazyCallGraph &G, Function &F)
391 : G(&G), F(&F), DFSNumber(0), LowLink(0) {}
396 Node(LazyCallGraph &G, Function &F) : G(&G), F(&F) {}
392397
393398 /// Implementation of the scan when populating.
394399 EdgeSequence &populateSlow();
477482 #endif
478483
479484 public:
480 typedef pointee_iterator::const_iterator> iterator;
485 using iterator = pointee_iterator::const_iterator>;
481486
482487 iterator begin() const { return Nodes.begin(); }
483488 iterator end() const { return Nodes.end(); }
605610 void handleTrivialEdgeInsertion(Node &SourceN, Node &TargetN);
606611
607612 public:
608 typedef pointee_iterator::const_iterator> iterator;
609 typedef iterator_range range;
610 typedef pointee_iterator::const_iterator>
611 parent_iterator;
613 using iterator = pointee_iterator::const_iterator>;
614 using range = iterator_range;
615 using parent_iterator =
616 pointee_iterator::const_iterator>;
612617
613618 iterator begin() const { return SCCs.begin(); }
614619 iterator end() const { return SCCs.end(); }
887892 struct IsAtEndT {};
888893
889894 LazyCallGraph *G;
890 RefSCC *RC;
895 RefSCC *RC = nullptr;
891896
892897 /// Build the begin iterator for a node.
893898 postorder_ref_scc_iterator(LazyCallGraph &G) : G(&G), RC(getRC(G, 0)) {}
894899
895900 /// Build the end iterator for a node. This is selected purely by overload.
896 postorder_ref_scc_iterator(LazyCallGraph &G, IsAtEndT /*Nonce*/)
897 : G(&G), RC(nullptr) {}
901 postorder_ref_scc_iterator(LazyCallGraph &G, IsAtEndT /*Nonce*/) : G(&G) {}
898902
899903 /// Get the post-order RefSCC at the given index of the postorder walk,
900904 /// populating it if necessary.
10961100 ///@}
10971101
10981102 private:
1099 typedef SmallVectorImpl::reverse_iterator node_stack_iterator;
1100 typedef iterator_range node_stack_range;
1103 using node_stack_iterator = SmallVectorImpl::reverse_iterator;
1104 using node_stack_range = iterator_range;
11011105
11021106 /// Allocator that holds all the call graph nodes.
11031107 SpecificBumpPtrAllocator BPA;
12171221
12181222 // Provide GraphTraits specializations for call graphs.
12191223 template <> struct GraphTraits {
1220 typedef LazyCallGraph::Node *NodeRef;
1221 typedef LazyCallGraph::EdgeSequence::iterator ChildIteratorType;
1224 using NodeRef = LazyCallGraph::Node *;
1225 using ChildIteratorType = LazyCallGraph::EdgeSequence::iterator;
12221226
12231227 static NodeRef getEntryNode(NodeRef N) { return N; }
12241228 static ChildIteratorType child_begin(NodeRef N) { return (*N)->begin(); }
12251229 static ChildIteratorType child_end(NodeRef N) { return (*N)->end(); }
12261230 };
12271231 template <> struct GraphTraits {
1228 typedef LazyCallGraph::Node *NodeRef;
1229 typedef LazyCallGraph::EdgeSequence::iterator ChildIteratorType;
1232 using NodeRef = LazyCallGraph::Node *;
1233 using ChildIteratorType = LazyCallGraph::EdgeSequence::iterator;
12301234
12311235 static NodeRef getEntryNode(NodeRef N) { return N; }
12321236 static ChildIteratorType child_begin(NodeRef N) { return (*N)->begin(); }
12361240 /// An analysis pass which computes the call graph for a module.
12371241 class LazyCallGraphAnalysis : public AnalysisInfoMixin {
12381242 friend AnalysisInfoMixin;
1243
12391244 static AnalysisKey Key;
12401245
12411246 public:
12421247 /// Inform generic clients of the result type.
1243 typedef LazyCallGraph Result;
1248 using Result = LazyCallGraph;
12441249
12451250 /// Compute the \c LazyCallGraph for the module \c M.
12461251 ///
12761281
12771282 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
12781283 };
1279 }
1280
1281 #endif
1284
1285 } // end namespace llvm
1286
1287 #endif // LLVM_ANALYSIS_LAZYCALLGRAPH_H
None //===- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation -==//
0 //==- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation --==//
11 //
22 // The LLVM Compiler Infrastructure
33 //
2525
2626 #include "llvm/Analysis/AliasAnalysis.h"
2727 #include "llvm/Analysis/BasicAliasAnalysis.h"
28 #include "llvm/Analysis/CFG.h"
2928 #include "llvm/Analysis/CFLAndersAliasAnalysis.h"
3029 #include "llvm/Analysis/CFLSteensAliasAnalysis.h"
3130 #include "llvm/Analysis/CaptureTracking.h"
3231 #include "llvm/Analysis/GlobalsModRef.h"
32 #include "llvm/Analysis/MemoryLocation.h"
3333 #include "llvm/Analysis/ObjCARCAliasAnalysis.h"
3434 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
3535 #include "llvm/Analysis/ScopedNoAliasAA.h"
3636 #include "llvm/Analysis/TargetLibraryInfo.h"
3737 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
3838 #include "llvm/Analysis/ValueTracking.h"
39 #include "llvm/IR/Argument.h"
40 #include "llvm/IR/Attributes.h"
3941 #include "llvm/IR/BasicBlock.h"
40 #include "llvm/IR/DataLayout.h"
41 #include "llvm/IR/Dominators.h"
42 #include "llvm/IR/Function.h"
42 #include "llvm/IR/CallSite.h"
43 #include "llvm/IR/Instruction.h"
4344 #include "llvm/IR/Instructions.h"
44 #include "llvm/IR/IntrinsicInst.h"
45 #include "llvm/IR/LLVMContext.h"
45 #include "llvm/IR/Module.h"
4646 #include "llvm/IR/Type.h"
47 #include "llvm/IR/Value.h"
4748 #include "llvm/Pass.h"
49 #include "llvm/Support/AtomicOrdering.h"
50 #include "llvm/Support/Casting.h"
51 #include "llvm/Support/CommandLine.h"
52 #include
53 #include
54 #include
55 #include
56
4857 using namespace llvm;
4958
5059 /// Allow disabling BasicAA from the AA results. This is particularly useful
376385
377386 ModRefInfo AAResults::getModRefInfo(const VAArgInst *V,
378387 const MemoryLocation &Loc) {
379
380388 if (Loc.Ptr) {
381389 // If the va_arg address cannot alias the pointer in question, then the
382390 // specified memory cannot be accessed by the va_arg.
470478 if (!CS.getInstruction() || CS.getInstruction() == Object)
471479 return MRI_ModRef;
472480
473 if (llvm::PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true,
474 /* StoreCaptures */ true, I, DT,
475 /* include Object */ true,
476 /* OrderedBasicBlock */ OBB))
481 if (PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true,
482 /* StoreCaptures */ true, I, DT,
483 /* include Object */ true,
484 /* OrderedBasicBlock */ OBB))
477485 return MRI_ModRef;
478486
479487 unsigned ArgNo = 0;
535543 }
536544
537545 // Provide a definition for the root virtual destructor.
538 AAResults::Concept::~Concept() {}
546 AAResults::Concept::~Concept() = default;
539547
540548 // Provide a definition for the static object used to identify passes.
541549 AnalysisKey AAManager::Key;
542550
543551 namespace {
552
544553 /// A wrapper pass for external alias analyses. This just squirrels away the
545554 /// callback used to run any analyses and register their results.
546555 struct ExternalAAWrapperPass : ImmutablePass {
547 typedef std::function CallbackT;
556 using CallbackT = std::function;
548557
549558 CallbackT CB;
550559
553562 ExternalAAWrapperPass() : ImmutablePass(ID) {
554563 initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
555564 }
565
556566 explicit ExternalAAWrapperPass(CallbackT CB)
557567 : ImmutablePass(ID), CB(std::move(CB)) {
558568 initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
562572 AU.setPreservesAll();
563573 }
564574 };
565 }
575
576 } // end anonymous namespace
566577
567578 char ExternalAAWrapperPass::ID = 0;
579
568580 INITIALIZE_PASS(ExternalAAWrapperPass, "external-aa", "External Alias Analysis",
569581 false, true)
570582
1313 //===----------------------------------------------------------------------===//
1414
1515 #include "llvm/Analysis/BasicAliasAnalysis.h"
16 #include "llvm/ADT/APInt.h"
17 #include "llvm/ADT/SmallPtrSet.h"
1618 #include "llvm/ADT/SmallVector.h"
1719 #include "llvm/ADT/Statistic.h"
1820 #include "llvm/Analysis/AliasAnalysis.h"
2224 #include "llvm/Analysis/InstructionSimplify.h"
2325 #include "llvm/Analysis/LoopInfo.h"
2426 #include "llvm/Analysis/MemoryBuiltins.h"
27 #include "llvm/Analysis/MemoryLocation.h"
28 #include "llvm/Analysis/TargetLibraryInfo.h"
2529 #include "llvm/Analysis/ValueTracking.h"
30 #include "llvm/IR/Argument.h"
31 #include "llvm/IR/Attributes.h"
32 #include "llvm/IR/CallSite.h"
33 #include "llvm/IR/Constant.h"
2634 #include "llvm/IR/Constants.h"
2735 #include "llvm/IR/DataLayout.h"
2836 #include "llvm/IR/DerivedTypes.h"
2937 #include "llvm/IR/Dominators.h"
38 #include "llvm/IR/Function.h"
39 #include "llvm/IR/GetElementPtrTypeIterator.h"
3040 #include "llvm/IR/GlobalAlias.h"
3141 #include "llvm/IR/GlobalVariable.h"
42 #include "llvm/IR/InstrTypes.h"
43 #include "llvm/IR/Instruction.h"
3244 #include "llvm/IR/Instructions.h"
3345 #include "llvm/IR/IntrinsicInst.h"
34 #include "llvm/IR/LLVMContext.h"
46 #include "llvm/IR/Intrinsics.h"
47 #include "llvm/IR/Metadata.h"
3548 #include "llvm/IR/Operator.h"
49 #include "llvm/IR/Type.h"
50 #include "llvm/IR/User.h"
51 #include "llvm/IR/Value.h"
3652 #include "llvm/Pass.h"
37 #include "llvm/Support/ErrorHandling.h"
53 #include "llvm/Support/Casting.h"
54 #include "llvm/Support/CommandLine.h"
55 #include "llvm/Support/Compiler.h"
3856 #include "llvm/Support/KnownBits.h"
39 #include <algorithm>
57 #include <cassert>
58 #include
59 #include
60 #include
4061
4162 #define DEBUG_TYPE "basicaa"
4263
222243
223244 if (const BinaryOperator *BOp = dyn_cast(V)) {
224245 if (ConstantInt *RHSC = dyn_cast(BOp->getOperand(1))) {
225
226246 // If we've been called recursively, then Offset and Scale will be wider
227247 // than the BOp operands. We'll always zext it here as we'll process sign
228248 // extensions below (see the isa / isa cases).
573593 // Otherwise be conservative.
574594 Visited.clear();
575595 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
576
577596 } while (!Worklist.empty() && --MaxLookup);
578597
579598 Visited.clear();
661680
662681 ModRefInfo BasicAAResult::getArgModRefInfo(ImmutableCallSite CS,
663682 unsigned ArgIdx) {
664
665683 // Checking for known builtin intrinsics and target library functions.
666684 if (isWriteOnlyParam(CS, ArgIdx, TLI))
667685 return MRI_Mod;
926944 const GEPOperator *GEP2,
927945 uint64_t V2Size,
928946 const DataLayout &DL) {
929
930947 assert(GEP1->getPointerOperand()->stripPointerCastsAndBarriers() ==
931948 GEP2->getPointerOperand()->stripPointerCastsAndBarriers() &&
932949 GEP1->getPointerOperandType() == GEP2->getPointerOperandType() &&
18131830 }
18141831
18151832 char BasicAAWrapperPass::ID = 0;
1833
18161834 void BasicAAWrapperPass::anchor() {}
18171835
18181836 INITIALIZE_PASS_BEGIN(BasicAAWrapperPass, "basicaa",
None //- CFLAndersAliasAnalysis.cpp - Unification-based Alias Analysis ---*- C++-*-//
0 //===- CFLAndersAliasAnalysis.cpp - Unification-based Alias Analysis ------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
5353 // FunctionPasses to run concurrently.
5454
5555 #include "llvm/Analysis/CFLAndersAliasAnalysis.h"
56 #include "AliasAnalysisSummary.h"
5657 #include "CFLGraph.h"
58 #include "llvm/ADT/DenseMap.h"
59 #include "llvm/ADT/DenseMapInfo.h"
5760 #include "llvm/ADT/DenseSet.h"
61 #include "llvm/ADT/None.h"
62 #include "llvm/ADT/Optional.h"
63 #include "llvm/ADT/STLExtras.h"
64 #include "llvm/ADT/SmallVector.h"
65 #include "llvm/ADT/iterator_range.h"
66 #include "llvm/Analysis/AliasAnalysis.h"
67 #include "llvm/Analysis/MemoryLocation.h"
68 #include "llvm/IR/Argument.h"
69 #include "llvm/IR/Function.h"
70 #include "llvm/IR/PassManager.h"
71 #include "llvm/IR/Type.h"
5872 #include "llvm/Pass.h"
73 #include "llvm/Support/Casting.h"
74 #include "llvm/Support/Compiler.h"
75 #include "llvm/Support/Debug.h"
76 #include "llvm/Support/raw_ostream.h"
77 #include
78 #include
79 #include
80 #include
81 #include
82 #include
83 #include
84 #include
5985
6086 using namespace llvm;
6187 using namespace llvm::cflaa;
6591 CFLAndersAAResult::CFLAndersAAResult(const TargetLibraryInfo &TLI) : TLI(TLI) {}
6692 CFLAndersAAResult::CFLAndersAAResult(CFLAndersAAResult &&RHS)
6793 : AAResultBase(std::move(RHS)), TLI(RHS.TLI) {}
68 CFLAndersAAResult::~CFLAndersAAResult() {}
94 CFLAndersAAResult::~CFLAndersAAResult() = default;
6995
7096 namespace {
7197
94120 FlowToMemAliasReadWrite,
95121 };
96122
97 typedef std::bitset<7> StateSet;
123 using StateSet = std::bitset<7>;
124
98125 const unsigned ReadOnlyStateMask =
99126 (1U << static_cast(MatchState::FlowFromReadOnly)) |
100127 (1U << static_cast(MatchState::FlowFromMemAliasReadOnly));
129156 // We use ReachabilitySet to keep track of value aliases (The nonterminal "V" in
130157 // the paper) during the analysis.
131158 class ReachabilitySet {
132 typedef DenseMap ValueStateMap;
133 typedef DenseMap ValueReachMap;
159 using ValueStateMap = DenseMap;
160 using ValueReachMap = DenseMap;
161
134162 ValueReachMap ReachMap;
135163
136164 public:
137 typedef ValueStateMap::const_iterator const_valuestate_iterator;
138 typedef ValueReachMap::const_iterator const_value_iterator;
165 using const_valuestate_iterator = ValueStateMap::const_iterator;
166 using const_value_iterator = ValueReachMap::const_iterator;
139167
140168 // Insert edge 'From->To' at state 'State'
141169 bool insert(InstantiatedValue From, InstantiatedValue To, MatchState State) {
168196 // We use AliasMemSet to keep track of all memory aliases (the nonterminal "M"
169197 // in the paper) during the analysis.
170198 class AliasMemSet {
171 typedef DenseSet MemSet;
172 typedef DenseMap MemMapType;
199 using MemSet = DenseSet;
200 using MemMapType = DenseMap;
201
173202 MemMapType MemMap;
174203
175204 public:
176 typedef MemSet::const_iterator const_mem_iterator;
205 using const_mem_iterator = MemSet::const_iterator;
177206
178207 bool insert(InstantiatedValue LHS, InstantiatedValue RHS) {
179208 // Top-level values can never be memory aliases because one cannot take the
192221
193222 // We use AliasAttrMap to keep track of the AliasAttr of each node.
194223 class AliasAttrMap {
195 typedef DenseMap MapType;
224 using MapType = DenseMap;
225
196226 MapType AttrMap;
197227
198228 public:
199 typedef MapType::const_iterator const_iterator;
229 using const_iterator = MapType::const_iterator;
200230
201231 bool add(InstantiatedValue V, AliasAttrs Attr) {
202232 auto &OldAttr = AttrMap[V];
233263 };
234264 SmallVector FromRecords, ToRecords;
235265 };
236 }
266
267 } // end anonymous namespace
237268
238269 namespace llvm {
270
239271 // Specialize DenseMapInfo for OffsetValue.
240272 template <> struct DenseMapInfo {
241273 static OffsetValue getEmptyKey() {
242274 return OffsetValue{DenseMapInfo::getEmptyKey(),
243275 DenseMapInfo::getEmptyKey()};
244276 }
277
245278 static OffsetValue getTombstoneKey() {
246279 return OffsetValue{DenseMapInfo::getTombstoneKey(),
247280 DenseMapInfo::getEmptyKey()};
248281 }
282
249283 static unsigned getHashValue(const OffsetValue &OVal) {
250284 return DenseMapInfo>::getHashValue(
251285 std::make_pair(OVal.Val, OVal.Offset));
252286 }
287
253288 static bool isEqual(const OffsetValue &LHS, const OffsetValue &RHS) {
254289 return LHS == RHS;
255290 }
262297 DenseMapInfo::getEmptyKey(),
263298 DenseMapInfo::getEmptyKey()};
264299 }
300
265301 static OffsetInstantiatedValue getTombstoneKey() {
266302 return OffsetInstantiatedValue{
267303 DenseMapInfo::getTombstoneKey(),
268304 DenseMapInfo::getEmptyKey()};
269305 }
306
270307 static unsigned getHashValue(const OffsetInstantiatedValue &OVal) {
271308 return DenseMapInfo>::getHashValue(
272309 std::make_pair(OVal.IVal, OVal.Offset));
273310 }
311
274312 static bool isEqual(const OffsetInstantiatedValue &LHS,
275313 const OffsetInstantiatedValue &RHS) {
276314 return LHS == RHS;
277315 }
278316 };
279 }
317
318 } // end namespace llvm
280319
281320 class CFLAndersAAResult::FunctionInfo {
282321 /// Map a value to other values that may alias it
653692 };
654693
655694 switch (Item.State) {
656 case MatchState::FlowFromReadOnly: {
695 case MatchState::FlowFromReadOnly:
657696 NextRevAssignState(MatchState::FlowFromReadOnly);
658697 NextAssignState(MatchState::FlowToReadWrite);
659698 NextMemState(MatchState::FlowFromMemAliasReadOnly);
660699 break;
661 }
662 case MatchState::FlowFromMemAliasNoReadWrite: {
700
701 case MatchState::FlowFromMemAliasNoReadWrite:
663702 NextRevAssignState(MatchState::FlowFromReadOnly);
664703 NextAssignState(MatchState::FlowToWriteOnly);
665704 break;
666 }
667 case MatchState::FlowFromMemAliasReadOnly: {
705
706 case MatchState::FlowFromMemAliasReadOnly:
668707 NextRevAssignState(MatchState::FlowFromReadOnly);
669708 NextAssignState(MatchState::FlowToReadWrite);
670709 break;
671 }
672 case MatchState::FlowToWriteOnly: {
710
711 case MatchState::FlowToWriteOnly:
673712 NextAssignState(MatchState::FlowToWriteOnly);
674713 NextMemState(MatchState::FlowToMemAliasWriteOnly);
675714 break;
676 }
677 case MatchState::FlowToReadWrite: {
715
716 case MatchState::FlowToReadWrite:
678717 NextAssignState(MatchState::FlowToReadWrite);
679718 NextMemState(MatchState::FlowToMemAliasReadWrite);
680719 break;
681 }
682 case MatchState::FlowToMemAliasWriteOnly: {
720
721 case MatchState::FlowToMemAliasWriteOnly:
683722 NextAssignState(MatchState::FlowToWriteOnly);
684723 break;
685 }
686 case MatchState::FlowToMemAliasReadWrite: {
724
725 case MatchState::FlowToMemAliasReadWrite:
687726 NextAssignState(MatchState::FlowToReadWrite);
688727 break;
689 }
690728 }
691729 }
692730
None //======- CFLGraph.h - Abstract stratified sets implementation. --------======//
0 //===- CFLGraph.h - Abstract stratified sets implementation. -----*- C++-*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
55 // License. See LICENSE.TXT for details.
66 //
77 //===----------------------------------------------------------------------===//
8 //
89 /// \file
910 /// This file defines CFLGraph, an auxiliary data structure used by CFL-based
1011 /// alias analysis.
11 ///
12 //
1213 //===----------------------------------------------------------------------===//
1314
14 #ifndef LLVM_ANALYSIS_CFLGRAPH_H
15 #define LLVM_ANALYSIS_CFLGRAPH_H
15 #ifndef LLVM_LIB_ANALYSIS_CFLGRAPH_H
16 #define LLVM_LIB_ANALYSIS_CFLGRAPH_H
1617
1718 #include "AliasAnalysisSummary.h"
19 #include "llvm/ADT/APInt.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/iterator_range.h"
1823 #include "llvm/Analysis/MemoryBuiltins.h"
24 #include "llvm/Analysis/TargetLibraryInfo.h"
25 #include "llvm/IR/Argument.h"
26 #include "llvm/IR/BasicBlock.h"
27 #include "llvm/IR/CallSite.h"
28 #include "llvm/IR/Constants.h"
29 #include "llvm/IR/DataLayout.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/GlobalValue.h"
1932 #include "llvm/IR/InstVisitor.h"
33 #include "llvm/IR/InstrTypes.h"
34 #include "llvm/IR/Instruction.h"
2035 #include "llvm/IR/Instructions.h"
36 #include "llvm/IR/Operator.h"
37 #include "llvm/IR/Type.h"
38 #include "llvm/IR/Value.h"
39 #include "llvm/Support/Casting.h"
40 #include "llvm/Support/ErrorHandling.h"
41 #include
42 #include
43 #include
2144
2245 namespace llvm {
2346 namespace cflaa {
3457 /// I+1) and a reference edge to (X, I-1).
3558 class CFLGraph {
3659 public:
37 typedef InstantiatedValue Node;
60 using Node = InstantiatedValue;
3861
3962 struct Edge {
4063 Node Other;
4164 int64_t Offset;
4265 };
4366
44 typedef std::vector EdgeList;
67 using EdgeList = std::vector;
4568
4669 struct NodeInfo {
4770 EdgeList Edges, ReverseEdges;
7396 };
7497
7598 private:
76 typedef DenseMap ValueMap;
99 using ValueMap = DenseMap;
100
77101 ValueMap ValueImpls;
78102
79103 NodeInfo *getNode(Node N) {
84108 }
85109
86110 public:
87 typedef ValueMap::const_iterator const_value_iterator;
111 using const_value_iterator = ValueMap::const_iterator;
88112
89113 bool addNode(Node N, AliasAttrs Attr = AliasAttrs()) {
90114 assert(N.Val != nullptr);
495519 addNode(Ptr, getAttrEscaped());
496520 break;
497521 }
498 case Instruction::IntToPtr: {
522 case Instruction::IntToPtr:
499523 addNode(CE, getAttrUnknown());
500524 break;
501 }
525
502526 case Instruction::BitCast:
503527 case Instruction::AddrSpaceCast:
504528 case Instruction::Trunc:
570594 case Instruction::LShr:
571595 case Instruction::AShr:
572596 case Instruction::ICmp:
573 case Instruction::FCmp: {
597 case Instruction::FCmp:
574598 addAssignEdge(CE->getOperand(0), CE);
575599 addAssignEdge(CE->getOperand(1), CE);
576600 break;
577 }
601
578602 default:
579603 llvm_unreachable("Unknown instruction type encountered!");
580604 }
639663 return ReturnedValues;
640664 }
641665 };
642 }
643 }
644
645 #endif
666
667 } // end namespace cflaa
668 } // end namespace llvm
669
670 #endif // LLVM_LIB_ANALYSIS_CFLGRAPH_H
None //- CFLSteensAliasAnalysis.cpp - Unification-based Alias Analysis ---*- C++-*-//
0 //===- CFLSteensAliasAnalysis.cpp - Unification-based Alias Analysis ------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
3535 // FunctionPasses to run concurrently.
3636
3737 #include "llvm/Analysis/CFLSteensAliasAnalysis.h"
38 #include "AliasAnalysisSummary.h"
3839 #include "CFLGraph.h"
3940 #include "StratifiedSets.h"
4041 #include "llvm/ADT/DenseMap.h"
41 #include "llvm/ADT/None.h"
4242 #include "llvm/ADT/Optional.h"
43 #include "llvm/ADT/SmallVector.h"
4344 #include "llvm/Analysis/TargetLibraryInfo.h"
4445 #include "llvm/IR/Constants.h"
4546 #include "llvm/IR/Function.h"
47 #include "llvm/IR/Type.h"
48 #include "llvm/IR/Value.h"
4649 #include "llvm/Pass.h"
47 #include "llvm/Support/Compiler.h"
4850 #include "llvm/Support/Debug.h"
49 #include "llvm/Support/ErrorHandling.h"
5051 #include "llvm/Support/raw_ostream.h"
5152 #include
5253 #include
54 #include
5355 #include
54 #include <tuple>
56 #include <utility>
5557
5658 using namespace llvm;
5759 using namespace llvm::cflaa;
6264 : AAResultBase(), TLI(TLI) {}
6365 CFLSteensAAResult::CFLSteensAAResult(CFLSteensAAResult &&Arg)
6466 : AAResultBase(std::move(Arg)), TLI(Arg.TLI) {}
65 CFLSteensAAResult::~CFLSteensAAResult() {}
67 CFLSteensAAResult::~CFLSteensAAResult() = default;
6668
6769 /// Information we have about a function and would like to keep around.
6870 class CFLSteensAAResult::FunctionInfo {
7678 const StratifiedSets &getStratifiedSets() const {
7779 return Sets;
7880 }
81
7982 const AliasSummary &getAliasSummary() const { return Summary; }
8083 };
8184
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/Analysis/LazyCallGraph.h"
10 #include "llvm/ADT/ArrayRef.h"
1011 #include "llvm/ADT/STLExtras.h"
1112 #include "llvm/ADT/ScopeExit.h"
1213 #include "llvm/ADT/Sequence.h"
14 #include "llvm/ADT/SmallPtrSet.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/iterator_range.h"
17 #include "llvm/Analysis/TargetLibraryInfo.h"
1318 #include "llvm/IR/CallSite.h"
14 #include "llvm/IR/InstVisitor.h"
15 #include "llvm/IR/Instructions.h"
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/GlobalVariable.h"
21 #include "llvm/IR/Instruction.h"
22 #include "llvm/IR/Module.h"
1623 #include "llvm/IR/PassManager.h"
24 #include "llvm/Support/Casting.h"
25 #include "llvm/Support/Compiler.h"
1726 #include "llvm/Support/Debug.h"
1827 #include "llvm/Support/GraphWriter.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include
30 #include
31 #include
32 #include
33 #include
34 #include
1935 #include
2036
2137 using namespace llvm;
13381354 // after this edge insertion.
13391355 assert(G->lookupRefSCC(SourceN) == this && "Source must be in this RefSCC.");
13401356 RefSCC &TargetRC = *G->lookupRefSCC(TargetN);
1341 if (&TargetRC == this) {
1342
1357 if (&TargetRC == this)
13431358 return;
1344 }
13451359
13461360 #ifdef EXPENSIVE_CHECKS
13471361 assert(TargetRC.isDescendantOf(*this) &&
15431557 void LazyCallGraph::buildGenericSCCs(RootsT &&Roots, GetBeginT &&GetBegin,
15441558 GetEndT &&GetEnd, GetNodeT &&GetNode,
15451559 FormSCCCallbackT &&FormSCC) {
1546 typedef decltype(GetBegin(std::declval())) EdgeItT;
1560 using EdgeItT = decltype(GetBegin(std::declval()));
15471561
15481562 SmallVector, 16> DFSStack;
15491563 SmallVector PendingSCCStack;