]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/dse.c
re PR c++/48089 ([C++0x] ICE on in(?)valid in constexpr constructors)
[thirdparty/gcc.git] / gcc / dse.c
CommitLineData
6fb5fa3c 1/* RTL dead store elimination.
457eeaae
JJ
2 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
6fb5fa3c
DB
4
5 Contributed by Richard Sandiford <rsandifor@codesourcery.com>
6 and Kenneth Zadeck <zadeck@naturalbridge.com>
7
8This file is part of GCC.
9
10GCC is free software; you can redistribute it and/or modify it under
11the terms of the GNU General Public License as published by the Free
9dcd6f09 12Software Foundation; either version 3, or (at your option) any later
6fb5fa3c
DB
13version.
14
15GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18for more details.
19
20You should have received a copy of the GNU General Public License
9dcd6f09
NC
21along with GCC; see the file COPYING3. If not see
22<http://www.gnu.org/licenses/>. */
6fb5fa3c
DB
23
24#undef BASELINE
25
26#include "config.h"
27#include "system.h"
28#include "coretypes.h"
29#include "hashtab.h"
30#include "tm.h"
31#include "rtl.h"
32#include "tree.h"
18b526e8 33#include "tm_p.h"
6fb5fa3c
DB
34#include "regs.h"
35#include "hard-reg-set.h"
36#include "flags.h"
37#include "df.h"
38#include "cselib.h"
39#include "timevar.h"
40#include "tree-pass.h"
41#include "alloc-pool.h"
42#include "alias.h"
43#include "insn-config.h"
44#include "expr.h"
45#include "recog.h"
46#include "dse.h"
8660aaae 47#include "optabs.h"
6fb5fa3c 48#include "dbgcnt.h"
67d0afe9 49#include "target.h"
6fb5fa3c
DB
50
51/* This file contains three techniques for performing Dead Store
b8698a0f 52 Elimination (dse).
6fb5fa3c
DB
53
54 * The first technique performs dse locally on any base address. It
55 is based on the cselib which is a local value numbering technique.
56 This technique is local to a basic block but deals with a fairly
57 general addresses.
b8698a0f 58
6fb5fa3c
DB
59 * The second technique performs dse globally but is restricted to
60 base addresses that are either constant or are relative to the
61 frame_pointer.
62
63 * The third technique, (which is only done after register allocation)
64 processes the spill spill slots. This differs from the second
65 technique because it takes advantage of the fact that spilling is
66 completely free from the effects of aliasing.
67
68 Logically, dse is a backwards dataflow problem. A store can be
69 deleted if it if cannot be reached in the backward direction by any
70 use of the value being stored. However, the local technique uses a
71 forwards scan of the basic block because cselib requires that the
72 block be processed in that order.
73
74 The pass is logically broken into 7 steps:
75
76 0) Initialization.
77
78 1) The local algorithm, as well as scanning the insns for the two
79 global algorithms.
80
81 2) Analysis to see if the global algs are necessary. In the case
82 of stores base on a constant address, there must be at least two
83 stores to that address, to make it possible to delete some of the
84 stores. In the case of stores off of the frame or spill related
85 stores, only one store to an address is necessary because those
86 stores die at the end of the function.
87
b8698a0f 88 3) Set up the global dataflow equations based on processing the
6fb5fa3c
DB
89 info parsed in the first step.
90
91 4) Solve the dataflow equations.
92
93 5) Delete the insns that the global analysis has indicated are
94 unnecessary.
95
8dd5516b
JJ
96 6) Delete insns that store the same value as preceeding store
97 where the earlier store couldn't be eliminated.
98
99 7) Cleanup.
6fb5fa3c
DB
100
101 This step uses cselib and canon_rtx to build the largest expression
102 possible for each address. This pass is a forwards pass through
103 each basic block. From the point of view of the global technique,
104 the first pass could examine a block in either direction. The
0d52bcc1 105 forwards ordering is to accommodate cselib.
6fb5fa3c
DB
106
107 We a simplifying assumption: addresses fall into four broad
108 categories:
109
110 1) base has rtx_varies_p == false, offset is constant.
111 2) base has rtx_varies_p == false, offset variable.
112 3) base has rtx_varies_p == true, offset constant.
113 4) base has rtx_varies_p == true, offset variable.
114
115 The local passes are able to process all 4 kinds of addresses. The
116 global pass only handles (1).
117
118 The global problem is formulated as follows:
119
120 A store, S1, to address A, where A is not relative to the stack
121 frame, can be eliminated if all paths from S1 to the end of the
122 of the function contain another store to A before a read to A.
123
124 If the address A is relative to the stack frame, a store S2 to A
125 can be eliminated if there are no paths from S1 that reach the
126 end of the function that read A before another store to A. In
127 this case S2 can be deleted if there are paths to from S2 to the
128 end of the function that have no reads or writes to A. This
129 second case allows stores to the stack frame to be deleted that
130 would otherwise die when the function returns. This cannot be
131 done if stores_off_frame_dead_at_return is not true. See the doc
132 for that variable for when this variable is false.
133
134 The global problem is formulated as a backwards set union
135 dataflow problem where the stores are the gens and reads are the
136 kills. Set union problems are rare and require some special
137 handling given our representation of bitmaps. A straightforward
138 implementation of requires a lot of bitmaps filled with 1s.
139 These are expensive and cumbersome in our bitmap formulation so
140 care has been taken to avoid large vectors filled with 1s. See
141 the comments in bb_info and in the dataflow confluence functions
b8698a0f 142 for details.
6fb5fa3c
DB
143
144 There are two places for further enhancements to this algorithm:
b8698a0f 145
6fb5fa3c
DB
146 1) The original dse which was embedded in a pass called flow also
147 did local address forwarding. For example in
148
149 A <- r100
150 ... <- A
151
152 flow would replace the right hand side of the second insn with a
6ed3da00 153 reference to r100. Most of the information is available to add this
6fb5fa3c
DB
154 to this pass. It has not done it because it is a lot of work in
155 the case that either r100 is assigned to between the first and
156 second insn and/or the second insn is a load of part of the value
157 stored by the first insn.
158
159 insn 5 in gcc.c-torture/compile/990203-1.c simple case.
160 insn 15 in gcc.c-torture/execute/20001017-2.c simple case.
161 insn 25 in gcc.c-torture/execute/20001026-1.c simple case.
162 insn 44 in gcc.c-torture/execute/20010910-1.c simple case.
163
164 2) The cleaning up of spill code is quite profitable. It currently
165 depends on reading tea leaves and chicken entrails left by reload.
166 This pass depends on reload creating a singleton alias set for each
167 spill slot and telling the next dse pass which of these alias sets
168 are the singletons. Rather than analyze the addresses of the
169 spills, dse's spill processing just does analysis of the loads and
170 stores that use those alias sets. There are three cases where this
171 falls short:
172
173 a) Reload sometimes creates the slot for one mode of access, and
174 then inserts loads and/or stores for a smaller mode. In this
175 case, the current code just punts on the slot. The proper thing
176 to do is to back out and use one bit vector position for each
177 byte of the entity associated with the slot. This depends on
178 KNOWING that reload always generates the accesses for each of the
179 bytes in some canonical (read that easy to understand several
180 passes after reload happens) way.
181
182 b) Reload sometimes decides that spill slot it allocated was not
183 large enough for the mode and goes back and allocates more slots
184 with the same mode and alias set. The backout in this case is a
185 little more graceful than (a). In this case the slot is unmarked
186 as being a spill slot and if final address comes out to be based
b8698a0f 187 off the frame pointer, the global algorithm handles this slot.
6fb5fa3c
DB
188
189 c) For any pass that may prespill, there is currently no
190 mechanism to tell the dse pass that the slot being used has the
191 special properties that reload uses. It may be that all that is
0d52bcc1 192 required is to have those passes make the same calls that reload
6fb5fa3c
DB
193 does, assuming that the alias sets can be manipulated in the same
194 way. */
195
196/* There are limits to the size of constant offsets we model for the
197 global problem. There are certainly test cases, that exceed this
198 limit, however, it is unlikely that there are important programs
199 that really have constant offsets this size. */
200#define MAX_OFFSET (64 * 1024)
201
202
203static bitmap scratch = NULL;
204struct insn_info;
205
206/* This structure holds information about a candidate store. */
b8698a0f 207struct store_info
6fb5fa3c
DB
208{
209
210 /* False means this is a clobber. */
211 bool is_set;
212
8dd5516b
JJ
213 /* False if a single HOST_WIDE_INT bitmap is used for positions_needed. */
214 bool is_large;
215
6fb5fa3c
DB
216 /* The id of the mem group of the base address. If rtx_varies_p is
217 true, this is -1. Otherwise, it is the index into the group
218 table. */
219 int group_id;
b8698a0f 220
6fb5fa3c
DB
221 /* This is the cselib value. */
222 cselib_val *cse_base;
223
224 /* This canonized mem. */
225 rtx mem;
226
6216f94e 227 /* Canonized MEM address for use by canon_true_dependence. */
6fb5fa3c
DB
228 rtx mem_addr;
229
230 /* If this is non-zero, it is the alias set of a spill location. */
4862826d 231 alias_set_type alias_set;
6fb5fa3c
DB
232
233 /* The offset of the first and byte before the last byte associated
234 with the operation. */
8dd5516b
JJ
235 HOST_WIDE_INT begin, end;
236
237 union
238 {
239 /* A bitmask as wide as the number of bytes in the word that
240 contains a 1 if the byte may be needed. The store is unused if
241 all of the bits are 0. This is used if IS_LARGE is false. */
242 unsigned HOST_WIDE_INT small_bitmask;
243
244 struct
245 {
246 /* A bitmap with one bit per byte. Cleared bit means the position
247 is needed. Used if IS_LARGE is false. */
dc491a25 248 bitmap bmap;
6fb5fa3c 249
8dd5516b
JJ
250 /* Number of set bits (i.e. unneeded bytes) in BITMAP. If it is
251 equal to END - BEGIN, the whole store is unused. */
252 int count;
253 } large;
254 } positions_needed;
6fb5fa3c
DB
255
256 /* The next store info for this insn. */
257 struct store_info *next;
258
259 /* The right hand side of the store. This is used if there is a
260 subsequent reload of the mems address somewhere later in the
261 basic block. */
8dd5516b
JJ
262 rtx rhs;
263
264 /* If rhs is or holds a constant, this contains that constant,
265 otherwise NULL. */
266 rtx const_rhs;
267
268 /* Set if this store stores the same constant value as REDUNDANT_REASON
269 insn stored. These aren't eliminated early, because doing that
270 might prevent the earlier larger store to be eliminated. */
271 struct insn_info *redundant_reason;
6fb5fa3c
DB
272};
273
4fe663b0
L
274/* Return a bitmask with the first N low bits set. */
275
276static unsigned HOST_WIDE_INT
277lowpart_bitmask (int n)
278{
279 unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT) 0;
280 return mask >> (HOST_BITS_PER_WIDE_INT - n);
281}
282
6fb5fa3c
DB
283typedef struct store_info *store_info_t;
284static alloc_pool cse_store_info_pool;
285static alloc_pool rtx_store_info_pool;
286
287/* This structure holds information about a load. These are only
288 built for rtx bases. */
b8698a0f 289struct read_info
6fb5fa3c
DB
290{
291 /* The id of the mem group of the base address. */
292 int group_id;
293
294 /* If this is non-zero, it is the alias set of a spill location. */
4862826d 295 alias_set_type alias_set;
6fb5fa3c
DB
296
297 /* The offset of the first and byte after the last byte associated
298 with the operation. If begin == end == 0, the read did not have
299 a constant offset. */
300 int begin, end;
301
302 /* The mem being read. */
303 rtx mem;
304
305 /* The next read_info for this insn. */
306 struct read_info *next;
307};
308typedef struct read_info *read_info_t;
309static alloc_pool read_info_pool;
310
311
312/* One of these records is created for each insn. */
313
b8698a0f 314struct insn_info
6fb5fa3c
DB
315{
316 /* Set true if the insn contains a store but the insn itself cannot
317 be deleted. This is set if the insn is a parallel and there is
318 more than one non dead output or if the insn is in some way
319 volatile. */
320 bool cannot_delete;
321
322 /* This field is only used by the global algorithm. It is set true
323 if the insn contains any read of mem except for a (1). This is
324 also set if the insn is a call or has a clobber mem. If the insn
325 contains a wild read, the use_rec will be null. */
326 bool wild_read;
327
50f0f366
EB
328 /* This field is only used for the processing of const functions.
329 These functions cannot read memory, but they can read the stack
64520bdc
EB
330 because that is where they may get their parms. We need to be
331 this conservative because, like the store motion pass, we don't
332 consider CALL_INSN_FUNCTION_USAGE when processing call insns.
333 Moreover, we need to distinguish two cases:
334 1. Before reload (register elimination), the stores related to
335 outgoing arguments are stack pointer based and thus deemed
336 of non-constant base in this pass. This requires special
337 handling but also means that the frame pointer based stores
338 need not be killed upon encountering a const function call.
339 2. After reload, the stores related to outgoing arguments can be
340 either stack pointer or hard frame pointer based. This means
341 that we have no other choice than also killing all the frame
342 pointer based stores upon encountering a const function call.
343 This field is set after reload for const function calls. Having
344 this set is less severe than a wild read, it just means that all
345 the frame related stores are killed rather than all the stores. */
346 bool frame_read;
347
348 /* This field is only used for the processing of const functions.
349 It is set if the insn may contain a stack pointer based store. */
50f0f366 350 bool stack_pointer_based;
6fb5fa3c
DB
351
352 /* This is true if any of the sets within the store contains a
353 cselib base. Such stores can only be deleted by the local
354 algorithm. */
355 bool contains_cselib_groups;
356
357 /* The insn. */
358 rtx insn;
359
360 /* The list of mem sets or mem clobbers that are contained in this
361 insn. If the insn is deletable, it contains only one mem set.
362 But it could also contain clobbers. Insns that contain more than
363 one mem set are not deletable, but each of those mems are here in
6ed3da00 364 order to provide info to delete other insns. */
6fb5fa3c
DB
365 store_info_t store_rec;
366
367 /* The linked list of mem uses in this insn. Only the reads from
368 rtx bases are listed here. The reads to cselib bases are
369 completely processed during the first scan and so are never
370 created. */
371 read_info_t read_rec;
372
373 /* The prev insn in the basic block. */
374 struct insn_info * prev_insn;
375
376 /* The linked list of insns that are in consideration for removal in
377 the forwards pass thru the basic block. This pointer may be
378 trash as it is not cleared when a wild read occurs. The only
fa10beec 379 time it is guaranteed to be correct is when the traversal starts
6fb5fa3c
DB
380 at active_local_stores. */
381 struct insn_info * next_local_store;
382};
383
384typedef struct insn_info *insn_info_t;
385static alloc_pool insn_info_pool;
386
387/* The linked list of stores that are under consideration in this
b8698a0f 388 basic block. */
6fb5fa3c
DB
389static insn_info_t active_local_stores;
390
b8698a0f 391struct bb_info
6fb5fa3c
DB
392{
393
394 /* Pointer to the insn info for the last insn in the block. These
395 are linked so this is how all of the insns are reached. During
396 scanning this is the current insn being scanned. */
397 insn_info_t last_insn;
398
399 /* The info for the global dataflow problem. */
400
401
402 /* This is set if the transfer function should and in the wild_read
403 bitmap before applying the kill and gen sets. That vector knocks
404 out most of the bits in the bitmap and thus speeds up the
405 operations. */
406 bool apply_wild_read;
407
02b47899
KZ
408 /* The following 4 bitvectors hold information about which positions
409 of which stores are live or dead. They are indexed by
410 get_bitmap_index. */
411
6fb5fa3c
DB
412 /* The set of store positions that exist in this block before a wild read. */
413 bitmap gen;
b8698a0f 414
6fb5fa3c
DB
415 /* The set of load positions that exist in this block above the
416 same position of a store. */
417 bitmap kill;
418
419 /* The set of stores that reach the top of the block without being
420 killed by a read.
421
422 Do not represent the in if it is all ones. Note that this is
423 what the bitvector should logically be initialized to for a set
424 intersection problem. However, like the kill set, this is too
425 expensive. So initially, the in set will only be created for the
426 exit block and any block that contains a wild read. */
427 bitmap in;
428
429 /* The set of stores that reach the bottom of the block from it's
430 successors.
431
432 Do not represent the in if it is all ones. Note that this is
433 what the bitvector should logically be initialized to for a set
434 intersection problem. However, like the kill and in set, this is
435 too expensive. So what is done is that the confluence operator
436 just initializes the vector from one of the out sets of the
437 successors of the block. */
438 bitmap out;
02b47899
KZ
439
440 /* The following bitvector is indexed by the reg number. It
441 contains the set of regs that are live at the current instruction
442 being processed. While it contains info for all of the
443 registers, only the pseudos are actually examined. It is used to
444 assure that shift sequences that are inserted do not accidently
445 clobber live hard regs. */
446 bitmap regs_live;
6fb5fa3c
DB
447};
448
449typedef struct bb_info *bb_info_t;
450static alloc_pool bb_info_pool;
451
452/* Table to hold all bb_infos. */
453static bb_info_t *bb_table;
454
455/* There is a group_info for each rtx base that is used to reference
456 memory. There are also not many of the rtx bases because they are
457 very limited in scope. */
458
b8698a0f 459struct group_info
6fb5fa3c
DB
460{
461 /* The actual base of the address. */
462 rtx rtx_base;
463
464 /* The sequential id of the base. This allows us to have a
465 canonical ordering of these that is not based on addresses. */
466 int id;
467
8f5929e1
JJ
468 /* True if there are any positions that are to be processed
469 globally. */
470 bool process_globally;
471
472 /* True if the base of this group is either the frame_pointer or
473 hard_frame_pointer. */
474 bool frame_related;
475
d32f725a
OH
476 /* A mem wrapped around the base pointer for the group in order to do
477 read dependency. It must be given BLKmode in order to encompass all
478 the possible offsets from the base. */
6fb5fa3c 479 rtx base_mem;
b8698a0f 480
6216f94e
JJ
481 /* Canonized version of base_mem's address. */
482 rtx canon_base_addr;
6fb5fa3c
DB
483
484 /* These two sets of two bitmaps are used to keep track of how many
6ed3da00 485 stores are actually referencing that position from this base. We
6fb5fa3c 486 only do this for rtx bases as this will be used to assign
6ed3da00 487 positions in the bitmaps for the global problem. Bit N is set in
6fb5fa3c
DB
488 store1 on the first store for offset N. Bit N is set in store2
489 for the second store to offset N. This is all we need since we
490 only care about offsets that have two or more stores for them.
491
492 The "_n" suffix is for offsets less than 0 and the "_p" suffix is
493 for 0 and greater offsets.
494
495 There is one special case here, for stores into the stack frame,
496 we will or store1 into store2 before deciding which stores look
497 at globally. This is because stores to the stack frame that have
498 no other reads before the end of the function can also be
499 deleted. */
500 bitmap store1_n, store1_p, store2_n, store2_p;
501
6ed3da00 502 /* The positions in this bitmap have the same assignments as the in,
6fb5fa3c 503 out, gen and kill bitmaps. This bitmap is all zeros except for
6ed3da00 504 the positions that are occupied by stores for this group. */
6fb5fa3c
DB
505 bitmap group_kill;
506
6fb5fa3c 507 /* The offset_map is used to map the offsets from this base into
6ed3da00 508 positions in the global bitmaps. It is only created after all of
6fb5fa3c
DB
509 the all of stores have been scanned and we know which ones we
510 care about. */
b8698a0f
L
511 int *offset_map_n, *offset_map_p;
512 int offset_map_size_n, offset_map_size_p;
6fb5fa3c
DB
513};
514typedef struct group_info *group_info_t;
5f754896 515typedef const struct group_info *const_group_info_t;
6fb5fa3c
DB
516static alloc_pool rtx_group_info_pool;
517
518/* Tables of group_info structures, hashed by base value. */
519static htab_t rtx_group_table;
520
521/* Index into the rtx_group_vec. */
522static int rtx_group_next_id;
523
524DEF_VEC_P(group_info_t);
525DEF_VEC_ALLOC_P(group_info_t,heap);
526
527static VEC(group_info_t,heap) *rtx_group_vec;
528
529
530/* This structure holds the set of changes that are being deferred
531 when removing read operation. See replace_read. */
b8698a0f 532struct deferred_change
6fb5fa3c
DB
533{
534
535 /* The mem that is being replaced. */
536 rtx *loc;
537
538 /* The reg it is being replaced with. */
539 rtx reg;
540
541 struct deferred_change *next;
542};
543
544typedef struct deferred_change *deferred_change_t;
545static alloc_pool deferred_change_pool;
546
547static deferred_change_t deferred_change_list = NULL;
548
549/* This are used to hold the alias sets of spill variables. Since
550 these are never aliased and there may be a lot of them, it makes
551 sense to treat them specially. This bitvector is only allocated in
552 calls from dse_record_singleton_alias_set which currently is only
553 made during reload1. So when dse is called before reload this
554 mechanism does nothing. */
555
556static bitmap clear_alias_sets = NULL;
557
558/* The set of clear_alias_sets that have been disqualified because
559 there are loads or stores using a different mode than the alias set
b8698a0f 560 was registered with. */
6fb5fa3c
DB
561static bitmap disqualified_clear_alias_sets = NULL;
562
563/* The group that holds all of the clear_alias_sets. */
564static group_info_t clear_alias_group;
565
566/* The modes of the clear_alias_sets. */
567static htab_t clear_alias_mode_table;
568
569/* Hash table element to look up the mode for an alias set. */
570struct clear_alias_mode_holder
571{
4862826d 572 alias_set_type alias_set;
6fb5fa3c
DB
573 enum machine_mode mode;
574};
575
576static alloc_pool clear_alias_mode_pool;
577
e3b5732b 578/* This is true except if cfun->stdarg -- i.e. we cannot do
9dd9bf80 579 this for vararg functions because they play games with the frame. */
6fb5fa3c
DB
580static bool stores_off_frame_dead_at_return;
581
582/* Counter for stats. */
b8698a0f
L
583static int globally_deleted;
584static int locally_deleted;
585static int spill_deleted;
586
6fb5fa3c
DB
587static bitmap all_blocks;
588
589/* The number of bits used in the global bitmaps. */
590static unsigned int current_position;
591
592
593static bool gate_dse (void);
7d817ebc
DE
594static bool gate_dse1 (void);
595static bool gate_dse2 (void);
6fb5fa3c
DB
596
597\f
598/*----------------------------------------------------------------------------
599 Zeroth step.
600
b8698a0f 601 Initialization.
6fb5fa3c
DB
602----------------------------------------------------------------------------*/
603
604/* Hashtable callbacks for maintaining the "bases" field of
605 store_group_info, given that the addresses are function invariants. */
606
607static int
608clear_alias_mode_eq (const void *p1, const void *p2)
609{
b8698a0f 610 const struct clear_alias_mode_holder * h1
6fb5fa3c 611 = (const struct clear_alias_mode_holder *) p1;
b8698a0f 612 const struct clear_alias_mode_holder * h2
6fb5fa3c
DB
613 = (const struct clear_alias_mode_holder *) p2;
614 return h1->alias_set == h2->alias_set;
615}
616
617
618static hashval_t
619clear_alias_mode_hash (const void *p)
620{
b8698a0f 621 const struct clear_alias_mode_holder *holder
6fb5fa3c
DB
622 = (const struct clear_alias_mode_holder *) p;
623 return holder->alias_set;
624}
625
626
627/* Find the entry associated with ALIAS_SET. */
628
629static struct clear_alias_mode_holder *
4862826d 630clear_alias_set_lookup (alias_set_type alias_set)
6fb5fa3c
DB
631{
632 struct clear_alias_mode_holder tmp_holder;
633 void **slot;
b8698a0f 634
6fb5fa3c
DB
635 tmp_holder.alias_set = alias_set;
636 slot = htab_find_slot (clear_alias_mode_table, &tmp_holder, NO_INSERT);
637 gcc_assert (*slot);
b8698a0f 638
f883e0a7 639 return (struct clear_alias_mode_holder *) *slot;
6fb5fa3c
DB
640}
641
642
643/* Hashtable callbacks for maintaining the "bases" field of
644 store_group_info, given that the addresses are function invariants. */
645
646static int
647invariant_group_base_eq (const void *p1, const void *p2)
648{
5f754896
KG
649 const_group_info_t gi1 = (const_group_info_t) p1;
650 const_group_info_t gi2 = (const_group_info_t) p2;
6fb5fa3c
DB
651 return rtx_equal_p (gi1->rtx_base, gi2->rtx_base);
652}
653
654
655static hashval_t
656invariant_group_base_hash (const void *p)
657{
5f754896 658 const_group_info_t gi = (const_group_info_t) p;
6fb5fa3c
DB
659 int do_not_record;
660 return hash_rtx (gi->rtx_base, Pmode, &do_not_record, NULL, false);
661}
662
663
664/* Get the GROUP for BASE. Add a new group if it is not there. */
665
666static group_info_t
667get_group_info (rtx base)
668{
b8698a0f
L
669 struct group_info tmp_gi;
670 group_info_t gi;
6fb5fa3c
DB
671 void **slot;
672
673 if (base)
674 {
675 /* Find the store_base_info structure for BASE, creating a new one
676 if necessary. */
677 tmp_gi.rtx_base = base;
678 slot = htab_find_slot (rtx_group_table, &tmp_gi, INSERT);
679 gi = (group_info_t) *slot;
680 }
681 else
682 {
683 if (!clear_alias_group)
684 {
f883e0a7
KG
685 clear_alias_group = gi =
686 (group_info_t) pool_alloc (rtx_group_info_pool);
6fb5fa3c
DB
687 memset (gi, 0, sizeof (struct group_info));
688 gi->id = rtx_group_next_id++;
689 gi->store1_n = BITMAP_ALLOC (NULL);
690 gi->store1_p = BITMAP_ALLOC (NULL);
691 gi->store2_n = BITMAP_ALLOC (NULL);
692 gi->store2_p = BITMAP_ALLOC (NULL);
693 gi->group_kill = BITMAP_ALLOC (NULL);
694 gi->process_globally = false;
695 gi->offset_map_size_n = 0;
696 gi->offset_map_size_p = 0;
697 gi->offset_map_n = NULL;
698 gi->offset_map_p = NULL;
699 VEC_safe_push (group_info_t, heap, rtx_group_vec, gi);
700 }
701 return clear_alias_group;
702 }
703
704 if (gi == NULL)
705 {
f883e0a7 706 *slot = gi = (group_info_t) pool_alloc (rtx_group_info_pool);
6fb5fa3c
DB
707 gi->rtx_base = base;
708 gi->id = rtx_group_next_id++;
d32f725a 709 gi->base_mem = gen_rtx_MEM (BLKmode, base);
6216f94e 710 gi->canon_base_addr = canon_rtx (base);
6fb5fa3c
DB
711 gi->store1_n = BITMAP_ALLOC (NULL);
712 gi->store1_p = BITMAP_ALLOC (NULL);
713 gi->store2_n = BITMAP_ALLOC (NULL);
714 gi->store2_p = BITMAP_ALLOC (NULL);
715 gi->group_kill = BITMAP_ALLOC (NULL);
716 gi->process_globally = false;
b8698a0f 717 gi->frame_related =
6fb5fa3c
DB
718 (base == frame_pointer_rtx) || (base == hard_frame_pointer_rtx);
719 gi->offset_map_size_n = 0;
720 gi->offset_map_size_p = 0;
721 gi->offset_map_n = NULL;
722 gi->offset_map_p = NULL;
723 VEC_safe_push (group_info_t, heap, rtx_group_vec, gi);
724 }
725
726 return gi;
727}
728
729
730/* Initialization of data structures. */
731
732static void
733dse_step0 (void)
734{
735 locally_deleted = 0;
736 globally_deleted = 0;
737 spill_deleted = 0;
738
739 scratch = BITMAP_ALLOC (NULL);
740
741 rtx_store_info_pool
b8698a0f 742 = create_alloc_pool ("rtx_store_info_pool",
6fb5fa3c
DB
743 sizeof (struct store_info), 100);
744 read_info_pool
b8698a0f 745 = create_alloc_pool ("read_info_pool",
6fb5fa3c
DB
746 sizeof (struct read_info), 100);
747 insn_info_pool
b8698a0f 748 = create_alloc_pool ("insn_info_pool",
6fb5fa3c
DB
749 sizeof (struct insn_info), 100);
750 bb_info_pool
b8698a0f 751 = create_alloc_pool ("bb_info_pool",
6fb5fa3c
DB
752 sizeof (struct bb_info), 100);
753 rtx_group_info_pool
b8698a0f 754 = create_alloc_pool ("rtx_group_info_pool",
6fb5fa3c
DB
755 sizeof (struct group_info), 100);
756 deferred_change_pool
b8698a0f 757 = create_alloc_pool ("deferred_change_pool",
6fb5fa3c
DB
758 sizeof (struct deferred_change), 10);
759
760 rtx_group_table = htab_create (11, invariant_group_base_hash,
761 invariant_group_base_eq, NULL);
762
763 bb_table = XCNEWVEC (bb_info_t, last_basic_block);
764 rtx_group_next_id = 0;
765
e3b5732b 766 stores_off_frame_dead_at_return = !cfun->stdarg;
6fb5fa3c
DB
767
768 init_alias_analysis ();
b8698a0f 769
6fb5fa3c
DB
770 if (clear_alias_sets)
771 clear_alias_group = get_group_info (NULL);
772 else
773 clear_alias_group = NULL;
774}
775
776
777\f
778/*----------------------------------------------------------------------------
779 First step.
780
781 Scan all of the insns. Any random ordering of the blocks is fine.
0d52bcc1 782 Each block is scanned in forward order to accommodate cselib which
6fb5fa3c
DB
783 is used to remove stores with non-constant bases.
784----------------------------------------------------------------------------*/
785
786/* Delete all of the store_info recs from INSN_INFO. */
787
b8698a0f 788static void
6fb5fa3c
DB
789free_store_info (insn_info_t insn_info)
790{
791 store_info_t store_info = insn_info->store_rec;
792 while (store_info)
793 {
794 store_info_t next = store_info->next;
8dd5516b 795 if (store_info->is_large)
dc491a25 796 BITMAP_FREE (store_info->positions_needed.large.bmap);
6fb5fa3c
DB
797 if (store_info->cse_base)
798 pool_free (cse_store_info_pool, store_info);
799 else
800 pool_free (rtx_store_info_pool, store_info);
801 store_info = next;
802 }
803
804 insn_info->cannot_delete = true;
805 insn_info->contains_cselib_groups = false;
806 insn_info->store_rec = NULL;
807}
808
4deef538
AO
809/* Callback for for_each_inc_dec that emits an INSN that sets DEST to
810 SRC + SRCOFF before insn ARG. */
6fb5fa3c
DB
811
812static int
4deef538
AO
813emit_inc_dec_insn_before (rtx mem ATTRIBUTE_UNUSED,
814 rtx op ATTRIBUTE_UNUSED,
815 rtx dest, rtx src, rtx srcoff, void *arg)
6fb5fa3c 816{
4deef538 817 rtx insn = (rtx)arg;
b8698a0f 818
4deef538
AO
819 if (srcoff)
820 src = gen_rtx_PLUS (GET_MODE (src), src, srcoff);
b8698a0f 821
4deef538
AO
822 /* We can reuse all operands without copying, because we are about
823 to delete the insn that contained it. */
6fb5fa3c 824
4deef538 825 emit_insn_before (gen_rtx_SET (VOIDmode, dest, src), insn);
6fb5fa3c 826
4deef538 827 return -1;
6fb5fa3c
DB
828}
829
830/* Before we delete INSN, make sure that the auto inc/dec, if it is
831 there, is split into a separate insn. */
832
3f82421f 833void
6fb5fa3c
DB
834check_for_inc_dec (rtx insn)
835{
836 rtx note = find_reg_note (insn, REG_INC, NULL_RTX);
837 if (note)
4deef538 838 for_each_inc_dec (&insn, emit_inc_dec_insn_before, insn);
6fb5fa3c
DB
839}
840
841
b8698a0f 842/* Delete the insn and free all of the fields inside INSN_INFO. */
6fb5fa3c
DB
843
844static void
845delete_dead_store_insn (insn_info_t insn_info)
846{
847 read_info_t read_info;
848
849 if (!dbg_cnt (dse))
850 return;
851
852 check_for_inc_dec (insn_info->insn);
853 if (dump_file)
854 {
b8698a0f 855 fprintf (dump_file, "Locally deleting insn %d ",
6fb5fa3c
DB
856 INSN_UID (insn_info->insn));
857 if (insn_info->store_rec->alias_set)
b8698a0f 858 fprintf (dump_file, "alias set %d\n",
4862826d 859 (int) insn_info->store_rec->alias_set);
6fb5fa3c
DB
860 else
861 fprintf (dump_file, "\n");
862 }
863
864 free_store_info (insn_info);
865 read_info = insn_info->read_rec;
b8698a0f 866
6fb5fa3c
DB
867 while (read_info)
868 {
869 read_info_t next = read_info->next;
870 pool_free (read_info_pool, read_info);
871 read_info = next;
872 }
873 insn_info->read_rec = NULL;
874
875 delete_insn (insn_info->insn);
876 locally_deleted++;
877 insn_info->insn = NULL;
878
879 insn_info->wild_read = false;
880}
881
882
883/* Set the store* bitmaps offset_map_size* fields in GROUP based on
884 OFFSET and WIDTH. */
885
886static void
887set_usage_bits (group_info_t group, HOST_WIDE_INT offset, HOST_WIDE_INT width)
888{
889 HOST_WIDE_INT i;
890
8dd5516b 891 if (offset > -MAX_OFFSET && offset + width < MAX_OFFSET)
6fb5fa3c
DB
892 for (i=offset; i<offset+width; i++)
893 {
894 bitmap store1;
895 bitmap store2;
896 int ai;
897 if (i < 0)
898 {
899 store1 = group->store1_n;
900 store2 = group->store2_n;
901 ai = -i;
902 }
903 else
904 {
905 store1 = group->store1_p;
906 store2 = group->store2_p;
907 ai = i;
908 }
b8698a0f 909
fcaa4ca4 910 if (!bitmap_set_bit (store1, ai))
6fb5fa3c 911 bitmap_set_bit (store2, ai);
b8698a0f 912 else
6fb5fa3c 913 {
6fb5fa3c
DB
914 if (i < 0)
915 {
916 if (group->offset_map_size_n < ai)
917 group->offset_map_size_n = ai;
918 }
919 else
920 {
921 if (group->offset_map_size_p < ai)
922 group->offset_map_size_p = ai;
923 }
924 }
925 }
926}
927
928
929/* Set the BB_INFO so that the last insn is marked as a wild read. */
930
931static void
932add_wild_read (bb_info_t bb_info)
933{
934 insn_info_t insn_info = bb_info->last_insn;
935 read_info_t *ptr = &insn_info->read_rec;
936
937 while (*ptr)
938 {
939 read_info_t next = (*ptr)->next;
4862826d 940 if ((*ptr)->alias_set == 0)
6fb5fa3c
DB
941 {
942 pool_free (read_info_pool, *ptr);
943 *ptr = next;
944 }
b8698a0f 945 else
6fb5fa3c
DB
946 ptr = &(*ptr)->next;
947 }
948 insn_info->wild_read = true;
949 active_local_stores = NULL;
950}
951
952
50f0f366
EB
953/* Return true if X is a constant or one of the registers that behave
954 as a constant over the life of a function. This is equivalent to
955 !rtx_varies_p for memory addresses. */
6fb5fa3c
DB
956
957static bool
958const_or_frame_p (rtx x)
959{
960 switch (GET_CODE (x))
961 {
6fb5fa3c
DB
962 case CONST:
963 case CONST_INT:
964 case CONST_DOUBLE:
965 case CONST_VECTOR:
966 case SYMBOL_REF:
967 case LABEL_REF:
968 return true;
969
970 case REG:
971 /* Note that we have to test for the actual rtx used for the frame
972 and arg pointers and not just the register number in case we have
973 eliminated the frame and/or arg pointer and are using it
974 for pseudos. */
975 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
976 /* The arg pointer varies if it is not a fixed register. */
977 || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])
978 || x == pic_offset_table_rtx)
979 return true;
980 return false;
981
982 default:
983 return false;
984 }
985}
986
b8698a0f
L
987/* Take all reasonable action to put the address of MEM into the form
988 that we can do analysis on.
6fb5fa3c
DB
989
990 The gold standard is to get the address into the form: address +
991 OFFSET where address is something that rtx_varies_p considers a
992 constant. When we can get the address in this form, we can do
993 global analysis on it. Note that for constant bases, address is
994 not actually returned, only the group_id. The address can be
995 obtained from that.
996
997 If that fails, we try cselib to get a value we can at least use
b8698a0f
L
998 locally. If that fails we return false.
999
6fb5fa3c
DB
1000 The GROUP_ID is set to -1 for cselib bases and the index of the
1001 group for non_varying bases.
1002
1003 FOR_READ is true if this is a mem read and false if not. */
1004
1005static bool
1006canon_address (rtx mem,
4862826d 1007 alias_set_type *alias_set_out,
6fb5fa3c 1008 int *group_id,
b8698a0f 1009 HOST_WIDE_INT *offset,
6fb5fa3c
DB
1010 cselib_val **base)
1011{
d4ebfa65
BE
1012 enum machine_mode address_mode
1013 = targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
6fb5fa3c
DB
1014 rtx mem_address = XEXP (mem, 0);
1015 rtx expanded_address, address;
403c7520
JJ
1016 int expanded;
1017
6fb5fa3c
DB
1018 /* Make sure that cselib is has initialized all of the operands of
1019 the address before asking it to do the subst. */
1020
1021 if (clear_alias_sets)
1022 {
1023 /* If this is a spill, do not do any further processing. */
4862826d 1024 alias_set_type alias_set = MEM_ALIAS_SET (mem);
6fb5fa3c 1025 if (dump_file)
4862826d 1026 fprintf (dump_file, "found alias set %d\n", (int) alias_set);
6fb5fa3c
DB
1027 if (bitmap_bit_p (clear_alias_sets, alias_set))
1028 {
b8698a0f 1029 struct clear_alias_mode_holder *entry
6fb5fa3c
DB
1030 = clear_alias_set_lookup (alias_set);
1031
1032 /* If the modes do not match, we cannot process this set. */
1033 if (entry->mode != GET_MODE (mem))
1034 {
1035 if (dump_file)
b8698a0f
L
1036 fprintf (dump_file,
1037 "disqualifying alias set %d, (%s) != (%s)\n",
1038 (int) alias_set, GET_MODE_NAME (entry->mode),
6fb5fa3c 1039 GET_MODE_NAME (GET_MODE (mem)));
b8698a0f 1040
6fb5fa3c
DB
1041 bitmap_set_bit (disqualified_clear_alias_sets, alias_set);
1042 return false;
1043 }
1044
1045 *alias_set_out = alias_set;
1046 *group_id = clear_alias_group->id;
1047 return true;
1048 }
1049 }
1050
1051 *alias_set_out = 0;
1052
4deef538 1053 cselib_lookup (mem_address, address_mode, 1, GET_MODE (mem));
6fb5fa3c
DB
1054
1055 if (dump_file)
1056 {
1057 fprintf (dump_file, " mem: ");
1058 print_inline_rtx (dump_file, mem_address, 0);
1059 fprintf (dump_file, "\n");
1060 }
1061
403c7520
JJ
1062 /* First see if just canon_rtx (mem_address) is const or frame,
1063 if not, try cselib_expand_value_rtx and call canon_rtx on that. */
1064 address = NULL_RTX;
1065 for (expanded = 0; expanded < 2; expanded++)
1066 {
1067 if (expanded)
1068 {
1069 /* Use cselib to replace all of the reg references with the full
b8698a0f 1070 expression. This will take care of the case where we have
6fb5fa3c 1071
403c7520
JJ
1072 r_x = base + offset;
1073 val = *r_x;
b8698a0f
L
1074
1075 by making it into
6fb5fa3c 1076
403c7520 1077 val = *(base + offset); */
6fb5fa3c 1078
403c7520
JJ
1079 expanded_address = cselib_expand_value_rtx (mem_address,
1080 scratch, 5);
6fb5fa3c 1081
403c7520
JJ
1082 /* If this fails, just go with the address from first
1083 iteration. */
1084 if (!expanded_address)
1085 break;
1086 }
1087 else
1088 expanded_address = mem_address;
6fb5fa3c 1089
403c7520
JJ
1090 /* Split the address into canonical BASE + OFFSET terms. */
1091 address = canon_rtx (expanded_address);
6fb5fa3c 1092
403c7520 1093 *offset = 0;
6fb5fa3c 1094
403c7520
JJ
1095 if (dump_file)
1096 {
1097 if (expanded)
1098 {
1099 fprintf (dump_file, "\n after cselib_expand address: ");
1100 print_inline_rtx (dump_file, expanded_address, 0);
1101 fprintf (dump_file, "\n");
1102 }
6fb5fa3c 1103
403c7520
JJ
1104 fprintf (dump_file, "\n after canon_rtx address: ");
1105 print_inline_rtx (dump_file, address, 0);
1106 fprintf (dump_file, "\n");
1107 }
6fb5fa3c 1108
403c7520
JJ
1109 if (GET_CODE (address) == CONST)
1110 address = XEXP (address, 0);
6fb5fa3c 1111
403c7520
JJ
1112 if (GET_CODE (address) == PLUS
1113 && CONST_INT_P (XEXP (address, 1)))
1114 {
1115 *offset = INTVAL (XEXP (address, 1));
1116 address = XEXP (address, 0);
1117 }
6fb5fa3c 1118
09e881c9
BE
1119 if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (mem))
1120 && const_or_frame_p (address))
6fb5fa3c 1121 {
403c7520
JJ
1122 group_info_t group = get_group_info (address);
1123
6fb5fa3c 1124 if (dump_file)
403c7520
JJ
1125 fprintf (dump_file, " gid=%d offset=%d \n",
1126 group->id, (int)*offset);
1127 *base = NULL;
1128 *group_id = group->id;
1129 return true;
6fb5fa3c 1130 }
403c7520
JJ
1131 }
1132
4deef538 1133 *base = cselib_lookup (address, address_mode, true, GET_MODE (mem));
403c7520
JJ
1134 *group_id = -1;
1135
1136 if (*base == NULL)
1137 {
6fb5fa3c 1138 if (dump_file)
403c7520
JJ
1139 fprintf (dump_file, " no cselib val - should be a wild read.\n");
1140 return false;
6fb5fa3c 1141 }
403c7520 1142 if (dump_file)
5440c0e7
AO
1143 fprintf (dump_file, " varying cselib base=%u:%u offset = %d\n",
1144 (*base)->uid, (*base)->hash, (int)*offset);
6fb5fa3c
DB
1145 return true;
1146}
1147
1148
1149/* Clear the rhs field from the active_local_stores array. */
1150
1151static void
1152clear_rhs_from_active_local_stores (void)
1153{
1154 insn_info_t ptr = active_local_stores;
1155
1156 while (ptr)
1157 {
1158 store_info_t store_info = ptr->store_rec;
1159 /* Skip the clobbers. */
1160 while (!store_info->is_set)
1161 store_info = store_info->next;
1162
1163 store_info->rhs = NULL;
8dd5516b 1164 store_info->const_rhs = NULL;
6fb5fa3c
DB
1165
1166 ptr = ptr->next_local_store;
1167 }
1168}
1169
1170
8dd5516b
JJ
1171/* Mark byte POS bytes from the beginning of store S_INFO as unneeded. */
1172
1173static inline void
1174set_position_unneeded (store_info_t s_info, int pos)
1175{
1176 if (__builtin_expect (s_info->is_large, false))
1177 {
fcaa4ca4
NF
1178 if (bitmap_set_bit (s_info->positions_needed.large.bmap, pos))
1179 s_info->positions_needed.large.count++;
8dd5516b
JJ
1180 }
1181 else
1182 s_info->positions_needed.small_bitmask
1183 &= ~(((unsigned HOST_WIDE_INT) 1) << pos);
1184}
1185
1186/* Mark the whole store S_INFO as unneeded. */
1187
1188static inline void
1189set_all_positions_unneeded (store_info_t s_info)
1190{
1191 if (__builtin_expect (s_info->is_large, false))
1192 {
1193 int pos, end = s_info->end - s_info->begin;
1194 for (pos = 0; pos < end; pos++)
dc491a25 1195 bitmap_set_bit (s_info->positions_needed.large.bmap, pos);
8dd5516b
JJ
1196 s_info->positions_needed.large.count = end;
1197 }
1198 else
1199 s_info->positions_needed.small_bitmask = (unsigned HOST_WIDE_INT) 0;
1200}
1201
1202/* Return TRUE if any bytes from S_INFO store are needed. */
1203
1204static inline bool
1205any_positions_needed_p (store_info_t s_info)
1206{
1207 if (__builtin_expect (s_info->is_large, false))
1208 return (s_info->positions_needed.large.count
1209 < s_info->end - s_info->begin);
1210 else
1211 return (s_info->positions_needed.small_bitmask
1212 != (unsigned HOST_WIDE_INT) 0);
1213}
1214
1215/* Return TRUE if all bytes START through START+WIDTH-1 from S_INFO
1216 store are needed. */
1217
1218static inline bool
1219all_positions_needed_p (store_info_t s_info, int start, int width)
1220{
1221 if (__builtin_expect (s_info->is_large, false))
1222 {
1223 int end = start + width;
1224 while (start < end)
dc491a25 1225 if (bitmap_bit_p (s_info->positions_needed.large.bmap, start++))
8dd5516b
JJ
1226 return false;
1227 return true;
1228 }
1229 else
1230 {
1231 unsigned HOST_WIDE_INT mask = lowpart_bitmask (width) << start;
1232 return (s_info->positions_needed.small_bitmask & mask) == mask;
1233 }
1234}
1235
1236
1237static rtx get_stored_val (store_info_t, enum machine_mode, HOST_WIDE_INT,
1238 HOST_WIDE_INT, basic_block, bool);
1239
1240
6fb5fa3c
DB
1241/* BODY is an instruction pattern that belongs to INSN. Return 1 if
1242 there is a candidate store, after adding it to the appropriate
1243 local store group if so. */
1244
1245static int
1246record_store (rtx body, bb_info_t bb_info)
1247{
6216f94e 1248 rtx mem, rhs, const_rhs, mem_addr;
6fb5fa3c
DB
1249 HOST_WIDE_INT offset = 0;
1250 HOST_WIDE_INT width = 0;
4862826d 1251 alias_set_type spill_alias_set;
6fb5fa3c
DB
1252 insn_info_t insn_info = bb_info->last_insn;
1253 store_info_t store_info = NULL;
1254 int group_id;
1255 cselib_val *base = NULL;
8dd5516b 1256 insn_info_t ptr, last, redundant_reason;
6fb5fa3c
DB
1257 bool store_is_unused;
1258
1259 if (GET_CODE (body) != SET && GET_CODE (body) != CLOBBER)
1260 return 0;
1261
8dd5516b
JJ
1262 mem = SET_DEST (body);
1263
6fb5fa3c
DB
1264 /* If this is not used, then this cannot be used to keep the insn
1265 from being deleted. On the other hand, it does provide something
1266 that can be used to prove that another store is dead. */
1267 store_is_unused
8dd5516b 1268 = (find_reg_note (insn_info->insn, REG_UNUSED, mem) != NULL);
6fb5fa3c
DB
1269
1270 /* Check whether that value is a suitable memory location. */
6fb5fa3c
DB
1271 if (!MEM_P (mem))
1272 {
1273 /* If the set or clobber is unused, then it does not effect our
1274 ability to get rid of the entire insn. */
1275 if (!store_is_unused)
1276 insn_info->cannot_delete = true;
1277 return 0;
1278 }
1279
1280 /* At this point we know mem is a mem. */
1281 if (GET_MODE (mem) == BLKmode)
1282 {
1283 if (GET_CODE (XEXP (mem, 0)) == SCRATCH)
1284 {
b8698a0f 1285 if (dump_file)
6fb5fa3c
DB
1286 fprintf (dump_file, " adding wild read for (clobber (mem:BLK (scratch))\n");
1287 add_wild_read (bb_info);
1288 insn_info->cannot_delete = true;
8dd5516b 1289 return 0;
6fb5fa3c 1290 }
8dd5516b
JJ
1291 /* Handle (set (mem:BLK (addr) [... S36 ...]) (const_int 0))
1292 as memset (addr, 0, 36); */
1293 else if (!MEM_SIZE (mem)
1294 || !CONST_INT_P (MEM_SIZE (mem))
1295 || GET_CODE (body) != SET
1296 || INTVAL (MEM_SIZE (mem)) <= 0
1297 || INTVAL (MEM_SIZE (mem)) > MAX_OFFSET
1298 || !CONST_INT_P (SET_SRC (body)))
6fb5fa3c 1299 {
8dd5516b
JJ
1300 if (!store_is_unused)
1301 {
1302 /* If the set or clobber is unused, then it does not effect our
1303 ability to get rid of the entire insn. */
1304 insn_info->cannot_delete = true;
1305 clear_rhs_from_active_local_stores ();
1306 }
1307 return 0;
6fb5fa3c 1308 }
6fb5fa3c
DB
1309 }
1310
1311 /* We can still process a volatile mem, we just cannot delete it. */
1312 if (MEM_VOLATILE_P (mem))
8dd5516b 1313 insn_info->cannot_delete = true;
6fb5fa3c
DB
1314
1315 if (!canon_address (mem, &spill_alias_set, &group_id, &offset, &base))
1316 {
1317 clear_rhs_from_active_local_stores ();
1318 return 0;
1319 }
1320
8dd5516b
JJ
1321 if (GET_MODE (mem) == BLKmode)
1322 width = INTVAL (MEM_SIZE (mem));
1323 else
1324 {
1325 width = GET_MODE_SIZE (GET_MODE (mem));
1326 gcc_assert ((unsigned) width <= HOST_BITS_PER_WIDE_INT);
1327 }
6fb5fa3c
DB
1328
1329 if (spill_alias_set)
1330 {
1331 bitmap store1 = clear_alias_group->store1_p;
1332 bitmap store2 = clear_alias_group->store2_p;
8dd5516b
JJ
1333
1334 gcc_assert (GET_MODE (mem) != BLKmode);
b8698a0f 1335
fcaa4ca4 1336 if (!bitmap_set_bit (store1, spill_alias_set))
6fb5fa3c 1337 bitmap_set_bit (store2, spill_alias_set);
b8698a0f 1338
6fb5fa3c
DB
1339 if (clear_alias_group->offset_map_size_p < spill_alias_set)
1340 clear_alias_group->offset_map_size_p = spill_alias_set;
b8698a0f 1341
f883e0a7 1342 store_info = (store_info_t) pool_alloc (rtx_store_info_pool);
6fb5fa3c
DB
1343
1344 if (dump_file)
1345 fprintf (dump_file, " processing spill store %d(%s)\n",
4862826d 1346 (int) spill_alias_set, GET_MODE_NAME (GET_MODE (mem)));
6fb5fa3c
DB
1347 }
1348 else if (group_id >= 0)
1349 {
1350 /* In the restrictive case where the base is a constant or the
1351 frame pointer we can do global analysis. */
b8698a0f
L
1352
1353 group_info_t group
6fb5fa3c 1354 = VEC_index (group_info_t, rtx_group_vec, group_id);
b8698a0f 1355
f883e0a7 1356 store_info = (store_info_t) pool_alloc (rtx_store_info_pool);
6fb5fa3c
DB
1357 set_usage_bits (group, offset, width);
1358
1359 if (dump_file)
1360 fprintf (dump_file, " processing const base store gid=%d[%d..%d)\n",
1361 group_id, (int)offset, (int)(offset+width));
1362 }
1363 else
1364 {
50f0f366
EB
1365 rtx base_term = find_base_term (XEXP (mem, 0));
1366 if (!base_term
1367 || (GET_CODE (base_term) == ADDRESS
1368 && GET_MODE (base_term) == Pmode
1369 && XEXP (base_term, 0) == stack_pointer_rtx))
1370 insn_info->stack_pointer_based = true;
6fb5fa3c 1371 insn_info->contains_cselib_groups = true;
50f0f366 1372
f883e0a7 1373 store_info = (store_info_t) pool_alloc (cse_store_info_pool);
6fb5fa3c
DB
1374 group_id = -1;
1375
1376 if (dump_file)
1377 fprintf (dump_file, " processing cselib store [%d..%d)\n",
1378 (int)offset, (int)(offset+width));
1379 }
1380
8dd5516b
JJ
1381 const_rhs = rhs = NULL_RTX;
1382 if (GET_CODE (body) == SET
1383 /* No place to keep the value after ra. */
1384 && !reload_completed
1385 && (REG_P (SET_SRC (body))
1386 || GET_CODE (SET_SRC (body)) == SUBREG
1387 || CONSTANT_P (SET_SRC (body)))
1388 && !MEM_VOLATILE_P (mem)
1389 /* Sometimes the store and reload is used for truncation and
1390 rounding. */
1391 && !(FLOAT_MODE_P (GET_MODE (mem)) && (flag_float_store)))
1392 {
1393 rhs = SET_SRC (body);
1394 if (CONSTANT_P (rhs))
1395 const_rhs = rhs;
1396 else if (body == PATTERN (insn_info->insn))
1397 {
1398 rtx tem = find_reg_note (insn_info->insn, REG_EQUAL, NULL_RTX);
1399 if (tem && CONSTANT_P (XEXP (tem, 0)))
1400 const_rhs = XEXP (tem, 0);
1401 }
1402 if (const_rhs == NULL_RTX && REG_P (rhs))
1403 {
1404 rtx tem = cselib_expand_value_rtx (rhs, scratch, 5);
1405
1406 if (tem && CONSTANT_P (tem))
1407 const_rhs = tem;
1408 }
1409 }
1410
6fb5fa3c
DB
1411 /* Check to see if this stores causes some other stores to be
1412 dead. */
1413 ptr = active_local_stores;
1414 last = NULL;
8dd5516b 1415 redundant_reason = NULL;
6216f94e
JJ
1416 mem = canon_rtx (mem);
1417 /* For alias_set != 0 canon_true_dependence should be never called. */
1418 if (spill_alias_set)
1419 mem_addr = NULL_RTX;
1420 else
1421 {
1422 if (group_id < 0)
1423 mem_addr = base->val_rtx;
1424 else
1425 {
1426 group_info_t group
1427 = VEC_index (group_info_t, rtx_group_vec, group_id);
1428 mem_addr = group->canon_base_addr;
1429 }
1430 if (offset)
1431 mem_addr = plus_constant (mem_addr, offset);
1432 }
6fb5fa3c
DB
1433
1434 while (ptr)
1435 {
1436 insn_info_t next = ptr->next_local_store;
1437 store_info_t s_info = ptr->store_rec;
60564289 1438 bool del = true;
6fb5fa3c
DB
1439
1440 /* Skip the clobbers. We delete the active insn if this insn
6ed3da00 1441 shadows the set. To have been put on the active list, it
6fb5fa3c
DB
1442 has exactly on set. */
1443 while (!s_info->is_set)
1444 s_info = s_info->next;
1445
1446 if (s_info->alias_set != spill_alias_set)
60564289 1447 del = false;
6fb5fa3c
DB
1448 else if (s_info->alias_set)
1449 {
b8698a0f 1450 struct clear_alias_mode_holder *entry
6fb5fa3c
DB
1451 = clear_alias_set_lookup (s_info->alias_set);
1452 /* Generally, spills cannot be processed if and of the
1453 references to the slot have a different mode. But if
1454 we are in the same block and mode is exactly the same
1455 between this store and one before in the same block,
1456 we can still delete it. */
1457 if ((GET_MODE (mem) == GET_MODE (s_info->mem))
1458 && (GET_MODE (mem) == entry->mode))
1459 {
60564289 1460 del = true;
8dd5516b 1461 set_all_positions_unneeded (s_info);
6fb5fa3c
DB
1462 }
1463 if (dump_file)
1464 fprintf (dump_file, " trying spill store in insn=%d alias_set=%d\n",
4862826d 1465 INSN_UID (ptr->insn), (int) s_info->alias_set);
6fb5fa3c 1466 }
b8698a0f 1467 else if ((s_info->group_id == group_id)
6fb5fa3c
DB
1468 && (s_info->cse_base == base))
1469 {
1470 HOST_WIDE_INT i;
1471 if (dump_file)
1472 fprintf (dump_file, " trying store in insn=%d gid=%d[%d..%d)\n",
b8698a0f 1473 INSN_UID (ptr->insn), s_info->group_id,
6fb5fa3c 1474 (int)s_info->begin, (int)s_info->end);
8dd5516b
JJ
1475
1476 /* Even if PTR won't be eliminated as unneeded, if both
1477 PTR and this insn store the same constant value, we might
1478 eliminate this insn instead. */
1479 if (s_info->const_rhs
1480 && const_rhs
1481 && offset >= s_info->begin
1482 && offset + width <= s_info->end
1483 && all_positions_needed_p (s_info, offset - s_info->begin,
1484 width))
1485 {
1486 if (GET_MODE (mem) == BLKmode)
1487 {
1488 if (GET_MODE (s_info->mem) == BLKmode
1489 && s_info->const_rhs == const_rhs)
1490 redundant_reason = ptr;
1491 }
1492 else if (s_info->const_rhs == const0_rtx
1493 && const_rhs == const0_rtx)
1494 redundant_reason = ptr;
1495 else
1496 {
1497 rtx val;
1498 start_sequence ();
1499 val = get_stored_val (s_info, GET_MODE (mem),
1500 offset, offset + width,
1501 BLOCK_FOR_INSN (insn_info->insn),
1502 true);
1503 if (get_insns () != NULL)
1504 val = NULL_RTX;
1505 end_sequence ();
1506 if (val && rtx_equal_p (val, const_rhs))
1507 redundant_reason = ptr;
1508 }
1509 }
1510
1511 for (i = MAX (offset, s_info->begin);
1512 i < offset + width && i < s_info->end;
1513 i++)
1514 set_position_unneeded (s_info, i - s_info->begin);
6fb5fa3c
DB
1515 }
1516 else if (s_info->rhs)
1517 /* Need to see if it is possible for this store to overwrite
1518 the value of store_info. If it is, set the rhs to NULL to
1519 keep it from being used to remove a load. */
1520 {
b8698a0f 1521 if (canon_true_dependence (s_info->mem,
6fb5fa3c
DB
1522 GET_MODE (s_info->mem),
1523 s_info->mem_addr,
6216f94e 1524 mem, mem_addr, rtx_varies_p))
8dd5516b
JJ
1525 {
1526 s_info->rhs = NULL;
1527 s_info->const_rhs = NULL;
1528 }
6fb5fa3c 1529 }
6216f94e 1530
6fb5fa3c
DB
1531 /* An insn can be deleted if every position of every one of
1532 its s_infos is zero. */
8dd5516b
JJ
1533 if (any_positions_needed_p (s_info)
1534 || ptr->cannot_delete)
60564289 1535 del = false;
8dd5516b 1536
60564289 1537 if (del)
6fb5fa3c
DB
1538 {
1539 insn_info_t insn_to_delete = ptr;
b8698a0f 1540
6fb5fa3c
DB
1541 if (last)
1542 last->next_local_store = ptr->next_local_store;
1543 else
1544 active_local_stores = ptr->next_local_store;
b8698a0f 1545
6fb5fa3c
DB
1546 delete_dead_store_insn (insn_to_delete);
1547 }
1548 else
1549 last = ptr;
b8698a0f 1550
6fb5fa3c
DB
1551 ptr = next;
1552 }
b8698a0f 1553
6fb5fa3c
DB
1554 /* Finish filling in the store_info. */
1555 store_info->next = insn_info->store_rec;
1556 insn_info->store_rec = store_info;
6216f94e 1557 store_info->mem = mem;
6fb5fa3c 1558 store_info->alias_set = spill_alias_set;
6216f94e 1559 store_info->mem_addr = mem_addr;
6fb5fa3c 1560 store_info->cse_base = base;
8dd5516b
JJ
1561 if (width > HOST_BITS_PER_WIDE_INT)
1562 {
1563 store_info->is_large = true;
1564 store_info->positions_needed.large.count = 0;
dc491a25 1565 store_info->positions_needed.large.bmap = BITMAP_ALLOC (NULL);
8dd5516b
JJ
1566 }
1567 else
1568 {
1569 store_info->is_large = false;
1570 store_info->positions_needed.small_bitmask = lowpart_bitmask (width);
1571 }
6fb5fa3c
DB
1572 store_info->group_id = group_id;
1573 store_info->begin = offset;
1574 store_info->end = offset + width;
1575 store_info->is_set = GET_CODE (body) == SET;
8dd5516b
JJ
1576 store_info->rhs = rhs;
1577 store_info->const_rhs = const_rhs;
1578 store_info->redundant_reason = redundant_reason;
6fb5fa3c 1579
6fb5fa3c
DB
1580 /* If this is a clobber, we return 0. We will only be able to
1581 delete this insn if there is only one store USED store, but we
1582 can use the clobber to delete other stores earlier. */
1583 return store_info->is_set ? 1 : 0;
1584}
1585
1586
1587static void
1588dump_insn_info (const char * start, insn_info_t insn_info)
1589{
b8698a0f 1590 fprintf (dump_file, "%s insn=%d %s\n", start,
6fb5fa3c
DB
1591 INSN_UID (insn_info->insn),
1592 insn_info->store_rec ? "has store" : "naked");
1593}
1594
1595
8660aaae
EC
1596/* If the modes are different and the value's source and target do not
1597 line up, we need to extract the value from lower part of the rhs of
1598 the store, shift it, and then put it into a form that can be shoved
1599 into the read_insn. This function generates a right SHIFT of a
1600 value that is at least ACCESS_SIZE bytes wide of READ_MODE. The
1601 shift sequence is returned or NULL if we failed to find a
1602 shift. */
1603
1604static rtx
18b526e8 1605find_shift_sequence (int access_size,
8660aaae 1606 store_info_t store_info,
8dd5516b
JJ
1607 enum machine_mode read_mode,
1608 int shift, bool speed, bool require_cst)
8660aaae
EC
1609{
1610 enum machine_mode store_mode = GET_MODE (store_info->mem);
18b526e8
RS
1611 enum machine_mode new_mode;
1612 rtx read_reg = NULL;
8660aaae
EC
1613
1614 /* Some machines like the x86 have shift insns for each size of
1615 operand. Other machines like the ppc or the ia-64 may only have
1616 shift insns that shift values within 32 or 64 bit registers.
1617 This loop tries to find the smallest shift insn that will right
1618 justify the value we want to read but is available in one insn on
1619 the machine. */
1620
18b526e8
RS
1621 for (new_mode = smallest_mode_for_size (access_size * BITS_PER_UNIT,
1622 MODE_INT);
1623 GET_MODE_BITSIZE (new_mode) <= BITS_PER_WORD;
1624 new_mode = GET_MODE_WIDER_MODE (new_mode))
8660aaae 1625 {
18b526e8 1626 rtx target, new_reg, shift_seq, insn, new_lhs;
d898d29b 1627 int cost;
348eea5f 1628
72a2609f
JJ
1629 /* If a constant was stored into memory, try to simplify it here,
1630 otherwise the cost of the shift might preclude this optimization
1631 e.g. at -Os, even when no actual shift will be needed. */
8dd5516b 1632 if (store_info->const_rhs)
72a2609f
JJ
1633 {
1634 unsigned int byte = subreg_lowpart_offset (new_mode, store_mode);
8dd5516b
JJ
1635 rtx ret = simplify_subreg (new_mode, store_info->const_rhs,
1636 store_mode, byte);
72a2609f
JJ
1637 if (ret && CONSTANT_P (ret))
1638 {
1639 ret = simplify_const_binary_operation (LSHIFTRT, new_mode,
1640 ret, GEN_INT (shift));
1641 if (ret && CONSTANT_P (ret))
1642 {
1643 byte = subreg_lowpart_offset (read_mode, new_mode);
1644 ret = simplify_subreg (read_mode, ret, new_mode, byte);
1645 if (ret && CONSTANT_P (ret)
1646 && rtx_cost (ret, SET, speed) <= COSTS_N_INSNS (1))
1647 return ret;
1648 }
1649 }
1650 }
1651
8dd5516b
JJ
1652 if (require_cst)
1653 return NULL_RTX;
1654
18b526e8
RS
1655 /* Try a wider mode if truncating the store mode to NEW_MODE
1656 requires a real instruction. */
1657 if (GET_MODE_BITSIZE (new_mode) < GET_MODE_BITSIZE (store_mode)
1658 && !TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (new_mode),
348eea5f
RS
1659 GET_MODE_BITSIZE (store_mode)))
1660 continue;
1661
18b526e8
RS
1662 /* Also try a wider mode if the necessary punning is either not
1663 desirable or not possible. */
1664 if (!CONSTANT_P (store_info->rhs)
1665 && !MODES_TIEABLE_P (new_mode, store_mode))
1666 continue;
18b526e8 1667
348eea5f 1668 new_reg = gen_reg_rtx (new_mode);
8660aaae
EC
1669
1670 start_sequence ();
1671
1672 /* In theory we could also check for an ashr. Ian Taylor knows
1673 of one dsp where the cost of these two was not the same. But
1674 this really is a rare case anyway. */
1675 target = expand_binop (new_mode, lshr_optab, new_reg,
1676 GEN_INT (shift), new_reg, 1, OPTAB_DIRECT);
1677
c6f3019a
RS
1678 shift_seq = get_insns ();
1679 end_sequence ();
8660aaae 1680
c6f3019a
RS
1681 if (target != new_reg || shift_seq == NULL)
1682 continue;
1683
1684 cost = 0;
1685 for (insn = shift_seq; insn != NULL_RTX; insn = NEXT_INSN (insn))
1686 if (INSN_P (insn))
f40751dd 1687 cost += insn_rtx_cost (PATTERN (insn), speed);
c6f3019a
RS
1688
1689 /* The computation up to here is essentially independent
1690 of the arguments and could be precomputed. It may
1691 not be worth doing so. We could precompute if
1692 worthwhile or at least cache the results. The result
06acf7d0
RS
1693 technically depends on both SHIFT and ACCESS_SIZE,
1694 but in practice the answer will depend only on ACCESS_SIZE. */
c6f3019a
RS
1695
1696 if (cost > COSTS_N_INSNS (1))
1697 continue;
1698
d898d29b
JJ
1699 new_lhs = extract_low_bits (new_mode, store_mode,
1700 copy_rtx (store_info->rhs));
1701 if (new_lhs == NULL_RTX)
1702 continue;
1703
c6f3019a
RS
1704 /* We found an acceptable shift. Generate a move to
1705 take the value from the store and put it into the
1706 shift pseudo, then shift it, then generate another
1707 move to put in into the target of the read. */
18b526e8 1708 emit_move_insn (new_reg, new_lhs);
c6f3019a 1709 emit_insn (shift_seq);
18b526e8 1710 read_reg = extract_low_bits (read_mode, new_mode, new_reg);
c6f3019a 1711 break;
8660aaae
EC
1712 }
1713
18b526e8 1714 return read_reg;
8660aaae
EC
1715}
1716
1717
02b47899
KZ
1718/* Call back for note_stores to find the hard regs set or clobbered by
1719 insn. Data is a bitmap of the hardregs set so far. */
1720
1721static void
1722look_for_hardregs (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
1723{
1724 bitmap regs_set = (bitmap) data;
1725
1726 if (REG_P (x)
1727 && REGNO (x) < FIRST_PSEUDO_REGISTER)
1728 {
1729 int regno = REGNO (x);
1730 int n = hard_regno_nregs[regno][GET_MODE (x)];
1731 while (--n >= 0)
1732 bitmap_set_bit (regs_set, regno + n);
1733 }
1734}
1735
8dd5516b
JJ
1736/* Helper function for replace_read and record_store.
1737 Attempt to return a value stored in STORE_INFO, from READ_BEGIN
1738 to one before READ_END bytes read in READ_MODE. Return NULL
1739 if not successful. If REQUIRE_CST is true, return always constant. */
1740
1741static rtx
1742get_stored_val (store_info_t store_info, enum machine_mode read_mode,
1743 HOST_WIDE_INT read_begin, HOST_WIDE_INT read_end,
1744 basic_block bb, bool require_cst)
1745{
1746 enum machine_mode store_mode = GET_MODE (store_info->mem);
1747 int shift;
1748 int access_size; /* In bytes. */
1749 rtx read_reg;
1750
1751 /* To get here the read is within the boundaries of the write so
1752 shift will never be negative. Start out with the shift being in
1753 bytes. */
1754 if (store_mode == BLKmode)
1755 shift = 0;
1756 else if (BYTES_BIG_ENDIAN)
1757 shift = store_info->end - read_end;
1758 else
1759 shift = read_begin - store_info->begin;
1760
1761 access_size = shift + GET_MODE_SIZE (read_mode);
1762
1763 /* From now on it is bits. */
1764 shift *= BITS_PER_UNIT;
1765
1766 if (shift)
1767 read_reg = find_shift_sequence (access_size, store_info, read_mode, shift,
1768 optimize_bb_for_speed_p (bb),
1769 require_cst);
1770 else if (store_mode == BLKmode)
1771 {
1772 /* The store is a memset (addr, const_val, const_size). */
1773 gcc_assert (CONST_INT_P (store_info->rhs));
1774 store_mode = int_mode_for_mode (read_mode);
1775 if (store_mode == BLKmode)
1776 read_reg = NULL_RTX;
1777 else if (store_info->rhs == const0_rtx)
1778 read_reg = extract_low_bits (read_mode, store_mode, const0_rtx);
1779 else if (GET_MODE_BITSIZE (store_mode) > HOST_BITS_PER_WIDE_INT
1780 || BITS_PER_UNIT >= HOST_BITS_PER_WIDE_INT)
1781 read_reg = NULL_RTX;
1782 else
1783 {
1784 unsigned HOST_WIDE_INT c
1785 = INTVAL (store_info->rhs)
1786 & (((HOST_WIDE_INT) 1 << BITS_PER_UNIT) - 1);
1787 int shift = BITS_PER_UNIT;
1788 while (shift < HOST_BITS_PER_WIDE_INT)
1789 {
1790 c |= (c << shift);
1791 shift <<= 1;
1792 }
1793 read_reg = GEN_INT (trunc_int_for_mode (c, store_mode));
1794 read_reg = extract_low_bits (read_mode, store_mode, read_reg);
1795 }
1796 }
1797 else if (store_info->const_rhs
1798 && (require_cst
1799 || GET_MODE_CLASS (read_mode) != GET_MODE_CLASS (store_mode)))
1800 read_reg = extract_low_bits (read_mode, store_mode,
1801 copy_rtx (store_info->const_rhs));
1802 else
1803 read_reg = extract_low_bits (read_mode, store_mode,
1804 copy_rtx (store_info->rhs));
1805 if (require_cst && read_reg && !CONSTANT_P (read_reg))
1806 read_reg = NULL_RTX;
1807 return read_reg;
1808}
02b47899 1809
6fb5fa3c
DB
1810/* Take a sequence of:
1811 A <- r1
1812 ...
1813 ... <- A
1814
b8698a0f 1815 and change it into
6fb5fa3c
DB
1816 r2 <- r1
1817 A <- r1
1818 ...
1819 ... <- r2
1820
8660aaae
EC
1821 or
1822
1823 r3 <- extract (r1)
1824 r3 <- r3 >> shift
1825 r2 <- extract (r3)
1826 ... <- r2
1827
1828 or
1829
1830 r2 <- extract (r1)
1831 ... <- r2
1832
1833 Depending on the alignment and the mode of the store and
1834 subsequent load.
1835
1836
1837 The STORE_INFO and STORE_INSN are for the store and READ_INFO
6fb5fa3c
DB
1838 and READ_INSN are for the read. Return true if the replacement
1839 went ok. */
1840
1841static bool
b8698a0f 1842replace_read (store_info_t store_info, insn_info_t store_insn,
8dd5516b
JJ
1843 read_info_t read_info, insn_info_t read_insn, rtx *loc,
1844 bitmap regs_live)
6fb5fa3c 1845{
8660aaae
EC
1846 enum machine_mode store_mode = GET_MODE (store_info->mem);
1847 enum machine_mode read_mode = GET_MODE (read_info->mem);
02b47899 1848 rtx insns, this_insn, read_reg;
8dd5516b 1849 basic_block bb;
8660aaae 1850
6fb5fa3c
DB
1851 if (!dbg_cnt (dse))
1852 return false;
1853
18b526e8
RS
1854 /* Create a sequence of instructions to set up the read register.
1855 This sequence goes immediately before the store and its result
1856 is read by the load.
1857
1858 We need to keep this in perspective. We are replacing a read
8660aaae
EC
1859 with a sequence of insns, but the read will almost certainly be
1860 in cache, so it is not going to be an expensive one. Thus, we
1861 are not willing to do a multi insn shift or worse a subroutine
1862 call to get rid of the read. */
18b526e8
RS
1863 if (dump_file)
1864 fprintf (dump_file, "trying to replace %smode load in insn %d"
1865 " from %smode store in insn %d\n",
1866 GET_MODE_NAME (read_mode), INSN_UID (read_insn->insn),
1867 GET_MODE_NAME (store_mode), INSN_UID (store_insn->insn));
1868 start_sequence ();
8dd5516b
JJ
1869 bb = BLOCK_FOR_INSN (read_insn->insn);
1870 read_reg = get_stored_val (store_info,
1871 read_mode, read_info->begin, read_info->end,
1872 bb, false);
18b526e8 1873 if (read_reg == NULL_RTX)
8660aaae 1874 {
18b526e8
RS
1875 end_sequence ();
1876 if (dump_file)
1877 fprintf (dump_file, " -- could not extract bits of stored value\n");
1878 return false;
8660aaae 1879 }
18b526e8
RS
1880 /* Force the value into a new register so that it won't be clobbered
1881 between the store and the load. */
1882 read_reg = copy_to_mode_reg (read_mode, read_reg);
1883 insns = get_insns ();
1884 end_sequence ();
8660aaae 1885
02b47899
KZ
1886 if (insns != NULL_RTX)
1887 {
1888 /* Now we have to scan the set of new instructions to see if the
1889 sequence contains and sets of hardregs that happened to be
1890 live at this point. For instance, this can happen if one of
1891 the insns sets the CC and the CC happened to be live at that
1892 point. This does occasionally happen, see PR 37922. */
1893 bitmap regs_set = BITMAP_ALLOC (NULL);
1894
1895 for (this_insn = insns; this_insn != NULL_RTX; this_insn = NEXT_INSN (this_insn))
1896 note_stores (PATTERN (this_insn), look_for_hardregs, regs_set);
b8698a0f 1897
02b47899
KZ
1898 bitmap_and_into (regs_set, regs_live);
1899 if (!bitmap_empty_p (regs_set))
1900 {
1901 if (dump_file)
1902 {
b8698a0f 1903 fprintf (dump_file,
02b47899
KZ
1904 "abandoning replacement because sequence clobbers live hardregs:");
1905 df_print_regset (dump_file, regs_set);
1906 }
b8698a0f 1907
02b47899
KZ
1908 BITMAP_FREE (regs_set);
1909 return false;
1910 }
1911 BITMAP_FREE (regs_set);
1912 }
1913
8660aaae 1914 if (validate_change (read_insn->insn, loc, read_reg, 0))
6fb5fa3c 1915 {
f883e0a7
KG
1916 deferred_change_t deferred_change =
1917 (deferred_change_t) pool_alloc (deferred_change_pool);
b8698a0f 1918
8660aaae
EC
1919 /* Insert this right before the store insn where it will be safe
1920 from later insns that might change it before the read. */
1921 emit_insn_before (insns, store_insn->insn);
b8698a0f 1922
8660aaae
EC
1923 /* And now for the kludge part: cselib croaks if you just
1924 return at this point. There are two reasons for this:
b8698a0f 1925
8660aaae
EC
1926 1) Cselib has an idea of how many pseudos there are and
1927 that does not include the new ones we just added.
b8698a0f 1928
8660aaae
EC
1929 2) Cselib does not know about the move insn we added
1930 above the store_info, and there is no way to tell it
1931 about it, because it has "moved on".
b8698a0f 1932
8660aaae
EC
1933 Problem (1) is fixable with a certain amount of engineering.
1934 Problem (2) is requires starting the bb from scratch. This
1935 could be expensive.
b8698a0f 1936
8660aaae
EC
1937 So we are just going to have to lie. The move/extraction
1938 insns are not really an issue, cselib did not see them. But
1939 the use of the new pseudo read_insn is a real problem because
1940 cselib has not scanned this insn. The way that we solve this
1941 problem is that we are just going to put the mem back for now
1942 and when we are finished with the block, we undo this. We
1943 keep a table of mems to get rid of. At the end of the basic
1944 block we can put them back. */
b8698a0f 1945
8660aaae
EC
1946 *loc = read_info->mem;
1947 deferred_change->next = deferred_change_list;
1948 deferred_change_list = deferred_change;
1949 deferred_change->loc = loc;
1950 deferred_change->reg = read_reg;
b8698a0f 1951
8660aaae
EC
1952 /* Get rid of the read_info, from the point of view of the
1953 rest of dse, play like this read never happened. */
1954 read_insn->read_rec = read_info->next;
1955 pool_free (read_info_pool, read_info);
18b526e8
RS
1956 if (dump_file)
1957 {
1958 fprintf (dump_file, " -- replaced the loaded MEM with ");
1959 print_simple_rtl (dump_file, read_reg);
1960 fprintf (dump_file, "\n");
1961 }
8660aaae 1962 return true;
6fb5fa3c 1963 }
b8698a0f 1964 else
6fb5fa3c 1965 {
6fb5fa3c 1966 if (dump_file)
18b526e8
RS
1967 {
1968 fprintf (dump_file, " -- replacing the loaded MEM with ");
1969 print_simple_rtl (dump_file, read_reg);
1970 fprintf (dump_file, " led to an invalid instruction\n");
1971 }
6fb5fa3c
DB
1972 return false;
1973 }
1974}
1975
6fb5fa3c
DB
1976/* A for_each_rtx callback in which DATA is the bb_info. Check to see
1977 if LOC is a mem and if it is look at the address and kill any
1978 appropriate stores that may be active. */
1979
1980static int
1981check_mem_read_rtx (rtx *loc, void *data)
1982{
6216f94e 1983 rtx mem = *loc, mem_addr;
6fb5fa3c
DB
1984 bb_info_t bb_info;
1985 insn_info_t insn_info;
1986 HOST_WIDE_INT offset = 0;
1987 HOST_WIDE_INT width = 0;
4862826d 1988 alias_set_type spill_alias_set = 0;
b8698a0f 1989 cselib_val *base = NULL;
6fb5fa3c
DB
1990 int group_id;
1991 read_info_t read_info;
1992
1993 if (!mem || !MEM_P (mem))
1994 return 0;
1995
1996 bb_info = (bb_info_t) data;
1997 insn_info = bb_info->last_insn;
1998
1999 if ((MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
2000 || (MEM_VOLATILE_P (mem)))
2001 {
2002 if (dump_file)
2003 fprintf (dump_file, " adding wild read, volatile or barrier.\n");
2004 add_wild_read (bb_info);
2005 insn_info->cannot_delete = true;
2006 return 0;
2007 }
2008
2009 /* If it is reading readonly mem, then there can be no conflict with
2010 another write. */
2011 if (MEM_READONLY_P (mem))
2012 return 0;
2013
2014 if (!canon_address (mem, &spill_alias_set, &group_id, &offset, &base))
2015 {
2016 if (dump_file)
2017 fprintf (dump_file, " adding wild read, canon_address failure.\n");
2018 add_wild_read (bb_info);
2019 return 0;
2020 }
2021
2022 if (GET_MODE (mem) == BLKmode)
2023 width = -1;
2024 else
2025 width = GET_MODE_SIZE (GET_MODE (mem));
2026
f883e0a7 2027 read_info = (read_info_t) pool_alloc (read_info_pool);
6fb5fa3c
DB
2028 read_info->group_id = group_id;
2029 read_info->mem = mem;
2030 read_info->alias_set = spill_alias_set;
2031 read_info->begin = offset;
2032 read_info->end = offset + width;
2033 read_info->next = insn_info->read_rec;
2034 insn_info->read_rec = read_info;
6216f94e
JJ
2035 /* For alias_set != 0 canon_true_dependence should be never called. */
2036 if (spill_alias_set)
2037 mem_addr = NULL_RTX;
2038 else
2039 {
2040 if (group_id < 0)
2041 mem_addr = base->val_rtx;
2042 else
2043 {
2044 group_info_t group
2045 = VEC_index (group_info_t, rtx_group_vec, group_id);
2046 mem_addr = group->canon_base_addr;
2047 }
2048 if (offset)
2049 mem_addr = plus_constant (mem_addr, offset);
2050 }
6fb5fa3c 2051
0d52bcc1 2052 /* We ignore the clobbers in store_info. The is mildly aggressive,
6fb5fa3c
DB
2053 but there really should not be a clobber followed by a read. */
2054
2055 if (spill_alias_set)
2056 {
2057 insn_info_t i_ptr = active_local_stores;
2058 insn_info_t last = NULL;
2059
2060 if (dump_file)
2061 fprintf (dump_file, " processing spill load %d\n",
4862826d 2062 (int) spill_alias_set);
6fb5fa3c
DB
2063
2064 while (i_ptr)
2065 {
2066 store_info_t store_info = i_ptr->store_rec;
2067
2068 /* Skip the clobbers. */
2069 while (!store_info->is_set)
2070 store_info = store_info->next;
b8698a0f 2071
6fb5fa3c
DB
2072 if (store_info->alias_set == spill_alias_set)
2073 {
2074 if (dump_file)
2075 dump_insn_info ("removing from active", i_ptr);
2076
2077 if (last)
2078 last->next_local_store = i_ptr->next_local_store;
2079 else
2080 active_local_stores = i_ptr->next_local_store;
2081 }
2082 else
2083 last = i_ptr;
2084 i_ptr = i_ptr->next_local_store;
2085 }
2086 }
2087 else if (group_id >= 0)
2088 {
2089 /* This is the restricted case where the base is a constant or
2090 the frame pointer and offset is a constant. */
2091 insn_info_t i_ptr = active_local_stores;
2092 insn_info_t last = NULL;
b8698a0f 2093
6fb5fa3c
DB
2094 if (dump_file)
2095 {
2096 if (width == -1)
2097 fprintf (dump_file, " processing const load gid=%d[BLK]\n",
2098 group_id);
2099 else
2100 fprintf (dump_file, " processing const load gid=%d[%d..%d)\n",
2101 group_id, (int)offset, (int)(offset+width));
2102 }
2103
2104 while (i_ptr)
2105 {
2106 bool remove = false;
2107 store_info_t store_info = i_ptr->store_rec;
b8698a0f 2108
6fb5fa3c
DB
2109 /* Skip the clobbers. */
2110 while (!store_info->is_set)
2111 store_info = store_info->next;
b8698a0f 2112
6fb5fa3c
DB
2113 /* There are three cases here. */
2114 if (store_info->group_id < 0)
2115 /* We have a cselib store followed by a read from a
2116 const base. */
b8698a0f
L
2117 remove
2118 = canon_true_dependence (store_info->mem,
6fb5fa3c
DB
2119 GET_MODE (store_info->mem),
2120 store_info->mem_addr,
6216f94e 2121 mem, mem_addr, rtx_varies_p);
b8698a0f 2122
6fb5fa3c
DB
2123 else if (group_id == store_info->group_id)
2124 {
2125 /* This is a block mode load. We may get lucky and
2126 canon_true_dependence may save the day. */
2127 if (width == -1)
b8698a0f
L
2128 remove
2129 = canon_true_dependence (store_info->mem,
6fb5fa3c
DB
2130 GET_MODE (store_info->mem),
2131 store_info->mem_addr,
6216f94e 2132 mem, mem_addr, rtx_varies_p);
b8698a0f 2133
6fb5fa3c
DB
2134 /* If this read is just reading back something that we just
2135 stored, rewrite the read. */
b8698a0f 2136 else
6fb5fa3c
DB
2137 {
2138 if (store_info->rhs
8dd5516b
JJ
2139 && offset >= store_info->begin
2140 && offset + width <= store_info->end
2141 && all_positions_needed_p (store_info,
2142 offset - store_info->begin,
2143 width)
2144 && replace_read (store_info, i_ptr, read_info,
2145 insn_info, loc, bb_info->regs_live))
2146 return 0;
2147
6fb5fa3c
DB
2148 /* The bases are the same, just see if the offsets
2149 overlap. */
b8698a0f 2150 if ((offset < store_info->end)
6fb5fa3c
DB
2151 && (offset + width > store_info->begin))
2152 remove = true;
2153 }
2154 }
b8698a0f
L
2155
2156 /* else
6fb5fa3c
DB
2157 The else case that is missing here is that the
2158 bases are constant but different. There is nothing
2159 to do here because there is no overlap. */
b8698a0f 2160
6fb5fa3c
DB
2161 if (remove)
2162 {
2163 if (dump_file)
2164 dump_insn_info ("removing from active", i_ptr);
2165
2166 if (last)
2167 last->next_local_store = i_ptr->next_local_store;
2168 else
2169 active_local_stores = i_ptr->next_local_store;
2170 }
2171 else
2172 last = i_ptr;
2173 i_ptr = i_ptr->next_local_store;
2174 }
2175 }
b8698a0f 2176 else
6fb5fa3c
DB
2177 {
2178 insn_info_t i_ptr = active_local_stores;
2179 insn_info_t last = NULL;
2180 if (dump_file)
2181 {
2182 fprintf (dump_file, " processing cselib load mem:");
2183 print_inline_rtx (dump_file, mem, 0);
2184 fprintf (dump_file, "\n");
2185 }
2186
2187 while (i_ptr)
2188 {
2189 bool remove = false;
2190 store_info_t store_info = i_ptr->store_rec;
b8698a0f 2191
6fb5fa3c
DB
2192 if (dump_file)
2193 fprintf (dump_file, " processing cselib load against insn %d\n",
2194 INSN_UID (i_ptr->insn));
2195
2196 /* Skip the clobbers. */
2197 while (!store_info->is_set)
2198 store_info = store_info->next;
2199
2200 /* If this read is just reading back something that we just
2201 stored, rewrite the read. */
2202 if (store_info->rhs
2203 && store_info->group_id == -1
2204 && store_info->cse_base == base
efc3527a 2205 && width != -1
8dd5516b
JJ
2206 && offset >= store_info->begin
2207 && offset + width <= store_info->end
2208 && all_positions_needed_p (store_info,
2209 offset - store_info->begin, width)
2210 && replace_read (store_info, i_ptr, read_info, insn_info, loc,
2211 bb_info->regs_live))
2212 return 0;
6fb5fa3c
DB
2213
2214 if (!store_info->alias_set)
b8698a0f 2215 remove = canon_true_dependence (store_info->mem,
6fb5fa3c
DB
2216 GET_MODE (store_info->mem),
2217 store_info->mem_addr,
6216f94e 2218 mem, mem_addr, rtx_varies_p);
b8698a0f 2219
6fb5fa3c
DB
2220 if (remove)
2221 {
2222 if (dump_file)
2223 dump_insn_info ("removing from active", i_ptr);
b8698a0f 2224
6fb5fa3c
DB
2225 if (last)
2226 last->next_local_store = i_ptr->next_local_store;
2227 else
2228 active_local_stores = i_ptr->next_local_store;
2229 }
2230 else
2231 last = i_ptr;
2232 i_ptr = i_ptr->next_local_store;
2233 }
2234 }
2235 return 0;
2236}
2237
b8698a0f 2238/* A for_each_rtx callback in which DATA points the INSN_INFO for
6fb5fa3c
DB
2239 as check_mem_read_rtx. Nullify the pointer if i_m_r_m_r returns
2240 true for any part of *LOC. */
2241
2242static void
2243check_mem_read_use (rtx *loc, void *data)
2244{
2245 for_each_rtx (loc, check_mem_read_rtx, data);
2246}
2247
8dd5516b
JJ
2248
2249/* Get arguments passed to CALL_INSN. Return TRUE if successful.
2250 So far it only handles arguments passed in registers. */
2251
2252static bool
2253get_call_args (rtx call_insn, tree fn, rtx *args, int nargs)
2254{
2255 CUMULATIVE_ARGS args_so_far;
2256 tree arg;
2257 int idx;
2258
2259 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fn), NULL_RTX, 0, 3);
2260
2261 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
2262 for (idx = 0;
2263 arg != void_list_node && idx < nargs;
2264 arg = TREE_CHAIN (arg), idx++)
2265 {
2266 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
3c07301f
NF
2267 rtx reg, link, tmp;
2268 reg = targetm.calls.function_arg (&args_so_far, mode, NULL_TREE, true);
8dd5516b
JJ
2269 if (!reg || !REG_P (reg) || GET_MODE (reg) != mode
2270 || GET_MODE_CLASS (mode) != MODE_INT)
2271 return false;
2272
2273 for (link = CALL_INSN_FUNCTION_USAGE (call_insn);
2274 link;
2275 link = XEXP (link, 1))
2276 if (GET_CODE (XEXP (link, 0)) == USE)
2277 {
2278 args[idx] = XEXP (XEXP (link, 0), 0);
2279 if (REG_P (args[idx])
2280 && REGNO (args[idx]) == REGNO (reg)
2281 && (GET_MODE (args[idx]) == mode
2282 || (GET_MODE_CLASS (GET_MODE (args[idx])) == MODE_INT
2283 && (GET_MODE_SIZE (GET_MODE (args[idx]))
2284 <= UNITS_PER_WORD)
2285 && (GET_MODE_SIZE (GET_MODE (args[idx]))
2286 > GET_MODE_SIZE (mode)))))
2287 break;
2288 }
2289 if (!link)
2290 return false;
2291
2292 tmp = cselib_expand_value_rtx (args[idx], scratch, 5);
2293 if (GET_MODE (args[idx]) != mode)
2294 {
2295 if (!tmp || !CONST_INT_P (tmp))
2296 return false;
2297 tmp = GEN_INT (trunc_int_for_mode (INTVAL (tmp), mode));
2298 }
2299 if (tmp)
2300 args[idx] = tmp;
2301
3c07301f 2302 targetm.calls.function_arg_advance (&args_so_far, mode, NULL_TREE, true);
8dd5516b
JJ
2303 }
2304 if (arg != void_list_node || idx != nargs)
2305 return false;
2306 return true;
2307}
2308
2309
6fb5fa3c
DB
2310/* Apply record_store to all candidate stores in INSN. Mark INSN
2311 if some part of it is not a candidate store and assigns to a
2312 non-register target. */
2313
2314static void
2315scan_insn (bb_info_t bb_info, rtx insn)
2316{
2317 rtx body;
f883e0a7 2318 insn_info_t insn_info = (insn_info_t) pool_alloc (insn_info_pool);
6fb5fa3c
DB
2319 int mems_found = 0;
2320 memset (insn_info, 0, sizeof (struct insn_info));
2321
2322 if (dump_file)
2323 fprintf (dump_file, "\n**scanning insn=%d\n",
2324 INSN_UID (insn));
2325
2326 insn_info->prev_insn = bb_info->last_insn;
2327 insn_info->insn = insn;
2328 bb_info->last_insn = insn_info;
b8698a0f 2329
b5b8b0ac
AO
2330 if (DEBUG_INSN_P (insn))
2331 {
2332 insn_info->cannot_delete = true;
2333 return;
2334 }
6fb5fa3c 2335
0d52bcc1 2336 /* Cselib clears the table for this case, so we have to essentially
6fb5fa3c
DB
2337 do the same. */
2338 if (NONJUMP_INSN_P (insn)
2339 && GET_CODE (PATTERN (insn)) == ASM_OPERANDS
2340 && MEM_VOLATILE_P (PATTERN (insn)))
2341 {
2342 add_wild_read (bb_info);
2343 insn_info->cannot_delete = true;
2344 return;
2345 }
2346
2347 /* Look at all of the uses in the insn. */
2348 note_uses (&PATTERN (insn), check_mem_read_use, bb_info);
2349
2350 if (CALL_P (insn))
2351 {
8dd5516b
JJ
2352 bool const_call;
2353 tree memset_call = NULL_TREE;
2354
6fb5fa3c 2355 insn_info->cannot_delete = true;
50f0f366 2356
6fb5fa3c 2357 /* Const functions cannot do anything bad i.e. read memory,
50f0f366 2358 however, they can read their parameters which may have
8dd5516b
JJ
2359 been pushed onto the stack.
2360 memset and bzero don't read memory either. */
2361 const_call = RTL_CONST_CALL_P (insn);
2362 if (!const_call)
2363 {
2364 rtx call = PATTERN (insn);
2365 if (GET_CODE (call) == PARALLEL)
2366 call = XVECEXP (call, 0, 0);
2367 if (GET_CODE (call) == SET)
2368 call = SET_SRC (call);
2369 if (GET_CODE (call) == CALL
2370 && MEM_P (XEXP (call, 0))
2371 && GET_CODE (XEXP (XEXP (call, 0), 0)) == SYMBOL_REF)
2372 {
2373 rtx symbol = XEXP (XEXP (call, 0), 0);
2374 if (SYMBOL_REF_DECL (symbol)
2375 && TREE_CODE (SYMBOL_REF_DECL (symbol)) == FUNCTION_DECL)
2376 {
2377 if ((DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol))
2378 == BUILT_IN_NORMAL
2379 && (DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol))
2380 == BUILT_IN_MEMSET))
2381 || SYMBOL_REF_DECL (symbol) == block_clear_fn)
2382 memset_call = SYMBOL_REF_DECL (symbol);
2383 }
2384 }
2385 }
2386 if (const_call || memset_call)
6fb5fa3c
DB
2387 {
2388 insn_info_t i_ptr = active_local_stores;
2389 insn_info_t last = NULL;
2390
2391 if (dump_file)
8dd5516b
JJ
2392 fprintf (dump_file, "%s call %d\n",
2393 const_call ? "const" : "memset", INSN_UID (insn));
6fb5fa3c 2394
64520bdc
EB
2395 /* See the head comment of the frame_read field. */
2396 if (reload_completed)
2397 insn_info->frame_read = true;
2398
2399 /* Loop over the active stores and remove those which are
2400 killed by the const function call. */
6fb5fa3c
DB
2401 while (i_ptr)
2402 {
64520bdc
EB
2403 bool remove_store = false;
2404
2405 /* The stack pointer based stores are always killed. */
50f0f366 2406 if (i_ptr->stack_pointer_based)
64520bdc
EB
2407 remove_store = true;
2408
2409 /* If the frame is read, the frame related stores are killed. */
2410 else if (insn_info->frame_read)
2411 {
2412 store_info_t store_info = i_ptr->store_rec;
2413
2414 /* Skip the clobbers. */
2415 while (!store_info->is_set)
2416 store_info = store_info->next;
2417
2418 if (store_info->group_id >= 0
2419 && VEC_index (group_info_t, rtx_group_vec,
2420 store_info->group_id)->frame_related)
2421 remove_store = true;
2422 }
2423
2424 if (remove_store)
6fb5fa3c
DB
2425 {
2426 if (dump_file)
2427 dump_insn_info ("removing from active", i_ptr);
b8698a0f 2428
6fb5fa3c
DB
2429 if (last)
2430 last->next_local_store = i_ptr->next_local_store;
2431 else
2432 active_local_stores = i_ptr->next_local_store;
2433 }
2434 else
2435 last = i_ptr;
64520bdc 2436
6fb5fa3c
DB
2437 i_ptr = i_ptr->next_local_store;
2438 }
8dd5516b
JJ
2439
2440 if (memset_call)
2441 {
2442 rtx args[3];
2443 if (get_call_args (insn, memset_call, args, 3)
2444 && CONST_INT_P (args[1])
2445 && CONST_INT_P (args[2])
2446 && INTVAL (args[2]) > 0)
2447 {
2448 rtx mem = gen_rtx_MEM (BLKmode, args[0]);
2449 set_mem_size (mem, args[2]);
2450 body = gen_rtx_SET (VOIDmode, mem, args[1]);
2451 mems_found += record_store (body, bb_info);
2452 if (dump_file)
2453 fprintf (dump_file, "handling memset as BLKmode store\n");
2454 if (mems_found == 1)
2455 {
2456 insn_info->next_local_store = active_local_stores;
2457 active_local_stores = insn_info;
2458 }
2459 }
2460 }
6fb5fa3c
DB
2461 }
2462
50f0f366
EB
2463 else
2464 /* Every other call, including pure functions, may read memory. */
2465 add_wild_read (bb_info);
2466
6fb5fa3c
DB
2467 return;
2468 }
2469
2470 /* Assuming that there are sets in these insns, we cannot delete
2471 them. */
2472 if ((GET_CODE (PATTERN (insn)) == CLOBBER)
0a64eeca 2473 || volatile_refs_p (PATTERN (insn))
1d65f45c 2474 || insn_could_throw_p (insn)
6fb5fa3c
DB
2475 || (RTX_FRAME_RELATED_P (insn))
2476 || find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX))
2477 insn_info->cannot_delete = true;
b8698a0f 2478
6fb5fa3c
DB
2479 body = PATTERN (insn);
2480 if (GET_CODE (body) == PARALLEL)
2481 {
2482 int i;
2483 for (i = 0; i < XVECLEN (body, 0); i++)
2484 mems_found += record_store (XVECEXP (body, 0, i), bb_info);
2485 }
2486 else
2487 mems_found += record_store (body, bb_info);
2488
2489 if (dump_file)
b8698a0f 2490 fprintf (dump_file, "mems_found = %d, cannot_delete = %s\n",
6fb5fa3c
DB
2491 mems_found, insn_info->cannot_delete ? "true" : "false");
2492
8dd5516b
JJ
2493 /* If we found some sets of mems, add it into the active_local_stores so
2494 that it can be locally deleted if found dead or used for
2495 replace_read and redundant constant store elimination. Otherwise mark
2496 it as cannot delete. This simplifies the processing later. */
2497 if (mems_found == 1)
6fb5fa3c
DB
2498 {
2499 insn_info->next_local_store = active_local_stores;
2500 active_local_stores = insn_info;
2501 }
2502 else
2503 insn_info->cannot_delete = true;
2504}
2505
2506
2507/* Remove BASE from the set of active_local_stores. This is a
2508 callback from cselib that is used to get rid of the stores in
2509 active_local_stores. */
2510
2511static void
2512remove_useless_values (cselib_val *base)
2513{
2514 insn_info_t insn_info = active_local_stores;
2515 insn_info_t last = NULL;
2516
2517 while (insn_info)
2518 {
2519 store_info_t store_info = insn_info->store_rec;
60564289 2520 bool del = false;
6fb5fa3c
DB
2521
2522 /* If ANY of the store_infos match the cselib group that is
2523 being deleted, then the insn can not be deleted. */
2524 while (store_info)
2525 {
b8698a0f 2526 if ((store_info->group_id == -1)
6fb5fa3c
DB
2527 && (store_info->cse_base == base))
2528 {
60564289 2529 del = true;
6fb5fa3c
DB
2530 break;
2531 }
2532 store_info = store_info->next;
2533 }
2534
60564289 2535 if (del)
6fb5fa3c
DB
2536 {
2537 if (last)
2538 last->next_local_store = insn_info->next_local_store;
2539 else
2540 active_local_stores = insn_info->next_local_store;
2541 free_store_info (insn_info);
2542 }
2543 else
2544 last = insn_info;
b8698a0f 2545
6fb5fa3c
DB
2546 insn_info = insn_info->next_local_store;
2547 }
2548}
2549
2550
2551/* Do all of step 1. */
2552
2553static void
2554dse_step1 (void)
2555{
2556 basic_block bb;
02b47899 2557 bitmap regs_live = BITMAP_ALLOC (NULL);
b8698a0f 2558
457eeaae 2559 cselib_init (0);
6fb5fa3c
DB
2560 all_blocks = BITMAP_ALLOC (NULL);
2561 bitmap_set_bit (all_blocks, ENTRY_BLOCK);
2562 bitmap_set_bit (all_blocks, EXIT_BLOCK);
2563
2564 FOR_ALL_BB (bb)
2565 {
2566 insn_info_t ptr;
f883e0a7 2567 bb_info_t bb_info = (bb_info_t) pool_alloc (bb_info_pool);
6fb5fa3c
DB
2568
2569 memset (bb_info, 0, sizeof (struct bb_info));
2570 bitmap_set_bit (all_blocks, bb->index);
02b47899
KZ
2571 bb_info->regs_live = regs_live;
2572
2573 bitmap_copy (regs_live, DF_LR_IN (bb));
2574 df_simulate_initialize_forwards (bb, regs_live);
6fb5fa3c
DB
2575
2576 bb_table[bb->index] = bb_info;
2577 cselib_discard_hook = remove_useless_values;
2578
2579 if (bb->index >= NUM_FIXED_BLOCKS)
2580 {
2581 rtx insn;
2582
2583 cse_store_info_pool
b8698a0f 2584 = create_alloc_pool ("cse_store_info_pool",
6fb5fa3c
DB
2585 sizeof (struct store_info), 100);
2586 active_local_stores = NULL;
2587 cselib_clear_table ();
b8698a0f 2588
6fb5fa3c
DB
2589 /* Scan the insns. */
2590 FOR_BB_INSNS (bb, insn)
2591 {
2592 if (INSN_P (insn))
2593 scan_insn (bb_info, insn);
2594 cselib_process_insn (insn);
02b47899
KZ
2595 if (INSN_P (insn))
2596 df_simulate_one_insn_forwards (bb, insn, regs_live);
6fb5fa3c 2597 }
b8698a0f 2598
6fb5fa3c
DB
2599 /* This is something of a hack, because the global algorithm
2600 is supposed to take care of the case where stores go dead
2601 at the end of the function. However, the global
2602 algorithm must take a more conservative view of block
2603 mode reads than the local alg does. So to get the case
2604 where you have a store to the frame followed by a non
0d52bcc1 2605 overlapping block more read, we look at the active local
6fb5fa3c
DB
2606 stores at the end of the function and delete all of the
2607 frame and spill based ones. */
2608 if (stores_off_frame_dead_at_return
2609 && (EDGE_COUNT (bb->succs) == 0
2610 || (single_succ_p (bb)
2611 && single_succ (bb) == EXIT_BLOCK_PTR
e3b5732b 2612 && ! crtl->calls_eh_return)))
6fb5fa3c
DB
2613 {
2614 insn_info_t i_ptr = active_local_stores;
2615 while (i_ptr)
2616 {
2617 store_info_t store_info = i_ptr->store_rec;
2618
2619 /* Skip the clobbers. */
2620 while (!store_info->is_set)
2621 store_info = store_info->next;
8dd5516b 2622 if (store_info->alias_set && !i_ptr->cannot_delete)
6fb5fa3c 2623 delete_dead_store_insn (i_ptr);
b8698a0f 2624 else
6fb5fa3c
DB
2625 if (store_info->group_id >= 0)
2626 {
b8698a0f 2627 group_info_t group
6fb5fa3c 2628 = VEC_index (group_info_t, rtx_group_vec, store_info->group_id);
8dd5516b 2629 if (group->frame_related && !i_ptr->cannot_delete)
6fb5fa3c
DB
2630 delete_dead_store_insn (i_ptr);
2631 }
2632
2633 i_ptr = i_ptr->next_local_store;
2634 }
2635 }
2636
2637 /* Get rid of the loads that were discovered in
2638 replace_read. Cselib is finished with this block. */
2639 while (deferred_change_list)
2640 {
2641 deferred_change_t next = deferred_change_list->next;
2642
2643 /* There is no reason to validate this change. That was
2644 done earlier. */
2645 *deferred_change_list->loc = deferred_change_list->reg;
2646 pool_free (deferred_change_pool, deferred_change_list);
2647 deferred_change_list = next;
2648 }
2649
2650 /* Get rid of all of the cselib based store_infos in this
2651 block and mark the containing insns as not being
2652 deletable. */
2653 ptr = bb_info->last_insn;
2654 while (ptr)
2655 {
2656 if (ptr->contains_cselib_groups)
8dd5516b
JJ
2657 {
2658 store_info_t s_info = ptr->store_rec;
2659 while (s_info && !s_info->is_set)
2660 s_info = s_info->next;
2661 if (s_info
2662 && s_info->redundant_reason
2663 && s_info->redundant_reason->insn
2664 && !ptr->cannot_delete)
2665 {
2666 if (dump_file)
2667 fprintf (dump_file, "Locally deleting insn %d "
2668 "because insn %d stores the "
2669 "same value and couldn't be "
2670 "eliminated\n",
2671 INSN_UID (ptr->insn),
2672 INSN_UID (s_info->redundant_reason->insn));
2673 delete_dead_store_insn (ptr);
2674 }
2675 if (s_info)
2676 s_info->redundant_reason = NULL;
2677 free_store_info (ptr);
2678 }
2679 else
2680 {
2681 store_info_t s_info;
2682
2683 /* Free at least positions_needed bitmaps. */
2684 for (s_info = ptr->store_rec; s_info; s_info = s_info->next)
2685 if (s_info->is_large)
2686 {
dc491a25 2687 BITMAP_FREE (s_info->positions_needed.large.bmap);
8dd5516b
JJ
2688 s_info->is_large = false;
2689 }
2690 }
6fb5fa3c
DB
2691 ptr = ptr->prev_insn;
2692 }
2693
2694 free_alloc_pool (cse_store_info_pool);
2695 }
02b47899 2696 bb_info->regs_live = NULL;
6fb5fa3c
DB
2697 }
2698
02b47899 2699 BITMAP_FREE (regs_live);
6fb5fa3c
DB
2700 cselib_finish ();
2701 htab_empty (rtx_group_table);
2702}
2703
2704\f
2705/*----------------------------------------------------------------------------
2706 Second step.
2707
2708 Assign each byte position in the stores that we are going to
2709 analyze globally to a position in the bitmaps. Returns true if
6ed3da00 2710 there are any bit positions assigned.
6fb5fa3c
DB
2711----------------------------------------------------------------------------*/
2712
2713static void
2714dse_step2_init (void)
2715{
2716 unsigned int i;
2717 group_info_t group;
2718
ac47786e 2719 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
6fb5fa3c
DB
2720 {
2721 /* For all non stack related bases, we only consider a store to
2722 be deletable if there are two or more stores for that
2723 position. This is because it takes one store to make the
2724 other store redundant. However, for the stores that are
2725 stack related, we consider them if there is only one store
2726 for the position. We do this because the stack related
2727 stores can be deleted if their is no read between them and
2728 the end of the function.
b8698a0f 2729
6fb5fa3c
DB
2730 To make this work in the current framework, we take the stack
2731 related bases add all of the bits from store1 into store2.
2732 This has the effect of making the eligible even if there is
2733 only one store. */
2734
2735 if (stores_off_frame_dead_at_return && group->frame_related)
2736 {
2737 bitmap_ior_into (group->store2_n, group->store1_n);
2738 bitmap_ior_into (group->store2_p, group->store1_p);
2739 if (dump_file)
b8698a0f 2740 fprintf (dump_file, "group %d is frame related ", i);
6fb5fa3c
DB
2741 }
2742
2743 group->offset_map_size_n++;
2744 group->offset_map_n = XNEWVEC (int, group->offset_map_size_n);
2745 group->offset_map_size_p++;
2746 group->offset_map_p = XNEWVEC (int, group->offset_map_size_p);
2747 group->process_globally = false;
2748 if (dump_file)
2749 {
b8698a0f 2750 fprintf (dump_file, "group %d(%d+%d): ", i,
6fb5fa3c
DB
2751 (int)bitmap_count_bits (group->store2_n),
2752 (int)bitmap_count_bits (group->store2_p));
2753 bitmap_print (dump_file, group->store2_n, "n ", " ");
2754 bitmap_print (dump_file, group->store2_p, "p ", "\n");
2755 }
2756 }
2757}
2758
2759
2760/* Init the offset tables for the normal case. */
2761
2762static bool
2763dse_step2_nospill (void)
2764{
2765 unsigned int i;
2766 group_info_t group;
2767 /* Position 0 is unused because 0 is used in the maps to mean
2768 unused. */
2769 current_position = 1;
2770
ac47786e 2771 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
6fb5fa3c
DB
2772 {
2773 bitmap_iterator bi;
2774 unsigned int j;
2775
2776 if (group == clear_alias_group)
2777 continue;
2778
2779 memset (group->offset_map_n, 0, sizeof(int) * group->offset_map_size_n);
2780 memset (group->offset_map_p, 0, sizeof(int) * group->offset_map_size_p);
2781 bitmap_clear (group->group_kill);
2782
2783 EXECUTE_IF_SET_IN_BITMAP (group->store2_n, 0, j, bi)
2784 {
2785 bitmap_set_bit (group->group_kill, current_position);
2786 group->offset_map_n[j] = current_position++;
2787 group->process_globally = true;
2788 }
2789 EXECUTE_IF_SET_IN_BITMAP (group->store2_p, 0, j, bi)
2790 {
b8698a0f 2791 bitmap_set_bit (group->group_kill, current_position);
6fb5fa3c
DB
2792 group->offset_map_p[j] = current_position++;
2793 group->process_globally = true;
2794 }
2795 }
2796 return current_position != 1;
2797}
2798
2799
2800/* Init the offset tables for the spill case. */
2801
2802static bool
2803dse_step2_spill (void)
2804{
2805 unsigned int j;
2806 group_info_t group = clear_alias_group;
2807 bitmap_iterator bi;
2808
2809 /* Position 0 is unused because 0 is used in the maps to mean
2810 unused. */
2811 current_position = 1;
2812
2813 if (dump_file)
2814 {
b8698a0f 2815 bitmap_print (dump_file, clear_alias_sets,
6fb5fa3c 2816 "clear alias sets ", "\n");
b8698a0f 2817 bitmap_print (dump_file, disqualified_clear_alias_sets,
6fb5fa3c
DB
2818 "disqualified clear alias sets ", "\n");
2819 }
2820
2821 memset (group->offset_map_n, 0, sizeof(int) * group->offset_map_size_n);
2822 memset (group->offset_map_p, 0, sizeof(int) * group->offset_map_size_p);
2823 bitmap_clear (group->group_kill);
b8698a0f 2824
6fb5fa3c
DB
2825 /* Remove the disqualified positions from the store2_p set. */
2826 bitmap_and_compl_into (group->store2_p, disqualified_clear_alias_sets);
b8698a0f 2827
6fb5fa3c
DB
2828 /* We do not need to process the store2_n set because
2829 alias_sets are always positive. */
2830 EXECUTE_IF_SET_IN_BITMAP (group->store2_p, 0, j, bi)
2831 {
b8698a0f 2832 bitmap_set_bit (group->group_kill, current_position);
6fb5fa3c
DB
2833 group->offset_map_p[j] = current_position++;
2834 group->process_globally = true;
2835 }
2836
2837 return current_position != 1;
2838}
2839
2840
2841\f
2842/*----------------------------------------------------------------------------
2843 Third step.
b8698a0f 2844
6fb5fa3c
DB
2845 Build the bit vectors for the transfer functions.
2846----------------------------------------------------------------------------*/
2847
2848
2849/* Note that this is NOT a general purpose function. Any mem that has
2850 an alias set registered here expected to be COMPLETELY unaliased:
b8698a0f 2851 i.e it's addresses are not and need not be examined.
6fb5fa3c
DB
2852
2853 It is known that all references to this address will have this
2854 alias set and there are NO other references to this address in the
b8698a0f 2855 function.
6fb5fa3c
DB
2856
2857 Currently the only place that is known to be clean enough to use
b8698a0f 2858 this interface is the code that assigns the spill locations.
6fb5fa3c
DB
2859
2860 All of the mems that have alias_sets registered are subjected to a
2861 very powerful form of dse where function calls, volatile reads and
b8698a0f 2862 writes, and reads from random location are not taken into account.
6fb5fa3c
DB
2863
2864 It is also assumed that these locations go dead when the function
2865 returns. This assumption could be relaxed if there were found to
2866 be places that this assumption was not correct.
2867
2868 The MODE is passed in and saved. The mode of each load or store to
2869 a mem with ALIAS_SET is checked against MEM. If the size of that
2870 load or store is different from MODE, processing is halted on this
2871 alias set. For the vast majority of aliases sets, all of the loads
2872 and stores will use the same mode. But vectors are treated
2873 differently: the alias set is established for the entire vector,
2874 but reload will insert loads and stores for individual elements and
2875 we do not necessarily have the information to track those separate
2876 elements. So when we see a mode mismatch, we just bail. */
2877
2878
b8698a0f
L
2879void
2880dse_record_singleton_alias_set (alias_set_type alias_set,
6fb5fa3c
DB
2881 enum machine_mode mode)
2882{
2883 struct clear_alias_mode_holder tmp_holder;
2884 struct clear_alias_mode_holder *entry;
2885 void **slot;
2886
2887 /* If we are not going to run dse, we need to return now or there
2888 will be problems with allocating the bitmaps. */
2889 if ((!gate_dse()) || !alias_set)
2890 return;
2891
2892 if (!clear_alias_sets)
2893 {
2894 clear_alias_sets = BITMAP_ALLOC (NULL);
2895 disqualified_clear_alias_sets = BITMAP_ALLOC (NULL);
2896 clear_alias_mode_table = htab_create (11, clear_alias_mode_hash,
2897 clear_alias_mode_eq, NULL);
b8698a0f 2898 clear_alias_mode_pool = create_alloc_pool ("clear_alias_mode_pool",
6fb5fa3c
DB
2899 sizeof (struct clear_alias_mode_holder), 100);
2900 }
2901
2902 bitmap_set_bit (clear_alias_sets, alias_set);
2903
2904 tmp_holder.alias_set = alias_set;
2905
2906 slot = htab_find_slot (clear_alias_mode_table, &tmp_holder, INSERT);
2907 gcc_assert (*slot == NULL);
2908
f883e0a7
KG
2909 *slot = entry =
2910 (struct clear_alias_mode_holder *) pool_alloc (clear_alias_mode_pool);
6fb5fa3c
DB
2911 entry->alias_set = alias_set;
2912 entry->mode = mode;
2913}
2914
2915
2916/* Remove ALIAS_SET from the sets of stack slots being considered. */
2917
b8698a0f 2918void
4862826d 2919dse_invalidate_singleton_alias_set (alias_set_type alias_set)
6fb5fa3c
DB
2920{
2921 if ((!gate_dse()) || !alias_set)
2922 return;
2923
2924 bitmap_clear_bit (clear_alias_sets, alias_set);
2925}
2926
2927
2928/* Look up the bitmap index for OFFSET in GROUP_INFO. If it is not
2929 there, return 0. */
2930
2931static int
2932get_bitmap_index (group_info_t group_info, HOST_WIDE_INT offset)
2933{
2934 if (offset < 0)
2935 {
2936 HOST_WIDE_INT offset_p = -offset;
2937 if (offset_p >= group_info->offset_map_size_n)
2938 return 0;
2939 return group_info->offset_map_n[offset_p];
2940 }
2941 else
2942 {
2943 if (offset >= group_info->offset_map_size_p)
2944 return 0;
2945 return group_info->offset_map_p[offset];
2946 }
2947}
2948
2949
2950/* Process the STORE_INFOs into the bitmaps into GEN and KILL. KILL
2951 may be NULL. */
2952
b8698a0f 2953static void
6fb5fa3c
DB
2954scan_stores_nospill (store_info_t store_info, bitmap gen, bitmap kill)
2955{
2956 while (store_info)
2957 {
2958 HOST_WIDE_INT i;
b8698a0f 2959 group_info_t group_info
6fb5fa3c
DB
2960 = VEC_index (group_info_t, rtx_group_vec, store_info->group_id);
2961 if (group_info->process_globally)
2962 for (i = store_info->begin; i < store_info->end; i++)
2963 {
2964 int index = get_bitmap_index (group_info, i);
2965 if (index != 0)
2966 {
2967 bitmap_set_bit (gen, index);
2968 if (kill)
2969 bitmap_clear_bit (kill, index);
2970 }
2971 }
2972 store_info = store_info->next;
2973 }
2974}
2975
2976
2977/* Process the STORE_INFOs into the bitmaps into GEN and KILL. KILL
2978 may be NULL. */
2979
b8698a0f 2980static void
6fb5fa3c
DB
2981scan_stores_spill (store_info_t store_info, bitmap gen, bitmap kill)
2982{
2983 while (store_info)
2984 {
2985 if (store_info->alias_set)
2986 {
b8698a0f 2987 int index = get_bitmap_index (clear_alias_group,
6fb5fa3c
DB
2988 store_info->alias_set);
2989 if (index != 0)
2990 {
2991 bitmap_set_bit (gen, index);
2992 if (kill)
2993 bitmap_clear_bit (kill, index);
2994 }
2995 }
2996 store_info = store_info->next;
2997 }
2998}
2999
3000
3001/* Process the READ_INFOs into the bitmaps into GEN and KILL. KILL
3002 may be NULL. */
3003
3004static void
3005scan_reads_nospill (insn_info_t insn_info, bitmap gen, bitmap kill)
3006{
3007 read_info_t read_info = insn_info->read_rec;
3008 int i;
3009 group_info_t group;
3010
64520bdc
EB
3011 /* If this insn reads the frame, kill all the frame related stores. */
3012 if (insn_info->frame_read)
3013 {
ac47786e 3014 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
64520bdc
EB
3015 if (group->process_globally && group->frame_related)
3016 {
3017 if (kill)
3018 bitmap_ior_into (kill, group->group_kill);
b8698a0f 3019 bitmap_and_compl_into (gen, group->group_kill);
64520bdc
EB
3020 }
3021 }
3022
6fb5fa3c
DB
3023 while (read_info)
3024 {
ac47786e 3025 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
6fb5fa3c
DB
3026 {
3027 if (group->process_globally)
3028 {
3029 if (i == read_info->group_id)
3030 {
3031 if (read_info->begin > read_info->end)
3032 {
3033 /* Begin > end for block mode reads. */
3034 if (kill)
3035 bitmap_ior_into (kill, group->group_kill);
3036 bitmap_and_compl_into (gen, group->group_kill);
3037 }
3038 else
3039 {
3040 /* The groups are the same, just process the
3041 offsets. */
3042 HOST_WIDE_INT j;
3043 for (j = read_info->begin; j < read_info->end; j++)
3044 {
3045 int index = get_bitmap_index (group, j);
3046 if (index != 0)
3047 {
3048 if (kill)
3049 bitmap_set_bit (kill, index);
3050 bitmap_clear_bit (gen, index);
3051 }
3052 }
3053 }
3054 }
3055 else
3056 {
3057 /* The groups are different, if the alias sets
3058 conflict, clear the entire group. We only need
3059 to apply this test if the read_info is a cselib
3060 read. Anything with a constant base cannot alias
3061 something else with a different constant
3062 base. */
3063 if ((read_info->group_id < 0)
b8698a0f 3064 && canon_true_dependence (group->base_mem,
d32f725a 3065 GET_MODE (group->base_mem),
6216f94e
JJ
3066 group->canon_base_addr,
3067 read_info->mem, NULL_RTX,
3068 rtx_varies_p))
6fb5fa3c
DB
3069 {
3070 if (kill)
3071 bitmap_ior_into (kill, group->group_kill);
3072 bitmap_and_compl_into (gen, group->group_kill);
3073 }
3074 }
3075 }
3076 }
b8698a0f 3077
6fb5fa3c
DB
3078 read_info = read_info->next;
3079 }
3080}
3081
3082/* Process the READ_INFOs into the bitmaps into GEN and KILL. KILL
3083 may be NULL. */
3084
3085static void
3086scan_reads_spill (read_info_t read_info, bitmap gen, bitmap kill)
3087{
3088 while (read_info)
3089 {
3090 if (read_info->alias_set)
3091 {
b8698a0f 3092 int index = get_bitmap_index (clear_alias_group,
6fb5fa3c
DB
3093 read_info->alias_set);
3094 if (index != 0)
3095 {
3096 if (kill)
3097 bitmap_set_bit (kill, index);
3098 bitmap_clear_bit (gen, index);
3099 }
3100 }
b8698a0f 3101
6fb5fa3c
DB
3102 read_info = read_info->next;
3103 }
3104}
3105
3106
3107/* Return the insn in BB_INFO before the first wild read or if there
3108 are no wild reads in the block, return the last insn. */
3109
3110static insn_info_t
3111find_insn_before_first_wild_read (bb_info_t bb_info)
3112{
3113 insn_info_t insn_info = bb_info->last_insn;
3114 insn_info_t last_wild_read = NULL;
3115
3116 while (insn_info)
3117 {
3118 if (insn_info->wild_read)
3119 {
3120 last_wild_read = insn_info->prev_insn;
3121 /* Block starts with wild read. */
3122 if (!last_wild_read)
3123 return NULL;
3124 }
3125
3126 insn_info = insn_info->prev_insn;
3127 }
3128
3129 if (last_wild_read)
3130 return last_wild_read;
3131 else
3132 return bb_info->last_insn;
3133}
3134
3135
3136/* Scan the insns in BB_INFO starting at PTR and going to the top of
3137 the block in order to build the gen and kill sets for the block.
3138 We start at ptr which may be the last insn in the block or may be
3139 the first insn with a wild read. In the latter case we are able to
3140 skip the rest of the block because it just does not matter:
3141 anything that happens is hidden by the wild read. */
3142
3143static void
3144dse_step3_scan (bool for_spills, basic_block bb)
3145{
3146 bb_info_t bb_info = bb_table[bb->index];
3147 insn_info_t insn_info;
3148
3149 if (for_spills)
3150 /* There are no wild reads in the spill case. */
3151 insn_info = bb_info->last_insn;
3152 else
3153 insn_info = find_insn_before_first_wild_read (bb_info);
b8698a0f 3154
6fb5fa3c
DB
3155 /* In the spill case or in the no_spill case if there is no wild
3156 read in the block, we will need a kill set. */
3157 if (insn_info == bb_info->last_insn)
3158 {
3159 if (bb_info->kill)
3160 bitmap_clear (bb_info->kill);
3161 else
3162 bb_info->kill = BITMAP_ALLOC (NULL);
3163 }
b8698a0f 3164 else
6fb5fa3c
DB
3165 if (bb_info->kill)
3166 BITMAP_FREE (bb_info->kill);
3167
3168 while (insn_info)
3169 {
3170 /* There may have been code deleted by the dce pass run before
3171 this phase. */
3172 if (insn_info->insn && INSN_P (insn_info->insn))
3173 {
b8698a0f 3174 /* Process the read(s) last. */
6fb5fa3c
DB
3175 if (for_spills)
3176 {
3177 scan_stores_spill (insn_info->store_rec, bb_info->gen, bb_info->kill);
3178 scan_reads_spill (insn_info->read_rec, bb_info->gen, bb_info->kill);
3179 }
3180 else
3181 {
3182 scan_stores_nospill (insn_info->store_rec, bb_info->gen, bb_info->kill);
3183 scan_reads_nospill (insn_info, bb_info->gen, bb_info->kill);
3184 }
b8698a0f 3185 }
6fb5fa3c
DB
3186
3187 insn_info = insn_info->prev_insn;
3188 }
3189}
3190
3191
3192/* Set the gen set of the exit block, and also any block with no
3193 successors that does not have a wild read. */
3194
3195static void
3196dse_step3_exit_block_scan (bb_info_t bb_info)
3197{
3198 /* The gen set is all 0's for the exit block except for the
3199 frame_pointer_group. */
b8698a0f 3200
6fb5fa3c
DB
3201 if (stores_off_frame_dead_at_return)
3202 {
3203 unsigned int i;
3204 group_info_t group;
b8698a0f 3205
ac47786e 3206 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
6fb5fa3c
DB
3207 {
3208 if (group->process_globally && group->frame_related)
3209 bitmap_ior_into (bb_info->gen, group->group_kill);
3210 }
3211 }
3212}
3213
3214
3215/* Find all of the blocks that are not backwards reachable from the
3216 exit block or any block with no successors (BB). These are the
3217 infinite loops or infinite self loops. These blocks will still
3218 have their bits set in UNREACHABLE_BLOCKS. */
3219
3220static void
3221mark_reachable_blocks (sbitmap unreachable_blocks, basic_block bb)
3222{
3223 edge e;
3224 edge_iterator ei;
3225
3226 if (TEST_BIT (unreachable_blocks, bb->index))
3227 {
3228 RESET_BIT (unreachable_blocks, bb->index);
3229 FOR_EACH_EDGE (e, ei, bb->preds)
b8698a0f 3230 {
6fb5fa3c 3231 mark_reachable_blocks (unreachable_blocks, e->src);
b8698a0f 3232 }
6fb5fa3c
DB
3233 }
3234}
3235
3236/* Build the transfer functions for the function. */
3237
3238static void
3239dse_step3 (bool for_spills)
3240{
3241 basic_block bb;
3242 sbitmap unreachable_blocks = sbitmap_alloc (last_basic_block);
3243 sbitmap_iterator sbi;
3244 bitmap all_ones = NULL;
3245 unsigned int i;
b8698a0f 3246
6fb5fa3c
DB
3247 sbitmap_ones (unreachable_blocks);
3248
3249 FOR_ALL_BB (bb)
3250 {
3251 bb_info_t bb_info = bb_table[bb->index];
3252 if (bb_info->gen)
3253 bitmap_clear (bb_info->gen);
3254 else
3255 bb_info->gen = BITMAP_ALLOC (NULL);
3256
3257 if (bb->index == ENTRY_BLOCK)
3258 ;
3259 else if (bb->index == EXIT_BLOCK)
3260 dse_step3_exit_block_scan (bb_info);
3261 else
3262 dse_step3_scan (for_spills, bb);
3263 if (EDGE_COUNT (bb->succs) == 0)
3264 mark_reachable_blocks (unreachable_blocks, bb);
3265
3266 /* If this is the second time dataflow is run, delete the old
3267 sets. */
3268 if (bb_info->in)
3269 BITMAP_FREE (bb_info->in);
3270 if (bb_info->out)
3271 BITMAP_FREE (bb_info->out);
3272 }
3273
3274 /* For any block in an infinite loop, we must initialize the out set
3275 to all ones. This could be expensive, but almost never occurs in
3276 practice. However, it is common in regression tests. */
3277 EXECUTE_IF_SET_IN_SBITMAP (unreachable_blocks, 0, i, sbi)
3278 {
3279 if (bitmap_bit_p (all_blocks, i))
3280 {
3281 bb_info_t bb_info = bb_table[i];
3282 if (!all_ones)
3283 {
3284 unsigned int j;
3285 group_info_t group;
3286
3287 all_ones = BITMAP_ALLOC (NULL);
ac47786e 3288 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, j, group)
6fb5fa3c
DB
3289 bitmap_ior_into (all_ones, group->group_kill);
3290 }
3291 if (!bb_info->out)
3292 {
3293 bb_info->out = BITMAP_ALLOC (NULL);
3294 bitmap_copy (bb_info->out, all_ones);
3295 }
3296 }
3297 }
3298
3299 if (all_ones)
3300 BITMAP_FREE (all_ones);
3301 sbitmap_free (unreachable_blocks);
3302}
3303
3304
3305\f
3306/*----------------------------------------------------------------------------
3307 Fourth step.
3308
3309 Solve the bitvector equations.
3310----------------------------------------------------------------------------*/
3311
3312
3313/* Confluence function for blocks with no successors. Create an out
3314 set from the gen set of the exit block. This block logically has
3315 the exit block as a successor. */
3316
3317
3318
3319static void
3320dse_confluence_0 (basic_block bb)
3321{
3322 bb_info_t bb_info = bb_table[bb->index];
3323
3324 if (bb->index == EXIT_BLOCK)
3325 return;
3326
3327 if (!bb_info->out)
3328 {
3329 bb_info->out = BITMAP_ALLOC (NULL);
3330 bitmap_copy (bb_info->out, bb_table[EXIT_BLOCK]->gen);
3331 }
3332}
3333
3334/* Propagate the information from the in set of the dest of E to the
3335 out set of the src of E. If the various in or out sets are not
3336 there, that means they are all ones. */
3337
1a0f3fa1 3338static bool
6fb5fa3c
DB
3339dse_confluence_n (edge e)
3340{
3341 bb_info_t src_info = bb_table[e->src->index];
3342 bb_info_t dest_info = bb_table[e->dest->index];
3343
3344 if (dest_info->in)
3345 {
3346 if (src_info->out)
3347 bitmap_and_into (src_info->out, dest_info->in);
3348 else
3349 {
3350 src_info->out = BITMAP_ALLOC (NULL);
3351 bitmap_copy (src_info->out, dest_info->in);
3352 }
3353 }
1a0f3fa1 3354 return true;
6fb5fa3c
DB
3355}
3356
3357
3358/* Propagate the info from the out to the in set of BB_INDEX's basic
b8698a0f 3359 block. There are three cases:
6fb5fa3c
DB
3360
3361 1) The block has no kill set. In this case the kill set is all
3362 ones. It does not matter what the out set of the block is, none of
3363 the info can reach the top. The only thing that reaches the top is
3364 the gen set and we just copy the set.
3365
3366 2) There is a kill set but no out set and bb has successors. In
3367 this case we just return. Eventually an out set will be created and
3368 it is better to wait than to create a set of ones.
3369
3370 3) There is both a kill and out set. We apply the obvious transfer
3371 function.
3372*/
3373
3374static bool
3375dse_transfer_function (int bb_index)
3376{
3377 bb_info_t bb_info = bb_table[bb_index];
3378
3379 if (bb_info->kill)
3380 {
3381 if (bb_info->out)
3382 {
3383 /* Case 3 above. */
3384 if (bb_info->in)
b8698a0f 3385 return bitmap_ior_and_compl (bb_info->in, bb_info->gen,
6fb5fa3c
DB
3386 bb_info->out, bb_info->kill);
3387 else
3388 {
3389 bb_info->in = BITMAP_ALLOC (NULL);
b8698a0f 3390 bitmap_ior_and_compl (bb_info->in, bb_info->gen,
6fb5fa3c
DB
3391 bb_info->out, bb_info->kill);
3392 return true;
3393 }
3394 }
3395 else
3396 /* Case 2 above. */
3397 return false;
3398 }
3399 else
3400 {
3401 /* Case 1 above. If there is already an in set, nothing
3402 happens. */
3403 if (bb_info->in)
3404 return false;
3405 else
3406 {
3407 bb_info->in = BITMAP_ALLOC (NULL);
3408 bitmap_copy (bb_info->in, bb_info->gen);
3409 return true;
3410 }
3411 }
3412}
3413
3414/* Solve the dataflow equations. */
3415
3416static void
3417dse_step4 (void)
3418{
b8698a0f
L
3419 df_simple_dataflow (DF_BACKWARD, NULL, dse_confluence_0,
3420 dse_confluence_n, dse_transfer_function,
3421 all_blocks, df_get_postorder (DF_BACKWARD),
6fb5fa3c
DB
3422 df_get_n_blocks (DF_BACKWARD));
3423 if (dump_file)
3424 {
3425 basic_block bb;
3426
3427 fprintf (dump_file, "\n\n*** Global dataflow info after analysis.\n");
3428 FOR_ALL_BB (bb)
3429 {
3430 bb_info_t bb_info = bb_table[bb->index];
3431
3432 df_print_bb_index (bb, dump_file);
3433 if (bb_info->in)
3434 bitmap_print (dump_file, bb_info->in, " in: ", "\n");
3435 else
3436 fprintf (dump_file, " in: *MISSING*\n");
3437 if (bb_info->gen)
3438 bitmap_print (dump_file, bb_info->gen, " gen: ", "\n");
3439 else
3440 fprintf (dump_file, " gen: *MISSING*\n");
3441 if (bb_info->kill)
3442 bitmap_print (dump_file, bb_info->kill, " kill: ", "\n");
3443 else
3444 fprintf (dump_file, " kill: *MISSING*\n");
3445 if (bb_info->out)
3446 bitmap_print (dump_file, bb_info->out, " out: ", "\n");
3447 else
3448 fprintf (dump_file, " out: *MISSING*\n\n");
3449 }
3450 }
3451}
3452
3453
3454\f
3455/*----------------------------------------------------------------------------
3456 Fifth step.
3457
0d52bcc1 3458 Delete the stores that can only be deleted using the global information.
6fb5fa3c
DB
3459----------------------------------------------------------------------------*/
3460
3461
3462static void
3463dse_step5_nospill (void)
3464{
3465 basic_block bb;
3466 FOR_EACH_BB (bb)
3467 {
3468 bb_info_t bb_info = bb_table[bb->index];
3469 insn_info_t insn_info = bb_info->last_insn;
3470 bitmap v = bb_info->out;
3471
3472 while (insn_info)
3473 {
3474 bool deleted = false;
3475 if (dump_file && insn_info->insn)
3476 {
3477 fprintf (dump_file, "starting to process insn %d\n",
3478 INSN_UID (insn_info->insn));
3479 bitmap_print (dump_file, v, " v: ", "\n");
3480 }
3481
3482 /* There may have been code deleted by the dce pass run before
3483 this phase. */
b8698a0f 3484 if (insn_info->insn
6fb5fa3c
DB
3485 && INSN_P (insn_info->insn)
3486 && (!insn_info->cannot_delete)
3487 && (!bitmap_empty_p (v)))
3488 {
3489 store_info_t store_info = insn_info->store_rec;
3490
3491 /* Try to delete the current insn. */
3492 deleted = true;
b8698a0f 3493
6fb5fa3c
DB
3494 /* Skip the clobbers. */
3495 while (!store_info->is_set)
3496 store_info = store_info->next;
3497
3498 if (store_info->alias_set)
3499 deleted = false;
3500 else
3501 {
3502 HOST_WIDE_INT i;
b8698a0f 3503 group_info_t group_info
6fb5fa3c 3504 = VEC_index (group_info_t, rtx_group_vec, store_info->group_id);
b8698a0f 3505
6fb5fa3c
DB
3506 for (i = store_info->begin; i < store_info->end; i++)
3507 {
3508 int index = get_bitmap_index (group_info, i);
b8698a0f 3509
6fb5fa3c 3510 if (dump_file)
b8698a0f 3511 fprintf (dump_file, "i = %d, index = %d\n", (int)i, index);
6fb5fa3c
DB
3512 if (index == 0 || !bitmap_bit_p (v, index))
3513 {
3514 if (dump_file)
b8698a0f 3515 fprintf (dump_file, "failing at i = %d\n", (int)i);
6fb5fa3c
DB
3516 deleted = false;
3517 break;
3518 }
3519 }
3520 }
3521 if (deleted)
3522 {
3523 if (dbg_cnt (dse))
3524 {
3525 check_for_inc_dec (insn_info->insn);
3526 delete_insn (insn_info->insn);
3527 insn_info->insn = NULL;
3528 globally_deleted++;
3529 }
3530 }
3531 }
3532 /* We do want to process the local info if the insn was
6ed3da00 3533 deleted. For instance, if the insn did a wild read, we
6fb5fa3c 3534 no longer need to trash the info. */
b8698a0f 3535 if (insn_info->insn
6fb5fa3c
DB
3536 && INSN_P (insn_info->insn)
3537 && (!deleted))
3538 {
3539 scan_stores_nospill (insn_info->store_rec, v, NULL);
3540 if (insn_info->wild_read)
3541 {
3542 if (dump_file)
3543 fprintf (dump_file, "wild read\n");
3544 bitmap_clear (v);
3545 }
3546 else if (insn_info->read_rec)
3547 {
3548 if (dump_file)
3549 fprintf (dump_file, "regular read\n");
3550 scan_reads_nospill (insn_info, v, NULL);
3551 }
3552 }
b8698a0f 3553
6fb5fa3c
DB
3554 insn_info = insn_info->prev_insn;
3555 }
3556 }
3557}
3558
3559
3560static void
3561dse_step5_spill (void)
3562{
3563 basic_block bb;
3564 FOR_EACH_BB (bb)
3565 {
3566 bb_info_t bb_info = bb_table[bb->index];
3567 insn_info_t insn_info = bb_info->last_insn;
3568 bitmap v = bb_info->out;
3569
3570 while (insn_info)
3571 {
3572 bool deleted = false;
3573 /* There may have been code deleted by the dce pass run before
3574 this phase. */
b8698a0f 3575 if (insn_info->insn
6fb5fa3c
DB
3576 && INSN_P (insn_info->insn)
3577 && (!insn_info->cannot_delete)
3578 && (!bitmap_empty_p (v)))
3579 {
3580 /* Try to delete the current insn. */
3581 store_info_t store_info = insn_info->store_rec;
3582 deleted = true;
b8698a0f 3583
6fb5fa3c
DB
3584 while (store_info)
3585 {
3586 if (store_info->alias_set)
3587 {
b8698a0f 3588 int index = get_bitmap_index (clear_alias_group,
6fb5fa3c
DB
3589 store_info->alias_set);
3590 if (index == 0 || !bitmap_bit_p (v, index))
3591 {
3592 deleted = false;
3593 break;
3594 }
3595 }
b8698a0f 3596 else
6fb5fa3c
DB
3597 deleted = false;
3598 store_info = store_info->next;
3599 }
3600 if (deleted && dbg_cnt (dse))
3601 {
3602 if (dump_file)
b8698a0f 3603 fprintf (dump_file, "Spill deleting insn %d\n",
6fb5fa3c
DB
3604 INSN_UID (insn_info->insn));
3605 check_for_inc_dec (insn_info->insn);
3606 delete_insn (insn_info->insn);
3607 spill_deleted++;
3608 insn_info->insn = NULL;
3609 }
3610 }
b8698a0f
L
3611
3612 if (insn_info->insn
6fb5fa3c
DB
3613 && INSN_P (insn_info->insn)
3614 && (!deleted))
3615 {
3616 scan_stores_spill (insn_info->store_rec, v, NULL);
3617 scan_reads_spill (insn_info->read_rec, v, NULL);
3618 }
b8698a0f 3619
6fb5fa3c
DB
3620 insn_info = insn_info->prev_insn;
3621 }
3622 }
3623}
3624
3625
3626\f
3627/*----------------------------------------------------------------------------
3628 Sixth step.
3629
8dd5516b
JJ
3630 Delete stores made redundant by earlier stores (which store the same
3631 value) that couldn't be eliminated.
3632----------------------------------------------------------------------------*/
3633
3634static void
3635dse_step6 (void)
3636{
3637 basic_block bb;
3638
3639 FOR_ALL_BB (bb)
3640 {
3641 bb_info_t bb_info = bb_table[bb->index];
3642 insn_info_t insn_info = bb_info->last_insn;
3643
3644 while (insn_info)
3645 {
3646 /* There may have been code deleted by the dce pass run before
3647 this phase. */
3648 if (insn_info->insn
3649 && INSN_P (insn_info->insn)
3650 && !insn_info->cannot_delete)
3651 {
3652 store_info_t s_info = insn_info->store_rec;
3653
3654 while (s_info && !s_info->is_set)
3655 s_info = s_info->next;
3656 if (s_info
3657 && s_info->redundant_reason
3658 && s_info->redundant_reason->insn
3659 && INSN_P (s_info->redundant_reason->insn))
3660 {
3661 rtx rinsn = s_info->redundant_reason->insn;
3662 if (dump_file)
3663 fprintf (dump_file, "Locally deleting insn %d "
3664 "because insn %d stores the "
3665 "same value and couldn't be "
3666 "eliminated\n",
3667 INSN_UID (insn_info->insn),
3668 INSN_UID (rinsn));
3669 delete_dead_store_insn (insn_info);
3670 }
3671 }
3672 insn_info = insn_info->prev_insn;
3673 }
3674 }
3675}
3676\f
3677/*----------------------------------------------------------------------------
3678 Seventh step.
3679
b8698a0f 3680 Destroy everything left standing.
6fb5fa3c
DB
3681----------------------------------------------------------------------------*/
3682
b8698a0f 3683static void
8dd5516b 3684dse_step7 (bool global_done)
6fb5fa3c
DB
3685{
3686 unsigned int i;
3687 group_info_t group;
3688 basic_block bb;
b8698a0f 3689
ac47786e 3690 FOR_EACH_VEC_ELT (group_info_t, rtx_group_vec, i, group)
6fb5fa3c 3691 {
370f38e8
KZ
3692 free (group->offset_map_n);
3693 free (group->offset_map_p);
3694 BITMAP_FREE (group->store1_n);
3695 BITMAP_FREE (group->store1_p);
3696 BITMAP_FREE (group->store2_n);
3697 BITMAP_FREE (group->store2_p);
3698 BITMAP_FREE (group->group_kill);
6fb5fa3c
DB
3699 }
3700
370f38e8
KZ
3701 if (global_done)
3702 FOR_ALL_BB (bb)
3703 {
3704 bb_info_t bb_info = bb_table[bb->index];
3705 BITMAP_FREE (bb_info->gen);
3706 if (bb_info->kill)
3707 BITMAP_FREE (bb_info->kill);
3708 if (bb_info->in)
3709 BITMAP_FREE (bb_info->in);
3710 if (bb_info->out)
3711 BITMAP_FREE (bb_info->out);
3712 }
3713
6fb5fa3c
DB
3714 if (clear_alias_sets)
3715 {
3716 BITMAP_FREE (clear_alias_sets);
3717 BITMAP_FREE (disqualified_clear_alias_sets);
3718 free_alloc_pool (clear_alias_mode_pool);
3719 htab_delete (clear_alias_mode_table);
3720 }
3721
3722 end_alias_analysis ();
3723 free (bb_table);
3724 htab_delete (rtx_group_table);
3725 VEC_free (group_info_t, heap, rtx_group_vec);
3726 BITMAP_FREE (all_blocks);
3727 BITMAP_FREE (scratch);
3728
3729 free_alloc_pool (rtx_store_info_pool);
3730 free_alloc_pool (read_info_pool);
3731 free_alloc_pool (insn_info_pool);
3732 free_alloc_pool (bb_info_pool);
3733 free_alloc_pool (rtx_group_info_pool);
3734 free_alloc_pool (deferred_change_pool);
3735}
3736
3737
6fb5fa3c
DB
3738/* -------------------------------------------------------------------------
3739 DSE
3740 ------------------------------------------------------------------------- */
3741
3742/* Callback for running pass_rtl_dse. */
3743
3744static unsigned int
3745rest_of_handle_dse (void)
3746{
3747 bool did_global = false;
3748
3749 df_set_flags (DF_DEFER_INSN_RESCAN);
3750
02b47899
KZ
3751 /* Need the notes since we must track live hardregs in the forwards
3752 direction. */
3753 df_note_add_problem ();
3754 df_analyze ();
3755
6fb5fa3c
DB
3756 dse_step0 ();
3757 dse_step1 ();
3758 dse_step2_init ();
3759 if (dse_step2_nospill ())
3760 {
3761 df_set_flags (DF_LR_RUN_DCE);
3762 df_analyze ();
3763 did_global = true;
3764 if (dump_file)
3765 fprintf (dump_file, "doing global processing\n");
3766 dse_step3 (false);
3767 dse_step4 ();
3768 dse_step5_nospill ();
3769 }
3770
3771 /* For the instance of dse that runs after reload, we make a special
3772 pass to process the spills. These are special in that they are
3773 totally transparent, i.e, there is no aliasing issues that need
3774 to be considered. This means that the wild reads that kill
b8698a0f 3775 everything else do not apply here. */
6fb5fa3c
DB
3776 if (clear_alias_sets && dse_step2_spill ())
3777 {
3778 if (!did_global)
3779 {
3780 df_set_flags (DF_LR_RUN_DCE);
3781 df_analyze ();
3782 }
3783 did_global = true;
3784 if (dump_file)
3785 fprintf (dump_file, "doing global spill processing\n");
3786 dse_step3 (true);
3787 dse_step4 ();
3788 dse_step5_spill ();
3789 }
8dd5516b
JJ
3790
3791 dse_step6 ();
3792 dse_step7 (did_global);
6fb5fa3c
DB
3793
3794 if (dump_file)
3795 fprintf (dump_file, "dse: local deletions = %d, global deletions = %d, spill deletions = %d\n",
3796 locally_deleted, globally_deleted, spill_deleted);
3797 return 0;
3798}
3799
3800static bool
3801gate_dse (void)
3802{
7d817ebc
DE
3803 return gate_dse1 () || gate_dse2 ();
3804}
3805
3806static bool
3807gate_dse1 (void)
3808{
3809 return optimize > 0 && flag_dse
3810 && dbg_cnt (dse1);
3811}
3812
3813static bool
3814gate_dse2 (void)
3815{
3816 return optimize > 0 && flag_dse
3817 && dbg_cnt (dse2);
6fb5fa3c
DB
3818}
3819
8ddbbcae 3820struct rtl_opt_pass pass_rtl_dse1 =
6fb5fa3c 3821{
8ddbbcae
JH
3822 {
3823 RTL_PASS,
6fb5fa3c 3824 "dse1", /* name */
7d817ebc 3825 gate_dse1, /* gate */
6fb5fa3c
DB
3826 rest_of_handle_dse, /* execute */
3827 NULL, /* sub */
3828 NULL, /* next */
3829 0, /* static_pass_number */
3830 TV_DSE1, /* tv_id */
3831 0, /* properties_required */
3832 0, /* properties_provided */
3833 0, /* properties_destroyed */
3834 0, /* todo_flags_start */
3835 TODO_dump_func |
a36b8a1e 3836 TODO_df_finish | TODO_verify_rtl_sharing |
8ddbbcae
JH
3837 TODO_ggc_collect /* todo_flags_finish */
3838 }
6fb5fa3c
DB
3839};
3840
8ddbbcae 3841struct rtl_opt_pass pass_rtl_dse2 =
6fb5fa3c 3842{
8ddbbcae
JH
3843 {
3844 RTL_PASS,
6fb5fa3c 3845 "dse2", /* name */
7d817ebc 3846 gate_dse2, /* gate */
6fb5fa3c
DB
3847 rest_of_handle_dse, /* execute */
3848 NULL, /* sub */
3849 NULL, /* next */
3850 0, /* static_pass_number */
3851 TV_DSE2, /* tv_id */
3852 0, /* properties_required */
3853 0, /* properties_provided */
3854 0, /* properties_destroyed */
3855 0, /* todo_flags_start */
3856 TODO_dump_func |
a36b8a1e 3857 TODO_df_finish | TODO_verify_rtl_sharing |
8ddbbcae
JH
3858 TODO_ggc_collect /* todo_flags_finish */
3859 }
6fb5fa3c 3860};