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/graph.h" | 5 #include "src/compiler/graph.h" |
6 | 6 |
7 #include "src/compiler/common-operator.h" | 7 #include <algorithm> |
8 #include "src/compiler/graph-inl.h" | 8 |
| 9 #include "src/base/bits.h" |
9 #include "src/compiler/node.h" | 10 #include "src/compiler/node.h" |
10 #include "src/compiler/node-aux-data-inl.h" | |
11 #include "src/compiler/node-properties.h" | |
12 #include "src/compiler/node-properties-inl.h" | |
13 #include "src/compiler/opcodes.h" | |
14 #include "src/compiler/operator-properties.h" | |
15 | 11 |
16 namespace v8 { | 12 namespace v8 { |
17 namespace internal { | 13 namespace internal { |
18 namespace compiler { | 14 namespace compiler { |
19 | 15 |
20 Graph::Graph(Zone* zone) | 16 Graph::Graph(Zone* zone) |
21 : zone_(zone), | 17 : zone_(zone), |
22 start_(NULL), | 18 start_(nullptr), |
23 end_(NULL), | 19 end_(nullptr), |
24 mark_max_(0), | 20 mark_max_(0), |
25 next_node_id_(0), | 21 next_node_id_(0), |
26 decorators_(zone) {} | 22 decorators_(zone) {} |
27 | 23 |
28 | 24 |
29 void Graph::Decorate(Node* node) { | 25 void Graph::Decorate(Node* node) { |
30 for (ZoneVector<GraphDecorator*>::iterator i = decorators_.begin(); | 26 for (auto const decorator : decorators_) decorator->Decorate(node); |
31 i != decorators_.end(); ++i) { | 27 } |
32 (*i)->Decorate(node); | 28 |
33 } | 29 |
| 30 void Graph::AddDecorator(GraphDecorator* decorator) { |
| 31 decorators_.push_back(decorator); |
| 32 } |
| 33 |
| 34 |
| 35 void Graph::RemoveDecorator(GraphDecorator* decorator) { |
| 36 auto const it = std::find(decorators_.begin(), decorators_.end(), decorator); |
| 37 DCHECK(it != decorators_.end()); |
| 38 decorators_.erase(it); |
34 } | 39 } |
35 | 40 |
36 | 41 |
37 Node* Graph::NewNode(const Operator* op, int input_count, Node** inputs, | 42 Node* Graph::NewNode(const Operator* op, int input_count, Node** inputs, |
38 bool incomplete) { | 43 bool incomplete) { |
39 DCHECK_LE(op->ValueInputCount(), input_count); | 44 DCHECK_LE(op->ValueInputCount(), input_count); |
40 Node* result = Node::New(this, input_count, inputs, incomplete); | 45 Node* const node = |
41 result->Initialize(op); | 46 Node::New(zone(), NextNodeId(), op, input_count, inputs, incomplete); |
42 if (!incomplete) { | 47 if (!incomplete) Decorate(node); |
43 Decorate(result); | 48 return node; |
44 } | 49 } |
45 return result; | 50 |
| 51 |
| 52 NodeId Graph::NextNodeId() { |
| 53 NodeId const id = next_node_id_; |
| 54 CHECK(!base::bits::SignedAddOverflow32(id, 1, &next_node_id_)); |
| 55 return id; |
46 } | 56 } |
47 | 57 |
48 } // namespace compiler | 58 } // namespace compiler |
49 } // namespace internal | 59 } // namespace internal |
50 } // namespace v8 | 60 } // namespace v8 |
OLD | NEW |