annotate gcc/tree-cfgcleanup.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* CFG cleanup for trees.
16
kono
parents: 14
diff changeset
2 Copyright (C) 2001-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 any later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 GNU General Public License for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "coretypes.h"
16
kono
parents: 14
diff changeset
23 #include "backend.h"
kono
parents: 14
diff changeset
24 #include "rtl.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "tree.h"
16
kono
parents: 14
diff changeset
26 #include "gimple.h"
kono
parents: 14
diff changeset
27 #include "cfghooks.h"
kono
parents: 14
diff changeset
28 #include "tree-pass.h"
kono
parents: 14
diff changeset
29 #include "ssa.h"
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
30 #include "diagnostic-core.h"
16
kono
parents: 14
diff changeset
31 #include "fold-const.h"
kono
parents: 14
diff changeset
32 #include "cfganal.h"
kono
parents: 14
diff changeset
33 #include "cfgcleanup.h"
kono
parents: 14
diff changeset
34 #include "tree-eh.h"
kono
parents: 14
diff changeset
35 #include "gimplify.h"
kono
parents: 14
diff changeset
36 #include "gimple-iterator.h"
kono
parents: 14
diff changeset
37 #include "tree-cfg.h"
kono
parents: 14
diff changeset
38 #include "tree-ssa-loop-manip.h"
kono
parents: 14
diff changeset
39 #include "tree-dfa.h"
kono
parents: 14
diff changeset
40 #include "tree-ssa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 #include "cfgloop.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 #include "tree-scalar-evolution.h"
16
kono
parents: 14
diff changeset
43 #include "gimple-match.h"
kono
parents: 14
diff changeset
44 #include "gimple-fold.h"
kono
parents: 14
diff changeset
45 #include "tree-ssa-loop-niter.h"
kono
parents: 14
diff changeset
46
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 /* The set of blocks in that at least one of the following changes happened:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 -- the statement at the end of the block was changed
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 -- the block was newly created
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 -- the set of the predecessors of the block changed
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 -- the set of the successors of the block changed
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 ??? Maybe we could track these changes separately, since they determine
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 what cleanups it makes sense to try on the block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 bitmap cfgcleanup_altered_bbs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 /* Remove any fallthru edge from EV. Return true if an edge was removed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 static bool
16
kono
parents: 14
diff changeset
60 remove_fallthru_edge (vec<edge, va_gc> *ev)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 FOR_EACH_EDGE (e, ei, ev)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 if ((e->flags & EDGE_FALLTHRU) != 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 {
16
kono
parents: 14
diff changeset
68 if (e->flags & EDGE_COMPLEX)
kono
parents: 14
diff changeset
69 e->flags &= ~EDGE_FALLTHRU;
kono
parents: 14
diff changeset
70 else
kono
parents: 14
diff changeset
71 remove_edge_and_dominated_blocks (e);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
16
kono
parents: 14
diff changeset
77 /* Convert a SWTCH with single non-default case to gcond and replace it
kono
parents: 14
diff changeset
78 at GSI. */
kono
parents: 14
diff changeset
79
kono
parents: 14
diff changeset
80 static bool
kono
parents: 14
diff changeset
81 convert_single_case_switch (gswitch *swtch, gimple_stmt_iterator &gsi)
kono
parents: 14
diff changeset
82 {
kono
parents: 14
diff changeset
83 if (gimple_switch_num_labels (swtch) != 2)
kono
parents: 14
diff changeset
84 return false;
kono
parents: 14
diff changeset
85
kono
parents: 14
diff changeset
86 tree index = gimple_switch_index (swtch);
kono
parents: 14
diff changeset
87 tree default_label = CASE_LABEL (gimple_switch_default_label (swtch));
kono
parents: 14
diff changeset
88 tree label = gimple_switch_label (swtch, 1);
kono
parents: 14
diff changeset
89 tree low = CASE_LOW (label);
kono
parents: 14
diff changeset
90 tree high = CASE_HIGH (label);
kono
parents: 14
diff changeset
91
kono
parents: 14
diff changeset
92 basic_block default_bb = label_to_block_fn (cfun, default_label);
kono
parents: 14
diff changeset
93 basic_block case_bb = label_to_block_fn (cfun, CASE_LABEL (label));
kono
parents: 14
diff changeset
94
kono
parents: 14
diff changeset
95 basic_block bb = gimple_bb (swtch);
kono
parents: 14
diff changeset
96 gcond *cond;
kono
parents: 14
diff changeset
97
kono
parents: 14
diff changeset
98 /* Replace switch statement with condition statement. */
kono
parents: 14
diff changeset
99 if (high)
kono
parents: 14
diff changeset
100 {
kono
parents: 14
diff changeset
101 tree lhs, rhs;
kono
parents: 14
diff changeset
102 generate_range_test (bb, index, low, high, &lhs, &rhs);
kono
parents: 14
diff changeset
103 cond = gimple_build_cond (LE_EXPR, lhs, rhs, NULL_TREE, NULL_TREE);
kono
parents: 14
diff changeset
104 }
kono
parents: 14
diff changeset
105 else
kono
parents: 14
diff changeset
106 cond = gimple_build_cond (EQ_EXPR, index,
kono
parents: 14
diff changeset
107 fold_convert (TREE_TYPE (index), low),
kono
parents: 14
diff changeset
108 NULL_TREE, NULL_TREE);
kono
parents: 14
diff changeset
109
kono
parents: 14
diff changeset
110 gsi_replace (&gsi, cond, true);
kono
parents: 14
diff changeset
111
kono
parents: 14
diff changeset
112 /* Update edges. */
kono
parents: 14
diff changeset
113 edge case_edge = find_edge (bb, case_bb);
kono
parents: 14
diff changeset
114 edge default_edge = find_edge (bb, default_bb);
kono
parents: 14
diff changeset
115
kono
parents: 14
diff changeset
116 case_edge->flags |= EDGE_TRUE_VALUE;
kono
parents: 14
diff changeset
117 default_edge->flags |= EDGE_FALSE_VALUE;
kono
parents: 14
diff changeset
118 return true;
kono
parents: 14
diff changeset
119 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 /* Disconnect an unreachable block in the control expression starting
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 at block BB. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 static bool
16
kono
parents: 14
diff changeset
125 cleanup_control_expr_graph (basic_block bb, gimple_stmt_iterator gsi,
kono
parents: 14
diff changeset
126 bool first_p)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 edge taken_edge;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 bool retval = false;
16
kono
parents: 14
diff changeset
130 gimple *stmt = gsi_stmt (gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 if (!single_succ_p (bb))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 bool warned;
16
kono
parents: 14
diff changeset
137 tree val = NULL_TREE;
kono
parents: 14
diff changeset
138
kono
parents: 14
diff changeset
139 /* Try to convert a switch with just a single non-default case to
kono
parents: 14
diff changeset
140 GIMPLE condition. */
kono
parents: 14
diff changeset
141 if (gimple_code (stmt) == GIMPLE_SWITCH
kono
parents: 14
diff changeset
142 && convert_single_case_switch (as_a<gswitch *> (stmt), gsi))
kono
parents: 14
diff changeset
143 stmt = gsi_stmt (gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 fold_defer_overflow_warnings ();
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
146 switch (gimple_code (stmt))
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
147 {
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
148 case GIMPLE_COND:
16
kono
parents: 14
diff changeset
149 /* During a first iteration on the CFG only remove trivially
kono
parents: 14
diff changeset
150 dead edges but mark other conditions for re-evaluation. */
kono
parents: 14
diff changeset
151 if (first_p)
kono
parents: 14
diff changeset
152 {
kono
parents: 14
diff changeset
153 val = const_binop (gimple_cond_code (stmt), boolean_type_node,
kono
parents: 14
diff changeset
154 gimple_cond_lhs (stmt),
kono
parents: 14
diff changeset
155 gimple_cond_rhs (stmt));
kono
parents: 14
diff changeset
156 if (! val)
kono
parents: 14
diff changeset
157 bitmap_set_bit (cfgcleanup_altered_bbs, bb->index);
kono
parents: 14
diff changeset
158 }
kono
parents: 14
diff changeset
159 else
kono
parents: 14
diff changeset
160 {
kono
parents: 14
diff changeset
161 code_helper rcode;
kono
parents: 14
diff changeset
162 tree ops[3] = {};
kono
parents: 14
diff changeset
163 if (gimple_simplify (stmt, &rcode, ops, NULL, no_follow_ssa_edges,
kono
parents: 14
diff changeset
164 no_follow_ssa_edges)
kono
parents: 14
diff changeset
165 && rcode == INTEGER_CST)
kono
parents: 14
diff changeset
166 val = ops[0];
kono
parents: 14
diff changeset
167 }
kono
parents: 14
diff changeset
168 break;
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
169
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
170 case GIMPLE_SWITCH:
16
kono
parents: 14
diff changeset
171 val = gimple_switch_index (as_a <gswitch *> (stmt));
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
172 break;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
173
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
174 default:
16
kono
parents: 14
diff changeset
175 ;
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
176 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 taken_edge = find_taken_edge (bb, val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 if (!taken_edge)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 fold_undefer_and_ignore_overflow_warnings ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 /* Remove all the edges except the one that is always executed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 warned = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 if (e != taken_edge)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 if (!warned)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 fold_undefer_overflow_warnings
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 (true, stmt, WARN_STRICT_OVERFLOW_CONDITIONAL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 warned = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 taken_edge->probability += e->probability;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 remove_edge_and_dominated_blocks (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 retval = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 ei_next (&ei);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 if (!warned)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 fold_undefer_and_ignore_overflow_warnings ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 taken_edge = single_succ_edge (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 bitmap_set_bit (cfgcleanup_altered_bbs, bb->index);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 gsi_remove (&gsi, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 taken_edge->flags = EDGE_FALLTHRU;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 return retval;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
16
kono
parents: 14
diff changeset
217 /* Cleanup the GF_CALL_CTRL_ALTERING flag according to
kono
parents: 14
diff changeset
218 to updated gimple_call_flags. */
kono
parents: 14
diff changeset
219
kono
parents: 14
diff changeset
220 static void
kono
parents: 14
diff changeset
221 cleanup_call_ctrl_altering_flag (gimple *bb_end)
kono
parents: 14
diff changeset
222 {
kono
parents: 14
diff changeset
223 if (!is_gimple_call (bb_end)
kono
parents: 14
diff changeset
224 || !gimple_call_ctrl_altering_p (bb_end))
kono
parents: 14
diff changeset
225 return;
kono
parents: 14
diff changeset
226
kono
parents: 14
diff changeset
227 int flags = gimple_call_flags (bb_end);
kono
parents: 14
diff changeset
228 if (((flags & (ECF_CONST | ECF_PURE))
kono
parents: 14
diff changeset
229 && !(flags & ECF_LOOPING_CONST_OR_PURE))
kono
parents: 14
diff changeset
230 || (flags & ECF_LEAF))
kono
parents: 14
diff changeset
231 gimple_call_set_ctrl_altering (bb_end, false);
kono
parents: 14
diff changeset
232 }
kono
parents: 14
diff changeset
233
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 /* Try to remove superfluous control structures in basic block BB. Returns
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 true if anything changes. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 static bool
16
kono
parents: 14
diff changeset
238 cleanup_control_flow_bb (basic_block bb, bool first_p)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 bool retval = false;
16
kono
parents: 14
diff changeset
242 gimple *stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 /* If the last statement of the block could throw and now cannot,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 we need to prune cfg. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 retval |= gimple_purge_dead_eh_edges (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247
16
kono
parents: 14
diff changeset
248 gsi = gsi_last_nondebug_bb (bb);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 if (gsi_end_p (gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 return retval;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 stmt = gsi_stmt (gsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253
16
kono
parents: 14
diff changeset
254 /* Try to cleanup ctrl altering flag for call which ends bb. */
kono
parents: 14
diff changeset
255 cleanup_call_ctrl_altering_flag (stmt);
kono
parents: 14
diff changeset
256
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 if (gimple_code (stmt) == GIMPLE_COND
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 || gimple_code (stmt) == GIMPLE_SWITCH)
16
kono
parents: 14
diff changeset
259 {
kono
parents: 14
diff changeset
260 gcc_checking_assert (gsi_stmt (gsi_last_bb (bb)) == stmt);
kono
parents: 14
diff changeset
261 retval |= cleanup_control_expr_graph (bb, gsi, first_p);
kono
parents: 14
diff changeset
262 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 else if (gimple_code (stmt) == GIMPLE_GOTO
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 && TREE_CODE (gimple_goto_dest (stmt)) == ADDR_EXPR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 && (TREE_CODE (TREE_OPERAND (gimple_goto_dest (stmt), 0))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 == LABEL_DECL))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 /* If we had a computed goto which has a compile-time determinable
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 destination, then we can eliminate the goto. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 tree label;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 basic_block target_block;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
16
kono
parents: 14
diff changeset
275 gcc_checking_assert (gsi_stmt (gsi_last_bb (bb)) == stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 /* First look at all the outgoing edges. Delete any outgoing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 edges which do not go to the right block. For the one
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 edge which goes to the right block, fix up its flags. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 label = TREE_OPERAND (gimple_goto_dest (stmt), 0);
16
kono
parents: 14
diff changeset
280 if (DECL_CONTEXT (label) != cfun->decl)
kono
parents: 14
diff changeset
281 return retval;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 target_block = label_to_block (label);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 if (e->dest != target_block)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 remove_edge_and_dominated_blocks (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 /* Turn off the EDGE_ABNORMAL flag. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 e->flags &= ~EDGE_ABNORMAL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 /* And set EDGE_FALLTHRU. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 e->flags |= EDGE_FALLTHRU;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 ei_next (&ei);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 bitmap_set_bit (cfgcleanup_altered_bbs, bb->index);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 bitmap_set_bit (cfgcleanup_altered_bbs, target_block->index);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 /* Remove the GOTO_EXPR as it is not needed. The CFG has all the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 relevant information we need. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 gsi_remove (&gsi, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 retval = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 /* Check for indirect calls that have been turned into
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 noreturn calls. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 else if (is_gimple_call (stmt)
16
kono
parents: 14
diff changeset
310 && gimple_call_noreturn_p (stmt))
kono
parents: 14
diff changeset
311 {
kono
parents: 14
diff changeset
312 /* If there are debug stmts after the noreturn call, remove them
kono
parents: 14
diff changeset
313 now, they should be all unreachable anyway. */
kono
parents: 14
diff changeset
314 for (gsi_next (&gsi); !gsi_end_p (gsi); )
kono
parents: 14
diff changeset
315 gsi_remove (&gsi, true);
kono
parents: 14
diff changeset
316 if (remove_fallthru_edge (bb->succs))
kono
parents: 14
diff changeset
317 retval = true;
kono
parents: 14
diff changeset
318 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 return retval;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 /* Return true if basic block BB does nothing except pass control
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 flow to another block and that we can safely insert a label at
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 the start of the successor block.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 As a precondition, we require that BB be not equal to
16
kono
parents: 14
diff changeset
328 the entry block. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 tree_forwarder_block_p (basic_block bb, bool phi_wanted)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 gimple_stmt_iterator gsi;
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
334 location_t locus;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 /* BB must have a single outgoing edge. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 if (single_succ_p (bb) != 1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 /* If PHI_WANTED is false, BB must not have any PHI nodes.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 Otherwise, BB must have PHI nodes. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 || gimple_seq_empty_p (phi_nodes (bb)) == phi_wanted
16
kono
parents: 14
diff changeset
341 /* BB may not be a predecessor of the exit block. */
kono
parents: 14
diff changeset
342 || single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 /* Nor should this be an infinite loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 || single_succ (bb) == bb
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 /* BB may not have an abnormal outgoing edge. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 || (single_succ_edge (bb)->flags & EDGE_ABNORMAL))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348
16
kono
parents: 14
diff changeset
349 gcc_checking_assert (bb != ENTRY_BLOCK_PTR_FOR_FN (cfun));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
351 locus = single_succ_edge (bb)->goto_locus;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
352
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
353 /* There should not be an edge coming from entry, or an EH edge. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
354 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
355 edge_iterator ei;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
356 edge e;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
357
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
358 FOR_EACH_EDGE (e, ei, bb->preds)
16
kono
parents: 14
diff changeset
359 if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun) || (e->flags & EDGE_EH))
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
360 return false;
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
361 /* If goto_locus of any of the edges differs, prevent removing
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
362 the forwarder block for -O0. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
363 else if (optimize == 0 && e->goto_locus != locus)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
364 return false;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
365 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
366
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 /* Now walk through the statements backward. We can ignore labels,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 anything else means this is not a forwarder block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 {
16
kono
parents: 14
diff changeset
371 gimple *stmt = gsi_stmt (gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 switch (gimple_code (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 case GIMPLE_LABEL:
16
kono
parents: 14
diff changeset
376 if (DECL_NONLOCAL (gimple_label_label (as_a <glabel *> (stmt))))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 return false;
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
378 if (optimize == 0 && gimple_location (stmt) != locus)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
379 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
382 /* ??? For now, hope there's a corresponding debug
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
383 assignment at the destination. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
384 case GIMPLE_DEBUG:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
385 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
386
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 if (current_loops)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 basic_block dest;
16
kono
parents: 14
diff changeset
395 /* Protect loop headers. */
kono
parents: 14
diff changeset
396 if (bb_loop_header_p (bb))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 return false;
16
kono
parents: 14
diff changeset
398
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 dest = EDGE_SUCC (bb, 0)->dest;
16
kono
parents: 14
diff changeset
400 /* Protect loop preheaders and latches if requested. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 if (dest->loop_father->header == dest)
16
kono
parents: 14
diff changeset
402 {
kono
parents: 14
diff changeset
403 if (bb->loop_father == dest->loop_father)
kono
parents: 14
diff changeset
404 {
kono
parents: 14
diff changeset
405 if (loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES))
kono
parents: 14
diff changeset
406 return false;
kono
parents: 14
diff changeset
407 /* If bb doesn't have a single predecessor we'd make this
kono
parents: 14
diff changeset
408 loop have multiple latches. Don't do that if that
kono
parents: 14
diff changeset
409 would in turn require disambiguating them. */
kono
parents: 14
diff changeset
410 return (single_pred_p (bb)
kono
parents: 14
diff changeset
411 || loops_state_satisfies_p
kono
parents: 14
diff changeset
412 (LOOPS_MAY_HAVE_MULTIPLE_LATCHES));
kono
parents: 14
diff changeset
413 }
kono
parents: 14
diff changeset
414 else if (bb->loop_father == loop_outer (dest->loop_father))
kono
parents: 14
diff changeset
415 return !loops_state_satisfies_p (LOOPS_HAVE_PREHEADERS);
kono
parents: 14
diff changeset
416 /* Always preserve other edges into loop headers that are
kono
parents: 14
diff changeset
417 not simple latches or preheaders. */
kono
parents: 14
diff changeset
418 return false;
kono
parents: 14
diff changeset
419 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 }
16
kono
parents: 14
diff changeset
421
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 /* If all the PHI nodes in DEST have alternatives for E1 and E2 and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 those alternatives are equal in each of the PHI nodes, then return
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 true, else return false. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 phi_alternatives_equal (basic_block dest, edge e1, edge e2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 int n1 = e1->dest_idx;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 int n2 = e2->dest_idx;
16
kono
parents: 14
diff changeset
434 gphi_iterator gsi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 for (gsi = gsi_start_phis (dest); !gsi_end_p (gsi); gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 {
16
kono
parents: 14
diff changeset
438 gphi *phi = gsi.phi ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 tree val1 = gimple_phi_arg_def (phi, n1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 tree val2 = gimple_phi_arg_def (phi, n2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 gcc_assert (val1 != NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 gcc_assert (val2 != NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 if (!operand_equal_for_phi_arg_p (val1, val2))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 /* Removes forwarder block BB. Returns false if this failed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 remove_forwarder_block (basic_block bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 edge succ = single_succ_edge (bb), e, s;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 basic_block dest = succ->dest;
16
kono
parents: 14
diff changeset
459 gimple *label;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 gimple_stmt_iterator gsi, gsi_to;
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
462 bool can_move_debug_stmts;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 /* We check for infinite loops already in tree_forwarder_block_p.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 However it may happen that the infinite loop is created
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 afterwards due to removal of forwarders. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 if (dest == bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
470 /* If the destination block consists of a nonlocal label or is a
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
471 EH landing pad, do not merge it. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 label = first_stmt (dest);
16
kono
parents: 14
diff changeset
473 if (label)
kono
parents: 14
diff changeset
474 if (glabel *label_stmt = dyn_cast <glabel *> (label))
kono
parents: 14
diff changeset
475 if (DECL_NONLOCAL (gimple_label_label (label_stmt))
kono
parents: 14
diff changeset
476 || EH_LANDING_PAD_NR (gimple_label_label (label_stmt)) != 0)
kono
parents: 14
diff changeset
477 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 /* If there is an abnormal edge to basic block BB, but not into
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 dest, problems might occur during removal of the phi node at out
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 of ssa due to overlapping live ranges of registers.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 If there is an abnormal edge in DEST, the problems would occur
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 anyway since cleanup_dead_labels would then merge the labels for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 two different eh regions, and rest of exception handling code
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 does not like it.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 So if there is an abnormal edge to BB, proceed only if there is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 no abnormal edge to DEST and there are no phi nodes in DEST. */
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
490 if (bb_has_abnormal_pred (bb)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
491 && (bb_has_abnormal_pred (dest)
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
492 || !gimple_seq_empty_p (phi_nodes (dest))))
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
493 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 /* If there are phi nodes in DEST, and some of the blocks that are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 predecessors of BB are also predecessors of DEST, check that the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 phi node arguments match. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 if (!gimple_seq_empty_p (phi_nodes (dest)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 FOR_EACH_EDGE (e, ei, bb->preds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 s = find_edge (e->src, dest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 if (!s)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 if (!phi_alternatives_equal (dest, succ, s))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510
16
kono
parents: 14
diff changeset
511 can_move_debug_stmts = MAY_HAVE_DEBUG_STMTS && single_pred_p (dest);
kono
parents: 14
diff changeset
512
kono
parents: 14
diff changeset
513 basic_block pred = NULL;
kono
parents: 14
diff changeset
514 if (single_pred_p (bb))
kono
parents: 14
diff changeset
515 pred = single_pred (bb);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
516
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 /* Redirect the edges. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); )
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 bitmap_set_bit (cfgcleanup_altered_bbs, e->src->index);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 if (e->flags & EDGE_ABNORMAL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 /* If there is an abnormal edge, redirect it anyway, and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 move the labels to the new block to make it legal. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 s = redirect_edge_succ_nodup (e, dest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 s = redirect_edge_and_branch (e, dest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 if (s == e)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 /* Create arguments for the phi nodes, since the edge was not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 here before. */
16
kono
parents: 14
diff changeset
535 for (gphi_iterator psi = gsi_start_phis (dest);
kono
parents: 14
diff changeset
536 !gsi_end_p (psi);
kono
parents: 14
diff changeset
537 gsi_next (&psi))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 {
16
kono
parents: 14
diff changeset
539 gphi *phi = psi.phi ();
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
540 source_location l = gimple_phi_arg_location_from_edge (phi, succ);
16
kono
parents: 14
diff changeset
541 tree def = gimple_phi_arg_def (phi, succ->dest_idx);
kono
parents: 14
diff changeset
542 add_phi_arg (phi, unshare_expr (def), s, l);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
547 /* Move nonlocal labels and computed goto targets as well as user
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
548 defined labels and labels with an EH landing pad number to the
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
549 new block, so that the redirection of the abnormal edges works,
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
550 jump targets end up in a sane place and debug information for
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
551 labels is retained. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
552 gsi_to = gsi_start_bb (dest);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
553 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); )
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 {
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
555 tree decl;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
556 label = gsi_stmt (gsi);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
557 if (is_gimple_debug (label))
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
558 break;
16
kono
parents: 14
diff changeset
559 decl = gimple_label_label (as_a <glabel *> (label));
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
560 if (EH_LANDING_PAD_NR (decl) != 0
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
561 || DECL_NONLOCAL (decl)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
562 || FORCED_LABEL (decl)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
563 || !DECL_ARTIFICIAL (decl))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 gsi_remove (&gsi, false);
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
566 gsi_insert_before (&gsi_to, label, GSI_SAME_STMT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 }
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
568 else
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
569 gsi_next (&gsi);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
570 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
571
16
kono
parents: 14
diff changeset
572 /* Move debug statements if the destination has a single predecessor. */
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
573 if (can_move_debug_stmts)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
574 {
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
575 gsi_to = gsi_after_labels (dest);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
576 for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); )
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
577 {
16
kono
parents: 14
diff changeset
578 gimple *debug = gsi_stmt (gsi);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
579 if (!is_gimple_debug (debug))
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
580 break;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
581 gsi_remove (&gsi, false);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
582 gsi_insert_before (&gsi_to, debug, GSI_SAME_STMT);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
583 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 bitmap_set_bit (cfgcleanup_altered_bbs, dest->index);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 /* Update the dominators. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 if (dom_info_available_p (CDI_DOMINATORS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 basic_block dom, dombb, domdest;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 dombb = get_immediate_dominator (CDI_DOMINATORS, bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 domdest = get_immediate_dominator (CDI_DOMINATORS, dest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 if (domdest == bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 /* Shortcut to avoid calling (relatively expensive)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 nearest_common_dominator unless necessary. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 dom = dombb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 dom = nearest_common_dominator (CDI_DOMINATORS, domdest, dombb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 set_immediate_dominator (CDI_DOMINATORS, dest, dom);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606
16
kono
parents: 14
diff changeset
607 /* Adjust latch infomation of BB's parent loop as otherwise
kono
parents: 14
diff changeset
608 the cfg hook has a hard time not to kill the loop. */
kono
parents: 14
diff changeset
609 if (current_loops && bb->loop_father->latch == bb)
kono
parents: 14
diff changeset
610 bb->loop_father->latch = pred;
kono
parents: 14
diff changeset
611
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 /* And kill the forwarder block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 delete_basic_block (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617
16
kono
parents: 14
diff changeset
618 /* STMT is a call that has been discovered noreturn. Split the
kono
parents: 14
diff changeset
619 block to prepare fixing up the CFG and remove LHS.
kono
parents: 14
diff changeset
620 Return true if cleanup-cfg needs to run. */
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
621
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
622 bool
16
kono
parents: 14
diff changeset
623 fixup_noreturn_call (gimple *stmt)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
624 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
625 basic_block bb = gimple_bb (stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
626 bool changed = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
627
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
628 if (gimple_call_builtin_p (stmt, BUILT_IN_RETURN))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
629 return false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
630
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
631 /* First split basic block if stmt is not last. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
632 if (stmt != gsi_stmt (gsi_last_bb (bb)))
16
kono
parents: 14
diff changeset
633 {
kono
parents: 14
diff changeset
634 if (stmt == gsi_stmt (gsi_last_nondebug_bb (bb)))
kono
parents: 14
diff changeset
635 {
kono
parents: 14
diff changeset
636 /* Don't split if there are only debug stmts
kono
parents: 14
diff changeset
637 after stmt, that can result in -fcompare-debug
kono
parents: 14
diff changeset
638 failures. Remove the debug stmts instead,
kono
parents: 14
diff changeset
639 they should be all unreachable anyway. */
kono
parents: 14
diff changeset
640 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
kono
parents: 14
diff changeset
641 for (gsi_next (&gsi); !gsi_end_p (gsi); )
kono
parents: 14
diff changeset
642 gsi_remove (&gsi, true);
kono
parents: 14
diff changeset
643 }
kono
parents: 14
diff changeset
644 else
kono
parents: 14
diff changeset
645 {
kono
parents: 14
diff changeset
646 split_block (bb, stmt);
kono
parents: 14
diff changeset
647 changed = true;
kono
parents: 14
diff changeset
648 }
kono
parents: 14
diff changeset
649 }
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
650
16
kono
parents: 14
diff changeset
651 /* If there is an LHS, remove it, but only if its type has fixed size.
kono
parents: 14
diff changeset
652 The LHS will need to be recreated during RTL expansion and creating
kono
parents: 14
diff changeset
653 temporaries of variable-sized types is not supported. Also don't
kono
parents: 14
diff changeset
654 do this with TREE_ADDRESSABLE types, as assign_temp will abort.
kono
parents: 14
diff changeset
655 Drop LHS regardless of TREE_ADDRESSABLE, if the function call
kono
parents: 14
diff changeset
656 has been changed into a call that does not return a value, like
kono
parents: 14
diff changeset
657 __builtin_unreachable or __cxa_pure_virtual. */
kono
parents: 14
diff changeset
658 tree lhs = gimple_call_lhs (stmt);
kono
parents: 14
diff changeset
659 if (lhs
kono
parents: 14
diff changeset
660 && (should_remove_lhs_p (lhs)
kono
parents: 14
diff changeset
661 || VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (stmt)))))
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
662 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
663 gimple_call_set_lhs (stmt, NULL_TREE);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
664
16
kono
parents: 14
diff changeset
665 /* We need to fix up the SSA name to avoid checking errors. */
kono
parents: 14
diff changeset
666 if (TREE_CODE (lhs) == SSA_NAME)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
667 {
16
kono
parents: 14
diff changeset
668 tree new_var = create_tmp_reg (TREE_TYPE (lhs));
kono
parents: 14
diff changeset
669 SET_SSA_NAME_VAR_OR_IDENTIFIER (lhs, new_var);
kono
parents: 14
diff changeset
670 SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();
kono
parents: 14
diff changeset
671 set_ssa_default_def (cfun, new_var, lhs);
kono
parents: 14
diff changeset
672 }
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
673
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
674 update_stmt (stmt);
16
kono
parents: 14
diff changeset
675 }
kono
parents: 14
diff changeset
676
kono
parents: 14
diff changeset
677 /* Mark the call as altering control flow. */
kono
parents: 14
diff changeset
678 if (!gimple_call_ctrl_altering_p (stmt))
kono
parents: 14
diff changeset
679 {
kono
parents: 14
diff changeset
680 gimple_call_set_ctrl_altering (stmt, true);
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
681 changed = true;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
682 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 return changed;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686
16
kono
parents: 14
diff changeset
687 /* Return true if we want to merge BB1 and BB2 into a single block. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 static bool
16
kono
parents: 14
diff changeset
690 want_merge_blocks_p (basic_block bb1, basic_block bb2)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 {
16
kono
parents: 14
diff changeset
692 if (!can_merge_blocks_p (bb1, bb2))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 return false;
16
kono
parents: 14
diff changeset
694 gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb1);
kono
parents: 14
diff changeset
695 if (gsi_end_p (gsi) || !stmt_can_terminate_bb_p (gsi_stmt (gsi)))
kono
parents: 14
diff changeset
696 return true;
kono
parents: 14
diff changeset
697 return bb1->count.ok_for_merging (bb2->count);
kono
parents: 14
diff changeset
698 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 /* Tries to cleanup cfg in basic block BB. Returns true if anything
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 changes. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 cleanup_tree_cfg_bb (basic_block bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 {
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
707 if (tree_forwarder_block_p (bb, false)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 && remove_forwarder_block (bb))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710
16
kono
parents: 14
diff changeset
711 /* If there is a merge opportunity with the predecessor
kono
parents: 14
diff changeset
712 do nothing now but wait until we process the predecessor.
kono
parents: 14
diff changeset
713 This happens when we visit BBs in a non-optimal order and
kono
parents: 14
diff changeset
714 avoids quadratic behavior with adjusting stmts BB pointer. */
kono
parents: 14
diff changeset
715 if (single_pred_p (bb)
kono
parents: 14
diff changeset
716 && want_merge_blocks_p (single_pred (bb), bb))
kono
parents: 14
diff changeset
717 /* But make sure we _do_ visit it. When we remove unreachable paths
kono
parents: 14
diff changeset
718 ending in a backedge we fail to mark the destinations predecessors
kono
parents: 14
diff changeset
719 as changed. */
kono
parents: 14
diff changeset
720 bitmap_set_bit (cfgcleanup_altered_bbs, single_pred (bb)->index);
kono
parents: 14
diff changeset
721
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 /* Merging the blocks may create new opportunities for folding
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 conditional branches (due to the elimination of single-valued PHI
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 nodes). */
16
kono
parents: 14
diff changeset
725 else if (single_succ_p (bb)
kono
parents: 14
diff changeset
726 && want_merge_blocks_p (bb, single_succ (bb)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 merge_blocks (bb, single_succ (bb));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731
16
kono
parents: 14
diff changeset
732 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 /* Iterate the cfg cleanups, while anything changes. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 cleanup_tree_cfg_1 (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 bool retval = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 unsigned i, n;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 /* Prepare the worklists of altered blocks. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 cfgcleanup_altered_bbs = BITMAP_ALLOC (NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 /* During forwarder block cleanup, we may redirect edges out of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 SWITCH_EXPRs, which can get expensive. So we want to enable
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 recording of edge to CASE_LABEL_EXPR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 start_recording_case_labels ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751
16
kono
parents: 14
diff changeset
752 /* We cannot use FOR_EACH_BB_FN for the BB iterations below
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 since the basic blocks may get removed. */
16
kono
parents: 14
diff changeset
754
kono
parents: 14
diff changeset
755 /* Start by iterating over all basic blocks looking for edge removal
kono
parents: 14
diff changeset
756 opportunities. Do this first because incoming SSA form may be
kono
parents: 14
diff changeset
757 invalid and we want to avoid performing SSA related tasks such
kono
parents: 14
diff changeset
758 as propgating out a PHI node during BB merging in that state. */
kono
parents: 14
diff changeset
759 n = last_basic_block_for_fn (cfun);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 for (i = NUM_FIXED_BLOCKS; i < n; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 {
16
kono
parents: 14
diff changeset
762 bb = BASIC_BLOCK_FOR_FN (cfun, i);
kono
parents: 14
diff changeset
763 if (bb)
kono
parents: 14
diff changeset
764 retval |= cleanup_control_flow_bb (bb, true);
kono
parents: 14
diff changeset
765 }
kono
parents: 14
diff changeset
766
kono
parents: 14
diff changeset
767 /* After doing the above SSA form should be valid (or an update SSA
kono
parents: 14
diff changeset
768 should be required). */
kono
parents: 14
diff changeset
769
kono
parents: 14
diff changeset
770 /* Continue by iterating over all basic blocks looking for BB merging
kono
parents: 14
diff changeset
771 opportunities. */
kono
parents: 14
diff changeset
772 n = last_basic_block_for_fn (cfun);
kono
parents: 14
diff changeset
773 for (i = NUM_FIXED_BLOCKS; i < n; i++)
kono
parents: 14
diff changeset
774 {
kono
parents: 14
diff changeset
775 bb = BASIC_BLOCK_FOR_FN (cfun, i);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 if (bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 retval |= cleanup_tree_cfg_bb (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 /* Now process the altered blocks, as long as any are available. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 while (!bitmap_empty_p (cfgcleanup_altered_bbs))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 i = bitmap_first_set_bit (cfgcleanup_altered_bbs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 bitmap_clear_bit (cfgcleanup_altered_bbs, i);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 if (i < NUM_FIXED_BLOCKS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787
16
kono
parents: 14
diff changeset
788 bb = BASIC_BLOCK_FOR_FN (cfun, i);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 if (!bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791
16
kono
parents: 14
diff changeset
792 retval |= cleanup_control_flow_bb (bb, false);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 retval |= cleanup_tree_cfg_bb (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 }
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
795
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 end_recording_case_labels ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 BITMAP_FREE (cfgcleanup_altered_bbs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 return retval;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800
16
kono
parents: 14
diff changeset
801 static bool
kono
parents: 14
diff changeset
802 mfb_keep_latches (edge e)
kono
parents: 14
diff changeset
803 {
kono
parents: 14
diff changeset
804 return ! dominated_by_p (CDI_DOMINATORS, e->src, e->dest);
kono
parents: 14
diff changeset
805 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 /* Remove unreachable blocks and other miscellaneous clean up work.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 Return true if the flowgraph was modified, false otherwise. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 cleanup_tree_cfg_noloop (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 bool changed;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 timevar_push (TV_TREE_CLEANUP_CFG);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
816
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 /* Iterate until there are no more cleanups left to do. If any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 iteration changed the flowgraph, set CHANGED to true.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
819
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 If dominance information is available, there cannot be any unreachable
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 blocks. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 if (!dom_info_available_p (CDI_DOMINATORS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 changed = delete_unreachable_blocks ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 calculate_dominance_info (CDI_DOMINATORS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828 {
16
kono
parents: 14
diff changeset
829 checking_verify_dominators (CDI_DOMINATORS);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 changed = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832
16
kono
parents: 14
diff changeset
833 /* Ensure that we have single entries into loop headers. Otherwise
kono
parents: 14
diff changeset
834 if one of the entries is becoming a latch due to CFG cleanup
kono
parents: 14
diff changeset
835 (from formerly being part of an irreducible region) then we mess
kono
parents: 14
diff changeset
836 up loop fixup and associate the old loop with a different region
kono
parents: 14
diff changeset
837 which makes niter upper bounds invalid. See for example PR80549.
kono
parents: 14
diff changeset
838 This needs to be done before we remove trivially dead edges as
kono
parents: 14
diff changeset
839 we need to capture the dominance state before the pending transform. */
kono
parents: 14
diff changeset
840 if (current_loops)
kono
parents: 14
diff changeset
841 {
kono
parents: 14
diff changeset
842 loop_p loop;
kono
parents: 14
diff changeset
843 unsigned i;
kono
parents: 14
diff changeset
844 FOR_EACH_VEC_ELT (*get_loops (cfun), i, loop)
kono
parents: 14
diff changeset
845 if (loop && loop->header)
kono
parents: 14
diff changeset
846 {
kono
parents: 14
diff changeset
847 basic_block bb = loop->header;
kono
parents: 14
diff changeset
848 edge_iterator ei;
kono
parents: 14
diff changeset
849 edge e;
kono
parents: 14
diff changeset
850 bool found_latch = false;
kono
parents: 14
diff changeset
851 bool any_abnormal = false;
kono
parents: 14
diff changeset
852 unsigned n = 0;
kono
parents: 14
diff changeset
853 /* We are only interested in preserving existing loops, but
kono
parents: 14
diff changeset
854 we need to check whether they are still real and of course
kono
parents: 14
diff changeset
855 if we need to add a preheader at all. */
kono
parents: 14
diff changeset
856 FOR_EACH_EDGE (e, ei, bb->preds)
kono
parents: 14
diff changeset
857 {
kono
parents: 14
diff changeset
858 if (e->flags & EDGE_ABNORMAL)
kono
parents: 14
diff changeset
859 {
kono
parents: 14
diff changeset
860 any_abnormal = true;
kono
parents: 14
diff changeset
861 break;
kono
parents: 14
diff changeset
862 }
kono
parents: 14
diff changeset
863 if (dominated_by_p (CDI_DOMINATORS, e->src, bb))
kono
parents: 14
diff changeset
864 {
kono
parents: 14
diff changeset
865 found_latch = true;
kono
parents: 14
diff changeset
866 continue;
kono
parents: 14
diff changeset
867 }
kono
parents: 14
diff changeset
868 n++;
kono
parents: 14
diff changeset
869 }
kono
parents: 14
diff changeset
870 /* If we have more than one entry to the loop header
kono
parents: 14
diff changeset
871 create a forwarder. */
kono
parents: 14
diff changeset
872 if (found_latch && ! any_abnormal && n > 1)
kono
parents: 14
diff changeset
873 {
kono
parents: 14
diff changeset
874 edge fallthru = make_forwarder_block (bb, mfb_keep_latches,
kono
parents: 14
diff changeset
875 NULL);
kono
parents: 14
diff changeset
876 loop->header = fallthru->dest;
kono
parents: 14
diff changeset
877 if (! loops_state_satisfies_p (LOOPS_NEED_FIXUP))
kono
parents: 14
diff changeset
878 {
kono
parents: 14
diff changeset
879 /* The loop updating from the CFG hook is incomplete
kono
parents: 14
diff changeset
880 when we have multiple latches, fixup manually. */
kono
parents: 14
diff changeset
881 remove_bb_from_loops (fallthru->src);
kono
parents: 14
diff changeset
882 loop_p cloop = loop;
kono
parents: 14
diff changeset
883 FOR_EACH_EDGE (e, ei, fallthru->src->preds)
kono
parents: 14
diff changeset
884 cloop = find_common_loop (cloop, e->src->loop_father);
kono
parents: 14
diff changeset
885 add_bb_to_loop (fallthru->src, cloop);
kono
parents: 14
diff changeset
886 }
kono
parents: 14
diff changeset
887 }
kono
parents: 14
diff changeset
888 }
kono
parents: 14
diff changeset
889 }
kono
parents: 14
diff changeset
890
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
891 changed |= cleanup_tree_cfg_1 ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
893 gcc_assert (dom_info_available_p (CDI_DOMINATORS));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894
16
kono
parents: 14
diff changeset
895 /* Do not renumber blocks if the SCEV cache is active, it is indexed by
kono
parents: 14
diff changeset
896 basic-block numbers. */
kono
parents: 14
diff changeset
897 if (! scev_initialized_p ())
kono
parents: 14
diff changeset
898 compact_blocks ();
kono
parents: 14
diff changeset
899
kono
parents: 14
diff changeset
900 checking_verify_flow_info ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
901
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
902 timevar_pop (TV_TREE_CLEANUP_CFG);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
903
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 if (changed && current_loops)
16
kono
parents: 14
diff changeset
905 {
kono
parents: 14
diff changeset
906 /* Removing edges and/or blocks may make recorded bounds refer
kono
parents: 14
diff changeset
907 to stale GIMPLE stmts now, so clear them. */
kono
parents: 14
diff changeset
908 free_numbers_of_iterations_estimates (cfun);
kono
parents: 14
diff changeset
909 loops_state_set (LOOPS_NEED_FIXUP);
kono
parents: 14
diff changeset
910 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 return changed;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
913 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 /* Repairs loop structures. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 repair_loop_structures (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 {
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
920 bitmap changed_bbs;
16
kono
parents: 14
diff changeset
921 unsigned n_new_loops;
kono
parents: 14
diff changeset
922
kono
parents: 14
diff changeset
923 calculate_dominance_info (CDI_DOMINATORS);
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
924
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
925 timevar_push (TV_REPAIR_LOOPS);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
926 changed_bbs = BITMAP_ALLOC (NULL);
16
kono
parents: 14
diff changeset
927 n_new_loops = fix_loop_structure (changed_bbs);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929 /* This usually does nothing. But sometimes parts of cfg that originally
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
930 were inside a loop get out of it due to edge removal (since they
16
kono
parents: 14
diff changeset
931 become unreachable by back edges from latch). Also a former
kono
parents: 14
diff changeset
932 irreducible loop can become reducible - in this case force a full
kono
parents: 14
diff changeset
933 rewrite into loop-closed SSA form. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934 if (loops_state_satisfies_p (LOOP_CLOSED_SSA))
16
kono
parents: 14
diff changeset
935 rewrite_into_loop_closed_ssa (n_new_loops ? NULL : changed_bbs,
kono
parents: 14
diff changeset
936 TODO_update_ssa);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 BITMAP_FREE (changed_bbs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939
16
kono
parents: 14
diff changeset
940 checking_verify_loop_structure ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941 scev_reset ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
943 timevar_pop (TV_REPAIR_LOOPS);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
944 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
945
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
946 /* Cleanup cfg and repair loop structures. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
947
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 cleanup_tree_cfg (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
950 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
951 bool changed = cleanup_tree_cfg_noloop ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
952
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 if (current_loops != NULL
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 && loops_state_satisfies_p (LOOPS_NEED_FIXUP))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 repair_loop_structures ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 return changed;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959
16
kono
parents: 14
diff changeset
960 /* Tries to merge the PHI nodes at BB into those at BB's sole successor.
kono
parents: 14
diff changeset
961 Returns true if successful. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962
16
kono
parents: 14
diff changeset
963 static bool
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
964 remove_forwarder_block_with_phi (basic_block bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
966 edge succ = single_succ_edge (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
967 basic_block dest = succ->dest;
16
kono
parents: 14
diff changeset
968 gimple *label;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969 basic_block dombb, domdest, dom;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
970
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971 /* We check for infinite loops already in tree_forwarder_block_p.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 However it may happen that the infinite loop is created
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
973 afterwards due to removal of forwarders. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 if (dest == bb)
16
kono
parents: 14
diff changeset
975 return false;
kono
parents: 14
diff changeset
976
kono
parents: 14
diff changeset
977 /* Removal of forwarders may expose new natural loops and thus
kono
parents: 14
diff changeset
978 a block may turn into a loop header. */
kono
parents: 14
diff changeset
979 if (current_loops && bb_loop_header_p (bb))
kono
parents: 14
diff changeset
980 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
981
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
982 /* If the destination block consists of a nonlocal label, do not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983 merge it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 label = first_stmt (dest);
16
kono
parents: 14
diff changeset
985 if (label)
kono
parents: 14
diff changeset
986 if (glabel *label_stmt = dyn_cast <glabel *> (label))
kono
parents: 14
diff changeset
987 if (DECL_NONLOCAL (gimple_label_label (label_stmt)))
kono
parents: 14
diff changeset
988 return false;
kono
parents: 14
diff changeset
989
kono
parents: 14
diff changeset
990 /* Record BB's single pred in case we need to update the father
kono
parents: 14
diff changeset
991 loop's latch information later. */
kono
parents: 14
diff changeset
992 basic_block pred = NULL;
kono
parents: 14
diff changeset
993 if (single_pred_p (bb))
kono
parents: 14
diff changeset
994 pred = single_pred (bb);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 /* Redirect each incoming edge to BB to DEST. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 while (EDGE_COUNT (bb->preds) > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
999 edge e = EDGE_PRED (bb, 0), s;
16
kono
parents: 14
diff changeset
1000 gphi_iterator gsi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 s = find_edge (e->src, dest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 if (s)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005 /* We already have an edge S from E->src to DEST. If S and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 E->dest's sole successor edge have the same PHI arguments
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1007 at DEST, redirect S to DEST. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1008 if (phi_alternatives_equal (dest, s, succ))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1009 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010 e = redirect_edge_and_branch (e, dest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011 redirect_edge_var_map_clear (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1014
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015 /* PHI arguments are different. Create a forwarder block by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 splitting E so that we can merge PHI arguments on E to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017 DEST. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1018 e = single_succ_edge (split_edge (e));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019 }
16
kono
parents: 14
diff changeset
1020 else
kono
parents: 14
diff changeset
1021 {
kono
parents: 14
diff changeset
1022 /* If we merge the forwarder into a loop header verify if we
kono
parents: 14
diff changeset
1023 are creating another loop latch edge. If so, reset
kono
parents: 14
diff changeset
1024 number of iteration information of the loop. */
kono
parents: 14
diff changeset
1025 if (dest->loop_father->header == dest
kono
parents: 14
diff changeset
1026 && dominated_by_p (CDI_DOMINATORS, e->src, dest))
kono
parents: 14
diff changeset
1027 {
kono
parents: 14
diff changeset
1028 dest->loop_father->any_upper_bound = false;
kono
parents: 14
diff changeset
1029 dest->loop_father->any_likely_upper_bound = false;
kono
parents: 14
diff changeset
1030 free_numbers_of_iterations_estimates (dest->loop_father);
kono
parents: 14
diff changeset
1031 }
kono
parents: 14
diff changeset
1032 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1034 s = redirect_edge_and_branch (e, dest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 /* redirect_edge_and_branch must not create a new edge. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 gcc_assert (s == e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 /* Add to the PHI nodes at DEST each PHI argument removed at the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 destination of E. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041 for (gsi = gsi_start_phis (dest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042 !gsi_end_p (gsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043 gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1044 {
16
kono
parents: 14
diff changeset
1045 gphi *phi = gsi.phi ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1046 tree def = gimple_phi_arg_def (phi, succ->dest_idx);
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
1047 source_location locus = gimple_phi_arg_location_from_edge (phi, succ);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1048
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049 if (TREE_CODE (def) == SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 /* If DEF is one of the results of PHI nodes removed during
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 redirection, replace it with the PHI argument that used
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 to be on E. */
16
kono
parents: 14
diff changeset
1054 vec<edge_var_map> *head = redirect_edge_var_map_vector (e);
kono
parents: 14
diff changeset
1055 size_t length = head ? head->length () : 0;
kono
parents: 14
diff changeset
1056 for (size_t i = 0; i < length; i++)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 {
16
kono
parents: 14
diff changeset
1058 edge_var_map *vm = &(*head)[i];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059 tree old_arg = redirect_edge_var_map_result (vm);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060 tree new_arg = redirect_edge_var_map_def (vm);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 if (def == old_arg)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1063 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064 def = new_arg;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
1065 locus = redirect_edge_var_map_location (vm);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1068 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1069 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
1071 add_phi_arg (phi, def, s, locus);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1072 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074 redirect_edge_var_map_clear (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1077 /* Update the dominators. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078 dombb = get_immediate_dominator (CDI_DOMINATORS, bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1079 domdest = get_immediate_dominator (CDI_DOMINATORS, dest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080 if (domdest == bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1081 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1082 /* Shortcut to avoid calling (relatively expensive)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083 nearest_common_dominator unless necessary. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084 dom = dombb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087 dom = nearest_common_dominator (CDI_DOMINATORS, domdest, dombb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089 set_immediate_dominator (CDI_DOMINATORS, dest, dom);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090
16
kono
parents: 14
diff changeset
1091 /* Adjust latch infomation of BB's parent loop as otherwise
kono
parents: 14
diff changeset
1092 the cfg hook has a hard time not to kill the loop. */
kono
parents: 14
diff changeset
1093 if (current_loops && bb->loop_father->latch == bb)
kono
parents: 14
diff changeset
1094 bb->loop_father->latch = pred;
kono
parents: 14
diff changeset
1095
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1096 /* Remove BB since all of BB's incoming edges have been redirected
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097 to DEST. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 delete_basic_block (bb);
16
kono
parents: 14
diff changeset
1099
kono
parents: 14
diff changeset
1100 return true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1101 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1103 /* This pass merges PHI nodes if one feeds into another. For example,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1104 suppose we have the following:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 goto <bb 9> (<L9>);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108 <L8>:;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 tem_17 = foo ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111 # tem_6 = PHI <tem_17(8), tem_23(7)>;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112 <L9>:;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1113
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1114 # tem_3 = PHI <tem_6(9), tem_2(5)>;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115 <L10>:;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1116
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1117 Then we merge the first PHI node into the second one like so:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1118
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119 goto <bb 9> (<L10>);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1120
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1121 <L8>:;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1122 tem_17 = foo ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1123
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1124 # tem_3 = PHI <tem_23(7), tem_2(5), tem_17(8)>;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1125 <L10>:;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1126 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1127
16
kono
parents: 14
diff changeset
1128 namespace {
kono
parents: 14
diff changeset
1129
kono
parents: 14
diff changeset
1130 const pass_data pass_data_merge_phi =
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1131 {
16
kono
parents: 14
diff changeset
1132 GIMPLE_PASS, /* type */
kono
parents: 14
diff changeset
1133 "mergephi", /* name */
kono
parents: 14
diff changeset
1134 OPTGROUP_NONE, /* optinfo_flags */
kono
parents: 14
diff changeset
1135 TV_TREE_MERGE_PHI, /* tv_id */
kono
parents: 14
diff changeset
1136 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 14
diff changeset
1137 0, /* properties_provided */
kono
parents: 14
diff changeset
1138 0, /* properties_destroyed */
kono
parents: 14
diff changeset
1139 0, /* todo_flags_start */
kono
parents: 14
diff changeset
1140 0, /* todo_flags_finish */
kono
parents: 14
diff changeset
1141 };
kono
parents: 14
diff changeset
1142
kono
parents: 14
diff changeset
1143 class pass_merge_phi : public gimple_opt_pass
kono
parents: 14
diff changeset
1144 {
kono
parents: 14
diff changeset
1145 public:
kono
parents: 14
diff changeset
1146 pass_merge_phi (gcc::context *ctxt)
kono
parents: 14
diff changeset
1147 : gimple_opt_pass (pass_data_merge_phi, ctxt)
kono
parents: 14
diff changeset
1148 {}
kono
parents: 14
diff changeset
1149
kono
parents: 14
diff changeset
1150 /* opt_pass methods: */
kono
parents: 14
diff changeset
1151 opt_pass * clone () { return new pass_merge_phi (m_ctxt); }
kono
parents: 14
diff changeset
1152 virtual unsigned int execute (function *);
kono
parents: 14
diff changeset
1153
kono
parents: 14
diff changeset
1154 }; // class pass_merge_phi
kono
parents: 14
diff changeset
1155
kono
parents: 14
diff changeset
1156 unsigned int
kono
parents: 14
diff changeset
1157 pass_merge_phi::execute (function *fun)
kono
parents: 14
diff changeset
1158 {
kono
parents: 14
diff changeset
1159 basic_block *worklist = XNEWVEC (basic_block, n_basic_blocks_for_fn (fun));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 basic_block *current = worklist;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 calculate_dominance_info (CDI_DOMINATORS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 /* Find all PHI nodes that we may be able to merge. */
16
kono
parents: 14
diff changeset
1166 FOR_EACH_BB_FN (bb, fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 basic_block dest;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 /* Look for a forwarder block with PHI nodes. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171 if (!tree_forwarder_block_p (bb, true))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174 dest = single_succ (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176 /* We have to feed into another basic block with PHI
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 nodes. */
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1178 if (gimple_seq_empty_p (phi_nodes (dest))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179 /* We don't want to deal with a basic block with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 abnormal edges. */
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1181 || bb_has_abnormal_pred (bb))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1183
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184 if (!dominated_by_p (CDI_DOMINATORS, dest, bb))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1185 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 /* If BB does not dominate DEST, then the PHI nodes at
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187 DEST must be the only users of the results of the PHI
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 nodes at BB. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 *current++ = bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 {
16
kono
parents: 14
diff changeset
1193 gphi_iterator gsi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194 unsigned int dest_idx = single_succ_edge (bb)->dest_idx;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 /* BB dominates DEST. There may be many users of the PHI
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 nodes in BB. However, there is still a trivial case we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198 can handle. If the result of every PHI in BB is used
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 only by a PHI in DEST, then we can trivially merge the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200 PHI nodes from BB into DEST. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202 gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203 {
16
kono
parents: 14
diff changeset
1204 gphi *phi = gsi.phi ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205 tree result = gimple_phi_result (phi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 use_operand_p imm_use;
16
kono
parents: 14
diff changeset
1207 gimple *use_stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 /* If the PHI's result is never used, then we can just
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 ignore it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 if (has_zero_uses (result))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1214 /* Get the single use of the result of this PHI node. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1215 if (!single_imm_use (result, &imm_use, &use_stmt)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216 || gimple_code (use_stmt) != GIMPLE_PHI
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1217 || gimple_bb (use_stmt) != dest
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1218 || gimple_phi_arg_def (use_stmt, dest_idx) != result)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1221
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1222 /* If the loop above iterated through all the PHI nodes
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1223 in BB, then we can merge the PHIs from BB into DEST. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1224 if (gsi_end_p (gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 *current++ = bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1229 /* Now let's drain WORKLIST. */
16
kono
parents: 14
diff changeset
1230 bool changed = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1231 while (current != worklist)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1232 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233 bb = *--current;
16
kono
parents: 14
diff changeset
1234 changed |= remove_forwarder_block_with_phi (bb);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1235 }
16
kono
parents: 14
diff changeset
1236 free (worklist);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1237
16
kono
parents: 14
diff changeset
1238 /* Removing forwarder blocks can cause formerly irreducible loops
kono
parents: 14
diff changeset
1239 to become reducible if we merged two entry blocks. */
kono
parents: 14
diff changeset
1240 if (changed
kono
parents: 14
diff changeset
1241 && current_loops)
kono
parents: 14
diff changeset
1242 loops_state_set (LOOPS_NEED_FIXUP);
kono
parents: 14
diff changeset
1243
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1244 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1246
16
kono
parents: 14
diff changeset
1247 } // anon namespace
kono
parents: 14
diff changeset
1248
kono
parents: 14
diff changeset
1249 gimple_opt_pass *
kono
parents: 14
diff changeset
1250 make_pass_merge_phi (gcc::context *ctxt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1251 {
16
kono
parents: 14
diff changeset
1252 return new pass_merge_phi (ctxt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1254
16
kono
parents: 14
diff changeset
1255 /* Pass: cleanup the CFG just before expanding trees to RTL.
kono
parents: 14
diff changeset
1256 This is just a round of label cleanups and case node grouping
kono
parents: 14
diff changeset
1257 because after the tree optimizers have run such cleanups may
kono
parents: 14
diff changeset
1258 be necessary. */
kono
parents: 14
diff changeset
1259
kono
parents: 14
diff changeset
1260 static unsigned int
kono
parents: 14
diff changeset
1261 execute_cleanup_cfg_post_optimizing (void)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262 {
16
kono
parents: 14
diff changeset
1263 unsigned int todo = execute_fixup_cfg ();
kono
parents: 14
diff changeset
1264 if (cleanup_tree_cfg ())
kono
parents: 14
diff changeset
1265 {
kono
parents: 14
diff changeset
1266 todo &= ~TODO_cleanup_cfg;
kono
parents: 14
diff changeset
1267 todo |= TODO_update_ssa;
kono
parents: 14
diff changeset
1268 }
kono
parents: 14
diff changeset
1269 maybe_remove_unreachable_handlers ();
kono
parents: 14
diff changeset
1270 cleanup_dead_labels ();
kono
parents: 14
diff changeset
1271 if (group_case_labels ())
kono
parents: 14
diff changeset
1272 todo |= TODO_cleanup_cfg;
kono
parents: 14
diff changeset
1273 if ((flag_compare_debug_opt || flag_compare_debug)
kono
parents: 14
diff changeset
1274 && flag_dump_final_insns)
kono
parents: 14
diff changeset
1275 {
kono
parents: 14
diff changeset
1276 FILE *final_output = fopen (flag_dump_final_insns, "a");
kono
parents: 14
diff changeset
1277
kono
parents: 14
diff changeset
1278 if (!final_output)
kono
parents: 14
diff changeset
1279 {
kono
parents: 14
diff changeset
1280 error ("could not open final insn dump file %qs: %m",
kono
parents: 14
diff changeset
1281 flag_dump_final_insns);
kono
parents: 14
diff changeset
1282 flag_dump_final_insns = NULL;
kono
parents: 14
diff changeset
1283 }
kono
parents: 14
diff changeset
1284 else
kono
parents: 14
diff changeset
1285 {
kono
parents: 14
diff changeset
1286 int save_unnumbered = flag_dump_unnumbered;
kono
parents: 14
diff changeset
1287 int save_noaddr = flag_dump_noaddr;
kono
parents: 14
diff changeset
1288
kono
parents: 14
diff changeset
1289 flag_dump_noaddr = flag_dump_unnumbered = 1;
kono
parents: 14
diff changeset
1290 fprintf (final_output, "\n");
kono
parents: 14
diff changeset
1291 dump_enumerated_decls (final_output, dump_flags | TDF_NOUID);
kono
parents: 14
diff changeset
1292 flag_dump_noaddr = save_noaddr;
kono
parents: 14
diff changeset
1293 flag_dump_unnumbered = save_unnumbered;
kono
parents: 14
diff changeset
1294 if (fclose (final_output))
kono
parents: 14
diff changeset
1295 {
kono
parents: 14
diff changeset
1296 error ("could not close final insn dump file %qs: %m",
kono
parents: 14
diff changeset
1297 flag_dump_final_insns);
kono
parents: 14
diff changeset
1298 flag_dump_final_insns = NULL;
kono
parents: 14
diff changeset
1299 }
kono
parents: 14
diff changeset
1300 }
kono
parents: 14
diff changeset
1301 }
kono
parents: 14
diff changeset
1302 return todo;
kono
parents: 14
diff changeset
1303 }
kono
parents: 14
diff changeset
1304
kono
parents: 14
diff changeset
1305 namespace {
kono
parents: 14
diff changeset
1306
kono
parents: 14
diff changeset
1307 const pass_data pass_data_cleanup_cfg_post_optimizing =
kono
parents: 14
diff changeset
1308 {
kono
parents: 14
diff changeset
1309 GIMPLE_PASS, /* type */
kono
parents: 14
diff changeset
1310 "optimized", /* name */
kono
parents: 14
diff changeset
1311 OPTGROUP_NONE, /* optinfo_flags */
kono
parents: 14
diff changeset
1312 TV_TREE_CLEANUP_CFG, /* tv_id */
kono
parents: 14
diff changeset
1313 PROP_cfg, /* properties_required */
kono
parents: 14
diff changeset
1314 0, /* properties_provided */
kono
parents: 14
diff changeset
1315 0, /* properties_destroyed */
kono
parents: 14
diff changeset
1316 0, /* todo_flags_start */
kono
parents: 14
diff changeset
1317 TODO_remove_unused_locals, /* todo_flags_finish */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1318 };
16
kono
parents: 14
diff changeset
1319
kono
parents: 14
diff changeset
1320 class pass_cleanup_cfg_post_optimizing : public gimple_opt_pass
kono
parents: 14
diff changeset
1321 {
kono
parents: 14
diff changeset
1322 public:
kono
parents: 14
diff changeset
1323 pass_cleanup_cfg_post_optimizing (gcc::context *ctxt)
kono
parents: 14
diff changeset
1324 : gimple_opt_pass (pass_data_cleanup_cfg_post_optimizing, ctxt)
kono
parents: 14
diff changeset
1325 {}
kono
parents: 14
diff changeset
1326
kono
parents: 14
diff changeset
1327 /* opt_pass methods: */
kono
parents: 14
diff changeset
1328 virtual unsigned int execute (function *)
kono
parents: 14
diff changeset
1329 {
kono
parents: 14
diff changeset
1330 return execute_cleanup_cfg_post_optimizing ();
kono
parents: 14
diff changeset
1331 }
kono
parents: 14
diff changeset
1332
kono
parents: 14
diff changeset
1333 }; // class pass_cleanup_cfg_post_optimizing
kono
parents: 14
diff changeset
1334
kono
parents: 14
diff changeset
1335 } // anon namespace
kono
parents: 14
diff changeset
1336
kono
parents: 14
diff changeset
1337 gimple_opt_pass *
kono
parents: 14
diff changeset
1338 make_pass_cleanup_cfg_post_optimizing (gcc::context *ctxt)
kono
parents: 14
diff changeset
1339 {
kono
parents: 14
diff changeset
1340 return new pass_cleanup_cfg_post_optimizing (ctxt);
kono
parents: 14
diff changeset
1341 }
kono
parents: 14
diff changeset
1342
kono
parents: 14
diff changeset
1343