]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/graphite.h
isl.m4: Remove support for ISL 0.14.
[thirdparty/gcc.git] / gcc / graphite.h
CommitLineData
2abae5f1 1/* Graphite polyhedral representation.
cbe34bb5 2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
2abae5f1
SP
3 Contributed by Sebastian Pop <sebastian.pop@amd.com> and
4 Tobias Grosser <grosser@fim.uni-passau.de>.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GCC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#ifndef GCC_GRAPHITE_POLY_H
23#define GCC_GRAPHITE_POLY_H
24
9c358739 25#include "sese.h"
616e2b4a
SP
26#include <isl/options.h>
27#include <isl/ctx.h>
28#include <isl/val_gmp.h>
29#include <isl/set.h>
30#include <isl/union_set.h>
31#include <isl/map.h>
32#include <isl/union_map.h>
33#include <isl/aff.h>
34#include <isl/constraint.h>
35#include <isl/flow.h>
36#include <isl/ilp.h>
9625f2a2 37#include <isl/schedule.h>
616e2b4a 38#include <isl/ast_build.h>
616e2b4a
SP
39#include <isl/schedule_node.h>
40
2abae5f1 41typedef struct poly_dr *poly_dr_p;
2abae5f1
SP
42
43typedef struct poly_bb *poly_bb_p;
2abae5f1
SP
44
45typedef struct scop *scop_p;
2abae5f1 46
33ad93b9 47typedef unsigned graphite_dim_t;
2abae5f1 48
2abae5f1
SP
49static inline graphite_dim_t scop_nb_params (scop_p);
50
51/* A data reference can write or read some memory or we
52 just know it may write some memory. */
e6dec0fb 53enum poly_dr_type
2abae5f1
SP
54{
55 PDR_READ,
d8eeb078
SP
56 /* PDR_MAY_READs are represented using PDR_READS. This does not
57 limit the expressiveness. */
2abae5f1
SP
58 PDR_WRITE,
59 PDR_MAY_WRITE
60};
61
62struct poly_dr
63{
afae0207
SP
64 /* An identifier for this PDR. */
65 int id;
66
7bd2a8a7
SP
67 /* The number of data refs identical to this one in the PBB. */
68 int nb_refs;
69
65b016eb
AK
70 /* A pointer to the gimple stmt containing this reference. */
71 gimple *stmt;
2abae5f1
SP
72
73 /* A pointer to the PBB that contains this data reference. */
74 poly_bb_p pbb;
75
e6dec0fb 76 enum poly_dr_type type;
2abae5f1
SP
77
78 /* The access polyhedron contains the polyhedral space this data
79 reference will access.
80
81 The polyhedron contains these dimensions:
82
1825f9a2
LF
83 - The alias set (a):
84 Every memory access is classified in at least one alias set.
2abae5f1 85
1825f9a2
LF
86 - The subscripts (s_0, ..., s_n):
87 The memory is accessed using zero or more subscript dimensions.
2abae5f1 88
1825f9a2 89 - The iteration domain (variables and parameters)
2abae5f1
SP
90
91 Do not hardcode the dimensions. Use the following accessor functions:
92 - pdr_alias_set_dim
93 - pdr_subscript_dim
94 - pdr_iterator_dim
95 - pdr_parameter_dim
96
97 Example:
98
99 | int A[1335][123];
100 | int *p = malloc ();
101 |
102 | k = ...
103 | for i
104 | {
105 | if (unknown_function ())
106 | p = A;
107 | ... = p[?][?];
108 | for j
25d7cc15 109 | A[i][j+k] = m;
2abae5f1
SP
110 | }
111
112 The data access A[i][j+k] in alias set "5" is described like this:
113
25d7cc15 114 | i j k a s0 s1 1
2abae5f1
SP
115 | 0 0 0 1 0 0 -5 = 0
116 |-1 0 0 0 1 0 0 = 0
117 | 0 -1 -1 0 0 1 0 = 0
66096911
SP
118 | 0 0 0 0 1 0 0 >= 0 # The last four lines describe the
119 | 0 0 0 0 0 1 0 >= 0 # array size.
2abae5f1
SP
120 | 0 0 0 0 -1 0 1335 >= 0
121 | 0 0 0 0 0 -1 123 >= 0
122
123 The pointer "*p" in alias set "5" and "7" is described as a union of
124 polyhedron:
125
126
25d7cc15 127 | i k a s0 1
2abae5f1
SP
128 | 0 0 1 0 -5 = 0
129 | 0 0 0 1 0 >= 0
130
131 "or"
132
25d7cc15 133 | i k a s0 1
2abae5f1
SP
134 | 0 0 1 0 -7 = 0
135 | 0 0 0 1 0 >= 0
136
137 "*p" accesses all of the object allocated with 'malloc'.
138
139 The scalar data access "m" is represented as an array with zero subscript
140 dimensions.
141
142 | i j k a 1
ae403f5a
RB
143 | 0 0 0 -1 15 = 0
144
145 The difference between the graphite internal format for access data and
146 the OpenSop format is in the order of columns.
147 Instead of having:
148
149 | i j k a s0 s1 1
150 | 0 0 0 1 0 0 -5 = 0
151 |-1 0 0 0 1 0 0 = 0
152 | 0 -1 -1 0 0 1 0 = 0
153 | 0 0 0 0 1 0 0 >= 0 # The last four lines describe the
154 | 0 0 0 0 0 1 0 >= 0 # array size.
155 | 0 0 0 0 -1 0 1335 >= 0
156 | 0 0 0 0 0 -1 123 >= 0
157
158 In OpenScop we have:
159
160 | a s0 s1 i j k 1
161 | 1 0 0 0 0 0 -5 = 0
162 | 0 1 0 -1 0 0 0 = 0
163 | 0 0 1 0 -1 -1 0 = 0
164 | 0 1 0 0 0 0 0 >= 0 # The last four lines describe the
165 | 0 0 1 0 0 0 0 >= 0 # array size.
166 | 0 -1 0 0 0 0 1335 >= 0
167 | 0 0 -1 0 0 0 123 >= 0
168
169 The OpenScop access function is printed as follows:
170
171 | 1 # The number of disjunct components in a union of access functions.
172 | R C O I L P # Described bellow.
173 | a s0 s1 i j k 1
174 | 1 0 0 0 0 0 -5 = 0
175 | 0 1 0 -1 0 0 0 = 0
176 | 0 0 1 0 -1 -1 0 = 0
177 | 0 1 0 0 0 0 0 >= 0 # The last four lines describe the
178 | 0 0 1 0 0 0 0 >= 0 # array size.
179 | 0 -1 0 0 0 0 1335 >= 0
180 | 0 0 -1 0 0 0 123 >= 0
181
182 Where:
183 - R: Number of rows.
184 - C: Number of columns.
185 - O: Number of output dimensions = alias set + number of subscripts.
186 - I: Number of input dimensions (iterators).
187 - L: Number of local (existentially quantified) dimensions.
188 - P: Number of parameters.
189
190 In the example, the vector "R C O I L P" is "7 7 3 2 0 1". */
33ad93b9 191 isl_map *accesses;
24757752 192 isl_set *subscript_sizes;
2abae5f1
SP
193};
194
afae0207 195#define PDR_ID(PDR) (PDR->id)
7bd2a8a7 196#define PDR_NB_REFS(PDR) (PDR->nb_refs)
2abae5f1
SP
197#define PDR_PBB(PDR) (PDR->pbb)
198#define PDR_TYPE(PDR) (PDR->type)
33ad93b9 199#define PDR_ACCESSES(PDR) (NULL)
2abae5f1 200
65b016eb
AK
201void new_poly_dr (poly_bb_p, gimple *, enum poly_dr_type,
202 isl_map *, isl_set *);
5c24066b
AK
203void debug_pdr (poly_dr_p);
204void print_pdr (FILE *, poly_dr_p);
d8eeb078
SP
205
206static inline bool
207pdr_read_p (poly_dr_p pdr)
208{
209 return PDR_TYPE (pdr) == PDR_READ;
210}
211
212/* Returns true when PDR is a "write". */
213
214static inline bool
215pdr_write_p (poly_dr_p pdr)
216{
217 return PDR_TYPE (pdr) == PDR_WRITE;
218}
219
220/* Returns true when PDR is a "may write". */
221
222static inline bool
223pdr_may_write_p (poly_dr_p pdr)
224{
225 return PDR_TYPE (pdr) == PDR_MAY_WRITE;
226}
227
2abae5f1
SP
228/* POLY_BB represents a blackbox in the polyhedral model. */
229
230struct poly_bb
231{
a1954f72 232 /* Pointer to a basic block or a statement in the compiler. */
8e4dc590 233 gimple_poly_bb_p black_box;
2abae5f1 234
a1954f72 235 /* Pointer to the SCOP containing this PBB. */
2abae5f1
SP
236 scop_p scop;
237
aa52513e
SP
238 /* The iteration domain of this bb. The layout of this polyhedron
239 is I|G with I the iteration domain, G the context parameters.
240
2abae5f1
SP
241 Example:
242
243 for (i = a - 7*b + 8; i <= 3*a + 13*b + 20; i++)
244 for (j = 2; j <= 2*i + 5; j++)
245 for (k = 0; k <= 5; k++)
246 S (i,j,k)
247
248 Loop iterators: i, j, k
249 Parameters: a, b
250
251 | i >= a - 7b + 8
252 | i <= 3a + 13b + 20
253 | j >= 2
254 | j <= 2i + 5
255 | k >= 0
256 | k <= 5
257
258 The number of variables in the DOMAIN may change and is not
259 related to the number of loops in the original code. */
33ad93b9 260 isl_set *domain;
adba512d 261 isl_set *iterators;
adba512d
AK
262
263 /* The data references we access. */
264 vec<poly_dr_p> drs;
a0dd1440 265
65b016eb
AK
266 /* The last basic block generated for this pbb. */
267 basic_block new_bb;
2abae5f1
SP
268};
269
65ef70d6 270#define PBB_BLACK_BOX(PBB) ((gimple_poly_bb_p) PBB->black_box)
2abae5f1 271#define PBB_SCOP(PBB) (PBB->scop)
2abae5f1 272#define PBB_DRS(PBB) (PBB->drs)
2abae5f1 273
8e4dc590 274extern poly_bb_p new_poly_bb (scop_p, gimple_poly_bb_p);
5c24066b
AK
275extern void print_pbb_domain (FILE *, poly_bb_p);
276extern void print_pbb (FILE *, poly_bb_p);
277extern void print_scop_context (FILE *, scop_p);
278extern void print_scop (FILE *, scop_p);
279extern void debug_pbb_domain (poly_bb_p);
280extern void debug_pbb (poly_bb_p);
281extern void print_pdrs (FILE *, poly_bb_p);
282extern void debug_pdrs (poly_bb_p);
283extern void debug_scop_context (scop_p);
284extern void debug_scop (scop_p);
285extern void print_scop_params (FILE *, scop_p);
286extern void debug_scop_params (scop_p);
287extern void print_iteration_domain (FILE *, poly_bb_p);
288extern void print_iteration_domains (FILE *, scop_p);
289extern void debug_iteration_domain (poly_bb_p);
290extern void debug_iteration_domains (scop_p);
33ad93b9
RG
291extern void print_isl_set (FILE *, isl_set *);
292extern void print_isl_map (FILE *, isl_map *);
ea17c0fe 293extern void print_isl_union_map (FILE *, isl_union_map *);
33ad93b9
RG
294extern void print_isl_aff (FILE *, isl_aff *);
295extern void print_isl_constraint (FILE *, isl_constraint *);
adba512d
AK
296extern void print_isl_schedule (FILE *, isl_schedule *);
297extern void debug_isl_schedule (isl_schedule *);
298extern void print_isl_ast (FILE *, isl_ast_node *);
299extern void debug_isl_ast (isl_ast_node *);
33ad93b9
RG
300extern void debug_isl_set (isl_set *);
301extern void debug_isl_map (isl_map *);
ea17c0fe 302extern void debug_isl_union_map (isl_union_map *);
33ad93b9
RG
303extern void debug_isl_aff (isl_aff *);
304extern void debug_isl_constraint (isl_constraint *);
33ad93b9 305extern void debug_gmp_value (mpz_t);
adba512d
AK
306extern void debug_scop_pbb (scop_p scop, int i);
307extern void print_schedule_ast (FILE *, __isl_keep isl_schedule *, scop_p);
308extern void debug_schedule_ast (__isl_keep isl_schedule *, scop_p);
2abae5f1 309
03922af3 310/* The basic block of the PBB. */
072edf07 311
03922af3
SP
312static inline basic_block
313pbb_bb (poly_bb_p pbb)
314{
315 return GBB_BB (PBB_BLACK_BOX (pbb));
316}
317
afae0207
SP
318static inline int
319pbb_index (poly_bb_p pbb)
320{
03922af3 321 return pbb_bb (pbb)->index;
afae0207
SP
322}
323
d48e288d
SP
324/* The loop of the PBB. */
325
326static inline loop_p
327pbb_loop (poly_bb_p pbb)
328{
329 return gbb_loop (PBB_BLACK_BOX (pbb));
330}
331
2abae5f1
SP
332/* The scop that contains the PDR. */
333
afae0207
SP
334static inline scop_p
335pdr_scop (poly_dr_p pdr)
2abae5f1
SP
336{
337 return PBB_SCOP (PDR_PBB (pdr));
338}
339
340/* Set black box of PBB to BLACKBOX. */
341
342static inline void
8e4dc590 343pbb_set_black_box (poly_bb_p pbb, gimple_poly_bb_p black_box)
2abae5f1
SP
344{
345 pbb->black_box = black_box;
346}
347
09fefdad
AK
348/* A helper structure to keep track of data references, polyhedral BBs, and
349 alias sets. */
350
351struct dr_info
352{
caf5b4df
AK
353 enum {
354 invalid_alias_set = -1
355 };
09fefdad
AK
356 /* The data reference. */
357 data_reference_p dr;
358
09fefdad
AK
359 /* The polyhedral BB containing this DR. */
360 poly_bb_p pbb;
361
caf5b4df
AK
362 /* ALIAS_SET is the SCC number assigned by a graph_dfs of the alias graph.
363 -1 is an invalid alias set. */
364 int alias_set;
365
09fefdad 366 /* Construct a DR_INFO from a data reference DR, an ALIAS_SET, and a PBB. */
caf5b4df
AK
367 dr_info (data_reference_p dr, poly_bb_p pbb,
368 int alias_set = invalid_alias_set)
369 : dr (dr), pbb (pbb), alias_set (alias_set) {}
09fefdad
AK
370};
371
2abae5f1
SP
372/* A SCOP is a Static Control Part of the program, simple enough to be
373 represented in polyhedral form. */
374struct scop
375{
376 /* A SCOP is defined as a SESE region. */
d37fc3aa 377 sese_info_p scop_info;
2abae5f1
SP
378
379 /* Number of parameters in SCoP. */
380 graphite_dim_t nb_params;
381
382 /* All the basic blocks in this scop that contain memory references
383 and that will be represented as statements in the polyhedral
384 representation. */
b0b5710c 385 vec<poly_bb_p> pbbs;
2abae5f1 386
09fefdad
AK
387 /* All the data references in this scop. */
388 vec<dr_info> drs;
389
2abae5f1
SP
390 /* The context describes known restrictions concerning the parameters
391 and relations in between the parameters.
392
393 void f (int8_t a, uint_16_t b) {
394 c = 2 a + b;
395 ...
396 }
397
398 Here we can add these restrictions to the context:
399
400 -128 >= a >= 127
401 0 >= b >= 65,535
402 c = 2a + b */
8e4dc590 403 isl_set *param_context;
33ad93b9 404
e357a5e0 405 /* The context used internally by isl. */
8e4dc590 406 isl_ctx *isl_context;
33ad93b9 407
adba512d
AK
408 /* SCoP original schedule. */
409 isl_schedule *original_schedule;
410
411 /* SCoP transformed schedule. */
412 isl_schedule *transformed_schedule;
9625f2a2 413
0f7a02a3
AK
414 /* The data dependence relation among the data references in this scop. */
415 isl_union_map *dependence;
2abae5f1
SP
416};
417
87ccab5d 418extern scop_p new_scop (edge, edge);
2abae5f1 419extern void free_scop (scop_p);
65b016eb
AK
420extern gimple_poly_bb_p new_gimple_poly_bb (basic_block, vec<data_reference_p>,
421 vec<scalar_use>, vec<tree>);
2abae5f1 422extern bool apply_poly_transforms (scop_p);
2abae5f1
SP
423
424/* Set the region of SCOP to REGION. */
425
426static inline void
bafcb153 427scop_set_region (scop_p scop, sese_info_p region)
2abae5f1 428{
d37fc3aa 429 scop->scop_info = region;
2abae5f1
SP
430}
431
432/* Returns the number of parameters for SCOP. */
433
434static inline graphite_dim_t
435scop_nb_params (scop_p scop)
436{
437 return scop->nb_params;
438}
439
440/* Set the number of params of SCOP to NB_PARAMS. */
441
442static inline void
443scop_set_nb_params (scop_p scop, graphite_dim_t nb_params)
444{
445 scop->nb_params = nb_params;
446}
447
adba512d 448extern void scop_get_dependences (scop_p scop);
574921c2
RG
449
450bool
451carries_deps (__isl_keep isl_union_map *schedule,
452 __isl_keep isl_union_map *deps,
453 int depth);
454
cf98f0f4
AK
455extern bool build_poly_scop (scop_p);
456extern bool graphite_regenerate_ast_isl (scop_p);
cf98f0f4 457extern void build_scops (vec<scop_p> *);
15256e28
AK
458extern void dot_all_sese (FILE *, vec<sese_l> &);
459extern void dot_sese (sese_l &);
460extern void dot_cfg ();
adba512d 461
2abae5f1 462#endif