mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Optimizer: Use return true / return false for functions returning bool
Changes done with Coccinelle:
@r1@
identifier fn;
typedef bool;
symbol false;
symbol true;
@@
bool fn ( ... )
{
<...
return
(
- 0
+ false
|
- 1
+ true
)
;
...>
}
Coccinelle patch sourced from
torvalds/linux@46b5c9b856.
This commit is contained in:
committed by
Tim Düsterhus
parent
8bbd59f064
commit
0b4ba560ce
@@ -42,9 +42,9 @@ bool zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int
|
||||
if (copy) {
|
||||
Z_TRY_ADDREF_P(result);
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
} else {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,9 +52,9 @@ bool zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int
|
||||
c = zend_get_special_const(ZSTR_VAL(name), ZSTR_LEN(name));
|
||||
if (c) {
|
||||
ZVAL_COPY_VALUE(result, &c->value);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Data dependencies macros */
|
||||
|
||||
@@ -62,13 +62,13 @@ typedef struct {
|
||||
static inline bool is_bad_mod(const zend_ssa *ssa, int use, int def) {
|
||||
if (def < 0) {
|
||||
/* This modification is not tracked by SSA, assume the worst */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (ssa->var_info[use].type & MAY_BE_REF) {
|
||||
/* Modification of reference may have side-effect */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool may_have_side_effects(
|
||||
@@ -125,18 +125,18 @@ static inline bool may_have_side_effects(
|
||||
case ZEND_FUNC_GET_ARGS:
|
||||
case ZEND_ARRAY_KEY_EXISTS:
|
||||
/* No side effects */
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_FREE:
|
||||
return opline->extended_value == ZEND_FREE_VOID_CAST;
|
||||
case ZEND_ADD_ARRAY_ELEMENT:
|
||||
/* TODO: We can't free two vars. Keep instruction alive. <?php [0, "$a" => "$b"]; */
|
||||
if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) && (opline->op2_type & (IS_VAR|IS_TMP_VAR))) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_ROPE_END:
|
||||
/* TODO: Rope dce optimization, see #76446 */
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_JMP:
|
||||
case ZEND_JMPZ:
|
||||
case ZEND_JMPNZ:
|
||||
@@ -149,7 +149,7 @@ static inline bool may_have_side_effects(
|
||||
case ZEND_BIND_INIT_STATIC_OR_JMP:
|
||||
case ZEND_JMP_FRAMELESS:
|
||||
/* For our purposes a jumps and branches are side effects. */
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_BEGIN_SILENCE:
|
||||
case ZEND_END_SILENCE:
|
||||
case ZEND_ECHO:
|
||||
@@ -164,7 +164,7 @@ static inline bool may_have_side_effects(
|
||||
case ZEND_YIELD_FROM:
|
||||
case ZEND_VERIFY_NEVER_TYPE:
|
||||
/* Intrinsic side effects */
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_DO_FCALL:
|
||||
case ZEND_DO_FCALL_BY_NAME:
|
||||
case ZEND_DO_ICALL:
|
||||
@@ -174,31 +174,31 @@ static inline bool may_have_side_effects(
|
||||
case ZEND_FRAMELESS_ICALL_2:
|
||||
case ZEND_FRAMELESS_ICALL_3:
|
||||
/* For now assume all calls have side effects */
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_RECV:
|
||||
case ZEND_RECV_INIT:
|
||||
/* Even though RECV_INIT can be side-effect free, these cannot be simply dropped
|
||||
* due to the prologue skipping code. */
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_ASSIGN_REF:
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_ASSIGN:
|
||||
{
|
||||
if (is_bad_mod(ssa, ssa_op->op1_use, ssa_op->op1_def)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (!reorder_dtor_effects) {
|
||||
if (opline->op2_type != IS_CONST
|
||||
&& (OP2_INFO() & MAY_HAVE_DTOR)
|
||||
&& ssa->vars[ssa_op->op2_use].escape_state != ESCAPE_STATE_NO_ESCAPE) {
|
||||
/* DCE might shorten lifetime */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
case ZEND_UNSET_VAR:
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_UNSET_CV:
|
||||
{
|
||||
uint32_t t1 = OP1_INFO();
|
||||
@@ -207,9 +207,9 @@ static inline bool may_have_side_effects(
|
||||
* an unset may be considered dead even if there is a later assignment to the
|
||||
* variable. Removing the unset in this case would not be correct if the variable
|
||||
* is a reference, because unset breaks references. */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
case ZEND_PRE_INC:
|
||||
case ZEND_POST_INC:
|
||||
@@ -223,7 +223,7 @@ static inline bool may_have_side_effects(
|
||||
case ZEND_ASSIGN_OBJ:
|
||||
if (is_bad_mod(ssa, ssa_op->op1_use, ssa_op->op1_def)
|
||||
|| ssa->vars[ssa_op->op1_def].escape_state != ESCAPE_STATE_NO_ESCAPE) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (!reorder_dtor_effects) {
|
||||
opline++;
|
||||
@@ -231,33 +231,33 @@ static inline bool may_have_side_effects(
|
||||
if (opline->op1_type != IS_CONST
|
||||
&& (OP1_INFO() & MAY_HAVE_DTOR)) {
|
||||
/* DCE might shorten lifetime */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_PRE_INC_OBJ:
|
||||
case ZEND_PRE_DEC_OBJ:
|
||||
case ZEND_POST_INC_OBJ:
|
||||
case ZEND_POST_DEC_OBJ:
|
||||
if (is_bad_mod(ssa, ssa_op->op1_use, ssa_op->op1_def)
|
||||
|| ssa->vars[ssa_op->op1_def].escape_state != ESCAPE_STATE_NO_ESCAPE) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_BIND_STATIC:
|
||||
if (op_array->static_variables) {
|
||||
/* Implicit and Explicit bind static is effectively prologue of closure so
|
||||
report it has side effects like RECV, RECV_INIT; This allows us to
|
||||
reflect on the closure and discover used variable at runtime */
|
||||
if ((opline->extended_value & (ZEND_BIND_IMPLICIT|ZEND_BIND_EXPLICIT))) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
/* Modifies static variables which are observable through reflection */
|
||||
if ((opline->extended_value & ZEND_BIND_REF) && opline->op2_type != IS_UNUSED) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_CHECK_VAR:
|
||||
return (OP1_INFO() & MAY_BE_UNDEF) != 0;
|
||||
case ZEND_FE_RESET_R:
|
||||
@@ -267,7 +267,7 @@ static inline bool may_have_side_effects(
|
||||
return (OP1_INFO() & MAY_BE_ANY) != MAY_BE_ARRAY;
|
||||
default:
|
||||
/* For everything we didn't handle, assume a side-effect */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ static inline bool is_var_dead(context *ctx, int var_num) {
|
||||
// Sometimes we can mark the var as EXT_UNUSED
|
||||
static bool try_remove_var_def(context *ctx, int free_var, int use_chain, zend_op *opline) {
|
||||
if (use_chain >= 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
zend_ssa_var *var = &ctx->ssa->vars[free_var];
|
||||
int def = var->definition;
|
||||
@@ -381,13 +381,13 @@ static bool try_remove_var_def(context *ctx, int free_var, int use_chain, zend_o
|
||||
def_opline->result.var = 0;
|
||||
def_op->result_def = -1;
|
||||
var->definition = -1;
|
||||
return 1;
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static zend_always_inline bool may_be_refcounted(uint32_t type) {
|
||||
@@ -400,13 +400,13 @@ static inline bool is_free_of_live_var(context *ctx, zend_op *opline, zend_ssa_o
|
||||
/* It is always safe to remove FREEs of non-refcounted values, even if they are live. */
|
||||
if ((ctx->ssa->var_info[ssa_op->op1_use].type & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) != 0
|
||||
&& !may_be_refcounted(ctx->ssa->var_info[ssa_op->op1_use].type)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
ZEND_FALLTHROUGH;
|
||||
case ZEND_FE_FREE:
|
||||
return !is_var_dead(ctx, ssa_op->op1_use);
|
||||
default:
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,12 +417,12 @@ static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
|
||||
uint8_t free_var_type;
|
||||
|
||||
if (opline->opcode == ZEND_NOP) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* We mark FREEs as dead, but they're only really dead if the destroyed var is dead */
|
||||
if (is_free_of_live_var(ctx, opline, ssa_op)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((opline->op1_type & (IS_VAR|IS_TMP_VAR))&& !is_var_dead(ctx, ssa_op->op1_use)) {
|
||||
@@ -440,7 +440,7 @@ static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
|
||||
if (free_var >= 0) {
|
||||
// TODO: We can't free two vars. Keep instruction alive.
|
||||
zend_bitset_excl(ctx->instr_dead, opline - ctx->op_array->opcodes);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
free_var = ssa_op->op2_use;
|
||||
free_var_type = opline->op2_type;
|
||||
@@ -459,9 +459,9 @@ static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
|
||||
ssa_op->op1_use = free_var;
|
||||
ssa_op->op1_use_chain = ssa->vars[free_var].use_chain;
|
||||
ssa->vars[free_var].use_chain = ssa_op - ssa->ops;
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline int get_common_phi_source(zend_ssa *ssa, zend_ssa_phi *phi) {
|
||||
@@ -507,17 +507,17 @@ static void try_remove_trivial_phi(context *ctx, zend_ssa_phi *phi) {
|
||||
static inline bool may_break_varargs(const zend_op_array *op_array, const zend_ssa *ssa, const zend_ssa_op *ssa_op) {
|
||||
if (ssa_op->op1_def >= 0
|
||||
&& ssa->vars[ssa_op->op1_def].var < op_array->num_args) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (ssa_op->op2_def >= 0
|
||||
&& ssa->vars[ssa_op->op2_def].var < op_array->num_args) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (ssa_op->result_def >= 0
|
||||
&& ssa->vars[ssa_op->result_def].var < op_array->num_args) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool may_throw_dce_exception(const zend_op *opline) {
|
||||
|
||||
@@ -256,11 +256,11 @@ static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_op
|
||||
|
||||
static bool safe_instanceof(const zend_class_entry *ce1, const zend_class_entry *ce2) {
|
||||
if (ce1 == ce2) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (!(ce1->ce_flags & ZEND_ACC_LINKED)) {
|
||||
/* This case could be generalized, similarly to unlinked_instanceof */
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
return instanceof_function(ce1, ce2);
|
||||
}
|
||||
@@ -297,7 +297,7 @@ static inline bool can_elide_return_type_check(
|
||||
zend_ssa_var_info *use_info = &ssa->var_info[ssa_op->op1_use];
|
||||
uint32_t use_type = use_info->type & (MAY_BE_ANY|MAY_BE_UNDEF);
|
||||
if (use_type & MAY_BE_REF) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (use_type & MAY_BE_UNDEF) {
|
||||
@@ -322,20 +322,20 @@ static bool opline_supports_assign_contraction(
|
||||
zend_op_array *op_array, zend_ssa *ssa, zend_op *opline, int src_var, uint32_t cv_var) {
|
||||
if (opline->opcode == ZEND_NEW) {
|
||||
/* see Zend/tests/generators/aborted_yield_during_new.phpt */
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Frameless calls override the return value, but the return value may overlap with the arguments. */
|
||||
switch (opline->opcode) {
|
||||
case ZEND_FRAMELESS_ICALL_3:
|
||||
if ((opline + 1)->op1_type == IS_CV && (opline + 1)->op1.var == cv_var) return 0;
|
||||
if ((opline + 1)->op1_type == IS_CV && (opline + 1)->op1.var == cv_var) return false;
|
||||
ZEND_FALLTHROUGH;
|
||||
case ZEND_FRAMELESS_ICALL_2:
|
||||
if (opline->op2_type == IS_CV && opline->op2.var == cv_var) return 0;
|
||||
if (opline->op2_type == IS_CV && opline->op2.var == cv_var) return false;
|
||||
ZEND_FALLTHROUGH;
|
||||
case ZEND_FRAMELESS_ICALL_1:
|
||||
if (opline->op1_type == IS_CV && opline->op1.var == cv_var) return 0;
|
||||
return 1;
|
||||
if (opline->op1_type == IS_CV && opline->op1.var == cv_var) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (opline->opcode == ZEND_DO_ICALL || opline->opcode == ZEND_DO_UCALL
|
||||
@@ -374,10 +374,10 @@ static bool opline_supports_assign_contraction(
|
||||
&& opline->op1_type == IS_CV
|
||||
&& opline->op1.var == cv_var
|
||||
&& zend_may_throw(opline, &ssa->ops[ssa->vars[src_var].definition], op_array, ssa)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool variable_defined_or_used_in_range(zend_ssa *ssa, int var, int start, int end)
|
||||
@@ -391,11 +391,11 @@ static bool variable_defined_or_used_in_range(zend_ssa *ssa, int var, int start,
|
||||
(ssa_op->op2_use >= 0 && ssa->vars[ssa_op->op2_use].var == var) ||
|
||||
(ssa_op->result_use >= 0 && ssa->vars[ssa_op->result_use].var == var)
|
||||
) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
start++;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa)
|
||||
@@ -989,7 +989,7 @@ static bool zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ss
|
||||
if ((opline->op1_type == IS_CV && opline->op1.var == cv)
|
||||
|| (opline->op2_type == IS_CV && opline->op2.var == cv)
|
||||
|| (opline->result_type == IS_CV && opline->result.var == cv)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
opline--;
|
||||
i--;
|
||||
@@ -1026,12 +1026,12 @@ static bool zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ss
|
||||
op_array->opcodes[use].result.var = cv;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx, zend_ssa *ssa, zend_call_info **call_map)
|
||||
|
||||
@@ -155,7 +155,7 @@ static bool is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, i
|
||||
if (ssa_op->result_def == var) {
|
||||
switch (opline->opcode) {
|
||||
case ZEND_INIT_ARRAY:
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_NEW: {
|
||||
/* objects with destructors should escape */
|
||||
zend_class_entry *ce = zend_optimizer_get_class_entry_from_op1(
|
||||
@@ -175,22 +175,22 @@ static bool is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, i
|
||||
&& !ce->__set
|
||||
&& !(ce->ce_flags & forbidden_flags)
|
||||
&& (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ZEND_QM_ASSIGN:
|
||||
if (opline->op1_type == IS_CONST
|
||||
&& Z_TYPE_P(CRT_CONSTANT(opline->op1)) == IS_ARRAY) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (opline->op1_type == IS_CV && (OP1_INFO() & MAY_BE_ARRAY)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case ZEND_ASSIGN:
|
||||
if (opline->op1_type == IS_CV && (OP1_INFO() & MAY_BE_ARRAY)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -199,22 +199,22 @@ static bool is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, i
|
||||
case ZEND_ASSIGN:
|
||||
if (opline->op2_type == IS_CONST
|
||||
&& Z_TYPE_P(CRT_CONSTANT(opline->op2)) == IS_ARRAY) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (opline->op2_type == IS_CV && (OP2_INFO() & MAY_BE_ARRAY)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case ZEND_ASSIGN_DIM:
|
||||
if (OP1_INFO() & (MAY_BE_UNDEF | MAY_BE_NULL | MAY_BE_FALSE)) {
|
||||
/* implicit object/array allocation */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -229,7 +229,7 @@ static bool is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int va
|
||||
case ZEND_ADD_ARRAY_ELEMENT:
|
||||
case ZEND_QM_ASSIGN:
|
||||
case ZEND_ASSIGN:
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_NEW: {
|
||||
/* objects with destructors should escape */
|
||||
zend_class_entry *ce = zend_optimizer_get_class_entry_from_op1(
|
||||
@@ -243,7 +243,7 @@ static bool is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int va
|
||||
&& !ce->__get
|
||||
&& !ce->__set
|
||||
&& !ce->parent) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -260,11 +260,11 @@ static bool is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int va
|
||||
case ZEND_PRE_DEC_OBJ:
|
||||
case ZEND_POST_INC_OBJ:
|
||||
case ZEND_POST_DEC_OBJ:
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -282,7 +282,7 @@ static bool is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int v
|
||||
if (opline->op1_type == IS_CV) {
|
||||
if (OP1_INFO() & MAY_BE_OBJECT) {
|
||||
/* object aliasing */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -294,7 +294,7 @@ static bool is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int v
|
||||
case ZEND_FETCH_OBJ_IS:
|
||||
break;
|
||||
case ZEND_ASSIGN_OP:
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_ASSIGN_DIM_OP:
|
||||
case ZEND_ASSIGN_OBJ_OP:
|
||||
case ZEND_ASSIGN_STATIC_PROP_OP:
|
||||
@@ -310,22 +310,22 @@ static bool is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int v
|
||||
case ZEND_INIT_ARRAY:
|
||||
case ZEND_ADD_ARRAY_ELEMENT:
|
||||
if (opline->extended_value & ZEND_ARRAY_ELEMENT_REF) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (OP1_INFO() & MAY_BE_OBJECT) {
|
||||
/* object aliasing */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
/* reference dependencies processed separately */
|
||||
break;
|
||||
case ZEND_OP_DATA:
|
||||
if ((opline-1)->opcode != ZEND_ASSIGN_DIM
|
||||
&& (opline-1)->opcode != ZEND_ASSIGN_OBJ) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (OP1_INFO() & MAY_BE_OBJECT) {
|
||||
/* object aliasing */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
opline--;
|
||||
ssa_op--;
|
||||
@@ -333,12 +333,12 @@ static bool is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int v
|
||||
|| (OP1_INFO() & MAY_BE_REF)
|
||||
|| (ssa_op->op1_def >= 0 && ssa->vars[ssa_op->op1_def].alias)) {
|
||||
/* assignment into escaping structure */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
/* reference dependencies processed separately */
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,17 +349,17 @@ static bool is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int v
|
||||
|| (OP1_INFO() & MAY_BE_REF)
|
||||
|| (ssa_op->op1_def >= 0 && ssa->vars[ssa_op->op1_def].alias)) {
|
||||
/* assignment into escaping variable */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (opline->op2_type == IS_CV || opline->result_type != IS_UNUSED) {
|
||||
if (OP2_INFO() & MAY_BE_OBJECT) {
|
||||
/* object aliasing */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,11 +371,11 @@ static bool is_escape_use(zend_op_array *op_array, zend_ssa *ssa, int use, int v
|
||||
case ZEND_ADD_ARRAY_ELEMENT:
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
@@ -37,10 +37,10 @@ static zend_always_inline bool in_hitlist(zend_op *target, zend_op **jmp_hitlist
|
||||
|
||||
for (i = 0; i < jmp_hitlist_count; i++) {
|
||||
if (jmp_hitlist[i] == target) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
#define CHECK_LOOP(target) \
|
||||
|
||||
@@ -244,7 +244,7 @@ static bool can_replace_op1(
|
||||
case ZEND_SEND_ARRAY:
|
||||
case ZEND_SEND_USER:
|
||||
case ZEND_FE_RESET_RW:
|
||||
return 0;
|
||||
return false;
|
||||
/* Do not accept CONST */
|
||||
case ZEND_ROPE_ADD:
|
||||
case ZEND_ROPE_END:
|
||||
@@ -254,7 +254,7 @@ static bool can_replace_op1(
|
||||
case ZEND_MAKE_REF:
|
||||
case ZEND_UNSET_CV:
|
||||
case ZEND_ISSET_ISEMPTY_CV:
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_INIT_ARRAY:
|
||||
case ZEND_ADD_ARRAY_ELEMENT:
|
||||
return !(opline->extended_value & ZEND_ARRAY_ELEMENT_REF);
|
||||
@@ -262,18 +262,18 @@ static bool can_replace_op1(
|
||||
return !(op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE);
|
||||
case ZEND_VERIFY_RETURN_TYPE:
|
||||
// TODO: This would require a non-local change ???
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_OP_DATA:
|
||||
return (opline - 1)->opcode != ZEND_ASSIGN_OBJ_REF &&
|
||||
(opline - 1)->opcode != ZEND_ASSIGN_STATIC_PROP_REF;
|
||||
default:
|
||||
if (ssa_op->op1_def != -1) {
|
||||
ZEND_UNREACHABLE();
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool can_replace_op2(
|
||||
@@ -284,9 +284,9 @@ static bool can_replace_op2(
|
||||
case ZEND_BIND_LEXICAL:
|
||||
case ZEND_FE_FETCH_R:
|
||||
case ZEND_FE_FETCH_RW:
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool try_replace_op1(
|
||||
@@ -295,11 +295,11 @@ static bool try_replace_op1(
|
||||
zval zv;
|
||||
ZVAL_COPY(&zv, value);
|
||||
if (zend_optimizer_update_op1_const(ctx->scdf.op_array, opline, &zv)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
zval_ptr_dtor_nogc(&zv);
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool try_replace_op2(
|
||||
@@ -308,11 +308,11 @@ static bool try_replace_op2(
|
||||
zval zv;
|
||||
ZVAL_COPY(&zv, value);
|
||||
if (zend_optimizer_update_op2_const(ctx->scdf.op_array, opline, &zv)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
zval_ptr_dtor_nogc(&zv);
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline zend_result ct_eval_binary_op(zval *result, uint8_t binop, zval *op1, zval *op2) {
|
||||
|
||||
@@ -25,20 +25,20 @@ static inline bool is_in_use_chain(zend_ssa *ssa, int var, int check) {
|
||||
int use;
|
||||
FOREACH_USE(&ssa->vars[var], use) {
|
||||
if (use == check) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
} FOREACH_USE_END();
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool is_in_phi_use_chain(zend_ssa *ssa, int var, zend_ssa_phi *check) {
|
||||
zend_ssa_phi *phi;
|
||||
FOREACH_PHI_USE(&ssa->vars[var], phi) {
|
||||
if (phi == check) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
} FOREACH_PHI_USE_END();
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool is_used_by_op(zend_ssa *ssa, int op, int check) {
|
||||
@@ -59,30 +59,30 @@ static inline bool is_in_phi_sources(zend_ssa *ssa, zend_ssa_phi *phi, int check
|
||||
int source;
|
||||
FOREACH_PHI_SOURCE(phi, source) {
|
||||
if (source == check) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
} FOREACH_PHI_SOURCE_END();
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool is_in_predecessors(zend_cfg *cfg, zend_basic_block *block, int check) {
|
||||
int i, *predecessors = &cfg->predecessors[block->predecessor_offset];
|
||||
for (i = 0; i < block->predecessors_count; i++) {
|
||||
if (predecessors[i] == check) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool is_in_successors(zend_basic_block *block, int check) {
|
||||
int s;
|
||||
for (s = 0; s < block->successors_count; s++) {
|
||||
if (block->successors[s] == check) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool is_var_type(uint8_t type) {
|
||||
|
||||
@@ -176,12 +176,12 @@ static bool zend_is_indirectly_recursive(zend_op_array *root, zend_op_array *op_
|
||||
bool ret = false;
|
||||
|
||||
if (op_array == root) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
func_info = ZEND_FUNC_INFO(op_array);
|
||||
if (zend_bitset_in(visited, func_info->num)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
zend_bitset_incl(visited, func_info->num);
|
||||
call_info = func_info->caller_info;
|
||||
|
||||
@@ -186,9 +186,9 @@ bool zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zva
|
||||
|
||||
if ((val = zend_hash_find(constants, Z_STR_P(name))) != NULL) {
|
||||
ZVAL_COPY(value, val);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
void zend_optimizer_convert_to_free_op1(zend_op_array *op_array, zend_op *opline)
|
||||
@@ -263,7 +263,7 @@ bool zend_optimizer_update_op1_const(zend_op_array *op_array,
|
||||
switch ((opline-1)->opcode) {
|
||||
case ZEND_ASSIGN_OBJ_REF:
|
||||
case ZEND_ASSIGN_STATIC_PROP_REF:
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
opline->op1.constant = zend_optimizer_add_literal(op_array, val);
|
||||
break;
|
||||
@@ -271,7 +271,7 @@ bool zend_optimizer_update_op1_const(zend_op_array *op_array,
|
||||
case ZEND_CHECK_VAR:
|
||||
MAKE_NOP(opline);
|
||||
zval_ptr_dtor_nogc(val);
|
||||
return 1;
|
||||
return true;
|
||||
case ZEND_SEND_VAR_EX:
|
||||
case ZEND_SEND_FUNC_ARG:
|
||||
case ZEND_FETCH_DIM_W:
|
||||
@@ -286,7 +286,7 @@ bool zend_optimizer_update_op1_const(zend_op_array *op_array,
|
||||
case ZEND_SEPARATE:
|
||||
case ZEND_SEND_VAR_NO_REF:
|
||||
case ZEND_SEND_VAR_NO_REF_EX:
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_CATCH:
|
||||
REQUIRES_STRING(val);
|
||||
drop_leading_backslash(val);
|
||||
@@ -368,10 +368,10 @@ bool zend_optimizer_update_op1_const(zend_op_array *op_array,
|
||||
case ZEND_VERIFY_RETURN_TYPE:
|
||||
/* This would require a non-local change.
|
||||
* zend_optimizer_replace_by_const() supports this. */
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_COPY_TMP:
|
||||
case ZEND_FETCH_CLASS_NAME:
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_ECHO:
|
||||
{
|
||||
zval zv;
|
||||
@@ -382,7 +382,7 @@ bool zend_optimizer_update_op1_const(zend_op_array *op_array,
|
||||
opline->op1.constant = zend_optimizer_add_literal(op_array, val);
|
||||
if (Z_TYPE_P(val) == IS_STRING && Z_STRLEN_P(val) == 0) {
|
||||
MAKE_NOP(opline);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
/* TODO: In a subsequent pass, *after* this step and compacting nops, combine consecutive ZEND_ECHOs using the block information from ssa->cfg */
|
||||
/* (e.g. for ext/opcache/tests/opt/sccp_010.phpt) */
|
||||
@@ -412,7 +412,7 @@ bool zend_optimizer_update_op1_const(zend_op_array *op_array,
|
||||
if (Z_TYPE(ZEND_OP1_LITERAL(opline)) == IS_STRING) {
|
||||
zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline)));
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool zend_optimizer_update_op2_const(zend_op_array *op_array,
|
||||
@@ -424,7 +424,7 @@ bool zend_optimizer_update_op2_const(zend_op_array *op_array,
|
||||
switch (opline->opcode) {
|
||||
case ZEND_ASSIGN_REF:
|
||||
case ZEND_FAST_CALL:
|
||||
return 0;
|
||||
return false;
|
||||
case ZEND_FETCH_CLASS:
|
||||
case ZEND_INSTANCEOF:
|
||||
REQUIRES_STRING(val);
|
||||
@@ -478,13 +478,13 @@ bool zend_optimizer_update_op2_const(zend_op_array *op_array,
|
||||
case ZEND_INIT_DYNAMIC_CALL:
|
||||
if (Z_TYPE_P(val) == IS_STRING) {
|
||||
if (zend_memrchr(Z_STRVAL_P(val), ':', Z_STRLEN_P(val))) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zend_optimizer_classify_function(Z_STR_P(val), opline->extended_value)) {
|
||||
/* Dynamic call to various special functions must stay dynamic,
|
||||
* otherwise would drop a warning */
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
opline->opcode = ZEND_INIT_FCALL_BY_NAME;
|
||||
@@ -594,7 +594,7 @@ bool zend_optimizer_update_op2_const(zend_op_array *op_array,
|
||||
if (Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING) {
|
||||
zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline)));
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool zend_optimizer_replace_by_const(zend_op_array *op_array,
|
||||
@@ -641,7 +641,7 @@ bool zend_optimizer_replace_by_const(zend_op_array *op_array,
|
||||
Z_TRY_ADDREF_P(val);
|
||||
if (!zend_optimizer_update_op1_const(op_array, opline, val)) {
|
||||
zval_ptr_dtor(val);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (is_last) {
|
||||
break;
|
||||
@@ -650,13 +650,13 @@ bool zend_optimizer_replace_by_const(zend_op_array *op_array,
|
||||
opline++;
|
||||
}
|
||||
zval_ptr_dtor_nogc(val);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
case ZEND_VERIFY_RETURN_TYPE: {
|
||||
zend_arg_info *ret_info = op_array->arg_info - 1;
|
||||
if (!ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(val))
|
||||
|| (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
MAKE_NOP(opline);
|
||||
|
||||
@@ -681,7 +681,7 @@ bool zend_optimizer_replace_by_const(zend_op_array *op_array,
|
||||
opline++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Update jump offsets after a jump was migrated to another opline */
|
||||
@@ -1506,7 +1506,7 @@ static bool needs_live_range(zend_op_array *op_array, zend_op *def_opline) {
|
||||
int ssa_var = ssa_op->result_def;
|
||||
if (ssa_var < 0) {
|
||||
/* Be conservative. */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* If the variable is used by a PHI, this may be the assignment of the final branch of a
|
||||
|
||||
@@ -52,10 +52,10 @@ static bool will_rejoin(
|
||||
/* The other successor dominates this predecessor,
|
||||
* so we will get the original value from it. */
|
||||
if (dominates(cfg->blocks, other_successor, predecessor)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool needs_pi(const zend_op_array *op_array, const zend_dfg *dfg, const zend_ssa *ssa, int from, int to, int var) /* {{{ */
|
||||
@@ -65,7 +65,7 @@ static bool needs_pi(const zend_op_array *op_array, const zend_dfg *dfg, const z
|
||||
|
||||
if (!DFG_ISSET(dfg->in, dfg->size, to, var)) {
|
||||
/* Variable is not live, certainly won't benefit from pi */
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Make sure that both successors of the from block aren't the same. Pi nodes are associated
|
||||
@@ -73,13 +73,13 @@ static bool needs_pi(const zend_op_array *op_array, const zend_dfg *dfg, const z
|
||||
from_block = &ssa->cfg.blocks[from];
|
||||
ZEND_ASSERT(from_block->successors_count == 2);
|
||||
if (from_block->successors[0] == from_block->successors[1]) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
to_block = &ssa->cfg.blocks[to];
|
||||
if (to_block->predecessors_count == 1) {
|
||||
/* Always place pi if one predecessor (an if branch) */
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Check whether we will rejoin with the original value coming from the other successor,
|
||||
|
||||
@@ -97,12 +97,12 @@ static inline bool zend_worklist_push(zend_worklist *worklist, int i)
|
||||
ZEND_ASSERT(i >= 0 && i < worklist->stack.capacity);
|
||||
|
||||
if (zend_bitset_in(worklist->visited, i)) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
zend_bitset_incl(worklist->visited, i);
|
||||
zend_worklist_stack_push(&worklist->stack, i);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline int zend_worklist_peek(const zend_worklist *worklist)
|
||||
|
||||
Reference in New Issue
Block a user