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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 BytecodeNode* const current) { | 134 BytecodeNode* const current) { |
135 DCHECK_EQ(last->bytecode(), Bytecode::kLdaZero); | 135 DCHECK_EQ(last->bytecode(), Bytecode::kLdaZero); |
136 BytecodeNode node(new_bytecode, 0, current->operand(0), current->operand(1), | 136 BytecodeNode node(new_bytecode, 0, current->operand(0), current->operand(1), |
137 current->source_info()); | 137 current->source_info()); |
138 if (last->source_info().is_valid()) { | 138 if (last->source_info().is_valid()) { |
139 node.set_source_info(last->source_info()); | 139 node.set_source_info(last->source_info()); |
140 } | 140 } |
141 return node; | 141 return node; |
142 } | 142 } |
143 | 143 |
144 BytecodeNode TransformEqualityWithNullOrUndefinedToTestUndetectable( | 144 BytecodeNode TransformEqualityWithNullOrUndefined(Bytecode new_bytecode, |
145 BytecodeNode* const last, BytecodeNode* const current) { | 145 BytecodeNode* const last, |
| 146 BytecodeNode* const current) { |
146 DCHECK((last->bytecode() == Bytecode::kLdaNull) || | 147 DCHECK((last->bytecode() == Bytecode::kLdaNull) || |
147 (last->bytecode() == Bytecode::kLdaUndefined)); | 148 (last->bytecode() == Bytecode::kLdaUndefined)); |
148 DCHECK_EQ(current->bytecode(), Bytecode::kTestEqual); | 149 DCHECK((current->bytecode() == Bytecode::kTestEqual) || |
149 BytecodeNode node(BytecodeNode::TestUndetectable(current->source_info(), | 150 (current->bytecode() == Bytecode::kTestEqualStrict)); |
150 current->operand(0))); | 151 BytecodeNode node(new_bytecode, current->operand(0), current->source_info()); |
151 if (last->source_info().is_valid()) { | 152 if (last->source_info().is_valid()) { |
152 node.set_source_info(last->source_info()); | 153 node.set_source_info(last->source_info()); |
153 } | 154 } |
154 return node; | 155 return node; |
155 } | 156 } |
156 | 157 |
157 } // namespace | 158 } // namespace |
158 | 159 |
159 void BytecodePeepholeOptimizer::DefaultAction( | 160 void BytecodePeepholeOptimizer::DefaultAction( |
160 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | 161 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) { | 261 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) { |
261 // Fused last and current into current. | 262 // Fused last and current into current. |
262 BytecodeNode new_node(TransformLdaZeroBinaryOpToBinaryOpWithZero( | 263 BytecodeNode new_node(TransformLdaZeroBinaryOpToBinaryOpWithZero( |
263 action_data->bytecode, last(), node)); | 264 action_data->bytecode, last(), node)); |
264 SetLast(&new_node); | 265 SetLast(&new_node); |
265 } else { | 266 } else { |
266 DefaultAction(node); | 267 DefaultAction(node); |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 void BytecodePeepholeOptimizer:: | 271 void BytecodePeepholeOptimizer::TransformEqualityWithNullOrUndefinedAction( |
271 TransformEqualityWithNullOrUndefinedToTestUndetectableAction( | 272 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
272 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | |
273 DCHECK(LastIsValid()); | 273 DCHECK(LastIsValid()); |
274 DCHECK(!Bytecodes::IsJump(node->bytecode())); | 274 DCHECK(!Bytecodes::IsJump(node->bytecode())); |
275 // Fused last and current into current. | 275 // Fused last and current into current. |
276 BytecodeNode new_node( | 276 BytecodeNode new_node(TransformEqualityWithNullOrUndefined( |
277 TransformEqualityWithNullOrUndefinedToTestUndetectable(last(), node)); | 277 action_data->bytecode, last(), node)); |
278 SetLast(&new_node); | 278 SetLast(&new_node); |
279 } | 279 } |
280 | 280 |
281 void BytecodePeepholeOptimizer::DefaultJumpAction( | 281 void BytecodePeepholeOptimizer::DefaultJumpAction( |
282 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | 282 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
283 DCHECK(LastIsValid()); | 283 DCHECK(LastIsValid()); |
284 DCHECK(Bytecodes::IsJump(node->bytecode())); | 284 DCHECK(Bytecodes::IsJump(node->bytecode())); |
285 | 285 |
286 next_stage()->Write(last()); | 286 next_stage()->Write(last()); |
287 InvalidateLast(); | 287 InvalidateLast(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 #undef CASE | 333 #undef CASE |
334 default: | 334 default: |
335 UNREACHABLE(); | 335 UNREACHABLE(); |
336 break; | 336 break; |
337 } | 337 } |
338 } | 338 } |
339 | 339 |
340 } // namespace interpreter | 340 } // namespace interpreter |
341 } // namespace internal | 341 } // namespace internal |
342 } // namespace v8 | 342 } // namespace v8 |
OLD | NEW |