[llvm] r183100 - Introduce needsCleanup() for APFloat and APInt.

Manuel Klimek klimek at google.com
Mon Jun 3 06:03:05 PDT 2013


Author: klimek
Date: Mon Jun  3 08:03:05 2013
New Revision: 183100

URL: http://llvm.org/viewvc/llvm-project?rev=183100&view=rev
Log:
Introduce needsCleanup() for APFloat and APInt.

This is needed in clang so one can check if the object needs the
destructor called after its memory was freed. This is useful when
creating many APInt/APFloat objects with placement new, where the
overhead of tracking the pointers for cleanup is significant.

Modified:
    llvm/trunk/include/llvm/ADT/APFloat.h
    llvm/trunk/include/llvm/ADT/APInt.h
    llvm/trunk/lib/Support/APFloat.cpp

Modified: llvm/trunk/include/llvm/ADT/APFloat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APFloat.h?rev=183100&r1=183099&r2=183100&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Mon Jun  3 08:03:05 2013
@@ -201,6 +201,9 @@ public:
 
   /// @}
 
+  /// \brief Returns whether this instance allocated memory.
+  bool needsCleanup() const { return partCount() > 1; }
+
   /// \name Convenience "constructors"
   /// @{
 

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=183100&r1=183099&r2=183100&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Mon Jun  3 08:03:05 2013
@@ -293,7 +293,7 @@ public:
 
   /// \brief Destructor.
   ~APInt() {
-    if (!isSingleWord())
+    if (needsCleanup())
       delete[] pVal;
   }
 
@@ -303,6 +303,9 @@ public:
   ///  method Read).
   explicit APInt() : BitWidth(1) {}
 
+  /// \brief Returns whether this instance allocated memory.
+  bool needsCleanup() const { return !isSingleWord(); }
+
   /// Used to insert APInt objects, or objects that contain APInt objects, into
   ///  FoldingSets.
   void Profile(FoldingSetNodeID &id) const;

Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=183100&r1=183099&r2=183100&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Mon Jun  3 08:03:05 2013
@@ -580,7 +580,7 @@ APFloat::initialize(const fltSemantics *
 void
 APFloat::freeSignificand()
 {
-  if (partCount() > 1)
+  if (needsCleanup())
     delete [] significand.parts;
 }
 





More information about the llvm-commits mailing list