Changeset 344 for eaccelerator/trunk/optimize.c
- Timestamp:
- 06/19/08 18:01:31 (7 months ago)
- Files:
-
- eaccelerator/trunk/optimize.c (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
eaccelerator/trunk/optimize.c
r324 r344 197 197 if ((op->op2.op_type == IS_VAR || op->op2.op_type == IS_TMP_VAR) && 198 198 !def[VAR_NUM(op->op2.u.var)] && !global[VAR_NUM(op->op2.u.var)]) { 199 #ifdef ZEND_ENGINE_2200 199 if (op->opcode != ZEND_OP_DATA) { 201 200 global[VAR_NUM(op->op2.u.var)] = 1; 202 201 } 203 #else 204 global[VAR_NUM(op->op2.u.var)] = 1; 205 #endif 206 } 207 #ifdef ZEND_ENGINE_2 202 } 208 203 if (op->opcode == ZEND_DECLARE_INHERITED_CLASS && 209 204 !def[VAR_NUM(op->extended_value)] && … … 211 206 global[VAR_NUM(op->extended_value)] = 1; 212 207 } 213 #endif214 208 if ((op->result.op_type == IS_VAR && 215 #ifdef ZEND_ENGINE_2216 209 (op->opcode == ZEND_RECV || op->opcode == ZEND_RECV_INIT || 217 210 (op->result.u.EA.type & EXT_TYPE_UNUSED) == 0)) || 218 #else219 (op->result.u.EA.type & EXT_TYPE_UNUSED) == 0) ||220 #endif221 211 (op->result.op_type == IS_TMP_VAR)) { 222 212 if (!def[VAR_NUM(op->result.u.var)] && !global[VAR_NUM(op->result.u.var)]) { … … 247 237 end--; 248 238 if (((end->result.op_type == IS_VAR && 249 #ifdef ZEND_ENGINE_2250 239 (end->opcode == ZEND_RECV || end->opcode == ZEND_RECV_INIT || 251 240 (end->result.u.EA.type & EXT_TYPE_UNUSED) == 0)) || 252 #else253 (end->result.u.EA.type & EXT_TYPE_UNUSED) == 0) ||254 #endif255 241 (end->result.op_type == IS_TMP_VAR)) && 256 242 !global[VAR_NUM(end->result.u.var)] && !used[VAR_NUM(end->result.u.var)]) { … … 288 274 break; 289 275 case ZEND_UNSET_VAR: 290 #ifndef ZEND_ENGINE_2_1291 /* Pre-PHP 5.1 only */292 case ZEND_UNSET_DIM_OBJ:293 end->result.op_type = IS_UNUSED;294 break;295 #else296 276 case ZEND_UNSET_DIM: 297 277 case ZEND_UNSET_OBJ: 298 278 end->result.op_type = IS_UNUSED; 299 279 break; 300 #endif301 280 case ZEND_RECV: 302 281 case ZEND_RECV_INIT: 303 282 /*case ZEND_ADD_ARRAY_ELEMENT:*/ 304 283 case ZEND_INCLUDE_OR_EVAL: 305 #ifndef ZEND_ENGINE_2_1306 /* Pre-PHP 5.1 only */307 case ZEND_JMP_NO_CTOR:308 #else309 284 case ZEND_NEW: 310 #endif311 285 case ZEND_FE_FETCH: 312 286 case ZEND_PRINT: 313 #ifdef ZEND_ENGINE_2314 287 case ZEND_INIT_METHOD_CALL: 315 288 case ZEND_INIT_STATIC_METHOD_CALL: … … 318 291 case ZEND_DECLARE_CLASS: 319 292 case ZEND_DECLARE_INHERITED_CLASS: 320 #endif321 293 break; 322 294 default: … … 331 303 } else if (end->result.op_type == IS_VAR && 332 304 (end->result.u.EA.type & EXT_TYPE_UNUSED) != 0 && 333 #ifdef ZEND_ENGINE_2334 305 end->opcode != ZEND_RECV && end->opcode != ZEND_RECV_INIT && 335 #endif336 306 used[VAR_NUM(end->result.u.var)]) { 337 307 end->result.u.EA.type &= ~EXT_TYPE_UNUSED; 338 308 } 339 309 if ((end->result.op_type == IS_VAR && 340 #ifdef ZEND_ENGINE_2341 310 (end->opcode == ZEND_RECV || end->opcode == ZEND_RECV_INIT || 342 311 (end->result.u.EA.type & EXT_TYPE_UNUSED) == 0)) || 343 #else344 (end->result.u.EA.type & EXT_TYPE_UNUSED) == 0) ||345 #endif346 312 (end->result.op_type == IS_TMP_VAR)) { 347 313 switch (end->opcode) { … … 361 327 used[VAR_NUM(end->op2.u.var)] = 1; 362 328 } 363 #ifdef ZEND_ENGINE_2364 329 if (end->opcode == ZEND_DECLARE_INHERITED_CLASS) { 365 330 used[VAR_NUM(end->extended_value)] = 1; 366 331 } 367 #endif368 332 } 369 333 p = p->next; … … 1334 1298 } 1335 1299 goto jmp_2; 1336 #ifndef ZEND_ENGINE_2_11337 /* Pre-PHP 5.1 only */1338 case ZEND_JMP_NO_CTOR:1339 #else1340 1300 case ZEND_NEW: 1341 #endif1342 1301 case ZEND_FE_FETCH: 1343 1302 jmp_2: … … 1626 1585 } 1627 1586 1628 #ifndef ZEND_ENGINE_21629 #define FETCH_TYPE(op) ((op)->op2.u.fetch_type)1630 #else1631 1587 #define FETCH_TYPE(op) ((op)->op2.u.EA.type) 1632 #endif1633 1634 1588 #define SET_UNDEFINED(op) Ts[VAR_NUM((op).u.var)] = NULL; 1635 1589 #define SET_DEFINED(op) Ts[VAR_NUM((op)->result.u.var)] = (op); … … 2082 2036 */ 2083 2037 } else if ( 2084 #ifndef ZEND_ENGINE_22085 op_array->uses_globals &&2086 #endif2087 2038 ((op->opcode == ZEND_FETCH_DIM_R && 2088 2039 op->op1.op_type == IS_VAR && … … 2110 2061 IS_DEFINED(op->op1) && 2111 2062 DEFINED_OP(op->op1)->opcode == ZEND_FETCH_UNSET)) && 2112 #ifdef ZEND_ENGINE_22113 2063 FETCH_TYPE(DEFINED_OP(op->op1)) == ZEND_FETCH_GLOBAL && 2114 #else2115 FETCH_TYPE(DEFINED_OP(op->op1)) == ZEND_FETCH_LOCAL &&2116 #endif2117 2064 DEFINED_OP(op->op1)->op1.op_type == IS_CONST && 2118 2065 DEFINED_OP(op->op1)->op1.u.constant.type == IS_STRING && … … 2129 2076 SET_DEFINED(x); 2130 2077 SET_TO_NOP(op); 2131 #ifndef ZEND_ENGINE_2 2132 if (x->op1.op_type == IS_VAR) { 2133 memcpy(&op->op1,&x->op1,sizeof(znode)); 2134 op->opcode = ZEND_SWITCH_FREE; 2135 op->extended_value = 0; 2136 } 2137 #endif 2138 } 2139 #ifdef ZEND_ENGINE_2 2078 } 2140 2079 /* FETCH_IS local("GLOBALS"),$x ISSET_ISEMPTY_VAR $y(global),res 2141 2080 ISSET_ISEMPTY_DIM_OBJ $x,$y,$res => NOP … … 2159 2098 SET_DEFINED(x); 2160 2099 SET_TO_NOP(op); 2161 #endif2162 2100 } else if (op->opcode == ZEND_FREE && 2163 2101 op->op1.op_type == IS_TMP_VAR && … … 2500 2438 op->opcode == ZEND_POST_INC || 2501 2439 op->opcode == ZEND_POST_DEC || 2502 #ifndef ZEND_ENGINE_2_12503 /* Pre-PHP 5.1 only */2504 op->opcode == ZEND_UNSET_DIM_OBJ ||2505 #else2506 2440 op->opcode == ZEND_UNSET_DIM || 2507 2441 op->opcode == ZEND_UNSET_OBJ || 2508 #endif 2509 op->opcode == ZEND_INCLUDE_OR_EVAL 2510 #ifdef ZEND_ENGINE_2 2511 || op->opcode == ZEND_ASSIGN_DIM 2512 || op->opcode == ZEND_ASSIGN_OBJ 2513 #endif 2514 ) { 2442 op->opcode == ZEND_INCLUDE_OR_EVAL || 2443 op->opcode == ZEND_ASSIGN_DIM || 2444 op->opcode == ZEND_ASSIGN_OBJ) { 2515 2445 zend_hash_clean(&assigns); 2516 2446 zend_hash_clean(&fetch_dim); … … 2534 2464 if ((op->result.u.EA.type & EXT_TYPE_UNUSED) != 0 && 2535 2465 op->op1.op_type == IS_VAR && 2536 #ifdef ZEND_ENGINE_22537 2466 op->extended_value != ZEND_ASSIGN_DIM && 2538 2467 op->extended_value != ZEND_ASSIGN_OBJ && 2539 #endif2540 2468 IS_DEFINED(op->op1)) { 2541 2469 zend_op *x = DEFINED_OP(op->op1); … … 2642 2570 } 2643 2571 if ((op->result.op_type == IS_VAR && 2644 #ifdef ZEND_ENGINE_22645 2572 (op->opcode == ZEND_RECV || op->opcode == ZEND_RECV_INIT || 2646 2573 (op->result.u.EA.type & EXT_TYPE_UNUSED) == 0)) || 2647 #else2648 (op->result.u.EA.type & EXT_TYPE_UNUSED) == 0) ||2649 #endif2650 2574 (op->result.op_type == IS_TMP_VAR)) { 2651 2575 if (op->opcode == ZEND_RECV || … … 2696 2620 BB* p; 2697 2621 int remove_brk_cont_array = 1; 2698 #ifndef ZEND_ENGINE_2 2699 int* overload_var = do_alloca(op_array->T * sizeof(int)); 2700 memset(overload_var,-1,op_array->T * sizeof(int)); 2701 #else 2702 /* HOESH: Just to use later... */ 2622 2623 /* HOESH: Just to use later... */ 2703 2624 zend_uint innermost_ketchup; 2704 2625 … … 2717 2638 } 2718 2639 } 2719 #endif 2720 /* Find Starts of Basic Blocks */2640 2641 /* Find Starts of Basic Blocks */ 2721 2642 bb[0].start = op; 2722 2643 for (line_num=0; line_num < len; op++,line_num++) 2723 2644 { 2724 #ifdef ZEND_ENGINE_22725 2645 const opcode_dsc* dsc = get_opcode_dsc(op->opcode); 2726 2646 if (dsc != NULL) … … 2764 2684 } 2765 2685 } 2766 #endif2767 2686 switch(op->opcode) 2768 2687 { … … 2784 2703 case ZEND_JMPZ_EX: 2785 2704 case ZEND_JMPNZ_EX: 2786 #ifndef ZEND_ENGINE_2_12787 /* Pre-PHP 5.1 only */2788 case ZEND_JMP_NO_CTOR:2789 #else2790 2705 case ZEND_NEW: 2791 2706 case ZEND_FE_RESET: 2792 #endif2793 2707 case ZEND_FE_FETCH: 2794 2708 bb[line_num+1].start = op+1; … … 2875 2789 bb[line_num+1].start = op+1; 2876 2790 break; 2877 #ifdef ZEND_ENGINE_22878 2791 case ZEND_CATCH: 2879 2792 bb[op->extended_value].start = &op_array->opcodes[op->extended_value]; … … 2895 2808 } 2896 2809 break; 2897 #else2898 case ZEND_INIT_FCALL_BY_NAME:2899 if (op->op1.op_type == IS_VAR && op->result.op_type == IS_VAR)2900 {2901 overload_var[op->result.u.var] = op->op1.u.var;2902 op->result.u.var = op->op1.u.var;2903 }2904 break;2905 case ZEND_DO_FCALL_BY_NAME:2906 if (op->op1.op_type == IS_VAR && overload_var[op->op1.u.var] >= 0)2907 {2908 op->op1.u.var = overload_var[op->op1.u.var];2909 }2910 break;2911 #endif2912 2810 case ZEND_UNSET_VAR: 2913 #ifndef ZEND_ENGINE_2_12914 /* Pre-PHP 5.1 only */2915 case ZEND_UNSET_DIM_OBJ:2916 op->result.op_type = IS_UNUSED;2917 break;2918 #else2919 2811 case ZEND_UNSET_DIM: 2920 2812 op->result.op_type = IS_UNUSED; … … 2923 2815 op->result.op_type = IS_UNUSED; 2924 2816 break; 2925 #endif2926 2817 default: 2927 2818 break; … … 2929 2820 } 2930 2821 2931 #ifndef ZEND_ENGINE_22932 free_alloca(overload_var);2933 #endif2934 2935 2822 /* Find Lengths of Basic Blocks and build CFG */ 2936 2823 p = bb; 2937 2824 for (line_num=1; line_num < len; line_num++) 2938 2825 { 2939 #ifdef ZEND_ENGINE_22940 2826 /* Calculate innermost CATCH op */ 2941 2827 innermost_ketchup = 0; … … 2957 2843 } 2958 2844 } 2959 #endif2960 2845 if (bb[line_num].start != NULL) 2961 2846 { … … 2967 2852 case ZEND_JMP: 2968 2853 p->jmp_1 = &bb[op->op1.u.opline_num]; 2969 #ifdef ZEND_ENGINE_22970 2854 if (op->extended_value == ZEND_BRK || op->extended_value == ZEND_CONT) 2971 2855 { … … 2983 2867 } 2984 2868 # endif 2985 #endif2986 2869 break; 2987 2870 case ZEND_JMPZNZ: … … 2993 2876 case ZEND_JMPZ_EX: 2994 2877 case ZEND_JMPNZ_EX: 2995 #ifndef ZEND_ENGINE_2_12996 /* Pre-PHP 5.1 only */2997 case ZEND_JMP_NO_CTOR:2998 #else2999 2878 case ZEND_NEW: 3000 2879 case ZEND_FE_RESET: 3001 #endif3002 2880 case ZEND_FE_FETCH: 3003 2881 p->jmp_2 = &bb[op->op2.u.opline_num]; … … 3008 2886 case ZEND_BRK: 3009 2887 case ZEND_CONT: 3010 #ifdef ZEND_ENGINE_23011 2888 /* HOESH: The control might flow to the innermost CATCH 3012 2889 * op if an exception thrown earlier. We can follow to CATCH … … 3036 2913 } 3037 2914 p->follow = &bb[line_num]; 3038 #endif3039 2915 break; 3040 2916 default: … … 3111 2987 } 3112 2988 3113 #ifdef ZEND_ENGINE_23114 2989 /* 3115 2990 * HOESH: Reassign try & catch blocks … … 3160 3035 } 3161 3036 } 3162 #endif3163 3037 } 3164 3038 … … 3186 3060 zend_uint i; 3187 3061 zend_uint n = 0; 3188 #ifndef ZEND_ENGINE_23189 int uses_globals = 0;3190 #endif3191 3062 int* assigned = do_alloca(op_array->T * sizeof(int)); 3192 3063 char* reg_pool = do_alloca(op_array->T * sizeof(char)); … … 3203 3074 zend_op* start = p->start; 3204 3075 zend_op* op = start + p->len; 3205 #ifdef ZEND_ENGINE_23206 3076 zend_op* op_data; 3207 #endif3208 3077 3209 3078 for (i = 0; i < op_array->T; i++) { … … 3217 3086 --op; 3218 3087 /* zend_printf("op=%d\n", op-op_array->opcodes); */ 3219 #ifdef ZEND_ENGINE_23220 3088 op_data = NULL; 3221 #else3222 if (op_array->uses_globals &&3223 (op->opcode == ZEND_FETCH_R ||3224 op->opcode == ZEND_FETCH_W ||3225 op->opcode == ZEND_FETCH_RW ||3226 op->opcode == ZEND_FETCH_IS ||3227 op->opcode == ZEND_FETCH_FUNC_ARG ||3228 op->opcode == ZEND_FETCH_UNSET) &&3229 op->op1.op_type == IS_CONST &&3230 op->op1.u.constant.type == IS_STRING &&3231 op->op1.u.constant.value.str.len == (sizeof("GLOBALS")-1) &&3232 memcmp(op->op1.u.constant.value.str.val, "GLOBALS", sizeof("GLOBALS")-1) == 0) {3233 uses_globals = 1;3234 }3235 #endif3236 3089 if (op->opcode == ZEND_DO_FCALL_BY_NAME && 3237 3090 op->op1.op_type == IS_CONST) { … … 3257 3110 op->op2.u.var = VAR_VAL(assigned[r]); 3258 3111 } 3259 #ifdef ZEND_ENGINE_23260 3112 if (op->opcode == ZEND_DECLARE_INHERITED_CLASS) { 3261 3113 int r = VAR_NUM(op->extended_value); … … 3263 3115 op->extended_value = VAR_VAL(assigned[r]); 3264 3116 } 3265 #endif3266 3117 if (op->result.op_type == IS_VAR || 3267 3118 op->result.op_type == IS_TMP_VAR) { … … 3270 3121 op->result.u.var = VAR_VAL(assigned[r]); 3271 3122 if (op->result.op_type == IS_VAR && 3272 #ifdef ZEND_ENGINE_23273 3123 op->opcode != ZEND_RECV && op->opcode != ZEND_RECV_INIT && 3274 #endif3275 3124 ((op->result.u.EA.type & EXT_TYPE_UNUSED) != 0)) { 3276 3125 FREE_REG(VAR_NUM(op->result.u.var)) … … 3295 3144 } 3296 3145 op_array->T = n; 3297 #ifndef ZEND_ENGINE_23298 if (op_array->uses_globals && !uses_globals) {3299 op_array->uses_globals = 0;3300 }3301 #endif3302 3146 free_alloca(used); 3303 3147 free_alloca(reg_pool); … … 3329 3173 3330 3174 TSRMLS_FETCH(); 3331 /*???3332 #ifdef ZEND_ENGINE_23333 return;3334 #endif3335 */3336 3175 if (!EAG(compiler) || op_array->type != ZEND_USER_FUNCTION) { 3337 3176 return; … … 3390 3229 free_alloca(global); 3391 3230 } 3392 # ifdef ZEND_ENGINE_2_13393 3231 else { 3394 3232 /* build_cfg encountered some nested ZEND_BRK or ZEND_CONT's … … 3402 3240 restore_operand_types(op_array); 3403 3241 } 3404 # endif3405 3242 free_alloca(bb); 3406 3243 }