Skip to content

Commit 9c0ca38

Browse files
committed
Update IR
IR commit: ed4fd9e5efeb676e88b29c40893d7e8154cab44b
1 parent f283f50 commit 9c0ca38

File tree

4 files changed

+66
-20
lines changed

4 files changed

+66
-20
lines changed

ext/opcache/jit/ir/ir.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ void ir_strtab_free(ir_strtab *strtab);
507507
#define IR_GEN_NATIVE (1<<19)
508508
#define IR_GEN_CODE (1<<20) /* C or LLVM */
509509

510+
#define IR_GEN_CACHE_DEMOTE (1<<21) /* Demote the generated code from closest CPU caches */
511+
510512
/* debug related */
511513
#ifdef IR_DEBUG
512514
# define IR_DEBUG_SCCP (1<<27)
@@ -837,14 +839,15 @@ int ir_patch(const void *code, size_t size, uint32_t jmp_table_size, const void
837839

838840
/* CPU information (implementation in ir_cpuinfo.c) */
839841
#if defined(IR_TARGET_X86) || defined(IR_TARGET_X64)
840-
# define IR_X86_SSE2 (1<<0)
841-
# define IR_X86_SSE3 (1<<1)
842-
# define IR_X86_SSSE3 (1<<2)
843-
# define IR_X86_SSE41 (1<<3)
844-
# define IR_X86_SSE42 (1<<4)
845-
# define IR_X86_AVX (1<<5)
846-
# define IR_X86_AVX2 (1<<6)
847-
# define IR_X86_BMI1 (1<<7)
842+
# define IR_X86_SSE2 (1<<0)
843+
# define IR_X86_SSE3 (1<<1)
844+
# define IR_X86_SSSE3 (1<<2)
845+
# define IR_X86_SSE41 (1<<3)
846+
# define IR_X86_SSE42 (1<<4)
847+
# define IR_X86_AVX (1<<5)
848+
# define IR_X86_AVX2 (1<<6)
849+
# define IR_X86_BMI1 (1<<7)
850+
# define IR_X86_CLDEMOTE (1<<8)
848851
#endif
849852

850853
uint32_t ir_cpuinfo(void);

ext/opcache/jit/ir/ir_aarch64.dasc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4102,10 +4102,19 @@ static int32_t ir_call_used_stack(ir_ctx *ctx, ir_insn *insn)
41024102
int int_reg_params_count = IR_REG_INT_ARGS;
41034103
int fp_reg_params_count = IR_REG_FP_ARGS;
41044104
int32_t used_stack = 0;
4105+
#ifdef __APPLE__
4106+
const ir_proto_t *proto = ir_call_proto(ctx, insn);
4107+
int last_named_input = (proto && (proto->flags & IR_VARARG_FUNC)) ? proto->params_count + 2 : insn->inputs_count;
4108+
#endif
41054109

41064110
n = insn->inputs_count;
41074111
for (j = 3; j <= n; j++) {
41084112
type = ctx->ir_base[ir_insn_op(insn, j)].type;
4113+
#ifdef __APPLE__
4114+
if (j > last_named_input) {
4115+
used_stack += IR_MAX(sizeof(void*), ir_type_size[type]);
4116+
} else
4117+
#endif
41094118
if (IR_IS_TYPE_INT(type)) {
41104119
if (int_param >= int_reg_params_count) {
41114120
used_stack += IR_MAX(sizeof(void*), ir_type_size[type]);
@@ -4171,6 +4180,11 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
41714180
}
41724181
}
41734182

4183+
#ifdef __APPLE__
4184+
const ir_proto_t *proto = ir_call_proto(ctx, insn);
4185+
int last_named_input = (proto && (proto->flags & IR_VARARG_FUNC)) ? proto->params_count + 2 : insn->inputs_count;
4186+
#endif
4187+
41744188
/* 1. move all register arguments that should be passed through stack
41754189
* and collect arguments that should be passed through registers */
41764190
copies = ir_mem_malloc((n - 2) * sizeof(ir_copy));
@@ -4179,6 +4193,11 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
41794193
src_reg = ir_get_alocated_reg(ctx, def, j);
41804194
arg_insn = &ctx->ir_base[arg];
41814195
type = arg_insn->type;
4196+
#ifdef __APPLE__
4197+
if (j > last_named_input) {
4198+
dst_reg = IR_REG_NONE; /* pass argument through stack */
4199+
} else
4200+
#endif
41824201
if (IR_IS_TYPE_INT(type)) {
41834202
if (int_param < int_reg_params_count) {
41844203
dst_reg = int_reg_params[int_param];
@@ -4244,6 +4263,11 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
42444263
src_reg = ir_get_alocated_reg(ctx, def, j);
42454264
arg_insn = &ctx->ir_base[arg];
42464265
type = arg_insn->type;
4266+
#ifdef __APPLE__
4267+
if (j > last_named_input) {
4268+
dst_reg = IR_REG_NONE; /* pass argument through stack */
4269+
} else
4270+
#endif
42474271
if (IR_IS_TYPE_INT(type)) {
42484272
if (int_param < int_reg_params_count) {
42494273
dst_reg = int_reg_params[int_param];

ext/opcache/jit/ir/ir_emit.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ static const int8_t _ir_fp_reg_params[IR_REG_FP_ARGS];
6666
static const int8_t *_ir_fp_reg_params;
6767
#endif
6868

69+
static const ir_proto_t *ir_call_proto(const ir_ctx *ctx, ir_insn *insn)
70+
{
71+
if (IR_IS_CONST_REF(insn->op2)) {
72+
const ir_insn *func = &ctx->ir_base[insn->op2];
73+
74+
if (func->op == IR_FUNC || func->op == IR_FUNC_ADDR) {
75+
if (func->proto) {
76+
return (const ir_proto_t *)ir_get_str(ctx, func->proto);
77+
}
78+
}
79+
} else if (ctx->ir_base[insn->op2].op == IR_PROTO) {
80+
return (const ir_proto_t *)ir_get_str(ctx, ctx->ir_base[insn->op2].op2);
81+
}
82+
return NULL;
83+
}
84+
6985
#ifdef IR_HAVE_FASTCALL
7086
static const int8_t _ir_int_fc_reg_params[IR_REG_INT_FCARGS];
7187
static const int8_t *_ir_fp_fc_reg_params;
@@ -101,19 +117,9 @@ bool ir_is_fastcall(const ir_ctx *ctx, const ir_insn *insn)
101117

102118
bool ir_is_vararg(const ir_ctx *ctx, ir_insn *insn)
103119
{
104-
if (IR_IS_CONST_REF(insn->op2)) {
105-
const ir_insn *func = &ctx->ir_base[insn->op2];
106-
107-
if (func->op == IR_FUNC || func->op == IR_FUNC_ADDR) {
108-
if (func->proto) {
109-
const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, func->proto);
110-
111-
return (proto->flags & IR_VARARG_FUNC) != 0;
112-
}
113-
}
114-
} else if (ctx->ir_base[insn->op2].op == IR_PROTO) {
115-
const ir_proto_t *proto = (const ir_proto_t *)ir_get_str(ctx, ctx->ir_base[insn->op2].op2);
120+
const ir_proto_t *proto = ir_call_proto(ctx, insn);
116121

122+
if (proto) {
117123
return (proto->flags & IR_VARARG_FUNC) != 0;
118124
}
119125
return 0;

ext/opcache/jit/ir/ir_x86.dasc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9717,6 +9717,19 @@ next_block:;
97179717

97189718
ir_mem_flush(entry, size);
97199719

9720+
#if defined(__GNUC__)
9721+
if ((ctx->flags & IR_GEN_CACHE_DEMOTE) && (ctx->mflags & IR_X86_CLDEMOTE)) {
9722+
uintptr_t start = (uintptr_t)entry;
9723+
uintptr_t p = (uintptr_t)start & ~0x3F;
9724+
9725+
do {
9726+
/* _cldemote(p); */
9727+
asm volatile(".byte 0x0f, 0x1c, 0x06" :: "S" (p));
9728+
p += 64;
9729+
} while (p < start + size);
9730+
}
9731+
#endif
9732+
97209733
if (ctx->code_buffer == NULL) {
97219734
ir_mem_protect(entry, size);
97229735
}

0 commit comments

Comments
 (0)