| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/node.h" | 5 #include "src/compiler/node.h" |
| 6 |
| 6 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
| 7 #include "src/zone.h" | 8 #include "src/zone.h" |
| 8 | 9 |
| 9 namespace v8 { | 10 namespace v8 { |
| 10 namespace internal { | 11 namespace internal { |
| 11 namespace compiler { | 12 namespace compiler { |
| 12 | 13 |
| 13 Node::Node(Graph* graph, int input_count, int reserve_input_count) | 14 Node::Node(NodeId id, int input_count, int reserved_input_count) |
| 14 : input_count_(input_count), | 15 : id_(id), |
| 15 reserve_input_count_(reserve_input_count), | 16 bit_field_(InputCountField::encode(input_count) | |
| 16 has_appendable_inputs_(false), | 17 ReservedInputCountField::encode(reserved_input_count) | |
| 17 use_count_(0), | 18 HasAppendableInputsField::encode(false)), |
| 18 first_use_(NULL), | 19 first_use_(nullptr), |
| 19 last_use_(NULL) { | 20 last_use_(nullptr) { |
| 20 DCHECK(reserve_input_count <= kMaxReservedInputs); | |
| 21 inputs_.static_ = reinterpret_cast<Input*>(this + 1); | 21 inputs_.static_ = reinterpret_cast<Input*>(this + 1); |
| 22 id_ = graph->NextNodeID(); | |
| 23 } | 22 } |
| 24 | 23 |
| 25 | 24 |
| 26 Node* Node::New(Graph* graph, int input_count, Node** inputs, | 25 Node* Node::New(Graph* graph, int input_count, Node** inputs, |
| 27 bool has_extensible_inputs) { | 26 bool has_extensible_inputs) { |
| 28 size_t node_size = sizeof(Node); | 27 size_t node_size = sizeof(Node); |
| 29 int reserve_input_count = has_extensible_inputs ? kDefaultReservedInputs : 0; | 28 int reserve_input_count = has_extensible_inputs ? kDefaultReservedInputs : 0; |
| 30 size_t inputs_size = (input_count + reserve_input_count) * sizeof(Input); | 29 size_t inputs_size = (input_count + reserve_input_count) * sizeof(Input); |
| 31 size_t uses_size = input_count * sizeof(Use); | 30 size_t uses_size = input_count * sizeof(Use); |
| 32 int size = static_cast<int>(node_size + inputs_size + uses_size); | 31 int size = static_cast<int>(node_size + inputs_size + uses_size); |
| 33 Zone* zone = graph->zone(); | 32 Zone* zone = graph->zone(); |
| 34 void* buffer = zone->New(size); | 33 void* buffer = zone->New(size); |
| 35 Node* result = new (buffer) Node(graph, input_count, reserve_input_count); | 34 Node* result = |
| 35 new (buffer) Node(graph->NextNodeID(), input_count, reserve_input_count); |
| 36 Input* input = | 36 Input* input = |
| 37 reinterpret_cast<Input*>(reinterpret_cast<char*>(buffer) + node_size); | 37 reinterpret_cast<Input*>(reinterpret_cast<char*>(buffer) + node_size); |
| 38 Use* use = | 38 Use* use = |
| 39 reinterpret_cast<Use*>(reinterpret_cast<char*>(input) + inputs_size); | 39 reinterpret_cast<Use*>(reinterpret_cast<char*>(input) + inputs_size); |
| 40 | 40 |
| 41 for (int current = 0; current < input_count; ++current) { | 41 for (int current = 0; current < input_count; ++current) { |
| 42 Node* to = *inputs++; | 42 Node* to = *inputs++; |
| 43 input->to = to; | 43 input->to = to; |
| 44 input->use = use; | 44 input->use = use; |
| 45 use->input_index = current; | 45 use->input_index = current; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 for (UseIter i = uses().begin(); i != uses().end(); ++i) { | 77 for (UseIter i = uses().begin(); i != uses().end(); ++i) { |
| 78 if ((*i)->opcode() == IrOpcode::kProjection && | 78 if ((*i)->opcode() == IrOpcode::kProjection && |
| 79 OpParameter<size_t>(*i) == projection_index) { | 79 OpParameter<size_t>(*i) == projection_index) { |
| 80 return *i; | 80 return *i; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 return NULL; | 83 return NULL; |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 int Node::UseCount() const { |
| 88 int use_count = 0; |
| 89 for (const Use* use = first_use_; use; use = use->next) { |
| 90 ++use_count; |
| 91 } |
| 92 return use_count; |
| 93 } |
| 94 |
| 95 |
| 96 Node* Node::UseAt(int index) const { |
| 97 DCHECK_LE(0, index); |
| 98 DCHECK_LT(index, UseCount()); |
| 99 Use* current = first_use_; |
| 100 while (index-- != 0) { |
| 101 current = current->next; |
| 102 } |
| 103 return current->from; |
| 104 } |
| 105 |
| 106 |
| 87 std::ostream& operator<<(std::ostream& os, const Node& n) { | 107 std::ostream& operator<<(std::ostream& os, const Node& n) { |
| 88 os << n.id() << ": " << *n.op(); | 108 os << n.id() << ": " << *n.op(); |
| 89 if (n.InputCount() > 0) { | 109 if (n.InputCount() > 0) { |
| 90 os << "("; | 110 os << "("; |
| 91 for (int i = 0; i < n.InputCount(); ++i) { | 111 for (int i = 0; i < n.InputCount(); ++i) { |
| 92 if (i != 0) os << ", "; | 112 if (i != 0) os << ", "; |
| 93 os << n.InputAt(i)->id(); | 113 os << n.InputAt(i)->id(); |
| 94 } | 114 } |
| 95 os << ")"; | 115 os << ")"; |
| 96 } | 116 } |
| 97 return os; | 117 return os; |
| 98 } | 118 } |
| 99 | 119 |
| 100 } // namespace compiler | 120 } // namespace compiler |
| 101 } // namespace internal | 121 } // namespace internal |
| 102 } // namespace v8 | 122 } // namespace v8 |
| OLD | NEW |