LLVM 23.0.0git
GenericCycleImpl.h
Go to the documentation of this file.
1//===- GenericCycleImpl.h -------------------------------------*- C++ -*---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This template implementation resides in a separate file so that it
11/// does not get injected into every .cpp file that includes the
12/// generic header.
13///
14/// DO NOT INCLUDE THIS FILE WHEN MERELY USING CYCLEINFO.
15///
16/// This file should only be included by files that implement a
17/// specialization of the relevant templates. Currently these are:
18/// - llvm/lib/IR/CycleInfo.cpp
19/// - llvm/lib/CodeGen/MachineCycleAnalysis.cpp
20///
21//===----------------------------------------------------------------------===//
22
23#ifndef LLVM_ADT_GENERICCYCLEIMPL_H
24#define LLVM_ADT_GENERICCYCLEIMPL_H
25
26#include "llvm/ADT/DenseSet.h"
30
31#define DEBUG_TYPE "generic-cycle-impl"
32
33namespace llvm {
34
35template <typename ContextT>
36bool GenericCycle<ContextT>::contains(const GenericCycle *C) const {
37 if (!C)
38 return false;
39
40 if (Depth > C->Depth)
41 return false;
42 while (Depth < C->Depth)
43 C = C->ParentCycle;
44 return this == C;
45}
46
47template <typename ContextT>
49 SmallVectorImpl<BlockT *> &TmpStorage) const {
50 if (!ExitBlocksCache.empty()) {
51 TmpStorage = ExitBlocksCache;
52 return;
53 }
54
55 TmpStorage.clear();
56
57 size_t NumExitBlocks = 0;
58 for (BlockT *Block : blocks()) {
60
61 for (size_t Idx = NumExitBlocks, End = TmpStorage.size(); Idx < End;
62 ++Idx) {
63 BlockT *Succ = TmpStorage[Idx];
64 if (!contains(Succ)) {
65 auto ExitEndIt = TmpStorage.begin() + NumExitBlocks;
66 if (std::find(TmpStorage.begin(), ExitEndIt, Succ) == ExitEndIt)
67 TmpStorage[NumExitBlocks++] = Succ;
68 }
69 }
70
71 TmpStorage.resize(NumExitBlocks);
72 }
73 ExitBlocksCache.append(TmpStorage.begin(), TmpStorage.end());
74}
75
76template <typename ContextT>
78 SmallVectorImpl<BlockT *> &TmpStorage) const {
79 TmpStorage.clear();
80
81 for (BlockT *Block : blocks()) {
82 for (BlockT *Succ : successors(Block)) {
83 if (!contains(Succ)) {
84 TmpStorage.push_back(Block);
85 break;
86 }
87 }
88 }
89}
90
91template <typename ContextT>
93 BlockT *Predecessor = getCyclePredecessor();
94 if (!Predecessor)
95 return nullptr;
96
97 assert(isReducible() && "Cycle Predecessor must be in a reducible cycle!");
98
99 if (succ_size(Predecessor) != 1)
100 return nullptr;
101
102 // Make sure we are allowed to hoist instructions into the predecessor.
103 if (!Predecessor->isLegalToHoistInto())
104 return nullptr;
105
106 return Predecessor;
107}
108
109template <typename ContextT>
111 if (!isReducible())
112 return nullptr;
113
114 BlockT *Out = nullptr;
115
116 // Loop over the predecessors of the header node...
117 BlockT *Header = getHeader();
118 for (const auto Pred : predecessors(Header)) {
119 if (!contains(Pred)) {
120 if (Out && Out != Pred)
121 return nullptr;
122 Out = Pred;
123 }
124 }
125
126 return Out;
127}
128
129/// \brief Verify that this is actually a well-formed cycle in the CFG.
130template <typename ContextT> void GenericCycle<ContextT>::verifyCycle() const {
131#ifndef NDEBUG
132 assert(!Blocks.empty() && "Cycle cannot be empty.");
133 DenseSet<BlockT *> Blocks;
134 for (BlockT *BB : blocks()) {
135 assert(Blocks.insert(BB).second); // duplicates in block list?
136 }
137 assert(!Entries.empty() && "Cycle must have one or more entries.");
138
139 DenseSet<BlockT *> Entries;
140 for (BlockT *Entry : entries()) {
141 assert(Entries.insert(Entry).second); // duplicate entry?
142 assert(contains(Entry));
143 }
144
145 // Setup for using a depth-first iterator to visit every block in the cycle.
147 getExitBlocks(ExitBBs);
149 VisitSet.insert(ExitBBs.begin(), ExitBBs.end());
150
151 // Keep track of the BBs visited.
152 SmallPtrSet<BlockT *, 8> VisitedBBs;
153
154 // Check the individual blocks.
155 for (BlockT *BB : depth_first_ext(getHeader(), VisitSet)) {
157 [&](BlockT *B) { return contains(B); }) &&
158 "Cycle block has no in-cycle successors!");
159
161 [&](BlockT *B) { return contains(B); }) &&
162 "Cycle block has no in-cycle predecessors!");
163
164 DenseSet<BlockT *> OutsideCyclePreds;
166 if (!contains(B))
167 OutsideCyclePreds.insert(B);
168
169 if (Entries.contains(BB)) {
170 assert(!OutsideCyclePreds.empty() && "Entry is unreachable!");
171 } else if (!OutsideCyclePreds.empty()) {
172 // A non-entry block shouldn't be reachable from outside the cycle,
173 // though it is permitted if the predecessor is not itself actually
174 // reachable.
175 BlockT *EntryBB = &BB->getParent()->front();
176 for (BlockT *CB : depth_first(EntryBB))
177 assert(!OutsideCyclePreds.contains(CB) &&
178 "Non-entry block reachable from outside!");
179 }
180 assert(BB != &getHeader()->getParent()->front() &&
181 "Cycle contains function entry block!");
182
183 VisitedBBs.insert(BB);
184 }
185
186 if (VisitedBBs.size() != getNumBlocks()) {
187 dbgs() << "The following blocks are unreachable in the cycle:\n ";
188 ListSeparator LS;
189 for (auto *BB : Blocks) {
190 if (!VisitedBBs.count(BB)) {
191 dbgs() << LS;
192 BB->printAsOperand(dbgs());
193 }
194 }
195 dbgs() << "\n";
196 llvm_unreachable("Unreachable block in cycle");
197 }
198
200#endif
201}
202
203/// \brief Verify the parent-child relations of this cycle.
204///
205/// Note that this does \em not check that cycle is really a cycle in the CFG.
206template <typename ContextT>
208#ifndef NDEBUG
209 // Check the subcycles.
210 for (GenericCycle *Child : children()) {
211 // Each block in each subcycle should be contained within this cycle.
212 for (BlockT *BB : Child->blocks()) {
213 assert(contains(BB) &&
214 "Cycle does not contain all the blocks of a subcycle!");
215 }
216 assert(Child->Depth == Depth + 1);
217 }
218
219 // Check the parent cycle pointer.
220 if (ParentCycle) {
221 assert(is_contained(ParentCycle->children(), this) &&
222 "Cycle is not a subcycle of its parent!");
223 assert(ParentCycle->TopLevelCycle == TopLevelCycle &&
224 "Top level cycle of parent cycle must be the same");
225 } else {
226 assert(TopLevelCycle == this &&
227 "Cycle without parent must be top-level cycle");
228 }
229#endif
230}
231
232/// \brief Helper class for computing cycle information.
233template <typename ContextT> class GenericCycleInfoCompute {
234 using BlockT = typename ContextT::BlockT;
235 using FunctionT = typename ContextT::FunctionT;
236 using CycleInfoT = GenericCycleInfo<ContextT>;
237 using CycleT = typename CycleInfoT::CycleT;
238
239 CycleInfoT &Info;
240
241 struct DFSInfo {
242 unsigned Start = 0; // DFS start; positive if block is found
243 unsigned End = 0; // DFS end
244
245 DFSInfo() = default;
246 explicit DFSInfo(unsigned Start) : Start(Start) {}
247
248 explicit operator bool() const { return Start; }
249
250 /// Whether this node is an ancestor (or equal to) the node \p Other
251 /// in the DFS tree.
252 bool isAncestorOf(const DFSInfo &Other) const {
253 return Start <= Other.Start && Other.End <= End;
254 }
255 };
256
257 // Indexed by block number.
258 SmallVector<DFSInfo, 8> BlockDFSInfo;
259 SmallVector<BlockT *, 8> BlockPreorder;
260
261 GenericCycleInfoCompute(const GenericCycleInfoCompute &) = delete;
262 GenericCycleInfoCompute &operator=(const GenericCycleInfoCompute &) = delete;
263
264 DFSInfo getDFSInfo(BlockT *B) const {
266 return BlockDFSInfo[Number];
267 }
268
269 DFSInfo &getOrInsertDFSInfo(BlockT *B) {
271 return BlockDFSInfo[Number];
272 }
273
274public:
275 GenericCycleInfoCompute(CycleInfoT &Info) : Info(Info) {}
276
277 void run(FunctionT *F);
278
279 static void updateDepth(CycleT *SubTree);
280
281private:
282 void dfs(FunctionT *F, BlockT *EntryBlock);
283};
284
285template <typename ContextT>
287 const BlockT *Block) const -> CycleT * {
289 return Cycle ? Cycle->TopLevelCycle : nullptr;
290}
291
292template <typename ContextT>
293void GenericCycleInfo<ContextT>::moveTopLevelCycleToNewParent(CycleT *NewParent,
294 CycleT *Child) {
295 assert((!Child->ParentCycle && !NewParent->ParentCycle) &&
296 "NewParent and Child must be both top level cycle!\n");
297 auto &CurrentContainer =
298 Child->ParentCycle ? Child->ParentCycle->Children : TopLevelCycles;
299 auto Pos = llvm::find_if(CurrentContainer, [=](const auto &Ptr) -> bool {
300 return Child == Ptr.get();
301 });
302 assert(Pos != CurrentContainer.end());
303 NewParent->Children.push_back(std::move(*Pos));
304 *Pos = std::move(CurrentContainer.back());
305 CurrentContainer.pop_back();
306 Child->ParentCycle = NewParent;
307 Child->TopLevelCycle = NewParent;
308 for (CycleT *Cycle : depth_first(Child))
309 Cycle->TopLevelCycle = NewParent;
310
311 NewParent->Blocks.insert_range(Child->blocks());
312 NewParent->clearCache();
313 Child->clearCache();
314}
316template <typename ContextT>
317void GenericCycleInfo<ContextT>::verifyBlockNumberEpoch(
318 const FunctionT *Fn) const {
319 assert(BlockNumberEpoch ==
321 "CycleInfo used with outdated block number epoch");
322}
323
324template <typename ContextT>
325void GenericCycleInfo<ContextT>::addToBlockMap(BlockT *Block, CycleT *Cycle) {
326 // The caller should ensure that BlockMap is large enough.
327 verifyBlockNumberEpoch(Block->getParent());
329 BlockMap[Number] = Cycle;
330}
331
332template <typename ContextT>
334 // Make sure BlockMap is large enough for the new block.
336 if (Number >= BlockMap.size())
337 BlockMap.resize(GraphTraits<FunctionT *>::getMaxNumber(Block->getParent()));
338
339 // FixMe: Appending NewBlock is fine as a set of blocks in a cycle. When
340 // printing, cycle NewBlock is at the end of list but it should be in the
341 // middle to represent actual traversal of a cycle.
342 Cycle->appendBlock(Block);
343 addToBlockMap(Block, Cycle);
344
345 CycleT *ParentCycle = Cycle->getParentCycle();
346 while (ParentCycle) {
347 Cycle = ParentCycle;
348 Cycle->appendBlock(Block);
349 ParentCycle = Cycle->getParentCycle();
350 }
351
352 Cycle->clearCache();
353}
354
355/// \brief Main function of the cycle info computations.
356template <typename ContextT>
358 BlockT *EntryBlock = GraphTraits<FunctionT *>::getEntryNode(F);
359 LLVM_DEBUG(errs() << "Entry block: " << Info.Context.print(EntryBlock)
360 << "\n");
361 dfs(F, EntryBlock);
362
364
365 for (BlockT *HeaderCandidate : llvm::reverse(BlockPreorder)) {
366 const DFSInfo CandidateInfo = getDFSInfo(HeaderCandidate);
367
368 for (BlockT *Pred : predecessors(HeaderCandidate)) {
369 const DFSInfo PredDFSInfo = getDFSInfo(Pred);
370 // This automatically ignores unreachable predecessors since they have
371 // zeros in their DFSInfo.
372 if (CandidateInfo.isAncestorOf(PredDFSInfo))
373 Worklist.push_back(Pred);
374 }
375 if (Worklist.empty()) {
376 continue;
377 }
378
379 // Found a cycle with the candidate as its header.
380 LLVM_DEBUG(errs() << "Found cycle for header: "
381 << Info.Context.print(HeaderCandidate) << "\n");
382 std::unique_ptr<CycleT> NewCycle = std::make_unique<CycleT>();
383 NewCycle->appendEntry(HeaderCandidate);
384 NewCycle->appendBlock(HeaderCandidate);
385 Info.addToBlockMap(HeaderCandidate, NewCycle.get());
386
387 // Helper function to process (non-back-edge) predecessors of a discovered
388 // block and either add them to the worklist or recognize that the given
389 // block is an additional cycle entry.
390 auto ProcessPredecessors = [&](BlockT *Block) {
391 LLVM_DEBUG(errs() << " block " << Info.Context.print(Block) << ": ");
392
393 bool IsEntry = false;
394 for (BlockT *Pred : predecessors(Block)) {
395 const DFSInfo PredDFSInfo = getDFSInfo(Pred);
396 if (CandidateInfo.isAncestorOf(PredDFSInfo)) {
397 Worklist.push_back(Pred);
398 } else if (!PredDFSInfo) {
399 // Ignore an unreachable predecessor. It will will incorrectly cause
400 // Block to be treated as a cycle entry.
401 LLVM_DEBUG(errs() << " skipped unreachable predecessor.\n");
402 } else {
403 IsEntry = true;
404 }
405 }
406 if (IsEntry) {
407 assert(!NewCycle->isEntry(Block));
408 LLVM_DEBUG(errs() << "append as entry\n");
409 NewCycle->appendEntry(Block);
410 } else {
411 LLVM_DEBUG(errs() << "append as child\n");
412 }
413 };
414
415 do {
416 BlockT *Block = Worklist.pop_back_val();
417 if (Block == HeaderCandidate)
418 continue;
419
420 // If the block has already been discovered by some cycle
421 // (possibly by ourself), then the outermost cycle containing it
422 // should become our child.
423 if (auto *BlockParent = Info.getTopLevelParentCycle(Block)) {
424 LLVM_DEBUG(errs() << " block " << Info.Context.print(Block) << ": ");
425
426 if (BlockParent != NewCycle.get()) {
428 << "discovered child cycle "
429 << Info.Context.print(BlockParent->getHeader()) << "\n");
430 // Make BlockParent the child of NewCycle.
431 Info.moveTopLevelCycleToNewParent(NewCycle.get(), BlockParent);
432
433 for (auto *ChildEntry : BlockParent->entries())
434 ProcessPredecessors(ChildEntry);
435 } else {
437 << "known child cycle "
438 << Info.Context.print(BlockParent->getHeader()) << "\n");
439 }
440 } else {
441 Info.addToBlockMap(Block, NewCycle.get());
442 assert(!is_contained(NewCycle->Blocks, Block));
443 NewCycle->Blocks.insert(Block);
444 ProcessPredecessors(Block);
445 }
446 } while (!Worklist.empty());
447
448 Info.TopLevelCycles.push_back(std::move(NewCycle));
449 }
450
451 // Fix top-level cycle links and compute cycle depths.
452 for (auto *TLC : Info.toplevel_cycles()) {
453 LLVM_DEBUG(errs() << "top-level cycle: "
454 << Info.Context.print(TLC->getHeader()) << "\n");
455
456 TLC->ParentCycle = nullptr;
457 updateDepth(TLC);
458 }
459}
460
461/// \brief Recompute depth values of \p SubTree and all descendants.
462template <typename ContextT>
464 for (CycleT *Cycle : depth_first(SubTree))
465 Cycle->Depth = Cycle->ParentCycle ? Cycle->ParentCycle->Depth + 1 : 1;
466}
467
468/// \brief Compute a DFS of basic blocks starting at the function entry.
469///
470/// Fills BlockDFSInfo with start/end counters and BlockPreorder.
471template <typename ContextT>
472void GenericCycleInfoCompute<ContextT>::dfs(FunctionT *F, BlockT *EntryBlock) {
473 SmallVector<unsigned, 8> DFSTreeStack;
474 SmallVector<BlockT *, 8> TraverseStack;
475 unsigned Counter = 0;
476 TraverseStack.emplace_back(EntryBlock);
477
478 BlockDFSInfo.resize(GraphTraits<FunctionT *>::getMaxNumber(F));
479 do {
480 BlockT *Block = TraverseStack.back();
481 LLVM_DEBUG(errs() << "DFS visiting block: " << Info.Context.print(Block)
482 << "\n");
483 DFSInfo &Info = getOrInsertDFSInfo(Block);
484 if (Info.Start == 0) {
485 Info.Start = ++Counter;
486
487 // We're visiting the block for the first time. Open its DFSInfo, add
488 // successors to the traversal stack, and remember the traversal stack
489 // depth at which the block was opened, so that we can correctly record
490 // its end time.
491 LLVM_DEBUG(errs() << " first encountered at depth "
492 << TraverseStack.size() << "\n");
493
494 DFSTreeStack.emplace_back(TraverseStack.size());
495 llvm::append_range(TraverseStack, successors(Block));
496
497 BlockPreorder.push_back(Block);
498 LLVM_DEBUG(errs() << " preorder number: " << Counter << "\n");
499 } else {
500 assert(!DFSTreeStack.empty());
501 if (DFSTreeStack.back() == TraverseStack.size()) {
502 LLVM_DEBUG(errs() << " ended at " << Counter << "\n");
503 Info.End = Counter;
504 DFSTreeStack.pop_back();
505 } else {
506 LLVM_DEBUG(errs() << " already done\n");
507 }
508 TraverseStack.pop_back();
509 }
510 } while (!TraverseStack.empty());
511 assert(DFSTreeStack.empty());
512
514 errs() << "Preorder:\n";
515 for (int i = 0, e = BlockPreorder.size(); i != e; ++i) {
516 errs() << " " << Info.Context.print(BlockPreorder[i]) << ": " << i << "\n";
517 }
518 );
519}
520
521/// \brief Reset the object to its initial state.
522template <typename ContextT> void GenericCycleInfo<ContextT>::clear() {
523 TopLevelCycles.clear();
524 BlockMap.clear();
525}
526
527/// \brief Compute the cycle info for a function.
528template <typename ContextT>
531 Context = ContextT(&F);
532 BlockNumberEpoch = GraphTraits<FunctionT *>::getNumberEpoch(&F);
533 BlockMap.resize(GraphTraits<FunctionT *>::getMaxNumber(&F));
534
535 LLVM_DEBUG(errs() << "Computing cycles for function: " << F.getName()
536 << "\n");
537 Compute.run(&F);
538}
539
540template <typename ContextT>
542 BlockT *NewBlock) {
543 // Edge Pred-Succ is replaced by edges Pred-NewBlock and NewBlock-Succ, all
544 // cycles that had blocks Pred and Succ also get NewBlock.
546 if (!Cycle)
547 return;
548
549 addBlockToCycle(NewBlock, Cycle);
551}
552
553/// \brief Find the innermost cycle containing a given block.
554///
555/// \returns the innermost cycle containing \p Block or nullptr if
556/// it is not contained in any cycle.
557template <typename ContextT>
559 -> CycleT * {
560 verifyBlockNumberEpoch(Block->getParent());
562 return Number < BlockMap.size() ? BlockMap[Number] : nullptr;
563}
564
565/// \brief Find the innermost cycle containing both given cycles.
566///
567/// \returns the innermost cycle containing both \p A and \p B
568/// or nullptr if there is no such cycle.
569template <typename ContextT>
571 CycleT *B) const
572 -> CycleT * {
573 if (!A || !B)
574 return nullptr;
575
576 // If cycles A and B have different depth replace them with parent cycle
577 // until they have the same depth.
578 while (A->getDepth() > B->getDepth())
579 A = A->getParentCycle();
580 while (B->getDepth() > A->getDepth())
581 B = B->getParentCycle();
582
583 // Cycles A and B are at same depth but may be disjoint, replace them with
584 // parent cycles until we find cycle that contains both or we run out of
585 // parent cycles.
586 while (A != B) {
587 A = A->getParentCycle();
588 B = B->getParentCycle();
589 }
590
591 return A;
592}
593
594/// \brief Find the innermost cycle containing both given blocks.
595///
596/// \returns the innermost cycle containing both \p A and \p B
597/// or nullptr if there is no such cycle.
598template <typename ContextT>
604
605/// \brief get the depth for the cycle which containing a given block.
606///
607/// \returns the depth for the innermost cycle containing \p Block or 0 if it is
608/// not contained in any cycle.
609template <typename ContextT>
612 if (!Cycle)
613 return 0;
614 return Cycle->getDepth();
615}
616
617/// \brief Verify the internal consistency of the cycle tree.
618///
619/// Note that this does \em not check that cycles are really cycles in the CFG,
620/// or that the right set of cycles in the CFG were found.
621template <typename ContextT>
623#ifndef NDEBUG
624 DenseSet<BlockT *> CycleHeaders;
625
626 for (CycleT *TopCycle : toplevel_cycles()) {
627 for (CycleT *Cycle : depth_first(TopCycle)) {
628 BlockT *Header = Cycle->getHeader();
629 assert(CycleHeaders.insert(Header).second);
630 if (VerifyFull)
631 Cycle->verifyCycle();
632 else
633 Cycle->verifyCycleNest();
634 // Check the block map entries for blocks contained in this cycle.
635 for (BlockT *BB : Cycle->blocks()) {
636 CycleT *CycleInBlockMap = getCycle(BB);
637 assert(CycleInBlockMap != nullptr);
638 assert(Cycle->contains(CycleInBlockMap));
639 }
640 }
641 }
642#endif
643}
644
645/// \brief Verify that the entire cycle tree well-formed.
646template <typename ContextT> void GenericCycleInfo<ContextT>::verify() const {
647 verifyCycleNest(/*VerifyFull=*/true);
648}
649
650/// \brief Print the cycle info.
651template <typename ContextT>
653 for (const auto *TLC : toplevel_cycles()) {
654 for (const CycleT *Cycle : depth_first(TLC)) {
655 for (unsigned I = 0; I < Cycle->Depth; ++I)
656 Out << " ";
657
658 Out << Cycle->print(Context) << '\n';
659 }
660 }
661}
662
663} // namespace llvm
664
665#undef DEBUG_TYPE
666
667#endif // LLVM_ADT_GENERICCYCLEIMPL_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static const Function * getParent(const Value *V)
bbsections Prepares for basic block by splitting functions into clusters of basic blocks
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseSet and SmallDenseSet classes.
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
Find all cycles in a control-flow graph, including irreducible loops.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:487
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:114
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
GenericCycleInfoCompute(CycleInfoT &Info)
void run(FunctionT *F)
Main function of the cycle info computations.
static void updateDepth(CycleT *SubTree)
Recompute depth values of SubTree and all descendants.
Cycle information for a function.
typename SSAContext::FunctionT FunctionT
void verify() const
Verify that the entire cycle tree well-formed.
void addBlockToCycle(BlockT *Block, CycleT *Cycle)
Assumes that Cycle is the innermost cycle containing Block.
iterator_range< const_toplevel_iterator > toplevel_cycles() const
CycleT * getTopLevelParentCycle(const BlockT *Block) const
friend class GenericCycleInfoCompute
void print(raw_ostream &Out) const
Print the cycle info.
CycleT * getSmallestCommonCycle(CycleT *A, CycleT *B) const
Find the innermost cycle containing both given cycles.
void clear()
Reset the object to its initial state.
GenericCycle< ContextT > CycleT
void compute(FunctionT &F)
Compute the cycle info for a function.
void splitCriticalEdge(BlockT *Pred, BlockT *Succ, BlockT *New)
unsigned getCycleDepth(const BlockT *Block) const
get the depth for the cycle which containing a given block.
void verifyCycleNest(bool VerifyFull=false) const
Methods for debug and self-test.
typename ContextT::BlockT BlockT
CycleT * getCycle(const BlockT *Block) const
Find the innermost cycle containing a given block.
void clearCache() const
Clear the cache of the cycle.
BlockT * getHeader() const
bool isReducible() const
Whether the cycle is a natural loop.
void getExitingBlocks(SmallVectorImpl< BlockT * > &TmpStorage) const
Return all blocks of this cycle that have successor outside of this cycle.
void verifyCycle() const
Verify that this is actually a well-formed cycle in the CFG.
iterator_range< const_entry_iterator > entries() const
void verifyCycleNest() const
Verify the parent-child relations of this cycle.
iterator_range< const_block_iterator > blocks() const
BlockT * getCyclePreheader() const
Return the preheader block for this cycle.
void getExitBlocks(SmallVectorImpl< BlockT * > &TmpStorage) const
Return all of the successor blocks of this cycle.
BlockT * getCyclePredecessor() const
If the cycle has exactly one entry with exactly one predecessor, return it, otherwise return nullptr.
bool contains(const BlockT *Block) const
Return whether Block is contained in the cycle.
typename ContextT::BlockT BlockT
size_t getNumBlocks() const
A helper class to return the specified delimiter string after the first invocation of operator String...
size_type size() const
Definition SmallPtrSet.h:99
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void resize(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
auto successors(const MachineBasicBlock *BB)
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2208
CycleInfo::CycleT Cycle
Definition CycleInfo.h:26
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1746
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
auto succ_size(const MachineBasicBlock *BB)
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Other
Any other memory.
Definition ModRef.h:68
iterator_range< typename GraphTraits< Inverse< GraphType > >::ChildIteratorType > inverse_children(const typename GraphTraits< GraphType >::NodeRef &G)
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1772
auto predecessors(const MachineBasicBlock *BB)
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
iterator_range< df_iterator< T > > depth_first(const T &G)
std::pair< iterator, bool > insert(NodeRef N)