annotate gcc/tree-ssa-propagate.c @ 123:ab229f40eab2

fix inline_call
author mir3636
date Fri, 30 Mar 2018 22:58:55 +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 /* Generic SSA value propagation engine.
111
kono
parents: 67
diff changeset
2 Copyright (C) 2004-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Diego Novillo <dnovillo@redhat.com>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 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
8 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
9 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
10 later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 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
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 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
15 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 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
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #include "coretypes.h"
111
kono
parents: 67
diff changeset
24 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "tree.h"
111
kono
parents: 67
diff changeset
26 #include "gimple.h"
kono
parents: 67
diff changeset
27 #include "ssa.h"
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
28 #include "gimple-pretty-print.h"
111
kono
parents: 67
diff changeset
29 #include "dumpfile.h"
kono
parents: 67
diff changeset
30 #include "gimple-fold.h"
kono
parents: 67
diff changeset
31 #include "tree-eh.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 "tree-cfg.h"
kono
parents: 67
diff changeset
35 #include "tree-ssa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 #include "tree-ssa-propagate.h"
111
kono
parents: 67
diff changeset
37 #include "domwalk.h"
kono
parents: 67
diff changeset
38 #include "cfgloop.h"
kono
parents: 67
diff changeset
39 #include "tree-cfgcleanup.h"
kono
parents: 67
diff changeset
40 #include "cfganal.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 /* This file implements a generic value propagation engine based on
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 the same propagation used by the SSA-CCP algorithm [1].
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 Propagation is performed by simulating the execution of every
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 statement that produces the value being propagated. Simulation
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 proceeds as follows:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 1- Initially, all edges of the CFG are marked not executable and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 the CFG worklist is seeded with all the statements in the entry
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 basic block (block 0).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 2- Every statement S is simulated with a call to the call-back
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 function SSA_PROP_VISIT_STMT. This evaluation may produce 3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 results:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 SSA_PROP_NOT_INTERESTING: Statement S produces nothing of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 interest and does not affect any of the work lists.
111
kono
parents: 67
diff changeset
59 The statement may be simulated again if any of its input
kono
parents: 67
diff changeset
60 operands change in future iterations of the simulator.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 SSA_PROP_VARYING: The value produced by S cannot be determined
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 at compile time. Further simulation of S is not required.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 If S is a conditional jump, all the outgoing edges for the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 block are considered executable and added to the work
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 list.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 SSA_PROP_INTERESTING: S produces a value that can be computed
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 at compile time. Its result can be propagated into the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 statements that feed from S. Furthermore, if S is a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 conditional jump, only the edge known to be taken is added
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 to the work list. Edges that are known not to execute are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 never simulated.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 3- PHI nodes are simulated with a call to SSA_PROP_VISIT_PHI. The
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 return value from SSA_PROP_VISIT_PHI has the same semantics as
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 described in #2.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 4- Three work lists are kept. Statements are only added to these
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 lists if they produce one of SSA_PROP_INTERESTING or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 SSA_PROP_VARYING.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 CFG_BLOCKS contains the list of blocks to be simulated.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 Blocks are added to this list if their incoming edges are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 found executable.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
111
kono
parents: 67
diff changeset
87 SSA_EDGE_WORKLIST contains the list of statements that we
kono
parents: 67
diff changeset
88 need to revisit.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 5- Simulation terminates when all three work lists are drained.
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 Before calling ssa_propagate, it is important to clear
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 prop_simulate_again_p for all the statements in the program that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 should be simulated. This initialization allows an implementation
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 to specify which statements should never be simulated.
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 It is also important to compute def-use information before calling
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 ssa_propagate.
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 References:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 [1] Constant propagation with conditional branches,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 Wegman and Zadeck, ACM TOPLAS 13(2):181-210.
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 [2] Building an Optimizing Compiler,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 Robert Morgan, Butterworth-Heinemann, 1998, Section 8.9.
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 [3] Advanced Compiler Design and Implementation,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 Steven Muchnick, Morgan Kaufmann, 1997, Section 12.6 */
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 /* Function pointers used to parameterize the propagation engine. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 static ssa_prop_visit_stmt_fn ssa_prop_visit_stmt;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 static ssa_prop_visit_phi_fn ssa_prop_visit_phi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
111
kono
parents: 67
diff changeset
115 /* Worklist of control flow edge destinations. This contains
kono
parents: 67
diff changeset
116 the CFG order number of the blocks so we can iterate in CFG
kono
parents: 67
diff changeset
117 order by visiting in bit-order. */
kono
parents: 67
diff changeset
118 static bitmap cfg_blocks;
kono
parents: 67
diff changeset
119 static int *bb_to_cfg_order;
kono
parents: 67
diff changeset
120 static int *cfg_order_to_bb;
0
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 /* Worklist of SSA edges which will need reexamination as their
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 definition has changed. SSA edges are def-use edges in the SSA
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 web. For each D-U edge, we store the target statement or PHI node
111
kono
parents: 67
diff changeset
125 UID in a bitmap. UIDs order stmts in execution order. */
kono
parents: 67
diff changeset
126 static bitmap ssa_edge_worklist;
kono
parents: 67
diff changeset
127 static vec<gimple *> uid_to_stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 /* Return true if the block worklist empty. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 static inline bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 cfg_blocks_empty_p (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 {
111
kono
parents: 67
diff changeset
134 return bitmap_empty_p (cfg_blocks);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137
111
kono
parents: 67
diff changeset
138 /* Add a basic block to the worklist. The block must not be the ENTRY
kono
parents: 67
diff changeset
139 or EXIT block. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
141 static void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 cfg_blocks_add (basic_block bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 {
111
kono
parents: 67
diff changeset
144 gcc_assert (bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)
kono
parents: 67
diff changeset
145 && bb != EXIT_BLOCK_PTR_FOR_FN (cfun));
kono
parents: 67
diff changeset
146 bitmap_set_bit (cfg_blocks, bb_to_cfg_order[bb->index]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 /* Remove a block from the worklist. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 static basic_block
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 cfg_blocks_get (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 gcc_assert (!cfg_blocks_empty_p ());
111
kono
parents: 67
diff changeset
156 int order_index = bitmap_first_set_bit (cfg_blocks);
kono
parents: 67
diff changeset
157 bitmap_clear_bit (cfg_blocks, order_index);
kono
parents: 67
diff changeset
158 return BASIC_BLOCK_FOR_FN (cfun, cfg_order_to_bb [order_index]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 /* We have just defined a new value for VAR. If IS_VARYING is true,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 add all immediate uses of VAR to VARYING_SSA_EDGES, otherwise add
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 them to INTERESTING_SSA_EDGES. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 static void
111
kono
parents: 67
diff changeset
167 add_ssa_edge (tree var)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 imm_use_iterator iter;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 use_operand_p use_p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 FOR_EACH_IMM_USE_FAST (use_p, iter, var)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 {
111
kono
parents: 67
diff changeset
174 gimple *use_stmt = USE_STMT (use_p);
kono
parents: 67
diff changeset
175
kono
parents: 67
diff changeset
176 /* If we did not yet simulate the block wait for this to happen
kono
parents: 67
diff changeset
177 and do not add the stmt to the SSA edge worklist. */
kono
parents: 67
diff changeset
178 if (! (gimple_bb (use_stmt)->flags & BB_VISITED))
kono
parents: 67
diff changeset
179 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 if (prop_simulate_again_p (use_stmt)
111
kono
parents: 67
diff changeset
182 && bitmap_set_bit (ssa_edge_worklist, gimple_uid (use_stmt)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 {
111
kono
parents: 67
diff changeset
184 uid_to_stmt[gimple_uid (use_stmt)] = use_stmt;
kono
parents: 67
diff changeset
185 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
186 {
kono
parents: 67
diff changeset
187 fprintf (dump_file, "ssa_edge_worklist: adding SSA use in ");
kono
parents: 67
diff changeset
188 print_gimple_stmt (dump_file, use_stmt, 0, TDF_SLIM);
kono
parents: 67
diff changeset
189 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 /* Add edge E to the control flow worklist. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 add_control_edge (edge e)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 basic_block bb = e->dest;
111
kono
parents: 67
diff changeset
201 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 /* If the edge had already been executed, skip it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 if (e->flags & EDGE_EXECUTABLE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 e->flags |= EDGE_EXECUTABLE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 cfg_blocks_add (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 if (dump_file && (dump_flags & TDF_DETAILS))
111
kono
parents: 67
diff changeset
213 fprintf (dump_file, "Adding destination of edge (%d -> %d) to worklist\n",
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 e->src->index, e->dest->index);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 /* Simulate the execution of STMT and update the work lists accordingly. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 static void
111
kono
parents: 67
diff changeset
221 simulate_stmt (gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 enum ssa_prop_result val = SSA_PROP_NOT_INTERESTING;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 edge taken_edge = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 tree output_name = NULL_TREE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226
111
kono
parents: 67
diff changeset
227 /* Pull the stmt off the SSA edge worklist. */
kono
parents: 67
diff changeset
228 bitmap_clear_bit (ssa_edge_worklist, gimple_uid (stmt));
kono
parents: 67
diff changeset
229
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 /* Don't bother visiting statements that are already
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 considered varying by the propagator. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 if (!prop_simulate_again_p (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 if (gimple_code (stmt) == GIMPLE_PHI)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 {
111
kono
parents: 67
diff changeset
237 val = ssa_prop_visit_phi (as_a <gphi *> (stmt));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 output_name = gimple_phi_result (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 val = ssa_prop_visit_stmt (stmt, &taken_edge, &output_name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 if (val == SSA_PROP_VARYING)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 prop_set_simulate_again (stmt, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 /* If the statement produced a new varying value, add the SSA
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 edges coming out of OUTPUT_NAME. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 if (output_name)
111
kono
parents: 67
diff changeset
250 add_ssa_edge (output_name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 /* If STMT transfers control out of its basic block, add
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 all outgoing edges to the work list. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 if (stmt_ends_bb_p (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 basic_block bb = gimple_bb (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 FOR_EACH_EDGE (e, ei, bb->succs)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 add_control_edge (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 }
111
kono
parents: 67
diff changeset
262 return;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 else if (val == SSA_PROP_INTERESTING)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 /* If the statement produced new value, add the SSA edges coming
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 out of OUTPUT_NAME. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 if (output_name)
111
kono
parents: 67
diff changeset
269 add_ssa_edge (output_name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 /* If we know which edge is going to be taken out of this block,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 add it to the CFG work list. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 if (taken_edge)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 add_control_edge (taken_edge);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 }
111
kono
parents: 67
diff changeset
276
kono
parents: 67
diff changeset
277 /* If there are no SSA uses on the stmt whose defs are simulated
kono
parents: 67
diff changeset
278 again then this stmt will be never visited again. */
kono
parents: 67
diff changeset
279 bool has_simulate_again_uses = false;
kono
parents: 67
diff changeset
280 use_operand_p use_p;
kono
parents: 67
diff changeset
281 ssa_op_iter iter;
kono
parents: 67
diff changeset
282 if (gimple_code (stmt) == GIMPLE_PHI)
kono
parents: 67
diff changeset
283 {
kono
parents: 67
diff changeset
284 edge_iterator ei;
kono
parents: 67
diff changeset
285 edge e;
kono
parents: 67
diff changeset
286 tree arg;
kono
parents: 67
diff changeset
287 FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->preds)
kono
parents: 67
diff changeset
288 if (!(e->flags & EDGE_EXECUTABLE)
kono
parents: 67
diff changeset
289 || ((arg = PHI_ARG_DEF_FROM_EDGE (stmt, e))
kono
parents: 67
diff changeset
290 && TREE_CODE (arg) == SSA_NAME
kono
parents: 67
diff changeset
291 && !SSA_NAME_IS_DEFAULT_DEF (arg)
kono
parents: 67
diff changeset
292 && prop_simulate_again_p (SSA_NAME_DEF_STMT (arg))))
kono
parents: 67
diff changeset
293 {
kono
parents: 67
diff changeset
294 has_simulate_again_uses = true;
kono
parents: 67
diff changeset
295 break;
kono
parents: 67
diff changeset
296 }
kono
parents: 67
diff changeset
297 }
kono
parents: 67
diff changeset
298 else
kono
parents: 67
diff changeset
299 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
kono
parents: 67
diff changeset
300 {
kono
parents: 67
diff changeset
301 gimple *def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p));
kono
parents: 67
diff changeset
302 if (!gimple_nop_p (def_stmt)
kono
parents: 67
diff changeset
303 && prop_simulate_again_p (def_stmt))
kono
parents: 67
diff changeset
304 {
kono
parents: 67
diff changeset
305 has_simulate_again_uses = true;
kono
parents: 67
diff changeset
306 break;
kono
parents: 67
diff changeset
307 }
kono
parents: 67
diff changeset
308 }
kono
parents: 67
diff changeset
309 if (!has_simulate_again_uses)
kono
parents: 67
diff changeset
310 {
kono
parents: 67
diff changeset
311 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
312 fprintf (dump_file, "marking stmt to be not simulated again\n");
kono
parents: 67
diff changeset
313 prop_set_simulate_again (stmt, false);
kono
parents: 67
diff changeset
314 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 /* Process an SSA edge worklist. WORKLIST is the SSA edge worklist to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 drain. This pops statements off the given WORKLIST and processes
111
kono
parents: 67
diff changeset
319 them until one statement was simulated or there are no more statements
kono
parents: 67
diff changeset
320 on WORKLIST. We take a pointer to WORKLIST because it may be reallocated
kono
parents: 67
diff changeset
321 when an SSA edge is added to it in simulate_stmt. Return true if a stmt
kono
parents: 67
diff changeset
322 was simulated. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 static void
111
kono
parents: 67
diff changeset
325 process_ssa_edge_worklist ()
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 {
111
kono
parents: 67
diff changeset
327 /* Process the next entry from the worklist. */
kono
parents: 67
diff changeset
328 unsigned stmt_uid = bitmap_first_set_bit (ssa_edge_worklist);
kono
parents: 67
diff changeset
329 bitmap_clear_bit (ssa_edge_worklist, stmt_uid);
kono
parents: 67
diff changeset
330 gimple *stmt = uid_to_stmt[stmt_uid];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331
111
kono
parents: 67
diff changeset
332 /* We should not have stmts in not yet simulated BBs on the worklist. */
kono
parents: 67
diff changeset
333 gcc_assert (gimple_bb (stmt)->flags & BB_VISITED);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334
111
kono
parents: 67
diff changeset
335 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
336 {
kono
parents: 67
diff changeset
337 fprintf (dump_file, "\nSimulating statement: ");
kono
parents: 67
diff changeset
338 print_gimple_stmt (dump_file, stmt, 0, dump_flags);
kono
parents: 67
diff changeset
339 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340
111
kono
parents: 67
diff changeset
341 simulate_stmt (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 /* Simulate the execution of BLOCK. Evaluate the statement associated
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 with each variable reference inside the block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 simulate_block (basic_block block)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 /* There is nothing to do for the exit block. */
111
kono
parents: 67
diff changeset
354 if (block == EXIT_BLOCK_PTR_FOR_FN (cfun))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 fprintf (dump_file, "\nSimulating block %d\n", block->index);
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 /* Always simulate PHI nodes, even if we have simulated this block
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 before. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 for (gsi = gsi_start_phis (block); !gsi_end_p (gsi); gsi_next (&gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 simulate_stmt (gsi_stmt (gsi));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 /* If this is the first time we've simulated this block, then we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 must simulate each of its statements. */
111
kono
parents: 67
diff changeset
367 if (! (block->flags & BB_VISITED))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 gimple_stmt_iterator j;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 unsigned int normal_edge_count;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 edge e, normal_edge;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 for (j = gsi_start_bb (block); !gsi_end_p (j); gsi_next (&j))
111
kono
parents: 67
diff changeset
375 simulate_stmt (gsi_stmt (j));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376
111
kono
parents: 67
diff changeset
377 /* Note that we have simulated this block. */
kono
parents: 67
diff changeset
378 block->flags |= BB_VISITED;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
380 /* We can not predict when abnormal and EH edges will be executed, so
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 once a block is considered executable, we consider any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 outgoing abnormal edges as executable.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
384 TODO: This is not exactly true. Simplifying statement might
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
385 prove it non-throwing and also computed goto can be handled
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
386 when destination is known.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
387
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 At the same time, if this block has only one successor that is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 reached by non-abnormal edges, then add that successor to the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 worklist. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 normal_edge_count = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 normal_edge = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 FOR_EACH_EDGE (e, ei, block->succs)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
395 if (e->flags & (EDGE_ABNORMAL | EDGE_EH))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 add_control_edge (e);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 else
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 normal_edge_count++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 normal_edge = e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 if (normal_edge_count == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 add_control_edge (normal_edge);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 /* Initialize local data structures and work lists. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 ssa_prop_init (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 /* Worklists of SSA edges. */
111
kono
parents: 67
diff changeset
420 ssa_edge_worklist = BITMAP_ALLOC (NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421
111
kono
parents: 67
diff changeset
422 /* Worklist of basic-blocks. */
kono
parents: 67
diff changeset
423 bb_to_cfg_order = XNEWVEC (int, last_basic_block_for_fn (cfun) + 1);
kono
parents: 67
diff changeset
424 cfg_order_to_bb = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
kono
parents: 67
diff changeset
425 int n = pre_and_rev_post_order_compute_fn (cfun, NULL,
kono
parents: 67
diff changeset
426 cfg_order_to_bb, false);
kono
parents: 67
diff changeset
427 for (int i = 0; i < n; ++i)
kono
parents: 67
diff changeset
428 bb_to_cfg_order[cfg_order_to_bb[i]] = i;
kono
parents: 67
diff changeset
429 cfg_blocks = BITMAP_ALLOC (NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 dump_immediate_uses (dump_file);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 /* Initially assume that every edge in the CFG is not executable.
111
kono
parents: 67
diff changeset
435 (including the edges coming out of the entry block). Mark blocks
kono
parents: 67
diff changeset
436 as not visited, blocks not yet visited will have all their statements
kono
parents: 67
diff changeset
437 simulated once an incoming edge gets executable. */
kono
parents: 67
diff changeset
438 set_gimple_stmt_max_uid (cfun, 0);
kono
parents: 67
diff changeset
439 for (int i = 0; i < n; ++i)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 gimple_stmt_iterator si;
111
kono
parents: 67
diff changeset
442 bb = BASIC_BLOCK_FOR_FN (cfun, cfg_order_to_bb[i]);
kono
parents: 67
diff changeset
443
kono
parents: 67
diff changeset
444 for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
kono
parents: 67
diff changeset
445 {
kono
parents: 67
diff changeset
446 gimple *stmt = gsi_stmt (si);
kono
parents: 67
diff changeset
447 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
kono
parents: 67
diff changeset
448 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
111
kono
parents: 67
diff changeset
451 {
kono
parents: 67
diff changeset
452 gimple *stmt = gsi_stmt (si);
kono
parents: 67
diff changeset
453 gimple_set_uid (stmt, inc_gimple_stmt_max_uid (cfun));
kono
parents: 67
diff changeset
454 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
455
111
kono
parents: 67
diff changeset
456 bb->flags &= ~BB_VISITED;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 FOR_EACH_EDGE (e, ei, bb->succs)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 e->flags &= ~EDGE_EXECUTABLE;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 }
111
kono
parents: 67
diff changeset
460 uid_to_stmt.safe_grow (gimple_stmt_max_uid (cfun));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 /* Seed the algorithm by adding the successors of the entry block to the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 edge worklist. */
111
kono
parents: 67
diff changeset
464 FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs)
kono
parents: 67
diff changeset
465 {
kono
parents: 67
diff changeset
466 e->flags &= ~EDGE_EXECUTABLE;
kono
parents: 67
diff changeset
467 add_control_edge (e);
kono
parents: 67
diff changeset
468 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 /* Free allocated storage. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 ssa_prop_fini (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 {
111
kono
parents: 67
diff changeset
477 BITMAP_FREE (cfg_blocks);
kono
parents: 67
diff changeset
478 free (bb_to_cfg_order);
kono
parents: 67
diff changeset
479 free (cfg_order_to_bb);
kono
parents: 67
diff changeset
480 BITMAP_FREE (ssa_edge_worklist);
kono
parents: 67
diff changeset
481 uid_to_stmt.release ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 /* Return true if EXPR is an acceptable right-hand-side for a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 GIMPLE assignment. We validate the entire tree, not just
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 the root node, thus catching expressions that embed complex
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 operands that are not permitted in GIMPLE. This function
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 is needed because the folding routines in fold-const.c
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 may return such expressions in some cases, e.g., an array
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 access with an embedded index addition. It may make more
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 sense to have folding routines that are sensitive to the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 constraints on GIMPLE operands, rather than abandoning any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 any attempt to fold if the usual folding turns out to be too
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 aggressive. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 valid_gimple_rhs_p (tree expr)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 enum tree_code code = TREE_CODE (expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 switch (TREE_CODE_CLASS (code))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 case tcc_declaration:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 if (!is_gimple_variable (expr))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 case tcc_constant:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 /* All constants are ok. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512
111
kono
parents: 67
diff changeset
513 case tcc_comparison:
kono
parents: 67
diff changeset
514 /* GENERIC allows comparisons with non-boolean types, reject
kono
parents: 67
diff changeset
515 those for GIMPLE. Let vector-typed comparisons pass - rules
kono
parents: 67
diff changeset
516 for GENERIC and GIMPLE are the same here. */
kono
parents: 67
diff changeset
517 if (!(INTEGRAL_TYPE_P (TREE_TYPE (expr))
kono
parents: 67
diff changeset
518 && (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE
kono
parents: 67
diff changeset
519 || TYPE_PRECISION (TREE_TYPE (expr)) == 1))
kono
parents: 67
diff changeset
520 && ! VECTOR_TYPE_P (TREE_TYPE (expr)))
kono
parents: 67
diff changeset
521 return false;
kono
parents: 67
diff changeset
522
kono
parents: 67
diff changeset
523 /* Fallthru. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 case tcc_binary:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 if (!is_gimple_val (TREE_OPERAND (expr, 0))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 || !is_gimple_val (TREE_OPERAND (expr, 1)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 case tcc_unary:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 if (!is_gimple_val (TREE_OPERAND (expr, 0)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 case tcc_expression:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 switch (code)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 case ADDR_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 tree t;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 if (is_gimple_min_invariant (expr))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 t = TREE_OPERAND (expr, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 while (handled_component_p (t))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 /* ??? More checks needed, see the GIMPLE verifier. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 if ((TREE_CODE (t) == ARRAY_REF
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 || TREE_CODE (t) == ARRAY_RANGE_REF)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 && !is_gimple_val (TREE_OPERAND (t, 1)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 t = TREE_OPERAND (t, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 if (!is_gimple_id (t))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 default:
111
kono
parents: 67
diff changeset
559 if (get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS)
kono
parents: 67
diff changeset
560 {
kono
parents: 67
diff changeset
561 if (((code == VEC_COND_EXPR || code == COND_EXPR)
kono
parents: 67
diff changeset
562 ? !is_gimple_condexpr (TREE_OPERAND (expr, 0))
kono
parents: 67
diff changeset
563 : !is_gimple_val (TREE_OPERAND (expr, 0)))
kono
parents: 67
diff changeset
564 || !is_gimple_val (TREE_OPERAND (expr, 1))
kono
parents: 67
diff changeset
565 || !is_gimple_val (TREE_OPERAND (expr, 2)))
kono
parents: 67
diff changeset
566 return false;
kono
parents: 67
diff changeset
567 break;
kono
parents: 67
diff changeset
568 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 break;
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 case tcc_vl_exp:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 case tcc_exceptional:
111
kono
parents: 67
diff changeset
577 if (code == CONSTRUCTOR)
kono
parents: 67
diff changeset
578 {
kono
parents: 67
diff changeset
579 unsigned i;
kono
parents: 67
diff changeset
580 tree elt;
kono
parents: 67
diff changeset
581 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), i, elt)
kono
parents: 67
diff changeset
582 if (!is_gimple_val (elt))
kono
parents: 67
diff changeset
583 return false;
kono
parents: 67
diff changeset
584 return true;
kono
parents: 67
diff changeset
585 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 if (code != SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589
111
kono
parents: 67
diff changeset
590 case tcc_reference:
kono
parents: 67
diff changeset
591 if (code == BIT_FIELD_REF)
kono
parents: 67
diff changeset
592 return is_gimple_val (TREE_OPERAND (expr, 0));
kono
parents: 67
diff changeset
593 return false;
kono
parents: 67
diff changeset
594
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 return false;
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 /* Return true if EXPR is a CALL_EXPR suitable for representation
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 as a single GIMPLE_CALL statement. If the arguments require
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 further gimplification, return false. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606
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
607 static bool
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 valid_gimple_call_p (tree expr)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 unsigned i, nargs;
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 if (TREE_CODE (expr) != CALL_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 nargs = call_expr_nargs (expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 for (i = 0; i < nargs; i++)
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
617 {
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
618 tree arg = CALL_EXPR_ARG (expr, i);
111
kono
parents: 67
diff changeset
619 if (is_gimple_reg_type (TREE_TYPE (arg)))
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
620 {
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
621 if (!is_gimple_val (arg))
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
622 return false;
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
623 }
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
624 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
625 if (!is_gimple_lvalue (arg))
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
626 return false;
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
627 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
632
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 /* Make SSA names defined by OLD_STMT point to NEW_STMT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 as their defining statement. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 void
111
kono
parents: 67
diff changeset
637 move_ssa_defining_stmt_for_defs (gimple *new_stmt, gimple *old_stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 tree var;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 ssa_op_iter iter;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 if (gimple_in_ssa_p (cfun))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 /* Make defined SSA_NAMEs point to the new
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 statement as their definition. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 FOR_EACH_SSA_TREE_OPERAND (var, old_stmt, iter, SSA_OP_ALL_DEFS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 if (TREE_CODE (var) == SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 SSA_NAME_DEF_STMT (var) = new_stmt;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653
111
kono
parents: 67
diff changeset
654 /* Helper function for update_gimple_call and update_call_from_tree.
kono
parents: 67
diff changeset
655 A GIMPLE_CALL STMT is being replaced with GIMPLE_CALL NEW_STMT. */
kono
parents: 67
diff changeset
656
kono
parents: 67
diff changeset
657 static void
kono
parents: 67
diff changeset
658 finish_update_gimple_call (gimple_stmt_iterator *si_p, gimple *new_stmt,
kono
parents: 67
diff changeset
659 gimple *stmt)
kono
parents: 67
diff changeset
660 {
kono
parents: 67
diff changeset
661 gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt));
kono
parents: 67
diff changeset
662 move_ssa_defining_stmt_for_defs (new_stmt, stmt);
kono
parents: 67
diff changeset
663 gimple_set_vuse (new_stmt, gimple_vuse (stmt));
kono
parents: 67
diff changeset
664 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
kono
parents: 67
diff changeset
665 gimple_set_location (new_stmt, gimple_location (stmt));
kono
parents: 67
diff changeset
666 if (gimple_block (new_stmt) == NULL_TREE)
kono
parents: 67
diff changeset
667 gimple_set_block (new_stmt, gimple_block (stmt));
kono
parents: 67
diff changeset
668 gsi_replace (si_p, new_stmt, false);
kono
parents: 67
diff changeset
669 }
kono
parents: 67
diff changeset
670
kono
parents: 67
diff changeset
671 /* Update a GIMPLE_CALL statement at iterator *SI_P to call to FN
kono
parents: 67
diff changeset
672 with number of arguments NARGS, where the arguments in GIMPLE form
kono
parents: 67
diff changeset
673 follow NARGS argument. */
kono
parents: 67
diff changeset
674
kono
parents: 67
diff changeset
675 bool
kono
parents: 67
diff changeset
676 update_gimple_call (gimple_stmt_iterator *si_p, tree fn, int nargs, ...)
kono
parents: 67
diff changeset
677 {
kono
parents: 67
diff changeset
678 va_list ap;
kono
parents: 67
diff changeset
679 gcall *new_stmt, *stmt = as_a <gcall *> (gsi_stmt (*si_p));
kono
parents: 67
diff changeset
680
kono
parents: 67
diff changeset
681 gcc_assert (is_gimple_call (stmt));
kono
parents: 67
diff changeset
682 va_start (ap, nargs);
kono
parents: 67
diff changeset
683 new_stmt = gimple_build_call_valist (fn, nargs, ap);
kono
parents: 67
diff changeset
684 finish_update_gimple_call (si_p, new_stmt, stmt);
kono
parents: 67
diff changeset
685 va_end (ap);
kono
parents: 67
diff changeset
686 return true;
kono
parents: 67
diff changeset
687 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 /* Update a GIMPLE_CALL statement at iterator *SI_P to reflect the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
690 value of EXPR, which is expected to be the result of folding the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 call. This can only be done if EXPR is a CALL_EXPR with valid
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
692 GIMPLE operands as arguments, or if it is a suitable RHS expression
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 for a GIMPLE_ASSIGN. More complex expressions will require
111
kono
parents: 67
diff changeset
694 gimplification, which will introduce additional statements. In this
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 event, no update is performed, and the function returns false.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 Note that we cannot mutate a GIMPLE_CALL in-place, so we always
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 replace the statement at *SI_P with an entirely new statement.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 The new statement need not be a call, e.g., if the original call
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 folded to a constant. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 update_call_from_tree (gimple_stmt_iterator *si_p, tree expr)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 {
111
kono
parents: 67
diff changeset
704 gimple *stmt = gsi_stmt (*si_p);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 if (valid_gimple_call_p (expr))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 /* The call has simplified to another call. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 tree fn = CALL_EXPR_FN (expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 unsigned i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 unsigned nargs = call_expr_nargs (expr);
111
kono
parents: 67
diff changeset
712 vec<tree> args = vNULL;
kono
parents: 67
diff changeset
713 gcall *new_stmt;
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 if (nargs > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 {
111
kono
parents: 67
diff changeset
717 args.create (nargs);
kono
parents: 67
diff changeset
718 args.safe_grow_cleared (nargs);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
719
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 for (i = 0; i < nargs; i++)
111
kono
parents: 67
diff changeset
721 args[i] = CALL_EXPR_ARG (expr, i);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 new_stmt = gimple_build_call_vec (fn, args);
111
kono
parents: 67
diff changeset
725 finish_update_gimple_call (si_p, new_stmt, stmt);
kono
parents: 67
diff changeset
726 args.release ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 else if (valid_gimple_rhs_p (expr))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 {
111
kono
parents: 67
diff changeset
732 tree lhs = gimple_call_lhs (stmt);
kono
parents: 67
diff changeset
733 gimple *new_stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 /* The call has simplified to an expression
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 that cannot be represented as a GIMPLE_CALL. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 if (lhs)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 /* A value is expected.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 Introduce a new GIMPLE_ASSIGN statement. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 STRIP_USELESS_TYPE_CONVERSION (expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 new_stmt = gimple_build_assign (lhs, expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 move_ssa_defining_stmt_for_defs (new_stmt, stmt);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
744 gimple_set_vuse (new_stmt, gimple_vuse (stmt));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
745 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 else if (!TREE_SIDE_EFFECTS (expr))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 /* No value is expected, and EXPR has no effect.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 Replace it with an empty statement. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 new_stmt = gimple_build_nop ();
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 if (gimple_in_ssa_p (cfun))
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 {
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
754 unlink_stmt_vdef (stmt);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
755 release_defs (stmt);
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
756 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 /* No value is expected, but EXPR has an effect,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 e.g., it could be a reference to a volatile
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 variable. Create an assignment statement
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763 with a dummy (unused) lhs variable. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 STRIP_USELESS_TYPE_CONVERSION (expr);
111
kono
parents: 67
diff changeset
765 if (gimple_in_ssa_p (cfun))
kono
parents: 67
diff changeset
766 lhs = make_ssa_name (TREE_TYPE (expr));
kono
parents: 67
diff changeset
767 else
kono
parents: 67
diff changeset
768 lhs = create_tmp_var (TREE_TYPE (expr));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 new_stmt = gimple_build_assign (lhs, expr);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
770 gimple_set_vuse (new_stmt, gimple_vuse (stmt));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
771 gimple_set_vdef (new_stmt, gimple_vdef (stmt));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 move_ssa_defining_stmt_for_defs (new_stmt, stmt);
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 gimple_set_location (new_stmt, gimple_location (stmt));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 gsi_replace (si_p, new_stmt, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 return true;
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 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 /* The call simplified to an expression that is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 not a valid GIMPLE RHS. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 /* Entry point to the propagation engine.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 VISIT_STMT is called for every statement visited.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 VISIT_PHI is called for every PHI node visited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 ssa_propagate (ssa_prop_visit_stmt_fn visit_stmt,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 ssa_prop_visit_phi_fn visit_phi)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 ssa_prop_visit_stmt = visit_stmt;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 ssa_prop_visit_phi = visit_phi;
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 ssa_prop_init ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 /* Iterate until the worklists are empty. */
111
kono
parents: 67
diff changeset
800 while (! cfg_blocks_empty_p ()
kono
parents: 67
diff changeset
801 || ! bitmap_empty_p (ssa_edge_worklist))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802 {
111
kono
parents: 67
diff changeset
803 /* First simulate whole blocks. */
kono
parents: 67
diff changeset
804 if (! cfg_blocks_empty_p ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 /* Pull the next block to simulate off the worklist. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 basic_block dest_block = cfg_blocks_get ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 simulate_block (dest_block);
111
kono
parents: 67
diff changeset
809 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811
111
kono
parents: 67
diff changeset
812 /* Then simulate from the SSA edge worklist. */
kono
parents: 67
diff changeset
813 process_ssa_edge_worklist ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 }
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 ssa_prop_fini ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 }
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 /* Return true if STMT is of the form 'mem_ref = RHS', where 'mem_ref'
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 is a non-volatile pointer dereference, a structure reference or a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 reference to a single _DECL. Ignore volatile memory references
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 because they are not interesting for the optimizers. */
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 bool
111
kono
parents: 67
diff changeset
826 stmt_makes_single_store (gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828 tree lhs;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 if (gimple_code (stmt) != GIMPLE_ASSIGN
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 && gimple_code (stmt) != GIMPLE_CALL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
834 if (!gimple_vdef (stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 lhs = gimple_get_lhs (stmt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 /* A call statement may have a null LHS. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 if (!lhs)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843 return (!TREE_THIS_VOLATILE (lhs)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 && (DECL_P (lhs)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 || REFERENCE_CLASS_P (lhs)));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
846 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 /* Propagation statistics. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 struct prop_stats_d
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 long num_const_prop;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 long num_copy_prop;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
854 long num_stmts_folded;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 long num_dce;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
858 static struct prop_stats_d prop_stats;
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 /* Replace USE references in statement STMT with the values stored in
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 PROP_VALUE. Return true if at least one reference was replaced. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862
111
kono
parents: 67
diff changeset
863 bool
kono
parents: 67
diff changeset
864 replace_uses_in (gimple *stmt, ssa_prop_get_value_fn get_value)
0
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 bool replaced = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 use_operand_p use;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
868 ssa_op_iter iter;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
870 FOR_EACH_SSA_USE_OPERAND (use, stmt, iter, SSA_OP_USE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 tree tuse = USE_FROM_PTR (use);
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
873 tree val = (*get_value) (tuse);
0
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 if (val == tuse || val == NULL_TREE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
876 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 if (gimple_code (stmt) == GIMPLE_ASM
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 && !may_propagate_copy_into_asm (tuse))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880 continue;
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 if (!may_propagate_copy (tuse, val))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
885 if (TREE_CODE (val) != SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 prop_stats.num_const_prop++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
887 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 prop_stats.num_copy_prop++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
889
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
890 propagate_value (use, val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
891
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892 replaced = true;
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 return replaced;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
896 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
897
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
898
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
899 /* Replace propagated values into all the arguments for PHI using the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
900 values from PROP_VALUE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
901
111
kono
parents: 67
diff changeset
902 static bool
kono
parents: 67
diff changeset
903 replace_phi_args_in (gphi *phi, ssa_prop_get_value_fn get_value)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
905 size_t i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
906 bool replaced = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908 if (dump_file && (dump_flags & TDF_DETAILS))
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 fprintf (dump_file, "Folding PHI node: ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 print_gimple_stmt (dump_file, phi, 0, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
913
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914 for (i = 0; i < gimple_phi_num_args (phi); i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 tree arg = gimple_phi_arg_def (phi, i);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 if (TREE_CODE (arg) == SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 {
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
920 tree val = (*get_value) (arg);
0
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 if (val && val != arg && may_propagate_copy (arg, val))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 {
111
kono
parents: 67
diff changeset
924 edge e = gimple_phi_arg_edge (phi, i);
kono
parents: 67
diff changeset
925
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926 if (TREE_CODE (val) != SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927 prop_stats.num_const_prop++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929 prop_stats.num_copy_prop++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
930
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
931 propagate_value (PHI_ARG_DEF_PTR (phi, i), val);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
932 replaced = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
933
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934 /* If we propagated a copy and this argument flows
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935 through an abnormal edge, update the replacement
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936 accordingly. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937 if (TREE_CODE (val) == SSA_NAME
111
kono
parents: 67
diff changeset
938 && e->flags & EDGE_ABNORMAL
kono
parents: 67
diff changeset
939 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val))
kono
parents: 67
diff changeset
940 {
kono
parents: 67
diff changeset
941 /* This can only occur for virtual operands, since
kono
parents: 67
diff changeset
942 for the real ones SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val))
kono
parents: 67
diff changeset
943 would prevent replacement. */
kono
parents: 67
diff changeset
944 gcc_checking_assert (virtual_operand_p (val));
kono
parents: 67
diff changeset
945 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val) = 1;
kono
parents: 67
diff changeset
946 }
0
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 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
950
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
951 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
952 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 if (!replaced)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 fprintf (dump_file, "No folding possible\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 fprintf (dump_file, "Folded into: ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 print_gimple_stmt (dump_file, phi, 0, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959 fprintf (dump_file, "\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961 }
111
kono
parents: 67
diff changeset
962
kono
parents: 67
diff changeset
963 return replaced;
0
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
966
111
kono
parents: 67
diff changeset
967 class substitute_and_fold_dom_walker : public dom_walker
kono
parents: 67
diff changeset
968 {
kono
parents: 67
diff changeset
969 public:
kono
parents: 67
diff changeset
970 substitute_and_fold_dom_walker (cdi_direction direction,
kono
parents: 67
diff changeset
971 ssa_prop_get_value_fn get_value_fn_,
kono
parents: 67
diff changeset
972 ssa_prop_fold_stmt_fn fold_fn_)
kono
parents: 67
diff changeset
973 : dom_walker (direction), get_value_fn (get_value_fn_),
kono
parents: 67
diff changeset
974 fold_fn (fold_fn_), something_changed (false)
kono
parents: 67
diff changeset
975 {
kono
parents: 67
diff changeset
976 stmts_to_remove.create (0);
kono
parents: 67
diff changeset
977 stmts_to_fixup.create (0);
kono
parents: 67
diff changeset
978 need_eh_cleanup = BITMAP_ALLOC (NULL);
kono
parents: 67
diff changeset
979 }
kono
parents: 67
diff changeset
980 ~substitute_and_fold_dom_walker ()
kono
parents: 67
diff changeset
981 {
kono
parents: 67
diff changeset
982 stmts_to_remove.release ();
kono
parents: 67
diff changeset
983 stmts_to_fixup.release ();
kono
parents: 67
diff changeset
984 BITMAP_FREE (need_eh_cleanup);
kono
parents: 67
diff changeset
985 }
kono
parents: 67
diff changeset
986
kono
parents: 67
diff changeset
987 virtual edge before_dom_children (basic_block);
kono
parents: 67
diff changeset
988 virtual void after_dom_children (basic_block) {}
kono
parents: 67
diff changeset
989
kono
parents: 67
diff changeset
990 ssa_prop_get_value_fn get_value_fn;
kono
parents: 67
diff changeset
991 ssa_prop_fold_stmt_fn fold_fn;
kono
parents: 67
diff changeset
992 bool something_changed;
kono
parents: 67
diff changeset
993 vec<gimple *> stmts_to_remove;
kono
parents: 67
diff changeset
994 vec<gimple *> stmts_to_fixup;
kono
parents: 67
diff changeset
995 bitmap need_eh_cleanup;
kono
parents: 67
diff changeset
996 };
kono
parents: 67
diff changeset
997
kono
parents: 67
diff changeset
998 edge
kono
parents: 67
diff changeset
999 substitute_and_fold_dom_walker::before_dom_children (basic_block bb)
kono
parents: 67
diff changeset
1000 {
kono
parents: 67
diff changeset
1001 /* Propagate known values into PHI nodes. */
kono
parents: 67
diff changeset
1002 for (gphi_iterator i = gsi_start_phis (bb);
kono
parents: 67
diff changeset
1003 !gsi_end_p (i);
kono
parents: 67
diff changeset
1004 gsi_next (&i))
kono
parents: 67
diff changeset
1005 {
kono
parents: 67
diff changeset
1006 gphi *phi = i.phi ();
kono
parents: 67
diff changeset
1007 tree res = gimple_phi_result (phi);
kono
parents: 67
diff changeset
1008 if (virtual_operand_p (res))
kono
parents: 67
diff changeset
1009 continue;
kono
parents: 67
diff changeset
1010 if (res && TREE_CODE (res) == SSA_NAME)
kono
parents: 67
diff changeset
1011 {
kono
parents: 67
diff changeset
1012 tree sprime = get_value_fn (res);
kono
parents: 67
diff changeset
1013 if (sprime
kono
parents: 67
diff changeset
1014 && sprime != res
kono
parents: 67
diff changeset
1015 && may_propagate_copy (res, sprime))
kono
parents: 67
diff changeset
1016 {
kono
parents: 67
diff changeset
1017 stmts_to_remove.safe_push (phi);
kono
parents: 67
diff changeset
1018 continue;
kono
parents: 67
diff changeset
1019 }
kono
parents: 67
diff changeset
1020 }
kono
parents: 67
diff changeset
1021 something_changed |= replace_phi_args_in (phi, get_value_fn);
kono
parents: 67
diff changeset
1022 }
kono
parents: 67
diff changeset
1023
kono
parents: 67
diff changeset
1024 /* Propagate known values into stmts. In some case it exposes
kono
parents: 67
diff changeset
1025 more trivially deletable stmts to walk backward. */
kono
parents: 67
diff changeset
1026 for (gimple_stmt_iterator i = gsi_start_bb (bb);
kono
parents: 67
diff changeset
1027 !gsi_end_p (i);
kono
parents: 67
diff changeset
1028 gsi_next (&i))
kono
parents: 67
diff changeset
1029 {
kono
parents: 67
diff changeset
1030 bool did_replace;
kono
parents: 67
diff changeset
1031 gimple *stmt = gsi_stmt (i);
kono
parents: 67
diff changeset
1032
kono
parents: 67
diff changeset
1033 /* No point propagating into a stmt we have a value for we
kono
parents: 67
diff changeset
1034 can propagate into all uses. Mark it for removal instead. */
kono
parents: 67
diff changeset
1035 tree lhs = gimple_get_lhs (stmt);
kono
parents: 67
diff changeset
1036 if (lhs && TREE_CODE (lhs) == SSA_NAME)
kono
parents: 67
diff changeset
1037 {
kono
parents: 67
diff changeset
1038 tree sprime = get_value_fn (lhs);
kono
parents: 67
diff changeset
1039 if (sprime
kono
parents: 67
diff changeset
1040 && sprime != lhs
kono
parents: 67
diff changeset
1041 && may_propagate_copy (lhs, sprime)
kono
parents: 67
diff changeset
1042 && !stmt_could_throw_p (stmt)
kono
parents: 67
diff changeset
1043 && !gimple_has_side_effects (stmt)
kono
parents: 67
diff changeset
1044 /* We have to leave ASSERT_EXPRs around for jump-threading. */
kono
parents: 67
diff changeset
1045 && (!is_gimple_assign (stmt)
kono
parents: 67
diff changeset
1046 || gimple_assign_rhs_code (stmt) != ASSERT_EXPR))
kono
parents: 67
diff changeset
1047 {
kono
parents: 67
diff changeset
1048 stmts_to_remove.safe_push (stmt);
kono
parents: 67
diff changeset
1049 continue;
kono
parents: 67
diff changeset
1050 }
kono
parents: 67
diff changeset
1051 }
kono
parents: 67
diff changeset
1052
kono
parents: 67
diff changeset
1053 /* Replace the statement with its folded version and mark it
kono
parents: 67
diff changeset
1054 folded. */
kono
parents: 67
diff changeset
1055 did_replace = false;
kono
parents: 67
diff changeset
1056 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
1057 {
kono
parents: 67
diff changeset
1058 fprintf (dump_file, "Folding statement: ");
kono
parents: 67
diff changeset
1059 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
kono
parents: 67
diff changeset
1060 }
kono
parents: 67
diff changeset
1061
kono
parents: 67
diff changeset
1062 gimple *old_stmt = stmt;
kono
parents: 67
diff changeset
1063 bool was_noreturn = (is_gimple_call (stmt)
kono
parents: 67
diff changeset
1064 && gimple_call_noreturn_p (stmt));
kono
parents: 67
diff changeset
1065
kono
parents: 67
diff changeset
1066 /* Replace real uses in the statement. */
kono
parents: 67
diff changeset
1067 did_replace |= replace_uses_in (stmt, get_value_fn);
kono
parents: 67
diff changeset
1068
kono
parents: 67
diff changeset
1069 /* If we made a replacement, fold the statement. */
kono
parents: 67
diff changeset
1070 if (did_replace)
kono
parents: 67
diff changeset
1071 {
kono
parents: 67
diff changeset
1072 fold_stmt (&i, follow_single_use_edges);
kono
parents: 67
diff changeset
1073 stmt = gsi_stmt (i);
kono
parents: 67
diff changeset
1074 gimple_set_modified (stmt, true);
kono
parents: 67
diff changeset
1075 }
kono
parents: 67
diff changeset
1076
kono
parents: 67
diff changeset
1077 /* Some statements may be simplified using propagator
kono
parents: 67
diff changeset
1078 specific information. Do this before propagating
kono
parents: 67
diff changeset
1079 into the stmt to not disturb pass specific information. */
kono
parents: 67
diff changeset
1080 if (fold_fn)
kono
parents: 67
diff changeset
1081 {
kono
parents: 67
diff changeset
1082 update_stmt_if_modified (stmt);
kono
parents: 67
diff changeset
1083 if ((*fold_fn)(&i))
kono
parents: 67
diff changeset
1084 {
kono
parents: 67
diff changeset
1085 did_replace = true;
kono
parents: 67
diff changeset
1086 prop_stats.num_stmts_folded++;
kono
parents: 67
diff changeset
1087 stmt = gsi_stmt (i);
kono
parents: 67
diff changeset
1088 gimple_set_modified (stmt, true);
kono
parents: 67
diff changeset
1089 }
kono
parents: 67
diff changeset
1090 }
kono
parents: 67
diff changeset
1091
kono
parents: 67
diff changeset
1092 /* If this is a control statement the propagator left edges
kono
parents: 67
diff changeset
1093 unexecuted on force the condition in a way consistent with
kono
parents: 67
diff changeset
1094 that. See PR66945 for cases where the propagator can end
kono
parents: 67
diff changeset
1095 up with a different idea of a taken edge than folding
kono
parents: 67
diff changeset
1096 (once undefined behavior is involved). */
kono
parents: 67
diff changeset
1097 if (gimple_code (stmt) == GIMPLE_COND)
kono
parents: 67
diff changeset
1098 {
kono
parents: 67
diff changeset
1099 if ((EDGE_SUCC (bb, 0)->flags & EDGE_EXECUTABLE)
kono
parents: 67
diff changeset
1100 ^ (EDGE_SUCC (bb, 1)->flags & EDGE_EXECUTABLE))
kono
parents: 67
diff changeset
1101 {
kono
parents: 67
diff changeset
1102 if (((EDGE_SUCC (bb, 0)->flags & EDGE_TRUE_VALUE) != 0)
kono
parents: 67
diff changeset
1103 == ((EDGE_SUCC (bb, 0)->flags & EDGE_EXECUTABLE) != 0))
kono
parents: 67
diff changeset
1104 gimple_cond_make_true (as_a <gcond *> (stmt));
kono
parents: 67
diff changeset
1105 else
kono
parents: 67
diff changeset
1106 gimple_cond_make_false (as_a <gcond *> (stmt));
kono
parents: 67
diff changeset
1107 gimple_set_modified (stmt, true);
kono
parents: 67
diff changeset
1108 did_replace = true;
kono
parents: 67
diff changeset
1109 }
kono
parents: 67
diff changeset
1110 }
kono
parents: 67
diff changeset
1111
kono
parents: 67
diff changeset
1112 /* Now cleanup. */
kono
parents: 67
diff changeset
1113 if (did_replace)
kono
parents: 67
diff changeset
1114 {
kono
parents: 67
diff changeset
1115 /* If we cleaned up EH information from the statement,
kono
parents: 67
diff changeset
1116 remove EH edges. */
kono
parents: 67
diff changeset
1117 if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
kono
parents: 67
diff changeset
1118 bitmap_set_bit (need_eh_cleanup, bb->index);
kono
parents: 67
diff changeset
1119
kono
parents: 67
diff changeset
1120 /* If we turned a not noreturn call into a noreturn one
kono
parents: 67
diff changeset
1121 schedule it for fixup. */
kono
parents: 67
diff changeset
1122 if (!was_noreturn
kono
parents: 67
diff changeset
1123 && is_gimple_call (stmt)
kono
parents: 67
diff changeset
1124 && gimple_call_noreturn_p (stmt))
kono
parents: 67
diff changeset
1125 stmts_to_fixup.safe_push (stmt);
kono
parents: 67
diff changeset
1126
kono
parents: 67
diff changeset
1127 if (gimple_assign_single_p (stmt))
kono
parents: 67
diff changeset
1128 {
kono
parents: 67
diff changeset
1129 tree rhs = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
1130
kono
parents: 67
diff changeset
1131 if (TREE_CODE (rhs) == ADDR_EXPR)
kono
parents: 67
diff changeset
1132 recompute_tree_invariant_for_addr_expr (rhs);
kono
parents: 67
diff changeset
1133 }
kono
parents: 67
diff changeset
1134
kono
parents: 67
diff changeset
1135 /* Determine what needs to be done to update the SSA form. */
kono
parents: 67
diff changeset
1136 update_stmt_if_modified (stmt);
kono
parents: 67
diff changeset
1137 if (!is_gimple_debug (stmt))
kono
parents: 67
diff changeset
1138 something_changed = true;
kono
parents: 67
diff changeset
1139 }
kono
parents: 67
diff changeset
1140
kono
parents: 67
diff changeset
1141 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
1142 {
kono
parents: 67
diff changeset
1143 if (did_replace)
kono
parents: 67
diff changeset
1144 {
kono
parents: 67
diff changeset
1145 fprintf (dump_file, "Folded into: ");
kono
parents: 67
diff changeset
1146 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
kono
parents: 67
diff changeset
1147 fprintf (dump_file, "\n");
kono
parents: 67
diff changeset
1148 }
kono
parents: 67
diff changeset
1149 else
kono
parents: 67
diff changeset
1150 fprintf (dump_file, "Not folded\n");
kono
parents: 67
diff changeset
1151 }
kono
parents: 67
diff changeset
1152 }
kono
parents: 67
diff changeset
1153 return NULL;
kono
parents: 67
diff changeset
1154 }
kono
parents: 67
diff changeset
1155
kono
parents: 67
diff changeset
1156
kono
parents: 67
diff changeset
1157
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 /* Perform final substitution and folding of propagated values.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 PROP_VALUE[I] contains the single value that should be substituted
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 at every use of SSA name N_I. If PROP_VALUE is NULL, no values are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 substituted.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1164 If FOLD_FN is non-NULL the function will be invoked on all statements
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1165 before propagating values for pass specific simplification.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166
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
1167 DO_DCE is true if trivially dead stmts can be removed.
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
1168
111
kono
parents: 67
diff changeset
1169 If DO_DCE is true, the statements within a BB are walked from
kono
parents: 67
diff changeset
1170 last to first element. Otherwise we scan from first to last element.
kono
parents: 67
diff changeset
1171
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 Return TRUE when something changed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174 bool
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
1175 substitute_and_fold (ssa_prop_get_value_fn get_value_fn,
111
kono
parents: 67
diff changeset
1176 ssa_prop_fold_stmt_fn fold_fn)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1177 {
111
kono
parents: 67
diff changeset
1178 gcc_assert (get_value_fn);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1179
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1180 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1181 fprintf (dump_file, "\nSubstituting values and folding statements\n\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1182
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1183 memset (&prop_stats, 0, sizeof (prop_stats));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184
111
kono
parents: 67
diff changeset
1185 calculate_dominance_info (CDI_DOMINATORS);
kono
parents: 67
diff changeset
1186 substitute_and_fold_dom_walker walker(CDI_DOMINATORS,
kono
parents: 67
diff changeset
1187 get_value_fn, fold_fn);
kono
parents: 67
diff changeset
1188 walker.walk (ENTRY_BLOCK_PTR_FOR_FN (cfun));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189
111
kono
parents: 67
diff changeset
1190 /* We cannot remove stmts during the BB walk, especially not release
kono
parents: 67
diff changeset
1191 SSA names there as that destroys the lattice of our callers.
kono
parents: 67
diff changeset
1192 Remove stmts in reverse order to make debug stmt creation possible. */
kono
parents: 67
diff changeset
1193 while (!walker.stmts_to_remove.is_empty ())
kono
parents: 67
diff changeset
1194 {
kono
parents: 67
diff changeset
1195 gimple *stmt = walker.stmts_to_remove.pop ();
kono
parents: 67
diff changeset
1196 if (dump_file && dump_flags & TDF_DETAILS)
kono
parents: 67
diff changeset
1197 {
kono
parents: 67
diff changeset
1198 fprintf (dump_file, "Removing dead stmt ");
kono
parents: 67
diff changeset
1199 print_gimple_stmt (dump_file, stmt, 0);
kono
parents: 67
diff changeset
1200 fprintf (dump_file, "\n");
kono
parents: 67
diff changeset
1201 }
kono
parents: 67
diff changeset
1202 prop_stats.num_dce++;
kono
parents: 67
diff changeset
1203 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
kono
parents: 67
diff changeset
1204 if (gimple_code (stmt) == GIMPLE_PHI)
kono
parents: 67
diff changeset
1205 remove_phi_node (&gsi, true);
kono
parents: 67
diff changeset
1206 else
kono
parents: 67
diff changeset
1207 {
kono
parents: 67
diff changeset
1208 unlink_stmt_vdef (stmt);
kono
parents: 67
diff changeset
1209 gsi_remove (&gsi, true);
kono
parents: 67
diff changeset
1210 release_defs (stmt);
kono
parents: 67
diff changeset
1211 }
kono
parents: 67
diff changeset
1212 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1213
111
kono
parents: 67
diff changeset
1214 if (!bitmap_empty_p (walker.need_eh_cleanup))
kono
parents: 67
diff changeset
1215 gimple_purge_all_dead_eh_edges (walker.need_eh_cleanup);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216
111
kono
parents: 67
diff changeset
1217 /* Fixup stmts that became noreturn calls. This may require splitting
kono
parents: 67
diff changeset
1218 blocks and thus isn't possible during the dominator walk. Do this
kono
parents: 67
diff changeset
1219 in reverse order so we don't inadvertedly remove a stmt we want to
kono
parents: 67
diff changeset
1220 fixup by visiting a dominating now noreturn call first. */
kono
parents: 67
diff changeset
1221 while (!walker.stmts_to_fixup.is_empty ())
kono
parents: 67
diff changeset
1222 {
kono
parents: 67
diff changeset
1223 gimple *stmt = walker.stmts_to_fixup.pop ();
kono
parents: 67
diff changeset
1224 if (dump_file && dump_flags & TDF_DETAILS)
kono
parents: 67
diff changeset
1225 {
kono
parents: 67
diff changeset
1226 fprintf (dump_file, "Fixing up noreturn call ");
kono
parents: 67
diff changeset
1227 print_gimple_stmt (dump_file, stmt, 0);
kono
parents: 67
diff changeset
1228 fprintf (dump_file, "\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1229 }
111
kono
parents: 67
diff changeset
1230 fixup_noreturn_call (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1231 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1232
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233 statistics_counter_event (cfun, "Constants propagated",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1234 prop_stats.num_const_prop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1235 statistics_counter_event (cfun, "Copies propagated",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1236 prop_stats.num_copy_prop);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1237 statistics_counter_event (cfun, "Statements folded",
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1238 prop_stats.num_stmts_folded);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1239 statistics_counter_event (cfun, "Statements deleted",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1240 prop_stats.num_dce);
111
kono
parents: 67
diff changeset
1241
kono
parents: 67
diff changeset
1242 return walker.something_changed;
kono
parents: 67
diff changeset
1243 }
kono
parents: 67
diff changeset
1244
kono
parents: 67
diff changeset
1245
kono
parents: 67
diff changeset
1246 /* Return true if we may propagate ORIG into DEST, false otherwise. */
kono
parents: 67
diff changeset
1247
kono
parents: 67
diff changeset
1248 bool
kono
parents: 67
diff changeset
1249 may_propagate_copy (tree dest, tree orig)
kono
parents: 67
diff changeset
1250 {
kono
parents: 67
diff changeset
1251 tree type_d = TREE_TYPE (dest);
kono
parents: 67
diff changeset
1252 tree type_o = TREE_TYPE (orig);
kono
parents: 67
diff changeset
1253
kono
parents: 67
diff changeset
1254 /* If ORIG is a default definition which flows in from an abnormal edge
kono
parents: 67
diff changeset
1255 then the copy can be propagated. It is important that we do so to avoid
kono
parents: 67
diff changeset
1256 uninitialized copies. */
kono
parents: 67
diff changeset
1257 if (TREE_CODE (orig) == SSA_NAME
kono
parents: 67
diff changeset
1258 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig)
kono
parents: 67
diff changeset
1259 && SSA_NAME_IS_DEFAULT_DEF (orig)
kono
parents: 67
diff changeset
1260 && (SSA_NAME_VAR (orig) == NULL_TREE
kono
parents: 67
diff changeset
1261 || TREE_CODE (SSA_NAME_VAR (orig)) == VAR_DECL))
kono
parents: 67
diff changeset
1262 ;
kono
parents: 67
diff changeset
1263 /* Otherwise if ORIG just flows in from an abnormal edge then the copy cannot
kono
parents: 67
diff changeset
1264 be propagated. */
kono
parents: 67
diff changeset
1265 else if (TREE_CODE (orig) == SSA_NAME
kono
parents: 67
diff changeset
1266 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig))
kono
parents: 67
diff changeset
1267 return false;
kono
parents: 67
diff changeset
1268 /* Similarly if DEST flows in from an abnormal edge then the copy cannot be
kono
parents: 67
diff changeset
1269 propagated. */
kono
parents: 67
diff changeset
1270 else if (TREE_CODE (dest) == SSA_NAME
kono
parents: 67
diff changeset
1271 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest))
kono
parents: 67
diff changeset
1272 return false;
kono
parents: 67
diff changeset
1273
kono
parents: 67
diff changeset
1274 /* Do not copy between types for which we *do* need a conversion. */
kono
parents: 67
diff changeset
1275 if (!useless_type_conversion_p (type_d, type_o))
kono
parents: 67
diff changeset
1276 return false;
kono
parents: 67
diff changeset
1277
kono
parents: 67
diff changeset
1278 /* Generally propagating virtual operands is not ok as that may
kono
parents: 67
diff changeset
1279 create overlapping life-ranges. */
kono
parents: 67
diff changeset
1280 if (TREE_CODE (dest) == SSA_NAME && virtual_operand_p (dest))
kono
parents: 67
diff changeset
1281 return false;
kono
parents: 67
diff changeset
1282
kono
parents: 67
diff changeset
1283 /* Anything else is OK. */
kono
parents: 67
diff changeset
1284 return true;
kono
parents: 67
diff changeset
1285 }
kono
parents: 67
diff changeset
1286
kono
parents: 67
diff changeset
1287 /* Like may_propagate_copy, but use as the destination expression
kono
parents: 67
diff changeset
1288 the principal expression (typically, the RHS) contained in
kono
parents: 67
diff changeset
1289 statement DEST. This is more efficient when working with the
kono
parents: 67
diff changeset
1290 gimple tuples representation. */
kono
parents: 67
diff changeset
1291
kono
parents: 67
diff changeset
1292 bool
kono
parents: 67
diff changeset
1293 may_propagate_copy_into_stmt (gimple *dest, tree orig)
kono
parents: 67
diff changeset
1294 {
kono
parents: 67
diff changeset
1295 tree type_d;
kono
parents: 67
diff changeset
1296 tree type_o;
kono
parents: 67
diff changeset
1297
kono
parents: 67
diff changeset
1298 /* If the statement is a switch or a single-rhs assignment,
kono
parents: 67
diff changeset
1299 then the expression to be replaced by the propagation may
kono
parents: 67
diff changeset
1300 be an SSA_NAME. Fortunately, there is an explicit tree
kono
parents: 67
diff changeset
1301 for the expression, so we delegate to may_propagate_copy. */
kono
parents: 67
diff changeset
1302
kono
parents: 67
diff changeset
1303 if (gimple_assign_single_p (dest))
kono
parents: 67
diff changeset
1304 return may_propagate_copy (gimple_assign_rhs1 (dest), orig);
kono
parents: 67
diff changeset
1305 else if (gswitch *dest_swtch = dyn_cast <gswitch *> (dest))
kono
parents: 67
diff changeset
1306 return may_propagate_copy (gimple_switch_index (dest_swtch), orig);
kono
parents: 67
diff changeset
1307
kono
parents: 67
diff changeset
1308 /* In other cases, the expression is not materialized, so there
kono
parents: 67
diff changeset
1309 is no destination to pass to may_propagate_copy. On the other
kono
parents: 67
diff changeset
1310 hand, the expression cannot be an SSA_NAME, so the analysis
kono
parents: 67
diff changeset
1311 is much simpler. */
kono
parents: 67
diff changeset
1312
kono
parents: 67
diff changeset
1313 if (TREE_CODE (orig) == SSA_NAME
kono
parents: 67
diff changeset
1314 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig))
kono
parents: 67
diff changeset
1315 return false;
kono
parents: 67
diff changeset
1316
kono
parents: 67
diff changeset
1317 if (is_gimple_assign (dest))
kono
parents: 67
diff changeset
1318 type_d = TREE_TYPE (gimple_assign_lhs (dest));
kono
parents: 67
diff changeset
1319 else if (gimple_code (dest) == GIMPLE_COND)
kono
parents: 67
diff changeset
1320 type_d = boolean_type_node;
kono
parents: 67
diff changeset
1321 else if (is_gimple_call (dest)
kono
parents: 67
diff changeset
1322 && gimple_call_lhs (dest) != NULL_TREE)
kono
parents: 67
diff changeset
1323 type_d = TREE_TYPE (gimple_call_lhs (dest));
kono
parents: 67
diff changeset
1324 else
kono
parents: 67
diff changeset
1325 gcc_unreachable ();
kono
parents: 67
diff changeset
1326
kono
parents: 67
diff changeset
1327 type_o = TREE_TYPE (orig);
kono
parents: 67
diff changeset
1328
kono
parents: 67
diff changeset
1329 if (!useless_type_conversion_p (type_d, type_o))
kono
parents: 67
diff changeset
1330 return false;
kono
parents: 67
diff changeset
1331
kono
parents: 67
diff changeset
1332 return true;
kono
parents: 67
diff changeset
1333 }
kono
parents: 67
diff changeset
1334
kono
parents: 67
diff changeset
1335 /* Similarly, but we know that we're propagating into an ASM_EXPR. */
kono
parents: 67
diff changeset
1336
kono
parents: 67
diff changeset
1337 bool
kono
parents: 67
diff changeset
1338 may_propagate_copy_into_asm (tree dest ATTRIBUTE_UNUSED)
kono
parents: 67
diff changeset
1339 {
kono
parents: 67
diff changeset
1340 return true;
0
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
111
kono
parents: 67
diff changeset
1343
kono
parents: 67
diff changeset
1344 /* Common code for propagate_value and replace_exp.
kono
parents: 67
diff changeset
1345
kono
parents: 67
diff changeset
1346 Replace use operand OP_P with VAL. FOR_PROPAGATION indicates if the
kono
parents: 67
diff changeset
1347 replacement is done to propagate a value or not. */
kono
parents: 67
diff changeset
1348
kono
parents: 67
diff changeset
1349 static void
kono
parents: 67
diff changeset
1350 replace_exp_1 (use_operand_p op_p, tree val,
kono
parents: 67
diff changeset
1351 bool for_propagation ATTRIBUTE_UNUSED)
kono
parents: 67
diff changeset
1352 {
kono
parents: 67
diff changeset
1353 if (flag_checking)
kono
parents: 67
diff changeset
1354 {
kono
parents: 67
diff changeset
1355 tree op = USE_FROM_PTR (op_p);
kono
parents: 67
diff changeset
1356 gcc_assert (!(for_propagation
kono
parents: 67
diff changeset
1357 && TREE_CODE (op) == SSA_NAME
kono
parents: 67
diff changeset
1358 && TREE_CODE (val) == SSA_NAME
kono
parents: 67
diff changeset
1359 && !may_propagate_copy (op, val)));
kono
parents: 67
diff changeset
1360 }
kono
parents: 67
diff changeset
1361
kono
parents: 67
diff changeset
1362 if (TREE_CODE (val) == SSA_NAME)
kono
parents: 67
diff changeset
1363 SET_USE (op_p, val);
kono
parents: 67
diff changeset
1364 else
kono
parents: 67
diff changeset
1365 SET_USE (op_p, unshare_expr (val));
kono
parents: 67
diff changeset
1366 }
kono
parents: 67
diff changeset
1367
kono
parents: 67
diff changeset
1368
kono
parents: 67
diff changeset
1369 /* Propagate the value VAL (assumed to be a constant or another SSA_NAME)
kono
parents: 67
diff changeset
1370 into the operand pointed to by OP_P.
kono
parents: 67
diff changeset
1371
kono
parents: 67
diff changeset
1372 Use this version for const/copy propagation as it will perform additional
kono
parents: 67
diff changeset
1373 checks to ensure validity of the const/copy propagation. */
kono
parents: 67
diff changeset
1374
kono
parents: 67
diff changeset
1375 void
kono
parents: 67
diff changeset
1376 propagate_value (use_operand_p op_p, tree val)
kono
parents: 67
diff changeset
1377 {
kono
parents: 67
diff changeset
1378 replace_exp_1 (op_p, val, true);
kono
parents: 67
diff changeset
1379 }
kono
parents: 67
diff changeset
1380
kono
parents: 67
diff changeset
1381 /* Replace *OP_P with value VAL (assumed to be a constant or another SSA_NAME).
kono
parents: 67
diff changeset
1382
kono
parents: 67
diff changeset
1383 Use this version when not const/copy propagating values. For example,
kono
parents: 67
diff changeset
1384 PRE uses this version when building expressions as they would appear
kono
parents: 67
diff changeset
1385 in specific blocks taking into account actions of PHI nodes.
kono
parents: 67
diff changeset
1386
kono
parents: 67
diff changeset
1387 The statement in which an expression has been replaced should be
kono
parents: 67
diff changeset
1388 folded using fold_stmt_inplace. */
kono
parents: 67
diff changeset
1389
kono
parents: 67
diff changeset
1390 void
kono
parents: 67
diff changeset
1391 replace_exp (use_operand_p op_p, tree val)
kono
parents: 67
diff changeset
1392 {
kono
parents: 67
diff changeset
1393 replace_exp_1 (op_p, val, false);
kono
parents: 67
diff changeset
1394 }
kono
parents: 67
diff changeset
1395
kono
parents: 67
diff changeset
1396
kono
parents: 67
diff changeset
1397 /* Propagate the value VAL (assumed to be a constant or another SSA_NAME)
kono
parents: 67
diff changeset
1398 into the tree pointed to by OP_P.
kono
parents: 67
diff changeset
1399
kono
parents: 67
diff changeset
1400 Use this version for const/copy propagation when SSA operands are not
kono
parents: 67
diff changeset
1401 available. It will perform the additional checks to ensure validity of
kono
parents: 67
diff changeset
1402 the const/copy propagation, but will not update any operand information.
kono
parents: 67
diff changeset
1403 Be sure to mark the stmt as modified. */
kono
parents: 67
diff changeset
1404
kono
parents: 67
diff changeset
1405 void
kono
parents: 67
diff changeset
1406 propagate_tree_value (tree *op_p, tree val)
kono
parents: 67
diff changeset
1407 {
kono
parents: 67
diff changeset
1408 if (TREE_CODE (val) == SSA_NAME)
kono
parents: 67
diff changeset
1409 *op_p = val;
kono
parents: 67
diff changeset
1410 else
kono
parents: 67
diff changeset
1411 *op_p = unshare_expr (val);
kono
parents: 67
diff changeset
1412 }
kono
parents: 67
diff changeset
1413
kono
parents: 67
diff changeset
1414
kono
parents: 67
diff changeset
1415 /* Like propagate_tree_value, but use as the operand to replace
kono
parents: 67
diff changeset
1416 the principal expression (typically, the RHS) contained in the
kono
parents: 67
diff changeset
1417 statement referenced by iterator GSI. Note that it is not
kono
parents: 67
diff changeset
1418 always possible to update the statement in-place, so a new
kono
parents: 67
diff changeset
1419 statement may be created to replace the original. */
kono
parents: 67
diff changeset
1420
kono
parents: 67
diff changeset
1421 void
kono
parents: 67
diff changeset
1422 propagate_tree_value_into_stmt (gimple_stmt_iterator *gsi, tree val)
kono
parents: 67
diff changeset
1423 {
kono
parents: 67
diff changeset
1424 gimple *stmt = gsi_stmt (*gsi);
kono
parents: 67
diff changeset
1425
kono
parents: 67
diff changeset
1426 if (is_gimple_assign (stmt))
kono
parents: 67
diff changeset
1427 {
kono
parents: 67
diff changeset
1428 tree expr = NULL_TREE;
kono
parents: 67
diff changeset
1429 if (gimple_assign_single_p (stmt))
kono
parents: 67
diff changeset
1430 expr = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
1431 propagate_tree_value (&expr, val);
kono
parents: 67
diff changeset
1432 gimple_assign_set_rhs_from_tree (gsi, expr);
kono
parents: 67
diff changeset
1433 }
kono
parents: 67
diff changeset
1434 else if (gcond *cond_stmt = dyn_cast <gcond *> (stmt))
kono
parents: 67
diff changeset
1435 {
kono
parents: 67
diff changeset
1436 tree lhs = NULL_TREE;
kono
parents: 67
diff changeset
1437 tree rhs = build_zero_cst (TREE_TYPE (val));
kono
parents: 67
diff changeset
1438 propagate_tree_value (&lhs, val);
kono
parents: 67
diff changeset
1439 gimple_cond_set_code (cond_stmt, NE_EXPR);
kono
parents: 67
diff changeset
1440 gimple_cond_set_lhs (cond_stmt, lhs);
kono
parents: 67
diff changeset
1441 gimple_cond_set_rhs (cond_stmt, rhs);
kono
parents: 67
diff changeset
1442 }
kono
parents: 67
diff changeset
1443 else if (is_gimple_call (stmt)
kono
parents: 67
diff changeset
1444 && gimple_call_lhs (stmt) != NULL_TREE)
kono
parents: 67
diff changeset
1445 {
kono
parents: 67
diff changeset
1446 tree expr = NULL_TREE;
kono
parents: 67
diff changeset
1447 bool res;
kono
parents: 67
diff changeset
1448 propagate_tree_value (&expr, val);
kono
parents: 67
diff changeset
1449 res = update_call_from_tree (gsi, expr);
kono
parents: 67
diff changeset
1450 gcc_assert (res);
kono
parents: 67
diff changeset
1451 }
kono
parents: 67
diff changeset
1452 else if (gswitch *swtch_stmt = dyn_cast <gswitch *> (stmt))
kono
parents: 67
diff changeset
1453 propagate_tree_value (gimple_switch_index_ptr (swtch_stmt), val);
kono
parents: 67
diff changeset
1454 else
kono
parents: 67
diff changeset
1455 gcc_unreachable ();
kono
parents: 67
diff changeset
1456 }