PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - lcov_data/ext/opcache/Optimizer - pass1_5.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 183 312 58.7 %
Date: 2014-08-04 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* pass 1
       2             :  * - substitute persistent constants (true, false, null, etc)
       3             :  * - perform compile-time evaluation of constant binary and unary operations
       4             :  * - optimize series of ADD_STRING and/or ADD_CHAR
       5             :  * - convert CAST(IS_BOOL,x) into BOOL(x)
       6             :  * - pre-evaluate constant function calls
       7             :  */
       8             : 
       9             : #if ZEND_EXTENSION_API_NO > PHP_5_2_X_API_NO
      10             : # define ZEND_IS_CONSTANT_TYPE(t)       (((t) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT)
      11             : #else
      12             : # define ZEND_IS_CONSTANT_TYPE(t)       ((t) == IS_CONSTANT)
      13             : #endif
      14             : 
      15         451 : if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
      16         451 :         int i = 0;
      17         451 :         zend_op *opline = op_array->opcodes;
      18         451 :         zend_op *end = opline + op_array->last;
      19         451 :         zend_bool collect_constants = (op_array == &script->main_op_array);
      20             : 
      21        7766 :         while (opline < end) {
      22        6864 :                 switch (opline->opcode) {
      23             :                 case ZEND_ADD:
      24             :                 case ZEND_SUB:
      25             :                 case ZEND_MUL:
      26             :                 case ZEND_DIV:
      27             :                 case ZEND_MOD:
      28             : #if ZEND_EXTENSION_API_NO >= PHP_5_6_X_API_NO
      29             :                 case ZEND_POW:
      30             : #endif
      31             :                 case ZEND_SL:
      32             :                 case ZEND_SR:
      33             :                 case ZEND_CONCAT:
      34             :                 case ZEND_IS_EQUAL:
      35             :                 case ZEND_IS_NOT_EQUAL:
      36             :                 case ZEND_IS_SMALLER:
      37             :                 case ZEND_IS_SMALLER_OR_EQUAL:
      38             :                 case ZEND_IS_IDENTICAL:
      39             :                 case ZEND_IS_NOT_IDENTICAL:
      40             :                 case ZEND_BW_OR:
      41             :                 case ZEND_BW_AND:
      42             :                 case ZEND_BW_XOR:
      43             :                 case ZEND_BOOL_XOR:
      44         262 :                         if (ZEND_OP1_TYPE(opline) == IS_CONST &&
      45          60 :                                 ZEND_OP2_TYPE(opline) == IS_CONST) {
      46             :                                 /* binary operation with constant operands */
      47          22 :                                 int (*binary_op)(zval *result, zval *op1, zval *op2 TSRMLS_DC) = get_binary_op(opline->opcode);
      48          22 :                                 zend_uint tv = ZEND_RESULT(opline).var;         /* temporary variable */
      49             :                                 zval result;
      50             :                                 int er;
      51             : 
      52          22 :                                 if (opline->opcode == ZEND_DIV &&
      53           0 :                                         Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_LONG &&
      54           0 :                                         Z_LVAL(ZEND_OP2_LITERAL(opline)) == 0) {
      55             :                                         /* div by 0 */
      56           0 :                                         break;
      57             :                                 }
      58          22 :                                 er = EG(error_reporting);
      59          22 :                                 EG(error_reporting) = 0;
      60             :                                 /* evaluate constant expression */
      61          22 :                                 if (binary_op(&result, &ZEND_OP1_LITERAL(opline), &ZEND_OP2_LITERAL(opline) TSRMLS_CC) != SUCCESS) {
      62           0 :                                         EG(error_reporting) = er;
      63           0 :                                         break;
      64             :                                 }
      65          22 :                                 EG(error_reporting) = er;
      66          22 :                                 PZ_SET_REFCOUNT_P(&result, 1);
      67             :                                 PZ_UNSET_ISREF_P(&result);
      68             : 
      69          44 :                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
      70          44 :                                 literal_dtor(&ZEND_OP2_LITERAL(opline));
      71          22 :                                 MAKE_NOP(opline);
      72             : 
      73          22 :                                 replace_tmp_by_const(op_array, opline + 1, tv, &result TSRMLS_CC);
      74             :                         }
      75         202 :                         break;
      76             : 
      77             :                 case ZEND_CAST:
      78           8 :                         if (ZEND_OP1_TYPE(opline) == IS_CONST &&
      79           1 :                                 opline->extended_value != IS_ARRAY &&
      80           1 :                                 opline->extended_value != IS_OBJECT &&
      81           1 :                                 opline->extended_value != IS_RESOURCE) {
      82             :                                 /* cast of constant operand */
      83           1 :                                 zend_uint tv = ZEND_RESULT(opline).var;         /* temporary variable */
      84             :                                 zval res;
      85           1 :                                 res = ZEND_OP1_LITERAL(opline);
      86             :                                 zval_copy_ctor(&res);
      87           1 :                                 switch (opline->extended_value) {
      88             :                                         case IS_NULL:
      89           0 :                                                 convert_to_null(&res);
      90           0 :                                                 break;
      91             :                                         case IS_BOOL:
      92           0 :                                                 convert_to_boolean(&res);
      93           0 :                                                 break;
      94             :                                         case IS_LONG:
      95           0 :                                                 convert_to_long(&res);
      96           0 :                                                 break;
      97             :                                         case IS_DOUBLE:
      98           0 :                                                 convert_to_double(&res);
      99           0 :                                                 break;
     100             :                                         case IS_STRING:
     101           1 :                                                 convert_to_string(&res);
     102             :                                                 break;
     103             :                                 }
     104             : 
     105           2 :                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
     106           1 :                                 MAKE_NOP(opline);
     107             : 
     108           1 :                                 replace_tmp_by_const(op_array, opline + 1, tv, &res TSRMLS_CC);
     109           3 :                         } else if (opline->extended_value == IS_BOOL) {
     110             :                                 /* T = CAST(X, IS_BOOL) => T = BOOL(X) */
     111           0 :                                 opline->opcode = ZEND_BOOL;
     112           0 :                                 opline->extended_value = 0;
     113             :                         }
     114           4 :                         break;
     115             : 
     116             :                 case ZEND_BW_NOT:
     117             :                 case ZEND_BOOL_NOT:
     118         230 :                         if (ZEND_OP1_TYPE(opline) == IS_CONST) {
     119             :                                 /* unary operation on constant operand */
     120         173 :                                 unary_op_type unary_op = get_unary_op(opline->opcode);
     121             :                                 zval result;
     122         173 :                                 zend_uint tv = ZEND_RESULT(opline).var;         /* temporary variable */
     123             :                                 int er;
     124             : 
     125         173 :                                 er = EG(error_reporting);
     126         173 :                                 EG(error_reporting) = 0;
     127             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     128             :                                 if (unary_op(&result, &ZEND_OP1_LITERAL(opline)) != SUCCESS) {
     129             : #else
     130         173 :                                 if (unary_op(&result, &ZEND_OP1_LITERAL(opline) TSRMLS_CC) != SUCCESS) {
     131             : #endif
     132           0 :                                         EG(error_reporting) = er;
     133           0 :                                         break;
     134             :                                 }
     135         173 :                                 EG(error_reporting) = er;
     136         173 :                                 PZ_SET_REFCOUNT_P(&result, 1);
     137             :                                 PZ_UNSET_ISREF_P(&result);
     138             : 
     139         346 :                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
     140         173 :                                 MAKE_NOP(opline);
     141             : 
     142         173 :                                 replace_tmp_by_const(op_array, opline + 1, tv, &result TSRMLS_CC);
     143             :                         }
     144         230 :                         break;
     145             : 
     146             :                 case ZEND_ADD_STRING:
     147             :                 case ZEND_ADD_CHAR:
     148             :                         {
     149          49 :                                 zend_op *next_op = opline + 1;
     150          49 :                                 int requires_conversion = (opline->opcode == ZEND_ADD_CHAR? 1 : 0);
     151          49 :                                 size_t final_length = 0;
     152             :                                 char *ptr;
     153             :                                 zend_op *last_op;
     154             : 
     155             :                                 /* There is always a ZEND_RETURN at the end
     156             :                                 if (next_op>=end) {
     157             :                                         break;
     158             :                                 }
     159             :                                 */
     160          98 :                                 while (next_op->opcode == ZEND_ADD_STRING || next_op->opcode == ZEND_ADD_CHAR) {
     161           0 :                                         if (ZEND_RESULT(opline).var != ZEND_RESULT(next_op).var) {
     162           0 :                                                 break;
     163             :                                         }
     164           0 :                                         if (next_op->opcode == ZEND_ADD_CHAR) {
     165           0 :                                                 final_length += 1;
     166             :                                         } else { /* ZEND_ADD_STRING */
     167           0 :                                                 final_length += ZEND_OP2_LITERAL(next_op).value.str.len;
     168             :                                         }
     169           0 :                                         next_op++;
     170             :                                 }
     171          49 :                                 if (final_length == 0) {
     172          49 :                                         break;
     173             :                                 }
     174           0 :                                 last_op = next_op;
     175           0 :                                 final_length += (requires_conversion? 1 : ZEND_OP2_LITERAL(opline).value.str.len);
     176           0 :                                 ptr = (char *)emalloc(final_length + 1);
     177           0 :                                 ptr[final_length] = '\0';
     178           0 :                                 if (requires_conversion) { /* ZEND_ADD_CHAR */
     179           0 :                                         char chval = (char)ZEND_OP2_LITERAL(opline).value.lval;
     180             : 
     181           0 :                                         ZEND_OP2_LITERAL(opline).value.str.val = ptr;
     182           0 :                                         ptr[0] = chval;
     183           0 :                                         ZEND_OP2_LITERAL(opline).type = IS_STRING;
     184           0 :                                         opline->opcode = ZEND_ADD_STRING;
     185           0 :                                         ptr++;
     186             :                                 } else { /* ZEND_ADD_STRING */
     187           0 :                                         memcpy(ptr, Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)));
     188           0 :                                         if (!IS_INTERNED(Z_STRVAL(ZEND_OP2_LITERAL(opline)))) {
     189           0 :                                                 efree(Z_STRVAL(ZEND_OP2_LITERAL(opline)));
     190             :                                         }
     191           0 :                                         Z_STRVAL(ZEND_OP2_LITERAL(opline)) = ptr;
     192           0 :                                         ptr += Z_STRLEN(ZEND_OP2_LITERAL(opline));
     193             :                                 }
     194           0 :                                 ZEND_OP2_LITERAL(opline).value.str.len = final_length;
     195           0 :                                 next_op = opline + 1;
     196           0 :                                 while (next_op < last_op) {
     197           0 :                                         if (next_op->opcode == ZEND_ADD_STRING) {
     198           0 :                                                 memcpy(ptr, ZEND_OP2_LITERAL(next_op).value.str.val, ZEND_OP2_LITERAL(next_op).value.str.len);
     199           0 :                                                 ptr += ZEND_OP2_LITERAL(next_op).value.str.len;
     200           0 :                                                 literal_dtor(&ZEND_OP2_LITERAL(next_op));
     201             :                                         } else { /* ZEND_ADD_CHAR */
     202           0 :                                                 *ptr = (char)ZEND_OP2_LITERAL(next_op).value.lval;
     203           0 :                                                 ptr++;
     204             :                                         }
     205           0 :                                         MAKE_NOP(next_op);
     206           0 :                                         next_op++;
     207             :                                 }
     208           0 :                                 if (!((ZEND_OPTIMIZER_PASS_5|ZEND_OPTIMIZER_PASS_10) & OPTIMIZATION_LEVEL)) {
     209             :                                         /* NOP removal is disabled => insert JMP over NOPs */
     210           0 :                                         if (last_op-opline >= 3) { /* If we have more than 2 NOPS then JMP over them */
     211           0 :                                                 (opline + 1)->opcode = ZEND_JMP;
     212           0 :                                                 ZEND_OP1(opline + 1).opline_num = last_op - op_array->opcodes; /* that's OK even for ZE2, since opline_num's are resolved in pass 2 later */
     213             :                                         }
     214             :                                 }
     215             :                         }
     216           0 :                         break;
     217             : 
     218             :                 case ZEND_FETCH_CONSTANT:
     219         470 :                         if (ZEND_OP1_TYPE(opline) == IS_UNUSED &&
     220         100 :                                 ZEND_OP2_TYPE(opline) == IS_CONST &&
     221         100 :                                 Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING &&
     222         100 :                                 Z_STRLEN(ZEND_OP2_LITERAL(opline)) == sizeof("__COMPILER_HALT_OFFSET__") - 1 &&
     223           4 :                                 memcmp(Z_STRVAL(ZEND_OP2_LITERAL(opline)), "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1) == 0) {
     224             :                                 /* substitute __COMPILER_HALT_OFFSET__ constant */
     225           0 :                                 zend_bool orig_in_execution = EG(in_execution);
     226           0 :                                 zend_op_array *orig_op_array = EG(active_op_array);
     227             :                                 zval offset;
     228             : 
     229           0 :                                 EG(in_execution) = 1;
     230           0 :                                 EG(active_op_array) = op_array;
     231           0 :                                 if (zend_get_constant("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1, &offset TSRMLS_CC)) {
     232           0 :                                         zend_uint tv = ZEND_RESULT(opline).var;
     233             : 
     234           0 :                                         literal_dtor(&ZEND_OP2_LITERAL(opline));
     235           0 :                                         MAKE_NOP(opline);
     236           0 :                                         replace_tmp_by_const(op_array, opline, tv, &offset TSRMLS_CC);
     237             :                                 }
     238           0 :                                 EG(active_op_array) = orig_op_array;
     239           0 :                                 EG(in_execution) = orig_in_execution;
     240           0 :                                 break;
     241             :                         }
     242             : 
     243         366 :                         if (ZEND_OP1_TYPE(opline) == IS_UNUSED &&
     244         100 :                                 ZEND_OP2_TYPE(opline) == IS_CONST &&
     245         100 :                                 ZEND_OP2_LITERAL(opline).type == IS_STRING) {
     246             :                                 /* substitute persistent constants */
     247         100 :                                 zend_uint tv = ZEND_RESULT(opline).var;
     248             :                                 zval c;
     249             : 
     250         100 :                                 if (!zend_get_persistent_constant(Z_STRVAL(ZEND_OP2_LITERAL(opline)), Z_STRLEN(ZEND_OP2_LITERAL(opline)), &c, 1 TSRMLS_CC)) {
     251           0 :                                         if (!*constants || !zend_optimizer_get_collected_constant(*constants, &ZEND_OP2_LITERAL(opline), &c)) {
     252             :                                                 break;
     253             :                                         }
     254             :                                 }
     255         200 :                                 literal_dtor(&ZEND_OP2_LITERAL(opline));
     256         100 :                                 MAKE_NOP(opline);
     257         100 :                                 replace_tmp_by_const(op_array, opline, tv, &c TSRMLS_CC);
     258             :                         }
     259             : 
     260             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     261             :                         /* class constant */
     262         298 :                         if (ZEND_OP1_TYPE(opline) != IS_UNUSED &&
     263          66 :                             ZEND_OP2_TYPE(opline) == IS_CONST &&
     264          66 :                                 ZEND_OP2_LITERAL(opline).type == IS_STRING) {
     265             : 
     266          66 :                                 zend_class_entry **pce = NULL;
     267             : 
     268         181 :                                 if (ZEND_OP1_TYPE(opline) == IS_CONST &&
     269          59 :                                 ZEND_OP1_LITERAL(opline).type == IS_STRING) {
     270             :                                         /* for A::B */
     271          59 :                                         if (op_array->scope && 
     272           0 :                                                 !strncasecmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     273           0 :                                                 op_array->scope->name, Z_STRLEN(ZEND_OP1_LITERAL(opline)) + 1)) {
     274           0 :                                                 pce = &op_array->scope;
     275             :                                         } else { 
     276         286 :                                                 if (zend_hash_quick_find(EG(class_table), 
     277          59 :                                                                 Z_STRVAL(op_array->literals[opline->op1.constant + 1].constant), 
     278          59 :                                                                 Z_STRLEN(op_array->literals[opline->op1.constant].constant) + 1, 
     279          59 :                                                                 Z_HASH_P(&op_array->literals[opline->op1.constant + 1].constant),
     280         236 :                                                                 (void **)&pce) == FAILURE ||
     281          56 :                                                                 ((*pce)->type == ZEND_INTERNAL_CLASS &&
     282          56 :                                                                  (*pce)->info.internal.module->type != MODULE_PERSISTENT) ||
     283          56 :                                                                 ((*pce)->type == ZEND_USER_CLASS &&
     284           0 :                                                                  ZEND_CE_FILENAME(*pce) != op_array->filename)) {
     285             :                                                         break;
     286             :                                                 }
     287             :                                         }
     288          42 :                                 } else if (op_array->scope &&
     289           7 :                                         ZEND_OP1_TYPE(opline) == IS_VAR &&
     290           7 :                                         (opline - 1)->opcode == ZEND_FETCH_CLASS && 
     291           7 :                                         (ZEND_OP1_TYPE(opline - 1) == IS_UNUSED &&
     292           7 :                                         ((opline - 1)->extended_value & ~ZEND_FETCH_CLASS_NO_AUTOLOAD) == ZEND_FETCH_CLASS_SELF) &&
     293           7 :                                         ZEND_RESULT((opline - 1)).var == ZEND_OP1(opline).var) {
     294             :                                         /* for self::B */
     295           7 :                                         pce = &op_array->scope;
     296             :                                 }
     297             : 
     298          63 :                                 if (pce) {
     299          63 :                                         zend_uint tv = ZEND_RESULT(opline).var;
     300             :                                         zval **c, t;
     301             : 
     302         189 :                                         if (zend_hash_find(&(*pce)->constants_table,
     303          63 :                                                         Z_STRVAL(ZEND_OP2_LITERAL(opline)),
     304          63 :                                                         Z_STRLEN(ZEND_OP2_LITERAL(opline)) + 1,
     305             :                                                         (void **) &c) == SUCCESS) {
     306          63 :                                                 if (ZEND_IS_CONSTANT_TYPE(Z_TYPE_PP(c))) { 
     307           0 :                                                         if (!zend_get_persistent_constant(Z_STRVAL_PP(c), Z_STRLEN_PP(c), &t, 1 TSRMLS_CC) ||
     308           0 :                                                             ZEND_IS_CONSTANT_TYPE(Z_TYPE(t))) {
     309             :                                                                 break;
     310             :                                                         }
     311             :                                                 } else {
     312          63 :                                                         t = **c;
     313             :                                                         zval_copy_ctor(&t);
     314             :                                                 }
     315             : 
     316          63 :                                                 if (ZEND_OP1_TYPE(opline) == IS_CONST) {
     317         112 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline));
     318             :                                                 } else {
     319           7 :                                                         MAKE_NOP((opline - 1));
     320             :                                                 }
     321         126 :                                                 literal_dtor(&ZEND_OP2_LITERAL(opline));
     322          63 :                                                 MAKE_NOP(opline);
     323          63 :                                                 replace_tmp_by_const(op_array, opline, tv, &t TSRMLS_CC);
     324             :                                         }
     325             :                                 }
     326             :                         }
     327             : #endif
     328         163 :                         break;
     329             : 
     330             :                 case ZEND_DO_FCALL:
     331             :                         /* define("name", scalar); */
     332        1373 :                         if (collect_constants &&
     333         272 :                             opline->extended_value == 2 &&
     334          11 :                             ZEND_OP1_TYPE(opline) == IS_CONST &&
     335          11 :                             Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
     336          11 :                             Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("define")-1 &&
     337           0 :                             zend_binary_strcasecmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)), Z_STRLEN(ZEND_OP1_LITERAL(opline)), "define", sizeof("define")-1) == 0 &&
     338           0 :                             (opline-1)->opcode == ZEND_SEND_VAL &&
     339           0 :                             ZEND_OP1_TYPE(opline-1) == IS_CONST &&
     340           0 :                             (Z_TYPE(ZEND_OP1_LITERAL(opline-1)) <= IS_BOOL ||
     341           0 :                              Z_TYPE(ZEND_OP1_LITERAL(opline-1)) == IS_STRING) &&
     342           0 :                             (opline-2)->opcode == ZEND_SEND_VAL &&
     343           0 :                             ZEND_OP1_TYPE(opline-2) == IS_CONST &&
     344           0 :                             Z_TYPE(ZEND_OP1_LITERAL(opline-2)) == IS_STRING) {
     345           0 :                                 zend_optimizer_collect_constant(constants, &ZEND_OP1_LITERAL(opline-2), &ZEND_OP1_LITERAL(opline-1));
     346           0 :                                 break;
     347             :                         } else {
     348             :                                 /* don't colllect constants after any other function call */
     349        1068 :                                 collect_constants = 0;
     350             :                         }
     351             : 
     352             :                         /* pre-evaluate constant functions:
     353             :                            defined(x)
     354             :                            constant(x)
     355             :                            function_exists(x)
     356             :                            is_callable(x)
     357             :                            extension_loaded(x)
     358             :                         */
     359        2430 :                         if (opline->extended_value == 1 && (opline - 1)->opcode == ZEND_SEND_VAL &&
     360         702 :                                 ZEND_OP1_TYPE(opline - 1) == IS_CONST && ZEND_OP1_LITERAL(opline - 1).type == IS_STRING &&
     361         660 :                                 ZEND_OP1_TYPE(opline) == IS_CONST && ZEND_OP1_LITERAL(opline).type == IS_STRING) {
     362         665 :                                 if ((Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("function_exists")-1 &&
     363           4 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     364             :                                                 "function_exists", sizeof("function_exists")-1)) ||
     365         326 :                                         (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("is_callable")-1 &&
     366           1 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     367             :                                                 "is_callable", sizeof("is_callable")))) {
     368             :                                         zend_internal_function *func;
     369           8 :                                         char *lc_name = zend_str_tolower_dup(
     370          12 :                                                         Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)), Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)));
     371             :                                         
     372          16 :                                         if (zend_hash_find(EG(function_table), lc_name, Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)) + 1,
     373          12 :                                                                 (void *)&func) == SUCCESS &&
     374           2 :                                                         func->type == ZEND_INTERNAL_FUNCTION &&
     375           2 :                                                         func->module->type == MODULE_PERSISTENT) {
     376             :                                                 zval t;
     377           2 :                                                 ZVAL_BOOL(&t, 1);
     378           2 :                                                 if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     379           4 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     380           2 :                                                         MAKE_NOP((opline - 1));
     381           4 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline));
     382           2 :                                                         MAKE_NOP(opline);
     383             :                                                 }
     384             :                                         }
     385           4 :                                         efree(lc_name);
     386         686 :                                 } else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("extension_loaded")-1 &&
     387         182 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     388             :                                                 "extension_loaded", sizeof("extension_loaded")-1)) {
     389             :                                         zval t;
     390             :                                         zend_module_entry *m;
     391         356 :                                         char *lc_name = zend_str_tolower_dup(
     392         534 :                                                         Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)), Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)));
     393         356 :                                         int found = zend_hash_find(&module_registry,
     394         356 :                                                         lc_name, Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)) + 1, (void *)&m) == SUCCESS;
     395             : 
     396         178 :                                         efree(lc_name);
     397         178 :                                         if (!found) {
     398           0 :                                                 if (!PG(enable_dl)) {
     399           0 :                                                         break;
     400             :                                                 } else {
     401           0 :                                                         ZVAL_BOOL(&t, 0);
     402             :                                                 }
     403             :                                         } else {
     404         178 :                                                 if (m->type == MODULE_PERSISTENT) {
     405         178 :                                                         ZVAL_BOOL(&t, 1);
     406             :                                                 } else {
     407           0 :                                                         break;
     408             :                                                 }
     409             :                                         } 
     410             : 
     411         178 :                                         if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     412         356 :                                                 literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     413         178 :                                                 MAKE_NOP((opline - 1));
     414         356 :                                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
     415         178 :                                                 MAKE_NOP(opline);
     416             :                                         }
     417         194 :                                 } else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("defined")-1 &&
     418          46 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     419             :                                                 "defined", sizeof("defined")-1)) {
     420             :                                         zval t;
     421             : 
     422           0 :                                         if (zend_get_persistent_constant(Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)),
     423           0 :                                                 Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)), &t, 0 TSRMLS_CC)) {
     424             : 
     425           0 :                                                 ZVAL_BOOL(&t, 1);
     426           0 :                                                 if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     427           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     428           0 :                                                         MAKE_NOP((opline - 1));
     429           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline));
     430           0 :                                                         MAKE_NOP(opline);
     431             :                                                 }
     432             :                                         }
     433         184 :                                 } else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("constant")-1 &&
     434          36 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     435             :                                                 "constant", sizeof("constant")-1)) {
     436             :                                         zval t;
     437             :                                         
     438           0 :                                         if (zend_get_persistent_constant(Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)),
     439           0 :                                                 Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)), &t, 1 TSRMLS_CC)) {
     440           0 :                                                 if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     441           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     442           0 :                                                         MAKE_NOP((opline - 1));
     443           0 :                                                         literal_dtor(&ZEND_OP1_LITERAL(opline));
     444           0 :                                                         MAKE_NOP(opline);
     445             :                                                 }
     446             :                                         }
     447         195 :                                 } else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("strlen")-1 &&
     448          47 :                                         !memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     449             :                                                 "strlen", sizeof("strlen")-1)) {
     450             :                                         zval t;
     451             : 
     452           0 :                                         ZVAL_LONG(&t, Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)));
     453           0 :                                         if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
     454           0 :                                                 literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
     455           0 :                                                 MAKE_NOP((opline - 1));
     456           0 :                                                 literal_dtor(&ZEND_OP1_LITERAL(opline));
     457           0 :                                                 MAKE_NOP(opline);
     458             :                                         }
     459             :                                 }
     460             :                         }                       
     461        1068 :                         break;
     462             : #if ZEND_EXTENSION_API_NO > PHP_5_2_X_API_NO
     463             :                 case ZEND_DECLARE_CONST:
     464           0 :                         if (collect_constants &&
     465           0 :                             Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
     466           0 :                             (Z_TYPE(ZEND_OP2_LITERAL(opline)) <= IS_BOOL ||
     467           0 :                              Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING)) {
     468           0 :                                 zend_optimizer_collect_constant(constants, &ZEND_OP1_LITERAL(opline), &ZEND_OP2_LITERAL(opline));
     469             :                         }
     470           0 :                         break;
     471             : #endif
     472             : 
     473             :                 case ZEND_RETURN:
     474             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     475             :                 case ZEND_RETURN_BY_REF:
     476             : #endif
     477             : #if ZEND_EXTENSION_API_NO > PHP_5_4_X_API_NO
     478             :                 case ZEND_GENERATOR_RETURN:
     479             : #endif
     480             :                 case ZEND_EXIT:
     481             :                 case ZEND_THROW:
     482             :                 case ZEND_CATCH:
     483             :                 case ZEND_BRK:
     484             :                 case ZEND_CONT:
     485             : #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
     486             :                 case ZEND_GOTO:
     487             : #endif
     488             : #if ZEND_EXTENSION_API_NO > PHP_5_4_X_API_NO
     489             :                 case ZEND_FAST_CALL:
     490             :                 case ZEND_FAST_RET:
     491             : #endif
     492             :                 case ZEND_JMP:
     493             :                 case ZEND_JMPZNZ:
     494             :                 case ZEND_JMPZ:
     495             :                 case ZEND_JMPNZ:
     496             :                 case ZEND_JMPZ_EX:
     497             :                 case ZEND_JMPNZ_EX:
     498             :                 case ZEND_FE_RESET:
     499             :                 case ZEND_FE_FETCH:
     500             :                 case ZEND_NEW:
     501             :                 case ZEND_DO_FCALL_BY_NAME:
     502             : #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
     503             :                 case ZEND_JMP_SET:
     504             : #endif
     505             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     506             :                 case ZEND_JMP_SET_VAR:
     507             : #endif
     508        1654 :                         collect_constants = 0;
     509        1654 :                         break;
     510             : 
     511             : #if ZEND_EXTENSION_API_NO >= PHP_5_5_X_API_NO
     512             :                 case ZEND_FETCH_R:
     513             :                 case ZEND_FETCH_W:
     514             :                 case ZEND_FETCH_RW:
     515             :                 case ZEND_FETCH_FUNC_ARG:
     516             :                 case ZEND_FETCH_IS:
     517             :                 case ZEND_FETCH_UNSET:
     518        1032 :                         if (opline != op_array->opcodes &&
     519         389 :                             (opline-1)->opcode == ZEND_BEGIN_SILENCE &&
     520          38 :                             (opline->extended_value & ZEND_FETCH_TYPE_MASK) == ZEND_FETCH_LOCAL &&
     521          37 :                                 opline->op1_type == IS_CONST &&
     522          37 :                             opline->op2_type == IS_UNUSED &&
     523          37 :                             Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING &&
     524          37 :                             (Z_STRLEN(ZEND_OP1_LITERAL(opline)) != sizeof("this")-1 ||
     525           7 :                              memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)), "this", sizeof("this") - 1) != 0)) {
     526             : 
     527          37 :                             int var = opline->result.var;
     528          37 :                             int level = 0;
     529          37 :                                 zend_op *op = opline + 1;
     530          37 :                                 zend_op *use = NULL;
     531             : 
     532         171 :                                 while (op < end) {
     533         134 :                                         if (op->opcode == ZEND_BEGIN_SILENCE) {
     534           0 :                                                 level++;
     535         134 :                                         } else if (op->opcode == ZEND_END_SILENCE) {
     536          37 :                                                 if (level == 0) {
     537          37 :                                                         break;
     538             :                                                 } else {
     539           0 :                                                         level--;
     540             :                                                 }
     541             :                                         }
     542         134 :                                         if (op->op1_type == IS_VAR && op->op1.var == var) {
     543          37 :                                                 if (use) {
     544             :                                                         /* used more than once */
     545           0 :                                                         use = NULL;
     546           0 :                                                         break;
     547             :                                                 }
     548          37 :                                                 use = op;
     549          60 :                                         } else if (op->op2_type == IS_VAR && op->op2.var == var) {
     550           0 :                                                 if (use) {
     551             :                                                         /* used more than once */
     552           0 :                                                         use = NULL;
     553           0 :                                                         break;
     554             :                                                 }
     555           0 :                                                 use = op;
     556             :                                         }
     557          97 :                                         op++;
     558             :                                 }
     559          37 :                                 if (use) {
     560          74 :                                         if (use->op1_type == IS_VAR && use->op1.var == var) {
     561          37 :                                                 use->op1_type = IS_CV;
     562          74 :                                                 use->op1.var = zend_optimizer_lookup_cv(op_array,
     563          37 :                                                         Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     564          37 :                                                         Z_STRLEN(ZEND_OP1_LITERAL(opline)));
     565          37 :                                                 MAKE_NOP(opline);
     566           0 :                                         } else if (use->op2_type == IS_VAR && use->op2.var == var) {
     567           0 :                                                 use->op2_type = IS_CV;
     568           0 :                                                 use->op2.var = zend_optimizer_lookup_cv(op_array,
     569           0 :                                                         Z_STRVAL(ZEND_OP1_LITERAL(opline)),
     570           0 :                                                         Z_STRLEN(ZEND_OP1_LITERAL(opline)));
     571           0 :                                                 MAKE_NOP(opline);
     572             :                                         }
     573             :                                 }
     574             :                         }
     575             :                         break;
     576             : #endif
     577             :                 
     578             :                 }
     579        6864 :                 opline++;
     580        6864 :                 i++;
     581             :         }
     582             : }

Generated by: LCOV version 1.10

Generated at Mon, 04 Aug 2014 15:49:18 +0000 (29 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.