annotate gcc/tree-ssa-dse.c @ 127:4c56639505ff

fix function.c and add CbC-example Makefile
author mir3636
date Wed, 11 Apr 2018 18:46:58 +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 /* Dead store elimination
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 any later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 GNU General Public License for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "coretypes.h"
111
kono
parents: 67
diff changeset
23 #include "backend.h"
kono
parents: 67
diff changeset
24 #include "rtl.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 "tree-pass.h"
kono
parents: 67
diff changeset
28 #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
29 #include "gimple-pretty-print.h"
111
kono
parents: 67
diff changeset
30 #include "fold-const.h"
kono
parents: 67
diff changeset
31 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
32 #include "tree-cfg.h"
kono
parents: 67
diff changeset
33 #include "tree-dfa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 #include "domwalk.h"
111
kono
parents: 67
diff changeset
35 #include "tree-cfgcleanup.h"
kono
parents: 67
diff changeset
36 #include "params.h"
kono
parents: 67
diff changeset
37 #include "alias.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 /* This file implements dead store elimination.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 A dead store is a store into a memory location which will later be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 overwritten by another store without any intervening loads. In this
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 case the earlier store can be deleted.
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 In our SSA + virtual operand world we use immediate uses of virtual
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 operands to detect dead stores. If a store's virtual definition
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 is used precisely once by a later store to the same location which
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
48 post dominates the first store, then the first store is dead.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 The single use of the store's virtual definition ensures that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 there are no intervening aliased loads and the requirement that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 the second load post dominate the first ensures that if the earlier
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 store executes, then the later stores will execute before the function
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 exits.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 It may help to think of this as first moving the earlier store to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 the point immediately before the later store. Again, the single
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 use of the virtual definition and the post-dominance relationship
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
59 ensure that such movement would be safe. Clearly if there are
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 back to back stores, then the second is redundant.
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 Reviewing section 10.7.2 in Morgan's "Building an Optimizing Compiler"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 may also help in understanding this code since it discusses the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 relationship between dead store and redundant load elimination. In
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 fact, they are the same transformation applied to different views of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 the CFG. */
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
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
69 /* Bitmap of blocks that have had EH statements cleaned. We should
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
70 remove their dead edges eventually. */
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
71 static bitmap need_eh_cleanup;
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
72
111
kono
parents: 67
diff changeset
73 /* Return value from dse_classify_store */
kono
parents: 67
diff changeset
74 enum dse_store_status
kono
parents: 67
diff changeset
75 {
kono
parents: 67
diff changeset
76 DSE_STORE_LIVE,
kono
parents: 67
diff changeset
77 DSE_STORE_MAYBE_PARTIAL_DEAD,
kono
parents: 67
diff changeset
78 DSE_STORE_DEAD
kono
parents: 67
diff changeset
79 };
kono
parents: 67
diff changeset
80
kono
parents: 67
diff changeset
81 /* STMT is a statement that may write into memory. Analyze it and
kono
parents: 67
diff changeset
82 initialize WRITE to describe how STMT affects memory.
kono
parents: 67
diff changeset
83
kono
parents: 67
diff changeset
84 Return TRUE if the the statement was analyzed, FALSE otherwise.
kono
parents: 67
diff changeset
85
kono
parents: 67
diff changeset
86 It is always safe to return FALSE. But typically better optimziation
kono
parents: 67
diff changeset
87 can be achieved by analyzing more statements. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
111
kono
parents: 67
diff changeset
89 static bool
kono
parents: 67
diff changeset
90 initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 {
111
kono
parents: 67
diff changeset
92 /* It's advantageous to handle certain mem* functions. */
kono
parents: 67
diff changeset
93 if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
kono
parents: 67
diff changeset
94 {
kono
parents: 67
diff changeset
95 switch (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt)))
kono
parents: 67
diff changeset
96 {
kono
parents: 67
diff changeset
97 case BUILT_IN_MEMCPY:
kono
parents: 67
diff changeset
98 case BUILT_IN_MEMMOVE:
kono
parents: 67
diff changeset
99 case BUILT_IN_MEMSET:
kono
parents: 67
diff changeset
100 {
kono
parents: 67
diff changeset
101 tree size = NULL_TREE;
kono
parents: 67
diff changeset
102 if (gimple_call_num_args (stmt) == 3)
kono
parents: 67
diff changeset
103 size = gimple_call_arg (stmt, 2);
kono
parents: 67
diff changeset
104 tree ptr = gimple_call_arg (stmt, 0);
kono
parents: 67
diff changeset
105 ao_ref_init_from_ptr_and_size (write, ptr, size);
kono
parents: 67
diff changeset
106 return true;
kono
parents: 67
diff changeset
107 }
kono
parents: 67
diff changeset
108 default:
kono
parents: 67
diff changeset
109 break;
kono
parents: 67
diff changeset
110 }
kono
parents: 67
diff changeset
111 }
kono
parents: 67
diff changeset
112 else if (is_gimple_assign (stmt))
kono
parents: 67
diff changeset
113 {
kono
parents: 67
diff changeset
114 ao_ref_init (write, gimple_assign_lhs (stmt));
kono
parents: 67
diff changeset
115 return true;
kono
parents: 67
diff changeset
116 }
kono
parents: 67
diff changeset
117 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
111
kono
parents: 67
diff changeset
120 /* Given REF from the the alias oracle, return TRUE if it is a valid
kono
parents: 67
diff changeset
121 memory reference for dead store elimination, false otherwise.
kono
parents: 67
diff changeset
122
kono
parents: 67
diff changeset
123 In particular, the reference must have a known base, known maximum
kono
parents: 67
diff changeset
124 size, start at a byte offset and have a size that is one or more
kono
parents: 67
diff changeset
125 bytes. */
kono
parents: 67
diff changeset
126
kono
parents: 67
diff changeset
127 static bool
kono
parents: 67
diff changeset
128 valid_ao_ref_for_dse (ao_ref *ref)
kono
parents: 67
diff changeset
129 {
kono
parents: 67
diff changeset
130 return (ao_ref_base (ref)
kono
parents: 67
diff changeset
131 && ref->max_size != -1
kono
parents: 67
diff changeset
132 && ref->size != 0
kono
parents: 67
diff changeset
133 && ref->max_size == ref->size
kono
parents: 67
diff changeset
134 && ref->offset >= 0
kono
parents: 67
diff changeset
135 && (ref->offset % BITS_PER_UNIT) == 0
kono
parents: 67
diff changeset
136 && (ref->size % BITS_PER_UNIT) == 0
kono
parents: 67
diff changeset
137 && (ref->size != -1));
kono
parents: 67
diff changeset
138 }
kono
parents: 67
diff changeset
139
kono
parents: 67
diff changeset
140 /* Normalize COPY (an ao_ref) relative to REF. Essentially when we are
kono
parents: 67
diff changeset
141 done COPY will only refer bytes found within REF.
kono
parents: 67
diff changeset
142
kono
parents: 67
diff changeset
143 We have already verified that COPY intersects at least one
kono
parents: 67
diff changeset
144 byte with REF. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 static void
111
kono
parents: 67
diff changeset
147 normalize_ref (ao_ref *copy, ao_ref *ref)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 {
111
kono
parents: 67
diff changeset
149 /* If COPY starts before REF, then reset the beginning of
kono
parents: 67
diff changeset
150 COPY to match REF and decrease the size of COPY by the
kono
parents: 67
diff changeset
151 number of bytes removed from COPY. */
kono
parents: 67
diff changeset
152 if (copy->offset < ref->offset)
kono
parents: 67
diff changeset
153 {
kono
parents: 67
diff changeset
154 copy->size -= (ref->offset - copy->offset);
kono
parents: 67
diff changeset
155 copy->offset = ref->offset;
kono
parents: 67
diff changeset
156 }
kono
parents: 67
diff changeset
157
kono
parents: 67
diff changeset
158 /* If COPY extends beyond REF, chop off its size appropriately. */
kono
parents: 67
diff changeset
159 if (copy->offset + copy->size > ref->offset + ref->size)
kono
parents: 67
diff changeset
160 copy->size -= (copy->offset + copy->size - (ref->offset + ref->size));
kono
parents: 67
diff changeset
161 }
kono
parents: 67
diff changeset
162
kono
parents: 67
diff changeset
163 /* Clear any bytes written by STMT from the bitmap LIVE_BYTES. The base
kono
parents: 67
diff changeset
164 address written by STMT must match the one found in REF, which must
kono
parents: 67
diff changeset
165 have its base address previously initialized.
kono
parents: 67
diff changeset
166
kono
parents: 67
diff changeset
167 This routine must be conservative. If we don't know the offset or
kono
parents: 67
diff changeset
168 actual size written, assume nothing was written. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
111
kono
parents: 67
diff changeset
170 static void
kono
parents: 67
diff changeset
171 clear_bytes_written_by (sbitmap live_bytes, gimple *stmt, ao_ref *ref)
kono
parents: 67
diff changeset
172 {
kono
parents: 67
diff changeset
173 ao_ref write;
kono
parents: 67
diff changeset
174 if (!initialize_ao_ref_for_dse (stmt, &write))
kono
parents: 67
diff changeset
175 return;
kono
parents: 67
diff changeset
176
kono
parents: 67
diff changeset
177 /* Verify we have the same base memory address, the write
kono
parents: 67
diff changeset
178 has a known size and overlaps with REF. */
kono
parents: 67
diff changeset
179 if (valid_ao_ref_for_dse (&write)
kono
parents: 67
diff changeset
180 && operand_equal_p (write.base, ref->base, OEP_ADDRESS_OF)
kono
parents: 67
diff changeset
181 && write.size == write.max_size
kono
parents: 67
diff changeset
182 && ((write.offset < ref->offset
kono
parents: 67
diff changeset
183 && write.offset + write.size > ref->offset)
kono
parents: 67
diff changeset
184 || (write.offset >= ref->offset
kono
parents: 67
diff changeset
185 && write.offset < ref->offset + ref->size)))
kono
parents: 67
diff changeset
186 {
kono
parents: 67
diff changeset
187 normalize_ref (&write, ref);
kono
parents: 67
diff changeset
188 bitmap_clear_range (live_bytes,
kono
parents: 67
diff changeset
189 (write.offset - ref->offset) / BITS_PER_UNIT,
kono
parents: 67
diff changeset
190 write.size / BITS_PER_UNIT);
kono
parents: 67
diff changeset
191 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
111
kono
parents: 67
diff changeset
194 /* REF is a memory write. Extract relevant information from it and
kono
parents: 67
diff changeset
195 initialize the LIVE_BYTES bitmap. If successful, return TRUE.
kono
parents: 67
diff changeset
196 Otherwise return FALSE. */
kono
parents: 67
diff changeset
197
kono
parents: 67
diff changeset
198 static bool
kono
parents: 67
diff changeset
199 setup_live_bytes_from_ref (ao_ref *ref, sbitmap live_bytes)
kono
parents: 67
diff changeset
200 {
kono
parents: 67
diff changeset
201 if (valid_ao_ref_for_dse (ref)
kono
parents: 67
diff changeset
202 && (ref->size / BITS_PER_UNIT
kono
parents: 67
diff changeset
203 <= PARAM_VALUE (PARAM_DSE_MAX_OBJECT_SIZE)))
kono
parents: 67
diff changeset
204 {
kono
parents: 67
diff changeset
205 bitmap_clear (live_bytes);
kono
parents: 67
diff changeset
206 bitmap_set_range (live_bytes, 0, ref->size / BITS_PER_UNIT);
kono
parents: 67
diff changeset
207 return true;
kono
parents: 67
diff changeset
208 }
kono
parents: 67
diff changeset
209 return false;
kono
parents: 67
diff changeset
210 }
kono
parents: 67
diff changeset
211
kono
parents: 67
diff changeset
212 /* Compute the number of elements that we can trim from the head and
kono
parents: 67
diff changeset
213 tail of ORIG resulting in a bitmap that is a superset of LIVE.
kono
parents: 67
diff changeset
214
kono
parents: 67
diff changeset
215 Store the number of elements trimmed from the head and tail in
kono
parents: 67
diff changeset
216 TRIM_HEAD and TRIM_TAIL.
kono
parents: 67
diff changeset
217
kono
parents: 67
diff changeset
218 STMT is the statement being trimmed and is used for debugging dump
kono
parents: 67
diff changeset
219 output only. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 static void
111
kono
parents: 67
diff changeset
222 compute_trims (ao_ref *ref, sbitmap live, int *trim_head, int *trim_tail,
kono
parents: 67
diff changeset
223 gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 {
111
kono
parents: 67
diff changeset
225 /* We use sbitmaps biased such that ref->offset is bit zero and the bitmap
kono
parents: 67
diff changeset
226 extends through ref->size. So we know that in the original bitmap
kono
parents: 67
diff changeset
227 bits 0..ref->size were true. We don't actually need the bitmap, just
kono
parents: 67
diff changeset
228 the REF to compute the trims. */
kono
parents: 67
diff changeset
229
kono
parents: 67
diff changeset
230 /* Now identify how much, if any of the tail we can chop off. */
kono
parents: 67
diff changeset
231 int last_orig = (ref->size / BITS_PER_UNIT) - 1;
kono
parents: 67
diff changeset
232 int last_live = bitmap_last_set_bit (live);
kono
parents: 67
diff changeset
233 *trim_tail = (last_orig - last_live) & ~0x1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234
111
kono
parents: 67
diff changeset
235 /* Identify how much, if any of the head we can chop off. */
kono
parents: 67
diff changeset
236 int first_orig = 0;
kono
parents: 67
diff changeset
237 int first_live = bitmap_first_set_bit (live);
kono
parents: 67
diff changeset
238 *trim_head = (first_live - first_orig) & ~0x1;
kono
parents: 67
diff changeset
239
kono
parents: 67
diff changeset
240 if ((*trim_head || *trim_tail)
kono
parents: 67
diff changeset
241 && dump_file && (dump_flags & TDF_DETAILS))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 {
111
kono
parents: 67
diff changeset
243 fprintf (dump_file, " Trimming statement (head = %d, tail = %d): ",
kono
parents: 67
diff changeset
244 *trim_head, *trim_tail);
kono
parents: 67
diff changeset
245 print_gimple_stmt (dump_file, stmt, 0, dump_flags);
kono
parents: 67
diff changeset
246 fprintf (dump_file, "\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249
111
kono
parents: 67
diff changeset
250 /* STMT initializes an object from COMPLEX_CST where one or more of the
kono
parents: 67
diff changeset
251 bytes written may be dead stores. REF is a representation of the
kono
parents: 67
diff changeset
252 memory written. LIVE is the bitmap of stores that are actually live.
kono
parents: 67
diff changeset
253
kono
parents: 67
diff changeset
254 Attempt to rewrite STMT so that only the real or imaginary part of
kono
parents: 67
diff changeset
255 the object is actually stored. */
kono
parents: 67
diff changeset
256
kono
parents: 67
diff changeset
257 static void
kono
parents: 67
diff changeset
258 maybe_trim_complex_store (ao_ref *ref, sbitmap live, gimple *stmt)
kono
parents: 67
diff changeset
259 {
kono
parents: 67
diff changeset
260 int trim_head, trim_tail;
kono
parents: 67
diff changeset
261 compute_trims (ref, live, &trim_head, &trim_tail, stmt);
kono
parents: 67
diff changeset
262
kono
parents: 67
diff changeset
263 /* The amount of data trimmed from the head or tail must be at
kono
parents: 67
diff changeset
264 least half the size of the object to ensure we're trimming
kono
parents: 67
diff changeset
265 the entire real or imaginary half. By writing things this
kono
parents: 67
diff changeset
266 way we avoid more O(n) bitmap operations. */
kono
parents: 67
diff changeset
267 if (trim_tail * 2 >= ref->size / BITS_PER_UNIT)
kono
parents: 67
diff changeset
268 {
kono
parents: 67
diff changeset
269 /* TREE_REALPART is live */
kono
parents: 67
diff changeset
270 tree x = TREE_REALPART (gimple_assign_rhs1 (stmt));
kono
parents: 67
diff changeset
271 tree y = gimple_assign_lhs (stmt);
kono
parents: 67
diff changeset
272 y = build1 (REALPART_EXPR, TREE_TYPE (x), y);
kono
parents: 67
diff changeset
273 gimple_assign_set_lhs (stmt, y);
kono
parents: 67
diff changeset
274 gimple_assign_set_rhs1 (stmt, x);
kono
parents: 67
diff changeset
275 }
kono
parents: 67
diff changeset
276 else if (trim_head * 2 >= ref->size / BITS_PER_UNIT)
kono
parents: 67
diff changeset
277 {
kono
parents: 67
diff changeset
278 /* TREE_IMAGPART is live */
kono
parents: 67
diff changeset
279 tree x = TREE_IMAGPART (gimple_assign_rhs1 (stmt));
kono
parents: 67
diff changeset
280 tree y = gimple_assign_lhs (stmt);
kono
parents: 67
diff changeset
281 y = build1 (IMAGPART_EXPR, TREE_TYPE (x), y);
kono
parents: 67
diff changeset
282 gimple_assign_set_lhs (stmt, y);
kono
parents: 67
diff changeset
283 gimple_assign_set_rhs1 (stmt, x);
kono
parents: 67
diff changeset
284 }
kono
parents: 67
diff changeset
285
kono
parents: 67
diff changeset
286 /* Other cases indicate parts of both the real and imag subobjects
kono
parents: 67
diff changeset
287 are live. We do not try to optimize those cases. */
kono
parents: 67
diff changeset
288 }
kono
parents: 67
diff changeset
289
kono
parents: 67
diff changeset
290 /* STMT initializes an object using a CONSTRUCTOR where one or more of the
kono
parents: 67
diff changeset
291 bytes written are dead stores. ORIG is the bitmap of bytes stored by
kono
parents: 67
diff changeset
292 STMT. LIVE is the bitmap of stores that are actually live.
kono
parents: 67
diff changeset
293
kono
parents: 67
diff changeset
294 Attempt to rewrite STMT so that only the real or imaginary part of
kono
parents: 67
diff changeset
295 the object is actually stored.
kono
parents: 67
diff changeset
296
kono
parents: 67
diff changeset
297 The most common case for getting here is a CONSTRUCTOR with no elements
kono
parents: 67
diff changeset
298 being used to zero initialize an object. We do not try to handle other
kono
parents: 67
diff changeset
299 cases as those would force us to fully cover the object with the
kono
parents: 67
diff changeset
300 CONSTRUCTOR node except for the components that are dead. */
kono
parents: 67
diff changeset
301
kono
parents: 67
diff changeset
302 static void
kono
parents: 67
diff changeset
303 maybe_trim_constructor_store (ao_ref *ref, sbitmap live, gimple *stmt)
kono
parents: 67
diff changeset
304 {
kono
parents: 67
diff changeset
305 tree ctor = gimple_assign_rhs1 (stmt);
kono
parents: 67
diff changeset
306
kono
parents: 67
diff changeset
307 /* This is the only case we currently handle. It actually seems to
kono
parents: 67
diff changeset
308 catch most cases of actual interest. */
kono
parents: 67
diff changeset
309 gcc_assert (CONSTRUCTOR_NELTS (ctor) == 0);
kono
parents: 67
diff changeset
310
kono
parents: 67
diff changeset
311 int head_trim = 0;
kono
parents: 67
diff changeset
312 int tail_trim = 0;
kono
parents: 67
diff changeset
313 compute_trims (ref, live, &head_trim, &tail_trim, stmt);
kono
parents: 67
diff changeset
314
kono
parents: 67
diff changeset
315 /* Now we want to replace the constructor initializer
kono
parents: 67
diff changeset
316 with memset (object + head_trim, 0, size - head_trim - tail_trim). */
kono
parents: 67
diff changeset
317 if (head_trim || tail_trim)
kono
parents: 67
diff changeset
318 {
kono
parents: 67
diff changeset
319 /* We want &lhs for the MEM_REF expression. */
kono
parents: 67
diff changeset
320 tree lhs_addr = build_fold_addr_expr (gimple_assign_lhs (stmt));
kono
parents: 67
diff changeset
321
kono
parents: 67
diff changeset
322 if (! is_gimple_min_invariant (lhs_addr))
kono
parents: 67
diff changeset
323 return;
kono
parents: 67
diff changeset
324
kono
parents: 67
diff changeset
325 /* The number of bytes for the new constructor. */
kono
parents: 67
diff changeset
326 int count = (ref->size / BITS_PER_UNIT) - head_trim - tail_trim;
kono
parents: 67
diff changeset
327
kono
parents: 67
diff changeset
328 /* And the new type for the CONSTRUCTOR. Essentially it's just
kono
parents: 67
diff changeset
329 a char array large enough to cover the non-trimmed parts of
kono
parents: 67
diff changeset
330 the original CONSTRUCTOR. Note we want explicit bounds here
kono
parents: 67
diff changeset
331 so that we know how many bytes to clear when expanding the
kono
parents: 67
diff changeset
332 CONSTRUCTOR. */
kono
parents: 67
diff changeset
333 tree type = build_array_type_nelts (char_type_node, count);
kono
parents: 67
diff changeset
334
kono
parents: 67
diff changeset
335 /* Build a suitable alias type rather than using alias set zero
kono
parents: 67
diff changeset
336 to avoid pessimizing. */
kono
parents: 67
diff changeset
337 tree alias_type = reference_alias_ptr_type (gimple_assign_lhs (stmt));
kono
parents: 67
diff changeset
338
kono
parents: 67
diff changeset
339 /* Build a MEM_REF representing the whole accessed area, starting
kono
parents: 67
diff changeset
340 at the first byte not trimmed. */
kono
parents: 67
diff changeset
341 tree exp = fold_build2 (MEM_REF, type, lhs_addr,
kono
parents: 67
diff changeset
342 build_int_cst (alias_type, head_trim));
kono
parents: 67
diff changeset
343
kono
parents: 67
diff changeset
344 /* Now update STMT with a new RHS and LHS. */
kono
parents: 67
diff changeset
345 gimple_assign_set_lhs (stmt, exp);
kono
parents: 67
diff changeset
346 gimple_assign_set_rhs1 (stmt, build_constructor (type, NULL));
kono
parents: 67
diff changeset
347 }
kono
parents: 67
diff changeset
348 }
kono
parents: 67
diff changeset
349
kono
parents: 67
diff changeset
350 /* STMT is a memcpy, memmove or memset. Decrement the number of bytes
kono
parents: 67
diff changeset
351 copied/set by DECREMENT. */
kono
parents: 67
diff changeset
352 static void
kono
parents: 67
diff changeset
353 decrement_count (gimple *stmt, int decrement)
kono
parents: 67
diff changeset
354 {
kono
parents: 67
diff changeset
355 tree *countp = gimple_call_arg_ptr (stmt, 2);
kono
parents: 67
diff changeset
356 gcc_assert (TREE_CODE (*countp) == INTEGER_CST);
kono
parents: 67
diff changeset
357 *countp = wide_int_to_tree (TREE_TYPE (*countp), (TREE_INT_CST_LOW (*countp)
kono
parents: 67
diff changeset
358 - decrement));
kono
parents: 67
diff changeset
359
kono
parents: 67
diff changeset
360 }
kono
parents: 67
diff changeset
361
kono
parents: 67
diff changeset
362 static void
kono
parents: 67
diff changeset
363 increment_start_addr (gimple *stmt, tree *where, int increment)
kono
parents: 67
diff changeset
364 {
kono
parents: 67
diff changeset
365 if (TREE_CODE (*where) == SSA_NAME)
kono
parents: 67
diff changeset
366 {
kono
parents: 67
diff changeset
367 tree tem = make_ssa_name (TREE_TYPE (*where));
kono
parents: 67
diff changeset
368 gassign *newop
kono
parents: 67
diff changeset
369 = gimple_build_assign (tem, POINTER_PLUS_EXPR, *where,
kono
parents: 67
diff changeset
370 build_int_cst (sizetype, increment));
kono
parents: 67
diff changeset
371 gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
kono
parents: 67
diff changeset
372 gsi_insert_before (&gsi, newop, GSI_SAME_STMT);
kono
parents: 67
diff changeset
373 *where = tem;
kono
parents: 67
diff changeset
374 update_stmt (gsi_stmt (gsi));
kono
parents: 67
diff changeset
375 return;
kono
parents: 67
diff changeset
376 }
kono
parents: 67
diff changeset
377
kono
parents: 67
diff changeset
378 *where = build_fold_addr_expr (fold_build2 (MEM_REF, char_type_node,
kono
parents: 67
diff changeset
379 *where,
kono
parents: 67
diff changeset
380 build_int_cst (ptr_type_node,
kono
parents: 67
diff changeset
381 increment)));
kono
parents: 67
diff changeset
382 }
kono
parents: 67
diff changeset
383
kono
parents: 67
diff changeset
384 /* STMT is builtin call that writes bytes in bitmap ORIG, some bytes are dead
kono
parents: 67
diff changeset
385 (ORIG & ~NEW) and need not be stored. Try to rewrite STMT to reduce
kono
parents: 67
diff changeset
386 the amount of data it actually writes.
kono
parents: 67
diff changeset
387
kono
parents: 67
diff changeset
388 Right now we only support trimming from the head or the tail of the
kono
parents: 67
diff changeset
389 memory region. In theory we could split the mem* call, but it's
kono
parents: 67
diff changeset
390 likely of marginal value. */
kono
parents: 67
diff changeset
391
kono
parents: 67
diff changeset
392 static void
kono
parents: 67
diff changeset
393 maybe_trim_memstar_call (ao_ref *ref, sbitmap live, gimple *stmt)
kono
parents: 67
diff changeset
394 {
kono
parents: 67
diff changeset
395 switch (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt)))
kono
parents: 67
diff changeset
396 {
kono
parents: 67
diff changeset
397 case BUILT_IN_MEMCPY:
kono
parents: 67
diff changeset
398 case BUILT_IN_MEMMOVE:
kono
parents: 67
diff changeset
399 {
kono
parents: 67
diff changeset
400 int head_trim, tail_trim;
kono
parents: 67
diff changeset
401 compute_trims (ref, live, &head_trim, &tail_trim, stmt);
kono
parents: 67
diff changeset
402
kono
parents: 67
diff changeset
403 /* Tail trimming is easy, we can just reduce the count. */
kono
parents: 67
diff changeset
404 if (tail_trim)
kono
parents: 67
diff changeset
405 decrement_count (stmt, tail_trim);
kono
parents: 67
diff changeset
406
kono
parents: 67
diff changeset
407 /* Head trimming requires adjusting all the arguments. */
kono
parents: 67
diff changeset
408 if (head_trim)
kono
parents: 67
diff changeset
409 {
kono
parents: 67
diff changeset
410 tree *dst = gimple_call_arg_ptr (stmt, 0);
kono
parents: 67
diff changeset
411 increment_start_addr (stmt, dst, head_trim);
kono
parents: 67
diff changeset
412 tree *src = gimple_call_arg_ptr (stmt, 1);
kono
parents: 67
diff changeset
413 increment_start_addr (stmt, src, head_trim);
kono
parents: 67
diff changeset
414 decrement_count (stmt, head_trim);
kono
parents: 67
diff changeset
415 }
kono
parents: 67
diff changeset
416 break;
kono
parents: 67
diff changeset
417 }
kono
parents: 67
diff changeset
418
kono
parents: 67
diff changeset
419 case BUILT_IN_MEMSET:
kono
parents: 67
diff changeset
420 {
kono
parents: 67
diff changeset
421 int head_trim, tail_trim;
kono
parents: 67
diff changeset
422 compute_trims (ref, live, &head_trim, &tail_trim, stmt);
kono
parents: 67
diff changeset
423
kono
parents: 67
diff changeset
424 /* Tail trimming is easy, we can just reduce the count. */
kono
parents: 67
diff changeset
425 if (tail_trim)
kono
parents: 67
diff changeset
426 decrement_count (stmt, tail_trim);
kono
parents: 67
diff changeset
427
kono
parents: 67
diff changeset
428 /* Head trimming requires adjusting all the arguments. */
kono
parents: 67
diff changeset
429 if (head_trim)
kono
parents: 67
diff changeset
430 {
kono
parents: 67
diff changeset
431 tree *dst = gimple_call_arg_ptr (stmt, 0);
kono
parents: 67
diff changeset
432 increment_start_addr (stmt, dst, head_trim);
kono
parents: 67
diff changeset
433 decrement_count (stmt, head_trim);
kono
parents: 67
diff changeset
434 }
kono
parents: 67
diff changeset
435 break;
kono
parents: 67
diff changeset
436 }
kono
parents: 67
diff changeset
437
kono
parents: 67
diff changeset
438 default:
kono
parents: 67
diff changeset
439 break;
kono
parents: 67
diff changeset
440 }
kono
parents: 67
diff changeset
441 }
kono
parents: 67
diff changeset
442
kono
parents: 67
diff changeset
443 /* STMT is a memory write where one or more bytes written are dead
kono
parents: 67
diff changeset
444 stores. ORIG is the bitmap of bytes stored by STMT. LIVE is the
kono
parents: 67
diff changeset
445 bitmap of stores that are actually live.
kono
parents: 67
diff changeset
446
kono
parents: 67
diff changeset
447 Attempt to rewrite STMT so that it writes fewer memory locations. Right
kono
parents: 67
diff changeset
448 now we only support trimming at the start or end of the memory region.
kono
parents: 67
diff changeset
449 It's not clear how much there is to be gained by trimming from the middle
kono
parents: 67
diff changeset
450 of the region. */
kono
parents: 67
diff changeset
451
kono
parents: 67
diff changeset
452 static void
kono
parents: 67
diff changeset
453 maybe_trim_partially_dead_store (ao_ref *ref, sbitmap live, gimple *stmt)
kono
parents: 67
diff changeset
454 {
kono
parents: 67
diff changeset
455 if (is_gimple_assign (stmt)
kono
parents: 67
diff changeset
456 && TREE_CODE (gimple_assign_lhs (stmt)) != TARGET_MEM_REF)
kono
parents: 67
diff changeset
457 {
kono
parents: 67
diff changeset
458 switch (gimple_assign_rhs_code (stmt))
kono
parents: 67
diff changeset
459 {
kono
parents: 67
diff changeset
460 case CONSTRUCTOR:
kono
parents: 67
diff changeset
461 maybe_trim_constructor_store (ref, live, stmt);
kono
parents: 67
diff changeset
462 break;
kono
parents: 67
diff changeset
463 case COMPLEX_CST:
kono
parents: 67
diff changeset
464 maybe_trim_complex_store (ref, live, stmt);
kono
parents: 67
diff changeset
465 break;
kono
parents: 67
diff changeset
466 default:
kono
parents: 67
diff changeset
467 break;
kono
parents: 67
diff changeset
468 }
kono
parents: 67
diff changeset
469 }
kono
parents: 67
diff changeset
470 }
kono
parents: 67
diff changeset
471
kono
parents: 67
diff changeset
472 /* Return TRUE if USE_REF reads bytes from LIVE where live is
kono
parents: 67
diff changeset
473 derived from REF, a write reference.
kono
parents: 67
diff changeset
474
kono
parents: 67
diff changeset
475 While this routine may modify USE_REF, it's passed by value, not
kono
parents: 67
diff changeset
476 location. So callers do not see those modifications. */
kono
parents: 67
diff changeset
477
kono
parents: 67
diff changeset
478 static bool
kono
parents: 67
diff changeset
479 live_bytes_read (ao_ref use_ref, ao_ref *ref, sbitmap live)
kono
parents: 67
diff changeset
480 {
kono
parents: 67
diff changeset
481 /* We have already verified that USE_REF and REF hit the same object.
kono
parents: 67
diff changeset
482 Now verify that there's actually an overlap between USE_REF and REF. */
kono
parents: 67
diff changeset
483 if (ranges_overlap_p (use_ref.offset, use_ref.size, ref->offset, ref->size))
kono
parents: 67
diff changeset
484 {
kono
parents: 67
diff changeset
485 normalize_ref (&use_ref, ref);
kono
parents: 67
diff changeset
486
kono
parents: 67
diff changeset
487 /* If USE_REF covers all of REF, then it will hit one or more
kono
parents: 67
diff changeset
488 live bytes. This avoids useless iteration over the bitmap
kono
parents: 67
diff changeset
489 below. */
kono
parents: 67
diff changeset
490 if (use_ref.offset <= ref->offset
kono
parents: 67
diff changeset
491 && use_ref.offset + use_ref.size >= ref->offset + ref->size)
kono
parents: 67
diff changeset
492 return true;
kono
parents: 67
diff changeset
493
kono
parents: 67
diff changeset
494 /* Now check if any of the remaining bits in use_ref are set in LIVE. */
kono
parents: 67
diff changeset
495 unsigned int start = (use_ref.offset - ref->offset) / BITS_PER_UNIT;
kono
parents: 67
diff changeset
496 unsigned int end = start + (use_ref.size / BITS_PER_UNIT) - 1;
kono
parents: 67
diff changeset
497 return bitmap_bit_in_range_p (live, start, end);
kono
parents: 67
diff changeset
498 }
kono
parents: 67
diff changeset
499 return true;
kono
parents: 67
diff changeset
500 }
kono
parents: 67
diff changeset
501
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 /* A helper of dse_optimize_stmt.
111
kono
parents: 67
diff changeset
503 Given a GIMPLE_ASSIGN in STMT that writes to REF, find a candidate
kono
parents: 67
diff changeset
504 statement *USE_STMT that may prove STMT to be dead.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 Return TRUE if the above conditions are met, otherwise FALSE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506
111
kono
parents: 67
diff changeset
507 static dse_store_status
kono
parents: 67
diff changeset
508 dse_classify_store (ao_ref *ref, gimple *stmt, gimple **use_stmt,
kono
parents: 67
diff changeset
509 bool byte_tracking_enabled, sbitmap live_bytes)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 {
111
kono
parents: 67
diff changeset
511 gimple *temp;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
512 unsigned cnt = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
513
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
514 *use_stmt = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
516 /* Find the first dominated statement that clobbers (part of) the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
517 memory stmt stores to with no intermediate statement that may use
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
518 part of the memory stmt stores. That is, find a store that may
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
519 prove stmt to be a dead store. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
520 temp = stmt;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
521 do
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 {
111
kono
parents: 67
diff changeset
523 gimple *use_stmt, *defvar_def;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
524 imm_use_iterator ui;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
525 bool fail = false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
526 tree defvar;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
528 /* Limit stmt walking to be linear in the number of possibly
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
529 dead stores. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
530 if (++cnt > 256)
111
kono
parents: 67
diff changeset
531 return DSE_STORE_LIVE;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 if (gimple_code (temp) == GIMPLE_PHI)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
534 defvar = PHI_RESULT (temp);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
535 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
536 defvar = gimple_vdef (temp);
111
kono
parents: 67
diff changeset
537 defvar_def = temp;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
538 temp = NULL;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
539 FOR_EACH_IMM_USE_STMT (use_stmt, ui, defvar)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
541 cnt++;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
543 /* If we ever reach our DSE candidate stmt again fail. We
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
544 cannot handle dead stores in loops. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
545 if (use_stmt == stmt)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
546 {
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
547 fail = true;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
548 BREAK_FROM_IMM_USE_STMT (ui);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
549 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
550 /* In simple cases we can look through PHI nodes, but we
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
551 have to be careful with loops and with memory references
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
552 containing operands that are also operands of PHI nodes.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
553 See gcc.c-torture/execute/20051110-*.c. */
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
554 else if (gimple_code (use_stmt) == GIMPLE_PHI)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
555 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
556 if (temp
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
557 /* Make sure we are not in a loop latch block. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
558 || gimple_bb (stmt) == gimple_bb (use_stmt)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
559 || dominated_by_p (CDI_DOMINATORS,
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
560 gimple_bb (stmt), gimple_bb (use_stmt))
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
561 /* We can look through PHIs to regions post-dominating
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
562 the DSE candidate stmt. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
563 || !dominated_by_p (CDI_POST_DOMINATORS,
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
564 gimple_bb (stmt), gimple_bb (use_stmt)))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
565 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
566 fail = true;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
567 BREAK_FROM_IMM_USE_STMT (ui);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
568 }
111
kono
parents: 67
diff changeset
569 /* Do not consider the PHI as use if it dominates the
kono
parents: 67
diff changeset
570 stmt defining the virtual operand we are processing,
kono
parents: 67
diff changeset
571 we have processed it already in this case. */
kono
parents: 67
diff changeset
572 if (gimple_bb (defvar_def) != gimple_bb (use_stmt)
kono
parents: 67
diff changeset
573 && !dominated_by_p (CDI_DOMINATORS,
kono
parents: 67
diff changeset
574 gimple_bb (defvar_def),
kono
parents: 67
diff changeset
575 gimple_bb (use_stmt)))
kono
parents: 67
diff changeset
576 temp = use_stmt;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
577 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
578 /* If the statement is a use the store is not dead. */
111
kono
parents: 67
diff changeset
579 else if (ref_maybe_used_by_stmt_p (use_stmt, ref))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 {
111
kono
parents: 67
diff changeset
581 /* Handle common cases where we can easily build an ao_ref
kono
parents: 67
diff changeset
582 structure for USE_STMT and in doing so we find that the
kono
parents: 67
diff changeset
583 references hit non-live bytes and thus can be ignored. */
kono
parents: 67
diff changeset
584 if (byte_tracking_enabled && (!gimple_vdef (use_stmt) || !temp))
kono
parents: 67
diff changeset
585 {
kono
parents: 67
diff changeset
586 if (is_gimple_assign (use_stmt))
kono
parents: 67
diff changeset
587 {
kono
parents: 67
diff changeset
588 /* Other cases were noted as non-aliasing by
kono
parents: 67
diff changeset
589 the call to ref_maybe_used_by_stmt_p. */
kono
parents: 67
diff changeset
590 ao_ref use_ref;
kono
parents: 67
diff changeset
591 ao_ref_init (&use_ref, gimple_assign_rhs1 (use_stmt));
kono
parents: 67
diff changeset
592 if (valid_ao_ref_for_dse (&use_ref)
kono
parents: 67
diff changeset
593 && use_ref.base == ref->base
kono
parents: 67
diff changeset
594 && use_ref.size == use_ref.max_size
kono
parents: 67
diff changeset
595 && !live_bytes_read (use_ref, ref, live_bytes))
kono
parents: 67
diff changeset
596 {
kono
parents: 67
diff changeset
597 /* If this statement has a VDEF, then it is the
kono
parents: 67
diff changeset
598 first store we have seen, so walk through it. */
kono
parents: 67
diff changeset
599 if (gimple_vdef (use_stmt))
kono
parents: 67
diff changeset
600 temp = use_stmt;
kono
parents: 67
diff changeset
601 continue;
kono
parents: 67
diff changeset
602 }
kono
parents: 67
diff changeset
603 }
kono
parents: 67
diff changeset
604 }
kono
parents: 67
diff changeset
605
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 fail = true;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
607 BREAK_FROM_IMM_USE_STMT (ui);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
608 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
609 /* If this is a store, remember it or bail out if we have
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
610 multiple ones (the will be in different CFG parts then). */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
611 else if (gimple_vdef (use_stmt))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
612 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
613 if (temp)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
614 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
615 fail = true;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
616 BREAK_FROM_IMM_USE_STMT (ui);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
617 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
618 temp = use_stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
622 if (fail)
111
kono
parents: 67
diff changeset
623 {
kono
parents: 67
diff changeset
624 /* STMT might be partially dead and we may be able to reduce
kono
parents: 67
diff changeset
625 how many memory locations it stores into. */
kono
parents: 67
diff changeset
626 if (byte_tracking_enabled && !gimple_clobber_p (stmt))
kono
parents: 67
diff changeset
627 return DSE_STORE_MAYBE_PARTIAL_DEAD;
kono
parents: 67
diff changeset
628 return DSE_STORE_LIVE;
kono
parents: 67
diff changeset
629 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
630
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
631 /* If we didn't find any definition this means the store is dead
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
632 if it isn't a store to global reachable memory. In this case
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
633 just pretend the stmt makes itself dead. Otherwise fail. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
634 if (!temp)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 {
111
kono
parents: 67
diff changeset
636 if (ref_may_alias_global_p (ref))
kono
parents: 67
diff changeset
637 return DSE_STORE_LIVE;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
638
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
639 temp = stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 }
111
kono
parents: 67
diff changeset
642
kono
parents: 67
diff changeset
643 if (byte_tracking_enabled && temp)
kono
parents: 67
diff changeset
644 clear_bytes_written_by (live_bytes, temp, ref);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 }
111
kono
parents: 67
diff changeset
646 /* Continue walking until we reach a full kill as a single statement
kono
parents: 67
diff changeset
647 or there are no more live bytes. */
kono
parents: 67
diff changeset
648 while (!stmt_kills_ref_p (temp, ref)
kono
parents: 67
diff changeset
649 && !(byte_tracking_enabled && bitmap_empty_p (live_bytes)));
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
650
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
651 *use_stmt = temp;
111
kono
parents: 67
diff changeset
652 return DSE_STORE_DEAD;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655
111
kono
parents: 67
diff changeset
656 class dse_dom_walker : public dom_walker
kono
parents: 67
diff changeset
657 {
kono
parents: 67
diff changeset
658 public:
kono
parents: 67
diff changeset
659 dse_dom_walker (cdi_direction direction)
kono
parents: 67
diff changeset
660 : dom_walker (direction),
kono
parents: 67
diff changeset
661 m_live_bytes (PARAM_VALUE (PARAM_DSE_MAX_OBJECT_SIZE)),
kono
parents: 67
diff changeset
662 m_byte_tracking_enabled (false) {}
kono
parents: 67
diff changeset
663
kono
parents: 67
diff changeset
664 virtual edge before_dom_children (basic_block);
kono
parents: 67
diff changeset
665
kono
parents: 67
diff changeset
666 private:
kono
parents: 67
diff changeset
667 auto_sbitmap m_live_bytes;
kono
parents: 67
diff changeset
668 bool m_byte_tracking_enabled;
kono
parents: 67
diff changeset
669 void dse_optimize_stmt (gimple_stmt_iterator *);
kono
parents: 67
diff changeset
670 };
kono
parents: 67
diff changeset
671
kono
parents: 67
diff changeset
672 /* Delete a dead call at GSI, which is mem* call of some kind. */
kono
parents: 67
diff changeset
673 static void
kono
parents: 67
diff changeset
674 delete_dead_call (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
675 {
kono
parents: 67
diff changeset
676 gimple *stmt = gsi_stmt (*gsi);
kono
parents: 67
diff changeset
677 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
678 {
kono
parents: 67
diff changeset
679 fprintf (dump_file, " Deleted dead call: ");
kono
parents: 67
diff changeset
680 print_gimple_stmt (dump_file, stmt, 0, dump_flags);
kono
parents: 67
diff changeset
681 fprintf (dump_file, "\n");
kono
parents: 67
diff changeset
682 }
kono
parents: 67
diff changeset
683
kono
parents: 67
diff changeset
684 tree lhs = gimple_call_lhs (stmt);
kono
parents: 67
diff changeset
685 if (lhs)
kono
parents: 67
diff changeset
686 {
kono
parents: 67
diff changeset
687 tree ptr = gimple_call_arg (stmt, 0);
kono
parents: 67
diff changeset
688 gimple *new_stmt = gimple_build_assign (lhs, ptr);
kono
parents: 67
diff changeset
689 unlink_stmt_vdef (stmt);
kono
parents: 67
diff changeset
690 if (gsi_replace (gsi, new_stmt, true))
kono
parents: 67
diff changeset
691 bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
kono
parents: 67
diff changeset
692 }
kono
parents: 67
diff changeset
693 else
kono
parents: 67
diff changeset
694 {
kono
parents: 67
diff changeset
695 /* Then we need to fix the operand of the consuming stmt. */
kono
parents: 67
diff changeset
696 unlink_stmt_vdef (stmt);
kono
parents: 67
diff changeset
697
kono
parents: 67
diff changeset
698 /* Remove the dead store. */
kono
parents: 67
diff changeset
699 if (gsi_remove (gsi, true))
kono
parents: 67
diff changeset
700 bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
kono
parents: 67
diff changeset
701 release_defs (stmt);
kono
parents: 67
diff changeset
702 }
kono
parents: 67
diff changeset
703 }
kono
parents: 67
diff changeset
704
kono
parents: 67
diff changeset
705 /* Delete a dead store at GSI, which is a gimple assignment. */
kono
parents: 67
diff changeset
706
kono
parents: 67
diff changeset
707 static void
kono
parents: 67
diff changeset
708 delete_dead_assignment (gimple_stmt_iterator *gsi)
kono
parents: 67
diff changeset
709 {
kono
parents: 67
diff changeset
710 gimple *stmt = gsi_stmt (*gsi);
kono
parents: 67
diff changeset
711 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
712 {
kono
parents: 67
diff changeset
713 fprintf (dump_file, " Deleted dead store: ");
kono
parents: 67
diff changeset
714 print_gimple_stmt (dump_file, stmt, 0, dump_flags);
kono
parents: 67
diff changeset
715 fprintf (dump_file, "\n");
kono
parents: 67
diff changeset
716 }
kono
parents: 67
diff changeset
717
kono
parents: 67
diff changeset
718 /* Then we need to fix the operand of the consuming stmt. */
kono
parents: 67
diff changeset
719 unlink_stmt_vdef (stmt);
kono
parents: 67
diff changeset
720
kono
parents: 67
diff changeset
721 /* Remove the dead store. */
kono
parents: 67
diff changeset
722 basic_block bb = gimple_bb (stmt);
kono
parents: 67
diff changeset
723 if (gsi_remove (gsi, true))
kono
parents: 67
diff changeset
724 bitmap_set_bit (need_eh_cleanup, bb->index);
kono
parents: 67
diff changeset
725
kono
parents: 67
diff changeset
726 /* And release any SSA_NAMEs set in this statement back to the
kono
parents: 67
diff changeset
727 SSA_NAME manager. */
kono
parents: 67
diff changeset
728 release_defs (stmt);
kono
parents: 67
diff changeset
729 }
kono
parents: 67
diff changeset
730
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 /* Attempt to eliminate dead stores in the statement referenced by BSI.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 A dead store is a store into a memory location which will later be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 overwritten by another store without any intervening loads. In this
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 case the earlier store can be deleted.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 In our SSA + virtual operand world we use immediate uses of virtual
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 operands to detect dead stores. If a store's virtual definition
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 is used precisely once by a later store to the same location which
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 post dominates the first store, then the first store is dead. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741
111
kono
parents: 67
diff changeset
742 void
kono
parents: 67
diff changeset
743 dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator *gsi)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 {
111
kono
parents: 67
diff changeset
745 gimple *stmt = gsi_stmt (*gsi);
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 /* If this statement has no virtual defs, then there is nothing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 to do. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
749 if (!gimple_vdef (stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751
111
kono
parents: 67
diff changeset
752 /* Don't return early on *this_2(D) ={v} {CLOBBER}. */
kono
parents: 67
diff changeset
753 if (gimple_has_volatile_ops (stmt)
kono
parents: 67
diff changeset
754 && (!gimple_clobber_p (stmt)
kono
parents: 67
diff changeset
755 || TREE_CODE (gimple_assign_lhs (stmt)) != MEM_REF))
kono
parents: 67
diff changeset
756 return;
kono
parents: 67
diff changeset
757
kono
parents: 67
diff changeset
758 ao_ref ref;
kono
parents: 67
diff changeset
759 if (!initialize_ao_ref_for_dse (stmt, &ref))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761
111
kono
parents: 67
diff changeset
762 /* We know we have virtual definitions. We can handle assignments and
kono
parents: 67
diff changeset
763 some builtin calls. */
kono
parents: 67
diff changeset
764 if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
kono
parents: 67
diff changeset
765 {
kono
parents: 67
diff changeset
766 switch (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt)))
kono
parents: 67
diff changeset
767 {
kono
parents: 67
diff changeset
768 case BUILT_IN_MEMCPY:
kono
parents: 67
diff changeset
769 case BUILT_IN_MEMMOVE:
kono
parents: 67
diff changeset
770 case BUILT_IN_MEMSET:
kono
parents: 67
diff changeset
771 {
kono
parents: 67
diff changeset
772 /* Occasionally calls with an explicit length of zero
kono
parents: 67
diff changeset
773 show up in the IL. It's pointless to do analysis
kono
parents: 67
diff changeset
774 on them, they're trivially dead. */
kono
parents: 67
diff changeset
775 tree size = gimple_call_arg (stmt, 2);
kono
parents: 67
diff changeset
776 if (integer_zerop (size))
kono
parents: 67
diff changeset
777 {
kono
parents: 67
diff changeset
778 delete_dead_call (gsi);
kono
parents: 67
diff changeset
779 return;
kono
parents: 67
diff changeset
780 }
kono
parents: 67
diff changeset
781
kono
parents: 67
diff changeset
782 gimple *use_stmt;
kono
parents: 67
diff changeset
783 enum dse_store_status store_status;
kono
parents: 67
diff changeset
784 m_byte_tracking_enabled
kono
parents: 67
diff changeset
785 = setup_live_bytes_from_ref (&ref, m_live_bytes);
kono
parents: 67
diff changeset
786 store_status = dse_classify_store (&ref, stmt, &use_stmt,
kono
parents: 67
diff changeset
787 m_byte_tracking_enabled,
kono
parents: 67
diff changeset
788 m_live_bytes);
kono
parents: 67
diff changeset
789 if (store_status == DSE_STORE_LIVE)
kono
parents: 67
diff changeset
790 return;
kono
parents: 67
diff changeset
791
kono
parents: 67
diff changeset
792 if (store_status == DSE_STORE_MAYBE_PARTIAL_DEAD)
kono
parents: 67
diff changeset
793 {
kono
parents: 67
diff changeset
794 maybe_trim_memstar_call (&ref, m_live_bytes, stmt);
kono
parents: 67
diff changeset
795 return;
kono
parents: 67
diff changeset
796 }
kono
parents: 67
diff changeset
797
kono
parents: 67
diff changeset
798 if (store_status == DSE_STORE_DEAD)
kono
parents: 67
diff changeset
799 delete_dead_call (gsi);
kono
parents: 67
diff changeset
800 return;
kono
parents: 67
diff changeset
801 }
kono
parents: 67
diff changeset
802
kono
parents: 67
diff changeset
803 default:
kono
parents: 67
diff changeset
804 return;
kono
parents: 67
diff changeset
805 }
kono
parents: 67
diff changeset
806 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 if (is_gimple_assign (stmt))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 {
111
kono
parents: 67
diff changeset
810 gimple *use_stmt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811
111
kono
parents: 67
diff changeset
812 /* Self-assignments are zombies. */
kono
parents: 67
diff changeset
813 if (operand_equal_p (gimple_assign_rhs1 (stmt),
kono
parents: 67
diff changeset
814 gimple_assign_lhs (stmt), 0))
kono
parents: 67
diff changeset
815 use_stmt = stmt;
kono
parents: 67
diff changeset
816 else
kono
parents: 67
diff changeset
817 {
kono
parents: 67
diff changeset
818 m_byte_tracking_enabled
kono
parents: 67
diff changeset
819 = setup_live_bytes_from_ref (&ref, m_live_bytes);
kono
parents: 67
diff changeset
820 enum dse_store_status store_status;
kono
parents: 67
diff changeset
821 store_status = dse_classify_store (&ref, stmt, &use_stmt,
kono
parents: 67
diff changeset
822 m_byte_tracking_enabled,
kono
parents: 67
diff changeset
823 m_live_bytes);
kono
parents: 67
diff changeset
824 if (store_status == DSE_STORE_LIVE)
kono
parents: 67
diff changeset
825 return;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826
111
kono
parents: 67
diff changeset
827 if (store_status == DSE_STORE_MAYBE_PARTIAL_DEAD)
kono
parents: 67
diff changeset
828 {
kono
parents: 67
diff changeset
829 maybe_trim_partially_dead_store (&ref, m_live_bytes, stmt);
kono
parents: 67
diff changeset
830 return;
kono
parents: 67
diff changeset
831 }
kono
parents: 67
diff changeset
832 }
kono
parents: 67
diff changeset
833
kono
parents: 67
diff changeset
834 /* Now we know that use_stmt kills the LHS of stmt. */
kono
parents: 67
diff changeset
835
kono
parents: 67
diff changeset
836 /* But only remove *this_2(D) ={v} {CLOBBER} if killed by
kono
parents: 67
diff changeset
837 another clobber stmt. */
kono
parents: 67
diff changeset
838 if (gimple_clobber_p (stmt)
kono
parents: 67
diff changeset
839 && !gimple_clobber_p (use_stmt))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
840 return;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841
111
kono
parents: 67
diff changeset
842 delete_dead_assignment (gsi);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845
111
kono
parents: 67
diff changeset
846 edge
kono
parents: 67
diff changeset
847 dse_dom_walker::before_dom_children (basic_block bb)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
848 {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850
111
kono
parents: 67
diff changeset
851 for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
kono
parents: 67
diff changeset
852 {
kono
parents: 67
diff changeset
853 dse_optimize_stmt (&gsi);
kono
parents: 67
diff changeset
854 if (gsi_end_p (gsi))
kono
parents: 67
diff changeset
855 gsi = gsi_last_bb (bb);
kono
parents: 67
diff changeset
856 else
kono
parents: 67
diff changeset
857 gsi_prev (&gsi);
kono
parents: 67
diff changeset
858 }
kono
parents: 67
diff changeset
859 return NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861
111
kono
parents: 67
diff changeset
862 namespace {
kono
parents: 67
diff changeset
863
kono
parents: 67
diff changeset
864 const pass_data pass_data_dse =
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 {
111
kono
parents: 67
diff changeset
866 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
867 "dse", /* name */
kono
parents: 67
diff changeset
868 OPTGROUP_NONE, /* optinfo_flags */
kono
parents: 67
diff changeset
869 TV_TREE_DSE, /* tv_id */
kono
parents: 67
diff changeset
870 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 67
diff changeset
871 0, /* properties_provided */
kono
parents: 67
diff changeset
872 0, /* properties_destroyed */
kono
parents: 67
diff changeset
873 0, /* todo_flags_start */
kono
parents: 67
diff changeset
874 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
875 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
876
111
kono
parents: 67
diff changeset
877 class pass_dse : public gimple_opt_pass
kono
parents: 67
diff changeset
878 {
kono
parents: 67
diff changeset
879 public:
kono
parents: 67
diff changeset
880 pass_dse (gcc::context *ctxt)
kono
parents: 67
diff changeset
881 : gimple_opt_pass (pass_data_dse, ctxt)
kono
parents: 67
diff changeset
882 {}
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883
111
kono
parents: 67
diff changeset
884 /* opt_pass methods: */
kono
parents: 67
diff changeset
885 opt_pass * clone () { return new pass_dse (m_ctxt); }
kono
parents: 67
diff changeset
886 virtual bool gate (function *) { return flag_tree_dse != 0; }
kono
parents: 67
diff changeset
887 virtual unsigned int execute (function *);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888
111
kono
parents: 67
diff changeset
889 }; // class pass_dse
kono
parents: 67
diff changeset
890
kono
parents: 67
diff changeset
891 unsigned int
kono
parents: 67
diff changeset
892 pass_dse::execute (function *fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
893 {
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
894 need_eh_cleanup = BITMAP_ALLOC (NULL);
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
895
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
896 renumber_gimple_stmt_uids ();
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 /* We might consider making this a property of each pass so that it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
899 can be [re]computed on an as-needed basis. Particularly since
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
900 this pass could be seen as an extension of DCE which needs post
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
901 dominators. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
902 calculate_dominance_info (CDI_POST_DOMINATORS);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
903 calculate_dominance_info (CDI_DOMINATORS);
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 /* Dead store elimination is fundamentally a walk of the post-dominator
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
906 tree and a backwards walk of statements within each block. */
111
kono
parents: 67
diff changeset
907 dse_dom_walker (CDI_POST_DOMINATORS).walk (fun->cfg->x_exit_block_ptr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908
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
909 /* Removal of stores may make some EH edges dead. Purge such edges from
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
910 the CFG as needed. */
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
911 if (!bitmap_empty_p (need_eh_cleanup))
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
912 {
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
913 gimple_purge_all_dead_eh_edges (need_eh_cleanup);
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
914 cleanup_tree_cfg ();
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
915 }
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
916
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
917 BITMAP_FREE (need_eh_cleanup);
111
kono
parents: 67
diff changeset
918
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 /* For now, just wipe the post-dominator information. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920 free_dominance_info (CDI_POST_DOMINATORS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
922 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923
111
kono
parents: 67
diff changeset
924 } // anon namespace
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
925
111
kono
parents: 67
diff changeset
926 gimple_opt_pass *
kono
parents: 67
diff changeset
927 make_pass_dse (gcc::context *ctxt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 {
111
kono
parents: 67
diff changeset
929 return new pass_dse (ctxt);
kono
parents: 67
diff changeset
930 }