annotate gcc/tree-ssa-loop-manip.c @ 128:fe568345ddd5

fix CbC-example
author mir3636
date Wed, 11 Apr 2018 19:32:28 +0900
parents 04ced10e8804
children 84e7813d76e9
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.
111
kono
parents: 67
diff changeset
2 Copyright (C) 2004-2017 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,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094 int num, int den)
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1098 if (den == 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;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107 scale_bbs_frequencies_int (&son, 1, num, den);
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
kono
parents: 67
diff changeset
1125 /* Without profile feedback, loops for which we do not know a better estimate
kono
parents: 67
diff changeset
1126 are assumed to roll 10 times. When we unroll such loop, it appears to
kono
parents: 67
diff changeset
1127 roll too little, and it may even seem to be cold. To avoid this, we
kono
parents: 67
diff changeset
1128 ensure that the created loop appears to roll at least 5 times (but at
kono
parents: 67
diff changeset
1129 most as many times as before unrolling). Don't do adjustment if profile
kono
parents: 67
diff changeset
1130 feedback is present. */
kono
parents: 67
diff changeset
1131 if (new_est_niter < 5 && !profile_p)
kono
parents: 67
diff changeset
1132 {
kono
parents: 67
diff changeset
1133 if (est_niter < 5)
kono
parents: 67
diff changeset
1134 new_est_niter = est_niter;
kono
parents: 67
diff changeset
1135 else
kono
parents: 67
diff changeset
1136 new_est_niter = 5;
kono
parents: 67
diff changeset
1137 }
kono
parents: 67
diff changeset
1138
kono
parents: 67
diff changeset
1139 if (loop->any_upper_bound)
kono
parents: 67
diff changeset
1140 {
kono
parents: 67
diff changeset
1141 /* As above, this is really CEIL (upper_bound + 1, factor) - 1. */
kono
parents: 67
diff changeset
1142 widest_int bound = wi::udiv_floor (loop->nb_iterations_upper_bound,
kono
parents: 67
diff changeset
1143 factor);
kono
parents: 67
diff changeset
1144 if (wi::ltu_p (bound, new_est_niter))
kono
parents: 67
diff changeset
1145 new_est_niter = bound.to_uhwi ();
kono
parents: 67
diff changeset
1146 }
kono
parents: 67
diff changeset
1147
kono
parents: 67
diff changeset
1148 return new_est_niter;
kono
parents: 67
diff changeset
1149 }
kono
parents: 67
diff changeset
1150
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1151 /* 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
1152 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
1153
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154 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
1155 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
1156
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 x = phi (init, next);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 pre;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 if (st)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 post;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 becomes (with possibly the exit conditions formulated a bit differently,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168 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
1169
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 if (MAY_BE_ZERO || N < FACTOR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171 goto rest;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173 do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 x = phi (init, next);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 pre;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1178 post;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179 pre;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 post;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 ...
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 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
1185
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 } while (N >= FACTOR);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 rest:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 init' = phi (init, x);
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 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 x = phi (init', next);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195 pre;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 if (st)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198 post;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1200
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 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
1202 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
1203 TRANSFORM. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205 /* 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
1206 #define PROB_UNROLLED_LOOP_ENTERED 90
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 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 tree_transform_and_unroll_loop (struct loop *loop, unsigned factor,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 edge exit, struct tree_niter_desc *desc,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 transform_callback transform,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 void *data)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213 {
111
kono
parents: 67
diff changeset
1214 gcond *exit_if;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1215 tree ctr_before, ctr_after;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216 tree enter_main_cond, exit_base, exit_step, exit_bound;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1217 enum tree_code exit_cmp;
111
kono
parents: 67
diff changeset
1218 gphi *phi_old_loop, *phi_new_loop, *phi_rest;
kono
parents: 67
diff changeset
1219 gphi_iterator psi_old_loop, psi_new_loop;
kono
parents: 67
diff changeset
1220 tree init, next, new_init;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1221 struct loop *new_loop;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1222 basic_block rest, exit_bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1223 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
1224 edge new_nonexit, e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 gimple_stmt_iterator bsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226 use_operand_p op;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227 bool ok;
111
kono
parents: 67
diff changeset
1228 unsigned i;
kono
parents: 67
diff changeset
1229 profile_probability prob, prob_entry, scale_unrolled;
kono
parents: 67
diff changeset
1230 profile_count freq_e, freq_h;
kono
parents: 67
diff changeset
1231 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
1232 unsigned irr = loop_preheader_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP;
111
kono
parents: 67
diff changeset
1233 auto_vec<edge> to_remove;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1234
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1235 determine_exit_conditions (loop, desc, factor,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1236 &enter_main_cond, &exit_base, &exit_step,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1237 &exit_cmp, &exit_bound);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239 /* 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
1240 if (integer_nonzerop (enter_main_cond))
111
kono
parents: 67
diff changeset
1241 prob_entry = profile_probability::always ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1242 else
111
kono
parents: 67
diff changeset
1243 prob_entry = profile_probability::guessed_always ()
kono
parents: 67
diff changeset
1244 .apply_scale (PROB_UNROLLED_LOOP_ENTERED, 100);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1246 /* 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
1247 to correct.
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 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
1250 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
1251 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
1252 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
1253 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
1254 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
1255 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
1256 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
1257 by appropriate factors). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1258 scale_unrolled = prob_entry;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1259
111
kono
parents: 67
diff changeset
1260 new_loop = loop_version (loop, enter_main_cond, NULL, prob_entry,
kono
parents: 67
diff changeset
1261 prob_entry.invert (), scale_unrolled,
kono
parents: 67
diff changeset
1262 profile_probability::guessed_always (),
kono
parents: 67
diff changeset
1263 true);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 gcc_assert (new_loop != NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265 update_ssa (TODO_update_ssa);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267 /* 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
1268 loop latch (and make its condition dummy, for the moment). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1269 rest = loop_preheader_edge (new_loop)->src;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 precond_edge = single_pred_edge (rest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1271 split_edge (loop_latch_edge (loop));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1272 exit_bb = single_pred (loop->latch);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274 /* 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
1275 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
1276 1 / (1 - exit->probability). */
111
kono
parents: 67
diff changeset
1277 if (exit->probability.initialized_p ())
kono
parents: 67
diff changeset
1278 scale_dominated_blocks_in_loop (loop, exit->src,
kono
parents: 67
diff changeset
1279 /* We are scaling up here so probability
kono
parents: 67
diff changeset
1280 does not fit. */
kono
parents: 67
diff changeset
1281 REG_BR_PROB_BASE,
kono
parents: 67
diff changeset
1282 REG_BR_PROB_BASE
kono
parents: 67
diff changeset
1283 - exit->probability.to_reg_br_prob_base ());
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1285 bsi = gsi_last_bb (exit_bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 exit_if = gimple_build_cond (EQ_EXPR, integer_zero_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287 integer_zero_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 NULL_TREE, NULL_TREE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 gsi_insert_after (&bsi, exit_if, GSI_NEW_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1291 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
1292 rescan_loop_exit (new_exit, true, false);
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 /* 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
1295 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
1296 1 - exit->probability. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1297 new_exit->probability = exit->probability;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1298 new_nonexit = single_pred_edge (loop->latch);
111
kono
parents: 67
diff changeset
1299 new_nonexit->probability = exit->probability.invert ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1300 new_nonexit->flags = EDGE_TRUE_VALUE;
111
kono
parents: 67
diff changeset
1301 if (new_nonexit->probability.initialized_p ())
kono
parents: 67
diff changeset
1302 scale_bbs_frequencies (&loop->latch, 1, new_nonexit->probability);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304 old_entry = loop_preheader_edge (loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1305 new_entry = loop_preheader_edge (new_loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 old_latch = loop_latch_edge (loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307 for (psi_old_loop = gsi_start_phis (loop->header),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308 psi_new_loop = gsi_start_phis (new_loop->header);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1309 !gsi_end_p (psi_old_loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310 gsi_next (&psi_old_loop), gsi_next (&psi_new_loop))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311 {
111
kono
parents: 67
diff changeset
1312 phi_old_loop = psi_old_loop.phi ();
kono
parents: 67
diff changeset
1313 phi_new_loop = psi_new_loop.phi ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1315 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
1316 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
1317 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
1318 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
1319
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1320 /* 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
1321 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
1322 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
1323 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
1324 && 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
1325 TREE_TYPE (init)))
111
kono
parents: 67
diff changeset
1326 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
1327 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
1328 && 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
1329 TREE_TYPE (next)))
111
kono
parents: 67
diff changeset
1330 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
1331 else if (useless_type_conversion_p (TREE_TYPE (next), TREE_TYPE (init)))
111
kono
parents: 67
diff changeset
1332 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
1333 else
111
kono
parents: 67
diff changeset
1334 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
1335
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1336 phi_rest = create_phi_node (new_init, rest);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1337
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1338 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
1339 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
1340 SET_USE (op, new_init);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1342
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1343 remove_path (exit);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1344
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1345 /* Transform the loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1346 if (transform)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1347 (*transform) (loop, data);
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 /* 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
1350 last one. */
111
kono
parents: 67
diff changeset
1351 auto_sbitmap wont_exit (factor);
kono
parents: 67
diff changeset
1352 bitmap_ones (wont_exit);
kono
parents: 67
diff changeset
1353 bitmap_clear_bit (wont_exit, factor - 1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1354
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1355 ok = gimple_duplicate_loop_to_header_edge
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1356 (loop, loop_latch_edge (loop), factor - 1,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1357 wont_exit, new_exit, &to_remove, DLTHE_FLAG_UPDATE_FREQ);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1358 gcc_assert (ok);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359
111
kono
parents: 67
diff changeset
1360 FOR_EACH_VEC_ELT (to_remove, i, e)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 ok = remove_path (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363 gcc_assert (ok);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1364 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365 update_ssa (TODO_update_ssa);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1366
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1367 /* 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
1368 number of iterations, and change the probability of the new
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1369 exit edge. */
111
kono
parents: 67
diff changeset
1370
kono
parents: 67
diff changeset
1371 freq_h = loop->header->count;
kono
parents: 67
diff changeset
1372 freq_e = (loop_preheader_edge (loop))->count ();
kono
parents: 67
diff changeset
1373 /* Use frequency only if counts are zero. */
kono
parents: 67
diff changeset
1374 if (!(freq_h > 0) && !(freq_e > 0))
kono
parents: 67
diff changeset
1375 {
kono
parents: 67
diff changeset
1376 freq_h = profile_count::from_gcov_type (loop->header->frequency);
kono
parents: 67
diff changeset
1377 freq_e = profile_count::from_gcov_type
kono
parents: 67
diff changeset
1378 (EDGE_FREQUENCY (loop_preheader_edge (loop)));
kono
parents: 67
diff changeset
1379 }
kono
parents: 67
diff changeset
1380 if (freq_h > 0)
kono
parents: 67
diff changeset
1381 {
kono
parents: 67
diff changeset
1382 /* Avoid dropping loop body profile counter to 0 because of zero count
kono
parents: 67
diff changeset
1383 in loop's preheader. */
kono
parents: 67
diff changeset
1384 if (freq_e == profile_count::zero ())
kono
parents: 67
diff changeset
1385 freq_e = profile_count::from_gcov_type (1);
kono
parents: 67
diff changeset
1386 scale_loop_frequencies (loop, freq_e.probability_in (freq_h));
kono
parents: 67
diff changeset
1387 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1388
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1389 exit_bb = single_pred (loop->latch);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1390 new_exit = find_edge (exit_bb, rest);
111
kono
parents: 67
diff changeset
1391 new_exit->probability = profile_probability::always ()
kono
parents: 67
diff changeset
1392 .apply_scale (1, new_est_niter + 1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1393
111
kono
parents: 67
diff changeset
1394 rest->count += new_exit->count ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1395 rest->frequency += EDGE_FREQUENCY (new_exit);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1396
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1397 new_nonexit = single_pred_edge (loop->latch);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1398 prob = new_nonexit->probability;
111
kono
parents: 67
diff changeset
1399 new_nonexit->probability = new_exit->probability.invert ();
kono
parents: 67
diff changeset
1400 prob = new_nonexit->probability / prob;
kono
parents: 67
diff changeset
1401 if (prob.initialized_p ())
kono
parents: 67
diff changeset
1402 scale_bbs_frequencies (&loop->latch, 1, prob);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1403
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1404 /* 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
1405 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
1406 bsi = gsi_last_nondebug_bb (exit_bb);
111
kono
parents: 67
diff changeset
1407 exit_if = as_a <gcond *> (gsi_stmt (bsi));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1408 create_iv (exit_base, exit_step, NULL_TREE, loop,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1409 &bsi, false, &ctr_before, &ctr_after);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1410 gimple_cond_set_code (exit_if, exit_cmp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1411 gimple_cond_set_lhs (exit_if, ctr_after);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1412 gimple_cond_set_rhs (exit_if, exit_bound);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1413 update_stmt (exit_if);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1414
111
kono
parents: 67
diff changeset
1415 checking_verify_flow_info ();
kono
parents: 67
diff changeset
1416 checking_verify_loop_structure ();
kono
parents: 67
diff changeset
1417 checking_verify_loop_closed_ssa (true, loop);
kono
parents: 67
diff changeset
1418 checking_verify_loop_closed_ssa (true, new_loop);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419 }
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 /* 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
1422 want to transform the loop before unrolling. The meaning
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1423 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
1424
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1425 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1426 tree_unroll_loop (struct loop *loop, unsigned factor,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1427 edge exit, struct tree_niter_desc *desc)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1428 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1429 tree_transform_and_unroll_loop (loop, factor, exit, desc,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1430 NULL, NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1431 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1432
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1433 /* 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
1434 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
1435
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1436 static void
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1437 rewrite_phi_with_iv (loop_p loop,
111
kono
parents: 67
diff changeset
1438 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
1439 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
1440 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
1441 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1442 affine_iv iv;
111
kono
parents: 67
diff changeset
1443 gassign *stmt;
kono
parents: 67
diff changeset
1444 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
1445 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
1446
111
kono
parents: 67
diff changeset
1447 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
1448 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1449 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
1450 return;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1451 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1452
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1453 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
1454 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1455 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
1456 return;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1457 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1458
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1459 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
1460
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1461 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
1462 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
1463 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
1464 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
1465 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
1466 ? 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
1467 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
1468 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
1469 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
1470 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
1471 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
1472 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1473
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 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
1475 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
1476
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1477 static void
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1478 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
1479 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1480 unsigned i;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1481 basic_block *bbs = get_loop_body_in_dom_order (loop);
111
kono
parents: 67
diff changeset
1482 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
1483
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1484 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
1485 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1486 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
1487 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
1488
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1489 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
1490 continue;
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 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
1493 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
1494 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1495
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1496 free (bbs);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1497 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1498
111
kono
parents: 67
diff changeset
1499 /* Bases all the induction variables in LOOP on a single induction variable
kono
parents: 67
diff changeset
1500 (with base 0 and step 1), whose final value is compared with *NIT. When the
kono
parents: 67
diff changeset
1501 IV type precision has to be larger than *NIT type precision, *NIT is
kono
parents: 67
diff changeset
1502 converted to the larger type, the conversion code is inserted before the
kono
parents: 67
diff changeset
1503 loop, and *NIT is updated to the new definition. When BUMP_IN_LATCH is true,
kono
parents: 67
diff changeset
1504 the induction variable is incremented in the loop latch, otherwise it is
kono
parents: 67
diff changeset
1505 incremented in the loop header. Return the induction variable that was
kono
parents: 67
diff changeset
1506 created. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1507
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1508 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
1509 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
1510 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1511 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
1512 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
1513 tree type, var_before;
111
kono
parents: 67
diff changeset
1514 gimple_stmt_iterator gsi;
kono
parents: 67
diff changeset
1515 gphi_iterator psi;
kono
parents: 67
diff changeset
1516 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
1517 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
1518 gimple_seq stmts;
111
kono
parents: 67
diff changeset
1519 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
1520
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1521 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
1522 !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
1523 {
111
kono
parents: 67
diff changeset
1524 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
1525 tree res = PHI_RESULT (phi);
111
kono
parents: 67
diff changeset
1526 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
1527
111
kono
parents: 67
diff changeset
1528 type = TREE_TYPE (res);
kono
parents: 67
diff changeset
1529 if (virtual_operand_p (res)
kono
parents: 67
diff changeset
1530 || (!INTEGRAL_TYPE_P (type)
kono
parents: 67
diff changeset
1531 && !POINTER_TYPE_P (type))
kono
parents: 67
diff changeset
1532 || TYPE_PRECISION (type) < precision)
kono
parents: 67
diff changeset
1533 continue;
kono
parents: 67
diff changeset
1534
kono
parents: 67
diff changeset
1535 uns = POINTER_TYPE_P (type) | TYPE_UNSIGNED (type);
kono
parents: 67
diff changeset
1536
kono
parents: 67
diff changeset
1537 if (TYPE_PRECISION (type) > precision)
kono
parents: 67
diff changeset
1538 unsigned_p = uns;
kono
parents: 67
diff changeset
1539 else
kono
parents: 67
diff changeset
1540 unsigned_p |= uns;
kono
parents: 67
diff changeset
1541
kono
parents: 67
diff changeset
1542 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
1543 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1544
111
kono
parents: 67
diff changeset
1545 scalar_int_mode mode = smallest_int_mode_for_size (precision);
kono
parents: 67
diff changeset
1546 precision = GET_MODE_PRECISION (mode);
kono
parents: 67
diff changeset
1547 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
1548
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1549 if (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
1550 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1551 *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
1552 *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
1553 if (stmts)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1554 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
1555 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1556
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
1557 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
1558 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
1559 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
1560 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
1561 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
1562 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
1563
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1564 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
1565
111
kono
parents: 67
diff changeset
1566 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
1567 /* 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
1568 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
1569 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1570 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
1571
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1572 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
1573 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
1574 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
1575 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1576 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
1577 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
1578 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
1579 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
1580
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1581 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
1582 }