[PATCH] D78425: [ValueLattice] Add move constructor

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 18 14:01:05 PDT 2020


nikic updated this revision to Diff 258553.
nikic added a comment.

Rebase, simplify copy constructor.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78425/new/

https://reviews.llvm.org/D78425

Files:
  include/llvm/Analysis/ValueLattice.h


Index: include/llvm/Analysis/ValueLattice.h
===================================================================
--- include/llvm/Analysis/ValueLattice.h
+++ include/llvm/Analysis/ValueLattice.h
@@ -114,21 +114,43 @@
     *this = Other;
   }
 
+  ValueLatticeElement(ValueLatticeElement &&Other) : Tag(unknown) {
+    *this = std::move(Other);
+  }
+
   /// Custom assignment operator, to ensure Range gets initialized when
   /// assigning a constant range lattice element.
   ValueLatticeElement &operator=(const ValueLatticeElement &Other) {
-    // If we change the state of this from constant range to non constant range,
-    // destroy Range.
-    if (isConstantRange() && !Other.isConstantRange())
+    if (isConstantRange())
+      Range.~ConstantRange();
+
+    switch (Other.Tag) {
+    case constantrange:
+    case constantrange_including_undef:
+      new (&Range) ConstantRange(Other.Range);
+      NumRangeExtensions = Other.NumRangeExtensions;
+      break;
+    case constant:
+    case notconstant:
+      ConstVal = Other.ConstVal;
+      break;
+    case overdefined:
+    case unknown:
+    case undef:
+      break;
+    }
+    Tag = Other.Tag;
+    return *this;
+  }
+
+  ValueLatticeElement &operator=(ValueLatticeElement &&Other) {
+    if (isConstantRange())
       Range.~ConstantRange();
 
     switch (Other.Tag) {
     case constantrange:
     case constantrange_including_undef:
-      if (!isConstantRange())
-        new (&Range) ConstantRange(Other.Range);
-      else
-        Range = Other.Range;
+      new (&Range) ConstantRange(std::move(Other.Range));
       NumRangeExtensions = Other.NumRangeExtensions;
       break;
     case constant:
@@ -141,6 +163,7 @@
       break;
     }
     Tag = Other.Tag;
+    Other.Tag = unknown;
     return *this;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78425.258553.patch
Type: text/x-patch
Size: 1796 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200418/44c925f2/attachment.bin>


More information about the llvm-commits mailing list