Skip to content

Commit 82ab848

Browse files
committed
Remove separate valid_T set
Rather than keeping track of a separate valid_T set (which must always be in sync with map_T), use a dummy value in map_T to denote unallocated temporaries.
1 parent ae1132b commit 82ab848

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

Zend/Optimizer/optimize_temp_vars_5.c

+5-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "zend_vm.h"
2828
#include "zend_bitset.h"
2929

30+
#define INVALID_VAR ((uint32_t)-1)
3031
#define GET_AVAILABLE_T() \
3132
for (i = 0; i < T; i++) { \
3233
if (!zend_bitset_in(taken_T, i)) { \
@@ -45,7 +46,6 @@ void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_c
4546
uint32_t bitset_len;
4647
zend_bitset taken_T; /* T index in use */
4748
zend_op **start_of_T; /* opline where T is first used */
48-
zend_bitset valid_T; /* Is the map_T valid */
4949
int *map_T; /* Map's the T to its new index */
5050
zend_op *opline, *end;
5151
int currT;
@@ -56,8 +56,8 @@ void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_c
5656
bitset_len = zend_bitset_len(T);
5757
taken_T = (zend_bitset) zend_arena_alloc(&ctx->arena, bitset_len * ZEND_BITSET_ELM_SIZE);
5858
start_of_T = (zend_op **) zend_arena_alloc(&ctx->arena, T * sizeof(zend_op *));
59-
valid_T = (zend_bitset) zend_arena_alloc(&ctx->arena, bitset_len * ZEND_BITSET_ELM_SIZE);
6059
map_T = (int *) zend_arena_alloc(&ctx->arena, T * sizeof(int));
60+
memset(map_T, 0xff, T * sizeof(int));
6161

6262
end = op_array->opcodes;
6363
opline = &op_array->opcodes[op_array->last - 1];
@@ -70,7 +70,6 @@ void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_c
7070
opline--;
7171
}
7272

73-
zend_bitset_clear(valid_T, bitset_len);
7473
zend_bitset_clear(taken_T, bitset_len);
7574

7675
end = op_array->opcodes;
@@ -90,15 +89,14 @@ void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_c
9089
max = MAX(max, var + num);
9190
var = var + 1;
9291
map_T[currT] = var;
93-
zend_bitset_incl(valid_T, currT);
9492
zend_bitset_incl(taken_T, var);
9593
opline->op1.var = NUM_VAR(var + offset);
9694
while (num > 1) {
9795
num--;
9896
zend_bitset_incl(taken_T, var + num);
9997
}
10098
} else {
101-
if (!zend_bitset_in(valid_T, currT)) {
99+
if (map_T[currT] == INVALID_VAR) {
102100
int use_new_var = 0;
103101

104102
/* Code in "finally" blocks may modify temporary variables.
@@ -132,29 +130,26 @@ void zend_optimize_temporary_variables(zend_op_array *op_array, zend_optimizer_c
132130
GET_AVAILABLE_T();
133131
}
134132
map_T[currT] = i;
135-
zend_bitset_incl(valid_T, currT);
136133
}
137134
opline->op1.var = NUM_VAR(map_T[currT] + offset);
138135
}
139136
}
140137

141138
if ((opline->op2_type & (IS_VAR | IS_TMP_VAR))) {
142139
currT = VAR_NUM(opline->op2.var) - offset;
143-
if (!zend_bitset_in(valid_T, currT)) {
140+
if (map_T[currT] == INVALID_VAR) {
144141
GET_AVAILABLE_T();
145142
map_T[currT] = i;
146-
zend_bitset_incl(valid_T, currT);
147143
}
148144
opline->op2.var = NUM_VAR(map_T[currT] + offset);
149145
}
150146

151147
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
152148
currT = VAR_NUM(opline->result.var) - offset;
153-
if (!zend_bitset_in(valid_T, currT)) {
149+
if (map_T[currT] == INVALID_VAR) {
154150
/* As a result of DCE, an opcode may have an unused result. */
155151
GET_AVAILABLE_T();
156152
map_T[currT] = i;
157-
zend_bitset_incl(valid_T, currT);
158153
}
159154
opline->result.var = NUM_VAR(map_T[currT] + offset);
160155
if (start_of_T[currT] == opline) {

0 commit comments

Comments
 (0)