annotate gcc/graphite-scop-detection.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 /* Detection of Static Control Parts (SCoP) for Graphite.
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> and
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 Tobias Grosser <grosser@fim.uni-passau.de>.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 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
7
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 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
9 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
10 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
11 any later version.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 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
14 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
15 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
16 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
17
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 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
19 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
20 <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
21
111
kono
parents: 67
diff changeset
22 #define USES_ISL
kono
parents: 67
diff changeset
23
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "config.h"
111
kono
parents: 67
diff changeset
25
kono
parents: 67
diff changeset
26 #ifdef HAVE_isl
kono
parents: 67
diff changeset
27
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "system.h"
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #include "coretypes.h"
111
kono
parents: 67
diff changeset
30 #include "backend.h"
kono
parents: 67
diff changeset
31 #include "cfghooks.h"
kono
parents: 67
diff changeset
32 #include "domwalk.h"
kono
parents: 67
diff changeset
33 #include "tree.h"
kono
parents: 67
diff changeset
34 #include "gimple.h"
kono
parents: 67
diff changeset
35 #include "ssa.h"
kono
parents: 67
diff changeset
36 #include "fold-const.h"
kono
parents: 67
diff changeset
37 #include "gimple-iterator.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-ssa.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 "tree-pass.h"
111
kono
parents: 67
diff changeset
48 #include "tree-ssa-propagate.h"
kono
parents: 67
diff changeset
49 #include "gimple-pretty-print.h"
kono
parents: 67
diff changeset
50 #include "cfganal.h"
kono
parents: 67
diff changeset
51 #include "graphite.h"
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
111
kono
parents: 67
diff changeset
53 class debug_printer
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 {
111
kono
parents: 67
diff changeset
55 private:
kono
parents: 67
diff changeset
56 FILE *dump_file;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
111
kono
parents: 67
diff changeset
58 public:
kono
parents: 67
diff changeset
59 void
kono
parents: 67
diff changeset
60 set_dump_file (FILE *f)
kono
parents: 67
diff changeset
61 {
kono
parents: 67
diff changeset
62 gcc_assert (f);
kono
parents: 67
diff changeset
63 dump_file = f;
kono
parents: 67
diff changeset
64 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
111
kono
parents: 67
diff changeset
66 friend debug_printer &
kono
parents: 67
diff changeset
67 operator<< (debug_printer &output, int i)
kono
parents: 67
diff changeset
68 {
kono
parents: 67
diff changeset
69 fprintf (output.dump_file, "%d", i);
kono
parents: 67
diff changeset
70 return output;
kono
parents: 67
diff changeset
71 }
kono
parents: 67
diff changeset
72 friend debug_printer &
kono
parents: 67
diff changeset
73 operator<< (debug_printer &output, const char *s)
kono
parents: 67
diff changeset
74 {
kono
parents: 67
diff changeset
75 fprintf (output.dump_file, "%s", s);
kono
parents: 67
diff changeset
76 return output;
kono
parents: 67
diff changeset
77 }
kono
parents: 67
diff changeset
78 } dp;
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
79
111
kono
parents: 67
diff changeset
80 #define DEBUG_PRINT(args) do \
kono
parents: 67
diff changeset
81 { \
kono
parents: 67
diff changeset
82 if (dump_file && (dump_flags & TDF_DETAILS)) { args; } \
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
83 } while (0)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 /* Pretty print to FILE all the SCoPs in DOT format and mark them with
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 different colors. If there are not enough colors, paint the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 remaining SCoPs in gray.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 Special nodes:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 - "*" after the node number denotes the entry of a SCoP,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 - "#" after the node number denotes the exit of a SCoP,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 - "()" around the node number denotes the entry or the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 exit nodes of the SCOP. These are not part of SCoP. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
111
kono
parents: 67
diff changeset
95 DEBUG_FUNCTION void
kono
parents: 67
diff changeset
96 dot_all_sese (FILE *file, vec<sese_l>& scops)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 /* Disable debugging while printing graph. */
111
kono
parents: 67
diff changeset
99 dump_flags_t tmp_dump_flags = dump_flags;
kono
parents: 67
diff changeset
100 dump_flags = TDF_NONE;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 fprintf (file, "digraph all {\n");
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
111
kono
parents: 67
diff changeset
104 basic_block bb;
kono
parents: 67
diff changeset
105 FOR_ALL_BB_FN (bb, cfun)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 int part_of_scop = false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 /* Use HTML for every bb label. So we are able to print bbs
111
kono
parents: 67
diff changeset
110 which are part of two different SCoPs, with two different
kono
parents: 67
diff changeset
111 background colors. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 fprintf (file, "%d [label=<\n <TABLE BORDER=\"0\" CELLBORDER=\"1\" ",
111
kono
parents: 67
diff changeset
113 bb->index);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 fprintf (file, "CELLSPACING=\"0\">\n");
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 /* Select color for SCoP. */
111
kono
parents: 67
diff changeset
117 sese_l *region;
kono
parents: 67
diff changeset
118 int i;
kono
parents: 67
diff changeset
119 FOR_EACH_VEC_ELT (scops, i, region)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 {
111
kono
parents: 67
diff changeset
121 bool sese_in_region = bb_in_sese_p (bb, *region);
kono
parents: 67
diff changeset
122 if (sese_in_region || (region->exit->dest == bb)
kono
parents: 67
diff changeset
123 || (region->entry->dest == bb))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 {
111
kono
parents: 67
diff changeset
125 const char *color;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 switch (i % 17)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 case 0: /* red */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 color = "#e41a1c";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 case 1: /* blue */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 color = "#377eb8";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 case 2: /* green */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 color = "#4daf4a";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 case 3: /* purple */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 color = "#984ea3";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 case 4: /* orange */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 color = "#ff7f00";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 case 5: /* yellow */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 color = "#ffff33";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 case 6: /* brown */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 color = "#a65628";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 case 7: /* rose */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 color = "#f781bf";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 case 8:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 color = "#8dd3c7";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 case 9:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 color = "#ffffb3";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 case 10:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 color = "#bebada";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 case 11:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 color = "#fb8072";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 case 12:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 color = "#80b1d3";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 case 13:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 color = "#fdb462";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 case 14:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 color = "#b3de69";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 case 15:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 color = "#fccde5";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 case 16:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 color = "#bc80bd";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 default: /* gray */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 color = "#999999";
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
111
kono
parents: 67
diff changeset
183 fprintf (file, " <TR><TD WIDTH=\"50\" BGCOLOR=\"%s\">",
kono
parents: 67
diff changeset
184 color);
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 if (!sese_in_region)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 fprintf (file, " (");
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 if (bb == region->entry->dest && bb == region->exit->dest)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 fprintf (file, " %d*# ", bb->index);
111
kono
parents: 67
diff changeset
191 else if (bb == region->entry->dest)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 fprintf (file, " %d* ", bb->index);
111
kono
parents: 67
diff changeset
193 else if (bb == region->exit->dest)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 fprintf (file, " %d# ", bb->index);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 fprintf (file, " %d ", bb->index);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
111
kono
parents: 67
diff changeset
198 fprintf (file, "{lp_%d}", bb->loop_father->num);
kono
parents: 67
diff changeset
199
kono
parents: 67
diff changeset
200 if (!sese_in_region)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 fprintf (file, ")");
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 fprintf (file, "</TD></TR>\n");
111
kono
parents: 67
diff changeset
204 part_of_scop = true;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207
111
kono
parents: 67
diff changeset
208 if (!part_of_scop)
kono
parents: 67
diff changeset
209 {
kono
parents: 67
diff changeset
210 fprintf (file, " <TR><TD WIDTH=\"50\" BGCOLOR=\"#ffffff\">");
kono
parents: 67
diff changeset
211 fprintf (file, " %d {lp_%d} </TD></TR>\n", bb->index,
kono
parents: 67
diff changeset
212 bb->loop_father->num);
kono
parents: 67
diff changeset
213 }
kono
parents: 67
diff changeset
214 fprintf (file, " </TABLE>>, shape=box, style=\"setlinewidth(0)\"]\n");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 }
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 FOR_ALL_BB_FN (bb, cfun)
kono
parents: 67
diff changeset
218 {
kono
parents: 67
diff changeset
219 edge e;
kono
parents: 67
diff changeset
220 edge_iterator ei;
kono
parents: 67
diff changeset
221 FOR_EACH_EDGE (e, ei, bb->succs)
kono
parents: 67
diff changeset
222 fprintf (file, "%d -> %d;\n", bb->index, e->dest->index);
kono
parents: 67
diff changeset
223 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 fputs ("}\n\n", file);
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 /* Enable debugging again. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 dump_flags = tmp_dump_flags;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230
111
kono
parents: 67
diff changeset
231 /* Display SCoP on stderr. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232
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
233 DEBUG_FUNCTION void
111
kono
parents: 67
diff changeset
234 dot_sese (sese_l& scop)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 {
111
kono
parents: 67
diff changeset
236 vec<sese_l> scops;
kono
parents: 67
diff changeset
237 scops.create (1);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
111
kono
parents: 67
diff changeset
239 if (scop)
kono
parents: 67
diff changeset
240 scops.safe_push (scop);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241
111
kono
parents: 67
diff changeset
242 dot_all_sese (stderr, scops);
kono
parents: 67
diff changeset
243
kono
parents: 67
diff changeset
244 scops.release ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246
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
247 DEBUG_FUNCTION void
111
kono
parents: 67
diff changeset
248 dot_cfg ()
55
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 vec<sese_l> scops;
kono
parents: 67
diff changeset
251 scops.create (1);
kono
parents: 67
diff changeset
252 dot_all_sese (stderr, scops);
kono
parents: 67
diff changeset
253 scops.release ();
kono
parents: 67
diff changeset
254 }
kono
parents: 67
diff changeset
255
kono
parents: 67
diff changeset
256 /* Returns a COND_EXPR statement when BB has a single predecessor, the
kono
parents: 67
diff changeset
257 edge between BB and its predecessor is not a loop exit edge, and
kono
parents: 67
diff changeset
258 the last statement of the single predecessor is a COND_EXPR. */
kono
parents: 67
diff changeset
259
kono
parents: 67
diff changeset
260 static gcond *
kono
parents: 67
diff changeset
261 single_pred_cond_non_loop_exit (basic_block bb)
kono
parents: 67
diff changeset
262 {
kono
parents: 67
diff changeset
263 if (single_pred_p (bb))
kono
parents: 67
diff changeset
264 {
kono
parents: 67
diff changeset
265 edge e = single_pred_edge (bb);
kono
parents: 67
diff changeset
266 basic_block pred = e->src;
kono
parents: 67
diff changeset
267 gimple *stmt;
kono
parents: 67
diff changeset
268
kono
parents: 67
diff changeset
269 if (loop_depth (pred->loop_father) > loop_depth (bb->loop_father))
kono
parents: 67
diff changeset
270 return NULL;
kono
parents: 67
diff changeset
271
kono
parents: 67
diff changeset
272 stmt = last_stmt (pred);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273
111
kono
parents: 67
diff changeset
274 if (stmt && gimple_code (stmt) == GIMPLE_COND)
kono
parents: 67
diff changeset
275 return as_a<gcond *> (stmt);
kono
parents: 67
diff changeset
276 }
kono
parents: 67
diff changeset
277
kono
parents: 67
diff changeset
278 return NULL;
kono
parents: 67
diff changeset
279 }
kono
parents: 67
diff changeset
280
kono
parents: 67
diff changeset
281 namespace
kono
parents: 67
diff changeset
282 {
kono
parents: 67
diff changeset
283
kono
parents: 67
diff changeset
284 /* Build the maximal scop containing LOOPs and add it to SCOPS. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285
111
kono
parents: 67
diff changeset
286 class scop_detection
kono
parents: 67
diff changeset
287 {
kono
parents: 67
diff changeset
288 public:
kono
parents: 67
diff changeset
289 scop_detection () : scops (vNULL) {}
kono
parents: 67
diff changeset
290
kono
parents: 67
diff changeset
291 ~scop_detection ()
kono
parents: 67
diff changeset
292 {
kono
parents: 67
diff changeset
293 scops.release ();
kono
parents: 67
diff changeset
294 }
kono
parents: 67
diff changeset
295
kono
parents: 67
diff changeset
296 /* A marker for invalid sese_l. */
kono
parents: 67
diff changeset
297 static sese_l invalid_sese;
kono
parents: 67
diff changeset
298
kono
parents: 67
diff changeset
299 /* Return the SCOPS in this SCOP_DETECTION. */
kono
parents: 67
diff changeset
300
kono
parents: 67
diff changeset
301 vec<sese_l>
kono
parents: 67
diff changeset
302 get_scops ()
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 {
111
kono
parents: 67
diff changeset
304 return scops;
kono
parents: 67
diff changeset
305 }
kono
parents: 67
diff changeset
306
kono
parents: 67
diff changeset
307 /* Return an sese_l around the LOOP. */
kono
parents: 67
diff changeset
308
kono
parents: 67
diff changeset
309 sese_l get_sese (loop_p loop);
kono
parents: 67
diff changeset
310
kono
parents: 67
diff changeset
311 /* Merge scops at same loop depth and returns the new sese.
kono
parents: 67
diff changeset
312 Returns a new SESE when merge was successful, INVALID_SESE otherwise. */
kono
parents: 67
diff changeset
313
kono
parents: 67
diff changeset
314 sese_l merge_sese (sese_l first, sese_l second) const;
kono
parents: 67
diff changeset
315
kono
parents: 67
diff changeset
316 /* Build scop outer->inner if possible. */
kono
parents: 67
diff changeset
317
kono
parents: 67
diff changeset
318 void build_scop_depth (loop_p loop);
kono
parents: 67
diff changeset
319
kono
parents: 67
diff changeset
320 /* Return true when BEGIN is the preheader edge of a loop with a single exit
kono
parents: 67
diff changeset
321 END. */
kono
parents: 67
diff changeset
322
kono
parents: 67
diff changeset
323 static bool region_has_one_loop (sese_l s);
kono
parents: 67
diff changeset
324
kono
parents: 67
diff changeset
325 /* Add to SCOPS a scop starting at SCOP_BEGIN and ending at SCOP_END. */
kono
parents: 67
diff changeset
326
kono
parents: 67
diff changeset
327 void add_scop (sese_l s);
kono
parents: 67
diff changeset
328
kono
parents: 67
diff changeset
329 /* Returns true if S1 subsumes/surrounds S2. */
kono
parents: 67
diff changeset
330 static bool subsumes (sese_l s1, sese_l s2);
kono
parents: 67
diff changeset
331
kono
parents: 67
diff changeset
332 /* Remove a SCoP which is subsumed by S1. */
kono
parents: 67
diff changeset
333 void remove_subscops (sese_l s1);
kono
parents: 67
diff changeset
334
kono
parents: 67
diff changeset
335 /* Returns true if S1 intersects with S2. Since we already know that S1 does
kono
parents: 67
diff changeset
336 not subsume S2 or vice-versa, we only check for entry bbs. */
kono
parents: 67
diff changeset
337
kono
parents: 67
diff changeset
338 static bool intersects (sese_l s1, sese_l s2);
kono
parents: 67
diff changeset
339
kono
parents: 67
diff changeset
340 /* Remove one of the scops when it intersects with any other. */
kono
parents: 67
diff changeset
341
kono
parents: 67
diff changeset
342 void remove_intersecting_scops (sese_l s1);
kono
parents: 67
diff changeset
343
kono
parents: 67
diff changeset
344 /* Return true when a statement in SCOP cannot be represented by Graphite. */
kono
parents: 67
diff changeset
345
kono
parents: 67
diff changeset
346 bool harmful_loop_in_region (sese_l scop) const;
kono
parents: 67
diff changeset
347
kono
parents: 67
diff changeset
348 /* Return true only when STMT is simple enough for being handled by Graphite.
kono
parents: 67
diff changeset
349 This depends on SCOP, as the parameters are initialized relatively to
kono
parents: 67
diff changeset
350 this basic block, the linear functions are initialized based on the
kono
parents: 67
diff changeset
351 outermost loop containing STMT inside the SCOP. BB is the place where we
kono
parents: 67
diff changeset
352 try to evaluate the STMT. */
kono
parents: 67
diff changeset
353
kono
parents: 67
diff changeset
354 bool stmt_simple_for_scop_p (sese_l scop, gimple *stmt,
kono
parents: 67
diff changeset
355 basic_block bb) const;
kono
parents: 67
diff changeset
356
kono
parents: 67
diff changeset
357 /* Something like "n * m" is not allowed. */
kono
parents: 67
diff changeset
358
kono
parents: 67
diff changeset
359 static bool graphite_can_represent_init (tree e);
kono
parents: 67
diff changeset
360
kono
parents: 67
diff changeset
361 /* Return true when SCEV can be represented in the polyhedral model.
kono
parents: 67
diff changeset
362
kono
parents: 67
diff changeset
363 An expression can be represented, if it can be expressed as an
kono
parents: 67
diff changeset
364 affine expression. For loops (i, j) and parameters (m, n) all
kono
parents: 67
diff changeset
365 affine expressions are of the form:
kono
parents: 67
diff changeset
366
kono
parents: 67
diff changeset
367 x1 * i + x2 * j + x3 * m + x4 * n + x5 * 1 where x1..x5 element of Z
kono
parents: 67
diff changeset
368
kono
parents: 67
diff changeset
369 1 i + 20 j + (-2) m + 25
kono
parents: 67
diff changeset
370
kono
parents: 67
diff changeset
371 Something like "i * n" or "n * m" is not allowed. */
kono
parents: 67
diff changeset
372
kono
parents: 67
diff changeset
373 static bool graphite_can_represent_scev (sese_l scop, tree scev);
kono
parents: 67
diff changeset
374
kono
parents: 67
diff changeset
375 /* Return true when EXPR can be represented in the polyhedral model.
kono
parents: 67
diff changeset
376
kono
parents: 67
diff changeset
377 This means an expression can be represented, if it is linear with respect
kono
parents: 67
diff changeset
378 to the loops and the strides are non parametric. LOOP is the place where
kono
parents: 67
diff changeset
379 the expr will be evaluated. SCOP defines the region we analyse. */
kono
parents: 67
diff changeset
380
kono
parents: 67
diff changeset
381 static bool graphite_can_represent_expr (sese_l scop, loop_p loop,
kono
parents: 67
diff changeset
382 tree expr);
kono
parents: 67
diff changeset
383
kono
parents: 67
diff changeset
384 /* Return true if the data references of STMT can be represented by Graphite.
kono
parents: 67
diff changeset
385 We try to analyze the data references in a loop contained in the SCOP. */
kono
parents: 67
diff changeset
386
kono
parents: 67
diff changeset
387 static bool stmt_has_simple_data_refs_p (sese_l scop, gimple *stmt);
kono
parents: 67
diff changeset
388
kono
parents: 67
diff changeset
389 /* Remove the close phi node at GSI and replace its rhs with the rhs
kono
parents: 67
diff changeset
390 of PHI. */
kono
parents: 67
diff changeset
391
kono
parents: 67
diff changeset
392 static void remove_duplicate_close_phi (gphi *phi, gphi_iterator *gsi);
kono
parents: 67
diff changeset
393
kono
parents: 67
diff changeset
394 /* Returns true when Graphite can represent LOOP in SCOP.
kono
parents: 67
diff changeset
395 FIXME: For the moment, graphite cannot be used on loops that iterate using
kono
parents: 67
diff changeset
396 induction variables that wrap. */
kono
parents: 67
diff changeset
397
kono
parents: 67
diff changeset
398 static bool can_represent_loop (loop_p loop, sese_l scop);
kono
parents: 67
diff changeset
399
kono
parents: 67
diff changeset
400 /* Returns the number of pbbs that are in loops contained in SCOP. */
kono
parents: 67
diff changeset
401
kono
parents: 67
diff changeset
402 static int nb_pbbs_in_loops (scop_p scop);
kono
parents: 67
diff changeset
403
kono
parents: 67
diff changeset
404 private:
kono
parents: 67
diff changeset
405 vec<sese_l> scops;
kono
parents: 67
diff changeset
406 };
kono
parents: 67
diff changeset
407
kono
parents: 67
diff changeset
408 sese_l scop_detection::invalid_sese (NULL, NULL);
kono
parents: 67
diff changeset
409
kono
parents: 67
diff changeset
410 /* Return an sese_l around the LOOP. */
kono
parents: 67
diff changeset
411
kono
parents: 67
diff changeset
412 sese_l
kono
parents: 67
diff changeset
413 scop_detection::get_sese (loop_p loop)
kono
parents: 67
diff changeset
414 {
kono
parents: 67
diff changeset
415 if (!loop)
kono
parents: 67
diff changeset
416 return invalid_sese;
kono
parents: 67
diff changeset
417
kono
parents: 67
diff changeset
418 edge scop_begin = loop_preheader_edge (loop);
kono
parents: 67
diff changeset
419 edge scop_end = single_exit (loop);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
420 if (!scop_end || (scop_end->flags & (EDGE_COMPLEX|EDGE_FAKE)))
111
kono
parents: 67
diff changeset
421 return invalid_sese;
kono
parents: 67
diff changeset
422
kono
parents: 67
diff changeset
423 return sese_l (scop_begin, scop_end);
kono
parents: 67
diff changeset
424 }
kono
parents: 67
diff changeset
425
kono
parents: 67
diff changeset
426 /* Merge scops at same loop depth and returns the new sese.
kono
parents: 67
diff changeset
427 Returns a new SESE when merge was successful, INVALID_SESE otherwise. */
kono
parents: 67
diff changeset
428
kono
parents: 67
diff changeset
429 sese_l
kono
parents: 67
diff changeset
430 scop_detection::merge_sese (sese_l first, sese_l second) const
kono
parents: 67
diff changeset
431 {
kono
parents: 67
diff changeset
432 /* In the trivial case first/second may be NULL. */
kono
parents: 67
diff changeset
433 if (!first)
kono
parents: 67
diff changeset
434 return second;
kono
parents: 67
diff changeset
435 if (!second)
kono
parents: 67
diff changeset
436 return first;
kono
parents: 67
diff changeset
437
kono
parents: 67
diff changeset
438 DEBUG_PRINT (dp << "[scop-detection] try merging sese s1: ";
kono
parents: 67
diff changeset
439 print_sese (dump_file, first);
kono
parents: 67
diff changeset
440 dp << "[scop-detection] try merging sese s2: ";
kono
parents: 67
diff changeset
441 print_sese (dump_file, second));
kono
parents: 67
diff changeset
442
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
443 auto_bitmap worklist, in_sese_region;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
444 bitmap_set_bit (worklist, get_entry_bb (first)->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
445 bitmap_set_bit (worklist, get_exit_bb (first)->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
446 bitmap_set_bit (worklist, get_entry_bb (second)->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
447 bitmap_set_bit (worklist, get_exit_bb (second)->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
448 edge entry = NULL, exit = NULL;
111
kono
parents: 67
diff changeset
449
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
450 /* We can optimize the case of adding a loop entry dest or exit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
451 src to the worklist (for single-exit loops) by skipping
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
452 directly to the exit dest / entry src. in_sese_region
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
453 doesn't have to cover all blocks in the region but merely
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
454 its border it acts more like a visited bitmap. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
455 do
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
456 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
457 int index = bitmap_first_set_bit (worklist);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
458 bitmap_clear_bit (worklist, index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
459 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
460 edge_iterator ei;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
461 edge e;
111
kono
parents: 67
diff changeset
462
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
463 /* With fake exit edges we can end up with no possible exit. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
464 if (index == EXIT_BLOCK)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
465 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
466 DEBUG_PRINT (dp << "[scop-detection-fail] cannot merge seses.\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
467 return invalid_sese;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
468 }
111
kono
parents: 67
diff changeset
469
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
470 bitmap_set_bit (in_sese_region, bb->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
471
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
472 basic_block dom = get_immediate_dominator (CDI_DOMINATORS, bb);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
473 FOR_EACH_EDGE (e, ei, bb->preds)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
474 if (e->src == dom
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
475 && (! entry
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
476 || dominated_by_p (CDI_DOMINATORS, entry->dest, bb)))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
477 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
478 if (entry
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
479 && ! bitmap_bit_p (in_sese_region, entry->src->index))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
480 bitmap_set_bit (worklist, entry->src->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
481 entry = e;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
482 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
483 else if (! bitmap_bit_p (in_sese_region, e->src->index))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
484 bitmap_set_bit (worklist, e->src->index);
111
kono
parents: 67
diff changeset
485
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
486 basic_block pdom = get_immediate_dominator (CDI_POST_DOMINATORS, bb);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
487 FOR_EACH_EDGE (e, ei, bb->succs)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
488 if (e->dest == pdom
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
489 && (! exit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
490 || dominated_by_p (CDI_POST_DOMINATORS, exit->src, bb)))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
491 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
492 if (exit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
493 && ! bitmap_bit_p (in_sese_region, exit->dest->index))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
494 bitmap_set_bit (worklist, exit->dest->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
495 exit = e;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
496 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
497 else if (! bitmap_bit_p (in_sese_region, e->dest->index))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
498 bitmap_set_bit (worklist, e->dest->index);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
499 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
500 while (! bitmap_empty_p (worklist));
111
kono
parents: 67
diff changeset
501
kono
parents: 67
diff changeset
502 sese_l combined (entry, exit);
kono
parents: 67
diff changeset
503
kono
parents: 67
diff changeset
504 DEBUG_PRINT (dp << "[merged-sese] s1: "; print_sese (dump_file, combined));
kono
parents: 67
diff changeset
505
kono
parents: 67
diff changeset
506 return combined;
kono
parents: 67
diff changeset
507 }
kono
parents: 67
diff changeset
508
kono
parents: 67
diff changeset
509 /* Build scop outer->inner if possible. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510
111
kono
parents: 67
diff changeset
511 void
kono
parents: 67
diff changeset
512 scop_detection::build_scop_depth (loop_p loop)
kono
parents: 67
diff changeset
513 {
kono
parents: 67
diff changeset
514 sese_l s = invalid_sese;
kono
parents: 67
diff changeset
515 loop = loop->inner;
kono
parents: 67
diff changeset
516 while (loop)
kono
parents: 67
diff changeset
517 {
kono
parents: 67
diff changeset
518 sese_l next = get_sese (loop);
kono
parents: 67
diff changeset
519 if (! next
kono
parents: 67
diff changeset
520 || harmful_loop_in_region (next))
kono
parents: 67
diff changeset
521 {
kono
parents: 67
diff changeset
522 if (s)
kono
parents: 67
diff changeset
523 add_scop (s);
kono
parents: 67
diff changeset
524 build_scop_depth (loop);
kono
parents: 67
diff changeset
525 s = invalid_sese;
kono
parents: 67
diff changeset
526 }
kono
parents: 67
diff changeset
527 else if (! s)
kono
parents: 67
diff changeset
528 s = next;
kono
parents: 67
diff changeset
529 else
kono
parents: 67
diff changeset
530 {
kono
parents: 67
diff changeset
531 sese_l combined = merge_sese (s, next);
kono
parents: 67
diff changeset
532 if (! combined
kono
parents: 67
diff changeset
533 || harmful_loop_in_region (combined))
kono
parents: 67
diff changeset
534 {
kono
parents: 67
diff changeset
535 add_scop (s);
kono
parents: 67
diff changeset
536 s = next;
kono
parents: 67
diff changeset
537 }
kono
parents: 67
diff changeset
538 else
kono
parents: 67
diff changeset
539 s = combined;
kono
parents: 67
diff changeset
540 }
kono
parents: 67
diff changeset
541 loop = loop->next;
kono
parents: 67
diff changeset
542 }
kono
parents: 67
diff changeset
543 if (s)
kono
parents: 67
diff changeset
544 add_scop (s);
kono
parents: 67
diff changeset
545 }
kono
parents: 67
diff changeset
546
kono
parents: 67
diff changeset
547 /* Returns true when Graphite can represent LOOP in SCOP.
kono
parents: 67
diff changeset
548 FIXME: For the moment, graphite cannot be used on loops that iterate using
kono
parents: 67
diff changeset
549 induction variables that wrap. */
kono
parents: 67
diff changeset
550
kono
parents: 67
diff changeset
551 bool
kono
parents: 67
diff changeset
552 scop_detection::can_represent_loop (loop_p loop, sese_l scop)
kono
parents: 67
diff changeset
553 {
kono
parents: 67
diff changeset
554 tree niter;
kono
parents: 67
diff changeset
555 struct tree_niter_desc niter_desc;
kono
parents: 67
diff changeset
556
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
557 /* We can only handle do {} while () style loops correctly. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
558 edge exit = single_exit (loop);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
559 if (!exit
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
560 || !single_pred_p (loop->latch)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
561 || exit->src != single_pred (loop->latch)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
562 || !empty_block_p (loop->latch))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
563 return false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
564
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
565 return !(loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP)
111
kono
parents: 67
diff changeset
566 && number_of_iterations_exit (loop, single_exit (loop), &niter_desc, false)
kono
parents: 67
diff changeset
567 && niter_desc.control.no_overflow
kono
parents: 67
diff changeset
568 && (niter = number_of_latch_executions (loop))
kono
parents: 67
diff changeset
569 && !chrec_contains_undetermined (niter)
kono
parents: 67
diff changeset
570 && graphite_can_represent_expr (scop, loop, niter);
kono
parents: 67
diff changeset
571 }
kono
parents: 67
diff changeset
572
kono
parents: 67
diff changeset
573 /* Return true when BEGIN is the preheader edge of a loop with a single exit
kono
parents: 67
diff changeset
574 END. */
kono
parents: 67
diff changeset
575
kono
parents: 67
diff changeset
576 bool
kono
parents: 67
diff changeset
577 scop_detection::region_has_one_loop (sese_l s)
kono
parents: 67
diff changeset
578 {
kono
parents: 67
diff changeset
579 edge begin = s.entry;
kono
parents: 67
diff changeset
580 edge end = s.exit;
kono
parents: 67
diff changeset
581 /* Check for a single perfectly nested loop. */
kono
parents: 67
diff changeset
582 if (begin->dest->loop_father->inner)
kono
parents: 67
diff changeset
583 return false;
kono
parents: 67
diff changeset
584
kono
parents: 67
diff changeset
585 /* Otherwise, check whether we have adjacent loops. */
kono
parents: 67
diff changeset
586 return (single_pred_p (end->src)
kono
parents: 67
diff changeset
587 && begin->dest->loop_father == single_pred (end->src)->loop_father);
kono
parents: 67
diff changeset
588 }
kono
parents: 67
diff changeset
589
kono
parents: 67
diff changeset
590 /* Add to SCOPS a scop starting at SCOP_BEGIN and ending at SCOP_END. */
kono
parents: 67
diff changeset
591
kono
parents: 67
diff changeset
592 void
kono
parents: 67
diff changeset
593 scop_detection::add_scop (sese_l s)
kono
parents: 67
diff changeset
594 {
kono
parents: 67
diff changeset
595 gcc_assert (s);
kono
parents: 67
diff changeset
596
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
597 /* If the exit edge is fake discard the SCoP for now as we're removing the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
598 fake edges again after analysis. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
599 if (s.exit->flags & EDGE_FAKE)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
600 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
601 DEBUG_PRINT (dp << "[scop-detection-fail] Discarding infinite loop SCoP: ";
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
602 print_sese (dump_file, s));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
603 return;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
604 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
605
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
606 /* Include the BB with the loop-closed SSA PHI nodes, we need this
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
607 block in the region for code-generating out-of-SSA copies.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
608 canonicalize_loop_closed_ssa makes sure that is in proper shape. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
609 if (s.exit->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
610 && loop_exit_edge_p (s.exit->src->loop_father, s.exit))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
611 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
612 gcc_assert (single_pred_p (s.exit->dest)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
613 && single_succ_p (s.exit->dest)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
614 && sese_trivially_empty_bb_p (s.exit->dest));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
615 s.exit = single_succ_edge (s.exit->dest);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
616 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
617
111
kono
parents: 67
diff changeset
618 /* Do not add scops with only one loop. */
kono
parents: 67
diff changeset
619 if (region_has_one_loop (s))
kono
parents: 67
diff changeset
620 {
kono
parents: 67
diff changeset
621 DEBUG_PRINT (dp << "[scop-detection-fail] Discarding one loop SCoP: ";
kono
parents: 67
diff changeset
622 print_sese (dump_file, s));
kono
parents: 67
diff changeset
623 return;
kono
parents: 67
diff changeset
624 }
kono
parents: 67
diff changeset
625
kono
parents: 67
diff changeset
626 if (get_exit_bb (s) == EXIT_BLOCK_PTR_FOR_FN (cfun))
kono
parents: 67
diff changeset
627 {
kono
parents: 67
diff changeset
628 DEBUG_PRINT (dp << "[scop-detection-fail] "
kono
parents: 67
diff changeset
629 << "Discarding SCoP exiting to return: ";
kono
parents: 67
diff changeset
630 print_sese (dump_file, s));
kono
parents: 67
diff changeset
631 return;
kono
parents: 67
diff changeset
632 }
kono
parents: 67
diff changeset
633
kono
parents: 67
diff changeset
634 /* Remove all the scops which are subsumed by s. */
kono
parents: 67
diff changeset
635 remove_subscops (s);
kono
parents: 67
diff changeset
636
kono
parents: 67
diff changeset
637 /* Remove intersecting scops. FIXME: It will be a good idea to keep
kono
parents: 67
diff changeset
638 the non-intersecting part of the scop already in the list. */
kono
parents: 67
diff changeset
639 remove_intersecting_scops (s);
kono
parents: 67
diff changeset
640
kono
parents: 67
diff changeset
641 scops.safe_push (s);
kono
parents: 67
diff changeset
642 DEBUG_PRINT (dp << "[scop-detection] Adding SCoP: "; print_sese (dump_file, s));
kono
parents: 67
diff changeset
643 }
kono
parents: 67
diff changeset
644
kono
parents: 67
diff changeset
645 /* Return true when a statement in SCOP cannot be represented by Graphite. */
kono
parents: 67
diff changeset
646
kono
parents: 67
diff changeset
647 bool
kono
parents: 67
diff changeset
648 scop_detection::harmful_loop_in_region (sese_l scop) const
kono
parents: 67
diff changeset
649 {
kono
parents: 67
diff changeset
650 basic_block exit_bb = get_exit_bb (scop);
kono
parents: 67
diff changeset
651 basic_block entry_bb = get_entry_bb (scop);
kono
parents: 67
diff changeset
652
kono
parents: 67
diff changeset
653 DEBUG_PRINT (dp << "[checking-harmful-bbs] ";
kono
parents: 67
diff changeset
654 print_sese (dump_file, scop));
kono
parents: 67
diff changeset
655 gcc_assert (dominated_by_p (CDI_DOMINATORS, exit_bb, entry_bb));
kono
parents: 67
diff changeset
656
kono
parents: 67
diff changeset
657 auto_vec<basic_block> worklist;
kono
parents: 67
diff changeset
658 auto_bitmap loops;
kono
parents: 67
diff changeset
659
kono
parents: 67
diff changeset
660 worklist.safe_push (entry_bb);
kono
parents: 67
diff changeset
661 while (! worklist.is_empty ())
kono
parents: 67
diff changeset
662 {
kono
parents: 67
diff changeset
663 basic_block bb = worklist.pop ();
kono
parents: 67
diff changeset
664 DEBUG_PRINT (dp << "Visiting bb_" << bb->index << "\n");
kono
parents: 67
diff changeset
665
kono
parents: 67
diff changeset
666 /* The basic block should not be part of an irreducible loop. */
kono
parents: 67
diff changeset
667 if (bb->flags & BB_IRREDUCIBLE_LOOP)
kono
parents: 67
diff changeset
668 return true;
kono
parents: 67
diff changeset
669
kono
parents: 67
diff changeset
670 /* Check for unstructured control flow: CFG not generated by structured
kono
parents: 67
diff changeset
671 if-then-else. */
kono
parents: 67
diff changeset
672 if (bb->succs->length () > 1)
kono
parents: 67
diff changeset
673 {
kono
parents: 67
diff changeset
674 edge e;
kono
parents: 67
diff changeset
675 edge_iterator ei;
kono
parents: 67
diff changeset
676 FOR_EACH_EDGE (e, ei, bb->succs)
kono
parents: 67
diff changeset
677 if (!dominated_by_p (CDI_POST_DOMINATORS, bb, e->dest)
kono
parents: 67
diff changeset
678 && !dominated_by_p (CDI_DOMINATORS, e->dest, bb))
kono
parents: 67
diff changeset
679 return true;
kono
parents: 67
diff changeset
680 }
kono
parents: 67
diff changeset
681
kono
parents: 67
diff changeset
682 /* Collect all loops in the current region. */
kono
parents: 67
diff changeset
683 loop_p loop = bb->loop_father;
kono
parents: 67
diff changeset
684 if (loop_in_sese_p (loop, scop))
kono
parents: 67
diff changeset
685 bitmap_set_bit (loops, loop->num);
kono
parents: 67
diff changeset
686
kono
parents: 67
diff changeset
687 /* Check for harmful statements in basic blocks part of the region. */
kono
parents: 67
diff changeset
688 for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
kono
parents: 67
diff changeset
689 !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents: 67
diff changeset
690 if (!stmt_simple_for_scop_p (scop, gsi_stmt (gsi), bb))
kono
parents: 67
diff changeset
691 return true;
kono
parents: 67
diff changeset
692
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
693 for (basic_block dom = first_dom_son (CDI_DOMINATORS, bb);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
694 dom;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
695 dom = next_dom_son (CDI_DOMINATORS, dom))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
696 if (dom != scop.exit->dest)
111
kono
parents: 67
diff changeset
697 worklist.safe_push (dom);
kono
parents: 67
diff changeset
698 }
kono
parents: 67
diff changeset
699
kono
parents: 67
diff changeset
700 /* Go through all loops and check that they are still valid in the combined
kono
parents: 67
diff changeset
701 scop. */
kono
parents: 67
diff changeset
702 unsigned j;
kono
parents: 67
diff changeset
703 bitmap_iterator bi;
kono
parents: 67
diff changeset
704 EXECUTE_IF_SET_IN_BITMAP (loops, 0, j, bi)
kono
parents: 67
diff changeset
705 {
kono
parents: 67
diff changeset
706 loop_p loop = (*current_loops->larray)[j];
kono
parents: 67
diff changeset
707 gcc_assert (loop->num == (int) j);
kono
parents: 67
diff changeset
708
kono
parents: 67
diff changeset
709 /* Check if the loop nests are to be optimized for speed. */
kono
parents: 67
diff changeset
710 if (! loop->inner
kono
parents: 67
diff changeset
711 && ! optimize_loop_for_speed_p (loop))
kono
parents: 67
diff changeset
712 {
kono
parents: 67
diff changeset
713 DEBUG_PRINT (dp << "[scop-detection-fail] loop_"
kono
parents: 67
diff changeset
714 << loop->num << " is not on a hot path.\n");
kono
parents: 67
diff changeset
715 return true;
kono
parents: 67
diff changeset
716 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
717
111
kono
parents: 67
diff changeset
718 if (! can_represent_loop (loop, scop))
kono
parents: 67
diff changeset
719 {
kono
parents: 67
diff changeset
720 DEBUG_PRINT (dp << "[scop-detection-fail] cannot represent loop_"
kono
parents: 67
diff changeset
721 << loop->num << "\n");
kono
parents: 67
diff changeset
722 return true;
kono
parents: 67
diff changeset
723 }
kono
parents: 67
diff changeset
724
kono
parents: 67
diff changeset
725 /* Check if all loop nests have at least one data reference.
kono
parents: 67
diff changeset
726 ??? This check is expensive and loops premature at this point.
kono
parents: 67
diff changeset
727 If important to retain we can pre-compute this for all innermost
kono
parents: 67
diff changeset
728 loops and reject those when we build a SESE region for a loop
kono
parents: 67
diff changeset
729 during SESE discovery. */
kono
parents: 67
diff changeset
730 if (! loop->inner
kono
parents: 67
diff changeset
731 && ! loop_nest_has_data_refs (loop))
kono
parents: 67
diff changeset
732 {
kono
parents: 67
diff changeset
733 DEBUG_PRINT (dp << "[scop-detection-fail] loop_" << loop->num
kono
parents: 67
diff changeset
734 << "does not have any data reference.\n");
kono
parents: 67
diff changeset
735 return true;
kono
parents: 67
diff changeset
736 }
kono
parents: 67
diff changeset
737 }
kono
parents: 67
diff changeset
738
kono
parents: 67
diff changeset
739 return false;
kono
parents: 67
diff changeset
740 }
kono
parents: 67
diff changeset
741
kono
parents: 67
diff changeset
742 /* Returns true if S1 subsumes/surrounds S2. */
kono
parents: 67
diff changeset
743 bool
kono
parents: 67
diff changeset
744 scop_detection::subsumes (sese_l s1, sese_l s2)
kono
parents: 67
diff changeset
745 {
kono
parents: 67
diff changeset
746 if (dominated_by_p (CDI_DOMINATORS, get_entry_bb (s2),
kono
parents: 67
diff changeset
747 get_entry_bb (s1))
kono
parents: 67
diff changeset
748 && dominated_by_p (CDI_POST_DOMINATORS, s2.exit->dest,
kono
parents: 67
diff changeset
749 s1.exit->dest))
kono
parents: 67
diff changeset
750 return true;
kono
parents: 67
diff changeset
751 return false;
kono
parents: 67
diff changeset
752 }
kono
parents: 67
diff changeset
753
kono
parents: 67
diff changeset
754 /* Remove a SCoP which is subsumed by S1. */
kono
parents: 67
diff changeset
755 void
kono
parents: 67
diff changeset
756 scop_detection::remove_subscops (sese_l s1)
kono
parents: 67
diff changeset
757 {
kono
parents: 67
diff changeset
758 int j;
kono
parents: 67
diff changeset
759 sese_l *s2;
kono
parents: 67
diff changeset
760 FOR_EACH_VEC_ELT_REVERSE (scops, j, s2)
kono
parents: 67
diff changeset
761 {
kono
parents: 67
diff changeset
762 if (subsumes (s1, *s2))
kono
parents: 67
diff changeset
763 {
kono
parents: 67
diff changeset
764 DEBUG_PRINT (dp << "Removing sub-SCoP";
kono
parents: 67
diff changeset
765 print_sese (dump_file, *s2));
kono
parents: 67
diff changeset
766 scops.unordered_remove (j);
kono
parents: 67
diff changeset
767 }
kono
parents: 67
diff changeset
768 }
kono
parents: 67
diff changeset
769 }
kono
parents: 67
diff changeset
770
kono
parents: 67
diff changeset
771 /* Returns true if S1 intersects with S2. Since we already know that S1 does
kono
parents: 67
diff changeset
772 not subsume S2 or vice-versa, we only check for entry bbs. */
kono
parents: 67
diff changeset
773
kono
parents: 67
diff changeset
774 bool
kono
parents: 67
diff changeset
775 scop_detection::intersects (sese_l s1, sese_l s2)
kono
parents: 67
diff changeset
776 {
kono
parents: 67
diff changeset
777 if (dominated_by_p (CDI_DOMINATORS, get_entry_bb (s2),
kono
parents: 67
diff changeset
778 get_entry_bb (s1))
kono
parents: 67
diff changeset
779 && !dominated_by_p (CDI_DOMINATORS, get_entry_bb (s2),
kono
parents: 67
diff changeset
780 get_exit_bb (s1)))
kono
parents: 67
diff changeset
781 return true;
kono
parents: 67
diff changeset
782 if ((s1.exit == s2.entry) || (s2.exit == s1.entry))
kono
parents: 67
diff changeset
783 return true;
kono
parents: 67
diff changeset
784
kono
parents: 67
diff changeset
785 return false;
kono
parents: 67
diff changeset
786 }
kono
parents: 67
diff changeset
787
kono
parents: 67
diff changeset
788 /* Remove one of the scops when it intersects with any other. */
kono
parents: 67
diff changeset
789
kono
parents: 67
diff changeset
790 void
kono
parents: 67
diff changeset
791 scop_detection::remove_intersecting_scops (sese_l s1)
kono
parents: 67
diff changeset
792 {
kono
parents: 67
diff changeset
793 int j;
kono
parents: 67
diff changeset
794 sese_l *s2;
kono
parents: 67
diff changeset
795 FOR_EACH_VEC_ELT_REVERSE (scops, j, s2)
kono
parents: 67
diff changeset
796 {
kono
parents: 67
diff changeset
797 if (intersects (s1, *s2))
kono
parents: 67
diff changeset
798 {
kono
parents: 67
diff changeset
799 DEBUG_PRINT (dp << "Removing intersecting SCoP";
kono
parents: 67
diff changeset
800 print_sese (dump_file, *s2);
kono
parents: 67
diff changeset
801 dp << "Intersects with:";
kono
parents: 67
diff changeset
802 print_sese (dump_file, s1));
kono
parents: 67
diff changeset
803 scops.unordered_remove (j);
kono
parents: 67
diff changeset
804 }
kono
parents: 67
diff changeset
805 }
kono
parents: 67
diff changeset
806 }
kono
parents: 67
diff changeset
807
kono
parents: 67
diff changeset
808 /* Something like "n * m" is not allowed. */
kono
parents: 67
diff changeset
809
kono
parents: 67
diff changeset
810 bool
kono
parents: 67
diff changeset
811 scop_detection::graphite_can_represent_init (tree e)
kono
parents: 67
diff changeset
812 {
kono
parents: 67
diff changeset
813 switch (TREE_CODE (e))
kono
parents: 67
diff changeset
814 {
kono
parents: 67
diff changeset
815 case POLYNOMIAL_CHREC:
kono
parents: 67
diff changeset
816 return graphite_can_represent_init (CHREC_LEFT (e))
kono
parents: 67
diff changeset
817 && graphite_can_represent_init (CHREC_RIGHT (e));
kono
parents: 67
diff changeset
818
kono
parents: 67
diff changeset
819 case MULT_EXPR:
kono
parents: 67
diff changeset
820 if (chrec_contains_symbols (TREE_OPERAND (e, 0)))
kono
parents: 67
diff changeset
821 return graphite_can_represent_init (TREE_OPERAND (e, 0))
kono
parents: 67
diff changeset
822 && tree_fits_shwi_p (TREE_OPERAND (e, 1));
kono
parents: 67
diff changeset
823 else
kono
parents: 67
diff changeset
824 return graphite_can_represent_init (TREE_OPERAND (e, 1))
kono
parents: 67
diff changeset
825 && tree_fits_shwi_p (TREE_OPERAND (e, 0));
kono
parents: 67
diff changeset
826
kono
parents: 67
diff changeset
827 case PLUS_EXPR:
kono
parents: 67
diff changeset
828 case POINTER_PLUS_EXPR:
kono
parents: 67
diff changeset
829 case MINUS_EXPR:
kono
parents: 67
diff changeset
830 return graphite_can_represent_init (TREE_OPERAND (e, 0))
kono
parents: 67
diff changeset
831 && graphite_can_represent_init (TREE_OPERAND (e, 1));
kono
parents: 67
diff changeset
832
kono
parents: 67
diff changeset
833 case NEGATE_EXPR:
kono
parents: 67
diff changeset
834 case BIT_NOT_EXPR:
kono
parents: 67
diff changeset
835 CASE_CONVERT:
kono
parents: 67
diff changeset
836 case NON_LVALUE_EXPR:
kono
parents: 67
diff changeset
837 return graphite_can_represent_init (TREE_OPERAND (e, 0));
kono
parents: 67
diff changeset
838
kono
parents: 67
diff changeset
839 default:
kono
parents: 67
diff changeset
840 break;
kono
parents: 67
diff changeset
841 }
kono
parents: 67
diff changeset
842
kono
parents: 67
diff changeset
843 return true;
kono
parents: 67
diff changeset
844 }
kono
parents: 67
diff changeset
845
kono
parents: 67
diff changeset
846 /* Return true when SCEV can be represented in the polyhedral model.
kono
parents: 67
diff changeset
847
kono
parents: 67
diff changeset
848 An expression can be represented, if it can be expressed as an
kono
parents: 67
diff changeset
849 affine expression. For loops (i, j) and parameters (m, n) all
kono
parents: 67
diff changeset
850 affine expressions are of the form:
kono
parents: 67
diff changeset
851
kono
parents: 67
diff changeset
852 x1 * i + x2 * j + x3 * m + x4 * n + x5 * 1 where x1..x5 element of Z
kono
parents: 67
diff changeset
853
kono
parents: 67
diff changeset
854 1 i + 20 j + (-2) m + 25
kono
parents: 67
diff changeset
855
kono
parents: 67
diff changeset
856 Something like "i * n" or "n * m" is not allowed. */
kono
parents: 67
diff changeset
857
kono
parents: 67
diff changeset
858 bool
kono
parents: 67
diff changeset
859 scop_detection::graphite_can_represent_scev (sese_l scop, tree scev)
kono
parents: 67
diff changeset
860 {
kono
parents: 67
diff changeset
861 if (chrec_contains_undetermined (scev))
kono
parents: 67
diff changeset
862 return false;
kono
parents: 67
diff changeset
863
kono
parents: 67
diff changeset
864 switch (TREE_CODE (scev))
kono
parents: 67
diff changeset
865 {
kono
parents: 67
diff changeset
866 case NEGATE_EXPR:
kono
parents: 67
diff changeset
867 case BIT_NOT_EXPR:
kono
parents: 67
diff changeset
868 CASE_CONVERT:
kono
parents: 67
diff changeset
869 case NON_LVALUE_EXPR:
kono
parents: 67
diff changeset
870 return graphite_can_represent_scev (scop, TREE_OPERAND (scev, 0));
kono
parents: 67
diff changeset
871
kono
parents: 67
diff changeset
872 case PLUS_EXPR:
kono
parents: 67
diff changeset
873 case POINTER_PLUS_EXPR:
kono
parents: 67
diff changeset
874 case MINUS_EXPR:
kono
parents: 67
diff changeset
875 return graphite_can_represent_scev (scop, TREE_OPERAND (scev, 0))
kono
parents: 67
diff changeset
876 && graphite_can_represent_scev (scop, TREE_OPERAND (scev, 1));
kono
parents: 67
diff changeset
877
kono
parents: 67
diff changeset
878 case MULT_EXPR:
kono
parents: 67
diff changeset
879 return !CONVERT_EXPR_CODE_P (TREE_CODE (TREE_OPERAND (scev, 0)))
kono
parents: 67
diff changeset
880 && !CONVERT_EXPR_CODE_P (TREE_CODE (TREE_OPERAND (scev, 1)))
kono
parents: 67
diff changeset
881 && !(chrec_contains_symbols (TREE_OPERAND (scev, 0))
kono
parents: 67
diff changeset
882 && chrec_contains_symbols (TREE_OPERAND (scev, 1)))
kono
parents: 67
diff changeset
883 && graphite_can_represent_init (scev)
kono
parents: 67
diff changeset
884 && graphite_can_represent_scev (scop, TREE_OPERAND (scev, 0))
kono
parents: 67
diff changeset
885 && graphite_can_represent_scev (scop, TREE_OPERAND (scev, 1));
kono
parents: 67
diff changeset
886
kono
parents: 67
diff changeset
887 case POLYNOMIAL_CHREC:
kono
parents: 67
diff changeset
888 /* Check for constant strides. With a non constant stride of
kono
parents: 67
diff changeset
889 'n' we would have a value of 'iv * n'. Also check that the
kono
parents: 67
diff changeset
890 initial value can represented: for example 'n * m' cannot be
kono
parents: 67
diff changeset
891 represented. */
kono
parents: 67
diff changeset
892 gcc_assert (loop_in_sese_p (get_loop (cfun,
kono
parents: 67
diff changeset
893 CHREC_VARIABLE (scev)), scop));
kono
parents: 67
diff changeset
894 if (!evolution_function_right_is_integer_cst (scev)
kono
parents: 67
diff changeset
895 || !graphite_can_represent_init (scev))
kono
parents: 67
diff changeset
896 return false;
kono
parents: 67
diff changeset
897 return graphite_can_represent_scev (scop, CHREC_LEFT (scev));
kono
parents: 67
diff changeset
898
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
899 case ADDR_EXPR:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
900 /* We cannot encode addresses for ISL. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
901 return false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
902
111
kono
parents: 67
diff changeset
903 default:
kono
parents: 67
diff changeset
904 break;
kono
parents: 67
diff changeset
905 }
kono
parents: 67
diff changeset
906
kono
parents: 67
diff changeset
907 /* Only affine functions can be represented. */
kono
parents: 67
diff changeset
908 if (tree_contains_chrecs (scev, NULL) || !scev_is_linear_expression (scev))
kono
parents: 67
diff changeset
909 return false;
kono
parents: 67
diff changeset
910
kono
parents: 67
diff changeset
911 return true;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff changeset
913
111
kono
parents: 67
diff changeset
914 /* Return true when EXPR can be represented in the polyhedral model.
kono
parents: 67
diff changeset
915
kono
parents: 67
diff changeset
916 This means an expression can be represented, if it is linear with respect to
kono
parents: 67
diff changeset
917 the loops and the strides are non parametric. LOOP is the place where the
kono
parents: 67
diff changeset
918 expr will be evaluated. SCOP defines the region we analyse. */
kono
parents: 67
diff changeset
919
kono
parents: 67
diff changeset
920 bool
kono
parents: 67
diff changeset
921 scop_detection::graphite_can_represent_expr (sese_l scop, loop_p loop,
kono
parents: 67
diff changeset
922 tree expr)
kono
parents: 67
diff changeset
923 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
924 tree scev = cached_scalar_evolution_in_region (scop, loop, expr);
111
kono
parents: 67
diff changeset
925 return graphite_can_represent_scev (scop, scev);
kono
parents: 67
diff changeset
926 }
kono
parents: 67
diff changeset
927
kono
parents: 67
diff changeset
928 /* Return true if the data references of STMT can be represented by Graphite.
kono
parents: 67
diff changeset
929 We try to analyze the data references in a loop contained in the SCOP. */
kono
parents: 67
diff changeset
930
kono
parents: 67
diff changeset
931 bool
kono
parents: 67
diff changeset
932 scop_detection::stmt_has_simple_data_refs_p (sese_l scop, gimple *stmt)
kono
parents: 67
diff changeset
933 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
934 edge nest = scop.entry;
111
kono
parents: 67
diff changeset
935 loop_p loop = loop_containing_stmt (stmt);
kono
parents: 67
diff changeset
936 if (!loop_in_sese_p (loop, scop))
kono
parents: 67
diff changeset
937 loop = NULL;
kono
parents: 67
diff changeset
938
kono
parents: 67
diff changeset
939 auto_vec<data_reference_p> drs;
kono
parents: 67
diff changeset
940 if (! graphite_find_data_references_in_stmt (nest, loop, stmt, &drs))
kono
parents: 67
diff changeset
941 return false;
kono
parents: 67
diff changeset
942
kono
parents: 67
diff changeset
943 int j;
kono
parents: 67
diff changeset
944 data_reference_p dr;
kono
parents: 67
diff changeset
945 FOR_EACH_VEC_ELT (drs, j, dr)
kono
parents: 67
diff changeset
946 {
kono
parents: 67
diff changeset
947 for (unsigned i = 0; i < DR_NUM_DIMENSIONS (dr); ++i)
kono
parents: 67
diff changeset
948 if (! graphite_can_represent_scev (scop, DR_ACCESS_FN (dr, i)))
kono
parents: 67
diff changeset
949 return false;
kono
parents: 67
diff changeset
950 }
kono
parents: 67
diff changeset
951
kono
parents: 67
diff changeset
952 return true;
kono
parents: 67
diff changeset
953 }
kono
parents: 67
diff changeset
954
kono
parents: 67
diff changeset
955 /* GIMPLE_ASM and GIMPLE_CALL may embed arbitrary side effects.
kono
parents: 67
diff changeset
956 Calls have side-effects, except those to const or pure
kono
parents: 67
diff changeset
957 functions. */
kono
parents: 67
diff changeset
958
kono
parents: 67
diff changeset
959 static bool
kono
parents: 67
diff changeset
960 stmt_has_side_effects (gimple *stmt)
kono
parents: 67
diff changeset
961 {
kono
parents: 67
diff changeset
962 if (gimple_has_volatile_ops (stmt)
kono
parents: 67
diff changeset
963 || (gimple_code (stmt) == GIMPLE_CALL
kono
parents: 67
diff changeset
964 && !(gimple_call_flags (stmt) & (ECF_CONST | ECF_PURE)))
kono
parents: 67
diff changeset
965 || (gimple_code (stmt) == GIMPLE_ASM))
kono
parents: 67
diff changeset
966 {
kono
parents: 67
diff changeset
967 DEBUG_PRINT (dp << "[scop-detection-fail] "
kono
parents: 67
diff changeset
968 << "Statement has side-effects:\n";
kono
parents: 67
diff changeset
969 print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS | TDF_MEMSYMS));
kono
parents: 67
diff changeset
970 return true;
kono
parents: 67
diff changeset
971 }
kono
parents: 67
diff changeset
972 return false;
kono
parents: 67
diff changeset
973 }
kono
parents: 67
diff changeset
974
kono
parents: 67
diff changeset
975 /* Return true only when STMT is simple enough for being handled by Graphite.
kono
parents: 67
diff changeset
976 This depends on SCOP, as the parameters are initialized relatively to
kono
parents: 67
diff changeset
977 this basic block, the linear functions are initialized based on the outermost
kono
parents: 67
diff changeset
978 loop containing STMT inside the SCOP. BB is the place where we try to
kono
parents: 67
diff changeset
979 evaluate the STMT. */
kono
parents: 67
diff changeset
980
kono
parents: 67
diff changeset
981 bool
kono
parents: 67
diff changeset
982 scop_detection::stmt_simple_for_scop_p (sese_l scop, gimple *stmt,
kono
parents: 67
diff changeset
983 basic_block bb) const
kono
parents: 67
diff changeset
984 {
kono
parents: 67
diff changeset
985 gcc_assert (scop);
kono
parents: 67
diff changeset
986
kono
parents: 67
diff changeset
987 if (is_gimple_debug (stmt))
kono
parents: 67
diff changeset
988 return true;
kono
parents: 67
diff changeset
989
kono
parents: 67
diff changeset
990 if (stmt_has_side_effects (stmt))
kono
parents: 67
diff changeset
991 return false;
kono
parents: 67
diff changeset
992
kono
parents: 67
diff changeset
993 if (!stmt_has_simple_data_refs_p (scop, stmt))
kono
parents: 67
diff changeset
994 {
kono
parents: 67
diff changeset
995 DEBUG_PRINT (dp << "[scop-detection-fail] "
kono
parents: 67
diff changeset
996 << "Graphite cannot handle data-refs in stmt:\n";
kono
parents: 67
diff changeset
997 print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS|TDF_MEMSYMS););
kono
parents: 67
diff changeset
998 return false;
kono
parents: 67
diff changeset
999 }
kono
parents: 67
diff changeset
1000
kono
parents: 67
diff changeset
1001 switch (gimple_code (stmt))
kono
parents: 67
diff changeset
1002 {
kono
parents: 67
diff changeset
1003 case GIMPLE_LABEL:
kono
parents: 67
diff changeset
1004 return true;
kono
parents: 67
diff changeset
1005
kono
parents: 67
diff changeset
1006 case GIMPLE_COND:
kono
parents: 67
diff changeset
1007 {
kono
parents: 67
diff changeset
1008 /* We can handle all binary comparisons. Inequalities are
kono
parents: 67
diff changeset
1009 also supported as they can be represented with union of
kono
parents: 67
diff changeset
1010 polyhedra. */
kono
parents: 67
diff changeset
1011 enum tree_code code = gimple_cond_code (stmt);
kono
parents: 67
diff changeset
1012 if (!(code == LT_EXPR
kono
parents: 67
diff changeset
1013 || code == GT_EXPR
kono
parents: 67
diff changeset
1014 || code == LE_EXPR
kono
parents: 67
diff changeset
1015 || code == GE_EXPR
kono
parents: 67
diff changeset
1016 || code == EQ_EXPR
kono
parents: 67
diff changeset
1017 || code == NE_EXPR))
kono
parents: 67
diff changeset
1018 {
kono
parents: 67
diff changeset
1019 DEBUG_PRINT (dp << "[scop-detection-fail] "
kono
parents: 67
diff changeset
1020 << "Graphite cannot handle cond stmt:\n";
kono
parents: 67
diff changeset
1021 print_gimple_stmt (dump_file, stmt, 0,
kono
parents: 67
diff changeset
1022 TDF_VOPS | TDF_MEMSYMS));
kono
parents: 67
diff changeset
1023 return false;
kono
parents: 67
diff changeset
1024 }
kono
parents: 67
diff changeset
1025
kono
parents: 67
diff changeset
1026 loop_p loop = bb->loop_father;
kono
parents: 67
diff changeset
1027 for (unsigned i = 0; i < 2; ++i)
kono
parents: 67
diff changeset
1028 {
kono
parents: 67
diff changeset
1029 tree op = gimple_op (stmt, i);
kono
parents: 67
diff changeset
1030 if (!graphite_can_represent_expr (scop, loop, op)
kono
parents: 67
diff changeset
1031 /* We can only constrain on integer type. */
kono
parents: 67
diff changeset
1032 || ! INTEGRAL_TYPE_P (TREE_TYPE (op)))
kono
parents: 67
diff changeset
1033 {
kono
parents: 67
diff changeset
1034 DEBUG_PRINT (dp << "[scop-detection-fail] "
kono
parents: 67
diff changeset
1035 << "Graphite cannot represent stmt:\n";
kono
parents: 67
diff changeset
1036 print_gimple_stmt (dump_file, stmt, 0,
kono
parents: 67
diff changeset
1037 TDF_VOPS | TDF_MEMSYMS));
kono
parents: 67
diff changeset
1038 return false;
kono
parents: 67
diff changeset
1039 }
kono
parents: 67
diff changeset
1040 }
kono
parents: 67
diff changeset
1041
kono
parents: 67
diff changeset
1042 return true;
kono
parents: 67
diff changeset
1043 }
kono
parents: 67
diff changeset
1044
kono
parents: 67
diff changeset
1045 case GIMPLE_ASSIGN:
kono
parents: 67
diff changeset
1046 case GIMPLE_CALL:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1047 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1048 tree op, lhs = gimple_get_lhs (stmt);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1049 ssa_op_iter i;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1050 /* If we are not going to instantiate the stmt do not require
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1051 its operands to be instantiatable at this point. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1052 if (lhs
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1053 && TREE_CODE (lhs) == SSA_NAME
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1054 && scev_analyzable_p (lhs, scop))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1055 return true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1056 /* Verify that if we can analyze operands at their def site we
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1057 also can represent them when analyzed at their uses. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1058 FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_USE)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1059 if (scev_analyzable_p (op, scop)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1060 && chrec_contains_undetermined
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1061 (cached_scalar_evolution_in_region (scop,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1062 bb->loop_father, op)))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1063 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1064 DEBUG_PRINT (dp << "[scop-detection-fail] "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1065 << "Graphite cannot code-gen stmt:\n";
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1066 print_gimple_stmt (dump_file, stmt, 0,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1067 TDF_VOPS | TDF_MEMSYMS));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1068 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1069 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1070 return true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1071 }
111
kono
parents: 67
diff changeset
1072
kono
parents: 67
diff changeset
1073 default:
kono
parents: 67
diff changeset
1074 /* These nodes cut a new scope. */
kono
parents: 67
diff changeset
1075 DEBUG_PRINT (
kono
parents: 67
diff changeset
1076 dp << "[scop-detection-fail] "
kono
parents: 67
diff changeset
1077 << "Gimple stmt not handled in Graphite:\n";
kono
parents: 67
diff changeset
1078 print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS | TDF_MEMSYMS));
kono
parents: 67
diff changeset
1079 return false;
kono
parents: 67
diff changeset
1080 }
kono
parents: 67
diff changeset
1081 }
kono
parents: 67
diff changeset
1082
kono
parents: 67
diff changeset
1083 /* Returns the number of pbbs that are in loops contained in SCOP. */
kono
parents: 67
diff changeset
1084
kono
parents: 67
diff changeset
1085 int
kono
parents: 67
diff changeset
1086 scop_detection::nb_pbbs_in_loops (scop_p scop)
kono
parents: 67
diff changeset
1087 {
kono
parents: 67
diff changeset
1088 int i;
kono
parents: 67
diff changeset
1089 poly_bb_p pbb;
kono
parents: 67
diff changeset
1090 int res = 0;
kono
parents: 67
diff changeset
1091
kono
parents: 67
diff changeset
1092 FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
kono
parents: 67
diff changeset
1093 if (loop_in_sese_p (gbb_loop (PBB_BLACK_BOX (pbb)), scop->scop_info->region))
kono
parents: 67
diff changeset
1094 res++;
kono
parents: 67
diff changeset
1095
kono
parents: 67
diff changeset
1096 return res;
kono
parents: 67
diff changeset
1097 }
kono
parents: 67
diff changeset
1098
kono
parents: 67
diff changeset
1099 /* Assigns the parameter NAME an index in REGION. */
kono
parents: 67
diff changeset
1100
kono
parents: 67
diff changeset
1101 static void
kono
parents: 67
diff changeset
1102 assign_parameter_index_in_region (tree name, sese_info_p region)
kono
parents: 67
diff changeset
1103 {
kono
parents: 67
diff changeset
1104 gcc_assert (TREE_CODE (name) == SSA_NAME
kono
parents: 67
diff changeset
1105 && INTEGRAL_TYPE_P (TREE_TYPE (name))
kono
parents: 67
diff changeset
1106 && ! defined_in_sese_p (name, region->region));
kono
parents: 67
diff changeset
1107 int i;
kono
parents: 67
diff changeset
1108 tree p;
kono
parents: 67
diff changeset
1109 FOR_EACH_VEC_ELT (region->params, i, p)
kono
parents: 67
diff changeset
1110 if (p == name)
kono
parents: 67
diff changeset
1111 return;
kono
parents: 67
diff changeset
1112
kono
parents: 67
diff changeset
1113 region->params.safe_push (name);
kono
parents: 67
diff changeset
1114 }
kono
parents: 67
diff changeset
1115
kono
parents: 67
diff changeset
1116 /* In the context of sese S, scan the expression E and translate it to
kono
parents: 67
diff changeset
1117 a linear expression C. When parsing a symbolic multiplication, K
kono
parents: 67
diff changeset
1118 represents the constant multiplier of an expression containing
kono
parents: 67
diff changeset
1119 parameters. */
kono
parents: 67
diff changeset
1120
kono
parents: 67
diff changeset
1121 static void
kono
parents: 67
diff changeset
1122 scan_tree_for_params (sese_info_p s, tree e)
kono
parents: 67
diff changeset
1123 {
kono
parents: 67
diff changeset
1124 if (e == chrec_dont_know)
kono
parents: 67
diff changeset
1125 return;
kono
parents: 67
diff changeset
1126
kono
parents: 67
diff changeset
1127 switch (TREE_CODE (e))
kono
parents: 67
diff changeset
1128 {
kono
parents: 67
diff changeset
1129 case POLYNOMIAL_CHREC:
kono
parents: 67
diff changeset
1130 scan_tree_for_params (s, CHREC_LEFT (e));
kono
parents: 67
diff changeset
1131 break;
kono
parents: 67
diff changeset
1132
kono
parents: 67
diff changeset
1133 case MULT_EXPR:
kono
parents: 67
diff changeset
1134 if (chrec_contains_symbols (TREE_OPERAND (e, 0)))
kono
parents: 67
diff changeset
1135 scan_tree_for_params (s, TREE_OPERAND (e, 0));
kono
parents: 67
diff changeset
1136 else
kono
parents: 67
diff changeset
1137 scan_tree_for_params (s, TREE_OPERAND (e, 1));
kono
parents: 67
diff changeset
1138 break;
kono
parents: 67
diff changeset
1139
kono
parents: 67
diff changeset
1140 case PLUS_EXPR:
kono
parents: 67
diff changeset
1141 case POINTER_PLUS_EXPR:
kono
parents: 67
diff changeset
1142 case MINUS_EXPR:
kono
parents: 67
diff changeset
1143 scan_tree_for_params (s, TREE_OPERAND (e, 0));
kono
parents: 67
diff changeset
1144 scan_tree_for_params (s, TREE_OPERAND (e, 1));
kono
parents: 67
diff changeset
1145 break;
kono
parents: 67
diff changeset
1146
kono
parents: 67
diff changeset
1147 case NEGATE_EXPR:
kono
parents: 67
diff changeset
1148 case BIT_NOT_EXPR:
kono
parents: 67
diff changeset
1149 CASE_CONVERT:
kono
parents: 67
diff changeset
1150 case NON_LVALUE_EXPR:
kono
parents: 67
diff changeset
1151 scan_tree_for_params (s, TREE_OPERAND (e, 0));
kono
parents: 67
diff changeset
1152 break;
kono
parents: 67
diff changeset
1153
kono
parents: 67
diff changeset
1154 case SSA_NAME:
kono
parents: 67
diff changeset
1155 assign_parameter_index_in_region (e, s);
kono
parents: 67
diff changeset
1156 break;
kono
parents: 67
diff changeset
1157
kono
parents: 67
diff changeset
1158 case INTEGER_CST:
kono
parents: 67
diff changeset
1159 case ADDR_EXPR:
kono
parents: 67
diff changeset
1160 case REAL_CST:
kono
parents: 67
diff changeset
1161 case COMPLEX_CST:
kono
parents: 67
diff changeset
1162 case VECTOR_CST:
kono
parents: 67
diff changeset
1163 break;
kono
parents: 67
diff changeset
1164
kono
parents: 67
diff changeset
1165 default:
kono
parents: 67
diff changeset
1166 gcc_unreachable ();
kono
parents: 67
diff changeset
1167 break;
kono
parents: 67
diff changeset
1168 }
kono
parents: 67
diff changeset
1169 }
kono
parents: 67
diff changeset
1170
kono
parents: 67
diff changeset
1171 /* Find parameters with respect to REGION in BB. We are looking in memory
kono
parents: 67
diff changeset
1172 access functions, conditions and loop bounds. */
kono
parents: 67
diff changeset
1173
kono
parents: 67
diff changeset
1174 static void
kono
parents: 67
diff changeset
1175 find_params_in_bb (sese_info_p region, gimple_poly_bb_p gbb)
kono
parents: 67
diff changeset
1176 {
kono
parents: 67
diff changeset
1177 /* Find parameters in the access functions of data references. */
kono
parents: 67
diff changeset
1178 int i;
kono
parents: 67
diff changeset
1179 data_reference_p dr;
kono
parents: 67
diff changeset
1180 FOR_EACH_VEC_ELT (GBB_DATA_REFS (gbb), i, dr)
kono
parents: 67
diff changeset
1181 for (unsigned j = 0; j < DR_NUM_DIMENSIONS (dr); j++)
kono
parents: 67
diff changeset
1182 scan_tree_for_params (region, DR_ACCESS_FN (dr, j));
kono
parents: 67
diff changeset
1183
kono
parents: 67
diff changeset
1184 /* Find parameters in conditional statements. */
kono
parents: 67
diff changeset
1185 gimple *stmt;
kono
parents: 67
diff changeset
1186 FOR_EACH_VEC_ELT (GBB_CONDITIONS (gbb), i, stmt)
kono
parents: 67
diff changeset
1187 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1188 loop_p loop = gimple_bb (stmt)->loop_father;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1189 tree lhs = cached_scalar_evolution_in_region (region->region, loop,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1190 gimple_cond_lhs (stmt));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1191 tree rhs = cached_scalar_evolution_in_region (region->region, loop,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1192 gimple_cond_rhs (stmt));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1193 gcc_assert (!chrec_contains_undetermined (lhs)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1194 && !chrec_contains_undetermined (rhs));
111
kono
parents: 67
diff changeset
1195
kono
parents: 67
diff changeset
1196 scan_tree_for_params (region, lhs);
kono
parents: 67
diff changeset
1197 scan_tree_for_params (region, rhs);
kono
parents: 67
diff changeset
1198 }
kono
parents: 67
diff changeset
1199 }
kono
parents: 67
diff changeset
1200
kono
parents: 67
diff changeset
1201 /* Record the parameters used in the SCOP BBs. A variable is a parameter
kono
parents: 67
diff changeset
1202 in a scop if it does not vary during the execution of that scop. */
kono
parents: 67
diff changeset
1203
kono
parents: 67
diff changeset
1204 static void
kono
parents: 67
diff changeset
1205 find_scop_parameters (scop_p scop)
kono
parents: 67
diff changeset
1206 {
kono
parents: 67
diff changeset
1207 unsigned i;
kono
parents: 67
diff changeset
1208 sese_info_p region = scop->scop_info;
kono
parents: 67
diff changeset
1209
kono
parents: 67
diff changeset
1210 /* Parameters used in loop bounds are processed during gather_bbs. */
kono
parents: 67
diff changeset
1211
kono
parents: 67
diff changeset
1212 /* Find the parameters used in data accesses. */
kono
parents: 67
diff changeset
1213 poly_bb_p pbb;
kono
parents: 67
diff changeset
1214 FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
kono
parents: 67
diff changeset
1215 find_params_in_bb (region, PBB_BLACK_BOX (pbb));
kono
parents: 67
diff changeset
1216
kono
parents: 67
diff changeset
1217 int nbp = sese_nb_params (region);
kono
parents: 67
diff changeset
1218 scop_set_nb_params (scop, nbp);
kono
parents: 67
diff changeset
1219 }
kono
parents: 67
diff changeset
1220
kono
parents: 67
diff changeset
1221 static void
kono
parents: 67
diff changeset
1222 add_write (vec<tree> *writes, tree def)
kono
parents: 67
diff changeset
1223 {
kono
parents: 67
diff changeset
1224 writes->safe_push (def);
kono
parents: 67
diff changeset
1225 DEBUG_PRINT (dp << "Adding scalar write: ";
kono
parents: 67
diff changeset
1226 print_generic_expr (dump_file, def);
kono
parents: 67
diff changeset
1227 dp << "\nFrom stmt: ";
kono
parents: 67
diff changeset
1228 print_gimple_stmt (dump_file,
kono
parents: 67
diff changeset
1229 SSA_NAME_DEF_STMT (def), 0));
kono
parents: 67
diff changeset
1230 }
kono
parents: 67
diff changeset
1231
kono
parents: 67
diff changeset
1232 static void
kono
parents: 67
diff changeset
1233 add_read (vec<scalar_use> *reads, tree use, gimple *use_stmt)
kono
parents: 67
diff changeset
1234 {
kono
parents: 67
diff changeset
1235 DEBUG_PRINT (dp << "Adding scalar read: ";
kono
parents: 67
diff changeset
1236 print_generic_expr (dump_file, use);
kono
parents: 67
diff changeset
1237 dp << "\nFrom stmt: ";
kono
parents: 67
diff changeset
1238 print_gimple_stmt (dump_file, use_stmt, 0));
kono
parents: 67
diff changeset
1239 reads->safe_push (std::make_pair (use_stmt, use));
kono
parents: 67
diff changeset
1240 }
kono
parents: 67
diff changeset
1241
kono
parents: 67
diff changeset
1242
kono
parents: 67
diff changeset
1243 /* Record DEF if it is used in other bbs different than DEF_BB in the SCOP. */
kono
parents: 67
diff changeset
1244
kono
parents: 67
diff changeset
1245 static void
kono
parents: 67
diff changeset
1246 build_cross_bb_scalars_def (scop_p scop, tree def, basic_block def_bb,
kono
parents: 67
diff changeset
1247 vec<tree> *writes)
kono
parents: 67
diff changeset
1248 {
kono
parents: 67
diff changeset
1249 if (!is_gimple_reg (def))
kono
parents: 67
diff changeset
1250 return;
kono
parents: 67
diff changeset
1251
kono
parents: 67
diff changeset
1252 bool scev_analyzable = scev_analyzable_p (def, scop->scop_info->region);
kono
parents: 67
diff changeset
1253
kono
parents: 67
diff changeset
1254 gimple *use_stmt;
kono
parents: 67
diff changeset
1255 imm_use_iterator imm_iter;
kono
parents: 67
diff changeset
1256 FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
kono
parents: 67
diff changeset
1257 /* Do not gather scalar variables that can be analyzed by SCEV as they can
kono
parents: 67
diff changeset
1258 be generated out of the induction variables. */
kono
parents: 67
diff changeset
1259 if ((! scev_analyzable
kono
parents: 67
diff changeset
1260 /* But gather SESE liveouts as we otherwise fail to rewrite their
kono
parents: 67
diff changeset
1261 exit PHIs. */
kono
parents: 67
diff changeset
1262 || ! bb_in_sese_p (gimple_bb (use_stmt), scop->scop_info->region))
kono
parents: 67
diff changeset
1263 && (def_bb != gimple_bb (use_stmt) && !is_gimple_debug (use_stmt)))
kono
parents: 67
diff changeset
1264 {
kono
parents: 67
diff changeset
1265 add_write (writes, def);
kono
parents: 67
diff changeset
1266 /* This is required by the FOR_EACH_IMM_USE_STMT when we want to break
kono
parents: 67
diff changeset
1267 before all the uses have been visited. */
kono
parents: 67
diff changeset
1268 BREAK_FROM_IMM_USE_STMT (imm_iter);
kono
parents: 67
diff changeset
1269 }
kono
parents: 67
diff changeset
1270 }
kono
parents: 67
diff changeset
1271
kono
parents: 67
diff changeset
1272 /* Record USE if it is defined in other bbs different than USE_STMT
kono
parents: 67
diff changeset
1273 in the SCOP. */
kono
parents: 67
diff changeset
1274
kono
parents: 67
diff changeset
1275 static void
kono
parents: 67
diff changeset
1276 build_cross_bb_scalars_use (scop_p scop, tree use, gimple *use_stmt,
kono
parents: 67
diff changeset
1277 vec<scalar_use> *reads)
kono
parents: 67
diff changeset
1278 {
kono
parents: 67
diff changeset
1279 if (!is_gimple_reg (use))
kono
parents: 67
diff changeset
1280 return;
kono
parents: 67
diff changeset
1281
kono
parents: 67
diff changeset
1282 /* Do not gather scalar variables that can be analyzed by SCEV as they can be
kono
parents: 67
diff changeset
1283 generated out of the induction variables. */
kono
parents: 67
diff changeset
1284 if (scev_analyzable_p (use, scop->scop_info->region))
kono
parents: 67
diff changeset
1285 return;
kono
parents: 67
diff changeset
1286
kono
parents: 67
diff changeset
1287 gimple *def_stmt = SSA_NAME_DEF_STMT (use);
kono
parents: 67
diff changeset
1288 if (gimple_bb (def_stmt) != gimple_bb (use_stmt))
kono
parents: 67
diff changeset
1289 add_read (reads, use, use_stmt);
kono
parents: 67
diff changeset
1290 }
kono
parents: 67
diff changeset
1291
kono
parents: 67
diff changeset
1292 /* Generates a polyhedral black box only if the bb contains interesting
kono
parents: 67
diff changeset
1293 information. */
kono
parents: 67
diff changeset
1294
kono
parents: 67
diff changeset
1295 static gimple_poly_bb_p
kono
parents: 67
diff changeset
1296 try_generate_gimple_bb (scop_p scop, basic_block bb)
kono
parents: 67
diff changeset
1297 {
kono
parents: 67
diff changeset
1298 vec<data_reference_p> drs = vNULL;
kono
parents: 67
diff changeset
1299 vec<tree> writes = vNULL;
kono
parents: 67
diff changeset
1300 vec<scalar_use> reads = vNULL;
kono
parents: 67
diff changeset
1301
kono
parents: 67
diff changeset
1302 sese_l region = scop->scop_info->region;
kono
parents: 67
diff changeset
1303 edge nest = region.entry;
kono
parents: 67
diff changeset
1304 loop_p loop = bb->loop_father;
kono
parents: 67
diff changeset
1305 if (!loop_in_sese_p (loop, region))
kono
parents: 67
diff changeset
1306 loop = NULL;
kono
parents: 67
diff changeset
1307
kono
parents: 67
diff changeset
1308 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
kono
parents: 67
diff changeset
1309 gsi_next (&gsi))
kono
parents: 67
diff changeset
1310 {
kono
parents: 67
diff changeset
1311 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
1312 if (is_gimple_debug (stmt))
kono
parents: 67
diff changeset
1313 continue;
kono
parents: 67
diff changeset
1314
kono
parents: 67
diff changeset
1315 graphite_find_data_references_in_stmt (nest, loop, stmt, &drs);
kono
parents: 67
diff changeset
1316
kono
parents: 67
diff changeset
1317 tree def = gimple_get_lhs (stmt);
kono
parents: 67
diff changeset
1318 if (def)
kono
parents: 67
diff changeset
1319 build_cross_bb_scalars_def (scop, def, gimple_bb (stmt), &writes);
kono
parents: 67
diff changeset
1320
kono
parents: 67
diff changeset
1321 ssa_op_iter iter;
kono
parents: 67
diff changeset
1322 tree use;
kono
parents: 67
diff changeset
1323 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
kono
parents: 67
diff changeset
1324 build_cross_bb_scalars_use (scop, use, stmt, &reads);
kono
parents: 67
diff changeset
1325 }
kono
parents: 67
diff changeset
1326
kono
parents: 67
diff changeset
1327 /* Handle defs and uses in PHIs. Those need special treatment given
kono
parents: 67
diff changeset
1328 that we have to present ISL with sth that looks like we've rewritten
kono
parents: 67
diff changeset
1329 the IL out-of-SSA. */
kono
parents: 67
diff changeset
1330 for (gphi_iterator psi = gsi_start_phis (bb); !gsi_end_p (psi);
kono
parents: 67
diff changeset
1331 gsi_next (&psi))
kono
parents: 67
diff changeset
1332 {
kono
parents: 67
diff changeset
1333 gphi *phi = psi.phi ();
kono
parents: 67
diff changeset
1334 tree res = gimple_phi_result (phi);
kono
parents: 67
diff changeset
1335 if (virtual_operand_p (res)
kono
parents: 67
diff changeset
1336 || scev_analyzable_p (res, scop->scop_info->region))
kono
parents: 67
diff changeset
1337 continue;
kono
parents: 67
diff changeset
1338 /* To simulate out-of-SSA the block containing the PHI node has
kono
parents: 67
diff changeset
1339 reads of the PHI destination. And to preserve SSA dependences
kono
parents: 67
diff changeset
1340 we also write to it (the out-of-SSA decl and the SSA result
kono
parents: 67
diff changeset
1341 are coalesced for dependence purposes which is good enough). */
kono
parents: 67
diff changeset
1342 add_read (&reads, res, phi);
kono
parents: 67
diff changeset
1343 add_write (&writes, res);
kono
parents: 67
diff changeset
1344 }
kono
parents: 67
diff changeset
1345 basic_block bb_for_succs = bb;
kono
parents: 67
diff changeset
1346 if (bb_for_succs == bb_for_succs->loop_father->latch
kono
parents: 67
diff changeset
1347 && bb_in_sese_p (bb_for_succs, scop->scop_info->region)
kono
parents: 67
diff changeset
1348 && sese_trivially_empty_bb_p (bb_for_succs))
kono
parents: 67
diff changeset
1349 bb_for_succs = NULL;
kono
parents: 67
diff changeset
1350 while (bb_for_succs)
kono
parents: 67
diff changeset
1351 {
kono
parents: 67
diff changeset
1352 basic_block latch = NULL;
kono
parents: 67
diff changeset
1353 edge_iterator ei;
kono
parents: 67
diff changeset
1354 edge e;
kono
parents: 67
diff changeset
1355 FOR_EACH_EDGE (e, ei, bb_for_succs->succs)
kono
parents: 67
diff changeset
1356 {
kono
parents: 67
diff changeset
1357 for (gphi_iterator psi = gsi_start_phis (e->dest); !gsi_end_p (psi);
kono
parents: 67
diff changeset
1358 gsi_next (&psi))
kono
parents: 67
diff changeset
1359 {
kono
parents: 67
diff changeset
1360 gphi *phi = psi.phi ();
kono
parents: 67
diff changeset
1361 tree res = gimple_phi_result (phi);
kono
parents: 67
diff changeset
1362 if (virtual_operand_p (res))
kono
parents: 67
diff changeset
1363 continue;
kono
parents: 67
diff changeset
1364 /* To simulate out-of-SSA the predecessor of edges into PHI nodes
kono
parents: 67
diff changeset
1365 has a copy from the PHI argument to the PHI destination. */
kono
parents: 67
diff changeset
1366 if (! scev_analyzable_p (res, scop->scop_info->region))
kono
parents: 67
diff changeset
1367 add_write (&writes, res);
kono
parents: 67
diff changeset
1368 tree use = PHI_ARG_DEF_FROM_EDGE (phi, e);
kono
parents: 67
diff changeset
1369 if (TREE_CODE (use) == SSA_NAME
kono
parents: 67
diff changeset
1370 && ! SSA_NAME_IS_DEFAULT_DEF (use)
kono
parents: 67
diff changeset
1371 && gimple_bb (SSA_NAME_DEF_STMT (use)) != bb_for_succs
kono
parents: 67
diff changeset
1372 && ! scev_analyzable_p (use, scop->scop_info->region))
kono
parents: 67
diff changeset
1373 add_read (&reads, use, phi);
kono
parents: 67
diff changeset
1374 }
kono
parents: 67
diff changeset
1375 if (e->dest == bb_for_succs->loop_father->latch
kono
parents: 67
diff changeset
1376 && bb_in_sese_p (e->dest, scop->scop_info->region)
kono
parents: 67
diff changeset
1377 && sese_trivially_empty_bb_p (e->dest))
kono
parents: 67
diff changeset
1378 latch = e->dest;
kono
parents: 67
diff changeset
1379 }
kono
parents: 67
diff changeset
1380 /* Handle empty latch block PHIs here, otherwise we confuse ISL
kono
parents: 67
diff changeset
1381 with extra conditional code where it then peels off the last
kono
parents: 67
diff changeset
1382 iteration just because of that. It would be simplest if we
kono
parents: 67
diff changeset
1383 just didn't force simple latches (thus remove the forwarder). */
kono
parents: 67
diff changeset
1384 bb_for_succs = latch;
kono
parents: 67
diff changeset
1385 }
kono
parents: 67
diff changeset
1386
kono
parents: 67
diff changeset
1387 /* For the region exit block add reads for all live-out vars. */
kono
parents: 67
diff changeset
1388 if (bb == scop->scop_info->region.exit->src)
kono
parents: 67
diff changeset
1389 {
kono
parents: 67
diff changeset
1390 sese_build_liveouts (scop->scop_info);
kono
parents: 67
diff changeset
1391 unsigned i;
kono
parents: 67
diff changeset
1392 bitmap_iterator bi;
kono
parents: 67
diff changeset
1393 EXECUTE_IF_SET_IN_BITMAP (scop->scop_info->liveout, 0, i, bi)
kono
parents: 67
diff changeset
1394 {
kono
parents: 67
diff changeset
1395 tree use = ssa_name (i);
kono
parents: 67
diff changeset
1396 add_read (&reads, use, NULL);
kono
parents: 67
diff changeset
1397 }
kono
parents: 67
diff changeset
1398 }
kono
parents: 67
diff changeset
1399
kono
parents: 67
diff changeset
1400 if (drs.is_empty () && writes.is_empty () && reads.is_empty ())
kono
parents: 67
diff changeset
1401 return NULL;
kono
parents: 67
diff changeset
1402
kono
parents: 67
diff changeset
1403 return new_gimple_poly_bb (bb, drs, reads, writes);
kono
parents: 67
diff changeset
1404 }
kono
parents: 67
diff changeset
1405
kono
parents: 67
diff changeset
1406 /* Compute alias-sets for all data references in DRS. */
kono
parents: 67
diff changeset
1407
kono
parents: 67
diff changeset
1408 static bool
kono
parents: 67
diff changeset
1409 build_alias_set (scop_p scop)
kono
parents: 67
diff changeset
1410 {
kono
parents: 67
diff changeset
1411 int num_vertices = scop->drs.length ();
kono
parents: 67
diff changeset
1412 struct graph *g = new_graph (num_vertices);
kono
parents: 67
diff changeset
1413 dr_info *dr1, *dr2;
kono
parents: 67
diff changeset
1414 int i, j;
kono
parents: 67
diff changeset
1415 int *all_vertices;
kono
parents: 67
diff changeset
1416
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1417 struct loop *nest
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1418 = find_common_loop (scop->scop_info->region.entry->dest->loop_father,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1419 scop->scop_info->region.exit->src->loop_father);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1420
111
kono
parents: 67
diff changeset
1421 FOR_EACH_VEC_ELT (scop->drs, i, dr1)
kono
parents: 67
diff changeset
1422 for (j = i+1; scop->drs.iterate (j, &dr2); j++)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1423 if (dr_may_alias_p (dr1->dr, dr2->dr, nest))
111
kono
parents: 67
diff changeset
1424 {
kono
parents: 67
diff changeset
1425 /* Dependences in the same alias set need to be handled
kono
parents: 67
diff changeset
1426 by just looking at DR_ACCESS_FNs. */
kono
parents: 67
diff changeset
1427 if (DR_NUM_DIMENSIONS (dr1->dr) == 0
kono
parents: 67
diff changeset
1428 || DR_NUM_DIMENSIONS (dr1->dr) != DR_NUM_DIMENSIONS (dr2->dr)
kono
parents: 67
diff changeset
1429 || ! operand_equal_p (DR_BASE_OBJECT (dr1->dr),
kono
parents: 67
diff changeset
1430 DR_BASE_OBJECT (dr2->dr),
kono
parents: 67
diff changeset
1431 OEP_ADDRESS_OF)
kono
parents: 67
diff changeset
1432 || ! types_compatible_p (TREE_TYPE (DR_BASE_OBJECT (dr1->dr)),
kono
parents: 67
diff changeset
1433 TREE_TYPE (DR_BASE_OBJECT (dr2->dr))))
kono
parents: 67
diff changeset
1434 {
kono
parents: 67
diff changeset
1435 free_graph (g);
kono
parents: 67
diff changeset
1436 return false;
kono
parents: 67
diff changeset
1437 }
kono
parents: 67
diff changeset
1438 add_edge (g, i, j);
kono
parents: 67
diff changeset
1439 add_edge (g, j, i);
kono
parents: 67
diff changeset
1440 }
kono
parents: 67
diff changeset
1441
kono
parents: 67
diff changeset
1442 all_vertices = XNEWVEC (int, num_vertices);
kono
parents: 67
diff changeset
1443 for (i = 0; i < num_vertices; i++)
kono
parents: 67
diff changeset
1444 all_vertices[i] = i;
kono
parents: 67
diff changeset
1445
kono
parents: 67
diff changeset
1446 scop->max_alias_set
kono
parents: 67
diff changeset
1447 = graphds_dfs (g, all_vertices, num_vertices, NULL, true, NULL) + 1;
kono
parents: 67
diff changeset
1448 free (all_vertices);
kono
parents: 67
diff changeset
1449
kono
parents: 67
diff changeset
1450 for (i = 0; i < g->n_vertices; i++)
kono
parents: 67
diff changeset
1451 scop->drs[i].alias_set = g->vertices[i].component + 1;
kono
parents: 67
diff changeset
1452
kono
parents: 67
diff changeset
1453 free_graph (g);
kono
parents: 67
diff changeset
1454 return true;
kono
parents: 67
diff changeset
1455 }
kono
parents: 67
diff changeset
1456
kono
parents: 67
diff changeset
1457 /* Gather BBs and conditions for a SCOP. */
kono
parents: 67
diff changeset
1458 class gather_bbs : public dom_walker
kono
parents: 67
diff changeset
1459 {
kono
parents: 67
diff changeset
1460 public:
kono
parents: 67
diff changeset
1461 gather_bbs (cdi_direction, scop_p, int *);
kono
parents: 67
diff changeset
1462
kono
parents: 67
diff changeset
1463 virtual edge before_dom_children (basic_block);
kono
parents: 67
diff changeset
1464 virtual void after_dom_children (basic_block);
kono
parents: 67
diff changeset
1465
kono
parents: 67
diff changeset
1466 private:
kono
parents: 67
diff changeset
1467 auto_vec<gimple *, 3> conditions, cases;
kono
parents: 67
diff changeset
1468 scop_p scop;
kono
parents: 67
diff changeset
1469 };
kono
parents: 67
diff changeset
1470 }
kono
parents: 67
diff changeset
1471 gather_bbs::gather_bbs (cdi_direction direction, scop_p scop, int *bb_to_rpo)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1472 : dom_walker (direction, ALL_BLOCKS, bb_to_rpo), scop (scop)
111
kono
parents: 67
diff changeset
1473 {
kono
parents: 67
diff changeset
1474 }
kono
parents: 67
diff changeset
1475
kono
parents: 67
diff changeset
1476 /* Call-back for dom_walk executed before visiting the dominated
kono
parents: 67
diff changeset
1477 blocks. */
kono
parents: 67
diff changeset
1478
kono
parents: 67
diff changeset
1479 edge
kono
parents: 67
diff changeset
1480 gather_bbs::before_dom_children (basic_block bb)
kono
parents: 67
diff changeset
1481 {
kono
parents: 67
diff changeset
1482 sese_info_p region = scop->scop_info;
kono
parents: 67
diff changeset
1483 if (!bb_in_sese_p (bb, region->region))
kono
parents: 67
diff changeset
1484 return dom_walker::STOP;
kono
parents: 67
diff changeset
1485
kono
parents: 67
diff changeset
1486 /* For loops fully contained in the region record parameters in the
kono
parents: 67
diff changeset
1487 loop bounds. */
kono
parents: 67
diff changeset
1488 loop_p loop = bb->loop_father;
kono
parents: 67
diff changeset
1489 if (loop->header == bb
kono
parents: 67
diff changeset
1490 && loop_in_sese_p (loop, region->region))
kono
parents: 67
diff changeset
1491 {
kono
parents: 67
diff changeset
1492 tree nb_iters = number_of_latch_executions (loop);
kono
parents: 67
diff changeset
1493 if (chrec_contains_symbols (nb_iters))
kono
parents: 67
diff changeset
1494 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1495 nb_iters = cached_scalar_evolution_in_region (region->region,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1496 loop, nb_iters);
111
kono
parents: 67
diff changeset
1497 scan_tree_for_params (region, nb_iters);
kono
parents: 67
diff changeset
1498 }
kono
parents: 67
diff changeset
1499 }
kono
parents: 67
diff changeset
1500
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1501 if (gcond *stmt = single_pred_cond_non_loop_exit (bb))
111
kono
parents: 67
diff changeset
1502 {
kono
parents: 67
diff changeset
1503 edge e = single_pred_edge (bb);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1504 /* Make sure the condition is in the region and thus was verified
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1505 to be handled. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1506 if (e != region->region.entry)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1507 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1508 conditions.safe_push (stmt);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1509 if (e->flags & EDGE_TRUE_VALUE)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1510 cases.safe_push (stmt);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1511 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1512 cases.safe_push (NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1513 }
111
kono
parents: 67
diff changeset
1514 }
kono
parents: 67
diff changeset
1515
kono
parents: 67
diff changeset
1516 scop->scop_info->bbs.safe_push (bb);
kono
parents: 67
diff changeset
1517
kono
parents: 67
diff changeset
1518 gimple_poly_bb_p gbb = try_generate_gimple_bb (scop, bb);
kono
parents: 67
diff changeset
1519 if (!gbb)
kono
parents: 67
diff changeset
1520 return NULL;
kono
parents: 67
diff changeset
1521
kono
parents: 67
diff changeset
1522 GBB_CONDITIONS (gbb) = conditions.copy ();
kono
parents: 67
diff changeset
1523 GBB_CONDITION_CASES (gbb) = cases.copy ();
kono
parents: 67
diff changeset
1524
kono
parents: 67
diff changeset
1525 poly_bb_p pbb = new_poly_bb (scop, gbb);
kono
parents: 67
diff changeset
1526 scop->pbbs.safe_push (pbb);
kono
parents: 67
diff changeset
1527
kono
parents: 67
diff changeset
1528 int i;
kono
parents: 67
diff changeset
1529 data_reference_p dr;
kono
parents: 67
diff changeset
1530 FOR_EACH_VEC_ELT (gbb->data_refs, i, dr)
kono
parents: 67
diff changeset
1531 {
kono
parents: 67
diff changeset
1532 DEBUG_PRINT (dp << "Adding memory ";
kono
parents: 67
diff changeset
1533 if (dr->is_read)
kono
parents: 67
diff changeset
1534 dp << "read: ";
kono
parents: 67
diff changeset
1535 else
kono
parents: 67
diff changeset
1536 dp << "write: ";
kono
parents: 67
diff changeset
1537 print_generic_expr (dump_file, dr->ref);
kono
parents: 67
diff changeset
1538 dp << "\nFrom stmt: ";
kono
parents: 67
diff changeset
1539 print_gimple_stmt (dump_file, dr->stmt, 0));
kono
parents: 67
diff changeset
1540
kono
parents: 67
diff changeset
1541 scop->drs.safe_push (dr_info (dr, pbb));
kono
parents: 67
diff changeset
1542 }
kono
parents: 67
diff changeset
1543
kono
parents: 67
diff changeset
1544 return NULL;
kono
parents: 67
diff changeset
1545 }
kono
parents: 67
diff changeset
1546
kono
parents: 67
diff changeset
1547 /* Call-back for dom_walk executed after visiting the dominated
kono
parents: 67
diff changeset
1548 blocks. */
kono
parents: 67
diff changeset
1549
kono
parents: 67
diff changeset
1550 void
kono
parents: 67
diff changeset
1551 gather_bbs::after_dom_children (basic_block bb)
kono
parents: 67
diff changeset
1552 {
kono
parents: 67
diff changeset
1553 if (!bb_in_sese_p (bb, scop->scop_info->region))
kono
parents: 67
diff changeset
1554 return;
kono
parents: 67
diff changeset
1555
kono
parents: 67
diff changeset
1556 if (single_pred_cond_non_loop_exit (bb))
kono
parents: 67
diff changeset
1557 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1558 edge e = single_pred_edge (bb);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1559 if (e != scop->scop_info->region.entry)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1560 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1561 conditions.pop ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1562 cases.pop ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1563 }
111
kono
parents: 67
diff changeset
1564 }
kono
parents: 67
diff changeset
1565 }
kono
parents: 67
diff changeset
1566
kono
parents: 67
diff changeset
1567
kono
parents: 67
diff changeset
1568 /* Compute sth like an execution order, dominator order with first executing
kono
parents: 67
diff changeset
1569 edges that stay inside the current loop, delaying processing exit edges. */
kono
parents: 67
diff changeset
1570
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1571 static int *bb_to_rpo;
111
kono
parents: 67
diff changeset
1572
kono
parents: 67
diff changeset
1573 /* Helper for qsort, sorting after order above. */
kono
parents: 67
diff changeset
1574
kono
parents: 67
diff changeset
1575 static int
kono
parents: 67
diff changeset
1576 cmp_pbbs (const void *pa, const void *pb)
kono
parents: 67
diff changeset
1577 {
kono
parents: 67
diff changeset
1578 poly_bb_p bb1 = *((const poly_bb_p *)pa);
kono
parents: 67
diff changeset
1579 poly_bb_p bb2 = *((const poly_bb_p *)pb);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1580 if (bb_to_rpo[bb1->black_box->bb->index]
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1581 < bb_to_rpo[bb2->black_box->bb->index])
111
kono
parents: 67
diff changeset
1582 return -1;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1583 else if (bb_to_rpo[bb1->black_box->bb->index]
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1584 > bb_to_rpo[bb2->black_box->bb->index])
111
kono
parents: 67
diff changeset
1585 return 1;
kono
parents: 67
diff changeset
1586 else
kono
parents: 67
diff changeset
1587 return 0;
kono
parents: 67
diff changeset
1588 }
kono
parents: 67
diff changeset
1589
kono
parents: 67
diff changeset
1590 /* Find Static Control Parts (SCoP) in the current function and pushes
kono
parents: 67
diff changeset
1591 them to SCOPS. */
kono
parents: 67
diff changeset
1592
kono
parents: 67
diff changeset
1593 void
kono
parents: 67
diff changeset
1594 build_scops (vec<scop_p> *scops)
kono
parents: 67
diff changeset
1595 {
kono
parents: 67
diff changeset
1596 if (dump_file)
kono
parents: 67
diff changeset
1597 dp.set_dump_file (dump_file);
kono
parents: 67
diff changeset
1598
kono
parents: 67
diff changeset
1599 scop_detection sb;
kono
parents: 67
diff changeset
1600 sb.build_scop_depth (current_loops->tree_root);
kono
parents: 67
diff changeset
1601
kono
parents: 67
diff changeset
1602 /* Now create scops from the lightweight SESEs. */
kono
parents: 67
diff changeset
1603 vec<sese_l> scops_l = sb.get_scops ();
kono
parents: 67
diff changeset
1604
kono
parents: 67
diff changeset
1605 /* Domwalk needs a bb to RPO mapping. Compute it once here. */
kono
parents: 67
diff changeset
1606 int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
kono
parents: 67
diff changeset
1607 int postorder_num = pre_and_rev_post_order_compute (NULL, postorder, true);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1608 bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
111
kono
parents: 67
diff changeset
1609 for (int i = 0; i < postorder_num; ++i)
kono
parents: 67
diff changeset
1610 bb_to_rpo[postorder[i]] = i;
kono
parents: 67
diff changeset
1611 free (postorder);
kono
parents: 67
diff changeset
1612
kono
parents: 67
diff changeset
1613 int i;
kono
parents: 67
diff changeset
1614 sese_l *s;
kono
parents: 67
diff changeset
1615 FOR_EACH_VEC_ELT (scops_l, i, s)
kono
parents: 67
diff changeset
1616 {
kono
parents: 67
diff changeset
1617 scop_p scop = new_scop (s->entry, s->exit);
kono
parents: 67
diff changeset
1618
kono
parents: 67
diff changeset
1619 /* Record all basic blocks and their conditions in REGION. */
kono
parents: 67
diff changeset
1620 gather_bbs (CDI_DOMINATORS, scop, bb_to_rpo).walk (s->entry->dest);
kono
parents: 67
diff changeset
1621
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1622 /* Sort pbbs after execution order for initial schedule generation. */
111
kono
parents: 67
diff changeset
1623 scop->pbbs.qsort (cmp_pbbs);
kono
parents: 67
diff changeset
1624
kono
parents: 67
diff changeset
1625 if (! build_alias_set (scop))
kono
parents: 67
diff changeset
1626 {
kono
parents: 67
diff changeset
1627 DEBUG_PRINT (dp << "[scop-detection-fail] cannot handle dependences\n");
kono
parents: 67
diff changeset
1628 free_scop (scop);
kono
parents: 67
diff changeset
1629 continue;
kono
parents: 67
diff changeset
1630 }
kono
parents: 67
diff changeset
1631
kono
parents: 67
diff changeset
1632 /* Do not optimize a scop containing only PBBs that do not belong
kono
parents: 67
diff changeset
1633 to any loops. */
kono
parents: 67
diff changeset
1634 if (sb.nb_pbbs_in_loops (scop) == 0)
kono
parents: 67
diff changeset
1635 {
kono
parents: 67
diff changeset
1636 DEBUG_PRINT (dp << "[scop-detection-fail] no data references.\n");
kono
parents: 67
diff changeset
1637 free_scop (scop);
kono
parents: 67
diff changeset
1638 continue;
kono
parents: 67
diff changeset
1639 }
kono
parents: 67
diff changeset
1640
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1641 unsigned max_arrays = param_graphite_max_arrays_per_scop;
111
kono
parents: 67
diff changeset
1642 if (max_arrays > 0
kono
parents: 67
diff changeset
1643 && scop->drs.length () >= max_arrays)
kono
parents: 67
diff changeset
1644 {
kono
parents: 67
diff changeset
1645 DEBUG_PRINT (dp << "[scop-detection-fail] too many data references: "
kono
parents: 67
diff changeset
1646 << scop->drs.length ()
kono
parents: 67
diff changeset
1647 << " is larger than --param graphite-max-arrays-per-scop="
kono
parents: 67
diff changeset
1648 << max_arrays << ".\n");
kono
parents: 67
diff changeset
1649 free_scop (scop);
kono
parents: 67
diff changeset
1650 continue;
kono
parents: 67
diff changeset
1651 }
kono
parents: 67
diff changeset
1652
kono
parents: 67
diff changeset
1653 find_scop_parameters (scop);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1654 graphite_dim_t max_dim = param_graphite_max_nb_scop_params;
111
kono
parents: 67
diff changeset
1655 if (max_dim > 0
kono
parents: 67
diff changeset
1656 && scop_nb_params (scop) > max_dim)
kono
parents: 67
diff changeset
1657 {
kono
parents: 67
diff changeset
1658 DEBUG_PRINT (dp << "[scop-detection-fail] too many parameters: "
kono
parents: 67
diff changeset
1659 << scop_nb_params (scop)
kono
parents: 67
diff changeset
1660 << " larger than --param graphite-max-nb-scop-params="
kono
parents: 67
diff changeset
1661 << max_dim << ".\n");
kono
parents: 67
diff changeset
1662 free_scop (scop);
kono
parents: 67
diff changeset
1663 continue;
kono
parents: 67
diff changeset
1664 }
kono
parents: 67
diff changeset
1665
kono
parents: 67
diff changeset
1666 scops->safe_push (scop);
kono
parents: 67
diff changeset
1667 }
kono
parents: 67
diff changeset
1668
kono
parents: 67
diff changeset
1669 free (bb_to_rpo);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1670 bb_to_rpo = NULL;
111
kono
parents: 67
diff changeset
1671 DEBUG_PRINT (dp << "number of SCoPs: " << (scops ? scops->length () : 0););
kono
parents: 67
diff changeset
1672 }
kono
parents: 67
diff changeset
1673
kono
parents: 67
diff changeset
1674 #endif /* HAVE_isl */