zend_optimizer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend OPcache |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | https://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@php.net> |
  16. | Zeev Suraski <zeev@php.net> |
  17. | Stanislav Malyshev <stas@zend.com> |
  18. | Dmitry Stogov <dmitry@php.net> |
  19. +----------------------------------------------------------------------+
  20. */
  21. #ifndef ZEND_OPTIMIZER_H
  22. #define ZEND_OPTIMIZER_H
  23. #include "zend.h"
  24. #include "zend_compile.h"
  25. #define ZEND_OPTIMIZER_PASS_1 (1<<0) /* Simple local optimizations */
  26. #define ZEND_OPTIMIZER_PASS_2 (1<<1) /* */
  27. #define ZEND_OPTIMIZER_PASS_3 (1<<2) /* Jump optimization */
  28. #define ZEND_OPTIMIZER_PASS_4 (1<<3) /* INIT_FCALL_BY_NAME -> DO_FCALL */
  29. #define ZEND_OPTIMIZER_PASS_5 (1<<4) /* CFG based optimization */
  30. #define ZEND_OPTIMIZER_PASS_6 (1<<5) /* DFA based optimization */
  31. #define ZEND_OPTIMIZER_PASS_7 (1<<6) /* CALL GRAPH optimization */
  32. #define ZEND_OPTIMIZER_PASS_8 (1<<7) /* SCCP (constant propagation) */
  33. #define ZEND_OPTIMIZER_PASS_9 (1<<8) /* TMP VAR usage */
  34. #define ZEND_OPTIMIZER_PASS_10 (1<<9) /* NOP removal */
  35. #define ZEND_OPTIMIZER_PASS_11 (1<<10) /* Merge equal constants */
  36. #define ZEND_OPTIMIZER_PASS_12 (1<<11) /* Adjust used stack */
  37. #define ZEND_OPTIMIZER_PASS_13 (1<<12) /* Remove unused variables */
  38. #define ZEND_OPTIMIZER_PASS_14 (1<<13) /* DCE (dead code elimination) */
  39. #define ZEND_OPTIMIZER_PASS_15 (1<<14) /* (unsafe) Collect constants */
  40. #define ZEND_OPTIMIZER_PASS_16 (1<<15) /* Inline functions */
  41. #define ZEND_OPTIMIZER_IGNORE_OVERLOADING (1<<16) /* (unsafe) Ignore possibility of operator overloading */
  42. #define ZEND_OPTIMIZER_NARROW_TO_DOUBLE (1<<17) /* try to narrow long constant assignments to double */
  43. #define ZEND_OPTIMIZER_ALL_PASSES 0x7FFFFFFF
  44. #define DEFAULT_OPTIMIZATION_LEVEL "0x7FFEBFFF"
  45. #define ZEND_DUMP_AFTER_PASS_1 ZEND_OPTIMIZER_PASS_1
  46. #define ZEND_DUMP_AFTER_PASS_2 ZEND_OPTIMIZER_PASS_2
  47. #define ZEND_DUMP_AFTER_PASS_3 ZEND_OPTIMIZER_PASS_3
  48. #define ZEND_DUMP_AFTER_PASS_4 ZEND_OPTIMIZER_PASS_4
  49. #define ZEND_DUMP_AFTER_PASS_5 ZEND_OPTIMIZER_PASS_5
  50. #define ZEND_DUMP_AFTER_PASS_6 ZEND_OPTIMIZER_PASS_6
  51. #define ZEND_DUMP_AFTER_PASS_7 ZEND_OPTIMIZER_PASS_7
  52. #define ZEND_DUMP_AFTER_PASS_8 ZEND_OPTIMIZER_PASS_8
  53. #define ZEND_DUMP_AFTER_PASS_9 ZEND_OPTIMIZER_PASS_9
  54. #define ZEND_DUMP_AFTER_PASS_10 ZEND_OPTIMIZER_PASS_10
  55. #define ZEND_DUMP_AFTER_PASS_11 ZEND_OPTIMIZER_PASS_11
  56. #define ZEND_DUMP_AFTER_PASS_12 ZEND_OPTIMIZER_PASS_12
  57. #define ZEND_DUMP_AFTER_PASS_13 ZEND_OPTIMIZER_PASS_13
  58. #define ZEND_DUMP_AFTER_PASS_14 ZEND_OPTIMIZER_PASS_14
  59. #define ZEND_DUMP_BEFORE_OPTIMIZER (1<<16)
  60. #define ZEND_DUMP_AFTER_OPTIMIZER (1<<17)
  61. #define ZEND_DUMP_BEFORE_BLOCK_PASS (1<<18)
  62. #define ZEND_DUMP_AFTER_BLOCK_PASS (1<<19)
  63. #define ZEND_DUMP_BLOCK_PASS_VARS (1<<20)
  64. #define ZEND_DUMP_BEFORE_DFA_PASS (1<<21)
  65. #define ZEND_DUMP_AFTER_DFA_PASS (1<<22)
  66. #define ZEND_DUMP_DFA_CFG (1<<23)
  67. #define ZEND_DUMP_DFA_DOMINATORS (1<<24)
  68. #define ZEND_DUMP_DFA_LIVENESS (1<<25)
  69. #define ZEND_DUMP_DFA_PHI (1<<26)
  70. #define ZEND_DUMP_DFA_SSA (1<<27)
  71. #define ZEND_DUMP_DFA_SSA_VARS (1<<28)
  72. #define ZEND_DUMP_SCCP (1<<29)
  73. typedef struct _zend_script {
  74. zend_string *filename;
  75. zend_op_array main_op_array;
  76. HashTable function_table;
  77. HashTable class_table;
  78. uint32_t first_early_binding_opline; /* the linked list of delayed declarations */
  79. } zend_script;
  80. typedef void (*zend_optimizer_pass_t)(zend_script *, void *context);
  81. BEGIN_EXTERN_C()
  82. ZEND_API int zend_optimize_script(zend_script *script, zend_long optimization_level, zend_long debug_level);
  83. ZEND_API int zend_optimizer_register_pass(zend_optimizer_pass_t pass);
  84. ZEND_API void zend_optimizer_unregister_pass(int idx);
  85. int zend_optimizer_startup(void);
  86. int zend_optimizer_shutdown(void);
  87. END_EXTERN_C()
  88. #endif