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