cvs: pecl /apc apc_optimizer.c
| From: | George Schlossnagle | Date: | Fri, 27 Jun 2003 14:26:23 +0000 |
| Subject: | cvs: pecl /apc apc_optimizer.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-332@lists.php.net to get a copy of this message | ||
gschlossnagle Fri Jun 27 10:26:23 2003 EDT
Modified files:
/pecl/apc apc_optimizer.c
Log:
sterling jumbo patch. couple bug fixines plus cast resolution and echo compression
Index: pecl/apc/apc_optimizer.c
diff -u pecl/apc/apc_optimizer.c:3.18 pecl/apc/apc_optimizer.c:3.19
--- pecl/apc/apc_optimizer.c:3.18 Thu Jun 26 20:18:38 2003
+++ pecl/apc/apc_optimizer.c Fri Jun 27 10:26:23 2003
@@ -221,10 +221,12 @@
switch (ops[cadr(p)].opcode) {
case ZEND_POST_INC:
ops[cadr(p)].opcode = ZEND_PRE_INC;
+ ops[cadr(p)].result.op_type = IS_VAR;
ops[cadr(p)].result.u.EA.type |= EXT_TYPE_UNUSED;
break;
case ZEND_POST_DEC:
ops[cadr(p)].opcode = ZEND_PRE_DEC;
+ ops[cadr(p)].result.op_type = IS_VAR;
ops[cadr(p)].result.u.EA.type |= EXT_TYPE_UNUSED;
break;
default:
@@ -252,6 +254,60 @@
result->type = IS_STRING;
}
+
+static void rewrite_multiple_echo(zend_op* ops, Pair* p)
+{
+ zend_op* first;
+ zend_op* second;
+ int newlen;
+
+ first = &ops[car(p)];
+ second = &ops[cadr(p)];
+
+ newlen = first->op1.u.constant.value.str.len + second->op1.u.constant.value.str.len;
+ first->op1.u.constant.value.str.val = erealloc(first->op1.u.constant.value.str.val,
newlen);
+ memcpy(first->op1.u.constant.value.str.val + first->op1.u.constant.value.str.len,
+ second->op1.u.constant.value.str.val,
+ second->op1.u.constant.value.str.len);
+ first->op1.u.constant.value.str.len = newlen;
+
+ clear_zend_op(second);
+}
+
+
+static void rewrite_const_cast(zend_op* ops, Pair* p)
+{
+ zend_op* cur;
+ zval convert;
+
+ cur = &ops[car(p)];
+
+ memcpy(&convert, &cur->op1.u.constant, sizeof(zval));
+ switch (cur->extended_value) {
+ case IS_NULL:
+ convert_to_null(&convert);
+ break;
+ case IS_BOOL:
+ convert_to_bool(&convert);
+ break;
+ case IS_LONG:
+ convert_to_long(&convert);
+ break;
+ case IS_DOUBLE:
+ convert_to_double(&convert);
+ break;
+ case IS_STRING:
+ convert_to_string(&convert);
+ break;
+ }
+ zval_dtor(&cur->op1.u.constant);
+ cur->opcode = ZEND_QM_ASSIGN;
+ cur->extended_value = 0;
+ cur->op1.op_type = IS_CONST;
+ memcpy(&cur->op1.u.constant, &convert, sizeof(zval));
+ cur->op2.op_type = IS_UNUSED;
+}
+
static void rewrite_add_string(zend_op* ops, Pair* p)
{
int curr = car(p);
@@ -487,6 +543,18 @@
/* {{{ peephole match functions */
+static Pair* peephole_cast(zend_op* ops, int i, int num_ops)
+{
+ if (ops[i].opcode == ZEND_CAST &&
+ ops[i].op1.op_type == IS_CONST &&
+ ops[i].result.op_type == IS_TMP_VAR &&
+ ops[i].extended_value != IS_ARRAY &&
+ ops[i].extended_value != IS_OBJECT &&
+ ops[i].extended_value != IS_RESOURCE) {
+ return cons(i, 0);
+ }
+ return NULL;
+}
static Pair* peephole_post_inc(zend_op* ops, int i, int num_ops)
{
@@ -577,6 +645,25 @@
return 0;
}
+
+static Pair* peephole_multiple_echo(zend_op* ops, int i, int num_ops)
+{
+ int j;
+
+ j = next_op(ops, i, num_ops);
+
+ if (j == num_ops) {
+ return NULL;
+ }
+
+ if (ops[i].opcode == ZEND_ECHO && ops[i].op1.op_type == IS_CONST &&
+ ops[j].opcode == ZEND_ECHO && ops[j].op1.op_type == IS_CONST) {
+ return cons(i, cons(j, 0));
+ }
+
+ return NULL;
+}
+
static Pair* peephole_print(zend_op* ops, int i, int num_ops)
{
int j; /* next op after i */
@@ -699,14 +786,21 @@
jumps = build_jump_array(op_array);
for (i = 0; i < op_array->last; i++) {
Pair* p;
-/* For some reason this optimization _still_ causes a major slowdown
+ if ((p = peephole_cast(op_array->opcodes, i, op_array->last))) {
+ rewrite_const_cast(op_array->opcodes, p);
+ RESTART_PEEPHOLE_LOOP;
+ }
if ((p = peephole_inc(op_array->opcodes, i, op_array->last))) {
if (!are_branch_targets(cdr(p), jumps)) {
rewrite_inc(op_array->opcodes, p);
}
RESTART_PEEPHOLE_LOOP;
}
-*/
+ if ((p = peephole_multiple_echo(op_array->opcodes, i, op_array->last))) {
+ if (!are_branch_targets(cdr(p), jumps)) {
+ rewrite_multiple_echo(op_array->opcodes, p);
+ }
+ }
if ((p = peephole_print(op_array->opcodes, i, op_array->last))) {
if (!are_branch_targets(cdr(p), jumps)) {
rewrite_print(op_array->opcodes, p);