| 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 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace compiler { | 13 namespace compiler { |
| 14 | 14 |
| 15 CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, | 15 CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, |
| 16 InstructionSequence* code) | 16 InstructionSequence* code, CompilationInfo* info) |
| 17 : frame_(frame), | 17 : frame_(frame), |
| 18 linkage_(linkage), | 18 linkage_(linkage), |
| 19 code_(code), | 19 code_(code), |
| 20 info_(info), |
| 20 current_block_(BasicBlock::RpoNumber::Invalid()), | 21 current_block_(BasicBlock::RpoNumber::Invalid()), |
| 21 current_source_position_(SourcePosition::Invalid()), | 22 current_source_position_(SourcePosition::Invalid()), |
| 22 masm_(code->zone()->isolate(), NULL, 0), | 23 masm_(code->zone()->isolate(), NULL, 0), |
| 23 resolver_(this), | 24 resolver_(this), |
| 24 safepoints_(code->zone()), | 25 safepoints_(code->zone()), |
| 25 deoptimization_states_(code->zone()), | 26 deoptimization_states_(code->zone()), |
| 26 deoptimization_literals_(code->zone()), | 27 deoptimization_literals_(code->zone()), |
| 27 translations_(code->zone()), | 28 translations_(code->zone()), |
| 28 last_lazy_deopt_pc_(0) {} | 29 last_lazy_deopt_pc_(0) {} |
| 29 | 30 |
| 30 | 31 |
| 31 Handle<Code> CodeGenerator::GenerateCode() { | 32 Handle<Code> CodeGenerator::GenerateCode() { |
| 32 CompilationInfo* info = linkage()->info(); | 33 CompilationInfo* info = this->info(); |
| 33 | 34 |
| 34 // Emit a code line info recording start event. | 35 // Emit a code line info recording start event. |
| 35 PositionsRecorder* recorder = masm()->positions_recorder(); | 36 PositionsRecorder* recorder = masm()->positions_recorder(); |
| 36 LOG_CODE_EVENT(isolate(), CodeStartLinePosInfoRecordEvent(recorder)); | 37 LOG_CODE_EVENT(isolate(), CodeStartLinePosInfoRecordEvent(recorder)); |
| 37 | 38 |
| 38 // Place function entry hook if requested to do so. | 39 // Place function entry hook if requested to do so. |
| 39 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { | 40 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { |
| 40 ProfileEntryHookStub::MaybeCallEntryHook(masm()); | 41 ProfileEntryHookStub::MaybeCallEntryHook(masm()); |
| 41 } | 42 } |
| 42 | 43 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 void CodeGenerator::AssembleSourcePosition(SourcePositionInstruction* instr) { | 160 void CodeGenerator::AssembleSourcePosition(SourcePositionInstruction* instr) { |
| 160 SourcePosition source_position = instr->source_position(); | 161 SourcePosition source_position = instr->source_position(); |
| 161 if (source_position == current_source_position_) return; | 162 if (source_position == current_source_position_) return; |
| 162 DCHECK(!source_position.IsInvalid()); | 163 DCHECK(!source_position.IsInvalid()); |
| 163 if (!source_position.IsUnknown()) { | 164 if (!source_position.IsUnknown()) { |
| 164 int code_pos = source_position.raw(); | 165 int code_pos = source_position.raw(); |
| 165 masm()->positions_recorder()->RecordPosition(source_position.raw()); | 166 masm()->positions_recorder()->RecordPosition(source_position.raw()); |
| 166 masm()->positions_recorder()->WriteRecordedPositions(); | 167 masm()->positions_recorder()->WriteRecordedPositions(); |
| 167 if (FLAG_code_comments) { | 168 if (FLAG_code_comments) { |
| 168 Vector<char> buffer = Vector<char>::New(256); | 169 Vector<char> buffer = Vector<char>::New(256); |
| 169 CompilationInfo* info = linkage()->info(); | 170 CompilationInfo* info = this->info(); |
| 170 int ln = Script::GetLineNumber(info->script(), code_pos); | 171 int ln = Script::GetLineNumber(info->script(), code_pos); |
| 171 int cn = Script::GetColumnNumber(info->script(), code_pos); | 172 int cn = Script::GetColumnNumber(info->script(), code_pos); |
| 172 if (info->script()->name()->IsString()) { | 173 if (info->script()->name()->IsString()) { |
| 173 Handle<String> file(String::cast(info->script()->name())); | 174 Handle<String> file(String::cast(info->script()->name())); |
| 174 base::OS::SNPrintF(buffer.start(), buffer.length(), "-- %s:%d:%d --", | 175 base::OS::SNPrintF(buffer.start(), buffer.length(), "-- %s:%d:%d --", |
| 175 file->ToCString().get(), ln, cn); | 176 file->ToCString().get(), ln, cn); |
| 176 } else { | 177 } else { |
| 177 base::OS::SNPrintF(buffer.start(), buffer.length(), | 178 base::OS::SNPrintF(buffer.start(), buffer.length(), |
| 178 "-- <unknown>:%d:%d --", ln, cn); | 179 "-- <unknown>:%d:%d --", ln, cn); |
| 179 } | 180 } |
| 180 masm()->RecordComment(buffer.start()); | 181 masm()->RecordComment(buffer.start()); |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 current_source_position_ = source_position; | 184 current_source_position_ = source_position; |
| 184 } | 185 } |
| 185 | 186 |
| 186 | 187 |
| 187 void CodeGenerator::AssembleGap(GapInstruction* instr) { | 188 void CodeGenerator::AssembleGap(GapInstruction* instr) { |
| 188 for (int i = GapInstruction::FIRST_INNER_POSITION; | 189 for (int i = GapInstruction::FIRST_INNER_POSITION; |
| 189 i <= GapInstruction::LAST_INNER_POSITION; i++) { | 190 i <= GapInstruction::LAST_INNER_POSITION; i++) { |
| 190 GapInstruction::InnerPosition inner_pos = | 191 GapInstruction::InnerPosition inner_pos = |
| 191 static_cast<GapInstruction::InnerPosition>(i); | 192 static_cast<GapInstruction::InnerPosition>(i); |
| 192 ParallelMove* move = instr->GetParallelMove(inner_pos); | 193 ParallelMove* move = instr->GetParallelMove(inner_pos); |
| 193 if (move != NULL) resolver()->Resolve(move); | 194 if (move != NULL) resolver()->Resolve(move); |
| 194 } | 195 } |
| 195 } | 196 } |
| 196 | 197 |
| 197 | 198 |
| 198 void CodeGenerator::PopulateDeoptimizationData(Handle<Code> code_object) { | 199 void CodeGenerator::PopulateDeoptimizationData(Handle<Code> code_object) { |
| 199 CompilationInfo* info = linkage()->info(); | 200 CompilationInfo* info = this->info(); |
| 200 int deopt_count = static_cast<int>(deoptimization_states_.size()); | 201 int deopt_count = static_cast<int>(deoptimization_states_.size()); |
| 201 if (deopt_count == 0) return; | 202 if (deopt_count == 0) return; |
| 202 Handle<DeoptimizationInputData> data = | 203 Handle<DeoptimizationInputData> data = |
| 203 DeoptimizationInputData::New(isolate(), deopt_count, TENURED); | 204 DeoptimizationInputData::New(isolate(), deopt_count, TENURED); |
| 204 | 205 |
| 205 Handle<ByteArray> translation_array = | 206 Handle<ByteArray> translation_array = |
| 206 translations_.CreateByteArray(isolate()->factory()); | 207 translations_.CreateByteArray(isolate()->factory()); |
| 207 | 208 |
| 208 data->SetTranslationByteArray(*translation_array); | 209 data->SetTranslationByteArray(*translation_array); |
| 209 data->SetInlinedFunctionCount(Smi::FromInt(0)); | 210 data->SetInlinedFunctionCount(Smi::FromInt(0)); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 525 } |
| 525 | 526 |
| 526 | 527 |
| 527 void CodeGenerator::AddNopForSmiCodeInlining() { UNIMPLEMENTED(); } | 528 void CodeGenerator::AddNopForSmiCodeInlining() { UNIMPLEMENTED(); } |
| 528 | 529 |
| 529 #endif // !V8_TURBOFAN_BACKEND | 530 #endif // !V8_TURBOFAN_BACKEND |
| 530 | 531 |
| 531 } // namespace compiler | 532 } // namespace compiler |
| 532 } // namespace internal | 533 } // namespace internal |
| 533 } // namespace v8 | 534 } // namespace v8 |
| OLD | NEW |