Introduce parser-time optimization that moves function's argument values to registers.
For functions with the optimization applied: - vm puts arguments values immediately to registers without putting them to variables in lexical environment; - number of arguments is extracted from corresponding 'reg_var_decl' instruction's argument; - for functions that also don't have local variables, lexical environments are not created. JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -164,8 +164,12 @@ typedef enum : vm_idx_t
|
||||
OPCODE_SCOPE_CODE_FLAGS_STRICT = (1u << 0), /**< code is strict mode code */
|
||||
OPCODE_SCOPE_CODE_FLAGS_NOT_REF_ARGUMENTS_IDENTIFIER = (1u << 1), /**< code doesn't reference
|
||||
* 'arguments' identifier */
|
||||
OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER = (1u << 2) /**< code doesn't reference
|
||||
OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER = (1u << 2), /**< code doesn't reference
|
||||
* 'eval' identifier */
|
||||
OPCODE_SCOPE_CODE_FLAGS_ARGUMENTS_ON_REGISTERS = (1u << 3), /**< function's arguments are moved to registers,
|
||||
* so should be initialized in vm registers,
|
||||
* and not in lexical environment */
|
||||
OPCODE_SCOPE_CODE_FLAGS_NO_LEX_ENV = (1u << 4) /**< no lex. env. is necessary for the function */
|
||||
} opcode_scope_code_flags_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -221,7 +221,7 @@ pp_op_meta (const bytecode_data_header_t *bytecode_data_p,
|
||||
PP_OP (VM_OP_PRE_INCR, "%s = ++%s;");
|
||||
PP_OP (VM_OP_PRE_DECR, "%s = --%s;");
|
||||
PP_OP (VM_OP_THROW_VALUE, "throw %s;");
|
||||
PP_OP (VM_OP_REG_VAR_DECL, "%d tmp regs, %d local variable regs");
|
||||
PP_OP (VM_OP_REG_VAR_DECL, "%d tmp regs, %d local variable regs, %d argument variable regs");
|
||||
PP_OP (VM_OP_VAR_DECL, "var %s;");
|
||||
PP_OP (VM_OP_RETVAL, "return %s;");
|
||||
PP_OP (VM_OP_RET, "ret;");
|
||||
@@ -572,6 +572,16 @@ pp_op_meta (const bytecode_data_header_t *bytecode_data_p,
|
||||
printf ("[no 'eval'] ");
|
||||
scope_flags &= (vm_idx_t) ~(OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER);
|
||||
}
|
||||
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_ARGUMENTS_ON_REGISTERS)
|
||||
{
|
||||
printf ("[arguments are placed on registers] ");
|
||||
scope_flags &= (vm_idx_t) ~(OPCODE_SCOPE_CODE_FLAGS_ARGUMENTS_ON_REGISTERS);
|
||||
}
|
||||
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_NO_LEX_ENV)
|
||||
{
|
||||
printf ("[no lexical environment should be created for the scope] ");
|
||||
scope_flags &= (vm_idx_t) ~(OPCODE_SCOPE_CODE_FLAGS_NO_LEX_ENV);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (scope_flags == 0);
|
||||
}
|
||||
|
||||
@@ -292,9 +292,10 @@ VM_OP_3 (is_false_jmp_down, IS_FALSE_JMP_DOWN,
|
||||
VM_OP_1 (var_decl, VAR_DECL,
|
||||
variable_name, VM_OP_ARG_TYPE_STRING)
|
||||
|
||||
VM_OP_2 (reg_var_decl, REG_VAR_DECL,
|
||||
VM_OP_3 (reg_var_decl, REG_VAR_DECL,
|
||||
tmp_regs_num, VM_OP_ARG_TYPE_INTEGER_CONST,
|
||||
local_var_regs_num, VM_OP_ARG_TYPE_INTEGER_CONST)
|
||||
local_var_regs_num, VM_OP_ARG_TYPE_INTEGER_CONST,
|
||||
arg_regs_num, VM_OP_ARG_TYPE_INTEGER_CONST)
|
||||
|
||||
VM_OP_3 (meta, META,
|
||||
type, VM_OP_ARG_TYPE_INTEGER_CONST,
|
||||
|
||||
@@ -77,8 +77,13 @@ void
|
||||
vm_stack_add_frame (vm_stack_frame_t *frame_p, /**< frame to initialize */
|
||||
ecma_value_t *regs_p, /**< array of register variables' values */
|
||||
uint32_t regs_num, /**< total number of register variables */
|
||||
uint32_t local_vars_regs_num) /**< number of register variables,
|
||||
uint32_t local_vars_regs_num, /**< number of register variables,
|
||||
* used for local variables */
|
||||
uint32_t arg_regs_num, /**< number of register variables,
|
||||
* used for arguments */
|
||||
ecma_collection_header_t *arguments_p) /**< collection of arguments
|
||||
* (for case, their values
|
||||
* are moved to registers) */
|
||||
{
|
||||
frame_p->prev_frame_p = vm_stack_top_frame_p;
|
||||
vm_stack_top_frame_p = frame_p;
|
||||
@@ -91,17 +96,30 @@ vm_stack_add_frame (vm_stack_frame_t *frame_p, /**< frame to initialize */
|
||||
|
||||
JERRY_ASSERT (regs_num >= VM_SPECIAL_REGS_NUMBER);
|
||||
|
||||
for (uint32_t i = 0; i < regs_num - local_vars_regs_num; i++)
|
||||
for (uint32_t i = 0; i < regs_num - local_vars_regs_num - arg_regs_num; i++)
|
||||
{
|
||||
regs_p[i] = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
|
||||
}
|
||||
|
||||
for (uint32_t i = regs_num - local_vars_regs_num;
|
||||
for (uint32_t i = regs_num - local_vars_regs_num - arg_regs_num;
|
||||
i < regs_num;
|
||||
i++)
|
||||
{
|
||||
regs_p[i] = ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
}
|
||||
|
||||
if (arg_regs_num != 0)
|
||||
{
|
||||
ecma_collection_iterator_t args_iterator;
|
||||
ecma_collection_iterator_init (&args_iterator, arguments_p);
|
||||
|
||||
for (uint32_t i = regs_num - arg_regs_num;
|
||||
i < regs_num && ecma_collection_iterator_next (&args_iterator);
|
||||
i++)
|
||||
{
|
||||
regs_p[i] = ecma_copy_value (*args_iterator.current_value_p, false);
|
||||
}
|
||||
}
|
||||
} /* vm_stack_add_frame */
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,7 +60,7 @@ extern void vm_stack_finalize (void);
|
||||
extern vm_stack_frame_t *
|
||||
vm_stack_get_top_frame (void);
|
||||
extern void
|
||||
vm_stack_add_frame (vm_stack_frame_t *, ecma_value_t *, uint32_t, uint32_t);
|
||||
vm_stack_add_frame (vm_stack_frame_t *, ecma_value_t *, uint32_t, uint32_t, uint32_t, ecma_collection_header_t *);
|
||||
extern void vm_stack_free_frame (vm_stack_frame_t *);
|
||||
extern ecma_value_t vm_stack_frame_get_reg_value (vm_stack_frame_t *, uint32_t);
|
||||
extern void vm_stack_frame_set_reg_value (vm_stack_frame_t *, uint32_t, ecma_value_t);
|
||||
|
||||
+30
-5
@@ -411,7 +411,8 @@ vm_run_global (void)
|
||||
ecma_make_object_value (glob_obj_p),
|
||||
lex_env_p,
|
||||
is_strict,
|
||||
false);
|
||||
false,
|
||||
NULL);
|
||||
|
||||
jerry_completion_code_t ret_code;
|
||||
|
||||
@@ -479,7 +480,8 @@ vm_run_eval (const bytecode_data_header_t *bytecode_data_p, /**< byte-code data
|
||||
this_binding,
|
||||
lex_env_p,
|
||||
is_strict,
|
||||
true);
|
||||
true,
|
||||
NULL);
|
||||
|
||||
if (ecma_is_completion_value_return (completion))
|
||||
{
|
||||
@@ -595,7 +597,13 @@ vm_run_from_pos (const bytecode_data_header_t *header_p, /**< byte-code data hea
|
||||
ecma_value_t this_binding_value, /**< value of 'ThisBinding' */
|
||||
ecma_object_t *lex_env_p, /**< lexical environment to use */
|
||||
bool is_strict, /**< is the code is strict mode code (ECMA-262 v5, 10.1.1) */
|
||||
bool is_eval_code) /**< is the code is eval code (ECMA-262 v5, 10.1) */
|
||||
bool is_eval_code, /**< is the code is eval code (ECMA-262 v5, 10.1) */
|
||||
ecma_collection_header_t *arg_collection_p) /**<
|
||||
* - collection of function call arguments,
|
||||
* if arguments for the called function
|
||||
* are placed on registers;
|
||||
* - NULL - otherwise.
|
||||
*/
|
||||
{
|
||||
ecma_completion_value_t completion;
|
||||
|
||||
@@ -605,8 +613,9 @@ vm_run_from_pos (const bytecode_data_header_t *header_p, /**< byte-code data hea
|
||||
|
||||
const uint32_t tmp_regs_num = curr->data.reg_var_decl.tmp_regs_num;
|
||||
const uint32_t local_var_regs_num = curr->data.reg_var_decl.local_var_regs_num;
|
||||
const uint32_t arg_regs_num = curr->data.reg_var_decl.arg_regs_num;
|
||||
|
||||
uint32_t regs_num = VM_SPECIAL_REGS_NUMBER + tmp_regs_num + local_var_regs_num;
|
||||
uint32_t regs_num = VM_SPECIAL_REGS_NUMBER + tmp_regs_num + local_var_regs_num + arg_regs_num;
|
||||
|
||||
MEM_DEFINE_LOCAL_ARRAY (regs, regs_num, ecma_value_t);
|
||||
|
||||
@@ -619,7 +628,7 @@ vm_run_from_pos (const bytecode_data_header_t *header_p, /**< byte-code data hea
|
||||
frame_ctx.is_call_in_direct_eval_form = false;
|
||||
frame_ctx.tmp_num_p = ecma_alloc_number ();
|
||||
|
||||
vm_stack_add_frame (&frame_ctx.stack_frame, regs, regs_num, local_var_regs_num);
|
||||
vm_stack_add_frame (&frame_ctx.stack_frame, regs, regs_num, local_var_regs_num, arg_regs_num, arg_collection_p);
|
||||
vm_stack_frame_set_reg_value (&frame_ctx.stack_frame,
|
||||
VM_REG_SPECIAL_THIS_BINDING,
|
||||
ecma_copy_value (this_binding_value, false));
|
||||
@@ -676,6 +685,22 @@ vm_get_scope_flags (const bytecode_data_header_t *bytecode_header_p, /**< byte-c
|
||||
return (opcode_scope_code_flags_t) flags_instr.data.meta.data_1;
|
||||
} /* vm_get_scope_flags */
|
||||
|
||||
/**
|
||||
* Get arguments number, encoded in specified reg_var_decl instruction
|
||||
*
|
||||
* @return value of "arguments number" reg_var_decl's parameter
|
||||
*/
|
||||
uint8_t
|
||||
vm_get_scope_args_num (const bytecode_data_header_t *bytecode_header_p, /**< byte-code data */
|
||||
vm_instr_counter_t reg_var_decl_oc) /**< position of reg_var_decl instruction */
|
||||
{
|
||||
const vm_instr_t *instrs_p = bytecode_header_p->instrs_p;
|
||||
const vm_instr_t *reg_var_decl_instr_p = &instrs_p[reg_var_decl_oc];
|
||||
JERRY_ASSERT (reg_var_decl_instr_p->op_idx == VM_OP_REG_VAR_DECL);
|
||||
|
||||
return reg_var_decl_instr_p->data.reg_var_decl.arg_regs_num;
|
||||
} /* vm_get_scope_args_num */
|
||||
|
||||
/**
|
||||
* Check whether currently executed code is strict mode code
|
||||
*
|
||||
|
||||
+2
-1
@@ -27,10 +27,11 @@ extern ecma_completion_value_t vm_run_eval (const bytecode_data_header_t *, bool
|
||||
|
||||
extern ecma_completion_value_t vm_loop (vm_frame_ctx_t *, vm_run_scope_t *);
|
||||
extern ecma_completion_value_t vm_run_from_pos (const bytecode_data_header_t *, vm_instr_counter_t,
|
||||
ecma_value_t, ecma_object_t *, bool, bool);
|
||||
ecma_value_t, ecma_object_t *, bool, bool, ecma_collection_header_t *);
|
||||
|
||||
extern vm_instr_t vm_get_instr (const vm_instr_t *, vm_instr_counter_t);
|
||||
extern opcode_scope_code_flags_t vm_get_scope_flags (const bytecode_data_header_t *, vm_instr_counter_t);
|
||||
extern uint8_t vm_get_scope_args_num (const bytecode_data_header_t *, vm_instr_counter_t);
|
||||
|
||||
extern bool vm_is_strict_mode (void);
|
||||
extern bool vm_is_direct_eval_form_call (void);
|
||||
|
||||
Reference in New Issue
Block a user