Commit cd339784 authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Remove last_use_ field from Node.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1022783002

Cr-Commit-Position: refs/heads/master@{#27319}
parent 84363499
......@@ -118,33 +118,23 @@ int Node::UseCount() const {
}
Node* Node::UseAt(int index) const {
DCHECK_LE(0, index);
DCHECK_LT(index, UseCount());
const Use* use = first_use_;
while (index-- != 0) {
use = use->next;
}
return use->from;
}
void Node::ReplaceUses(Node* replace_to) {
for (Use* use = first_use_; use; use = use->next) {
use->from->GetInputRecordPtr(use->input_index)->to = replace_to;
void Node::ReplaceUses(Node* that) {
DCHECK(this->first_use_ == nullptr || this->first_use_->prev == nullptr);
DCHECK(that->first_use_ == nullptr || that->first_use_->prev == nullptr);
// Update the pointers to {this} to point to {that}.
Use* last_use = nullptr;
for (Use* use = this->first_use_; use; use = use->next) {
use->from->GetInputRecordPtr(use->input_index)->to = that;
last_use = use;
}
if (!replace_to->last_use_) {
DCHECK(!replace_to->first_use_);
replace_to->first_use_ = first_use_;
replace_to->last_use_ = last_use_;
} else if (first_use_) {
DCHECK_NOT_NULL(replace_to->first_use_);
replace_to->last_use_->next = first_use_;
first_use_->prev = replace_to->last_use_;
replace_to->last_use_ = last_use_;
if (last_use) {
// Concat the use list of {this} and {that}.
last_use->next = that->first_use_;
if (that->first_use_) that->first_use_->prev = last_use;
that->first_use_ = this->first_use_;
}
first_use_ = nullptr;
last_use_ = nullptr;
}
......@@ -174,8 +164,7 @@ Node::Node(NodeId id, const Operator* op, int input_count,
bit_field_(InputCountField::encode(input_count) |
ReservedInputCountField::encode(reserved_input_count) |
HasAppendableInputsField::encode(false)),
first_use_(nullptr),
last_use_(nullptr) {}
first_use_(nullptr) {}
void Node::EnsureAppendableInputs(Zone* zone) {
......@@ -192,24 +181,21 @@ void Node::EnsureAppendableInputs(Zone* zone) {
void Node::AppendUse(Use* const use) {
use->next = nullptr;
use->prev = last_use_;
if (last_use_) {
last_use_->next = use;
} else {
first_use_ = use;
}
last_use_ = use;
DCHECK(first_use_ == nullptr || first_use_->prev == nullptr);
use->next = first_use_;
use->prev = nullptr;
if (first_use_) first_use_->prev = use;
first_use_ = use;
}
void Node::RemoveUse(Use* const use) {
if (use == last_use_) {
last_use_ = use->prev;
}
DCHECK(first_use_ == nullptr || first_use_->prev == nullptr);
if (use->prev) {
DCHECK_NE(first_use_, use);
use->prev->next = use->next;
} else {
DCHECK_EQ(first_use_, use);
first_use_ = use->next;
}
if (use->next) {
......
......@@ -67,7 +67,6 @@ class Node FINAL {
void TrimInputCount(int new_input_count);
int UseCount() const;
Node* UseAt(int index) const;
void ReplaceUses(Node* replace_to);
class InputEdges FINAL {
......@@ -226,7 +225,6 @@ class Node FINAL {
NodeId const id_;
unsigned bit_field_;
Use* first_use_;
Use* last_use_;
union {
// When a node is initially allocated, it uses a static buffer to hold its
// inputs under the assumption that the number of outputs will not increase.
......
This diff is collapsed.
......@@ -10,6 +10,7 @@
using testing::AnyOf;
using testing::ElementsAre;
using testing::IsNull;
using testing::UnorderedElementsAre;
namespace v8 {
namespace internal {
......@@ -56,7 +57,7 @@ TEST_F(NodePropertiesTest, ReplaceWithValue_EffectUse) {
EXPECT_EQ(0, node->UseCount());
EXPECT_EQ(2, start->UseCount());
EXPECT_EQ(0, replacement->UseCount());
EXPECT_THAT(start->uses(), ElementsAre(node, use_effect));
EXPECT_THAT(start->uses(), UnorderedElementsAre(use_effect, node));
}
......@@ -72,7 +73,7 @@ TEST_F(NodePropertiesTest, ReplaceWithValue_ControlUse) {
EXPECT_EQ(0, node->UseCount());
EXPECT_EQ(2, start->UseCount());
EXPECT_EQ(0, replacement->UseCount());
EXPECT_THAT(start->uses(), ElementsAre(node, use_control));
EXPECT_THAT(start->uses(), UnorderedElementsAre(use_control, node));
}
......
......@@ -543,11 +543,23 @@ class IsEffectSetMatcher FINAL : public NodeMatcher {
}
bool MatchAndExplain(Node* node, MatchResultListener* listener) const FINAL {
return (NodeMatcher::MatchAndExplain(node, listener) &&
PrintMatchAndExplain(NodeProperties::GetEffectInput(node, 0),
"effect0", effect0_matcher_, listener) &&
PrintMatchAndExplain(NodeProperties::GetEffectInput(node, 1),
"effect1", effect1_matcher_, listener));
if (!NodeMatcher::MatchAndExplain(node, listener)) return false;
Node* effect0 = NodeProperties::GetEffectInput(node, 0);
Node* effect1 = NodeProperties::GetEffectInput(node, 1);
{
// Try matching in the reverse order first.
StringMatchResultListener value_listener;
if (effect0_matcher_.MatchAndExplain(effect1, &value_listener) &&
effect1_matcher_.MatchAndExplain(effect0, &value_listener)) {
return true;
}
}
return PrintMatchAndExplain(effect0, "effect0", effect0_matcher_,
listener) &&
PrintMatchAndExplain(effect1, "effect1", effect1_matcher_, listener);
}
private:
......
......@@ -48,15 +48,15 @@ TEST_F(NodeTest, NewWithInputs) {
EXPECT_EQ(0, n0->InputCount());
Node* n1 = Node::New(zone(), 1, &kOp1, 1, &n0, false);
EXPECT_EQ(1, n0->UseCount());
EXPECT_EQ(n1, n0->UseAt(0));
EXPECT_THAT(n0->uses(), UnorderedElementsAre(n1));
EXPECT_EQ(0, n1->UseCount());
EXPECT_EQ(1, n1->InputCount());
EXPECT_EQ(n0, n1->InputAt(0));
Node* n0_n1[] = {n0, n1};
Node* n2 = Node::New(zone(), 2, &kOp2, 2, n0_n1, false);
EXPECT_EQ(2, n0->UseCount());
EXPECT_EQ(n1, n0->UseAt(0));
EXPECT_EQ(n2, n0->UseAt(1));
EXPECT_THAT(n0->uses(), UnorderedElementsAre(n1, n2));
EXPECT_THAT(n1->uses(), UnorderedElementsAre(n2));
EXPECT_EQ(2, n2->InputCount());
EXPECT_EQ(n0, n2->InputAt(0));
EXPECT_EQ(n1, n2->InputAt(1));
......
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