comparison gcc/graphite-scop-detection.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Detection of Static Control Parts (SCoP) for Graphite. 1 /* Detection of Static Control Parts (SCoP) for Graphite.
2 Copyright (C) 2009-2017 Free Software Foundation, Inc. 2 Copyright (C) 2009-2018 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <sebastian.pop@amd.com> and 3 Contributed by Sebastian Pop <sebastian.pop@amd.com> and
4 Tobias Grosser <grosser@fim.uni-passau.de>. 4 Tobias Grosser <grosser@fim.uni-passau.de>.
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
79 } dp; 79 } dp;
80 80
81 #define DEBUG_PRINT(args) do \ 81 #define DEBUG_PRINT(args) do \
82 { \ 82 { \
83 if (dump_file && (dump_flags & TDF_DETAILS)) { args; } \ 83 if (dump_file && (dump_flags & TDF_DETAILS)) { args; } \
84 } while (0); 84 } while (0)
85 85
86 /* Pretty print to FILE all the SCoPs in DOT format and mark them with 86 /* Pretty print to FILE all the SCoPs in DOT format and mark them with
87 different colors. If there are not enough colors, paint the 87 different colors. If there are not enough colors, paint the
88 remaining SCoPs in gray. 88 remaining SCoPs in gray.
89 89
307 307
308 /* Return an sese_l around the LOOP. */ 308 /* Return an sese_l around the LOOP. */
309 309
310 sese_l get_sese (loop_p loop); 310 sese_l get_sese (loop_p loop);
311 311
312 /* Return the closest dominator with a single entry edge. In case of a
313 back-loop the back-edge is not counted. */
314
315 static edge get_nearest_dom_with_single_entry (basic_block dom);
316
317 /* Return the closest post-dominator with a single exit edge. In case of a
318 back-loop the back-edge is not counted. */
319
320 static edge get_nearest_pdom_with_single_exit (basic_block dom);
321
322 /* Merge scops at same loop depth and returns the new sese. 312 /* Merge scops at same loop depth and returns the new sese.
323 Returns a new SESE when merge was successful, INVALID_SESE otherwise. */ 313 Returns a new SESE when merge was successful, INVALID_SESE otherwise. */
324 314
325 sese_l merge_sese (sese_l first, sese_l second) const; 315 sese_l merge_sese (sese_l first, sese_l second) const;
326 316
426 if (!loop) 416 if (!loop)
427 return invalid_sese; 417 return invalid_sese;
428 418
429 edge scop_begin = loop_preheader_edge (loop); 419 edge scop_begin = loop_preheader_edge (loop);
430 edge scop_end = single_exit (loop); 420 edge scop_end = single_exit (loop);
431 if (!scop_end || (scop_end->flags & EDGE_COMPLEX)) 421 if (!scop_end || (scop_end->flags & (EDGE_COMPLEX|EDGE_FAKE)))
432 return invalid_sese; 422 return invalid_sese;
433 /* Include the BB with the loop-closed SSA PHI nodes.
434 canonicalize_loop_closed_ssa makes sure that is in proper shape. */
435 if (! single_pred_p (scop_end->dest)
436 || ! single_succ_p (scop_end->dest)
437 || ! sese_trivially_empty_bb_p (scop_end->dest))
438 gcc_unreachable ();
439 scop_end = single_succ_edge (scop_end->dest);
440 423
441 return sese_l (scop_begin, scop_end); 424 return sese_l (scop_begin, scop_end);
442 }
443
444 /* Return the closest dominator with a single entry edge. */
445
446 edge
447 scop_detection::get_nearest_dom_with_single_entry (basic_block dom)
448 {
449 if (!dom->preds)
450 return NULL;
451
452 /* If any of the dominators has two predecessors but one of them is a back
453 edge, then that basic block also qualifies as a dominator with single
454 entry. */
455 if (dom->preds->length () == 2)
456 {
457 /* If e1->src dominates e2->src then e1->src will also dominate dom. */
458 edge e1 = (*dom->preds)[0];
459 edge e2 = (*dom->preds)[1];
460 loop_p l = dom->loop_father;
461 loop_p l1 = e1->src->loop_father;
462 loop_p l2 = e2->src->loop_father;
463 if (l != l1 && l == l2
464 && dominated_by_p (CDI_DOMINATORS, e2->src, e1->src))
465 return e1;
466 if (l != l2 && l == l1
467 && dominated_by_p (CDI_DOMINATORS, e1->src, e2->src))
468 return e2;
469 }
470
471 while (dom->preds->length () != 1)
472 {
473 if (dom->preds->length () < 1)
474 return NULL;
475 dom = get_immediate_dominator (CDI_DOMINATORS, dom);
476 if (!dom->preds)
477 return NULL;
478 }
479 return (*dom->preds)[0];
480 }
481
482 /* Return the closest post-dominator with a single exit edge. In case of a
483 back-loop the back-edge is not counted. */
484
485 edge
486 scop_detection::get_nearest_pdom_with_single_exit (basic_block pdom)
487 {
488 if (!pdom->succs)
489 return NULL;
490
491 /* If any of the post-dominators has two successors but one of them is a back
492 edge, then that basic block also qualifies as a post-dominator with single
493 exit. */
494 if (pdom->succs->length () == 2)
495 {
496 /* If e1->dest post-dominates e2->dest then e1->dest will also
497 post-dominate pdom. */
498 edge e1 = (*pdom->succs)[0];
499 edge e2 = (*pdom->succs)[1];
500 loop_p l = pdom->loop_father;
501 loop_p l1 = e1->dest->loop_father;
502 loop_p l2 = e2->dest->loop_father;
503 if (l != l1 && l == l2
504 && dominated_by_p (CDI_POST_DOMINATORS, e2->dest, e1->dest))
505 return e1;
506 if (l != l2 && l == l1
507 && dominated_by_p (CDI_POST_DOMINATORS, e1->dest, e2->dest))
508 return e2;
509 }
510
511 while (pdom->succs->length () != 1)
512 {
513 if (pdom->succs->length () < 1)
514 return NULL;
515 pdom = get_immediate_dominator (CDI_POST_DOMINATORS, pdom);
516 if (!pdom->succs)
517 return NULL;
518 }
519
520 return (*pdom->succs)[0];
521 } 425 }
522 426
523 /* Merge scops at same loop depth and returns the new sese. 427 /* Merge scops at same loop depth and returns the new sese.
524 Returns a new SESE when merge was successful, INVALID_SESE otherwise. */ 428 Returns a new SESE when merge was successful, INVALID_SESE otherwise. */
525 429
535 DEBUG_PRINT (dp << "[scop-detection] try merging sese s1: "; 439 DEBUG_PRINT (dp << "[scop-detection] try merging sese s1: ";
536 print_sese (dump_file, first); 440 print_sese (dump_file, first);
537 dp << "[scop-detection] try merging sese s2: "; 441 dp << "[scop-detection] try merging sese s2: ";
538 print_sese (dump_file, second)); 442 print_sese (dump_file, second));
539 443
540 /* Assumption: Both the sese's should be at the same loop depth or one scop 444 auto_bitmap worklist, in_sese_region;
541 should subsume the other like in case of nested loops. */ 445 bitmap_set_bit (worklist, get_entry_bb (first)->index);
542 446 bitmap_set_bit (worklist, get_exit_bb (first)->index);
543 /* Find the common dominators for entry, 447 bitmap_set_bit (worklist, get_entry_bb (second)->index);
544 and common post-dominators for the exit. */ 448 bitmap_set_bit (worklist, get_exit_bb (second)->index);
545 basic_block dom = nearest_common_dominator (CDI_DOMINATORS, 449 edge entry = NULL, exit = NULL;
546 get_entry_bb (first), 450
547 get_entry_bb (second)); 451 /* We can optimize the case of adding a loop entry dest or exit
548 452 src to the worklist (for single-exit loops) by skipping
549 edge entry = get_nearest_dom_with_single_entry (dom); 453 directly to the exit dest / entry src. in_sese_region
550 454 doesn't have to cover all blocks in the region but merely
551 if (!entry || (entry->flags & EDGE_IRREDUCIBLE_LOOP)) 455 its border it acts more like a visited bitmap. */
552 return invalid_sese; 456 do
553 457 {
554 basic_block pdom = nearest_common_dominator (CDI_POST_DOMINATORS, 458 int index = bitmap_first_set_bit (worklist);
555 get_exit_bb (first), 459 bitmap_clear_bit (worklist, index);
556 get_exit_bb (second)); 460 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, index);
557 pdom = nearest_common_dominator (CDI_POST_DOMINATORS, dom, pdom); 461 edge_iterator ei;
558 462 edge e;
559 edge exit = get_nearest_pdom_with_single_exit (pdom); 463
560 464 /* With fake exit edges we can end up with no possible exit. */
561 if (!exit || (exit->flags & EDGE_IRREDUCIBLE_LOOP)) 465 if (index == EXIT_BLOCK)
562 return invalid_sese; 466 {
467 DEBUG_PRINT (dp << "[scop-detection-fail] cannot merge seses.\n");
468 return invalid_sese;
469 }
470
471 bitmap_set_bit (in_sese_region, bb->index);
472
473 basic_block dom = get_immediate_dominator (CDI_DOMINATORS, bb);
474 FOR_EACH_EDGE (e, ei, bb->preds)
475 if (e->src == dom
476 && (! entry
477 || dominated_by_p (CDI_DOMINATORS, entry->dest, bb)))
478 {
479 if (entry
480 && ! bitmap_bit_p (in_sese_region, entry->src->index))
481 bitmap_set_bit (worklist, entry->src->index);
482 entry = e;
483 }
484 else if (! bitmap_bit_p (in_sese_region, e->src->index))
485 bitmap_set_bit (worklist, e->src->index);
486
487 basic_block pdom = get_immediate_dominator (CDI_POST_DOMINATORS, bb);
488 FOR_EACH_EDGE (e, ei, bb->succs)
489 if (e->dest == pdom
490 && (! exit
491 || dominated_by_p (CDI_POST_DOMINATORS, exit->src, bb)))
492 {
493 if (exit
494 && ! bitmap_bit_p (in_sese_region, exit->dest->index))
495 bitmap_set_bit (worklist, exit->dest->index);
496 exit = e;
497 }
498 else if (! bitmap_bit_p (in_sese_region, e->dest->index))
499 bitmap_set_bit (worklist, e->dest->index);
500 }
501 while (! bitmap_empty_p (worklist));
563 502
564 sese_l combined (entry, exit); 503 sese_l combined (entry, exit);
565
566 DEBUG_PRINT (dp << "[scop-detection] checking combined sese: ";
567 print_sese (dump_file, combined));
568
569 /* FIXME: We could iterate to find the dom which dominates pdom, and pdom
570 which post-dominates dom, until it stabilizes. Also, ENTRY->SRC and
571 EXIT->DEST should be in the same loop nest. */
572 if (!dominated_by_p (CDI_DOMINATORS, pdom, dom)
573 || loop_depth (entry->src->loop_father)
574 != loop_depth (exit->dest->loop_father))
575 return invalid_sese;
576
577 /* For now we just bail out when there is a loop exit in the region
578 that is not also the exit of the region. We could enlarge the
579 region to cover the loop that region exits to. See PR79977. */
580 if (loop_outer (entry->src->loop_father))
581 {
582 vec<edge> exits = get_loop_exit_edges (entry->src->loop_father);
583 for (unsigned i = 0; i < exits.length (); ++i)
584 {
585 if (exits[i] != exit
586 && bb_in_region (exits[i]->src, entry->dest, exit->src))
587 {
588 DEBUG_PRINT (dp << "[scop-detection-fail] cannot merge seses.\n");
589 exits.release ();
590 return invalid_sese;
591 }
592 }
593 exits.release ();
594 }
595
596 /* For now we just want to bail out when exit does not post-dominate entry.
597 TODO: We might just add a basic_block at the exit to make exit
598 post-dominate entry (the entire region). */
599 if (!dominated_by_p (CDI_POST_DOMINATORS, get_entry_bb (combined),
600 get_exit_bb (combined))
601 || !dominated_by_p (CDI_DOMINATORS, get_exit_bb (combined),
602 get_entry_bb (combined)))
603 {
604 DEBUG_PRINT (dp << "[scop-detection-fail] cannot merge seses.\n");
605 return invalid_sese;
606 }
607 504
608 DEBUG_PRINT (dp << "[merged-sese] s1: "; print_sese (dump_file, combined)); 505 DEBUG_PRINT (dp << "[merged-sese] s1: "; print_sese (dump_file, combined));
609 506
610 return combined; 507 return combined;
611 } 508 }
691 void 588 void
692 scop_detection::add_scop (sese_l s) 589 scop_detection::add_scop (sese_l s)
693 { 590 {
694 gcc_assert (s); 591 gcc_assert (s);
695 592
593 /* If the exit edge is fake discard the SCoP for now as we're removing the
594 fake edges again after analysis. */
595 if (s.exit->flags & EDGE_FAKE)
596 {
597 DEBUG_PRINT (dp << "[scop-detection-fail] Discarding infinite loop SCoP: ";
598 print_sese (dump_file, s));
599 return;
600 }
601
602 /* Include the BB with the loop-closed SSA PHI nodes, we need this
603 block in the region for code-generating out-of-SSA copies.
604 canonicalize_loop_closed_ssa makes sure that is in proper shape. */
605 if (s.exit->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)
606 && loop_exit_edge_p (s.exit->src->loop_father, s.exit))
607 {
608 gcc_assert (single_pred_p (s.exit->dest)
609 && single_succ_p (s.exit->dest)
610 && sese_trivially_empty_bb_p (s.exit->dest));
611 s.exit = single_succ_edge (s.exit->dest);
612 }
613
696 /* Do not add scops with only one loop. */ 614 /* Do not add scops with only one loop. */
697 if (region_has_one_loop (s)) 615 if (region_has_one_loop (s))
698 { 616 {
699 DEBUG_PRINT (dp << "[scop-detection-fail] Discarding one loop SCoP: "; 617 DEBUG_PRINT (dp << "[scop-detection-fail] Discarding one loop SCoP: ";
700 print_sese (dump_file, s)); 618 print_sese (dump_file, s));
766 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); 684 for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
767 !gsi_end_p (gsi); gsi_next (&gsi)) 685 !gsi_end_p (gsi); gsi_next (&gsi))
768 if (!stmt_simple_for_scop_p (scop, gsi_stmt (gsi), bb)) 686 if (!stmt_simple_for_scop_p (scop, gsi_stmt (gsi), bb))
769 return true; 687 return true;
770 688
771 if (bb != exit_bb) 689 for (basic_block dom = first_dom_son (CDI_DOMINATORS, bb);
772 for (basic_block dom = first_dom_son (CDI_DOMINATORS, bb); 690 dom;
773 dom; 691 dom = next_dom_son (CDI_DOMINATORS, dom))
774 dom = next_dom_son (CDI_DOMINATORS, dom)) 692 if (dom != scop.exit->dest)
775 worklist.safe_push (dom); 693 worklist.safe_push (dom);
776 } 694 }
777 695
778 /* Go through all loops and check that they are still valid in the combined 696 /* Go through all loops and check that they are still valid in the combined
779 scop. */ 697 scop. */
1003 We try to analyze the data references in a loop contained in the SCOP. */ 921 We try to analyze the data references in a loop contained in the SCOP. */
1004 922
1005 bool 923 bool
1006 scop_detection::stmt_has_simple_data_refs_p (sese_l scop, gimple *stmt) 924 scop_detection::stmt_has_simple_data_refs_p (sese_l scop, gimple *stmt)
1007 { 925 {
1008 edge nest = scop.entry;; 926 edge nest = scop.entry;
1009 loop_p loop = loop_containing_stmt (stmt); 927 loop_p loop = loop_containing_stmt (stmt);
1010 if (!loop_in_sese_p (loop, scop)) 928 if (!loop_in_sese_p (loop, scop))
1011 loop = NULL; 929 loop = NULL;
1012 930
1013 auto_vec<data_reference_p> drs; 931 auto_vec<data_reference_p> drs;
1116 return true; 1034 return true;
1117 } 1035 }
1118 1036
1119 case GIMPLE_ASSIGN: 1037 case GIMPLE_ASSIGN:
1120 case GIMPLE_CALL: 1038 case GIMPLE_CALL:
1121 return true; 1039 {
1040 tree op, lhs = gimple_get_lhs (stmt);
1041 ssa_op_iter i;
1042 /* If we are not going to instantiate the stmt do not require
1043 its operands to be instantiatable at this point. */
1044 if (lhs
1045 && TREE_CODE (lhs) == SSA_NAME
1046 && scev_analyzable_p (lhs, scop))
1047 return true;
1048 /* Verify that if we can analyze operands at their def site we
1049 also can represent them when analyzed at their uses. */
1050 FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_USE)
1051 if (scev_analyzable_p (op, scop)
1052 && chrec_contains_undetermined
1053 (scalar_evolution_in_region (scop, bb->loop_father, op)))
1054 {
1055 DEBUG_PRINT (dp << "[scop-detection-fail] "
1056 << "Graphite cannot code-gen stmt:\n";
1057 print_gimple_stmt (dump_file, stmt, 0,
1058 TDF_VOPS | TDF_MEMSYMS));
1059 return false;
1060 }
1061 return true;
1062 }
1122 1063
1123 default: 1064 default:
1124 /* These nodes cut a new scope. */ 1065 /* These nodes cut a new scope. */
1125 DEBUG_PRINT ( 1066 DEBUG_PRINT (
1126 dp << "[scop-detection-fail] " 1067 dp << "[scop-detection-fail] "
1233 for (unsigned j = 0; j < DR_NUM_DIMENSIONS (dr); j++) 1174 for (unsigned j = 0; j < DR_NUM_DIMENSIONS (dr); j++)
1234 scan_tree_for_params (region, DR_ACCESS_FN (dr, j)); 1175 scan_tree_for_params (region, DR_ACCESS_FN (dr, j));
1235 1176
1236 /* Find parameters in conditional statements. */ 1177 /* Find parameters in conditional statements. */
1237 gimple *stmt; 1178 gimple *stmt;
1238 loop_p loop = GBB_BB (gbb)->loop_father;
1239 FOR_EACH_VEC_ELT (GBB_CONDITIONS (gbb), i, stmt) 1179 FOR_EACH_VEC_ELT (GBB_CONDITIONS (gbb), i, stmt)
1240 { 1180 {
1181 loop_p loop = gimple_bb (stmt)->loop_father;
1241 tree lhs = scalar_evolution_in_region (region->region, loop, 1182 tree lhs = scalar_evolution_in_region (region->region, loop,
1242 gimple_cond_lhs (stmt)); 1183 gimple_cond_lhs (stmt));
1243 tree rhs = scalar_evolution_in_region (region->region, loop, 1184 tree rhs = scalar_evolution_in_region (region->region, loop,
1244 gimple_cond_rhs (stmt)); 1185 gimple_cond_rhs (stmt));
1186 gcc_assert (!chrec_contains_undetermined (lhs)
1187 && !chrec_contains_undetermined (rhs));
1245 1188
1246 scan_tree_for_params (region, lhs); 1189 scan_tree_for_params (region, lhs);
1247 scan_tree_for_params (region, rhs); 1190 scan_tree_for_params (region, rhs);
1248 } 1191 }
1249 } 1192 }
1513 auto_vec<gimple *, 3> conditions, cases; 1456 auto_vec<gimple *, 3> conditions, cases;
1514 scop_p scop; 1457 scop_p scop;
1515 }; 1458 };
1516 } 1459 }
1517 gather_bbs::gather_bbs (cdi_direction direction, scop_p scop, int *bb_to_rpo) 1460 gather_bbs::gather_bbs (cdi_direction direction, scop_p scop, int *bb_to_rpo)
1518 : dom_walker (direction, false, bb_to_rpo), scop (scop) 1461 : dom_walker (direction, ALL_BLOCKS, bb_to_rpo), scop (scop)
1519 { 1462 {
1520 } 1463 }
1521 1464
1522 /* Call-back for dom_walk executed before visiting the dominated 1465 /* Call-back for dom_walk executed before visiting the dominated
1523 blocks. */ 1466 blocks. */
1542 loop, nb_iters); 1485 loop, nb_iters);
1543 scan_tree_for_params (region, nb_iters); 1486 scan_tree_for_params (region, nb_iters);
1544 } 1487 }
1545 } 1488 }
1546 1489
1547 gcond *stmt = single_pred_cond_non_loop_exit (bb); 1490 if (gcond *stmt = single_pred_cond_non_loop_exit (bb))
1548
1549 if (stmt)
1550 { 1491 {
1551 edge e = single_pred_edge (bb); 1492 edge e = single_pred_edge (bb);
1552 1493 /* Make sure the condition is in the region and thus was verified
1553 conditions.safe_push (stmt); 1494 to be handled. */
1554 1495 if (e != region->region.entry)
1555 if (e->flags & EDGE_TRUE_VALUE) 1496 {
1556 cases.safe_push (stmt); 1497 conditions.safe_push (stmt);
1557 else 1498 if (e->flags & EDGE_TRUE_VALUE)
1558 cases.safe_push (NULL); 1499 cases.safe_push (stmt);
1500 else
1501 cases.safe_push (NULL);
1502 }
1559 } 1503 }
1560 1504
1561 scop->scop_info->bbs.safe_push (bb); 1505 scop->scop_info->bbs.safe_push (bb);
1562 1506
1563 gimple_poly_bb_p gbb = try_generate_gimple_bb (scop, bb); 1507 gimple_poly_bb_p gbb = try_generate_gimple_bb (scop, bb);
1598 if (!bb_in_sese_p (bb, scop->scop_info->region)) 1542 if (!bb_in_sese_p (bb, scop->scop_info->region))
1599 return; 1543 return;
1600 1544
1601 if (single_pred_cond_non_loop_exit (bb)) 1545 if (single_pred_cond_non_loop_exit (bb))
1602 { 1546 {
1603 conditions.pop (); 1547 edge e = single_pred_edge (bb);
1604 cases.pop (); 1548 if (e != scop->scop_info->region.entry)
1549 {
1550 conditions.pop ();
1551 cases.pop ();
1552 }
1605 } 1553 }
1606 } 1554 }
1607 1555
1608 1556
1609 /* Compute sth like an execution order, dominator order with first executing 1557 /* Compute sth like an execution order, dominator order with first executing
1610 edges that stay inside the current loop, delaying processing exit edges. */ 1558 edges that stay inside the current loop, delaying processing exit edges. */
1611 1559
1612 static vec<unsigned> order; 1560 static int *bb_to_rpo;
1613
1614 static void
1615 get_order (scop_p scop, basic_block bb, vec<unsigned> *order, unsigned *dfs_num)
1616 {
1617 if (! bb_in_sese_p (bb, scop->scop_info->region))
1618 return;
1619
1620 (*order)[bb->index] = (*dfs_num)++;
1621 for (basic_block son = first_dom_son (CDI_DOMINATORS, bb);
1622 son;
1623 son = next_dom_son (CDI_DOMINATORS, son))
1624 if (flow_bb_inside_loop_p (bb->loop_father, son))
1625 get_order (scop, son, order, dfs_num);
1626 for (basic_block son = first_dom_son (CDI_DOMINATORS, bb);
1627 son;
1628 son = next_dom_son (CDI_DOMINATORS, son))
1629 if (! flow_bb_inside_loop_p (bb->loop_father, son))
1630 get_order (scop, son, order, dfs_num);
1631 }
1632 1561
1633 /* Helper for qsort, sorting after order above. */ 1562 /* Helper for qsort, sorting after order above. */
1634 1563
1635 static int 1564 static int
1636 cmp_pbbs (const void *pa, const void *pb) 1565 cmp_pbbs (const void *pa, const void *pb)
1637 { 1566 {
1638 poly_bb_p bb1 = *((const poly_bb_p *)pa); 1567 poly_bb_p bb1 = *((const poly_bb_p *)pa);
1639 poly_bb_p bb2 = *((const poly_bb_p *)pb); 1568 poly_bb_p bb2 = *((const poly_bb_p *)pb);
1640 if (order[bb1->black_box->bb->index] < order[bb2->black_box->bb->index]) 1569 if (bb_to_rpo[bb1->black_box->bb->index]
1570 < bb_to_rpo[bb2->black_box->bb->index])
1641 return -1; 1571 return -1;
1642 else if (order[bb1->black_box->bb->index] > order[bb2->black_box->bb->index]) 1572 else if (bb_to_rpo[bb1->black_box->bb->index]
1573 > bb_to_rpo[bb2->black_box->bb->index])
1643 return 1; 1574 return 1;
1644 else 1575 else
1645 return 0; 1576 return 0;
1646 } 1577 }
1647 1578
1661 vec<sese_l> scops_l = sb.get_scops (); 1592 vec<sese_l> scops_l = sb.get_scops ();
1662 1593
1663 /* Domwalk needs a bb to RPO mapping. Compute it once here. */ 1594 /* Domwalk needs a bb to RPO mapping. Compute it once here. */
1664 int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun)); 1595 int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
1665 int postorder_num = pre_and_rev_post_order_compute (NULL, postorder, true); 1596 int postorder_num = pre_and_rev_post_order_compute (NULL, postorder, true);
1666 int *bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (cfun)); 1597 bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
1667 for (int i = 0; i < postorder_num; ++i) 1598 for (int i = 0; i < postorder_num; ++i)
1668 bb_to_rpo[postorder[i]] = i; 1599 bb_to_rpo[postorder[i]] = i;
1669 free (postorder); 1600 free (postorder);
1670 1601
1671 int i; 1602 int i;
1675 scop_p scop = new_scop (s->entry, s->exit); 1606 scop_p scop = new_scop (s->entry, s->exit);
1676 1607
1677 /* Record all basic blocks and their conditions in REGION. */ 1608 /* Record all basic blocks and their conditions in REGION. */
1678 gather_bbs (CDI_DOMINATORS, scop, bb_to_rpo).walk (s->entry->dest); 1609 gather_bbs (CDI_DOMINATORS, scop, bb_to_rpo).walk (s->entry->dest);
1679 1610
1680 /* domwalk does not fulfil our code-generations constraints on the 1611 /* Sort pbbs after execution order for initial schedule generation. */
1681 order of pbb which is to produce sth like execution order, delaying
1682 exection of loop exit edges. So compute such order and sort after
1683 that. */
1684 order.create (last_basic_block_for_fn (cfun));
1685 order.quick_grow (last_basic_block_for_fn (cfun));
1686 unsigned dfs_num = 0;
1687 get_order (scop, s->entry->dest, &order, &dfs_num);
1688 scop->pbbs.qsort (cmp_pbbs); 1612 scop->pbbs.qsort (cmp_pbbs);
1689 order.release ();
1690 1613
1691 if (! build_alias_set (scop)) 1614 if (! build_alias_set (scop))
1692 { 1615 {
1693 DEBUG_PRINT (dp << "[scop-detection-fail] cannot handle dependences\n"); 1616 DEBUG_PRINT (dp << "[scop-detection-fail] cannot handle dependences\n");
1694 free_scop (scop); 1617 free_scop (scop);
1731 1654
1732 scops->safe_push (scop); 1655 scops->safe_push (scop);
1733 } 1656 }
1734 1657
1735 free (bb_to_rpo); 1658 free (bb_to_rpo);
1659 bb_to_rpo = NULL;
1736 DEBUG_PRINT (dp << "number of SCoPs: " << (scops ? scops->length () : 0);); 1660 DEBUG_PRINT (dp << "number of SCoPs: " << (scops ? scops->length () : 0););
1737 } 1661 }
1738 1662
1739 #endif /* HAVE_isl */ 1663 #endif /* HAVE_isl */