| 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/hydrogen.h" | 5 #include "src/hydrogen.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/v8.h" | 9 #include "src/v8.h" |
| 10 | 10 |
| (...skipping 3346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3357 } | 3357 } |
| 3358 | 3358 |
| 3359 | 3359 |
| 3360 void HBasicBlock::FinishExit(HControlInstruction* instruction, | 3360 void HBasicBlock::FinishExit(HControlInstruction* instruction, |
| 3361 HSourcePosition position) { | 3361 HSourcePosition position) { |
| 3362 Finish(instruction, position); | 3362 Finish(instruction, position); |
| 3363 ClearEnvironment(); | 3363 ClearEnvironment(); |
| 3364 } | 3364 } |
| 3365 | 3365 |
| 3366 | 3366 |
| 3367 OStream& operator<<(OStream& os, const HBasicBlock& b) { |
| 3368 return os << "B" << b.block_id(); |
| 3369 } |
| 3370 |
| 3371 |
| 3367 HGraph::HGraph(CompilationInfo* info) | 3372 HGraph::HGraph(CompilationInfo* info) |
| 3368 : isolate_(info->isolate()), | 3373 : isolate_(info->isolate()), |
| 3369 next_block_id_(0), | 3374 next_block_id_(0), |
| 3370 entry_block_(NULL), | 3375 entry_block_(NULL), |
| 3371 blocks_(8, info->zone()), | 3376 blocks_(8, info->zone()), |
| 3372 values_(16, info->zone()), | 3377 values_(16, info->zone()), |
| 3373 phi_list_(NULL), | 3378 phi_list_(NULL), |
| 3374 uint32_instructions_(NULL), | 3379 uint32_instructions_(NULL), |
| 3375 osr_(NULL), | 3380 osr_(NULL), |
| 3376 info_(info), | 3381 info_(info), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3431 break; | 3436 break; |
| 3432 } | 3437 } |
| 3433 } | 3438 } |
| 3434 | 3439 |
| 3435 if (id == inlined_functions_.length()) { | 3440 if (id == inlined_functions_.length()) { |
| 3436 inlined_functions_.Add(InlinedFunctionInfo(shared), zone()); | 3441 inlined_functions_.Add(InlinedFunctionInfo(shared), zone()); |
| 3437 | 3442 |
| 3438 if (!shared->script()->IsUndefined()) { | 3443 if (!shared->script()->IsUndefined()) { |
| 3439 Handle<Script> script(Script::cast(shared->script())); | 3444 Handle<Script> script(Script::cast(shared->script())); |
| 3440 if (!script->source()->IsUndefined()) { | 3445 if (!script->source()->IsUndefined()) { |
| 3441 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); | 3446 CodeTracer::Scope tracing_scopex(isolate()->GetCodeTracer()); |
| 3442 PrintF(tracing_scope.file(), | 3447 OFStream os(tracing_scopex.file()); |
| 3443 "--- FUNCTION SOURCE (%s) id{%d,%d} ---\n", | 3448 os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get() |
| 3444 shared->DebugName()->ToCString().get(), | 3449 << ") id{" << info()->optimization_id() << "," << id << "} ---\n"; |
| 3445 info()->optimization_id(), | |
| 3446 id); | |
| 3447 | |
| 3448 { | 3450 { |
| 3449 ConsStringIteratorOp op; | 3451 ConsStringIteratorOp op; |
| 3450 StringCharacterStream stream(String::cast(script->source()), | 3452 StringCharacterStream stream(String::cast(script->source()), |
| 3451 &op, | 3453 &op, |
| 3452 shared->start_position()); | 3454 shared->start_position()); |
| 3453 // fun->end_position() points to the last character in the stream. We | 3455 // fun->end_position() points to the last character in the stream. We |
| 3454 // need to compensate by adding one to calculate the length. | 3456 // need to compensate by adding one to calculate the length. |
| 3455 int source_len = | 3457 int source_len = |
| 3456 shared->end_position() - shared->start_position() + 1; | 3458 shared->end_position() - shared->start_position() + 1; |
| 3457 for (int i = 0; i < source_len; i++) { | 3459 for (int i = 0; i < source_len; i++) { |
| 3458 if (stream.HasMore()) { | 3460 if (stream.HasMore()) { |
| 3459 PrintF(tracing_scope.file(), "%c", stream.GetNext()); | 3461 os.put(stream.GetNext()); |
| 3460 } | 3462 } |
| 3461 } | 3463 } |
| 3462 } | 3464 } |
| 3463 | 3465 |
| 3464 PrintF(tracing_scope.file(), "\n--- END ---\n"); | 3466 os << "\n--- END ---\n"; |
| 3465 } | 3467 } |
| 3466 } | 3468 } |
| 3467 } | 3469 } |
| 3468 | 3470 |
| 3469 int inline_id = next_inline_id_++; | 3471 int inline_id = next_inline_id_++; |
| 3470 | 3472 |
| 3471 if (inline_id != 0) { | 3473 if (inline_id != 0) { |
| 3472 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); | 3474 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); |
| 3473 PrintF(tracing_scope.file(), "INLINE (%s) id{%d,%d} AS %d AT ", | 3475 OFStream os(tracing_scope.file()); |
| 3474 shared->DebugName()->ToCString().get(), | 3476 os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{" |
| 3475 info()->optimization_id(), | 3477 << info()->optimization_id() << "," << id << "} AS " << inline_id |
| 3476 id, | 3478 << " AT " << position << endl; |
| 3477 inline_id); | |
| 3478 position.PrintTo(tracing_scope.file()); | |
| 3479 PrintF(tracing_scope.file(), "\n"); | |
| 3480 } | 3479 } |
| 3481 | 3480 |
| 3482 return inline_id; | 3481 return inline_id; |
| 3483 } | 3482 } |
| 3484 | 3483 |
| 3485 | 3484 |
| 3486 int HGraph::SourcePositionToScriptPosition(HSourcePosition pos) { | 3485 int HGraph::SourcePositionToScriptPosition(HSourcePosition pos) { |
| 3487 if (!FLAG_hydrogen_track_positions || pos.IsUnknown()) { | 3486 if (!FLAG_hydrogen_track_positions || pos.IsUnknown()) { |
| 3488 return pos.raw(); | 3487 return pos.raw(); |
| 3489 } | 3488 } |
| (...skipping 8541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12031 inner->SetValueAt(arity + 1, context()); | 12030 inner->SetValueAt(arity + 1, context()); |
| 12032 for (int i = arity + 2; i < inner->length(); ++i) { | 12031 for (int i = arity + 2; i < inner->length(); ++i) { |
| 12033 inner->SetValueAt(i, undefined); | 12032 inner->SetValueAt(i, undefined); |
| 12034 } | 12033 } |
| 12035 | 12034 |
| 12036 inner->set_ast_id(BailoutId::FunctionEntry()); | 12035 inner->set_ast_id(BailoutId::FunctionEntry()); |
| 12037 return inner; | 12036 return inner; |
| 12038 } | 12037 } |
| 12039 | 12038 |
| 12040 | 12039 |
| 12041 void HEnvironment::PrintTo(StringStream* stream) { | 12040 OStream& operator<<(OStream& os, const HEnvironment& env) { |
| 12042 for (int i = 0; i < length(); i++) { | 12041 for (int i = 0; i < env.length(); i++) { |
| 12043 if (i == 0) stream->Add("parameters\n"); | 12042 if (i == 0) os << "parameters\n"; |
| 12044 if (i == parameter_count()) stream->Add("specials\n"); | 12043 if (i == env.parameter_count()) os << "specials\n"; |
| 12045 if (i == parameter_count() + specials_count()) stream->Add("locals\n"); | 12044 if (i == env.parameter_count() + env.specials_count()) os << "locals\n"; |
| 12046 if (i == parameter_count() + specials_count() + local_count()) { | 12045 if (i == env.parameter_count() + env.specials_count() + env.local_count()) { |
| 12047 stream->Add("expressions\n"); | 12046 os << "expressions\n"; |
| 12048 } | 12047 } |
| 12049 HValue* val = values_.at(i); | 12048 HValue* val = env.values()->at(i); |
| 12050 stream->Add("%d: ", i); | 12049 os << i << ": "; |
| 12051 if (val != NULL) { | 12050 if (val != NULL) { |
| 12052 val->PrintNameTo(stream); | 12051 os << val; |
| 12053 } else { | 12052 } else { |
| 12054 stream->Add("NULL"); | 12053 os << "NULL"; |
| 12055 } | 12054 } |
| 12056 stream->Add("\n"); | 12055 os << "\n"; |
| 12057 } | 12056 } |
| 12058 PrintF("\n"); | 12057 return os << "\n"; |
| 12059 } | 12058 } |
| 12060 | 12059 |
| 12061 | 12060 |
| 12062 void HEnvironment::PrintToStd() { | |
| 12063 HeapStringAllocator string_allocator; | |
| 12064 StringStream trace(&string_allocator); | |
| 12065 PrintTo(&trace); | |
| 12066 PrintF("%s", trace.ToCString().get()); | |
| 12067 } | |
| 12068 | |
| 12069 | |
| 12070 void HTracer::TraceCompilation(CompilationInfo* info) { | 12061 void HTracer::TraceCompilation(CompilationInfo* info) { |
| 12071 Tag tag(this, "compilation"); | 12062 Tag tag(this, "compilation"); |
| 12072 if (info->IsOptimizing()) { | 12063 if (info->IsOptimizing()) { |
| 12073 Handle<String> name = info->function()->debug_name(); | 12064 Handle<String> name = info->function()->debug_name(); |
| 12074 PrintStringProperty("name", name->ToCString().get()); | 12065 PrintStringProperty("name", name->ToCString().get()); |
| 12075 PrintIndent(); | 12066 PrintIndent(); |
| 12076 trace_.Add("method \"%s:%d\"\n", | 12067 trace_.Add("method \"%s:%d\"\n", |
| 12077 name->ToCString().get(), | 12068 name->ToCString().get(), |
| 12078 info->optimization_id()); | 12069 info->optimization_id()); |
| 12079 } else { | 12070 } else { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12171 | 12162 |
| 12172 { | 12163 { |
| 12173 Tag states_tag(this, "states"); | 12164 Tag states_tag(this, "states"); |
| 12174 Tag locals_tag(this, "locals"); | 12165 Tag locals_tag(this, "locals"); |
| 12175 int total = current->phis()->length(); | 12166 int total = current->phis()->length(); |
| 12176 PrintIntProperty("size", current->phis()->length()); | 12167 PrintIntProperty("size", current->phis()->length()); |
| 12177 PrintStringProperty("method", "None"); | 12168 PrintStringProperty("method", "None"); |
| 12178 for (int j = 0; j < total; ++j) { | 12169 for (int j = 0; j < total; ++j) { |
| 12179 HPhi* phi = current->phis()->at(j); | 12170 HPhi* phi = current->phis()->at(j); |
| 12180 PrintIndent(); | 12171 PrintIndent(); |
| 12181 trace_.Add("%d ", phi->merged_index()); | 12172 OStringStream os; |
| 12182 phi->PrintNameTo(&trace_); | 12173 os << phi->merged_index() << " " << NameOf(phi) << " " << *phi << "\n"; |
| 12183 trace_.Add(" "); | 12174 trace_.Add(os.c_str()); |
| 12184 phi->PrintTo(&trace_); | |
| 12185 trace_.Add("\n"); | |
| 12186 } | 12175 } |
| 12187 } | 12176 } |
| 12188 | 12177 |
| 12189 { | 12178 { |
| 12190 Tag HIR_tag(this, "HIR"); | 12179 Tag HIR_tag(this, "HIR"); |
| 12191 for (HInstructionIterator it(current); !it.Done(); it.Advance()) { | 12180 for (HInstructionIterator it(current); !it.Done(); it.Advance()) { |
| 12192 HInstruction* instruction = it.Current(); | 12181 HInstruction* instruction = it.Current(); |
| 12193 int uses = instruction->UseCount(); | 12182 int uses = instruction->UseCount(); |
| 12194 PrintIndent(); | 12183 PrintIndent(); |
| 12195 trace_.Add("0 %d ", uses); | 12184 OStringStream os; |
| 12196 instruction->PrintNameTo(&trace_); | 12185 os << "0 " << uses << " " << NameOf(instruction) << " " << *instruction; |
| 12197 trace_.Add(" "); | |
| 12198 instruction->PrintTo(&trace_); | |
| 12199 if (FLAG_hydrogen_track_positions && | 12186 if (FLAG_hydrogen_track_positions && |
| 12200 instruction->has_position() && | 12187 instruction->has_position() && |
| 12201 instruction->position().raw() != 0) { | 12188 instruction->position().raw() != 0) { |
| 12202 const HSourcePosition pos = instruction->position(); | 12189 const HSourcePosition pos = instruction->position(); |
| 12203 trace_.Add(" pos:"); | 12190 os << " pos:"; |
| 12204 if (pos.inlining_id() != 0) { | 12191 if (pos.inlining_id() != 0) os << pos.inlining_id() << "_"; |
| 12205 trace_.Add("%d_", pos.inlining_id()); | 12192 os << pos.position(); |
| 12206 } | |
| 12207 trace_.Add("%d", pos.position()); | |
| 12208 } | 12193 } |
| 12209 trace_.Add(" <|@\n"); | 12194 os << " <|@\n"; |
| 12195 trace_.Add(os.c_str()); |
| 12210 } | 12196 } |
| 12211 } | 12197 } |
| 12212 | 12198 |
| 12213 | 12199 |
| 12214 if (chunk != NULL) { | 12200 if (chunk != NULL) { |
| 12215 Tag LIR_tag(this, "LIR"); | 12201 Tag LIR_tag(this, "LIR"); |
| 12216 int first_index = current->first_instruction_index(); | 12202 int first_index = current->first_instruction_index(); |
| 12217 int last_index = current->last_instruction_index(); | 12203 int last_index = current->last_instruction_index(); |
| 12218 if (first_index != -1 && last_index != -1) { | 12204 if (first_index != -1 && last_index != -1) { |
| 12219 const ZoneList<LInstruction*>* instructions = chunk->instructions(); | 12205 const ZoneList<LInstruction*>* instructions = chunk->instructions(); |
| 12220 for (int i = first_index; i <= last_index; ++i) { | 12206 for (int i = first_index; i <= last_index; ++i) { |
| 12221 LInstruction* linstr = instructions->at(i); | 12207 LInstruction* linstr = instructions->at(i); |
| 12222 if (linstr != NULL) { | 12208 if (linstr != NULL) { |
| 12223 PrintIndent(); | 12209 PrintIndent(); |
| 12224 trace_.Add("%d ", | 12210 trace_.Add("%d ", |
| 12225 LifetimePosition::FromInstructionIndex(i).Value()); | 12211 LifetimePosition::FromInstructionIndex(i).Value()); |
| 12226 linstr->PrintTo(&trace_); | 12212 linstr->PrintTo(&trace_); |
| 12227 trace_.Add(" [hir:"); | 12213 OStringStream os; |
| 12228 linstr->hydrogen_value()->PrintNameTo(&trace_); | 12214 os << " [hir:" << NameOf(linstr->hydrogen_value()) << "] <|@\n"; |
| 12229 trace_.Add("]"); | 12215 trace_.Add(os.c_str()); |
| 12230 trace_.Add(" <|@\n"); | |
| 12231 } | 12216 } |
| 12232 } | 12217 } |
| 12233 } | 12218 } |
| 12234 } | 12219 } |
| 12235 } | 12220 } |
| 12236 } | 12221 } |
| 12237 | 12222 |
| 12238 | 12223 |
| 12239 void HTracer::TraceLiveRanges(const char* name, LAllocator* allocator) { | 12224 void HTracer::TraceLiveRanges(const char* name, LAllocator* allocator) { |
| 12240 Tag tag(this, "intervals"); | 12225 Tag tag(this, "intervals"); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12400 if (ShouldProduceTraceOutput()) { | 12385 if (ShouldProduceTraceOutput()) { |
| 12401 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 12386 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
| 12402 } | 12387 } |
| 12403 | 12388 |
| 12404 #ifdef DEBUG | 12389 #ifdef DEBUG |
| 12405 graph_->Verify(false); // No full verify. | 12390 graph_->Verify(false); // No full verify. |
| 12406 #endif | 12391 #endif |
| 12407 } | 12392 } |
| 12408 | 12393 |
| 12409 } } // namespace v8::internal | 12394 } } // namespace v8::internal |
| OLD | NEW |