This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[graphite] Transform schedule to scattering for all bbs
- From: "Sebastian Pop" <sebpop at gmail dot com>
- To: "GCC Patches" <gcc-patches at gcc dot gnu dot org>, "Tobias Grosser" <grosser at fim dot uni-passau dot de>
- Date: Tue, 29 Jan 2008 20:50:31 -0600
- Subject: [graphite] Transform schedule to scattering for all bbs
Always from this email from Tobias, committed:
I wrote a function, which converts the graphite scheduling function into a cloog
scattering function matrix. It will be used to restore the original control
flow, as the domains we pass to cloog do not contain this yet.
2008-01-29 Tobias Grosser <grosser@fim.uni-passau.de>
* graphite.c (schedule_to_scattering, nb_loops_around_gb): New.
(print_graphite_bb): Print scattering.
Index: graphite.c
===================================================================
--- graphite.c (revision 131954)
+++ graphite.c (working copy)
@@ -49,6 +49,7 @@ Software Foundation, 51 Franklin Street,
VEC (scop_p, heap) *current_scops;
static bool basic_block_simple_for_scop_p (basic_block);
+static CloogMatrix *schedule_to_scattering (graphite_bb_p);
/* Print the schedules from SCHED. */
@@ -63,9 +64,13 @@ print_graphite_bb (FILE *file, graphite_
print_loops_bb (file, GBB_BB (gb), indent+2, verbosity);
- if (0)
+ if (GBB_DATA_REFS (gb))
dump_data_references (file, GBB_DATA_REFS (gb));
+ fprintf (file, " (scattering: \n");
+ cloog_matrix_print (file, schedule_to_scattering (gb));
+ fprintf (file, " )\n");
+
fprintf (file, ")\n");
}
@@ -1156,6 +1161,83 @@ setup_cloog_loop (scop_p scop, struct lo
return res;
}
+/* Calculate the number of loops around GB in the current SCOP. */
+
+static inline int
+nb_loops_around_gb (graphite_bb_p gb)
+{
+ struct loop *loop = gbb_loop (gb);
+ struct loop *outer_loop = SCOP_ENTRY (GBB_SCOP (gb))->loop_father;
+
+ return loop_depth (loop) - loop_depth (outer_loop);
+}
+
+/* Converts the graphite scheduling function into a cloog scattering
+ function matrix, which restores the original control flow. */
+
+static CloogMatrix *
+schedule_to_scattering (graphite_bb_p gb)
+{
+ /* Conservative aproximation, the maximal loop depth of all bbs would be
+ sufficient, as we use in cloog one iterator for loops of the same loop
+ depth. */
+ int max_nb_iterators = scop_nb_loops (GBB_SCOP (gb));
+ struct loop *loop = gbb_loop (gb);
+ int nb_iterators = nb_loops_around_gb (gb);
+
+ /* Number of columns:
+ 1 col = Eq/Inq,
+ 2 * max_nb_iterators + 1 cols = Scattering dimensions,
+ nb_iterators cols = bb's iterators,
+ 1 col = Constant 1
+ The scattering domain contains one dimension for every iterator (which
+ iteration of this loop should be scattered) and max_nb_iterators + 1
+ dimension for the textual order of every loop. */
+ int nb_cols = 1 + 2 * max_nb_iterators + 1 + nb_iterators + 1;
+ int col_const = nb_cols - 1;
+ int col_iter_offset = 1 + 2 * max_nb_iterators + 1;
+
+ CloogMatrix *scat = cloog_matrix_alloc (nb_iterators * 2 + 1, nb_cols);
+
+ int i;
+ int loop_index;
+ int row = 0;
+
+ /* Reverse, because we get the inner loops first. */
+ for (i = nb_iterators - 1; i >= 0; i--)
+ {
+ loop_index = scop_loop_index (GBB_SCOP (gb), loop);
+
+ /* Set textual order for bb's of loop. */
+ value_init (scat->p[row][2 * i + 3]);
+ value_set_si (scat->p[row][2 * i + 3], 1);
+ value_init (scat->p[row][col_const]);
+ value_set_si (scat->p[row][col_const],
+ GBB_STATIC_SCHEDULE (gb)[loop_index]);
+
+ row++;
+
+ /* Set scattering for loop iterator. */
+ value_init (scat->p[row][2 * i + 2]);
+ value_set_si (scat->p[row][2 * i + 2], 1);
+ value_init (scat->p[row][col_iter_offset + i]);
+ value_set_si (scat->p[row][col_iter_offset + i], 1);
+
+ loop = loop_outer (loop);
+ row++;
+ }
+
+ /* Set textual order for outer loop. */
+ loop_index = scop_loop_index (GBB_SCOP (gb), loop);
+
+ value_init (scat->p[row][1]);
+ value_set_si (scat->p[row][1], 1);
+ value_init (scat->p[row][col_const]);
+ value_set_si (scat->p[row][col_const], GBB_STATIC_SCHEDULE (gb)[loop_index]);
+
+ return scat;
+}
+
/* Build the current domain matrix: the loops belonging to the current
SCOP, and that vary for the execution of the current basic block.
Returns false if there is no loop in SCOP. */