Commit 7763a926 authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[node] OwnedBy fix for only one owner check

In the case of having:
 * NodeA(...)
 * NodeB(NodeA, NodeA), with this being the only use of NodeA.
this CL gives A's ownership to B.

Before, we used to say that B didn't have ownership of A due to A having
two uses.

This brings it in line with OwnedBy with two owners check:
https://source.chromium.org/chromium/_/chromium/v8/v8.git/+/abd1a0fc04476bbb27ef2dfda2e444cc1467f5f6:src/compiler/node.cc;l=291

Change-Id: I15fdf373136a21bf423e6dffd9588054fd720d72
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2007502Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65867}
parent 92df7d10
......@@ -287,6 +287,17 @@ void Node::ReplaceUses(Node* that) {
first_use_ = nullptr;
}
bool Node::OwnedBy(Node const* owner) const {
unsigned mask = 0;
for (Use* use = first_use_; use; use = use->next) {
if (use->from() == owner) {
mask |= 1;
} else {
return false;
}
}
return mask == 1;
}
bool Node::OwnedBy(Node const* owner1, Node const* owner2) const {
unsigned mask = 0;
......
......@@ -139,9 +139,7 @@ class V8_EXPORT_PRIVATE Node final {
Uses uses() { return Uses(this); }
// Returns true if {owner} is the only user of {this} node.
bool OwnedBy(Node* owner) const {
return first_use_ && first_use_->from() == owner && !first_use_->next;
}
bool OwnedBy(Node const* owner) const;
// Returns true if {owner1} and {owner2} are the only users of {this} node.
bool OwnedBy(Node const* owner1, Node const* owner2) const;
......
......@@ -42,8 +42,22 @@ void CheckUseChain(Node* node, Node** uses, int use_count) {
// Check ownership.
if (use_count == 1) CHECK(node->OwnedBy(uses[0]));
if (use_count > 1) {
Node* first_use = uses[0];
bool different_uses = false;
for (int i = 0; i < use_count; i++) {
CHECK(!node->OwnedBy(uses[i]));
if (uses[i] != first_use) {
different_uses = true;
break;
}
}
if (different_uses) {
// If there are different uses, check that node is not owned by any use.
for (int i = 0; i < use_count; i++) {
CHECK(!node->OwnedBy(uses[i]));
}
} else {
// If all uses are the same, check that node is owned by that use.
CHECK(node->OwnedBy(first_use));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment