index.html (3.10): Add note about mips atomicity.h.
[official-gcc.git] / gcc / loop-init.c
blob6cae157e66dec9abce45d21774c3d6dc3a90c064
1 /* Loop optimizer initialization routines.
2 Copyright (C) 2002, 2003 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 (dumpfile)
35 FILE *dumpfile;
37 struct loops *loops = xcalloc (1, sizeof (struct loops));
38 edge e;
40 /* Avoid annoying special cases of edges going to exit
41 block. */
42 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
43 if ((e->flags & EDGE_FALLTHRU) && e->src->succ->succ_next)
44 split_edge (e);
46 /* Find the loops. */
48 if (flow_loops_find (loops, LOOP_TREE) <= 1)
50 /* No loops. */
51 flow_loops_free (loops);
52 free (loops);
53 return NULL;
56 /* Not going to update these. */
57 free (loops->cfg.rc_order);
58 loops->cfg.rc_order = NULL;
59 free (loops->cfg.dfs_order);
60 loops->cfg.dfs_order = NULL;
62 /* Initialize structures for layout changes. */
63 cfg_layout_initialize (loops);
65 /* Create pre-headers. */
66 create_preheaders (loops, CP_SIMPLE_PREHEADERS | CP_INSIDE_CFGLAYOUT);
68 /* Force all latches to have only single successor. */
69 force_single_succ_latches (loops);
71 /* Mark irreducible loops. */
72 mark_irreducible_loops (loops);
74 /* Dump loops. */
75 flow_loops_dump (loops, dumpfile, NULL, 1);
77 #ifdef ENABLE_CHECKING
78 verify_dominators (loops->cfg.dom);
79 verify_loop_structure (loops);
80 #endif
82 return loops;
85 /* Finalize loop optimizer. */
86 void
87 loop_optimizer_finalize (loops, dumpfile)
88 struct loops *loops;
89 FILE *dumpfile;
91 basic_block bb;
93 /* Finalize layout changes. */
94 /* Make chain. */
95 FOR_EACH_BB (bb)
96 if (bb->next_bb != EXIT_BLOCK_PTR)
97 RBI (bb)->next = bb->next_bb;
99 /* Another dump. */
100 flow_loops_dump (loops, dumpfile, NULL, 1);
102 /* Clean up. */
103 flow_loops_free (loops);
104 free (loops);
106 /* Finalize changes. */
107 cfg_layout_finalize ();
109 /* Checking. */
110 #ifdef ENABLE_CHECKING
111 verify_flow_info ();
112 #endif