[PATCH] Extract out LPPassManager::cloneLoop

Sanjoy Das sanjoy at playingwithpointers.com
Tue Dec 16 14:00:26 PST 2014


This is depended on by the next change.

http://reviews.llvm.org/D6691

Files:
  include/llvm/Analysis/LoopPass.h
  lib/Analysis/LoopPass.cpp
  lib/Transforms/Scalar/LoopUnswitch.cpp

Index: include/llvm/Analysis/LoopPass.h
===================================================================
--- include/llvm/Analysis/LoopPass.h
+++ include/llvm/Analysis/LoopPass.h
@@ -17,6 +17,7 @@
 
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/IR/LegacyPassManagers.h"
+#include "llvm/Transforms/Utils/ValueMapper.h"
 #include "llvm/Pass.h"
 #include <deque>
 
@@ -142,6 +143,10 @@
   // utility may send LPPassManager into infinite loops so use caution.
   void redoLoop(Loop *L);
 
+  /// cloneLoop - Recursively clone the specified loop and all of its
+  /// children, mapping the blocks with the specified map.
+  Loop *cloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM, LoopInfo *LI);
+
   //===--------------------------------------------------------------------===//
   /// SimpleAnalysis - Provides simple interface to update analysis info
   /// maintained by various passes. Note, if required this interface can
Index: lib/Analysis/LoopPass.cpp
===================================================================
--- lib/Analysis/LoopPass.cpp
+++ lib/Analysis/LoopPass.cpp
@@ -309,6 +309,26 @@
   return Changed;
 }
 
+
+/// cloneLoop - Recursively clone the specified loop and all of its children,
+/// mapping the blocks with the specified map.
+Loop *LPPassManager::cloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM,
+                               LoopInfo *LI) {
+  Loop *New = new Loop;
+  insertLoop(New, PL);
+
+  // Add all of the blocks in L to the new loop.
+  for (BasicBlock *BB : L->getBlocks())
+    if (LI->getLoopFor(BB) == L)
+      New->addBasicBlockToLoop(cast<BasicBlock>(VM[BB]), LI->getBase());
+
+  // Add all of the subloops to the new loop.
+  for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
+    cloneLoop(*I, New, VM, LI);
+
+  return New;
+}
+
 /// Print passes managed by this manager
 void LPPassManager::dumpPassStructure(unsigned Offset) {
   errs().indent(Offset*2) << "Loop Pass Manager\n";
Index: lib/Transforms/Scalar/LoopUnswitch.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnswitch.cpp
+++ lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -663,26 +663,6 @@
   return true;
 }
 
-/// CloneLoop - Recursively clone the specified loop and all of its children,
-/// mapping the blocks with the specified map.
-static Loop *CloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM,
-                       LoopInfo *LI, LPPassManager *LPM) {
-  Loop *New = new Loop();
-  LPM->insertLoop(New, PL);
-
-  // Add all of the blocks in L to the new loop.
-  for (Loop::block_iterator I = L->block_begin(), E = L->block_end();
-       I != E; ++I)
-    if (LI->getLoopFor(*I) == L)
-      New->addBasicBlockToLoop(cast<BasicBlock>(VM[*I]), LI->getBase());
-
-  // Add all of the subloops to the new loop.
-  for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
-    CloneLoop(*I, New, VM, LI, LPM);
-
-  return New;
-}
-
 /// EmitPreheaderBranchOnCondition - Emit a conditional branch on two values
 /// if LIC == Val, branch to TrueDst, otherwise branch to FalseDest.  Insert the
 /// code immediately before InsertPt.
@@ -839,7 +819,7 @@
   AT->forgetCachedAssumptions(F);
 
   // Now we create the new Loop object for the versioned loop.
-  Loop *NewLoop = CloneLoop(L, L->getParentLoop(), VMap, LI, LPM);
+  Loop *NewLoop = LPM->cloneLoop(L, L->getParentLoop(), VMap, LI);
 
   // Recalculate unswitching quota, inherit simplified switches info for NewBB,
   // Probably clone more loop-unswitch related loop properties.

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6691.17359.patch
Type: text/x-patch
Size: 3546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141216/f63570c3/attachment.bin>


More information about the llvm-commits mailing list