Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit fd7b88d

Browse files
committed
flattenSequenceOrSet: move outside of class
This function does not need to access private members of the class. Furthermore, it is only applicable to some subclasses of ScheduleTree, so it does not belong in the main class. Move it outside the class. Keep the definition as inline in the header.
1 parent 29f10ec commit fd7b88d

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

tc/core/polyhedral/schedule_tree.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ namespace detail {
126126

127127
std::ostream& operator<<(std::ostream& os, const ScheduleTree& tree);
128128

129+
void flattenSequenceOrSet(ScheduleTree* tree);
130+
129131
struct ScheduleTree {
130132
friend std::ostream& tc::polyhedral::detail::operator<<(
131133
std::ostream&,
@@ -385,26 +387,6 @@ struct ScheduleTree {
385387
return fromList<ScheduleTreeElemSequence>(std::forward<Args>(args)...);
386388
}
387389

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-
408390
// disallow empty lists in syntax
409391
template <typename T, typename Arg, typename... Args>
410392
static ScheduleTreeUPtr fromList(Arg&& arg, Args&&... args) {
@@ -422,7 +404,7 @@ struct ScheduleTree {
422404
auto res = ScheduleTreeUPtr(new T(ctx));
423405
res->appendChildren(
424406
vectorFromArgs(std::forward<Arg>(arg), std::forward<Args>(args)...));
425-
res->flattenSequenceOrSet();
407+
flattenSequenceOrSet(res.get());
426408
return res;
427409
}
428410

@@ -502,6 +484,26 @@ struct ScheduleTree {
502484
detail::ScheduleTreeType type_{detail::ScheduleTreeType::None};
503485
};
504486

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+
505507
} // namespace detail
506508
} // namespace polyhedral
507509
} // namespace tc

0 commit comments

Comments
 (0)