| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/base/adapters.h" | 5 #include "src/base/adapters.h" |
| 6 #include "src/compiler/frame-elider.h" | 6 #include "src/compiler/frame-elider.h" |
| 7 | 7 |
| 8 namespace v8 { | 8 namespace v8 { |
| 9 namespace internal { | 9 namespace internal { |
| 10 namespace compiler { | 10 namespace compiler { |
| 11 | 11 |
| 12 FrameElider::FrameElider(InstructionSequence* code) : code_(code) {} | 12 FrameElider::FrameElider(InstructionSequence* code) : code_(code) {} |
| 13 | 13 |
| 14 void FrameElider::Run() { | 14 void FrameElider::Run() { |
| 15 MarkBlocks(); | 15 MarkBlocks(); |
| 16 PropagateMarks(); | 16 PropagateMarks(); |
| 17 MarkDeConstruction(); | 17 MarkDeConstruction(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 | |
| 21 void FrameElider::MarkBlocks() { | 20 void FrameElider::MarkBlocks() { |
| 22 for (InstructionBlock* block : instruction_blocks()) { | 21 for (InstructionBlock* block : instruction_blocks()) { |
| 23 if (block->needs_frame()) continue; | 22 if (block->needs_frame()) continue; |
| 24 for (int i = block->code_start(); i < block->code_end(); ++i) { | 23 for (int i = block->code_start(); i < block->code_end(); ++i) { |
| 25 if (InstructionAt(i)->IsCall() || | 24 const Instruction* instr = InstructionAt(i); |
| 26 InstructionAt(i)->opcode() == ArchOpcode::kArchDeoptimize) { | 25 if (instr->IsCall() || instr->IsDeoptimizeCall() || |
| 26 instr->arch_opcode() == ArchOpcode::kArchStackPointer) { |
| 27 block->mark_needs_frame(); | 27 block->mark_needs_frame(); |
| 28 break; | 28 break; |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 | 34 |
| 35 void FrameElider::PropagateMarks() { | 35 void FrameElider::PropagateMarks() { |
| 36 while (PropagateInOrder() || PropagateReversed()) { | 36 while (PropagateInOrder() || PropagateReversed()) { |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 | 40 |
| 41 void FrameElider::MarkDeConstruction() { | 41 void FrameElider::MarkDeConstruction() { |
| 42 for (InstructionBlock* block : instruction_blocks()) { | 42 for (InstructionBlock* block : instruction_blocks()) { |
| 43 if (block->needs_frame()) { | 43 if (block->needs_frame()) { |
| 44 // Special case: The start block needs a frame. | 44 // Special case: The start block needs a frame. |
| 45 if (block->predecessors().empty()) { | 45 if (block->predecessors().empty()) { |
| 46 block->mark_must_construct_frame(); | 46 block->mark_must_construct_frame(); |
| 47 } | 47 } |
| 48 // Find "frame -> no frame" transitions, inserting frame | 48 // Find "frame -> no frame" transitions, inserting frame |
| 49 // deconstructions. | 49 // deconstructions. |
| 50 for (RpoNumber& succ : block->successors()) { | 50 for (RpoNumber& succ : block->successors()) { |
| 51 if (!InstructionBlockAt(succ)->needs_frame()) { | 51 if (!InstructionBlockAt(succ)->needs_frame()) { |
| 52 DCHECK_EQ(1U, block->SuccessorCount()); | 52 DCHECK_EQ(1U, block->SuccessorCount()); |
| 53 const Instruction* last = |
| 54 InstructionAt(block->last_instruction_index()); |
| 55 if (last->IsThrow() || last->IsTailCall() || |
| 56 last->IsDeoptimizeCall()) { |
| 57 // We need to keep the frame if we exit the block through any |
| 58 // of these. |
| 59 continue; |
| 60 } |
| 61 // The only cases when we need to deconstruct are ret and jump. |
| 62 DCHECK(last->IsRet() || last->IsJump()); |
| 53 block->mark_must_deconstruct_frame(); | 63 block->mark_must_deconstruct_frame(); |
| 54 } | 64 } |
| 55 } | 65 } |
| 56 } else { | 66 } else { |
| 57 // Find "no frame -> frame" transitions, inserting frame constructions. | 67 // Find "no frame -> frame" transitions, inserting frame constructions. |
| 58 for (RpoNumber& succ : block->successors()) { | 68 for (RpoNumber& succ : block->successors()) { |
| 59 if (InstructionBlockAt(succ)->needs_frame()) { | 69 if (InstructionBlockAt(succ)->needs_frame()) { |
| 60 DCHECK_NE(1U, block->SuccessorCount()); | 70 DCHECK_NE(1U, block->SuccessorCount()); |
| 61 InstructionBlockAt(succ)->mark_must_construct_frame(); | 71 InstructionBlockAt(succ)->mark_must_construct_frame(); |
| 62 } | 72 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 132 } |
| 123 | 133 |
| 124 | 134 |
| 125 Instruction* FrameElider::InstructionAt(int index) const { | 135 Instruction* FrameElider::InstructionAt(int index) const { |
| 126 return code_->InstructionAt(index); | 136 return code_->InstructionAt(index); |
| 127 } | 137 } |
| 128 | 138 |
| 129 } // namespace compiler | 139 } // namespace compiler |
| 130 } // namespace internal | 140 } // namespace internal |
| 131 } // namespace v8 | 141 } // namespace v8 |
| OLD | NEW |