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/base/adapters.h" | 8 #include "src/base/adapters.h" |
9 #include "src/compilation-info.h" | 9 #include "src/compilation-info.h" |
10 #include "src/compiler/code-generator-impl.h" | 10 #include "src/compiler/code-generator-impl.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 | 81 |
82 // Place function entry hook if requested to do so. | 82 // Place function entry hook if requested to do so. |
83 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { | 83 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { |
84 ProfileEntryHookStub::MaybeCallEntryHook(masm()); | 84 ProfileEntryHookStub::MaybeCallEntryHook(masm()); |
85 } | 85 } |
86 // Architecture-specific, linkage-specific prologue. | 86 // Architecture-specific, linkage-specific prologue. |
87 info->set_prologue_offset(masm()->pc_offset()); | 87 info->set_prologue_offset(masm()->pc_offset()); |
88 | 88 |
89 // Define deoptimization literals for all inlined functions. | 89 // Define deoptimization literals for all inlined functions. |
90 DCHECK_EQ(0u, deoptimization_literals_.size()); | 90 DCHECK_EQ(0u, deoptimization_literals_.size()); |
91 for (const CompilationInfo::InlinedFunctionHolder& inlined : | 91 for (CompilationInfo::InlinedFunctionHolder& inlined : |
92 info->inlined_functions()) { | 92 info->inlined_functions()) { |
93 if (!inlined.shared_info.is_identical_to(info->shared_info())) { | 93 if (!inlined.shared_info.is_identical_to(info->shared_info())) { |
94 inlined.RegisterInlinedFunctionId(deoptimization_literals_.size()); | |
94 DefineDeoptimizationLiteral(inlined.shared_info); | 95 DefineDeoptimizationLiteral(inlined.shared_info); |
95 } | 96 } |
96 } | 97 } |
97 inlined_function_count_ = deoptimization_literals_.size(); | 98 inlined_function_count_ = deoptimization_literals_.size(); |
98 | 99 |
99 // Define deoptimization literals for all unoptimized code objects of inlined | 100 // Define deoptimization literals for all unoptimized code objects of inlined |
100 // functions. This ensures unoptimized code is kept alive by optimized code. | 101 // functions. This ensures unoptimized code is kept alive by optimized code. |
101 for (const CompilationInfo::InlinedFunctionHolder& inlined : | 102 for (const CompilationInfo::InlinedFunctionHolder& inlined : |
102 info->inlined_functions()) { | 103 info->inlined_functions()) { |
103 if (!inlined.shared_info.is_identical_to(info->shared_info())) { | 104 if (!inlined.shared_info.is_identical_to(info->shared_info())) { |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 } | 467 } |
467 return kSuccess; | 468 return kSuccess; |
468 } | 469 } |
469 | 470 |
470 | 471 |
471 void CodeGenerator::AssembleSourcePosition(Instruction* instr) { | 472 void CodeGenerator::AssembleSourcePosition(Instruction* instr) { |
472 SourcePosition source_position; | 473 SourcePosition source_position; |
473 if (!code()->GetSourcePosition(instr, &source_position)) return; | 474 if (!code()->GetSourcePosition(instr, &source_position)) return; |
474 if (source_position == current_source_position_) return; | 475 if (source_position == current_source_position_) return; |
475 current_source_position_ = source_position; | 476 current_source_position_ = source_position; |
476 if (source_position.IsUnknown()) return; | 477 if (!source_position.IsKnown()) return; |
477 int code_pos = source_position.raw(); | 478 source_position_table_builder_.AddPosition(masm()->pc_offset(), |
478 source_position_table_builder_.AddPosition(masm()->pc_offset(), code_pos, | 479 source_position, false); |
479 false); | |
480 if (FLAG_code_comments) { | 480 if (FLAG_code_comments) { |
481 CompilationInfo* info = this->info(); | 481 CompilationInfo* info = this->info(); |
482 if (!info->parse_info()) return; | 482 if (!info->parse_info()) return; |
483 Vector<char> buffer = Vector<char>::New(256); | 483 std::ostringstream buffer; |
484 int ln = Script::GetLineNumber(info->script(), code_pos); | 484 buffer << "-- " << source_position.InliningStack(info) << " --"; |
485 int cn = Script::GetColumnNumber(info->script(), code_pos); | 485 masm()->RecordComment(StrDup(buffer.str().c_str())); |
486 if (info->script()->name()->IsString()) { | |
487 Handle<String> file(String::cast(info->script()->name())); | |
488 base::OS::SNPrintF(buffer.start(), buffer.length(), "-- %s:%d:%d --", | |
489 file->ToCString().get(), ln, cn); | |
490 } else { | |
491 base::OS::SNPrintF(buffer.start(), buffer.length(), | |
492 "-- <unknown>:%d:%d --", ln, cn); | |
493 } | |
494 masm()->RecordComment(buffer.start()); | |
495 } | 486 } |
496 } | 487 } |
497 | 488 |
498 bool CodeGenerator::GetSlotAboveSPBeforeTailCall(Instruction* instr, | 489 bool CodeGenerator::GetSlotAboveSPBeforeTailCall(Instruction* instr, |
499 int* slot) { | 490 int* slot) { |
500 if (instr->IsTailCall()) { | 491 if (instr->IsTailCall()) { |
501 InstructionOperandConverter g(this, instr); | 492 InstructionOperandConverter g(this, instr); |
502 *slot = g.InputInt32(instr->InputCount() - 1); | 493 *slot = g.InputInt32(instr->InputCount() - 1); |
503 return true; | 494 return true; |
504 } else { | 495 } else { |
505 return false; | 496 return false; |
506 } | 497 } |
507 } | 498 } |
508 | 499 |
509 void CodeGenerator::AssembleGaps(Instruction* instr) { | 500 void CodeGenerator::AssembleGaps(Instruction* instr) { |
510 for (int i = Instruction::FIRST_GAP_POSITION; | 501 for (int i = Instruction::FIRST_GAP_POSITION; |
511 i <= Instruction::LAST_GAP_POSITION; i++) { | 502 i <= Instruction::LAST_GAP_POSITION; i++) { |
512 Instruction::GapPosition inner_pos = | 503 Instruction::GapPosition inner_pos = |
513 static_cast<Instruction::GapPosition>(i); | 504 static_cast<Instruction::GapPosition>(i); |
514 ParallelMove* move = instr->GetParallelMove(inner_pos); | 505 ParallelMove* move = instr->GetParallelMove(inner_pos); |
515 if (move != nullptr) resolver()->Resolve(move); | 506 if (move != nullptr) resolver()->Resolve(move); |
516 } | 507 } |
517 } | 508 } |
518 | 509 |
510 namespace { | |
511 | |
512 Handle<PodArray<InliningPosition>> CreateInliningPositions( | |
513 CompilationInfo* info) { | |
514 const CompilationInfo::InlinedFunctionList& inlined_functions = | |
515 info->inlined_functions(); | |
516 if (inlined_functions.size() == 0) | |
vogelheim
2016/11/07 17:53:27
style nitpick: use if with braces, if it extends t
| |
517 return Handle<PodArray<InliningPosition>>::cast( | |
518 info->isolate()->factory()->empty_byte_array()); | |
519 Handle<PodArray<InliningPosition>> inl_positions = | |
520 PodArray<InliningPosition>::New( | |
521 info->isolate(), static_cast<int>(inlined_functions.size()), TENURED); | |
522 for (int i = 0; i < inlined_functions.size(); ++i) { | |
523 inl_positions->set(i, inlined_functions[i].position); | |
524 } | |
525 return inl_positions; | |
526 } | |
527 | |
528 } // namespace | |
519 | 529 |
520 void CodeGenerator::PopulateDeoptimizationData(Handle<Code> code_object) { | 530 void CodeGenerator::PopulateDeoptimizationData(Handle<Code> code_object) { |
521 CompilationInfo* info = this->info(); | 531 CompilationInfo* info = this->info(); |
522 int deopt_count = static_cast<int>(deoptimization_states_.size()); | 532 int deopt_count = static_cast<int>(deoptimization_states_.size()); |
523 if (deopt_count == 0 && !info->is_osr()) return; | 533 if (deopt_count == 0 && !info->is_osr()) return; |
524 Handle<DeoptimizationInputData> data = | 534 Handle<DeoptimizationInputData> data = |
525 DeoptimizationInputData::New(isolate(), deopt_count, TENURED); | 535 DeoptimizationInputData::New(isolate(), deopt_count, TENURED); |
526 | 536 |
527 Handle<ByteArray> translation_array = | 537 Handle<ByteArray> translation_array = |
528 translations_.CreateByteArray(isolate()->factory()); | 538 translations_.CreateByteArray(isolate()->factory()); |
(...skipping 12 matching lines...) Expand all Loading... | |
541 Handle<FixedArray> literals = isolate()->factory()->NewFixedArray( | 551 Handle<FixedArray> literals = isolate()->factory()->NewFixedArray( |
542 static_cast<int>(deoptimization_literals_.size()), TENURED); | 552 static_cast<int>(deoptimization_literals_.size()), TENURED); |
543 { | 553 { |
544 AllowDeferredHandleDereference copy_handles; | 554 AllowDeferredHandleDereference copy_handles; |
545 for (unsigned i = 0; i < deoptimization_literals_.size(); i++) { | 555 for (unsigned i = 0; i < deoptimization_literals_.size(); i++) { |
546 literals->set(i, *deoptimization_literals_[i]); | 556 literals->set(i, *deoptimization_literals_[i]); |
547 } | 557 } |
548 data->SetLiteralArray(*literals); | 558 data->SetLiteralArray(*literals); |
549 } | 559 } |
550 | 560 |
561 data->SetInliningPositions(*CreateInliningPositions(info)); | |
562 | |
551 if (info->is_osr()) { | 563 if (info->is_osr()) { |
552 DCHECK(osr_pc_offset_ >= 0); | 564 DCHECK(osr_pc_offset_ >= 0); |
553 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); | 565 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id().ToInt())); |
554 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); | 566 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
555 } else { | 567 } else { |
556 BailoutId osr_ast_id = BailoutId::None(); | 568 BailoutId osr_ast_id = BailoutId::None(); |
557 data->SetOsrAstId(Smi::FromInt(osr_ast_id.ToInt())); | 569 data->SetOsrAstId(Smi::FromInt(osr_ast_id.ToInt())); |
558 data->SetOsrPcOffset(Smi::FromInt(-1)); | 570 data->SetOsrPcOffset(Smi::FromInt(-1)); |
559 } | 571 } |
560 | 572 |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 : frame_(gen->frame()), masm_(gen->masm()), next_(gen->ools_) { | 947 : frame_(gen->frame()), masm_(gen->masm()), next_(gen->ools_) { |
936 gen->ools_ = this; | 948 gen->ools_ = this; |
937 } | 949 } |
938 | 950 |
939 | 951 |
940 OutOfLineCode::~OutOfLineCode() {} | 952 OutOfLineCode::~OutOfLineCode() {} |
941 | 953 |
942 } // namespace compiler | 954 } // namespace compiler |
943 } // namespace internal | 955 } // namespace internal |
944 } // namespace v8 | 956 } // namespace v8 |
OLD | NEW |