@@ -162,39 +162,52 @@ void ir_dump_use_lists(const ir_ctx *ctx, FILE *f)
162162 }
163163}
164164
165- static int ir_dump_dessa_move ( ir_ctx * ctx , uint8_t type , ir_ref from , ir_ref to )
165+ static void ir_dump_dessa_moves ( const ir_ctx * ctx , int b , ir_block * bb , FILE * f )
166166{
167- FILE * f = ctx -> data ;
168- int8_t reg ;
169-
170- if (IR_IS_CONST_REF (from )) {
171- fprintf (f , "\tmov c_%d -> " , - from );
172- } else if (from ) {
173- fprintf (f , "\tmov R%d" , ctx -> vregs [from ]);
174- if (ctx -> live_intervals && ctx -> live_intervals [ctx -> vregs [from ]]) {
175- reg = ctx -> live_intervals [ctx -> vregs [from ]]-> reg ;
176- if (reg >= 0 ) {
177- fprintf (f , " [%%%s]" , ir_reg_name (reg , type ));
167+ uint32_t succ ;
168+ ir_block * succ_bb ;
169+ ir_use_list * use_list ;
170+ ir_ref k , i , * p , use_ref , input ;
171+ ir_insn * use_insn ;
172+
173+ IR_ASSERT (bb -> successors_count == 1 );
174+ succ = ctx -> cfg_edges [bb -> successors ];
175+ succ_bb = & ctx -> cfg_blocks [succ ];
176+ IR_ASSERT (succ_bb -> predecessors_count > 1 );
177+ use_list = & ctx -> use_lists [succ_bb -> start ];
178+ k = ir_phi_input_number (ctx , succ_bb , b );
179+
180+ for (i = 0 , p = & ctx -> use_edges [use_list -> refs ]; i < use_list -> count ; i ++ , p ++ ) {
181+ use_ref = * p ;
182+ use_insn = & ctx -> ir_base [use_ref ];
183+ if (use_insn -> op == IR_PHI ) {
184+ input = ir_insn_op (use_insn , k );
185+ if (IR_IS_CONST_REF (input )) {
186+ fprintf (f , "\t# DESSA MOV c_%d" , - input );
187+ } else if (ctx -> vregs [input ] != ctx -> vregs [use_ref ]) {
188+ fprintf (f , "\t# DESSA MOV d_%d {R%d}" , input , ctx -> vregs [input ]);
189+ } else {
190+ continue ;
191+ }
192+ if (ctx -> regs ) {
193+ int8_t * regs = ctx -> regs [use_ref ];
194+ int8_t reg = regs [k ];
195+ if (reg != IR_REG_NONE ) {
196+ fprintf (f , " {%%%s%s}" , ir_reg_name (IR_REG_NUM (reg ), ctx -> ir_base [input ].type ),
197+ (reg & (IR_REG_SPILL_LOAD |IR_REG_SPILL_SPECIAL )) ? ":load" : "" );
198+ }
178199 }
179- }
180- fprintf (f , " -> " );
181- } else {
182- fprintf (f , "\tmov TMP -> " );
183- }
184-
185- if (to ) {
186- fprintf (f , "R%d" , ctx -> vregs [to ]);
187- if (ctx -> live_intervals && ctx -> live_intervals [ctx -> vregs [to ]]) {
188- reg = ctx -> live_intervals [ctx -> vregs [to ]]-> reg ;
189- if (reg >= 0 ) {
190- fprintf (f , " [%%%s]" , ir_reg_name (reg , type ));
200+ fprintf (f , " -> d_%d {R%d}" , use_ref , ctx -> vregs [use_ref ]);
201+ if (ctx -> regs ) {
202+ int8_t reg = ctx -> regs [use_ref ][0 ];
203+ if (reg != IR_REG_NONE ) {
204+ fprintf (f , " {%%%s%s}" , ir_reg_name (IR_REG_NUM (reg ), ctx -> ir_base [use_ref ].type ),
205+ (reg & (IR_REG_SPILL_STORE |IR_REG_SPILL_SPECIAL )) ? ":store" : "" );
206+ }
191207 }
208+ fprintf (f , "\n" );
192209 }
193- fprintf (f , "\n" );
194- } else {
195- fprintf (f , "TMP\n" );
196210 }
197- return 1 ;
198211}
199212
200213void ir_dump_cfg (ir_ctx * ctx , FILE * f )
@@ -283,8 +296,7 @@ void ir_dump_cfg(ir_ctx *ctx, FILE *f)
283296 }
284297 }
285298 if (bb -> flags & IR_BB_DESSA_MOVES ) {
286- ctx -> data = f ;
287- ir_gen_dessa_moves (ctx , b , ir_dump_dessa_move );
299+ ir_dump_dessa_moves (ctx , b , bb , f );
288300 }
289301 }
290302 fprintf (f , "}\n" );
@@ -621,50 +633,7 @@ void ir_dump_codegen(const ir_ctx *ctx, FILE *f)
621633 }
622634
623635 if (bb -> flags & IR_BB_DESSA_MOVES ) {
624- uint32_t succ ;
625- ir_block * succ_bb ;
626- ir_use_list * use_list ;
627- ir_ref k , i , * p , use_ref , input ;
628- ir_insn * use_insn ;
629-
630- IR_ASSERT (bb -> successors_count == 1 );
631- succ = ctx -> cfg_edges [bb -> successors ];
632- succ_bb = & ctx -> cfg_blocks [succ ];
633- IR_ASSERT (succ_bb -> predecessors_count > 1 );
634- use_list = & ctx -> use_lists [succ_bb -> start ];
635- k = ir_phi_input_number (ctx , succ_bb , b );
636-
637- for (i = 0 , p = & ctx -> use_edges [use_list -> refs ]; i < use_list -> count ; i ++ , p ++ ) {
638- use_ref = * p ;
639- use_insn = & ctx -> ir_base [use_ref ];
640- if (use_insn -> op == IR_PHI ) {
641- input = ir_insn_op (use_insn , k );
642- if (IR_IS_CONST_REF (input )) {
643- fprintf (f , "\t# DESSA MOV c_%d" , - input );
644- } else if (ctx -> vregs [input ] != ctx -> vregs [use_ref ]) {
645- fprintf (f , "\t# DESSA MOV d_%d {R%d}" , input , ctx -> vregs [input ]);
646- } else {
647- continue ;
648- }
649- if (ctx -> regs ) {
650- int8_t * regs = ctx -> regs [use_ref ];
651- int8_t reg = regs [k ];
652- if (reg != IR_REG_NONE ) {
653- fprintf (f , " {%%%s%s}" , ir_reg_name (IR_REG_NUM (reg ), ctx -> ir_base [input ].type ),
654- (reg & (IR_REG_SPILL_LOAD |IR_REG_SPILL_SPECIAL )) ? ":load" : "" );
655- }
656- }
657- fprintf (f , " -> d_%d {R%d}" , use_ref , ctx -> vregs [use_ref ]);
658- if (ctx -> regs ) {
659- int8_t reg = ctx -> regs [use_ref ][0 ];
660- if (reg != IR_REG_NONE ) {
661- fprintf (f , " {%%%s%s}" , ir_reg_name (IR_REG_NUM (reg ), ctx -> ir_base [use_ref ].type ),
662- (reg & (IR_REG_SPILL_STORE |IR_REG_SPILL_SPECIAL )) ? ":store" : "" );
663- }
664- }
665- fprintf (f , "\n" );
666- }
667- }
636+ ir_dump_dessa_moves (ctx , b , bb , f );
668637 }
669638
670639 insn = & ctx -> ir_base [bb -> end ];
0 commit comments