[PM] Make the LoopInfoBase and LoopInfo objects movable so that they can
authorChandler Carruth <chandlerc@gmail.com>
Tue, 20 Jan 2015 10:58:38 +0000 (10:58 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 20 Jan 2015 10:58:38 +0000 (10:58 +0000)
be used as results in the new pass manager.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226559 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LoopInfo.h

index 18e572a19048d4260bd89f587f99be2e0de20df6..0b78983380f49a61ab217cc4ee35da420f5b5b19 100644 (file)
@@ -502,6 +502,24 @@ public:
   LoopInfoBase() { }
   ~LoopInfoBase() { releaseMemory(); }
 
+  LoopInfoBase(LoopInfoBase &&Arg)
+      : BBMap(std::move(Arg.BBMap)),
+        TopLevelLoops(std::move(Arg.TopLevelLoops)) {
+    // We have to clear the arguments top level loops as we've taken ownership.
+    Arg.TopLevelLoops.clear();
+  }
+  LoopInfoBase &operator=(LoopInfoBase &&RHS) {
+    if (&RHS != this) {
+      BBMap = std::move(RHS.BBMap);
+
+      for (auto *L : TopLevelLoops)
+        delete L;
+      TopLevelLoops = std::move(RHS.TopLevelLoops);
+      RHS.TopLevelLoops.clear();
+    }
+    return *this;
+  }
+
   void releaseMemory() {
     BBMap.clear();
 
@@ -635,6 +653,12 @@ class LoopInfo : public LoopInfoBase<BasicBlock, Loop> {
 public:
   LoopInfo() {}
 
+  LoopInfo(LoopInfo &&Arg) : BaseT(std::move(static_cast<BaseT &>(Arg))) {}
+  LoopInfo &operator=(LoopInfo &&RHS) {
+    BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
+    return *this;
+  }
+
   // Most of the public interface is provided via LoopInfoBase.
 
   /// updateUnloop - Update LoopInfo after removing the last backedge from a