OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 void HGlobalValueNumberingPhase::ComputeBlockSideEffects() { | 389 void HGlobalValueNumberingPhase::ComputeBlockSideEffects() { |
390 // The Analyze phase of GVN can be called multiple times. Clear loop side | 390 // The Analyze phase of GVN can be called multiple times. Clear loop side |
391 // effects before computing them to erase the contents from previous Analyze | 391 // effects before computing them to erase the contents from previous Analyze |
392 // passes. | 392 // passes. |
393 for (int i = 0; i < loop_side_effects_.length(); ++i) { | 393 for (int i = 0; i < loop_side_effects_.length(); ++i) { |
394 loop_side_effects_[i].RemoveAll(); | 394 loop_side_effects_[i].RemoveAll(); |
395 } | 395 } |
396 for (int i = graph()->blocks()->length() - 1; i >= 0; --i) { | 396 for (int i = graph()->blocks()->length() - 1; i >= 0; --i) { |
397 // Compute side effects for the block. | 397 // Compute side effects for the block. |
398 HBasicBlock* block = graph()->blocks()->at(i); | 398 HBasicBlock* block = graph()->blocks()->at(i); |
399 int id = block->block_id(); | |
400 GVNFlagSet side_effects; | 399 GVNFlagSet side_effects; |
401 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { | 400 if (block->IsReachable() && !block->IsDeoptimizing()) { |
402 HInstruction* instr = it.Current(); | 401 int id = block->block_id(); |
403 side_effects.Add(instr->ChangesFlags()); | 402 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { |
404 if (instr->IsDeoptimize()) { | 403 HInstruction* instr = it.Current(); |
405 block_side_effects_[id].RemoveAll(); | 404 side_effects.Add(instr->ChangesFlags()); |
406 side_effects.RemoveAll(); | |
407 break; | |
408 } | 405 } |
409 } | 406 block_side_effects_[id].Add(side_effects); |
410 block_side_effects_[id].Add(side_effects); | |
411 | 407 |
412 // Loop headers are part of their loop. | 408 // Loop headers are part of their loop. |
413 if (block->IsLoopHeader()) { | 409 if (block->IsLoopHeader()) { |
414 loop_side_effects_[id].Add(side_effects); | 410 loop_side_effects_[id].Add(side_effects); |
415 } | 411 } |
416 | 412 |
417 // Propagate loop side effects upwards. | 413 // Propagate loop side effects upwards. |
418 if (block->HasParentLoopHeader()) { | 414 if (block->HasParentLoopHeader()) { |
419 int header_id = block->parent_loop_header()->block_id(); | 415 int header_id = block->parent_loop_header()->block_id(); |
420 loop_side_effects_[header_id].Add(block->IsLoopHeader() | 416 loop_side_effects_[header_id].Add(block->IsLoopHeader() |
421 ? loop_side_effects_[id] | 417 ? loop_side_effects_[id] |
422 : side_effects); | 418 : side_effects); |
| 419 } |
423 } | 420 } |
424 } | 421 } |
425 } | 422 } |
426 | 423 |
427 | 424 |
428 SmartArrayPointer<char> GetGVNFlagsString(GVNFlagSet flags) { | 425 SmartArrayPointer<char> GetGVNFlagsString(GVNFlagSet flags) { |
429 char underlying_buffer[kLastFlag * 128]; | 426 char underlying_buffer[kLastFlag * 128]; |
430 Vector<char> buffer(underlying_buffer, sizeof(underlying_buffer)); | 427 Vector<char> buffer(underlying_buffer, sizeof(underlying_buffer)); |
431 #if DEBUG | 428 #if DEBUG |
432 int offset = 0; | 429 int offset = 0; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 599 |
603 bool HGlobalValueNumberingPhase::AllowCodeMotion() { | 600 bool HGlobalValueNumberingPhase::AllowCodeMotion() { |
604 return info()->IsStub() || info()->opt_count() + 1 < FLAG_max_opt_count; | 601 return info()->IsStub() || info()->opt_count() + 1 < FLAG_max_opt_count; |
605 } | 602 } |
606 | 603 |
607 | 604 |
608 bool HGlobalValueNumberingPhase::ShouldMove(HInstruction* instr, | 605 bool HGlobalValueNumberingPhase::ShouldMove(HInstruction* instr, |
609 HBasicBlock* loop_header) { | 606 HBasicBlock* loop_header) { |
610 // If we've disabled code motion or we're in a block that unconditionally | 607 // If we've disabled code motion or we're in a block that unconditionally |
611 // deoptimizes, don't move any instructions. | 608 // deoptimizes, don't move any instructions. |
612 return AllowCodeMotion() && !instr->block()->IsDeoptimizing(); | 609 return AllowCodeMotion() && !instr->block()->IsDeoptimizing() && |
| 610 instr->block()->IsReachable(); |
613 } | 611 } |
614 | 612 |
615 | 613 |
616 GVNFlagSet | 614 GVNFlagSet |
617 HGlobalValueNumberingPhase::CollectSideEffectsOnPathsToDominatedBlock( | 615 HGlobalValueNumberingPhase::CollectSideEffectsOnPathsToDominatedBlock( |
618 HBasicBlock* dominator, HBasicBlock* dominated) { | 616 HBasicBlock* dominator, HBasicBlock* dominated) { |
619 GVNFlagSet side_effects; | 617 GVNFlagSet side_effects; |
620 for (int i = 0; i < dominated->predecessors()->length(); ++i) { | 618 for (int i = 0; i < dominated->predecessors()->length(); ++i) { |
621 HBasicBlock* block = dominated->predecessors()->at(i); | 619 HBasicBlock* block = dominated->predecessors()->at(i); |
622 if (dominator->block_id() < block->block_id() && | 620 if (dominator->block_id() < block->block_id() && |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 dominated); | 844 dominated); |
847 successor_map->Kill(side_effects_on_all_paths); | 845 successor_map->Kill(side_effects_on_all_paths); |
848 successor_dominators->Kill(side_effects_on_all_paths); | 846 successor_dominators->Kill(side_effects_on_all_paths); |
849 } | 847 } |
850 } | 848 } |
851 current = next; | 849 current = next; |
852 } | 850 } |
853 } | 851 } |
854 | 852 |
855 } } // namespace v8::internal | 853 } } // namespace v8::internal |
OLD | NEW |