From: verwaest Date: Mon, 4 May 2015 13:38:50 +0000 (-0700) Subject: Only swap undefined for the global object if necessary in the prologue X-Git-Tag: upstream/4.7.83~2840 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fab3508062396c2768b5dcfa0fd7d40eba527d62;p=platform%2Fupstream%2Fv8.git Only swap undefined for the global object if necessary in the prologue BUG= Review URL: https://codereview.chromium.org/1120093002 Cr-Commit-Position: refs/heads/master@{#28200} --- diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index 2154b6e..2522b09 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -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)); diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index b480fd9..d11bfc7 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -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; diff --git a/src/arm64/full-codegen-arm64.cc b/src/arm64/full-codegen-arm64.cc index d1ee80e..af4a6d6 100644 --- a/src/arm64/full-codegen-arm64.cc +++ b/src/arm64/full-codegen-arm64.cc @@ -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); diff --git a/src/arm64/lithium-codegen-arm64.cc b/src/arm64/lithium-codegen-arm64.cc index a249ca4..78e296b 100644 --- a/src/arm64/lithium-codegen-arm64.cc +++ b/src/arm64/lithium-codegen-arm64.cc @@ -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; diff --git a/src/compiler.cc b/src/compiler.cc index ada773c..2ad1ff4 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -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 shared, SourcePosition position, int parent_id) { diff --git a/src/compiler.h b/src/compiler.h index 8e0aab9..ff3a86a 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -148,6 +148,7 @@ class CompilationInfo { Handle closure() const; FunctionLiteral* function() const; Scope* scope() const; + bool MayUseThis() const; Handle context() const; Handle shared_info() const; bool has_shared_info() const; diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc index e62e34e..8842288 100644 --- a/src/compiler/ast-graph-builder.cc +++ b/src/compiler/ast-graph-builder.cc @@ -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(); diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 788fda4..9bdc070 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -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()); diff --git a/src/hydrogen.h b/src/hydrogen.h index f5fa62f..3eb34a2 100644 --- a/src/hydrogen.h +++ b/src/hydrogen.h @@ -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_; diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc index 6c38b70..7033301 100644 --- a/src/ia32/full-codegen-ia32.cc +++ b/src/ia32/full-codegen-ia32.cc @@ -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; diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index f28afa8..03fd248 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -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. diff --git a/src/mips/full-codegen-mips.cc b/src/mips/full-codegen-mips.cc index 24d448d..0756b09 100644 --- a/src/mips/full-codegen-mips.cc +++ b/src/mips/full-codegen-mips.cc @@ -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)); diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index 2abde16..e5adc80 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -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; diff --git a/src/mips64/full-codegen-mips64.cc b/src/mips64/full-codegen-mips64.cc index b3ed1bb..0e3f072 100644 --- a/src/mips64/full-codegen-mips64.cc +++ b/src/mips64/full-codegen-mips64.cc @@ -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)); diff --git a/src/mips64/lithium-codegen-mips64.cc b/src/mips64/lithium-codegen-mips64.cc index 58ea58c..ed0e5f5 100644 --- a/src/mips64/lithium-codegen-mips64.cc +++ b/src/mips64/lithium-codegen-mips64.cc @@ -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; diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc index 94da774..7f0f66d 100644 --- a/src/x64/full-codegen-x64.cc +++ b/src/x64/full-codegen-x64.cc @@ -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()); diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index e70bebd..51b85fc 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -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()); diff --git a/src/x87/full-codegen-x87.cc b/src/x87/full-codegen-x87.cc index 3a6edec..3dbb6d4 100644 --- a/src/x87/full-codegen-x87.cc +++ b/src/x87/full-codegen-x87.cc @@ -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; diff --git a/src/x87/lithium-codegen-x87.cc b/src/x87/lithium-codegen-x87.cc index af118d5..ba650ab 100644 --- a/src/x87/lithium-codegen-x87.cc +++ b/src/x87/lithium-codegen-x87.cc @@ -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.