Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1183)

Side by Side Diff: src/crankshaft/hydrogen.cc

Issue 1944323002: [compiler] Move inline function tracing to Crankshaft. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/crankshaft/hydrogen.h ('k') | src/crankshaft/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/crankshaft/hydrogen.h" 5 #include "src/crankshaft/hydrogen.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "src/allocation-site-scopes.h" 9 #include "src/allocation-site-scopes.h"
10 #include "src/ast/ast-numbering.h" 10 #include "src/ast/ast-numbering.h"
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 } else { 1346 } else {
1347 builder_->set_current_block(exit_block_); 1347 builder_->set_current_block(exit_block_);
1348 } 1348 }
1349 finished_ = true; 1349 finished_ = true;
1350 } 1350 }
1351 1351
1352 1352
1353 HGraph* HGraphBuilder::CreateGraph() { 1353 HGraph* HGraphBuilder::CreateGraph() {
1354 graph_ = new (zone()) HGraph(info_, descriptor_); 1354 graph_ = new (zone()) HGraph(info_, descriptor_);
1355 if (FLAG_hydrogen_stats) isolate()->GetHStatistics()->Initialize(info_); 1355 if (FLAG_hydrogen_stats) isolate()->GetHStatistics()->Initialize(info_);
1356 if (!info_->IsStub() && info_->is_tracking_positions()) {
1357 TraceInlinedFunction(info_->shared_info(), SourcePosition::Unknown(),
1358 InlinedFunctionInfo::kNoParentId);
1359 }
1356 CompilationPhase phase("H_Block building", info_); 1360 CompilationPhase phase("H_Block building", info_);
1357 set_current_block(graph()->entry_block()); 1361 set_current_block(graph()->entry_block());
1358 if (!BuildGraph()) return NULL; 1362 if (!BuildGraph()) return NULL;
1359 graph()->FinalizeUniqueness(); 1363 graph()->FinalizeUniqueness();
1360 return graph_; 1364 return graph_;
1361 } 1365 }
1362 1366
1367 int HGraphBuilder::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
1368 SourcePosition position,
1369 int parent_id) {
1370 DCHECK(info_->is_tracking_positions());
1371
1372 int inline_id = static_cast<int>(info_->inlined_function_infos().size());
1373 InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId,
1374 shared->start_position());
1375 if (!shared->script()->IsUndefined()) {
1376 Handle<Script> script(Script::cast(shared->script()));
1377 info.script_id = script->id();
1378
1379 if (FLAG_hydrogen_track_positions && !script->source()->IsUndefined()) {
1380 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
1381 OFStream os(tracing_scope.file());
1382 os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get()
1383 << ") id{" << info_->optimization_id() << "," << inline_id
1384 << "} ---\n";
1385 {
1386 DisallowHeapAllocation no_allocation;
1387 int start = shared->start_position();
1388 int len = shared->end_position() - start;
1389 String::SubStringRange source(String::cast(script->source()), start,
1390 len);
1391 for (const auto& c : source) {
1392 os << AsReversiblyEscapedUC16(c);
1393 }
1394 }
1395
1396 os << "\n--- END ---\n";
1397 }
1398 }
1399
1400 info_->inlined_function_infos().push_back(info);
1401
1402 if (FLAG_hydrogen_track_positions && inline_id != 0) {
1403 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
1404 OFStream os(tracing_scope.file());
1405 os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{"
1406 << info_->optimization_id() << "," << inline_id << "} AS " << inline_id
1407 << " AT " << position << std::endl;
1408 }
1409
1410 return inline_id;
1411 }
1363 1412
1364 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { 1413 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) {
1365 DCHECK(current_block() != NULL); 1414 DCHECK(current_block() != NULL);
1366 DCHECK(!FLAG_hydrogen_track_positions || 1415 DCHECK(!FLAG_hydrogen_track_positions ||
1367 !position_.IsUnknown() || 1416 !position_.IsUnknown() ||
1368 !info_->IsOptimizing()); 1417 !info_->IsOptimizing());
1369 current_block()->AddInstruction(instr, source_position()); 1418 current_block()->AddInstruction(instr, source_position());
1370 if (graph()->IsInsideNoSideEffectsScope()) { 1419 if (graph()->IsInsideNoSideEffectsScope()) {
1371 instr->SetFlag(HValue::kHasNoObservableSideEffects); 1420 instr->SetFlag(HValue::kHasNoObservableSideEffects);
1372 } 1421 }
(...skipping 2407 matching lines...) Expand 10 before | Expand all | Expand 10 after
3780 depends_on_empty_array_proto_elements_(false), 3829 depends_on_empty_array_proto_elements_(false),
3781 type_change_checksum_(0), 3830 type_change_checksum_(0),
3782 maximum_environment_size_(0), 3831 maximum_environment_size_(0),
3783 no_side_effects_scope_count_(0), 3832 no_side_effects_scope_count_(0),
3784 disallow_adding_new_values_(false) { 3833 disallow_adding_new_values_(false) {
3785 if (info->IsStub()) { 3834 if (info->IsStub()) {
3786 // For stubs, explicitly add the context to the environment. 3835 // For stubs, explicitly add the context to the environment.
3787 start_environment_ = new (zone_) 3836 start_environment_ = new (zone_)
3788 HEnvironment(zone_, descriptor.GetRegisterParameterCount() + 1); 3837 HEnvironment(zone_, descriptor.GetRegisterParameterCount() + 1);
3789 } else { 3838 } else {
3790 if (info->is_tracking_positions()) {
3791 info->TraceInlinedFunction(info->shared_info(), SourcePosition::Unknown(),
3792 InlinedFunctionInfo::kNoParentId);
3793 }
3794 start_environment_ = 3839 start_environment_ =
3795 new(zone_) HEnvironment(NULL, info->scope(), info->closure(), zone_); 3840 new(zone_) HEnvironment(NULL, info->scope(), info->closure(), zone_);
3796 } 3841 }
3797 start_environment_->set_ast_id(BailoutId::FunctionContext()); 3842 start_environment_->set_ast_id(BailoutId::FunctionContext());
3798 entry_block_ = CreateBasicBlock(); 3843 entry_block_ = CreateBasicBlock();
3799 entry_block_->SetInitialEnvironment(start_environment_); 3844 entry_block_->SetInitialEnvironment(start_environment_);
3800 } 3845 }
3801 3846
3802 3847
3803 HBasicBlock* HGraph::CreateBasicBlock() { 3848 HBasicBlock* HGraph::CreateBasicBlock() {
3804 HBasicBlock* result = new(zone()) HBasicBlock(this); 3849 HBasicBlock* result = new(zone()) HBasicBlock(this);
3805 blocks_.Add(result, zone()); 3850 blocks_.Add(result, zone());
3806 return result; 3851 return result;
3807 } 3852 }
3808 3853
3809 3854
3810 void HGraph::FinalizeUniqueness() { 3855 void HGraph::FinalizeUniqueness() {
3811 DisallowHeapAllocation no_gc; 3856 DisallowHeapAllocation no_gc;
3812 for (int i = 0; i < blocks()->length(); ++i) { 3857 for (int i = 0; i < blocks()->length(); ++i) {
3813 for (HInstructionIterator it(blocks()->at(i)); !it.Done(); it.Advance()) { 3858 for (HInstructionIterator it(blocks()->at(i)); !it.Done(); it.Advance()) {
3814 it.Current()->FinalizeUniqueness(); 3859 it.Current()->FinalizeUniqueness();
3815 } 3860 }
3816 } 3861 }
3817 } 3862 }
3818 3863
3819 3864
3820 int HGraph::SourcePositionToScriptPosition(SourcePosition pos) { 3865 int HGraph::SourcePositionToScriptPosition(SourcePosition pos) {
3821 return (FLAG_hydrogen_track_positions && !pos.IsUnknown()) 3866 return (FLAG_hydrogen_track_positions && !pos.IsUnknown())
3822 ? info()->start_position_for(pos.inlining_id()) + pos.position() 3867 ? info()->inlined_function_infos()
3868 .at(pos.inlining_id())
3869 .start_position +
3870 pos.position()
3823 : pos.raw(); 3871 : pos.raw();
3824 } 3872 }
3825 3873
3826 3874
3827 // Block ordering was implemented with two mutually recursive methods, 3875 // Block ordering was implemented with two mutually recursive methods,
3828 // HGraph::Postorder and HGraph::PostorderLoopBlocks. 3876 // HGraph::Postorder and HGraph::PostorderLoopBlocks.
3829 // The recursion could lead to stack overflow so the algorithm has been 3877 // The recursion could lead to stack overflow so the algorithm has been
3830 // implemented iteratively. 3878 // implemented iteratively.
3831 // At a high level the algorithm looks like this: 3879 // At a high level the algorithm looks like this:
3832 // 3880 //
(...skipping 4807 matching lines...) Expand 10 before | Expand all | Expand 10 after
8640 // TryInline should always return true). 8688 // TryInline should always return true).
8641 8689
8642 // Type-check the inlined function. 8690 // Type-check the inlined function.
8643 DCHECK(target_shared->has_deoptimization_support()); 8691 DCHECK(target_shared->has_deoptimization_support());
8644 AstTyper(target_info.isolate(), target_info.zone(), target_info.closure(), 8692 AstTyper(target_info.isolate(), target_info.zone(), target_info.closure(),
8645 target_info.scope(), target_info.osr_ast_id(), target_info.literal()) 8693 target_info.scope(), target_info.osr_ast_id(), target_info.literal())
8646 .Run(); 8694 .Run();
8647 8695
8648 int inlining_id = 0; 8696 int inlining_id = 0;
8649 if (top_info()->is_tracking_positions()) { 8697 if (top_info()->is_tracking_positions()) {
8650 inlining_id = top_info()->TraceInlinedFunction( 8698 inlining_id = TraceInlinedFunction(target_shared, source_position(),
8651 target_shared, source_position(), function_state()->inlining_id()); 8699 function_state()->inlining_id());
8652 } 8700 }
8653 8701
8654 // Save the pending call context. Set up new one for the inlined function. 8702 // Save the pending call context. Set up new one for the inlined function.
8655 // The function state is new-allocated because we need to delete it 8703 // The function state is new-allocated because we need to delete it
8656 // in two different places. 8704 // in two different places.
8657 FunctionState* target_state = new FunctionState( 8705 FunctionState* target_state = new FunctionState(
8658 this, &target_info, inlining_kind, inlining_id, 8706 this, &target_info, inlining_kind, inlining_id,
8659 function_state()->ComputeTailCallMode(syntactic_tail_call_mode)); 8707 function_state()->ComputeTailCallMode(syntactic_tail_call_mode));
8660 8708
8661 HConstant* undefined = graph()->GetConstantUndefined(); 8709 HConstant* undefined = graph()->GetConstantUndefined();
(...skipping 5061 matching lines...) Expand 10 before | Expand all | Expand 10 after
13723 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 13771 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
13724 } 13772 }
13725 13773
13726 #ifdef DEBUG 13774 #ifdef DEBUG
13727 graph_->Verify(false); // No full verify. 13775 graph_->Verify(false); // No full verify.
13728 #endif 13776 #endif
13729 } 13777 }
13730 13778
13731 } // namespace internal 13779 } // namespace internal
13732 } // namespace v8 13780 } // namespace v8
OLDNEW
« no previous file with comments | « src/crankshaft/hydrogen.h ('k') | src/crankshaft/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698