Skip to content

Commit 818e94e

Browse files
committed
Add helper macro for pushing refs
1 parent 44f7ffc commit 818e94e

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

Python/flowgraph.c

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,7 +2584,6 @@ insert_superinstructions(cfg_builder *g)
25842584

25852585
#define NOT_LOCAL -1
25862586
#define DUMMY_INSTR -1
2587-
#define DUMMY_REF (ref){DUMMY_INSTR, NOT_LOCAL}
25882587

25892588
typedef struct {
25902589
// Index of instruction that produced the reference or DUMMY_INSTR.
@@ -2766,6 +2765,14 @@ optimize_load_fast(cfg_builder *g)
27662765
entryblock->b_startdepth = 0;
27672766
entryblock->b_visited = 1;
27682767

2768+
#define PUSH_REF(instr, local) \
2769+
do { \
2770+
if (ref_stack_push(&refs, (ref){(instr), (local)}) < 0) { \
2771+
status = ERROR; \
2772+
goto done; \
2773+
} \
2774+
} while(0)
2775+
27692776
while (sp != blocks) {
27702777
basicblock *block = *--sp;
27712778
assert(block->b_startdepth > -1);
@@ -2778,10 +2785,7 @@ optimize_load_fast(cfg_builder *g)
27782785
// presence. Add dummy references as necessary.
27792786
ref_stack_clear(&refs);
27802787
for (int i = 0; i < block->b_startdepth; i++) {
2781-
if (ref_stack_push(&refs, DUMMY_REF) < 0) {
2782-
status = ERROR;
2783-
goto done;
2784-
}
2788+
PUSH_REF(DUMMY_INSTR, NOT_LOCAL);
27852789
}
27862790

27872791
for (int i = 0; i < block->b_iused; i++) {
@@ -2802,31 +2806,19 @@ optimize_load_fast(cfg_builder *g)
28022806
}
28032807

28042808
case LOAD_FAST: {
2805-
if (ref_stack_push(&refs, (ref){i, oparg}) < 0) {
2806-
status = ERROR;
2807-
goto done;
2808-
}
2809+
PUSH_REF(i, oparg);
28092810
break;
28102811
}
28112812

28122813
case LOAD_FAST_AND_CLEAR: {
28132814
kill_local(instr_flags, &refs, oparg);
2814-
if (ref_stack_push(&refs, (ref){i, oparg}) < 0) {
2815-
status = ERROR;
2816-
goto done;
2817-
}
2815+
PUSH_REF(i, oparg);
28182816
break;
28192817
}
28202818

28212819
case LOAD_FAST_LOAD_FAST: {
2822-
if (ref_stack_push(&refs, (ref){i, oparg >> 4}) < 0) {
2823-
status = ERROR;
2824-
goto done;
2825-
}
2826-
if (ref_stack_push(&refs, (ref){i, oparg & 15}) < 0) {
2827-
status = ERROR;
2828-
goto done;
2829-
}
2820+
PUSH_REF(i, oparg >> 4);
2821+
PUSH_REF(i, oparg & 15);
28302822
break;
28312823
}
28322824

@@ -2841,10 +2833,7 @@ optimize_load_fast(cfg_builder *g)
28412833
ref r = ref_stack_pop(&refs);
28422834
store_local(instr_flags, &refs, oparg >> 4, r);
28432835
// LOAD_FAST
2844-
if (ref_stack_push(&refs, (ref){i, oparg & 15}) < 0) {
2845-
status = ERROR;
2846-
goto done;
2847-
}
2836+
PUSH_REF(i, oparg & 15);
28482837
break;
28492838
}
28502839

@@ -2877,10 +2866,7 @@ optimize_load_fast(cfg_builder *g)
28772866
ref_stack_pop(&refs);
28782867
}
28792868
for (int j = 0; j < num_pushed; j++) {
2880-
if (ref_stack_push(&refs, (ref){i, NOT_LOCAL}) < 0) {
2881-
status = ERROR;
2882-
goto done;
2883-
}
2869+
PUSH_REF(i, NOT_LOCAL);
28842870
}
28852871
}
28862872
break;
@@ -2924,6 +2910,8 @@ optimize_load_fast(cfg_builder *g)
29242910
}
29252911
}
29262912

2913+
#undef PUSH_REF
2914+
29272915
status = SUCCESS;
29282916

29292917
done:

0 commit comments

Comments
 (0)