Change gcov file interface to single file at a time.
[platform/upstream/gcc.git] / gcc / loop-init.c
1 /* Loop optimizer initialization routines.
2    Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING.  If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "rtl.h"
26 #include "hard-reg-set.h"
27 #include "basic-block.h"
28 #include "cfgloop.h"
29 #include "cfglayout.h"
30 #include "profile.h"
31
32 /* Initialize loop optimizer.  */
33
34 struct loops *
35 loop_optimizer_init (dumpfile)
36      FILE *dumpfile;
37 {
38   struct loops *loops = xcalloc (1, sizeof (struct loops));
39   edge e;
40
41   /* Avoid annoying special cases of edges going to exit
42      block.  */
43   for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
44     if ((e->flags & EDGE_FALLTHRU) && e->src->succ->succ_next)
45       split_edge (e);
46
47   /* Find the loops.  */
48
49   if (flow_loops_find (loops, LOOP_TREE) <= 1)
50     {
51       /* No loops.  */
52       flow_loops_free (loops);
53       free (loops);
54       return NULL;
55     }
56
57   /* Not going to update these.  */
58   free (loops->cfg.rc_order);
59   loops->cfg.rc_order = NULL;
60   free (loops->cfg.dfs_order);
61   loops->cfg.dfs_order = NULL;
62
63   /* Initialize structures for layout changes.  */
64   cfg_layout_initialize (loops);
65
66   /* Create pre-headers.  */
67   create_preheaders (loops, CP_SIMPLE_PREHEADERS | CP_INSIDE_CFGLAYOUT);
68
69   /* Force all latches to have only single successor.  */
70   force_single_succ_latches (loops);
71
72   /* Mark irreducible loops.  */
73   mark_irreducible_loops (loops);
74
75   /* Dump loops.  */
76   flow_loops_dump (loops, dumpfile, NULL, 1);
77
78 #ifdef ENABLE_CHECKING
79   verify_dominators (loops->cfg.dom);
80   verify_loop_structure (loops);
81 #endif
82
83   return loops;
84 }
85
86 /* Finalize loop optimizer.  */
87 void
88 loop_optimizer_finalize (loops, dumpfile)
89      struct loops *loops;
90      FILE *dumpfile;
91 {
92   basic_block bb;
93
94   /* Finalize layout changes.  */
95   /* Make chain.  */
96   FOR_EACH_BB (bb)
97     if (bb->next_bb != EXIT_BLOCK_PTR)
98       RBI (bb)->next = bb->next_bb;
99
100   /* Another dump.  */
101   flow_loops_dump (loops, dumpfile, NULL, 1);
102
103   /* Clean up.  */
104   flow_loops_free (loops);
105   free (loops);
106  
107   /* Finalize changes.  */
108   cfg_layout_finalize ();
109
110   /* Checking.  */
111 #ifdef ENABLE_CHECKING
112   verify_flow_info ();
113 #endif
114 }
115