Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-parloops.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
21 <http://www.gnu.org/licenses/>. */ | 21 <http://www.gnu.org/licenses/>. */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 #include "system.h" | 24 #include "system.h" |
25 #include "coretypes.h" | 25 #include "coretypes.h" |
26 #include "tm.h" | |
27 #include "tree.h" | |
28 #include "tree-flow.h" | 26 #include "tree-flow.h" |
29 #include "cfgloop.h" | 27 #include "cfgloop.h" |
30 #include "tree-data-ref.h" | 28 #include "tree-data-ref.h" |
31 #include "diagnostic.h" | 29 #include "tree-scalar-evolution.h" |
32 #include "tree-pretty-print.h" | |
33 #include "gimple-pretty-print.h" | 30 #include "gimple-pretty-print.h" |
34 #include "tree-pass.h" | 31 #include "tree-pass.h" |
35 #include "tree-scalar-evolution.h" | |
36 #include "hashtab.h" | |
37 #include "langhooks.h" | 32 #include "langhooks.h" |
38 #include "tree-vectorizer.h" | 33 #include "tree-vectorizer.h" |
39 | 34 |
40 /* This pass tries to distribute iterations of loops into several threads. | 35 /* This pass tries to distribute iterations of loops into several threads. |
41 The implementation is straightforward -- for each loop we test whether its | 36 The implementation is straightforward -- for each loop we test whether its |
167 struct reduction_info | 162 struct reduction_info |
168 { | 163 { |
169 gimple reduc_stmt; /* reduction statement. */ | 164 gimple reduc_stmt; /* reduction statement. */ |
170 gimple reduc_phi; /* The phi node defining the reduction. */ | 165 gimple reduc_phi; /* The phi node defining the reduction. */ |
171 enum tree_code reduction_code;/* code for the reduction operation. */ | 166 enum tree_code reduction_code;/* code for the reduction operation. */ |
167 unsigned reduc_version; /* SSA_NAME_VERSION of original reduc_phi | |
168 result. */ | |
172 gimple keep_res; /* The PHI_RESULT of this phi is the resulting value | 169 gimple keep_res; /* The PHI_RESULT of this phi is the resulting value |
173 of the reduction variable when existing the loop. */ | 170 of the reduction variable when existing the loop. */ |
174 tree initial_value; /* The initial value of the reduction var before entering the loop. */ | 171 tree initial_value; /* The initial value of the reduction var before entering the loop. */ |
175 tree field; /* the name of the field in the parloop data structure intended for reduction. */ | 172 tree field; /* the name of the field in the parloop data structure intended for reduction. */ |
176 tree init; /* reduction initialization value. */ | 173 tree init; /* reduction initialization value. */ |
194 static hashval_t | 191 static hashval_t |
195 reduction_info_hash (const void *aa) | 192 reduction_info_hash (const void *aa) |
196 { | 193 { |
197 const struct reduction_info *a = (const struct reduction_info *) aa; | 194 const struct reduction_info *a = (const struct reduction_info *) aa; |
198 | 195 |
199 return htab_hash_pointer (a->reduc_phi); | 196 return a->reduc_version; |
200 } | 197 } |
201 | 198 |
202 static struct reduction_info * | 199 static struct reduction_info * |
203 reduction_phi (htab_t reduction_list, gimple phi) | 200 reduction_phi (htab_t reduction_list, gimple phi) |
204 { | 201 { |
205 struct reduction_info tmpred, *red; | 202 struct reduction_info tmpred, *red; |
206 | 203 |
207 if (htab_elements (reduction_list) == 0) | 204 if (htab_elements (reduction_list) == 0 || phi == NULL) |
208 return NULL; | 205 return NULL; |
209 | 206 |
210 tmpred.reduc_phi = phi; | 207 tmpred.reduc_phi = phi; |
208 tmpred.reduc_version = gimple_uid (phi); | |
211 red = (struct reduction_info *) htab_find (reduction_list, &tmpred); | 209 red = (struct reduction_info *) htab_find (reduction_list, &tmpred); |
212 | 210 |
213 return red; | 211 return red; |
214 } | 212 } |
215 | 213 |
240 const struct name_to_copy_elt *a = (const struct name_to_copy_elt *) aa; | 238 const struct name_to_copy_elt *a = (const struct name_to_copy_elt *) aa; |
241 | 239 |
242 return (hashval_t) a->version; | 240 return (hashval_t) a->version; |
243 } | 241 } |
244 | 242 |
243 /* A transformation matrix, which is a self-contained ROWSIZE x COLSIZE | |
244 matrix. Rather than use floats, we simply keep a single DENOMINATOR that | |
245 represents the denominator for every element in the matrix. */ | |
246 typedef struct lambda_trans_matrix_s | |
247 { | |
248 lambda_matrix matrix; | |
249 int rowsize; | |
250 int colsize; | |
251 int denominator; | |
252 } *lambda_trans_matrix; | |
253 #define LTM_MATRIX(T) ((T)->matrix) | |
254 #define LTM_ROWSIZE(T) ((T)->rowsize) | |
255 #define LTM_COLSIZE(T) ((T)->colsize) | |
256 #define LTM_DENOMINATOR(T) ((T)->denominator) | |
257 | |
258 /* Allocate a new transformation matrix. */ | |
259 | |
260 static lambda_trans_matrix | |
261 lambda_trans_matrix_new (int colsize, int rowsize, | |
262 struct obstack * lambda_obstack) | |
263 { | |
264 lambda_trans_matrix ret; | |
265 | |
266 ret = (lambda_trans_matrix) | |
267 obstack_alloc (lambda_obstack, sizeof (struct lambda_trans_matrix_s)); | |
268 LTM_MATRIX (ret) = lambda_matrix_new (rowsize, colsize, lambda_obstack); | |
269 LTM_ROWSIZE (ret) = rowsize; | |
270 LTM_COLSIZE (ret) = colsize; | |
271 LTM_DENOMINATOR (ret) = 1; | |
272 return ret; | |
273 } | |
274 | |
275 /* Multiply a vector VEC by a matrix MAT. | |
276 MAT is an M*N matrix, and VEC is a vector with length N. The result | |
277 is stored in DEST which must be a vector of length M. */ | |
278 | |
279 static void | |
280 lambda_matrix_vector_mult (lambda_matrix matrix, int m, int n, | |
281 lambda_vector vec, lambda_vector dest) | |
282 { | |
283 int i, j; | |
284 | |
285 lambda_vector_clear (dest, m); | |
286 for (i = 0; i < m; i++) | |
287 for (j = 0; j < n; j++) | |
288 dest[i] += matrix[i][j] * vec[j]; | |
289 } | |
290 | |
291 /* Return true if TRANS is a legal transformation matrix that respects | |
292 the dependence vectors in DISTS and DIRS. The conservative answer | |
293 is false. | |
294 | |
295 "Wolfe proves that a unimodular transformation represented by the | |
296 matrix T is legal when applied to a loop nest with a set of | |
297 lexicographically non-negative distance vectors RDG if and only if | |
298 for each vector d in RDG, (T.d >= 0) is lexicographically positive. | |
299 i.e.: if and only if it transforms the lexicographically positive | |
300 distance vectors to lexicographically positive vectors. Note that | |
301 a unimodular matrix must transform the zero vector (and only it) to | |
302 the zero vector." S.Muchnick. */ | |
303 | |
304 static bool | |
305 lambda_transform_legal_p (lambda_trans_matrix trans, | |
306 int nb_loops, | |
307 VEC (ddr_p, heap) *dependence_relations) | |
308 { | |
309 unsigned int i, j; | |
310 lambda_vector distres; | |
311 struct data_dependence_relation *ddr; | |
312 | |
313 gcc_assert (LTM_COLSIZE (trans) == nb_loops | |
314 && LTM_ROWSIZE (trans) == nb_loops); | |
315 | |
316 /* When there are no dependences, the transformation is correct. */ | |
317 if (VEC_length (ddr_p, dependence_relations) == 0) | |
318 return true; | |
319 | |
320 ddr = VEC_index (ddr_p, dependence_relations, 0); | |
321 if (ddr == NULL) | |
322 return true; | |
323 | |
324 /* When there is an unknown relation in the dependence_relations, we | |
325 know that it is no worth looking at this loop nest: give up. */ | |
326 if (DDR_ARE_DEPENDENT (ddr) == chrec_dont_know) | |
327 return false; | |
328 | |
329 distres = lambda_vector_new (nb_loops); | |
330 | |
331 /* For each distance vector in the dependence graph. */ | |
332 FOR_EACH_VEC_ELT (ddr_p, dependence_relations, i, ddr) | |
333 { | |
334 /* Don't care about relations for which we know that there is no | |
335 dependence, nor about read-read (aka. output-dependences): | |
336 these data accesses can happen in any order. */ | |
337 if (DDR_ARE_DEPENDENT (ddr) == chrec_known | |
338 || (DR_IS_READ (DDR_A (ddr)) && DR_IS_READ (DDR_B (ddr)))) | |
339 continue; | |
340 | |
341 /* Conservatively answer: "this transformation is not valid". */ | |
342 if (DDR_ARE_DEPENDENT (ddr) == chrec_dont_know) | |
343 return false; | |
344 | |
345 /* If the dependence could not be captured by a distance vector, | |
346 conservatively answer that the transform is not valid. */ | |
347 if (DDR_NUM_DIST_VECTS (ddr) == 0) | |
348 return false; | |
349 | |
350 /* Compute trans.dist_vect */ | |
351 for (j = 0; j < DDR_NUM_DIST_VECTS (ddr); j++) | |
352 { | |
353 lambda_matrix_vector_mult (LTM_MATRIX (trans), nb_loops, nb_loops, | |
354 DDR_DIST_VECT (ddr, j), distres); | |
355 | |
356 if (!lambda_vector_lexico_pos (distres, nb_loops)) | |
357 return false; | |
358 } | |
359 } | |
360 return true; | |
361 } | |
245 | 362 |
246 /* Data dependency analysis. Returns true if the iterations of LOOP | 363 /* Data dependency analysis. Returns true if the iterations of LOOP |
247 are independent on each other (that is, if we can execute them | 364 are independent on each other (that is, if we can execute them |
248 in parallel). */ | 365 in parallel). */ |
249 | 366 |
250 static bool | 367 static bool |
251 loop_parallel_p (struct loop *loop, struct obstack * parloop_obstack) | 368 loop_parallel_p (struct loop *loop, struct obstack * parloop_obstack) |
252 { | 369 { |
253 VEC (ddr_p, heap) * dependence_relations; | 370 VEC (loop_p, heap) *loop_nest; |
371 VEC (ddr_p, heap) *dependence_relations; | |
254 VEC (data_reference_p, heap) *datarefs; | 372 VEC (data_reference_p, heap) *datarefs; |
255 lambda_trans_matrix trans; | 373 lambda_trans_matrix trans; |
256 bool ret = false; | 374 bool ret = false; |
257 | 375 |
258 if (dump_file && (dump_flags & TDF_DETAILS)) | 376 if (dump_file && (dump_flags & TDF_DETAILS)) |
266 | 384 |
267 /* Check for problems with dependences. If the loop can be reversed, | 385 /* Check for problems with dependences. If the loop can be reversed, |
268 the iterations are independent. */ | 386 the iterations are independent. */ |
269 datarefs = VEC_alloc (data_reference_p, heap, 10); | 387 datarefs = VEC_alloc (data_reference_p, heap, 10); |
270 dependence_relations = VEC_alloc (ddr_p, heap, 10 * 10); | 388 dependence_relations = VEC_alloc (ddr_p, heap, 10 * 10); |
271 compute_data_dependences_for_loop (loop, true, &datarefs, | 389 loop_nest = VEC_alloc (loop_p, heap, 3); |
390 compute_data_dependences_for_loop (loop, true, &loop_nest, &datarefs, | |
272 &dependence_relations); | 391 &dependence_relations); |
273 if (dump_file && (dump_flags & TDF_DETAILS)) | 392 if (dump_file && (dump_flags & TDF_DETAILS)) |
274 dump_data_dependence_relations (dump_file, dependence_relations); | 393 dump_data_dependence_relations (dump_file, dependence_relations); |
275 | 394 |
276 trans = lambda_trans_matrix_new (1, 1, parloop_obstack); | 395 trans = lambda_trans_matrix_new (1, 1, parloop_obstack); |
284 } | 403 } |
285 else if (dump_file && (dump_flags & TDF_DETAILS)) | 404 else if (dump_file && (dump_flags & TDF_DETAILS)) |
286 fprintf (dump_file, | 405 fprintf (dump_file, |
287 " FAILED: data dependencies exist across iterations\n"); | 406 " FAILED: data dependencies exist across iterations\n"); |
288 | 407 |
408 VEC_free (loop_p, heap, loop_nest); | |
289 free_dependence_relations (dependence_relations); | 409 free_dependence_relations (dependence_relations); |
290 free_data_refs (datarefs); | 410 free_data_refs (datarefs); |
291 | 411 |
292 return ret; | 412 return ret; |
293 } | 413 } |
313 } | 433 } |
314 | 434 |
315 /* Assigns the address of OBJ in TYPE to an ssa name, and returns this name. | 435 /* Assigns the address of OBJ in TYPE to an ssa name, and returns this name. |
316 The assignment statement is placed on edge ENTRY. DECL_ADDRESS maps decls | 436 The assignment statement is placed on edge ENTRY. DECL_ADDRESS maps decls |
317 to their addresses that can be reused. The address of OBJ is known to | 437 to their addresses that can be reused. The address of OBJ is known to |
318 be invariant in the whole function. */ | 438 be invariant in the whole function. Other needed statements are placed |
439 right before GSI. */ | |
319 | 440 |
320 static tree | 441 static tree |
321 take_address_of (tree obj, tree type, edge entry, htab_t decl_address) | 442 take_address_of (tree obj, tree type, edge entry, htab_t decl_address, |
443 gimple_stmt_iterator *gsi) | |
322 { | 444 { |
323 int uid; | 445 int uid; |
324 void **dslot; | 446 void **dslot; |
325 struct int_tree_map ielt, *nielt; | 447 struct int_tree_map ielt, *nielt; |
326 tree *var_p, name, bvar, addr; | 448 tree *var_p, name, bvar, addr; |
332 obj = unshare_expr (obj); | 454 obj = unshare_expr (obj); |
333 for (var_p = &obj; | 455 for (var_p = &obj; |
334 handled_component_p (*var_p); | 456 handled_component_p (*var_p); |
335 var_p = &TREE_OPERAND (*var_p, 0)) | 457 var_p = &TREE_OPERAND (*var_p, 0)) |
336 continue; | 458 continue; |
337 uid = DECL_UID (*var_p); | 459 |
338 | 460 /* Canonicalize the access to base on a MEM_REF. */ |
461 if (DECL_P (*var_p)) | |
462 *var_p = build_simple_mem_ref (build_fold_addr_expr (*var_p)); | |
463 | |
464 /* Assign a canonical SSA name to the address of the base decl used | |
465 in the address and share it for all accesses and addresses based | |
466 on it. */ | |
467 uid = DECL_UID (TREE_OPERAND (TREE_OPERAND (*var_p, 0), 0)); | |
339 ielt.uid = uid; | 468 ielt.uid = uid; |
340 dslot = htab_find_slot_with_hash (decl_address, &ielt, uid, INSERT); | 469 dslot = htab_find_slot_with_hash (decl_address, &ielt, uid, INSERT); |
341 if (!*dslot) | 470 if (!*dslot) |
342 { | 471 { |
343 addr = build_addr (*var_p, current_function_decl); | 472 if (gsi == NULL) |
344 bvar = create_tmp_var (TREE_TYPE (addr), get_name (*var_p)); | 473 return NULL; |
474 addr = TREE_OPERAND (*var_p, 0); | |
475 bvar = create_tmp_var (TREE_TYPE (addr), | |
476 get_name (TREE_OPERAND | |
477 (TREE_OPERAND (*var_p, 0), 0))); | |
345 add_referenced_var (bvar); | 478 add_referenced_var (bvar); |
346 stmt = gimple_build_assign (bvar, addr); | 479 stmt = gimple_build_assign (bvar, addr); |
347 name = make_ssa_name (bvar, stmt); | 480 name = make_ssa_name (bvar, stmt); |
348 gimple_assign_set_lhs (stmt, name); | 481 gimple_assign_set_lhs (stmt, name); |
349 gsi_insert_on_edge_immediate (entry, stmt); | 482 gsi_insert_on_edge_immediate (entry, stmt); |
354 *dslot = nielt; | 487 *dslot = nielt; |
355 } | 488 } |
356 else | 489 else |
357 name = ((struct int_tree_map *) *dslot)->to; | 490 name = ((struct int_tree_map *) *dslot)->to; |
358 | 491 |
359 if (var_p != &obj) | 492 /* Express the address in terms of the canonical SSA name. */ |
360 { | 493 TREE_OPERAND (*var_p, 0) = name; |
361 *var_p = build1 (INDIRECT_REF, TREE_TYPE (*var_p), name); | 494 if (gsi == NULL) |
362 name = force_gimple_operand (build_addr (obj, current_function_decl), | 495 return build_fold_addr_expr_with_type (obj, type); |
363 &stmts, true, NULL_TREE); | 496 |
364 if (!gimple_seq_empty_p (stmts)) | 497 name = force_gimple_operand (build_addr (obj, current_function_decl), |
365 gsi_insert_seq_on_edge_immediate (entry, stmts); | 498 &stmts, true, NULL_TREE); |
366 } | 499 if (!gimple_seq_empty_p (stmts)) |
367 | 500 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT); |
368 if (TREE_TYPE (name) != type) | 501 |
502 if (!useless_type_conversion_p (type, TREE_TYPE (name))) | |
369 { | 503 { |
370 name = force_gimple_operand (fold_convert (type, name), &stmts, true, | 504 name = force_gimple_operand (fold_convert (type, name), &stmts, true, |
371 NULL_TREE); | 505 NULL_TREE); |
372 if (!gimple_seq_empty_p (stmts)) | 506 if (!gimple_seq_empty_p (stmts)) |
373 gsi_insert_seq_on_edge_immediate (entry, stmts); | 507 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT); |
374 } | 508 } |
375 | 509 |
376 return name; | 510 return name; |
377 } | 511 } |
378 | 512 |
430 struct elv_data | 564 struct elv_data |
431 { | 565 { |
432 struct walk_stmt_info info; | 566 struct walk_stmt_info info; |
433 edge entry; | 567 edge entry; |
434 htab_t decl_address; | 568 htab_t decl_address; |
569 gimple_stmt_iterator *gsi; | |
435 bool changed; | 570 bool changed; |
571 bool reset; | |
436 }; | 572 }; |
437 | 573 |
438 /* Eliminates references to local variables in *TP out of the single | 574 /* Eliminates references to local variables in *TP out of the single |
439 entry single exit region starting at DTA->ENTRY. | 575 entry single exit region starting at DTA->ENTRY. |
440 DECL_ADDRESS contains addresses of the references that had their | 576 DECL_ADDRESS contains addresses of the references that had their |
454 if (!SSA_VAR_P (t) || DECL_EXTERNAL (t)) | 590 if (!SSA_VAR_P (t) || DECL_EXTERNAL (t)) |
455 return NULL_TREE; | 591 return NULL_TREE; |
456 | 592 |
457 type = TREE_TYPE (t); | 593 type = TREE_TYPE (t); |
458 addr_type = build_pointer_type (type); | 594 addr_type = build_pointer_type (type); |
459 addr = take_address_of (t, addr_type, dta->entry, dta->decl_address); | 595 addr = take_address_of (t, addr_type, dta->entry, dta->decl_address, |
460 *tp = build1 (INDIRECT_REF, TREE_TYPE (*tp), addr); | 596 dta->gsi); |
597 if (dta->gsi == NULL && addr == NULL_TREE) | |
598 { | |
599 dta->reset = true; | |
600 return NULL_TREE; | |
601 } | |
602 | |
603 *tp = build_simple_mem_ref (addr); | |
461 | 604 |
462 dta->changed = true; | 605 dta->changed = true; |
463 return NULL_TREE; | 606 return NULL_TREE; |
464 } | 607 } |
465 | 608 |
484 var = get_base_address (obj); | 627 var = get_base_address (obj); |
485 if (!var || !SSA_VAR_P (var) || DECL_EXTERNAL (var)) | 628 if (!var || !SSA_VAR_P (var) || DECL_EXTERNAL (var)) |
486 return NULL_TREE; | 629 return NULL_TREE; |
487 | 630 |
488 addr_type = TREE_TYPE (t); | 631 addr_type = TREE_TYPE (t); |
489 addr = take_address_of (obj, addr_type, dta->entry, dta->decl_address); | 632 addr = take_address_of (obj, addr_type, dta->entry, dta->decl_address, |
633 dta->gsi); | |
634 if (dta->gsi == NULL && addr == NULL_TREE) | |
635 { | |
636 dta->reset = true; | |
637 return NULL_TREE; | |
638 } | |
490 *tp = addr; | 639 *tp = addr; |
491 | 640 |
492 dta->changed = true; | 641 dta->changed = true; |
493 return NULL_TREE; | 642 return NULL_TREE; |
494 } | 643 } |
497 *walk_subtrees = 0; | 646 *walk_subtrees = 0; |
498 | 647 |
499 return NULL_TREE; | 648 return NULL_TREE; |
500 } | 649 } |
501 | 650 |
502 /* Moves the references to local variables in STMT out of the single | 651 /* Moves the references to local variables in STMT at *GSI out of the single |
503 entry single exit region starting at ENTRY. DECL_ADDRESS contains | 652 entry single exit region starting at ENTRY. DECL_ADDRESS contains |
504 addresses of the references that had their address taken | 653 addresses of the references that had their address taken |
505 already. */ | 654 already. */ |
506 | 655 |
507 static void | 656 static void |
508 eliminate_local_variables_stmt (edge entry, gimple stmt, | 657 eliminate_local_variables_stmt (edge entry, gimple_stmt_iterator *gsi, |
509 htab_t decl_address) | 658 htab_t decl_address) |
510 { | 659 { |
511 struct elv_data dta; | 660 struct elv_data dta; |
661 gimple stmt = gsi_stmt (*gsi); | |
512 | 662 |
513 memset (&dta.info, '\0', sizeof (dta.info)); | 663 memset (&dta.info, '\0', sizeof (dta.info)); |
514 dta.entry = entry; | 664 dta.entry = entry; |
515 dta.decl_address = decl_address; | 665 dta.decl_address = decl_address; |
516 dta.changed = false; | 666 dta.changed = false; |
667 dta.reset = false; | |
517 | 668 |
518 if (gimple_debug_bind_p (stmt)) | 669 if (gimple_debug_bind_p (stmt)) |
519 walk_tree (gimple_debug_bind_get_value_ptr (stmt), | 670 { |
520 eliminate_local_variables_1, &dta.info, NULL); | 671 dta.gsi = NULL; |
672 walk_tree (gimple_debug_bind_get_value_ptr (stmt), | |
673 eliminate_local_variables_1, &dta.info, NULL); | |
674 if (dta.reset) | |
675 { | |
676 gimple_debug_bind_reset_value (stmt); | |
677 dta.changed = true; | |
678 } | |
679 } | |
521 else | 680 else |
522 walk_gimple_op (stmt, eliminate_local_variables_1, &dta.info); | 681 { |
682 dta.gsi = gsi; | |
683 walk_gimple_op (stmt, eliminate_local_variables_1, &dta.info); | |
684 } | |
523 | 685 |
524 if (dta.changed) | 686 if (dta.changed) |
525 update_stmt (stmt); | 687 update_stmt (stmt); |
526 } | 688 } |
527 | 689 |
541 { | 703 { |
542 basic_block bb; | 704 basic_block bb; |
543 VEC (basic_block, heap) *body = VEC_alloc (basic_block, heap, 3); | 705 VEC (basic_block, heap) *body = VEC_alloc (basic_block, heap, 3); |
544 unsigned i; | 706 unsigned i; |
545 gimple_stmt_iterator gsi; | 707 gimple_stmt_iterator gsi; |
708 bool has_debug_stmt = false; | |
546 htab_t decl_address = htab_create (10, int_tree_map_hash, int_tree_map_eq, | 709 htab_t decl_address = htab_create (10, int_tree_map_hash, int_tree_map_eq, |
547 free); | 710 free); |
548 basic_block entry_bb = entry->src; | 711 basic_block entry_bb = entry->src; |
549 basic_block exit_bb = exit->dest; | 712 basic_block exit_bb = exit->dest; |
550 | 713 |
551 gather_blocks_in_sese_region (entry_bb, exit_bb, &body); | 714 gather_blocks_in_sese_region (entry_bb, exit_bb, &body); |
552 | 715 |
553 for (i = 0; VEC_iterate (basic_block, body, i, bb); i++) | 716 FOR_EACH_VEC_ELT (basic_block, body, i, bb) |
554 if (bb != entry_bb && bb != exit_bb) | 717 if (bb != entry_bb && bb != exit_bb) |
555 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | 718 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
556 eliminate_local_variables_stmt (entry, gsi_stmt (gsi), | 719 if (gimple_debug_bind_p (gsi_stmt (gsi))) |
557 decl_address); | 720 has_debug_stmt = true; |
721 else | |
722 eliminate_local_variables_stmt (entry, &gsi, decl_address); | |
723 | |
724 if (has_debug_stmt) | |
725 FOR_EACH_VEC_ELT (basic_block, body, i, bb) | |
726 if (bb != entry_bb && bb != exit_bb) | |
727 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | |
728 if (gimple_debug_bind_p (gsi_stmt (gsi))) | |
729 eliminate_local_variables_stmt (entry, &gsi, decl_address); | |
558 | 730 |
559 htab_delete (decl_address); | 731 htab_delete (decl_address); |
560 VEC_free (basic_block, heap, body); | 732 VEC_free (basic_block, heap, body); |
561 } | 733 } |
562 | 734 |
856 { | 1028 { |
857 struct reduction_info *const reduc = (struct reduction_info *) *slot; | 1029 struct reduction_info *const reduc = (struct reduction_info *) *slot; |
858 struct clsn_data *const clsn_data = (struct clsn_data *) data; | 1030 struct clsn_data *const clsn_data = (struct clsn_data *) data; |
859 gimple_stmt_iterator gsi; | 1031 gimple_stmt_iterator gsi; |
860 tree type = TREE_TYPE (PHI_RESULT (reduc->reduc_phi)); | 1032 tree type = TREE_TYPE (PHI_RESULT (reduc->reduc_phi)); |
861 tree struct_type = TREE_TYPE (TREE_TYPE (clsn_data->load)); | |
862 tree load_struct; | 1033 tree load_struct; |
863 basic_block bb; | 1034 basic_block bb; |
864 basic_block new_bb; | 1035 basic_block new_bb; |
865 edge e; | 1036 edge e; |
866 tree t, addr, ref, x; | 1037 tree t, addr, ref, x; |
867 tree tmp_load, name; | 1038 tree tmp_load, name; |
868 gimple load; | 1039 gimple load; |
869 | 1040 |
870 load_struct = fold_build1 (INDIRECT_REF, struct_type, clsn_data->load); | 1041 load_struct = build_simple_mem_ref (clsn_data->load); |
871 t = build3 (COMPONENT_REF, type, load_struct, reduc->field, NULL_TREE); | 1042 t = build3 (COMPONENT_REF, type, load_struct, reduc->field, NULL_TREE); |
872 | 1043 |
873 addr = build_addr (t, current_function_decl); | 1044 addr = build_addr (t, current_function_decl); |
874 | 1045 |
875 /* Create phi node. */ | 1046 /* Create phi node. */ |
924 struct reduction_info *const red = (struct reduction_info *) *slot; | 1095 struct reduction_info *const red = (struct reduction_info *) *slot; |
925 struct clsn_data *const clsn_data = (struct clsn_data *) data; | 1096 struct clsn_data *const clsn_data = (struct clsn_data *) data; |
926 gimple stmt; | 1097 gimple stmt; |
927 gimple_stmt_iterator gsi; | 1098 gimple_stmt_iterator gsi; |
928 tree type = TREE_TYPE (gimple_assign_lhs (red->reduc_stmt)); | 1099 tree type = TREE_TYPE (gimple_assign_lhs (red->reduc_stmt)); |
929 tree struct_type = TREE_TYPE (TREE_TYPE (clsn_data->load)); | |
930 tree load_struct; | 1100 tree load_struct; |
931 tree name; | 1101 tree name; |
932 tree x; | 1102 tree x; |
933 | 1103 |
934 gsi = gsi_after_labels (clsn_data->load_bb); | 1104 gsi = gsi_after_labels (clsn_data->load_bb); |
935 load_struct = fold_build1 (INDIRECT_REF, struct_type, clsn_data->load); | 1105 load_struct = build_simple_mem_ref (clsn_data->load); |
936 load_struct = build3 (COMPONENT_REF, type, load_struct, red->field, | 1106 load_struct = build3 (COMPONENT_REF, type, load_struct, red->field, |
937 NULL_TREE); | 1107 NULL_TREE); |
938 | 1108 |
939 x = load_struct; | 1109 x = load_struct; |
940 name = PHI_RESULT (red->keep_res); | 1110 name = PHI_RESULT (red->keep_res); |
1011 struct clsn_data *const clsn_data = (struct clsn_data *) data; | 1181 struct clsn_data *const clsn_data = (struct clsn_data *) data; |
1012 tree t; | 1182 tree t; |
1013 gimple stmt; | 1183 gimple stmt; |
1014 gimple_stmt_iterator gsi; | 1184 gimple_stmt_iterator gsi; |
1015 tree type = TREE_TYPE (elt->new_name); | 1185 tree type = TREE_TYPE (elt->new_name); |
1016 tree struct_type = TREE_TYPE (TREE_TYPE (clsn_data->load)); | |
1017 tree load_struct; | 1186 tree load_struct; |
1018 | 1187 |
1019 gsi = gsi_last_bb (clsn_data->store_bb); | 1188 gsi = gsi_last_bb (clsn_data->store_bb); |
1020 t = build3 (COMPONENT_REF, type, clsn_data->store, elt->field, NULL_TREE); | 1189 t = build3 (COMPONENT_REF, type, clsn_data->store, elt->field, NULL_TREE); |
1021 stmt = gimple_build_assign (t, ssa_name (elt->version)); | 1190 stmt = gimple_build_assign (t, ssa_name (elt->version)); |
1022 mark_virtual_ops_for_renaming (stmt); | 1191 mark_virtual_ops_for_renaming (stmt); |
1023 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); | 1192 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); |
1024 | 1193 |
1025 gsi = gsi_last_bb (clsn_data->load_bb); | 1194 gsi = gsi_last_bb (clsn_data->load_bb); |
1026 load_struct = fold_build1 (INDIRECT_REF, struct_type, clsn_data->load); | 1195 load_struct = build_simple_mem_ref (clsn_data->load); |
1027 t = build3 (COMPONENT_REF, type, load_struct, elt->field, NULL_TREE); | 1196 t = build3 (COMPONENT_REF, type, load_struct, elt->field, NULL_TREE); |
1028 stmt = gimple_build_assign (elt->new_name, t); | 1197 stmt = gimple_build_assign (elt->new_name, t); |
1029 SSA_NAME_DEF_STMT (elt->new_name) = stmt; | 1198 SSA_NAME_DEF_STMT (elt->new_name) = stmt; |
1030 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); | 1199 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); |
1031 | 1200 |
1089 bool has_debug_stmt = false; | 1258 bool has_debug_stmt = false; |
1090 | 1259 |
1091 entry = single_succ_edge (entry_bb); | 1260 entry = single_succ_edge (entry_bb); |
1092 gather_blocks_in_sese_region (entry_bb, exit_bb, &body); | 1261 gather_blocks_in_sese_region (entry_bb, exit_bb, &body); |
1093 | 1262 |
1094 for (i = 0; VEC_iterate (basic_block, body, i, bb); i++) | 1263 FOR_EACH_VEC_ELT (basic_block, body, i, bb) |
1095 { | 1264 { |
1096 if (bb != entry_bb && bb != exit_bb) | 1265 if (bb != entry_bb && bb != exit_bb) |
1097 { | 1266 { |
1098 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | 1267 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
1099 separate_decls_in_region_stmt (entry, exit, gsi_stmt (gsi), | 1268 separate_decls_in_region_stmt (entry, exit, gsi_stmt (gsi), |
1117 make sure we will have debug info for as many variables as | 1286 make sure we will have debug info for as many variables as |
1118 possible (all of those that were dealt with in the loop above), | 1287 possible (all of those that were dealt with in the loop above), |
1119 and discard those for which we know there's nothing we can | 1288 and discard those for which we know there's nothing we can |
1120 do. */ | 1289 do. */ |
1121 if (has_debug_stmt) | 1290 if (has_debug_stmt) |
1122 for (i = 0; VEC_iterate (basic_block, body, i, bb); i++) | 1291 FOR_EACH_VEC_ELT (basic_block, body, i, bb) |
1123 if (bb != entry_bb && bb != exit_bb) | 1292 if (bb != entry_bb && bb != exit_bb) |
1124 { | 1293 { |
1125 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);) | 1294 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);) |
1126 { | 1295 { |
1127 gimple stmt = gsi_stmt (gsi); | 1296 gimple stmt = gsi_stmt (gsi); |
1152 } | 1321 } |
1153 else | 1322 else |
1154 { | 1323 { |
1155 /* Create the type for the structure to store the ssa names to. */ | 1324 /* Create the type for the structure to store the ssa names to. */ |
1156 type = lang_hooks.types.make_type (RECORD_TYPE); | 1325 type = lang_hooks.types.make_type (RECORD_TYPE); |
1157 type_name = build_decl (BUILTINS_LOCATION, | 1326 type_name = build_decl (UNKNOWN_LOCATION, |
1158 TYPE_DECL, create_tmp_var_name (".paral_data"), | 1327 TYPE_DECL, create_tmp_var_name (".paral_data"), |
1159 type); | 1328 type); |
1160 TYPE_NAME (type) = type_name; | 1329 TYPE_NAME (type) = type_name; |
1161 | 1330 |
1162 htab_traverse (name_copies, add_field_for_name, type); | 1331 htab_traverse (name_copies, add_field_for_name, type); |
1219 | 1388 |
1220 /* Creates and returns an empty function that will receive the body of | 1389 /* Creates and returns an empty function that will receive the body of |
1221 a parallelized loop. */ | 1390 a parallelized loop. */ |
1222 | 1391 |
1223 static tree | 1392 static tree |
1224 create_loop_fn (void) | 1393 create_loop_fn (location_t loc) |
1225 { | 1394 { |
1226 char buf[100]; | 1395 char buf[100]; |
1227 char *tname; | 1396 char *tname; |
1228 tree decl, type, name, t; | 1397 tree decl, type, name, t; |
1229 struct function *act_cfun = cfun; | 1398 struct function *act_cfun = cfun; |
1233 ASM_FORMAT_PRIVATE_NAME (tname, buf, loopfn_num++); | 1402 ASM_FORMAT_PRIVATE_NAME (tname, buf, loopfn_num++); |
1234 clean_symbol_name (tname); | 1403 clean_symbol_name (tname); |
1235 name = get_identifier (tname); | 1404 name = get_identifier (tname); |
1236 type = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); | 1405 type = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); |
1237 | 1406 |
1238 decl = build_decl (BUILTINS_LOCATION, | 1407 decl = build_decl (loc, FUNCTION_DECL, name, type); |
1239 FUNCTION_DECL, name, type); | |
1240 if (!parallelized_functions) | 1408 if (!parallelized_functions) |
1241 parallelized_functions = BITMAP_GGC_ALLOC (); | 1409 parallelized_functions = BITMAP_GGC_ALLOC (); |
1242 bitmap_set_bit (parallelized_functions, DECL_UID (decl)); | 1410 bitmap_set_bit (parallelized_functions, DECL_UID (decl)); |
1243 | 1411 |
1244 TREE_STATIC (decl) = 1; | 1412 TREE_STATIC (decl) = 1; |
1249 DECL_UNINLINABLE (decl) = 1; | 1417 DECL_UNINLINABLE (decl) = 1; |
1250 DECL_EXTERNAL (decl) = 0; | 1418 DECL_EXTERNAL (decl) = 0; |
1251 DECL_CONTEXT (decl) = NULL_TREE; | 1419 DECL_CONTEXT (decl) = NULL_TREE; |
1252 DECL_INITIAL (decl) = make_node (BLOCK); | 1420 DECL_INITIAL (decl) = make_node (BLOCK); |
1253 | 1421 |
1254 t = build_decl (BUILTINS_LOCATION, | 1422 t = build_decl (loc, RESULT_DECL, NULL_TREE, void_type_node); |
1255 RESULT_DECL, NULL_TREE, void_type_node); | |
1256 DECL_ARTIFICIAL (t) = 1; | 1423 DECL_ARTIFICIAL (t) = 1; |
1257 DECL_IGNORED_P (t) = 1; | 1424 DECL_IGNORED_P (t) = 1; |
1258 DECL_RESULT (decl) = t; | 1425 DECL_RESULT (decl) = t; |
1259 | 1426 |
1260 t = build_decl (BUILTINS_LOCATION, | 1427 t = build_decl (loc, PARM_DECL, get_identifier (".paral_data_param"), |
1261 PARM_DECL, get_identifier (".paral_data_param"), | |
1262 ptr_type_node); | 1428 ptr_type_node); |
1263 DECL_ARTIFICIAL (t) = 1; | 1429 DECL_ARTIFICIAL (t) = 1; |
1264 DECL_ARG_TYPE (t) = ptr_type_node; | 1430 DECL_ARG_TYPE (t) = ptr_type_node; |
1265 DECL_CONTEXT (t) = decl; | 1431 DECL_CONTEXT (t) = decl; |
1266 TREE_USED (t) = 1; | 1432 TREE_USED (t) = 1; |
1398 of LOOP_FN. N_THREADS is the requested number of threads. Returns the | 1564 of LOOP_FN. N_THREADS is the requested number of threads. Returns the |
1399 basic block containing GIMPLE_OMP_PARALLEL tree. */ | 1565 basic block containing GIMPLE_OMP_PARALLEL tree. */ |
1400 | 1566 |
1401 static basic_block | 1567 static basic_block |
1402 create_parallel_loop (struct loop *loop, tree loop_fn, tree data, | 1568 create_parallel_loop (struct loop *loop, tree loop_fn, tree data, |
1403 tree new_data, unsigned n_threads) | 1569 tree new_data, unsigned n_threads, location_t loc) |
1404 { | 1570 { |
1405 gimple_stmt_iterator gsi; | 1571 gimple_stmt_iterator gsi; |
1406 basic_block bb, paral_bb, for_bb, ex_bb; | 1572 basic_block bb, paral_bb, for_bb, ex_bb; |
1407 tree t, param; | 1573 tree t, param; |
1408 gimple stmt, for_stmt, phi, cond_stmt; | 1574 gimple stmt, for_stmt, phi, cond_stmt; |
1412 /* Prepare the GIMPLE_OMP_PARALLEL statement. */ | 1578 /* Prepare the GIMPLE_OMP_PARALLEL statement. */ |
1413 bb = loop_preheader_edge (loop)->src; | 1579 bb = loop_preheader_edge (loop)->src; |
1414 paral_bb = single_pred (bb); | 1580 paral_bb = single_pred (bb); |
1415 gsi = gsi_last_bb (paral_bb); | 1581 gsi = gsi_last_bb (paral_bb); |
1416 | 1582 |
1417 t = build_omp_clause (BUILTINS_LOCATION, OMP_CLAUSE_NUM_THREADS); | 1583 t = build_omp_clause (loc, OMP_CLAUSE_NUM_THREADS); |
1418 OMP_CLAUSE_NUM_THREADS_EXPR (t) | 1584 OMP_CLAUSE_NUM_THREADS_EXPR (t) |
1419 = build_int_cst (integer_type_node, n_threads); | 1585 = build_int_cst (integer_type_node, n_threads); |
1420 stmt = gimple_build_omp_parallel (NULL, t, loop_fn, data); | 1586 stmt = gimple_build_omp_parallel (NULL, t, loop_fn, data); |
1587 gimple_set_location (stmt, loc); | |
1421 | 1588 |
1422 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); | 1589 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); |
1423 | 1590 |
1424 /* Initialize NEW_DATA. */ | 1591 /* Initialize NEW_DATA. */ |
1425 if (data) | 1592 if (data) |
1438 } | 1605 } |
1439 | 1606 |
1440 /* Emit GIMPLE_OMP_RETURN for GIMPLE_OMP_PARALLEL. */ | 1607 /* Emit GIMPLE_OMP_RETURN for GIMPLE_OMP_PARALLEL. */ |
1441 bb = split_loop_exit_edge (single_dom_exit (loop)); | 1608 bb = split_loop_exit_edge (single_dom_exit (loop)); |
1442 gsi = gsi_last_bb (bb); | 1609 gsi = gsi_last_bb (bb); |
1443 gsi_insert_after (&gsi, gimple_build_omp_return (false), GSI_NEW_STMT); | 1610 stmt = gimple_build_omp_return (false); |
1611 gimple_set_location (stmt, loc); | |
1612 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); | |
1444 | 1613 |
1445 /* Extract data for GIMPLE_OMP_FOR. */ | 1614 /* Extract data for GIMPLE_OMP_FOR. */ |
1446 gcc_assert (loop->header == single_dom_exit (loop)->src); | 1615 gcc_assert (loop->header == single_dom_exit (loop)->src); |
1447 cond_stmt = last_stmt (loop->header); | 1616 cond_stmt = last_stmt (loop->header); |
1448 | 1617 |
1453 initvar = make_ssa_name (cvar_base, NULL); | 1622 initvar = make_ssa_name (cvar_base, NULL); |
1454 SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, loop_preheader_edge (loop)), | 1623 SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, loop_preheader_edge (loop)), |
1455 initvar); | 1624 initvar); |
1456 cvar_next = PHI_ARG_DEF_FROM_EDGE (phi, loop_latch_edge (loop)); | 1625 cvar_next = PHI_ARG_DEF_FROM_EDGE (phi, loop_latch_edge (loop)); |
1457 | 1626 |
1458 gsi = gsi_last_bb (loop->latch); | 1627 gsi = gsi_last_nondebug_bb (loop->latch); |
1459 gcc_assert (gsi_stmt (gsi) == SSA_NAME_DEF_STMT (cvar_next)); | 1628 gcc_assert (gsi_stmt (gsi) == SSA_NAME_DEF_STMT (cvar_next)); |
1460 gsi_remove (&gsi, true); | 1629 gsi_remove (&gsi, true); |
1461 | 1630 |
1462 /* Prepare cfg. */ | 1631 /* Prepare cfg. */ |
1463 for_bb = split_edge (loop_preheader_edge (loop)); | 1632 for_bb = split_edge (loop_preheader_edge (loop)); |
1488 PENDING_STMT (e) = NULL; | 1657 PENDING_STMT (e) = NULL; |
1489 | 1658 |
1490 /* Emit GIMPLE_OMP_FOR. */ | 1659 /* Emit GIMPLE_OMP_FOR. */ |
1491 gimple_cond_set_lhs (cond_stmt, cvar_base); | 1660 gimple_cond_set_lhs (cond_stmt, cvar_base); |
1492 type = TREE_TYPE (cvar); | 1661 type = TREE_TYPE (cvar); |
1493 t = build_omp_clause (BUILTINS_LOCATION, OMP_CLAUSE_SCHEDULE); | 1662 t = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); |
1494 OMP_CLAUSE_SCHEDULE_KIND (t) = OMP_CLAUSE_SCHEDULE_STATIC; | 1663 OMP_CLAUSE_SCHEDULE_KIND (t) = OMP_CLAUSE_SCHEDULE_STATIC; |
1495 | 1664 |
1496 for_stmt = gimple_build_omp_for (NULL, t, 1, NULL); | 1665 for_stmt = gimple_build_omp_for (NULL, t, 1, NULL); |
1666 gimple_set_location (for_stmt, loc); | |
1497 gimple_omp_for_set_index (for_stmt, 0, initvar); | 1667 gimple_omp_for_set_index (for_stmt, 0, initvar); |
1498 gimple_omp_for_set_initial (for_stmt, 0, cvar_init); | 1668 gimple_omp_for_set_initial (for_stmt, 0, cvar_init); |
1499 gimple_omp_for_set_final (for_stmt, 0, gimple_cond_rhs (cond_stmt)); | 1669 gimple_omp_for_set_final (for_stmt, 0, gimple_cond_rhs (cond_stmt)); |
1500 gimple_omp_for_set_cond (for_stmt, 0, gimple_cond_code (cond_stmt)); | 1670 gimple_omp_for_set_cond (for_stmt, 0, gimple_cond_code (cond_stmt)); |
1501 gimple_omp_for_set_incr (for_stmt, 0, build2 (PLUS_EXPR, type, | 1671 gimple_omp_for_set_incr (for_stmt, 0, build2 (PLUS_EXPR, type, |
1507 SSA_NAME_DEF_STMT (initvar) = for_stmt; | 1677 SSA_NAME_DEF_STMT (initvar) = for_stmt; |
1508 | 1678 |
1509 /* Emit GIMPLE_OMP_CONTINUE. */ | 1679 /* Emit GIMPLE_OMP_CONTINUE. */ |
1510 gsi = gsi_last_bb (loop->latch); | 1680 gsi = gsi_last_bb (loop->latch); |
1511 stmt = gimple_build_omp_continue (cvar_next, cvar); | 1681 stmt = gimple_build_omp_continue (cvar_next, cvar); |
1682 gimple_set_location (stmt, loc); | |
1512 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); | 1683 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); |
1513 SSA_NAME_DEF_STMT (cvar_next) = stmt; | 1684 SSA_NAME_DEF_STMT (cvar_next) = stmt; |
1514 | 1685 |
1515 /* Emit GIMPLE_OMP_RETURN for GIMPLE_OMP_FOR. */ | 1686 /* Emit GIMPLE_OMP_RETURN for GIMPLE_OMP_FOR. */ |
1516 gsi = gsi_last_bb (ex_bb); | 1687 gsi = gsi_last_bb (ex_bb); |
1517 gsi_insert_after (&gsi, gimple_build_omp_return (true), GSI_NEW_STMT); | 1688 stmt = gimple_build_omp_return (true); |
1689 gimple_set_location (stmt, loc); | |
1690 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); | |
1518 | 1691 |
1519 return paral_bb; | 1692 return paral_bb; |
1520 } | 1693 } |
1521 | 1694 |
1522 /* Generates code to execute the iterations of LOOP in N_THREADS | 1695 /* Generates code to execute the iterations of LOOP in N_THREADS |
1535 gimple_seq stmts; | 1708 gimple_seq stmts; |
1536 basic_block parallel_head; | 1709 basic_block parallel_head; |
1537 edge entry, exit; | 1710 edge entry, exit; |
1538 struct clsn_data clsn_data; | 1711 struct clsn_data clsn_data; |
1539 unsigned prob; | 1712 unsigned prob; |
1713 location_t loc; | |
1714 gimple cond_stmt; | |
1540 | 1715 |
1541 /* From | 1716 /* From |
1542 | 1717 |
1543 --------------------------------------------------------------------- | 1718 --------------------------------------------------------------------- |
1544 loop | 1719 loop |
1646 and back, and create separate decls for the variables used in loop. */ | 1821 and back, and create separate decls for the variables used in loop. */ |
1647 separate_decls_in_region (entry, exit, reduction_list, &arg_struct, | 1822 separate_decls_in_region (entry, exit, reduction_list, &arg_struct, |
1648 &new_arg_struct, &clsn_data); | 1823 &new_arg_struct, &clsn_data); |
1649 | 1824 |
1650 /* Create the parallel constructs. */ | 1825 /* Create the parallel constructs. */ |
1651 parallel_head = create_parallel_loop (loop, create_loop_fn (), arg_struct, | 1826 loc = UNKNOWN_LOCATION; |
1652 new_arg_struct, n_threads); | 1827 cond_stmt = last_stmt (loop->header); |
1828 if (cond_stmt) | |
1829 loc = gimple_location (cond_stmt); | |
1830 parallel_head = create_parallel_loop (loop, create_loop_fn (loc), arg_struct, | |
1831 new_arg_struct, n_threads, loc); | |
1653 if (htab_elements (reduction_list) > 0) | 1832 if (htab_elements (reduction_list) > 0) |
1654 create_call_for_reduction (loop, reduction_list, &clsn_data); | 1833 create_call_for_reduction (loop, reduction_list, &clsn_data); |
1655 | 1834 |
1656 scev_reset (); | 1835 scev_reset (); |
1657 | 1836 |
1714 | 1893 |
1715 new_reduction = XCNEW (struct reduction_info); | 1894 new_reduction = XCNEW (struct reduction_info); |
1716 | 1895 |
1717 new_reduction->reduc_stmt = reduc_stmt; | 1896 new_reduction->reduc_stmt = reduc_stmt; |
1718 new_reduction->reduc_phi = phi; | 1897 new_reduction->reduc_phi = phi; |
1898 new_reduction->reduc_version = SSA_NAME_VERSION (gimple_phi_result (phi)); | |
1719 new_reduction->reduction_code = gimple_assign_rhs_code (reduc_stmt); | 1899 new_reduction->reduction_code = gimple_assign_rhs_code (reduc_stmt); |
1720 slot = htab_find_slot (reduction_list, new_reduction, INSERT); | 1900 slot = htab_find_slot (reduction_list, new_reduction, INSERT); |
1721 *slot = new_reduction; | 1901 *slot = new_reduction; |
1902 } | |
1903 | |
1904 /* Callback for htab_traverse. Sets gimple_uid of reduc_phi stmts. */ | |
1905 | |
1906 static int | |
1907 set_reduc_phi_uids (void **slot, void *data ATTRIBUTE_UNUSED) | |
1908 { | |
1909 struct reduction_info *const red = (struct reduction_info *) *slot; | |
1910 gimple_set_uid (red->reduc_phi, red->reduc_version); | |
1911 return 1; | |
1722 } | 1912 } |
1723 | 1913 |
1724 /* Detect all reductions in the LOOP, insert them into REDUCTION_LIST. */ | 1914 /* Detect all reductions in the LOOP, insert them into REDUCTION_LIST. */ |
1725 | 1915 |
1726 static void | 1916 static void |
1750 &double_reduc); | 1940 &double_reduc); |
1751 if (reduc_stmt && !double_reduc) | 1941 if (reduc_stmt && !double_reduc) |
1752 build_new_reduction (reduction_list, reduc_stmt, phi); | 1942 build_new_reduction (reduction_list, reduc_stmt, phi); |
1753 } | 1943 } |
1754 } | 1944 } |
1755 destroy_loop_vec_info (simple_loop_info, true); | 1945 destroy_loop_vec_info (simple_loop_info, true); |
1946 | |
1947 /* As gimple_uid is used by the vectorizer in between vect_analyze_loop_form | |
1948 and destroy_loop_vec_info, we can set gimple_uid of reduc_phi stmts | |
1949 only now. */ | |
1950 htab_traverse (reduction_list, set_reduc_phi_uids, NULL); | |
1756 } | 1951 } |
1757 | 1952 |
1758 /* Try to initialize NITER for code generation part. */ | 1953 /* Try to initialize NITER for code generation part. */ |
1759 | 1954 |
1760 static bool | 1955 static bool |
1820 return false; | 2015 return false; |
1821 } | 2016 } |
1822 reduc_phi = NULL; | 2017 reduc_phi = NULL; |
1823 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, val) | 2018 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, val) |
1824 { | 2019 { |
1825 if (flow_bb_inside_loop_p (loop, gimple_bb (USE_STMT (use_p)))) | 2020 if (!gimple_debug_bind_p (USE_STMT (use_p)) |
2021 && flow_bb_inside_loop_p (loop, gimple_bb (USE_STMT (use_p)))) | |
1826 { | 2022 { |
1827 reduc_phi = USE_STMT (use_p); | 2023 reduc_phi = USE_STMT (use_p); |
1828 break; | 2024 break; |
1829 } | 2025 } |
1830 } | 2026 } |