Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-outof-ssa.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | f6334be47118 |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* Convert a program in SSA form into Normal form. | 1 /* Convert a program in SSA form into Normal form. |
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 | 2 Copyright (C) 2004-2017 Free Software Foundation, Inc. |
3 Free Software Foundation, Inc. | |
4 Contributed by Andrew Macleod <amacleod@redhat.com> | 3 Contributed by Andrew Macleod <amacleod@redhat.com> |
5 | 4 |
6 This file is part of GCC. | 5 This file is part of GCC. |
7 | 6 |
8 GCC is free software; you can redistribute it and/or modify | 7 GCC is free software; you can redistribute it and/or modify |
20 <http://www.gnu.org/licenses/>. */ | 19 <http://www.gnu.org/licenses/>. */ |
21 | 20 |
22 #include "config.h" | 21 #include "config.h" |
23 #include "system.h" | 22 #include "system.h" |
24 #include "coretypes.h" | 23 #include "coretypes.h" |
25 #include "tm.h" | 24 #include "backend.h" |
25 #include "rtl.h" | |
26 #include "tree.h" | 26 #include "tree.h" |
27 #include "ggc.h" | 27 #include "gimple.h" |
28 #include "basic-block.h" | 28 #include "cfghooks.h" |
29 #include "tree-pretty-print.h" | 29 #include "ssa.h" |
30 #include "memmodel.h" | |
31 #include "emit-rtl.h" | |
30 #include "gimple-pretty-print.h" | 32 #include "gimple-pretty-print.h" |
31 #include "bitmap.h" | |
32 #include "tree-flow.h" | |
33 #include "timevar.h" | |
34 #include "tree-dump.h" | |
35 #include "tree-pass.h" | |
36 #include "diagnostic-core.h" | 33 #include "diagnostic-core.h" |
37 #include "ssaexpand.h" | 34 #include "stor-layout.h" |
35 #include "cfgrtl.h" | |
36 #include "cfganal.h" | |
37 #include "tree-eh.h" | |
38 #include "gimple-iterator.h" | |
39 #include "tree-cfg.h" | |
40 #include "dumpfile.h" | |
41 #include "tree-ssa-live.h" | |
42 #include "tree-ssa-ter.h" | |
43 #include "tree-ssa-coalesce.h" | |
44 #include "tree-outof-ssa.h" | |
45 #include "dojump.h" | |
38 | 46 |
39 /* FIXME: A lot of code here deals with expanding to RTL. All that code | 47 /* FIXME: A lot of code here deals with expanding to RTL. All that code |
40 should be in cfgexpand.c. */ | 48 should be in cfgexpand.c. */ |
49 #include "explow.h" | |
41 #include "expr.h" | 50 #include "expr.h" |
42 | 51 |
43 | 52 /* Return TRUE if expression STMT is suitable for replacement. */ |
44 DEF_VEC_I(source_location); | 53 |
45 DEF_VEC_ALLOC_I(source_location,heap); | 54 bool |
55 ssa_is_replaceable_p (gimple *stmt) | |
56 { | |
57 use_operand_p use_p; | |
58 tree def; | |
59 gimple *use_stmt; | |
60 | |
61 /* Only consider modify stmts. */ | |
62 if (!is_gimple_assign (stmt)) | |
63 return false; | |
64 | |
65 /* If the statement may throw an exception, it cannot be replaced. */ | |
66 if (stmt_could_throw_p (stmt)) | |
67 return false; | |
68 | |
69 /* Punt if there is more than 1 def. */ | |
70 def = SINGLE_SSA_TREE_OPERAND (stmt, SSA_OP_DEF); | |
71 if (!def) | |
72 return false; | |
73 | |
74 /* Only consider definitions which have a single use. */ | |
75 if (!single_imm_use (def, &use_p, &use_stmt)) | |
76 return false; | |
77 | |
78 /* Used in this block, but at the TOP of the block, not the end. */ | |
79 if (gimple_code (use_stmt) == GIMPLE_PHI) | |
80 return false; | |
81 | |
82 /* There must be no VDEFs. */ | |
83 if (gimple_vdef (stmt)) | |
84 return false; | |
85 | |
86 /* Float expressions must go through memory if float-store is on. */ | |
87 if (flag_float_store | |
88 && FLOAT_TYPE_P (gimple_expr_type (stmt))) | |
89 return false; | |
90 | |
91 /* An assignment with a register variable on the RHS is not | |
92 replaceable. */ | |
93 if (gimple_assign_rhs_code (stmt) == VAR_DECL | |
94 && DECL_HARD_REGISTER (gimple_assign_rhs1 (stmt))) | |
95 return false; | |
96 | |
97 /* No function calls can be replaced. */ | |
98 if (is_gimple_call (stmt)) | |
99 return false; | |
100 | |
101 /* Leave any stmt with volatile operands alone as well. */ | |
102 if (gimple_has_volatile_ops (stmt)) | |
103 return false; | |
104 | |
105 return true; | |
106 } | |
107 | |
46 | 108 |
47 /* Used to hold all the components required to do SSA PHI elimination. | 109 /* Used to hold all the components required to do SSA PHI elimination. |
48 The node and pred/succ list is a simple linear list of nodes and | 110 The node and pred/succ list is a simple linear list of nodes and |
49 edges represented as pairs of nodes. | 111 edges represented as pairs of nodes. |
50 | 112 |
63 3, and in a bootstrap of GCC, the maximum size encountered was 7. | 125 3, and in a bootstrap of GCC, the maximum size encountered was 7. |
64 This also limits the number of possible nodes that are involved to | 126 This also limits the number of possible nodes that are involved to |
65 rarely more than 6, and in the bootstrap of gcc, the maximum number | 127 rarely more than 6, and in the bootstrap of gcc, the maximum number |
66 of nodes encountered was 12. */ | 128 of nodes encountered was 12. */ |
67 | 129 |
68 typedef struct _elim_graph { | 130 struct elim_graph |
131 { | |
132 elim_graph (var_map map); | |
133 | |
69 /* Size of the elimination vectors. */ | 134 /* Size of the elimination vectors. */ |
70 int size; | 135 int size; |
71 | 136 |
72 /* List of nodes in the elimination graph. */ | 137 /* List of nodes in the elimination graph. */ |
73 VEC(int,heap) *nodes; | 138 auto_vec<int> nodes; |
74 | 139 |
75 /* The predecessor and successor edge list. */ | 140 /* The predecessor and successor edge list. */ |
76 VEC(int,heap) *edge_list; | 141 auto_vec<int> edge_list; |
77 | 142 |
78 /* Source locus on each edge */ | 143 /* Source locus on each edge */ |
79 VEC(source_location,heap) *edge_locus; | 144 auto_vec<source_location> edge_locus; |
80 | 145 |
81 /* Visited vector. */ | 146 /* Visited vector. */ |
82 sbitmap visited; | 147 auto_sbitmap visited; |
83 | 148 |
84 /* Stack for visited nodes. */ | 149 /* Stack for visited nodes. */ |
85 VEC(int,heap) *stack; | 150 auto_vec<int> stack; |
86 | 151 |
87 /* The variable partition map. */ | 152 /* The variable partition map. */ |
88 var_map map; | 153 var_map map; |
89 | 154 |
90 /* Edge being eliminated by this graph. */ | 155 /* Edge being eliminated by this graph. */ |
91 edge e; | 156 edge e; |
92 | 157 |
93 /* List of constant copies to emit. These are pushed on in pairs. */ | 158 /* List of constant copies to emit. These are pushed on in pairs. */ |
94 VEC(int,heap) *const_dests; | 159 auto_vec<int> const_dests; |
95 VEC(tree,heap) *const_copies; | 160 auto_vec<tree> const_copies; |
96 | 161 |
97 /* Source locations for any constant copies. */ | 162 /* Source locations for any constant copies. */ |
98 VEC(source_location,heap) *copy_locus; | 163 auto_vec<source_location> copy_locus; |
99 } *elim_graph; | 164 }; |
100 | 165 |
101 | 166 |
102 /* For an edge E find out a good source location to associate with | 167 /* For an edge E find out a good source location to associate with |
103 instructions inserted on edge E. If E has an implicit goto set, | 168 instructions inserted on edge E. If E has an implicit goto set, |
104 use its location. Otherwise search instructions in predecessors | 169 use its location. Otherwise search instructions in predecessors |
109 static void | 174 static void |
110 set_location_for_edge (edge e) | 175 set_location_for_edge (edge e) |
111 { | 176 { |
112 if (e->goto_locus) | 177 if (e->goto_locus) |
113 { | 178 { |
114 set_curr_insn_source_location (e->goto_locus); | 179 set_curr_insn_location (e->goto_locus); |
115 set_curr_insn_block (e->goto_block); | |
116 } | 180 } |
117 else | 181 else |
118 { | 182 { |
119 basic_block bb = e->src; | 183 basic_block bb = e->src; |
120 gimple_stmt_iterator gsi; | 184 gimple_stmt_iterator gsi; |
121 | 185 |
122 do | 186 do |
123 { | 187 { |
124 for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi)) | 188 for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi)) |
125 { | 189 { |
126 gimple stmt = gsi_stmt (gsi); | 190 gimple *stmt = gsi_stmt (gsi); |
127 if (is_gimple_debug (stmt)) | 191 if (is_gimple_debug (stmt)) |
128 continue; | 192 continue; |
129 if (gimple_has_location (stmt) || gimple_block (stmt)) | 193 if (gimple_has_location (stmt) || gimple_block (stmt)) |
130 { | 194 { |
131 set_curr_insn_source_location (gimple_location (stmt)); | 195 set_curr_insn_location (gimple_location (stmt)); |
132 set_curr_insn_block (gimple_block (stmt)); | |
133 return; | 196 return; |
134 } | 197 } |
135 } | 198 } |
136 /* Nothing found in this basic block. Make a half-assed attempt | 199 /* Nothing found in this basic block. Make a half-assed attempt |
137 to continue with another block. */ | 200 to continue with another block. */ |
146 | 209 |
147 /* Emit insns to copy SRC into DEST converting SRC if necessary. As | 210 /* Emit insns to copy SRC into DEST converting SRC if necessary. As |
148 SRC/DEST might be BLKmode memory locations SIZEEXP is a tree from | 211 SRC/DEST might be BLKmode memory locations SIZEEXP is a tree from |
149 which we deduce the size to copy in that case. */ | 212 which we deduce the size to copy in that case. */ |
150 | 213 |
151 static inline rtx | 214 static inline rtx_insn * |
152 emit_partition_copy (rtx dest, rtx src, int unsignedsrcp, tree sizeexp) | 215 emit_partition_copy (rtx dest, rtx src, int unsignedsrcp, tree sizeexp) |
153 { | 216 { |
154 rtx seq; | |
155 | |
156 start_sequence (); | 217 start_sequence (); |
157 | 218 |
158 if (GET_MODE (src) != VOIDmode && GET_MODE (src) != GET_MODE (dest)) | 219 if (GET_MODE (src) != VOIDmode && GET_MODE (src) != GET_MODE (dest)) |
159 src = convert_to_mode (GET_MODE (dest), src, unsignedsrcp); | 220 src = convert_to_mode (GET_MODE (dest), src, unsignedsrcp); |
160 if (GET_MODE (src) == BLKmode) | 221 if (GET_MODE (src) == BLKmode) |
162 gcc_assert (GET_MODE (dest) == BLKmode); | 223 gcc_assert (GET_MODE (dest) == BLKmode); |
163 emit_block_move (dest, src, expr_size (sizeexp), BLOCK_OP_NORMAL); | 224 emit_block_move (dest, src, expr_size (sizeexp), BLOCK_OP_NORMAL); |
164 } | 225 } |
165 else | 226 else |
166 emit_move_insn (dest, src); | 227 emit_move_insn (dest, src); |
167 | 228 do_pending_stack_adjust (); |
168 seq = get_insns (); | 229 |
230 rtx_insn *seq = get_insns (); | |
169 end_sequence (); | 231 end_sequence (); |
170 | 232 |
171 return seq; | 233 return seq; |
172 } | 234 } |
173 | 235 |
175 | 237 |
176 static void | 238 static void |
177 insert_partition_copy_on_edge (edge e, int dest, int src, source_location locus) | 239 insert_partition_copy_on_edge (edge e, int dest, int src, source_location locus) |
178 { | 240 { |
179 tree var; | 241 tree var; |
180 rtx seq; | |
181 if (dump_file && (dump_flags & TDF_DETAILS)) | 242 if (dump_file && (dump_flags & TDF_DETAILS)) |
182 { | 243 { |
183 fprintf (dump_file, | 244 fprintf (dump_file, |
184 "Inserting a partition copy on edge BB%d->BB%d :" | 245 "Inserting a partition copy on edge BB%d->BB%d : " |
185 "PART.%d = PART.%d", | 246 "PART.%d = PART.%d", |
186 e->src->index, | 247 e->src->index, |
187 e->dest->index, dest, src); | 248 e->dest->index, dest, src); |
188 fprintf (dump_file, "\n"); | 249 fprintf (dump_file, "\n"); |
189 } | 250 } |
192 gcc_assert (SA.partition_to_pseudo[src]); | 253 gcc_assert (SA.partition_to_pseudo[src]); |
193 | 254 |
194 set_location_for_edge (e); | 255 set_location_for_edge (e); |
195 /* If a locus is provided, override the default. */ | 256 /* If a locus is provided, override the default. */ |
196 if (locus) | 257 if (locus) |
197 set_curr_insn_source_location (locus); | 258 set_curr_insn_location (locus); |
198 | 259 |
199 var = partition_to_var (SA.map, src); | 260 var = partition_to_var (SA.map, src); |
200 seq = emit_partition_copy (SA.partition_to_pseudo[dest], | 261 rtx_insn *seq = emit_partition_copy (copy_rtx (SA.partition_to_pseudo[dest]), |
201 SA.partition_to_pseudo[src], | 262 copy_rtx (SA.partition_to_pseudo[src]), |
202 TYPE_UNSIGNED (TREE_TYPE (var)), | 263 TYPE_UNSIGNED (TREE_TYPE (var)), |
203 var); | 264 var); |
204 | 265 |
205 insert_insn_on_edge (seq, e); | 266 insert_insn_on_edge (seq, e); |
206 } | 267 } |
207 | 268 |
208 /* Insert a copy instruction from expression SRC to partition DEST | 269 /* Insert a copy instruction from expression SRC to partition DEST |
209 onto edge E. */ | 270 onto edge E. */ |
210 | 271 |
211 static void | 272 static void |
212 insert_value_copy_on_edge (edge e, int dest, tree src, source_location locus) | 273 insert_value_copy_on_edge (edge e, int dest, tree src, source_location locus) |
213 { | 274 { |
214 rtx seq, x; | 275 rtx dest_rtx, seq, x; |
215 enum machine_mode dest_mode, src_mode; | 276 machine_mode dest_mode, src_mode; |
216 int unsignedp; | 277 int unsignedp; |
217 tree var; | |
218 | 278 |
219 if (dump_file && (dump_flags & TDF_DETAILS)) | 279 if (dump_file && (dump_flags & TDF_DETAILS)) |
220 { | 280 { |
221 fprintf (dump_file, | 281 fprintf (dump_file, |
222 "Inserting a value copy on edge BB%d->BB%d : PART.%d = ", | 282 "Inserting a value copy on edge BB%d->BB%d : PART.%d = ", |
224 e->dest->index, dest); | 284 e->dest->index, dest); |
225 print_generic_expr (dump_file, src, TDF_SLIM); | 285 print_generic_expr (dump_file, src, TDF_SLIM); |
226 fprintf (dump_file, "\n"); | 286 fprintf (dump_file, "\n"); |
227 } | 287 } |
228 | 288 |
229 gcc_assert (SA.partition_to_pseudo[dest]); | 289 dest_rtx = copy_rtx (SA.partition_to_pseudo[dest]); |
290 gcc_assert (dest_rtx); | |
230 | 291 |
231 set_location_for_edge (e); | 292 set_location_for_edge (e); |
232 /* If a locus is provided, override the default. */ | 293 /* If a locus is provided, override the default. */ |
233 if (locus) | 294 if (locus) |
234 set_curr_insn_source_location (locus); | 295 set_curr_insn_location (locus); |
235 | 296 |
236 start_sequence (); | 297 start_sequence (); |
237 | 298 |
238 var = SSA_NAME_VAR (partition_to_var (SA.map, dest)); | 299 tree name = partition_to_var (SA.map, dest); |
239 src_mode = TYPE_MODE (TREE_TYPE (src)); | 300 src_mode = TYPE_MODE (TREE_TYPE (src)); |
240 dest_mode = promote_decl_mode (var, &unsignedp); | 301 dest_mode = GET_MODE (dest_rtx); |
241 gcc_assert (src_mode == TYPE_MODE (TREE_TYPE (var))); | 302 gcc_assert (src_mode == TYPE_MODE (TREE_TYPE (name))); |
242 gcc_assert (dest_mode == GET_MODE (SA.partition_to_pseudo[dest])); | 303 gcc_assert (!REG_P (dest_rtx) |
304 || dest_mode == promote_ssa_mode (name, &unsignedp)); | |
243 | 305 |
244 if (src_mode != dest_mode) | 306 if (src_mode != dest_mode) |
245 { | 307 { |
246 x = expand_expr (src, NULL, src_mode, EXPAND_NORMAL); | 308 x = expand_expr (src, NULL, src_mode, EXPAND_NORMAL); |
247 x = convert_modes (dest_mode, src_mode, x, unsignedp); | 309 x = convert_modes (dest_mode, src_mode, x, unsignedp); |
248 } | 310 } |
249 else if (src_mode == BLKmode) | 311 else if (src_mode == BLKmode) |
250 { | 312 { |
251 x = SA.partition_to_pseudo[dest]; | 313 x = dest_rtx; |
252 store_expr (src, x, 0, false); | 314 store_expr (src, x, 0, false, false); |
253 } | 315 } |
254 else | 316 else |
255 x = expand_expr (src, SA.partition_to_pseudo[dest], | 317 x = expand_expr (src, dest_rtx, dest_mode, EXPAND_NORMAL); |
256 dest_mode, EXPAND_NORMAL); | 318 |
257 | 319 if (x != dest_rtx) |
258 if (x != SA.partition_to_pseudo[dest]) | 320 emit_move_insn (dest_rtx, x); |
259 emit_move_insn (SA.partition_to_pseudo[dest], x); | 321 do_pending_stack_adjust (); |
322 | |
260 seq = get_insns (); | 323 seq = get_insns (); |
261 end_sequence (); | 324 end_sequence (); |
262 | 325 |
263 insert_insn_on_edge (seq, e); | 326 insert_insn_on_edge (seq, e); |
264 } | 327 } |
268 | 331 |
269 static void | 332 static void |
270 insert_rtx_to_part_on_edge (edge e, int dest, rtx src, int unsignedsrcp, | 333 insert_rtx_to_part_on_edge (edge e, int dest, rtx src, int unsignedsrcp, |
271 source_location locus) | 334 source_location locus) |
272 { | 335 { |
273 rtx seq; | |
274 if (dump_file && (dump_flags & TDF_DETAILS)) | 336 if (dump_file && (dump_flags & TDF_DETAILS)) |
275 { | 337 { |
276 fprintf (dump_file, | 338 fprintf (dump_file, |
277 "Inserting a temp copy on edge BB%d->BB%d : PART.%d = ", | 339 "Inserting a temp copy on edge BB%d->BB%d : PART.%d = ", |
278 e->src->index, | 340 e->src->index, |
284 gcc_assert (SA.partition_to_pseudo[dest]); | 346 gcc_assert (SA.partition_to_pseudo[dest]); |
285 | 347 |
286 set_location_for_edge (e); | 348 set_location_for_edge (e); |
287 /* If a locus is provided, override the default. */ | 349 /* If a locus is provided, override the default. */ |
288 if (locus) | 350 if (locus) |
289 set_curr_insn_source_location (locus); | 351 set_curr_insn_location (locus); |
290 | 352 |
291 /* We give the destination as sizeexp in case src/dest are BLKmode | 353 /* We give the destination as sizeexp in case src/dest are BLKmode |
292 mems. Usually we give the source. As we result from SSA names | 354 mems. Usually we give the source. As we result from SSA names |
293 the left and right size should be the same (and no WITH_SIZE_EXPR | 355 the left and right size should be the same (and no WITH_SIZE_EXPR |
294 involved), so it doesn't matter. */ | 356 involved), so it doesn't matter. */ |
295 seq = emit_partition_copy (SA.partition_to_pseudo[dest], | 357 rtx_insn *seq = emit_partition_copy (copy_rtx (SA.partition_to_pseudo[dest]), |
296 src, unsignedsrcp, | 358 src, unsignedsrcp, |
297 partition_to_var (SA.map, dest)); | 359 partition_to_var (SA.map, dest)); |
298 | 360 |
299 insert_insn_on_edge (seq, e); | 361 insert_insn_on_edge (seq, e); |
300 } | 362 } |
301 | 363 |
302 /* Insert a copy instruction from partition SRC to RTL lvalue DEST | 364 /* Insert a copy instruction from partition SRC to RTL lvalue DEST |
304 | 366 |
305 static void | 367 static void |
306 insert_part_to_rtx_on_edge (edge e, rtx dest, int src, source_location locus) | 368 insert_part_to_rtx_on_edge (edge e, rtx dest, int src, source_location locus) |
307 { | 369 { |
308 tree var; | 370 tree var; |
309 rtx seq; | |
310 if (dump_file && (dump_flags & TDF_DETAILS)) | 371 if (dump_file && (dump_flags & TDF_DETAILS)) |
311 { | 372 { |
312 fprintf (dump_file, | 373 fprintf (dump_file, |
313 "Inserting a temp copy on edge BB%d->BB%d : ", | 374 "Inserting a temp copy on edge BB%d->BB%d : ", |
314 e->src->index, | 375 e->src->index, |
320 gcc_assert (SA.partition_to_pseudo[src]); | 381 gcc_assert (SA.partition_to_pseudo[src]); |
321 | 382 |
322 set_location_for_edge (e); | 383 set_location_for_edge (e); |
323 /* If a locus is provided, override the default. */ | 384 /* If a locus is provided, override the default. */ |
324 if (locus) | 385 if (locus) |
325 set_curr_insn_source_location (locus); | 386 set_curr_insn_location (locus); |
326 | 387 |
327 var = partition_to_var (SA.map, src); | 388 var = partition_to_var (SA.map, src); |
328 seq = emit_partition_copy (dest, | 389 rtx_insn *seq = emit_partition_copy (dest, |
329 SA.partition_to_pseudo[src], | 390 copy_rtx (SA.partition_to_pseudo[src]), |
330 TYPE_UNSIGNED (TREE_TYPE (var)), | 391 TYPE_UNSIGNED (TREE_TYPE (var)), |
331 var); | 392 var); |
332 | 393 |
333 insert_insn_on_edge (seq, e); | 394 insert_insn_on_edge (seq, e); |
334 } | 395 } |
335 | 396 |
336 | 397 |
337 /* Create an elimination graph with SIZE nodes and associated data | 398 /* Create an elimination graph for map. */ |
338 structures. */ | 399 |
339 | 400 elim_graph::elim_graph (var_map map) : |
340 static elim_graph | 401 nodes (30), edge_list (20), edge_locus (10), visited (map->num_partitions), |
341 new_elim_graph (int size) | 402 stack (30), map (map), const_dests (20), const_copies (20), copy_locus (10) |
342 { | 403 { |
343 elim_graph g = (elim_graph) xmalloc (sizeof (struct _elim_graph)); | |
344 | |
345 g->nodes = VEC_alloc (int, heap, 30); | |
346 g->const_dests = VEC_alloc (int, heap, 20); | |
347 g->const_copies = VEC_alloc (tree, heap, 20); | |
348 g->copy_locus = VEC_alloc (source_location, heap, 10); | |
349 g->edge_list = VEC_alloc (int, heap, 20); | |
350 g->edge_locus = VEC_alloc (source_location, heap, 10); | |
351 g->stack = VEC_alloc (int, heap, 30); | |
352 | |
353 g->visited = sbitmap_alloc (size); | |
354 | |
355 return g; | |
356 } | 404 } |
357 | 405 |
358 | 406 |
359 /* Empty elimination graph G. */ | 407 /* Empty elimination graph G. */ |
360 | 408 |
361 static inline void | 409 static inline void |
362 clear_elim_graph (elim_graph g) | 410 clear_elim_graph (elim_graph *g) |
363 { | 411 { |
364 VEC_truncate (int, g->nodes, 0); | 412 g->nodes.truncate (0); |
365 VEC_truncate (int, g->edge_list, 0); | 413 g->edge_list.truncate (0); |
366 VEC_truncate (source_location, g->edge_locus, 0); | 414 g->edge_locus.truncate (0); |
367 } | 415 } |
368 | 416 |
369 | 417 |
370 /* Delete elimination graph G. */ | 418 /* Return the number of nodes in graph G. */ |
419 | |
420 static inline int | |
421 elim_graph_size (elim_graph *g) | |
422 { | |
423 return g->nodes.length (); | |
424 } | |
425 | |
426 | |
427 /* Add NODE to graph G, if it doesn't exist already. */ | |
371 | 428 |
372 static inline void | 429 static inline void |
373 delete_elim_graph (elim_graph g) | 430 elim_graph_add_node (elim_graph *g, int node) |
374 { | |
375 sbitmap_free (g->visited); | |
376 VEC_free (int, heap, g->stack); | |
377 VEC_free (int, heap, g->edge_list); | |
378 VEC_free (tree, heap, g->const_copies); | |
379 VEC_free (int, heap, g->const_dests); | |
380 VEC_free (int, heap, g->nodes); | |
381 VEC_free (source_location, heap, g->copy_locus); | |
382 VEC_free (source_location, heap, g->edge_locus); | |
383 | |
384 free (g); | |
385 } | |
386 | |
387 | |
388 /* Return the number of nodes in graph G. */ | |
389 | |
390 static inline int | |
391 elim_graph_size (elim_graph g) | |
392 { | |
393 return VEC_length (int, g->nodes); | |
394 } | |
395 | |
396 | |
397 /* Add NODE to graph G, if it doesn't exist already. */ | |
398 | |
399 static inline void | |
400 elim_graph_add_node (elim_graph g, int node) | |
401 { | 431 { |
402 int x; | 432 int x; |
403 int t; | 433 int t; |
404 | 434 |
405 FOR_EACH_VEC_ELT (int, g->nodes, x, t) | 435 FOR_EACH_VEC_ELT (g->nodes, x, t) |
406 if (t == node) | 436 if (t == node) |
407 return; | 437 return; |
408 VEC_safe_push (int, heap, g->nodes, node); | 438 g->nodes.safe_push (node); |
409 } | 439 } |
410 | 440 |
411 | 441 |
412 /* Add the edge PRED->SUCC to graph G. */ | 442 /* Add the edge PRED->SUCC to graph G. */ |
413 | 443 |
414 static inline void | 444 static inline void |
415 elim_graph_add_edge (elim_graph g, int pred, int succ, source_location locus) | 445 elim_graph_add_edge (elim_graph *g, int pred, int succ, source_location locus) |
416 { | 446 { |
417 VEC_safe_push (int, heap, g->edge_list, pred); | 447 g->edge_list.safe_push (pred); |
418 VEC_safe_push (int, heap, g->edge_list, succ); | 448 g->edge_list.safe_push (succ); |
419 VEC_safe_push (source_location, heap, g->edge_locus, locus); | 449 g->edge_locus.safe_push (locus); |
420 } | 450 } |
421 | 451 |
422 | 452 |
423 /* Remove an edge from graph G for which NODE is the predecessor, and | 453 /* Remove an edge from graph G for which NODE is the predecessor, and |
424 return the successor node. -1 is returned if there is no such edge. */ | 454 return the successor node. -1 is returned if there is no such edge. */ |
425 | 455 |
426 static inline int | 456 static inline int |
427 elim_graph_remove_succ_edge (elim_graph g, int node, source_location *locus) | 457 elim_graph_remove_succ_edge (elim_graph *g, int node, source_location *locus) |
428 { | 458 { |
429 int y; | 459 int y; |
430 unsigned x; | 460 unsigned x; |
431 for (x = 0; x < VEC_length (int, g->edge_list); x += 2) | 461 for (x = 0; x < g->edge_list.length (); x += 2) |
432 if (VEC_index (int, g->edge_list, x) == node) | 462 if (g->edge_list[x] == node) |
433 { | 463 { |
434 VEC_replace (int, g->edge_list, x, -1); | 464 g->edge_list[x] = -1; |
435 y = VEC_index (int, g->edge_list, x + 1); | 465 y = g->edge_list[x + 1]; |
436 VEC_replace (int, g->edge_list, x + 1, -1); | 466 g->edge_list[x + 1] = -1; |
437 *locus = VEC_index (source_location, g->edge_locus, x / 2); | 467 *locus = g->edge_locus[x / 2]; |
438 VEC_replace (source_location, g->edge_locus, x / 2, UNKNOWN_LOCATION); | 468 g->edge_locus[x / 2] = UNKNOWN_LOCATION; |
439 return y; | 469 return y; |
440 } | 470 } |
441 *locus = UNKNOWN_LOCATION; | 471 *locus = UNKNOWN_LOCATION; |
442 return -1; | 472 return -1; |
443 } | 473 } |
449 | 479 |
450 #define FOR_EACH_ELIM_GRAPH_SUCC(GRAPH, NODE, VAR, LOCUS, CODE) \ | 480 #define FOR_EACH_ELIM_GRAPH_SUCC(GRAPH, NODE, VAR, LOCUS, CODE) \ |
451 do { \ | 481 do { \ |
452 unsigned x_; \ | 482 unsigned x_; \ |
453 int y_; \ | 483 int y_; \ |
454 for (x_ = 0; x_ < VEC_length (int, (GRAPH)->edge_list); x_ += 2) \ | 484 for (x_ = 0; x_ < (GRAPH)->edge_list.length (); x_ += 2) \ |
455 { \ | 485 { \ |
456 y_ = VEC_index (int, (GRAPH)->edge_list, x_); \ | 486 y_ = (GRAPH)->edge_list[x_]; \ |
457 if (y_ != (NODE)) \ | 487 if (y_ != (NODE)) \ |
458 continue; \ | 488 continue; \ |
459 (void) ((VAR) = VEC_index (int, (GRAPH)->edge_list, x_ + 1)); \ | 489 (void) ((VAR) = (GRAPH)->edge_list[x_ + 1]); \ |
460 (void) ((LOCUS) = VEC_index (source_location, \ | 490 (void) ((LOCUS) = (GRAPH)->edge_locus[x_ / 2]); \ |
461 (GRAPH)->edge_locus, x_ / 2)); \ | |
462 CODE; \ | 491 CODE; \ |
463 } \ | 492 } \ |
464 } while (0) | 493 } while (0) |
465 | 494 |
466 | 495 |
470 | 499 |
471 #define FOR_EACH_ELIM_GRAPH_PRED(GRAPH, NODE, VAR, LOCUS, CODE) \ | 500 #define FOR_EACH_ELIM_GRAPH_PRED(GRAPH, NODE, VAR, LOCUS, CODE) \ |
472 do { \ | 501 do { \ |
473 unsigned x_; \ | 502 unsigned x_; \ |
474 int y_; \ | 503 int y_; \ |
475 for (x_ = 0; x_ < VEC_length (int, (GRAPH)->edge_list); x_ += 2) \ | 504 for (x_ = 0; x_ < (GRAPH)->edge_list.length (); x_ += 2) \ |
476 { \ | 505 { \ |
477 y_ = VEC_index (int, (GRAPH)->edge_list, x_ + 1); \ | 506 y_ = (GRAPH)->edge_list[x_ + 1]; \ |
478 if (y_ != (NODE)) \ | 507 if (y_ != (NODE)) \ |
479 continue; \ | 508 continue; \ |
480 (void) ((VAR) = VEC_index (int, (GRAPH)->edge_list, x_)); \ | 509 (void) ((VAR) = (GRAPH)->edge_list[x_]); \ |
481 (void) ((LOCUS) = VEC_index (source_location, \ | 510 (void) ((LOCUS) = (GRAPH)->edge_locus[x_ / 2]); \ |
482 (GRAPH)->edge_locus, x_ / 2)); \ | |
483 CODE; \ | 511 CODE; \ |
484 } \ | 512 } \ |
485 } while (0) | 513 } while (0) |
486 | 514 |
487 | 515 |
488 /* Add T to elimination graph G. */ | 516 /* Add T to elimination graph G. */ |
489 | 517 |
490 static inline void | 518 static inline void |
491 eliminate_name (elim_graph g, int T) | 519 eliminate_name (elim_graph *g, int T) |
492 { | 520 { |
493 elim_graph_add_node (g, T); | 521 elim_graph_add_node (g, T); |
494 } | 522 } |
495 | 523 |
524 /* Return true if this phi argument T should have a copy queued when using | |
525 var_map MAP. PHI nodes should contain only ssa_names and invariants. A | |
526 test for ssa_name is definitely simpler, but don't let invalid contents | |
527 slip through in the meantime. */ | |
528 | |
529 static inline bool | |
530 queue_phi_copy_p (var_map map, tree t) | |
531 { | |
532 if (TREE_CODE (t) == SSA_NAME) | |
533 { | |
534 if (var_to_partition (map, t) == NO_PARTITION) | |
535 return true; | |
536 return false; | |
537 } | |
538 gcc_checking_assert (is_gimple_min_invariant (t)); | |
539 return true; | |
540 } | |
496 | 541 |
497 /* Build elimination graph G for basic block BB on incoming PHI edge | 542 /* Build elimination graph G for basic block BB on incoming PHI edge |
498 G->e. */ | 543 G->e. */ |
499 | 544 |
500 static void | 545 static void |
501 eliminate_build (elim_graph g) | 546 eliminate_build (elim_graph *g) |
502 { | 547 { |
503 tree Ti; | 548 tree Ti; |
504 int p0, pi; | 549 int p0, pi; |
505 gimple_stmt_iterator gsi; | 550 gphi_iterator gsi; |
506 | 551 |
507 clear_elim_graph (g); | 552 clear_elim_graph (g); |
508 | 553 |
509 for (gsi = gsi_start_phis (g->e->dest); !gsi_end_p (gsi); gsi_next (&gsi)) | 554 for (gsi = gsi_start_phis (g->e->dest); !gsi_end_p (gsi); gsi_next (&gsi)) |
510 { | 555 { |
511 gimple phi = gsi_stmt (gsi); | 556 gphi *phi = gsi.phi (); |
512 source_location locus; | 557 source_location locus; |
513 | 558 |
514 p0 = var_to_partition (g->map, gimple_phi_result (phi)); | 559 p0 = var_to_partition (g->map, gimple_phi_result (phi)); |
515 /* Ignore results which are not in partitions. */ | 560 /* Ignore results which are not in partitions. */ |
516 if (p0 == NO_PARTITION) | 561 if (p0 == NO_PARTITION) |
520 locus = gimple_phi_arg_location_from_edge (phi, g->e); | 565 locus = gimple_phi_arg_location_from_edge (phi, g->e); |
521 | 566 |
522 /* If this argument is a constant, or a SSA_NAME which is being | 567 /* If this argument is a constant, or a SSA_NAME which is being |
523 left in SSA form, just queue a copy to be emitted on this | 568 left in SSA form, just queue a copy to be emitted on this |
524 edge. */ | 569 edge. */ |
525 if (!phi_ssa_name_p (Ti) | 570 if (queue_phi_copy_p (g->map, Ti)) |
526 || (TREE_CODE (Ti) == SSA_NAME | |
527 && var_to_partition (g->map, Ti) == NO_PARTITION)) | |
528 { | 571 { |
529 /* Save constant copies until all other copies have been emitted | 572 /* Save constant copies until all other copies have been emitted |
530 on this edge. */ | 573 on this edge. */ |
531 VEC_safe_push (int, heap, g->const_dests, p0); | 574 g->const_dests.safe_push (p0); |
532 VEC_safe_push (tree, heap, g->const_copies, Ti); | 575 g->const_copies.safe_push (Ti); |
533 VEC_safe_push (source_location, heap, g->copy_locus, locus); | 576 g->copy_locus.safe_push (locus); |
534 } | 577 } |
535 else | 578 else |
536 { | 579 { |
537 pi = var_to_partition (g->map, Ti); | 580 pi = var_to_partition (g->map, Ti); |
538 if (p0 != pi) | 581 if (p0 != pi) |
547 | 590 |
548 | 591 |
549 /* Push successors of T onto the elimination stack for G. */ | 592 /* Push successors of T onto the elimination stack for G. */ |
550 | 593 |
551 static void | 594 static void |
552 elim_forward (elim_graph g, int T) | 595 elim_forward (elim_graph *g, int T) |
553 { | 596 { |
554 int S; | 597 int S; |
555 source_location locus; | 598 source_location locus; |
556 | 599 |
557 SET_BIT (g->visited, T); | 600 bitmap_set_bit (g->visited, T); |
558 FOR_EACH_ELIM_GRAPH_SUCC (g, T, S, locus, | 601 FOR_EACH_ELIM_GRAPH_SUCC (g, T, S, locus, |
559 { | 602 { |
560 if (!TEST_BIT (g->visited, S)) | 603 if (!bitmap_bit_p (g->visited, S)) |
561 elim_forward (g, S); | 604 elim_forward (g, S); |
562 }); | 605 }); |
563 VEC_safe_push (int, heap, g->stack, T); | 606 g->stack.safe_push (T); |
564 } | 607 } |
565 | 608 |
566 | 609 |
567 /* Return 1 if there unvisited predecessors of T in graph G. */ | 610 /* Return 1 if there unvisited predecessors of T in graph G. */ |
568 | 611 |
569 static int | 612 static int |
570 elim_unvisited_predecessor (elim_graph g, int T) | 613 elim_unvisited_predecessor (elim_graph *g, int T) |
571 { | 614 { |
572 int P; | 615 int P; |
573 source_location locus; | 616 source_location locus; |
574 | 617 |
575 FOR_EACH_ELIM_GRAPH_PRED (g, T, P, locus, | 618 FOR_EACH_ELIM_GRAPH_PRED (g, T, P, locus, |
576 { | 619 { |
577 if (!TEST_BIT (g->visited, P)) | 620 if (!bitmap_bit_p (g->visited, P)) |
578 return 1; | 621 return 1; |
579 }); | 622 }); |
580 return 0; | 623 return 0; |
581 } | 624 } |
582 | 625 |
583 /* Process predecessors first, and insert a copy. */ | 626 /* Process predecessors first, and insert a copy. */ |
584 | 627 |
585 static void | 628 static void |
586 elim_backward (elim_graph g, int T) | 629 elim_backward (elim_graph *g, int T) |
587 { | 630 { |
588 int P; | 631 int P; |
589 source_location locus; | 632 source_location locus; |
590 | 633 |
591 SET_BIT (g->visited, T); | 634 bitmap_set_bit (g->visited, T); |
592 FOR_EACH_ELIM_GRAPH_PRED (g, T, P, locus, | 635 FOR_EACH_ELIM_GRAPH_PRED (g, T, P, locus, |
593 { | 636 { |
594 if (!TEST_BIT (g->visited, P)) | 637 if (!bitmap_bit_p (g->visited, P)) |
595 { | 638 { |
596 elim_backward (g, P); | 639 elim_backward (g, P); |
597 insert_partition_copy_on_edge (g->e, P, T, locus); | 640 insert_partition_copy_on_edge (g->e, P, T, locus); |
598 } | 641 } |
599 }); | 642 }); |
603 in NAME (a decl or SSA name), i.e. with matching mode and attributes. */ | 646 in NAME (a decl or SSA name), i.e. with matching mode and attributes. */ |
604 | 647 |
605 static rtx | 648 static rtx |
606 get_temp_reg (tree name) | 649 get_temp_reg (tree name) |
607 { | 650 { |
608 tree var = TREE_CODE (name) == SSA_NAME ? SSA_NAME_VAR (name) : name; | 651 tree type = TREE_TYPE (name); |
609 tree type = TREE_TYPE (var); | |
610 int unsignedp; | 652 int unsignedp; |
611 enum machine_mode reg_mode = promote_decl_mode (var, &unsignedp); | 653 machine_mode reg_mode = promote_ssa_mode (name, &unsignedp); |
612 rtx x = gen_reg_rtx (reg_mode); | 654 rtx x = gen_reg_rtx (reg_mode); |
613 if (POINTER_TYPE_P (type)) | 655 if (POINTER_TYPE_P (type)) |
614 mark_reg_pointer (x, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (var)))); | 656 mark_reg_pointer (x, TYPE_ALIGN (TREE_TYPE (type))); |
615 return x; | 657 return x; |
616 } | 658 } |
617 | 659 |
618 /* Insert required copies for T in graph G. Check for a strongly connected | 660 /* Insert required copies for T in graph G. Check for a strongly connected |
619 region, and create a temporary to break the cycle if one is found. */ | 661 region, and create a temporary to break the cycle if one is found. */ |
620 | 662 |
621 static void | 663 static void |
622 elim_create (elim_graph g, int T) | 664 elim_create (elim_graph *g, int T) |
623 { | 665 { |
624 int P, S; | 666 int P, S; |
625 source_location locus; | 667 source_location locus; |
626 | 668 |
627 if (elim_unvisited_predecessor (g, T)) | 669 if (elim_unvisited_predecessor (g, T)) |
631 int unsignedsrcp = TYPE_UNSIGNED (TREE_TYPE (var)); | 673 int unsignedsrcp = TYPE_UNSIGNED (TREE_TYPE (var)); |
632 | 674 |
633 insert_part_to_rtx_on_edge (g->e, U, T, UNKNOWN_LOCATION); | 675 insert_part_to_rtx_on_edge (g->e, U, T, UNKNOWN_LOCATION); |
634 FOR_EACH_ELIM_GRAPH_PRED (g, T, P, locus, | 676 FOR_EACH_ELIM_GRAPH_PRED (g, T, P, locus, |
635 { | 677 { |
636 if (!TEST_BIT (g->visited, P)) | 678 if (!bitmap_bit_p (g->visited, P)) |
637 { | 679 { |
638 elim_backward (g, P); | 680 elim_backward (g, P); |
639 insert_rtx_to_part_on_edge (g->e, P, U, unsignedsrcp, locus); | 681 insert_rtx_to_part_on_edge (g->e, P, U, unsignedsrcp, locus); |
640 } | 682 } |
641 }); | 683 }); |
643 else | 685 else |
644 { | 686 { |
645 S = elim_graph_remove_succ_edge (g, T, &locus); | 687 S = elim_graph_remove_succ_edge (g, T, &locus); |
646 if (S != -1) | 688 if (S != -1) |
647 { | 689 { |
648 SET_BIT (g->visited, T); | 690 bitmap_set_bit (g->visited, T); |
649 insert_partition_copy_on_edge (g->e, T, S, locus); | 691 insert_partition_copy_on_edge (g->e, T, S, locus); |
650 } | 692 } |
651 } | 693 } |
652 } | 694 } |
653 | 695 |
654 | 696 |
655 /* Eliminate all the phi nodes on edge E in graph G. */ | 697 /* Eliminate all the phi nodes on edge E in graph G. */ |
656 | 698 |
657 static void | 699 static void |
658 eliminate_phi (edge e, elim_graph g) | 700 eliminate_phi (edge e, elim_graph *g) |
659 { | 701 { |
660 int x; | 702 int x; |
661 | 703 |
662 gcc_assert (VEC_length (tree, g->const_copies) == 0); | 704 gcc_assert (g->const_copies.length () == 0); |
663 gcc_assert (VEC_length (source_location, g->copy_locus) == 0); | 705 gcc_assert (g->copy_locus.length () == 0); |
664 | 706 |
665 /* Abnormal edges already have everything coalesced. */ | 707 /* Abnormal edges already have everything coalesced. */ |
666 if (e->flags & EDGE_ABNORMAL) | 708 if (e->flags & EDGE_ABNORMAL) |
667 return; | 709 return; |
668 | 710 |
672 | 714 |
673 if (elim_graph_size (g) != 0) | 715 if (elim_graph_size (g) != 0) |
674 { | 716 { |
675 int part; | 717 int part; |
676 | 718 |
677 sbitmap_zero (g->visited); | 719 bitmap_clear (g->visited); |
678 VEC_truncate (int, g->stack, 0); | 720 g->stack.truncate (0); |
679 | 721 |
680 FOR_EACH_VEC_ELT (int, g->nodes, x, part) | 722 FOR_EACH_VEC_ELT (g->nodes, x, part) |
681 { | 723 { |
682 if (!TEST_BIT (g->visited, part)) | 724 if (!bitmap_bit_p (g->visited, part)) |
683 elim_forward (g, part); | 725 elim_forward (g, part); |
684 } | 726 } |
685 | 727 |
686 sbitmap_zero (g->visited); | 728 bitmap_clear (g->visited); |
687 while (VEC_length (int, g->stack) > 0) | 729 while (g->stack.length () > 0) |
688 { | 730 { |
689 x = VEC_pop (int, g->stack); | 731 x = g->stack.pop (); |
690 if (!TEST_BIT (g->visited, x)) | 732 if (!bitmap_bit_p (g->visited, x)) |
691 elim_create (g, x); | 733 elim_create (g, x); |
692 } | 734 } |
693 } | 735 } |
694 | 736 |
695 /* If there are any pending constant copies, issue them now. */ | 737 /* If there are any pending constant copies, issue them now. */ |
696 while (VEC_length (tree, g->const_copies) > 0) | 738 while (g->const_copies.length () > 0) |
697 { | 739 { |
698 int dest; | 740 int dest; |
699 tree src; | 741 tree src; |
700 source_location locus; | 742 source_location locus; |
701 | 743 |
702 src = VEC_pop (tree, g->const_copies); | 744 src = g->const_copies.pop (); |
703 dest = VEC_pop (int, g->const_dests); | 745 dest = g->const_dests.pop (); |
704 locus = VEC_pop (source_location, g->copy_locus); | 746 locus = g->copy_locus.pop (); |
705 insert_value_copy_on_edge (e, dest, src, locus); | 747 insert_value_copy_on_edge (e, dest, src, locus); |
706 } | 748 } |
707 } | 749 } |
708 | 750 |
709 | 751 |
710 /* Remove each argument from PHI. If an arg was the last use of an SSA_NAME, | 752 /* Remove each argument from PHI. If an arg was the last use of an SSA_NAME, |
711 check to see if this allows another PHI node to be removed. */ | 753 check to see if this allows another PHI node to be removed. */ |
712 | 754 |
713 static void | 755 static void |
714 remove_gimple_phi_args (gimple phi) | 756 remove_gimple_phi_args (gphi *phi) |
715 { | 757 { |
716 use_operand_p arg_p; | 758 use_operand_p arg_p; |
717 ssa_op_iter iter; | 759 ssa_op_iter iter; |
718 | 760 |
719 if (dump_file && (dump_flags & TDF_DETAILS)) | 761 if (dump_file && (dump_flags & TDF_DETAILS)) |
729 { | 771 { |
730 /* Remove the reference to the existing argument. */ | 772 /* Remove the reference to the existing argument. */ |
731 SET_USE (arg_p, NULL_TREE); | 773 SET_USE (arg_p, NULL_TREE); |
732 if (has_zero_uses (arg)) | 774 if (has_zero_uses (arg)) |
733 { | 775 { |
734 gimple stmt; | 776 gimple *stmt; |
735 gimple_stmt_iterator gsi; | 777 gimple_stmt_iterator gsi; |
736 | 778 |
737 stmt = SSA_NAME_DEF_STMT (arg); | 779 stmt = SSA_NAME_DEF_STMT (arg); |
738 | 780 |
739 /* Also remove the def if it is a PHI node. */ | 781 /* Also remove the def if it is a PHI node. */ |
740 if (gimple_code (stmt) == GIMPLE_PHI) | 782 if (gimple_code (stmt) == GIMPLE_PHI) |
741 { | 783 { |
742 remove_gimple_phi_args (stmt); | 784 remove_gimple_phi_args (as_a <gphi *> (stmt)); |
743 gsi = gsi_for_stmt (stmt); | 785 gsi = gsi_for_stmt (stmt); |
744 remove_phi_node (&gsi, true); | 786 remove_phi_node (&gsi, true); |
745 } | 787 } |
746 | 788 |
747 } | 789 } |
753 | 795 |
754 static void | 796 static void |
755 eliminate_useless_phis (void) | 797 eliminate_useless_phis (void) |
756 { | 798 { |
757 basic_block bb; | 799 basic_block bb; |
758 gimple_stmt_iterator gsi; | 800 gphi_iterator gsi; |
759 tree result; | 801 tree result; |
760 | 802 |
761 FOR_EACH_BB (bb) | 803 FOR_EACH_BB_FN (bb, cfun) |
762 { | 804 { |
763 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); ) | 805 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); ) |
764 { | 806 { |
765 gimple phi = gsi_stmt (gsi); | 807 gphi *phi = gsi.phi (); |
766 result = gimple_phi_result (phi); | 808 result = gimple_phi_result (phi); |
767 if (!is_gimple_reg (SSA_NAME_VAR (result))) | 809 if (virtual_operand_p (result)) |
768 { | 810 { |
769 #ifdef ENABLE_CHECKING | |
770 size_t i; | |
771 /* There should be no arguments which are not virtual, or the | 811 /* There should be no arguments which are not virtual, or the |
772 results will be incorrect. */ | 812 results will be incorrect. */ |
773 for (i = 0; i < gimple_phi_num_args (phi); i++) | 813 if (flag_checking) |
774 { | 814 for (size_t i = 0; i < gimple_phi_num_args (phi); i++) |
775 tree arg = PHI_ARG_DEF (phi, i); | 815 { |
776 if (TREE_CODE (arg) == SSA_NAME | 816 tree arg = PHI_ARG_DEF (phi, i); |
777 && is_gimple_reg (SSA_NAME_VAR (arg))) | 817 if (TREE_CODE (arg) == SSA_NAME |
778 { | 818 && !virtual_operand_p (arg)) |
779 fprintf (stderr, "Argument of PHI is not virtual ("); | 819 { |
780 print_generic_expr (stderr, arg, TDF_SLIM); | 820 fprintf (stderr, "Argument of PHI is not virtual ("); |
781 fprintf (stderr, "), but the result is :"); | 821 print_generic_expr (stderr, arg, TDF_SLIM); |
782 print_gimple_stmt (stderr, phi, 0, TDF_SLIM); | 822 fprintf (stderr, "), but the result is :"); |
783 internal_error ("SSA corruption"); | 823 print_gimple_stmt (stderr, phi, 0, TDF_SLIM); |
784 } | 824 internal_error ("SSA corruption"); |
785 } | 825 } |
786 #endif | 826 } |
827 | |
787 remove_phi_node (&gsi, true); | 828 remove_phi_node (&gsi, true); |
788 } | 829 } |
789 else | 830 else |
790 { | 831 { |
791 /* Also remove real PHIs with no uses. */ | 832 /* Also remove real PHIs with no uses. */ |
807 occurrences of partitions with non-null entries in the vector will be | 848 occurrences of partitions with non-null entries in the vector will be |
808 replaced with the expression in the vector instead of its mapped | 849 replaced with the expression in the vector instead of its mapped |
809 variable. */ | 850 variable. */ |
810 | 851 |
811 static void | 852 static void |
812 rewrite_trees (var_map map ATTRIBUTE_UNUSED) | 853 rewrite_trees (var_map map) |
813 { | 854 { |
814 #ifdef ENABLE_CHECKING | 855 if (!flag_checking) |
856 return; | |
857 | |
815 basic_block bb; | 858 basic_block bb; |
816 /* Search for PHIs where the destination has no partition, but one | 859 /* Search for PHIs where the destination has no partition, but one |
817 or more arguments has a partition. This should not happen and can | 860 or more arguments has a partition. This should not happen and can |
818 create incorrect code. */ | 861 create incorrect code. */ |
819 FOR_EACH_BB (bb) | 862 FOR_EACH_BB_FN (bb, cfun) |
820 { | 863 { |
821 gimple_stmt_iterator gsi; | 864 gphi_iterator gsi; |
822 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | 865 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
823 { | 866 { |
824 gimple phi = gsi_stmt (gsi); | 867 gphi *phi = gsi.phi (); |
825 tree T0 = var_to_partition_to_var (map, gimple_phi_result (phi)); | 868 tree T0 = var_to_partition_to_var (map, gimple_phi_result (phi)); |
826 if (T0 == NULL_TREE) | 869 if (T0 == NULL_TREE) |
827 { | 870 { |
828 size_t i; | 871 size_t i; |
829 for (i = 0; i < gimple_phi_num_args (phi); i++) | 872 for (i = 0; i < gimple_phi_num_args (phi); i++) |
841 } | 884 } |
842 } | 885 } |
843 } | 886 } |
844 } | 887 } |
845 } | 888 } |
846 #endif | |
847 } | 889 } |
848 | 890 |
849 /* Given the out-of-ssa info object SA (with prepared partitions) | 891 /* Given the out-of-ssa info object SA (with prepared partitions) |
850 eliminate all phi nodes in all basic blocks. Afterwards no | 892 eliminate all phi nodes in all basic blocks. Afterwards no |
851 basic block will have phi nodes anymore and there are possibly | 893 basic block will have phi nodes anymore and there are possibly |
853 | 895 |
854 void | 896 void |
855 expand_phi_nodes (struct ssaexpand *sa) | 897 expand_phi_nodes (struct ssaexpand *sa) |
856 { | 898 { |
857 basic_block bb; | 899 basic_block bb; |
858 elim_graph g = new_elim_graph (sa->map->num_partitions); | 900 elim_graph g (sa->map); |
859 g->map = sa->map; | 901 |
860 | 902 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb, |
861 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR->next_bb, EXIT_BLOCK_PTR, next_bb) | 903 EXIT_BLOCK_PTR_FOR_FN (cfun), next_bb) |
862 if (!gimple_seq_empty_p (phi_nodes (bb))) | 904 if (!gimple_seq_empty_p (phi_nodes (bb))) |
863 { | 905 { |
864 edge e; | 906 edge e; |
865 edge_iterator ei; | 907 edge_iterator ei; |
866 FOR_EACH_EDGE (e, ei, bb->preds) | 908 FOR_EACH_EDGE (e, ei, bb->preds) |
867 eliminate_phi (e, g); | 909 eliminate_phi (e, &g); |
868 set_phi_nodes (bb, NULL); | 910 set_phi_nodes (bb, NULL); |
869 /* We can't redirect EH edges in RTL land, so we need to do this | 911 /* We can't redirect EH edges in RTL land, so we need to do this |
870 here. Redirection happens only when splitting is necessary, | 912 here. Redirection happens only when splitting is necessary, |
871 which it is only for critical edges, normally. For EH edges | 913 which it is only for critical edges, normally. For EH edges |
872 it might also be necessary when the successor has more than | 914 it might also be necessary when the successor has more than |
878 for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); ) | 920 for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); ) |
879 { | 921 { |
880 if (e->insns.r && (e->flags & EDGE_EH) | 922 if (e->insns.r && (e->flags & EDGE_EH) |
881 && !single_pred_p (e->dest)) | 923 && !single_pred_p (e->dest)) |
882 { | 924 { |
883 rtx insns = e->insns.r; | 925 rtx_insn *insns = e->insns.r; |
884 basic_block bb; | 926 basic_block bb; |
885 e->insns.r = NULL_RTX; | 927 e->insns.r = NULL; |
886 bb = split_edge (e); | 928 bb = split_edge (e); |
887 single_pred_edge (bb)->insns.r = insns; | 929 single_pred_edge (bb)->insns.r = insns; |
888 } | 930 } |
889 else | 931 else |
890 ei_next (&ei); | 932 ei_next (&ei); |
891 } | 933 } |
892 } | 934 } |
893 | |
894 delete_elim_graph (g); | |
895 } | 935 } |
896 | 936 |
897 | 937 |
898 /* Remove the ssa-names in the current function and translate them into normal | 938 /* Remove the ssa-names in the current function and translate them into normal |
899 compiler variables. PERFORM_TER is true if Temporary Expression Replacement | 939 compiler variables. PERFORM_TER is true if Temporary Expression Replacement |
902 static void | 942 static void |
903 remove_ssa_form (bool perform_ter, struct ssaexpand *sa) | 943 remove_ssa_form (bool perform_ter, struct ssaexpand *sa) |
904 { | 944 { |
905 bitmap values = NULL; | 945 bitmap values = NULL; |
906 var_map map; | 946 var_map map; |
907 unsigned i; | |
908 | 947 |
909 map = coalesce_ssa_name (); | 948 map = coalesce_ssa_name (); |
910 | 949 |
911 /* Return to viewing the variable list as just all reference variables after | 950 /* Return to viewing the variable list as just all reference variables after |
912 coalescing has been performed. */ | 951 coalescing has been performed. */ |
913 partition_view_normal (map, false); | 952 partition_view_normal (map); |
914 | 953 |
915 if (dump_file && (dump_flags & TDF_DETAILS)) | 954 if (dump_file && (dump_flags & TDF_DETAILS)) |
916 { | 955 { |
917 fprintf (dump_file, "After Coalescing:\n"); | 956 fprintf (dump_file, "After Coalescing:\n"); |
918 dump_var_map (dump_file, map); | 957 dump_var_map (dump_file, map); |
927 | 966 |
928 rewrite_trees (map); | 967 rewrite_trees (map); |
929 | 968 |
930 sa->map = map; | 969 sa->map = map; |
931 sa->values = values; | 970 sa->values = values; |
932 sa->partition_has_default_def = BITMAP_ALLOC (NULL); | 971 sa->partitions_for_parm_default_defs = get_parm_default_def_partitions (map); |
933 for (i = 1; i < num_ssa_names; i++) | 972 sa->partitions_for_undefined_values = get_undefined_value_partitions (map); |
934 { | |
935 tree t = ssa_name (i); | |
936 if (t && SSA_NAME_IS_DEFAULT_DEF (t)) | |
937 { | |
938 int p = var_to_partition (map, t); | |
939 if (p != NO_PARTITION) | |
940 bitmap_set_bit (sa->partition_has_default_def, p); | |
941 } | |
942 } | |
943 } | 973 } |
944 | 974 |
945 | 975 |
946 /* If not already done so for basic block BB, assign increasing uids | 976 /* If not already done so for basic block BB, assign increasing uids |
947 to each of its instructions. */ | 977 to each of its instructions. */ |
955 if (!bb->aux) | 985 if (!bb->aux) |
956 return; | 986 return; |
957 bb->aux = NULL; | 987 bb->aux = NULL; |
958 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | 988 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
959 { | 989 { |
960 gimple stmt = gsi_stmt (gsi); | 990 gimple *stmt = gsi_stmt (gsi); |
961 gimple_set_uid (stmt, i); | 991 gimple_set_uid (stmt, i); |
962 i++; | 992 i++; |
963 } | 993 } |
964 } | 994 } |
965 | 995 |
971 static bool | 1001 static bool |
972 trivially_conflicts_p (basic_block bb, tree result, tree arg) | 1002 trivially_conflicts_p (basic_block bb, tree result, tree arg) |
973 { | 1003 { |
974 use_operand_p use; | 1004 use_operand_p use; |
975 imm_use_iterator imm_iter; | 1005 imm_use_iterator imm_iter; |
976 gimple defa = SSA_NAME_DEF_STMT (arg); | 1006 gimple *defa = SSA_NAME_DEF_STMT (arg); |
977 | 1007 |
978 /* If ARG isn't defined in the same block it's too complicated for | 1008 /* If ARG isn't defined in the same block it's too complicated for |
979 our little mind. */ | 1009 our little mind. */ |
980 if (gimple_bb (defa) != bb) | 1010 if (gimple_bb (defa) != bb) |
981 return false; | 1011 return false; |
982 | 1012 |
983 FOR_EACH_IMM_USE_FAST (use, imm_iter, result) | 1013 FOR_EACH_IMM_USE_FAST (use, imm_iter, result) |
984 { | 1014 { |
985 gimple use_stmt = USE_STMT (use); | 1015 gimple *use_stmt = USE_STMT (use); |
986 if (is_gimple_debug (use_stmt)) | 1016 if (is_gimple_debug (use_stmt)) |
987 continue; | 1017 continue; |
988 /* Now, if there's a use of RESULT that lies outside this basic block, | 1018 /* Now, if there's a use of RESULT that lies outside this basic block, |
989 then there surely is a conflict with ARG. */ | 1019 then there surely is a conflict with ARG. */ |
990 if (gimple_bb (use_stmt) != bb) | 1020 if (gimple_bb (use_stmt) != bb) |
1017 | 1047 |
1018 static void | 1048 static void |
1019 insert_backedge_copies (void) | 1049 insert_backedge_copies (void) |
1020 { | 1050 { |
1021 basic_block bb; | 1051 basic_block bb; |
1022 gimple_stmt_iterator gsi; | 1052 gphi_iterator gsi; |
1023 | 1053 |
1024 FOR_EACH_BB (bb) | 1054 mark_dfs_back_edges (); |
1055 | |
1056 FOR_EACH_BB_FN (bb, cfun) | |
1025 { | 1057 { |
1026 /* Mark block as possibly needing calculation of UIDs. */ | 1058 /* Mark block as possibly needing calculation of UIDs. */ |
1027 bb->aux = &bb->aux; | 1059 bb->aux = &bb->aux; |
1028 | 1060 |
1029 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | 1061 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
1030 { | 1062 { |
1031 gimple phi = gsi_stmt (gsi); | 1063 gphi *phi = gsi.phi (); |
1032 tree result = gimple_phi_result (phi); | 1064 tree result = gimple_phi_result (phi); |
1033 tree result_var; | |
1034 size_t i; | 1065 size_t i; |
1035 | 1066 |
1036 if (!is_gimple_reg (result)) | 1067 if (virtual_operand_p (result)) |
1037 continue; | 1068 continue; |
1038 | 1069 |
1039 result_var = SSA_NAME_VAR (result); | |
1040 for (i = 0; i < gimple_phi_num_args (phi); i++) | 1070 for (i = 0; i < gimple_phi_num_args (phi); i++) |
1041 { | 1071 { |
1042 tree arg = gimple_phi_arg_def (phi, i); | 1072 tree arg = gimple_phi_arg_def (phi, i); |
1043 edge e = gimple_phi_arg_edge (phi, i); | 1073 edge e = gimple_phi_arg_edge (phi, i); |
1044 | 1074 |
1046 constant initialization. If the argument is an SSA_NAME with | 1076 constant initialization. If the argument is an SSA_NAME with |
1047 a different underlying variable then a copy statement will be | 1077 a different underlying variable then a copy statement will be |
1048 needed. */ | 1078 needed. */ |
1049 if ((e->flags & EDGE_DFS_BACK) | 1079 if ((e->flags & EDGE_DFS_BACK) |
1050 && (TREE_CODE (arg) != SSA_NAME | 1080 && (TREE_CODE (arg) != SSA_NAME |
1051 || SSA_NAME_VAR (arg) != result_var | 1081 || SSA_NAME_VAR (arg) != SSA_NAME_VAR (result) |
1052 || trivially_conflicts_p (bb, result, arg))) | 1082 || trivially_conflicts_p (bb, result, arg))) |
1053 { | 1083 { |
1054 tree name; | 1084 tree name; |
1055 gimple stmt, last = NULL; | 1085 gassign *stmt; |
1086 gimple *last = NULL; | |
1056 gimple_stmt_iterator gsi2; | 1087 gimple_stmt_iterator gsi2; |
1057 | 1088 |
1058 gsi2 = gsi_last_bb (gimple_phi_arg_edge (phi, i)->src); | 1089 gsi2 = gsi_last_bb (gimple_phi_arg_edge (phi, i)->src); |
1059 if (!gsi_end_p (gsi2)) | 1090 if (!gsi_end_p (gsi2)) |
1060 last = gsi_stmt (gsi2); | 1091 last = gsi_stmt (gsi2); |
1076 continue; | 1107 continue; |
1077 } | 1108 } |
1078 | 1109 |
1079 /* Create a new instance of the underlying variable of the | 1110 /* Create a new instance of the underlying variable of the |
1080 PHI result. */ | 1111 PHI result. */ |
1081 stmt = gimple_build_assign (result_var, | 1112 name = copy_ssa_name (result); |
1113 stmt = gimple_build_assign (name, | |
1082 gimple_phi_arg_def (phi, i)); | 1114 gimple_phi_arg_def (phi, i)); |
1083 name = make_ssa_name (result_var, stmt); | |
1084 gimple_assign_set_lhs (stmt, name); | |
1085 | 1115 |
1086 /* copy location if present. */ | 1116 /* copy location if present. */ |
1087 if (gimple_phi_arg_has_location (phi, i)) | 1117 if (gimple_phi_arg_has_location (phi, i)) |
1088 gimple_set_location (stmt, | 1118 gimple_set_location (stmt, |
1089 gimple_phi_arg_location (phi, i)); | 1119 gimple_phi_arg_location (phi, i)); |
1112 { | 1142 { |
1113 free (sa->partition_to_pseudo); | 1143 free (sa->partition_to_pseudo); |
1114 if (sa->values) | 1144 if (sa->values) |
1115 BITMAP_FREE (sa->values); | 1145 BITMAP_FREE (sa->values); |
1116 delete_var_map (sa->map); | 1146 delete_var_map (sa->map); |
1117 BITMAP_FREE (sa->partition_has_default_def); | 1147 BITMAP_FREE (sa->partitions_for_parm_default_defs); |
1148 BITMAP_FREE (sa->partitions_for_undefined_values); | |
1118 memset (sa, 0, sizeof *sa); | 1149 memset (sa, 0, sizeof *sa); |
1119 } | 1150 } |
1120 | 1151 |
1121 /* Take the current function out of SSA form, translating PHIs as described in | 1152 /* Take the current function out of SSA form, translating PHIs as described in |
1122 R. Morgan, ``Building an Optimizing Compiler'', | 1153 R. Morgan, ``Building an Optimizing Compiler'', |