[PATCH] D64359: [LOOPINFO] Add member function to retrieve loops in breadth-first order
Ettore Tiotto via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 12:03:46 PDT 2019
etiotto created this revision.
etiotto added reviewers: Whitney, Meinersbur.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
etiotto added reviewers: fhahn, hfinkel.
LoopInfo contains a utility to retrieve loops in depth-first order (preorder traversal). This patch adds a similar utility to retrieve loops in breadth-first order.
Repository:
rL LLVM
https://reviews.llvm.org/D64359
Files:
llvm/include/llvm/Analysis/LoopInfo.h
Index: llvm/include/llvm/Analysis/LoopInfo.h
===================================================================
--- llvm/include/llvm/Analysis/LoopInfo.h
+++ llvm/include/llvm/Analysis/LoopInfo.h
@@ -346,6 +346,43 @@
return PreOrderLoops;
}
+ /// Return all inner loops in the loop nest rooted by the loop in
+ /// breadth-first order.
+ template <class Type>
+ static void
+ getInnerLoopsInBreadthFirstOrder(const LoopT &L,
+ SmallVectorImpl<Type> &BreadthFirstLoops) {
+ SmallVector<LoopT *, 4> BreadthFirstWorklist;
+ BreadthFirstWorklist.push_back(const_cast<LoopT *>(&L));
+
+ while (!BreadthFirstWorklist.empty()) {
+ LoopT *L = BreadthFirstWorklist.pop_back_val();
+ const auto &SubLoops = L->getSubLoops();
+ if (!SubLoops.empty()) {
+ BreadthFirstWorklist.insert(BreadthFirstWorklist.begin(),
+ SubLoops.rbegin(), SubLoops.rend());
+ BreadthFirstLoops.append(SubLoops.begin(), SubLoops.end());
+ }
+ }
+ }
+
+ /// Return all loops in the loop nest rooted by the loop in breadth-first
+ /// order.
+ SmallVector<const LoopT *, 4> getLoopsInBreadthFirstOrder() const {
+ SmallVector<const LoopT *, 4> BreadthFirstLoops;
+ const LoopT *CurLoop = static_cast<const LoopT *>(this);
+ BreadthFirstLoops.push_back(CurLoop);
+ getInnerLoopsInBreadthFirstOrder(*CurLoop, BreadthFirstLoops);
+ return BreadthFirstLoops;
+ }
+ SmallVector<LoopT *, 4> getLoopsInBreadthFirstOrder() {
+ SmallVector<LoopT *, 4> BreadthFirstLoops;
+ LoopT *CurLoop = static_cast<LoopT *>(this);
+ BreadthFirstLoops.push_back(CurLoop);
+ getInnerLoopsInBreadthFirstOrder(*CurLoop, BreadthFirstLoops);
+ return BreadthFirstLoops;
+ }
+
//===--------------------------------------------------------------------===//
// APIs for updating loop information after changing the CFG
//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64359.208444.patch
Type: text/x-patch
Size: 1932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190708/de6155bd/attachment.bin>
More information about the llvm-commits
mailing list