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

Commit 597e1da

Browse files
committed
ScheduleTree: replace operator== with treeEquals
In tree-like structures, the behavior of the default comparison operators (operator== and operator!=) is not intuitive. They may compare individual tree nodes or the subtrees rooted at those nodes. Replace the equality comparison operator on ScheduleTree with the treeEquals method, which makes it clear that subtrees are compared (as opposed to nodeEquals introduced previously). Removing the overloaded comparison operators may make it harder to use standard containers and algorithms on ScheduleTrees. However, the caller is never supposed to operate on ScheduleTrees by-value, and pointers are trivially comparable. Internal functions may define and use a comparator class with clear intended behavior when necessary. For external uses, explicitly-named functions offer a better alternative.
1 parent 82656e9 commit 597e1da

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

tc/core/polyhedral/schedule_isl_conversion.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ std::unique_ptr<ScheduleTree> fromIslSchedule(isl::schedule schedule) {
311311
// Note that the children of set and sequence nodes are always filters, so
312312
// they cannot be replaced by empty trees.
313313
bool validateSchedule(const ScheduleTree* st) {
314-
return *st == *fromIslSchedule(toIslSchedule(st));
314+
return st->treeEquals(fromIslSchedule(toIslSchedule(st)).get());
315315
}
316316

317317
bool validateSchedule(isl::schedule sc) {

tc/core/polyhedral/schedule_tree.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,21 +336,17 @@ vector<const ScheduleTree*> ScheduleTree::collectDFSPreorder(
336336
return functional::Filter(filterType, collectDFSPreorder(tree));
337337
}
338338

339-
bool ScheduleTree::operator==(const ScheduleTree& other) const {
340-
// ctx_ cmp ?
341-
if (type_ != other.type_) {
339+
bool ScheduleTree::treeEquals(const ScheduleTree* other) const {
340+
if (!nodeEquals(other)) {
342341
return false;
343342
}
344-
if (children_.size() != other.children_.size()) {
343+
if (numChildren() != other->numChildren()) {
345344
return false;
346345
}
347-
if (!this->nodeEquals(&other)) {
348-
return false;
349-
}
350-
TC_CHECK(!other.as<ScheduleTreeSet>())
346+
TC_CHECK(!other->as<ScheduleTreeSet>())
351347
<< "NYI: ScheduleTreeType::Set comparison";
352-
for (size_t i = 0; i < children_.size(); ++i) {
353-
if (*children_[i] != *other.children_[i]) {
348+
for (size_t i = 0, e = numChildren(); i < e; ++i) {
349+
if (!child({i})->treeEquals(other->child({i}))) {
354350
return false;
355351
}
356352
}

tc/core/polyhedral/schedule_tree.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ struct ScheduleTree {
156156
public:
157157
virtual ~ScheduleTree();
158158

159-
bool operator==(const ScheduleTree& other) const;
160-
bool operator!=(const ScheduleTree& other) const {
161-
return !(*this == other);
162-
}
163-
164159
// Swap a tree with with the given tree.
165160
void swapChild(size_t pos, ScheduleTreeUPtr& swappee) {
166161
TC_CHECK_GE(pos, 0u) << "position out of children bounds";
@@ -474,6 +469,10 @@ struct ScheduleTree {
474469
// use treeEquals() instead to compare entire trees.
475470
virtual bool nodeEquals(const ScheduleTree* other) const = 0;
476471

472+
// Comapre the subtree rooted at the current node to the subtree
473+
// rooted at "other".
474+
bool treeEquals(const ScheduleTree* other) const;
475+
477476
//
478477
// Data members
479478
//

test/test_cuda_mapper.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ struct PolyhedralMapperTest : public ::testing::Test {
144144
islNode = islNode.as<isl::schedule_node_band>().tile(mv);
145145
auto scheduleISL = fromIslSchedule(islNode.get_schedule().reset_user());
146146

147-
ASSERT_TRUE(*scheduleISL == *scheduleISLPP) << *scheduleISL << "\nVS\n"
148-
<< *scheduleISLPP;
147+
ASSERT_TRUE(scheduleISL->treeEquals(scheduleISLPP.get()))
148+
<< *scheduleISL << "\nVS\n"
149+
<< *scheduleISLPP;
149150
}
150151
}
151152

0 commit comments

Comments
 (0)