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

Unified Diff: src/full-codegen.cc

Issue 7860045: Stack allocating block scoped variables. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased on tip of tree. Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/full-codegen.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/full-codegen.cc
diff --git a/src/full-codegen.cc b/src/full-codegen.cc
index 960700b9e65ea41ff2cdef46ba8a0b0a84327dc3..f4aa1f3e823e74c0a6891c9c150b229cc0608757 100644
--- a/src/full-codegen.cc
+++ b/src/full-codegen.cc
@@ -795,12 +795,29 @@ void FullCodeGenerator::VisitBlock(Block* stmt) {
SetStatementPosition(stmt);
Scope* saved_scope = scope();
- // Push a block context when entering a block with block scoped variables.
if (stmt->block_scope() != NULL) {
- { Comment cmnt(masm_, "[ Extend block context");
- scope_ = stmt->block_scope();
+ scope_ = stmt->block_scope();
+ int num_stack_slots = scope_->num_stack_slots();
+
+ // Allocate stack locals.
+ if (num_stack_slots > 0) {
+ Comment cmnt(masm_, "[ Allocate block stack locals");
+ if (num_stack_slots == 1) {
+ __ Push(isolate()->factory()->the_hole_value());
+ } else {
+ __ Move(result_register(), isolate()->factory()->the_hole_value());
+ for (int i = 0; i < num_stack_slots; i++) {
+ __ push(result_register());
+ }
+ }
+ }
+
+ // Allocate context locals.
+ if (scope_->num_heap_slots() > 0) {
+ Comment cmnt(masm_, "[ Extend block context");
Handle<ScopeInfo> scope_info = scope_->GetScopeInfo();
- int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS;
+ int heap_slots =
+ scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS;
__ Push(scope_info);
PushFunctionArgumentForContextAllocation();
if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) {
@@ -824,12 +841,22 @@ void FullCodeGenerator::VisitBlock(Block* stmt) {
__ bind(nested_block.break_label());
PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
- // Pop block context if necessary.
if (stmt->block_scope() != NULL) {
- LoadContextField(context_register(), Context::PREVIOUS_INDEX);
- // Update local stack frame context field.
- StoreToFrameField(StandardFrameConstants::kContextOffset,
- context_register());
+ Scope* scope = stmt->block_scope();
+ int num_stack_slots = scope->num_stack_slots();
+
+ // Pop block context if necessary.
+ if (scope->num_heap_slots() > 0) {
+ LoadContextField(context_register(), Context::PREVIOUS_INDEX);
+ // Update local stack frame context field.
+ StoreToFrameField(StandardFrameConstants::kContextOffset,
+ context_register());
+ }
+
+ // Deallocate stack locals.
+ if (num_stack_slots > 0) {
+ __ Drop(num_stack_slots);
+ }
}
}
@@ -1271,6 +1298,46 @@ void FullCodeGenerator::VisitThrow(Throw* expr) {
}
+FullCodeGenerator::NestedStatement::NestedStatement(
+ FullCodeGenerator* codegen, int stack_delta)
+ : codegen_(codegen), stack_delta_(stack_delta) {
+ // Link into codegen's nesting stack.
+ previous_ = codegen->nesting_stack_;
+ codegen->nesting_stack_ = this;
+ stack_depth_ = stack_delta_;
+ if (previous_ != NULL) {
+ stack_depth_ += previous_->StackDepth();
+ } else {
+ stack_depth_ += codegen->function()->scope()->num_stack_slots();
+ }
+}
+
+
+FullCodeGenerator::NestedBlock::NestedBlock(
+ FullCodeGenerator* codegen, Block* block)
+ : Breakable(codegen,
+ block,
+ block->block_scope() == NULL ? 0
+ : block->block_scope()->num_stack_slots()) {
+ Scope* scope = block->block_scope();
+ if (scope != NULL) {
+ scope->set_stack_slots_depth(StackDepthBase());
+ }
+}
+
+
+FullCodeGenerator::NestedStatement* FullCodeGenerator::NestedBlock::Exit(
+ int* stack_depth,
+ int* context_length) {
+ Scope* scope = statement()->AsBlock()->block_scope();
+ if (scope != NULL) {
+ if (scope->num_heap_slots() > 0) ++(*context_length);
+ *stack_depth += scope->num_stack_slots();
+ }
+ return previous_;
+}
+
+
FullCodeGenerator::NestedStatement* FullCodeGenerator::TryCatch::Exit(
int* stack_depth,
int* context_length) {
« no previous file with comments | « src/full-codegen.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698