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 - optimize_temp_vars_5.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 71 77 92.2 %
Date: 2014-08-04 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
       2             : 
       3             : /* ops that use CLs:
       4             : op1:
       5             : ZEND_FETCH_CONSTANT:
       6             : ZEND_INIT_CTOR_CALL:
       7             : ZEND_INIT_STATIC_METHOD_CALL:
       8             : ZEND_INIT_METHOD_CALL:
       9             : ZEND_IMPORT_CLASS:
      10             : ZEND_IMPORT_FUNCTION:
      11             : ZEND_IMPORT_CONST:
      12             : ZEND_ADD_INTERFACE:
      13             : ZEND_VERIFY_ABSTRACT_CLASS:
      14             : ZEND_NEW:
      15             : ZEND_CATCH:
      16             : ZEND_INIT_FCALL_BY_NAME:
      17             : 
      18             : op2:
      19             : ZEND_UNSET_VAR:
      20             : ZEND_ISSET_ISEMPTY_VAR:
      21             : ZEND_FETCH_UNSET:
      22             : ZEND_FETCH_IS:
      23             : ZEND_FETCH_R:
      24             : ZEND_FETCH_W:
      25             : ZEND_FETCH_RW:
      26             : ZEND_FETCH_FUNC_ARG:
      27             : ZEND_ADD_INTERFACE:
      28             : ZEND_INSTANCEOF:
      29             : 
      30             : extended_value:
      31             : ZEND_DECLARE_INHERITED_CLASS:
      32             : 
      33             : ignore result
      34             : INIT_METHOD_CALL:
      35             : */
      36             : 
      37             : #define OP1_CONST_IS_CLASS 1
      38             : #define OP2_CONST_IS_CLASS 2
      39             : #define EXT_CONST_IS_CLASS 4
      40             : #define RESULT_IS_UNUSED   8
      41             : 
      42             : static const char op_const_means_class[256]  = {
      43             :         /* 0 */
      44             :         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      45             :         /* 32 */
      46             :         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
      47             :         /* 64 */
      48             :         0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 2,
      49             :         /* 96 */
      50             :         0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 9, 1, 2, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      51             :         /* 128 */
      52             :         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 0, 0, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      53             :         /* 160 */
      54             :         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      55             :         /* 192 */
      56             :         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      57             :         /* 224 */
      58             :         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
      59             : };
      60             : #endif
      61             : 
      62             : #define GET_AVAILABLE_T()               \
      63             :         for (i = 0; i < T; i++) {    \
      64             :                 if (!taken_T[i]) {              \
      65             :                         break;                          \
      66             :                 }                                               \
      67             :         }                                                       \
      68             :         taken_T[i] = 1;                         \
      69             :         if (i > max) {                               \
      70             :                 max = i;                                \
      71             :         }
      72             : 
      73         451 : static void optimize_temporary_variables(zend_op_array *op_array)
      74             : {
      75         451 :         int T = op_array->T;
      76             :         char *taken_T;                  /* T index in use */
      77             :         zend_op **start_of_T;   /* opline where T is first used */
      78             :         char *valid_T;                  /* Is the map_T valid */
      79             :         int *map_T;                             /* Map's the T to its new index */
      80             :         zend_op *opline, *end;
      81             :         int currT;
      82             :         int i;
      83         451 :         int max = -1;
      84         451 :         int var_to_free = -1;
      85             : 
      86         451 :         taken_T = (char *) emalloc(T);
      87         451 :         start_of_T = (zend_op **) emalloc(T * sizeof(zend_op *));
      88         451 :         valid_T = (char *) emalloc(T);
      89         451 :         map_T = (int *) emalloc(T * sizeof(int));
      90             : 
      91         451 :     end = op_array->opcodes;
      92         451 :     opline = &op_array->opcodes[op_array->last - 1];
      93             : 
      94             :     /* Find T definition points */
      95        5920 :     while (opline >= end) {
      96             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
      97             :         if (ZEND_RESULT_TYPE(opline) & (IS_VAR | IS_TMP_VAR | IS_CONST)) {
      98             :                         if (!(op_const_means_class[opline->opcode] & RESULT_IS_UNUSED)) {
      99             :                                 start_of_T[VAR_NUM(ZEND_RESULT(opline).var)] = opline;
     100             :                         }
     101             :                 }
     102             : #else
     103        5018 :         if (ZEND_RESULT_TYPE(opline) & (IS_VAR | IS_TMP_VAR)) {
     104        2405 :                         start_of_T[VAR_NUM(ZEND_RESULT(opline).var)] = opline;
     105             :                 }
     106             : #endif
     107        5018 :                 opline--;
     108             :         }
     109             : 
     110         451 :         memset(valid_T, 0, T);
     111         451 :         memset(taken_T, 0, T);
     112             : 
     113         451 :     end = op_array->opcodes;
     114         451 :     opline = &op_array->opcodes[op_array->last - 1];
     115             : 
     116        5920 :     while (opline >= end) {
     117        5018 :                 if ((ZEND_OP1_TYPE(opline) & (IS_VAR | IS_TMP_VAR))
     118             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     119             :                         || ((op_const_means_class[opline->opcode] & OP1_CONST_IS_CLASS) && ZEND_OP1_TYPE(opline) == IS_CONST)
     120             : #endif
     121             :                         ) {
     122        1255 :                         currT = VAR_NUM(ZEND_OP1(opline).var);
     123        1255 :                         if (!valid_T[currT]) {
     124        1208 :                                 GET_AVAILABLE_T();
     125        1208 :                                 map_T[currT] = i;
     126        1208 :                                 valid_T[currT] = 1;
     127             :                         }
     128        1255 :                         ZEND_OP1(opline).var = NUM_VAR(map_T[currT]);
     129             :                 }
     130             : 
     131             :                 /* Skip OP_DATA */
     132        5025 :                 if (opline->opcode == ZEND_OP_DATA &&
     133           7 :                     (opline-1)->opcode == ZEND_ASSIGN_DIM) {
     134           4 :                     opline--;
     135           4 :                     continue;
     136             :                 }
     137             : 
     138        5014 :                 if ((ZEND_OP2_TYPE(opline) & (IS_VAR | IS_TMP_VAR))
     139             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     140             :                         || ((op_const_means_class[opline->opcode] & OP2_CONST_IS_CLASS) && ZEND_OP2_TYPE(opline) == IS_CONST)
     141             : #endif
     142             :                    ) {
     143         231 :                         currT = VAR_NUM(ZEND_OP2(opline).var);
     144         231 :                         if (!valid_T[currT]) {
     145         231 :                                 GET_AVAILABLE_T();
     146         231 :                                 map_T[currT] = i;
     147         231 :                                 valid_T[currT] = 1;
     148             :                         }
     149         231 :                         ZEND_OP2(opline).var = NUM_VAR(map_T[currT]);
     150             :                 }
     151             : 
     152             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     153             :                 if ((op_const_means_class[opline->opcode] & EXT_CONST_IS_CLASS)) {
     154             : #else
     155       10028 :                 if (opline->opcode == ZEND_DECLARE_INHERITED_CLASS ||
     156        5014 :             opline->opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED) {
     157             : #endif
     158           0 :                         currT = VAR_NUM(opline->extended_value);
     159           0 :                         if (!valid_T[currT]) {
     160           0 :                                 GET_AVAILABLE_T();
     161           0 :                                 map_T[currT] = i;
     162           0 :                                 valid_T[currT] = 1;
     163             :                         }
     164           0 :                         opline->extended_value = NUM_VAR(map_T[currT]);
     165             :                 }
     166             : 
     167             :                 /* Allocate OP_DATA->op2 after "operands", but before "result" */
     168        5022 :                 if (opline->opcode == ZEND_ASSIGN_DIM &&
     169           4 :                     (opline + 1)->opcode == ZEND_OP_DATA &&
     170           4 :                     ZEND_OP2_TYPE(opline + 1) & (IS_VAR | IS_TMP_VAR)) {
     171           4 :                         currT = VAR_NUM(ZEND_OP2(opline + 1).var);
     172           4 :                         GET_AVAILABLE_T();
     173           4 :                         map_T[currT] = i;
     174           4 :                         valid_T[currT] = 1;
     175           4 :                         taken_T[i] = 0;
     176           4 :                         ZEND_OP2(opline + 1).var = NUM_VAR(i);
     177           4 :                         var_to_free = i;
     178             :                 }
     179             : 
     180             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     181             :                 if (ZEND_RESULT_TYPE(opline) & (IS_VAR | IS_TMP_VAR | IS_CONST)) {
     182             :                         if (!(op_const_means_class[opline->opcode] & RESULT_IS_UNUSED)) {
     183             : #else
     184        5014 :                 if (ZEND_RESULT_TYPE(opline) & (IS_VAR | IS_TMP_VAR)) {
     185             : #endif
     186        2405 :                                 currT = VAR_NUM(ZEND_RESULT(opline).var);
     187        2405 :                                 if (valid_T[currT]) {
     188        1626 :                                         if (start_of_T[currT] == opline) {
     189        1438 :                                                 taken_T[map_T[currT]] = 0;
     190             :                                         }
     191        1626 :                                         ZEND_RESULT(opline).var = NUM_VAR(map_T[currT]);
     192             :                                 } else { /* Au still needs to be assigned a T which is a bit dumb. Should consider changing Zend */
     193         779 :                                         GET_AVAILABLE_T();
     194             : 
     195         779 :                                         if (RESULT_UNUSED(opline)) {
     196         777 :                                                 taken_T[i] = 0;
     197             :                                         } else {
     198             :                                                 /* Code which gets here is using a wrongly built opcode such as RECV() */
     199           2 :                                                 map_T[currT] = i;
     200           2 :                                                 valid_T[currT] = 1;
     201             :                                         }
     202         779 :                                         ZEND_RESULT(opline).var = NUM_VAR(i);
     203             :                                 }
     204             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     205             :                         }
     206             : #endif
     207             :                 }
     208             : 
     209        5014 :                 if (var_to_free >= 0) {
     210           4 :                         taken_T[var_to_free] = 0;
     211           4 :                         var_to_free = -1;
     212             :                 }
     213             : 
     214        5014 :                 opline--;
     215             :         }
     216             : 
     217         451 :         efree(taken_T);
     218         451 :         efree(start_of_T);
     219         451 :         efree(valid_T);
     220         451 :         efree(map_T);
     221         451 :         op_array->T = max + 1;
     222         451 : }

Generated by: LCOV version 1.10

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

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