Revision: 9699
Author: [email protected]
Date: Wed Oct 19 04:41:22 2011
Log: 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.
Review URL: http://codereview.chromium.org/8346032
http://code.google.com/p/v8/source/detail?r=9699
Modified:
/branches/bleeding_edge/src/arm/lithium-arm.h
/branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
/branches/bleeding_edge/src/ast.cc
/branches/bleeding_edge/src/hydrogen-instructions.h
/branches/bleeding_edge/src/hydrogen.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-ia32.h
/branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-x64.h
=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.h Fri Oct 14 00:45:18 2011
+++ /branches/bleeding_edge/src/arm/lithium-arm.h Wed Oct 19 04:41:22 2011
@@ -1276,7 +1276,9 @@
class LThisFunction: public LTemplateInstruction<1, 0, 0> {
+ public:
DECLARE_CONCRETE_INSTRUCTION(ThisFunction, "this-function")
+ DECLARE_HYDROGEN_ACCESSOR(ThisFunction)
};
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Wed Oct 19
04:36:55 2011
+++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Wed Oct 19
04:41:22 2011
@@ -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());
}
=======================================
--- /branches/bleeding_edge/src/ast.cc Tue Oct 18 04:18:55 2011
+++ /branches/bleeding_edge/src/ast.cc Wed Oct 19 04:41:22 2011
@@ -465,7 +465,7 @@
bool ThisFunction::IsInlineable() const {
- return false;
+ return true;
}
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Wed Oct 19 00:35:30
2011
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Wed Oct 19 04:41:22
2011
@@ -1347,7 +1347,7 @@
class HThisFunction: public HTemplateInstruction<0> {
public:
- HThisFunction() {
+ explicit HThisFunction(Handle<JSFunction> closure) : closure_(closure) {
set_representation(Representation::Tagged());
SetFlag(kUseGVN);
}
@@ -1355,11 +1355,19 @@
virtual Representation RequiredInputRepresentation(int index) {
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_;
};
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc Wed Oct 19 04:36:55 2011
+++ /branches/bleeding_edge/src/hydrogen.cc Wed Oct 19 04:41:22 2011
@@ -6001,7 +6001,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());
}
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Wed Oct 19
04:36:55 2011
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Wed Oct 19
04:41:22 2011
@@ -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());
}
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.h Fri Oct 14 00:45:18 2011
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.h Wed Oct 19 04:41:22 2011
@@ -1311,7 +1311,9 @@
class LThisFunction: public LTemplateInstruction<1, 0, 0> {
+ public:
DECLARE_CONCRETE_INSTRUCTION(ThisFunction, "this-function")
+ DECLARE_HYDROGEN_ACCESSOR(ThisFunction)
};
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Wed Oct 19
04:36:55 2011
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Wed Oct 19
04:41:22 2011
@@ -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());
}
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.h Fri Oct 14 00:45:18 2011
+++ /branches/bleeding_edge/src/x64/lithium-x64.h Wed Oct 19 04:41:22 2011
@@ -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