diff options
author | Alina Sbirlea <asbirlea@google.com> | 2017-09-15 00:04:16 +0000 |
---|---|---|
committer | Alina Sbirlea <asbirlea@google.com> | 2017-09-15 00:04:16 +0000 |
commit | 7ed5856a3226f19f47d39a16ff17a5a0a4448020 (patch) | |
tree | abacaf240c9a0fd1a20625acacff1cdb602347e2 /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | f716931bb27aebb67a0a1b79e84bf4c11d951694 (diff) | |
download | llvm-7ed5856a3226f19f47d39a16ff17a5a0a4448020.zip llvm-7ed5856a3226f19f47d39a16ff17a5a0a4448020.tar.gz llvm-7ed5856a3226f19f47d39a16ff17a5a0a4448020.tar.bz2 |
Refactor collectChildrenInLoop to LoopUtils [NFC]
Summary: Move to LoopUtils method that collects all children of a node inside a loop.
Reviewers: majnemer, sanjoy
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D37870
llvm-svn: 313322
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index f2015c6..bd89b6b 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1116,6 +1116,27 @@ Optional<const MDOperand *> llvm::findStringMetadataForLoop(Loop *TheLoop, return None; } +/// Does a BFS from a given node to all of its children inside a given loop. +/// The returned vector of nodes includes the starting point. +SmallVector<DomTreeNode *, 16> +llvm::collectChildrenInLoop(DomTreeNode *N, const Loop *CurLoop) { + SmallVector<DomTreeNode *, 16> Worklist; + auto AddRegionToWorklist = [&](DomTreeNode *DTN) { + // Only include subregions in the top level loop. + BasicBlock *BB = DTN->getBlock(); + if (CurLoop->contains(BB)) + Worklist.push_back(DTN); + }; + + AddRegionToWorklist(N); + + for (size_t I = 0; I < Worklist.size(); I++) + for (DomTreeNode *Child : Worklist[I]->getChildren()) + AddRegionToWorklist(Child); + + return Worklist; +} + /// Returns true if the instruction in a loop is guaranteed to execute at least /// once. bool llvm::isGuaranteedToExecute(const Instruction &Inst, |