Home | History | Annotate | Download | only in compiler
      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 
      7 #include <algorithm>
      8 
      9 #include "src/base/bits.h"
     10 #include "src/compiler/node.h"
     11 #include "src/compiler/node-properties.h"
     12 #include "src/compiler/verifier.h"
     13 
     14 namespace v8 {
     15 namespace internal {
     16 namespace compiler {
     17 
     18 Graph::Graph(Zone* zone)
     19     : zone_(zone),
     20       start_(nullptr),
     21       end_(nullptr),
     22       mark_max_(0),
     23       next_node_id_(0),
     24       decorators_(zone) {}
     25 
     26 
     27 void Graph::Decorate(Node* node) {
     28   for (GraphDecorator* const decorator : decorators_) {
     29     decorator->Decorate(node);
     30   }
     31 }
     32 
     33 
     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 
     45 Node* Graph::NewNode(const Operator* op, int input_count, Node* const* inputs,
     46                      bool incomplete) {
     47   Node* node = NewNodeUnchecked(op, input_count, inputs, incomplete);
     48   Verifier::VerifyNode(node);
     49   return node;
     50 }
     51 
     52 Node* Graph::NewNodeUnchecked(const Operator* op, int input_count,
     53                               Node* const* inputs, bool incomplete) {
     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;
     73 }
     74 
     75 }  // namespace compiler
     76 }  // namespace internal
     77 }  // namespace v8
     78