Only swap undefined for the global object if necessary in the prologue
authorverwaest <verwaest@chromium.org>
Mon, 4 May 2015 13:38:50 +0000 (06:38 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 4 May 2015 13:39:00 +0000 (13:39 +0000)
BUG=

Review URL: https://codereview.chromium.org/1120093002

Cr-Commit-Position: refs/heads/master@{#28200}

19 files changed:
src/arm/full-codegen-arm.cc
src/arm/lithium-codegen-arm.cc
src/arm64/full-codegen-arm64.cc
src/arm64/lithium-codegen-arm64.cc
src/compiler.cc
src/compiler.h
src/compiler/ast-graph-builder.cc
src/hydrogen.cc
src/hydrogen.h
src/ia32/full-codegen-ia32.cc
src/ia32/lithium-codegen-ia32.cc
src/mips/full-codegen-mips.cc
src/mips/lithium-codegen-mips.cc
src/mips64/full-codegen-mips64.cc
src/mips64/lithium-codegen-mips64.cc
src/x64/full-codegen-x64.cc
src/x64/lithium-codegen-x64.cc
src/x87/full-codegen-x87.cc
src/x87/lithium-codegen-x87.cc

index 2154b6eb4f9477a8413f035942d5e48152242655..2522b09a68886257be64c5843fd77cb02a36ba94 100644 (file)
@@ -126,7 +126,8 @@ void FullCodeGenerator::Generate() {
   // Sloppy mode functions and builtins need to replace the receiver with the
   // global proxy when called as functions (without an explicit receiver
   // object).
-  if (is_sloppy(info->language_mode()) && !info->is_native()) {
+  if (is_sloppy(info->language_mode()) && !info->is_native() &&
+      info->MayUseThis()) {
     Label ok;
     int receiver_offset = info->scope()->num_parameters() * kPointerSize;
     __ ldr(r2, MemOperand(sp, receiver_offset));
index b480fd91639cb4317fb4bc2b4d0288f75e2ca233..d11bfc7547803b9885796761f4d55c46fac1d28f 100644 (file)
@@ -120,7 +120,7 @@ bool LCodeGen::GeneratePrologue() {
     // Sloppy mode functions and builtins need to replace the receiver with the
     // global proxy when called as functions (without an explicit receiver
     // object).
-    if (graph()->this_has_uses() && is_sloppy(info_->language_mode()) &&
+    if (is_sloppy(info_->language_mode()) && info()->MayUseThis() &&
         !info_->is_native()) {
       Label ok;
       int receiver_offset = info_->scope()->num_parameters() * kPointerSize;
index d1ee80e54a56a7e838387a7674c5cef3fc141681..af4a6d647d9f3e2d54900a6c863078ab16368888 100644 (file)
@@ -124,7 +124,8 @@ void FullCodeGenerator::Generate() {
   // Sloppy mode functions and builtins need to replace the receiver with the
   // global proxy when called as functions (without an explicit receiver
   // object).
-  if (is_sloppy(info->language_mode()) && !info->is_native()) {
+  if (is_sloppy(info->language_mode()) && !info->is_native() &&
+      info->MayUseThis()) {
     Label ok;
     int receiver_offset = info->scope()->num_parameters() * kXRegSize;
     __ Peek(x10, receiver_offset);
index a249ca423b6ac7578a8eea13e8d63065c97752b8..78e296b79576885ecea75ce475b64ba83029e078 100644 (file)
@@ -668,7 +668,7 @@ bool LCodeGen::GeneratePrologue() {
     // Sloppy mode functions and builtins need to replace the receiver with the
     // global proxy when called as functions (without an explicit receiver
     // object).
-    if (graph()->this_has_uses() && is_sloppy(info()->language_mode()) &&
+    if (is_sloppy(info_->language_mode()) && info()->MayUseThis() &&
         !info_->is_native()) {
       Label ok;
       int receiver_offset = info_->scope()->num_parameters() * kXRegSize;
index ada773c3861eb177629de03f60cc279d8eb2518e..2ad1ff447e26d51a7b4750ab979e8a9b96d0a1bb 100644 (file)
@@ -214,6 +214,12 @@ bool CompilationInfo::is_simple_parameter_list() {
 }
 
 
+bool CompilationInfo::MayUseThis() const {
+  return scope()->uses_this() || scope()->inner_uses_this() ||
+         scope()->calls_sloppy_eval();
+}
+
+
 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
                                           SourcePosition position,
                                           int parent_id) {
index 8e0aab931ca9bb8fa2ad7e9a3b74c1fcf0c0221d..ff3a86a10c47f2db9d32958bb3debfb4be4671ff 100644 (file)
@@ -148,6 +148,7 @@ class CompilationInfo {
   Handle<JSFunction> closure() const;
   FunctionLiteral* function() const;
   Scope* scope() const;
+  bool MayUseThis() const;
   Handle<Context> context() const;
   Handle<SharedFunctionInfo> shared_info() const;
   bool has_shared_info() const;
index e62e34ef07809b8ee0062614472d09699ac820ce..88422886edeea86ac4d6e8ab9d48cee772484d04 100644 (file)
@@ -2642,10 +2642,7 @@ Node* AstGraphBuilder::BuildPatchReceiverToGlobalProxy(Node* receiver) {
   // There is no need to perform patching if the receiver is never used. Note
   // that scope predicates are purely syntactical, a call to eval might still
   // inspect the receiver value.
-  if (!info()->scope()->uses_this() && !info()->scope()->inner_uses_this() &&
-      !info()->scope()->calls_sloppy_eval()) {
-    return receiver;
-  }
+  if (!info()->MayUseThis()) return receiver;
 
   IfBuilder receiver_check(this);
   Node* undefined = jsgraph()->UndefinedConstant();
index 788fda4a33923bf9ed68cc5ae66a7b5c39eae170..9bdc070300512b44f0c6ea5ba292b8530655ef9f 100644 (file)
@@ -3496,7 +3496,6 @@ HGraph::HGraph(CompilationInfo* info)
       info_(info),
       zone_(info->zone()),
       is_recursive_(false),
-      this_has_uses_(false),
       use_optimistic_licm_(false),
       depends_on_empty_array_proto_elements_(false),
       type_change_checksum_(0),
@@ -5402,10 +5401,6 @@ HValue* HOptimizedGraphBuilder::BuildContextChainWalk(Variable* var) {
 
 
 void HOptimizedGraphBuilder::VisitVariableProxy(VariableProxy* expr) {
-  if (expr->is_this()) {
-    graph()->MarkThisHasUses();
-  }
-
   DCHECK(!HasStackOverflow());
   DCHECK(current_block() != NULL);
   DCHECK(current_block()->HasPredecessor());
index f5fa62f49463489b0b596aeec775e52118c737a1..3eb34a2d79200e6124a54ce3d31486d92fc9413e 100644 (file)
@@ -410,9 +410,6 @@ class HGraph final : public ZoneObject {
   void MarkRecursive() { is_recursive_ = true; }
   bool is_recursive() const { return is_recursive_; }
 
-  void MarkThisHasUses() { this_has_uses_ = true; }
-  bool this_has_uses() const { return this_has_uses_; }
-
   void MarkDependsOnEmptyArrayProtoElements() {
     // Add map dependency if not already added.
     if (depends_on_empty_array_proto_elements_) return;
@@ -493,7 +490,6 @@ class HGraph final : public ZoneObject {
   Zone* zone_;
 
   bool is_recursive_;
-  bool this_has_uses_;
   bool use_optimistic_licm_;
   bool depends_on_empty_array_proto_elements_;
   int type_change_checksum_;
index 6c38b70e5464d4552574034b20008f8837796166..703330142e12aa3b00f90b63f42aa9f6cfc01749 100644 (file)
@@ -114,7 +114,8 @@ void FullCodeGenerator::Generate() {
   // Sloppy mode functions and builtins need to replace the receiver with the
   // global proxy when called as functions (without an explicit receiver
   // object).
-  if (is_sloppy(info->language_mode()) && !info->is_native()) {
+  if (is_sloppy(info->language_mode()) && !info->is_native() &&
+      info->MayUseThis()) {
     Label ok;
     // +1 for return address.
     int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize;
index f28afa8141f91282756c69a382cb7205cfd94c5e..03fd248d0882bdac0af381dff936bdf68d52ae96 100644 (file)
@@ -141,7 +141,7 @@ bool LCodeGen::GeneratePrologue() {
     // Sloppy mode functions and builtins need to replace the receiver with the
     // global proxy when called as functions (without an explicit receiver
     // object).
-    if (graph()->this_has_uses() && is_sloppy(info_->language_mode()) &&
+    if (is_sloppy(info_->language_mode()) && info()->MayUseThis() &&
         !info_->is_native()) {
       Label ok;
       // +1 for return address.
index 24d448d585aa9253ac71cf9f16ca973d020e1e41..0756b092f39f27359e7a441219651c165f5ecb5f 100644 (file)
@@ -134,7 +134,8 @@ void FullCodeGenerator::Generate() {
   // Sloppy mode functions and builtins need to replace the receiver with the
   // global proxy when called as functions (without an explicit receiver
   // object).
-  if (is_sloppy(info->language_mode()) && !info->is_native()) {
+  if (is_sloppy(info->language_mode()) && !info->is_native() &&
+      info->MayUseThis()) {
     Label ok;
     int receiver_offset = info->scope()->num_parameters() * kPointerSize;
     __ lw(at, MemOperand(sp, receiver_offset));
index 2abde16a40b3a2e3efe092081cbcc82cafa139c7..e5adc8066f56fa6c3b9a50166a19107409c0d570 100644 (file)
@@ -143,7 +143,7 @@ bool LCodeGen::GeneratePrologue() {
     // Sloppy mode functions and builtins need to replace the receiver with the
     // global proxy when called as functions (without an explicit receiver
     // object).
-    if (graph()->this_has_uses() && is_sloppy(info_->language_mode()) &&
+    if (is_sloppy(info_->language_mode()) && info()->MayUseThis() &&
         !info_->is_native()) {
       Label ok;
       int receiver_offset = info_->scope()->num_parameters() * kPointerSize;
index b3ed1bb9d83c5e759600275147152f5b8856092c..0e3f0725e6360671947716dd01174da5575199b0 100644 (file)
@@ -134,7 +134,8 @@ void FullCodeGenerator::Generate() {
   // Sloppy mode functions and builtins need to replace the receiver with the
   // global proxy when called as functions (without an explicit receiver
   // object).
-  if (is_sloppy(info->language_mode()) && !info->is_native()) {
+  if (is_sloppy(info->language_mode()) && !info->is_native() &&
+      info->MayUseThis()) {
     Label ok;
     int receiver_offset = info->scope()->num_parameters() * kPointerSize;
     __ ld(at, MemOperand(sp, receiver_offset));
index 58ea58ca907807fc71f450f4157be7f0cfd5c8a3..ed0e5f501ba4702e47365ed38cad3ccba2a084c3 100644 (file)
@@ -118,7 +118,7 @@ bool LCodeGen::GeneratePrologue() {
     // Sloppy mode functions and builtins need to replace the receiver with the
     // global proxy when called as functions (without an explicit receiver
     // object).
-    if (graph()->this_has_uses() && is_sloppy(info_->language_mode()) &&
+    if (is_sloppy(info_->language_mode()) && info()->MayUseThis() &&
         !info_->is_native()) {
       Label ok;
       int receiver_offset = info_->scope()->num_parameters() * kPointerSize;
index 94da774891d40872bfa5302e32a52e760bf41823..7f0f66d0e5f7d2686ec10f4c1aeb6ca5684faef8 100644 (file)
@@ -114,7 +114,8 @@ void FullCodeGenerator::Generate() {
   // Sloppy mode functions and builtins need to replace the receiver with the
   // global proxy when called as functions (without an explicit receiver
   // object).
-  if (is_sloppy(info->language_mode()) && !info->is_native()) {
+  if (is_sloppy(info->language_mode()) && !info->is_native() &&
+      info->MayUseThis()) {
     Label ok;
     // +1 for return address.
     StackArgumentsAccessor args(rsp, info->scope()->num_parameters());
index e70bebd938043890832a5bb106bca22fbf64ef06..51b85fc7f9489b2e8077f5b635e0fc23f899abed 100644 (file)
@@ -129,7 +129,7 @@ bool LCodeGen::GeneratePrologue() {
 
     // Sloppy mode functions need to replace the receiver with the global proxy
     // when called as functions (without an explicit receiver object).
-    if (graph()->this_has_uses() && is_sloppy(info_->language_mode()) &&
+    if (is_sloppy(info_->language_mode()) && info()->MayUseThis() &&
         !info_->is_native()) {
       Label ok;
       StackArgumentsAccessor args(rsp, scope()->num_parameters());
index 3a6edec82be993d679f2ddd75c34726a46a9d4d0..3dbb6d41b128b27ddce603a58aff3e7c49f83d38 100644 (file)
@@ -114,7 +114,8 @@ void FullCodeGenerator::Generate() {
   // Sloppy mode functions and builtins need to replace the receiver with the
   // global proxy when called as functions (without an explicit receiver
   // object).
-  if (is_sloppy(info->language_mode()) && !info->is_native()) {
+  if (is_sloppy(info->language_mode()) && !info->is_native() &&
+      info->MayUseThis()) {
     Label ok;
     // +1 for return address.
     int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize;
index af118d5edfed23dbd0765b800e567bf5ce56347a..ba650abbbb6c2a386ff1a94de4ada55488dd476d 100644 (file)
@@ -110,7 +110,7 @@ bool LCodeGen::GeneratePrologue() {
     // Sloppy mode functions and builtins need to replace the receiver with the
     // global proxy when called as functions (without an explicit receiver
     // object).
-    if (graph()->this_has_uses() && is_sloppy(info_->language_mode()) &&
+    if (is_sloppy(info_->language_mode()) && info()->MayUseThis() &&
         !info_->is_native()) {
       Label ok;
       // +1 for return address.