annotate gcc/tree-ssa-loop-manip.c @ 132:d34655255c78

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