[polly] r308923 - Move MemoryAccess::InvalidDomain to isl++

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 13:30:34 PDT 2017


Author: grosser
Date: Mon Jul 24 13:30:34 2017
New Revision: 308923

URL: http://llvm.org/viewvc/llvm-project?rev=308923&view=rev
Log:
Move MemoryAccess::InvalidDomain to isl++

Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/External/isl/isl_flow.c

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=308923&r1=308922&r2=308923&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Mon Jul 24 13:30:34 2017
@@ -543,7 +543,7 @@ private:
   /// The invalid domain for an access describes all parameter combinations
   /// under which the statement looks to be executed but is in fact not because
   /// some assumption/restriction makes the access invalid.
-  isl_set *InvalidDomain;
+  isl::set InvalidDomain;
 
   // Properties describing the accessed array.
   // TODO: It might be possible to move them to ScopArrayInfo.
@@ -918,14 +918,10 @@ public:
   isl::pw_aff getPwAff(const SCEV *E);
 
   /// Get the invalid domain for this access.
-  __isl_give isl_set *getInvalidDomain() const {
-    return isl_set_copy(InvalidDomain);
-  }
+  isl::set getInvalidDomain() const { return InvalidDomain; }
 
   /// Get the invalid context for this access.
-  __isl_give isl_set *getInvalidContext() const {
-    return isl_set_params(getInvalidDomain());
-  }
+  isl::set getInvalidContext() const { return getInvalidDomain().params(); }
 
   /// Get the stride of this memory access in the specified Schedule. Schedule
   /// is a map from the statement to a schedule where the innermost dimension is

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=308923&r1=308922&r2=308923&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon Jul 24 13:30:34 2017
@@ -639,7 +639,7 @@ static MemoryAccess::ReductionType getRe
   }
 }
 
-MemoryAccess::~MemoryAccess() { isl_set_free(InvalidDomain); }
+MemoryAccess::~MemoryAccess() {}
 
 const ScopArrayInfo *MemoryAccess::getOriginalScopArrayInfo() const {
   isl::id ArrayId = getArrayId();
@@ -947,11 +947,10 @@ void MemoryAccess::buildAccessRelation(c
 
   // Initialize the invalid domain which describes all iterations for which the
   // access relation is not modeled correctly.
-  auto *StmtInvalidDomain = getStatement()->getInvalidDomain();
-  InvalidDomain = isl_set_empty(isl_set_get_space(StmtInvalidDomain));
-  isl_set_free(StmtInvalidDomain);
+  isl::set StmtInvalidDomain = isl::manage(getStatement()->getInvalidDomain());
+  InvalidDomain = isl::set::empty(StmtInvalidDomain.get_space());
 
-  isl_ctx *Ctx = Id.get_ctx().release();
+  isl::ctx Ctx = Id.get_ctx();
   isl::id BaseAddrId = SAI->getBasePtrId();
 
   if (getAccessInstruction() && isa<MemIntrinsic>(getAccessInstruction())) {
@@ -1029,9 +1028,9 @@ MemoryAccess::MemoryAccess(ScopStmt *Stm
 }
 
 void MemoryAccess::realignParams() {
-  auto *Ctx = Statement->getParent()->getContext();
-  InvalidDomain = isl_set_gist_params(InvalidDomain, isl_set_copy(Ctx));
-  AccessRelation = AccessRelation.gist_params(isl::manage(Ctx));
+  isl::set Ctx = isl::manage(Statement->getParent()->getContext());
+  InvalidDomain = InvalidDomain.gist_params(Ctx);
+  AccessRelation = AccessRelation.gist_params(Ctx);
 }
 
 const std::string MemoryAccess::getReductionOperatorStr() const {
@@ -1087,7 +1086,7 @@ isl::pw_aff MemoryAccess::getPwAff(const
   isl::set StmtDom = isl::manage(getStatement()->getDomain());
   StmtDom = StmtDom.reset_tuple_id();
   isl::set NewInvalidDom = StmtDom.intersect(isl::manage(PWAC.second));
-  InvalidDomain = isl_set_union(InvalidDomain, NewInvalidDom.release());
+  InvalidDomain = InvalidDomain.unite(NewInvalidDom);
   return isl::manage(PWAC.first);
 }
 
@@ -3965,7 +3964,7 @@ void Scop::addInvariantLoads(ScopStmt &S
     Type *Ty = LInst->getType();
     const SCEV *PointerSCEV = SE->getSCEV(LInst->getPointerOperand());
 
-    auto *MAInvalidCtx = MA->getInvalidContext();
+    auto *MAInvalidCtx = MA->getInvalidContext().release();
     bool NonHoistableCtxIsEmpty = isl_set_is_empty(NHCtx);
     bool MAInvalidCtxIsEmpty = isl_set_is_empty(MAInvalidCtx);
 

Modified: polly/trunk/lib/External/isl/isl_flow.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_flow.c?rev=308923&r1=308922&r2=308923&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_flow.c (original)
+++ polly/trunk/lib/External/isl/isl_flow.c Mon Jul 24 13:30:34 2017
@@ -311,6 +311,13 @@ error:
 	return NULL;
 }
 
+/* A helper struct carrying the isl_access_info and an error condition.
+ */
+struct access_sort_info {
+	isl_access_info *access_info;
+	int error;
+};
+
 /* Return -n, 0 or n (with n a positive value), depending on whether
  * the source access identified by p1 should be sorted before, together
  * or after that identified by p2.
@@ -323,10 +330,18 @@ error:
  * If not, we try to order the two statements based on the description
  * of the iteration domains.  This results in an arbitrary, but fairly
  * stable ordering.
+ *
+ * In case of an error, sort_info.error is set to true and all elements are
+ * reported to be equal.
  */
 static int access_sort_cmp(const void *p1, const void *p2, void *user)
 {
-	isl_access_info *acc = user;
+	struct access_sort_info *sort_info = user;
+	isl_access_info *acc = sort_info->access_info;
+
+	if (sort_info->error)
+		return 0;
+
 	const struct isl_labeled_map *i1, *i2;
 	int level1, level2;
 	uint32_t h1, h2;
@@ -334,16 +349,25 @@ static int access_sort_cmp(const void *p
 	i2 = (const struct isl_labeled_map *) p2;
 
 	level1 = acc->level_before(i1->data, i2->data);
+	if (level1 < 0)
+		goto error;
 	if (level1 % 2)
 		return -1;
 
 	level2 = acc->level_before(i2->data, i1->data);
+	if (level2 < 0)
+		goto error;
 	if (level2 % 2)
 		return 1;
 
 	h1 = isl_map_get_hash(i1->map);
 	h2 = isl_map_get_hash(i2->map);
 	return h1 > h2 ? 1 : h1 < h2 ? -1 : 0;
+
+error:
+	sort_info->error = 1;
+	return 0;
+
 }
 
 /* Sort the must source accesses in their textual order.
@@ -351,13 +375,21 @@ static int access_sort_cmp(const void *p
 static __isl_give isl_access_info *isl_access_info_sort_sources(
 	__isl_take isl_access_info *acc)
 {
+	struct access_sort_info sort_info;
+
+	sort_info.access_info = acc;
+	sort_info.error = 0;
+
 	if (!acc)
 		return NULL;
 	if (acc->n_must <= 1)
 		return acc;
 
 	if (isl_sort(acc->source, acc->n_must, sizeof(struct isl_labeled_map),
-		    access_sort_cmp, acc) < 0)
+		    access_sort_cmp, &sort_info) < 0)
+		return isl_access_info_free(acc);
+
+	if (sort_info.error)
 		return isl_access_info_free(acc);
 
 	return acc;
@@ -690,6 +722,9 @@ static int can_precede_at_level(int shar
  *
  * If temp_rel[j] is empty, then there can be no improvement and
  * we return immediately.
+ *
+ * This function returns 0 in case it was executed successfully and
+ * -1 in case of errors during the execution of this function.
  */
 static int intermediate_sources(__isl_keep isl_access_info *acc,
 	struct isl_map **temp_rel, int j, int sink_level)
@@ -703,11 +738,16 @@ static int intermediate_sources(__isl_ke
 	for (k = j - 1; k >= 0; --k) {
 		int plevel, plevel2;
 		plevel = acc->level_before(acc->source[k].data, acc->sink.data);
+		if (plevel < 0)
+			return -1;
+
 		if (!can_precede_at_level(plevel, sink_level))
 			continue;
 
 		plevel2 = acc->level_before(acc->source[j].data,
 						acc->source[k].data);
+		if (plevel2 < 0)
+			return -1;
 
 		for (level = sink_level; level <= depth; ++level) {
 			struct isl_map *T;
@@ -816,6 +856,8 @@ static __isl_give isl_map *all_intermedi
 
 		plevel = acc->level_before(acc->source[k].data,
 					acc->source[acc->n_must + j].data);
+		if (plevel < 0)
+			return isl_map_free(map);
 
 		for (level = sink_level; level <= depth; ++level) {
 			isl_map *T;
@@ -864,10 +906,14 @@ static __isl_give isl_map *all_intermedi
  * uncurried to [T -> S] -> K.
  * This result is then intersected with the dependence relation S -> K
  * to form the output.
+ *
+ * In case a negative depth is given, NULL is returned.
  */
 static __isl_give isl_map *coscheduled_source(__isl_keep isl_access_info *acc,
 	__isl_keep isl_map *old_map, int pos, int depth)
 {
+	if (depth < 0)
+		return NULL;
 	isl_space *space;
 	isl_set *set_C;
 	isl_map *read_map;
@@ -1009,6 +1055,9 @@ static __isl_give isl_flow *compute_mem_
 		isl_map *dep;
 
 		plevel = acc->level_before(acc->source[i].data, acc->sink.data);
+		if (plevel < 0)
+			goto error;
+
 		is_before = plevel & 1;
 		plevel >>= 1;
 
@@ -1029,6 +1078,11 @@ static __isl_give isl_flow *compute_mem_
 	res->must_no_source = mustdo;
 
 	return res;
+error:
+	isl_set_free(mustdo);
+	isl_set_free(maydo);
+	isl_flow_free(res);
+	return NULL;
 }
 
 /* Compute dependences for the case where there is at least one
@@ -1119,6 +1173,9 @@ static __isl_give isl_flow *compute_val_
 
 			plevel = acc->level_before(acc->source[j].data,
 						     acc->sink.data);
+			if (plevel < 0)
+				goto error;
+
 			if (!can_precede_at_level(plevel, level))
 				continue;
 
@@ -1126,13 +1183,15 @@ static __isl_give isl_flow *compute_val_
 			must_rel[j] = isl_map_union_disjoint(must_rel[j], T);
 			mustdo = rest;
 
-			intermediate_sources(acc, must_rel, j, level);
+			if (intermediate_sources(acc, must_rel, j, level))
+				goto error;
 
 			T = last_source(acc, maydo, j, level, &rest);
 			may_rel[j] = isl_map_union_disjoint(may_rel[j], T);
 			maydo = rest;
 
-			intermediate_sources(acc, may_rel, j, level);
+			if (intermediate_sources(acc, may_rel, j, level))
+				goto error;
 
 			if (isl_set_plain_is_empty(mustdo) &&
 			    isl_set_plain_is_empty(maydo))
@@ -1143,11 +1202,15 @@ static __isl_give isl_flow *compute_val_
 
 			plevel = acc->level_before(acc->source[j].data,
 						     acc->sink.data);
+			if (plevel < 0)
+				goto error;
 			if (!can_precede_at_level(plevel, level))
 				continue;
 
-			intermediate_sources(acc, must_rel, j, level);
-			intermediate_sources(acc, may_rel, j, level);
+			if (intermediate_sources(acc, must_rel, j, level))
+				goto error;
+			if (intermediate_sources(acc, may_rel, j, level))
+				goto error;
 		}
 
 		handle_coscheduled(acc, must_rel, may_rel, res);
@@ -1159,6 +1222,8 @@ static __isl_give isl_flow *compute_val_
 
 			plevel = acc->level_before(acc->source[acc->n_must + j].data,
 						     acc->sink.data);
+			if (plevel < 0)
+				goto error;
 			if (!can_precede_at_level(plevel, level))
 				continue;
 




More information about the llvm-commits mailing list