annotate gcc/tree-ssa-tail-merge.c @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Tail merging for gimple.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2011-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Tom de Vries (tom@codesourcery.com)
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
10 any later version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
15 GNU General Public License for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 /* Pass overview.
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 MOTIVATIONAL EXAMPLE
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 gimple representation of gcc/testsuite/gcc.dg/pr43864.c at
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 hprofStartupp (charD.1 * outputFileNameD.2600, charD.1 * ctxD.2601)
kono
parents:
diff changeset
29 {
kono
parents:
diff changeset
30 struct FILED.1638 * fpD.2605;
kono
parents:
diff changeset
31 charD.1 fileNameD.2604[1000];
kono
parents:
diff changeset
32 intD.0 D.3915;
kono
parents:
diff changeset
33 const charD.1 * restrict outputFileName.0D.3914;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 # BLOCK 2 freq:10000
kono
parents:
diff changeset
36 # PRED: ENTRY [100.0%] (fallthru,exec)
kono
parents:
diff changeset
37 # PT = nonlocal { D.3926 } (restr)
kono
parents:
diff changeset
38 outputFileName.0D.3914_3
kono
parents:
diff changeset
39 = (const charD.1 * restrict) outputFileNameD.2600_2(D);
kono
parents:
diff changeset
40 # .MEMD.3923_13 = VDEF <.MEMD.3923_12(D)>
kono
parents:
diff changeset
41 # USE = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
42 # CLB = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
43 sprintfD.759 (&fileNameD.2604, outputFileName.0D.3914_3);
kono
parents:
diff changeset
44 # .MEMD.3923_14 = VDEF <.MEMD.3923_13>
kono
parents:
diff changeset
45 # USE = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
46 # CLB = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
47 D.3915_4 = accessD.2606 (&fileNameD.2604, 1);
kono
parents:
diff changeset
48 if (D.3915_4 == 0)
kono
parents:
diff changeset
49 goto <bb 3>;
kono
parents:
diff changeset
50 else
kono
parents:
diff changeset
51 goto <bb 4>;
kono
parents:
diff changeset
52 # SUCC: 3 [10.0%] (true,exec) 4 [90.0%] (false,exec)
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 # BLOCK 3 freq:1000
kono
parents:
diff changeset
55 # PRED: 2 [10.0%] (true,exec)
kono
parents:
diff changeset
56 # .MEMD.3923_15 = VDEF <.MEMD.3923_14>
kono
parents:
diff changeset
57 # USE = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
58 # CLB = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
59 freeD.898 (ctxD.2601_5(D));
kono
parents:
diff changeset
60 goto <bb 7>;
kono
parents:
diff changeset
61 # SUCC: 7 [100.0%] (fallthru,exec)
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 # BLOCK 4 freq:9000
kono
parents:
diff changeset
64 # PRED: 2 [90.0%] (false,exec)
kono
parents:
diff changeset
65 # .MEMD.3923_16 = VDEF <.MEMD.3923_14>
kono
parents:
diff changeset
66 # PT = nonlocal escaped
kono
parents:
diff changeset
67 # USE = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
68 # CLB = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
69 fpD.2605_8 = fopenD.1805 (&fileNameD.2604[0], 0B);
kono
parents:
diff changeset
70 if (fpD.2605_8 == 0B)
kono
parents:
diff changeset
71 goto <bb 5>;
kono
parents:
diff changeset
72 else
kono
parents:
diff changeset
73 goto <bb 6>;
kono
parents:
diff changeset
74 # SUCC: 5 [1.9%] (true,exec) 6 [98.1%] (false,exec)
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 # BLOCK 5 freq:173
kono
parents:
diff changeset
77 # PRED: 4 [1.9%] (true,exec)
kono
parents:
diff changeset
78 # .MEMD.3923_17 = VDEF <.MEMD.3923_16>
kono
parents:
diff changeset
79 # USE = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
80 # CLB = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
81 freeD.898 (ctxD.2601_5(D));
kono
parents:
diff changeset
82 goto <bb 7>;
kono
parents:
diff changeset
83 # SUCC: 7 [100.0%] (fallthru,exec)
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 # BLOCK 6 freq:8827
kono
parents:
diff changeset
86 # PRED: 4 [98.1%] (false,exec)
kono
parents:
diff changeset
87 # .MEMD.3923_18 = VDEF <.MEMD.3923_16>
kono
parents:
diff changeset
88 # USE = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
89 # CLB = nonlocal null { fileNameD.2604 D.3926 } (restr)
kono
parents:
diff changeset
90 fooD.2599 (outputFileNameD.2600_2(D), fpD.2605_8);
kono
parents:
diff changeset
91 # SUCC: 7 [100.0%] (fallthru,exec)
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 # BLOCK 7 freq:10000
kono
parents:
diff changeset
94 # PRED: 3 [100.0%] (fallthru,exec) 5 [100.0%] (fallthru,exec)
kono
parents:
diff changeset
95 6 [100.0%] (fallthru,exec)
kono
parents:
diff changeset
96 # PT = nonlocal null
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 # ctxD.2601_1 = PHI <0B(3), 0B(5), ctxD.2601_5(D)(6)>
kono
parents:
diff changeset
99 # .MEMD.3923_11 = PHI <.MEMD.3923_15(3), .MEMD.3923_17(5),
kono
parents:
diff changeset
100 .MEMD.3923_18(6)>
kono
parents:
diff changeset
101 # VUSE <.MEMD.3923_11>
kono
parents:
diff changeset
102 return ctxD.2601_1;
kono
parents:
diff changeset
103 # SUCC: EXIT [100.0%]
kono
parents:
diff changeset
104 }
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 bb 3 and bb 5 can be merged. The blocks have different predecessors, but the
kono
parents:
diff changeset
107 same successors, and the same operations.
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 CONTEXT
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 A technique called tail merging (or cross jumping) can fix the example
kono
parents:
diff changeset
113 above. For a block, we look for common code at the end (the tail) of the
kono
parents:
diff changeset
114 predecessor blocks, and insert jumps from one block to the other.
kono
parents:
diff changeset
115 The example is a special case for tail merging, in that 2 whole blocks
kono
parents:
diff changeset
116 can be merged, rather than just the end parts of it.
kono
parents:
diff changeset
117 We currently only focus on whole block merging, so in that sense
kono
parents:
diff changeset
118 calling this pass tail merge is a bit of a misnomer.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 We distinguish 2 kinds of situations in which blocks can be merged:
kono
parents:
diff changeset
121 - same operations, same predecessors. The successor edges coming from one
kono
parents:
diff changeset
122 block are redirected to come from the other block.
kono
parents:
diff changeset
123 - same operations, same successors. The predecessor edges entering one block
kono
parents:
diff changeset
124 are redirected to enter the other block. Note that this operation might
kono
parents:
diff changeset
125 involve introducing phi operations.
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 For efficient implementation, we would like to value numbers the blocks, and
kono
parents:
diff changeset
128 have a comparison operator that tells us whether the blocks are equal.
kono
parents:
diff changeset
129 Besides being runtime efficient, block value numbering should also abstract
kono
parents:
diff changeset
130 from irrelevant differences in order of operations, much like normal value
kono
parents:
diff changeset
131 numbering abstracts from irrelevant order of operations.
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 For the first situation (same_operations, same predecessors), normal value
kono
parents:
diff changeset
134 numbering fits well. We can calculate a block value number based on the
kono
parents:
diff changeset
135 value numbers of the defs and vdefs.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 For the second situation (same operations, same successors), this approach
kono
parents:
diff changeset
138 doesn't work so well. We can illustrate this using the example. The calls
kono
parents:
diff changeset
139 to free use different vdefs: MEMD.3923_16 and MEMD.3923_14, and these will
kono
parents:
diff changeset
140 remain different in value numbering, since they represent different memory
kono
parents:
diff changeset
141 states. So the resulting vdefs of the frees will be different in value
kono
parents:
diff changeset
142 numbering, so the block value numbers will be different.
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 The reason why we call the blocks equal is not because they define the same
kono
parents:
diff changeset
145 values, but because uses in the blocks use (possibly different) defs in the
kono
parents:
diff changeset
146 same way. To be able to detect this efficiently, we need to do some kind of
kono
parents:
diff changeset
147 reverse value numbering, meaning number the uses rather than the defs, and
kono
parents:
diff changeset
148 calculate a block value number based on the value number of the uses.
kono
parents:
diff changeset
149 Ideally, a block comparison operator will also indicate which phis are needed
kono
parents:
diff changeset
150 to merge the blocks.
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 For the moment, we don't do block value numbering, but we do insn-by-insn
kono
parents:
diff changeset
153 matching, using scc value numbers to match operations with results, and
kono
parents:
diff changeset
154 structural comparison otherwise, while ignoring vop mismatches.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 IMPLEMENTATION
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 1. The pass first determines all groups of blocks with the same successor
kono
parents:
diff changeset
160 blocks.
kono
parents:
diff changeset
161 2. Within each group, it tries to determine clusters of equal basic blocks.
kono
parents:
diff changeset
162 3. The clusters are applied.
kono
parents:
diff changeset
163 4. The same successor groups are updated.
kono
parents:
diff changeset
164 5. This process is repeated from 2 onwards, until no more changes.
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 LIMITATIONS/TODO
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 - block only
kono
parents:
diff changeset
170 - handles only 'same operations, same successors'.
kono
parents:
diff changeset
171 It handles same predecessors as a special subcase though.
kono
parents:
diff changeset
172 - does not implement the reverse value numbering and block value numbering.
kono
parents:
diff changeset
173 - improve memory allocation: use garbage collected memory, obstacks,
kono
parents:
diff changeset
174 allocpools where appropriate.
kono
parents:
diff changeset
175 - no insertion of gimple_reg phis, We only introduce vop-phis.
kono
parents:
diff changeset
176 - handle blocks with gimple_reg phi_nodes.
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 PASS PLACEMENT
kono
parents:
diff changeset
180 This 'pass' is not a stand-alone gimple pass, but runs as part of
kono
parents:
diff changeset
181 pass_pre, in order to share the value numbering.
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 SWITCHES
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 - ftree-tail-merge. On at -O2. We may have to enable it only at -Os. */
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 #include "config.h"
kono
parents:
diff changeset
189 #include "system.h"
kono
parents:
diff changeset
190 #include "coretypes.h"
kono
parents:
diff changeset
191 #include "backend.h"
kono
parents:
diff changeset
192 #include "tree.h"
kono
parents:
diff changeset
193 #include "gimple.h"
kono
parents:
diff changeset
194 #include "cfghooks.h"
kono
parents:
diff changeset
195 #include "tree-pass.h"
kono
parents:
diff changeset
196 #include "ssa.h"
kono
parents:
diff changeset
197 #include "fold-const.h"
kono
parents:
diff changeset
198 #include "trans-mem.h"
kono
parents:
diff changeset
199 #include "cfganal.h"
kono
parents:
diff changeset
200 #include "cfgcleanup.h"
kono
parents:
diff changeset
201 #include "gimple-iterator.h"
kono
parents:
diff changeset
202 #include "tree-cfg.h"
kono
parents:
diff changeset
203 #include "tree-into-ssa.h"
kono
parents:
diff changeset
204 #include "params.h"
kono
parents:
diff changeset
205 #include "tree-ssa-sccvn.h"
kono
parents:
diff changeset
206 #include "cfgloop.h"
kono
parents:
diff changeset
207 #include "tree-eh.h"
kono
parents:
diff changeset
208 #include "tree-cfgcleanup.h"
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 const int ignore_edge_flags = EDGE_DFS_BACK | EDGE_EXECUTABLE;
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 /* Describes a group of bbs with the same successors. The successor bbs are
kono
parents:
diff changeset
213 cached in succs, and the successor edge flags are cached in succ_flags.
kono
parents:
diff changeset
214 If a bb has the EDGE_TRUE/FALSE_VALUE flags swapped compared to succ_flags,
kono
parents:
diff changeset
215 it's marked in inverse.
kono
parents:
diff changeset
216 Additionally, the hash value for the struct is cached in hashval, and
kono
parents:
diff changeset
217 in_worklist indicates whether it's currently part of worklist. */
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 struct same_succ : pointer_hash <same_succ>
kono
parents:
diff changeset
220 {
kono
parents:
diff changeset
221 /* The bbs that have the same successor bbs. */
kono
parents:
diff changeset
222 bitmap bbs;
kono
parents:
diff changeset
223 /* The successor bbs. */
kono
parents:
diff changeset
224 bitmap succs;
kono
parents:
diff changeset
225 /* Indicates whether the EDGE_TRUE/FALSE_VALUEs of succ_flags are swapped for
kono
parents:
diff changeset
226 bb. */
kono
parents:
diff changeset
227 bitmap inverse;
kono
parents:
diff changeset
228 /* The edge flags for each of the successor bbs. */
kono
parents:
diff changeset
229 vec<int> succ_flags;
kono
parents:
diff changeset
230 /* Indicates whether the struct is currently in the worklist. */
kono
parents:
diff changeset
231 bool in_worklist;
kono
parents:
diff changeset
232 /* The hash value of the struct. */
kono
parents:
diff changeset
233 hashval_t hashval;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 /* hash_table support. */
kono
parents:
diff changeset
236 static inline hashval_t hash (const same_succ *);
kono
parents:
diff changeset
237 static int equal (const same_succ *, const same_succ *);
kono
parents:
diff changeset
238 static void remove (same_succ *);
kono
parents:
diff changeset
239 };
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 /* hash routine for hash_table support, returns hashval of E. */
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 inline hashval_t
kono
parents:
diff changeset
244 same_succ::hash (const same_succ *e)
kono
parents:
diff changeset
245 {
kono
parents:
diff changeset
246 return e->hashval;
kono
parents:
diff changeset
247 }
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 /* A group of bbs where 1 bb from bbs can replace the other bbs. */
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 struct bb_cluster
kono
parents:
diff changeset
252 {
kono
parents:
diff changeset
253 /* The bbs in the cluster. */
kono
parents:
diff changeset
254 bitmap bbs;
kono
parents:
diff changeset
255 /* The preds of the bbs in the cluster. */
kono
parents:
diff changeset
256 bitmap preds;
kono
parents:
diff changeset
257 /* Index in all_clusters vector. */
kono
parents:
diff changeset
258 int index;
kono
parents:
diff changeset
259 /* The bb to replace the cluster with. */
kono
parents:
diff changeset
260 basic_block rep_bb;
kono
parents:
diff changeset
261 };
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 /* Per bb-info. */
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 struct aux_bb_info
kono
parents:
diff changeset
266 {
kono
parents:
diff changeset
267 /* The number of non-debug statements in the bb. */
kono
parents:
diff changeset
268 int size;
kono
parents:
diff changeset
269 /* The same_succ that this bb is a member of. */
kono
parents:
diff changeset
270 same_succ *bb_same_succ;
kono
parents:
diff changeset
271 /* The cluster that this bb is a member of. */
kono
parents:
diff changeset
272 bb_cluster *cluster;
kono
parents:
diff changeset
273 /* The vop state at the exit of a bb. This is shortlived data, used to
kono
parents:
diff changeset
274 communicate data between update_block_by and update_vuses. */
kono
parents:
diff changeset
275 tree vop_at_exit;
kono
parents:
diff changeset
276 /* The bb that either contains or is dominated by the dependencies of the
kono
parents:
diff changeset
277 bb. */
kono
parents:
diff changeset
278 basic_block dep_bb;
kono
parents:
diff changeset
279 };
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 /* Macros to access the fields of struct aux_bb_info. */
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 #define BB_SIZE(bb) (((struct aux_bb_info *)bb->aux)->size)
kono
parents:
diff changeset
284 #define BB_SAME_SUCC(bb) (((struct aux_bb_info *)bb->aux)->bb_same_succ)
kono
parents:
diff changeset
285 #define BB_CLUSTER(bb) (((struct aux_bb_info *)bb->aux)->cluster)
kono
parents:
diff changeset
286 #define BB_VOP_AT_EXIT(bb) (((struct aux_bb_info *)bb->aux)->vop_at_exit)
kono
parents:
diff changeset
287 #define BB_DEP_BB(bb) (((struct aux_bb_info *)bb->aux)->dep_bb)
kono
parents:
diff changeset
288
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
289 /* Valueization helper querying the VN lattice. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
290
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
291 static tree
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
292 tail_merge_valueize (tree name)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
293 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
294 if (TREE_CODE (name) == SSA_NAME
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
295 && has_VN_INFO (name))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
296 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
297 tree tem = VN_INFO (name)->valnum;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
298 if (tem != VN_TOP)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
299 return tem;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
300 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
301 return name;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
302 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
303
111
kono
parents:
diff changeset
304 /* Returns true if the only effect a statement STMT has, is to define locally
kono
parents:
diff changeset
305 used SSA_NAMEs. */
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 static bool
kono
parents:
diff changeset
308 stmt_local_def (gimple *stmt)
kono
parents:
diff changeset
309 {
kono
parents:
diff changeset
310 basic_block bb, def_bb;
kono
parents:
diff changeset
311 imm_use_iterator iter;
kono
parents:
diff changeset
312 use_operand_p use_p;
kono
parents:
diff changeset
313 tree val;
kono
parents:
diff changeset
314 def_operand_p def_p;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 if (gimple_vdef (stmt) != NULL_TREE
kono
parents:
diff changeset
317 || gimple_has_side_effects (stmt)
kono
parents:
diff changeset
318 || gimple_could_trap_p_1 (stmt, false, false)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
319 || gimple_vuse (stmt) != NULL_TREE
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
320 /* Copied from tree-ssa-ifcombine.c:bb_no_side_effects_p():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
321 const calls don't match any of the above, yet they could
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
322 still have some side-effects - they could contain
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
323 gimple_could_trap_p statements, like floating point
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
324 exceptions or integer division by zero. See PR70586.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
325 FIXME: perhaps gimple_has_side_effects or gimple_could_trap_p
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
326 should handle this. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
327 || is_gimple_call (stmt))
111
kono
parents:
diff changeset
328 return false;
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF);
kono
parents:
diff changeset
331 if (def_p == NULL)
kono
parents:
diff changeset
332 return false;
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 val = DEF_FROM_PTR (def_p);
kono
parents:
diff changeset
335 if (val == NULL_TREE || TREE_CODE (val) != SSA_NAME)
kono
parents:
diff changeset
336 return false;
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 def_bb = gimple_bb (stmt);
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 FOR_EACH_IMM_USE_FAST (use_p, iter, val)
kono
parents:
diff changeset
341 {
kono
parents:
diff changeset
342 if (is_gimple_debug (USE_STMT (use_p)))
kono
parents:
diff changeset
343 continue;
kono
parents:
diff changeset
344 bb = gimple_bb (USE_STMT (use_p));
kono
parents:
diff changeset
345 if (bb == def_bb)
kono
parents:
diff changeset
346 continue;
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 if (gimple_code (USE_STMT (use_p)) == GIMPLE_PHI
kono
parents:
diff changeset
349 && EDGE_PRED (bb, PHI_ARG_INDEX_FROM_USE (use_p))->src == def_bb)
kono
parents:
diff changeset
350 continue;
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 return false;
kono
parents:
diff changeset
353 }
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 return true;
kono
parents:
diff changeset
356 }
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 /* Let GSI skip forwards over local defs. */
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 static void
kono
parents:
diff changeset
361 gsi_advance_fw_nondebug_nonlocal (gimple_stmt_iterator *gsi)
kono
parents:
diff changeset
362 {
kono
parents:
diff changeset
363 gimple *stmt;
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 while (true)
kono
parents:
diff changeset
366 {
kono
parents:
diff changeset
367 if (gsi_end_p (*gsi))
kono
parents:
diff changeset
368 return;
kono
parents:
diff changeset
369 stmt = gsi_stmt (*gsi);
kono
parents:
diff changeset
370 if (!stmt_local_def (stmt))
kono
parents:
diff changeset
371 return;
kono
parents:
diff changeset
372 gsi_next_nondebug (gsi);
kono
parents:
diff changeset
373 }
kono
parents:
diff changeset
374 }
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 /* VAL1 and VAL2 are either:
kono
parents:
diff changeset
377 - uses in BB1 and BB2, or
kono
parents:
diff changeset
378 - phi alternatives for BB1 and BB2.
kono
parents:
diff changeset
379 Return true if the uses have the same gvn value. */
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 static bool
kono
parents:
diff changeset
382 gvn_uses_equal (tree val1, tree val2)
kono
parents:
diff changeset
383 {
kono
parents:
diff changeset
384 gcc_checking_assert (val1 != NULL_TREE && val2 != NULL_TREE);
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 if (val1 == val2)
kono
parents:
diff changeset
387 return true;
kono
parents:
diff changeset
388
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
389 if (tail_merge_valueize (val1) != tail_merge_valueize (val2))
111
kono
parents:
diff changeset
390 return false;
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 return ((TREE_CODE (val1) == SSA_NAME || CONSTANT_CLASS_P (val1))
kono
parents:
diff changeset
393 && (TREE_CODE (val2) == SSA_NAME || CONSTANT_CLASS_P (val2)));
kono
parents:
diff changeset
394 }
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 /* Prints E to FILE. */
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 static void
kono
parents:
diff changeset
399 same_succ_print (FILE *file, const same_succ *e)
kono
parents:
diff changeset
400 {
kono
parents:
diff changeset
401 unsigned int i;
kono
parents:
diff changeset
402 bitmap_print (file, e->bbs, "bbs:", "\n");
kono
parents:
diff changeset
403 bitmap_print (file, e->succs, "succs:", "\n");
kono
parents:
diff changeset
404 bitmap_print (file, e->inverse, "inverse:", "\n");
kono
parents:
diff changeset
405 fprintf (file, "flags:");
kono
parents:
diff changeset
406 for (i = 0; i < e->succ_flags.length (); ++i)
kono
parents:
diff changeset
407 fprintf (file, " %x", e->succ_flags[i]);
kono
parents:
diff changeset
408 fprintf (file, "\n");
kono
parents:
diff changeset
409 }
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 /* Prints same_succ VE to VFILE. */
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 inline int
kono
parents:
diff changeset
414 ssa_same_succ_print_traverse (same_succ **pe, FILE *file)
kono
parents:
diff changeset
415 {
kono
parents:
diff changeset
416 const same_succ *e = *pe;
kono
parents:
diff changeset
417 same_succ_print (file, e);
kono
parents:
diff changeset
418 return 1;
kono
parents:
diff changeset
419 }
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 /* Update BB_DEP_BB (USE_BB), given a use of VAL in USE_BB. */
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 static void
kono
parents:
diff changeset
424 update_dep_bb (basic_block use_bb, tree val)
kono
parents:
diff changeset
425 {
kono
parents:
diff changeset
426 basic_block dep_bb;
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 /* Not a dep. */
kono
parents:
diff changeset
429 if (TREE_CODE (val) != SSA_NAME)
kono
parents:
diff changeset
430 return;
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 /* Skip use of global def. */
kono
parents:
diff changeset
433 if (SSA_NAME_IS_DEFAULT_DEF (val))
kono
parents:
diff changeset
434 return;
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 /* Skip use of local def. */
kono
parents:
diff changeset
437 dep_bb = gimple_bb (SSA_NAME_DEF_STMT (val));
kono
parents:
diff changeset
438 if (dep_bb == use_bb)
kono
parents:
diff changeset
439 return;
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 if (BB_DEP_BB (use_bb) == NULL
kono
parents:
diff changeset
442 || dominated_by_p (CDI_DOMINATORS, dep_bb, BB_DEP_BB (use_bb)))
kono
parents:
diff changeset
443 BB_DEP_BB (use_bb) = dep_bb;
kono
parents:
diff changeset
444 }
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 /* Update BB_DEP_BB, given the dependencies in STMT. */
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 static void
kono
parents:
diff changeset
449 stmt_update_dep_bb (gimple *stmt)
kono
parents:
diff changeset
450 {
kono
parents:
diff changeset
451 ssa_op_iter iter;
kono
parents:
diff changeset
452 use_operand_p use;
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 FOR_EACH_SSA_USE_OPERAND (use, stmt, iter, SSA_OP_USE)
kono
parents:
diff changeset
455 update_dep_bb (gimple_bb (stmt), USE_FROM_PTR (use));
kono
parents:
diff changeset
456 }
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 /* Calculates hash value for same_succ VE. */
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 static hashval_t
kono
parents:
diff changeset
461 same_succ_hash (const same_succ *e)
kono
parents:
diff changeset
462 {
kono
parents:
diff changeset
463 inchash::hash hstate (bitmap_hash (e->succs));
kono
parents:
diff changeset
464 int flags;
kono
parents:
diff changeset
465 unsigned int i;
kono
parents:
diff changeset
466 unsigned int first = bitmap_first_set_bit (e->bbs);
kono
parents:
diff changeset
467 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, first);
kono
parents:
diff changeset
468 int size = 0;
kono
parents:
diff changeset
469 gimple *stmt;
kono
parents:
diff changeset
470 tree arg;
kono
parents:
diff changeset
471 unsigned int s;
kono
parents:
diff changeset
472 bitmap_iterator bs;
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 for (gimple_stmt_iterator gsi = gsi_start_nondebug_bb (bb);
kono
parents:
diff changeset
475 !gsi_end_p (gsi); gsi_next_nondebug (&gsi))
kono
parents:
diff changeset
476 {
kono
parents:
diff changeset
477 stmt = gsi_stmt (gsi);
kono
parents:
diff changeset
478 stmt_update_dep_bb (stmt);
kono
parents:
diff changeset
479 if (stmt_local_def (stmt))
kono
parents:
diff changeset
480 continue;
kono
parents:
diff changeset
481 size++;
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 hstate.add_int (gimple_code (stmt));
kono
parents:
diff changeset
484 if (is_gimple_assign (stmt))
kono
parents:
diff changeset
485 hstate.add_int (gimple_assign_rhs_code (stmt));
kono
parents:
diff changeset
486 if (!is_gimple_call (stmt))
kono
parents:
diff changeset
487 continue;
kono
parents:
diff changeset
488 if (gimple_call_internal_p (stmt))
kono
parents:
diff changeset
489 hstate.add_int (gimple_call_internal_fn (stmt));
kono
parents:
diff changeset
490 else
kono
parents:
diff changeset
491 {
kono
parents:
diff changeset
492 inchash::add_expr (gimple_call_fn (stmt), hstate);
kono
parents:
diff changeset
493 if (gimple_call_chain (stmt))
kono
parents:
diff changeset
494 inchash::add_expr (gimple_call_chain (stmt), hstate);
kono
parents:
diff changeset
495 }
kono
parents:
diff changeset
496 for (i = 0; i < gimple_call_num_args (stmt); i++)
kono
parents:
diff changeset
497 {
kono
parents:
diff changeset
498 arg = gimple_call_arg (stmt, i);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
499 arg = tail_merge_valueize (arg);
111
kono
parents:
diff changeset
500 inchash::add_expr (arg, hstate);
kono
parents:
diff changeset
501 }
kono
parents:
diff changeset
502 }
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 hstate.add_int (size);
kono
parents:
diff changeset
505 BB_SIZE (bb) = size;
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 hstate.add_int (bb->loop_father->num);
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 for (i = 0; i < e->succ_flags.length (); ++i)
kono
parents:
diff changeset
510 {
kono
parents:
diff changeset
511 flags = e->succ_flags[i];
kono
parents:
diff changeset
512 flags = flags & ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
kono
parents:
diff changeset
513 hstate.add_int (flags);
kono
parents:
diff changeset
514 }
kono
parents:
diff changeset
515
kono
parents:
diff changeset
516 EXECUTE_IF_SET_IN_BITMAP (e->succs, 0, s, bs)
kono
parents:
diff changeset
517 {
kono
parents:
diff changeset
518 int n = find_edge (bb, BASIC_BLOCK_FOR_FN (cfun, s))->dest_idx;
kono
parents:
diff changeset
519 for (gphi_iterator gsi = gsi_start_phis (BASIC_BLOCK_FOR_FN (cfun, s));
kono
parents:
diff changeset
520 !gsi_end_p (gsi);
kono
parents:
diff changeset
521 gsi_next (&gsi))
kono
parents:
diff changeset
522 {
kono
parents:
diff changeset
523 gphi *phi = gsi.phi ();
kono
parents:
diff changeset
524 tree lhs = gimple_phi_result (phi);
kono
parents:
diff changeset
525 tree val = gimple_phi_arg_def (phi, n);
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 if (virtual_operand_p (lhs))
kono
parents:
diff changeset
528 continue;
kono
parents:
diff changeset
529 update_dep_bb (bb, val);
kono
parents:
diff changeset
530 }
kono
parents:
diff changeset
531 }
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 return hstate.end ();
kono
parents:
diff changeset
534 }
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 /* Returns true if E1 and E2 have 2 successors, and if the successor flags
kono
parents:
diff changeset
537 are inverse for the EDGE_TRUE_VALUE and EDGE_FALSE_VALUE flags, and equal for
kono
parents:
diff changeset
538 the other edge flags. */
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 static bool
kono
parents:
diff changeset
541 inverse_flags (const same_succ *e1, const same_succ *e2)
kono
parents:
diff changeset
542 {
kono
parents:
diff changeset
543 int f1a, f1b, f2a, f2b;
kono
parents:
diff changeset
544 int mask = ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE);
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 if (e1->succ_flags.length () != 2)
kono
parents:
diff changeset
547 return false;
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 f1a = e1->succ_flags[0];
kono
parents:
diff changeset
550 f1b = e1->succ_flags[1];
kono
parents:
diff changeset
551 f2a = e2->succ_flags[0];
kono
parents:
diff changeset
552 f2b = e2->succ_flags[1];
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 if (f1a == f2a && f1b == f2b)
kono
parents:
diff changeset
555 return false;
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 return (f1a & mask) == (f2a & mask) && (f1b & mask) == (f2b & mask);
kono
parents:
diff changeset
558 }
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 /* Compares SAME_SUCCs E1 and E2. */
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 int
kono
parents:
diff changeset
563 same_succ::equal (const same_succ *e1, const same_succ *e2)
kono
parents:
diff changeset
564 {
kono
parents:
diff changeset
565 unsigned int i, first1, first2;
kono
parents:
diff changeset
566 gimple_stmt_iterator gsi1, gsi2;
kono
parents:
diff changeset
567 gimple *s1, *s2;
kono
parents:
diff changeset
568 basic_block bb1, bb2;
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 if (e1 == e2)
kono
parents:
diff changeset
571 return 1;
kono
parents:
diff changeset
572
kono
parents:
diff changeset
573 if (e1->hashval != e2->hashval)
kono
parents:
diff changeset
574 return 0;
kono
parents:
diff changeset
575
kono
parents:
diff changeset
576 if (e1->succ_flags.length () != e2->succ_flags.length ())
kono
parents:
diff changeset
577 return 0;
kono
parents:
diff changeset
578
kono
parents:
diff changeset
579 if (!bitmap_equal_p (e1->succs, e2->succs))
kono
parents:
diff changeset
580 return 0;
kono
parents:
diff changeset
581
kono
parents:
diff changeset
582 if (!inverse_flags (e1, e2))
kono
parents:
diff changeset
583 {
kono
parents:
diff changeset
584 for (i = 0; i < e1->succ_flags.length (); ++i)
kono
parents:
diff changeset
585 if (e1->succ_flags[i] != e2->succ_flags[i])
kono
parents:
diff changeset
586 return 0;
kono
parents:
diff changeset
587 }
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589 first1 = bitmap_first_set_bit (e1->bbs);
kono
parents:
diff changeset
590 first2 = bitmap_first_set_bit (e2->bbs);
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 bb1 = BASIC_BLOCK_FOR_FN (cfun, first1);
kono
parents:
diff changeset
593 bb2 = BASIC_BLOCK_FOR_FN (cfun, first2);
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 if (BB_SIZE (bb1) != BB_SIZE (bb2))
kono
parents:
diff changeset
596 return 0;
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 if (bb1->loop_father != bb2->loop_father)
kono
parents:
diff changeset
599 return 0;
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601 gsi1 = gsi_start_nondebug_bb (bb1);
kono
parents:
diff changeset
602 gsi2 = gsi_start_nondebug_bb (bb2);
kono
parents:
diff changeset
603 gsi_advance_fw_nondebug_nonlocal (&gsi1);
kono
parents:
diff changeset
604 gsi_advance_fw_nondebug_nonlocal (&gsi2);
kono
parents:
diff changeset
605 while (!(gsi_end_p (gsi1) || gsi_end_p (gsi2)))
kono
parents:
diff changeset
606 {
kono
parents:
diff changeset
607 s1 = gsi_stmt (gsi1);
kono
parents:
diff changeset
608 s2 = gsi_stmt (gsi2);
kono
parents:
diff changeset
609 if (gimple_code (s1) != gimple_code (s2))
kono
parents:
diff changeset
610 return 0;
kono
parents:
diff changeset
611 if (is_gimple_call (s1) && !gimple_call_same_target_p (s1, s2))
kono
parents:
diff changeset
612 return 0;
kono
parents:
diff changeset
613 gsi_next_nondebug (&gsi1);
kono
parents:
diff changeset
614 gsi_next_nondebug (&gsi2);
kono
parents:
diff changeset
615 gsi_advance_fw_nondebug_nonlocal (&gsi1);
kono
parents:
diff changeset
616 gsi_advance_fw_nondebug_nonlocal (&gsi2);
kono
parents:
diff changeset
617 }
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 return 1;
kono
parents:
diff changeset
620 }
kono
parents:
diff changeset
621
kono
parents:
diff changeset
622 /* Alloc and init a new SAME_SUCC. */
kono
parents:
diff changeset
623
kono
parents:
diff changeset
624 static same_succ *
kono
parents:
diff changeset
625 same_succ_alloc (void)
kono
parents:
diff changeset
626 {
kono
parents:
diff changeset
627 same_succ *same = XNEW (struct same_succ);
kono
parents:
diff changeset
628
kono
parents:
diff changeset
629 same->bbs = BITMAP_ALLOC (NULL);
kono
parents:
diff changeset
630 same->succs = BITMAP_ALLOC (NULL);
kono
parents:
diff changeset
631 same->inverse = BITMAP_ALLOC (NULL);
kono
parents:
diff changeset
632 same->succ_flags.create (10);
kono
parents:
diff changeset
633 same->in_worklist = false;
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 return same;
kono
parents:
diff changeset
636 }
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 /* Delete same_succ E. */
kono
parents:
diff changeset
639
kono
parents:
diff changeset
640 void
kono
parents:
diff changeset
641 same_succ::remove (same_succ *e)
kono
parents:
diff changeset
642 {
kono
parents:
diff changeset
643 BITMAP_FREE (e->bbs);
kono
parents:
diff changeset
644 BITMAP_FREE (e->succs);
kono
parents:
diff changeset
645 BITMAP_FREE (e->inverse);
kono
parents:
diff changeset
646 e->succ_flags.release ();
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 XDELETE (e);
kono
parents:
diff changeset
649 }
kono
parents:
diff changeset
650
kono
parents:
diff changeset
651 /* Reset same_succ SAME. */
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 static void
kono
parents:
diff changeset
654 same_succ_reset (same_succ *same)
kono
parents:
diff changeset
655 {
kono
parents:
diff changeset
656 bitmap_clear (same->bbs);
kono
parents:
diff changeset
657 bitmap_clear (same->succs);
kono
parents:
diff changeset
658 bitmap_clear (same->inverse);
kono
parents:
diff changeset
659 same->succ_flags.truncate (0);
kono
parents:
diff changeset
660 }
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 static hash_table<same_succ> *same_succ_htab;
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 /* Array that is used to store the edge flags for a successor. */
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 static int *same_succ_edge_flags;
kono
parents:
diff changeset
667
kono
parents:
diff changeset
668 /* Bitmap that is used to mark bbs that are recently deleted. */
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 static bitmap deleted_bbs;
kono
parents:
diff changeset
671
kono
parents:
diff changeset
672 /* Bitmap that is used to mark predecessors of bbs that are
kono
parents:
diff changeset
673 deleted. */
kono
parents:
diff changeset
674
kono
parents:
diff changeset
675 static bitmap deleted_bb_preds;
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 /* Prints same_succ_htab to stderr. */
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 extern void debug_same_succ (void);
kono
parents:
diff changeset
680 DEBUG_FUNCTION void
kono
parents:
diff changeset
681 debug_same_succ ( void)
kono
parents:
diff changeset
682 {
kono
parents:
diff changeset
683 same_succ_htab->traverse <FILE *, ssa_same_succ_print_traverse> (stderr);
kono
parents:
diff changeset
684 }
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 /* Vector of bbs to process. */
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 static vec<same_succ *> worklist;
kono
parents:
diff changeset
690
kono
parents:
diff changeset
691 /* Prints worklist to FILE. */
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 static void
kono
parents:
diff changeset
694 print_worklist (FILE *file)
kono
parents:
diff changeset
695 {
kono
parents:
diff changeset
696 unsigned int i;
kono
parents:
diff changeset
697 for (i = 0; i < worklist.length (); ++i)
kono
parents:
diff changeset
698 same_succ_print (file, worklist[i]);
kono
parents:
diff changeset
699 }
kono
parents:
diff changeset
700
kono
parents:
diff changeset
701 /* Adds SAME to worklist. */
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 static void
kono
parents:
diff changeset
704 add_to_worklist (same_succ *same)
kono
parents:
diff changeset
705 {
kono
parents:
diff changeset
706 if (same->in_worklist)
kono
parents:
diff changeset
707 return;
kono
parents:
diff changeset
708
kono
parents:
diff changeset
709 if (bitmap_count_bits (same->bbs) < 2)
kono
parents:
diff changeset
710 return;
kono
parents:
diff changeset
711
kono
parents:
diff changeset
712 same->in_worklist = true;
kono
parents:
diff changeset
713 worklist.safe_push (same);
kono
parents:
diff changeset
714 }
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 /* Add BB to same_succ_htab. */
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 static void
kono
parents:
diff changeset
719 find_same_succ_bb (basic_block bb, same_succ **same_p)
kono
parents:
diff changeset
720 {
kono
parents:
diff changeset
721 unsigned int j;
kono
parents:
diff changeset
722 bitmap_iterator bj;
kono
parents:
diff changeset
723 same_succ *same = *same_p;
kono
parents:
diff changeset
724 same_succ **slot;
kono
parents:
diff changeset
725 edge_iterator ei;
kono
parents:
diff changeset
726 edge e;
kono
parents:
diff changeset
727
kono
parents:
diff changeset
728 if (bb == NULL)
kono
parents:
diff changeset
729 return;
kono
parents:
diff changeset
730 bitmap_set_bit (same->bbs, bb->index);
kono
parents:
diff changeset
731 FOR_EACH_EDGE (e, ei, bb->succs)
kono
parents:
diff changeset
732 {
kono
parents:
diff changeset
733 int index = e->dest->index;
kono
parents:
diff changeset
734 bitmap_set_bit (same->succs, index);
kono
parents:
diff changeset
735 same_succ_edge_flags[index] = (e->flags & ~ignore_edge_flags);
kono
parents:
diff changeset
736 }
kono
parents:
diff changeset
737 EXECUTE_IF_SET_IN_BITMAP (same->succs, 0, j, bj)
kono
parents:
diff changeset
738 same->succ_flags.safe_push (same_succ_edge_flags[j]);
kono
parents:
diff changeset
739
kono
parents:
diff changeset
740 same->hashval = same_succ_hash (same);
kono
parents:
diff changeset
741
kono
parents:
diff changeset
742 slot = same_succ_htab->find_slot_with_hash (same, same->hashval, INSERT);
kono
parents:
diff changeset
743 if (*slot == NULL)
kono
parents:
diff changeset
744 {
kono
parents:
diff changeset
745 *slot = same;
kono
parents:
diff changeset
746 BB_SAME_SUCC (bb) = same;
kono
parents:
diff changeset
747 add_to_worklist (same);
kono
parents:
diff changeset
748 *same_p = NULL;
kono
parents:
diff changeset
749 }
kono
parents:
diff changeset
750 else
kono
parents:
diff changeset
751 {
kono
parents:
diff changeset
752 bitmap_set_bit ((*slot)->bbs, bb->index);
kono
parents:
diff changeset
753 BB_SAME_SUCC (bb) = *slot;
kono
parents:
diff changeset
754 add_to_worklist (*slot);
kono
parents:
diff changeset
755 if (inverse_flags (same, *slot))
kono
parents:
diff changeset
756 bitmap_set_bit ((*slot)->inverse, bb->index);
kono
parents:
diff changeset
757 same_succ_reset (same);
kono
parents:
diff changeset
758 }
kono
parents:
diff changeset
759 }
kono
parents:
diff changeset
760
kono
parents:
diff changeset
761 /* Find bbs with same successors. */
kono
parents:
diff changeset
762
kono
parents:
diff changeset
763 static void
kono
parents:
diff changeset
764 find_same_succ (void)
kono
parents:
diff changeset
765 {
kono
parents:
diff changeset
766 same_succ *same = same_succ_alloc ();
kono
parents:
diff changeset
767 basic_block bb;
kono
parents:
diff changeset
768
kono
parents:
diff changeset
769 FOR_EACH_BB_FN (bb, cfun)
kono
parents:
diff changeset
770 {
kono
parents:
diff changeset
771 find_same_succ_bb (bb, &same);
kono
parents:
diff changeset
772 if (same == NULL)
kono
parents:
diff changeset
773 same = same_succ_alloc ();
kono
parents:
diff changeset
774 }
kono
parents:
diff changeset
775
kono
parents:
diff changeset
776 same_succ::remove (same);
kono
parents:
diff changeset
777 }
kono
parents:
diff changeset
778
kono
parents:
diff changeset
779 /* Initializes worklist administration. */
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 static void
kono
parents:
diff changeset
782 init_worklist (void)
kono
parents:
diff changeset
783 {
kono
parents:
diff changeset
784 alloc_aux_for_blocks (sizeof (struct aux_bb_info));
kono
parents:
diff changeset
785 same_succ_htab = new hash_table<same_succ> (n_basic_blocks_for_fn (cfun));
kono
parents:
diff changeset
786 same_succ_edge_flags = XCNEWVEC (int, last_basic_block_for_fn (cfun));
kono
parents:
diff changeset
787 deleted_bbs = BITMAP_ALLOC (NULL);
kono
parents:
diff changeset
788 deleted_bb_preds = BITMAP_ALLOC (NULL);
kono
parents:
diff changeset
789 worklist.create (n_basic_blocks_for_fn (cfun));
kono
parents:
diff changeset
790 find_same_succ ();
kono
parents:
diff changeset
791
kono
parents:
diff changeset
792 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents:
diff changeset
793 {
kono
parents:
diff changeset
794 fprintf (dump_file, "initial worklist:\n");
kono
parents:
diff changeset
795 print_worklist (dump_file);
kono
parents:
diff changeset
796 }
kono
parents:
diff changeset
797 }
kono
parents:
diff changeset
798
kono
parents:
diff changeset
799 /* Deletes worklist administration. */
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 static void
kono
parents:
diff changeset
802 delete_worklist (void)
kono
parents:
diff changeset
803 {
kono
parents:
diff changeset
804 free_aux_for_blocks ();
kono
parents:
diff changeset
805 delete same_succ_htab;
kono
parents:
diff changeset
806 same_succ_htab = NULL;
kono
parents:
diff changeset
807 XDELETEVEC (same_succ_edge_flags);
kono
parents:
diff changeset
808 same_succ_edge_flags = NULL;
kono
parents:
diff changeset
809 BITMAP_FREE (deleted_bbs);
kono
parents:
diff changeset
810 BITMAP_FREE (deleted_bb_preds);
kono
parents:
diff changeset
811 worklist.release ();
kono
parents:
diff changeset
812 }
kono
parents:
diff changeset
813
kono
parents:
diff changeset
814 /* Mark BB as deleted, and mark its predecessors. */
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816 static void
kono
parents:
diff changeset
817 mark_basic_block_deleted (basic_block bb)
kono
parents:
diff changeset
818 {
kono
parents:
diff changeset
819 edge e;
kono
parents:
diff changeset
820 edge_iterator ei;
kono
parents:
diff changeset
821
kono
parents:
diff changeset
822 bitmap_set_bit (deleted_bbs, bb->index);
kono
parents:
diff changeset
823
kono
parents:
diff changeset
824 FOR_EACH_EDGE (e, ei, bb->preds)
kono
parents:
diff changeset
825 bitmap_set_bit (deleted_bb_preds, e->src->index);
kono
parents:
diff changeset
826 }
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 /* Removes BB from its corresponding same_succ. */
kono
parents:
diff changeset
829
kono
parents:
diff changeset
830 static void
kono
parents:
diff changeset
831 same_succ_flush_bb (basic_block bb)
kono
parents:
diff changeset
832 {
kono
parents:
diff changeset
833 same_succ *same = BB_SAME_SUCC (bb);
kono
parents:
diff changeset
834 if (! same)
kono
parents:
diff changeset
835 return;
kono
parents:
diff changeset
836
kono
parents:
diff changeset
837 BB_SAME_SUCC (bb) = NULL;
kono
parents:
diff changeset
838 if (bitmap_single_bit_set_p (same->bbs))
kono
parents:
diff changeset
839 same_succ_htab->remove_elt_with_hash (same, same->hashval);
kono
parents:
diff changeset
840 else
kono
parents:
diff changeset
841 bitmap_clear_bit (same->bbs, bb->index);
kono
parents:
diff changeset
842 }
kono
parents:
diff changeset
843
kono
parents:
diff changeset
844 /* Removes all bbs in BBS from their corresponding same_succ. */
kono
parents:
diff changeset
845
kono
parents:
diff changeset
846 static void
kono
parents:
diff changeset
847 same_succ_flush_bbs (bitmap bbs)
kono
parents:
diff changeset
848 {
kono
parents:
diff changeset
849 unsigned int i;
kono
parents:
diff changeset
850 bitmap_iterator bi;
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 EXECUTE_IF_SET_IN_BITMAP (bbs, 0, i, bi)
kono
parents:
diff changeset
853 same_succ_flush_bb (BASIC_BLOCK_FOR_FN (cfun, i));
kono
parents:
diff changeset
854 }
kono
parents:
diff changeset
855
kono
parents:
diff changeset
856 /* Release the last vdef in BB, either normal or phi result. */
kono
parents:
diff changeset
857
kono
parents:
diff changeset
858 static void
kono
parents:
diff changeset
859 release_last_vdef (basic_block bb)
kono
parents:
diff changeset
860 {
kono
parents:
diff changeset
861 for (gimple_stmt_iterator i = gsi_last_bb (bb); !gsi_end_p (i);
kono
parents:
diff changeset
862 gsi_prev_nondebug (&i))
kono
parents:
diff changeset
863 {
kono
parents:
diff changeset
864 gimple *stmt = gsi_stmt (i);
kono
parents:
diff changeset
865 if (gimple_vdef (stmt) == NULL_TREE)
kono
parents:
diff changeset
866 continue;
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 mark_virtual_operand_for_renaming (gimple_vdef (stmt));
kono
parents:
diff changeset
869 return;
kono
parents:
diff changeset
870 }
kono
parents:
diff changeset
871
kono
parents:
diff changeset
872 for (gphi_iterator i = gsi_start_phis (bb); !gsi_end_p (i);
kono
parents:
diff changeset
873 gsi_next (&i))
kono
parents:
diff changeset
874 {
kono
parents:
diff changeset
875 gphi *phi = i.phi ();
kono
parents:
diff changeset
876 tree res = gimple_phi_result (phi);
kono
parents:
diff changeset
877
kono
parents:
diff changeset
878 if (!virtual_operand_p (res))
kono
parents:
diff changeset
879 continue;
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 mark_virtual_phi_result_for_renaming (phi);
kono
parents:
diff changeset
882 return;
kono
parents:
diff changeset
883 }
kono
parents:
diff changeset
884 }
kono
parents:
diff changeset
885
kono
parents:
diff changeset
886 /* For deleted_bb_preds, find bbs with same successors. */
kono
parents:
diff changeset
887
kono
parents:
diff changeset
888 static void
kono
parents:
diff changeset
889 update_worklist (void)
kono
parents:
diff changeset
890 {
kono
parents:
diff changeset
891 unsigned int i;
kono
parents:
diff changeset
892 bitmap_iterator bi;
kono
parents:
diff changeset
893 basic_block bb;
kono
parents:
diff changeset
894 same_succ *same;
kono
parents:
diff changeset
895
kono
parents:
diff changeset
896 bitmap_and_compl_into (deleted_bb_preds, deleted_bbs);
kono
parents:
diff changeset
897 bitmap_clear (deleted_bbs);
kono
parents:
diff changeset
898
kono
parents:
diff changeset
899 bitmap_clear_bit (deleted_bb_preds, ENTRY_BLOCK);
kono
parents:
diff changeset
900 same_succ_flush_bbs (deleted_bb_preds);
kono
parents:
diff changeset
901
kono
parents:
diff changeset
902 same = same_succ_alloc ();
kono
parents:
diff changeset
903 EXECUTE_IF_SET_IN_BITMAP (deleted_bb_preds, 0, i, bi)
kono
parents:
diff changeset
904 {
kono
parents:
diff changeset
905 bb = BASIC_BLOCK_FOR_FN (cfun, i);
kono
parents:
diff changeset
906 gcc_assert (bb != NULL);
kono
parents:
diff changeset
907 find_same_succ_bb (bb, &same);
kono
parents:
diff changeset
908 if (same == NULL)
kono
parents:
diff changeset
909 same = same_succ_alloc ();
kono
parents:
diff changeset
910 }
kono
parents:
diff changeset
911 same_succ::remove (same);
kono
parents:
diff changeset
912 bitmap_clear (deleted_bb_preds);
kono
parents:
diff changeset
913 }
kono
parents:
diff changeset
914
kono
parents:
diff changeset
915 /* Prints cluster C to FILE. */
kono
parents:
diff changeset
916
kono
parents:
diff changeset
917 static void
kono
parents:
diff changeset
918 print_cluster (FILE *file, bb_cluster *c)
kono
parents:
diff changeset
919 {
kono
parents:
diff changeset
920 if (c == NULL)
kono
parents:
diff changeset
921 return;
kono
parents:
diff changeset
922 bitmap_print (file, c->bbs, "bbs:", "\n");
kono
parents:
diff changeset
923 bitmap_print (file, c->preds, "preds:", "\n");
kono
parents:
diff changeset
924 }
kono
parents:
diff changeset
925
kono
parents:
diff changeset
926 /* Prints cluster C to stderr. */
kono
parents:
diff changeset
927
kono
parents:
diff changeset
928 extern void debug_cluster (bb_cluster *);
kono
parents:
diff changeset
929 DEBUG_FUNCTION void
kono
parents:
diff changeset
930 debug_cluster (bb_cluster *c)
kono
parents:
diff changeset
931 {
kono
parents:
diff changeset
932 print_cluster (stderr, c);
kono
parents:
diff changeset
933 }
kono
parents:
diff changeset
934
kono
parents:
diff changeset
935 /* Update C->rep_bb, given that BB is added to the cluster. */
kono
parents:
diff changeset
936
kono
parents:
diff changeset
937 static void
kono
parents:
diff changeset
938 update_rep_bb (bb_cluster *c, basic_block bb)
kono
parents:
diff changeset
939 {
kono
parents:
diff changeset
940 /* Initial. */
kono
parents:
diff changeset
941 if (c->rep_bb == NULL)
kono
parents:
diff changeset
942 {
kono
parents:
diff changeset
943 c->rep_bb = bb;
kono
parents:
diff changeset
944 return;
kono
parents:
diff changeset
945 }
kono
parents:
diff changeset
946
kono
parents:
diff changeset
947 /* Current needs no deps, keep it. */
kono
parents:
diff changeset
948 if (BB_DEP_BB (c->rep_bb) == NULL)
kono
parents:
diff changeset
949 return;
kono
parents:
diff changeset
950
kono
parents:
diff changeset
951 /* Bb needs no deps, change rep_bb. */
kono
parents:
diff changeset
952 if (BB_DEP_BB (bb) == NULL)
kono
parents:
diff changeset
953 {
kono
parents:
diff changeset
954 c->rep_bb = bb;
kono
parents:
diff changeset
955 return;
kono
parents:
diff changeset
956 }
kono
parents:
diff changeset
957
kono
parents:
diff changeset
958 /* Bb needs last deps earlier than current, change rep_bb. A potential
kono
parents:
diff changeset
959 problem with this, is that the first deps might also be earlier, which
kono
parents:
diff changeset
960 would mean we prefer longer lifetimes for the deps. To be able to check
kono
parents:
diff changeset
961 for this, we would have to trace BB_FIRST_DEP_BB as well, besides
kono
parents:
diff changeset
962 BB_DEP_BB, which is really BB_LAST_DEP_BB.
kono
parents:
diff changeset
963 The benefit of choosing the bb with last deps earlier, is that it can
kono
parents:
diff changeset
964 potentially be used as replacement for more bbs. */
kono
parents:
diff changeset
965 if (dominated_by_p (CDI_DOMINATORS, BB_DEP_BB (c->rep_bb), BB_DEP_BB (bb)))
kono
parents:
diff changeset
966 c->rep_bb = bb;
kono
parents:
diff changeset
967 }
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 /* Add BB to cluster C. Sets BB in C->bbs, and preds of BB in C->preds. */
kono
parents:
diff changeset
970
kono
parents:
diff changeset
971 static void
kono
parents:
diff changeset
972 add_bb_to_cluster (bb_cluster *c, basic_block bb)
kono
parents:
diff changeset
973 {
kono
parents:
diff changeset
974 edge e;
kono
parents:
diff changeset
975 edge_iterator ei;
kono
parents:
diff changeset
976
kono
parents:
diff changeset
977 bitmap_set_bit (c->bbs, bb->index);
kono
parents:
diff changeset
978
kono
parents:
diff changeset
979 FOR_EACH_EDGE (e, ei, bb->preds)
kono
parents:
diff changeset
980 bitmap_set_bit (c->preds, e->src->index);
kono
parents:
diff changeset
981
kono
parents:
diff changeset
982 update_rep_bb (c, bb);
kono
parents:
diff changeset
983 }
kono
parents:
diff changeset
984
kono
parents:
diff changeset
985 /* Allocate and init new cluster. */
kono
parents:
diff changeset
986
kono
parents:
diff changeset
987 static bb_cluster *
kono
parents:
diff changeset
988 new_cluster (void)
kono
parents:
diff changeset
989 {
kono
parents:
diff changeset
990 bb_cluster *c;
kono
parents:
diff changeset
991 c = XCNEW (bb_cluster);
kono
parents:
diff changeset
992 c->bbs = BITMAP_ALLOC (NULL);
kono
parents:
diff changeset
993 c->preds = BITMAP_ALLOC (NULL);
kono
parents:
diff changeset
994 c->rep_bb = NULL;
kono
parents:
diff changeset
995 return c;
kono
parents:
diff changeset
996 }
kono
parents:
diff changeset
997
kono
parents:
diff changeset
998 /* Delete clusters. */
kono
parents:
diff changeset
999
kono
parents:
diff changeset
1000 static void
kono
parents:
diff changeset
1001 delete_cluster (bb_cluster *c)
kono
parents:
diff changeset
1002 {
kono
parents:
diff changeset
1003 if (c == NULL)
kono
parents:
diff changeset
1004 return;
kono
parents:
diff changeset
1005 BITMAP_FREE (c->bbs);
kono
parents:
diff changeset
1006 BITMAP_FREE (c->preds);
kono
parents:
diff changeset
1007 XDELETE (c);
kono
parents:
diff changeset
1008 }
kono
parents:
diff changeset
1009
kono
parents:
diff changeset
1010
kono
parents:
diff changeset
1011 /* Array that contains all clusters. */
kono
parents:
diff changeset
1012
kono
parents:
diff changeset
1013 static vec<bb_cluster *> all_clusters;
kono
parents:
diff changeset
1014
kono
parents:
diff changeset
1015 /* Allocate all cluster vectors. */
kono
parents:
diff changeset
1016
kono
parents:
diff changeset
1017 static void
kono
parents:
diff changeset
1018 alloc_cluster_vectors (void)
kono
parents:
diff changeset
1019 {
kono
parents:
diff changeset
1020 all_clusters.create (n_basic_blocks_for_fn (cfun));
kono
parents:
diff changeset
1021 }
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 /* Reset all cluster vectors. */
kono
parents:
diff changeset
1024
kono
parents:
diff changeset
1025 static void
kono
parents:
diff changeset
1026 reset_cluster_vectors (void)
kono
parents:
diff changeset
1027 {
kono
parents:
diff changeset
1028 unsigned int i;
kono
parents:
diff changeset
1029 basic_block bb;
kono
parents:
diff changeset
1030 for (i = 0; i < all_clusters.length (); ++i)
kono
parents:
diff changeset
1031 delete_cluster (all_clusters[i]);
kono
parents:
diff changeset
1032 all_clusters.truncate (0);
kono
parents:
diff changeset
1033 FOR_EACH_BB_FN (bb, cfun)
kono
parents:
diff changeset
1034 BB_CLUSTER (bb) = NULL;
kono
parents:
diff changeset
1035 }
kono
parents:
diff changeset
1036
kono
parents:
diff changeset
1037 /* Delete all cluster vectors. */
kono
parents:
diff changeset
1038
kono
parents:
diff changeset
1039 static void
kono
parents:
diff changeset
1040 delete_cluster_vectors (void)
kono
parents:
diff changeset
1041 {
kono
parents:
diff changeset
1042 unsigned int i;
kono
parents:
diff changeset
1043 for (i = 0; i < all_clusters.length (); ++i)
kono
parents:
diff changeset
1044 delete_cluster (all_clusters[i]);
kono
parents:
diff changeset
1045 all_clusters.release ();
kono
parents:
diff changeset
1046 }
kono
parents:
diff changeset
1047
kono
parents:
diff changeset
1048 /* Merge cluster C2 into C1. */
kono
parents:
diff changeset
1049
kono
parents:
diff changeset
1050 static void
kono
parents:
diff changeset
1051 merge_clusters (bb_cluster *c1, bb_cluster *c2)
kono
parents:
diff changeset
1052 {
kono
parents:
diff changeset
1053 bitmap_ior_into (c1->bbs, c2->bbs);
kono
parents:
diff changeset
1054 bitmap_ior_into (c1->preds, c2->preds);
kono
parents:
diff changeset
1055 }
kono
parents:
diff changeset
1056
kono
parents:
diff changeset
1057 /* Register equivalence of BB1 and BB2 (members of cluster C). Store c in
kono
parents:
diff changeset
1058 all_clusters, or merge c with existing cluster. */
kono
parents:
diff changeset
1059
kono
parents:
diff changeset
1060 static void
kono
parents:
diff changeset
1061 set_cluster (basic_block bb1, basic_block bb2)
kono
parents:
diff changeset
1062 {
kono
parents:
diff changeset
1063 basic_block merge_bb, other_bb;
kono
parents:
diff changeset
1064 bb_cluster *merge, *old, *c;
kono
parents:
diff changeset
1065
kono
parents:
diff changeset
1066 if (BB_CLUSTER (bb1) == NULL && BB_CLUSTER (bb2) == NULL)
kono
parents:
diff changeset
1067 {
kono
parents:
diff changeset
1068 c = new_cluster ();
kono
parents:
diff changeset
1069 add_bb_to_cluster (c, bb1);
kono
parents:
diff changeset
1070 add_bb_to_cluster (c, bb2);
kono
parents:
diff changeset
1071 BB_CLUSTER (bb1) = c;
kono
parents:
diff changeset
1072 BB_CLUSTER (bb2) = c;
kono
parents:
diff changeset
1073 c->index = all_clusters.length ();
kono
parents:
diff changeset
1074 all_clusters.safe_push (c);
kono
parents:
diff changeset
1075 }
kono
parents:
diff changeset
1076 else if (BB_CLUSTER (bb1) == NULL || BB_CLUSTER (bb2) == NULL)
kono
parents:
diff changeset
1077 {
kono
parents:
diff changeset
1078 merge_bb = BB_CLUSTER (bb1) == NULL ? bb2 : bb1;
kono
parents:
diff changeset
1079 other_bb = BB_CLUSTER (bb1) == NULL ? bb1 : bb2;
kono
parents:
diff changeset
1080 merge = BB_CLUSTER (merge_bb);
kono
parents:
diff changeset
1081 add_bb_to_cluster (merge, other_bb);
kono
parents:
diff changeset
1082 BB_CLUSTER (other_bb) = merge;
kono
parents:
diff changeset
1083 }
kono
parents:
diff changeset
1084 else if (BB_CLUSTER (bb1) != BB_CLUSTER (bb2))
kono
parents:
diff changeset
1085 {
kono
parents:
diff changeset
1086 unsigned int i;
kono
parents:
diff changeset
1087 bitmap_iterator bi;
kono
parents:
diff changeset
1088
kono
parents:
diff changeset
1089 old = BB_CLUSTER (bb2);
kono
parents:
diff changeset
1090 merge = BB_CLUSTER (bb1);
kono
parents:
diff changeset
1091 merge_clusters (merge, old);
kono
parents:
diff changeset
1092 EXECUTE_IF_SET_IN_BITMAP (old->bbs, 0, i, bi)
kono
parents:
diff changeset
1093 BB_CLUSTER (BASIC_BLOCK_FOR_FN (cfun, i)) = merge;
kono
parents:
diff changeset
1094 all_clusters[old->index] = NULL;
kono
parents:
diff changeset
1095 update_rep_bb (merge, old->rep_bb);
kono
parents:
diff changeset
1096 delete_cluster (old);
kono
parents:
diff changeset
1097 }
kono
parents:
diff changeset
1098 else
kono
parents:
diff changeset
1099 gcc_unreachable ();
kono
parents:
diff changeset
1100 }
kono
parents:
diff changeset
1101
kono
parents:
diff changeset
1102 /* Return true if gimple operands T1 and T2 have the same value. */
kono
parents:
diff changeset
1103
kono
parents:
diff changeset
1104 static bool
kono
parents:
diff changeset
1105 gimple_operand_equal_value_p (tree t1, tree t2)
kono
parents:
diff changeset
1106 {
kono
parents:
diff changeset
1107 if (t1 == t2)
kono
parents:
diff changeset
1108 return true;
kono
parents:
diff changeset
1109
kono
parents:
diff changeset
1110 if (t1 == NULL_TREE
kono
parents:
diff changeset
1111 || t2 == NULL_TREE)
kono
parents:
diff changeset
1112 return false;
kono
parents:
diff changeset
1113
kono
parents:
diff changeset
1114 if (operand_equal_p (t1, t2, OEP_MATCH_SIDE_EFFECTS))
kono
parents:
diff changeset
1115 return true;
kono
parents:
diff changeset
1116
kono
parents:
diff changeset
1117 return gvn_uses_equal (t1, t2);
kono
parents:
diff changeset
1118 }
kono
parents:
diff changeset
1119
kono
parents:
diff changeset
1120 /* Return true if gimple statements S1 and S2 are equal. Gimple_bb (s1) and
kono
parents:
diff changeset
1121 gimple_bb (s2) are members of SAME_SUCC. */
kono
parents:
diff changeset
1122
kono
parents:
diff changeset
1123 static bool
kono
parents:
diff changeset
1124 gimple_equal_p (same_succ *same_succ, gimple *s1, gimple *s2)
kono
parents:
diff changeset
1125 {
kono
parents:
diff changeset
1126 unsigned int i;
kono
parents:
diff changeset
1127 tree lhs1, lhs2;
kono
parents:
diff changeset
1128 basic_block bb1 = gimple_bb (s1), bb2 = gimple_bb (s2);
kono
parents:
diff changeset
1129 tree t1, t2;
kono
parents:
diff changeset
1130 bool inv_cond;
kono
parents:
diff changeset
1131 enum tree_code code1, code2;
kono
parents:
diff changeset
1132
kono
parents:
diff changeset
1133 if (gimple_code (s1) != gimple_code (s2))
kono
parents:
diff changeset
1134 return false;
kono
parents:
diff changeset
1135
kono
parents:
diff changeset
1136 switch (gimple_code (s1))
kono
parents:
diff changeset
1137 {
kono
parents:
diff changeset
1138 case GIMPLE_CALL:
kono
parents:
diff changeset
1139 if (!gimple_call_same_target_p (s1, s2))
kono
parents:
diff changeset
1140 return false;
kono
parents:
diff changeset
1141
kono
parents:
diff changeset
1142 t1 = gimple_call_chain (s1);
kono
parents:
diff changeset
1143 t2 = gimple_call_chain (s2);
kono
parents:
diff changeset
1144 if (!gimple_operand_equal_value_p (t1, t2))
kono
parents:
diff changeset
1145 return false;
kono
parents:
diff changeset
1146
kono
parents:
diff changeset
1147 if (gimple_call_num_args (s1) != gimple_call_num_args (s2))
kono
parents:
diff changeset
1148 return false;
kono
parents:
diff changeset
1149
kono
parents:
diff changeset
1150 for (i = 0; i < gimple_call_num_args (s1); ++i)
kono
parents:
diff changeset
1151 {
kono
parents:
diff changeset
1152 t1 = gimple_call_arg (s1, i);
kono
parents:
diff changeset
1153 t2 = gimple_call_arg (s2, i);
kono
parents:
diff changeset
1154 if (!gimple_operand_equal_value_p (t1, t2))
kono
parents:
diff changeset
1155 return false;
kono
parents:
diff changeset
1156 }
kono
parents:
diff changeset
1157
kono
parents:
diff changeset
1158 lhs1 = gimple_get_lhs (s1);
kono
parents:
diff changeset
1159 lhs2 = gimple_get_lhs (s2);
kono
parents:
diff changeset
1160 if (lhs1 == NULL_TREE && lhs2 == NULL_TREE)
kono
parents:
diff changeset
1161 return true;
kono
parents:
diff changeset
1162 if (lhs1 == NULL_TREE || lhs2 == NULL_TREE)
kono
parents:
diff changeset
1163 return false;
kono
parents:
diff changeset
1164 if (TREE_CODE (lhs1) == SSA_NAME && TREE_CODE (lhs2) == SSA_NAME)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1165 return tail_merge_valueize (lhs1) == tail_merge_valueize (lhs2);
111
kono
parents:
diff changeset
1166 return operand_equal_p (lhs1, lhs2, 0);
kono
parents:
diff changeset
1167
kono
parents:
diff changeset
1168 case GIMPLE_ASSIGN:
kono
parents:
diff changeset
1169 lhs1 = gimple_get_lhs (s1);
kono
parents:
diff changeset
1170 lhs2 = gimple_get_lhs (s2);
kono
parents:
diff changeset
1171 if (TREE_CODE (lhs1) != SSA_NAME
kono
parents:
diff changeset
1172 && TREE_CODE (lhs2) != SSA_NAME)
kono
parents:
diff changeset
1173 return (operand_equal_p (lhs1, lhs2, 0)
kono
parents:
diff changeset
1174 && gimple_operand_equal_value_p (gimple_assign_rhs1 (s1),
kono
parents:
diff changeset
1175 gimple_assign_rhs1 (s2)));
kono
parents:
diff changeset
1176 else if (TREE_CODE (lhs1) == SSA_NAME
kono
parents:
diff changeset
1177 && TREE_CODE (lhs2) == SSA_NAME)
kono
parents:
diff changeset
1178 return operand_equal_p (gimple_assign_rhs1 (s1),
kono
parents:
diff changeset
1179 gimple_assign_rhs1 (s2), 0);
kono
parents:
diff changeset
1180 return false;
kono
parents:
diff changeset
1181
kono
parents:
diff changeset
1182 case GIMPLE_COND:
kono
parents:
diff changeset
1183 t1 = gimple_cond_lhs (s1);
kono
parents:
diff changeset
1184 t2 = gimple_cond_lhs (s2);
kono
parents:
diff changeset
1185 if (!gimple_operand_equal_value_p (t1, t2))
kono
parents:
diff changeset
1186 return false;
kono
parents:
diff changeset
1187
kono
parents:
diff changeset
1188 t1 = gimple_cond_rhs (s1);
kono
parents:
diff changeset
1189 t2 = gimple_cond_rhs (s2);
kono
parents:
diff changeset
1190 if (!gimple_operand_equal_value_p (t1, t2))
kono
parents:
diff changeset
1191 return false;
kono
parents:
diff changeset
1192
kono
parents:
diff changeset
1193 code1 = gimple_expr_code (s1);
kono
parents:
diff changeset
1194 code2 = gimple_expr_code (s2);
kono
parents:
diff changeset
1195 inv_cond = (bitmap_bit_p (same_succ->inverse, bb1->index)
kono
parents:
diff changeset
1196 != bitmap_bit_p (same_succ->inverse, bb2->index));
kono
parents:
diff changeset
1197 if (inv_cond)
kono
parents:
diff changeset
1198 {
kono
parents:
diff changeset
1199 bool honor_nans = HONOR_NANS (t1);
kono
parents:
diff changeset
1200 code2 = invert_tree_comparison (code2, honor_nans);
kono
parents:
diff changeset
1201 }
kono
parents:
diff changeset
1202 return code1 == code2;
kono
parents:
diff changeset
1203
kono
parents:
diff changeset
1204 default:
kono
parents:
diff changeset
1205 return false;
kono
parents:
diff changeset
1206 }
kono
parents:
diff changeset
1207 }
kono
parents:
diff changeset
1208
kono
parents:
diff changeset
1209 /* Let GSI skip backwards over local defs. Return the earliest vuse in VUSE.
kono
parents:
diff changeset
1210 Return true in VUSE_ESCAPED if the vuse influenced a SSA_OP_DEF of one of the
kono
parents:
diff changeset
1211 processed statements. */
kono
parents:
diff changeset
1212
kono
parents:
diff changeset
1213 static void
kono
parents:
diff changeset
1214 gsi_advance_bw_nondebug_nonlocal (gimple_stmt_iterator *gsi, tree *vuse,
kono
parents:
diff changeset
1215 bool *vuse_escaped)
kono
parents:
diff changeset
1216 {
kono
parents:
diff changeset
1217 gimple *stmt;
kono
parents:
diff changeset
1218 tree lvuse;
kono
parents:
diff changeset
1219
kono
parents:
diff changeset
1220 while (true)
kono
parents:
diff changeset
1221 {
kono
parents:
diff changeset
1222 if (gsi_end_p (*gsi))
kono
parents:
diff changeset
1223 return;
kono
parents:
diff changeset
1224 stmt = gsi_stmt (*gsi);
kono
parents:
diff changeset
1225
kono
parents:
diff changeset
1226 lvuse = gimple_vuse (stmt);
kono
parents:
diff changeset
1227 if (lvuse != NULL_TREE)
kono
parents:
diff changeset
1228 {
kono
parents:
diff changeset
1229 *vuse = lvuse;
kono
parents:
diff changeset
1230 if (!ZERO_SSA_OPERANDS (stmt, SSA_OP_DEF))
kono
parents:
diff changeset
1231 *vuse_escaped = true;
kono
parents:
diff changeset
1232 }
kono
parents:
diff changeset
1233
kono
parents:
diff changeset
1234 if (!stmt_local_def (stmt))
kono
parents:
diff changeset
1235 return;
kono
parents:
diff changeset
1236 gsi_prev_nondebug (gsi);
kono
parents:
diff changeset
1237 }
kono
parents:
diff changeset
1238 }
kono
parents:
diff changeset
1239
kono
parents:
diff changeset
1240 /* Return true if equal (in the sense of gimple_equal_p) statements STMT1 and
kono
parents:
diff changeset
1241 STMT2 are allowed to be merged. */
kono
parents:
diff changeset
1242
kono
parents:
diff changeset
1243 static bool
kono
parents:
diff changeset
1244 merge_stmts_p (gimple *stmt1, gimple *stmt2)
kono
parents:
diff changeset
1245 {
kono
parents:
diff changeset
1246 /* What could be better than this here is to blacklist the bb
kono
parents:
diff changeset
1247 containing the stmt, when encountering the stmt f.i. in
kono
parents:
diff changeset
1248 same_succ_hash. */
kono
parents:
diff changeset
1249 if (is_tm_ending (stmt1))
kono
parents:
diff changeset
1250 return false;
kono
parents:
diff changeset
1251
kono
parents:
diff changeset
1252 /* Verify EH landing pads. */
kono
parents:
diff changeset
1253 if (lookup_stmt_eh_lp_fn (cfun, stmt1) != lookup_stmt_eh_lp_fn (cfun, stmt2))
kono
parents:
diff changeset
1254 return false;
kono
parents:
diff changeset
1255
kono
parents:
diff changeset
1256 if (is_gimple_call (stmt1)
kono
parents:
diff changeset
1257 && gimple_call_internal_p (stmt1))
kono
parents:
diff changeset
1258 switch (gimple_call_internal_fn (stmt1))
kono
parents:
diff changeset
1259 {
kono
parents:
diff changeset
1260 case IFN_UBSAN_NULL:
kono
parents:
diff changeset
1261 case IFN_UBSAN_BOUNDS:
kono
parents:
diff changeset
1262 case IFN_UBSAN_VPTR:
kono
parents:
diff changeset
1263 case IFN_UBSAN_CHECK_ADD:
kono
parents:
diff changeset
1264 case IFN_UBSAN_CHECK_SUB:
kono
parents:
diff changeset
1265 case IFN_UBSAN_CHECK_MUL:
kono
parents:
diff changeset
1266 case IFN_UBSAN_OBJECT_SIZE:
kono
parents:
diff changeset
1267 case IFN_UBSAN_PTR:
kono
parents:
diff changeset
1268 case IFN_ASAN_CHECK:
kono
parents:
diff changeset
1269 /* For these internal functions, gimple_location is an implicit
kono
parents:
diff changeset
1270 parameter, which will be used explicitly after expansion.
kono
parents:
diff changeset
1271 Merging these statements may cause confusing line numbers in
kono
parents:
diff changeset
1272 sanitizer messages. */
kono
parents:
diff changeset
1273 return gimple_location (stmt1) == gimple_location (stmt2);
kono
parents:
diff changeset
1274 default:
kono
parents:
diff changeset
1275 break;
kono
parents:
diff changeset
1276 }
kono
parents:
diff changeset
1277
kono
parents:
diff changeset
1278 return true;
kono
parents:
diff changeset
1279 }
kono
parents:
diff changeset
1280
kono
parents:
diff changeset
1281 /* Determines whether BB1 and BB2 (members of same_succ) are duplicates. If so,
kono
parents:
diff changeset
1282 clusters them. */
kono
parents:
diff changeset
1283
kono
parents:
diff changeset
1284 static void
kono
parents:
diff changeset
1285 find_duplicate (same_succ *same_succ, basic_block bb1, basic_block bb2)
kono
parents:
diff changeset
1286 {
kono
parents:
diff changeset
1287 gimple_stmt_iterator gsi1 = gsi_last_nondebug_bb (bb1);
kono
parents:
diff changeset
1288 gimple_stmt_iterator gsi2 = gsi_last_nondebug_bb (bb2);
kono
parents:
diff changeset
1289 tree vuse1 = NULL_TREE, vuse2 = NULL_TREE;
kono
parents:
diff changeset
1290 bool vuse_escaped = false;
kono
parents:
diff changeset
1291
kono
parents:
diff changeset
1292 gsi_advance_bw_nondebug_nonlocal (&gsi1, &vuse1, &vuse_escaped);
kono
parents:
diff changeset
1293 gsi_advance_bw_nondebug_nonlocal (&gsi2, &vuse2, &vuse_escaped);
kono
parents:
diff changeset
1294
kono
parents:
diff changeset
1295 while (!gsi_end_p (gsi1) && !gsi_end_p (gsi2))
kono
parents:
diff changeset
1296 {
kono
parents:
diff changeset
1297 gimple *stmt1 = gsi_stmt (gsi1);
kono
parents:
diff changeset
1298 gimple *stmt2 = gsi_stmt (gsi2);
kono
parents:
diff changeset
1299
kono
parents:
diff changeset
1300 if (gimple_code (stmt1) == GIMPLE_LABEL
kono
parents:
diff changeset
1301 && gimple_code (stmt2) == GIMPLE_LABEL)
kono
parents:
diff changeset
1302 break;
kono
parents:
diff changeset
1303
kono
parents:
diff changeset
1304 if (!gimple_equal_p (same_succ, stmt1, stmt2))
kono
parents:
diff changeset
1305 return;
kono
parents:
diff changeset
1306
kono
parents:
diff changeset
1307 if (!merge_stmts_p (stmt1, stmt2))
kono
parents:
diff changeset
1308 return;
kono
parents:
diff changeset
1309
kono
parents:
diff changeset
1310 gsi_prev_nondebug (&gsi1);
kono
parents:
diff changeset
1311 gsi_prev_nondebug (&gsi2);
kono
parents:
diff changeset
1312 gsi_advance_bw_nondebug_nonlocal (&gsi1, &vuse1, &vuse_escaped);
kono
parents:
diff changeset
1313 gsi_advance_bw_nondebug_nonlocal (&gsi2, &vuse2, &vuse_escaped);
kono
parents:
diff changeset
1314 }
kono
parents:
diff changeset
1315
kono
parents:
diff changeset
1316 while (!gsi_end_p (gsi1) && gimple_code (gsi_stmt (gsi1)) == GIMPLE_LABEL)
kono
parents:
diff changeset
1317 {
kono
parents:
diff changeset
1318 tree label = gimple_label_label (as_a <glabel *> (gsi_stmt (gsi1)));
kono
parents:
diff changeset
1319 if (DECL_NONLOCAL (label) || FORCED_LABEL (label))
kono
parents:
diff changeset
1320 return;
kono
parents:
diff changeset
1321 gsi_prev (&gsi1);
kono
parents:
diff changeset
1322 }
kono
parents:
diff changeset
1323 while (!gsi_end_p (gsi2) && gimple_code (gsi_stmt (gsi2)) == GIMPLE_LABEL)
kono
parents:
diff changeset
1324 {
kono
parents:
diff changeset
1325 tree label = gimple_label_label (as_a <glabel *> (gsi_stmt (gsi2)));
kono
parents:
diff changeset
1326 if (DECL_NONLOCAL (label) || FORCED_LABEL (label))
kono
parents:
diff changeset
1327 return;
kono
parents:
diff changeset
1328 gsi_prev (&gsi2);
kono
parents:
diff changeset
1329 }
kono
parents:
diff changeset
1330 if (!(gsi_end_p (gsi1) && gsi_end_p (gsi2)))
kono
parents:
diff changeset
1331 return;
kono
parents:
diff changeset
1332
kono
parents:
diff changeset
1333 /* If the incoming vuses are not the same, and the vuse escaped into an
kono
parents:
diff changeset
1334 SSA_OP_DEF, then merging the 2 blocks will change the value of the def,
kono
parents:
diff changeset
1335 which potentially means the semantics of one of the blocks will be changed.
kono
parents:
diff changeset
1336 TODO: make this check more precise. */
kono
parents:
diff changeset
1337 if (vuse_escaped && vuse1 != vuse2)
kono
parents:
diff changeset
1338 return;
kono
parents:
diff changeset
1339
kono
parents:
diff changeset
1340 if (dump_file)
kono
parents:
diff changeset
1341 fprintf (dump_file, "find_duplicates: <bb %d> duplicate of <bb %d>\n",
kono
parents:
diff changeset
1342 bb1->index, bb2->index);
kono
parents:
diff changeset
1343
kono
parents:
diff changeset
1344 set_cluster (bb1, bb2);
kono
parents:
diff changeset
1345 }
kono
parents:
diff changeset
1346
kono
parents:
diff changeset
1347 /* Returns whether for all phis in DEST the phi alternatives for E1 and
kono
parents:
diff changeset
1348 E2 are equal. */
kono
parents:
diff changeset
1349
kono
parents:
diff changeset
1350 static bool
kono
parents:
diff changeset
1351 same_phi_alternatives_1 (basic_block dest, edge e1, edge e2)
kono
parents:
diff changeset
1352 {
kono
parents:
diff changeset
1353 int n1 = e1->dest_idx, n2 = e2->dest_idx;
kono
parents:
diff changeset
1354 gphi_iterator gsi;
kono
parents:
diff changeset
1355
kono
parents:
diff changeset
1356 for (gsi = gsi_start_phis (dest); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents:
diff changeset
1357 {
kono
parents:
diff changeset
1358 gphi *phi = gsi.phi ();
kono
parents:
diff changeset
1359 tree lhs = gimple_phi_result (phi);
kono
parents:
diff changeset
1360 tree val1 = gimple_phi_arg_def (phi, n1);
kono
parents:
diff changeset
1361 tree val2 = gimple_phi_arg_def (phi, n2);
kono
parents:
diff changeset
1362
kono
parents:
diff changeset
1363 if (virtual_operand_p (lhs))
kono
parents:
diff changeset
1364 continue;
kono
parents:
diff changeset
1365
kono
parents:
diff changeset
1366 if (operand_equal_for_phi_arg_p (val1, val2))
kono
parents:
diff changeset
1367 continue;
kono
parents:
diff changeset
1368 if (gvn_uses_equal (val1, val2))
kono
parents:
diff changeset
1369 continue;
kono
parents:
diff changeset
1370
kono
parents:
diff changeset
1371 return false;
kono
parents:
diff changeset
1372 }
kono
parents:
diff changeset
1373
kono
parents:
diff changeset
1374 return true;
kono
parents:
diff changeset
1375 }
kono
parents:
diff changeset
1376
kono
parents:
diff changeset
1377 /* Returns whether for all successors of BB1 and BB2 (members of SAME_SUCC), the
kono
parents:
diff changeset
1378 phi alternatives for BB1 and BB2 are equal. */
kono
parents:
diff changeset
1379
kono
parents:
diff changeset
1380 static bool
kono
parents:
diff changeset
1381 same_phi_alternatives (same_succ *same_succ, basic_block bb1, basic_block bb2)
kono
parents:
diff changeset
1382 {
kono
parents:
diff changeset
1383 unsigned int s;
kono
parents:
diff changeset
1384 bitmap_iterator bs;
kono
parents:
diff changeset
1385 edge e1, e2;
kono
parents:
diff changeset
1386 basic_block succ;
kono
parents:
diff changeset
1387
kono
parents:
diff changeset
1388 EXECUTE_IF_SET_IN_BITMAP (same_succ->succs, 0, s, bs)
kono
parents:
diff changeset
1389 {
kono
parents:
diff changeset
1390 succ = BASIC_BLOCK_FOR_FN (cfun, s);
kono
parents:
diff changeset
1391 e1 = find_edge (bb1, succ);
kono
parents:
diff changeset
1392 e2 = find_edge (bb2, succ);
kono
parents:
diff changeset
1393 if (e1->flags & EDGE_COMPLEX
kono
parents:
diff changeset
1394 || e2->flags & EDGE_COMPLEX)
kono
parents:
diff changeset
1395 return false;
kono
parents:
diff changeset
1396
kono
parents:
diff changeset
1397 /* For all phis in bb, the phi alternatives for e1 and e2 need to have
kono
parents:
diff changeset
1398 the same value. */
kono
parents:
diff changeset
1399 if (!same_phi_alternatives_1 (succ, e1, e2))
kono
parents:
diff changeset
1400 return false;
kono
parents:
diff changeset
1401 }
kono
parents:
diff changeset
1402
kono
parents:
diff changeset
1403 return true;
kono
parents:
diff changeset
1404 }
kono
parents:
diff changeset
1405
kono
parents:
diff changeset
1406 /* Return true if BB has non-vop phis. */
kono
parents:
diff changeset
1407
kono
parents:
diff changeset
1408 static bool
kono
parents:
diff changeset
1409 bb_has_non_vop_phi (basic_block bb)
kono
parents:
diff changeset
1410 {
kono
parents:
diff changeset
1411 gimple_seq phis = phi_nodes (bb);
kono
parents:
diff changeset
1412 gimple *phi;
kono
parents:
diff changeset
1413
kono
parents:
diff changeset
1414 if (phis == NULL)
kono
parents:
diff changeset
1415 return false;
kono
parents:
diff changeset
1416
kono
parents:
diff changeset
1417 if (!gimple_seq_singleton_p (phis))
kono
parents:
diff changeset
1418 return true;
kono
parents:
diff changeset
1419
kono
parents:
diff changeset
1420 phi = gimple_seq_first_stmt (phis);
kono
parents:
diff changeset
1421 return !virtual_operand_p (gimple_phi_result (phi));
kono
parents:
diff changeset
1422 }
kono
parents:
diff changeset
1423
kono
parents:
diff changeset
1424 /* Returns true if redirecting the incoming edges of FROM to TO maintains the
kono
parents:
diff changeset
1425 invariant that uses in FROM are dominates by their defs. */
kono
parents:
diff changeset
1426
kono
parents:
diff changeset
1427 static bool
kono
parents:
diff changeset
1428 deps_ok_for_redirect_from_bb_to_bb (basic_block from, basic_block to)
kono
parents:
diff changeset
1429 {
kono
parents:
diff changeset
1430 basic_block cd, dep_bb = BB_DEP_BB (to);
kono
parents:
diff changeset
1431 edge_iterator ei;
kono
parents:
diff changeset
1432 edge e;
kono
parents:
diff changeset
1433
kono
parents:
diff changeset
1434 if (dep_bb == NULL)
kono
parents:
diff changeset
1435 return true;
kono
parents:
diff changeset
1436
kono
parents:
diff changeset
1437 bitmap from_preds = BITMAP_ALLOC (NULL);
kono
parents:
diff changeset
1438 FOR_EACH_EDGE (e, ei, from->preds)
kono
parents:
diff changeset
1439 bitmap_set_bit (from_preds, e->src->index);
kono
parents:
diff changeset
1440 cd = nearest_common_dominator_for_set (CDI_DOMINATORS, from_preds);
kono
parents:
diff changeset
1441 BITMAP_FREE (from_preds);
kono
parents:
diff changeset
1442
kono
parents:
diff changeset
1443 return dominated_by_p (CDI_DOMINATORS, dep_bb, cd);
kono
parents:
diff changeset
1444 }
kono
parents:
diff changeset
1445
kono
parents:
diff changeset
1446 /* Returns true if replacing BB1 (or its replacement bb) by BB2 (or its
kono
parents:
diff changeset
1447 replacement bb) and vice versa maintains the invariant that uses in the
kono
parents:
diff changeset
1448 replacement are dominates by their defs. */
kono
parents:
diff changeset
1449
kono
parents:
diff changeset
1450 static bool
kono
parents:
diff changeset
1451 deps_ok_for_redirect (basic_block bb1, basic_block bb2)
kono
parents:
diff changeset
1452 {
kono
parents:
diff changeset
1453 if (BB_CLUSTER (bb1) != NULL)
kono
parents:
diff changeset
1454 bb1 = BB_CLUSTER (bb1)->rep_bb;
kono
parents:
diff changeset
1455
kono
parents:
diff changeset
1456 if (BB_CLUSTER (bb2) != NULL)
kono
parents:
diff changeset
1457 bb2 = BB_CLUSTER (bb2)->rep_bb;
kono
parents:
diff changeset
1458
kono
parents:
diff changeset
1459 return (deps_ok_for_redirect_from_bb_to_bb (bb1, bb2)
kono
parents:
diff changeset
1460 && deps_ok_for_redirect_from_bb_to_bb (bb2, bb1));
kono
parents:
diff changeset
1461 }
kono
parents:
diff changeset
1462
kono
parents:
diff changeset
1463 /* Within SAME_SUCC->bbs, find clusters of bbs which can be merged. */
kono
parents:
diff changeset
1464
kono
parents:
diff changeset
1465 static void
kono
parents:
diff changeset
1466 find_clusters_1 (same_succ *same_succ)
kono
parents:
diff changeset
1467 {
kono
parents:
diff changeset
1468 basic_block bb1, bb2;
kono
parents:
diff changeset
1469 unsigned int i, j;
kono
parents:
diff changeset
1470 bitmap_iterator bi, bj;
kono
parents:
diff changeset
1471 int nr_comparisons;
kono
parents:
diff changeset
1472 int max_comparisons = PARAM_VALUE (PARAM_MAX_TAIL_MERGE_COMPARISONS);
kono
parents:
diff changeset
1473
kono
parents:
diff changeset
1474 EXECUTE_IF_SET_IN_BITMAP (same_succ->bbs, 0, i, bi)
kono
parents:
diff changeset
1475 {
kono
parents:
diff changeset
1476 bb1 = BASIC_BLOCK_FOR_FN (cfun, i);
kono
parents:
diff changeset
1477
kono
parents:
diff changeset
1478 /* TODO: handle blocks with phi-nodes. We'll have to find corresponding
kono
parents:
diff changeset
1479 phi-nodes in bb1 and bb2, with the same alternatives for the same
kono
parents:
diff changeset
1480 preds. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1481 if (bb_has_non_vop_phi (bb1) || bb_has_eh_pred (bb1)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1482 || bb_has_abnormal_pred (bb1))
111
kono
parents:
diff changeset
1483 continue;
kono
parents:
diff changeset
1484
kono
parents:
diff changeset
1485 nr_comparisons = 0;
kono
parents:
diff changeset
1486 EXECUTE_IF_SET_IN_BITMAP (same_succ->bbs, i + 1, j, bj)
kono
parents:
diff changeset
1487 {
kono
parents:
diff changeset
1488 bb2 = BASIC_BLOCK_FOR_FN (cfun, j);
kono
parents:
diff changeset
1489
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1490 if (bb_has_non_vop_phi (bb2) || bb_has_eh_pred (bb2)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1491 || bb_has_abnormal_pred (bb2))
111
kono
parents:
diff changeset
1492 continue;
kono
parents:
diff changeset
1493
kono
parents:
diff changeset
1494 if (BB_CLUSTER (bb1) != NULL && BB_CLUSTER (bb1) == BB_CLUSTER (bb2))
kono
parents:
diff changeset
1495 continue;
kono
parents:
diff changeset
1496
kono
parents:
diff changeset
1497 /* Limit quadratic behavior. */
kono
parents:
diff changeset
1498 nr_comparisons++;
kono
parents:
diff changeset
1499 if (nr_comparisons > max_comparisons)
kono
parents:
diff changeset
1500 break;
kono
parents:
diff changeset
1501
kono
parents:
diff changeset
1502 /* This is a conservative dependency check. We could test more
kono
parents:
diff changeset
1503 precise for allowed replacement direction. */
kono
parents:
diff changeset
1504 if (!deps_ok_for_redirect (bb1, bb2))
kono
parents:
diff changeset
1505 continue;
kono
parents:
diff changeset
1506
kono
parents:
diff changeset
1507 if (!(same_phi_alternatives (same_succ, bb1, bb2)))
kono
parents:
diff changeset
1508 continue;
kono
parents:
diff changeset
1509
kono
parents:
diff changeset
1510 find_duplicate (same_succ, bb1, bb2);
kono
parents:
diff changeset
1511 }
kono
parents:
diff changeset
1512 }
kono
parents:
diff changeset
1513 }
kono
parents:
diff changeset
1514
kono
parents:
diff changeset
1515 /* Find clusters of bbs which can be merged. */
kono
parents:
diff changeset
1516
kono
parents:
diff changeset
1517 static void
kono
parents:
diff changeset
1518 find_clusters (void)
kono
parents:
diff changeset
1519 {
kono
parents:
diff changeset
1520 same_succ *same;
kono
parents:
diff changeset
1521
kono
parents:
diff changeset
1522 while (!worklist.is_empty ())
kono
parents:
diff changeset
1523 {
kono
parents:
diff changeset
1524 same = worklist.pop ();
kono
parents:
diff changeset
1525 same->in_worklist = false;
kono
parents:
diff changeset
1526 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents:
diff changeset
1527 {
kono
parents:
diff changeset
1528 fprintf (dump_file, "processing worklist entry\n");
kono
parents:
diff changeset
1529 same_succ_print (dump_file, same);
kono
parents:
diff changeset
1530 }
kono
parents:
diff changeset
1531 find_clusters_1 (same);
kono
parents:
diff changeset
1532 }
kono
parents:
diff changeset
1533 }
kono
parents:
diff changeset
1534
kono
parents:
diff changeset
1535 /* Returns the vop phi of BB, if any. */
kono
parents:
diff changeset
1536
kono
parents:
diff changeset
1537 static gphi *
kono
parents:
diff changeset
1538 vop_phi (basic_block bb)
kono
parents:
diff changeset
1539 {
kono
parents:
diff changeset
1540 gphi *stmt;
kono
parents:
diff changeset
1541 gphi_iterator gsi;
kono
parents:
diff changeset
1542 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents:
diff changeset
1543 {
kono
parents:
diff changeset
1544 stmt = gsi.phi ();
kono
parents:
diff changeset
1545 if (! virtual_operand_p (gimple_phi_result (stmt)))
kono
parents:
diff changeset
1546 continue;
kono
parents:
diff changeset
1547 return stmt;
kono
parents:
diff changeset
1548 }
kono
parents:
diff changeset
1549 return NULL;
kono
parents:
diff changeset
1550 }
kono
parents:
diff changeset
1551
kono
parents:
diff changeset
1552 /* Redirect all edges from BB1 to BB2, removes BB1 and marks it as removed. */
kono
parents:
diff changeset
1553
kono
parents:
diff changeset
1554 static void
kono
parents:
diff changeset
1555 replace_block_by (basic_block bb1, basic_block bb2)
kono
parents:
diff changeset
1556 {
kono
parents:
diff changeset
1557 edge pred_edge;
kono
parents:
diff changeset
1558 unsigned int i;
kono
parents:
diff changeset
1559 gphi *bb2_phi;
kono
parents:
diff changeset
1560
kono
parents:
diff changeset
1561 bb2_phi = vop_phi (bb2);
kono
parents:
diff changeset
1562
kono
parents:
diff changeset
1563 /* Mark the basic block as deleted. */
kono
parents:
diff changeset
1564 mark_basic_block_deleted (bb1);
kono
parents:
diff changeset
1565
kono
parents:
diff changeset
1566 /* Redirect the incoming edges of bb1 to bb2. */
kono
parents:
diff changeset
1567 for (i = EDGE_COUNT (bb1->preds); i > 0 ; --i)
kono
parents:
diff changeset
1568 {
kono
parents:
diff changeset
1569 pred_edge = EDGE_PRED (bb1, i - 1);
kono
parents:
diff changeset
1570 pred_edge = redirect_edge_and_branch (pred_edge, bb2);
kono
parents:
diff changeset
1571 gcc_assert (pred_edge != NULL);
kono
parents:
diff changeset
1572
kono
parents:
diff changeset
1573 if (bb2_phi == NULL)
kono
parents:
diff changeset
1574 continue;
kono
parents:
diff changeset
1575
kono
parents:
diff changeset
1576 /* The phi might have run out of capacity when the redirect added an
kono
parents:
diff changeset
1577 argument, which means it could have been replaced. Refresh it. */
kono
parents:
diff changeset
1578 bb2_phi = vop_phi (bb2);
kono
parents:
diff changeset
1579
kono
parents:
diff changeset
1580 add_phi_arg (bb2_phi, SSA_NAME_VAR (gimple_phi_result (bb2_phi)),
kono
parents:
diff changeset
1581 pred_edge, UNKNOWN_LOCATION);
kono
parents:
diff changeset
1582 }
kono
parents:
diff changeset
1583
kono
parents:
diff changeset
1584
kono
parents:
diff changeset
1585 /* Merge the outgoing edge counts from bb1 onto bb2. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1586 edge e1, e2;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1587 edge_iterator ei;
111
kono
parents:
diff changeset
1588
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1589 if (bb2->count.initialized_p ())
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1590 FOR_EACH_EDGE (e1, ei, bb1->succs)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1591 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1592 e2 = find_edge (bb2, e1->dest);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1593 gcc_assert (e2);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1594
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1595 /* If probabilities are same, we are done.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1596 If counts are nonzero we can distribute accordingly. In remaining
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1597 cases just avreage the values and hope for the best. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1598 e2->probability = e1->probability.combine_with_count
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1599 (bb1->count, e2->probability, bb2->count);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1600 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1601 bb2->count += bb1->count;
111
kono
parents:
diff changeset
1602
kono
parents:
diff changeset
1603 /* Move over any user labels from bb1 after the bb2 labels. */
kono
parents:
diff changeset
1604 gimple_stmt_iterator gsi1 = gsi_start_bb (bb1);
kono
parents:
diff changeset
1605 if (!gsi_end_p (gsi1) && gimple_code (gsi_stmt (gsi1)) == GIMPLE_LABEL)
kono
parents:
diff changeset
1606 {
kono
parents:
diff changeset
1607 gimple_stmt_iterator gsi2 = gsi_after_labels (bb2);
kono
parents:
diff changeset
1608 while (!gsi_end_p (gsi1)
kono
parents:
diff changeset
1609 && gimple_code (gsi_stmt (gsi1)) == GIMPLE_LABEL)
kono
parents:
diff changeset
1610 {
kono
parents:
diff changeset
1611 tree label = gimple_label_label (as_a <glabel *> (gsi_stmt (gsi1)));
kono
parents:
diff changeset
1612 gcc_assert (!DECL_NONLOCAL (label) && !FORCED_LABEL (label));
kono
parents:
diff changeset
1613 if (DECL_ARTIFICIAL (label))
kono
parents:
diff changeset
1614 gsi_next (&gsi1);
kono
parents:
diff changeset
1615 else
kono
parents:
diff changeset
1616 gsi_move_before (&gsi1, &gsi2);
kono
parents:
diff changeset
1617 }
kono
parents:
diff changeset
1618 }
kono
parents:
diff changeset
1619
kono
parents:
diff changeset
1620 /* Clear range info from all stmts in BB2 -- this transformation
kono
parents:
diff changeset
1621 could make them out of date. */
kono
parents:
diff changeset
1622 reset_flow_sensitive_info_in_bb (bb2);
kono
parents:
diff changeset
1623
kono
parents:
diff changeset
1624 /* Do updates that use bb1, before deleting bb1. */
kono
parents:
diff changeset
1625 release_last_vdef (bb1);
kono
parents:
diff changeset
1626 same_succ_flush_bb (bb1);
kono
parents:
diff changeset
1627
kono
parents:
diff changeset
1628 delete_basic_block (bb1);
kono
parents:
diff changeset
1629 }
kono
parents:
diff changeset
1630
kono
parents:
diff changeset
1631 /* Bbs for which update_debug_stmt need to be called. */
kono
parents:
diff changeset
1632
kono
parents:
diff changeset
1633 static bitmap update_bbs;
kono
parents:
diff changeset
1634
kono
parents:
diff changeset
1635 /* For each cluster in all_clusters, merge all cluster->bbs. Returns
kono
parents:
diff changeset
1636 number of bbs removed. */
kono
parents:
diff changeset
1637
kono
parents:
diff changeset
1638 static int
kono
parents:
diff changeset
1639 apply_clusters (void)
kono
parents:
diff changeset
1640 {
kono
parents:
diff changeset
1641 basic_block bb1, bb2;
kono
parents:
diff changeset
1642 bb_cluster *c;
kono
parents:
diff changeset
1643 unsigned int i, j;
kono
parents:
diff changeset
1644 bitmap_iterator bj;
kono
parents:
diff changeset
1645 int nr_bbs_removed = 0;
kono
parents:
diff changeset
1646
kono
parents:
diff changeset
1647 for (i = 0; i < all_clusters.length (); ++i)
kono
parents:
diff changeset
1648 {
kono
parents:
diff changeset
1649 c = all_clusters[i];
kono
parents:
diff changeset
1650 if (c == NULL)
kono
parents:
diff changeset
1651 continue;
kono
parents:
diff changeset
1652
kono
parents:
diff changeset
1653 bb2 = c->rep_bb;
kono
parents:
diff changeset
1654 bitmap_set_bit (update_bbs, bb2->index);
kono
parents:
diff changeset
1655
kono
parents:
diff changeset
1656 bitmap_clear_bit (c->bbs, bb2->index);
kono
parents:
diff changeset
1657 EXECUTE_IF_SET_IN_BITMAP (c->bbs, 0, j, bj)
kono
parents:
diff changeset
1658 {
kono
parents:
diff changeset
1659 bb1 = BASIC_BLOCK_FOR_FN (cfun, j);
kono
parents:
diff changeset
1660 bitmap_clear_bit (update_bbs, bb1->index);
kono
parents:
diff changeset
1661
kono
parents:
diff changeset
1662 replace_block_by (bb1, bb2);
kono
parents:
diff changeset
1663 nr_bbs_removed++;
kono
parents:
diff changeset
1664 }
kono
parents:
diff changeset
1665 }
kono
parents:
diff changeset
1666
kono
parents:
diff changeset
1667 return nr_bbs_removed;
kono
parents:
diff changeset
1668 }
kono
parents:
diff changeset
1669
kono
parents:
diff changeset
1670 /* Resets debug statement STMT if it has uses that are not dominated by their
kono
parents:
diff changeset
1671 defs. */
kono
parents:
diff changeset
1672
kono
parents:
diff changeset
1673 static void
kono
parents:
diff changeset
1674 update_debug_stmt (gimple *stmt)
kono
parents:
diff changeset
1675 {
kono
parents:
diff changeset
1676 use_operand_p use_p;
kono
parents:
diff changeset
1677 ssa_op_iter oi;
kono
parents:
diff changeset
1678 basic_block bbuse;
kono
parents:
diff changeset
1679
kono
parents:
diff changeset
1680 if (!gimple_debug_bind_p (stmt))
kono
parents:
diff changeset
1681 return;
kono
parents:
diff changeset
1682
kono
parents:
diff changeset
1683 bbuse = gimple_bb (stmt);
kono
parents:
diff changeset
1684 FOR_EACH_PHI_OR_STMT_USE (use_p, stmt, oi, SSA_OP_USE)
kono
parents:
diff changeset
1685 {
kono
parents:
diff changeset
1686 tree name = USE_FROM_PTR (use_p);
kono
parents:
diff changeset
1687 gimple *def_stmt = SSA_NAME_DEF_STMT (name);
kono
parents:
diff changeset
1688 basic_block bbdef = gimple_bb (def_stmt);
kono
parents:
diff changeset
1689 if (bbdef == NULL || bbuse == bbdef
kono
parents:
diff changeset
1690 || dominated_by_p (CDI_DOMINATORS, bbuse, bbdef))
kono
parents:
diff changeset
1691 continue;
kono
parents:
diff changeset
1692
kono
parents:
diff changeset
1693 gimple_debug_bind_reset_value (stmt);
kono
parents:
diff changeset
1694 update_stmt (stmt);
kono
parents:
diff changeset
1695 break;
kono
parents:
diff changeset
1696 }
kono
parents:
diff changeset
1697 }
kono
parents:
diff changeset
1698
kono
parents:
diff changeset
1699 /* Resets all debug statements that have uses that are not
kono
parents:
diff changeset
1700 dominated by their defs. */
kono
parents:
diff changeset
1701
kono
parents:
diff changeset
1702 static void
kono
parents:
diff changeset
1703 update_debug_stmts (void)
kono
parents:
diff changeset
1704 {
kono
parents:
diff changeset
1705 basic_block bb;
kono
parents:
diff changeset
1706 bitmap_iterator bi;
kono
parents:
diff changeset
1707 unsigned int i;
kono
parents:
diff changeset
1708
kono
parents:
diff changeset
1709 EXECUTE_IF_SET_IN_BITMAP (update_bbs, 0, i, bi)
kono
parents:
diff changeset
1710 {
kono
parents:
diff changeset
1711 gimple *stmt;
kono
parents:
diff changeset
1712 gimple_stmt_iterator gsi;
kono
parents:
diff changeset
1713
kono
parents:
diff changeset
1714 bb = BASIC_BLOCK_FOR_FN (cfun, i);
kono
parents:
diff changeset
1715 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents:
diff changeset
1716 {
kono
parents:
diff changeset
1717 stmt = gsi_stmt (gsi);
kono
parents:
diff changeset
1718 if (!is_gimple_debug (stmt))
kono
parents:
diff changeset
1719 continue;
kono
parents:
diff changeset
1720 update_debug_stmt (stmt);
kono
parents:
diff changeset
1721 }
kono
parents:
diff changeset
1722 }
kono
parents:
diff changeset
1723 }
kono
parents:
diff changeset
1724
kono
parents:
diff changeset
1725 /* Runs tail merge optimization. */
kono
parents:
diff changeset
1726
kono
parents:
diff changeset
1727 unsigned int
kono
parents:
diff changeset
1728 tail_merge_optimize (unsigned int todo)
kono
parents:
diff changeset
1729 {
kono
parents:
diff changeset
1730 int nr_bbs_removed_total = 0;
kono
parents:
diff changeset
1731 int nr_bbs_removed;
kono
parents:
diff changeset
1732 bool loop_entered = false;
kono
parents:
diff changeset
1733 int iteration_nr = 0;
kono
parents:
diff changeset
1734 int max_iterations = PARAM_VALUE (PARAM_MAX_TAIL_MERGE_ITERATIONS);
kono
parents:
diff changeset
1735
kono
parents:
diff changeset
1736 if (!flag_tree_tail_merge
kono
parents:
diff changeset
1737 || max_iterations == 0)
kono
parents:
diff changeset
1738 return 0;
kono
parents:
diff changeset
1739
kono
parents:
diff changeset
1740 timevar_push (TV_TREE_TAIL_MERGE);
kono
parents:
diff changeset
1741
kono
parents:
diff changeset
1742 /* We enter from PRE which has critical edges split. Elimination
kono
parents:
diff changeset
1743 does not process trivially dead code so cleanup the CFG if we
kono
parents:
diff changeset
1744 are told so. And re-split critical edges then. */
kono
parents:
diff changeset
1745 if (todo & TODO_cleanup_cfg)
kono
parents:
diff changeset
1746 {
kono
parents:
diff changeset
1747 cleanup_tree_cfg ();
kono
parents:
diff changeset
1748 todo &= ~TODO_cleanup_cfg;
kono
parents:
diff changeset
1749 split_critical_edges ();
kono
parents:
diff changeset
1750 }
kono
parents:
diff changeset
1751
kono
parents:
diff changeset
1752 if (!dom_info_available_p (CDI_DOMINATORS))
kono
parents:
diff changeset
1753 {
kono
parents:
diff changeset
1754 /* PRE can leave us with unreachable blocks, remove them now. */
kono
parents:
diff changeset
1755 delete_unreachable_blocks ();
kono
parents:
diff changeset
1756 calculate_dominance_info (CDI_DOMINATORS);
kono
parents:
diff changeset
1757 }
kono
parents:
diff changeset
1758 init_worklist ();
kono
parents:
diff changeset
1759
kono
parents:
diff changeset
1760 while (!worklist.is_empty ())
kono
parents:
diff changeset
1761 {
kono
parents:
diff changeset
1762 if (!loop_entered)
kono
parents:
diff changeset
1763 {
kono
parents:
diff changeset
1764 loop_entered = true;
kono
parents:
diff changeset
1765 alloc_cluster_vectors ();
kono
parents:
diff changeset
1766 update_bbs = BITMAP_ALLOC (NULL);
kono
parents:
diff changeset
1767 }
kono
parents:
diff changeset
1768 else
kono
parents:
diff changeset
1769 reset_cluster_vectors ();
kono
parents:
diff changeset
1770
kono
parents:
diff changeset
1771 iteration_nr++;
kono
parents:
diff changeset
1772 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents:
diff changeset
1773 fprintf (dump_file, "worklist iteration #%d\n", iteration_nr);
kono
parents:
diff changeset
1774
kono
parents:
diff changeset
1775 find_clusters ();
kono
parents:
diff changeset
1776 gcc_assert (worklist.is_empty ());
kono
parents:
diff changeset
1777 if (all_clusters.is_empty ())
kono
parents:
diff changeset
1778 break;
kono
parents:
diff changeset
1779
kono
parents:
diff changeset
1780 nr_bbs_removed = apply_clusters ();
kono
parents:
diff changeset
1781 nr_bbs_removed_total += nr_bbs_removed;
kono
parents:
diff changeset
1782 if (nr_bbs_removed == 0)
kono
parents:
diff changeset
1783 break;
kono
parents:
diff changeset
1784
kono
parents:
diff changeset
1785 free_dominance_info (CDI_DOMINATORS);
kono
parents:
diff changeset
1786
kono
parents:
diff changeset
1787 if (iteration_nr == max_iterations)
kono
parents:
diff changeset
1788 break;
kono
parents:
diff changeset
1789
kono
parents:
diff changeset
1790 calculate_dominance_info (CDI_DOMINATORS);
kono
parents:
diff changeset
1791 update_worklist ();
kono
parents:
diff changeset
1792 }
kono
parents:
diff changeset
1793
kono
parents:
diff changeset
1794 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents:
diff changeset
1795 fprintf (dump_file, "htab collision / search: %f\n",
kono
parents:
diff changeset
1796 same_succ_htab->collisions ());
kono
parents:
diff changeset
1797
kono
parents:
diff changeset
1798 if (nr_bbs_removed_total > 0)
kono
parents:
diff changeset
1799 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1800 if (MAY_HAVE_DEBUG_BIND_STMTS)
111
kono
parents:
diff changeset
1801 {
kono
parents:
diff changeset
1802 calculate_dominance_info (CDI_DOMINATORS);
kono
parents:
diff changeset
1803 update_debug_stmts ();
kono
parents:
diff changeset
1804 }
kono
parents:
diff changeset
1805
kono
parents:
diff changeset
1806 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents:
diff changeset
1807 {
kono
parents:
diff changeset
1808 fprintf (dump_file, "Before TODOs.\n");
kono
parents:
diff changeset
1809 dump_function_to_file (current_function_decl, dump_file, dump_flags);
kono
parents:
diff changeset
1810 }
kono
parents:
diff changeset
1811
kono
parents:
diff changeset
1812 mark_virtual_operands_for_renaming (cfun);
kono
parents:
diff changeset
1813 }
kono
parents:
diff changeset
1814
kono
parents:
diff changeset
1815 delete_worklist ();
kono
parents:
diff changeset
1816 if (loop_entered)
kono
parents:
diff changeset
1817 {
kono
parents:
diff changeset
1818 delete_cluster_vectors ();
kono
parents:
diff changeset
1819 BITMAP_FREE (update_bbs);
kono
parents:
diff changeset
1820 }
kono
parents:
diff changeset
1821
kono
parents:
diff changeset
1822 timevar_pop (TV_TREE_TAIL_MERGE);
kono
parents:
diff changeset
1823
kono
parents:
diff changeset
1824 return todo;
kono
parents:
diff changeset
1825 }