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.
5 #ifndef V8_COMPILER_GRAPH_H_
6 #define V8_COMPILER_GRAPH_H_
11 #include "src/compiler/generic-algorithm.h"
12 #include "src/compiler/node.h"
13 #include "src/compiler/node-aux-data.h"
14 #include "src/compiler/source-position.h"
23 class Graph : public GenericGraph<Node> {
25 explicit Graph(Zone* zone);
27 // Base implementation used by all factory methods.
28 Node* NewNode(const Operator* op, int input_count, Node** inputs);
30 // Factories for nodes with static input counts.
31 Node* NewNode(const Operator* op) {
32 return NewNode(op, 0, static_cast<Node**>(NULL));
34 Node* NewNode(const Operator* op, Node* n1) { return NewNode(op, 1, &n1); }
35 Node* NewNode(const Operator* op, Node* n1, Node* n2) {
36 Node* nodes[] = {n1, n2};
37 return NewNode(op, arraysize(nodes), nodes);
39 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3) {
40 Node* nodes[] = {n1, n2, n3};
41 return NewNode(op, arraysize(nodes), nodes);
43 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) {
44 Node* nodes[] = {n1, n2, n3, n4};
45 return NewNode(op, arraysize(nodes), nodes);
47 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
49 Node* nodes[] = {n1, n2, n3, n4, n5};
50 return NewNode(op, arraysize(nodes), nodes);
52 Node* NewNode(const Operator* op, Node* n1, Node* n2, Node* n3, Node* n4,
54 Node* nodes[] = {n1, n2, n3, n4, n5, n6};
55 return NewNode(op, arraysize(nodes), nodes);
58 template <class Visitor>
59 void VisitNodeUsesFrom(Node* node, Visitor* visitor);
61 template <class Visitor>
62 void VisitNodeUsesFromStart(Visitor* visitor);
64 template <class Visitor>
65 void VisitNodeInputsFromEnd(Visitor* visitor);
67 void AddDecorator(GraphDecorator* decorator) {
68 decorators_.push_back(decorator);
71 void RemoveDecorator(GraphDecorator* decorator) {
72 ZoneVector<GraphDecorator*>::iterator it =
73 std::find(decorators_.begin(), decorators_.end(), decorator);
74 DCHECK(it != decorators_.end());
75 decorators_.erase(it, it + 1);
79 ZoneVector<GraphDecorator*> decorators_;
83 class GraphDecorator : public ZoneObject {
85 virtual ~GraphDecorator() {}
86 virtual void Decorate(Node* node) = 0;
89 } // namespace compiler
90 } // namespace internal
93 #endif // V8_COMPILER_GRAPH_H_