Skip to content

Commit 24fa223

Browse files
committed
JIT/FFI better support for temporary POINTER types
1 parent b43811f commit 24fa223

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ typedef struct zend_jit_ffi_info {
5656
uint32_t info;
5757
} zend_jit_ffi_info;
5858

59+
static zend_ffi_type *zend_jit_ffi_type_pointer_to(const zend_ffi_type *type, zend_ffi_type *holder)
60+
{
61+
holder->kind = ZEND_FFI_TYPE_POINTER;
62+
holder->attr = 0;
63+
holder->size = sizeof(void*);
64+
holder->align = _Alignof(void*);
65+
holder->pointer.type = ZEND_FFI_TYPE(type);
66+
return holder;
67+
}
68+
5969
static bool zend_jit_ffi_supported_type(zend_ffi_type *type)
6070
{
6171
if (sizeof(void*) == 4) {

ext/opcache/jit/zend_jit_ir.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17365,13 +17365,18 @@ static bool zend_jit_opline_supports_reg(const zend_op_array *op_array, zend_ssa
1736517365
&& (trace+1)->op == ZEND_JIT_TRACE_OP1_TYPE
1736617366
&& (trace+2)->op == ZEND_JIT_TRACE_OP1_FFI_TYPE) {
1736717367
zend_ffi_type *op1_ffi_type = (zend_ffi_type*)(trace+2)->ptr;
17368-
if (op1_ffi_type
17369-
&& (op1_ffi_type->kind == ZEND_FFI_TYPE_ARRAY || op1_ffi_type->kind == ZEND_FFI_TYPE_POINTER)
17370-
&& op2_info == MAY_BE_LONG
17371-
&& ZEND_FFI_TYPE(op1_ffi_type->array.type)->kind < ZEND_FFI_TYPE_POINTER
17372-
&& ZEND_FFI_TYPE(op1_ffi_type->array.type)->kind != ZEND_FFI_TYPE_VOID
17373-
&& zend_jit_ffi_supported_type(ZEND_FFI_TYPE(op1_ffi_type->array.type))) {
17374-
return 1;
17368+
if (op1_ffi_type) {
17369+
zend_ffi_type holder;
17370+
if (ZEND_FFI_TYPE_IS_OWNED(op1_ffi_type)) {
17371+
op1_ffi_type = zend_jit_ffi_type_pointer_to(op1_ffi_type, &holder);
17372+
}
17373+
if ((op1_ffi_type->kind == ZEND_FFI_TYPE_ARRAY || op1_ffi_type->kind == ZEND_FFI_TYPE_POINTER)
17374+
&& op2_info == MAY_BE_LONG
17375+
&& ZEND_FFI_TYPE(op1_ffi_type->array.type)->kind < ZEND_FFI_TYPE_POINTER
17376+
&& ZEND_FFI_TYPE(op1_ffi_type->array.type)->kind != ZEND_FFI_TYPE_VOID
17377+
&& zend_jit_ffi_supported_type(ZEND_FFI_TYPE(op1_ffi_type->array.type))) {
17378+
return 1;
17379+
}
1737517380
}
1737617381
}
1737717382
#endif
@@ -17428,17 +17433,25 @@ static bool zend_jit_opline_supports_reg(const zend_op_array *op_array, zend_ssa
1742817433
zend_ffi_type *op1_ffi_type = (zend_ffi_type*)(trace+2)->ptr;
1742917434
zend_ffi_type *op3_ffi_type = NULL;
1743017435
uint32_t op1_data_info = OP1_DATA_INFO();
17436+
zend_ffi_type holder, holder2;
1743117437

1743217438
if ((trace+3)->op == ZEND_JIT_TRACE_OP3_TYPE
1743317439
&& (trace+4)->op == ZEND_JIT_TRACE_OP3_FFI_TYPE) {
1743417440
op3_ffi_type = (zend_ffi_type*)(trace+4)->ptr;
17441+
if (ZEND_FFI_TYPE_IS_OWNED(op3_ffi_type)) {
17442+
op3_ffi_type = zend_jit_ffi_type_pointer_to(op3_ffi_type, &holder2);
17443+
}
1743517444
}
1743617445

17437-
if (op1_ffi_type
17438-
&& (op1_ffi_type->kind == ZEND_FFI_TYPE_ARRAY || op1_ffi_type->kind == ZEND_FFI_TYPE_POINTER)
17439-
&& op2_info == MAY_BE_LONG
17440-
&& zend_jit_ffi_compatible(op1_ffi_type->array.type, op1_data_info, op3_ffi_type)) {
17441-
return 1;
17446+
if (op1_ffi_type) {
17447+
if (ZEND_FFI_TYPE_IS_OWNED(op1_ffi_type)) {
17448+
op1_ffi_type = zend_jit_ffi_type_pointer_to(op1_ffi_type, &holder);
17449+
}
17450+
if ((op1_ffi_type->kind == ZEND_FFI_TYPE_ARRAY || op1_ffi_type->kind == ZEND_FFI_TYPE_POINTER)
17451+
&& op2_info == MAY_BE_LONG
17452+
&& zend_jit_ffi_compatible(op1_ffi_type->array.type, op1_data_info, op3_ffi_type)) {
17453+
return 1;
17454+
}
1744217455
}
1744317456
}
1744417457
#endif

ext/opcache/jit/zend_jit_ir_ffi.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@
1616
* +----------------------------------------------------------------------+
1717
*/
1818

19-
20-
static zend_ffi_type *zend_jit_ffi_type_pointer_to(const zend_ffi_type *type, zend_ffi_type *holder)
21-
{
22-
holder->kind = ZEND_FFI_TYPE_POINTER;
23-
holder->attr = 0;
24-
holder->size = sizeof(void*);
25-
holder->align = _Alignof(void*);
26-
holder->pointer.type = ZEND_FFI_TYPE(type);
27-
return holder;
28-
}
29-
3019
static ir_ref jit_FFI_CDATA_PTR(zend_jit_ctx *jit, ir_ref obj_ref)
3120
{
3221
return ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_ffi_cdata, ptr)));
@@ -125,12 +114,6 @@ static int zend_jit_ffi_send_val(zend_jit_ctx *jit,
125114
ir_ref ref = IR_UNUSED;
126115
uint8_t arg_type = IS_UNDEF;
127116
uint8_t arg_flags = 0;
128-
zend_ffi_type type_holder;
129-
130-
if (ZEND_FFI_TYPE_IS_OWNED(op1_ffi_type)) {
131-
/* OWNED flag means POINTER TO */
132-
op1_ffi_type = zend_jit_ffi_type_pointer_to(op1_ffi_type, &type_holder);
133-
}
134117

135118
ZEND_ASSERT(type->kind == ZEND_FFI_TYPE_FUNC);
136119
if (type->attr & ZEND_FFI_ATTR_VARIADIC) {

ext/opcache/jit/zend_jit_trace.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4415,6 +4415,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
44154415
zend_ffi_type *op1_ffi_type = NULL;
44164416
zend_ffi_type *op2_ffi_type = NULL;
44174417
zend_ffi_type *op3_ffi_type = NULL;
4418+
zend_ffi_type holder1, holder2, holder3;
44184419
HashTable *op1_ffi_symbols = NULL;
44194420
(void)op2_ffi_type;
44204421
#endif
@@ -4441,6 +4442,9 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
44414442
#ifdef HAVE_FFI
44424443
if ((p+1)->op == ZEND_JIT_TRACE_OP1_FFI_TYPE) {
44434444
op1_ffi_type = (zend_ffi_type*)(p+1)->ptr;
4445+
if (ZEND_FFI_TYPE_IS_OWNED(op1_ffi_type)) {
4446+
op1_ffi_type = zend_jit_ffi_type_pointer_to(op1_ffi_type, &holder1);
4447+
}
44444448
p++;
44454449
} else if ((p+1)->op == ZEND_JIT_TRACE_OP1_FFI_SYMBOLS) {
44464450
op1_ffi_symbols = (HashTable*)(p+1)->ptr;
@@ -4454,6 +4458,9 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
44544458
#ifdef HAVE_FFI
44554459
if ((p+1)->op == ZEND_JIT_TRACE_OP2_FFI_TYPE) {
44564460
op2_ffi_type = (zend_ffi_type*)(p+1)->ptr;
4461+
if (ZEND_FFI_TYPE_IS_OWNED(op2_ffi_type)) {
4462+
op2_ffi_type = zend_jit_ffi_type_pointer_to(op2_ffi_type, &holder2);
4463+
}
44574464
p++;
44584465
}
44594466
#endif
@@ -4464,6 +4471,9 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
44644471
#ifdef HAVE_FFI
44654472
if ((p+1)->op == ZEND_JIT_TRACE_OP3_FFI_TYPE) {
44664473
op3_ffi_type = (zend_ffi_type*)(p+1)->ptr;
4474+
if (ZEND_FFI_TYPE_IS_OWNED(op3_ffi_type)) {
4475+
op3_ffi_type = zend_jit_ffi_type_pointer_to(op3_ffi_type, &holder3);
4476+
}
44674477
p++;
44684478
}
44694479
#endif

0 commit comments

Comments
 (0)