| OLD | NEW |
| (Empty) | |
| 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 #ifndef V8_COMPILER_GRAPH_H_ |
| 6 #define V8_COMPILER_GRAPH_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 |
| 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" |
| 15 |
| 16 namespace v8 { |
| 17 namespace internal { |
| 18 namespace compiler { |
| 19 |
| 20 class GraphDecorator; |
| 21 |
| 22 |
| 23 class Graph : public GenericGraph<Node> { |
| 24 public: |
| 25 explicit Graph(Zone* zone); |
| 26 |
| 27 // Base implementation used by all factory methods. |
| 28 Node* NewNode(Operator* op, int input_count, Node** inputs); |
| 29 |
| 30 // Factories for nodes with static input counts. |
| 31 Node* NewNode(Operator* op) { |
| 32 return NewNode(op, 0, static_cast<Node**>(NULL)); |
| 33 } |
| 34 Node* NewNode(Operator* op, Node* n1) { |
| 35 return NewNode(op, 1, &n1); |
| 36 } |
| 37 Node* NewNode(Operator* op, Node* n1, Node* n2) { |
| 38 Node* nodes[] = { n1, n2 }; |
| 39 return NewNode(op, ARRAY_SIZE(nodes), nodes); |
| 40 } |
| 41 Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3) { |
| 42 Node* nodes[] = { n1, n2, n3 }; |
| 43 return NewNode(op, ARRAY_SIZE(nodes), nodes); |
| 44 } |
| 45 Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4) { |
| 46 Node* nodes[] = { n1, n2, n3, n4 }; |
| 47 return NewNode(op, ARRAY_SIZE(nodes), nodes); |
| 48 } |
| 49 Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, |
| 50 Node* n5) { |
| 51 Node* nodes[] = { n1, n2, n3, n4, n5 }; |
| 52 return NewNode(op, ARRAY_SIZE(nodes), nodes); |
| 53 } |
| 54 Node* NewNode(Operator* op, Node* n1, Node* n2, Node* n3, Node* n4, |
| 55 Node* n5, Node* n6) { |
| 56 Node* nodes[] = { n1, n2, n3, n4, n5, n6 }; |
| 57 return NewNode(op, ARRAY_SIZE(nodes), nodes); |
| 58 } |
| 59 |
| 60 void ChangeOperator(Node* node, Operator* op); |
| 61 void DeleteNode(Node* node); |
| 62 |
| 63 template <class Visitor> |
| 64 void VisitNodeUsesFrom(Node* node, Visitor* visitor); |
| 65 |
| 66 template <class Visitor> |
| 67 void VisitNodeUsesFromStart(Visitor* visitor); |
| 68 |
| 69 template <class Visitor> |
| 70 void VisitNodeInputsFromEnd(Visitor* visitor); |
| 71 |
| 72 void AddDecorator(GraphDecorator* decorator) { |
| 73 decorators_.push_back(decorator); |
| 74 } |
| 75 |
| 76 void RemoveDecorator(GraphDecorator* decorator) { |
| 77 DecoratorVector::iterator it = |
| 78 std::find(decorators_.begin(), decorators_.end(), decorator); |
| 79 ASSERT(it != decorators_.end()); |
| 80 decorators_.erase(it, it + 1); |
| 81 } |
| 82 |
| 83 private: |
| 84 typedef std::vector<GraphDecorator*, zone_allocator<GraphDecorator*> > |
| 85 DecoratorVector; |
| 86 DecoratorVector decorators_; |
| 87 }; |
| 88 |
| 89 |
| 90 class GraphDecorator : public ZoneObject { |
| 91 public: |
| 92 virtual ~GraphDecorator() {} |
| 93 virtual void Decorate(Node* node) = 0; |
| 94 }; |
| 95 |
| 96 } } } // namespace v8::internal::compiler |
| 97 |
| 98 #endif // V8_COMPILER_GRAPH_H_ |
| OLD | NEW |