* 16 of the SSA book.
*/
-#if 0
-#define SCP_DEBUG(...) php_printf(__VA_ARGS__)
-#else
-#define SCP_DEBUG(...)
-#endif
+#define SCP_DEBUG 0
typedef struct _sccp_ctx {
scdf_ctx scdf;
#define MAKE_TOP(zv) (Z_TYPE_INFO_P(zv) = TOP)
#define MAKE_BOT(zv) (Z_TYPE_INFO_P(zv) = BOT)
+static void scp_dump_value(zval *zv) {
+ if (IS_TOP(zv)) {
+ fprintf(stderr, " top");
+ } else if (IS_BOT(zv)) {
+ fprintf(stderr, " bot");
+ } else if (Z_TYPE_P(zv) == IS_ARRAY || IS_PARTIAL_ARRAY(zv)) {
+ fprintf(stderr, " %s[", IS_PARTIAL_ARRAY(zv) ? "partial " : "");
+ zend_dump_ht(Z_ARRVAL_P(zv));
+ fprintf(stderr, "]");
+ } else if (IS_PARTIAL_OBJECT(zv)) {
+ fprintf(stderr, " {");
+ zend_dump_ht(Z_ARRVAL_P(zv));
+ fprintf(stderr, "}");
+ } else {
+ zend_dump_const(zv);
+ }
+}
+
static void empty_partial_array(zval *zv)
{
MAKE_PARTIAL_ARRAY(zv);
return;
}
- if (IS_BOT(new)) {
- SCP_DEBUG("Lowering var %d to BOT\n", var);
- } else if (!IS_PARTIAL_ARRAY(new) && !IS_PARTIAL_OBJECT(new)) {
- SCP_DEBUG("Lowering var %d to %Z\n", var, new);
- }
+#if SCP_DEBUG
+ fprintf(stderr, "Lowering #%d.", var);
+ zend_dump_var(scdf->op_array, IS_CV, scdf->ssa->vars[var].var);
+ fprintf(stderr, " from");
+ scp_dump_value(value);
+ fprintf(stderr, " to");
+ scp_dump_value(new);
+ fprintf(stderr, "\n");
+#endif
if (IS_TOP(value) || IS_BOT(new)) {
zval_ptr_dtor_nogc(value);
int i;
zval result;
MAKE_TOP(&result);
- SCP_DEBUG("Handling PHI(");
+#if SCP_DEBUG
+ fprintf(stderr, "Handling phi(");
+#endif
if (phi->pi >= 0) {
ZEND_ASSERT(phi->sources[0] >= 0);
if (scdf_is_edge_feasible(scdf, phi->pi, phi->block)) {
for (i = 0; i < block->predecessors_count; i++) {
ZEND_ASSERT(phi->sources[i] >= 0);
if (scdf_is_edge_feasible(scdf, predecessors[i], phi->block)) {
- SCP_DEBUG("val, ");
+#if SCP_DEBUG
+ scp_dump_value(&ctx->values[phi->sources[i]]);
+ fprintf(stderr, ",");
+#endif
join_phi_values(&result, &ctx->values[phi->sources[i]], ssa->vars[phi->ssa_var].escape_state != ESCAPE_STATE_NO_ESCAPE);
} else {
- SCP_DEBUG("--, ");
+#if SCP_DEBUG
+ fprintf(stderr, " --,");
+#endif
}
}
}
- SCP_DEBUG(")\n");
+#if SCP_DEBUG
+ fprintf(stderr, ")\n");
+#endif
set_value(scdf, ctx, phi->ssa_var, &result);
zval_ptr_dtor_nogc(&result);
}
fprintf(stderr, " #%d.", i);
zend_dump_var(op_array, IS_CV, ssa->vars[i].var);
- if (Z_TYPE_P(zv) == IS_ARRAY || IS_PARTIAL_ARRAY(zv)) {
- fprintf(stderr, " = %s[", IS_PARTIAL_ARRAY(zv) ? "partial " : "");
- zend_dump_ht(Z_ARRVAL_P(zv));
- fprintf(stderr, "]");
- } else if (IS_PARTIAL_OBJECT(zv)) {
- fprintf(stderr, " = {");
- zend_dump_ht(Z_ARRVAL_P(zv));
- fprintf(stderr, "}");
- } else {
- fprintf(stderr, " =");
- zend_dump_const(zv);
- }
+ fprintf(stderr, " =");
+ scp_dump_value(zv);
fprintf(stderr, "\n");
}
}