comparison gcc/tree-parloops.c @ 69:1b10fe6932e1

merge 69
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 21 Aug 2011 07:53:12 +0900
parents f6334be47118
children 04ced10e8804
comparison
equal deleted inserted replaced
66:b362627d71ba 69:1b10fe6932e1
1 /* Loop autoparallelization. 1 /* Loop autoparallelization.
2 Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 2 Copyright (C) 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <pop@cri.ensmp.fr> and 4 Contributed by Sebastian Pop <pop@cri.ensmp.fr> and
4 Zdenek Dvorak <dvorakz@suse.cz>. 5 Zdenek Dvorak <dvorakz@suse.cz>.
5 6
6 This file is part of GCC. 7 This file is part of GCC.
7 8
20 <http://www.gnu.org/licenses/>. */ 21 <http://www.gnu.org/licenses/>. */
21 22
22 #include "config.h" 23 #include "config.h"
23 #include "system.h" 24 #include "system.h"
24 #include "coretypes.h" 25 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "tree-flow.h" 26 #include "tree-flow.h"
29 #include "cfgloop.h" 27 #include "cfgloop.h"
30 #include "ggc.h"
31 #include "tree-data-ref.h" 28 #include "tree-data-ref.h"
32 #include "diagnostic.h" 29 #include "tree-scalar-evolution.h"
30 #include "gimple-pretty-print.h"
33 #include "tree-pass.h" 31 #include "tree-pass.h"
34 #include "tree-scalar-evolution.h"
35 #include "hashtab.h"
36 #include "langhooks.h" 32 #include "langhooks.h"
37 #include "tree-vectorizer.h" 33 #include "tree-vectorizer.h"
38 34
39 /* This pass tries to distribute iterations of loops into several threads. 35 /* This pass tries to distribute iterations of loops into several threads.
40 The implementation is straightforward -- for each loop we test whether its 36 The implementation is straightforward -- for each loop we test whether its
61 -- handling of common scalar dependence patterns (accumulation, ...) 57 -- handling of common scalar dependence patterns (accumulation, ...)
62 -- handling of non-innermost loops */ 58 -- handling of non-innermost loops */
63 59
64 /* 60 /*
65 Reduction handling: 61 Reduction handling:
66 currently we use vect_is_simple_reduction() to detect reduction patterns. 62 currently we use vect_force_simple_reduction() to detect reduction patterns.
67 The code transformation will be introduced by an example. 63 The code transformation will be introduced by an example.
68 64
69 65
70 parloop 66 parloop
71 { 67 {
166 struct reduction_info 162 struct reduction_info
167 { 163 {
168 gimple reduc_stmt; /* reduction statement. */ 164 gimple reduc_stmt; /* reduction statement. */
169 gimple reduc_phi; /* The phi node defining the reduction. */ 165 gimple reduc_phi; /* The phi node defining the reduction. */
170 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. */
171 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
172 of the reduction variable when existing the loop. */ 170 of the reduction variable when existing the loop. */
173 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. */
174 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. */
175 tree init; /* reduction initialization value. */ 173 tree init; /* reduction initialization value. */
193 static hashval_t 191 static hashval_t
194 reduction_info_hash (const void *aa) 192 reduction_info_hash (const void *aa)
195 { 193 {
196 const struct reduction_info *a = (const struct reduction_info *) aa; 194 const struct reduction_info *a = (const struct reduction_info *) aa;
197 195
198 return htab_hash_pointer (a->reduc_phi); 196 return a->reduc_version;
199 } 197 }
200 198
201 static struct reduction_info * 199 static struct reduction_info *
202 reduction_phi (htab_t reduction_list, gimple phi) 200 reduction_phi (htab_t reduction_list, gimple phi)
203 { 201 {
204 struct reduction_info tmpred, *red; 202 struct reduction_info tmpred, *red;
205 203
206 if (htab_elements (reduction_list) == 0) 204 if (htab_elements (reduction_list) == 0 || phi == NULL)
207 return NULL; 205 return NULL;
208 206
209 tmpred.reduc_phi = phi; 207 tmpred.reduc_phi = phi;
208 tmpred.reduc_version = gimple_uid (phi);
210 red = (struct reduction_info *) htab_find (reduction_list, &tmpred); 209 red = (struct reduction_info *) htab_find (reduction_list, &tmpred);
211 210
212 return red; 211 return red;
213 } 212 }
214 213
239 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;
240 239
241 return (hashval_t) a->version; 240 return (hashval_t) a->version;
242 } 241 }
243 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 }
244 362
245 /* Data dependency analysis. Returns true if the iterations of LOOP 363 /* Data dependency analysis. Returns true if the iterations of LOOP
246 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
247 in parallel). */ 365 in parallel). */
248 366
249 static bool 367 static bool
250 loop_parallel_p (struct loop *loop) 368 loop_parallel_p (struct loop *loop, struct obstack * parloop_obstack)
251 { 369 {
252 VEC (ddr_p, heap) * dependence_relations; 370 VEC (loop_p, heap) *loop_nest;
371 VEC (ddr_p, heap) *dependence_relations;
253 VEC (data_reference_p, heap) *datarefs; 372 VEC (data_reference_p, heap) *datarefs;
254 lambda_trans_matrix trans; 373 lambda_trans_matrix trans;
255 bool ret = false; 374 bool ret = false;
256 375
257 if (dump_file && (dump_flags & TDF_DETAILS)) 376 if (dump_file && (dump_flags & TDF_DETAILS))
265 384
266 /* Check for problems with dependences. If the loop can be reversed, 385 /* Check for problems with dependences. If the loop can be reversed,
267 the iterations are independent. */ 386 the iterations are independent. */
268 datarefs = VEC_alloc (data_reference_p, heap, 10); 387 datarefs = VEC_alloc (data_reference_p, heap, 10);
269 dependence_relations = VEC_alloc (ddr_p, heap, 10 * 10); 388 dependence_relations = VEC_alloc (ddr_p, heap, 10 * 10);
270 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,
271 &dependence_relations); 391 &dependence_relations);
272 if (dump_file && (dump_flags & TDF_DETAILS)) 392 if (dump_file && (dump_flags & TDF_DETAILS))
273 dump_data_dependence_relations (dump_file, dependence_relations); 393 dump_data_dependence_relations (dump_file, dependence_relations);
274 394
275 trans = lambda_trans_matrix_new (1, 1); 395 trans = lambda_trans_matrix_new (1, 1, parloop_obstack);
276 LTM_MATRIX (trans)[0][0] = -1; 396 LTM_MATRIX (trans)[0][0] = -1;
277 397
278 if (lambda_transform_legal_p (trans, 1, dependence_relations)) 398 if (lambda_transform_legal_p (trans, 1, dependence_relations))
279 { 399 {
280 ret = true; 400 ret = true;
283 } 403 }
284 else if (dump_file && (dump_flags & TDF_DETAILS)) 404 else if (dump_file && (dump_flags & TDF_DETAILS))
285 fprintf (dump_file, 405 fprintf (dump_file,
286 " FAILED: data dependencies exist across iterations\n"); 406 " FAILED: data dependencies exist across iterations\n");
287 407
408 VEC_free (loop_p, heap, loop_nest);
288 free_dependence_relations (dependence_relations); 409 free_dependence_relations (dependence_relations);
289 free_data_refs (datarefs); 410 free_data_refs (datarefs);
290 411
291 return ret; 412 return ret;
292 } 413 }
312 } 433 }
313 434
314 /* 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.
315 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
316 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
317 be invariant in the whole function. */ 438 be invariant in the whole function. Other needed statements are placed
439 right before GSI. */
318 440
319 static tree 441 static tree
320 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)
321 { 444 {
322 int uid; 445 int uid;
323 void **dslot; 446 void **dslot;
324 struct int_tree_map ielt, *nielt; 447 struct int_tree_map ielt, *nielt;
325 tree *var_p, name, bvar, addr; 448 tree *var_p, name, bvar, addr;
331 obj = unshare_expr (obj); 454 obj = unshare_expr (obj);
332 for (var_p = &obj; 455 for (var_p = &obj;
333 handled_component_p (*var_p); 456 handled_component_p (*var_p);
334 var_p = &TREE_OPERAND (*var_p, 0)) 457 var_p = &TREE_OPERAND (*var_p, 0))
335 continue; 458 continue;
336 uid = DECL_UID (*var_p); 459
337 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));
338 ielt.uid = uid; 468 ielt.uid = uid;
339 dslot = htab_find_slot_with_hash (decl_address, &ielt, uid, INSERT); 469 dslot = htab_find_slot_with_hash (decl_address, &ielt, uid, INSERT);
340 if (!*dslot) 470 if (!*dslot)
341 { 471 {
342 addr = build_addr (*var_p, current_function_decl); 472 if (gsi == NULL)
343 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)));
344 add_referenced_var (bvar); 478 add_referenced_var (bvar);
345 stmt = gimple_build_assign (bvar, addr); 479 stmt = gimple_build_assign (bvar, addr);
346 name = make_ssa_name (bvar, stmt); 480 name = make_ssa_name (bvar, stmt);
347 gimple_assign_set_lhs (stmt, name); 481 gimple_assign_set_lhs (stmt, name);
348 gsi_insert_on_edge_immediate (entry, stmt); 482 gsi_insert_on_edge_immediate (entry, stmt);
353 *dslot = nielt; 487 *dslot = nielt;
354 } 488 }
355 else 489 else
356 name = ((struct int_tree_map *) *dslot)->to; 490 name = ((struct int_tree_map *) *dslot)->to;
357 491
358 if (var_p != &obj) 492 /* Express the address in terms of the canonical SSA name. */
359 { 493 TREE_OPERAND (*var_p, 0) = name;
360 *var_p = build1 (INDIRECT_REF, TREE_TYPE (*var_p), name); 494 if (gsi == NULL)
361 name = force_gimple_operand (build_addr (obj, current_function_decl), 495 return build_fold_addr_expr_with_type (obj, type);
362 &stmts, true, NULL_TREE); 496
363 if (!gimple_seq_empty_p (stmts)) 497 name = force_gimple_operand (build_addr (obj, current_function_decl),
364 gsi_insert_seq_on_edge_immediate (entry, stmts); 498 &stmts, true, NULL_TREE);
365 } 499 if (!gimple_seq_empty_p (stmts))
366 500 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
367 if (TREE_TYPE (name) != type) 501
502 if (!useless_type_conversion_p (type, TREE_TYPE (name)))
368 { 503 {
369 name = force_gimple_operand (fold_convert (type, name), &stmts, true, 504 name = force_gimple_operand (fold_convert (type, name), &stmts, true,
370 NULL_TREE); 505 NULL_TREE);
371 if (!gimple_seq_empty_p (stmts)) 506 if (!gimple_seq_empty_p (stmts))
372 gsi_insert_seq_on_edge_immediate (entry, stmts); 507 gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
373 } 508 }
374 509
375 return name; 510 return name;
376 } 511 }
377 512
429 struct elv_data 564 struct elv_data
430 { 565 {
431 struct walk_stmt_info info; 566 struct walk_stmt_info info;
432 edge entry; 567 edge entry;
433 htab_t decl_address; 568 htab_t decl_address;
569 gimple_stmt_iterator *gsi;
434 bool changed; 570 bool changed;
571 bool reset;
435 }; 572 };
436 573
437 /* Eliminates references to local variables in *TP out of the single 574 /* Eliminates references to local variables in *TP out of the single
438 entry single exit region starting at DTA->ENTRY. 575 entry single exit region starting at DTA->ENTRY.
439 DECL_ADDRESS contains addresses of the references that had their 576 DECL_ADDRESS contains addresses of the references that had their
453 if (!SSA_VAR_P (t) || DECL_EXTERNAL (t)) 590 if (!SSA_VAR_P (t) || DECL_EXTERNAL (t))
454 return NULL_TREE; 591 return NULL_TREE;
455 592
456 type = TREE_TYPE (t); 593 type = TREE_TYPE (t);
457 addr_type = build_pointer_type (type); 594 addr_type = build_pointer_type (type);
458 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,
459 *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);
460 604
461 dta->changed = true; 605 dta->changed = true;
462 return NULL_TREE; 606 return NULL_TREE;
463 } 607 }
464 608
483 var = get_base_address (obj); 627 var = get_base_address (obj);
484 if (!var || !SSA_VAR_P (var) || DECL_EXTERNAL (var)) 628 if (!var || !SSA_VAR_P (var) || DECL_EXTERNAL (var))
485 return NULL_TREE; 629 return NULL_TREE;
486 630
487 addr_type = TREE_TYPE (t); 631 addr_type = TREE_TYPE (t);
488 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 }
489 *tp = addr; 639 *tp = addr;
490 640
491 dta->changed = true; 641 dta->changed = true;
492 return NULL_TREE; 642 return NULL_TREE;
493 } 643 }
496 *walk_subtrees = 0; 646 *walk_subtrees = 0;
497 647
498 return NULL_TREE; 648 return NULL_TREE;
499 } 649 }
500 650
501 /* 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
502 entry single exit region starting at ENTRY. DECL_ADDRESS contains 652 entry single exit region starting at ENTRY. DECL_ADDRESS contains
503 addresses of the references that had their address taken 653 addresses of the references that had their address taken
504 already. */ 654 already. */
505 655
506 static void 656 static void
507 eliminate_local_variables_stmt (edge entry, gimple stmt, 657 eliminate_local_variables_stmt (edge entry, gimple_stmt_iterator *gsi,
508 htab_t decl_address) 658 htab_t decl_address)
509 { 659 {
510 struct elv_data dta; 660 struct elv_data dta;
661 gimple stmt = gsi_stmt (*gsi);
511 662
512 memset (&dta.info, '\0', sizeof (dta.info)); 663 memset (&dta.info, '\0', sizeof (dta.info));
513 dta.entry = entry; 664 dta.entry = entry;
514 dta.decl_address = decl_address; 665 dta.decl_address = decl_address;
515 dta.changed = false; 666 dta.changed = false;
667 dta.reset = false;
516 668
517 if (gimple_debug_bind_p (stmt)) 669 if (gimple_debug_bind_p (stmt))
518 walk_tree (gimple_debug_bind_get_value_ptr (stmt), 670 {
519 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 }
520 else 680 else
521 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 }
522 685
523 if (dta.changed) 686 if (dta.changed)
524 update_stmt (stmt); 687 update_stmt (stmt);
525 } 688 }
526 689
540 { 703 {
541 basic_block bb; 704 basic_block bb;
542 VEC (basic_block, heap) *body = VEC_alloc (basic_block, heap, 3); 705 VEC (basic_block, heap) *body = VEC_alloc (basic_block, heap, 3);
543 unsigned i; 706 unsigned i;
544 gimple_stmt_iterator gsi; 707 gimple_stmt_iterator gsi;
708 bool has_debug_stmt = false;
545 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,
546 free); 710 free);
547 basic_block entry_bb = entry->src; 711 basic_block entry_bb = entry->src;
548 basic_block exit_bb = exit->dest; 712 basic_block exit_bb = exit->dest;
549 713
550 gather_blocks_in_sese_region (entry_bb, exit_bb, &body); 714 gather_blocks_in_sese_region (entry_bb, exit_bb, &body);
551 715
552 for (i = 0; VEC_iterate (basic_block, body, i, bb); i++) 716 FOR_EACH_VEC_ELT (basic_block, body, i, bb)
553 if (bb != entry_bb && bb != exit_bb) 717 if (bb != entry_bb && bb != exit_bb)
554 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))
555 eliminate_local_variables_stmt (entry, gsi_stmt (gsi), 719 if (gimple_debug_bind_p (gsi_stmt (gsi)))
556 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);
557 730
558 htab_delete (decl_address); 731 htab_delete (decl_address);
559 VEC_free (basic_block, heap, body); 732 VEC_free (basic_block, heap, body);
560 } 733 }
561 734
855 { 1028 {
856 struct reduction_info *const reduc = (struct reduction_info *) *slot; 1029 struct reduction_info *const reduc = (struct reduction_info *) *slot;
857 struct clsn_data *const clsn_data = (struct clsn_data *) data; 1030 struct clsn_data *const clsn_data = (struct clsn_data *) data;
858 gimple_stmt_iterator gsi; 1031 gimple_stmt_iterator gsi;
859 tree type = TREE_TYPE (PHI_RESULT (reduc->reduc_phi)); 1032 tree type = TREE_TYPE (PHI_RESULT (reduc->reduc_phi));
860 tree struct_type = TREE_TYPE (TREE_TYPE (clsn_data->load));
861 tree load_struct; 1033 tree load_struct;
862 basic_block bb; 1034 basic_block bb;
863 basic_block new_bb; 1035 basic_block new_bb;
864 edge e; 1036 edge e;
865 tree t, addr, ref, x; 1037 tree t, addr, ref, x;
866 tree tmp_load, name; 1038 tree tmp_load, name;
867 gimple load; 1039 gimple load;
868 1040
869 load_struct = fold_build1 (INDIRECT_REF, struct_type, clsn_data->load); 1041 load_struct = build_simple_mem_ref (clsn_data->load);
870 t = build3 (COMPONENT_REF, type, load_struct, reduc->field, NULL_TREE); 1042 t = build3 (COMPONENT_REF, type, load_struct, reduc->field, NULL_TREE);
871 1043
872 addr = build_addr (t, current_function_decl); 1044 addr = build_addr (t, current_function_decl);
873 1045
874 /* Create phi node. */ 1046 /* Create phi node. */
923 struct reduction_info *const red = (struct reduction_info *) *slot; 1095 struct reduction_info *const red = (struct reduction_info *) *slot;
924 struct clsn_data *const clsn_data = (struct clsn_data *) data; 1096 struct clsn_data *const clsn_data = (struct clsn_data *) data;
925 gimple stmt; 1097 gimple stmt;
926 gimple_stmt_iterator gsi; 1098 gimple_stmt_iterator gsi;
927 tree type = TREE_TYPE (gimple_assign_lhs (red->reduc_stmt)); 1099 tree type = TREE_TYPE (gimple_assign_lhs (red->reduc_stmt));
928 tree struct_type = TREE_TYPE (TREE_TYPE (clsn_data->load));
929 tree load_struct; 1100 tree load_struct;
930 tree name; 1101 tree name;
931 tree x; 1102 tree x;
932 1103
933 gsi = gsi_after_labels (clsn_data->load_bb); 1104 gsi = gsi_after_labels (clsn_data->load_bb);
934 load_struct = fold_build1 (INDIRECT_REF, struct_type, clsn_data->load); 1105 load_struct = build_simple_mem_ref (clsn_data->load);
935 load_struct = build3 (COMPONENT_REF, type, load_struct, red->field, 1106 load_struct = build3 (COMPONENT_REF, type, load_struct, red->field,
936 NULL_TREE); 1107 NULL_TREE);
937 1108
938 x = load_struct; 1109 x = load_struct;
939 name = PHI_RESULT (red->keep_res); 1110 name = PHI_RESULT (red->keep_res);
1010 struct clsn_data *const clsn_data = (struct clsn_data *) data; 1181 struct clsn_data *const clsn_data = (struct clsn_data *) data;
1011 tree t; 1182 tree t;
1012 gimple stmt; 1183 gimple stmt;
1013 gimple_stmt_iterator gsi; 1184 gimple_stmt_iterator gsi;
1014 tree type = TREE_TYPE (elt->new_name); 1185 tree type = TREE_TYPE (elt->new_name);
1015 tree struct_type = TREE_TYPE (TREE_TYPE (clsn_data->load));
1016 tree load_struct; 1186 tree load_struct;
1017 1187
1018 gsi = gsi_last_bb (clsn_data->store_bb); 1188 gsi = gsi_last_bb (clsn_data->store_bb);
1019 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);
1020 stmt = gimple_build_assign (t, ssa_name (elt->version)); 1190 stmt = gimple_build_assign (t, ssa_name (elt->version));
1021 mark_virtual_ops_for_renaming (stmt); 1191 mark_virtual_ops_for_renaming (stmt);
1022 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); 1192 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
1023 1193
1024 gsi = gsi_last_bb (clsn_data->load_bb); 1194 gsi = gsi_last_bb (clsn_data->load_bb);
1025 load_struct = fold_build1 (INDIRECT_REF, struct_type, clsn_data->load); 1195 load_struct = build_simple_mem_ref (clsn_data->load);
1026 t = build3 (COMPONENT_REF, type, load_struct, elt->field, NULL_TREE); 1196 t = build3 (COMPONENT_REF, type, load_struct, elt->field, NULL_TREE);
1027 stmt = gimple_build_assign (elt->new_name, t); 1197 stmt = gimple_build_assign (elt->new_name, t);
1028 SSA_NAME_DEF_STMT (elt->new_name) = stmt; 1198 SSA_NAME_DEF_STMT (elt->new_name) = stmt;
1029 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); 1199 gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
1030 1200
1088 bool has_debug_stmt = false; 1258 bool has_debug_stmt = false;
1089 1259
1090 entry = single_succ_edge (entry_bb); 1260 entry = single_succ_edge (entry_bb);
1091 gather_blocks_in_sese_region (entry_bb, exit_bb, &body); 1261 gather_blocks_in_sese_region (entry_bb, exit_bb, &body);
1092 1262
1093 for (i = 0; VEC_iterate (basic_block, body, i, bb); i++) 1263 FOR_EACH_VEC_ELT (basic_block, body, i, bb)
1094 { 1264 {
1095 if (bb != entry_bb && bb != exit_bb) 1265 if (bb != entry_bb && bb != exit_bb)
1096 { 1266 {
1097 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))
1098 separate_decls_in_region_stmt (entry, exit, gsi_stmt (gsi), 1268 separate_decls_in_region_stmt (entry, exit, gsi_stmt (gsi),
1116 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
1117 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),
1118 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
1119 do. */ 1289 do. */
1120 if (has_debug_stmt) 1290 if (has_debug_stmt)
1121 for (i = 0; VEC_iterate (basic_block, body, i, bb); i++) 1291 FOR_EACH_VEC_ELT (basic_block, body, i, bb)
1122 if (bb != entry_bb && bb != exit_bb) 1292 if (bb != entry_bb && bb != exit_bb)
1123 { 1293 {
1124 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);) 1294 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
1125 { 1295 {
1126 gimple stmt = gsi_stmt (gsi); 1296 gimple stmt = gsi_stmt (gsi);
1151 } 1321 }
1152 else 1322 else
1153 { 1323 {
1154 /* 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. */
1155 type = lang_hooks.types.make_type (RECORD_TYPE); 1325 type = lang_hooks.types.make_type (RECORD_TYPE);
1156 type_name = build_decl (BUILTINS_LOCATION, 1326 type_name = build_decl (UNKNOWN_LOCATION,
1157 TYPE_DECL, create_tmp_var_name (".paral_data"), 1327 TYPE_DECL, create_tmp_var_name (".paral_data"),
1158 type); 1328 type);
1159 TYPE_NAME (type) = type_name; 1329 TYPE_NAME (type) = type_name;
1160 1330
1161 htab_traverse (name_copies, add_field_for_name, type); 1331 htab_traverse (name_copies, add_field_for_name, type);
1218 1388
1219 /* 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
1220 a parallelized loop. */ 1390 a parallelized loop. */
1221 1391
1222 static tree 1392 static tree
1223 create_loop_fn (void) 1393 create_loop_fn (location_t loc)
1224 { 1394 {
1225 char buf[100]; 1395 char buf[100];
1226 char *tname; 1396 char *tname;
1227 tree decl, type, name, t; 1397 tree decl, type, name, t;
1228 struct function *act_cfun = cfun; 1398 struct function *act_cfun = cfun;
1232 ASM_FORMAT_PRIVATE_NAME (tname, buf, loopfn_num++); 1402 ASM_FORMAT_PRIVATE_NAME (tname, buf, loopfn_num++);
1233 clean_symbol_name (tname); 1403 clean_symbol_name (tname);
1234 name = get_identifier (tname); 1404 name = get_identifier (tname);
1235 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);
1236 1406
1237 decl = build_decl (BUILTINS_LOCATION, 1407 decl = build_decl (loc, FUNCTION_DECL, name, type);
1238 FUNCTION_DECL, name, type);
1239 if (!parallelized_functions) 1408 if (!parallelized_functions)
1240 parallelized_functions = BITMAP_GGC_ALLOC (); 1409 parallelized_functions = BITMAP_GGC_ALLOC ();
1241 bitmap_set_bit (parallelized_functions, DECL_UID (decl)); 1410 bitmap_set_bit (parallelized_functions, DECL_UID (decl));
1242 1411
1243 TREE_STATIC (decl) = 1; 1412 TREE_STATIC (decl) = 1;
1248 DECL_UNINLINABLE (decl) = 1; 1417 DECL_UNINLINABLE (decl) = 1;
1249 DECL_EXTERNAL (decl) = 0; 1418 DECL_EXTERNAL (decl) = 0;
1250 DECL_CONTEXT (decl) = NULL_TREE; 1419 DECL_CONTEXT (decl) = NULL_TREE;
1251 DECL_INITIAL (decl) = make_node (BLOCK); 1420 DECL_INITIAL (decl) = make_node (BLOCK);
1252 1421
1253 t = build_decl (BUILTINS_LOCATION, 1422 t = build_decl (loc, RESULT_DECL, NULL_TREE, void_type_node);
1254 RESULT_DECL, NULL_TREE, void_type_node);
1255 DECL_ARTIFICIAL (t) = 1; 1423 DECL_ARTIFICIAL (t) = 1;
1256 DECL_IGNORED_P (t) = 1; 1424 DECL_IGNORED_P (t) = 1;
1257 DECL_RESULT (decl) = t; 1425 DECL_RESULT (decl) = t;
1258 1426
1259 t = build_decl (BUILTINS_LOCATION, 1427 t = build_decl (loc, PARM_DECL, get_identifier (".paral_data_param"),
1260 PARM_DECL, get_identifier (".paral_data_param"),
1261 ptr_type_node); 1428 ptr_type_node);
1262 DECL_ARTIFICIAL (t) = 1; 1429 DECL_ARTIFICIAL (t) = 1;
1263 DECL_ARG_TYPE (t) = ptr_type_node; 1430 DECL_ARG_TYPE (t) = ptr_type_node;
1264 DECL_CONTEXT (t) = decl; 1431 DECL_CONTEXT (t) = decl;
1265 TREE_USED (t) = 1; 1432 TREE_USED (t) = 1;
1327 } 1494 }
1328 bbs = get_loop_body_in_dom_order (loop); 1495 bbs = get_loop_body_in_dom_order (loop);
1329 1496
1330 for (n = 0; bbs[n] != loop->latch; n++) 1497 for (n = 0; bbs[n] != loop->latch; n++)
1331 continue; 1498 continue;
1332 n--;
1333 nbbs = XNEWVEC (basic_block, n); 1499 nbbs = XNEWVEC (basic_block, n);
1334 ok = gimple_duplicate_sese_tail (single_succ_edge (loop->header), exit, 1500 ok = gimple_duplicate_sese_tail (single_succ_edge (loop->header), exit,
1335 bbs + 1, n, nbbs); 1501 bbs + 1, n, nbbs);
1336 gcc_assert (ok); 1502 gcc_assert (ok);
1337 free (bbs); 1503 free (bbs);
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
1625 prob, prob, REG_BR_PROB_BASE - prob, true); 1800 prob, prob, REG_BR_PROB_BASE - prob, true);
1626 update_ssa (TODO_update_ssa); 1801 update_ssa (TODO_update_ssa);
1627 free_original_copy_tables (); 1802 free_original_copy_tables ();
1628 1803
1629 /* Base all the induction variables in LOOP on a single control one. */ 1804 /* Base all the induction variables in LOOP on a single control one. */
1630 canonicalize_loop_ivs (loop, &nit); 1805 canonicalize_loop_ivs (loop, &nit, true);
1631 1806
1632 /* Ensure that the exit condition is the first statement in the loop. */ 1807 /* Ensure that the exit condition is the first statement in the loop. */
1633 transform_to_exit_first_loop (loop, reduction_list, nit); 1808 transform_to_exit_first_loop (loop, reduction_list, nit);
1634 1809
1635 /* Generate initializations for reductions. */ 1810 /* Generate initializations for reductions. */
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
1743 continue; 1933 continue;
1744 1934
1745 if (!simple_iv (loop, loop, res, &iv, true) 1935 if (!simple_iv (loop, loop, res, &iv, true)
1746 && simple_loop_info) 1936 && simple_loop_info)
1747 { 1937 {
1748 gimple reduc_stmt = vect_is_simple_reduction (simple_loop_info, phi, true, &double_reduc); 1938 gimple reduc_stmt = vect_force_simple_reduction (simple_loop_info,
1939 phi, true,
1940 &double_reduc);
1749 if (reduc_stmt && !double_reduc) 1941 if (reduc_stmt && !double_reduc)
1750 build_new_reduction (reduction_list, reduc_stmt, phi); 1942 build_new_reduction (reduction_list, reduc_stmt, phi);
1751 } 1943 }
1752 } 1944 }
1753 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);
1754 } 1951 }
1755 1952
1756 /* Try to initialize NITER for code generation part. */ 1953 /* Try to initialize NITER for code generation part. */
1757 1954
1758 static bool 1955 static bool
1818 return false; 2015 return false;
1819 } 2016 }
1820 reduc_phi = NULL; 2017 reduc_phi = NULL;
1821 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, val) 2018 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, val)
1822 { 2019 {
1823 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))))
1824 { 2022 {
1825 reduc_phi = USE_STMT (use_p); 2023 reduc_phi = USE_STMT (use_p);
1826 break; 2024 break;
1827 } 2025 }
1828 } 2026 }
1882 bool changed = false; 2080 bool changed = false;
1883 struct loop *loop; 2081 struct loop *loop;
1884 struct tree_niter_desc niter_desc; 2082 struct tree_niter_desc niter_desc;
1885 loop_iterator li; 2083 loop_iterator li;
1886 htab_t reduction_list; 2084 htab_t reduction_list;
2085 struct obstack parloop_obstack;
2086 HOST_WIDE_INT estimated;
2087 LOC loop_loc;
1887 2088
1888 /* Do not parallelize loops in the functions created by parallelization. */ 2089 /* Do not parallelize loops in the functions created by parallelization. */
1889 if (parallelized_function_p (cfun->decl)) 2090 if (parallelized_function_p (cfun->decl))
1890 return false; 2091 return false;
1891 2092 if (cfun->has_nonlocal_label)
2093 return false;
2094
2095 gcc_obstack_init (&parloop_obstack);
1892 reduction_list = htab_create (10, reduction_info_hash, 2096 reduction_list = htab_create (10, reduction_info_hash,
1893 reduction_info_eq, free); 2097 reduction_info_eq, free);
1894 init_stmt_vec_info_vec (); 2098 init_stmt_vec_info_vec ();
1895 2099
1896 FOR_EACH_LOOP (li, loop, 0) 2100 FOR_EACH_LOOP (li, loop, 0)
1924 } 2128 }
1925 2129
1926 if (/* And of course, the loop must be parallelizable. */ 2130 if (/* And of course, the loop must be parallelizable. */
1927 !can_duplicate_loop_p (loop) 2131 !can_duplicate_loop_p (loop)
1928 || loop_has_blocks_with_irreducible_flag (loop) 2132 || loop_has_blocks_with_irreducible_flag (loop)
2133 || (loop_preheader_edge (loop)->src->flags & BB_IRREDUCIBLE_LOOP)
1929 /* FIXME: the check for vector phi nodes could be removed. */ 2134 /* FIXME: the check for vector phi nodes could be removed. */
1930 || loop_has_vector_phi_nodes (loop)) 2135 || loop_has_vector_phi_nodes (loop))
1931 continue; 2136 continue;
1932 2137 estimated = estimated_loop_iterations_int (loop, false);
1933 /* FIXME: Bypass this check as graphite doesn't update the 2138 /* FIXME: Bypass this check as graphite doesn't update the
1934 count and frequency correctly now. */ 2139 count and frequency correctly now. */
1935 if (!flag_loop_parallelize_all 2140 if (!flag_loop_parallelize_all
1936 && ((estimated_loop_iterations_int (loop, false) 2141 && ((estimated !=-1
1937 <= (HOST_WIDE_INT) n_threads * MIN_PER_THREAD) 2142 && estimated <= (HOST_WIDE_INT) n_threads * MIN_PER_THREAD)
1938 /* Do not bother with loops in cold areas. */ 2143 /* Do not bother with loops in cold areas. */
1939 || optimize_loop_nest_for_size_p (loop))) 2144 || optimize_loop_nest_for_size_p (loop)))
1940 continue; 2145 continue;
1941 2146
1942 if (!try_get_loop_niter (loop, &niter_desc)) 2147 if (!try_get_loop_niter (loop, &niter_desc))
1943 continue; 2148 continue;
1944 2149
1945 if (!try_create_reduction_list (loop, reduction_list)) 2150 if (!try_create_reduction_list (loop, reduction_list))
1946 continue; 2151 continue;
1947 2152
1948 if (!flag_loop_parallelize_all && !loop_parallel_p (loop)) 2153 if (!flag_loop_parallelize_all
2154 && !loop_parallel_p (loop, &parloop_obstack))
1949 continue; 2155 continue;
1950 2156
1951 changed = true; 2157 changed = true;
1952 if (dump_file && (dump_flags & TDF_DETAILS)) 2158 if (dump_file && (dump_flags & TDF_DETAILS))
1953 { 2159 {
1954 fprintf (dump_file, "parallelizing ");
1955 if (loop->inner) 2160 if (loop->inner)
1956 fprintf (dump_file, "outer loop\n"); 2161 fprintf (dump_file, "parallelizing outer loop %d\n",loop->header->index);
1957 else 2162 else
1958 fprintf (dump_file, "inner loop\n"); 2163 fprintf (dump_file, "parallelizing inner loop %d\n",loop->header->index);
2164 loop_loc = find_loop_location (loop);
2165 if (loop_loc != UNKNOWN_LOC)
2166 fprintf (dump_file, "\nloop at %s:%d: ",
2167 LOC_FILE (loop_loc), LOC_LINE (loop_loc));
1959 } 2168 }
1960 gen_parallel_loop (loop, reduction_list, 2169 gen_parallel_loop (loop, reduction_list,
1961 n_threads, &niter_desc); 2170 n_threads, &niter_desc);
1962 verify_flow_info (); 2171 verify_flow_info ();
1963 verify_dominators (CDI_DOMINATORS); 2172 verify_dominators (CDI_DOMINATORS);
1964 verify_loop_structure (); 2173 verify_loop_structure ();
1965 verify_loop_closed_ssa (); 2174 verify_loop_closed_ssa (true);
1966 } 2175 }
1967 2176
1968 free_stmt_vec_info_vec (); 2177 free_stmt_vec_info_vec ();
1969 htab_delete (reduction_list); 2178 htab_delete (reduction_list);
2179 obstack_free (&parloop_obstack, NULL);
1970 2180
1971 /* Parallelization will cause new function calls to be inserted through 2181 /* Parallelization will cause new function calls to be inserted through
1972 which local variables will escape. Reset the points-to solutions 2182 which local variables will escape. Reset the points-to solution
1973 for ESCAPED and CALLUSED. */ 2183 for ESCAPED. */
1974 if (changed) 2184 if (changed)
1975 { 2185 pt_solution_reset (&cfun->gimple_df->escaped);
1976 pt_solution_reset (&cfun->gimple_df->escaped);
1977 pt_solution_reset (&cfun->gimple_df->callused);
1978 }
1979 2186
1980 return changed; 2187 return changed;
1981 } 2188 }
1982 2189
1983 #include "gt-tree-parloops.h" 2190 #include "gt-tree-parloops.h"