* bt-load.c, cfgloop.c, convert.c, dominance.c, global.c,
[official-gcc.git] / gcc / loop-init.c
blob5aa0db11a9c26b805231fcbdd17606266f711995
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 "obstack.h"
28 #include "basic-block.h"
29 #include "cfgloop.h"
30 #include "cfglayout.h"
32 /* Initialize loop optimizer. */
34 struct loops *
35 loop_optimizer_init (FILE *dumpfile)
37 struct loops *loops = xcalloc (1, sizeof (struct loops));
38 edge e;
39 edge_iterator ei;
40 static bool first_time = true;
42 if (first_time)
44 first_time = false;
45 init_set_costs ();
48 /* Avoid annoying special cases of edges going to exit
49 block. */
51 for (ei = ei_start (EXIT_BLOCK_PTR->preds); (e = ei_safe_edge (ei)); )
52 if ((e->flags & EDGE_FALLTHRU) && EDGE_COUNT (e->src->succs) > 1)
53 split_edge (e);
54 else
55 ei_next (&ei);
57 /* Find the loops. */
59 if (flow_loops_find (loops, LOOP_TREE) <= 1)
61 /* No loops. */
62 flow_loops_free (loops);
63 free (loops);
65 return NULL;
68 /* Not going to update these. */
69 free (loops->cfg.rc_order);
70 loops->cfg.rc_order = NULL;
71 free (loops->cfg.dfs_order);
72 loops->cfg.dfs_order = NULL;
74 /* Create pre-headers. */
75 create_preheaders (loops, CP_SIMPLE_PREHEADERS);
77 /* Force all latches to have only single successor. */
78 force_single_succ_latches (loops);
80 /* Mark irreducible loops. */
81 mark_irreducible_loops (loops);
83 /* Dump loops. */
84 flow_loops_dump (loops, dumpfile, NULL, 1);
86 #ifdef ENABLE_CHECKING
87 verify_dominators (CDI_DOMINATORS);
88 verify_loop_structure (loops);
89 #endif
91 return loops;
94 /* Finalize loop optimizer. */
95 void
96 loop_optimizer_finalize (struct loops *loops, FILE *dumpfile)
98 unsigned i;
100 if (!loops)
101 return;
103 for (i = 1; i < loops->num; i++)
104 if (loops->parray[i])
105 free_simple_loop_desc (loops->parray[i]);
107 /* Another dump. */
108 flow_loops_dump (loops, dumpfile, NULL, 1);
110 /* Clean up. */
111 flow_loops_free (loops);
112 free (loops);
114 /* Checking. */
115 #ifdef ENABLE_CHECKING
116 verify_flow_info ();
117 #endif