Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ce96aa9

Browse files
committed
Update IR
IR commit: f7c0ddb1b4630e1287b0239f85d64a6965dfea29
1 parent 1e770d1 commit ce96aa9

File tree

9 files changed

+331
-92
lines changed

9 files changed

+331
-92
lines changed

‎ext/opcache/jit/ir/ir.c‎

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ ir_ref ir_unique_const_addr(ir_ctx *ctx, uintptr_t addr)
488488
return ref;
489489
}
490490

491-
staticIR_NEVER_INLINEir_ref ir_const_ex(ir_ctx *ctx, ir_val val, uint8_t type, uint32_t optx)
491+
ir_ref ir_const_ex(ir_ctx *ctx, ir_val val, uint8_t type, uint32_t optx)
492492
{
493493
ir_insn *insn, *prev_insn;
494494
ir_ref ref, prev;
@@ -1499,7 +1499,7 @@ ir_ref ir_addrtab_find(const ir_hashtab *tab, uint64_t key)
14991499
return IR_INVALID_VAL;
15001500
}
15011501

1502-
boolir_addrtab_add(ir_hashtab *tab, uint64_t key, ir_ref val)
1502+
voidir_addrtab_set(ir_hashtab *tab, uint64_t key, ir_ref val)
15031503
{
15041504
char *data = (char*)tab->data;
15051505
uint32_t pos = ((uint32_t*)data)[(int32_t)(key | tab->mask)];
@@ -1508,7 +1508,8 @@ bool ir_addrtab_add(ir_hashtab *tab, uint64_t key, ir_ref val)
15081508
while (pos != IR_INVALID_IDX) {
15091509
p = (ir_addrtab_bucket*)(data + pos);
15101510
if (p->key == key) {
1511-
return p->val == val;
1511+
p->val = val;
1512+
return;
15121513
}
15131514
pos = p->next;
15141515
}
@@ -1527,7 +1528,6 @@ bool ir_addrtab_add(ir_hashtab *tab, uint64_t key, ir_ref val)
15271528
key |= tab->mask;
15281529
p->next = ((uint32_t*)data)[(int32_t)key];
15291530
((uint32_t*)data)[(int32_t)key] = pos;
1530-
return 1;
15311531
}
15321532

15331533
/* Memory API */
@@ -1977,6 +1977,18 @@ ir_ref _ir_END_LIST(ir_ctx *ctx, ir_ref list)
19771977
return ref;
19781978
}
19791979

1980+
ir_ref _ir_END_PHI_LIST(ir_ctx *ctx, ir_ref list, ir_ref val)
1981+
{
1982+
ir_ref ref;
1983+
1984+
IR_ASSERT(ctx->control);
1985+
IR_ASSERT(!list || ctx->ir_base[list].op == IR_END);
1986+
/* create a liked list of END nodes with the same destination through END.op2 */
1987+
ref = ir_emit3(ctx, IR_END, ctx->control, list, val);
1988+
ctx->control = IR_UNUSED;
1989+
return ref;
1990+
}
1991+
19801992
void _ir_MERGE_LIST(ir_ctx *ctx, ir_ref list)
19811993
{
19821994
ir_ref ref = list;
@@ -2016,6 +2028,41 @@ void _ir_MERGE_LIST(ir_ctx *ctx, ir_ref list)
20162028
}
20172029
}
20182030

2031+
ir_ref _ir_PHI_LIST(ir_ctx *ctx, ir_ref list)
2032+
{
2033+
ir_insn *merge, *end;
2034+
ir_ref phi, *ops, i;
2035+
ir_type type;
2036+
2037+
if (list == IR_UNUSED) {
2038+
return IR_UNUSED;
2039+
}
2040+
end = &ctx->ir_base[list];
2041+
if (!end->op2) {
2042+
phi = end->op3;
2043+
end->op3 = IR_UNUSED;
2044+
_ir_BEGIN(ctx, list);
2045+
} else if (!end->op3) {
2046+
_ir_MERGE_LIST(ctx, list);
2047+
phi = IR_UNUSED;
2048+
} else {
2049+
type = ctx->ir_base[end->op3].type;
2050+
_ir_MERGE_LIST(ctx, list);
2051+
merge = &ctx->ir_base[ctx->control];
2052+
IR_ASSERT(merge->op == IR_MERGE);
2053+
phi = ir_emit_N(ctx, IR_OPT(IR_PHI, type), merge->inputs_count + 1);
2054+
merge = &ctx->ir_base[ctx->control];
2055+
ops = merge->ops;
2056+
ir_set_op(ctx, phi, 1, ctx->control);
2057+
for (i = 0; i < merge->inputs_count; i++) {
2058+
end = &ctx->ir_base[ops[i + 1]];
2059+
ir_set_op(ctx, phi, i + 2, end->op3);
2060+
end->op3 = IR_END;
2061+
}
2062+
}
2063+
return phi;
2064+
}
2065+
20192066
ir_ref _ir_LOOP_BEGIN(ir_ctx *ctx, ir_ref src1)
20202067
{
20212068
IR_ASSERT(!ctx->control);

‎ext/opcache/jit/ir/ir.h‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,14 @@ void ir_strtab_free(ir_strtab *strtab);
501501
#define IR_GEN_ENDBR (1<<14)
502502
#define IR_MERGE_EMPTY_ENTRIES (1<<15)
503503

504-
#define IR_OPT_FOLDING (1<<16)
505-
#define IR_OPT_CFG (1<<17) /* merge BBs, by remove END->BEGIN nodes during CFG construction */
506-
#define IR_OPT_CODEGEN (1<<18)
507-
#define IR_GEN_NATIVE (1<<19)
508-
#define IR_GEN_CODE (1<<20) /* C or LLVM */
509-
510-
#define IR_GEN_CACHE_DEMOTE (1<<21) /* Demote the generated code from closest CPU caches */
504+
#define IR_OPT_INLINE (1<<16)
505+
#define IR_OPT_FOLDING (1<<17)
506+
#define IR_OPT_CFG (1<<18) /* merge BBs, by remove END->BEGIN nodes during CFG construction */
507+
#define IR_OPT_CODEGEN (1<<19)
508+
#define IR_GEN_NATIVE (1<<20)
509+
#define IR_GEN_CODE (1<<21) /* C or LLVM */
510+
511+
#define IR_GEN_CACHE_DEMOTE (1<<22) /* Demote the generated code from closest CPU caches */
511512

512513
/* debug related */
513514
#ifdef IR_DEBUG

‎ext/opcache/jit/ir/ir_aarch64.dasc‎

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ int ir_get_target_constraints(ir_ctx *ctx, ir_ref ref, ir_target_constraints *co
561561
n++;
562562
}
563563
}
564-
flags = IR_USE_SHOULD_BE_IN_REG | IR_OP2_SHOULD_BE_IN_REG | IR_OP3_SHOULD_BE_IN_REG;
564+
flags = IR_USE_SHOULD_BE_IN_REG | IR_OP2_MUST_BE_IN_REG | IR_OP3_SHOULD_BE_IN_REG;
565565
break;
566566
case IR_COND:
567567
insn = &ctx->ir_base[ref];
@@ -3953,6 +3953,10 @@ static void ir_emit_alloca(ir_ctx *ctx, ir_ref def, ir_insn *insn)
39533953
dasm_State **Dst = &data->dasm_state;
39543954
ir_reg def_reg = IR_REG_NUM(ctx->regs[def][0]);
39553955

3956+
if (ctx->use_lists[def].count == 1) {
3957+
/* dead alloca */
3958+
return;
3959+
}
39563960
if (IR_IS_CONST_REF(insn->op2)) {
39573961
ir_insn *val = &ctx->ir_base[insn->op2];
39583962
int32_t size = val->val.i32;
@@ -4314,16 +4318,18 @@ static void ir_emit_switch(ir_ctx *ctx, uint32_t b, ir_ref def, ir_insn *insn)
43144318
}
43154319
}
43164320

4317-
if (aarch64_may_encode_imm12(max.i64)) {
4318-
| ASM_REG_IMM_OP cmp, type, op2_reg, max.i64
4319-
} else {
4320-
ir_emit_load_imm_int(ctx, type, tmp_reg, max.i64);
4321-
| ASM_REG_REG_OP cmp, type, op2_reg, tmp_reg
4322-
}
4323-
if (IR_IS_TYPE_SIGNED(type)) {
4324-
| bgt =>default_label
4325-
} else {
4326-
| bhi =>default_label
4321+
if (default_label) {
4322+
if (aarch64_may_encode_imm12(max.i64)) {
4323+
| ASM_REG_IMM_OP cmp, type, op2_reg, max.i64
4324+
} else {
4325+
ir_emit_load_imm_int(ctx, type, tmp_reg, max.i64);
4326+
| ASM_REG_REG_OP cmp, type, op2_reg, tmp_reg
4327+
}
4328+
if (IR_IS_TYPE_SIGNED(type)) {
4329+
| bgt =>default_label
4330+
} else {
4331+
| bhi =>default_label
4332+
}
43274333
}
43284334

43294335
if (op1_reg == IR_REG_NONE) {
@@ -4335,11 +4341,15 @@ static void ir_emit_switch(ir_ctx *ctx, uint32_t b, ir_ref def, ir_insn *insn)
43354341
ir_emit_load_imm_int(ctx, type, tmp_reg, min.i64);
43364342
| ASM_REG_REG_REG_OP subs, type, op1_reg, op2_reg, tmp_reg
43374343
}
4338-
if (IR_IS_TYPE_SIGNED(type)) {
4339-
| blt =>default_label
4340-
} else {
4341-
| blo =>default_label
4344+
4345+
if (default_label) {
4346+
if (IR_IS_TYPE_SIGNED(type)) {
4347+
| blt =>default_label
4348+
} else {
4349+
| blo =>default_label
4350+
}
43424351
}
4352+
43434353
| adr Rx(tmp_reg), >1
43444354
| ldr Rx(tmp_reg), [Rx(tmp_reg), Rx(op1_reg), lsl #3]
43454355
| br Rx(tmp_reg)
@@ -4352,25 +4362,29 @@ static void ir_emit_switch(ir_ctx *ctx, uint32_t b, ir_ref def, ir_insn *insn)
43524362
|1:
43534363
for (i = 0; i <= (max.i64 - min.i64); i++) {
43544364
int b = labels[i];
4355-
ir_block *bb = &ctx->cfg_blocks[b];
4356-
ir_insn *insn = &ctx->ir_base[bb->end];
4357-
4358-
if (insn->op == IR_IJMP && IR_IS_CONST_REF(insn->op2)) {
4359-
ir_ref prev = ctx->prev_ref[bb->end];
4360-
if (prev != bb->start && ctx->ir_base[prev].op == IR_SNAPSHOT) {
4361-
prev = ctx->prev_ref[prev];
4362-
}
4363-
if (prev == bb->start) {
4364-
void *addr = ir_jmp_addr(ctx, insn, &ctx->ir_base[insn->op2]);
4365+
if (b) {
4366+
ir_block *bb = &ctx->cfg_blocks[b];
4367+
ir_insn *insn = &ctx->ir_base[bb->end];
4368+
4369+
if (insn->op == IR_IJMP && IR_IS_CONST_REF(insn->op2)) {
4370+
ir_ref prev = ctx->prev_ref[bb->end];
4371+
if (prev != bb->start && ctx->ir_base[prev].op == IR_SNAPSHOT) {
4372+
prev = ctx->prev_ref[prev];
4373+
}
4374+
if (prev == bb->start) {
4375+
void *addr = ir_jmp_addr(ctx, insn, &ctx->ir_base[insn->op2]);
43654376

4366-
| .addr &addr
4367-
if (ctx->ir_base[bb->start].op != IR_CASE_DEFAULT) {
4368-
bb->flags |= IR_BB_EMPTY;
4377+
| .addr &addr
4378+
if (ctx->ir_base[bb->start].op != IR_CASE_DEFAULT) {
4379+
bb->flags |= IR_BB_EMPTY;
4380+
}
4381+
continue;
43694382
}
4370-
continue;
43714383
}
4384+
| .addr =>b
4385+
} else {
4386+
| .addr 0
43724387
}
4373-
| .addr =>b
43744388
}
43754389
|.code
43764390
ir_mem_free(labels);
@@ -5187,7 +5201,9 @@ static void ir_emit_load_params(ir_ctx *ctx)
51875201
dst_reg = IR_REG_NUM(ctx->regs[use][0]);
51885202
IR_ASSERT(src_reg != IR_REG_NONE || dst_reg != IR_REG_NONE ||
51895203
stack_offset == ctx->live_intervals[ctx->vregs[use]]->stack_spill_pos +
5190-
((ctx->flags & IR_USE_FRAME_POINTER) ? -ctx->stack_frame_size : ctx->call_stack_size));
5204+
((ctx->flags & IR_USE_FRAME_POINTER) ?
5205+
-(ctx->stack_frame_size - ctx->stack_frame_alignment) :
5206+
ctx->call_stack_size));
51915207
if (src_reg != dst_reg) {
51925208
ir_emit_param_move(ctx, insn->type, src_reg, dst_reg, use, stack_offset);
51935209
}

‎ext/opcache/jit/ir/ir_builder.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,9 @@ extern "C" {
614614
#define ir_END_list(_list) do { _list = _ir_END_LIST(_ir_CTX, _list); } while (0)
615615
#define ir_MERGE_list(_list) _ir_MERGE_LIST(_ir_CTX, (_list))
616616

617+
#define ir_END_PHI_list(_list, _val) do { _list = _ir_END_PHI_LIST(_ir_CTX, _list, _val); } while (0)
618+
#define ir_PHI_list(_list) _ir_PHI_LIST(_ir_CTX, (_list))
619+
617620
#define ir_MERGE_WITH(_src2) do {ir_ref end = ir_END(); ir_MERGE_2(end, _src2);} while (0)
618621
#define ir_MERGE_WITH_EMPTY_TRUE(_if) do {ir_ref end = ir_END(); ir_IF_TRUE(_if); ir_MERGE_2(end, ir_END());} while (0)
619622
#define ir_MERGE_WITH_EMPTY_FALSE(_if) do {ir_ref end = ir_END(); ir_IF_FALSE(_if); ir_MERGE_2(end, ir_END());} while (0)
@@ -655,6 +658,7 @@ void _ir_ENTRY(ir_ctx *ctx, ir_ref src, ir_ref num);
655658
void _ir_BEGIN(ir_ctx *ctx, ir_ref src);
656659
ir_ref _ir_END(ir_ctx *ctx);
657660
ir_ref _ir_END_LIST(ir_ctx *ctx, ir_ref list);
661+
ir_ref _ir_END_PHI_LIST(ir_ctx *ctx, ir_ref list, ir_ref val);
658662
ir_ref _ir_IF(ir_ctx *ctx, ir_ref condition);
659663
void _ir_IF_TRUE(ir_ctx *ctx, ir_ref if_ref);
660664
void _ir_IF_TRUE_cold(ir_ctx *ctx, ir_ref if_ref);
@@ -664,6 +668,7 @@ void _ir_MERGE_2(ir_ctx *ctx, ir_ref src1, ir_ref src2);
664668
void _ir_MERGE_N(ir_ctx *ctx, ir_ref n, ir_ref *inputs);
665669
void _ir_MERGE_SET_OP(ir_ctx *ctx, ir_ref merge, ir_ref pos, ir_ref src);
666670
void _ir_MERGE_LIST(ir_ctx *ctx, ir_ref list);
671+
ir_ref _ir_PHI_LIST(ir_ctx *ctx, ir_ref list);
667672
ir_ref _ir_LOOP_BEGIN(ir_ctx *ctx, ir_ref src1);
668673
ir_ref _ir_LOOP_END(ir_ctx *ctx);
669674
ir_ref _ir_TLS(ir_ctx *ctx, ir_ref index, ir_ref offset);

‎ext/opcache/jit/ir/ir_emit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static void ir_emit_dessa_move(ir_ctx *ctx, ir_type type, ir_ref to, ir_ref from
664664

665665
IR_ALWAYS_INLINE void ir_dessa_resolve_cycle(ir_ctx *ctx, int32_t *pred, int32_t *loc, ir_bitset todo, ir_type type, int32_t to, ir_reg tmp_reg, ir_reg tmp_fp_reg)
666666
{
667-
ir_reg from;
667+
ir_ref from;
668668
ir_mem tmp_spill_slot;
669669

670670
IR_MEM_VAL(tmp_spill_slot) = 0;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /