@@ -606,59 +606,66 @@ void solve_phi_insertion(void)
606
606
basic_block_t * work_list [64 ];
607
607
int work_list_idx = 0 ;
608
608
609
+ /* Initialize work list with blocks that reference this variable */
609
610
for (ref_block_t * ref = var -> ref_block_list .head ; ref ;
610
611
ref = ref -> next ) {
611
612
if (work_list_idx >= 64 ) /* Prevent buffer overflow */
612
613
break ;
613
614
work_list [work_list_idx ++ ] = ref -> bb ;
614
615
}
615
616
617
+ /* Process work list items */
616
618
for (int i = 0 ; i < work_list_idx ; i ++ ) {
617
619
basic_block_t * bb = work_list [i ];
620
+
618
621
for (int j = 0 ; j < bb -> df_idx ; j ++ ) {
619
622
basic_block_t * df = bb -> DF [j ];
623
+
624
+ /* Skip early conditions */
620
625
if (!var_check_in_scope (var , df -> scope ))
621
626
continue ;
627
+ if (df == func -> exit )
628
+ continue ;
629
+ if (var -> is_global )
630
+ continue ;
622
631
632
+ /* Check if variable already declared in this block */
623
633
bool is_decl = false;
624
634
for (symbol_t * s = df -> symbol_list .head ; s ; s = s -> next ) {
625
635
if (s -> var == var ) {
626
636
is_decl = true;
627
637
break ;
628
638
}
629
639
}
630
-
631
640
if (is_decl )
632
641
continue ;
633
642
634
- if (df == func -> exit )
643
+ /* Try to insert phi instruction */
644
+ if (!insert_phi_insn (df , var ))
635
645
continue ;
636
646
637
- if (var -> is_global )
647
+ /* Restrict phi insertion of ternary operation, and
648
+ * logical-and/or operation.
649
+ *
650
+ * The ternary and logical-and/or operations don't
651
+ * create new scope, so prevent temporary variable from
652
+ * propagating through the dominance tree.
653
+ */
654
+ if (var -> is_ternary_ret || var -> is_logical_ret )
638
655
continue ;
639
656
640
- if (insert_phi_insn (df , var )) {
641
- bool found = false;
642
-
643
- /* Restrict phi insertion of ternary operation, and
644
- * logical-and/or operation.
645
- *
646
- * The ternary and logical-and/or operations don't
647
- * create new scope, so prevent temporary variable from
648
- * propagating through the dominance tree.
649
- */
650
- if (var -> is_ternary_ret || var -> is_logical_ret )
651
- continue ;
652
-
653
- for (int l = 0 ; l < work_list_idx ; l ++ ) {
654
- if (work_list [l ] == df ) {
655
- found = true;
656
- break ;
657
- }
657
+ /* Check if already in work list */
658
+ bool found = false;
659
+ for (int l = 0 ; l < work_list_idx ; l ++ ) {
660
+ if (work_list [l ] == df ) {
661
+ found = true;
662
+ break ;
658
663
}
659
- if (!found && work_list_idx < 64 ) /* Bounds check */
660
- work_list [work_list_idx ++ ] = df ;
661
664
}
665
+
666
+ /* Add to work list if not found and space available */
667
+ if (!found && work_list_idx < 64 ) /* Bounds check */
668
+ work_list [work_list_idx ++ ] = df ;
662
669
}
663
670
}
664
671
}
0 commit comments