OSDN Git Service

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