1 /* Translation of ISL AST to Gimple.
2 Copyright (C) 2014 Free Software Foundation, Inc.
3 Contributed by Roman Gareev <gareevroman@gmail.com>.
5 This file is part of GCC.
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)
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.
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/>. */
26 #include <isl/union_map.h>
27 #include <isl/ast_build.h>
31 #include "coretypes.h"
33 #include "basic-block.h"
34 #include "tree-ssa-alias.h"
35 #include "internal-fn.h"
36 #include "gimple-expr.h"
39 #include "gimple-iterator.h"
40 #include "tree-ssa-loop.h"
41 #include "tree-pass.h"
43 #include "tree-data-ref.h"
47 #include "graphite-poly.h"
48 #include "graphite-isl-ast-to-gimple.h"
50 /* This flag is set when an error occurred during the translation of
53 static bool graphite_regenerate_error
;
55 /* Prints NODE to FILE. */
58 print_isl_ast_node (FILE *file
, __isl_keep isl_ast_node
*node
,
59 __isl_keep isl_ctx
*ctx
)
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
);
68 /* Generates a build, which specifies the constraints on the parameters. */
70 static __isl_give isl_ast_build
*
71 generate_isl_context (scop_p scop
)
73 isl_set
*context_isl
= isl_set_params (isl_set_copy (scop
->context
));
74 return isl_ast_build_from_context (context_isl
);
77 /* Generates a schedule, which specifies an order used to
78 visit elements in a domain. */
80 static __isl_give isl_union_map
*
81 generate_isl_schedule (scop_p scop
)
85 isl_union_map
*schedule_isl
=
86 isl_union_map_empty (isl_set_get_space (scop
->context
));
88 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
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
))
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
));
99 isl_union_map_union (schedule_isl
,
100 isl_union_map_from_map (bb_schedule
));
105 static __isl_give isl_ast_node
*
106 scop_to_isl_ast (scop_p scop
)
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
,
112 isl_ast_build_free (context_isl
);
116 /* GIMPLE Loop Generator: generates loops from STMT in GIMPLE form for
117 the given SCOP. Return true if code generation succeeded.
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. */
123 graphite_regenerate_ast_isl (scop_p scop
)
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
))
130 fprintf (dump_file
, "\nISL AST generated by ISL: \n");
131 print_isl_ast_node (dump_file
, root_node
, scop
->ctx
);
133 isl_ast_node_free (root_node
);
134 timevar_pop (TV_GRAPHITE_CODE_GEN
);
135 return !graphite_regenerate_error
;