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

Do less redundant work in UnpackBuffers #8104

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Changes from all commits
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
37 changes: 23 additions & 14 deletions src/UnpackBuffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,46 @@ class FindBufferSymbols : public IRVisitor {
void visit_param(const string &ref_name, const Parameter &param) {
if (param.defined() && param.is_buffer()) {
const string &name = param.name();
buffers[name] =
BufferInfo{Variable::make(type_of<halide_buffer_t *>(), name + ".buffer", param),
param.dimensions()};
auto r = buffers.try_emplace(name);
if (r.second) {
// It's the first time we've seen this Parameter
r.first->second.handle = Variable::make(type_of<halide_buffer_t *>(), name + ".buffer", param);
r.first->second.dimensions = param.dimensions();
}
}
}

void visit_buffer(const string &ref_name, const Buffer<> &buffer) {
if (buffer.defined()) {
const string &name = buffer.name();
buffers[name] =
BufferInfo{Variable::make(type_of<halide_buffer_t *>(), name + ".buffer", buffer),
buffer.dimensions()};
auto r = buffers.try_emplace(name);
if (r.second) {
// It's the first time we've seen this Buffer
r.first->second.handle = Variable::make(type_of<halide_buffer_t *>(), name + ".buffer", buffer);
r.first->second.dimensions = buffer.dimensions();
}
}
}

void visit(const Variable *op) override {
visit_param(op->name, op->param);
visit_buffer(op->name, op->image);
symbols.insert(op->name);
if (symbols.insert(op->name).second) {
visit_param(op->name, op->param);
visit_buffer(op->name, op->image);
}
}

void visit(const Load *op) override {
visit_param(op->name, op->param);
visit_buffer(op->name, op->image);
symbols.insert(op->name);
if (symbols.insert(op->name).second) {
visit_param(op->name, op->param);
visit_buffer(op->name, op->image);
}
IRVisitor::visit(op);
}

void visit(const Store *op) override {
visit_param(op->name, op->param);
symbols.insert(op->name);
if (symbols.insert(op->name).second) {
visit_param(op->name, op->param);
}
IRVisitor::visit(op);
}

Expand Down
Loading