| 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/objects-inl.h" | 7 #include "src/objects-inl.h" |
| 8 #include "src/objects.h" | 8 #include "src/objects.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 BytecodeNode* const last, | 131 BytecodeNode* const last, |
| 132 BytecodeNode* const current) { | 132 BytecodeNode* const current) { |
| 133 DCHECK_EQ(last->bytecode(), Bytecode::kLdaZero); | 133 DCHECK_EQ(last->bytecode(), Bytecode::kLdaZero); |
| 134 current->set_bytecode(new_bytecode, 0, current->operand(0), | 134 current->set_bytecode(new_bytecode, 0, current->operand(0), |
| 135 current->operand(1)); | 135 current->operand(1)); |
| 136 if (last->source_info().is_valid()) { | 136 if (last->source_info().is_valid()) { |
| 137 current->set_source_info(last->source_info()); | 137 current->set_source_info(last->source_info()); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 void TransformEqualityWithNullOrUndefinedToTestUndetectable( | 141 void TransformEqualityWithNullOrUndefined(Bytecode new_bytecode, |
| 142 BytecodeNode* const last, BytecodeNode* const current) { | 142 BytecodeNode* const last, |
| 143 BytecodeNode* const current) { |
| 143 DCHECK((last->bytecode() == Bytecode::kLdaNull) || | 144 DCHECK((last->bytecode() == Bytecode::kLdaNull) || |
| 144 (last->bytecode() == Bytecode::kLdaUndefined)); | 145 (last->bytecode() == Bytecode::kLdaUndefined)); |
| 145 DCHECK_EQ(current->bytecode(), Bytecode::kTestEqual); | 146 DCHECK((current->bytecode() == Bytecode::kTestEqual) || |
| 146 current->set_bytecode(Bytecode::kTestUndetectable, current->operand(0)); | 147 (current->bytecode() == Bytecode::kTestEqualStrict)); |
| 148 current->set_bytecode(new_bytecode, current->operand(0)); |
| 147 if (last->source_info().is_valid()) { | 149 if (last->source_info().is_valid()) { |
| 148 current->set_source_info(last->source_info()); | 150 current->set_source_info(last->source_info()); |
| 149 } | 151 } |
| 150 } | 152 } |
| 151 | 153 |
| 152 } // namespace | 154 } // namespace |
| 153 | 155 |
| 154 void BytecodePeepholeOptimizer::DefaultAction( | 156 void BytecodePeepholeOptimizer::DefaultAction( |
| 155 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | 157 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
| 156 DCHECK(LastIsValid()); | 158 DCHECK(LastIsValid()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) { | 257 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) { |
| 256 // Fused last and current into current. | 258 // Fused last and current into current. |
| 257 TransformLdaZeroBinaryOpToBinaryOpWithZero(action_data->bytecode, last(), | 259 TransformLdaZeroBinaryOpToBinaryOpWithZero(action_data->bytecode, last(), |
| 258 node); | 260 node); |
| 259 SetLast(node); | 261 SetLast(node); |
| 260 } else { | 262 } else { |
| 261 DefaultAction(node); | 263 DefaultAction(node); |
| 262 } | 264 } |
| 263 } | 265 } |
| 264 | 266 |
| 265 void BytecodePeepholeOptimizer:: | 267 void BytecodePeepholeOptimizer::TransformEqualityWithNullOrUndefinedAction( |
| 266 TransformEqualityWithNullOrUndefinedToTestUndetectableAction( | 268 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
| 267 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | |
| 268 DCHECK(LastIsValid()); | 269 DCHECK(LastIsValid()); |
| 269 DCHECK(!Bytecodes::IsJump(node->bytecode())); | 270 DCHECK(!Bytecodes::IsJump(node->bytecode())); |
| 270 // Fused last and current into current. | 271 // Fused last and current into current. |
| 271 TransformEqualityWithNullOrUndefinedToTestUndetectable(last(), node); | 272 TransformEqualityWithNullOrUndefined(action_data->bytecode, last(), node); |
| 272 SetLast(node); | 273 SetLast(node); |
| 273 } | 274 } |
| 274 | 275 |
| 275 void BytecodePeepholeOptimizer::DefaultJumpAction( | 276 void BytecodePeepholeOptimizer::DefaultJumpAction( |
| 276 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | 277 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
| 277 DCHECK(LastIsValid()); | 278 DCHECK(LastIsValid()); |
| 278 DCHECK(Bytecodes::IsJump(node->bytecode())); | 279 DCHECK(Bytecodes::IsJump(node->bytecode())); |
| 279 | 280 |
| 280 next_stage()->Write(last()); | 281 next_stage()->Write(last()); |
| 281 InvalidateLast(); | 282 InvalidateLast(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 #undef CASE | 328 #undef CASE |
| 328 default: | 329 default: |
| 329 UNREACHABLE(); | 330 UNREACHABLE(); |
| 330 break; | 331 break; |
| 331 } | 332 } |
| 332 } | 333 } |
| 333 | 334 |
| 334 } // namespace interpreter | 335 } // namespace interpreter |
| 335 } // namespace internal | 336 } // namespace internal |
| 336 } // namespace v8 | 337 } // namespace v8 |
| OLD | NEW |