[polly] r294094 - [Support] Add convertZoneToTimepoints. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 4 07:42:17 PST 2017


Author: meinersbur
Date: Sat Feb  4 09:42:17 2017
New Revision: 294094

URL: http://llvm.org/viewvc/llvm-project?rev=294094&view=rev
Log:
[Support] Add convertZoneToTimepoints. NFC.

This function has been extracted from the upcoming DeLICM patch
(https://reviews.llvm.org/D24716).

In contrast to computeReachingWrite and computeArrayUnused,
convertZoneToTimepoints implies a format for zones (ranges between timepoints).
Zones at the moment are unique to DeLICM, but convertZoneToTimepoints makes most
sense in conjunction with the previous two functions.

Modified:
    polly/trunk/include/polly/Support/ISLTools.h
    polly/trunk/lib/Support/ISLTools.cpp
    polly/trunk/unittests/Isl/IslTest.cpp

Modified: polly/trunk/include/polly/Support/ISLTools.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Support/ISLTools.h?rev=294094&r1=294093&r2=294094&view=diff
==============================================================================
--- polly/trunk/include/polly/Support/ISLTools.h (original)
+++ polly/trunk/include/polly/Support/ISLTools.h Sat Feb  4 09:42:17 2017
@@ -299,6 +299,53 @@ IslPtr<isl_union_map> computeArrayUnused
                                          bool ReadEltInSameInst,
                                          bool InclLastRead, bool InclWrite);
 
+/// Convert a zone (range between timepoints) to timepoints.
+///
+/// A zone represents the time between (integer) timepoints, but not the
+/// timepoints themselves. This function can be used to determine whether a
+/// timepoint lies within a zone.
+///
+/// For instance, the range (1,3), representing the time between 1 and 3, is
+/// represented by the zone
+///
+/// { [i] : 1 < i <= 3 }
+///
+/// The set of timepoints that lie completely within this range is
+///
+/// { [i] : 1 < i < 3 }
+///
+/// A typical use-case is the range in which a value written by a store is
+/// available until it is overwritten by another value. If the write is at
+/// timepoint 1 and its value is overwritten by another value at timepoint 3,
+/// the value is available between those timepoints: timepoint 2 in this
+/// example.
+///
+///
+/// When InclStart is true, the range is interpreted left-inclusive, i.e. adds
+/// the timepoint 1 to the result:
+///
+/// { [i] : 1 <= i < 3 }
+///
+/// In the use-case mentioned above that means that the value written at
+/// timepoint 1 is already available in timepoint 1 (write takes place before
+/// any read of it even if executed at the same timepoint)
+///
+/// When InclEnd is true, the range is interpreted right-inclusive, i.e. adds
+/// the timepoint 3 to the result:
+///
+/// { [i] : 1 < i <= 3 }
+///
+/// In the use-case mentioned above that means that although the value is
+/// overwritten in timepoint 3, the old value is still available at timepoint 3
+/// (write takes place after any read even if executed at the same timepoint)
+///
+/// @param Zone      { Zone[] }
+/// @param InclStart Include timepoints adjacent to the beginning of a zone.
+/// @param InclEnd   Include timepoints adjacent to the ending of a zone.
+///
+/// @return { Scatter[] }
+IslPtr<isl_union_set> convertZoneToTimepoints(IslPtr<isl_union_set> Zone,
+                                              bool InclStart, bool InclEnd);
 } // namespace polly
 
 #endif /* POLLY_ISLTOOLS_H */

Modified: polly/trunk/lib/Support/ISLTools.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/ISLTools.cpp?rev=294094&r1=294093&r2=294094&view=diff
==============================================================================
--- polly/trunk/lib/Support/ISLTools.cpp (original)
+++ polly/trunk/lib/Support/ISLTools.cpp Sat Feb  4 09:42:17 2017
@@ -367,3 +367,19 @@ IslPtr<isl_union_map> polly::computeArra
       BeforeWritesBeforeAnyReads.take(),
       isl_union_map_domain_factor_domain(BetweenLastReadOverwrite.take())));
 }
+
+IslPtr<isl_union_set> polly::convertZoneToTimepoints(IslPtr<isl_union_set> Zone,
+                                                     bool InclStart,
+                                                     bool InclEnd) {
+  if (!InclStart && InclEnd)
+    return Zone;
+
+  auto ShiftedZone = shiftDim(Zone, -1, -1);
+  if (InclStart && !InclEnd)
+    return ShiftedZone;
+  else if (!InclStart && !InclEnd)
+    return give(isl_union_set_intersect(Zone.take(), ShiftedZone.take()));
+
+  assert(InclStart && InclEnd);
+  return give(isl_union_set_union(Zone.take(), ShiftedZone.take()));
+}

Modified: polly/trunk/unittests/Isl/IslTest.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/unittests/Isl/IslTest.cpp?rev=294094&r1=294093&r2=294094&view=diff
==============================================================================
--- polly/trunk/unittests/Isl/IslTest.cpp (original)
+++ polly/trunk/unittests/Isl/IslTest.cpp Sat Feb  4 09:42:17 2017
@@ -807,4 +807,57 @@ TEST(DeLICM, computeArrayUnused) {
                                UMAP("{ RW[] -> Elt[] }"), false, true, true));
 }
 
+TEST(DeLICM, convertZoneToTimepoints) {
+  std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
+                                                        &isl_ctx_free);
+
+  // Corner case: empty set
+  EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{}"), false, false));
+  EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{}"), true, false));
+  EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{}"), false, true));
+  EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{}"), true, true));
+
+  // Basic usage
+  EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{ [1] }"), false, false));
+  EXPECT_EQ(USET("{ [0] }"),
+            convertZoneToTimepoints(USET("{ [1] }"), true, false));
+  EXPECT_EQ(USET("{ [1] }"),
+            convertZoneToTimepoints(USET("{ [1] }"), false, true));
+  EXPECT_EQ(USET("{ [0]; [1] }"),
+            convertZoneToTimepoints(USET("{ [1] }"), true, true));
+
+  // Non-adjacent ranges
+  EXPECT_EQ(USET("{}"),
+            convertZoneToTimepoints(USET("{ [1]; [11] }"), false, false));
+  EXPECT_EQ(USET("{ [0]; [10] }"),
+            convertZoneToTimepoints(USET("{ [1]; [11] }"), true, false));
+  EXPECT_EQ(USET("{ [1]; [11] }"),
+            convertZoneToTimepoints(USET("{ [1]; [11] }"), false, true));
+  EXPECT_EQ(USET("{ [0]; [1]; [10]; [11] }"),
+            convertZoneToTimepoints(USET("{ [1]; [11] }"), true, true));
+
+  // Adjacent unit ranges
+  EXPECT_EQ(
+      USET("{ [i] : 0 < i < 10 }"),
+      convertZoneToTimepoints(USET("{ [i] : 0 < i <= 10 }"), false, false));
+  EXPECT_EQ(
+      USET("{ [i] : 0 <= i < 10 }"),
+      convertZoneToTimepoints(USET("{ [i] : 0 < i <= 10 }"), true, false));
+  EXPECT_EQ(
+      USET("{ [i] : 0 < i <= 10 }"),
+      convertZoneToTimepoints(USET("{ [i] : 0 < i <= 10 }"), false, true));
+  EXPECT_EQ(USET("{ [i] : 0 <= i <= 10 }"),
+            convertZoneToTimepoints(USET("{ [i] : 0 < i <= 10 }"), true, true));
+
+  // More than one dimension
+  EXPECT_EQ(USET("{}"),
+            convertZoneToTimepoints(USET("{ [0,1] }"), false, false));
+  EXPECT_EQ(USET("{ [0,0] }"),
+            convertZoneToTimepoints(USET("{ [0,1] }"), true, false));
+  EXPECT_EQ(USET("{ [0,1] }"),
+            convertZoneToTimepoints(USET("{ [0,1] }"), false, true));
+  EXPECT_EQ(USET("{ [0,0]; [0,1] }"),
+            convertZoneToTimepoints(USET("{ [0,1] }"), true, true));
+}
+
 } // anonymous namespace




More information about the llvm-commits mailing list