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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 safepoints_(code->zone()), | 45 safepoints_(code->zone()), |
46 handlers_(code->zone()), | 46 handlers_(code->zone()), |
47 deoptimization_exits_(code->zone()), | 47 deoptimization_exits_(code->zone()), |
48 deoptimization_states_(code->zone()), | 48 deoptimization_states_(code->zone()), |
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 deconstruct_frame_when_leaving_(true), | |
57 deconstruct_frame_between_blocks_(false) { | |
56 for (int i = 0; i < code->InstructionBlockCount(); ++i) { | 58 for (int i = 0; i < code->InstructionBlockCount(); ++i) { |
57 new (&labels_[i]) Label; | 59 new (&labels_[i]) Label; |
58 } | 60 } |
59 if (code->ContainsCall()) { | 61 } |
60 frame->MarkNeedsFrame(); | 62 |
63 void CodeGenerator::SetupFrameAccessForBlock(const InstructionBlock* block) { | |
64 if (block->needs_frame()) { | |
65 frame_access_state()->SetFrameAccessToFP(); | |
66 frame_access_state()->set_used_frame_slots( | |
67 frame()->GetTotalFrameSlotCount()); | |
68 } else { | |
69 frame_access_state()->SetFrameAccessToSP(); | |
70 frame_access_state()->set_used_frame_slots(kElidedFrameSlots); | |
61 } | 71 } |
62 } | 72 } |
63 | 73 |
64 | |
65 Handle<Code> CodeGenerator::GenerateCode() { | 74 Handle<Code> CodeGenerator::GenerateCode() { |
66 CompilationInfo* info = this->info(); | 75 CompilationInfo* info = this->info(); |
67 | 76 |
68 // Open a frame scope to indicate that there is a frame on the stack. The | 77 // 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 | 78 // MANUAL indicates that the scope shouldn't actually generate code to set up |
70 // the frame (that is done in AssemblePrologue). | 79 // the frame (that is done in AssemblePrologue). |
71 FrameScope frame_scope(masm(), StackFrame::MANUAL); | 80 FrameScope frame_scope(masm(), StackFrame::MANUAL); |
72 | 81 |
73 // Emit a code line info recording start event. | 82 // Emit a code line info recording start event. |
74 PositionsRecorder* recorder = masm()->positions_recorder(); | 83 PositionsRecorder* recorder = masm()->positions_recorder(); |
75 LOG_CODE_EVENT(isolate(), CodeStartLinePosInfoRecordEvent(recorder)); | 84 LOG_CODE_EVENT(isolate(), CodeStartLinePosInfoRecordEvent(recorder)); |
76 | 85 |
77 // Place function entry hook if requested to do so. | 86 // Place function entry hook if requested to do so. |
78 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { | 87 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { |
79 ProfileEntryHookStub::MaybeCallEntryHook(masm()); | 88 ProfileEntryHookStub::MaybeCallEntryHook(masm()); |
80 } | 89 } |
81 // Architecture-specific, linkage-specific prologue. | 90 // Architecture-specific, linkage-specific prologue. |
82 info->set_prologue_offset(masm()->pc_offset()); | 91 info->set_prologue_offset(masm()->pc_offset()); |
83 AssemblePrologue(); | 92 // ARM64? |
93 // frame()->AlignFrame(16); | |
94 // SetupStackPointer(); | |
95 // | |
84 if (linkage()->GetIncomingDescriptor()->InitializeRootRegister()) { | 96 if (linkage()->GetIncomingDescriptor()->InitializeRootRegister()) { |
85 masm()->InitializeRootRegister(); | 97 masm()->InitializeRootRegister(); |
Mircea Trofin
2016/03/16 20:20:46
What's the root register? Seems like something tha
danno
2016/03/16 21:20:56
Nah, this is unrelated to the frame and should sta
Mircea Trofin
2016/03/16 21:51:00
it seems that Simulator::CheckPCSComplianceAndRun
| |
86 } | 98 } |
87 | 99 |
88 // Define deoptimization literals for all inlined functions. | 100 // Define deoptimization literals for all inlined functions. |
89 DCHECK_EQ(0u, deoptimization_literals_.size()); | 101 DCHECK_EQ(0u, deoptimization_literals_.size()); |
90 for (const CompilationInfo::InlinedFunctionHolder& inlined : | 102 for (const CompilationInfo::InlinedFunctionHolder& inlined : |
91 info->inlined_functions()) { | 103 info->inlined_functions()) { |
92 if (!inlined.shared_info.is_identical_to(info->shared_info())) { | 104 if (!inlined.shared_info.is_identical_to(info->shared_info())) { |
93 DefineDeoptimizationLiteral(inlined.shared_info); | 105 DefineDeoptimizationLiteral(inlined.shared_info); |
94 } | 106 } |
95 } | 107 } |
96 inlined_function_count_ = deoptimization_literals_.size(); | 108 inlined_function_count_ = deoptimization_literals_.size(); |
97 | 109 |
98 // Define deoptimization literals for all unoptimized code objects of inlined | 110 // Define deoptimization literals for all unoptimized code objects of inlined |
99 // functions. This ensures unoptimized code is kept alive by optimized code. | 111 // functions. This ensures unoptimized code is kept alive by optimized code. |
100 for (const CompilationInfo::InlinedFunctionHolder& inlined : | 112 for (const CompilationInfo::InlinedFunctionHolder& inlined : |
101 info->inlined_functions()) { | 113 info->inlined_functions()) { |
102 if (!inlined.shared_info.is_identical_to(info->shared_info())) { | 114 if (!inlined.shared_info.is_identical_to(info->shared_info())) { |
103 DefineDeoptimizationLiteral(inlined.inlined_code_object_root); | 115 DefineDeoptimizationLiteral(inlined.inlined_code_object_root); |
104 } | 116 } |
105 } | 117 } |
106 | |
107 // Assemble all non-deferred blocks, followed by deferred ones. | 118 // Assemble all non-deferred blocks, followed by deferred ones. |
108 for (int deferred = 0; deferred < 2; ++deferred) { | 119 for (int deferred = 0; deferred < 2; ++deferred) { |
109 for (const InstructionBlock* block : code()->instruction_blocks()) { | 120 for (const InstructionBlock* block : code()->instruction_blocks()) { |
110 if (block->IsDeferred() == (deferred == 0)) { | 121 if (block->IsDeferred() == (deferred == 0)) { |
111 continue; | 122 continue; |
112 } | 123 } |
113 // Align loop headers on 16-byte boundaries. | 124 // Align loop headers on 16-byte boundaries. |
114 if (block->IsLoopHeader()) masm()->Align(16); | 125 if (block->IsLoopHeader()) masm()->Align(16); |
115 // Ensure lazy deopt doesn't patch handler entry points. | 126 // Ensure lazy deopt doesn't patch handler entry points. |
116 if (block->IsHandler()) EnsureSpaceForLazyDeopt(); | 127 if (block->IsHandler()) EnsureSpaceForLazyDeopt(); |
(...skipping 19 matching lines...) Expand all Loading... | |
136 buffer = buffer.SubVector(next, buffer.length()); | 147 buffer = buffer.SubVector(next, buffer.length()); |
137 } | 148 } |
138 if (block->loop_header().IsValid()) { | 149 if (block->loop_header().IsValid()) { |
139 next = | 150 next = |
140 SNPrintF(buffer, " (in loop %d)", block->loop_header().ToInt()); | 151 SNPrintF(buffer, " (in loop %d)", block->loop_header().ToInt()); |
141 buffer = buffer.SubVector(next, buffer.length()); | 152 buffer = buffer.SubVector(next, buffer.length()); |
142 } | 153 } |
143 SNPrintF(buffer, " --"); | 154 SNPrintF(buffer, " --"); |
144 masm()->RecordComment(buffer_start); | 155 masm()->RecordComment(buffer_start); |
145 } | 156 } |
157 | |
158 SetupFrameAccessForBlock(block); | |
159 | |
146 masm()->bind(GetLabel(current_block_)); | 160 masm()->bind(GetLabel(current_block_)); |
161 if (block->must_construct_frame()) { | |
162 DCHECK(frame_access_state()->access_frame_with_fp()); | |
163 AssemblePrologue(); | |
164 } | |
165 set_deconstruct_frame_between_blocks(false); | |
166 set_deconstruct_frame_when_leaving(false); | |
167 | |
147 for (int i = block->code_start(); i < block->code_end(); ++i) { | 168 for (int i = block->code_start(); i < block->code_end(); ++i) { |
148 AssembleInstruction(code()->InstructionAt(i)); | 169 Instruction* instr = code()->InstructionAt(i); |
170 bool leaves_function = | |
danno
2016/03/16 18:18:11
This should not be calculated here. When the bloc
Mircea Trofin
2016/03/16 20:20:46
That makes sense, indeed. This is also a remnant o
| |
171 instr->arch_opcode() == ArchOpcode::kArchRet || | |
172 instr->arch_opcode() == ArchOpcode::kArchDeoptimize; | |
173 if (i == block->last_instruction_index()) { | |
174 set_deconstruct_frame_when_leaving(block->must_deconstruct_frame()); | |
175 set_deconstruct_frame_between_blocks(!leaves_function && | |
176 block->must_deconstruct_frame()); | |
177 } | |
178 AssembleInstruction(instr); | |
149 } | 179 } |
180 AssembleDeconstructFrameBetweenBlocks(); | |
150 } | 181 } |
151 } | 182 } |
152 | 183 |
153 // Assemble all out-of-line code. | 184 // Assemble all out-of-line code. |
154 if (ools_) { | 185 if (ools_) { |
155 masm()->RecordComment("-- Out of line code --"); | 186 masm()->RecordComment("-- Out of line code --"); |
156 for (OutOfLineCode* ool = ools_; ool; ool = ool->next()) { | 187 for (OutOfLineCode* ool = ools_; ool; ool = ool->next()) { |
157 masm()->bind(ool->entry()); | 188 masm()->bind(ool->entry()); |
158 ool->Generate(); | 189 ool->Generate(); |
159 if (ool->exit()->is_bound()) masm()->jmp(ool->exit()); | 190 if (ool->exit()->is_bound()) masm()->jmp(ool->exit()); |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 instr, -1, frame_state_offset, OutputFrameStateCombine::Ignore()); | 787 instr, -1, frame_state_offset, OutputFrameStateCombine::Ignore()); |
757 DeoptimizationExit* const exit = | 788 DeoptimizationExit* const exit = |
758 new (zone()) DeoptimizationExit(deoptimization_id); | 789 new (zone()) DeoptimizationExit(deoptimization_id); |
759 deoptimization_exits_.push_back(exit); | 790 deoptimization_exits_.push_back(exit); |
760 return exit; | 791 return exit; |
761 } | 792 } |
762 | 793 |
763 int CodeGenerator::TailCallFrameStackSlotDelta(int stack_param_delta) { | 794 int CodeGenerator::TailCallFrameStackSlotDelta(int stack_param_delta) { |
764 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 795 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
765 int spill_slots = frame()->GetSpillSlotCount(); | 796 int spill_slots = frame()->GetSpillSlotCount(); |
766 bool has_frame = descriptor->IsJSFunctionCall() || spill_slots > 0; | 797 bool has_frame = descriptor->IsJSFunctionCall() || spill_slots > 0; |
danno
2016/03/16 21:20:56
by the way, this will probably end up being
bool
| |
767 // Leave the PC on the stack on platforms that have that as part of their ABI | 798 // 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; | 799 int pc_slots = V8_TARGET_ARCH_STORES_RETURN_ADDRESS_ON_STACK ? 1 : 0; |
769 int sp_slot_delta = | 800 int sp_slot_delta = |
770 has_frame ? (frame()->GetTotalFrameSlotCount() - pc_slots) : 0; | 801 has_frame ? (frame_access_state()->used_frame_slots() - pc_slots) : 0; |
danno
2016/03/16 21:20:56
If you use frame_access_state->has_frame(), you ca
| |
771 // Discard only slots that won't be used by new parameters. | 802 // Discard only slots that won't be used by new parameters. |
772 sp_slot_delta += stack_param_delta; | 803 sp_slot_delta += stack_param_delta; |
773 return sp_slot_delta; | 804 return sp_slot_delta; |
774 } | 805 } |
775 | 806 |
776 | |
777 OutOfLineCode::OutOfLineCode(CodeGenerator* gen) | 807 OutOfLineCode::OutOfLineCode(CodeGenerator* gen) |
778 : frame_(gen->frame()), masm_(gen->masm()), next_(gen->ools_) { | 808 : frame_(gen->frame()), |
809 frame_access_state_(gen->frame_access_state()), | |
810 masm_(gen->masm()), | |
811 next_(gen->ools_) { | |
779 gen->ools_ = this; | 812 gen->ools_ = this; |
780 } | 813 } |
781 | 814 |
782 | 815 |
783 OutOfLineCode::~OutOfLineCode() {} | 816 OutOfLineCode::~OutOfLineCode() {} |
784 | 817 |
785 } // namespace compiler | 818 } // namespace compiler |
786 } // namespace internal | 819 } // namespace internal |
787 } // namespace v8 | 820 } // namespace v8 |
OLD | NEW |