@@ -126,6 +126,8 @@ namespace detail {
126
126
127
127
std::ostream& operator <<(std::ostream& os, const ScheduleTree& tree);
128
128
129
+ void flattenSequenceOrSet (ScheduleTree* tree);
130
+
129
131
struct ScheduleTree {
130
132
friend std::ostream& tc::polyhedral::detail::operator <<(
131
133
std::ostream&,
@@ -385,26 +387,6 @@ struct ScheduleTree {
385
387
return fromList<ScheduleTreeElemSequence>(std::forward<Args>(args)...);
386
388
}
387
389
388
- // Flatten nested nodes of the same type.
389
- void flattenSequenceOrSet () {
390
- // This should be enforced by the type system...
391
- TC_CHECK (
392
- type_ == detail::ScheduleTreeType::Sequence ||
393
- type_ == detail::ScheduleTreeType::Set);
394
-
395
- // Iterate over the changing list of children. If a child has the same list
396
- // type as a parent, replace it with grandchildren and traverse them too.
397
- for (size_t i = 0 ; i < numChildren (); ++i) {
398
- if (child ({i})->type_ != type_) {
399
- continue ;
400
- }
401
- auto grandChildren = child ({i})->detachChildren ();
402
- detachChild (i);
403
- insertChildren (i, std::move (grandChildren));
404
- --i;
405
- }
406
- }
407
-
408
390
// disallow empty lists in syntax
409
391
template <typename T, typename Arg, typename ... Args>
410
392
static ScheduleTreeUPtr fromList (Arg&& arg, Args&&... args) {
@@ -422,7 +404,7 @@ struct ScheduleTree {
422
404
auto res = ScheduleTreeUPtr (new T (ctx));
423
405
res->appendChildren (
424
406
vectorFromArgs (std::forward<Arg>(arg), std::forward<Args>(args)...));
425
- res-> flattenSequenceOrSet ();
407
+ flattenSequenceOrSet (res. get () );
426
408
return res;
427
409
}
428
410
@@ -502,6 +484,26 @@ struct ScheduleTree {
502
484
detail::ScheduleTreeType type_{detail::ScheduleTreeType::None};
503
485
};
504
486
487
+ // Flatten nested nodes of the same type.
488
+ inline void flattenSequenceOrSet (ScheduleTree* tree) {
489
+ // This should be enforced by the type system...
490
+ TC_CHECK (
491
+ tree->type_ == ScheduleTreeType::Sequence ||
492
+ tree->type_ == ScheduleTreeType::Set);
493
+
494
+ // Iterate over the changing list of children. If a child has the same list
495
+ // type as a parent, replace it with grandchildren and traverse them too.
496
+ for (size_t i = 0 ; i < tree->numChildren (); ++i) {
497
+ if (tree->child ({i})->type_ != tree->type_ ) {
498
+ continue ;
499
+ }
500
+ auto grandChildren = tree->child ({i})->detachChildren ();
501
+ tree->detachChild (i);
502
+ tree->insertChildren (i, std::move (grandChildren));
503
+ --i;
504
+ }
505
+ }
506
+
505
507
} // namespace detail
506
508
} // namespace polyhedral
507
509
} // namespace tc
0 commit comments