annotate gcc/tree-ssa-tail-merge.c @ 158:494b0b89df80 default tip

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