Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_GRAPH_BUILDER_H_ | 5 #ifndef V8_COMPILER_GRAPH_BUILDER_H_ |
| 6 #define V8_COMPILER_GRAPH_BUILDER_H_ | 6 #define V8_COMPILER_GRAPH_BUILDER_H_ |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| 11 #include "src/compiler/common-operator.h" | 11 #include "src/compiler/common-operator.h" |
| 12 #include "src/compiler/graph.h" | 12 #include "src/compiler/graph.h" |
| 13 #include "src/compiler/node.h" | 13 #include "src/compiler/node.h" |
| 14 #include "src/unique.h" | 14 #include "src/unique.h" |
| 15 | 15 |
| 16 namespace v8 { | 16 namespace v8 { |
| 17 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 class BitVector; | 19 class BitVector; |
| 20 | 20 |
| 21 namespace compiler { | 21 namespace compiler { |
| 22 | 22 |
| 23 class Node; | 23 class Node; |
| 24 | 24 |
| 25 // A common base class for anything that creates nodes in a graph. | 25 // A common base class for anything that creates nodes in a graph. |
| 26 class GraphBuilder { | 26 class GraphBuilder { |
| 27 public: | 27 public: |
| 28 explicit GraphBuilder(Graph* graph) : graph_(graph) {} | 28 GraphBuilder(Isolate* isolate, Graph* graph) |
| 29 : isolate_(isolate), graph_(graph) {} | |
| 29 virtual ~GraphBuilder() {} | 30 virtual ~GraphBuilder() {} |
| 30 | 31 |
| 31 Node* NewNode(const Operator* op, bool incomplete = false) { | 32 Node* NewNode(const Operator* op, bool incomplete = false) { |
| 32 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); | 33 return MakeNode(op, 0, static_cast<Node**>(NULL), incomplete); |
| 33 } | 34 } |
| 34 | 35 |
| 35 Node* NewNode(const Operator* op, Node* n1) { | 36 Node* NewNode(const Operator* op, Node* n1) { |
| 36 return MakeNode(op, 1, &n1, false); | 37 return MakeNode(op, 1, &n1, false); |
| 37 } | 38 } |
| 38 | 39 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 61 Node* n5, Node* n6) { | 62 Node* n5, Node* n6) { |
| 62 Node* nodes[] = {n1, n2, n3, n4, n5, n6}; | 63 Node* nodes[] = {n1, n2, n3, n4, n5, n6}; |
| 63 return MakeNode(op, arraysize(nodes), nodes, false); | 64 return MakeNode(op, arraysize(nodes), nodes, false); |
| 64 } | 65 } |
| 65 | 66 |
| 66 Node* NewNode(const Operator* op, int value_input_count, Node** value_inputs, | 67 Node* NewNode(const Operator* op, int value_input_count, Node** value_inputs, |
| 67 bool incomplete = false) { | 68 bool incomplete = false) { |
| 68 return MakeNode(op, value_input_count, value_inputs, incomplete); | 69 return MakeNode(op, value_input_count, value_inputs, incomplete); |
| 69 } | 70 } |
| 70 | 71 |
| 72 Isolate* isolate() const { return isolate_; } | |
| 71 Graph* graph() const { return graph_; } | 73 Graph* graph() const { return graph_; } |
| 72 | 74 |
| 73 protected: | 75 protected: |
| 74 // Base implementation used by all factory methods. | 76 // Base implementation used by all factory methods. |
| 75 virtual Node* MakeNode(const Operator* op, int value_input_count, | 77 virtual Node* MakeNode(const Operator* op, int value_input_count, |
| 76 Node** value_inputs, bool incomplete) = 0; | 78 Node** value_inputs, bool incomplete) = 0; |
| 77 | 79 |
| 78 private: | 80 private: |
| 81 Isolate* isolate_; | |
| 79 Graph* graph_; | 82 Graph* graph_; |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 | 85 |
| 83 // The StructuredGraphBuilder produces a high-level IR graph. It is used as the | 86 // The StructuredGraphBuilder produces a high-level IR graph. It is used as the |
| 84 // base class for concrete implementations (e.g the AstGraphBuilder or the | 87 // base class for concrete implementations (e.g the AstGraphBuilder or the |
| 85 // StubGraphBuilder). | 88 // StubGraphBuilder). |
| 86 class StructuredGraphBuilder : public GraphBuilder { | 89 class StructuredGraphBuilder : public GraphBuilder { |
| 87 public: | 90 public: |
| 88 StructuredGraphBuilder(Zone* zone, Graph* graph, | 91 StructuredGraphBuilder(Isolate* isolate, Zone* zone, Graph* graph, |
| 89 CommonOperatorBuilder* common); | 92 CommonOperatorBuilder* common); |
| 90 ~StructuredGraphBuilder() OVERRIDE {} | 93 ~StructuredGraphBuilder() OVERRIDE {} |
| 91 | 94 |
| 92 // Creates a new Phi node having {count} input values. | 95 // Creates a new Phi node having {count} input values. |
| 93 Node* NewPhi(int count, Node* input, Node* control); | 96 Node* NewPhi(int count, Node* input, Node* control); |
| 94 Node* NewEffectPhi(int count, Node* input, Node* control); | 97 Node* NewEffectPhi(int count, Node* input, Node* control); |
| 95 | 98 |
| 96 // Helpers for merging control, effect or value dependencies. | 99 // Helpers for merging control, effect or value dependencies. |
| 97 Node* MergeControl(Node* control, Node* other); | 100 Node* MergeControl(Node* control, Node* other); |
| 98 Node* MergeEffect(Node* value, Node* other, Node* control); | 101 Node* MergeEffect(Node* value, Node* other, Node* control); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 124 Node* current_context() const { return current_context_; } | 127 Node* current_context() const { return current_context_; } |
| 125 void set_current_context(Node* context) { current_context_ = context; } | 128 void set_current_context(Node* context) { current_context_ = context; } |
| 126 | 129 |
| 127 Node* exit_control() const { return exit_control_; } | 130 Node* exit_control() const { return exit_control_; } |
| 128 void set_exit_control(Node* node) { exit_control_ = node; } | 131 void set_exit_control(Node* node) { exit_control_ = node; } |
| 129 | 132 |
| 130 Node* dead_control(); | 133 Node* dead_control(); |
| 131 | 134 |
| 132 Zone* graph_zone() const { return graph()->zone(); } | 135 Zone* graph_zone() const { return graph()->zone(); } |
| 133 Zone* local_zone() const { return local_zone_; } | 136 Zone* local_zone() const { return local_zone_; } |
| 134 Isolate* isolate() const { return graph_zone()->isolate(); } | 137 Isolate* isolate() const { return isolate_; } |
|
Michael Starzinger
2015/01/23 14:21:10
Can be dropped since it now just overrides GraphBu
danno
2015/01/23 14:45:20
Done.
| |
| 135 CommonOperatorBuilder* common() const { return common_; } | 138 CommonOperatorBuilder* common() const { return common_; } |
| 136 | 139 |
| 137 // Helper to wrap a Handle<T> into a Unique<T>. | 140 // Helper to wrap a Handle<T> into a Unique<T>. |
| 138 template <class T> | 141 template <class T> |
| 139 Unique<T> MakeUnique(Handle<T> object) { | 142 Unique<T> MakeUnique(Handle<T> object) { |
| 140 return Unique<T>::CreateUninitialized(object); | 143 return Unique<T>::CreateUninitialized(object); |
| 141 } | 144 } |
| 142 | 145 |
| 143 // Support for control flow builders. The concrete type of the environment | 146 // Support for control flow builders. The concrete type of the environment |
| 144 // depends on the graph builder, but environments themselves are not virtual. | 147 // depends on the graph builder, but environments themselves are not virtual. |
| 145 virtual Environment* CopyEnvironment(Environment* env); | 148 virtual Environment* CopyEnvironment(Environment* env); |
| 146 | 149 |
| 147 // Helper to indicate a node exits the function body. | 150 // Helper to indicate a node exits the function body. |
| 148 void UpdateControlDependencyToLeaveFunction(Node* exit); | 151 void UpdateControlDependencyToLeaveFunction(Node* exit); |
| 149 | 152 |
| 150 private: | 153 private: |
| 151 CommonOperatorBuilder* common_; | 154 CommonOperatorBuilder* common_; |
| 152 Environment* environment_; | 155 Environment* environment_; |
| 153 | 156 |
| 157 Isolate* isolate_; | |
|
Michael Starzinger
2015/01/23 14:21:10
Can be dropped now since it shadows GraphBuilder::
danno
2015/01/23 14:45:20
Done.
| |
| 158 | |
| 154 // Zone local to the builder for data not leaking into the graph. | 159 // Zone local to the builder for data not leaking into the graph. |
| 155 Zone* local_zone_; | 160 Zone* local_zone_; |
| 156 | 161 |
| 157 // Temporary storage for building node input lists. | 162 // Temporary storage for building node input lists. |
| 158 int input_buffer_size_; | 163 int input_buffer_size_; |
| 159 Node** input_buffer_; | 164 Node** input_buffer_; |
| 160 | 165 |
| 161 // Node representing the control dependency for dead code. | 166 // Node representing the control dependency for dead code. |
| 162 SetOncePointer<Node> dead_control_; | 167 SetOncePointer<Node> dead_control_; |
| 163 | 168 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 StructuredGraphBuilder* builder_; | 245 StructuredGraphBuilder* builder_; |
| 241 Node* control_dependency_; | 246 Node* control_dependency_; |
| 242 Node* effect_dependency_; | 247 Node* effect_dependency_; |
| 243 NodeVector values_; | 248 NodeVector values_; |
| 244 }; | 249 }; |
| 245 } | 250 } |
| 246 } | 251 } |
| 247 } // namespace v8::internal::compiler | 252 } // namespace v8::internal::compiler |
| 248 | 253 |
| 249 #endif // V8_COMPILER_GRAPH_BUILDER_H__ | 254 #endif // V8_COMPILER_GRAPH_BUILDER_H__ |
| OLD | NEW |