[PATCH] D30614: [APInt] Move operator~ out of line to make it better able to reused memory allocation from temporary objects

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 5 00:03:53 PST 2017


craig.topper created this revision.

This makes operator~ take the APInt by value so if it came from a temporary APInt the move constructor will get invoked and it will be able to reuse the memory allocation from the temporary.

This is similar to what was already done for 2s complement negation.


https://reviews.llvm.org/D30614

Files:
  include/llvm/ADT/APInt.h


Index: include/llvm/ADT/APInt.h
===================================================================
--- include/llvm/ADT/APInt.h
+++ include/llvm/ADT/APInt.h
@@ -612,17 +612,6 @@
   /// \returns *this decremented by one.
   APInt &operator--();
 
-  /// \brief Unary bitwise complement operator.
-  ///
-  /// Performs a bitwise complement operation on this APInt.
-  ///
-  /// \returns an APInt that is the bitwise complement of *this
-  APInt operator~() const {
-    APInt Result(*this);
-    Result.flipAllBits();
-    return Result;
-  }
-
   /// \brief Logical negation operator.
   ///
   /// Performs logical negation operation on this APInt.
@@ -1750,6 +1739,11 @@
 
 inline bool operator!=(uint64_t V1, const APInt &V2) { return V2 != V1; }
 
+inline APInt operator~(APInt v) {
+  v.flipAllBits();
+  return v;
+}
+
 inline APInt operator&(APInt a, uint64_t RHS) {
   a &= RHS;
   return a;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30614.90599.patch
Type: text/x-patch
Size: 902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170305/89338a67/attachment.bin>


More information about the llvm-commits mailing list