-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[ir] Add a function to test if two IRNodes are equivalent #683
Conversation
Shall we move Line 577 in e8e42f3
to IRNode in order to test if IRNode *other is of the same type with the current IRNode * ? (for example, to test if other is Block * in void visit(Block *stmt_list) )
|
Good idea! |
I was writing the IRNode comparator while referring to the IR printer to see which fields each kind of Stmts has. I noticed that many I wonder if, in the stage of calling our IRNode comparator, there would be no |
Yes, you can assume you are working on a lowered AST. |
…sit(SNodeOpStmt *)
Is |
Yes, we should assume this process happens only after |
taichi/analysis/same_statements.cpp
Outdated
std::map<int, int> id_map; // map the id from this node to the other node | ||
std::set<int> captured_id; // ids which don't belong to either node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to use the std::unordered_
versions for efficienty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage of map? If unordered_map always superior, then why they don't replace it then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::map
uses less memory, provides functions about the order (lower_bound
for example), and guarantees worst-case O(log(n)) time (std::unordered_map
has a worst-case complexity of O(n)). I agree that we should use std::unordered_map
in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that the indices inserted to id_map
must be in ascending order. Maybe std::vector
is more efficient if the range is not too big (and after re_id
, it is not). However, I would still prefer to use std::unordered_map
for maintainable code.
Why are there |
Well... In some cases, a |
Or you can define a function that takes in SNode * and returns the unique_ids and -1 on null pointers. |
Let's take the second approach, considering we may allow deleting/adding new SNodes dynamically and reuse pointer addresses in the future. LLVM uses pointer comparison on its types because it assumes once created the types won't get recycled. |
It can't be applied directly with this macro though... #define DEFINE_FIELD_CHECK(field) \
if (stmt->field != other->field) { \
same = false; \
return; \
} Shall I write another macro like this? #define DEFINE_SNODE_CHECK(snode) \
if (get_snode_id(stmt->snode) != get_snode_id(other->snode)) { \
same = false; \
return; \
} |
…sit(SNodeOpStmt *)
Why is Travis CI failing? |
I see. Probably because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
One final thing before merging this: could you add a pass after |
I realized |
|
Should |
Maybe I should redefine |
LGTM now. Thank you so much, Mingkuan! |
Related issue = #656 (comment)
[Click here for the format server]