OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/interpreter/bytecode-peephole-optimizer.h" | 5 #include "src/interpreter/bytecode-peephole-optimizer.h" |
6 | 6 |
7 #include "src/interpreter/constant-array-builder.h" | 7 #include "src/interpreter/constant-array-builder.h" |
Michael Starzinger
2016/08/11 13:19:14
nit: Header file inclusion should be obsolete. Let
rmcilroy
2016/08/11 14:46:17
Good catch, thanks. Done.
| |
8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace interpreter { | 13 namespace interpreter { |
14 | 14 |
15 BytecodePeepholeOptimizer::BytecodePeepholeOptimizer( | 15 BytecodePeepholeOptimizer::BytecodePeepholeOptimizer( |
16 ConstantArrayBuilder* constant_array_builder, | |
17 BytecodePipelineStage* next_stage) | 16 BytecodePipelineStage* next_stage) |
18 : constant_array_builder_(constant_array_builder), next_stage_(next_stage) { | 17 : next_stage_(next_stage) { |
19 InvalidateLast(); | 18 InvalidateLast(); |
20 } | 19 } |
21 | 20 |
22 // override | 21 // override |
23 Handle<BytecodeArray> BytecodePeepholeOptimizer::ToBytecodeArray( | 22 Handle<BytecodeArray> BytecodePeepholeOptimizer::ToBytecodeArray( |
24 int fixed_register_count, int parameter_count, | 23 int fixed_register_count, int parameter_count, |
25 Handle<FixedArray> handler_table) { | 24 Handle<FixedArray> handler_table) { |
26 Flush(); | 25 Flush(); |
27 return next_stage_->ToBytecodeArray(fixed_register_count, parameter_count, | 26 return next_stage_->ToBytecodeArray(fixed_register_count, parameter_count, |
28 handler_table); | 27 handler_table); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 | 75 |
77 void BytecodePeepholeOptimizer::SetLast(const BytecodeNode* const node) { | 76 void BytecodePeepholeOptimizer::SetLast(const BytecodeNode* const node) { |
78 // An action shouldn't leave a NOP as last bytecode unless it has | 77 // An action shouldn't leave a NOP as last bytecode unless it has |
79 // source position information. NOP without source information can | 78 // source position information. NOP without source information can |
80 // always be elided. | 79 // always be elided. |
81 DCHECK(node->bytecode() != Bytecode::kNop || node->source_info().is_valid()); | 80 DCHECK(node->bytecode() != Bytecode::kNop || node->source_info().is_valid()); |
82 | 81 |
83 last_.Clone(node); | 82 last_.Clone(node); |
84 } | 83 } |
85 | 84 |
86 Handle<Object> BytecodePeepholeOptimizer::GetConstantForIndexOperand( | |
87 const BytecodeNode* const node, int index) const { | |
88 DCHECK_LE(index, node->operand_count()); | |
89 DCHECK_EQ(Bytecodes::GetOperandType(node->bytecode(), 0), OperandType::kIdx); | |
90 uint32_t index_operand = node->operand(0); | |
91 return constant_array_builder_->At(index_operand); | |
92 } | |
93 | |
94 bool BytecodePeepholeOptimizer::CanElideLastBasedOnSourcePosition( | 85 bool BytecodePeepholeOptimizer::CanElideLastBasedOnSourcePosition( |
95 const BytecodeNode* const current) const { | 86 const BytecodeNode* const current) const { |
96 // | 87 // |
97 // The rules for allowing the elision of the last bytecode based | 88 // The rules for allowing the elision of the last bytecode based |
98 // on source position are: | 89 // on source position are: |
99 // | 90 // |
100 // C U R R E N T | 91 // C U R R E N T |
101 // +--------+--------+--------+ | 92 // +--------+--------+--------+ |
102 // | None | Expr | Stmt | | 93 // | None | Expr | Stmt | |
103 // L +--------+--------+--------+--------+ | 94 // L +--------+--------+--------+--------+ |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) { | 273 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) { |
283 // Fused last and current into current. | 274 // Fused last and current into current. |
284 TransformLdaZeroBinaryOpToBinaryOpWithZero(action_data->bytecode, last(), | 275 TransformLdaZeroBinaryOpToBinaryOpWithZero(action_data->bytecode, last(), |
285 node); | 276 node); |
286 SetLast(node); | 277 SetLast(node); |
287 } else { | 278 } else { |
288 DefaultAction(node); | 279 DefaultAction(node); |
289 } | 280 } |
290 } | 281 } |
291 | 282 |
292 void BytecodePeepholeOptimizer::TransformToStarIfLoadingNameConstantAction( | |
293 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | |
294 DCHECK_EQ(last()->bytecode(), Bytecode::kLdaConstant); | |
295 DCHECK(!Bytecodes::IsJump(node->bytecode())); | |
296 | |
297 // TODO(5203): Remove this temporary exception. | |
298 AllowHandleDereference allow_deref; | |
299 if (GetConstantForIndexOperand(last(), 0)->IsName()) { | |
300 node->replace_bytecode(Bytecode::kStar); | |
301 } | |
302 DefaultAction(node); | |
303 } | |
304 | |
305 void BytecodePeepholeOptimizer::DefaultJumpAction( | 283 void BytecodePeepholeOptimizer::DefaultJumpAction( |
306 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | 284 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
307 DCHECK(LastIsValid()); | 285 DCHECK(LastIsValid()); |
308 DCHECK(Bytecodes::IsJump(node->bytecode())); | 286 DCHECK(Bytecodes::IsJump(node->bytecode())); |
309 | 287 |
310 next_stage()->Write(last()); | 288 next_stage()->Write(last()); |
311 InvalidateLast(); | 289 InvalidateLast(); |
312 } | 290 } |
313 | 291 |
314 void BytecodePeepholeOptimizer::UpdateLastJumpAction( | 292 void BytecodePeepholeOptimizer::UpdateLastJumpAction( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 #undef CASE | 335 #undef CASE |
358 default: | 336 default: |
359 UNREACHABLE(); | 337 UNREACHABLE(); |
360 break; | 338 break; |
361 } | 339 } |
362 } | 340 } |
363 | 341 |
364 } // namespace interpreter | 342 } // namespace interpreter |
365 } // namespace internal | 343 } // namespace internal |
366 } // namespace v8 | 344 } // namespace v8 |
OLD | NEW |