Introduce ZEND_BITSET_FOREACH macros

This commit is contained in:
Nikita Popov 2016-04-24 17:04:22 +02:00
parent 62240f2653
commit cafe78d12a
2 changed files with 70 additions and 51 deletions

View file

@ -174,6 +174,33 @@ static inline int zend_bitset_last(zend_bitset set, uint32_t len)
return -1; /* empty set */ return -1; /* empty set */
} }
#define ZEND_BITSET_FOREACH(set, len, bit) do { \
zend_bitset _set = (set); \
uint32_t _i, _len = (len); \
for (_i = 0; _i < len; _i++) { \
zend_ulong _x = _set[_i]; \
if (_x) { \
(bit) = ZEND_BITSET_ELM_SIZE * 8 * _i; \
for (; _x != 0; _x >>= Z_UL(1), (bit)++) { \
if (!(_x & Z_UL(1))) continue;
#define ZEND_BITSET_REVERSE_FOREACH(set, len, bit) do { \
zend_bitset _set = (set); \
uint32_t _i = (len); \
zend_ulong _test = Z_UL(1) << (ZEND_BITSET_ELM_SIZE * 8 - 1); \
while (_i-- > 0) { \
zend_ulong _x = _set[_i]; \
if (_x) { \
(bit) = ZEND_BITSET_ELM_SIZE * 8 * (_i + 1) - 1; \
for (; _x != 0; _x <<= Z_UL(1), (bit)--) { \
if (!(_x & _test)) continue; \
#define ZEND_BITSET_FOREACH_END() \
} \
} \
} \
} while (0)
#endif /* _ZEND_BITSET_H_ */ #endif /* _ZEND_BITSET_H_ */
/* /*

View file

@ -856,10 +856,7 @@ int zend_build_ssa(zend_arena **arena, const zend_op_array *op_array, uint32_t b
} }
if (!zend_bitset_empty(tmp, set_size)) { if (!zend_bitset_empty(tmp, set_size)) {
i = op_array->last_var + op_array->T; ZEND_BITSET_REVERSE_FOREACH(tmp, set_size, i) {
while (i > 0) {
i--;
if (zend_bitset_in(tmp, i)) {
zend_ssa_phi *phi = zend_arena_calloc(arena, 1, zend_ssa_phi *phi = zend_arena_calloc(arena, 1,
sizeof(zend_ssa_phi) + sizeof(zend_ssa_phi) +
sizeof(int) * blocks[j].predecessors_count + sizeof(int) * blocks[j].predecessors_count +
@ -877,8 +874,7 @@ int zend_build_ssa(zend_arena **arena, const zend_op_array *op_array, uint32_t b
phi->ssa_var = -1; phi->ssa_var = -1;
phi->next = ssa_blocks[j].phis; phi->next = ssa_blocks[j].phis;
ssa_blocks[j].phis = phi; ssa_blocks[j].phis = phi;
} } ZEND_BITSET_FOREACH_END();
}
} }
} }
} }
@ -921,10 +917,7 @@ int zend_build_ssa(zend_arena **arena, const zend_op_array *op_array, uint32_t b
} }
if (!zend_bitset_empty(tmp, set_size)) { if (!zend_bitset_empty(tmp, set_size)) {
i = op_array->last_var + op_array->T; ZEND_BITSET_REVERSE_FOREACH(tmp, set_size, i) {
while (i > 0) {
i--;
if (zend_bitset_in(tmp, i)) {
zend_ssa_phi **pp = &ssa_blocks[j].phis; zend_ssa_phi **pp = &ssa_blocks[j].phis;
while (*pp) { while (*pp) {
if ((*pp)->pi <= 0 && (*pp)->var == i) { if ((*pp)->pi <= 0 && (*pp)->var == i) {
@ -951,8 +944,7 @@ int zend_build_ssa(zend_arena **arena, const zend_op_array *op_array, uint32_t b
phi->next = NULL; phi->next = NULL;
*pp = phi; *pp = phi;
} }
} } ZEND_BITSET_FOREACH_END();
}
} }
} }
} }