Skip to content

Commit 3778abf

Browse files
committed
Added ability to manually sort opcode handlers (not used yet)
1 parent 633d037 commit 3778abf

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

Zend/zend_vm_gen.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ function is_hot_handler($hot, $op1, $op2, $extra_spec) {
10271027

10281028
// Generates opcode handler
10291029
function gen_handler($f, $spec, $kind, $name, $op1, $op2, $use, $code, $lineno, $opcode, $extra_spec = null, &$switch_labels = array()) {
1030-
global $definition_file, $prefix, $opnames;
1030+
global $definition_file, $prefix, $opnames, $gen_order;
10311031

10321032
if ($spec && skip_extra_spec_function($op1, $op2, $extra_spec)) {
10331033
return;
@@ -1046,7 +1046,11 @@ function gen_handler($f, $spec, $kind, $name, $op1, $op2, $use, $code, $lineno,
10461046
. "\t\t\t\tVM_TRACE($spec_name)\n"
10471047
. "\t\t\t\t{$spec_name}_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);\n"
10481048
. "\t\t\t\tHYBRID_BREAK();\n";
1049-
out($f, $code);
1049+
if (is_array($gen_order)) {
1050+
$gen_order[$spec_name] = $code;
1051+
} else {
1052+
out($f, $code);
1053+
}
10501054
return;
10511055
case ZEND_VM_KIND_CALL:
10521056
if ($opcode["hot"] && ZEND_VM_KIND == ZEND_VM_KIND_HYBRID && is_hot_handler($opcode["hot"], $op1, $op2, $extra_spec)) {
@@ -1532,9 +1536,31 @@ function extra_spec_handler($dsc) {
15321536
return $f($specs);
15331537
}
15341538

1539+
function read_order_file($fn) {
1540+
$f = fopen($fn, "r");
1541+
if (!is_resource($f)) {
1542+
return false;
1543+
}
1544+
$order = [];
1545+
while (!feof($f)) {
1546+
$op = trim(fgets($f));
1547+
if ($op !== "") {
1548+
$order[$op] = null;
1549+
}
1550+
}
1551+
fclose($f);
1552+
return $order;
1553+
}
1554+
15351555
// Generates all opcode handlers and helpers (specialized or unspecilaized)
15361556
function gen_executor_code($f, $spec, $kind, $prolog, &$switch_labels = array()) {
1537-
global $list, $opcodes, $helpers, $op_types_ex;
1557+
global $list, $opcodes, $helpers, $op_types_ex, $gen_order;
1558+
1559+
if ($kind == ZEND_VM_KIND_HYBRID && file_exists(__DIR__ . "/zend_vm_order.txt")) {
1560+
$gen_order = read_order_file(__DIR__ . "/zend_vm_order.txt");
1561+
} else {
1562+
$gen_order = null;
1563+
}
15381564

15391565
if ($spec) {
15401566
// Produce specialized executor
@@ -1595,6 +1621,14 @@ function gen_executor_code($f, $spec, $kind, $prolog, &$switch_labels = array())
15951621
}
15961622
}
15971623

1624+
if (is_array($gen_order)) {
1625+
foreach ($gen_order as $txt) {
1626+
if ($txt !== null) {
1627+
out($f, $txt);
1628+
}
1629+
}
1630+
}
1631+
15981632
if (ZEND_VM_LINES) {
15991633
// Reset #line directives
16001634
out_line($f);

0 commit comments

Comments
 (0)