Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the number of memory allocations in def-use #4904

Merged
merged 16 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify
Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
  • Loading branch information
asl committed Sep 10, 2024
commit feacfa9005c61fd3a388b46a120045c39989a2fa
23 changes: 11 additions & 12 deletions frontends/p4/def_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,6 @@ bool LocationSet::operator==(const LocationSet &other) const {
return it == other.end();
}

void ProgramPoints::add(const ProgramPoints *from) {
points.insert(from->points.begin(), from->points.end());
}

const ProgramPoints *ProgramPoints::merge(const ProgramPoints *with) const {
auto *result = new ProgramPoints(points);
result->points.insert(with->points.begin(), with->points.end());
return result;
}

ProgramPoint::ProgramPoint(const ProgramPoint &context, const IR::Node *node) {
assign(context, node);
}
Expand All @@ -302,6 +292,16 @@ bool ProgramPoint::operator==(const ProgramPoint &other) const {

std::size_t ProgramPoint::hash() const { return Util::hash_range(stack.begin(), stack.end()); }

void ProgramPoints::add(const ProgramPoints *from) {
points.insert(from->points.begin(), from->points.end());
}

const ProgramPoints *ProgramPoints::merge(const ProgramPoints *with) const {
auto *result = new ProgramPoints(points);
result->points.insert(with->points.begin(), with->points.end());
return result;
}

bool ProgramPoints::operator==(const ProgramPoints &other) const {
if (points.size() != other.points.size()) return false;
for (auto p : points)
Expand Down Expand Up @@ -364,8 +364,7 @@ const ProgramPoints *Definitions::getPoints(const LocationSet *locations) const

Definitions *Definitions::writes(ProgramPoint point, const LocationSet *locations) const {
auto result = new Definitions(*this);
auto points = new ProgramPoints();
points->add(point);
auto points = new ProgramPoints(point);
auto canon = locations->canonicalize();
for (auto l : *canon) result->setDefinition(l->to<BaseLocation>(), points);
return result;
Expand Down
1 change: 0 additions & 1 deletion frontends/p4/def_use.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ class ProgramPoints : public IHasDbPrint {
public:
ProgramPoints() = default;
explicit ProgramPoints(ProgramPoint point) { points.emplace(point); }
void add(ProgramPoint point) { points.emplace(point); }
void add(const ProgramPoints *from);
const ProgramPoints *merge(const ProgramPoints *with) const;
bool operator==(const ProgramPoints &other) const;
Expand Down