llvm.org GIT mirror llvm / 4114bcf
[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@308936 91177308-0d34-0410-b5e6-96231b3b80d8 Eugene Zelenko 3 years ago
12 changed file(s) with 255 addition(s) and 185 deletion(s). Raw diff Collapse all Expand all
1717 #define LLVM_ANALYSIS_ALIASSETTRACKER_H
1818
1919 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/DenseMapInfo.h"
2021 #include "llvm/ADT/ilist.h"
2122 #include "llvm/ADT/ilist_node.h"
2223 #include "llvm/Analysis/AliasAnalysis.h"
24 #include "llvm/IR/Instruction.h"
2325 #include "llvm/IR/Metadata.h"
2426 #include "llvm/IR/ValueHandle.h"
27 #include "llvm/Support/Casting.h"
28 #include
29 #include
30 #include
31 #include
2532 #include
2633
2734 namespace llvm {
2835
36 class AliasSetTracker;
37 class BasicBlock;
2938 class LoadInst;
39 class MemSetInst;
40 class MemTransferInst;
41 class raw_ostream;
3042 class StoreInst;
3143 class VAArgInst;
32 class MemSetInst;
33 class AliasSetTracker;
34 class AliasSet;
44 class Value;
3545
3646 class AliasSet : public ilist_node {
3747 friend class AliasSetTracker;
3848
3949 class PointerRec {
4050 Value *Val; // The pointer this record corresponds to.
41 PointerRec **PrevInList, *NextInList;
42 AliasSet *AS;
43 uint64_t Size;
51 PointerRec **PrevInList = nullptr;
52 PointerRec *NextInList = nullptr;
53 AliasSet *AS = nullptr;
54 uint64_t Size = 0;
4455 AAMDNodes AAInfo;
4556
4657 public:
4758 PointerRec(Value *V)
48 : Val(V), PrevInList(nullptr), NextInList(nullptr), AS(nullptr), Size(0),
49 AAInfo(DenseMapInfo::getEmptyKey()) {}
59 : Val(V), AAInfo(DenseMapInfo::getEmptyKey()) {}
5060
5161 Value *getValue() const { return Val; }
5262
120130 };
121131
122132 // Doubly linked list of nodes.
123 PointerRec *PtrList, **PtrListEnd;
133 PointerRec *PtrList = nullptr;
134 PointerRec **PtrListEnd;
124135 // Forwarding pointer.
125 AliasSet *Forward;
136 AliasSet *Forward = nullptr;
126137
127138 /// All instructions without a specific address in this alias set.
128139 /// In rare cases this vector can have a null'ed out WeakVH
166177 /// True if this alias set contains volatile loads or stores.
167178 unsigned Volatile : 1;
168179
169 unsigned SetSize;
180 unsigned SetSize = 0;
170181
171182 void addRef() { ++RefCount; }
172183
182193 }
183194
184195 public:
196 AliasSet(const AliasSet &) = delete;
197 AliasSet &operator=(const AliasSet &) = delete;
198
185199 /// Accessors...
186200 bool isRef() const { return Access & RefAccess; }
187201 bool isMod() const { return Access & ModAccess; }
248262 private:
249263 // Can only be created by AliasSetTracker.
250264 AliasSet()
251 : PtrList(nullptr), PtrListEnd(&PtrList), Forward(nullptr), RefCount(0),
252 AliasAny(false), Access(NoAccess), Alias(SetMustAlias),
253 Volatile(false), SetSize(0) {}
254
255 AliasSet(const AliasSet &AS) = delete;
256 void operator=(const AliasSet &AS) = delete;
265 : PtrListEnd(&PtrList), RefCount(0), AliasAny(false), Access(NoAccess),
266 Alias(SetMustAlias), Volatile(false) {}
257267
258268 PointerRec *getSomePointer() const {
259269 return PtrList;
280290 const AAMDNodes &AAInfo,
281291 bool KnownMustAlias = false);
282292 void addUnknownInst(Instruction *I, AliasAnalysis &AA);
293
283294 void removeUnknownInst(AliasSetTracker &AST, Instruction *I) {
284295 bool WasEmpty = UnknownInsts.empty();
285296 for (size_t i = 0, e = UnknownInsts.size(); i != e; ++i)
291302 if (!WasEmpty && UnknownInsts.empty())
292303 dropRef(AST);
293304 }
305
294306 void setVolatile() { Volatile = true; }
295307
296308 public:
311323 /// Value is deleted.
312324 class ASTCallbackVH final : public CallbackVH {
313325 AliasSetTracker *AST;
326
314327 void deleted() override;
315328 void allUsesReplacedWith(Value *) override;
316329
317330 public:
318331 ASTCallbackVH(Value *V, AliasSetTracker *AST = nullptr);
332
319333 ASTCallbackVH &operator=(Value *V);
320334 };
321335 /// Traits to tell DenseMap that tell us how to compare and hash the value
325339 AliasAnalysis &AA;
326340 ilist AliasSets;
327341
328 typedef DenseMap
329 ASTCallbackVHDenseMapInfo>
330 PointerMapType;
342 using PointerMapType = DenseMap
343 ASTCallbackVHDenseMapInfo>;
331344
332345 // Map from pointers to their node
333346 PointerMapType PointerMap;
335348 public:
336349 /// Create an empty collection of AliasSets, and use the specified alias
337350 /// analysis object to disambiguate load and store addresses.
338 explicit AliasSetTracker(AliasAnalysis &aa)
339 : AA(aa), TotalMayAliasSetSize(0), AliasAnyAS(nullptr) {}
351 explicit AliasSetTracker(AliasAnalysis &aa) : AA(aa) {}
340352 ~AliasSetTracker() { clear(); }
341353
342354 /// These methods are used to add different types of instructions to the alias
400412 /// tracker already knows about a value, it will ignore the request.
401413 void copyValue(Value *From, Value *To);
402414
403 typedef ilist::iterator iterator;
404 typedef ilist::const_iterator const_iterator;
415 using iterator = ilist::iterator;
416 using const_iterator = ilist::const_iterator;
405417
406418 const_iterator begin() const { return AliasSets.begin(); }
407419 const_iterator end() const { return AliasSets.end(); }
416428 friend class AliasSet;
417429
418430 // The total number of pointers contained in all "may" alias sets.
419 unsigned TotalMayAliasSetSize;
431 unsigned TotalMayAliasSetSize = 0;
420432
421433 // A non-null value signifies this AST is saturated. A saturated AST lumps
422434 // all pointers into a single "May" set.
423 AliasSet *AliasAnyAS;
435 AliasSet *AliasAnyAS = nullptr;
424436
425437 void removeAliasSet(AliasSet *AS);
426438
450462 return OS;
451463 }
452464
453 } // End llvm namespace
454
455 #endif
465 } // end namespace llvm
466
467 #endif // LLVM_ANALYSIS_ALIASSETTRACKER_H
5353 #include "llvm/IR/PassManager.h"
5454 #include "llvm/IR/ValueHandle.h"
5555 #include "llvm/Pass.h"
56 #include
5657 #include
58 #include
59 #include
60 #include
5761
5862 namespace llvm {
5963
60 class Function;
64 class CallGraphNode;
6165 class Module;
62 class CallGraphNode;
66 class raw_ostream;
6367
6468 /// \brief The basic data container for the call graph of a \c Module of IR.
6569 ///
6973 class CallGraph {
7074 Module &M;
7175
72 typedef std::map>
73 FunctionMapTy;
76 using FunctionMapTy =
77 std::map>;
7478
7579 /// \brief A map from \c Function* to \c CallGraphNode*.
7680 FunctionMapTy FunctionMap;
102106 void print(raw_ostream &OS) const;
103107 void dump() const;
104108
105 typedef FunctionMapTy::iterator iterator;
106 typedef FunctionMapTy::const_iterator const_iterator;
109 using iterator = FunctionMapTy::iterator;
110 using const_iterator = FunctionMapTy::const_iterator;
107111
108112 /// \brief Returns the module the call graph corresponds to.
109113 Module &getModule() const { return M; }
161165 public:
162166 /// \brief A pair of the calling instruction (a call or invoke)
163167 /// and the call graph node being called.
164 typedef std::pair CallRecord;
168 using CallRecord = std::pair;
165169
166170 public:
167 typedef std::vector CalledFunctionsVector;
171 using CalledFunctionsVector = std::vector;
168172
169173 /// \brief Creates a node for the specified function.
170 inline CallGraphNode(Function *F) : F(F), NumReferences(0) {}
174 inline CallGraphNode(Function *F) : F(F) {}
175
176 CallGraphNode(const CallGraphNode &) = delete;
177 CallGraphNode &operator=(const CallGraphNode &) = delete;
171178
172179 ~CallGraphNode() {
173180 assert(NumReferences == 0 && "Node deleted while references remain");
174181 }
175182
176 typedef std::vector::iterator iterator;
177 typedef std::vector::const_iterator const_iterator;
183 using iterator = std::vector::iterator;
184 using const_iterator = std::vector::const_iterator;
178185
179186 /// \brief Returns the function that this call graph node represents.
180187 Function *getFunction() const { return F; }
267274
268275 /// \brief The number of times that this CallGraphNode occurs in the
269276 /// CalledFunctions array of this or other CallGraphNodes.
270 unsigned NumReferences;
271
272 CallGraphNode(const CallGraphNode &) = delete;
273 void operator=(const CallGraphNode &) = delete;
277 unsigned NumReferences = 0;
274278
275279 void DropRef() { --NumReferences; }
276280 void AddRef() { ++NumReferences; }
286290 /// resulting data.
287291 class CallGraphAnalysis : public AnalysisInfoMixin {
288292 friend AnalysisInfoMixin;
293
289294 static AnalysisKey Key;
290295
291296 public:
292 /// \brief A formulaic typedef to inform clients of the result type.
293 typedef CallGraph Result;
297 /// \brief A formulaic type to inform clients of the result type.
298 using Result = CallGraph;
294299
295300 /// \brief Compute the \c CallGraph for the module \c M.
296301 ///
304309
305310 public:
306311 explicit CallGraphPrinterPass(raw_ostream &OS) : OS(OS) {}
312
307313 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
308314 };
309315
328334 const CallGraph &getCallGraph() const { return *G; }
329335 CallGraph &getCallGraph() { return *G; }
330336
331 typedef CallGraph::iterator iterator;
332 typedef CallGraph::const_iterator const_iterator;
337 using iterator = CallGraph::iterator;
338 using const_iterator = CallGraph::const_iterator;
333339
334340 /// \brief Returns the module the call graph corresponds to.
335341 Module &getModule() const { return G->getModule(); }
398404 // Provide graph traits for tranversing call graphs using standard graph
399405 // traversals.
400406 template <> struct GraphTraits {
401 typedef CallGraphNode *NodeRef;
402
403 typedef CallGraphNode::CallRecord CGNPairTy;
407 using NodeRef = CallGraphNode *;
408 using CGNPairTy = CallGraphNode::CallRecord;
404409
405410 static NodeRef getEntryNode(CallGraphNode *CGN) { return CGN; }
406
407411 static CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
408412
409 typedef mapped_iterator
410 ChildIteratorType;
413 using ChildIteratorType =
414 mapped_iterator;
411415
412416 static ChildIteratorType child_begin(NodeRef N) {
413417 return ChildIteratorType(N->begin(), &CGNGetValue);
414418 }
419
415420 static ChildIteratorType child_end(NodeRef N) {
416421 return ChildIteratorType(N->end(), &CGNGetValue);
417422 }
418423 };
419424
420425 template <> struct GraphTraits {
421 typedef const CallGraphNode *NodeRef;
422
423 typedef CallGraphNode::CallRecord CGNPairTy;
426 using NodeRef = const CallGraphNode *;
427 using CGNPairTy = CallGraphNode::CallRecord;
424428
425429 static NodeRef getEntryNode(const CallGraphNode *CGN) { return CGN; }
426
427430 static const CallGraphNode *CGNGetValue(CGNPairTy P) { return P.second; }
428431
429 typedef mapped_iterator
430 ChildIteratorType;
432 using ChildIteratorType =
433 mapped_iterator;
431434
432435 static ChildIteratorType child_begin(NodeRef N) {
433436 return ChildIteratorType(N->begin(), &CGNGetValue);
434437 }
438
435439 static ChildIteratorType child_end(NodeRef N) {
436440 return ChildIteratorType(N->end(), &CGNGetValue);
437441 }
439443
440444 template <>
441445 struct GraphTraits : public GraphTraits {
446 using PairTy =
447 std::pair>;
448
442449 static NodeRef getEntryNode(CallGraph *CGN) {
443450 return CGN->getExternalCallingNode(); // Start at the external node!
444451 }
445 typedef std::pair>
446 PairTy;
452
447453 static CallGraphNode *CGGetValuePtr(const PairTy &P) {
448454 return P.second.get();
449455 }
450456
451457 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
452 typedef mapped_iterator
453 nodes_iterator;
458 using nodes_iterator =
459 mapped_iterator;
460
454461 static nodes_iterator nodes_begin(CallGraph *CG) {
455462 return nodes_iterator(CG->begin(), &CGGetValuePtr);
456463 }
464
457465 static nodes_iterator nodes_end(CallGraph *CG) {
458466 return nodes_iterator(CG->end(), &CGGetValuePtr);
459467 }
462470 template <>
463471 struct GraphTraits : public GraphTraits<
464472 const CallGraphNode *> {
473 using PairTy =
474 std::pair>;
475
465476 static NodeRef getEntryNode(const CallGraph *CGN) {
466477 return CGN->getExternalCallingNode(); // Start at the external node!
467478 }
468 typedef std::pair>
469 PairTy;
479
470480 static const CallGraphNode *CGGetValuePtr(const PairTy &P) {
471481 return P.second.get();
472482 }
473483
474484 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
475 typedef mapped_iterator
476 nodes_iterator;
485 using nodes_iterator =
486 mapped_iterator;
487
477488 static nodes_iterator nodes_begin(const CallGraph *CG) {
478489 return nodes_iterator(CG->begin(), &CGGetValuePtr);
479490 }
491
480492 static nodes_iterator nodes_end(const CallGraph *CG) {
481493 return nodes_iterator(CG->end(), &CGGetValuePtr);
482494 }
483495 };
484496
485 } // End llvm namespace
486
487 #endif
497 } // end namespace llvm
498
499 #endif // LLVM_ANALYSIS_CALLGRAPH_H
1717 #ifndef LLVM_ANALYSIS_DOMINANCEFRONTIER_H
1818 #define LLVM_ANALYSIS_DOMINANCEFRONTIER_H
1919
20 #include "llvm/IR/Dominators.h"
20 #include "llvm/ADT/GraphTraits.h"
2121 #include "llvm/IR/PassManager.h"
22 #include "llvm/Pass.h"
23 #include "llvm/Support/GenericDomTree.h"
24 #include
2225 #include
2326 #include
27 #include
28 #include
2429
2530 namespace llvm {
31
32 class Function;
33 class raw_ostream;
2634
2735 //===----------------------------------------------------------------------===//
2836 /// DominanceFrontierBase - Common base class for computing forward and inverse
3038 ///
3139 template
3240 class DominanceFrontierBase {
33 public:
34 typedef std::set DomSetType; // Dom set for a bb
35 typedef std::map DomSetMapType; // Dom set map
41 public:
42 using DomSetType = std::set; // Dom set for a bb
43 using DomSetMapType = std::map; // Dom set map
3644
3745 protected:
38 typedef GraphTraits BlockTraits;
46 using BlockTraits = GraphTraits;
3947
4048 DomSetMapType Frontiers;
4149 std::vector Roots;
4250 static constexpr bool IsPostDominators = IsPostDom;
4351
44 public:
45 DominanceFrontierBase() {}
52 public:
53 DominanceFrontierBase() = default;
4654
4755 /// getRoots - Return the root blocks of the current CFG. This may include
4856 /// multiple blocks if we are computing post dominators. For forward
4957 /// dominators, this will always be a single block (the entry node).
50 ///
5158 inline const std::vector &getRoots() const {
5259 return Roots;
5360 }
5865 }
5966
6067 /// isPostDominator - Returns true if analysis based of postdoms
61 ///
6268 bool isPostDominator() const {
6369 return IsPostDominators;
6470 }
6874 }
6975
7076 // Accessor interface:
71 typedef typename DomSetMapType::iterator iterator;
72 typedef typename DomSetMapType::const_iterator const_iterator;
77 using iterator = typename DomSetMapType::iterator;
78 using const_iterator = typename DomSetMapType::const_iterator;
79
7380 iterator begin() { return Frontiers.begin(); }
7481 const_iterator begin() const { return Frontiers.begin(); }
7582 iterator end() { return Frontiers.end(); }
114121 template
115122 class ForwardDominanceFrontierBase
116123 : public DominanceFrontierBase {
117 private:
118 typedef GraphTraits BlockTraits;
119
120 public:
121 typedef DomTreeBase DomTreeT;
122 typedef DomTreeNodeBase DomTreeNodeT;
123 typedef typename DominanceFrontierBase::DomSetType DomSetType;
124
125 void analyze(DomTreeT &DT) {
126 this->Roots = DT.getRoots();
127 assert(this->Roots.size() == 1 &&
128 "Only one entry block for forward domfronts!");
129 calculate(DT, DT[this->Roots[0]]);
124 private:
125 using BlockTraits = GraphTraits;
126
127 public:
128 using DomTreeT = DomTreeBase;
129 using DomTreeNodeT = DomTreeNodeBase;
130 using DomSetType = typename DominanceFrontierBase::DomSetType;
131
132 void analyze(DomTreeT &DT) {
133 this->Roots = DT.getRoots();
134 assert(this->Roots.size() == 1 &&
135 "Only one entry block for forward domfronts!");
136 calculate(DT, DT[this->Roots[0]]);
130137 }
131138
132139 const DomSetType &calculate(const DomTreeT &DT, const DomTreeNodeT *Node);
134141
135142 class DominanceFrontier : public ForwardDominanceFrontierBase {
136143 public:
137 typedef DomTreeBase DomTreeT;
138 typedef DomTreeNodeBase DomTreeNodeT;
139 typedef DominanceFrontierBase::DomSetType DomSetType;
140 typedef DominanceFrontierBase::iterator iterator;
141 typedef DominanceFrontierBase::const_iterator
142 const_iterator;
143
144 /// Handle invalidation explicitly.
145 bool invalidate(Function &F, const PreservedAnalyses &PA,
146 FunctionAnalysisManager::Invalidator &);
144 using DomTreeT = DomTreeBase;
145 using DomTreeNodeT = DomTreeNodeBase;
146 using DomSetType = DominanceFrontierBase::DomSetType;
147 using iterator = DominanceFrontierBase::iterator;
148 using const_iterator =
149 DominanceFrontierBase::const_iterator;
150
151 /// Handle invalidation explicitly.
152 bool invalidate(Function &F, const PreservedAnalyses &PA,
153 FunctionAnalysisManager::Invalidator &);
147154 };
148155
149156 class DominanceFrontierWrapperPass : public FunctionPass {
150157 DominanceFrontier DF;
158
151159 public:
152160 static char ID; // Pass ID, replacement for typeid
153161
175183 class DominanceFrontierAnalysis
176184 : public AnalysisInfoMixin {
177185 friend AnalysisInfoMixin;
186
178187 static AnalysisKey Key;
179188
180189 public:
181 /// \brief Provide the result typedef for this analysis pass.
182 typedef DominanceFrontier Result;
190 /// \brief Provide the result type for this analysis pass.
191 using Result = DominanceFrontier;
183192
184193 /// \brief Run the analysis pass over a function and produce a dominator tree.
185194 DominanceFrontier run(Function &F, FunctionAnalysisManager &AM);
192201
193202 public:
194203 explicit DominanceFrontierPrinterPass(raw_ostream &OS);
204
195205 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
196206 };
197207
198 } // End llvm namespace
199
200 #endif
208 } // end namespace llvm
209
210 #endif // LLVM_ANALYSIS_DOMINANCEFRONTIER_H
1717 #ifndef LLVM_ANALYSIS_DOMINANCEFRONTIERIMPL_H
1818 #define LLVM_ANALYSIS_DOMINANCEFRONTIERIMPL_H
1919
20 #include "llvm/ADT/GraphTraits.h"
2021 #include "llvm/ADT/SmallPtrSet.h"
2122 #include "llvm/Analysis/DominanceFrontier.h"
2223 #include "llvm/Support/Debug.h"
2324 #include "llvm/Support/GenericDomTree.h"
25 #include "llvm/Support/raw_ostream.h"
26 #include
27 #include
28 #include
29 #include
2430
2531 namespace llvm {
2632
2733 template
2834 class DFCalculateWorkObject {
2935 public:
30 typedef DomTreeNodeBase DomTreeNodeT;
36 using DomTreeNodeT = DomTreeNodeBase;
3137
3238 DFCalculateWorkObject(BlockT *B, BlockT *P, const DomTreeNodeT *N,
3339 const DomTreeNodeT *PN)
3440 : currentBB(B), parentBB(P), Node(N), parentNode(PN) {}
41
3542 BlockT *currentBB;
3643 BlockT *parentBB;
3744 const DomTreeNodeT *Node;
218225 return *Result;
219226 }
220227
221 } // End llvm namespace
222
223 #endif
228 } // end namespace llvm
229
230 #endif // LLVM_ANALYSIS_DOMINANCEFRONTIERIMPL_H
3838 /// interval. Also, any loops in this interval must go through the HeaderNode.
3939 ///
4040 BasicBlock *HeaderNode;
41
4142 public:
42 typedef std::vector::iterator succ_iterator;
43 typedef std::vector::iterator pred_iterator;
44 typedef std::vector::iterator node_iterator;
43 using succ_iterator = std::vector::iterator;
44 using pred_iterator = std::vector::iterator;
45 using node_iterator = std::vector::iterator;
4546
4647 inline Interval(BasicBlock *Header) : HeaderNode(Header) {
4748 Nodes.push_back(Header);
5051 inline BasicBlock *getHeaderNode() const { return HeaderNode; }
5152
5253 /// Nodes - The basic blocks in this interval.
53 ///
5454 std::vector Nodes;
5555
5656 /// Successors - List of BasicBlocks that are reachable directly from nodes in
5757 /// this interval, but are not in the interval themselves.
5858 /// These nodes necessarily must be header nodes for other intervals.
59 ///
6059 std::vector Successors;
6160
6261 /// Predecessors - List of BasicBlocks that have this Interval's header block
6362 /// as one of their successors.
64 ///
6563 std::vector Predecessors;
6664
6765 /// contains - Find out if a basic block is in this interval
8785 /// Equality operator. It is only valid to compare two intervals from the
8886 /// same partition, because of this, all we have to check is the header node
8987 /// for equality.
90 ///
9188 inline bool operator==(const Interval &I) const {
9289 return HeaderNode == I.HeaderNode;
9390 }
120117 }
121118
122119 template <> struct GraphTraits {
123 typedef Interval *NodeRef;
124 typedef Interval::succ_iterator ChildIteratorType;
120 using NodeRef = Interval *;
121 using ChildIteratorType = Interval::succ_iterator;
125122
126123 static NodeRef getEntryNode(Interval *I) { return I; }
127124
130127 static ChildIteratorType child_end(NodeRef N) { return succ_end(N); }
131128 };
132129
133 template <> struct GraphTraits > {
134 typedef Interval *NodeRef;
135 typedef Interval::pred_iterator ChildIteratorType;
130 template <> struct GraphTraits> {
131 using NodeRef = Interval *;
132 using ChildIteratorType = Interval::pred_iterator;
133
136134 static NodeRef getEntryNode(Inverse G) { return G.Graph; }
137135 static ChildIteratorType child_begin(NodeRef N) { return pred_begin(N); }
138136 static ChildIteratorType child_end(NodeRef N) { return pred_end(N); }
139137 };
140138
141 } // End llvm namespace
139 } // end namespace llvm
142140
143 #endif
141 #endif // LLVM_ANALYSIS_INTERVAL_H
3232 #ifndef LLVM_ANALYSIS_INTERVALITERATOR_H
3333 #define LLVM_ANALYSIS_INTERVALITERATOR_H
3434
35 #include "llvm/ADT/GraphTraits.h"
36 #include "llvm/Analysis/Interval.h"
3537 #include "llvm/Analysis/IntervalPartition.h"
3638 #include "llvm/IR/CFG.h"
3739 #include "llvm/IR/Function.h"
40 #include "llvm/Support/ErrorHandling.h"
3841 #include
42 #include
43 #include
3944 #include
45 #include
4046 #include
4147
4248 namespace llvm {
49
50 class BasicBlock;
4351
4452 // getNodeHeader - Given a source graph node and the source graph, return the
4553 // BasicBlock that is the header node. This is the opposite of
4654 // getSourceGraphNode.
47 //
4855 inline BasicBlock *getNodeHeader(BasicBlock *BB) { return BB; }
4956 inline BasicBlock *getNodeHeader(Interval *I) { return I->getHeaderNode(); }
5057
5158 // getSourceGraphNode - Given a BasicBlock and the source graph, return the
5259 // source graph node that corresponds to the BasicBlock. This is the opposite
5360 // of getNodeHeader.
54 //
5561 inline BasicBlock *getSourceGraphNode(Function *, BasicBlock *BB) {
5662 return BB;
5763 }
6369 // with the task of adding a node to the new interval, depending on the
6470 // type of the source node. In the case of a CFG source graph (BasicBlock
6571 // case), the BasicBlock itself is added to the interval.
66 //
6772 inline void addNodeToInterval(Interval *Int, BasicBlock *BB) {
6873 Int->Nodes.push_back(BB);
6974 }
7479 // case), the BasicBlock itself is added to the interval. In the case of
7580 // an IntervalPartition source graph (Interval case), all of the member
7681 // BasicBlocks are added to the interval.
77 //
7882 inline void addNodeToInterval(Interval *Int, Interval *I) {
7983 // Add all of the nodes in I as new nodes in Int.
8084 Int->Nodes.insert(Int->Nodes.end(), I->Nodes.begin(), I->Nodes.end());
8185 }
8286
83
84
85
86
87 template,
88 class IGT = GraphTraits > >
87 template,
88 class IGT = GraphTraits>>
8989 class IntervalIterator {
90 std::vector > IntStack;
91 std::set Visited;
90 std::vector> IntStack;
91 std::set Visited;
9292 OrigContainer_t *OrigContainer;
9393 bool IOwnMem; // If True, delete intervals when done with them
9494 // See file header for conditions of use
95
9596 public:
96 typedef std::forward_iterator_tag iterator_category;
97
98 IntervalIterator() {} // End iterator, empty stack
97 using iterator_category = std::forward_iterator_tag;
98
99 IntervalIterator() = default; // End iterator, empty stack
100
99101 IntervalIterator(Function *M, bool OwnMemory) : IOwnMem(OwnMemory) {
100102 OrigContainer = M;
101103 if (!ProcessInterval(&M->front())) {
156158
157159 return *this;
158160 }
161
159162 IntervalIterator operator++(int) { // Postincrement
160163 IntervalIterator tmp = *this;
161164 ++*this;
170173 //
171174 // This method is templated because it may operate on two different source
172175 // graphs: a basic block graph, or a preexisting interval graph.
173 //
174176 bool ProcessInterval(NodeTy *Node) {
175177 BasicBlock *Header = getNodeHeader(Node);
176178 if (!Visited.insert(Header).second)
195197 //
196198 // This method is templated because it may operate on two different source
197199 // graphs: a basic block graph, or a preexisting interval graph.
198 //
199200 void ProcessNode(Interval *Int, NodeTy *Node) {
200201 assert(Int && "Null interval == bad!");
201202 assert(Node && "Null Node == bad!");
240241 }
241242 };
242243
243 typedef IntervalIterator function_interval_iterator;
244 typedef IntervalIterator
245 interval_part_interval_iterator;
246
244 using function_interval_iterator = IntervalIterator;
245 using interval_part_interval_iterator =
246 IntervalIterator;
247247
248248 inline function_interval_iterator intervals_begin(Function *F,
249249 bool DeleteInts = true) {
262262 return interval_part_interval_iterator();
263263 }
264264
265 } // End llvm namespace
266
267 #endif
265 } // end namespace llvm
266
267 #endif // LLVM_ANALYSIS_INTERVALITERATOR_H
2222 #ifndef LLVM_ANALYSIS_INTERVALPARTITION_H
2323 #define LLVM_ANALYSIS_INTERVALPARTITION_H
2424
25 #include "llvm/Analysis/Interval.h"
2625 #include "llvm/Pass.h"
2726 #include
27 #include
2828
2929 namespace llvm {
30
31 class BasicBlock;
32 class Interval;
3033
3134 //===----------------------------------------------------------------------===//
3235 //
3740 // nodes following it.
3841 //
3942 class IntervalPartition : public FunctionPass {
40 typedef std::map IntervalMapTy;
43 using IntervalMapTy = std::map;
4144 IntervalMapTy IntervalMap;
4245
43 typedef std::vector IntervalListTy;
44 Interval *RootInterval;
45 std::vector Intervals;
46 using IntervalListTy = std::vector;
47 Interval *RootInterval = nullptr;
48 std::vector Intervals;
4649
4750 public:
4851 static char ID; // Pass identification, replacement for typeid
4952
50 IntervalPartition() : FunctionPass(ID), RootInterval(nullptr) {
53 IntervalPartition() : FunctionPass(ID) {
5154 initializeIntervalPartitionPass(*PassRegistry::getPassRegistry());
5255 }
5356
5760 // IntervalPartition ctor - Build a reduced interval partition from an
5861 // existing interval graph. This takes an additional boolean parameter to
5962 // distinguish it from a copy constructor. Always pass in false for now.
60 //
6163 IntervalPartition(IntervalPartition &I, bool);
6264
6365 // print - Show contents in human readable format...
9496 // addIntervalToPartition - Add an interval to the internal list of intervals,
9597 // and then add mappings from all of the basic blocks in the interval to the
9698 // interval itself (in the IntervalMap).
97 //
9899 void addIntervalToPartition(Interval *I);
99100
100101 // updatePredecessors - Interval generation only sets the successor fields of
101102 // the interval data structures. After interval generation is complete,
102103 // run through all of the intervals and propagate successor info as
103104 // predecessor info.
104 //
105105 void updatePredecessors(Interval *Int);
106106 };
107107
108 } // End llvm namespace
108 } // end namespace llvm
109109
110 #endif
110 #endif // LLVM_ANALYSIS_INTERVALPARTITION_H
1212
1313 #include "llvm/Analysis/AliasSetTracker.h"
1414 #include "llvm/Analysis/AliasAnalysis.h"
15 #include "llvm/Analysis/MemoryLocation.h"
16 #include "llvm/IR/CallSite.h"
17 #include "llvm/IR/Constants.h"
1518 #include "llvm/IR/DataLayout.h"
19 #include "llvm/IR/Function.h"
1620 #include "llvm/IR/InstIterator.h"
21 #include "llvm/IR/Instruction.h"
1722 #include "llvm/IR/Instructions.h"
1823 #include "llvm/IR/IntrinsicInst.h"
19 #include "llvm/IR/LLVMContext.h"
2024 #include "llvm/IR/Module.h"
21 #include "llvm/IR/Type.h"
25 #include "llvm/IR/Value.h"
2226 #include "llvm/Pass.h"
27 #include "llvm/Support/AtomicOrdering.h"
28 #include "llvm/Support/Casting.h"
29 #include "llvm/Support/CommandLine.h"
30 #include "llvm/Support/Compiler.h"
2331 #include "llvm/Support/Debug.h"
2432 #include "llvm/Support/ErrorHandling.h"
2533 #include "llvm/Support/raw_ostream.h"
34 #include
35 #include
36 #include
37
2638 using namespace llvm;
2739
2840 static cl::opt
105117 TotalMayAliasSetSize -= AS->size();
106118
107119 AliasSets.erase(AS);
108
109120 }
110121
111122 void AliasSet::removeFromTracker(AliasSetTracker &AST) {
579590 AliasSet &AliasSetTracker::addPointer(Value *P, uint64_t Size,
580591 const AAMDNodes &AAInfo,
581592 AliasSet::AccessLattice E) {
582
583593 AliasSet &AS = getAliasSetForPointer(P, Size, AAInfo);
584594 AS.Access |= E;
585595
610620 if (Forward)
611621 OS << " forwarding to " << (void*)Forward;
612622
613
614623 if (!empty()) {
615624 OS << "Pointers: ";
616625 for (iterator I = begin(), E = end(); I != E; ++I) {
670679 //===----------------------------------------------------------------------===//
671680
672681 namespace {
682
673683 class AliasSetPrinter : public FunctionPass {
674684 AliasSetTracker *Tracker;
685
675686 public:
676687 static char ID; // Pass identification, replacement for typeid
688
677689 AliasSetPrinter() : FunctionPass(ID) {
678690 initializeAliasSetPrinterPass(*PassRegistry::getPassRegistry());
679691 }
694706 return false;
695707 }
696708 };
697 }
709
710 } // end anonymous namespace
698711
699712 char AliasSetPrinter::ID = 0;
713
700714 INITIALIZE_PASS_BEGIN(AliasSetPrinter, "print-alias-sets",
701715 "Alias Set Printer", false, true)
702716 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/Analysis/CallGraph.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/ADT/SmallVector.h"
1012 #include "llvm/IR/CallSite.h"
11 #include "llvm/IR/Instructions.h"
12 #include "llvm/IR/IntrinsicInst.h"
1313 #include "llvm/IR/Module.h"
14 #include "llvm/IR/Function.h"
15 #include "llvm/IR/Intrinsics.h"
16 #include "llvm/IR/PassManager.h"
17 #include "llvm/Pass.h"
18 #include "llvm/Support/Compiler.h"
1419 #include "llvm/Support/Debug.h"
1520 #include "llvm/Support/raw_ostream.h"
21 #include
22 #include
23
1624 using namespace llvm;
1725
1826 //===----------------------------------------------------------------------===//
124132 /// This does not rescan the body of the function, so it is suitable when
125133 /// splicing the body of the old function to the new while also updating all
126134 /// callers from old to new.
127 ///
128135 void CallGraph::spliceFunction(const Function *From, const Function *To) {
129136 assert(FunctionMap.count(From) && "No CallGraphNode for function!");
130137 assert(!FunctionMap.count(To) &&
255262 initializeCallGraphWrapperPassPass(*PassRegistry::getPassRegistry());
256263 }
257264
258 CallGraphWrapperPass::~CallGraphWrapperPass() {}
265 CallGraphWrapperPass::~CallGraphWrapperPass() = default;
259266
260267 void CallGraphWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
261268 AU.setPreservesAll();
290297 #endif
291298
292299 namespace {
300
293301 struct CallGraphPrinterLegacyPass : public ModulePass {
294302 static char ID; // Pass ID, replacement for typeid
303
295304 CallGraphPrinterLegacyPass() : ModulePass(ID) {
296305 initializeCallGraphPrinterLegacyPassPass(*PassRegistry::getPassRegistry());
297306 }
300309 AU.setPreservesAll();
301310 AU.addRequiredTransitive();
302311 }
312
303313 bool runOnModule(Module &M) override {
304314 getAnalysis().print(errs(), &M);
305315 return false;
306316 }
307317 };
308 }
318
319 } // end anonymous namespace
309320
310321 char CallGraphPrinterLegacyPass::ID = 0;
311322
88
99 #include "llvm/Analysis/DominanceFrontier.h"
1010 #include "llvm/Analysis/DominanceFrontierImpl.h"
11 #include "llvm/IR/Dominators.h"
12 #include "llvm/IR/Function.h"
1113 #include "llvm/IR/PassManager.h"
14 #include "llvm/Pass.h"
15 #include "llvm/Support/Compiler.h"
16 #include "llvm/Support/Debug.h"
17 #include "llvm/Support/raw_ostream.h"
1218
1319 using namespace llvm;
1420
1521 namespace llvm {
22
1623 template class DominanceFrontierBase;
1724 template class DominanceFrontierBase;
1825 template class ForwardDominanceFrontierBase;
19 }
26
27 } // end namespace llvm
2028
2129 char DominanceFrontierWrapperPass::ID = 0;
2230
2634 INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier",
2735 "Dominance Frontier Construction", true, true)
2836
29 DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
37 DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
3038 : FunctionPass(ID), DF() {
3139 initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry());
3240 }
1515 #include "llvm/IR/BasicBlock.h"
1616 #include "llvm/IR/CFG.h"
1717 #include "llvm/Support/raw_ostream.h"
18 #include
1918
2019 using namespace llvm;
2120
2423 //===----------------------------------------------------------------------===//
2524
2625 // isLoop - Find out if there is a back edge in this interval...
27 //
2826 bool Interval::isLoop() const {
2927 // There is a loop in this interval iff one of the predecessors of the header
3028 // node lives in the interval.
3432 return true;
3533 return false;
3634 }
37
3835
3936 void Interval::print(raw_ostream &OS) const {
4037 OS << "-------------------------------------------------------------\n"
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/Analysis/IntervalPartition.h"
15 #include "llvm/Analysis/Interval.h"
1416 #include "llvm/Analysis/IntervalIterator.h"
17 #include "llvm/Pass.h"
18 #include
19 #include
20
1521 using namespace llvm;
1622
1723 char IntervalPartition::ID = 0;
24
1825 INITIALIZE_PASS(IntervalPartition, "intervals",
1926 "Interval Partition Construction", true, true)
2027
3946 // addIntervalToPartition - Add an interval to the internal list of intervals,
4047 // and then add mappings from all of the basic blocks in the interval to the
4148 // interval itself (in the IntervalMap).
42 //
4349 void IntervalPartition::addIntervalToPartition(Interval *I) {
4450 Intervals.push_back(I);
4551
5359 // the interval data structures. After interval generation is complete,
5460 // run through all of the intervals and propagate successor info as
5561 // predecessor info.
56 //
5762 void IntervalPartition::updatePredecessors(Interval *Int) {
5863 BasicBlock *Header = Int->getHeaderNode();
5964 for (BasicBlock *Successor : Int->Successors)
6267
6368 // IntervalPartition ctor - Build the first level interval partition for the
6469 // specified function...
65 //
6670 bool IntervalPartition::runOnFunction(Function &F) {
6771 // Pass false to intervals_begin because we take ownership of it's memory
6872 function_interval_iterator I = intervals_begin(&F, false);
8387 return false;
8488 }
8589
86
8790 // IntervalPartition ctor - Build a reduced interval partition from an
8891 // existing interval graph. This takes an additional boolean parameter to
8992 // distinguish it from a copy constructor. Always pass in false for now.
90 //
9193 IntervalPartition::IntervalPartition(IntervalPartition &IP, bool)
9294 : FunctionPass(ID) {
9395 assert(IP.getRootInterval() && "Cannot operate on empty IntervalPartitions!");
109111 for (unsigned i = 0, e = Intervals.size(); i != e; ++i)
110112 updatePredecessors(Intervals[i]);
111113 }
112