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

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

Issue 113259: Inline the code dealing with entering spilled scopes and maintaining a... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 bool is_eval) 76 bool is_eval)
77 : is_eval_(is_eval), 77 : is_eval_(is_eval),
78 script_(script), 78 script_(script),
79 deferred_(8), 79 deferred_(8),
80 masm_(new MacroAssembler(NULL, buffer_size)), 80 masm_(new MacroAssembler(NULL, buffer_size)),
81 scope_(NULL), 81 scope_(NULL),
82 frame_(NULL), 82 frame_(NULL),
83 allocator_(NULL), 83 allocator_(NULL),
84 state_(NULL), 84 state_(NULL),
85 loop_nesting_(0), 85 loop_nesting_(0),
86 function_return_is_shadowed_(false), 86 function_return_is_shadowed_(false) {
87 in_spilled_code_(false) { 87 #ifdef DEBUG
88 in_spilled_code_ = false;
89 #endif
88 } 90 }
89 91
90 92
91 // Calling conventions: 93 // Calling conventions:
92 // ebp: caller's frame pointer 94 // ebp: caller's frame pointer
93 // esp: stack pointer 95 // esp: stack pointer
94 // edi: called JS function 96 // edi: called JS function
95 // esi: callee's context 97 // esi: callee's context
96 98
97 void CodeGenerator::GenCode(FunctionLiteral* fun) { 99 void CodeGenerator::GenCode(FunctionLiteral* fun) {
98 // Record the position for debugging purposes. 100 // Record the position for debugging purposes.
99 CodeForFunctionPosition(fun); 101 CodeForFunctionPosition(fun);
100 102
101 ZoneList<Statement*>* body = fun->body(); 103 ZoneList<Statement*>* body = fun->body();
102 104
103 // Initialize state. 105 // Initialize state.
104 ASSERT(scope_ == NULL); 106 ASSERT(scope_ == NULL);
105 scope_ = fun->scope(); 107 scope_ = fun->scope();
106 ASSERT(allocator_ == NULL); 108 ASSERT(allocator_ == NULL);
107 RegisterAllocator register_allocator(this); 109 RegisterAllocator register_allocator(this);
108 allocator_ = &register_allocator; 110 allocator_ = &register_allocator;
109 ASSERT(frame_ == NULL); 111 ASSERT(frame_ == NULL);
110 frame_ = new VirtualFrame(this); 112 frame_ = new VirtualFrame(this);
111 set_in_spilled_code(false); 113 ASSERT(!in_spilled_code());
112 114
113 // Adjust for function-level loop nesting. 115 // Adjust for function-level loop nesting.
114 loop_nesting_ += fun->loop_nesting(); 116 loop_nesting_ += fun->loop_nesting();
115 117
116 { 118 {
117 CodeGenState state(this); 119 CodeGenState state(this);
118 120
119 // Entry: 121 // Entry:
120 // Stack: receiver, arguments, return address. 122 // Stack: receiver, arguments, return address.
121 // ebp: caller's frame pointer 123 // ebp: caller's frame pointer
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 if (force_control && !dest->is_used()) { 441 if (force_control && !dest->is_used()) {
440 // Convert the TOS value into flow to the control destination. 442 // Convert the TOS value into flow to the control destination.
441 ToBoolean(dest); 443 ToBoolean(dest);
442 } 444 }
443 445
444 ASSERT(!(force_control && !dest->is_used())); 446 ASSERT(!(force_control && !dest->is_used()));
445 ASSERT(dest->is_used() || frame_->height() == original_height + 1); 447 ASSERT(dest->is_used() || frame_->height() == original_height + 1);
446 } 448 }
447 449
448 450
449 void CodeGenerator::LoadAndSpill(Expression* expression,
450 TypeofState typeof_state) {
451 ASSERT(in_spilled_code());
452 set_in_spilled_code(false);
453 Load(expression, typeof_state);
454 frame_->SpillAll();
455 set_in_spilled_code(true);
456 }
457
458
459 void CodeGenerator::Load(Expression* x, TypeofState typeof_state) { 451 void CodeGenerator::Load(Expression* x, TypeofState typeof_state) {
460 #ifdef DEBUG 452 #ifdef DEBUG
461 int original_height = frame_->height(); 453 int original_height = frame_->height();
462 #endif 454 #endif
463 ASSERT(!in_spilled_code()); 455 ASSERT(!in_spilled_code());
464 JumpTarget true_target(this); 456 JumpTarget true_target(this);
465 JumpTarget false_target(this); 457 JumpTarget false_target(this);
466 ControlDestination dest(&true_target, &false_target, true); 458 ControlDestination dest(&true_target, &false_target, true);
467 LoadCondition(x, typeof_state, &dest, false); 459 LoadCondition(x, typeof_state, &dest, false);
468 460
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 loaded.Bind(); 505 loaded.Bind();
514 } 506 }
515 } 507 }
516 508
517 ASSERT(has_valid_frame()); 509 ASSERT(has_valid_frame());
518 ASSERT(frame_->height() == original_height + 1); 510 ASSERT(frame_->height() == original_height + 1);
519 } 511 }
520 512
521 513
522 void CodeGenerator::LoadGlobal() { 514 void CodeGenerator::LoadGlobal() {
523 if (in_spilled_code()) { 515 ASSERT(!in_spilled_code());
524 frame_->EmitPush(GlobalObject()); 516 Result temp = allocator_->Allocate();
525 } else { 517 __ mov(temp.reg(), GlobalObject());
526 Result temp = allocator_->Allocate(); 518 frame_->Push(&temp);
527 __ mov(temp.reg(), GlobalObject());
528 frame_->Push(&temp);
529 }
530 } 519 }
531 520
532 521
533 void CodeGenerator::LoadGlobalReceiver() { 522 void CodeGenerator::LoadGlobalReceiver() {
534 Result temp = allocator_->Allocate(); 523 Result temp = allocator_->Allocate();
535 Register reg = temp.reg(); 524 Register reg = temp.reg();
536 __ mov(reg, GlobalObject()); 525 __ mov(reg, GlobalObject());
537 __ mov(reg, FieldOperand(reg, GlobalObject::kGlobalReceiverOffset)); 526 __ mov(reg, FieldOperand(reg, GlobalObject::kGlobalReceiverOffset));
538 frame_->Push(&temp); 527 frame_->Push(&temp);
539 } 528 }
(...skipping 25 matching lines...) Expand all
565 cgen->LoadReference(this); 554 cgen->LoadReference(this);
566 } 555 }
567 556
568 557
569 Reference::~Reference() { 558 Reference::~Reference() {
570 cgen_->UnloadReference(this); 559 cgen_->UnloadReference(this);
571 } 560 }
572 561
573 562
574 void CodeGenerator::LoadReference(Reference* ref) { 563 void CodeGenerator::LoadReference(Reference* ref) {
564 #ifdef DEBUG
575 // References are loaded from both spilled and unspilled code. Set the 565 // References are loaded from both spilled and unspilled code. Set the
576 // state to unspilled to allow that (and explicitly spill after 566 // state to unspilled to allow that (and explicitly spill after
577 // construction at the construction sites). 567 // construction at the construction sites, if necessary).
578 bool was_in_spilled_code = in_spilled_code_; 568 bool was_in_spilled_code = in_spilled_code_;
579 in_spilled_code_ = false; 569 in_spilled_code_ = false;
570 #endif
580 571
581 Comment cmnt(masm_, "[ LoadReference"); 572 Comment cmnt(masm_, "[ LoadReference");
582 Expression* e = ref->expression(); 573 Expression* e = ref->expression();
583 Property* property = e->AsProperty(); 574 Property* property = e->AsProperty();
584 Variable* var = e->AsVariableProxy()->AsVariable(); 575 Variable* var = e->AsVariableProxy()->AsVariable();
585 576
586 if (property != NULL) { 577 if (property != NULL) {
587 // The expression is either a property or a variable proxy that rewrites 578 // The expression is either a property or a variable proxy that rewrites
588 // to a property. 579 // to a property.
589 Load(property->obj()); 580 Load(property->obj());
(...skipping 20 matching lines...) Expand all
610 } else { 601 } else {
611 ASSERT(var->slot() != NULL); 602 ASSERT(var->slot() != NULL);
612 ref->set_type(Reference::SLOT); 603 ref->set_type(Reference::SLOT);
613 } 604 }
614 } else { 605 } else {
615 // Anything else is a runtime error. 606 // Anything else is a runtime error.
616 Load(e); 607 Load(e);
617 frame_->CallRuntime(Runtime::kThrowReferenceError, 1); 608 frame_->CallRuntime(Runtime::kThrowReferenceError, 1);
618 } 609 }
619 610
611 #ifdef DEBUG
620 in_spilled_code_ = was_in_spilled_code; 612 in_spilled_code_ = was_in_spilled_code;
613 #endif
621 } 614 }
622 615
623 616
624 void CodeGenerator::UnloadReference(Reference* ref) { 617 void CodeGenerator::UnloadReference(Reference* ref) {
625 // Pop a reference from the stack while preserving TOS. 618 // Pop a reference from the stack while preserving TOS.
626 Comment cmnt(masm_, "[ UnloadReference"); 619 Comment cmnt(masm_, "[ UnloadReference");
627 frame_->Nip(ref->size()); 620 frame_->Nip(ref->size());
628 } 621 }
629 622
630 623
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 DeferredStackCheck* deferred = new DeferredStackCheck(this); 1702 DeferredStackCheck* deferred = new DeferredStackCheck(this);
1710 ExternalReference stack_guard_limit = 1703 ExternalReference stack_guard_limit =
1711 ExternalReference::address_of_stack_guard_limit(); 1704 ExternalReference::address_of_stack_guard_limit();
1712 __ cmp(esp, Operand::StaticVariable(stack_guard_limit)); 1705 __ cmp(esp, Operand::StaticVariable(stack_guard_limit));
1713 deferred->enter()->Branch(below, not_taken); 1706 deferred->enter()->Branch(below, not_taken);
1714 deferred->BindExit(); 1707 deferred->BindExit();
1715 } 1708 }
1716 } 1709 }
1717 1710
1718 1711
1719 void CodeGenerator::VisitAndSpill(Statement* statement) {
1720 ASSERT(in_spilled_code());
1721 set_in_spilled_code(false);
1722 Visit(statement);
1723 if (frame_ != NULL) {
1724 frame_->SpillAll();
1725 }
1726 set_in_spilled_code(true);
1727 }
1728
1729
1730 void CodeGenerator::VisitStatementsAndSpill(ZoneList<Statement*>* statements) {
1731 ASSERT(in_spilled_code());
1732 set_in_spilled_code(false);
1733 VisitStatements(statements);
1734 if (frame_ != NULL) {
1735 frame_->SpillAll();
1736 }
1737 set_in_spilled_code(true);
1738 }
1739
1740
1741 void CodeGenerator::VisitStatements(ZoneList<Statement*>* statements) { 1712 void CodeGenerator::VisitStatements(ZoneList<Statement*>* statements) {
1742 ASSERT(!in_spilled_code()); 1713 ASSERT(!in_spilled_code());
1743 for (int i = 0; has_valid_frame() && i < statements->length(); i++) { 1714 for (int i = 0; has_valid_frame() && i < statements->length(); i++) {
1744 Visit(statements->at(i)); 1715 Visit(statements->at(i));
1745 } 1716 }
1746 } 1717 }
1747 1718
1748 1719
1749 void CodeGenerator::VisitBlock(Block* node) { 1720 void CodeGenerator::VisitBlock(Block* node) {
1750 ASSERT(!in_spilled_code()); 1721 ASSERT(!in_spilled_code());
(...skipping 5478 matching lines...) Expand 10 before | Expand all | Expand 10 after
7229 7200
7230 // Slow-case: Go through the JavaScript implementation. 7201 // Slow-case: Go through the JavaScript implementation.
7231 __ bind(&slow); 7202 __ bind(&slow);
7232 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); 7203 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
7233 } 7204 }
7234 7205
7235 7206
7236 #undef __ 7207 #undef __
7237 7208
7238 } } // namespace v8::internal 7209 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698