OSDN Git Service

* config/sh/sh.c (sh_use_dfa_interface): Add TARGET_SH1.
[pf3gnuchains/gcc-fork.git] / gcc / loop-init.c
1 /* Loop optimizer initialization routines.
2    Copyright (C) 2002, 2003, 2004 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   static bool first_time = true;
39
40   if (first_time)
41     {
42       first_time = false;
43       init_set_costs ();
44     }
45
46   /* Avoid annoying special cases of edges going to exit
47      block.  */
48   for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
49     if ((e->flags & EDGE_FALLTHRU) && e->src->succ->succ_next)
50       split_edge (e);
51
52   /* Find the loops.  */
53
54   if (flow_loops_find (loops, LOOP_TREE) <= 1)
55     {
56       /* No loops.  */
57       flow_loops_free (loops);
58       free_dominance_info (CDI_DOMINATORS);
59       free (loops);
60
61       return NULL;
62     }
63
64   /* Not going to update these.  */
65   free (loops->cfg.rc_order);
66   loops->cfg.rc_order = NULL;
67   free (loops->cfg.dfs_order);
68   loops->cfg.dfs_order = NULL;
69
70   /* Create pre-headers.  */
71   create_preheaders (loops, CP_SIMPLE_PREHEADERS);
72
73   /* Force all latches to have only single successor.  */
74   force_single_succ_latches (loops);
75
76   /* Mark irreducible loops.  */
77   mark_irreducible_loops (loops);
78
79   /* Dump loops.  */
80   flow_loops_dump (loops, dumpfile, NULL, 1);
81
82 #ifdef ENABLE_CHECKING
83   verify_dominators (CDI_DOMINATORS);
84   verify_loop_structure (loops);
85 #endif
86
87   return loops;
88 }
89
90 /* Finalize loop optimizer.  */
91 void
92 loop_optimizer_finalize (struct loops *loops, FILE *dumpfile)
93 {
94   unsigned i;
95
96   if (!loops)
97     return;
98
99   for (i = 1; i < loops->num; i++)
100     if (loops->parray[i])
101       free_simple_loop_desc (loops->parray[i]);
102
103   /* Another dump.  */
104   flow_loops_dump (loops, dumpfile, NULL, 1);
105
106   /* Clean up.  */
107   flow_loops_free (loops);
108   free_dominance_info (CDI_DOMINATORS);
109   free (loops);
110
111   /* Checking.  */
112 #ifdef ENABLE_CHECKING
113   verify_flow_info ();
114 #endif
115 }