| 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/compiler/frame-elider.h" |
| 5 #include "src/base/adapters.h" | 6 #include "src/base/adapters.h" |
| 6 #include "src/compiler/frame-elider.h" | 7 #include "src/compiler/linkage.h" |
| 7 | 8 |
| 8 namespace v8 { | 9 namespace v8 { |
| 9 namespace internal { | 10 namespace internal { |
| 10 namespace compiler { | 11 namespace compiler { |
| 11 | 12 |
| 12 FrameElider::FrameElider(InstructionSequence* code) : code_(code) {} | 13 FrameElider::FrameElider(InstructionSequence* code) : code_(code) {} |
| 13 | 14 |
| 14 void FrameElider::Run() { | 15 void FrameElider::Run(const CallDescriptor* descriptor) { |
| 15 MarkBlocks(); | 16 MarkBlocks(); |
| 16 PropagateMarks(); | 17 PropagateMarks(); |
| 17 MarkDeConstruction(); | 18 MarkDeConstruction(); |
| 18 } | 19 } |
| 19 | 20 |
| 21 bool IsDeoptimize(const Instruction* instr) { |
| 22 return instr->arch_opcode() == ArchOpcode::kArchDeoptimize || |
| 23 FlagsModeField::decode(instr->opcode()) == kFlags_deoptimize; |
| 24 } |
| 20 | 25 |
| 21 void FrameElider::MarkBlocks() { | 26 void FrameElider::MarkBlocks() { |
| 22 for (InstructionBlock* block : instruction_blocks()) { | 27 for (InstructionBlock* block : instruction_blocks()) { |
| 23 if (block->needs_frame()) continue; | 28 if (block->needs_frame()) continue; |
| 24 for (int i = block->code_start(); i < block->code_end(); ++i) { | 29 for (int i = block->code_start(); i < block->code_end(); ++i) { |
| 25 if (InstructionAt(i)->IsCall() || | 30 if (InstructionAt(i)->IsCall() || IsDeoptimize(InstructionAt(i)) || |
| 26 InstructionAt(i)->opcode() == ArchOpcode::kArchDeoptimize) { | 31 InstructionAt(i)->arch_opcode() == ArchOpcode::kArchStackPointer) { |
| 27 block->mark_needs_frame(); | 32 block->mark_needs_frame(); |
| 28 break; | 33 break; |
| 29 } | 34 } |
| 30 } | 35 } |
| 31 } | 36 } |
| 32 } | 37 } |
| 33 | 38 |
| 34 | 39 |
| 35 void FrameElider::PropagateMarks() { | 40 void FrameElider::PropagateMarks() { |
| 36 while (PropagateInOrder() && PropagateReversed()) { | 41 while (PropagateInOrder() || PropagateReversed()) { |
| 37 } | 42 } |
| 38 } | 43 } |
| 39 | 44 |
| 40 | 45 |
| 41 void FrameElider::MarkDeConstruction() { | 46 void FrameElider::MarkDeConstruction() { |
| 42 for (InstructionBlock* block : instruction_blocks()) { | 47 for (InstructionBlock* block : instruction_blocks()) { |
| 43 if (block->needs_frame()) { | 48 if (block->needs_frame()) { |
| 44 // Special case: The start block needs a frame. | 49 // Special case: The start block needs a frame. |
| 45 if (block->predecessors().empty()) { | 50 if (block->predecessors().empty()) { |
| 46 block->mark_must_construct_frame(); | 51 block->mark_must_construct_frame(); |
| 47 } | 52 } |
| 48 // Find "frame -> no frame" transitions, inserting frame | 53 // Find "frame -> no frame" transitions, inserting frame |
| 49 // deconstructions. | 54 // deconstructions. |
| 55 // TODO(mtrofin): we currently have to deal with deferred blocks |
| 56 // that branch to deferred on non-deferred blocks, and when |
| 57 // the deferred path continues to need a frame, while the non-deferred |
| 58 // one doesn't. To avoid penalizing the non-deferred path with the cost of |
| 59 // deconstruction, we deconstruct and reconstruct on the deferred path. |
| 60 // This is a bit hacky and inefficient (code size). Alternatively, we |
| 61 // should insert a deferred block on the edge between the deferred block |
| 62 // and the non-deferred one, so we may insert there the deconstruction. |
| 63 bool makes_switch = false; |
| 50 for (RpoNumber& succ : block->successors()) { | 64 for (RpoNumber& succ : block->successors()) { |
| 51 if (!InstructionBlockAt(succ)->needs_frame()) { | 65 if (!InstructionBlockAt(succ)->needs_frame()) { |
| 52 DCHECK_EQ(1U, block->SuccessorCount()); | 66 makes_switch = true; |
| 53 block->mark_must_deconstruct_frame(); | 67 break; |
| 68 } |
| 69 } |
| 70 if (!makes_switch) continue; |
| 71 |
| 72 ArchOpcode last_opcode = |
| 73 code_->InstructionAt(block->last_instruction_index())->arch_opcode(); |
| 74 if (last_opcode == kArchThrowTerminator || |
| 75 IsDeoptimize(code_->InstructionAt(block->last_instruction_index()))) { |
| 76 continue; |
| 77 } |
| 78 block->mark_must_deconstruct_frame(); |
| 79 if (block->SuccessorCount() > 1) { |
| 80 for (RpoNumber& succ : block->successors()) { |
| 81 InstructionBlock* succ_block = InstructionBlockAt(succ); |
| 82 if (succ_block->needs_frame() && succ_block->IsDeferred()) { |
| 83 succ_block->mark_must_construct_frame(); |
| 84 } |
| 85 DCHECK_IMPLIES(!succ_block->IsDeferred(), !succ_block->needs_frame()); |
| 54 } | 86 } |
| 55 } | 87 } |
| 56 } else { | 88 } else { |
| 57 // Find "no frame -> frame" transitions, inserting frame constructions. | 89 // Find "no frame -> frame" transitions, inserting frame constructions. |
| 58 for (RpoNumber& succ : block->successors()) { | 90 for (RpoNumber& succ : block->successors()) { |
| 59 if (InstructionBlockAt(succ)->needs_frame()) { | 91 if (InstructionBlockAt(succ)->needs_frame()) { |
| 60 DCHECK_NE(1U, block->SuccessorCount()); | 92 DCHECK_NE(1U, block->SuccessorCount()); |
| 61 InstructionBlockAt(succ)->mark_must_construct_frame(); | 93 InstructionBlockAt(succ)->mark_must_construct_frame(); |
| 62 } | 94 } |
| 63 } | 95 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 154 } |
| 123 | 155 |
| 124 | 156 |
| 125 Instruction* FrameElider::InstructionAt(int index) const { | 157 Instruction* FrameElider::InstructionAt(int index) const { |
| 126 return code_->InstructionAt(index); | 158 return code_->InstructionAt(index); |
| 127 } | 159 } |
| 128 | 160 |
| 129 } // namespace compiler | 161 } // namespace compiler |
| 130 } // namespace internal | 162 } // namespace internal |
| 131 } // namespace v8 | 163 } // namespace v8 |
| OLD | NEW |