Eagerly set arguments_, new_target_ and ths_function_ Scope, and unset if we don't need to allocate them.
This probably slightly speeds up AllocateParameterLocals, but more importantly it removes ast_value_factory_ uses. If we get rid of ast_value_factory from Scope it's easier to lazily allocate it later from within a ScopeState object. BUG=v8:5209 Review-Url: https://codereview.chromium.org/2158333002 Cr-Commit-Position: refs/heads/master@{#37868}
This commit is contained in:
parent
562bb5823c
commit
3442519d56
@ -320,14 +320,17 @@ void Scope::Initialize() {
|
|||||||
// Declare 'arguments' variable which exists in all non arrow functions.
|
// Declare 'arguments' variable which exists in all non arrow functions.
|
||||||
// Note that it might never be accessed, in which case it won't be
|
// Note that it might never be accessed, in which case it won't be
|
||||||
// allocated during variable allocation.
|
// allocated during variable allocation.
|
||||||
|
arguments_ =
|
||||||
variables_.Declare(this, ast_value_factory_->arguments_string(), VAR,
|
variables_.Declare(this, ast_value_factory_->arguments_string(), VAR,
|
||||||
Variable::ARGUMENTS, kCreatedInitialized);
|
Variable::ARGUMENTS, kCreatedInitialized);
|
||||||
|
|
||||||
|
new_target_ =
|
||||||
variables_.Declare(this, ast_value_factory_->new_target_string(), CONST,
|
variables_.Declare(this, ast_value_factory_->new_target_string(), CONST,
|
||||||
Variable::NORMAL, kCreatedInitialized);
|
Variable::NORMAL, kCreatedInitialized);
|
||||||
|
|
||||||
if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) ||
|
if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) ||
|
||||||
IsAccessorFunction(function_kind_)) {
|
IsAccessorFunction(function_kind_)) {
|
||||||
|
this_function_ =
|
||||||
variables_.Declare(this, ast_value_factory_->this_function_string(),
|
variables_.Declare(this, ast_value_factory_->this_function_string(),
|
||||||
CONST, Variable::NORMAL, kCreatedInitialized);
|
CONST, Variable::NORMAL, kCreatedInitialized);
|
||||||
}
|
}
|
||||||
@ -1332,14 +1335,11 @@ void Scope::AllocateHeapSlot(Variable* var) {
|
|||||||
|
|
||||||
void Scope::AllocateParameterLocals(Isolate* isolate) {
|
void Scope::AllocateParameterLocals(Isolate* isolate) {
|
||||||
DCHECK(is_function_scope());
|
DCHECK(is_function_scope());
|
||||||
Variable* arguments = LookupLocal(ast_value_factory_->arguments_string());
|
|
||||||
// Functions have 'arguments' declared implicitly in all non arrow functions.
|
|
||||||
DCHECK(arguments != nullptr || is_arrow_scope());
|
|
||||||
|
|
||||||
bool uses_sloppy_arguments = false;
|
bool uses_sloppy_arguments = false;
|
||||||
|
|
||||||
if (arguments != nullptr && MustAllocate(arguments) &&
|
// Functions have 'arguments' declared implicitly in all non arrow functions.
|
||||||
!HasArgumentsParameter(isolate)) {
|
if (arguments_ != nullptr) {
|
||||||
// 'arguments' is used. Unless there is also a parameter called
|
// 'arguments' is used. Unless there is also a parameter called
|
||||||
// 'arguments', we must be conservative and allocate all parameters to
|
// 'arguments', we must be conservative and allocate all parameters to
|
||||||
// the context assuming they will be captured by the arguments object.
|
// the context assuming they will be captured by the arguments object.
|
||||||
@ -1348,21 +1348,25 @@ void Scope::AllocateParameterLocals(Isolate* isolate) {
|
|||||||
// that specific parameter value and cannot be used to access the
|
// that specific parameter value and cannot be used to access the
|
||||||
// parameters, which is why we don't need to allocate an arguments
|
// parameters, which is why we don't need to allocate an arguments
|
||||||
// object in that case.
|
// object in that case.
|
||||||
|
if (MustAllocate(arguments_) && !HasArgumentsParameter(isolate)) {
|
||||||
// We are using 'arguments'. Tell the code generator that is needs to
|
|
||||||
// allocate the arguments object by setting 'arguments_'.
|
|
||||||
arguments_ = arguments;
|
|
||||||
|
|
||||||
// In strict mode 'arguments' does not alias formal parameters.
|
// In strict mode 'arguments' does not alias formal parameters.
|
||||||
// Therefore in strict mode we allocate parameters as if 'arguments'
|
// Therefore in strict mode we allocate parameters as if 'arguments'
|
||||||
// were not used.
|
// were not used.
|
||||||
// If the parameter list is not simple, arguments isn't sloppy either.
|
// If the parameter list is not simple, arguments isn't sloppy either.
|
||||||
uses_sloppy_arguments =
|
uses_sloppy_arguments =
|
||||||
is_sloppy(language_mode()) && has_simple_parameters();
|
is_sloppy(language_mode()) && has_simple_parameters();
|
||||||
|
} else {
|
||||||
|
// 'arguments' is unused. Tell the code generator that it does not need to
|
||||||
|
// allocate the arguments object by nulling out arguments_.
|
||||||
|
arguments_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
DCHECK(is_arrow_scope());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rest_parameter_ && !MustAllocate(rest_parameter_)) {
|
if (rest_parameter_ && !MustAllocate(rest_parameter_)) {
|
||||||
rest_parameter_ = NULL;
|
rest_parameter_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The same parameter may occur multiple times in the parameters_ list.
|
// The same parameter may occur multiple times in the parameters_ list.
|
||||||
@ -1484,16 +1488,12 @@ void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) {
|
|||||||
AllocateNonParameterLocal(isolate, rest_parameter_);
|
AllocateNonParameterLocal(isolate, rest_parameter_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variable* new_target_var =
|
if (new_target_ != nullptr && !MustAllocate(new_target_)) {
|
||||||
LookupLocal(ast_value_factory_->new_target_string());
|
new_target_ = nullptr;
|
||||||
if (new_target_var != nullptr && MustAllocate(new_target_var)) {
|
|
||||||
new_target_ = new_target_var;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variable* this_function_var =
|
if (this_function_ != nullptr && !MustAllocate(this_function_)) {
|
||||||
LookupLocal(ast_value_factory_->this_function_string());
|
this_function_ = nullptr;
|
||||||
if (this_function_var != nullptr && MustAllocate(this_function_var)) {
|
|
||||||
this_function_ = this_function_var;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user