annotate gcc/graphite-sese-to-poly.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Conversion of SESE regions to Polyhedra.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2009-2020 Free Software Foundation, Inc.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Sebastian Pop <sebastian.pop@amd.com>.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 any later version.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 GNU General Public License for more details.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
111
kono
parents: 67
diff changeset
21 #define USES_ISL
kono
parents: 67
diff changeset
22
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #include "config.h"
111
kono
parents: 67
diff changeset
24
kono
parents: 67
diff changeset
25 #ifdef HAVE_isl
kono
parents: 67
diff changeset
26
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "system.h"
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "coretypes.h"
111
kono
parents: 67
diff changeset
29 #include "backend.h"
kono
parents: 67
diff changeset
30 #include "cfghooks.h"
kono
parents: 67
diff changeset
31 #include "tree.h"
kono
parents: 67
diff changeset
32 #include "gimple.h"
kono
parents: 67
diff changeset
33 #include "ssa.h"
kono
parents: 67
diff changeset
34 #include "fold-const.h"
kono
parents: 67
diff changeset
35 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
36 #include "gimplify.h"
kono
parents: 67
diff changeset
37 #include "gimplify-me.h"
kono
parents: 67
diff changeset
38 #include "tree-cfg.h"
kono
parents: 67
diff changeset
39 #include "tree-ssa-loop-manip.h"
kono
parents: 67
diff changeset
40 #include "tree-ssa-loop-niter.h"
kono
parents: 67
diff changeset
41 #include "tree-ssa-loop.h"
kono
parents: 67
diff changeset
42 #include "tree-into-ssa.h"
kono
parents: 67
diff changeset
43 #include "tree-pass.h"
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 #include "cfgloop.h"
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 #include "tree-data-ref.h"
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 #include "tree-scalar-evolution.h"
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 #include "domwalk.h"
111
kono
parents: 67
diff changeset
48 #include "tree-ssa-propagate.h"
kono
parents: 67
diff changeset
49
kono
parents: 67
diff changeset
50 #include <isl/constraint.h>
kono
parents: 67
diff changeset
51 #include <isl/set.h>
kono
parents: 67
diff changeset
52 #include <isl/map.h>
kono
parents: 67
diff changeset
53 #include <isl/union_map.h>
kono
parents: 67
diff changeset
54 #include <isl/constraint.h>
kono
parents: 67
diff changeset
55 #include <isl/aff.h>
kono
parents: 67
diff changeset
56 #include <isl/val.h>
kono
parents: 67
diff changeset
57
kono
parents: 67
diff changeset
58 #include "graphite.h"
kono
parents: 67
diff changeset
59
kono
parents: 67
diff changeset
60 /* Return an isl identifier for the polyhedral basic block PBB. */
kono
parents: 67
diff changeset
61
kono
parents: 67
diff changeset
62 static isl_id *
kono
parents: 67
diff changeset
63 isl_id_for_pbb (scop_p s, poly_bb_p pbb)
kono
parents: 67
diff changeset
64 {
kono
parents: 67
diff changeset
65 char name[14];
kono
parents: 67
diff changeset
66 snprintf (name, sizeof (name), "S_%d", pbb_index (pbb));
kono
parents: 67
diff changeset
67 return isl_id_alloc (s->isl_context, name, pbb);
kono
parents: 67
diff changeset
68 }
kono
parents: 67
diff changeset
69
kono
parents: 67
diff changeset
70 static isl_pw_aff *extract_affine (scop_p, tree, __isl_take isl_space *space);
kono
parents: 67
diff changeset
71
kono
parents: 67
diff changeset
72 /* Extract an affine expression from the chain of recurrence E. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
111
kono
parents: 67
diff changeset
74 static isl_pw_aff *
kono
parents: 67
diff changeset
75 extract_affine_chrec (scop_p s, tree e, __isl_take isl_space *space)
kono
parents: 67
diff changeset
76 {
kono
parents: 67
diff changeset
77 isl_pw_aff *lhs = extract_affine (s, CHREC_LEFT (e), isl_space_copy (space));
kono
parents: 67
diff changeset
78 isl_pw_aff *rhs = extract_affine (s, CHREC_RIGHT (e), isl_space_copy (space));
kono
parents: 67
diff changeset
79 isl_local_space *ls = isl_local_space_from_space (space);
kono
parents: 67
diff changeset
80 unsigned pos = sese_loop_depth (s->scop_info->region, get_chrec_loop (e)) - 1;
kono
parents: 67
diff changeset
81 isl_aff *loop = isl_aff_set_coefficient_si
kono
parents: 67
diff changeset
82 (isl_aff_zero_on_domain (ls), isl_dim_in, pos, 1);
kono
parents: 67
diff changeset
83 isl_pw_aff *l = isl_pw_aff_from_aff (loop);
kono
parents: 67
diff changeset
84
kono
parents: 67
diff changeset
85 /* Before multiplying, make sure that the result is affine. */
kono
parents: 67
diff changeset
86 gcc_assert (isl_pw_aff_is_cst (rhs)
kono
parents: 67
diff changeset
87 || isl_pw_aff_is_cst (l));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
111
kono
parents: 67
diff changeset
89 return isl_pw_aff_add (lhs, isl_pw_aff_mul (rhs, l));
kono
parents: 67
diff changeset
90 }
kono
parents: 67
diff changeset
91
kono
parents: 67
diff changeset
92 /* Extract an affine expression from the mult_expr E. */
kono
parents: 67
diff changeset
93
kono
parents: 67
diff changeset
94 static isl_pw_aff *
kono
parents: 67
diff changeset
95 extract_affine_mul (scop_p s, tree e, __isl_take isl_space *space)
kono
parents: 67
diff changeset
96 {
kono
parents: 67
diff changeset
97 isl_pw_aff *lhs = extract_affine (s, TREE_OPERAND (e, 0),
kono
parents: 67
diff changeset
98 isl_space_copy (space));
kono
parents: 67
diff changeset
99 isl_pw_aff *rhs = extract_affine (s, TREE_OPERAND (e, 1), space);
kono
parents: 67
diff changeset
100
kono
parents: 67
diff changeset
101 if (!isl_pw_aff_is_cst (lhs)
kono
parents: 67
diff changeset
102 && !isl_pw_aff_is_cst (rhs))
kono
parents: 67
diff changeset
103 {
kono
parents: 67
diff changeset
104 isl_pw_aff_free (lhs);
kono
parents: 67
diff changeset
105 isl_pw_aff_free (rhs);
kono
parents: 67
diff changeset
106 return NULL;
kono
parents: 67
diff changeset
107 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108
111
kono
parents: 67
diff changeset
109 return isl_pw_aff_mul (lhs, rhs);
kono
parents: 67
diff changeset
110 }
kono
parents: 67
diff changeset
111
kono
parents: 67
diff changeset
112 /* Return an isl identifier from the name of the ssa_name E. */
kono
parents: 67
diff changeset
113
kono
parents: 67
diff changeset
114 static isl_id *
kono
parents: 67
diff changeset
115 isl_id_for_ssa_name (scop_p s, tree e)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 {
111
kono
parents: 67
diff changeset
117 char name1[14];
kono
parents: 67
diff changeset
118 snprintf (name1, sizeof (name1), "P_%d", SSA_NAME_VERSION (e));
kono
parents: 67
diff changeset
119 return isl_id_alloc (s->isl_context, name1, e);
kono
parents: 67
diff changeset
120 }
kono
parents: 67
diff changeset
121
kono
parents: 67
diff changeset
122 /* Return an isl identifier for the data reference DR. Data references and
kono
parents: 67
diff changeset
123 scalar references get the same isl_id. They need to be comparable and are
kono
parents: 67
diff changeset
124 distinguished through the first dimension, which contains the alias set or
kono
parents: 67
diff changeset
125 SSA_NAME_VERSION number. */
kono
parents: 67
diff changeset
126
kono
parents: 67
diff changeset
127 static isl_id *
kono
parents: 67
diff changeset
128 isl_id_for_dr (scop_p s)
kono
parents: 67
diff changeset
129 {
kono
parents: 67
diff changeset
130 return isl_id_alloc (s->isl_context, "", 0);
kono
parents: 67
diff changeset
131 }
kono
parents: 67
diff changeset
132
kono
parents: 67
diff changeset
133 /* Extract an affine expression from the ssa_name E. */
kono
parents: 67
diff changeset
134
kono
parents: 67
diff changeset
135 static isl_pw_aff *
kono
parents: 67
diff changeset
136 extract_affine_name (int dimension, __isl_take isl_space *space)
kono
parents: 67
diff changeset
137 {
kono
parents: 67
diff changeset
138 isl_set *dom = isl_set_universe (isl_space_copy (space));
kono
parents: 67
diff changeset
139 isl_aff *aff = isl_aff_zero_on_domain (isl_local_space_from_space (space));
kono
parents: 67
diff changeset
140 aff = isl_aff_add_coefficient_si (aff, isl_dim_param, dimension, 1);
kono
parents: 67
diff changeset
141 return isl_pw_aff_alloc (dom, aff);
kono
parents: 67
diff changeset
142 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
111
kono
parents: 67
diff changeset
144 /* Convert WI to a isl_val with CTX. */
kono
parents: 67
diff changeset
145
kono
parents: 67
diff changeset
146 static __isl_give isl_val *
kono
parents: 67
diff changeset
147 isl_val_int_from_wi (isl_ctx *ctx, const widest_int &wi)
kono
parents: 67
diff changeset
148 {
kono
parents: 67
diff changeset
149 if (wi::neg_p (wi, SIGNED))
kono
parents: 67
diff changeset
150 {
kono
parents: 67
diff changeset
151 widest_int mwi = -wi;
kono
parents: 67
diff changeset
152 return isl_val_neg (isl_val_int_from_chunks (ctx, mwi.get_len (),
kono
parents: 67
diff changeset
153 sizeof (HOST_WIDE_INT),
kono
parents: 67
diff changeset
154 mwi.get_val ()));
kono
parents: 67
diff changeset
155 }
kono
parents: 67
diff changeset
156 return isl_val_int_from_chunks (ctx, wi.get_len (), sizeof (HOST_WIDE_INT),
kono
parents: 67
diff changeset
157 wi.get_val ());
kono
parents: 67
diff changeset
158 }
kono
parents: 67
diff changeset
159
kono
parents: 67
diff changeset
160 /* Extract an affine expression from the gmp constant G. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
161
111
kono
parents: 67
diff changeset
162 static isl_pw_aff *
kono
parents: 67
diff changeset
163 extract_affine_wi (const widest_int &g, __isl_take isl_space *space)
kono
parents: 67
diff changeset
164 {
kono
parents: 67
diff changeset
165 isl_local_space *ls = isl_local_space_from_space (isl_space_copy (space));
kono
parents: 67
diff changeset
166 isl_aff *aff = isl_aff_zero_on_domain (ls);
kono
parents: 67
diff changeset
167 isl_set *dom = isl_set_universe (space);
kono
parents: 67
diff changeset
168 isl_ctx *ct = isl_aff_get_ctx (aff);
kono
parents: 67
diff changeset
169 isl_val *v = isl_val_int_from_wi (ct, g);
kono
parents: 67
diff changeset
170 aff = isl_aff_add_constant_val (aff, v);
kono
parents: 67
diff changeset
171
kono
parents: 67
diff changeset
172 return isl_pw_aff_alloc (dom, aff);
kono
parents: 67
diff changeset
173 }
kono
parents: 67
diff changeset
174
kono
parents: 67
diff changeset
175 /* Extract an affine expression from the integer_cst E. */
kono
parents: 67
diff changeset
176
kono
parents: 67
diff changeset
177 static isl_pw_aff *
kono
parents: 67
diff changeset
178 extract_affine_int (tree e, __isl_take isl_space *space)
kono
parents: 67
diff changeset
179 {
kono
parents: 67
diff changeset
180 isl_pw_aff *res = extract_affine_wi (wi::to_widest (e), space);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
181 return res;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183
111
kono
parents: 67
diff changeset
184 /* Compute pwaff mod 2^width. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185
111
kono
parents: 67
diff changeset
186 static isl_pw_aff *
kono
parents: 67
diff changeset
187 wrap (isl_pw_aff *pwaff, unsigned width)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 {
111
kono
parents: 67
diff changeset
189 isl_val *mod;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
111
kono
parents: 67
diff changeset
191 mod = isl_val_int_from_ui (isl_pw_aff_get_ctx (pwaff), width);
kono
parents: 67
diff changeset
192 mod = isl_val_2exp (mod);
kono
parents: 67
diff changeset
193 pwaff = isl_pw_aff_mod_val (pwaff, mod);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194
111
kono
parents: 67
diff changeset
195 return pwaff;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 /* When parameter NAME is in REGION, returns its index in SESE_PARAMS.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 Otherwise returns -1. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 static inline int
111
kono
parents: 67
diff changeset
202 parameter_index_in_region (tree name, sese_info_p region)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 int i;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 tree p;
111
kono
parents: 67
diff changeset
206 FOR_EACH_VEC_ELT (region->params, i, p)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 if (p == name)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 return i;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 return -1;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
111
kono
parents: 67
diff changeset
212 /* Extract an affine expression from the tree E in the scop S. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213
111
kono
parents: 67
diff changeset
214 static isl_pw_aff *
kono
parents: 67
diff changeset
215 extract_affine (scop_p s, tree e, __isl_take isl_space *space)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 {
111
kono
parents: 67
diff changeset
217 isl_pw_aff *lhs, *rhs, *res;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
111
kono
parents: 67
diff changeset
219 if (e == chrec_dont_know) {
kono
parents: 67
diff changeset
220 isl_space_free (space);
kono
parents: 67
diff changeset
221 return NULL;
kono
parents: 67
diff changeset
222 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223
111
kono
parents: 67
diff changeset
224 tree type = TREE_TYPE (e);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 switch (TREE_CODE (e))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 case POLYNOMIAL_CHREC:
111
kono
parents: 67
diff changeset
228 res = extract_affine_chrec (s, e, space);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 case MULT_EXPR:
111
kono
parents: 67
diff changeset
232 res = extract_affine_mul (s, e, space);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 case POINTER_PLUS_EXPR:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 {
111
kono
parents: 67
diff changeset
237 lhs = extract_affine (s, TREE_OPERAND (e, 0), isl_space_copy (space));
kono
parents: 67
diff changeset
238 /* The RHS of a pointer-plus expression is to be interpreted
kono
parents: 67
diff changeset
239 as signed value. Try to look through a sign-changing conversion
kono
parents: 67
diff changeset
240 first. */
kono
parents: 67
diff changeset
241 tree tem = TREE_OPERAND (e, 1);
kono
parents: 67
diff changeset
242 STRIP_NOPS (tem);
kono
parents: 67
diff changeset
243 rhs = extract_affine (s, tem, space);
kono
parents: 67
diff changeset
244 if (TYPE_UNSIGNED (TREE_TYPE (tem)))
kono
parents: 67
diff changeset
245 rhs = wrap (rhs, TYPE_PRECISION (type) - 1);
kono
parents: 67
diff changeset
246 res = isl_pw_aff_add (lhs, rhs);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249
111
kono
parents: 67
diff changeset
250 case PLUS_EXPR:
kono
parents: 67
diff changeset
251 lhs = extract_affine (s, TREE_OPERAND (e, 0), isl_space_copy (space));
kono
parents: 67
diff changeset
252 rhs = extract_affine (s, TREE_OPERAND (e, 1), space);
kono
parents: 67
diff changeset
253 res = isl_pw_aff_add (lhs, rhs);
kono
parents: 67
diff changeset
254 break;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
111
kono
parents: 67
diff changeset
256 case MINUS_EXPR:
kono
parents: 67
diff changeset
257 lhs = extract_affine (s, TREE_OPERAND (e, 0), isl_space_copy (space));
kono
parents: 67
diff changeset
258 rhs = extract_affine (s, TREE_OPERAND (e, 1), space);
kono
parents: 67
diff changeset
259 res = isl_pw_aff_sub (lhs, rhs);
kono
parents: 67
diff changeset
260 break;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 case BIT_NOT_EXPR:
111
kono
parents: 67
diff changeset
263 lhs = extract_affine (s, integer_minus_one_node, isl_space_copy (space));
kono
parents: 67
diff changeset
264 rhs = extract_affine (s, TREE_OPERAND (e, 0), space);
kono
parents: 67
diff changeset
265 res = isl_pw_aff_sub (lhs, rhs);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
266 /* We need to always wrap the result of a bitwise operation. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
267 return wrap (res, TYPE_PRECISION (type) - (TYPE_UNSIGNED (type) ? 0 : 1));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268
111
kono
parents: 67
diff changeset
269 case NEGATE_EXPR:
kono
parents: 67
diff changeset
270 lhs = extract_affine (s, TREE_OPERAND (e, 0), isl_space_copy (space));
kono
parents: 67
diff changeset
271 rhs = extract_affine (s, integer_minus_one_node, space);
kono
parents: 67
diff changeset
272 res = isl_pw_aff_mul (lhs, rhs);
kono
parents: 67
diff changeset
273 break;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 case SSA_NAME:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 {
111
kono
parents: 67
diff changeset
277 gcc_assert (! defined_in_sese_p (e, s->scop_info->region));
kono
parents: 67
diff changeset
278 int dim = parameter_index_in_region (e, s->scop_info);
kono
parents: 67
diff changeset
279 gcc_assert (dim != -1);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
280 /* No need to wrap a parameter. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
281 return extract_affine_name (dim, space);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 case INTEGER_CST:
111
kono
parents: 67
diff changeset
285 res = extract_affine_int (e, space);
kono
parents: 67
diff changeset
286 /* No need to wrap a single integer. */
kono
parents: 67
diff changeset
287 return res;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 CASE_CONVERT:
111
kono
parents: 67
diff changeset
290 {
kono
parents: 67
diff changeset
291 tree itype = TREE_TYPE (TREE_OPERAND (e, 0));
kono
parents: 67
diff changeset
292 res = extract_affine (s, TREE_OPERAND (e, 0), space);
kono
parents: 67
diff changeset
293 /* Signed values, even if overflow is undefined, get modulo-reduced.
kono
parents: 67
diff changeset
294 But only if not all values of the old type fit in the new. */
kono
parents: 67
diff changeset
295 if (! TYPE_UNSIGNED (type)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
296 && ((TYPE_UNSIGNED (itype)
111
kono
parents: 67
diff changeset
297 && TYPE_PRECISION (type) <= TYPE_PRECISION (itype))
kono
parents: 67
diff changeset
298 || TYPE_PRECISION (type) < TYPE_PRECISION (itype)))
kono
parents: 67
diff changeset
299 res = wrap (res, TYPE_PRECISION (type) - 1);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
300 else if (TYPE_UNSIGNED (type)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
301 && (!TYPE_UNSIGNED (itype)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
302 || TYPE_PRECISION (type) < TYPE_PRECISION (itype)))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
303 res = wrap (res, TYPE_PRECISION (type));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
304 return res;
111
kono
parents: 67
diff changeset
305 }
kono
parents: 67
diff changeset
306
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 case NON_LVALUE_EXPR:
111
kono
parents: 67
diff changeset
308 res = extract_affine (s, TREE_OPERAND (e, 0), space);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310
111
kono
parents: 67
diff changeset
311 default:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 gcc_unreachable ();
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 }
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
315
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
316 /* For all wrapping arithmetic wrap the result. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
317 if (TYPE_OVERFLOW_WRAPS (type))
111
kono
parents: 67
diff changeset
318 res = wrap (res, TYPE_PRECISION (type));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319
111
kono
parents: 67
diff changeset
320 return res;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 /* Returns a linear expression for tree T evaluated in PBB. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324
111
kono
parents: 67
diff changeset
325 static isl_pw_aff *
kono
parents: 67
diff changeset
326 create_pw_aff_from_tree (poly_bb_p pbb, loop_p loop, tree t)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 {
111
kono
parents: 67
diff changeset
328 scop_p scop = PBB_SCOP (pbb);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
330 t = cached_scalar_evolution_in_region (scop->scop_info->region, loop, t);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331
111
kono
parents: 67
diff changeset
332 gcc_assert (!chrec_contains_undetermined (t));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 gcc_assert (!automatically_generated_chrec_p (t));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334
111
kono
parents: 67
diff changeset
335 return extract_affine (scop, t, isl_set_get_space (pbb->domain));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337
111
kono
parents: 67
diff changeset
338 /* Add conditional statement STMT to pbb. CODE is used as the comparison
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 operator. This allows us to invert the condition or to handle
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 inequalities. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 static void
111
kono
parents: 67
diff changeset
343 add_condition_to_pbb (poly_bb_p pbb, gcond *stmt, enum tree_code code)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 {
111
kono
parents: 67
diff changeset
345 loop_p loop = gimple_bb (stmt)->loop_father;
kono
parents: 67
diff changeset
346 isl_pw_aff *lhs = create_pw_aff_from_tree (pbb, loop, gimple_cond_lhs (stmt));
kono
parents: 67
diff changeset
347 isl_pw_aff *rhs = create_pw_aff_from_tree (pbb, loop, gimple_cond_rhs (stmt));
kono
parents: 67
diff changeset
348
kono
parents: 67
diff changeset
349 isl_set *cond;
kono
parents: 67
diff changeset
350 switch (code)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 {
111
kono
parents: 67
diff changeset
352 case LT_EXPR:
kono
parents: 67
diff changeset
353 cond = isl_pw_aff_lt_set (lhs, rhs);
kono
parents: 67
diff changeset
354 break;
kono
parents: 67
diff changeset
355
kono
parents: 67
diff changeset
356 case GT_EXPR:
kono
parents: 67
diff changeset
357 cond = isl_pw_aff_gt_set (lhs, rhs);
kono
parents: 67
diff changeset
358 break;
kono
parents: 67
diff changeset
359
kono
parents: 67
diff changeset
360 case LE_EXPR:
kono
parents: 67
diff changeset
361 cond = isl_pw_aff_le_set (lhs, rhs);
kono
parents: 67
diff changeset
362 break;
kono
parents: 67
diff changeset
363
kono
parents: 67
diff changeset
364 case GE_EXPR:
kono
parents: 67
diff changeset
365 cond = isl_pw_aff_ge_set (lhs, rhs);
kono
parents: 67
diff changeset
366 break;
kono
parents: 67
diff changeset
367
kono
parents: 67
diff changeset
368 case EQ_EXPR:
kono
parents: 67
diff changeset
369 cond = isl_pw_aff_eq_set (lhs, rhs);
kono
parents: 67
diff changeset
370 break;
kono
parents: 67
diff changeset
371
kono
parents: 67
diff changeset
372 case NE_EXPR:
kono
parents: 67
diff changeset
373 cond = isl_pw_aff_ne_set (lhs, rhs);
kono
parents: 67
diff changeset
374 break;
kono
parents: 67
diff changeset
375
kono
parents: 67
diff changeset
376 default:
kono
parents: 67
diff changeset
377 gcc_unreachable ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 }
111
kono
parents: 67
diff changeset
379
kono
parents: 67
diff changeset
380 cond = isl_set_coalesce (cond);
kono
parents: 67
diff changeset
381 cond = isl_set_set_tuple_id (cond, isl_set_get_tuple_id (pbb->domain));
kono
parents: 67
diff changeset
382 pbb->domain = isl_set_coalesce (isl_set_intersect (pbb->domain, cond));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 /* Add conditions to the domain of PBB. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 static void
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 add_conditions_to_domain (poly_bb_p pbb)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 unsigned int i;
111
kono
parents: 67
diff changeset
391 gimple *stmt;
kono
parents: 67
diff changeset
392 gimple_poly_bb_p gbb = PBB_BLACK_BOX (pbb);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
393
111
kono
parents: 67
diff changeset
394 if (GBB_CONDITIONS (gbb).is_empty ())
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 return;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396
111
kono
parents: 67
diff changeset
397 FOR_EACH_VEC_ELT (GBB_CONDITIONS (gbb), i, stmt)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 switch (gimple_code (stmt))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 case GIMPLE_COND:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 {
111
kono
parents: 67
diff changeset
402 /* Don't constrain on anything else than INTEGER_TYPE. */
kono
parents: 67
diff changeset
403 if (TREE_CODE (TREE_TYPE (gimple_cond_lhs (stmt))) != INTEGER_TYPE)
kono
parents: 67
diff changeset
404 break;
kono
parents: 67
diff changeset
405
kono
parents: 67
diff changeset
406 gcond *cond_stmt = as_a <gcond *> (stmt);
kono
parents: 67
diff changeset
407 enum tree_code code = gimple_cond_code (cond_stmt);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 /* The conditions for ELSE-branches are inverted. */
111
kono
parents: 67
diff changeset
410 if (!GBB_CONDITION_CASES (gbb)[i])
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 code = invert_tree_comparison (code, false);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412
111
kono
parents: 67
diff changeset
413 add_condition_to_pbb (pbb, cond_stmt, code);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 default:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 gcc_unreachable ();
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
422
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 /* Add constraints on the possible values of parameter P from the type
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 of P. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 static void
111
kono
parents: 67
diff changeset
427 add_param_constraints (scop_p scop, graphite_dim_t p, tree parameter)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 tree type = TREE_TYPE (parameter);
111
kono
parents: 67
diff changeset
430 wide_int min, max;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
431
111
kono
parents: 67
diff changeset
432 gcc_assert (INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type));
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
433
111
kono
parents: 67
diff changeset
434 if (INTEGRAL_TYPE_P (type)
kono
parents: 67
diff changeset
435 && get_range_info (parameter, &min, &max) == VR_RANGE)
kono
parents: 67
diff changeset
436 ;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
437 else
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 {
111
kono
parents: 67
diff changeset
439 min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
kono
parents: 67
diff changeset
440 max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442
111
kono
parents: 67
diff changeset
443 isl_space *space = isl_set_get_space (scop->param_context);
kono
parents: 67
diff changeset
444 isl_constraint *c = isl_inequality_alloc (isl_local_space_from_space (space));
kono
parents: 67
diff changeset
445 isl_val *v = isl_val_int_from_wi (scop->isl_context,
kono
parents: 67
diff changeset
446 widest_int::from (min, TYPE_SIGN (type)));
kono
parents: 67
diff changeset
447 v = isl_val_neg (v);
kono
parents: 67
diff changeset
448 c = isl_constraint_set_constant_val (c, v);
kono
parents: 67
diff changeset
449 c = isl_constraint_set_coefficient_si (c, isl_dim_param, p, 1);
kono
parents: 67
diff changeset
450 scop->param_context = isl_set_coalesce
kono
parents: 67
diff changeset
451 (isl_set_add_constraint (scop->param_context, c));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452
111
kono
parents: 67
diff changeset
453 space = isl_set_get_space (scop->param_context);
kono
parents: 67
diff changeset
454 c = isl_inequality_alloc (isl_local_space_from_space (space));
kono
parents: 67
diff changeset
455 v = isl_val_int_from_wi (scop->isl_context,
kono
parents: 67
diff changeset
456 widest_int::from (max, TYPE_SIGN (type)));
kono
parents: 67
diff changeset
457 c = isl_constraint_set_constant_val (c, v);
kono
parents: 67
diff changeset
458 c = isl_constraint_set_coefficient_si (c, isl_dim_param, p, -1);
kono
parents: 67
diff changeset
459 scop->param_context = isl_set_coalesce
kono
parents: 67
diff changeset
460 (isl_set_add_constraint (scop->param_context, c));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 /* Add a constrain to the ACCESSES polyhedron for the alias set of
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 data reference DR. ACCESSP_NB_DIMS is the dimension of the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 ACCESSES polyhedron, DOM_NB_DIMS is the dimension of the iteration
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 domain. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467
111
kono
parents: 67
diff changeset
468 static isl_map *
kono
parents: 67
diff changeset
469 pdr_add_alias_set (isl_map *acc, dr_info &dri)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 {
111
kono
parents: 67
diff changeset
471 isl_constraint *c = isl_equality_alloc
kono
parents: 67
diff changeset
472 (isl_local_space_from_space (isl_map_get_space (acc)));
kono
parents: 67
diff changeset
473 /* Positive numbers for all alias sets. */
kono
parents: 67
diff changeset
474 c = isl_constraint_set_constant_si (c, -dri.alias_set);
kono
parents: 67
diff changeset
475 c = isl_constraint_set_coefficient_si (c, isl_dim_out, 0, 1);
kono
parents: 67
diff changeset
476
kono
parents: 67
diff changeset
477 return isl_map_add_constraint (acc, c);
kono
parents: 67
diff changeset
478 }
kono
parents: 67
diff changeset
479
kono
parents: 67
diff changeset
480 /* Assign the affine expression INDEX to the output dimension POS of
kono
parents: 67
diff changeset
481 MAP and return the result. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482
111
kono
parents: 67
diff changeset
483 static isl_map *
kono
parents: 67
diff changeset
484 set_index (isl_map *map, int pos, isl_pw_aff *index)
kono
parents: 67
diff changeset
485 {
kono
parents: 67
diff changeset
486 isl_map *index_map;
kono
parents: 67
diff changeset
487 int len = isl_map_dim (map, isl_dim_out);
kono
parents: 67
diff changeset
488 isl_id *id;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
489
111
kono
parents: 67
diff changeset
490 index_map = isl_map_from_pw_aff (index);
kono
parents: 67
diff changeset
491 index_map = isl_map_insert_dims (index_map, isl_dim_out, 0, pos);
kono
parents: 67
diff changeset
492 index_map = isl_map_add_dims (index_map, isl_dim_out, len - pos - 1);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493
111
kono
parents: 67
diff changeset
494 id = isl_map_get_tuple_id (map, isl_dim_out);
kono
parents: 67
diff changeset
495 index_map = isl_map_set_tuple_id (index_map, isl_dim_out, id);
kono
parents: 67
diff changeset
496 id = isl_map_get_tuple_id (map, isl_dim_in);
kono
parents: 67
diff changeset
497 index_map = isl_map_set_tuple_id (index_map, isl_dim_in, id);
kono
parents: 67
diff changeset
498
kono
parents: 67
diff changeset
499 return isl_map_intersect (map, index_map);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
501
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 /* Add to ACCESSES polyhedron equalities defining the access functions
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 to the memory. ACCESSP_NB_DIMS is the dimension of the ACCESSES
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 polyhedron, DOM_NB_DIMS is the dimension of the iteration domain.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 PBB is the poly_bb_p that contains the data reference DR. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506
111
kono
parents: 67
diff changeset
507 static isl_map *
kono
parents: 67
diff changeset
508 pdr_add_memory_accesses (isl_map *acc, dr_info &dri)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 {
111
kono
parents: 67
diff changeset
510 data_reference_p dr = dri.dr;
kono
parents: 67
diff changeset
511 poly_bb_p pbb = dri.pbb;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 int i, nb_subscripts = DR_NUM_DIMENSIONS (dr);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 scop_p scop = PBB_SCOP (pbb);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 for (i = 0; i < nb_subscripts; i++)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 {
111
kono
parents: 67
diff changeset
517 isl_pw_aff *aff;
kono
parents: 67
diff changeset
518 tree afn = DR_ACCESS_FN (dr, i);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
519
111
kono
parents: 67
diff changeset
520 aff = extract_affine (scop, afn,
kono
parents: 67
diff changeset
521 isl_space_domain (isl_map_get_space (acc)));
kono
parents: 67
diff changeset
522 acc = set_index (acc, nb_subscripts - i , aff);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524
111
kono
parents: 67
diff changeset
525 return isl_map_coalesce (acc);
kono
parents: 67
diff changeset
526 }
kono
parents: 67
diff changeset
527
kono
parents: 67
diff changeset
528 /* Return true when the LOW and HIGH bounds of an array reference REF are valid
kono
parents: 67
diff changeset
529 to extract constraints on accessed elements of the array. Returning false is
kono
parents: 67
diff changeset
530 the conservative answer. */
kono
parents: 67
diff changeset
531
kono
parents: 67
diff changeset
532 static bool
kono
parents: 67
diff changeset
533 bounds_are_valid (tree ref, tree low, tree high)
kono
parents: 67
diff changeset
534 {
kono
parents: 67
diff changeset
535 if (!high)
kono
parents: 67
diff changeset
536 return false;
kono
parents: 67
diff changeset
537
kono
parents: 67
diff changeset
538 if (!tree_fits_shwi_p (low)
kono
parents: 67
diff changeset
539 || !tree_fits_shwi_p (high))
kono
parents: 67
diff changeset
540 return false;
kono
parents: 67
diff changeset
541
kono
parents: 67
diff changeset
542 /* 1-element arrays at end of structures may extend over
kono
parents: 67
diff changeset
543 their declared size. */
kono
parents: 67
diff changeset
544 if (array_at_struct_end_p (ref)
kono
parents: 67
diff changeset
545 && operand_equal_p (low, high, 0))
kono
parents: 67
diff changeset
546 return false;
kono
parents: 67
diff changeset
547
kono
parents: 67
diff changeset
548 /* Fortran has some arrays where high bound is -1 and low is 0. */
kono
parents: 67
diff changeset
549 if (integer_onep (fold_build2 (LT_EXPR, boolean_type_node, high, low)))
kono
parents: 67
diff changeset
550 return false;
kono
parents: 67
diff changeset
551
kono
parents: 67
diff changeset
552 return true;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
554
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 /* Add constrains representing the size of the accessed data to the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 ACCESSES polyhedron. ACCESSP_NB_DIMS is the dimension of the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 ACCESSES polyhedron, DOM_NB_DIMS is the dimension of the iteration
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 domain. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
559
111
kono
parents: 67
diff changeset
560 static isl_set *
kono
parents: 67
diff changeset
561 pdr_add_data_dimensions (isl_set *subscript_sizes, scop_p scop,
kono
parents: 67
diff changeset
562 data_reference_p dr)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 tree ref = DR_REF (dr);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
565
111
kono
parents: 67
diff changeset
566 int nb_subscripts = DR_NUM_DIMENSIONS (dr);
kono
parents: 67
diff changeset
567 for (int i = nb_subscripts - 1; i >= 0; i--, ref = TREE_OPERAND (ref, 0))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 if (TREE_CODE (ref) != ARRAY_REF)
111
kono
parents: 67
diff changeset
570 return subscript_sizes;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
571
111
kono
parents: 67
diff changeset
572 tree low = array_ref_low_bound (ref);
kono
parents: 67
diff changeset
573 tree high = array_ref_up_bound (ref);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
574
111
kono
parents: 67
diff changeset
575 if (!bounds_are_valid (ref, low, high))
kono
parents: 67
diff changeset
576 continue;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
577
111
kono
parents: 67
diff changeset
578 isl_space *space = isl_set_get_space (subscript_sizes);
kono
parents: 67
diff changeset
579 isl_pw_aff *lb = extract_affine_int (low, isl_space_copy (space));
kono
parents: 67
diff changeset
580 isl_pw_aff *ub = extract_affine_int (high, isl_space_copy (space));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
581
111
kono
parents: 67
diff changeset
582 /* high >= 0 */
kono
parents: 67
diff changeset
583 isl_set *valid = isl_pw_aff_nonneg_set (isl_pw_aff_copy (ub));
kono
parents: 67
diff changeset
584 valid = isl_set_project_out (valid, isl_dim_set, 0,
kono
parents: 67
diff changeset
585 isl_set_dim (valid, isl_dim_set));
kono
parents: 67
diff changeset
586 scop->param_context = isl_set_coalesce
kono
parents: 67
diff changeset
587 (isl_set_intersect (scop->param_context, valid));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
588
111
kono
parents: 67
diff changeset
589 isl_aff *aff
kono
parents: 67
diff changeset
590 = isl_aff_zero_on_domain (isl_local_space_from_space (space));
kono
parents: 67
diff changeset
591 aff = isl_aff_add_coefficient_si (aff, isl_dim_in, i + 1, 1);
kono
parents: 67
diff changeset
592 isl_set *univ
kono
parents: 67
diff changeset
593 = isl_set_universe (isl_space_domain (isl_aff_get_space (aff)));
kono
parents: 67
diff changeset
594 isl_pw_aff *index = isl_pw_aff_alloc (univ, aff);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
595
111
kono
parents: 67
diff changeset
596 isl_id *id = isl_set_get_tuple_id (subscript_sizes);
kono
parents: 67
diff changeset
597 lb = isl_pw_aff_set_tuple_id (lb, isl_dim_in, isl_id_copy (id));
kono
parents: 67
diff changeset
598 ub = isl_pw_aff_set_tuple_id (ub, isl_dim_in, id);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
599
111
kono
parents: 67
diff changeset
600 /* low <= sub_i <= high */
kono
parents: 67
diff changeset
601 isl_set *lbs = isl_pw_aff_ge_set (isl_pw_aff_copy (index), lb);
kono
parents: 67
diff changeset
602 isl_set *ubs = isl_pw_aff_le_set (index, ub);
kono
parents: 67
diff changeset
603 subscript_sizes = isl_set_intersect (subscript_sizes, lbs);
kono
parents: 67
diff changeset
604 subscript_sizes = isl_set_intersect (subscript_sizes, ubs);
kono
parents: 67
diff changeset
605 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
606
111
kono
parents: 67
diff changeset
607 return isl_set_coalesce (subscript_sizes);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
609
111
kono
parents: 67
diff changeset
610 /* Build data accesses for DRI. */
kono
parents: 67
diff changeset
611
kono
parents: 67
diff changeset
612 static void
kono
parents: 67
diff changeset
613 build_poly_dr (dr_info &dri)
kono
parents: 67
diff changeset
614 {
kono
parents: 67
diff changeset
615 isl_map *acc;
kono
parents: 67
diff changeset
616 isl_set *subscript_sizes;
kono
parents: 67
diff changeset
617 poly_bb_p pbb = dri.pbb;
kono
parents: 67
diff changeset
618 data_reference_p dr = dri.dr;
kono
parents: 67
diff changeset
619 scop_p scop = PBB_SCOP (pbb);
kono
parents: 67
diff changeset
620 isl_id *id = isl_id_for_dr (scop);
kono
parents: 67
diff changeset
621
kono
parents: 67
diff changeset
622 {
kono
parents: 67
diff changeset
623 isl_space *dc = isl_set_get_space (pbb->domain);
kono
parents: 67
diff changeset
624 int nb_out = 1 + DR_NUM_DIMENSIONS (dr);
kono
parents: 67
diff changeset
625 isl_space *space = isl_space_add_dims (isl_space_from_domain (dc),
kono
parents: 67
diff changeset
626 isl_dim_out, nb_out);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
627
111
kono
parents: 67
diff changeset
628 acc = isl_map_universe (space);
kono
parents: 67
diff changeset
629 acc = isl_map_set_tuple_id (acc, isl_dim_out, isl_id_copy (id));
kono
parents: 67
diff changeset
630 }
kono
parents: 67
diff changeset
631
kono
parents: 67
diff changeset
632 acc = pdr_add_alias_set (acc, dri);
kono
parents: 67
diff changeset
633 acc = pdr_add_memory_accesses (acc, dri);
kono
parents: 67
diff changeset
634
kono
parents: 67
diff changeset
635 {
kono
parents: 67
diff changeset
636 int nb = 1 + DR_NUM_DIMENSIONS (dr);
kono
parents: 67
diff changeset
637 isl_space *space = isl_space_set_alloc (scop->isl_context, 0, nb);
kono
parents: 67
diff changeset
638
kono
parents: 67
diff changeset
639 space = isl_space_set_tuple_id (space, isl_dim_set, id);
kono
parents: 67
diff changeset
640 subscript_sizes = isl_set_nat_universe (space);
kono
parents: 67
diff changeset
641 subscript_sizes = isl_set_fix_si (subscript_sizes, isl_dim_set, 0,
kono
parents: 67
diff changeset
642 dri.alias_set);
kono
parents: 67
diff changeset
643 subscript_sizes = pdr_add_data_dimensions (subscript_sizes, scop, dr);
kono
parents: 67
diff changeset
644 }
kono
parents: 67
diff changeset
645
kono
parents: 67
diff changeset
646 new_poly_dr (pbb, DR_STMT (dr), DR_IS_READ (dr) ? PDR_READ : PDR_WRITE,
kono
parents: 67
diff changeset
647 acc, subscript_sizes);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
649
111
kono
parents: 67
diff changeset
650 static void
kono
parents: 67
diff changeset
651 build_poly_sr_1 (poly_bb_p pbb, gimple *stmt, tree var, enum poly_dr_type kind,
kono
parents: 67
diff changeset
652 isl_map *acc, isl_set *subscript_sizes)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 {
111
kono
parents: 67
diff changeset
654 scop_p scop = PBB_SCOP (pbb);
kono
parents: 67
diff changeset
655 /* Each scalar variables has a unique alias set number starting from
kono
parents: 67
diff changeset
656 the maximum alias set assigned to a dr. */
kono
parents: 67
diff changeset
657 int alias_set = scop->max_alias_set + SSA_NAME_VERSION (var);
kono
parents: 67
diff changeset
658 subscript_sizes = isl_set_fix_si (subscript_sizes, isl_dim_set, 0,
kono
parents: 67
diff changeset
659 alias_set);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
660
111
kono
parents: 67
diff changeset
661 /* Add a constrain to the ACCESSES polyhedron for the alias set of
kono
parents: 67
diff changeset
662 data reference DR. */
kono
parents: 67
diff changeset
663 isl_constraint *c
kono
parents: 67
diff changeset
664 = isl_equality_alloc (isl_local_space_from_space (isl_map_get_space (acc)));
kono
parents: 67
diff changeset
665 c = isl_constraint_set_constant_si (c, -alias_set);
kono
parents: 67
diff changeset
666 c = isl_constraint_set_coefficient_si (c, isl_dim_out, 0, 1);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
667
111
kono
parents: 67
diff changeset
668 new_poly_dr (pbb, stmt, kind, isl_map_add_constraint (acc, c),
kono
parents: 67
diff changeset
669 subscript_sizes);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
671
111
kono
parents: 67
diff changeset
672 /* Record all cross basic block scalar variables in PBB. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
673
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 static void
111
kono
parents: 67
diff changeset
675 build_poly_sr (poly_bb_p pbb)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 {
111
kono
parents: 67
diff changeset
677 scop_p scop = PBB_SCOP (pbb);
kono
parents: 67
diff changeset
678 gimple_poly_bb_p gbb = PBB_BLACK_BOX (pbb);
kono
parents: 67
diff changeset
679 vec<scalar_use> &reads = gbb->read_scalar_refs;
kono
parents: 67
diff changeset
680 vec<tree> &writes = gbb->write_scalar_refs;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
681
111
kono
parents: 67
diff changeset
682 isl_space *dc = isl_set_get_space (pbb->domain);
kono
parents: 67
diff changeset
683 int nb_out = 1;
kono
parents: 67
diff changeset
684 isl_space *space = isl_space_add_dims (isl_space_from_domain (dc),
kono
parents: 67
diff changeset
685 isl_dim_out, nb_out);
kono
parents: 67
diff changeset
686 isl_id *id = isl_id_for_dr (scop);
kono
parents: 67
diff changeset
687 space = isl_space_set_tuple_id (space, isl_dim_set, isl_id_copy (id));
kono
parents: 67
diff changeset
688 isl_map *acc = isl_map_universe (isl_space_copy (space));
kono
parents: 67
diff changeset
689 acc = isl_map_set_tuple_id (acc, isl_dim_out, id);
kono
parents: 67
diff changeset
690 isl_set *subscript_sizes = isl_set_nat_universe (space);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
691
111
kono
parents: 67
diff changeset
692 int i;
kono
parents: 67
diff changeset
693 tree var;
kono
parents: 67
diff changeset
694 FOR_EACH_VEC_ELT (writes, i, var)
kono
parents: 67
diff changeset
695 build_poly_sr_1 (pbb, SSA_NAME_DEF_STMT (var), var, PDR_WRITE,
kono
parents: 67
diff changeset
696 isl_map_copy (acc), isl_set_copy (subscript_sizes));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
697
111
kono
parents: 67
diff changeset
698 scalar_use *use;
kono
parents: 67
diff changeset
699 FOR_EACH_VEC_ELT (reads, i, use)
kono
parents: 67
diff changeset
700 build_poly_sr_1 (pbb, use->first, use->second, PDR_READ, isl_map_copy (acc),
kono
parents: 67
diff changeset
701 isl_set_copy (subscript_sizes));
kono
parents: 67
diff changeset
702
kono
parents: 67
diff changeset
703 isl_map_free (acc);
kono
parents: 67
diff changeset
704 isl_set_free (subscript_sizes);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
706
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 /* Build data references in SCOP. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
708
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 static void
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 build_scop_drs (scop_p scop)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 {
111
kono
parents: 67
diff changeset
712 int i;
kono
parents: 67
diff changeset
713 dr_info *dri;
kono
parents: 67
diff changeset
714 FOR_EACH_VEC_ELT (scop->drs, i, dri)
kono
parents: 67
diff changeset
715 build_poly_dr (*dri);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
716
111
kono
parents: 67
diff changeset
717 poly_bb_p pbb;
kono
parents: 67
diff changeset
718 FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
kono
parents: 67
diff changeset
719 build_poly_sr (pbb);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
721
111
kono
parents: 67
diff changeset
722 /* Add to the iteration DOMAIN one extra dimension for LOOP->num. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
723
111
kono
parents: 67
diff changeset
724 static isl_set *
kono
parents: 67
diff changeset
725 add_iter_domain_dimension (__isl_take isl_set *domain, loop_p loop, scop_p scop)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
726 {
111
kono
parents: 67
diff changeset
727 int loop_index = isl_set_dim (domain, isl_dim_set);
kono
parents: 67
diff changeset
728 domain = isl_set_add_dims (domain, isl_dim_set, 1);
kono
parents: 67
diff changeset
729 char name[50];
kono
parents: 67
diff changeset
730 snprintf (name, sizeof(name), "i%d", loop->num);
kono
parents: 67
diff changeset
731 isl_id *label = isl_id_alloc (scop->isl_context, name, NULL);
kono
parents: 67
diff changeset
732 return isl_set_set_dim_id (domain, isl_dim_set, loop_index, label);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
733 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
734
111
kono
parents: 67
diff changeset
735 /* Add constraints to DOMAIN for each loop from LOOP up to CONTEXT. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
736
111
kono
parents: 67
diff changeset
737 static isl_set *
kono
parents: 67
diff changeset
738 add_loop_constraints (scop_p scop, __isl_take isl_set *domain, loop_p loop,
kono
parents: 67
diff changeset
739 loop_p context)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 {
111
kono
parents: 67
diff changeset
741 if (loop == context)
kono
parents: 67
diff changeset
742 return domain;
kono
parents: 67
diff changeset
743 const sese_l &region = scop->scop_info->region;
kono
parents: 67
diff changeset
744 if (!loop_in_sese_p (loop, region))
kono
parents: 67
diff changeset
745 return domain;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
746
111
kono
parents: 67
diff changeset
747 /* Recursion all the way up to the context loop. */
kono
parents: 67
diff changeset
748 domain = add_loop_constraints (scop, domain, loop_outer (loop), context);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
749
111
kono
parents: 67
diff changeset
750 /* Then, build constraints over the loop in post-order: outer to inner. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
751
111
kono
parents: 67
diff changeset
752 int loop_index = isl_set_dim (domain, isl_dim_set);
kono
parents: 67
diff changeset
753 if (dump_file)
kono
parents: 67
diff changeset
754 fprintf (dump_file, "[sese-to-poly] adding one extra dimension to the "
kono
parents: 67
diff changeset
755 "domain for loop_%d.\n", loop->num);
kono
parents: 67
diff changeset
756 domain = add_iter_domain_dimension (domain, loop, scop);
kono
parents: 67
diff changeset
757 isl_space *space = isl_set_get_space (domain);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
758
111
kono
parents: 67
diff changeset
759 /* 0 <= loop_i */
kono
parents: 67
diff changeset
760 isl_local_space *ls = isl_local_space_from_space (isl_space_copy (space));
kono
parents: 67
diff changeset
761 isl_constraint *c = isl_inequality_alloc (ls);
kono
parents: 67
diff changeset
762 c = isl_constraint_set_coefficient_si (c, isl_dim_set, loop_index, 1);
kono
parents: 67
diff changeset
763 if (dump_file)
kono
parents: 67
diff changeset
764 {
kono
parents: 67
diff changeset
765 fprintf (dump_file, "[sese-to-poly] adding constraint to the domain: ");
kono
parents: 67
diff changeset
766 print_isl_constraint (dump_file, c);
kono
parents: 67
diff changeset
767 }
kono
parents: 67
diff changeset
768 domain = isl_set_add_constraint (domain, c);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
769
111
kono
parents: 67
diff changeset
770 tree nb_iters = number_of_latch_executions (loop);
kono
parents: 67
diff changeset
771 if (TREE_CODE (nb_iters) == INTEGER_CST)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
772 {
111
kono
parents: 67
diff changeset
773 /* loop_i <= cst_nb_iters */
kono
parents: 67
diff changeset
774 isl_local_space *ls = isl_local_space_from_space (space);
kono
parents: 67
diff changeset
775 isl_constraint *c = isl_inequality_alloc (ls);
kono
parents: 67
diff changeset
776 c = isl_constraint_set_coefficient_si (c, isl_dim_set, loop_index, -1);
kono
parents: 67
diff changeset
777 isl_val *v
kono
parents: 67
diff changeset
778 = isl_val_int_from_wi (scop->isl_context, wi::to_widest (nb_iters));
kono
parents: 67
diff changeset
779 c = isl_constraint_set_constant_val (c, v);
kono
parents: 67
diff changeset
780 return isl_set_add_constraint (domain, c);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
781 }
111
kono
parents: 67
diff changeset
782 /* loop_i <= expr_nb_iters */
kono
parents: 67
diff changeset
783 gcc_assert (!chrec_contains_undetermined (nb_iters));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
784 nb_iters = cached_scalar_evolution_in_region (region, loop, nb_iters);
111
kono
parents: 67
diff changeset
785 gcc_assert (!chrec_contains_undetermined (nb_iters));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
786
111
kono
parents: 67
diff changeset
787 isl_pw_aff *aff_nb_iters = extract_affine (scop, nb_iters,
kono
parents: 67
diff changeset
788 isl_space_copy (space));
kono
parents: 67
diff changeset
789 isl_set *valid = isl_pw_aff_nonneg_set (isl_pw_aff_copy (aff_nb_iters));
kono
parents: 67
diff changeset
790 valid = isl_set_project_out (valid, isl_dim_set, 0,
kono
parents: 67
diff changeset
791 isl_set_dim (valid, isl_dim_set));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
792
111
kono
parents: 67
diff changeset
793 if (valid)
kono
parents: 67
diff changeset
794 scop->param_context = isl_set_intersect (scop->param_context, valid);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
795
111
kono
parents: 67
diff changeset
796 ls = isl_local_space_from_space (isl_space_copy (space));
kono
parents: 67
diff changeset
797 isl_aff *loop_i = isl_aff_set_coefficient_si (isl_aff_zero_on_domain (ls),
kono
parents: 67
diff changeset
798 isl_dim_in, loop_index, 1);
kono
parents: 67
diff changeset
799 isl_set *le = isl_pw_aff_le_set (isl_pw_aff_from_aff (loop_i),
kono
parents: 67
diff changeset
800 isl_pw_aff_copy (aff_nb_iters));
kono
parents: 67
diff changeset
801 if (dump_file)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
802 {
111
kono
parents: 67
diff changeset
803 fprintf (dump_file, "[sese-to-poly] adding constraint to the domain: ");
kono
parents: 67
diff changeset
804 print_isl_set (dump_file, le);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
805 }
111
kono
parents: 67
diff changeset
806 domain = isl_set_intersect (domain, le);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
807
111
kono
parents: 67
diff changeset
808 widest_int nit;
kono
parents: 67
diff changeset
809 if (!max_stmt_executions (loop, &nit))
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
810 {
111
kono
parents: 67
diff changeset
811 isl_pw_aff_free (aff_nb_iters);
kono
parents: 67
diff changeset
812 isl_space_free (space);
kono
parents: 67
diff changeset
813 return domain;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
814 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
815
111
kono
parents: 67
diff changeset
816 /* NIT is an upper bound to NB_ITERS: "NIT >= NB_ITERS", although we
kono
parents: 67
diff changeset
817 do not know whether the loop executes at least once. */
kono
parents: 67
diff changeset
818 --nit;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
819
111
kono
parents: 67
diff changeset
820 isl_pw_aff *approx = extract_affine_wi (nit, isl_space_copy (space));
kono
parents: 67
diff changeset
821 isl_set *x = isl_pw_aff_ge_set (approx, aff_nb_iters);
kono
parents: 67
diff changeset
822 x = isl_set_project_out (x, isl_dim_set, 0,
kono
parents: 67
diff changeset
823 isl_set_dim (x, isl_dim_set));
kono
parents: 67
diff changeset
824 scop->param_context = isl_set_intersect (scop->param_context, x);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
825
111
kono
parents: 67
diff changeset
826 ls = isl_local_space_from_space (space);
kono
parents: 67
diff changeset
827 c = isl_inequality_alloc (ls);
kono
parents: 67
diff changeset
828 c = isl_constraint_set_coefficient_si (c, isl_dim_set, loop_index, -1);
kono
parents: 67
diff changeset
829 isl_val *v = isl_val_int_from_wi (scop->isl_context, nit);
kono
parents: 67
diff changeset
830 c = isl_constraint_set_constant_val (c, v);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
831
111
kono
parents: 67
diff changeset
832 if (dump_file)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 {
111
kono
parents: 67
diff changeset
834 fprintf (dump_file, "[sese-to-poly] adding constraint to the domain: ");
kono
parents: 67
diff changeset
835 print_isl_constraint (dump_file, c);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
837
111
kono
parents: 67
diff changeset
838 return isl_set_add_constraint (domain, c);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
840
111
kono
parents: 67
diff changeset
841 /* Builds the original iteration domains for each pbb in the SCOP. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
842
111
kono
parents: 67
diff changeset
843 static int
kono
parents: 67
diff changeset
844 build_iteration_domains (scop_p scop, __isl_keep isl_set *context,
kono
parents: 67
diff changeset
845 int index, loop_p context_loop)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
846 {
111
kono
parents: 67
diff changeset
847 loop_p current = pbb_loop (scop->pbbs[index]);
kono
parents: 67
diff changeset
848 isl_set *domain = isl_set_copy (context);
kono
parents: 67
diff changeset
849 domain = add_loop_constraints (scop, domain, current, context_loop);
kono
parents: 67
diff changeset
850 const sese_l &region = scop->scop_info->region;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
851
111
kono
parents: 67
diff changeset
852 int i;
kono
parents: 67
diff changeset
853 poly_bb_p pbb;
kono
parents: 67
diff changeset
854 FOR_EACH_VEC_ELT_FROM (scop->pbbs, i, pbb, index)
kono
parents: 67
diff changeset
855 {
kono
parents: 67
diff changeset
856 loop_p loop = pbb_loop (pbb);
kono
parents: 67
diff changeset
857 if (current == loop)
kono
parents: 67
diff changeset
858 {
kono
parents: 67
diff changeset
859 pbb->iterators = isl_set_copy (domain);
kono
parents: 67
diff changeset
860 pbb->domain = isl_set_copy (domain);
kono
parents: 67
diff changeset
861 pbb->domain = isl_set_set_tuple_id (pbb->domain,
kono
parents: 67
diff changeset
862 isl_id_for_pbb (scop, pbb));
kono
parents: 67
diff changeset
863 add_conditions_to_domain (pbb);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
864
111
kono
parents: 67
diff changeset
865 if (dump_file)
kono
parents: 67
diff changeset
866 {
kono
parents: 67
diff changeset
867 fprintf (dump_file, "[sese-to-poly] set pbb_%d->domain: ",
kono
parents: 67
diff changeset
868 pbb_index (pbb));
kono
parents: 67
diff changeset
869 print_isl_set (dump_file, domain);
kono
parents: 67
diff changeset
870 }
kono
parents: 67
diff changeset
871 continue;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
873
111
kono
parents: 67
diff changeset
874 while (loop_in_sese_p (loop, region)
kono
parents: 67
diff changeset
875 && current != loop)
kono
parents: 67
diff changeset
876 loop = loop_outer (loop);
kono
parents: 67
diff changeset
877
kono
parents: 67
diff changeset
878 if (current != loop)
kono
parents: 67
diff changeset
879 {
kono
parents: 67
diff changeset
880 /* A statement in a different loop nest than CURRENT loop. */
kono
parents: 67
diff changeset
881 isl_set_free (domain);
kono
parents: 67
diff changeset
882 return i;
kono
parents: 67
diff changeset
883 }
kono
parents: 67
diff changeset
884
kono
parents: 67
diff changeset
885 /* A statement nested in the CURRENT loop. */
kono
parents: 67
diff changeset
886 i = build_iteration_domains (scop, domain, i, current);
kono
parents: 67
diff changeset
887 i--;
kono
parents: 67
diff changeset
888 }
kono
parents: 67
diff changeset
889
kono
parents: 67
diff changeset
890 isl_set_free (domain);
kono
parents: 67
diff changeset
891 return i;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
892 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
893
111
kono
parents: 67
diff changeset
894 /* Assign dimension for each parameter in SCOP and add constraints for the
kono
parents: 67
diff changeset
895 parameters. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
896
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
897 static void
111
kono
parents: 67
diff changeset
898 build_scop_context (scop_p scop)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
899 {
111
kono
parents: 67
diff changeset
900 sese_info_p region = scop->scop_info;
kono
parents: 67
diff changeset
901 unsigned nbp = sese_nb_params (region);
kono
parents: 67
diff changeset
902 isl_space *space = isl_space_set_alloc (scop->isl_context, nbp, 0);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
903
111
kono
parents: 67
diff changeset
904 unsigned i;
kono
parents: 67
diff changeset
905 tree e;
kono
parents: 67
diff changeset
906 FOR_EACH_VEC_ELT (region->params, i, e)
kono
parents: 67
diff changeset
907 space = isl_space_set_dim_id (space, isl_dim_param, i,
kono
parents: 67
diff changeset
908 isl_id_for_ssa_name (scop, e));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
909
111
kono
parents: 67
diff changeset
910 scop->param_context = isl_set_universe (space);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
911
111
kono
parents: 67
diff changeset
912 FOR_EACH_VEC_ELT (region->params, i, e)
kono
parents: 67
diff changeset
913 add_param_constraints (scop, i, e);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
914 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
915
111
kono
parents: 67
diff changeset
916 /* Return true when loop A is nested in loop B. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
917
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
918 static bool
111
kono
parents: 67
diff changeset
919 nested_in (loop_p a, loop_p b)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
920 {
111
kono
parents: 67
diff changeset
921 return b == find_common_loop (a, b);
kono
parents: 67
diff changeset
922 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
923
111
kono
parents: 67
diff changeset
924 /* Return the loop at a specific SCOP->pbbs[*INDEX]. */
kono
parents: 67
diff changeset
925 static loop_p
kono
parents: 67
diff changeset
926 loop_at (scop_p scop, int *index)
kono
parents: 67
diff changeset
927 {
kono
parents: 67
diff changeset
928 return pbb_loop (scop->pbbs[*index]);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
929 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
930
111
kono
parents: 67
diff changeset
931 /* Return the index of any pbb belonging to loop or a subloop of A. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
932
111
kono
parents: 67
diff changeset
933 static int
kono
parents: 67
diff changeset
934 index_outermost_in_loop (loop_p a, scop_p scop)
kono
parents: 67
diff changeset
935 {
kono
parents: 67
diff changeset
936 int i, outermost = -1;
kono
parents: 67
diff changeset
937 int last_depth = -1;
kono
parents: 67
diff changeset
938 poly_bb_p pbb;
kono
parents: 67
diff changeset
939 FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
kono
parents: 67
diff changeset
940 if (nested_in (pbb_loop (pbb), a)
kono
parents: 67
diff changeset
941 && (last_depth == -1
kono
parents: 67
diff changeset
942 || last_depth > (int) loop_depth (pbb_loop (pbb))))
kono
parents: 67
diff changeset
943 {
kono
parents: 67
diff changeset
944 outermost = i;
kono
parents: 67
diff changeset
945 last_depth = loop_depth (pbb_loop (pbb));
kono
parents: 67
diff changeset
946 }
kono
parents: 67
diff changeset
947 return outermost;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
949
111
kono
parents: 67
diff changeset
950 /* Return the index of any pbb belonging to loop or a subloop of A. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
951
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
952 static int
111
kono
parents: 67
diff changeset
953 index_pbb_in_loop (loop_p a, scop_p scop)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 int i;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
956 poly_bb_p pbb;
111
kono
parents: 67
diff changeset
957 FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
kono
parents: 67
diff changeset
958 if (pbb_loop (pbb) == a)
kono
parents: 67
diff changeset
959 return i;
kono
parents: 67
diff changeset
960 return -1;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
961 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
962
111
kono
parents: 67
diff changeset
963 static poly_bb_p
kono
parents: 67
diff changeset
964 outermost_pbb_in (loop_p loop, scop_p scop)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 {
111
kono
parents: 67
diff changeset
966 int x = index_pbb_in_loop (loop, scop);
kono
parents: 67
diff changeset
967 if (x == -1)
kono
parents: 67
diff changeset
968 x = index_outermost_in_loop (loop, scop);
kono
parents: 67
diff changeset
969 return scop->pbbs[x];
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
970 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
971
111
kono
parents: 67
diff changeset
972 static isl_schedule *
kono
parents: 67
diff changeset
973 add_in_sequence (__isl_take isl_schedule *a, __isl_take isl_schedule *b)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 {
111
kono
parents: 67
diff changeset
975 gcc_assert (a || b);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
976
111
kono
parents: 67
diff changeset
977 if (!a)
kono
parents: 67
diff changeset
978 return b;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
979
111
kono
parents: 67
diff changeset
980 if (!b)
kono
parents: 67
diff changeset
981 return a;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
982
111
kono
parents: 67
diff changeset
983 return isl_schedule_sequence (a, b);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
985
111
kono
parents: 67
diff changeset
986 struct map_to_dimension_data {
kono
parents: 67
diff changeset
987 int n;
kono
parents: 67
diff changeset
988 isl_union_pw_multi_aff *res;
kono
parents: 67
diff changeset
989 };
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
990
111
kono
parents: 67
diff changeset
991 /* Create a function that maps the elements of SET to its N-th dimension and add
kono
parents: 67
diff changeset
992 it to USER->res. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
993
111
kono
parents: 67
diff changeset
994 static isl_stat
kono
parents: 67
diff changeset
995 add_outer_projection (__isl_take isl_set *set, void *user)
kono
parents: 67
diff changeset
996 {
kono
parents: 67
diff changeset
997 struct map_to_dimension_data *data = (struct map_to_dimension_data *) user;
kono
parents: 67
diff changeset
998 int dim = isl_set_dim (set, isl_dim_set);
kono
parents: 67
diff changeset
999 isl_space *space = isl_set_get_space (set);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000
111
kono
parents: 67
diff changeset
1001 gcc_assert (dim >= data->n);
kono
parents: 67
diff changeset
1002 isl_pw_multi_aff *pma
kono
parents: 67
diff changeset
1003 = isl_pw_multi_aff_project_out_map (space, isl_dim_set, data->n,
kono
parents: 67
diff changeset
1004 dim - data->n);
kono
parents: 67
diff changeset
1005 data->res = isl_union_pw_multi_aff_add_pw_multi_aff (data->res, pma);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006
111
kono
parents: 67
diff changeset
1007 isl_set_free (set);
kono
parents: 67
diff changeset
1008 return isl_stat_ok;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1009 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010
111
kono
parents: 67
diff changeset
1011 /* Return SET in which all inner dimensions above N are removed. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012
111
kono
parents: 67
diff changeset
1013 static isl_multi_union_pw_aff *
kono
parents: 67
diff changeset
1014 outer_projection_mupa (__isl_take isl_union_set *set, int n)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015 {
111
kono
parents: 67
diff changeset
1016 gcc_assert (n >= 0);
kono
parents: 67
diff changeset
1017 gcc_assert (set);
kono
parents: 67
diff changeset
1018 gcc_assert (!isl_union_set_is_empty (set));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019
111
kono
parents: 67
diff changeset
1020 isl_space *space = isl_union_set_get_space (set);
kono
parents: 67
diff changeset
1021 isl_union_pw_multi_aff *pwaff = isl_union_pw_multi_aff_empty (space);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1022
111
kono
parents: 67
diff changeset
1023 struct map_to_dimension_data data = {n, pwaff};
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024
111
kono
parents: 67
diff changeset
1025 if (isl_union_set_foreach_set (set, &add_outer_projection, &data) < 0)
kono
parents: 67
diff changeset
1026 data.res = isl_union_pw_multi_aff_free (data.res);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027
111
kono
parents: 67
diff changeset
1028 isl_union_set_free (set);
kono
parents: 67
diff changeset
1029 return isl_multi_union_pw_aff_from_union_pw_multi_aff (data.res);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1031
111
kono
parents: 67
diff changeset
1032 /* Embed SCHEDULE in the constraints of the LOOP domain. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033
111
kono
parents: 67
diff changeset
1034 static isl_schedule *
kono
parents: 67
diff changeset
1035 add_loop_schedule (__isl_take isl_schedule *schedule, loop_p loop,
kono
parents: 67
diff changeset
1036 scop_p scop)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 {
111
kono
parents: 67
diff changeset
1038 poly_bb_p pbb = outermost_pbb_in (loop, scop);
kono
parents: 67
diff changeset
1039 isl_set *iterators = pbb->iterators;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040
111
kono
parents: 67
diff changeset
1041 int empty = isl_set_is_empty (iterators);
kono
parents: 67
diff changeset
1042 if (empty < 0 || empty)
kono
parents: 67
diff changeset
1043 return empty < 0 ? isl_schedule_free (schedule) : schedule;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1044
111
kono
parents: 67
diff changeset
1045 isl_union_set *domain = isl_schedule_get_domain (schedule);
kono
parents: 67
diff changeset
1046 /* We cannot apply an empty domain to pbbs in this loop so return early. */
kono
parents: 67
diff changeset
1047 if (isl_union_set_is_empty (domain))
kono
parents: 67
diff changeset
1048 {
kono
parents: 67
diff changeset
1049 isl_union_set_free (domain);
kono
parents: 67
diff changeset
1050 return schedule;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052
111
kono
parents: 67
diff changeset
1053 isl_space *space = isl_set_get_space (iterators);
kono
parents: 67
diff changeset
1054 int loop_index = isl_space_dim (space, isl_dim_set) - 1;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1055
111
kono
parents: 67
diff changeset
1056 loop_p ploop = pbb_loop (pbb);
kono
parents: 67
diff changeset
1057 while (loop != ploop)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1058 {
111
kono
parents: 67
diff changeset
1059 --loop_index;
kono
parents: 67
diff changeset
1060 ploop = loop_outer (ploop);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1061 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1062
111
kono
parents: 67
diff changeset
1063 isl_local_space *ls = isl_local_space_from_space (space);
kono
parents: 67
diff changeset
1064 isl_aff *aff = isl_aff_var_on_domain (ls, isl_dim_set, loop_index);
kono
parents: 67
diff changeset
1065 isl_multi_aff *prefix = isl_multi_aff_from_aff (aff);
kono
parents: 67
diff changeset
1066 char name[50];
kono
parents: 67
diff changeset
1067 snprintf (name, sizeof(name), "L_%d", loop->num);
kono
parents: 67
diff changeset
1068 isl_id *label = isl_id_alloc (isl_schedule_get_ctx (schedule),
kono
parents: 67
diff changeset
1069 name, NULL);
kono
parents: 67
diff changeset
1070 prefix = isl_multi_aff_set_tuple_id (prefix, isl_dim_out, label);
kono
parents: 67
diff changeset
1071
kono
parents: 67
diff changeset
1072 int n = isl_multi_aff_dim (prefix, isl_dim_in);
kono
parents: 67
diff changeset
1073 isl_multi_union_pw_aff *mupa = outer_projection_mupa (domain, n);
kono
parents: 67
diff changeset
1074 mupa = isl_multi_union_pw_aff_apply_multi_aff (mupa, prefix);
kono
parents: 67
diff changeset
1075 return isl_schedule_insert_partial_schedule (schedule, mupa);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1076 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1077
111
kono
parents: 67
diff changeset
1078 /* Build schedule for the pbb at INDEX. */
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1079
111
kono
parents: 67
diff changeset
1080 static isl_schedule *
kono
parents: 67
diff changeset
1081 build_schedule_pbb (scop_p scop, int *index)
kono
parents: 67
diff changeset
1082 {
kono
parents: 67
diff changeset
1083 poly_bb_p pbb = scop->pbbs[*index];
kono
parents: 67
diff changeset
1084 ++*index;
kono
parents: 67
diff changeset
1085 isl_set *domain = isl_set_copy (pbb->domain);
kono
parents: 67
diff changeset
1086 isl_union_set *ud = isl_union_set_from_set (domain);
kono
parents: 67
diff changeset
1087 return isl_schedule_from_domain (ud);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089
111
kono
parents: 67
diff changeset
1090 static isl_schedule *build_schedule_loop_nest (scop_p, int *, loop_p);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091
111
kono
parents: 67
diff changeset
1092 /* Build the schedule of the loop containing the SCOP pbb at INDEX. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1093
111
kono
parents: 67
diff changeset
1094 static isl_schedule *
kono
parents: 67
diff changeset
1095 build_schedule_loop (scop_p scop, int *index)
kono
parents: 67
diff changeset
1096 {
kono
parents: 67
diff changeset
1097 int max = scop->pbbs.length ();
kono
parents: 67
diff changeset
1098 gcc_assert (*index < max);
kono
parents: 67
diff changeset
1099 loop_p loop = loop_at (scop, index);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1100
111
kono
parents: 67
diff changeset
1101 isl_schedule *s = NULL;
kono
parents: 67
diff changeset
1102 while (nested_in (loop_at (scop, index), loop))
kono
parents: 67
diff changeset
1103 {
kono
parents: 67
diff changeset
1104 if (loop == loop_at (scop, index))
kono
parents: 67
diff changeset
1105 s = add_in_sequence (s, build_schedule_pbb (scop, index));
kono
parents: 67
diff changeset
1106 else
kono
parents: 67
diff changeset
1107 s = add_in_sequence (s, build_schedule_loop_nest (scop, index, loop));
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1108
111
kono
parents: 67
diff changeset
1109 if (*index == max)
kono
parents: 67
diff changeset
1110 break;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1111 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1112
111
kono
parents: 67
diff changeset
1113 return add_loop_schedule (s, loop, scop);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1114 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1115
111
kono
parents: 67
diff changeset
1116 /* S is the schedule of the loop LOOP. Embed the schedule S in all outer loops.
kono
parents: 67
diff changeset
1117 When CONTEXT_LOOP is null, embed the schedule in all loops contained in the
kono
parents: 67
diff changeset
1118 SCOP surrounding LOOP. When CONTEXT_LOOP is non null, only embed S in the
kono
parents: 67
diff changeset
1119 maximal loop nest contained within CONTEXT_LOOP. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1120
111
kono
parents: 67
diff changeset
1121 static isl_schedule *
kono
parents: 67
diff changeset
1122 embed_in_surrounding_loops (__isl_take isl_schedule *s, scop_p scop,
kono
parents: 67
diff changeset
1123 loop_p loop, int *index, loop_p context_loop)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1124 {
111
kono
parents: 67
diff changeset
1125 loop_p outer = loop_outer (loop);
kono
parents: 67
diff changeset
1126 sese_l region = scop->scop_info->region;
kono
parents: 67
diff changeset
1127 if (context_loop == outer
kono
parents: 67
diff changeset
1128 || !loop_in_sese_p (outer, region))
kono
parents: 67
diff changeset
1129 return s;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1130
111
kono
parents: 67
diff changeset
1131 int max = scop->pbbs.length ();
kono
parents: 67
diff changeset
1132 if (*index == max
kono
parents: 67
diff changeset
1133 || (context_loop && !nested_in (loop_at (scop, index), context_loop))
kono
parents: 67
diff changeset
1134 || (!context_loop
kono
parents: 67
diff changeset
1135 && !loop_in_sese_p (find_common_loop (outer, loop_at (scop, index)),
kono
parents: 67
diff changeset
1136 region)))
kono
parents: 67
diff changeset
1137 return embed_in_surrounding_loops (add_loop_schedule (s, outer, scop),
kono
parents: 67
diff changeset
1138 scop, outer, index, context_loop);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1139
111
kono
parents: 67
diff changeset
1140 bool a_pbb;
kono
parents: 67
diff changeset
1141 while ((a_pbb = (outer == loop_at (scop, index)))
kono
parents: 67
diff changeset
1142 || nested_in (loop_at (scop, index), outer))
kono
parents: 67
diff changeset
1143 {
kono
parents: 67
diff changeset
1144 if (a_pbb)
kono
parents: 67
diff changeset
1145 s = add_in_sequence (s, build_schedule_pbb (scop, index));
kono
parents: 67
diff changeset
1146 else
kono
parents: 67
diff changeset
1147 s = add_in_sequence (s, build_schedule_loop (scop, index));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1148
111
kono
parents: 67
diff changeset
1149 if (*index == max)
kono
parents: 67
diff changeset
1150 break;
kono
parents: 67
diff changeset
1151 }
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1152
111
kono
parents: 67
diff changeset
1153 /* We reached the end of the OUTER loop: embed S in OUTER. */
kono
parents: 67
diff changeset
1154 return embed_in_surrounding_loops (add_loop_schedule (s, outer, scop), scop,
kono
parents: 67
diff changeset
1155 outer, index, context_loop);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1156 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1157
111
kono
parents: 67
diff changeset
1158 /* Build schedule for the full loop nest containing the pbb at INDEX. When
kono
parents: 67
diff changeset
1159 CONTEXT_LOOP is null, build the schedule of all loops contained in the SCOP
kono
parents: 67
diff changeset
1160 surrounding the pbb. When CONTEXT_LOOP is non null, only build the maximal loop
kono
parents: 67
diff changeset
1161 nest contained within CONTEXT_LOOP. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162
111
kono
parents: 67
diff changeset
1163 static isl_schedule *
kono
parents: 67
diff changeset
1164 build_schedule_loop_nest (scop_p scop, int *index, loop_p context_loop)
kono
parents: 67
diff changeset
1165 {
kono
parents: 67
diff changeset
1166 gcc_assert (*index != (int) scop->pbbs.length ());
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167
111
kono
parents: 67
diff changeset
1168 loop_p loop = loop_at (scop, index);
kono
parents: 67
diff changeset
1169 isl_schedule *s = build_schedule_loop (scop, index);
kono
parents: 67
diff changeset
1170 return embed_in_surrounding_loops (s, scop, loop, index, context_loop);
kono
parents: 67
diff changeset
1171 }
kono
parents: 67
diff changeset
1172
kono
parents: 67
diff changeset
1173 /* Build the schedule of the SCOP. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 static void
111
kono
parents: 67
diff changeset
1176 build_original_schedule (scop_p scop)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 {
111
kono
parents: 67
diff changeset
1178 int i = 0;
kono
parents: 67
diff changeset
1179 int n = scop->pbbs.length ();
kono
parents: 67
diff changeset
1180 while (i < n)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 {
111
kono
parents: 67
diff changeset
1182 poly_bb_p pbb = scop->pbbs[i];
kono
parents: 67
diff changeset
1183 isl_schedule *s = NULL;
kono
parents: 67
diff changeset
1184 if (!loop_in_sese_p (pbb_loop (pbb), scop->scop_info->region))
kono
parents: 67
diff changeset
1185 s = build_schedule_pbb (scop, &i);
kono
parents: 67
diff changeset
1186 else
kono
parents: 67
diff changeset
1187 s = build_schedule_loop_nest (scop, &i, NULL);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188
111
kono
parents: 67
diff changeset
1189 scop->original_schedule = add_in_sequence (scop->original_schedule, s);
kono
parents: 67
diff changeset
1190 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191
111
kono
parents: 67
diff changeset
1192 if (dump_file)
kono
parents: 67
diff changeset
1193 {
kono
parents: 67
diff changeset
1194 fprintf (dump_file, "[sese-to-poly] original schedule:\n");
kono
parents: 67
diff changeset
1195 print_isl_schedule (dump_file, scop->original_schedule);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 /* Builds the polyhedral representation for a SESE region. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200
111
kono
parents: 67
diff changeset
1201 bool
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202 build_poly_scop (scop_p scop)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203 {
111
kono
parents: 67
diff changeset
1204 int old_err = isl_options_get_on_error (scop->isl_context);
kono
parents: 67
diff changeset
1205 isl_options_set_on_error (scop->isl_context, ISL_ON_ERROR_CONTINUE);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206
111
kono
parents: 67
diff changeset
1207 build_scop_context (scop);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1208
111
kono
parents: 67
diff changeset
1209 unsigned i = 0;
kono
parents: 67
diff changeset
1210 unsigned n = scop->pbbs.length ();
kono
parents: 67
diff changeset
1211 while (i < n)
kono
parents: 67
diff changeset
1212 i = build_iteration_domains (scop, scop->param_context, i, NULL);
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1213
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1214 build_scop_drs (scop);
111
kono
parents: 67
diff changeset
1215 build_original_schedule (scop);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216
111
kono
parents: 67
diff changeset
1217 enum isl_error err = isl_ctx_last_error (scop->isl_context);
kono
parents: 67
diff changeset
1218 isl_ctx_reset_error (scop->isl_context);
kono
parents: 67
diff changeset
1219 isl_options_set_on_error (scop->isl_context, old_err);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1220 if (err != isl_error_none
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1221 && dump_enabled_p ())
111
kono
parents: 67
diff changeset
1222 dump_printf (MSG_MISSED_OPTIMIZATION,
kono
parents: 67
diff changeset
1223 "ISL error while building poly scop\n");
kono
parents: 67
diff changeset
1224
kono
parents: 67
diff changeset
1225 return err == isl_error_none;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226 }
111
kono
parents: 67
diff changeset
1227 #endif /* HAVE_isl */