graphite-isl-ast-to-gimple.c (generate_isl_context): Add __isl_give to the declaration.
[gcc.git] / gcc / graphite-isl-ast-to-gimple.c
1 /* Translation of ISL AST to Gimple.
2 Copyright (C) 2014 Free Software Foundation, Inc.
3 Contributed by Roman Gareev <gareevroman@gmail.com>.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22
23 #ifdef HAVE_cloog
24 #include <isl/set.h>
25 #include <isl/map.h>
26 #include <isl/union_map.h>
27 #include <isl/ast_build.h>
28 #endif
29
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tree.h"
33 #include "basic-block.h"
34 #include "tree-ssa-alias.h"
35 #include "internal-fn.h"
36 #include "gimple-expr.h"
37 #include "is-a.h"
38 #include "gimple.h"
39 #include "gimple-iterator.h"
40 #include "tree-ssa-loop.h"
41 #include "tree-pass.h"
42 #include "cfgloop.h"
43 #include "tree-data-ref.h"
44 #include "sese.h"
45
46 #ifdef HAVE_cloog
47 #include "graphite-poly.h"
48 #include "graphite-isl-ast-to-gimple.h"
49
50 /* This flag is set when an error occurred during the translation of
51 ISL AST to Gimple. */
52
53 static bool graphite_regenerate_error;
54
55 /* Prints NODE to FILE. */
56
57 void
58 print_isl_ast_node (FILE *file, __isl_keep isl_ast_node *node,
59 __isl_keep isl_ctx *ctx)
60 {
61 isl_printer *prn = isl_printer_to_file (ctx, file);
62 prn = isl_printer_set_output_format (prn, ISL_FORMAT_C);
63 prn = isl_printer_print_ast_node (prn, node);
64 prn = isl_printer_print_str (prn, "\n");
65 isl_printer_free (prn);
66 }
67
68 /* Generates a build, which specifies the constraints on the parameters. */
69
70 static __isl_give isl_ast_build *
71 generate_isl_context (scop_p scop)
72 {
73 isl_set *context_isl = isl_set_params (isl_set_copy (scop->context));
74 return isl_ast_build_from_context (context_isl);
75 }
76
77 /* Generates a schedule, which specifies an order used to
78 visit elements in a domain. */
79
80 static __isl_give isl_union_map *
81 generate_isl_schedule (scop_p scop)
82 {
83 int i;
84 poly_bb_p pbb;
85 isl_union_map *schedule_isl =
86 isl_union_map_empty (isl_set_get_space (scop->context));
87
88 FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb)
89 {
90 /* Dead code elimination: when the domain of a PBB is empty,
91 don't generate code for the PBB. */
92 if (isl_set_is_empty (pbb->domain))
93 continue;
94
95 isl_map *bb_schedule = isl_map_copy (pbb->transformed);
96 bb_schedule = isl_map_intersect_domain (bb_schedule,
97 isl_set_copy (pbb->domain));
98 schedule_isl =
99 isl_union_map_union (schedule_isl,
100 isl_union_map_from_map (bb_schedule));
101 }
102 return schedule_isl;
103 }
104
105 static __isl_give isl_ast_node *
106 scop_to_isl_ast (scop_p scop)
107 {
108 isl_union_map *schedule_isl = generate_isl_schedule (scop);
109 isl_ast_build *context_isl = generate_isl_context (scop);
110 isl_ast_node *ast_isl = isl_ast_build_ast_from_schedule (context_isl,
111 schedule_isl);
112 isl_ast_build_free (context_isl);
113 return ast_isl;
114 }
115
116 /* GIMPLE Loop Generator: generates loops from STMT in GIMPLE form for
117 the given SCOP. Return true if code generation succeeded.
118
119 FIXME: This is not yet a full implementation of the code generator
120 with ISL ASTs. Generation of GIMPLE code is have to be added. */
121
122 bool
123 graphite_regenerate_ast_isl (scop_p scop)
124 {
125 timevar_push (TV_GRAPHITE_CODE_GEN);
126 graphite_regenerate_error = false;
127 isl_ast_node *root_node = scop_to_isl_ast (scop);
128 if (dump_file && (dump_flags & TDF_DETAILS))
129 {
130 fprintf (dump_file, "\nISL AST generated by ISL: \n");
131 print_isl_ast_node (dump_file, root_node, scop->ctx);
132 }
133 isl_ast_node_free (root_node);
134 timevar_pop (TV_GRAPHITE_CODE_GEN);
135 return !graphite_regenerate_error;
136 }
137 #endif