This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[graphite] Graphite branch cleanups [4/4]
- From: Sebastian Pop <sebpop at gmail dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 21 Feb 2009 11:05:04 -0600
- Subject: [graphite] Graphite branch cleanups [4/4]
2009-02-20 Sebastian Pop <sebastian.pop@amd.com>
Tobias Grosser <grosser@fim.uni-passau.de>
* graphite-scop-detection.c (dot_all_scops_1,
dot_all_scops): Moved here.
* graphite-scop-detection.h (dot_all_scops): Declared here.
* graphite.c (graphite_initialize, graphite_finalize): New.
(graphite_transform_loops): Cleaned up.
* sese.c (debug_oldivs): Moved here.
* graphite-poly.c (graphite_apply_transformations): Renamed
apply_poly_transforms.
(debug_loop_vec): Moved here.
* graphite-sese-to-poly.c (build_bb_loops, build_sese_conditions_1,
scop_contains_non_iv_scalar_phi_nodes, build_sese_conditions,
find_scop_parameters, build_scop_iteration_domain,
add_conditions_to_constraints, build_scop_canonical_schedules,
build_scop_data_accesses): Now static.
(build_poly_scop, check_poly_representation): New.
2009-02-20 Sebastian Pop <sebastian.pop@amd.com>
Tobias Grosser <grosser@fim.uni-passau.de>
* graphite-scop-detection.c (dot_all_scops_1,
dot_all_scops): Moved here.
* graphite-scop-detection.h (dot_all_scops): Declared here.
* graphite.c (graphite_initialize, graphite_finalize): New.
(graphite_transform_loops): Cleaned up.
* sese.c (debug_oldivs): Moved here.
* graphite-poly.c (graphite_apply_transformations): Renamed
apply_poly_transforms.
(debug_loop_vec): Moved here.
* graphite-sese-to-poly.c (build_bb_loops, build_sese_conditions_1,
scop_contains_non_iv_scalar_phi_nodes, build_sese_conditions,
find_scop_parameters, build_scop_iteration_domain,
add_conditions_to_constraints, build_scop_canonical_schedules,
build_scop_data_accesses): Now static.
(build_poly_scop, check_poly_representation): New.
Index: graphite-scop-detection.c
===================================================================
--- graphite-scop-detection.c (revision 144315)
+++ graphite-scop-detection.c (working copy)
@@ -1038,6 +1038,169 @@ build_scops (VEC (scop_p, heap) **scops)
build_graphite_scops (regions, scops);
limit_scops (scops);
VEC_free (sd_region, heap, regions);
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "\nnumber of SCoPs: %d\n", VEC_length (scop_p, *scops));
+}
+
+/* Pretty print all SCoPs in DOT format and mark them with different colors.
+ If there are not enough colors, paint later SCoPs gray.
+ Special nodes:
+ - "*" after the node number: entry of a SCoP,
+ - "#" after the node number: exit of a SCoP,
+ - "()" entry or exit not part of SCoP. */
+
+static void
+dot_all_scops_1 (FILE *file, VEC (scop_p, heap) *scops)
+{
+ basic_block bb;
+ edge e;
+ edge_iterator ei;
+ scop_p scop;
+ const char* color;
+ int i;
+
+ /* Disable debugging while printing graph. */
+ int tmp_dump_flags = dump_flags;
+ dump_flags = 0;
+
+ fprintf (file, "digraph all {\n");
+
+ FOR_ALL_BB (bb)
+ {
+ int part_of_scop = false;
+
+ /* Use HTML for every bb label. So we are able to print bbs
+ which are part of two different SCoPs, with two different
+ background colors. */
+ fprintf (file, "%d [label=<\n <TABLE BORDER=\"0\" CELLBORDER=\"1\" ",
+ bb->index);
+ fprintf (file, "CELLSPACING=\"0\">\n");
+
+ /* Select color for SCoP. */
+ for (i = 0; VEC_iterate (scop_p, scops, i, scop); i++)
+ if (bb_in_sese_p (bb, SCOP_REGION (scop))
+ || (SCOP_EXIT (scop) == bb)
+ || (SCOP_ENTRY (scop) == bb))
+ {
+ switch (i % 17)
+ {
+ case 0: /* red */
+ color = "#e41a1c";
+ break;
+ case 1: /* blue */
+ color = "#377eb8";
+ break;
+ case 2: /* green */
+ color = "#4daf4a";
+ break;
+ case 3: /* purple */
+ color = "#984ea3";
+ break;
+ case 4: /* orange */
+ color = "#ff7f00";
+ break;
+ case 5: /* yellow */
+ color = "#ffff33";
+ break;
+ case 6: /* brown */
+ color = "#a65628";
+ break;
+ case 7: /* rose */
+ color = "#f781bf";
+ break;
+ case 8:
+ color = "#8dd3c7";
+ break;
+ case 9:
+ color = "#ffffb3";
+ break;
+ case 10:
+ color = "#bebada";
+ break;
+ case 11:
+ color = "#fb8072";
+ break;
+ case 12:
+ color = "#80b1d3";
+ break;
+ case 13:
+ color = "#fdb462";
+ break;
+ case 14:
+ color = "#b3de69";
+ break;
+ case 15:
+ color = "#fccde5";
+ break;
+ case 16:
+ color = "#bc80bd";
+ break;
+ default: /* gray */
+ color = "#999999";
+ }
+
+ fprintf (file, " <TR><TD WIDTH=\"50\" BGCOLOR=\"%s\">", color);
+
+ if (!bb_in_sese_p (bb, SCOP_REGION (scop)))
+ fprintf (file, " (");
+
+ if (bb == SCOP_ENTRY (scop)
+ && bb == SCOP_EXIT (scop))
+ fprintf (file, " %d*# ", bb->index);
+ else if (bb == SCOP_ENTRY (scop))
+ fprintf (file, " %d* ", bb->index);
+ else if (bb == SCOP_EXIT (scop))
+ fprintf (file, " %d# ", bb->index);
+ else
+ fprintf (file, " %d ", bb->index);
+
+ if (!bb_in_sese_p (bb, SCOP_REGION (scop)))
+ fprintf (file, ")");
+
+ fprintf (file, "</TD></TR>\n");
+ part_of_scop = true;
+ }
+
+ if (!part_of_scop)
+ {
+ fprintf (file, " <TR><TD WIDTH=\"50\" BGCOLOR=\"#ffffff\">");
+ fprintf (file, " %d </TD></TR>\n", bb->index);
+ }
+
+ fprintf (file, " </TABLE>>, shape=box, style=\"setlinewidth(0)\"]\n");
+ }
+
+ FOR_ALL_BB (bb)
+ {
+ FOR_EACH_EDGE (e, ei, bb->succs)
+ fprintf (file, "%d -> %d;\n", bb->index, e->dest->index);
+ }
+
+ fputs ("}\n\n", file);
+
+ /* Enable debugging again. */
+ dump_flags = tmp_dump_flags;
+}
+
+/* Display all SCoPs using dotty. */
+
+void
+dot_all_scops (VEC (scop_p, heap) *scops)
+{
+ /* When debugging, enable the following code. This cannot be used
+ in production compilers because it calls "system". */
+#if 1
+ FILE *stream = fopen ("/tmp/allscops.dot", "w");
+ gcc_assert (stream);
+
+ dot_all_scops_1 (stream, scops);
+ fclose (stream);
+
+ system ("dotty /tmp/allscops.dot");
+#else
+ dot_all_scops_1 (stderr, scops);
+#endif
}
#endif
Index: graphite-scop-detection.h
===================================================================
--- graphite-scop-detection.h (revision 144315)
+++ graphite-scop-detection.h (working copy)
@@ -20,5 +20,6 @@ along with GCC; see the file COPYING3.
<http://www.gnu.org/licenses/>. */
-void build_scops (VEC (scop_p, heap) **);
-void build_scop_bbs (scop_p);
+extern void build_scops (VEC (scop_p, heap) **);
+extern void build_scop_bbs (scop_p);
+extern void dot_all_scops (VEC (scop_p, heap) *);
Index: graphite.c
===================================================================
--- graphite.c (revision 144331)
+++ graphite.c (working copy)
@@ -67,199 +67,31 @@ along with GCC; see the file COPYING3.
#include "graphite-clast-to-gimple.h"
#include "graphite-sese-to-poly.h"
-/* Debug the list of old induction variables for this SCOP. */
+/* Initialize graphite: when there are no loops returns false. */
-void
-debug_oldivs (sese region)
+static bool
+graphite_initialize (void)
{
- int i;
- name_tree oldiv;
-
- fprintf (stderr, "Old IVs:");
-
- for (i = 0; VEC_iterate (name_tree, SESE_OLDIVS (region), i, oldiv); i++)
- {
- fprintf (stderr, "(");
- print_generic_expr (stderr, oldiv->t, 0);
- fprintf (stderr, ", %s, %d)\n", oldiv->name, oldiv->loop->num);
- }
- fprintf (stderr, "\n");
-}
-
-/* Debug the loops around basic block GB. */
-
-void
-debug_loop_vec (poly_bb_p pbb)
-{
- int i;
- loop_p loop;
-
- fprintf (stderr, "Loop Vec:");
+ if (number_of_loops () <= 1)
+ return false;
- for (i = 0; VEC_iterate (loop_p, PBB_LOOPS (pbb), i, loop); i++)
- fprintf (stderr, "%d: %d, ", i, loop ? loop->num : -1);
+ recompute_all_dominators ();
+ initialize_original_copy_tables ();
+ cloog_initialize ();
- fprintf (stderr, "\n");
+ return true;
}
-/* Pretty print all SCoPs in DOT format and mark them with different colors.
- If there are not enough colors, paint later SCoPs gray.
- Special nodes:
- - "*" after the node number: entry of a SCoP,
- - "#" after the node number: exit of a SCoP,
- - "()" entry or exit not part of SCoP. */
+/* Finalize graphite: perform cleanup when TRANSFORM_DONE. */
static void
-dot_all_scops_1 (FILE *file, VEC (scop_p, heap) *scops)
+graphite_finalize (bool transform_done)
{
- basic_block bb;
- edge e;
- edge_iterator ei;
- scop_p scop;
- const char* color;
- int i;
-
- /* Disable debugging while printing graph. */
- int tmp_dump_flags = dump_flags;
- dump_flags = 0;
-
- fprintf (file, "digraph all {\n");
-
- FOR_ALL_BB (bb)
- {
- int part_of_scop = false;
-
- /* Use HTML for every bb label. So we are able to print bbs
- which are part of two different SCoPs, with two different
- background colors. */
- fprintf (file, "%d [label=<\n <TABLE BORDER=\"0\" CELLBORDER=\"1\" ",
- bb->index);
- fprintf (file, "CELLSPACING=\"0\">\n");
-
- /* Select color for SCoP. */
- for (i = 0; VEC_iterate (scop_p, scops, i, scop); i++)
- if (bb_in_sese_p (bb, SCOP_REGION (scop))
- || (SCOP_EXIT (scop) == bb)
- || (SCOP_ENTRY (scop) == bb))
- {
- switch (i % 17)
- {
- case 0: /* red */
- color = "#e41a1c";
- break;
- case 1: /* blue */
- color = "#377eb8";
- break;
- case 2: /* green */
- color = "#4daf4a";
- break;
- case 3: /* purple */
- color = "#984ea3";
- break;
- case 4: /* orange */
- color = "#ff7f00";
- break;
- case 5: /* yellow */
- color = "#ffff33";
- break;
- case 6: /* brown */
- color = "#a65628";
- break;
- case 7: /* rose */
- color = "#f781bf";
- break;
- case 8:
- color = "#8dd3c7";
- break;
- case 9:
- color = "#ffffb3";
- break;
- case 10:
- color = "#bebada";
- break;
- case 11:
- color = "#fb8072";
- break;
- case 12:
- color = "#80b1d3";
- break;
- case 13:
- color = "#fdb462";
- break;
- case 14:
- color = "#b3de69";
- break;
- case 15:
- color = "#fccde5";
- break;
- case 16:
- color = "#bc80bd";
- break;
- default: /* gray */
- color = "#999999";
- }
-
- fprintf (file, " <TR><TD WIDTH=\"50\" BGCOLOR=\"%s\">", color);
-
- if (!bb_in_sese_p (bb, SCOP_REGION (scop)))
- fprintf (file, " (");
-
- if (bb == SCOP_ENTRY (scop)
- && bb == SCOP_EXIT (scop))
- fprintf (file, " %d*# ", bb->index);
- else if (bb == SCOP_ENTRY (scop))
- fprintf (file, " %d* ", bb->index);
- else if (bb == SCOP_EXIT (scop))
- fprintf (file, " %d# ", bb->index);
- else
- fprintf (file, " %d ", bb->index);
-
- if (!bb_in_sese_p (bb, SCOP_REGION (scop)))
- fprintf (file, ")");
-
- fprintf (file, "</TD></TR>\n");
- part_of_scop = true;
- }
-
- if (!part_of_scop)
- {
- fprintf (file, " <TR><TD WIDTH=\"50\" BGCOLOR=\"#ffffff\">");
- fprintf (file, " %d </TD></TR>\n", bb->index);
- }
-
- fprintf (file, " </TABLE>>, shape=box, style=\"setlinewidth(0)\"]\n");
- }
-
- FOR_ALL_BB (bb)
- {
- FOR_EACH_EDGE (e, ei, bb->succs)
- fprintf (file, "%d -> %d;\n", bb->index, e->dest->index);
- }
-
- fputs ("}\n\n", file);
-
- /* Enable debugging again. */
- dump_flags = tmp_dump_flags;
-}
-
-/* Display all SCoPs using dotty. */
+ if (transform_done)
+ cleanup_tree_cfg ();
-void
-dot_all_scops (VEC (scop_p, heap) *scops)
-{
- /* When debugging, enable the following code. This cannot be used
- in production compilers because it calls "system". */
-#if 1
- FILE *stream = fopen ("/tmp/allscops.dot", "w");
- gcc_assert (stream);
-
- dot_all_scops_1 (stream, scops);
- fclose (stream);
-
- system ("dotty /tmp/allscops.dot");
-#else
- dot_all_scops_1 (stderr, scops);
-#endif
+ cloog_finalize ();
+ free_original_copy_tables ();
}
/* Perform a set of linear transforms on the loops of the current
@@ -273,58 +105,19 @@ graphite_transform_loops (void)
bool transform_done = false;
VEC (scop_p, heap) *scops = NULL;
- if (number_of_loops () <= 1)
+ if (!graphite_initialize ())
return;
- recompute_all_dominators ();
-
- if (dump_file && (dump_flags & TDF_DETAILS))
- fprintf (dump_file, "Graphite loop transformations \n");
-
- initialize_original_copy_tables ();
- cloog_initialize ();
build_scops (&scops);
- if (dump_file && (dump_flags & TDF_DETAILS))
- fprintf (dump_file, "\nnumber of SCoPs: %d\n",
- VEC_length (scop_p, scops));
-
for (i = 0; VEC_iterate (scop_p, scops, i, scop); i++)
- {
- build_scop_bbs (scop);
- if (!build_sese_loop_nests (SCOP_REGION (scop)))
- continue;
-
- if (scop_contains_non_iv_scalar_phi_nodes (scop))
- continue;
-
- build_bb_loops (scop);
- build_sese_conditions (SCOP_REGION (scop));
- find_scop_parameters (scop);
- build_scop_iteration_domain (scop);
- add_conditions_to_constraints (scop);
- build_scop_canonical_schedules (scop);
- build_scop_data_accesses (scop);
-
- if (graphite_apply_transformations (scop))
- transform_done = gloog (scop);
-#ifdef ENABLE_CHECKING
- else
- {
- cloog_prog_clast pc = scop_to_clast (scop);
- cloog_clast_free (pc.stmt);
- cloog_program_free (pc.prog);
- }
-#endif
- }
-
- /* Cleanup. */
- if (transform_done)
- cleanup_tree_cfg ();
+ if (build_poly_scop (scop)
+ && (apply_poly_transforms (scop)
+ || check_poly_representation (scop)))
+ transform_done |= gloog (scop);
free_scops (scops);
- cloog_finalize ();
- free_original_copy_tables ();
+ graphite_finalize (transform_done);
}
#else /* If Cloog is not available: #ifndef HAVE_cloog. */
Index: sese.c
===================================================================
--- sese.c (revision 144330)
+++ sese.c (working copy)
@@ -358,6 +358,25 @@ graphite_loop_normal_form (loop_p loop)
return canonicalize_loop_ivs (loop, NULL, nit);
}
+/* Debug the list of old induction variables for this SCOP. */
+
+void
+debug_oldivs (sese region)
+{
+ int i;
+ name_tree oldiv;
+
+ fprintf (stderr, "Old IVs:");
+
+ for (i = 0; VEC_iterate (name_tree, SESE_OLDIVS (region), i, oldiv); i++)
+ {
+ fprintf (stderr, "(");
+ print_generic_expr (stderr, oldiv->t, 0);
+ fprintf (stderr, ", %s, %d)\n", oldiv->name, oldiv->loop->num);
+ }
+ fprintf (stderr, "\n");
+}
+
/* Record LOOP as occuring in REGION. Returns true when the operation
was successful. */
@@ -1450,3 +1469,4 @@ move_sese_in_condition (sese region)
return if_region;
}
+
Index: graphite-poly.c
===================================================================
--- graphite-poly.c (revision 144330)
+++ graphite-poly.c (working copy)
@@ -506,7 +506,7 @@ graphite_trans_scop_block (scop_p scop)
/* Apply graphite transformations to all the basic blocks of SCOP. */
bool
-graphite_apply_transformations (scop_p scop)
+apply_poly_transforms (scop_p scop)
{
bool transform_done = false;
@@ -687,5 +687,22 @@ schedule_to_scattering (poly_bb_p pbb, i
return ph;
}
+
+/* Debug the loops around basic block GB. */
+
+void
+debug_loop_vec (poly_bb_p pbb)
+{
+ int i;
+ loop_p loop;
+
+ fprintf (stderr, "Loop Vec:");
+
+ for (i = 0; VEC_iterate (loop_p, PBB_LOOPS (pbb), i, loop); i++)
+ fprintf (stderr, "%d: %d, ", i, loop ? loop->num : -1);
+
+ fprintf (stderr, "\n");
+}
+
#endif
Index: graphite-poly.h
===================================================================
--- graphite-poly.h (revision 144330)
+++ graphite-poly.h (working copy)
@@ -245,11 +245,10 @@ struct scop
extern scop_p new_scop (sese);
extern void free_scop (scop_p);
extern void free_scops (VEC (scop_p, heap) *);
-extern void dot_all_scops (VEC (scop_p, heap) *);
extern void print_generated_program (FILE *, scop_p);
extern void debug_generated_program (scop_p);
extern int scop_max_loop_depth (scop_p);
-extern bool graphite_apply_transformations (scop_p);
+extern bool apply_poly_transforms (scop_p);
/* Returns the number of parameters for SCOP. */
Index: graphite-sese-to-poly.c
===================================================================
--- graphite-sese-to-poly.c (revision 144331)
+++ graphite-sese-to-poly.c (working copy)
@@ -331,7 +331,7 @@ compare_prefix_loops (VEC (loop_p, heap)
F 2
*/
-void
+static void
build_scop_canonical_schedules (scop_p scop)
{
int i;
@@ -382,7 +382,7 @@ build_scop_canonical_schedules (scop_p s
/* Build the LOOPS vector for all bbs in SCOP. */
-void
+static void
build_bb_loops (scop_p scop)
{
poly_bb_p pbb;
@@ -672,7 +672,7 @@ find_params_in_bb (sese sese, gimple_bb_
/* Record the parameters used in the SCOP. A variable is a parameter
in a scop if it does not vary during the execution of that scop. */
-void
+static void
find_scop_parameters (scop_p scop)
{
poly_bb_p pbb;
@@ -947,7 +947,7 @@ bb_contains_non_iv_scalar_phi_nodes (bas
/* Check if SCOP contains non scalar phi nodes. */
-bool
+static bool
scop_contains_non_iv_scalar_phi_nodes (scop_p scop)
{
int i;
@@ -963,7 +963,7 @@ scop_contains_non_iv_scalar_phi_nodes (s
/* Helper recursive function. Record in CONDITIONS and CASES all
conditions from 'if's and 'switch'es occurring in BB from REGION. */
-void
+static void
build_sese_conditions_1 (VEC (gimple, heap) **conditions,
VEC (gimple, heap) **cases, basic_block bb,
sese region)
@@ -1100,7 +1100,7 @@ build_sese_conditions_1 (VEC (gimple, he
/* Record all conditions in REGION. */
-void
+static void
build_sese_conditions (sese region)
{
VEC (gimple, heap) *conditions = NULL;
@@ -1116,7 +1116,7 @@ build_sese_conditions (sese region)
/* Traverses all the GBBs of the SCOP and add their constraints to the
iteration domains. */
-void
+static void
add_conditions_to_constraints (scop_p scop)
{
int i;
@@ -1130,7 +1130,7 @@ add_conditions_to_constraints (scop_p sc
SCOP, and that vary for the execution of the current basic block.
Returns false if there is no loop in SCOP. */
-void
+static void
build_scop_iteration_domain (scop_p scop)
{
struct loop *loop;
@@ -1247,7 +1247,7 @@ build_access_matrix (data_reference_p re
/* Build the access matrices for the data references in the SCOP. */
-void
+static void
build_scop_data_accesses (scop_p scop)
{
int i;
@@ -1278,4 +1278,38 @@ build_scop_data_accesses (scop_p scop)
}
}
+/* Builds the polyhedral representation for a SESE region. */
+
+bool
+build_poly_scop (scop_p scop)
+{
+ build_scop_bbs (scop);
+ if (!build_sese_loop_nests (SCOP_REGION (scop))
+ || scop_contains_non_iv_scalar_phi_nodes (scop))
+ return false;
+
+ build_bb_loops (scop);
+ build_sese_conditions (SCOP_REGION (scop));
+ find_scop_parameters (scop);
+ build_scop_iteration_domain (scop);
+ add_conditions_to_constraints (scop);
+ build_scop_canonical_schedules (scop);
+ build_scop_data_accesses (scop);
+
+ return true;
+}
+
+/* Always return false. Exercise the scop_to_clast function. */
+
+bool
+check_poly_representation (scop_p scop)
+{
+#ifdef ENABLE_CHECKING
+ cloog_prog_clast pc = scop_to_clast (scop);
+ cloog_clast_free (pc.stmt);
+ cloog_program_free (pc.prog);
+#endif
+
+ return false;
+}
#endif
Index: graphite-sese-to-poly.h
===================================================================
--- graphite-sese-to-poly.h (revision 144331)
+++ graphite-sese-to-poly.h (working copy)
@@ -21,16 +21,7 @@ along with GCC; see the file COPYING3.
#ifndef GCC_GRAPHITE_SESE_TO_POLY_H
#define GCC_GRAPHITE_SESE_TO_POLY_H
-extern void build_bb_loops (scop_p);
-extern void build_sese_conditions_1 (VEC (gimple, heap) **,
- VEC (gimple, heap) **,
- basic_block, sese);
-extern bool scop_contains_non_iv_scalar_phi_nodes (scop_p);
-extern void build_sese_conditions (sese);
-extern void find_scop_parameters (scop_p);
-extern void build_scop_iteration_domain (scop_p);
-extern void add_conditions_to_constraints (scop_p);
-extern void build_scop_canonical_schedules (scop_p);
-extern void build_scop_data_accesses (scop_p);
+bool build_poly_scop (scop_p);
+bool check_poly_representation (scop_p);
#endif