annotate gcc/tree-ssa-loop-manip.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* High-level loop manipulation functions.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2004-2020 Free Software Foundation, Inc.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 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"
kono
parents: 67
diff changeset
27 #include "tree-pass.h" /* ??? for TODO_update_ssa but this isn't a pass. */
kono
parents: 67
diff changeset
28 #include "ssa.h"
kono
parents: 67
diff changeset
29 #include "gimple-pretty-print.h"
kono
parents: 67
diff changeset
30 #include "fold-const.h"
kono
parents: 67
diff changeset
31 #include "cfganal.h"
kono
parents: 67
diff changeset
32 #include "gimplify.h"
kono
parents: 67
diff changeset
33 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
34 #include "gimplify-me.h"
kono
parents: 67
diff changeset
35 #include "tree-cfg.h"
kono
parents: 67
diff changeset
36 #include "tree-ssa-loop-ivopts.h"
kono
parents: 67
diff changeset
37 #include "tree-ssa-loop-manip.h"
kono
parents: 67
diff changeset
38 #include "tree-ssa-loop-niter.h"
kono
parents: 67
diff changeset
39 #include "tree-ssa-loop.h"
kono
parents: 67
diff changeset
40 #include "tree-into-ssa.h"
kono
parents: 67
diff changeset
41 #include "tree-ssa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 #include "cfgloop.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 #include "tree-scalar-evolution.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 #include "tree-inline.h"
111
kono
parents: 67
diff changeset
45
kono
parents: 67
diff changeset
46 /* All bitmaps for rewriting into loop-closed SSA go on this obstack,
kono
parents: 67
diff changeset
47 so that we can free them all at once. */
kono
parents: 67
diff changeset
48 static bitmap_obstack loop_renamer_obstack;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 /* Creates an induction variable with value BASE + STEP * iteration in LOOP.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 It is expected that neither BASE nor STEP are shared with other expressions
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 (unless the sharing rules allow this). Use VAR as a base var_decl for it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 (if NULL, a new temporary will be created). The increment will occur at
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
54 INCR_POS (after it if AFTER is true, before it otherwise). INCR_POS and
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 AFTER can be computed using standard_iv_increment_position. The ssa versions
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 of the variable before and after increment will be stored in VAR_BEFORE and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 VAR_AFTER (unless they are NULL). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
60 create_iv (tree base, tree step, tree var, class loop *loop,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 gimple_stmt_iterator *incr_pos, bool after,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 tree *var_before, tree *var_after)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 {
111
kono
parents: 67
diff changeset
64 gassign *stmt;
kono
parents: 67
diff changeset
65 gphi *phi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 tree initial, step1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 gimple_seq stmts;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 tree vb, va;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 enum tree_code incr_op = PLUS_EXPR;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 edge pe = loop_preheader_edge (loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
111
kono
parents: 67
diff changeset
72 if (var != NULL_TREE)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 {
111
kono
parents: 67
diff changeset
74 vb = make_ssa_name (var);
kono
parents: 67
diff changeset
75 va = make_ssa_name (var);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 }
111
kono
parents: 67
diff changeset
77 else
kono
parents: 67
diff changeset
78 {
kono
parents: 67
diff changeset
79 vb = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
kono
parents: 67
diff changeset
80 va = make_temp_ssa_name (TREE_TYPE (base), NULL, "ivtmp");
kono
parents: 67
diff changeset
81 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 if (var_before)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 *var_before = vb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 if (var_after)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 *var_after = va;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 /* For easier readability of the created code, produce MINUS_EXPRs
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 when suitable. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 if (TREE_CODE (step) == INTEGER_CST)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 if (TYPE_UNSIGNED (TREE_TYPE (step)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 if (tree_int_cst_lt (step1, step))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 incr_op = MINUS_EXPR;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 step = step1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 bool ovf;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 if (!tree_expr_nonnegative_warnv_p (step, &ovf)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 && may_negate_without_overflow_p (step))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 incr_op = MINUS_EXPR;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 if (POINTER_TYPE_P (TREE_TYPE (base)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
114 if (TREE_CODE (base) == ADDR_EXPR)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
115 mark_addressable (TREE_OPERAND (base, 0));
111
kono
parents: 67
diff changeset
116 step = convert_to_ptrofftype (step);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 if (incr_op == MINUS_EXPR)
111
kono
parents: 67
diff changeset
118 step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 incr_op = POINTER_PLUS_EXPR;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 /* Gimplify the step if necessary. We put the computations in front of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 loop (i.e. the step should be loop invariant). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 step = force_gimple_operand (step, &stmts, true, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 if (stmts)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 gsi_insert_seq_on_edge_immediate (pe, stmts);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126
111
kono
parents: 67
diff changeset
127 stmt = gimple_build_assign (va, incr_op, vb, step);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
128 /* Prevent the increment from inheriting a bogus location if it is not put
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
129 immediately after a statement whose location is known. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 if (after)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
131 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
132 if (gsi_end_p (*incr_pos))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
133 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
134 edge e = single_succ_edge (gsi_bb (*incr_pos));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
135 gimple_set_location (stmt, e->goto_locus);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
136 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
137 gsi_insert_after (incr_pos, stmt, GSI_NEW_STMT);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
138 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 else
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
140 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
141 if (!gsi_end_p (*incr_pos))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
142 gimple_set_location (stmt, gimple_location (gsi_stmt (*incr_pos)));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
143 gsi_insert_before (incr_pos, stmt, GSI_NEW_STMT);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
144 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 initial = force_gimple_operand (base, &stmts, true, var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 if (stmts)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 gsi_insert_seq_on_edge_immediate (pe, stmts);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
111
kono
parents: 67
diff changeset
150 phi = create_phi_node (vb, loop->header);
kono
parents: 67
diff changeset
151 add_phi_arg (phi, initial, loop_preheader_edge (loop), UNKNOWN_LOCATION);
kono
parents: 67
diff changeset
152 add_phi_arg (phi, va, loop_latch_edge (loop), UNKNOWN_LOCATION);
kono
parents: 67
diff changeset
153 }
kono
parents: 67
diff changeset
154
kono
parents: 67
diff changeset
155 /* Return the innermost superloop LOOP of USE_LOOP that is a superloop of
kono
parents: 67
diff changeset
156 both DEF_LOOP and USE_LOOP. */
kono
parents: 67
diff changeset
157
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
158 static inline class loop *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
159 find_sibling_superloop (class loop *use_loop, class loop *def_loop)
111
kono
parents: 67
diff changeset
160 {
kono
parents: 67
diff changeset
161 unsigned ud = loop_depth (use_loop);
kono
parents: 67
diff changeset
162 unsigned dd = loop_depth (def_loop);
kono
parents: 67
diff changeset
163 gcc_assert (ud > 0 && dd > 0);
kono
parents: 67
diff changeset
164 if (ud > dd)
kono
parents: 67
diff changeset
165 use_loop = superloop_at_depth (use_loop, dd);
kono
parents: 67
diff changeset
166 if (ud < dd)
kono
parents: 67
diff changeset
167 def_loop = superloop_at_depth (def_loop, ud);
kono
parents: 67
diff changeset
168 while (loop_outer (use_loop) != loop_outer (def_loop))
kono
parents: 67
diff changeset
169 {
kono
parents: 67
diff changeset
170 use_loop = loop_outer (use_loop);
kono
parents: 67
diff changeset
171 def_loop = loop_outer (def_loop);
kono
parents: 67
diff changeset
172 gcc_assert (use_loop && def_loop);
kono
parents: 67
diff changeset
173 }
kono
parents: 67
diff changeset
174 return use_loop;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176
111
kono
parents: 67
diff changeset
177 /* DEF_BB is a basic block containing a DEF that needs rewriting into
kono
parents: 67
diff changeset
178 loop-closed SSA form. USE_BLOCKS is the set of basic blocks containing
kono
parents: 67
diff changeset
179 uses of DEF that "escape" from the loop containing DEF_BB (i.e. blocks in
kono
parents: 67
diff changeset
180 USE_BLOCKS are dominated by DEF_BB but not in the loop father of DEF_B).
kono
parents: 67
diff changeset
181 ALL_EXITS[I] is the set of all basic blocks that exit loop I.
kono
parents: 67
diff changeset
182
kono
parents: 67
diff changeset
183 Compute the subset of LOOP_EXITS that exit the loop containing DEF_BB
kono
parents: 67
diff changeset
184 or one of its loop fathers, in which DEF is live. This set is returned
kono
parents: 67
diff changeset
185 in the bitmap LIVE_EXITS.
kono
parents: 67
diff changeset
186
kono
parents: 67
diff changeset
187 Instead of computing the complete livein set of the def, we use the loop
kono
parents: 67
diff changeset
188 nesting tree as a form of poor man's structure analysis. This greatly
kono
parents: 67
diff changeset
189 speeds up the analysis, which is important because this function may be
kono
parents: 67
diff changeset
190 called on all SSA names that need rewriting, one at a time. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 static void
111
kono
parents: 67
diff changeset
193 compute_live_loop_exits (bitmap live_exits, bitmap use_blocks,
kono
parents: 67
diff changeset
194 bitmap *loop_exits, basic_block def_bb)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 {
111
kono
parents: 67
diff changeset
196 unsigned i;
kono
parents: 67
diff changeset
197 bitmap_iterator bi;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
198 class loop *def_loop = def_bb->loop_father;
111
kono
parents: 67
diff changeset
199 unsigned def_loop_depth = loop_depth (def_loop);
kono
parents: 67
diff changeset
200 bitmap def_loop_exits;
kono
parents: 67
diff changeset
201
kono
parents: 67
diff changeset
202 /* Normally the work list size is bounded by the number of basic
kono
parents: 67
diff changeset
203 blocks in the largest loop. We don't know this number, but we
kono
parents: 67
diff changeset
204 can be fairly sure that it will be relatively small. */
kono
parents: 67
diff changeset
205 auto_vec<basic_block> worklist (MAX (8, n_basic_blocks_for_fn (cfun) / 128));
kono
parents: 67
diff changeset
206
kono
parents: 67
diff changeset
207 EXECUTE_IF_SET_IN_BITMAP (use_blocks, 0, i, bi)
kono
parents: 67
diff changeset
208 {
kono
parents: 67
diff changeset
209 basic_block use_bb = BASIC_BLOCK_FOR_FN (cfun, i);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
210 class loop *use_loop = use_bb->loop_father;
111
kono
parents: 67
diff changeset
211 gcc_checking_assert (def_loop != use_loop
kono
parents: 67
diff changeset
212 && ! flow_loop_nested_p (def_loop, use_loop));
kono
parents: 67
diff changeset
213 if (! flow_loop_nested_p (use_loop, def_loop))
kono
parents: 67
diff changeset
214 use_bb = find_sibling_superloop (use_loop, def_loop)->header;
kono
parents: 67
diff changeset
215 if (bitmap_set_bit (live_exits, use_bb->index))
kono
parents: 67
diff changeset
216 worklist.safe_push (use_bb);
kono
parents: 67
diff changeset
217 }
kono
parents: 67
diff changeset
218
kono
parents: 67
diff changeset
219 /* Iterate until the worklist is empty. */
kono
parents: 67
diff changeset
220 while (! worklist.is_empty ())
kono
parents: 67
diff changeset
221 {
kono
parents: 67
diff changeset
222 edge e;
kono
parents: 67
diff changeset
223 edge_iterator ei;
kono
parents: 67
diff changeset
224
kono
parents: 67
diff changeset
225 /* Pull a block off the worklist. */
kono
parents: 67
diff changeset
226 basic_block bb = worklist.pop ();
kono
parents: 67
diff changeset
227
kono
parents: 67
diff changeset
228 /* Make sure we have at least enough room in the work list
kono
parents: 67
diff changeset
229 for all predecessors of this block. */
kono
parents: 67
diff changeset
230 worklist.reserve (EDGE_COUNT (bb->preds));
kono
parents: 67
diff changeset
231
kono
parents: 67
diff changeset
232 /* For each predecessor block. */
kono
parents: 67
diff changeset
233 FOR_EACH_EDGE (e, ei, bb->preds)
kono
parents: 67
diff changeset
234 {
kono
parents: 67
diff changeset
235 basic_block pred = e->src;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
236 class loop *pred_loop = pred->loop_father;
111
kono
parents: 67
diff changeset
237 unsigned pred_loop_depth = loop_depth (pred_loop);
kono
parents: 67
diff changeset
238 bool pred_visited;
kono
parents: 67
diff changeset
239
kono
parents: 67
diff changeset
240 /* We should have met DEF_BB along the way. */
kono
parents: 67
diff changeset
241 gcc_assert (pred != ENTRY_BLOCK_PTR_FOR_FN (cfun));
kono
parents: 67
diff changeset
242
kono
parents: 67
diff changeset
243 if (pred_loop_depth >= def_loop_depth)
kono
parents: 67
diff changeset
244 {
kono
parents: 67
diff changeset
245 if (pred_loop_depth > def_loop_depth)
kono
parents: 67
diff changeset
246 pred_loop = superloop_at_depth (pred_loop, def_loop_depth);
kono
parents: 67
diff changeset
247 /* If we've reached DEF_LOOP, our train ends here. */
kono
parents: 67
diff changeset
248 if (pred_loop == def_loop)
kono
parents: 67
diff changeset
249 continue;
kono
parents: 67
diff changeset
250 }
kono
parents: 67
diff changeset
251 else if (! flow_loop_nested_p (pred_loop, def_loop))
kono
parents: 67
diff changeset
252 pred = find_sibling_superloop (pred_loop, def_loop)->header;
kono
parents: 67
diff changeset
253
kono
parents: 67
diff changeset
254 /* Add PRED to the LIVEIN set. PRED_VISITED is true if
kono
parents: 67
diff changeset
255 we had already added PRED to LIVEIN before. */
kono
parents: 67
diff changeset
256 pred_visited = !bitmap_set_bit (live_exits, pred->index);
kono
parents: 67
diff changeset
257
kono
parents: 67
diff changeset
258 /* If we have visited PRED before, don't add it to the worklist.
kono
parents: 67
diff changeset
259 If BB dominates PRED, then we're probably looking at a loop.
kono
parents: 67
diff changeset
260 We're only interested in looking up in the dominance tree
kono
parents: 67
diff changeset
261 because DEF_BB dominates all the uses. */
kono
parents: 67
diff changeset
262 if (pred_visited || dominated_by_p (CDI_DOMINATORS, pred, bb))
kono
parents: 67
diff changeset
263 continue;
kono
parents: 67
diff changeset
264
kono
parents: 67
diff changeset
265 worklist.quick_push (pred);
kono
parents: 67
diff changeset
266 }
kono
parents: 67
diff changeset
267 }
kono
parents: 67
diff changeset
268
kono
parents: 67
diff changeset
269 def_loop_exits = BITMAP_ALLOC (&loop_renamer_obstack);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
270 for (class loop *loop = def_loop;
111
kono
parents: 67
diff changeset
271 loop != current_loops->tree_root;
kono
parents: 67
diff changeset
272 loop = loop_outer (loop))
kono
parents: 67
diff changeset
273 bitmap_ior_into (def_loop_exits, loop_exits[loop->num]);
kono
parents: 67
diff changeset
274 bitmap_and_into (live_exits, def_loop_exits);
kono
parents: 67
diff changeset
275 BITMAP_FREE (def_loop_exits);
kono
parents: 67
diff changeset
276 }
kono
parents: 67
diff changeset
277
kono
parents: 67
diff changeset
278 /* Add a loop-closing PHI for VAR in basic block EXIT. */
kono
parents: 67
diff changeset
279
kono
parents: 67
diff changeset
280 static void
kono
parents: 67
diff changeset
281 add_exit_phi (basic_block exit, tree var)
kono
parents: 67
diff changeset
282 {
kono
parents: 67
diff changeset
283 gphi *phi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286
111
kono
parents: 67
diff changeset
287 /* Check that at least one of the edges entering the EXIT block exits
kono
parents: 67
diff changeset
288 the loop, or a superloop of that loop, that VAR is defined in. */
kono
parents: 67
diff changeset
289 if (flag_checking)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 {
111
kono
parents: 67
diff changeset
291 gimple *def_stmt = SSA_NAME_DEF_STMT (var);
kono
parents: 67
diff changeset
292 basic_block def_bb = gimple_bb (def_stmt);
kono
parents: 67
diff changeset
293 FOR_EACH_EDGE (e, ei, exit->preds)
kono
parents: 67
diff changeset
294 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
295 class loop *aloop = find_common_loop (def_bb->loop_father,
111
kono
parents: 67
diff changeset
296 e->src->loop_father);
kono
parents: 67
diff changeset
297 if (!flow_bb_inside_loop_p (aloop, e->dest))
kono
parents: 67
diff changeset
298 break;
kono
parents: 67
diff changeset
299 }
kono
parents: 67
diff changeset
300 gcc_assert (e);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302
111
kono
parents: 67
diff changeset
303 phi = create_phi_node (NULL_TREE, exit);
kono
parents: 67
diff changeset
304 create_new_def_for (var, phi, gimple_phi_result_ptr (phi));
kono
parents: 67
diff changeset
305 FOR_EACH_EDGE (e, ei, exit->preds)
kono
parents: 67
diff changeset
306 add_phi_arg (phi, var, e, UNKNOWN_LOCATION);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307
111
kono
parents: 67
diff changeset
308 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
309 {
kono
parents: 67
diff changeset
310 fprintf (dump_file, ";; Created LCSSA PHI: ");
kono
parents: 67
diff changeset
311 print_gimple_stmt (dump_file, phi, 0, dump_flags);
kono
parents: 67
diff changeset
312 }
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 /* Add exit phis for VAR that is used in LIVEIN.
111
kono
parents: 67
diff changeset
316 Exits of the loops are stored in LOOP_EXITS. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 static void
111
kono
parents: 67
diff changeset
319 add_exit_phis_var (tree var, bitmap use_blocks, bitmap *loop_exits)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 unsigned index;
111
kono
parents: 67
diff changeset
322 bitmap_iterator bi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 basic_block def_bb = gimple_bb (SSA_NAME_DEF_STMT (var));
111
kono
parents: 67
diff changeset
324 bitmap live_exits = BITMAP_ALLOC (&loop_renamer_obstack);
kono
parents: 67
diff changeset
325
kono
parents: 67
diff changeset
326 gcc_checking_assert (! bitmap_bit_p (use_blocks, def_bb->index));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327
111
kono
parents: 67
diff changeset
328 compute_live_loop_exits (live_exits, use_blocks, loop_exits, def_bb);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
111
kono
parents: 67
diff changeset
330 EXECUTE_IF_SET_IN_BITMAP (live_exits, 0, index, bi)
kono
parents: 67
diff changeset
331 {
kono
parents: 67
diff changeset
332 add_exit_phi (BASIC_BLOCK_FOR_FN (cfun, index), var);
kono
parents: 67
diff changeset
333 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334
111
kono
parents: 67
diff changeset
335 BITMAP_FREE (live_exits);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 /* Add exit phis for the names marked in NAMES_TO_RENAME.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 Exits of the loops are stored in EXITS. Sets of blocks where the ssa
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 names are used are stored in USE_BLOCKS. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 static void
111
kono
parents: 67
diff changeset
343 add_exit_phis (bitmap names_to_rename, bitmap *use_blocks, bitmap *loop_exits)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 unsigned i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 bitmap_iterator bi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 EXECUTE_IF_SET_IN_BITMAP (names_to_rename, 0, i, bi)
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 add_exit_phis_var (ssa_name (i), use_blocks[i], loop_exits);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 }
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
111
kono
parents: 67
diff changeset
354 /* Fill the array of bitmaps LOOP_EXITS with all loop exit edge targets. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355
111
kono
parents: 67
diff changeset
356 static void
kono
parents: 67
diff changeset
357 get_loops_exits (bitmap *loop_exits)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
359 class loop *loop;
111
kono
parents: 67
diff changeset
360 unsigned j;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362
111
kono
parents: 67
diff changeset
363 FOR_EACH_LOOP (loop, 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 {
111
kono
parents: 67
diff changeset
365 vec<edge> exit_edges = get_loop_exit_edges (loop);
kono
parents: 67
diff changeset
366 loop_exits[loop->num] = BITMAP_ALLOC (&loop_renamer_obstack);
kono
parents: 67
diff changeset
367 FOR_EACH_VEC_ELT (exit_edges, j, e)
kono
parents: 67
diff changeset
368 bitmap_set_bit (loop_exits[loop->num], e->dest->index);
kono
parents: 67
diff changeset
369 exit_edges.release ();
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 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 /* For USE in BB, if it is used outside of the loop it is defined in,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 mark it for rewrite. Record basic block BB where it is used
111
kono
parents: 67
diff changeset
375 to USE_BLOCKS. Record the ssa name index to NEED_PHIS bitmap.
kono
parents: 67
diff changeset
376 Note that for USEs in phis, BB should be the src of the edge corresponding to
kono
parents: 67
diff changeset
377 the use, rather than the bb containing the phi. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 find_uses_to_rename_use (basic_block bb, tree use, bitmap *use_blocks,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 bitmap need_phis)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 unsigned ver;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 basic_block def_bb;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
385 class loop *def_loop;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 if (TREE_CODE (use) != SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 return;
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 ver = SSA_NAME_VERSION (use);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 def_bb = gimple_bb (SSA_NAME_DEF_STMT (use));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 if (!def_bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 def_loop = def_bb->loop_father;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 /* If the definition is not inside a loop, it is not interesting. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 if (!loop_outer (def_loop))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 /* If the use is not outside of the loop it is defined in, it is not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 interesting. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 if (flow_bb_inside_loop_p (def_loop, bb))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404
111
kono
parents: 67
diff changeset
405 /* If we're seeing VER for the first time, we still have to allocate
kono
parents: 67
diff changeset
406 a bitmap for its uses. */
kono
parents: 67
diff changeset
407 if (bitmap_set_bit (need_phis, ver))
kono
parents: 67
diff changeset
408 use_blocks[ver] = BITMAP_ALLOC (&loop_renamer_obstack);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 bitmap_set_bit (use_blocks[ver], bb->index);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411
111
kono
parents: 67
diff changeset
412 /* For uses matching USE_FLAGS in STMT, mark names that are used outside of the
kono
parents: 67
diff changeset
413 loop they are defined to rewrite. Record the set of blocks in which the ssa
kono
parents: 67
diff changeset
414 names are used to USE_BLOCKS, and the ssa names themselves to NEED_PHIS. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 static void
111
kono
parents: 67
diff changeset
417 find_uses_to_rename_stmt (gimple *stmt, bitmap *use_blocks, bitmap need_phis,
kono
parents: 67
diff changeset
418 int use_flags)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 ssa_op_iter iter;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 tree var;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 basic_block bb = gimple_bb (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
424 if (is_gimple_debug (stmt))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
425 return;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
426
111
kono
parents: 67
diff changeset
427 /* FOR_EACH_SSA_TREE_OPERAND iterator does not allows SSA_OP_VIRTUAL_USES
kono
parents: 67
diff changeset
428 only. */
kono
parents: 67
diff changeset
429 if (use_flags == SSA_OP_VIRTUAL_USES)
kono
parents: 67
diff changeset
430 {
kono
parents: 67
diff changeset
431 tree vuse = gimple_vuse (stmt);
kono
parents: 67
diff changeset
432 if (vuse != NULL_TREE)
kono
parents: 67
diff changeset
433 find_uses_to_rename_use (bb, gimple_vuse (stmt), use_blocks, need_phis);
kono
parents: 67
diff changeset
434 }
kono
parents: 67
diff changeset
435 else
kono
parents: 67
diff changeset
436 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, use_flags)
kono
parents: 67
diff changeset
437 find_uses_to_rename_use (bb, var, use_blocks, need_phis);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439
111
kono
parents: 67
diff changeset
440 /* Marks names matching USE_FLAGS that are used in BB and outside of the loop
kono
parents: 67
diff changeset
441 they are defined in for rewrite. Records the set of blocks in which the ssa
kono
parents: 67
diff changeset
442 names are used to USE_BLOCKS. Record the SSA names that will
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 need exit PHIs in NEED_PHIS. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 static void
111
kono
parents: 67
diff changeset
446 find_uses_to_rename_bb (basic_block bb, bitmap *use_blocks, bitmap need_phis,
kono
parents: 67
diff changeset
447 int use_flags)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 edge_iterator ei;
111
kono
parents: 67
diff changeset
451 bool do_virtuals = (use_flags & SSA_OP_VIRTUAL_USES) != 0;
kono
parents: 67
diff changeset
452 bool do_nonvirtuals = (use_flags & SSA_OP_USE) != 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 FOR_EACH_EDGE (e, ei, bb->succs)
111
kono
parents: 67
diff changeset
455 for (gphi_iterator bsi = gsi_start_phis (e->dest); !gsi_end_p (bsi);
kono
parents: 67
diff changeset
456 gsi_next (&bsi))
kono
parents: 67
diff changeset
457 {
kono
parents: 67
diff changeset
458 gphi *phi = bsi.phi ();
kono
parents: 67
diff changeset
459 bool virtual_p = virtual_operand_p (gimple_phi_result (phi));
kono
parents: 67
diff changeset
460 if ((virtual_p && do_virtuals)
kono
parents: 67
diff changeset
461 || (!virtual_p && do_nonvirtuals))
kono
parents: 67
diff changeset
462 find_uses_to_rename_use (bb, PHI_ARG_DEF_FROM_EDGE (phi, e),
kono
parents: 67
diff changeset
463 use_blocks, need_phis);
kono
parents: 67
diff changeset
464 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
465
111
kono
parents: 67
diff changeset
466 for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
kono
parents: 67
diff changeset
467 gsi_next (&bsi))
kono
parents: 67
diff changeset
468 find_uses_to_rename_stmt (gsi_stmt (bsi), use_blocks, need_phis,
kono
parents: 67
diff changeset
469 use_flags);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
471
111
kono
parents: 67
diff changeset
472 /* Marks names matching USE_FLAGS that are used outside of the loop they are
kono
parents: 67
diff changeset
473 defined in for rewrite. Records the set of blocks in which the ssa names are
kono
parents: 67
diff changeset
474 used to USE_BLOCKS. Record the SSA names that will need exit PHIs in
kono
parents: 67
diff changeset
475 NEED_PHIS. If CHANGED_BBS is not NULL, scan only blocks in this set. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 static void
111
kono
parents: 67
diff changeset
478 find_uses_to_rename (bitmap changed_bbs, bitmap *use_blocks, bitmap need_phis,
kono
parents: 67
diff changeset
479 int use_flags)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 unsigned index;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 bitmap_iterator bi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484
111
kono
parents: 67
diff changeset
485 if (changed_bbs)
kono
parents: 67
diff changeset
486 EXECUTE_IF_SET_IN_BITMAP (changed_bbs, 0, index, bi)
kono
parents: 67
diff changeset
487 {
kono
parents: 67
diff changeset
488 bb = BASIC_BLOCK_FOR_FN (cfun, index);
kono
parents: 67
diff changeset
489 if (bb)
kono
parents: 67
diff changeset
490 find_uses_to_rename_bb (bb, use_blocks, need_phis, use_flags);
kono
parents: 67
diff changeset
491 }
kono
parents: 67
diff changeset
492 else
kono
parents: 67
diff changeset
493 FOR_EACH_BB_FN (bb, cfun)
kono
parents: 67
diff changeset
494 find_uses_to_rename_bb (bb, use_blocks, need_phis, use_flags);
kono
parents: 67
diff changeset
495 }
kono
parents: 67
diff changeset
496
kono
parents: 67
diff changeset
497 /* Mark uses of DEF that are used outside of the loop they are defined in for
kono
parents: 67
diff changeset
498 rewrite. Record the set of blocks in which the ssa names are used to
kono
parents: 67
diff changeset
499 USE_BLOCKS. Record the SSA names that will need exit PHIs in NEED_PHIS. */
kono
parents: 67
diff changeset
500
kono
parents: 67
diff changeset
501 static void
kono
parents: 67
diff changeset
502 find_uses_to_rename_def (tree def, bitmap *use_blocks, bitmap need_phis)
kono
parents: 67
diff changeset
503 {
kono
parents: 67
diff changeset
504 gimple *use_stmt;
kono
parents: 67
diff changeset
505 imm_use_iterator imm_iter;
kono
parents: 67
diff changeset
506
kono
parents: 67
diff changeset
507 FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 {
111
kono
parents: 67
diff changeset
509 if (is_gimple_debug (use_stmt))
kono
parents: 67
diff changeset
510 continue;
kono
parents: 67
diff changeset
511
kono
parents: 67
diff changeset
512 basic_block use_bb = gimple_bb (use_stmt);
kono
parents: 67
diff changeset
513
kono
parents: 67
diff changeset
514 use_operand_p use_p;
kono
parents: 67
diff changeset
515 FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 {
111
kono
parents: 67
diff changeset
517 if (gimple_code (use_stmt) == GIMPLE_PHI)
kono
parents: 67
diff changeset
518 {
kono
parents: 67
diff changeset
519 edge e = gimple_phi_arg_edge (as_a <gphi *> (use_stmt),
kono
parents: 67
diff changeset
520 PHI_ARG_INDEX_FROM_USE (use_p));
kono
parents: 67
diff changeset
521 use_bb = e->src;
kono
parents: 67
diff changeset
522 }
kono
parents: 67
diff changeset
523 find_uses_to_rename_use (use_bb, USE_FROM_PTR (use_p), use_blocks,
kono
parents: 67
diff changeset
524 need_phis);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 }
111
kono
parents: 67
diff changeset
527 }
kono
parents: 67
diff changeset
528
kono
parents: 67
diff changeset
529 /* Marks names matching USE_FLAGS that are defined in LOOP and used outside of
kono
parents: 67
diff changeset
530 it for rewrite. Records the set of blocks in which the ssa names are used to
kono
parents: 67
diff changeset
531 USE_BLOCKS. Record the SSA names that will need exit PHIs in NEED_PHIS. */
kono
parents: 67
diff changeset
532
kono
parents: 67
diff changeset
533 static void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
534 find_uses_to_rename_in_loop (class loop *loop, bitmap *use_blocks,
111
kono
parents: 67
diff changeset
535 bitmap need_phis, int use_flags)
kono
parents: 67
diff changeset
536 {
kono
parents: 67
diff changeset
537 bool do_virtuals = (use_flags & SSA_OP_VIRTUAL_USES) != 0;
kono
parents: 67
diff changeset
538 bool do_nonvirtuals = (use_flags & SSA_OP_USE) != 0;
kono
parents: 67
diff changeset
539 int def_flags = ((do_virtuals ? SSA_OP_VIRTUAL_DEFS : 0)
kono
parents: 67
diff changeset
540 | (do_nonvirtuals ? SSA_OP_DEF : 0));
kono
parents: 67
diff changeset
541
kono
parents: 67
diff changeset
542
kono
parents: 67
diff changeset
543 basic_block *bbs = get_loop_body (loop);
kono
parents: 67
diff changeset
544
kono
parents: 67
diff changeset
545 for (unsigned int i = 0; i < loop->num_nodes; i++)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 {
111
kono
parents: 67
diff changeset
547 basic_block bb = bbs[i];
kono
parents: 67
diff changeset
548
kono
parents: 67
diff changeset
549 for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
kono
parents: 67
diff changeset
550 gsi_next (&bsi))
kono
parents: 67
diff changeset
551 {
kono
parents: 67
diff changeset
552 gphi *phi = bsi.phi ();
kono
parents: 67
diff changeset
553 tree res = gimple_phi_result (phi);
kono
parents: 67
diff changeset
554 bool virtual_p = virtual_operand_p (res);
kono
parents: 67
diff changeset
555 if ((virtual_p && do_virtuals)
kono
parents: 67
diff changeset
556 || (!virtual_p && do_nonvirtuals))
kono
parents: 67
diff changeset
557 find_uses_to_rename_def (res, use_blocks, need_phis);
kono
parents: 67
diff changeset
558 }
kono
parents: 67
diff changeset
559
kono
parents: 67
diff changeset
560 for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
kono
parents: 67
diff changeset
561 gsi_next (&bsi))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 {
111
kono
parents: 67
diff changeset
563 gimple *stmt = gsi_stmt (bsi);
kono
parents: 67
diff changeset
564 /* FOR_EACH_SSA_TREE_OPERAND iterator does not allows
kono
parents: 67
diff changeset
565 SSA_OP_VIRTUAL_DEFS only. */
kono
parents: 67
diff changeset
566 if (def_flags == SSA_OP_VIRTUAL_DEFS)
kono
parents: 67
diff changeset
567 {
kono
parents: 67
diff changeset
568 tree vdef = gimple_vdef (stmt);
kono
parents: 67
diff changeset
569 if (vdef != NULL)
kono
parents: 67
diff changeset
570 find_uses_to_rename_def (vdef, use_blocks, need_phis);
kono
parents: 67
diff changeset
571 }
kono
parents: 67
diff changeset
572 else
kono
parents: 67
diff changeset
573 {
kono
parents: 67
diff changeset
574 tree var;
kono
parents: 67
diff changeset
575 ssa_op_iter iter;
kono
parents: 67
diff changeset
576 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, def_flags)
kono
parents: 67
diff changeset
577 find_uses_to_rename_def (var, use_blocks, need_phis);
kono
parents: 67
diff changeset
578 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 }
111
kono
parents: 67
diff changeset
581
kono
parents: 67
diff changeset
582 XDELETEVEC (bbs);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 /* Rewrites the program into a loop closed ssa form -- i.e. inserts extra
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 phi nodes to ensure that no variable is used outside the loop it is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 defined in.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 This strengthening of the basic ssa form has several advantages:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 1) Updating it during unrolling/peeling/versioning is trivial, since
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 we do not need to care about the uses outside of the loop.
111
kono
parents: 67
diff changeset
593 The same applies to virtual operands which are also rewritten into
kono
parents: 67
diff changeset
594 loop closed SSA form. Note that virtual operands are always live
kono
parents: 67
diff changeset
595 until function exit.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 2) The behavior of all uses of an induction variable is the same.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 Without this, you need to distinguish the case when the variable
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 is used outside of the loop it is defined in, for example
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 for (i = 0; i < 100; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 for (j = 0; j < 100; j++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 k = i + j;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 use1 (k);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 use2 (k);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 Looking from the outer loop with the normal SSA form, the first use of k
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 is not well-behaved, while the second one is an induction variable with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 base 99 and step 1.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
613
111
kono
parents: 67
diff changeset
614 If LOOP is non-null, only rewrite uses that have defs in LOOP. Otherwise,
kono
parents: 67
diff changeset
615 if CHANGED_BBS is not NULL, we look for uses outside loops only in the
kono
parents: 67
diff changeset
616 basic blocks in this set.
kono
parents: 67
diff changeset
617
kono
parents: 67
diff changeset
618 USE_FLAGS allows us to specify whether we want virtual, non-virtual or
kono
parents: 67
diff changeset
619 both variables rewritten.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 UPDATE_FLAG is used in the call to update_ssa. See
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 TODO_update_ssa* for documentation. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
623
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 void
111
kono
parents: 67
diff changeset
625 rewrite_into_loop_closed_ssa_1 (bitmap changed_bbs, unsigned update_flag,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
626 int use_flags, class loop *loop)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 bitmap *use_blocks;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 bitmap names_to_rename;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 loops_state_set (LOOP_CLOSED_SSA);
111
kono
parents: 67
diff changeset
632 if (number_of_loops (cfun) <= 1)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 /* If the pass has caused the SSA form to be out-of-date, update it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 now. */
111
kono
parents: 67
diff changeset
637 if (update_flag != 0)
kono
parents: 67
diff changeset
638 update_ssa (update_flag);
kono
parents: 67
diff changeset
639 else if (flag_checking)
kono
parents: 67
diff changeset
640 verify_ssa (true, true);
kono
parents: 67
diff changeset
641
kono
parents: 67
diff changeset
642 bitmap_obstack_initialize (&loop_renamer_obstack);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643
111
kono
parents: 67
diff changeset
644 names_to_rename = BITMAP_ALLOC (&loop_renamer_obstack);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645
111
kono
parents: 67
diff changeset
646 /* Uses of names to rename. We don't have to initialize this array,
kono
parents: 67
diff changeset
647 because we know that we will only have entries for the SSA names
kono
parents: 67
diff changeset
648 in NAMES_TO_RENAME. */
kono
parents: 67
diff changeset
649 use_blocks = XNEWVEC (bitmap, num_ssa_names);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650
111
kono
parents: 67
diff changeset
651 if (loop != NULL)
kono
parents: 67
diff changeset
652 {
kono
parents: 67
diff changeset
653 gcc_assert (changed_bbs == NULL);
kono
parents: 67
diff changeset
654 find_uses_to_rename_in_loop (loop, use_blocks, names_to_rename,
kono
parents: 67
diff changeset
655 use_flags);
kono
parents: 67
diff changeset
656 }
kono
parents: 67
diff changeset
657 else
kono
parents: 67
diff changeset
658 {
kono
parents: 67
diff changeset
659 gcc_assert (loop == NULL);
kono
parents: 67
diff changeset
660 find_uses_to_rename (changed_bbs, use_blocks, names_to_rename, use_flags);
kono
parents: 67
diff changeset
661 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662
111
kono
parents: 67
diff changeset
663 if (!bitmap_empty_p (names_to_rename))
kono
parents: 67
diff changeset
664 {
kono
parents: 67
diff changeset
665 /* An array of bitmaps where LOOP_EXITS[I] is the set of basic blocks
kono
parents: 67
diff changeset
666 that are the destination of an edge exiting loop number I. */
kono
parents: 67
diff changeset
667 bitmap *loop_exits = XNEWVEC (bitmap, number_of_loops (cfun));
kono
parents: 67
diff changeset
668 get_loops_exits (loop_exits);
kono
parents: 67
diff changeset
669
kono
parents: 67
diff changeset
670 /* Add the PHI nodes on exits of the loops for the names we need to
kono
parents: 67
diff changeset
671 rewrite. */
kono
parents: 67
diff changeset
672 add_exit_phis (names_to_rename, use_blocks, loop_exits);
kono
parents: 67
diff changeset
673
kono
parents: 67
diff changeset
674 free (loop_exits);
kono
parents: 67
diff changeset
675
kono
parents: 67
diff changeset
676 /* Fix up all the names found to be used outside their original
kono
parents: 67
diff changeset
677 loops. */
kono
parents: 67
diff changeset
678 update_ssa (TODO_update_ssa);
kono
parents: 67
diff changeset
679 }
kono
parents: 67
diff changeset
680
kono
parents: 67
diff changeset
681 bitmap_obstack_release (&loop_renamer_obstack);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 free (use_blocks);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684
111
kono
parents: 67
diff changeset
685 /* Rewrites the non-virtual defs and uses into a loop closed ssa form. If
kono
parents: 67
diff changeset
686 CHANGED_BBS is not NULL, we look for uses outside loops only in the basic
kono
parents: 67
diff changeset
687 blocks in this set. UPDATE_FLAG is used in the call to update_ssa. See
kono
parents: 67
diff changeset
688 TODO_update_ssa* for documentation. */
kono
parents: 67
diff changeset
689
kono
parents: 67
diff changeset
690 void
kono
parents: 67
diff changeset
691 rewrite_into_loop_closed_ssa (bitmap changed_bbs, unsigned update_flag)
kono
parents: 67
diff changeset
692 {
kono
parents: 67
diff changeset
693 rewrite_into_loop_closed_ssa_1 (changed_bbs, update_flag, SSA_OP_USE, NULL);
kono
parents: 67
diff changeset
694 }
kono
parents: 67
diff changeset
695
kono
parents: 67
diff changeset
696 /* Rewrites virtual defs and uses with def in LOOP into loop closed ssa
kono
parents: 67
diff changeset
697 form. */
kono
parents: 67
diff changeset
698
kono
parents: 67
diff changeset
699 void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
700 rewrite_virtuals_into_loop_closed_ssa (class loop *loop)
111
kono
parents: 67
diff changeset
701 {
kono
parents: 67
diff changeset
702 rewrite_into_loop_closed_ssa_1 (NULL, 0, SSA_OP_VIRTUAL_USES, loop);
kono
parents: 67
diff changeset
703 }
kono
parents: 67
diff changeset
704
kono
parents: 67
diff changeset
705 /* Check invariants of the loop closed ssa form for the def in DEF_BB. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 static void
111
kono
parents: 67
diff changeset
708 check_loop_closed_ssa_def (basic_block def_bb, tree def)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 {
111
kono
parents: 67
diff changeset
710 use_operand_p use_p;
kono
parents: 67
diff changeset
711 imm_use_iterator iterator;
kono
parents: 67
diff changeset
712 FOR_EACH_IMM_USE_FAST (use_p, iterator, def)
kono
parents: 67
diff changeset
713 {
kono
parents: 67
diff changeset
714 if (is_gimple_debug (USE_STMT (use_p)))
kono
parents: 67
diff changeset
715 continue;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
716
111
kono
parents: 67
diff changeset
717 basic_block use_bb = gimple_bb (USE_STMT (use_p));
kono
parents: 67
diff changeset
718 if (is_a <gphi *> (USE_STMT (use_p)))
kono
parents: 67
diff changeset
719 use_bb = EDGE_PRED (use_bb, PHI_ARG_INDEX_FROM_USE (use_p))->src;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720
111
kono
parents: 67
diff changeset
721 gcc_assert (flow_bb_inside_loop_p (def_bb->loop_father, use_bb));
kono
parents: 67
diff changeset
722 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724
111
kono
parents: 67
diff changeset
725 /* Checks invariants of loop closed ssa form in BB. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 static void
111
kono
parents: 67
diff changeset
728 check_loop_closed_ssa_bb (basic_block bb)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 {
111
kono
parents: 67
diff changeset
730 for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
kono
parents: 67
diff changeset
731 gsi_next (&bsi))
kono
parents: 67
diff changeset
732 {
kono
parents: 67
diff changeset
733 gphi *phi = bsi.phi ();
kono
parents: 67
diff changeset
734
kono
parents: 67
diff changeset
735 if (!virtual_operand_p (PHI_RESULT (phi)))
kono
parents: 67
diff changeset
736 check_loop_closed_ssa_def (bb, PHI_RESULT (phi));
kono
parents: 67
diff changeset
737 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738
111
kono
parents: 67
diff changeset
739 for (gimple_stmt_iterator bsi = gsi_start_nondebug_bb (bb); !gsi_end_p (bsi);
kono
parents: 67
diff changeset
740 gsi_next_nondebug (&bsi))
kono
parents: 67
diff changeset
741 {
kono
parents: 67
diff changeset
742 ssa_op_iter iter;
kono
parents: 67
diff changeset
743 tree var;
kono
parents: 67
diff changeset
744 gimple *stmt = gsi_stmt (bsi);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
745
111
kono
parents: 67
diff changeset
746 FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF)
kono
parents: 67
diff changeset
747 check_loop_closed_ssa_def (bb, var);
kono
parents: 67
diff changeset
748 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
751 /* Checks that invariants of the loop closed ssa form are preserved.
111
kono
parents: 67
diff changeset
752 Call verify_ssa when VERIFY_SSA_P is true. Note all loops are checked
kono
parents: 67
diff changeset
753 if LOOP is NULL, otherwise, only LOOP is checked. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754
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
755 DEBUG_FUNCTION void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
756 verify_loop_closed_ssa (bool verify_ssa_p, class loop *loop)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 {
111
kono
parents: 67
diff changeset
758 if (number_of_loops (cfun) <= 1)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
761 if (verify_ssa_p)
111
kono
parents: 67
diff changeset
762 verify_ssa (false, true);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763
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
764 timevar_push (TV_VERIFY_LOOP_CLOSED);
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
765
111
kono
parents: 67
diff changeset
766 if (loop == NULL)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 {
111
kono
parents: 67
diff changeset
768 basic_block bb;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769
111
kono
parents: 67
diff changeset
770 FOR_EACH_BB_FN (bb, cfun)
kono
parents: 67
diff changeset
771 if (bb->loop_father && bb->loop_father->num > 0)
kono
parents: 67
diff changeset
772 check_loop_closed_ssa_bb (bb);
kono
parents: 67
diff changeset
773 }
kono
parents: 67
diff changeset
774 else
kono
parents: 67
diff changeset
775 {
kono
parents: 67
diff changeset
776 basic_block *bbs = get_loop_body (loop);
kono
parents: 67
diff changeset
777
kono
parents: 67
diff changeset
778 for (unsigned i = 0; i < loop->num_nodes; ++i)
kono
parents: 67
diff changeset
779 check_loop_closed_ssa_bb (bbs[i]);
kono
parents: 67
diff changeset
780
kono
parents: 67
diff changeset
781 free (bbs);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 }
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
783
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
784 timevar_pop (TV_VERIFY_LOOP_CLOSED);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 /* Split loop exit edge EXIT. The things are a bit complicated by a need to
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
788 preserve the loop closed ssa form. If COPY_CONSTANTS_P is true then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
789 forwarder PHIs are also created for constant arguments.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
790 The newly created block is returned. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 basic_block
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
793 split_loop_exit_edge (edge exit, bool copy_constants_p)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 basic_block dest = exit->dest;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 basic_block bb = split_edge (exit);
111
kono
parents: 67
diff changeset
797 gphi *phi, *new_phi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 tree new_name, name;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 use_operand_p op_p;
111
kono
parents: 67
diff changeset
800 gphi_iterator psi;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
801 location_t locus;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 for (psi = gsi_start_phis (dest); !gsi_end_p (psi); gsi_next (&psi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 {
111
kono
parents: 67
diff changeset
805 phi = psi.phi ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 op_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, single_succ_edge (bb));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
807 locus = gimple_phi_arg_location_from_edge (phi, single_succ_edge (bb));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 name = USE_FROM_PTR (op_p);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 /* If the argument of the PHI node is a constant, we do not need
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812 to keep it inside loop. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
813 if (TREE_CODE (name) != SSA_NAME
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
814 && !copy_constants_p)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
816
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 /* Otherwise create an auxiliary phi node that will copy the value
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 of the SSA name out of the loop. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
819 new_name = duplicate_ssa_name (PHI_RESULT (phi), NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 new_phi = create_phi_node (new_name, bb);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
821 add_phi_arg (new_phi, name, exit, locus);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 SET_USE (op_p, new_name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 return bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828 /* Returns the basic block in that statements should be emitted for induction
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829 variables incremented at the end of the LOOP. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 basic_block
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
832 ip_end_pos (class loop *loop)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834 return loop->latch;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 /* Returns the basic block in that statements should be emitted for induction
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 variables incremented just before exit condition of a LOOP. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 basic_block
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
841 ip_normal_pos (class loop *loop)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842 {
111
kono
parents: 67
diff changeset
843 gimple *last;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 edge exit;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
846
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 if (!single_pred_p (loop->latch))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 bb = single_pred (loop->latch);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 last = last_stmt (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 if (!last
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 || gimple_code (last) != GIMPLE_COND)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856 exit = EDGE_SUCC (bb, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 if (exit->dest == loop->latch)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
858 exit = EDGE_SUCC (bb, 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
859
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 if (flow_bb_inside_loop_p (loop, exit->dest))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
863 return bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
864 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 /* Stores the standard position for induction variable increment in LOOP
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 (just before the exit condition if it is available and latch block is empty,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
868 end of the latch block otherwise) to BSI. INSERT_AFTER is set to true if
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869 the increment should be inserted after *BSI. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
870
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
872 standard_iv_increment_position (class loop *loop, gimple_stmt_iterator *bsi,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
873 bool *insert_after)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875 basic_block bb = ip_normal_pos (loop), latch = ip_end_pos (loop);
111
kono
parents: 67
diff changeset
876 gimple *last = last_stmt (latch);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 if (!bb
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 || (last && gimple_code (last) != GIMPLE_LABEL))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
881 *bsi = gsi_last_bb (latch);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 *insert_after = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
885 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 *bsi = gsi_last_bb (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
887 *insert_after = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
889 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
890
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
891 /* Copies phi node arguments for duplicated blocks. The index of the first
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892 duplicated block is FIRST_NEW_BLOCK. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
893
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
895 copy_phi_node_args (unsigned first_new_block)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
896 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
897 unsigned i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
898
111
kono
parents: 67
diff changeset
899 for (i = first_new_block; i < (unsigned) last_basic_block_for_fn (cfun); i++)
kono
parents: 67
diff changeset
900 BASIC_BLOCK_FOR_FN (cfun, i)->flags |= BB_DUPLICATED;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
901
111
kono
parents: 67
diff changeset
902 for (i = first_new_block; i < (unsigned) last_basic_block_for_fn (cfun); i++)
kono
parents: 67
diff changeset
903 add_phi_args_after_copy_bb (BASIC_BLOCK_FOR_FN (cfun, i));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904
111
kono
parents: 67
diff changeset
905 for (i = first_new_block; i < (unsigned) last_basic_block_for_fn (cfun); i++)
kono
parents: 67
diff changeset
906 BASIC_BLOCK_FOR_FN (cfun, i)->flags &= ~BB_DUPLICATED;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
909
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
910 /* The same as cfgloopmanip.c:duplicate_loop_to_header_edge, but also
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 updates the PHI nodes at start of the copied region. In order to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 achieve this, only loops whose exits all lead to the same location
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
913 are handled.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 Notice that we do not completely update the SSA web after
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 duplication. The caller is responsible for calling update_ssa
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 after the loop has been duplicated. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
920 gimple_duplicate_loop_to_header_edge (class loop *loop, edge e,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 unsigned int ndupl, sbitmap wont_exit,
111
kono
parents: 67
diff changeset
922 edge orig, vec<edge> *to_remove,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 int flags)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
924 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
925 unsigned first_new_block;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927 if (!loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929 if (!loops_state_satisfies_p (LOOPS_HAVE_PREHEADERS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
930 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
931
111
kono
parents: 67
diff changeset
932 first_new_block = last_basic_block_for_fn (cfun);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
933 if (!duplicate_loop_to_header_edge (loop, e, ndupl, wont_exit,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934 orig, to_remove, flags))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937 /* Readd the removed phi args for e. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 flush_pending_stmts (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
940 /* Copy the phi node arguments. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941 copy_phi_node_args (first_new_block);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
943 scev_reset ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
944
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
945 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
946 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
947
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 /* Returns true if we can unroll LOOP FACTOR times. Number
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 of iterations of the loop is returned in NITER. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
950
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
951 bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
952 can_unroll_loop_p (class loop *loop, unsigned factor,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
953 class tree_niter_desc *niter)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 edge exit;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 /* Check whether unrolling is possible. We only want to unroll loops
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 for that we are able to determine number of iterations. We also
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959 want to split the extra iterations of the loop from its end,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 therefore we require that the loop has precisely one
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961 exit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
963 exit = single_dom_exit (loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
964 if (!exit)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
966
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
967 if (!number_of_iterations_exit (loop, exit, niter, false)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
968 || niter->cmp == ERROR_MARK
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969 /* Scalar evolutions analysis might have copy propagated
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
970 the abnormal ssa names into these expressions, hence
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971 emitting the computations based on them during loop
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
972 unrolling might create overlapping life ranges for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
973 them, and failures in out-of-ssa. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 || contains_abnormal_ssa_name_p (niter->may_be_zero)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
975 || contains_abnormal_ssa_name_p (niter->control.base)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976 || contains_abnormal_ssa_name_p (niter->control.step)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
977 || contains_abnormal_ssa_name_p (niter->bound))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
978 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
980 /* And of course, we must be able to duplicate the loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
981 if (!can_duplicate_loop_p (loop))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
982 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 /* The final loop should be small enough. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
985 if (tree_num_loop_insns (loop, &eni_size_weights) * factor
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
986 > (unsigned) param_max_unrolled_insns)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
987 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
992 /* Determines the conditions that control execution of LOOP unrolled FACTOR
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
993 times. DESC is number of iterations of LOOP. ENTER_COND is set to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 condition that must be true if the main loop can be entered.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995 EXIT_BASE, EXIT_STEP, EXIT_CMP and EXIT_BOUND are set to values describing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 how the exit from the unrolled loop should be controlled. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 static void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
999 determine_exit_conditions (class loop *loop, class tree_niter_desc *desc,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 unsigned factor, tree *enter_cond,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001 tree *exit_base, tree *exit_step,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 enum tree_code *exit_cmp, tree *exit_bound)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 gimple_seq stmts;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005 tree base = desc->control.base;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 tree step = desc->control.step;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1007 tree bound = desc->bound;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1008 tree type = TREE_TYPE (step);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1009 tree bigstep, delta;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010 tree min = lower_bound_in_type (type, type);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011 tree max = upper_bound_in_type (type, type);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012 enum tree_code cmp = desc->cmp;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013 tree cond = boolean_true_node, assum;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1014
111
kono
parents: 67
diff changeset
1015 /* For pointers, do the arithmetics in the type of step. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 base = fold_convert (type, base);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017 bound = fold_convert (type, bound);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1018
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019 *enter_cond = boolean_false_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020 *exit_base = NULL_TREE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1021 *exit_step = NULL_TREE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1022 *exit_cmp = ERROR_MARK;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023 *exit_bound = NULL_TREE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 gcc_assert (cmp != ERROR_MARK);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026 /* We only need to be correct when we answer question
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 "Do at least FACTOR more iterations remain?" in the unrolled loop.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028 Thus, transforming BASE + STEP * i <> BOUND to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029 BASE + STEP * i < BOUND is ok. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030 if (cmp == NE_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1031 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1032 if (tree_int_cst_sign_bit (step))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033 cmp = GT_EXPR;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1034 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 cmp = LT_EXPR;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 else if (cmp == LT_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 gcc_assert (!tree_int_cst_sign_bit (step));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041 else if (cmp == GT_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043 gcc_assert (tree_int_cst_sign_bit (step));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1044 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1045 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1046 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1047
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1048 /* The main body of the loop may be entered iff:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 1) desc->may_be_zero is false.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 2) it is possible to check that there are at least FACTOR iterations
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 of the loop, i.e., BOUND - step * FACTOR does not overflow.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 3) # of iterations is at least FACTOR */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055 if (!integer_zerop (desc->may_be_zero))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056 cond = fold_build2 (TRUTH_AND_EXPR, boolean_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 invert_truthvalue (desc->may_be_zero),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 cond);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060 bigstep = fold_build2 (MULT_EXPR, type, step,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 build_int_cst_type (type, factor));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 delta = fold_build2 (MINUS_EXPR, type, bigstep, step);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1063 if (cmp == LT_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064 assum = fold_build2 (GE_EXPR, boolean_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 bound,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 fold_build2 (PLUS_EXPR, type, min, delta));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1068 assum = fold_build2 (LE_EXPR, boolean_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1069 bound,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070 fold_build2 (PLUS_EXPR, type, max, delta));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1071 cond = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, assum, cond);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1072
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073 bound = fold_build2 (MINUS_EXPR, type, bound, delta);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074 assum = fold_build2 (cmp, boolean_type_node, base, bound);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075 cond = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, assum, cond);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1077 cond = force_gimple_operand (unshare_expr (cond), &stmts, false, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078 if (stmts)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1079 gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080 /* cond now may be a gimple comparison, which would be OK, but also any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1081 other gimple rhs (say a && b). In this case we need to force it to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1082 operand. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083 if (!is_gimple_condexpr (cond))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085 cond = force_gimple_operand (cond, &stmts, true, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1086 if (stmts)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087 gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089 *enter_cond = cond;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1090
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091 base = force_gimple_operand (unshare_expr (base), &stmts, true, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092 if (stmts)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093 gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094 bound = force_gimple_operand (unshare_expr (bound), &stmts, true, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1095 if (stmts)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1096 gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 *exit_base = base;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1099 *exit_step = bigstep;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100 *exit_cmp = cmp;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1101 *exit_bound = bound;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1103
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1104 /* Scales the frequencies of all basic blocks in LOOP that are strictly
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 dominated by BB by NUM/DEN. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107 static void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1108 scale_dominated_blocks_in_loop (class loop *loop, basic_block bb,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1109 profile_count num, profile_count den)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111 basic_block son;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1113 if (!den.nonzero_p () && !(num == profile_count::zero ()))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1114 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1116 for (son = first_dom_son (CDI_DOMINATORS, bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1117 son;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1118 son = next_dom_son (CDI_DOMINATORS, son))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1120 if (!flow_bb_inside_loop_p (loop, son))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1121 continue;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1122 scale_bbs_frequencies_profile_count (&son, 1, num, den);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1123 scale_dominated_blocks_in_loop (loop, son, num, den);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1124 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1125 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1126
111
kono
parents: 67
diff changeset
1127 /* Return estimated niter for LOOP after unrolling by FACTOR times. */
kono
parents: 67
diff changeset
1128
kono
parents: 67
diff changeset
1129 gcov_type
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1130 niter_for_unrolled_loop (class loop *loop, unsigned factor)
111
kono
parents: 67
diff changeset
1131 {
kono
parents: 67
diff changeset
1132 gcc_assert (factor != 0);
kono
parents: 67
diff changeset
1133 bool profile_p = false;
kono
parents: 67
diff changeset
1134 gcov_type est_niter = expected_loop_iterations_unbounded (loop, &profile_p);
kono
parents: 67
diff changeset
1135 /* Note that this is really CEIL (est_niter + 1, factor) - 1, where the
kono
parents: 67
diff changeset
1136 "+ 1" converts latch iterations to loop iterations and the "- 1"
kono
parents: 67
diff changeset
1137 converts back. */
kono
parents: 67
diff changeset
1138 gcov_type new_est_niter = est_niter / factor;
kono
parents: 67
diff changeset
1139
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1140 if (est_niter == -1)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1141 return -1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1142
111
kono
parents: 67
diff changeset
1143 /* Without profile feedback, loops for which we do not know a better estimate
kono
parents: 67
diff changeset
1144 are assumed to roll 10 times. When we unroll such loop, it appears to
kono
parents: 67
diff changeset
1145 roll too little, and it may even seem to be cold. To avoid this, we
kono
parents: 67
diff changeset
1146 ensure that the created loop appears to roll at least 5 times (but at
kono
parents: 67
diff changeset
1147 most as many times as before unrolling). Don't do adjustment if profile
kono
parents: 67
diff changeset
1148 feedback is present. */
kono
parents: 67
diff changeset
1149 if (new_est_niter < 5 && !profile_p)
kono
parents: 67
diff changeset
1150 {
kono
parents: 67
diff changeset
1151 if (est_niter < 5)
kono
parents: 67
diff changeset
1152 new_est_niter = est_niter;
kono
parents: 67
diff changeset
1153 else
kono
parents: 67
diff changeset
1154 new_est_niter = 5;
kono
parents: 67
diff changeset
1155 }
kono
parents: 67
diff changeset
1156
kono
parents: 67
diff changeset
1157 if (loop->any_upper_bound)
kono
parents: 67
diff changeset
1158 {
kono
parents: 67
diff changeset
1159 /* As above, this is really CEIL (upper_bound + 1, factor) - 1. */
kono
parents: 67
diff changeset
1160 widest_int bound = wi::udiv_floor (loop->nb_iterations_upper_bound,
kono
parents: 67
diff changeset
1161 factor);
kono
parents: 67
diff changeset
1162 if (wi::ltu_p (bound, new_est_niter))
kono
parents: 67
diff changeset
1163 new_est_niter = bound.to_uhwi ();
kono
parents: 67
diff changeset
1164 }
kono
parents: 67
diff changeset
1165
kono
parents: 67
diff changeset
1166 return new_est_niter;
kono
parents: 67
diff changeset
1167 }
kono
parents: 67
diff changeset
1168
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169 /* Unroll LOOP FACTOR times. DESC describes number of iterations of LOOP.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 EXIT is the exit of the loop to that DESC corresponds.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 If N is number of iterations of the loop and MAY_BE_ZERO is the condition
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173 under that loop exits in the first iteration even if N != 0,
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1174
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 x = phi (init, next);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179 pre;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 if (st)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182 post;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1183 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1185 becomes (with possibly the exit conditions formulated a bit differently,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 avoiding the need to create a new iv):
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1187
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 if (MAY_BE_ZERO || N < FACTOR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 goto rest;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191 do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 x = phi (init, next);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195 pre;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 post;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 pre;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198 post;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 ...
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200 pre;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 post;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202 N -= FACTOR;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1203
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204 } while (N >= FACTOR);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 rest:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207 init' = phi (init, x);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 x = phi (init', next);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213 pre;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1214 if (st)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1215 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216 post;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1217 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1218
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219 Before the loop is unrolled, TRANSFORM is called for it (only for the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220 unrolled loop, but not for its versioned copy). DATA is passed to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1221 TRANSFORM. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1222
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1223 /* Probability in % that the unrolled loop is entered. Just a guess. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1224 #define PROB_UNROLLED_LOOP_ENTERED 90
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226 void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1227 tree_transform_and_unroll_loop (class loop *loop, unsigned factor,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1228 edge exit, class tree_niter_desc *desc,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1229 transform_callback transform,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1230 void *data)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1231 {
111
kono
parents: 67
diff changeset
1232 gcond *exit_if;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233 tree ctr_before, ctr_after;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1234 tree enter_main_cond, exit_base, exit_step, exit_bound;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1235 enum tree_code exit_cmp;
111
kono
parents: 67
diff changeset
1236 gphi *phi_old_loop, *phi_new_loop, *phi_rest;
kono
parents: 67
diff changeset
1237 gphi_iterator psi_old_loop, psi_new_loop;
kono
parents: 67
diff changeset
1238 tree init, next, new_init;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1239 class loop *new_loop;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1240 basic_block rest, exit_bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1241 edge old_entry, new_entry, old_latch, precond_edge, new_exit;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1242 edge new_nonexit, e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1243 gimple_stmt_iterator bsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1244 use_operand_p op;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245 bool ok;
111
kono
parents: 67
diff changeset
1246 unsigned i;
kono
parents: 67
diff changeset
1247 profile_probability prob, prob_entry, scale_unrolled;
kono
parents: 67
diff changeset
1248 profile_count freq_e, freq_h;
kono
parents: 67
diff changeset
1249 gcov_type new_est_niter = niter_for_unrolled_loop (loop, factor);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1250 unsigned irr = loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP;
111
kono
parents: 67
diff changeset
1251 auto_vec<edge> to_remove;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1252
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1253 determine_exit_conditions (loop, desc, factor,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1254 &enter_main_cond, &exit_base, &exit_step,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1255 &exit_cmp, &exit_bound);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1256
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1257 /* Let us assume that the unrolled loop is quite likely to be entered. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1258 if (integer_nonzerop (enter_main_cond))
111
kono
parents: 67
diff changeset
1259 prob_entry = profile_probability::always ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1260 else
111
kono
parents: 67
diff changeset
1261 prob_entry = profile_probability::guessed_always ()
kono
parents: 67
diff changeset
1262 .apply_scale (PROB_UNROLLED_LOOP_ENTERED, 100);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1263
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 /* The values for scales should keep profile consistent, and somewhat close
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265 to correct.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267 TODO: The current value of SCALE_REST makes it appear that the loop that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1268 is created by splitting the remaining iterations of the unrolled loop is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1269 executed the same number of times as the original loop, and with the same
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 frequencies, which is obviously wrong. This does not appear to cause
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1271 problems, so we do not bother with fixing it for now. To make the profile
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1272 correct, we would need to change the probability of the exit edge of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273 loop, and recompute the distribution of frequencies in its body because
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274 of this change (scale the frequencies of blocks before and after the exit
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1275 by appropriate factors). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1276 scale_unrolled = prob_entry;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1277
111
kono
parents: 67
diff changeset
1278 new_loop = loop_version (loop, enter_main_cond, NULL, prob_entry,
kono
parents: 67
diff changeset
1279 prob_entry.invert (), scale_unrolled,
kono
parents: 67
diff changeset
1280 profile_probability::guessed_always (),
kono
parents: 67
diff changeset
1281 true);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282 gcc_assert (new_loop != NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283 update_ssa (TODO_update_ssa);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1285 /* Prepare the cfg and update the phi nodes. Move the loop exit to the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 loop latch (and make its condition dummy, for the moment). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287 rest = loop_preheader_edge (new_loop)->src;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 precond_edge = single_pred_edge (rest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 split_edge (loop_latch_edge (loop));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 exit_bb = single_pred (loop->latch);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1291
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1292 /* Since the exit edge will be removed, the frequency of all the blocks
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293 in the loop that are dominated by it must be scaled by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1294 1 / (1 - exit->probability). */
111
kono
parents: 67
diff changeset
1295 if (exit->probability.initialized_p ())
kono
parents: 67
diff changeset
1296 scale_dominated_blocks_in_loop (loop, exit->src,
kono
parents: 67
diff changeset
1297 /* We are scaling up here so probability
kono
parents: 67
diff changeset
1298 does not fit. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1299 loop->header->count,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1300 loop->header->count
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1301 - loop->header->count.apply_probability
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1302 (exit->probability));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304 bsi = gsi_last_bb (exit_bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1305 exit_if = gimple_build_cond (EQ_EXPR, integer_zero_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 integer_zero_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307 NULL_TREE, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1309 gsi_insert_after (&bsi, exit_if, GSI_NEW_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310 new_exit = make_edge (exit_bb, rest, EDGE_FALSE_VALUE | irr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311 rescan_loop_exit (new_exit, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1312
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313 /* Set the probability of new exit to the same of the old one. Fix
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314 the frequency of the latch block, by scaling it back by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1315 1 - exit->probability. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1316 new_exit->probability = exit->probability;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1317 new_nonexit = single_pred_edge (loop->latch);
111
kono
parents: 67
diff changeset
1318 new_nonexit->probability = exit->probability.invert ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1319 new_nonexit->flags = EDGE_TRUE_VALUE;
111
kono
parents: 67
diff changeset
1320 if (new_nonexit->probability.initialized_p ())
kono
parents: 67
diff changeset
1321 scale_bbs_frequencies (&loop->latch, 1, new_nonexit->probability);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1322
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1323 old_entry = loop_preheader_edge (loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1324 new_entry = loop_preheader_edge (new_loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1325 old_latch = loop_latch_edge (loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326 for (psi_old_loop = gsi_start_phis (loop->header),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 psi_new_loop = gsi_start_phis (new_loop->header);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 !gsi_end_p (psi_old_loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329 gsi_next (&psi_old_loop), gsi_next (&psi_new_loop))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330 {
111
kono
parents: 67
diff changeset
1331 phi_old_loop = psi_old_loop.phi ();
kono
parents: 67
diff changeset
1332 phi_new_loop = psi_new_loop.phi ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1333
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1334 init = PHI_ARG_DEF_FROM_EDGE (phi_old_loop, old_entry);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1335 op = PHI_ARG_DEF_PTR_FROM_EDGE (phi_new_loop, new_entry);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1336 gcc_assert (operand_equal_for_phi_arg_p (init, USE_FROM_PTR (op)));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1337 next = PHI_ARG_DEF_FROM_EDGE (phi_old_loop, old_latch);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1338
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1339 /* Prefer using original variable as a base for the new ssa name.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1340 This is necessary for virtual ops, and useful in order to avoid
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 losing debug info for real ops. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1342 if (TREE_CODE (next) == SSA_NAME
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1343 && useless_type_conversion_p (TREE_TYPE (next),
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1344 TREE_TYPE (init)))
111
kono
parents: 67
diff changeset
1345 new_init = copy_ssa_name (next);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1346 else if (TREE_CODE (init) == SSA_NAME
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1347 && useless_type_conversion_p (TREE_TYPE (init),
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1348 TREE_TYPE (next)))
111
kono
parents: 67
diff changeset
1349 new_init = copy_ssa_name (init);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1350 else if (useless_type_conversion_p (TREE_TYPE (next), TREE_TYPE (init)))
111
kono
parents: 67
diff changeset
1351 new_init = make_temp_ssa_name (TREE_TYPE (next), NULL, "unrinittmp");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1352 else
111
kono
parents: 67
diff changeset
1353 new_init = make_temp_ssa_name (TREE_TYPE (init), NULL, "unrinittmp");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1354
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1355 phi_rest = create_phi_node (new_init, rest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1356
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1357 add_phi_arg (phi_rest, init, precond_edge, UNKNOWN_LOCATION);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1358 add_phi_arg (phi_rest, next, new_exit, UNKNOWN_LOCATION);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359 SET_USE (op, new_init);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1360 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 remove_path (exit);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1364 /* Transform the loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365 if (transform)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1366 (*transform) (loop, data);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1367
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1368 /* Unroll the loop and remove the exits in all iterations except for the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1369 last one. */
111
kono
parents: 67
diff changeset
1370 auto_sbitmap wont_exit (factor);
kono
parents: 67
diff changeset
1371 bitmap_ones (wont_exit);
kono
parents: 67
diff changeset
1372 bitmap_clear_bit (wont_exit, factor - 1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1373
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1374 ok = gimple_duplicate_loop_to_header_edge
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1375 (loop, loop_latch_edge (loop), factor - 1,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1376 wont_exit, new_exit, &to_remove, DLTHE_FLAG_UPDATE_FREQ);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1377 gcc_assert (ok);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1378
111
kono
parents: 67
diff changeset
1379 FOR_EACH_VEC_ELT (to_remove, i, e)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1380 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1381 ok = remove_path (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1382 gcc_assert (ok);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1383 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1384 update_ssa (TODO_update_ssa);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1385
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1386 /* Ensure that the frequencies in the loop match the new estimated
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1387 number of iterations, and change the probability of the new
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1388 exit edge. */
111
kono
parents: 67
diff changeset
1389
kono
parents: 67
diff changeset
1390 freq_h = loop->header->count;
kono
parents: 67
diff changeset
1391 freq_e = (loop_preheader_edge (loop))->count ();
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1392 if (freq_h.nonzero_p ())
111
kono
parents: 67
diff changeset
1393 {
kono
parents: 67
diff changeset
1394 /* Avoid dropping loop body profile counter to 0 because of zero count
kono
parents: 67
diff changeset
1395 in loop's preheader. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1396 if (freq_h.nonzero_p () && !(freq_e == profile_count::zero ()))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1397 freq_e = freq_e.force_nonzero ();
111
kono
parents: 67
diff changeset
1398 scale_loop_frequencies (loop, freq_e.probability_in (freq_h));
kono
parents: 67
diff changeset
1399 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1400
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1401 exit_bb = single_pred (loop->latch);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1402 new_exit = find_edge (exit_bb, rest);
111
kono
parents: 67
diff changeset
1403 new_exit->probability = profile_probability::always ()
kono
parents: 67
diff changeset
1404 .apply_scale (1, new_est_niter + 1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1405
111
kono
parents: 67
diff changeset
1406 rest->count += new_exit->count ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1407
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1408 new_nonexit = single_pred_edge (loop->latch);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1409 prob = new_nonexit->probability;
111
kono
parents: 67
diff changeset
1410 new_nonexit->probability = new_exit->probability.invert ();
kono
parents: 67
diff changeset
1411 prob = new_nonexit->probability / prob;
kono
parents: 67
diff changeset
1412 if (prob.initialized_p ())
kono
parents: 67
diff changeset
1413 scale_bbs_frequencies (&loop->latch, 1, prob);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1414
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1415 /* Finally create the new counter for number of iterations and add the new
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1416 exit instruction. */
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
1417 bsi = gsi_last_nondebug_bb (exit_bb);
111
kono
parents: 67
diff changeset
1418 exit_if = as_a <gcond *> (gsi_stmt (bsi));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419 create_iv (exit_base, exit_step, NULL_TREE, loop,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1420 &bsi, false, &ctr_before, &ctr_after);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1421 gimple_cond_set_code (exit_if, exit_cmp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1422 gimple_cond_set_lhs (exit_if, ctr_after);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1423 gimple_cond_set_rhs (exit_if, exit_bound);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1424 update_stmt (exit_if);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1425
111
kono
parents: 67
diff changeset
1426 checking_verify_flow_info ();
kono
parents: 67
diff changeset
1427 checking_verify_loop_structure ();
kono
parents: 67
diff changeset
1428 checking_verify_loop_closed_ssa (true, loop);
kono
parents: 67
diff changeset
1429 checking_verify_loop_closed_ssa (true, new_loop);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1430 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1431
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1432 /* Wrapper over tree_transform_and_unroll_loop for case we do not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1433 want to transform the loop before unrolling. The meaning
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1434 of the arguments is the same as for tree_transform_and_unroll_loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1435
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1436 void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1437 tree_unroll_loop (class loop *loop, unsigned factor,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1438 edge exit, class tree_niter_desc *desc)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1439 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1440 tree_transform_and_unroll_loop (loop, factor, exit, desc,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1441 NULL, NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1442 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1443
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1444 /* Rewrite the phi node at position PSI in function of the main
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1445 induction variable MAIN_IV and insert the generated code at GSI. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1446
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1447 static void
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1448 rewrite_phi_with_iv (loop_p loop,
111
kono
parents: 67
diff changeset
1449 gphi_iterator *psi,
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1450 gimple_stmt_iterator *gsi,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1451 tree main_iv)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1452 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1453 affine_iv iv;
111
kono
parents: 67
diff changeset
1454 gassign *stmt;
kono
parents: 67
diff changeset
1455 gphi *phi = psi->phi ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1456 tree atype, mtype, val, res = PHI_RESULT (phi);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1457
111
kono
parents: 67
diff changeset
1458 if (virtual_operand_p (res) || res == main_iv)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1459 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1460 gsi_next (psi);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1461 return;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1462 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1463
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1464 if (!simple_iv (loop, loop, res, &iv, true))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1465 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1466 gsi_next (psi);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1467 return;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1468 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1469
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1470 remove_phi_node (psi, false);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1471
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1472 atype = TREE_TYPE (res);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1473 mtype = POINTER_TYPE_P (atype) ? sizetype : atype;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1474 val = fold_build2 (MULT_EXPR, mtype, unshare_expr (iv.step),
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1475 fold_convert (mtype, main_iv));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1476 val = fold_build2 (POINTER_TYPE_P (atype)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1477 ? POINTER_PLUS_EXPR : PLUS_EXPR,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1478 atype, unshare_expr (iv.base), val);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1479 val = force_gimple_operand_gsi (gsi, val, false, NULL_TREE, true,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1480 GSI_SAME_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1481 stmt = gimple_build_assign (res, val);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1482 gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1483 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1484
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1485 /* Rewrite all the phi nodes of LOOP in function of the main induction
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1486 variable MAIN_IV. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1487
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1488 static void
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1489 rewrite_all_phi_nodes_with_iv (loop_p loop, tree main_iv)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1490 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1491 unsigned i;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1492 basic_block *bbs = get_loop_body_in_dom_order (loop);
111
kono
parents: 67
diff changeset
1493 gphi_iterator psi;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1494
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1495 for (i = 0; i < loop->num_nodes; i++)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1496 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1497 basic_block bb = bbs[i];
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1498 gimple_stmt_iterator gsi = gsi_after_labels (bb);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1499
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1500 if (bb->loop_father != loop)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1501 continue;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1502
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1503 for (psi = gsi_start_phis (bb); !gsi_end_p (psi); )
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1504 rewrite_phi_with_iv (loop, &psi, &gsi, main_iv);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1505 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1506
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1507 free (bbs);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1508 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1509
111
kono
parents: 67
diff changeset
1510 /* Bases all the induction variables in LOOP on a single induction variable
kono
parents: 67
diff changeset
1511 (with base 0 and step 1), whose final value is compared with *NIT. When the
kono
parents: 67
diff changeset
1512 IV type precision has to be larger than *NIT type precision, *NIT is
kono
parents: 67
diff changeset
1513 converted to the larger type, the conversion code is inserted before the
kono
parents: 67
diff changeset
1514 loop, and *NIT is updated to the new definition. When BUMP_IN_LATCH is true,
kono
parents: 67
diff changeset
1515 the induction variable is incremented in the loop latch, otherwise it is
kono
parents: 67
diff changeset
1516 incremented in the loop header. Return the induction variable that was
kono
parents: 67
diff changeset
1517 created. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1518
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1519 tree
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1520 canonicalize_loop_ivs (class loop *loop, tree *nit, bool bump_in_latch)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1521 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1522 unsigned precision = TYPE_PRECISION (TREE_TYPE (*nit));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1523 unsigned original_precision = precision;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1524 tree type, var_before;
111
kono
parents: 67
diff changeset
1525 gimple_stmt_iterator gsi;
kono
parents: 67
diff changeset
1526 gphi_iterator psi;
kono
parents: 67
diff changeset
1527 gcond *stmt;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1528 edge exit = single_dom_exit (loop);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1529 gimple_seq stmts;
111
kono
parents: 67
diff changeset
1530 bool unsigned_p = false;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1531
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1532 for (psi = gsi_start_phis (loop->header);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1533 !gsi_end_p (psi); gsi_next (&psi))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1534 {
111
kono
parents: 67
diff changeset
1535 gphi *phi = psi.phi ();
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1536 tree res = PHI_RESULT (phi);
111
kono
parents: 67
diff changeset
1537 bool uns;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1538
111
kono
parents: 67
diff changeset
1539 type = TREE_TYPE (res);
kono
parents: 67
diff changeset
1540 if (virtual_operand_p (res)
kono
parents: 67
diff changeset
1541 || (!INTEGRAL_TYPE_P (type)
kono
parents: 67
diff changeset
1542 && !POINTER_TYPE_P (type))
kono
parents: 67
diff changeset
1543 || TYPE_PRECISION (type) < precision)
kono
parents: 67
diff changeset
1544 continue;
kono
parents: 67
diff changeset
1545
kono
parents: 67
diff changeset
1546 uns = POINTER_TYPE_P (type) | TYPE_UNSIGNED (type);
kono
parents: 67
diff changeset
1547
kono
parents: 67
diff changeset
1548 if (TYPE_PRECISION (type) > precision)
kono
parents: 67
diff changeset
1549 unsigned_p = uns;
kono
parents: 67
diff changeset
1550 else
kono
parents: 67
diff changeset
1551 unsigned_p |= uns;
kono
parents: 67
diff changeset
1552
kono
parents: 67
diff changeset
1553 precision = TYPE_PRECISION (type);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1554 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1555
111
kono
parents: 67
diff changeset
1556 scalar_int_mode mode = smallest_int_mode_for_size (precision);
kono
parents: 67
diff changeset
1557 precision = GET_MODE_PRECISION (mode);
kono
parents: 67
diff changeset
1558 type = build_nonstandard_integer_type (precision, unsigned_p);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1559
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1560 if (original_precision != precision
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1561 || TYPE_UNSIGNED (TREE_TYPE (*nit)) != unsigned_p)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1562 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1563 *nit = fold_convert (type, *nit);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1564 *nit = force_gimple_operand (*nit, &stmts, true, NULL_TREE);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1565 if (stmts)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1566 gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1567 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1568
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
1569 if (bump_in_latch)
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
1570 gsi = gsi_last_bb (loop->latch);
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
1571 else
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
1572 gsi = gsi_last_nondebug_bb (loop->header);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1573 create_iv (build_int_cst_type (type, 0), build_int_cst (type, 1), NULL_TREE,
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1574 loop, &gsi, bump_in_latch, &var_before, NULL);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1575
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1576 rewrite_all_phi_nodes_with_iv (loop, var_before);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1577
111
kono
parents: 67
diff changeset
1578 stmt = as_a <gcond *> (last_stmt (exit->src));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1579 /* Make the loop exit if the control condition is not satisfied. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1580 if (exit->flags & EDGE_TRUE_VALUE)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1581 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1582 edge te, fe;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1583
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1584 extract_true_false_edges_from_block (exit->src, &te, &fe);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1585 te->flags = EDGE_FALSE_VALUE;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1586 fe->flags = EDGE_TRUE_VALUE;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1587 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1588 gimple_cond_set_code (stmt, LT_EXPR);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1589 gimple_cond_set_lhs (stmt, var_before);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1590 gimple_cond_set_rhs (stmt, *nit);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1591 update_stmt (stmt);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1592
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1593 return var_before;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1594 }