Skip to content

Commit 9b57e07

Browse files
committed
Consolidate op1/op2 vm flags
1 parent 64cb71c commit 9b57e07

File tree

3 files changed

+89
-109
lines changed

3 files changed

+89
-109
lines changed

Zend/zend_vm_gen.php

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,18 @@
5555
define("ZEND_VM_KIND_GOTO", 3);
5656

5757
$vm_op_flags = array(
58-
"ZEND_VM_OP1_SPEC" => 1<<0,
59-
"ZEND_VM_OP1_CONST" => 1<<1,
60-
"ZEND_VM_OP1_TMPVAR" => 1<<2,
61-
"ZEND_VM_OP1_MASK" => 0xf0,
62-
"ZEND_VM_OP1_NUM" => 0x10,
63-
"ZEND_VM_OP1_JMP_ADDR" => 0x20,
64-
"ZEND_VM_OP1_TRY_CATCH" => 0x30,
65-
"ZEND_VM_OP1_LIVE_RANGE" => 0x40,
66-
"ZEND_VM_OP1_THIS" => 0x50,
67-
"ZEND_VM_OP1_NEXT" => 0x60,
68-
"ZEND_VM_OP1_CLASS_FETCH" => 0x70,
69-
"ZEND_VM_OP1_CONSTRUCTOR" => 0x80,
70-
71-
"ZEND_VM_OP2_SPEC" => 1<<8,
72-
"ZEND_VM_OP2_CONST" => 1<<9,
73-
"ZEND_VM_OP2_TMPVAR" => 1<<10,
74-
"ZEND_VM_OP2_MASK" => 0xf000,
75-
"ZEND_VM_OP2_NUM" => 0x1000,
76-
"ZEND_VM_OP2_JMP_ADDR" => 0x2000,
77-
"ZEND_VM_OP2_TRY_CATCH" => 0x3000,
78-
"ZEND_VM_OP2_LIVE_RANGE" => 0x4000,
79-
"ZEND_VM_OP2_THIS" => 0x5000,
80-
"ZEND_VM_OP2_NEXT" => 0x6000,
81-
"ZEND_VM_OP2_CLASS_FETCH" => 0x7000,
82-
"ZEND_VM_OP2_CONSTRUCTOR" => 0x8000,
58+
"ZEND_VM_OP_SPEC" => 1<<0,
59+
"ZEND_VM_OP_CONST" => 1<<1,
60+
"ZEND_VM_OP_TMPVAR" => 1<<2,
61+
"ZEND_VM_OP_MASK" => 0xf0,
62+
"ZEND_VM_OP_NUM" => 0x10,
63+
"ZEND_VM_OP_JMP_ADDR" => 0x20,
64+
"ZEND_VM_OP_TRY_CATCH" => 0x30,
65+
"ZEND_VM_OP_LIVE_RANGE" => 0x40,
66+
"ZEND_VM_OP_THIS" => 0x50,
67+
"ZEND_VM_OP_NEXT" => 0x60,
68+
"ZEND_VM_OP_CLASS_FETCH" => 0x70,
69+
"ZEND_VM_OP_CONSTRUCTOR" => 0x80,
8370

8471
"ZEND_VM_EXT_VAR_FETCH" => 1<<16,
8572
"ZEND_VM_EXT_ISSET" => 1<<17,
@@ -107,20 +94,20 @@
10794

10895
$vm_op_decode = array(
10996
"ANY" => 0,
110-
"CONST" => ZEND_VM_OP1_SPEC | ZEND_VM_OP1_CONST,
111-
"TMP" => ZEND_VM_OP1_SPEC,
112-
"VAR" => ZEND_VM_OP1_SPEC,
113-
"UNUSED" => ZEND_VM_OP1_SPEC,
114-
"CV" => ZEND_VM_OP1_SPEC,
115-
"TMPVAR" => ZEND_VM_OP1_SPEC | ZEND_VM_OP1_TMPVAR,
116-
"NUM" => ZEND_VM_OP1_NUM,
117-
"JMP_ADDR" => ZEND_VM_OP1_JMP_ADDR,
118-
"TRY_CATCH" => ZEND_VM_OP1_TRY_CATCH,
119-
"LIVE_RANGE" => ZEND_VM_OP1_LIVE_RANGE,
120-
"THIS" => ZEND_VM_OP1_THIS,
121-
"NEXT" => ZEND_VM_OP1_NEXT,
122-
"CLASS_FETCH" => ZEND_VM_OP1_CLASS_FETCH,
123-
"CONSTRUCTOR" => ZEND_VM_OP1_CONSTRUCTOR,
97+
"CONST" => ZEND_VM_OP_SPEC | ZEND_VM_OP_CONST,
98+
"TMP" => ZEND_VM_OP_SPEC,
99+
"VAR" => ZEND_VM_OP_SPEC,
100+
"UNUSED" => ZEND_VM_OP_SPEC,
101+
"CV" => ZEND_VM_OP_SPEC,
102+
"TMPVAR" => ZEND_VM_OP_SPEC | ZEND_VM_OP_TMPVAR,
103+
"NUM" => ZEND_VM_OP_NUM,
104+
"JMP_ADDR" => ZEND_VM_OP_JMP_ADDR,
105+
"TRY_CATCH" => ZEND_VM_OP_TRY_CATCH,
106+
"LIVE_RANGE" => ZEND_VM_OP_LIVE_RANGE,
107+
"THIS" => ZEND_VM_OP_THIS,
108+
"NEXT" => ZEND_VM_OP_NEXT,
109+
"CLASS_FETCH" => ZEND_VM_OP_CLASS_FETCH,
110+
"CONSTRUCTOR" => ZEND_VM_OP_CONSTRUCTOR,
124111
);
125112

126113
$vm_ext_decode = array(
@@ -1445,7 +1432,7 @@ function parse_operand_spec($def, $lineno, $str, &$flags) {
14451432
die("ERROR ($def:$lineno): Wrong operand type '$str'\n");
14461433
}
14471434
}
1448-
if (!($flags & ZEND_VM_OP1_SPEC)) {
1435+
if (!($flags & ZEND_VM_OP_SPEC)) {
14491436
if (count($a) != 1) {
14501437
die("ERROR ($def:$lineno): Wrong operand type '$str'\n");
14511438
}
@@ -1649,6 +1636,8 @@ function gen_vm($def, $skel) {
16491636
foreach($vm_op_flags as $name => $val) {
16501637
fprintf($f, "#define %-24s 0x%08x\n", $name, $val);
16511638
}
1639+
fputs($f, "#define ZEND_VM_OP1_FLAGS(flags) (flags & 0xff)\n");
1640+
fputs($f, "#define ZEND_VM_OP2_FLAGS(flags) ((flags >> 8) & 0xff)\n");
16521641
fputs($f, "\n");
16531642
fputs($f, "BEGIN_EXTERN_C()\n\n");
16541643
fputs($f, "ZEND_API const char *zend_get_opcode_name(zend_uchar opcode);\n");

Zend/zend_vm_opcodes.h

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,18 @@
2828
#define ZEND_VM_KIND_GOTO 3
2929
#define ZEND_VM_KIND ZEND_VM_KIND_CALL
3030

31-
#define ZEND_VM_OP1_SPEC 0x00000001
32-
#define ZEND_VM_OP1_CONST 0x00000002
33-
#define ZEND_VM_OP1_TMPVAR 0x00000004
34-
#define ZEND_VM_OP1_MASK 0x000000f0
35-
#define ZEND_VM_OP1_NUM 0x00000010
36-
#define ZEND_VM_OP1_JMP_ADDR 0x00000020
37-
#define ZEND_VM_OP1_TRY_CATCH 0x00000030
38-
#define ZEND_VM_OP1_LIVE_RANGE 0x00000040
39-
#define ZEND_VM_OP1_THIS 0x00000050
40-
#define ZEND_VM_OP1_NEXT 0x00000060
41-
#define ZEND_VM_OP1_CLASS_FETCH 0x00000070
42-
#define ZEND_VM_OP1_CONSTRUCTOR 0x00000080
43-
#define ZEND_VM_OP2_SPEC 0x00000100
44-
#define ZEND_VM_OP2_CONST 0x00000200
45-
#define ZEND_VM_OP2_TMPVAR 0x00000400
46-
#define ZEND_VM_OP2_MASK 0x0000f000
47-
#define ZEND_VM_OP2_NUM 0x00001000
48-
#define ZEND_VM_OP2_JMP_ADDR 0x00002000
49-
#define ZEND_VM_OP2_TRY_CATCH 0x00003000
50-
#define ZEND_VM_OP2_LIVE_RANGE 0x00004000
51-
#define ZEND_VM_OP2_THIS 0x00005000
52-
#define ZEND_VM_OP2_NEXT 0x00006000
53-
#define ZEND_VM_OP2_CLASS_FETCH 0x00007000
54-
#define ZEND_VM_OP2_CONSTRUCTOR 0x00008000
31+
#define ZEND_VM_OP_SPEC 0x00000001
32+
#define ZEND_VM_OP_CONST 0x00000002
33+
#define ZEND_VM_OP_TMPVAR 0x00000004
34+
#define ZEND_VM_OP_MASK 0x000000f0
35+
#define ZEND_VM_OP_NUM 0x00000010
36+
#define ZEND_VM_OP_JMP_ADDR 0x00000020
37+
#define ZEND_VM_OP_TRY_CATCH 0x00000030
38+
#define ZEND_VM_OP_LIVE_RANGE 0x00000040
39+
#define ZEND_VM_OP_THIS 0x00000050
40+
#define ZEND_VM_OP_NEXT 0x00000060
41+
#define ZEND_VM_OP_CLASS_FETCH 0x00000070
42+
#define ZEND_VM_OP_CONSTRUCTOR 0x00000080
5543
#define ZEND_VM_EXT_VAR_FETCH 0x00010000
5644
#define ZEND_VM_EXT_ISSET 0x00020000
5745
#define ZEND_VM_EXT_ARG_NUM 0x00040000
@@ -69,6 +57,8 @@
6957
#define ZEND_VM_EXT_FAST_RET 0x0a000000
7058
#define ZEND_VM_EXT_SRC 0x0b000000
7159
#define ZEND_VM_EXT_SEND 0x0c000000
60+
#define ZEND_VM_OP1_FLAGS(flags) (flags & 0xff)
61+
#define ZEND_VM_OP2_FLAGS(flags) ((flags >> 8) & 0xff)
7262

7363
BEGIN_EXTERN_C()
7464

ext/opcache/Optimizer/zend_dump.c

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ static void zend_dump_class_fetch_type(uint32_t fetch_type)
8888
}
8989
}
9090

91+
static void zend_dump_unused_op(const zend_op *opline, znode_op op, uint32_t flags) {
92+
if (ZEND_VM_OP_NUM == (flags & ZEND_VM_OP_MASK)) {
93+
fprintf(stderr, " %u", op.num);
94+
} else if (ZEND_VM_OP_TRY_CATCH == (flags & ZEND_VM_OP_MASK)) {
95+
fprintf(stderr, " try-catch(%u)", op.num);
96+
} else if (ZEND_VM_OP_LIVE_RANGE == (flags & ZEND_VM_OP_MASK)) {
97+
if (opline->extended_value & ZEND_FREE_ON_RETURN) {
98+
fprintf(stderr, " live-range(%u)", op.num);
99+
}
100+
} else if (ZEND_VM_OP_THIS == (flags & ZEND_VM_OP_MASK)) {
101+
fprintf(stderr, " THIS");
102+
} else if (ZEND_VM_OP_NEXT == (flags & ZEND_VM_OP_MASK)) {
103+
fprintf(stderr, " NEXT");
104+
} else if (ZEND_VM_OP_CLASS_FETCH == (flags & ZEND_VM_OP_MASK)) {
105+
zend_dump_class_fetch_type(op.num);
106+
} else if (ZEND_VM_OP_CONSTRUCTOR == (flags & ZEND_VM_OP_MASK)) {
107+
fprintf(stderr, " CONSTRUCTOR");
108+
}
109+
}
110+
91111
void zend_dump_var(const zend_op_array *op_array, zend_uchar var_type, int var_num)
92112
{
93113
if (var_type == IS_CV && var_num < op_array->last_var) {
@@ -546,21 +566,8 @@ static void zend_dump_op(const zend_op_array *op_array, const zend_basic_block *
546566
}
547567
}
548568
}
549-
if (ZEND_VM_OP1_JMP_ADDR == (flags & ZEND_VM_OP1_MASK)) {
550-
if (b) {
551-
fprintf(stderr, " BB%d", b->successors[n++]);
552-
} else {
553-
fprintf(stderr, " L%u", (uint32_t)(OP_JMP_ADDR(opline, opline->op1) - op_array->opcodes));
554-
}
555-
} else if (ZEND_VM_OP1_NUM == (flags & ZEND_VM_OP1_MASK)) {
556-
fprintf(stderr, " %u", opline->op1.num);
557-
} else if (ZEND_VM_OP1_TRY_CATCH == (flags & ZEND_VM_OP1_MASK)) {
558-
fprintf(stderr, " try-catch(%u)", opline->op1.num);
559-
} else if (ZEND_VM_OP1_LIVE_RANGE == (flags & ZEND_VM_OP1_MASK)) {
560-
if (opline->extended_value & ZEND_FREE_ON_RETURN) {
561-
fprintf(stderr, " live-range(%u)", opline->op1.num);
562-
}
563-
} else if (opline->op1_type == IS_CONST) {
569+
570+
if (opline->op1_type == IS_CONST) {
564571
zend_dump_const(CRT_CONSTANT_EX(op_array, opline->op1, (dump_flags & ZEND_DUMP_RT_CONSTANTS)));
565572
} else if (opline->op1_type == IS_CV ||
566573
opline->op1_type == IS_VAR ||
@@ -585,30 +592,20 @@ static void zend_dump_op(const zend_op_array *op_array, const zend_basic_block *
585592
zend_dump_ssa_var(op_array, ssa, ssa_var_num, opline->op1_type, EX_VAR_TO_NUM(opline->op1.var));
586593
}
587594
}
588-
} else if (ZEND_VM_OP1_THIS == (flags & ZEND_VM_OP1_MASK)) {
589-
fprintf(stderr, " THIS");
590-
} else if (ZEND_VM_OP1_NEXT == (flags & ZEND_VM_OP1_MASK)) {
591-
fprintf(stderr, " NEXT");
592-
} else if (ZEND_VM_OP1_CLASS_FETCH == (flags & ZEND_VM_OP1_MASK)) {
593-
zend_dump_class_fetch_type(opline->op1.num);
594-
} else if (ZEND_VM_OP1_CONSTRUCTOR == (flags & ZEND_VM_OP1_MASK)) {
595-
fprintf(stderr, " CONSTRUCTOR");
596-
}
597-
if (ZEND_VM_OP2_JMP_ADDR == (flags & ZEND_VM_OP2_MASK)) {
598-
if (b) {
599-
fprintf(stderr, " BB%d", b->successors[n++]);
595+
} else {
596+
uint32_t op1_flags = ZEND_VM_OP1_FLAGS(flags);
597+
if (ZEND_VM_OP_JMP_ADDR == (op1_flags & ZEND_VM_OP_MASK)) {
598+
if (b) {
599+
fprintf(stderr, " BB%d", b->successors[n++]);
600+
} else {
601+
fprintf(stderr, " L%u", (uint32_t)(OP_JMP_ADDR(opline, opline->op1) - op_array->opcodes));
602+
}
600603
} else {
601-
fprintf(stderr, " L%u", (uint32_t)(OP_JMP_ADDR(opline, opline->op2) - op_array->opcodes));
602-
}
603-
} else if (ZEND_VM_OP2_NUM == (flags & ZEND_VM_OP2_MASK)) {
604-
fprintf(stderr, " %u", opline->op2.num);
605-
} else if (ZEND_VM_OP2_TRY_CATCH == (flags & ZEND_VM_OP2_MASK)) {
606-
fprintf(stderr, " try-catch(%u)", opline->op2.num);
607-
} else if (ZEND_VM_OP2_LIVE_RANGE == (flags & ZEND_VM_OP2_MASK)) {
608-
if (opline->extended_value & ZEND_FREE_ON_RETURN) {
609-
fprintf(stderr, " live-range(%u)", opline->op2.num);
604+
zend_dump_unused_op(opline, opline->op1, op1_flags);
610605
}
611-
} else if (opline->op2_type == IS_CONST) {
606+
}
607+
608+
if (opline->op2_type == IS_CONST) {
612609
zend_dump_const(CRT_CONSTANT_EX(op_array, opline->op2, (dump_flags & ZEND_DUMP_RT_CONSTANTS)));
613610
} else if (opline->op2_type == IS_CV ||
614611
opline->op2_type == IS_VAR ||
@@ -633,15 +630,19 @@ static void zend_dump_op(const zend_op_array *op_array, const zend_basic_block *
633630
zend_dump_ssa_var(op_array, ssa, ssa_var_num, opline->op2_type, EX_VAR_TO_NUM(opline->op2.var));
634631
}
635632
}
636-
} else if (ZEND_VM_OP2_THIS == (flags & ZEND_VM_OP2_MASK)) {
637-
fprintf(stderr, " THIS");
638-
} else if (ZEND_VM_OP2_NEXT == (flags & ZEND_VM_OP2_MASK)) {
639-
fprintf(stderr, " NEXT");
640-
} else if (ZEND_VM_OP2_CLASS_FETCH == (flags & ZEND_VM_OP2_MASK)) {
641-
zend_dump_class_fetch_type(opline->op2.num);
642-
} else if (ZEND_VM_OP2_CONSTRUCTOR == (flags & ZEND_VM_OP2_MASK)) {
643-
fprintf(stderr, " CONSTRUCTOR");
633+
} else {
634+
uint32_t op2_flags = ZEND_VM_OP2_FLAGS(flags);
635+
if (ZEND_VM_OP_JMP_ADDR == (op2_flags & ZEND_VM_OP_MASK)) {
636+
if (b) {
637+
fprintf(stderr, " BB%d", b->successors[n++]);
638+
} else {
639+
fprintf(stderr, " L%u", (uint32_t)(OP_JMP_ADDR(opline, opline->op2) - op_array->opcodes));
640+
}
641+
} else {
642+
zend_dump_unused_op(opline, opline->op2, op2_flags);
643+
}
644644
}
645+
645646
if (ZEND_VM_EXT_JMP_ADDR == (flags & ZEND_VM_EXT_MASK)) {
646647
if (opline->opcode != ZEND_CATCH || !opline->result.num) {
647648
if (b) {

0 commit comments

Comments
 (0)