Revision: 9112
Author:   [email protected]
Date:     Thu Sep  1 09:33:57 2011
Log:      Support declarations of context allocated locals in Crankshaft.

The changes to scopes and parser introduce a VariableProxy
wrapping the function-name variable for function literals.
It seems the easiest way to get an AST id for the HSimulate
after context-slot stores in declarations.
Review URL: http://codereview.chromium.org/7826009
http://code.google.com/p/v8/source/detail?r=9112

Modified:
 /branches/bleeding_edge/src/arm/full-codegen-arm.cc
 /branches/bleeding_edge/src/full-codegen.h
 /branches/bleeding_edge/src/hydrogen.cc
 /branches/bleeding_edge/src/hydrogen.h
 /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
 /branches/bleeding_edge/src/scopeinfo.cc
 /branches/bleeding_edge/src/scopes.cc
 /branches/bleeding_edge/src/scopes.h
 /branches/bleeding_edge/src/x64/full-codegen-x64.cc

=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Thu Sep 1 05:31:18 2011 +++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Thu Sep 1 09:33:57 2011
@@ -688,10 +688,11 @@
 }


-void FullCodeGenerator::EmitDeclaration(Variable* variable,
+void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
                                         Variable::Mode mode,
                                         FunctionLiteral* function) {
   Comment cmnt(masm_, "[ Declaration");
+  Variable* variable = proxy->var();
   ASSERT(variable != NULL);  // Must have been resolved.
   Slot* slot = variable->AsSlot();
   ASSERT(slot != NULL);
@@ -729,10 +730,12 @@
         // We know that we have written a function, which is not a smi.
         __ mov(r1, Operand(cp));
         __ RecordWrite(r1, Operand(offset), r2, result_register());
+        PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
       } else if (mode == Variable::CONST || mode == Variable::LET) {
         __ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
         __ str(ip, ContextOperand(cp, slot->index()));
         // No write barrier since the_hole_value is in old space.
+        PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
       }
       break;

@@ -767,7 +770,7 @@


 void FullCodeGenerator::VisitDeclaration(Declaration* decl) {
-  EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun());
+  EmitDeclaration(decl->proxy(), decl->mode(), decl->fun());
 }


=======================================
--- /branches/bleeding_edge/src/full-codegen.h  Thu Sep  1 04:57:02 2011
+++ /branches/bleeding_edge/src/full-codegen.h  Thu Sep  1 09:33:57 2011
@@ -403,7 +403,7 @@

   // Platform-specific code for a variable, constant, or function
   // declaration.  Functions have an initial value.
-  void EmitDeclaration(Variable* variable,
+  void EmitDeclaration(VariableProxy* proxy,
                        Variable::Mode mode,
                        FunctionLiteral* function);

=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Thu Sep  1 04:06:03 2011
+++ /branches/bleeding_edge/src/hydrogen.cc     Thu Sep  1 09:33:57 2011
@@ -2298,11 +2298,7 @@
     // Handle implicit declaration of the function name in named function
     // expressions before other declarations.
     if (scope->is_function_scope() && scope->function() != NULL) {
-      if (!scope->function()->IsStackAllocated()) {
-        Bailout("unsupported declaration");
-        return NULL;
-      }
-      environment()->Bind(scope->function(), graph()->GetConstantHole());
+      HandleDeclaration(scope->function(), Variable::CONST, NULL);
     }
     VisitDeclarations(scope->declarations());
     AddSimulate(AstNode::kDeclarationsId);
@@ -5822,20 +5818,51 @@


 void HGraphBuilder::VisitDeclaration(Declaration* decl) {
-  // We support only declarations that do not require code generation.
-  Variable* var = decl->proxy()->var();
-  if (!var->IsStackAllocated() ||
-      decl->mode() == Variable::LET) {
-    return Bailout("unsupported declaration");
-  }
-
-  if (decl->mode() == Variable::CONST) {
-    ASSERT(var->IsStackAllocated());
-    environment()->Bind(var, graph()->GetConstantHole());
-  } else if (decl->fun() != NULL) {
-    VisitForValue(decl->fun());
-    HValue* function = Pop();
-    environment()->Bind(var, function);
+  HandleDeclaration(decl->proxy(), decl->mode(), decl->fun());
+}
+
+
+void HGraphBuilder::HandleDeclaration(VariableProxy* proxy,
+                                    Variable::Mode mode,
+                                    FunctionLiteral* function) {
+  if (mode == Variable::LET) return Bailout("unsupported let declaration");
+  Variable* var = proxy->var();
+  Slot* slot = var->AsSlot();
+  ASSERT(slot != NULL);
+  switch (slot->type()) {
+    case Slot::PARAMETER:
+    case Slot::LOCAL:
+      if (mode == Variable::CONST) {
+        environment()->Bind(var, graph()->GetConstantHole());
+      } else if (function != NULL) {
+        VisitForValue(function);
+        HValue* function_value = Pop();
+        environment()->Bind(var, function_value);
+      }
+      break;
+    case Slot::CONTEXT: {
+      HValue* context = environment()->LookupContext();
+      if (mode == Variable::CONST) {
+        HStoreContextSlot* store =
+            new HStoreContextSlot(context,
+                                  slot->index(),
+                                  graph()->GetConstantHole());
+        AddInstruction(store);
+        if (store->HasSideEffects()) AddSimulate(proxy->id());
+      } else if (function != NULL) {
+        VisitForValue(function);
+        HValue* function_value = Pop();
+        HStoreContextSlot* store =
+            new HStoreContextSlot(context,
+                                  slot->index(),
+                                  function_value);
+        AddInstruction(store);
+        if (store->HasSideEffects()) AddSimulate(proxy->id());
+      }
+      break;
+    }
+    case Slot::LOOKUP:
+      return Bailout("unsupported lookup slot in declaration");
   }
 }

=======================================
--- /branches/bleeding_edge/src/hydrogen.h      Mon Aug 22 07:23:37 2011
+++ /branches/bleeding_edge/src/hydrogen.h      Thu Sep  1 09:33:57 2011
@@ -779,6 +779,10 @@
   INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_DECLARATION)
 #undef INLINE_FUNCTION_GENERATOR_DECLARATION

+  void HandleDeclaration(VariableProxy* proxy,
+                         Variable::Mode mode,
+                         FunctionLiteral* function);
+
   void VisitDelete(UnaryOperation* expr);
   void VisitVoid(UnaryOperation* expr);
   void VisitTypeof(UnaryOperation* expr);
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Thu Sep 1 05:31:18 2011 +++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Thu Sep 1 09:33:57 2011
@@ -684,10 +684,11 @@
 }


-void FullCodeGenerator::EmitDeclaration(Variable* variable,
+void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
                                         Variable::Mode mode,
                                         FunctionLiteral* function) {
   Comment cmnt(masm_, "[ Declaration");
+  Variable* variable = proxy->var();
   ASSERT(variable != NULL);  // Must have been resolved.
   Slot* slot = variable->AsSlot();
   ASSERT(slot != NULL);
@@ -724,10 +725,12 @@
         int offset = Context::SlotOffset(slot->index());
         __ mov(ebx, esi);
         __ RecordWrite(ebx, offset, result_register(), ecx);
+        PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
       } else if (mode == Variable::CONST || mode == Variable::LET) {
         __ mov(ContextOperand(esi, slot->index()),
                Immediate(isolate()->factory()->the_hole_value()));
         // No write barrier since the hole value is in old space.
+        PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
       }
       break;

@@ -763,7 +766,7 @@


 void FullCodeGenerator::VisitDeclaration(Declaration* decl) {
-  EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun());
+  EmitDeclaration(decl->proxy(), decl->mode(), decl->fun());
 }


=======================================
--- /branches/bleeding_edge/src/scopeinfo.cc    Thu Aug 11 09:29:28 2011
+++ /branches/bleeding_edge/src/scopeinfo.cc    Thu Sep  1 09:33:57 2011
@@ -131,18 +131,18 @@
   // For now, this must happen at the very end because of the
   // ordering of the scope info slots and the respective slot indices.
   if (scope->is_function_scope()) {
-    Variable* var = scope->function();
-    if (var != NULL &&
-        var->is_used() &&
-        var->AsSlot()->type() == Slot::CONTEXT) {
-      function_name_ = var->name();
+    VariableProxy* proxy = scope->function();
+    if (proxy != NULL &&
+        proxy->var()->is_used() &&
+        proxy->var()->IsContextSlot()) {
+      function_name_ = proxy->name();
       // Note that we must not find the function name in the context slot
       // list - instead it must be handled separately in the
// Contexts::Lookup() function. Thus record an empty symbol here so we
       // get the correct number of context slots.
-      ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS ==
+ ASSERT(proxy->var()->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS ==
              context_slots_.length());
-      ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS ==
+ ASSERT(proxy->var()->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS ==
              context_modes_.length());
       context_slots_.Add(FACTORY->empty_symbol());
       context_modes_.Add(Variable::INTERNAL);
=======================================
--- /branches/bleeding_edge/src/scopes.cc       Thu Sep  1 05:31:18 2011
+++ /branches/bleeding_edge/src/scopes.cc       Thu Sep  1 09:33:57 2011
@@ -378,8 +378,10 @@

 Variable* Scope::DeclareFunctionVar(Handle<String> name) {
   ASSERT(is_function_scope() && function_ == NULL);
- function_ = new Variable(this, name, Variable::CONST, true, Variable::NORMAL);
-  return function_;
+  Variable* function_var =
+      new Variable(this, name, Variable::CONST, true, Variable::NORMAL);
+  function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var);
+  return function_->var();
 }


@@ -715,7 +717,7 @@
   PrettyPrinter printer;
   Indent(n1, "// function var\n");
   if (function_ != NULL) {
-    PrintVar(&printer, n1, function_);
+    PrintVar(&printer, n1, function_->var());
   }

   Indent(n1, "// temporary vars\n");
@@ -796,7 +798,7 @@
     // the name of named function literal is kept in an intermediate scope
     // in between this scope and the next outer scope.)
     if (function_ != NULL && function_->name().is_identical_to(name)) {
-      var = function_;
+      var = function_->var();

     } else if (outer_scope_ != NULL) {
       var = outer_scope_->LookupRecursive(
@@ -1114,7 +1116,7 @@
   // because of the current ScopeInfo implementation (see
   // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor).
   if (function_ != NULL) {
-    AllocateNonParameterLocal(function_);
+    AllocateNonParameterLocal(function_->var());
   }
 }

=======================================
--- /branches/bleeding_edge/src/scopes.h        Thu Sep  1 05:31:18 2011
+++ /branches/bleeding_edge/src/scopes.h        Thu Sep  1 09:33:57 2011
@@ -239,7 +239,7 @@
   // The variable holding the function literal for named function
   // literals, or NULL.
   // Only valid for function scopes.
-  Variable* function() const {
+  VariableProxy* function() const {
     ASSERT(is_function_scope());
     return function_;
   }
@@ -358,7 +358,7 @@
   // Convenience variable.
   Variable* receiver_;
   // Function variable, if any; function scopes only.
-  Variable* function_;
+  VariableProxy* function_;
   // Convenience variable; function scopes only.
   Variable* arguments_;

=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Thu Sep 1 05:31:18 2011 +++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Thu Sep 1 09:33:57 2011
@@ -659,10 +659,11 @@
 }


-void FullCodeGenerator::EmitDeclaration(Variable* variable,
+void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
                                         Variable::Mode mode,
                                         FunctionLiteral* function) {
   Comment cmnt(masm_, "[ Declaration");
+  Variable* variable = proxy->var();
   ASSERT(variable != NULL);  // Must have been resolved.
   Slot* slot = variable->AsSlot();
   ASSERT(slot != NULL);
@@ -699,10 +700,12 @@
         int offset = Context::SlotOffset(slot->index());
         __ movq(rbx, rsi);
         __ RecordWrite(rbx, offset, result_register(), rcx);
+        PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
       } else if (mode == Variable::CONST || mode == Variable::LET) {
         __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
         __ movq(ContextOperand(rsi, slot->index()), kScratchRegister);
         // No write barrier since the hole value is in old space.
+        PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
       }
       break;

@@ -734,7 +737,7 @@


 void FullCodeGenerator::VisitDeclaration(Declaration* decl) {
-  EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun());
+  EmitDeclaration(decl->proxy(), decl->mode(), decl->fun());
 }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to