annotate gcc/tree-ssa-loop-ch.c @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Loop header copying on trees.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2004-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: 0
diff changeset
3
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
5
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Free Software Foundation; either version 3, or (at your option) any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 later version.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
10
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 for more details.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
15
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "coretypes.h"
111
kono
parents: 67
diff changeset
23 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "tree.h"
111
kono
parents: 67
diff changeset
25 #include "gimple.h"
kono
parents: 67
diff changeset
26 #include "cfghooks.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "tree-pass.h"
111
kono
parents: 67
diff changeset
28 #include "gimple-ssa.h"
kono
parents: 67
diff changeset
29 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
30 #include "tree-cfg.h"
kono
parents: 67
diff changeset
31 #include "tree-into-ssa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #include "cfgloop.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 #include "tree-inline.h"
111
kono
parents: 67
diff changeset
34 #include "tree-ssa-scopedtables.h"
kono
parents: 67
diff changeset
35 #include "tree-ssa-threadedge.h"
kono
parents: 67
diff changeset
36 #include "params.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 /* Duplicates headers of loops if they are small enough, so that the statements
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 in the loop body are always executed when the loop is entered. This
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 increases effectiveness of code motion optimizations, and reduces the need
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 for loop preconditioning. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 /* Check whether we should duplicate HEADER of LOOP. At most *LIMIT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 instructions should be duplicated, limit is decreased by the actual
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 amount. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 should_duplicate_loop_header_p (basic_block header, struct loop *loop,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 int *limit)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 gimple_stmt_iterator bsi;
111
kono
parents: 67
diff changeset
52 gimple *last;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
111
kono
parents: 67
diff changeset
54 gcc_assert (!header->aux);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 /* Loop header copying usually increases size of the code. This used not to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 be true, since quite often it is possible to verify that the condition is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 satisfied in the first iteration and therefore to eliminate it. Jump
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 threading handles these cases now. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
60 if (optimize_loop_for_size_p (loop)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
61 && !loop->force_vectorize)
111
kono
parents: 67
diff changeset
62 {
kono
parents: 67
diff changeset
63 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
64 fprintf (dump_file,
kono
parents: 67
diff changeset
65 " Not duplicating bb %i: optimizing for size.\n",
kono
parents: 67
diff changeset
66 header->index);
kono
parents: 67
diff changeset
67 return false;
kono
parents: 67
diff changeset
68 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 gcc_assert (EDGE_COUNT (header->succs) > 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 if (single_succ_p (header))
111
kono
parents: 67
diff changeset
72 {
kono
parents: 67
diff changeset
73 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
74 fprintf (dump_file,
kono
parents: 67
diff changeset
75 " Not duplicating bb %i: it is single succ.\n",
kono
parents: 67
diff changeset
76 header->index);
kono
parents: 67
diff changeset
77 return false;
kono
parents: 67
diff changeset
78 }
kono
parents: 67
diff changeset
79
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 if (flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 0)->dest)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 && flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 1)->dest))
111
kono
parents: 67
diff changeset
82 {
kono
parents: 67
diff changeset
83 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
84 fprintf (dump_file,
kono
parents: 67
diff changeset
85 " Not duplicating bb %i: both sucessors are in loop.\n",
kono
parents: 67
diff changeset
86 loop->num);
kono
parents: 67
diff changeset
87 return false;
kono
parents: 67
diff changeset
88 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 /* If this is not the original loop header, we want it to have just
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 one predecessor in order to match the && pattern. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 if (header != loop->header && !single_pred_p (header))
111
kono
parents: 67
diff changeset
93 {
kono
parents: 67
diff changeset
94 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
95 fprintf (dump_file,
kono
parents: 67
diff changeset
96 " Not duplicating bb %i: it has mutiple predecestors.\n",
kono
parents: 67
diff changeset
97 header->index);
kono
parents: 67
diff changeset
98 return false;
kono
parents: 67
diff changeset
99 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 last = last_stmt (header);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 if (gimple_code (last) != GIMPLE_COND)
111
kono
parents: 67
diff changeset
103 {
kono
parents: 67
diff changeset
104 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
105 fprintf (dump_file,
kono
parents: 67
diff changeset
106 " Not duplicating bb %i: it does not end by conditional.\n",
kono
parents: 67
diff changeset
107 header->index);
kono
parents: 67
diff changeset
108 return false;
kono
parents: 67
diff changeset
109 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
111
kono
parents: 67
diff changeset
111 /* Count number of instructions and punt on calls. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 for (bsi = gsi_start_bb (header); !gsi_end_p (bsi); gsi_next (&bsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 last = gsi_stmt (bsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 if (gimple_code (last) == GIMPLE_LABEL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
119 if (is_gimple_debug (last))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
120 continue;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
121
111
kono
parents: 67
diff changeset
122 if (gimple_code (last) == GIMPLE_CALL
kono
parents: 67
diff changeset
123 && (!gimple_inexpensive_call_p (as_a <gcall *> (last))
kono
parents: 67
diff changeset
124 /* IFN_LOOP_DIST_ALIAS means that inner loop is distributed
kono
parents: 67
diff changeset
125 at current loop's header. Don't copy in this case. */
kono
parents: 67
diff changeset
126 || gimple_call_internal_p (last, IFN_LOOP_DIST_ALIAS)))
kono
parents: 67
diff changeset
127 {
kono
parents: 67
diff changeset
128 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
129 fprintf (dump_file,
kono
parents: 67
diff changeset
130 " Not duplicating bb %i: it contains call.\n",
kono
parents: 67
diff changeset
131 header->index);
kono
parents: 67
diff changeset
132 return false;
kono
parents: 67
diff changeset
133 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 *limit -= estimate_num_insns (last, &eni_size_weights);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 if (*limit < 0)
111
kono
parents: 67
diff changeset
137 {
kono
parents: 67
diff changeset
138 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
139 fprintf (dump_file,
kono
parents: 67
diff changeset
140 " Not duplicating bb %i contains too many insns.\n",
kono
parents: 67
diff changeset
141 header->index);
kono
parents: 67
diff changeset
142 return false;
kono
parents: 67
diff changeset
143 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 }
111
kono
parents: 67
diff changeset
145 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
146 fprintf (dump_file, " Will duplicate bb %i\n", header->index);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 /* Checks whether LOOP is a do-while style loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 do_while_loop_p (struct loop *loop)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 {
111
kono
parents: 67
diff changeset
155 gimple *stmt = last_stmt (loop->latch);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 /* If the latch of the loop is not empty, it is not a do-while loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 if (stmt
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 && gimple_code (stmt) != GIMPLE_LABEL)
111
kono
parents: 67
diff changeset
160 {
kono
parents: 67
diff changeset
161 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
162 fprintf (dump_file,
kono
parents: 67
diff changeset
163 "Loop %i is not do-while loop: latch is not empty.\n",
kono
parents: 67
diff changeset
164 loop->num);
kono
parents: 67
diff changeset
165 return false;
kono
parents: 67
diff changeset
166 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
168 /* If the latch does not have a single predecessor, it is not a
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
169 do-while loop. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
170 if (!single_pred_p (loop->latch))
111
kono
parents: 67
diff changeset
171 {
kono
parents: 67
diff changeset
172 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
173 fprintf (dump_file,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
174 "Loop %i is not do-while loop: latch has multiple "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
175 "predecessors.\n", loop->num);
111
kono
parents: 67
diff changeset
176 return false;
kono
parents: 67
diff changeset
177 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
178
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
179 /* If the latch predecessor doesn't exit the loop, it is not a
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
180 do-while loop. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
181 if (!loop_exits_from_bb_p (loop, single_pred (loop->latch)))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
182 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
183 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
184 fprintf (dump_file,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
185 "Loop %i is not do-while loop: latch predecessor "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
186 "does not exit loop.\n", loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
187 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
188 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
189
111
kono
parents: 67
diff changeset
190 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
191 fprintf (dump_file, "Loop %i is do-while loop\n", loop->num);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195
111
kono
parents: 67
diff changeset
196 namespace {
kono
parents: 67
diff changeset
197
kono
parents: 67
diff changeset
198 /* Common superclass for both header-copying phases. */
kono
parents: 67
diff changeset
199 class ch_base : public gimple_opt_pass
kono
parents: 67
diff changeset
200 {
kono
parents: 67
diff changeset
201 protected:
kono
parents: 67
diff changeset
202 ch_base (pass_data data, gcc::context *ctxt)
kono
parents: 67
diff changeset
203 : gimple_opt_pass (data, ctxt)
kono
parents: 67
diff changeset
204 {}
kono
parents: 67
diff changeset
205
kono
parents: 67
diff changeset
206 /* Copies headers of all loops in FUN for which process_loop_p is true. */
kono
parents: 67
diff changeset
207 unsigned int copy_headers (function *fun);
kono
parents: 67
diff changeset
208
kono
parents: 67
diff changeset
209 /* Return true to copy headers of LOOP or false to skip. */
kono
parents: 67
diff changeset
210 virtual bool process_loop_p (struct loop *loop) = 0;
kono
parents: 67
diff changeset
211 };
kono
parents: 67
diff changeset
212
kono
parents: 67
diff changeset
213 const pass_data pass_data_ch =
kono
parents: 67
diff changeset
214 {
kono
parents: 67
diff changeset
215 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
216 "ch", /* name */
kono
parents: 67
diff changeset
217 OPTGROUP_LOOP, /* optinfo_flags */
kono
parents: 67
diff changeset
218 TV_TREE_CH, /* tv_id */
kono
parents: 67
diff changeset
219 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 67
diff changeset
220 0, /* properties_provided */
kono
parents: 67
diff changeset
221 0, /* properties_destroyed */
kono
parents: 67
diff changeset
222 0, /* todo_flags_start */
kono
parents: 67
diff changeset
223 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
224 };
kono
parents: 67
diff changeset
225
kono
parents: 67
diff changeset
226 class pass_ch : public ch_base
kono
parents: 67
diff changeset
227 {
kono
parents: 67
diff changeset
228 public:
kono
parents: 67
diff changeset
229 pass_ch (gcc::context *ctxt)
kono
parents: 67
diff changeset
230 : ch_base (pass_data_ch, ctxt)
kono
parents: 67
diff changeset
231 {}
kono
parents: 67
diff changeset
232
kono
parents: 67
diff changeset
233 /* opt_pass methods: */
kono
parents: 67
diff changeset
234 virtual bool gate (function *) { return flag_tree_ch != 0; }
kono
parents: 67
diff changeset
235
kono
parents: 67
diff changeset
236 /* Initialize and finalize loop structures, copying headers inbetween. */
kono
parents: 67
diff changeset
237 virtual unsigned int execute (function *);
kono
parents: 67
diff changeset
238
kono
parents: 67
diff changeset
239 opt_pass * clone () { return new pass_ch (m_ctxt); }
kono
parents: 67
diff changeset
240
kono
parents: 67
diff changeset
241 protected:
kono
parents: 67
diff changeset
242 /* ch_base method: */
kono
parents: 67
diff changeset
243 virtual bool process_loop_p (struct loop *loop);
kono
parents: 67
diff changeset
244 }; // class pass_ch
kono
parents: 67
diff changeset
245
kono
parents: 67
diff changeset
246 const pass_data pass_data_ch_vect =
kono
parents: 67
diff changeset
247 {
kono
parents: 67
diff changeset
248 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
249 "ch_vect", /* name */
kono
parents: 67
diff changeset
250 OPTGROUP_LOOP, /* optinfo_flags */
kono
parents: 67
diff changeset
251 TV_TREE_CH, /* tv_id */
kono
parents: 67
diff changeset
252 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 67
diff changeset
253 0, /* properties_provided */
kono
parents: 67
diff changeset
254 0, /* properties_destroyed */
kono
parents: 67
diff changeset
255 0, /* todo_flags_start */
kono
parents: 67
diff changeset
256 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
257 };
kono
parents: 67
diff changeset
258
kono
parents: 67
diff changeset
259 /* This is a more aggressive version of the same pass, designed to run just
kono
parents: 67
diff changeset
260 before if-conversion and vectorization, to put more loops into the form
kono
parents: 67
diff changeset
261 required for those phases. */
kono
parents: 67
diff changeset
262 class pass_ch_vect : public ch_base
kono
parents: 67
diff changeset
263 {
kono
parents: 67
diff changeset
264 public:
kono
parents: 67
diff changeset
265 pass_ch_vect (gcc::context *ctxt)
kono
parents: 67
diff changeset
266 : ch_base (pass_data_ch_vect, ctxt)
kono
parents: 67
diff changeset
267 {}
kono
parents: 67
diff changeset
268
kono
parents: 67
diff changeset
269 /* opt_pass methods: */
kono
parents: 67
diff changeset
270 virtual bool gate (function *fun)
kono
parents: 67
diff changeset
271 {
kono
parents: 67
diff changeset
272 return flag_tree_ch != 0
kono
parents: 67
diff changeset
273 && (flag_tree_loop_vectorize != 0 || fun->has_force_vectorize_loops);
kono
parents: 67
diff changeset
274 }
kono
parents: 67
diff changeset
275
kono
parents: 67
diff changeset
276 /* Just copy headers, no initialization/finalization of loop structures. */
kono
parents: 67
diff changeset
277 virtual unsigned int execute (function *);
kono
parents: 67
diff changeset
278
kono
parents: 67
diff changeset
279 protected:
kono
parents: 67
diff changeset
280 /* ch_base method: */
kono
parents: 67
diff changeset
281 virtual bool process_loop_p (struct loop *loop);
kono
parents: 67
diff changeset
282 }; // class pass_ch_vect
kono
parents: 67
diff changeset
283
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 /* For all loops, copy the condition at the end of the loop body in front
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 of the loop. This is beneficial since it increases efficiency of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 code motion optimizations. It also saves one jump on entry to the loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287
111
kono
parents: 67
diff changeset
288 unsigned int
kono
parents: 67
diff changeset
289 ch_base::copy_headers (function *fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 struct loop *loop;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 basic_block header;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 edge exit, entry;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 basic_block *bbs, *copied_bbs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 unsigned n_bbs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 unsigned bbs_size;
111
kono
parents: 67
diff changeset
297 bool changed = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298
111
kono
parents: 67
diff changeset
299 if (number_of_loops (fun) <= 1)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301
111
kono
parents: 67
diff changeset
302 bbs = XNEWVEC (basic_block, n_basic_blocks_for_fn (fun));
kono
parents: 67
diff changeset
303 copied_bbs = XNEWVEC (basic_block, n_basic_blocks_for_fn (fun));
kono
parents: 67
diff changeset
304 bbs_size = n_basic_blocks_for_fn (fun);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305
111
kono
parents: 67
diff changeset
306 FOR_EACH_LOOP (loop, 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 {
111
kono
parents: 67
diff changeset
308 int initial_limit = PARAM_VALUE (PARAM_MAX_LOOP_HEADER_INSNS);
kono
parents: 67
diff changeset
309 int remaining_limit = initial_limit;
kono
parents: 67
diff changeset
310 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
311 fprintf (dump_file,
kono
parents: 67
diff changeset
312 "Analyzing loop %i\n", loop->num);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 header = loop->header;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 /* If the loop is already a do-while style one (either because it was
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 written as such, or because jump threading transformed it into one),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 we might be in fact peeling the first iteration of the loop. This
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
319 in general is not a good idea. Also avoid touching infinite loops. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
320 if (!loop_has_exit_edges (loop)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
321 || !process_loop_p (loop))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 /* Iterate the header copying up to limit; this takes care of the cases
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 like while (a && b) {...}, where we want to have both of the conditions
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 copied. TODO -- handle while (a || b) - like cases, by not requiring
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 the header to have just a single successor and copying up to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 postdominator. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 exit = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 n_bbs = 0;
111
kono
parents: 67
diff changeset
332 while (should_duplicate_loop_header_p (header, loop, &remaining_limit))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 /* Find a successor of header that is inside a loop; i.e. the new
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 header after the condition is copied. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 if (flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 0)->dest))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 exit = EDGE_SUCC (header, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 exit = EDGE_SUCC (header, 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 bbs[n_bbs++] = header;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 gcc_assert (bbs_size > n_bbs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 header = exit->dest;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
343 /* Make sure to stop copying after we copied the first exit test.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
344 Without further heuristics we do not want to rotate the loop
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
345 any further. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
346 if (loop_exits_from_bb_p (loop, exit->src))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
347 break;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 if (!exit)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 fprintf (dump_file,
111
kono
parents: 67
diff changeset
355 "Duplicating header of the loop %d up to edge %d->%d,"
kono
parents: 67
diff changeset
356 " %i insns.\n",
kono
parents: 67
diff changeset
357 loop->num, exit->src->index, exit->dest->index,
kono
parents: 67
diff changeset
358 initial_limit - remaining_limit);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 /* Ensure that the header will have just the latch as a predecessor
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 inside the loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 if (!single_pred_p (exit->dest))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 exit = single_pred_edge (split_edge (exit));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 entry = loop_preheader_edge (loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366
111
kono
parents: 67
diff changeset
367 propagate_threaded_block_debug_into (exit->dest, entry->dest);
kono
parents: 67
diff changeset
368 if (!gimple_duplicate_sese_region (entry, exit, bbs, n_bbs, copied_bbs,
kono
parents: 67
diff changeset
369 true))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 fprintf (dump_file, "Duplication failed.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 /* If the loop has the form "for (i = j; i < j + 10; i++)" then
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 this copying can introduce a case where we rely on undefined
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 signed overflow to eliminate the preheader condition, because
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 we assume that "j < j + 10" is true. We don't want to warn
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 about that case for -Wstrict-overflow, because in general we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 don't warn about overflow involving loops. Prevent the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 warning by setting the no_warning flag in the condition. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 if (warn_strict_overflow > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 unsigned int i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 for (i = 0; i < n_bbs; ++i)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 gimple_stmt_iterator bsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 for (bsi = gsi_start_bb (copied_bbs[i]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 !gsi_end_p (bsi);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 gsi_next (&bsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 {
111
kono
parents: 67
diff changeset
394 gimple *stmt = gsi_stmt (bsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 if (gimple_code (stmt) == GIMPLE_COND)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 gimple_set_no_warning (stmt, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 else if (is_gimple_assign (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 if (TREE_CODE_CLASS (rhs_code) == tcc_comparison)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 gimple_set_no_warning (stmt, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 /* Ensure that the latch and the preheader is simple (we know that they
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 are not now, since there was the loop exit condition. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 split_edge (loop_preheader_edge (loop));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 split_edge (loop_latch_edge (loop));
111
kono
parents: 67
diff changeset
411
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
412 if (dump_file && (dump_flags & TDF_DETAILS))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
413 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
414 if (do_while_loop_p (loop))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
415 fprintf (dump_file, "Loop %d is now do-while loop.\n", loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
416 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
417 fprintf (dump_file, "Loop %d is still not do-while loop.\n",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
418 loop->num);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
419 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
420
111
kono
parents: 67
diff changeset
421 changed = true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423
111
kono
parents: 67
diff changeset
424 if (changed)
kono
parents: 67
diff changeset
425 update_ssa (TODO_update_ssa);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 free (bbs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 free (copied_bbs);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428
111
kono
parents: 67
diff changeset
429 return changed ? TODO_cleanup_cfg : 0;
kono
parents: 67
diff changeset
430 }
kono
parents: 67
diff changeset
431
kono
parents: 67
diff changeset
432 /* Initialize the loop structures we need, and finalize after. */
kono
parents: 67
diff changeset
433
kono
parents: 67
diff changeset
434 unsigned int
kono
parents: 67
diff changeset
435 pass_ch::execute (function *fun)
kono
parents: 67
diff changeset
436 {
kono
parents: 67
diff changeset
437 loop_optimizer_init (LOOPS_HAVE_PREHEADERS
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
438 | LOOPS_HAVE_SIMPLE_LATCHES
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
439 | LOOPS_HAVE_RECORDED_EXITS);
111
kono
parents: 67
diff changeset
440
kono
parents: 67
diff changeset
441 unsigned int res = copy_headers (fun);
kono
parents: 67
diff changeset
442
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 loop_optimizer_finalize ();
111
kono
parents: 67
diff changeset
444 return res;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446
111
kono
parents: 67
diff changeset
447 /* Assume an earlier phase has already initialized all the loop structures that
kono
parents: 67
diff changeset
448 we need here (and perhaps others too), and that these will be finalized by
kono
parents: 67
diff changeset
449 a later phase. */
kono
parents: 67
diff changeset
450
kono
parents: 67
diff changeset
451 unsigned int
kono
parents: 67
diff changeset
452 pass_ch_vect::execute (function *fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 {
111
kono
parents: 67
diff changeset
454 return copy_headers (fun);
kono
parents: 67
diff changeset
455 }
kono
parents: 67
diff changeset
456
kono
parents: 67
diff changeset
457 /* Apply header copying according to a very simple test of do-while shape. */
kono
parents: 67
diff changeset
458
kono
parents: 67
diff changeset
459 bool
kono
parents: 67
diff changeset
460 pass_ch::process_loop_p (struct loop *loop)
kono
parents: 67
diff changeset
461 {
kono
parents: 67
diff changeset
462 return !do_while_loop_p (loop);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464
111
kono
parents: 67
diff changeset
465 /* Apply header-copying to loops where we might enable vectorization. */
kono
parents: 67
diff changeset
466
kono
parents: 67
diff changeset
467 bool
kono
parents: 67
diff changeset
468 pass_ch_vect::process_loop_p (struct loop *loop)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 {
111
kono
parents: 67
diff changeset
470 if (!flag_tree_loop_vectorize && !loop->force_vectorize)
kono
parents: 67
diff changeset
471 return false;
kono
parents: 67
diff changeset
472
kono
parents: 67
diff changeset
473 if (loop->dont_vectorize)
kono
parents: 67
diff changeset
474 return false;
kono
parents: 67
diff changeset
475
kono
parents: 67
diff changeset
476 if (!do_while_loop_p (loop))
kono
parents: 67
diff changeset
477 return true;
kono
parents: 67
diff changeset
478
kono
parents: 67
diff changeset
479 /* The vectorizer won't handle anything with multiple exits, so skip. */
kono
parents: 67
diff changeset
480 edge exit = single_exit (loop);
kono
parents: 67
diff changeset
481 if (!exit)
kono
parents: 67
diff changeset
482 return false;
kono
parents: 67
diff changeset
483
kono
parents: 67
diff changeset
484 /* Copy headers iff there looks to be code in the loop after the exit block,
kono
parents: 67
diff changeset
485 i.e. the exit block has an edge to another block (besides the latch,
kono
parents: 67
diff changeset
486 which should be empty). */
kono
parents: 67
diff changeset
487 edge_iterator ei;
kono
parents: 67
diff changeset
488 edge e;
kono
parents: 67
diff changeset
489 FOR_EACH_EDGE (e, ei, exit->src->succs)
kono
parents: 67
diff changeset
490 if (!loop_exit_edge_p (loop, e)
kono
parents: 67
diff changeset
491 && e->dest != loop->header
kono
parents: 67
diff changeset
492 && e->dest != loop->latch)
kono
parents: 67
diff changeset
493 return true;
kono
parents: 67
diff changeset
494
kono
parents: 67
diff changeset
495 return false;
kono
parents: 67
diff changeset
496 }
kono
parents: 67
diff changeset
497
kono
parents: 67
diff changeset
498 } // anon namespace
kono
parents: 67
diff changeset
499
kono
parents: 67
diff changeset
500 gimple_opt_pass *
kono
parents: 67
diff changeset
501 make_pass_ch_vect (gcc::context *ctxt)
kono
parents: 67
diff changeset
502 {
kono
parents: 67
diff changeset
503 return new pass_ch_vect (ctxt);
kono
parents: 67
diff changeset
504 }
kono
parents: 67
diff changeset
505
kono
parents: 67
diff changeset
506 gimple_opt_pass *
kono
parents: 67
diff changeset
507 make_pass_ch (gcc::context *ctxt)
kono
parents: 67
diff changeset
508 {
kono
parents: 67
diff changeset
509 return new pass_ch (ctxt);
kono
parents: 67
diff changeset
510 }