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/generic-node-inl.h" | 7 #include "src/zone.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
11 namespace compiler { | 11 namespace compiler { |
12 | 12 |
| 13 Node::Node(Graph* graph, int input_count, int reserve_input_count) |
| 14 : NodeData(graph->zone()), |
| 15 input_count_(input_count), |
| 16 reserve_input_count_(reserve_input_count), |
| 17 has_appendable_inputs_(false), |
| 18 use_count_(0), |
| 19 first_use_(NULL), |
| 20 last_use_(NULL) { |
| 21 DCHECK(reserve_input_count <= kMaxReservedInputs); |
| 22 inputs_.static_ = reinterpret_cast<Input*>(this + 1); |
| 23 id_ = graph->NextNodeID(); |
| 24 } |
| 25 |
| 26 |
| 27 Node* Node::New(Graph* graph, int input_count, Node** inputs, |
| 28 bool has_extensible_inputs) { |
| 29 size_t node_size = sizeof(Node); |
| 30 int reserve_input_count = has_extensible_inputs ? kDefaultReservedInputs : 0; |
| 31 size_t inputs_size = (input_count + reserve_input_count) * sizeof(Input); |
| 32 size_t uses_size = input_count * sizeof(Use); |
| 33 int size = static_cast<int>(node_size + inputs_size + uses_size); |
| 34 Zone* zone = graph->zone(); |
| 35 void* buffer = zone->New(size); |
| 36 Node* result = new (buffer) Node(graph, input_count, reserve_input_count); |
| 37 Input* input = |
| 38 reinterpret_cast<Input*>(reinterpret_cast<char*>(buffer) + node_size); |
| 39 Use* use = |
| 40 reinterpret_cast<Use*>(reinterpret_cast<char*>(input) + inputs_size); |
| 41 |
| 42 for (int current = 0; current < input_count; ++current) { |
| 43 Node* to = *inputs++; |
| 44 input->to = to; |
| 45 input->use = use; |
| 46 use->input_index = current; |
| 47 use->from = result; |
| 48 to->AppendUse(use); |
| 49 ++use; |
| 50 ++input; |
| 51 } |
| 52 return result; |
| 53 } |
| 54 |
| 55 |
13 void Node::Kill() { | 56 void Node::Kill() { |
14 DCHECK_NOT_NULL(op()); | 57 DCHECK_NOT_NULL(op()); |
15 RemoveAllInputs(); | 58 RemoveAllInputs(); |
16 DCHECK(uses().empty()); | 59 DCHECK(uses().empty()); |
17 } | 60 } |
18 | 61 |
19 | 62 |
20 void Node::CollectProjections(NodeVector* projections) { | 63 void Node::CollectProjections(NodeVector* projections) { |
21 for (size_t i = 0; i < projections->size(); i++) { | 64 for (size_t i = 0; i < projections->size(); i++) { |
22 (*projections)[i] = NULL; | 65 (*projections)[i] = NULL; |
(...skipping 28 matching lines...) Expand all Loading... |
51 os << n.InputAt(i)->id(); | 94 os << n.InputAt(i)->id(); |
52 } | 95 } |
53 os << ")"; | 96 os << ")"; |
54 } | 97 } |
55 return os; | 98 return os; |
56 } | 99 } |
57 | 100 |
58 } // namespace compiler | 101 } // namespace compiler |
59 } // namespace internal | 102 } // namespace internal |
60 } // namespace v8 | 103 } // namespace v8 |
OLD | NEW |