xref: /dflybsd-src/contrib/gcc-8.0/gcc/sel-sched-dump.c (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* Instruction scheduling pass.   Log dumping infrastructure.
2*38fd1498Szrj    Copyright (C) 2006-2018 Free Software Foundation, Inc.
3*38fd1498Szrj 
4*38fd1498Szrj This file is part of GCC.
5*38fd1498Szrj 
6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
7*38fd1498Szrj the terms of the GNU General Public License as published by the Free
8*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
9*38fd1498Szrj version.
10*38fd1498Szrj 
11*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14*38fd1498Szrj for more details.
15*38fd1498Szrj 
16*38fd1498Szrj You should have received a copy of the GNU General Public License
17*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
18*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
19*38fd1498Szrj 
20*38fd1498Szrj #include "config.h"
21*38fd1498Szrj #include "system.h"
22*38fd1498Szrj #include "coretypes.h"
23*38fd1498Szrj #include "backend.h"
24*38fd1498Szrj #include "rtl.h"
25*38fd1498Szrj #include "df.h"
26*38fd1498Szrj #include "insn-attr.h"
27*38fd1498Szrj #include "cselib.h"
28*38fd1498Szrj 
29*38fd1498Szrj #ifdef INSN_SCHEDULING
30*38fd1498Szrj #include "regset.h"
31*38fd1498Szrj #include "sched-int.h"
32*38fd1498Szrj #include "cfgloop.h"
33*38fd1498Szrj #include "sel-sched-ir.h"
34*38fd1498Szrj #include "sel-sched-dump.h"
35*38fd1498Szrj #include "print-rtl.h"
36*38fd1498Szrj 
37*38fd1498Szrj 
38*38fd1498Szrj /* These variables control high-level pretty printing.  */
39*38fd1498Szrj static int sel_dump_cfg_flags = SEL_DUMP_CFG_FLAGS;
40*38fd1498Szrj static int sel_debug_cfg_flags = SEL_DUMP_CFG_FLAGS;
41*38fd1498Szrj 
42*38fd1498Szrj /* True when a cfg should be dumped.  */
43*38fd1498Szrj static bool sel_dump_cfg_p;
44*38fd1498Szrj 
45*38fd1498Szrj /* Variables that are used to build the cfg dump file name.  */
46*38fd1498Szrj static const char * const sel_debug_cfg_root = "./";
47*38fd1498Szrj static const char * const sel_debug_cfg_root_postfix_default = "";
48*38fd1498Szrj static const char *sel_debug_cfg_root_postfix = "";
49*38fd1498Szrj static int sel_dump_cfg_fileno = -1;
50*38fd1498Szrj static int sel_debug_cfg_fileno = -1;
51*38fd1498Szrj 
52*38fd1498Szrj /* When this flag is on, we are dumping to the .dot file.
53*38fd1498Szrj    When it is off, we are dumping to log.
54*38fd1498Szrj    This is useful to differentiate formatting between log and .dot
55*38fd1498Szrj    files.  */
56*38fd1498Szrj bool sched_dump_to_dot_p = false;
57*38fd1498Szrj 
58*38fd1498Szrj /* Controls how insns from a fence list should be dumped.  */
59*38fd1498Szrj static int dump_flist_insn_flags = (DUMP_INSN_UID | DUMP_INSN_BBN
60*38fd1498Szrj                                     | DUMP_INSN_SEQNO);
61*38fd1498Szrj 
62*38fd1498Szrj 
63*38fd1498Szrj /* The variable used to hold the value of sched_dump when temporarily
64*38fd1498Szrj    switching dump output to the other source, e.g. the .dot file.  */
65*38fd1498Szrj static FILE *saved_sched_dump = NULL;
66*38fd1498Szrj 
67*38fd1498Szrj /* Switch sched_dump to TO.  It must not be called twice.  */
68*38fd1498Szrj static void
switch_dump(FILE * to)69*38fd1498Szrj switch_dump (FILE *to)
70*38fd1498Szrj {
71*38fd1498Szrj   gcc_assert (saved_sched_dump == NULL);
72*38fd1498Szrj 
73*38fd1498Szrj   saved_sched_dump = sched_dump;
74*38fd1498Szrj   sched_dump = to;
75*38fd1498Szrj }
76*38fd1498Szrj 
77*38fd1498Szrj /* Restore previously switched dump.  */
78*38fd1498Szrj static void
restore_dump(void)79*38fd1498Szrj restore_dump (void)
80*38fd1498Szrj {
81*38fd1498Szrj   sched_dump = saved_sched_dump;
82*38fd1498Szrj   saved_sched_dump = NULL;
83*38fd1498Szrj }
84*38fd1498Szrj 
85*38fd1498Szrj 
86*38fd1498Szrj /* Functions for dumping instructions, av sets, and exprs.  */
87*38fd1498Szrj 
88*38fd1498Szrj /* Default flags for dumping insns.  */
89*38fd1498Szrj static int dump_insn_rtx_flags = DUMP_INSN_RTX_UID | DUMP_INSN_RTX_PATTERN;
90*38fd1498Szrj 
91*38fd1498Szrj /* Default flags for dumping vinsns.  */
92*38fd1498Szrj static int dump_vinsn_flags = (DUMP_VINSN_INSN_RTX | DUMP_VINSN_TYPE
93*38fd1498Szrj 			       | DUMP_VINSN_COUNT);
94*38fd1498Szrj 
95*38fd1498Szrj /* Default flags for dumping expressions.  */
96*38fd1498Szrj static int dump_expr_flags = DUMP_EXPR_ALL;
97*38fd1498Szrj 
98*38fd1498Szrj /* Default flags for dumping insns when debugging.  */
99*38fd1498Szrj static int debug_insn_rtx_flags = DUMP_INSN_RTX_ALL;
100*38fd1498Szrj 
101*38fd1498Szrj /* Default flags for dumping vinsns when debugging.  */
102*38fd1498Szrj static int debug_vinsn_flags = DUMP_VINSN_ALL;
103*38fd1498Szrj 
104*38fd1498Szrj /* Default flags for dumping expressions when debugging.  */
105*38fd1498Szrj static int debug_expr_flags = DUMP_EXPR_ALL;
106*38fd1498Szrj 
107*38fd1498Szrj /* Controls how an insn from stream should be dumped when debugging.  */
108*38fd1498Szrj static int debug_insn_flags = DUMP_INSN_ALL;
109*38fd1498Szrj 
110*38fd1498Szrj /* Print an rtx X.  */
111*38fd1498Szrj void
sel_print_rtl(rtx x)112*38fd1498Szrj sel_print_rtl (rtx x)
113*38fd1498Szrj {
114*38fd1498Szrj   print_rtl_single (sched_dump, x);
115*38fd1498Szrj }
116*38fd1498Szrj 
117*38fd1498Szrj /* Dump insn INSN honoring FLAGS.  */
118*38fd1498Szrj void
dump_insn_rtx_1(rtx insn,int flags)119*38fd1498Szrj dump_insn_rtx_1 (rtx insn, int flags)
120*38fd1498Szrj {
121*38fd1498Szrj   int all;
122*38fd1498Szrj 
123*38fd1498Szrj   /* flags == -1 also means dumping all.  */
124*38fd1498Szrj   all = (flags & 1);
125*38fd1498Szrj   if (all)
126*38fd1498Szrj     flags |= DUMP_INSN_RTX_ALL;
127*38fd1498Szrj 
128*38fd1498Szrj   sel_print ("(");
129*38fd1498Szrj 
130*38fd1498Szrj   if (flags & DUMP_INSN_RTX_UID)
131*38fd1498Szrj     sel_print ("%d;", INSN_UID (insn));
132*38fd1498Szrj 
133*38fd1498Szrj   if (flags & DUMP_INSN_RTX_PATTERN)
134*38fd1498Szrj     sel_print ("%s;", str_pattern_slim (PATTERN (insn)));
135*38fd1498Szrj 
136*38fd1498Szrj   if (flags & DUMP_INSN_RTX_BBN)
137*38fd1498Szrj     {
138*38fd1498Szrj       basic_block bb = BLOCK_FOR_INSN (insn);
139*38fd1498Szrj 
140*38fd1498Szrj       sel_print ("bb:%d;", bb != NULL ? bb->index : -1);
141*38fd1498Szrj     }
142*38fd1498Szrj 
143*38fd1498Szrj   sel_print (")");
144*38fd1498Szrj }
145*38fd1498Szrj 
146*38fd1498Szrj 
147*38fd1498Szrj /* Dump INSN with default flags.  */
148*38fd1498Szrj void
dump_insn_rtx(rtx insn)149*38fd1498Szrj dump_insn_rtx (rtx insn)
150*38fd1498Szrj {
151*38fd1498Szrj   dump_insn_rtx_1 (insn, dump_insn_rtx_flags);
152*38fd1498Szrj }
153*38fd1498Szrj 
154*38fd1498Szrj 
155*38fd1498Szrj /* Dump INSN to stderr.  */
156*38fd1498Szrj DEBUG_FUNCTION void
debug_insn_rtx(rtx insn)157*38fd1498Szrj debug_insn_rtx (rtx insn)
158*38fd1498Szrj {
159*38fd1498Szrj   switch_dump (stderr);
160*38fd1498Szrj   dump_insn_rtx_1 (insn, debug_insn_rtx_flags);
161*38fd1498Szrj   sel_print ("\n");
162*38fd1498Szrj   restore_dump ();
163*38fd1498Szrj }
164*38fd1498Szrj 
165*38fd1498Szrj /* Dump vinsn VI honoring flags.  */
166*38fd1498Szrj void
dump_vinsn_1(vinsn_t vi,int flags)167*38fd1498Szrj dump_vinsn_1 (vinsn_t vi, int flags)
168*38fd1498Szrj {
169*38fd1498Szrj   int all;
170*38fd1498Szrj 
171*38fd1498Szrj   /* flags == -1 also means dumping all.  */
172*38fd1498Szrj   all = flags & 1;
173*38fd1498Szrj   if (all)
174*38fd1498Szrj     flags |= DUMP_VINSN_ALL;
175*38fd1498Szrj 
176*38fd1498Szrj   sel_print ("(");
177*38fd1498Szrj 
178*38fd1498Szrj   if (flags & DUMP_VINSN_INSN_RTX)
179*38fd1498Szrj     dump_insn_rtx_1 (VINSN_INSN_RTX (vi), dump_insn_rtx_flags | all);
180*38fd1498Szrj 
181*38fd1498Szrj   if (flags & DUMP_VINSN_TYPE)
182*38fd1498Szrj     sel_print ("type:%s;", GET_RTX_NAME (VINSN_TYPE (vi)));
183*38fd1498Szrj 
184*38fd1498Szrj   if (flags & DUMP_VINSN_COUNT)
185*38fd1498Szrj     sel_print ("count:%d;", VINSN_COUNT (vi));
186*38fd1498Szrj 
187*38fd1498Szrj   if (flags & DUMP_VINSN_COST)
188*38fd1498Szrj     {
189*38fd1498Szrj       int cost = vi->cost;
190*38fd1498Szrj 
191*38fd1498Szrj       if (cost != -1)
192*38fd1498Szrj 	sel_print ("cost:%d;", cost);
193*38fd1498Szrj     }
194*38fd1498Szrj 
195*38fd1498Szrj   sel_print (")");
196*38fd1498Szrj }
197*38fd1498Szrj 
198*38fd1498Szrj /* Dump vinsn VI with default flags.  */
199*38fd1498Szrj void
dump_vinsn(vinsn_t vi)200*38fd1498Szrj dump_vinsn (vinsn_t vi)
201*38fd1498Szrj {
202*38fd1498Szrj   dump_vinsn_1 (vi, dump_vinsn_flags);
203*38fd1498Szrj }
204*38fd1498Szrj 
205*38fd1498Szrj DEBUG_FUNCTION void
debug(vinsn_def & ref)206*38fd1498Szrj debug (vinsn_def &ref)
207*38fd1498Szrj {
208*38fd1498Szrj   switch_dump (stderr);
209*38fd1498Szrj   dump_vinsn_1 (&ref, dump_vinsn_flags);
210*38fd1498Szrj   sel_print ("\n");
211*38fd1498Szrj   restore_dump ();
212*38fd1498Szrj }
213*38fd1498Szrj 
214*38fd1498Szrj DEBUG_FUNCTION void
debug(vinsn_def * ptr)215*38fd1498Szrj debug (vinsn_def *ptr)
216*38fd1498Szrj {
217*38fd1498Szrj   if (ptr)
218*38fd1498Szrj     debug (*ptr);
219*38fd1498Szrj   else
220*38fd1498Szrj     fprintf (stderr, "<nil>\n");
221*38fd1498Szrj }
222*38fd1498Szrj 
223*38fd1498Szrj DEBUG_FUNCTION void
debug_verbose(vinsn_def & ref)224*38fd1498Szrj debug_verbose (vinsn_def &ref)
225*38fd1498Szrj {
226*38fd1498Szrj   switch_dump (stderr);
227*38fd1498Szrj   dump_vinsn_1 (&ref, debug_vinsn_flags);
228*38fd1498Szrj   sel_print ("\n");
229*38fd1498Szrj   restore_dump ();
230*38fd1498Szrj }
231*38fd1498Szrj 
232*38fd1498Szrj DEBUG_FUNCTION void
debug_verbose(vinsn_def * ptr)233*38fd1498Szrj debug_verbose (vinsn_def *ptr)
234*38fd1498Szrj {
235*38fd1498Szrj   if (ptr)
236*38fd1498Szrj     debug (*ptr);
237*38fd1498Szrj   else
238*38fd1498Szrj     fprintf (stderr, "<nil>\n");
239*38fd1498Szrj }
240*38fd1498Szrj 
241*38fd1498Szrj /* Dump vinsn VI to stderr.  */
242*38fd1498Szrj DEBUG_FUNCTION void
debug_vinsn(vinsn_t vi)243*38fd1498Szrj debug_vinsn (vinsn_t vi)
244*38fd1498Szrj {
245*38fd1498Szrj   switch_dump (stderr);
246*38fd1498Szrj   dump_vinsn_1 (vi, debug_vinsn_flags);
247*38fd1498Szrj   sel_print ("\n");
248*38fd1498Szrj   restore_dump ();
249*38fd1498Szrj }
250*38fd1498Szrj 
251*38fd1498Szrj /* Dump EXPR honoring flags.  */
252*38fd1498Szrj void
dump_expr_1(expr_t expr,int flags)253*38fd1498Szrj dump_expr_1 (expr_t expr, int flags)
254*38fd1498Szrj {
255*38fd1498Szrj   int all;
256*38fd1498Szrj 
257*38fd1498Szrj   /* flags == -1 also means dumping all.  */
258*38fd1498Szrj   all = flags & 1;
259*38fd1498Szrj   if (all)
260*38fd1498Szrj     flags |= DUMP_EXPR_ALL;
261*38fd1498Szrj 
262*38fd1498Szrj   sel_print ("[");
263*38fd1498Szrj 
264*38fd1498Szrj   if (flags & DUMP_EXPR_VINSN)
265*38fd1498Szrj     dump_vinsn_1 (EXPR_VINSN (expr), dump_vinsn_flags | all);
266*38fd1498Szrj 
267*38fd1498Szrj   if (flags & DUMP_EXPR_SPEC)
268*38fd1498Szrj     {
269*38fd1498Szrj       int spec = EXPR_SPEC (expr);
270*38fd1498Szrj 
271*38fd1498Szrj       if (spec != 0)
272*38fd1498Szrj 	sel_print ("spec:%d;", spec);
273*38fd1498Szrj     }
274*38fd1498Szrj 
275*38fd1498Szrj   if (flags & DUMP_EXPR_USEFULNESS)
276*38fd1498Szrj     {
277*38fd1498Szrj       int use = EXPR_USEFULNESS (expr);
278*38fd1498Szrj 
279*38fd1498Szrj       if (use != REG_BR_PROB_BASE)
280*38fd1498Szrj         sel_print ("use:%d;", use);
281*38fd1498Szrj     }
282*38fd1498Szrj 
283*38fd1498Szrj   if (flags & DUMP_EXPR_PRIORITY)
284*38fd1498Szrj     sel_print ("prio:%d;", EXPR_PRIORITY (expr));
285*38fd1498Szrj 
286*38fd1498Szrj   if (flags & DUMP_EXPR_SCHED_TIMES)
287*38fd1498Szrj     {
288*38fd1498Szrj       int times = EXPR_SCHED_TIMES (expr);
289*38fd1498Szrj 
290*38fd1498Szrj       if (times != 0)
291*38fd1498Szrj 	sel_print ("times:%d;", times);
292*38fd1498Szrj     }
293*38fd1498Szrj 
294*38fd1498Szrj   if (flags & DUMP_EXPR_SPEC_DONE_DS)
295*38fd1498Szrj     {
296*38fd1498Szrj       ds_t spec_done_ds = EXPR_SPEC_DONE_DS (expr);
297*38fd1498Szrj 
298*38fd1498Szrj       if (spec_done_ds != 0)
299*38fd1498Szrj 	sel_print ("ds:%d;", spec_done_ds);
300*38fd1498Szrj     }
301*38fd1498Szrj 
302*38fd1498Szrj   if (flags & DUMP_EXPR_ORIG_BB)
303*38fd1498Szrj     {
304*38fd1498Szrj       int orig_bb = EXPR_ORIG_BB_INDEX (expr);
305*38fd1498Szrj 
306*38fd1498Szrj       if (orig_bb != 0)
307*38fd1498Szrj 	sel_print ("orig_bb:%d;", orig_bb);
308*38fd1498Szrj     }
309*38fd1498Szrj 
310*38fd1498Szrj   if (EXPR_TARGET_AVAILABLE (expr) < 1)
311*38fd1498Szrj     sel_print ("target:%d;", EXPR_TARGET_AVAILABLE (expr));
312*38fd1498Szrj   sel_print ("]");
313*38fd1498Szrj }
314*38fd1498Szrj 
315*38fd1498Szrj /* Dump expression EXPR with default flags.  */
316*38fd1498Szrj void
dump_expr(expr_t expr)317*38fd1498Szrj dump_expr (expr_t expr)
318*38fd1498Szrj {
319*38fd1498Szrj   dump_expr_1 (expr, dump_expr_flags);
320*38fd1498Szrj }
321*38fd1498Szrj 
322*38fd1498Szrj /* Dump expression EXPR to stderr.  */
323*38fd1498Szrj DEBUG_FUNCTION void
debug_expr(expr_t expr)324*38fd1498Szrj debug_expr (expr_t expr)
325*38fd1498Szrj {
326*38fd1498Szrj   switch_dump (stderr);
327*38fd1498Szrj   dump_expr_1 (expr, debug_expr_flags);
328*38fd1498Szrj   sel_print ("\n");
329*38fd1498Szrj   restore_dump ();
330*38fd1498Szrj }
331*38fd1498Szrj 
332*38fd1498Szrj /* Dump expression REF.  */
333*38fd1498Szrj 
334*38fd1498Szrj DEBUG_FUNCTION void
debug(expr_def & ref)335*38fd1498Szrj debug (expr_def &ref)
336*38fd1498Szrj {
337*38fd1498Szrj   switch_dump (stderr);
338*38fd1498Szrj   dump_expr_1 (&ref, 0);
339*38fd1498Szrj   sel_print ("\n");
340*38fd1498Szrj   restore_dump ();
341*38fd1498Szrj }
342*38fd1498Szrj 
343*38fd1498Szrj DEBUG_FUNCTION void
debug(expr_def * ptr)344*38fd1498Szrj debug (expr_def *ptr)
345*38fd1498Szrj {
346*38fd1498Szrj   if (ptr)
347*38fd1498Szrj     debug (*ptr);
348*38fd1498Szrj   else
349*38fd1498Szrj     fprintf (stderr, "<nil>\n");
350*38fd1498Szrj }
351*38fd1498Szrj 
352*38fd1498Szrj /* Dump expression REF verbosely.  */
353*38fd1498Szrj 
354*38fd1498Szrj DEBUG_FUNCTION void
debug_verbose(expr_def & ref)355*38fd1498Szrj debug_verbose (expr_def &ref)
356*38fd1498Szrj {
357*38fd1498Szrj   switch_dump (stderr);
358*38fd1498Szrj   dump_expr_1 (&ref, DUMP_EXPR_ALL);
359*38fd1498Szrj   sel_print ("\n");
360*38fd1498Szrj   restore_dump ();
361*38fd1498Szrj }
362*38fd1498Szrj 
363*38fd1498Szrj DEBUG_FUNCTION void
debug_verbose(expr_def * ptr)364*38fd1498Szrj debug_verbose (expr_def *ptr)
365*38fd1498Szrj {
366*38fd1498Szrj   if (ptr)
367*38fd1498Szrj     debug_verbose (*ptr);
368*38fd1498Szrj   else
369*38fd1498Szrj     fprintf (stderr, "<nil>\n");
370*38fd1498Szrj }
371*38fd1498Szrj 
372*38fd1498Szrj /* Dump insn I honoring FLAGS.  */
373*38fd1498Szrj void
dump_insn_1(insn_t i,int flags)374*38fd1498Szrj dump_insn_1 (insn_t i, int flags)
375*38fd1498Szrj {
376*38fd1498Szrj   int all;
377*38fd1498Szrj 
378*38fd1498Szrj   all = flags & 1;
379*38fd1498Szrj   if (all)
380*38fd1498Szrj     flags |= DUMP_INSN_ALL;
381*38fd1498Szrj 
382*38fd1498Szrj   if (!sched_dump_to_dot_p)
383*38fd1498Szrj     sel_print ("(");
384*38fd1498Szrj 
385*38fd1498Szrj   if (flags & DUMP_INSN_EXPR)
386*38fd1498Szrj     {
387*38fd1498Szrj       dump_expr_1 (INSN_EXPR (i), dump_expr_flags | all);
388*38fd1498Szrj       sel_print (";");
389*38fd1498Szrj     }
390*38fd1498Szrj   else if (flags & DUMP_INSN_PATTERN)
391*38fd1498Szrj     {
392*38fd1498Szrj       dump_insn_rtx_1 (i, DUMP_INSN_RTX_PATTERN | all);
393*38fd1498Szrj       sel_print (";");
394*38fd1498Szrj     }
395*38fd1498Szrj   else if (flags & DUMP_INSN_UID)
396*38fd1498Szrj     sel_print ("uid:%d;", INSN_UID (i));
397*38fd1498Szrj 
398*38fd1498Szrj   if (flags & DUMP_INSN_SEQNO)
399*38fd1498Szrj     sel_print ("seqno:%d;", INSN_SEQNO (i));
400*38fd1498Szrj 
401*38fd1498Szrj   if (flags & DUMP_INSN_SCHED_CYCLE)
402*38fd1498Szrj     {
403*38fd1498Szrj       int cycle = INSN_SCHED_CYCLE (i);
404*38fd1498Szrj 
405*38fd1498Szrj       if (cycle != 0)
406*38fd1498Szrj 	sel_print ("cycle:%d;", cycle);
407*38fd1498Szrj     }
408*38fd1498Szrj 
409*38fd1498Szrj   if (!sched_dump_to_dot_p)
410*38fd1498Szrj     sel_print (")");
411*38fd1498Szrj }
412*38fd1498Szrj 
413*38fd1498Szrj /* Dump insn I with default flags.  */
414*38fd1498Szrj void
dump_insn(insn_t i)415*38fd1498Szrj dump_insn (insn_t i)
416*38fd1498Szrj {
417*38fd1498Szrj   dump_insn_1 (i, DUMP_INSN_EXPR | DUMP_INSN_SCHED_CYCLE);
418*38fd1498Szrj }
419*38fd1498Szrj 
420*38fd1498Szrj /* Dump INSN to stderr.  */
421*38fd1498Szrj DEBUG_FUNCTION void
debug_insn(insn_t insn)422*38fd1498Szrj debug_insn (insn_t insn)
423*38fd1498Szrj {
424*38fd1498Szrj   switch_dump (stderr);
425*38fd1498Szrj   dump_insn_1 (insn, debug_insn_flags);
426*38fd1498Szrj   sel_print ("\n");
427*38fd1498Szrj   restore_dump ();
428*38fd1498Szrj }
429*38fd1498Szrj 
430*38fd1498Szrj /* Dumps av_set AV.  */
431*38fd1498Szrj void
dump_av_set(av_set_t av)432*38fd1498Szrj dump_av_set (av_set_t av)
433*38fd1498Szrj {
434*38fd1498Szrj   av_set_iterator i;
435*38fd1498Szrj   expr_t expr;
436*38fd1498Szrj 
437*38fd1498Szrj   if (!sched_dump_to_dot_p)
438*38fd1498Szrj     sel_print ("{");
439*38fd1498Szrj 
440*38fd1498Szrj   FOR_EACH_EXPR (expr, i, av)
441*38fd1498Szrj     {
442*38fd1498Szrj       dump_expr (expr);
443*38fd1498Szrj       if (!sched_dump_to_dot_p)
444*38fd1498Szrj         sel_print (" ");
445*38fd1498Szrj       else
446*38fd1498Szrj         sel_print ("\n");
447*38fd1498Szrj     }
448*38fd1498Szrj 
449*38fd1498Szrj   if (!sched_dump_to_dot_p)
450*38fd1498Szrj     sel_print ("}");
451*38fd1498Szrj }
452*38fd1498Szrj 
453*38fd1498Szrj /* Dumps lvset LV.  */
454*38fd1498Szrj void
dump_lv_set(regset lv)455*38fd1498Szrj dump_lv_set (regset lv)
456*38fd1498Szrj {
457*38fd1498Szrj   sel_print ("{");
458*38fd1498Szrj 
459*38fd1498Szrj   /* This code was adapted from cfg.c: dump_regset ().  */
460*38fd1498Szrj   if (lv == NULL)
461*38fd1498Szrj     sel_print ("nil");
462*38fd1498Szrj   else
463*38fd1498Szrj     {
464*38fd1498Szrj       unsigned i;
465*38fd1498Szrj       reg_set_iterator rsi;
466*38fd1498Szrj       int count = 0;
467*38fd1498Szrj 
468*38fd1498Szrj       EXECUTE_IF_SET_IN_REG_SET (lv, 0, i, rsi)
469*38fd1498Szrj         {
470*38fd1498Szrj           sel_print (" %d", i);
471*38fd1498Szrj           if (i < FIRST_PSEUDO_REGISTER)
472*38fd1498Szrj             {
473*38fd1498Szrj               sel_print (" [%s]", reg_names[i]);
474*38fd1498Szrj               ++count;
475*38fd1498Szrj             }
476*38fd1498Szrj 
477*38fd1498Szrj           ++count;
478*38fd1498Szrj 
479*38fd1498Szrj           if (sched_dump_to_dot_p && count == 12)
480*38fd1498Szrj             {
481*38fd1498Szrj               count = 0;
482*38fd1498Szrj               sel_print ("\n");
483*38fd1498Szrj             }
484*38fd1498Szrj         }
485*38fd1498Szrj     }
486*38fd1498Szrj 
487*38fd1498Szrj   sel_print ("}\n");
488*38fd1498Szrj }
489*38fd1498Szrj 
490*38fd1498Szrj /* Dumps a list of instructions pointed to by P.  */
491*38fd1498Szrj static void
dump_ilist(ilist_t p)492*38fd1498Szrj dump_ilist (ilist_t p)
493*38fd1498Szrj {
494*38fd1498Szrj   while (p)
495*38fd1498Szrj     {
496*38fd1498Szrj       dump_insn (ILIST_INSN (p));
497*38fd1498Szrj       p = ILIST_NEXT (p);
498*38fd1498Szrj     }
499*38fd1498Szrj }
500*38fd1498Szrj 
501*38fd1498Szrj /* Dumps a list of boundaries pointed to by BNDS.  */
502*38fd1498Szrj void
dump_blist(blist_t bnds)503*38fd1498Szrj dump_blist (blist_t bnds)
504*38fd1498Szrj {
505*38fd1498Szrj   for (; bnds; bnds = BLIST_NEXT (bnds))
506*38fd1498Szrj     {
507*38fd1498Szrj       bnd_t bnd = BLIST_BND (bnds);
508*38fd1498Szrj 
509*38fd1498Szrj       sel_print ("[to: %d; ptr: ", INSN_UID (BND_TO (bnd)));
510*38fd1498Szrj       dump_ilist (BND_PTR (bnd));
511*38fd1498Szrj       sel_print ("] ");
512*38fd1498Szrj     }
513*38fd1498Szrj }
514*38fd1498Szrj 
515*38fd1498Szrj /* Dumps a list of fences pointed to by L.  */
516*38fd1498Szrj void
dump_flist(flist_t l)517*38fd1498Szrj dump_flist (flist_t l)
518*38fd1498Szrj {
519*38fd1498Szrj   while (l)
520*38fd1498Szrj     {
521*38fd1498Szrj       dump_insn_1 (FENCE_INSN (FLIST_FENCE (l)), dump_flist_insn_flags);
522*38fd1498Szrj       sel_print (" ");
523*38fd1498Szrj       l = FLIST_NEXT (l);
524*38fd1498Szrj     }
525*38fd1498Szrj }
526*38fd1498Szrj 
527*38fd1498Szrj /* Dumps an insn vector SUCCS.  */
528*38fd1498Szrj void
dump_insn_vector(rtx_vec_t succs)529*38fd1498Szrj dump_insn_vector (rtx_vec_t succs)
530*38fd1498Szrj {
531*38fd1498Szrj   int i;
532*38fd1498Szrj   rtx_insn *succ;
533*38fd1498Szrj 
534*38fd1498Szrj   FOR_EACH_VEC_ELT (succs, i, succ)
535*38fd1498Szrj     if (succ)
536*38fd1498Szrj       dump_insn (succ);
537*38fd1498Szrj     else
538*38fd1498Szrj       sel_print ("NULL ");
539*38fd1498Szrj }
540*38fd1498Szrj 
541*38fd1498Szrj /* Dumps a hard reg set SET to FILE using PREFIX.  */
542*38fd1498Szrj static void
print_hard_reg_set(FILE * file,const char * prefix,HARD_REG_SET set)543*38fd1498Szrj print_hard_reg_set (FILE *file, const char *prefix, HARD_REG_SET set)
544*38fd1498Szrj {
545*38fd1498Szrj   int i;
546*38fd1498Szrj 
547*38fd1498Szrj   fprintf (file, "%s{ ", prefix);
548*38fd1498Szrj   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
549*38fd1498Szrj     {
550*38fd1498Szrj       if (TEST_HARD_REG_BIT (set, i))
551*38fd1498Szrj 	fprintf (file, "%d ", i);
552*38fd1498Szrj     }
553*38fd1498Szrj   fprintf (file, "}\n");
554*38fd1498Szrj }
555*38fd1498Szrj 
556*38fd1498Szrj /* Dumps a hard reg set SET using PREFIX.  */
557*38fd1498Szrj void
dump_hard_reg_set(const char * prefix,HARD_REG_SET set)558*38fd1498Szrj dump_hard_reg_set (const char *prefix, HARD_REG_SET set)
559*38fd1498Szrj {
560*38fd1498Szrj   print_hard_reg_set (sched_dump, prefix, set);
561*38fd1498Szrj }
562*38fd1498Szrj 
563*38fd1498Szrj /* Pretty print INSN.  This is used as a hook.  */
564*38fd1498Szrj const char *
sel_print_insn(const rtx_insn * insn,int aligned ATTRIBUTE_UNUSED)565*38fd1498Szrj sel_print_insn (const rtx_insn *insn, int aligned ATTRIBUTE_UNUSED)
566*38fd1498Szrj {
567*38fd1498Szrj   static char buf[80];
568*38fd1498Szrj 
569*38fd1498Szrj   /* '+' before insn means it is a new cycle start and it's not been
570*38fd1498Szrj      scheduled yet.  '>' - has been scheduled.  */
571*38fd1498Szrj   if (s_i_d.exists () && INSN_LUID (insn) > 0)
572*38fd1498Szrj     if (GET_MODE (insn) == TImode)
573*38fd1498Szrj       sprintf (buf, "%s %4d",
574*38fd1498Szrj                INSN_SCHED_TIMES (insn) > 0 ? "> " : "< ",
575*38fd1498Szrj                INSN_UID (insn));
576*38fd1498Szrj     else
577*38fd1498Szrj       sprintf (buf, "%s %4d",
578*38fd1498Szrj                INSN_SCHED_TIMES (insn) > 0 ? "! " : "  ",
579*38fd1498Szrj                INSN_UID (insn));
580*38fd1498Szrj   else
581*38fd1498Szrj     if (GET_MODE (insn) == TImode)
582*38fd1498Szrj       sprintf (buf, "+ %4d", INSN_UID (insn));
583*38fd1498Szrj     else
584*38fd1498Szrj       sprintf (buf, "  %4d", INSN_UID (insn));
585*38fd1498Szrj 
586*38fd1498Szrj   return buf;
587*38fd1498Szrj }
588*38fd1498Szrj 
589*38fd1498Szrj 
590*38fd1498Szrj /* Functions for pretty printing of CFG.  */
591*38fd1498Szrj /* FIXME: Using pretty-print here could simplify this stuff.  */
592*38fd1498Szrj 
593*38fd1498Szrj /* Replace all occurencies of STR1 to STR2 in BUF.
594*38fd1498Szrj    The BUF must be large enough to hold the result.  */
595*38fd1498Szrj static void
replace_str_in_buf(char * buf,const char * str1,const char * str2)596*38fd1498Szrj replace_str_in_buf (char *buf, const char *str1, const char *str2)
597*38fd1498Szrj {
598*38fd1498Szrj   int buf_len = strlen (buf);
599*38fd1498Szrj   int str1_len = strlen (str1);
600*38fd1498Szrj   int str2_len = strlen (str2);
601*38fd1498Szrj   int diff = str2_len - str1_len;
602*38fd1498Szrj 
603*38fd1498Szrj   char *p = buf;
604*38fd1498Szrj   do
605*38fd1498Szrj     {
606*38fd1498Szrj       p = strstr (p, str1);
607*38fd1498Szrj       if (p)
608*38fd1498Szrj 	{
609*38fd1498Szrj 	  char *p1 = p + str1_len;
610*38fd1498Szrj 	  /* Copy the rest of buf and '\0'.  */
611*38fd1498Szrj 	  int n = buf + buf_len - p1;
612*38fd1498Szrj 	  int i;
613*38fd1498Szrj 
614*38fd1498Szrj 	  /* Shift str by DIFF chars.  */
615*38fd1498Szrj 	  if (diff > 0)
616*38fd1498Szrj             for (i = n; i >= 0; i--)
617*38fd1498Szrj               p1[i + diff] = p1[i];
618*38fd1498Szrj 	  else
619*38fd1498Szrj             for (i = 0; i <= n; i++)
620*38fd1498Szrj               p1[i + diff] = p1[i];
621*38fd1498Szrj 
622*38fd1498Szrj 	  /* Copy str2.  */
623*38fd1498Szrj 	  for (i = 0; i < str2_len; i++)
624*38fd1498Szrj 	    p[i] = str2[i];
625*38fd1498Szrj 
626*38fd1498Szrj 	  p += str2_len;
627*38fd1498Szrj 	  buf_len += diff;
628*38fd1498Szrj 	}
629*38fd1498Szrj 
630*38fd1498Szrj     }
631*38fd1498Szrj   while (p);
632*38fd1498Szrj }
633*38fd1498Szrj 
634*38fd1498Szrj /* Replace characters in BUF that have special meaning in .dot file.
635*38fd1498Szrj    Similar to pp_write_text_as_dot_label_to_stream.  */
636*38fd1498Szrj static void
sel_prepare_string_for_dot_label(char * buf)637*38fd1498Szrj sel_prepare_string_for_dot_label (char *buf)
638*38fd1498Szrj {
639*38fd1498Szrj   static char specials_from[7][2] = { "<", ">", "{", "|", "}", "\"",
640*38fd1498Szrj                                       "\n" };
641*38fd1498Szrj   static char specials_to[7][3] = { "\\<", "\\>", "\\{", "\\|", "\\}",
642*38fd1498Szrj                                     "\\\"", "\\l" };
643*38fd1498Szrj   unsigned i;
644*38fd1498Szrj 
645*38fd1498Szrj   for (i = 0; i < 7; i++)
646*38fd1498Szrj     replace_str_in_buf (buf, specials_from[i], specials_to[i]);
647*38fd1498Szrj }
648*38fd1498Szrj 
649*38fd1498Szrj /* This function acts like printf but dumps to the sched_dump file.  */
650*38fd1498Szrj void
sel_print(const char * fmt,...)651*38fd1498Szrj sel_print (const char *fmt, ...)
652*38fd1498Szrj {
653*38fd1498Szrj   va_list ap;
654*38fd1498Szrj   va_start (ap, fmt);
655*38fd1498Szrj   if (sched_dump_to_dot_p)
656*38fd1498Szrj     {
657*38fd1498Szrj       char *message;
658*38fd1498Szrj       if (vasprintf (&message, fmt, ap) >= 0 && message != NULL)
659*38fd1498Szrj 	{
660*38fd1498Szrj 	  message = (char *) xrealloc (message, 2 * strlen (message) + 1);
661*38fd1498Szrj 	  sel_prepare_string_for_dot_label (message);
662*38fd1498Szrj 	  fprintf (sched_dump, "%s", message);
663*38fd1498Szrj 	  free (message);
664*38fd1498Szrj 	}
665*38fd1498Szrj     }
666*38fd1498Szrj   else
667*38fd1498Szrj     vfprintf (sched_dump, fmt, ap);
668*38fd1498Szrj   va_end (ap);
669*38fd1498Szrj }
670*38fd1498Szrj 
671*38fd1498Szrj /* Dump INSN with FLAGS.  */
672*38fd1498Szrj static void
sel_dump_cfg_insn(insn_t insn,int flags)673*38fd1498Szrj sel_dump_cfg_insn (insn_t insn, int flags)
674*38fd1498Szrj {
675*38fd1498Szrj   int insn_flags = DUMP_INSN_UID | DUMP_INSN_PATTERN;
676*38fd1498Szrj 
677*38fd1498Szrj   if (sched_luids.exists () && INSN_LUID (insn) > 0)
678*38fd1498Szrj     {
679*38fd1498Szrj       if (flags & SEL_DUMP_CFG_INSN_SEQNO)
680*38fd1498Szrj 	insn_flags |= DUMP_INSN_SEQNO | DUMP_INSN_SCHED_CYCLE | DUMP_INSN_EXPR;
681*38fd1498Szrj     }
682*38fd1498Szrj 
683*38fd1498Szrj   dump_insn_1 (insn, insn_flags);
684*38fd1498Szrj }
685*38fd1498Szrj 
686*38fd1498Szrj /* Dump E to the dot file F.  */
687*38fd1498Szrj static void
sel_dump_cfg_edge(FILE * f,edge e)688*38fd1498Szrj sel_dump_cfg_edge (FILE *f, edge e)
689*38fd1498Szrj {
690*38fd1498Szrj   int w;
691*38fd1498Szrj   const char *color;
692*38fd1498Szrj 
693*38fd1498Szrj   if (e->flags & EDGE_FALLTHRU)
694*38fd1498Szrj     {
695*38fd1498Szrj       w = 10;
696*38fd1498Szrj       color = ", color = red";
697*38fd1498Szrj     }
698*38fd1498Szrj   else if (e->src->next_bb == e->dest)
699*38fd1498Szrj     {
700*38fd1498Szrj       w = 3;
701*38fd1498Szrj       color = ", color = blue";
702*38fd1498Szrj     }
703*38fd1498Szrj   else
704*38fd1498Szrj     {
705*38fd1498Szrj       w = 1;
706*38fd1498Szrj       color = "";
707*38fd1498Szrj     }
708*38fd1498Szrj 
709*38fd1498Szrj   fprintf (f, "\tbb%d -> bb%d [weight = %d%s];\n",
710*38fd1498Szrj 	   e->src->index, e->dest->index, w, color);
711*38fd1498Szrj }
712*38fd1498Szrj 
713*38fd1498Szrj 
714*38fd1498Szrj /* Return true if BB has a predesessor from current region.
715*38fd1498Szrj    TODO: Either make this function to trace back through empty block
716*38fd1498Szrj    or just remove those empty blocks.  */
717*38fd1498Szrj static bool
has_preds_in_current_region_p(basic_block bb)718*38fd1498Szrj has_preds_in_current_region_p (basic_block bb)
719*38fd1498Szrj {
720*38fd1498Szrj   edge e;
721*38fd1498Szrj   edge_iterator ei;
722*38fd1498Szrj 
723*38fd1498Szrj   gcc_assert (!in_current_region_p (bb));
724*38fd1498Szrj 
725*38fd1498Szrj   FOR_EACH_EDGE (e, ei, bb->preds)
726*38fd1498Szrj     if (in_current_region_p (e->src))
727*38fd1498Szrj       return true;
728*38fd1498Szrj 
729*38fd1498Szrj   return false;
730*38fd1498Szrj }
731*38fd1498Szrj 
732*38fd1498Szrj /* Dump a cfg region to the dot file F honoring FLAGS.  */
733*38fd1498Szrj static void
sel_dump_cfg_2(FILE * f,int flags)734*38fd1498Szrj sel_dump_cfg_2 (FILE *f, int flags)
735*38fd1498Szrj {
736*38fd1498Szrj   basic_block bb;
737*38fd1498Szrj 
738*38fd1498Szrj   sched_dump_to_dot_p = true;
739*38fd1498Szrj   switch_dump (f);
740*38fd1498Szrj 
741*38fd1498Szrj   fprintf (f, "digraph G {\n"
742*38fd1498Szrj 	   "\tratio = 2.25;\n"
743*38fd1498Szrj 	   "\tnode [shape = record, fontsize = 9];\n");
744*38fd1498Szrj 
745*38fd1498Szrj   if (flags & SEL_DUMP_CFG_FUNCTION_NAME)
746*38fd1498Szrj     fprintf (f, "function [label = \"%s\"];\n", current_function_name ());
747*38fd1498Szrj 
748*38fd1498Szrj   FOR_EACH_BB_FN (bb, cfun)
749*38fd1498Szrj     {
750*38fd1498Szrj       insn_t insn = BB_HEAD (bb);
751*38fd1498Szrj       insn_t next_tail = NEXT_INSN (BB_END (bb));
752*38fd1498Szrj       edge e;
753*38fd1498Szrj       edge_iterator ei;
754*38fd1498Szrj       bool in_region_p = ((flags & SEL_DUMP_CFG_CURRENT_REGION)
755*38fd1498Szrj 			  && in_current_region_p (bb));
756*38fd1498Szrj       bool full_p = (!(flags & SEL_DUMP_CFG_CURRENT_REGION)
757*38fd1498Szrj 		     || in_region_p);
758*38fd1498Szrj       bool some_p = full_p || has_preds_in_current_region_p (bb);
759*38fd1498Szrj       const char *color;
760*38fd1498Szrj       const char *style;
761*38fd1498Szrj 
762*38fd1498Szrj       if (!some_p)
763*38fd1498Szrj 	continue;
764*38fd1498Szrj 
765*38fd1498Szrj       if ((flags & SEL_DUMP_CFG_CURRENT_REGION)
766*38fd1498Szrj 	  && in_current_region_p (bb)
767*38fd1498Szrj 	  && BLOCK_TO_BB (bb->index) == 0)
768*38fd1498Szrj 	color = "color = green, ";
769*38fd1498Szrj       else
770*38fd1498Szrj 	color = "";
771*38fd1498Szrj 
772*38fd1498Szrj       if ((flags & SEL_DUMP_CFG_FENCES)
773*38fd1498Szrj 	  && in_region_p)
774*38fd1498Szrj 	{
775*38fd1498Szrj 	  style = "";
776*38fd1498Szrj 
777*38fd1498Szrj 	  if (!sel_bb_empty_p (bb))
778*38fd1498Szrj 	    {
779*38fd1498Szrj 	      bool first_p = true;
780*38fd1498Szrj 	      insn_t tail = BB_END (bb);
781*38fd1498Szrj 	      insn_t cur_insn;
782*38fd1498Szrj 
783*38fd1498Szrj 	      cur_insn = bb_note (bb);
784*38fd1498Szrj 
785*38fd1498Szrj 	      do
786*38fd1498Szrj 		{
787*38fd1498Szrj 		  fence_t fence;
788*38fd1498Szrj 
789*38fd1498Szrj 		  cur_insn = NEXT_INSN (cur_insn);
790*38fd1498Szrj 		  fence = flist_lookup (fences, cur_insn);
791*38fd1498Szrj 
792*38fd1498Szrj 		  if (fence != NULL)
793*38fd1498Szrj 		    {
794*38fd1498Szrj 		      if (!FENCE_SCHEDULED_P (fence))
795*38fd1498Szrj 			{
796*38fd1498Szrj 			  if (first_p)
797*38fd1498Szrj 			    color = "color = red, ";
798*38fd1498Szrj 			  else
799*38fd1498Szrj 			    color = "color = yellow, ";
800*38fd1498Szrj 			}
801*38fd1498Szrj 		      else
802*38fd1498Szrj 			color = "color = blue, ";
803*38fd1498Szrj 		    }
804*38fd1498Szrj 
805*38fd1498Szrj 		  first_p = false;
806*38fd1498Szrj 		}
807*38fd1498Szrj 	      while (cur_insn != tail);
808*38fd1498Szrj 	    }
809*38fd1498Szrj 	}
810*38fd1498Szrj       else if (!full_p)
811*38fd1498Szrj 	style = "style = dashed, ";
812*38fd1498Szrj       else
813*38fd1498Szrj 	style = "";
814*38fd1498Szrj 
815*38fd1498Szrj       fprintf (f, "\tbb%d [%s%slabel = \"{Basic block %d", bb->index,
816*38fd1498Szrj 	       style, color, bb->index);
817*38fd1498Szrj 
818*38fd1498Szrj       if ((flags & SEL_DUMP_CFG_BB_LOOP)
819*38fd1498Szrj 	  && bb->loop_father != NULL)
820*38fd1498Szrj 	fprintf (f, ", loop %d", bb->loop_father->num);
821*38fd1498Szrj 
822*38fd1498Szrj       if (full_p
823*38fd1498Szrj 	  && (flags & SEL_DUMP_CFG_BB_NOTES_LIST))
824*38fd1498Szrj 	{
825*38fd1498Szrj 	  insn_t notes = BB_NOTE_LIST (bb);
826*38fd1498Szrj 
827*38fd1498Szrj 	  if (notes != NULL_RTX)
828*38fd1498Szrj 	    {
829*38fd1498Szrj 	      fprintf (f, "|");
830*38fd1498Szrj 
831*38fd1498Szrj 	      /* For simplicity, we dump notes from note_list in reversed order
832*38fd1498Szrj 		 to that what they will appear in the code.  */
833*38fd1498Szrj 	      while (notes != NULL_RTX)
834*38fd1498Szrj 		{
835*38fd1498Szrj 		  sel_dump_cfg_insn (notes, flags);
836*38fd1498Szrj 		  fprintf (f, "\\l");
837*38fd1498Szrj 
838*38fd1498Szrj 		  notes = PREV_INSN (notes);
839*38fd1498Szrj 		}
840*38fd1498Szrj 	    }
841*38fd1498Szrj 	}
842*38fd1498Szrj 
843*38fd1498Szrj       if (full_p
844*38fd1498Szrj 	  && (flags & SEL_DUMP_CFG_AV_SET)
845*38fd1498Szrj 	  && in_current_region_p (bb)
846*38fd1498Szrj 	  && !sel_bb_empty_p (bb))
847*38fd1498Szrj 	{
848*38fd1498Szrj 	  fprintf (f, "|");
849*38fd1498Szrj 
850*38fd1498Szrj 	  if (BB_AV_SET_VALID_P (bb))
851*38fd1498Szrj 	    dump_av_set (BB_AV_SET (bb));
852*38fd1498Szrj 	  else if (BB_AV_LEVEL (bb) == -1)
853*38fd1498Szrj 	    fprintf (f, "AV_SET needs update");
854*38fd1498Szrj 	}
855*38fd1498Szrj 
856*38fd1498Szrj       if ((flags & SEL_DUMP_CFG_LV_SET)
857*38fd1498Szrj 	  && !sel_bb_empty_p (bb))
858*38fd1498Szrj  	{
859*38fd1498Szrj 	  fprintf (f, "|");
860*38fd1498Szrj 
861*38fd1498Szrj 	  if (BB_LV_SET_VALID_P (bb))
862*38fd1498Szrj 	    dump_lv_set (BB_LV_SET (bb));
863*38fd1498Szrj 	  else
864*38fd1498Szrj 	    fprintf (f, "LV_SET needs update");
865*38fd1498Szrj 	}
866*38fd1498Szrj 
867*38fd1498Szrj       if (full_p
868*38fd1498Szrj 	  && (flags & SEL_DUMP_CFG_BB_INSNS))
869*38fd1498Szrj 	{
870*38fd1498Szrj 	  fprintf (f, "|");
871*38fd1498Szrj 	  while (insn != next_tail)
872*38fd1498Szrj 	    {
873*38fd1498Szrj 	      sel_dump_cfg_insn (insn, flags);
874*38fd1498Szrj 	      fprintf (f, "\\l");
875*38fd1498Szrj 
876*38fd1498Szrj 	      insn = NEXT_INSN (insn);
877*38fd1498Szrj 	    }
878*38fd1498Szrj 	}
879*38fd1498Szrj 
880*38fd1498Szrj       fprintf (f, "}\"];\n");
881*38fd1498Szrj 
882*38fd1498Szrj       FOR_EACH_EDGE (e, ei, bb->succs)
883*38fd1498Szrj 	if (full_p || in_current_region_p (e->dest))
884*38fd1498Szrj 	  sel_dump_cfg_edge (f, e);
885*38fd1498Szrj     }
886*38fd1498Szrj 
887*38fd1498Szrj   fprintf (f, "}");
888*38fd1498Szrj 
889*38fd1498Szrj   restore_dump ();
890*38fd1498Szrj   sched_dump_to_dot_p = false;
891*38fd1498Szrj }
892*38fd1498Szrj 
893*38fd1498Szrj /* Dump a cfg region to the file specified by TAG honoring flags.
894*38fd1498Szrj    The file is created by the function.  */
895*38fd1498Szrj static void
sel_dump_cfg_1(const char * tag,int flags)896*38fd1498Szrj sel_dump_cfg_1 (const char *tag, int flags)
897*38fd1498Szrj {
898*38fd1498Szrj   char *buf;
899*38fd1498Szrj   int i;
900*38fd1498Szrj   FILE *f;
901*38fd1498Szrj 
902*38fd1498Szrj   ++sel_dump_cfg_fileno;
903*38fd1498Szrj 
904*38fd1498Szrj   if (!sel_dump_cfg_p)
905*38fd1498Szrj     return;
906*38fd1498Szrj 
907*38fd1498Szrj   i = 1 + snprintf (NULL, 0, "%s/%s%05d-%s.dot", sel_debug_cfg_root,
908*38fd1498Szrj 		    sel_debug_cfg_root_postfix, sel_dump_cfg_fileno, tag);
909*38fd1498Szrj   buf = XNEWVEC (char, i);
910*38fd1498Szrj   snprintf (buf, i, "%s/%s%05d-%s.dot", sel_debug_cfg_root,
911*38fd1498Szrj 	    sel_debug_cfg_root_postfix, sel_dump_cfg_fileno, tag);
912*38fd1498Szrj 
913*38fd1498Szrj   f = fopen (buf, "w");
914*38fd1498Szrj 
915*38fd1498Szrj   if (f == NULL)
916*38fd1498Szrj     fprintf (stderr, "Can't create file: %s.\n", buf);
917*38fd1498Szrj   else
918*38fd1498Szrj     {
919*38fd1498Szrj       sel_dump_cfg_2 (f, flags);
920*38fd1498Szrj 
921*38fd1498Szrj       fclose (f);
922*38fd1498Szrj     }
923*38fd1498Szrj 
924*38fd1498Szrj   free (buf);
925*38fd1498Szrj }
926*38fd1498Szrj 
927*38fd1498Szrj /* Setup cfg dumping flags.  Used for debugging.  */
928*38fd1498Szrj void
setup_dump_cfg_params(void)929*38fd1498Szrj setup_dump_cfg_params (void)
930*38fd1498Szrj {
931*38fd1498Szrj   sel_dump_cfg_flags = SEL_DUMP_CFG_FLAGS;
932*38fd1498Szrj   sel_dump_cfg_p = 0;
933*38fd1498Szrj   sel_debug_cfg_root_postfix = sel_debug_cfg_root_postfix_default;
934*38fd1498Szrj }
935*38fd1498Szrj 
936*38fd1498Szrj /* Debug a cfg region with FLAGS.  */
937*38fd1498Szrj void
sel_debug_cfg_1(int flags)938*38fd1498Szrj sel_debug_cfg_1 (int flags)
939*38fd1498Szrj {
940*38fd1498Szrj   bool t1 = sel_dump_cfg_p;
941*38fd1498Szrj   int t2 = sel_dump_cfg_fileno;
942*38fd1498Szrj 
943*38fd1498Szrj   sel_dump_cfg_p = true;
944*38fd1498Szrj   sel_dump_cfg_fileno = ++sel_debug_cfg_fileno;
945*38fd1498Szrj 
946*38fd1498Szrj   sel_dump_cfg_1 ("sel-debug-cfg", flags);
947*38fd1498Szrj 
948*38fd1498Szrj   sel_dump_cfg_fileno = t2;
949*38fd1498Szrj   sel_dump_cfg_p = t1;
950*38fd1498Szrj }
951*38fd1498Szrj 
952*38fd1498Szrj /* Dumps av_set AV to stderr.  */
953*38fd1498Szrj DEBUG_FUNCTION void
debug_av_set(av_set_t av)954*38fd1498Szrj debug_av_set (av_set_t av)
955*38fd1498Szrj {
956*38fd1498Szrj   switch_dump (stderr);
957*38fd1498Szrj   dump_av_set (av);
958*38fd1498Szrj   sel_print ("\n");
959*38fd1498Szrj   restore_dump ();
960*38fd1498Szrj }
961*38fd1498Szrj 
962*38fd1498Szrj /* Dump LV to stderr.  */
963*38fd1498Szrj DEBUG_FUNCTION void
debug_lv_set(regset lv)964*38fd1498Szrj debug_lv_set (regset lv)
965*38fd1498Szrj {
966*38fd1498Szrj   switch_dump (stderr);
967*38fd1498Szrj   dump_lv_set (lv);
968*38fd1498Szrj   sel_print ("\n");
969*38fd1498Szrj   restore_dump ();
970*38fd1498Szrj }
971*38fd1498Szrj 
972*38fd1498Szrj /* Dump an instruction list P to stderr.  */
973*38fd1498Szrj DEBUG_FUNCTION void
debug_ilist(ilist_t p)974*38fd1498Szrj debug_ilist (ilist_t p)
975*38fd1498Szrj {
976*38fd1498Szrj   switch_dump (stderr);
977*38fd1498Szrj   dump_ilist (p);
978*38fd1498Szrj   sel_print ("\n");
979*38fd1498Szrj   restore_dump ();
980*38fd1498Szrj }
981*38fd1498Szrj 
982*38fd1498Szrj /* Dump a boundary list BNDS to stderr.  */
983*38fd1498Szrj DEBUG_FUNCTION void
debug_blist(blist_t bnds)984*38fd1498Szrj debug_blist (blist_t bnds)
985*38fd1498Szrj {
986*38fd1498Szrj   switch_dump (stderr);
987*38fd1498Szrj   dump_blist (bnds);
988*38fd1498Szrj   sel_print ("\n");
989*38fd1498Szrj   restore_dump ();
990*38fd1498Szrj }
991*38fd1498Szrj 
992*38fd1498Szrj /* Dump a hard reg set SET to stderr.  */
993*38fd1498Szrj DEBUG_FUNCTION void
debug_hard_reg_set(HARD_REG_SET set)994*38fd1498Szrj debug_hard_reg_set (HARD_REG_SET set)
995*38fd1498Szrj {
996*38fd1498Szrj   switch_dump (stderr);
997*38fd1498Szrj   dump_hard_reg_set ("", set);
998*38fd1498Szrj   sel_print ("\n");
999*38fd1498Szrj   restore_dump ();
1000*38fd1498Szrj }
1001*38fd1498Szrj 
1002*38fd1498Szrj /* Debug a cfg region with default flags.  */
1003*38fd1498Szrj void
sel_debug_cfg(void)1004*38fd1498Szrj sel_debug_cfg (void)
1005*38fd1498Szrj {
1006*38fd1498Szrj   sel_debug_cfg_1 (sel_debug_cfg_flags);
1007*38fd1498Szrj }
1008*38fd1498Szrj 
1009*38fd1498Szrj /* Print a current cselib value for X's address to stderr.  */
1010*38fd1498Szrj DEBUG_FUNCTION rtx
debug_mem_addr_value(rtx x)1011*38fd1498Szrj debug_mem_addr_value (rtx x)
1012*38fd1498Szrj {
1013*38fd1498Szrj   rtx t, addr;
1014*38fd1498Szrj   machine_mode address_mode;
1015*38fd1498Szrj 
1016*38fd1498Szrj   gcc_assert (MEM_P (x));
1017*38fd1498Szrj   address_mode = get_address_mode (x);
1018*38fd1498Szrj 
1019*38fd1498Szrj   t = shallow_copy_rtx (x);
1020*38fd1498Szrj   if (cselib_lookup (XEXP (t, 0), address_mode, 0, GET_MODE (t)))
1021*38fd1498Szrj     XEXP (t, 0) = cselib_subst_to_values (XEXP (t, 0), GET_MODE (t));
1022*38fd1498Szrj 
1023*38fd1498Szrj   t = canon_rtx (t);
1024*38fd1498Szrj   addr = get_addr (XEXP (t, 0));
1025*38fd1498Szrj   debug_rtx (t);
1026*38fd1498Szrj   debug_rtx (addr);
1027*38fd1498Szrj   return t;
1028*38fd1498Szrj }
1029*38fd1498Szrj #endif
1030*38fd1498Szrj 
1031