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" |
8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 | 10 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 DCHECK(LastIsValid()); | 214 DCHECK(LastIsValid()); |
215 DCHECK(!Bytecodes::IsJump(node->bytecode())); | 215 DCHECK(!Bytecodes::IsJump(node->bytecode())); |
216 | 216 |
217 if (last()->operand(0) == node->operand(0)) { | 217 if (last()->operand(0) == node->operand(0)) { |
218 ElideCurrentAction(node); | 218 ElideCurrentAction(node); |
219 } else { | 219 } else { |
220 DefaultAction(node); | 220 DefaultAction(node); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 void BytecodePeepholeOptimizer::ElideCurrentIfLoadingNameConstantAction( | |
225 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | |
226 DCHECK_EQ(last()->bytecode(), Bytecode::kLdaConstant); | |
227 DCHECK(!Bytecodes::IsJump(node->bytecode())); | |
228 | |
229 if (GetConstantForIndexOperand(last(), 0)->IsName()) { | |
230 ElideCurrentAction(node); | |
231 } else { | |
232 DefaultAction(node); | |
233 } | |
234 } | |
235 | |
236 void BytecodePeepholeOptimizer::ElideLastAction( | 224 void BytecodePeepholeOptimizer::ElideLastAction( |
237 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | 225 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
238 DCHECK(LastIsValid()); | 226 DCHECK(LastIsValid()); |
239 DCHECK(!Bytecodes::IsJump(node->bytecode())); | 227 DCHECK(!Bytecodes::IsJump(node->bytecode())); |
240 | 228 |
241 if (CanElideLastBasedOnSourcePosition(node)) { | 229 if (CanElideLastBasedOnSourcePosition(node)) { |
242 if (last()->source_info().is_valid()) { | 230 if (last()->source_info().is_valid()) { |
243 // |node| can not have a valid source position if the source | 231 // |node| can not have a valid source position if the source |
244 // position of last() is valid (per rules in | 232 // position of last() is valid (per rules in |
245 // CanElideLastBasedOnSourcePosition()). | 233 // CanElideLastBasedOnSourcePosition()). |
246 node->source_info().Clone(last()->source_info()); | 234 node->source_info().Clone(last()->source_info()); |
247 } | 235 } |
248 SetLast(node); | 236 SetLast(node); |
249 } else { | 237 } else { |
250 DefaultAction(node); | 238 DefaultAction(node); |
251 } | 239 } |
252 } | 240 } |
253 | 241 |
254 void BytecodePeepholeOptimizer::ChangeBytecodeAction( | 242 void BytecodePeepholeOptimizer::ChangeBytecodeAction( |
255 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | 243 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
256 DCHECK(LastIsValid()); | 244 DCHECK(LastIsValid()); |
257 DCHECK(!Bytecodes::IsJump(node->bytecode())); | 245 DCHECK(!Bytecodes::IsJump(node->bytecode())); |
258 | 246 |
259 node->set_bytecode(action_data->bytecode); | 247 node->replace_bytecode(action_data->bytecode); |
260 DefaultAction(node); | 248 DefaultAction(node); |
261 } | 249 } |
262 | 250 |
263 void BytecodePeepholeOptimizer::TransformLdaStarToLdrLdarAction( | 251 void BytecodePeepholeOptimizer::TransformLdaStarToLdrLdarAction( |
264 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | 252 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
265 DCHECK(LastIsValid()); | 253 DCHECK(LastIsValid()); |
266 DCHECK(!Bytecodes::IsJump(node->bytecode())); | 254 DCHECK(!Bytecodes::IsJump(node->bytecode())); |
267 | 255 |
268 if (!node->source_info().is_statement()) { | 256 if (!node->source_info().is_statement()) { |
269 TransformLdaStarToLdrLdar(action_data->bytecode, last(), node); | 257 TransformLdaStarToLdrLdar(action_data->bytecode, last(), node); |
(...skipping 24 matching lines...) Expand all Loading... |
294 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) { | 282 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) { |
295 // Fused last and current into current. | 283 // Fused last and current into current. |
296 TransformLdaZeroBinaryOpToBinaryOpWithZero(action_data->bytecode, last(), | 284 TransformLdaZeroBinaryOpToBinaryOpWithZero(action_data->bytecode, last(), |
297 node); | 285 node); |
298 SetLast(node); | 286 SetLast(node); |
299 } else { | 287 } else { |
300 DefaultAction(node); | 288 DefaultAction(node); |
301 } | 289 } |
302 } | 290 } |
303 | 291 |
| 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 if (GetConstantForIndexOperand(last(), 0)->IsName()) { |
| 298 node->replace_bytecode(Bytecode::kStar); |
| 299 } |
| 300 DefaultAction(node); |
| 301 } |
| 302 |
304 void BytecodePeepholeOptimizer::DefaultJumpAction( | 303 void BytecodePeepholeOptimizer::DefaultJumpAction( |
305 BytecodeNode* const node, const PeepholeActionAndData* action_data) { | 304 BytecodeNode* const node, const PeepholeActionAndData* action_data) { |
306 DCHECK(LastIsValid()); | 305 DCHECK(LastIsValid()); |
307 DCHECK(Bytecodes::IsJump(node->bytecode())); | 306 DCHECK(Bytecodes::IsJump(node->bytecode())); |
308 | 307 |
309 next_stage()->Write(last()); | 308 next_stage()->Write(last()); |
310 InvalidateLast(); | 309 InvalidateLast(); |
311 } | 310 } |
312 | 311 |
313 void BytecodePeepholeOptimizer::UpdateLastJumpAction( | 312 void BytecodePeepholeOptimizer::UpdateLastJumpAction( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 #undef CASE | 356 #undef CASE |
358 default: | 357 default: |
359 UNREACHABLE(); | 358 UNREACHABLE(); |
360 break; | 359 break; |
361 } | 360 } |
362 } | 361 } |
363 | 362 |
364 } // namespace interpreter | 363 } // namespace interpreter |
365 } // namespace internal | 364 } // namespace internal |
366 } // namespace v8 | 365 } // namespace v8 |
OLD | NEW |