/src/php-src/ext/opcache/jit/zend_jit_ir.c
Line | Count | Source |
1 | | /* |
2 | | * +----------------------------------------------------------------------+ |
3 | | * | Zend JIT | |
4 | | * +----------------------------------------------------------------------+ |
5 | | * | Copyright (c) The PHP Group | |
6 | | * +----------------------------------------------------------------------+ |
7 | | * | This source file is subject to version 3.01 of the PHP license, | |
8 | | * | that is bundled with this package in the file LICENSE, and is | |
9 | | * | available through the world-wide-web at the following url: | |
10 | | * | https://www.php.net/license/3_01.txt | |
11 | | * | If you did not receive a copy of the PHP license and are unable to | |
12 | | * | obtain it through the world-wide-web, please send a note to | |
13 | | * | license@php.net so we can mail you a copy immediately. | |
14 | | * +----------------------------------------------------------------------+ |
15 | | * | Authors: Dmitry Stogov <dmitry@php.net> | |
16 | | * +----------------------------------------------------------------------+ |
17 | | */ |
18 | | |
19 | | #include "Zend/zend_types.h" |
20 | | #include "Zend/zend_type_info.h" |
21 | | #include "jit/ir/ir.h" |
22 | | #include "jit/ir/ir_builder.h" |
23 | | #include "jit/tls/zend_jit_tls.h" |
24 | | |
25 | | #if defined(IR_TARGET_X86) |
26 | | # define IR_REG_SP 4 /* IR_REG_RSP */ |
27 | | # define IR_REG_FP 5 /* IR_REG_RBP */ |
28 | | # define ZREG_FP 6 /* IR_REG_RSI */ |
29 | | # define ZREG_IP 7 /* IR_REG_RDI */ |
30 | | # define ZREG_FIRST_FPR 8 |
31 | | # define IR_REGSET_PRESERVED ((1<<3) | (1<<5) | (1<<6) | (1<<7)) /* all preserved registers */ |
32 | | # if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL |
33 | | # error |
34 | | # endif |
35 | | #elif defined(IR_TARGET_X64) |
36 | 0 | # define IR_REG_SP 4 /* IR_REG_RSP */ |
37 | 0 | # define IR_REG_FP 5 /* IR_REG_RBP */ |
38 | | # if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL |
39 | | /* Use the first two arg registers of the preserve_none calling convention for FP/IP |
40 | | * https://github.com/llvm/llvm-project/blob/68bfe91b5a34f80dbcc4f0a7fa5d7aa1cdf959c2/llvm/lib/Target/X86/X86CallingConv.td#L1029 */ |
41 | 0 | # define ZREG_FP 12 /* IR_REG_R12 */ |
42 | 0 | # define ZREG_IP 13 /* IR_REG_R13 */ |
43 | | # else |
44 | | # define ZREG_FP 14 /* IR_REG_R14 */ |
45 | | # define ZREG_IP 15 /* IR_REG_R15 */ |
46 | | # endif |
47 | 0 | # define ZREG_FIRST_FPR 16 |
48 | | # if defined(_WIN64) |
49 | | # define IR_REGSET_PRESERVED ((1<<3) | (1<<5) | (1<<6) | (1<<7) | (1<<12) | (1<<13) | (1<<14) | (1<<15)) |
50 | | /* |
51 | | # define IR_REGSET_PRESERVED ((1<<3) | (1<<5) | (1<<6) | (1<<7) | (1<<12) | (1<<13) | (1<<14) | (1<<15) | \ |
52 | | (1<<(16+6)) | (1<<(16+7)) | (1<<(16+8)) | (1<<(16+9)) | (1<<(16+10)) | \ |
53 | | (1<<(16+11)) | (1<<(16+12)) | (1<<(16+13)) | (1<<(16+14)) | (1<<(16+15))) |
54 | | */ |
55 | | # define IR_SHADOW_ARGS 32 |
56 | | # else |
57 | 0 | # define IR_REGSET_PRESERVED ((1<<3) | (1<<5) | (1<<12) | (1<<13) | (1<<14) | (1<<15)) /* all preserved registers */ |
58 | | # endif |
59 | | #elif defined(IR_TARGET_AARCH64) |
60 | | # define IR_REG_SP 31 /* IR_REG_RSP */ |
61 | | # define IR_REG_LR 30 /* IR_REG_X30 */ |
62 | | # define IR_REG_FP 29 /* IR_REG_X29 */ |
63 | | # if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL |
64 | | /* Use the first two arg registers of the preserve_none calling convention for FP/IP |
65 | | * https://github.com/llvm/llvm-project/blob/68bfe91b5a34f80dbcc4f0a7fa5d7aa1cdf959c2/llvm/lib/Target/AArch64/AArch64CallingConvention.td#L541 */ |
66 | | # define ZREG_FP 20 /* IR_REG_X20 */ |
67 | | # define ZREG_IP 21 /* IR_REG_X21 */ |
68 | | # else |
69 | | # define ZREG_FP 27 /* IR_REG_X27 */ |
70 | | # define ZREG_IP 28 /* IR_REG_X28 */ |
71 | | # endif |
72 | | # define ZREG_FIRST_FPR 32 |
73 | | # define IR_REGSET_PRESERVED ((1<<19) | (1<<20) | (1<<21) | (1<<22) | (1<<23) | \ |
74 | | (1<<24) | (1<<25) | (1<<26) | (1<<27) | (1<<28)) /* all preserved registers */ |
75 | | #else |
76 | | # error "Unknown IR target" |
77 | | #endif |
78 | | |
79 | 0 | #define ZREG_RX ZREG_IP |
80 | | |
81 | | #define OPTIMIZE_FOR_SIZE 0 |
82 | | |
83 | | /* IR builder defines */ |
84 | | #undef _ir_CTX |
85 | 0 | #define _ir_CTX (&jit->ctx) |
86 | | |
87 | | #if GCC_GLOBAL_REGS |
88 | | # define IR_OPCODE_HANDLER_RET IR_VOID |
89 | | #else |
90 | | # define IR_OPCODE_HANDLER_RET IR_ADDR |
91 | | #endif |
92 | | |
93 | | #undef ir_CONST_ADDR |
94 | 0 | #define ir_CONST_ADDR(_addr) jit_CONST_ADDR(jit, (uintptr_t)(_addr)) |
95 | | #define ir_CONST_FUNC(_addr) jit_CONST_FUNC(jit, (uintptr_t)(_addr), 0) |
96 | 0 | #define ir_CONST_FC_FUNC(_addr) jit_CONST_FUNC(jit, (uintptr_t)(_addr), IR_FASTCALL_FUNC) |
97 | | #define ir_CAST_FC_FUNC(_addr) ir_fold2(_ir_CTX, IR_OPT(IR_PROTO, IR_ADDR), (_addr), \ |
98 | | ir_proto_0(_ir_CTX, IR_FASTCALL_FUNC, IR_I32)) |
99 | | # define ir_CONST_OPCODE_HANDLER_FUNC(_addr) \ |
100 | 0 | jit_CONST_OPCODE_HANDLER_FUNC(jit, _addr) |
101 | | # define ir_CAST_OPCODE_HANDLER_FUNC(_addr) ir_fold2(_ir_CTX, IR_OPT(IR_PROTO, IR_ADDR), (_addr), \ |
102 | | ir_proto_0(_ir_CTX, IR_FASTCALL_FUNC, IR_OPCODE_HANDLER_RET)) |
103 | | |
104 | | #define ir_CONST_FUNC_PROTO(_addr, _proto) \ |
105 | | jit_CONST_FUNC_PROTO(jit, (uintptr_t)(_addr), (_proto)) |
106 | | |
107 | | #undef ir_ADD_OFFSET |
108 | | #define ir_ADD_OFFSET(_addr, _offset) \ |
109 | 0 | jit_ADD_OFFSET(jit, _addr, _offset) |
110 | | |
111 | | #ifdef ZEND_ENABLE_ZVAL_LONG64 |
112 | 0 | # define IR_LONG IR_I64 |
113 | 0 | # define ir_CONST_LONG ir_CONST_I64 |
114 | | # define ir_UNARY_OP_L ir_UNARY_OP_I64 |
115 | 0 | # define ir_BINARY_OP_L ir_BINARY_OP_I64 |
116 | | # define ir_ADD_L ir_ADD_I64 |
117 | 0 | # define ir_SUB_L ir_SUB_I64 |
118 | 0 | # define ir_MUL_L ir_MUL_I64 |
119 | 0 | # define ir_DIV_L ir_DIV_I64 |
120 | 0 | # define ir_MOD_L ir_MOD_I64 |
121 | | # define ir_NEG_L ir_NEG_I64 |
122 | | # define ir_ABS_L ir_ABS_I64 |
123 | | # define ir_SEXT_L ir_SEXT_I64 |
124 | 0 | # define ir_ZEXT_L ir_ZEXT_I64 |
125 | | # define ir_TRUNC_L ir_TRUNC_I64 |
126 | 0 | # define ir_BITCAST_L ir_BITCAST_I64 |
127 | | # define ir_FP2L ir_FP2I64 |
128 | 0 | # define ir_ADD_OV_L ir_ADD_OV_I64 |
129 | 0 | # define ir_SUB_OV_L ir_SUB_OV_I64 |
130 | | # define ir_MUL_OV_L ir_MUL_OV_I64 |
131 | | # define ir_NOT_L ir_NOT_I64 |
132 | | # define ir_OR_L ir_OR_I64 |
133 | 0 | # define ir_AND_L ir_AND_I64 |
134 | | # define ir_XOR_L ir_XOR_I64 |
135 | 0 | # define ir_SHL_L ir_SHL_I64 |
136 | 0 | # define ir_SHR_L ir_SHR_I64 |
137 | 0 | # define ir_SAR_L ir_SAR_I64 |
138 | | # define ir_ROL_L ir_ROL_I64 |
139 | | # define ir_ROR_L ir_ROR_I64 |
140 | | # define ir_MIN_L ir_MIN_I64 |
141 | | # define ir_MAX_L ir_MAX_I64 |
142 | 0 | # define ir_LOAD_L ir_LOAD_I64 |
143 | | #else |
144 | | # define IR_LONG IR_I32 |
145 | | # define ir_CONST_LONG ir_CONST_I32 |
146 | | # define ir_UNARY_OP_L ir_UNARY_OP_I32 |
147 | | # define ir_BINARY_OP_L ir_BINARY_OP_I32 |
148 | | # define ir_ADD_L ir_ADD_I32 |
149 | | # define ir_SUB_L ir_SUB_I32 |
150 | | # define ir_MUL_L ir_MUL_I32 |
151 | | # define ir_DIV_L ir_DIV_I32 |
152 | | # define ir_MOD_L ir_MOD_I32 |
153 | | # define ir_NEG_L ir_NEG_I32 |
154 | | # define ir_ABS_L ir_ABS_I32 |
155 | | # define ir_SEXT_L ir_SEXT_I32 |
156 | | # define ir_ZEXT_L ir_ZEXT_I32 |
157 | | # define ir_TRUNC_L ir_TRUNC_I32 |
158 | | # define ir_BITCAST_L ir_BITCAST_I32 |
159 | | # define ir_FP2L ir_FP2I32 |
160 | | # define ir_ADD_OV_L ir_ADD_OV_I32 |
161 | | # define ir_SUB_OV_L ir_SUB_OV_I32 |
162 | | # define ir_MUL_OV_L ir_MUL_OV_I32 |
163 | | # define ir_NOT_L ir_NOT_I32 |
164 | | # define ir_OR_L ir_OR_I32 |
165 | | # define ir_AND_L ir_AND_I32 |
166 | | # define ir_XOR_L ir_XOR_I32 |
167 | | # define ir_SHL_L ir_SHL_I32 |
168 | | # define ir_SHR_L ir_SHR_I32 |
169 | | # define ir_SAR_L ir_SAR_I32 |
170 | | # define ir_ROL_L ir_ROL_I32 |
171 | | # define ir_ROR_L ir_ROR_I32 |
172 | | # define ir_MIN_L ir_MIN_I32 |
173 | | # define ir_MAX_L ir_MAX_I32 |
174 | | # define ir_LOAD_L ir_LOAD_I32 |
175 | | #endif |
176 | | |
177 | | /* A helper structure to collect IT rers for the following use in (MERGE/PHI)_N */ |
178 | | typedef struct _ir_refs { |
179 | | uint32_t count; |
180 | | uint32_t limit; |
181 | | ir_ref refs[] ZEND_ELEMENT_COUNT(count); |
182 | | } ir_refs; |
183 | | |
184 | | #define ir_refs_size(_n) (offsetof(ir_refs, refs) + sizeof(ir_ref) * (_n)) |
185 | 0 | #define ir_refs_init(_name, _n) _name = alloca(ir_refs_size(_n)); \ |
186 | 0 | do {_name->count = 0; _name->limit = (_n);} while (0) |
187 | | |
188 | | static void ir_refs_add(ir_refs *refs, ir_ref ref) |
189 | 0 | { |
190 | 0 | ir_ref *ptr; |
191 | |
|
192 | 0 | ZEND_ASSERT(refs->count < refs->limit); |
193 | 0 | ptr = refs->refs; |
194 | 0 | ptr[refs->count++] = ref; |
195 | 0 | } |
196 | | |
197 | | static size_t zend_jit_trace_prologue_size = (size_t)-1; |
198 | | #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) |
199 | | static uint32_t allowed_opt_flags = 0; |
200 | | static uint32_t default_mflags = 0; |
201 | | #endif |
202 | | static bool delayed_call_chain = false; // TODO: remove this var (use jit->delayed_call_level) ??? |
203 | | |
204 | | #ifdef ZTS |
205 | | static size_t tsrm_ls_cache_tcb_offset = 0; |
206 | | static size_t tsrm_tls_index = -1; |
207 | | static size_t tsrm_tls_offset = -1; |
208 | | |
209 | | # define EG_TLS_OFFSET(field) \ |
210 | | (executor_globals_offset + offsetof(zend_executor_globals, field)) |
211 | | |
212 | | # define CG_TLS_OFFSET(field) \ |
213 | | (compiler_globals_offset + offsetof(zend_compiler_globals, field)) |
214 | | |
215 | | # define jit_EG(_field) \ |
216 | | ir_ADD_OFFSET(jit_TLS(jit), EG_TLS_OFFSET(_field)) |
217 | | |
218 | | # define jit_CG(_field) \ |
219 | | ir_ADD_OFFSET(jit_TLS(jit), CG_TLS_OFFSET(_field)) |
220 | | |
221 | | #else |
222 | | |
223 | | # define jit_EG(_field) \ |
224 | 0 | ir_CONST_ADDR(&EG(_field)) |
225 | | |
226 | | # define jit_CG(_field) \ |
227 | | ir_CONST_ADDR(&CG(_field)) |
228 | | |
229 | | #endif |
230 | | |
231 | | #define jit_CALL(_call, _field) \ |
232 | 0 | ir_ADD_OFFSET(_call, offsetof(zend_execute_data, _field)) |
233 | | |
234 | | #define jit_EX(_field) \ |
235 | | jit_CALL(jit_FP(jit), _field) |
236 | | |
237 | | #define jit_RX(_field) \ |
238 | | jit_CALL(jit_IP(jit), _field) |
239 | | |
240 | | #define JIT_STUBS(_) \ |
241 | | _(exception_handler, IR_SKIP_PROLOGUE) \ |
242 | | _(exception_handler_undef, IR_SKIP_PROLOGUE) \ |
243 | | _(exception_handler_free_op2, IR_SKIP_PROLOGUE) \ |
244 | | _(exception_handler_free_op1_op2, IR_SKIP_PROLOGUE) \ |
245 | | _(interrupt_handler, IR_SKIP_PROLOGUE) \ |
246 | | _(leave_function_handler, IR_SKIP_PROLOGUE) \ |
247 | | _(negative_shift, IR_SKIP_PROLOGUE) \ |
248 | | _(mod_by_zero, IR_SKIP_PROLOGUE) \ |
249 | | _(invalid_this, IR_SKIP_PROLOGUE) \ |
250 | | _(undefined_function, IR_SKIP_PROLOGUE) \ |
251 | | _(throw_cannot_pass_by_ref, IR_SKIP_PROLOGUE) \ |
252 | | _(icall_throw, IR_SKIP_PROLOGUE) \ |
253 | | _(leave_throw, IR_SKIP_PROLOGUE) \ |
254 | | _(hybrid_runtime_jit, IR_SKIP_PROLOGUE | IR_START_BR_TARGET) \ |
255 | | _(hybrid_profile_jit, IR_SKIP_PROLOGUE | IR_START_BR_TARGET) \ |
256 | | _(hybrid_func_hot_counter, IR_SKIP_PROLOGUE | IR_START_BR_TARGET) \ |
257 | | _(hybrid_loop_hot_counter, IR_SKIP_PROLOGUE | IR_START_BR_TARGET) \ |
258 | | _(hybrid_func_trace_counter, IR_SKIP_PROLOGUE | IR_START_BR_TARGET) \ |
259 | | _(hybrid_ret_trace_counter, IR_SKIP_PROLOGUE | IR_START_BR_TARGET) \ |
260 | | _(hybrid_loop_trace_counter, IR_SKIP_PROLOGUE | IR_START_BR_TARGET) \ |
261 | | _(trace_halt, IR_SKIP_PROLOGUE) \ |
262 | | _(trace_escape, IR_SKIP_PROLOGUE) \ |
263 | | _(trace_exit, IR_SKIP_PROLOGUE) \ |
264 | | _(undefined_offset, IR_FUNCTION | IR_FASTCALL_FUNC) \ |
265 | | _(undefined_key, IR_FUNCTION | IR_FASTCALL_FUNC) \ |
266 | | _(cannot_add_element, IR_FUNCTION | IR_FASTCALL_FUNC) \ |
267 | | _(assign_const, IR_FUNCTION | IR_FASTCALL_FUNC) \ |
268 | | _(assign_tmp, IR_FUNCTION | IR_FASTCALL_FUNC) \ |
269 | | _(assign_var, IR_FUNCTION | IR_FASTCALL_FUNC) \ |
270 | | _(assign_cv_noref, IR_FUNCTION | IR_FASTCALL_FUNC) \ |
271 | | _(assign_cv, IR_FUNCTION | IR_FASTCALL_FUNC) \ |
272 | | _(new_array, IR_FUNCTION | IR_FASTCALL_FUNC) \ |
273 | | |
274 | | #define JIT_STUB_ID(name, flags) \ |
275 | | jit_stub_ ## name, |
276 | | |
277 | | #define JIT_STUB_FORWARD(name, flags) \ |
278 | | static int zend_jit_ ## name ## _stub(zend_jit_ctx *jit); |
279 | | |
280 | | #define JIT_STUB(name, flags) \ |
281 | | {JIT_STUB_PREFIX #name, zend_jit_ ## name ## _stub, flags}, |
282 | | |
283 | | typedef enum _jit_stub_id { |
284 | | JIT_STUBS(JIT_STUB_ID) |
285 | | jit_last_stub |
286 | | } jit_stub_id; |
287 | | |
288 | | typedef struct _zend_jit_reg_var { |
289 | | ir_ref ref; |
290 | | uint32_t flags; |
291 | | } zend_jit_reg_var; |
292 | | |
293 | | typedef struct _zend_jit_ctx { |
294 | | ir_ctx ctx; |
295 | | const zend_op *last_valid_opline; |
296 | | bool use_last_valid_opline; |
297 | | bool track_last_valid_opline; |
298 | | bool reuse_ip; |
299 | | uint32_t delayed_call_level; |
300 | | int b; /* current basic block number or -1 */ |
301 | | #ifdef ZTS |
302 | | ir_ref tls; |
303 | | #endif |
304 | | ir_ref fp; |
305 | | ir_ref poly_func_ref; /* restored from parent trace snapshot */ |
306 | | ir_ref poly_this_ref; /* restored from parent trace snapshot */ |
307 | | ir_ref trace_loop_ref; |
308 | | ir_ref return_inputs; |
309 | | const zend_op_array *op_array; |
310 | | const zend_op_array *current_op_array; |
311 | | zend_ssa *ssa; |
312 | | zend_string *name; |
313 | | ir_ref *bb_start_ref; /* PHP BB -> IR ref mapping */ |
314 | | ir_ref *bb_predecessors; /* PHP BB -> index in bb_edges -> IR refs of predessors */ |
315 | | ir_ref *bb_edges; |
316 | | zend_jit_trace_info *trace; |
317 | | zend_jit_reg_var *ra; |
318 | | int delay_var; |
319 | | ir_refs *delay_refs; |
320 | | ir_ref eg_exception_addr; |
321 | | HashTable addr_hash; |
322 | | ir_ref stub_addr[jit_last_stub]; |
323 | | } zend_jit_ctx; |
324 | | |
325 | | typedef int8_t zend_reg; |
326 | | |
327 | | typedef struct _zend_jit_registers_buf { |
328 | | #if defined(IR_TARGET_X64) |
329 | | uint64_t gpr[16]; /* general purpose integer register */ |
330 | | double fpr[16]; /* floating point registers */ |
331 | | #elif defined(IR_TARGET_X86) |
332 | | uint32_t gpr[8]; /* general purpose integer register */ |
333 | | double fpr[8]; /* floating point registers */ |
334 | | #elif defined (IR_TARGET_AARCH64) |
335 | | uint64_t gpr[32]; /* general purpose integer register */ |
336 | | double fpr[32]; /* floating point registers */ |
337 | | #else |
338 | | # error "Unknown IR target" |
339 | | #endif |
340 | | } zend_jit_registers_buf; |
341 | | |
342 | | /* Keep 32 exit points in a single code block */ |
343 | 0 | #define ZEND_JIT_EXIT_POINTS_SPACING 4 // push byte + short jmp = bytes |
344 | 0 | #define ZEND_JIT_EXIT_POINTS_PER_GROUP 32 // number of continuous exit points |
345 | | |
346 | | static uint32_t zend_jit_exit_point_by_addr(const void *addr); |
347 | | int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf *regs); |
348 | | |
349 | | static int zend_jit_assign_to_variable(zend_jit_ctx *jit, |
350 | | const zend_op *opline, |
351 | | zend_jit_addr var_use_addr, |
352 | | zend_jit_addr var_addr, |
353 | | uint32_t var_info, |
354 | | uint32_t var_def_info, |
355 | | uint8_t val_type, |
356 | | zend_jit_addr val_addr, |
357 | | uint32_t val_info, |
358 | | zend_jit_addr res_addr, |
359 | | zend_jit_addr ref_addr, |
360 | | bool check_exception); |
361 | | |
362 | | static ir_ref jit_CONST_FUNC(zend_jit_ctx *jit, uintptr_t addr, uint16_t flags); |
363 | | |
364 | | typedef struct _zend_jit_stub { |
365 | | const char *name; |
366 | | int (*stub)(zend_jit_ctx *jit); |
367 | | uint32_t flags; |
368 | | } zend_jit_stub; |
369 | | |
370 | | JIT_STUBS(JIT_STUB_FORWARD) |
371 | | |
372 | | static const zend_jit_stub zend_jit_stubs[] = { |
373 | | JIT_STUBS(JIT_STUB) |
374 | | }; |
375 | | |
376 | | #if defined(_WIN32) || defined(IR_TARGET_AARCH64) |
377 | | /* We keep addresses in SHM to share them between sepaeate processes (on Windows) or to support veneers (on AArch64) */ |
378 | | static void** zend_jit_stub_handlers = NULL; |
379 | | #else |
380 | | static void* zend_jit_stub_handlers[sizeof(zend_jit_stubs) / sizeof(zend_jit_stubs[0])]; |
381 | | #endif |
382 | | |
383 | | #if defined(IR_TARGET_AARCH64) |
384 | | |
385 | | # ifdef __FreeBSD__ |
386 | | /* https://github.com/freebsd/freebsd-src/blob/c52ca7dd09066648b1cc40f758289404d68ab886/libexec/rtld-elf/aarch64/reloc.c#L180-L184 */ |
387 | | typedef struct TLSDescriptor { |
388 | | void* thunk; |
389 | | int index; |
390 | | size_t offset; |
391 | | } TLSDescriptor; |
392 | | # endif |
393 | | |
394 | | #define IR_HAS_VENEERS (1U<<31) /* IR_RESERVED_FLAG_1 */ |
395 | | |
396 | | static const void *zend_jit_get_veneer(ir_ctx *ctx, const void *addr) |
397 | | { |
398 | | int i, count = sizeof(zend_jit_stubs) / sizeof(zend_jit_stubs[0]); |
399 | | |
400 | | for (i = 0; i < count; i++) { |
401 | | if (zend_jit_stub_handlers[i] == addr) { |
402 | | return zend_jit_stub_handlers[count + i]; |
403 | | } |
404 | | } |
405 | | |
406 | | if (((zend_jit_ctx*)ctx)->trace |
407 | | && (void*)addr >= dasm_buf && (void*)addr < dasm_end) { |
408 | | uint32_t exit_point = zend_jit_exit_point_by_addr(addr); |
409 | | |
410 | | if (exit_point != (uint32_t)-1) { |
411 | | zend_jit_trace_info *t = ((zend_jit_ctx*)ctx)->trace; |
412 | | |
413 | | ZEND_ASSERT(exit_point < t->exit_count); |
414 | | return (const void*)((char*)ctx->deoptimization_exits_base + (exit_point * 4)); |
415 | | } |
416 | | } |
417 | | |
418 | | return NULL; |
419 | | } |
420 | | |
421 | | static bool zend_jit_set_veneer(ir_ctx *ctx, const void *addr, const void *veneer) |
422 | | { |
423 | | int i, count = sizeof(zend_jit_stubs) / sizeof(zend_jit_stubs[0]); |
424 | | uint32_t exit_point = zend_jit_exit_point_by_addr(addr); |
425 | | |
426 | | if (exit_point != (uint32_t)-1) { |
427 | | return true; |
428 | | } |
429 | | for (i = 0; i < count; i++) { |
430 | | if (zend_jit_stub_handlers[i] == addr) { |
431 | | const void **ptr = (const void**)&zend_jit_stub_handlers[count + i]; |
432 | | *ptr = veneer; |
433 | | ctx->flags2 |= IR_HAS_VENEERS; |
434 | | #ifdef HAVE_CAPSTONE |
435 | | int64_t offset; |
436 | | if (JIT_G(debug) & ZEND_JIT_DEBUG_ASM) { |
437 | | const char *name = ir_disasm_find_symbol((uint64_t)(uintptr_t)addr, &offset); |
438 | | |
439 | | if (name && !offset) { |
440 | | if (strstr(name, "@veneer") == NULL) { |
441 | | char *new_name; |
442 | | |
443 | | zend_spprintf(&new_name, 0, "%s@veneer", name); |
444 | | ir_disasm_add_symbol(new_name, (uint64_t)(uintptr_t)veneer, 4); |
445 | | efree(new_name); |
446 | | } else { |
447 | | ir_disasm_add_symbol(name, (uint64_t)(uintptr_t)veneer, 4); |
448 | | } |
449 | | } |
450 | | } |
451 | | #endif |
452 | | return true; |
453 | | } |
454 | | } |
455 | | |
456 | | return false; |
457 | | } |
458 | | |
459 | | static void zend_jit_commit_veneers(void) |
460 | | { |
461 | | int i, count = sizeof(zend_jit_stubs) / sizeof(zend_jit_stubs[0]); |
462 | | |
463 | | for (i = 0; i < count; i++) { |
464 | | if (zend_jit_stub_handlers[count + i]) { |
465 | | zend_jit_stub_handlers[i] = zend_jit_stub_handlers[count + i]; |
466 | | zend_jit_stub_handlers[count + i] = NULL; |
467 | | } |
468 | | } |
469 | | } |
470 | | #endif |
471 | | |
472 | | static bool zend_jit_prefer_const_addr_load(zend_jit_ctx *jit, uintptr_t addr) |
473 | 0 | { |
474 | | #if defined(IR_TARGET_X86) |
475 | | return false; /* always use immediate value */ |
476 | | #elif defined(IR_TARGET_X64) |
477 | | return addr > 0xffffffff; /* prefer loading long constant from memery */ |
478 | | #elif defined(IR_TARGET_AARCH64) |
479 | | return addr > 0xffff; |
480 | | #else |
481 | | # error "Unknown IR target" |
482 | | #endif |
483 | 0 | } |
484 | | |
485 | | static const char* zend_reg_name(int8_t reg) |
486 | 0 | { |
487 | 0 | return ir_reg_name(reg, ir_reg_is_int(reg) ? IR_LONG : IR_DOUBLE); |
488 | 0 | } |
489 | | |
490 | | /* IR helpers */ |
491 | | |
492 | | #ifdef ZTS |
493 | | static void * ZEND_FASTCALL zend_jit_get_tsrm_ls_cache(void) |
494 | | { |
495 | | return _tsrm_ls_cache; |
496 | | } |
497 | | |
498 | | static ir_ref jit_TLS(zend_jit_ctx *jit) |
499 | | { |
500 | | ZEND_ASSERT(jit->ctx.control); |
501 | | if (jit->tls) { |
502 | | /* Emit "TLS" once for basic block */ |
503 | | ir_insn *insn; |
504 | | ir_ref ref = jit->ctx.control; |
505 | | |
506 | | while (1) { |
507 | | if (ref == jit->tls) { |
508 | | return jit->tls; |
509 | | } |
510 | | insn = &jit->ctx.ir_base[ref]; |
511 | | if (insn->op >= IR_START || insn->op == IR_CALL) { |
512 | | break; |
513 | | } |
514 | | ref = insn->op1; |
515 | | } |
516 | | } |
517 | | |
518 | | if (tsrm_ls_cache_tcb_offset == 0 && tsrm_tls_index == -1) { |
519 | | jit->tls = ir_CALL(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_get_tsrm_ls_cache)); |
520 | | } else { |
521 | | jit->tls = ir_TLS( |
522 | | tsrm_ls_cache_tcb_offset ? tsrm_ls_cache_tcb_offset : tsrm_tls_index, |
523 | | tsrm_ls_cache_tcb_offset ? IR_NULL : tsrm_tls_offset); |
524 | | } |
525 | | |
526 | | return jit->tls; |
527 | | } |
528 | | #endif |
529 | | |
530 | | static ir_ref jit_CONST_ADDR(zend_jit_ctx *jit, uintptr_t addr) |
531 | 0 | { |
532 | 0 | ir_ref ref; |
533 | 0 | zval *zv; |
534 | |
|
535 | 0 | if (addr == 0) { |
536 | 0 | return IR_NULL; |
537 | 0 | } |
538 | 0 | zv = zend_hash_index_lookup(&jit->addr_hash, addr); |
539 | 0 | if (Z_TYPE_P(zv) == IS_LONG) { |
540 | 0 | ref = Z_LVAL_P(zv); |
541 | 0 | ZEND_ASSERT(jit->ctx.ir_base[ref].opt == IR_OPT(IR_ADDR, IR_ADDR)); |
542 | 0 | } else { |
543 | 0 | ref = ir_unique_const_addr(&jit->ctx, addr); |
544 | 0 | ZVAL_LONG(zv, ref); |
545 | 0 | } |
546 | 0 | return ref; |
547 | 0 | } |
548 | | |
549 | | static ir_ref jit_CONST_FUNC_PROTO(zend_jit_ctx *jit, uintptr_t addr, ir_ref proto) |
550 | 0 | { |
551 | 0 | ir_ref ref; |
552 | 0 | ir_insn *insn; |
553 | 0 | zval *zv; |
554 | |
|
555 | 0 | ZEND_ASSERT(addr != 0); |
556 | 0 | zv = zend_hash_index_lookup(&jit->addr_hash, addr); |
557 | 0 | if (Z_TYPE_P(zv) == IS_LONG) { |
558 | 0 | ref = Z_LVAL_P(zv); |
559 | 0 | ZEND_ASSERT(jit->ctx.ir_base[ref].opt == IR_OPT(IR_FUNC_ADDR, IR_ADDR) && jit->ctx.ir_base[ref].proto == proto); |
560 | 0 | } else { |
561 | 0 | ref = ir_unique_const_addr(&jit->ctx, addr); |
562 | 0 | insn = &jit->ctx.ir_base[ref]; |
563 | 0 | insn->optx = IR_OPT(IR_FUNC_ADDR, IR_ADDR); |
564 | 0 | insn->proto = proto; |
565 | 0 | ZVAL_LONG(zv, ref); |
566 | 0 | } |
567 | 0 | return ref; |
568 | 0 | } |
569 | | |
570 | | static ir_ref jit_CONST_FUNC(zend_jit_ctx *jit, uintptr_t addr, uint16_t flags) |
571 | 0 | { |
572 | | #if defined(IR_TARGET_X86) |
573 | | /* TODO: dummy prototype (only flags matter) ??? */ |
574 | | ir_ref proto = flags ? ir_proto_0(&jit->ctx, flags, IR_I32) : 0; |
575 | | #else |
576 | 0 | ir_ref proto = 0; |
577 | 0 | #endif |
578 | |
|
579 | 0 | return jit_CONST_FUNC_PROTO(jit, addr, proto); |
580 | 0 | } |
581 | | |
582 | | static ir_ref jit_CONST_OPCODE_HANDLER_FUNC(zend_jit_ctx *jit, zend_vm_opcode_handler_t handler) |
583 | 0 | { |
584 | 0 | return jit_CONST_FUNC(jit, (uintptr_t)handler, IR_FASTCALL_FUNC); |
585 | 0 | } |
586 | | |
587 | | static ir_ref jit_ADD_OFFSET(zend_jit_ctx *jit, ir_ref addr, uintptr_t offset) |
588 | 0 | { |
589 | 0 | if (offset) { |
590 | 0 | addr = ir_ADD_A(addr, ir_CONST_ADDR(offset)); |
591 | 0 | } |
592 | 0 | return addr; |
593 | 0 | } |
594 | | |
595 | | static ir_ref jit_EG_exception(zend_jit_ctx *jit) |
596 | 0 | { |
597 | | #ifdef ZTS |
598 | | return jit_EG(exception); |
599 | | #else |
600 | 0 | ir_ref ref = jit->eg_exception_addr; |
601 | |
|
602 | 0 | if (UNEXPECTED(!ref)) { |
603 | 0 | ref = ir_unique_const_addr(&jit->ctx, (uintptr_t)&EG(exception)); |
604 | 0 | jit->eg_exception_addr = ref; |
605 | 0 | } |
606 | 0 | return ref; |
607 | 0 | #endif |
608 | 0 | } |
609 | | |
610 | | static ir_ref jit_STUB_ADDR(zend_jit_ctx *jit, jit_stub_id id) |
611 | 0 | { |
612 | 0 | ir_ref ref = jit->stub_addr[id]; |
613 | |
|
614 | 0 | if (UNEXPECTED(!ref)) { |
615 | 0 | ref = ir_unique_const_addr(&jit->ctx, (uintptr_t)zend_jit_stub_handlers[id]); |
616 | 0 | jit->stub_addr[id] = ref; |
617 | 0 | } |
618 | 0 | return ref; |
619 | 0 | } |
620 | | |
621 | | static ir_ref jit_STUB_FUNC_ADDR(zend_jit_ctx *jit, jit_stub_id id, uint16_t flags) |
622 | 0 | { |
623 | 0 | ir_ref ref = jit->stub_addr[id]; |
624 | 0 | ir_insn *insn; |
625 | |
|
626 | 0 | if (UNEXPECTED(!ref)) { |
627 | 0 | ref = ir_unique_const_addr(&jit->ctx, (uintptr_t)zend_jit_stub_handlers[id]); |
628 | 0 | insn = &jit->ctx.ir_base[ref]; |
629 | 0 | insn->optx = IR_OPT(IR_FUNC_ADDR, IR_ADDR); |
630 | | #if defined(IR_TARGET_X86) |
631 | | /* TODO: dummy prototype (only flags matter) ??? */ |
632 | | insn->proto = flags ? ir_proto_0(&jit->ctx, flags, IR_I32) : 0; |
633 | | #else |
634 | 0 | insn->proto = 0; |
635 | 0 | #endif |
636 | 0 | jit->stub_addr[id] = ref; |
637 | 0 | } |
638 | 0 | return ref; |
639 | 0 | } |
640 | | |
641 | | static void jit_SNAPSHOT(zend_jit_ctx *jit, ir_ref addr) |
642 | 0 | { |
643 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && JIT_G(current_frame)) { |
644 | 0 | const void *ptr = (const void*)jit->ctx.ir_base[addr].val.addr; |
645 | 0 | const zend_op_array *op_array = &JIT_G(current_frame)->func->op_array; |
646 | 0 | uint32_t stack_size = op_array->last_var + op_array->T; |
647 | |
|
648 | 0 | if (ptr == zend_jit_stub_handlers[jit_stub_exception_handler] |
649 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_exception_handler_undef] |
650 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_exception_handler_free_op1_op2] |
651 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_exception_handler_free_op2] |
652 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_interrupt_handler] |
653 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_leave_function_handler] |
654 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_negative_shift] |
655 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_mod_by_zero] |
656 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_invalid_this] |
657 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_undefined_function] |
658 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_throw_cannot_pass_by_ref] |
659 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_icall_throw] |
660 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_leave_throw] |
661 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_trace_halt] |
662 | 0 | || ptr == zend_jit_stub_handlers[jit_stub_trace_escape]) { |
663 | | /* This is a GUARD that trigger exit through a stub code (without deoptimization) */ |
664 | 0 | return; |
665 | 0 | } |
666 | | |
667 | | /* Check if we need snapshot entries for polymorphic method call */ |
668 | 0 | zend_jit_trace_info *t = jit->trace; |
669 | 0 | uint32_t exit_point = 0, n = 0; |
670 | |
|
671 | 0 | if (addr < 0) { |
672 | | /* addr is not always the address of the *last* exit point, |
673 | | * so we can not optimize this to 'exit_point = t->exit_count-1' */ |
674 | 0 | exit_point = zend_jit_exit_point_by_addr(ptr); |
675 | 0 | ZEND_ASSERT(exit_point != -1); |
676 | 0 | if (t->exit_info[exit_point].flags & ZEND_JIT_EXIT_METHOD_CALL) { |
677 | 0 | n = 2; |
678 | 0 | } |
679 | 0 | } |
680 | |
|
681 | 0 | if (stack_size || n) { |
682 | 0 | zend_jit_trace_stack *stack = JIT_G(current_frame)->stack; |
683 | 0 | uint32_t snapshot_size, i; |
684 | |
|
685 | 0 | snapshot_size = stack_size; |
686 | 0 | while (snapshot_size > 0) { |
687 | 0 | ir_ref ref = STACK_REF(stack, snapshot_size - 1); |
688 | |
|
689 | 0 | if (!ref || ref == IR_NULL || (STACK_FLAGS(stack, snapshot_size - 1) & (/*ZREG_LOAD|*/ZREG_STORE))) { |
690 | 0 | snapshot_size--; |
691 | 0 | } else { |
692 | 0 | break; |
693 | 0 | } |
694 | 0 | } |
695 | 0 | if (snapshot_size || n) { |
696 | 0 | ir_ref snapshot; |
697 | |
|
698 | 0 | snapshot = ir_SNAPSHOT(snapshot_size + n); |
699 | 0 | for (i = 0; i < snapshot_size; i++) { |
700 | 0 | ir_ref ref = STACK_REF(stack, i); |
701 | |
|
702 | 0 | if (!ref || ref == IR_NULL || (STACK_FLAGS(stack, i) & (/*ZREG_LOAD|*/ZREG_STORE))) { |
703 | 0 | ref = IR_UNUSED; |
704 | 0 | } |
705 | 0 | ir_SNAPSHOT_SET_OP(snapshot, i + 1, ref); |
706 | 0 | } |
707 | 0 | if (n) { |
708 | 0 | ir_SNAPSHOT_SET_OP(snapshot, snapshot_size + 1, t->exit_info[exit_point].poly_func.ref); |
709 | 0 | ir_SNAPSHOT_SET_OP(snapshot, snapshot_size + 2, t->exit_info[exit_point].poly_this.ref); |
710 | 0 | } |
711 | 0 | } |
712 | 0 | } |
713 | 0 | } |
714 | 0 | } |
715 | | |
716 | | static int32_t _add_trace_const(zend_jit_trace_info *t, int64_t val) |
717 | 0 | { |
718 | 0 | int32_t i; |
719 | |
|
720 | 0 | for (i = 0; i < t->consts_count; i++) { |
721 | 0 | if (t->constants[i].i == val) { |
722 | 0 | return i; |
723 | 0 | } |
724 | 0 | } |
725 | 0 | ZEND_ASSERT(i < 0x7fffffff); |
726 | 0 | t->consts_count = i + 1; |
727 | 0 | t->constants = erealloc(t->constants, (i + 1) * sizeof(zend_jit_exit_const)); |
728 | 0 | t->constants[i].i = val; |
729 | 0 | return i; |
730 | 0 | } |
731 | | |
732 | | uint32_t zend_jit_duplicate_exit_point(ir_ctx *ctx, zend_jit_trace_info *t, uint32_t exit_point, ir_ref snapshot_ref) |
733 | 0 | { |
734 | 0 | uint32_t stack_size, stack_offset; |
735 | 0 | uint32_t new_exit_point = t->exit_count; |
736 | |
|
737 | 0 | if (new_exit_point >= ZEND_JIT_TRACE_MAX_EXITS) { |
738 | 0 | ctx->status = -ZEND_JIT_TRACE_STOP_TOO_MANY_EXITS; |
739 | 0 | return exit_point; |
740 | 0 | } |
741 | | |
742 | 0 | t->exit_count++; |
743 | 0 | memcpy(&t->exit_info[new_exit_point], &t->exit_info[exit_point], sizeof(zend_jit_trace_exit_info)); |
744 | 0 | stack_size = t->exit_info[new_exit_point].stack_size; |
745 | 0 | if (stack_size != 0) { |
746 | 0 | stack_offset = t->stack_map_size; |
747 | 0 | t->stack_map_size += stack_size; |
748 | | // TODO: reduce number of reallocations ??? |
749 | 0 | t->stack_map = erealloc(t->stack_map, t->stack_map_size * sizeof(zend_jit_trace_stack)); |
750 | 0 | memcpy(t->stack_map + stack_offset, t->stack_map + t->exit_info[new_exit_point].stack_offset, stack_size * sizeof(zend_jit_trace_stack)); |
751 | 0 | t->exit_info[new_exit_point].stack_offset = stack_offset; |
752 | 0 | } |
753 | 0 | t->exit_info[new_exit_point].flags &= ~ZEND_JIT_EXIT_FIXED; |
754 | |
|
755 | 0 | return new_exit_point; |
756 | 0 | } |
757 | | |
758 | | static void zend_jit_resolve_ref_snapshot(zend_jit_ref_snapshot *dest, ir_ctx *ctx, ir_ref snapshot_ref, ir_insn *snapshot, int op) |
759 | 0 | { |
760 | 0 | int8_t *reg_ops = ctx->regs[snapshot_ref]; |
761 | 0 | ZEND_ASSERT(reg_ops[op] != ZREG_NONE); |
762 | |
|
763 | 0 | int8_t reg = reg_ops[op]; |
764 | 0 | int32_t offset; |
765 | |
|
766 | 0 | if (IR_REG_SPILLED(reg)) { |
767 | 0 | reg = ((ctx->flags & IR_USE_FRAME_POINTER) ? IR_REG_FP : IR_REG_SP) | IR_REG_SPILL_LOAD; |
768 | 0 | offset = ir_get_spill_slot_offset(ctx, ir_insn_op(snapshot, op)); |
769 | 0 | } else { |
770 | 0 | offset = 0; |
771 | 0 | } |
772 | |
|
773 | 0 | dest->reg = reg; |
774 | 0 | dest->offset = offset; |
775 | 0 | } |
776 | | |
777 | | static bool zend_jit_ref_snapshot_equals(const zend_jit_ref_snapshot *a, const zend_jit_ref_snapshot *b) |
778 | 0 | { |
779 | 0 | return a->reg == b->reg |
780 | 0 | && (!IR_REG_SPILLED(a->reg) || (a->offset == b->offset)); |
781 | 0 | } |
782 | | |
783 | | void *zend_jit_snapshot_handler(ir_ctx *ctx, ir_ref snapshot_ref, ir_insn *snapshot, void *addr) |
784 | 0 | { |
785 | 0 | zend_jit_trace_info *t = ((zend_jit_ctx*)ctx)->trace; |
786 | 0 | uint32_t exit_point, exit_flags; |
787 | 0 | ir_ref n = snapshot->inputs_count; |
788 | 0 | ir_ref i; |
789 | |
|
790 | 0 | exit_point = zend_jit_exit_point_by_addr(addr); |
791 | 0 | ZEND_ASSERT(exit_point < t->exit_count); |
792 | 0 | exit_flags = t->exit_info[exit_point].flags; |
793 | |
|
794 | 0 | if (exit_flags & ZEND_JIT_EXIT_METHOD_CALL) { |
795 | 0 | zend_jit_ref_snapshot func, this; |
796 | 0 | zend_jit_resolve_ref_snapshot(&func, ctx, snapshot_ref, snapshot, n - 1); |
797 | 0 | zend_jit_resolve_ref_snapshot(&this, ctx, snapshot_ref, snapshot, n); |
798 | |
|
799 | 0 | if ((exit_flags & ZEND_JIT_EXIT_FIXED) |
800 | 0 | && (!zend_jit_ref_snapshot_equals(&t->exit_info[exit_point].poly_func, &func) |
801 | 0 | || !zend_jit_ref_snapshot_equals(&t->exit_info[exit_point].poly_this, &this))) { |
802 | 0 | exit_point = zend_jit_duplicate_exit_point(ctx, t, exit_point, snapshot_ref); |
803 | 0 | addr = (void*)zend_jit_trace_get_exit_addr(exit_point); |
804 | 0 | exit_flags &= ~ZEND_JIT_EXIT_FIXED; |
805 | 0 | } |
806 | 0 | t->exit_info[exit_point].poly_func = func; |
807 | 0 | t->exit_info[exit_point].poly_this = this; |
808 | 0 | n -= 2; |
809 | 0 | } |
810 | |
|
811 | 0 | for (i = 2; i <= n; i++) { |
812 | 0 | ir_ref ref = ir_insn_op(snapshot, i); |
813 | |
|
814 | 0 | if (ref) { |
815 | 0 | int8_t *reg_ops = ctx->regs[snapshot_ref]; |
816 | 0 | int8_t reg = reg_ops[i]; |
817 | 0 | ir_ref var = i - 2; |
818 | |
|
819 | 0 | ZEND_ASSERT(var < t->exit_info[exit_point].stack_size); |
820 | 0 | if (t->stack_map[t->exit_info[exit_point].stack_offset + var].flags == ZREG_ZVAL_COPY) { |
821 | 0 | ZEND_ASSERT(reg != ZREG_NONE); |
822 | 0 | if ((exit_flags & ZEND_JIT_EXIT_FIXED) |
823 | 0 | && t->stack_map[t->exit_info[exit_point].stack_offset + var].reg != IR_REG_NUM(reg)) { |
824 | 0 | exit_point = zend_jit_duplicate_exit_point(ctx, t, exit_point, snapshot_ref); |
825 | 0 | addr = (void*)zend_jit_trace_get_exit_addr(exit_point); |
826 | 0 | exit_flags &= ~ZEND_JIT_EXIT_FIXED; |
827 | 0 | } |
828 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].reg = IR_REG_NUM(reg); |
829 | 0 | } else if (t->stack_map[t->exit_info[exit_point].stack_offset + var].flags != ZREG_CONST) { |
830 | 0 | ZEND_ASSERT(t->stack_map[t->exit_info[exit_point].stack_offset + var].type == IS_LONG || |
831 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].type == IS_DOUBLE); |
832 | |
|
833 | 0 | if (ref > 0) { |
834 | 0 | if (reg != ZREG_NONE) { |
835 | 0 | if (reg & IR_REG_SPILL_LOAD) { |
836 | 0 | ZEND_ASSERT(!(reg & IR_REG_SPILL_SPECIAL)); |
837 | | /* spill slot on a CPU stack */ |
838 | 0 | if ((exit_flags & ZEND_JIT_EXIT_FIXED) |
839 | 0 | && (t->stack_map[t->exit_info[exit_point].stack_offset + var].ref != ref |
840 | 0 | || t->stack_map[t->exit_info[exit_point].stack_offset + var].reg != ZREG_NONE |
841 | 0 | || !(t->stack_map[t->exit_info[exit_point].stack_offset + var].flags & ZREG_SPILL_SLOT))) { |
842 | 0 | exit_point = zend_jit_duplicate_exit_point(ctx, t, exit_point, snapshot_ref); |
843 | 0 | addr = (void*)zend_jit_trace_get_exit_addr(exit_point); |
844 | 0 | exit_flags &= ~ZEND_JIT_EXIT_FIXED; |
845 | 0 | } |
846 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].ref = ref; |
847 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].reg = ZREG_NONE; |
848 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].flags |= ZREG_SPILL_SLOT; |
849 | 0 | } else if (reg & IR_REG_SPILL_SPECIAL) { |
850 | | /* spill slot on a VM stack */ |
851 | 0 | if ((exit_flags & ZEND_JIT_EXIT_FIXED) |
852 | 0 | && (t->stack_map[t->exit_info[exit_point].stack_offset + var].reg != ZREG_NONE |
853 | 0 | || t->stack_map[t->exit_info[exit_point].stack_offset + var].flags != ZREG_TYPE_ONLY)) { |
854 | 0 | exit_point = zend_jit_duplicate_exit_point(ctx, t, exit_point, snapshot_ref); |
855 | 0 | addr = (void*)zend_jit_trace_get_exit_addr(exit_point); |
856 | 0 | exit_flags &= ~ZEND_JIT_EXIT_FIXED; |
857 | 0 | } |
858 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].reg = ZREG_NONE; |
859 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].flags = ZREG_TYPE_ONLY; |
860 | 0 | } else { |
861 | 0 | if ((exit_flags & ZEND_JIT_EXIT_FIXED) |
862 | 0 | && t->stack_map[t->exit_info[exit_point].stack_offset + var].reg != IR_REG_NUM(reg)) { |
863 | 0 | exit_point = zend_jit_duplicate_exit_point(ctx, t, exit_point, snapshot_ref); |
864 | 0 | addr = (void*)zend_jit_trace_get_exit_addr(exit_point); |
865 | 0 | exit_flags &= ~ZEND_JIT_EXIT_FIXED; |
866 | 0 | } |
867 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].reg = IR_REG_NUM(reg); |
868 | 0 | } |
869 | 0 | } else { |
870 | 0 | if ((exit_flags & ZEND_JIT_EXIT_FIXED) |
871 | 0 | && (t->stack_map[t->exit_info[exit_point].stack_offset + var].reg != ZREG_NONE |
872 | 0 | || t->stack_map[t->exit_info[exit_point].stack_offset + var].flags != ZREG_TYPE_ONLY)) { |
873 | 0 | exit_point = zend_jit_duplicate_exit_point(ctx, t, exit_point, snapshot_ref); |
874 | 0 | addr = (void*)zend_jit_trace_get_exit_addr(exit_point); |
875 | 0 | exit_flags &= ~ZEND_JIT_EXIT_FIXED; |
876 | 0 | } |
877 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].reg = ZREG_NONE; |
878 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].flags = ZREG_TYPE_ONLY; |
879 | 0 | } |
880 | 0 | } else if (!(exit_flags & ZEND_JIT_EXIT_FIXED)) { |
881 | 0 | int32_t idx = _add_trace_const(t, ctx->ir_base[ref].val.i64); |
882 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].flags = ZREG_CONST; |
883 | 0 | t->stack_map[t->exit_info[exit_point].stack_offset + var].ref = idx; |
884 | 0 | } |
885 | 0 | } |
886 | 0 | } |
887 | 0 | } |
888 | 0 | t->exit_info[exit_point].flags |= ZEND_JIT_EXIT_FIXED; |
889 | 0 | return addr; |
890 | 0 | } |
891 | | |
892 | | static void jit_SIDE_EXIT(zend_jit_ctx *jit, ir_ref addr) |
893 | 0 | { |
894 | 0 | jit_SNAPSHOT(jit, addr); |
895 | 0 | ir_IJMP(addr); |
896 | 0 | } |
897 | | |
898 | | /* PHP JIT helpers */ |
899 | | |
900 | | static ir_ref jit_EMALLOC(zend_jit_ctx *jit, size_t size, const zend_op_array *op_array, const zend_op *opline) |
901 | 0 | { |
902 | 0 | #if ZEND_DEBUG |
903 | 0 | return ir_CALL_5(IR_ADDR, ir_CONST_FC_FUNC(_emalloc), |
904 | 0 | ir_CONST_ADDR(size), |
905 | 0 | op_array->filename ? ir_CONST_ADDR(op_array->filename->val) : IR_NULL, |
906 | 0 | ir_CONST_U32(opline ? opline->lineno : 0), |
907 | 0 | IR_NULL, |
908 | 0 | ir_CONST_U32(0)); |
909 | | #elif defined(HAVE_BUILTIN_CONSTANT_P) |
910 | | if (size > 24 && size <= 32) { |
911 | | return ir_CALL(IR_ADDR, ir_CONST_FC_FUNC(_emalloc_32)); |
912 | | } else { |
913 | | return ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(_emalloc), ir_CONST_ADDR(size)); |
914 | | } |
915 | | #else |
916 | | return ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(_emalloc), ir_CONST_ADDR(size)); |
917 | | #endif |
918 | 0 | } |
919 | | |
920 | | static ir_ref jit_EFREE(zend_jit_ctx *jit, ir_ref ptr, size_t size, const zend_op_array *op_array, const zend_op *opline) |
921 | 0 | { |
922 | 0 | #if ZEND_DEBUG |
923 | 0 | return ir_CALL_5(IR_ADDR, ir_CONST_FC_FUNC(_efree), |
924 | 0 | ptr, |
925 | 0 | op_array && op_array->filename ? ir_CONST_ADDR(op_array->filename->val) : IR_NULL, |
926 | 0 | ir_CONST_U32(opline ? opline->lineno : 0), |
927 | 0 | IR_NULL, |
928 | 0 | ir_CONST_U32(0)); |
929 | | #elif defined(HAVE_BUILTIN_CONSTANT_P) |
930 | | if (size > 24 && size <= 32) { |
931 | | return ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(_efree_32), ptr); |
932 | | } else { |
933 | | return ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(_efree), ptr); |
934 | | } |
935 | | #else |
936 | | return ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(_efree), ptr); |
937 | | #endif |
938 | 0 | } |
939 | | |
940 | | static ir_ref jit_FP(zend_jit_ctx *jit) |
941 | 0 | { |
942 | 0 | ZEND_ASSERT(jit->ctx.control); |
943 | 0 | if (jit->fp == IR_UNUSED) { |
944 | | /* Emit "RLOAD FP" once for basic block */ |
945 | 0 | jit->fp = ir_RLOAD_A(ZREG_FP); |
946 | 0 | } else { |
947 | 0 | ir_insn *insn; |
948 | 0 | ir_ref ref = jit->ctx.control; |
949 | |
|
950 | 0 | while (1) { |
951 | 0 | if (ref == jit->fp) { |
952 | 0 | break; |
953 | 0 | } |
954 | 0 | insn = &jit->ctx.ir_base[ref]; |
955 | 0 | if (insn->op >= IR_START || insn->op == IR_CALL) { |
956 | 0 | jit->fp = ir_RLOAD_A(ZREG_FP); |
957 | 0 | break; |
958 | 0 | } |
959 | 0 | ref = insn->op1; |
960 | 0 | } |
961 | 0 | } |
962 | 0 | return jit->fp; |
963 | 0 | } |
964 | | |
965 | | static void jit_STORE_FP(zend_jit_ctx *jit, ir_ref ref) |
966 | 0 | { |
967 | 0 | ir_RSTORE(ZREG_FP, ref); |
968 | 0 | jit->fp = IR_UNUSED; |
969 | 0 | } |
970 | | |
971 | | static ir_ref jit_IP(zend_jit_ctx *jit) |
972 | 0 | { |
973 | 0 | return ir_RLOAD_A(ZREG_IP); |
974 | 0 | } |
975 | | |
976 | | static void jit_STORE_IP(zend_jit_ctx *jit, ir_ref ref) |
977 | 0 | { |
978 | 0 | ir_RSTORE(ZREG_IP, ref); |
979 | 0 | } |
980 | | |
981 | | static ir_ref jit_IP32(zend_jit_ctx *jit) |
982 | 0 | { |
983 | 0 | return ir_RLOAD_U32(ZREG_IP); |
984 | 0 | } |
985 | | |
986 | | static void jit_LOAD_IP_ADDR(zend_jit_ctx *jit, const zend_op *target) |
987 | 0 | { |
988 | 0 | jit_STORE_IP(jit, ir_CONST_ADDR(target)); |
989 | 0 | } |
990 | | |
991 | | static void zend_jit_track_last_valid_opline(zend_jit_ctx *jit) |
992 | 0 | { |
993 | 0 | jit->use_last_valid_opline = false; |
994 | 0 | jit->track_last_valid_opline = true; |
995 | 0 | } |
996 | | |
997 | | static void zend_jit_use_last_valid_opline(zend_jit_ctx *jit) |
998 | 0 | { |
999 | 0 | if (jit->track_last_valid_opline) { |
1000 | 0 | jit->use_last_valid_opline = true; |
1001 | 0 | jit->track_last_valid_opline = false; |
1002 | 0 | } |
1003 | 0 | } |
1004 | | |
1005 | | static bool zend_jit_trace_uses_initial_ip(zend_jit_ctx *jit) |
1006 | 0 | { |
1007 | 0 | return jit->use_last_valid_opline; |
1008 | 0 | } |
1009 | | |
1010 | | static void zend_jit_set_last_valid_opline(zend_jit_ctx *jit, const zend_op *opline) |
1011 | 0 | { |
1012 | 0 | if (!jit->reuse_ip) { |
1013 | 0 | jit->track_last_valid_opline = true; |
1014 | 0 | jit->last_valid_opline = opline; |
1015 | 0 | } |
1016 | 0 | } |
1017 | | |
1018 | | static void zend_jit_reset_last_valid_opline(zend_jit_ctx *jit) |
1019 | 0 | { |
1020 | 0 | jit->track_last_valid_opline = false; |
1021 | 0 | jit->last_valid_opline = NULL; |
1022 | 0 | } |
1023 | | |
1024 | | static void zend_jit_start_reuse_ip(zend_jit_ctx *jit) |
1025 | 0 | { |
1026 | 0 | zend_jit_reset_last_valid_opline(jit); |
1027 | 0 | jit->reuse_ip = true; |
1028 | 0 | } |
1029 | | |
1030 | | static int zend_jit_reuse_ip(zend_jit_ctx *jit) |
1031 | 0 | { |
1032 | 0 | if (!jit->reuse_ip) { |
1033 | 0 | zend_jit_start_reuse_ip(jit); |
1034 | | // RX = EX(call); |
1035 | 0 | jit_STORE_IP(jit, ir_LOAD_A(jit_EX(call))); |
1036 | 0 | } |
1037 | 0 | return 1; |
1038 | 0 | } |
1039 | | |
1040 | | static void zend_jit_stop_reuse_ip(zend_jit_ctx *jit) |
1041 | 0 | { |
1042 | 0 | jit->reuse_ip = false; |
1043 | 0 | } |
1044 | | |
1045 | | static int zend_jit_save_call_chain(zend_jit_ctx *jit, uint32_t call_level) |
1046 | 0 | { |
1047 | 0 | ir_ref rx, call; |
1048 | |
|
1049 | 0 | if (call_level == 1) { |
1050 | | // JIT: call = NULL; |
1051 | 0 | call = IR_NULL; |
1052 | 0 | } else { |
1053 | | // JIT: call = EX(call); |
1054 | 0 | call = ir_LOAD_A(jit_EX(call)); |
1055 | 0 | } |
1056 | |
|
1057 | 0 | rx = jit_IP(jit); |
1058 | | |
1059 | | // JIT: call->prev_execute_data = call; |
1060 | 0 | ir_STORE(jit_CALL(rx, prev_execute_data), call); |
1061 | | |
1062 | | // JIT: EX(call) = call; |
1063 | 0 | ir_STORE(jit_EX(call), rx); |
1064 | |
|
1065 | 0 | jit->delayed_call_level = 0; |
1066 | 0 | delayed_call_chain = false; |
1067 | |
|
1068 | 0 | return 1; |
1069 | 0 | } |
1070 | | |
1071 | | static int zend_jit_set_ip(zend_jit_ctx *jit, const zend_op *target) |
1072 | 0 | { |
1073 | 0 | ir_ref ref; |
1074 | |
|
1075 | 0 | if (jit->delayed_call_level) { |
1076 | 0 | if (!zend_jit_save_call_chain(jit, jit->delayed_call_level)) { |
1077 | 0 | return 0; |
1078 | 0 | } |
1079 | 0 | } |
1080 | | |
1081 | 0 | if (jit->last_valid_opline) { |
1082 | 0 | zend_jit_use_last_valid_opline(jit); |
1083 | 0 | if (jit->last_valid_opline != target) { |
1084 | 0 | ref = jit_IP(jit); |
1085 | 0 | if (target > jit->last_valid_opline) { |
1086 | 0 | ref = ir_ADD_OFFSET(ref, (uintptr_t)target - (uintptr_t)jit->last_valid_opline); |
1087 | 0 | } else { |
1088 | 0 | ref = ir_SUB_A(ref, ir_CONST_ADDR((uintptr_t)jit->last_valid_opline - (uintptr_t)target)); |
1089 | 0 | } |
1090 | 0 | jit_STORE_IP(jit, ref); |
1091 | 0 | } |
1092 | 0 | } else { |
1093 | 0 | jit_STORE_IP(jit, ir_CONST_ADDR(target)); |
1094 | 0 | } |
1095 | 0 | jit->reuse_ip = false; |
1096 | 0 | zend_jit_set_last_valid_opline(jit, target); |
1097 | 0 | return 1; |
1098 | 0 | } |
1099 | | |
1100 | | static void jit_SET_EX_OPLINE(zend_jit_ctx *jit, const zend_op *target) |
1101 | 0 | { |
1102 | 0 | if (jit->last_valid_opline == target) { |
1103 | 0 | zend_jit_use_last_valid_opline(jit); |
1104 | | // EX(opline) = opline |
1105 | 0 | ir_STORE(jit_EX(opline), jit_IP(jit)); |
1106 | 0 | } else { |
1107 | 0 | ir_STORE(jit_EX(opline), ir_CONST_ADDR(target)); |
1108 | 0 | } |
1109 | 0 | } |
1110 | | |
1111 | | static ir_ref jit_ZVAL_ADDR(zend_jit_ctx *jit, zend_jit_addr addr) |
1112 | 0 | { |
1113 | 0 | if (Z_MODE(addr) == IS_MEM_ZVAL) { |
1114 | 0 | ir_ref reg; |
1115 | |
|
1116 | 0 | if (Z_REG(addr) == ZREG_FP) { |
1117 | 0 | reg = jit_FP(jit); |
1118 | 0 | } else if (Z_REG(addr) == ZREG_RX) { |
1119 | 0 | reg = jit_IP(jit); |
1120 | 0 | } else { |
1121 | 0 | ZEND_UNREACHABLE(); |
1122 | 0 | } |
1123 | 0 | return ir_ADD_OFFSET(reg, Z_OFFSET(addr)); |
1124 | 0 | } else if (Z_MODE(addr) == IS_REF_ZVAL) { |
1125 | 0 | return Z_IR_REF(addr); |
1126 | 0 | } else { |
1127 | 0 | ZEND_ASSERT(Z_MODE(addr) == IS_CONST_ZVAL); |
1128 | 0 | return ir_CONST_ADDR(Z_ZV(addr)); |
1129 | 0 | } |
1130 | 0 | } |
1131 | | |
1132 | | static ir_ref jit_Z_TYPE_ref(zend_jit_ctx *jit, ir_ref ref) |
1133 | 0 | { |
1134 | 0 | return ir_LOAD_U8(ir_ADD_OFFSET(ref, offsetof(zval, u1.v.type))); |
1135 | 0 | } |
1136 | | |
1137 | | static ir_ref jit_Z_TYPE(zend_jit_ctx *jit, zend_jit_addr addr) |
1138 | 0 | { |
1139 | 0 | if (Z_MODE(addr) == IS_CONST_ZVAL) { |
1140 | 0 | return ir_CONST_U8(Z_TYPE_P(Z_ZV(addr))); |
1141 | 0 | } else if (Z_MODE(addr) == IS_MEM_ZVAL) { |
1142 | 0 | ir_ref reg; |
1143 | |
|
1144 | 0 | ZEND_ASSERT(Z_MODE(addr) == IS_MEM_ZVAL); |
1145 | 0 | if (Z_REG(addr) == ZREG_FP) { |
1146 | 0 | reg = jit_FP(jit); |
1147 | 0 | } else if (Z_REG(addr) == ZREG_RX) { |
1148 | 0 | reg = jit_IP(jit); |
1149 | 0 | } else { |
1150 | 0 | ZEND_UNREACHABLE(); |
1151 | 0 | } |
1152 | 0 | return ir_LOAD_U8(ir_ADD_OFFSET(reg, Z_OFFSET(addr) + offsetof(zval, u1.v.type))); |
1153 | 0 | } else { |
1154 | 0 | return jit_Z_TYPE_ref(jit, jit_ZVAL_ADDR(jit, addr)); |
1155 | 0 | } |
1156 | 0 | } |
1157 | | |
1158 | | static ir_ref jit_Z_TYPE_FLAGS_ref(zend_jit_ctx *jit, ir_ref ref) |
1159 | 0 | { |
1160 | 0 | return ir_LOAD_U8(ir_ADD_OFFSET(ref, offsetof(zval, u1.v.type_flags))); |
1161 | 0 | } |
1162 | | |
1163 | | static ir_ref jit_Z_TYPE_FLAGS(zend_jit_ctx *jit, zend_jit_addr addr) |
1164 | 0 | { |
1165 | 0 | if (Z_MODE(addr) == IS_CONST_ZVAL) { |
1166 | 0 | return ir_CONST_U8(Z_TYPE_FLAGS_P(Z_ZV(addr))); |
1167 | 0 | } else if (Z_MODE(addr) == IS_MEM_ZVAL) { |
1168 | 0 | ir_ref reg; |
1169 | |
|
1170 | 0 | ZEND_ASSERT(Z_MODE(addr) == IS_MEM_ZVAL); |
1171 | 0 | if (Z_REG(addr) == ZREG_FP) { |
1172 | 0 | reg = jit_FP(jit); |
1173 | 0 | } else if (Z_REG(addr) == ZREG_RX) { |
1174 | 0 | reg = jit_IP(jit); |
1175 | 0 | } else { |
1176 | 0 | ZEND_UNREACHABLE(); |
1177 | 0 | } |
1178 | 0 | return ir_LOAD_U8(ir_ADD_OFFSET(reg, Z_OFFSET(addr) + offsetof(zval, u1.v.type_flags))); |
1179 | 0 | } else { |
1180 | 0 | return jit_Z_TYPE_FLAGS_ref(jit, jit_ZVAL_ADDR(jit, addr)); |
1181 | 0 | } |
1182 | 0 | } |
1183 | | |
1184 | | static ir_ref jit_Z_TYPE_INFO_ref(zend_jit_ctx *jit, ir_ref ref) |
1185 | 0 | { |
1186 | 0 | return ir_LOAD_U32(ir_ADD_OFFSET(ref, offsetof(zval, u1.type_info))); |
1187 | 0 | } |
1188 | | |
1189 | | static ir_ref jit_Z_TYPE_INFO(zend_jit_ctx *jit, zend_jit_addr addr) |
1190 | 0 | { |
1191 | 0 | if (Z_MODE(addr) == IS_CONST_ZVAL) { |
1192 | 0 | return ir_CONST_U32(Z_TYPE_INFO_P(Z_ZV(addr))); |
1193 | 0 | } else if (Z_MODE(addr) == IS_MEM_ZVAL) { |
1194 | 0 | ir_ref reg; |
1195 | |
|
1196 | 0 | ZEND_ASSERT(Z_MODE(addr) == IS_MEM_ZVAL); |
1197 | 0 | if (Z_REG(addr) == ZREG_FP) { |
1198 | 0 | reg = jit_FP(jit); |
1199 | 0 | } else if (Z_REG(addr) == ZREG_RX) { |
1200 | 0 | reg = jit_IP(jit); |
1201 | 0 | } else { |
1202 | 0 | ZEND_UNREACHABLE(); |
1203 | 0 | } |
1204 | 0 | return ir_LOAD_U32(ir_ADD_OFFSET(reg, Z_OFFSET(addr) + offsetof(zval, u1.type_info))); |
1205 | 0 | } else { |
1206 | 0 | return jit_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, addr)); |
1207 | 0 | } |
1208 | 0 | } |
1209 | | |
1210 | | static void jit_set_Z_TYPE_INFO_ref(zend_jit_ctx *jit, ir_ref ref, ir_ref type_info) |
1211 | 0 | { |
1212 | 0 | ir_STORE(ir_ADD_OFFSET(ref, offsetof(zval, u1.type_info)), type_info); |
1213 | 0 | } |
1214 | | |
1215 | | static void jit_set_Z_TYPE_INFO_ex(zend_jit_ctx *jit, zend_jit_addr addr, ir_ref type_info) |
1216 | 0 | { |
1217 | 0 | if (Z_MODE(addr) == IS_MEM_ZVAL) { |
1218 | 0 | ir_ref reg; |
1219 | |
|
1220 | 0 | ZEND_ASSERT(Z_MODE(addr) == IS_MEM_ZVAL); |
1221 | 0 | if (Z_REG(addr) == ZREG_FP) { |
1222 | 0 | reg = jit_FP(jit); |
1223 | 0 | } else if (Z_REG(addr) == ZREG_RX) { |
1224 | 0 | reg = jit_IP(jit); |
1225 | 0 | } else { |
1226 | 0 | ZEND_UNREACHABLE(); |
1227 | 0 | } |
1228 | 0 | ir_STORE(ir_ADD_OFFSET(reg, Z_OFFSET(addr) + offsetof(zval, u1.type_info)), type_info); |
1229 | 0 | } else { |
1230 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, addr), type_info); |
1231 | 0 | } |
1232 | 0 | } |
1233 | | |
1234 | | static void jit_set_Z_TYPE_INFO(zend_jit_ctx *jit, zend_jit_addr addr, uint32_t type_info) |
1235 | 0 | { |
1236 | 0 | if (type_info < IS_STRING |
1237 | 0 | && Z_MODE(addr) == IS_MEM_ZVAL |
1238 | 0 | && Z_REG(addr) == ZREG_FP |
1239 | 0 | && JIT_G(current_frame) |
1240 | 0 | && STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(addr))) == type_info) { |
1241 | | /* type is already set */ |
1242 | 0 | return; |
1243 | 0 | } |
1244 | 0 | jit_set_Z_TYPE_INFO_ex(jit, addr, ir_CONST_U32(type_info)); |
1245 | 0 | } |
1246 | | |
1247 | | static ir_ref jit_if_Z_TYPE_ref(zend_jit_ctx *jit, ir_ref ref, ir_ref type) |
1248 | 0 | { |
1249 | 0 | return ir_IF(ir_EQ(jit_Z_TYPE_ref(jit, ref), type)); |
1250 | 0 | } |
1251 | | |
1252 | | static ir_ref jit_if_Z_TYPE(zend_jit_ctx *jit, zend_jit_addr addr, uint8_t type) |
1253 | 0 | { |
1254 | 0 | ZEND_ASSERT(type != IS_UNDEF); |
1255 | 0 | return ir_IF(ir_EQ(jit_Z_TYPE(jit, addr), ir_CONST_U8(type))); |
1256 | 0 | } |
1257 | | |
1258 | | static ir_ref jit_if_not_Z_TYPE(zend_jit_ctx *jit, zend_jit_addr addr, uint8_t type) |
1259 | 0 | { |
1260 | 0 | ir_ref ref = jit_Z_TYPE(jit, addr); |
1261 | |
|
1262 | 0 | if (type != IS_UNDEF) { |
1263 | 0 | ref = ir_NE(ref, ir_CONST_U8(type)); |
1264 | 0 | } |
1265 | 0 | return ir_IF(ref); |
1266 | 0 | } |
1267 | | |
1268 | | static void jit_guard_Z_TYPE(zend_jit_ctx *jit, zend_jit_addr addr, uint8_t type, const void *exit_addr) |
1269 | 0 | { |
1270 | 0 | ir_ref ref = jit_Z_TYPE(jit, addr); |
1271 | |
|
1272 | 0 | if (type != IS_UNDEF) { |
1273 | 0 | ir_GUARD(ir_EQ(ref, ir_CONST_U8(type)), ir_CONST_ADDR(exit_addr)); |
1274 | 0 | } else { |
1275 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
1276 | 0 | } |
1277 | 0 | } |
1278 | | |
1279 | | static void jit_guard_not_Z_TYPE(zend_jit_ctx *jit, zend_jit_addr addr, uint8_t type, const void *exit_addr) |
1280 | 0 | { |
1281 | 0 | ir_ref ref = jit_Z_TYPE(jit, addr); |
1282 | |
|
1283 | 0 | if (type != IS_UNDEF) { |
1284 | 0 | ref = ir_NE(ref, ir_CONST_U8(type)); |
1285 | 0 | } |
1286 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
1287 | 0 | } |
1288 | | |
1289 | | static ir_ref jit_if_REFCOUNTED(zend_jit_ctx *jit, zend_jit_addr addr) |
1290 | 0 | { |
1291 | 0 | return ir_IF(jit_Z_TYPE_FLAGS(jit, addr)); |
1292 | 0 | } |
1293 | | |
1294 | | static ir_ref jit_if_COLLECTABLE_ref(zend_jit_ctx *jit, ir_ref addr_ref) |
1295 | 0 | { |
1296 | 0 | return ir_IF(ir_AND_U8(jit_Z_TYPE_FLAGS_ref(jit, addr_ref), ir_CONST_U8(IS_TYPE_COLLECTABLE))); |
1297 | 0 | } |
1298 | | |
1299 | | static ir_ref jit_Z_LVAL_ref(zend_jit_ctx *jit, ir_ref ref) |
1300 | 0 | { |
1301 | 0 | return ir_LOAD_L(ref); |
1302 | 0 | } |
1303 | | |
1304 | | static ir_ref jit_Z_DVAL_ref(zend_jit_ctx *jit, ir_ref ref) |
1305 | 0 | { |
1306 | 0 | return ir_LOAD_D(ref); |
1307 | 0 | } |
1308 | | |
1309 | | static bool zend_jit_spilling_may_cause_conflict(zend_jit_ctx *jit, int var, ir_ref val) |
1310 | 0 | { |
1311 | 0 | if (jit->ctx.ir_base[val].op == IR_RLOAD) { |
1312 | | /* Deoptimization */ |
1313 | 0 | return false; |
1314 | 0 | } |
1315 | | // if (jit->ctx.ir_base[val].op == IR_LOAD |
1316 | | // && jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op == IR_ADD |
1317 | | // && jit->ctx.ir_base[jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op1].op == IR_RLOAD |
1318 | | // && jit->ctx.ir_base[jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op1].op2 == ZREG_FP |
1319 | | // && IR_IS_CONST_REF(jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op2) |
1320 | | // && jit->ctx.ir_base[jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op2].val.addr == (uintptr_t)EX_NUM_TO_VAR(jit->ssa->vars[var].var)) { |
1321 | | // /* LOAD from the same location (the LOAD is pinned) */ |
1322 | | // // TODO: should be anti-dependent with the following stores ??? |
1323 | | // return 0; |
1324 | | // } |
1325 | 0 | if (jit->ssa->vars[var].var < jit->current_op_array->last_var) { |
1326 | | /* IS_CV */ |
1327 | 0 | if (jit->ctx.ir_base[val].op == IR_LOAD |
1328 | 0 | && jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op == IR_ADD |
1329 | 0 | && jit->ctx.ir_base[jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op1].op == IR_RLOAD |
1330 | 0 | && jit->ctx.ir_base[jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op1].op2 == ZREG_FP |
1331 | 0 | && IR_IS_CONST_REF(jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op2) |
1332 | 0 | && jit->ctx.ir_base[jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op2].val.addr != (uintptr_t)EX_NUM_TO_VAR(jit->ssa->vars[var].var) |
1333 | 0 | && EX_VAR_TO_NUM(jit->ctx.ir_base[jit->ctx.ir_base[jit->ctx.ir_base[val].op2].op2].val.addr) < jit->current_op_array->last_var) { |
1334 | | /* binding between different CVs may cause spill conflict */ |
1335 | 0 | return true; |
1336 | 0 | } else if (jit->ssa->vars[var].definition >= 0 |
1337 | 0 | && jit->ssa->ops[jit->ssa->vars[var].definition].op1_def == var |
1338 | 0 | && jit->ssa->ops[jit->ssa->vars[var].definition].op1_use >= 0 |
1339 | 0 | && jit->ssa->vars[jit->ssa->ops[jit->ssa->vars[var].definition].op1_use].no_val |
1340 | 0 | && jit->ssa->vars[jit->ssa->ops[jit->ssa->vars[var].definition].op1_use].definition_phi |
1341 | 0 | && (jit->ssa->cfg.blocks[jit->ssa->vars[jit->ssa->ops[jit->ssa->vars[var].definition].op1_use].definition_phi->block].flags & ZEND_BB_LOOP_HEADER)) { |
1342 | | /* Avoid moving spill store out of loop */ |
1343 | 0 | return true; |
1344 | 0 | } else if (jit->ssa->vars[var].definition >= 0 |
1345 | 0 | && jit->ssa->ops[jit->ssa->vars[var].definition].op1_def == var |
1346 | 0 | && jit->ssa->ops[jit->ssa->vars[var].definition].op1_use >= 0 |
1347 | 0 | && jit->ssa->ops[jit->ssa->vars[var].definition].op2_use >= 0 |
1348 | 0 | && jit->ra[jit->ssa->ops[jit->ssa->vars[var].definition].op2_use].ref == val) { |
1349 | | /* Avoid spill conflict between of ASSIGN.op1_def and ASSIGN.op1_use */ |
1350 | 0 | return true; |
1351 | 0 | } |
1352 | 0 | return false; |
1353 | 0 | } |
1354 | 0 | return true; |
1355 | 0 | } |
1356 | | |
1357 | | static void zend_jit_def_reg(zend_jit_ctx *jit, zend_jit_addr addr, ir_ref val) |
1358 | 0 | { |
1359 | 0 | int var; |
1360 | |
|
1361 | 0 | ZEND_ASSERT(Z_MODE(addr) == IS_REG); |
1362 | 0 | var = Z_SSA_VAR(addr); |
1363 | 0 | if (var == jit->delay_var) { |
1364 | 0 | ir_refs_add(jit->delay_refs, val); |
1365 | 0 | return; |
1366 | 0 | } |
1367 | 0 | ZEND_ASSERT(jit->ra && jit->ra[var].ref == IR_NULL); |
1368 | | |
1369 | | /* Negative "var" has special meaning for IR */ |
1370 | 0 | if (val > 0) { |
1371 | 0 | if (jit->ctx.binding) { |
1372 | 0 | ir_ref old = ir_binding_find(&jit->ctx, val); |
1373 | 0 | if (old && old != -EX_NUM_TO_VAR(jit->ssa->vars[var].var)) { |
1374 | 0 | val = ir_emit2(&jit->ctx, IR_OPT(IR_COPY, jit->ctx.ir_base[val].type), val, 1); |
1375 | 0 | } |
1376 | 0 | } |
1377 | 0 | if (!zend_jit_spilling_may_cause_conflict(jit, var, val)) { |
1378 | 0 | val = ir_bind(&jit->ctx, -EX_NUM_TO_VAR(jit->ssa->vars[var].var), val); |
1379 | 0 | } |
1380 | 0 | } |
1381 | 0 | jit->ra[var].ref = val; |
1382 | |
|
1383 | 0 | if (jit->ra[var].flags & ZREG_FORWARD) { |
1384 | 0 | zend_ssa_phi *phi = jit->ssa->vars[var].phi_use_chain; |
1385 | 0 | zend_basic_block *bb; |
1386 | 0 | int n, j, *p; |
1387 | 0 | ir_ref *q; |
1388 | |
|
1389 | 0 | jit->ra[var].flags &= ~ZREG_FORWARD; |
1390 | 0 | while (phi != NULL) { |
1391 | 0 | zend_ssa_phi *dst_phi = phi; |
1392 | 0 | int src_var = var; |
1393 | |
|
1394 | 0 | if (dst_phi->pi >= 0) { |
1395 | 0 | jit->ra[src_var].ref = val; |
1396 | 0 | src_var = dst_phi->ssa_var; |
1397 | 0 | if (!(jit->ra[src_var].flags & ZREG_FORWARD)) { |
1398 | 0 | phi = zend_ssa_next_use_phi(jit->ssa, var, phi); |
1399 | 0 | continue; |
1400 | 0 | } |
1401 | 0 | dst_phi = jit->ssa->vars[src_var].phi_use_chain; |
1402 | 0 | ZEND_ASSERT(dst_phi != NULL && "reg forwarding"); |
1403 | 0 | ZEND_ASSERT(!zend_ssa_next_use_phi(jit->ssa, src_var, dst_phi) && "reg forwarding"); |
1404 | 0 | jit->ra[src_var].flags &= ~ZREG_FORWARD; |
1405 | 0 | } |
1406 | | |
1407 | 0 | if (jit->ra[dst_phi->ssa_var].ref > 0) { |
1408 | 0 | ir_insn *phi_insn = &jit->ctx.ir_base[jit->ra[dst_phi->ssa_var].ref]; |
1409 | 0 | if (phi_insn->op == IR_PHI) { |
1410 | | // ZEND_ASSERT(ir_operands_count(ctx, phi_insn) == n + 1); |
1411 | 0 | bb = &jit->ssa->cfg.blocks[dst_phi->block]; |
1412 | 0 | n = bb->predecessors_count; |
1413 | 0 | for (j = 0, p = &dst_phi->sources[0], q = phi_insn->ops + 2; j < n; j++, p++, q++) { |
1414 | 0 | if (*p == src_var) { |
1415 | 0 | *q = val; |
1416 | 0 | } |
1417 | 0 | } |
1418 | 0 | } |
1419 | 0 | } |
1420 | |
|
1421 | 0 | phi = zend_ssa_next_use_phi(jit->ssa, var, phi); |
1422 | 0 | } |
1423 | 0 | } |
1424 | 0 | } |
1425 | | |
1426 | | static ir_ref zend_jit_use_reg(zend_jit_ctx *jit, zend_jit_addr addr) |
1427 | 0 | { |
1428 | 0 | int var = Z_SSA_VAR(addr); |
1429 | |
|
1430 | 0 | ZEND_ASSERT(Z_MODE(addr) == IS_REG); |
1431 | 0 | ZEND_ASSERT(jit->ra && jit->ra[var].ref); |
1432 | 0 | if (jit->ra[var].ref == IR_NULL) { |
1433 | 0 | zend_jit_addr mem_addr; |
1434 | 0 | ir_ref ref; |
1435 | |
|
1436 | 0 | ZEND_ASSERT(jit->ra[var].flags & ZREG_LOAD); |
1437 | 0 | mem_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(jit->ssa->vars[var].var)); |
1438 | 0 | if ((jit->ssa->var_info[var].type & MAY_BE_ANY) == MAY_BE_LONG) { |
1439 | 0 | ref = jit_Z_LVAL_ref(jit, jit_ZVAL_ADDR(jit, mem_addr)); |
1440 | 0 | } else if ((jit->ssa->var_info[var].type & MAY_BE_ANY) == MAY_BE_DOUBLE) { |
1441 | 0 | ref = jit_Z_DVAL_ref(jit, jit_ZVAL_ADDR(jit, mem_addr)); |
1442 | 0 | } else { |
1443 | 0 | ZEND_UNREACHABLE(); |
1444 | 0 | } |
1445 | 0 | zend_jit_def_reg(jit, addr, ref); |
1446 | 0 | return ref; |
1447 | 0 | } |
1448 | 0 | return jit->ra[Z_SSA_VAR(addr)].ref; |
1449 | 0 | } |
1450 | | |
1451 | | static void zend_jit_gen_pi(zend_jit_ctx *jit, zend_ssa_phi *phi) |
1452 | 0 | { |
1453 | 0 | int src_var = phi->sources[0]; |
1454 | 0 | int dst_var = phi->ssa_var; |
1455 | |
|
1456 | 0 | ZEND_ASSERT(phi->pi >= 0); |
1457 | 0 | ZEND_ASSERT(!(jit->ra[dst_var].flags & ZREG_LOAD)); |
1458 | 0 | ZEND_ASSERT(jit->ra[src_var].ref); |
1459 | |
|
1460 | 0 | if (jit->ra[src_var].ref == IR_NULL) { |
1461 | | /* Not defined yet */ |
1462 | 0 | if (jit->ssa->vars[dst_var].use_chain < 0 |
1463 | 0 | && jit->ssa->vars[dst_var].phi_use_chain) { |
1464 | 0 | zend_ssa_phi *phi = jit->ssa->vars[dst_var].phi_use_chain; |
1465 | 0 | if (!zend_ssa_next_use_phi(jit->ssa, dst_var, phi)) { |
1466 | | /* This is a Pi forwarded to Phi */ |
1467 | 0 | jit->ra[src_var].flags |= ZREG_FORWARD; |
1468 | 0 | return; |
1469 | 0 | } |
1470 | 0 | } |
1471 | 0 | ZEND_ASSERT(0 && "Not defined Pi source"); |
1472 | 0 | } |
1473 | | /* Reuse register */ |
1474 | 0 | zend_jit_def_reg(jit, ZEND_ADDR_REG(dst_var), |
1475 | 0 | zend_jit_use_reg(jit, ZEND_ADDR_REG(src_var))); |
1476 | 0 | } |
1477 | | |
1478 | | static void zend_jit_gen_phi(zend_jit_ctx *jit, zend_ssa_phi *phi) |
1479 | 0 | { |
1480 | 0 | int dst_var = phi->ssa_var; |
1481 | 0 | zend_basic_block *bb = &jit->ssa->cfg.blocks[phi->block]; |
1482 | 0 | uint32_t n = bb->predecessors_count; |
1483 | 0 | ir_type type = (jit->ssa->var_info[phi->ssa_var].type & MAY_BE_LONG) ? IR_LONG : IR_DOUBLE; |
1484 | 0 | ir_ref merge = jit->bb_start_ref[phi->block]; |
1485 | 0 | ir_ref ref; |
1486 | 0 | ir_ref old_insns_count = jit->ctx.insns_count; |
1487 | 0 | ir_ref same_src_ref = IR_UNUSED; |
1488 | 0 | bool phi_inputs_are_the_same = true; |
1489 | |
|
1490 | 0 | ZEND_ASSERT(phi->pi < 0); |
1491 | 0 | ZEND_ASSERT(!(jit->ra[dst_var].flags & ZREG_LOAD)); |
1492 | 0 | ZEND_ASSERT(merge); |
1493 | 0 | ZEND_ASSERT(jit->ctx.ir_base[merge].op == IR_MERGE || jit->ctx.ir_base[merge].op == IR_LOOP_BEGIN); |
1494 | 0 | ZEND_ASSERT(n == jit->ctx.ir_base[merge].inputs_count); |
1495 | |
|
1496 | 0 | ref = ir_emit_N(&jit->ctx, IR_OPT(IR_PHI, type), n + 1); |
1497 | 0 | ir_set_op(&jit->ctx, ref, 1, merge); |
1498 | |
|
1499 | 0 | for (uint32_t i = 0; i < n; i++) { |
1500 | 0 | int src_var = phi->sources[i]; |
1501 | |
|
1502 | 0 | ZEND_ASSERT(jit->ra[src_var].ref); |
1503 | 0 | if (jit->ra[src_var].ref == IR_NULL) { |
1504 | 0 | jit->ra[src_var].flags |= ZREG_FORWARD; |
1505 | 0 | phi_inputs_are_the_same = false; |
1506 | 0 | } else { |
1507 | 0 | ir_ref src_ref = zend_jit_use_reg(jit, ZEND_ADDR_REG(src_var)); |
1508 | 0 | if (i == 0) { |
1509 | 0 | same_src_ref = src_ref; |
1510 | 0 | } else if (same_src_ref != src_ref) { |
1511 | 0 | phi_inputs_are_the_same = false; |
1512 | 0 | } |
1513 | 0 | ir_set_op(&jit->ctx, ref, i + 2, src_ref); |
1514 | 0 | } |
1515 | 0 | } |
1516 | 0 | if (phi_inputs_are_the_same) { |
1517 | 0 | ref = same_src_ref; |
1518 | 0 | jit->ctx.insns_count = old_insns_count; |
1519 | 0 | } |
1520 | |
|
1521 | 0 | zend_jit_def_reg(jit, ZEND_ADDR_REG(dst_var), ref); |
1522 | 0 | } |
1523 | | |
1524 | | static ir_ref jit_Z_LVAL(zend_jit_ctx *jit, zend_jit_addr addr) |
1525 | 0 | { |
1526 | 0 | if (Z_MODE(addr) == IS_CONST_ZVAL) { |
1527 | 0 | return ir_CONST_LONG(Z_LVAL_P(Z_ZV(addr))); |
1528 | 0 | } else if (Z_MODE(addr) == IS_REG) { |
1529 | 0 | return zend_jit_use_reg(jit, addr); |
1530 | 0 | } else { |
1531 | 0 | return jit_Z_LVAL_ref(jit, jit_ZVAL_ADDR(jit, addr)); |
1532 | 0 | } |
1533 | 0 | } |
1534 | | |
1535 | | static void jit_set_Z_LVAL(zend_jit_ctx *jit, zend_jit_addr addr, ir_ref lval) |
1536 | 0 | { |
1537 | 0 | if (Z_MODE(addr) == IS_REG) { |
1538 | 0 | zend_jit_def_reg(jit, addr, lval); |
1539 | 0 | } else { |
1540 | 0 | ir_STORE(jit_ZVAL_ADDR(jit, addr), lval); |
1541 | 0 | } |
1542 | 0 | } |
1543 | | |
1544 | | #if SIZEOF_ZEND_LONG == 4 |
1545 | | static ir_ref jit_Z_W2(zend_jit_ctx *jit, zend_jit_addr addr) |
1546 | | { |
1547 | | if (Z_MODE(addr) == IS_CONST_ZVAL) { |
1548 | | return ir_CONST_U32((Z_ZV(addr))->value.ww.w2); |
1549 | | } else { |
1550 | | return ir_LOAD_L(ir_ADD_OFFSET(jit_ZVAL_ADDR(jit, addr), offsetof(zval, value.ww.w2))); |
1551 | | } |
1552 | | } |
1553 | | |
1554 | | static void jit_set_Z_W2(zend_jit_ctx *jit, zend_jit_addr addr, ir_ref lval) |
1555 | | { |
1556 | | ir_STORE(ir_ADD_OFFSET(jit_ZVAL_ADDR(jit, addr), offsetof(zval, value.ww.w2)), lval); |
1557 | | } |
1558 | | #endif |
1559 | | |
1560 | | static ir_ref jit_Z_DVAL(zend_jit_ctx *jit, zend_jit_addr addr) |
1561 | 0 | { |
1562 | 0 | if (Z_MODE(addr) == IS_CONST_ZVAL) { |
1563 | 0 | return ir_CONST_DOUBLE(Z_DVAL_P(Z_ZV(addr))); |
1564 | 0 | } else if (Z_MODE(addr) == IS_REG) { |
1565 | 0 | return zend_jit_use_reg(jit, addr); |
1566 | 0 | } else { |
1567 | 0 | return jit_Z_DVAL_ref(jit, jit_ZVAL_ADDR(jit, addr)); |
1568 | 0 | } |
1569 | 0 | } |
1570 | | |
1571 | | static void jit_set_Z_DVAL(zend_jit_ctx *jit, zend_jit_addr addr, ir_ref dval) |
1572 | 0 | { |
1573 | 0 | if (Z_MODE(addr) == IS_REG) { |
1574 | 0 | zend_jit_def_reg(jit, addr, dval); |
1575 | 0 | } else { |
1576 | 0 | ir_STORE(jit_ZVAL_ADDR(jit, addr), dval); |
1577 | 0 | } |
1578 | 0 | } |
1579 | | |
1580 | | static ir_ref jit_Z_PTR_ref(zend_jit_ctx *jit, ir_ref ref) |
1581 | 0 | { |
1582 | 0 | return ir_LOAD_A(ref); |
1583 | 0 | } |
1584 | | |
1585 | | static ir_ref jit_Z_PTR(zend_jit_ctx *jit, zend_jit_addr addr) |
1586 | 0 | { |
1587 | 0 | if (Z_MODE(addr) == IS_CONST_ZVAL) { |
1588 | 0 | return ir_CONST_ADDR(Z_PTR_P(Z_ZV(addr))); |
1589 | 0 | } else { |
1590 | 0 | return jit_Z_PTR_ref(jit, jit_ZVAL_ADDR(jit, addr)); |
1591 | 0 | } |
1592 | 0 | } |
1593 | | |
1594 | | static void jit_set_Z_PTR(zend_jit_ctx *jit, zend_jit_addr addr, ir_ref ptr) |
1595 | 0 | { |
1596 | 0 | ir_STORE(jit_ZVAL_ADDR(jit, addr), ptr); |
1597 | 0 | } |
1598 | | |
1599 | | static ir_ref jit_GC_REFCOUNT(zend_jit_ctx *jit, ir_ref ref) |
1600 | 0 | { |
1601 | 0 | return ir_LOAD_U32(ref); |
1602 | 0 | } |
1603 | | |
1604 | | static void jit_set_GC_REFCOUNT(zend_jit_ctx *jit, ir_ref ref, uint32_t refcount) |
1605 | 0 | { |
1606 | 0 | ir_STORE(ref, ir_CONST_U32(refcount)); |
1607 | 0 | } |
1608 | | |
1609 | | static void jit_GC_ADDREF(zend_jit_ctx *jit, ir_ref ref) |
1610 | 0 | { |
1611 | 0 | ir_STORE(ref, ir_ADD_U32(ir_LOAD_U32(ref), ir_CONST_U32(1))); |
1612 | 0 | } |
1613 | | |
1614 | | static void jit_GC_ADDREF2(zend_jit_ctx *jit, ir_ref ref) |
1615 | 0 | { |
1616 | 0 | ir_ref counter = ir_LOAD_U32(ref); |
1617 | 0 | ir_STORE(ref, ir_ADD_U32(counter, ir_CONST_U32(2))); |
1618 | 0 | } |
1619 | | |
1620 | | static ir_ref jit_GC_DELREF(zend_jit_ctx *jit, ir_ref ref) |
1621 | 0 | { |
1622 | 0 | ir_ref counter = ir_LOAD_U32(ref); |
1623 | 0 | counter = ir_SUB_U32(counter, ir_CONST_U32(1)); |
1624 | 0 | ir_STORE(ref, counter); |
1625 | 0 | return counter; |
1626 | 0 | } |
1627 | | |
1628 | | static ir_ref jit_if_GC_MAY_NOT_LEAK(zend_jit_ctx *jit, ir_ref ref) |
1629 | 0 | { |
1630 | 0 | return ir_IF( |
1631 | 0 | ir_AND_U32( |
1632 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(ref, offsetof(zend_refcounted, gc.u.type_info))), |
1633 | 0 | ir_CONST_U32(GC_INFO_MASK | (GC_NOT_COLLECTABLE << GC_FLAGS_SHIFT)))); |
1634 | 0 | } |
1635 | | |
1636 | | static void jit_ZVAL_COPY_CONST(zend_jit_ctx *jit, zend_jit_addr dst, uint32_t dst_info, uint32_t dst_def_info, zval *zv, bool addref) |
1637 | 0 | { |
1638 | 0 | ir_ref ref = IR_UNUSED; |
1639 | |
|
1640 | 0 | if (Z_TYPE_P(zv) > IS_TRUE) { |
1641 | 0 | if (Z_TYPE_P(zv) == IS_DOUBLE) { |
1642 | 0 | jit_set_Z_DVAL(jit, dst, ir_CONST_DOUBLE(Z_DVAL_P(zv))); |
1643 | 0 | } else if (Z_TYPE_P(zv) == IS_LONG && dst_def_info == MAY_BE_DOUBLE) { |
1644 | 0 | jit_set_Z_DVAL(jit, dst, ir_CONST_DOUBLE((double)Z_LVAL_P(zv))); |
1645 | 0 | } else if (Z_TYPE_P(zv) == IS_LONG) { |
1646 | 0 | jit_set_Z_LVAL(jit, dst, ir_CONST_LONG(Z_LVAL_P(zv))); |
1647 | 0 | } else { |
1648 | 0 | ref = ir_CONST_ADDR(Z_PTR_P(zv)); |
1649 | 0 | jit_set_Z_PTR(jit, dst, ref); |
1650 | 0 | if (addref && Z_REFCOUNTED_P(zv)) { |
1651 | 0 | jit_GC_ADDREF(jit, ref); |
1652 | 0 | } |
1653 | 0 | } |
1654 | 0 | } |
1655 | 0 | if (Z_MODE(dst) != IS_REG) { |
1656 | 0 | if (dst_def_info == MAY_BE_DOUBLE) { |
1657 | 0 | if ((dst_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) != MAY_BE_DOUBLE) { |
1658 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_DOUBLE); |
1659 | 0 | } |
1660 | 0 | } else if (((dst_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) != (1<<Z_TYPE_P(zv))) || (dst_info & (MAY_BE_STRING|MAY_BE_ARRAY)) != 0) { |
1661 | 0 | jit_set_Z_TYPE_INFO(jit, dst, Z_TYPE_INFO_P(zv)); |
1662 | 0 | } |
1663 | 0 | } |
1664 | 0 | } |
1665 | | |
1666 | | static ir_ref jit_if_TYPED_REF(zend_jit_ctx *jit, ir_ref ref) |
1667 | 0 | { |
1668 | 0 | return ir_IF(ir_LOAD_A(ir_ADD_OFFSET(ref, offsetof(zend_reference, sources.ptr)))); |
1669 | 0 | } |
1670 | | |
1671 | | static void jit_ZVAL_COPY(zend_jit_ctx *jit, zend_jit_addr dst, uint32_t dst_info, zend_jit_addr src, uint32_t src_info, bool addref) |
1672 | 0 | { |
1673 | 0 | ir_ref ref = IR_UNUSED; |
1674 | |
|
1675 | 0 | if (src_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE))) { |
1676 | 0 | if ((src_info & (MAY_BE_ANY|MAY_BE_GUARD)) == MAY_BE_LONG) { |
1677 | 0 | jit_set_Z_LVAL(jit, dst, jit_Z_LVAL(jit, src)); |
1678 | 0 | } else if ((src_info & (MAY_BE_ANY|MAY_BE_GUARD)) == MAY_BE_DOUBLE) { |
1679 | 0 | jit_set_Z_DVAL(jit, dst, jit_Z_DVAL(jit, src)); |
1680 | 0 | } else { |
1681 | | #if SIZEOF_ZEND_LONG == 4 |
1682 | | if (src_info & (MAY_BE_DOUBLE|MAY_BE_GUARD)) { |
1683 | | jit_set_Z_W2(jit, dst, jit_Z_W2(jit, src)); |
1684 | | } |
1685 | | #endif |
1686 | 0 | ref = jit_Z_PTR(jit, src); |
1687 | 0 | jit_set_Z_PTR(jit, dst, ref); |
1688 | 0 | } |
1689 | 0 | } |
1690 | 0 | if (has_concrete_type(src_info & MAY_BE_ANY) |
1691 | 0 | && (src_info & (MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE)) |
1692 | 0 | && !(src_info & MAY_BE_GUARD)) { |
1693 | 0 | if (Z_MODE(dst) != IS_REG |
1694 | 0 | && (dst_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) != (src_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD))) { |
1695 | 0 | uint8_t type = concrete_type(src_info); |
1696 | 0 | jit_set_Z_TYPE_INFO(jit, dst, type); |
1697 | 0 | } |
1698 | 0 | } else { |
1699 | 0 | ir_ref type = jit_Z_TYPE_INFO(jit, src); |
1700 | 0 | jit_set_Z_TYPE_INFO_ex(jit, dst, type); |
1701 | 0 | if (addref) { |
1702 | 0 | if (src_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
1703 | 0 | ir_ref if_refcounted = IR_UNUSED; |
1704 | |
|
1705 | 0 | if (src_info & (MAY_BE_ANY-(MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
1706 | 0 | if_refcounted = ir_IF(ir_AND_U32(type, ir_CONST_U32(0xff00))); |
1707 | 0 | ir_IF_TRUE(if_refcounted); |
1708 | 0 | } |
1709 | |
|
1710 | 0 | jit_GC_ADDREF(jit, ref); |
1711 | |
|
1712 | 0 | if (src_info & (MAY_BE_ANY-(MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
1713 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_refcounted); |
1714 | 0 | } |
1715 | 0 | } |
1716 | 0 | } |
1717 | 0 | } |
1718 | 0 | } |
1719 | | |
1720 | | static void jit_ZVAL_COPY_2(zend_jit_ctx *jit, zend_jit_addr dst2, zend_jit_addr dst, uint32_t dst_info, zend_jit_addr src, uint32_t src_info, int addref) |
1721 | 0 | { |
1722 | 0 | ir_ref ref = IR_UNUSED; |
1723 | |
|
1724 | 0 | if (src_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE))) { |
1725 | 0 | if ((src_info & (MAY_BE_ANY|MAY_BE_GUARD)) == MAY_BE_LONG) { |
1726 | 0 | ref = jit_Z_LVAL(jit, src); |
1727 | 0 | jit_set_Z_LVAL(jit, dst, ref); |
1728 | 0 | jit_set_Z_LVAL(jit, dst2, ref); |
1729 | 0 | } else if ((src_info & (MAY_BE_ANY|MAY_BE_GUARD)) == MAY_BE_DOUBLE) { |
1730 | 0 | ref = jit_Z_DVAL(jit, src); |
1731 | 0 | jit_set_Z_DVAL(jit, dst, ref); |
1732 | 0 | jit_set_Z_DVAL(jit, dst2, ref); |
1733 | 0 | } else { |
1734 | | #if SIZEOF_ZEND_LONG == 4 |
1735 | | if (src_info & (MAY_BE_DOUBLE|MAY_BE_GUARD)) { |
1736 | | ref = jit_Z_W2(jit, src); |
1737 | | jit_set_Z_W2(jit, dst, ref); |
1738 | | jit_set_Z_W2(jit, dst2, ref); |
1739 | | } |
1740 | | #endif |
1741 | 0 | ref = jit_Z_PTR(jit, src); |
1742 | 0 | jit_set_Z_PTR(jit, dst, ref); |
1743 | 0 | jit_set_Z_PTR(jit, dst2, ref); |
1744 | 0 | } |
1745 | 0 | } |
1746 | 0 | if (has_concrete_type(src_info & MAY_BE_ANY) |
1747 | 0 | && (src_info & (MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE)) |
1748 | 0 | && !(src_info & MAY_BE_GUARD)) { |
1749 | 0 | uint8_t type = concrete_type(src_info); |
1750 | 0 | ir_ref type_ref = ir_CONST_U32(type); |
1751 | |
|
1752 | 0 | if (Z_MODE(dst) != IS_REG |
1753 | 0 | && (dst_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) != (src_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD))) { |
1754 | 0 | jit_set_Z_TYPE_INFO_ex(jit, dst, type_ref); |
1755 | 0 | } |
1756 | 0 | if (Z_MODE(dst2) != IS_REG) { |
1757 | 0 | jit_set_Z_TYPE_INFO_ex(jit, dst2, type_ref); |
1758 | 0 | } |
1759 | 0 | } else { |
1760 | 0 | ir_ref type = jit_Z_TYPE_INFO(jit, src); |
1761 | 0 | jit_set_Z_TYPE_INFO_ex(jit, dst, type); |
1762 | 0 | jit_set_Z_TYPE_INFO_ex(jit, dst2, type); |
1763 | 0 | if (addref) { |
1764 | 0 | if (src_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
1765 | 0 | ir_ref if_refcounted = IR_UNUSED; |
1766 | |
|
1767 | 0 | if (src_info & (MAY_BE_ANY-(MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
1768 | 0 | if_refcounted = ir_IF(ir_AND_U32(type, ir_CONST_U32(0xff00))); |
1769 | 0 | ir_IF_TRUE(if_refcounted); |
1770 | 0 | } |
1771 | |
|
1772 | 0 | if (addref == 2) { |
1773 | 0 | jit_GC_ADDREF2(jit, ref); |
1774 | 0 | } else { |
1775 | 0 | jit_GC_ADDREF(jit, ref); |
1776 | 0 | } |
1777 | |
|
1778 | 0 | if (src_info & (MAY_BE_ANY-(MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
1779 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_refcounted); |
1780 | 0 | } |
1781 | 0 | } |
1782 | 0 | } |
1783 | 0 | } |
1784 | 0 | } |
1785 | | |
1786 | | static void jit_ZVAL_DTOR(zend_jit_ctx *jit, ir_ref ref, uint32_t op_info, const zend_op *opline) |
1787 | 0 | { |
1788 | 0 | if (!((op_info) & MAY_BE_GUARD) |
1789 | 0 | && has_concrete_type((op_info) & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
1790 | 0 | uint8_t type = concrete_type((op_info) & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)); |
1791 | 0 | if (type == IS_STRING && !ZEND_DEBUG) { |
1792 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(_efree), ref); |
1793 | 0 | return; |
1794 | 0 | } else if (type == IS_ARRAY) { |
1795 | 0 | if ((op_info) & (MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_REF)) { |
1796 | 0 | if (opline && ((op_info) & (MAY_BE_ARRAY_OF_ARRAY|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_REF))) { |
1797 | 0 | jit_SET_EX_OPLINE(jit, opline); |
1798 | 0 | } |
1799 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_array_destroy), ref); |
1800 | 0 | } else { |
1801 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_array_free), ref); |
1802 | 0 | } |
1803 | 0 | return; |
1804 | 0 | } else if (type == IS_OBJECT) { |
1805 | 0 | if (opline) { |
1806 | 0 | jit_SET_EX_OPLINE(jit, opline); |
1807 | 0 | } |
1808 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_objects_store_del), ref); |
1809 | 0 | return; |
1810 | 0 | } |
1811 | 0 | } |
1812 | 0 | if (opline) { |
1813 | 0 | jit_SET_EX_OPLINE(jit, opline); |
1814 | 0 | } |
1815 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(rc_dtor_func), ref); |
1816 | 0 | } |
1817 | | |
1818 | | static void jit_ZVAL_PTR_DTOR(zend_jit_ctx *jit, |
1819 | | zend_jit_addr addr, |
1820 | | uint32_t op_info, |
1821 | | bool gc, |
1822 | | const zend_op *opline) |
1823 | 0 | { |
1824 | 0 | ir_ref ref, ref2; |
1825 | 0 | ir_ref if_refcounted = IR_UNUSED; |
1826 | 0 | ir_ref if_not_zero = IR_UNUSED; |
1827 | 0 | ir_ref end_inputs = IR_UNUSED; |
1828 | |
|
1829 | 0 | if (op_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF|MAY_BE_GUARD)) { |
1830 | 0 | if ((op_info) & ((MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_INDIRECT|MAY_BE_GUARD)-(MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
1831 | 0 | if_refcounted = jit_if_REFCOUNTED(jit, addr); |
1832 | 0 | ir_IF_FALSE(if_refcounted); |
1833 | 0 | ir_END_list(end_inputs); |
1834 | 0 | ir_IF_TRUE(if_refcounted); |
1835 | 0 | } |
1836 | 0 | ref = jit_Z_PTR(jit, addr); |
1837 | 0 | ref2 = jit_GC_DELREF(jit, ref); |
1838 | |
|
1839 | 0 | if (((op_info) & MAY_BE_GUARD) || RC_MAY_BE_1(op_info)) { |
1840 | 0 | if (((op_info) & MAY_BE_GUARD) || RC_MAY_BE_N(op_info)) { |
1841 | 0 | if_not_zero = ir_IF(ref2); |
1842 | 0 | ir_IF_FALSE(if_not_zero); |
1843 | 0 | } |
1844 | | // zval_dtor_func(r); |
1845 | 0 | jit_ZVAL_DTOR(jit, ref, op_info, opline); |
1846 | 0 | if (if_not_zero) { |
1847 | 0 | ir_END_list(end_inputs); |
1848 | 0 | ir_IF_TRUE(if_not_zero); |
1849 | 0 | } |
1850 | 0 | } |
1851 | 0 | if (gc && (((op_info) & MAY_BE_GUARD) || (RC_MAY_BE_N(op_info) && ((op_info) & (MAY_BE_REF|MAY_BE_ARRAY|MAY_BE_OBJECT)) != 0))) { |
1852 | 0 | ir_ref if_may_not_leak; |
1853 | |
|
1854 | 0 | if ((op_info) & (MAY_BE_REF|MAY_BE_GUARD)) { |
1855 | 0 | ir_ref if_ref, if_collectable; |
1856 | |
|
1857 | 0 | if_ref = jit_if_Z_TYPE(jit, addr, IS_REFERENCE); |
1858 | 0 | ir_IF_TRUE(if_ref); |
1859 | |
|
1860 | 0 | ref2 = ir_ADD_OFFSET(ref, offsetof(zend_reference, val)); |
1861 | |
|
1862 | 0 | if_collectable = jit_if_COLLECTABLE_ref(jit, ref2); |
1863 | 0 | ir_IF_FALSE(if_collectable); |
1864 | 0 | ir_END_list(end_inputs); |
1865 | 0 | ir_IF_TRUE(if_collectable); |
1866 | |
|
1867 | 0 | ref2 = jit_Z_PTR_ref(jit, ref2); |
1868 | |
|
1869 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_ref); |
1870 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
1871 | 0 | } |
1872 | |
|
1873 | 0 | if_may_not_leak = jit_if_GC_MAY_NOT_LEAK(jit, ref); |
1874 | 0 | ir_IF_TRUE(if_may_not_leak); |
1875 | 0 | ir_END_list(end_inputs); |
1876 | 0 | ir_IF_FALSE(if_may_not_leak); |
1877 | |
|
1878 | 0 | if (opline) { |
1879 | 0 | jit_SET_EX_OPLINE(jit, opline); |
1880 | 0 | } |
1881 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(gc_possible_root), ref); |
1882 | 0 | } |
1883 | |
|
1884 | 0 | if (end_inputs) { |
1885 | 0 | ir_END_list(end_inputs); |
1886 | 0 | ir_MERGE_list(end_inputs); |
1887 | 0 | } |
1888 | 0 | } |
1889 | 0 | } |
1890 | | |
1891 | | static void jit_FREE_OP(zend_jit_ctx *jit, |
1892 | | uint8_t op_type, |
1893 | | znode_op op, |
1894 | | uint32_t op_info, |
1895 | | const zend_op *opline) |
1896 | 0 | { |
1897 | 0 | if (op_type & (IS_VAR|IS_TMP_VAR)) { |
1898 | 0 | jit_ZVAL_PTR_DTOR(jit, |
1899 | 0 | ZEND_ADDR_MEM_ZVAL(ZREG_FP, op.var), |
1900 | 0 | op_info, false, opline); |
1901 | 0 | } |
1902 | 0 | } |
1903 | | |
1904 | | static void jit_OBJ_RELEASE(zend_jit_ctx *jit, ir_ref ref) |
1905 | 0 | { |
1906 | 0 | ir_ref end_inputs = IR_UNUSED; |
1907 | 0 | ir_ref if_not_zero, if_may_not_leak; |
1908 | | |
1909 | | // JIT: if (GC_DELREF(obj) == 0) { |
1910 | 0 | if_not_zero = ir_IF(jit_GC_DELREF(jit, ref)); |
1911 | 0 | ir_IF_FALSE(if_not_zero); |
1912 | | |
1913 | | // JIT: zend_objects_store_del(obj) |
1914 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_objects_store_del), ref); |
1915 | 0 | ir_END_list(end_inputs); |
1916 | |
|
1917 | 0 | ir_IF_TRUE(if_not_zero); |
1918 | 0 | if_may_not_leak = jit_if_GC_MAY_NOT_LEAK(jit, ref); |
1919 | |
|
1920 | 0 | ir_IF_TRUE(if_may_not_leak); |
1921 | 0 | ir_END_list(end_inputs); |
1922 | |
|
1923 | 0 | ir_IF_FALSE(if_may_not_leak); |
1924 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(gc_possible_root), ref); |
1925 | 0 | ir_END_list(end_inputs); |
1926 | |
|
1927 | 0 | ir_MERGE_list(end_inputs); |
1928 | 0 | } |
1929 | | |
1930 | | static void zend_jit_check_timeout(zend_jit_ctx *jit, const zend_op *opline, const void *exit_addr) |
1931 | 0 | { |
1932 | 0 | ir_ref ref = ir_LOAD_U8(jit_EG(vm_interrupt)); |
1933 | |
|
1934 | 0 | if (exit_addr) { |
1935 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
1936 | 0 | } else if (!opline || jit->last_valid_opline == opline) { |
1937 | 0 | ir_GUARD_NOT(ref, jit_STUB_ADDR(jit, jit_stub_interrupt_handler)); |
1938 | 0 | } else { |
1939 | 0 | ir_ref if_timeout = ir_IF(ref); |
1940 | |
|
1941 | 0 | ir_IF_TRUE_cold(if_timeout); |
1942 | 0 | jit_LOAD_IP_ADDR(jit, opline); |
1943 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_interrupt_handler)); |
1944 | 0 | ir_IF_FALSE(if_timeout); |
1945 | 0 | } |
1946 | 0 | } |
1947 | | |
1948 | | static void zend_jit_vm_enter(zend_jit_ctx *jit, ir_ref to_opline) |
1949 | 0 | { |
1950 | | // ZEND_VM_ENTER() |
1951 | 0 | ir_RETURN(ir_OR_A(to_opline, ir_CONST_ADDR(ZEND_VM_ENTER_BIT))); |
1952 | 0 | } |
1953 | | |
1954 | | static void zend_jit_vm_leave(zend_jit_ctx *jit, ir_ref to_opline) |
1955 | 0 | { |
1956 | 0 | // ZEND_VM_LEAVE() |
1957 | 0 | ir_RETURN(ir_OR_A(to_opline, ir_CONST_ADDR(ZEND_VM_ENTER_BIT))); |
1958 | 0 | } |
1959 | | |
1960 | | static void zend_jit_tailcall_handler(zend_jit_ctx *jit, ir_ref handler) |
1961 | 0 | { |
1962 | | #if defined(IR_TARGET_X86) |
1963 | | if (!IR_IS_CONST_REF(handler)) { |
1964 | | handler = ir_CAST_OPCODE_HANDLER_FUNC(handler); |
1965 | | } |
1966 | | #endif |
1967 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
1968 | 0 | ir_TAILCALL(IR_OPCODE_HANDLER_RET, handler); |
1969 | 0 | } else { |
1970 | 0 | ir_TAILCALL_2(IR_ADDR, handler, jit_FP(jit), jit_IP(jit)); |
1971 | 0 | } |
1972 | 0 | } |
1973 | | |
1974 | | /* stubs */ |
1975 | | |
1976 | | static int zend_jit_exception_handler_stub(zend_jit_ctx *jit) |
1977 | 0 | { |
1978 | 0 | if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) { |
1979 | 0 | zend_vm_opcode_handler_func_t handler = (zend_vm_opcode_handler_func_t)zend_get_opcode_handler_func(EG(exception_op)); |
1980 | |
|
1981 | 0 | ir_CALL(IR_VOID, ir_CONST_FUNC(handler)); |
1982 | 0 | ir_TAILCALL(IR_VOID, ir_LOAD_A(jit_IP(jit))); |
1983 | 0 | } else { |
1984 | 0 | zend_vm_opcode_handler_t handler = EG(exception_op)->handler; |
1985 | |
|
1986 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
1987 | 0 | zend_jit_tailcall_handler(jit, ir_CONST_OPCODE_HANDLER_FUNC(handler)); |
1988 | 0 | } else { |
1989 | 0 | ir_ref ref = ir_CALL_2(IR_ADDR, ir_CONST_OPCODE_HANDLER_FUNC(handler), jit_FP(jit), jit_IP(jit)); |
1990 | 0 | zend_jit_vm_enter(jit, ref); |
1991 | 0 | } |
1992 | 0 | } |
1993 | 0 | return 1; |
1994 | 0 | } |
1995 | | |
1996 | | static int zend_jit_exception_handler_undef_stub(zend_jit_ctx *jit) |
1997 | 0 | { |
1998 | 0 | ir_ref ref, result_type, if_result_used; |
1999 | |
|
2000 | 0 | ref = jit_EG(opline_before_exception); |
2001 | 0 | result_type = ir_LOAD_U8(ir_ADD_OFFSET(ir_LOAD_A(ref), offsetof(zend_op, result_type))); |
2002 | |
|
2003 | 0 | if_result_used = ir_IF(ir_AND_U8(result_type, ir_CONST_U8(IS_TMP_VAR|IS_VAR))); |
2004 | 0 | ir_IF_TRUE(if_result_used); |
2005 | |
|
2006 | 0 | ref = ir_LOAD_U32(ir_ADD_OFFSET(ir_LOAD_A(ref), offsetof(zend_op, result.var))); |
2007 | 0 | if (sizeof(void*) == 8) { |
2008 | 0 | ref = ir_ZEXT_A(ref); |
2009 | 0 | } |
2010 | 0 | ir_STORE(ir_ADD_OFFSET(ir_ADD_A(jit_FP(jit), ref), offsetof(zval, u1.type_info)), ir_CONST_U32(IS_UNDEF)); |
2011 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_result_used); |
2012 | |
|
2013 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
2014 | |
|
2015 | 0 | return 1; |
2016 | 0 | } |
2017 | | |
2018 | | static int zend_jit_exception_handler_free_op1_op2_stub(zend_jit_ctx *jit) |
2019 | 0 | { |
2020 | 0 | ir_ref ref, if_dtor; |
2021 | 0 | zend_jit_addr var_addr; |
2022 | |
|
2023 | 0 | ref = ir_LOAD_A(jit_EG(opline_before_exception)); |
2024 | 0 | if_dtor = ir_IF(ir_AND_U8(ir_LOAD_U8(ir_ADD_OFFSET(ref, offsetof(zend_op, op1_type))), |
2025 | 0 | ir_CONST_U8(IS_TMP_VAR|IS_VAR))); |
2026 | 0 | ir_IF_TRUE(if_dtor); |
2027 | 0 | ref = ir_LOAD_U32(ir_ADD_OFFSET(ref, offsetof(zend_op, op1.var))); |
2028 | 0 | if (sizeof(void*) == 8) { |
2029 | 0 | ref = ir_ZEXT_A(ref); |
2030 | 0 | } |
2031 | 0 | ref = ir_ADD_A(jit_FP(jit), ref); |
2032 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
2033 | 0 | jit_ZVAL_PTR_DTOR(jit, var_addr, MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN|MAY_BE_REF, false, NULL); |
2034 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_dtor); |
2035 | |
|
2036 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler_free_op2)); |
2037 | |
|
2038 | 0 | return 1; |
2039 | 0 | } |
2040 | | |
2041 | | static int zend_jit_exception_handler_free_op2_stub(zend_jit_ctx *jit) |
2042 | 0 | { |
2043 | 0 | ir_ref ref, if_dtor; |
2044 | 0 | zend_jit_addr var_addr; |
2045 | |
|
2046 | 0 | ref = ir_LOAD_A(jit_EG(opline_before_exception)); |
2047 | 0 | if_dtor = ir_IF(ir_AND_U8(ir_LOAD_U8(ir_ADD_OFFSET(ref, offsetof(zend_op, op2_type))), |
2048 | 0 | ir_CONST_U8(IS_TMP_VAR|IS_VAR))); |
2049 | 0 | ir_IF_TRUE(if_dtor); |
2050 | 0 | ref = ir_LOAD_U32(ir_ADD_OFFSET(ref, offsetof(zend_op, op2.var))); |
2051 | 0 | if (sizeof(void*) == 8) { |
2052 | 0 | ref = ir_ZEXT_A(ref); |
2053 | 0 | } |
2054 | 0 | ref = ir_ADD_A(jit_FP(jit), ref); |
2055 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
2056 | 0 | jit_ZVAL_PTR_DTOR(jit, var_addr, MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN|MAY_BE_REF, false, NULL); |
2057 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_dtor); |
2058 | |
|
2059 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler_undef)); |
2060 | |
|
2061 | 0 | return 1; |
2062 | 0 | } |
2063 | | |
2064 | | static int zend_jit_interrupt_handler_stub(zend_jit_ctx *jit) |
2065 | 0 | { |
2066 | 0 | ir_ref if_timeout, if_exception; |
2067 | | |
2068 | | // EX(opline) = opline |
2069 | 0 | ir_STORE(jit_EX(opline), jit_IP(jit)); |
2070 | |
|
2071 | 0 | ir_STORE(jit_EG(vm_interrupt), ir_CONST_U8(0)); |
2072 | 0 | if_timeout = ir_IF(ir_EQ(ir_LOAD_U8(jit_EG(timed_out)), ir_CONST_U8(0))); |
2073 | 0 | ir_IF_FALSE(if_timeout); |
2074 | 0 | ir_CALL(IR_VOID, ir_CONST_FUNC(zend_timeout)); |
2075 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_timeout); |
2076 | |
|
2077 | 0 | if (zend_interrupt_function) { |
2078 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FUNC(zend_interrupt_function), jit_FP(jit)); |
2079 | 0 | if_exception = ir_IF(ir_LOAD_A(jit_EG(exception))); |
2080 | 0 | ir_IF_TRUE(if_exception); |
2081 | 0 | ir_CALL(IR_VOID, ir_CONST_FUNC(zend_jit_exception_in_interrupt_handler_helper)); |
2082 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_exception); |
2083 | |
|
2084 | 0 | jit_STORE_FP(jit, ir_LOAD_A(jit_EG(current_execute_data))); |
2085 | 0 | jit_STORE_IP(jit, ir_LOAD_A(jit_EX(opline))); |
2086 | 0 | } |
2087 | |
|
2088 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
2089 | 0 | zend_jit_tailcall_handler(jit, ir_LOAD_A(jit_IP(jit))); |
2090 | 0 | } else { |
2091 | 0 | zend_jit_vm_enter(jit, jit_IP(jit)); |
2092 | 0 | } |
2093 | 0 | return 1; |
2094 | 0 | } |
2095 | | |
2096 | | static int zend_jit_leave_function_handler_stub(zend_jit_ctx *jit) |
2097 | 0 | { |
2098 | 0 | #if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL |
2099 | 0 | ir_TAILCALL(IR_OPCODE_HANDLER_RET, ir_CONST_OPCODE_HANDLER_FUNC(zend_jit_leave_func_helper_tailcall)); |
2100 | 0 | return 1; |
2101 | | #else |
2102 | | ir_ref call_info = ir_LOAD_U32(jit_EX(This.u1.type_info)); |
2103 | | ir_ref if_top = ir_IF(ir_AND_U32(call_info, ir_CONST_U32(ZEND_CALL_TOP))); |
2104 | | |
2105 | | ir_IF_FALSE(if_top); |
2106 | | |
2107 | | if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) { |
2108 | | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_leave_nested_func_helper), call_info); |
2109 | | jit_STORE_IP(jit, |
2110 | | ir_LOAD_A(jit_EX(opline))); |
2111 | | ir_TAILCALL(IR_VOID, ir_LOAD_A(jit_IP(jit))); |
2112 | | } else if (GCC_GLOBAL_REGS) { |
2113 | | ir_TAILCALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_leave_nested_func_helper), call_info); |
2114 | | } else { |
2115 | | ir_TAILCALL_3(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_leave_nested_func_helper), jit_FP(jit), jit_IP(jit), call_info); |
2116 | | } |
2117 | | |
2118 | | ir_IF_TRUE(if_top); |
2119 | | |
2120 | | if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) { |
2121 | | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_leave_top_func_helper), call_info); |
2122 | | ir_TAILCALL(IR_VOID, ir_LOAD_A(jit_IP(jit))); |
2123 | | } else if (GCC_GLOBAL_REGS) { |
2124 | | ir_TAILCALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_leave_top_func_helper), call_info); |
2125 | | } else { |
2126 | | ir_TAILCALL_3(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_leave_top_func_helper), jit_FP(jit), jit_IP(jit), call_info); |
2127 | | } |
2128 | | |
2129 | | return 1; |
2130 | | #endif /* ZEND_VM_KIND != ZEND_VM_KIND_TAILCALL */ |
2131 | 0 | } |
2132 | | |
2133 | | static int zend_jit_negative_shift_stub(zend_jit_ctx *jit) |
2134 | 0 | { |
2135 | 0 | ir_CALL_2(IR_VOID, |
2136 | 0 | ir_CONST_FUNC_PROTO(zend_throw_error, |
2137 | 0 | ir_proto_2(&jit->ctx, IR_VARARG_FUNC, IR_VOID, IR_ADDR, IR_ADDR)), |
2138 | 0 | ir_CONST_ADDR(zend_ce_arithmetic_error), |
2139 | 0 | ir_CONST_ADDR("Bit shift by negative number")); |
2140 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler_free_op1_op2)); |
2141 | 0 | return 1; |
2142 | 0 | } |
2143 | | |
2144 | | static int zend_jit_mod_by_zero_stub(zend_jit_ctx *jit) |
2145 | 0 | { |
2146 | 0 | ir_CALL_2(IR_VOID, |
2147 | 0 | ir_CONST_FUNC_PROTO(zend_throw_error, |
2148 | 0 | ir_proto_2(&jit->ctx, IR_VARARG_FUNC, IR_VOID, IR_ADDR, IR_ADDR)), |
2149 | 0 | ir_CONST_ADDR(zend_ce_division_by_zero_error), |
2150 | 0 | ir_CONST_ADDR("Modulo by zero")); |
2151 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler_free_op1_op2)); |
2152 | 0 | return 1; |
2153 | 0 | } |
2154 | | |
2155 | | static int zend_jit_invalid_this_stub(zend_jit_ctx *jit) |
2156 | 0 | { |
2157 | 0 | ir_CALL_2(IR_VOID, |
2158 | 0 | ir_CONST_FUNC_PROTO(zend_throw_error, |
2159 | 0 | ir_proto_2(&jit->ctx, IR_VARARG_FUNC, IR_VOID, IR_ADDR, IR_ADDR)), |
2160 | 0 | IR_NULL, |
2161 | 0 | ir_CONST_ADDR("Using $this when not in object context")); |
2162 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler_undef)); |
2163 | 0 | return 1; |
2164 | 0 | } |
2165 | | |
2166 | | static int zend_jit_undefined_function_stub(zend_jit_ctx *jit) |
2167 | 0 | { |
2168 | | // JIT: load EX(opline) |
2169 | 0 | ir_ref ref = ir_LOAD_A(jit_FP(jit)); |
2170 | 0 | ir_ref arg3 = ir_LOAD_U32(ir_ADD_OFFSET(ref, offsetof(zend_op, op2.constant))); |
2171 | |
|
2172 | 0 | if (sizeof(void*) == 8) { |
2173 | 0 | arg3 = ir_LOAD_A(ir_ADD_A(ref, ir_SEXT_A(arg3))); |
2174 | 0 | } else { |
2175 | 0 | arg3 = ir_LOAD_A(arg3); |
2176 | 0 | } |
2177 | 0 | arg3 = ir_ADD_OFFSET(arg3, offsetof(zend_string, val)); |
2178 | |
|
2179 | 0 | ir_CALL_3(IR_VOID, |
2180 | 0 | ir_CONST_FUNC_PROTO(zend_throw_error, |
2181 | 0 | ir_proto_2(&jit->ctx, IR_VARARG_FUNC, IR_VOID, IR_ADDR, IR_ADDR)), |
2182 | 0 | IR_NULL, |
2183 | 0 | ir_CONST_ADDR("Call to undefined function %s()"), |
2184 | 0 | arg3); |
2185 | |
|
2186 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
2187 | |
|
2188 | 0 | return 1; |
2189 | 0 | } |
2190 | | |
2191 | | static int zend_jit_throw_cannot_pass_by_ref_stub(zend_jit_ctx *jit) |
2192 | 0 | { |
2193 | 0 | ir_ref opline, ref, rx, if_eq, if_tmp; |
2194 | | |
2195 | | // JIT: opline = EX(opline) |
2196 | 0 | opline = ir_LOAD_A(jit_FP(jit)); |
2197 | | |
2198 | | // JIT: ZVAL_UNDEF(ZEND_CALL_VAR(RX, opline->result.var)) |
2199 | 0 | ref = ir_LOAD_U32(ir_ADD_OFFSET(opline, offsetof(zend_op, result.var))); |
2200 | 0 | if (sizeof(void*) == 8) { |
2201 | 0 | ref = ir_ZEXT_A(ref); |
2202 | 0 | } |
2203 | 0 | rx = jit_IP(jit); |
2204 | 0 | jit_set_Z_TYPE_INFO_ref(jit, ir_ADD_A(rx, ref), ir_CONST_U32(IS_UNDEF)); |
2205 | | |
2206 | | // last EX(call) frame may be delayed |
2207 | | // JIT: if (EX(call) == RX) |
2208 | 0 | ref = ir_LOAD_A(jit_EX(call)); |
2209 | 0 | if_eq = ir_IF(ir_EQ(rx, ref)); |
2210 | 0 | ir_IF_FALSE(if_eq); |
2211 | | |
2212 | | // JIT: RX->prev_execute_data == EX(call) |
2213 | 0 | ir_STORE(jit_CALL(rx, prev_execute_data), ref); |
2214 | | |
2215 | | // JIT: EX(call) = RX |
2216 | 0 | ir_STORE(jit_EX(call), rx); |
2217 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_eq); |
2218 | | |
2219 | | // JIT: IP = opline |
2220 | 0 | jit_STORE_IP(jit, opline); |
2221 | | |
2222 | | // JIT: zend_cannot_pass_by_reference(opline->op2.num) |
2223 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_cannot_pass_by_reference), |
2224 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(opline, offsetof(zend_op, op2.num)))); |
2225 | | |
2226 | | // JIT: if (IP->op1_type == IS_TMP_VAR) |
2227 | 0 | ref = ir_LOAD_U8(ir_ADD_OFFSET(jit_IP(jit), offsetof(zend_op, op1_type))); |
2228 | 0 | if_tmp = ir_IF(ir_EQ(ref, ir_CONST_U8(IS_TMP_VAR))); |
2229 | 0 | ir_IF_TRUE(if_tmp); |
2230 | | |
2231 | | // JIT: zval_ptr_dtor(EX_VAR(IP->op1.var)) |
2232 | 0 | ref = ir_LOAD_U32(ir_ADD_OFFSET(jit_IP(jit), offsetof(zend_op, op1.var))); |
2233 | 0 | if (sizeof(void*) == 8) { |
2234 | 0 | ref = ir_ZEXT_A(ref); |
2235 | 0 | } |
2236 | 0 | ref = ir_ADD_A(jit_FP(jit), ref); |
2237 | 0 | jit_ZVAL_PTR_DTOR(jit, |
2238 | 0 | ZEND_ADDR_REF_ZVAL(ref), |
2239 | 0 | MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN|MAY_BE_REF, false, NULL); |
2240 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_tmp); |
2241 | |
|
2242 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
2243 | |
|
2244 | 0 | return 1; |
2245 | 0 | } |
2246 | | |
2247 | | static int zend_jit_icall_throw_stub(zend_jit_ctx *jit) |
2248 | 0 | { |
2249 | 0 | ir_ref ip, if_set; |
2250 | | |
2251 | | // JIT: zend_rethrow_exception(zend_execute_data *execute_data) |
2252 | | // JIT: if (EX(opline)->opcode != ZEND_HANDLE_EXCEPTION) { |
2253 | 0 | jit_STORE_IP(jit, ir_LOAD_A(jit_EX(opline))); |
2254 | 0 | ip = jit_IP(jit); |
2255 | 0 | if_set = ir_IF(ir_EQ(ir_LOAD_U8(ir_ADD_OFFSET(ip, offsetof(zend_op, opcode))), |
2256 | 0 | ir_CONST_U8(ZEND_HANDLE_EXCEPTION))); |
2257 | 0 | ir_IF_FALSE(if_set); |
2258 | | |
2259 | | // JIT: EG(opline_before_exception) = opline; |
2260 | 0 | ir_STORE(jit_EG(opline_before_exception), ip); |
2261 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_set); |
2262 | | |
2263 | | // JIT: opline = EG(exception_op); |
2264 | 0 | jit_STORE_IP(jit, jit_EG(exception_op)); |
2265 | |
|
2266 | 0 | ir_STORE(jit_EX(opline), jit_IP(jit)); |
2267 | |
|
2268 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
2269 | |
|
2270 | 0 | return 1; |
2271 | 0 | } |
2272 | | |
2273 | | static int zend_jit_leave_throw_stub(zend_jit_ctx *jit) |
2274 | 0 | { |
2275 | 0 | ir_ref ip, if_set; |
2276 | | |
2277 | | // JIT: if (opline->opcode != ZEND_HANDLE_EXCEPTION) { |
2278 | 0 | jit_STORE_IP(jit, ir_LOAD_A(jit_EX(opline))); |
2279 | 0 | ip = jit_IP(jit); |
2280 | 0 | if_set = ir_IF(ir_EQ(ir_LOAD_U8(ir_ADD_OFFSET(ip, offsetof(zend_op, opcode))), |
2281 | 0 | ir_CONST_U8(ZEND_HANDLE_EXCEPTION))); |
2282 | 0 | ir_IF_FALSE(if_set); |
2283 | | |
2284 | | // JIT: EG(opline_before_exception) = opline; |
2285 | 0 | ir_STORE(jit_EG(opline_before_exception), ip); |
2286 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_set); |
2287 | | |
2288 | | // JIT: opline = EG(exception_op); |
2289 | 0 | jit_STORE_IP(jit, jit_EG(exception_op)); |
2290 | |
|
2291 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
2292 | 0 | ir_STORE(jit_EX(opline), jit_IP(jit)); |
2293 | | |
2294 | | // JIT: HANDLE_EXCEPTION() |
2295 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
2296 | 0 | } else { |
2297 | 0 | zend_jit_vm_leave(jit, jit_IP(jit)); |
2298 | 0 | } |
2299 | |
|
2300 | 0 | return 1; |
2301 | 0 | } |
2302 | | |
2303 | | static int zend_jit_hybrid_runtime_jit_stub(zend_jit_ctx *jit) |
2304 | 0 | { |
2305 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_HYBRID) { |
2306 | 0 | return 0; |
2307 | 0 | } |
2308 | | |
2309 | 0 | ir_CALL(IR_VOID, ir_CONST_OPCODE_HANDLER_FUNC(zend_runtime_jit)); |
2310 | 0 | ir_IJMP(ir_LOAD_A(jit_IP(jit))); |
2311 | 0 | return 1; |
2312 | 0 | } |
2313 | | |
2314 | | static int zend_jit_hybrid_profile_jit_stub(zend_jit_ctx *jit) |
2315 | 0 | { |
2316 | 0 | ir_ref addr, func, run_time_cache, jit_extension; |
2317 | |
|
2318 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_HYBRID) { |
2319 | 0 | return 0; |
2320 | 0 | } |
2321 | | |
2322 | 0 | addr = ir_CONST_ADDR(&zend_jit_profile_counter), |
2323 | 0 | ir_STORE(addr, ir_ADD_L(ir_LOAD_L(addr), ir_CONST_LONG(1))); |
2324 | |
|
2325 | 0 | func = ir_LOAD_A(jit_EX(func)); |
2326 | 0 | run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
2327 | 0 | jit_extension = ir_LOAD_A(ir_ADD_OFFSET(func, offsetof(zend_op_array, reserved[zend_func_info_rid]))); |
2328 | |
|
2329 | 0 | if (zend_jit_profile_counter_rid) { |
2330 | 0 | addr = ir_ADD_OFFSET(run_time_cache, zend_jit_profile_counter_rid * sizeof(void*)); |
2331 | 0 | } else { |
2332 | 0 | addr = run_time_cache; |
2333 | 0 | } |
2334 | 0 | ir_STORE(addr, ir_ADD_L(ir_LOAD_L(addr), ir_CONST_LONG(1))); |
2335 | |
|
2336 | 0 | addr = ir_ADD_OFFSET(jit_extension, offsetof(zend_jit_op_array_extension, orig_handler)); |
2337 | 0 | ir_IJMP(ir_LOAD_A(addr)); |
2338 | |
|
2339 | 0 | return 1; |
2340 | 0 | } |
2341 | | |
2342 | | static int _zend_jit_hybrid_hot_counter_stub(zend_jit_ctx *jit, uint32_t cost) |
2343 | 0 | { |
2344 | 0 | ir_ref func, jit_extension, addr, ref, if_overflow; |
2345 | 0 |
|
2346 | 0 | func = ir_LOAD_A(jit_EX(func)); |
2347 | 0 | jit_extension = ir_LOAD_A(ir_ADD_OFFSET(func, offsetof(zend_op_array, reserved[zend_func_info_rid]))); |
2348 | 0 | addr = ir_LOAD_A(ir_ADD_OFFSET(jit_extension, offsetof(zend_jit_op_array_hot_extension, counter))); |
2349 | 0 | ref = ir_SUB_I16(ir_LOAD_I16(addr), ir_CONST_I16(cost)); |
2350 | 0 | ir_STORE(addr, ref); |
2351 | 0 | if_overflow = ir_IF(ir_LE(ref, ir_CONST_I16(0))); |
2352 | 0 |
|
2353 | 0 | ir_IF_TRUE_cold(if_overflow); |
2354 | 0 | ir_STORE(addr, ir_CONST_I16(ZEND_JIT_COUNTER_INIT)); |
2355 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_hot_func), |
2356 | 0 | jit_FP(jit), |
2357 | 0 | jit_IP(jit)); |
2358 | 0 | ir_IJMP(ir_LOAD_A(jit_IP(jit))); |
2359 | 0 |
|
2360 | 0 | ir_IF_FALSE(if_overflow); |
2361 | 0 | ref = ir_SUB_A(jit_IP(jit), |
2362 | 0 | ir_LOAD_A(ir_ADD_OFFSET(func, offsetof(zend_op_array, opcodes)))); |
2363 | 0 | ref = ir_DIV_A(ref, ir_CONST_ADDR(sizeof(zend_op) / sizeof(void*))); |
2364 | 0 |
|
2365 | 0 | addr = ir_ADD_A(ir_ADD_OFFSET(jit_extension, offsetof(zend_jit_op_array_hot_extension, orig_handlers)), |
2366 | 0 | ref); |
2367 | 0 | ir_IJMP(ir_LOAD_A(addr)); |
2368 | 0 |
|
2369 | 0 | return 1; |
2370 | 0 | } |
2371 | | |
2372 | | static int zend_jit_hybrid_func_hot_counter_stub(zend_jit_ctx *jit) |
2373 | 0 | { |
2374 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_HYBRID || !JIT_G(hot_func)) { |
2375 | 0 | return 0; |
2376 | 0 | } |
2377 | | |
2378 | 0 | return _zend_jit_hybrid_hot_counter_stub(jit, |
2379 | 0 | ((ZEND_JIT_COUNTER_INIT + JIT_G(hot_func) - 1) / JIT_G(hot_func))); |
2380 | 0 | } |
2381 | | |
2382 | | static int zend_jit_hybrid_loop_hot_counter_stub(zend_jit_ctx *jit) |
2383 | 0 | { |
2384 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_HYBRID || !JIT_G(hot_loop)) { |
2385 | 0 | return 0; |
2386 | 0 | } |
2387 | | |
2388 | 0 | return _zend_jit_hybrid_hot_counter_stub(jit, |
2389 | 0 | ((ZEND_JIT_COUNTER_INIT + JIT_G(hot_loop) - 1) / JIT_G(hot_loop))); |
2390 | 0 | } |
2391 | | |
2392 | | static ir_ref _zend_jit_orig_opline_handler(zend_jit_ctx *jit, ir_ref offset) |
2393 | 0 | { |
2394 | 0 | ir_ref addr = ir_ADD_A(offset, jit_IP(jit)); |
2395 | |
|
2396 | 0 | return ir_LOAD_A(addr); |
2397 | 0 | } |
2398 | | |
2399 | | static ir_ref zend_jit_orig_opline_handler(zend_jit_ctx *jit) |
2400 | 0 | { |
2401 | 0 | ir_ref func, jit_extension, offset; |
2402 | |
|
2403 | 0 | func = ir_LOAD_A(jit_EX(func)); |
2404 | 0 | jit_extension = ir_LOAD_A(ir_ADD_OFFSET(func, offsetof(zend_op_array, reserved[zend_func_info_rid]))); |
2405 | 0 | offset = ir_LOAD_A(ir_ADD_OFFSET(jit_extension, offsetof(zend_jit_op_array_trace_extension, offset))); |
2406 | 0 | return _zend_jit_orig_opline_handler(jit, offset); |
2407 | 0 | } |
2408 | | |
2409 | | static int _zend_jit_hybrid_trace_counter_stub(zend_jit_ctx *jit, uint32_t cost) |
2410 | 0 | { |
2411 | 0 | ir_ref func, jit_extension, offset, addr, ref, if_overflow, ret, if_halt; |
2412 | 0 |
|
2413 | 0 | func = ir_LOAD_A(jit_EX(func)); |
2414 | 0 | jit_extension = ir_LOAD_A(ir_ADD_OFFSET(func, offsetof(zend_op_array, reserved[zend_func_info_rid]))); |
2415 | 0 | offset = ir_LOAD_A(ir_ADD_OFFSET(jit_extension, offsetof(zend_jit_op_array_trace_extension, offset))); |
2416 | 0 | addr = ir_LOAD_A(ir_ADD_OFFSET(ir_ADD_A(offset, jit_IP(jit)), offsetof(zend_op_trace_info, counter))); |
2417 | 0 | ref = ir_SUB_I16(ir_LOAD_I16(addr), ir_CONST_I16(cost)); |
2418 | 0 | ir_STORE(addr, ref); |
2419 | 0 | if_overflow = ir_IF(ir_LE(ref, ir_CONST_I16(0))); |
2420 | 0 |
|
2421 | 0 | ir_IF_TRUE_cold(if_overflow); |
2422 | 0 | ir_STORE(addr, ir_CONST_I16(ZEND_JIT_COUNTER_INIT)); |
2423 | 0 | ret = ir_CALL_2(IR_I32, ir_CONST_FC_FUNC(zend_jit_trace_hot_root), |
2424 | 0 | jit_FP(jit), |
2425 | 0 | jit_IP(jit)); |
2426 | 0 | if_halt = ir_IF(ir_LT(ret, ir_CONST_I32(0))); |
2427 | 0 | ir_IF_FALSE(if_halt); |
2428 | 0 |
|
2429 | 0 | ref = jit_EG(current_execute_data); |
2430 | 0 | jit_STORE_FP(jit, ir_LOAD_A(ref)); |
2431 | 0 | ref = ir_LOAD_A(jit_EX(opline)); |
2432 | 0 | jit_STORE_IP(jit, ref); |
2433 | 0 | ir_IJMP(ir_LOAD_A(jit_IP(jit))); |
2434 | 0 |
|
2435 | 0 | ir_IF_FALSE(if_overflow); |
2436 | 0 | ir_IJMP(_zend_jit_orig_opline_handler(jit, offset)); |
2437 | 0 |
|
2438 | 0 | ir_IF_TRUE(if_halt); |
2439 | 0 | ir_IJMP(ir_CONST_OPCODE_HANDLER_FUNC(zend_jit_halt_op->handler)); |
2440 | 0 |
|
2441 | 0 | return 1; |
2442 | 0 | } |
2443 | | |
2444 | | static int zend_jit_hybrid_func_trace_counter_stub(zend_jit_ctx *jit) |
2445 | 0 | { |
2446 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_HYBRID || !JIT_G(hot_func)) { |
2447 | 0 | return 0; |
2448 | 0 | } |
2449 | | |
2450 | 0 | return _zend_jit_hybrid_trace_counter_stub(jit, |
2451 | 0 | ((ZEND_JIT_COUNTER_INIT + JIT_G(hot_func) - 1) / JIT_G(hot_func))); |
2452 | 0 | } |
2453 | | |
2454 | | static int zend_jit_hybrid_ret_trace_counter_stub(zend_jit_ctx *jit) |
2455 | 0 | { |
2456 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_HYBRID || !JIT_G(hot_return)) { |
2457 | 0 | return 0; |
2458 | 0 | } |
2459 | | |
2460 | 0 | return _zend_jit_hybrid_trace_counter_stub(jit, |
2461 | 0 | ((ZEND_JIT_COUNTER_INIT + JIT_G(hot_return) - 1) / JIT_G(hot_return))); |
2462 | 0 | } |
2463 | | |
2464 | | static int zend_jit_hybrid_loop_trace_counter_stub(zend_jit_ctx *jit) |
2465 | 0 | { |
2466 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_HYBRID || !JIT_G(hot_loop)) { |
2467 | 0 | return 0; |
2468 | 0 | } |
2469 | | |
2470 | 0 | return _zend_jit_hybrid_trace_counter_stub(jit, |
2471 | 0 | ((ZEND_JIT_COUNTER_INIT + JIT_G(hot_loop) - 1) / JIT_G(hot_loop))); |
2472 | 0 | } |
2473 | | |
2474 | | static int zend_jit_trace_halt_stub(zend_jit_ctx *jit) |
2475 | 0 | { |
2476 | 0 | if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) { |
2477 | 0 | ir_TAILCALL(IR_VOID, ir_CONST_OPCODE_HANDLER_FUNC(zend_jit_halt_op->handler)); |
2478 | 0 | } else if (GCC_GLOBAL_REGS) { |
2479 | 0 | jit_STORE_IP(jit, IR_NULL); |
2480 | 0 | ir_RETURN(IR_VOID); |
2481 | 0 | } else { |
2482 | 0 | ir_RETURN(ir_CONST_ADDR(ZEND_VM_ENTER_BIT)); // ZEND_VM_RETURN |
2483 | 0 | } |
2484 | 0 | return 1; |
2485 | 0 | } |
2486 | | |
2487 | | static int zend_jit_trace_escape_stub(zend_jit_ctx *jit) |
2488 | 0 | { |
2489 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
2490 | 0 | zend_jit_tailcall_handler(jit, ir_LOAD_A(jit_IP(jit))); |
2491 | 0 | } else { |
2492 | 0 | zend_jit_vm_enter(jit, jit_IP(jit)); |
2493 | 0 | } |
2494 | |
|
2495 | 0 | return 1; |
2496 | 0 | } |
2497 | | |
2498 | | static int zend_jit_trace_exit_stub(zend_jit_ctx *jit) |
2499 | 0 | { |
2500 | 0 | ir_ref ref, ret, if_zero, addr; |
2501 | | |
2502 | | // EX(opline) = opline |
2503 | 0 | ir_STORE(jit_EX(opline), jit_IP(jit)); |
2504 | |
|
2505 | 0 | ret = ir_EXITCALL(ir_CONST_FC_FUNC(zend_jit_trace_exit)); |
2506 | |
|
2507 | 0 | if_zero = ir_IF(ir_EQ(ret, ir_CONST_I32(0))); |
2508 | |
|
2509 | 0 | ir_IF_TRUE(if_zero); |
2510 | |
|
2511 | 0 | ref = jit_EG(current_execute_data); |
2512 | 0 | jit_STORE_FP(jit, ir_LOAD_A(ref)); |
2513 | 0 | ref = ir_LOAD_A(jit_EX(opline)); |
2514 | 0 | jit_STORE_IP(jit, ref); |
2515 | |
|
2516 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
2517 | 0 | zend_jit_tailcall_handler(jit, ir_LOAD_A(jit_IP(jit))); |
2518 | 0 | } else { |
2519 | 0 | zend_jit_vm_enter(jit, ref); |
2520 | 0 | } |
2521 | |
|
2522 | 0 | ir_IF_FALSE(if_zero); |
2523 | |
|
2524 | 0 | ir_GUARD(ir_GE(ret, ir_CONST_I32(0)), jit_STUB_ADDR(jit, jit_stub_trace_halt)); |
2525 | |
|
2526 | 0 | ref = jit_EG(current_execute_data); |
2527 | 0 | jit_STORE_FP(jit, ir_LOAD_A(ref)); |
2528 | |
|
2529 | 0 | ref = ir_LOAD_A(jit_EX(opline)); |
2530 | 0 | jit_STORE_IP(jit, ref); |
2531 | | |
2532 | | // check for interrupt (try to avoid this ???) |
2533 | 0 | zend_jit_check_timeout(jit, NULL, NULL); |
2534 | |
|
2535 | 0 | addr = zend_jit_orig_opline_handler(jit); |
2536 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
2537 | 0 | zend_jit_tailcall_handler(jit, addr); |
2538 | 0 | } else { |
2539 | | #if defined(IR_TARGET_X86) |
2540 | | addr = ir_CAST_OPCODE_HANDLER_FUNC(addr); |
2541 | | #endif |
2542 | 0 | ref = ir_CALL_2(IR_ADDR, addr, jit_FP(jit), jit_IP(jit)); |
2543 | 0 | zend_jit_vm_enter(jit, ref); |
2544 | 0 | } |
2545 | |
|
2546 | 0 | return 1; |
2547 | 0 | } |
2548 | | |
2549 | | static int zend_jit_undefined_offset_stub(zend_jit_ctx *jit) |
2550 | 0 | { |
2551 | 0 | if (GCC_GLOBAL_REGS) { |
2552 | 0 | ir_TAILCALL(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_long_key)); |
2553 | 0 | } else { |
2554 | 0 | ir_TAILCALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_long_key), jit_FP(jit)); |
2555 | 0 | } |
2556 | |
|
2557 | 0 | return 1; |
2558 | 0 | } |
2559 | | |
2560 | | static int zend_jit_undefined_key_stub(zend_jit_ctx *jit) |
2561 | 0 | { |
2562 | 0 | if (GCC_GLOBAL_REGS) { |
2563 | 0 | ir_TAILCALL(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_string_key)); |
2564 | 0 | } else { |
2565 | 0 | ir_TAILCALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_string_key), jit_FP(jit)); |
2566 | 0 | } |
2567 | |
|
2568 | 0 | return 1; |
2569 | 0 | } |
2570 | | |
2571 | | static int zend_jit_cannot_add_element_stub(zend_jit_ctx *jit) |
2572 | 0 | { |
2573 | 0 | ir_ref opline = ir_LOAD_A(jit_EX(opline)); |
2574 | 0 | ir_ref ref, if_result_used; |
2575 | |
|
2576 | 0 | if_result_used = ir_IF(ir_AND_U8( |
2577 | 0 | ir_LOAD_U8(ir_ADD_OFFSET(opline, offsetof(zend_op, result_type))), |
2578 | 0 | ir_CONST_U8(IS_TMP_VAR|IS_VAR))); |
2579 | 0 | ir_IF_TRUE(if_result_used); |
2580 | |
|
2581 | 0 | ref = ir_LOAD_U32(ir_ADD_OFFSET(opline, offsetof(zend_op, result.var))); |
2582 | 0 | if (sizeof(void*) == 8) { |
2583 | 0 | ref = ir_ZEXT_A(ref); |
2584 | 0 | } |
2585 | 0 | jit_set_Z_TYPE_INFO_ref(jit, ir_ADD_A(jit_FP(jit), ref), ir_CONST_U32(IS_UNDEF)); |
2586 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_result_used); |
2587 | |
|
2588 | 0 | ir_CALL_2(IR_VOID, |
2589 | 0 | ir_CONST_FUNC_PROTO(zend_throw_error, |
2590 | 0 | ir_proto_2(&jit->ctx, IR_VARARG_FUNC, IR_VOID, IR_ADDR, IR_ADDR)), |
2591 | 0 | IR_NULL, |
2592 | 0 | ir_CONST_ADDR("Cannot add element to the array as the next element is already occupied")); |
2593 | 0 | ir_RETURN(IR_VOID); |
2594 | |
|
2595 | 0 | return 1; |
2596 | 0 | } |
2597 | | |
2598 | | static int zend_jit_assign_const_stub(zend_jit_ctx *jit) |
2599 | 0 | { |
2600 | 0 | ir_ref var = ir_PARAM(IR_ADDR, "var", 1); |
2601 | 0 | ir_ref val = ir_PARAM(IR_ADDR, "val", 2); |
2602 | |
|
2603 | 0 | zend_jit_addr var_addr = ZEND_ADDR_REF_ZVAL(var); |
2604 | 0 | zend_jit_addr val_addr = ZEND_ADDR_REF_ZVAL(val); |
2605 | 0 | uint32_t val_info = MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN; |
2606 | |
|
2607 | 0 | if (!zend_jit_assign_to_variable( |
2608 | 0 | jit, NULL, |
2609 | 0 | var_addr, var_addr, -1, -1, |
2610 | 0 | IS_CONST, val_addr, val_info, |
2611 | 0 | 0, 0, false)) { |
2612 | 0 | return 0; |
2613 | 0 | } |
2614 | 0 | ir_RETURN(IR_VOID); |
2615 | 0 | return 1; |
2616 | 0 | } |
2617 | | |
2618 | | static int zend_jit_assign_tmp_stub(zend_jit_ctx *jit) |
2619 | 0 | { |
2620 | 0 | ir_ref var = ir_PARAM(IR_ADDR, "var", 1); |
2621 | 0 | ir_ref val = ir_PARAM(IR_ADDR, "val", 2); |
2622 | |
|
2623 | 0 | zend_jit_addr var_addr = ZEND_ADDR_REF_ZVAL(var); |
2624 | 0 | zend_jit_addr val_addr = ZEND_ADDR_REF_ZVAL(val); |
2625 | 0 | uint32_t val_info = MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN; |
2626 | |
|
2627 | 0 | if (!zend_jit_assign_to_variable( |
2628 | 0 | jit, NULL, |
2629 | 0 | var_addr, var_addr, -1, -1, |
2630 | 0 | IS_TMP_VAR, val_addr, val_info, |
2631 | 0 | 0, 0, false)) { |
2632 | 0 | return 0; |
2633 | 0 | } |
2634 | 0 | ir_RETURN(IR_VOID); |
2635 | 0 | return 1; |
2636 | 0 | } |
2637 | | |
2638 | | static int zend_jit_assign_var_stub(zend_jit_ctx *jit) |
2639 | 0 | { |
2640 | 0 | ir_ref var = ir_PARAM(IR_ADDR, "var", 1); |
2641 | 0 | ir_ref val = ir_PARAM(IR_ADDR, "val", 2); |
2642 | |
|
2643 | 0 | zend_jit_addr var_addr = ZEND_ADDR_REF_ZVAL(var); |
2644 | 0 | zend_jit_addr val_addr = ZEND_ADDR_REF_ZVAL(val); |
2645 | 0 | uint32_t val_info = MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN|MAY_BE_REF; |
2646 | |
|
2647 | 0 | if (!zend_jit_assign_to_variable( |
2648 | 0 | jit, NULL, |
2649 | 0 | var_addr, var_addr, -1, -1, |
2650 | 0 | IS_VAR, val_addr, val_info, |
2651 | 0 | 0, 0, false)) { |
2652 | 0 | return 0; |
2653 | 0 | } |
2654 | 0 | ir_RETURN(IR_VOID); |
2655 | 0 | return 1; |
2656 | 0 | } |
2657 | | |
2658 | | static int zend_jit_assign_cv_noref_stub(zend_jit_ctx *jit) |
2659 | 0 | { |
2660 | 0 | ir_ref var = ir_PARAM(IR_ADDR, "var", 1); |
2661 | 0 | ir_ref val = ir_PARAM(IR_ADDR, "val", 2); |
2662 | |
|
2663 | 0 | zend_jit_addr var_addr = ZEND_ADDR_REF_ZVAL(var); |
2664 | 0 | zend_jit_addr val_addr = ZEND_ADDR_REF_ZVAL(val); |
2665 | 0 | uint32_t val_info = MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN/*|MAY_BE_UNDEF*/; |
2666 | |
|
2667 | 0 | if (!zend_jit_assign_to_variable( |
2668 | 0 | jit, NULL, |
2669 | 0 | var_addr, var_addr, -1, -1, |
2670 | 0 | IS_CV, val_addr, val_info, |
2671 | 0 | 0, 0, false)) { |
2672 | 0 | return 0; |
2673 | 0 | } |
2674 | 0 | ir_RETURN(IR_VOID); |
2675 | 0 | return 1; |
2676 | 0 | } |
2677 | | |
2678 | | static int zend_jit_new_array_stub(zend_jit_ctx *jit) |
2679 | 0 | { |
2680 | 0 | ir_ref var = ir_PARAM(IR_ADDR, "var", 1); |
2681 | 0 | zend_jit_addr var_addr = ZEND_ADDR_REF_ZVAL(var); |
2682 | 0 | ir_ref ref = ir_CALL(IR_ADDR, ir_CONST_FC_FUNC(_zend_new_array_0)); |
2683 | |
|
2684 | 0 | jit_set_Z_PTR(jit, var_addr, ref); |
2685 | 0 | jit_set_Z_TYPE_INFO(jit, var_addr, IS_ARRAY_EX); |
2686 | 0 | ir_RETURN(ref); |
2687 | 0 | return 1; |
2688 | 0 | } |
2689 | | |
2690 | | static int zend_jit_assign_cv_stub(zend_jit_ctx *jit) |
2691 | 0 | { |
2692 | 0 | ir_ref var = ir_PARAM(IR_ADDR, "var", 1); |
2693 | 0 | ir_ref val = ir_PARAM(IR_ADDR, "val", 2); |
2694 | |
|
2695 | 0 | zend_jit_addr var_addr = ZEND_ADDR_REF_ZVAL(var); |
2696 | 0 | zend_jit_addr val_addr = ZEND_ADDR_REF_ZVAL(val); |
2697 | 0 | uint32_t val_info = MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN|MAY_BE_REF/*|MAY_BE_UNDEF*/; |
2698 | |
|
2699 | 0 | if (!zend_jit_assign_to_variable( |
2700 | 0 | jit, NULL, |
2701 | 0 | var_addr, var_addr, -1, -1, |
2702 | 0 | IS_CV, val_addr, val_info, |
2703 | 0 | 0, 0, false)) { |
2704 | 0 | return 0; |
2705 | 0 | } |
2706 | 0 | ir_RETURN(IR_VOID); |
2707 | 0 | return 1; |
2708 | 0 | } |
2709 | | |
2710 | | static void zend_jit_init_ctx(zend_jit_ctx *jit, uint32_t flags) |
2711 | 0 | { |
2712 | | #if defined (__CET__) && (__CET__ & 1) != 0 |
2713 | | flags |= IR_GEN_ENDBR; |
2714 | | #endif |
2715 | 0 | flags |= IR_OPT_FOLDING | IR_OPT_CFG | IR_OPT_CODEGEN; |
2716 | |
|
2717 | 0 | ir_init(&jit->ctx, flags, 256, 1024); |
2718 | 0 | jit->ctx.ret_type = -1; |
2719 | |
|
2720 | 0 | #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) |
2721 | 0 | jit->ctx.mflags |= default_mflags; |
2722 | 0 | if (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) { |
2723 | 0 | jit->ctx.mflags |= IR_X86_AVX; |
2724 | 0 | } |
2725 | | #elif defined(IR_TARGET_AARCH64) |
2726 | | jit->ctx.get_veneer = zend_jit_get_veneer; |
2727 | | jit->ctx.set_veneer = zend_jit_set_veneer; |
2728 | | #endif |
2729 | |
|
2730 | 0 | jit->ctx.fixed_regset = (1<<ZREG_FP) | (1<<ZREG_IP); |
2731 | 0 | if (!(flags & IR_FUNCTION)) { |
2732 | 0 | jit->ctx.flags |= IR_NO_STACK_COMBINE; |
2733 | 0 | if (ZEND_VM_KIND == ZEND_VM_KIND_CALL || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
2734 | 0 | jit->ctx.flags |= IR_FUNCTION; |
2735 | | /* Stack must be 16 byte aligned */ |
2736 | | /* TODO: select stack size ??? */ |
2737 | 0 | #if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL |
2738 | | # if defined(IR_TARGET_AARCH64) |
2739 | | /* Must save LR */ |
2740 | | jit->ctx.flags |= IR_USE_FRAME_POINTER; |
2741 | | /* Same as HYBRID VM */ |
2742 | | jit->ctx.fixed_stack_frame_size = sizeof(void*) * 4; /* 4 spill slots */ |
2743 | | # else |
2744 | | /* Same as HYBRID VM, plus 1 slot for re-alignment (caller pushes return address, frame is not aligned on entry) */ |
2745 | 0 | jit->ctx.fixed_stack_frame_size = sizeof(void*) * 5; /* 5 spill slots (8 bytes) or 10 spill slots (4 bytes) */ |
2746 | 0 | # endif |
2747 | | #elif defined(IR_TARGET_AARCH64) |
2748 | | jit->ctx.flags |= IR_USE_FRAME_POINTER; |
2749 | | jit->ctx.fixed_stack_frame_size = sizeof(void*) * 16; /* 10 saved registers and 6 spill slots (8 bytes) */ |
2750 | | #elif defined(_WIN64) |
2751 | | jit->ctx.fixed_stack_frame_size = sizeof(void*) * 11; /* 8 saved registers and 3 spill slots (8 bytes) */ |
2752 | | #elif defined(IR_TARGET_X86_64) |
2753 | | jit->ctx.fixed_stack_frame_size = sizeof(void*) * 9; /* 6 saved registers and 3 spill slots (8 bytes) */ |
2754 | | #else /* IR_TARGET_x86 */ |
2755 | | jit->ctx.fixed_stack_frame_size = sizeof(void*) * 11; /* 4 saved registers and 7 spill slots (4 bytes) */ |
2756 | | #endif |
2757 | | /* JIT-ed code is called only from execute_ex, which takes care |
2758 | | * of saving ZREG_FP, ZREG_IP when GCC_GLOBAL_REGS is 1, so we don't |
2759 | | * have to save them. |
2760 | | */ |
2761 | 0 | if (GCC_GLOBAL_REGS) { |
2762 | 0 | jit->ctx.fixed_save_regset = IR_REGSET_PRESERVED & ~((1<<ZREG_FP) | (1<<ZREG_IP)); |
2763 | 0 | } else if (ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
2764 | | /* The only preserved register on x86 is RBP: |
2765 | | * https://github.com/llvm/llvm-project/blob/a414877a7a5f000d01370acb1162eb1dea87f48c/llvm/lib/Target/X86/X86RegisterInfo.cpp#L319 |
2766 | | * https://github.com/llvm/llvm-project/blob/68bfe91b5a34f80dbcc4f0a7fa5d7aa1cdf959c2/llvm/lib/Target/X86/X86CallingConv.td#L1183 |
2767 | | * On AArch64 it's LR, FP: |
2768 | | * https://github.com/llvm/llvm-project/blob/68bfe91b5a34f80dbcc4f0a7fa5d7aa1cdf959c2/llvm/lib/Target/AArch64/AArch64CallingConvention.td#L681 |
2769 | | * |
2770 | | * Add them to the fixed_regset to prevent usage or these regs. |
2771 | | * It's cheaper to not use them than to save them. |
2772 | | */ |
2773 | 0 | #if defined(IR_TARGET_X64) |
2774 | 0 | jit->ctx.fixed_regset |= (1<<IR_REG_FP); |
2775 | | #elif defined(IR_TARGET_AARCH64) |
2776 | | jit->ctx.fixed_regset |= (1<<IR_REG_FP) | (1<<IR_REG_LR); |
2777 | | #else |
2778 | | ZEND_UNREACHABLE(); |
2779 | | #endif |
2780 | 0 | } else { |
2781 | 0 | jit->ctx.fixed_save_regset = IR_REGSET_PRESERVED; |
2782 | | //#ifdef _WIN64 |
2783 | | // jit->ctx.fixed_save_regset &= 0xffff; // TODO: don't save FP registers ??? |
2784 | | //#endif |
2785 | 0 | } |
2786 | | #ifdef _WIN64 |
2787 | | jit->ctx.fixed_call_stack_size = 16 + IR_SHADOW_ARGS; |
2788 | | #else |
2789 | 0 | jit->ctx.fixed_call_stack_size = 16; |
2790 | 0 | #endif |
2791 | 0 | } else { |
2792 | | #ifdef ZEND_VM_HYBRID_JIT_RED_ZONE_SIZE |
2793 | | jit->ctx.fixed_stack_red_zone = ZEND_VM_HYBRID_JIT_RED_ZONE_SIZE; |
2794 | | if (jit->ctx.fixed_stack_red_zone > 16) { |
2795 | | jit->ctx.fixed_stack_frame_size = jit->ctx.fixed_stack_red_zone - 16; |
2796 | | jit->ctx.fixed_call_stack_size = 16; |
2797 | | } |
2798 | | jit->ctx.flags |= IR_MERGE_EMPTY_ENTRIES; |
2799 | | #else |
2800 | 0 | jit->ctx.fixed_stack_red_zone = 0; |
2801 | 0 | jit->ctx.fixed_stack_frame_size = 32; /* 4 spill slots (8 bytes) or 8 spill slots (4 bytes) */ |
2802 | 0 | jit->ctx.fixed_call_stack_size = 16; |
2803 | 0 | #endif |
2804 | 0 | #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) |
2805 | 0 | jit->ctx.fixed_regset |= (1<<IR_REG_FP); /* prevent %rbp (%r5) usage */ |
2806 | 0 | #endif |
2807 | 0 | } |
2808 | 0 | } |
2809 | |
|
2810 | 0 | jit->ctx.snapshot_create = (ir_snapshot_create_t)jit_SNAPSHOT; |
2811 | |
|
2812 | 0 | jit->op_array = NULL; |
2813 | 0 | jit->current_op_array = NULL; |
2814 | 0 | jit->ssa = NULL; |
2815 | 0 | jit->name = NULL; |
2816 | 0 | jit->last_valid_opline = NULL; |
2817 | 0 | jit->use_last_valid_opline = false; |
2818 | 0 | jit->track_last_valid_opline = false; |
2819 | 0 | jit->reuse_ip = false; |
2820 | 0 | jit->delayed_call_level = 0; |
2821 | 0 | delayed_call_chain = false; |
2822 | 0 | jit->b = -1; |
2823 | | #ifdef ZTS |
2824 | | jit->tls = IR_UNUSED; |
2825 | | #endif |
2826 | 0 | jit->fp = IR_UNUSED; |
2827 | 0 | jit->poly_func_ref = IR_UNUSED; |
2828 | 0 | jit->poly_this_ref = IR_UNUSED; |
2829 | 0 | jit->trace_loop_ref = IR_UNUSED; |
2830 | 0 | jit->return_inputs = IR_UNUSED; |
2831 | 0 | jit->bb_start_ref = NULL; |
2832 | 0 | jit->bb_predecessors = NULL; |
2833 | 0 | jit->bb_edges = NULL; |
2834 | 0 | jit->trace = NULL; |
2835 | 0 | jit->ra = NULL; |
2836 | 0 | jit->delay_var = -1; |
2837 | 0 | jit->delay_refs = NULL; |
2838 | 0 | jit->eg_exception_addr = 0; |
2839 | 0 | zend_hash_init(&jit->addr_hash, 64, NULL, NULL, 0); |
2840 | 0 | memset(jit->stub_addr, 0, sizeof(jit->stub_addr)); |
2841 | |
|
2842 | 0 | ir_START(); |
2843 | 0 | } |
2844 | | |
2845 | | static int zend_jit_free_ctx(zend_jit_ctx *jit) |
2846 | 0 | { |
2847 | 0 | if (jit->name) { |
2848 | 0 | zend_string_release(jit->name); |
2849 | 0 | } |
2850 | 0 | zend_hash_destroy(&jit->addr_hash); |
2851 | 0 | ir_free(&jit->ctx); |
2852 | 0 | return 1; |
2853 | 0 | } |
2854 | | |
2855 | | static void *zend_jit_ir_compile(ir_ctx *ctx, size_t *size, const char *name) |
2856 | 0 | { |
2857 | 0 | void *entry; |
2858 | 0 | ir_code_buffer code_buffer; |
2859 | |
|
2860 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_IR_SRC) { |
2861 | 0 | if (name) fprintf(stderr, "%s: ; after folding\n", name); |
2862 | 0 | ir_save(ctx, 0, stderr); |
2863 | 0 | } |
2864 | |
|
2865 | 0 | #if ZEND_DEBUG |
2866 | 0 | ir_check(ctx); |
2867 | 0 | #endif |
2868 | |
|
2869 | 0 | ir_build_def_use_lists(ctx); |
2870 | |
|
2871 | 0 | #if ZEND_DEBUG |
2872 | 0 | ir_check(ctx); |
2873 | 0 | #endif |
2874 | |
|
2875 | 0 | #if 1 |
2876 | 0 | ir_sccp(ctx); |
2877 | 0 | #endif |
2878 | |
|
2879 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_IR_AFTER_SCCP) { |
2880 | 0 | if (name) fprintf(stderr, "%s: ; after SCCP\n", name); |
2881 | 0 | ir_save(ctx, 0, stderr); |
2882 | 0 | } |
2883 | |
|
2884 | 0 | ir_build_cfg(ctx); |
2885 | 0 | ir_build_dominators_tree(ctx); |
2886 | 0 | ir_find_loops(ctx); |
2887 | |
|
2888 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_IR_AFTER_CFG) { |
2889 | 0 | if (name) fprintf(stderr, "%s: ; after CFG\n", name); |
2890 | 0 | ir_save(ctx, IR_SAVE_CFG, stderr); |
2891 | 0 | } |
2892 | |
|
2893 | 0 | ir_gcm(ctx); |
2894 | |
|
2895 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_IR_AFTER_GCM) { |
2896 | 0 | if (name) fprintf(stderr, "%s: ; after GCM\n", name); |
2897 | 0 | ir_save(ctx, IR_SAVE_CFG|IR_SAVE_CFG_MAP, stderr); |
2898 | 0 | } |
2899 | |
|
2900 | 0 | ir_schedule(ctx); |
2901 | |
|
2902 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_IR_AFTER_SCHEDULE) { |
2903 | 0 | if (name) fprintf(stderr, "%s: ; after schedule\n", name); |
2904 | 0 | ir_save(ctx, IR_SAVE_CFG, stderr); |
2905 | 0 | } |
2906 | |
|
2907 | 0 | ir_match(ctx); |
2908 | 0 | #if !defined(IR_TARGET_AARCH64) |
2909 | 0 | ctx->flags &= ~IR_USE_FRAME_POINTER; /* don't use FRAME_POINTER even with ALLOCA, TODO: cleanup this ??? */ |
2910 | 0 | #endif |
2911 | 0 | ir_assign_virtual_registers(ctx); |
2912 | 0 | ir_compute_live_ranges(ctx); |
2913 | 0 | ir_coalesce(ctx); |
2914 | 0 | ir_reg_alloc(ctx); |
2915 | |
|
2916 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_IR_AFTER_REGS) { |
2917 | 0 | if (name) fprintf(stderr, "%s: ; after register allocation\n", name); |
2918 | 0 | ir_save(ctx, IR_SAVE_CFG|IR_SAVE_RULES|IR_SAVE_REGS, stderr); |
2919 | 0 | ir_dump_live_ranges(ctx, stderr); |
2920 | 0 | } |
2921 | |
|
2922 | 0 | ir_schedule_blocks(ctx); |
2923 | |
|
2924 | 0 | if (JIT_G(debug) & (ZEND_JIT_DEBUG_IR_FINAL|ZEND_JIT_DEBUG_IR_CODEGEN)) { |
2925 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_IR_CODEGEN) { |
2926 | 0 | if (name) fprintf(stderr, "%s: ; codegen\n", name); |
2927 | 0 | ir_dump_codegen(ctx, stderr); |
2928 | 0 | } else { |
2929 | 0 | if (name) fprintf(stderr, "%s: ; final\n", name); |
2930 | 0 | ir_save(ctx, IR_SAVE_CFG|IR_SAVE_RULES|IR_SAVE_REGS, stderr); |
2931 | 0 | } |
2932 | 0 | } |
2933 | |
|
2934 | 0 | #if ZEND_DEBUG |
2935 | 0 | ir_check(ctx); |
2936 | 0 | #endif |
2937 | |
|
2938 | 0 | code_buffer.start = dasm_buf; |
2939 | 0 | code_buffer.end = dasm_end; |
2940 | 0 | code_buffer.pos = *dasm_ptr; |
2941 | 0 | ctx->code_buffer = &code_buffer; |
2942 | |
|
2943 | 0 | entry = ir_emit_code(ctx, size); |
2944 | |
|
2945 | 0 | *dasm_ptr = code_buffer.pos; |
2946 | |
|
2947 | | #if defined(IR_TARGET_AARCH64) |
2948 | | if (ctx->flags2 & IR_HAS_VENEERS) { |
2949 | | zend_jit_commit_veneers(); |
2950 | | } |
2951 | | #endif |
2952 | |
|
2953 | 0 | return entry; |
2954 | 0 | } |
2955 | | |
2956 | | static void zend_jit_setup_stubs(void) |
2957 | 0 | { |
2958 | 0 | zend_jit_ctx jit; |
2959 | 0 | void *entry; |
2960 | 0 | size_t size; |
2961 | 0 | uint32_t i; |
2962 | |
|
2963 | 0 | for (i = 0; i < sizeof(zend_jit_stubs)/sizeof(zend_jit_stubs[0]); i++) { |
2964 | 0 | zend_jit_init_ctx(&jit, zend_jit_stubs[i].flags); |
2965 | |
|
2966 | 0 | if (!zend_jit_stubs[i].stub(&jit)) { |
2967 | 0 | zend_jit_free_ctx(&jit); |
2968 | 0 | zend_jit_stub_handlers[i] = NULL; |
2969 | 0 | continue; |
2970 | 0 | } |
2971 | | |
2972 | 0 | entry = zend_jit_ir_compile(&jit.ctx, &size, zend_jit_stubs[i].name); |
2973 | 0 | if (!entry) { |
2974 | 0 | zend_jit_free_ctx(&jit); |
2975 | 0 | zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not compile stub"); |
2976 | 0 | } |
2977 | | |
2978 | 0 | zend_jit_stub_handlers[i] = entry; |
2979 | |
|
2980 | 0 | if (JIT_G(debug) & (ZEND_JIT_DEBUG_ASM|ZEND_JIT_DEBUG_ASM_STUBS|ZEND_JIT_DEBUG_GDB|ZEND_JIT_DEBUG_PERF|ZEND_JIT_DEBUG_PERF_DUMP)) { |
2981 | | #ifdef HAVE_CAPSTONE |
2982 | | if (JIT_G(debug) & (ZEND_JIT_DEBUG_ASM|ZEND_JIT_DEBUG_ASM_STUBS)) { |
2983 | | ir_disasm_add_symbol(zend_jit_stubs[i].name, (uintptr_t)entry, size); |
2984 | | } |
2985 | | if (JIT_G(debug) & ZEND_JIT_DEBUG_ASM_STUBS) { |
2986 | | ir_disasm(zend_jit_stubs[i].name, |
2987 | | entry, size, (JIT_G(debug) & ZEND_JIT_DEBUG_ASM_ADDR) != 0, &jit.ctx, stderr); |
2988 | | } |
2989 | | #endif |
2990 | 0 | #ifndef _WIN32 |
2991 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_GDB) { |
2992 | | // ir_mem_unprotect(entry, size); |
2993 | 0 | ir_gdb_register(zend_jit_stubs[i].name, entry, size, 0, 0); |
2994 | | // ir_mem_protect(entry, size); |
2995 | 0 | } |
2996 | |
|
2997 | 0 | if (JIT_G(debug) & (ZEND_JIT_DEBUG_PERF|ZEND_JIT_DEBUG_PERF_DUMP)) { |
2998 | 0 | ir_perf_map_register(zend_jit_stubs[i].name, entry, size); |
2999 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_PERF_DUMP) { |
3000 | 0 | ir_perf_jitdump_register(zend_jit_stubs[i].name, entry, size); |
3001 | 0 | } |
3002 | 0 | } |
3003 | 0 | #endif |
3004 | 0 | } |
3005 | 0 | zend_jit_free_ctx(&jit); |
3006 | 0 | } |
3007 | 0 | } |
3008 | | |
3009 | | #define REGISTER_HELPER(n) \ |
3010 | | ir_disasm_add_symbol(#n, (uint64_t)(uintptr_t)n, sizeof(void*)); |
3011 | | #define REGISTER_DATA(n) \ |
3012 | | ir_disasm_add_symbol(#n, (uint64_t)(uintptr_t)&n, sizeof(n)); |
3013 | | |
3014 | | static void zend_jit_setup_disasm(void) |
3015 | 0 | { |
3016 | | #ifdef HAVE_CAPSTONE |
3017 | | ir_disasm_init(); |
3018 | | |
3019 | | if (zend_vm_kind() == ZEND_VM_KIND_HYBRID) { |
3020 | | zend_op opline; |
3021 | | |
3022 | | memset(&opline, 0, sizeof(opline)); |
3023 | | |
3024 | | opline.opcode = ZEND_DO_UCALL; |
3025 | | opline.result_type = IS_UNUSED; |
3026 | | zend_vm_set_opcode_handler(&opline); |
3027 | | ir_disasm_add_symbol("ZEND_DO_UCALL_SPEC_RETVAL_UNUSED_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3028 | | |
3029 | | opline.opcode = ZEND_DO_UCALL; |
3030 | | opline.result_type = IS_VAR; |
3031 | | zend_vm_set_opcode_handler(&opline); |
3032 | | ir_disasm_add_symbol("ZEND_DO_UCALL_SPEC_RETVAL_USED_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3033 | | |
3034 | | opline.opcode = ZEND_DO_FCALL_BY_NAME; |
3035 | | opline.result_type = IS_UNUSED; |
3036 | | zend_vm_set_opcode_handler(&opline); |
3037 | | ir_disasm_add_symbol("ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_UNUSED_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3038 | | |
3039 | | opline.opcode = ZEND_DO_FCALL_BY_NAME; |
3040 | | opline.result_type = IS_VAR; |
3041 | | zend_vm_set_opcode_handler(&opline); |
3042 | | ir_disasm_add_symbol("ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3043 | | |
3044 | | opline.opcode = ZEND_DO_FCALL; |
3045 | | opline.result_type = IS_UNUSED; |
3046 | | zend_vm_set_opcode_handler(&opline); |
3047 | | ir_disasm_add_symbol("ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3048 | | |
3049 | | opline.opcode = ZEND_DO_FCALL; |
3050 | | opline.result_type = IS_VAR; |
3051 | | zend_vm_set_opcode_handler(&opline); |
3052 | | ir_disasm_add_symbol("ZEND_DO_FCALL_SPEC_RETVAL_USED_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3053 | | |
3054 | | opline.opcode = ZEND_RETURN; |
3055 | | opline.op1_type = IS_CONST; |
3056 | | zend_vm_set_opcode_handler(&opline); |
3057 | | ir_disasm_add_symbol("ZEND_RETURN_SPEC_CONST_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3058 | | |
3059 | | opline.opcode = ZEND_RETURN; |
3060 | | opline.op1_type = IS_TMP_VAR; |
3061 | | zend_vm_set_opcode_handler(&opline); |
3062 | | ir_disasm_add_symbol("ZEND_RETURN_SPEC_TMP_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3063 | | |
3064 | | opline.opcode = ZEND_RETURN; |
3065 | | opline.op1_type = IS_VAR; |
3066 | | zend_vm_set_opcode_handler(&opline); |
3067 | | ir_disasm_add_symbol("ZEND_RETURN_SPEC_VAR_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3068 | | |
3069 | | opline.opcode = ZEND_RETURN; |
3070 | | opline.op1_type = IS_CV; |
3071 | | zend_vm_set_opcode_handler(&opline); |
3072 | | ir_disasm_add_symbol("ZEND_RETURN_SPEC_CV_LABEL", (uint64_t)(uintptr_t)opline.handler, sizeof(void*)); |
3073 | | |
3074 | | ir_disasm_add_symbol("ZEND_HYBRID_HALT_LABEL", (uint64_t)(uintptr_t)zend_jit_halt_op->handler, sizeof(void*)); |
3075 | | } |
3076 | | |
3077 | | REGISTER_DATA(zend_jit_profile_counter); |
3078 | | |
3079 | | REGISTER_HELPER(zend_runtime_jit); |
3080 | | REGISTER_HELPER(zend_jit_hot_func); |
3081 | | REGISTER_HELPER(zend_jit_trace_hot_root); |
3082 | | REGISTER_HELPER(zend_jit_trace_exit); |
3083 | | |
3084 | | REGISTER_HELPER(zend_jit_array_free); |
3085 | | REGISTER_HELPER(zend_jit_undefined_op_helper); |
3086 | | REGISTER_HELPER(zend_jit_pre_inc_typed_ref); |
3087 | | REGISTER_HELPER(zend_jit_pre_dec_typed_ref); |
3088 | | REGISTER_HELPER(zend_jit_post_inc_typed_ref); |
3089 | | REGISTER_HELPER(zend_jit_post_dec_typed_ref); |
3090 | | REGISTER_HELPER(zend_jit_pre_inc); |
3091 | | REGISTER_HELPER(zend_jit_pre_dec); |
3092 | | REGISTER_HELPER(zend_jit_add_arrays_helper); |
3093 | | REGISTER_HELPER(zend_jit_fast_assign_concat_helper); |
3094 | | REGISTER_HELPER(zend_jit_fast_concat_helper); |
3095 | | REGISTER_HELPER(zend_jit_fast_concat_tmp_helper); |
3096 | | REGISTER_HELPER(zend_jit_assign_op_to_typed_ref_tmp); |
3097 | | REGISTER_HELPER(zend_jit_assign_op_to_typed_ref); |
3098 | | REGISTER_HELPER(zend_jit_assign_const_to_typed_ref); |
3099 | | REGISTER_HELPER(zend_jit_assign_tmp_to_typed_ref); |
3100 | | REGISTER_HELPER(zend_jit_assign_var_to_typed_ref); |
3101 | | REGISTER_HELPER(zend_jit_assign_cv_to_typed_ref); |
3102 | | REGISTER_HELPER(zend_jit_assign_const_to_typed_ref2); |
3103 | | REGISTER_HELPER(zend_jit_assign_tmp_to_typed_ref2); |
3104 | | REGISTER_HELPER(zend_jit_assign_var_to_typed_ref2); |
3105 | | REGISTER_HELPER(zend_jit_assign_cv_to_typed_ref2); |
3106 | | REGISTER_HELPER(zend_jit_check_constant); |
3107 | | REGISTER_HELPER(zend_jit_get_constant); |
3108 | | REGISTER_HELPER(zend_jit_int_extend_stack_helper); |
3109 | | REGISTER_HELPER(zend_jit_extend_stack_helper); |
3110 | | REGISTER_HELPER(zend_jit_init_func_run_time_cache_helper); |
3111 | | REGISTER_HELPER(zend_jit_find_func_helper); |
3112 | | REGISTER_HELPER(zend_jit_find_ns_func_helper); |
3113 | | REGISTER_HELPER(zend_jit_jmp_frameless_helper); |
3114 | | REGISTER_HELPER(zend_jit_unref_helper); |
3115 | | REGISTER_HELPER(zend_jit_invalid_method_call); |
3116 | | REGISTER_HELPER(zend_jit_invalid_method_call_tmp); |
3117 | | REGISTER_HELPER(zend_jit_find_method_helper); |
3118 | | REGISTER_HELPER(zend_jit_find_method_tmp_helper); |
3119 | | REGISTER_HELPER(zend_jit_push_static_method_call_frame); |
3120 | | REGISTER_HELPER(zend_jit_push_static_method_call_frame_tmp); |
3121 | | REGISTER_HELPER(zend_jit_find_class_helper); |
3122 | | REGISTER_HELPER(zend_jit_find_static_method_helper); |
3123 | | REGISTER_HELPER(zend_jit_push_this_method_call_frame); |
3124 | | REGISTER_HELPER(zend_jit_free_trampoline_helper); |
3125 | | REGISTER_HELPER(zend_jit_verify_return_slow); |
3126 | | REGISTER_HELPER(zend_jit_deprecated_helper); |
3127 | | REGISTER_HELPER(zend_jit_undefined_long_key); |
3128 | | REGISTER_HELPER(zend_jit_undefined_long_key_ex); |
3129 | | REGISTER_HELPER(zend_jit_undefined_string_key); |
3130 | | REGISTER_HELPER(zend_jit_copy_extra_args_helper); |
3131 | | REGISTER_HELPER(zend_jit_copy_extra_args_helper_no_skip_recv); |
3132 | | REGISTER_HELPER(zend_jit_vm_stack_free_args_helper); |
3133 | | REGISTER_HELPER(zend_free_extra_named_params); |
3134 | | REGISTER_HELPER(zend_jit_free_call_frame); |
3135 | | REGISTER_HELPER(zend_jit_exception_in_interrupt_handler_helper); |
3136 | | REGISTER_HELPER(zend_jit_verify_arg_slow); |
3137 | | REGISTER_HELPER(zend_missing_arg_error); |
3138 | | REGISTER_HELPER(zend_jit_only_vars_by_reference); |
3139 | | REGISTER_HELPER(zend_jit_leave_func_helper); |
3140 | | REGISTER_HELPER(zend_jit_leave_nested_func_helper); |
3141 | | REGISTER_HELPER(zend_jit_leave_top_func_helper); |
3142 | | REGISTER_HELPER(zend_jit_fetch_global_helper); |
3143 | | REGISTER_HELPER(zend_jit_hash_index_lookup_rw_no_packed); |
3144 | | REGISTER_HELPER(zend_jit_hash_index_lookup_rw); |
3145 | | REGISTER_HELPER(zend_jit_hash_lookup_rw); |
3146 | | REGISTER_HELPER(zend_jit_symtable_find); |
3147 | | REGISTER_HELPER(zend_jit_symtable_lookup_w); |
3148 | | REGISTER_HELPER(zend_jit_symtable_lookup_rw); |
3149 | | REGISTER_HELPER(zend_jit_fetch_dim_r_helper); |
3150 | | REGISTER_HELPER(zend_jit_fetch_dim_is_helper); |
3151 | | REGISTER_HELPER(zend_jit_fetch_dim_isset_helper); |
3152 | | REGISTER_HELPER(zend_jit_fetch_dim_rw_helper); |
3153 | | REGISTER_HELPER(zend_jit_fetch_dim_w_helper); |
3154 | | REGISTER_HELPER(zend_jit_fetch_dim_str_offset_r_helper); |
3155 | | REGISTER_HELPER(zend_jit_fetch_dim_str_r_helper); |
3156 | | REGISTER_HELPER(zend_jit_fetch_dim_str_is_helper); |
3157 | | REGISTER_HELPER(zend_jit_fetch_dim_obj_r_helper); |
3158 | | REGISTER_HELPER(zend_jit_fetch_dim_obj_is_helper); |
3159 | | REGISTER_HELPER(zend_jit_invalid_array_access); |
3160 | | REGISTER_HELPER(zend_jit_zval_array_dup); |
3161 | | REGISTER_HELPER(zend_jit_prepare_assign_dim_ref); |
3162 | | REGISTER_HELPER(zend_jit_fetch_dim_obj_w_helper); |
3163 | | REGISTER_HELPER(zend_jit_fetch_dim_obj_rw_helper); |
3164 | | REGISTER_HELPER(zend_jit_isset_dim_helper); |
3165 | | REGISTER_HELPER(zend_jit_assign_dim_helper); |
3166 | | REGISTER_HELPER(zend_jit_assign_dim_op_helper); |
3167 | | REGISTER_HELPER(zend_jit_fetch_obj_w_slow); |
3168 | | REGISTER_HELPER(zend_jit_fetch_obj_r_slow); |
3169 | | REGISTER_HELPER(zend_jit_fetch_obj_r_slow_ex); |
3170 | | REGISTER_HELPER(zend_jit_fetch_obj_is_slow); |
3171 | | REGISTER_HELPER(zend_jit_fetch_obj_is_slow_ex); |
3172 | | REGISTER_HELPER(zend_jit_fetch_obj_r_dynamic); |
3173 | | REGISTER_HELPER(zend_jit_fetch_obj_r_dynamic_ex); |
3174 | | REGISTER_HELPER(zend_jit_fetch_obj_is_dynamic); |
3175 | | REGISTER_HELPER(zend_jit_fetch_obj_is_dynamic_ex); |
3176 | | REGISTER_HELPER(zend_jit_check_array_promotion); |
3177 | | REGISTER_HELPER(zend_jit_create_typed_ref); |
3178 | | REGISTER_HELPER(zend_jit_invalid_property_write); |
3179 | | REGISTER_HELPER(zend_jit_invalid_property_read); |
3180 | | REGISTER_HELPER(zend_jit_extract_helper); |
3181 | | REGISTER_HELPER(zend_jit_invalid_property_assign); |
3182 | | REGISTER_HELPER(zend_jit_assign_to_typed_prop); |
3183 | | REGISTER_HELPER(zend_jit_assign_obj_helper); |
3184 | | REGISTER_HELPER(zend_jit_invalid_property_assign_op); |
3185 | | REGISTER_HELPER(zend_jit_assign_op_to_typed_prop); |
3186 | | REGISTER_HELPER(zend_jit_assign_obj_op_helper); |
3187 | | REGISTER_HELPER(zend_jit_invalid_property_incdec); |
3188 | | REGISTER_HELPER(zend_jit_inc_typed_prop); |
3189 | | REGISTER_HELPER(zend_jit_dec_typed_prop); |
3190 | | REGISTER_HELPER(zend_jit_pre_inc_typed_prop); |
3191 | | REGISTER_HELPER(zend_jit_post_inc_typed_prop); |
3192 | | REGISTER_HELPER(zend_jit_pre_dec_typed_prop); |
3193 | | REGISTER_HELPER(zend_jit_post_dec_typed_prop); |
3194 | | REGISTER_HELPER(zend_jit_pre_inc_obj_helper); |
3195 | | REGISTER_HELPER(zend_jit_post_inc_obj_helper); |
3196 | | REGISTER_HELPER(zend_jit_pre_dec_obj_helper); |
3197 | | REGISTER_HELPER(zend_jit_post_dec_obj_helper); |
3198 | | REGISTER_HELPER(zend_jit_uninit_static_prop); |
3199 | | REGISTER_HELPER(zend_jit_rope_end); |
3200 | | REGISTER_HELPER(zend_fcall_interrupt); |
3201 | | |
3202 | | #ifndef ZTS |
3203 | | REGISTER_DATA(EG(current_execute_data)); |
3204 | | REGISTER_DATA(EG(exception)); |
3205 | | REGISTER_DATA(EG(opline_before_exception)); |
3206 | | REGISTER_DATA(EG(vm_interrupt)); |
3207 | | REGISTER_DATA(EG(timed_out)); |
3208 | | REGISTER_DATA(EG(uninitialized_zval)); |
3209 | | REGISTER_DATA(EG(zend_constants)); |
3210 | | REGISTER_DATA(EG(jit_trace_num)); |
3211 | | REGISTER_DATA(EG(vm_stack_top)); |
3212 | | REGISTER_DATA(EG(vm_stack_end)); |
3213 | | REGISTER_DATA(EG(exception_op)); |
3214 | | REGISTER_DATA(EG(symbol_table)); |
3215 | | |
3216 | | REGISTER_DATA(CG(map_ptr_base)); |
3217 | | #else /* ZTS */ |
3218 | | REGISTER_HELPER(zend_jit_get_tsrm_ls_cache); |
3219 | | #endif |
3220 | | #endif |
3221 | 0 | } |
3222 | | |
3223 | | static void zend_jit_calc_trace_prologue_size(void) |
3224 | 0 | { |
3225 | 0 | zend_jit_ctx jit_ctx; |
3226 | 0 | zend_jit_ctx *jit = &jit_ctx; |
3227 | 0 | void *entry; |
3228 | 0 | size_t size; |
3229 | |
|
3230 | 0 | zend_jit_init_ctx(jit, (ZEND_VM_KIND == ZEND_VM_KIND_CALL || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) ? 0 : IR_START_BR_TARGET); |
3231 | |
|
3232 | 0 | if (!GCC_GLOBAL_REGS) { |
3233 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_TAILCALL) { |
3234 | 0 | ir_ref execute_data_ref = ir_PARAM(IR_ADDR, "execute_data", 1); |
3235 | 0 | ir_ref opline_ref = ir_PARAM(IR_ADDR, "opline", 2); |
3236 | 0 | jit_STORE_FP(jit, execute_data_ref); |
3237 | 0 | jit_STORE_IP(jit, opline_ref); |
3238 | 0 | } |
3239 | 0 | jit->ctx.flags |= IR_FASTCALL_FUNC; |
3240 | 0 | } |
3241 | |
|
3242 | 0 | ir_UNREACHABLE(); |
3243 | |
|
3244 | 0 | entry = zend_jit_ir_compile(&jit->ctx, &size, "JIT$trace_prologue"); |
3245 | 0 | zend_jit_free_ctx(jit); |
3246 | |
|
3247 | 0 | if (!entry) { |
3248 | 0 | zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: could not compile prologue"); |
3249 | 0 | } |
3250 | | |
3251 | 0 | zend_jit_trace_prologue_size = size; |
3252 | 0 | } |
3253 | | |
3254 | | #if !defined(ZEND_WIN32) && !defined(IR_TARGET_AARCH64) |
3255 | | static uintptr_t zend_jit_hybrid_vm_sp_adj = 0; |
3256 | | |
3257 | | typedef struct _Unwind_Context _Unwind_Context; |
3258 | | typedef int (*_Unwind_Trace_Fn)(_Unwind_Context *, void *); |
3259 | | extern int _Unwind_Backtrace(_Unwind_Trace_Fn, void *); |
3260 | | extern uintptr_t _Unwind_GetCFA(_Unwind_Context *); |
3261 | | |
3262 | | typedef struct _zend_jit_unwind_arg { |
3263 | | int cnt; |
3264 | | uintptr_t cfa[3]; |
3265 | | } zend_jit_unwind_arg; |
3266 | | |
3267 | | static int zend_jit_unwind_cb(_Unwind_Context *ctx, void *a) |
3268 | 0 | { |
3269 | 0 | zend_jit_unwind_arg *arg = (zend_jit_unwind_arg*)a; |
3270 | 0 | arg->cfa[arg->cnt] = _Unwind_GetCFA(ctx); |
3271 | 0 | arg->cnt++; |
3272 | 0 | if (arg->cnt == 3) { |
3273 | 0 | return 5; // _URC_END_OF_STACK |
3274 | 0 | } |
3275 | 0 | return 0; // _URC_NO_REASON; |
3276 | 0 | } |
3277 | | |
3278 | | static void ZEND_FASTCALL zend_jit_touch_vm_stack_data(void *vm_stack_data) |
3279 | 0 | { |
3280 | 0 | zend_jit_unwind_arg arg; |
3281 | 0 |
|
3282 | 0 | memset(&arg, 0, sizeof(arg)); |
3283 | 0 | _Unwind_Backtrace(zend_jit_unwind_cb, &arg); |
3284 | 0 | if (arg.cnt == 3) { |
3285 | 0 | zend_jit_hybrid_vm_sp_adj = arg.cfa[2] - arg.cfa[1]; |
3286 | 0 | } |
3287 | 0 | } |
3288 | | |
3289 | | extern void (ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data); |
3290 | | |
3291 | | static zend_never_inline void zend_jit_set_sp_adj_vm(void) |
3292 | 0 | { |
3293 | 0 | void (ZEND_FASTCALL *orig_zend_touch_vm_stack_data)(void *); |
3294 | 0 |
|
3295 | 0 | orig_zend_touch_vm_stack_data = zend_touch_vm_stack_data; |
3296 | 0 | zend_touch_vm_stack_data = zend_jit_touch_vm_stack_data; |
3297 | 0 | execute_ex(NULL); // set sp_adj[SP_ADJ_VM] |
3298 | 0 | zend_touch_vm_stack_data = orig_zend_touch_vm_stack_data; |
3299 | 0 | } |
3300 | | #endif |
3301 | | |
3302 | | #ifdef _WIN64 |
3303 | | /* |
3304 | | * We use a single unwind entry for the whole JIT buffer. |
3305 | | * This works, because all the JIT-ed PHP functions have the same "fixed stack frame". |
3306 | | */ |
3307 | | static PRUNTIME_FUNCTION zend_jit_uw_func = NULL; |
3308 | | |
3309 | | #ifdef ZEND_JIT_RT_UNWINDER |
3310 | | static PRUNTIME_FUNCTION zend_jit_unwind_callback(DWORD64 pc, PVOID context) |
3311 | | { |
3312 | | return zend_jit_uw_func; |
3313 | | } |
3314 | | #endif |
3315 | | |
3316 | | static void zend_jit_setup_unwinder(void) |
3317 | | { |
3318 | | /* Hardcoded SEH unwind data for JIT-ed PHP functions with "fixed stack frame" */ |
3319 | | static const unsigned char uw_data[] = { |
3320 | | 0x01, // UBYTE: 3 Version , UBYTE: 5 Flags |
3321 | | 0x10, // UBYTE Size of prolog |
3322 | | 0x09, // UBYTE Count of unwind codes |
3323 | | 0x00, // UBYTE: 4 Frame Register, UBYTE: 4 Frame Register offset (scaled) |
3324 | | // USHORT * n Unwind codes array |
3325 | | 0x10, 0x82, // c: subq $0x48, %rsp |
3326 | | 0x0c, 0xf0, // a: pushq %r15 |
3327 | | 0x0a, 0xe0, // 8: pushq %r14 |
3328 | | 0x08, 0xd0, // 6: pushq %r13 |
3329 | | 0x06, 0xc0, // 4: pushq %r12 |
3330 | | 0x04, 0x70, // 3: pushq %rdi |
3331 | | 0x03, 0x60, // 2: pushq %rsi |
3332 | | 0x02, 0x50, // 1: pushq %rbp |
3333 | | 0x01, 0x30, // 0: pushq %rbx |
3334 | | 0x00, 0x00, |
3335 | | }; |
3336 | | static const unsigned char uw_data_exitcall[] = { |
3337 | | 0x01, // UBYTE: 3 Version , UBYTE: 5 Flags |
3338 | | 0x10, // UBYTE Size of prolog |
3339 | | 0x0a, // UBYTE Count of unwind codes |
3340 | | 0x00, // UBYTE: 4 Frame Register, UBYTE: 4 Frame Register offset (scaled) |
3341 | | // USHORT * n Unwind codes array |
3342 | | 0x10, 0x01, 0x2f, 0x00, // c: subq 376, %rsp ; 0x48 + 32+16*8+16*8+8+8 |
3343 | | 0x0c, 0xf0, // a: pushq %r15 |
3344 | | 0x0a, 0xe0, // 8: pushq %r14 |
3345 | | 0x08, 0xd0, // 6: pushq %r13 |
3346 | | 0x06, 0xc0, // 4: pushq %r12 |
3347 | | 0x04, 0x70, // 3: pushq %rdi |
3348 | | 0x03, 0x60, // 2: pushq %rsi |
3349 | | 0x02, 0x50, // 1: pushq %rbp |
3350 | | 0x01, 0x30, // 0: pushq %rbx |
3351 | | }; |
3352 | | |
3353 | | zend_jit_uw_func = (PRUNTIME_FUNCTION)*dasm_ptr; |
3354 | | *dasm_ptr = (char*)*dasm_ptr + ZEND_MM_ALIGNED_SIZE_EX(sizeof(RUNTIME_FUNCTION) * 4 + |
3355 | | sizeof(uw_data) + sizeof(uw_data_exitcall) + sizeof(uw_data), 16); |
3356 | | |
3357 | | zend_jit_uw_func[0].BeginAddress = 0; |
3358 | | zend_jit_uw_func[1].BeginAddress = (uintptr_t)zend_jit_stub_handlers[jit_stub_trace_exit] - (uintptr_t)dasm_buf; |
3359 | | zend_jit_uw_func[2].BeginAddress = (uintptr_t)zend_jit_stub_handlers[jit_stub_undefined_offset] - (uintptr_t)dasm_buf; |
3360 | | |
3361 | | zend_jit_uw_func[0].EndAddress = zend_jit_uw_func[1].BeginAddress; |
3362 | | zend_jit_uw_func[1].EndAddress = zend_jit_uw_func[2].BeginAddress; |
3363 | | zend_jit_uw_func[2].EndAddress = (uintptr_t)dasm_end - (uintptr_t)dasm_buf; |
3364 | | |
3365 | | zend_jit_uw_func[0].UnwindData = (uintptr_t)zend_jit_uw_func - (uintptr_t)dasm_buf + sizeof(RUNTIME_FUNCTION) * 4; |
3366 | | zend_jit_uw_func[1].UnwindData = zend_jit_uw_func[0].UnwindData + sizeof(uw_data); |
3367 | | zend_jit_uw_func[2].UnwindData = zend_jit_uw_func[1].UnwindData + sizeof(uw_data_exitcall); |
3368 | | |
3369 | | memcpy((char*)dasm_buf + zend_jit_uw_func[0].UnwindData, uw_data, sizeof(uw_data)); |
3370 | | memcpy((char*)dasm_buf + zend_jit_uw_func[1].UnwindData, uw_data_exitcall, sizeof(uw_data_exitcall)); |
3371 | | memcpy((char*)dasm_buf + zend_jit_uw_func[2].UnwindData, uw_data, sizeof(uw_data)); |
3372 | | |
3373 | | #ifdef ZEND_JIT_RT_UNWINDER |
3374 | | RtlInstallFunctionTableCallback( |
3375 | | (uintptr_t)dasm_buf | 3, |
3376 | | (uintptr_t) dasm_buf, |
3377 | | (uintptr_t)dasm_end - (uintptr_t)dasm_buf, |
3378 | | zend_jit_unwind_callback, |
3379 | | NULL, |
3380 | | NULL); |
3381 | | #else |
3382 | | RtlAddFunctionTable(zend_jit_uw_func, 3, (uintptr_t)dasm_buf); |
3383 | | #endif |
3384 | | } |
3385 | | #endif |
3386 | | |
3387 | | static void zend_jit_setup(bool reattached) |
3388 | 0 | { |
3389 | | #if defined(IR_TARGET_X86) |
3390 | | if (!zend_cpu_supports_sse2()) { |
3391 | | zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Could not enable JIT: CPU doesn't support SSE2"); |
3392 | | } |
3393 | | #endif |
3394 | 0 | #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) |
3395 | 0 | allowed_opt_flags = 0; |
3396 | 0 | if (zend_cpu_supports_avx()) { |
3397 | 0 | allowed_opt_flags |= ZEND_JIT_CPU_AVX; |
3398 | 0 | } |
3399 | | # if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000) |
3400 | | if (zend_cpu_supports_cldemote()) { |
3401 | | default_mflags |= IR_X86_CLDEMOTE; |
3402 | | } |
3403 | | # endif |
3404 | 0 | #endif |
3405 | |
|
3406 | | #ifdef ZTS |
3407 | | zend_result result = zend_jit_resolve_tsrm_ls_cache_offsets( |
3408 | | &tsrm_ls_cache_tcb_offset, |
3409 | | &tsrm_tls_index, |
3410 | | &tsrm_tls_offset |
3411 | | ); |
3412 | | if (result == FAILURE) { |
3413 | | zend_accel_error(ACCEL_LOG_INFO, |
3414 | | "Could not get _tsrm_ls_cache offsets, will fallback to runtime resolution"); |
3415 | | } |
3416 | | #endif |
3417 | |
|
3418 | 0 | #if !defined(ZEND_WIN32) && !defined(IR_TARGET_AARCH64) |
3419 | 0 | if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) { |
3420 | 0 | zend_jit_set_sp_adj_vm(); // set zend_jit_hybrid_vm_sp_adj |
3421 | 0 | } |
3422 | 0 | #endif |
3423 | |
|
3424 | 0 | if (JIT_G(debug) & (ZEND_JIT_DEBUG_ASM|ZEND_JIT_DEBUG_ASM_STUBS)) { |
3425 | 0 | zend_jit_setup_disasm(); |
3426 | 0 | } |
3427 | |
|
3428 | 0 | #ifndef _WIN32 |
3429 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_PERF_DUMP) { |
3430 | 0 | ir_perf_jitdump_open(); |
3431 | 0 | } |
3432 | |
|
3433 | 0 | #endif |
3434 | 0 | zend_long debug = JIT_G(debug); |
3435 | 0 | if (!(debug & ZEND_JIT_DEBUG_ASM_STUBS)) { |
3436 | 0 | JIT_G(debug) &= ~(ZEND_JIT_DEBUG_IR_SRC|ZEND_JIT_DEBUG_IR_FINAL| |
3437 | 0 | ZEND_JIT_DEBUG_IR_CODEGEN| |
3438 | 0 | ZEND_JIT_DEBUG_IR_AFTER_SCCP|ZEND_JIT_DEBUG_IR_AFTER_CFG|ZEND_JIT_DEBUG_IR_AFTER_GCM| |
3439 | 0 | ZEND_JIT_DEBUG_IR_AFTER_SCHEDULE|ZEND_JIT_DEBUG_IR_AFTER_REGS); |
3440 | 0 | } |
3441 | |
|
3442 | 0 | zend_jit_calc_trace_prologue_size(); |
3443 | 0 | if (!reattached) { |
3444 | 0 | zend_jit_setup_stubs(); |
3445 | 0 | } |
3446 | 0 | JIT_G(debug) = debug; |
3447 | |
|
3448 | | #ifdef _WIN64 |
3449 | | zend_jit_setup_unwinder(); |
3450 | | #endif |
3451 | 0 | } |
3452 | | |
3453 | | static void zend_jit_shutdown_ir(void) |
3454 | 0 | { |
3455 | 0 | #ifndef _WIN32 |
3456 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_PERF_DUMP) { |
3457 | 0 | ir_perf_jitdump_close(); |
3458 | 0 | } |
3459 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_GDB) { |
3460 | 0 | ir_gdb_unregister_all(); |
3461 | 0 | } |
3462 | 0 | #endif |
3463 | | #ifdef HAVE_CAPSTONE |
3464 | | if (JIT_G(debug) & (ZEND_JIT_DEBUG_ASM|ZEND_JIT_DEBUG_ASM_STUBS)) { |
3465 | | ir_disasm_free(); |
3466 | | } |
3467 | | #endif |
3468 | 0 | } |
3469 | | |
3470 | | /* PHP control flow reconstruction helpers */ |
3471 | | static ir_ref jit_IF_ex(zend_jit_ctx *jit, ir_ref condition, ir_ref true_block) |
3472 | 0 | { |
3473 | 0 | ir_ref ref = ir_IF(condition); |
3474 | | /* op3 is used as a temporary storage for PHP BB number to reconstruct PHP control flow. |
3475 | | * |
3476 | | * It's used in jit_IF_TRUE_FALSE_ex() to select IF_TRUE or IF_FALSE instructions |
3477 | | * to start target block |
3478 | | */ |
3479 | 0 | ir_set_op(&jit->ctx, ref, 3, true_block); |
3480 | 0 | return ref; |
3481 | 0 | } |
3482 | | |
3483 | | static void jit_IF_TRUE_FALSE_ex(zend_jit_ctx *jit, ir_ref if_ref, ir_ref true_block) |
3484 | 0 | { |
3485 | 0 | ZEND_ASSERT(JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE); |
3486 | 0 | ZEND_ASSERT(if_ref); |
3487 | 0 | ZEND_ASSERT(jit->ctx.ir_base[if_ref].op == IR_IF); |
3488 | 0 | ZEND_ASSERT(jit->ctx.ir_base[if_ref].op3); |
3489 | 0 | if (jit->ctx.ir_base[if_ref].op3 == true_block) { |
3490 | 0 | ir_IF_TRUE(if_ref); |
3491 | 0 | } else { |
3492 | 0 | ir_IF_FALSE(if_ref); |
3493 | 0 | } |
3494 | 0 | } |
3495 | | |
3496 | | static void zend_jit_case_start(zend_jit_ctx *jit, int switch_b, int case_b, ir_ref switch_ref); |
3497 | | |
3498 | | static void _zend_jit_add_predecessor_ref(zend_jit_ctx *jit, int b, int pred, ir_ref ref) |
3499 | 0 | { |
3500 | 0 | int *p; |
3501 | 0 | zend_basic_block *bb; |
3502 | 0 | ir_ref *r, header; |
3503 | |
|
3504 | 0 | ZEND_ASSERT(JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE); |
3505 | 0 | bb = &jit->ssa->cfg.blocks[b]; |
3506 | 0 | p = &jit->ssa->cfg.predecessors[bb->predecessor_offset]; |
3507 | 0 | r = &jit->bb_edges[jit->bb_predecessors[b]]; |
3508 | 0 | for (uint32_t i = 0; i < bb->predecessors_count; i++, p++, r++) { |
3509 | 0 | if (*p == pred) { |
3510 | 0 | ZEND_ASSERT(*r == IR_UNUSED || *r == ref); |
3511 | 0 | header = jit->bb_start_ref[b]; |
3512 | 0 | if (header) { |
3513 | | /* this is back edge */ |
3514 | 0 | ZEND_ASSERT(jit->ctx.ir_base[header].op == IR_LOOP_BEGIN); |
3515 | 0 | if (jit->ctx.ir_base[ref].op == IR_END) { |
3516 | 0 | jit->ctx.ir_base[ref].op = IR_LOOP_END; |
3517 | 0 | } else if (jit->ctx.ir_base[ref].op == IR_IF) { |
3518 | 0 | jit_IF_TRUE_FALSE_ex(jit, ref, b); |
3519 | 0 | ref = ir_LOOP_END(); |
3520 | 0 | } else if (jit->ctx.ir_base[ref].op == IR_SWITCH) { |
3521 | 0 | zend_jit_case_start(jit, pred, b, ref); |
3522 | 0 | ref = ir_LOOP_END(); |
3523 | 0 | } else if (jit->ctx.ir_base[ref].op == IR_UNREACHABLE) { |
3524 | 0 | ir_BEGIN(ref); |
3525 | 0 | ref = ir_LOOP_END(); |
3526 | 0 | } else { |
3527 | 0 | ZEND_UNREACHABLE(); |
3528 | 0 | } |
3529 | 0 | ir_MERGE_SET_OP(header, i + 1, ref); |
3530 | 0 | } |
3531 | 0 | *r = ref; |
3532 | 0 | return; |
3533 | 0 | } |
3534 | 0 | } |
3535 | 0 | ZEND_UNREACHABLE(); |
3536 | 0 | } |
3537 | | |
3538 | | static void _zend_jit_merge_smart_branch_inputs(zend_jit_ctx *jit, |
3539 | | uint32_t true_label, |
3540 | | uint32_t false_label, |
3541 | | ir_ref true_inputs, |
3542 | | ir_ref false_inputs) |
3543 | 0 | { |
3544 | 0 | ir_ref true_path = IR_UNUSED, false_path = IR_UNUSED; |
3545 | |
|
3546 | 0 | ZEND_ASSERT(JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE); |
3547 | 0 | if (true_inputs) { |
3548 | 0 | ZEND_ASSERT(jit->ctx.ir_base[true_inputs].op == IR_END); |
3549 | 0 | if (!jit->ctx.ir_base[true_inputs].op2) { |
3550 | 0 | true_path = true_inputs; |
3551 | 0 | } else { |
3552 | 0 | ir_MERGE_list(true_inputs); |
3553 | 0 | true_path = ir_END(); |
3554 | 0 | } |
3555 | 0 | } |
3556 | 0 | if (false_inputs) { |
3557 | 0 | ZEND_ASSERT(jit->ctx.ir_base[false_inputs].op == IR_END); |
3558 | 0 | if (!jit->ctx.ir_base[false_inputs].op2) { |
3559 | 0 | false_path = false_inputs; |
3560 | 0 | } else { |
3561 | 0 | ir_MERGE_list(false_inputs); |
3562 | 0 | false_path = ir_END(); |
3563 | 0 | } |
3564 | 0 | } |
3565 | |
|
3566 | 0 | if (true_label == false_label && true_path && false_path) { |
3567 | 0 | ir_MERGE_2(true_path, false_path); |
3568 | 0 | _zend_jit_add_predecessor_ref(jit, true_label, jit->b, ir_END()); |
3569 | 0 | } else if (!true_path && !false_path) { |
3570 | | /* dead code */ |
3571 | 0 | true_path = ir_END(); |
3572 | 0 | _zend_jit_add_predecessor_ref(jit, true_label, jit->b, true_path); |
3573 | 0 | } else { |
3574 | 0 | if (true_path) { |
3575 | 0 | _zend_jit_add_predecessor_ref(jit, true_label, jit->b, true_path); |
3576 | 0 | } |
3577 | 0 | if (false_path) { |
3578 | 0 | _zend_jit_add_predecessor_ref(jit, false_label, jit->b, false_path); |
3579 | 0 | } |
3580 | 0 | } |
3581 | |
|
3582 | 0 | jit->b = -1; |
3583 | 0 | } |
3584 | | |
3585 | | static void _zend_jit_fix_merges(zend_jit_ctx *jit) |
3586 | 0 | { |
3587 | 0 | int i, count; |
3588 | 0 | ir_ref j, k, n, *p, *q, *r; |
3589 | 0 | ir_ref ref; |
3590 | 0 | ir_insn *insn, *phi; |
3591 | |
|
3592 | 0 | ZEND_ASSERT(JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE); |
3593 | 0 | count = jit->ssa->cfg.blocks_count; |
3594 | 0 | for (i = 0, p = jit->bb_start_ref; i < count; i++, p++) { |
3595 | 0 | ref = *p; |
3596 | 0 | if (ref) { |
3597 | 0 | insn = &jit->ctx.ir_base[ref]; |
3598 | 0 | if (insn->op == IR_MERGE || insn->op == IR_LOOP_BEGIN) { |
3599 | 0 | n = insn->inputs_count; |
3600 | | /* Remove IS_UNUSED inputs */ |
3601 | 0 | for (j = k = 0, q = r = insn->ops + 1; j < n; j++, q++) { |
3602 | 0 | if (*q) { |
3603 | 0 | if (q != r) { |
3604 | 0 | *r = *q; |
3605 | 0 | phi = insn + 1 + (n >> 2); |
3606 | 0 | while (phi->op == IR_PI) { |
3607 | 0 | phi++; |
3608 | 0 | } |
3609 | 0 | while (phi->op == IR_PHI) { |
3610 | 0 | ir_insn_set_op(phi, k + 2, ir_insn_op(phi, j + 2)); |
3611 | 0 | phi += 1 + ((n + 1) >> 2); |
3612 | 0 | } |
3613 | 0 | } |
3614 | 0 | k++; |
3615 | 0 | r++; |
3616 | 0 | } |
3617 | 0 | } |
3618 | 0 | if (k != n) { |
3619 | 0 | ir_ref n2, k2; |
3620 | |
|
3621 | 0 | if (k <= 1) { |
3622 | 0 | insn->op = IR_BEGIN; |
3623 | 0 | insn->inputs_count = 0; |
3624 | 0 | } else { |
3625 | 0 | insn->inputs_count = k; |
3626 | 0 | } |
3627 | 0 | n2 = 1 + (n >> 2); |
3628 | 0 | k2 = 1 + (k >> 2); |
3629 | 0 | while (k2 != n2) { |
3630 | 0 | (insn+k2)->optx = IR_NOP; |
3631 | 0 | k2++; |
3632 | 0 | } |
3633 | 0 | phi = insn + 1 + (n >> 2); |
3634 | 0 | while (phi->op == IR_PI) { |
3635 | 0 | phi++; |
3636 | 0 | } |
3637 | 0 | while (phi->op == IR_PHI) { |
3638 | 0 | if (k <= 1) { |
3639 | 0 | phi->op = IR_COPY; |
3640 | 0 | phi->op1 = phi->op2; |
3641 | 0 | phi->op2 = 1; |
3642 | 0 | phi->inputs_count = 0; |
3643 | 0 | } else { |
3644 | 0 | phi->inputs_count = k + 1; |
3645 | 0 | } |
3646 | 0 | n2 = 1 + ((n + 1) >> 2); |
3647 | 0 | k2 = 1 + ((k + 1) >> 2); |
3648 | 0 | while (k2 != n2) { |
3649 | 0 | (phi+k2)->optx = IR_NOP; |
3650 | 0 | k2++; |
3651 | 0 | } |
3652 | 0 | phi += 1 + ((n + 1) >> 2); |
3653 | 0 | } |
3654 | 0 | } |
3655 | 0 | } |
3656 | 0 | } |
3657 | 0 | } |
3658 | 0 | } |
3659 | | |
3660 | | static void zend_jit_case_start(zend_jit_ctx *jit, int switch_b, int case_b, ir_ref switch_ref) |
3661 | 0 | { |
3662 | 0 | zend_basic_block *bb = &jit->ssa->cfg.blocks[switch_b]; |
3663 | 0 | const zend_op *opline = &jit->op_array->opcodes[bb->start + bb->len - 1]; |
3664 | |
|
3665 | 0 | if (opline->opcode == ZEND_SWITCH_LONG |
3666 | 0 | || opline->opcode == ZEND_SWITCH_STRING |
3667 | 0 | || opline->opcode == ZEND_MATCH) { |
3668 | 0 | HashTable *jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2)); |
3669 | 0 | const zend_op *default_opline = ZEND_OFFSET_TO_OPLINE(opline, opline->extended_value); |
3670 | 0 | int default_b = jit->ssa->cfg.map[default_opline - jit->op_array->opcodes]; |
3671 | 0 | zval *zv; |
3672 | 0 | ir_ref list = IR_UNUSED, idx; |
3673 | 0 | bool first = true; |
3674 | |
|
3675 | 0 | ZEND_HASH_FOREACH_VAL(jumptable, zv) { |
3676 | 0 | const zend_op *target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(zv)); |
3677 | 0 | int b = jit->ssa->cfg.map[target - jit->op_array->opcodes]; |
3678 | |
|
3679 | 0 | if (b == case_b) { |
3680 | 0 | if (!first) { |
3681 | 0 | ir_END_list(list); |
3682 | 0 | } |
3683 | 0 | if (HT_IS_PACKED(jumptable)) { |
3684 | 0 | idx = ir_CONST_LONG(zv - jumptable->arPacked); |
3685 | 0 | } else { |
3686 | 0 | idx = ir_CONST_LONG((Bucket*)zv - jumptable->arData); |
3687 | 0 | } |
3688 | 0 | ir_CASE_VAL(switch_ref, idx); |
3689 | 0 | first = false; |
3690 | 0 | } |
3691 | 0 | } ZEND_HASH_FOREACH_END(); |
3692 | 0 | if (default_b == case_b) { |
3693 | 0 | if (!first) { |
3694 | 0 | ir_END_list(list); |
3695 | 0 | } |
3696 | 0 | if (jit->ctx.ir_base[switch_ref].op3) { |
3697 | | /* op3 may contain a list of additional "default" path inputs for MATCH */ |
3698 | 0 | ir_ref ref = jit->ctx.ir_base[switch_ref].op3; |
3699 | 0 | jit->ctx.ir_base[switch_ref].op3 = IS_UNDEF; |
3700 | 0 | ZEND_ASSERT(jit->ctx.ir_base[ref].op == IR_END); |
3701 | 0 | ir_ref end = ref; |
3702 | 0 | while (jit->ctx.ir_base[end].op2) { |
3703 | 0 | ZEND_ASSERT(jit->ctx.ir_base[end].op == IR_END); |
3704 | 0 | end = jit->ctx.ir_base[end].op2; |
3705 | 0 | } |
3706 | 0 | jit->ctx.ir_base[end].op2 = list; |
3707 | 0 | list = ref; |
3708 | 0 | } |
3709 | 0 | ir_CASE_DEFAULT(switch_ref); |
3710 | 0 | } |
3711 | 0 | if (list) { |
3712 | 0 | ir_END_list(list); |
3713 | 0 | ir_MERGE_list(list); |
3714 | 0 | } |
3715 | 0 | } else { |
3716 | 0 | ZEND_UNREACHABLE(); |
3717 | 0 | } |
3718 | 0 | } |
3719 | | |
3720 | | static int zend_jit_bb_start(zend_jit_ctx *jit, int b) |
3721 | 0 | { |
3722 | 0 | zend_basic_block *bb; |
3723 | 0 | int *p, pred; |
3724 | 0 | ir_ref ref, bb_start; |
3725 | |
|
3726 | 0 | ZEND_ASSERT(JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE); |
3727 | 0 | ZEND_ASSERT(b < jit->ssa->cfg.blocks_count); |
3728 | 0 | bb = &jit->ssa->cfg.blocks[b]; |
3729 | 0 | ZEND_ASSERT((bb->flags & ZEND_BB_REACHABLE) != 0); |
3730 | 0 | uint32_t n = bb->predecessors_count; |
3731 | |
|
3732 | 0 | if (n == 0) { |
3733 | | /* pass */ |
3734 | 0 | ZEND_ASSERT(jit->ctx.control); |
3735 | 0 | #if ZEND_DEBUG |
3736 | 0 | ref = jit->ctx.control; |
3737 | 0 | ir_insn *insn = &jit->ctx.ir_base[ref]; |
3738 | 0 | while (insn->op >= IR_CALL && insn->op <= IR_TRAP) { |
3739 | 0 | ref = insn->op1; |
3740 | 0 | insn = &jit->ctx.ir_base[ref]; |
3741 | 0 | } |
3742 | 0 | ZEND_ASSERT(insn->op == IR_START); |
3743 | 0 | ZEND_ASSERT(ref == 1); |
3744 | 0 | #endif |
3745 | 0 | bb_start = 1; |
3746 | 0 | if (jit->ssa->cfg.flags & ZEND_FUNC_RECURSIVE_DIRECTLY) { |
3747 | | /* prvent END/BEGIN merging */ |
3748 | 0 | jit->ctx.control = ir_emit1(&jit->ctx, IR_BEGIN, ir_END()); |
3749 | 0 | bb_start = jit->ctx.control; |
3750 | 0 | } |
3751 | 0 | } else if (n == 1) { |
3752 | 0 | ZEND_ASSERT(!jit->ctx.control); |
3753 | 0 | pred = jit->ssa->cfg.predecessors[bb->predecessor_offset]; |
3754 | 0 | ref = jit->bb_edges[jit->bb_predecessors[b]]; |
3755 | 0 | if (ref == IR_UNUSED) { |
3756 | 0 | if (!jit->ctx.control) { |
3757 | 0 | ir_BEGIN(IR_UNUSED); /* unreachable block */ |
3758 | 0 | } |
3759 | 0 | } else { |
3760 | 0 | ir_op op = jit->ctx.ir_base[ref].op; |
3761 | |
|
3762 | 0 | if (op == IR_IF) { |
3763 | 0 | if (!jit->ctx.control) { |
3764 | 0 | jit_IF_TRUE_FALSE_ex(jit, ref, b); |
3765 | 0 | } else { |
3766 | 0 | ir_ref entry_path = ir_END(); |
3767 | 0 | jit_IF_TRUE_FALSE_ex(jit, ref, b); |
3768 | 0 | ir_MERGE_WITH(entry_path); |
3769 | 0 | } |
3770 | 0 | } else if (op == IR_SWITCH) { |
3771 | 0 | zend_jit_case_start(jit, pred, b, ref); |
3772 | 0 | } else { |
3773 | 0 | if (!jit->ctx.control) { |
3774 | 0 | ZEND_ASSERT(op == IR_END || op == IR_UNREACHABLE || op == IR_RETURN); |
3775 | 0 | if ((jit->ssa->cfg.blocks[b].flags & ZEND_BB_RECV_ENTRY) |
3776 | 0 | && (jit->ssa->cfg.flags & ZEND_FUNC_RECURSIVE_DIRECTLY)) { |
3777 | | /* prvent END/BEGIN merging */ |
3778 | 0 | jit->ctx.control = ir_emit1(&jit->ctx, IR_BEGIN, ref); |
3779 | 0 | } else { |
3780 | 0 | ir_BEGIN(ref); |
3781 | 0 | } |
3782 | 0 | } else { |
3783 | 0 | ir_MERGE_WITH(ref); |
3784 | 0 | } |
3785 | 0 | } |
3786 | 0 | } |
3787 | 0 | bb_start = jit->ctx.control; |
3788 | 0 | } else { |
3789 | 0 | int forward_edges_count = 0; |
3790 | 0 | int back_edges_count = 0; |
3791 | 0 | ir_ref *pred_refs; |
3792 | 0 | ir_ref entry_path = IR_UNUSED; |
3793 | 0 | ALLOCA_FLAG(use_heap); |
3794 | |
|
3795 | 0 | ZEND_ASSERT(!jit->ctx.control); |
3796 | 0 | if (jit->ctx.control) { |
3797 | 0 | entry_path = ir_END(); |
3798 | 0 | } |
3799 | 0 | pred_refs = (ir_ref *)do_alloca(sizeof(ir_ref) * n, use_heap); |
3800 | 0 | uint32_t i; |
3801 | 0 | for (i = 0, p = jit->ssa->cfg.predecessors + bb->predecessor_offset; i < n; p++, i++) { |
3802 | 0 | pred = *p; |
3803 | 0 | if (jit->bb_start_ref[pred]) { |
3804 | | /* forward edge */ |
3805 | 0 | forward_edges_count++; |
3806 | 0 | ref = jit->bb_edges[jit->bb_predecessors[b] + i]; |
3807 | 0 | if (ref == IR_UNUSED) { |
3808 | | /* dead edge */ |
3809 | 0 | pred_refs[i] = IR_UNUSED; |
3810 | 0 | } else { |
3811 | 0 | ir_op op = jit->ctx.ir_base[ref].op; |
3812 | |
|
3813 | 0 | if (op == IR_IF) { |
3814 | 0 | jit_IF_TRUE_FALSE_ex(jit, ref, b); |
3815 | 0 | pred_refs[i] = ir_END(); |
3816 | 0 | } else if (op == IR_SWITCH) { |
3817 | 0 | zend_jit_case_start(jit, pred, b, ref); |
3818 | 0 | pred_refs[i] = ir_END(); |
3819 | 0 | } else { |
3820 | 0 | ZEND_ASSERT(op == IR_END || op == IR_UNREACHABLE || op == IR_RETURN); |
3821 | 0 | pred_refs[i] = ref; |
3822 | 0 | } |
3823 | 0 | } |
3824 | 0 | } else { |
3825 | | /* backward edge */ |
3826 | 0 | back_edges_count++; |
3827 | 0 | pred_refs[i] = IR_UNUSED; |
3828 | 0 | } |
3829 | 0 | } |
3830 | |
|
3831 | 0 | if (bb->flags & ZEND_BB_LOOP_HEADER) { |
3832 | 0 | ZEND_ASSERT(back_edges_count != 0); |
3833 | 0 | ZEND_ASSERT(forward_edges_count != 0); |
3834 | 0 | ir_MERGE_N(n, pred_refs); |
3835 | 0 | jit->ctx.ir_base[jit->ctx.control].op = IR_LOOP_BEGIN; |
3836 | 0 | bb_start = jit->ctx.control; |
3837 | 0 | if (entry_path) { |
3838 | 0 | ir_MERGE_WITH(entry_path); |
3839 | 0 | } |
3840 | 0 | } else { |
3841 | | // ZEND_ASSERT(back_edges_count != 0); |
3842 | | /* edges from exceptional blocks may be counted as back edges */ |
3843 | 0 | ir_MERGE_N(n, pred_refs); |
3844 | 0 | bb_start = jit->ctx.control; |
3845 | 0 | if (entry_path) { |
3846 | 0 | ir_MERGE_WITH(entry_path); |
3847 | 0 | } |
3848 | 0 | } |
3849 | 0 | free_alloca(pred_refs, use_heap); |
3850 | 0 | } |
3851 | 0 | jit->b = b; |
3852 | 0 | jit->bb_start_ref[b] = bb_start; |
3853 | |
|
3854 | 0 | if ((bb->flags & ZEND_BB_ENTRY) || (bb->idom >= 0 && jit->bb_start_ref[bb->idom] < jit->ctx.fold_cse_limit)) { |
3855 | 0 | jit->ctx.fold_cse_limit = bb_start; |
3856 | 0 | } |
3857 | |
|
3858 | 0 | return 1; |
3859 | 0 | } |
3860 | | |
3861 | | static int zend_jit_bb_end(zend_jit_ctx *jit, int b) |
3862 | 0 | { |
3863 | 0 | int succ; |
3864 | 0 | zend_basic_block *bb; |
3865 | |
|
3866 | 0 | ZEND_ASSERT(JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE); |
3867 | 0 | if (jit->b != b) { |
3868 | 0 | return 1; |
3869 | 0 | } |
3870 | | |
3871 | 0 | bb = &jit->ssa->cfg.blocks[b]; |
3872 | 0 | ZEND_ASSERT(bb->successors_count != 0); |
3873 | 0 | if (bb->successors_count == 1) { |
3874 | 0 | succ = bb->successors[0]; |
3875 | 0 | } else { |
3876 | 0 | const zend_op *opline = &jit->op_array->opcodes[bb->start + bb->len - 1]; |
3877 | | |
3878 | | /* Use only the following successor of SWITCH and FE_RESET_R */ |
3879 | 0 | ZEND_ASSERT(opline->opcode == ZEND_SWITCH_LONG |
3880 | 0 | || opline->opcode == ZEND_SWITCH_STRING |
3881 | 0 | || opline->opcode == ZEND_MATCH |
3882 | 0 | || opline->opcode == ZEND_FE_RESET_R); |
3883 | 0 | succ = b + 1; |
3884 | 0 | } |
3885 | 0 | _zend_jit_add_predecessor_ref(jit, succ, b, ir_END()); |
3886 | 0 | jit->b = -1; |
3887 | 0 | return 1; |
3888 | 0 | } |
3889 | | |
3890 | | static int jit_CMP_IP(zend_jit_ctx *jit, ir_op op, const zend_op *next_opline) |
3891 | 0 | { |
3892 | 0 | ir_ref ref; |
3893 | |
|
3894 | 0 | #if 1 |
3895 | 0 | ref = jit_IP32(jit); |
3896 | 0 | ref = ir_CMP_OP(op, ref, ir_CONST_U32((uint32_t)(uintptr_t)next_opline)); |
3897 | | #else |
3898 | | ref = jit_IP(jit); |
3899 | | ref = ir_CMP_OP(op, ref, ir_CONST_ADDR(next_opline)); |
3900 | | #endif |
3901 | 0 | return ref; |
3902 | 0 | } |
3903 | | |
3904 | | static int zend_jit_jmp_frameless( |
3905 | | zend_jit_ctx *jit, |
3906 | | const zend_op *opline, |
3907 | | const void *exit_addr, |
3908 | | zend_jmp_fl_result guard |
3909 | 0 | ) { |
3910 | 0 | ir_ref ref, if_ref, cache_result, function_result, phi_result, cache_slot_ref; |
3911 | 0 | zend_basic_block *bb; |
3912 | | |
3913 | | // JIT: CACHED_PTR(opline->extended_value) |
3914 | 0 | cache_slot_ref = ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->extended_value); |
3915 | 0 | cache_result = ir_LOAD_L(cache_slot_ref); |
3916 | | |
3917 | | // JIT: if (UNEXPECTED(!result)) |
3918 | 0 | if_ref = ir_IF(cache_result); |
3919 | 0 | ir_IF_FALSE_cold(if_ref); |
3920 | 0 | zval *func_name_zv = RT_CONSTANT(opline, opline->op1); |
3921 | 0 | function_result = ir_CALL_2(IR_LONG, ir_CONST_FC_FUNC(zend_jit_jmp_frameless_helper), |
3922 | 0 | ir_CONST_ADDR(func_name_zv), |
3923 | 0 | cache_slot_ref); |
3924 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_ref); |
3925 | |
|
3926 | 0 | phi_result = ir_PHI_2(IR_LONG, function_result, cache_result); |
3927 | |
|
3928 | 0 | if (exit_addr) { |
3929 | 0 | ir_GUARD(ir_EQ(phi_result, ir_CONST_LONG(guard)), ir_CONST_ADDR(exit_addr)); |
3930 | 0 | } else { |
3931 | 0 | ZEND_ASSERT(jit->b >= 0); |
3932 | 0 | bb = &jit->ssa->cfg.blocks[jit->b]; |
3933 | | // JIT: if (result == ZEND_JMP_FL_HIT) |
3934 | 0 | ref = jit_IF_ex(jit, ir_EQ(phi_result, ir_CONST_LONG(ZEND_JMP_FL_HIT)), bb->successors[0]); |
3935 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ref); |
3936 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[1], jit->b, ref); |
3937 | 0 | jit->b = -1; |
3938 | 0 | } |
3939 | |
|
3940 | 0 | return 1; |
3941 | 0 | } |
3942 | | |
3943 | | static int zend_jit_cond_jmp(zend_jit_ctx *jit, const zend_op *next_opline, int target_block) |
3944 | 0 | { |
3945 | 0 | ir_ref ref; |
3946 | 0 | zend_basic_block *bb; |
3947 | |
|
3948 | 0 | ZEND_ASSERT(jit->b >= 0); |
3949 | 0 | bb = &jit->ssa->cfg.blocks[jit->b]; |
3950 | |
|
3951 | 0 | ZEND_ASSERT(bb->successors_count == 2); |
3952 | 0 | if (bb->successors[0] == bb->successors[1]) { |
3953 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ir_END()); |
3954 | 0 | jit->b = -1; |
3955 | 0 | zend_jit_set_last_valid_opline(jit, next_opline); |
3956 | 0 | return 1; |
3957 | 0 | } |
3958 | | |
3959 | 0 | ref = jit_IF_ex(jit, jit_CMP_IP(jit, IR_NE, next_opline), target_block); |
3960 | |
|
3961 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ref); |
3962 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[1], jit->b, ref); |
3963 | |
|
3964 | 0 | jit->b = -1; |
3965 | 0 | zend_jit_set_last_valid_opline(jit, next_opline); |
3966 | |
|
3967 | 0 | return 1; |
3968 | 0 | } |
3969 | | |
3970 | | static int zend_jit_set_cond(zend_jit_ctx *jit, const zend_op *next_opline, uint32_t var) |
3971 | 0 | { |
3972 | 0 | ir_ref ref; |
3973 | |
|
3974 | 0 | ref = ir_ADD_U32(ir_ZEXT_U32(jit_CMP_IP(jit, IR_EQ, next_opline)), ir_CONST_U32(IS_FALSE)); |
3975 | | |
3976 | | // EX_VAR(var) = ... |
3977 | 0 | ir_STORE(ir_ADD_OFFSET(jit_FP(jit), var + offsetof(zval, u1.type_info)), ref); |
3978 | |
|
3979 | 0 | zend_jit_reset_last_valid_opline(jit); |
3980 | 0 | return zend_jit_set_ip(jit, next_opline - 1); |
3981 | 0 | } |
3982 | | |
3983 | | /* PHP JIT handlers */ |
3984 | | static void zend_jit_check_exception(zend_jit_ctx *jit) |
3985 | 0 | { |
3986 | 0 | ir_GUARD_NOT(ir_LOAD_A(jit_EG_exception(jit)), |
3987 | 0 | jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
3988 | 0 | } |
3989 | | |
3990 | | static void zend_jit_check_exception_undef_result(zend_jit_ctx *jit, const zend_op *opline) |
3991 | 0 | { |
3992 | 0 | ir_GUARD_NOT(ir_LOAD_A(jit_EG_exception(jit)), |
3993 | 0 | jit_STUB_ADDR(jit, |
3994 | 0 | (opline->result_type & (IS_TMP_VAR|IS_VAR)) ? jit_stub_exception_handler_undef : jit_stub_exception_handler)); |
3995 | 0 | } |
3996 | | |
3997 | | static void zend_jit_type_check_undef(zend_jit_ctx *jit, |
3998 | | ir_ref type, |
3999 | | uint32_t var, |
4000 | | const zend_op *opline, |
4001 | | bool check_exception, |
4002 | | bool in_cold_path, |
4003 | | bool undef_result) |
4004 | 0 | { |
4005 | 0 | ir_ref if_def = ir_IF(type); |
4006 | |
|
4007 | 0 | if (!in_cold_path) { |
4008 | 0 | ir_IF_FALSE_cold(if_def); |
4009 | 0 | } else { |
4010 | 0 | ir_IF_FALSE(if_def); |
4011 | 0 | } |
4012 | 0 | if (opline) { |
4013 | 0 | jit_SET_EX_OPLINE(jit, opline); |
4014 | 0 | } |
4015 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(var)); |
4016 | 0 | if (check_exception) { |
4017 | 0 | if (undef_result) { |
4018 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
4019 | 0 | } else { |
4020 | 0 | zend_jit_check_exception(jit); |
4021 | 0 | } |
4022 | 0 | } |
4023 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_def); |
4024 | 0 | } |
4025 | | |
4026 | | static ir_ref zend_jit_zval_check_undef(zend_jit_ctx *jit, |
4027 | | ir_ref ref, |
4028 | | uint32_t var, |
4029 | | const zend_op *opline, |
4030 | | bool check_exception) |
4031 | 0 | { |
4032 | 0 | ir_ref if_def, ref2; |
4033 | |
|
4034 | 0 | if_def = ir_IF(jit_Z_TYPE_ref(jit, ref)); |
4035 | 0 | ir_IF_FALSE_cold(if_def); |
4036 | |
|
4037 | 0 | if (opline) { |
4038 | 0 | jit_SET_EX_OPLINE(jit, opline); |
4039 | 0 | } |
4040 | |
|
4041 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(var)); |
4042 | |
|
4043 | 0 | if (check_exception) { |
4044 | 0 | zend_jit_check_exception(jit); |
4045 | 0 | } |
4046 | |
|
4047 | 0 | ref2 = jit_EG(uninitialized_zval); |
4048 | |
|
4049 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_def); |
4050 | |
|
4051 | 0 | return ir_PHI_2(IR_ADDR, ref2, ref); |
4052 | 0 | } |
4053 | | |
4054 | | static void zend_jit_recv_entry(zend_jit_ctx *jit, int b) |
4055 | 0 | { |
4056 | 0 | zend_basic_block *bb = &jit->ssa->cfg.blocks[b]; |
4057 | 0 | int pred; |
4058 | 0 | ir_ref ref; |
4059 | |
|
4060 | 0 | ZEND_ASSERT(bb->predecessors_count > 0); |
4061 | |
|
4062 | 0 | pred = jit->bb_predecessors[b]; |
4063 | 0 | ref = jit->bb_edges[pred]; |
4064 | |
|
4065 | 0 | ZEND_ASSERT(ref); |
4066 | 0 | ZEND_ASSERT(jit->ctx.ir_base[ref].op == IR_END); |
4067 | | |
4068 | | /* Insert a MERGE block with additional ENTRY input between predecessor and this one */ |
4069 | 0 | ir_ENTRY(ref, bb->start); |
4070 | 0 | if (!GCC_GLOBAL_REGS && ZEND_VM_KIND != ZEND_VM_KIND_TAILCALL) { |
4071 | | /* 2 and 3 are hardcoded reference to IR_PARAMs */ |
4072 | 0 | ZEND_ASSERT(jit->ctx.ir_base[2].op == IR_PARAM); |
4073 | 0 | ZEND_ASSERT(jit->ctx.ir_base[2].op3 == 1); |
4074 | 0 | jit_STORE_FP(jit, 2); |
4075 | 0 | ZEND_ASSERT(jit->ctx.ir_base[3].op == IR_PARAM); |
4076 | 0 | ZEND_ASSERT(jit->ctx.ir_base[3].op3 == 2); |
4077 | 0 | jit_STORE_IP(jit, 3); |
4078 | 0 | } |
4079 | |
|
4080 | 0 | ir_MERGE_WITH(ref); |
4081 | 0 | jit->bb_edges[pred] = ir_END(); |
4082 | 0 | } |
4083 | | |
4084 | | static void zend_jit_osr_entry(zend_jit_ctx *jit, int b) |
4085 | 0 | { |
4086 | 0 | zend_basic_block *bb = &jit->ssa->cfg.blocks[b]; |
4087 | 0 | ir_ref ref = ir_END(); |
4088 | | |
4089 | | /* Insert a MERGE block with additional ENTRY input between predecessor and this one */ |
4090 | 0 | ir_ENTRY(ref, bb->start); |
4091 | 0 | if (!GCC_GLOBAL_REGS && ZEND_VM_KIND != ZEND_VM_KIND_TAILCALL) { |
4092 | | /* 2 and 3 are hardcoded reference to IR_PARAMs */ |
4093 | 0 | ZEND_ASSERT(jit->ctx.ir_base[2].op == IR_PARAM); |
4094 | 0 | ZEND_ASSERT(jit->ctx.ir_base[2].op3 == 1); |
4095 | 0 | jit_STORE_FP(jit, 2); |
4096 | 0 | ZEND_ASSERT(jit->ctx.ir_base[3].op == IR_PARAM); |
4097 | 0 | ZEND_ASSERT(jit->ctx.ir_base[3].op3 == 2); |
4098 | 0 | jit_STORE_IP(jit, 3); |
4099 | 0 | } |
4100 | |
|
4101 | 0 | ir_MERGE_WITH(ref); |
4102 | 0 | } |
4103 | | |
4104 | | static ir_ref zend_jit_continue_entry(zend_jit_ctx *jit, ir_ref src, unsigned int label) |
4105 | 0 | { |
4106 | 0 | ir_ENTRY(src, label); |
4107 | 0 | if (!GCC_GLOBAL_REGS && ZEND_VM_KIND != ZEND_VM_KIND_TAILCALL) { |
4108 | | /* 2 and 3 are hardcoded reference to IR_PARAMs */ |
4109 | 0 | ZEND_ASSERT(jit->ctx.ir_base[2].op == IR_PARAM); |
4110 | 0 | ZEND_ASSERT(jit->ctx.ir_base[2].op3 == 1); |
4111 | 0 | jit_STORE_FP(jit, 2); |
4112 | 0 | ZEND_ASSERT(jit->ctx.ir_base[3].op == IR_PARAM); |
4113 | 0 | ZEND_ASSERT(jit->ctx.ir_base[3].op3 == 2); |
4114 | 0 | jit_STORE_IP(jit, 3); |
4115 | 0 | } |
4116 | 0 | return ir_END(); |
4117 | 0 | } |
4118 | | |
4119 | | static int zend_jit_handler(zend_jit_ctx *jit, const zend_op *opline, int may_throw) |
4120 | 0 | { |
4121 | 0 | zend_jit_set_ip(jit, opline); |
4122 | 0 | if (GCC_GLOBAL_REGS) { |
4123 | 0 | zend_vm_opcode_handler_func_t handler = (zend_vm_opcode_handler_func_t)zend_get_opcode_handler_func(opline); |
4124 | 0 | ir_CALL(IR_VOID, ir_CONST_FUNC(handler)); |
4125 | 0 | } else if (ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
4126 | 0 | zend_vm_opcode_handler_func_t handler = (zend_vm_opcode_handler_func_t)zend_get_opcode_handler_func(opline); |
4127 | 0 | ir_ref ip = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(handler), jit_FP(jit), jit_IP(jit)); |
4128 | 0 | jit_STORE_IP(jit, ip); |
4129 | 0 | } else { |
4130 | 0 | zend_vm_opcode_handler_t handler = opline->handler; |
4131 | 0 | ir_ref ip = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(handler), jit_FP(jit), jit_IP(jit)); |
4132 | 0 | jit_STORE_IP(jit, ip); |
4133 | 0 | } |
4134 | 0 | if (may_throw) { |
4135 | 0 | zend_jit_check_exception(jit); |
4136 | 0 | } |
4137 | | /* Skip the following OP_DATA */ |
4138 | 0 | switch (opline->opcode) { |
4139 | 0 | case ZEND_ASSIGN_DIM: |
4140 | 0 | case ZEND_ASSIGN_OBJ: |
4141 | 0 | case ZEND_ASSIGN_STATIC_PROP: |
4142 | 0 | case ZEND_ASSIGN_DIM_OP: |
4143 | 0 | case ZEND_ASSIGN_OBJ_OP: |
4144 | 0 | case ZEND_ASSIGN_STATIC_PROP_OP: |
4145 | 0 | case ZEND_ASSIGN_STATIC_PROP_REF: |
4146 | 0 | case ZEND_ASSIGN_OBJ_REF: |
4147 | 0 | case ZEND_FRAMELESS_ICALL_3: |
4148 | 0 | case ZEND_DECLARE_ATTRIBUTED_CONST: |
4149 | 0 | zend_jit_set_last_valid_opline(jit, opline + 2); |
4150 | 0 | break; |
4151 | 0 | default: |
4152 | 0 | zend_jit_set_last_valid_opline(jit, opline + 1); |
4153 | 0 | break; |
4154 | 0 | } |
4155 | 0 | return 1; |
4156 | 0 | } |
4157 | | |
4158 | | static int zend_jit_tail_handler(zend_jit_ctx *jit, const zend_op *opline) |
4159 | 0 | { |
4160 | 0 | ir_ref ref; |
4161 | 0 | zend_basic_block *bb; |
4162 | |
|
4163 | 0 | zend_jit_set_ip(jit, opline); |
4164 | 0 | if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) { |
4165 | 0 | if (opline->opcode == ZEND_DO_UCALL || |
4166 | 0 | opline->opcode == ZEND_DO_FCALL_BY_NAME || |
4167 | 0 | opline->opcode == ZEND_DO_FCALL || |
4168 | 0 | opline->opcode == ZEND_RETURN) { |
4169 | | |
4170 | | /* Use inlined HYBRID VM handler */ |
4171 | 0 | zend_vm_opcode_handler_t handler = opline->handler; |
4172 | 0 | ir_TAILCALL(IR_VOID, ir_CONST_FUNC(handler)); |
4173 | 0 | } else { |
4174 | 0 | zend_vm_opcode_handler_func_t handler = (zend_vm_opcode_handler_func_t)zend_get_opcode_handler_func(opline); |
4175 | 0 | ir_CALL(IR_VOID, ir_CONST_FUNC(handler)); |
4176 | 0 | ref = ir_LOAD_A(jit_IP(jit)); |
4177 | 0 | ir_TAILCALL(IR_VOID, ref); |
4178 | 0 | } |
4179 | 0 | } else { |
4180 | 0 | zend_vm_opcode_handler_t handler = opline->handler; |
4181 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
4182 | 0 | zend_jit_tailcall_handler(jit, ir_CONST_OPCODE_HANDLER_FUNC(handler)); |
4183 | 0 | } else if ((jit->ssa->cfg.flags & ZEND_FUNC_RECURSIVE_DIRECTLY) |
4184 | 0 | && (opline->opcode == ZEND_CATCH |
4185 | 0 | || opline->opcode == ZEND_FAST_CALL |
4186 | 0 | || opline->opcode == ZEND_FAST_RET |
4187 | 0 | || opline->opcode == ZEND_MATCH_ERROR |
4188 | 0 | || opline->opcode == ZEND_THROW |
4189 | 0 | || opline->opcode == ZEND_VERIFY_NEVER_TYPE)) { |
4190 | 0 | ir_ref ip = ir_CALL_2(IR_ADDR, ir_CONST_OPCODE_HANDLER_FUNC(handler), jit_FP(jit), jit_IP(jit)); |
4191 | 0 | zend_jit_vm_enter(jit, ip); |
4192 | 0 | } else { |
4193 | 0 | ir_TAILCALL_2(IR_ADDR, ir_CONST_OPCODE_HANDLER_FUNC(handler), jit_FP(jit), jit_IP(jit)); |
4194 | 0 | } |
4195 | 0 | } |
4196 | 0 | if (jit->b >= 0) { |
4197 | 0 | bb = &jit->ssa->cfg.blocks[jit->b]; |
4198 | 0 | if (bb->successors_count > 0 |
4199 | 0 | && (opline->opcode == ZEND_DO_FCALL |
4200 | 0 | || opline->opcode == ZEND_DO_UCALL |
4201 | 0 | || opline->opcode == ZEND_DO_FCALL_BY_NAME |
4202 | 0 | || opline->opcode == ZEND_INCLUDE_OR_EVAL |
4203 | 0 | || opline->opcode == ZEND_GENERATOR_CREATE |
4204 | 0 | || opline->opcode == ZEND_YIELD |
4205 | 0 | || opline->opcode == ZEND_YIELD_FROM |
4206 | 0 | || opline->opcode == ZEND_FAST_CALL)) { |
4207 | | /* Add a fake control edge from UNREACHABLE to the following ENTRY */ |
4208 | 0 | int succ; |
4209 | |
|
4210 | 0 | if (bb->successors_count == 1) { |
4211 | 0 | succ = bb->successors[0]; |
4212 | 0 | ZEND_ASSERT(jit->ssa->cfg.blocks[succ].flags & ZEND_BB_ENTRY); |
4213 | 0 | } else { |
4214 | | /* Use only the following successor of FAST_CALL */ |
4215 | 0 | ZEND_ASSERT(opline->opcode == ZEND_FAST_CALL); |
4216 | 0 | succ = jit->b + 1; |
4217 | | /* we need an entry */ |
4218 | 0 | jit->ssa->cfg.blocks[succ].flags |= ZEND_BB_ENTRY; |
4219 | 0 | } |
4220 | 0 | ref = jit->ctx.insns_count - 1; |
4221 | 0 | ZEND_ASSERT(jit->ctx.ir_base[ref].op == IR_UNREACHABLE || jit->ctx.ir_base[ref].op == IR_RETURN); |
4222 | 0 | ref = zend_jit_continue_entry(jit, ref, jit->ssa->cfg.blocks[succ].start); |
4223 | 0 | _zend_jit_add_predecessor_ref(jit, succ, jit->b, ref); |
4224 | 0 | } |
4225 | 0 | jit->b = -1; |
4226 | 0 | zend_jit_reset_last_valid_opline(jit); |
4227 | 0 | } |
4228 | 0 | return 1; |
4229 | 0 | } |
4230 | | |
4231 | | static int zend_jit_call(zend_jit_ctx *jit, const zend_op *opline, unsigned int next_block) |
4232 | 0 | { |
4233 | 0 | return zend_jit_tail_handler(jit, opline); |
4234 | 0 | } |
4235 | | |
4236 | | static int zend_jit_spill_store(zend_jit_ctx *jit, zend_jit_addr src, zend_jit_addr dst, uint32_t info, bool set_type) |
4237 | 0 | { |
4238 | 0 | ZEND_ASSERT(Z_MODE(src) == IS_REG); |
4239 | 0 | ZEND_ASSERT(Z_MODE(dst) == IS_MEM_ZVAL); |
4240 | |
|
4241 | 0 | if ((info & MAY_BE_ANY) == MAY_BE_LONG) { |
4242 | 0 | jit_set_Z_LVAL(jit, dst, zend_jit_use_reg(jit, src)); |
4243 | 0 | if (set_type && |
4244 | 0 | (Z_REG(dst) != ZREG_FP || |
4245 | 0 | !JIT_G(current_frame) || |
4246 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_LONG)) { |
4247 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_LONG); |
4248 | 0 | } |
4249 | 0 | } else if ((info & MAY_BE_ANY) == MAY_BE_DOUBLE) { |
4250 | 0 | jit_set_Z_DVAL(jit, dst, zend_jit_use_reg(jit, src)); |
4251 | 0 | if (set_type && |
4252 | 0 | (Z_REG(dst) != ZREG_FP || |
4253 | 0 | !JIT_G(current_frame) || |
4254 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_DOUBLE)) { |
4255 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_DOUBLE); |
4256 | 0 | } |
4257 | 0 | } else { |
4258 | 0 | ZEND_UNREACHABLE(); |
4259 | 0 | } |
4260 | 0 | return 1; |
4261 | 0 | } |
4262 | | |
4263 | | static int zend_jit_spill_store_inv(zend_jit_ctx *jit, zend_jit_addr src, zend_jit_addr dst, uint32_t info) |
4264 | 0 | { |
4265 | 0 | ZEND_ASSERT(Z_MODE(src) == IS_REG); |
4266 | 0 | ZEND_ASSERT(Z_MODE(dst) == IS_MEM_ZVAL); |
4267 | |
|
4268 | 0 | if (Z_LOAD(src) || Z_STORE(src)) { |
4269 | | /* it's not necessary to store register if it was previously loaded or already stored */ |
4270 | 0 | return 1; |
4271 | 0 | } |
4272 | | |
4273 | 0 | if ((info & MAY_BE_ANY) == MAY_BE_LONG) { |
4274 | 0 | jit_set_Z_LVAL(jit, dst, zend_jit_use_reg(jit, src)); |
4275 | 0 | if (Z_REG(dst) != ZREG_FP || !JIT_G(current_frame)) { |
4276 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_LONG); |
4277 | 0 | } else if (STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_LONG) { |
4278 | | /* invalidate memory type */ |
4279 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) = IS_UNKNOWN; |
4280 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_LONG); |
4281 | 0 | } |
4282 | 0 | } else if ((info & MAY_BE_ANY) == MAY_BE_DOUBLE) { |
4283 | 0 | jit_set_Z_DVAL(jit, dst, zend_jit_use_reg(jit, src)); |
4284 | 0 | if (Z_REG(dst) != ZREG_FP || !JIT_G(current_frame)) { |
4285 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_DOUBLE); |
4286 | 0 | } else if (STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_DOUBLE) { |
4287 | | /* invalidate memory type */ |
4288 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) = IS_UNKNOWN; |
4289 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_DOUBLE); |
4290 | 0 | } |
4291 | 0 | } else { |
4292 | 0 | ZEND_UNREACHABLE(); |
4293 | 0 | } |
4294 | 0 | return 1; |
4295 | 0 | } |
4296 | | |
4297 | | static int zend_jit_load_reg(zend_jit_ctx *jit, zend_jit_addr src, zend_jit_addr dst, uint32_t info) |
4298 | 0 | { |
4299 | 0 | ZEND_ASSERT(Z_MODE(src) == IS_MEM_ZVAL); |
4300 | 0 | ZEND_ASSERT(Z_MODE(dst) == IS_REG); |
4301 | |
|
4302 | 0 | if ((info & MAY_BE_ANY) == MAY_BE_LONG) { |
4303 | 0 | zend_jit_def_reg(jit, dst, jit_Z_LVAL(jit, src)); |
4304 | 0 | } else if ((info & MAY_BE_ANY) == MAY_BE_DOUBLE) { |
4305 | 0 | zend_jit_def_reg(jit, dst, jit_Z_DVAL(jit, src)); |
4306 | 0 | } else { |
4307 | 0 | ZEND_UNREACHABLE(); |
4308 | 0 | } |
4309 | 0 | return 1; |
4310 | 0 | } |
4311 | | |
4312 | | static int zend_jit_store_var(zend_jit_ctx *jit, uint32_t info, int var, int ssa_var, bool set_type) |
4313 | 0 | { |
4314 | 0 | zend_jit_addr src = ZEND_ADDR_REG(ssa_var); |
4315 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
4316 | |
|
4317 | 0 | return zend_jit_spill_store(jit, src, dst, info, set_type); |
4318 | 0 | } |
4319 | | |
4320 | | static int zend_jit_store_ref(zend_jit_ctx *jit, uint32_t info, int var, int32_t src, bool set_type) |
4321 | 0 | { |
4322 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
4323 | |
|
4324 | 0 | if ((info & MAY_BE_ANY) == MAY_BE_LONG) { |
4325 | 0 | jit_set_Z_LVAL(jit, dst, src); |
4326 | 0 | if (set_type && |
4327 | 0 | (Z_REG(dst) != ZREG_FP || |
4328 | 0 | !JIT_G(current_frame) || |
4329 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_LONG)) { |
4330 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_LONG); |
4331 | 0 | } |
4332 | 0 | } else if ((info & MAY_BE_ANY) == MAY_BE_DOUBLE) { |
4333 | 0 | jit_set_Z_DVAL(jit, dst, src); |
4334 | 0 | if (set_type && |
4335 | 0 | (Z_REG(dst) != ZREG_FP || |
4336 | 0 | !JIT_G(current_frame) || |
4337 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_DOUBLE)) { |
4338 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_DOUBLE); |
4339 | 0 | } |
4340 | 0 | } else { |
4341 | 0 | ZEND_UNREACHABLE(); |
4342 | 0 | } |
4343 | 0 | return 1; |
4344 | 0 | } |
4345 | | |
4346 | | static ir_ref zend_jit_deopt_rload(zend_jit_ctx *jit, ir_type type, int32_t reg) |
4347 | 0 | { |
4348 | 0 | ir_ref ref = jit->ctx.control; |
4349 | 0 | ir_insn *insn; |
4350 | |
|
4351 | 0 | while (1) { |
4352 | 0 | insn = &jit->ctx.ir_base[ref]; |
4353 | 0 | if (insn->op == IR_RLOAD && insn->op2 == reg) { |
4354 | 0 | ZEND_ASSERT(insn->type == type); |
4355 | 0 | return ref; |
4356 | 0 | } else if (insn->op == IR_START) { |
4357 | 0 | break; |
4358 | 0 | } |
4359 | 0 | ref = insn->op1; |
4360 | 0 | } |
4361 | 0 | return ir_RLOAD(type, reg); |
4362 | 0 | } |
4363 | | |
4364 | | /* Same as zend_jit_deopt_rload(), but 'reg' may be spilled on C stack */ |
4365 | | static ir_ref zend_jit_deopt_rload_spilled(zend_jit_ctx *jit, ir_type type, int8_t reg, int32_t offset) |
4366 | 0 | { |
4367 | 0 | ZEND_ASSERT(reg >= 0); |
4368 | |
|
4369 | 0 | if (IR_REG_SPILLED(reg)) { |
4370 | 0 | return ir_LOAD(type, ir_ADD_OFFSET(zend_jit_deopt_rload(jit, type, IR_REG_NUM(reg)), offset)); |
4371 | 0 | } else { |
4372 | 0 | return zend_jit_deopt_rload(jit, type, reg); |
4373 | 0 | } |
4374 | 0 | } |
4375 | | |
4376 | | static int zend_jit_store_const_long(zend_jit_ctx *jit, int var, zend_long val) |
4377 | 0 | { |
4378 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
4379 | 0 | ir_ref src = ir_CONST_LONG(val); |
4380 | |
|
4381 | 0 | if (jit->ra && jit->ra[var].ref == IR_NULL) { |
4382 | 0 | zend_jit_def_reg(jit, ZEND_ADDR_REG(var), src); |
4383 | 0 | } |
4384 | 0 | jit_set_Z_LVAL(jit, dst, src); |
4385 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_LONG); |
4386 | 0 | return 1; |
4387 | 0 | } |
4388 | | |
4389 | | static int zend_jit_store_const_double(zend_jit_ctx *jit, int var, double val) |
4390 | 0 | { |
4391 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
4392 | 0 | ir_ref src = ir_CONST_DOUBLE(val); |
4393 | |
|
4394 | 0 | if (jit->ra && jit->ra[var].ref == IR_NULL) { |
4395 | 0 | zend_jit_def_reg(jit, ZEND_ADDR_REG(var), src); |
4396 | 0 | } |
4397 | 0 | jit_set_Z_DVAL(jit, dst, src); |
4398 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_DOUBLE); |
4399 | 0 | return 1; |
4400 | 0 | } |
4401 | | |
4402 | | static int zend_jit_store_type(zend_jit_ctx *jit, int var, uint8_t type) |
4403 | 0 | { |
4404 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
4405 | |
|
4406 | 0 | ZEND_ASSERT(type <= IS_DOUBLE); |
4407 | 0 | jit_set_Z_TYPE_INFO(jit, dst, type); |
4408 | 0 | return 1; |
4409 | 0 | } |
4410 | | |
4411 | | static int zend_jit_store_reg(zend_jit_ctx *jit, uint32_t info, int var, int8_t reg, bool in_mem, bool set_type) |
4412 | 0 | { |
4413 | 0 | zend_jit_addr src; |
4414 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
4415 | 0 | ir_type type; |
4416 | |
|
4417 | 0 | if ((info & MAY_BE_ANY) == MAY_BE_LONG) { |
4418 | 0 | type = IR_LONG; |
4419 | 0 | src = zend_jit_deopt_rload(jit, type, reg); |
4420 | 0 | if (jit->ra && jit->ra[var].ref == IR_NULL) { |
4421 | 0 | zend_jit_def_reg(jit, ZEND_ADDR_REG(var), src); |
4422 | 0 | } else if (!in_mem) { |
4423 | 0 | jit_set_Z_LVAL(jit, dst, src); |
4424 | 0 | if (set_type && |
4425 | 0 | (Z_REG(dst) != ZREG_FP || |
4426 | 0 | !JIT_G(current_frame) || |
4427 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_LONG)) { |
4428 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_LONG); |
4429 | 0 | } |
4430 | 0 | } |
4431 | 0 | } else if ((info & MAY_BE_ANY) == MAY_BE_DOUBLE) { |
4432 | 0 | type = IR_DOUBLE; |
4433 | 0 | src = zend_jit_deopt_rload(jit, type, reg); |
4434 | 0 | if (jit->ra && jit->ra[var].ref == IR_NULL) { |
4435 | 0 | zend_jit_def_reg(jit, ZEND_ADDR_REG(var), src); |
4436 | 0 | } else if (!in_mem) { |
4437 | 0 | jit_set_Z_DVAL(jit, dst, src); |
4438 | 0 | if (set_type && |
4439 | 0 | (Z_REG(dst) != ZREG_FP || |
4440 | 0 | !JIT_G(current_frame) || |
4441 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_DOUBLE)) { |
4442 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_DOUBLE); |
4443 | 0 | } |
4444 | 0 | } |
4445 | 0 | } else { |
4446 | 0 | ZEND_UNREACHABLE(); |
4447 | 0 | } |
4448 | 0 | return 1; |
4449 | 0 | } |
4450 | | |
4451 | | static int zend_jit_store_spill_slot(zend_jit_ctx *jit, uint32_t info, int var, int8_t reg, int32_t offset, bool set_type) |
4452 | 0 | { |
4453 | 0 | zend_jit_addr src; |
4454 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
4455 | |
|
4456 | 0 | if ((info & MAY_BE_ANY) == MAY_BE_LONG) { |
4457 | 0 | src = ir_LOAD_L(ir_ADD_OFFSET(ir_RLOAD_A(reg), offset)); |
4458 | 0 | if (jit->ra && jit->ra[var].ref == IR_NULL) { |
4459 | 0 | zend_jit_def_reg(jit, ZEND_ADDR_REG(var), src); |
4460 | 0 | } else { |
4461 | 0 | jit_set_Z_LVAL(jit, dst, src); |
4462 | 0 | if (set_type && |
4463 | 0 | (Z_REG(dst) != ZREG_FP || |
4464 | 0 | !JIT_G(current_frame) || |
4465 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_LONG)) { |
4466 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_LONG); |
4467 | 0 | } |
4468 | 0 | } |
4469 | 0 | } else if ((info & MAY_BE_ANY) == MAY_BE_DOUBLE) { |
4470 | 0 | src = ir_LOAD_D(ir_ADD_OFFSET(ir_RLOAD_A(reg), offset)); |
4471 | 0 | if (jit->ra && jit->ra[var].ref == IR_NULL) { |
4472 | 0 | zend_jit_def_reg(jit, ZEND_ADDR_REG(var), src); |
4473 | 0 | } else { |
4474 | 0 | jit_set_Z_DVAL(jit, dst, src); |
4475 | 0 | if (set_type && |
4476 | 0 | (Z_REG(dst) != ZREG_FP || |
4477 | 0 | !JIT_G(current_frame) || |
4478 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(dst))) != IS_DOUBLE)) { |
4479 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_DOUBLE); |
4480 | 0 | } |
4481 | 0 | } |
4482 | 0 | } else { |
4483 | 0 | ZEND_UNREACHABLE(); |
4484 | 0 | } |
4485 | 0 | return 1; |
4486 | 0 | } |
4487 | | |
4488 | | static int zend_jit_store_var_type(zend_jit_ctx *jit, int var, uint32_t type) |
4489 | 0 | { |
4490 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
4491 | |
|
4492 | 0 | jit_set_Z_TYPE_INFO(jit, dst, type); |
4493 | 0 | return 1; |
4494 | 0 | } |
4495 | | |
4496 | | static int zend_jit_zval_try_addref(zend_jit_ctx *jit, zend_jit_addr var_addr) |
4497 | 0 | { |
4498 | 0 | ir_ref if_refcounted, end1; |
4499 | |
|
4500 | 0 | if_refcounted = jit_if_REFCOUNTED(jit, var_addr); |
4501 | 0 | ir_IF_FALSE(if_refcounted); |
4502 | 0 | end1 = ir_END(); |
4503 | 0 | ir_IF_TRUE(if_refcounted); |
4504 | 0 | jit_GC_ADDREF(jit, jit_Z_PTR(jit, var_addr)); |
4505 | 0 | ir_MERGE_WITH(end1); |
4506 | 0 | return 1; |
4507 | 0 | } |
4508 | | |
4509 | | static int zend_jit_store_var_if_necessary(zend_jit_ctx *jit, int var, zend_jit_addr src, uint32_t info) |
4510 | 0 | { |
4511 | 0 | if (Z_MODE(src) == IS_REG && Z_STORE(src)) { |
4512 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var); |
4513 | 0 | return zend_jit_spill_store(jit, src, dst, info, true); |
4514 | 0 | } |
4515 | 0 | return 1; |
4516 | 0 | } |
4517 | | |
4518 | | static int zend_jit_store_var_if_necessary_ex(zend_jit_ctx *jit, int var, zend_jit_addr src, uint32_t info, zend_jit_addr old, uint32_t old_info) |
4519 | 0 | { |
4520 | 0 | if (Z_MODE(src) == IS_REG && Z_STORE(src)) { |
4521 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var); |
4522 | 0 | bool set_type = true; |
4523 | |
|
4524 | 0 | if ((info & (MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF)) == |
4525 | 0 | (old_info & (MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF))) { |
4526 | 0 | if (Z_MODE(old) != IS_REG || Z_LOAD(old) || Z_STORE(old)) { |
4527 | 0 | if (JIT_G(current_frame)) { |
4528 | 0 | uint32_t mem_type = STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var)); |
4529 | |
|
4530 | 0 | if (mem_type != IS_UNKNOWN |
4531 | 0 | && (info & (MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF)) == (1 << mem_type)) { |
4532 | 0 | set_type = false; |
4533 | 0 | } |
4534 | 0 | } else { |
4535 | 0 | set_type = false; |
4536 | 0 | } |
4537 | 0 | } |
4538 | 0 | } |
4539 | 0 | return zend_jit_spill_store(jit, src, dst, info, set_type); |
4540 | 0 | } |
4541 | 0 | return 1; |
4542 | 0 | } |
4543 | | |
4544 | | static int zend_jit_load_var(zend_jit_ctx *jit, uint32_t info, int var, int ssa_var) |
4545 | 0 | { |
4546 | 0 | zend_jit_addr src = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
4547 | 0 | zend_jit_addr dst = ZEND_ADDR_REG(ssa_var); |
4548 | |
|
4549 | 0 | return zend_jit_load_reg(jit, src, dst, info); |
4550 | 0 | } |
4551 | | |
4552 | | static int zend_jit_invalidate_var_if_necessary(zend_jit_ctx *jit, uint8_t op_type, zend_jit_addr addr, znode_op op) |
4553 | 0 | { |
4554 | 0 | if ((op_type & (IS_TMP_VAR|IS_VAR)) && Z_MODE(addr) == IS_REG && !Z_LOAD(addr) && !Z_STORE(addr)) { |
4555 | | /* Invalidate operand type to prevent incorrect destuction by exception_handler_free_op1_op2() */ |
4556 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, op.var); |
4557 | 0 | jit_set_Z_TYPE_INFO(jit, dst, IS_UNDEF); |
4558 | 0 | } |
4559 | 0 | return 1; |
4560 | 0 | } |
4561 | | |
4562 | | static int zend_jit_update_regs(zend_jit_ctx *jit, uint32_t var, zend_jit_addr src, zend_jit_addr dst, uint32_t info) |
4563 | 0 | { |
4564 | 0 | if (!zend_jit_same_addr(src, dst)) { |
4565 | 0 | if (Z_MODE(src) == IS_REG) { |
4566 | 0 | if (Z_MODE(dst) == IS_REG) { |
4567 | 0 | zend_jit_def_reg(jit, dst, zend_jit_use_reg(jit, src)); |
4568 | 0 | if (!Z_LOAD(src) && !Z_STORE(src) && Z_STORE(dst)) { |
4569 | 0 | zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var); |
4570 | |
|
4571 | 0 | if (!zend_jit_spill_store(jit, dst, var_addr, info, |
4572 | 0 | JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || |
4573 | 0 | JIT_G(current_frame) == NULL || |
4574 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var)) == IS_UNKNOWN || |
4575 | 0 | (1 << STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var))) != (info & MAY_BE_ANY) |
4576 | 0 | )) { |
4577 | 0 | return 0; |
4578 | 0 | } |
4579 | 0 | } |
4580 | 0 | } else if (Z_MODE(dst) == IS_MEM_ZVAL) { |
4581 | 0 | if (!Z_LOAD(src) && !Z_STORE(src)) { |
4582 | 0 | if (!zend_jit_spill_store(jit, src, dst, info, |
4583 | 0 | JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || |
4584 | 0 | JIT_G(current_frame) == NULL || |
4585 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var)) == IS_UNKNOWN || |
4586 | 0 | (1 << STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var))) != (info & MAY_BE_ANY) |
4587 | 0 | )) { |
4588 | 0 | return 0; |
4589 | 0 | } |
4590 | 0 | } |
4591 | 0 | } else { |
4592 | 0 | ZEND_UNREACHABLE(); |
4593 | 0 | } |
4594 | 0 | } else if (Z_MODE(src) == IS_MEM_ZVAL) { |
4595 | 0 | if (Z_MODE(dst) == IS_REG) { |
4596 | 0 | if (!zend_jit_load_reg(jit, src, dst, info)) { |
4597 | 0 | return 0; |
4598 | 0 | } |
4599 | 0 | } else { |
4600 | 0 | ZEND_UNREACHABLE(); |
4601 | 0 | } |
4602 | 0 | } else { |
4603 | 0 | ZEND_UNREACHABLE(); |
4604 | 0 | } |
4605 | 0 | } else if (Z_MODE(dst) == IS_REG && Z_STORE(dst)) { |
4606 | 0 | dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var); |
4607 | 0 | if (!zend_jit_spill_store(jit, src, dst, info, |
4608 | 0 | JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || |
4609 | 0 | JIT_G(current_frame) == NULL || |
4610 | 0 | STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var)) == IS_UNKNOWN || |
4611 | 0 | (1 << STACK_MEM_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(var))) != (info & MAY_BE_ANY) |
4612 | 0 | )) { |
4613 | 0 | return 0; |
4614 | 0 | } |
4615 | 0 | } |
4616 | 0 | return 1; |
4617 | 0 | } |
4618 | | |
4619 | | struct jit_observer_fcall_is_unobserved_data { |
4620 | | ir_ref if_unobserved; |
4621 | | ir_ref ir_end_inputs; |
4622 | | }; |
4623 | | |
4624 | 0 | static struct jit_observer_fcall_is_unobserved_data jit_observer_fcall_is_unobserved_start(zend_jit_ctx *jit, const zend_function *func, ir_ref *observer_handler, ir_ref rx, ir_ref func_ref) { |
4625 | 0 | ir_ref run_time_cache; |
4626 | 0 | struct jit_observer_fcall_is_unobserved_data data = { .ir_end_inputs = IR_UNUSED }; |
4627 | 0 | if (func) { |
4628 | 0 | ZEND_ASSERT((func->common.fn_flags & (ZEND_ACC_CALL_VIA_TRAMPOLINE | ZEND_ACC_GENERATOR)) == 0); |
4629 | 0 | } else { |
4630 | | // JIT: if (function->common.fn_flags & (ZEND_ACC_CALL_VIA_TRAMPOLINE | ZEND_ACC_GENERATOR)) { |
4631 | 0 | ZEND_ASSERT(rx != IR_UNUSED); |
4632 | 0 | ir_ref if_trampoline_or_generator = ir_IF(ir_AND_U32( |
4633 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_function, common.fn_flags))), |
4634 | 0 | ir_CONST_U32(ZEND_ACC_CALL_VIA_TRAMPOLINE | ZEND_ACC_GENERATOR))); |
4635 | 0 | ir_IF_TRUE(if_trampoline_or_generator); |
4636 | 0 | ir_END_list(data.ir_end_inputs); |
4637 | 0 | ir_IF_FALSE(if_trampoline_or_generator); |
4638 | 0 | } |
4639 | 0 | if (func && (func->common.fn_flags & ZEND_ACC_CLOSURE) == 0 && ZEND_MAP_PTR_IS_OFFSET(func->common.run_time_cache)) { |
4640 | | // JIT: ZEND_MAP_PTR_GET_IMM(func->common.runtime_cache) |
4641 | 0 | run_time_cache = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_CG(map_ptr_base)), (uintptr_t)ZEND_MAP_PTR(func->common.run_time_cache))); |
4642 | 0 | #ifndef ZTS |
4643 | 0 | } else if (func && rx == IS_UNUSED) { // happens for internal functions only |
4644 | 0 | ZEND_ASSERT(!ZEND_USER_CODE(func->type)); |
4645 | 0 | run_time_cache = ir_LOAD_A(ir_ADD_OFFSET(ir_CONST_ADDR(func), offsetof(zend_op_array, run_time_cache__ptr))); |
4646 | 0 | #endif |
4647 | 0 | } else { |
4648 | | // Closures may be duplicated and have a different runtime cache. Use the regular run_time_cache access pattern for these |
4649 | 0 | if (func && ZEND_USER_CODE(func->type)) { // not a closure and definitely not an internal function |
4650 | 0 | run_time_cache = ir_LOAD_A(jit_CALL(rx, run_time_cache)); |
4651 | 0 | } else { |
4652 | | // JIT: ZEND_MAP_PTR_GET(func->common.runtime_cache) |
4653 | 0 | run_time_cache = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_CALL(rx, func)), offsetof(zend_op_array, run_time_cache__ptr))); |
4654 | 0 | ir_ref if_odd = ir_IF(ir_AND_A(run_time_cache, ir_CONST_ADDR(1))); |
4655 | 0 | ir_IF_TRUE(if_odd); |
4656 | |
|
4657 | 0 | ir_ref run_time_cache2 = ir_LOAD_A(ir_ADD_A(run_time_cache, ir_LOAD_A(jit_CG(map_ptr_base)))); |
4658 | |
|
4659 | 0 | ir_ref if_odd_end = ir_END(); |
4660 | 0 | ir_IF_FALSE(if_odd); |
4661 | | |
4662 | | // JIT: if (func->common.runtime_cache != NULL) { |
4663 | 0 | ir_ref if_rt_cache = ir_IF(ir_EQ(run_time_cache, IR_NULL)); |
4664 | 0 | ir_IF_TRUE(if_rt_cache); |
4665 | 0 | ir_END_list(data.ir_end_inputs); |
4666 | 0 | ir_IF_FALSE(if_rt_cache); |
4667 | |
|
4668 | 0 | ir_MERGE_WITH(if_odd_end); |
4669 | 0 | run_time_cache = ir_PHI_2(IR_ADDR, run_time_cache, run_time_cache2); |
4670 | 0 | } |
4671 | 0 | } |
4672 | | // JIT: observer_handler = runtime_cache + ZEND_OBSERVER_HANDLE(function) |
4673 | 0 | if (func) { |
4674 | 0 | *observer_handler = ir_ADD_OFFSET(run_time_cache, ZEND_OBSERVER_HANDLE(func) * sizeof(void *)); |
4675 | 0 | } else { |
4676 | | // JIT: (func->type == ZEND_INTERNAL_FUNCTION ? zend_observer_fcall_internal_function_extension : zend_observer_fcall_op_array_extension) * sizeof(void *) |
4677 | 0 | ir_ref tmp = ir_LOAD_U8(ir_ADD_OFFSET(func_ref, offsetof(zend_function, type))); |
4678 | 0 | ir_ref if_internal_func = ir_IF(ir_AND_U8(tmp, ir_CONST_U8(ZEND_INTERNAL_FUNCTION))); |
4679 | 0 | ir_IF_TRUE(if_internal_func); |
4680 | |
|
4681 | 0 | ir_ref observer_handler_internal = ir_ADD_OFFSET(run_time_cache, zend_observer_fcall_internal_function_extension * sizeof(void *)); |
4682 | |
|
4683 | 0 | ir_ref if_internal_func_end = ir_END(); |
4684 | 0 | ir_IF_FALSE(if_internal_func); |
4685 | |
|
4686 | 0 | ir_ref observer_handler_user = ir_ADD_OFFSET(run_time_cache, zend_observer_fcall_op_array_extension * sizeof(void *)); |
4687 | |
|
4688 | 0 | ir_MERGE_WITH(if_internal_func_end); |
4689 | 0 | *observer_handler = ir_PHI_2(IR_ADDR, observer_handler_internal, observer_handler_user); |
4690 | 0 | } |
4691 | | |
4692 | | // JIT: if (*observer_handler == ZEND_OBSERVER_NONE_OBSERVED) { |
4693 | 0 | data.if_unobserved = ir_IF(ir_EQ(ir_LOAD_A(*observer_handler), ir_CONST_ADDR(ZEND_OBSERVER_NONE_OBSERVED))); |
4694 | 0 | ir_IF_FALSE(data.if_unobserved); |
4695 | 0 | return data; |
4696 | 0 | } |
4697 | | |
4698 | | /* For frameless the true branch of if_unobserved is used and this function not called. */ |
4699 | 0 | static void jit_observer_fcall_is_unobserved_end(zend_jit_ctx *jit, struct jit_observer_fcall_is_unobserved_data *data) { |
4700 | 0 | ir_END_list(data->ir_end_inputs); |
4701 | 0 | ir_IF_TRUE(data->if_unobserved); |
4702 | 0 | ir_END_list(data->ir_end_inputs); |
4703 | 0 | ir_MERGE_list(data->ir_end_inputs); |
4704 | 0 | } |
4705 | | |
4706 | 0 | static void jit_observer_fcall_begin(zend_jit_ctx *jit, ir_ref rx, ir_ref observer_handler) { |
4707 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_observer_fcall_begin_prechecked), rx, observer_handler); |
4708 | 0 | } |
4709 | | |
4710 | 0 | static void jit_observer_fcall_end(zend_jit_ctx *jit, ir_ref rx, ir_ref res_ref) { |
4711 | | // JIT: if (execute_data == EG(current_observed_frame)) { |
4712 | 0 | ir_ref has_end_observer = ir_IF(ir_EQ(rx, ir_LOAD_A(jit_EG(current_observed_frame)))); |
4713 | 0 | ir_IF_TRUE(has_end_observer); |
4714 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_observer_fcall_end_prechecked), |
4715 | 0 | rx, res_ref); |
4716 | 0 | ir_MERGE_WITH_EMPTY_FALSE(has_end_observer); |
4717 | 0 | } |
4718 | | |
4719 | | static int zend_jit_inc_dec(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, uint32_t op1_def_info, zend_jit_addr op1_def_addr, uint32_t res_use_info, uint32_t res_info, zend_jit_addr res_addr, int may_overflow, int may_throw) |
4720 | 0 | { |
4721 | 0 | ir_ref if_long = IR_UNUSED; |
4722 | 0 | ir_ref op1_lval_ref = IR_UNUSED; |
4723 | 0 | ir_ref ref; |
4724 | 0 | ir_op op; |
4725 | |
|
4726 | 0 | if (op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY)-MAY_BE_LONG)) { |
4727 | 0 | if_long = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
4728 | 0 | ir_IF_TRUE(if_long); |
4729 | 0 | } |
4730 | 0 | if (opline->opcode == ZEND_POST_INC || opline->opcode == ZEND_POST_DEC) { |
4731 | 0 | op1_lval_ref = jit_Z_LVAL(jit, op1_addr); |
4732 | 0 | jit_set_Z_LVAL(jit, res_addr, op1_lval_ref); |
4733 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
4734 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
4735 | 0 | } |
4736 | 0 | } |
4737 | 0 | if (Z_MODE(op1_def_addr) == IS_MEM_ZVAL |
4738 | 0 | && Z_MODE(op1_addr) == IS_REG |
4739 | 0 | && !Z_LOAD(op1_addr) |
4740 | 0 | && !Z_STORE(op1_addr)) { |
4741 | 0 | jit_set_Z_TYPE_INFO(jit, op1_def_addr, IS_LONG); |
4742 | 0 | } |
4743 | 0 | if (opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_POST_INC) { |
4744 | 0 | op = may_overflow ? IR_ADD_OV : IR_ADD; |
4745 | 0 | } else { |
4746 | 0 | op = may_overflow ? IR_SUB_OV : IR_SUB; |
4747 | 0 | } |
4748 | 0 | if (!op1_lval_ref) { |
4749 | 0 | op1_lval_ref = jit_Z_LVAL(jit, op1_addr); |
4750 | 0 | } |
4751 | 0 | ref = ir_BINARY_OP_L(op, op1_lval_ref, ir_CONST_LONG(1)); |
4752 | 0 | if (op1_def_info & MAY_BE_LONG) { |
4753 | 0 | jit_set_Z_LVAL(jit, op1_def_addr, ref); |
4754 | 0 | } |
4755 | 0 | if (may_overflow && |
4756 | 0 | (((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD)) || |
4757 | 0 | ((opline->result_type != IS_UNUSED && (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_LONG|MAY_BE_GUARD))))) { |
4758 | 0 | int32_t exit_point; |
4759 | 0 | const void *exit_addr; |
4760 | 0 | zend_jit_trace_stack *stack; |
4761 | 0 | uint32_t old_op1_info, old_res_info = 0; |
4762 | |
|
4763 | 0 | stack = JIT_G(current_frame)->stack; |
4764 | 0 | old_op1_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var)); |
4765 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var), IS_DOUBLE, 0); |
4766 | 0 | if (opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_POST_INC) { |
4767 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->op1.var), ir_CONST_DOUBLE((double)ZEND_LONG_MAX + 1.0)); |
4768 | 0 | } else { |
4769 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->op1.var), ir_CONST_DOUBLE((double)ZEND_LONG_MIN - 1.0)); |
4770 | 0 | } |
4771 | 0 | if (opline->result_type != IS_UNUSED) { |
4772 | 0 | old_res_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var)); |
4773 | 0 | if (opline->opcode == ZEND_PRE_INC) { |
4774 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_DOUBLE, 0); |
4775 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var), ir_CONST_DOUBLE((double)ZEND_LONG_MAX + 1.0)); |
4776 | 0 | } else if (opline->opcode == ZEND_PRE_DEC) { |
4777 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_DOUBLE, 0); |
4778 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var), ir_CONST_DOUBLE((double)ZEND_LONG_MIN - 1.0)); |
4779 | 0 | } else if (opline->opcode == ZEND_POST_INC) { |
4780 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_LONG, 0); |
4781 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var), ir_CONST_LONG(ZEND_LONG_MAX)); |
4782 | 0 | } else if (opline->opcode == ZEND_POST_DEC) { |
4783 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_LONG, 0); |
4784 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var), ir_CONST_LONG(ZEND_LONG_MIN)); |
4785 | 0 | } |
4786 | 0 | } |
4787 | |
|
4788 | 0 | exit_point = zend_jit_trace_get_exit_point(opline + 1, 0); |
4789 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
4790 | 0 | ir_GUARD_NOT(ir_OVERFLOW(ref), ir_CONST_ADDR(exit_addr)); |
4791 | |
|
4792 | 0 | if ((opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_PRE_DEC) && |
4793 | 0 | opline->result_type != IS_UNUSED) { |
4794 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
4795 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
4796 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
4797 | 0 | } |
4798 | 0 | } |
4799 | |
|
4800 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var), old_op1_info); |
4801 | 0 | if (opline->result_type != IS_UNUSED) { |
4802 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var), old_res_info); |
4803 | 0 | } |
4804 | 0 | } else if (may_overflow) { |
4805 | 0 | ir_ref if_overflow; |
4806 | 0 | ir_ref merge_inputs = IR_UNUSED; |
4807 | |
|
4808 | 0 | if (((op1_def_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_DOUBLE|MAY_BE_GUARD)) |
4809 | 0 | || (opline->result_type != IS_UNUSED && (res_info & (MAY_BE_ANY|MAY_BE_GUARD)) == (MAY_BE_DOUBLE|MAY_BE_GUARD))) { |
4810 | 0 | int32_t exit_point; |
4811 | 0 | const void *exit_addr; |
4812 | 0 | zend_jit_trace_stack *stack; |
4813 | 0 | uint32_t old_res_info = 0, old_op1_info = 0; |
4814 | |
|
4815 | 0 | stack = JIT_G(current_frame)->stack; |
4816 | 0 | if (opline->result_type != IS_UNUSED) { |
4817 | 0 | old_res_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var)); |
4818 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_LONG, 0); |
4819 | 0 | if (opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_PRE_DEC) { |
4820 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var), ref); |
4821 | 0 | } else { |
4822 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var), op1_lval_ref); |
4823 | 0 | } |
4824 | 0 | } |
4825 | 0 | old_op1_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var)); |
4826 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var), IS_LONG, 0); |
4827 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->op1.var), ref); |
4828 | |
|
4829 | 0 | exit_point = zend_jit_trace_get_exit_point(opline + 1, 0); |
4830 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
4831 | 0 | ir_GUARD(ir_OVERFLOW(ref), ir_CONST_ADDR(exit_addr)); |
4832 | |
|
4833 | 0 | if (opline->result_type != IS_UNUSED) { |
4834 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var), old_res_info); |
4835 | 0 | } |
4836 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var), old_op1_info); |
4837 | 0 | } else { |
4838 | 0 | if_overflow = ir_IF(ir_OVERFLOW(ref)); |
4839 | 0 | ir_IF_FALSE(if_overflow); |
4840 | 0 | if ((opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_PRE_DEC) && |
4841 | 0 | opline->result_type != IS_UNUSED) { |
4842 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
4843 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
4844 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
4845 | 0 | } |
4846 | 0 | } |
4847 | 0 | ir_END_list(merge_inputs); |
4848 | | |
4849 | | /* overflow => cold path */ |
4850 | 0 | ir_IF_TRUE_cold(if_overflow); |
4851 | 0 | } |
4852 | |
|
4853 | 0 | if (opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_POST_INC) { |
4854 | 0 | if (Z_MODE(op1_def_addr) == IS_REG) { |
4855 | 0 | jit_set_Z_DVAL(jit, op1_def_addr, ir_CONST_DOUBLE((double)ZEND_LONG_MAX + 1.0)); |
4856 | 0 | } else { |
4857 | | #if SIZEOF_ZEND_LONG == 4 |
4858 | | jit_set_Z_LVAL(jit, op1_def_addr, ir_CONST_LONG(0)); |
4859 | | jit_set_Z_W2(jit, op1_def_addr, ir_CONST_U32(0x41e00000)); |
4860 | | #else |
4861 | 0 | jit_set_Z_LVAL(jit, op1_def_addr, ir_CONST_LONG(0x43e0000000000000)); |
4862 | 0 | #endif |
4863 | 0 | jit_set_Z_TYPE_INFO(jit, op1_def_addr, IS_DOUBLE); |
4864 | 0 | } |
4865 | 0 | } else { |
4866 | 0 | if (Z_MODE(op1_def_addr) == IS_REG) { |
4867 | 0 | jit_set_Z_DVAL(jit, op1_def_addr, ir_CONST_DOUBLE((double)ZEND_LONG_MIN - 1.0)); |
4868 | 0 | } else { |
4869 | | #if SIZEOF_ZEND_LONG == 4 |
4870 | | jit_set_Z_LVAL(jit, op1_def_addr, ir_CONST_LONG(0x00200000)); |
4871 | | jit_set_Z_W2(jit, op1_def_addr, ir_CONST_U32(0xc1e00000)); |
4872 | | #else |
4873 | 0 | jit_set_Z_LVAL(jit, op1_def_addr, ir_CONST_LONG(0xc3e0000000000000)); |
4874 | 0 | #endif |
4875 | 0 | jit_set_Z_TYPE_INFO(jit, op1_def_addr, IS_DOUBLE); |
4876 | 0 | } |
4877 | 0 | } |
4878 | 0 | if ((opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_PRE_DEC) && |
4879 | 0 | opline->result_type != IS_UNUSED) { |
4880 | 0 | if (opline->opcode == ZEND_PRE_INC) { |
4881 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
4882 | 0 | jit_set_Z_DVAL(jit, res_addr, ir_CONST_DOUBLE((double)ZEND_LONG_MAX + 1.0)); |
4883 | 0 | } else { |
4884 | | #if SIZEOF_ZEND_LONG == 4 |
4885 | | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0)); |
4886 | | jit_set_Z_W2(jit, res_addr, ir_CONST_U32(0x41e00000)); |
4887 | | #else |
4888 | 0 | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0x43e0000000000000)); |
4889 | 0 | #endif |
4890 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
4891 | 0 | } |
4892 | 0 | } else { |
4893 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
4894 | 0 | jit_set_Z_DVAL(jit, res_addr, ir_CONST_DOUBLE((double)ZEND_LONG_MIN - 1.0)); |
4895 | 0 | } else { |
4896 | | #if SIZEOF_ZEND_LONG == 4 |
4897 | | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0x00200000)); |
4898 | | jit_set_Z_W2(jit, res_addr, ir_CONST_U32(0xc1e00000)); |
4899 | | #else |
4900 | 0 | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0xc3e0000000000000)); |
4901 | 0 | #endif |
4902 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
4903 | 0 | } |
4904 | 0 | } |
4905 | 0 | } |
4906 | |
|
4907 | 0 | if (merge_inputs) { |
4908 | 0 | ir_END_list(merge_inputs); |
4909 | 0 | ir_MERGE_list(merge_inputs); |
4910 | 0 | } |
4911 | 0 | } else { |
4912 | 0 | if ((opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_PRE_DEC) && |
4913 | 0 | opline->result_type != IS_UNUSED) { |
4914 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
4915 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
4916 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
4917 | 0 | } |
4918 | 0 | } |
4919 | 0 | } |
4920 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) { |
4921 | 0 | ir_ref merge_inputs = ir_END(); |
4922 | | |
4923 | | /* !is_long => cold path */ |
4924 | 0 | ir_IF_FALSE_cold(if_long); |
4925 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) { |
4926 | 0 | jit_SET_EX_OPLINE(jit, opline); |
4927 | 0 | if (op1_info & MAY_BE_UNDEF) { |
4928 | 0 | ir_ref if_def; |
4929 | |
|
4930 | 0 | if_def = jit_if_not_Z_TYPE(jit, op1_addr, IS_UNDEF); |
4931 | 0 | ir_IF_FALSE_cold(if_def); |
4932 | | |
4933 | | // zend_error_unchecked(E_WARNING, "Undefined variable $%S", CV_DEF_OF(EX_VAR_TO_NUM(opline->op1.var))); |
4934 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op1.var)); |
4935 | |
|
4936 | 0 | jit_set_Z_TYPE_INFO(jit, op1_def_addr, IS_NULL); |
4937 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_def); |
4938 | |
|
4939 | 0 | op1_info |= MAY_BE_NULL; |
4940 | 0 | } |
4941 | |
|
4942 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
4943 | |
|
4944 | 0 | if (op1_info & MAY_BE_REF) { |
4945 | 0 | ir_ref if_ref, if_typed, func, ref2, arg2; |
4946 | |
|
4947 | 0 | if_ref = jit_if_Z_TYPE_ref(jit, ref, ir_CONST_U8(IS_REFERENCE)); |
4948 | 0 | ir_IF_TRUE(if_ref); |
4949 | 0 | ref2 = jit_Z_PTR_ref(jit, ref); |
4950 | |
|
4951 | 0 | if_typed = jit_if_TYPED_REF(jit, ref2); |
4952 | 0 | ir_IF_TRUE(if_typed); |
4953 | |
|
4954 | 0 | if (RETURN_VALUE_USED(opline)) { |
4955 | 0 | ZEND_ASSERT(Z_MODE(res_addr) != IS_REG); |
4956 | 0 | arg2 = jit_ZVAL_ADDR(jit, res_addr); |
4957 | 0 | } else { |
4958 | 0 | arg2 = IR_NULL; |
4959 | 0 | } |
4960 | 0 | if (opline->opcode == ZEND_PRE_INC) { |
4961 | 0 | func = ir_CONST_FC_FUNC(zend_jit_pre_inc_typed_ref); |
4962 | 0 | } else if (opline->opcode == ZEND_PRE_DEC) { |
4963 | 0 | func = ir_CONST_FC_FUNC(zend_jit_pre_dec_typed_ref); |
4964 | 0 | } else if (opline->opcode == ZEND_POST_INC) { |
4965 | 0 | func = ir_CONST_FC_FUNC(zend_jit_post_inc_typed_ref); |
4966 | 0 | } else if (opline->opcode == ZEND_POST_DEC) { |
4967 | 0 | func = ir_CONST_FC_FUNC(zend_jit_post_dec_typed_ref); |
4968 | 0 | } else { |
4969 | 0 | ZEND_UNREACHABLE(); |
4970 | 0 | } |
4971 | | |
4972 | 0 | ir_CALL_2(IR_VOID, func, ref2, arg2); |
4973 | 0 | zend_jit_check_exception(jit); |
4974 | 0 | ir_END_list(merge_inputs); |
4975 | |
|
4976 | 0 | ir_IF_FALSE(if_typed); |
4977 | 0 | ref2 = ir_ADD_OFFSET(ref2, offsetof(zend_reference, val)); |
4978 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_ref); |
4979 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
4980 | 0 | } |
4981 | | |
4982 | 0 | if (opline->opcode == ZEND_POST_INC || opline->opcode == ZEND_POST_DEC) { |
4983 | 0 | jit_ZVAL_COPY(jit, |
4984 | 0 | res_addr, |
4985 | 0 | res_use_info, |
4986 | 0 | ZEND_ADDR_REF_ZVAL(ref), op1_info, true); |
4987 | 0 | } |
4988 | 0 | if (opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_POST_INC) { |
4989 | 0 | if (opline->opcode == ZEND_PRE_INC && opline->result_type != IS_UNUSED) { |
4990 | 0 | ir_ref arg2 = jit_ZVAL_ADDR(jit, res_addr); |
4991 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_pre_inc), ref, arg2); |
4992 | 0 | } else { |
4993 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(increment_function), ref); |
4994 | 0 | } |
4995 | 0 | } else { |
4996 | 0 | if (opline->opcode == ZEND_PRE_DEC && opline->result_type != IS_UNUSED) { |
4997 | 0 | ir_ref arg2 = jit_ZVAL_ADDR(jit, res_addr); |
4998 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_pre_dec), ref, arg2); |
4999 | 0 | } else { |
5000 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(decrement_function), ref); |
5001 | 0 | } |
5002 | 0 | } |
5003 | 0 | if (may_throw) { |
5004 | 0 | zend_jit_check_exception(jit); |
5005 | 0 | } |
5006 | 0 | } else { |
5007 | 0 | ref = jit_Z_DVAL(jit, op1_addr); |
5008 | 0 | if (opline->opcode == ZEND_POST_INC || opline->opcode == ZEND_POST_DEC) { |
5009 | 0 | jit_set_Z_DVAL(jit, res_addr, ref); |
5010 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
5011 | 0 | } |
5012 | 0 | if (opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_POST_INC) { |
5013 | 0 | op = IR_ADD; |
5014 | 0 | } else { |
5015 | 0 | op = IR_SUB; |
5016 | 0 | } |
5017 | 0 | ref = ir_BINARY_OP_D(op, ref, ir_CONST_DOUBLE(1.0)); |
5018 | 0 | jit_set_Z_DVAL(jit, op1_def_addr, ref); |
5019 | 0 | if ((opline->opcode == ZEND_PRE_INC || opline->opcode == ZEND_PRE_DEC) && |
5020 | 0 | opline->result_type != IS_UNUSED) { |
5021 | 0 | jit_set_Z_DVAL(jit, res_addr, ref); |
5022 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
5023 | 0 | } |
5024 | 0 | } |
5025 | 0 | ir_END_list(merge_inputs); |
5026 | 0 | ir_MERGE_list(merge_inputs); |
5027 | 0 | } |
5028 | 0 | if (!zend_jit_store_var_if_necessary_ex(jit, opline->op1.var, op1_def_addr, op1_def_info, op1_addr, op1_info)) { |
5029 | 0 | return 0; |
5030 | 0 | } |
5031 | 0 | if (opline->result_type != IS_UNUSED) { |
5032 | 0 | if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, res_info)) { |
5033 | 0 | return 0; |
5034 | 0 | } |
5035 | 0 | } |
5036 | 0 | return 1; |
5037 | 0 | } |
5038 | | |
5039 | | static int zend_jit_math_long_long(zend_jit_ctx *jit, |
5040 | | const zend_op *opline, |
5041 | | uint8_t opcode, |
5042 | | zend_jit_addr op1_addr, |
5043 | | zend_jit_addr op2_addr, |
5044 | | zend_jit_addr res_addr, |
5045 | | uint32_t res_info, |
5046 | | uint32_t res_use_info, |
5047 | | int may_overflow) |
5048 | 0 | { |
5049 | 0 | bool same_ops = zend_jit_same_addr(op1_addr, op2_addr); |
5050 | 0 | ir_op op; |
5051 | 0 | ir_ref op1, op2, ref, if_overflow = IR_UNUSED; |
5052 | |
|
5053 | 0 | if (opcode == ZEND_ADD) { |
5054 | 0 | op = may_overflow ? IR_ADD_OV : IR_ADD; |
5055 | 0 | } else if (opcode == ZEND_SUB) { |
5056 | 0 | op = may_overflow ? IR_SUB_OV : IR_SUB; |
5057 | 0 | } else if (opcode == ZEND_MUL) { |
5058 | 0 | op = may_overflow ? IR_MUL_OV : IR_MUL; |
5059 | 0 | } else { |
5060 | 0 | ZEND_UNREACHABLE(); |
5061 | 0 | } |
5062 | 0 | op1 = jit_Z_LVAL(jit, op1_addr); |
5063 | 0 | op2 = (same_ops) ? op1 : jit_Z_LVAL(jit, op2_addr); |
5064 | 0 | ref = ir_BINARY_OP_L(op, op1, op2); |
5065 | |
|
5066 | 0 | if (may_overflow) { |
5067 | 0 | if (res_info & MAY_BE_GUARD) { |
5068 | 0 | if ((res_info & MAY_BE_ANY) == MAY_BE_LONG) { |
5069 | 0 | zend_jit_trace_stack *stack = JIT_G(current_frame)->stack; |
5070 | 0 | uint32_t old_res_info; |
5071 | 0 | int32_t exit_point; |
5072 | 0 | const void *exit_addr; |
5073 | |
|
5074 | 0 | if (opline->opcode == ZEND_ADD |
5075 | 0 | && Z_MODE(op2_addr) == IS_CONST_ZVAL && Z_LVAL_P(Z_ZV(op2_addr)) == 1) { |
5076 | 0 | old_res_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var)); |
5077 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_DOUBLE, 0); |
5078 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var), ir_CONST_DOUBLE((double)ZEND_LONG_MAX + 1.0)); |
5079 | 0 | exit_point = zend_jit_trace_get_exit_point(opline + 1, 0); |
5080 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var), old_res_info); |
5081 | 0 | } else if (opline->opcode == ZEND_SUB |
5082 | 0 | && Z_MODE(op2_addr) == IS_CONST_ZVAL && Z_LVAL_P(Z_ZV(op2_addr)) == 1) { |
5083 | 0 | old_res_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var)); |
5084 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_DOUBLE, 0); |
5085 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var), ir_CONST_DOUBLE((double)ZEND_LONG_MIN - 1.0)); |
5086 | 0 | exit_point = zend_jit_trace_get_exit_point(opline + 1, 0); |
5087 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var), old_res_info); |
5088 | 0 | } else { |
5089 | 0 | exit_point = zend_jit_trace_get_exit_point(opline, 0); |
5090 | 0 | } |
5091 | |
|
5092 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
5093 | 0 | if (!exit_addr) { |
5094 | 0 | return 0; |
5095 | 0 | } |
5096 | 0 | ir_GUARD_NOT(ir_OVERFLOW(ref), ir_CONST_ADDR(exit_addr)); |
5097 | 0 | may_overflow = 0; |
5098 | 0 | } else if ((res_info & MAY_BE_ANY) == MAY_BE_DOUBLE) { |
5099 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
5100 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
5101 | |
|
5102 | 0 | if (!exit_addr) { |
5103 | 0 | return 0; |
5104 | 0 | } |
5105 | 0 | ir_GUARD(ir_OVERFLOW(ref), ir_CONST_ADDR(exit_addr)); |
5106 | 0 | } else { |
5107 | 0 | ZEND_UNREACHABLE(); |
5108 | 0 | } |
5109 | 0 | } else { |
5110 | 0 | if_overflow = ir_IF(ir_OVERFLOW(ref)); |
5111 | 0 | ir_IF_FALSE(if_overflow); |
5112 | 0 | } |
5113 | 0 | } |
5114 | | |
5115 | 0 | if ((res_info & MAY_BE_ANY) != MAY_BE_DOUBLE) { |
5116 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
5117 | |
|
5118 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
5119 | 0 | if (!zend_jit_same_addr(op1_addr, res_addr)) { |
5120 | 0 | if ((res_use_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF|MAY_BE_GUARD)) != MAY_BE_LONG) { |
5121 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
5122 | 0 | } |
5123 | 0 | } |
5124 | 0 | } |
5125 | 0 | } |
5126 | |
|
5127 | 0 | if (may_overflow) { |
5128 | 0 | ir_ref fast_path = IR_UNUSED; |
5129 | |
|
5130 | 0 | if ((res_info & MAY_BE_ANY) != MAY_BE_DOUBLE) { |
5131 | 0 | fast_path = ir_END(); |
5132 | 0 | ir_IF_TRUE_cold(if_overflow); |
5133 | 0 | } |
5134 | 0 | if (opcode == ZEND_ADD) { |
5135 | 0 | if (Z_MODE(op2_addr) == IS_CONST_ZVAL && Z_LVAL_P(Z_ZV(op2_addr)) == 1) { |
5136 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5137 | 0 | jit_set_Z_DVAL(jit, res_addr, ir_CONST_DOUBLE((double)ZEND_LONG_MAX + 1.0)); |
5138 | 0 | } else { |
5139 | | #if SIZEOF_ZEND_LONG == 4 |
5140 | | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0)); |
5141 | | jit_set_Z_W2(jit, res_addr, ir_CONST_U32(0x41e00000)); |
5142 | | #else |
5143 | 0 | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0x43e0000000000000)); |
5144 | 0 | #endif |
5145 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
5146 | 0 | } |
5147 | 0 | if ((res_info & MAY_BE_ANY) != MAY_BE_DOUBLE) { |
5148 | 0 | ir_MERGE_WITH(fast_path); |
5149 | 0 | } |
5150 | 0 | return 1; |
5151 | 0 | } |
5152 | 0 | op = IR_ADD; |
5153 | 0 | } else if (opcode == ZEND_SUB) { |
5154 | 0 | if (Z_MODE(op2_addr) == IS_CONST_ZVAL && Z_LVAL_P(Z_ZV(op2_addr)) == 1) { |
5155 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5156 | 0 | jit_set_Z_DVAL(jit, res_addr, ir_CONST_DOUBLE((double)ZEND_LONG_MIN - 1.0)); |
5157 | 0 | } else { |
5158 | | #if SIZEOF_ZEND_LONG == 4 |
5159 | | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0x00200000)); |
5160 | | jit_set_Z_W2(jit, res_addr, ir_CONST_U32(0xc1e00000)); |
5161 | | #else |
5162 | 0 | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0xc3e0000000000000)); |
5163 | 0 | #endif |
5164 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
5165 | 0 | } |
5166 | 0 | if ((res_info & MAY_BE_ANY) != MAY_BE_DOUBLE) { |
5167 | 0 | ir_MERGE_WITH(fast_path); |
5168 | 0 | } |
5169 | 0 | return 1; |
5170 | 0 | } |
5171 | 0 | op = IR_SUB; |
5172 | 0 | } else if (opcode == ZEND_MUL) { |
5173 | 0 | op = IR_MUL; |
5174 | 0 | } else { |
5175 | 0 | ZEND_UNREACHABLE(); |
5176 | 0 | } |
5177 | 0 | #if 1 |
5178 | | /* reload */ |
5179 | 0 | op1 = jit_Z_LVAL(jit, op1_addr); |
5180 | 0 | op2 = (same_ops) ? op1 : jit_Z_LVAL(jit, op2_addr); |
5181 | 0 | #endif |
5182 | 0 | #if 1 |
5183 | | /* disable CSE */ |
5184 | 0 | ir_ref old_cse_limit = jit->ctx.fold_cse_limit; |
5185 | 0 | jit->ctx.fold_cse_limit = 0x7fffffff; |
5186 | 0 | #endif |
5187 | 0 | op1 = ir_INT2D(op1); |
5188 | 0 | op2 = ir_INT2D(op2); |
5189 | 0 | #if 1 |
5190 | 0 | jit->ctx.fold_cse_limit = old_cse_limit; |
5191 | 0 | #endif |
5192 | 0 | ref = ir_BINARY_OP_D(op, op1, op2); |
5193 | 0 | jit_set_Z_DVAL(jit, res_addr, ref); |
5194 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
5195 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
5196 | 0 | } |
5197 | 0 | if ((res_info & MAY_BE_ANY) != MAY_BE_DOUBLE) { |
5198 | 0 | ir_MERGE_WITH(fast_path); |
5199 | 0 | } |
5200 | 0 | } |
5201 | | |
5202 | 0 | return 1; |
5203 | 0 | } |
5204 | | |
5205 | | static int zend_jit_math_long_double(zend_jit_ctx *jit, |
5206 | | uint8_t opcode, |
5207 | | zend_jit_addr op1_addr, |
5208 | | zend_jit_addr op2_addr, |
5209 | | zend_jit_addr res_addr, |
5210 | | uint32_t res_use_info) |
5211 | 0 | { |
5212 | 0 | ir_op op; |
5213 | 0 | ir_ref op1, op2, ref; |
5214 | |
|
5215 | 0 | if (opcode == ZEND_ADD) { |
5216 | 0 | op = IR_ADD; |
5217 | 0 | } else if (opcode == ZEND_SUB) { |
5218 | 0 | op = IR_SUB; |
5219 | 0 | } else if (opcode == ZEND_MUL) { |
5220 | 0 | op = IR_MUL; |
5221 | 0 | } else if (opcode == ZEND_DIV) { |
5222 | 0 | op = IR_DIV; |
5223 | 0 | } else { |
5224 | 0 | ZEND_UNREACHABLE(); |
5225 | 0 | } |
5226 | 0 | op1 = jit_Z_LVAL(jit, op1_addr); |
5227 | 0 | op2 = jit_Z_DVAL(jit, op2_addr); |
5228 | 0 | ref = ir_BINARY_OP_D(op, ir_INT2D(op1), op2); |
5229 | 0 | jit_set_Z_DVAL(jit, res_addr, ref); |
5230 | |
|
5231 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
5232 | 0 | if ((res_use_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF|MAY_BE_GUARD)) != MAY_BE_DOUBLE) { |
5233 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
5234 | 0 | } |
5235 | 0 | } |
5236 | 0 | return 1; |
5237 | 0 | } |
5238 | | |
5239 | | static int zend_jit_math_double_long(zend_jit_ctx *jit, |
5240 | | uint8_t opcode, |
5241 | | zend_jit_addr op1_addr, |
5242 | | zend_jit_addr op2_addr, |
5243 | | zend_jit_addr res_addr, |
5244 | | uint32_t res_use_info) |
5245 | 0 | { |
5246 | 0 | ir_op op; |
5247 | 0 | ir_ref op1, op2, ref; |
5248 | |
|
5249 | 0 | if (opcode == ZEND_ADD) { |
5250 | 0 | op = IR_ADD; |
5251 | 0 | } else if (opcode == ZEND_SUB) { |
5252 | 0 | op = IR_SUB; |
5253 | 0 | } else if (opcode == ZEND_MUL) { |
5254 | 0 | op = IR_MUL; |
5255 | 0 | } else if (opcode == ZEND_DIV) { |
5256 | 0 | op = IR_DIV; |
5257 | 0 | } else { |
5258 | 0 | ZEND_UNREACHABLE(); |
5259 | 0 | } |
5260 | 0 | op1 = jit_Z_DVAL(jit, op1_addr); |
5261 | 0 | op2 = jit_Z_LVAL(jit, op2_addr); |
5262 | 0 | ref = ir_BINARY_OP_D(op, op1, ir_INT2D(op2)); |
5263 | 0 | jit_set_Z_DVAL(jit, res_addr, ref); |
5264 | |
|
5265 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
5266 | 0 | if (!zend_jit_same_addr(op1_addr, res_addr)) { |
5267 | 0 | if ((res_use_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF|MAY_BE_GUARD)) != MAY_BE_DOUBLE) { |
5268 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
5269 | 0 | } |
5270 | 0 | } |
5271 | 0 | } |
5272 | 0 | return 1; |
5273 | 0 | } |
5274 | | |
5275 | | static int zend_jit_math_double_double(zend_jit_ctx *jit, |
5276 | | uint8_t opcode, |
5277 | | zend_jit_addr op1_addr, |
5278 | | zend_jit_addr op2_addr, |
5279 | | zend_jit_addr res_addr, |
5280 | | uint32_t res_use_info) |
5281 | 0 | { |
5282 | 0 | bool same_ops = zend_jit_same_addr(op1_addr, op2_addr); |
5283 | 0 | ir_op op; |
5284 | 0 | ir_ref op1, op2, ref; |
5285 | |
|
5286 | 0 | if (opcode == ZEND_ADD) { |
5287 | 0 | op = IR_ADD; |
5288 | 0 | } else if (opcode == ZEND_SUB) { |
5289 | 0 | op = IR_SUB; |
5290 | 0 | } else if (opcode == ZEND_MUL) { |
5291 | 0 | op = IR_MUL; |
5292 | 0 | } else if (opcode == ZEND_DIV) { |
5293 | 0 | op = IR_DIV; |
5294 | 0 | } else { |
5295 | 0 | ZEND_UNREACHABLE(); |
5296 | 0 | } |
5297 | 0 | op1 = jit_Z_DVAL(jit, op1_addr); |
5298 | 0 | op2 = (same_ops) ? op1 : jit_Z_DVAL(jit, op2_addr); |
5299 | 0 | ref = ir_BINARY_OP_D(op, op1, op2); |
5300 | 0 | jit_set_Z_DVAL(jit, res_addr, ref); |
5301 | |
|
5302 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
5303 | 0 | if (!zend_jit_same_addr(op1_addr, res_addr)) { |
5304 | 0 | if ((res_use_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF|MAY_BE_GUARD)) != MAY_BE_DOUBLE) { |
5305 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
5306 | 0 | } |
5307 | 0 | } |
5308 | 0 | } |
5309 | 0 | return 1; |
5310 | 0 | } |
5311 | | |
5312 | | static int zend_jit_math_helper(zend_jit_ctx *jit, |
5313 | | const zend_op *opline, |
5314 | | uint8_t opcode, |
5315 | | uint8_t op1_type, |
5316 | | znode_op op1, |
5317 | | zend_jit_addr op1_addr, |
5318 | | uint32_t op1_info, |
5319 | | uint8_t op2_type, |
5320 | | znode_op op2, |
5321 | | zend_jit_addr op2_addr, |
5322 | | uint32_t op2_info, |
5323 | | uint32_t res_var, |
5324 | | zend_jit_addr res_addr, |
5325 | | uint32_t res_info, |
5326 | | uint32_t res_use_info, |
5327 | | int may_overflow, |
5328 | | int may_throw) |
5329 | 0 | { |
5330 | 0 | ir_ref if_op1_long = IR_UNUSED; |
5331 | 0 | ir_ref if_op1_double = IR_UNUSED; |
5332 | 0 | ir_ref if_op2_double = IR_UNUSED; |
5333 | 0 | ir_ref if_op1_long_op2_long = IR_UNUSED; |
5334 | 0 | ir_ref if_op1_long_op2_double = IR_UNUSED; |
5335 | 0 | ir_ref if_op1_double_op2_double = IR_UNUSED; |
5336 | 0 | ir_ref if_op1_double_op2_long = IR_UNUSED; |
5337 | 0 | ir_ref slow_inputs = IR_UNUSED; |
5338 | 0 | bool same_ops = zend_jit_same_addr(op1_addr, op2_addr); |
5339 | 0 | ir_refs *end_inputs; |
5340 | 0 | ir_refs *res_inputs; |
5341 | |
|
5342 | 0 | ir_refs_init(end_inputs, 6); |
5343 | 0 | ir_refs_init(res_inputs, 6); |
5344 | |
|
5345 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
5346 | 0 | if (!has_concrete_type(op2_info & MAY_BE_ANY) && jit->ra[Z_SSA_VAR(op1_addr)].ref == IR_NULL) { |
5347 | | /* Force load */ |
5348 | 0 | zend_jit_use_reg(jit, op1_addr); |
5349 | 0 | } |
5350 | 0 | } else if (Z_MODE(op2_addr) == IS_REG) { |
5351 | 0 | if (!has_concrete_type(op1_info & MAY_BE_ANY) && jit->ra[Z_SSA_VAR(op2_addr)].ref == IR_NULL) { |
5352 | | /* Force load */ |
5353 | 0 | zend_jit_use_reg(jit, op2_addr); |
5354 | 0 | } |
5355 | 0 | } |
5356 | |
|
5357 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5358 | 0 | jit->delay_var = Z_SSA_VAR(res_addr); |
5359 | 0 | jit->delay_refs = res_inputs; |
5360 | 0 | } |
5361 | |
|
5362 | 0 | if ((res_info & MAY_BE_GUARD) && (res_info & MAY_BE_LONG) && (op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG)) { |
5363 | 0 | if (op1_info & (MAY_BE_ANY-MAY_BE_LONG)) { |
5364 | 0 | if_op1_long = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
5365 | 0 | ir_IF_TRUE(if_op1_long); |
5366 | 0 | } |
5367 | 0 | if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_LONG))) { |
5368 | 0 | if_op1_long_op2_long = jit_if_Z_TYPE(jit, op2_addr, IS_LONG); |
5369 | 0 | ir_IF_TRUE(if_op1_long_op2_long); |
5370 | 0 | } |
5371 | 0 | if (!zend_jit_math_long_long(jit, opline, opcode, op1_addr, op2_addr, res_addr, res_info, res_use_info, may_overflow)) { |
5372 | 0 | return 0; |
5373 | 0 | } |
5374 | 0 | ir_refs_add(end_inputs, ir_END()); |
5375 | 0 | if (if_op1_long) { |
5376 | 0 | ir_IF_FALSE_cold(if_op1_long); |
5377 | 0 | ir_END_list(slow_inputs); |
5378 | 0 | } |
5379 | 0 | if (if_op1_long_op2_long) { |
5380 | 0 | ir_IF_FALSE_cold(if_op1_long_op2_long); |
5381 | 0 | ir_END_list(slow_inputs); |
5382 | 0 | } |
5383 | 0 | } else if ((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG) && (res_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) { |
5384 | 0 | if (op1_info & (MAY_BE_ANY-MAY_BE_LONG)) { |
5385 | 0 | if_op1_long = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
5386 | 0 | ir_IF_TRUE(if_op1_long); |
5387 | 0 | } |
5388 | 0 | if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_LONG))) { |
5389 | 0 | if_op1_long_op2_long = jit_if_Z_TYPE(jit, op2_addr, IS_LONG); |
5390 | 0 | ir_IF_FALSE_cold(if_op1_long_op2_long); |
5391 | 0 | if (op2_info & MAY_BE_DOUBLE) { |
5392 | 0 | if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) { |
5393 | 0 | if_op1_long_op2_double = jit_if_Z_TYPE(jit, op2_addr, IS_DOUBLE); |
5394 | 0 | ir_IF_FALSE_cold(if_op1_long_op2_double); |
5395 | 0 | ir_END_list(slow_inputs); |
5396 | 0 | ir_IF_TRUE(if_op1_long_op2_double); |
5397 | 0 | } |
5398 | 0 | if (!zend_jit_math_long_double(jit, opcode, op1_addr, op2_addr, res_addr, res_use_info)) { |
5399 | 0 | return 0; |
5400 | 0 | } |
5401 | 0 | ir_refs_add(end_inputs, ir_END()); |
5402 | 0 | } else { |
5403 | 0 | ir_END_list(slow_inputs); |
5404 | 0 | } |
5405 | 0 | ir_IF_TRUE(if_op1_long_op2_long); |
5406 | 0 | } |
5407 | 0 | if (!zend_jit_math_long_long(jit, opline, opcode, op1_addr, op2_addr, res_addr, res_info, res_use_info, may_overflow)) { |
5408 | 0 | return 0; |
5409 | 0 | } |
5410 | 0 | ir_refs_add(end_inputs, ir_END()); |
5411 | |
|
5412 | 0 | if (if_op1_long) { |
5413 | 0 | ir_IF_FALSE_cold(if_op1_long); |
5414 | 0 | } |
5415 | |
|
5416 | 0 | if (op1_info & MAY_BE_DOUBLE) { |
5417 | 0 | if (op1_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) { |
5418 | 0 | if_op1_double = jit_if_Z_TYPE(jit, op1_addr, IS_DOUBLE); |
5419 | 0 | ir_IF_FALSE_cold(if_op1_double); |
5420 | 0 | ir_END_list(slow_inputs); |
5421 | 0 | ir_IF_TRUE(if_op1_double); |
5422 | 0 | } |
5423 | 0 | if (op2_info & MAY_BE_DOUBLE) { |
5424 | 0 | if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) { |
5425 | 0 | if_op1_double_op2_double = jit_if_Z_TYPE(jit, op2_addr, IS_DOUBLE); |
5426 | 0 | ir_IF_TRUE(if_op1_double_op2_double); |
5427 | 0 | } |
5428 | 0 | if (!zend_jit_math_double_double(jit, opcode, op1_addr, op2_addr, res_addr, res_use_info)) { |
5429 | 0 | return 0; |
5430 | 0 | } |
5431 | 0 | ir_refs_add(end_inputs, ir_END()); |
5432 | 0 | if (if_op1_double_op2_double) { |
5433 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_double); |
5434 | 0 | } |
5435 | 0 | } |
5436 | 0 | if (!same_ops) { |
5437 | 0 | if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) { |
5438 | 0 | if_op1_double_op2_long = jit_if_Z_TYPE(jit, op2_addr, IS_LONG); |
5439 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_long); |
5440 | 0 | ir_END_list(slow_inputs); |
5441 | 0 | ir_IF_TRUE(if_op1_double_op2_long); |
5442 | 0 | } |
5443 | 0 | if (!zend_jit_math_double_long(jit, opcode, op1_addr, op2_addr, res_addr, res_use_info)) { |
5444 | 0 | return 0; |
5445 | 0 | } |
5446 | 0 | ir_refs_add(end_inputs, ir_END()); |
5447 | 0 | } else if (if_op1_double_op2_double) { |
5448 | 0 | ir_END_list(slow_inputs); |
5449 | 0 | } |
5450 | 0 | } else if (if_op1_long) { |
5451 | 0 | ir_END_list(slow_inputs); |
5452 | 0 | } |
5453 | 0 | } else if ((op1_info & MAY_BE_DOUBLE) && |
5454 | 0 | !(op1_info & MAY_BE_LONG) && |
5455 | 0 | (op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE)) && |
5456 | 0 | (res_info & MAY_BE_DOUBLE)) { |
5457 | 0 | if (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) { |
5458 | 0 | if_op1_double = jit_if_Z_TYPE(jit, op1_addr, IS_DOUBLE); |
5459 | 0 | ir_IF_FALSE_cold(if_op1_double); |
5460 | 0 | ir_END_list(slow_inputs); |
5461 | 0 | ir_IF_TRUE(if_op1_double); |
5462 | 0 | } |
5463 | 0 | if (op2_info & MAY_BE_DOUBLE) { |
5464 | 0 | if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) { |
5465 | 0 | if_op1_double_op2_double = jit_if_Z_TYPE(jit, op2_addr, IS_DOUBLE); |
5466 | 0 | ir_IF_TRUE(if_op1_double_op2_double); |
5467 | 0 | } |
5468 | 0 | if (!zend_jit_math_double_double(jit, opcode, op1_addr, op2_addr, res_addr, res_use_info)) { |
5469 | 0 | return 0; |
5470 | 0 | } |
5471 | 0 | ir_refs_add(end_inputs, ir_END()); |
5472 | 0 | if (if_op1_double_op2_double) { |
5473 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_double); |
5474 | 0 | } |
5475 | 0 | } |
5476 | 0 | if (!same_ops && (op2_info & MAY_BE_LONG)) { |
5477 | 0 | if (op2_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) { |
5478 | 0 | if_op1_double_op2_long = jit_if_Z_TYPE(jit, op2_addr, IS_LONG); |
5479 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_long); |
5480 | 0 | ir_END_list(slow_inputs); |
5481 | 0 | ir_IF_TRUE(if_op1_double_op2_long); |
5482 | 0 | } |
5483 | 0 | if (!zend_jit_math_double_long(jit, opcode, op1_addr, op2_addr, res_addr, res_use_info)) { |
5484 | 0 | return 0; |
5485 | 0 | } |
5486 | 0 | ir_refs_add(end_inputs, ir_END()); |
5487 | 0 | } else if (if_op1_double_op2_double) { |
5488 | 0 | ir_END_list(slow_inputs); |
5489 | 0 | } |
5490 | 0 | } else if ((op2_info & MAY_BE_DOUBLE) && |
5491 | 0 | !(op2_info & MAY_BE_LONG) && |
5492 | 0 | (op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE)) && |
5493 | 0 | (res_info & MAY_BE_DOUBLE)) { |
5494 | 0 | if (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) { |
5495 | 0 | if_op2_double = jit_if_Z_TYPE(jit, op2_addr, IS_DOUBLE); |
5496 | 0 | ir_IF_FALSE_cold(if_op2_double); |
5497 | 0 | ir_END_list(slow_inputs); |
5498 | 0 | ir_IF_TRUE(if_op2_double); |
5499 | 0 | } |
5500 | 0 | if (op1_info & MAY_BE_DOUBLE) { |
5501 | 0 | if (!same_ops && (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) { |
5502 | 0 | if_op1_double_op2_double = jit_if_Z_TYPE(jit, op1_addr, IS_DOUBLE); |
5503 | 0 | ir_IF_TRUE(if_op1_double_op2_double); |
5504 | 0 | } |
5505 | 0 | if (!zend_jit_math_double_double(jit, opcode, op1_addr, op2_addr, res_addr, res_use_info)) { |
5506 | 0 | return 0; |
5507 | 0 | } |
5508 | 0 | ir_refs_add(end_inputs, ir_END()); |
5509 | 0 | if (if_op1_double_op2_double) { |
5510 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_double); |
5511 | 0 | } |
5512 | 0 | } |
5513 | 0 | if (!same_ops && (op1_info & MAY_BE_LONG)) { |
5514 | 0 | if (op1_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) { |
5515 | 0 | if_op1_long_op2_double = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
5516 | 0 | ir_IF_FALSE_cold(if_op1_long_op2_double); |
5517 | 0 | ir_END_list(slow_inputs); |
5518 | 0 | ir_IF_TRUE(if_op1_long_op2_double); |
5519 | 0 | } |
5520 | 0 | if (!zend_jit_math_long_double(jit, opcode, op1_addr, op2_addr, res_addr, res_use_info)) { |
5521 | 0 | return 0; |
5522 | 0 | } |
5523 | 0 | ir_refs_add(end_inputs, ir_END()); |
5524 | 0 | } else if (if_op1_double_op2_double) { |
5525 | 0 | ir_END_list(slow_inputs); |
5526 | 0 | } |
5527 | 0 | } |
5528 | | |
5529 | 0 | if ((op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) || |
5530 | 0 | (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE)))) { |
5531 | 0 | ir_ref func, arg1, arg2, arg3; |
5532 | |
|
5533 | 0 | if (slow_inputs) { |
5534 | 0 | ir_MERGE_list(slow_inputs); |
5535 | 0 | } |
5536 | |
|
5537 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
5538 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, op1.var); |
5539 | 0 | if (!zend_jit_spill_store_inv(jit, op1_addr, real_addr, op1_info)) { |
5540 | 0 | return 0; |
5541 | 0 | } |
5542 | 0 | op1_addr = real_addr; |
5543 | 0 | } |
5544 | 0 | if (Z_MODE(op2_addr) == IS_REG) { |
5545 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, op2.var); |
5546 | 0 | if (!zend_jit_spill_store_inv(jit, op2_addr, real_addr, op2_info)) { |
5547 | 0 | return 0; |
5548 | 0 | } |
5549 | 0 | op2_addr = real_addr; |
5550 | 0 | } |
5551 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5552 | 0 | arg1 = jit_ZVAL_ADDR(jit, ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var)); |
5553 | 0 | } else { |
5554 | 0 | arg1 = jit_ZVAL_ADDR(jit, res_addr); |
5555 | 0 | } |
5556 | 0 | arg2 = jit_ZVAL_ADDR(jit, op1_addr); |
5557 | 0 | arg3 = jit_ZVAL_ADDR(jit, op2_addr); |
5558 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5559 | 0 | if (opcode == ZEND_ADD) { |
5560 | 0 | func = ir_CONST_FC_FUNC(add_function); |
5561 | 0 | } else if (opcode == ZEND_SUB) { |
5562 | 0 | func = ir_CONST_FC_FUNC(sub_function); |
5563 | 0 | } else if (opcode == ZEND_MUL) { |
5564 | 0 | func = ir_CONST_FC_FUNC(mul_function); |
5565 | 0 | } else if (opcode == ZEND_DIV) { |
5566 | 0 | func = ir_CONST_FC_FUNC(div_function); |
5567 | 0 | } else { |
5568 | 0 | ZEND_UNREACHABLE(); |
5569 | 0 | } |
5570 | 0 | ir_CALL_3(IR_VOID, func, arg1, arg2, arg3); |
5571 | |
|
5572 | 0 | jit_FREE_OP(jit, op1_type, op1, op1_info, NULL); |
5573 | 0 | jit_FREE_OP(jit, op2_type, op2, op2_info, NULL); |
5574 | |
|
5575 | 0 | if (may_throw) { |
5576 | 0 | if (opline->opcode == ZEND_ASSIGN_DIM_OP && (opline->op2_type & (IS_VAR|IS_TMP_VAR))) { |
5577 | 0 | ir_GUARD_NOT(ir_LOAD_A(jit_EG_exception(jit)), |
5578 | 0 | jit_STUB_ADDR(jit, jit_stub_exception_handler_free_op2)); |
5579 | 0 | } else if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) { |
5580 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
5581 | 0 | } else { |
5582 | 0 | zend_jit_check_exception(jit); |
5583 | 0 | } |
5584 | 0 | } |
5585 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5586 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var); |
5587 | 0 | if (!zend_jit_load_reg(jit, real_addr, res_addr, res_info)) { |
5588 | 0 | return 0; |
5589 | 0 | } |
5590 | 0 | } |
5591 | 0 | ir_refs_add(end_inputs, ir_END()); |
5592 | 0 | } |
5593 | | |
5594 | 0 | if (end_inputs->count) { |
5595 | 0 | ir_MERGE_N(end_inputs->count, end_inputs->refs); |
5596 | 0 | } |
5597 | |
|
5598 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5599 | 0 | ZEND_ASSERT(jit->delay_refs == res_inputs); |
5600 | 0 | ZEND_ASSERT(end_inputs->count == res_inputs->count); |
5601 | 0 | jit->delay_var = -1; |
5602 | 0 | jit->delay_refs = NULL; |
5603 | 0 | if (res_inputs->count == 1) { |
5604 | 0 | zend_jit_def_reg(jit, res_addr, res_inputs->refs[0]); |
5605 | 0 | } else { |
5606 | 0 | ir_ref phi = ir_PHI_N((res_info & MAY_BE_LONG) ? IR_LONG : IR_DOUBLE, res_inputs->count, res_inputs->refs); |
5607 | 0 | zend_jit_def_reg(jit, res_addr, phi); |
5608 | 0 | } |
5609 | 0 | } |
5610 | |
|
5611 | 0 | return 1; |
5612 | 0 | } |
5613 | | |
5614 | | static int zend_jit_math(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, uint32_t op2_info, zend_jit_addr op2_addr, uint32_t res_use_info, uint32_t res_info, zend_jit_addr res_addr, int may_overflow, int may_throw) |
5615 | 0 | { |
5616 | 0 | ZEND_ASSERT(!(op1_info & MAY_BE_UNDEF) && !(op2_info & MAY_BE_UNDEF)); |
5617 | |
|
5618 | 0 | if (!zend_jit_math_helper(jit, opline, opline->opcode, opline->op1_type, opline->op1, op1_addr, op1_info, opline->op2_type, opline->op2, op2_addr, op2_info, opline->result.var, res_addr, res_info, res_use_info, may_overflow, may_throw)) { |
5619 | 0 | return 0; |
5620 | 0 | } |
5621 | 0 | if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, res_info)) { |
5622 | 0 | return 0; |
5623 | 0 | } |
5624 | 0 | return 1; |
5625 | 0 | } |
5626 | | |
5627 | | static int zend_jit_add_arrays(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, uint32_t op2_info, zend_jit_addr op2_addr, zend_jit_addr res_addr) |
5628 | 0 | { |
5629 | 0 | ir_ref ref; |
5630 | 0 | ir_ref arg1 = jit_Z_PTR(jit, op1_addr); |
5631 | 0 | ir_ref arg2 = jit_Z_PTR(jit, op2_addr); |
5632 | |
|
5633 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_add_arrays_helper), arg1, arg2); |
5634 | 0 | jit_set_Z_PTR(jit, res_addr, ref); |
5635 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_ARRAY_EX); |
5636 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
5637 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, opline); |
5638 | 0 | return 1; |
5639 | 0 | } |
5640 | | |
5641 | | static int zend_jit_long_math_helper(zend_jit_ctx *jit, |
5642 | | const zend_op *opline, |
5643 | | uint8_t opcode, |
5644 | | uint8_t op1_type, |
5645 | | znode_op op1, |
5646 | | zend_jit_addr op1_addr, |
5647 | | uint32_t op1_info, |
5648 | | zend_ssa_range *op1_range, |
5649 | | uint8_t op2_type, |
5650 | | znode_op op2, |
5651 | | zend_jit_addr op2_addr, |
5652 | | uint32_t op2_info, |
5653 | | zend_ssa_range *op2_range, |
5654 | | uint32_t res_var, |
5655 | | zend_jit_addr res_addr, |
5656 | | uint32_t res_info, |
5657 | | uint32_t res_use_info, |
5658 | | int may_throw) |
5659 | 0 | { |
5660 | 0 | ir_ref ref = IR_UNUSED; |
5661 | 0 | ir_ref if_long1 = IR_UNUSED; |
5662 | 0 | ir_ref if_long2 = IR_UNUSED; |
5663 | 0 | bool same_ops = zend_jit_same_addr(op1_addr, op2_addr); |
5664 | 0 | ir_refs *res_inputs; |
5665 | |
|
5666 | 0 | ir_refs_init(res_inputs, 2); |
5667 | |
|
5668 | 0 | if (Z_MODE(op1_addr) == IS_REG |
5669 | 0 | && Z_LOAD(op1_addr) |
5670 | 0 | && jit->ra[Z_SSA_VAR(op1_addr)].ref == IR_NULL) { |
5671 | | /* Force load */ |
5672 | 0 | zend_jit_use_reg(jit, op1_addr); |
5673 | 0 | } |
5674 | 0 | if (Z_MODE(op2_addr) == IS_REG |
5675 | 0 | && Z_LOAD(op2_addr) |
5676 | 0 | && jit->ra[Z_SSA_VAR(op2_addr)].ref == IR_NULL) { |
5677 | | /* Force load */ |
5678 | 0 | zend_jit_use_reg(jit, op2_addr); |
5679 | 0 | } |
5680 | |
|
5681 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) { |
5682 | 0 | if_long1 = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
5683 | 0 | ir_IF_TRUE(if_long1); |
5684 | 0 | } |
5685 | 0 | if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG))) { |
5686 | 0 | if_long2 = jit_if_Z_TYPE(jit, op2_addr, IS_LONG); |
5687 | 0 | ir_IF_TRUE(if_long2); |
5688 | 0 | } |
5689 | |
|
5690 | 0 | if (opcode == ZEND_SL) { |
5691 | 0 | if (Z_MODE(op2_addr) == IS_CONST_ZVAL) { |
5692 | 0 | zend_long op2_lval = Z_LVAL_P(Z_ZV(op2_addr)); |
5693 | |
|
5694 | 0 | if (UNEXPECTED((zend_ulong)op2_lval >= SIZEOF_ZEND_LONG * 8)) { |
5695 | 0 | if (EXPECTED(op2_lval > 0)) { |
5696 | 0 | ref = ir_CONST_LONG(0); |
5697 | 0 | } else { |
5698 | 0 | zend_jit_invalidate_var_if_necessary(jit, op1_type, op1_addr, op1); |
5699 | 0 | zend_jit_invalidate_var_if_necessary(jit, op2_type, op2_addr, op2); |
5700 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5701 | 0 | ir_GUARD(IR_FALSE, jit_STUB_ADDR(jit, jit_stub_negative_shift)); |
5702 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5703 | 0 | ref = ir_CONST_LONG(0); // dead code |
5704 | 0 | } |
5705 | 0 | } |
5706 | 0 | } else { |
5707 | 0 | ref = ir_SHL_L(jit_Z_LVAL(jit, op1_addr), ir_CONST_LONG(op2_lval)); |
5708 | 0 | } |
5709 | 0 | } else { |
5710 | 0 | ref = jit_Z_LVAL(jit, op2_addr); |
5711 | 0 | if (!op2_range || |
5712 | 0 | op2_range->min < 0 || |
5713 | 0 | op2_range->max >= SIZEOF_ZEND_LONG * 8) { |
5714 | |
|
5715 | 0 | ir_ref if_wrong, cold_path, ref2, if_ok; |
5716 | 0 | ir_ref op1_ref = jit_Z_LVAL(jit, op1_addr); |
5717 | |
|
5718 | 0 | if_wrong = ir_IF(ir_UGT(ref, ir_CONST_LONG((SIZEOF_ZEND_LONG * 8) - 1))); |
5719 | 0 | ir_IF_TRUE_cold(if_wrong); |
5720 | 0 | if_ok = ir_IF(ir_GE(ref, ir_CONST_LONG(0))); |
5721 | 0 | ir_IF_FALSE(if_ok); |
5722 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5723 | 0 | zend_jit_invalidate_var_if_necessary(jit, op1_type, op1_addr, op1); |
5724 | 0 | zend_jit_invalidate_var_if_necessary(jit, op2_type, op2_addr, op2); |
5725 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_negative_shift)); |
5726 | 0 | ir_IF_TRUE(if_ok); |
5727 | 0 | ref2 = ir_CONST_LONG(0); |
5728 | 0 | cold_path = ir_END(); |
5729 | 0 | ir_IF_FALSE(if_wrong); |
5730 | 0 | ref = ir_SHL_L(op1_ref, ref); |
5731 | 0 | ir_MERGE_WITH(cold_path); |
5732 | 0 | ref = ir_PHI_2(IR_LONG, ref, ref2); |
5733 | 0 | } else { |
5734 | 0 | ref = ir_SHL_L(jit_Z_LVAL(jit, op1_addr), ref); |
5735 | 0 | } |
5736 | 0 | } |
5737 | 0 | } else if (opcode == ZEND_SR) { |
5738 | 0 | if (Z_MODE(op2_addr) == IS_CONST_ZVAL) { |
5739 | 0 | zend_long op2_lval = Z_LVAL_P(Z_ZV(op2_addr)); |
5740 | |
|
5741 | 0 | if (UNEXPECTED((zend_ulong)op2_lval >= SIZEOF_ZEND_LONG * 8)) { |
5742 | 0 | if (EXPECTED(op2_lval > 0)) { |
5743 | 0 | ref = ir_SAR_L( |
5744 | 0 | jit_Z_LVAL(jit, op1_addr), |
5745 | 0 | ir_CONST_LONG((SIZEOF_ZEND_LONG * 8) - 1)); |
5746 | 0 | } else { |
5747 | 0 | zend_jit_invalidate_var_if_necessary(jit, op1_type, op1_addr, op1); |
5748 | 0 | zend_jit_invalidate_var_if_necessary(jit, op2_type, op2_addr, op2); |
5749 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5750 | 0 | ir_GUARD(IR_FALSE, jit_STUB_ADDR(jit, jit_stub_negative_shift)); |
5751 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5752 | 0 | ref = ir_CONST_LONG(0); // dead code |
5753 | 0 | } |
5754 | 0 | } |
5755 | 0 | } else { |
5756 | 0 | ref = ir_SAR_L(jit_Z_LVAL(jit, op1_addr), ir_CONST_LONG(op2_lval)); |
5757 | 0 | } |
5758 | 0 | } else { |
5759 | 0 | ref = jit_Z_LVAL(jit, op2_addr); |
5760 | 0 | if (!op2_range || |
5761 | 0 | op2_range->min < 0 || |
5762 | 0 | op2_range->max >= SIZEOF_ZEND_LONG * 8) { |
5763 | |
|
5764 | 0 | ir_ref if_wrong, cold_path, ref2, if_ok; |
5765 | |
|
5766 | 0 | if_wrong = ir_IF(ir_UGT(ref, ir_CONST_LONG((SIZEOF_ZEND_LONG * 8) - 1))); |
5767 | 0 | ir_IF_TRUE_cold(if_wrong); |
5768 | 0 | if_ok = ir_IF(ir_GE(ref, ir_CONST_LONG(0))); |
5769 | 0 | ir_IF_FALSE(if_ok); |
5770 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5771 | 0 | zend_jit_invalidate_var_if_necessary(jit, op1_type, op1_addr, op1); |
5772 | 0 | zend_jit_invalidate_var_if_necessary(jit, op2_type, op2_addr, op2); |
5773 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_negative_shift)); |
5774 | 0 | ir_IF_TRUE(if_ok); |
5775 | 0 | ref2 = ir_CONST_LONG((SIZEOF_ZEND_LONG * 8) - 1); |
5776 | 0 | cold_path = ir_END(); |
5777 | 0 | ir_IF_FALSE(if_wrong); |
5778 | 0 | ir_MERGE_WITH(cold_path); |
5779 | 0 | ref = ir_PHI_2(IR_LONG, ref, ref2); |
5780 | 0 | } |
5781 | 0 | ref = ir_SAR_L(jit_Z_LVAL(jit, op1_addr), ref); |
5782 | 0 | } |
5783 | 0 | } else if (opcode == ZEND_MOD) { |
5784 | 0 | if (Z_MODE(op2_addr) == IS_CONST_ZVAL) { |
5785 | 0 | zend_long op2_lval = Z_LVAL_P(Z_ZV(op2_addr)); |
5786 | |
|
5787 | 0 | if (op2_lval == 0) { |
5788 | 0 | zend_jit_invalidate_var_if_necessary(jit, op1_type, op1_addr, op1); |
5789 | 0 | zend_jit_invalidate_var_if_necessary(jit, op2_type, op2_addr, op2); |
5790 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5791 | 0 | ir_GUARD(IR_FALSE, jit_STUB_ADDR(jit, jit_stub_mod_by_zero)); |
5792 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5793 | 0 | ref = ir_CONST_LONG(0); // dead code |
5794 | 0 | } |
5795 | 0 | } else if (zend_long_is_power_of_two(op2_lval) && op1_range && op1_range->min >= 0) { |
5796 | 0 | ref = ir_AND_L(jit_Z_LVAL(jit, op1_addr), ir_CONST_LONG(op2_lval - 1)); |
5797 | 0 | } else { |
5798 | 0 | ref = ir_MOD_L(jit_Z_LVAL(jit, op1_addr), ir_CONST_LONG(op2_lval)); |
5799 | 0 | } |
5800 | 0 | } else { |
5801 | 0 | ir_ref zero_path = 0; |
5802 | 0 | ir_ref op1_ref = jit_Z_LVAL(jit, op1_addr); |
5803 | |
|
5804 | 0 | ref = jit_Z_LVAL(jit, op2_addr); |
5805 | 0 | if ((op2_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) || !op2_range || (op2_range->min <= 0 && op2_range->max >= 0)) { |
5806 | 0 | ir_ref if_ok = ir_IF(ref); |
5807 | 0 | ir_IF_FALSE(if_ok); |
5808 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5809 | 0 | zend_jit_invalidate_var_if_necessary(jit, op1_type, op1_addr, op1); |
5810 | 0 | zend_jit_invalidate_var_if_necessary(jit, op2_type, op2_addr, op2); |
5811 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_mod_by_zero)); |
5812 | 0 | ir_IF_TRUE(if_ok); |
5813 | 0 | } |
5814 | | |
5815 | | /* Prevent overflow error/crash if op1 == LONG_MIN and op2 == -1 */ |
5816 | 0 | if (!op2_range || (op2_range->min <= -1 && op2_range->max >= -1)) { |
5817 | 0 | ir_ref if_minus_one = ir_IF(ir_EQ(ref, ir_CONST_LONG(-1))); |
5818 | 0 | ir_IF_TRUE_cold(if_minus_one); |
5819 | 0 | zero_path = ir_END(); |
5820 | 0 | ir_IF_FALSE(if_minus_one); |
5821 | 0 | } |
5822 | 0 | ref = ir_MOD_L(op1_ref, ref); |
5823 | |
|
5824 | 0 | if (zero_path) { |
5825 | 0 | ir_MERGE_WITH(zero_path); |
5826 | 0 | ref = ir_PHI_2(IR_LONG, ref, ir_CONST_LONG(0)); |
5827 | 0 | } |
5828 | 0 | } |
5829 | 0 | } else { |
5830 | 0 | ir_op op; |
5831 | 0 | ir_ref op1, op2; |
5832 | |
|
5833 | 0 | if (opcode == ZEND_BW_OR) { |
5834 | 0 | op = IR_OR; |
5835 | 0 | } else if (opcode == ZEND_BW_AND) { |
5836 | 0 | op = IR_AND; |
5837 | 0 | } else if (opcode == ZEND_BW_XOR) { |
5838 | 0 | op = IR_XOR; |
5839 | 0 | } else { |
5840 | 0 | ZEND_UNREACHABLE(); |
5841 | 0 | } |
5842 | 0 | op1 = jit_Z_LVAL(jit, op1_addr); |
5843 | 0 | op2 = (same_ops) ? op1 : jit_Z_LVAL(jit, op2_addr); |
5844 | 0 | ref = ir_BINARY_OP_L(op, op1, op2); |
5845 | 0 | } |
5846 | | |
5847 | 0 | if (ref) { |
5848 | 0 | if (Z_MODE(res_addr) == IS_REG |
5849 | 0 | && ((op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) |
5850 | 0 | || (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)))) { |
5851 | 0 | jit->delay_var = Z_SSA_VAR(res_addr); |
5852 | 0 | jit->delay_refs = res_inputs; |
5853 | 0 | } |
5854 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
5855 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
5856 | 0 | if (!zend_jit_same_addr(op1_addr, res_addr)) { |
5857 | 0 | if ((res_use_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF|MAY_BE_GUARD)) != MAY_BE_LONG) { |
5858 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
5859 | 0 | } |
5860 | 0 | } |
5861 | 0 | } |
5862 | 0 | } |
5863 | |
|
5864 | 0 | if ((op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) || |
5865 | 0 | (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG))) { |
5866 | 0 | ir_ref fast_path = ir_END(); |
5867 | 0 | ir_ref func, arg1, arg2, arg3; |
5868 | |
|
5869 | 0 | if (if_long2 && if_long1) { |
5870 | 0 | ir_ref ref; |
5871 | 0 | ir_IF_FALSE_cold(if_long2); |
5872 | 0 | ref = ir_END(); |
5873 | 0 | ir_IF_FALSE_cold(if_long1); |
5874 | 0 | ir_MERGE_2(ref, ir_END()); |
5875 | 0 | } else if (if_long1) { |
5876 | 0 | ir_IF_FALSE_cold(if_long1); |
5877 | 0 | } else if (if_long2) { |
5878 | 0 | ir_IF_FALSE_cold(if_long2); |
5879 | 0 | } |
5880 | |
|
5881 | 0 | if (op1_info & MAY_BE_UNDEF) { |
5882 | 0 | ir_ref if_def, ref, ref2; |
5883 | |
|
5884 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
5885 | 0 | if_def = jit_if_not_Z_TYPE(jit, op1_addr, IS_UNDEF); |
5886 | 0 | ir_IF_FALSE_cold(if_def); |
5887 | | |
5888 | | // zend_error_unchecked(E_WARNING, "Undefined variable $%S", CV_DEF_OF(EX_VAR_TO_NUM(opline->op1.var))); |
5889 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5890 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op1.var)); |
5891 | |
|
5892 | 0 | ref2 = jit_EG(uninitialized_zval); |
5893 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_def); |
5894 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
5895 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
5896 | 0 | } |
5897 | |
|
5898 | 0 | if (op2_info & MAY_BE_UNDEF) { |
5899 | 0 | ir_ref if_def, ref, ref2; |
5900 | |
|
5901 | 0 | ref = jit_ZVAL_ADDR(jit, op2_addr); |
5902 | 0 | if_def = jit_if_not_Z_TYPE(jit, op2_addr, IS_UNDEF); |
5903 | 0 | ir_IF_FALSE_cold(if_def); |
5904 | | |
5905 | | // zend_error_unchecked(E_WARNING, "Undefined variable $%S", CV_DEF_OF(EX_VAR_TO_NUM(opline->op2.var))); |
5906 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5907 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op2.var)); |
5908 | |
|
5909 | 0 | ref2 = jit_EG(uninitialized_zval); |
5910 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_def); |
5911 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
5912 | 0 | op2_addr = ZEND_ADDR_REF_ZVAL(ref); |
5913 | 0 | } |
5914 | |
|
5915 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
5916 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, op1.var); |
5917 | 0 | if (!zend_jit_spill_store_inv(jit, op1_addr, real_addr, op1_info)) { |
5918 | 0 | return 0; |
5919 | 0 | } |
5920 | 0 | op1_addr = real_addr; |
5921 | 0 | } |
5922 | 0 | if (Z_MODE(op2_addr) == IS_REG) { |
5923 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, op2.var); |
5924 | 0 | if (!zend_jit_spill_store_inv(jit, op2_addr, real_addr, op2_info)) { |
5925 | 0 | return 0; |
5926 | 0 | } |
5927 | 0 | op2_addr = real_addr; |
5928 | 0 | } |
5929 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5930 | 0 | arg1 = jit_ZVAL_ADDR(jit, ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var)); |
5931 | 0 | } else { |
5932 | 0 | arg1 = jit_ZVAL_ADDR(jit, res_addr); |
5933 | 0 | } |
5934 | 0 | arg2 = jit_ZVAL_ADDR(jit, op1_addr); |
5935 | 0 | arg3 = jit_ZVAL_ADDR(jit, op2_addr); |
5936 | 0 | jit_SET_EX_OPLINE(jit, opline); |
5937 | 0 | if (opcode == ZEND_BW_OR) { |
5938 | 0 | func = ir_CONST_FC_FUNC(bitwise_or_function); |
5939 | 0 | } else if (opcode == ZEND_BW_AND) { |
5940 | 0 | func = ir_CONST_FC_FUNC(bitwise_and_function); |
5941 | 0 | } else if (opcode == ZEND_BW_XOR) { |
5942 | 0 | func = ir_CONST_FC_FUNC(bitwise_xor_function); |
5943 | 0 | } else if (opcode == ZEND_SL) { |
5944 | 0 | func = ir_CONST_FC_FUNC(shift_left_function); |
5945 | 0 | } else if (opcode == ZEND_SR) { |
5946 | 0 | func = ir_CONST_FC_FUNC(shift_right_function); |
5947 | 0 | } else if (opcode == ZEND_MOD) { |
5948 | 0 | func = ir_CONST_FC_FUNC(mod_function); |
5949 | 0 | } else { |
5950 | 0 | ZEND_UNREACHABLE(); |
5951 | 0 | } |
5952 | 0 | ir_CALL_3(IR_VOID, func, arg1, arg2, arg3); |
5953 | |
|
5954 | 0 | if (op1_addr == res_addr && (op2_info & MAY_BE_RCN)) { |
5955 | | /* compound assignment may decrement "op2" refcount */ |
5956 | 0 | op2_info |= MAY_BE_RC1; |
5957 | 0 | } |
5958 | |
|
5959 | 0 | jit_FREE_OP(jit, op1_type, op1, op1_info, NULL); |
5960 | 0 | jit_FREE_OP(jit, op2_type, op2, op2_info, NULL); |
5961 | |
|
5962 | 0 | if (may_throw) { |
5963 | 0 | if (opline->opcode == ZEND_ASSIGN_DIM_OP && (opline->op2_type & (IS_VAR|IS_TMP_VAR))) { |
5964 | 0 | ir_GUARD_NOT(ir_LOAD_A(jit_EG_exception(jit)), |
5965 | 0 | jit_STUB_ADDR(jit, jit_stub_exception_handler_free_op2)); |
5966 | 0 | } else if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) { |
5967 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
5968 | 0 | } else { |
5969 | 0 | zend_jit_check_exception(jit); |
5970 | 0 | } |
5971 | 0 | } |
5972 | |
|
5973 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5974 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var); |
5975 | 0 | if (!zend_jit_load_reg(jit, real_addr, res_addr, res_info)) { |
5976 | 0 | return 0; |
5977 | 0 | } |
5978 | 0 | } |
5979 | | |
5980 | 0 | ir_MERGE_2(fast_path, ir_END()); |
5981 | |
|
5982 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
5983 | 0 | ZEND_ASSERT(jit->delay_refs == res_inputs); |
5984 | 0 | ZEND_ASSERT(res_inputs->count == 2); |
5985 | 0 | jit->delay_var = -1; |
5986 | 0 | jit->delay_refs = NULL; |
5987 | 0 | if (res_inputs->count == 1) { |
5988 | 0 | zend_jit_def_reg(jit, res_addr, res_inputs->refs[0]); |
5989 | 0 | } else { |
5990 | 0 | ir_ref phi = ir_PHI_N(IR_LONG, res_inputs->count, res_inputs->refs); |
5991 | 0 | zend_jit_def_reg(jit, res_addr, phi); |
5992 | 0 | } |
5993 | 0 | } |
5994 | 0 | } |
5995 | | |
5996 | 0 | return 1; |
5997 | 0 | } |
5998 | | |
5999 | | static int zend_jit_long_math(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_ssa_range *op1_range, zend_jit_addr op1_addr, uint32_t op2_info, zend_ssa_range *op2_range, zend_jit_addr op2_addr, uint32_t res_use_info, uint32_t res_info, zend_jit_addr res_addr, int may_throw) |
6000 | 0 | { |
6001 | 0 | ZEND_ASSERT((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG)); |
6002 | |
|
6003 | 0 | if (!zend_jit_long_math_helper(jit, opline, opline->opcode, |
6004 | 0 | opline->op1_type, opline->op1, op1_addr, op1_info, op1_range, |
6005 | 0 | opline->op2_type, opline->op2, op2_addr, op2_info, op2_range, |
6006 | 0 | opline->result.var, res_addr, res_info, res_use_info, may_throw)) { |
6007 | 0 | return 0; |
6008 | 0 | } |
6009 | 0 | if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, res_info)) { |
6010 | 0 | return 0; |
6011 | 0 | } |
6012 | 0 | return 1; |
6013 | 0 | } |
6014 | | |
6015 | | static int zend_jit_concat_helper(zend_jit_ctx *jit, |
6016 | | const zend_op *opline, |
6017 | | uint8_t op1_type, |
6018 | | znode_op op1, |
6019 | | zend_jit_addr op1_addr, |
6020 | | uint32_t op1_info, |
6021 | | uint8_t op2_type, |
6022 | | znode_op op2, |
6023 | | zend_jit_addr op2_addr, |
6024 | | uint32_t op2_info, |
6025 | | zend_jit_addr res_addr, |
6026 | | int may_throw) |
6027 | 0 | { |
6028 | 0 | ir_ref if_op1_string = IR_UNUSED; |
6029 | 0 | ir_ref if_op2_string = IR_UNUSED; |
6030 | 0 | ir_ref fast_path = IR_UNUSED; |
6031 | |
|
6032 | 0 | if ((op1_info & MAY_BE_STRING) && (op2_info & MAY_BE_STRING)) { |
6033 | 0 | if (op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF) - MAY_BE_STRING)) { |
6034 | 0 | if_op1_string = jit_if_Z_TYPE(jit, op1_addr, IS_STRING); |
6035 | 0 | ir_IF_TRUE(if_op1_string); |
6036 | 0 | } |
6037 | 0 | if (op2_info & ((MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF) - MAY_BE_STRING)) { |
6038 | 0 | if_op2_string = jit_if_Z_TYPE(jit, op2_addr, IS_STRING); |
6039 | 0 | ir_IF_TRUE(if_op2_string); |
6040 | 0 | } |
6041 | 0 | if (zend_jit_same_addr(op1_addr, res_addr)) { |
6042 | 0 | ir_ref arg1 = jit_ZVAL_ADDR(jit, res_addr); |
6043 | 0 | ir_ref arg2 = jit_ZVAL_ADDR(jit, op2_addr); |
6044 | |
|
6045 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fast_assign_concat_helper), arg1, arg2); |
6046 | | /* concatenation with itself may reduce refcount */ |
6047 | 0 | op2_info |= MAY_BE_RC1; |
6048 | 0 | } else { |
6049 | 0 | ir_ref arg1 = jit_ZVAL_ADDR(jit, res_addr); |
6050 | 0 | ir_ref arg2 = jit_ZVAL_ADDR(jit, op1_addr); |
6051 | 0 | ir_ref arg3 = jit_ZVAL_ADDR(jit, op2_addr); |
6052 | |
|
6053 | 0 | if (op1_type == IS_CV || op1_type == IS_CONST) { |
6054 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fast_concat_helper), arg1, arg2, arg3); |
6055 | 0 | } else { |
6056 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fast_concat_tmp_helper), arg1, arg2, arg3); |
6057 | 0 | } |
6058 | 0 | } |
6059 | | /* concatenation with empty string may increase refcount */ |
6060 | 0 | op2_info |= MAY_BE_RCN; |
6061 | 0 | jit_FREE_OP(jit, op2_type, op2, op2_info, opline); |
6062 | 0 | if (if_op1_string || if_op2_string) { |
6063 | 0 | fast_path = ir_END(); |
6064 | 0 | } |
6065 | 0 | } |
6066 | 0 | if ((op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF) - MAY_BE_STRING)) || |
6067 | 0 | (op2_info & ((MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF) - MAY_BE_STRING))) { |
6068 | 0 | if ((op1_info & MAY_BE_STRING) && (op2_info & MAY_BE_STRING)) { |
6069 | 0 | if (if_op1_string && if_op2_string) { |
6070 | 0 | ir_IF_FALSE(if_op1_string); |
6071 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_op2_string); |
6072 | 0 | } else if (if_op1_string) { |
6073 | 0 | ir_IF_FALSE_cold(if_op1_string); |
6074 | 0 | } else if (if_op2_string) { |
6075 | 0 | ir_IF_FALSE_cold(if_op2_string); |
6076 | 0 | } |
6077 | 0 | } |
6078 | 0 | ir_ref arg1 = jit_ZVAL_ADDR(jit, res_addr); |
6079 | 0 | ir_ref arg2 = jit_ZVAL_ADDR(jit, op1_addr); |
6080 | 0 | ir_ref arg3 = jit_ZVAL_ADDR(jit, op2_addr); |
6081 | |
|
6082 | 0 | jit_SET_EX_OPLINE(jit, opline); |
6083 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(concat_function), arg1, arg2, arg3); |
6084 | | /* concatenation with empty string may increase refcount */ |
6085 | 0 | op1_info |= MAY_BE_RCN; |
6086 | 0 | op2_info |= MAY_BE_RCN; |
6087 | 0 | jit_FREE_OP(jit, op1_type, op1, op1_info, NULL); |
6088 | 0 | jit_FREE_OP(jit, op2_type, op2, op2_info, NULL); |
6089 | 0 | if (may_throw) { |
6090 | 0 | if (opline->opcode == ZEND_ASSIGN_DIM_OP && (opline->op2_type & (IS_VAR|IS_TMP_VAR))) { |
6091 | 0 | ir_GUARD_NOT(ir_LOAD_A(jit_EG_exception(jit)), |
6092 | 0 | jit_STUB_ADDR(jit, jit_stub_exception_handler_free_op2)); |
6093 | 0 | } else if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) { |
6094 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
6095 | 0 | } else { |
6096 | 0 | zend_jit_check_exception(jit); |
6097 | 0 | } |
6098 | 0 | } |
6099 | 0 | if ((op1_info & MAY_BE_STRING) && (op2_info & MAY_BE_STRING)) { |
6100 | 0 | ir_MERGE_WITH(fast_path); |
6101 | 0 | } |
6102 | 0 | } |
6103 | 0 | return 1; |
6104 | 0 | } |
6105 | | |
6106 | | static int zend_jit_concat(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, uint32_t op2_info, zend_jit_addr res_addr, int may_throw) |
6107 | 0 | { |
6108 | 0 | zend_jit_addr op1_addr, op2_addr; |
6109 | |
|
6110 | 0 | ZEND_ASSERT(!(op1_info & MAY_BE_UNDEF) && !(op2_info & MAY_BE_UNDEF)); |
6111 | 0 | ZEND_ASSERT((op1_info & MAY_BE_STRING) && (op2_info & MAY_BE_STRING)); |
6112 | |
|
6113 | 0 | op1_addr = OP1_ADDR(); |
6114 | 0 | op2_addr = OP2_ADDR(); |
6115 | |
|
6116 | 0 | return zend_jit_concat_helper(jit, opline, opline->op1_type, opline->op1, op1_addr, op1_info, opline->op2_type, opline->op2, op2_addr, op2_info, res_addr, may_throw); |
6117 | 0 | } |
6118 | | |
6119 | | static int zend_jit_assign_op(zend_jit_ctx *jit, |
6120 | | const zend_op *opline, |
6121 | | uint32_t op1_info, |
6122 | | zend_jit_addr op1_addr, |
6123 | | zend_ssa_range *op1_range, |
6124 | | uint32_t op1_def_info, |
6125 | | zend_jit_addr op1_def_addr, |
6126 | | uint32_t op1_mem_info, |
6127 | | uint32_t op2_info, |
6128 | | zend_jit_addr op2_addr, |
6129 | | zend_ssa_range *op2_range, |
6130 | | int may_overflow, |
6131 | | int may_throw) |
6132 | 0 | { |
6133 | 0 | int result = 1; |
6134 | 0 | ir_ref slow_path = IR_UNUSED; |
6135 | |
|
6136 | 0 | ZEND_ASSERT(opline->op1_type == IS_CV && opline->result_type == IS_UNUSED); |
6137 | 0 | ZEND_ASSERT(!(op1_info & MAY_BE_UNDEF) && !(op2_info & MAY_BE_UNDEF)); |
6138 | |
|
6139 | 0 | if (op1_info & MAY_BE_REF) { |
6140 | 0 | ir_ref ref, ref2, arg2, op1_noref_path; |
6141 | 0 | ir_ref if_op1_ref = IR_UNUSED; |
6142 | 0 | ir_ref if_op1_typed = IR_UNUSED; |
6143 | 0 | binary_op_type binary_op = get_binary_op(opline->extended_value); |
6144 | |
|
6145 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
6146 | 0 | if_op1_ref = jit_if_Z_TYPE_ref(jit, ref, ir_CONST_U8(IS_REFERENCE)); |
6147 | 0 | ir_IF_FALSE(if_op1_ref); |
6148 | 0 | op1_noref_path = ir_END(); |
6149 | 0 | ir_IF_TRUE(if_op1_ref); |
6150 | 0 | ref2 = jit_Z_PTR_ref(jit, ref); |
6151 | |
|
6152 | 0 | if_op1_typed = jit_if_TYPED_REF(jit, ref2); |
6153 | 0 | ir_IF_TRUE_cold(if_op1_typed); |
6154 | |
|
6155 | 0 | if (Z_MODE(op2_addr) == IS_REG) { |
6156 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op2.var); |
6157 | 0 | if (!zend_jit_spill_store_inv(jit, op2_addr, real_addr, op2_info)) { |
6158 | 0 | return 0; |
6159 | 0 | } |
6160 | 0 | arg2 = jit_ZVAL_ADDR(jit, real_addr); |
6161 | 0 | } else { |
6162 | 0 | arg2 = jit_ZVAL_ADDR(jit, op2_addr); |
6163 | 0 | } |
6164 | 0 | jit_SET_EX_OPLINE(jit, opline); |
6165 | 0 | if ((opline->op2_type & (IS_TMP_VAR|IS_VAR)) |
6166 | 0 | && (op2_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
6167 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_op_to_typed_ref_tmp), |
6168 | 0 | ref2, arg2, ir_CONST_FC_FUNC(binary_op)); |
6169 | 0 | } else { |
6170 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_op_to_typed_ref), |
6171 | 0 | ref2, arg2, ir_CONST_FC_FUNC(binary_op)); |
6172 | 0 | } |
6173 | 0 | zend_jit_check_exception(jit); |
6174 | 0 | slow_path = ir_END(); |
6175 | |
|
6176 | 0 | ir_IF_FALSE(if_op1_typed); |
6177 | 0 | ref2 = ir_ADD_OFFSET(ref2, offsetof(zend_reference, val)); |
6178 | |
|
6179 | 0 | ir_MERGE_WITH(op1_noref_path); |
6180 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
6181 | 0 | ZEND_ASSERT(op1_addr == op1_def_addr); |
6182 | 0 | op1_def_addr = op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
6183 | 0 | } |
6184 | | |
6185 | 0 | switch (opline->extended_value) { |
6186 | 0 | case ZEND_ADD: |
6187 | 0 | case ZEND_SUB: |
6188 | 0 | case ZEND_MUL: |
6189 | 0 | case ZEND_DIV: |
6190 | 0 | result = zend_jit_math_helper(jit, opline, opline->extended_value, opline->op1_type, opline->op1, op1_addr, op1_info, opline->op2_type, opline->op2, op2_addr, op2_info, opline->op1.var, op1_def_addr, op1_def_info, op1_mem_info, may_overflow, may_throw); |
6191 | 0 | break; |
6192 | 0 | case ZEND_BW_OR: |
6193 | 0 | case ZEND_BW_AND: |
6194 | 0 | case ZEND_BW_XOR: |
6195 | 0 | case ZEND_SL: |
6196 | 0 | case ZEND_SR: |
6197 | 0 | case ZEND_MOD: |
6198 | 0 | result = zend_jit_long_math_helper(jit, opline, opline->extended_value, |
6199 | 0 | opline->op1_type, opline->op1, op1_addr, op1_info, op1_range, |
6200 | 0 | opline->op2_type, opline->op2, op2_addr, op2_info, op2_range, |
6201 | 0 | opline->op1.var, op1_def_addr, op1_def_info, op1_mem_info, may_throw); |
6202 | 0 | break; |
6203 | 0 | case ZEND_CONCAT: |
6204 | 0 | result = zend_jit_concat_helper(jit, opline, opline->op1_type, opline->op1, op1_addr, op1_info, opline->op2_type, opline->op2, op2_addr, op2_info, op1_def_addr, may_throw); |
6205 | 0 | break; |
6206 | 0 | default: |
6207 | 0 | ZEND_UNREACHABLE(); |
6208 | 0 | } |
6209 | | |
6210 | 0 | if (!zend_jit_store_var_if_necessary_ex(jit, opline->op1.var, op1_def_addr, op1_def_info, op1_addr, op1_info)) { |
6211 | 0 | return 0; |
6212 | 0 | } |
6213 | | |
6214 | 0 | if (op1_info & MAY_BE_REF) { |
6215 | 0 | ir_MERGE_WITH(slow_path); |
6216 | 0 | } |
6217 | |
|
6218 | 0 | return result; |
6219 | 0 | } |
6220 | | |
6221 | | static ir_ref jit_ZVAL_DEREF_ref(zend_jit_ctx *jit, ir_ref ref) |
6222 | 0 | { |
6223 | 0 | ir_ref if_ref, ref2; |
6224 | |
|
6225 | 0 | if_ref = ir_IF(ir_EQ(jit_Z_TYPE_ref(jit, ref), ir_CONST_U8(IS_REFERENCE))); |
6226 | 0 | ir_IF_TRUE(if_ref); |
6227 | 0 | ref2 = ir_ADD_OFFSET(jit_Z_PTR_ref(jit, ref), offsetof(zend_reference, val)); |
6228 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_ref); |
6229 | 0 | return ir_PHI_2(IR_ADDR, ref2, ref); |
6230 | 0 | } |
6231 | | |
6232 | | static zend_jit_addr jit_ZVAL_DEREF(zend_jit_ctx *jit, zend_jit_addr addr) |
6233 | 0 | { |
6234 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, addr); |
6235 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
6236 | 0 | return ZEND_ADDR_REF_ZVAL(ref); |
6237 | 0 | } |
6238 | | |
6239 | | static ir_ref jit_ZVAL_INDIRECT_DEREF_ref(zend_jit_ctx *jit, ir_ref ref) |
6240 | 0 | { |
6241 | 0 | ir_ref if_ref, ref2; |
6242 | |
|
6243 | 0 | if_ref = ir_IF(ir_EQ(jit_Z_TYPE_ref(jit, ref), ir_CONST_U8(IS_INDIRECT))); |
6244 | 0 | ir_IF_TRUE(if_ref); |
6245 | 0 | ref2 = jit_Z_PTR_ref(jit, ref); |
6246 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_ref); |
6247 | 0 | return ir_PHI_2(IR_ADDR, ref2, ref); |
6248 | 0 | } |
6249 | | |
6250 | | static zend_jit_addr jit_ZVAL_INDIRECT_DEREF(zend_jit_ctx *jit, zend_jit_addr addr) |
6251 | 0 | { |
6252 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, addr); |
6253 | 0 | ref = jit_ZVAL_INDIRECT_DEREF_ref(jit, ref); |
6254 | 0 | return ZEND_ADDR_REF_ZVAL(ref); |
6255 | 0 | } |
6256 | | |
6257 | | static int zend_jit_simple_assign(zend_jit_ctx *jit, |
6258 | | const zend_op *opline, |
6259 | | zend_jit_addr var_addr, |
6260 | | uint32_t var_info, |
6261 | | uint32_t var_def_info, |
6262 | | uint8_t val_type, |
6263 | | zend_jit_addr val_addr, |
6264 | | uint32_t val_info, |
6265 | | zend_jit_addr res_addr, |
6266 | | bool check_exception) |
6267 | 0 | { |
6268 | 0 | ir_ref end_inputs = IR_UNUSED; |
6269 | |
|
6270 | 0 | if (Z_MODE(val_addr) == IS_CONST_ZVAL) { |
6271 | 0 | zval *zv = Z_ZV(val_addr); |
6272 | |
|
6273 | 0 | if (!res_addr) { |
6274 | 0 | jit_ZVAL_COPY_CONST(jit, |
6275 | 0 | var_addr, |
6276 | 0 | var_info, var_def_info, |
6277 | 0 | zv, true); |
6278 | 0 | } else { |
6279 | 0 | jit_ZVAL_COPY_CONST(jit, |
6280 | 0 | var_addr, |
6281 | 0 | var_info, var_def_info, |
6282 | 0 | zv, true); |
6283 | 0 | jit_ZVAL_COPY_CONST(jit, |
6284 | 0 | res_addr, |
6285 | 0 | -1, var_def_info, |
6286 | 0 | zv, true); |
6287 | 0 | } |
6288 | 0 | } else { |
6289 | 0 | if (val_info & MAY_BE_UNDEF) { |
6290 | 0 | ir_ref if_def, ret; |
6291 | |
|
6292 | 0 | if_def = jit_if_not_Z_TYPE(jit, val_addr, IS_UNDEF); |
6293 | 0 | ir_IF_FALSE_cold(if_def); |
6294 | |
|
6295 | 0 | jit_set_Z_TYPE_INFO(jit, var_addr, IS_NULL); |
6296 | 0 | if (res_addr) { |
6297 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
6298 | 0 | } |
6299 | 0 | jit_SET_EX_OPLINE(jit, opline); |
6300 | |
|
6301 | 0 | ZEND_ASSERT(Z_MODE(val_addr) == IS_MEM_ZVAL); |
6302 | | // zend_error_unchecked(E_WARNING, "Undefined variable $%S", CV_DEF_OF(EX_VAR_TO_NUM(opline->op1.var))); |
6303 | 0 | ret = ir_CALL_1(IR_I32, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(Z_OFFSET(val_addr))); |
6304 | |
|
6305 | 0 | if (check_exception) { |
6306 | 0 | ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler_undef)); |
6307 | 0 | } |
6308 | |
|
6309 | 0 | ir_END_list(end_inputs); |
6310 | 0 | ir_IF_TRUE(if_def); |
6311 | 0 | } |
6312 | 0 | if (val_info & MAY_BE_REF) { |
6313 | 0 | if (val_type == IS_CV) { |
6314 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, val_addr); |
6315 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
6316 | 0 | val_addr = ZEND_ADDR_REF_ZVAL(ref); |
6317 | 0 | } else { |
6318 | 0 | ir_ref ref, type, if_ref, ref2, refcount, if_not_zero; |
6319 | |
|
6320 | 0 | ref = jit_ZVAL_ADDR(jit, val_addr); |
6321 | 0 | type = jit_Z_TYPE_ref(jit, ref); |
6322 | 0 | if_ref = ir_IF(ir_EQ(type, ir_CONST_U8(IS_REFERENCE))); |
6323 | |
|
6324 | 0 | ir_IF_TRUE_cold(if_ref); |
6325 | 0 | ref = jit_Z_PTR_ref(jit, ref); |
6326 | 0 | ref2 = ir_ADD_OFFSET(ref, offsetof(zend_reference, val)); |
6327 | 0 | if (!res_addr) { |
6328 | 0 | jit_ZVAL_COPY(jit, |
6329 | 0 | var_addr, |
6330 | 0 | var_info, |
6331 | 0 | ZEND_ADDR_REF_ZVAL(ref2), val_info, true); |
6332 | 0 | } else { |
6333 | 0 | jit_ZVAL_COPY_2(jit, |
6334 | 0 | res_addr, |
6335 | 0 | var_addr, |
6336 | 0 | var_info, |
6337 | 0 | ZEND_ADDR_REF_ZVAL(ref2), val_info, 2); |
6338 | 0 | } |
6339 | |
|
6340 | 0 | refcount = jit_GC_DELREF(jit, ref); |
6341 | 0 | if_not_zero = ir_IF(refcount); |
6342 | 0 | ir_IF_FALSE(if_not_zero); |
6343 | | // TODO: instead of dtor() call and ADDREF above, we may call efree() and move addref at "true" path ??? |
6344 | | // This is related to GH-10168 (keep this before GH-10168 is completely closed) |
6345 | | // jit_EFREE(jit, ref, sizeof(zend_reference), NULL, NULL); |
6346 | 0 | jit_ZVAL_DTOR(jit, ref, val_info, opline); |
6347 | 0 | ir_END_list(end_inputs); |
6348 | 0 | ir_IF_TRUE(if_not_zero); |
6349 | 0 | ir_END_list(end_inputs); |
6350 | |
|
6351 | 0 | ir_IF_FALSE(if_ref); |
6352 | 0 | } |
6353 | 0 | } |
6354 | |
|
6355 | 0 | if (!res_addr) { |
6356 | 0 | jit_ZVAL_COPY(jit, |
6357 | 0 | var_addr, |
6358 | 0 | var_info, |
6359 | 0 | val_addr, val_info, val_type == IS_CV); |
6360 | 0 | } else { |
6361 | 0 | jit_ZVAL_COPY_2(jit, |
6362 | 0 | res_addr, |
6363 | 0 | var_addr, |
6364 | 0 | var_info, |
6365 | 0 | val_addr, val_info, val_type == IS_CV ? 2 : 1); |
6366 | 0 | } |
6367 | 0 | } |
6368 | |
|
6369 | 0 | if (end_inputs) { |
6370 | 0 | ir_END_list(end_inputs); |
6371 | 0 | ir_MERGE_list(end_inputs); |
6372 | 0 | } |
6373 | |
|
6374 | 0 | return 1; |
6375 | 0 | } |
6376 | | |
6377 | | static int zend_jit_assign_to_variable_call(zend_jit_ctx *jit, |
6378 | | const zend_op *opline, |
6379 | | zend_jit_addr __var_use_addr, |
6380 | | zend_jit_addr var_addr, |
6381 | | uint32_t __var_info, |
6382 | | uint32_t __var_def_info, |
6383 | | uint8_t val_type, |
6384 | | zend_jit_addr val_addr, |
6385 | | uint32_t val_info, |
6386 | | zend_jit_addr __res_addr, |
6387 | | bool __check_exception) |
6388 | 0 | { |
6389 | 0 | jit_stub_id func; |
6390 | 0 | ir_ref undef_path = IR_UNUSED; |
6391 | |
|
6392 | 0 | if (val_info & MAY_BE_UNDEF) { |
6393 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
6394 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
6395 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
6396 | |
|
6397 | 0 | if (!exit_addr) { |
6398 | 0 | return 0; |
6399 | 0 | } |
6400 | | |
6401 | 0 | jit_guard_not_Z_TYPE(jit, val_addr, IS_UNDEF, exit_addr); |
6402 | 0 | } else { |
6403 | 0 | ir_ref if_def; |
6404 | |
|
6405 | 0 | ZEND_ASSERT(Z_MODE(val_addr) == IS_MEM_ZVAL && Z_REG(val_addr) == ZREG_FP); |
6406 | 0 | if_def = ir_IF(jit_Z_TYPE(jit, val_addr)); |
6407 | 0 | ir_IF_FALSE_cold(if_def); |
6408 | 0 | jit_SET_EX_OPLINE(jit, opline); |
6409 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(Z_OFFSET(val_addr))); |
6410 | |
|
6411 | 0 | ir_CALL_2(IR_VOID, jit_STUB_FUNC_ADDR(jit, jit_stub_assign_const, IR_FASTCALL_FUNC), |
6412 | 0 | jit_ZVAL_ADDR(jit, var_addr), |
6413 | 0 | jit_EG(uninitialized_zval)); |
6414 | |
|
6415 | 0 | undef_path = ir_END(); |
6416 | 0 | ir_IF_TRUE(if_def); |
6417 | 0 | } |
6418 | 0 | } |
6419 | | |
6420 | 0 | if (!(val_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF))) { |
6421 | 0 | func = jit_stub_assign_tmp; |
6422 | 0 | } else if (val_type == IS_CONST) { |
6423 | 0 | func = jit_stub_assign_const; |
6424 | 0 | } else if (val_type == IS_TMP_VAR) { |
6425 | 0 | func = jit_stub_assign_tmp; |
6426 | 0 | } else if (val_type == IS_VAR) { |
6427 | 0 | if (!(val_info & MAY_BE_REF)) { |
6428 | 0 | func = jit_stub_assign_tmp; |
6429 | 0 | } else { |
6430 | 0 | func = jit_stub_assign_var; |
6431 | 0 | } |
6432 | 0 | } else if (val_type == IS_CV) { |
6433 | 0 | if (!(val_info & MAY_BE_REF)) { |
6434 | 0 | func = jit_stub_assign_cv_noref; |
6435 | 0 | } else { |
6436 | 0 | func = jit_stub_assign_cv; |
6437 | 0 | } |
6438 | 0 | } else { |
6439 | 0 | ZEND_UNREACHABLE(); |
6440 | 0 | } |
6441 | | |
6442 | 0 | if (opline) { |
6443 | 0 | jit_SET_EX_OPLINE(jit, opline); |
6444 | 0 | } |
6445 | |
|
6446 | 0 | ir_CALL_2(IR_VOID, jit_STUB_FUNC_ADDR(jit, func, IR_FASTCALL_FUNC), |
6447 | 0 | jit_ZVAL_ADDR(jit, var_addr), |
6448 | 0 | jit_ZVAL_ADDR(jit, val_addr)); |
6449 | |
|
6450 | 0 | if (undef_path) { |
6451 | 0 | ir_MERGE_WITH(undef_path); |
6452 | 0 | } |
6453 | |
|
6454 | 0 | return 1; |
6455 | 0 | } |
6456 | | |
6457 | | static int zend_jit_assign_to_variable(zend_jit_ctx *jit, |
6458 | | const zend_op *opline, |
6459 | | zend_jit_addr var_use_addr, |
6460 | | zend_jit_addr var_addr, |
6461 | | uint32_t var_info, |
6462 | | uint32_t var_def_info, |
6463 | | uint8_t val_type, |
6464 | | zend_jit_addr val_addr, |
6465 | | uint32_t val_info, |
6466 | | zend_jit_addr res_addr, |
6467 | | zend_jit_addr ref_addr, |
6468 | | bool check_exception) |
6469 | 0 | { |
6470 | 0 | ir_ref if_refcounted = IR_UNUSED; |
6471 | 0 | ir_ref simple_inputs = IR_UNUSED; |
6472 | 0 | bool done = false; |
6473 | 0 | zend_jit_addr real_res_addr = 0; |
6474 | 0 | ir_refs *end_inputs; |
6475 | 0 | ir_refs *res_inputs; |
6476 | |
|
6477 | 0 | ir_refs_init(end_inputs, 6); |
6478 | 0 | ir_refs_init(res_inputs, 6); |
6479 | |
|
6480 | 0 | if (Z_MODE(val_addr) == IS_REG && jit->ra[Z_SSA_VAR(val_addr)].ref == IR_NULL) { |
6481 | | /* Force load */ |
6482 | 0 | zend_jit_use_reg(jit, val_addr); |
6483 | 0 | } |
6484 | |
|
6485 | 0 | if (Z_MODE(var_addr) == IS_REG) { |
6486 | 0 | jit->delay_var = Z_SSA_VAR(var_addr); |
6487 | 0 | jit->delay_refs = res_inputs; |
6488 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
6489 | 0 | real_res_addr = res_addr; |
6490 | 0 | res_addr = 0; |
6491 | 0 | } |
6492 | 0 | } else if (Z_MODE(res_addr) == IS_REG) { |
6493 | 0 | jit->delay_var = Z_SSA_VAR(res_addr); |
6494 | 0 | jit->delay_refs = res_inputs; |
6495 | 0 | } |
6496 | |
|
6497 | 0 | if ((var_info & MAY_BE_REF) || ref_addr) { |
6498 | 0 | ir_ref ref = 0, if_ref = 0, ref2, arg2, if_typed, non_ref_path; |
6499 | 0 | uintptr_t func; |
6500 | |
|
6501 | 0 | if (!ref_addr) { |
6502 | 0 | ref = jit_ZVAL_ADDR(jit, var_use_addr); |
6503 | 0 | if_ref = jit_if_Z_TYPE_ref(jit, ref, ir_CONST_U8(IS_REFERENCE)); |
6504 | 0 | ir_IF_TRUE(if_ref); |
6505 | 0 | ref2 = jit_Z_PTR_ref(jit, ref); |
6506 | 0 | } else { |
6507 | 0 | ref2 = jit_ZVAL_ADDR(jit, ref_addr); |
6508 | 0 | } |
6509 | 0 | if_typed = jit_if_TYPED_REF(jit, ref2); |
6510 | 0 | ir_IF_TRUE_cold(if_typed); |
6511 | 0 | jit_SET_EX_OPLINE(jit, opline); |
6512 | 0 | if (Z_MODE(val_addr) == IS_REG) { |
6513 | 0 | zend_jit_addr real_addr; |
6514 | |
|
6515 | 0 | if (opline->opcode == ZEND_ASSIGN_DIM || opline->opcode == ZEND_ASSIGN_OBJ) { |
6516 | 0 | real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, (opline+1)->op1.var); |
6517 | 0 | } else { |
6518 | 0 | ZEND_ASSERT(opline->opcode == ZEND_ASSIGN); |
6519 | 0 | real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op2.var); |
6520 | 0 | } |
6521 | 0 | if (!zend_jit_spill_store_inv(jit, val_addr, real_addr, val_info)) { |
6522 | 0 | return 0; |
6523 | 0 | } |
6524 | 0 | arg2 = jit_ZVAL_ADDR(jit, real_addr); |
6525 | 0 | } else { |
6526 | 0 | arg2 = jit_ZVAL_ADDR(jit, val_addr); |
6527 | 0 | } |
6528 | 0 | if (!res_addr) { |
6529 | 0 | if (val_type == IS_CONST) { |
6530 | 0 | func = (uintptr_t)zend_jit_assign_const_to_typed_ref; |
6531 | 0 | } else if (val_type == IS_TMP_VAR) { |
6532 | 0 | func = (uintptr_t)zend_jit_assign_tmp_to_typed_ref; |
6533 | 0 | } else if (val_type == IS_VAR) { |
6534 | 0 | func = (uintptr_t)zend_jit_assign_var_to_typed_ref; |
6535 | 0 | } else if (val_type == IS_CV) { |
6536 | 0 | func = (uintptr_t)zend_jit_assign_cv_to_typed_ref; |
6537 | 0 | } else { |
6538 | 0 | ZEND_UNREACHABLE(); |
6539 | 0 | } |
6540 | 0 | ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(func), ref2, arg2); |
6541 | 0 | } else { |
6542 | 0 | if (val_type == IS_CONST) { |
6543 | 0 | func = (uintptr_t)zend_jit_assign_const_to_typed_ref2; |
6544 | 0 | } else if (val_type == IS_TMP_VAR) { |
6545 | 0 | func = (uintptr_t)zend_jit_assign_tmp_to_typed_ref2; |
6546 | 0 | } else if (val_type == IS_VAR) { |
6547 | 0 | func = (uintptr_t)zend_jit_assign_var_to_typed_ref2; |
6548 | 0 | } else if (val_type == IS_CV) { |
6549 | 0 | func = (uintptr_t)zend_jit_assign_cv_to_typed_ref2; |
6550 | 0 | } else { |
6551 | 0 | ZEND_UNREACHABLE(); |
6552 | 0 | } |
6553 | 0 | ir_CALL_3(IR_ADDR, ir_CONST_FC_FUNC(func), ref2, arg2, jit_ZVAL_ADDR(jit, res_addr)); |
6554 | 0 | } |
6555 | 0 | if (check_exception) { |
6556 | 0 | zend_jit_check_exception(jit); |
6557 | 0 | } |
6558 | 0 | ir_refs_add(end_inputs, ir_END()); |
6559 | |
|
6560 | 0 | if (!ref_addr) { |
6561 | 0 | ir_IF_FALSE(if_ref); |
6562 | 0 | non_ref_path = ir_END(); |
6563 | 0 | ir_IF_FALSE(if_typed); |
6564 | 0 | ref2 = ir_ADD_OFFSET(ref2, offsetof(zend_reference, val)); |
6565 | 0 | ir_MERGE_WITH(non_ref_path); |
6566 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
6567 | 0 | var_addr = var_use_addr = ZEND_ADDR_REF_ZVAL(ref); |
6568 | 0 | } else { |
6569 | 0 | ir_IF_FALSE(if_typed); |
6570 | 0 | } |
6571 | 0 | } |
6572 | | |
6573 | 0 | if (var_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
6574 | 0 | ir_ref ref, counter, if_not_zero; |
6575 | |
|
6576 | 0 | if (var_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
6577 | 0 | if_refcounted = jit_if_REFCOUNTED(jit, var_use_addr); |
6578 | 0 | ir_IF_FALSE(if_refcounted); |
6579 | 0 | ir_END_list(simple_inputs); |
6580 | 0 | ir_IF_TRUE_cold(if_refcounted); |
6581 | 0 | } else if (RC_MAY_BE_1(var_info)) { |
6582 | 0 | done = true; |
6583 | 0 | } |
6584 | 0 | ref = jit_Z_PTR(jit, var_use_addr); |
6585 | 0 | if (RC_MAY_BE_1(var_info)) { |
6586 | 0 | if (!zend_jit_simple_assign(jit, opline, var_addr, var_info, var_def_info, val_type, val_addr, val_info, res_addr, false)) { |
6587 | 0 | return 0; |
6588 | 0 | } |
6589 | 0 | counter = jit_GC_DELREF(jit, ref); |
6590 | |
|
6591 | 0 | if_not_zero = ir_IF(counter); |
6592 | 0 | ir_IF_FALSE(if_not_zero); |
6593 | 0 | jit_ZVAL_DTOR(jit, ref, var_info, opline); |
6594 | 0 | if (check_exception) { |
6595 | 0 | zend_jit_check_exception(jit); |
6596 | 0 | } |
6597 | 0 | ir_refs_add(end_inputs, ir_END()); |
6598 | 0 | ir_IF_TRUE(if_not_zero); |
6599 | 0 | if (RC_MAY_BE_N(var_info) && (var_info & (MAY_BE_ARRAY|MAY_BE_OBJECT)) != 0) { |
6600 | 0 | ir_ref if_may_leak = jit_if_GC_MAY_NOT_LEAK(jit, ref); |
6601 | 0 | ir_IF_FALSE(if_may_leak); |
6602 | 0 | if (opline) { |
6603 | 0 | jit_SET_EX_OPLINE(jit, opline); |
6604 | 0 | } |
6605 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(gc_possible_root), ref); |
6606 | |
|
6607 | 0 | if (Z_MODE(var_addr) == IS_REG || Z_MODE(res_addr) == IS_REG) { |
6608 | 0 | ZEND_ASSERT(jit->delay_refs == res_inputs); |
6609 | 0 | ZEND_ASSERT(res_inputs->count > 0); |
6610 | 0 | ir_refs_add(res_inputs, res_inputs->refs[res_inputs->count - 1]); |
6611 | 0 | } |
6612 | 0 | if (check_exception && (val_info & MAY_BE_UNDEF)) { |
6613 | 0 | zend_jit_check_exception(jit); |
6614 | 0 | } |
6615 | 0 | ir_refs_add(end_inputs, ir_END()); |
6616 | 0 | ir_IF_TRUE(if_may_leak); |
6617 | 0 | } |
6618 | 0 | if (Z_MODE(var_addr) == IS_REG || Z_MODE(res_addr) == IS_REG) { |
6619 | 0 | ZEND_ASSERT(jit->delay_refs == res_inputs); |
6620 | 0 | ZEND_ASSERT(res_inputs->count > 0); |
6621 | 0 | ir_refs_add(res_inputs, res_inputs->refs[res_inputs->count - 1]); |
6622 | 0 | } |
6623 | 0 | if (check_exception && (val_info & MAY_BE_UNDEF)) { |
6624 | 0 | zend_jit_check_exception(jit); |
6625 | 0 | } |
6626 | 0 | ir_refs_add(end_inputs, ir_END()); |
6627 | 0 | } else /* if (RC_MAY_BE_N(var_info)) */ { |
6628 | 0 | jit_GC_DELREF(jit, ref); |
6629 | 0 | if (var_info & (MAY_BE_ARRAY|MAY_BE_OBJECT)) { |
6630 | 0 | ir_ref if_may_leak = jit_if_GC_MAY_NOT_LEAK(jit, ref); |
6631 | 0 | ir_IF_FALSE(if_may_leak); |
6632 | 0 | if (opline) { |
6633 | 0 | jit_SET_EX_OPLINE(jit, opline); |
6634 | 0 | } |
6635 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(gc_possible_root), ref); |
6636 | 0 | ir_END_list(simple_inputs); |
6637 | 0 | ir_IF_TRUE(if_may_leak); |
6638 | 0 | } |
6639 | 0 | ir_END_list(simple_inputs); |
6640 | 0 | } |
6641 | 0 | } |
6642 | | |
6643 | 0 | if (simple_inputs) { |
6644 | 0 | ir_MERGE_list(simple_inputs); |
6645 | 0 | } |
6646 | |
|
6647 | 0 | if (!done) { |
6648 | 0 | if (!zend_jit_simple_assign(jit, opline, var_addr, var_info, var_def_info, val_type, val_addr, val_info, res_addr, check_exception)) { |
6649 | 0 | return 0; |
6650 | 0 | } |
6651 | 0 | if (end_inputs->count) { |
6652 | 0 | ir_refs_add(end_inputs, ir_END()); |
6653 | 0 | } |
6654 | 0 | } |
6655 | | |
6656 | 0 | if (end_inputs->count) { |
6657 | 0 | ir_MERGE_N(end_inputs->count, end_inputs->refs); |
6658 | 0 | } |
6659 | |
|
6660 | 0 | if (Z_MODE(var_addr) == IS_REG || Z_MODE(res_addr) == IS_REG) { |
6661 | 0 | ir_ref phi; |
6662 | |
|
6663 | 0 | ZEND_ASSERT(jit->delay_refs == res_inputs); |
6664 | 0 | ZEND_ASSERT(end_inputs->count == res_inputs->count || (end_inputs->count == 0 && res_inputs->count == 1)); |
6665 | 0 | jit->delay_var = -1; |
6666 | 0 | jit->delay_refs = NULL; |
6667 | 0 | if (res_inputs->count == 1) { |
6668 | 0 | phi = res_inputs->refs[0]; |
6669 | 0 | } else { |
6670 | 0 | phi = ir_PHI_N((var_def_info & MAY_BE_LONG & MAY_BE_LONG) ? IR_LONG : IR_DOUBLE, |
6671 | 0 | res_inputs->count, res_inputs->refs); |
6672 | 0 | } |
6673 | 0 | if (Z_MODE(var_addr) == IS_REG) { |
6674 | 0 | if ((var_info & (MAY_BE_REF|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) || ref_addr) { |
6675 | 0 | phi = ir_emit2(&jit->ctx, IR_OPT(IR_COPY, jit->ctx.ir_base[phi].type), phi, 1); |
6676 | 0 | } |
6677 | 0 | zend_jit_def_reg(jit, var_addr, phi); |
6678 | 0 | if (real_res_addr) { |
6679 | 0 | if (var_def_info & MAY_BE_LONG) { |
6680 | 0 | jit_set_Z_LVAL(jit, real_res_addr, jit_Z_LVAL(jit, var_addr)); |
6681 | 0 | } else { |
6682 | 0 | jit_set_Z_DVAL(jit, real_res_addr, jit_Z_DVAL(jit, var_addr)); |
6683 | 0 | } |
6684 | 0 | } |
6685 | 0 | } else { |
6686 | 0 | zend_jit_def_reg(jit, res_addr, phi); |
6687 | 0 | } |
6688 | 0 | } |
6689 | |
|
6690 | 0 | return 1; |
6691 | 0 | } |
6692 | | |
6693 | | static int zend_jit_qm_assign(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, zend_jit_addr op1_def_addr, uint32_t res_use_info, uint32_t res_info, zend_jit_addr res_addr) |
6694 | 0 | { |
6695 | 0 | if (op1_addr != op1_def_addr) { |
6696 | 0 | if (!zend_jit_update_regs(jit, opline->op1.var, op1_addr, op1_def_addr, op1_info)) { |
6697 | 0 | return 0; |
6698 | 0 | } |
6699 | 0 | if (Z_MODE(op1_def_addr) == IS_REG && Z_MODE(op1_addr) != IS_REG) { |
6700 | 0 | op1_addr = op1_def_addr; |
6701 | 0 | } |
6702 | 0 | } |
6703 | | |
6704 | 0 | if (!zend_jit_simple_assign(jit, opline, res_addr, res_use_info, res_info, opline->op1_type, op1_addr, op1_info, 0, true)) { |
6705 | 0 | return 0; |
6706 | 0 | } |
6707 | 0 | if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, res_info)) { |
6708 | 0 | return 0; |
6709 | 0 | } |
6710 | 0 | return 1; |
6711 | 0 | } |
6712 | | |
6713 | | static int zend_jit_assign(zend_jit_ctx *jit, |
6714 | | const zend_op *opline, |
6715 | | uint32_t op1_info, |
6716 | | zend_jit_addr op1_use_addr, |
6717 | | uint32_t op1_def_info, |
6718 | | zend_jit_addr op1_addr, |
6719 | | uint32_t op2_info, |
6720 | | zend_jit_addr op2_addr, |
6721 | | zend_jit_addr op2_def_addr, |
6722 | | uint32_t res_info, |
6723 | | zend_jit_addr res_addr, |
6724 | | zend_jit_addr ref_addr, |
6725 | | int may_throw) |
6726 | 0 | { |
6727 | 0 | ZEND_ASSERT(opline->op1_type == IS_CV); |
6728 | |
|
6729 | 0 | if (op2_addr != op2_def_addr) { |
6730 | 0 | if (!zend_jit_update_regs(jit, opline->op2.var, op2_addr, op2_def_addr, op2_info)) { |
6731 | 0 | return 0; |
6732 | 0 | } |
6733 | 0 | if (Z_MODE(op2_def_addr) == IS_REG && Z_MODE(op2_addr) != IS_REG) { |
6734 | 0 | op2_addr = op2_def_addr; |
6735 | 0 | } |
6736 | 0 | } |
6737 | | |
6738 | 0 | if (Z_MODE(op1_addr) != IS_REG |
6739 | 0 | && Z_MODE(op1_use_addr) == IS_REG |
6740 | 0 | && !Z_LOAD(op1_use_addr) |
6741 | 0 | && !Z_STORE(op1_use_addr)) { |
6742 | | /* Force type update */ |
6743 | 0 | op1_info |= MAY_BE_UNDEF; |
6744 | 0 | } |
6745 | 0 | if (!zend_jit_assign_to_variable(jit, opline, op1_use_addr, op1_addr, op1_info, op1_def_info, |
6746 | 0 | opline->op2_type, op2_addr, op2_info, res_addr, ref_addr, may_throw)) { |
6747 | 0 | return 0; |
6748 | 0 | } |
6749 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
6750 | 0 | if (Z_STORE(op1_addr)) { |
6751 | 0 | if (!zend_jit_store_var_if_necessary_ex(jit, opline->op1.var, op1_addr, op1_def_info, op1_use_addr, op1_info)) { |
6752 | 0 | return 0; |
6753 | 0 | } |
6754 | 0 | } else if ((op1_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) |
6755 | 0 | && Z_MODE(op1_use_addr) == IS_MEM_ZVAL |
6756 | 0 | && Z_REG(op1_use_addr) == ZREG_FP |
6757 | 0 | && EX_VAR_TO_NUM(Z_OFFSET(op1_use_addr)) < jit->current_op_array->last_var) { |
6758 | | /* We have to update type of CV because it may be captured by exception backtrace or released on RETURN */ |
6759 | 0 | if ((op1_def_info & MAY_BE_ANY) == MAY_BE_LONG) { |
6760 | 0 | jit_set_Z_TYPE_INFO(jit, op1_use_addr, IS_LONG); |
6761 | 0 | if (JIT_G(current_frame)) { |
6762 | 0 | SET_STACK_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(op1_use_addr)), IS_LONG, 1); |
6763 | 0 | } |
6764 | 0 | } else if ((op1_def_info & MAY_BE_ANY) == MAY_BE_DOUBLE) { |
6765 | 0 | jit_set_Z_TYPE_INFO(jit, op1_use_addr, IS_DOUBLE); |
6766 | 0 | if (JIT_G(current_frame)) { |
6767 | 0 | SET_STACK_TYPE(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(Z_OFFSET(op1_use_addr)), IS_DOUBLE, 1); |
6768 | 0 | } |
6769 | 0 | } else { |
6770 | 0 | ZEND_UNREACHABLE(); |
6771 | 0 | } |
6772 | 0 | } |
6773 | 0 | } |
6774 | 0 | if (opline->result_type != IS_UNUSED) { |
6775 | 0 | if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, res_info)) { |
6776 | 0 | return 0; |
6777 | 0 | } |
6778 | 0 | } |
6779 | | |
6780 | 0 | return 1; |
6781 | 0 | } |
6782 | | |
6783 | | static ir_op zend_jit_cmp_op(const zend_op *opline) |
6784 | 0 | { |
6785 | 0 | ir_op op; |
6786 | |
|
6787 | 0 | switch (opline->opcode) { |
6788 | 0 | case ZEND_IS_EQUAL: |
6789 | 0 | case ZEND_IS_IDENTICAL: |
6790 | 0 | case ZEND_CASE: |
6791 | 0 | case ZEND_CASE_STRICT: |
6792 | 0 | op = IR_EQ; |
6793 | 0 | break; |
6794 | 0 | case ZEND_IS_NOT_EQUAL: |
6795 | 0 | case ZEND_IS_NOT_IDENTICAL: |
6796 | 0 | op = IR_NE; |
6797 | 0 | break; |
6798 | 0 | case ZEND_IS_SMALLER: |
6799 | 0 | op = IR_LT; |
6800 | 0 | break; |
6801 | 0 | case ZEND_IS_SMALLER_OR_EQUAL: |
6802 | 0 | op = IR_LE; |
6803 | 0 | break; |
6804 | 0 | default: |
6805 | 0 | ZEND_UNREACHABLE(); |
6806 | 0 | } |
6807 | 0 | return op; |
6808 | 0 | } |
6809 | | |
6810 | | static ir_ref zend_jit_cmp_long_long(zend_jit_ctx *jit, |
6811 | | const zend_op *opline, |
6812 | | zend_ssa_range *op1_range, |
6813 | | zend_jit_addr op1_addr, |
6814 | | zend_ssa_range *op2_range, |
6815 | | zend_jit_addr op2_addr, |
6816 | | zend_jit_addr res_addr, |
6817 | | uint8_t smart_branch_opcode, |
6818 | | uint32_t target_label, |
6819 | | uint32_t target_label2, |
6820 | | const void *exit_addr, |
6821 | | bool skip_comparison) |
6822 | 0 | { |
6823 | 0 | ir_ref ref; |
6824 | 0 | bool result; |
6825 | |
|
6826 | 0 | if (zend_jit_is_constant_cmp_long_long(opline, op1_range, op1_addr, op2_range, op2_addr, &result)) { |
6827 | 0 | if (!smart_branch_opcode || |
6828 | 0 | smart_branch_opcode == ZEND_JMPZ_EX || |
6829 | 0 | smart_branch_opcode == ZEND_JMPNZ_EX) { |
6830 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, result ? IS_TRUE : IS_FALSE); |
6831 | 0 | } |
6832 | 0 | if (smart_branch_opcode && !exit_addr) { |
6833 | 0 | if (smart_branch_opcode == ZEND_JMPZ || |
6834 | 0 | smart_branch_opcode == ZEND_JMPZ_EX) { |
6835 | 0 | return jit_IF_ex(jit, IR_FALSE, result ? target_label : target_label2); |
6836 | 0 | } else if (smart_branch_opcode == ZEND_JMPNZ || |
6837 | 0 | smart_branch_opcode == ZEND_JMPNZ_EX) { |
6838 | 0 | return jit_IF_ex(jit, IR_TRUE, result ? target_label : target_label2); |
6839 | 0 | } else { |
6840 | 0 | ZEND_UNREACHABLE(); |
6841 | 0 | } |
6842 | 0 | } |
6843 | 0 | if (opline->opcode != ZEND_IS_IDENTICAL |
6844 | 0 | && opline->opcode != ZEND_IS_NOT_IDENTICAL |
6845 | 0 | && opline->opcode != ZEND_CASE_STRICT) { |
6846 | 0 | return ir_END(); |
6847 | 0 | } else { |
6848 | 0 | return IR_NULL; /* success */ |
6849 | 0 | } |
6850 | 0 | } |
6851 | | |
6852 | 0 | ref = ir_CMP_OP(zend_jit_cmp_op(opline), jit_Z_LVAL(jit, op1_addr), jit_Z_LVAL(jit, op2_addr)); |
6853 | |
|
6854 | 0 | if (!smart_branch_opcode || smart_branch_opcode == ZEND_JMPNZ_EX || smart_branch_opcode == ZEND_JMPZ_EX) { |
6855 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
6856 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
6857 | 0 | } |
6858 | 0 | if (exit_addr) { |
6859 | 0 | if (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) { |
6860 | 0 | if (opline->opcode != ZEND_IS_NOT_IDENTICAL) { |
6861 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
6862 | 0 | } else { |
6863 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
6864 | 0 | } |
6865 | 0 | } else { |
6866 | 0 | if (opline->opcode != ZEND_IS_NOT_IDENTICAL) { |
6867 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
6868 | 0 | } else { |
6869 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
6870 | 0 | } |
6871 | 0 | } |
6872 | 0 | } else if (smart_branch_opcode) { |
6873 | 0 | return jit_IF_ex(jit, ref, |
6874 | 0 | (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? target_label2 : target_label); |
6875 | 0 | } |
6876 | | |
6877 | 0 | if (opline->opcode != ZEND_IS_IDENTICAL |
6878 | 0 | && opline->opcode != ZEND_IS_NOT_IDENTICAL |
6879 | 0 | && opline->opcode != ZEND_CASE_STRICT) { |
6880 | 0 | return ir_END(); |
6881 | 0 | } else { |
6882 | 0 | return IR_NULL; /* success */ |
6883 | 0 | } |
6884 | 0 | } |
6885 | | |
6886 | | static ir_ref zend_jit_cmp_long_double(zend_jit_ctx *jit, const zend_op *opline, zend_jit_addr op1_addr, zend_jit_addr op2_addr, zend_jit_addr res_addr, uint8_t smart_branch_opcode, uint32_t target_label, uint32_t target_label2, const void *exit_addr) |
6887 | 0 | { |
6888 | 0 | ir_ref ref = ir_CMP_OP(zend_jit_cmp_op(opline), ir_INT2D(jit_Z_LVAL(jit, op1_addr)), jit_Z_DVAL(jit, op2_addr)); |
6889 | |
|
6890 | 0 | if (!smart_branch_opcode || smart_branch_opcode == ZEND_JMPNZ_EX || smart_branch_opcode == ZEND_JMPZ_EX) { |
6891 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
6892 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
6893 | 0 | } |
6894 | 0 | if (exit_addr) { |
6895 | 0 | if (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) { |
6896 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
6897 | 0 | } else { |
6898 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
6899 | 0 | } |
6900 | 0 | } else if (smart_branch_opcode) { |
6901 | 0 | return jit_IF_ex(jit, ref, |
6902 | 0 | (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? target_label2 : target_label); |
6903 | 0 | } |
6904 | 0 | return ir_END(); |
6905 | 0 | } |
6906 | | |
6907 | | static ir_ref zend_jit_cmp_double_long(zend_jit_ctx *jit, const zend_op *opline, zend_jit_addr op1_addr, zend_jit_addr op2_addr, zend_jit_addr res_addr, uint8_t smart_branch_opcode, uint32_t target_label, uint32_t target_label2, const void *exit_addr) |
6908 | 0 | { |
6909 | 0 | ir_ref ref = ir_CMP_OP(zend_jit_cmp_op(opline), jit_Z_DVAL(jit, op1_addr), ir_INT2D(jit_Z_LVAL(jit, op2_addr))); |
6910 | |
|
6911 | 0 | if (!smart_branch_opcode || smart_branch_opcode == ZEND_JMPNZ_EX || smart_branch_opcode == ZEND_JMPZ_EX) { |
6912 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
6913 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
6914 | 0 | } |
6915 | 0 | if (exit_addr) { |
6916 | 0 | if (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) { |
6917 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
6918 | 0 | } else { |
6919 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
6920 | 0 | } |
6921 | 0 | } else if (smart_branch_opcode) { |
6922 | 0 | return jit_IF_ex(jit, ref, |
6923 | 0 | (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? target_label2 : target_label); |
6924 | 0 | } |
6925 | 0 | return ir_END(); |
6926 | 0 | } |
6927 | | |
6928 | | static ir_ref zend_jit_cmp_double_double(zend_jit_ctx *jit, const zend_op *opline, zend_jit_addr op1_addr, zend_jit_addr op2_addr, zend_jit_addr res_addr, uint8_t smart_branch_opcode, uint32_t target_label, uint32_t target_label2, const void *exit_addr) |
6929 | 0 | { |
6930 | 0 | ir_ref ref = ir_CMP_OP(zend_jit_cmp_op(opline), jit_Z_DVAL(jit, op1_addr), jit_Z_DVAL(jit, op2_addr)); |
6931 | |
|
6932 | 0 | if (!smart_branch_opcode || smart_branch_opcode == ZEND_JMPNZ_EX || smart_branch_opcode == ZEND_JMPZ_EX) { |
6933 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
6934 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
6935 | 0 | } |
6936 | 0 | if (exit_addr) { |
6937 | 0 | if (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) { |
6938 | 0 | if (opline->opcode != ZEND_IS_NOT_IDENTICAL) { |
6939 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
6940 | 0 | } else { |
6941 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
6942 | 0 | } |
6943 | 0 | } else { |
6944 | 0 | if (opline->opcode != ZEND_IS_NOT_IDENTICAL) { |
6945 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
6946 | 0 | } else { |
6947 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
6948 | 0 | } |
6949 | 0 | } |
6950 | 0 | } else if (smart_branch_opcode) { |
6951 | 0 | return jit_IF_ex(jit, ref, |
6952 | 0 | (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? target_label2 : target_label); |
6953 | 0 | } |
6954 | 0 | if (opline->opcode != ZEND_IS_IDENTICAL |
6955 | 0 | && opline->opcode != ZEND_IS_NOT_IDENTICAL |
6956 | 0 | && opline->opcode != ZEND_CASE_STRICT) { |
6957 | 0 | return ir_END(); |
6958 | 0 | } else { |
6959 | 0 | return IR_NULL; /* success */ |
6960 | 0 | } |
6961 | 0 | } |
6962 | | |
6963 | | static ir_ref zend_jit_cmp_slow(zend_jit_ctx *jit, ir_ref ref, const zend_op *opline, zend_jit_addr res_addr, uint8_t smart_branch_opcode, uint32_t target_label, uint32_t target_label2, const void *exit_addr) |
6964 | 0 | { |
6965 | 0 | ref = ir_CMP_OP(zend_jit_cmp_op(opline), ref, ir_CONST_I32(0)); |
6966 | |
|
6967 | 0 | if (!smart_branch_opcode || smart_branch_opcode == ZEND_JMPNZ_EX || smart_branch_opcode == ZEND_JMPZ_EX) { |
6968 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
6969 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
6970 | 0 | } |
6971 | 0 | if (exit_addr) { |
6972 | 0 | if (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) { |
6973 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
6974 | 0 | } else { |
6975 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
6976 | 0 | } |
6977 | 0 | } else if (smart_branch_opcode) { |
6978 | 0 | return jit_IF_ex(jit, ref, |
6979 | 0 | (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? target_label2 : target_label); |
6980 | 0 | } |
6981 | | |
6982 | 0 | return ir_END(); |
6983 | 0 | } |
6984 | | |
6985 | | static int zend_jit_cmp(zend_jit_ctx *jit, |
6986 | | const zend_op *opline, |
6987 | | uint32_t op1_info, |
6988 | | zend_ssa_range *op1_range, |
6989 | | zend_jit_addr op1_addr, |
6990 | | uint32_t op2_info, |
6991 | | zend_ssa_range *op2_range, |
6992 | | zend_jit_addr op2_addr, |
6993 | | zend_jit_addr res_addr, |
6994 | | int may_throw, |
6995 | | uint8_t smart_branch_opcode, |
6996 | | uint32_t target_label, |
6997 | | uint32_t target_label2, |
6998 | | const void *exit_addr, |
6999 | | bool skip_comparison) |
7000 | 0 | { |
7001 | 0 | ir_ref ref = IR_UNUSED; |
7002 | 0 | ir_ref if_op1_long = IR_UNUSED; |
7003 | 0 | ir_ref if_op1_double = IR_UNUSED; |
7004 | 0 | ir_ref if_op2_double = IR_UNUSED; |
7005 | 0 | ir_ref if_op1_long_op2_long = IR_UNUSED; |
7006 | 0 | ir_ref if_op1_long_op2_double = IR_UNUSED; |
7007 | 0 | ir_ref if_op1_double_op2_double = IR_UNUSED; |
7008 | 0 | ir_ref if_op1_double_op2_long = IR_UNUSED; |
7009 | 0 | ir_ref slow_inputs = IR_UNUSED; |
7010 | 0 | bool same_ops = zend_jit_same_addr(op1_addr, op2_addr); |
7011 | 0 | bool has_slow = |
7012 | 0 | (op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE)) && |
7013 | 0 | (op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE)) && |
7014 | 0 | ((op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) || |
7015 | 0 | (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE)))); |
7016 | 0 | ir_refs *end_inputs; |
7017 | |
|
7018 | 0 | ir_refs_init(end_inputs, 8); |
7019 | |
|
7020 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
7021 | 0 | if (!has_concrete_type(op2_info & MAY_BE_ANY) && jit->ra[Z_SSA_VAR(op1_addr)].ref == IR_NULL) { |
7022 | | /* Force load */ |
7023 | 0 | zend_jit_use_reg(jit, op1_addr); |
7024 | 0 | } |
7025 | 0 | } else if (Z_MODE(op2_addr) == IS_REG) { |
7026 | 0 | if (!has_concrete_type(op1_info & MAY_BE_ANY) && jit->ra[Z_SSA_VAR(op2_addr)].ref == IR_NULL) { |
7027 | | /* Force load */ |
7028 | 0 | zend_jit_use_reg(jit, op2_addr); |
7029 | 0 | } |
7030 | 0 | } |
7031 | |
|
7032 | 0 | if ((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG)) { |
7033 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) { |
7034 | 0 | if_op1_long = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
7035 | 0 | ir_IF_TRUE(if_op1_long); |
7036 | 0 | } |
7037 | 0 | if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG))) { |
7038 | 0 | if_op1_long_op2_long = jit_if_Z_TYPE(jit, op2_addr, IS_LONG); |
7039 | 0 | ir_IF_FALSE_cold(if_op1_long_op2_long); |
7040 | 0 | if (op2_info & MAY_BE_DOUBLE) { |
7041 | 0 | if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) { |
7042 | 0 | if_op1_long_op2_double = jit_if_Z_TYPE(jit, op2_addr, IS_DOUBLE); |
7043 | 0 | ir_IF_FALSE_cold(if_op1_long_op2_double); |
7044 | 0 | ir_END_list(slow_inputs); |
7045 | 0 | ir_IF_TRUE(if_op1_long_op2_double); |
7046 | 0 | } |
7047 | 0 | ref = zend_jit_cmp_long_double(jit, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr); |
7048 | 0 | if (!ref) { |
7049 | 0 | return 0; |
7050 | 0 | } |
7051 | 0 | ir_refs_add(end_inputs, ref); |
7052 | 0 | } else { |
7053 | 0 | ir_END_list(slow_inputs); |
7054 | 0 | } |
7055 | 0 | ir_IF_TRUE(if_op1_long_op2_long); |
7056 | 0 | } |
7057 | 0 | ref = zend_jit_cmp_long_long(jit, opline, op1_range, op1_addr, op2_range, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr, skip_comparison); |
7058 | 0 | if (!ref) { |
7059 | 0 | return 0; |
7060 | 0 | } |
7061 | 0 | ir_refs_add(end_inputs, ref); |
7062 | |
|
7063 | 0 | if (if_op1_long) { |
7064 | 0 | ir_IF_FALSE_cold(if_op1_long); |
7065 | 0 | } |
7066 | 0 | if (op1_info & MAY_BE_DOUBLE) { |
7067 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) { |
7068 | 0 | if_op1_double = jit_if_Z_TYPE(jit, op1_addr, IS_DOUBLE); |
7069 | 0 | ir_IF_FALSE_cold(if_op1_double); |
7070 | 0 | ir_END_list(slow_inputs); |
7071 | 0 | ir_IF_TRUE(if_op1_double); |
7072 | 0 | } |
7073 | 0 | if (op2_info & MAY_BE_DOUBLE) { |
7074 | 0 | if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) { |
7075 | 0 | if_op1_double_op2_double = jit_if_Z_TYPE(jit, op2_addr, IS_DOUBLE); |
7076 | 0 | ir_IF_TRUE(if_op1_double_op2_double); |
7077 | 0 | } |
7078 | 0 | ref = zend_jit_cmp_double_double(jit, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr); |
7079 | 0 | if (!ref) { |
7080 | 0 | return 0; |
7081 | 0 | } |
7082 | 0 | ir_refs_add(end_inputs, ref); |
7083 | 0 | if (if_op1_double_op2_double) { |
7084 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_double); |
7085 | 0 | } |
7086 | 0 | } |
7087 | 0 | if (!same_ops) { |
7088 | 0 | if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) { |
7089 | 0 | if_op1_double_op2_long = jit_if_Z_TYPE(jit, op2_addr, IS_LONG); |
7090 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_long); |
7091 | 0 | ir_END_list(slow_inputs); |
7092 | 0 | ir_IF_TRUE(if_op1_double_op2_long); |
7093 | 0 | } |
7094 | 0 | ref = zend_jit_cmp_double_long(jit, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr); |
7095 | 0 | if (!ref) { |
7096 | 0 | return 0; |
7097 | 0 | } |
7098 | 0 | ir_refs_add(end_inputs, ref); |
7099 | 0 | } else if (if_op1_double_op2_double) { |
7100 | 0 | ir_END_list(slow_inputs); |
7101 | 0 | } |
7102 | 0 | } else if (if_op1_long) { |
7103 | 0 | ir_END_list(slow_inputs); |
7104 | 0 | } |
7105 | 0 | } else if ((op1_info & MAY_BE_DOUBLE) && |
7106 | 0 | !(op1_info & MAY_BE_LONG) && |
7107 | 0 | (op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) { |
7108 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) { |
7109 | 0 | if_op1_double = jit_if_Z_TYPE(jit, op1_addr, IS_DOUBLE); |
7110 | 0 | ir_IF_FALSE_cold(if_op1_double); |
7111 | 0 | ir_END_list(slow_inputs); |
7112 | 0 | ir_IF_TRUE(if_op1_double); |
7113 | 0 | } |
7114 | 0 | if (op2_info & MAY_BE_DOUBLE) { |
7115 | 0 | if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) { |
7116 | 0 | if_op1_double_op2_double = jit_if_Z_TYPE(jit, op2_addr, IS_DOUBLE); |
7117 | 0 | ir_IF_TRUE(if_op1_double_op2_double); |
7118 | 0 | } |
7119 | 0 | ref = zend_jit_cmp_double_double(jit, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr); |
7120 | 0 | if (!ref) { |
7121 | 0 | return 0; |
7122 | 0 | } |
7123 | 0 | ir_refs_add(end_inputs, ref); |
7124 | 0 | if (if_op1_double_op2_double) { |
7125 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_double); |
7126 | 0 | } |
7127 | 0 | } |
7128 | 0 | if (!same_ops && (op2_info & MAY_BE_LONG)) { |
7129 | 0 | if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) { |
7130 | 0 | if_op1_double_op2_long = jit_if_Z_TYPE(jit, op2_addr, IS_LONG); |
7131 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_long); |
7132 | 0 | ir_END_list(slow_inputs); |
7133 | 0 | ir_IF_TRUE(if_op1_double_op2_long); |
7134 | 0 | } |
7135 | 0 | ref = zend_jit_cmp_double_long(jit, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr); |
7136 | 0 | if (!ref) { |
7137 | 0 | return 0; |
7138 | 0 | } |
7139 | 0 | ir_refs_add(end_inputs, ref); |
7140 | 0 | } else if (if_op1_double_op2_double) { |
7141 | 0 | ir_END_list(slow_inputs); |
7142 | 0 | } |
7143 | 0 | } else if ((op2_info & MAY_BE_DOUBLE) && |
7144 | 0 | !(op2_info & MAY_BE_LONG) && |
7145 | 0 | (op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) { |
7146 | 0 | if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) { |
7147 | 0 | if_op2_double = jit_if_Z_TYPE(jit, op2_addr, IS_DOUBLE); |
7148 | 0 | ir_IF_FALSE_cold(if_op2_double); |
7149 | 0 | ir_END_list(slow_inputs); |
7150 | 0 | ir_IF_TRUE(if_op2_double); |
7151 | 0 | } |
7152 | 0 | if (op1_info & MAY_BE_DOUBLE) { |
7153 | 0 | if (!same_ops && (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) { |
7154 | 0 | if_op1_double_op2_double = jit_if_Z_TYPE(jit, op1_addr, IS_DOUBLE); |
7155 | 0 | ir_IF_TRUE(if_op1_double_op2_double); |
7156 | 0 | } |
7157 | 0 | ref = zend_jit_cmp_double_double(jit, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr); |
7158 | 0 | if (!ref) { |
7159 | 0 | return 0; |
7160 | 0 | } |
7161 | 0 | ir_refs_add(end_inputs, ref); |
7162 | 0 | if (if_op1_double_op2_double) { |
7163 | 0 | ir_IF_FALSE_cold(if_op1_double_op2_double); |
7164 | 0 | } |
7165 | 0 | } |
7166 | 0 | if (!same_ops && (op1_info & MAY_BE_LONG)) { |
7167 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) { |
7168 | 0 | if_op1_long_op2_double = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
7169 | 0 | ir_IF_FALSE_cold(if_op1_long_op2_double); |
7170 | 0 | ir_END_list(slow_inputs); |
7171 | 0 | ir_IF_TRUE(if_op1_long_op2_double); |
7172 | 0 | } |
7173 | 0 | ref = zend_jit_cmp_long_double(jit, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr); |
7174 | 0 | if (!ref) { |
7175 | 0 | return 0; |
7176 | 0 | } |
7177 | 0 | ir_refs_add(end_inputs, ref); |
7178 | 0 | } else if (if_op1_double_op2_double) { |
7179 | 0 | ir_END_list(slow_inputs); |
7180 | 0 | } |
7181 | 0 | } |
7182 | | |
7183 | 0 | if (has_slow || |
7184 | 0 | (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) || |
7185 | 0 | (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE)))) { |
7186 | 0 | ir_ref op1, op2, ref; |
7187 | |
|
7188 | 0 | if (slow_inputs) { |
7189 | 0 | ir_MERGE_list(slow_inputs); |
7190 | 0 | } |
7191 | 0 | jit_SET_EX_OPLINE(jit, opline); |
7192 | |
|
7193 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
7194 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op1.var); |
7195 | 0 | if (!zend_jit_spill_store_inv(jit, op1_addr, real_addr, op1_info)) { |
7196 | 0 | return 0; |
7197 | 0 | } |
7198 | 0 | op1_addr = real_addr; |
7199 | 0 | } |
7200 | 0 | if (Z_MODE(op2_addr) == IS_REG) { |
7201 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op2.var); |
7202 | 0 | if (!zend_jit_spill_store_inv(jit, op2_addr, real_addr, op2_info)) { |
7203 | 0 | return 0; |
7204 | 0 | } |
7205 | 0 | op2_addr = real_addr; |
7206 | 0 | } |
7207 | | |
7208 | 0 | op1 = jit_ZVAL_ADDR(jit, op1_addr); |
7209 | 0 | if (opline->op1_type == IS_CV && (op1_info & MAY_BE_UNDEF)) { |
7210 | 0 | op1 = zend_jit_zval_check_undef(jit, op1, opline->op1.var, NULL, false); |
7211 | 0 | } |
7212 | 0 | op2 = jit_ZVAL_ADDR(jit, op2_addr); |
7213 | 0 | if (opline->op2_type == IS_CV && (op2_info & MAY_BE_UNDEF)) { |
7214 | 0 | op2 = zend_jit_zval_check_undef(jit, op2, opline->op2.var, NULL, false); |
7215 | 0 | } |
7216 | 0 | ref = ir_CALL_2(IR_I32, ir_CONST_FC_FUNC(zend_compare), op1, op2); |
7217 | 0 | if (opline->opcode != ZEND_CASE) { |
7218 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL); |
7219 | 0 | } |
7220 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, NULL); |
7221 | 0 | if (may_throw) { |
7222 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
7223 | 0 | } |
7224 | |
|
7225 | 0 | ref = zend_jit_cmp_slow(jit, ref, opline, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr); |
7226 | 0 | if (!ref) { |
7227 | 0 | return 0; |
7228 | 0 | } |
7229 | 0 | ir_refs_add(end_inputs, ref); |
7230 | 0 | } |
7231 | | |
7232 | 0 | if (end_inputs->count) { |
7233 | 0 | uint32_t n = end_inputs->count; |
7234 | |
|
7235 | 0 | if (smart_branch_opcode && !exit_addr) { |
7236 | 0 | zend_basic_block *bb; |
7237 | 0 | ir_ref ref; |
7238 | 0 | uint32_t label = (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? |
7239 | 0 | target_label2 : target_label; |
7240 | 0 | uint32_t label2 = (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? |
7241 | 0 | target_label : target_label2; |
7242 | |
|
7243 | 0 | ZEND_ASSERT(jit->b >= 0); |
7244 | 0 | bb = &jit->ssa->cfg.blocks[jit->b]; |
7245 | 0 | ZEND_ASSERT(bb->successors_count == 2); |
7246 | |
|
7247 | 0 | if (UNEXPECTED(bb->successors[0] == bb->successors[1])) { |
7248 | 0 | ir_ref merge_inputs = IR_UNUSED; |
7249 | |
|
7250 | 0 | while (n) { |
7251 | 0 | n--; |
7252 | 0 | ir_IF_TRUE(end_inputs->refs[n]); |
7253 | 0 | ir_END_list(merge_inputs); |
7254 | 0 | ir_IF_FALSE(end_inputs->refs[n]); |
7255 | 0 | ir_END_list(merge_inputs); |
7256 | 0 | } |
7257 | 0 | ir_MERGE_list(merge_inputs); |
7258 | 0 | _zend_jit_add_predecessor_ref(jit, label, jit->b, ir_END()); |
7259 | 0 | } else if (n == 1) { |
7260 | 0 | ref = end_inputs->refs[0]; |
7261 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ref); |
7262 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[1], jit->b, ref); |
7263 | 0 | } else { |
7264 | 0 | ir_ref true_inputs = IR_UNUSED, false_inputs = IR_UNUSED; |
7265 | |
|
7266 | 0 | while (n) { |
7267 | 0 | n--; |
7268 | 0 | jit_IF_TRUE_FALSE_ex(jit, end_inputs->refs[n], label); |
7269 | 0 | ir_END_list(true_inputs); |
7270 | 0 | jit_IF_TRUE_FALSE_ex(jit, end_inputs->refs[n], label2); |
7271 | 0 | ir_END_list(false_inputs); |
7272 | 0 | } |
7273 | 0 | ir_MERGE_list(true_inputs); |
7274 | 0 | _zend_jit_add_predecessor_ref(jit, label, jit->b, ir_END()); |
7275 | 0 | ir_MERGE_list(false_inputs); |
7276 | 0 | _zend_jit_add_predecessor_ref(jit, label2, jit->b, ir_END()); |
7277 | 0 | } |
7278 | 0 | jit->b = -1; |
7279 | 0 | } else { |
7280 | 0 | ir_MERGE_N(n, end_inputs->refs); |
7281 | 0 | } |
7282 | 0 | } else if (smart_branch_opcode && !exit_addr) { |
7283 | | /* dead code */ |
7284 | 0 | _zend_jit_add_predecessor_ref(jit, target_label, jit->b, ir_END()); |
7285 | 0 | jit->b = -1; |
7286 | 0 | } |
7287 | |
|
7288 | 0 | return 1; |
7289 | 0 | } |
7290 | | |
7291 | | static int zend_jit_identical(zend_jit_ctx *jit, |
7292 | | const zend_op *opline, |
7293 | | uint32_t op1_info, |
7294 | | zend_ssa_range *op1_range, |
7295 | | zend_jit_addr op1_addr, |
7296 | | uint32_t op2_info, |
7297 | | zend_ssa_range *op2_range, |
7298 | | zend_jit_addr op2_addr, |
7299 | | zend_jit_addr res_addr, |
7300 | | int may_throw, |
7301 | | uint8_t smart_branch_opcode, |
7302 | | uint32_t target_label, |
7303 | | uint32_t target_label2, |
7304 | | const void *exit_addr, |
7305 | | bool skip_comparison) |
7306 | 0 | { |
7307 | 0 | bool always_false = false, always_true = false; |
7308 | 0 | ir_ref ref = IR_UNUSED; |
7309 | |
|
7310 | 0 | if (opline->op1_type == IS_CV && (op1_info & MAY_BE_UNDEF)) { |
7311 | 0 | ir_ref op1 = jit_ZVAL_ADDR(jit, op1_addr); |
7312 | 0 | op1 = zend_jit_zval_check_undef(jit, op1, opline->op1.var, opline, false); |
7313 | 0 | op1_info |= MAY_BE_NULL; |
7314 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(op1); |
7315 | 0 | } |
7316 | 0 | if (opline->op2_type == IS_CV && (op2_info & MAY_BE_UNDEF)) { |
7317 | 0 | ir_ref op2 = jit_ZVAL_ADDR(jit, op2_addr); |
7318 | 0 | op2 = zend_jit_zval_check_undef(jit, op2, opline->op2.var, opline, false); |
7319 | 0 | op2_info |= MAY_BE_NULL; |
7320 | 0 | op2_addr = ZEND_ADDR_REF_ZVAL(op2); |
7321 | 0 | } |
7322 | |
|
7323 | 0 | if ((op1_info & op2_info & MAY_BE_ANY) == 0) { |
7324 | 0 | always_false = true; |
7325 | 0 | } else if (has_concrete_type(op1_info) |
7326 | 0 | && has_concrete_type(op2_info) |
7327 | 0 | && concrete_type(op1_info) == concrete_type(op2_info) |
7328 | 0 | && concrete_type(op1_info) <= IS_TRUE) { |
7329 | 0 | always_true = true; |
7330 | 0 | } else if (Z_MODE(op1_addr) == IS_CONST_ZVAL && Z_MODE(op2_addr) == IS_CONST_ZVAL) { |
7331 | 0 | if (zend_is_identical(Z_ZV(op1_addr), Z_ZV(op2_addr))) { |
7332 | 0 | always_true = true; |
7333 | 0 | } else { |
7334 | 0 | always_false = true; |
7335 | 0 | } |
7336 | 0 | } |
7337 | |
|
7338 | 0 | if (always_true) { |
7339 | 0 | if (opline->opcode != ZEND_CASE_STRICT) { |
7340 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
7341 | 0 | } |
7342 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, opline); |
7343 | 0 | if (!smart_branch_opcode |
7344 | 0 | || smart_branch_opcode == ZEND_JMPZ_EX |
7345 | 0 | || smart_branch_opcode == ZEND_JMPNZ_EX) { |
7346 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, opline->opcode != ZEND_IS_NOT_IDENTICAL ? IS_TRUE : IS_FALSE); |
7347 | 0 | } |
7348 | 0 | if (may_throw) { |
7349 | 0 | zend_jit_check_exception(jit); |
7350 | 0 | } |
7351 | 0 | if (exit_addr) { |
7352 | 0 | if (smart_branch_opcode == ZEND_JMPNZ || smart_branch_opcode == ZEND_JMPNZ_EX) { |
7353 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
7354 | 0 | } |
7355 | 0 | } else if (smart_branch_opcode) { |
7356 | 0 | uint32_t label; |
7357 | |
|
7358 | 0 | if (opline->opcode == ZEND_IS_NOT_IDENTICAL) { |
7359 | 0 | label = (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? |
7360 | 0 | target_label : target_label2; |
7361 | 0 | } else { |
7362 | 0 | label = (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? |
7363 | 0 | target_label2 : target_label; |
7364 | 0 | } |
7365 | 0 | _zend_jit_add_predecessor_ref(jit, label, jit->b, ir_END()); |
7366 | 0 | jit->b = -1; |
7367 | 0 | } |
7368 | 0 | return 1; |
7369 | 0 | } else if (always_false) { |
7370 | 0 | if (opline->opcode != ZEND_CASE_STRICT) { |
7371 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
7372 | 0 | } |
7373 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, opline); |
7374 | 0 | if (!smart_branch_opcode |
7375 | 0 | || smart_branch_opcode == ZEND_JMPZ_EX |
7376 | 0 | || smart_branch_opcode == ZEND_JMPNZ_EX) { |
7377 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, opline->opcode != ZEND_IS_NOT_IDENTICAL ? IS_FALSE : IS_TRUE); |
7378 | 0 | } |
7379 | 0 | if (may_throw) { |
7380 | 0 | zend_jit_check_exception(jit); |
7381 | 0 | } |
7382 | 0 | if (exit_addr) { |
7383 | 0 | if (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) { |
7384 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
7385 | 0 | } |
7386 | 0 | } else if (smart_branch_opcode) { |
7387 | 0 | uint32_t label; |
7388 | |
|
7389 | 0 | if (opline->opcode == ZEND_IS_NOT_IDENTICAL) { |
7390 | 0 | label = (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? |
7391 | 0 | target_label2 : target_label; |
7392 | 0 | } else { |
7393 | 0 | label = (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? |
7394 | 0 | target_label : target_label2; |
7395 | 0 | } |
7396 | 0 | _zend_jit_add_predecessor_ref(jit, label, jit->b, ir_END()); |
7397 | 0 | jit->b = -1; |
7398 | 0 | } |
7399 | 0 | return 1; |
7400 | 0 | } |
7401 | | |
7402 | 0 | if ((opline->op1_type & (IS_CV|IS_VAR)) && (op1_info & MAY_BE_REF)) { |
7403 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
7404 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
7405 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
7406 | 0 | } |
7407 | 0 | if ((opline->op2_type & (IS_CV|IS_VAR)) && (op2_info & MAY_BE_REF)) { |
7408 | 0 | ref = jit_ZVAL_ADDR(jit, op2_addr); |
7409 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
7410 | 0 | op2_addr = ZEND_ADDR_REF_ZVAL(ref); |
7411 | 0 | } |
7412 | |
|
7413 | 0 | if ((op1_info & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_LONG && |
7414 | 0 | (op2_info & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_LONG) { |
7415 | 0 | ref = zend_jit_cmp_long_long(jit, opline, op1_range, op1_addr, op2_range, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr, skip_comparison); |
7416 | 0 | if (!ref) { |
7417 | 0 | return 0; |
7418 | 0 | } |
7419 | 0 | } else if ((op1_info & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_DOUBLE && |
7420 | 0 | (op2_info & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_DOUBLE) { |
7421 | 0 | ref = zend_jit_cmp_double_double(jit, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr); |
7422 | 0 | if (!ref) { |
7423 | 0 | return 0; |
7424 | 0 | } |
7425 | 0 | } else { |
7426 | 0 | if (opline->op1_type != IS_CONST) { |
7427 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
7428 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op1.var); |
7429 | 0 | if (!zend_jit_spill_store_inv(jit, op1_addr, real_addr, op1_info)) { |
7430 | 0 | return 0; |
7431 | 0 | } |
7432 | 0 | op1_addr = real_addr; |
7433 | 0 | } |
7434 | 0 | } |
7435 | 0 | if (opline->op2_type != IS_CONST) { |
7436 | 0 | if (Z_MODE(op2_addr) == IS_REG) { |
7437 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op2.var); |
7438 | 0 | if (!zend_jit_spill_store_inv(jit, op2_addr, real_addr, op2_info)) { |
7439 | 0 | return 0; |
7440 | 0 | } |
7441 | 0 | } |
7442 | 0 | } |
7443 | | |
7444 | 0 | if (Z_MODE(op1_addr) == IS_CONST_ZVAL && Z_TYPE_P(Z_ZV(op1_addr)) <= IS_TRUE) { |
7445 | 0 | zval *val = Z_ZV(op1_addr); |
7446 | |
|
7447 | 0 | ref = ir_EQ(jit_Z_TYPE(jit, op2_addr), ir_CONST_U8(Z_TYPE_P(val))); |
7448 | 0 | } else if (Z_MODE(op2_addr) == IS_CONST_ZVAL && Z_TYPE_P(Z_ZV(op2_addr)) <= IS_TRUE) { |
7449 | 0 | zval *val = Z_ZV(op2_addr); |
7450 | |
|
7451 | 0 | ref = ir_EQ(jit_Z_TYPE(jit, op1_addr), ir_CONST_U8(Z_TYPE_P(val))); |
7452 | 0 | } else { |
7453 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
7454 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op1.var); |
7455 | 0 | if (!zend_jit_spill_store_inv(jit, op1_addr, real_addr, op1_info)) { |
7456 | 0 | return 0; |
7457 | 0 | } |
7458 | 0 | op1_addr = real_addr; |
7459 | 0 | } |
7460 | 0 | if (Z_MODE(op2_addr) == IS_REG) { |
7461 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op2.var); |
7462 | 0 | if (!zend_jit_spill_store_inv(jit, op2_addr, real_addr, op2_info)) { |
7463 | 0 | return 0; |
7464 | 0 | } |
7465 | 0 | op2_addr = real_addr; |
7466 | 0 | } |
7467 | 0 | if (may_throw) { |
7468 | 0 | jit_SET_EX_OPLINE(jit, opline); |
7469 | 0 | } |
7470 | |
|
7471 | 0 | ref = ir_CALL_2(IR_BOOL, ir_CONST_FC_FUNC(zend_is_identical), |
7472 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
7473 | 0 | jit_ZVAL_ADDR(jit, op2_addr)); |
7474 | 0 | } |
7475 | | |
7476 | 0 | if (!smart_branch_opcode || smart_branch_opcode == ZEND_JMPNZ_EX || smart_branch_opcode == ZEND_JMPZ_EX) { |
7477 | 0 | if (opline->opcode == ZEND_IS_NOT_IDENTICAL) { |
7478 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7479 | 0 | ir_SUB_U32(ir_CONST_U32(IS_TRUE), ir_ZEXT_U32(ref))); |
7480 | 0 | } else { |
7481 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7482 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
7483 | 0 | } |
7484 | 0 | } |
7485 | 0 | if (opline->opcode != ZEND_CASE_STRICT) { |
7486 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL); |
7487 | 0 | } |
7488 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, NULL); |
7489 | 0 | if (may_throw) { |
7490 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
7491 | 0 | } |
7492 | 0 | if (exit_addr) { |
7493 | 0 | if (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) { |
7494 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
7495 | 0 | } else { |
7496 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
7497 | 0 | } |
7498 | 0 | } else if (smart_branch_opcode) { |
7499 | 0 | if (opline->opcode == ZEND_IS_NOT_IDENTICAL) { |
7500 | | /* swap labels */ |
7501 | 0 | uint32_t tmp = target_label; |
7502 | 0 | target_label = target_label2; |
7503 | 0 | target_label2 = tmp; |
7504 | 0 | } |
7505 | 0 | ref = jit_IF_ex(jit, ref, |
7506 | 0 | (smart_branch_opcode == ZEND_JMPZ || smart_branch_opcode == ZEND_JMPZ_EX) ? target_label2 : target_label); |
7507 | 0 | } |
7508 | 0 | } |
7509 | | |
7510 | 0 | if (smart_branch_opcode && !exit_addr) { |
7511 | 0 | zend_basic_block *bb; |
7512 | |
|
7513 | 0 | ZEND_ASSERT(jit->b >= 0); |
7514 | 0 | bb = &jit->ssa->cfg.blocks[jit->b]; |
7515 | 0 | ZEND_ASSERT(bb->successors_count == 2); |
7516 | |
|
7517 | 0 | if (bb->successors_count == 2 && bb->successors[0] == bb->successors[1]) { |
7518 | 0 | ir_IF_TRUE(ref); |
7519 | 0 | ir_MERGE_WITH_EMPTY_FALSE(ref); |
7520 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ir_END()); |
7521 | 0 | } else { |
7522 | 0 | ZEND_ASSERT(bb->successors_count == 2); |
7523 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ref); |
7524 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[1], jit->b, ref); |
7525 | 0 | } |
7526 | 0 | jit->b = -1; |
7527 | 0 | } |
7528 | |
|
7529 | 0 | return 1; |
7530 | 0 | } |
7531 | | |
7532 | | static int zend_jit_bool_jmpznz(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, zend_jit_addr res_addr, uint32_t target_label, uint32_t target_label2, int may_throw, uint8_t branch_opcode, const void *exit_addr) |
7533 | 0 | { |
7534 | 0 | uint32_t true_label = -1; |
7535 | 0 | uint32_t false_label = -1; |
7536 | 0 | bool set_bool = false; |
7537 | 0 | bool set_bool_not = false; |
7538 | 0 | bool always_true = false, always_false = false; |
7539 | 0 | ir_ref ref, end_inputs = IR_UNUSED, true_inputs = IR_UNUSED, false_inputs = IR_UNUSED; |
7540 | 0 | ir_type type = IR_UNUSED; |
7541 | |
|
7542 | 0 | if (branch_opcode == ZEND_BOOL) { |
7543 | 0 | set_bool = true; |
7544 | 0 | } else if (branch_opcode == ZEND_BOOL_NOT) { |
7545 | 0 | set_bool = true; |
7546 | 0 | set_bool_not = true; |
7547 | 0 | } else if (branch_opcode == ZEND_JMPZ) { |
7548 | 0 | true_label = target_label2; |
7549 | 0 | false_label = target_label; |
7550 | 0 | } else if (branch_opcode == ZEND_JMPNZ) { |
7551 | 0 | true_label = target_label; |
7552 | 0 | false_label = target_label2; |
7553 | 0 | } else if (branch_opcode == ZEND_JMPZ_EX) { |
7554 | 0 | set_bool = true; |
7555 | 0 | true_label = target_label2; |
7556 | 0 | false_label = target_label; |
7557 | 0 | } else if (branch_opcode == ZEND_JMPNZ_EX) { |
7558 | 0 | set_bool = true; |
7559 | 0 | true_label = target_label; |
7560 | 0 | false_label = target_label2; |
7561 | 0 | } else { |
7562 | 0 | ZEND_UNREACHABLE(); |
7563 | 0 | } |
7564 | | |
7565 | 0 | if (opline->op1_type == IS_CV && (op1_info & MAY_BE_REF)) { |
7566 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
7567 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
7568 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
7569 | 0 | } |
7570 | |
|
7571 | 0 | if (Z_MODE(op1_addr) == IS_CONST_ZVAL |
7572 | | /* NAN Value must cause a warning to be emitted */ |
7573 | 0 | && (Z_TYPE_P(Z_ZV(op1_addr)) != IS_DOUBLE || !zend_isnan(Z_DVAL_P(Z_ZV(op1_addr))))) { |
7574 | 0 | if (zend_is_true(Z_ZV(op1_addr))) { |
7575 | 0 | always_true = true; |
7576 | 0 | } else { |
7577 | 0 | always_false = true; |
7578 | 0 | } |
7579 | 0 | } else if (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE)) { |
7580 | 0 | if (!(op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY)-MAY_BE_TRUE))) { |
7581 | 0 | always_true = true; |
7582 | 0 | } else if (!(op1_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_FALSE)))) { |
7583 | 0 | if (opline->op1_type == IS_CV && (op1_info & MAY_BE_UNDEF)) { |
7584 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
7585 | 0 | zend_jit_zval_check_undef(jit, ref, opline->op1.var, opline, false); |
7586 | 0 | } |
7587 | 0 | always_false = true; |
7588 | 0 | } |
7589 | 0 | } |
7590 | |
|
7591 | 0 | if (always_true) { |
7592 | 0 | if (set_bool) { |
7593 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_FALSE : IS_TRUE); |
7594 | 0 | } |
7595 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
7596 | 0 | if (may_throw) { |
7597 | 0 | zend_jit_check_exception(jit); |
7598 | 0 | } |
7599 | 0 | if (true_label != (uint32_t)-1) { |
7600 | 0 | ZEND_ASSERT(exit_addr == NULL); |
7601 | 0 | _zend_jit_add_predecessor_ref(jit, true_label, jit->b, ir_END()); |
7602 | 0 | jit->b = -1; |
7603 | 0 | } |
7604 | 0 | return 1; |
7605 | 0 | } else if (always_false) { |
7606 | 0 | if (set_bool) { |
7607 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_TRUE : IS_FALSE); |
7608 | 0 | } |
7609 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
7610 | 0 | if (may_throw) { |
7611 | 0 | zend_jit_check_exception(jit); |
7612 | 0 | } |
7613 | 0 | if (false_label != (uint32_t)-1) { |
7614 | 0 | ZEND_ASSERT(exit_addr == NULL); |
7615 | 0 | _zend_jit_add_predecessor_ref(jit, false_label, jit->b, ir_END()); |
7616 | 0 | jit->b = -1; |
7617 | 0 | } |
7618 | 0 | return 1; |
7619 | 0 | } |
7620 | | |
7621 | 0 | if (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE)) { |
7622 | 0 | type = jit_Z_TYPE(jit, op1_addr); |
7623 | 0 | if (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) { |
7624 | 0 | ir_ref if_type = ir_IF(ir_LT(type, ir_CONST_U8(IS_TRUE))); |
7625 | |
|
7626 | 0 | ir_IF_TRUE_cold(if_type); |
7627 | |
|
7628 | 0 | if (op1_info & MAY_BE_UNDEF) { |
7629 | 0 | zend_jit_type_check_undef(jit, |
7630 | 0 | type, |
7631 | 0 | opline->op1.var, |
7632 | 0 | opline, true, false, true); |
7633 | 0 | } |
7634 | 0 | if (set_bool) { |
7635 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_TRUE : IS_FALSE); |
7636 | 0 | } |
7637 | 0 | if (exit_addr) { |
7638 | 0 | if (branch_opcode == ZEND_JMPNZ || branch_opcode == ZEND_JMPNZ_EX) { |
7639 | 0 | ir_END_list(end_inputs); |
7640 | 0 | } else { |
7641 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
7642 | 0 | } |
7643 | 0 | } else if (false_label != (uint32_t)-1) { |
7644 | 0 | ir_END_list(false_inputs); |
7645 | 0 | } else { |
7646 | 0 | ir_END_list(end_inputs); |
7647 | 0 | } |
7648 | 0 | ir_IF_FALSE(if_type); |
7649 | 0 | } |
7650 | |
|
7651 | 0 | if (op1_info & MAY_BE_TRUE) { |
7652 | 0 | ir_ref if_type = IR_UNUSED; |
7653 | |
|
7654 | 0 | if (op1_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE))) { |
7655 | 0 | if_type = ir_IF(ir_EQ(type, ir_CONST_U8(IS_TRUE))); |
7656 | |
|
7657 | 0 | ir_IF_TRUE(if_type); |
7658 | 0 | } |
7659 | 0 | if (set_bool) { |
7660 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_FALSE : IS_TRUE); |
7661 | 0 | } |
7662 | 0 | if (exit_addr) { |
7663 | 0 | if (branch_opcode == ZEND_JMPZ || branch_opcode == ZEND_JMPZ_EX) { |
7664 | 0 | ir_END_list(end_inputs); |
7665 | 0 | } else { |
7666 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
7667 | 0 | } |
7668 | 0 | } else if (true_label != (uint32_t)-1) { |
7669 | 0 | ir_END_list(true_inputs); |
7670 | 0 | } else { |
7671 | 0 | ir_END_list(end_inputs); |
7672 | 0 | } |
7673 | 0 | if (if_type) { |
7674 | 0 | ir_IF_FALSE(if_type); |
7675 | 0 | } |
7676 | 0 | } |
7677 | 0 | } |
7678 | |
|
7679 | 0 | if (op1_info & MAY_BE_LONG) { |
7680 | 0 | ir_ref if_long = IR_UNUSED; |
7681 | 0 | ir_ref ref; |
7682 | |
|
7683 | 0 | if (op1_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG))) { |
7684 | 0 | if (!type) { |
7685 | 0 | type = jit_Z_TYPE(jit, op1_addr); |
7686 | 0 | } |
7687 | 0 | if_long = ir_IF(ir_EQ(type, ir_CONST_U8(IS_LONG))); |
7688 | 0 | ir_IF_TRUE(if_long); |
7689 | 0 | } |
7690 | 0 | ref = jit_Z_LVAL(jit, op1_addr); |
7691 | 0 | if (branch_opcode == ZEND_BOOL || branch_opcode == ZEND_BOOL_NOT) { |
7692 | 0 | ref = ir_NE(ref, ir_CONST_LONG(0)); |
7693 | 0 | if (set_bool_not) { |
7694 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7695 | 0 | ir_SUB_U32(ir_CONST_U32(IS_TRUE), ir_ZEXT_U32(ref))); |
7696 | 0 | } else { |
7697 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7698 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
7699 | 0 | } |
7700 | 0 | ir_END_list(end_inputs); |
7701 | 0 | } else if (exit_addr) { |
7702 | 0 | if (set_bool) { |
7703 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7704 | 0 | ir_ADD_U32(ir_ZEXT_U32(ir_NE(ref, ir_CONST_LONG(0))), ir_CONST_U32(IS_FALSE))); |
7705 | 0 | } |
7706 | 0 | if (branch_opcode == ZEND_JMPZ || branch_opcode == ZEND_JMPZ_EX) { |
7707 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
7708 | 0 | } else { |
7709 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
7710 | 0 | } |
7711 | 0 | ir_END_list(end_inputs); |
7712 | 0 | } else { |
7713 | 0 | ir_ref if_val = ir_IF(ref); |
7714 | 0 | ir_IF_TRUE(if_val); |
7715 | 0 | if (set_bool) { |
7716 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_FALSE : IS_TRUE); |
7717 | 0 | } |
7718 | 0 | ir_END_list(true_inputs); |
7719 | 0 | ir_IF_FALSE(if_val); |
7720 | 0 | if (set_bool) { |
7721 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_TRUE : IS_FALSE); |
7722 | 0 | } |
7723 | 0 | ir_END_list(false_inputs); |
7724 | 0 | } |
7725 | 0 | if (if_long) { |
7726 | 0 | ir_IF_FALSE(if_long); |
7727 | 0 | } |
7728 | 0 | } |
7729 | |
|
7730 | 0 | if (op1_info & MAY_BE_DOUBLE) { |
7731 | 0 | ir_ref if_double = IR_UNUSED; |
7732 | 0 | ir_ref ref; |
7733 | |
|
7734 | 0 | if (op1_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE))) { |
7735 | 0 | if (!type) { |
7736 | 0 | type = jit_Z_TYPE(jit, op1_addr); |
7737 | 0 | } |
7738 | 0 | if_double = ir_IF(ir_EQ(type, ir_CONST_U8(IS_DOUBLE))); |
7739 | 0 | ir_IF_TRUE(if_double); |
7740 | 0 | } |
7741 | |
|
7742 | 0 | ir_ref dval = jit_Z_DVAL(jit, op1_addr); |
7743 | 0 | ir_ref is_nan = ir_NE(dval, dval); |
7744 | 0 | ir_ref if_val = ir_IF(is_nan); |
7745 | 0 | ir_IF_TRUE_cold(if_val); |
7746 | 0 | jit_SET_EX_OPLINE(jit, opline); |
7747 | 0 | ir_CALL(IR_VOID, ir_CONST_FC_FUNC(zend_jit_nan_coerced_to_type_warning)); |
7748 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_val); |
7749 | |
|
7750 | 0 | ref = ir_NE(dval, ir_CONST_DOUBLE(0.0)); |
7751 | 0 | if (branch_opcode == ZEND_BOOL || branch_opcode == ZEND_BOOL_NOT) { |
7752 | 0 | if (set_bool_not) { |
7753 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7754 | 0 | ir_SUB_U32(ir_CONST_U32(IS_TRUE), ir_ZEXT_U32(ref))); |
7755 | 0 | } else { |
7756 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7757 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
7758 | 0 | } |
7759 | 0 | ir_END_list(end_inputs); |
7760 | 0 | } else if (exit_addr) { |
7761 | 0 | if (set_bool) { |
7762 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7763 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
7764 | 0 | } |
7765 | 0 | if (branch_opcode == ZEND_JMPZ || branch_opcode == ZEND_JMPZ_EX) { |
7766 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
7767 | 0 | } else { |
7768 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
7769 | 0 | } |
7770 | 0 | ir_END_list(end_inputs); |
7771 | 0 | } else { |
7772 | 0 | ir_ref if_val = ir_IF(ref); |
7773 | 0 | ir_IF_TRUE(if_val); |
7774 | 0 | if (set_bool) { |
7775 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_FALSE : IS_TRUE); |
7776 | 0 | } |
7777 | 0 | ir_END_list(true_inputs); |
7778 | 0 | ir_IF_FALSE(if_val); |
7779 | 0 | if (set_bool) { |
7780 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_TRUE : IS_FALSE); |
7781 | 0 | } |
7782 | 0 | ir_END_list(false_inputs); |
7783 | 0 | } |
7784 | 0 | if (if_double) { |
7785 | 0 | ir_IF_FALSE(if_double); |
7786 | 0 | } |
7787 | 0 | } |
7788 | |
|
7789 | 0 | if (op1_info & (MAY_BE_ANY - (MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE))) { |
7790 | 0 | jit_SET_EX_OPLINE(jit, opline); |
7791 | 0 | ref = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_is_true), jit_ZVAL_ADDR(jit, op1_addr)); |
7792 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL); |
7793 | 0 | if (may_throw) { |
7794 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
7795 | 0 | } |
7796 | 0 | if (branch_opcode == ZEND_BOOL || branch_opcode == ZEND_BOOL_NOT) { |
7797 | 0 | if (set_bool_not) { |
7798 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7799 | 0 | ir_SUB_U32(ir_CONST_U32(IS_TRUE), ir_ZEXT_U32(ref))); |
7800 | 0 | } else { |
7801 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7802 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
7803 | 0 | } |
7804 | 0 | if (end_inputs) { |
7805 | 0 | ir_END_list(end_inputs); |
7806 | 0 | } |
7807 | 0 | } else if (exit_addr) { |
7808 | 0 | if (set_bool) { |
7809 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7810 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
7811 | 0 | } |
7812 | 0 | if (branch_opcode == ZEND_JMPZ || branch_opcode == ZEND_JMPZ_EX) { |
7813 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
7814 | 0 | } else { |
7815 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
7816 | 0 | } |
7817 | 0 | if (end_inputs) { |
7818 | 0 | ir_END_list(end_inputs); |
7819 | 0 | } |
7820 | 0 | } else { |
7821 | 0 | ir_ref if_val = ir_IF(ref); |
7822 | 0 | ir_IF_TRUE(if_val); |
7823 | 0 | if (set_bool) { |
7824 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_FALSE : IS_TRUE); |
7825 | 0 | } |
7826 | 0 | ir_END_list(true_inputs); |
7827 | 0 | ir_IF_FALSE(if_val); |
7828 | 0 | if (set_bool) { |
7829 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, set_bool_not ? IS_TRUE : IS_FALSE); |
7830 | 0 | } |
7831 | 0 | ir_END_list(false_inputs); |
7832 | 0 | } |
7833 | 0 | } |
7834 | |
|
7835 | 0 | if (branch_opcode == ZEND_BOOL || branch_opcode == ZEND_BOOL_NOT || exit_addr) { |
7836 | 0 | if (end_inputs) { |
7837 | 0 | ir_MERGE_list(end_inputs); |
7838 | 0 | } |
7839 | 0 | } else { |
7840 | 0 | _zend_jit_merge_smart_branch_inputs(jit, true_label, false_label, true_inputs, false_inputs); |
7841 | 0 | } |
7842 | |
|
7843 | 0 | return 1; |
7844 | 0 | } |
7845 | | |
7846 | | static int zend_jit_defined(zend_jit_ctx *jit, const zend_op *opline, uint8_t smart_branch_opcode, uint32_t target_label, uint32_t target_label2, const void *exit_addr) |
7847 | 0 | { |
7848 | 0 | uint32_t defined_label = (uint32_t)-1; |
7849 | 0 | uint32_t undefined_label = (uint32_t)-1; |
7850 | 0 | zval *zv = RT_CONSTANT(opline, opline->op1); |
7851 | 0 | zend_jit_addr res_addr = 0; |
7852 | 0 | ir_ref ref, ref2, if_set, if_zero, if_set2; |
7853 | 0 | ir_ref end_inputs = IR_UNUSED, true_inputs = IR_UNUSED, false_inputs = IR_UNUSED; |
7854 | |
|
7855 | 0 | if (smart_branch_opcode && !exit_addr) { |
7856 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
7857 | 0 | defined_label = target_label2; |
7858 | 0 | undefined_label = target_label; |
7859 | 0 | } else if (smart_branch_opcode == ZEND_JMPNZ) { |
7860 | 0 | defined_label = target_label; |
7861 | 0 | undefined_label = target_label2; |
7862 | 0 | } else { |
7863 | 0 | ZEND_UNREACHABLE(); |
7864 | 0 | } |
7865 | 0 | } else { |
7866 | 0 | res_addr = RES_ADDR(); |
7867 | 0 | } |
7868 | | |
7869 | | // if (CACHED_PTR(opline->extended_value)) { |
7870 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->extended_value)); |
7871 | |
|
7872 | 0 | if_set = ir_IF(ref); |
7873 | |
|
7874 | 0 | ir_IF_FALSE_cold(if_set); |
7875 | 0 | if_zero = ir_END(); |
7876 | |
|
7877 | 0 | ir_IF_TRUE(if_set); |
7878 | 0 | if_set2 = ir_IF(ir_AND_A(ref, ir_CONST_ADDR(CACHE_SPECIAL))); |
7879 | 0 | ir_IF_FALSE(if_set2); |
7880 | |
|
7881 | 0 | if (exit_addr) { |
7882 | 0 | if (smart_branch_opcode == ZEND_JMPNZ) { |
7883 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
7884 | 0 | } else { |
7885 | 0 | ir_END_list(end_inputs); |
7886 | 0 | } |
7887 | 0 | } else if (smart_branch_opcode) { |
7888 | 0 | ir_END_list(true_inputs); |
7889 | 0 | } else { |
7890 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_TRUE); |
7891 | 0 | ir_END_list(end_inputs); |
7892 | 0 | } |
7893 | |
|
7894 | 0 | ir_IF_TRUE_cold(if_set2); |
7895 | |
|
7896 | 0 | ref2 = jit_EG(zend_constants); |
7897 | 0 | ref = ir_SHR_A(ref, ir_CONST_ADDR(1)); |
7898 | 0 | if (sizeof(void*) == 8) { |
7899 | 0 | ref = ir_TRUNC_U32(ref); |
7900 | 0 | } |
7901 | 0 | ref2 = ir_EQ(ref, ir_LOAD_U32(ir_ADD_OFFSET(ir_LOAD_A(ref2), offsetof(HashTable, nNumOfElements)))); |
7902 | 0 | ref2 = ir_IF(ref2); |
7903 | 0 | ir_IF_TRUE(ref2); |
7904 | |
|
7905 | 0 | if (exit_addr) { |
7906 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
7907 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
7908 | 0 | } else { |
7909 | 0 | ir_END_list(end_inputs); |
7910 | 0 | } |
7911 | 0 | } else if (smart_branch_opcode) { |
7912 | 0 | ir_END_list(false_inputs); |
7913 | 0 | } else { |
7914 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_FALSE); |
7915 | 0 | ir_END_list(end_inputs); |
7916 | 0 | } |
7917 | |
|
7918 | 0 | ir_IF_FALSE(ref2); |
7919 | 0 | ir_MERGE_2(if_zero, ir_END()); |
7920 | |
|
7921 | 0 | jit_SET_EX_OPLINE(jit, opline); |
7922 | 0 | ref2 = ir_NE(ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_check_constant), ir_CONST_ADDR(zv)), IR_NULL); |
7923 | 0 | if (exit_addr) { |
7924 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
7925 | 0 | ir_GUARD(ref2, ir_CONST_ADDR(exit_addr)); |
7926 | 0 | } else { |
7927 | 0 | ir_GUARD_NOT(ref2, ir_CONST_ADDR(exit_addr)); |
7928 | 0 | } |
7929 | 0 | ir_END_list(end_inputs); |
7930 | 0 | } else if (smart_branch_opcode) { |
7931 | 0 | ref2 = ir_IF(ref2); |
7932 | 0 | ir_IF_TRUE(ref2); |
7933 | 0 | ir_END_list(true_inputs); |
7934 | 0 | ir_IF_FALSE(ref2); |
7935 | 0 | ir_END_list(false_inputs); |
7936 | 0 | } else { |
7937 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
7938 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref2), ir_CONST_U32(IS_FALSE))); |
7939 | 0 | ir_END_list(end_inputs); |
7940 | 0 | } |
7941 | |
|
7942 | 0 | if (!smart_branch_opcode || exit_addr) { |
7943 | 0 | if (end_inputs) { |
7944 | 0 | ir_MERGE_list(end_inputs); |
7945 | 0 | } |
7946 | 0 | } else { |
7947 | 0 | _zend_jit_merge_smart_branch_inputs(jit, defined_label, undefined_label, true_inputs, false_inputs); |
7948 | 0 | } |
7949 | |
|
7950 | 0 | return 1; |
7951 | 0 | } |
7952 | | |
7953 | | static int zend_jit_escape_if_undef(zend_jit_ctx *jit, int var, uint32_t flags, const zend_op *opline, const zend_op_array *op_array, int8_t reg) |
7954 | 0 | { |
7955 | 0 | zend_jit_addr reg_addr = ZEND_ADDR_REF_ZVAL(zend_jit_deopt_rload(jit, IR_ADDR, reg)); |
7956 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE(jit, reg_addr)); |
7957 | |
|
7958 | 0 | ir_IF_FALSE_cold(if_def); |
7959 | |
|
7960 | 0 | if (flags & ZEND_JIT_EXIT_RESTORE_CALL) { |
7961 | 0 | if (!zend_jit_save_call_chain(jit, -1)) { |
7962 | 0 | return 0; |
7963 | 0 | } |
7964 | 0 | } |
7965 | | |
7966 | 0 | if ((opline-1)->opcode != ZEND_FETCH_CONSTANT |
7967 | 0 | && (opline-1)->opcode != ZEND_FETCH_LIST_R |
7968 | 0 | && ((opline-1)->op1_type & (IS_VAR|IS_TMP_VAR)) |
7969 | 0 | && !(flags & ZEND_JIT_EXIT_FREE_OP1)) { |
7970 | 0 | zend_jit_addr val_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, (opline-1)->op1.var); |
7971 | |
|
7972 | 0 | zend_jit_zval_try_addref(jit, val_addr); |
7973 | 0 | } |
7974 | |
|
7975 | 0 | jit_LOAD_IP_ADDR(jit, opline - 1); |
7976 | | |
7977 | | /* We can't use trace_escape() because opcode handler may be overridden by JIT */ |
7978 | 0 | zend_jit_op_array_trace_extension *jit_extension = |
7979 | 0 | (zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array); |
7980 | 0 | size_t offset = jit_extension->offset; |
7981 | 0 | ir_ref ref = ir_CONST_ADDR(ZEND_OP_TRACE_INFO((opline - 1), offset)->orig_handler); |
7982 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
7983 | 0 | ir_TAILCALL(IR_OPCODE_HANDLER_RET, ref); |
7984 | 0 | } else { |
7985 | | #if defined(IR_TARGET_X86) |
7986 | | ref = ir_CAST_FC_FUNC(ref); |
7987 | | #endif |
7988 | 0 | ir_TAILCALL_2(IR_ADDR, ref, jit_FP(jit), jit_IP(jit)); |
7989 | 0 | } |
7990 | |
|
7991 | 0 | ir_IF_TRUE(if_def); |
7992 | |
|
7993 | 0 | return 1; |
7994 | 0 | } |
7995 | | |
7996 | | static int zend_jit_restore_zval(zend_jit_ctx *jit, int var, int8_t reg) |
7997 | 0 | { |
7998 | 0 | zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var); |
7999 | 0 | zend_jit_addr reg_addr = ZEND_ADDR_REF_ZVAL(zend_jit_deopt_rload(jit, IR_ADDR, reg)); |
8000 | | |
8001 | | // JIT: ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value); (no dup) |
8002 | 0 | jit_ZVAL_COPY(jit, var_addr, MAY_BE_ANY, reg_addr, MAY_BE_ANY, true); |
8003 | 0 | return 1; |
8004 | 0 | } |
8005 | | |
8006 | | static zend_jit_addr zend_jit_guard_fetch_result_type(zend_jit_ctx *jit, |
8007 | | const zend_op *opline, |
8008 | | zend_jit_addr val_addr, |
8009 | | uint8_t type, |
8010 | | bool deref, |
8011 | | uint32_t flags, |
8012 | | bool op1_avoid_refcounting) |
8013 | 0 | { |
8014 | 0 | zend_jit_trace_stack *stack = JIT_G(current_frame)->stack; |
8015 | 0 | int32_t exit_point; |
8016 | 0 | const void *res_exit_addr = NULL; |
8017 | 0 | ir_ref end1 = IR_UNUSED, ref1 = IR_UNUSED; |
8018 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, val_addr); |
8019 | 0 | uint32_t old_op1_info = 0; |
8020 | 0 | uint32_t old_info; |
8021 | 0 | ir_ref old_ref; |
8022 | | |
8023 | |
|
8024 | 0 | if (opline->op1_type & (IS_VAR|IS_TMP_VAR|IS_CV)) { |
8025 | 0 | old_op1_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var)); |
8026 | 0 | if (op1_avoid_refcounting |
8027 | 0 | || ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) |
8028 | 0 | && STACK_FLAGS(stack, EX_VAR_TO_NUM(opline->op1.var)) & (ZREG_ZVAL_ADDREF|ZREG_THIS))) { |
8029 | 0 | SET_STACK_REG(stack, EX_VAR_TO_NUM(opline->op1.var), ZREG_NONE); |
8030 | 0 | } |
8031 | 0 | } |
8032 | 0 | old_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var)); |
8033 | 0 | old_ref = STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var)); |
8034 | 0 | CLEAR_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var)); |
8035 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_UNKNOWN, 1); |
8036 | |
|
8037 | 0 | if (deref) { |
8038 | 0 | ir_ref if_type; |
8039 | |
|
8040 | 0 | if (type == IS_NULL && (opline->opcode == ZEND_FETCH_DIM_IS || opline->opcode == ZEND_FETCH_OBJ_IS)) { |
8041 | 0 | if_type = ir_IF(ir_ULE(jit_Z_TYPE(jit, val_addr), ir_CONST_U8(type))); |
8042 | 0 | } else { |
8043 | 0 | if_type = jit_if_Z_TYPE(jit, val_addr, type); |
8044 | 0 | } |
8045 | 0 | ir_IF_TRUE(if_type); |
8046 | 0 | end1 = ir_END(); |
8047 | 0 | ref1 = ref; |
8048 | 0 | ir_IF_FALSE_cold(if_type); |
8049 | |
|
8050 | 0 | SET_STACK_REF_EX(stack, EX_VAR_TO_NUM(opline->result.var), ref, ZREG_ZVAL_COPY); |
8051 | 0 | exit_point = zend_jit_trace_get_exit_point(opline+1, flags); |
8052 | 0 | res_exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
8053 | 0 | if (!res_exit_addr) { |
8054 | 0 | return 0; |
8055 | 0 | } |
8056 | | |
8057 | 0 | jit_guard_Z_TYPE(jit, val_addr, IS_REFERENCE, res_exit_addr); |
8058 | 0 | ref = ir_ADD_OFFSET(jit_Z_PTR(jit, val_addr), offsetof(zend_reference, val)); |
8059 | 0 | val_addr = ZEND_ADDR_REF_ZVAL(ref); |
8060 | 0 | } |
8061 | | |
8062 | 0 | SET_STACK_REF_EX(stack, EX_VAR_TO_NUM(opline->result.var), ref, ZREG_ZVAL_COPY); |
8063 | 0 | exit_point = zend_jit_trace_get_exit_point(opline+1, flags); |
8064 | 0 | res_exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
8065 | 0 | if (!res_exit_addr) { |
8066 | 0 | return 0; |
8067 | 0 | } |
8068 | | |
8069 | 0 | if (!deref && type == IS_NULL && (opline->opcode == ZEND_FETCH_DIM_IS || opline->opcode == ZEND_FETCH_OBJ_IS)) { |
8070 | 0 | ir_GUARD(ir_ULE(jit_Z_TYPE(jit, val_addr), ir_CONST_U8(type)), ir_CONST_ADDR(res_exit_addr)); |
8071 | 0 | } else { |
8072 | 0 | jit_guard_Z_TYPE(jit, val_addr, type, res_exit_addr); |
8073 | 0 | } |
8074 | |
|
8075 | 0 | if (deref) { |
8076 | 0 | ir_MERGE_WITH(end1); |
8077 | 0 | ref = ir_PHI_2(IR_ADDR, ref, ref1); |
8078 | 0 | } |
8079 | |
|
8080 | 0 | val_addr = ZEND_ADDR_REF_ZVAL(ref); |
8081 | |
|
8082 | 0 | SET_STACK_REF(stack, EX_VAR_TO_NUM(opline->result.var), old_ref); |
8083 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var), old_info); |
8084 | 0 | if (opline->op1_type & (IS_VAR|IS_TMP_VAR|IS_CV)) { |
8085 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var), old_op1_info); |
8086 | 0 | } |
8087 | |
|
8088 | 0 | return val_addr; |
8089 | 0 | } |
8090 | | |
8091 | | static int zend_jit_fetch_constant(zend_jit_ctx *jit, |
8092 | | const zend_op *opline, |
8093 | | const zend_op_array *op_array, |
8094 | | zend_ssa *ssa, |
8095 | | const zend_ssa_op *ssa_op, |
8096 | | zend_jit_addr res_addr) |
8097 | 0 | { |
8098 | 0 | zval *zv = RT_CONSTANT(opline, opline->op2) + 1; |
8099 | 0 | uint32_t res_info = RES_INFO(); |
8100 | 0 | ir_ref ref, ref2, if_set, if_special, not_set_path, special_path, fast_path; |
8101 | | |
8102 | | // JIT: c = CACHED_PTR(opline->extended_value); |
8103 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->extended_value)); |
8104 | | |
8105 | | // JIT: if (c != NULL) |
8106 | 0 | if_set = ir_IF(ref); |
8107 | |
|
8108 | 0 | if (!zend_jit_is_persistent_constant(zv, opline->op1.num)) { |
8109 | | // JIT: if (!IS_SPECIAL_CACHE_VAL(c)) |
8110 | 0 | ir_IF_FALSE_cold(if_set); |
8111 | 0 | not_set_path = ir_END(); |
8112 | 0 | ir_IF_TRUE(if_set); |
8113 | 0 | if_special = ir_IF(ir_AND_A(ref, ir_CONST_ADDR(CACHE_SPECIAL))); |
8114 | 0 | ir_IF_TRUE_cold(if_special); |
8115 | 0 | special_path = ir_END(); |
8116 | 0 | ir_IF_FALSE(if_special); |
8117 | 0 | fast_path = ir_END(); |
8118 | 0 | ir_MERGE_2(not_set_path, special_path); |
8119 | 0 | } else { |
8120 | 0 | ir_IF_TRUE(if_set); |
8121 | 0 | fast_path = ir_END(); |
8122 | 0 | ir_IF_FALSE_cold(if_set); |
8123 | 0 | } |
8124 | | |
8125 | | // JIT: zend_jit_get_constant(RT_CONSTANT(opline, opline->op2) + 1, opline->op1.num); |
8126 | 0 | jit_SET_EX_OPLINE(jit, opline); |
8127 | 0 | ref2 = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_get_constant), |
8128 | 0 | ir_CONST_ADDR(zv), |
8129 | 0 | ir_CONST_U32(opline->op1.num)); |
8130 | 0 | ir_GUARD(ref2, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
8131 | |
|
8132 | 0 | ir_MERGE_WITH(fast_path); |
8133 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
8134 | |
|
8135 | 0 | if ((res_info & MAY_BE_GUARD) && JIT_G(current_frame)) { |
8136 | 0 | uint8_t type = concrete_type(res_info); |
8137 | 0 | zend_jit_addr const_addr = ZEND_ADDR_REF_ZVAL(ref); |
8138 | |
|
8139 | 0 | const_addr = zend_jit_guard_fetch_result_type(jit, opline, const_addr, type, false, 0, false); |
8140 | 0 | if (!const_addr) { |
8141 | 0 | return 0; |
8142 | 0 | } |
8143 | | |
8144 | 0 | res_info &= ~MAY_BE_GUARD; |
8145 | 0 | ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD; |
8146 | | |
8147 | | // JIT: ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value); (no dup) |
8148 | 0 | jit_ZVAL_COPY(jit, res_addr, MAY_BE_ANY, const_addr, res_info, true); |
8149 | 0 | if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, res_info)) { |
8150 | 0 | return 0; |
8151 | 0 | } |
8152 | 0 | } else { |
8153 | 0 | ir_ref const_addr = ZEND_ADDR_REF_ZVAL(ref); |
8154 | | |
8155 | | // JIT: ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value); (no dup) |
8156 | 0 | jit_ZVAL_COPY(jit, res_addr, MAY_BE_ANY, const_addr, MAY_BE_ANY, true); |
8157 | 0 | } |
8158 | | |
8159 | | |
8160 | 0 | return 1; |
8161 | 0 | } |
8162 | | |
8163 | | static int zend_jit_type_check(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, uint8_t smart_branch_opcode, uint32_t target_label, uint32_t target_label2, const void *exit_addr) |
8164 | 0 | { |
8165 | 0 | uint32_t mask; |
8166 | 0 | zend_jit_addr op1_addr = OP1_ADDR(); |
8167 | 0 | zend_jit_addr res_addr = 0; |
8168 | 0 | uint32_t true_label = -1, false_label = -1; |
8169 | 0 | ir_ref end_inputs = IR_UNUSED, true_inputs = IR_UNUSED, false_inputs = IR_UNUSED; |
8170 | | |
8171 | | // TODO: support for is_resource() ??? |
8172 | 0 | ZEND_ASSERT(opline->extended_value != MAY_BE_RESOURCE); |
8173 | |
|
8174 | 0 | if (smart_branch_opcode && !exit_addr) { |
8175 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
8176 | 0 | true_label = target_label2; |
8177 | 0 | false_label = target_label; |
8178 | 0 | } else if (smart_branch_opcode == ZEND_JMPNZ) { |
8179 | 0 | true_label = target_label; |
8180 | 0 | false_label = target_label2; |
8181 | 0 | } else { |
8182 | 0 | ZEND_UNREACHABLE(); |
8183 | 0 | } |
8184 | 0 | } else { |
8185 | 0 | res_addr = RES_ADDR(); |
8186 | 0 | } |
8187 | | |
8188 | 0 | if (op1_info & MAY_BE_UNDEF) { |
8189 | 0 | ir_ref if_def = IR_UNUSED; |
8190 | |
|
8191 | 0 | if (op1_info & (MAY_BE_ANY|MAY_BE_REF)) { |
8192 | 0 | if_def = jit_if_not_Z_TYPE(jit, op1_addr, IS_UNDEF); |
8193 | 0 | ir_IF_FALSE_cold(if_def); |
8194 | 0 | } |
8195 | |
|
8196 | 0 | jit_SET_EX_OPLINE(jit, opline); |
8197 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op1.var)); |
8198 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
8199 | 0 | if (opline->extended_value & MAY_BE_NULL) { |
8200 | 0 | if (exit_addr) { |
8201 | 0 | if (smart_branch_opcode == ZEND_JMPNZ) { |
8202 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
8203 | 0 | } else { |
8204 | 0 | ir_END_list(end_inputs); |
8205 | 0 | } |
8206 | 0 | } else if (smart_branch_opcode) { |
8207 | 0 | ir_END_list(true_inputs); |
8208 | 0 | } else { |
8209 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_TRUE); |
8210 | 0 | ir_END_list(end_inputs); |
8211 | 0 | } |
8212 | 0 | } else { |
8213 | 0 | if (exit_addr) { |
8214 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
8215 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
8216 | 0 | } else { |
8217 | 0 | ir_END_list(end_inputs); |
8218 | 0 | } |
8219 | 0 | } else if (smart_branch_opcode) { |
8220 | 0 | ir_END_list(false_inputs); |
8221 | 0 | } else { |
8222 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_FALSE); |
8223 | 0 | if (if_def) { |
8224 | 0 | ir_END_list(end_inputs); |
8225 | 0 | } |
8226 | 0 | } |
8227 | 0 | } |
8228 | |
|
8229 | 0 | if (if_def) { |
8230 | 0 | ir_IF_TRUE(if_def); |
8231 | 0 | op1_info |= MAY_BE_NULL; |
8232 | 0 | } |
8233 | 0 | } |
8234 | |
|
8235 | 0 | if (op1_info & (MAY_BE_ANY|MAY_BE_REF)) { |
8236 | 0 | mask = opline->extended_value; |
8237 | 0 | if (!(op1_info & MAY_BE_GUARD) && !(op1_info & (MAY_BE_ANY - mask))) { |
8238 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
8239 | 0 | if (exit_addr) { |
8240 | 0 | if (smart_branch_opcode == ZEND_JMPNZ) { |
8241 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
8242 | 0 | } else if (end_inputs) { |
8243 | 0 | ir_END_list(end_inputs); |
8244 | 0 | } |
8245 | 0 | } else if (smart_branch_opcode) { |
8246 | 0 | ir_END_list(true_inputs); |
8247 | 0 | } else { |
8248 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_TRUE); |
8249 | 0 | ir_END_list(end_inputs); |
8250 | 0 | } |
8251 | 0 | } else if (!(op1_info & MAY_BE_GUARD) && !(op1_info & mask)) { |
8252 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
8253 | 0 | if (exit_addr) { |
8254 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
8255 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
8256 | 0 | } else if (end_inputs) { |
8257 | 0 | ir_END_list(end_inputs); |
8258 | 0 | } |
8259 | 0 | } else if (smart_branch_opcode) { |
8260 | 0 | ir_END_list(false_inputs); |
8261 | 0 | } else { |
8262 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_FALSE); |
8263 | 0 | ir_END_list(end_inputs); |
8264 | 0 | } |
8265 | 0 | } else { |
8266 | 0 | ir_ref ref; |
8267 | 0 | bool invert = false; |
8268 | 0 | uint8_t type; |
8269 | |
|
8270 | 0 | switch (mask) { |
8271 | 0 | case MAY_BE_NULL: type = IS_NULL; break; |
8272 | 0 | case MAY_BE_FALSE: type = IS_FALSE; break; |
8273 | 0 | case MAY_BE_TRUE: type = IS_TRUE; break; |
8274 | 0 | case MAY_BE_LONG: type = IS_LONG; break; |
8275 | 0 | case MAY_BE_DOUBLE: type = IS_DOUBLE; break; |
8276 | 0 | case MAY_BE_STRING: type = IS_STRING; break; |
8277 | 0 | case MAY_BE_ARRAY: type = IS_ARRAY; break; |
8278 | 0 | case MAY_BE_OBJECT: type = IS_OBJECT; break; |
8279 | 0 | case MAY_BE_ANY - MAY_BE_NULL: type = IS_NULL; invert = true; break; |
8280 | 0 | case MAY_BE_ANY - MAY_BE_FALSE: type = IS_FALSE; invert = true; break; |
8281 | 0 | case MAY_BE_ANY - MAY_BE_TRUE: type = IS_TRUE; invert = true; break; |
8282 | 0 | case MAY_BE_ANY - MAY_BE_LONG: type = IS_LONG; invert = true; break; |
8283 | 0 | case MAY_BE_ANY - MAY_BE_DOUBLE: type = IS_DOUBLE; invert = true; break; |
8284 | 0 | case MAY_BE_ANY - MAY_BE_STRING: type = IS_STRING; invert = true; break; |
8285 | 0 | case MAY_BE_ANY - MAY_BE_ARRAY: type = IS_ARRAY; invert = true; break; |
8286 | 0 | case MAY_BE_ANY - MAY_BE_OBJECT: type = IS_OBJECT; invert = true; break; |
8287 | 0 | case MAY_BE_ANY - MAY_BE_RESOURCE: type = IS_OBJECT; invert = true; break; |
8288 | 0 | default: |
8289 | 0 | type = 0; |
8290 | 0 | } |
8291 | | |
8292 | 0 | if (op1_info & MAY_BE_REF) { |
8293 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, op1_addr); |
8294 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
8295 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
8296 | 0 | } |
8297 | 0 | if (type == 0) { |
8298 | 0 | ref = ir_AND_U32(ir_SHL_U32(ir_CONST_U32(1), jit_Z_TYPE(jit, op1_addr)), ir_CONST_U32(mask)); |
8299 | 0 | if (!smart_branch_opcode) { |
8300 | 0 | ref = ir_NE(ref, ir_CONST_U32(0)); |
8301 | 0 | } |
8302 | 0 | } else if (invert) { |
8303 | 0 | ref = ir_NE(jit_Z_TYPE(jit, op1_addr), ir_CONST_U8(type)); |
8304 | 0 | } else { |
8305 | 0 | ref = ir_EQ(jit_Z_TYPE(jit, op1_addr), ir_CONST_U8(type)); |
8306 | 0 | } |
8307 | |
|
8308 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
8309 | |
|
8310 | 0 | if (exit_addr) { |
8311 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
8312 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
8313 | 0 | } else { |
8314 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
8315 | 0 | } |
8316 | 0 | if (end_inputs) { |
8317 | 0 | ir_END_list(end_inputs); |
8318 | 0 | } |
8319 | 0 | } else if (smart_branch_opcode) { |
8320 | 0 | ir_ref if_val = ir_IF(ref); |
8321 | 0 | ir_IF_TRUE(if_val); |
8322 | 0 | ir_END_list(true_inputs); |
8323 | 0 | ir_IF_FALSE(if_val); |
8324 | 0 | ir_END_list(false_inputs); |
8325 | 0 | } else { |
8326 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
8327 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
8328 | 0 | ir_END_list(end_inputs); |
8329 | 0 | } |
8330 | 0 | } |
8331 | 0 | } |
8332 | | |
8333 | 0 | if (!smart_branch_opcode || exit_addr) { |
8334 | 0 | if (end_inputs) { |
8335 | 0 | ir_MERGE_list(end_inputs); |
8336 | 0 | } else if (exit_addr && !jit->ctx.control) { |
8337 | 0 | ir_BEGIN(IR_UNUSED); /* unreachable block */ |
8338 | 0 | } |
8339 | 0 | } else { |
8340 | 0 | _zend_jit_merge_smart_branch_inputs(jit, true_label, false_label, true_inputs, false_inputs); |
8341 | 0 | } |
8342 | |
|
8343 | 0 | return 1; |
8344 | 0 | } |
8345 | | |
8346 | | static int zend_jit_isset_isempty_cv(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, uint8_t smart_branch_opcode, uint32_t target_label, uint32_t target_label2, const void *exit_addr) |
8347 | 0 | { |
8348 | 0 | zend_jit_addr res_addr = RES_ADDR(); |
8349 | 0 | uint32_t true_label = -1, false_label = -1; |
8350 | 0 | ir_ref end_inputs = IR_UNUSED, true_inputs = IR_UNUSED, false_inputs = IR_UNUSED; |
8351 | | |
8352 | | // TODO: support for empty() ??? |
8353 | 0 | ZEND_ASSERT(opline->extended_value != MAY_BE_RESOURCE); |
8354 | |
|
8355 | 0 | if (smart_branch_opcode && !exit_addr) { |
8356 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
8357 | 0 | true_label = target_label2; |
8358 | 0 | false_label = target_label; |
8359 | 0 | } else if (smart_branch_opcode == ZEND_JMPNZ) { |
8360 | 0 | true_label = target_label; |
8361 | 0 | false_label = target_label2; |
8362 | 0 | } else { |
8363 | 0 | ZEND_UNREACHABLE(); |
8364 | 0 | } |
8365 | 0 | } else { |
8366 | 0 | res_addr = RES_ADDR(); |
8367 | 0 | } |
8368 | | |
8369 | 0 | if (op1_info & MAY_BE_REF) { |
8370 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, op1_addr); |
8371 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
8372 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
8373 | 0 | } |
8374 | |
|
8375 | 0 | if (!(op1_info & (MAY_BE_UNDEF|MAY_BE_NULL))) { |
8376 | 0 | if (exit_addr) { |
8377 | 0 | ZEND_ASSERT(smart_branch_opcode == ZEND_JMPZ); |
8378 | 0 | } else if (smart_branch_opcode) { |
8379 | 0 | ir_END_list(true_inputs); |
8380 | 0 | } else { |
8381 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_TRUE); |
8382 | 0 | ir_END_list(end_inputs); |
8383 | 0 | } |
8384 | 0 | } else if (!(op1_info & (MAY_BE_ANY - MAY_BE_NULL))) { |
8385 | 0 | if (exit_addr) { |
8386 | 0 | ZEND_ASSERT(smart_branch_opcode == ZEND_JMPNZ); |
8387 | 0 | } else if (smart_branch_opcode) { |
8388 | 0 | ir_END_list(false_inputs); |
8389 | 0 | } else { |
8390 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_FALSE); |
8391 | 0 | ir_END_list(end_inputs); |
8392 | 0 | } |
8393 | 0 | } else { |
8394 | 0 | ir_ref ref = ir_GT(jit_Z_TYPE(jit, op1_addr), ir_CONST_U8(IS_NULL)); |
8395 | 0 | if (exit_addr) { |
8396 | 0 | if (smart_branch_opcode == ZEND_JMPNZ) { |
8397 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
8398 | 0 | } else { |
8399 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
8400 | 0 | } |
8401 | 0 | } else if (smart_branch_opcode) { |
8402 | 0 | ir_ref if_val = ir_IF(ref); |
8403 | 0 | ir_IF_TRUE(if_val); |
8404 | 0 | ir_END_list(true_inputs); |
8405 | 0 | ir_IF_FALSE(if_val); |
8406 | 0 | ir_END_list(false_inputs); |
8407 | 0 | } else { |
8408 | 0 | jit_set_Z_TYPE_INFO_ref(jit, jit_ZVAL_ADDR(jit, res_addr), |
8409 | 0 | ir_ADD_U32(ir_ZEXT_U32(ref), ir_CONST_U32(IS_FALSE))); |
8410 | 0 | ir_END_list(end_inputs); |
8411 | 0 | } |
8412 | 0 | } |
8413 | |
|
8414 | 0 | if (!smart_branch_opcode || exit_addr) { |
8415 | 0 | if (end_inputs) { |
8416 | 0 | ir_MERGE_list(end_inputs); |
8417 | 0 | } |
8418 | 0 | } else { |
8419 | 0 | _zend_jit_merge_smart_branch_inputs(jit, true_label, false_label, true_inputs, false_inputs); |
8420 | 0 | } |
8421 | |
|
8422 | 0 | return 1; |
8423 | 0 | } |
8424 | | |
8425 | | /* copy of hidden zend_closure */ |
8426 | | typedef struct _zend_closure { |
8427 | | zend_object std; |
8428 | | zend_function func; |
8429 | | zval this_ptr; |
8430 | | zend_class_entry *called_scope; |
8431 | | zif_handler orig_internal_handler; |
8432 | | } zend_closure; |
8433 | | |
8434 | | static int zend_jit_stack_check(zend_jit_ctx *jit, const zend_op *opline, uint32_t used_stack) |
8435 | 0 | { |
8436 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
8437 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
8438 | |
|
8439 | 0 | if (!exit_addr) { |
8440 | 0 | return 0; |
8441 | 0 | } |
8442 | | |
8443 | | // JIT: if (EG(vm_stack_end) - EG(vm_stack_top) < used_stack) |
8444 | 0 | ir_GUARD( |
8445 | 0 | ir_UGE( |
8446 | 0 | ir_SUB_A(ir_LOAD_A(jit_EG(vm_stack_end)), ir_LOAD_A(jit_EG(vm_stack_top))), |
8447 | 0 | ir_CONST_ADDR(used_stack)), |
8448 | 0 | ir_CONST_ADDR(exit_addr)); |
8449 | |
|
8450 | 0 | return 1; |
8451 | 0 | } |
8452 | | |
8453 | | static int zend_jit_free_trampoline(zend_jit_ctx *jit, ir_ref func) |
8454 | 0 | { |
8455 | | // JIT: if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) |
8456 | 0 | ir_ref if_trampoline = ir_IF(ir_AND_U32( |
8457 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func, offsetof(zend_function, common.fn_flags))), |
8458 | 0 | ir_CONST_U32(ZEND_ACC_CALL_VIA_TRAMPOLINE))); |
8459 | |
|
8460 | 0 | ir_IF_TRUE(if_trampoline); |
8461 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_free_trampoline_helper), func); |
8462 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_trampoline); |
8463 | |
|
8464 | 0 | return 1; |
8465 | 0 | } |
8466 | | |
8467 | | static int zend_jit_push_call_frame(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, zend_function *func, bool is_closure, bool delayed_fetch_this, int checked_stack, ir_ref func_ref, ir_ref this_ref) |
8468 | 0 | { |
8469 | 0 | uint32_t used_stack; |
8470 | 0 | ir_ref used_stack_ref = IR_UNUSED; |
8471 | 0 | bool stack_check = true; |
8472 | 0 | ir_ref rx, ref, top, if_enough_stack, cold_path = IR_UNUSED; |
8473 | |
|
8474 | 0 | ZEND_ASSERT(func_ref != IR_NULL); |
8475 | 0 | if (func) { |
8476 | 0 | used_stack = zend_vm_calc_used_stack(opline->extended_value, func); |
8477 | 0 | if ((int)used_stack <= checked_stack) { |
8478 | 0 | stack_check = false; |
8479 | 0 | } |
8480 | 0 | used_stack_ref = ir_CONST_ADDR(used_stack); |
8481 | 0 | } else { |
8482 | 0 | ir_ref num_args_ref; |
8483 | 0 | ir_ref if_internal_func = IR_UNUSED; |
8484 | 0 | const size_t func_type_offset = is_closure ? offsetof(zend_closure, func.type) : offsetof(zend_function, type); |
8485 | |
|
8486 | 0 | used_stack = (ZEND_CALL_FRAME_SLOT + opline->extended_value + ZEND_OBSERVER_ENABLED) * sizeof(zval); |
8487 | 0 | used_stack_ref = ir_CONST_ADDR(used_stack); |
8488 | 0 | used_stack_ref = ir_HARD_COPY_A(used_stack_ref); /* load constant once */ |
8489 | | |
8490 | | // JIT: if (EXPECTED(ZEND_USER_CODE(func->type))) { |
8491 | 0 | ir_ref tmp = ir_LOAD_U8(ir_ADD_OFFSET(func_ref, func_type_offset)); |
8492 | 0 | if_internal_func = ir_IF(ir_AND_U8(tmp, ir_CONST_U8(1))); |
8493 | 0 | ir_IF_FALSE(if_internal_func); |
8494 | | |
8495 | | // JIT: used_stack += (func->op_array.last_var + func->op_array.T - MIN(func->op_array.num_args, num_args)) * sizeof(zval); |
8496 | 0 | num_args_ref = ir_CONST_U32(opline->extended_value); |
8497 | 0 | if (!is_closure) { |
8498 | 0 | ref = ir_SUB_U32( |
8499 | 0 | ir_SUB_U32( |
8500 | 0 | ir_MIN_U32( |
8501 | 0 | num_args_ref, |
8502 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_function, op_array.num_args)))), |
8503 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_function, op_array.last_var)))), |
8504 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_function, op_array.T)))); |
8505 | 0 | } else { |
8506 | 0 | ref = ir_SUB_U32( |
8507 | 0 | ir_SUB_U32( |
8508 | 0 | ir_MIN_U32( |
8509 | 0 | num_args_ref, |
8510 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_closure, func.op_array.num_args)))), |
8511 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_closure, func.op_array.last_var)))), |
8512 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_closure, func.op_array.T)))); |
8513 | 0 | } |
8514 | 0 | ref = ir_MUL_U32(ref, ir_CONST_U32(sizeof(zval))); |
8515 | 0 | if (sizeof(void*) == 8) { |
8516 | 0 | ref = ir_SEXT_A(ref); |
8517 | 0 | } |
8518 | 0 | ref = ir_SUB_A(used_stack_ref, ref); |
8519 | |
|
8520 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_internal_func); |
8521 | 0 | used_stack_ref = ir_PHI_2(IR_ADDR, ref, used_stack_ref); |
8522 | 0 | } |
8523 | |
|
8524 | 0 | zend_jit_start_reuse_ip(jit); |
8525 | | |
8526 | | // JIT: if (UNEXPECTED(used_stack > (size_t)(((char*)EG(vm_stack_end)) - (char*)call))) { |
8527 | 0 | jit_STORE_IP(jit, ir_LOAD_A(jit_EG(vm_stack_top))); |
8528 | |
|
8529 | 0 | if (stack_check) { |
8530 | | // JIT: Check Stack Overflow |
8531 | 0 | ref = ir_UGE( |
8532 | 0 | ir_SUB_A( |
8533 | 0 | ir_LOAD_A(jit_EG(vm_stack_end)), |
8534 | 0 | jit_IP(jit)), |
8535 | 0 | used_stack_ref); |
8536 | |
|
8537 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
8538 | 0 | bool may_be_trampoline = !func && (opline->opcode == ZEND_INIT_METHOD_CALL); |
8539 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, |
8540 | 0 | may_be_trampoline ? |
8541 | 0 | (ZEND_JIT_EXIT_TO_VM | ZEND_JIT_EXIT_METHOD_CALL) : ZEND_JIT_EXIT_TO_VM); |
8542 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
8543 | |
|
8544 | 0 | if (!exit_addr) { |
8545 | 0 | return 0; |
8546 | 0 | } |
8547 | | |
8548 | 0 | if (may_be_trampoline) { |
8549 | 0 | jit->trace->exit_info[exit_point].poly_func.ref = func_ref; |
8550 | 0 | jit->trace->exit_info[exit_point].poly_this.ref = this_ref; |
8551 | 0 | } |
8552 | |
|
8553 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
8554 | 0 | } else { |
8555 | 0 | if_enough_stack = ir_IF(ref); |
8556 | 0 | ir_IF_FALSE_cold(if_enough_stack); |
8557 | |
|
8558 | | #ifdef _WIN32 |
8559 | | if (0) { |
8560 | | #else |
8561 | 0 | if (opline->opcode == ZEND_INIT_FCALL && func && func->type == ZEND_INTERNAL_FUNCTION) { |
8562 | 0 | #endif |
8563 | 0 | jit_SET_EX_OPLINE(jit, opline); |
8564 | 0 | ref = ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_int_extend_stack_helper), used_stack_ref); |
8565 | 0 | } else { |
8566 | 0 | if (!is_closure) { |
8567 | 0 | ref = func_ref; |
8568 | 0 | } else { |
8569 | 0 | ref = ir_ADD_OFFSET(func_ref, offsetof(zend_closure, func)); |
8570 | 0 | } |
8571 | 0 | jit_SET_EX_OPLINE(jit, opline); |
8572 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_extend_stack_helper), |
8573 | 0 | used_stack_ref, ref); |
8574 | 0 | } |
8575 | 0 | jit_STORE_IP(jit, ref); |
8576 | |
|
8577 | 0 | cold_path = ir_END(); |
8578 | 0 | ir_IF_TRUE(if_enough_stack); |
8579 | 0 | } |
8580 | 0 | } |
8581 | | |
8582 | 0 | ref = jit_EG(vm_stack_top); |
8583 | 0 | rx = jit_IP(jit); |
8584 | 0 | #if !OPTIMIZE_FOR_SIZE |
8585 | | /* JIT: EG(vm_stack_top) = (zval*)((char*)call + used_stack); |
8586 | | * This vesions is longer but faster |
8587 | | * mov EG(vm_stack_top), %CALL |
8588 | | * lea size(%call), %tmp |
8589 | | * mov %tmp, EG(vm_stack_top) |
8590 | | */ |
8591 | 0 | top = rx; |
8592 | | #else |
8593 | | /* JIT: EG(vm_stack_top) += used_stack; |
8594 | | * Use ir_emit() because ir_LOAD() makes load forwarding and doesn't allow load/store fusion |
8595 | | * mov EG(vm_stack_top), %CALL |
8596 | | * add $size, EG(vm_stack_top) |
8597 | | */ |
8598 | | top = jit->ctx.control = ir_emit2(&jit->ctx, IR_OPT(IR_LOAD, IR_ADDR), jit->ctx.control, ref); |
8599 | | #endif |
8600 | 0 | ir_STORE(ref, ir_ADD_A(top, used_stack_ref)); |
8601 | | |
8602 | | // JIT: zend_vm_init_call_frame(call, call_info, func, num_args, called_scope, object); |
8603 | 0 | if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || opline->opcode != ZEND_INIT_METHOD_CALL) { |
8604 | | // JIT: ZEND_SET_CALL_INFO(call, 0, call_info); |
8605 | 0 | ir_STORE(jit_CALL(rx, This.u1.type_info), ir_CONST_U32(IS_UNDEF | ZEND_CALL_NESTED_FUNCTION)); |
8606 | 0 | } |
8607 | | #ifdef _WIN32 |
8608 | | if (0) { |
8609 | | #else |
8610 | 0 | if (opline->opcode == ZEND_INIT_FCALL && func && func->type == ZEND_INTERNAL_FUNCTION) { |
8611 | 0 | #endif |
8612 | 0 | if (cold_path) { |
8613 | 0 | ir_MERGE_WITH(cold_path); |
8614 | 0 | rx = jit_IP(jit); |
8615 | 0 | } |
8616 | | |
8617 | | // JIT: call->func = func; |
8618 | 0 | ir_STORE(jit_CALL(rx, func), func_ref); |
8619 | 0 | } else { |
8620 | 0 | if (!is_closure) { |
8621 | | // JIT: call->func = func; |
8622 | 0 | ir_STORE(jit_CALL(rx, func), func_ref); |
8623 | 0 | } else { |
8624 | | // JIT: call->func = &closure->func; |
8625 | 0 | ir_STORE(jit_CALL(rx, func), ir_ADD_OFFSET(func_ref, offsetof(zend_closure, func))); |
8626 | 0 | } |
8627 | 0 | if (cold_path) { |
8628 | 0 | ir_MERGE_WITH(cold_path); |
8629 | 0 | rx = jit_IP(jit); |
8630 | 0 | } |
8631 | 0 | } |
8632 | 0 | if (opline->opcode == ZEND_INIT_METHOD_CALL) { |
8633 | | // JIT: Z_PTR(call->This) = obj; |
8634 | 0 | ZEND_ASSERT(this_ref != IR_NULL); |
8635 | 0 | ir_STORE(jit_CALL(rx, This.value.ptr), this_ref); |
8636 | 0 | if (opline->op1_type == IS_UNUSED || delayed_fetch_this) { |
8637 | | // JIT: call->call_info |= ZEND_CALL_HAS_THIS; |
8638 | 0 | ref = jit_CALL(rx, This.u1.type_info); |
8639 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
8640 | 0 | ir_STORE(ref, ir_CONST_U32( ZEND_CALL_HAS_THIS)); |
8641 | 0 | } else { |
8642 | 0 | ir_STORE(ref, ir_OR_U32(ir_LOAD_U32(ref), ir_CONST_U32(ZEND_CALL_HAS_THIS))); |
8643 | 0 | } |
8644 | 0 | } else { |
8645 | 0 | if (opline->op1_type == IS_CV) { |
8646 | | // JIT: GC_ADDREF(obj); |
8647 | 0 | jit_GC_ADDREF(jit, this_ref); |
8648 | 0 | } |
8649 | | |
8650 | | // JIT: call->call_info |= ZEND_CALL_HAS_THIS | ZEND_CALL_RELEASE_THIS; |
8651 | 0 | ref = jit_CALL(rx, This.u1.type_info); |
8652 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
8653 | 0 | ir_STORE(ref, ir_CONST_U32( ZEND_CALL_HAS_THIS | ZEND_CALL_RELEASE_THIS)); |
8654 | 0 | } else { |
8655 | 0 | ir_STORE(ref, |
8656 | 0 | ir_OR_U32(ir_LOAD_U32(ref), |
8657 | 0 | ir_CONST_U32(ZEND_CALL_HAS_THIS | ZEND_CALL_RELEASE_THIS))); |
8658 | 0 | } |
8659 | 0 | } |
8660 | 0 | } else if (opline->opcode == ZEND_INIT_STATIC_METHOD_CALL) { |
8661 | | // JIT: Z_CE(call->This) = called_scope; |
8662 | 0 | ir_STORE(jit_CALL(rx, This), this_ref); |
8663 | 0 | } else if (!is_closure) { |
8664 | | // JIT: Z_CE(call->This) = called_scope; |
8665 | 0 | ir_STORE(jit_CALL(rx, This), IR_NULL); |
8666 | 0 | } else { |
8667 | 0 | ir_ref object_or_called_scope, call_info, call_info2, object, if_cond; |
8668 | 0 | ir_ref if_cond_user = IR_UNUSED; |
8669 | |
|
8670 | 0 | if (opline->op2_type == IS_CV) { |
8671 | | // JIT: GC_ADDREF(closure); |
8672 | 0 | jit_GC_ADDREF(jit, func_ref); |
8673 | 0 | } |
8674 | | |
8675 | | // JIT: RX(object_or_called_scope) = closure->called_scope; |
8676 | 0 | object_or_called_scope = ir_LOAD_A(ir_ADD_OFFSET(func_ref, offsetof(zend_closure, called_scope))); |
8677 | | |
8678 | | // JIT: call_info = ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC | ZEND_CALL_CLOSURE | |
8679 | | // (closure->func->common.fn_flags & ZEND_ACC_FAKE_CLOSURE); |
8680 | 0 | call_info = ir_OR_U32( |
8681 | 0 | ir_AND_U32( |
8682 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_closure, func.common.fn_flags))), |
8683 | 0 | ir_CONST_U32(ZEND_ACC_FAKE_CLOSURE)), |
8684 | 0 | ir_CONST_U32(ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC | ZEND_CALL_CLOSURE)); |
8685 | | // JIT: if (Z_TYPE(closure->this_ptr) != IS_UNDEF) { |
8686 | 0 | if_cond = ir_IF(ir_LOAD_U8(ir_ADD_OFFSET(func_ref, offsetof(zend_closure, this_ptr.u1.v.type)))); |
8687 | 0 | ir_IF_TRUE(if_cond); |
8688 | | |
8689 | | // JIT: call_info |= ZEND_CALL_HAS_THIS; |
8690 | 0 | call_info2 = ir_OR_U32(call_info, ir_CONST_U32(ZEND_CALL_HAS_THIS)); |
8691 | | |
8692 | | // JIT: object_or_called_scope = Z_OBJ(closure->this_ptr); |
8693 | 0 | object = ir_LOAD_A(ir_ADD_OFFSET(func_ref, offsetof(zend_closure, this_ptr.value.ptr))); |
8694 | |
|
8695 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_cond); |
8696 | 0 | call_info = ir_PHI_2(IR_U32, call_info2, call_info); |
8697 | 0 | object_or_called_scope = ir_PHI_2(IR_ADDR, object, object_or_called_scope); |
8698 | | |
8699 | | // JIT: ZEND_SET_CALL_INFO(call, 0, call_info); |
8700 | 0 | ref = jit_CALL(rx, This.u1.type_info); |
8701 | 0 | ir_STORE(ref, ir_OR_U32(ir_LOAD_U32(ref), call_info)); |
8702 | | |
8703 | | // JIT: Z_PTR(call->This) = object_or_called_scope; |
8704 | 0 | ir_STORE(jit_CALL(rx, This.value.ptr), object_or_called_scope); |
8705 | |
|
8706 | 0 | if (!func) { |
8707 | | // JIT: if (closure->func.common.type & ZEND_USER_FUNCTION) |
8708 | 0 | ir_ref type = ir_LOAD_U8(ir_ADD_OFFSET(func_ref, offsetof(zend_closure, func.type))); |
8709 | 0 | if_cond_user = ir_IF(ir_AND_U8(type, ir_CONST_U8(ZEND_USER_FUNCTION))); |
8710 | 0 | ir_IF_TRUE(if_cond_user); |
8711 | 0 | } |
8712 | |
|
8713 | 0 | if (!func || func->common.type == ZEND_USER_FUNCTION) { |
8714 | | // JIT: zend_jit_init_func_run_time_cache_helper(closure->func); |
8715 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_init_func_run_time_cache_helper), |
8716 | 0 | ir_ADD_OFFSET(func_ref, offsetof(zend_closure, func))); |
8717 | 0 | } |
8718 | |
|
8719 | 0 | if (!func) { |
8720 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_cond_user); |
8721 | 0 | } |
8722 | 0 | } |
8723 | | |
8724 | | // JIT: ZEND_CALL_NUM_ARGS(call) = num_args; |
8725 | 0 | ir_STORE(jit_CALL(rx, This.u2.num_args), ir_CONST_U32(opline->extended_value)); |
8726 | |
|
8727 | 0 | return 1; |
8728 | 0 | } |
8729 | | |
8730 | | static int zend_jit_func_guard(zend_jit_ctx *jit, ir_ref func_ref, const zend_function *func, const void *exit_addr) |
8731 | 0 | { |
8732 | 0 | if (func->type == ZEND_USER_FUNCTION && |
8733 | 0 | (!(func->common.fn_flags & ZEND_ACC_IMMUTABLE) || |
8734 | 0 | (func->common.fn_flags & ZEND_ACC_CLOSURE) || |
8735 | 0 | !func->common.function_name)) { |
8736 | 0 | const zend_op *opcodes = func->op_array.opcodes; |
8737 | | |
8738 | | // JIT: if (call->func.op_array.opcodes != opcodes) goto exit_addr; |
8739 | 0 | ir_GUARD( |
8740 | 0 | ir_EQ( |
8741 | 0 | ir_LOAD_A(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, opcodes))), |
8742 | 0 | ir_CONST_ADDR(opcodes)), |
8743 | 0 | ir_CONST_ADDR(exit_addr)); |
8744 | | #ifdef ZEND_WIN32 |
8745 | | } else if (func->type == ZEND_INTERNAL_FUNCTION) { |
8746 | | // ASLR may cause different addresses in different workers. Check for the internal function handler. |
8747 | | // JIT: if (call->func.internal_function.handler != handler) goto exit_addr; |
8748 | | ir_GUARD( |
8749 | | ir_EQ( |
8750 | | ir_LOAD_A(ir_ADD_OFFSET(func_ref, offsetof(zend_internal_function, handler))), |
8751 | | ir_CONST_FC_FUNC(func->internal_function.handler)), |
8752 | | ir_CONST_ADDR(exit_addr)); |
8753 | | #endif |
8754 | 0 | } else { |
8755 | | // JIT: if (call->func != func) goto exit_addr; |
8756 | 0 | ir_GUARD(ir_EQ(func_ref, ir_CONST_ADDR(func)), ir_CONST_ADDR(exit_addr)); |
8757 | 0 | } |
8758 | |
|
8759 | 0 | return 1; |
8760 | 0 | } |
8761 | | |
8762 | | static int zend_jit_init_fcall_guard(zend_jit_ctx *jit, uint32_t level, const zend_function *func, const zend_op *to_opline) |
8763 | 0 | { |
8764 | 0 | int32_t exit_point; |
8765 | 0 | const void *exit_addr; |
8766 | 0 | ir_ref call; |
8767 | |
|
8768 | 0 | if (func->type == ZEND_USER_FUNCTION |
8769 | 0 | && !zend_accel_in_shm(func->op_array.opcodes)) { |
8770 | | /* op_array and op_array->opcodes are not persistent. We can't link. */ |
8771 | 0 | return 0; |
8772 | 0 | } |
8773 | | |
8774 | 0 | exit_point = zend_jit_trace_get_exit_point(to_opline, ZEND_JIT_EXIT_POLYMORPHISM); |
8775 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
8776 | 0 | if (!exit_addr) { |
8777 | 0 | return 0; |
8778 | 0 | } |
8779 | | |
8780 | | // call = EX(call); |
8781 | 0 | call = ir_LOAD_A(jit_EX(call)); |
8782 | 0 | while (level > 0) { |
8783 | | // call = call->prev_execute_data |
8784 | 0 | call = ir_LOAD_A(jit_CALL(call, prev_execute_data)); |
8785 | 0 | level--; |
8786 | 0 | } |
8787 | |
|
8788 | 0 | return zend_jit_func_guard(jit, ir_LOAD_A(jit_CALL(call, func)), func, exit_addr); |
8789 | 0 | } |
8790 | | |
8791 | | static int zend_jit_init_fcall(zend_jit_ctx *jit, const zend_op *opline, uint32_t b, const zend_op_array *op_array, zend_ssa *ssa, const zend_ssa_op *ssa_op, int call_level, zend_jit_trace_rec *trace, int checked_stack) |
8792 | 0 | { |
8793 | 0 | zend_func_info *info = ZEND_FUNC_INFO(op_array); |
8794 | 0 | zend_call_info *call_info = NULL; |
8795 | 0 | zend_function *func = NULL; |
8796 | 0 | ir_ref func_ref = IR_UNUSED; |
8797 | |
|
8798 | 0 | if (jit->delayed_call_level) { |
8799 | 0 | if (!zend_jit_save_call_chain(jit, jit->delayed_call_level)) { |
8800 | 0 | return 0; |
8801 | 0 | } |
8802 | 0 | } |
8803 | | |
8804 | 0 | if (info) { |
8805 | 0 | call_info = info->callee_info; |
8806 | 0 | while (call_info && call_info->caller_init_opline != opline) { |
8807 | 0 | call_info = call_info->next_callee; |
8808 | 0 | } |
8809 | 0 | if (call_info && call_info->callee_func && !call_info->is_prototype) { |
8810 | 0 | func = call_info->callee_func; |
8811 | 0 | } |
8812 | 0 | } |
8813 | |
|
8814 | 0 | if (!func |
8815 | 0 | && trace |
8816 | 0 | && trace->op == ZEND_JIT_TRACE_INIT_CALL) { |
8817 | | #ifdef _WIN32 |
8818 | | /* ASLR */ |
8819 | | if (trace->func->type != ZEND_INTERNAL_FUNCTION) { |
8820 | | func = (zend_function*)trace->func; |
8821 | | } |
8822 | | #else |
8823 | 0 | func = (zend_function*)trace->func; |
8824 | 0 | #endif |
8825 | 0 | } |
8826 | |
|
8827 | | #ifdef _WIN32 |
8828 | | if (0) { |
8829 | | #else |
8830 | 0 | if (opline->opcode == ZEND_INIT_FCALL |
8831 | 0 | && func |
8832 | 0 | && func->type == ZEND_INTERNAL_FUNCTION) { |
8833 | 0 | #endif |
8834 | | /* load constant address later */ |
8835 | 0 | func_ref = ir_CONST_ADDR(func); |
8836 | 0 | } else if (func && op_array == &func->op_array) { |
8837 | | /* recursive call */ |
8838 | 0 | if (!(func->op_array.fn_flags & ZEND_ACC_IMMUTABLE) |
8839 | 0 | || zend_jit_prefer_const_addr_load(jit, (uintptr_t)func)) { |
8840 | 0 | func_ref = ir_LOAD_A(jit_EX(func)); |
8841 | 0 | } else { |
8842 | 0 | func_ref = ir_CONST_ADDR(func); |
8843 | 0 | } |
8844 | 0 | } else { |
8845 | 0 | ir_ref if_func, cache_slot_ref, ref; |
8846 | | |
8847 | | // JIT: if (CACHED_PTR(opline->result.num)) |
8848 | 0 | cache_slot_ref = ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->result.num); |
8849 | 0 | func_ref = ir_LOAD_A(cache_slot_ref); |
8850 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
8851 | 0 | && func |
8852 | 0 | && (func->common.fn_flags & ZEND_ACC_IMMUTABLE) |
8853 | 0 | && opline->opcode != ZEND_INIT_FCALL) { |
8854 | | /* Called func may be changed because of recompilation. See ext/opcache/tests/jit/init_fcall_003.phpt */ |
8855 | 0 | if_func = ir_IF(ir_EQ(func_ref, ir_CONST_ADDR(func))); |
8856 | 0 | } else { |
8857 | 0 | if_func = ir_IF(func_ref); |
8858 | 0 | } |
8859 | 0 | ir_IF_FALSE_cold(if_func); |
8860 | 0 | if (opline->opcode == ZEND_INIT_FCALL |
8861 | 0 | && func |
8862 | 0 | && func->type == ZEND_USER_FUNCTION |
8863 | 0 | && (func->op_array.fn_flags & ZEND_ACC_IMMUTABLE)) { |
8864 | 0 | ref = ir_HARD_COPY_A(ir_CONST_ADDR(func)); /* load constant once */ |
8865 | 0 | ir_STORE(cache_slot_ref, ref); |
8866 | 0 | ref = ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_init_func_run_time_cache_helper), ref); |
8867 | 0 | } else { |
8868 | 0 | zval *zv = RT_CONSTANT(opline, opline->op2); |
8869 | |
|
8870 | 0 | if (opline->opcode == ZEND_INIT_FCALL) { |
8871 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_find_func_helper), |
8872 | 0 | ir_CONST_ADDR(Z_STR_P(zv)), |
8873 | 0 | cache_slot_ref); |
8874 | 0 | } else if (opline->opcode == ZEND_INIT_FCALL_BY_NAME) { |
8875 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_find_func_helper), |
8876 | 0 | ir_CONST_ADDR(Z_STR_P(zv + 1)), |
8877 | 0 | cache_slot_ref); |
8878 | 0 | } else if (opline->opcode == ZEND_INIT_NS_FCALL_BY_NAME) { |
8879 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_find_ns_func_helper), |
8880 | 0 | ir_CONST_ADDR(zv), |
8881 | 0 | cache_slot_ref); |
8882 | 0 | } else { |
8883 | 0 | ZEND_UNREACHABLE(); |
8884 | 0 | } |
8885 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
8886 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, |
8887 | 0 | func && (func->common.fn_flags & ZEND_ACC_IMMUTABLE) ? ZEND_JIT_EXIT_INVALIDATE : 0); |
8888 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
8889 | |
|
8890 | 0 | if (!exit_addr) { |
8891 | 0 | return 0; |
8892 | 0 | } |
8893 | 0 | if (!func || opline->opcode == ZEND_INIT_FCALL) { |
8894 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
8895 | 0 | } else if (!zend_jit_func_guard(jit, ref, func, exit_addr)) { |
8896 | 0 | return 0; |
8897 | 0 | } |
8898 | 0 | } else { |
8899 | 0 | jit_SET_EX_OPLINE(jit, opline); |
8900 | 0 | ir_GUARD(ref, jit_STUB_ADDR(jit, jit_stub_undefined_function)); |
8901 | 0 | } |
8902 | 0 | } |
8903 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_func); |
8904 | 0 | func_ref = ir_PHI_2(IR_ADDR, ref, func_ref); |
8905 | 0 | } |
8906 | | |
8907 | 0 | if (!zend_jit_push_call_frame(jit, opline, op_array, func, false, false, checked_stack, func_ref, IR_UNUSED)) { |
8908 | 0 | return 0; |
8909 | 0 | } |
8910 | | |
8911 | 0 | if (zend_jit_needs_call_chain(call_info, b, op_array, ssa, ssa_op, opline, call_level, trace)) { |
8912 | 0 | if (!zend_jit_save_call_chain(jit, call_level)) { |
8913 | 0 | return 0; |
8914 | 0 | } |
8915 | 0 | } else { |
8916 | 0 | ZEND_ASSERT(call_level > 0); |
8917 | 0 | jit->delayed_call_level = call_level; |
8918 | 0 | delayed_call_chain = true; |
8919 | 0 | } |
8920 | | |
8921 | 0 | if (trace |
8922 | 0 | && trace->op == ZEND_JIT_TRACE_END |
8923 | 0 | && trace->stop >= ZEND_JIT_TRACE_STOP_INTERPRETER) { |
8924 | 0 | if (!zend_jit_set_ip(jit, opline + 1)) { |
8925 | 0 | return 0; |
8926 | 0 | } |
8927 | 0 | } |
8928 | | |
8929 | 0 | return 1; |
8930 | 0 | } |
8931 | | |
8932 | | static int zend_jit_init_method_call(zend_jit_ctx *jit, |
8933 | | const zend_op *opline, |
8934 | | uint32_t b, |
8935 | | const zend_op_array *op_array, |
8936 | | zend_ssa *ssa, |
8937 | | const zend_ssa_op *ssa_op, |
8938 | | int call_level, |
8939 | | uint32_t op1_info, |
8940 | | zend_jit_addr op1_addr, |
8941 | | zend_class_entry *ce, |
8942 | | bool ce_is_instanceof, |
8943 | | bool on_this, |
8944 | | bool delayed_fetch_this, |
8945 | | zend_class_entry *trace_ce, |
8946 | | zend_jit_trace_rec *trace, |
8947 | | int checked_stack, |
8948 | | ir_ref func_ref, |
8949 | | ir_ref this_ref, |
8950 | | bool polymorphic_side_trace) |
8951 | 0 | { |
8952 | 0 | zend_func_info *info = ZEND_FUNC_INFO(op_array); |
8953 | 0 | zend_call_info *call_info = NULL; |
8954 | 0 | zend_function *func = NULL; |
8955 | 0 | zval *function_name; |
8956 | 0 | ir_ref if_static = IR_UNUSED, cold_path; |
8957 | |
|
8958 | 0 | ZEND_ASSERT(opline->op2_type == IS_CONST); |
8959 | 0 | ZEND_ASSERT(op1_info & MAY_BE_OBJECT); |
8960 | |
|
8961 | 0 | function_name = RT_CONSTANT(opline, opline->op2); |
8962 | |
|
8963 | 0 | if (info) { |
8964 | 0 | call_info = info->callee_info; |
8965 | 0 | while (call_info && call_info->caller_init_opline != opline) { |
8966 | 0 | call_info = call_info->next_callee; |
8967 | 0 | } |
8968 | 0 | if (call_info && call_info->callee_func && !call_info->is_prototype) { |
8969 | 0 | func = call_info->callee_func; |
8970 | 0 | } |
8971 | 0 | } |
8972 | |
|
8973 | 0 | if (polymorphic_side_trace) { |
8974 | | /* function is passed from parent snapshot */ |
8975 | 0 | ZEND_ASSERT(func_ref != IR_UNUSED && this_ref != IR_UNUSED); |
8976 | 0 | } else { |
8977 | 0 | ir_ref ref, ref2, if_found, fast_path, run_time_cache, this_ref2; |
8978 | |
|
8979 | 0 | if (on_this) { |
8980 | 0 | zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This)); |
8981 | 0 | this_ref = jit_Z_PTR(jit, this_addr); |
8982 | 0 | } else { |
8983 | 0 | if (op1_info & MAY_BE_REF) { |
8984 | 0 | if (opline->op1_type == IS_CV) { |
8985 | | // JIT: ZVAL_DEREF(op1) |
8986 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, op1_addr); |
8987 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
8988 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
8989 | 0 | } else { |
8990 | 0 | ir_ref if_ref; |
8991 | | |
8992 | | /* Hack: Convert reference to regular value to simplify JIT code */ |
8993 | 0 | ZEND_ASSERT(Z_REG(op1_addr) == ZREG_FP); |
8994 | |
|
8995 | 0 | if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_REFERENCE); |
8996 | 0 | ir_IF_TRUE(if_ref); |
8997 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_unref_helper), jit_ZVAL_ADDR(jit, op1_addr)); |
8998 | |
|
8999 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_ref); |
9000 | 0 | } |
9001 | 0 | } |
9002 | 0 | if (op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY)- MAY_BE_OBJECT)) { |
9003 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
9004 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
9005 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
9006 | |
|
9007 | 0 | if (!exit_addr) { |
9008 | 0 | return 0; |
9009 | 0 | } |
9010 | 0 | ir_GUARD(ir_EQ(jit_Z_TYPE(jit, op1_addr), ir_CONST_U8(IS_OBJECT)), |
9011 | 0 | ir_CONST_ADDR(exit_addr)); |
9012 | 0 | } else { |
9013 | 0 | ir_ref if_object = jit_if_Z_TYPE(jit, op1_addr, IS_OBJECT); |
9014 | |
|
9015 | 0 | ir_IF_FALSE_cold(if_object); |
9016 | |
|
9017 | 0 | jit_SET_EX_OPLINE(jit, opline); |
9018 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) && !delayed_fetch_this) { |
9019 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_invalid_method_call_tmp), |
9020 | 0 | jit_ZVAL_ADDR(jit, op1_addr)); |
9021 | 0 | } else { |
9022 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_invalid_method_call), |
9023 | 0 | jit_ZVAL_ADDR(jit, op1_addr)); |
9024 | 0 | } |
9025 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
9026 | 0 | ir_IF_TRUE(if_object); |
9027 | 0 | } |
9028 | 0 | } |
9029 | | |
9030 | 0 | this_ref = jit_Z_PTR(jit, op1_addr); |
9031 | 0 | } |
9032 | | |
9033 | 0 | if (jit->delayed_call_level) { |
9034 | 0 | if (!zend_jit_save_call_chain(jit, jit->delayed_call_level)) { |
9035 | 0 | return 0; |
9036 | 0 | } |
9037 | 0 | } |
9038 | | |
9039 | 0 | if (func) { |
9040 | | // JIT: fbc = CACHED_PTR(opline->result.num + sizeof(void*)); |
9041 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->result.num + sizeof(void*))); |
9042 | |
|
9043 | 0 | if_found = ir_IF(ref); |
9044 | 0 | ir_IF_TRUE(if_found); |
9045 | 0 | fast_path = ir_END(); |
9046 | 0 | } else { |
9047 | | // JIT: if (CACHED_PTR(opline->result.num) == obj->ce)) { |
9048 | 0 | run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
9049 | 0 | ref = ir_EQ( |
9050 | 0 | ir_LOAD_A(ir_ADD_OFFSET(run_time_cache, opline->result.num)), |
9051 | 0 | ir_LOAD_A(ir_ADD_OFFSET(this_ref, offsetof(zend_object, ce)))); |
9052 | 0 | if_found = ir_IF(ref); |
9053 | 0 | ir_IF_TRUE(if_found); |
9054 | | |
9055 | | // JIT: fbc = CACHED_PTR(opline->result.num + sizeof(void*)); |
9056 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(run_time_cache, opline->result.num + sizeof(void*))); |
9057 | 0 | fast_path = ir_END(); |
9058 | |
|
9059 | 0 | } |
9060 | |
|
9061 | 0 | ir_IF_FALSE_cold(if_found); |
9062 | 0 | jit_SET_EX_OPLINE(jit, opline); |
9063 | |
|
9064 | 0 | if (!jit->ctx.fixed_call_stack_size) { |
9065 | | // JIT: alloca(sizeof(void*)); |
9066 | 0 | this_ref2 = ir_ALLOCA(ir_CONST_ADDR(0x10)); |
9067 | 0 | } else { |
9068 | | #ifdef _WIN64 |
9069 | | this_ref2 = ir_HARD_COPY_A(jit_ADD_OFFSET(jit, ir_RLOAD_A(IR_REG_SP), IR_SHADOW_ARGS)); |
9070 | | #else |
9071 | 0 | this_ref2 = ir_HARD_COPY_A(ir_RLOAD_A(IR_REG_SP)); |
9072 | 0 | #endif |
9073 | 0 | } |
9074 | 0 | ir_STORE(this_ref2, this_ref); |
9075 | |
|
9076 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) && !delayed_fetch_this) { |
9077 | 0 | ref2 = ir_CALL_3(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_find_method_tmp_helper), |
9078 | 0 | this_ref, |
9079 | 0 | ir_CONST_ADDR(function_name), |
9080 | 0 | this_ref2); |
9081 | 0 | } else { |
9082 | 0 | ref2 = ir_CALL_3(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_find_method_helper), |
9083 | 0 | this_ref, |
9084 | 0 | ir_CONST_ADDR(function_name), |
9085 | 0 | this_ref2); |
9086 | 0 | } |
9087 | | |
9088 | |
|
9089 | 0 | if (!jit->ctx.fixed_call_stack_size) { |
9090 | 0 | this_ref2 = ir_LOAD_A(ir_RLOAD_A(IR_REG_SP)); |
9091 | | // JIT: revert alloca |
9092 | 0 | ir_AFREE(ir_CONST_ADDR(0x10)); |
9093 | 0 | } else { |
9094 | | #ifdef _WIN64 |
9095 | | this_ref2 = ir_LOAD_A(jit_ADD_OFFSET(jit, ir_RLOAD_A(IR_REG_SP), IR_SHADOW_ARGS)); |
9096 | | #else |
9097 | 0 | this_ref2 = ir_LOAD_A(ir_RLOAD_A(IR_REG_SP)); |
9098 | 0 | #endif |
9099 | 0 | } |
9100 | |
|
9101 | 0 | ir_GUARD(ref2, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
9102 | |
|
9103 | 0 | ir_MERGE_WITH(fast_path); |
9104 | 0 | func_ref = ir_PHI_2(IR_ADDR, ref2, ref); |
9105 | 0 | this_ref = ir_PHI_2(IR_ADDR, this_ref2, this_ref); |
9106 | 0 | } |
9107 | | |
9108 | 0 | if ((!func || zend_jit_may_be_modified(func, op_array)) |
9109 | 0 | && trace |
9110 | 0 | && trace->op == ZEND_JIT_TRACE_INIT_CALL |
9111 | 0 | && trace->func) { |
9112 | 0 | int32_t exit_point; |
9113 | 0 | const void *exit_addr; |
9114 | |
|
9115 | 0 | exit_point = zend_jit_trace_get_exit_point(opline, func ? ZEND_JIT_EXIT_INVALIDATE : ZEND_JIT_EXIT_METHOD_CALL); |
9116 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
9117 | 0 | if (!exit_addr) { |
9118 | 0 | return 0; |
9119 | 0 | } |
9120 | | |
9121 | 0 | jit->trace->exit_info[exit_point].poly_func.ref = func_ref; |
9122 | 0 | jit->trace->exit_info[exit_point].poly_this.ref = this_ref; |
9123 | |
|
9124 | 0 | func = (zend_function*)trace->func; |
9125 | |
|
9126 | 0 | if (!zend_jit_func_guard(jit, func_ref, func, exit_addr)) { |
9127 | 0 | return 0; |
9128 | 0 | } |
9129 | 0 | } |
9130 | | |
9131 | 0 | if (!func) { |
9132 | | // JIT: if (fbc->common.fn_flags & ZEND_ACC_STATIC) { |
9133 | 0 | if_static = ir_IF(ir_AND_U32( |
9134 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_function, common.fn_flags))), |
9135 | 0 | ir_CONST_U32(ZEND_ACC_STATIC))); |
9136 | 0 | ir_IF_TRUE_cold(if_static); |
9137 | 0 | } |
9138 | |
|
9139 | 0 | if (!func || (func->common.fn_flags & ZEND_ACC_STATIC) != 0) { |
9140 | 0 | ir_ref ret; |
9141 | |
|
9142 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) && !delayed_fetch_this) { |
9143 | 0 | ret = ir_CALL_3(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_push_static_method_call_frame_tmp), |
9144 | 0 | this_ref, |
9145 | 0 | func_ref, |
9146 | 0 | ir_CONST_U32(opline->extended_value)); |
9147 | 0 | } else { |
9148 | 0 | ret = ir_CALL_3(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_push_static_method_call_frame), |
9149 | 0 | this_ref, |
9150 | 0 | func_ref, |
9151 | 0 | ir_CONST_U32(opline->extended_value)); |
9152 | 0 | } |
9153 | |
|
9154 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR) && !delayed_fetch_this)) { |
9155 | 0 | ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
9156 | 0 | } |
9157 | 0 | jit_STORE_IP(jit, ret); |
9158 | 0 | } |
9159 | |
|
9160 | 0 | if (!func) { |
9161 | 0 | cold_path = ir_END(); |
9162 | 0 | ir_IF_FALSE(if_static); |
9163 | 0 | } |
9164 | |
|
9165 | 0 | if (!func || (func->common.fn_flags & ZEND_ACC_STATIC) == 0) { |
9166 | 0 | if (!zend_jit_push_call_frame(jit, opline, NULL, func, false, delayed_fetch_this, checked_stack, func_ref, this_ref)) { |
9167 | 0 | return 0; |
9168 | 0 | } |
9169 | 0 | } |
9170 | | |
9171 | 0 | if (!func) { |
9172 | 0 | ir_MERGE_WITH(cold_path); |
9173 | 0 | } |
9174 | 0 | zend_jit_start_reuse_ip(jit); |
9175 | |
|
9176 | 0 | if (zend_jit_needs_call_chain(call_info, b, op_array, ssa, ssa_op, opline, call_level, trace)) { |
9177 | 0 | if (!zend_jit_save_call_chain(jit, call_level)) { |
9178 | 0 | return 0; |
9179 | 0 | } |
9180 | 0 | } else { |
9181 | 0 | ZEND_ASSERT(call_level > 0); |
9182 | 0 | delayed_call_chain = true; |
9183 | 0 | jit->delayed_call_level = call_level; |
9184 | 0 | } |
9185 | | |
9186 | 0 | if (trace |
9187 | 0 | && trace->op == ZEND_JIT_TRACE_END |
9188 | 0 | && trace->stop >= ZEND_JIT_TRACE_STOP_INTERPRETER) { |
9189 | 0 | if (!zend_jit_set_ip(jit, opline + 1)) { |
9190 | 0 | return 0; |
9191 | 0 | } |
9192 | 0 | } |
9193 | | |
9194 | 0 | return 1; |
9195 | 0 | } |
9196 | | |
9197 | | static int zend_jit_init_static_method_call(zend_jit_ctx *jit, |
9198 | | const zend_op *opline, |
9199 | | uint32_t b, |
9200 | | const zend_op_array *op_array, |
9201 | | zend_ssa *ssa, |
9202 | | const zend_ssa_op *ssa_op, |
9203 | | int call_level, |
9204 | | zend_jit_trace_rec *trace, |
9205 | | int checked_stack) |
9206 | 0 | { |
9207 | 0 | zend_func_info *info = ZEND_FUNC_INFO(op_array); |
9208 | 0 | zend_call_info *call_info = NULL; |
9209 | 0 | zend_class_entry *ce; |
9210 | 0 | zend_function *func = NULL; |
9211 | 0 | ir_ref func_ref, func_ref2, scope_ref, scope_ref2, if_cached, cold_path, ref; |
9212 | 0 | ir_ref if_static = IR_UNUSED; |
9213 | |
|
9214 | 0 | if (info) { |
9215 | 0 | call_info = info->callee_info; |
9216 | 0 | while (call_info && call_info->caller_init_opline != opline) { |
9217 | 0 | call_info = call_info->next_callee; |
9218 | 0 | } |
9219 | 0 | if (call_info && call_info->callee_func && !call_info->is_prototype) { |
9220 | 0 | func = call_info->callee_func; |
9221 | 0 | } |
9222 | 0 | } |
9223 | |
|
9224 | 0 | ce = zend_get_known_class(op_array, opline, opline->op1_type, opline->op1); |
9225 | 0 | if (!func && ce && (opline->op1_type == IS_CONST || !(ce->ce_flags & ZEND_ACC_TRAIT))) { |
9226 | 0 | zval *zv = RT_CONSTANT(opline, opline->op2); |
9227 | 0 | zend_string *method_name; |
9228 | |
|
9229 | 0 | ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING); |
9230 | 0 | method_name = Z_STR_P(zv); |
9231 | 0 | zv = zend_hash_find(&ce->function_table, method_name); |
9232 | 0 | if (zv) { |
9233 | 0 | zend_function *fn = Z_PTR_P(zv); |
9234 | |
|
9235 | 0 | if (fn->common.scope == op_array->scope |
9236 | 0 | || (fn->common.fn_flags & ZEND_ACC_PUBLIC) |
9237 | 0 | || ((fn->common.fn_flags & ZEND_ACC_PROTECTED) |
9238 | 0 | && op_array->scope |
9239 | 0 | && instanceof_function_slow(op_array->scope, fn->common.scope))) { |
9240 | 0 | func = fn; |
9241 | 0 | } |
9242 | 0 | } |
9243 | 0 | } |
9244 | |
|
9245 | 0 | if (jit->delayed_call_level) { |
9246 | 0 | if (!zend_jit_save_call_chain(jit, jit->delayed_call_level)) { |
9247 | 0 | return 0; |
9248 | 0 | } |
9249 | 0 | } |
9250 | | |
9251 | | // JIT: fbc = CACHED_PTR(opline->result.num + sizeof(void*)); |
9252 | 0 | func_ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->result.num + sizeof(void*))); |
9253 | | |
9254 | | // JIT: if (fbc) |
9255 | 0 | if_cached = ir_IF(func_ref); |
9256 | 0 | ir_IF_FALSE_cold(if_cached); |
9257 | |
|
9258 | 0 | jit_SET_EX_OPLINE(jit, opline); |
9259 | 0 | scope_ref2 = ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_find_class_helper), jit_FP(jit)); |
9260 | 0 | ir_GUARD(scope_ref2, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
9261 | |
|
9262 | 0 | func_ref2 = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_find_static_method_helper), jit_FP(jit), scope_ref2); |
9263 | 0 | ir_GUARD(func_ref2, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
9264 | |
|
9265 | 0 | cold_path = ir_END(); |
9266 | |
|
9267 | 0 | ir_IF_TRUE(if_cached); |
9268 | 0 | if (ce && (ce->ce_flags & ZEND_ACC_IMMUTABLE) && (ce->ce_flags & ZEND_ACC_LINKED)) { |
9269 | 0 | scope_ref = ir_CONST_ADDR(ce); |
9270 | 0 | } else { |
9271 | 0 | scope_ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->result.num)); |
9272 | 0 | } |
9273 | |
|
9274 | 0 | ir_MERGE_2(cold_path, ir_END()); |
9275 | 0 | func_ref = ir_PHI_2(IR_ADDR, func_ref2, func_ref); |
9276 | 0 | scope_ref = ir_PHI_2(IR_ADDR, scope_ref2, scope_ref); |
9277 | |
|
9278 | 0 | if ((!func || zend_jit_may_be_modified(func, op_array)) |
9279 | 0 | && trace |
9280 | 0 | && trace->op == ZEND_JIT_TRACE_INIT_CALL |
9281 | 0 | && trace->func) { |
9282 | 0 | int32_t exit_point; |
9283 | 0 | const void *exit_addr; |
9284 | |
|
9285 | 0 | exit_point = zend_jit_trace_get_exit_point(opline, func ? ZEND_JIT_EXIT_INVALIDATE : 0); |
9286 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
9287 | 0 | if (!exit_addr) { |
9288 | 0 | return 0; |
9289 | 0 | } |
9290 | | |
9291 | | // jit->trace->exit_info[exit_point].poly_func_ref = func_ref; |
9292 | | // jit->trace->exit_info[exit_point].poly_this_ref = scope_ref; |
9293 | | |
9294 | 0 | func = (zend_function*)trace->func; |
9295 | |
|
9296 | 0 | if (!zend_jit_func_guard(jit, func_ref, func, exit_addr)) { |
9297 | 0 | return 0; |
9298 | 0 | } |
9299 | 0 | } |
9300 | | |
9301 | 0 | if (!func || !(func->common.fn_flags & ZEND_ACC_STATIC)) { |
9302 | 0 | if (!func) { |
9303 | | // JIT: if (fbc->common.fn_flags & ZEND_ACC_STATIC) { |
9304 | 0 | if_static = ir_IF(ir_AND_U32( |
9305 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_function, common.fn_flags))), |
9306 | 0 | ir_CONST_U32(ZEND_ACC_STATIC))); |
9307 | 0 | ir_IF_FALSE_cold(if_static); |
9308 | 0 | } |
9309 | |
|
9310 | 0 | jit_SET_EX_OPLINE(jit, opline); |
9311 | 0 | ref = ir_CALL_3(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_push_this_method_call_frame), |
9312 | 0 | scope_ref, |
9313 | 0 | func_ref, |
9314 | 0 | ir_CONST_U32(opline->extended_value)); |
9315 | 0 | ir_GUARD(ref, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
9316 | 0 | jit_STORE_IP(jit, ref); |
9317 | |
|
9318 | 0 | if (!func) { |
9319 | 0 | cold_path = ir_END(); |
9320 | 0 | ir_IF_TRUE(if_static); |
9321 | 0 | } |
9322 | 0 | } |
9323 | |
|
9324 | 0 | if (!func || (func->common.fn_flags & ZEND_ACC_STATIC)) { |
9325 | 0 | if (opline->op1_type == IS_UNUSED |
9326 | 0 | && ((opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_PARENT || |
9327 | 0 | (opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF)) { |
9328 | 0 | if (op_array->fn_flags & ZEND_ACC_STATIC) { |
9329 | 0 | scope_ref = ir_LOAD_A(jit_EX(This.value.ref)); |
9330 | 0 | } else if (op_array->fn_flags & ZEND_ACC_CLOSURE) { |
9331 | 0 | ir_ref if_object, values = IR_UNUSED; |
9332 | |
|
9333 | 0 | if_object = ir_IF(ir_EQ(jit_Z_TYPE_ref(jit, jit_EX(This)), ir_CONST_U8(IS_OBJECT))); |
9334 | 0 | ir_IF_TRUE(if_object); |
9335 | 0 | ir_END_PHI_list(values, |
9336 | 0 | ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(This.value.ref)), offsetof(zend_object, ce)))); |
9337 | 0 | ir_IF_FALSE(if_object); |
9338 | 0 | ir_END_PHI_list(values, ir_LOAD_A(jit_EX(This.value.ref))); |
9339 | 0 | ir_PHI_list(values); |
9340 | 0 | } else { |
9341 | 0 | scope_ref = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(This.value.ref)), offsetof(zend_object, ce))); |
9342 | 0 | } |
9343 | 0 | } |
9344 | 0 | if (!zend_jit_push_call_frame(jit, opline, op_array, func, false, false, checked_stack, func_ref, scope_ref)) { |
9345 | 0 | return 0; |
9346 | 0 | } |
9347 | | |
9348 | 0 | if (!func) { |
9349 | 0 | ir_MERGE_2(cold_path, ir_END()); |
9350 | 0 | } |
9351 | 0 | } |
9352 | | |
9353 | 0 | zend_jit_start_reuse_ip(jit); |
9354 | 0 | if (zend_jit_needs_call_chain(call_info, b, op_array, ssa, ssa_op, opline, call_level, trace)) { |
9355 | 0 | if (!zend_jit_save_call_chain(jit, call_level)) { |
9356 | 0 | return 0; |
9357 | 0 | } |
9358 | 0 | } else { |
9359 | 0 | ZEND_ASSERT(call_level > 0); |
9360 | 0 | jit->delayed_call_level = call_level; |
9361 | 0 | delayed_call_chain = true; |
9362 | 0 | } |
9363 | | |
9364 | 0 | if (trace |
9365 | 0 | && trace->op == ZEND_JIT_TRACE_END |
9366 | 0 | && trace->stop >= ZEND_JIT_TRACE_STOP_INTERPRETER) { |
9367 | 0 | if (!zend_jit_set_ip(jit, opline + 1)) { |
9368 | 0 | return 0; |
9369 | 0 | } |
9370 | 0 | } |
9371 | | |
9372 | 0 | return 1; |
9373 | 0 | } |
9374 | | |
9375 | | static int zend_jit_init_closure_call(zend_jit_ctx *jit, |
9376 | | const zend_op *opline, |
9377 | | uint32_t b, |
9378 | | const zend_op_array *op_array, |
9379 | | zend_ssa *ssa, |
9380 | | const zend_ssa_op *ssa_op, |
9381 | | int call_level, |
9382 | | zend_jit_trace_rec *trace, |
9383 | | int checked_stack) |
9384 | 0 | { |
9385 | 0 | zend_function *func = NULL; |
9386 | 0 | zend_jit_addr op2_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op2.var); |
9387 | 0 | ir_ref ref; |
9388 | |
|
9389 | 0 | ref = jit_Z_PTR(jit, op2_addr); |
9390 | |
|
9391 | 0 | if (ssa->var_info[ssa_op->op2_use].ce != zend_ce_closure |
9392 | 0 | && !(ssa->var_info[ssa_op->op2_use].type & MAY_BE_CLASS_GUARD)) { |
9393 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
9394 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
9395 | |
|
9396 | 0 | if (!exit_addr) { |
9397 | 0 | return 0; |
9398 | 0 | } |
9399 | | |
9400 | 0 | ir_GUARD( |
9401 | 0 | ir_EQ( |
9402 | 0 | ir_LOAD_A(ir_ADD_OFFSET(ref, offsetof(zend_object, ce))), |
9403 | 0 | ir_CONST_ADDR(zend_ce_closure)), |
9404 | 0 | ir_CONST_ADDR(exit_addr)); |
9405 | |
|
9406 | 0 | if (ssa->var_info && ssa_op->op2_use >= 0) { |
9407 | 0 | ssa->var_info[ssa_op->op2_use].type |= MAY_BE_CLASS_GUARD; |
9408 | 0 | ssa->var_info[ssa_op->op2_use].ce = zend_ce_closure; |
9409 | 0 | ssa->var_info[ssa_op->op2_use].is_instanceof = 0; |
9410 | 0 | } |
9411 | 0 | } |
9412 | | |
9413 | 0 | if (trace |
9414 | 0 | && trace->op == ZEND_JIT_TRACE_INIT_CALL |
9415 | 0 | && trace->func |
9416 | 0 | && trace->func->type == ZEND_USER_FUNCTION) { |
9417 | 0 | const zend_op *opcodes; |
9418 | 0 | int32_t exit_point; |
9419 | 0 | const void *exit_addr; |
9420 | |
|
9421 | 0 | func = (zend_function*)trace->func; |
9422 | 0 | opcodes = func->op_array.opcodes; |
9423 | 0 | exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_CLOSURE_CALL); |
9424 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
9425 | 0 | if (!exit_addr) { |
9426 | 0 | return 0; |
9427 | 0 | } |
9428 | | |
9429 | 0 | ir_GUARD( |
9430 | 0 | ir_EQ( |
9431 | 0 | ir_LOAD_A(ir_ADD_OFFSET(ref, offsetof(zend_closure, func.op_array.opcodes))), |
9432 | 0 | ir_CONST_ADDR(opcodes)), |
9433 | 0 | ir_CONST_ADDR(exit_addr)); |
9434 | 0 | } |
9435 | | |
9436 | 0 | if (jit->delayed_call_level) { |
9437 | 0 | if (!zend_jit_save_call_chain(jit, jit->delayed_call_level)) { |
9438 | 0 | return 0; |
9439 | 0 | } |
9440 | 0 | } |
9441 | | |
9442 | 0 | if (!zend_jit_push_call_frame(jit, opline, NULL, func, true, false, checked_stack, ref, IR_UNUSED)) { |
9443 | 0 | return 0; |
9444 | 0 | } |
9445 | | |
9446 | 0 | if (zend_jit_needs_call_chain(NULL, b, op_array, ssa, ssa_op, opline, call_level, trace)) { |
9447 | 0 | if (!zend_jit_save_call_chain(jit, call_level)) { |
9448 | 0 | return 0; |
9449 | 0 | } |
9450 | 0 | } else { |
9451 | 0 | ZEND_ASSERT(call_level > 0); |
9452 | 0 | delayed_call_chain = true; |
9453 | 0 | jit->delayed_call_level = call_level; |
9454 | 0 | } |
9455 | | |
9456 | 0 | if (trace |
9457 | 0 | && trace->op == ZEND_JIT_TRACE_END |
9458 | 0 | && trace->stop >= ZEND_JIT_TRACE_STOP_INTERPRETER) { |
9459 | 0 | if (!zend_jit_set_ip(jit, opline + 1)) { |
9460 | 0 | return 0; |
9461 | 0 | } |
9462 | 0 | } |
9463 | | |
9464 | 0 | return 1; |
9465 | 0 | } |
9466 | | |
9467 | | static int zend_jit_send_val(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr) |
9468 | 0 | { |
9469 | 0 | uint32_t arg_num = opline->op2.num; |
9470 | 0 | zend_jit_addr arg_addr; |
9471 | |
|
9472 | 0 | ZEND_ASSERT(opline->opcode == ZEND_SEND_VAL || arg_num <= MAX_ARG_FLAG_NUM); |
9473 | |
|
9474 | 0 | if (!zend_jit_reuse_ip(jit)) { |
9475 | 0 | return 0; |
9476 | 0 | } |
9477 | | |
9478 | 0 | if (opline->opcode == ZEND_SEND_VAL_EX) { |
9479 | 0 | uint32_t mask = ZEND_SEND_BY_REF << ((arg_num + 3) * 2); |
9480 | |
|
9481 | 0 | ZEND_ASSERT(arg_num <= MAX_ARG_FLAG_NUM); |
9482 | |
|
9483 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
9484 | 0 | && JIT_G(current_frame) |
9485 | 0 | && JIT_G(current_frame)->call |
9486 | 0 | && JIT_G(current_frame)->call->func) { |
9487 | 0 | if (ARG_MUST_BE_SENT_BY_REF(JIT_G(current_frame)->call->func, arg_num)) { |
9488 | | /* Don't generate code that always throws exception */ |
9489 | 0 | return 0; |
9490 | 0 | } |
9491 | 0 | } else { |
9492 | 0 | ir_ref cond = ir_AND_U32( |
9493 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(ir_LOAD_A(jit_RX(func)), offsetof(zend_function, quick_arg_flags))), |
9494 | 0 | ir_CONST_U32(mask)); |
9495 | |
|
9496 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
9497 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
9498 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
9499 | 0 | if (!exit_addr) { |
9500 | 0 | return 0; |
9501 | 0 | } |
9502 | 0 | ir_GUARD_NOT(cond, ir_CONST_ADDR(exit_addr)); |
9503 | 0 | } else { |
9504 | 0 | ir_ref if_pass_by_ref; |
9505 | |
|
9506 | 0 | if_pass_by_ref = ir_IF(cond); |
9507 | |
|
9508 | 0 | ir_IF_TRUE_cold(if_pass_by_ref); |
9509 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
9510 | | /* set type to avoid zval_ptr_dtor() on uninitialized value */ |
9511 | 0 | zend_jit_addr addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op1.var); |
9512 | 0 | jit_set_Z_TYPE_INFO(jit, addr, IS_UNDEF); |
9513 | 0 | } |
9514 | 0 | jit_SET_EX_OPLINE(jit, opline); |
9515 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_throw_cannot_pass_by_ref)); |
9516 | |
|
9517 | 0 | ir_IF_FALSE(if_pass_by_ref); |
9518 | 0 | } |
9519 | 0 | } |
9520 | 0 | } |
9521 | | |
9522 | 0 | arg_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, opline->result.var); |
9523 | |
|
9524 | 0 | if (opline->op1_type == IS_CONST) { |
9525 | 0 | zval *zv = RT_CONSTANT(opline, opline->op1); |
9526 | |
|
9527 | 0 | jit_ZVAL_COPY_CONST(jit, |
9528 | 0 | arg_addr, |
9529 | 0 | MAY_BE_ANY, MAY_BE_ANY, |
9530 | 0 | zv, true); |
9531 | 0 | } else { |
9532 | 0 | jit_ZVAL_COPY(jit, |
9533 | 0 | arg_addr, |
9534 | 0 | MAY_BE_ANY, |
9535 | 0 | op1_addr, op1_info, false); |
9536 | 0 | } |
9537 | |
|
9538 | 0 | return 1; |
9539 | 0 | } |
9540 | | |
9541 | | static int zend_jit_send_ref(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, uint32_t op1_info, int cold) |
9542 | 0 | { |
9543 | 0 | zend_jit_addr op1_addr, arg_addr, ref_addr; |
9544 | 0 | ir_ref ref_path = IR_UNUSED; |
9545 | |
|
9546 | 0 | op1_addr = OP1_ADDR(); |
9547 | 0 | arg_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, opline->result.var); |
9548 | |
|
9549 | 0 | if (!zend_jit_reuse_ip(jit)) { |
9550 | 0 | return 0; |
9551 | 0 | } |
9552 | | |
9553 | 0 | if (opline->op1_type == IS_VAR) { |
9554 | 0 | if (op1_info & MAY_BE_INDIRECT) { |
9555 | 0 | op1_addr = jit_ZVAL_INDIRECT_DEREF(jit, op1_addr); |
9556 | 0 | } |
9557 | 0 | } else if (opline->op1_type == IS_CV) { |
9558 | 0 | if (op1_info & MAY_BE_UNDEF) { |
9559 | 0 | if (op1_info & (MAY_BE_ANY|MAY_BE_REF)) { |
9560 | | // JIT: if (Z_TYPE_P(op1) == IS_UNDEF) |
9561 | 0 | ir_ref if_def = jit_if_not_Z_TYPE(jit, op1_addr, IS_UNDEF); |
9562 | 0 | ir_IF_FALSE(if_def); |
9563 | | // JIT: ZVAL_NULL(op1) |
9564 | 0 | jit_set_Z_TYPE_INFO(jit,op1_addr, IS_NULL); |
9565 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_def); |
9566 | 0 | } |
9567 | 0 | op1_info &= ~MAY_BE_UNDEF; |
9568 | 0 | op1_info |= MAY_BE_NULL; |
9569 | 0 | } |
9570 | 0 | } else { |
9571 | 0 | ZEND_UNREACHABLE(); |
9572 | 0 | } |
9573 | | |
9574 | 0 | if (op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) { |
9575 | 0 | ir_ref ref, ref2; |
9576 | |
|
9577 | 0 | if (op1_info & MAY_BE_REF) { |
9578 | 0 | ir_ref if_ref; |
9579 | | |
9580 | | // JIT: if (Z_TYPE_P(op1) == IS_UNDEF) |
9581 | 0 | if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_REFERENCE); |
9582 | 0 | ir_IF_TRUE(if_ref); |
9583 | | // JIT: ref = Z_PTR_P(op1) |
9584 | 0 | ref = jit_Z_PTR(jit, op1_addr); |
9585 | | // JIT: GC_ADDREF(ref) |
9586 | 0 | jit_GC_ADDREF(jit, ref); |
9587 | | // JIT: ZVAL_REFERENCE(arg, ref) |
9588 | 0 | jit_set_Z_PTR(jit, arg_addr, ref); |
9589 | 0 | jit_set_Z_TYPE_INFO(jit, arg_addr, IS_REFERENCE_EX); |
9590 | 0 | ref_path = ir_END(); |
9591 | 0 | ir_IF_FALSE(if_ref); |
9592 | 0 | } |
9593 | | |
9594 | | // JIT: ZVAL_NEW_REF(arg, varptr); |
9595 | | // JIT: ref = emalloc(sizeof(zend_reference)); |
9596 | 0 | ref = jit_EMALLOC(jit, sizeof(zend_reference), op_array, opline); |
9597 | | // JIT: GC_REFCOUNT(ref) = 2 |
9598 | 0 | jit_set_GC_REFCOUNT(jit, ref, 2); |
9599 | | // JIT: GC_TYPE(ref) = GC_REFERENCE |
9600 | 0 | ir_STORE(ir_ADD_OFFSET(ref, offsetof(zend_reference, gc.u.type_info)), ir_CONST_U32(GC_REFERENCE)); |
9601 | 0 | ir_STORE(ir_ADD_OFFSET(ref, offsetof(zend_reference, sources.ptr)), IR_NULL); |
9602 | 0 | ref2 = ir_ADD_OFFSET(ref, offsetof(zend_reference, val)); |
9603 | 0 | ref_addr = ZEND_ADDR_REF_ZVAL(ref2); |
9604 | | |
9605 | | // JIT: ZVAL_COPY_VALUE(&ref->val, op1) |
9606 | 0 | jit_ZVAL_COPY(jit, |
9607 | 0 | ref_addr, |
9608 | 0 | MAY_BE_ANY, |
9609 | 0 | op1_addr, op1_info, false); |
9610 | | |
9611 | | // JIT: ZVAL_REFERENCE(arg, ref) |
9612 | 0 | jit_set_Z_PTR(jit, op1_addr, ref); |
9613 | 0 | jit_set_Z_TYPE_INFO(jit, op1_addr, IS_REFERENCE_EX); |
9614 | | |
9615 | | // JIT: ZVAL_REFERENCE(arg, ref) |
9616 | 0 | jit_set_Z_PTR(jit, arg_addr, ref); |
9617 | 0 | jit_set_Z_TYPE_INFO(jit, arg_addr, IS_REFERENCE_EX); |
9618 | 0 | } |
9619 | |
|
9620 | 0 | if (ref_path) { |
9621 | 0 | ir_MERGE_WITH(ref_path); |
9622 | 0 | } |
9623 | |
|
9624 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
9625 | |
|
9626 | 0 | return 1; |
9627 | 0 | } |
9628 | | |
9629 | | static int zend_jit_send_var(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, uint32_t op1_info, zend_jit_addr op1_addr, zend_jit_addr op1_def_addr) |
9630 | 0 | { |
9631 | 0 | uint32_t arg_num = opline->op2.num; |
9632 | 0 | zend_jit_addr arg_addr; |
9633 | 0 | ir_ref end_inputs = IR_UNUSED; |
9634 | |
|
9635 | 0 | ZEND_ASSERT((opline->opcode != ZEND_SEND_VAR_EX && |
9636 | 0 | opline->opcode != ZEND_SEND_VAR_NO_REF_EX) || |
9637 | 0 | arg_num <= MAX_ARG_FLAG_NUM); |
9638 | |
|
9639 | 0 | arg_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, opline->result.var); |
9640 | |
|
9641 | 0 | if (!zend_jit_reuse_ip(jit)) { |
9642 | 0 | return 0; |
9643 | 0 | } |
9644 | | |
9645 | 0 | if (opline->opcode == ZEND_SEND_VAR_EX) { |
9646 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
9647 | 0 | && JIT_G(current_frame) |
9648 | 0 | && JIT_G(current_frame)->call |
9649 | 0 | && JIT_G(current_frame)->call->func) { |
9650 | 0 | if (ARG_SHOULD_BE_SENT_BY_REF(JIT_G(current_frame)->call->func, arg_num)) { |
9651 | 0 | if (!zend_jit_send_ref(jit, opline, op_array, op1_info, 0)) { |
9652 | 0 | return 0; |
9653 | 0 | } |
9654 | 0 | return 1; |
9655 | 0 | } |
9656 | 0 | } else { |
9657 | 0 | uint32_t mask = (ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF) << ((arg_num + 3) * 2); |
9658 | | |
9659 | | // JIT: if (RX->func->quick_arg_flags & mask) |
9660 | 0 | ir_ref if_send_by_ref = ir_IF(ir_AND_U32( |
9661 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(ir_LOAD_A(jit_RX(func)), offsetof(zend_function, quick_arg_flags))), |
9662 | 0 | ir_CONST_U32(mask))); |
9663 | 0 | ir_IF_TRUE_cold(if_send_by_ref); |
9664 | |
|
9665 | 0 | if (!zend_jit_send_ref(jit, opline, op_array, op1_info, 1)) { |
9666 | 0 | return 0; |
9667 | 0 | } |
9668 | | |
9669 | 0 | ir_END_list(end_inputs); |
9670 | 0 | ir_IF_FALSE(if_send_by_ref); |
9671 | 0 | } |
9672 | 0 | } else if (opline->opcode == ZEND_SEND_VAR_NO_REF_EX) { |
9673 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
9674 | 0 | && JIT_G(current_frame) |
9675 | 0 | && JIT_G(current_frame)->call |
9676 | 0 | && JIT_G(current_frame)->call->func) { |
9677 | 0 | if (ARG_SHOULD_BE_SENT_BY_REF(JIT_G(current_frame)->call->func, arg_num)) { |
9678 | | |
9679 | | // JIT: ZVAL_COPY_VALUE(arg, op1) |
9680 | 0 | jit_ZVAL_COPY(jit, |
9681 | 0 | arg_addr, |
9682 | 0 | MAY_BE_ANY, |
9683 | 0 | op1_addr, op1_info, false); |
9684 | |
|
9685 | 0 | if (!ARG_MAY_BE_SENT_BY_REF(JIT_G(current_frame)->call->func, arg_num)) { |
9686 | 0 | if (!(op1_info & MAY_BE_REF)) { |
9687 | | /* Don't generate code that always throws exception */ |
9688 | 0 | return 0; |
9689 | 0 | } else { |
9690 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
9691 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
9692 | 0 | if (!exit_addr) { |
9693 | 0 | return 0; |
9694 | 0 | } |
9695 | | |
9696 | | // JIT: if (Z_TYPE_P(op1) != IS_REFERENCE) |
9697 | 0 | ir_GUARD(ir_EQ(jit_Z_TYPE(jit, op1_addr), ir_CONST_U32(IS_REFERENCE)), |
9698 | 0 | ir_CONST_ADDR(exit_addr)); |
9699 | 0 | } |
9700 | 0 | } |
9701 | 0 | return 1; |
9702 | 0 | } |
9703 | 0 | } else { |
9704 | 0 | uint32_t mask = (ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF) << ((arg_num + 3) * 2); |
9705 | 0 | ir_ref func, if_send_by_ref, if_prefer_ref; |
9706 | | |
9707 | | // JIT: if (RX->func->quick_arg_flags & mask) |
9708 | 0 | func = ir_LOAD_A(jit_RX(func)); |
9709 | 0 | if_send_by_ref = ir_IF(ir_AND_U32( |
9710 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func, offsetof(zend_function, quick_arg_flags))), |
9711 | 0 | ir_CONST_U32(mask))); |
9712 | 0 | ir_IF_TRUE_cold(if_send_by_ref); |
9713 | |
|
9714 | 0 | mask = ZEND_SEND_PREFER_REF << ((arg_num + 3) * 2); |
9715 | | |
9716 | | // JIT: ZVAL_COPY_VALUE(arg, op1) |
9717 | 0 | jit_ZVAL_COPY(jit, |
9718 | 0 | arg_addr, |
9719 | 0 | MAY_BE_ANY, |
9720 | 0 | op1_addr, op1_info, false); |
9721 | |
|
9722 | 0 | if (op1_info & MAY_BE_REF) { |
9723 | 0 | ir_ref if_ref = jit_if_Z_TYPE(jit, arg_addr, IS_REFERENCE); |
9724 | 0 | ir_IF_TRUE(if_ref); |
9725 | 0 | ir_END_list(end_inputs); |
9726 | 0 | ir_IF_FALSE(if_ref); |
9727 | 0 | } |
9728 | | |
9729 | | // JIT: if (RX->func->quick_arg_flags & mask) |
9730 | 0 | if_prefer_ref = ir_IF(ir_AND_U32( |
9731 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func, offsetof(zend_function, quick_arg_flags))), |
9732 | 0 | ir_CONST_U32(mask))); |
9733 | 0 | ir_IF_TRUE(if_prefer_ref); |
9734 | 0 | ir_END_list(end_inputs); |
9735 | 0 | ir_IF_FALSE(if_prefer_ref); |
9736 | |
|
9737 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
9738 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
9739 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
9740 | 0 | if (!exit_addr) { |
9741 | 0 | return 0; |
9742 | 0 | } |
9743 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
9744 | 0 | } else { |
9745 | 0 | jit_SET_EX_OPLINE(jit, opline); |
9746 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_only_vars_by_reference), |
9747 | 0 | jit_ZVAL_ADDR(jit, arg_addr)); |
9748 | 0 | zend_jit_check_exception(jit); |
9749 | 0 | ir_END_list(end_inputs); |
9750 | 0 | } |
9751 | | |
9752 | 0 | ir_IF_FALSE(if_send_by_ref); |
9753 | 0 | } |
9754 | 0 | } else if (opline->opcode == ZEND_SEND_FUNC_ARG) { |
9755 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
9756 | 0 | && JIT_G(current_frame) |
9757 | 0 | && JIT_G(current_frame)->call |
9758 | 0 | && JIT_G(current_frame)->call->func) { |
9759 | 0 | if (ARG_SHOULD_BE_SENT_BY_REF(JIT_G(current_frame)->call->func, arg_num)) { |
9760 | 0 | if (!zend_jit_send_ref(jit, opline, op_array, op1_info, 0)) { |
9761 | 0 | return 0; |
9762 | 0 | } |
9763 | 0 | return 1; |
9764 | 0 | } |
9765 | 0 | } else { |
9766 | | // JIT: if (RX->This.u1.type_info & ZEND_CALL_SEND_ARG_BY_REF) |
9767 | 0 | ir_ref if_send_by_ref = ir_IF(ir_AND_U32( |
9768 | 0 | ir_LOAD_U32(jit_RX(This.u1.type_info)), |
9769 | 0 | ir_CONST_U32(ZEND_CALL_SEND_ARG_BY_REF))); |
9770 | 0 | ir_IF_TRUE_cold(if_send_by_ref); |
9771 | |
|
9772 | 0 | if (!zend_jit_send_ref(jit, opline, op_array, op1_info, 1)) { |
9773 | 0 | return 0; |
9774 | 0 | } |
9775 | | |
9776 | 0 | ir_END_list(end_inputs); |
9777 | 0 | ir_IF_FALSE(if_send_by_ref); |
9778 | 0 | } |
9779 | 0 | } |
9780 | | |
9781 | 0 | if (op1_info & MAY_BE_UNDEF) { |
9782 | 0 | ir_ref ref, if_def = IR_UNUSED; |
9783 | |
|
9784 | 0 | if (op1_info & (MAY_BE_ANY|MAY_BE_REF)) { |
9785 | 0 | if_def = jit_if_not_Z_TYPE(jit, op1_addr, IS_UNDEF); |
9786 | 0 | ir_IF_FALSE_cold(if_def); |
9787 | 0 | } |
9788 | | |
9789 | | // JIT: zend_jit_undefined_op_helper(opline->op1.var) |
9790 | 0 | jit_SET_EX_OPLINE(jit, opline); |
9791 | 0 | ref = ir_CALL_1(IR_I32, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), |
9792 | 0 | ir_CONST_U32(opline->op1.var)); |
9793 | | |
9794 | | // JIT: ZVAL_NULL(arg) |
9795 | 0 | jit_set_Z_TYPE_INFO(jit, arg_addr, IS_NULL); |
9796 | | |
9797 | | // JIT: check_exception |
9798 | 0 | ir_GUARD(ref, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
9799 | |
|
9800 | 0 | if (op1_info & (MAY_BE_ANY|MAY_BE_REF)) { |
9801 | 0 | ir_END_list(end_inputs); |
9802 | 0 | ir_IF_TRUE(if_def); |
9803 | 0 | } else { |
9804 | 0 | if (end_inputs) { |
9805 | 0 | ir_END_list(end_inputs); |
9806 | 0 | ir_MERGE_list(end_inputs); |
9807 | 0 | } |
9808 | 0 | return 1; |
9809 | 0 | } |
9810 | 0 | } |
9811 | | |
9812 | 0 | if (opline->opcode == ZEND_SEND_VAR_NO_REF) { |
9813 | | // JIT: ZVAL_COPY_VALUE(arg, op1) |
9814 | 0 | jit_ZVAL_COPY(jit, |
9815 | 0 | arg_addr, |
9816 | 0 | MAY_BE_ANY, |
9817 | 0 | op1_addr, op1_info, false); |
9818 | 0 | if (op1_info & MAY_BE_REF) { |
9819 | | // JIT: if (Z_TYPE_P(arg) == IS_REFERENCE) |
9820 | 0 | ir_ref if_ref = jit_if_Z_TYPE(jit, arg_addr, IS_REFERENCE); |
9821 | 0 | ir_IF_TRUE(if_ref); |
9822 | 0 | ir_END_list(end_inputs); |
9823 | 0 | ir_IF_FALSE(if_ref); |
9824 | 0 | } |
9825 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
9826 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
9827 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
9828 | 0 | if (!exit_addr) { |
9829 | 0 | return 0; |
9830 | 0 | } |
9831 | 0 | ir_GUARD(IR_FALSE, ir_CONST_ADDR(exit_addr)); |
9832 | 0 | } else { |
9833 | 0 | jit_SET_EX_OPLINE(jit, opline); |
9834 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_only_vars_by_reference), |
9835 | 0 | jit_ZVAL_ADDR(jit, arg_addr)); |
9836 | 0 | zend_jit_check_exception(jit); |
9837 | 0 | } |
9838 | 0 | } else { |
9839 | 0 | if (op1_info & MAY_BE_REF) { |
9840 | 0 | if (opline->op1_type == IS_CV) { |
9841 | 0 | ir_ref ref; |
9842 | | |
9843 | | // JIT: ZVAL_DEREF(op1) |
9844 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
9845 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
9846 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
9847 | | |
9848 | | // JIT: ZVAL_COPY(arg, op1) |
9849 | 0 | jit_ZVAL_COPY(jit, |
9850 | 0 | arg_addr, |
9851 | 0 | MAY_BE_ANY, |
9852 | 0 | op1_addr, op1_info, true); |
9853 | 0 | } else { |
9854 | 0 | ir_ref if_ref, ref, ref2, refcount, if_not_zero, if_refcounted; |
9855 | 0 | zend_jit_addr ref_addr; |
9856 | | |
9857 | | // JIT: if (Z_TYPE_P(op1) == IS_REFERENCE) |
9858 | 0 | if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_REFERENCE); |
9859 | 0 | ir_IF_TRUE_cold(if_ref); |
9860 | | |
9861 | | // JIT: ref = Z_COUNTED_P(op1); |
9862 | 0 | ref = jit_Z_PTR(jit, op1_addr); |
9863 | 0 | ref2 = ir_ADD_OFFSET(ref, offsetof(zend_reference, val)); |
9864 | 0 | ref_addr = ZEND_ADDR_REF_ZVAL(ref2); |
9865 | | |
9866 | | // JIT: ZVAL_COPY_VALUE(arg, op1); |
9867 | 0 | jit_ZVAL_COPY(jit, |
9868 | 0 | arg_addr, |
9869 | 0 | MAY_BE_ANY, |
9870 | 0 | ref_addr, op1_info, false); |
9871 | | |
9872 | | // JIT: if (GC_DELREF(ref) != 0) |
9873 | 0 | refcount = jit_GC_DELREF(jit, ref); |
9874 | 0 | if_not_zero = ir_IF(refcount); |
9875 | 0 | ir_IF_TRUE(if_not_zero); |
9876 | | |
9877 | | // JIT: if (Z_REFCOUNTED_P(arg) |
9878 | 0 | if_refcounted = jit_if_REFCOUNTED(jit, arg_addr); |
9879 | 0 | ir_IF_TRUE(if_refcounted); |
9880 | | // JIT: Z_ADDREF_P(arg) |
9881 | 0 | jit_GC_ADDREF(jit, jit_Z_PTR(jit, arg_addr)); |
9882 | 0 | ir_END_list(end_inputs); |
9883 | 0 | ir_IF_FALSE(if_refcounted); |
9884 | 0 | ir_END_list(end_inputs); |
9885 | |
|
9886 | 0 | ir_IF_FALSE(if_not_zero); |
9887 | | |
9888 | | // JIT: efree(ref) |
9889 | 0 | jit_EFREE(jit, ref, sizeof(zend_reference), op_array, opline); |
9890 | 0 | ir_END_list(end_inputs); |
9891 | |
|
9892 | 0 | ir_IF_FALSE(if_ref); |
9893 | | |
9894 | | // JIT: ZVAL_COPY_VALUE(arg, op1); |
9895 | 0 | jit_ZVAL_COPY(jit, |
9896 | 0 | arg_addr, |
9897 | 0 | MAY_BE_ANY, |
9898 | 0 | op1_addr, op1_info, false); |
9899 | 0 | } |
9900 | 0 | } else { |
9901 | 0 | if (op1_addr != op1_def_addr) { |
9902 | 0 | if (!zend_jit_update_regs(jit, opline->op1.var, op1_addr, op1_def_addr, op1_info)) { |
9903 | 0 | return 0; |
9904 | 0 | } |
9905 | 0 | if (Z_MODE(op1_def_addr) == IS_REG && Z_MODE(op1_addr) != IS_REG) { |
9906 | 0 | op1_addr = op1_def_addr; |
9907 | 0 | } |
9908 | 0 | } |
9909 | | |
9910 | | // JIT: ZVAL_COPY_VALUE(arg, op1) |
9911 | 0 | jit_ZVAL_COPY(jit, |
9912 | 0 | arg_addr, |
9913 | 0 | MAY_BE_ANY, |
9914 | 0 | op1_addr, op1_info, opline->op1_type == IS_CV); |
9915 | 0 | } |
9916 | 0 | } |
9917 | | |
9918 | 0 | if (end_inputs) { |
9919 | 0 | ir_END_list(end_inputs); |
9920 | 0 | ir_MERGE_list(end_inputs); |
9921 | 0 | } |
9922 | |
|
9923 | 0 | return 1; |
9924 | 0 | } |
9925 | | |
9926 | | static int zend_jit_check_func_arg(zend_jit_ctx *jit, const zend_op *opline) |
9927 | 0 | { |
9928 | 0 | uint32_t arg_num = opline->op2.num; |
9929 | 0 | ir_ref ref; |
9930 | |
|
9931 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
9932 | 0 | && JIT_G(current_frame) |
9933 | 0 | && JIT_G(current_frame)->call |
9934 | 0 | && JIT_G(current_frame)->call->func) { |
9935 | 0 | if (ARG_SHOULD_BE_SENT_BY_REF(JIT_G(current_frame)->call->func, arg_num)) { |
9936 | 0 | if (!TRACE_FRAME_IS_LAST_SEND_BY_REF(JIT_G(current_frame)->call)) { |
9937 | 0 | TRACE_FRAME_SET_LAST_SEND_BY_REF(JIT_G(current_frame)->call); |
9938 | | // JIT: ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_SEND_ARG_BY_REF); |
9939 | 0 | if (jit->reuse_ip) { |
9940 | 0 | ref = jit_IP(jit); |
9941 | 0 | } else { |
9942 | 0 | ref = ir_LOAD_A(jit_EX(call)); |
9943 | 0 | } |
9944 | 0 | ref = jit_CALL(ref, This.u1.type_info); |
9945 | 0 | ir_STORE(ref, ir_OR_U32(ir_LOAD_U32(ref), ir_CONST_U32(ZEND_CALL_SEND_ARG_BY_REF))); |
9946 | 0 | } |
9947 | 0 | } else { |
9948 | 0 | if (!TRACE_FRAME_IS_LAST_SEND_BY_VAL(JIT_G(current_frame)->call)) { |
9949 | 0 | TRACE_FRAME_SET_LAST_SEND_BY_VAL(JIT_G(current_frame)->call); |
9950 | | // JIT: ZEND_DEL_CALL_FLAG(EX(call), ZEND_CALL_SEND_ARG_BY_REF); |
9951 | 0 | if (jit->reuse_ip) { |
9952 | 0 | ref = jit_IP(jit); |
9953 | 0 | } else { |
9954 | 0 | ref = ir_LOAD_A(jit_EX(call)); |
9955 | 0 | } |
9956 | 0 | ref = jit_CALL(ref, This.u1.type_info); |
9957 | 0 | ir_STORE(ref, ir_AND_U32(ir_LOAD_U32(ref), ir_CONST_U32(~ZEND_CALL_SEND_ARG_BY_REF))); |
9958 | 0 | } |
9959 | 0 | } |
9960 | 0 | } else { |
9961 | | // JIT: if (QUICK_ARG_SHOULD_BE_SENT_BY_REF(EX(call)->func, arg_num)) { |
9962 | 0 | uint32_t mask = (ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF) << ((arg_num + 3) * 2); |
9963 | 0 | ir_ref rx, if_ref, cold_path; |
9964 | |
|
9965 | 0 | if (!zend_jit_reuse_ip(jit)) { |
9966 | 0 | return 0; |
9967 | 0 | } |
9968 | | |
9969 | 0 | rx = jit_IP(jit); |
9970 | |
|
9971 | 0 | ref = ir_AND_U32( |
9972 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(ir_LOAD_A(jit_CALL(rx, func)), offsetof(zend_function, quick_arg_flags))), |
9973 | 0 | ir_CONST_U32(mask)); |
9974 | 0 | if_ref = ir_IF(ref); |
9975 | 0 | ir_IF_TRUE_cold(if_ref); |
9976 | | |
9977 | | // JIT: ZEND_ADD_CALL_FLAG(EX(call), ZEND_CALL_SEND_ARG_BY_REF); |
9978 | 0 | ref = jit_CALL(rx, This.u1.type_info); |
9979 | 0 | ir_STORE(ref, ir_OR_U32(ir_LOAD_U32(ref), ir_CONST_U32(ZEND_CALL_SEND_ARG_BY_REF))); |
9980 | |
|
9981 | 0 | cold_path = ir_END(); |
9982 | 0 | ir_IF_FALSE(if_ref); |
9983 | | |
9984 | | // JIT: ZEND_DEL_CALL_FLAG(EX(call), ZEND_CALL_SEND_ARG_BY_REF); |
9985 | 0 | ref = jit_CALL(rx, This.u1.type_info); |
9986 | 0 | ir_STORE(ref, ir_AND_U32(ir_LOAD_U32(ref), ir_CONST_U32(~ZEND_CALL_SEND_ARG_BY_REF))); |
9987 | |
|
9988 | 0 | ir_MERGE_WITH(cold_path); |
9989 | 0 | } |
9990 | | |
9991 | 0 | return 1; |
9992 | 0 | } |
9993 | | |
9994 | | static int zend_jit_check_undef_args(zend_jit_ctx *jit, const zend_op *opline) |
9995 | 0 | { |
9996 | 0 | ir_ref call, if_may_have_undef, ret; |
9997 | |
|
9998 | 0 | if (jit->reuse_ip) { |
9999 | 0 | call = jit_IP(jit); |
10000 | 0 | } else { |
10001 | 0 | call = ir_LOAD_A(jit_EX(call)); |
10002 | 0 | } |
10003 | |
|
10004 | 0 | if_may_have_undef = ir_IF(ir_AND_U8( |
10005 | 0 | ir_LOAD_U8(ir_ADD_OFFSET(call, offsetof(zend_execute_data, This.u1.type_info) + 3)), |
10006 | 0 | ir_CONST_U8(ZEND_CALL_MAY_HAVE_UNDEF >> 24))); |
10007 | |
|
10008 | 0 | ir_IF_TRUE_cold(if_may_have_undef); |
10009 | 0 | jit_SET_EX_OPLINE(jit, opline); |
10010 | 0 | ret = ir_CALL_1(IR_I32, ir_CONST_FC_FUNC(zend_handle_undef_args), call); |
10011 | 0 | ir_GUARD_NOT(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
10012 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_may_have_undef); |
10013 | |
|
10014 | 0 | return 1; |
10015 | 0 | } |
10016 | | |
10017 | | static int zend_jit_do_fcall(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, zend_ssa *ssa, int call_level, unsigned int next_block, zend_jit_trace_rec *trace) |
10018 | 0 | { |
10019 | 0 | zend_func_info *info = ZEND_FUNC_INFO(op_array); |
10020 | 0 | zend_call_info *call_info = NULL; |
10021 | 0 | const zend_function *func = NULL; |
10022 | 0 | uint32_t i; |
10023 | 0 | uint32_t call_num_args = 0; |
10024 | 0 | bool unknown_num_args = false; |
10025 | 0 | const void *exit_addr = NULL; |
10026 | 0 | const zend_op *prev_opline; |
10027 | 0 | ir_ref rx, func_ref = IR_UNUSED, if_user = IR_UNUSED, user_path = IR_UNUSED; |
10028 | |
|
10029 | 0 | prev_opline = opline - 1; |
10030 | 0 | while (prev_opline->opcode == ZEND_EXT_FCALL_BEGIN || prev_opline->opcode == ZEND_TICKS) { |
10031 | 0 | prev_opline--; |
10032 | 0 | } |
10033 | 0 | if (prev_opline->opcode == ZEND_SEND_UNPACK || prev_opline->opcode == ZEND_SEND_ARRAY || |
10034 | 0 | prev_opline->opcode == ZEND_CHECK_UNDEF_ARGS) { |
10035 | 0 | unknown_num_args = true; |
10036 | 0 | } |
10037 | |
|
10038 | 0 | if (info) { |
10039 | 0 | call_info = info->callee_info; |
10040 | 0 | while (call_info && call_info->caller_call_opline != opline) { |
10041 | 0 | call_info = call_info->next_callee; |
10042 | 0 | } |
10043 | 0 | if (call_info && call_info->callee_func && !call_info->is_prototype) { |
10044 | 0 | func = call_info->callee_func; |
10045 | 0 | } |
10046 | 0 | if ((op_array->fn_flags & ZEND_ACC_TRAIT_CLONE) |
10047 | 0 | && (!JIT_G(current_frame) |
10048 | 0 | || !JIT_G(current_frame)->call |
10049 | 0 | || !JIT_G(current_frame)->call->func)) { |
10050 | 0 | call_info = NULL; func = NULL; /* megamorphic call from trait */ |
10051 | 0 | } |
10052 | 0 | } |
10053 | 0 | if (!func) { |
10054 | | /* resolve function at run time */ |
10055 | 0 | } else if (func->type == ZEND_USER_FUNCTION) { |
10056 | 0 | ZEND_ASSERT(opline->opcode != ZEND_DO_ICALL); |
10057 | 0 | call_num_args = call_info->num_args; |
10058 | 0 | } else if (func->type == ZEND_INTERNAL_FUNCTION) { |
10059 | 0 | ZEND_ASSERT(opline->opcode != ZEND_DO_UCALL); |
10060 | 0 | call_num_args = call_info->num_args; |
10061 | 0 | } else { |
10062 | 0 | ZEND_UNREACHABLE(); |
10063 | 0 | } |
10064 | | |
10065 | 0 | if (trace && !func) { |
10066 | 0 | if (trace->op == ZEND_JIT_TRACE_DO_ICALL) { |
10067 | 0 | ZEND_ASSERT(!trace->func || trace->func->type == ZEND_INTERNAL_FUNCTION); |
10068 | 0 | #ifndef ZEND_WIN32 |
10069 | | // TODO: ASLR may cause different addresses in different workers ??? |
10070 | 0 | func = trace->func; |
10071 | 0 | if (JIT_G(current_frame) && |
10072 | 0 | JIT_G(current_frame)->call && |
10073 | 0 | TRACE_FRAME_NUM_ARGS(JIT_G(current_frame)->call) >= 0) { |
10074 | 0 | call_num_args = TRACE_FRAME_NUM_ARGS(JIT_G(current_frame)->call); |
10075 | 0 | } else { |
10076 | 0 | unknown_num_args = true; |
10077 | 0 | } |
10078 | 0 | #endif |
10079 | 0 | } else if (trace->op == ZEND_JIT_TRACE_ENTER) { |
10080 | 0 | ZEND_ASSERT(trace->func->type == ZEND_USER_FUNCTION); |
10081 | 0 | if (zend_accel_in_shm(trace->func->op_array.opcodes)) { |
10082 | 0 | func = trace->func; |
10083 | 0 | if (JIT_G(current_frame) && |
10084 | 0 | JIT_G(current_frame)->call && |
10085 | 0 | TRACE_FRAME_NUM_ARGS(JIT_G(current_frame)->call) >= 0) { |
10086 | 0 | call_num_args = TRACE_FRAME_NUM_ARGS(JIT_G(current_frame)->call); |
10087 | 0 | } else { |
10088 | 0 | unknown_num_args = true; |
10089 | 0 | } |
10090 | 0 | } |
10091 | 0 | } |
10092 | 0 | } |
10093 | |
|
10094 | 0 | bool may_have_extra_named_params = |
10095 | 0 | opline->extended_value == ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS && |
10096 | 0 | (!func || func->common.fn_flags & ZEND_ACC_VARIADIC); |
10097 | |
|
10098 | 0 | if (!jit->reuse_ip) { |
10099 | 0 | zend_jit_start_reuse_ip(jit); |
10100 | | // JIT: call = EX(call); |
10101 | 0 | jit_STORE_IP(jit, ir_LOAD_A(jit_EX(call))); |
10102 | 0 | } |
10103 | 0 | rx = jit_IP(jit); |
10104 | 0 | zend_jit_stop_reuse_ip(jit); |
10105 | |
|
10106 | 0 | jit_SET_EX_OPLINE(jit, opline); |
10107 | |
|
10108 | 0 | if (opline->opcode == ZEND_DO_FCALL || opline->opcode == ZEND_DO_FCALL_BY_NAME) { |
10109 | 0 | if (!func) { |
10110 | 0 | if (trace) { |
10111 | 0 | uint32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
10112 | |
|
10113 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
10114 | 0 | if (!exit_addr) { |
10115 | 0 | return 0; |
10116 | 0 | } |
10117 | | |
10118 | 0 | func_ref = ir_LOAD_A(jit_CALL(rx, func)); |
10119 | 0 | ir_GUARD_NOT( |
10120 | 0 | ir_AND_U32( |
10121 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, fn_flags))), |
10122 | 0 | ir_CONST_U32(ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD)), |
10123 | 0 | ir_CONST_ADDR(exit_addr)); |
10124 | 0 | } |
10125 | 0 | } |
10126 | 0 | } |
10127 | | |
10128 | 0 | if (!jit->delayed_call_level) { |
10129 | | // JIT: EX(call) = call->prev_execute_data; |
10130 | 0 | ir_STORE(jit_EX(call), |
10131 | 0 | (call_level == 1) ? IR_NULL : ir_LOAD_A(jit_CALL(rx, prev_execute_data))); |
10132 | 0 | } |
10133 | 0 | delayed_call_chain = false; |
10134 | 0 | jit->delayed_call_level = 0; |
10135 | | |
10136 | | // JIT: call->prev_execute_data = execute_data; |
10137 | 0 | ir_STORE(jit_CALL(rx, prev_execute_data), jit_FP(jit)); |
10138 | |
|
10139 | 0 | if (!func) { |
10140 | 0 | if (!func_ref) { |
10141 | 0 | func_ref = ir_LOAD_A(jit_CALL(rx, func)); |
10142 | 0 | } |
10143 | 0 | } |
10144 | |
|
10145 | 0 | if (opline->opcode == ZEND_DO_FCALL || opline->opcode == ZEND_DO_FCALL_BY_NAME) { |
10146 | 0 | if (!func) { |
10147 | 0 | if (!trace) { |
10148 | 0 | ir_ref if_deprecated_nodiscard, ret; |
10149 | |
|
10150 | 0 | uint32_t no_discard = RETURN_VALUE_USED(opline) ? 0 : ZEND_ACC_NODISCARD; |
10151 | |
|
10152 | 0 | if_deprecated_nodiscard = ir_IF(ir_AND_U32( |
10153 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, fn_flags))), |
10154 | 0 | ir_CONST_U32(ZEND_ACC_DEPRECATED|no_discard))); |
10155 | 0 | ir_IF_TRUE_cold(if_deprecated_nodiscard); |
10156 | |
|
10157 | 0 | ir_ref helper = ir_CONST_FC_FUNC(no_discard ? zend_jit_deprecated_nodiscard_helper : zend_jit_deprecated_helper); |
10158 | 0 | if (GCC_GLOBAL_REGS) { |
10159 | 0 | ret = ir_CALL(IR_BOOL, helper); |
10160 | 0 | } else { |
10161 | 0 | ret = ir_CALL_1(IR_BOOL, helper, rx); |
10162 | 0 | } |
10163 | 0 | ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
10164 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_deprecated_nodiscard); |
10165 | 0 | } |
10166 | 0 | } else { |
10167 | 0 | if (func->common.fn_flags & ZEND_ACC_DEPRECATED) { |
10168 | 0 | ir_ref ret; |
10169 | |
|
10170 | 0 | if (GCC_GLOBAL_REGS) { |
10171 | 0 | ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper)); |
10172 | 0 | } else { |
10173 | 0 | ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_deprecated_helper), rx); |
10174 | 0 | } |
10175 | 0 | ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
10176 | 0 | } |
10177 | |
|
10178 | 0 | if ((func->common.fn_flags & ZEND_ACC_NODISCARD) && !RETURN_VALUE_USED(opline)) { |
10179 | 0 | ir_ref ret; |
10180 | |
|
10181 | 0 | if (GCC_GLOBAL_REGS) { |
10182 | 0 | ret = ir_CALL(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper)); |
10183 | 0 | } else { |
10184 | 0 | ret = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_nodiscard_helper), rx); |
10185 | 0 | } |
10186 | 0 | ir_GUARD(ret, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
10187 | 0 | } |
10188 | 0 | } |
10189 | 0 | } |
10190 | |
|
10191 | 0 | if (!func |
10192 | 0 | && opline->opcode != ZEND_DO_UCALL |
10193 | 0 | && opline->opcode != ZEND_DO_ICALL) { |
10194 | 0 | ir_ref type_ref = ir_LOAD_U8(ir_ADD_OFFSET(func_ref, offsetof(zend_function, type))); |
10195 | 0 | if_user = ir_IF(ir_EQ(type_ref, ir_CONST_U8(ZEND_USER_FUNCTION))); |
10196 | 0 | ir_IF_TRUE(if_user); |
10197 | 0 | } |
10198 | |
|
10199 | 0 | if ((!func || func->type == ZEND_USER_FUNCTION) |
10200 | 0 | && opline->opcode != ZEND_DO_ICALL) { |
10201 | 0 | bool recursive_call_through_jmp = false; |
10202 | 0 | uint32_t num_args = 0; |
10203 | | |
10204 | | // JIT: EX(call) = NULL; |
10205 | 0 | ir_STORE(jit_CALL(rx, call), IR_NULL); |
10206 | | |
10207 | | // JIT: EX(return_value) = RETURN_VALUE_USED(opline) ? EX_VAR(opline->result.var) : 0; |
10208 | 0 | ir_STORE(jit_CALL(rx, return_value), |
10209 | 0 | RETURN_VALUE_USED(opline) ? |
10210 | 0 | jit_ZVAL_ADDR(jit, ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var)) : |
10211 | 0 | IR_NULL); |
10212 | | |
10213 | | // JIT: EX_LOAD_RUN_TIME_CACHE(op_array); |
10214 | 0 | if (!func || func->op_array.cache_size) { |
10215 | 0 | ir_ref run_time_cache; |
10216 | |
|
10217 | 0 | if (func && op_array == &func->op_array) { |
10218 | | /* recursive call */ |
10219 | 0 | run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
10220 | 0 | } else if (func |
10221 | 0 | && !(func->op_array.fn_flags & ZEND_ACC_CLOSURE) |
10222 | 0 | && ZEND_MAP_PTR_IS_OFFSET(func->op_array.run_time_cache)) { |
10223 | 0 | run_time_cache = ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_CG(map_ptr_base)), |
10224 | 0 | (uintptr_t)ZEND_MAP_PTR(func->op_array.run_time_cache))); |
10225 | 0 | } else if ((func && (func->op_array.fn_flags & ZEND_ACC_CLOSURE)) || |
10226 | 0 | (JIT_G(current_frame) && |
10227 | 0 | JIT_G(current_frame)->call && |
10228 | 0 | TRACE_FRAME_IS_CLOSURE_CALL(JIT_G(current_frame)->call))) { |
10229 | | /* Closures always use direct pointers */ |
10230 | 0 | ir_ref local_func_ref = func_ref ? func_ref : ir_LOAD_A(jit_CALL(rx, func)); |
10231 | |
|
10232 | 0 | run_time_cache = ir_LOAD_A(ir_ADD_OFFSET(local_func_ref, offsetof(zend_op_array, run_time_cache__ptr))); |
10233 | 0 | } else { |
10234 | 0 | ir_ref if_odd, run_time_cache2; |
10235 | 0 | ir_ref local_func_ref = func_ref ? func_ref : ir_LOAD_A(jit_CALL(rx, func)); |
10236 | |
|
10237 | 0 | run_time_cache = ir_LOAD_A(ir_ADD_OFFSET(local_func_ref, offsetof(zend_op_array, run_time_cache__ptr))); |
10238 | 0 | if_odd = ir_IF(ir_AND_A(run_time_cache, ir_CONST_ADDR(1))); |
10239 | 0 | ir_IF_TRUE(if_odd); |
10240 | |
|
10241 | 0 | run_time_cache2 = ir_LOAD_A(ir_ADD_A(run_time_cache, ir_LOAD_A(jit_CG(map_ptr_base)))); |
10242 | |
|
10243 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_odd); |
10244 | 0 | run_time_cache = ir_PHI_2(IR_ADDR, run_time_cache2, run_time_cache); |
10245 | 0 | } |
10246 | |
|
10247 | 0 | ir_STORE(jit_CALL(rx, run_time_cache), run_time_cache); |
10248 | 0 | } |
10249 | | |
10250 | | // JIT: EG(current_execute_data) = execute_data = call; |
10251 | 0 | ir_STORE(jit_EG(current_execute_data), rx); |
10252 | 0 | jit_STORE_FP(jit, rx); |
10253 | | |
10254 | | // JIT: opline = op_array->opcodes; |
10255 | 0 | if (func && !unknown_num_args) { |
10256 | |
|
10257 | 0 | for (i = call_num_args; i < func->op_array.last_var; i++) { |
10258 | 0 | uint32_t n = EX_NUM_TO_VAR(i); |
10259 | 0 | zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, n); |
10260 | |
|
10261 | 0 | jit_set_Z_TYPE_INFO_ex(jit, var_addr, ir_CONST_U32(IS_UNDEF)); |
10262 | 0 | } |
10263 | |
|
10264 | 0 | if (call_num_args <= func->op_array.num_args) { |
10265 | 0 | if (!trace || (trace->op == ZEND_JIT_TRACE_END |
10266 | 0 | && trace->stop >= ZEND_JIT_TRACE_STOP_INTERPRETER)) { |
10267 | 0 | if ((func->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) != 0) { |
10268 | 0 | if (trace) { |
10269 | 0 | num_args = 0; |
10270 | 0 | } else if (call_info) { |
10271 | 0 | num_args = skip_valid_arguments(op_array, ssa, call_info); |
10272 | 0 | } else { |
10273 | 0 | num_args = call_num_args; |
10274 | 0 | } |
10275 | 0 | } else { |
10276 | 0 | num_args = call_num_args; |
10277 | 0 | } |
10278 | 0 | if (zend_accel_in_shm(func->op_array.opcodes)) { |
10279 | 0 | jit_LOAD_IP_ADDR(jit, func->op_array.opcodes + num_args); |
10280 | 0 | } else { |
10281 | 0 | if (!func_ref) { |
10282 | 0 | func_ref = ir_LOAD_A(jit_CALL(rx, func)); |
10283 | 0 | } |
10284 | 0 | ir_ref ip = ir_LOAD_A(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, opcodes))); |
10285 | 0 | if (num_args) { |
10286 | 0 | ip = ir_ADD_OFFSET(ip, num_args * sizeof(zend_op)); |
10287 | 0 | } |
10288 | 0 | jit_STORE_IP(jit, ip); |
10289 | 0 | } |
10290 | |
|
10291 | 0 | if (!trace && op_array == &func->op_array && call_num_args >= op_array->required_num_args) { |
10292 | | /* recursive call */ |
10293 | 0 | recursive_call_through_jmp = true; |
10294 | 0 | } |
10295 | 0 | } |
10296 | 0 | } else { |
10297 | 0 | ir_ref helper; |
10298 | 0 | if (!trace || (trace->op == ZEND_JIT_TRACE_END |
10299 | 0 | && trace->stop >= ZEND_JIT_TRACE_STOP_INTERPRETER)) { |
10300 | 0 | ir_ref ip; |
10301 | |
|
10302 | 0 | if (zend_accel_in_shm(func->op_array.opcodes)) { |
10303 | 0 | ip = ir_CONST_ADDR(func->op_array.opcodes); |
10304 | 0 | } else { |
10305 | 0 | if (!func_ref) { |
10306 | 0 | func_ref = ir_LOAD_A(jit_CALL(rx, func)); |
10307 | 0 | } |
10308 | 0 | ip = ir_LOAD_A(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, opcodes))); |
10309 | 0 | } |
10310 | 0 | jit_STORE_IP(jit, ip); |
10311 | 0 | helper = ir_CONST_FC_FUNC(zend_jit_copy_extra_args_helper); |
10312 | 0 | } else { |
10313 | 0 | helper = ir_CONST_FC_FUNC(zend_jit_copy_extra_args_helper_no_skip_recv); |
10314 | 0 | } |
10315 | 0 | if (GCC_GLOBAL_REGS) { |
10316 | 0 | ir_CALL(IR_VOID, helper); |
10317 | 0 | } else if (ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
10318 | 0 | ir_CALL_2(IR_ADDR, helper, jit_FP(jit), jit_IP(jit)); |
10319 | 0 | } else { |
10320 | 0 | ir_ref ref = ir_CALL_2(IR_ADDR, helper, jit_FP(jit), jit_IP(jit)); |
10321 | 0 | jit_STORE_IP(jit, ref); |
10322 | 0 | } |
10323 | 0 | } |
10324 | 0 | } else { |
10325 | 0 | ir_ref ip; |
10326 | 0 | ir_ref merge_inputs = IR_UNUSED; |
10327 | | |
10328 | | // JIT: opline = op_array->opcodes |
10329 | 0 | if (func && zend_accel_in_shm(func->op_array.opcodes)) { |
10330 | 0 | ip = ir_CONST_ADDR(func->op_array.opcodes); |
10331 | 0 | } else { |
10332 | 0 | if (!func_ref) { |
10333 | 0 | func_ref = ir_LOAD_A(jit_CALL(rx, func)); |
10334 | 0 | } |
10335 | 0 | ip = ir_LOAD_A(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, opcodes))); |
10336 | 0 | } |
10337 | 0 | jit_STORE_IP(jit, ip); |
10338 | | |
10339 | | // JIT: num_args = EX_NUM_ARGS(); |
10340 | 0 | ir_ref num_args, first_extra_arg; |
10341 | |
|
10342 | 0 | num_args = ir_LOAD_U32(jit_EX(This.u2.num_args)); |
10343 | 0 | if (func) { |
10344 | 0 | first_extra_arg = ir_CONST_U32(func->op_array.num_args); |
10345 | 0 | } else { |
10346 | | // JIT: first_extra_arg = op_array->num_args; |
10347 | 0 | ZEND_ASSERT(func_ref); |
10348 | 0 | first_extra_arg = ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, num_args))); |
10349 | 0 | } |
10350 | | |
10351 | | // JIT: if (UNEXPECTED(num_args > first_extra_arg)) |
10352 | 0 | ir_ref if_extra_args = ir_IF(ir_GT(num_args, first_extra_arg)); |
10353 | 0 | ir_IF_TRUE_cold(if_extra_args); |
10354 | 0 | if (GCC_GLOBAL_REGS) { |
10355 | 0 | ir_CALL(IR_VOID, ir_CONST_FC_FUNC(zend_jit_copy_extra_args_helper)); |
10356 | 0 | } else { |
10357 | 0 | ir_ref ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_copy_extra_args_helper), jit_FP(jit), jit_IP(jit)); |
10358 | 0 | jit_STORE_IP(jit, ref); |
10359 | 0 | } |
10360 | 0 | ir_END_list(merge_inputs); |
10361 | 0 | ir_IF_FALSE(if_extra_args); |
10362 | 0 | if (!func || (func->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0) { |
10363 | 0 | if (!func) { |
10364 | | // JIT: if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) |
10365 | 0 | ir_ref if_has_type_hints = ir_IF(ir_AND_U32( |
10366 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, fn_flags))), |
10367 | 0 | ir_CONST_U32(ZEND_ACC_HAS_TYPE_HINTS))); |
10368 | 0 | ir_IF_TRUE(if_has_type_hints); |
10369 | 0 | ir_END_list(merge_inputs); |
10370 | 0 | ir_IF_FALSE(if_has_type_hints); |
10371 | 0 | } |
10372 | | // JIT: opline += num_args; |
10373 | |
|
10374 | 0 | ir_ref ref = ir_MUL_U32(num_args, ir_CONST_U32(sizeof(zend_op))); |
10375 | |
|
10376 | 0 | if (sizeof(void*) == 8) { |
10377 | 0 | ref = ir_ZEXT_A(ref); |
10378 | 0 | } |
10379 | |
|
10380 | 0 | jit_STORE_IP(jit, ir_ADD_A(jit_IP(jit), ref)); |
10381 | 0 | } |
10382 | |
|
10383 | 0 | ir_END_list(merge_inputs); |
10384 | 0 | ir_MERGE_list(merge_inputs); |
10385 | | |
10386 | | // JIT: if (EXPECTED((int)num_args < op_array->last_var)) { |
10387 | 0 | ir_ref last_var; |
10388 | |
|
10389 | 0 | if (func) { |
10390 | 0 | last_var = ir_CONST_U32(func->op_array.last_var); |
10391 | 0 | } else { |
10392 | 0 | ZEND_ASSERT(func_ref); |
10393 | 0 | last_var = ir_LOAD_U32(ir_ADD_OFFSET(func_ref, offsetof(zend_op_array, last_var))); |
10394 | 0 | } |
10395 | |
|
10396 | 0 | ir_ref idx = ir_SUB_U32(last_var, num_args); |
10397 | 0 | ir_ref if_need = ir_IF(ir_GT(idx, ir_CONST_U32(0))); |
10398 | 0 | ir_IF_TRUE(if_need); |
10399 | | |
10400 | | // JIT: zval *var = EX_VAR_NUM(num_args); |
10401 | 0 | if (sizeof(void*) == 8) { |
10402 | 0 | num_args = ir_ZEXT_A(num_args); |
10403 | 0 | } |
10404 | 0 | ir_ref var_ref = ir_ADD_OFFSET( |
10405 | 0 | ir_ADD_A(jit_FP(jit), ir_MUL_A(num_args, ir_CONST_ADDR(sizeof(zval)))), |
10406 | 0 | (ZEND_CALL_FRAME_SLOT * sizeof(zval)) + offsetof(zval, u1.type_info)); |
10407 | |
|
10408 | 0 | ir_ref loop = ir_LOOP_BEGIN(ir_END()); |
10409 | 0 | var_ref = ir_PHI_2(IR_ADDR, var_ref, IR_UNUSED); |
10410 | 0 | idx = ir_PHI_2(IR_U32, idx, IR_UNUSED); |
10411 | 0 | ir_STORE(var_ref, ir_CONST_I32(IS_UNDEF)); |
10412 | 0 | ir_PHI_SET_OP(var_ref, 2, ir_ADD_OFFSET(var_ref, sizeof(zval))); |
10413 | 0 | ir_ref idx2 = ir_SUB_U32(idx, ir_CONST_U32(1)); |
10414 | 0 | ir_PHI_SET_OP(idx, 2, idx2); |
10415 | 0 | ir_ref if_not_zero = ir_IF(idx2); |
10416 | 0 | ir_IF_TRUE(if_not_zero); |
10417 | 0 | ir_MERGE_SET_OP(loop, 2, ir_LOOP_END()); |
10418 | 0 | ir_IF_FALSE(if_not_zero); |
10419 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_need); |
10420 | 0 | } |
10421 | |
|
10422 | 0 | if (ZEND_OBSERVER_ENABLED && (!func || (func->common.fn_flags & (ZEND_ACC_CALL_VIA_TRAMPOLINE | ZEND_ACC_GENERATOR)) == 0)) { |
10423 | 0 | ir_ref observer_handler; |
10424 | 0 | ir_ref rx = jit_FP(jit); |
10425 | 0 | struct jit_observer_fcall_is_unobserved_data unobserved_data = jit_observer_fcall_is_unobserved_start(jit, func, &observer_handler, rx, func_ref); |
10426 | 0 | if (trace && (trace->op != ZEND_JIT_TRACE_END || trace->stop < ZEND_JIT_TRACE_STOP_INTERPRETER)) { |
10427 | 0 | ZEND_ASSERT(trace[1].op == ZEND_JIT_TRACE_VM || trace[1].op == ZEND_JIT_TRACE_END); |
10428 | 0 | jit_SET_EX_OPLINE(jit, trace[1].opline); |
10429 | 0 | } else { |
10430 | | // EX(opline) = opline |
10431 | 0 | ir_STORE(jit_EX(opline), jit_IP(jit)); |
10432 | 0 | } |
10433 | 0 | jit_observer_fcall_begin(jit, rx, observer_handler); |
10434 | |
|
10435 | 0 | if (trace) { |
10436 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
10437 | |
|
10438 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
10439 | 0 | if (!exit_addr) { |
10440 | 0 | return 0; |
10441 | 0 | } |
10442 | 0 | } else { |
10443 | 0 | exit_addr = NULL; |
10444 | 0 | } |
10445 | | |
10446 | 0 | zend_jit_check_timeout(jit, NULL /* we're inside the called function */, exit_addr); |
10447 | |
|
10448 | 0 | jit_observer_fcall_is_unobserved_end(jit, &unobserved_data); |
10449 | 0 | } |
10450 | | |
10451 | 0 | if (trace) { |
10452 | 0 | if (!func && (opline->opcode != ZEND_DO_UCALL)) { |
10453 | 0 | user_path = ir_END(); |
10454 | 0 | } |
10455 | 0 | } else { |
10456 | 0 | zend_basic_block *bb; |
10457 | |
|
10458 | 0 | do { |
10459 | 0 | if (recursive_call_through_jmp) { |
10460 | 0 | ir_ref begin, end; |
10461 | 0 | ir_insn *insn; |
10462 | | |
10463 | | /* attempt to convert direct recursive call into loop */ |
10464 | 0 | begin = jit->bb_start_ref[num_args]; |
10465 | 0 | ZEND_ASSERT(begin != IR_UNUSED); |
10466 | 0 | insn = &jit->ctx.ir_base[begin]; |
10467 | 0 | if (insn->op == IR_BEGIN) { |
10468 | 0 | end = ir_LOOP_END(); |
10469 | 0 | insn = &jit->ctx.ir_base[begin]; |
10470 | 0 | insn->op = IR_LOOP_BEGIN; |
10471 | 0 | insn->inputs_count = 2; |
10472 | 0 | insn->op2 = end; |
10473 | 0 | break; |
10474 | 0 | } else if ((insn->op == IR_MERGE || insn->op == IR_LOOP_BEGIN) |
10475 | 0 | && insn->inputs_count == 2) { |
10476 | 0 | end = ir_LOOP_END(); |
10477 | 0 | insn = &jit->ctx.ir_base[begin]; |
10478 | 0 | insn->op = IR_LOOP_BEGIN; |
10479 | 0 | insn->inputs_count = 3; |
10480 | 0 | insn->op3 = end; |
10481 | 0 | break; |
10482 | 0 | } else if (insn->op == IR_LOOP_BEGIN && insn->inputs_count == 3) { |
10483 | 0 | ZEND_ASSERT(jit->ctx.ir_base[insn->op3].op == IR_LOOP_END); |
10484 | 0 | jit->ctx.ir_base[insn->op3].op = IR_END; |
10485 | 0 | ir_MERGE_2(insn->op3, ir_END()); |
10486 | 0 | end = ir_LOOP_END(); |
10487 | 0 | insn = &jit->ctx.ir_base[begin]; |
10488 | 0 | insn->op3 = end; |
10489 | 0 | break; |
10490 | 0 | } |
10491 | 0 | } |
10492 | | /* fallback to indirect JMP or RETURN */ |
10493 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
10494 | 0 | zend_jit_tailcall_handler(jit, ir_LOAD_A(jit_IP(jit))); |
10495 | 0 | } else { |
10496 | 0 | zend_jit_vm_enter(jit, jit_IP(jit)); |
10497 | 0 | } |
10498 | 0 | } while (0); |
10499 | | |
10500 | 0 | bb = &jit->ssa->cfg.blocks[jit->b]; |
10501 | 0 | if (bb->successors_count > 0) { |
10502 | 0 | int succ; |
10503 | 0 | ir_ref ref; |
10504 | |
|
10505 | 0 | ZEND_ASSERT(bb->successors_count == 1); |
10506 | 0 | succ = bb->successors[0]; |
10507 | | /* Add a fake control edge from UNREACHABLE/RETURN to the following ENTRY */ |
10508 | 0 | ref = jit->ctx.insns_count - 1; |
10509 | 0 | ZEND_ASSERT(jit->ctx.ir_base[ref].op == IR_UNREACHABLE |
10510 | 0 | || jit->ctx.ir_base[ref].op == IR_RETURN |
10511 | 0 | || jit->ctx.ir_base[ref].op == IR_LOOP_END); |
10512 | 0 | ZEND_ASSERT(jit->ssa->cfg.blocks[succ].flags & ZEND_BB_ENTRY); |
10513 | 0 | ref = zend_jit_continue_entry(jit, ref, jit->ssa->cfg.blocks[succ].start); |
10514 | 0 | if (func || (opline->opcode == ZEND_DO_UCALL)) { |
10515 | 0 | _zend_jit_add_predecessor_ref(jit, succ, jit->b, ref); |
10516 | 0 | jit->b = -1; |
10517 | 0 | } else { |
10518 | 0 | user_path = ref; |
10519 | 0 | } |
10520 | 0 | } |
10521 | 0 | } |
10522 | 0 | } |
10523 | | |
10524 | 0 | if ((!func || func->type == ZEND_INTERNAL_FUNCTION) |
10525 | 0 | && (opline->opcode != ZEND_DO_UCALL)) { |
10526 | 0 | if (!func && (opline->opcode != ZEND_DO_ICALL)) { |
10527 | 0 | ir_IF_FALSE(if_user); |
10528 | 0 | } |
10529 | | |
10530 | | // JIT: EG(current_execute_data) = execute_data; |
10531 | 0 | ir_STORE(jit_EG(current_execute_data), rx); |
10532 | |
|
10533 | 0 | bool may_have_observer = ZEND_OBSERVER_ENABLED && (!func || (func->common.fn_flags & (ZEND_ACC_CALL_VIA_TRAMPOLINE | ZEND_ACC_GENERATOR)) == 0); |
10534 | 0 | if (may_have_observer) { |
10535 | 0 | ir_ref observer_handler; |
10536 | 0 | struct jit_observer_fcall_is_unobserved_data unobserved_data = jit_observer_fcall_is_unobserved_start(jit, func, &observer_handler, rx, func_ref ? func_ref : ir_LOAD_A(jit_CALL(rx, func))); |
10537 | 0 | jit_observer_fcall_begin(jit, rx, observer_handler); |
10538 | 0 | jit_observer_fcall_is_unobserved_end(jit, &unobserved_data); |
10539 | 0 | } |
10540 | | |
10541 | | // JIT: ZVAL_NULL(EX_VAR(opline->result.var)); |
10542 | 0 | ir_ref res_addr = IR_UNUSED, func_ptr; |
10543 | |
|
10544 | 0 | if (RETURN_VALUE_USED(opline)) { |
10545 | 0 | res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
10546 | 0 | } else { |
10547 | | /* CPU stack allocated temporary zval */ |
10548 | 0 | ir_ref ptr; |
10549 | |
|
10550 | 0 | if (!jit->ctx.fixed_call_stack_size) { |
10551 | | // JIT: alloca(sizeof(void*)); |
10552 | 0 | ptr = ir_ALLOCA(ir_CONST_ADDR(sizeof(zval))); |
10553 | 0 | } else { |
10554 | | #ifdef _WIN64 |
10555 | | ptr = ir_HARD_COPY_A(jit_ADD_OFFSET(jit, ir_RLOAD_A(IR_REG_SP), IR_SHADOW_ARGS)); |
10556 | | #else |
10557 | 0 | ptr = ir_HARD_COPY_A(ir_RLOAD_A(IR_REG_SP)); |
10558 | 0 | #endif |
10559 | 0 | } |
10560 | 0 | res_addr = ZEND_ADDR_REF_ZVAL(ptr); |
10561 | 0 | } |
10562 | |
|
10563 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
10564 | |
|
10565 | 0 | zend_jit_reset_last_valid_opline(jit); |
10566 | | |
10567 | | // JIT: (zend_execute_internal ? zend_execute_internal : fbc->internal_function.handler)(call, ret); |
10568 | 0 | ir_ref res_ref = jit_ZVAL_ADDR(jit, res_addr); |
10569 | 0 | if (zend_execute_internal) { |
10570 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FUNC(zend_execute_internal), rx, res_ref); |
10571 | 0 | } else { |
10572 | 0 | if (func) { |
10573 | 0 | func_ptr = ir_CONST_FC_FUNC(func->internal_function.handler); |
10574 | 0 | } else { |
10575 | 0 | func_ptr = ir_LOAD_A(ir_ADD_OFFSET(func_ref, offsetof(zend_internal_function, handler))); |
10576 | | #if defined(IR_TARGET_X86) |
10577 | | func_ptr = ir_CAST_FC_FUNC(func_ptr); |
10578 | | #endif |
10579 | 0 | } |
10580 | 0 | ir_CALL_2(IR_VOID, func_ptr, rx, res_ref); |
10581 | 0 | } |
10582 | |
|
10583 | 0 | if (may_have_observer) { |
10584 | 0 | jit_observer_fcall_end(jit, rx, res_ref); |
10585 | 0 | } |
10586 | | |
10587 | | /* When zend_interrupt_function is set, it gets called while |
10588 | | * the frame is still on top. This is less efficient than |
10589 | | * doing it later once it's popped off. There is code further |
10590 | | * down that handles when there isn't an interrupt function. |
10591 | | */ |
10592 | 0 | if (zend_interrupt_function) { |
10593 | | // JIT: if (EG(vm_interrupt)) zend_fcall_interrupt(execute_data); |
10594 | 0 | ir_ref if_interrupt = ir_IF(ir_LOAD_U8(jit_EG(vm_interrupt))); |
10595 | 0 | ir_IF_TRUE_cold(if_interrupt); |
10596 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_fcall_interrupt), rx); |
10597 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_interrupt); |
10598 | 0 | } |
10599 | | |
10600 | | // JIT: EG(current_execute_data) = execute_data; |
10601 | 0 | ir_STORE(jit_EG(current_execute_data), jit_FP(jit)); |
10602 | | |
10603 | | // JIT: zend_vm_stack_free_args(call); |
10604 | 0 | if (func && !unknown_num_args) { |
10605 | 0 | for (i = 0; i < call_num_args; i++ ) { |
10606 | 0 | if (zend_jit_needs_arg_dtor(func, i, call_info)) { |
10607 | 0 | uint32_t offset = EX_NUM_TO_VAR(i); |
10608 | 0 | zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_RX, offset); |
10609 | |
|
10610 | 0 | jit_ZVAL_PTR_DTOR(jit, var_addr, MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN, false, |
10611 | 0 | opline); |
10612 | 0 | } |
10613 | 0 | } |
10614 | 0 | } else { |
10615 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_vm_stack_free_args_helper), rx); |
10616 | 0 | } |
10617 | |
|
10618 | 0 | if (may_have_extra_named_params) { |
10619 | | // JIT: if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) |
10620 | 0 | ir_ref if_has_named = ir_IF(ir_AND_U8( |
10621 | 0 | ir_LOAD_U8(ir_ADD_OFFSET(rx, offsetof(zend_execute_data, This.u1.type_info) + 3)), |
10622 | 0 | ir_CONST_U8(ZEND_CALL_HAS_EXTRA_NAMED_PARAMS >> 24))); |
10623 | 0 | ir_IF_TRUE_cold(if_has_named); |
10624 | |
|
10625 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_free_extra_named_params), |
10626 | 0 | ir_LOAD_A(jit_CALL(rx, extra_named_params))); |
10627 | |
|
10628 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_has_named); |
10629 | 0 | } |
10630 | |
|
10631 | 0 | if (opline->opcode == ZEND_DO_FCALL) { |
10632 | | // TODO: optimize ??? |
10633 | | // JIT: if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_RELEASE_THIS)) |
10634 | 0 | ir_ref if_release_this = ir_IF(ir_AND_U8( |
10635 | 0 | ir_LOAD_U8(ir_ADD_OFFSET(rx, offsetof(zend_execute_data, This.u1.type_info) + 2)), |
10636 | 0 | ir_CONST_U8(ZEND_CALL_RELEASE_THIS >> 16))); |
10637 | 0 | ir_IF_TRUE_cold(if_release_this); |
10638 | | |
10639 | | // JIT: OBJ_RELEASE(Z_OBJ(RX->This)); |
10640 | 0 | jit_OBJ_RELEASE(jit, ir_LOAD_A(jit_CALL(rx, This.value.obj))); |
10641 | |
|
10642 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_release_this); |
10643 | 0 | } |
10644 | | |
10645 | |
|
10646 | 0 | ir_ref allocated_path = IR_UNUSED; |
10647 | |
|
10648 | 0 | if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || |
10649 | 0 | !JIT_G(current_frame) || |
10650 | 0 | !JIT_G(current_frame)->call || |
10651 | 0 | !TRACE_FRAME_IS_NESTED(JIT_G(current_frame)->call) || |
10652 | 0 | prev_opline->opcode == ZEND_SEND_UNPACK || |
10653 | 0 | prev_opline->opcode == ZEND_SEND_ARRAY || |
10654 | 0 | prev_opline->opcode == ZEND_CHECK_UNDEF_ARGS) { |
10655 | | |
10656 | | // JIT: zend_vm_stack_free_call_frame(call); |
10657 | | // JIT: if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_ALLOCATED)) |
10658 | 0 | ir_ref if_allocated = ir_IF(ir_AND_U8( |
10659 | 0 | ir_LOAD_U8(ir_ADD_OFFSET(rx, offsetof(zend_execute_data, This.u1.type_info) + 2)), |
10660 | 0 | ir_CONST_U8(ZEND_CALL_ALLOCATED >> 16))); |
10661 | 0 | ir_IF_TRUE_cold(if_allocated); |
10662 | |
|
10663 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_free_call_frame), rx); |
10664 | |
|
10665 | 0 | allocated_path = ir_END(); |
10666 | 0 | ir_IF_FALSE(if_allocated); |
10667 | 0 | } |
10668 | |
|
10669 | 0 | ir_STORE(jit_EG(vm_stack_top), rx); |
10670 | |
|
10671 | 0 | if (allocated_path) { |
10672 | 0 | ir_MERGE_WITH(allocated_path); |
10673 | 0 | } |
10674 | |
|
10675 | 0 | if (!RETURN_VALUE_USED(opline)) { |
10676 | 0 | zend_class_entry *ce; |
10677 | 0 | bool ce_is_instanceof; |
10678 | 0 | uint32_t func_info = call_info ? |
10679 | 0 | zend_get_func_info(call_info, ssa, &ce, &ce_is_instanceof) : |
10680 | 0 | (MAY_BE_ANY|MAY_BE_REF|MAY_BE_RC1|MAY_BE_RCN); |
10681 | | |
10682 | | /* If an exception is thrown, the return_value may stay at the |
10683 | | * original value of null. */ |
10684 | 0 | func_info |= MAY_BE_NULL; |
10685 | |
|
10686 | 0 | if (func_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) { |
10687 | 0 | ir_ref sp; |
10688 | 0 | if (!jit->ctx.fixed_call_stack_size) { |
10689 | 0 | sp = ir_RLOAD_A(IR_REG_SP); |
10690 | 0 | } else { |
10691 | | #ifdef _WIN64 |
10692 | | sp = jit_ADD_OFFSET(jit, ir_RLOAD_A(IR_REG_SP), IR_SHADOW_ARGS); |
10693 | | #else |
10694 | 0 | sp = ir_RLOAD_A(IR_REG_SP); |
10695 | 0 | #endif |
10696 | 0 | } |
10697 | 0 | res_addr = ZEND_ADDR_REF_ZVAL(sp); |
10698 | 0 | jit_ZVAL_PTR_DTOR(jit, res_addr, func_info, true, opline); |
10699 | 0 | } |
10700 | 0 | if (!jit->ctx.fixed_call_stack_size) { |
10701 | | // JIT: revert alloca |
10702 | 0 | ir_AFREE(ir_CONST_ADDR(sizeof(zval))); |
10703 | 0 | } |
10704 | 0 | } |
10705 | | |
10706 | | // JIT: if (UNEXPECTED(EG(exception) != NULL)) { |
10707 | 0 | ir_GUARD_NOT(ir_LOAD_A(jit_EG_exception(jit)), |
10708 | 0 | jit_STUB_ADDR(jit, jit_stub_icall_throw)); |
10709 | | |
10710 | | /* If there isn't a zend_interrupt_function, the timeout is |
10711 | | * handled here because it's more efficient. |
10712 | | */ |
10713 | 0 | if (!zend_interrupt_function) { |
10714 | | // TODO: Can we avoid checking for interrupts after each call ??? |
10715 | 0 | if (trace && jit->last_valid_opline != opline) { |
10716 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline + 1, ZEND_JIT_EXIT_TO_VM); |
10717 | |
|
10718 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
10719 | 0 | if (!exit_addr) { |
10720 | 0 | return 0; |
10721 | 0 | } |
10722 | 0 | } else { |
10723 | 0 | exit_addr = NULL; |
10724 | 0 | } |
10725 | | |
10726 | 0 | zend_jit_check_timeout(jit, opline + 1, exit_addr); |
10727 | 0 | } |
10728 | | |
10729 | 0 | if ((!trace || !func) && opline->opcode != ZEND_DO_ICALL) { |
10730 | 0 | jit_LOAD_IP_ADDR(jit, opline + 1); |
10731 | 0 | } else if (trace |
10732 | 0 | && trace->op == ZEND_JIT_TRACE_END |
10733 | 0 | && trace->stop >= ZEND_JIT_TRACE_STOP_INTERPRETER) { |
10734 | 0 | jit_LOAD_IP_ADDR(jit, opline + 1); |
10735 | 0 | } |
10736 | 0 | } |
10737 | | |
10738 | 0 | if (user_path) { |
10739 | 0 | ir_MERGE_WITH(user_path); |
10740 | 0 | } |
10741 | |
|
10742 | 0 | return 1; |
10743 | 0 | } |
10744 | | |
10745 | | static int zend_jit_constructor(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, zend_ssa *ssa, int call_level, int next_block) |
10746 | 0 | { |
10747 | 0 | ir_ref if_skip_constructor = jit_IF_ex(jit, jit_CMP_IP(jit, IR_NE, opline), next_block); |
10748 | |
|
10749 | 0 | ir_IF_FALSE(if_skip_constructor); |
10750 | |
|
10751 | 0 | if (JIT_G(opt_level) < ZEND_JIT_LEVEL_INLINE) { |
10752 | 0 | if (!zend_jit_tail_handler(jit, opline)) { |
10753 | 0 | return 0; |
10754 | 0 | } |
10755 | 0 | } else { |
10756 | 0 | if (!zend_jit_do_fcall(jit, opline, op_array, ssa, call_level, next_block, NULL)) { |
10757 | 0 | return 0; |
10758 | 0 | } |
10759 | 0 | } |
10760 | | |
10761 | | /* override predecessors of the next block */ |
10762 | 0 | ZEND_ASSERT(jit->ssa->cfg.blocks[next_block].predecessors_count == 1); |
10763 | 0 | if (!jit->ctx.control) { |
10764 | 0 | ZEND_ASSERT(jit->bb_edges[jit->bb_predecessors[next_block]]); |
10765 | 0 | ir_IF_TRUE(if_skip_constructor); |
10766 | 0 | ir_MERGE_2(jit->bb_edges[jit->bb_predecessors[next_block]], ir_END()); |
10767 | 0 | jit->bb_edges[jit->bb_predecessors[next_block]] = ir_END(); |
10768 | 0 | } else { |
10769 | 0 | ZEND_ASSERT(!jit->bb_edges[jit->bb_predecessors[next_block]]); |
10770 | | /* merge current control path with the true branch of constructor skip condition */ |
10771 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_skip_constructor); |
10772 | 0 | jit->bb_edges[jit->bb_predecessors[next_block]] = ir_END(); |
10773 | |
|
10774 | 0 | jit->b = -1; |
10775 | 0 | } |
10776 | |
|
10777 | 0 | return 1; |
10778 | 0 | } |
10779 | | |
10780 | | static int zend_jit_verify_arg_type(zend_jit_ctx *jit, const zend_op *opline, zend_arg_info *arg_info, bool check_exception) |
10781 | 0 | { |
10782 | 0 | zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
10783 | 0 | uint32_t type_mask = ZEND_TYPE_PURE_MASK(arg_info->type) & MAY_BE_ANY; |
10784 | 0 | ir_ref ref, fast_path = IR_UNUSED; |
10785 | |
|
10786 | 0 | ref = jit_ZVAL_ADDR(jit, res_addr); |
10787 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
10788 | 0 | && JIT_G(current_frame) |
10789 | 0 | && JIT_G(current_frame)->prev) { |
10790 | 0 | zend_jit_trace_stack *stack = JIT_G(current_frame)->stack; |
10791 | 0 | uint8_t type = STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var)); |
10792 | |
|
10793 | 0 | if (type != IS_UNKNOWN && (type_mask & (1u << type))) { |
10794 | 0 | return 1; |
10795 | 0 | } |
10796 | 0 | } |
10797 | | |
10798 | 0 | if (ZEND_ARG_SEND_MODE(arg_info)) { |
10799 | 0 | if (opline->opcode == ZEND_RECV_INIT) { |
10800 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
10801 | 0 | } else { |
10802 | 0 | ref = jit_Z_PTR_ref(jit, ref); |
10803 | 0 | ref = ir_ADD_OFFSET(ref, offsetof(zend_reference, val)); |
10804 | 0 | } |
10805 | 0 | } |
10806 | |
|
10807 | 0 | if (type_mask != 0) { |
10808 | 0 | if (is_power_of_two(type_mask)) { |
10809 | 0 | uint32_t type_code = concrete_type(type_mask); |
10810 | 0 | ir_ref if_ok = jit_if_Z_TYPE_ref(jit, ref, ir_CONST_U8(type_code)); |
10811 | 0 | ir_IF_TRUE(if_ok); |
10812 | 0 | fast_path = ir_END(); |
10813 | 0 | ir_IF_FALSE_cold(if_ok); |
10814 | 0 | } else { |
10815 | 0 | ir_ref if_ok = ir_IF(ir_AND_U32( |
10816 | 0 | ir_SHL_U32(ir_CONST_U32(1), jit_Z_TYPE_ref(jit, ref)), |
10817 | 0 | ir_CONST_U32(type_mask))); |
10818 | 0 | ir_IF_TRUE(if_ok); |
10819 | 0 | fast_path = ir_END(); |
10820 | 0 | ir_IF_FALSE_cold(if_ok); |
10821 | 0 | } |
10822 | 0 | } |
10823 | |
|
10824 | 0 | jit_SET_EX_OPLINE(jit, opline); |
10825 | 0 | ref = ir_CALL_2(IR_BOOL, ir_CONST_FC_FUNC(zend_jit_verify_arg_slow), |
10826 | 0 | ref, ir_CONST_ADDR(arg_info)); |
10827 | |
|
10828 | 0 | if (check_exception) { |
10829 | 0 | ir_GUARD(ref, jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
10830 | 0 | } |
10831 | |
|
10832 | 0 | if (fast_path) { |
10833 | 0 | ir_MERGE_WITH(fast_path); |
10834 | 0 | } |
10835 | |
|
10836 | 0 | return 1; |
10837 | 0 | } |
10838 | | |
10839 | | static int zend_jit_recv(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array) |
10840 | 0 | { |
10841 | 0 | uint32_t arg_num = opline->op1.num; |
10842 | 0 | zend_arg_info *arg_info = NULL; |
10843 | |
|
10844 | 0 | if (op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) { |
10845 | 0 | if (EXPECTED(arg_num <= op_array->num_args)) { |
10846 | 0 | arg_info = &op_array->arg_info[arg_num-1]; |
10847 | 0 | } else if (UNEXPECTED(op_array->fn_flags & ZEND_ACC_VARIADIC)) { |
10848 | 0 | arg_info = &op_array->arg_info[op_array->num_args]; |
10849 | 0 | } |
10850 | 0 | if (arg_info && !ZEND_TYPE_IS_SET(arg_info->type)) { |
10851 | 0 | arg_info = NULL; |
10852 | 0 | } |
10853 | 0 | } |
10854 | |
|
10855 | 0 | if (arg_info || (opline+1)->opcode != ZEND_RECV) { |
10856 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
10857 | 0 | if (!JIT_G(current_frame) || |
10858 | 0 | TRACE_FRAME_NUM_ARGS(JIT_G(current_frame)) < 0 || |
10859 | 0 | arg_num > TRACE_FRAME_NUM_ARGS(JIT_G(current_frame))) { |
10860 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
10861 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
10862 | |
|
10863 | 0 | if (!exit_addr) { |
10864 | 0 | return 0; |
10865 | 0 | } |
10866 | 0 | ir_GUARD(ir_GE(ir_LOAD_U32(jit_EX(This.u2.num_args)), ir_CONST_U32(arg_num)), |
10867 | 0 | ir_CONST_ADDR(exit_addr)); |
10868 | 0 | } |
10869 | 0 | } else { |
10870 | 0 | ir_ref if_ok =ir_IF(ir_GE(ir_LOAD_U32(jit_EX(This.u2.num_args)), ir_CONST_U32(arg_num))); |
10871 | 0 | ir_IF_FALSE_cold(if_ok); |
10872 | |
|
10873 | 0 | jit_SET_EX_OPLINE(jit, opline); |
10874 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_missing_arg_error), jit_FP(jit)); |
10875 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
10876 | 0 | ir_IF_TRUE(if_ok); |
10877 | 0 | } |
10878 | 0 | } |
10879 | | |
10880 | 0 | if (arg_info) { |
10881 | 0 | if (!zend_jit_verify_arg_type(jit, opline, arg_info, true)) { |
10882 | 0 | return 0; |
10883 | 0 | } |
10884 | 0 | } |
10885 | | |
10886 | 0 | return 1; |
10887 | 0 | } |
10888 | | |
10889 | | static int zend_jit_recv_init(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, bool is_last, int may_throw) |
10890 | 0 | { |
10891 | 0 | uint32_t arg_num = opline->op1.num; |
10892 | 0 | zval *zv = RT_CONSTANT(opline, opline->op2); |
10893 | 0 | zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
10894 | 0 | ir_ref ref, if_fail, skip_path = IR_UNUSED; |
10895 | |
|
10896 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
10897 | 0 | && JIT_G(current_frame) |
10898 | 0 | && TRACE_FRAME_NUM_ARGS(JIT_G(current_frame)) >= 0) { |
10899 | 0 | if (arg_num > TRACE_FRAME_NUM_ARGS(JIT_G(current_frame))) { |
10900 | 0 | jit_ZVAL_COPY_CONST(jit, |
10901 | 0 | res_addr, |
10902 | 0 | -1, -1, |
10903 | 0 | zv, true); |
10904 | 0 | } |
10905 | 0 | } else { |
10906 | 0 | if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || |
10907 | 0 | (op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) { |
10908 | 0 | ir_ref if_skip = ir_IF(ir_GE(ir_LOAD_U32(jit_EX(This.u2.num_args)), ir_CONST_U32(arg_num))); |
10909 | 0 | ir_IF_TRUE(if_skip); |
10910 | 0 | skip_path = ir_END(); |
10911 | 0 | ir_IF_FALSE(if_skip); |
10912 | 0 | } |
10913 | 0 | jit_ZVAL_COPY_CONST(jit, |
10914 | 0 | res_addr, |
10915 | 0 | -1, -1, |
10916 | 0 | zv, true); |
10917 | 0 | } |
10918 | |
|
10919 | 0 | if (Z_CONSTANT_P(zv)) { |
10920 | 0 | jit_SET_EX_OPLINE(jit, opline); |
10921 | 0 | ref = ir_CALL_2(IR_I32, ir_CONST_FC_FUNC(zval_update_constant_ex), |
10922 | 0 | jit_ZVAL_ADDR(jit, res_addr), |
10923 | 0 | ir_LOAD_A(ir_ADD_OFFSET(ir_LOAD_A(jit_EX(func)), offsetof(zend_op_array, scope)))); |
10924 | |
|
10925 | 0 | if_fail = ir_IF(ref); |
10926 | 0 | ir_IF_TRUE_cold(if_fail); |
10927 | 0 | jit_ZVAL_PTR_DTOR(jit, res_addr, MAY_BE_ANY|MAY_BE_RC1|MAY_BE_RCN, true, opline); |
10928 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
10929 | 0 | ir_IF_FALSE(if_fail); |
10930 | 0 | } |
10931 | |
|
10932 | 0 | if (skip_path) { |
10933 | 0 | ir_MERGE_WITH(skip_path); |
10934 | 0 | } |
10935 | |
|
10936 | 0 | if (op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) { |
10937 | 0 | do { |
10938 | 0 | zend_arg_info *arg_info; |
10939 | |
|
10940 | 0 | if (arg_num <= op_array->num_args) { |
10941 | 0 | arg_info = &op_array->arg_info[arg_num-1]; |
10942 | 0 | } else if (op_array->fn_flags & ZEND_ACC_VARIADIC) { |
10943 | 0 | arg_info = &op_array->arg_info[op_array->num_args]; |
10944 | 0 | } else { |
10945 | 0 | break; |
10946 | 0 | } |
10947 | 0 | if (!ZEND_TYPE_IS_SET(arg_info->type)) { |
10948 | 0 | break; |
10949 | 0 | } |
10950 | 0 | if (!zend_jit_verify_arg_type(jit, opline, arg_info, may_throw)) { |
10951 | 0 | return 0; |
10952 | 0 | } |
10953 | 0 | } while (0); |
10954 | 0 | } |
10955 | | |
10956 | 0 | return 1; |
10957 | 0 | } |
10958 | | |
10959 | | static bool zend_jit_verify_return_type(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, uint32_t op1_info) |
10960 | 0 | { |
10961 | 0 | zend_arg_info *arg_info = &op_array->arg_info[-1]; |
10962 | 0 | ZEND_ASSERT(ZEND_TYPE_IS_SET(arg_info->type)); |
10963 | 0 | zend_jit_addr op1_addr = OP1_ADDR(); |
10964 | 0 | bool needs_slow_check = true; |
10965 | 0 | uint32_t type_mask = ZEND_TYPE_PURE_MASK(arg_info->type) & MAY_BE_ANY; |
10966 | 0 | ir_ref fast_path = IR_UNUSED; |
10967 | |
|
10968 | 0 | if (type_mask != 0) { |
10969 | 0 | if (((op1_info & MAY_BE_ANY) & type_mask) == 0) { |
10970 | | /* pass */ |
10971 | 0 | } else if (((op1_info & MAY_BE_ANY) | type_mask) == type_mask) { |
10972 | 0 | needs_slow_check = false; |
10973 | 0 | } else if (is_power_of_two(type_mask)) { |
10974 | 0 | uint32_t type_code = concrete_type(type_mask); |
10975 | 0 | ir_ref if_ok = jit_if_Z_TYPE(jit, op1_addr, type_code); |
10976 | |
|
10977 | 0 | ir_IF_TRUE(if_ok); |
10978 | 0 | fast_path = ir_END(); |
10979 | 0 | ir_IF_FALSE_cold(if_ok); |
10980 | 0 | } else { |
10981 | 0 | ir_ref if_ok = ir_IF(ir_AND_U32( |
10982 | 0 | ir_SHL_U32(ir_CONST_U32(1), jit_Z_TYPE(jit, op1_addr)), |
10983 | 0 | ir_CONST_U32(type_mask))); |
10984 | |
|
10985 | 0 | ir_IF_TRUE(if_ok); |
10986 | 0 | fast_path = ir_END(); |
10987 | 0 | ir_IF_FALSE_cold(if_ok); |
10988 | 0 | } |
10989 | 0 | } |
10990 | 0 | if (needs_slow_check) { |
10991 | 0 | ir_ref ref; |
10992 | |
|
10993 | 0 | jit_SET_EX_OPLINE(jit, opline); |
10994 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
10995 | 0 | if (op1_info & MAY_BE_UNDEF) { |
10996 | 0 | ref = zend_jit_zval_check_undef(jit, ref, opline->op1.var, NULL, true); |
10997 | 0 | } |
10998 | |
|
10999 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_verify_return_slow), |
11000 | 0 | ref, |
11001 | 0 | ir_LOAD_A(jit_EX(func)), |
11002 | 0 | ir_CONST_ADDR(arg_info)); |
11003 | |
|
11004 | 0 | zend_jit_check_exception(jit); |
11005 | |
|
11006 | 0 | if (fast_path) { |
11007 | 0 | ir_MERGE_WITH(fast_path); |
11008 | 0 | } |
11009 | 0 | } |
11010 | |
|
11011 | 0 | return true; |
11012 | 0 | } |
11013 | | |
11014 | | static int zend_jit_leave_frame(zend_jit_ctx *jit) |
11015 | 0 | { |
11016 | | // JIT: EG(current_execute_data) = EX(prev_execute_data); |
11017 | 0 | ir_STORE(jit_EG(current_execute_data), ir_LOAD_A(jit_EX(prev_execute_data))); |
11018 | 0 | return 1; |
11019 | 0 | } |
11020 | | |
11021 | | static int zend_jit_free_cvs(zend_jit_ctx *jit) |
11022 | 0 | { |
11023 | | // JIT: EG(current_execute_data) = EX(prev_execute_data); |
11024 | 0 | ir_STORE(jit_EG(current_execute_data), ir_LOAD_A(jit_EX(prev_execute_data))); |
11025 | | |
11026 | | // JIT: zend_free_compiled_variables(execute_data); |
11027 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_free_compiled_variables), jit_FP(jit)); |
11028 | 0 | return 1; |
11029 | 0 | } |
11030 | | |
11031 | | static int zend_jit_free_cv(zend_jit_ctx *jit, uint32_t info, uint32_t var) |
11032 | 0 | { |
11033 | 0 | if (info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) { |
11034 | 0 | zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, EX_NUM_TO_VAR(var)); |
11035 | |
|
11036 | 0 | jit_ZVAL_PTR_DTOR(jit, var_addr, info, true, NULL); |
11037 | 0 | } |
11038 | 0 | return 1; |
11039 | 0 | } |
11040 | | |
11041 | | static int zend_jit_free_op(zend_jit_ctx *jit, const zend_op *opline, uint32_t info, uint32_t var_offset) |
11042 | 0 | { |
11043 | 0 | if (info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) { |
11044 | 0 | jit_ZVAL_PTR_DTOR(jit, ZEND_ADDR_MEM_ZVAL(ZREG_FP, var_offset), info, false, opline); |
11045 | 0 | } |
11046 | 0 | return 1; |
11047 | 0 | } |
11048 | | |
11049 | | static int zend_jit_leave_func(zend_jit_ctx *jit, |
11050 | | const zend_op_array *op_array, |
11051 | | const zend_op *opline, |
11052 | | uint32_t op1_info, |
11053 | | bool left_frame, |
11054 | | zend_jit_trace_rec *trace, |
11055 | | zend_jit_trace_info *trace_info, |
11056 | | int indirect_var_access, |
11057 | | int may_throw) |
11058 | 0 | { |
11059 | 0 | bool may_be_top_frame = |
11060 | 0 | JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || |
11061 | 0 | !JIT_G(current_frame) || |
11062 | 0 | !TRACE_FRAME_IS_NESTED(JIT_G(current_frame)); |
11063 | 0 | bool may_need_call_helper = |
11064 | 0 | indirect_var_access || /* may have symbol table */ |
11065 | 0 | !op_array->function_name || /* may have symbol table */ |
11066 | 0 | may_be_top_frame || |
11067 | 0 | (op_array->fn_flags & ZEND_ACC_VARIADIC) || /* may have extra named args */ |
11068 | 0 | JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || |
11069 | 0 | !JIT_G(current_frame) || |
11070 | 0 | TRACE_FRAME_NUM_ARGS(JIT_G(current_frame)) == -1 || /* unknown number of args */ |
11071 | 0 | (uint32_t)TRACE_FRAME_NUM_ARGS(JIT_G(current_frame)) > op_array->num_args; /* extra args */ |
11072 | 0 | bool may_need_release_this = |
11073 | 0 | !(op_array->fn_flags & ZEND_ACC_CLOSURE) && |
11074 | 0 | op_array->scope && |
11075 | 0 | !(op_array->fn_flags & ZEND_ACC_STATIC) && |
11076 | 0 | (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || |
11077 | 0 | !JIT_G(current_frame) || |
11078 | 0 | !TRACE_FRAME_NO_NEED_RELEASE_THIS(JIT_G(current_frame))); |
11079 | 0 | ir_ref call_info = IR_UNUSED, ref, cold_path = IR_UNUSED; |
11080 | |
|
11081 | 0 | if (may_need_call_helper) { |
11082 | 0 | if (!left_frame) { |
11083 | 0 | left_frame = true; |
11084 | 0 | if (!zend_jit_leave_frame(jit)) { |
11085 | 0 | return 0; |
11086 | 0 | } |
11087 | 0 | } |
11088 | | /* ZEND_CALL_FAKE_CLOSURE handled on slow path to eliminate check for ZEND_CALL_CLOSURE on fast path */ |
11089 | 0 | call_info = ir_LOAD_U32(jit_EX(This.u1.type_info)); |
11090 | 0 | ref = ir_AND_U32(call_info, |
11091 | 0 | ir_CONST_U32(ZEND_CALL_TOP|ZEND_CALL_HAS_SYMBOL_TABLE|ZEND_CALL_FREE_EXTRA_ARGS|ZEND_CALL_ALLOCATED|ZEND_CALL_HAS_EXTRA_NAMED_PARAMS|ZEND_CALL_FAKE_CLOSURE)); |
11092 | 0 | if (trace && trace->op != ZEND_JIT_TRACE_END) { |
11093 | 0 | ir_ref if_slow = ir_IF(ref); |
11094 | |
|
11095 | 0 | ir_IF_TRUE_cold(if_slow); |
11096 | 0 | if (!GCC_GLOBAL_REGS) { |
11097 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_leave_func_helper), jit_FP(jit), jit_IP(jit)); |
11098 | 0 | } else { |
11099 | 0 | ir_CALL(IR_VOID, ir_CONST_FC_FUNC(zend_jit_leave_func_helper)); |
11100 | 0 | } |
11101 | |
|
11102 | 0 | if (may_be_top_frame) { |
11103 | | // TODO: try to avoid this check ??? |
11104 | 0 | if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) { |
11105 | | #if 0 |
11106 | | /* this check should be handled by the following OPLINE guard */ |
11107 | | | cmp IP, zend_jit_halt_op |
11108 | | | je ->trace_halt |
11109 | | #endif |
11110 | 0 | } else if (GCC_GLOBAL_REGS) { |
11111 | 0 | ir_GUARD(jit_IP(jit), jit_STUB_ADDR(jit, jit_stub_trace_halt)); |
11112 | 0 | } else { |
11113 | 0 | ir_GUARD(ir_NE(ref, ir_CONST_ADDR(ZEND_VM_ENTER_BIT)), jit_STUB_ADDR(jit, jit_stub_trace_halt)); |
11114 | 0 | jit_STORE_IP(jit, ref); |
11115 | 0 | } |
11116 | 0 | } |
11117 | |
|
11118 | 0 | if (!GCC_GLOBAL_REGS) { |
11119 | | // execute_data = EG(current_execute_data) |
11120 | 0 | jit_STORE_FP(jit, ir_LOAD_A(jit_EG(current_execute_data))); |
11121 | 0 | } |
11122 | 0 | cold_path = ir_END(); |
11123 | 0 | ir_IF_FALSE(if_slow); |
11124 | 0 | } else { |
11125 | 0 | ir_GUARD_NOT(ref, jit_STUB_ADDR(jit, jit_stub_leave_function_handler)); |
11126 | 0 | } |
11127 | 0 | } |
11128 | | |
11129 | 0 | if ((op_array->fn_flags & (ZEND_ACC_CLOSURE|ZEND_ACC_FAKE_CLOSURE)) == ZEND_ACC_CLOSURE) { |
11130 | 0 | if (!left_frame) { |
11131 | 0 | left_frame = true; |
11132 | 0 | if (!zend_jit_leave_frame(jit)) { |
11133 | 0 | return 0; |
11134 | 0 | } |
11135 | 0 | } |
11136 | | // JIT: OBJ_RELEASE(ZEND_CLOSURE_OBJECT(EX(func))); |
11137 | 0 | jit_OBJ_RELEASE(jit, ir_ADD_OFFSET(ir_LOAD_A(jit_EX(func)), -sizeof(zend_object))); |
11138 | 0 | } else if (may_need_release_this) { |
11139 | 0 | ir_ref if_release, fast_path = IR_UNUSED; |
11140 | |
|
11141 | 0 | if (!left_frame) { |
11142 | 0 | left_frame = true; |
11143 | 0 | if (!zend_jit_leave_frame(jit)) { |
11144 | 0 | return 0; |
11145 | 0 | } |
11146 | 0 | } |
11147 | 0 | if (!JIT_G(current_frame) || !TRACE_FRAME_ALWAYS_RELEASE_THIS(JIT_G(current_frame))) { |
11148 | | // JIT: if (call_info & ZEND_CALL_RELEASE_THIS) |
11149 | 0 | if (!call_info) { |
11150 | 0 | call_info = ir_LOAD_U32(jit_EX(This.u1.type_info)); |
11151 | 0 | } |
11152 | 0 | if_release = ir_IF(ir_AND_U32(call_info, ir_CONST_U32(ZEND_CALL_RELEASE_THIS))); |
11153 | 0 | ir_IF_FALSE(if_release); |
11154 | 0 | fast_path = ir_END(); |
11155 | 0 | ir_IF_TRUE(if_release); |
11156 | 0 | } |
11157 | | // JIT: OBJ_RELEASE(execute_data->This)) |
11158 | 0 | jit_OBJ_RELEASE(jit, ir_LOAD_A(jit_EX(This.value.obj))); |
11159 | 0 | if (fast_path) { |
11160 | 0 | ir_MERGE_WITH(fast_path); |
11161 | 0 | } |
11162 | | // TODO: avoid EG(excption) check for $this->foo() calls |
11163 | 0 | may_throw = 1; |
11164 | 0 | } |
11165 | | |
11166 | | // JIT: EG(vm_stack_top) = (zval*)execute_data |
11167 | 0 | ir_STORE(jit_EG(vm_stack_top), jit_FP(jit)); |
11168 | | |
11169 | | // JITL execute_data = EX(prev_execute_data) |
11170 | 0 | jit_STORE_FP(jit, ir_LOAD_A(jit_EX(prev_execute_data))); |
11171 | |
|
11172 | 0 | if (!left_frame) { |
11173 | | // JIT: EG(current_execute_data) = execute_data |
11174 | 0 | ir_STORE(jit_EG(current_execute_data), jit_FP(jit)); |
11175 | 0 | } |
11176 | |
|
11177 | 0 | if (trace) { |
11178 | 0 | if (trace->op != ZEND_JIT_TRACE_END |
11179 | 0 | && (JIT_G(current_frame) && !TRACE_FRAME_IS_UNKNOWN_RETURN(JIT_G(current_frame)))) { |
11180 | 0 | zend_jit_reset_last_valid_opline(jit); |
11181 | 0 | } else { |
11182 | | /* We add extra RLOAD and RSTORE to make fusion for persistent register |
11183 | | * mov (%FP), %IP |
11184 | | * add $0x1c, %IP |
11185 | | * The naive (commented) code leads to extra register allocation and move. |
11186 | | * mov (%FP), %tmp |
11187 | | * add $0x1c, %tmp |
11188 | | * mov %tmp, %FP |
11189 | | */ |
11190 | | #if 0 |
11191 | | jit_STORE_IP(jit, ir_ADD_OFFSET(ir_LOAD_A(jit_EX(opline)), sizeof(zend_op))); |
11192 | | #else |
11193 | 0 | jit_STORE_IP(jit, ir_LOAD_A(jit_EX(opline))); |
11194 | 0 | jit_STORE_IP(jit, ir_ADD_OFFSET(jit_IP(jit), sizeof(zend_op))); |
11195 | 0 | #endif |
11196 | 0 | } |
11197 | |
|
11198 | 0 | if (cold_path) { |
11199 | 0 | ir_MERGE_WITH(cold_path); |
11200 | 0 | } |
11201 | |
|
11202 | 0 | if (trace->op == ZEND_JIT_TRACE_BACK |
11203 | 0 | && (!JIT_G(current_frame) || TRACE_FRAME_IS_UNKNOWN_RETURN(JIT_G(current_frame)))) { |
11204 | 0 | const zend_op *next_opline = trace->opline; |
11205 | |
|
11206 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) |
11207 | 0 | && (op1_info & MAY_BE_RC1) |
11208 | 0 | && (op1_info & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY))) { |
11209 | | /* exception might be thrown during destruction of unused return value */ |
11210 | | // JIT: if (EG(exception)) |
11211 | 0 | ir_GUARD_NOT(ir_LOAD_A(jit_EG(exception)), jit_STUB_ADDR(jit, jit_stub_leave_throw)); |
11212 | 0 | } |
11213 | 0 | do { |
11214 | 0 | trace++; |
11215 | 0 | } while (trace->op == ZEND_JIT_TRACE_INIT_CALL); |
11216 | 0 | ZEND_ASSERT(trace->op == ZEND_JIT_TRACE_VM || trace->op == ZEND_JIT_TRACE_END); |
11217 | 0 | next_opline = trace->opline; |
11218 | 0 | ZEND_ASSERT(next_opline != NULL); |
11219 | |
|
11220 | 0 | if (trace->op == ZEND_JIT_TRACE_END |
11221 | 0 | && trace->stop == ZEND_JIT_TRACE_STOP_RECURSIVE_RET) { |
11222 | 0 | trace_info->flags |= ZEND_JIT_TRACE_LOOP; |
11223 | |
|
11224 | 0 | ir_ref if_eq = ir_IF(jit_CMP_IP(jit, IR_EQ, next_opline)); |
11225 | |
|
11226 | 0 | ir_IF_TRUE(if_eq); |
11227 | 0 | ZEND_ASSERT(jit->trace_loop_ref); |
11228 | 0 | ZEND_ASSERT(jit->ctx.ir_base[jit->trace_loop_ref].op2 == IR_UNUSED); |
11229 | 0 | ir_MERGE_SET_OP(jit->trace_loop_ref, 2, ir_END()); |
11230 | 0 | ir_IF_FALSE(if_eq); |
11231 | |
|
11232 | | #ifdef ZEND_VM_HYBRID_JIT_RED_ZONE_SIZE |
11233 | | ir_TAILCALL(IR_VOID, ir_LOAD_A(jit_IP(jit))); |
11234 | | #else |
11235 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_trace_escape)); |
11236 | 0 | #endif |
11237 | 0 | } else { |
11238 | 0 | ir_GUARD(jit_CMP_IP(jit, IR_EQ, next_opline), jit_STUB_ADDR(jit, jit_stub_trace_escape)); |
11239 | 0 | } |
11240 | |
|
11241 | 0 | zend_jit_set_last_valid_opline(jit, trace->opline); |
11242 | |
|
11243 | 0 | return 1; |
11244 | 0 | } else if (may_throw || |
11245 | 0 | (((opline->op1_type & (IS_VAR|IS_TMP_VAR)) |
11246 | 0 | && (op1_info & MAY_BE_RC1) |
11247 | 0 | && (op1_info & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY))) |
11248 | 0 | && (!JIT_G(current_frame) || TRACE_FRAME_IS_RETURN_VALUE_UNUSED(JIT_G(current_frame))))) { |
11249 | | // JIT: if (EG(exception)) |
11250 | 0 | ir_GUARD_NOT(ir_LOAD_A(jit_EG(exception)), jit_STUB_ADDR(jit, jit_stub_leave_throw)); |
11251 | 0 | } |
11252 | | |
11253 | 0 | return 1; |
11254 | 0 | } else { |
11255 | | // JIT: if (EG(exception)) |
11256 | 0 | ir_GUARD_NOT(ir_LOAD_A(jit_EG(exception)), jit_STUB_ADDR(jit, jit_stub_leave_throw)); |
11257 | | // JIT: opline = EX(opline) + 1 |
11258 | 0 | jit_STORE_IP(jit, ir_LOAD_A(jit_EX(opline))); |
11259 | 0 | jit_STORE_IP(jit, ir_ADD_OFFSET(jit_IP(jit), sizeof(zend_op))); |
11260 | 0 | } |
11261 | | |
11262 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
11263 | 0 | zend_jit_tailcall_handler(jit, ir_LOAD_A(jit_IP(jit))); |
11264 | 0 | } else { |
11265 | 0 | zend_jit_vm_leave(jit, jit_IP(jit)); |
11266 | 0 | } |
11267 | |
|
11268 | 0 | jit->b = -1; |
11269 | |
|
11270 | 0 | return 1; |
11271 | 0 | } |
11272 | | |
11273 | | static void zend_jit_common_return(zend_jit_ctx *jit) |
11274 | 0 | { |
11275 | 0 | ZEND_ASSERT(jit->return_inputs); |
11276 | 0 | ir_MERGE_list(jit->return_inputs); |
11277 | 0 | } |
11278 | | |
11279 | | static int zend_jit_return(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, uint32_t op1_info, zend_jit_addr op1_addr) |
11280 | 0 | { |
11281 | 0 | zend_jit_addr ret_addr; |
11282 | 0 | int8_t return_value_used = -1; |
11283 | 0 | ir_ref return_value = IR_UNUSED, ref, refcount, if_return_value_used = IR_UNUSED; |
11284 | |
|
11285 | 0 | ZEND_ASSERT(op_array->type != ZEND_EVAL_CODE && op_array->function_name); |
11286 | 0 | ZEND_ASSERT(!(op1_info & MAY_BE_UNDEF)); |
11287 | |
|
11288 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
11289 | 0 | jit->return_inputs = IR_UNUSED; |
11290 | 0 | if (JIT_G(current_frame)) { |
11291 | 0 | if (TRACE_FRAME_IS_RETURN_VALUE_USED(JIT_G(current_frame))) { |
11292 | 0 | return_value_used = 1; |
11293 | 0 | } else if (TRACE_FRAME_IS_RETURN_VALUE_UNUSED(JIT_G(current_frame))) { |
11294 | 0 | return_value_used = 0; |
11295 | 0 | } else { |
11296 | 0 | return_value_used = -1; |
11297 | 0 | } |
11298 | 0 | } |
11299 | 0 | } |
11300 | |
|
11301 | 0 | if (ZEND_OBSERVER_ENABLED) { |
11302 | 0 | if (Z_MODE(op1_addr) == IS_REG) { |
11303 | 0 | zend_jit_addr dst = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op1.var); |
11304 | |
|
11305 | 0 | if (!zend_jit_spill_store_inv(jit, op1_addr, dst, op1_info)) { |
11306 | 0 | return 0; |
11307 | 0 | } |
11308 | 0 | op1_addr = dst; |
11309 | 0 | } |
11310 | 0 | jit_observer_fcall_end(jit, jit_FP(jit), jit_ZVAL_ADDR(jit, op1_addr)); |
11311 | 0 | } |
11312 | | |
11313 | | // JIT: if (!EX(return_value)) |
11314 | 0 | return_value = ir_LOAD_A(jit_EX(return_value)); |
11315 | 0 | ret_addr = ZEND_ADDR_REF_ZVAL(return_value); |
11316 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) && |
11317 | 0 | (op1_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
11318 | 0 | if (return_value_used == -1) { |
11319 | 0 | if_return_value_used = ir_IF(return_value); |
11320 | 0 | ir_IF_FALSE_cold(if_return_value_used); |
11321 | 0 | } |
11322 | 0 | if (return_value_used != 1) { |
11323 | 0 | if (op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)-(MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
11324 | 0 | ir_ref if_refcounted = jit_if_REFCOUNTED(jit, op1_addr); |
11325 | 0 | ir_IF_FALSE(if_refcounted); |
11326 | 0 | ir_END_list(jit->return_inputs); |
11327 | 0 | ir_IF_TRUE(if_refcounted); |
11328 | 0 | } |
11329 | 0 | ref = jit_Z_PTR(jit, op1_addr); |
11330 | 0 | refcount = jit_GC_DELREF(jit, ref); |
11331 | |
|
11332 | 0 | if (RC_MAY_BE_1(op1_info)) { |
11333 | 0 | if (RC_MAY_BE_N(op1_info)) { |
11334 | 0 | ir_ref if_non_zero = ir_IF(refcount); |
11335 | 0 | ir_IF_TRUE(if_non_zero); |
11336 | 0 | ir_END_list(jit->return_inputs); |
11337 | 0 | ir_IF_FALSE(if_non_zero); |
11338 | 0 | } |
11339 | 0 | jit_ZVAL_DTOR(jit, ref, op1_info, opline); |
11340 | 0 | } |
11341 | 0 | if (return_value_used == -1) { |
11342 | 0 | ir_END_list(jit->return_inputs); |
11343 | 0 | } |
11344 | 0 | } |
11345 | 0 | } else if (return_value_used == -1) { |
11346 | 0 | if_return_value_used = ir_IF(return_value); |
11347 | 0 | ir_IF_FALSE_cold(if_return_value_used); |
11348 | 0 | ir_END_list(jit->return_inputs); |
11349 | 0 | } |
11350 | |
|
11351 | 0 | if (if_return_value_used) { |
11352 | 0 | ir_IF_TRUE(if_return_value_used); |
11353 | 0 | } |
11354 | |
|
11355 | 0 | if (return_value_used == 0) { |
11356 | 0 | if (jit->return_inputs) { |
11357 | 0 | ZEND_ASSERT(JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE); |
11358 | 0 | ir_END_list(jit->return_inputs); |
11359 | 0 | ir_MERGE_list(jit->return_inputs); |
11360 | 0 | jit->return_inputs = IR_UNUSED; |
11361 | 0 | } |
11362 | 0 | return 1; |
11363 | 0 | } |
11364 | | |
11365 | 0 | if (opline->op1_type == IS_CONST) { |
11366 | 0 | zval *zv = RT_CONSTANT(opline, opline->op1); |
11367 | |
|
11368 | 0 | jit_ZVAL_COPY_CONST(jit, ret_addr, MAY_BE_ANY, MAY_BE_ANY, zv, true); |
11369 | 0 | } else if (opline->op1_type == IS_TMP_VAR) { |
11370 | 0 | jit_ZVAL_COPY(jit, ret_addr, MAY_BE_ANY, op1_addr, op1_info, false); |
11371 | 0 | } else if (opline->op1_type == IS_CV) { |
11372 | 0 | if (op1_info & MAY_BE_REF) { |
11373 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
11374 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
11375 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
11376 | 0 | } |
11377 | |
|
11378 | 0 | if (op1_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
11379 | 0 | if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || |
11380 | 0 | (op1_info & (MAY_BE_REF|MAY_BE_OBJECT)) || |
11381 | 0 | !op_array->function_name) { |
11382 | 0 | jit_ZVAL_COPY(jit, ret_addr, MAY_BE_ANY, op1_addr, op1_info, true); |
11383 | 0 | } else if (return_value_used != 1) { |
11384 | 0 | jit_ZVAL_COPY(jit, ret_addr, MAY_BE_ANY, op1_addr, op1_info, false); |
11385 | | // JIT: if (EXPECTED(!(EX_CALL_INFO() & ZEND_CALL_CODE))) ZVAL_NULL(retval_ptr); |
11386 | 0 | jit_set_Z_TYPE_INFO(jit, op1_addr, IS_NULL); |
11387 | 0 | } else { |
11388 | 0 | jit_ZVAL_COPY(jit, ret_addr, MAY_BE_ANY, op1_addr, op1_info, false); |
11389 | 0 | } |
11390 | 0 | } else { |
11391 | 0 | jit_ZVAL_COPY(jit, ret_addr, MAY_BE_ANY, op1_addr, op1_info, false); |
11392 | 0 | } |
11393 | 0 | } else { |
11394 | 0 | if (op1_info & MAY_BE_REF) { |
11395 | 0 | ir_ref if_ref, ref2, if_non_zero; |
11396 | 0 | zend_jit_addr ref_addr; |
11397 | |
|
11398 | 0 | if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_REFERENCE); |
11399 | 0 | ir_IF_TRUE_cold(if_ref); |
11400 | | |
11401 | | // JIT: zend_refcounted *ref = Z_COUNTED_P(retval_ptr) |
11402 | 0 | ref = jit_Z_PTR(jit, op1_addr); |
11403 | | |
11404 | | // JIT: ZVAL_COPY_VALUE(return_value, &ref->value) |
11405 | 0 | ref2 = ir_ADD_OFFSET(ref, offsetof(zend_reference, val)); |
11406 | 0 | ref_addr = ZEND_ADDR_REF_ZVAL(ref2); |
11407 | 0 | jit_ZVAL_COPY(jit, ret_addr, MAY_BE_ANY, ref_addr, op1_info, false); |
11408 | 0 | ref2 = jit_GC_DELREF(jit, ref); |
11409 | 0 | if_non_zero = ir_IF(ref2); |
11410 | 0 | ir_IF_TRUE(if_non_zero); |
11411 | | |
11412 | | // JIT: if (IS_REFCOUNTED()) |
11413 | 0 | ir_ref if_refcounted = jit_if_REFCOUNTED(jit, ret_addr); |
11414 | 0 | ir_IF_FALSE(if_refcounted); |
11415 | 0 | ir_END_list(jit->return_inputs); |
11416 | 0 | ir_IF_TRUE(if_refcounted); |
11417 | | |
11418 | | // JIT: ADDREF |
11419 | 0 | ref2 = jit_Z_PTR(jit, ret_addr); |
11420 | 0 | jit_GC_ADDREF(jit, ref2); |
11421 | 0 | ir_END_list(jit->return_inputs); |
11422 | |
|
11423 | 0 | ir_IF_FALSE(if_non_zero); |
11424 | |
|
11425 | 0 | jit_EFREE(jit, ref, sizeof(zend_reference), op_array, opline); |
11426 | 0 | ir_END_list(jit->return_inputs); |
11427 | |
|
11428 | 0 | ir_IF_FALSE(if_ref); |
11429 | 0 | } |
11430 | 0 | jit_ZVAL_COPY(jit, ret_addr, MAY_BE_ANY, op1_addr, op1_info, false); |
11431 | 0 | } |
11432 | |
|
11433 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
11434 | 0 | if (jit->return_inputs) { |
11435 | 0 | ir_END_list(jit->return_inputs); |
11436 | 0 | ir_MERGE_list(jit->return_inputs); |
11437 | 0 | jit->return_inputs = IR_UNUSED; |
11438 | 0 | } |
11439 | 0 | } else { |
11440 | 0 | ir_END_list(jit->return_inputs); |
11441 | 0 | jit->b = -1; |
11442 | 0 | } |
11443 | |
|
11444 | 0 | return 1; |
11445 | 0 | } |
11446 | | |
11447 | | static int zend_jit_bind_global(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info) |
11448 | 0 | { |
11449 | 0 | zend_jit_addr op1_addr = OP1_ADDR(); |
11450 | 0 | zend_string *varname = Z_STR_P(RT_CONSTANT(opline, opline->op2)); |
11451 | 0 | ir_ref cache_slot_ref, idx_ref, num_used_ref, bucket_ref, ref, ref2; |
11452 | 0 | ir_ref if_fit, if_reference, if_same_key, fast_path; |
11453 | 0 | ir_ref slow_inputs = IR_UNUSED, end_inputs = IR_UNUSED; |
11454 | | |
11455 | | // JIT: idx = (uintptr_t)CACHED_PTR(opline->extended_value) - 1; |
11456 | 0 | cache_slot_ref = ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), opline->extended_value); |
11457 | 0 | idx_ref = ir_SUB_A(ir_LOAD_A(cache_slot_ref), ir_CONST_ADDR(1)); |
11458 | | |
11459 | | // JIT: if (EXPECTED(idx < EG(symbol_table).nNumUsed * sizeof(Bucket))) |
11460 | 0 | num_used_ref = ir_MUL_U32(ir_LOAD_U32(jit_EG(symbol_table.nNumUsed)), |
11461 | 0 | ir_CONST_U32(sizeof(Bucket))); |
11462 | 0 | if (sizeof(void*) == 8) { |
11463 | 0 | num_used_ref = ir_ZEXT_A(num_used_ref); |
11464 | 0 | } |
11465 | 0 | if_fit = ir_IF(ir_ULT(idx_ref, num_used_ref)); |
11466 | 0 | ir_IF_FALSE_cold(if_fit); |
11467 | 0 | ir_END_list(slow_inputs); |
11468 | 0 | ir_IF_TRUE(if_fit); |
11469 | | |
11470 | | // JIT: Bucket *p = (Bucket*)((char*)EG(symbol_table).arData + idx); |
11471 | 0 | bucket_ref = ir_ADD_A(ir_LOAD_A(jit_EG(symbol_table.arData)), idx_ref); |
11472 | 0 | if_reference = jit_if_Z_TYPE_ref(jit, bucket_ref, ir_CONST_U8(IS_REFERENCE)); |
11473 | 0 | ir_IF_FALSE_cold(if_reference); |
11474 | 0 | ir_END_list(slow_inputs); |
11475 | 0 | ir_IF_TRUE(if_reference); |
11476 | | |
11477 | | // JIT: (EXPECTED(p->key == varname)) |
11478 | 0 | if_same_key = ir_IF(ir_EQ(ir_LOAD_A(ir_ADD_OFFSET(bucket_ref, offsetof(Bucket, key))), ir_CONST_ADDR(varname))); |
11479 | 0 | ir_IF_FALSE_cold(if_same_key); |
11480 | 0 | ir_END_list(slow_inputs); |
11481 | 0 | ir_IF_TRUE(if_same_key); |
11482 | | |
11483 | | // JIT: GC_ADDREF(Z_PTR(p->val)) |
11484 | 0 | ref = jit_Z_PTR_ref(jit, bucket_ref); |
11485 | 0 | jit_GC_ADDREF(jit, ref); |
11486 | |
|
11487 | 0 | fast_path = ir_END(); |
11488 | 0 | ir_MERGE_list(slow_inputs); |
11489 | |
|
11490 | 0 | ref2 = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_fetch_global_helper), |
11491 | 0 | ir_CONST_ADDR(varname), |
11492 | 0 | cache_slot_ref); |
11493 | |
|
11494 | 0 | ir_MERGE_WITH(fast_path); |
11495 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
11496 | |
|
11497 | 0 | if (op1_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) { |
11498 | 0 | ir_ref if_refcounted = IR_UNUSED, refcount, if_non_zero, if_may_not_leak; |
11499 | |
|
11500 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
11501 | | // JIT: if (UNEXPECTED(Z_REFCOUNTED_P(variable_ptr))) |
11502 | 0 | if_refcounted = jit_if_REFCOUNTED(jit, op1_addr); |
11503 | 0 | ir_IF_TRUE_cold(if_refcounted); |
11504 | 0 | } |
11505 | | |
11506 | | // JIT:zend_refcounted *garbage = Z_COUNTED_P(variable_ptr); |
11507 | 0 | ref2 = jit_Z_PTR(jit, op1_addr); |
11508 | | |
11509 | | // JIT: ZVAL_REF(variable_ptr, ref) |
11510 | 0 | jit_set_Z_PTR(jit, op1_addr, ref); |
11511 | 0 | jit_set_Z_TYPE_INFO(jit, op1_addr, IS_REFERENCE_EX); |
11512 | | |
11513 | | // JIT: if (GC_DELREF(garbage) == 0) |
11514 | 0 | refcount = jit_GC_DELREF(jit, ref2); |
11515 | 0 | if_non_zero = ir_IF(refcount); |
11516 | 0 | if (!(op1_info & (MAY_BE_REF|MAY_BE_ARRAY|MAY_BE_OBJECT))) { |
11517 | 0 | ir_IF_TRUE(if_non_zero); |
11518 | 0 | ir_END_list(end_inputs); |
11519 | 0 | } |
11520 | 0 | ir_IF_FALSE(if_non_zero); |
11521 | |
|
11522 | 0 | jit_ZVAL_DTOR(jit, ref2, op1_info, opline); |
11523 | 0 | if (op1_info & (MAY_BE_REF|MAY_BE_ARRAY|MAY_BE_OBJECT)) { |
11524 | 0 | ir_END_list(end_inputs); |
11525 | 0 | ir_IF_TRUE(if_non_zero); |
11526 | | |
11527 | | // JIT: GC_ZVAL_CHECK_POSSIBLE_ROOT(variable_ptr) |
11528 | 0 | if_may_not_leak = jit_if_GC_MAY_NOT_LEAK(jit, ref2); |
11529 | 0 | ir_IF_TRUE(if_may_not_leak); |
11530 | 0 | ir_END_list(end_inputs); |
11531 | 0 | ir_IF_FALSE(if_may_not_leak); |
11532 | 0 | if (opline) { |
11533 | 0 | jit_SET_EX_OPLINE(jit, opline); |
11534 | 0 | } |
11535 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(gc_possible_root), ref2); |
11536 | 0 | } |
11537 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
11538 | 0 | ir_END_list(end_inputs); |
11539 | 0 | ir_IF_FALSE(if_refcounted); |
11540 | 0 | } |
11541 | 0 | } |
11542 | |
|
11543 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
11544 | | // JIT: ZVAL_REF(variable_ptr, ref) |
11545 | 0 | jit_set_Z_PTR(jit, op1_addr, ref); |
11546 | 0 | jit_set_Z_TYPE_INFO(jit, op1_addr, IS_REFERENCE_EX); |
11547 | 0 | } |
11548 | |
|
11549 | 0 | if (end_inputs) { |
11550 | 0 | ir_END_list(end_inputs); |
11551 | 0 | ir_MERGE_list(end_inputs); |
11552 | 0 | } |
11553 | |
|
11554 | 0 | return 1; |
11555 | 0 | } |
11556 | | |
11557 | | static int zend_jit_free(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, int may_throw) |
11558 | 0 | { |
11559 | 0 | zend_jit_addr op1_addr = OP1_ADDR(); |
11560 | |
|
11561 | 0 | if (op1_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_REF)) { |
11562 | 0 | if (may_throw) { |
11563 | 0 | jit_SET_EX_OPLINE(jit, opline); |
11564 | 0 | } |
11565 | 0 | if (opline->opcode == ZEND_FE_FREE && (op1_info & (MAY_BE_OBJECT|MAY_BE_REF))) { |
11566 | 0 | ir_ref ref, if_array, if_exists, end_inputs = IR_UNUSED; |
11567 | |
|
11568 | 0 | if (op1_info & MAY_BE_ARRAY) { |
11569 | 0 | if_array = jit_if_Z_TYPE(jit, op1_addr, IS_ARRAY); |
11570 | 0 | ir_IF_TRUE(if_array); |
11571 | 0 | ir_END_list(end_inputs); |
11572 | 0 | ir_IF_FALSE(if_array); |
11573 | 0 | } |
11574 | 0 | ref = ir_LOAD_U32(ir_ADD_OFFSET(jit_FP(jit), opline->op1.var + offsetof(zval, u2.fe_iter_idx))); |
11575 | 0 | if_exists = ir_IF(ir_EQ(ref, ir_CONST_U32(-1))); |
11576 | 0 | ir_IF_TRUE(if_exists); |
11577 | 0 | ir_END_list(end_inputs); |
11578 | 0 | ir_IF_FALSE(if_exists); |
11579 | |
|
11580 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_hash_iterator_del), ref); |
11581 | |
|
11582 | 0 | ir_END_list(end_inputs); |
11583 | 0 | ir_MERGE_list(end_inputs); |
11584 | 0 | } |
11585 | |
|
11586 | 0 | jit_ZVAL_PTR_DTOR(jit, op1_addr, op1_info, false, opline); |
11587 | |
|
11588 | 0 | if (may_throw) { |
11589 | 0 | zend_jit_check_exception(jit); |
11590 | 0 | } |
11591 | 0 | } |
11592 | |
|
11593 | 0 | return 1; |
11594 | 0 | } |
11595 | | |
11596 | | static int zend_jit_echo(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info) |
11597 | 0 | { |
11598 | 0 | if (opline->op1_type == IS_CONST) { |
11599 | 0 | zval *zv; |
11600 | 0 | size_t len; |
11601 | |
|
11602 | 0 | zv = RT_CONSTANT(opline, opline->op1); |
11603 | 0 | ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING); |
11604 | 0 | len = Z_STRLEN_P(zv); |
11605 | |
|
11606 | 0 | if (len > 0) { |
11607 | 0 | const char *str = Z_STRVAL_P(zv); |
11608 | |
|
11609 | 0 | jit_SET_EX_OPLINE(jit, opline); |
11610 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FUNC(zend_write), |
11611 | 0 | ir_CONST_ADDR(str), ir_CONST_ADDR(len)); |
11612 | |
|
11613 | 0 | zend_jit_check_exception(jit); |
11614 | 0 | } |
11615 | 0 | } else { |
11616 | 0 | zend_jit_addr op1_addr = OP1_ADDR(); |
11617 | 0 | ir_ref ref; |
11618 | |
|
11619 | 0 | ZEND_ASSERT((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) == MAY_BE_STRING); |
11620 | |
|
11621 | 0 | jit_SET_EX_OPLINE(jit, opline); |
11622 | |
|
11623 | 0 | ref = jit_Z_PTR(jit, op1_addr); |
11624 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FUNC(zend_write), |
11625 | 0 | ir_ADD_OFFSET(ref, offsetof(zend_string, val)), |
11626 | 0 | ir_LOAD_A(ir_ADD_OFFSET(ref, offsetof(zend_string, len)))); |
11627 | |
|
11628 | 0 | if (opline->op1_type & (IS_VAR|IS_TMP_VAR)) { |
11629 | 0 | jit_ZVAL_PTR_DTOR(jit, op1_addr, op1_info, false, opline); |
11630 | 0 | } |
11631 | |
|
11632 | 0 | zend_jit_check_exception(jit); |
11633 | 0 | } |
11634 | 0 | return 1; |
11635 | 0 | } |
11636 | | |
11637 | | static int zend_jit_strlen(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, zend_jit_addr res_addr) |
11638 | 0 | { |
11639 | 0 | if (opline->op1_type == IS_CONST) { |
11640 | 0 | zval *zv; |
11641 | 0 | size_t len; |
11642 | |
|
11643 | 0 | zv = RT_CONSTANT(opline, opline->op1); |
11644 | 0 | ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING); |
11645 | 0 | len = Z_STRLEN_P(zv); |
11646 | |
|
11647 | 0 | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(len)); |
11648 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
11649 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
11650 | 0 | } else if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, MAY_BE_LONG)) { |
11651 | 0 | return 0; |
11652 | 0 | } |
11653 | 0 | } else { |
11654 | 0 | ir_ref ref; |
11655 | |
|
11656 | 0 | ZEND_ASSERT((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) == MAY_BE_STRING); |
11657 | |
|
11658 | 0 | ref = jit_Z_PTR(jit, op1_addr); |
11659 | 0 | ref = ir_LOAD_L(ir_ADD_OFFSET(ref, offsetof(zend_string, len))); |
11660 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
11661 | |
|
11662 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
11663 | 0 | if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, MAY_BE_LONG)) { |
11664 | 0 | return 0; |
11665 | 0 | } |
11666 | 0 | } else { |
11667 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
11668 | 0 | } |
11669 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
11670 | 0 | } |
11671 | 0 | return 1; |
11672 | 0 | } |
11673 | | |
11674 | | static int zend_jit_count(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, zend_jit_addr res_addr, int may_throw) |
11675 | 0 | { |
11676 | 0 | if (opline->op1_type == IS_CONST) { |
11677 | 0 | zval *zv; |
11678 | 0 | zend_long count; |
11679 | |
|
11680 | 0 | zv = RT_CONSTANT(opline, opline->op1); |
11681 | 0 | ZEND_ASSERT(Z_TYPE_P(zv) == IS_ARRAY); |
11682 | 0 | count = zend_hash_num_elements(Z_ARRVAL_P(zv)); |
11683 | |
|
11684 | 0 | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(count)); |
11685 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
11686 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
11687 | 0 | } else if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, MAY_BE_LONG)) { |
11688 | 0 | return 0; |
11689 | 0 | } |
11690 | 0 | } else { |
11691 | 0 | ir_ref ref; |
11692 | |
|
11693 | 0 | ZEND_ASSERT((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) == MAY_BE_ARRAY); |
11694 | | // Note: See the implementation of ZEND_COUNT in Zend/zend_vm_def.h - arrays do not contain IS_UNDEF starting in php 8.1+. |
11695 | |
|
11696 | 0 | ref = jit_Z_PTR(jit, op1_addr); |
11697 | 0 | if (sizeof(void*) == 8) { |
11698 | 0 | ref = ir_LOAD_U32(ir_ADD_OFFSET(ref, offsetof(HashTable, nNumOfElements))); |
11699 | 0 | ref = ir_ZEXT_L(ref); |
11700 | 0 | } else { |
11701 | 0 | ref = ir_LOAD_L(ir_ADD_OFFSET(ref, offsetof(HashTable, nNumOfElements))); |
11702 | 0 | } |
11703 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
11704 | |
|
11705 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
11706 | 0 | if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, MAY_BE_LONG)) { |
11707 | 0 | return 0; |
11708 | 0 | } |
11709 | 0 | } else { |
11710 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
11711 | 0 | } |
11712 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
11713 | 0 | } |
11714 | | |
11715 | 0 | if (may_throw) { |
11716 | 0 | zend_jit_check_exception(jit); |
11717 | 0 | } |
11718 | 0 | return 1; |
11719 | 0 | } |
11720 | | |
11721 | | static int zend_jit_in_array(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, uint8_t smart_branch_opcode, uint32_t target_label, uint32_t target_label2, const void *exit_addr) |
11722 | 0 | { |
11723 | 0 | HashTable *ht = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2)); |
11724 | 0 | zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
11725 | 0 | ir_ref ref; |
11726 | |
|
11727 | 0 | ZEND_ASSERT(opline->op1_type != IS_VAR && opline->op1_type != IS_TMP_VAR); |
11728 | 0 | ZEND_ASSERT((op1_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF)) == MAY_BE_STRING); |
11729 | | |
11730 | | // JIT: result = zend_hash_find_ex(ht, Z_STR_P(op1), OP1_TYPE == IS_CONST); |
11731 | 0 | if (opline->op1_type != IS_CONST) { |
11732 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_find), |
11733 | 0 | ir_CONST_ADDR(ht), |
11734 | 0 | jit_Z_PTR(jit, op1_addr)); |
11735 | 0 | } else { |
11736 | 0 | zend_string *str = Z_STR_P(RT_CONSTANT(opline, opline->op1)); |
11737 | |
|
11738 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_find_known_hash), |
11739 | 0 | ir_CONST_ADDR(ht), ir_CONST_ADDR(str)); |
11740 | 0 | } |
11741 | |
|
11742 | 0 | if (exit_addr) { |
11743 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
11744 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
11745 | 0 | } else { |
11746 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
11747 | 0 | } |
11748 | 0 | } else if (smart_branch_opcode) { |
11749 | 0 | zend_basic_block *bb; |
11750 | |
|
11751 | 0 | ZEND_ASSERT(jit->b >= 0); |
11752 | 0 | bb = &jit->ssa->cfg.blocks[jit->b]; |
11753 | 0 | ZEND_ASSERT(bb->successors_count == 2); |
11754 | 0 | ref = jit_IF_ex(jit, ref, |
11755 | 0 | (smart_branch_opcode == ZEND_JMPZ) ? target_label2 : target_label); |
11756 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ref); |
11757 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[1], jit->b, ref); |
11758 | 0 | jit->b = -1; |
11759 | 0 | } else { |
11760 | 0 | jit_set_Z_TYPE_INFO_ex(jit, res_addr, |
11761 | 0 | ir_ADD_U32(ir_ZEXT_U32(ir_NE(ref, IR_NULL)), ir_CONST_U32(IS_FALSE))); |
11762 | 0 | } |
11763 | |
|
11764 | 0 | return 1; |
11765 | 0 | } |
11766 | | |
11767 | | static int zend_jit_rope(zend_jit_ctx *jit, const zend_op *opline, uint32_t op2_info) |
11768 | 0 | { |
11769 | 0 | uint32_t offset; |
11770 | |
|
11771 | 0 | offset = (opline->opcode == ZEND_ROPE_INIT) ? |
11772 | 0 | opline->result.var : |
11773 | 0 | opline->op1.var + opline->extended_value * sizeof(zend_string*); |
11774 | |
|
11775 | 0 | if (opline->op2_type == IS_CONST) { |
11776 | 0 | zval *zv = RT_CONSTANT(opline, opline->op2); |
11777 | 0 | zend_string *str; |
11778 | |
|
11779 | 0 | ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING); |
11780 | 0 | str = Z_STR_P(zv); |
11781 | |
|
11782 | 0 | ir_STORE(ir_ADD_OFFSET(jit_FP(jit), offset), ir_CONST_ADDR(str)); |
11783 | 0 | } else { |
11784 | 0 | zend_jit_addr op2_addr = OP2_ADDR(); |
11785 | 0 | ir_ref ref; |
11786 | |
|
11787 | 0 | ZEND_ASSERT((op2_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) == MAY_BE_STRING); |
11788 | |
|
11789 | 0 | ref = jit_Z_PTR(jit, op2_addr); |
11790 | 0 | ir_STORE(ir_ADD_OFFSET(jit_FP(jit), offset), ref); |
11791 | 0 | if (opline->op2_type == IS_CV) { |
11792 | 0 | ir_ref if_refcounted, long_path; |
11793 | |
|
11794 | 0 | if_refcounted = jit_if_REFCOUNTED(jit, op2_addr); |
11795 | 0 | ir_IF_TRUE(if_refcounted); |
11796 | 0 | jit_GC_ADDREF(jit, ref); |
11797 | 0 | long_path = ir_END(); |
11798 | |
|
11799 | 0 | ir_IF_FALSE(if_refcounted); |
11800 | 0 | ir_MERGE_WITH(long_path); |
11801 | 0 | } |
11802 | 0 | } |
11803 | |
|
11804 | 0 | if (opline->opcode == ZEND_ROPE_END) { |
11805 | 0 | zend_jit_addr res_addr = RES_ADDR(); |
11806 | 0 | ir_ref ref; |
11807 | |
|
11808 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_rope_end), |
11809 | 0 | ir_ADD_OFFSET(jit_FP(jit), opline->op1.var), |
11810 | 0 | ir_CONST_U32(opline->extended_value)); |
11811 | |
|
11812 | 0 | jit_set_Z_PTR(jit, res_addr, ref); |
11813 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_STRING_EX); |
11814 | 0 | } |
11815 | |
|
11816 | 0 | return 1; |
11817 | 0 | } |
11818 | | |
11819 | | static int zend_jit_zval_copy_deref_reg(zend_jit_ctx *jit, zend_jit_addr res_addr, uint32_t res_info, zend_jit_addr val_addr, ir_ref type, ir_ref *values) |
11820 | 0 | { |
11821 | 0 | ir_ref if_type, val; |
11822 | |
|
11823 | 0 | if (res_info == MAY_BE_LONG) { |
11824 | 0 | if_type = ir_IF(ir_EQ(type, ir_CONST_U32(IS_LONG))); |
11825 | 0 | ir_IF_TRUE(if_type); |
11826 | 0 | val = jit_ZVAL_ADDR(jit, val_addr); |
11827 | 0 | ir_END_PHI_list(*values, val); |
11828 | 0 | ir_IF_FALSE(if_type); |
11829 | 0 | val = ir_ADD_OFFSET(jit_Z_PTR(jit, val_addr), offsetof(zend_reference, val)); |
11830 | 0 | ir_END_PHI_list(*values, val); |
11831 | 0 | } else if (res_info == MAY_BE_DOUBLE) { |
11832 | 0 | if_type = ir_IF(ir_EQ(type, ir_CONST_U32(IS_DOUBLE))); |
11833 | 0 | ir_IF_TRUE(if_type); |
11834 | 0 | val = jit_ZVAL_ADDR(jit, val_addr); |
11835 | 0 | ir_END_PHI_list(*values, val); |
11836 | 0 | ir_IF_FALSE(if_type); |
11837 | 0 | val = ir_ADD_OFFSET(jit_Z_PTR(jit, val_addr), offsetof(zend_reference, val)); |
11838 | 0 | ir_END_PHI_list(*values, val); |
11839 | 0 | } else { |
11840 | 0 | ZEND_UNREACHABLE(); |
11841 | 0 | } |
11842 | 0 | return 1; |
11843 | 0 | } |
11844 | | |
11845 | | static int zend_jit_zval_copy_deref(zend_jit_ctx *jit, zend_jit_addr res_addr, zend_jit_addr val_addr, ir_ref type) |
11846 | 0 | { |
11847 | 0 | ir_ref if_refcounted, if_reference, if_refcounted2, ptr, val2, ptr2, type2; |
11848 | 0 | ir_refs *merge_inputs, *types, *ptrs; |
11849 | | #if SIZEOF_ZEND_LONG == 4 |
11850 | | ir_ref val = jit_ZVAL_ADDR(jit, val_addr); |
11851 | | ir_refs *values; /* we need this only for zval.w2 copy */ |
11852 | | #endif |
11853 | |
|
11854 | 0 | ir_refs_init(merge_inputs, 4); |
11855 | 0 | ir_refs_init(types, 4); |
11856 | 0 | ir_refs_init(ptrs, 4); |
11857 | | #if SIZEOF_ZEND_LONG == 4 |
11858 | | ir_refs_init(values, 4); |
11859 | | #endif |
11860 | | |
11861 | | // JIT: ptr = Z_PTR_P(val); |
11862 | 0 | ptr = jit_Z_PTR(jit, val_addr); |
11863 | | |
11864 | | // JIT: if (Z_OPT_REFCOUNTED_P(val)) { |
11865 | 0 | if_refcounted = ir_IF(ir_AND_U32(type, ir_CONST_U32(Z_TYPE_FLAGS_MASK))); |
11866 | 0 | ir_IF_FALSE_cold(if_refcounted); |
11867 | 0 | ir_refs_add(merge_inputs, ir_END()); |
11868 | 0 | ir_refs_add(types, type); |
11869 | 0 | ir_refs_add(ptrs, ptr); |
11870 | | #if SIZEOF_ZEND_LONG == 4 |
11871 | | ir_refs_add(values, val); |
11872 | | #endif |
11873 | |
|
11874 | 0 | ir_IF_TRUE(if_refcounted); |
11875 | | |
11876 | | // JIT: if (UNEXPECTED(Z_OPT_ISREF_P(val))) { |
11877 | 0 | if_reference = ir_IF(ir_EQ(type, ir_CONST_U32(IS_REFERENCE_EX))); |
11878 | | // if_reference = ir_IF(ir_EQ(ir_TRUNC_U8(type), ir_CONST_U8(IS_REFERENCE))); // TODO: fix IR to avoid need for extra register ??? |
11879 | 0 | ir_IF_TRUE(if_reference); |
11880 | | |
11881 | | // JIT: val = Z_REFVAL_P(val); |
11882 | 0 | val2 = ir_ADD_OFFSET(ptr, offsetof(zend_reference, val)); |
11883 | 0 | type2 = jit_Z_TYPE_INFO_ref(jit, val2); |
11884 | 0 | ptr2 = jit_Z_PTR_ref(jit, val2); |
11885 | | |
11886 | | // JIT: if (Z_OPT_REFCOUNTED_P(val)) { |
11887 | 0 | if_refcounted2 = ir_IF(ir_AND_U32(type2, ir_CONST_U32(Z_TYPE_FLAGS_MASK))); |
11888 | 0 | ir_IF_FALSE_cold(if_refcounted2); |
11889 | 0 | ir_refs_add(merge_inputs, ir_END()); |
11890 | 0 | ir_refs_add(types, type2); |
11891 | 0 | ir_refs_add(ptrs, ptr2); |
11892 | | #if SIZEOF_ZEND_LONG == 4 |
11893 | | ir_refs_add(values, val2); |
11894 | | #endif |
11895 | |
|
11896 | 0 | ir_IF_TRUE(if_refcounted2); |
11897 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_reference); |
11898 | 0 | type = ir_PHI_2(IR_U32, type2, type); |
11899 | 0 | ptr = ir_PHI_2(IR_ADDR, ptr2, ptr); |
11900 | | #if SIZEOF_ZEND_LONG == 4 |
11901 | | val = ir_PHI_2(IR_ADDR, val2, val); |
11902 | | #endif |
11903 | | |
11904 | | // JIT: Z_ADDREF_P(val); |
11905 | 0 | jit_GC_ADDREF(jit, ptr); |
11906 | 0 | ir_refs_add(merge_inputs, ir_END()); |
11907 | 0 | ir_refs_add(types, type); |
11908 | 0 | ir_refs_add(ptrs, ptr); |
11909 | | #if SIZEOF_ZEND_LONG == 4 |
11910 | | ir_refs_add(values, val); |
11911 | | #endif |
11912 | |
|
11913 | 0 | ir_MERGE_N(merge_inputs->count, merge_inputs->refs); |
11914 | 0 | type = ir_PHI_N(IR_U32, types->count, types->refs); |
11915 | 0 | ptr = ir_PHI_N(IR_ADDR, ptrs->count, ptrs->refs); |
11916 | | #if SIZEOF_ZEND_LONG == 4 |
11917 | | val = ir_PHI_N(IR_ADDR, values->count, values->refs); |
11918 | | val_addr = ZEND_ADDR_REF_ZVAL(val); |
11919 | | #endif |
11920 | | |
11921 | | // JIT: Z_PTR_P(res) = ptr; |
11922 | 0 | jit_set_Z_PTR(jit, res_addr, ptr); |
11923 | | #if SIZEOF_ZEND_LONG == 4 |
11924 | | jit_set_Z_W2(jit, res_addr, jit_Z_W2(jit, val_addr)); |
11925 | | #endif |
11926 | 0 | jit_set_Z_TYPE_INFO_ex(jit, res_addr, type); |
11927 | |
|
11928 | 0 | return 1; |
11929 | 0 | } |
11930 | | |
11931 | | static int zend_jit_fetch_dimension_address_inner(zend_jit_ctx *jit, |
11932 | | const zend_op *opline, |
11933 | | uint32_t type, |
11934 | | uint32_t op1_info, |
11935 | | uint32_t op2_info, |
11936 | | zend_jit_addr op2_addr, |
11937 | | zend_ssa_range *op2_range, |
11938 | | uint8_t dim_type, |
11939 | | const void *found_exit_addr, |
11940 | | const void *not_found_exit_addr, |
11941 | | const void *exit_addr, |
11942 | | bool result_type_guard, |
11943 | | ir_ref ht_ref, |
11944 | | ir_refs *found_inputs, |
11945 | | ir_refs *found_vals, |
11946 | | ir_ref *end_inputs, |
11947 | | ir_ref *not_found_inputs) |
11948 | 0 | { |
11949 | 0 | zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
11950 | 0 | ir_ref ref = IR_UNUSED, cond, if_found; |
11951 | 0 | ir_ref if_type = IS_UNUSED; |
11952 | 0 | ir_refs *test_zval_inputs, *test_zval_values; |
11953 | |
|
11954 | 0 | ir_refs_init(test_zval_inputs, 4); |
11955 | 0 | ir_refs_init(test_zval_values, 4); |
11956 | |
|
11957 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
11958 | 0 | && type == BP_VAR_R |
11959 | 0 | && !exit_addr) { |
11960 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
11961 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
11962 | 0 | if (!exit_addr) { |
11963 | 0 | return 0; |
11964 | 0 | } |
11965 | 0 | } |
11966 | | |
11967 | 0 | if (op2_info & MAY_BE_LONG) { |
11968 | 0 | bool op2_loaded = false; |
11969 | 0 | bool packed_loaded = false; |
11970 | 0 | bool bad_packed_key = false; |
11971 | 0 | ir_ref if_packed = IS_UNDEF; |
11972 | 0 | ir_ref h = IR_UNUSED; |
11973 | 0 | ir_ref idx_not_found_inputs = IR_UNUSED; |
11974 | |
|
11975 | 0 | if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - MAY_BE_LONG)) { |
11976 | | // JIT: if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) |
11977 | 0 | if_type = jit_if_Z_TYPE(jit, op2_addr, IS_LONG); |
11978 | 0 | ir_IF_TRUE(if_type); |
11979 | 0 | } |
11980 | 0 | if (op1_info & MAY_BE_PACKED_GUARD) { |
11981 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_PACKED_GUARD); |
11982 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
11983 | |
|
11984 | 0 | if (!exit_addr) { |
11985 | 0 | return 0; |
11986 | 0 | } |
11987 | 0 | cond = ir_AND_U32( |
11988 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(ht_ref, offsetof(zend_array, u.flags))), |
11989 | 0 | ir_CONST_U32(HASH_FLAG_PACKED)); |
11990 | 0 | if (op1_info & MAY_BE_ARRAY_PACKED) { |
11991 | 0 | ir_GUARD(cond, ir_CONST_ADDR(exit_addr)); |
11992 | 0 | } else { |
11993 | 0 | ir_GUARD_NOT(cond, ir_CONST_ADDR(exit_addr)); |
11994 | 0 | } |
11995 | 0 | } |
11996 | 0 | if (type == BP_VAR_W) { |
11997 | | // JIT: hval = Z_LVAL_P(dim); |
11998 | 0 | h = jit_Z_LVAL(jit, op2_addr); |
11999 | 0 | op2_loaded = true; |
12000 | 0 | } |
12001 | 0 | if (op1_info & MAY_BE_ARRAY_PACKED) { |
12002 | 0 | zend_long val = -1; |
12003 | |
|
12004 | 0 | if (Z_MODE(op2_addr) == IS_CONST_ZVAL) { |
12005 | 0 | val = Z_LVAL_P(Z_ZV(op2_addr)); |
12006 | 0 | if (val >= 0 && val < HT_MAX_SIZE) { |
12007 | 0 | packed_loaded = true; |
12008 | 0 | } else { |
12009 | 0 | bad_packed_key = true; |
12010 | 0 | } |
12011 | 0 | h = ir_CONST_LONG(val); |
12012 | 0 | } else { |
12013 | 0 | if (!op2_loaded) { |
12014 | | // JIT: hval = Z_LVAL_P(dim); |
12015 | 0 | h = jit_Z_LVAL(jit, op2_addr); |
12016 | 0 | op2_loaded = true; |
12017 | 0 | } |
12018 | 0 | packed_loaded = true; |
12019 | 0 | } |
12020 | |
|
12021 | 0 | if (dim_type == IS_UNDEF && type == BP_VAR_W && packed_loaded) { |
12022 | | /* don't generate "fast" code for packed array */ |
12023 | 0 | packed_loaded = false; |
12024 | 0 | } |
12025 | |
|
12026 | 0 | if (packed_loaded) { |
12027 | | // JIT: ZEND_HASH_INDEX_FIND(ht, hval, retval, num_undef); |
12028 | 0 | if (op1_info & MAY_BE_ARRAY_NUMERIC_HASH) { |
12029 | 0 | if_packed = ir_IF( |
12030 | 0 | ir_AND_U32( |
12031 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(ht_ref, offsetof(zend_array, u.flags))), |
12032 | 0 | ir_CONST_U32(HASH_FLAG_PACKED))); |
12033 | 0 | ir_IF_TRUE(if_packed); |
12034 | 0 | } |
12035 | | // JIT: if (EXPECTED((zend_ulong)(_h) < (zend_ulong)(_ht)->nNumUsed)) |
12036 | 0 | ref = ir_LOAD_U32(ir_ADD_OFFSET(ht_ref, offsetof(zend_array, nNumUsed))); |
12037 | 0 | #if SIZEOF_ZEND_LONG == 8 |
12038 | 0 | if ((Z_MODE(op2_addr) == IS_CONST_ZVAL && val >= 0 && val <= UINT32_MAX) |
12039 | 0 | || (op2_range && op2_range->min >= 0 && op2_range->max <= UINT32_MAX)) { |
12040 | | /* comapre only the lower 32-bits to allow load fusion on x86_64 */ |
12041 | 0 | cond = ir_ULT(ir_TRUNC_U32(h), ref); |
12042 | 0 | } else { |
12043 | 0 | cond = ir_ULT(h, ir_ZEXT_L(ref)); |
12044 | 0 | } |
12045 | | #else |
12046 | | cond = ir_ULT(h, ref); |
12047 | | #endif |
12048 | 0 | if (type == BP_JIT_IS) { |
12049 | 0 | if (not_found_exit_addr) { |
12050 | 0 | ir_GUARD(cond, ir_CONST_ADDR(not_found_exit_addr)); |
12051 | 0 | } else { |
12052 | 0 | ir_ref if_fit = ir_IF(cond); |
12053 | 0 | ir_IF_FALSE(if_fit); |
12054 | 0 | ir_END_list(*end_inputs); |
12055 | 0 | ir_IF_TRUE(if_fit); |
12056 | 0 | } |
12057 | 0 | } else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) { |
12058 | 0 | ir_GUARD(cond, ir_CONST_ADDR(exit_addr)); |
12059 | 0 | } else if (type == BP_VAR_IS && not_found_exit_addr) { |
12060 | 0 | ir_GUARD(cond, ir_CONST_ADDR(not_found_exit_addr)); |
12061 | 0 | } else if (type == BP_VAR_RW && not_found_exit_addr) { |
12062 | 0 | ir_GUARD(cond, ir_CONST_ADDR(not_found_exit_addr)); |
12063 | 0 | } else if (type == BP_VAR_IS && result_type_guard) { |
12064 | 0 | ir_ref if_fit = ir_IF(cond); |
12065 | 0 | ir_IF_FALSE(if_fit); |
12066 | 0 | ir_END_list(*not_found_inputs); |
12067 | 0 | ir_IF_TRUE(if_fit); |
12068 | 0 | } else { |
12069 | 0 | ir_ref if_fit = ir_IF(cond); |
12070 | 0 | ir_IF_FALSE(if_fit); |
12071 | 0 | ir_END_list(idx_not_found_inputs); |
12072 | 0 | ir_IF_TRUE(if_fit); |
12073 | 0 | } |
12074 | | // JIT: _ret = &_ht->arPacked[h]; |
12075 | 0 | ref = ir_MUL_L(h, ir_CONST_LONG(sizeof(zval))); |
12076 | 0 | ref = ir_BITCAST_A(ref); |
12077 | 0 | ref = ir_ADD_A(ir_LOAD_A(ir_ADD_OFFSET(ht_ref, offsetof(zend_array, arPacked))), ref); |
12078 | 0 | if (type == BP_JIT_IS) { |
12079 | 0 | ir_refs_add(test_zval_values, ref); |
12080 | 0 | ir_refs_add(test_zval_inputs, ir_END()); |
12081 | 0 | } |
12082 | 0 | } |
12083 | 0 | } |
12084 | 0 | switch (type) { |
12085 | 0 | case BP_JIT_IS: |
12086 | 0 | if (op1_info & MAY_BE_ARRAY_NUMERIC_HASH) { |
12087 | 0 | if (if_packed) { |
12088 | 0 | ir_IF_FALSE(if_packed); |
12089 | 0 | if_packed = IR_UNUSED; |
12090 | 0 | } |
12091 | 0 | if (!op2_loaded) { |
12092 | | // JIT: hval = Z_LVAL_P(dim); |
12093 | 0 | h = jit_Z_LVAL(jit, op2_addr); |
12094 | 0 | op2_loaded = true; |
12095 | 0 | } |
12096 | 0 | if (packed_loaded) { |
12097 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(_zend_hash_index_find), ht_ref, h); |
12098 | 0 | } else { |
12099 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_index_find), ht_ref, h); |
12100 | 0 | } |
12101 | 0 | if (not_found_exit_addr) { |
12102 | 0 | ir_GUARD(ref, ir_CONST_ADDR(not_found_exit_addr)); |
12103 | 0 | } else { |
12104 | 0 | if_found = ir_IF(ref); |
12105 | 0 | ir_IF_FALSE(if_found); |
12106 | 0 | ir_END_list(*end_inputs); |
12107 | 0 | ir_IF_TRUE(if_found); |
12108 | 0 | } |
12109 | 0 | ir_refs_add(test_zval_values, ref); |
12110 | 0 | ir_refs_add(test_zval_inputs, ir_END()); |
12111 | 0 | } else if (!not_found_exit_addr && !packed_loaded) { |
12112 | 0 | ir_END_list(*end_inputs); |
12113 | 0 | } |
12114 | 0 | break; |
12115 | 0 | case BP_VAR_R: |
12116 | 0 | case BP_VAR_IS: |
12117 | 0 | case BP_VAR_UNSET: |
12118 | 0 | if (packed_loaded) { |
12119 | 0 | ir_ref type_ref = jit_Z_TYPE_ref(jit, ref); |
12120 | |
|
12121 | 0 | if (result_type_guard) { |
12122 | | /* perform IS_UNDEF check only after result type guard (during deoptimization) */ |
12123 | 0 | } else if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) { |
12124 | 0 | ir_GUARD(type_ref, ir_CONST_ADDR(exit_addr)); |
12125 | 0 | } else if (type == BP_VAR_IS && not_found_exit_addr) { |
12126 | 0 | ir_GUARD(type_ref, ir_CONST_ADDR(not_found_exit_addr)); |
12127 | 0 | } else { |
12128 | 0 | ir_ref if_def = ir_IF(type_ref); |
12129 | 0 | ir_IF_FALSE(if_def); |
12130 | 0 | ir_END_list(idx_not_found_inputs); |
12131 | 0 | ir_IF_TRUE(if_def); |
12132 | 0 | } |
12133 | 0 | ir_refs_add(found_inputs, ir_END()); |
12134 | 0 | ir_refs_add(found_vals, ref); |
12135 | 0 | } |
12136 | 0 | if (op1_info & MAY_BE_ARRAY_NUMERIC_HASH) { |
12137 | 0 | if (if_packed) { |
12138 | 0 | ir_IF_FALSE(if_packed); |
12139 | 0 | if_packed = IR_UNUSED; |
12140 | 0 | } |
12141 | 0 | if (!op2_loaded) { |
12142 | | // JIT: hval = Z_LVAL_P(dim); |
12143 | 0 | h = jit_Z_LVAL(jit, op2_addr); |
12144 | 0 | op2_loaded = true; |
12145 | 0 | } |
12146 | 0 | if (packed_loaded) { |
12147 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(_zend_hash_index_find), ht_ref, h); |
12148 | 0 | } else { |
12149 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_index_find), ht_ref, h); |
12150 | 0 | } |
12151 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) { |
12152 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
12153 | 0 | } else if (type == BP_VAR_IS && not_found_exit_addr) { |
12154 | 0 | ir_GUARD(ref, ir_CONST_ADDR(not_found_exit_addr)); |
12155 | 0 | } else if (type == BP_VAR_IS && result_type_guard) { |
12156 | 0 | if_found = ir_IF(ref); |
12157 | 0 | ir_IF_FALSE(if_found); |
12158 | 0 | ir_END_list(*not_found_inputs); |
12159 | 0 | ir_IF_TRUE(if_found); |
12160 | 0 | } else { |
12161 | 0 | if_found = ir_IF(ref); |
12162 | 0 | ir_IF_FALSE(if_found); |
12163 | 0 | ir_END_list(idx_not_found_inputs); |
12164 | 0 | ir_IF_TRUE(if_found); |
12165 | 0 | } |
12166 | 0 | ir_refs_add(found_inputs, ir_END()); |
12167 | 0 | ir_refs_add(found_vals, ref); |
12168 | 0 | } else if (!packed_loaded) { |
12169 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) { |
12170 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
12171 | 0 | } else if (type == BP_VAR_IS && not_found_exit_addr) { |
12172 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(not_found_exit_addr)); |
12173 | 0 | } else if (type == BP_VAR_IS && result_type_guard) { |
12174 | 0 | ir_END_list(*not_found_inputs); |
12175 | 0 | } else { |
12176 | 0 | ir_END_list(idx_not_found_inputs); |
12177 | 0 | } |
12178 | 0 | } |
12179 | |
|
12180 | 0 | if (idx_not_found_inputs) { |
12181 | 0 | ir_MERGE_list(idx_not_found_inputs); |
12182 | 0 | switch (type) { |
12183 | 0 | case BP_VAR_R: |
12184 | 0 | ZEND_ASSERT(JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE); |
12185 | | // JIT: zend_error(E_WARNING,"Undefined array key " ZEND_LONG_FMT, hval); |
12186 | | // JIT: retval = &EG(uninitialized_zval); |
12187 | 0 | jit_SET_EX_OPLINE(jit, opline); |
12188 | 0 | if (Z_MODE(op2_addr) == IS_REG) { |
12189 | 0 | if (!op2_loaded) { |
12190 | | // JIT: hval = Z_LVAL_P(dim); |
12191 | 0 | h = jit_Z_LVAL(jit, op2_addr); |
12192 | 0 | } |
12193 | 0 | if (GCC_GLOBAL_REGS) { |
12194 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_long_key_ex), h); |
12195 | 0 | } else { |
12196 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_long_key_ex), h, jit_FP(jit)); |
12197 | 0 | } |
12198 | 0 | } else { |
12199 | 0 | ir_CALL(IR_VOID, jit_STUB_FUNC_ADDR(jit, jit_stub_undefined_offset, IR_FASTCALL_FUNC)); |
12200 | 0 | } |
12201 | 0 | ir_END_list(*end_inputs); |
12202 | 0 | break; |
12203 | 0 | case BP_VAR_IS: |
12204 | 0 | case BP_VAR_UNSET: |
12205 | 0 | if (!not_found_exit_addr) { |
12206 | | // JIT: retval = &EG(uninitialized_zval); |
12207 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
12208 | 0 | ir_END_list(*end_inputs); |
12209 | 0 | } |
12210 | 0 | break; |
12211 | 0 | default: |
12212 | 0 | ZEND_UNREACHABLE(); |
12213 | 0 | } |
12214 | 0 | } |
12215 | 0 | break; |
12216 | 0 | case BP_VAR_RW: |
12217 | 0 | if (packed_loaded) { |
12218 | 0 | if (not_found_exit_addr) { |
12219 | 0 | ir_refs_add(found_inputs, ir_END()); |
12220 | 0 | ir_refs_add(found_vals, ref); |
12221 | 0 | } else { |
12222 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE_ref(jit, ref)); |
12223 | 0 | ir_IF_TRUE(if_def); |
12224 | 0 | ir_refs_add(found_inputs, ir_END()); |
12225 | 0 | ir_refs_add(found_vals, ref); |
12226 | 0 | ir_IF_FALSE_cold(if_def); |
12227 | 0 | ir_END_list(idx_not_found_inputs); |
12228 | 0 | } |
12229 | 0 | } |
12230 | 0 | if (!packed_loaded || |
12231 | 0 | !not_found_exit_addr || |
12232 | 0 | (op1_info & MAY_BE_ARRAY_NUMERIC_HASH)) { |
12233 | 0 | if (if_packed) { |
12234 | 0 | ir_IF_FALSE(if_packed); |
12235 | 0 | if_packed = IR_UNUSED; |
12236 | 0 | ir_END_list(idx_not_found_inputs); |
12237 | 0 | } else if (!packed_loaded) { |
12238 | 0 | ir_END_list(idx_not_found_inputs); |
12239 | 0 | } |
12240 | |
|
12241 | 0 | ir_MERGE_list(idx_not_found_inputs); |
12242 | 0 | if (!op2_loaded) { |
12243 | | // JIT: hval = Z_LVAL_P(dim); |
12244 | 0 | h = jit_Z_LVAL(jit, op2_addr); |
12245 | 0 | } |
12246 | 0 | if (packed_loaded) { |
12247 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_hash_index_lookup_rw_no_packed), |
12248 | 0 | ht_ref, h); |
12249 | 0 | } else { |
12250 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_hash_index_lookup_rw), ht_ref, h); |
12251 | 0 | } |
12252 | 0 | if (not_found_exit_addr) { |
12253 | 0 | ir_GUARD(ref, ir_CONST_ADDR(not_found_exit_addr)); |
12254 | 0 | } else { |
12255 | 0 | if_found = ir_IF(ref); |
12256 | 0 | ir_IF_FALSE(if_found); |
12257 | 0 | ir_END_list(*end_inputs); |
12258 | 0 | ir_IF_TRUE(if_found); |
12259 | 0 | } |
12260 | 0 | ir_refs_add(found_inputs, ir_END()); |
12261 | 0 | ir_refs_add(found_vals, ref); |
12262 | 0 | } |
12263 | 0 | break; |
12264 | 0 | case BP_VAR_W: |
12265 | 0 | if (packed_loaded) { |
12266 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE_ref(jit, ref)); |
12267 | 0 | ir_IF_TRUE_cold(if_def); |
12268 | 0 | ir_refs_add(found_inputs, ir_END()); |
12269 | 0 | ir_refs_add(found_vals, ref); |
12270 | 0 | ir_IF_FALSE(if_def); |
12271 | 0 | ir_END_list(idx_not_found_inputs); |
12272 | 0 | } |
12273 | 0 | if (!(op1_info & MAY_BE_ARRAY_KEY_LONG) || (op1_info & MAY_BE_ARRAY_NUMERIC_HASH) || packed_loaded || bad_packed_key || dim_type == IS_UNDEF) { |
12274 | 0 | if (if_packed) { |
12275 | 0 | ir_IF_FALSE(if_packed); |
12276 | 0 | if_packed = IR_UNUSED; |
12277 | 0 | ir_END_list(idx_not_found_inputs); |
12278 | 0 | } else if (!packed_loaded) { |
12279 | 0 | ir_END_list(idx_not_found_inputs); |
12280 | 0 | } |
12281 | 0 | ir_MERGE_list(idx_not_found_inputs); |
12282 | 0 | if (!op2_loaded) { |
12283 | | // JIT: hval = Z_LVAL_P(dim); |
12284 | 0 | h = jit_Z_LVAL(jit, op2_addr); |
12285 | 0 | } |
12286 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_index_lookup), ht_ref, h); |
12287 | 0 | ir_refs_add(found_inputs, ir_END()); |
12288 | 0 | ir_refs_add(found_vals, ref); |
12289 | 0 | } |
12290 | 0 | break; |
12291 | 0 | default: |
12292 | 0 | ZEND_UNREACHABLE(); |
12293 | 0 | } |
12294 | 0 | } |
12295 | | |
12296 | 0 | if (op2_info & MAY_BE_STRING) { |
12297 | 0 | ir_ref key; |
12298 | |
|
12299 | 0 | if (if_type) { |
12300 | 0 | ir_IF_FALSE(if_type); |
12301 | 0 | if_type = IS_UNUSED; |
12302 | 0 | } |
12303 | |
|
12304 | 0 | if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_STRING))) { |
12305 | | // JIT: if (EXPECTED(Z_TYPE_P(dim) == IS_STRING)) |
12306 | 0 | if_type = jit_if_Z_TYPE(jit, op2_addr, IS_STRING); |
12307 | 0 | ir_IF_TRUE(if_type); |
12308 | 0 | } |
12309 | | |
12310 | | // JIT: offset_key = Z_STR_P(dim); |
12311 | 0 | key = jit_Z_PTR(jit, op2_addr); |
12312 | | |
12313 | | // JIT: retval = zend_hash_find(ht, offset_key); |
12314 | 0 | switch (type) { |
12315 | 0 | case BP_JIT_IS: |
12316 | 0 | if (opline->op2_type != IS_CONST) { |
12317 | 0 | ir_ref if_num, end1, ref2; |
12318 | |
|
12319 | 0 | if_num = ir_IF( |
12320 | 0 | ir_ULE( |
12321 | 0 | ir_LOAD_C(ir_ADD_OFFSET(key, offsetof(zend_string, val))), |
12322 | 0 | ir_CONST_CHAR('9'))); |
12323 | 0 | ir_IF_TRUE_cold(if_num); |
12324 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_symtable_find), ht_ref, key); |
12325 | 0 | end1 = ir_END(); |
12326 | 0 | ir_IF_FALSE(if_num); |
12327 | 0 | ref2 = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_find), ht_ref, key); |
12328 | 0 | ir_MERGE_WITH(end1); |
12329 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
12330 | 0 | } else { |
12331 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_find_known_hash), ht_ref, key); |
12332 | 0 | } |
12333 | 0 | if (not_found_exit_addr) { |
12334 | 0 | ir_GUARD(ref, ir_CONST_ADDR(not_found_exit_addr)); |
12335 | 0 | } else { |
12336 | 0 | if_found = ir_IF(ref); |
12337 | 0 | ir_IF_FALSE(if_found); |
12338 | 0 | ir_END_list(*end_inputs); |
12339 | 0 | ir_IF_TRUE(if_found); |
12340 | 0 | } |
12341 | 0 | ir_refs_add(test_zval_values, ref); |
12342 | 0 | ir_refs_add(test_zval_inputs, ir_END()); |
12343 | 0 | break; |
12344 | 0 | case BP_VAR_R: |
12345 | 0 | case BP_VAR_IS: |
12346 | 0 | case BP_VAR_UNSET: |
12347 | 0 | if (opline->op2_type != IS_CONST) { |
12348 | 0 | ir_ref if_num, end1, ref2; |
12349 | |
|
12350 | 0 | if_num = ir_IF( |
12351 | 0 | ir_ULE( |
12352 | 0 | ir_LOAD_C(ir_ADD_OFFSET(key, offsetof(zend_string, val))), |
12353 | 0 | ir_CONST_CHAR('9'))); |
12354 | 0 | ir_IF_TRUE_cold(if_num); |
12355 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_symtable_find), ht_ref, key); |
12356 | 0 | end1 = ir_END(); |
12357 | 0 | ir_IF_FALSE(if_num); |
12358 | 0 | ref2 = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_find), ht_ref, key); |
12359 | 0 | ir_MERGE_WITH(end1); |
12360 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
12361 | 0 | } else { |
12362 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_find_known_hash), ht_ref, key); |
12363 | 0 | } |
12364 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && type == BP_VAR_R) { |
12365 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
12366 | 0 | } else if (type == BP_VAR_IS && not_found_exit_addr) { |
12367 | 0 | ir_GUARD(ref, ir_CONST_ADDR(not_found_exit_addr)); |
12368 | 0 | } else if (type == BP_VAR_IS && result_type_guard) { |
12369 | 0 | if_found = ir_IF(ref); |
12370 | 0 | ir_IF_FALSE(if_found); |
12371 | 0 | ir_END_list(*not_found_inputs); |
12372 | 0 | ir_IF_TRUE(if_found); |
12373 | 0 | } else { |
12374 | 0 | if_found = ir_IF(ref); |
12375 | 0 | switch (type) { |
12376 | 0 | case BP_VAR_R: |
12377 | 0 | ir_IF_FALSE_cold(if_found); |
12378 | | // JIT: zend_error(E_WARNING, "Undefined array key \"%s\"", ZSTR_VAL(offset_key)); |
12379 | 0 | jit_SET_EX_OPLINE(jit, opline); |
12380 | 0 | ir_CALL(IR_VOID, jit_STUB_FUNC_ADDR(jit, jit_stub_undefined_key, IR_FASTCALL_FUNC)); |
12381 | 0 | ir_END_list(*end_inputs); |
12382 | 0 | break; |
12383 | 0 | case BP_VAR_IS: |
12384 | 0 | case BP_VAR_UNSET: |
12385 | 0 | ir_IF_FALSE(if_found); |
12386 | | // JIT: retval = &EG(uninitialized_zval); |
12387 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
12388 | 0 | ir_END_list(*end_inputs); |
12389 | 0 | break; |
12390 | 0 | default: |
12391 | 0 | ZEND_UNREACHABLE(); |
12392 | 0 | } |
12393 | 0 | ir_IF_TRUE(if_found); |
12394 | 0 | } |
12395 | 0 | ir_refs_add(found_inputs, ir_END()); |
12396 | 0 | ir_refs_add(found_vals, ref); |
12397 | 0 | break; |
12398 | 0 | case BP_VAR_RW: |
12399 | 0 | if (opline->op2_type != IS_CONST) { |
12400 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_symtable_lookup_rw), ht_ref, key); |
12401 | 0 | } else { |
12402 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_hash_lookup_rw), ht_ref, key); |
12403 | 0 | } |
12404 | 0 | if (not_found_exit_addr) { |
12405 | 0 | ir_GUARD(ref, ir_CONST_ADDR(not_found_exit_addr)); |
12406 | 0 | } else { |
12407 | 0 | if_found = ir_IF(ref); |
12408 | 0 | ir_IF_FALSE(if_found); |
12409 | 0 | ir_END_list(*end_inputs); |
12410 | 0 | ir_IF_TRUE(if_found); |
12411 | 0 | } |
12412 | 0 | ir_refs_add(found_inputs, ir_END()); |
12413 | 0 | ir_refs_add(found_vals, ref); |
12414 | 0 | break; |
12415 | 0 | case BP_VAR_W: |
12416 | 0 | if (opline->op2_type != IS_CONST) { |
12417 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_symtable_lookup_w), ht_ref, key); |
12418 | 0 | } else { |
12419 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_lookup), ht_ref, key); |
12420 | 0 | } |
12421 | 0 | ir_refs_add(found_inputs, ir_END()); |
12422 | 0 | ir_refs_add(found_vals, ref); |
12423 | 0 | break; |
12424 | 0 | default: |
12425 | 0 | ZEND_UNREACHABLE(); |
12426 | 0 | } |
12427 | 0 | } |
12428 | | |
12429 | 0 | if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_STRING))) { |
12430 | 0 | if (if_type) { |
12431 | 0 | ir_IF_FALSE_cold(if_type); |
12432 | 0 | if_type = IS_UNDEF; |
12433 | 0 | } |
12434 | 0 | if (type != BP_VAR_RW) { |
12435 | 0 | jit_SET_EX_OPLINE(jit, opline); |
12436 | 0 | } |
12437 | 0 | ref = jit_ZVAL_ADDR(jit, op2_addr); |
12438 | 0 | switch (type) { |
12439 | 0 | case BP_VAR_R: |
12440 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_dim_r_helper), |
12441 | 0 | ht_ref, |
12442 | 0 | ref, |
12443 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
12444 | 0 | ir_END_list(*end_inputs); |
12445 | 0 | break; |
12446 | 0 | case BP_JIT_IS: |
12447 | 0 | ref = ir_CALL_2(IR_I32, ir_CONST_FC_FUNC(zend_jit_fetch_dim_isset_helper), ht_ref, ref); |
12448 | 0 | if (not_found_exit_addr) { |
12449 | 0 | ir_GUARD(ref, ir_CONST_ADDR(not_found_exit_addr)); |
12450 | 0 | ir_refs_add(found_inputs, ir_END()); |
12451 | 0 | } else if (found_exit_addr) { |
12452 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(found_exit_addr)); |
12453 | 0 | ir_END_list(*end_inputs); |
12454 | 0 | } else { |
12455 | 0 | if_found = ir_IF(ref); |
12456 | 0 | ir_IF_TRUE(if_found); |
12457 | 0 | ir_refs_add(found_inputs, ir_END()); |
12458 | 0 | ir_IF_FALSE(if_found); |
12459 | 0 | ir_END_list(*end_inputs); |
12460 | 0 | } |
12461 | 0 | break; |
12462 | 0 | case BP_VAR_IS: |
12463 | 0 | case BP_VAR_UNSET: |
12464 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_dim_is_helper), |
12465 | 0 | ht_ref, |
12466 | 0 | ref, |
12467 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
12468 | 0 | ir_END_list(*end_inputs); |
12469 | 0 | break; |
12470 | 0 | case BP_VAR_RW: |
12471 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_fetch_dim_rw_helper), ht_ref, ref); |
12472 | 0 | if_found = ir_IF(ref); |
12473 | 0 | ir_IF_TRUE(if_found); |
12474 | 0 | ir_refs_add(found_inputs, ir_END()); |
12475 | 0 | ir_refs_add(found_vals, ref); |
12476 | 0 | ir_IF_FALSE(if_found); |
12477 | 0 | ir_END_list(*end_inputs); |
12478 | 0 | break; |
12479 | 0 | case BP_VAR_W: |
12480 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_fetch_dim_w_helper), ht_ref, ref); |
12481 | 0 | if_found = ir_IF(ref); |
12482 | 0 | ir_IF_TRUE(if_found); |
12483 | 0 | ir_refs_add(found_inputs, ir_END()); |
12484 | 0 | ir_refs_add(found_vals, ref); |
12485 | 0 | ir_IF_FALSE(if_found); |
12486 | 0 | ir_END_list(*end_inputs); |
12487 | 0 | break; |
12488 | 0 | default: |
12489 | 0 | ZEND_UNREACHABLE(); |
12490 | 0 | } |
12491 | 0 | } |
12492 | | |
12493 | 0 | if (type == BP_JIT_IS |
12494 | 0 | && !(op2_info & (MAY_BE_ANY|MAY_BE_UNDEF))) { |
12495 | | /* dead code */ |
12496 | 0 | ir_END_list(*end_inputs); |
12497 | 0 | } else if (type == BP_JIT_IS |
12498 | 0 | && (op1_info & MAY_BE_ARRAY) |
12499 | 0 | && (op2_info & (MAY_BE_LONG|MAY_BE_STRING)) |
12500 | 0 | && test_zval_inputs->count) { |
12501 | |
|
12502 | 0 | ir_MERGE_N(test_zval_inputs->count, test_zval_inputs->refs); |
12503 | 0 | ref = ir_PHI_N(IR_ADDR, test_zval_values->count, test_zval_values->refs); |
12504 | |
|
12505 | 0 | if (op1_info & MAY_BE_ARRAY_OF_REF) { |
12506 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
12507 | 0 | } |
12508 | 0 | cond = ir_GT(jit_Z_TYPE_ref(jit, ref), ir_CONST_U8(IS_NULL)); |
12509 | 0 | if (not_found_exit_addr) { |
12510 | 0 | ir_GUARD(cond, ir_CONST_ADDR(not_found_exit_addr)); |
12511 | 0 | ir_refs_add(found_inputs, ir_END()); |
12512 | 0 | } else if (found_exit_addr) { |
12513 | 0 | ir_GUARD_NOT(cond, ir_CONST_ADDR(found_exit_addr)); |
12514 | 0 | ir_END_list(*end_inputs); |
12515 | 0 | } else { |
12516 | 0 | ir_ref if_set = ir_IF(cond); |
12517 | 0 | ir_IF_FALSE(if_set); |
12518 | 0 | ir_END_list(*end_inputs); |
12519 | 0 | ir_IF_TRUE(if_set); |
12520 | 0 | ir_refs_add(found_inputs, ir_END()); |
12521 | 0 | } |
12522 | 0 | } |
12523 | |
|
12524 | 0 | return 1; |
12525 | 0 | } |
12526 | | |
12527 | | static int zend_jit_fetch_dim_read(zend_jit_ctx *jit, |
12528 | | const zend_op *opline, |
12529 | | zend_ssa *ssa, |
12530 | | const zend_ssa_op *ssa_op, |
12531 | | uint32_t op1_info, |
12532 | | zend_jit_addr op1_addr, |
12533 | | bool op1_avoid_refcounting, |
12534 | | uint32_t op2_info, |
12535 | | zend_jit_addr op2_addr, |
12536 | | zend_ssa_range *op2_range, |
12537 | | uint32_t res_info, |
12538 | | zend_jit_addr res_addr, |
12539 | | uint8_t dim_type) |
12540 | 0 | { |
12541 | 0 | zend_jit_addr orig_op1_addr; |
12542 | 0 | const void *exit_addr = NULL; |
12543 | 0 | const void *not_found_exit_addr = NULL; |
12544 | 0 | bool result_type_guard = false; |
12545 | 0 | bool result_avoid_refcounting = false; |
12546 | 0 | uint32_t may_be_string = (opline->opcode != ZEND_FETCH_LIST_R) ? MAY_BE_STRING : 0; |
12547 | 0 | int may_throw = 0; |
12548 | 0 | ir_ref if_type = IR_UNUSED; |
12549 | 0 | ir_ref end_inputs = IR_UNUSED; |
12550 | 0 | ir_ref not_found_inputs = IR_UNUSED; |
12551 | |
|
12552 | 0 | orig_op1_addr = OP1_ADDR(); |
12553 | |
|
12554 | 0 | if (opline->opcode != ZEND_FETCH_DIM_IS |
12555 | 0 | && JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
12556 | 0 | && !has_concrete_type(op1_info)) { |
12557 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
12558 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
12559 | 0 | if (!exit_addr) { |
12560 | 0 | return 0; |
12561 | 0 | } |
12562 | 0 | } |
12563 | | |
12564 | 0 | if ((res_info & MAY_BE_GUARD) |
12565 | 0 | && JIT_G(current_frame) |
12566 | 0 | && (op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY) { |
12567 | |
|
12568 | 0 | if (!(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF) - (MAY_BE_STRING|MAY_BE_LONG)))) { |
12569 | 0 | result_type_guard = true; |
12570 | 0 | res_info &= ~MAY_BE_GUARD; |
12571 | 0 | ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD; |
12572 | 0 | } |
12573 | |
|
12574 | 0 | if ((opline->result_type & (IS_VAR|IS_TMP_VAR)) |
12575 | 0 | && (opline->opcode == ZEND_FETCH_LIST_R |
12576 | 0 | || !(opline->op1_type & (IS_VAR|IS_TMP_VAR)) |
12577 | 0 | || op1_avoid_refcounting) |
12578 | 0 | && (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) |
12579 | 0 | && (ssa_op+1)->op1_use == ssa_op->result_def |
12580 | 0 | && !(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF) - (MAY_BE_STRING|MAY_BE_LONG))) |
12581 | 0 | && zend_jit_may_avoid_refcounting(opline+1, res_info)) { |
12582 | 0 | result_avoid_refcounting = true; |
12583 | 0 | ssa->var_info[ssa_op->result_def].avoid_refcounting = 1; |
12584 | 0 | } |
12585 | |
|
12586 | 0 | if (opline->opcode == ZEND_FETCH_DIM_IS |
12587 | 0 | && !(res_info & MAY_BE_NULL)) { |
12588 | 0 | uint32_t flags = 0; |
12589 | 0 | uint32_t old_op1_info = 0; |
12590 | 0 | uint32_t old_info; |
12591 | 0 | zend_jit_trace_stack *stack = JIT_G(current_frame)->stack; |
12592 | 0 | int32_t exit_point; |
12593 | |
|
12594 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) |
12595 | 0 | && !op1_avoid_refcounting) { |
12596 | 0 | flags |= ZEND_JIT_EXIT_FREE_OP1; |
12597 | 0 | } |
12598 | 0 | if ((opline->op2_type & (IS_VAR|IS_TMP_VAR)) |
12599 | 0 | && (op2_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
12600 | 0 | flags |= ZEND_JIT_EXIT_FREE_OP2; |
12601 | 0 | } |
12602 | |
|
12603 | 0 | if (op1_avoid_refcounting) { |
12604 | 0 | old_op1_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var)); |
12605 | 0 | SET_STACK_REG(stack, EX_VAR_TO_NUM(opline->op1.var), ZREG_NONE); |
12606 | 0 | } |
12607 | |
|
12608 | 0 | old_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var)); |
12609 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_NULL, 0); |
12610 | 0 | SET_STACK_REG_EX(stack, EX_VAR_TO_NUM(opline->result.var), ZREG_NONE, ZREG_TYPE_ONLY); |
12611 | 0 | exit_point = zend_jit_trace_get_exit_point(opline+1, flags); |
12612 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var), old_info); |
12613 | 0 | not_found_exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
12614 | 0 | if (!not_found_exit_addr) { |
12615 | 0 | return 0; |
12616 | 0 | } |
12617 | | |
12618 | 0 | if (op1_avoid_refcounting) { |
12619 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var), old_op1_info); |
12620 | 0 | } |
12621 | 0 | } |
12622 | 0 | } |
12623 | | |
12624 | 0 | if (op1_info & MAY_BE_REF) { |
12625 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, op1_addr); |
12626 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
12627 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
12628 | 0 | } |
12629 | |
|
12630 | 0 | if (op1_info & MAY_BE_ARRAY) { |
12631 | 0 | ir_ref ht_ref, ref; |
12632 | 0 | zend_jit_addr val_addr; |
12633 | 0 | ir_refs *found_inputs, *found_vals; |
12634 | |
|
12635 | 0 | ir_refs_init(found_inputs, 10); |
12636 | 0 | ir_refs_init(found_vals, 10); |
12637 | |
|
12638 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - MAY_BE_ARRAY)) { |
12639 | 0 | if (exit_addr && !(op1_info & (MAY_BE_OBJECT|may_be_string))) { |
12640 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_ARRAY, exit_addr); |
12641 | 0 | } else { |
12642 | 0 | if_type = jit_if_Z_TYPE(jit, op1_addr, IS_ARRAY); |
12643 | 0 | ir_IF_TRUE(if_type); |
12644 | 0 | } |
12645 | 0 | } |
12646 | |
|
12647 | 0 | ht_ref = jit_Z_PTR(jit, op1_addr); |
12648 | |
|
12649 | 0 | if ((op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_STRING))) || |
12650 | 0 | (opline->opcode != ZEND_FETCH_DIM_IS && JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE)) { |
12651 | 0 | may_throw = 1; |
12652 | 0 | } |
12653 | |
|
12654 | 0 | if (!zend_jit_fetch_dimension_address_inner(jit, opline, |
12655 | 0 | (opline->opcode != ZEND_FETCH_DIM_IS) ? BP_VAR_R : BP_VAR_IS, |
12656 | 0 | op1_info, op2_info, op2_addr, op2_range, dim_type, NULL, not_found_exit_addr, exit_addr, |
12657 | 0 | result_type_guard, ht_ref, found_inputs, found_vals, |
12658 | 0 | &end_inputs, ¬_found_inputs)) { |
12659 | 0 | return 0; |
12660 | 0 | } |
12661 | | |
12662 | 0 | if (found_inputs->count) { |
12663 | 0 | ir_MERGE_N(found_inputs->count, found_inputs->refs); |
12664 | 0 | ref = ir_PHI_N(IR_ADDR, found_vals->count, found_vals->refs); |
12665 | 0 | val_addr = ZEND_ADDR_REF_ZVAL(ref); |
12666 | |
|
12667 | 0 | if (result_type_guard) { |
12668 | 0 | uint8_t type = concrete_type(res_info); |
12669 | 0 | uint32_t flags = 0; |
12670 | |
|
12671 | 0 | if (opline->opcode != ZEND_FETCH_LIST_R |
12672 | 0 | && (opline->op1_type & (IS_VAR|IS_TMP_VAR)) |
12673 | 0 | && !op1_avoid_refcounting) { |
12674 | 0 | flags |= ZEND_JIT_EXIT_FREE_OP1; |
12675 | 0 | } |
12676 | 0 | if ((opline->op2_type & (IS_VAR|IS_TMP_VAR)) |
12677 | 0 | && (op2_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
12678 | 0 | flags |= ZEND_JIT_EXIT_FREE_OP2; |
12679 | 0 | } |
12680 | |
|
12681 | 0 | val_addr = zend_jit_guard_fetch_result_type(jit, opline, val_addr, type, |
12682 | 0 | (op1_info & MAY_BE_ARRAY_OF_REF) != 0, flags, op1_avoid_refcounting); |
12683 | 0 | if (!val_addr) { |
12684 | 0 | return 0; |
12685 | 0 | } |
12686 | | |
12687 | 0 | if (not_found_inputs) { |
12688 | 0 | ir_END_list(not_found_inputs); |
12689 | 0 | ir_MERGE_list(not_found_inputs); |
12690 | 0 | } |
12691 | | |
12692 | | // ZVAL_COPY |
12693 | 0 | jit_ZVAL_COPY(jit, res_addr, -1, val_addr, res_info, !result_avoid_refcounting); |
12694 | 0 | if (Z_MODE(res_addr) != IS_REG) { |
12695 | 0 | } else if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, res_info)) { |
12696 | 0 | return 0; |
12697 | 0 | } |
12698 | 0 | } else if (op1_info & MAY_BE_ARRAY_OF_REF) { |
12699 | | // ZVAL_COPY_DEREF |
12700 | 0 | ir_ref type_info = jit_Z_TYPE_INFO(jit, val_addr); |
12701 | 0 | if (!zend_jit_zval_copy_deref(jit, res_addr, val_addr, type_info)) { |
12702 | 0 | return 0; |
12703 | 0 | } |
12704 | 0 | } else { |
12705 | | // ZVAL_COPY |
12706 | 0 | jit_ZVAL_COPY(jit, res_addr, -1, val_addr, res_info, true); |
12707 | 0 | } |
12708 | | |
12709 | 0 | ir_END_list(end_inputs); |
12710 | 0 | } else if (not_found_inputs) { |
12711 | 0 | ir_MERGE_list(not_found_inputs); |
12712 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
12713 | 0 | ir_END_list(end_inputs); |
12714 | 0 | } else if (!end_inputs && jit->ctx.control) { |
12715 | 0 | ir_END_list(end_inputs); /* dead code */ |
12716 | 0 | } |
12717 | 0 | } |
12718 | | |
12719 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_ARRAY)) { |
12720 | 0 | if (if_type) { |
12721 | 0 | ir_IF_FALSE_cold(if_type); |
12722 | 0 | if_type = IS_UNDEF; |
12723 | 0 | } |
12724 | |
|
12725 | 0 | if (opline->opcode != ZEND_FETCH_LIST_R && (op1_info & MAY_BE_STRING)) { |
12726 | 0 | ir_ref str_ref; |
12727 | |
|
12728 | 0 | may_throw = 1; |
12729 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_ARRAY|MAY_BE_STRING))) { |
12730 | 0 | if (exit_addr && !(op1_info & MAY_BE_OBJECT)) { |
12731 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_STRING, exit_addr); |
12732 | 0 | } else { |
12733 | 0 | if_type = jit_if_Z_TYPE(jit, op1_addr, IS_STRING); |
12734 | 0 | ir_IF_TRUE(if_type); |
12735 | 0 | } |
12736 | 0 | } |
12737 | 0 | jit_SET_EX_OPLINE(jit, opline); |
12738 | 0 | str_ref = jit_Z_PTR(jit, op1_addr); |
12739 | 0 | if (opline->opcode != ZEND_FETCH_DIM_IS) { |
12740 | 0 | ir_ref ref; |
12741 | |
|
12742 | 0 | if ((op2_info & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_GUARD)) == MAY_BE_LONG) { |
12743 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_fetch_dim_str_offset_r_helper), |
12744 | 0 | str_ref, jit_Z_LVAL(jit, op2_addr)); |
12745 | 0 | } else { |
12746 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_fetch_dim_str_r_helper), |
12747 | 0 | str_ref, jit_ZVAL_ADDR(jit, op2_addr)); |
12748 | 0 | } |
12749 | 0 | jit_set_Z_PTR(jit, res_addr, ref); |
12750 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_STRING); |
12751 | 0 | } else { |
12752 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_dim_str_is_helper), |
12753 | 0 | str_ref, |
12754 | 0 | jit_ZVAL_ADDR(jit, op2_addr), |
12755 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
12756 | 0 | } |
12757 | 0 | ir_END_list(end_inputs); |
12758 | 0 | } |
12759 | |
|
12760 | 0 | if (op1_info & MAY_BE_OBJECT) { |
12761 | 0 | ir_ref arg2; |
12762 | |
|
12763 | 0 | if (if_type) { |
12764 | 0 | ir_IF_FALSE_cold(if_type); |
12765 | 0 | if_type = IS_UNDEF; |
12766 | 0 | } |
12767 | |
|
12768 | 0 | may_throw = 1; |
12769 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_ARRAY|MAY_BE_OBJECT|may_be_string))) { |
12770 | 0 | if (exit_addr) { |
12771 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_OBJECT, exit_addr); |
12772 | 0 | } else { |
12773 | 0 | if_type = jit_if_Z_TYPE(jit, op1_addr, IS_OBJECT); |
12774 | 0 | ir_IF_TRUE(if_type); |
12775 | 0 | } |
12776 | 0 | } |
12777 | |
|
12778 | 0 | jit_SET_EX_OPLINE(jit, opline); |
12779 | 0 | if (opline->op2_type == IS_CONST && Z_EXTRA_P(RT_CONSTANT(opline, opline->op2)) == ZEND_EXTRA_VALUE) { |
12780 | 0 | ZEND_ASSERT(Z_MODE(op2_addr) == IS_CONST_ZVAL); |
12781 | 0 | arg2 = ir_CONST_ADDR(Z_ZV(op2_addr)+1); |
12782 | 0 | } else { |
12783 | 0 | arg2 = jit_ZVAL_ADDR(jit, op2_addr); |
12784 | 0 | } |
12785 | |
|
12786 | 0 | if (opline->opcode != ZEND_FETCH_DIM_IS) { |
12787 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_dim_obj_r_helper), |
12788 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
12789 | 0 | arg2, |
12790 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
12791 | 0 | } else { |
12792 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_dim_obj_is_helper), |
12793 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
12794 | 0 | arg2, |
12795 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
12796 | 0 | } |
12797 | |
|
12798 | 0 | ir_END_list(end_inputs); |
12799 | 0 | } |
12800 | |
|
12801 | 0 | if ((op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_ARRAY|MAY_BE_OBJECT|may_be_string))) |
12802 | 0 | && (!exit_addr || !(op1_info & (MAY_BE_ARRAY|MAY_BE_OBJECT|may_be_string)))) { |
12803 | |
|
12804 | 0 | if (if_type) { |
12805 | 0 | ir_IF_FALSE_cold(if_type); |
12806 | 0 | if_type = IS_UNDEF; |
12807 | 0 | } |
12808 | |
|
12809 | 0 | if ((opline->opcode != ZEND_FETCH_DIM_IS && (op1_info & MAY_BE_UNDEF)) || (op2_info & MAY_BE_UNDEF)) { |
12810 | 0 | jit_SET_EX_OPLINE(jit, opline); |
12811 | 0 | if (opline->opcode != ZEND_FETCH_DIM_IS && (op1_info & MAY_BE_UNDEF)) { |
12812 | 0 | may_throw = 1; |
12813 | 0 | zend_jit_type_check_undef(jit, jit_Z_TYPE(jit, op1_addr), opline->op1.var, NULL, |
12814 | 0 | false, true, false); |
12815 | 0 | } |
12816 | |
|
12817 | 0 | if (op2_info & MAY_BE_UNDEF) { |
12818 | 0 | may_throw = 1; |
12819 | 0 | zend_jit_type_check_undef(jit, jit_Z_TYPE(jit, op2_addr), opline->op2.var, NULL, |
12820 | 0 | false, true, false); |
12821 | 0 | } |
12822 | 0 | } |
12823 | |
|
12824 | 0 | if (opline->opcode != ZEND_FETCH_DIM_IS) { |
12825 | 0 | ir_ref ref; |
12826 | |
|
12827 | 0 | may_throw = 1; |
12828 | 0 | if ((op1_info & MAY_BE_UNDEF) || (op2_info & MAY_BE_UNDEF)) { |
12829 | 0 | ref = jit_ZVAL_ADDR(jit, orig_op1_addr); |
12830 | 0 | } else { |
12831 | 0 | jit_SET_EX_OPLINE(jit, opline); |
12832 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
12833 | 0 | } |
12834 | 0 | if (opline->opcode == ZEND_FETCH_LIST_R) { |
12835 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_invalid_array_use), ref); |
12836 | 0 | } else { |
12837 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_invalid_array_access), ref); |
12838 | 0 | } |
12839 | 0 | } |
12840 | |
|
12841 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
12842 | 0 | ir_END_list(end_inputs); |
12843 | 0 | } |
12844 | 0 | } |
12845 | |
|
12846 | 0 | if (end_inputs) { |
12847 | 0 | ir_MERGE_list(end_inputs); |
12848 | |
|
12849 | 0 | #ifdef ZEND_JIT_USE_RC_INFERENCE |
12850 | 0 | if ((opline->op2_type & (IS_TMP_VAR|IS_VAR)) && (op1_info & MAY_BE_OBJECT)) { |
12851 | | /* Magic offsetGet() may increase refcount of the key */ |
12852 | 0 | op2_info |= MAY_BE_RCN; |
12853 | 0 | } |
12854 | 0 | #endif |
12855 | |
|
12856 | 0 | if (opline->op2_type & (IS_TMP_VAR|IS_VAR)) { |
12857 | 0 | if ((op2_info & MAY_HAVE_DTOR) && (op2_info & MAY_BE_RC1)) { |
12858 | 0 | may_throw = 1; |
12859 | 0 | } |
12860 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, opline); |
12861 | 0 | } |
12862 | 0 | if (opline->opcode != ZEND_FETCH_LIST_R && !op1_avoid_refcounting) { |
12863 | 0 | if (opline->op1_type & (IS_TMP_VAR|IS_VAR)) { |
12864 | 0 | if ((op1_info & MAY_HAVE_DTOR) && (op1_info & MAY_BE_RC1)) { |
12865 | 0 | may_throw = 1; |
12866 | 0 | } |
12867 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
12868 | 0 | } |
12869 | 0 | } |
12870 | |
|
12871 | 0 | if (may_throw) { |
12872 | 0 | zend_jit_check_exception(jit); |
12873 | 0 | } |
12874 | 0 | } else if (op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) { |
12875 | 0 | ir_BEGIN(IR_UNUSED); /* unreachable tail */ |
12876 | 0 | } |
12877 | |
|
12878 | 0 | return 1; |
12879 | 0 | } |
12880 | | |
12881 | | static zend_jit_addr zend_jit_prepare_array_update(zend_jit_ctx *jit, |
12882 | | const zend_op *opline, |
12883 | | uint32_t *op1_info_ptr, |
12884 | | zend_jit_addr op1_addr, |
12885 | | ir_ref *if_type, |
12886 | | ir_ref *ht_ref, |
12887 | | int *may_throw) |
12888 | 0 | { |
12889 | 0 | ir_ref ref = IR_UNUSED; |
12890 | 0 | ir_ref array_reference_end = IR_UNUSED, array_reference_ref = IR_UNUSED; |
12891 | 0 | ir_refs *array_inputs, *array_values; |
12892 | 0 | uint32_t op1_info = *op1_info_ptr; |
12893 | |
|
12894 | 0 | ir_refs_init(array_inputs, 4); |
12895 | 0 | ir_refs_init(array_values, 4); |
12896 | |
|
12897 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
12898 | 0 | if (op1_info & MAY_BE_REF) { |
12899 | 0 | ir_ref if_reference, if_array, end1, ref2; |
12900 | |
|
12901 | 0 | *may_throw = 1; |
12902 | 0 | if_reference = jit_if_Z_TYPE(jit, op1_addr, IS_REFERENCE); |
12903 | 0 | ir_IF_FALSE(if_reference); |
12904 | 0 | end1 = ir_END(); |
12905 | 0 | ir_IF_TRUE_cold(if_reference); |
12906 | 0 | array_reference_ref = ir_ADD_OFFSET(jit_Z_PTR_ref(jit, ref), offsetof(zend_reference, val)); |
12907 | 0 | if_array = jit_if_Z_TYPE_ref(jit, array_reference_ref, ir_CONST_U8(IS_ARRAY)); |
12908 | 0 | ir_IF_TRUE(if_array); |
12909 | 0 | array_reference_end = ir_END(); |
12910 | 0 | ir_IF_FALSE_cold(if_array); |
12911 | 0 | if (opline->opcode != ZEND_FETCH_DIM_RW && opline->opcode != ZEND_ASSIGN_DIM_OP) { |
12912 | 0 | jit_SET_EX_OPLINE(jit, opline); |
12913 | 0 | } |
12914 | 0 | ref2 = ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_prepare_assign_dim_ref), ref); |
12915 | 0 | ir_GUARD(ref2, jit_STUB_ADDR(jit, jit_stub_exception_handler_undef)); |
12916 | |
|
12917 | 0 | ir_MERGE_WITH(end1); |
12918 | 0 | ref = ir_PHI_2(IR_ADDR, ref2, ref); |
12919 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
12920 | 0 | } |
12921 | |
|
12922 | 0 | if (op1_info & MAY_BE_ARRAY) { |
12923 | 0 | ir_ref op1_ref = ref; |
12924 | |
|
12925 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - MAY_BE_ARRAY)) { |
12926 | 0 | *if_type = jit_if_Z_TYPE(jit, op1_addr, IS_ARRAY); |
12927 | 0 | ir_IF_TRUE(*if_type); |
12928 | 0 | } |
12929 | 0 | if (array_reference_end) { |
12930 | 0 | ir_MERGE_WITH(array_reference_end); |
12931 | 0 | op1_ref = ir_PHI_2(IR_ADDR, ref, array_reference_ref); |
12932 | 0 | } |
12933 | | // JIT: SEPARATE_ARRAY() |
12934 | 0 | ref = jit_Z_PTR_ref(jit, op1_ref); |
12935 | 0 | if (RC_MAY_BE_N(op1_info)) { |
12936 | 0 | if (RC_MAY_BE_1(op1_info)) { |
12937 | 0 | ir_ref if_refcount_1 = ir_IF(ir_EQ(jit_GC_REFCOUNT(jit, ref), ir_CONST_U32(1))); |
12938 | 0 | ir_IF_TRUE(if_refcount_1); |
12939 | 0 | ir_refs_add(array_inputs, ir_END()); |
12940 | 0 | ir_refs_add(array_values, ref); |
12941 | 0 | ir_IF_FALSE(if_refcount_1); |
12942 | 0 | } |
12943 | 0 | ref = ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_zval_array_dup), op1_ref); |
12944 | 0 | } |
12945 | 0 | if (array_inputs->count || (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL))) { |
12946 | 0 | ir_refs_add(array_inputs, ir_END()); |
12947 | 0 | ir_refs_add(array_values, ref); |
12948 | 0 | } |
12949 | 0 | } |
12950 | |
|
12951 | 0 | if (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL)) { |
12952 | 0 | if (*if_type) { |
12953 | 0 | ir_IF_FALSE_cold(*if_type); |
12954 | 0 | *if_type = IR_UNUSED; |
12955 | 0 | } |
12956 | 0 | if (op1_info & (MAY_BE_ANY-(MAY_BE_NULL|MAY_BE_ARRAY))) { |
12957 | 0 | *if_type = ir_IF(ir_LE(jit_Z_TYPE(jit, op1_addr), ir_CONST_U8(IS_NULL))); |
12958 | 0 | ir_IF_TRUE(*if_type); |
12959 | 0 | } |
12960 | 0 | if ((op1_info & MAY_BE_UNDEF) |
12961 | 0 | && (opline->opcode == ZEND_FETCH_DIM_RW || opline->opcode == ZEND_ASSIGN_DIM_OP)) { |
12962 | 0 | ir_ref end1 = IR_UNUSED; |
12963 | |
|
12964 | 0 | *may_throw = 1; |
12965 | 0 | if (op1_info & MAY_BE_NULL) { |
12966 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE(jit, op1_addr)); |
12967 | 0 | ir_IF_TRUE(if_def); |
12968 | 0 | end1 = ir_END(); |
12969 | 0 | ir_IF_FALSE(if_def); |
12970 | 0 | } |
12971 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op1.var)); |
12972 | 0 | if (end1) { |
12973 | 0 | ir_MERGE_WITH(end1); |
12974 | 0 | } |
12975 | 0 | } |
12976 | | // JIT: ZVAL_ARR(container, zend_new_array(8)); |
12977 | 0 | ref = ir_CALL_1(IR_ADDR, |
12978 | 0 | jit_STUB_FUNC_ADDR(jit, jit_stub_new_array, IR_FASTCALL_FUNC), |
12979 | 0 | jit_ZVAL_ADDR(jit, op1_addr)); |
12980 | 0 | if (array_inputs->count) { |
12981 | 0 | ir_refs_add(array_inputs, ir_END()); |
12982 | 0 | ir_refs_add(array_values, ref); |
12983 | 0 | } |
12984 | 0 | op1_info &= ~(MAY_BE_UNDEF | MAY_BE_NULL); |
12985 | 0 | op1_info |= MAY_BE_ARRAY | MAY_BE_RC1; |
12986 | 0 | *op1_info_ptr = op1_info; |
12987 | 0 | } |
12988 | |
|
12989 | 0 | if (array_inputs->count) { |
12990 | 0 | ir_MERGE_N(array_inputs->count, array_inputs->refs); |
12991 | 0 | ref = ir_PHI_N(IR_ADDR, array_values->count, array_values->refs); |
12992 | 0 | } |
12993 | |
|
12994 | 0 | *ht_ref = ref; |
12995 | 0 | return op1_addr; |
12996 | 0 | } |
12997 | | |
12998 | | static int zend_jit_fetch_dim(zend_jit_ctx *jit, |
12999 | | const zend_op *opline, |
13000 | | uint32_t op1_info, |
13001 | | zend_jit_addr op1_addr, |
13002 | | uint32_t op2_info, |
13003 | | zend_jit_addr op2_addr, |
13004 | | zend_ssa_range *op2_range, |
13005 | | zend_jit_addr res_addr, |
13006 | | uint8_t dim_type) |
13007 | 0 | { |
13008 | 0 | int may_throw = 0; |
13009 | 0 | ir_ref end_inputs = IR_UNUSED; |
13010 | 0 | ir_ref ref, if_type = IR_UNUSED, ht_ref; |
13011 | |
|
13012 | 0 | if (opline->opcode == ZEND_FETCH_DIM_RW) { |
13013 | 0 | jit_SET_EX_OPLINE(jit, opline); |
13014 | 0 | } |
13015 | |
|
13016 | 0 | op1_addr = zend_jit_prepare_array_update(jit, opline, &op1_info, op1_addr, &if_type, &ht_ref, &may_throw); |
13017 | |
|
13018 | 0 | if (op1_info & MAY_BE_ARRAY) { |
13019 | 0 | ir_refs *found_inputs, *found_vals; |
13020 | |
|
13021 | 0 | ir_refs_init(found_inputs, 8); |
13022 | 0 | ir_refs_init(found_vals, 8); |
13023 | |
|
13024 | 0 | if (opline->op2_type == IS_UNUSED) { |
13025 | 0 | ir_ref if_ok; |
13026 | |
|
13027 | 0 | may_throw = 1; |
13028 | | // JIT:var_ptr = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval)); |
13029 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_next_index_insert), |
13030 | 0 | ht_ref, jit_EG(uninitialized_zval)); |
13031 | | |
13032 | | // JIT: if (UNEXPECTED(!var_ptr)) { |
13033 | 0 | if_ok = ir_IF(ref); |
13034 | 0 | ir_IF_FALSE_cold(if_ok); |
13035 | 0 | if (opline->opcode != ZEND_FETCH_DIM_RW) { |
13036 | 0 | jit_SET_EX_OPLINE(jit, opline); |
13037 | 0 | } |
13038 | 0 | ir_CALL(IR_VOID, jit_STUB_FUNC_ADDR(jit, jit_stub_cannot_add_element, IR_FASTCALL_FUNC)); |
13039 | 0 | ir_END_list(end_inputs); |
13040 | |
|
13041 | 0 | ir_IF_TRUE(if_ok); |
13042 | 0 | jit_set_Z_PTR(jit, res_addr, ref); |
13043 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_INDIRECT); |
13044 | |
|
13045 | 0 | ir_END_list(end_inputs); |
13046 | 0 | } else { |
13047 | 0 | uint32_t type; |
13048 | |
|
13049 | 0 | switch (opline->opcode) { |
13050 | 0 | case ZEND_FETCH_DIM_W: |
13051 | 0 | case ZEND_FETCH_LIST_W: |
13052 | 0 | type = BP_VAR_W; |
13053 | 0 | break; |
13054 | 0 | case ZEND_FETCH_DIM_RW: |
13055 | 0 | may_throw = 1; |
13056 | 0 | type = BP_VAR_RW; |
13057 | 0 | break; |
13058 | 0 | case ZEND_FETCH_DIM_UNSET: |
13059 | 0 | type = BP_VAR_UNSET; |
13060 | 0 | break; |
13061 | 0 | default: |
13062 | 0 | ZEND_UNREACHABLE(); |
13063 | 0 | } |
13064 | | |
13065 | 0 | if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_STRING))) { |
13066 | 0 | may_throw = 1; |
13067 | 0 | } |
13068 | 0 | if (!zend_jit_fetch_dimension_address_inner(jit, opline, type, op1_info, |
13069 | 0 | op2_info, op2_addr, op2_range, dim_type, NULL, NULL, NULL, |
13070 | 0 | false, ht_ref, found_inputs, found_vals, &end_inputs, NULL)) { |
13071 | 0 | return 0; |
13072 | 0 | } |
13073 | | |
13074 | 0 | if (type == BP_VAR_RW || (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_STRING)))) { |
13075 | 0 | if (end_inputs) { |
13076 | 0 | ir_MERGE_list(end_inputs); |
13077 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
13078 | 0 | end_inputs = ir_END(); |
13079 | 0 | } |
13080 | 0 | } else if (!(op2_info & (MAY_BE_ANY|MAY_BE_UNDEF))) { |
13081 | | /* impossible dead path */ |
13082 | 0 | end_inputs = ir_END(); |
13083 | 0 | } else { |
13084 | 0 | ZEND_ASSERT(end_inputs == IR_UNUSED); |
13085 | 0 | } |
13086 | |
|
13087 | 0 | if (found_inputs->count) { |
13088 | 0 | ir_MERGE_N(found_inputs->count, found_inputs->refs); |
13089 | 0 | ref = ir_PHI_N(IR_ADDR, found_vals->count, found_vals->refs); |
13090 | 0 | jit_set_Z_PTR(jit, res_addr, ref); |
13091 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_INDIRECT); |
13092 | 0 | ir_END_list(end_inputs); |
13093 | 0 | } |
13094 | |
|
13095 | 0 | } |
13096 | 0 | } |
13097 | | |
13098 | 0 | if (op1_info & (MAY_BE_ANY-MAY_BE_ARRAY)) { |
13099 | 0 | ir_ref arg2; |
13100 | |
|
13101 | 0 | may_throw = 1; |
13102 | |
|
13103 | 0 | if (if_type) { |
13104 | 0 | ir_IF_FALSE(if_type); |
13105 | 0 | if_type = IR_UNUSED; |
13106 | 0 | } |
13107 | |
|
13108 | 0 | if (opline->opcode != ZEND_FETCH_DIM_RW) { |
13109 | 0 | jit_SET_EX_OPLINE(jit, opline); |
13110 | 0 | } |
13111 | |
|
13112 | 0 | if (opline->op2_type == IS_UNUSED) { |
13113 | 0 | arg2 = IR_NULL; |
13114 | 0 | } else if (opline->op2_type == IS_CONST && Z_EXTRA_P(RT_CONSTANT(opline, opline->op2)) == ZEND_EXTRA_VALUE) { |
13115 | 0 | ZEND_ASSERT(Z_MODE(op2_addr) == IS_CONST_ZVAL); |
13116 | 0 | arg2 = ir_CONST_ADDR(Z_ZV(op2_addr) + 1); |
13117 | 0 | } else { |
13118 | 0 | arg2 = jit_ZVAL_ADDR(jit, op2_addr); |
13119 | 0 | } |
13120 | |
|
13121 | 0 | switch (opline->opcode) { |
13122 | 0 | case ZEND_FETCH_DIM_W: |
13123 | 0 | case ZEND_FETCH_LIST_W: |
13124 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_dim_obj_w_helper), |
13125 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
13126 | 0 | arg2, |
13127 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
13128 | 0 | break; |
13129 | 0 | case ZEND_FETCH_DIM_RW: |
13130 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_dim_obj_rw_helper), |
13131 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
13132 | 0 | arg2, |
13133 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
13134 | 0 | break; |
13135 | | // case ZEND_FETCH_DIM_UNSET: |
13136 | | // | EXT_CALL zend_jit_fetch_dim_obj_unset_helper, r0 |
13137 | | // break; |
13138 | 0 | default: |
13139 | 0 | ZEND_UNREACHABLE(); |
13140 | 0 | } |
13141 | | |
13142 | 0 | if (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_ARRAY)) { |
13143 | 0 | ir_END_list(end_inputs); |
13144 | 0 | } |
13145 | 0 | } |
13146 | | |
13147 | 0 | #ifdef ZEND_JIT_USE_RC_INFERENCE |
13148 | 0 | if ((opline->op2_type & (IS_TMP_VAR|IS_VAR)) && (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_ARRAY|MAY_BE_OBJECT))) { |
13149 | | /* ASSIGN_DIM may increase refcount of the key */ |
13150 | 0 | op2_info |= MAY_BE_RCN; |
13151 | 0 | } |
13152 | 0 | #endif |
13153 | |
|
13154 | 0 | if ((opline->op2_type & (IS_TMP_VAR|IS_VAR)) |
13155 | 0 | && (op2_info & MAY_HAVE_DTOR) |
13156 | 0 | && (op2_info & MAY_BE_RC1)) { |
13157 | 0 | may_throw = 1; |
13158 | 0 | } |
13159 | |
|
13160 | 0 | if (end_inputs) { |
13161 | 0 | ir_MERGE_list(end_inputs); |
13162 | 0 | } |
13163 | |
|
13164 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, opline); |
13165 | |
|
13166 | 0 | if (may_throw) { |
13167 | 0 | zend_jit_check_exception(jit); |
13168 | 0 | } |
13169 | |
|
13170 | 0 | return 1; |
13171 | 0 | } |
13172 | | |
13173 | | static int zend_jit_isset_isempty_dim(zend_jit_ctx *jit, |
13174 | | const zend_op *opline, |
13175 | | uint32_t op1_info, |
13176 | | zend_jit_addr op1_addr, |
13177 | | bool op1_avoid_refcounting, |
13178 | | uint32_t op2_info, |
13179 | | zend_jit_addr op2_addr, |
13180 | | zend_ssa_range *op2_range, |
13181 | | uint8_t dim_type, |
13182 | | int may_throw, |
13183 | | uint8_t smart_branch_opcode, |
13184 | | uint32_t target_label, |
13185 | | uint32_t target_label2, |
13186 | | const void *exit_addr) |
13187 | 0 | { |
13188 | 0 | zend_jit_addr res_addr; |
13189 | 0 | ir_ref if_type = IR_UNUSED; |
13190 | 0 | ir_ref false_inputs = IR_UNUSED, end_inputs = IR_UNUSED; |
13191 | 0 | ir_refs *true_inputs; |
13192 | |
|
13193 | 0 | ir_refs_init(true_inputs, 8); |
13194 | | |
13195 | | // TODO: support for empty() ??? |
13196 | 0 | ZEND_ASSERT(!(opline->extended_value & ZEND_ISEMPTY)); |
13197 | |
|
13198 | 0 | res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
13199 | |
|
13200 | 0 | if (op1_info & MAY_BE_REF) { |
13201 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, op1_addr); |
13202 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
13203 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
13204 | 0 | } |
13205 | |
|
13206 | 0 | if (op1_info & MAY_BE_ARRAY) { |
13207 | 0 | const void *found_exit_addr = NULL; |
13208 | 0 | const void *not_found_exit_addr = NULL; |
13209 | 0 | ir_ref ht_ref; |
13210 | |
|
13211 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - MAY_BE_ARRAY)) { |
13212 | 0 | if_type = jit_if_Z_TYPE(jit, op1_addr, IS_ARRAY); |
13213 | 0 | ir_IF_TRUE(if_type); |
13214 | 0 | } |
13215 | |
|
13216 | 0 | ht_ref = jit_Z_PTR(jit, op1_addr); |
13217 | |
|
13218 | 0 | if (exit_addr |
13219 | 0 | && !(op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_ARRAY)) |
13220 | 0 | && !may_throw |
13221 | 0 | && (!(opline->op1_type & (IS_TMP_VAR|IS_VAR)) || op1_avoid_refcounting) |
13222 | 0 | && (!(opline->op2_type & (IS_TMP_VAR|IS_VAR)) || !(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)))) { |
13223 | 0 | if (smart_branch_opcode == ZEND_JMPNZ) { |
13224 | 0 | found_exit_addr = exit_addr; |
13225 | 0 | } else { |
13226 | 0 | not_found_exit_addr = exit_addr; |
13227 | 0 | } |
13228 | 0 | } |
13229 | 0 | if (!zend_jit_fetch_dimension_address_inner(jit, opline, BP_JIT_IS, op1_info, |
13230 | 0 | op2_info, op2_addr, op2_range, dim_type, found_exit_addr, not_found_exit_addr, NULL, |
13231 | 0 | false, ht_ref, true_inputs, NULL, &false_inputs, NULL)) { |
13232 | 0 | return 0; |
13233 | 0 | } |
13234 | | |
13235 | 0 | if (found_exit_addr) { |
13236 | 0 | ir_MERGE_list(false_inputs); |
13237 | 0 | return 1; |
13238 | 0 | } else if (not_found_exit_addr) { |
13239 | 0 | ir_MERGE_N(true_inputs->count, true_inputs->refs); |
13240 | 0 | return 1; |
13241 | 0 | } |
13242 | 0 | } |
13243 | | |
13244 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_ARRAY)) { |
13245 | 0 | if (if_type) { |
13246 | 0 | ir_IF_FALSE(if_type); |
13247 | 0 | if_type = IR_UNUSED; |
13248 | 0 | } |
13249 | |
|
13250 | 0 | if (op1_info & (MAY_BE_STRING|MAY_BE_OBJECT)) { |
13251 | 0 | ir_ref ref, arg1, arg2, if_true; |
13252 | |
|
13253 | 0 | jit_SET_EX_OPLINE(jit, opline); |
13254 | 0 | arg1 = jit_ZVAL_ADDR(jit, op1_addr); |
13255 | 0 | if (opline->op2_type == IS_CONST && Z_EXTRA_P(RT_CONSTANT(opline, opline->op2)) == ZEND_EXTRA_VALUE) { |
13256 | 0 | ZEND_ASSERT(Z_MODE(op2_addr) == IS_CONST_ZVAL); |
13257 | 0 | arg2 = ir_CONST_ADDR(Z_ZV(op2_addr)+1); |
13258 | 0 | } else { |
13259 | 0 | arg2 = jit_ZVAL_ADDR(jit, op2_addr); |
13260 | 0 | } |
13261 | 0 | ref = ir_CALL_2(IR_I32, ir_CONST_FC_FUNC(zend_jit_isset_dim_helper), arg1, arg2); |
13262 | 0 | if_true = ir_IF(ref); |
13263 | 0 | ir_IF_TRUE(if_true); |
13264 | 0 | ir_refs_add(true_inputs, ir_END()); |
13265 | 0 | ir_IF_FALSE(if_true); |
13266 | 0 | ir_END_list(false_inputs); |
13267 | 0 | } else { |
13268 | 0 | if (op2_info & MAY_BE_UNDEF) { |
13269 | 0 | ir_ref end1 = IR_UNUSED; |
13270 | |
|
13271 | 0 | if (op2_info & MAY_BE_ANY) { |
13272 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE(jit, op2_addr)); |
13273 | 0 | ir_IF_TRUE(if_def); |
13274 | 0 | end1 = ir_END(); |
13275 | 0 | ir_IF_FALSE(if_def); |
13276 | 0 | } |
13277 | 0 | jit_SET_EX_OPLINE(jit, opline); |
13278 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op2.var)); |
13279 | 0 | if (end1) { |
13280 | 0 | ir_MERGE_WITH(end1); |
13281 | 0 | } |
13282 | 0 | } |
13283 | 0 | ir_END_list(false_inputs); |
13284 | 0 | } |
13285 | 0 | } |
13286 | |
|
13287 | 0 | #ifdef ZEND_JIT_USE_RC_INFERENCE |
13288 | 0 | if ((opline->op2_type & (IS_TMP_VAR|IS_VAR)) && (op1_info & MAY_BE_OBJECT)) { |
13289 | | /* Magic offsetExists() may increase refcount of the key */ |
13290 | 0 | op2_info |= MAY_BE_RCN; |
13291 | 0 | } |
13292 | 0 | #endif |
13293 | |
|
13294 | 0 | if (true_inputs->count) { |
13295 | 0 | ir_MERGE_N(true_inputs->count, true_inputs->refs); |
13296 | |
|
13297 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, opline); |
13298 | 0 | if (!op1_avoid_refcounting) { |
13299 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
13300 | 0 | } |
13301 | 0 | if (may_throw) { |
13302 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
13303 | 0 | } |
13304 | 0 | if (!(opline->extended_value & ZEND_ISEMPTY)) { |
13305 | 0 | if (exit_addr) { |
13306 | 0 | if (smart_branch_opcode == ZEND_JMPNZ) { |
13307 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
13308 | 0 | } else { |
13309 | 0 | ir_END_list(end_inputs); |
13310 | 0 | } |
13311 | 0 | } else if (smart_branch_opcode) { |
13312 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
13313 | 0 | _zend_jit_add_predecessor_ref(jit, target_label2, jit->b, ir_END()); |
13314 | 0 | } else if (smart_branch_opcode == ZEND_JMPNZ) { |
13315 | 0 | _zend_jit_add_predecessor_ref(jit, target_label, jit->b, ir_END()); |
13316 | 0 | } else { |
13317 | 0 | ZEND_UNREACHABLE(); |
13318 | 0 | } |
13319 | 0 | } else { |
13320 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_TRUE); |
13321 | 0 | ir_END_list(end_inputs); |
13322 | 0 | } |
13323 | 0 | } else { |
13324 | 0 | ZEND_UNREACHABLE(); // TODO: support for empty() |
13325 | 0 | } |
13326 | 0 | } |
13327 | | |
13328 | 0 | ir_MERGE_list(false_inputs); |
13329 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, opline); |
13330 | 0 | if (!op1_avoid_refcounting) { |
13331 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
13332 | 0 | } |
13333 | 0 | if (may_throw) { |
13334 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
13335 | 0 | } |
13336 | 0 | if (!(opline->extended_value & ZEND_ISEMPTY)) { |
13337 | 0 | if (exit_addr) { |
13338 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
13339 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
13340 | 0 | } else { |
13341 | 0 | ir_END_list(end_inputs); |
13342 | 0 | } |
13343 | 0 | } else if (smart_branch_opcode) { |
13344 | 0 | if (smart_branch_opcode == ZEND_JMPZ) { |
13345 | 0 | _zend_jit_add_predecessor_ref(jit, target_label, jit->b, ir_END()); |
13346 | 0 | } else if (smart_branch_opcode == ZEND_JMPNZ) { |
13347 | 0 | _zend_jit_add_predecessor_ref(jit, target_label2, jit->b, ir_END()); |
13348 | 0 | } else { |
13349 | 0 | ZEND_UNREACHABLE(); |
13350 | 0 | } |
13351 | 0 | } else { |
13352 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_FALSE); |
13353 | 0 | ir_END_list(end_inputs); |
13354 | 0 | } |
13355 | 0 | } else { |
13356 | 0 | ZEND_UNREACHABLE(); // TODO: support for empty() |
13357 | 0 | } |
13358 | | |
13359 | 0 | if (!exit_addr && smart_branch_opcode) { |
13360 | 0 | jit->b = -1; |
13361 | 0 | } else { |
13362 | 0 | ir_MERGE_list(end_inputs); |
13363 | 0 | } |
13364 | |
|
13365 | 0 | return 1; |
13366 | 0 | } |
13367 | | |
13368 | | static int zend_jit_assign_dim(zend_jit_ctx *jit, |
13369 | | const zend_op *opline, |
13370 | | uint32_t op1_info, |
13371 | | zend_jit_addr op1_addr, |
13372 | | bool op1_indirect, |
13373 | | uint32_t op2_info, |
13374 | | zend_jit_addr op2_addr, |
13375 | | zend_ssa_range *op2_range, |
13376 | | uint32_t val_info, |
13377 | | zend_jit_addr op3_addr, |
13378 | | zend_jit_addr op3_def_addr, |
13379 | | zend_jit_addr res_addr, |
13380 | | uint8_t dim_type, |
13381 | | int may_throw) |
13382 | 0 | { |
13383 | 0 | ir_ref if_type = IR_UNUSED; |
13384 | 0 | ir_ref end_inputs = IR_UNUSED, ht_ref; |
13385 | |
|
13386 | 0 | if (op3_addr != op3_def_addr && op3_def_addr) { |
13387 | 0 | if (!zend_jit_update_regs(jit, (opline+1)->op1.var, op3_addr, op3_def_addr, val_info)) { |
13388 | 0 | return 0; |
13389 | 0 | } |
13390 | 0 | if (Z_MODE(op3_def_addr) == IS_REG && Z_MODE(op3_addr) != IS_REG) { |
13391 | 0 | op3_addr = op3_def_addr; |
13392 | 0 | } |
13393 | 0 | } |
13394 | | |
13395 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && (val_info & MAY_BE_UNDEF)) { |
13396 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
13397 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
13398 | |
|
13399 | 0 | if (!exit_addr) { |
13400 | 0 | return 0; |
13401 | 0 | } |
13402 | | |
13403 | 0 | jit_guard_not_Z_TYPE(jit, op3_addr, IS_UNDEF, exit_addr); |
13404 | |
|
13405 | 0 | val_info &= ~MAY_BE_UNDEF; |
13406 | 0 | } |
13407 | | |
13408 | 0 | op1_addr = zend_jit_prepare_array_update(jit, opline, &op1_info, op1_addr, &if_type, &ht_ref, &may_throw); |
13409 | |
|
13410 | 0 | if (op1_info & MAY_BE_ARRAY) { |
13411 | 0 | if (opline->op2_type == IS_UNUSED) { |
13412 | 0 | uint32_t var_info = MAY_BE_NULL; |
13413 | 0 | ir_ref if_ok, ref; |
13414 | 0 | zend_jit_addr var_addr; |
13415 | | |
13416 | | // JIT: var_ptr = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval)); |
13417 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_next_index_insert), |
13418 | 0 | ht_ref, jit_EG(uninitialized_zval)); |
13419 | | |
13420 | | // JIT: if (UNEXPECTED(!var_ptr)) { |
13421 | 0 | if_ok = ir_IF(ref); |
13422 | 0 | ir_IF_FALSE_cold(if_ok); |
13423 | | |
13424 | | // JIT: zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied"); |
13425 | 0 | jit_SET_EX_OPLINE(jit, opline); |
13426 | 0 | ir_CALL(IR_VOID, jit_STUB_FUNC_ADDR(jit, jit_stub_cannot_add_element, IR_FASTCALL_FUNC)); |
13427 | |
|
13428 | 0 | ir_END_list(end_inputs); |
13429 | |
|
13430 | 0 | ir_IF_TRUE(if_ok); |
13431 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
13432 | 0 | if (!zend_jit_simple_assign(jit, opline, var_addr, var_info, -1, (opline+1)->op1_type, op3_addr, val_info, res_addr, false)) { |
13433 | 0 | return 0; |
13434 | 0 | } |
13435 | 0 | } else { |
13436 | 0 | uint32_t var_info = zend_array_element_type(op1_info, opline->op1_type, 0, 0); |
13437 | 0 | zend_jit_addr var_addr; |
13438 | 0 | ir_ref ref; |
13439 | 0 | ir_refs *found_inputs, *found_values; |
13440 | |
|
13441 | 0 | ir_refs_init(found_inputs, 8); |
13442 | 0 | ir_refs_init(found_values, 8); |
13443 | |
|
13444 | 0 | if (!zend_jit_fetch_dimension_address_inner(jit, opline, BP_VAR_W, op1_info, |
13445 | 0 | op2_info, op2_addr, op2_range, dim_type, NULL, NULL, NULL, |
13446 | 0 | false, ht_ref, found_inputs, found_values, &end_inputs, NULL)) { |
13447 | 0 | return 0; |
13448 | 0 | } |
13449 | | |
13450 | 0 | if (op1_info & (MAY_BE_ARRAY_OF_REF|MAY_BE_OBJECT)) { |
13451 | 0 | var_info |= MAY_BE_REF; |
13452 | 0 | } |
13453 | 0 | if (var_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
13454 | 0 | var_info |= MAY_BE_RC1; |
13455 | 0 | } |
13456 | |
|
13457 | 0 | if (found_inputs->count) { |
13458 | 0 | ir_MERGE_N(found_inputs->count, found_inputs->refs); |
13459 | 0 | ref = ir_PHI_N(IR_ADDR, found_values->count, found_values->refs); |
13460 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
13461 | | |
13462 | | // JIT: value = zend_assign_to_variable(variable_ptr, value, OP_DATA_TYPE); |
13463 | 0 | if (opline->op1_type == IS_VAR |
13464 | 0 | && Z_MODE(op3_addr) != IS_REG |
13465 | 0 | && opline->result_type == IS_UNUSED |
13466 | 0 | && (res_addr == 0 || Z_MODE(res_addr) != IS_REG)) { |
13467 | 0 | if (!zend_jit_assign_to_variable_call(jit, opline, var_addr, var_addr, var_info, -1, (opline+1)->op1_type, op3_addr, val_info, res_addr, false)) { |
13468 | 0 | return 0; |
13469 | 0 | } |
13470 | 0 | } else { |
13471 | 0 | if (!zend_jit_assign_to_variable(jit, opline, var_addr, var_addr, var_info, -1, (opline+1)->op1_type, op3_addr, val_info, res_addr, 0, false)) { |
13472 | 0 | return 0; |
13473 | 0 | } |
13474 | 0 | } |
13475 | 0 | } |
13476 | 0 | } |
13477 | | |
13478 | 0 | ir_END_list(end_inputs); |
13479 | 0 | } |
13480 | | |
13481 | 0 | if (op1_info & (MAY_BE_ANY-MAY_BE_ARRAY)) { |
13482 | 0 | ir_ref arg2, arg4; |
13483 | |
|
13484 | 0 | if (if_type) { |
13485 | 0 | ir_IF_FALSE_cold(if_type); |
13486 | 0 | if_type = IR_UNUSED; |
13487 | 0 | } |
13488 | |
|
13489 | 0 | jit_SET_EX_OPLINE(jit, opline); |
13490 | |
|
13491 | 0 | if (opline->op2_type == IS_UNUSED) { |
13492 | 0 | arg2 = IR_NULL; |
13493 | 0 | } else if (opline->op2_type == IS_CONST && Z_EXTRA_P(RT_CONSTANT(opline, opline->op2)) == ZEND_EXTRA_VALUE) { |
13494 | 0 | ZEND_ASSERT(Z_MODE(op2_addr) == IS_CONST_ZVAL); |
13495 | 0 | arg2 = ir_CONST_ADDR(Z_ZV(op2_addr) + 1); |
13496 | 0 | } else { |
13497 | 0 | arg2 = jit_ZVAL_ADDR(jit, op2_addr); |
13498 | 0 | } |
13499 | |
|
13500 | 0 | if (opline->result_type == IS_UNUSED) { |
13501 | 0 | arg4 = IR_NULL; |
13502 | 0 | } else { |
13503 | 0 | arg4 = jit_ZVAL_ADDR(jit, res_addr); |
13504 | 0 | } |
13505 | 0 | ir_CALL_4(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_dim_helper), |
13506 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
13507 | 0 | arg2, |
13508 | 0 | jit_ZVAL_ADDR(jit, op3_addr), |
13509 | 0 | arg4); |
13510 | |
|
13511 | 0 | #ifdef ZEND_JIT_USE_RC_INFERENCE |
13512 | 0 | if (((opline+1)->op1_type & (IS_TMP_VAR|IS_VAR)) && (val_info & MAY_BE_RC1)) { |
13513 | | /* ASSIGN_DIM may increase refcount of the value */ |
13514 | 0 | val_info |= MAY_BE_RCN; |
13515 | 0 | } |
13516 | 0 | #endif |
13517 | |
|
13518 | 0 | jit_FREE_OP(jit, (opline+1)->op1_type, (opline+1)->op1, val_info, NULL); |
13519 | |
|
13520 | 0 | ir_END_list(end_inputs); |
13521 | 0 | } |
13522 | |
|
13523 | 0 | #ifdef ZEND_JIT_USE_RC_INFERENCE |
13524 | 0 | if ((opline->op2_type & (IS_TMP_VAR|IS_VAR)) && (op1_info & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_ARRAY|MAY_BE_OBJECT))) { |
13525 | | /* ASSIGN_DIM may increase refcount of the key */ |
13526 | 0 | op2_info |= MAY_BE_RCN; |
13527 | 0 | } |
13528 | 0 | #endif |
13529 | |
|
13530 | 0 | ir_MERGE_list(end_inputs); |
13531 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, opline); |
13532 | |
|
13533 | 0 | if (!op1_indirect) { |
13534 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
13535 | 0 | } |
13536 | |
|
13537 | 0 | if (may_throw) { |
13538 | 0 | zend_jit_check_exception(jit); |
13539 | 0 | } |
13540 | |
|
13541 | 0 | return 1; |
13542 | 0 | } |
13543 | | |
13544 | | static int zend_jit_assign_dim_op(zend_jit_ctx *jit, |
13545 | | const zend_op *opline, |
13546 | | uint32_t op1_info, |
13547 | | uint32_t op1_def_info, |
13548 | | zend_jit_addr op1_addr, |
13549 | | bool op1_indirect, |
13550 | | uint32_t op2_info, |
13551 | | zend_jit_addr op2_addr, |
13552 | | zend_ssa_range *op2_range, |
13553 | | uint32_t op1_data_info, |
13554 | | zend_jit_addr op3_addr, |
13555 | | zend_ssa_range *op1_data_range, |
13556 | | uint8_t dim_type, |
13557 | | int may_throw) |
13558 | 0 | { |
13559 | 0 | zend_jit_addr var_addr = IS_UNUSED; |
13560 | 0 | const void *not_found_exit_addr = NULL; |
13561 | 0 | uint32_t var_info = MAY_BE_NULL; |
13562 | 0 | ir_ref if_type = IS_UNUSED; |
13563 | 0 | ir_ref end_inputs = IR_UNUSED, ht_ref; |
13564 | 0 | bool emit_fast_path = true; |
13565 | |
|
13566 | 0 | ZEND_ASSERT(opline->result_type == IS_UNUSED); |
13567 | |
|
13568 | 0 | if (may_throw) { |
13569 | 0 | jit_SET_EX_OPLINE(jit, opline); |
13570 | 0 | } |
13571 | |
|
13572 | 0 | op1_addr = zend_jit_prepare_array_update(jit, opline, &op1_info, op1_addr, &if_type, &ht_ref, &may_throw); |
13573 | |
|
13574 | 0 | if (Z_MODE(op3_addr) == IS_REG |
13575 | 0 | && Z_LOAD(op3_addr) |
13576 | 0 | && jit->ra[Z_SSA_VAR(op3_addr)].ref == IR_NULL) { |
13577 | | /* Force load */ |
13578 | 0 | zend_jit_use_reg(jit, op3_addr); |
13579 | 0 | } |
13580 | |
|
13581 | 0 | if (op1_info & MAY_BE_ARRAY) { |
13582 | 0 | uint32_t var_def_info = zend_array_element_type(op1_def_info, opline->op1_type, 1, 0); |
13583 | |
|
13584 | 0 | if (opline->op2_type == IS_UNUSED) { |
13585 | 0 | var_info = MAY_BE_NULL; |
13586 | 0 | ir_ref if_ok, ref; |
13587 | | |
13588 | | // JIT: var_ptr = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval)); |
13589 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_hash_next_index_insert), |
13590 | 0 | ht_ref, jit_EG(uninitialized_zval)); |
13591 | | |
13592 | | // JIT: if (UNEXPECTED(!var_ptr)) { |
13593 | 0 | if_ok = ir_IF(ref); |
13594 | 0 | ir_IF_FALSE_cold(if_ok); |
13595 | | |
13596 | | // JIT: zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied"); |
13597 | 0 | ir_CALL(IR_VOID, jit_STUB_FUNC_ADDR(jit, jit_stub_cannot_add_element, IR_FASTCALL_FUNC)); |
13598 | |
|
13599 | 0 | ir_END_list(end_inputs); |
13600 | |
|
13601 | 0 | ir_IF_TRUE(if_ok); |
13602 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
13603 | 0 | } else { |
13604 | 0 | ir_ref ref; |
13605 | 0 | ir_refs *found_inputs, *found_values; |
13606 | |
|
13607 | 0 | ir_refs_init(found_inputs, 8); |
13608 | 0 | ir_refs_init(found_values, 8); |
13609 | |
|
13610 | 0 | var_info = zend_array_element_type(op1_info, opline->op1_type, 0, 0); |
13611 | 0 | if (op1_info & (MAY_BE_ARRAY_OF_REF|MAY_BE_OBJECT)) { |
13612 | 0 | var_info |= MAY_BE_REF; |
13613 | 0 | } |
13614 | 0 | if (var_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
13615 | 0 | var_info |= MAY_BE_RC1; |
13616 | 0 | } |
13617 | |
|
13618 | 0 | if (dim_type != IS_UNKNOWN |
13619 | 0 | && dim_type != IS_UNDEF |
13620 | 0 | && (op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY |
13621 | 0 | && (op2_info & (MAY_BE_LONG|MAY_BE_STRING)) |
13622 | 0 | && !(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF) - (MAY_BE_LONG|MAY_BE_STRING)))) { |
13623 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
13624 | 0 | not_found_exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
13625 | 0 | if (!not_found_exit_addr) { |
13626 | 0 | return 0; |
13627 | 0 | } |
13628 | 0 | } |
13629 | | |
13630 | 0 | if (!zend_jit_fetch_dimension_address_inner(jit, opline, BP_VAR_RW, op1_info, |
13631 | 0 | op2_info, op2_addr, op2_range, dim_type, NULL, not_found_exit_addr, NULL, |
13632 | 0 | false, ht_ref, found_inputs, found_values, &end_inputs, NULL)) { |
13633 | 0 | return 0; |
13634 | 0 | } |
13635 | | |
13636 | 0 | if (found_inputs->count) { |
13637 | 0 | ir_MERGE_N(found_inputs->count, found_inputs->refs); |
13638 | 0 | ref = ir_PHI_N(IR_ADDR, found_values->count, found_values->refs); |
13639 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
13640 | |
|
13641 | 0 | if (not_found_exit_addr && dim_type != IS_REFERENCE) { |
13642 | 0 | jit_guard_Z_TYPE(jit, var_addr, dim_type, not_found_exit_addr); |
13643 | 0 | var_info = (1 << dim_type) | (var_info & ~(MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF)); |
13644 | 0 | } |
13645 | 0 | if (var_info & MAY_BE_REF) { |
13646 | 0 | binary_op_type binary_op = get_binary_op(opline->extended_value); |
13647 | 0 | ir_ref if_ref, if_typed, noref_path, ref_path, ref, reference, ref2, arg2; |
13648 | |
|
13649 | 0 | ref = jit_ZVAL_ADDR(jit, var_addr); |
13650 | 0 | if_ref = jit_if_Z_TYPE(jit, var_addr, IS_REFERENCE); |
13651 | 0 | ir_IF_FALSE(if_ref); |
13652 | 0 | noref_path = ir_END(); |
13653 | 0 | ir_IF_TRUE(if_ref); |
13654 | |
|
13655 | 0 | reference = jit_Z_PTR_ref(jit, ref); |
13656 | 0 | ref2 = ir_ADD_OFFSET(reference, offsetof(zend_reference, val)); |
13657 | 0 | if_typed = jit_if_TYPED_REF(jit, reference); |
13658 | 0 | ir_IF_FALSE(if_typed); |
13659 | 0 | ref_path = ir_END(); |
13660 | 0 | ir_IF_TRUE_cold(if_typed); |
13661 | |
|
13662 | 0 | if (Z_MODE(op3_addr) == IS_REG) { |
13663 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, (opline+1)->op1.var); |
13664 | 0 | if (!zend_jit_spill_store_inv(jit, op3_addr, real_addr, op1_data_info)) { |
13665 | 0 | return 0; |
13666 | 0 | } |
13667 | 0 | op3_addr = real_addr; |
13668 | 0 | } |
13669 | 0 | arg2 = jit_ZVAL_ADDR(jit, op3_addr); |
13670 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_op_to_typed_ref), |
13671 | 0 | reference, arg2, ir_CONST_FC_FUNC(binary_op)); |
13672 | |
|
13673 | 0 | ir_END_list(end_inputs); |
13674 | |
|
13675 | 0 | ir_MERGE_2(noref_path, ref_path); |
13676 | 0 | ref = ir_PHI_2(IR_ADDR, ref, ref2); |
13677 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
13678 | 0 | } |
13679 | 0 | } else { |
13680 | 0 | emit_fast_path = false; |
13681 | 0 | } |
13682 | 0 | } |
13683 | | |
13684 | 0 | if (emit_fast_path) { |
13685 | 0 | uint8_t val_op_type = (opline+1)->op1_type; |
13686 | |
|
13687 | 0 | if (val_op_type & (IS_TMP_VAR|IS_VAR)) { |
13688 | | /* prevent FREE_OP in the helpers */ |
13689 | 0 | val_op_type = IS_CV; |
13690 | 0 | } |
13691 | |
|
13692 | 0 | switch (opline->extended_value) { |
13693 | 0 | case ZEND_ADD: |
13694 | 0 | case ZEND_SUB: |
13695 | 0 | case ZEND_MUL: |
13696 | 0 | case ZEND_DIV: |
13697 | 0 | if (!zend_jit_math_helper(jit, opline, opline->extended_value, IS_CV, opline->op1, var_addr, var_info, val_op_type, (opline+1)->op1, op3_addr, op1_data_info, 0, var_addr, var_def_info, var_info, |
13698 | 0 | 1 /* may overflow */, may_throw)) { |
13699 | 0 | return 0; |
13700 | 0 | } |
13701 | 0 | break; |
13702 | 0 | case ZEND_BW_OR: |
13703 | 0 | case ZEND_BW_AND: |
13704 | 0 | case ZEND_BW_XOR: |
13705 | 0 | case ZEND_SL: |
13706 | 0 | case ZEND_SR: |
13707 | 0 | case ZEND_MOD: |
13708 | 0 | if (!zend_jit_long_math_helper(jit, opline, opline->extended_value, |
13709 | 0 | IS_CV, opline->op1, var_addr, var_info, NULL, |
13710 | 0 | val_op_type, (opline+1)->op1, op3_addr, op1_data_info, |
13711 | 0 | op1_data_range, |
13712 | 0 | 0, var_addr, var_def_info, var_info, may_throw)) { |
13713 | 0 | return 0; |
13714 | 0 | } |
13715 | 0 | break; |
13716 | 0 | case ZEND_CONCAT: |
13717 | 0 | if (!zend_jit_concat_helper(jit, opline, IS_CV, opline->op1, var_addr, var_info, val_op_type, (opline+1)->op1, op3_addr, op1_data_info, var_addr, |
13718 | 0 | may_throw)) { |
13719 | 0 | return 0; |
13720 | 0 | } |
13721 | 0 | break; |
13722 | 0 | default: |
13723 | 0 | ZEND_UNREACHABLE(); |
13724 | 0 | } |
13725 | | |
13726 | 0 | ir_END_list(end_inputs); |
13727 | 0 | } |
13728 | 0 | } |
13729 | | |
13730 | 0 | if (op1_info & (MAY_BE_ANY-MAY_BE_ARRAY)) { |
13731 | 0 | binary_op_type binary_op; |
13732 | 0 | ir_ref arg2; |
13733 | |
|
13734 | 0 | if (if_type) { |
13735 | 0 | ir_IF_FALSE_cold(if_type); |
13736 | 0 | if_type = IS_UNUSED; |
13737 | 0 | } |
13738 | |
|
13739 | 0 | if (opline->op2_type == IS_UNUSED) { |
13740 | 0 | arg2 = IR_NULL; |
13741 | 0 | } else if (opline->op2_type == IS_CONST && Z_EXTRA_P(RT_CONSTANT(opline, opline->op2)) == ZEND_EXTRA_VALUE) { |
13742 | 0 | ZEND_ASSERT(Z_MODE(op2_addr) == IS_CONST_ZVAL); |
13743 | 0 | arg2 = ir_CONST_ADDR(Z_ZV(op2_addr) + 1); |
13744 | 0 | } else { |
13745 | 0 | arg2 = jit_ZVAL_ADDR(jit, op2_addr); |
13746 | 0 | } |
13747 | 0 | binary_op = get_binary_op(opline->extended_value); |
13748 | 0 | ir_CALL_4(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_dim_op_helper), |
13749 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
13750 | 0 | arg2, |
13751 | 0 | jit_ZVAL_ADDR(jit, op3_addr), |
13752 | 0 | ir_CONST_FC_FUNC(binary_op)); |
13753 | 0 | ir_END_list(end_inputs); |
13754 | 0 | } |
13755 | |
|
13756 | 0 | if (end_inputs) { |
13757 | 0 | ir_MERGE_list(end_inputs); |
13758 | 0 | } |
13759 | |
|
13760 | 0 | jit_FREE_OP(jit, (opline+1)->op1_type, (opline+1)->op1, op1_data_info, NULL); |
13761 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, NULL); |
13762 | 0 | if (!op1_indirect) { |
13763 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL); |
13764 | 0 | } |
13765 | 0 | if (may_throw) { |
13766 | 0 | zend_jit_check_exception(jit); |
13767 | 0 | } |
13768 | |
|
13769 | 0 | return 1; |
13770 | 0 | } |
13771 | | |
13772 | | static int zend_jit_fe_reset(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info) |
13773 | 0 | { |
13774 | 0 | zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
13775 | | |
13776 | | // JIT: ZVAL_COPY(res, value); |
13777 | 0 | if (opline->op1_type == IS_CONST) { |
13778 | 0 | zval *zv = RT_CONSTANT(opline, opline->op1); |
13779 | |
|
13780 | 0 | jit_ZVAL_COPY_CONST(jit, res_addr, MAY_BE_ANY, MAY_BE_ANY, zv, true); |
13781 | 0 | } else { |
13782 | 0 | zend_jit_addr op1_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op1.var); |
13783 | |
|
13784 | 0 | jit_ZVAL_COPY(jit, res_addr, -1, op1_addr, op1_info, opline->op1_type == IS_CV); |
13785 | 0 | } |
13786 | | |
13787 | | // JIT: Z_FE_POS_P(res) = 0; |
13788 | 0 | ir_STORE(ir_ADD_OFFSET(jit_FP(jit), opline->result.var + offsetof(zval, u2.fe_pos)), ir_CONST_U32(0)); |
13789 | |
|
13790 | 0 | return 1; |
13791 | 0 | } |
13792 | | |
13793 | | static int zend_jit_packed_guard(zend_jit_ctx *jit, const zend_op *opline, uint32_t var, uint32_t op_info) |
13794 | 0 | { |
13795 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_PACKED_GUARD); |
13796 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
13797 | 0 | zend_jit_addr addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var); |
13798 | 0 | ir_ref ref; |
13799 | |
|
13800 | 0 | if (!exit_addr) { |
13801 | 0 | return 0; |
13802 | 0 | } |
13803 | | |
13804 | 0 | ref = ir_AND_U32( |
13805 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(jit_Z_PTR(jit, addr), offsetof(zend_array, u.flags))), |
13806 | 0 | ir_CONST_U32(HASH_FLAG_PACKED)); |
13807 | 0 | if (op_info & MAY_BE_ARRAY_PACKED) { |
13808 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
13809 | 0 | } else { |
13810 | 0 | ir_GUARD_NOT(ref, ir_CONST_ADDR(exit_addr)); |
13811 | 0 | } |
13812 | |
|
13813 | 0 | return 1; |
13814 | 0 | } |
13815 | | |
13816 | | static int zend_jit_fe_fetch(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, uint32_t op2_info, unsigned int target_label, uint8_t exit_opcode, const void *exit_addr) |
13817 | 0 | { |
13818 | 0 | zend_jit_addr op1_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op1.var); |
13819 | 0 | ir_ref ref, ht_ref, hash_pos_ref, packed_pos_ref, hash_p_ref = IR_UNUSED, packed_p_ref = IR_UNUSED, if_packed = IR_UNUSED; |
13820 | 0 | ir_ref if_def_hash = IR_UNUSED, if_def_packed = IR_UNUSED; |
13821 | 0 | ir_ref exit_inputs = IR_UNUSED; |
13822 | |
|
13823 | 0 | if (!MAY_BE_HASH(op1_info) && !MAY_BE_PACKED(op1_info)) { |
13824 | | /* empty array */ |
13825 | 0 | if (exit_addr) { |
13826 | 0 | if (exit_opcode == ZEND_JMP) { |
13827 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
13828 | 0 | } |
13829 | 0 | } else { |
13830 | 0 | zend_basic_block *bb; |
13831 | |
|
13832 | 0 | ZEND_ASSERT(jit->b >= 0); |
13833 | 0 | bb = &jit->ssa->cfg.blocks[jit->b]; |
13834 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ir_END()); |
13835 | 0 | jit->b = -1; |
13836 | 0 | } |
13837 | 0 | return 1; |
13838 | 0 | } |
13839 | | |
13840 | | // JIT: array = EX_VAR(opline->op1.var); |
13841 | | // JIT: fe_ht = Z_ARRVAL_P(array); |
13842 | 0 | ht_ref = jit_Z_PTR(jit, op1_addr); |
13843 | |
|
13844 | 0 | if (op1_info & MAY_BE_PACKED_GUARD) { |
13845 | 0 | if (!zend_jit_packed_guard(jit, opline, opline->op1.var, op1_info)) { |
13846 | 0 | return 0; |
13847 | 0 | } |
13848 | 0 | } |
13849 | | |
13850 | | // JIT: pos = Z_FE_POS_P(array); |
13851 | 0 | hash_pos_ref = packed_pos_ref = ir_LOAD_U32(ir_ADD_OFFSET(jit_FP(jit), opline->op1.var + offsetof(zval, u2.fe_pos))); |
13852 | |
|
13853 | 0 | if (MAY_BE_HASH(op1_info)) { |
13854 | 0 | ir_ref loop_ref, pos2_ref, p2_ref; |
13855 | |
|
13856 | 0 | if (MAY_BE_PACKED(op1_info)) { |
13857 | 0 | ref = ir_AND_U32( |
13858 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(ht_ref, offsetof(zend_array, u.flags))), |
13859 | 0 | ir_CONST_U32(HASH_FLAG_PACKED)); |
13860 | 0 | if_packed = ir_IF(ref); |
13861 | 0 | ir_IF_FALSE(if_packed); |
13862 | 0 | } |
13863 | | |
13864 | | // JIT: p = fe_ht->arData + pos; |
13865 | 0 | if (sizeof(void*) == 8) { |
13866 | 0 | ref = ir_ZEXT_A(hash_pos_ref); |
13867 | 0 | } else { |
13868 | 0 | ref = ir_BITCAST_A(hash_pos_ref); |
13869 | 0 | } |
13870 | 0 | hash_p_ref = ir_ADD_A( |
13871 | 0 | ir_MUL_A(ref, ir_CONST_ADDR(sizeof(Bucket))), |
13872 | 0 | ir_LOAD_A(ir_ADD_OFFSET(ht_ref, offsetof(zend_array, arData)))); |
13873 | |
|
13874 | 0 | loop_ref = ir_LOOP_BEGIN(ir_END()); |
13875 | 0 | hash_pos_ref = ir_PHI_2(IR_U32, hash_pos_ref, IR_UNUSED); |
13876 | 0 | hash_p_ref = ir_PHI_2(IR_ADDR, hash_p_ref, IR_UNUSED); |
13877 | | |
13878 | | // JIT: if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { |
13879 | 0 | ref = ir_ULT(hash_pos_ref, |
13880 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(ht_ref, offsetof(zend_array, nNumUsed)))); |
13881 | | |
13882 | | // JIT: ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); |
13883 | | // JIT: ZEND_VM_CONTINUE(); |
13884 | |
|
13885 | 0 | if (exit_addr) { |
13886 | 0 | if (exit_opcode == ZEND_JMP) { |
13887 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
13888 | 0 | } else { |
13889 | 0 | ir_ref if_fit = ir_IF(ref); |
13890 | 0 | ir_IF_FALSE(if_fit); |
13891 | 0 | ir_END_list(exit_inputs); |
13892 | 0 | ir_IF_TRUE(if_fit); |
13893 | 0 | } |
13894 | 0 | } else { |
13895 | 0 | ir_ref if_fit = ir_IF(ref); |
13896 | 0 | ir_IF_FALSE(if_fit); |
13897 | 0 | ir_END_list(exit_inputs); |
13898 | 0 | ir_IF_TRUE(if_fit); |
13899 | 0 | } |
13900 | | |
13901 | | // JIT: pos++; |
13902 | 0 | pos2_ref = ir_ADD_U32(hash_pos_ref, ir_CONST_U32(1)); |
13903 | | |
13904 | | // JIT: value_type = Z_TYPE_INFO_P(value); |
13905 | | // JIT: if (EXPECTED(value_type != IS_UNDEF)) { |
13906 | 0 | if (!exit_addr || exit_opcode == ZEND_JMP) { |
13907 | 0 | if_def_hash = ir_IF(jit_Z_TYPE_ref(jit, hash_p_ref)); |
13908 | 0 | ir_IF_FALSE(if_def_hash); |
13909 | 0 | } else { |
13910 | 0 | ir_GUARD_NOT(jit_Z_TYPE_ref(jit, hash_p_ref), ir_CONST_ADDR(exit_addr)); |
13911 | 0 | } |
13912 | | |
13913 | | // JIT: p++; |
13914 | 0 | p2_ref = ir_ADD_OFFSET(hash_p_ref, sizeof(Bucket)); |
13915 | |
|
13916 | 0 | ir_MERGE_SET_OP(loop_ref, 2, ir_LOOP_END()); |
13917 | 0 | ir_PHI_SET_OP(hash_pos_ref, 2, pos2_ref); |
13918 | 0 | ir_PHI_SET_OP(hash_p_ref, 2, p2_ref); |
13919 | |
|
13920 | 0 | if (MAY_BE_PACKED(op1_info)) { |
13921 | 0 | ir_IF_TRUE(if_packed); |
13922 | 0 | } |
13923 | 0 | } |
13924 | 0 | if (MAY_BE_PACKED(op1_info)) { |
13925 | 0 | ir_ref loop_ref, pos2_ref, p2_ref; |
13926 | | |
13927 | | // JIT: p = fe_ht->arPacked + pos; |
13928 | 0 | if (sizeof(void*) == 8) { |
13929 | 0 | ref = ir_ZEXT_A(packed_pos_ref); |
13930 | 0 | } else { |
13931 | 0 | ref = ir_BITCAST_A(packed_pos_ref); |
13932 | 0 | } |
13933 | 0 | packed_p_ref = ir_ADD_A( |
13934 | 0 | ir_MUL_A(ref, ir_CONST_ADDR(sizeof(zval))), |
13935 | 0 | ir_LOAD_A(ir_ADD_OFFSET(ht_ref, offsetof(zend_array, arPacked)))); |
13936 | |
|
13937 | 0 | loop_ref = ir_LOOP_BEGIN(ir_END()); |
13938 | 0 | packed_pos_ref = ir_PHI_2(IR_U32, packed_pos_ref, IR_UNUSED); |
13939 | 0 | packed_p_ref = ir_PHI_2(IR_ADDR, packed_p_ref, IR_UNUSED); |
13940 | | |
13941 | | // JIT: if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { |
13942 | 0 | ref = ir_ULT(packed_pos_ref, |
13943 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(ht_ref, offsetof(zend_array, nNumUsed)))); |
13944 | | |
13945 | | // JIT: ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); |
13946 | | // JIT: ZEND_VM_CONTINUE(); |
13947 | 0 | if (exit_addr) { |
13948 | 0 | if (exit_opcode == ZEND_JMP) { |
13949 | 0 | ir_GUARD(ref, ir_CONST_ADDR(exit_addr)); |
13950 | 0 | } else { |
13951 | 0 | ir_ref if_fit = ir_IF(ref); |
13952 | 0 | ir_IF_FALSE(if_fit); |
13953 | 0 | ir_END_list(exit_inputs); |
13954 | 0 | ir_IF_TRUE(if_fit); |
13955 | 0 | } |
13956 | 0 | } else { |
13957 | 0 | ir_ref if_fit = ir_IF(ref); |
13958 | 0 | ir_IF_FALSE(if_fit); |
13959 | 0 | ir_END_list(exit_inputs); |
13960 | 0 | ir_IF_TRUE(if_fit); |
13961 | 0 | } |
13962 | | |
13963 | | // JIT: pos++; |
13964 | 0 | pos2_ref = ir_ADD_U32(packed_pos_ref, ir_CONST_U32(1)); |
13965 | | |
13966 | | // JIT: value_type = Z_TYPE_INFO_P(value); |
13967 | | // JIT: if (EXPECTED(value_type != IS_UNDEF)) { |
13968 | 0 | if (!exit_addr || exit_opcode == ZEND_JMP) { |
13969 | 0 | if_def_packed = ir_IF(jit_Z_TYPE_ref(jit, packed_p_ref)); |
13970 | 0 | ir_IF_FALSE(if_def_packed); |
13971 | 0 | } else { |
13972 | 0 | ir_GUARD_NOT(jit_Z_TYPE_ref(jit, packed_p_ref), ir_CONST_ADDR(exit_addr)); |
13973 | 0 | } |
13974 | | |
13975 | | // JIT: p++; |
13976 | 0 | p2_ref = ir_ADD_OFFSET(packed_p_ref, sizeof(zval)); |
13977 | |
|
13978 | 0 | ir_MERGE_SET_OP(loop_ref, 2, ir_LOOP_END()); |
13979 | 0 | ir_PHI_SET_OP(packed_pos_ref, 2, pos2_ref); |
13980 | 0 | ir_PHI_SET_OP(packed_p_ref, 2, p2_ref); |
13981 | 0 | } |
13982 | |
|
13983 | 0 | if (!exit_addr || exit_opcode == ZEND_JMP) { |
13984 | 0 | zend_jit_addr val_addr; |
13985 | 0 | zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op2.var); |
13986 | 0 | uint32_t val_info; |
13987 | 0 | ir_ref p_ref = IR_UNUSED, hash_path = IR_UNUSED; |
13988 | |
|
13989 | 0 | if (RETURN_VALUE_USED(opline)) { |
13990 | 0 | zend_jit_addr res_addr = RES_ADDR(); |
13991 | |
|
13992 | 0 | if (MAY_BE_HASH(op1_info)) { |
13993 | 0 | ir_ref key_ref = IR_UNUSED, if_key = IR_UNUSED, key_path = IR_UNUSED; |
13994 | |
|
13995 | 0 | ZEND_ASSERT(if_def_hash); |
13996 | 0 | ir_IF_TRUE(if_def_hash); |
13997 | | |
13998 | | // JIT: Z_FE_POS_P(array) = pos + 1; |
13999 | 0 | ir_STORE(ir_ADD_OFFSET(jit_FP(jit), opline->op1.var + offsetof(zval, u2.fe_pos)), |
14000 | 0 | ir_ADD_U32(hash_pos_ref, ir_CONST_U32(1))); |
14001 | |
|
14002 | 0 | if (op1_info & MAY_BE_ARRAY_KEY_STRING) { |
14003 | 0 | key_ref = ir_LOAD_A(ir_ADD_OFFSET(hash_p_ref, offsetof(Bucket, key))); |
14004 | 0 | } |
14005 | 0 | if ((op1_info & MAY_BE_ARRAY_KEY_LONG) |
14006 | 0 | && (op1_info & MAY_BE_ARRAY_KEY_STRING)) { |
14007 | | // JIT: if (!p->key) { |
14008 | 0 | if_key = ir_IF(key_ref); |
14009 | 0 | ir_IF_TRUE(if_key); |
14010 | 0 | } |
14011 | 0 | if (op1_info & MAY_BE_ARRAY_KEY_STRING) { |
14012 | 0 | ir_ref if_interned, interned_path; |
14013 | | |
14014 | | // JIT: ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); |
14015 | 0 | jit_set_Z_PTR(jit, res_addr, key_ref); |
14016 | 0 | ref = ir_AND_U32( |
14017 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(key_ref, offsetof(zend_refcounted, gc.u.type_info))), |
14018 | 0 | ir_CONST_U32(IS_STR_INTERNED)); |
14019 | 0 | if_interned = ir_IF(ref); |
14020 | 0 | ir_IF_TRUE(if_interned); |
14021 | |
|
14022 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_STRING); |
14023 | |
|
14024 | 0 | interned_path = ir_END(); |
14025 | 0 | ir_IF_FALSE(if_interned); |
14026 | |
|
14027 | 0 | jit_GC_ADDREF(jit, key_ref); |
14028 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_STRING_EX); |
14029 | |
|
14030 | 0 | ir_MERGE_WITH(interned_path); |
14031 | |
|
14032 | 0 | if (op1_info & MAY_BE_ARRAY_KEY_LONG) { |
14033 | 0 | key_path = ir_END(); |
14034 | 0 | } |
14035 | 0 | } |
14036 | 0 | if (op1_info & MAY_BE_ARRAY_KEY_LONG) { |
14037 | 0 | if (op1_info & MAY_BE_ARRAY_KEY_STRING) { |
14038 | 0 | ir_IF_FALSE(if_key); |
14039 | 0 | } |
14040 | | // JIT: ZVAL_LONG(EX_VAR(opline->result.var), p->h); |
14041 | 0 | ref = ir_LOAD_L(ir_ADD_OFFSET(hash_p_ref, offsetof(Bucket, h))); |
14042 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
14043 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
14044 | |
|
14045 | 0 | if (op1_info & MAY_BE_ARRAY_KEY_STRING) { |
14046 | 0 | ir_MERGE_WITH(key_path); |
14047 | 0 | } |
14048 | 0 | } |
14049 | 0 | if (MAY_BE_PACKED(op1_info)) { |
14050 | 0 | hash_path = ir_END(); |
14051 | 0 | } else { |
14052 | 0 | p_ref = hash_p_ref; |
14053 | 0 | } |
14054 | 0 | } |
14055 | 0 | if (MAY_BE_PACKED(op1_info)) { |
14056 | 0 | ZEND_ASSERT(if_def_packed); |
14057 | 0 | ir_IF_TRUE(if_def_packed); |
14058 | | |
14059 | | // JIT: Z_FE_POS_P(array) = pos + 1; |
14060 | 0 | ir_STORE(ir_ADD_OFFSET(jit_FP(jit), opline->op1.var + offsetof(zval, u2.fe_pos)), |
14061 | 0 | ir_ADD_U32(packed_pos_ref, ir_CONST_U32(1))); |
14062 | | |
14063 | | // JIT: ZVAL_LONG(EX_VAR(opline->result.var), pos); |
14064 | 0 | if (sizeof(zend_long) == 8) { |
14065 | 0 | packed_pos_ref = ir_ZEXT_L(packed_pos_ref); |
14066 | 0 | } else { |
14067 | 0 | packed_pos_ref = ir_BITCAST_L(packed_pos_ref); |
14068 | 0 | } |
14069 | 0 | jit_set_Z_LVAL(jit, res_addr, packed_pos_ref); |
14070 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
14071 | |
|
14072 | 0 | if (MAY_BE_HASH(op1_info)) { |
14073 | 0 | ir_MERGE_WITH(hash_path); |
14074 | 0 | p_ref = ir_PHI_2(IR_ADDR, packed_p_ref, hash_p_ref); |
14075 | 0 | } else { |
14076 | 0 | p_ref = packed_p_ref; |
14077 | 0 | } |
14078 | 0 | } |
14079 | 0 | } else { |
14080 | 0 | ir_ref pos_ref = IR_UNUSED; |
14081 | |
|
14082 | 0 | if (if_def_hash && if_def_packed) { |
14083 | 0 | ir_IF_TRUE(if_def_hash); |
14084 | 0 | ir_MERGE_WITH_EMPTY_TRUE(if_def_packed); |
14085 | 0 | pos_ref = ir_PHI_2(IR_U32, hash_pos_ref, packed_pos_ref); |
14086 | 0 | p_ref = ir_PHI_2(IR_ADDR, hash_p_ref, packed_p_ref); |
14087 | 0 | } else if (if_def_hash) { |
14088 | 0 | ir_IF_TRUE(if_def_hash); |
14089 | 0 | pos_ref = hash_pos_ref; |
14090 | 0 | p_ref = hash_p_ref; |
14091 | 0 | } else if (if_def_packed) { |
14092 | 0 | ir_IF_TRUE(if_def_packed); |
14093 | 0 | pos_ref = packed_pos_ref; |
14094 | 0 | p_ref = packed_p_ref; |
14095 | 0 | } else { |
14096 | 0 | ZEND_UNREACHABLE(); |
14097 | 0 | } |
14098 | | |
14099 | | // JIT: Z_FE_POS_P(array) = pos + 1; |
14100 | 0 | ir_STORE(ir_ADD_OFFSET(jit_FP(jit), opline->op1.var + offsetof(zval, u2.fe_pos)), |
14101 | 0 | ir_ADD_U32(pos_ref, ir_CONST_U32(1))); |
14102 | 0 | } |
14103 | | |
14104 | 0 | val_info = ((op1_info & MAY_BE_ARRAY_OF_ANY) >> MAY_BE_ARRAY_SHIFT); |
14105 | 0 | if (val_info & MAY_BE_ARRAY) { |
14106 | 0 | val_info |= MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF; |
14107 | 0 | } |
14108 | 0 | if (op1_info & MAY_BE_ARRAY_OF_REF) { |
14109 | 0 | val_info |= MAY_BE_REF | MAY_BE_RC1 | MAY_BE_RCN | MAY_BE_ANY | |
14110 | 0 | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF; |
14111 | 0 | } else if (val_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
14112 | 0 | val_info |= MAY_BE_RC1 | MAY_BE_RCN; |
14113 | 0 | } |
14114 | |
|
14115 | 0 | val_addr = ZEND_ADDR_REF_ZVAL(p_ref); |
14116 | 0 | if (opline->op2_type == IS_CV) { |
14117 | | // JIT: zend_assign_to_variable(variable_ptr, value, IS_CV, EX_USES_STRICT_TYPES()); |
14118 | 0 | if (!zend_jit_assign_to_variable(jit, opline, var_addr, var_addr, op2_info, -1, IS_CV, val_addr, val_info, 0, 0, true)) { |
14119 | 0 | return 0; |
14120 | 0 | } |
14121 | 0 | } else { |
14122 | | // JIT: ZVAL_DEREF(value); |
14123 | 0 | if (val_info & MAY_BE_REF) { |
14124 | 0 | ir_ref ref = jit_ZVAL_ADDR(jit, val_addr); |
14125 | 0 | ref = jit_ZVAL_DEREF_ref(jit, ref); |
14126 | 0 | val_addr = ZEND_ADDR_REF_ZVAL(ref); |
14127 | 0 | val_info &= ~MAY_BE_REF; |
14128 | 0 | } |
14129 | | // JIT: ZVAL_COPY(res, value); |
14130 | 0 | jit_ZVAL_COPY(jit, var_addr, -1, val_addr, val_info, true); |
14131 | 0 | } |
14132 | | |
14133 | 0 | if (!exit_addr) { |
14134 | 0 | zend_basic_block *bb; |
14135 | |
|
14136 | 0 | ZEND_ASSERT(jit->b >= 0); |
14137 | 0 | bb = &jit->ssa->cfg.blocks[jit->b]; |
14138 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[1], jit->b, ir_END()); |
14139 | 0 | ZEND_ASSERT(exit_inputs); |
14140 | 0 | if (!jit->ctx.ir_base[exit_inputs].op2) { |
14141 | 0 | ref = exit_inputs; |
14142 | 0 | } else { |
14143 | 0 | ir_MERGE_list(exit_inputs); |
14144 | 0 | ref = ir_END(); |
14145 | 0 | } |
14146 | 0 | _zend_jit_add_predecessor_ref(jit, bb->successors[0], jit->b, ref); |
14147 | 0 | jit->b = -1; |
14148 | 0 | } |
14149 | 0 | } else { |
14150 | 0 | ZEND_ASSERT(exit_inputs); |
14151 | 0 | ir_MERGE_list(exit_inputs); |
14152 | 0 | } |
14153 | | |
14154 | 0 | return 1; |
14155 | 0 | } |
14156 | | |
14157 | | static int zend_jit_load_this(zend_jit_ctx *jit, uint32_t var) |
14158 | 0 | { |
14159 | 0 | zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This)); |
14160 | 0 | zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var); |
14161 | 0 | ir_ref ref = jit_Z_PTR(jit, this_addr); |
14162 | |
|
14163 | 0 | jit_set_Z_PTR(jit, var_addr, ref); |
14164 | 0 | jit_set_Z_TYPE_INFO(jit, var_addr, IS_OBJECT_EX); |
14165 | 0 | jit_GC_ADDREF(jit, ref); |
14166 | |
|
14167 | 0 | return 1; |
14168 | 0 | } |
14169 | | |
14170 | | static int zend_jit_fetch_this(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, bool check_only) |
14171 | 0 | { |
14172 | 0 | if (!op_array->scope || |
14173 | 0 | (op_array->fn_flags & ZEND_ACC_STATIC) || |
14174 | 0 | ((op_array->fn_flags & (ZEND_ACC_CLOSURE|ZEND_ACC_IMMUTABLE)) == ZEND_ACC_CLOSURE)) { |
14175 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
14176 | 0 | if (!JIT_G(current_frame) || |
14177 | 0 | !TRACE_FRAME_IS_THIS_CHECKED(JIT_G(current_frame))) { |
14178 | |
|
14179 | 0 | zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This)); |
14180 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
14181 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
14182 | |
|
14183 | 0 | if (!exit_addr) { |
14184 | 0 | return 0; |
14185 | 0 | } |
14186 | | |
14187 | 0 | jit_guard_Z_TYPE(jit, this_addr, IS_OBJECT, exit_addr); |
14188 | |
|
14189 | 0 | if (JIT_G(current_frame)) { |
14190 | 0 | TRACE_FRAME_SET_THIS_CHECKED(JIT_G(current_frame)); |
14191 | 0 | } |
14192 | 0 | } |
14193 | 0 | } else { |
14194 | 0 | zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This)); |
14195 | 0 | ir_ref if_object = jit_if_Z_TYPE(jit, this_addr, IS_OBJECT); |
14196 | |
|
14197 | 0 | ir_IF_FALSE_cold(if_object); |
14198 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14199 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_invalid_this)); |
14200 | |
|
14201 | 0 | ir_IF_TRUE(if_object); |
14202 | 0 | } |
14203 | 0 | } |
14204 | | |
14205 | 0 | if (!check_only) { |
14206 | 0 | if (!zend_jit_load_this(jit, opline->result.var)) { |
14207 | 0 | return 0; |
14208 | 0 | } |
14209 | 0 | } |
14210 | | |
14211 | 0 | return 1; |
14212 | 0 | } |
14213 | | |
14214 | | static int zend_jit_class_guard(zend_jit_ctx *jit, const zend_op *opline, ir_ref obj_ref, zend_class_entry *ce) |
14215 | 0 | { |
14216 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
14217 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
14218 | |
|
14219 | 0 | if (!exit_addr) { |
14220 | 0 | return 0; |
14221 | 0 | } |
14222 | | |
14223 | 0 | ir_GUARD(ir_EQ(ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_object, ce))), ir_CONST_ADDR(ce)), |
14224 | 0 | ir_CONST_ADDR(exit_addr)); |
14225 | |
|
14226 | 0 | return 1; |
14227 | 0 | } |
14228 | | |
14229 | | static int zend_jit_fetch_obj(zend_jit_ctx *jit, |
14230 | | const zend_op *opline, |
14231 | | const zend_op_array *op_array, |
14232 | | zend_ssa *ssa, |
14233 | | const zend_ssa_op *ssa_op, |
14234 | | uint32_t op1_info, |
14235 | | zend_jit_addr op1_addr, |
14236 | | bool op1_indirect, |
14237 | | zend_class_entry *ce, |
14238 | | bool ce_is_instanceof, |
14239 | | bool on_this, |
14240 | | bool delayed_fetch_this, |
14241 | | bool op1_avoid_refcounting, |
14242 | | zend_class_entry *trace_ce, |
14243 | | zend_jit_addr res_addr, |
14244 | | uint8_t prop_type, |
14245 | | int may_throw) |
14246 | 0 | { |
14247 | 0 | zval *member; |
14248 | 0 | zend_property_info *prop_info; |
14249 | 0 | bool may_be_dynamic = true; |
14250 | 0 | zend_jit_addr prop_addr; |
14251 | 0 | uint32_t res_info = RES_INFO(); |
14252 | 0 | ir_ref prop_type_ref = IR_UNUSED; |
14253 | 0 | ir_ref obj_ref = IR_UNUSED; |
14254 | 0 | ir_ref prop_ref = IR_UNUSED; |
14255 | 0 | ir_ref end_inputs = IR_UNUSED; |
14256 | 0 | ir_ref slow_inputs = IR_UNUSED; |
14257 | 0 | ir_ref end_values = IR_UNUSED; |
14258 | |
|
14259 | 0 | ZEND_ASSERT(opline->op2_type == IS_CONST); |
14260 | 0 | ZEND_ASSERT(op1_info & MAY_BE_OBJECT); |
14261 | |
|
14262 | 0 | member = RT_CONSTANT(opline, opline->op2); |
14263 | 0 | ZEND_ASSERT(Z_TYPE_P(member) == IS_STRING && Z_STRVAL_P(member)[0] != '\0'); |
14264 | 0 | prop_info = zend_get_known_property_info(op_array, ce, Z_STR_P(member), on_this, op_array->filename); |
14265 | |
|
14266 | 0 | if (on_this) { |
14267 | 0 | zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This)); |
14268 | 0 | obj_ref = jit_Z_PTR(jit, this_addr); |
14269 | 0 | } else { |
14270 | 0 | if (opline->op1_type == IS_VAR |
14271 | 0 | && opline->opcode == ZEND_FETCH_OBJ_W |
14272 | 0 | && (op1_info & MAY_BE_INDIRECT) |
14273 | 0 | && Z_REG(op1_addr) == ZREG_FP) { |
14274 | 0 | op1_addr = jit_ZVAL_INDIRECT_DEREF(jit, op1_addr); |
14275 | 0 | } |
14276 | 0 | if (op1_info & MAY_BE_REF) { |
14277 | 0 | op1_addr = jit_ZVAL_DEREF(jit, op1_addr); |
14278 | 0 | } |
14279 | 0 | if (op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY)- MAY_BE_OBJECT)) { |
14280 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
14281 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
14282 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
14283 | |
|
14284 | 0 | if (!exit_addr) { |
14285 | 0 | return 0; |
14286 | 0 | } |
14287 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_OBJECT, exit_addr); |
14288 | 0 | } else { |
14289 | 0 | ir_ref if_obj = jit_if_Z_TYPE(jit, op1_addr, IS_OBJECT); |
14290 | |
|
14291 | 0 | ir_IF_FALSE_cold(if_obj); |
14292 | 0 | if (opline->opcode != ZEND_FETCH_OBJ_IS) { |
14293 | 0 | ir_ref op1_ref = IR_UNUSED; |
14294 | |
|
14295 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14296 | 0 | if (opline->opcode != ZEND_FETCH_OBJ_W && (op1_info & MAY_BE_UNDEF)) { |
14297 | 0 | zend_jit_addr orig_op1_addr = OP1_ADDR(); |
14298 | 0 | ir_ref fast_path = IR_UNUSED; |
14299 | |
|
14300 | 0 | if (op1_info & MAY_BE_ANY) { |
14301 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE(jit, op1_addr)); |
14302 | 0 | ir_IF_TRUE(if_def); |
14303 | 0 | fast_path = ir_END(); |
14304 | 0 | ir_IF_FALSE_cold(if_def); |
14305 | 0 | } |
14306 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), |
14307 | 0 | ir_CONST_U32(opline->op1.var)); |
14308 | 0 | if (fast_path) { |
14309 | 0 | ir_MERGE_WITH(fast_path); |
14310 | 0 | } |
14311 | 0 | op1_ref = jit_ZVAL_ADDR(jit, orig_op1_addr); |
14312 | 0 | } else { |
14313 | 0 | op1_ref = jit_ZVAL_ADDR(jit, op1_addr); |
14314 | 0 | } |
14315 | 0 | if (opline->opcode == ZEND_FETCH_OBJ_W) { |
14316 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_invalid_property_write), |
14317 | 0 | op1_ref, ir_CONST_ADDR(Z_STRVAL_P(member))); |
14318 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, _IS_ERROR); |
14319 | 0 | } else { |
14320 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_invalid_property_read), |
14321 | 0 | op1_ref, ir_CONST_ADDR(Z_STRVAL_P(member))); |
14322 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
14323 | 0 | } |
14324 | 0 | } else { |
14325 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
14326 | 0 | } |
14327 | 0 | ir_END_list(end_inputs); |
14328 | |
|
14329 | 0 | ir_IF_TRUE(if_obj); |
14330 | 0 | } |
14331 | 0 | } |
14332 | 0 | obj_ref = jit_Z_PTR(jit, op1_addr); |
14333 | 0 | } |
14334 | | |
14335 | 0 | ZEND_ASSERT(obj_ref); |
14336 | 0 | if (!prop_info && trace_ce && (trace_ce->ce_flags & ZEND_ACC_IMMUTABLE)) { |
14337 | 0 | prop_info = zend_get_known_property_info(op_array, trace_ce, Z_STR_P(member), on_this, op_array->filename); |
14338 | 0 | if (prop_info) { |
14339 | 0 | ce = trace_ce; |
14340 | 0 | ce_is_instanceof = false; |
14341 | 0 | if (!(op1_info & MAY_BE_CLASS_GUARD)) { |
14342 | 0 | if (on_this && JIT_G(current_frame) |
14343 | 0 | && TRACE_FRAME_IS_THIS_CLASS_CHECKED(JIT_G(current_frame))) { |
14344 | 0 | ZEND_ASSERT(JIT_G(current_frame)->ce == ce); |
14345 | 0 | } else if (zend_jit_class_guard(jit, opline, obj_ref, ce)) { |
14346 | 0 | if (on_this && JIT_G(current_frame)) { |
14347 | 0 | JIT_G(current_frame)->ce = ce; |
14348 | 0 | TRACE_FRAME_SET_THIS_CLASS_CHECKED(JIT_G(current_frame)); |
14349 | 0 | } |
14350 | 0 | } else { |
14351 | 0 | return 0; |
14352 | 0 | } |
14353 | 0 | if (ssa->var_info && ssa_op->op1_use >= 0) { |
14354 | 0 | ssa->var_info[ssa_op->op1_use].type |= MAY_BE_CLASS_GUARD; |
14355 | 0 | ssa->var_info[ssa_op->op1_use].ce = ce; |
14356 | 0 | ssa->var_info[ssa_op->op1_use].is_instanceof = ce_is_instanceof; |
14357 | 0 | } |
14358 | 0 | } |
14359 | 0 | } |
14360 | 0 | } |
14361 | | |
14362 | 0 | if (!prop_info) { |
14363 | 0 | ir_ref run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
14364 | 0 | ir_ref ref = ir_LOAD_A(ir_ADD_OFFSET(run_time_cache, opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS)); |
14365 | 0 | ir_ref if_same = ir_IF(ir_EQ(ref, |
14366 | 0 | ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_object, ce))))); |
14367 | |
|
14368 | 0 | ir_IF_FALSE_cold(if_same); |
14369 | 0 | ir_END_list(slow_inputs); |
14370 | |
|
14371 | 0 | ir_IF_TRUE(if_same); |
14372 | 0 | ir_ref offset_ref = ir_LOAD_A( |
14373 | 0 | ir_ADD_OFFSET(run_time_cache, (opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*))); |
14374 | |
|
14375 | 0 | may_be_dynamic = zend_may_be_dynamic_property(ce, Z_STR_P(member), opline->op1_type == IS_UNUSED, op_array); |
14376 | 0 | if (may_be_dynamic) { |
14377 | 0 | ir_ref if_dynamic = ir_IF(ir_LT(offset_ref, ir_CONST_ADDR(ZEND_FIRST_PROPERTY_OFFSET))); |
14378 | 0 | if (opline->opcode == ZEND_FETCH_OBJ_W) { |
14379 | 0 | ir_IF_TRUE_cold(if_dynamic); |
14380 | 0 | ir_END_list(slow_inputs); |
14381 | 0 | } else { |
14382 | 0 | ir_IF_TRUE_cold(if_dynamic); |
14383 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14384 | |
|
14385 | 0 | if (opline->opcode != ZEND_FETCH_OBJ_IS) { |
14386 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
14387 | 0 | ir_ref val_addr = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_fetch_obj_r_dynamic_ex), |
14388 | 0 | obj_ref, offset_ref); |
14389 | 0 | ir_END_PHI_list(end_values, val_addr); |
14390 | 0 | } else { |
14391 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_obj_r_dynamic), |
14392 | 0 | obj_ref, offset_ref); |
14393 | 0 | ir_END_list(end_inputs); |
14394 | 0 | } |
14395 | 0 | } else { |
14396 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
14397 | 0 | ir_ref val_addr = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_fetch_obj_is_dynamic_ex), |
14398 | 0 | obj_ref, offset_ref); |
14399 | 0 | ir_END_PHI_list(end_values, val_addr); |
14400 | 0 | } else { |
14401 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_obj_is_dynamic), |
14402 | 0 | obj_ref, offset_ref); |
14403 | 0 | ir_END_list(end_inputs); |
14404 | 0 | } |
14405 | 0 | } |
14406 | 0 | } |
14407 | 0 | ir_IF_FALSE(if_dynamic); |
14408 | 0 | } |
14409 | 0 | prop_ref = ir_ADD_A(obj_ref, offset_ref); |
14410 | 0 | prop_type_ref = jit_Z_TYPE_ref(jit, prop_ref); |
14411 | 0 | ir_ref if_def = ir_IF(prop_type_ref); |
14412 | 0 | ir_IF_FALSE_cold(if_def); |
14413 | 0 | ir_END_list(slow_inputs); |
14414 | 0 | ir_IF_TRUE(if_def); |
14415 | 0 | prop_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
14416 | 0 | if (opline->opcode == ZEND_FETCH_OBJ_W |
14417 | 0 | && (!ce || ce_is_instanceof || (ce->ce_flags & (ZEND_ACC_HAS_TYPE_HINTS|ZEND_ACC_TRAIT)))) { |
14418 | 0 | uint32_t flags = opline->extended_value & ZEND_FETCH_OBJ_FLAGS; |
14419 | |
|
14420 | 0 | ir_ref allowed_inputs = IR_UNUSED; |
14421 | 0 | ir_ref forbidden_inputs = IR_UNUSED; |
14422 | |
|
14423 | 0 | ir_ref prop_info_ref = ir_LOAD_A( |
14424 | 0 | ir_ADD_OFFSET(run_time_cache, (opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*) * 2)); |
14425 | 0 | ir_ref if_has_prop_info = ir_IF(prop_info_ref); |
14426 | |
|
14427 | 0 | ir_IF_TRUE_cold(if_has_prop_info); |
14428 | |
|
14429 | 0 | ir_ref prop_flags = ir_LOAD_U32(ir_ADD_OFFSET(prop_info_ref, offsetof(zend_property_info, flags))); |
14430 | 0 | ir_ref if_readonly_or_avis = ir_IF(ir_AND_U32(prop_flags, ir_CONST_U32(ZEND_ACC_READONLY|ZEND_ACC_PPP_SET_MASK))); |
14431 | |
|
14432 | 0 | ir_IF_FALSE(if_readonly_or_avis); |
14433 | 0 | ir_END_list(allowed_inputs); |
14434 | |
|
14435 | 0 | ir_IF_TRUE_cold(if_readonly_or_avis); |
14436 | |
|
14437 | 0 | ir_ref if_readonly = ir_IF(ir_AND_U32(prop_flags, ir_CONST_U32(ZEND_ACC_READONLY))); |
14438 | 0 | ir_IF_TRUE(if_readonly); |
14439 | 0 | ir_END_list(forbidden_inputs); |
14440 | |
|
14441 | 0 | ir_IF_FALSE(if_readonly); |
14442 | 0 | ir_ref has_avis_access = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_asymmetric_property_has_set_access), prop_info_ref); |
14443 | 0 | ir_ref if_avis_access = ir_IF(has_avis_access); |
14444 | 0 | ir_IF_TRUE(if_avis_access); |
14445 | 0 | ir_END_list(allowed_inputs); |
14446 | |
|
14447 | 0 | ir_IF_FALSE(if_avis_access); |
14448 | 0 | ir_END_list(forbidden_inputs); |
14449 | |
|
14450 | 0 | ir_MERGE_list(forbidden_inputs); |
14451 | |
|
14452 | 0 | ir_ref if_prop_obj = jit_if_Z_TYPE(jit, prop_addr, IS_OBJECT); |
14453 | 0 | ir_IF_TRUE(if_prop_obj); |
14454 | 0 | ref = jit_Z_PTR(jit, prop_addr); |
14455 | 0 | jit_GC_ADDREF(jit, ref); |
14456 | 0 | jit_set_Z_PTR(jit, res_addr, ref); |
14457 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_OBJECT_EX); |
14458 | 0 | ir_END_list(end_inputs); |
14459 | |
|
14460 | 0 | ir_IF_FALSE_cold(if_prop_obj); |
14461 | |
|
14462 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14463 | 0 | if_readonly = ir_IF(ir_AND_U32(prop_flags, ir_CONST_U32(ZEND_ACC_READONLY))); |
14464 | 0 | ir_IF_TRUE(if_readonly); |
14465 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_readonly_property_indirect_modification_error), prop_info_ref); |
14466 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, _IS_ERROR); |
14467 | 0 | ir_END_list(end_inputs); |
14468 | |
|
14469 | 0 | ir_IF_FALSE(if_readonly); |
14470 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_asymmetric_visibility_property_modification_error), |
14471 | 0 | prop_info_ref, ir_CONST_ADDR("indirectly modify")); |
14472 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, _IS_ERROR); |
14473 | 0 | ir_END_list(end_inputs); |
14474 | |
|
14475 | 0 | ir_MERGE_list(allowed_inputs); |
14476 | |
|
14477 | 0 | if (flags == ZEND_FETCH_DIM_WRITE) { |
14478 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14479 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_check_array_promotion), |
14480 | 0 | prop_ref, prop_info_ref); |
14481 | 0 | ir_END_list(end_inputs); |
14482 | 0 | ir_IF_FALSE(if_has_prop_info); |
14483 | 0 | } else if (flags == ZEND_FETCH_REF) { |
14484 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_create_typed_ref), |
14485 | 0 | prop_ref, |
14486 | 0 | prop_info_ref, |
14487 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
14488 | 0 | ir_END_list(end_inputs); |
14489 | 0 | ir_IF_FALSE(if_has_prop_info); |
14490 | 0 | } else { |
14491 | 0 | ZEND_ASSERT(flags == 0); |
14492 | 0 | ir_MERGE_WITH_EMPTY_FALSE(if_has_prop_info); |
14493 | 0 | } |
14494 | 0 | } |
14495 | 0 | } else { |
14496 | 0 | prop_ref = ir_ADD_OFFSET(obj_ref, prop_info->offset); |
14497 | 0 | prop_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
14498 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
14499 | 0 | if (opline->opcode == ZEND_FETCH_OBJ_W || !(res_info & MAY_BE_GUARD) || !JIT_G(current_frame)) { |
14500 | | /* perform IS_UNDEF check only after result type guard (during deoptimization) */ |
14501 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
14502 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
14503 | |
|
14504 | 0 | if (!exit_addr) { |
14505 | 0 | return 0; |
14506 | 0 | } |
14507 | 0 | prop_type_ref = jit_Z_TYPE_INFO(jit, prop_addr); |
14508 | 0 | ir_GUARD(prop_type_ref, ir_CONST_ADDR(exit_addr)); |
14509 | 0 | } |
14510 | 0 | } else { |
14511 | 0 | prop_type_ref = jit_Z_TYPE_INFO(jit, prop_addr); |
14512 | 0 | ir_ref if_def = ir_IF(prop_type_ref); |
14513 | 0 | ir_IF_FALSE_cold(if_def); |
14514 | 0 | ir_END_list(slow_inputs); |
14515 | 0 | ir_IF_TRUE(if_def); |
14516 | 0 | } |
14517 | 0 | if (opline->opcode == ZEND_FETCH_OBJ_W && (prop_info->flags & ZEND_ACC_READONLY)) { |
14518 | 0 | ir_ref if_prop_obj = jit_if_Z_TYPE(jit, prop_addr, IS_OBJECT); |
14519 | 0 | ir_IF_TRUE(if_prop_obj); |
14520 | 0 | ir_ref ref = jit_Z_PTR(jit, prop_addr); |
14521 | 0 | jit_GC_ADDREF(jit, ref); |
14522 | 0 | jit_set_Z_PTR(jit, res_addr, ref); |
14523 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_OBJECT_EX); |
14524 | 0 | ir_END_list(end_inputs); |
14525 | |
|
14526 | 0 | ir_IF_FALSE_cold(if_prop_obj); |
14527 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14528 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_readonly_property_indirect_modification_error), ir_CONST_ADDR(prop_info)); |
14529 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, _IS_ERROR); |
14530 | 0 | ir_END_list(end_inputs); |
14531 | |
|
14532 | 0 | goto result_fetched; |
14533 | 0 | } else if (opline->opcode == ZEND_FETCH_OBJ_W && (prop_info->flags & ZEND_ACC_PPP_SET_MASK)) { |
14534 | | /* Readonly properties which are also asymmetric are never mutable indirectly, which is |
14535 | | * handled by the previous branch. */ |
14536 | 0 | ir_ref has_access = ir_CALL_1(IR_BOOL, ir_CONST_FC_FUNC(zend_asymmetric_property_has_set_access), ir_CONST_ADDR(prop_info)); |
14537 | |
|
14538 | 0 | ir_ref if_access = ir_IF(has_access); |
14539 | 0 | ir_IF_FALSE_cold(if_access); |
14540 | |
|
14541 | 0 | ir_ref if_prop_obj = jit_if_Z_TYPE(jit, prop_addr, IS_OBJECT); |
14542 | 0 | ir_IF_TRUE(if_prop_obj); |
14543 | 0 | ir_ref ref = jit_Z_PTR(jit, prop_addr); |
14544 | 0 | jit_GC_ADDREF(jit, ref); |
14545 | 0 | jit_set_Z_PTR(jit, res_addr, ref); |
14546 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_OBJECT_EX); |
14547 | 0 | ir_END_list(end_inputs); |
14548 | |
|
14549 | 0 | ir_IF_FALSE_cold(if_prop_obj); |
14550 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_asymmetric_visibility_property_modification_error), |
14551 | 0 | ir_CONST_ADDR(prop_info), ir_CONST_ADDR("indirectly modify")); |
14552 | 0 | ir_END_list(end_inputs); |
14553 | |
|
14554 | 0 | ir_IF_TRUE(if_access); |
14555 | 0 | } |
14556 | | |
14557 | 0 | if (opline->opcode == ZEND_FETCH_OBJ_W |
14558 | 0 | && (opline->extended_value & ZEND_FETCH_OBJ_FLAGS) |
14559 | 0 | && ZEND_TYPE_IS_SET(prop_info->type)) { |
14560 | 0 | uint32_t flags = opline->extended_value & ZEND_FETCH_OBJ_FLAGS; |
14561 | |
|
14562 | 0 | if (flags == ZEND_FETCH_DIM_WRITE) { |
14563 | 0 | if ((ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_ARRAY) == 0) { |
14564 | 0 | if (!prop_type_ref) { |
14565 | 0 | prop_type_ref = jit_Z_TYPE_INFO(jit, prop_addr); |
14566 | 0 | } |
14567 | 0 | ir_ref if_null_or_flase = ir_IF(ir_LE(prop_type_ref, ir_CONST_U32(IR_FALSE))); |
14568 | 0 | ir_IF_TRUE_cold(if_null_or_flase); |
14569 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14570 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_check_array_promotion), |
14571 | 0 | prop_ref, ir_CONST_ADDR(prop_info)); |
14572 | 0 | ir_END_list(end_inputs); |
14573 | 0 | ir_IF_FALSE(if_null_or_flase); |
14574 | 0 | } |
14575 | 0 | } else if (flags == ZEND_FETCH_REF) { |
14576 | 0 | ir_ref ref; |
14577 | |
|
14578 | 0 | if (!prop_type_ref) { |
14579 | 0 | prop_type_ref = jit_Z_TYPE_INFO(jit, prop_addr); |
14580 | 0 | } |
14581 | |
|
14582 | 0 | ir_ref if_reference = ir_IF(ir_EQ(prop_type_ref, ir_CONST_U32(IS_REFERENCE_EX))); |
14583 | 0 | ir_IF_FALSE(if_reference); |
14584 | 0 | if (ce && ce->ce_flags & ZEND_ACC_IMMUTABLE) { |
14585 | 0 | ref = ir_CONST_ADDR(prop_info); |
14586 | 0 | } else { |
14587 | 0 | int prop_info_offset = |
14588 | 0 | (((prop_info->offset - (sizeof(zend_object) - sizeof(zval))) / sizeof(zval)) * sizeof(void*)); |
14589 | |
|
14590 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_object, ce))); |
14591 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ref, offsetof(zend_class_entry, properties_info_table))); |
14592 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ref, prop_info_offset)); |
14593 | 0 | } |
14594 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_create_typed_ref), |
14595 | 0 | prop_ref, |
14596 | 0 | ref, |
14597 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
14598 | 0 | ir_END_list(end_inputs); |
14599 | 0 | ir_IF_TRUE(if_reference); |
14600 | 0 | } else { |
14601 | 0 | ZEND_UNREACHABLE(); |
14602 | 0 | } |
14603 | 0 | } |
14604 | 0 | } |
14605 | | |
14606 | 0 | if (opline->opcode == ZEND_FETCH_OBJ_W) { |
14607 | 0 | ZEND_ASSERT(prop_ref); |
14608 | 0 | jit_set_Z_PTR(jit, res_addr, prop_ref); |
14609 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_INDIRECT); |
14610 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && prop_info) { |
14611 | 0 | ssa->var_info[ssa_op->result_def].indirect_reference = 1; |
14612 | 0 | } |
14613 | 0 | ir_END_list(end_inputs); |
14614 | 0 | } else { |
14615 | 0 | if ((res_info & MAY_BE_GUARD) && JIT_G(current_frame) && prop_info) { |
14616 | 0 | ir_END_PHI_list(end_values, jit_ZVAL_ADDR(jit, prop_addr)); |
14617 | 0 | } else if ((res_info & MAY_BE_GUARD) && Z_MODE(res_addr) == IS_REG) { |
14618 | 0 | ir_END_PHI_list(end_values, jit_ZVAL_ADDR(jit, prop_addr)); |
14619 | 0 | } else if (Z_MODE(res_addr) == IS_REG) { |
14620 | 0 | prop_type_ref = jit_Z_TYPE_INFO(jit, prop_addr); |
14621 | |
|
14622 | 0 | if (!zend_jit_zval_copy_deref_reg(jit, res_addr, res_info & ~MAY_BE_GUARD, prop_addr, prop_type_ref, &end_values)) { |
14623 | 0 | return 0; |
14624 | 0 | } |
14625 | 0 | } else { |
14626 | 0 | prop_type_ref = jit_Z_TYPE_INFO(jit, prop_addr); |
14627 | |
|
14628 | 0 | if (!zend_jit_zval_copy_deref(jit, res_addr, prop_addr, prop_type_ref)) { |
14629 | 0 | return 0; |
14630 | 0 | } |
14631 | 0 | ir_END_list(end_inputs); |
14632 | 0 | } |
14633 | 0 | } |
14634 | | |
14635 | 0 | result_fetched: |
14636 | 0 | if (op1_avoid_refcounting) { |
14637 | 0 | SET_STACK_REG(JIT_G(current_frame)->stack, EX_VAR_TO_NUM(opline->op1.var), ZREG_NONE); |
14638 | 0 | } |
14639 | |
|
14640 | 0 | if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE || !prop_info) { |
14641 | 0 | ir_MERGE_list(slow_inputs); |
14642 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14643 | |
|
14644 | 0 | op1_info |= MAY_BE_RC1 | MAY_BE_RCN; /* object may be captured/released in magic handler */ |
14645 | 0 | if (opline->opcode == ZEND_FETCH_OBJ_W) { |
14646 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_obj_w_slow), obj_ref); |
14647 | 0 | ir_END_list(end_inputs); |
14648 | 0 | } else if (opline->opcode != ZEND_FETCH_OBJ_IS) { |
14649 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
14650 | 0 | ir_ref val_ref = ir_CALL_1(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_fetch_obj_r_slow_ex), obj_ref); |
14651 | 0 | ir_END_PHI_list(end_values, val_ref); |
14652 | 0 | } else { |
14653 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_obj_r_slow), obj_ref); |
14654 | 0 | ir_END_list(end_inputs); |
14655 | 0 | } |
14656 | 0 | } else { |
14657 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_fetch_obj_is_slow), obj_ref); |
14658 | 0 | ir_END_list(end_inputs); |
14659 | 0 | } |
14660 | 0 | } |
14661 | |
|
14662 | 0 | if (end_values) { |
14663 | 0 | ir_ref val_ref = ir_PHI_list(end_values); |
14664 | 0 | zend_jit_addr val_addr = ZEND_ADDR_REF_ZVAL(val_ref); |
14665 | 0 | bool result_avoid_refcounting = false; |
14666 | |
|
14667 | 0 | ZEND_ASSERT(opline->opcode == ZEND_FETCH_OBJ_R |
14668 | 0 | || opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG |
14669 | 0 | || opline->opcode == ZEND_FETCH_OBJ_IS); |
14670 | 0 | ZEND_ASSERT(end_inputs == IR_UNUSED); |
14671 | 0 | if ((res_info & MAY_BE_GUARD) && JIT_G(current_frame)) { |
14672 | 0 | uint8_t type = concrete_type(res_info); |
14673 | 0 | uint32_t flags = ZEND_JIT_EXIT_CHECK_EXCEPTION; |
14674 | |
|
14675 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) |
14676 | 0 | && !delayed_fetch_this |
14677 | 0 | && !op1_avoid_refcounting) { |
14678 | 0 | flags |= ZEND_JIT_EXIT_FREE_OP1; |
14679 | 0 | } |
14680 | |
|
14681 | 0 | if ((opline->result_type & (IS_VAR|IS_TMP_VAR)) |
14682 | 0 | && !(flags & ZEND_JIT_EXIT_FREE_OP1) |
14683 | 0 | && (res_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) |
14684 | 0 | && (ssa_op+1)->op1_use == ssa_op->result_def |
14685 | 0 | && zend_jit_may_avoid_refcounting(opline+1, res_info)) { |
14686 | 0 | result_avoid_refcounting = true; |
14687 | 0 | ssa->var_info[ssa_op->result_def].avoid_refcounting = 1; |
14688 | 0 | } |
14689 | |
|
14690 | 0 | val_addr = zend_jit_guard_fetch_result_type(jit, opline, val_addr, type, |
14691 | 0 | true, flags, op1_avoid_refcounting); |
14692 | 0 | if (!val_addr) { |
14693 | 0 | return 0; |
14694 | 0 | } |
14695 | | |
14696 | 0 | res_info &= ~MAY_BE_GUARD; |
14697 | 0 | ssa->var_info[ssa_op->result_def].type &= ~MAY_BE_GUARD; |
14698 | 0 | } |
14699 | | |
14700 | | // ZVAL_COPY |
14701 | 0 | jit_ZVAL_COPY(jit, res_addr, -1, val_addr, res_info, !result_avoid_refcounting); |
14702 | |
|
14703 | 0 | if (!zend_jit_store_var_if_necessary(jit, opline->result.var, res_addr, res_info)) { |
14704 | 0 | return 0; |
14705 | 0 | } |
14706 | 0 | } else { |
14707 | 0 | ir_MERGE_list(end_inputs); |
14708 | 0 | } |
14709 | | |
14710 | 0 | if (opline->op1_type != IS_UNUSED && !delayed_fetch_this && !op1_indirect) { |
14711 | 0 | if (opline->op1_type == IS_VAR |
14712 | 0 | && opline->opcode == ZEND_FETCH_OBJ_W |
14713 | 0 | && (op1_info & MAY_BE_RC1)) { |
14714 | 0 | zend_jit_addr orig_op1_addr = OP1_ADDR(); |
14715 | 0 | ir_ref if_refcounted, ptr, refcount, if_non_zero; |
14716 | 0 | ir_ref merge_inputs = IR_UNUSED; |
14717 | |
|
14718 | 0 | if_refcounted = jit_if_REFCOUNTED(jit, orig_op1_addr); |
14719 | 0 | ir_IF_FALSE( if_refcounted); |
14720 | 0 | ir_END_list(merge_inputs); |
14721 | 0 | ir_IF_TRUE( if_refcounted); |
14722 | 0 | ptr = jit_Z_PTR(jit, orig_op1_addr); |
14723 | 0 | refcount = jit_GC_DELREF(jit, ptr); |
14724 | 0 | if_non_zero = ir_IF(refcount); |
14725 | 0 | ir_IF_TRUE( if_non_zero); |
14726 | 0 | ir_END_list(merge_inputs); |
14727 | 0 | ir_IF_FALSE( if_non_zero); |
14728 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14729 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_extract_helper), ptr); |
14730 | 0 | ir_END_list(merge_inputs); |
14731 | 0 | ir_MERGE_list(merge_inputs); |
14732 | 0 | } else if (!op1_avoid_refcounting) { |
14733 | 0 | if (on_this) { |
14734 | 0 | op1_info &= ~MAY_BE_RC1; |
14735 | 0 | } |
14736 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
14737 | 0 | } |
14738 | 0 | } |
14739 | |
|
14740 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE |
14741 | 0 | && prop_info |
14742 | 0 | && (opline->opcode != ZEND_FETCH_OBJ_W || |
14743 | 0 | !(opline->extended_value & ZEND_FETCH_OBJ_FLAGS) || |
14744 | 0 | !ZEND_TYPE_IS_SET(prop_info->type)) |
14745 | 0 | && (!(opline->op1_type & (IS_VAR|IS_TMP_VAR)) || on_this || op1_indirect)) { |
14746 | 0 | may_throw = 0; |
14747 | 0 | } |
14748 | |
|
14749 | 0 | if (may_throw) { |
14750 | 0 | if (Z_MODE(res_addr) == IS_REG) { |
14751 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
14752 | 0 | } else { |
14753 | 0 | zend_jit_check_exception(jit); |
14754 | 0 | } |
14755 | 0 | } |
14756 | |
|
14757 | 0 | return 1; |
14758 | 0 | } |
14759 | | |
14760 | | static int zend_jit_assign_obj(zend_jit_ctx *jit, |
14761 | | const zend_op *opline, |
14762 | | const zend_op_array *op_array, |
14763 | | zend_ssa *ssa, |
14764 | | const zend_ssa_op *ssa_op, |
14765 | | uint32_t op1_info, |
14766 | | zend_jit_addr op1_addr, |
14767 | | uint32_t val_info, |
14768 | | zend_jit_addr val_addr, |
14769 | | zend_jit_addr val_def_addr, |
14770 | | zend_jit_addr res_addr, |
14771 | | bool op1_indirect, |
14772 | | zend_class_entry *ce, |
14773 | | bool ce_is_instanceof, |
14774 | | bool on_this, |
14775 | | bool delayed_fetch_this, |
14776 | | zend_class_entry *trace_ce, |
14777 | | uint8_t prop_type, |
14778 | | int may_throw) |
14779 | 0 | { |
14780 | 0 | zval *member; |
14781 | 0 | zend_string *name; |
14782 | 0 | zend_property_info *prop_info; |
14783 | 0 | zend_jit_addr prop_addr; |
14784 | 0 | ir_ref obj_ref = IR_UNUSED; |
14785 | 0 | ir_ref prop_ref = IR_UNUSED; |
14786 | 0 | ir_ref delayed_end_input = IR_UNUSED; |
14787 | 0 | ir_ref end_inputs = IR_UNUSED; |
14788 | 0 | ir_ref slow_inputs = IR_UNUSED; |
14789 | 0 | uint32_t res_info = RES_INFO(); |
14790 | |
|
14791 | 0 | if (Z_MODE(val_addr) == IS_REG |
14792 | 0 | && Z_LOAD(val_addr) |
14793 | 0 | && jit->ra[Z_SSA_VAR(val_addr)].ref == IR_NULL) { |
14794 | | /* Force load */ |
14795 | 0 | zend_jit_use_reg(jit, val_addr); |
14796 | 0 | } |
14797 | |
|
14798 | 0 | if (val_addr != val_def_addr && val_def_addr) { |
14799 | 0 | if (!zend_jit_update_regs(jit, (opline+1)->op1.var, val_addr, val_def_addr, val_info)) { |
14800 | 0 | return 0; |
14801 | 0 | } |
14802 | 0 | if (Z_MODE(val_def_addr) == IS_REG && Z_MODE(val_addr) != IS_REG) { |
14803 | 0 | val_addr = val_def_addr; |
14804 | 0 | } |
14805 | 0 | } |
14806 | | |
14807 | 0 | ZEND_ASSERT(opline->op2_type == IS_CONST); |
14808 | 0 | ZEND_ASSERT(op1_info & MAY_BE_OBJECT); |
14809 | |
|
14810 | 0 | member = RT_CONSTANT(opline, opline->op2); |
14811 | 0 | ZEND_ASSERT(Z_TYPE_P(member) == IS_STRING && Z_STRVAL_P(member)[0] != '\0'); |
14812 | 0 | name = Z_STR_P(member); |
14813 | 0 | prop_info = zend_get_known_property_info(op_array, ce, name, on_this, op_array->filename); |
14814 | |
|
14815 | 0 | if (on_this) { |
14816 | 0 | zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This)); |
14817 | 0 | obj_ref = jit_Z_PTR(jit, this_addr); |
14818 | 0 | } else { |
14819 | 0 | if (opline->op1_type == IS_VAR |
14820 | 0 | && (op1_info & MAY_BE_INDIRECT) |
14821 | 0 | && Z_REG(op1_addr) == ZREG_FP) { |
14822 | 0 | op1_addr = jit_ZVAL_INDIRECT_DEREF(jit, op1_addr); |
14823 | 0 | } |
14824 | 0 | if (op1_info & MAY_BE_REF) { |
14825 | 0 | op1_addr = jit_ZVAL_DEREF(jit, op1_addr); |
14826 | 0 | } |
14827 | 0 | if (op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY)- MAY_BE_OBJECT)) { |
14828 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
14829 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
14830 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
14831 | |
|
14832 | 0 | if (!exit_addr) { |
14833 | 0 | return 0; |
14834 | 0 | } |
14835 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_OBJECT, exit_addr); |
14836 | 0 | } else { |
14837 | 0 | ir_ref if_obj = jit_if_Z_TYPE(jit, op1_addr, IS_OBJECT); |
14838 | 0 | ir_IF_FALSE_cold(if_obj); |
14839 | |
|
14840 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14841 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_invalid_property_assign), |
14842 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
14843 | 0 | ir_CONST_ADDR(ZSTR_VAL(name))); |
14844 | |
|
14845 | 0 | if (RETURN_VALUE_USED(opline) && Z_MODE(res_addr) != IS_REG) { |
14846 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
14847 | 0 | } |
14848 | |
|
14849 | 0 | ir_END_list(end_inputs); |
14850 | |
|
14851 | 0 | ir_IF_TRUE(if_obj); |
14852 | 0 | } |
14853 | 0 | } |
14854 | 0 | obj_ref = jit_Z_PTR(jit, op1_addr); |
14855 | 0 | } |
14856 | | |
14857 | 0 | ZEND_ASSERT(obj_ref); |
14858 | 0 | if (!prop_info && trace_ce && (trace_ce->ce_flags & ZEND_ACC_IMMUTABLE)) { |
14859 | 0 | prop_info = zend_get_known_property_info(op_array, trace_ce, name, on_this, op_array->filename); |
14860 | 0 | if (prop_info) { |
14861 | 0 | ce = trace_ce; |
14862 | 0 | ce_is_instanceof = false; |
14863 | 0 | if (!(op1_info & MAY_BE_CLASS_GUARD)) { |
14864 | 0 | if (on_this && JIT_G(current_frame) |
14865 | 0 | && TRACE_FRAME_IS_THIS_CLASS_CHECKED(JIT_G(current_frame))) { |
14866 | 0 | ZEND_ASSERT(JIT_G(current_frame)->ce == ce); |
14867 | 0 | } else if (zend_jit_class_guard(jit, opline, obj_ref, ce)) { |
14868 | 0 | if (on_this && JIT_G(current_frame)) { |
14869 | 0 | JIT_G(current_frame)->ce = ce; |
14870 | 0 | TRACE_FRAME_SET_THIS_CLASS_CHECKED(JIT_G(current_frame)); |
14871 | 0 | } |
14872 | 0 | } else { |
14873 | 0 | return 0; |
14874 | 0 | } |
14875 | 0 | if (ssa->var_info && ssa_op->op1_use >= 0) { |
14876 | 0 | ssa->var_info[ssa_op->op1_use].type |= MAY_BE_CLASS_GUARD; |
14877 | 0 | ssa->var_info[ssa_op->op1_use].ce = ce; |
14878 | 0 | ssa->var_info[ssa_op->op1_use].is_instanceof = ce_is_instanceof; |
14879 | 0 | } |
14880 | 0 | if (ssa->var_info && ssa_op->op1_def >= 0) { |
14881 | 0 | ssa->var_info[ssa_op->op1_def].type |= MAY_BE_CLASS_GUARD; |
14882 | 0 | ssa->var_info[ssa_op->op1_def].ce = ce; |
14883 | 0 | ssa->var_info[ssa_op->op1_def].is_instanceof = ce_is_instanceof; |
14884 | 0 | } |
14885 | 0 | } |
14886 | 0 | } |
14887 | 0 | } |
14888 | | |
14889 | 0 | if (!prop_info) { |
14890 | 0 | ir_ref run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
14891 | 0 | ir_ref ref = ir_LOAD_A(ir_ADD_OFFSET(run_time_cache, opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS)); |
14892 | 0 | ir_ref if_same = ir_IF(ir_EQ(ref, ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_object, ce))))); |
14893 | |
|
14894 | 0 | ir_IF_FALSE_cold(if_same); |
14895 | 0 | ir_END_list(slow_inputs); |
14896 | |
|
14897 | 0 | ir_IF_TRUE(if_same); |
14898 | 0 | ir_ref offset_ref = ir_LOAD_A( |
14899 | 0 | ir_ADD_OFFSET(run_time_cache, (opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*))); |
14900 | |
|
14901 | 0 | ir_ref if_dynamic = ir_IF(ir_LT(offset_ref, ir_CONST_ADDR(ZEND_FIRST_PROPERTY_OFFSET))); |
14902 | 0 | ir_IF_TRUE_cold(if_dynamic); |
14903 | 0 | ir_END_list(slow_inputs); |
14904 | |
|
14905 | 0 | ir_IF_FALSE(if_dynamic); |
14906 | 0 | prop_ref = ir_ADD_A(obj_ref, offset_ref); |
14907 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE_ref(jit, prop_ref)); |
14908 | 0 | ir_IF_FALSE_cold(if_def); |
14909 | 0 | ir_END_list(slow_inputs); |
14910 | |
|
14911 | 0 | ir_IF_TRUE(if_def); |
14912 | 0 | prop_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
14913 | |
|
14914 | 0 | if (!ce || ce_is_instanceof || (ce->ce_flags & (ZEND_ACC_HAS_TYPE_HINTS|ZEND_ACC_TRAIT))) { |
14915 | 0 | ir_ref arg3, arg4; |
14916 | 0 | ir_ref prop_info_ref = ir_LOAD_A( |
14917 | 0 | ir_ADD_OFFSET(run_time_cache, (opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*) * 2)); |
14918 | 0 | ir_ref if_has_prop_info = ir_IF(prop_info_ref); |
14919 | 0 | ir_IF_TRUE_cold(if_has_prop_info); |
14920 | |
|
14921 | 0 | if (Z_MODE(val_addr) == IS_REG) { |
14922 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, (opline+1)->op1.var); |
14923 | 0 | if (!zend_jit_spill_store_inv(jit, val_addr, real_addr, val_info)) { |
14924 | 0 | return 0; |
14925 | 0 | } |
14926 | 0 | arg3 = jit_ZVAL_ADDR(jit, real_addr); |
14927 | 0 | } else { |
14928 | 0 | arg3 = jit_ZVAL_ADDR(jit, val_addr); |
14929 | 0 | } |
14930 | | |
14931 | 0 | if (!RETURN_VALUE_USED(opline)) { |
14932 | 0 | arg4 = IR_NULL; |
14933 | 0 | } else if (Z_MODE(res_addr) == IS_REG) { |
14934 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
14935 | 0 | arg4 = jit_ZVAL_ADDR(jit, real_addr); |
14936 | 0 | } else { |
14937 | 0 | arg4 = jit_ZVAL_ADDR(jit, res_addr); |
14938 | 0 | } |
14939 | | // JIT: value = zend_assign_to_typed_prop(prop_info, property_val, value EXECUTE_DATA_CC); |
14940 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14941 | 0 | ir_CALL_4(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_to_typed_prop), |
14942 | 0 | prop_ref, |
14943 | 0 | prop_info_ref, |
14944 | 0 | arg3, |
14945 | 0 | arg4); |
14946 | |
|
14947 | 0 | if ((opline+1)->op1_type == IS_CONST) { |
14948 | | // TODO: ??? |
14949 | | // if (Z_TYPE_P(value) == orig_type) { |
14950 | | // CACHE_PTR_EX(cache_slot + 2, NULL); |
14951 | 0 | } |
14952 | |
|
14953 | 0 | ir_END_list(end_inputs); |
14954 | 0 | ir_IF_FALSE(if_has_prop_info); |
14955 | 0 | } |
14956 | 0 | } else { |
14957 | 0 | prop_ref = ir_ADD_OFFSET(obj_ref, prop_info->offset); |
14958 | 0 | prop_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
14959 | | /* With the exception of __clone(), readonly assignment always happens on IS_UNDEF, doding |
14960 | | * the fast path. Thus, the fast path is not useful. */ |
14961 | 0 | if (prop_info->flags & ZEND_ACC_READONLY) { |
14962 | 0 | ZEND_ASSERT(slow_inputs == IR_UNUSED); |
14963 | 0 | goto slow_path; |
14964 | 0 | } |
14965 | | |
14966 | | // Undefined property with potential magic __get()/__set() or lazy object |
14967 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE && prop_type != IS_UNDEF) { |
14968 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
14969 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
14970 | |
|
14971 | 0 | if (!exit_addr) { |
14972 | 0 | return 0; |
14973 | 0 | } |
14974 | 0 | ir_GUARD(jit_Z_TYPE_INFO(jit, prop_addr), ir_CONST_ADDR(exit_addr)); |
14975 | 0 | } else { |
14976 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE_INFO(jit, prop_addr)); |
14977 | 0 | ir_IF_FALSE_cold(if_def); |
14978 | 0 | ir_END_list(slow_inputs); |
14979 | 0 | ir_IF_TRUE(if_def); |
14980 | 0 | } |
14981 | 0 | if (ZEND_TYPE_IS_SET(prop_info->type)) { |
14982 | 0 | ir_ref ref, arg3, arg4; |
14983 | | |
14984 | | // JIT: value = zend_assign_to_typed_prop(prop_info, property_val, value EXECUTE_DATA_CC); |
14985 | 0 | jit_SET_EX_OPLINE(jit, opline); |
14986 | 0 | if (ce && ce->ce_flags & ZEND_ACC_IMMUTABLE) { |
14987 | 0 | ref = ir_CONST_ADDR(prop_info); |
14988 | 0 | } else { |
14989 | 0 | int prop_info_offset = |
14990 | 0 | (((prop_info->offset - (sizeof(zend_object) - sizeof(zval))) / sizeof(zval)) * sizeof(void*)); |
14991 | |
|
14992 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_object, ce))); |
14993 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ref, offsetof(zend_class_entry, properties_info_table))); |
14994 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ref, prop_info_offset)); |
14995 | 0 | } |
14996 | 0 | if (Z_MODE(val_addr) == IS_REG) { |
14997 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, (opline+1)->op1.var); |
14998 | 0 | if (!zend_jit_spill_store_inv(jit, val_addr, real_addr, val_info)) { |
14999 | 0 | return 0; |
15000 | 0 | } |
15001 | 0 | arg3 = jit_ZVAL_ADDR(jit, real_addr); |
15002 | 0 | } else { |
15003 | 0 | arg3 = jit_ZVAL_ADDR(jit, val_addr); |
15004 | 0 | } |
15005 | 0 | if (!RETURN_VALUE_USED(opline)) { |
15006 | 0 | arg4 = IR_NULL; |
15007 | 0 | } else if (Z_MODE(res_addr) == IS_REG) { |
15008 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
15009 | 0 | arg4 = jit_ZVAL_ADDR(jit, real_addr); |
15010 | 0 | } else { |
15011 | 0 | arg4 = jit_ZVAL_ADDR(jit, res_addr); |
15012 | 0 | } |
15013 | 0 | ir_CALL_4(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_to_typed_prop), |
15014 | 0 | prop_ref, |
15015 | 0 | ref, |
15016 | 0 | arg3, |
15017 | 0 | arg4); |
15018 | |
|
15019 | 0 | ir_END_list(end_inputs); |
15020 | 0 | } |
15021 | 0 | } |
15022 | | |
15023 | 0 | if (!prop_info || !ZEND_TYPE_IS_SET(prop_info->type)) { |
15024 | 0 | if (Z_MODE(val_addr) != IS_REG |
15025 | 0 | && (res_addr == 0 || Z_MODE(res_addr) != IS_REG) |
15026 | 0 | && opline->result_type == IS_UNUSED) { |
15027 | 0 | if (!zend_jit_assign_to_variable_call(jit, opline, prop_addr, prop_addr, -1, -1, (opline+1)->op1_type, val_addr, val_info, res_addr, false)) { |
15028 | 0 | return 0; |
15029 | 0 | } |
15030 | 0 | } else { |
15031 | 0 | zend_jit_addr real_res_addr; |
15032 | |
|
15033 | 0 | if (res_addr && Z_MODE(res_addr) == IS_REG) { |
15034 | 0 | real_res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
15035 | 0 | } else { |
15036 | 0 | real_res_addr = res_addr; |
15037 | 0 | } |
15038 | 0 | if (!zend_jit_assign_to_variable(jit, opline, prop_addr, prop_addr, -1, -1, (opline+1)->op1_type, val_addr, val_info, real_res_addr, 0, false)) { |
15039 | 0 | return 0; |
15040 | 0 | } |
15041 | 0 | } |
15042 | 0 | if (end_inputs || slow_inputs) { |
15043 | 0 | if (((opline+1)->op1_type & (IS_VAR|IS_TMP_VAR)) |
15044 | 0 | && (val_info & (MAY_BE_REF|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
15045 | | /* skip FREE_OP_DATA() */ |
15046 | 0 | delayed_end_input = ir_END(); |
15047 | 0 | } else { |
15048 | 0 | ir_END_list(end_inputs); |
15049 | 0 | } |
15050 | 0 | } |
15051 | 0 | } |
15052 | | |
15053 | 0 | if (slow_inputs) { |
15054 | 0 | ir_ref arg3, arg5; |
15055 | |
|
15056 | 0 | ir_MERGE_list(slow_inputs); |
15057 | |
|
15058 | 0 | slow_path: |
15059 | 0 | jit_SET_EX_OPLINE(jit, opline); |
15060 | |
|
15061 | 0 | if (Z_MODE(val_addr) == IS_REG) { |
15062 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, (opline+1)->op1.var); |
15063 | 0 | if (!zend_jit_spill_store_inv(jit, val_addr, real_addr, val_info)) { |
15064 | 0 | return 0; |
15065 | 0 | } |
15066 | 0 | arg3 = jit_ZVAL_ADDR(jit, real_addr); |
15067 | 0 | } else { |
15068 | 0 | arg3 = jit_ZVAL_ADDR(jit, val_addr); |
15069 | 0 | } |
15070 | 0 | if (!RETURN_VALUE_USED(opline)) { |
15071 | 0 | arg5 = IR_NULL; |
15072 | 0 | } else if (Z_MODE(res_addr) == IS_REG) { |
15073 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
15074 | 0 | arg5 = jit_ZVAL_ADDR(jit, real_addr); |
15075 | 0 | } else { |
15076 | 0 | arg5 = jit_ZVAL_ADDR(jit, res_addr); |
15077 | 0 | } |
15078 | | |
15079 | | // JIT: value = zobj->handlers->write_property(zobj, name, value, CACHE_ADDR(opline->extended_value)); |
15080 | 0 | ir_ref run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
15081 | 0 | ir_CALL_5(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_obj_helper), |
15082 | 0 | obj_ref, |
15083 | 0 | ir_CONST_ADDR(name), |
15084 | 0 | arg3, |
15085 | 0 | ir_ADD_OFFSET(run_time_cache, opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS), |
15086 | 0 | arg5); |
15087 | |
|
15088 | 0 | ir_END_list(end_inputs); |
15089 | 0 | } |
15090 | | |
15091 | 0 | if (end_inputs) { |
15092 | 0 | ir_MERGE_list(end_inputs); |
15093 | |
|
15094 | 0 | if (val_info & (MAY_BE_REF|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
15095 | 0 | val_info |= MAY_BE_RC1|MAY_BE_RCN; |
15096 | 0 | } |
15097 | 0 | jit_FREE_OP(jit, (opline+1)->op1_type, (opline+1)->op1, val_info, opline); |
15098 | |
|
15099 | 0 | if (delayed_end_input) { |
15100 | 0 | ir_MERGE_WITH(delayed_end_input); |
15101 | 0 | } |
15102 | 0 | } |
15103 | |
|
15104 | 0 | if (opline->op1_type != IS_UNUSED && !delayed_fetch_this && !op1_indirect) { |
15105 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
15106 | 0 | } |
15107 | |
|
15108 | 0 | if (RETURN_VALUE_USED(opline) && Z_MODE(res_addr) == IS_REG) { |
15109 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
15110 | 0 | if (!zend_jit_load_reg(jit, real_addr, res_addr, res_info)) { |
15111 | 0 | return 0; |
15112 | 0 | } |
15113 | 0 | } |
15114 | | |
15115 | 0 | if (may_throw) { |
15116 | 0 | zend_jit_check_exception(jit); |
15117 | 0 | } |
15118 | |
|
15119 | 0 | return 1; |
15120 | 0 | } |
15121 | | |
15122 | | static int zend_jit_assign_obj_op(zend_jit_ctx *jit, |
15123 | | const zend_op *opline, |
15124 | | const zend_op_array *op_array, |
15125 | | zend_ssa *ssa, |
15126 | | const zend_ssa_op *ssa_op, |
15127 | | uint32_t op1_info, |
15128 | | zend_jit_addr op1_addr, |
15129 | | uint32_t val_info, |
15130 | | zend_jit_addr val_addr, |
15131 | | zend_ssa_range *val_range, |
15132 | | bool op1_indirect, |
15133 | | zend_class_entry *ce, |
15134 | | bool ce_is_instanceof, |
15135 | | bool on_this, |
15136 | | bool delayed_fetch_this, |
15137 | | zend_class_entry *trace_ce, |
15138 | | uint8_t prop_type) |
15139 | 0 | { |
15140 | 0 | zval *member; |
15141 | 0 | zend_string *name; |
15142 | 0 | zend_property_info *prop_info; |
15143 | 0 | zend_jit_addr prop_addr; |
15144 | 0 | bool use_prop_guard = false; |
15145 | 0 | bool may_throw = false; |
15146 | 0 | binary_op_type binary_op = get_binary_op(opline->extended_value); |
15147 | 0 | ir_ref obj_ref = IR_UNUSED; |
15148 | 0 | ir_ref prop_ref = IR_UNUSED; |
15149 | 0 | ir_ref end_inputs = IR_UNUSED; |
15150 | 0 | ir_ref slow_inputs = IR_UNUSED; |
15151 | |
|
15152 | 0 | ZEND_ASSERT(opline->op2_type == IS_CONST); |
15153 | 0 | ZEND_ASSERT(op1_info & MAY_BE_OBJECT); |
15154 | 0 | ZEND_ASSERT(opline->result_type == IS_UNUSED); |
15155 | |
|
15156 | 0 | member = RT_CONSTANT(opline, opline->op2); |
15157 | 0 | ZEND_ASSERT(Z_TYPE_P(member) == IS_STRING && Z_STRVAL_P(member)[0] != '\0'); |
15158 | 0 | name = Z_STR_P(member); |
15159 | 0 | prop_info = zend_get_known_property_info(op_array, ce, name, on_this, op_array->filename); |
15160 | |
|
15161 | 0 | if (on_this) { |
15162 | 0 | zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This)); |
15163 | 0 | obj_ref = jit_Z_PTR(jit, this_addr); |
15164 | 0 | } else { |
15165 | 0 | if (opline->op1_type == IS_VAR |
15166 | 0 | && (op1_info & MAY_BE_INDIRECT) |
15167 | 0 | && Z_REG(op1_addr) == ZREG_FP) { |
15168 | 0 | op1_addr = jit_ZVAL_INDIRECT_DEREF(jit, op1_addr); |
15169 | 0 | } |
15170 | 0 | if (op1_info & MAY_BE_REF) { |
15171 | 0 | op1_addr = jit_ZVAL_DEREF(jit, op1_addr); |
15172 | 0 | } |
15173 | 0 | if (op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY)- MAY_BE_OBJECT)) { |
15174 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
15175 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
15176 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
15177 | |
|
15178 | 0 | if (!exit_addr) { |
15179 | 0 | return 0; |
15180 | 0 | } |
15181 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_OBJECT, exit_addr); |
15182 | 0 | } else { |
15183 | 0 | ir_ref if_obj = jit_if_Z_TYPE(jit, op1_addr, IS_OBJECT); |
15184 | 0 | ir_IF_FALSE_cold(if_obj); |
15185 | |
|
15186 | 0 | jit_SET_EX_OPLINE(jit, opline); |
15187 | 0 | ir_CALL_2(IR_VOID, |
15188 | 0 | (op1_info & MAY_BE_UNDEF) ? |
15189 | 0 | ir_CONST_FC_FUNC(zend_jit_invalid_property_assign_op) : |
15190 | 0 | ir_CONST_FC_FUNC(zend_jit_invalid_property_assign), |
15191 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
15192 | 0 | ir_CONST_ADDR(ZSTR_VAL(name))); |
15193 | |
|
15194 | 0 | may_throw = true; |
15195 | |
|
15196 | 0 | ir_END_list(end_inputs); |
15197 | 0 | ir_IF_TRUE(if_obj); |
15198 | 0 | } |
15199 | 0 | } |
15200 | 0 | obj_ref = jit_Z_PTR(jit, op1_addr); |
15201 | 0 | } |
15202 | | |
15203 | 0 | ZEND_ASSERT(obj_ref); |
15204 | 0 | if (!prop_info && trace_ce && (trace_ce->ce_flags & ZEND_ACC_IMMUTABLE)) { |
15205 | 0 | prop_info = zend_get_known_property_info(op_array, trace_ce, name, on_this, op_array->filename); |
15206 | 0 | if (prop_info) { |
15207 | 0 | ce = trace_ce; |
15208 | 0 | ce_is_instanceof = false; |
15209 | 0 | if (!(op1_info & MAY_BE_CLASS_GUARD)) { |
15210 | 0 | if (on_this && JIT_G(current_frame) |
15211 | 0 | && TRACE_FRAME_IS_THIS_CLASS_CHECKED(JIT_G(current_frame))) { |
15212 | 0 | ZEND_ASSERT(JIT_G(current_frame)->ce == ce); |
15213 | 0 | } else if (zend_jit_class_guard(jit, opline, obj_ref, ce)) { |
15214 | 0 | if (on_this && JIT_G(current_frame)) { |
15215 | 0 | JIT_G(current_frame)->ce = ce; |
15216 | 0 | TRACE_FRAME_SET_THIS_CLASS_CHECKED(JIT_G(current_frame)); |
15217 | 0 | } |
15218 | 0 | } else { |
15219 | 0 | return 0; |
15220 | 0 | } |
15221 | 0 | if (ssa->var_info && ssa_op->op1_use >= 0) { |
15222 | 0 | ssa->var_info[ssa_op->op1_use].type |= MAY_BE_CLASS_GUARD; |
15223 | 0 | ssa->var_info[ssa_op->op1_use].ce = ce; |
15224 | 0 | ssa->var_info[ssa_op->op1_use].is_instanceof = ce_is_instanceof; |
15225 | 0 | } |
15226 | 0 | if (ssa->var_info && ssa_op->op1_def >= 0) { |
15227 | 0 | ssa->var_info[ssa_op->op1_def].type |= MAY_BE_CLASS_GUARD; |
15228 | 0 | ssa->var_info[ssa_op->op1_def].ce = ce; |
15229 | 0 | ssa->var_info[ssa_op->op1_def].is_instanceof = ce_is_instanceof; |
15230 | 0 | } |
15231 | 0 | } |
15232 | 0 | } |
15233 | 0 | } |
15234 | | |
15235 | 0 | use_prop_guard = (prop_type != IS_UNKNOWN |
15236 | 0 | && prop_type != IS_UNDEF |
15237 | 0 | && prop_type != IS_REFERENCE |
15238 | 0 | && (op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_OBJECT); |
15239 | |
|
15240 | 0 | if (Z_MODE(val_addr) == IS_REG |
15241 | 0 | && Z_LOAD(val_addr) |
15242 | 0 | && jit->ra[Z_SSA_VAR(val_addr)].ref == IR_NULL) { |
15243 | | /* Force load */ |
15244 | 0 | zend_jit_use_reg(jit, val_addr); |
15245 | 0 | } |
15246 | |
|
15247 | 0 | if (!prop_info) { |
15248 | 0 | ir_ref run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
15249 | 0 | ir_ref ref = ir_LOAD_A(ir_ADD_OFFSET(run_time_cache, (opline+1)->extended_value & ~ZEND_FETCH_OBJ_FLAGS)); |
15250 | 0 | ir_ref if_same = ir_IF(ir_EQ(ref, ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_object, ce))))); |
15251 | |
|
15252 | 0 | ir_IF_FALSE_cold(if_same); |
15253 | 0 | ir_END_list(slow_inputs); |
15254 | |
|
15255 | 0 | ir_IF_TRUE(if_same); |
15256 | 0 | if (!ce || ce_is_instanceof || (ce->ce_flags & (ZEND_ACC_HAS_TYPE_HINTS|ZEND_ACC_TRAIT))) { |
15257 | 0 | ir_ref prop_info_ref = ir_LOAD_A( |
15258 | 0 | ir_ADD_OFFSET(run_time_cache, ((opline+1)->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*) * 2)); |
15259 | 0 | ir_ref if_has_prop_info = ir_IF(prop_info_ref); |
15260 | 0 | ir_IF_TRUE_cold(if_has_prop_info); |
15261 | 0 | ir_END_list(slow_inputs); |
15262 | |
|
15263 | 0 | ir_IF_FALSE(if_has_prop_info); |
15264 | 0 | } |
15265 | 0 | ir_ref offset_ref = ir_LOAD_A( |
15266 | 0 | ir_ADD_OFFSET(run_time_cache, ((opline+1)->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*))); |
15267 | |
|
15268 | 0 | ir_ref if_dynamic = ir_IF(ir_LT(offset_ref, ir_CONST_ADDR(ZEND_FIRST_PROPERTY_OFFSET))); |
15269 | 0 | ir_IF_TRUE_cold(if_dynamic); |
15270 | 0 | ir_END_list(slow_inputs); |
15271 | |
|
15272 | 0 | ir_IF_FALSE(if_dynamic); |
15273 | |
|
15274 | 0 | prop_ref = ir_ADD_A(obj_ref, offset_ref); |
15275 | 0 | if (!use_prop_guard) { |
15276 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE_ref(jit, prop_ref)); |
15277 | 0 | ir_IF_FALSE_cold(if_def); |
15278 | 0 | ir_END_list(slow_inputs); |
15279 | |
|
15280 | 0 | ir_IF_TRUE(if_def); |
15281 | 0 | } |
15282 | 0 | prop_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
15283 | 0 | } else { |
15284 | 0 | prop_ref = ir_ADD_OFFSET(obj_ref, prop_info->offset); |
15285 | 0 | prop_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
15286 | |
|
15287 | 0 | if (ZEND_TYPE_IS_SET(prop_info->type) || !use_prop_guard) { |
15288 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
15289 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
15290 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
15291 | |
|
15292 | 0 | if (!exit_addr) { |
15293 | 0 | return 0; |
15294 | 0 | } |
15295 | 0 | ir_GUARD(jit_Z_TYPE_INFO(jit, prop_addr), ir_CONST_ADDR(exit_addr)); |
15296 | 0 | } else { |
15297 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE_INFO(jit, prop_addr)); |
15298 | 0 | ir_IF_FALSE_cold(if_def); |
15299 | 0 | ir_END_list(slow_inputs); |
15300 | 0 | ir_IF_TRUE(if_def); |
15301 | 0 | } |
15302 | 0 | } |
15303 | 0 | if (ZEND_TYPE_IS_SET(prop_info->type)) { |
15304 | 0 | ir_ref if_ref, if_typed, noref_path, ref_path, reference, ref, arg2; |
15305 | |
|
15306 | 0 | may_throw = true; |
15307 | |
|
15308 | 0 | jit_SET_EX_OPLINE(jit, opline); |
15309 | |
|
15310 | 0 | if (Z_MODE(val_addr) == IS_REG) { |
15311 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, (opline+1)->op1.var); |
15312 | 0 | if (!zend_jit_spill_store_inv(jit, val_addr, real_addr, val_info)) { |
15313 | 0 | return 0; |
15314 | 0 | } |
15315 | 0 | arg2 = jit_ZVAL_ADDR(jit, real_addr); |
15316 | 0 | } else { |
15317 | 0 | arg2 = jit_ZVAL_ADDR(jit, val_addr); |
15318 | 0 | } |
15319 | | |
15320 | 0 | if_ref = jit_if_Z_TYPE(jit, prop_addr, IS_REFERENCE); |
15321 | 0 | ir_IF_FALSE(if_ref); |
15322 | 0 | noref_path = ir_END(); |
15323 | 0 | ir_IF_TRUE(if_ref); |
15324 | |
|
15325 | 0 | reference = jit_Z_PTR(jit, prop_addr); |
15326 | 0 | ref = ir_ADD_OFFSET(reference, offsetof(zend_reference, val)); |
15327 | 0 | if_typed = jit_if_TYPED_REF(jit, reference); |
15328 | 0 | ir_IF_FALSE(if_typed); |
15329 | 0 | ref_path = ir_END(); |
15330 | 0 | ir_IF_TRUE_cold(if_typed); |
15331 | |
|
15332 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_op_to_typed_ref), |
15333 | 0 | reference, |
15334 | 0 | arg2, |
15335 | 0 | ir_CONST_FC_FUNC(binary_op)); |
15336 | |
|
15337 | 0 | ir_END_list(end_inputs); |
15338 | |
|
15339 | 0 | ir_MERGE_2(noref_path, ref_path); |
15340 | 0 | prop_ref = ir_PHI_2(IR_ADDR, prop_ref, ref); |
15341 | 0 | prop_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
15342 | | |
15343 | | // JIT: value = zend_assign_to_typed_prop(prop_info, property_val, value EXECUTE_DATA_CC); |
15344 | 0 | if (ce && ce->ce_flags & ZEND_ACC_IMMUTABLE) { |
15345 | 0 | ref = ir_CONST_ADDR(prop_info); |
15346 | 0 | } else { |
15347 | 0 | int prop_info_offset = |
15348 | 0 | (((prop_info->offset - (sizeof(zend_object) - sizeof(zval))) / sizeof(zval)) * sizeof(void*)); |
15349 | |
|
15350 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_object, ce))); |
15351 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ref, offsetof(zend_class_entry, properties_info_table))); |
15352 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ref, prop_info_offset)); |
15353 | 0 | } |
15354 | |
|
15355 | 0 | ir_CALL_4(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_op_to_typed_prop), |
15356 | 0 | prop_ref, |
15357 | 0 | ref, |
15358 | 0 | arg2, |
15359 | 0 | ir_CONST_FC_FUNC(binary_op)); |
15360 | |
|
15361 | 0 | ir_END_list(end_inputs); |
15362 | 0 | } |
15363 | 0 | } |
15364 | | |
15365 | 0 | if (!prop_info || !ZEND_TYPE_IS_SET(prop_info->type)) { |
15366 | 0 | zend_jit_addr var_addr = prop_addr; |
15367 | 0 | uint32_t var_info = MAY_BE_ANY|MAY_BE_REF|MAY_BE_RC1|MAY_BE_RCN; |
15368 | 0 | uint32_t var_def_info = MAY_BE_ANY|MAY_BE_REF|MAY_BE_RC1|MAY_BE_RCN; |
15369 | |
|
15370 | 0 | if (use_prop_guard) { |
15371 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
15372 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
15373 | 0 | if (!exit_addr) { |
15374 | 0 | return 0; |
15375 | 0 | } |
15376 | | |
15377 | 0 | jit_guard_Z_TYPE(jit, prop_addr, prop_type, exit_addr); |
15378 | 0 | var_info = (1 << prop_type) | (var_info & ~(MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF)); |
15379 | 0 | } |
15380 | | |
15381 | 0 | if (var_info & MAY_BE_REF) { |
15382 | 0 | ir_ref if_ref, if_typed, noref_path, ref_path, reference, ref, arg2; |
15383 | |
|
15384 | 0 | may_throw = true; |
15385 | |
|
15386 | 0 | if_ref = jit_if_Z_TYPE(jit, prop_addr, IS_REFERENCE); |
15387 | 0 | ir_IF_FALSE(if_ref); |
15388 | 0 | noref_path = ir_END(); |
15389 | 0 | ir_IF_TRUE(if_ref); |
15390 | |
|
15391 | 0 | reference = jit_Z_PTR(jit, var_addr); |
15392 | 0 | ref = ir_ADD_OFFSET(reference, offsetof(zend_reference, val)); |
15393 | 0 | if_typed = jit_if_TYPED_REF(jit, reference); |
15394 | 0 | ir_IF_FALSE(if_typed); |
15395 | 0 | ref_path = ir_END(); |
15396 | 0 | ir_IF_TRUE_cold(if_typed); |
15397 | |
|
15398 | 0 | jit_SET_EX_OPLINE(jit, opline); |
15399 | |
|
15400 | 0 | if (Z_MODE(val_addr) == IS_REG) { |
15401 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, (opline+1)->op1.var); |
15402 | 0 | if (!zend_jit_spill_store_inv(jit, val_addr, real_addr, val_info)) { |
15403 | 0 | return 0; |
15404 | 0 | } |
15405 | 0 | arg2 = jit_ZVAL_ADDR(jit, real_addr); |
15406 | 0 | } else { |
15407 | 0 | arg2 = jit_ZVAL_ADDR(jit, val_addr); |
15408 | 0 | } |
15409 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_op_to_typed_ref), |
15410 | 0 | reference, |
15411 | 0 | arg2, |
15412 | 0 | ir_CONST_FC_FUNC(binary_op)); |
15413 | |
|
15414 | 0 | ir_END_list(end_inputs); |
15415 | |
|
15416 | 0 | ir_MERGE_2(noref_path, ref_path); |
15417 | 0 | prop_ref = ir_PHI_2(IR_ADDR, prop_ref, ref); |
15418 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
15419 | |
|
15420 | 0 | var_info &= ~MAY_BE_REF; |
15421 | 0 | } |
15422 | | |
15423 | 0 | uint8_t val_op_type = (opline+1)->op1_type; |
15424 | 0 | if (val_op_type & (IS_TMP_VAR|IS_VAR)) { |
15425 | | /* prevent FREE_OP in the helpers */ |
15426 | 0 | val_op_type = IS_CV; |
15427 | 0 | } |
15428 | |
|
15429 | 0 | switch (opline->extended_value) { |
15430 | 0 | case ZEND_ADD: |
15431 | 0 | case ZEND_SUB: |
15432 | 0 | case ZEND_MUL: |
15433 | 0 | if ((var_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) || |
15434 | 0 | (val_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
15435 | 0 | if (opline->extended_value != ZEND_ADD || |
15436 | 0 | (var_info & MAY_BE_ANY) != MAY_BE_ARRAY || |
15437 | 0 | (val_info & MAY_BE_ANY) == MAY_BE_ARRAY) { |
15438 | 0 | may_throw = true; |
15439 | 0 | } |
15440 | 0 | } |
15441 | 0 | if (!zend_jit_math_helper(jit, opline, opline->extended_value, IS_CV, opline->op1, var_addr, var_info, val_op_type, (opline+1)->op1, val_addr, val_info, 0, var_addr, var_def_info, var_info, |
15442 | 0 | 1 /* may overflow */, 0)) { |
15443 | 0 | return 0; |
15444 | 0 | } |
15445 | 0 | break; |
15446 | 0 | case ZEND_BW_OR: |
15447 | 0 | case ZEND_BW_AND: |
15448 | 0 | case ZEND_BW_XOR: |
15449 | 0 | if ((var_info & (MAY_BE_STRING|MAY_BE_DOUBLE|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) || |
15450 | 0 | (val_info & (MAY_BE_STRING|MAY_BE_DOUBLE|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
15451 | 0 | if ((var_info & MAY_BE_ANY) != MAY_BE_STRING || |
15452 | 0 | (val_info & MAY_BE_ANY) != MAY_BE_STRING) { |
15453 | 0 | may_throw = true; |
15454 | 0 | } |
15455 | 0 | } |
15456 | 0 | goto long_math; |
15457 | 0 | case ZEND_SL: |
15458 | 0 | case ZEND_SR: |
15459 | 0 | if ((var_info & (MAY_BE_STRING|MAY_BE_DOUBLE|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) || |
15460 | 0 | (val_info & (MAY_BE_STRING|MAY_BE_DOUBLE|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
15461 | 0 | may_throw = true; |
15462 | 0 | } |
15463 | 0 | if (val_op_type != IS_CONST || |
15464 | 0 | Z_TYPE_P(RT_CONSTANT((opline+1), (opline+1)->op1)) != IS_LONG || |
15465 | 0 | Z_LVAL_P(RT_CONSTANT((opline+1), (opline+1)->op1)) < 0) { |
15466 | 0 | may_throw = true; |
15467 | 0 | } |
15468 | 0 | goto long_math; |
15469 | 0 | case ZEND_MOD: |
15470 | 0 | if ((var_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) || |
15471 | 0 | (val_info & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE))) { |
15472 | 0 | may_throw = true; |
15473 | 0 | } |
15474 | 0 | if (val_op_type != IS_CONST || |
15475 | 0 | Z_TYPE_P(RT_CONSTANT((opline+1), (opline+1)->op1)) != IS_LONG || |
15476 | 0 | Z_LVAL_P(RT_CONSTANT((opline+1), (opline+1)->op1)) == 0) { |
15477 | 0 | may_throw = true; |
15478 | 0 | } |
15479 | 0 | long_math: |
15480 | 0 | if (!zend_jit_long_math_helper(jit, opline, opline->extended_value, |
15481 | 0 | IS_CV, opline->op1, var_addr, var_info, NULL, |
15482 | 0 | val_op_type, (opline+1)->op1, val_addr, val_info, |
15483 | 0 | val_range, |
15484 | 0 | 0, var_addr, var_def_info, var_info, /* may throw */ 1)) { |
15485 | 0 | return 0; |
15486 | 0 | } |
15487 | 0 | break; |
15488 | 0 | case ZEND_CONCAT: |
15489 | 0 | may_throw = true; |
15490 | 0 | if (!zend_jit_concat_helper(jit, opline, IS_CV, opline->op1, var_addr, var_info, val_op_type, (opline+1)->op1, val_addr, val_info, var_addr, |
15491 | 0 | 0)) { |
15492 | 0 | return 0; |
15493 | 0 | } |
15494 | 0 | break; |
15495 | 0 | default: |
15496 | 0 | ZEND_UNREACHABLE(); |
15497 | 0 | } |
15498 | 0 | if (end_inputs || slow_inputs) { |
15499 | 0 | ir_END_list(end_inputs); |
15500 | 0 | } |
15501 | 0 | } |
15502 | | |
15503 | 0 | if (slow_inputs) { |
15504 | 0 | ir_ref arg3; |
15505 | |
|
15506 | 0 | ir_MERGE_list(slow_inputs); |
15507 | |
|
15508 | 0 | may_throw = true; |
15509 | |
|
15510 | 0 | if (Z_MODE(val_addr) == IS_REG) { |
15511 | 0 | zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, (opline+1)->op1.var); |
15512 | 0 | if (!zend_jit_spill_store_inv(jit, val_addr, real_addr, val_info)) { |
15513 | 0 | return 0; |
15514 | 0 | } |
15515 | 0 | arg3 = jit_ZVAL_ADDR(jit, real_addr); |
15516 | 0 | } else { |
15517 | 0 | arg3 = jit_ZVAL_ADDR(jit, val_addr); |
15518 | 0 | } |
15519 | 0 | jit_SET_EX_OPLINE(jit, opline); |
15520 | 0 | ir_ref run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
15521 | 0 | ir_CALL_5(IR_VOID, ir_CONST_FC_FUNC(zend_jit_assign_obj_op_helper), |
15522 | 0 | obj_ref, |
15523 | 0 | ir_CONST_ADDR(name), |
15524 | 0 | arg3, |
15525 | 0 | ir_ADD_OFFSET(run_time_cache, (opline+1)->extended_value & ~ZEND_FETCH_OBJ_FLAGS), |
15526 | 0 | ir_CONST_FC_FUNC(binary_op)); |
15527 | |
|
15528 | 0 | ir_END_list(end_inputs); |
15529 | 0 | } |
15530 | | |
15531 | 0 | if (end_inputs) { |
15532 | 0 | ir_MERGE_list(end_inputs); |
15533 | 0 | } |
15534 | |
|
15535 | 0 | if (val_info & (MAY_BE_REF|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
15536 | 0 | val_info |= MAY_BE_RC1|MAY_BE_RCN; |
15537 | 0 | } |
15538 | | |
15539 | | // JIT: FREE_OP_DATA(); |
15540 | 0 | jit_FREE_OP(jit, (opline+1)->op1_type, (opline+1)->op1, val_info, opline); |
15541 | |
|
15542 | 0 | if (opline->op1_type != IS_UNUSED && !delayed_fetch_this && !op1_indirect) { |
15543 | 0 | if ((op1_info & MAY_HAVE_DTOR) && (op1_info & MAY_BE_RC1)) { |
15544 | 0 | may_throw = true; |
15545 | 0 | } |
15546 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
15547 | 0 | } |
15548 | |
|
15549 | 0 | if (may_throw) { |
15550 | 0 | zend_jit_check_exception(jit); |
15551 | 0 | } |
15552 | |
|
15553 | 0 | return 1; |
15554 | 0 | } |
15555 | | |
15556 | | static int zend_jit_incdec_obj(zend_jit_ctx *jit, |
15557 | | const zend_op *opline, |
15558 | | const zend_op_array *op_array, |
15559 | | zend_ssa *ssa, |
15560 | | const zend_ssa_op *ssa_op, |
15561 | | uint32_t op1_info, |
15562 | | zend_jit_addr op1_addr, |
15563 | | bool op1_indirect, |
15564 | | zend_class_entry *ce, |
15565 | | bool ce_is_instanceof, |
15566 | | bool on_this, |
15567 | | bool delayed_fetch_this, |
15568 | | zend_class_entry *trace_ce, |
15569 | | uint8_t prop_type) |
15570 | 0 | { |
15571 | 0 | zval *member; |
15572 | 0 | zend_string *name; |
15573 | 0 | zend_property_info *prop_info; |
15574 | 0 | zend_jit_addr res_addr = 0; |
15575 | 0 | zend_jit_addr prop_addr; |
15576 | 0 | bool use_prop_guard = false; |
15577 | 0 | bool may_throw = false; |
15578 | 0 | uint32_t res_info = (opline->result_type != IS_UNDEF) ? RES_INFO() : 0; |
15579 | 0 | ir_ref obj_ref = IR_UNUSED; |
15580 | 0 | ir_ref prop_ref = IR_UNUSED; |
15581 | 0 | ir_ref end_inputs = IR_UNUSED; |
15582 | 0 | ir_ref slow_inputs = IR_UNUSED; |
15583 | |
|
15584 | 0 | ZEND_ASSERT(opline->op2_type == IS_CONST); |
15585 | 0 | ZEND_ASSERT(op1_info & MAY_BE_OBJECT); |
15586 | |
|
15587 | 0 | if (opline->result_type != IS_UNUSED) { |
15588 | 0 | res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); |
15589 | 0 | } |
15590 | |
|
15591 | 0 | member = RT_CONSTANT(opline, opline->op2); |
15592 | 0 | ZEND_ASSERT(Z_TYPE_P(member) == IS_STRING && Z_STRVAL_P(member)[0] != '\0'); |
15593 | 0 | name = Z_STR_P(member); |
15594 | 0 | prop_info = zend_get_known_property_info(op_array, ce, name, on_this, op_array->filename); |
15595 | |
|
15596 | 0 | if (on_this) { |
15597 | 0 | zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This)); |
15598 | 0 | obj_ref = jit_Z_PTR(jit, this_addr); |
15599 | 0 | } else { |
15600 | 0 | if (opline->op1_type == IS_VAR |
15601 | 0 | && (op1_info & MAY_BE_INDIRECT) |
15602 | 0 | && Z_REG(op1_addr) == ZREG_FP) { |
15603 | 0 | op1_addr = jit_ZVAL_INDIRECT_DEREF(jit, op1_addr); |
15604 | 0 | } |
15605 | 0 | if (op1_info & MAY_BE_REF) { |
15606 | 0 | op1_addr = jit_ZVAL_DEREF(jit, op1_addr); |
15607 | 0 | } |
15608 | 0 | if (op1_info & ((MAY_BE_UNDEF|MAY_BE_ANY)- MAY_BE_OBJECT)) { |
15609 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
15610 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
15611 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
15612 | |
|
15613 | 0 | if (!exit_addr) { |
15614 | 0 | return 0; |
15615 | 0 | } |
15616 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_OBJECT, exit_addr); |
15617 | 0 | } else { |
15618 | 0 | ir_ref if_obj = jit_if_Z_TYPE(jit, op1_addr, IS_OBJECT); |
15619 | 0 | ir_IF_FALSE_cold(if_obj); |
15620 | |
|
15621 | 0 | jit_SET_EX_OPLINE(jit, opline); |
15622 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_invalid_property_incdec), |
15623 | 0 | jit_ZVAL_ADDR(jit, op1_addr), |
15624 | 0 | ir_CONST_ADDR(ZSTR_VAL(name))); |
15625 | |
|
15626 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler)); |
15627 | 0 | ir_IF_TRUE(if_obj); |
15628 | 0 | } |
15629 | 0 | } |
15630 | 0 | obj_ref = jit_Z_PTR(jit, op1_addr); |
15631 | 0 | } |
15632 | | |
15633 | 0 | ZEND_ASSERT(obj_ref); |
15634 | 0 | if (!prop_info && trace_ce && (trace_ce->ce_flags & ZEND_ACC_IMMUTABLE)) { |
15635 | 0 | prop_info = zend_get_known_property_info(op_array, trace_ce, name, on_this, op_array->filename); |
15636 | 0 | if (prop_info) { |
15637 | 0 | ce = trace_ce; |
15638 | 0 | ce_is_instanceof = false; |
15639 | 0 | if (!(op1_info & MAY_BE_CLASS_GUARD)) { |
15640 | 0 | if (on_this && JIT_G(current_frame) |
15641 | 0 | && TRACE_FRAME_IS_THIS_CLASS_CHECKED(JIT_G(current_frame))) { |
15642 | 0 | ZEND_ASSERT(JIT_G(current_frame)->ce == ce); |
15643 | 0 | } else if (zend_jit_class_guard(jit, opline, obj_ref, ce)) { |
15644 | 0 | if (on_this && JIT_G(current_frame)) { |
15645 | 0 | JIT_G(current_frame)->ce = ce; |
15646 | 0 | TRACE_FRAME_SET_THIS_CLASS_CHECKED(JIT_G(current_frame)); |
15647 | 0 | } |
15648 | 0 | } else { |
15649 | 0 | return 0; |
15650 | 0 | } |
15651 | 0 | if (ssa->var_info && ssa_op->op1_use >= 0) { |
15652 | 0 | ssa->var_info[ssa_op->op1_use].type |= MAY_BE_CLASS_GUARD; |
15653 | 0 | ssa->var_info[ssa_op->op1_use].ce = ce; |
15654 | 0 | ssa->var_info[ssa_op->op1_use].is_instanceof = ce_is_instanceof; |
15655 | 0 | } |
15656 | 0 | if (ssa->var_info && ssa_op->op1_def >= 0) { |
15657 | 0 | ssa->var_info[ssa_op->op1_def].type |= MAY_BE_CLASS_GUARD; |
15658 | 0 | ssa->var_info[ssa_op->op1_def].ce = ce; |
15659 | 0 | ssa->var_info[ssa_op->op1_def].is_instanceof = ce_is_instanceof; |
15660 | 0 | } |
15661 | 0 | } |
15662 | 0 | } |
15663 | 0 | } |
15664 | | |
15665 | 0 | use_prop_guard = (prop_type != IS_UNKNOWN |
15666 | 0 | && prop_type != IS_UNDEF |
15667 | 0 | && prop_type != IS_REFERENCE |
15668 | 0 | && (op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_OBJECT); |
15669 | |
|
15670 | 0 | if (!prop_info) { |
15671 | 0 | ir_ref run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
15672 | 0 | ir_ref ref = ir_LOAD_A(ir_ADD_OFFSET(run_time_cache, opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS)); |
15673 | 0 | ir_ref if_same = ir_IF(ir_EQ(ref, ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_object, ce))))); |
15674 | |
|
15675 | 0 | ir_IF_FALSE_cold(if_same); |
15676 | 0 | ir_END_list(slow_inputs); |
15677 | |
|
15678 | 0 | ir_IF_TRUE(if_same); |
15679 | 0 | if (!ce || ce_is_instanceof || (ce->ce_flags & (ZEND_ACC_HAS_TYPE_HINTS|ZEND_ACC_TRAIT))) { |
15680 | 0 | ir_ref prop_info_ref = ir_LOAD_A( |
15681 | 0 | ir_ADD_OFFSET(run_time_cache, (opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*) * 2)); |
15682 | 0 | ir_ref if_has_prop_info = ir_IF(prop_info_ref); |
15683 | 0 | ir_IF_TRUE_cold(if_has_prop_info); |
15684 | 0 | ir_END_list(slow_inputs); |
15685 | |
|
15686 | 0 | ir_IF_FALSE(if_has_prop_info); |
15687 | 0 | } |
15688 | 0 | ir_ref offset_ref = ir_LOAD_A( |
15689 | 0 | ir_ADD_OFFSET(run_time_cache, (opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS) + sizeof(void*))); |
15690 | |
|
15691 | 0 | ir_ref if_dynamic = ir_IF(ir_LT(offset_ref, ir_CONST_ADDR(ZEND_FIRST_PROPERTY_OFFSET))); |
15692 | 0 | ir_IF_TRUE_cold(if_dynamic); |
15693 | 0 | ir_END_list(slow_inputs); |
15694 | |
|
15695 | 0 | ir_IF_FALSE(if_dynamic); |
15696 | |
|
15697 | 0 | prop_ref = ir_ADD_A(obj_ref, offset_ref); |
15698 | 0 | if (!use_prop_guard) { |
15699 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE_ref(jit, prop_ref)); |
15700 | 0 | ir_IF_FALSE_cold(if_def); |
15701 | 0 | ir_END_list(slow_inputs); |
15702 | |
|
15703 | 0 | ir_IF_TRUE(if_def); |
15704 | 0 | } |
15705 | 0 | prop_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
15706 | 0 | } else { |
15707 | 0 | prop_ref = ir_ADD_OFFSET(obj_ref, prop_info->offset); |
15708 | 0 | prop_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
15709 | |
|
15710 | 0 | if (ZEND_TYPE_IS_SET(prop_info->type) || !use_prop_guard) { |
15711 | 0 | if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) { |
15712 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_TO_VM); |
15713 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
15714 | |
|
15715 | 0 | if (!exit_addr) { |
15716 | 0 | return 0; |
15717 | 0 | } |
15718 | 0 | ir_GUARD(jit_Z_TYPE_INFO(jit, prop_addr), ir_CONST_ADDR(exit_addr)); |
15719 | 0 | } else { |
15720 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE_INFO(jit, prop_addr)); |
15721 | 0 | ir_IF_FALSE_cold(if_def); |
15722 | 0 | ir_END_list(slow_inputs); |
15723 | 0 | ir_IF_TRUE(if_def); |
15724 | 0 | } |
15725 | 0 | } |
15726 | | |
15727 | 0 | if (ZEND_TYPE_IS_SET(prop_info->type)) { |
15728 | 0 | const void *func; |
15729 | 0 | ir_ref ref; |
15730 | |
|
15731 | 0 | may_throw = true; |
15732 | 0 | jit_SET_EX_OPLINE(jit, opline); |
15733 | |
|
15734 | 0 | if (ce && ce->ce_flags & ZEND_ACC_IMMUTABLE) { |
15735 | 0 | ref = ir_CONST_ADDR(prop_info); |
15736 | 0 | } else { |
15737 | 0 | int prop_info_offset = |
15738 | 0 | (((prop_info->offset - (sizeof(zend_object) - sizeof(zval))) / sizeof(zval)) * sizeof(void*)); |
15739 | |
|
15740 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_object, ce))); |
15741 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ref, offsetof(zend_class_entry, properties_info_table))); |
15742 | 0 | ref = ir_LOAD_A(ir_ADD_OFFSET(ref, prop_info_offset)); |
15743 | 0 | } |
15744 | |
|
15745 | 0 | if (opline->result_type == IS_UNUSED) { |
15746 | 0 | switch (opline->opcode) { |
15747 | 0 | case ZEND_PRE_INC_OBJ: |
15748 | 0 | case ZEND_POST_INC_OBJ: |
15749 | 0 | func = zend_jit_inc_typed_prop; |
15750 | 0 | break; |
15751 | 0 | case ZEND_PRE_DEC_OBJ: |
15752 | 0 | case ZEND_POST_DEC_OBJ: |
15753 | 0 | func = zend_jit_dec_typed_prop; |
15754 | 0 | break; |
15755 | 0 | default: |
15756 | 0 | ZEND_UNREACHABLE(); |
15757 | 0 | } |
15758 | | |
15759 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(func), prop_ref, ref); |
15760 | 0 | } else { |
15761 | 0 | switch (opline->opcode) { |
15762 | 0 | case ZEND_PRE_INC_OBJ: |
15763 | 0 | func = zend_jit_pre_inc_typed_prop; |
15764 | 0 | break; |
15765 | 0 | case ZEND_PRE_DEC_OBJ: |
15766 | 0 | func = zend_jit_pre_dec_typed_prop; |
15767 | 0 | break; |
15768 | 0 | case ZEND_POST_INC_OBJ: |
15769 | 0 | func = zend_jit_post_inc_typed_prop; |
15770 | 0 | break; |
15771 | 0 | case ZEND_POST_DEC_OBJ: |
15772 | 0 | func = zend_jit_post_dec_typed_prop; |
15773 | 0 | break; |
15774 | 0 | default: |
15775 | 0 | ZEND_UNREACHABLE(); |
15776 | 0 | } |
15777 | 0 | ir_CALL_3(IR_VOID, ir_CONST_FC_FUNC(func), |
15778 | 0 | prop_ref, |
15779 | 0 | ref, |
15780 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
15781 | 0 | } |
15782 | 0 | ir_END_list(end_inputs); |
15783 | 0 | } |
15784 | 0 | } |
15785 | | |
15786 | 0 | if (!prop_info || !ZEND_TYPE_IS_SET(prop_info->type)) { |
15787 | 0 | uint32_t var_info = MAY_BE_ANY|MAY_BE_REF|MAY_BE_RC1|MAY_BE_RCN; |
15788 | 0 | zend_jit_addr var_addr = prop_addr; |
15789 | 0 | ir_ref if_long = IR_UNUSED; |
15790 | 0 | ir_ref if_overflow = IR_UNUSED; |
15791 | |
|
15792 | 0 | if (use_prop_guard) { |
15793 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
15794 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
15795 | 0 | if (!exit_addr) { |
15796 | 0 | return 0; |
15797 | 0 | } |
15798 | | |
15799 | 0 | jit_guard_Z_TYPE(jit, prop_addr, prop_type, exit_addr); |
15800 | 0 | var_info = (1 << prop_type) | (var_info & ~(MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF)); |
15801 | 0 | } |
15802 | | |
15803 | 0 | if (var_info & MAY_BE_REF) { |
15804 | 0 | const void *func; |
15805 | 0 | ir_ref if_ref, if_typed, noref_path, ref_path, reference, ref; |
15806 | |
|
15807 | 0 | if_ref = jit_if_Z_TYPE(jit, prop_addr, IS_REFERENCE); |
15808 | 0 | ir_IF_FALSE(if_ref); |
15809 | 0 | noref_path = ir_END(); |
15810 | 0 | ir_IF_TRUE(if_ref); |
15811 | |
|
15812 | 0 | reference = jit_Z_PTR(jit, var_addr); |
15813 | 0 | ref = ir_ADD_OFFSET(reference, offsetof(zend_reference, val)); |
15814 | 0 | if_typed = jit_if_TYPED_REF(jit, reference); |
15815 | 0 | ir_IF_FALSE(if_typed); |
15816 | 0 | ref_path = ir_END(); |
15817 | 0 | ir_IF_TRUE_cold(if_typed); |
15818 | |
|
15819 | 0 | switch (opline->opcode) { |
15820 | 0 | case ZEND_PRE_INC_OBJ: |
15821 | 0 | func = zend_jit_pre_inc_typed_ref; |
15822 | 0 | break; |
15823 | 0 | case ZEND_PRE_DEC_OBJ: |
15824 | 0 | func = zend_jit_pre_dec_typed_ref; |
15825 | 0 | break; |
15826 | 0 | case ZEND_POST_INC_OBJ: |
15827 | 0 | func = zend_jit_post_inc_typed_ref; |
15828 | 0 | break; |
15829 | 0 | case ZEND_POST_DEC_OBJ: |
15830 | 0 | func = zend_jit_post_dec_typed_ref; |
15831 | 0 | break; |
15832 | 0 | default: |
15833 | 0 | ZEND_UNREACHABLE(); |
15834 | 0 | } |
15835 | | |
15836 | 0 | may_throw = true; |
15837 | 0 | jit_SET_EX_OPLINE(jit, opline); |
15838 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(func), |
15839 | 0 | reference, |
15840 | 0 | (opline->result_type == IS_UNUSED) ? IR_NULL : jit_ZVAL_ADDR(jit, res_addr)); |
15841 | |
|
15842 | 0 | ir_END_list(end_inputs); |
15843 | |
|
15844 | 0 | ir_MERGE_2(noref_path, ref_path); |
15845 | 0 | prop_ref = ir_PHI_2(IR_ADDR, prop_ref, ref); |
15846 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(prop_ref); |
15847 | |
|
15848 | 0 | var_info &= ~MAY_BE_REF; |
15849 | 0 | } |
15850 | | |
15851 | 0 | if (var_info & MAY_BE_LONG) { |
15852 | 0 | ir_ref addr, ref; |
15853 | |
|
15854 | 0 | if (var_info & (MAY_BE_ANY - MAY_BE_LONG)) { |
15855 | 0 | if_long = jit_if_Z_TYPE(jit, var_addr, IS_LONG); |
15856 | 0 | ir_IF_TRUE(if_long); |
15857 | 0 | } |
15858 | |
|
15859 | 0 | addr = jit_ZVAL_ADDR(jit, var_addr); |
15860 | 0 | ref = ir_LOAD_L(addr); |
15861 | 0 | if (opline->opcode == ZEND_POST_INC_OBJ || opline->opcode == ZEND_POST_DEC_OBJ) { |
15862 | 0 | if (opline->result_type != IS_UNUSED) { |
15863 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
15864 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
15865 | 0 | } |
15866 | 0 | } |
15867 | 0 | if (opline->opcode == ZEND_PRE_INC_OBJ || opline->opcode == ZEND_POST_INC_OBJ) { |
15868 | 0 | ref = ir_ADD_OV_L(ref, ir_CONST_LONG(1)); |
15869 | 0 | } else { |
15870 | 0 | ref = ir_SUB_OV_L(ref, ir_CONST_LONG(1)); |
15871 | 0 | } |
15872 | |
|
15873 | 0 | ir_STORE(addr, ref); |
15874 | 0 | if_overflow = ir_IF(ir_OVERFLOW(ref)); |
15875 | 0 | ir_IF_FALSE(if_overflow); |
15876 | |
|
15877 | 0 | if (opline->opcode == ZEND_PRE_INC_OBJ || opline->opcode == ZEND_PRE_DEC_OBJ) { |
15878 | 0 | if (opline->result_type != IS_UNUSED) { |
15879 | 0 | jit_set_Z_LVAL(jit, res_addr, ref); |
15880 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_LONG); |
15881 | 0 | } |
15882 | 0 | } |
15883 | 0 | ir_END_list(end_inputs); |
15884 | 0 | } |
15885 | |
|
15886 | 0 | if (var_info & (MAY_BE_ANY - MAY_BE_LONG)) { |
15887 | 0 | if (var_info & (MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) { |
15888 | 0 | may_throw = true; |
15889 | 0 | } |
15890 | 0 | if (if_long) { |
15891 | 0 | ir_IF_FALSE_cold(if_long); |
15892 | 0 | } |
15893 | 0 | if (opline->opcode == ZEND_POST_INC_OBJ || opline->opcode == ZEND_POST_DEC_OBJ) { |
15894 | 0 | jit_ZVAL_COPY(jit, res_addr, -1, var_addr, var_info, true); |
15895 | 0 | } |
15896 | 0 | if (opline->opcode == ZEND_PRE_INC_OBJ || opline->opcode == ZEND_POST_INC_OBJ) { |
15897 | 0 | if (opline->opcode == ZEND_PRE_INC_OBJ && opline->result_type != IS_UNUSED) { |
15898 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_pre_inc), |
15899 | 0 | jit_ZVAL_ADDR(jit, var_addr), |
15900 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
15901 | 0 | } else { |
15902 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(increment_function), |
15903 | 0 | jit_ZVAL_ADDR(jit, var_addr)); |
15904 | 0 | } |
15905 | 0 | } else { |
15906 | 0 | if (opline->opcode == ZEND_PRE_DEC_OBJ && opline->result_type != IS_UNUSED) { |
15907 | 0 | ir_CALL_2(IR_VOID, ir_CONST_FC_FUNC(zend_jit_pre_dec), |
15908 | 0 | jit_ZVAL_ADDR(jit, var_addr), |
15909 | 0 | jit_ZVAL_ADDR(jit, res_addr)); |
15910 | 0 | } else { |
15911 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(decrement_function), |
15912 | 0 | jit_ZVAL_ADDR(jit, var_addr)); |
15913 | 0 | } |
15914 | 0 | } |
15915 | |
|
15916 | 0 | ir_END_list(end_inputs); |
15917 | 0 | } |
15918 | 0 | if (var_info & MAY_BE_LONG) { |
15919 | 0 | ir_IF_TRUE_cold(if_overflow); |
15920 | 0 | if (opline->opcode == ZEND_PRE_INC_OBJ || opline->opcode == ZEND_POST_INC_OBJ) { |
15921 | | #if SIZEOF_ZEND_LONG == 4 |
15922 | | jit_set_Z_LVAL(jit, var_addr, ir_CONST_LONG(0)); |
15923 | | jit_set_Z_W2(jit, var_addr, ir_CONST_U32(0x41e00000)); |
15924 | | #else |
15925 | 0 | jit_set_Z_LVAL(jit, var_addr, ir_CONST_LONG(0x43e0000000000000)); |
15926 | 0 | #endif |
15927 | 0 | jit_set_Z_TYPE_INFO(jit, var_addr, IS_DOUBLE); |
15928 | 0 | if (opline->opcode == ZEND_PRE_INC_OBJ && opline->result_type != IS_UNUSED) { |
15929 | | #if SIZEOF_ZEND_LONG == 4 |
15930 | | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0)); |
15931 | | jit_set_Z_W2(jit, res_addr, ir_CONST_U32(0x41e00000)); |
15932 | | #else |
15933 | 0 | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0x43e0000000000000)); |
15934 | 0 | #endif |
15935 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
15936 | 0 | } |
15937 | 0 | } else { |
15938 | | #if SIZEOF_ZEND_LONG == 4 |
15939 | | jit_set_Z_LVAL(jit, var_addr, ir_CONST_LONG(0x00200000)); |
15940 | | jit_set_Z_W2(jit, var_addr, ir_CONST_U32(0xc1e00000)); |
15941 | | #else |
15942 | 0 | jit_set_Z_LVAL(jit, var_addr, ir_CONST_LONG(0xc3e0000000000000)); |
15943 | 0 | #endif |
15944 | 0 | jit_set_Z_TYPE_INFO(jit, var_addr, IS_DOUBLE); |
15945 | 0 | if (opline->opcode == ZEND_PRE_DEC_OBJ && opline->result_type != IS_UNUSED) { |
15946 | | #if SIZEOF_ZEND_LONG == 4 |
15947 | | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0x00200000)); |
15948 | | jit_set_Z_W2(jit, res_addr, ir_CONST_U32(0xc1e00000)); |
15949 | | #else |
15950 | 0 | jit_set_Z_LVAL(jit, res_addr, ir_CONST_LONG(0xc3e0000000000000)); |
15951 | 0 | #endif |
15952 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_DOUBLE); |
15953 | 0 | } |
15954 | 0 | } |
15955 | 0 | if (opline->result_type != IS_UNUSED |
15956 | 0 | && (opline->opcode == ZEND_PRE_INC_OBJ || opline->opcode == ZEND_PRE_DEC_OBJ) |
15957 | 0 | && prop_info |
15958 | 0 | && !ZEND_TYPE_IS_SET(prop_info->type) |
15959 | 0 | && (res_info & MAY_BE_GUARD) |
15960 | 0 | && (res_info & MAY_BE_LONG)) { |
15961 | 0 | zend_jit_trace_stack *stack = JIT_G(current_frame)->stack; |
15962 | 0 | uint32_t old_res_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var)); |
15963 | 0 | int32_t exit_point; |
15964 | 0 | const void *exit_addr; |
15965 | |
|
15966 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_DOUBLE, 0); |
15967 | 0 | exit_point = zend_jit_trace_get_exit_point(opline + 1, 0); |
15968 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
15969 | 0 | if (!exit_addr) { |
15970 | 0 | return 0; |
15971 | 0 | } |
15972 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var), old_res_info); |
15973 | 0 | ssa->var_info[ssa_op->result_def].type = res_info & ~MAY_BE_GUARD; |
15974 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
15975 | 0 | } else { |
15976 | 0 | ir_END_list(end_inputs); |
15977 | 0 | } |
15978 | 0 | } |
15979 | 0 | } |
15980 | | |
15981 | 0 | if (slow_inputs) { |
15982 | 0 | const void *func; |
15983 | |
|
15984 | 0 | ir_MERGE_list(slow_inputs); |
15985 | | |
15986 | | // JIT: zend_jit_pre_inc_obj_helper(zobj, name, CACHE_ADDR(opline->extended_value), result); |
15987 | 0 | switch (opline->opcode) { |
15988 | 0 | case ZEND_PRE_INC_OBJ: |
15989 | 0 | func = zend_jit_pre_inc_obj_helper; |
15990 | 0 | break; |
15991 | 0 | case ZEND_PRE_DEC_OBJ: |
15992 | 0 | func = zend_jit_pre_dec_obj_helper; |
15993 | 0 | break; |
15994 | 0 | case ZEND_POST_INC_OBJ: |
15995 | 0 | func = zend_jit_post_inc_obj_helper; |
15996 | 0 | break; |
15997 | 0 | case ZEND_POST_DEC_OBJ: |
15998 | 0 | func = zend_jit_post_dec_obj_helper; |
15999 | 0 | break; |
16000 | 0 | default: |
16001 | 0 | ZEND_UNREACHABLE(); |
16002 | 0 | } |
16003 | | |
16004 | 0 | may_throw = true; |
16005 | 0 | jit_SET_EX_OPLINE(jit, opline); |
16006 | 0 | ir_ref run_time_cache = ir_LOAD_A(jit_EX(run_time_cache)); |
16007 | 0 | ir_CALL_4(IR_VOID, ir_CONST_FC_FUNC(func), |
16008 | 0 | obj_ref, |
16009 | 0 | ir_CONST_ADDR(name), |
16010 | 0 | ir_ADD_OFFSET(run_time_cache, opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS), |
16011 | 0 | (opline->result_type == IS_UNUSED) ? IR_NULL : jit_ZVAL_ADDR(jit, res_addr)); |
16012 | |
|
16013 | 0 | ir_END_list(end_inputs); |
16014 | 0 | } |
16015 | | |
16016 | 0 | if (end_inputs) { |
16017 | 0 | ir_MERGE_list(end_inputs); |
16018 | 0 | } |
16019 | |
|
16020 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) && !delayed_fetch_this && !op1_indirect) { |
16021 | 0 | if ((op1_info & MAY_HAVE_DTOR) && (op1_info & MAY_BE_RC1)) { |
16022 | 0 | may_throw = true; |
16023 | 0 | } |
16024 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, opline); |
16025 | 0 | } |
16026 | |
|
16027 | 0 | if (may_throw) { |
16028 | 0 | zend_jit_check_exception(jit); |
16029 | 0 | } |
16030 | |
|
16031 | 0 | return 1; |
16032 | 0 | } |
16033 | | |
16034 | | static int zend_jit_fetch_static_prop(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array) |
16035 | 0 | { |
16036 | 0 | zend_jit_addr res_addr = RES_ADDR(); |
16037 | 0 | uint32_t cache_slot = opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS; |
16038 | 0 | uint32_t flags; |
16039 | 0 | ir_ref ref, ref2, if_cached, fast_path, cold_path, prop_info_ref, if_typed, if_def; |
16040 | 0 | int fetch_type; |
16041 | 0 | zend_property_info *known_prop_info = NULL; |
16042 | 0 | zend_class_entry *ce; |
16043 | |
|
16044 | 0 | ce = zend_get_known_class(op_array, opline, opline->op2_type, opline->op2); |
16045 | 0 | if (ce && (opline->op2_type == IS_CONST || !(ce->ce_flags & ZEND_ACC_TRAIT))) { |
16046 | 0 | zval *zv = RT_CONSTANT(opline, opline->op1); |
16047 | 0 | zend_string *prop_name; |
16048 | |
|
16049 | 0 | ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING); |
16050 | 0 | prop_name = Z_STR_P(zv); |
16051 | 0 | zv = zend_hash_find(&ce->properties_info, prop_name); |
16052 | 0 | if (zv) { |
16053 | 0 | zend_property_info *prop_info = Z_PTR_P(zv); |
16054 | |
|
16055 | 0 | if (prop_info->flags & ZEND_ACC_STATIC) { |
16056 | 0 | if (prop_info->ce == op_array->scope |
16057 | 0 | || (prop_info->flags & ZEND_ACC_PUBLIC) |
16058 | 0 | || ((prop_info->flags & ZEND_ACC_PROTECTED) |
16059 | 0 | && op_array->scope |
16060 | 0 | && instanceof_function_slow(op_array->scope, prop_info->ce))) { |
16061 | 0 | known_prop_info = prop_info; |
16062 | 0 | } |
16063 | 0 | } |
16064 | 0 | } |
16065 | 0 | } |
16066 | |
|
16067 | 0 | switch (opline->opcode) { |
16068 | 0 | case ZEND_FETCH_STATIC_PROP_R: |
16069 | 0 | case ZEND_FETCH_STATIC_PROP_FUNC_ARG: |
16070 | 0 | fetch_type = BP_VAR_R; |
16071 | 0 | break; |
16072 | 0 | case ZEND_FETCH_STATIC_PROP_IS: |
16073 | 0 | fetch_type = BP_VAR_IS; |
16074 | 0 | break; |
16075 | 0 | case ZEND_FETCH_STATIC_PROP_W: |
16076 | 0 | fetch_type = BP_VAR_W; |
16077 | 0 | break; |
16078 | 0 | case ZEND_FETCH_STATIC_PROP_RW: |
16079 | 0 | fetch_type = BP_VAR_RW; |
16080 | 0 | break; |
16081 | 0 | case ZEND_FETCH_STATIC_PROP_UNSET: |
16082 | 0 | fetch_type = BP_VAR_UNSET; |
16083 | 0 | break; |
16084 | 0 | EMPTY_SWITCH_DEFAULT_CASE(); |
16085 | 0 | } |
16086 | | |
16087 | | // JIT: result = CACHED_PTR(cache_slot + sizeof(void *)); |
16088 | 0 | ref = ir_LOAD_A( |
16089 | 0 | ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), cache_slot + sizeof(void*))); |
16090 | | |
16091 | | // JIT: if (result) |
16092 | 0 | if_cached = ir_IF(ref); |
16093 | 0 | ir_IF_TRUE(if_cached); |
16094 | |
|
16095 | 0 | if (fetch_type == BP_VAR_R || fetch_type == BP_VAR_RW) { |
16096 | 0 | if (!known_prop_info || ZEND_TYPE_IS_SET(known_prop_info->type)) { |
16097 | 0 | ir_ref merge = IR_UNUSED; |
16098 | | |
16099 | | // JIT: if (UNEXPECTED(Z_TYPE_P(result) == IS_UNDEF) |
16100 | 0 | if_typed = IR_UNUSED; |
16101 | 0 | if_def = ir_IF(jit_Z_TYPE_ref(jit, ref)); |
16102 | 0 | ir_IF_FALSE_cold(if_def); |
16103 | 0 | if (!known_prop_info) { |
16104 | | // JIT: if (ZEND_TYPE_IS_SET(property_info->type)) |
16105 | 0 | prop_info_ref = ir_LOAD_L( |
16106 | 0 | ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), cache_slot + sizeof(void*) * 2)); |
16107 | 0 | if_typed = ir_IF(ir_AND_U32( |
16108 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(prop_info_ref, offsetof(zend_property_info, type.type_mask))), |
16109 | 0 | ir_CONST_U32(_ZEND_TYPE_MASK))); |
16110 | 0 | ir_IF_FALSE(if_typed); |
16111 | 0 | ir_END_list(merge); |
16112 | 0 | ir_IF_TRUE(if_typed); |
16113 | 0 | } |
16114 | | // JIT: zend_throw_error(NULL, "Typed static property %s::$%s must not be accessed before initialization", |
16115 | | // ZSTR_VAL(property_info->ce->name), |
16116 | | // zend_get_unmangled_property_name(property_info->name)); |
16117 | 0 | jit_SET_EX_OPLINE(jit, opline); |
16118 | 0 | ir_CALL(IR_VOID, ir_CONST_FC_FUNC(zend_jit_uninit_static_prop)); |
16119 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler_undef)); |
16120 | |
|
16121 | 0 | ir_IF_TRUE(if_def); |
16122 | 0 | if (!known_prop_info) { |
16123 | 0 | ir_END_list(merge); |
16124 | 0 | ir_MERGE_list(merge); |
16125 | 0 | } |
16126 | 0 | } |
16127 | 0 | } else if (fetch_type == BP_VAR_W) { |
16128 | 0 | flags = opline->extended_value & ZEND_FETCH_OBJ_FLAGS; |
16129 | 0 | if (flags && (!known_prop_info || ZEND_TYPE_IS_SET(known_prop_info->type))) { |
16130 | 0 | ir_ref merge = IR_UNUSED; |
16131 | |
|
16132 | 0 | if (!known_prop_info) { |
16133 | | // JIT: if (ZEND_TYPE_IS_SET(property_info->type)) |
16134 | 0 | prop_info_ref = ir_LOAD_L( |
16135 | 0 | ir_ADD_OFFSET(ir_LOAD_A(jit_EX(run_time_cache)), cache_slot + sizeof(void*) * 2)); |
16136 | 0 | if_typed = ir_IF(ir_AND_U32( |
16137 | 0 | ir_LOAD_U32(ir_ADD_OFFSET(prop_info_ref, offsetof(zend_property_info, type.type_mask))), |
16138 | 0 | ir_CONST_U32(_ZEND_TYPE_MASK))); |
16139 | 0 | ir_IF_FALSE(if_typed); |
16140 | 0 | ir_END_list(merge); |
16141 | 0 | ir_IF_TRUE(if_typed); |
16142 | 0 | } else { |
16143 | 0 | prop_info_ref = ir_CONST_ADDR(known_prop_info); |
16144 | 0 | } |
16145 | | |
16146 | | // JIT: zend_handle_fetch_obj_flags(NULL, *retval, NULL, property_info, flags); |
16147 | 0 | ir_ref if_ok = ir_IF(ir_CALL_5(IR_BOOL, ir_CONST_FUNC(zend_handle_fetch_obj_flags), |
16148 | 0 | IR_NULL, ref, IR_NULL, prop_info_ref, ir_CONST_U32(flags))); |
16149 | 0 | ir_IF_FALSE_cold(if_ok); |
16150 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_exception_handler_undef)); |
16151 | 0 | ir_IF_TRUE(if_ok); |
16152 | 0 | if (!known_prop_info) { |
16153 | 0 | ir_END_list(merge); |
16154 | 0 | ir_MERGE_list(merge); |
16155 | 0 | } |
16156 | 0 | } |
16157 | 0 | } |
16158 | |
|
16159 | 0 | fast_path = ir_END(); |
16160 | |
|
16161 | 0 | ir_IF_FALSE_cold(if_cached); |
16162 | 0 | jit_SET_EX_OPLINE(jit, opline); |
16163 | 0 | ref2 = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(zend_fetch_static_property), jit_FP(jit), ir_CONST_I32(fetch_type)); |
16164 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
16165 | 0 | cold_path = ir_END(); |
16166 | |
|
16167 | 0 | ir_MERGE_2(fast_path, cold_path); |
16168 | 0 | ref = ir_PHI_2(IR_ADDR, ref, ref2); |
16169 | |
|
16170 | 0 | if (fetch_type == BP_VAR_R || fetch_type == BP_VAR_IS) { |
16171 | | // JIT: ZVAL_COPY_DEREF(EX_VAR(opline->result.var), result); |
16172 | 0 | if (!zend_jit_zval_copy_deref(jit, res_addr, ZEND_ADDR_REF_ZVAL(ref), |
16173 | 0 | jit_Z_TYPE_INFO_ref(jit, ref))) { |
16174 | 0 | return 0; |
16175 | 0 | } |
16176 | 0 | } else { |
16177 | | // JIT: ZVAL_INDIRECT(EX_VAR(opline->result.var), result); |
16178 | 0 | jit_set_Z_PTR(jit, res_addr, ref); |
16179 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_INDIRECT); |
16180 | 0 | } |
16181 | | |
16182 | 0 | return 1; |
16183 | 0 | } |
16184 | | |
16185 | | static int zend_jit_switch(zend_jit_ctx *jit, const zend_op *opline, const zend_op_array *op_array, zend_ssa *ssa, zend_jit_trace_rec *trace, zend_jit_trace_info *trace_info) |
16186 | 0 | { |
16187 | 0 | HashTable *jumptable = Z_ARRVAL_P(RT_CONSTANT(opline, opline->op2)); |
16188 | 0 | const zend_op *next_opline = NULL; |
16189 | 0 | ir_refs *slow_inputs; |
16190 | |
|
16191 | 0 | ir_refs_init(slow_inputs, 8); |
16192 | |
|
16193 | 0 | if (trace) { |
16194 | 0 | ZEND_ASSERT(trace->op == ZEND_JIT_TRACE_VM || trace->op == ZEND_JIT_TRACE_END); |
16195 | 0 | ZEND_ASSERT(trace->opline != NULL); |
16196 | 0 | next_opline = trace->opline; |
16197 | 0 | } |
16198 | |
|
16199 | 0 | if (opline->op1_type == IS_CONST) { |
16200 | 0 | zval *zv = RT_CONSTANT(opline, opline->op1); |
16201 | 0 | zval *jump_zv = NULL; |
16202 | 0 | int b; |
16203 | |
|
16204 | 0 | if (opline->opcode == ZEND_SWITCH_LONG) { |
16205 | 0 | if (Z_TYPE_P(zv) == IS_LONG) { |
16206 | 0 | jump_zv = zend_hash_index_find(jumptable, Z_LVAL_P(zv)); |
16207 | 0 | } |
16208 | 0 | } else if (opline->opcode == ZEND_SWITCH_STRING) { |
16209 | 0 | if (Z_TYPE_P(zv) == IS_STRING) { |
16210 | 0 | jump_zv = zend_hash_find_known_hash(jumptable, Z_STR_P(zv)); |
16211 | 0 | } |
16212 | 0 | } else if (opline->opcode == ZEND_MATCH) { |
16213 | 0 | if (Z_TYPE_P(zv) == IS_LONG) { |
16214 | 0 | jump_zv = zend_hash_index_find(jumptable, Z_LVAL_P(zv)); |
16215 | 0 | } else if (Z_TYPE_P(zv) == IS_STRING) { |
16216 | 0 | jump_zv = zend_hash_find_known_hash(jumptable, Z_STR_P(zv)); |
16217 | 0 | } |
16218 | 0 | } else { |
16219 | 0 | ZEND_UNREACHABLE(); |
16220 | 0 | } |
16221 | 0 | if (next_opline) { |
16222 | 0 | const zend_op *target; |
16223 | |
|
16224 | 0 | if (jump_zv != NULL) { |
16225 | 0 | target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(jump_zv)); |
16226 | 0 | } else { |
16227 | 0 | target = ZEND_OFFSET_TO_OPLINE(opline, opline->extended_value); |
16228 | 0 | } |
16229 | 0 | ZEND_ASSERT(target == next_opline); |
16230 | 0 | } else { |
16231 | 0 | if (jump_zv != NULL) { |
16232 | 0 | b = ssa->cfg.map[ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(jump_zv)) - op_array->opcodes]; |
16233 | 0 | } else { |
16234 | 0 | b = ssa->cfg.map[ZEND_OFFSET_TO_OPLINE(opline, opline->extended_value) - op_array->opcodes]; |
16235 | 0 | } |
16236 | 0 | _zend_jit_add_predecessor_ref(jit, b, jit->b, ir_END()); |
16237 | 0 | jit->b = -1; |
16238 | 0 | } |
16239 | 0 | } else { |
16240 | 0 | zend_ssa_op *ssa_op = ssa->ops ? &ssa->ops[opline - op_array->opcodes] : NULL; |
16241 | 0 | uint32_t op1_info = OP1_INFO(); |
16242 | 0 | zend_jit_addr op1_addr = OP1_ADDR(); |
16243 | 0 | const zend_op *default_opline = ZEND_OFFSET_TO_OPLINE(opline, opline->extended_value); |
16244 | 0 | const zend_op *target; |
16245 | 0 | int default_b = next_opline ? -1 : ssa->cfg.map[default_opline - op_array->opcodes]; |
16246 | 0 | int b; |
16247 | 0 | int32_t exit_point; |
16248 | 0 | const void *exit_addr; |
16249 | 0 | const void *default_label = NULL; |
16250 | 0 | zval *zv; |
16251 | |
|
16252 | 0 | if (next_opline) { |
16253 | 0 | if (next_opline != default_opline) { |
16254 | 0 | exit_point = zend_jit_trace_get_exit_point(default_opline, 0); |
16255 | 0 | default_label = zend_jit_trace_get_exit_addr(exit_point); |
16256 | 0 | if (!default_label) { |
16257 | 0 | return 0; |
16258 | 0 | } |
16259 | 0 | } |
16260 | 0 | } |
16261 | | |
16262 | 0 | if (opline->opcode == ZEND_SWITCH_LONG) { |
16263 | 0 | if (op1_info & MAY_BE_LONG) { |
16264 | 0 | const void *fallback_label = NULL; |
16265 | |
|
16266 | 0 | if (next_opline) { |
16267 | 0 | if (next_opline != opline + 1) { |
16268 | 0 | exit_point = zend_jit_trace_get_exit_point(opline + 1, 0); |
16269 | 0 | fallback_label = zend_jit_trace_get_exit_addr(exit_point); |
16270 | 0 | if (!fallback_label) { |
16271 | 0 | return 0; |
16272 | 0 | } |
16273 | 0 | } |
16274 | 0 | } |
16275 | 0 | if (op1_info & MAY_BE_REF) { |
16276 | 0 | ir_ref ref, if_long, fast_path, ref2; |
16277 | |
|
16278 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
16279 | 0 | if_long = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
16280 | 0 | ir_IF_TRUE(if_long); |
16281 | 0 | fast_path = ir_END(); |
16282 | 0 | ir_IF_FALSE_cold(if_long); |
16283 | | |
16284 | | // JIT: ZVAL_DEREF(op) |
16285 | 0 | if (fallback_label) { |
16286 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_REFERENCE, fallback_label); |
16287 | 0 | } else { |
16288 | 0 | ir_ref if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_REFERENCE); |
16289 | 0 | ir_IF_FALSE_cold(if_ref); |
16290 | 0 | ir_refs_add(slow_inputs, ir_END()); |
16291 | 0 | ir_IF_TRUE(if_ref); |
16292 | 0 | } |
16293 | |
|
16294 | 0 | ref2 = ir_ADD_OFFSET(jit_Z_PTR(jit, op1_addr), offsetof(zend_reference, val)); |
16295 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref2); |
16296 | |
|
16297 | 0 | if (fallback_label) { |
16298 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_LONG, fallback_label); |
16299 | 0 | } else { |
16300 | 0 | if_long = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
16301 | 0 | ir_IF_FALSE_cold(if_long); |
16302 | 0 | ir_refs_add(slow_inputs, ir_END()); |
16303 | 0 | ir_IF_TRUE(if_long); |
16304 | 0 | } |
16305 | |
|
16306 | 0 | ir_MERGE_2(fast_path, ir_END()); |
16307 | 0 | ref = ir_PHI_2(IR_ADDR, ref, ref2); |
16308 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
16309 | 0 | } else if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) { |
16310 | 0 | if (fallback_label) { |
16311 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_LONG, fallback_label); |
16312 | 0 | } else { |
16313 | 0 | ir_ref if_long = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
16314 | 0 | ir_IF_FALSE_cold(if_long); |
16315 | 0 | ir_refs_add(slow_inputs, ir_END()); |
16316 | 0 | ir_IF_TRUE(if_long); |
16317 | 0 | } |
16318 | 0 | } |
16319 | 0 | ir_ref ref = jit_Z_LVAL(jit, op1_addr); |
16320 | |
|
16321 | 0 | if (!HT_IS_PACKED(jumptable)) { |
16322 | 0 | ref = ir_CALL_2(IR_LONG, ir_CONST_FC_FUNC(zend_hash_index_find), |
16323 | 0 | ir_CONST_ADDR(jumptable), ref); |
16324 | 0 | ref = ir_SUB_L(ref, ir_CONST_LONG((uintptr_t)jumptable->arData)); |
16325 | | /* Signed DIV by power of 2 may be optimized into SHR only for positive operands */ |
16326 | 0 | if (sizeof(Bucket) == 32) { |
16327 | 0 | ref = ir_SHR_L(ref, ir_CONST_LONG(5)); |
16328 | 0 | } else { |
16329 | 0 | ref = ir_DIV_L(ref, ir_CONST_LONG(sizeof(Bucket))); |
16330 | 0 | } |
16331 | 0 | } |
16332 | 0 | ref = ir_SWITCH(ref); |
16333 | |
|
16334 | 0 | if (next_opline) { |
16335 | 0 | ir_ref continue_list = IR_UNUSED; |
16336 | |
|
16337 | 0 | ZEND_HASH_FOREACH_VAL(jumptable, zv) { |
16338 | 0 | ir_ref idx; |
16339 | 0 | target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(zv)); |
16340 | |
|
16341 | 0 | if (HT_IS_PACKED(jumptable)) { |
16342 | 0 | idx = ir_CONST_LONG(zv - jumptable->arPacked); |
16343 | 0 | } else { |
16344 | 0 | idx = ir_CONST_LONG((Bucket*)zv - jumptable->arData); |
16345 | 0 | } |
16346 | 0 | ir_CASE_VAL(ref, idx); |
16347 | 0 | if (target == next_opline) { |
16348 | 0 | ir_END_list(continue_list); |
16349 | 0 | } else { |
16350 | 0 | exit_point = zend_jit_trace_get_exit_point(target, 0); |
16351 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
16352 | 0 | if (!exit_addr) { |
16353 | 0 | return 0; |
16354 | 0 | } |
16355 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
16356 | 0 | } |
16357 | 0 | } ZEND_HASH_FOREACH_END(); |
16358 | | |
16359 | 0 | ir_CASE_DEFAULT(ref); |
16360 | 0 | if (next_opline == default_opline) { |
16361 | 0 | ir_END_list(continue_list); |
16362 | 0 | } else { |
16363 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(default_label)); |
16364 | 0 | } |
16365 | 0 | if (continue_list) { |
16366 | 0 | ir_MERGE_list(continue_list); |
16367 | 0 | } else { |
16368 | 0 | ZEND_ASSERT(slow_inputs->count); |
16369 | 0 | ir_MERGE_N(slow_inputs->count, slow_inputs->refs); |
16370 | 0 | } |
16371 | 0 | } else { |
16372 | 0 | ZEND_HASH_FOREACH_VAL(jumptable, zv) { |
16373 | 0 | target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(zv)); |
16374 | 0 | b = ssa->cfg.map[target - op_array->opcodes]; |
16375 | 0 | _zend_jit_add_predecessor_ref(jit, b, jit->b, ref); |
16376 | 0 | } ZEND_HASH_FOREACH_END(); |
16377 | |
|
16378 | 0 | _zend_jit_add_predecessor_ref(jit, default_b, jit->b, ref); |
16379 | 0 | if (slow_inputs->count) { |
16380 | 0 | ir_MERGE_N(slow_inputs->count, slow_inputs->refs); |
16381 | 0 | _zend_jit_add_predecessor_ref(jit, jit->b + 1, jit->b, ir_END()); |
16382 | 0 | } |
16383 | 0 | jit->b = -1; |
16384 | 0 | } |
16385 | 0 | } else if (!next_opline) { |
16386 | 0 | _zend_jit_add_predecessor_ref(jit, jit->b + 1, jit->b, ir_END()); |
16387 | 0 | jit->b = -1; |
16388 | 0 | } |
16389 | 0 | } else if (opline->opcode == ZEND_SWITCH_STRING) { |
16390 | 0 | if (op1_info & MAY_BE_STRING) { |
16391 | 0 | const void *fallback_label = NULL; |
16392 | |
|
16393 | 0 | if (next_opline) { |
16394 | 0 | if (next_opline != opline + 1) { |
16395 | 0 | exit_point = zend_jit_trace_get_exit_point(opline + 1, 0); |
16396 | 0 | fallback_label = zend_jit_trace_get_exit_addr(exit_point); |
16397 | 0 | if (!fallback_label) { |
16398 | 0 | return 0; |
16399 | 0 | } |
16400 | 0 | } |
16401 | 0 | } |
16402 | 0 | if (op1_info & MAY_BE_REF) { |
16403 | 0 | ir_ref ref, if_string, fast_path, ref2; |
16404 | |
|
16405 | 0 | ref = jit_ZVAL_ADDR(jit, op1_addr); |
16406 | 0 | if_string = jit_if_Z_TYPE(jit, op1_addr, IS_STRING); |
16407 | 0 | ir_IF_TRUE(if_string); |
16408 | 0 | fast_path = ir_END(); |
16409 | 0 | ir_IF_FALSE_cold(if_string); |
16410 | | |
16411 | | // JIT: ZVAL_DEREF(op) |
16412 | 0 | if (fallback_label) { |
16413 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_REFERENCE, fallback_label); |
16414 | 0 | } else { |
16415 | 0 | ir_ref if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_STRING); |
16416 | 0 | ir_IF_FALSE_cold(if_ref); |
16417 | 0 | ir_refs_add(slow_inputs, ir_END()); |
16418 | 0 | ir_IF_TRUE(if_ref); |
16419 | 0 | } |
16420 | |
|
16421 | 0 | ref2 = ir_ADD_OFFSET(jit_Z_PTR(jit, op1_addr), offsetof(zend_reference, val)); |
16422 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref2); |
16423 | |
|
16424 | 0 | if (fallback_label) { |
16425 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_LONG, fallback_label); |
16426 | 0 | } else { |
16427 | 0 | if_string = jit_if_Z_TYPE(jit, op1_addr, IS_STRING); |
16428 | 0 | ir_IF_FALSE_cold(if_string); |
16429 | 0 | ir_refs_add(slow_inputs, ir_END()); |
16430 | 0 | ir_IF_TRUE(if_string); |
16431 | 0 | } |
16432 | |
|
16433 | 0 | ir_MERGE_2(fast_path, ir_END()); |
16434 | 0 | ref = ir_PHI_2(IR_ADDR, ref, ref2); |
16435 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(ref); |
16436 | 0 | } else if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_STRING)) { |
16437 | 0 | if (fallback_label) { |
16438 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_STRING, fallback_label); |
16439 | 0 | } else { |
16440 | 0 | ir_ref if_string = jit_if_Z_TYPE(jit, op1_addr, IS_STRING); |
16441 | 0 | ir_IF_FALSE_cold(if_string); |
16442 | 0 | ir_refs_add(slow_inputs, ir_END()); |
16443 | 0 | ir_IF_TRUE(if_string); |
16444 | 0 | } |
16445 | 0 | } |
16446 | |
|
16447 | 0 | ir_ref ref = jit_Z_PTR(jit, op1_addr); |
16448 | 0 | ref = ir_CALL_2(IR_LONG, ir_CONST_FC_FUNC(zend_hash_find), |
16449 | 0 | ir_CONST_ADDR(jumptable), ref); |
16450 | 0 | ref = ir_SUB_L(ref, ir_CONST_LONG((uintptr_t)jumptable->arData)); |
16451 | | /* Signed DIV by power of 2 may be optimized into SHR only for positive operands */ |
16452 | 0 | if (sizeof(Bucket) == 32) { |
16453 | 0 | ref = ir_SHR_L(ref, ir_CONST_LONG(5)); |
16454 | 0 | } else { |
16455 | 0 | ref = ir_DIV_L(ref, ir_CONST_LONG(sizeof(Bucket))); |
16456 | 0 | } |
16457 | 0 | ref = ir_SWITCH(ref); |
16458 | |
|
16459 | 0 | if (next_opline) { |
16460 | 0 | ir_ref continue_list = IR_UNUSED; |
16461 | |
|
16462 | 0 | ZEND_HASH_FOREACH_VAL(jumptable, zv) { |
16463 | 0 | ir_ref idx; |
16464 | 0 | target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(zv)); |
16465 | |
|
16466 | 0 | if (HT_IS_PACKED(jumptable)) { |
16467 | 0 | idx = ir_CONST_LONG(zv - jumptable->arPacked); |
16468 | 0 | } else { |
16469 | 0 | idx = ir_CONST_LONG((Bucket*)zv - jumptable->arData); |
16470 | 0 | } |
16471 | 0 | ir_CASE_VAL(ref, idx); |
16472 | 0 | if (target == next_opline) { |
16473 | 0 | ir_END_list(continue_list); |
16474 | 0 | } else { |
16475 | 0 | exit_point = zend_jit_trace_get_exit_point(target, 0); |
16476 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
16477 | 0 | if (!exit_addr) { |
16478 | 0 | return 0; |
16479 | 0 | } |
16480 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
16481 | 0 | } |
16482 | 0 | } ZEND_HASH_FOREACH_END(); |
16483 | | |
16484 | 0 | ir_CASE_DEFAULT(ref); |
16485 | 0 | if (next_opline == default_opline) { |
16486 | 0 | ir_END_list(continue_list); |
16487 | 0 | } else { |
16488 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(default_label)); |
16489 | 0 | } |
16490 | 0 | if (continue_list) { |
16491 | 0 | ir_MERGE_list(continue_list); |
16492 | 0 | } else { |
16493 | 0 | ZEND_ASSERT(slow_inputs->count); |
16494 | 0 | ir_MERGE_N(slow_inputs->count, slow_inputs->refs); |
16495 | 0 | } |
16496 | 0 | } else { |
16497 | 0 | ZEND_HASH_FOREACH_VAL(jumptable, zv) { |
16498 | 0 | target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(zv)); |
16499 | 0 | b = ssa->cfg.map[target - op_array->opcodes]; |
16500 | 0 | _zend_jit_add_predecessor_ref(jit, b, jit->b, ref); |
16501 | 0 | } ZEND_HASH_FOREACH_END(); |
16502 | 0 | _zend_jit_add_predecessor_ref(jit, default_b, jit->b, ref); |
16503 | 0 | if (slow_inputs->count) { |
16504 | 0 | ir_MERGE_N(slow_inputs->count, slow_inputs->refs); |
16505 | 0 | _zend_jit_add_predecessor_ref(jit, jit->b + 1, jit->b, ir_END()); |
16506 | 0 | } |
16507 | 0 | jit->b = -1; |
16508 | 0 | } |
16509 | 0 | } else if (!next_opline) { |
16510 | 0 | _zend_jit_add_predecessor_ref(jit, jit->b + 1, jit->b, ir_END()); |
16511 | 0 | jit->b = -1; |
16512 | 0 | } |
16513 | 0 | } else if (opline->opcode == ZEND_MATCH) { |
16514 | 0 | ir_ref if_type = IR_UNUSED, default_input_list = IR_UNUSED, ref = IR_UNUSED; |
16515 | 0 | ir_ref continue_list = IR_UNUSED; |
16516 | |
|
16517 | 0 | if (op1_info & (MAY_BE_LONG|MAY_BE_STRING)) { |
16518 | 0 | ir_ref long_path = IR_UNUSED; |
16519 | |
|
16520 | 0 | if (op1_info & MAY_BE_REF) { |
16521 | 0 | op1_addr = jit_ZVAL_DEREF(jit, op1_addr); |
16522 | 0 | } |
16523 | 0 | if (op1_info & MAY_BE_LONG) { |
16524 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) { |
16525 | 0 | if (op1_info & (MAY_BE_STRING|MAY_BE_UNDEF)) { |
16526 | 0 | if_type = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
16527 | 0 | ir_IF_TRUE(if_type); |
16528 | 0 | } else if (default_label) { |
16529 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_LONG, default_label); |
16530 | 0 | } else if (next_opline) { |
16531 | 0 | ir_ref if_type = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
16532 | 0 | ir_IF_FALSE(if_type); |
16533 | 0 | ir_END_list(continue_list); |
16534 | 0 | ir_IF_TRUE(if_type); |
16535 | 0 | } else { |
16536 | 0 | ir_ref if_type = jit_if_Z_TYPE(jit, op1_addr, IS_LONG); |
16537 | 0 | ir_IF_FALSE(if_type); |
16538 | 0 | ir_END_list(default_input_list); |
16539 | 0 | ir_IF_TRUE(if_type); |
16540 | 0 | } |
16541 | 0 | } |
16542 | 0 | ref = jit_Z_LVAL(jit, op1_addr); |
16543 | 0 | ref = ir_CALL_2(IR_LONG, ir_CONST_FC_FUNC(zend_hash_index_find), |
16544 | 0 | ir_CONST_ADDR(jumptable), ref); |
16545 | 0 | if (op1_info & MAY_BE_STRING) { |
16546 | 0 | long_path = ir_END(); |
16547 | 0 | } |
16548 | 0 | } |
16549 | 0 | if (op1_info & MAY_BE_STRING) { |
16550 | 0 | if (if_type) { |
16551 | 0 | ir_IF_FALSE(if_type); |
16552 | 0 | if_type = IS_UNUSED; |
16553 | 0 | } |
16554 | 0 | if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_STRING))) { |
16555 | 0 | if (op1_info & MAY_BE_UNDEF) { |
16556 | 0 | if_type = jit_if_Z_TYPE(jit, op1_addr, IS_STRING); |
16557 | 0 | ir_IF_TRUE(if_type); |
16558 | 0 | } else if (default_label) { |
16559 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_STRING, default_label); |
16560 | 0 | } else if (next_opline) { |
16561 | 0 | ir_ref if_type = jit_if_Z_TYPE(jit, op1_addr, IS_STRING); |
16562 | 0 | ir_IF_FALSE(if_type); |
16563 | 0 | ir_END_list(continue_list); |
16564 | 0 | ir_IF_TRUE(if_type); |
16565 | 0 | } else { |
16566 | 0 | ir_ref if_type = jit_if_Z_TYPE(jit, op1_addr, IS_STRING); |
16567 | 0 | ir_IF_FALSE(if_type); |
16568 | 0 | ir_END_list(default_input_list); |
16569 | 0 | ir_IF_TRUE(if_type); |
16570 | 0 | } |
16571 | 0 | } |
16572 | 0 | ir_ref ref2 = jit_Z_PTR(jit, op1_addr); |
16573 | 0 | ref2 = ir_CALL_2(IR_LONG, ir_CONST_FC_FUNC(zend_hash_find), |
16574 | 0 | ir_CONST_ADDR(jumptable), ref2); |
16575 | 0 | if (op1_info & MAY_BE_LONG) { |
16576 | 0 | ir_MERGE_WITH(long_path); |
16577 | 0 | ref = ir_PHI_2(IR_LONG, ref2, ref); |
16578 | 0 | } else { |
16579 | 0 | ref = ref2; |
16580 | 0 | } |
16581 | 0 | } |
16582 | |
|
16583 | 0 | ref = ir_SUB_L(ref, ir_CONST_LONG((uintptr_t)jumptable->arData)); |
16584 | | /* Signed DIV by power of 2 may be optimized into SHR only for positive operands */ |
16585 | 0 | if (HT_IS_PACKED(jumptable)) { |
16586 | 0 | ZEND_ASSERT(sizeof(zval) == 16); |
16587 | 0 | ref = ir_SHR_L(ref, ir_CONST_LONG(4)); |
16588 | 0 | } else { |
16589 | 0 | if (sizeof(Bucket) == 32) { |
16590 | 0 | ref = ir_SHR_L(ref, ir_CONST_LONG(5)); |
16591 | 0 | } else { |
16592 | 0 | ref = ir_DIV_L(ref, ir_CONST_LONG(sizeof(Bucket))); |
16593 | 0 | } |
16594 | 0 | } |
16595 | 0 | ref = ir_SWITCH(ref); |
16596 | |
|
16597 | 0 | if (next_opline) { |
16598 | 0 | ZEND_HASH_FOREACH_VAL(jumptable, zv) { |
16599 | 0 | ir_ref idx; |
16600 | 0 | target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(zv)); |
16601 | |
|
16602 | 0 | if (HT_IS_PACKED(jumptable)) { |
16603 | 0 | idx = ir_CONST_LONG(zv - jumptable->arPacked); |
16604 | 0 | } else { |
16605 | 0 | idx = ir_CONST_LONG((Bucket*)zv - jumptable->arData); |
16606 | 0 | } |
16607 | 0 | ir_CASE_VAL(ref, idx); |
16608 | 0 | if (target == next_opline) { |
16609 | 0 | ir_END_list(continue_list); |
16610 | 0 | } else { |
16611 | 0 | exit_point = zend_jit_trace_get_exit_point(target, 0); |
16612 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
16613 | 0 | if (!exit_addr) { |
16614 | 0 | return 0; |
16615 | 0 | } |
16616 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(exit_addr)); |
16617 | 0 | } |
16618 | 0 | } ZEND_HASH_FOREACH_END(); |
16619 | | |
16620 | 0 | ir_CASE_DEFAULT(ref); |
16621 | 0 | if (next_opline == default_opline) { |
16622 | 0 | ir_END_list(continue_list); |
16623 | 0 | } else { |
16624 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(default_label)); |
16625 | 0 | } |
16626 | 0 | } else { |
16627 | 0 | ZEND_HASH_FOREACH_VAL(jumptable, zv) { |
16628 | 0 | target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(zv)); |
16629 | 0 | b = ssa->cfg.map[target - op_array->opcodes]; |
16630 | 0 | _zend_jit_add_predecessor_ref(jit, b, jit->b, ref); |
16631 | 0 | } ZEND_HASH_FOREACH_END(); |
16632 | 0 | _zend_jit_add_predecessor_ref(jit, default_b, jit->b, ref); |
16633 | 0 | } |
16634 | 0 | } else if (!(op1_info & MAY_BE_UNDEF)) { |
16635 | 0 | if (next_opline) { |
16636 | 0 | if (next_opline == default_opline) { |
16637 | 0 | ir_END_list(continue_list); |
16638 | 0 | } else { |
16639 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(default_label)); |
16640 | 0 | } |
16641 | 0 | } else { |
16642 | 0 | _zend_jit_add_predecessor_ref(jit, default_b, jit->b, ir_END()); |
16643 | 0 | } |
16644 | 0 | } |
16645 | | |
16646 | 0 | if (op1_info & MAY_BE_UNDEF) { |
16647 | 0 | if (if_type) { |
16648 | 0 | ir_IF_FALSE(if_type); |
16649 | 0 | if_type = IS_UNUSED; |
16650 | 0 | } |
16651 | 0 | if (op1_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_STRING))) { |
16652 | 0 | if (default_label) { |
16653 | 0 | jit_guard_Z_TYPE(jit, op1_addr, IS_UNDEF, default_label); |
16654 | 0 | } else if (next_opline) { |
16655 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE(jit, op1_addr)); |
16656 | 0 | ir_IF_TRUE(if_def); |
16657 | 0 | ir_END_list(continue_list); |
16658 | 0 | ir_IF_FALSE_cold(if_def); |
16659 | 0 | } else { |
16660 | 0 | ir_ref if_def = ir_IF(jit_Z_TYPE(jit, op1_addr)); |
16661 | 0 | ir_IF_TRUE(if_def); |
16662 | 0 | ir_END_list(default_input_list); |
16663 | 0 | ir_IF_FALSE_cold(if_def); |
16664 | 0 | } |
16665 | 0 | } |
16666 | |
|
16667 | 0 | jit_SET_EX_OPLINE(jit, opline); |
16668 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), |
16669 | 0 | ir_CONST_U32(opline->op1.var)); |
16670 | 0 | zend_jit_check_exception_undef_result(jit, opline); |
16671 | 0 | if (default_label) { |
16672 | 0 | jit_SIDE_EXIT(jit, ir_CONST_ADDR(default_label)); |
16673 | 0 | } else if (next_opline) { |
16674 | 0 | ir_END_list(continue_list); |
16675 | 0 | } else { |
16676 | 0 | ir_END_list(default_input_list); |
16677 | 0 | } |
16678 | 0 | } |
16679 | 0 | if (next_opline) { |
16680 | 0 | ZEND_ASSERT(continue_list); |
16681 | 0 | ir_MERGE_list(continue_list); |
16682 | 0 | } else { |
16683 | 0 | if (default_input_list) { |
16684 | 0 | if (jit->ctx.ir_base[ref].op == IR_SWITCH) { |
16685 | 0 | ZEND_ASSERT(jit->ctx.ir_base[ref].op3 == IR_UNUSED); |
16686 | 0 | jit->ctx.ir_base[ref].op3 = default_input_list; |
16687 | 0 | } else { |
16688 | 0 | ir_MERGE_list(default_input_list); |
16689 | 0 | _zend_jit_add_predecessor_ref(jit, default_b, jit->b, ir_END()); |
16690 | 0 | } |
16691 | 0 | } |
16692 | 0 | jit->b = -1; |
16693 | 0 | } |
16694 | 0 | } else { |
16695 | 0 | ZEND_UNREACHABLE(); |
16696 | 0 | } |
16697 | 0 | } |
16698 | 0 | return 1; |
16699 | 0 | } |
16700 | | |
16701 | | static int zend_jit_start(zend_jit_ctx *jit, const zend_op_array *op_array, zend_ssa *ssa) |
16702 | 0 | { |
16703 | 0 | uint32_t i, count; |
16704 | 0 | zend_basic_block *bb; |
16705 | |
|
16706 | 0 | zend_jit_init_ctx(jit, (ZEND_VM_KIND == ZEND_VM_KIND_CALL || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) ? 0 : (IR_START_BR_TARGET|IR_ENTRY_BR_TARGET)); |
16707 | |
|
16708 | 0 | jit->ctx.spill_base = ZREG_FP; |
16709 | |
|
16710 | 0 | jit->op_array = jit->current_op_array = op_array; |
16711 | 0 | jit->ssa = ssa; |
16712 | 0 | jit->bb_start_ref = zend_arena_calloc(&CG(arena), ssa->cfg.blocks_count * 2, sizeof(ir_ref)); |
16713 | 0 | jit->bb_predecessors = jit->bb_start_ref + ssa->cfg.blocks_count; |
16714 | |
|
16715 | 0 | count = 0; |
16716 | 0 | for (i = 0, bb = ssa->cfg.blocks; i < ssa->cfg.blocks_count; i++, bb++) { |
16717 | 0 | jit->bb_predecessors[i] = count; |
16718 | 0 | count += bb->predecessors_count; |
16719 | 0 | } |
16720 | 0 | jit->bb_edges = zend_arena_calloc(&CG(arena), count, sizeof(ir_ref)); |
16721 | |
|
16722 | 0 | if (!GCC_GLOBAL_REGS) { |
16723 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_TAILCALL) { |
16724 | 0 | ir_ref execute_data_ref = ir_PARAM(IR_ADDR, "execute_data", 1); |
16725 | 0 | ir_ref opline_ref = ir_PARAM(IR_ADDR, "opline", 2); |
16726 | 0 | jit_STORE_FP(jit, execute_data_ref); |
16727 | 0 | jit_STORE_IP(jit, opline_ref); |
16728 | 0 | } |
16729 | 0 | jit->ctx.flags |= IR_FASTCALL_FUNC; |
16730 | 0 | } |
16731 | |
|
16732 | 0 | return 1; |
16733 | 0 | } |
16734 | | |
16735 | | static zend_vm_opcode_handler_t zend_jit_finish(zend_jit_ctx *jit) |
16736 | 0 | { |
16737 | 0 | void *entry; |
16738 | 0 | size_t size; |
16739 | 0 | zend_string *str = NULL; |
16740 | |
|
16741 | 0 | if (JIT_G(debug) & (ZEND_JIT_DEBUG_ASM|ZEND_JIT_DEBUG_GDB|ZEND_JIT_DEBUG_PERF|ZEND_JIT_DEBUG_PERF_DUMP| |
16742 | 0 | ZEND_JIT_DEBUG_IR_SRC|ZEND_JIT_DEBUG_IR_AFTER_SCCP|ZEND_JIT_DEBUG_IR_AFTER_SCCP| |
16743 | 0 | ZEND_JIT_DEBUG_IR_AFTER_SCHEDULE|ZEND_JIT_DEBUG_IR_AFTER_REGS|ZEND_JIT_DEBUG_IR_FINAL|ZEND_JIT_DEBUG_IR_CODEGEN)) { |
16744 | 0 | if (jit->name) { |
16745 | 0 | str = zend_string_copy(jit->name); |
16746 | 0 | } else { |
16747 | 0 | str = zend_jit_func_name(jit->op_array); |
16748 | 0 | } |
16749 | 0 | } |
16750 | |
|
16751 | 0 | if (jit->op_array) { |
16752 | | /* Only for function JIT */ |
16753 | 0 | _zend_jit_fix_merges(jit); |
16754 | | #if defined(IR_TARGET_AARCH64) |
16755 | | } else if (jit->trace) { |
16756 | | jit->ctx.deoptimization_exits = jit->trace->exit_count; |
16757 | | jit->ctx.get_exit_addr = zend_jit_trace_get_exit_addr; |
16758 | | #endif |
16759 | 0 | } else { |
16760 | 0 | #if defined(IR_TARGET_X86) || defined(IR_TARGET_X64) |
16761 | 0 | jit->ctx.flags |= IR_GEN_CACHE_DEMOTE; |
16762 | 0 | #endif |
16763 | 0 | } |
16764 | |
|
16765 | 0 | entry = zend_jit_ir_compile(&jit->ctx, &size, str ? ZSTR_VAL(str) : NULL); |
16766 | 0 | if (entry) { |
16767 | 0 | if (JIT_G(debug) & (ZEND_JIT_DEBUG_ASM|ZEND_JIT_DEBUG_GDB|ZEND_JIT_DEBUG_PERF|ZEND_JIT_DEBUG_PERF_DUMP)) { |
16768 | | #ifdef HAVE_CAPSTONE |
16769 | | if (JIT_G(debug) & ZEND_JIT_DEBUG_ASM) { |
16770 | | if (str) { |
16771 | | ir_disasm_add_symbol(ZSTR_VAL(str), (uintptr_t)entry, size); |
16772 | | } |
16773 | | ir_disasm(str ? ZSTR_VAL(str) : "unknown", |
16774 | | entry, size, |
16775 | | (JIT_G(debug) & ZEND_JIT_DEBUG_ASM_ADDR) != 0, |
16776 | | &jit->ctx, stderr); |
16777 | | } |
16778 | | #endif |
16779 | 0 | #ifndef _WIN32 |
16780 | 0 | if (str) { |
16781 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_GDB) { |
16782 | 0 | uintptr_t sp_offset = 0; |
16783 | | |
16784 | | // ir_mem_unprotect(entry, size); |
16785 | 0 | if (!(jit->ctx.flags & IR_FUNCTION) |
16786 | 0 | && ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) { |
16787 | 0 | #if !defined(ZEND_WIN32) && !defined(IR_TARGET_AARCH64) |
16788 | 0 | sp_offset = zend_jit_hybrid_vm_sp_adj; |
16789 | | #else |
16790 | | sp_offset = sizeof(void*); |
16791 | | #endif |
16792 | 0 | } else { |
16793 | 0 | sp_offset = sizeof(void*); |
16794 | 0 | } |
16795 | 0 | ir_gdb_register(ZSTR_VAL(str), entry, size, sp_offset, 0); |
16796 | | // ir_mem_protect(entry, size); |
16797 | 0 | } |
16798 | |
|
16799 | 0 | if (JIT_G(debug) & (ZEND_JIT_DEBUG_PERF|ZEND_JIT_DEBUG_PERF_DUMP)) { |
16800 | 0 | ir_perf_map_register(ZSTR_VAL(str), entry, size); |
16801 | 0 | if (JIT_G(debug) & ZEND_JIT_DEBUG_PERF_DUMP) { |
16802 | 0 | ir_perf_jitdump_register(ZSTR_VAL(str), entry, size); |
16803 | 0 | } |
16804 | 0 | } |
16805 | 0 | } |
16806 | 0 | #endif |
16807 | 0 | } |
16808 | |
|
16809 | 0 | if (jit->op_array) { |
16810 | | /* Only for function JIT */ |
16811 | 0 | const zend_op_array *op_array = jit->op_array; |
16812 | 0 | zend_op *opline = (zend_op*)op_array->opcodes; |
16813 | |
|
16814 | 0 | if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) { |
16815 | 0 | while (opline->opcode == ZEND_RECV) { |
16816 | 0 | opline++; |
16817 | 0 | } |
16818 | 0 | } |
16819 | 0 | opline->handler = (zend_vm_opcode_handler_t)entry; |
16820 | |
|
16821 | 0 | if (jit->ctx.entries_count) { |
16822 | | /* For all entries */ |
16823 | 0 | int i = jit->ctx.entries_count; |
16824 | 0 | do { |
16825 | 0 | ir_insn *insn = &jit->ctx.ir_base[jit->ctx.entries[--i]]; |
16826 | 0 | op_array->opcodes[insn->op2].handler = (zend_vm_opcode_handler_t)((char*)entry + insn->op3); |
16827 | 0 | } while (i != 0); |
16828 | 0 | } |
16829 | 0 | } else { |
16830 | | /* Only for tracing JIT */ |
16831 | 0 | zend_jit_trace_info *t = jit->trace; |
16832 | 0 | zend_jit_trace_stack *stack; |
16833 | 0 | uint32_t i; |
16834 | |
|
16835 | 0 | if (t) { |
16836 | 0 | for (i = 0; i < t->stack_map_size; i++) { |
16837 | 0 | stack = t->stack_map + i; |
16838 | 0 | if (stack->flags & ZREG_SPILL_SLOT) { |
16839 | 0 | stack->reg = (jit->ctx.flags & IR_USE_FRAME_POINTER) ? IR_REG_FP : IR_REG_SP; |
16840 | 0 | stack->ref = ir_get_spill_slot_offset(&jit->ctx, stack->ref); |
16841 | 0 | } |
16842 | 0 | } |
16843 | 0 | } |
16844 | |
|
16845 | 0 | zend_jit_trace_add_code(entry, size); |
16846 | 0 | } |
16847 | 0 | } |
16848 | |
|
16849 | 0 | if (str) { |
16850 | 0 | zend_string_release(str); |
16851 | 0 | } |
16852 | |
|
16853 | 0 | return (zend_vm_opcode_handler_t)entry; |
16854 | 0 | } |
16855 | | |
16856 | | static const void *zend_jit_trace_allocate_exit_group(uint32_t n) |
16857 | 0 | { |
16858 | 0 | const void *entry; |
16859 | 0 | size_t size; |
16860 | 0 | ir_code_buffer code_buffer; |
16861 | |
|
16862 | 0 | code_buffer.start = dasm_buf; |
16863 | 0 | code_buffer.end = dasm_end; |
16864 | 0 | code_buffer.pos = *dasm_ptr; |
16865 | |
|
16866 | 0 | entry = ir_emit_exitgroup(n, ZEND_JIT_EXIT_POINTS_PER_GROUP, zend_jit_stub_handlers[jit_stub_trace_exit], |
16867 | 0 | &code_buffer, &size); |
16868 | |
|
16869 | 0 | *dasm_ptr = code_buffer.pos; |
16870 | |
|
16871 | 0 | if (entry) { |
16872 | | #ifdef HAVE_CAPSTONE |
16873 | | if (JIT_G(debug) & ZEND_JIT_DEBUG_ASM) { |
16874 | | uint32_t i; |
16875 | | char name[32]; |
16876 | | |
16877 | | for (i = 0; i < ZEND_JIT_EXIT_POINTS_PER_GROUP; i++) { |
16878 | | snprintf(name, sizeof(name), "jit$$trace_exit_%d", n + i); |
16879 | | ir_disasm_add_symbol(name, (uintptr_t)entry + (i * ZEND_JIT_EXIT_POINTS_SPACING), ZEND_JIT_EXIT_POINTS_SPACING); |
16880 | | } |
16881 | | } |
16882 | | #endif |
16883 | 0 | } |
16884 | |
|
16885 | 0 | return entry; |
16886 | 0 | } |
16887 | | |
16888 | | static int zend_jit_type_guard(zend_jit_ctx *jit, const zend_op *opline, uint32_t var, uint8_t type) |
16889 | 0 | { |
16890 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
16891 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
16892 | 0 | zend_jit_addr addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var); |
16893 | |
|
16894 | 0 | if (!exit_addr) { |
16895 | 0 | return 0; |
16896 | 0 | } |
16897 | 0 | ir_GUARD(ir_EQ(jit_Z_TYPE(jit, addr), ir_CONST_U8(type)), ir_CONST_ADDR(exit_addr)); |
16898 | |
|
16899 | 0 | return 1; |
16900 | 0 | } |
16901 | | |
16902 | | static int zend_jit_scalar_type_guard(zend_jit_ctx *jit, const zend_op *opline, uint32_t var) |
16903 | 0 | { |
16904 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
16905 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
16906 | 0 | zend_jit_addr addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, var); |
16907 | |
|
16908 | 0 | if (!exit_addr) { |
16909 | 0 | return 0; |
16910 | 0 | } |
16911 | 0 | ir_GUARD(ir_LT(jit_Z_TYPE(jit, addr), ir_CONST_U8(IS_STRING)), ir_CONST_ADDR(exit_addr)); |
16912 | |
|
16913 | 0 | return 1; |
16914 | 0 | } |
16915 | | |
16916 | | static bool zend_jit_noref_guard(zend_jit_ctx *jit, const zend_op *opline, zend_jit_addr var_addr) |
16917 | 0 | { |
16918 | 0 | uint32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
16919 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
16920 | |
|
16921 | 0 | if (!exit_addr) { |
16922 | 0 | return false; |
16923 | 0 | } |
16924 | 0 | ir_GUARD(ir_NE(jit_Z_TYPE(jit, var_addr), ir_CONST_U8(IS_REFERENCE)), ir_CONST_ADDR(exit_addr)); |
16925 | |
|
16926 | 0 | return true; |
16927 | 0 | } |
16928 | | |
16929 | | static int zend_jit_trace_opline_guard(zend_jit_ctx *jit, const zend_op *opline) |
16930 | 0 | { |
16931 | 0 | uint32_t exit_point = zend_jit_trace_get_exit_point(NULL, 0); |
16932 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
16933 | |
|
16934 | 0 | if (!exit_addr) { |
16935 | 0 | return 0; |
16936 | 0 | } |
16937 | | |
16938 | 0 | ir_GUARD(jit_CMP_IP(jit, IR_EQ, opline), ir_CONST_ADDR(exit_addr)); |
16939 | 0 | zend_jit_set_last_valid_opline(jit, opline); |
16940 | |
|
16941 | 0 | return 1; |
16942 | 0 | } |
16943 | | |
16944 | | static bool zend_jit_guard_reference(zend_jit_ctx *jit, |
16945 | | const zend_op *opline, |
16946 | | zend_jit_addr *var_addr_ptr, |
16947 | | zend_jit_addr *ref_addr_ptr, |
16948 | | bool add_ref_guard) |
16949 | 0 | { |
16950 | 0 | zend_jit_addr var_addr = *var_addr_ptr; |
16951 | 0 | const void *exit_addr = NULL; |
16952 | 0 | ir_ref ref; |
16953 | |
|
16954 | 0 | if (add_ref_guard) { |
16955 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
16956 | |
|
16957 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
16958 | 0 | if (!exit_addr) { |
16959 | 0 | return false; |
16960 | 0 | } |
16961 | | |
16962 | 0 | ref = jit_Z_TYPE(jit, var_addr); |
16963 | 0 | ir_GUARD(ir_EQ(ref, ir_CONST_U8(IS_REFERENCE)), ir_CONST_ADDR(exit_addr)); |
16964 | 0 | } |
16965 | | |
16966 | 0 | ref = jit_Z_PTR(jit, var_addr); |
16967 | 0 | *ref_addr_ptr = ZEND_ADDR_REF_ZVAL(ref); |
16968 | 0 | ref = ir_ADD_OFFSET(ref, offsetof(zend_reference, val)); |
16969 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
16970 | 0 | *var_addr_ptr = var_addr; |
16971 | |
|
16972 | 0 | return true; |
16973 | 0 | } |
16974 | | |
16975 | | static bool zend_jit_fetch_reference(zend_jit_ctx *jit, |
16976 | | const zend_op *opline, |
16977 | | uint8_t var_type, |
16978 | | uint32_t *var_info_ptr, |
16979 | | zend_jit_addr *var_addr_ptr, |
16980 | | bool add_ref_guard, |
16981 | | bool add_type_guard) |
16982 | 0 | { |
16983 | 0 | zend_jit_addr var_addr = *var_addr_ptr; |
16984 | 0 | uint32_t var_info = *var_info_ptr; |
16985 | 0 | const void *exit_addr = NULL; |
16986 | 0 | ir_ref ref; |
16987 | |
|
16988 | 0 | if (add_ref_guard || add_type_guard) { |
16989 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
16990 | |
|
16991 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
16992 | 0 | if (!exit_addr) { |
16993 | 0 | return false; |
16994 | 0 | } |
16995 | 0 | } |
16996 | | |
16997 | 0 | if (add_ref_guard) { |
16998 | 0 | ref = jit_Z_TYPE(jit, var_addr); |
16999 | 0 | ir_GUARD(ir_EQ(ref, ir_CONST_U8(IS_REFERENCE)), ir_CONST_ADDR(exit_addr)); |
17000 | 0 | } |
17001 | 0 | if (opline->opcode == ZEND_INIT_METHOD_CALL && opline->op1_type == IS_VAR) { |
17002 | | /* Hack: Convert reference to regular value to simplify JIT code for INIT_METHOD_CALL */ |
17003 | 0 | ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_unref_helper), |
17004 | 0 | jit_ZVAL_ADDR(jit, var_addr)); |
17005 | 0 | *var_addr_ptr = var_addr; |
17006 | 0 | } else { |
17007 | 0 | ref = jit_Z_PTR(jit, var_addr); |
17008 | 0 | ref = ir_ADD_OFFSET(ref, offsetof(zend_reference, val)); |
17009 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
17010 | 0 | *var_addr_ptr = var_addr; |
17011 | 0 | } |
17012 | |
|
17013 | 0 | if (var_type != IS_UNKNOWN) { |
17014 | 0 | var_type &= ~(IS_TRACE_REFERENCE|IS_TRACE_INDIRECT|IS_TRACE_PACKED); |
17015 | 0 | } |
17016 | 0 | if (add_type_guard |
17017 | 0 | && var_type != IS_UNKNOWN |
17018 | 0 | && (var_info & (MAY_BE_ANY|MAY_BE_UNDEF)) != (1 << var_type)) { |
17019 | 0 | ref = jit_Z_TYPE(jit, var_addr); |
17020 | 0 | ir_GUARD(ir_EQ(ref, ir_CONST_U8(var_type)), ir_CONST_ADDR(exit_addr)); |
17021 | |
|
17022 | 0 | ZEND_ASSERT(var_info & (1 << var_type)); |
17023 | 0 | if (var_type < IS_STRING) { |
17024 | 0 | var_info = (1 << var_type); |
17025 | 0 | } else if (var_type != IS_ARRAY) { |
17026 | 0 | var_info = (1 << var_type) | (var_info & (MAY_BE_RC1|MAY_BE_RCN)); |
17027 | 0 | } else { |
17028 | 0 | var_info = MAY_BE_ARRAY | (var_info & (MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF|MAY_BE_ARRAY_KEY_ANY|MAY_BE_RC1|MAY_BE_RCN)); |
17029 | 0 | } |
17030 | |
|
17031 | 0 | *var_info_ptr = var_info; |
17032 | 0 | } else { |
17033 | 0 | var_info &= ~MAY_BE_REF; |
17034 | 0 | *var_info_ptr = var_info; |
17035 | 0 | } |
17036 | 0 | *var_info_ptr |= MAY_BE_GUARD; /* prevent generation of specialized zval dtor */ |
17037 | |
|
17038 | 0 | return true; |
17039 | 0 | } |
17040 | | |
17041 | | static bool zend_jit_fetch_indirect_var(zend_jit_ctx *jit, const zend_op *opline, uint8_t var_type, uint32_t *var_info_ptr, zend_jit_addr *var_addr_ptr, bool add_indirect_guard) |
17042 | 0 | { |
17043 | 0 | zend_jit_addr var_addr = *var_addr_ptr; |
17044 | 0 | uint32_t var_info = *var_info_ptr; |
17045 | 0 | int32_t exit_point; |
17046 | 0 | const void *exit_addr; |
17047 | 0 | ir_ref ref = IR_UNUSED; |
17048 | |
|
17049 | 0 | if (add_indirect_guard) { |
17050 | 0 | int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0); |
17051 | 0 | const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
17052 | |
|
17053 | 0 | if (!exit_addr) { |
17054 | 0 | return false; |
17055 | 0 | } |
17056 | 0 | jit_guard_Z_TYPE(jit, var_addr, IS_INDIRECT, exit_addr); |
17057 | 0 | ref = jit_Z_PTR(jit, var_addr); |
17058 | 0 | } else { |
17059 | | /* This LOAD of INDIRECT VAR, stored by the previous FETCH_(DIM/OBJ)_W, |
17060 | | * is eliminated by store forwarding (S2L) */ |
17061 | 0 | ref = jit_Z_PTR(jit, var_addr); |
17062 | 0 | } |
17063 | 0 | *var_info_ptr &= ~MAY_BE_INDIRECT; |
17064 | 0 | var_addr = ZEND_ADDR_REF_ZVAL(ref); |
17065 | 0 | *var_addr_ptr = var_addr; |
17066 | |
|
17067 | 0 | if (var_type != IS_UNKNOWN) { |
17068 | 0 | var_type &= ~(IS_TRACE_INDIRECT|IS_TRACE_PACKED); |
17069 | 0 | } |
17070 | 0 | if (!(var_type & IS_TRACE_REFERENCE) |
17071 | 0 | && var_type != IS_UNKNOWN |
17072 | 0 | && (var_info & (MAY_BE_ANY|MAY_BE_UNDEF)) != (1 << var_type)) { |
17073 | 0 | exit_point = zend_jit_trace_get_exit_point(opline, 0); |
17074 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
17075 | |
|
17076 | 0 | if (!exit_addr) { |
17077 | 0 | return false; |
17078 | 0 | } |
17079 | | |
17080 | 0 | jit_guard_Z_TYPE(jit, var_addr, var_type, exit_addr); |
17081 | | |
17082 | | //var_info = zend_jit_trace_type_to_info_ex(var_type, var_info); |
17083 | 0 | ZEND_ASSERT(var_info & (1 << var_type)); |
17084 | 0 | if (var_type < IS_STRING) { |
17085 | 0 | var_info = (1 << var_type); |
17086 | 0 | } else if (var_type != IS_ARRAY) { |
17087 | 0 | var_info = (1 << var_type) | (var_info & (MAY_BE_RC1|MAY_BE_RCN)); |
17088 | 0 | } else { |
17089 | 0 | var_info = MAY_BE_ARRAY | (var_info & (MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF|MAY_BE_ARRAY_KEY_ANY|MAY_BE_RC1|MAY_BE_RCN)); |
17090 | 0 | } |
17091 | |
|
17092 | 0 | *var_info_ptr = var_info; |
17093 | 0 | } |
17094 | | |
17095 | 0 | return true; |
17096 | 0 | } |
17097 | | |
17098 | | static int zend_jit_trace_handler(zend_jit_ctx *jit, const zend_op_array *op_array, const zend_op *opline, int may_throw, zend_jit_trace_rec *trace) |
17099 | 0 | { |
17100 | 0 | zend_jit_op_array_trace_extension *jit_extension = |
17101 | 0 | (zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array); |
17102 | 0 | size_t offset = jit_extension->offset; |
17103 | 0 | zend_vm_opcode_handler_func_t handler = |
17104 | 0 | ZEND_OP_TRACE_INFO(opline, offset)->call_handler; |
17105 | 0 | ir_ref ref; |
17106 | |
|
17107 | 0 | zend_jit_set_ip(jit, opline); |
17108 | 0 | if (GCC_GLOBAL_REGS) { |
17109 | 0 | ir_CALL(IR_VOID, ir_CONST_FUNC(handler)); |
17110 | 0 | } else { |
17111 | 0 | ref = ir_CALL_2(IR_ADDR, ir_CONST_FC_FUNC(handler), jit_FP(jit), jit_IP(jit)); |
17112 | 0 | if (opline->opcode == ZEND_RETURN || |
17113 | 0 | opline->opcode == ZEND_RETURN_BY_REF || |
17114 | 0 | opline->opcode == ZEND_DO_UCALL || |
17115 | 0 | opline->opcode == ZEND_DO_FCALL_BY_NAME || |
17116 | 0 | opline->opcode == ZEND_DO_FCALL || |
17117 | 0 | opline->opcode == ZEND_GENERATOR_CREATE || |
17118 | 0 | opline->opcode == ZEND_INCLUDE_OR_EVAL) { |
17119 | |
|
17120 | 0 | jit_STORE_IP(jit, ir_AND_A(ref, ir_CONST_ADDR(~ZEND_VM_ENTER_BIT))); |
17121 | 0 | } else { |
17122 | 0 | jit_STORE_IP(jit, ref); |
17123 | 0 | } |
17124 | 0 | } |
17125 | 0 | if (may_throw |
17126 | 0 | && opline->opcode != ZEND_RETURN |
17127 | 0 | && opline->opcode != ZEND_RETURN_BY_REF) { |
17128 | 0 | zend_jit_check_exception(jit); |
17129 | 0 | } |
17130 | |
|
17131 | 0 | while (trace->op != ZEND_JIT_TRACE_VM && trace->op != ZEND_JIT_TRACE_END) { |
17132 | 0 | trace++; |
17133 | 0 | } |
17134 | |
|
17135 | 0 | if ((!GCC_GLOBAL_REGS |
17136 | 0 | && (trace->op != ZEND_JIT_TRACE_END || trace->stop != ZEND_JIT_TRACE_STOP_RETURN)) |
17137 | 0 | || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
17138 | 0 | if (opline->opcode == ZEND_RETURN || |
17139 | 0 | opline->opcode == ZEND_RETURN_BY_REF || |
17140 | 0 | opline->opcode == ZEND_DO_UCALL || |
17141 | 0 | opline->opcode == ZEND_DO_FCALL_BY_NAME || |
17142 | 0 | opline->opcode == ZEND_DO_FCALL || |
17143 | 0 | opline->opcode == ZEND_GENERATOR_CREATE || |
17144 | 0 | opline->opcode == ZEND_INCLUDE_OR_EVAL) { |
17145 | |
|
17146 | 0 | ir_ref addr = jit_EG(current_execute_data); |
17147 | |
|
17148 | 0 | jit_STORE_FP(jit, ir_LOAD_A(addr)); |
17149 | 0 | } |
17150 | 0 | } |
17151 | |
|
17152 | 0 | if (zend_jit_trace_may_exit(op_array, opline)) { |
17153 | 0 | if (opline->opcode == ZEND_RETURN || |
17154 | 0 | opline->opcode == ZEND_RETURN_BY_REF || |
17155 | 0 | opline->opcode == ZEND_GENERATOR_CREATE) { |
17156 | |
|
17157 | 0 | if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) { |
17158 | 0 | if (trace->op != ZEND_JIT_TRACE_END || |
17159 | 0 | (trace->stop != ZEND_JIT_TRACE_STOP_RETURN && |
17160 | 0 | trace->stop < ZEND_JIT_TRACE_STOP_INTERPRETER)) { |
17161 | | /* this check may be handled by the following OPLINE guard or jmp [IP] */ |
17162 | 0 | ir_GUARD(ir_NE(jit_IP(jit), ir_CONST_ADDR(zend_jit_halt_op)), |
17163 | 0 | jit_STUB_ADDR(jit, jit_stub_trace_halt)); |
17164 | 0 | } |
17165 | 0 | } else { |
17166 | | /* IP has been cleared of ZEND_VM_ENTER_BIT already */ |
17167 | 0 | ir_GUARD(jit_IP(jit), jit_STUB_ADDR(jit, jit_stub_trace_halt)); |
17168 | 0 | } |
17169 | 0 | } else if (opline->opcode == ZEND_GENERATOR_RETURN || |
17170 | 0 | opline->opcode == ZEND_YIELD || |
17171 | 0 | opline->opcode == ZEND_YIELD_FROM) { |
17172 | 0 | ir_IJMP(jit_STUB_ADDR(jit, jit_stub_trace_halt)); |
17173 | 0 | ir_BEGIN(IR_UNUSED); /* unreachable block */ |
17174 | 0 | } |
17175 | 0 | if (trace->op != ZEND_JIT_TRACE_END || |
17176 | 0 | (trace->stop != ZEND_JIT_TRACE_STOP_RETURN && |
17177 | 0 | trace->stop < ZEND_JIT_TRACE_STOP_INTERPRETER)) { |
17178 | |
|
17179 | 0 | const zend_op *next_opline = trace->opline; |
17180 | 0 | const zend_op *exit_opline = NULL; |
17181 | 0 | uint32_t exit_point; |
17182 | 0 | const void *exit_addr; |
17183 | 0 | uint32_t old_info = 0; |
17184 | 0 | uint32_t old_res_info = 0; |
17185 | 0 | zend_jit_trace_stack *stack = JIT_G(current_frame)->stack; |
17186 | |
|
17187 | 0 | if (zend_is_smart_branch(opline)) { |
17188 | 0 | bool exit_if_true = false; |
17189 | 0 | exit_opline = zend_jit_trace_get_exit_opline(trace, opline + 1, &exit_if_true); |
17190 | 0 | } else { |
17191 | 0 | switch (opline->opcode) { |
17192 | 0 | case ZEND_JMPZ: |
17193 | 0 | case ZEND_JMPNZ: |
17194 | 0 | case ZEND_JMPZ_EX: |
17195 | 0 | case ZEND_JMPNZ_EX: |
17196 | 0 | case ZEND_JMP_SET: |
17197 | 0 | case ZEND_COALESCE: |
17198 | 0 | case ZEND_JMP_NULL: |
17199 | 0 | case ZEND_FE_RESET_R: |
17200 | 0 | case ZEND_FE_RESET_RW: |
17201 | 0 | exit_opline = (trace->opline == opline + 1) ? |
17202 | 0 | OP_JMP_ADDR(opline, opline->op2) : |
17203 | 0 | opline + 1; |
17204 | 0 | break; |
17205 | 0 | case ZEND_FE_FETCH_R: |
17206 | 0 | case ZEND_FE_FETCH_RW: |
17207 | 0 | exit_opline = (trace->opline == opline + 1) ? |
17208 | 0 | ZEND_OFFSET_TO_OPLINE(opline, opline->extended_value) : |
17209 | 0 | opline + 1; |
17210 | 0 | break; |
17211 | |
|
17212 | 0 | } |
17213 | 0 | } |
17214 | | |
17215 | 0 | switch (opline->opcode) { |
17216 | 0 | case ZEND_FE_FETCH_R: |
17217 | 0 | case ZEND_FE_FETCH_RW: |
17218 | 0 | if (opline->op2_type != IS_UNUSED) { |
17219 | 0 | old_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->op2.var)); |
17220 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op2.var), IS_UNKNOWN, 1); |
17221 | 0 | } |
17222 | 0 | break; |
17223 | 0 | case ZEND_FE_RESET_RW: |
17224 | 0 | case ZEND_BIND_INIT_STATIC_OR_JMP: |
17225 | 0 | if (opline->op1_type == IS_CV) { |
17226 | 0 | old_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var)); |
17227 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->op1.var), IS_UNKNOWN, 1); |
17228 | 0 | } |
17229 | 0 | break; |
17230 | 0 | } |
17231 | 0 | if (opline->result_type == IS_VAR || opline->result_type == IS_TMP_VAR) { |
17232 | 0 | old_res_info = STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var)); |
17233 | 0 | SET_STACK_TYPE(stack, EX_VAR_TO_NUM(opline->result.var), IS_UNKNOWN, 1); |
17234 | 0 | } |
17235 | 0 | exit_point = zend_jit_trace_get_exit_point(exit_opline, 0); |
17236 | 0 | exit_addr = zend_jit_trace_get_exit_addr(exit_point); |
17237 | |
|
17238 | 0 | if (opline->result_type == IS_VAR || opline->result_type == IS_TMP_VAR) { |
17239 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->result.var), old_res_info); |
17240 | 0 | } |
17241 | 0 | switch (opline->opcode) { |
17242 | 0 | case ZEND_FE_FETCH_R: |
17243 | 0 | case ZEND_FE_FETCH_RW: |
17244 | 0 | if (opline->op2_type != IS_UNUSED) { |
17245 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->op2.var), old_info); |
17246 | 0 | } |
17247 | 0 | break; |
17248 | 0 | case ZEND_FE_RESET_RW: |
17249 | 0 | case ZEND_BIND_INIT_STATIC_OR_JMP: |
17250 | 0 | if (opline->op1_type == IS_CV) { |
17251 | 0 | SET_STACK_INFO(stack, EX_VAR_TO_NUM(opline->op1.var), old_info); |
17252 | 0 | } |
17253 | 0 | break; |
17254 | 0 | } |
17255 | | |
17256 | 0 | if (!exit_addr) { |
17257 | 0 | return 0; |
17258 | 0 | } |
17259 | 0 | ir_GUARD(jit_CMP_IP(jit, IR_EQ, next_opline), ir_CONST_ADDR(exit_addr)); |
17260 | 0 | } |
17261 | 0 | } |
17262 | | |
17263 | 0 | zend_jit_set_last_valid_opline(jit, trace->opline); |
17264 | |
|
17265 | 0 | return 1; |
17266 | 0 | } |
17267 | | |
17268 | | static int zend_jit_deoptimizer_start(zend_jit_ctx *jit, |
17269 | | zend_string *name, |
17270 | | uint32_t trace_num, |
17271 | | uint32_t exit_num) |
17272 | 0 | { |
17273 | 0 | zend_jit_init_ctx(jit, (ZEND_VM_KIND == ZEND_VM_KIND_CALL || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) ? 0 : IR_START_BR_TARGET); |
17274 | |
|
17275 | 0 | jit->ctx.spill_base = ZREG_FP; |
17276 | |
|
17277 | 0 | jit->op_array = NULL; |
17278 | 0 | jit->ssa = NULL; |
17279 | 0 | jit->name = zend_string_copy(name); |
17280 | |
|
17281 | 0 | jit->ctx.flags |= IR_SKIP_PROLOGUE; |
17282 | |
|
17283 | 0 | return 1; |
17284 | 0 | } |
17285 | | |
17286 | | static int zend_jit_trace_start(zend_jit_ctx *jit, |
17287 | | const zend_op_array *op_array, |
17288 | | zend_ssa *ssa, |
17289 | | zend_string *name, |
17290 | | uint32_t trace_num, |
17291 | | zend_jit_trace_info *parent, |
17292 | | uint32_t exit_num) |
17293 | 0 | { |
17294 | 0 | zend_jit_init_ctx(jit, (ZEND_VM_KIND == ZEND_VM_KIND_CALL || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) ? 0 : IR_START_BR_TARGET); |
17295 | |
|
17296 | 0 | jit->ctx.spill_base = ZREG_FP; |
17297 | |
|
17298 | 0 | jit->op_array = NULL; |
17299 | 0 | jit->current_op_array = op_array; |
17300 | 0 | jit->ssa = ssa; |
17301 | 0 | jit->name = zend_string_copy(name); |
17302 | |
|
17303 | 0 | if (!GCC_GLOBAL_REGS) { |
17304 | 0 | if (!parent) { |
17305 | 0 | if (ZEND_VM_KIND != ZEND_VM_KIND_TAILCALL) { |
17306 | 0 | ir_ref execute_data_ref = ir_PARAM(IR_ADDR, "execute_data", 1); |
17307 | 0 | ir_ref opline_ref = ir_PARAM(IR_ADDR, "opline", 2); |
17308 | 0 | jit_STORE_FP(jit, execute_data_ref); |
17309 | 0 | jit_STORE_IP(jit, opline_ref); |
17310 | 0 | } |
17311 | 0 | jit->ctx.flags |= IR_FASTCALL_FUNC; |
17312 | 0 | } |
17313 | 0 | } |
17314 | |
|
17315 | 0 | if (parent) { |
17316 | 0 | jit->ctx.flags |= IR_SKIP_PROLOGUE; |
17317 | 0 | } |
17318 | |
|
17319 | 0 | if (parent) { |
17320 | 0 | int i; |
17321 | 0 | int parent_vars_count = parent->exit_info[exit_num].stack_size; |
17322 | 0 | zend_jit_trace_stack *parent_stack = parent_vars_count == 0 ? NULL : |
17323 | 0 | parent->stack_map + |
17324 | 0 | parent->exit_info[exit_num].stack_offset; |
17325 | | |
17326 | | /* prevent clobbering of registers used for deoptimization */ |
17327 | 0 | for (i = 0; i < parent_vars_count; i++) { |
17328 | 0 | if (STACK_FLAGS(parent_stack, i) != ZREG_CONST |
17329 | 0 | && STACK_REG(parent_stack, i) != ZREG_NONE) { |
17330 | 0 | int32_t reg = STACK_REG(parent_stack, i); |
17331 | 0 | ir_type type; |
17332 | |
|
17333 | 0 | if (STACK_FLAGS(parent_stack, i) == ZREG_ZVAL_COPY) { |
17334 | 0 | type = IR_ADDR; |
17335 | 0 | } else if (STACK_TYPE(parent_stack, i) == IS_LONG) { |
17336 | 0 | type = IR_LONG; |
17337 | 0 | } else if (STACK_TYPE(parent_stack, i) == IS_DOUBLE) { |
17338 | 0 | type = IR_DOUBLE; |
17339 | 0 | } else { |
17340 | 0 | ZEND_UNREACHABLE(); |
17341 | 0 | } |
17342 | 0 | if (ssa && ssa->vars[i].no_val) { |
17343 | | /* pass */ |
17344 | 0 | } else { |
17345 | 0 | ir_ref ref = ir_RLOAD(type, reg); |
17346 | |
|
17347 | 0 | if (STACK_FLAGS(parent_stack, i) & (ZREG_LOAD|ZREG_STORE)) { |
17348 | | /* op3 is used as a flag that the value is already stored in memory. |
17349 | | * In case the IR framework decides to spill the result of IR_LOAD, |
17350 | | * it doesn't have to store the value once again. |
17351 | | * |
17352 | | * See: insn->op3 check in ir_emit_rload() |
17353 | | */ |
17354 | 0 | ir_set_op(&jit->ctx, ref, 3, EX_NUM_TO_VAR(i)); |
17355 | 0 | } |
17356 | 0 | } |
17357 | 0 | } |
17358 | 0 | } |
17359 | 0 | } |
17360 | | |
17361 | 0 | if (parent && parent->exit_info[exit_num].flags & ZEND_JIT_EXIT_METHOD_CALL) { |
17362 | 0 | ZEND_ASSERT(parent->exit_info[exit_num].poly_func.reg >= 0 && parent->exit_info[exit_num].poly_this.reg >= 0); |
17363 | 0 | if (!IR_REG_SPILLED(parent->exit_info[exit_num].poly_func.reg)) { |
17364 | 0 | ir_RLOAD_A(parent->exit_info[exit_num].poly_func.reg); |
17365 | 0 | } |
17366 | 0 | if (!IR_REG_SPILLED(parent->exit_info[exit_num].poly_this.reg)) { |
17367 | 0 | ir_RLOAD_A(parent->exit_info[exit_num].poly_this.reg); |
17368 | 0 | } |
17369 | 0 | } |
17370 | |
|
17371 | 0 | ir_STORE(jit_EG(jit_trace_num), ir_CONST_U32(trace_num)); |
17372 | |
|
17373 | 0 | return 1; |
17374 | 0 | } |
17375 | | |
17376 | | static int zend_jit_trace_begin_loop(zend_jit_ctx *jit) |
17377 | 0 | { |
17378 | 0 | return ir_LOOP_BEGIN(ir_END()); |
17379 | 0 | } |
17380 | | |
17381 | | static void zend_jit_trace_gen_phi(zend_jit_ctx *jit, zend_ssa_phi *phi) |
17382 | 0 | { |
17383 | 0 | int dst_var = phi->ssa_var; |
17384 | 0 | int src_var = phi->sources[0]; |
17385 | 0 | ir_ref ref; |
17386 | |
|
17387 | 0 | ZEND_ASSERT(!(jit->ra[dst_var].flags & ZREG_LOAD)); |
17388 | 0 | ZEND_ASSERT(jit->ra[src_var].ref != IR_UNUSED && jit->ra[src_var].ref != IR_NULL); |
17389 | |
|
17390 | 0 | ref = ir_PHI_2( |
17391 | 0 | (jit->ssa->var_info[src_var].type & MAY_BE_LONG) ? IR_LONG : IR_DOUBLE, |
17392 | 0 | zend_jit_use_reg(jit, ZEND_ADDR_REG(src_var)), IR_UNUSED); |
17393 | |
|
17394 | 0 | src_var = phi->sources[1]; |
17395 | 0 | ZEND_ASSERT(jit->ra[src_var].ref == IR_NULL); |
17396 | 0 | jit->ra[src_var].flags |= ZREG_FORWARD; |
17397 | |
|
17398 | 0 | zend_jit_def_reg(jit, ZEND_ADDR_REG(dst_var), ref); |
17399 | 0 | } |
17400 | | |
17401 | | static int zend_jit_trace_end_loop(zend_jit_ctx *jit, int loop_ref, const void *timeout_exit_addr) |
17402 | 0 | { |
17403 | 0 | if (timeout_exit_addr) { |
17404 | 0 | zend_jit_check_timeout(jit, NULL, timeout_exit_addr); |
17405 | 0 | } |
17406 | 0 | ZEND_ASSERT(jit->ctx.ir_base[loop_ref].op2 == IR_UNUSED); |
17407 | 0 | ir_MERGE_SET_OP(loop_ref, 2, ir_LOOP_END()); |
17408 | 0 | return 1; |
17409 | 0 | } |
17410 | | |
17411 | | static int zend_jit_trace_return(zend_jit_ctx *jit, bool original_handler, const zend_op *opline) |
17412 | 0 | { |
17413 | 0 | if (GCC_GLOBAL_REGS || ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL) { |
17414 | 0 | if (!original_handler) { |
17415 | 0 | zend_jit_tailcall_handler(jit, ir_LOAD_A(jit_IP(jit))); |
17416 | 0 | } else { |
17417 | 0 | zend_jit_tailcall_handler(jit, zend_jit_orig_opline_handler(jit)); |
17418 | 0 | } |
17419 | 0 | } else { |
17420 | 0 | if (original_handler) { |
17421 | 0 | ir_ref ref; |
17422 | 0 | ir_ref addr = zend_jit_orig_opline_handler(jit); |
17423 | |
|
17424 | | #if defined(IR_TARGET_X86) |
17425 | | addr = ir_CAST_FC_FUNC(addr); |
17426 | | #endif |
17427 | 0 | ref = ir_CALL_2(IR_ADDR, addr, jit_FP(jit), jit_IP(jit)); |
17428 | 0 | zend_jit_vm_enter(jit, ref); |
17429 | 0 | return 1; |
17430 | 0 | } |
17431 | 0 | zend_jit_vm_enter(jit, jit_IP(jit)); |
17432 | 0 | } |
17433 | 0 | return 1; |
17434 | 0 | } |
17435 | | |
17436 | | static int zend_jit_link_side_trace(const void *code, size_t size, uint32_t jmp_table_size, uint32_t exit_num, const void *addr) |
17437 | 0 | { |
17438 | 0 | return ir_patch(code, size, jmp_table_size, zend_jit_trace_get_exit_addr(exit_num), addr); |
17439 | 0 | } |
17440 | | |
17441 | | static int zend_jit_trace_link_to_root(zend_jit_ctx *jit, zend_jit_trace_info *t, const void *timeout_exit_addr) |
17442 | 0 | { |
17443 | 0 | const void *link_addr; |
17444 | | |
17445 | | /* Skip prologue. */ |
17446 | 0 | ZEND_ASSERT(zend_jit_trace_prologue_size != (size_t)-1); |
17447 | 0 | link_addr = (const void*)((const char*)t->code_start + zend_jit_trace_prologue_size); |
17448 | |
|
17449 | 0 | if (timeout_exit_addr) { |
17450 | 0 | zend_jit_check_timeout(jit, NULL, timeout_exit_addr); |
17451 | 0 | } |
17452 | 0 | ir_IJMP(ir_CONST_ADDR(link_addr)); |
17453 | |
|
17454 | 0 | return 1; |
17455 | 0 | } |
17456 | | |
17457 | | static bool zend_jit_opline_supports_reg(const zend_op_array *op_array, zend_ssa *ssa, const zend_op *opline, const zend_ssa_op *ssa_op, zend_jit_trace_rec *trace) |
17458 | 0 | { |
17459 | 0 | uint32_t op1_info, op2_info; |
17460 | |
|
17461 | 0 | switch (opline->opcode) { |
17462 | 0 | case ZEND_SEND_VAR: |
17463 | 0 | case ZEND_SEND_VAL: |
17464 | 0 | case ZEND_SEND_VAL_EX: |
17465 | 0 | return (opline->op2_type != IS_CONST) && (opline->opcode != ZEND_SEND_VAL_EX || opline->op2.num <= MAX_ARG_FLAG_NUM); |
17466 | 0 | case ZEND_QM_ASSIGN: |
17467 | 0 | case ZEND_IS_SMALLER: |
17468 | 0 | case ZEND_IS_SMALLER_OR_EQUAL: |
17469 | 0 | case ZEND_IS_EQUAL: |
17470 | 0 | case ZEND_IS_NOT_EQUAL: |
17471 | 0 | case ZEND_IS_IDENTICAL: |
17472 | 0 | case ZEND_IS_NOT_IDENTICAL: |
17473 | 0 | case ZEND_CASE: |
17474 | 0 | return true; |
17475 | 0 | case ZEND_RETURN: |
17476 | 0 | return (op_array->type != ZEND_EVAL_CODE && op_array->function_name); |
17477 | 0 | case ZEND_ASSIGN: |
17478 | 0 | return (opline->op1_type == IS_CV); |
17479 | 0 | case ZEND_ASSIGN_OP: |
17480 | 0 | if (opline->op1_type != IS_CV || opline->result_type != IS_UNUSED) { |
17481 | 0 | return false; |
17482 | 0 | } |
17483 | 0 | op1_info = OP1_INFO(); |
17484 | 0 | op2_info = OP2_INFO(); |
17485 | 0 | return zend_jit_supported_binary_op(opline->extended_value, op1_info, op2_info); |
17486 | 0 | case ZEND_ADD: |
17487 | 0 | case ZEND_SUB: |
17488 | 0 | case ZEND_MUL: |
17489 | 0 | op1_info = OP1_INFO(); |
17490 | 0 | op2_info = OP2_INFO(); |
17491 | 0 | if ((op1_info & MAY_BE_UNDEF) || (op2_info & MAY_BE_UNDEF)) { |
17492 | 0 | return false; |
17493 | 0 | } |
17494 | 0 | if (trace && trace->op1_type != IS_UNKNOWN) { |
17495 | 0 | op1_info &= 1U << (trace->op1_type & ~(IS_TRACE_REFERENCE|IS_TRACE_INDIRECT|IS_TRACE_PACKED)); |
17496 | 0 | } |
17497 | 0 | if (trace && trace->op2_type != IS_UNKNOWN) { |
17498 | 0 | op2_info &= 1U << (trace->op2_type & ~(IS_TRACE_REFERENCE|IS_TRACE_INDIRECT|IS_TRACE_PACKED)); |
17499 | 0 | } |
17500 | 0 | return !(op1_info & MAY_BE_UNDEF) |
17501 | 0 | && !(op2_info & MAY_BE_UNDEF) |
17502 | 0 | && (op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE)) |
17503 | 0 | && (op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE)); |
17504 | 0 | case ZEND_BW_OR: |
17505 | 0 | case ZEND_BW_AND: |
17506 | 0 | case ZEND_BW_XOR: |
17507 | 0 | case ZEND_SL: |
17508 | 0 | case ZEND_SR: |
17509 | 0 | case ZEND_MOD: |
17510 | 0 | op1_info = OP1_INFO(); |
17511 | 0 | op2_info = OP2_INFO(); |
17512 | 0 | if (trace && trace->op1_type != IS_UNKNOWN) { |
17513 | 0 | op1_info &= 1U << (trace->op1_type & ~(IS_TRACE_REFERENCE|IS_TRACE_INDIRECT|IS_TRACE_PACKED)); |
17514 | 0 | } |
17515 | 0 | if (trace && trace->op2_type != IS_UNKNOWN) { |
17516 | 0 | op2_info &= 1U << (trace->op2_type & ~(IS_TRACE_REFERENCE|IS_TRACE_INDIRECT|IS_TRACE_PACKED)); |
17517 | 0 | } |
17518 | 0 | return (op1_info & MAY_BE_LONG) |
17519 | 0 | && (op2_info & MAY_BE_LONG); |
17520 | 0 | case ZEND_PRE_INC: |
17521 | 0 | case ZEND_PRE_DEC: |
17522 | 0 | case ZEND_POST_INC: |
17523 | 0 | case ZEND_POST_DEC: |
17524 | 0 | op1_info = OP1_INFO(); |
17525 | 0 | return opline->op1_type == IS_CV |
17526 | 0 | && (op1_info & MAY_BE_LONG) |
17527 | 0 | && !(op1_info & MAY_BE_REF); |
17528 | 0 | case ZEND_STRLEN: |
17529 | 0 | op1_info = OP1_INFO(); |
17530 | 0 | return (opline->op1_type & (IS_CV|IS_CONST)) |
17531 | 0 | && (op1_info & (MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF)) == MAY_BE_STRING; |
17532 | 0 | case ZEND_COUNT: |
17533 | 0 | op1_info = OP1_INFO(); |
17534 | 0 | return (opline->op1_type & (IS_CV|IS_CONST)) |
17535 | 0 | && (op1_info & (MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF)) == MAY_BE_ARRAY; |
17536 | 0 | case ZEND_JMPZ: |
17537 | 0 | case ZEND_JMPNZ: |
17538 | 0 | if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE) { |
17539 | 0 | if (!ssa->cfg.map) { |
17540 | 0 | return false; |
17541 | 0 | } |
17542 | 0 | if (opline > op_array->opcodes + ssa->cfg.blocks[ssa->cfg.map[opline-op_array->opcodes]].start && |
17543 | 0 | ((opline-1)->result_type & (IS_SMART_BRANCH_JMPZ|IS_SMART_BRANCH_JMPNZ)) != 0) { |
17544 | 0 | return false; |
17545 | 0 | } |
17546 | 0 | } |
17547 | 0 | ZEND_FALLTHROUGH; |
17548 | 0 | case ZEND_BOOL: |
17549 | 0 | case ZEND_BOOL_NOT: |
17550 | 0 | case ZEND_JMPZ_EX: |
17551 | 0 | case ZEND_JMPNZ_EX: |
17552 | 0 | return true; |
17553 | 0 | case ZEND_FETCH_CONSTANT: |
17554 | 0 | return true; |
17555 | 0 | case ZEND_ISSET_ISEMPTY_DIM_OBJ: |
17556 | 0 | if ((opline->extended_value & ZEND_ISEMPTY)) { |
17557 | 0 | return false; |
17558 | 0 | } |
17559 | 0 | ZEND_FALLTHROUGH; |
17560 | 0 | case ZEND_FETCH_DIM_R: |
17561 | 0 | case ZEND_FETCH_DIM_IS: |
17562 | 0 | case ZEND_FETCH_LIST_R: |
17563 | 0 | op1_info = OP1_INFO(); |
17564 | 0 | op2_info = OP2_INFO(); |
17565 | 0 | if (trace |
17566 | 0 | && trace->op1_type != IS_UNKNOWN |
17567 | 0 | && (trace->op1_type & ~(IS_TRACE_REFERENCE|IS_TRACE_INDIRECT|IS_TRACE_PACKED)) == IS_ARRAY) { |
17568 | 0 | op1_info &= ~((MAY_BE_ANY|MAY_BE_UNDEF) - MAY_BE_ARRAY); |
17569 | 0 | } |
17570 | 0 | return ((op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY) && |
17571 | 0 | (((op2_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_LONG) || |
17572 | 0 | ((op2_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_STRING)); |
17573 | 0 | case ZEND_ASSIGN_DIM_OP: |
17574 | 0 | if (opline->result_type != IS_UNUSED) { |
17575 | 0 | return false; |
17576 | 0 | } |
17577 | 0 | if (!zend_jit_supported_binary_op(opline->extended_value, MAY_BE_ANY, OP1_DATA_INFO())) { |
17578 | 0 | return false; |
17579 | 0 | } |
17580 | 0 | ZEND_FALLTHROUGH; |
17581 | 0 | case ZEND_ASSIGN_DIM: |
17582 | 0 | case ZEND_FETCH_DIM_W: |
17583 | 0 | case ZEND_FETCH_DIM_RW: |
17584 | 0 | case ZEND_FETCH_LIST_W: |
17585 | 0 | op1_info = OP1_INFO(); |
17586 | 0 | op2_info = OP2_INFO(); |
17587 | 0 | if (trace) { |
17588 | 0 | if (opline->op1_type == IS_CV) { |
17589 | 0 | if ((opline->opcode == ZEND_ASSIGN_DIM |
17590 | 0 | || opline->opcode == ZEND_ASSIGN_DIM_OP) |
17591 | 0 | && (opline+1)->op1_type == IS_CV |
17592 | 0 | && (opline+1)->op1.var == opline->op1.var) { |
17593 | | /* skip $a[x] = $a; */ |
17594 | 0 | return false; |
17595 | 0 | } |
17596 | 0 | } else if (opline->op1_type == IS_VAR) { |
17597 | 0 | if (trace->op1_type == IS_UNKNOWN |
17598 | 0 | || !(trace->op1_type & IS_TRACE_INDIRECT) |
17599 | 0 | || opline->result_type != IS_UNUSED) { |
17600 | 0 | return false; |
17601 | 0 | } |
17602 | 0 | } |
17603 | 0 | if (trace->op1_type != IS_UNKNOWN |
17604 | 0 | && (trace->op1_type & ~(IS_TRACE_REFERENCE|IS_TRACE_INDIRECT|IS_TRACE_PACKED)) == IS_ARRAY) { |
17605 | 0 | op1_info &= ~((MAY_BE_ANY|MAY_BE_UNDEF) - MAY_BE_ARRAY); |
17606 | 0 | } |
17607 | 0 | } else { |
17608 | 0 | if (opline->op1_type != IS_CV) { |
17609 | 0 | return false; |
17610 | 0 | } |
17611 | 0 | } |
17612 | 0 | return ((op1_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_ARRAY) && |
17613 | 0 | (((op2_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_LONG) || |
17614 | 0 | ((op2_info & (MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_STRING)); |
17615 | 0 | case ZEND_ASSIGN_OBJ_OP: |
17616 | 0 | if (opline->result_type != IS_UNUSED) { |
17617 | 0 | return false; |
17618 | 0 | } |
17619 | 0 | if (!zend_jit_supported_binary_op(opline->extended_value, MAY_BE_ANY, OP1_DATA_INFO())) { |
17620 | 0 | return false; |
17621 | 0 | } |
17622 | 0 | ZEND_FALLTHROUGH; |
17623 | 0 | case ZEND_FETCH_OBJ_R: |
17624 | 0 | case ZEND_ASSIGN_OBJ: |
17625 | 0 | if (opline->op2_type != IS_CONST |
17626 | 0 | || Z_TYPE_P(RT_CONSTANT(opline, opline->op2)) != IS_STRING |
17627 | 0 | || Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))[0] == '\0') { |
17628 | 0 | return false; |
17629 | 0 | } |
17630 | 0 | op1_info = OP1_INFO(); |
17631 | 0 | return opline->op1_type == IS_UNUSED || (op1_info & MAY_BE_OBJECT); |
17632 | 0 | } |
17633 | 0 | return false; |
17634 | 0 | } |
17635 | | |
17636 | | static bool zend_jit_var_supports_reg(zend_ssa *ssa, int var) |
17637 | 0 | { |
17638 | 0 | if (ssa->vars[var].no_val) { |
17639 | | /* we don't need the value */ |
17640 | 0 | return false; |
17641 | 0 | } |
17642 | | |
17643 | 0 | if (!(JIT_G(opt_flags) & ZEND_JIT_REG_ALLOC_GLOBAL)) { |
17644 | | /* Disable global register allocation, |
17645 | | * register allocation for SSA variables connected through Phi functions |
17646 | | */ |
17647 | 0 | if (ssa->vars[var].definition_phi) { |
17648 | 0 | return false; |
17649 | 0 | } |
17650 | 0 | if (ssa->vars[var].phi_use_chain) { |
17651 | 0 | zend_ssa_phi *phi = ssa->vars[var].phi_use_chain; |
17652 | 0 | do { |
17653 | 0 | if (!ssa->vars[phi->ssa_var].no_val) { |
17654 | 0 | return false; |
17655 | 0 | } |
17656 | 0 | phi = zend_ssa_next_use_phi(ssa, var, phi); |
17657 | 0 | } while (phi); |
17658 | 0 | } |
17659 | 0 | } |
17660 | | |
17661 | 0 | if (((ssa->var_info[var].type & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF)) != MAY_BE_DOUBLE) && |
17662 | 0 | ((ssa->var_info[var].type & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_REF)) != MAY_BE_LONG)) { |
17663 | | /* bad type */ |
17664 | 0 | return false; |
17665 | 0 | } |
17666 | | |
17667 | 0 | return true; |
17668 | 0 | } |
17669 | | |
17670 | | static bool zend_jit_may_be_in_reg(const zend_op_array *op_array, zend_ssa *ssa, int var) |
17671 | 0 | { |
17672 | 0 | if (!zend_jit_var_supports_reg(ssa, var)) { |
17673 | 0 | return false; |
17674 | 0 | } |
17675 | | |
17676 | 0 | if (ssa->vars[var].definition >= 0) { |
17677 | 0 | uint32_t def = ssa->vars[var].definition; |
17678 | 0 | if (!zend_jit_opline_supports_reg(op_array, ssa, op_array->opcodes + def, ssa->ops + def, NULL)) { |
17679 | 0 | return false; |
17680 | 0 | } |
17681 | 0 | } |
17682 | | |
17683 | 0 | if (ssa->vars[var].use_chain >= 0) { |
17684 | 0 | int use = ssa->vars[var].use_chain; |
17685 | |
|
17686 | 0 | do { |
17687 | 0 | if (!zend_ssa_is_no_val_use(op_array->opcodes + use, ssa->ops + use, var) && |
17688 | 0 | !zend_jit_opline_supports_reg(op_array, ssa, op_array->opcodes + use, ssa->ops + use, NULL)) { |
17689 | 0 | return false; |
17690 | 0 | } |
17691 | 0 | use = zend_ssa_next_use(ssa->ops, var, use); |
17692 | 0 | } while (use >= 0); |
17693 | 0 | } |
17694 | | |
17695 | 0 | if (JIT_G(trigger) != ZEND_JIT_ON_HOT_TRACE) { |
17696 | 0 | uint32_t def_block, use_block; |
17697 | 0 | int b, use; |
17698 | 0 | uint32_t j; |
17699 | 0 | zend_basic_block *bb; |
17700 | 0 | zend_ssa_phi *p; |
17701 | 0 | bool ret = true; |
17702 | 0 | zend_worklist worklist; |
17703 | 0 | ALLOCA_FLAG(use_heap) |
17704 | | |
17705 | | /* Check if live range is split by ENTRY block */ |
17706 | 0 | if (ssa->vars[var].definition >= 0) { |
17707 | 0 | def_block =ssa->cfg.map[ssa->vars[var].definition]; |
17708 | 0 | } else { |
17709 | 0 | ZEND_ASSERT(ssa->vars[var].definition_phi); |
17710 | 0 | def_block = ssa->vars[var].definition_phi->block; |
17711 | 0 | } |
17712 | |
|
17713 | 0 | ZEND_WORKLIST_ALLOCA(&worklist, ssa->cfg.blocks_count, use_heap); |
17714 | |
|
17715 | 0 | if (ssa->vars[var].use_chain >= 0) { |
17716 | 0 | use = ssa->vars[var].use_chain; |
17717 | 0 | do { |
17718 | 0 | use_block = ssa->cfg.map[use]; |
17719 | 0 | if (use_block != def_block) { |
17720 | 0 | zend_worklist_push(&worklist, use_block); |
17721 | 0 | } |
17722 | 0 | use = zend_ssa_next_use(ssa->ops, var, use); |
17723 | 0 | } while (use >= 0); |
17724 | 0 | } |
17725 | |
|
17726 | 0 | p = ssa->vars[var].phi_use_chain; |
17727 | 0 | while (p) { |
17728 | 0 | use_block = p->block; |
17729 | 0 | if (use_block != def_block) { |
17730 | 0 | bb = &ssa->cfg.blocks[use_block]; |
17731 | 0 | for (j = 0; j < bb->predecessors_count; j++) { |
17732 | 0 | if (p->sources[j] == var) { |
17733 | 0 | use_block = ssa->cfg.predecessors[bb->predecessor_offset + j]; |
17734 | 0 | if (use_block != def_block) { |
17735 | 0 | zend_worklist_push(&worklist, use_block); |
17736 | 0 | } |
17737 | 0 | } |
17738 | 0 | } |
17739 | 0 | } |
17740 | 0 | p = zend_ssa_next_use_phi(ssa, var, p); |
17741 | 0 | } |
17742 | |
|
17743 | 0 | while (zend_worklist_len(&worklist) != 0) { |
17744 | 0 | b = zend_worklist_pop(&worklist); |
17745 | 0 | bb = &ssa->cfg.blocks[b]; |
17746 | 0 | if (bb->flags & (ZEND_BB_ENTRY|ZEND_BB_RECV_ENTRY)) { |
17747 | 0 | ret = false; |
17748 | 0 | break; |
17749 | 0 | } |
17750 | 0 | for (j = 0; j < bb->predecessors_count; j++) { |
17751 | 0 | b = ssa->cfg.predecessors[bb->predecessor_offset + j]; |
17752 | 0 | if (b != def_block) { |
17753 | 0 | zend_worklist_push(&worklist, b); |
17754 | 0 | } |
17755 | 0 | } |
17756 | 0 | } |
17757 | |
|
17758 | 0 | ZEND_WORKLIST_FREE_ALLOCA(&worklist, use_heap); |
17759 | |
|
17760 | 0 | return ret; |
17761 | 0 | } |
17762 | | |
17763 | 0 | return true; |
17764 | 0 | } |
17765 | | |
17766 | 0 | static ir_ref jit_frameless_observer(zend_jit_ctx *jit, const zend_op *opline) { |
17767 | | // JIT: zend_observer_handler_is_unobserved(ZEND_OBSERVER_DATA(fbc)) |
17768 | 0 | ir_ref observer_handler; |
17769 | 0 | zend_function *fbc = ZEND_FLF_FUNC(opline); |
17770 | | // Not need for runtime cache or generator checks here, we just need if_unobserved |
17771 | 0 | ir_ref if_unobserved = jit_observer_fcall_is_unobserved_start(jit, fbc, &observer_handler, IR_UNUSED, IR_UNUSED).if_unobserved; |
17772 | | |
17773 | | // Call zend_frameless_observed_call for the main logic. |
17774 | 0 | ir_CALL_1(IR_VOID, ir_CONST_ADDR((size_t)zend_frameless_observed_call), jit_FP(jit)); |
17775 | |
|
17776 | 0 | ir_ref skip = ir_END(); |
17777 | 0 | ir_IF_TRUE(if_unobserved); |
17778 | 0 | return skip; |
17779 | 0 | } |
17780 | | |
17781 | | static void jit_frameless_icall0(zend_jit_ctx *jit, const zend_op *opline) |
17782 | 0 | { |
17783 | 0 | jit_SET_EX_OPLINE(jit, opline); |
17784 | |
|
17785 | 0 | void *function = ZEND_FLF_HANDLER(opline); |
17786 | 0 | zend_jit_addr res_addr = RES_ADDR(); |
17787 | 0 | ir_ref res_ref = jit_ZVAL_ADDR(jit, res_addr); |
17788 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
17789 | |
|
17790 | 0 | ir_ref skip_observer = IR_UNUSED; |
17791 | 0 | if (ZEND_OBSERVER_ENABLED) { |
17792 | 0 | skip_observer = jit_frameless_observer(jit, opline); |
17793 | 0 | } |
17794 | |
|
17795 | 0 | ir_CALL_1(IR_VOID, ir_CONST_ADDR((size_t)function), res_ref); |
17796 | |
|
17797 | 0 | if (skip_observer != IR_UNUSED) { |
17798 | 0 | ir_MERGE_WITH(skip_observer); |
17799 | 0 | } |
17800 | |
|
17801 | 0 | zend_jit_check_exception(jit); |
17802 | 0 | } |
17803 | | |
17804 | | static void jit_frameless_icall1(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info) |
17805 | 0 | { |
17806 | 0 | jit_SET_EX_OPLINE(jit, opline); |
17807 | | |
17808 | | /* Avoid dropping RC check in case op escapes. */ |
17809 | 0 | if (op1_info & MAY_BE_RC1) { |
17810 | 0 | op1_info |= MAY_BE_RCN; |
17811 | 0 | } |
17812 | |
|
17813 | 0 | void *function = ZEND_FLF_HANDLER(opline); |
17814 | 0 | zend_jit_addr res_addr = RES_ADDR(); |
17815 | 0 | zend_jit_addr op1_addr = OP1_ADDR(); |
17816 | 0 | ir_ref res_ref = jit_ZVAL_ADDR(jit, res_addr); |
17817 | 0 | ir_ref op1_ref = jit_ZVAL_ADDR(jit, op1_addr); |
17818 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
17819 | 0 | if (opline->op1_type == IS_CV && (op1_info & MAY_BE_UNDEF)) { |
17820 | 0 | op1_ref = zend_jit_zval_check_undef(jit, op1_ref, opline->op1.var, opline, true); |
17821 | 0 | op1_info &= ~MAY_BE_UNDEF; |
17822 | 0 | op1_info |= MAY_BE_NULL; |
17823 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(op1_ref); |
17824 | 0 | } |
17825 | 0 | if (op1_info & MAY_BE_REF) { |
17826 | 0 | op1_ref = jit_ZVAL_DEREF_ref(jit, op1_ref); |
17827 | 0 | } |
17828 | |
|
17829 | 0 | ir_ref skip_observer = IR_UNUSED; |
17830 | 0 | if (ZEND_OBSERVER_ENABLED) { |
17831 | 0 | skip_observer = jit_frameless_observer(jit, opline); |
17832 | 0 | } |
17833 | |
|
17834 | 0 | ir_CALL_2(IR_VOID, ir_CONST_ADDR((size_t)function), res_ref, op1_ref); |
17835 | |
|
17836 | 0 | if (skip_observer != IR_UNUSED) { |
17837 | 0 | ir_MERGE_WITH(skip_observer); |
17838 | 0 | } |
17839 | |
|
17840 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL); |
17841 | 0 | zend_jit_check_exception(jit); |
17842 | 0 | } |
17843 | | |
17844 | | static void jit_frameless_icall2(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, uint32_t op2_info) |
17845 | 0 | { |
17846 | 0 | jit_SET_EX_OPLINE(jit, opline); |
17847 | | |
17848 | | /* Avoid dropping RC check in case op escapes. */ |
17849 | 0 | if (op1_info & MAY_BE_RC1) { |
17850 | 0 | op1_info |= MAY_BE_RCN; |
17851 | 0 | } |
17852 | 0 | if (op2_info & MAY_BE_RC1) { |
17853 | 0 | op2_info |= MAY_BE_RCN; |
17854 | 0 | } |
17855 | |
|
17856 | 0 | void *function = ZEND_FLF_HANDLER(opline); |
17857 | 0 | zend_jit_addr res_addr = RES_ADDR(); |
17858 | 0 | zend_jit_addr op1_addr = OP1_ADDR(); |
17859 | 0 | zend_jit_addr op2_addr = OP2_ADDR(); |
17860 | 0 | ir_ref res_ref = jit_ZVAL_ADDR(jit, res_addr); |
17861 | 0 | ir_ref op1_ref = jit_ZVAL_ADDR(jit, op1_addr); |
17862 | 0 | ir_ref op2_ref = jit_ZVAL_ADDR(jit, op2_addr); |
17863 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
17864 | 0 | if (opline->op1_type == IS_CV && (op1_info & MAY_BE_UNDEF)) { |
17865 | 0 | op1_ref = zend_jit_zval_check_undef(jit, op1_ref, opline->op1.var, opline, true); |
17866 | 0 | op1_info &= ~MAY_BE_UNDEF; |
17867 | 0 | op1_info |= MAY_BE_NULL; |
17868 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(op1_ref); |
17869 | 0 | } |
17870 | 0 | if (opline->op2_type == IS_CV && (op2_info & MAY_BE_UNDEF)) { |
17871 | 0 | op2_ref = zend_jit_zval_check_undef(jit, op2_ref, opline->op2.var, opline, true); |
17872 | 0 | op2_info &= ~MAY_BE_UNDEF; |
17873 | 0 | op2_info |= MAY_BE_NULL; |
17874 | 0 | op2_addr = ZEND_ADDR_REF_ZVAL(op2_ref); |
17875 | 0 | } |
17876 | 0 | if (op1_info & MAY_BE_REF) { |
17877 | 0 | op1_ref = jit_ZVAL_DEREF_ref(jit, op1_ref); |
17878 | 0 | } |
17879 | 0 | if (op2_info & MAY_BE_REF) { |
17880 | 0 | op2_ref = jit_ZVAL_DEREF_ref(jit, op2_ref); |
17881 | 0 | } |
17882 | |
|
17883 | 0 | ir_ref skip_observer = IR_UNUSED; |
17884 | 0 | if (ZEND_OBSERVER_ENABLED) { |
17885 | 0 | skip_observer = jit_frameless_observer(jit, opline); |
17886 | 0 | } |
17887 | |
|
17888 | 0 | ir_CALL_3(IR_VOID, ir_CONST_ADDR((size_t)function), res_ref, op1_ref, op2_ref); |
17889 | |
|
17890 | 0 | if (skip_observer != IR_UNUSED) { |
17891 | 0 | ir_MERGE_WITH(skip_observer); |
17892 | 0 | } |
17893 | |
|
17894 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL); |
17895 | | /* Set OP1 to UNDEF in case FREE_OP2() throws. */ |
17896 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) != 0 |
17897 | 0 | && (opline->op2_type & (IS_VAR|IS_TMP_VAR)) != 0 |
17898 | 0 | && (op2_info & MAY_BE_RC1) |
17899 | 0 | && (op2_info & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY))) { |
17900 | 0 | jit_set_Z_TYPE_INFO(jit, op1_addr, IS_UNDEF); |
17901 | 0 | if (JIT_G(current_frame)) { |
17902 | 0 | SET_STACK_TYPE(JIT_G(current_frame)->stack, |
17903 | 0 | EX_VAR_TO_NUM(opline->op1.var), IS_UNKNOWN, 1); |
17904 | 0 | } |
17905 | 0 | } |
17906 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, NULL); |
17907 | 0 | zend_jit_check_exception(jit); |
17908 | 0 | } |
17909 | | |
17910 | | static void jit_frameless_icall3(zend_jit_ctx *jit, const zend_op *opline, uint32_t op1_info, uint32_t op2_info, uint32_t op1_data_info) |
17911 | 0 | { |
17912 | 0 | jit_SET_EX_OPLINE(jit, opline); |
17913 | | |
17914 | | /* Avoid dropping RC check in case op escapes. */ |
17915 | 0 | if (op1_info & MAY_BE_RC1) { |
17916 | 0 | op1_info |= MAY_BE_RCN; |
17917 | 0 | } |
17918 | 0 | if (op2_info & MAY_BE_RC1) { |
17919 | 0 | op2_info |= MAY_BE_RCN; |
17920 | 0 | } |
17921 | 0 | if (op1_data_info & MAY_BE_RC1) { |
17922 | 0 | op1_data_info |= MAY_BE_RCN; |
17923 | 0 | } |
17924 | |
|
17925 | 0 | void *function = ZEND_FLF_HANDLER(opline); |
17926 | 0 | uint8_t op_data_type = (opline + 1)->op1_type; |
17927 | 0 | zend_jit_addr res_addr = RES_ADDR(); |
17928 | 0 | zend_jit_addr op1_addr = OP1_ADDR(); |
17929 | 0 | zend_jit_addr op2_addr = OP2_ADDR(); |
17930 | 0 | zend_jit_addr op3_addr = OP1_DATA_ADDR(); |
17931 | 0 | ir_ref res_ref = jit_ZVAL_ADDR(jit, res_addr); |
17932 | 0 | ir_ref op1_ref = jit_ZVAL_ADDR(jit, op1_addr); |
17933 | 0 | ir_ref op2_ref = jit_ZVAL_ADDR(jit, op2_addr); |
17934 | 0 | ir_ref op3_ref = jit_ZVAL_ADDR(jit, op3_addr); |
17935 | 0 | jit_set_Z_TYPE_INFO(jit, res_addr, IS_NULL); |
17936 | 0 | if (opline->op1_type == IS_CV && (op1_info & MAY_BE_UNDEF)) { |
17937 | 0 | op1_ref = zend_jit_zval_check_undef(jit, op1_ref, opline->op1.var, opline, true); |
17938 | 0 | op1_info &= ~MAY_BE_UNDEF; |
17939 | 0 | op1_info |= MAY_BE_NULL; |
17940 | 0 | op1_addr = ZEND_ADDR_REF_ZVAL(op1_ref); |
17941 | 0 | } |
17942 | 0 | if (opline->op2_type == IS_CV && (op2_info & MAY_BE_UNDEF)) { |
17943 | 0 | op2_ref = zend_jit_zval_check_undef(jit, op2_ref, opline->op2.var, opline, true); |
17944 | 0 | op2_info &= ~MAY_BE_UNDEF; |
17945 | 0 | op2_info |= MAY_BE_NULL; |
17946 | 0 | op2_addr = ZEND_ADDR_REF_ZVAL(op2_ref); |
17947 | 0 | } |
17948 | 0 | if ((opline+1)->op1_type == IS_CV && (op1_data_info & MAY_BE_UNDEF)) { |
17949 | 0 | op3_ref = zend_jit_zval_check_undef(jit, op3_ref, (opline+1)->op1.var, opline, true); |
17950 | 0 | op1_data_info &= ~MAY_BE_UNDEF; |
17951 | 0 | op1_data_info |= MAY_BE_NULL; |
17952 | 0 | op3_addr = ZEND_ADDR_REF_ZVAL(op3_ref); |
17953 | 0 | } |
17954 | 0 | if (op1_info & MAY_BE_REF) { |
17955 | 0 | op1_ref = jit_ZVAL_DEREF_ref(jit, op1_ref); |
17956 | 0 | } |
17957 | 0 | if (op2_info & MAY_BE_REF) { |
17958 | 0 | op2_ref = jit_ZVAL_DEREF_ref(jit, op2_ref); |
17959 | 0 | } |
17960 | 0 | if (op1_data_info & MAY_BE_REF) { |
17961 | 0 | op3_ref = jit_ZVAL_DEREF_ref(jit, op3_ref); |
17962 | 0 | } |
17963 | |
|
17964 | 0 | ir_ref skip_observer = IR_UNUSED; |
17965 | 0 | if (ZEND_OBSERVER_ENABLED) { |
17966 | 0 | skip_observer = jit_frameless_observer(jit, opline); |
17967 | 0 | } |
17968 | |
|
17969 | 0 | ir_CALL_4(IR_VOID, ir_CONST_ADDR((size_t)function), res_ref, op1_ref, op2_ref, op3_ref); |
17970 | |
|
17971 | 0 | if (skip_observer != IR_UNUSED) { |
17972 | 0 | ir_MERGE_WITH(skip_observer); |
17973 | 0 | } |
17974 | |
|
17975 | 0 | jit_FREE_OP(jit, opline->op1_type, opline->op1, op1_info, NULL); |
17976 | | /* Set OP1 to UNDEF in case FREE_OP2() throws. */ |
17977 | 0 | bool op1_undef = false; |
17978 | 0 | if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) |
17979 | 0 | && (((opline->op2_type & (IS_VAR|IS_TMP_VAR)) |
17980 | 0 | && (op2_info & MAY_BE_RC1) |
17981 | 0 | && (op2_info & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY))) |
17982 | 0 | || ((op_data_type & (IS_VAR|IS_TMP_VAR)) |
17983 | 0 | && (op1_data_info & MAY_BE_RC1) |
17984 | 0 | && (op1_data_info & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY))))) { |
17985 | 0 | op1_undef = true; |
17986 | 0 | jit_set_Z_TYPE_INFO(jit, op1_addr, IS_UNDEF); |
17987 | 0 | if (JIT_G(current_frame)) { |
17988 | 0 | SET_STACK_TYPE(JIT_G(current_frame)->stack, |
17989 | 0 | EX_VAR_TO_NUM(opline->op1.var), IS_UNKNOWN, 1); |
17990 | 0 | } |
17991 | 0 | } |
17992 | 0 | jit_FREE_OP(jit, opline->op2_type, opline->op2, op2_info, NULL); |
17993 | | /* If OP1 is set to UNDEF, we don't need to set OP2 to UNDEF on free because |
17994 | | * zend_fetch_debug_backtrace aborts when it encounters the first UNDEF TMP|VAR. */ |
17995 | 0 | if (!op1_undef |
17996 | 0 | && (opline->op2_type & (IS_VAR|IS_TMP_VAR)) != 0 |
17997 | 0 | && (op_data_type & (IS_VAR|IS_TMP_VAR)) != 0 |
17998 | 0 | && (op1_data_info & MAY_BE_RC1) |
17999 | 0 | && (op1_data_info & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY))) { |
18000 | 0 | jit_set_Z_TYPE_INFO(jit, op2_addr, IS_UNDEF); |
18001 | 0 | if (JIT_G(current_frame)) { |
18002 | 0 | SET_STACK_TYPE(JIT_G(current_frame)->stack, |
18003 | 0 | EX_VAR_TO_NUM(opline->op2.var), IS_UNKNOWN, 1); |
18004 | 0 | } |
18005 | 0 | } |
18006 | | jit_FREE_OP(jit, (opline+1)->op1_type, (opline+1)->op1, op1_data_info, NULL); |
18007 | 0 | zend_jit_check_exception(jit); |
18008 | 0 | } |
18009 | | |
18010 | | /* |
18011 | | * Local variables: |
18012 | | * tab-width: 4 |
18013 | | * c-basic-offset: 4 |
18014 | | * indent-tabs-mode: t |
18015 | | * End: |
18016 | | */ |