Makefile.in: Add the compilation of graphite-isl-ast-to-gimple.o.
[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 #include <isl/set.h>
24 #include <isl/map.h>
25 #include <isl/union_map.h>
26 #include <isl/ast_build.h>
27
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tree.h"
31 #include "basic-block.h"
32 #include "tree-ssa-alias.h"
33 #include "internal-fn.h"
34 #include "gimple-expr.h"
35 #include "is-a.h"
36 #include "gimple.h"
37 #include "gimple-iterator.h"
38 #include "tree-ssa-loop.h"
39 #include "tree-pass.h"
40 #include "cfgloop.h"
41 #include "tree-data-ref.h"
42 #include "sese.h"
43
44 #include "graphite-poly.h"
45 #include "graphite-isl-ast-to-gimple.h"
46
47 /* This flag is set when an error occurred during the translation of
48 ISL AST to Gimple. */
49
50 static bool graphite_regenerate_error;
51
52 /* Prints NODE to FILE. */
53
54 void
55 print_isl_ast_node (FILE *file, __isl_keep isl_ast_node *node,
56 __isl_keep isl_ctx *ctx)
57 {
58 isl_printer *prn = isl_printer_to_file (ctx, file);
59 prn = isl_printer_set_output_format (prn, ISL_FORMAT_C);
60 prn = isl_printer_print_ast_node (prn, node);
61 prn = isl_printer_print_str (prn, "\n");
62 isl_printer_free (prn);
63 }
64
65 /* Generates a build, which specifies the constraints on the parameters. */
66
67 static isl_ast_build *
68 generate_isl_context (scop_p scop)
69 {
70 isl_set *context_isl = isl_set_params (isl_set_copy (scop->context));
71 return isl_ast_build_from_context (context_isl);
72 }
73
74 /* Generates a schedule, which specifies an order used to
75 visit elements in a domain. */
76
77 static isl_union_map *
78 generate_isl_schedule (scop_p scop)
79 {
80 int i;
81 poly_bb_p pbb;
82 isl_union_map *schedule_isl =
83 isl_union_map_empty (isl_set_get_space (scop->context));
84
85 FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb)
86 {
87 /* Dead code elimination: when the domain of a PBB is empty,
88 don't generate code for the PBB. */
89 if (isl_set_is_empty (pbb->domain))
90 continue;
91
92 isl_map *bb_schedule = isl_map_copy (pbb->transformed);
93 bb_schedule = isl_map_intersect_domain (bb_schedule,
94 isl_set_copy (pbb->domain));
95 schedule_isl =
96 isl_union_map_union (schedule_isl,
97 isl_union_map_from_map (bb_schedule));
98 }
99 return schedule_isl;
100 }
101
102 static isl_ast_node *
103 scop_to_isl_ast (scop_p scop)
104 {
105 isl_union_map *schedule_isl = generate_isl_schedule (scop);
106 isl_ast_build *context_isl = generate_isl_context (scop);
107 isl_ast_node *ast_isl = isl_ast_build_ast_from_schedule (context_isl,
108 schedule_isl);
109 isl_ast_build_free (context_isl);
110 return ast_isl;
111 }
112
113 /* GIMPLE Loop Generator: generates loops from STMT in GIMPLE form for
114 the given SCOP. Return true if code generation succeeded.
115
116 FIXME: This is not yet a full implementation of the code generator
117 with ISL ASTs. Generation of GIMPLE code is have to be added. */
118
119 bool
120 graphite_regenerate_ast_isl (scop_p scop)
121 {
122 timevar_push (TV_GRAPHITE_CODE_GEN);
123 graphite_regenerate_error = false;
124 isl_ast_node *root_node = scop_to_isl_ast (scop);
125 if (dump_file && (dump_flags & TDF_DETAILS))
126 {
127 fprintf (dump_file, "\nISL AST generated by ISL: \n");
128 print_isl_ast_node (dump_file, root_node, scop->ctx);
129 }
130 isl_ast_node_free (root_node);
131 timevar_pop (TV_GRAPHITE_CODE_GEN);
132 return !graphite_regenerate_error;
133 }