From 154124adc3c03105c7b308791d656f4392d55bbd Mon Sep 17 00:00:00 2001 From: Alina Sbirlea Date: Fri, 15 Sep 2017 00:04:16 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313322 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Transforms/Utils/LoopUtils.h | 5 +++++ lib/Transforms/Scalar/LICM.cpp | 23 ----------------------- lib/Transforms/Utils/LoopUtils.cpp | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/include/llvm/Transforms/Utils/LoopUtils.h b/include/llvm/Transforms/Utils/LoopUtils.h index cabd5655589..75b32902f30 100644 --- a/include/llvm/Transforms/Utils/LoopUtils.h +++ b/include/llvm/Transforms/Utils/LoopUtils.h @@ -455,6 +455,11 @@ bool promoteLoopAccessesToScalars(const SmallSetVector &, Loop *, AliasSetTracker *, LoopSafetyInfo *, OptimizationRemarkEmitter *); +/// 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 collectChildrenInLoop(DomTreeNode *N, + const Loop *CurLoop); + /// \brief Computes safety information for a loop /// checks loop body & header for the possibility of may throw /// exception, it takes LoopSafetyInfo and loop as argument. diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp index 0241ec8c70c..f45d362e077 100644 --- a/lib/Transforms/Scalar/LICM.cpp +++ b/lib/Transforms/Scalar/LICM.cpp @@ -345,29 +345,6 @@ bool LoopInvariantCodeMotion::runOnLoop(Loop *L, AliasAnalysis *AA, return Changed; } -// 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. -static SmallVector -collectChildrenInLoop(DomTreeNode *N, const Loop *CurLoop) { - SmallVector Worklist; - auto add_region_to_worklist = [&](DomTreeNode *DTN) { - // Only include subregions in the top level loop. - BasicBlock *BB = DTN->getBlock(); - if (CurLoop->contains(BB)) - Worklist.push_back(DTN); - }; - - add_region_to_worklist(N); - - for (size_t I = 0; I < Worklist.size(); I++) { - DomTreeNode *DTN = Worklist[I]; - for (DomTreeNode *Child : DTN->getChildren()) - add_region_to_worklist(Child); - } - - return Worklist; -} - /// Walk the specified region of the CFG (defined by all blocks dominated by /// the specified block, and that are in the current loop) in reverse depth /// first order w.r.t the DominatorTree. This allows us to visit uses before diff --git a/lib/Transforms/Utils/LoopUtils.cpp b/lib/Transforms/Utils/LoopUtils.cpp index f2015c6389b..bd89b6b2630 100644 --- a/lib/Transforms/Utils/LoopUtils.cpp +++ b/lib/Transforms/Utils/LoopUtils.cpp @@ -1116,6 +1116,27 @@ Optional 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 +llvm::collectChildrenInLoop(DomTreeNode *N, const Loop *CurLoop) { + SmallVector 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, -- 2.40.0