@@ -188,6 +188,30 @@ void fixThreadsBelow(
188188 mscop.mapThreadsBackward (bandTree);
189189}
190190
191+ /*
192+ * Try and order the other statements in "domain" (if any)
193+ * before the "updates" statements, returning true is the operation succeeds.
194+ * In particular, only do this if it doesn't violate any dependences.
195+ * TODO (#454): order statements before or after the reduction based on
196+ * dependences.
197+ */
198+ bool separatedOut (
199+ Scop& scop,
200+ detail::ScheduleTree* tree,
201+ isl::union_set domain,
202+ isl::union_set updates) {
203+ auto other = domain.subtract (updates);
204+ if (other.is_empty ()) {
205+ return true ;
206+ }
207+ auto dependences = scop.activeDependences (tree);
208+ if (!canOrderBefore (scop.scheduleRoot (), tree, other, dependences)) {
209+ return false ;
210+ }
211+ orderBefore (scop.scheduleRoot (), tree, other);
212+ return true ;
213+ }
214+
191215} // namespace
192216
193217bool MappedScop::detectReductions (detail::ScheduleTree* tree) {
@@ -238,16 +262,8 @@ bool MappedScop::detectReductions(detail::ScheduleTree* tree) {
238262 // Order the other statements (if any) before the update statements
239263 // to ensure the band from which the reduction band has been split off
240264 // only contains update statements.
241- // Only do this if it doesn't violate any dependences.
242- // TODO (#454): order statements before or after the reduction based on
243- // dependences.
244- auto other = domain.subtract (updates);
245- if (!other.is_empty ()) {
246- auto dependences = scop_->activeDependences (tree);
247- if (!canOrderBefore (scop_->scheduleRoot (), tree, other, dependences)) {
248- return false ;
249- }
250- orderBefore (scop_->scheduleRoot (), tree, other);
265+ if (!separatedOut (scop (), tree, domain, updates)) {
266+ return false ;
251267 }
252268 reductionBandUpdates_.emplace (tree, Reduction (updateIds));
253269 return true ;
0 commit comments