graph.cc 1.56 KB
Newer Older
1 2 3 4 5 6
// Copyright 2013 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/compiler/graph.h"

7 8 9
#include <algorithm>

#include "src/base/bits.h"
10 11 12 13 14 15
#include "src/compiler/node.h"

namespace v8 {
namespace internal {
namespace compiler {

16
Graph::Graph(Zone* zone)
17
    : zone_(zone),
18 19
      start_(nullptr),
      end_(nullptr),
20 21 22
      mark_max_(0),
      next_node_id_(0),
      decorators_(zone) {}
23 24


25
void Graph::Decorate(Node* node) {
26
  for (auto const decorator : decorators_) {
27
    decorator->Decorate(node);
28
  }
29 30 31 32 33 34 35 36 37 38 39 40
}


void Graph::AddDecorator(GraphDecorator* decorator) {
  decorators_.push_back(decorator);
}


void Graph::RemoveDecorator(GraphDecorator* decorator) {
  auto const it = std::find(decorators_.begin(), decorators_.end(), decorator);
  DCHECK(it != decorators_.end());
  decorators_.erase(it);
41 42 43
}


44 45
Node* Graph::NewNode(const Operator* op, int input_count, Node** inputs,
                     bool incomplete) {
46
  DCHECK_LE(op->ValueInputCount(), input_count);
47 48
  Node* const node =
      Node::New(zone(), NextNodeId(), op, input_count, inputs, incomplete);
49
  Decorate(node);
50 51 52 53
  return node;
}


54 55 56 57 58 59 60 61
Node* Graph::CloneNode(const Node* node) {
  DCHECK_NOT_NULL(node);
  Node* const clone = Node::Clone(zone(), NextNodeId(), node);
  Decorate(clone);
  return clone;
}


62 63
NodeId Graph::NextNodeId() {
  NodeId const id = next_node_id_;
64
  CHECK(!base::bits::UnsignedAddOverflow32(id, 1, &next_node_id_));
65
  return id;
66 67
}

68 69 70
}  // namespace compiler
}  // namespace internal
}  // namespace v8