OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/code-generator.h" | 5 #include "src/compiler/code-generator.h" |
6 | 6 |
7 #include "src/address-map.h" | 7 #include "src/address-map.h" |
8 #include "src/compiler/code-generator-impl.h" | 8 #include "src/compiler/code-generator-impl.h" |
9 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
10 #include "src/compiler/pipeline.h" | 10 #include "src/compiler/pipeline.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 deoptimization_literals_(code->zone()), | 49 deoptimization_literals_(code->zone()), |
50 inlined_function_count_(0), | 50 inlined_function_count_(0), |
51 translations_(code->zone()), | 51 translations_(code->zone()), |
52 last_lazy_deopt_pc_(0), | 52 last_lazy_deopt_pc_(0), |
53 jump_tables_(nullptr), | 53 jump_tables_(nullptr), |
54 ools_(nullptr), | 54 ools_(nullptr), |
55 osr_pc_offset_(-1) { | 55 osr_pc_offset_(-1) { |
56 for (int i = 0; i < code->InstructionBlockCount(); ++i) { | 56 for (int i = 0; i < code->InstructionBlockCount(); ++i) { |
57 new (&labels_[i]) Label; | 57 new (&labels_[i]) Label; |
58 } | 58 } |
59 if (code->ContainsCall()) { | |
60 frame->MarkNeedsFrame(); | |
61 } | |
62 } | 59 } |
63 | 60 |
64 | |
65 Handle<Code> CodeGenerator::GenerateCode() { | 61 Handle<Code> CodeGenerator::GenerateCode() { |
66 CompilationInfo* info = this->info(); | 62 CompilationInfo* info = this->info(); |
67 | 63 |
68 // Open a frame scope to indicate that there is a frame on the stack. The | 64 // Open a frame scope to indicate that there is a frame on the stack. The |
69 // MANUAL indicates that the scope shouldn't actually generate code to set up | 65 // MANUAL indicates that the scope shouldn't actually generate code to set up |
70 // the frame (that is done in AssemblePrologue). | 66 // the frame (that is done in AssemblePrologue). |
71 FrameScope frame_scope(masm(), StackFrame::MANUAL); | 67 FrameScope frame_scope(masm(), StackFrame::MANUAL); |
72 | 68 |
73 // Emit a code line info recording start event. | 69 // Emit a code line info recording start event. |
74 PositionsRecorder* recorder = masm()->positions_recorder(); | 70 PositionsRecorder* recorder = masm()->positions_recorder(); |
75 LOG_CODE_EVENT(isolate(), CodeStartLinePosInfoRecordEvent(recorder)); | 71 LOG_CODE_EVENT(isolate(), CodeStartLinePosInfoRecordEvent(recorder)); |
76 | 72 |
77 // Place function entry hook if requested to do so. | 73 // Place function entry hook if requested to do so. |
78 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { | 74 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { |
79 ProfileEntryHookStub::MaybeCallEntryHook(masm()); | 75 ProfileEntryHookStub::MaybeCallEntryHook(masm()); |
80 } | 76 } |
81 // Architecture-specific, linkage-specific prologue. | 77 // Architecture-specific, linkage-specific prologue. |
82 info->set_prologue_offset(masm()->pc_offset()); | 78 info->set_prologue_offset(masm()->pc_offset()); |
83 AssemblePrologue(); | |
84 if (linkage()->GetIncomingDescriptor()->InitializeRootRegister()) { | |
85 masm()->InitializeRootRegister(); | |
86 } | |
87 | 79 |
88 // Define deoptimization literals for all inlined functions. | 80 // Define deoptimization literals for all inlined functions. |
89 DCHECK_EQ(0u, deoptimization_literals_.size()); | 81 DCHECK_EQ(0u, deoptimization_literals_.size()); |
90 for (const CompilationInfo::InlinedFunctionHolder& inlined : | 82 for (const CompilationInfo::InlinedFunctionHolder& inlined : |
91 info->inlined_functions()) { | 83 info->inlined_functions()) { |
92 if (!inlined.shared_info.is_identical_to(info->shared_info())) { | 84 if (!inlined.shared_info.is_identical_to(info->shared_info())) { |
93 DefineDeoptimizationLiteral(inlined.shared_info); | 85 DefineDeoptimizationLiteral(inlined.shared_info); |
94 } | 86 } |
95 } | 87 } |
96 inlined_function_count_ = deoptimization_literals_.size(); | 88 inlined_function_count_ = deoptimization_literals_.size(); |
97 | 89 |
98 // Define deoptimization literals for all unoptimized code objects of inlined | 90 // Define deoptimization literals for all unoptimized code objects of inlined |
99 // functions. This ensures unoptimized code is kept alive by optimized code. | 91 // functions. This ensures unoptimized code is kept alive by optimized code. |
100 for (const CompilationInfo::InlinedFunctionHolder& inlined : | 92 for (const CompilationInfo::InlinedFunctionHolder& inlined : |
101 info->inlined_functions()) { | 93 info->inlined_functions()) { |
102 if (!inlined.shared_info.is_identical_to(info->shared_info())) { | 94 if (!inlined.shared_info.is_identical_to(info->shared_info())) { |
103 DefineDeoptimizationLiteral(inlined.inlined_code_object_root); | 95 DefineDeoptimizationLiteral(inlined.inlined_code_object_root); |
104 } | 96 } |
105 } | 97 } |
106 | 98 |
| 99 // Finish the Frame |
| 100 frame()->AlignFrame(kFrameAlignmentInBytes); |
| 101 AssembleSetupStackPointer(); |
107 // Assemble all non-deferred blocks, followed by deferred ones. | 102 // Assemble all non-deferred blocks, followed by deferred ones. |
108 for (int deferred = 0; deferred < 2; ++deferred) { | 103 for (int deferred = 0; deferred < 2; ++deferred) { |
109 for (const InstructionBlock* block : code()->instruction_blocks()) { | 104 for (const InstructionBlock* block : code()->instruction_blocks()) { |
110 if (block->IsDeferred() == (deferred == 0)) { | 105 if (block->IsDeferred() == (deferred == 0)) { |
111 continue; | 106 continue; |
112 } | 107 } |
113 // Align loop headers on 16-byte boundaries. | 108 // Align loop headers on 16-byte boundaries. |
114 if (block->IsLoopHeader()) masm()->Align(16); | 109 if (block->IsLoopHeader()) masm()->Align(16); |
115 // Ensure lazy deopt doesn't patch handler entry points. | 110 // Ensure lazy deopt doesn't patch handler entry points. |
116 if (block->IsHandler()) EnsureSpaceForLazyDeopt(); | 111 if (block->IsHandler()) EnsureSpaceForLazyDeopt(); |
(...skipping 19 matching lines...) Expand all Loading... |
136 buffer = buffer.SubVector(next, buffer.length()); | 131 buffer = buffer.SubVector(next, buffer.length()); |
137 } | 132 } |
138 if (block->loop_header().IsValid()) { | 133 if (block->loop_header().IsValid()) { |
139 next = | 134 next = |
140 SNPrintF(buffer, " (in loop %d)", block->loop_header().ToInt()); | 135 SNPrintF(buffer, " (in loop %d)", block->loop_header().ToInt()); |
141 buffer = buffer.SubVector(next, buffer.length()); | 136 buffer = buffer.SubVector(next, buffer.length()); |
142 } | 137 } |
143 SNPrintF(buffer, " --"); | 138 SNPrintF(buffer, " --"); |
144 masm()->RecordComment(buffer_start); | 139 masm()->RecordComment(buffer_start); |
145 } | 140 } |
| 141 |
| 142 frame_access_state()->MarkHasFrame(block->needs_frame()); |
| 143 |
146 masm()->bind(GetLabel(current_block_)); | 144 masm()->bind(GetLabel(current_block_)); |
| 145 if (block->must_construct_frame()) { |
| 146 AssemblePrologue(); |
| 147 // We need to setup the root register after we assemble the prologue, to |
| 148 // avoid clobbering callee saved registers in case of C linkage and |
| 149 // using the roots. |
| 150 // TODO(mtrofin): investigate how we can avoid doing this repeatedly. |
| 151 if (linkage()->GetIncomingDescriptor()->InitializeRootRegister()) { |
| 152 masm()->InitializeRootRegister(); |
| 153 } |
| 154 } |
| 155 |
147 for (int i = block->code_start(); i < block->code_end(); ++i) { | 156 for (int i = block->code_start(); i < block->code_end(); ++i) { |
148 AssembleInstruction(code()->InstructionAt(i)); | 157 Instruction* instr = code()->InstructionAt(i); |
| 158 AssembleInstruction(instr, block); |
149 } | 159 } |
150 } | 160 } |
151 } | 161 } |
152 | 162 |
153 // Assemble all out-of-line code. | 163 // Assemble all out-of-line code. |
154 if (ools_) { | 164 if (ools_) { |
155 masm()->RecordComment("-- Out of line code --"); | 165 masm()->RecordComment("-- Out of line code --"); |
156 for (OutOfLineCode* ool = ools_; ool; ool = ool->next()) { | 166 for (OutOfLineCode* ool = ools_; ool; ool = ool->next()) { |
157 masm()->bind(ool->entry()); | 167 masm()->bind(ool->entry()); |
158 ool->Generate(); | 168 ool->Generate(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 RootIndexMap map(isolate()); | 293 RootIndexMap map(isolate()); |
284 int root_index = map.Lookup(*object); | 294 int root_index = map.Lookup(*object); |
285 if (root_index != RootIndexMap::kInvalidRootIndex) { | 295 if (root_index != RootIndexMap::kInvalidRootIndex) { |
286 *index_return = static_cast<Heap::RootListIndex>(root_index); | 296 *index_return = static_cast<Heap::RootListIndex>(root_index); |
287 return true; | 297 return true; |
288 } | 298 } |
289 } | 299 } |
290 return false; | 300 return false; |
291 } | 301 } |
292 | 302 |
293 | 303 void CodeGenerator::AssembleInstruction(Instruction* instr, |
294 void CodeGenerator::AssembleInstruction(Instruction* instr) { | 304 const InstructionBlock* block) { |
295 AssembleGaps(instr); | 305 AssembleGaps(instr); |
| 306 if (instr->IsJump() && block->must_deconstruct_frame()) { |
| 307 AssembleDeconstructFrame(); |
| 308 } |
296 AssembleSourcePosition(instr); | 309 AssembleSourcePosition(instr); |
297 // Assemble architecture-specific code for the instruction. | 310 // Assemble architecture-specific code for the instruction. |
298 AssembleArchInstruction(instr); | 311 AssembleArchInstruction(instr); |
299 | 312 |
300 FlagsMode mode = FlagsModeField::decode(instr->opcode()); | 313 FlagsMode mode = FlagsModeField::decode(instr->opcode()); |
301 FlagsCondition condition = FlagsConditionField::decode(instr->opcode()); | 314 FlagsCondition condition = FlagsConditionField::decode(instr->opcode()); |
302 switch (mode) { | 315 switch (mode) { |
303 case kFlags_branch: { | 316 case kFlags_branch: { |
304 // Assemble a branch after this instruction. | 317 // Assemble a branch after this instruction. |
305 InstructionOperandConverter i(this, instr); | 318 InstructionOperandConverter i(this, instr); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 Instruction* instr, size_t frame_state_offset) { | 767 Instruction* instr, size_t frame_state_offset) { |
755 int const deoptimization_id = BuildTranslation( | 768 int const deoptimization_id = BuildTranslation( |
756 instr, -1, frame_state_offset, OutputFrameStateCombine::Ignore()); | 769 instr, -1, frame_state_offset, OutputFrameStateCombine::Ignore()); |
757 DeoptimizationExit* const exit = | 770 DeoptimizationExit* const exit = |
758 new (zone()) DeoptimizationExit(deoptimization_id); | 771 new (zone()) DeoptimizationExit(deoptimization_id); |
759 deoptimization_exits_.push_back(exit); | 772 deoptimization_exits_.push_back(exit); |
760 return exit; | 773 return exit; |
761 } | 774 } |
762 | 775 |
763 int CodeGenerator::TailCallFrameStackSlotDelta(int stack_param_delta) { | 776 int CodeGenerator::TailCallFrameStackSlotDelta(int stack_param_delta) { |
764 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | |
765 int spill_slots = frame()->GetSpillSlotCount(); | |
766 bool has_frame = descriptor->IsJSFunctionCall() || spill_slots > 0; | |
767 // Leave the PC on the stack on platforms that have that as part of their ABI | 777 // Leave the PC on the stack on platforms that have that as part of their ABI |
768 int pc_slots = V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK ? 1 : 0; | 778 int pc_slots = V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK ? 1 : 0; |
769 int sp_slot_delta = | 779 int sp_slot_delta = frame_access_state()->has_frame() |
770 has_frame ? (frame()->GetTotalFrameSlotCount() - pc_slots) : 0; | 780 ? (frame()->GetTotalFrameSlotCount() - pc_slots) |
| 781 : 0; |
771 // Discard only slots that won't be used by new parameters. | 782 // Discard only slots that won't be used by new parameters. |
772 sp_slot_delta += stack_param_delta; | 783 sp_slot_delta += stack_param_delta; |
773 return sp_slot_delta; | 784 return sp_slot_delta; |
774 } | 785 } |
775 | 786 |
776 | 787 |
777 OutOfLineCode::OutOfLineCode(CodeGenerator* gen) | 788 OutOfLineCode::OutOfLineCode(CodeGenerator* gen) |
778 : frame_(gen->frame()), masm_(gen->masm()), next_(gen->ools_) { | 789 : frame_(gen->frame()), masm_(gen->masm()), next_(gen->ools_) { |
779 gen->ools_ = this; | 790 gen->ools_ = this; |
780 } | 791 } |
781 | 792 |
782 | 793 |
783 OutOfLineCode::~OutOfLineCode() {} | 794 OutOfLineCode::~OutOfLineCode() {} |
784 | 795 |
785 } // namespace compiler | 796 } // namespace compiler |
786 } // namespace internal | 797 } // namespace internal |
787 } // namespace v8 | 798 } // namespace v8 |
OLD | NEW |