annotate gcc/graphite-scop-detection.c @ 137:d22083d7f10b

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