summaryrefslogtreecommitdiff
path: root/deps/v8/src/compiler/graph.h
blob: 65ea3b30a42c4a1dc286832f55ea86003cd2f41e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// 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.

#ifndef V8_COMPILER_GRAPH_H_
#define V8_COMPILER_GRAPH_H_

#include <map>
#include <set>

#include "src/compiler/generic-algorithm.h"
#include "src/compiler/node.h"
#include "src/compiler/node-aux-data.h"
#include "src/compiler/source-position.h"

namespace v8 {
namespace internal {
namespace compiler {

class GraphDecorator;


class Graph : public GenericGraph<Node> {
 public:
  explicit Graph(Zone* zone);

  // Base implementation used by all factory methods.
  Node* NewNode(Operator* op, int input_count, Node** inputs);

  // Factories for nodes with static input counts.
  Node* NewNode(Operator* op) {
    return NewNode(op, 0, static_cast<Node**>(NULL));
  }
  Node* NewNode(Operator* op, Node* n1) { return NewNode(op, 1, &n1); }
  Node* NewNode(Operator* op, Node* n1, Node* n2) {
    Node* nodes[] = {n1, n2};
    return NewNode(op, ARRAY_SIZE(nodes), nodes);
  }
  Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3) {
    Node* nodes[] = {n1, n2, n3};
    return NewNode(op, ARRAY_SIZE(nodes), nodes);
  }
  Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) {
    Node* nodes[] = {n1, n2, n3, n4};
    return NewNode(op, ARRAY_SIZE(nodes), nodes);
  }
  Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
                Node* n5) {
    Node* nodes[] = {n1, n2, n3, n4, n5};
    return NewNode(op, ARRAY_SIZE(nodes), nodes);
  }
  Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, Node* n5,
                Node* n6) {
    Node* nodes[] = {n1, n2, n3, n4, n5, n6};
    return NewNode(op, ARRAY_SIZE(nodes), nodes);
  }

  void ChangeOperator(Node* node, Operator* op);
  void DeleteNode(Node* node);

  template <class Visitor>
  void VisitNodeUsesFrom(Node* node, Visitor* visitor);

  template <class Visitor>
  void VisitNodeUsesFromStart(Visitor* visitor);

  template <class Visitor>
  void VisitNodeInputsFromEnd(Visitor* visitor);

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

  void RemoveDecorator(GraphDecorator* decorator) {
    DecoratorVector::iterator it =
        std::find(decorators_.begin(), decorators_.end(), decorator);
    DCHECK(it != decorators_.end());
    decorators_.erase(it, it + 1);
  }

 private:
  typedef std::vector<GraphDecorator*, zone_allocator<GraphDecorator*> >
      DecoratorVector;
  DecoratorVector decorators_;
};


class GraphDecorator : public ZoneObject {
 public:
  virtual ~GraphDecorator() {}
  virtual void Decorate(Node* node) = 0;
};
}
}
}  // namespace v8::internal::compiler

#endif  // V8_COMPILER_GRAPH_H_