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

Implement optree transformation: Join identical conditional branches #176

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MaksimShagov
Copy link
Collaborator

No description provided.

auto ifOp = op->as<IfOp>();
if (auto elseOp = ifOp.elseOp()) {
auto thenOp = ifOp.thenOp();
if (elseOp->body.size() == thenOp->body.size()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вроде бы можно просто функцию сверху заколить через ренж

@vla5924 vla5924 linked an issue May 23, 2024 that may be closed by this pull request
static inline bool compareOperations(const Operation::Ptr &lhs, const Operation::Ptr &rhs) {
auto attrEqual = [](const Attribute &lhs, const Attribute &rhs) { return lhs.storage == rhs.storage; };
bool attr = std::ranges::equal(lhs->attributes, rhs->attributes, attrEqual);
auto valueEqual = [](const Value::Ptr &lhs, const Value::Ptr &rhs) { return lhs->type == rhs->type; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это неправильное сравнение. Например, два таких body по твоей логике будут одинаковые, хотя value 0 и 1 используются по разному:

Op1 (...) -> (#0: float)
Op2 (...) -> (#1: float)
Op3 (#0, #1) -> (...)
---
Op1 (...) -> (#0: float)
Op2 (...) -> (#1: float)
Op3 (#1, #0) -> (...)

И более простой случай (если 0 и 1 созданы где-то снаружи):

Op1 (#0: float, #1: float) -> (...)
---
Op1 (#1: float, #0: float) -> (...)

А еще у операций есть specId и name, которые тоже должны совпадать. Надо бы вынести все это в отдельную функцию в helpers, по идее #179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement optree transformation: Join identical conditional branches
2 participants