[polly] r282864 - [Support] Call isl_*_free() only on non-null pointers. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 08:29:43 PDT 2016


Author: meinersbur
Date: Fri Sep 30 10:29:43 2016
New Revision: 282864

URL: http://llvm.org/viewvc/llvm-project?rev=282864&view=rev
Log:
[Support] Call isl_*_free() only on non-null pointers. NFC.

Add a non-NULL check before calling the free function into functions that are
supposed to be inlined. First, this is a form of partial inlining of the free
function, namely the nullptr test that free has to do. Secondly, and more
importantly, it allows the compiler to remove the call to isl_*_free() when it
knows that the object is nullptr, for instance because the last call is a
take(). "Consuming" the last use of an ISL object using take()
(instead of copy()) is a common pattern.

Modified:
    polly/trunk/include/polly/Support/GICHelper.h

Modified: polly/trunk/include/polly/Support/GICHelper.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Support/GICHelper.h?rev=282864&r1=282863&r2=282864&view=diff
==============================================================================
--- polly/trunk/include/polly/Support/GICHelper.h (original)
+++ polly/trunk/include/polly/Support/GICHelper.h Fri Sep 30 10:29:43 2016
@@ -260,10 +260,14 @@ public:
     That.Obj = nullptr;
   }
   /* implicit */ IslPtr(NonowningIslPtr<T> That) : IslPtr(That.copy(), true) {}
-  ~IslPtr() { Traits::free(Obj); }
+  ~IslPtr() {
+    if (Obj)
+      Traits::free(Obj);
+  }
 
   ThisTy &operator=(const ThisTy &That) {
-    Traits::free(this->Obj);
+    if (Obj)
+      Traits::free(Obj);
     this->Obj = Traits::copy(That.Obj);
     return *this;
   }




More information about the llvm-commits mailing list