Download src/php/php-src/ext/opcache/jit/zend_jit_internal.h from meddyrat/dis-bench: direct link, hf CLI and curl.
- Browser
- Download file 29.7 kB
-
https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/ext/opcache/jit/zend_jit_internal.h
- Command line
-
hf download hf://datasets/meddyrat/dis-bench/src/php/php-src/ext/opcache/jit/zend_jit_internal.h
-
curl -L -o zend_jit_internal.h https://huggingface.co/datasets/meddyrat/dis-bench/resolve/main/src/php/php-src/ext/opcache/jit/zend_jit_internal.h
29.7 kB
| /* | |
| +----------------------------------------------------------------------+ | |
| | Zend JIT | | |
| +----------------------------------------------------------------------+ | |
| | Copyright (c) The PHP Group | | |
| +----------------------------------------------------------------------+ | |
| | This source file is subject to version 3.01 of the PHP license, | | |
| | that is bundled with this package in the file LICENSE, and is | | |
| | available through the world-wide-web at the following url: | | |
| | https://www.php.net/license/3_01.txt | | |
| | If you did not receive a copy of the PHP license and are unable to | | |
| | obtain it through the world-wide-web, please send a note to | | |
| | license@php.net so we can mail you a copy immediately. | | |
| +----------------------------------------------------------------------+ | |
| | Authors: Dmitry Stogov <dmitry@php.net> | | |
| | Xinchen Hui <laruence@php.net> | | |
| | Hao Sun <hao.sun@arm.com> | | |
| +----------------------------------------------------------------------+ | |
| */ | |
| /* Address Encoding */ | |
| typedef uintptr_t zend_jit_addr; | |
| static zend_always_inline bool zend_jit_same_addr(zend_jit_addr addr1, zend_jit_addr addr2) | |
| { | |
| if (addr1 == addr2) { | |
| return 1; | |
| } else if (Z_MODE(addr1) == IS_REG && Z_MODE(addr2) == IS_REG) { | |
| return Z_SSA_VAR(addr1) == Z_SSA_VAR(addr2); | |
| } else if (Z_MODE(addr1) == IS_REF_ZVAL && Z_MODE(addr2) == IS_REF_ZVAL) { | |
| return Z_IR_REF(addr1) == Z_IR_REF(addr2); | |
| } | |
| return 0; | |
| } | |
| typedef struct _zend_jit_op_array_extension { | |
| zend_func_info func_info; | |
| const zend_op_array *op_array; | |
| const void *orig_handler; | |
| } zend_jit_op_array_extension; | |
| /* Profiler */ | |
| extern zend_ulong zend_jit_profile_counter; | |
| extern int zend_jit_profile_counter_rid; | |
| /* Hot Counters */ | |
| extern int16_t zend_jit_hot_counters[ZEND_HOT_COUNTERS_COUNT]; | |
| static zend_always_inline zend_long zend_jit_hash(const void *ptr) | |
| { | |
| uintptr_t x; | |
| x = (uintptr_t)ptr >> 3; | |
| x = ((x >> 16) ^ x) * 0x45d9f3b; | |
| x = ((x >> 16) ^ x) * 0x45d9f3b; | |
| x = (x >> 16) ^ x; | |
| x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; | |
| x = (x ^ (x >> 27)) * 0x94d049bb133111eb; | |
| x = x ^ (x >> 31); | |
| return x; | |
| } | |
| void ZEND_FASTCALL zend_jit_hot_func(zend_execute_data *execute_data, const zend_op *opline); | |
| typedef struct _zend_jit_op_array_hot_extension { | |
| zend_func_info func_info; | |
| const zend_op_array *op_array; | |
| int16_t *counter; | |
| const void *orig_handlers[1]; | |
| } zend_jit_op_array_hot_extension; | |
| extern const zend_op *zend_jit_halt_op; | |
| /* VM handlers */ | |
| typedef ZEND_OPCODE_HANDLER_RET (ZEND_FASTCALL *zend_vm_opcode_handler_t)(ZEND_OPCODE_HANDLER_ARGS); | |
| /* VM helpers */ | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_leave_nested_func_helper(ZEND_OPCODE_HANDLER_ARGS_EX uint32_t call_info); | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_leave_top_func_helper(ZEND_OPCODE_HANDLER_ARGS_EX uint32_t call_info); | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_leave_func_helper(ZEND_OPCODE_HANDLER_ARGS); | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_profile_helper(ZEND_OPCODE_HANDLER_ARGS); | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_func_counter_helper(ZEND_OPCODE_HANDLER_ARGS); | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_counter_helper(ZEND_OPCODE_HANDLER_ARGS); | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_copy_extra_args_helper(ZEND_OPCODE_HANDLER_ARGS); | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_copy_extra_args_helper_no_skip_recv(ZEND_OPCODE_HANDLER_ARGS); | |
| bool ZEND_FASTCALL zend_jit_deprecated_helper(OPLINE_D); | |
| bool ZEND_FASTCALL zend_jit_nodiscard_helper(OPLINE_D); | |
| bool ZEND_FASTCALL zend_jit_deprecated_nodiscard_helper(OPLINE_D); | |
| void ZEND_FASTCALL zend_jit_undefined_long_key(EXECUTE_DATA_D); | |
| void ZEND_FASTCALL zend_jit_undefined_long_key_ex(zend_long key EXECUTE_DATA_DC); | |
| void ZEND_FASTCALL zend_jit_undefined_string_key(EXECUTE_DATA_D); | |
| zend_constant* ZEND_FASTCALL zend_jit_get_constant(const zval *key, uint32_t flags); | |
| zend_constant* ZEND_FASTCALL zend_jit_check_constant(const zval *key); | |
| /* Tracer */ | |
| typedef enum _zend_jit_trace_stop { | |
| ZEND_JIT_TRACE_STOP(ZEND_JIT_TRACE_STOP_NAME) | |
| ZEND_JIT_TRACE_HALT = 0x40 | |
| } zend_jit_trace_stop; | |
| typedef union _zend_op_trace_info { | |
| zend_op dummy; /* the size of this structure must be the same as zend_op */ | |
| struct { | |
| const void *orig_handler; | |
| const void *call_handler; | |
| int16_t *counter; | |
| uint8_t trace_flags; | |
| }; | |
| } zend_op_trace_info; | |
| typedef struct _zend_jit_op_array_trace_extension { | |
| zend_func_info func_info; | |
| const zend_op_array *op_array; | |
| size_t offset; /* offset from "zend_op" to corresponding "op_info" */ | |
| zend_op_trace_info trace_info[1]; | |
| } zend_jit_op_array_trace_extension; | |
| /* Recorder */ | |
| typedef enum _zend_jit_trace_op { | |
| ZEND_JIT_TRACE_VM, | |
| ZEND_JIT_TRACE_OP1_TYPE, | |
| ZEND_JIT_TRACE_OP2_TYPE, | |
| ZEND_JIT_TRACE_VAL_INFO, | |
| ZEND_JIT_TRACE_INIT_CALL, | |
| ZEND_JIT_TRACE_DO_ICALL, | |
| ZEND_JIT_TRACE_ENTER, | |
| ZEND_JIT_TRACE_BACK, | |
| ZEND_JIT_TRACE_END, | |
| ZEND_JIT_TRACE_START, | |
| } zend_jit_trace_op; | |
| struct _zend_jit_trace_rec { | |
| union { | |
| struct { ZEND_ENDIAN_LOHI( | |
| uint8_t op, /* zend_jit_trace_op */ | |
| union { | |
| struct { | |
| uint8_t op1_type;/* recorded zval op1_type for ZEND_JIT_TRACE_VM */ | |
| uint8_t op2_type;/* recorded zval op2_type for ZEND_JIT_TRACE_VM */ | |
| uint8_t op3_type;/* recorded zval for op_data.op1_type for ZEND_JIT_TRACE_VM */ | |
| }; | |
| struct { | |
| uint8_t start; /* ZEND_JIT_TRACE_START_MASK for ZEND_JIT_TRACE_START/END */ | |
| uint8_t stop; /* zend_jit_trace_stop for ZEND_JIT_TRACE_START/END */ | |
| uint8_t level; /* recursive return level for ZEND_JIT_TRACE_START */ | |
| }; | |
| }) | |
| }; | |
| uint32_t last; | |
| uint32_t info; /* "first_ssa_var" for ZEND_JIT_TRACE_ENTER and ZEND_JIT_TRACE_BACK, | |
| * "return_value_used" for ZEND_JIT_TRACE_ENTER, | |
| * "fake" for ZEND_JIT_TRACE_INIT_CALL */ | |
| }; | |
| union { | |
| const void *ptr; | |
| const zend_function *func; | |
| const zend_op_array *op_array; | |
| const zend_op *opline; | |
| const zend_class_entry *ce; | |
| }; | |
| }; | |
| typedef struct _zend_jit_ref_snapshot { | |
| union { | |
| int32_t ref; /* While generating code: The ir_ref to snapshot */ | |
| int32_t offset; /* After compilation / during deopt: C stack offset if 'reg' is spilled */ | |
| }; | |
| int8_t reg; /* Set after compilation by zend_jit_snapshot_handler() */ | |
| } zend_jit_ref_snapshot; | |
| typedef struct _zend_jit_trace_exit_info { | |
| const zend_op *opline; /* opline where VM should continue execution */ | |
| const zend_op_array *op_array; | |
| uint32_t flags; /* set of ZEND_JIT_EXIT_... */ | |
| uint32_t stack_size; | |
| uint32_t stack_offset; | |
| zend_jit_ref_snapshot poly_func; | |
| zend_jit_ref_snapshot poly_this; | |
| } zend_jit_trace_exit_info; | |
| typedef struct _zend_jit_trace_stack { | |
| union { | |
| uint32_t info; | |
| struct { | |
| uint8_t type; /* variable type (for type inference) */ | |
| uint8_t mem_type; /* stack slot type (for eliminate dead type store) */ | |
| int8_t reg; | |
| uint8_t flags; | |
| }; | |
| }; | |
| int32_t ref; | |
| } zend_jit_trace_stack; | |
| /* trace info flags */ | |
| typedef union _zend_jit_exit_const { | |
| int64_t i; | |
| double d; | |
| } zend_jit_exit_const; | |
| typedef struct _zend_jit_trace_info { | |
| uint32_t id; /* trace id */ | |
| uint32_t root; /* root trace id or self id for root traces */ | |
| uint32_t parent; /* parent trace id or 0 for root traces */ | |
| uint32_t link; /* link trace id or self id for loop) */ | |
| uint32_t exit_count; /* number of side exits */ | |
| uint32_t child_count; /* number of side traces for root traces */ | |
| uint32_t code_size; /* size of native code */ | |
| uint32_t exit_counters; /* offset in exit counters array */ | |
| uint32_t stack_map_size; | |
| uint32_t flags; /* See ZEND_JIT_TRACE_... defines above */ | |
| uint32_t polymorphism; /* Counter of polymorphic calls */ | |
| uint32_t jmp_table_size;/* number of jmp_table slots */ | |
| const zend_op_array *op_array; /* function */ | |
| const zend_op *opline; /* first opline */ | |
| const void *code_start; /* address of native code */ | |
| zend_jit_trace_exit_info *exit_info; /* info about side exits */ | |
| zend_jit_trace_stack *stack_map; | |
| //uint32_t loop_offset; | |
| uint32_t consts_count; /* number of side exits */ | |
| zend_jit_exit_const *constants; | |
| } zend_jit_trace_info; | |
| struct _zend_jit_trace_stack_frame { | |
| zend_jit_trace_stack_frame *call; | |
| zend_jit_trace_stack_frame *prev; | |
| const zend_function *func; | |
| const zend_op *call_opline; | |
| zend_class_entry *ce; /* $this */ | |
| uint32_t call_level; | |
| uint32_t _info; | |
| int used_stack; | |
| int old_checked_stack; | |
| int old_peek_checked_stack; | |
| zend_jit_trace_stack stack[1]; | |
| }; | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_func_trace_helper(ZEND_OPCODE_HANDLER_ARGS); | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_ret_trace_helper(ZEND_OPCODE_HANDLER_ARGS); | |
| ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_loop_trace_helper(ZEND_OPCODE_HANDLER_ARGS); | |
| int ZEND_FASTCALL zend_jit_trace_hot_root(zend_execute_data *execute_data, const zend_op *opline); | |
| zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *execute_data, | |
| const zend_op *opline, | |
| zend_jit_trace_rec *trace_buffer, | |
| uint8_t start, | |
| uint32_t is_megamorphc, | |
| int ret_depth); | |
| static zend_always_inline const zend_op* zend_jit_trace_get_exit_opline(zend_jit_trace_rec *trace, const zend_op *opline, bool *exit_if_true) | |
| { | |
| if (trace->op == ZEND_JIT_TRACE_VM || trace->op == ZEND_JIT_TRACE_END) { | |
| if (trace->opline == opline + 1) { | |
| /* not taken branch */ | |
| *exit_if_true = opline->opcode == ZEND_JMPNZ; | |
| return OP_JMP_ADDR(opline, opline->op2); | |
| } else if (trace->opline == OP_JMP_ADDR(opline, opline->op2)) { | |
| /* taken branch */ | |
| *exit_if_true = opline->opcode == ZEND_JMPZ; | |
| return opline + 1; | |
| } else { | |
| ZEND_UNREACHABLE(); | |
| } | |
| } else { | |
| ZEND_UNREACHABLE(); | |
| } | |
| *exit_if_true = 0; | |
| return NULL; | |
| } | |
| static zend_always_inline bool zend_jit_may_be_polymorphic_call(const zend_op *opline) | |
| { | |
| if (opline->opcode == ZEND_INIT_FCALL | |
| || opline->opcode == ZEND_INIT_FCALL_BY_NAME | |
| || opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME | |
| || opline->opcode == ZEND_INIT_PARENT_PROPERTY_HOOK_CALL) { | |
| return 0; | |
| } else if (opline->opcode == ZEND_INIT_METHOD_CALL | |
| || opline->opcode == ZEND_INIT_DYNAMIC_CALL) { | |
| return 1; | |
| } else if (opline->opcode == ZEND_INIT_STATIC_METHOD_CALL) { | |
| return (opline->op1_type != IS_CONST || opline->op2_type != IS_CONST); | |
| } else if (opline->opcode == ZEND_INIT_USER_CALL) { | |
| return (opline->op2_type != IS_CONST); | |
| } else if (opline->opcode == ZEND_NEW) { | |
| return (opline->op1_type != IS_CONST); | |
| } else { | |
| ZEND_UNREACHABLE(); | |
| return 0; | |
| } | |
| } | |
| /* Instruction cache flush */ | |
| /* bit helpers */ | |
| static zend_always_inline bool zend_long_is_power_of_two(zend_long x) | |
| { | |
| return (x > 0) && !(x & (x - 1)); | |
| } | |
| /* from http://aggregate.org/MAGIC/ */ | |
| static zend_always_inline uint32_t ones32(uint32_t x) | |
| { | |
| x -= ((x >> 1) & 0x55555555); | |
| x = (((x >> 2) & 0x33333333) + (x & 0x33333333)); | |
| x = (((x >> 4) + x) & 0x0f0f0f0f); | |
| x += (x >> 8); | |
| x += (x >> 16); | |
| return x & 0x0000003f; | |
| } | |
| static zend_always_inline uint32_t floor_log2(uint32_t x) | |
| { | |
| ZEND_ASSERT(x != 0); | |
| x |= (x >> 1); | |
| x |= (x >> 2); | |
| x |= (x >> 4); | |
| x |= (x >> 8); | |
| x |= (x >> 16); | |
| return ones32(x) - 1; | |
| } | |
| static zend_always_inline bool is_power_of_two(uint32_t x) | |
| { | |
| return !(x & (x - 1)) && x != 0; | |
| } | |
| static zend_always_inline bool has_concrete_type(uint32_t value_type) | |
| { | |
| return is_power_of_two (value_type & (MAY_BE_ANY|MAY_BE_UNDEF)); | |
| } | |
| static zend_always_inline uint32_t concrete_type(uint32_t value_type) | |
| { | |
| return floor_log2(value_type & (MAY_BE_ANY|MAY_BE_UNDEF)); | |
| } | |
| static zend_always_inline bool is_signed(double d) | |
| { | |
| return (((unsigned char*)&d)[sizeof(double)-1] & 0x80) != 0; | |
| } | |