annotate gcc/tree-cfgcleanup.c @ 138:fc828634a951

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