[polly] r295998 - [Support] Remove NonowningIslPtr. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 23 09:57:27 PST 2017


Author: meinersbur
Date: Thu Feb 23 11:57:27 2017
New Revision: 295998

URL: http://llvm.org/viewvc/llvm-project?rev=295998&view=rev
Log:
[Support] Remove NonowningIslPtr. NFC.

NonowningIslPtr<isl_X> was used as types of function parameters when the
function does not consume the isl object, i.e. an __isl_keep parameter.

The alternatives are:

1. IslPtr<isl_X>
   This has additional calls to isl_X_copy and isl_X_free to
   increase/decrease the reference counter even though not needed. The
   caller already owns a reference to the isl object.

2. const IslPtr<isl_X>&
   This does not change the reference counter, but requires an
   additional load to get the pointer to the isl object (instead of just
   passing the pointer itself).
   Moreover, the compiler cannot rely on the constness of the pointer
   and has to reload the pointer every time it writes to memory (unless
   alias analysis such as TBAA says it is not possible).

The isl C++ bindings currently in development do not have an equivalent
to NonowningIslPtr and adding one would make the binding more
complicated and its advantage in performance is small. In order to
simplify the transition to these C++ bindings, remove NonowningIslPtr.
Change every former use of it to alternative 2 mentioned aboce
(const IslPtr<isl_X>&).

Modified:
    polly/trunk/include/polly/Support/GICHelper.h
    polly/trunk/include/polly/Support/ISLTools.h
    polly/trunk/lib/Support/GICHelper.cpp
    polly/trunk/lib/Support/ISLTools.cpp
    polly/trunk/lib/Transform/FlattenAlgo.cpp
    polly/trunk/lib/Transform/FlattenSchedule.cpp
    polly/trunk/unittests/DeLICM/DeLICMTest.cpp

Modified: polly/trunk/include/polly/Support/GICHelper.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Support/GICHelper.h?rev=295998&r1=295997&r2=295998&view=diff
==============================================================================
--- polly/trunk/include/polly/Support/GICHelper.h (original)
+++ polly/trunk/include/polly/Support/GICHelper.h Thu Feb 23 11:57:27 2017
@@ -227,8 +227,6 @@ DECLARE_TRAITS(union_pw_aff)
 DECLARE_TRAITS(multi_union_pw_aff)
 DECLARE_TRAITS(union_pw_multi_aff)
 
-template <typename T> class NonowningIslPtr;
-
 /// Smart pointer to an ISL object.
 ///
 /// An object of this class owns an reference of an ISL object, meaning if will
@@ -266,7 +264,6 @@ public:
   /* implicit */ IslPtr(ThisTy &&That) : IslPtr(That.Obj) {
     That.Obj = nullptr;
   }
-  /* implicit */ IslPtr(NonowningIslPtr<T> That) : IslPtr(That.copy()) {}
   ~IslPtr() {
     if (Obj)
       Traits::free(Obj);
@@ -327,88 +324,39 @@ operator<<(llvm::DiagnosticInfoOptimizat
   return OS;
 }
 
-/// Smart pointer to an ISL object, but does not release it when destroyed.
-///
-/// This is meant to be used as function parameter type. The caller guarantees
-/// that the reference is alive during the function's execution and hence
-/// doesn't need to add a reference. Therefore, it is equivalent to the
-/// __isl_keep annotation (IslPtr being equivalent to __isl_take which can be
-/// either copied or moved).
-///
-/// Just as IslPtr, it has keep() and copy() methods. The take() method is
-/// missing as this would steal the reference from the owner (the caller).
-template <typename T> class NonowningIslPtr {
-  typedef NonowningIslPtr<T> ThisTy;
-  typedef IslObjTraits<T> Traits;
-
-private:
-  T *Obj;
-
-  /* implicit */ NonowningIslPtr(__isl_keep T *Obj) : Obj(Obj) {}
-
-public:
-  NonowningIslPtr() : Obj(nullptr) {}
-  /* implicit */ NonowningIslPtr(std::nullptr_t That) : NonowningIslPtr() {}
-
-  /* implicit */ NonowningIslPtr(const IslPtr<T> &That)
-      : NonowningIslPtr(That.keep()) {}
-
-  explicit operator bool() const { return Obj; }
-
-  static void swap(ThisTy &LHS, ThisTy &RHS) { std::swap(LHS.Obj, RHS.Obj); }
-
-  T *keep() const { return Obj; }
-  __isl_give T *copy() const { return Traits::copy(Obj); }
-
-  isl_ctx *getCtx() const { return Traits::get_ctx(Obj); }
-  std::string toStr() const { return Traits::to_str(Obj); }
-
-  /// Print a string representation of this ISL object to stderr.
-  ///
-  /// @see IslPtr<T>::dump()
-  void dump() const;
-};
-
-template <typename T>
-static llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
-                                     NonowningIslPtr<T> Obj) {
-  OS << IslObjTraits<T>::to_str(Obj.keep());
-  return OS;
-}
-
 /// Enumerate all isl_basic_maps of an isl_map.
 ///
 /// This basically wraps isl_map_foreach_basic_map() and allows to call back
 /// C++11 closures.
-void foreachElt(NonowningIslPtr<isl_map> Map,
+void foreachElt(const IslPtr<isl_map> &Map,
                 const std::function<void(IslPtr<isl_basic_map>)> &F);
 
 /// Enumerate all isl_basic_sets of an isl_set.
 ///
 /// This basically wraps isl_set_foreach_basic_set() and allows to call back
 /// C++11 closures.
-void foreachElt(NonowningIslPtr<isl_set> Set,
+void foreachElt(const IslPtr<isl_set> &Set,
                 const std::function<void(IslPtr<isl_basic_set>)> &F);
 
 /// Enumerate all isl_maps of an isl_union_map.
 ///
 /// This basically wraps isl_union_map_foreach_map() and allows to call back
 /// C++11 closures.
-void foreachElt(NonowningIslPtr<isl_union_map> UMap,
+void foreachElt(const IslPtr<isl_union_map> &UMap,
                 const std::function<void(IslPtr<isl_map> Map)> &F);
 
 /// Enumerate all isl_sets of an isl_union_set.
 ///
 /// This basically wraps isl_union_set_foreach_set() and allows to call back
 /// C++11 closures.
-void foreachElt(NonowningIslPtr<isl_union_set> USet,
+void foreachElt(const IslPtr<isl_union_set> &USet,
                 const std::function<void(IslPtr<isl_set> Set)> &F);
 
 /// Enumerate all isl_pw_aff of an isl_union_pw_aff.
 ///
 /// This basically wraps isl_union_pw_aff(), but also allows to call back C++11
 /// closures.
-void foreachElt(NonowningIslPtr<isl_union_pw_aff> UPwAff,
+void foreachElt(const IslPtr<isl_union_pw_aff> &UPwAff,
                 const std::function<void(IslPtr<isl_pw_aff>)> &F);
 
 /// Enumerate all polyhedra of an isl_map.
@@ -424,7 +372,7 @@ void foreachElt(NonowningIslPtr<isl_unio
 /// @return The isl_stat returned by the last callback invocation; isl_stat_ok
 ///         if the collection was empty.
 isl_stat
-foreachEltWithBreak(NonowningIslPtr<isl_map> Map,
+foreachEltWithBreak(const IslPtr<isl_map> &Map,
                     const std::function<isl_stat(IslPtr<isl_basic_map>)> &F);
 
 /// Enumerate all isl_maps of an isl_union_map.
@@ -441,7 +389,7 @@ foreachEltWithBreak(NonowningIslPtr<isl_
 /// @return The isl_stat returned by the last callback invocation; isl_stat_ok
 ///         if the collection was initially empty.
 isl_stat
-foreachEltWithBreak(NonowningIslPtr<isl_union_map> UMap,
+foreachEltWithBreak(const IslPtr<isl_union_map> &UMap,
                     const std::function<isl_stat(IslPtr<isl_map> Map)> &F);
 
 /// Enumerate all pieces of an isl_pw_aff.
@@ -457,7 +405,7 @@ foreachEltWithBreak(NonowningIslPtr<isl_
 /// @return The isl_stat returned by the last callback invocation; isl_stat_ok
 ///         if the collection was initially empty.
 isl_stat foreachPieceWithBreak(
-    NonowningIslPtr<isl_pw_aff> PwAff,
+    const IslPtr<isl_pw_aff> &PwAff,
     const std::function<isl_stat(IslPtr<isl_set>, IslPtr<isl_aff>)> &F);
 
 /// Scoped limit of ISL operations.

Modified: polly/trunk/include/polly/Support/ISLTools.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Support/ISLTools.h?rev=295998&r1=295997&r2=295998&view=diff
==============================================================================
--- polly/trunk/include/polly/Support/ISLTools.h (original)
+++ polly/trunk/include/polly/Support/ISLTools.h Thu Feb 23 11:57:27 2017
@@ -45,7 +45,7 @@ IslPtr<isl_union_map> beforeScatter(IslP
 IslPtr<isl_map> afterScatter(IslPtr<isl_map> Map, bool Strict);
 
 /// Piecewise afterScatter(IslPtr<isl_map>,bool).
-IslPtr<isl_union_map> afterScatter(NonowningIslPtr<isl_union_map> UMap,
+IslPtr<isl_union_map> afterScatter(const IslPtr<isl_union_map> &UMap,
                                    bool Strict);
 
 /// Construct a range of timepoints between two timepoints.
@@ -114,13 +114,13 @@ IslPtr<isl_set> singleton(IslPtr<isl_uni
 /// The implementation currently returns the maximum number of dimensions it
 /// encounters, if different, and 0 if none is encountered. However, most other
 /// code will most likely fail if one of these happen.
-unsigned getNumScatterDims(NonowningIslPtr<isl_union_map> Schedule);
+unsigned getNumScatterDims(const IslPtr<isl_union_map> &Schedule);
 
 /// Return the scatter space of a @p Schedule.
 ///
 /// This is basically the range space of the schedule map, but harder to
 /// determine because it is an isl_union_map.
-IslPtr<isl_space> getScatterSpace(NonowningIslPtr<isl_union_map> Schedule);
+IslPtr<isl_space> getScatterSpace(const IslPtr<isl_union_map> &Schedule);
 
 /// Construct an identity map for the given domain values.
 ///
@@ -136,7 +136,7 @@ IslPtr<isl_space> getScatterSpace(Nonown
 ///
 /// @return { Space[] -> Space[] }
 ///         A map that maps each value of @p USet to itself.
-IslPtr<isl_union_map> makeIdentityMap(NonowningIslPtr<isl_union_set> USet,
+IslPtr<isl_union_map> makeIdentityMap(const IslPtr<isl_union_set> &USet,
                                       bool RestrictDomain);
 
 /// Reverse the nested map tuple in @p Map's domain.
@@ -147,7 +147,7 @@ IslPtr<isl_union_map> makeIdentityMap(No
 IslPtr<isl_map> reverseDomain(IslPtr<isl_map> Map);
 
 /// Piecewise reverseDomain(IslPtr<isl_map>).
-IslPtr<isl_union_map> reverseDomain(NonowningIslPtr<isl_union_map> UMap);
+IslPtr<isl_union_map> reverseDomain(const IslPtr<isl_union_map> &UMap);
 
 /// Add a constant to one dimension of a set.
 ///

Modified: polly/trunk/lib/Support/GICHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/GICHelper.cpp?rev=295998&r1=295997&r2=295998&view=diff
==============================================================================
--- polly/trunk/lib/Support/GICHelper.cpp (original)
+++ polly/trunk/lib/Support/GICHelper.cpp Thu Feb 23 11:57:27 2017
@@ -205,12 +205,7 @@ std::string polly::getIslCompatibleName(
 }
 
 #define DEFINE_ISLPTR(TYPE)                                                    \
-  template <> void IslPtr<isl_##TYPE>::dump() const {                          \
-    isl_##TYPE##_dump(Obj);                                                    \
-  }                                                                            \
-  template <> void NonowningIslPtr<isl_##TYPE>::dump() const {                 \
-    isl_##TYPE##_dump(Obj);                                                    \
-  }
+  template <> void IslPtr<isl_##TYPE>::dump() const { isl_##TYPE##_dump(Obj); }
 
 namespace polly {
 DEFINE_ISLPTR(id)
@@ -232,7 +227,7 @@ DEFINE_ISLPTR(multi_union_pw_aff)
 DEFINE_ISLPTR(union_pw_multi_aff)
 }
 
-void polly::foreachElt(NonowningIslPtr<isl_map> Map,
+void polly::foreachElt(const IslPtr<isl_map> &Map,
                        const std::function<void(IslPtr<isl_basic_map>)> &F) {
   isl_map_foreach_basic_map(
       Map.keep(),
@@ -246,7 +241,7 @@ void polly::foreachElt(NonowningIslPtr<i
       const_cast<void *>(static_cast<const void *>(&F)));
 }
 
-void polly::foreachElt(NonowningIslPtr<isl_set> Set,
+void polly::foreachElt(const IslPtr<isl_set> &Set,
                        const std::function<void(IslPtr<isl_basic_set>)> &F) {
   isl_set_foreach_basic_set(
       Set.keep(),
@@ -260,7 +255,7 @@ void polly::foreachElt(NonowningIslPtr<i
       const_cast<void *>(static_cast<const void *>(&F)));
 }
 
-void polly::foreachElt(NonowningIslPtr<isl_union_map> UMap,
+void polly::foreachElt(const IslPtr<isl_union_map> &UMap,
                        const std::function<void(IslPtr<isl_map> Map)> &F) {
   isl_union_map_foreach_map(
       UMap.keep(),
@@ -273,7 +268,7 @@ void polly::foreachElt(NonowningIslPtr<i
       const_cast<void *>(static_cast<const void *>(&F)));
 }
 
-void polly::foreachElt(NonowningIslPtr<isl_union_set> USet,
+void polly::foreachElt(const IslPtr<isl_union_set> &USet,
                        const std::function<void(IslPtr<isl_set> Set)> &F) {
   isl_union_set_foreach_set(
       USet.keep(),
@@ -286,7 +281,7 @@ void polly::foreachElt(NonowningIslPtr<i
       const_cast<void *>(static_cast<const void *>(&F)));
 }
 
-void polly::foreachElt(NonowningIslPtr<isl_union_pw_aff> UPwAff,
+void polly::foreachElt(const IslPtr<isl_union_pw_aff> &UPwAff,
                        const std::function<void(IslPtr<isl_pw_aff>)> &F) {
   isl_union_pw_aff_foreach_pw_aff(
       UPwAff.keep(),
@@ -300,7 +295,7 @@ void polly::foreachElt(NonowningIslPtr<i
 }
 
 isl_stat polly::foreachEltWithBreak(
-    NonowningIslPtr<isl_map> Map,
+    const IslPtr<isl_map> &Map,
     const std::function<isl_stat(IslPtr<isl_basic_map>)> &F) {
   return isl_map_foreach_basic_map(
       Map.keep(),
@@ -313,7 +308,7 @@ isl_stat polly::foreachEltWithBreak(
 }
 
 isl_stat polly::foreachEltWithBreak(
-    NonowningIslPtr<isl_union_map> UMap,
+    const IslPtr<isl_union_map> &UMap,
     const std::function<isl_stat(IslPtr<isl_map> Map)> &F) {
   return isl_union_map_foreach_map(
       UMap.keep(),
@@ -327,7 +322,7 @@ isl_stat polly::foreachEltWithBreak(
 }
 
 isl_stat polly::foreachPieceWithBreak(
-    NonowningIslPtr<isl_pw_aff> PwAff,
+    const IslPtr<isl_pw_aff> &PwAff,
     const std::function<isl_stat(IslPtr<isl_set>, IslPtr<isl_aff>)> &F) {
   return isl_pw_aff_foreach_piece(
       PwAff.keep(),

Modified: polly/trunk/lib/Support/ISLTools.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/ISLTools.cpp?rev=295998&r1=295997&r2=295998&view=diff
==============================================================================
--- polly/trunk/lib/Support/ISLTools.cpp (original)
+++ polly/trunk/lib/Support/ISLTools.cpp Thu Feb 23 11:57:27 2017
@@ -106,7 +106,7 @@ IslPtr<isl_map> polly::afterScatter(IslP
   return give(isl_map_apply_range(Map.take(), ScatterRel.take()));
 }
 
-IslPtr<isl_union_map> polly::afterScatter(NonowningIslPtr<isl_union_map> UMap,
+IslPtr<isl_union_map> polly::afterScatter(const IslPtr<isl_union_map> &UMap,
                                           bool Strict) {
   auto Result = give(isl_union_map_empty(isl_union_map_get_space(UMap.keep())));
   foreachElt(UMap, [=, &Result](IslPtr<isl_map> Map) {
@@ -163,7 +163,7 @@ IslPtr<isl_set> polly::singleton(IslPtr<
   return Result;
 }
 
-unsigned polly::getNumScatterDims(NonowningIslPtr<isl_union_map> Schedule) {
+unsigned polly::getNumScatterDims(const IslPtr<isl_union_map> &Schedule) {
   unsigned Dims = 0;
   foreachElt(Schedule, [&Dims](IslPtr<isl_map> Map) {
     Dims = std::max(Dims, isl_map_dim(Map.keep(), isl_dim_out));
@@ -172,7 +172,7 @@ unsigned polly::getNumScatterDims(Nonown
 }
 
 IslPtr<isl_space>
-polly::getScatterSpace(NonowningIslPtr<isl_union_map> Schedule) {
+polly::getScatterSpace(const IslPtr<isl_union_map> &Schedule) {
   if (!Schedule)
     return nullptr;
   auto Dims = getNumScatterDims(Schedule);
@@ -181,9 +181,8 @@ polly::getScatterSpace(NonowningIslPtr<i
   return give(isl_space_add_dims(ScatterSpace.take(), isl_dim_set, Dims));
 }
 
-IslPtr<isl_union_map>
-polly::makeIdentityMap(NonowningIslPtr<isl_union_set> USet,
-                       bool RestrictDomain) {
+IslPtr<isl_union_map> polly::makeIdentityMap(const IslPtr<isl_union_set> &USet,
+                                             bool RestrictDomain) {
   auto Result = give(isl_union_map_empty(isl_union_set_get_space(USet.keep())));
   foreachElt(USet, [=, &Result](IslPtr<isl_set> Set) {
     auto IdentityMap = give(isl_map_identity(
@@ -205,8 +204,7 @@ IslPtr<isl_map> polly::reverseDomain(Isl
   return give(isl_map_apply_domain(Map.take(), Swap.take()));
 }
 
-IslPtr<isl_union_map>
-polly::reverseDomain(NonowningIslPtr<isl_union_map> UMap) {
+IslPtr<isl_union_map> polly::reverseDomain(const IslPtr<isl_union_map> &UMap) {
   auto Result = give(isl_union_map_empty(isl_union_map_get_space(UMap.keep())));
   foreachElt(UMap, [=, &Result](IslPtr<isl_map> Map) {
     auto Reversed = reverseDomain(std::move(Map));

Modified: polly/trunk/lib/Transform/FlattenAlgo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Transform/FlattenAlgo.cpp?rev=295998&r1=295997&r2=295998&view=diff
==============================================================================
--- polly/trunk/lib/Transform/FlattenAlgo.cpp (original)
+++ polly/trunk/lib/Transform/FlattenAlgo.cpp Thu Feb 23 11:57:27 2017
@@ -45,14 +45,14 @@ bool isDimBoundedByParameter(IslPtr<isl_
 }
 
 /// Whether BMap's first out-dimension is not a constant.
-bool isVariableDim(NonowningIslPtr<isl_basic_map> BMap) {
+bool isVariableDim(const IslPtr<isl_basic_map> &BMap) {
   auto FixedVal =
       give(isl_basic_map_plain_get_val_if_fixed(BMap.keep(), isl_dim_out, 0));
   return !FixedVal || isl_val_is_nan(FixedVal.keep());
 }
 
 /// Whether Map's first out dimension is no constant nor piecewise constant.
-bool isVariableDim(NonowningIslPtr<isl_map> Map) {
+bool isVariableDim(const IslPtr<isl_map> &Map) {
   return foreachEltWithBreak(Map, [](IslPtr<isl_basic_map> BMap) -> isl_stat {
     if (isVariableDim(BMap))
       return isl_stat_error;
@@ -61,7 +61,7 @@ bool isVariableDim(NonowningIslPtr<isl_m
 }
 
 /// Whether UMap's first out dimension is no (piecewise) constant.
-bool isVariableDim(NonowningIslPtr<isl_union_map> UMap) {
+bool isVariableDim(const IslPtr<isl_union_map> &UMap) {
   return foreachEltWithBreak(UMap, [](IslPtr<isl_map> Map) -> isl_stat {
     if (isVariableDim(Map))
       return isl_stat_error;
@@ -155,7 +155,7 @@ IslPtr<isl_union_pw_aff> multiply(IslPtr
 ///
 /// It is assumed that all maps in the maps have at least the necessary number
 /// of out dimensions.
-IslPtr<isl_union_map> scheduleProjectOut(NonowningIslPtr<isl_union_map> UMap,
+IslPtr<isl_union_map> scheduleProjectOut(const IslPtr<isl_union_map> &UMap,
                                          unsigned first, unsigned n) {
   if (n == 0)
     return UMap; /* isl_map_project_out would also reset the tuple, which should
@@ -175,7 +175,7 @@ IslPtr<isl_union_map> scheduleProjectOut
 /// Because this function takes an isl_union_map, the out dimensions could be
 /// different. We return the maximum number in this case. However, a different
 /// number of dimensions is not supported by the other code in this file.
-size_t scheduleScatterDims(NonowningIslPtr<isl_union_map> Schedule) {
+size_t scheduleScatterDims(const IslPtr<isl_union_map> &Schedule) {
   unsigned Dims = 0;
   foreachElt(Schedule, [&Dims](IslPtr<isl_map> Map) {
     Dims = std::max(Dims, isl_map_dim(Map.keep(), isl_dim_out));

Modified: polly/trunk/lib/Transform/FlattenSchedule.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Transform/FlattenSchedule.cpp?rev=295998&r1=295997&r2=295998&view=diff
==============================================================================
--- polly/trunk/lib/Transform/FlattenSchedule.cpp (original)
+++ polly/trunk/lib/Transform/FlattenSchedule.cpp Thu Feb 23 11:57:27 2017
@@ -27,7 +27,7 @@ namespace {
 /// Print a schedule to @p OS.
 ///
 /// Prints the schedule for each statements on a new line.
-void printSchedule(raw_ostream &OS, NonowningIslPtr<isl_union_map> Schedule,
+void printSchedule(raw_ostream &OS, const IslPtr<isl_union_map> &Schedule,
                    int indent) {
   foreachElt(Schedule, [&OS, indent](IslPtr<isl_map> Map) {
     OS.indent(indent) << Map << "\n";

Modified: polly/trunk/unittests/DeLICM/DeLICMTest.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/unittests/DeLICM/DeLICMTest.cpp?rev=295998&r1=295997&r2=295998&view=diff
==============================================================================
--- polly/trunk/unittests/DeLICM/DeLICMTest.cpp (original)
+++ polly/trunk/unittests/DeLICM/DeLICMTest.cpp Thu Feb 23 11:57:27 2017
@@ -22,7 +22,7 @@ using namespace polly;
 namespace {
 
 /// Get the universes of all spaces in @p USet.
-IslPtr<isl_union_set> unionSpace(NonowningIslPtr<isl_union_set> USet) {
+IslPtr<isl_union_set> unionSpace(const IslPtr<isl_union_set> &USet) {
   auto Result = give(isl_union_set_empty(isl_union_set_get_space(USet.keep())));
   foreachElt(USet, [=, &Result](IslPtr<isl_set> Set) {
     auto Space = give(isl_set_get_space(Set.keep()));




More information about the llvm-commits mailing list