| 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/compiler/code-generator-impl.h" | 7 #include "src/compiler/code-generator-impl.h" |
| 8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
| 9 #include "src/compiler/pipeline.h" | 9 #include "src/compiler/pipeline.h" |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 : frame_(frame), | 35 : frame_(frame), |
| 36 linkage_(linkage), | 36 linkage_(linkage), |
| 37 code_(code), | 37 code_(code), |
| 38 info_(info), | 38 info_(info), |
| 39 labels_(zone()->NewArray<Label>(code->InstructionBlockCount())), | 39 labels_(zone()->NewArray<Label>(code->InstructionBlockCount())), |
| 40 current_block_(BasicBlock::RpoNumber::Invalid()), | 40 current_block_(BasicBlock::RpoNumber::Invalid()), |
| 41 current_source_position_(SourcePosition::Invalid()), | 41 current_source_position_(SourcePosition::Invalid()), |
| 42 masm_(info->isolate(), NULL, 0), | 42 masm_(info->isolate(), NULL, 0), |
| 43 resolver_(this), | 43 resolver_(this), |
| 44 safepoints_(code->zone()), | 44 safepoints_(code->zone()), |
| 45 handlers_(code->zone()), |
| 45 deoptimization_states_(code->zone()), | 46 deoptimization_states_(code->zone()), |
| 46 deoptimization_literals_(code->zone()), | 47 deoptimization_literals_(code->zone()), |
| 47 translations_(code->zone()), | 48 translations_(code->zone()), |
| 48 last_lazy_deopt_pc_(0), | 49 last_lazy_deopt_pc_(0), |
| 49 jump_tables_(nullptr), | 50 jump_tables_(nullptr), |
| 50 ools_(nullptr), | 51 ools_(nullptr), |
| 51 osr_pc_offset_(-1) { | 52 osr_pc_offset_(-1) { |
| 52 for (int i = 0; i < code->InstructionBlockCount(); ++i) { | 53 for (int i = 0; i < code->InstructionBlockCount(); ++i) { |
| 53 new (&labels_[i]) Label; | 54 new (&labels_[i]) Label; |
| 54 } | 55 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 125 } |
| 125 | 126 |
| 126 safepoints()->Emit(masm(), frame()->GetSpillSlotCount()); | 127 safepoints()->Emit(masm(), frame()->GetSpillSlotCount()); |
| 127 | 128 |
| 128 Handle<Code> result = v8::internal::CodeGenerator::MakeCodeEpilogue( | 129 Handle<Code> result = v8::internal::CodeGenerator::MakeCodeEpilogue( |
| 129 masm(), info->flags(), info); | 130 masm(), info->flags(), info); |
| 130 result->set_is_turbofanned(true); | 131 result->set_is_turbofanned(true); |
| 131 result->set_stack_slots(frame()->GetSpillSlotCount()); | 132 result->set_stack_slots(frame()->GetSpillSlotCount()); |
| 132 result->set_safepoint_table_offset(safepoints()->GetCodeOffset()); | 133 result->set_safepoint_table_offset(safepoints()->GetCodeOffset()); |
| 133 | 134 |
| 135 // Emit exception handler table. |
| 136 if (!handlers_.empty()) { |
| 137 Handle<FixedArray> table = isolate()->factory()->NewFixedArray( |
| 138 static_cast<int>(handlers_.size()) * 2, TENURED); |
| 139 for (size_t i = 0; i < handlers_.size(); ++i) { |
| 140 int table_index = static_cast<int>(i * 2); |
| 141 table->set(table_index + 0, Smi::FromInt(handlers_[i].pc_offset)); |
| 142 table->set(table_index + 1, Smi::FromInt(handlers_[i].handler->pos())); |
| 143 } |
| 144 result->set_handler_table(*table); |
| 145 } |
| 146 |
| 134 PopulateDeoptimizationData(result); | 147 PopulateDeoptimizationData(result); |
| 135 | 148 |
| 136 // Ensure there is space for lazy deoptimization in the relocation info. | 149 // Ensure there is space for lazy deoptimization in the relocation info. |
| 137 if (!info->IsStub()) { | 150 if (!info->IsStub()) { |
| 138 Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(result); | 151 Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(result); |
| 139 } | 152 } |
| 140 | 153 |
| 141 // Emit a code line info recording stop event. | 154 // Emit a code line info recording stop event. |
| 142 void* line_info = recorder->DetachJITHandlerData(); | 155 void* line_info = recorder->DetachJITHandlerData(); |
| 143 LOG_CODE_EVENT(isolate(), CodeEndLinePosInfoRecordEvent(*result, line_info)); | 156 LOG_CODE_EVENT(isolate(), CodeEndLinePosInfoRecordEvent(*result, line_info)); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 code_object->set_deoptimization_data(*data); | 327 code_object->set_deoptimization_data(*data); |
| 315 } | 328 } |
| 316 | 329 |
| 317 | 330 |
| 318 Label* CodeGenerator::AddJumpTable(Label** targets, size_t target_count) { | 331 Label* CodeGenerator::AddJumpTable(Label** targets, size_t target_count) { |
| 319 jump_tables_ = new (zone()) JumpTable(jump_tables_, targets, target_count); | 332 jump_tables_ = new (zone()) JumpTable(jump_tables_, targets, target_count); |
| 320 return jump_tables_->label(); | 333 return jump_tables_->label(); |
| 321 } | 334 } |
| 322 | 335 |
| 323 | 336 |
| 324 void CodeGenerator::AddSafepointAndDeopt(Instruction* instr) { | 337 void CodeGenerator::RecordCallPosition(Instruction* instr) { |
| 325 CallDescriptor::Flags flags(MiscField::decode(instr->opcode())); | 338 CallDescriptor::Flags flags(MiscField::decode(instr->opcode())); |
| 326 | 339 |
| 327 bool needs_frame_state = (flags & CallDescriptor::kNeedsFrameState); | 340 bool needs_frame_state = (flags & CallDescriptor::kNeedsFrameState); |
| 328 | 341 |
| 329 RecordSafepoint( | 342 RecordSafepoint( |
| 330 instr->pointer_map(), Safepoint::kSimple, 0, | 343 instr->pointer_map(), Safepoint::kSimple, 0, |
| 331 needs_frame_state ? Safepoint::kLazyDeopt : Safepoint::kNoLazyDeopt); | 344 needs_frame_state ? Safepoint::kLazyDeopt : Safepoint::kNoLazyDeopt); |
| 332 | 345 |
| 346 if (flags & CallDescriptor::kHasExceptionHandler) { |
| 347 InstructionOperandConverter i(this, instr); |
| 348 BasicBlock::RpoNumber handler_rpo = |
| 349 i.InputRpo(static_cast<int>(instr->InputCount()) - 1); |
| 350 handlers_.push_back({GetLabel(handler_rpo), masm()->pc_offset()}); |
| 351 } |
| 352 |
| 333 if (flags & CallDescriptor::kNeedsNopAfterCall) { | 353 if (flags & CallDescriptor::kNeedsNopAfterCall) { |
| 334 AddNopForSmiCodeInlining(); | 354 AddNopForSmiCodeInlining(); |
| 335 } | 355 } |
| 336 | 356 |
| 337 if (needs_frame_state) { | 357 if (needs_frame_state) { |
| 338 MarkLazyDeoptSite(); | 358 MarkLazyDeoptSite(); |
| 339 // If the frame state is present, it starts at argument 1 | 359 // If the frame state is present, it starts at argument 1 (just after the |
| 340 // (just after the code address). | 360 // code address). |
| 341 InstructionOperandConverter converter(this, instr); | |
| 342 // Deoptimization info starts at argument 1 | |
| 343 size_t frame_state_offset = 1; | 361 size_t frame_state_offset = 1; |
| 344 FrameStateDescriptor* descriptor = | 362 FrameStateDescriptor* descriptor = |
| 345 GetFrameStateDescriptor(instr, frame_state_offset); | 363 GetFrameStateDescriptor(instr, frame_state_offset); |
| 346 int pc_offset = masm()->pc_offset(); | 364 int pc_offset = masm()->pc_offset(); |
| 347 int deopt_state_id = BuildTranslation(instr, pc_offset, frame_state_offset, | 365 int deopt_state_id = BuildTranslation(instr, pc_offset, frame_state_offset, |
| 348 descriptor->state_combine()); | 366 descriptor->state_combine()); |
| 349 // If the pre-call frame state differs from the post-call one, produce the | 367 // If the pre-call frame state differs from the post-call one, produce the |
| 350 // pre-call frame state, too. | 368 // pre-call frame state, too. |
| 351 // TODO(jarin) We might want to avoid building the pre-call frame state | 369 // TODO(jarin) We might want to avoid building the pre-call frame state |
| 352 // because it is only used to get locals and arguments (by the debugger and | 370 // because it is only used to get locals and arguments (by the debugger and |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 : masm_(gen->masm()), next_(gen->ools_) { | 636 : masm_(gen->masm()), next_(gen->ools_) { |
| 619 gen->ools_ = this; | 637 gen->ools_ = this; |
| 620 } | 638 } |
| 621 | 639 |
| 622 | 640 |
| 623 OutOfLineCode::~OutOfLineCode() {} | 641 OutOfLineCode::~OutOfLineCode() {} |
| 624 | 642 |
| 625 } // namespace compiler | 643 } // namespace compiler |
| 626 } // namespace internal | 644 } // namespace internal |
| 627 } // namespace v8 | 645 } // namespace v8 |
| OLD | NEW |