* basic-block.h (FOR_EACH_EDGE): Record initial edge count.
[official-gcc.git] / gcc / loop-init.c
blob77a412d758e7e5f5cc9c9c607d5fe68967559808
1 /* Loop optimizer initialization routines.
2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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. */
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"
31 /* Initialize loop optimizer. */
33 struct loops *
34 loop_optimizer_init (FILE *dumpfile)
36 struct loops *loops = xcalloc (1, sizeof (struct loops));
37 edge e;
38 static bool first_time = true;
40 if (first_time)
42 first_time = false;
43 init_set_costs ();
46 /* Avoid annoying special cases of edges going to exit
47 block. */
48 FOR_EACH_EDGE (e, EXIT_BLOCK_PTR->preds)
50 if ((e->flags & EDGE_FALLTHRU) && EDGE_COUNT (e->src->succs) > 1)
51 split_edge (e);
53 END_FOR_EACH_EDGE;
55 /* Find the loops. */
57 if (flow_loops_find (loops, LOOP_TREE) <= 1)
59 /* No loops. */
60 flow_loops_free (loops);
61 free (loops);
63 return NULL;
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;
72 /* Create pre-headers. */
73 create_preheaders (loops, CP_SIMPLE_PREHEADERS);
75 /* Force all latches to have only single successor. */
76 force_single_succ_latches (loops);
78 /* Mark irreducible loops. */
79 mark_irreducible_loops (loops);
81 /* Dump loops. */
82 flow_loops_dump (loops, dumpfile, NULL, 1);
84 #ifdef ENABLE_CHECKING
85 verify_dominators (CDI_DOMINATORS);
86 verify_loop_structure (loops);
87 #endif
89 return loops;
92 /* Finalize loop optimizer. */
93 void
94 loop_optimizer_finalize (struct loops *loops, FILE *dumpfile)
96 unsigned i;
98 if (!loops)
99 return;
101 for (i = 1; i < loops->num; i++)
102 if (loops->parray[i])
103 free_simple_loop_desc (loops->parray[i]);
105 /* Another dump. */
106 flow_loops_dump (loops, dumpfile, NULL, 1);
108 /* Clean up. */
109 flow_loops_free (loops);
110 free (loops);
112 /* Checking. */
113 #ifdef ENABLE_CHECKING
114 verify_flow_info ();
115 #endif