Reviewers: Vyacheslav Egorov,

Description:
Allow inlining of named function expressions containing ThisFunction reference.

Named function expression have an implicit local variable that
refers to the current function (ThisFunction). Before we only could inline
anonymous function expressions like:

A.prototype.foo = function() {}

as opposed to

A.prototype.foo = function foo() {}

This change enables inlining function of expressions like this.

Please review this at http://codereview.chromium.org/8346032/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/arm/lithium-arm.h
  M     src/arm/lithium-codegen-arm.cc
  M     src/ast.cc
  M     src/hydrogen-instructions.h
  M     src/hydrogen.cc
  M     src/ia32/lithium-codegen-ia32.cc
  M     src/ia32/lithium-ia32.h
  M     src/x64/lithium-codegen-x64.cc
  M     src/x64/lithium-x64.h


Index: src/arm/lithium-arm.h
===================================================================
--- src/arm/lithium-arm.h       (revision 9687)
+++ src/arm/lithium-arm.h       (working copy)
@@ -1276,7 +1276,9 @@


 class LThisFunction: public LTemplateInstruction<1, 0, 0> {
+ public:
   DECLARE_CONCRETE_INSTRUCTION(ThisFunction, "this-function")
+  DECLARE_HYDROGEN_ACCESSOR(ThisFunction)
 };


Index: src/arm/lithium-codegen-arm.cc
===================================================================
--- src/arm/lithium-codegen-arm.cc      (revision 9687)
+++ src/arm/lithium-codegen-arm.cc      (working copy)
@@ -2786,7 +2786,7 @@

 void LCodeGen::DoThisFunction(LThisFunction* instr) {
   Register result = ToRegister(instr->result());
- __ ldr(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
+  LoadHeapObject(result, instr->hydrogen()->closure());
 }


Index: src/ast.cc
===================================================================
--- src/ast.cc  (revision 9687)
+++ src/ast.cc  (working copy)
@@ -465,7 +465,7 @@


 bool ThisFunction::IsInlineable() const {
-  return false;
+  return true;
 }


Index: src/hydrogen-instructions.h
===================================================================
--- src/hydrogen-instructions.h (revision 9687)
+++ src/hydrogen-instructions.h (working copy)
@@ -1347,7 +1347,7 @@

 class HThisFunction: public HTemplateInstruction<0> {
  public:
-  HThisFunction() {
+  explicit HThisFunction(Handle<JSFunction> closure) : closure_(closure) {
     set_representation(Representation::Tagged());
     SetFlag(kUseGVN);
   }
@@ -1356,10 +1356,18 @@
     return Representation::None();
   }

+  Handle<JSFunction> closure() const { return closure_; }
+
   DECLARE_CONCRETE_INSTRUCTION(ThisFunction)

  protected:
-  virtual bool DataEquals(HValue* other) { return true; }
+  virtual bool DataEquals(HValue* other) {
+    HThisFunction* b = HThisFunction::cast(other);
+    return *closure() == *b->closure();
+  }
+
+ private:
+  Handle<JSFunction> closure_;
 };


Index: src/hydrogen.cc
===================================================================
--- src/hydrogen.cc     (revision 9687)
+++ src/hydrogen.cc     (working copy)
@@ -5964,7 +5964,8 @@
   ASSERT(!HasStackOverflow());
   ASSERT(current_block() != NULL);
   ASSERT(current_block()->HasPredecessor());
-  HThisFunction* self = new(zone()) HThisFunction;
+  HThisFunction* self = new(zone()) HThisFunction(
+      function_state()->compilation_info()->closure());
   return ast_context()->ReturnInstruction(self, expr->id());
 }

Index: src/ia32/lithium-codegen-ia32.cc
===================================================================
--- src/ia32/lithium-codegen-ia32.cc    (revision 9687)
+++ src/ia32/lithium-codegen-ia32.cc    (working copy)
@@ -2626,7 +2626,7 @@

 void LCodeGen::DoThisFunction(LThisFunction* instr) {
   Register result = ToRegister(instr->result());
-  __ mov(result, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
+  LoadHeapObject(result, instr->hydrogen()->closure());
 }


Index: src/ia32/lithium-ia32.h
===================================================================
--- src/ia32/lithium-ia32.h     (revision 9687)
+++ src/ia32/lithium-ia32.h     (working copy)
@@ -1311,7 +1311,9 @@


 class LThisFunction: public LTemplateInstruction<1, 0, 0> {
+ public:
   DECLARE_CONCRETE_INSTRUCTION(ThisFunction, "this-function")
+  DECLARE_HYDROGEN_ACCESSOR(ThisFunction)
 };


Index: src/x64/lithium-codegen-x64.cc
===================================================================
--- src/x64/lithium-codegen-x64.cc      (revision 9687)
+++ src/x64/lithium-codegen-x64.cc      (working copy)
@@ -2572,7 +2572,7 @@

 void LCodeGen::DoThisFunction(LThisFunction* instr) {
   Register result = ToRegister(instr->result());
-  __ movq(result, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
+  LoadHeapObject(result, instr->hydrogen()->closure());
 }


Index: src/x64/lithium-x64.h
===================================================================
--- src/x64/lithium-x64.h       (revision 9687)
+++ src/x64/lithium-x64.h       (working copy)
@@ -1276,7 +1276,9 @@


 class LThisFunction: public LTemplateInstruction<1, 0, 0> {
+ public:
   DECLARE_CONCRETE_INSTRUCTION(ThisFunction, "this-function")
+  DECLARE_HYDROGEN_ACCESSOR(ThisFunction)
 };




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

Reply via email to