8
8
#include "ir.h"
9
9
#include "ir_private.h"
10
10
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
-
35
11
static void ir_get_true_false_refs (const ir_ctx * ctx , ir_ref if_ref , ir_ref * if_true_ref , ir_ref * if_false_ref )
36
12
{
37
13
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)
54
30
{
55
31
ir_ref prev , next ;
56
32
ir_use_list * use_list ;
57
- ir_ref n , * p ;
58
33
59
34
IR_ASSERT (ctx -> ir_base [begin ].op == IR_BEGIN );
60
35
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)
68
43
next = ctx -> use_edges [use_list -> refs ];
69
44
70
45
/* 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 );
77
48
78
49
/* connect their predecessor and successor */
79
50
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 );
88
52
return next ;
89
53
}
90
54
@@ -141,7 +105,7 @@ static ir_ref ir_try_remove_empty_diamond(ir_ctx *ctx, ir_ref ref, ir_insn *insn
141
105
IR_ASSERT (ctx -> use_lists [start2_ref ].count == 1 );
142
106
143
107
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 );
145
109
if (!IR_IS_CONST_REF (root -> op2 )) {
146
110
ir_use_list_remove_all (ctx , root -> op2 , root_ref );
147
111
}
@@ -189,7 +153,7 @@ static ir_ref ir_try_remove_empty_diamond(ir_ctx *ctx, ir_ref ref, ir_insn *insn
189
153
ir_insn * root = & ctx -> ir_base [root_ref ];
190
154
191
155
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 );
193
157
ir_use_list_remove_all (ctx , root -> op2 , root_ref );
194
158
195
159
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_
303
267
insn -> op3 = IR_UNUSED ;
304
268
305
269
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 );
308
271
if (!IR_IS_CONST_REF (insn -> op1 )) {
309
272
ir_use_list_remove_all (ctx , insn -> op1 , cond_ref );
310
273
}
@@ -384,8 +347,8 @@ static ir_ref ir_optimize_phi(ir_ctx *ctx, ir_ref merge_ref, ir_insn *merge, ir_
384
347
insn -> op3 = IR_UNUSED ;
385
348
386
349
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 );
389
352
if (!IR_IS_CONST_REF (insn -> op1 )) {
390
353
ir_use_list_remove_all (ctx , insn -> op1 , cond_ref );
391
354
}
@@ -440,8 +403,8 @@ static ir_ref ir_optimize_phi(ir_ctx *ctx, ir_ref merge_ref, ir_insn *merge, ir_
440
403
}
441
404
442
405
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 );
445
408
ir_use_list_remove_all (ctx , root -> op2 , root_ref );
446
409
447
410
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)
619
582
ir_use_list_remove_all (ctx , merge_ref , cond_ref );
620
583
ir_use_list_remove_all (ctx , ref , if_true_ref );
621
584
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 );
623
586
}
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 );
625
588
ir_use_list_add (ctx , end2_ref , if_true_ref );
626
589
627
590
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
722
685
* | |
723
686
*/
724
687
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 );
727
690
728
691
MAKE_NOP (merge ); CLEAR_USES (merge_ref );
729
692
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
762
725
* | |
763
726
*/
764
727
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 );
767
730
768
731
MAKE_NOP (merge ); CLEAR_USES (merge_ref );
769
732
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
809
772
ir_use_list_remove_all (ctx , merge_ref , phi_ref );
810
773
ir_use_list_remove_all (ctx , ref , if_true_ref );
811
774
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 );
813
776
}
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 );
816
779
ir_use_list_add (ctx , end2_ref , if_true_ref );
817
780
818
781
end2 -> optx = IR_OPTX (IR_IF , IR_VOID , 2 );
0 commit comments