Skip to content

Commit 968a807

Browse files
committed
Update IR
IR commit: 84df6f8d409c7d06daa68d96a25d0aed81dcbf4a
1 parent 9bed0b5 commit 968a807

File tree

7 files changed

+229
-244
lines changed

7 files changed

+229
-244
lines changed

ext/opcache/jit/ir/gen_ir_fold_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static int parse_rule(const char *buf)
238238
return mask;
239239
}
240240

241-
int main()
241+
int main(int argc, char **argv)
242242
{
243243
char buf[4096];
244244
FILE *f = stdin;

ext/opcache/jit/ir/ir.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ void ir_init(ir_ctx *ctx, uint32_t flags, ir_ref consts_limit, ir_ref insns_limi
382382
buf = ir_mem_malloc((consts_limit + insns_limit) * sizeof(ir_insn));
383383
ctx->ir_base = buf + consts_limit;
384384

385-
ctx->ir_base[IR_UNUSED].optx = IR_NOP;
385+
MAKE_NOP(&ctx->ir_base[IR_UNUSED]);
386386
ctx->ir_base[IR_NULL].optx = IR_OPT(IR_C_ADDR, IR_ADDR);
387387
ctx->ir_base[IR_NULL].val.u64 = 0;
388388
ctx->ir_base[IR_FALSE].optx = IR_OPT(IR_C_BOOL, IR_BOOL);
@@ -1296,7 +1296,7 @@ void ir_use_list_remove_one(ir_ctx *ctx, ir_ref from, ir_ref ref)
12961296
}
12971297
}
12981298

1299-
void ir_use_list_replace(ir_ctx *ctx, ir_ref ref, ir_ref use, ir_ref new_use)
1299+
void ir_use_list_replace_one(ir_ctx *ctx, ir_ref ref, ir_ref use, ir_ref new_use)
13001300
{
13011301
ir_use_list *use_list = &ctx->use_lists[ref];
13021302
ir_ref i, n, *p;
@@ -1310,6 +1310,19 @@ void ir_use_list_replace(ir_ctx *ctx, ir_ref ref, ir_ref use, ir_ref new_use)
13101310
}
13111311
}
13121312

1313+
void ir_use_list_replace_all(ir_ctx *ctx, ir_ref ref, ir_ref use, ir_ref new_use)
1314+
{
1315+
ir_use_list *use_list = &ctx->use_lists[ref];
1316+
ir_ref i, n, *p;
1317+
1318+
n = use_list->count;
1319+
for (i = 0, p = &ctx->use_edges[use_list->refs]; i < n; i++, p++) {
1320+
if (*p == use) {
1321+
*p = new_use;
1322+
}
1323+
}
1324+
}
1325+
13131326
bool ir_use_list_add(ir_ctx *ctx, ir_ref to, ir_ref ref)
13141327
{
13151328
ir_use_list *use_list = &ctx->use_lists[to];
@@ -2679,10 +2692,7 @@ void _ir_STORE(ir_ctx *ctx, ir_ref addr, ir_ref val)
26792692
} else {
26802693
ctx->control = insn->op1;
26812694
}
2682-
insn->optx = IR_NOP;
2683-
insn->op1 = IR_NOP;
2684-
insn->op2 = IR_NOP;
2685-
insn->op3 = IR_NOP;
2695+
MAKE_NOP(insn);
26862696
}
26872697
break;
26882698
}

ext/opcache/jit/ir/ir_cfg.c

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,6 @@
88
#include "ir.h"
99
#include "ir_private.h"
1010

11-
#define MAKE_NOP(_insn) do { \
12-
ir_insn *__insn = _insn; \
13-
__insn->optx = IR_NOP; \
14-
__insn->op1 = __insn->op2 = __insn->op3 = IR_UNUSED; \
15-
} while (0)
16-
17-
#define CLEAR_USES(_ref) do { \
18-
ir_use_list *__use_list = &ctx->use_lists[_ref]; \
19-
__use_list->count = 0; \
20-
__use_list->refs = 0; \
21-
} while (0)
22-
23-
#define SWAP_REFS(_ref1, _ref2) do { \
24-
ir_ref _tmp = _ref1; \
25-
_ref1 = _ref2; \
26-
_ref2 = _tmp; \
27-
} while (0)
28-
29-
#define SWAP_INSNS(_insn1, _insn2) do { \
30-
ir_insn *_tmp = _insn1; \
31-
_insn1 = _insn2; \
32-
_insn2 = _tmp; \
33-
} while (0)
34-
3511
static void ir_get_true_false_refs(const ir_ctx *ctx, ir_ref if_ref, ir_ref *if_true_ref, ir_ref *if_false_ref)
3612
{
3713
ir_use_list *use_list = &ctx->use_lists[if_ref];
@@ -54,7 +30,6 @@ static ir_ref _ir_merge_blocks(ir_ctx *ctx, ir_ref end, ir_ref begin)
5430
{
5531
ir_ref prev, next;
5632
ir_use_list *use_list;
57-
ir_ref n, *p;
5833

5934
IR_ASSERT(ctx->ir_base[begin].op == IR_BEGIN);
6035
IR_ASSERT(ctx->ir_base[end].op == IR_END);
@@ -68,23 +43,12 @@ static ir_ref _ir_merge_blocks(ir_ctx *ctx, ir_ref end, ir_ref begin)
6843
next = ctx->use_edges[use_list->refs];
6944

7045
/* remove BEGIN and END */
71-
ctx->ir_base[begin].op = IR_NOP;
72-
ctx->ir_base[begin].op1 = IR_UNUSED;
73-
ctx->use_lists[begin].count = 0;
74-
ctx->ir_base[end].op = IR_NOP;
75-
ctx->ir_base[end].op1 = IR_UNUSED;
76-
ctx->use_lists[end].count = 0;
46+
MAKE_NOP(&ctx->ir_base[begin]); CLEAR_USES(begin);
47+
MAKE_NOP(&ctx->ir_base[end]); CLEAR_USES(end);
7748

7849
/* connect their predecessor and successor */
7950
ctx->ir_base[next].op1 = prev;
80-
use_list = &ctx->use_lists[prev];
81-
n = use_list->count;
82-
for (p = &ctx->use_edges[use_list->refs]; n > 0; p++, n--) {
83-
if (*p == end) {
84-
*p = next;
85-
}
86-
}
87-
51+
ir_use_list_replace_all(ctx, prev, end, next);
8852
return next;
8953
}
9054

@@ -141,7 +105,7 @@ static ir_ref ir_try_remove_empty_diamond(ir_ctx *ctx, ir_ref ref, ir_insn *insn
141105
IR_ASSERT(ctx->use_lists[start2_ref].count == 1);
142106

143107
next->op1 = root->op1;
144-
ir_use_list_replace(ctx, root->op1, root_ref, next_ref);
108+
ir_use_list_replace_one(ctx, root->op1, root_ref, next_ref);
145109
if (!IR_IS_CONST_REF(root->op2)) {
146110
ir_use_list_remove_all(ctx, root->op2, root_ref);
147111
}
@@ -189,7 +153,7 @@ static ir_ref ir_try_remove_empty_diamond(ir_ctx *ctx, ir_ref ref, ir_insn *insn
189153
ir_insn *root = &ctx->ir_base[root_ref];
190154

191155
next->op1 = root->op1;
192-
ir_use_list_replace(ctx, root->op1, root_ref, next_ref);
156+
ir_use_list_replace_one(ctx, root->op1, root_ref, next_ref);
193157
ir_use_list_remove_all(ctx, root->op2, root_ref);
194158

195159
MAKE_NOP(root); CLEAR_USES(root_ref);
@@ -303,8 +267,7 @@ static ir_ref ir_optimize_phi(ir_ctx *ctx, ir_ref merge_ref, ir_insn *merge, ir_
303267
insn->op3 = IR_UNUSED;
304268

305269
next->op1 = root->op1;
306-
ir_use_list_replace(ctx, root->op1, root_ref, next_ref);
307-
ir_use_list_remove_all(ctx, root->op2, root_ref);
270+
ir_use_list_replace_one(ctx, root->op1, root_ref, next_ref);
308271
if (!IR_IS_CONST_REF(insn->op1)) {
309272
ir_use_list_remove_all(ctx, insn->op1, cond_ref);
310273
}
@@ -384,8 +347,8 @@ static ir_ref ir_optimize_phi(ir_ctx *ctx, ir_ref merge_ref, ir_insn *merge, ir_
384347
insn->op3 = IR_UNUSED;
385348

386349
next->op1 = root->op1;
387-
ir_use_list_replace(ctx, root->op1, root_ref, next_ref);
388-
ir_use_list_remove_all(ctx, root->op2, root_ref);
350+
ir_use_list_replace_one(ctx, root->op1, root_ref, next_ref);
351+
ir_use_list_remove_one(ctx, insn->op1, neg_ref);
389352
if (!IR_IS_CONST_REF(insn->op1)) {
390353
ir_use_list_remove_all(ctx, insn->op1, cond_ref);
391354
}
@@ -440,8 +403,8 @@ static ir_ref ir_optimize_phi(ir_ctx *ctx, ir_ref merge_ref, ir_insn *merge, ir_
440403
}
441404

442405
next->op1 = root->op1;
443-
ir_use_list_replace(ctx, cond_ref, root_ref, ref);
444-
ir_use_list_replace(ctx, root->op1, root_ref, next_ref);
406+
ir_use_list_replace_one(ctx, cond_ref, root_ref, ref);
407+
ir_use_list_replace_one(ctx, root->op1, root_ref, next_ref);
445408
ir_use_list_remove_all(ctx, root->op2, root_ref);
446409

447410
MAKE_NOP(root); CLEAR_USES(root_ref);
@@ -619,9 +582,9 @@ static ir_ref ir_try_split_if(ir_ctx *ctx, ir_ref ref, ir_insn *insn)
619582
ir_use_list_remove_all(ctx, merge_ref, cond_ref);
620583
ir_use_list_remove_all(ctx, ref, if_true_ref);
621584
if (!IR_IS_CONST_REF(cond->op3)) {
622-
ir_use_list_replace(ctx, cond->op3, cond_ref, end2_ref);
585+
ir_use_list_replace_one(ctx, cond->op3, cond_ref, end2_ref);
623586
}
624-
ir_use_list_replace(ctx, end1_ref, merge_ref, if_false_ref);
587+
ir_use_list_replace_one(ctx, end1_ref, merge_ref, if_false_ref);
625588
ir_use_list_add(ctx, end2_ref, if_true_ref);
626589

627590
end2->optx = IR_OPTX(IR_IF, IR_VOID, 2);
@@ -722,8 +685,8 @@ static ir_ref ir_try_split_if_cmp(ir_ctx *ctx, ir_worklist *worklist, ir_ref ref
722685
* | |
723686
*/
724687

725-
ir_use_list_replace(ctx, end1_ref, merge_ref, if_false_ref);
726-
ir_use_list_replace(ctx, end2_ref, merge_ref, if_true_ref);
688+
ir_use_list_replace_one(ctx, end1_ref, merge_ref, if_false_ref);
689+
ir_use_list_replace_one(ctx, end2_ref, merge_ref, if_true_ref);
727690

728691
MAKE_NOP(merge); CLEAR_USES(merge_ref);
729692
MAKE_NOP(phi); CLEAR_USES(phi_ref);
@@ -762,8 +725,8 @@ static ir_ref ir_try_split_if_cmp(ir_ctx *ctx, ir_worklist *worklist, ir_ref ref
762725
* | |
763726
*/
764727

765-
ir_use_list_replace(ctx, end1_ref, merge_ref, if_false_ref);
766-
ir_use_list_replace(ctx, end2_ref, merge_ref, if_false_ref);
728+
ir_use_list_replace_one(ctx, end1_ref, merge_ref, if_false_ref);
729+
ir_use_list_replace_one(ctx, end2_ref, merge_ref, if_false_ref);
767730

768731
MAKE_NOP(merge); CLEAR_USES(merge_ref);
769732
MAKE_NOP(phi); CLEAR_USES(phi_ref);
@@ -809,10 +772,10 @@ static ir_ref ir_try_split_if_cmp(ir_ctx *ctx, ir_worklist *worklist, ir_ref ref
809772
ir_use_list_remove_all(ctx, merge_ref, phi_ref);
810773
ir_use_list_remove_all(ctx, ref, if_true_ref);
811774
if (!IR_IS_CONST_REF(phi->op3)) {
812-
ir_use_list_replace(ctx, phi->op3, phi_ref, insn->op2);
775+
ir_use_list_replace_one(ctx, phi->op3, phi_ref, insn->op2);
813776
}
814-
ir_use_list_replace(ctx, end1_ref, merge_ref, if_false_ref);
815-
ir_use_list_replace(ctx, cond_ref, ref, end2_ref);
777+
ir_use_list_replace_one(ctx, end1_ref, merge_ref, if_false_ref);
778+
ir_use_list_replace_one(ctx, cond_ref, ref, end2_ref);
816779
ir_use_list_add(ctx, end2_ref, if_true_ref);
817780

818781
end2->optx = IR_OPTX(IR_IF, IR_VOID, 2);

ext/opcache/jit/ir/ir_check.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ bool ir_check(const ir_ctx *ctx)
125125
ok = 0;
126126
}
127127
}
128-
if (use >= i
129-
&& !(insn->op == IR_PHI
130-
&& (!(ctx->flags2 & IR_LINEAR) || ctx->ir_base[insn->op1].op == IR_LOOP_BEGIN))) {
128+
if ((ctx->flags2 & IR_LINEAR)
129+
&& use >= i
130+
&& !(insn->op == IR_PHI && ctx->ir_base[insn->op1].op == IR_LOOP_BEGIN)) {
131131
fprintf(stderr, "ir_base[%d].ops[%d] invalid forward reference (%d)\n", i, j, use);
132132
ok = 0;
133133
}
@@ -216,7 +216,8 @@ bool ir_check(const ir_ctx *ctx)
216216
}
217217
break;
218218
case IR_OPND_CONTROL_DEP:
219-
if (use >= i
219+
if ((ctx->flags2 & IR_LINEAR)
220+
&& use >= i
220221
&& !(insn->op == IR_LOOP_BEGIN)) {
221222
fprintf(stderr, "ir_base[%d].ops[%d] invalid forward reference (%d)\n", i, j, use);
222223
ok = 0;

0 commit comments

Comments
 (0)