a04faefaf336ae2bd45014cac13927f00d24bfd5
[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
31 /* Initialize loop optimizer.  */
32
33 struct loops *
34 loop_optimizer_init (dumpfile)
35      FILE *dumpfile;
36 {
37   struct loops *loops = xcalloc (1, sizeof (struct loops));
38   edge e;
39
40   /* Initialize structures for layout changes.  */
41   cfg_layout_initialize ();
42
43   /* Avoid annoying special cases of edges going to exit
44      block.  */
45   for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
46     if ((e->flags & EDGE_FALLTHRU) && e->src->succ->succ_next)
47       split_edge (e);
48
49   /* Find the loops.  */
50
51   if (flow_loops_find (loops, LOOP_TREE) <= 1)
52     {
53       basic_block bb;
54
55       /* No loops.  */
56       flow_loops_free (loops);
57       free (loops);
58       /* Make chain.  */
59       FOR_EACH_BB (bb)
60         if (bb->next_bb != EXIT_BLOCK_PTR)
61           bb->rbi->next = bb->next_bb;
62           cfg_layout_finalize ();
63       return NULL;
64     }
65
66   /* Not going to update these.  */
67   free (loops->cfg.rc_order);
68   loops->cfg.rc_order = NULL;
69   free (loops->cfg.dfs_order);
70   loops->cfg.dfs_order = NULL;
71
72   /* Create pre-headers.  */
73   create_preheaders (loops, CP_SIMPLE_PREHEADERS);
74
75   /* Force all latches to have only single successor.  */
76   force_single_succ_latches (loops);
77
78   /* Mark irreducible loops.  */
79   mark_irreducible_loops (loops);
80
81   /* Dump loops.  */
82   flow_loops_dump (loops, dumpfile, NULL, 1);
83
84 #ifdef ENABLE_CHECKING
85   verify_dominators (loops->cfg.dom);
86   verify_loop_structure (loops);
87 #endif
88
89   return loops;
90 }
91
92 /* Finalize loop optimizer.  */
93 void
94 loop_optimizer_finalize (loops, dumpfile)
95      struct loops *loops;
96      FILE *dumpfile;
97 {
98   basic_block bb;
99
100   /* Finalize layout changes.  */
101   /* Make chain.  */
102   FOR_EACH_BB (bb)
103     if (bb->next_bb != EXIT_BLOCK_PTR)
104       bb->rbi->next = bb->next_bb;
105
106   /* Another dump.  */
107   flow_loops_dump (loops, dumpfile, NULL, 1);
108
109   /* Clean up.  */
110   flow_loops_free (loops);
111   free (loops);
112  
113   /* Finalize changes.  */
114   cfg_layout_finalize ();
115
116   /* Checking.  */
117 #ifdef ENABLE_CHECKING
118   verify_flow_info ();
119 #endif
120 }
121