OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_BYTECODE_GRAPH_BUILDER_H_ | 5 #ifndef V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ |
6 #define V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ | 6 #define V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ |
7 | 7 |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/compiler/bytecode-branch-analysis.h" | 9 #include "src/compiler/bytecode-branch-analysis.h" |
10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
11 #include "src/interpreter/bytecode-array-iterator.h" | 11 #include "src/interpreter/bytecode-array-iterator.h" |
12 #include "src/interpreter/bytecodes.h" | 12 #include "src/interpreter/bytecodes.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 namespace compiler { | 16 namespace compiler { |
17 | 17 |
18 // The BytecodeGraphBuilder produces a high-level IR graph based on | 18 // The BytecodeGraphBuilder produces a high-level IR graph based on |
19 // interpreter bytecodes. | 19 // interpreter bytecodes. |
20 class BytecodeGraphBuilder { | 20 class BytecodeGraphBuilder { |
21 public: | 21 public: |
22 BytecodeGraphBuilder(Zone* local_zone, CompilationInfo* info, | 22 BytecodeGraphBuilder(Zone* local_zone, CompilationInfo* info, |
23 JSGraph* jsgraph); | 23 JSGraph* jsgraph); |
24 | 24 |
25 // Creates a graph by visiting bytecodes. | 25 // Creates a graph by visiting bytecodes. |
26 bool CreateGraph(bool stack_check = true); | 26 bool CreateGraph(bool stack_check = true); |
27 | 27 |
28 Graph* graph() const { return jsgraph_->graph(); } | |
29 | |
30 private: | 28 private: |
31 class Environment; | 29 class Environment; |
32 class FrameStateBeforeAndAfter; | 30 class FrameStateBeforeAndAfter; |
33 | 31 |
34 void CreateGraphBody(bool stack_check); | 32 void CreateGraphBody(bool stack_check); |
35 void VisitBytecodes(); | 33 void VisitBytecodes(); |
36 | 34 |
37 Node* LoadAccumulator(Node* value); | |
38 | |
39 // Get or create the node that represents the outer function closure. | 35 // Get or create the node that represents the outer function closure. |
40 Node* GetFunctionClosure(); | 36 Node* GetFunctionClosure(); |
41 | 37 |
42 // Get or create the node that represents the outer function context. | 38 // Get or create the node that represents the outer function context. |
43 Node* GetFunctionContext(); | 39 Node* GetFunctionContext(); |
44 | 40 |
45 // Get or create the node that represents the incoming new target value. | 41 // Get or create the node that represents the incoming new target value. |
46 Node* GetNewTarget(); | 42 Node* GetNewTarget(); |
47 | 43 |
48 // Builder for accessing a (potentially immutable) object field. | 44 // Builder for accessing a (potentially immutable) object field. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 114 |
119 Node* ProcessCallArguments(const Operator* call_op, Node* callee, | 115 Node* ProcessCallArguments(const Operator* call_op, Node* callee, |
120 interpreter::Register receiver, size_t arity); | 116 interpreter::Register receiver, size_t arity); |
121 Node* ProcessCallNewArguments(const Operator* call_new_op, | 117 Node* ProcessCallNewArguments(const Operator* call_new_op, |
122 interpreter::Register callee, | 118 interpreter::Register callee, |
123 interpreter::Register first_arg, size_t arity); | 119 interpreter::Register first_arg, size_t arity); |
124 Node* ProcessCallRuntimeArguments(const Operator* call_runtime_op, | 120 Node* ProcessCallRuntimeArguments(const Operator* call_runtime_op, |
125 interpreter::Register first_arg, | 121 interpreter::Register first_arg, |
126 size_t arity); | 122 size_t arity); |
127 | 123 |
128 void BuildCreateLiteral(const Operator* op, | 124 void BuildCreateLiteral(const Operator* op); |
129 const interpreter::BytecodeArrayIterator& iterator); | 125 void BuildCreateRegExpLiteral(); |
130 void BuildCreateRegExpLiteral( | 126 void BuildCreateArrayLiteral(); |
131 const interpreter::BytecodeArrayIterator& iterator); | 127 void BuildCreateObjectLiteral(); |
132 void BuildCreateArrayLiteral( | 128 void BuildCreateArguments(CreateArgumentsParameters::Type type); |
133 const interpreter::BytecodeArrayIterator& iterator); | 129 void BuildLoadGlobal(TypeofMode typeof_mode); |
134 void BuildCreateObjectLiteral( | 130 void BuildStoreGlobal(); |
135 const interpreter::BytecodeArrayIterator& iterator); | 131 void BuildNamedLoad(); |
136 void BuildCreateArguments(CreateArgumentsParameters::Type type, | 132 void BuildKeyedLoad(); |
137 const interpreter::BytecodeArrayIterator& iterator); | 133 void BuildNamedStore(); |
138 void BuildLoadGlobal(const interpreter::BytecodeArrayIterator& iterator, | 134 void BuildKeyedStore(); |
139 TypeofMode typeof_mode); | 135 void BuildLdaLookupSlot(TypeofMode typeof_mode); |
140 void BuildStoreGlobal(const interpreter::BytecodeArrayIterator& iterator); | 136 void BuildStaLookupSlot(LanguageMode language_mode); |
141 void BuildNamedLoad(const interpreter::BytecodeArrayIterator& iterator); | 137 void BuildCall(); |
142 void BuildKeyedLoad(const interpreter::BytecodeArrayIterator& iterator); | 138 void BuildCallJSRuntime(); |
143 void BuildNamedStore(const interpreter::BytecodeArrayIterator& iterator); | 139 void BuildCallRuntime(); |
144 void BuildKeyedStore(const interpreter::BytecodeArrayIterator& iterator); | 140 void BuildCallRuntimeForPair(); |
145 void BuildLdaLookupSlot(TypeofMode typeof_mode, | 141 void BuildCallConstruct(); |
146 const interpreter::BytecodeArrayIterator& iterator); | 142 void BuildBinaryOp(const Operator* op); |
147 void BuildStaLookupSlot(LanguageMode language_mode, | 143 void BuildCompareOp(const Operator* op); |
148 const interpreter::BytecodeArrayIterator& iterator); | 144 void BuildDelete(); |
149 void BuildCall(const interpreter::BytecodeArrayIterator& iterator); | 145 void BuildCastOperator(const Operator* js_op); |
150 void BuildCallJSRuntime(const interpreter::BytecodeArrayIterator& iterator); | 146 void BuildForInPrepare(); |
151 void BuildCallRuntime(const interpreter::BytecodeArrayIterator& iterator); | 147 void BuildForInNext(); |
152 void BuildCallRuntimeForPair( | |
153 const interpreter::BytecodeArrayIterator& iterator); | |
154 void BuildCallConstruct(const interpreter::BytecodeArrayIterator& iterator); | |
155 void BuildBinaryOp(const Operator* op, | |
156 const interpreter::BytecodeArrayIterator& iterator); | |
157 void BuildCompareOp(const Operator* op, | |
158 const interpreter::BytecodeArrayIterator& iterator); | |
159 void BuildDelete(const interpreter::BytecodeArrayIterator& iterator); | |
160 void BuildCastOperator(const Operator* js_op, | |
161 const interpreter::BytecodeArrayIterator& iterator); | |
162 void BuildForInPrepare(const interpreter::BytecodeArrayIterator& iterator); | |
163 void BuildForInNext(const interpreter::BytecodeArrayIterator& iterator); | |
164 | 148 |
165 // Control flow plumbing. | 149 // Control flow plumbing. |
166 void BuildJump(int source_offset, int target_offset); | 150 void BuildJump(int source_offset, int target_offset); |
167 void BuildJump(); | 151 void BuildJump(); |
168 void BuildConditionalJump(Node* condition); | 152 void BuildConditionalJump(Node* condition); |
169 void BuildJumpIfEqual(Node* comperand); | 153 void BuildJumpIfEqual(Node* comperand); |
170 void BuildJumpIfToBooleanEqual(Node* boolean_comperand); | 154 void BuildJumpIfToBooleanEqual(Node* boolean_comperand); |
171 | 155 |
172 // Constructing merge and loop headers. | 156 // Constructing merge and loop headers. |
173 void MergeEnvironmentsOfBackwardBranches(int source_offset, | 157 void MergeEnvironmentsOfBackwardBranches(int source_offset, |
(...skipping 15 matching lines...) Expand all Loading... |
189 // entered and exited while the graph builder is iterating over the | 173 // entered and exited while the graph builder is iterating over the |
190 // underlying bytecode. The exception handlers within the bytecode are | 174 // underlying bytecode. The exception handlers within the bytecode are |
191 // well scoped, hence will form a stack during iteration. | 175 // well scoped, hence will form a stack during iteration. |
192 struct ExceptionHandler { | 176 struct ExceptionHandler { |
193 int start_offset_; // Start offset of the handled area in the bytecode. | 177 int start_offset_; // Start offset of the handled area in the bytecode. |
194 int end_offset_; // End offset of the handled area in the bytecode. | 178 int end_offset_; // End offset of the handled area in the bytecode. |
195 int handler_offset_; // Handler entry offset within the bytecode. | 179 int handler_offset_; // Handler entry offset within the bytecode. |
196 }; | 180 }; |
197 | 181 |
198 // Field accessors | 182 // Field accessors |
| 183 Graph* graph() const { return jsgraph_->graph(); } |
199 CommonOperatorBuilder* common() const { return jsgraph_->common(); } | 184 CommonOperatorBuilder* common() const { return jsgraph_->common(); } |
200 Zone* graph_zone() const { return graph()->zone(); } | 185 Zone* graph_zone() const { return graph()->zone(); } |
201 CompilationInfo* info() const { return info_; } | 186 CompilationInfo* info() const { return info_; } |
202 JSGraph* jsgraph() const { return jsgraph_; } | 187 JSGraph* jsgraph() const { return jsgraph_; } |
203 JSOperatorBuilder* javascript() const { return jsgraph_->javascript(); } | 188 JSOperatorBuilder* javascript() const { return jsgraph_->javascript(); } |
204 Zone* local_zone() const { return local_zone_; } | 189 Zone* local_zone() const { return local_zone_; } |
205 const Handle<BytecodeArray>& bytecode_array() const { | 190 const Handle<BytecodeArray>& bytecode_array() const { |
206 return bytecode_array_; | 191 return bytecode_array_; |
207 } | 192 } |
208 const Handle<HandlerTable>& exception_handler_table() const { | 193 const Handle<HandlerTable>& exception_handler_table() const { |
209 return exception_handler_table_; | 194 return exception_handler_table_; |
210 } | 195 } |
211 const FrameStateFunctionInfo* frame_state_function_info() const { | 196 const FrameStateFunctionInfo* frame_state_function_info() const { |
212 return frame_state_function_info_; | 197 return frame_state_function_info_; |
213 } | 198 } |
214 | 199 |
215 LanguageMode language_mode() const { | 200 LanguageMode language_mode() const { |
216 // TODO(mythria): Don't rely on parse information to get language mode. | 201 // TODO(mythria): Don't rely on parse information to get language mode. |
217 return info()->language_mode(); | 202 return info()->language_mode(); |
218 } | 203 } |
219 | 204 |
220 const interpreter::BytecodeArrayIterator* bytecode_iterator() const { | 205 const interpreter::BytecodeArrayIterator& bytecode_iterator() const { |
221 return bytecode_iterator_; | 206 return *bytecode_iterator_; |
222 } | 207 } |
223 | 208 |
224 void set_bytecode_iterator( | 209 void set_bytecode_iterator( |
225 const interpreter::BytecodeArrayIterator* bytecode_iterator) { | 210 const interpreter::BytecodeArrayIterator* bytecode_iterator) { |
226 bytecode_iterator_ = bytecode_iterator; | 211 bytecode_iterator_ = bytecode_iterator; |
227 } | 212 } |
228 | 213 |
229 const BytecodeBranchAnalysis* branch_analysis() const { | 214 const BytecodeBranchAnalysis* branch_analysis() const { |
230 return branch_analysis_; | 215 return branch_analysis_; |
231 } | 216 } |
232 | 217 |
233 void set_branch_analysis(BytecodeBranchAnalysis* branch_analysis) { | 218 void set_branch_analysis(BytecodeBranchAnalysis* branch_analysis) { |
234 branch_analysis_ = branch_analysis; | 219 branch_analysis_ = branch_analysis; |
235 } | 220 } |
236 | 221 |
237 #define DECLARE_VISIT_BYTECODE(name, ...) \ | 222 #define DECLARE_VISIT_BYTECODE(name, ...) void Visit##name(); |
238 void Visit##name(const interpreter::BytecodeArrayIterator& iterator); | |
239 BYTECODE_LIST(DECLARE_VISIT_BYTECODE) | 223 BYTECODE_LIST(DECLARE_VISIT_BYTECODE) |
240 #undef DECLARE_VISIT_BYTECODE | 224 #undef DECLARE_VISIT_BYTECODE |
241 | 225 |
242 Zone* local_zone_; | 226 Zone* local_zone_; |
243 CompilationInfo* info_; | 227 CompilationInfo* info_; |
244 JSGraph* jsgraph_; | 228 JSGraph* jsgraph_; |
245 Handle<BytecodeArray> bytecode_array_; | 229 Handle<BytecodeArray> bytecode_array_; |
246 Handle<HandlerTable> exception_handler_table_; | 230 Handle<HandlerTable> exception_handler_table_; |
247 const FrameStateFunctionInfo* frame_state_function_info_; | 231 const FrameStateFunctionInfo* frame_state_function_info_; |
248 const interpreter::BytecodeArrayIterator* bytecode_iterator_; | 232 const interpreter::BytecodeArrayIterator* bytecode_iterator_; |
(...skipping 28 matching lines...) Expand all Loading... |
277 ZoneVector<Node*> exit_controls_; | 261 ZoneVector<Node*> exit_controls_; |
278 | 262 |
279 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilder); | 263 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilder); |
280 }; | 264 }; |
281 | 265 |
282 } // namespace compiler | 266 } // namespace compiler |
283 } // namespace internal | 267 } // namespace internal |
284 } // namespace v8 | 268 } // namespace v8 |
285 | 269 |
286 #endif // V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ | 270 #endif // V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ |
OLD | NEW |