| Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | 
|  | 3 | // found in the LICENSE file. | 
|  | 4 |  | 
|  | 5 | #include "src/compiler/graph.h" | 
|  | 6 |  | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7 | #include <algorithm> | 
|  | 8 |  | 
|  | 9 | #include "src/base/bits.h" | 
| Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/compiler/node.h" | 
| Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/compiler/node-properties.h" | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 12 | #include "src/compiler/verifier.h" | 
| Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 13 |  | 
|  | 14 | namespace v8 { | 
|  | 15 | namespace internal { | 
|  | 16 | namespace compiler { | 
|  | 17 |  | 
| Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 18 | Graph::Graph(Zone* zone) | 
|  | 19 | : zone_(zone), | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 20 | start_(nullptr), | 
|  | 21 | end_(nullptr), | 
| Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 22 | mark_max_(0), | 
|  | 23 | next_node_id_(0), | 
|  | 24 | decorators_(zone) {} | 
| Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 25 |  | 
|  | 26 |  | 
| Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 27 | void Graph::Decorate(Node* node) { | 
| Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 28 | for (GraphDecorator* const decorator : decorators_) { | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 29 | decorator->Decorate(node); | 
| Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 30 | } | 
|  | 31 | } | 
|  | 32 |  | 
|  | 33 |  | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 34 | void Graph::AddDecorator(GraphDecorator* decorator) { | 
|  | 35 | decorators_.push_back(decorator); | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 |  | 
|  | 39 | void Graph::RemoveDecorator(GraphDecorator* decorator) { | 
|  | 40 | auto const it = std::find(decorators_.begin(), decorators_.end(), decorator); | 
|  | 41 | DCHECK(it != decorators_.end()); | 
|  | 42 | decorators_.erase(it); | 
|  | 43 | } | 
|  | 44 |  | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 45 | Node* Graph::NewNode(const Operator* op, int input_count, Node* const* inputs, | 
| Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 46 | bool incomplete) { | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 47 | Node* node = NewNodeUnchecked(op, input_count, inputs, incomplete); | 
|  | 48 | Verifier::VerifyNode(node); | 
|  | 49 | return node; | 
|  | 50 | } | 
|  | 51 |  | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 52 | Node* Graph::NewNodeUnchecked(const Operator* op, int input_count, | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 53 | Node* const* inputs, bool incomplete) { | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 54 | Node* const node = | 
|  | 55 | Node::New(zone(), NextNodeId(), op, input_count, inputs, incomplete); | 
|  | 56 | Decorate(node); | 
|  | 57 | return node; | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 |  | 
|  | 61 | Node* Graph::CloneNode(const Node* node) { | 
|  | 62 | DCHECK_NOT_NULL(node); | 
|  | 63 | Node* const clone = Node::Clone(zone(), NextNodeId(), node); | 
|  | 64 | Decorate(clone); | 
|  | 65 | return clone; | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 |  | 
|  | 69 | NodeId Graph::NextNodeId() { | 
|  | 70 | NodeId const id = next_node_id_; | 
|  | 71 | CHECK(!base::bits::UnsignedAddOverflow32(id, 1, &next_node_id_)); | 
|  | 72 | return id; | 
| Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 73 | } | 
|  | 74 |  | 
|  | 75 | }  // namespace compiler | 
|  | 76 | }  // namespace internal | 
|  | 77 | }  // namespace v8 |