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

Side by Side Diff: src/full-codegen.cc

Issue 185653004: Experimental parser: merge to r19637 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/full-codegen.h ('k') | src/gdb-jit.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } 338 }
339 unsigned table_offset = cgen.EmitBackEdgeTable(); 339 unsigned table_offset = cgen.EmitBackEdgeTable();
340 340
341 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION); 341 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION);
342 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info); 342 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info);
343 code->set_optimizable(info->IsOptimizable() && 343 code->set_optimizable(info->IsOptimizable() &&
344 !info->function()->dont_optimize() && 344 !info->function()->dont_optimize() &&
345 info->function()->scope()->AllowsLazyCompilation()); 345 info->function()->scope()->AllowsLazyCompilation());
346 cgen.PopulateDeoptimizationData(code); 346 cgen.PopulateDeoptimizationData(code);
347 cgen.PopulateTypeFeedbackInfo(code); 347 cgen.PopulateTypeFeedbackInfo(code);
348 cgen.PopulateTypeFeedbackCells(code);
349 code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); 348 code->set_has_deoptimization_support(info->HasDeoptimizationSupport());
350 code->set_handler_table(*cgen.handler_table()); 349 code->set_handler_table(*cgen.handler_table());
351 #ifdef ENABLE_DEBUGGER_SUPPORT 350 #ifdef ENABLE_DEBUGGER_SUPPORT
352 code->set_compiled_optimizable(info->IsOptimizable()); 351 code->set_compiled_optimizable(info->IsOptimizable());
353 #endif // ENABLE_DEBUGGER_SUPPORT 352 #endif // ENABLE_DEBUGGER_SUPPORT
354 code->set_allow_osr_at_loop_nesting_level(0); 353 code->set_allow_osr_at_loop_nesting_level(0);
355 code->set_profiler_ticks(0); 354 code->set_profiler_ticks(0);
356 code->set_back_edge_table_offset(table_offset); 355 code->set_back_edge_table_offset(table_offset);
357 code->set_back_edges_patched_for_osr(false); 356 code->set_back_edges_patched_for_osr(false);
358 CodeGenerator::PrintCode(code, info); 357 CodeGenerator::PrintCode(code, info);
(...skipping 21 matching lines...) Expand all
380 __ dd(length); 379 __ dd(length);
381 for (unsigned i = 0; i < length; ++i) { 380 for (unsigned i = 0; i < length; ++i) {
382 __ dd(back_edges_[i].id.ToInt()); 381 __ dd(back_edges_[i].id.ToInt());
383 __ dd(back_edges_[i].pc); 382 __ dd(back_edges_[i].pc);
384 __ dd(back_edges_[i].loop_depth); 383 __ dd(back_edges_[i].loop_depth);
385 } 384 }
386 return offset; 385 return offset;
387 } 386 }
388 387
389 388
389 void FullCodeGenerator::InitializeFeedbackVector() {
390 int length = info_->function()->slot_count();
391 ASSERT_EQ(isolate()->heap()->the_hole_value(),
392 *TypeFeedbackInfo::UninitializedSentinel(isolate()));
393 feedback_vector_ = isolate()->factory()->NewFixedArrayWithHoles(length,
394 TENURED);
395 }
396
397
390 void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { 398 void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) {
391 // Fill in the deoptimization information. 399 // Fill in the deoptimization information.
392 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); 400 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty());
393 if (!info_->HasDeoptimizationSupport()) return; 401 if (!info_->HasDeoptimizationSupport()) return;
394 int length = bailout_entries_.length(); 402 int length = bailout_entries_.length();
395 Handle<DeoptimizationOutputData> data = isolate()->factory()-> 403 Handle<DeoptimizationOutputData> data = isolate()->factory()->
396 NewDeoptimizationOutputData(length, TENURED); 404 NewDeoptimizationOutputData(length, TENURED);
397 for (int i = 0; i < length; i++) { 405 for (int i = 0; i < length; i++) {
398 data->SetAstId(i, bailout_entries_[i].id); 406 data->SetAstId(i, bailout_entries_[i].id);
399 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); 407 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state));
400 } 408 }
401 code->set_deoptimization_data(*data); 409 code->set_deoptimization_data(*data);
402 } 410 }
403 411
404 412
405 void FullCodeGenerator::PopulateTypeFeedbackInfo(Handle<Code> code) { 413 void FullCodeGenerator::PopulateTypeFeedbackInfo(Handle<Code> code) {
406 Handle<TypeFeedbackInfo> info = isolate()->factory()->NewTypeFeedbackInfo(); 414 Handle<TypeFeedbackInfo> info = isolate()->factory()->NewTypeFeedbackInfo();
407 info->set_ic_total_count(ic_total_count_); 415 info->set_ic_total_count(ic_total_count_);
416 info->set_feedback_vector(*FeedbackVector());
408 ASSERT(!isolate()->heap()->InNewSpace(*info)); 417 ASSERT(!isolate()->heap()->InNewSpace(*info));
409 code->set_type_feedback_info(*info); 418 code->set_type_feedback_info(*info);
410 } 419 }
411 420
412 421
413 void FullCodeGenerator::Initialize() { 422 void FullCodeGenerator::Initialize() {
414 // The generation of debug code must match between the snapshot code and the 423 // The generation of debug code must match between the snapshot code and the
415 // code that is generated later. This is assumed by the debugger when it is 424 // code that is generated later. This is assumed by the debugger when it is
416 // calculating PC offsets after generating a debug version of code. Therefore 425 // calculating PC offsets after generating a debug version of code. Therefore
417 // we disable the production of debug code in the full compiler if we are 426 // we disable the production of debug code in the full compiler if we are
418 // either generating a snapshot or we booted from a snapshot. 427 // either generating a snapshot or we booted from a snapshot.
419 generate_debug_code_ = FLAG_debug_code && 428 generate_debug_code_ = FLAG_debug_code &&
420 !Serializer::enabled() && 429 !Serializer::enabled() &&
421 !Snapshot::HaveASnapshotToStartFrom(); 430 !Snapshot::HaveASnapshotToStartFrom();
422 masm_->set_emit_debug_code(generate_debug_code_); 431 masm_->set_emit_debug_code(generate_debug_code_);
423 masm_->set_predictable_code_size(true); 432 masm_->set_predictable_code_size(true);
424 InitializeAstVisitor(info_->isolate()); 433 InitializeAstVisitor(info_->zone());
425 } 434 }
426 435
427 436
428 void FullCodeGenerator::PopulateTypeFeedbackCells(Handle<Code> code) {
429 if (type_feedback_cells_.is_empty()) return;
430 int length = type_feedback_cells_.length();
431 int array_size = TypeFeedbackCells::LengthOfFixedArray(length);
432 Handle<TypeFeedbackCells> cache = Handle<TypeFeedbackCells>::cast(
433 isolate()->factory()->NewFixedArray(array_size, TENURED));
434 for (int i = 0; i < length; i++) {
435 cache->SetAstId(i, type_feedback_cells_[i].ast_id);
436 cache->SetCell(i, *type_feedback_cells_[i].cell);
437 }
438 TypeFeedbackInfo::cast(code->type_feedback_info())->set_type_feedback_cells(
439 *cache);
440 }
441
442
443 void FullCodeGenerator::PrepareForBailout(Expression* node, State state) { 437 void FullCodeGenerator::PrepareForBailout(Expression* node, State state) {
444 PrepareForBailoutForId(node->id(), state); 438 PrepareForBailoutForId(node->id(), state);
445 } 439 }
446 440
447 441
448 void FullCodeGenerator::CallLoadIC(ContextualMode mode, TypeFeedbackId id) { 442 void FullCodeGenerator::CallLoadIC(ContextualMode contextual_mode,
449 Handle<Code> ic = LoadIC::initialize_stub(isolate(), mode); 443 TypeFeedbackId id) {
450 CallIC(ic, mode, id); 444 ExtraICState extra_state = LoadIC::ComputeExtraICState(contextual_mode);
445 Handle<Code> ic = LoadIC::initialize_stub(isolate(), extra_state);
446 CallIC(ic, id);
451 } 447 }
452 448
453 449
454 void FullCodeGenerator::CallStoreIC(ContextualMode mode, TypeFeedbackId id) { 450 void FullCodeGenerator::CallStoreIC(TypeFeedbackId id) {
455 Handle<Code> ic = StoreIC::initialize_stub(isolate(), strict_mode()); 451 Handle<Code> ic = StoreIC::initialize_stub(isolate(), strict_mode());
456 CallIC(ic, mode, id); 452 CallIC(ic, id);
457 } 453 }
458 454
459 455
460 void FullCodeGenerator::RecordJSReturnSite(Call* call) { 456 void FullCodeGenerator::RecordJSReturnSite(Call* call) {
461 // We record the offset of the function return so we can rebuild the frame 457 // We record the offset of the function return so we can rebuild the frame
462 // if the function was inlined, i.e., this is the return address in the 458 // if the function was inlined, i.e., this is the return address in the
463 // inlined function's frame. 459 // inlined function's frame.
464 // 460 //
465 // The state is ignored. We defensively set it to TOS_REG, which is the 461 // The state is ignored. We defensively set it to TOS_REG, which is the
466 // real state of the unoptimized code at the return site. 462 // real state of the unoptimized code at the return site.
(...skipping 14 matching lines...) Expand all
481 unsigned pc_and_state = 477 unsigned pc_and_state =
482 StateField::encode(state) | PcField::encode(masm_->pc_offset()); 478 StateField::encode(state) | PcField::encode(masm_->pc_offset());
483 ASSERT(Smi::IsValid(pc_and_state)); 479 ASSERT(Smi::IsValid(pc_and_state));
484 BailoutEntry entry = { id, pc_and_state }; 480 BailoutEntry entry = { id, pc_and_state };
485 ASSERT(!prepared_bailout_ids_.Contains(id.ToInt())); 481 ASSERT(!prepared_bailout_ids_.Contains(id.ToInt()));
486 prepared_bailout_ids_.Add(id.ToInt(), zone()); 482 prepared_bailout_ids_.Add(id.ToInt(), zone());
487 bailout_entries_.Add(entry, zone()); 483 bailout_entries_.Add(entry, zone());
488 } 484 }
489 485
490 486
491 void FullCodeGenerator::RecordTypeFeedbackCell(
492 TypeFeedbackId id, Handle<Cell> cell) {
493 TypeFeedbackCellEntry entry = { id, cell };
494 type_feedback_cells_.Add(entry, zone());
495 }
496
497
498 void FullCodeGenerator::RecordBackEdge(BailoutId ast_id) { 487 void FullCodeGenerator::RecordBackEdge(BailoutId ast_id) {
499 // The pc offset does not need to be encoded and packed together with a state. 488 // The pc offset does not need to be encoded and packed together with a state.
500 ASSERT(masm_->pc_offset() > 0); 489 ASSERT(masm_->pc_offset() > 0);
501 ASSERT(loop_depth() > 0); 490 ASSERT(loop_depth() > 0);
502 uint8_t depth = Min(loop_depth(), Code::kMaxLoopNestingMarker); 491 uint8_t depth = Min(loop_depth(), Code::kMaxLoopNestingMarker);
503 BackEdgeEntry entry = 492 BackEdgeEntry entry =
504 { ast_id, static_cast<unsigned>(masm_->pc_offset()), depth }; 493 { ast_id, static_cast<unsigned>(masm_->pc_offset()), depth };
505 back_edges_.Add(entry, zone()); 494 back_edges_.Add(entry, zone());
506 } 495 }
507 496
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 } 829 }
841 830
842 831
843 void FullCodeGenerator::SetStatementPosition(Statement* stmt) { 832 void FullCodeGenerator::SetStatementPosition(Statement* stmt) {
844 #ifdef ENABLE_DEBUGGER_SUPPORT 833 #ifdef ENABLE_DEBUGGER_SUPPORT
845 if (!isolate()->debugger()->IsDebuggerActive()) { 834 if (!isolate()->debugger()->IsDebuggerActive()) {
846 CodeGenerator::RecordPositions(masm_, stmt->position()); 835 CodeGenerator::RecordPositions(masm_, stmt->position());
847 } else { 836 } else {
848 // Check if the statement will be breakable without adding a debug break 837 // Check if the statement will be breakable without adding a debug break
849 // slot. 838 // slot.
850 BreakableStatementChecker checker(isolate()); 839 BreakableStatementChecker checker(zone());
851 checker.Check(stmt); 840 checker.Check(stmt);
852 // Record the statement position right here if the statement is not 841 // Record the statement position right here if the statement is not
853 // breakable. For breakable statements the actual recording of the 842 // breakable. For breakable statements the actual recording of the
854 // position will be postponed to the breakable code (typically an IC). 843 // position will be postponed to the breakable code (typically an IC).
855 bool position_recorded = CodeGenerator::RecordPositions( 844 bool position_recorded = CodeGenerator::RecordPositions(
856 masm_, stmt->position(), !checker.is_breakable()); 845 masm_, stmt->position(), !checker.is_breakable());
857 // If the position recording did record a new position generate a debug 846 // If the position recording did record a new position generate a debug
858 // break slot to make the statement breakable. 847 // break slot to make the statement breakable.
859 if (position_recorded) { 848 if (position_recorded) {
860 Debug::GenerateSlot(masm_); 849 Debug::GenerateSlot(masm_);
861 } 850 }
862 } 851 }
863 #else 852 #else
864 CodeGenerator::RecordPositions(masm_, stmt->position()); 853 CodeGenerator::RecordPositions(masm_, stmt->position());
865 #endif 854 #endif
866 } 855 }
867 856
868 857
869 void FullCodeGenerator::SetExpressionPosition(Expression* expr) { 858 void FullCodeGenerator::SetExpressionPosition(Expression* expr) {
870 #ifdef ENABLE_DEBUGGER_SUPPORT 859 #ifdef ENABLE_DEBUGGER_SUPPORT
871 if (!isolate()->debugger()->IsDebuggerActive()) { 860 if (!isolate()->debugger()->IsDebuggerActive()) {
872 CodeGenerator::RecordPositions(masm_, expr->position()); 861 CodeGenerator::RecordPositions(masm_, expr->position());
873 } else { 862 } else {
874 // Check if the expression will be breakable without adding a debug break 863 // Check if the expression will be breakable without adding a debug break
875 // slot. 864 // slot.
876 BreakableStatementChecker checker(isolate()); 865 BreakableStatementChecker checker(zone());
877 checker.Check(expr); 866 checker.Check(expr);
878 // Record a statement position right here if the expression is not 867 // Record a statement position right here if the expression is not
879 // breakable. For breakable expressions the actual recording of the 868 // breakable. For breakable expressions the actual recording of the
880 // position will be postponed to the breakable code (typically an IC). 869 // position will be postponed to the breakable code (typically an IC).
881 // NOTE this will record a statement position for something which might 870 // NOTE this will record a statement position for something which might
882 // not be a statement. As stepping in the debugger will only stop at 871 // not be a statement. As stepping in the debugger will only stop at
883 // statement positions this is used for e.g. the condition expression of 872 // statement positions this is used for e.g. the condition expression of
884 // a do while loop. 873 // a do while loop.
885 bool position_recorded = CodeGenerator::RecordPositions( 874 bool position_recorded = CodeGenerator::RecordPositions(
886 masm_, expr->position(), !checker.is_breakable()); 875 masm_, expr->position(), !checker.is_breakable());
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 Comment cmnt(masm_, "[ Block"); 1080 Comment cmnt(masm_, "[ Block");
1092 NestedBlock nested_block(this, stmt); 1081 NestedBlock nested_block(this, stmt);
1093 SetStatementPosition(stmt); 1082 SetStatementPosition(stmt);
1094 1083
1095 Scope* saved_scope = scope(); 1084 Scope* saved_scope = scope();
1096 // Push a block context when entering a block with block scoped variables. 1085 // Push a block context when entering a block with block scoped variables.
1097 if (stmt->scope() != NULL) { 1086 if (stmt->scope() != NULL) {
1098 scope_ = stmt->scope(); 1087 scope_ = stmt->scope();
1099 ASSERT(!scope_->is_module_scope()); 1088 ASSERT(!scope_->is_module_scope());
1100 { Comment cmnt(masm_, "[ Extend block context"); 1089 { Comment cmnt(masm_, "[ Extend block context");
1101 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); 1090 __ Push(scope_->GetScopeInfo());
1102 int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS;
1103 __ Push(scope_info);
1104 PushFunctionArgumentForContextAllocation(); 1091 PushFunctionArgumentForContextAllocation();
1105 if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) { 1092 __ CallRuntime(Runtime::kPushBlockContext, 2);
1106 FastNewBlockContextStub stub(heap_slots);
1107 __ CallStub(&stub);
1108 } else {
1109 __ CallRuntime(Runtime::kPushBlockContext, 2);
1110 }
1111 1093
1112 // Replace the context stored in the frame. 1094 // Replace the context stored in the frame.
1113 StoreToFrameField(StandardFrameConstants::kContextOffset, 1095 StoreToFrameField(StandardFrameConstants::kContextOffset,
1114 context_register()); 1096 context_register());
1115 } 1097 }
1116 { Comment cmnt(masm_, "[ Declarations"); 1098 { Comment cmnt(masm_, "[ Declarations");
1117 VisitDeclarations(scope_->declarations()); 1099 VisitDeclarations(scope_->declarations());
1118 } 1100 }
1119 } 1101 }
1120 1102
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 } 1728 }
1747 return true; 1729 return true;
1748 } 1730 }
1749 #endif // DEBUG 1731 #endif // DEBUG
1750 1732
1751 1733
1752 #undef __ 1734 #undef __
1753 1735
1754 1736
1755 } } // namespace v8::internal 1737 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/full-codegen.h ('k') | src/gdb-jit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698