88#include "ir.h"
99#include "ir_private.h"
1010
11- #define MAKE_NOP (_insn ) do { \
12- ir_insn *__insn = _insn; \
13- __insn->optx = IR_NOP; \
14- __insn->op1 = __insn->op2 = __insn->op3 = IR_UNUSED; \
15- } while (0)
16-
17- #define CLEAR_USES (_ref ) do { \
18- ir_use_list *__use_list = &ctx->use_lists[_ref]; \
19- __use_list->count = 0; \
20- __use_list->refs = 0; \
21- } while (0)
22-
23- #define SWAP_REFS (_ref1 , _ref2 ) do { \
24- ir_ref _tmp = _ref1; \
25- _ref1 = _ref2; \
26- _ref2 = _tmp; \
27- } while (0)
28-
29- #define SWAP_INSNS (_insn1 , _insn2 ) do { \
30- ir_insn *_tmp = _insn1; \
31- _insn1 = _insn2; \
32- _insn2 = _tmp; \
33- } while (0)
34-
3511static void ir_get_true_false_refs (const ir_ctx * ctx , ir_ref if_ref , ir_ref * if_true_ref , ir_ref * if_false_ref )
3612{
3713 ir_use_list * use_list = & ctx -> use_lists [if_ref ];
@@ -54,7 +30,6 @@ static ir_ref _ir_merge_blocks(ir_ctx *ctx, ir_ref end, ir_ref begin)
5430{
5531 ir_ref prev , next ;
5632 ir_use_list * use_list ;
57- ir_ref n , * p ;
5833
5934 IR_ASSERT (ctx -> ir_base [begin ].op == IR_BEGIN );
6035 IR_ASSERT (ctx -> ir_base [end ].op == IR_END );
@@ -68,23 +43,12 @@ static ir_ref _ir_merge_blocks(ir_ctx *ctx, ir_ref end, ir_ref begin)
6843 next = ctx -> use_edges [use_list -> refs ];
6944
7045 /* remove BEGIN and END */
71- ctx -> ir_base [begin ].op = IR_NOP ;
72- ctx -> ir_base [begin ].op1 = IR_UNUSED ;
73- ctx -> use_lists [begin ].count = 0 ;
74- ctx -> ir_base [end ].op = IR_NOP ;
75- ctx -> ir_base [end ].op1 = IR_UNUSED ;
76- ctx -> use_lists [end ].count = 0 ;
46+ MAKE_NOP (& ctx -> ir_base [begin ]); CLEAR_USES (begin );
47+ MAKE_NOP (& ctx -> ir_base [end ]); CLEAR_USES (end );
7748
7849 /* connect their predecessor and successor */
7950 ctx -> ir_base [next ].op1 = prev ;
80- use_list = & ctx -> use_lists [prev ];
81- n = use_list -> count ;
82- for (p = & ctx -> use_edges [use_list -> refs ]; n > 0 ; p ++ , n -- ) {
83- if (* p == end ) {
84- * p = next ;
85- }
86- }
87-
51+ ir_use_list_replace_all (ctx , prev , end , next );
8852 return next ;
8953}
9054
@@ -141,7 +105,7 @@ static ir_ref ir_try_remove_empty_diamond(ir_ctx *ctx, ir_ref ref, ir_insn *insn
141105 IR_ASSERT (ctx -> use_lists [start2_ref ].count == 1 );
142106
143107 next -> op1 = root -> op1 ;
144- ir_use_list_replace (ctx , root -> op1 , root_ref , next_ref );
108+ ir_use_list_replace_one (ctx , root -> op1 , root_ref , next_ref );
145109 if (!IR_IS_CONST_REF (root -> op2 )) {
146110 ir_use_list_remove_all (ctx , root -> op2 , root_ref );
147111 }
@@ -189,7 +153,7 @@ static ir_ref ir_try_remove_empty_diamond(ir_ctx *ctx, ir_ref ref, ir_insn *insn
189153 ir_insn * root = & ctx -> ir_base [root_ref ];
190154
191155 next -> op1 = root -> op1 ;
192- ir_use_list_replace (ctx , root -> op1 , root_ref , next_ref );
156+ ir_use_list_replace_one (ctx , root -> op1 , root_ref , next_ref );
193157 ir_use_list_remove_all (ctx , root -> op2 , root_ref );
194158
195159 MAKE_NOP (root ); CLEAR_USES (root_ref );
@@ -303,8 +267,7 @@ static ir_ref ir_optimize_phi(ir_ctx *ctx, ir_ref merge_ref, ir_insn *merge, ir_
303267 insn -> op3 = IR_UNUSED ;
304268
305269 next -> op1 = root -> op1 ;
306- ir_use_list_replace (ctx , root -> op1 , root_ref , next_ref );
307- ir_use_list_remove_all (ctx , root -> op2 , root_ref );
270+ ir_use_list_replace_one (ctx , root -> op1 , root_ref , next_ref );
308271 if (!IR_IS_CONST_REF (insn -> op1 )) {
309272 ir_use_list_remove_all (ctx , insn -> op1 , cond_ref );
310273 }
@@ -384,8 +347,8 @@ static ir_ref ir_optimize_phi(ir_ctx *ctx, ir_ref merge_ref, ir_insn *merge, ir_
384347 insn -> op3 = IR_UNUSED ;
385348
386349 next -> op1 = root -> op1 ;
387- ir_use_list_replace (ctx , root -> op1 , root_ref , next_ref );
388- ir_use_list_remove_all (ctx , root -> op2 , root_ref );
350+ ir_use_list_replace_one (ctx , root -> op1 , root_ref , next_ref );
351+ ir_use_list_remove_one (ctx , insn -> op1 , neg_ref );
389352 if (!IR_IS_CONST_REF (insn -> op1 )) {
390353 ir_use_list_remove_all (ctx , insn -> op1 , cond_ref );
391354 }
@@ -440,8 +403,8 @@ static ir_ref ir_optimize_phi(ir_ctx *ctx, ir_ref merge_ref, ir_insn *merge, ir_
440403 }
441404
442405 next -> op1 = root -> op1 ;
443- ir_use_list_replace (ctx , cond_ref , root_ref , ref );
444- ir_use_list_replace (ctx , root -> op1 , root_ref , next_ref );
406+ ir_use_list_replace_one (ctx , cond_ref , root_ref , ref );
407+ ir_use_list_replace_one (ctx , root -> op1 , root_ref , next_ref );
445408 ir_use_list_remove_all (ctx , root -> op2 , root_ref );
446409
447410 MAKE_NOP (root ); CLEAR_USES (root_ref );
@@ -619,9 +582,9 @@ static ir_ref ir_try_split_if(ir_ctx *ctx, ir_ref ref, ir_insn *insn)
619582 ir_use_list_remove_all (ctx , merge_ref , cond_ref );
620583 ir_use_list_remove_all (ctx , ref , if_true_ref );
621584 if (!IR_IS_CONST_REF (cond -> op3 )) {
622- ir_use_list_replace (ctx , cond -> op3 , cond_ref , end2_ref );
585+ ir_use_list_replace_one (ctx , cond -> op3 , cond_ref , end2_ref );
623586 }
624- ir_use_list_replace (ctx , end1_ref , merge_ref , if_false_ref );
587+ ir_use_list_replace_one (ctx , end1_ref , merge_ref , if_false_ref );
625588 ir_use_list_add (ctx , end2_ref , if_true_ref );
626589
627590 end2 -> optx = IR_OPTX (IR_IF , IR_VOID , 2 );
@@ -722,8 +685,8 @@ static ir_ref ir_try_split_if_cmp(ir_ctx *ctx, ir_worklist *worklist, ir_ref ref
722685 * | |
723686 */
724687
725- ir_use_list_replace (ctx , end1_ref , merge_ref , if_false_ref );
726- ir_use_list_replace (ctx , end2_ref , merge_ref , if_true_ref );
688+ ir_use_list_replace_one (ctx , end1_ref , merge_ref , if_false_ref );
689+ ir_use_list_replace_one (ctx , end2_ref , merge_ref , if_true_ref );
727690
728691 MAKE_NOP (merge ); CLEAR_USES (merge_ref );
729692 MAKE_NOP (phi ); CLEAR_USES (phi_ref );
@@ -762,8 +725,8 @@ static ir_ref ir_try_split_if_cmp(ir_ctx *ctx, ir_worklist *worklist, ir_ref ref
762725 * | |
763726 */
764727
765- ir_use_list_replace (ctx , end1_ref , merge_ref , if_false_ref );
766- ir_use_list_replace (ctx , end2_ref , merge_ref , if_false_ref );
728+ ir_use_list_replace_one (ctx , end1_ref , merge_ref , if_false_ref );
729+ ir_use_list_replace_one (ctx , end2_ref , merge_ref , if_false_ref );
767730
768731 MAKE_NOP (merge ); CLEAR_USES (merge_ref );
769732 MAKE_NOP (phi ); CLEAR_USES (phi_ref );
@@ -809,10 +772,10 @@ static ir_ref ir_try_split_if_cmp(ir_ctx *ctx, ir_worklist *worklist, ir_ref ref
809772 ir_use_list_remove_all (ctx , merge_ref , phi_ref );
810773 ir_use_list_remove_all (ctx , ref , if_true_ref );
811774 if (!IR_IS_CONST_REF (phi -> op3 )) {
812- ir_use_list_replace (ctx , phi -> op3 , phi_ref , insn -> op2 );
775+ ir_use_list_replace_one (ctx , phi -> op3 , phi_ref , insn -> op2 );
813776 }
814- ir_use_list_replace (ctx , end1_ref , merge_ref , if_false_ref );
815- ir_use_list_replace (ctx , cond_ref , ref , end2_ref );
777+ ir_use_list_replace_one (ctx , end1_ref , merge_ref , if_false_ref );
778+ ir_use_list_replace_one (ctx , cond_ref , ref , end2_ref );
816779 ir_use_list_add (ctx , end2_ref , if_true_ref );
817780
818781 end2 -> optx = IR_OPTX (IR_IF , IR_VOID , 2 );
0 commit comments