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 |
7 #include <algorithm> | 7 #include <algorithm> |
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::New(Zone* zone, NodeId id, const Operator* op, int input_count, | 13 Node* Node::New(Zone* zone, NodeId id, const Operator* op, int input_count, |
14 Node** inputs, bool has_extensible_inputs) { | 14 Node** inputs, bool has_extensible_inputs) { |
15 size_t node_size = sizeof(Node); | 15 size_t node_size = sizeof(Node) - sizeof(Input); |
16 int reserve_input_count = has_extensible_inputs ? kDefaultReservedInputs : 0; | 16 int reserve_input_count = has_extensible_inputs ? kDefaultReservedInputs : 0; |
17 size_t inputs_size = (input_count + reserve_input_count) * sizeof(Input); | 17 size_t inputs_size = std::max<size_t>( |
| 18 (input_count + reserve_input_count) * sizeof(Input), sizeof(InputDeque*)); |
18 size_t uses_size = input_count * sizeof(Use); | 19 size_t uses_size = input_count * sizeof(Use); |
19 int size = static_cast<int>(node_size + inputs_size + uses_size); | 20 int size = static_cast<int>(node_size + inputs_size + uses_size); |
20 void* buffer = zone->New(size); | 21 void* buffer = zone->New(size); |
21 Node* result = new (buffer) Node(id, op, input_count, reserve_input_count); | 22 Node* result = new (buffer) Node(id, op, input_count, reserve_input_count); |
22 Input* input = | 23 Input* input = result->inputs_.static_; |
23 reinterpret_cast<Input*>(reinterpret_cast<char*>(buffer) + node_size); | |
24 Use* use = | 24 Use* use = |
25 reinterpret_cast<Use*>(reinterpret_cast<char*>(input) + inputs_size); | 25 reinterpret_cast<Use*>(reinterpret_cast<char*>(input) + inputs_size); |
26 | 26 |
27 for (int current = 0; current < input_count; ++current) { | 27 for (int current = 0; current < input_count; ++current) { |
28 Node* to = *inputs++; | 28 Node* to = *inputs++; |
29 input->to = to; | 29 input->to = to; |
30 input->use = use; | 30 input->use = use; |
31 use->input_index = current; | 31 use->input_index = current; |
32 use->from = result; | 32 use->from = result; |
33 to->AppendUse(use); | 33 to->AppendUse(use); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 Node::Node(NodeId id, const Operator* op, int input_count, | 169 Node::Node(NodeId id, const Operator* op, int input_count, |
170 int reserved_input_count) | 170 int reserved_input_count) |
171 : op_(op), | 171 : op_(op), |
172 mark_(0), | 172 mark_(0), |
173 id_(id), | 173 id_(id), |
174 bit_field_(InputCountField::encode(input_count) | | 174 bit_field_(InputCountField::encode(input_count) | |
175 ReservedInputCountField::encode(reserved_input_count) | | 175 ReservedInputCountField::encode(reserved_input_count) | |
176 HasAppendableInputsField::encode(false)), | 176 HasAppendableInputsField::encode(false)), |
177 first_use_(nullptr), | 177 first_use_(nullptr), |
178 last_use_(nullptr) { | 178 last_use_(nullptr) {} |
179 inputs_.static_ = reinterpret_cast<Input*>(this + 1); | |
180 } | |
181 | 179 |
182 | 180 |
183 void Node::EnsureAppendableInputs(Zone* zone) { | 181 void Node::EnsureAppendableInputs(Zone* zone) { |
184 if (!has_appendable_inputs()) { | 182 if (!has_appendable_inputs()) { |
185 void* deque_buffer = zone->New(sizeof(InputDeque)); | 183 void* deque_buffer = zone->New(sizeof(InputDeque)); |
186 InputDeque* deque = new (deque_buffer) InputDeque(zone); | 184 InputDeque* deque = new (deque_buffer) InputDeque(zone); |
187 for (int i = 0; i < input_count(); ++i) { | 185 for (int i = 0; i < input_count(); ++i) { |
188 deque->push_back(inputs_.static_[i]); | 186 deque->push_back(inputs_.static_[i]); |
189 } | 187 } |
190 inputs_.appendable_ = deque; | 188 inputs_.appendable_ = deque; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 ++(*this); | 267 ++(*this); |
270 return result; | 268 return result; |
271 } | 269 } |
272 | 270 |
273 | 271 |
274 bool Node::Uses::empty() const { return begin() == end(); } | 272 bool Node::Uses::empty() const { return begin() == end(); } |
275 | 273 |
276 } // namespace compiler | 274 } // namespace compiler |
277 } // namespace internal | 275 } // namespace internal |
278 } // namespace v8 | 276 } // namespace v8 |
OLD | NEW |