| Index: src/compiler/generic-node-inl.h
|
| diff --git a/src/compiler/node.cc b/src/compiler/generic-node-inl.h
|
| similarity index 56%
|
| copy from src/compiler/node.cc
|
| copy to src/compiler/generic-node-inl.h
|
| index 9615632724a47c6e03d5014423027af390e777dd..afbd1f0ebf2067eb35cb370c16a7b7f5eefe2aa5 100644
|
| --- a/src/compiler/node.cc
|
| +++ b/src/compiler/generic-node-inl.h
|
| @@ -2,23 +2,24 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#ifndef V8_COMPILER_GENERIC_NODE_INL_H_
|
| +#define V8_COMPILER_GENERIC_NODE_INL_H_
|
| +
|
| #include "src/v8.h"
|
|
|
| -#include "src/compiler/node.h"
|
| +#include "src/compiler/generic-graph.h"
|
| +#include "src/compiler/generic-node.h"
|
| +#include "src/zone.h"
|
|
|
| namespace v8 {
|
| namespace internal {
|
| namespace compiler {
|
|
|
| -void Node::Kill() {
|
| - DCHECK_NOT_NULL(op());
|
| - RemoveAllInputs();
|
| - DCHECK(uses().empty());
|
| -}
|
| -
|
| -
|
| -Node::Node(GenericGraphBase* graph, int input_count, int reserve_input_count)
|
| - : input_count_(input_count),
|
| +template <class B, class S>
|
| +GenericNode<B, S>::GenericNode(GenericGraphBase* graph, int input_count,
|
| + int reserve_input_count)
|
| + : BaseClass(graph->zone()),
|
| + input_count_(input_count),
|
| reserve_input_count_(reserve_input_count),
|
| has_appendable_inputs_(false),
|
| use_count_(0),
|
| @@ -29,56 +30,38 @@ Node::Node(GenericGraphBase* graph, int input_count, int reserve_input_count)
|
| AssignUniqueID(graph);
|
| }
|
|
|
| -
|
| -void Node::CollectProjections(NodeVector* projections) {
|
| - for (size_t i = 0; i < projections->size(); i++) {
|
| - (*projections)[i] = NULL;
|
| - }
|
| - for (UseIter i = uses().begin(); i != uses().end(); ++i) {
|
| - if ((*i)->opcode() != IrOpcode::kProjection) continue;
|
| - size_t index = OpParameter<size_t>(*i);
|
| - DCHECK_LT(index, projections->size());
|
| - DCHECK_EQ(NULL, (*projections)[index]);
|
| - (*projections)[index] = *i;
|
| - }
|
| -}
|
| -
|
| -
|
| -Node* Node::FindProjection(size_t projection_index) {
|
| - for (UseIter i = uses().begin(); i != uses().end(); ++i) {
|
| - if ((*i)->opcode() == IrOpcode::kProjection &&
|
| - OpParameter<size_t>(*i) == projection_index) {
|
| - return *i;
|
| - }
|
| - }
|
| - return NULL;
|
| -}
|
| -
|
| -
|
| -void Node::AssignUniqueID(GenericGraphBase* graph) {
|
| +template <class B, class S>
|
| +inline void GenericNode<B, S>::AssignUniqueID(GenericGraphBase* graph) {
|
| id_ = graph->NextNodeID();
|
| }
|
|
|
| -
|
| -Node::Inputs::iterator Node::Inputs::begin() {
|
| - return Node::Inputs::iterator(this->node_, 0);
|
| +template <class B, class S>
|
| +inline typename GenericNode<B, S>::Inputs::iterator
|
| +GenericNode<B, S>::Inputs::begin() {
|
| + return typename GenericNode<B, S>::Inputs::iterator(this->node_, 0);
|
| }
|
|
|
| -
|
| -Node::Inputs::iterator Node::Inputs::end() {
|
| - return Node::Inputs::iterator(this->node_, this->node_->InputCount());
|
| +template <class B, class S>
|
| +inline typename GenericNode<B, S>::Inputs::iterator
|
| +GenericNode<B, S>::Inputs::end() {
|
| + return typename GenericNode<B, S>::Inputs::iterator(
|
| + this->node_, this->node_->InputCount());
|
| }
|
|
|
| -
|
| -Node::Uses::iterator Node::Uses::begin() {
|
| - return Node::Uses::iterator(this->node_);
|
| +template <class B, class S>
|
| +inline typename GenericNode<B, S>::Uses::iterator
|
| +GenericNode<B, S>::Uses::begin() {
|
| + return typename GenericNode<B, S>::Uses::iterator(this->node_);
|
| }
|
|
|
| +template <class B, class S>
|
| +inline typename GenericNode<B, S>::Uses::iterator
|
| +GenericNode<B, S>::Uses::end() {
|
| + return typename GenericNode<B, S>::Uses::iterator();
|
| +}
|
|
|
| -Node::Uses::iterator Node::Uses::end() { return Node::Uses::iterator(); }
|
| -
|
| -
|
| -void Node::ReplaceUses(Node* replace_to) {
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::ReplaceUses(GenericNode* replace_to) {
|
| for (Use* use = first_use_; use != NULL; use = use->next) {
|
| use->from->GetInputRecordPtr(use->input_index)->to = replace_to;
|
| }
|
| @@ -98,37 +81,52 @@ void Node::ReplaceUses(Node* replace_to) {
|
| last_use_ = NULL;
|
| }
|
|
|
| +template <class B, class S>
|
| +template <class UnaryPredicate>
|
| +void GenericNode<B, S>::ReplaceUsesIf(UnaryPredicate pred,
|
| + GenericNode* replace_to) {
|
| + for (Use* use = first_use_; use != NULL;) {
|
| + Use* next = use->next;
|
| + if (pred(static_cast<S*>(use->from))) {
|
| + RemoveUse(use);
|
| + replace_to->AppendUse(use);
|
| + use->from->GetInputRecordPtr(use->input_index)->to = replace_to;
|
| + }
|
| + use = next;
|
| + }
|
| +}
|
|
|
| -void Node::RemoveAllInputs() {
|
| - for (Inputs::iterator iter(inputs().begin()); iter != inputs().end();
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::RemoveAllInputs() {
|
| + for (typename Inputs::iterator iter(inputs().begin()); iter != inputs().end();
|
| ++iter) {
|
| iter.GetInput()->Update(NULL);
|
| }
|
| }
|
|
|
| -
|
| -void Node::TrimInputCount(int new_input_count) {
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::TrimInputCount(int new_input_count) {
|
| if (new_input_count == input_count_) return; // Nothing to do.
|
|
|
| DCHECK(new_input_count < input_count_);
|
|
|
| // Update inline inputs.
|
| for (int i = new_input_count; i < input_count_; i++) {
|
| - Node::Input* input = GetInputRecordPtr(i);
|
| + typename GenericNode<B, S>::Input* input = GetInputRecordPtr(i);
|
| input->Update(NULL);
|
| }
|
| input_count_ = new_input_count;
|
| }
|
|
|
| -
|
| -void Node::ReplaceInput(int index, Node* new_to) {
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::ReplaceInput(int index, GenericNode<B, S>* new_to) {
|
| Input* input = GetInputRecordPtr(index);
|
| input->Update(new_to);
|
| }
|
|
|
| -
|
| -void Node::Input::Update(Node* new_to) {
|
| - Node* old_to = this->to;
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::Input::Update(GenericNode<B, S>* new_to) {
|
| + GenericNode* old_to = this->to;
|
| if (new_to == old_to) return; // Nothing to do.
|
| // Snip out the use from where it used to be
|
| if (old_to != NULL) {
|
| @@ -144,8 +142,8 @@ void Node::Input::Update(Node* new_to) {
|
| }
|
| }
|
|
|
| -
|
| -void Node::EnsureAppendableInputs(Zone* zone) {
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::EnsureAppendableInputs(Zone* zone) {
|
| if (!has_appendable_inputs_) {
|
| void* deque_buffer = zone->New(sizeof(InputDeque));
|
| InputDeque* deque = new (deque_buffer) InputDeque(zone);
|
| @@ -157,8 +155,8 @@ void Node::EnsureAppendableInputs(Zone* zone) {
|
| }
|
| }
|
|
|
| -
|
| -void Node::AppendInput(Zone* zone, Node* to_append) {
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::AppendInput(Zone* zone, GenericNode<B, S>* to_append) {
|
| Use* new_use = new (zone) Use;
|
| Input new_input;
|
| new_input.to = to_append;
|
| @@ -177,8 +175,9 @@ void Node::AppendInput(Zone* zone, Node* to_append) {
|
| input_count_++;
|
| }
|
|
|
| -
|
| -void Node::InsertInput(Zone* zone, int index, Node* to_insert) {
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::InsertInput(Zone* zone, int index,
|
| + GenericNode<B, S>* to_insert) {
|
| DCHECK(index >= 0 && index < InputCount());
|
| // TODO(turbofan): Optimize this implementation!
|
| AppendInput(zone, InputAt(InputCount() - 1));
|
| @@ -188,8 +187,8 @@ void Node::InsertInput(Zone* zone, int index, Node* to_insert) {
|
| ReplaceInput(index, to_insert);
|
| }
|
|
|
| -
|
| -void Node::RemoveInput(int index) {
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::RemoveInput(int index) {
|
| DCHECK(index >= 0 && index < InputCount());
|
| // TODO(turbofan): Optimize this implementation!
|
| for (; index < InputCount() - 1; ++index) {
|
| @@ -198,8 +197,8 @@ void Node::RemoveInput(int index) {
|
| TrimInputCount(InputCount() - 1);
|
| }
|
|
|
| -
|
| -void Node::AppendUse(Use* use) {
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::AppendUse(Use* use) {
|
| use->next = NULL;
|
| use->prev = last_use_;
|
| if (last_use_ == NULL) {
|
| @@ -211,8 +210,8 @@ void Node::AppendUse(Use* use) {
|
| ++use_count_;
|
| }
|
|
|
| -
|
| -void Node::RemoveUse(Use* use) {
|
| +template <class B, class S>
|
| +void GenericNode<B, S>::RemoveUse(Use* use) {
|
| if (last_use_ == use) {
|
| last_use_ = use->prev;
|
| }
|
| @@ -227,30 +226,30 @@ void Node::RemoveUse(Use* use) {
|
| --use_count_;
|
| }
|
|
|
| -
|
| -bool Node::OwnedBy(Node* owner) const {
|
| +template <class B, class S>
|
| +inline bool GenericNode<B, S>::OwnedBy(GenericNode* owner) const {
|
| return first_use_ != NULL && first_use_->from == owner &&
|
| first_use_->next == NULL;
|
| }
|
|
|
| -
|
| -Node* Node::New(GenericGraphBase* graph, int input_count, Node** inputs,
|
| - bool has_extensible_inputs) {
|
| - size_t node_size = sizeof(Node);
|
| +template <class B, class S>
|
| +S* GenericNode<B, S>::New(GenericGraphBase* graph, int input_count, S** inputs,
|
| + bool has_extensible_inputs) {
|
| + size_t node_size = sizeof(GenericNode);
|
| int reserve_input_count = has_extensible_inputs ? kDefaultReservedInputs : 0;
|
| size_t inputs_size = (input_count + reserve_input_count) * sizeof(Input);
|
| size_t uses_size = input_count * sizeof(Use);
|
| int size = static_cast<int>(node_size + inputs_size + uses_size);
|
| Zone* zone = graph->zone();
|
| void* buffer = zone->New(size);
|
| - Node* result = new (buffer) Node(graph, input_count, reserve_input_count);
|
| + S* result = new (buffer) S(graph, input_count, reserve_input_count);
|
| Input* input =
|
| reinterpret_cast<Input*>(reinterpret_cast<char*>(buffer) + node_size);
|
| Use* use =
|
| reinterpret_cast<Use*>(reinterpret_cast<char*>(input) + inputs_size);
|
|
|
| for (int current = 0; current < input_count; ++current) {
|
| - Node* to = *inputs++;
|
| + GenericNode* to = *inputs++;
|
| input->to = to;
|
| input->use = use;
|
| use->input_index = current;
|
| @@ -261,24 +260,8 @@ Node* Node::New(GenericGraphBase* graph, int input_count, Node** inputs,
|
| }
|
| return result;
|
| }
|
| -
|
| -
|
| -bool Node::Uses::empty() { return begin() == end(); }
|
| -
|
| -
|
| -std::ostream& operator<<(std::ostream& os, const Node& n) {
|
| - os << n.id() << ": " << *n.op();
|
| - if (n.op()->InputCount() != 0) {
|
| - os << "(";
|
| - for (int i = 0; i < n.op()->InputCount(); ++i) {
|
| - if (i != 0) os << ", ";
|
| - os << n.InputAt(i)->id();
|
| - }
|
| - os << ")";
|
| - }
|
| - return os;
|
| }
|
| +}
|
| +} // namespace v8::internal::compiler
|
|
|
| -} // namespace compiler
|
| -} // namespace internal
|
| -} // namespace v8
|
| +#endif // V8_COMPILER_GENERIC_NODE_INL_H_
|
|
|