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

Commit b66ba3e

Browse files
committed
ScheduleTreeBand: hide copy constructor
ScheduleTree nodes are not supposed to be manipulated by-value, only via unique pointers. Make the copy constructor of ScheduleTreeBand private, similarly to its main constructor, and provide a static member function to return copies wrapped in a unique pointer. Note that unlike the conventional copy constructor, this static function takes a pointer to the tree rather than a reference. This keeps the API consistent as all other functions manipulate with pointers to the tree nodes rather than references.
1 parent ff810a8 commit b66ba3e

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

tc/core/polyhedral/schedule_tree.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static std::unique_ptr<ScheduleTree> makeElem(const ScheduleTree& st) {
137137
if (st.type_ == detail::ScheduleTreeType::None) {
138138
LOG(FATAL) << "Hit Error node!";
139139
}
140-
ELEM_MAKE_CASE(ScheduleTreeBand)
140+
ELEM_MAKE_CASE_CSTR(ScheduleTreeBand)
141141
ELEM_MAKE_CASE_CSTR(ScheduleTreeContext)
142142
ELEM_MAKE_CASE_CSTR(ScheduleTreeDomain)
143143
ELEM_MAKE_CASE_CSTR(ScheduleTreeExtension)

tc/core/polyhedral/schedule_tree_elem.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ std::unique_ptr<ScheduleTreeBand> ScheduleTreeBand::make(
201201
return band;
202202
}
203203

204+
std::unique_ptr<ScheduleTreeBand> ScheduleTreeBand::make(
205+
const ScheduleTreeBand* tree,
206+
std::vector<ScheduleTreeUPtr>&& children) {
207+
auto res = std::unique_ptr<ScheduleTreeBand>(new ScheduleTreeBand(*tree));
208+
res->appendChildren(std::move(children));
209+
return res;
210+
}
211+
204212
// Return the number of scheduling dimensions in the band
205213
size_t ScheduleTreeBand::nMember() const {
206214
size_t res = mupa_.size();

tc/core/polyhedral/schedule_tree_elem.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,17 @@ struct ScheduleTreeSet : public ScheduleTree {
261261
struct ScheduleTreeBand : public ScheduleTree {
262262
private:
263263
explicit ScheduleTreeBand(isl::ctx ctx) : ScheduleTree(ctx, {}, NodeType) {}
264-
265-
public:
266-
static constexpr detail::ScheduleTreeType NodeType =
267-
detail::ScheduleTreeType::Band;
268-
269264
ScheduleTreeBand(const ScheduleTreeBand& eb)
270265
: ScheduleTree(eb),
271266
permutable_(eb.permutable_),
272267
mupa_(eb.mupa_),
273268
coincident_(eb.coincident_),
274269
unroll_(eb.unroll_) {}
270+
271+
public:
272+
static constexpr detail::ScheduleTreeType NodeType =
273+
detail::ScheduleTreeType::Band;
274+
275275
virtual ~ScheduleTreeBand() override {}
276276

277277
bool operator==(const ScheduleTreeBand& other) const;
@@ -290,6 +290,9 @@ struct ScheduleTreeBand : public ScheduleTree {
290290
std::vector<bool> coincident,
291291
std::vector<bool> unroll,
292292
std::vector<ScheduleTreeUPtr>&& children = {});
293+
static std::unique_ptr<ScheduleTreeBand> make(
294+
const ScheduleTreeBand* tree,
295+
std::vector<ScheduleTreeUPtr>&& children = {});
293296

294297
// Return the number of scheduling dimensions in the band
295298
size_t nMember() const;

0 commit comments

Comments
 (0)