2013-01-08 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / dse.c
blob6a530ca7d265d18268ad751b8486f52cffe180b8
1 /* RTL dead store elimination.
2 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 Free Software Foundation, Inc.
5 Contributed by Richard Sandiford <rsandifor@codesourcery.com>
6 and Kenneth Zadeck <zadeck@naturalbridge.com>
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 #undef BASELINE
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "hash-table.h"
30 #include "tm.h"
31 #include "rtl.h"
32 #include "tree.h"
33 #include "tm_p.h"
34 #include "regs.h"
35 #include "hard-reg-set.h"
36 #include "regset.h"
37 #include "flags.h"
38 #include "df.h"
39 #include "cselib.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 "optabs.h"
47 #include "dbgcnt.h"
48 #include "target.h"
49 #include "params.h"
50 #include "tree-flow.h" /* for may_be_aliased */
52 /* This file contains three techniques for performing Dead Store
53 Elimination (dse).
55 * The first technique performs dse locally on any base address. It
56 is based on the cselib which is a local value numbering technique.
57 This technique is local to a basic block but deals with a fairly
58 general addresses.
60 * The second technique performs dse globally but is restricted to
61 base addresses that are either constant or are relative to the
62 frame_pointer.
64 * The third technique, (which is only done after register allocation)
65 processes the spill spill slots. This differs from the second
66 technique because it takes advantage of the fact that spilling is
67 completely free from the effects of aliasing.
69 Logically, dse is a backwards dataflow problem. A store can be
70 deleted if it if cannot be reached in the backward direction by any
71 use of the value being stored. However, the local technique uses a
72 forwards scan of the basic block because cselib requires that the
73 block be processed in that order.
75 The pass is logically broken into 7 steps:
77 0) Initialization.
79 1) The local algorithm, as well as scanning the insns for the two
80 global algorithms.
82 2) Analysis to see if the global algs are necessary. In the case
83 of stores base on a constant address, there must be at least two
84 stores to that address, to make it possible to delete some of the
85 stores. In the case of stores off of the frame or spill related
86 stores, only one store to an address is necessary because those
87 stores die at the end of the function.
89 3) Set up the global dataflow equations based on processing the
90 info parsed in the first step.
92 4) Solve the dataflow equations.
94 5) Delete the insns that the global analysis has indicated are
95 unnecessary.
97 6) Delete insns that store the same value as preceding store
98 where the earlier store couldn't be eliminated.
100 7) Cleanup.
102 This step uses cselib and canon_rtx to build the largest expression
103 possible for each address. This pass is a forwards pass through
104 each basic block. From the point of view of the global technique,
105 the first pass could examine a block in either direction. The
106 forwards ordering is to accommodate cselib.
108 We make a simplifying assumption: addresses fall into four broad
109 categories:
111 1) base has rtx_varies_p == false, offset is constant.
112 2) base has rtx_varies_p == false, offset variable.
113 3) base has rtx_varies_p == true, offset constant.
114 4) base has rtx_varies_p == true, offset variable.
116 The local passes are able to process all 4 kinds of addresses. The
117 global pass only handles 1).
119 The global problem is formulated as follows:
121 A store, S1, to address A, where A is not relative to the stack
122 frame, can be eliminated if all paths from S1 to the end of the
123 function contain another store to A before a read to A.
125 If the address A is relative to the stack frame, a store S2 to A
126 can be eliminated if there are no paths from S2 that reach the
127 end of the function that read A before another store to A. In
128 this case S2 can be deleted if there are paths from S2 to the
129 end of the function that have no reads or writes to A. This
130 second case allows stores to the stack frame to be deleted that
131 would otherwise die when the function returns. This cannot be
132 done if stores_off_frame_dead_at_return is not true. See the doc
133 for that variable for when this variable is false.
135 The global problem is formulated as a backwards set union
136 dataflow problem where the stores are the gens and reads are the
137 kills. Set union problems are rare and require some special
138 handling given our representation of bitmaps. A straightforward
139 implementation requires a lot of bitmaps filled with 1s.
140 These are expensive and cumbersome in our bitmap formulation so
141 care has been taken to avoid large vectors filled with 1s. See
142 the comments in bb_info and in the dataflow confluence functions
143 for details.
145 There are two places for further enhancements to this algorithm:
147 1) The original dse which was embedded in a pass called flow also
148 did local address forwarding. For example in
150 A <- r100
151 ... <- A
153 flow would replace the right hand side of the second insn with a
154 reference to r100. Most of the information is available to add this
155 to this pass. It has not done it because it is a lot of work in
156 the case that either r100 is assigned to between the first and
157 second insn and/or the second insn is a load of part of the value
158 stored by the first insn.
160 insn 5 in gcc.c-torture/compile/990203-1.c simple case.
161 insn 15 in gcc.c-torture/execute/20001017-2.c simple case.
162 insn 25 in gcc.c-torture/execute/20001026-1.c simple case.
163 insn 44 in gcc.c-torture/execute/20010910-1.c simple case.
165 2) The cleaning up of spill code is quite profitable. It currently
166 depends on reading tea leaves and chicken entrails left by reload.
167 This pass depends on reload creating a singleton alias set for each
168 spill slot and telling the next dse pass which of these alias sets
169 are the singletons. Rather than analyze the addresses of the
170 spills, dse's spill processing just does analysis of the loads and
171 stores that use those alias sets. There are three cases where this
172 falls short:
174 a) Reload sometimes creates the slot for one mode of access, and
175 then inserts loads and/or stores for a smaller mode. In this
176 case, the current code just punts on the slot. The proper thing
177 to do is to back out and use one bit vector position for each
178 byte of the entity associated with the slot. This depends on
179 KNOWING that reload always generates the accesses for each of the
180 bytes in some canonical (read that easy to understand several
181 passes after reload happens) way.
183 b) Reload sometimes decides that spill slot it allocated was not
184 large enough for the mode and goes back and allocates more slots
185 with the same mode and alias set. The backout in this case is a
186 little more graceful than (a). In this case the slot is unmarked
187 as being a spill slot and if final address comes out to be based
188 off the frame pointer, the global algorithm handles this slot.
190 c) For any pass that may prespill, there is currently no
191 mechanism to tell the dse pass that the slot being used has the
192 special properties that reload uses. It may be that all that is
193 required is to have those passes make the same calls that reload
194 does, assuming that the alias sets can be manipulated in the same
195 way. */
197 /* There are limits to the size of constant offsets we model for the
198 global problem. There are certainly test cases, that exceed this
199 limit, however, it is unlikely that there are important programs
200 that really have constant offsets this size. */
201 #define MAX_OFFSET (64 * 1024)
203 /* Obstack for the DSE dataflow bitmaps. We don't want to put these
204 on the default obstack because these bitmaps can grow quite large
205 (~2GB for the small (!) test case of PR54146) and we'll hold on to
206 all that memory until the end of the compiler run.
207 As a bonus, delete_tree_live_info can destroy all the bitmaps by just
208 releasing the whole obstack. */
209 static bitmap_obstack dse_bitmap_obstack;
211 /* Obstack for other data. As for above: Kinda nice to be able to
212 throw it all away at the end in one big sweep. */
213 static struct obstack dse_obstack;
215 /* Scratch bitmap for cselib's cselib_expand_value_rtx. */
216 static bitmap scratch = NULL;
218 struct insn_info;
220 /* This structure holds information about a candidate store. */
221 struct store_info
224 /* False means this is a clobber. */
225 bool is_set;
227 /* False if a single HOST_WIDE_INT bitmap is used for positions_needed. */
228 bool is_large;
230 /* The id of the mem group of the base address. If rtx_varies_p is
231 true, this is -1. Otherwise, it is the index into the group
232 table. */
233 int group_id;
235 /* This is the cselib value. */
236 cselib_val *cse_base;
238 /* This canonized mem. */
239 rtx mem;
241 /* Canonized MEM address for use by canon_true_dependence. */
242 rtx mem_addr;
244 /* If this is non-zero, it is the alias set of a spill location. */
245 alias_set_type alias_set;
247 /* The offset of the first and byte before the last byte associated
248 with the operation. */
249 HOST_WIDE_INT begin, end;
251 union
253 /* A bitmask as wide as the number of bytes in the word that
254 contains a 1 if the byte may be needed. The store is unused if
255 all of the bits are 0. This is used if IS_LARGE is false. */
256 unsigned HOST_WIDE_INT small_bitmask;
258 struct
260 /* A bitmap with one bit per byte. Cleared bit means the position
261 is needed. Used if IS_LARGE is false. */
262 bitmap bmap;
264 /* Number of set bits (i.e. unneeded bytes) in BITMAP. If it is
265 equal to END - BEGIN, the whole store is unused. */
266 int count;
267 } large;
268 } positions_needed;
270 /* The next store info for this insn. */
271 struct store_info *next;
273 /* The right hand side of the store. This is used if there is a
274 subsequent reload of the mems address somewhere later in the
275 basic block. */
276 rtx rhs;
278 /* If rhs is or holds a constant, this contains that constant,
279 otherwise NULL. */
280 rtx const_rhs;
282 /* Set if this store stores the same constant value as REDUNDANT_REASON
283 insn stored. These aren't eliminated early, because doing that
284 might prevent the earlier larger store to be eliminated. */
285 struct insn_info *redundant_reason;
288 /* Return a bitmask with the first N low bits set. */
290 static unsigned HOST_WIDE_INT
291 lowpart_bitmask (int n)
293 unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT) 0;
294 return mask >> (HOST_BITS_PER_WIDE_INT - n);
297 typedef struct store_info *store_info_t;
298 static alloc_pool cse_store_info_pool;
299 static alloc_pool rtx_store_info_pool;
301 /* This structure holds information about a load. These are only
302 built for rtx bases. */
303 struct read_info
305 /* The id of the mem group of the base address. */
306 int group_id;
308 /* If this is non-zero, it is the alias set of a spill location. */
309 alias_set_type alias_set;
311 /* The offset of the first and byte after the last byte associated
312 with the operation. If begin == end == 0, the read did not have
313 a constant offset. */
314 int begin, end;
316 /* The mem being read. */
317 rtx mem;
319 /* The next read_info for this insn. */
320 struct read_info *next;
322 typedef struct read_info *read_info_t;
323 static alloc_pool read_info_pool;
326 /* One of these records is created for each insn. */
328 struct insn_info
330 /* Set true if the insn contains a store but the insn itself cannot
331 be deleted. This is set if the insn is a parallel and there is
332 more than one non dead output or if the insn is in some way
333 volatile. */
334 bool cannot_delete;
336 /* This field is only used by the global algorithm. It is set true
337 if the insn contains any read of mem except for a (1). This is
338 also set if the insn is a call or has a clobber mem. If the insn
339 contains a wild read, the use_rec will be null. */
340 bool wild_read;
342 /* This is true only for CALL instructions which could potentially read
343 any non-frame memory location. This field is used by the global
344 algorithm. */
345 bool non_frame_wild_read;
347 /* This field is only used for the processing of const functions.
348 These functions cannot read memory, but they can read the stack
349 because that is where they may get their parms. We need to be
350 this conservative because, like the store motion pass, we don't
351 consider CALL_INSN_FUNCTION_USAGE when processing call insns.
352 Moreover, we need to distinguish two cases:
353 1. Before reload (register elimination), the stores related to
354 outgoing arguments are stack pointer based and thus deemed
355 of non-constant base in this pass. This requires special
356 handling but also means that the frame pointer based stores
357 need not be killed upon encountering a const function call.
358 2. After reload, the stores related to outgoing arguments can be
359 either stack pointer or hard frame pointer based. This means
360 that we have no other choice than also killing all the frame
361 pointer based stores upon encountering a const function call.
362 This field is set after reload for const function calls. Having
363 this set is less severe than a wild read, it just means that all
364 the frame related stores are killed rather than all the stores. */
365 bool frame_read;
367 /* This field is only used for the processing of const functions.
368 It is set if the insn may contain a stack pointer based store. */
369 bool stack_pointer_based;
371 /* This is true if any of the sets within the store contains a
372 cselib base. Such stores can only be deleted by the local
373 algorithm. */
374 bool contains_cselib_groups;
376 /* The insn. */
377 rtx insn;
379 /* The list of mem sets or mem clobbers that are contained in this
380 insn. If the insn is deletable, it contains only one mem set.
381 But it could also contain clobbers. Insns that contain more than
382 one mem set are not deletable, but each of those mems are here in
383 order to provide info to delete other insns. */
384 store_info_t store_rec;
386 /* The linked list of mem uses in this insn. Only the reads from
387 rtx bases are listed here. The reads to cselib bases are
388 completely processed during the first scan and so are never
389 created. */
390 read_info_t read_rec;
392 /* The live fixed registers. We assume only fixed registers can
393 cause trouble by being clobbered from an expanded pattern;
394 storing only the live fixed registers (rather than all registers)
395 means less memory needs to be allocated / copied for the individual
396 stores. */
397 regset fixed_regs_live;
399 /* The prev insn in the basic block. */
400 struct insn_info * prev_insn;
402 /* The linked list of insns that are in consideration for removal in
403 the forwards pass through the basic block. This pointer may be
404 trash as it is not cleared when a wild read occurs. The only
405 time it is guaranteed to be correct is when the traversal starts
406 at active_local_stores. */
407 struct insn_info * next_local_store;
410 typedef struct insn_info *insn_info_t;
411 static alloc_pool insn_info_pool;
413 /* The linked list of stores that are under consideration in this
414 basic block. */
415 static insn_info_t active_local_stores;
416 static int active_local_stores_len;
418 struct bb_info
421 /* Pointer to the insn info for the last insn in the block. These
422 are linked so this is how all of the insns are reached. During
423 scanning this is the current insn being scanned. */
424 insn_info_t last_insn;
426 /* The info for the global dataflow problem. */
429 /* This is set if the transfer function should and in the wild_read
430 bitmap before applying the kill and gen sets. That vector knocks
431 out most of the bits in the bitmap and thus speeds up the
432 operations. */
433 bool apply_wild_read;
435 /* The following 4 bitvectors hold information about which positions
436 of which stores are live or dead. They are indexed by
437 get_bitmap_index. */
439 /* The set of store positions that exist in this block before a wild read. */
440 bitmap gen;
442 /* The set of load positions that exist in this block above the
443 same position of a store. */
444 bitmap kill;
446 /* The set of stores that reach the top of the block without being
447 killed by a read.
449 Do not represent the in if it is all ones. Note that this is
450 what the bitvector should logically be initialized to for a set
451 intersection problem. However, like the kill set, this is too
452 expensive. So initially, the in set will only be created for the
453 exit block and any block that contains a wild read. */
454 bitmap in;
456 /* The set of stores that reach the bottom of the block from it's
457 successors.
459 Do not represent the in if it is all ones. Note that this is
460 what the bitvector should logically be initialized to for a set
461 intersection problem. However, like the kill and in set, this is
462 too expensive. So what is done is that the confluence operator
463 just initializes the vector from one of the out sets of the
464 successors of the block. */
465 bitmap out;
467 /* The following bitvector is indexed by the reg number. It
468 contains the set of regs that are live at the current instruction
469 being processed. While it contains info for all of the
470 registers, only the hard registers are actually examined. It is used
471 to assure that shift and/or add sequences that are inserted do not
472 accidentally clobber live hard regs. */
473 bitmap regs_live;
476 typedef struct bb_info *bb_info_t;
477 static alloc_pool bb_info_pool;
479 /* Table to hold all bb_infos. */
480 static bb_info_t *bb_table;
482 /* There is a group_info for each rtx base that is used to reference
483 memory. There are also not many of the rtx bases because they are
484 very limited in scope. */
486 struct group_info
488 /* The actual base of the address. */
489 rtx rtx_base;
491 /* The sequential id of the base. This allows us to have a
492 canonical ordering of these that is not based on addresses. */
493 int id;
495 /* True if there are any positions that are to be processed
496 globally. */
497 bool process_globally;
499 /* True if the base of this group is either the frame_pointer or
500 hard_frame_pointer. */
501 bool frame_related;
503 /* A mem wrapped around the base pointer for the group in order to do
504 read dependency. It must be given BLKmode in order to encompass all
505 the possible offsets from the base. */
506 rtx base_mem;
508 /* Canonized version of base_mem's address. */
509 rtx canon_base_addr;
511 /* These two sets of two bitmaps are used to keep track of how many
512 stores are actually referencing that position from this base. We
513 only do this for rtx bases as this will be used to assign
514 positions in the bitmaps for the global problem. Bit N is set in
515 store1 on the first store for offset N. Bit N is set in store2
516 for the second store to offset N. This is all we need since we
517 only care about offsets that have two or more stores for them.
519 The "_n" suffix is for offsets less than 0 and the "_p" suffix is
520 for 0 and greater offsets.
522 There is one special case here, for stores into the stack frame,
523 we will or store1 into store2 before deciding which stores look
524 at globally. This is because stores to the stack frame that have
525 no other reads before the end of the function can also be
526 deleted. */
527 bitmap store1_n, store1_p, store2_n, store2_p;
529 /* These bitmaps keep track of offsets in this group escape this function.
530 An offset escapes if it corresponds to a named variable whose
531 addressable flag is set. */
532 bitmap escaped_n, escaped_p;
534 /* The positions in this bitmap have the same assignments as the in,
535 out, gen and kill bitmaps. This bitmap is all zeros except for
536 the positions that are occupied by stores for this group. */
537 bitmap group_kill;
539 /* The offset_map is used to map the offsets from this base into
540 positions in the global bitmaps. It is only created after all of
541 the all of stores have been scanned and we know which ones we
542 care about. */
543 int *offset_map_n, *offset_map_p;
544 int offset_map_size_n, offset_map_size_p;
546 typedef struct group_info *group_info_t;
547 typedef const struct group_info *const_group_info_t;
548 static alloc_pool rtx_group_info_pool;
550 /* Index into the rtx_group_vec. */
551 static int rtx_group_next_id;
554 static vec<group_info_t> rtx_group_vec;
557 /* This structure holds the set of changes that are being deferred
558 when removing read operation. See replace_read. */
559 struct deferred_change
562 /* The mem that is being replaced. */
563 rtx *loc;
565 /* The reg it is being replaced with. */
566 rtx reg;
568 struct deferred_change *next;
571 typedef struct deferred_change *deferred_change_t;
572 static alloc_pool deferred_change_pool;
574 static deferred_change_t deferred_change_list = NULL;
576 /* This are used to hold the alias sets of spill variables. Since
577 these are never aliased and there may be a lot of them, it makes
578 sense to treat them specially. This bitvector is only allocated in
579 calls from dse_record_singleton_alias_set which currently is only
580 made during reload1. So when dse is called before reload this
581 mechanism does nothing. */
583 static bitmap clear_alias_sets = NULL;
585 /* The set of clear_alias_sets that have been disqualified because
586 there are loads or stores using a different mode than the alias set
587 was registered with. */
588 static bitmap disqualified_clear_alias_sets = NULL;
590 /* The group that holds all of the clear_alias_sets. */
591 static group_info_t clear_alias_group;
593 /* The modes of the clear_alias_sets. */
594 static htab_t clear_alias_mode_table;
596 /* Hash table element to look up the mode for an alias set. */
597 struct clear_alias_mode_holder
599 alias_set_type alias_set;
600 enum machine_mode mode;
603 static alloc_pool clear_alias_mode_pool;
605 /* This is true except if cfun->stdarg -- i.e. we cannot do
606 this for vararg functions because they play games with the frame. */
607 static bool stores_off_frame_dead_at_return;
609 /* Counter for stats. */
610 static int globally_deleted;
611 static int locally_deleted;
612 static int spill_deleted;
614 static bitmap all_blocks;
616 /* Locations that are killed by calls in the global phase. */
617 static bitmap kill_on_calls;
619 /* The number of bits used in the global bitmaps. */
620 static unsigned int current_position;
623 static bool gate_dse1 (void);
624 static bool gate_dse2 (void);
627 /*----------------------------------------------------------------------------
628 Zeroth step.
630 Initialization.
631 ----------------------------------------------------------------------------*/
634 /* Find the entry associated with ALIAS_SET. */
636 static struct clear_alias_mode_holder *
637 clear_alias_set_lookup (alias_set_type alias_set)
639 struct clear_alias_mode_holder tmp_holder;
640 void **slot;
642 tmp_holder.alias_set = alias_set;
643 slot = htab_find_slot (clear_alias_mode_table, &tmp_holder, NO_INSERT);
644 gcc_assert (*slot);
646 return (struct clear_alias_mode_holder *) *slot;
650 /* Hashtable callbacks for maintaining the "bases" field of
651 store_group_info, given that the addresses are function invariants. */
653 struct invariant_group_base_hasher : typed_noop_remove <group_info>
655 typedef group_info value_type;
656 typedef group_info compare_type;
657 static inline hashval_t hash (const value_type *);
658 static inline bool equal (const value_type *, const compare_type *);
661 inline bool
662 invariant_group_base_hasher::equal (const value_type *gi1,
663 const compare_type *gi2)
665 return rtx_equal_p (gi1->rtx_base, gi2->rtx_base);
668 inline hashval_t
669 invariant_group_base_hasher::hash (const value_type *gi)
671 int do_not_record;
672 return hash_rtx (gi->rtx_base, Pmode, &do_not_record, NULL, false);
675 /* Tables of group_info structures, hashed by base value. */
676 static hash_table <invariant_group_base_hasher> rtx_group_table;
679 /* Get the GROUP for BASE. Add a new group if it is not there. */
681 static group_info_t
682 get_group_info (rtx base)
684 struct group_info tmp_gi;
685 group_info_t gi;
686 group_info **slot;
688 if (base)
690 /* Find the store_base_info structure for BASE, creating a new one
691 if necessary. */
692 tmp_gi.rtx_base = base;
693 slot = rtx_group_table.find_slot (&tmp_gi, INSERT);
694 gi = (group_info_t) *slot;
696 else
698 if (!clear_alias_group)
700 clear_alias_group = gi =
701 (group_info_t) pool_alloc (rtx_group_info_pool);
702 memset (gi, 0, sizeof (struct group_info));
703 gi->id = rtx_group_next_id++;
704 gi->store1_n = BITMAP_ALLOC (&dse_bitmap_obstack);
705 gi->store1_p = BITMAP_ALLOC (&dse_bitmap_obstack);
706 gi->store2_n = BITMAP_ALLOC (&dse_bitmap_obstack);
707 gi->store2_p = BITMAP_ALLOC (&dse_bitmap_obstack);
708 gi->escaped_p = BITMAP_ALLOC (&dse_bitmap_obstack);
709 gi->escaped_n = BITMAP_ALLOC (&dse_bitmap_obstack);
710 gi->group_kill = BITMAP_ALLOC (&dse_bitmap_obstack);
711 gi->process_globally = false;
712 gi->offset_map_size_n = 0;
713 gi->offset_map_size_p = 0;
714 gi->offset_map_n = NULL;
715 gi->offset_map_p = NULL;
716 rtx_group_vec.safe_push (gi);
718 return clear_alias_group;
721 if (gi == NULL)
723 *slot = gi = (group_info_t) pool_alloc (rtx_group_info_pool);
724 gi->rtx_base = base;
725 gi->id = rtx_group_next_id++;
726 gi->base_mem = gen_rtx_MEM (BLKmode, base);
727 gi->canon_base_addr = canon_rtx (base);
728 gi->store1_n = BITMAP_ALLOC (&dse_bitmap_obstack);
729 gi->store1_p = BITMAP_ALLOC (&dse_bitmap_obstack);
730 gi->store2_n = BITMAP_ALLOC (&dse_bitmap_obstack);
731 gi->store2_p = BITMAP_ALLOC (&dse_bitmap_obstack);
732 gi->escaped_p = BITMAP_ALLOC (&dse_bitmap_obstack);
733 gi->escaped_n = BITMAP_ALLOC (&dse_bitmap_obstack);
734 gi->group_kill = BITMAP_ALLOC (&dse_bitmap_obstack);
735 gi->process_globally = false;
736 gi->frame_related =
737 (base == frame_pointer_rtx) || (base == hard_frame_pointer_rtx);
738 gi->offset_map_size_n = 0;
739 gi->offset_map_size_p = 0;
740 gi->offset_map_n = NULL;
741 gi->offset_map_p = NULL;
742 rtx_group_vec.safe_push (gi);
745 return gi;
749 /* Initialization of data structures. */
751 static void
752 dse_step0 (void)
754 locally_deleted = 0;
755 globally_deleted = 0;
756 spill_deleted = 0;
758 bitmap_obstack_initialize (&dse_bitmap_obstack);
759 gcc_obstack_init (&dse_obstack);
761 scratch = BITMAP_ALLOC (&reg_obstack);
762 kill_on_calls = BITMAP_ALLOC (&dse_bitmap_obstack);
764 rtx_store_info_pool
765 = create_alloc_pool ("rtx_store_info_pool",
766 sizeof (struct store_info), 100);
767 read_info_pool
768 = create_alloc_pool ("read_info_pool",
769 sizeof (struct read_info), 100);
770 insn_info_pool
771 = create_alloc_pool ("insn_info_pool",
772 sizeof (struct insn_info), 100);
773 bb_info_pool
774 = create_alloc_pool ("bb_info_pool",
775 sizeof (struct bb_info), 100);
776 rtx_group_info_pool
777 = create_alloc_pool ("rtx_group_info_pool",
778 sizeof (struct group_info), 100);
779 deferred_change_pool
780 = create_alloc_pool ("deferred_change_pool",
781 sizeof (struct deferred_change), 10);
783 rtx_group_table.create (11);
785 bb_table = XNEWVEC (bb_info_t, last_basic_block);
786 rtx_group_next_id = 0;
788 stores_off_frame_dead_at_return = !cfun->stdarg;
790 init_alias_analysis ();
792 if (clear_alias_sets)
793 clear_alias_group = get_group_info (NULL);
794 else
795 clear_alias_group = NULL;
800 /*----------------------------------------------------------------------------
801 First step.
803 Scan all of the insns. Any random ordering of the blocks is fine.
804 Each block is scanned in forward order to accommodate cselib which
805 is used to remove stores with non-constant bases.
806 ----------------------------------------------------------------------------*/
808 /* Delete all of the store_info recs from INSN_INFO. */
810 static void
811 free_store_info (insn_info_t insn_info)
813 store_info_t store_info = insn_info->store_rec;
814 while (store_info)
816 store_info_t next = store_info->next;
817 if (store_info->is_large)
818 BITMAP_FREE (store_info->positions_needed.large.bmap);
819 if (store_info->cse_base)
820 pool_free (cse_store_info_pool, store_info);
821 else
822 pool_free (rtx_store_info_pool, store_info);
823 store_info = next;
826 insn_info->cannot_delete = true;
827 insn_info->contains_cselib_groups = false;
828 insn_info->store_rec = NULL;
831 typedef struct
833 rtx first, current;
834 regset fixed_regs_live;
835 bool failure;
836 } note_add_store_info;
838 /* Callback for emit_inc_dec_insn_before via note_stores.
839 Check if a register is clobbered which is live afterwards. */
841 static void
842 note_add_store (rtx loc, const_rtx expr ATTRIBUTE_UNUSED, void *data)
844 rtx insn;
845 note_add_store_info *info = (note_add_store_info *) data;
846 int r, n;
848 if (!REG_P (loc))
849 return;
851 /* If this register is referenced by the current or an earlier insn,
852 that's OK. E.g. this applies to the register that is being incremented
853 with this addition. */
854 for (insn = info->first;
855 insn != NEXT_INSN (info->current);
856 insn = NEXT_INSN (insn))
857 if (reg_referenced_p (loc, PATTERN (insn)))
858 return;
860 /* If we come here, we have a clobber of a register that's only OK
861 if that register is not live. If we don't have liveness information
862 available, fail now. */
863 if (!info->fixed_regs_live)
865 info->failure = true;
866 return;
868 /* Now check if this is a live fixed register. */
869 r = REGNO (loc);
870 n = hard_regno_nregs[r][GET_MODE (loc)];
871 while (--n >= 0)
872 if (REGNO_REG_SET_P (info->fixed_regs_live, r+n))
873 info->failure = true;
876 /* Callback for for_each_inc_dec that emits an INSN that sets DEST to
877 SRC + SRCOFF before insn ARG. */
879 static int
880 emit_inc_dec_insn_before (rtx mem ATTRIBUTE_UNUSED,
881 rtx op ATTRIBUTE_UNUSED,
882 rtx dest, rtx src, rtx srcoff, void *arg)
884 insn_info_t insn_info = (insn_info_t) arg;
885 rtx insn = insn_info->insn, new_insn, cur;
886 note_add_store_info info;
888 /* We can reuse all operands without copying, because we are about
889 to delete the insn that contained it. */
890 if (srcoff)
892 start_sequence ();
893 emit_insn (gen_add3_insn (dest, src, srcoff));
894 new_insn = get_insns ();
895 end_sequence ();
897 else
898 new_insn = gen_move_insn (dest, src);
899 info.first = new_insn;
900 info.fixed_regs_live = insn_info->fixed_regs_live;
901 info.failure = false;
902 for (cur = new_insn; cur; cur = NEXT_INSN (cur))
904 info.current = cur;
905 note_stores (PATTERN (cur), note_add_store, &info);
908 /* If a failure was flagged above, return 1 so that for_each_inc_dec will
909 return it immediately, communicating the failure to its caller. */
910 if (info.failure)
911 return 1;
913 emit_insn_before (new_insn, insn);
915 return -1;
918 /* Before we delete INSN_INFO->INSN, make sure that the auto inc/dec, if it
919 is there, is split into a separate insn.
920 Return true on success (or if there was nothing to do), false on failure. */
922 static bool
923 check_for_inc_dec_1 (insn_info_t insn_info)
925 rtx insn = insn_info->insn;
926 rtx note = find_reg_note (insn, REG_INC, NULL_RTX);
927 if (note)
928 return for_each_inc_dec (&insn, emit_inc_dec_insn_before, insn_info) == 0;
929 return true;
933 /* Entry point for postreload. If you work on reload_cse, or you need this
934 anywhere else, consider if you can provide register liveness information
935 and add a parameter to this function so that it can be passed down in
936 insn_info.fixed_regs_live. */
937 bool
938 check_for_inc_dec (rtx insn)
940 struct insn_info insn_info;
941 rtx note;
943 insn_info.insn = insn;
944 insn_info.fixed_regs_live = NULL;
945 note = find_reg_note (insn, REG_INC, NULL_RTX);
946 if (note)
947 return for_each_inc_dec (&insn, emit_inc_dec_insn_before, &insn_info) == 0;
948 return true;
951 /* Delete the insn and free all of the fields inside INSN_INFO. */
953 static void
954 delete_dead_store_insn (insn_info_t insn_info)
956 read_info_t read_info;
958 if (!dbg_cnt (dse))
959 return;
961 if (!check_for_inc_dec_1 (insn_info))
962 return;
963 if (dump_file)
965 fprintf (dump_file, "Locally deleting insn %d ",
966 INSN_UID (insn_info->insn));
967 if (insn_info->store_rec->alias_set)
968 fprintf (dump_file, "alias set %d\n",
969 (int) insn_info->store_rec->alias_set);
970 else
971 fprintf (dump_file, "\n");
974 free_store_info (insn_info);
975 read_info = insn_info->read_rec;
977 while (read_info)
979 read_info_t next = read_info->next;
980 pool_free (read_info_pool, read_info);
981 read_info = next;
983 insn_info->read_rec = NULL;
985 delete_insn (insn_info->insn);
986 locally_deleted++;
987 insn_info->insn = NULL;
989 insn_info->wild_read = false;
992 /* Return whether DECL, a local variable, can possibly escape the current
993 function scope. */
995 static bool
996 local_variable_can_escape (tree decl)
998 if (TREE_ADDRESSABLE (decl))
999 return true;
1001 /* If this is a partitioned variable, we need to consider all the variables
1002 in the partition. This is necessary because a store into one of them can
1003 be replaced with a store into another and this may not change the outcome
1004 of the escape analysis. */
1005 if (cfun->gimple_df->decls_to_pointers != NULL)
1007 void *namep
1008 = pointer_map_contains (cfun->gimple_df->decls_to_pointers, decl);
1009 if (namep)
1010 return TREE_ADDRESSABLE (*(tree *)namep);
1013 return false;
1016 /* Return whether EXPR can possibly escape the current function scope. */
1018 static bool
1019 can_escape (tree expr)
1021 tree base;
1022 if (!expr)
1023 return true;
1024 base = get_base_address (expr);
1025 if (DECL_P (base)
1026 && !may_be_aliased (base)
1027 && !(TREE_CODE (base) == VAR_DECL
1028 && !DECL_EXTERNAL (base)
1029 && !TREE_STATIC (base)
1030 && local_variable_can_escape (base)))
1031 return false;
1032 return true;
1035 /* Set the store* bitmaps offset_map_size* fields in GROUP based on
1036 OFFSET and WIDTH. */
1038 static void
1039 set_usage_bits (group_info_t group, HOST_WIDE_INT offset, HOST_WIDE_INT width,
1040 tree expr)
1042 HOST_WIDE_INT i;
1043 bool expr_escapes = can_escape (expr);
1044 if (offset > -MAX_OFFSET && offset + width < MAX_OFFSET)
1045 for (i=offset; i<offset+width; i++)
1047 bitmap store1;
1048 bitmap store2;
1049 bitmap escaped;
1050 int ai;
1051 if (i < 0)
1053 store1 = group->store1_n;
1054 store2 = group->store2_n;
1055 escaped = group->escaped_n;
1056 ai = -i;
1058 else
1060 store1 = group->store1_p;
1061 store2 = group->store2_p;
1062 escaped = group->escaped_p;
1063 ai = i;
1066 if (!bitmap_set_bit (store1, ai))
1067 bitmap_set_bit (store2, ai);
1068 else
1070 if (i < 0)
1072 if (group->offset_map_size_n < ai)
1073 group->offset_map_size_n = ai;
1075 else
1077 if (group->offset_map_size_p < ai)
1078 group->offset_map_size_p = ai;
1081 if (expr_escapes)
1082 bitmap_set_bit (escaped, ai);
1086 static void
1087 reset_active_stores (void)
1089 active_local_stores = NULL;
1090 active_local_stores_len = 0;
1093 /* Free all READ_REC of the LAST_INSN of BB_INFO. */
1095 static void
1096 free_read_records (bb_info_t bb_info)
1098 insn_info_t insn_info = bb_info->last_insn;
1099 read_info_t *ptr = &insn_info->read_rec;
1100 while (*ptr)
1102 read_info_t next = (*ptr)->next;
1103 if ((*ptr)->alias_set == 0)
1105 pool_free (read_info_pool, *ptr);
1106 *ptr = next;
1108 else
1109 ptr = &(*ptr)->next;
1113 /* Set the BB_INFO so that the last insn is marked as a wild read. */
1115 static void
1116 add_wild_read (bb_info_t bb_info)
1118 insn_info_t insn_info = bb_info->last_insn;
1119 insn_info->wild_read = true;
1120 free_read_records (bb_info);
1121 reset_active_stores ();
1124 /* Set the BB_INFO so that the last insn is marked as a wild read of
1125 non-frame locations. */
1127 static void
1128 add_non_frame_wild_read (bb_info_t bb_info)
1130 insn_info_t insn_info = bb_info->last_insn;
1131 insn_info->non_frame_wild_read = true;
1132 free_read_records (bb_info);
1133 reset_active_stores ();
1136 /* Return true if X is a constant or one of the registers that behave
1137 as a constant over the life of a function. This is equivalent to
1138 !rtx_varies_p for memory addresses. */
1140 static bool
1141 const_or_frame_p (rtx x)
1143 if (CONSTANT_P (x))
1144 return true;
1146 if (GET_CODE (x) == REG)
1148 /* Note that we have to test for the actual rtx used for the frame
1149 and arg pointers and not just the register number in case we have
1150 eliminated the frame and/or arg pointer and are using it
1151 for pseudos. */
1152 if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
1153 /* The arg pointer varies if it is not a fixed register. */
1154 || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])
1155 || x == pic_offset_table_rtx)
1156 return true;
1157 return false;
1160 return false;
1163 /* Take all reasonable action to put the address of MEM into the form
1164 that we can do analysis on.
1166 The gold standard is to get the address into the form: address +
1167 OFFSET where address is something that rtx_varies_p considers a
1168 constant. When we can get the address in this form, we can do
1169 global analysis on it. Note that for constant bases, address is
1170 not actually returned, only the group_id. The address can be
1171 obtained from that.
1173 If that fails, we try cselib to get a value we can at least use
1174 locally. If that fails we return false.
1176 The GROUP_ID is set to -1 for cselib bases and the index of the
1177 group for non_varying bases.
1179 FOR_READ is true if this is a mem read and false if not. */
1181 static bool
1182 canon_address (rtx mem,
1183 alias_set_type *alias_set_out,
1184 int *group_id,
1185 HOST_WIDE_INT *offset,
1186 cselib_val **base)
1188 enum machine_mode address_mode = get_address_mode (mem);
1189 rtx mem_address = XEXP (mem, 0);
1190 rtx expanded_address, address;
1191 int expanded;
1193 /* Make sure that cselib is has initialized all of the operands of
1194 the address before asking it to do the subst. */
1196 if (clear_alias_sets)
1198 /* If this is a spill, do not do any further processing. */
1199 alias_set_type alias_set = MEM_ALIAS_SET (mem);
1200 if (dump_file)
1201 fprintf (dump_file, "found alias set %d\n", (int) alias_set);
1202 if (bitmap_bit_p (clear_alias_sets, alias_set))
1204 struct clear_alias_mode_holder *entry
1205 = clear_alias_set_lookup (alias_set);
1207 /* If the modes do not match, we cannot process this set. */
1208 if (entry->mode != GET_MODE (mem))
1210 if (dump_file)
1211 fprintf (dump_file,
1212 "disqualifying alias set %d, (%s) != (%s)\n",
1213 (int) alias_set, GET_MODE_NAME (entry->mode),
1214 GET_MODE_NAME (GET_MODE (mem)));
1216 bitmap_set_bit (disqualified_clear_alias_sets, alias_set);
1217 return false;
1220 *alias_set_out = alias_set;
1221 *group_id = clear_alias_group->id;
1222 return true;
1226 *alias_set_out = 0;
1228 cselib_lookup (mem_address, address_mode, 1, GET_MODE (mem));
1230 if (dump_file)
1232 fprintf (dump_file, " mem: ");
1233 print_inline_rtx (dump_file, mem_address, 0);
1234 fprintf (dump_file, "\n");
1237 /* First see if just canon_rtx (mem_address) is const or frame,
1238 if not, try cselib_expand_value_rtx and call canon_rtx on that. */
1239 address = NULL_RTX;
1240 for (expanded = 0; expanded < 2; expanded++)
1242 if (expanded)
1244 /* Use cselib to replace all of the reg references with the full
1245 expression. This will take care of the case where we have
1247 r_x = base + offset;
1248 val = *r_x;
1250 by making it into
1252 val = *(base + offset); */
1254 expanded_address = cselib_expand_value_rtx (mem_address,
1255 scratch, 5);
1257 /* If this fails, just go with the address from first
1258 iteration. */
1259 if (!expanded_address)
1260 break;
1262 else
1263 expanded_address = mem_address;
1265 /* Split the address into canonical BASE + OFFSET terms. */
1266 address = canon_rtx (expanded_address);
1268 *offset = 0;
1270 if (dump_file)
1272 if (expanded)
1274 fprintf (dump_file, "\n after cselib_expand address: ");
1275 print_inline_rtx (dump_file, expanded_address, 0);
1276 fprintf (dump_file, "\n");
1279 fprintf (dump_file, "\n after canon_rtx address: ");
1280 print_inline_rtx (dump_file, address, 0);
1281 fprintf (dump_file, "\n");
1284 if (GET_CODE (address) == CONST)
1285 address = XEXP (address, 0);
1287 if (GET_CODE (address) == PLUS
1288 && CONST_INT_P (XEXP (address, 1)))
1290 *offset = INTVAL (XEXP (address, 1));
1291 address = XEXP (address, 0);
1294 if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (mem))
1295 && const_or_frame_p (address))
1297 group_info_t group = get_group_info (address);
1299 if (dump_file)
1300 fprintf (dump_file, " gid=%d offset=%d \n",
1301 group->id, (int)*offset);
1302 *base = NULL;
1303 *group_id = group->id;
1304 return true;
1308 *base = cselib_lookup (address, address_mode, true, GET_MODE (mem));
1309 *group_id = -1;
1311 if (*base == NULL)
1313 if (dump_file)
1314 fprintf (dump_file, " no cselib val - should be a wild read.\n");
1315 return false;
1317 if (dump_file)
1318 fprintf (dump_file, " varying cselib base=%u:%u offset = %d\n",
1319 (*base)->uid, (*base)->hash, (int)*offset);
1320 return true;
1324 /* Clear the rhs field from the active_local_stores array. */
1326 static void
1327 clear_rhs_from_active_local_stores (void)
1329 insn_info_t ptr = active_local_stores;
1331 while (ptr)
1333 store_info_t store_info = ptr->store_rec;
1334 /* Skip the clobbers. */
1335 while (!store_info->is_set)
1336 store_info = store_info->next;
1338 store_info->rhs = NULL;
1339 store_info->const_rhs = NULL;
1341 ptr = ptr->next_local_store;
1346 /* Mark byte POS bytes from the beginning of store S_INFO as unneeded. */
1348 static inline void
1349 set_position_unneeded (store_info_t s_info, int pos)
1351 if (__builtin_expect (s_info->is_large, false))
1353 if (bitmap_set_bit (s_info->positions_needed.large.bmap, pos))
1354 s_info->positions_needed.large.count++;
1356 else
1357 s_info->positions_needed.small_bitmask
1358 &= ~(((unsigned HOST_WIDE_INT) 1) << pos);
1361 /* Mark the whole store S_INFO as unneeded. */
1363 static inline void
1364 set_all_positions_unneeded (store_info_t s_info)
1366 if (__builtin_expect (s_info->is_large, false))
1368 int pos, end = s_info->end - s_info->begin;
1369 for (pos = 0; pos < end; pos++)
1370 bitmap_set_bit (s_info->positions_needed.large.bmap, pos);
1371 s_info->positions_needed.large.count = end;
1373 else
1374 s_info->positions_needed.small_bitmask = (unsigned HOST_WIDE_INT) 0;
1377 /* Return TRUE if any bytes from S_INFO store are needed. */
1379 static inline bool
1380 any_positions_needed_p (store_info_t s_info)
1382 if (__builtin_expect (s_info->is_large, false))
1383 return (s_info->positions_needed.large.count
1384 < s_info->end - s_info->begin);
1385 else
1386 return (s_info->positions_needed.small_bitmask
1387 != (unsigned HOST_WIDE_INT) 0);
1390 /* Return TRUE if all bytes START through START+WIDTH-1 from S_INFO
1391 store are needed. */
1393 static inline bool
1394 all_positions_needed_p (store_info_t s_info, int start, int width)
1396 if (__builtin_expect (s_info->is_large, false))
1398 int end = start + width;
1399 while (start < end)
1400 if (bitmap_bit_p (s_info->positions_needed.large.bmap, start++))
1401 return false;
1402 return true;
1404 else
1406 unsigned HOST_WIDE_INT mask = lowpart_bitmask (width) << start;
1407 return (s_info->positions_needed.small_bitmask & mask) == mask;
1412 static rtx get_stored_val (store_info_t, enum machine_mode, HOST_WIDE_INT,
1413 HOST_WIDE_INT, basic_block, bool);
1416 /* BODY is an instruction pattern that belongs to INSN. Return 1 if
1417 there is a candidate store, after adding it to the appropriate
1418 local store group if so. */
1420 static int
1421 record_store (rtx body, bb_info_t bb_info)
1423 rtx mem, rhs, const_rhs, mem_addr;
1424 HOST_WIDE_INT offset = 0;
1425 HOST_WIDE_INT width = 0;
1426 alias_set_type spill_alias_set;
1427 insn_info_t insn_info = bb_info->last_insn;
1428 store_info_t store_info = NULL;
1429 int group_id;
1430 cselib_val *base = NULL;
1431 insn_info_t ptr, last, redundant_reason;
1432 bool store_is_unused;
1434 if (GET_CODE (body) != SET && GET_CODE (body) != CLOBBER)
1435 return 0;
1437 mem = SET_DEST (body);
1439 /* If this is not used, then this cannot be used to keep the insn
1440 from being deleted. On the other hand, it does provide something
1441 that can be used to prove that another store is dead. */
1442 store_is_unused
1443 = (find_reg_note (insn_info->insn, REG_UNUSED, mem) != NULL);
1445 /* Check whether that value is a suitable memory location. */
1446 if (!MEM_P (mem))
1448 /* If the set or clobber is unused, then it does not effect our
1449 ability to get rid of the entire insn. */
1450 if (!store_is_unused)
1451 insn_info->cannot_delete = true;
1452 return 0;
1455 /* At this point we know mem is a mem. */
1456 if (GET_MODE (mem) == BLKmode)
1458 if (GET_CODE (XEXP (mem, 0)) == SCRATCH)
1460 if (dump_file)
1461 fprintf (dump_file, " adding wild read for (clobber (mem:BLK (scratch))\n");
1462 add_wild_read (bb_info);
1463 insn_info->cannot_delete = true;
1464 return 0;
1466 /* Handle (set (mem:BLK (addr) [... S36 ...]) (const_int 0))
1467 as memset (addr, 0, 36); */
1468 else if (!MEM_SIZE_KNOWN_P (mem)
1469 || MEM_SIZE (mem) <= 0
1470 || MEM_SIZE (mem) > MAX_OFFSET
1471 || GET_CODE (body) != SET
1472 || !CONST_INT_P (SET_SRC (body)))
1474 if (!store_is_unused)
1476 /* If the set or clobber is unused, then it does not effect our
1477 ability to get rid of the entire insn. */
1478 insn_info->cannot_delete = true;
1479 clear_rhs_from_active_local_stores ();
1481 return 0;
1485 /* We can still process a volatile mem, we just cannot delete it. */
1486 if (MEM_VOLATILE_P (mem))
1487 insn_info->cannot_delete = true;
1489 if (!canon_address (mem, &spill_alias_set, &group_id, &offset, &base))
1491 clear_rhs_from_active_local_stores ();
1492 return 0;
1495 if (GET_MODE (mem) == BLKmode)
1496 width = MEM_SIZE (mem);
1497 else
1499 width = GET_MODE_SIZE (GET_MODE (mem));
1500 gcc_assert ((unsigned) width <= HOST_BITS_PER_WIDE_INT);
1503 if (spill_alias_set)
1505 bitmap store1 = clear_alias_group->store1_p;
1506 bitmap store2 = clear_alias_group->store2_p;
1508 gcc_assert (GET_MODE (mem) != BLKmode);
1510 if (!bitmap_set_bit (store1, spill_alias_set))
1511 bitmap_set_bit (store2, spill_alias_set);
1513 if (clear_alias_group->offset_map_size_p < spill_alias_set)
1514 clear_alias_group->offset_map_size_p = spill_alias_set;
1516 store_info = (store_info_t) pool_alloc (rtx_store_info_pool);
1518 if (dump_file)
1519 fprintf (dump_file, " processing spill store %d(%s)\n",
1520 (int) spill_alias_set, GET_MODE_NAME (GET_MODE (mem)));
1522 else if (group_id >= 0)
1524 /* In the restrictive case where the base is a constant or the
1525 frame pointer we can do global analysis. */
1527 group_info_t group
1528 = rtx_group_vec[group_id];
1529 tree expr = MEM_EXPR (mem);
1531 store_info = (store_info_t) pool_alloc (rtx_store_info_pool);
1532 set_usage_bits (group, offset, width, expr);
1534 if (dump_file)
1535 fprintf (dump_file, " processing const base store gid=%d[%d..%d)\n",
1536 group_id, (int)offset, (int)(offset+width));
1538 else
1540 if (may_be_sp_based_p (XEXP (mem, 0)))
1541 insn_info->stack_pointer_based = true;
1542 insn_info->contains_cselib_groups = true;
1544 store_info = (store_info_t) pool_alloc (cse_store_info_pool);
1545 group_id = -1;
1547 if (dump_file)
1548 fprintf (dump_file, " processing cselib store [%d..%d)\n",
1549 (int)offset, (int)(offset+width));
1552 const_rhs = rhs = NULL_RTX;
1553 if (GET_CODE (body) == SET
1554 /* No place to keep the value after ra. */
1555 && !reload_completed
1556 && (REG_P (SET_SRC (body))
1557 || GET_CODE (SET_SRC (body)) == SUBREG
1558 || CONSTANT_P (SET_SRC (body)))
1559 && !MEM_VOLATILE_P (mem)
1560 /* Sometimes the store and reload is used for truncation and
1561 rounding. */
1562 && !(FLOAT_MODE_P (GET_MODE (mem)) && (flag_float_store)))
1564 rhs = SET_SRC (body);
1565 if (CONSTANT_P (rhs))
1566 const_rhs = rhs;
1567 else if (body == PATTERN (insn_info->insn))
1569 rtx tem = find_reg_note (insn_info->insn, REG_EQUAL, NULL_RTX);
1570 if (tem && CONSTANT_P (XEXP (tem, 0)))
1571 const_rhs = XEXP (tem, 0);
1573 if (const_rhs == NULL_RTX && REG_P (rhs))
1575 rtx tem = cselib_expand_value_rtx (rhs, scratch, 5);
1577 if (tem && CONSTANT_P (tem))
1578 const_rhs = tem;
1582 /* Check to see if this stores causes some other stores to be
1583 dead. */
1584 ptr = active_local_stores;
1585 last = NULL;
1586 redundant_reason = NULL;
1587 mem = canon_rtx (mem);
1588 /* For alias_set != 0 canon_true_dependence should be never called. */
1589 if (spill_alias_set)
1590 mem_addr = NULL_RTX;
1591 else
1593 if (group_id < 0)
1594 mem_addr = base->val_rtx;
1595 else
1597 group_info_t group
1598 = rtx_group_vec[group_id];
1599 mem_addr = group->canon_base_addr;
1601 if (offset)
1602 mem_addr = plus_constant (get_address_mode (mem), mem_addr, offset);
1605 while (ptr)
1607 insn_info_t next = ptr->next_local_store;
1608 store_info_t s_info = ptr->store_rec;
1609 bool del = true;
1611 /* Skip the clobbers. We delete the active insn if this insn
1612 shadows the set. To have been put on the active list, it
1613 has exactly on set. */
1614 while (!s_info->is_set)
1615 s_info = s_info->next;
1617 if (s_info->alias_set != spill_alias_set)
1618 del = false;
1619 else if (s_info->alias_set)
1621 struct clear_alias_mode_holder *entry
1622 = clear_alias_set_lookup (s_info->alias_set);
1623 /* Generally, spills cannot be processed if and of the
1624 references to the slot have a different mode. But if
1625 we are in the same block and mode is exactly the same
1626 between this store and one before in the same block,
1627 we can still delete it. */
1628 if ((GET_MODE (mem) == GET_MODE (s_info->mem))
1629 && (GET_MODE (mem) == entry->mode))
1631 del = true;
1632 set_all_positions_unneeded (s_info);
1634 if (dump_file)
1635 fprintf (dump_file, " trying spill store in insn=%d alias_set=%d\n",
1636 INSN_UID (ptr->insn), (int) s_info->alias_set);
1638 else if ((s_info->group_id == group_id)
1639 && (s_info->cse_base == base))
1641 HOST_WIDE_INT i;
1642 if (dump_file)
1643 fprintf (dump_file, " trying store in insn=%d gid=%d[%d..%d)\n",
1644 INSN_UID (ptr->insn), s_info->group_id,
1645 (int)s_info->begin, (int)s_info->end);
1647 /* Even if PTR won't be eliminated as unneeded, if both
1648 PTR and this insn store the same constant value, we might
1649 eliminate this insn instead. */
1650 if (s_info->const_rhs
1651 && const_rhs
1652 && offset >= s_info->begin
1653 && offset + width <= s_info->end
1654 && all_positions_needed_p (s_info, offset - s_info->begin,
1655 width))
1657 if (GET_MODE (mem) == BLKmode)
1659 if (GET_MODE (s_info->mem) == BLKmode
1660 && s_info->const_rhs == const_rhs)
1661 redundant_reason = ptr;
1663 else if (s_info->const_rhs == const0_rtx
1664 && const_rhs == const0_rtx)
1665 redundant_reason = ptr;
1666 else
1668 rtx val;
1669 start_sequence ();
1670 val = get_stored_val (s_info, GET_MODE (mem),
1671 offset, offset + width,
1672 BLOCK_FOR_INSN (insn_info->insn),
1673 true);
1674 if (get_insns () != NULL)
1675 val = NULL_RTX;
1676 end_sequence ();
1677 if (val && rtx_equal_p (val, const_rhs))
1678 redundant_reason = ptr;
1682 for (i = MAX (offset, s_info->begin);
1683 i < offset + width && i < s_info->end;
1684 i++)
1685 set_position_unneeded (s_info, i - s_info->begin);
1687 else if (s_info->rhs)
1688 /* Need to see if it is possible for this store to overwrite
1689 the value of store_info. If it is, set the rhs to NULL to
1690 keep it from being used to remove a load. */
1692 if (canon_true_dependence (s_info->mem,
1693 GET_MODE (s_info->mem),
1694 s_info->mem_addr,
1695 mem, mem_addr))
1697 s_info->rhs = NULL;
1698 s_info->const_rhs = NULL;
1702 /* An insn can be deleted if every position of every one of
1703 its s_infos is zero. */
1704 if (any_positions_needed_p (s_info))
1705 del = false;
1707 if (del)
1709 insn_info_t insn_to_delete = ptr;
1711 active_local_stores_len--;
1712 if (last)
1713 last->next_local_store = ptr->next_local_store;
1714 else
1715 active_local_stores = ptr->next_local_store;
1717 if (!insn_to_delete->cannot_delete)
1718 delete_dead_store_insn (insn_to_delete);
1720 else
1721 last = ptr;
1723 ptr = next;
1726 /* Finish filling in the store_info. */
1727 store_info->next = insn_info->store_rec;
1728 insn_info->store_rec = store_info;
1729 store_info->mem = mem;
1730 store_info->alias_set = spill_alias_set;
1731 store_info->mem_addr = mem_addr;
1732 store_info->cse_base = base;
1733 if (width > HOST_BITS_PER_WIDE_INT)
1735 store_info->is_large = true;
1736 store_info->positions_needed.large.count = 0;
1737 store_info->positions_needed.large.bmap = BITMAP_ALLOC (&dse_bitmap_obstack);
1739 else
1741 store_info->is_large = false;
1742 store_info->positions_needed.small_bitmask = lowpart_bitmask (width);
1744 store_info->group_id = group_id;
1745 store_info->begin = offset;
1746 store_info->end = offset + width;
1747 store_info->is_set = GET_CODE (body) == SET;
1748 store_info->rhs = rhs;
1749 store_info->const_rhs = const_rhs;
1750 store_info->redundant_reason = redundant_reason;
1752 /* If this is a clobber, we return 0. We will only be able to
1753 delete this insn if there is only one store USED store, but we
1754 can use the clobber to delete other stores earlier. */
1755 return store_info->is_set ? 1 : 0;
1759 static void
1760 dump_insn_info (const char * start, insn_info_t insn_info)
1762 fprintf (dump_file, "%s insn=%d %s\n", start,
1763 INSN_UID (insn_info->insn),
1764 insn_info->store_rec ? "has store" : "naked");
1768 /* If the modes are different and the value's source and target do not
1769 line up, we need to extract the value from lower part of the rhs of
1770 the store, shift it, and then put it into a form that can be shoved
1771 into the read_insn. This function generates a right SHIFT of a
1772 value that is at least ACCESS_SIZE bytes wide of READ_MODE. The
1773 shift sequence is returned or NULL if we failed to find a
1774 shift. */
1776 static rtx
1777 find_shift_sequence (int access_size,
1778 store_info_t store_info,
1779 enum machine_mode read_mode,
1780 int shift, bool speed, bool require_cst)
1782 enum machine_mode store_mode = GET_MODE (store_info->mem);
1783 enum machine_mode new_mode;
1784 rtx read_reg = NULL;
1786 /* Some machines like the x86 have shift insns for each size of
1787 operand. Other machines like the ppc or the ia-64 may only have
1788 shift insns that shift values within 32 or 64 bit registers.
1789 This loop tries to find the smallest shift insn that will right
1790 justify the value we want to read but is available in one insn on
1791 the machine. */
1793 for (new_mode = smallest_mode_for_size (access_size * BITS_PER_UNIT,
1794 MODE_INT);
1795 GET_MODE_BITSIZE (new_mode) <= BITS_PER_WORD;
1796 new_mode = GET_MODE_WIDER_MODE (new_mode))
1798 rtx target, new_reg, shift_seq, insn, new_lhs;
1799 int cost;
1801 /* If a constant was stored into memory, try to simplify it here,
1802 otherwise the cost of the shift might preclude this optimization
1803 e.g. at -Os, even when no actual shift will be needed. */
1804 if (store_info->const_rhs)
1806 unsigned int byte = subreg_lowpart_offset (new_mode, store_mode);
1807 rtx ret = simplify_subreg (new_mode, store_info->const_rhs,
1808 store_mode, byte);
1809 if (ret && CONSTANT_P (ret))
1811 ret = simplify_const_binary_operation (LSHIFTRT, new_mode,
1812 ret, GEN_INT (shift));
1813 if (ret && CONSTANT_P (ret))
1815 byte = subreg_lowpart_offset (read_mode, new_mode);
1816 ret = simplify_subreg (read_mode, ret, new_mode, byte);
1817 if (ret && CONSTANT_P (ret)
1818 && set_src_cost (ret, speed) <= COSTS_N_INSNS (1))
1819 return ret;
1824 if (require_cst)
1825 return NULL_RTX;
1827 /* Try a wider mode if truncating the store mode to NEW_MODE
1828 requires a real instruction. */
1829 if (GET_MODE_BITSIZE (new_mode) < GET_MODE_BITSIZE (store_mode)
1830 && !TRULY_NOOP_TRUNCATION_MODES_P (new_mode, store_mode))
1831 continue;
1833 /* Also try a wider mode if the necessary punning is either not
1834 desirable or not possible. */
1835 if (!CONSTANT_P (store_info->rhs)
1836 && !MODES_TIEABLE_P (new_mode, store_mode))
1837 continue;
1839 new_reg = gen_reg_rtx (new_mode);
1841 start_sequence ();
1843 /* In theory we could also check for an ashr. Ian Taylor knows
1844 of one dsp where the cost of these two was not the same. But
1845 this really is a rare case anyway. */
1846 target = expand_binop (new_mode, lshr_optab, new_reg,
1847 GEN_INT (shift), new_reg, 1, OPTAB_DIRECT);
1849 shift_seq = get_insns ();
1850 end_sequence ();
1852 if (target != new_reg || shift_seq == NULL)
1853 continue;
1855 cost = 0;
1856 for (insn = shift_seq; insn != NULL_RTX; insn = NEXT_INSN (insn))
1857 if (INSN_P (insn))
1858 cost += insn_rtx_cost (PATTERN (insn), speed);
1860 /* The computation up to here is essentially independent
1861 of the arguments and could be precomputed. It may
1862 not be worth doing so. We could precompute if
1863 worthwhile or at least cache the results. The result
1864 technically depends on both SHIFT and ACCESS_SIZE,
1865 but in practice the answer will depend only on ACCESS_SIZE. */
1867 if (cost > COSTS_N_INSNS (1))
1868 continue;
1870 new_lhs = extract_low_bits (new_mode, store_mode,
1871 copy_rtx (store_info->rhs));
1872 if (new_lhs == NULL_RTX)
1873 continue;
1875 /* We found an acceptable shift. Generate a move to
1876 take the value from the store and put it into the
1877 shift pseudo, then shift it, then generate another
1878 move to put in into the target of the read. */
1879 emit_move_insn (new_reg, new_lhs);
1880 emit_insn (shift_seq);
1881 read_reg = extract_low_bits (read_mode, new_mode, new_reg);
1882 break;
1885 return read_reg;
1889 /* Call back for note_stores to find the hard regs set or clobbered by
1890 insn. Data is a bitmap of the hardregs set so far. */
1892 static void
1893 look_for_hardregs (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
1895 bitmap regs_set = (bitmap) data;
1897 if (REG_P (x)
1898 && HARD_REGISTER_P (x))
1900 unsigned int regno = REGNO (x);
1901 bitmap_set_range (regs_set, regno,
1902 hard_regno_nregs[regno][GET_MODE (x)]);
1906 /* Helper function for replace_read and record_store.
1907 Attempt to return a value stored in STORE_INFO, from READ_BEGIN
1908 to one before READ_END bytes read in READ_MODE. Return NULL
1909 if not successful. If REQUIRE_CST is true, return always constant. */
1911 static rtx
1912 get_stored_val (store_info_t store_info, enum machine_mode read_mode,
1913 HOST_WIDE_INT read_begin, HOST_WIDE_INT read_end,
1914 basic_block bb, bool require_cst)
1916 enum machine_mode store_mode = GET_MODE (store_info->mem);
1917 int shift;
1918 int access_size; /* In bytes. */
1919 rtx read_reg;
1921 /* To get here the read is within the boundaries of the write so
1922 shift will never be negative. Start out with the shift being in
1923 bytes. */
1924 if (store_mode == BLKmode)
1925 shift = 0;
1926 else if (BYTES_BIG_ENDIAN)
1927 shift = store_info->end - read_end;
1928 else
1929 shift = read_begin - store_info->begin;
1931 access_size = shift + GET_MODE_SIZE (read_mode);
1933 /* From now on it is bits. */
1934 shift *= BITS_PER_UNIT;
1936 if (shift)
1937 read_reg = find_shift_sequence (access_size, store_info, read_mode, shift,
1938 optimize_bb_for_speed_p (bb),
1939 require_cst);
1940 else if (store_mode == BLKmode)
1942 /* The store is a memset (addr, const_val, const_size). */
1943 gcc_assert (CONST_INT_P (store_info->rhs));
1944 store_mode = int_mode_for_mode (read_mode);
1945 if (store_mode == BLKmode)
1946 read_reg = NULL_RTX;
1947 else if (store_info->rhs == const0_rtx)
1948 read_reg = extract_low_bits (read_mode, store_mode, const0_rtx);
1949 else if (GET_MODE_BITSIZE (store_mode) > HOST_BITS_PER_WIDE_INT
1950 || BITS_PER_UNIT >= HOST_BITS_PER_WIDE_INT)
1951 read_reg = NULL_RTX;
1952 else
1954 unsigned HOST_WIDE_INT c
1955 = INTVAL (store_info->rhs)
1956 & (((HOST_WIDE_INT) 1 << BITS_PER_UNIT) - 1);
1957 int shift = BITS_PER_UNIT;
1958 while (shift < HOST_BITS_PER_WIDE_INT)
1960 c |= (c << shift);
1961 shift <<= 1;
1963 read_reg = gen_int_mode (c, store_mode);
1964 read_reg = extract_low_bits (read_mode, store_mode, read_reg);
1967 else if (store_info->const_rhs
1968 && (require_cst
1969 || GET_MODE_CLASS (read_mode) != GET_MODE_CLASS (store_mode)))
1970 read_reg = extract_low_bits (read_mode, store_mode,
1971 copy_rtx (store_info->const_rhs));
1972 else
1973 read_reg = extract_low_bits (read_mode, store_mode,
1974 copy_rtx (store_info->rhs));
1975 if (require_cst && read_reg && !CONSTANT_P (read_reg))
1976 read_reg = NULL_RTX;
1977 return read_reg;
1980 /* Take a sequence of:
1981 A <- r1
1983 ... <- A
1985 and change it into
1986 r2 <- r1
1987 A <- r1
1989 ... <- r2
1993 r3 <- extract (r1)
1994 r3 <- r3 >> shift
1995 r2 <- extract (r3)
1996 ... <- r2
2000 r2 <- extract (r1)
2001 ... <- r2
2003 Depending on the alignment and the mode of the store and
2004 subsequent load.
2007 The STORE_INFO and STORE_INSN are for the store and READ_INFO
2008 and READ_INSN are for the read. Return true if the replacement
2009 went ok. */
2011 static bool
2012 replace_read (store_info_t store_info, insn_info_t store_insn,
2013 read_info_t read_info, insn_info_t read_insn, rtx *loc,
2014 bitmap regs_live)
2016 enum machine_mode store_mode = GET_MODE (store_info->mem);
2017 enum machine_mode read_mode = GET_MODE (read_info->mem);
2018 rtx insns, this_insn, read_reg;
2019 basic_block bb;
2021 if (!dbg_cnt (dse))
2022 return false;
2024 /* Create a sequence of instructions to set up the read register.
2025 This sequence goes immediately before the store and its result
2026 is read by the load.
2028 We need to keep this in perspective. We are replacing a read
2029 with a sequence of insns, but the read will almost certainly be
2030 in cache, so it is not going to be an expensive one. Thus, we
2031 are not willing to do a multi insn shift or worse a subroutine
2032 call to get rid of the read. */
2033 if (dump_file)
2034 fprintf (dump_file, "trying to replace %smode load in insn %d"
2035 " from %smode store in insn %d\n",
2036 GET_MODE_NAME (read_mode), INSN_UID (read_insn->insn),
2037 GET_MODE_NAME (store_mode), INSN_UID (store_insn->insn));
2038 start_sequence ();
2039 bb = BLOCK_FOR_INSN (read_insn->insn);
2040 read_reg = get_stored_val (store_info,
2041 read_mode, read_info->begin, read_info->end,
2042 bb, false);
2043 if (read_reg == NULL_RTX)
2045 end_sequence ();
2046 if (dump_file)
2047 fprintf (dump_file, " -- could not extract bits of stored value\n");
2048 return false;
2050 /* Force the value into a new register so that it won't be clobbered
2051 between the store and the load. */
2052 read_reg = copy_to_mode_reg (read_mode, read_reg);
2053 insns = get_insns ();
2054 end_sequence ();
2056 if (insns != NULL_RTX)
2058 /* Now we have to scan the set of new instructions to see if the
2059 sequence contains and sets of hardregs that happened to be
2060 live at this point. For instance, this can happen if one of
2061 the insns sets the CC and the CC happened to be live at that
2062 point. This does occasionally happen, see PR 37922. */
2063 bitmap regs_set = BITMAP_ALLOC (&reg_obstack);
2065 for (this_insn = insns; this_insn != NULL_RTX; this_insn = NEXT_INSN (this_insn))
2066 note_stores (PATTERN (this_insn), look_for_hardregs, regs_set);
2068 bitmap_and_into (regs_set, regs_live);
2069 if (!bitmap_empty_p (regs_set))
2071 if (dump_file)
2073 fprintf (dump_file,
2074 "abandoning replacement because sequence clobbers live hardregs:");
2075 df_print_regset (dump_file, regs_set);
2078 BITMAP_FREE (regs_set);
2079 return false;
2081 BITMAP_FREE (regs_set);
2084 if (validate_change (read_insn->insn, loc, read_reg, 0))
2086 deferred_change_t deferred_change =
2087 (deferred_change_t) pool_alloc (deferred_change_pool);
2089 /* Insert this right before the store insn where it will be safe
2090 from later insns that might change it before the read. */
2091 emit_insn_before (insns, store_insn->insn);
2093 /* And now for the kludge part: cselib croaks if you just
2094 return at this point. There are two reasons for this:
2096 1) Cselib has an idea of how many pseudos there are and
2097 that does not include the new ones we just added.
2099 2) Cselib does not know about the move insn we added
2100 above the store_info, and there is no way to tell it
2101 about it, because it has "moved on".
2103 Problem (1) is fixable with a certain amount of engineering.
2104 Problem (2) is requires starting the bb from scratch. This
2105 could be expensive.
2107 So we are just going to have to lie. The move/extraction
2108 insns are not really an issue, cselib did not see them. But
2109 the use of the new pseudo read_insn is a real problem because
2110 cselib has not scanned this insn. The way that we solve this
2111 problem is that we are just going to put the mem back for now
2112 and when we are finished with the block, we undo this. We
2113 keep a table of mems to get rid of. At the end of the basic
2114 block we can put them back. */
2116 *loc = read_info->mem;
2117 deferred_change->next = deferred_change_list;
2118 deferred_change_list = deferred_change;
2119 deferred_change->loc = loc;
2120 deferred_change->reg = read_reg;
2122 /* Get rid of the read_info, from the point of view of the
2123 rest of dse, play like this read never happened. */
2124 read_insn->read_rec = read_info->next;
2125 pool_free (read_info_pool, read_info);
2126 if (dump_file)
2128 fprintf (dump_file, " -- replaced the loaded MEM with ");
2129 print_simple_rtl (dump_file, read_reg);
2130 fprintf (dump_file, "\n");
2132 return true;
2134 else
2136 if (dump_file)
2138 fprintf (dump_file, " -- replacing the loaded MEM with ");
2139 print_simple_rtl (dump_file, read_reg);
2140 fprintf (dump_file, " led to an invalid instruction\n");
2142 return false;
2146 /* A for_each_rtx callback in which DATA is the bb_info. Check to see
2147 if LOC is a mem and if it is look at the address and kill any
2148 appropriate stores that may be active. */
2150 static int
2151 check_mem_read_rtx (rtx *loc, void *data)
2153 rtx mem = *loc, mem_addr;
2154 bb_info_t bb_info;
2155 insn_info_t insn_info;
2156 HOST_WIDE_INT offset = 0;
2157 HOST_WIDE_INT width = 0;
2158 alias_set_type spill_alias_set = 0;
2159 cselib_val *base = NULL;
2160 int group_id;
2161 read_info_t read_info;
2163 if (!mem || !MEM_P (mem))
2164 return 0;
2166 bb_info = (bb_info_t) data;
2167 insn_info = bb_info->last_insn;
2169 if ((MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
2170 || (MEM_VOLATILE_P (mem)))
2172 if (dump_file)
2173 fprintf (dump_file, " adding wild read, volatile or barrier.\n");
2174 add_wild_read (bb_info);
2175 insn_info->cannot_delete = true;
2176 return 0;
2179 /* If it is reading readonly mem, then there can be no conflict with
2180 another write. */
2181 if (MEM_READONLY_P (mem))
2182 return 0;
2184 if (!canon_address (mem, &spill_alias_set, &group_id, &offset, &base))
2186 if (dump_file)
2187 fprintf (dump_file, " adding wild read, canon_address failure.\n");
2188 add_wild_read (bb_info);
2189 return 0;
2192 if (GET_MODE (mem) == BLKmode)
2193 width = -1;
2194 else
2195 width = GET_MODE_SIZE (GET_MODE (mem));
2197 read_info = (read_info_t) pool_alloc (read_info_pool);
2198 read_info->group_id = group_id;
2199 read_info->mem = mem;
2200 read_info->alias_set = spill_alias_set;
2201 read_info->begin = offset;
2202 read_info->end = offset + width;
2203 read_info->next = insn_info->read_rec;
2204 insn_info->read_rec = read_info;
2205 /* For alias_set != 0 canon_true_dependence should be never called. */
2206 if (spill_alias_set)
2207 mem_addr = NULL_RTX;
2208 else
2210 if (group_id < 0)
2211 mem_addr = base->val_rtx;
2212 else
2214 group_info_t group
2215 = rtx_group_vec[group_id];
2216 mem_addr = group->canon_base_addr;
2218 if (offset)
2219 mem_addr = plus_constant (get_address_mode (mem), mem_addr, offset);
2222 /* We ignore the clobbers in store_info. The is mildly aggressive,
2223 but there really should not be a clobber followed by a read. */
2225 if (spill_alias_set)
2227 insn_info_t i_ptr = active_local_stores;
2228 insn_info_t last = NULL;
2230 if (dump_file)
2231 fprintf (dump_file, " processing spill load %d\n",
2232 (int) spill_alias_set);
2234 while (i_ptr)
2236 store_info_t store_info = i_ptr->store_rec;
2238 /* Skip the clobbers. */
2239 while (!store_info->is_set)
2240 store_info = store_info->next;
2242 if (store_info->alias_set == spill_alias_set)
2244 if (dump_file)
2245 dump_insn_info ("removing from active", i_ptr);
2247 active_local_stores_len--;
2248 if (last)
2249 last->next_local_store = i_ptr->next_local_store;
2250 else
2251 active_local_stores = i_ptr->next_local_store;
2253 else
2254 last = i_ptr;
2255 i_ptr = i_ptr->next_local_store;
2258 else if (group_id >= 0)
2260 /* This is the restricted case where the base is a constant or
2261 the frame pointer and offset is a constant. */
2262 insn_info_t i_ptr = active_local_stores;
2263 insn_info_t last = NULL;
2265 if (dump_file)
2267 if (width == -1)
2268 fprintf (dump_file, " processing const load gid=%d[BLK]\n",
2269 group_id);
2270 else
2271 fprintf (dump_file, " processing const load gid=%d[%d..%d)\n",
2272 group_id, (int)offset, (int)(offset+width));
2275 while (i_ptr)
2277 bool remove = false;
2278 store_info_t store_info = i_ptr->store_rec;
2280 /* Skip the clobbers. */
2281 while (!store_info->is_set)
2282 store_info = store_info->next;
2284 /* There are three cases here. */
2285 if (store_info->group_id < 0)
2286 /* We have a cselib store followed by a read from a
2287 const base. */
2288 remove
2289 = canon_true_dependence (store_info->mem,
2290 GET_MODE (store_info->mem),
2291 store_info->mem_addr,
2292 mem, mem_addr);
2294 else if (group_id == store_info->group_id)
2296 /* This is a block mode load. We may get lucky and
2297 canon_true_dependence may save the day. */
2298 if (width == -1)
2299 remove
2300 = canon_true_dependence (store_info->mem,
2301 GET_MODE (store_info->mem),
2302 store_info->mem_addr,
2303 mem, mem_addr);
2305 /* If this read is just reading back something that we just
2306 stored, rewrite the read. */
2307 else
2309 if (store_info->rhs
2310 && offset >= store_info->begin
2311 && offset + width <= store_info->end
2312 && all_positions_needed_p (store_info,
2313 offset - store_info->begin,
2314 width)
2315 && replace_read (store_info, i_ptr, read_info,
2316 insn_info, loc, bb_info->regs_live))
2317 return 0;
2319 /* The bases are the same, just see if the offsets
2320 overlap. */
2321 if ((offset < store_info->end)
2322 && (offset + width > store_info->begin))
2323 remove = true;
2327 /* else
2328 The else case that is missing here is that the
2329 bases are constant but different. There is nothing
2330 to do here because there is no overlap. */
2332 if (remove)
2334 if (dump_file)
2335 dump_insn_info ("removing from active", i_ptr);
2337 active_local_stores_len--;
2338 if (last)
2339 last->next_local_store = i_ptr->next_local_store;
2340 else
2341 active_local_stores = i_ptr->next_local_store;
2343 else
2344 last = i_ptr;
2345 i_ptr = i_ptr->next_local_store;
2348 else
2350 insn_info_t i_ptr = active_local_stores;
2351 insn_info_t last = NULL;
2352 if (dump_file)
2354 fprintf (dump_file, " processing cselib load mem:");
2355 print_inline_rtx (dump_file, mem, 0);
2356 fprintf (dump_file, "\n");
2359 while (i_ptr)
2361 bool remove = false;
2362 store_info_t store_info = i_ptr->store_rec;
2364 if (dump_file)
2365 fprintf (dump_file, " processing cselib load against insn %d\n",
2366 INSN_UID (i_ptr->insn));
2368 /* Skip the clobbers. */
2369 while (!store_info->is_set)
2370 store_info = store_info->next;
2372 /* If this read is just reading back something that we just
2373 stored, rewrite the read. */
2374 if (store_info->rhs
2375 && store_info->group_id == -1
2376 && store_info->cse_base == base
2377 && width != -1
2378 && offset >= store_info->begin
2379 && offset + width <= store_info->end
2380 && all_positions_needed_p (store_info,
2381 offset - store_info->begin, width)
2382 && replace_read (store_info, i_ptr, read_info, insn_info, loc,
2383 bb_info->regs_live))
2384 return 0;
2386 if (!store_info->alias_set)
2387 remove = canon_true_dependence (store_info->mem,
2388 GET_MODE (store_info->mem),
2389 store_info->mem_addr,
2390 mem, mem_addr);
2392 if (remove)
2394 if (dump_file)
2395 dump_insn_info ("removing from active", i_ptr);
2397 active_local_stores_len--;
2398 if (last)
2399 last->next_local_store = i_ptr->next_local_store;
2400 else
2401 active_local_stores = i_ptr->next_local_store;
2403 else
2404 last = i_ptr;
2405 i_ptr = i_ptr->next_local_store;
2408 return 0;
2411 /* A for_each_rtx callback in which DATA points the INSN_INFO for
2412 as check_mem_read_rtx. Nullify the pointer if i_m_r_m_r returns
2413 true for any part of *LOC. */
2415 static void
2416 check_mem_read_use (rtx *loc, void *data)
2418 for_each_rtx (loc, check_mem_read_rtx, data);
2422 /* Get arguments passed to CALL_INSN. Return TRUE if successful.
2423 So far it only handles arguments passed in registers. */
2425 static bool
2426 get_call_args (rtx call_insn, tree fn, rtx *args, int nargs)
2428 CUMULATIVE_ARGS args_so_far_v;
2429 cumulative_args_t args_so_far;
2430 tree arg;
2431 int idx;
2433 INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
2434 args_so_far = pack_cumulative_args (&args_so_far_v);
2436 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
2437 for (idx = 0;
2438 arg != void_list_node && idx < nargs;
2439 arg = TREE_CHAIN (arg), idx++)
2441 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
2442 rtx reg, link, tmp;
2443 reg = targetm.calls.function_arg (args_so_far, mode, NULL_TREE, true);
2444 if (!reg || !REG_P (reg) || GET_MODE (reg) != mode
2445 || GET_MODE_CLASS (mode) != MODE_INT)
2446 return false;
2448 for (link = CALL_INSN_FUNCTION_USAGE (call_insn);
2449 link;
2450 link = XEXP (link, 1))
2451 if (GET_CODE (XEXP (link, 0)) == USE)
2453 args[idx] = XEXP (XEXP (link, 0), 0);
2454 if (REG_P (args[idx])
2455 && REGNO (args[idx]) == REGNO (reg)
2456 && (GET_MODE (args[idx]) == mode
2457 || (GET_MODE_CLASS (GET_MODE (args[idx])) == MODE_INT
2458 && (GET_MODE_SIZE (GET_MODE (args[idx]))
2459 <= UNITS_PER_WORD)
2460 && (GET_MODE_SIZE (GET_MODE (args[idx]))
2461 > GET_MODE_SIZE (mode)))))
2462 break;
2464 if (!link)
2465 return false;
2467 tmp = cselib_expand_value_rtx (args[idx], scratch, 5);
2468 if (GET_MODE (args[idx]) != mode)
2470 if (!tmp || !CONST_INT_P (tmp))
2471 return false;
2472 tmp = gen_int_mode (INTVAL (tmp), mode);
2474 if (tmp)
2475 args[idx] = tmp;
2477 targetm.calls.function_arg_advance (args_so_far, mode, NULL_TREE, true);
2479 if (arg != void_list_node || idx != nargs)
2480 return false;
2481 return true;
2484 /* Return a bitmap of the fixed registers contained in IN. */
2486 static bitmap
2487 copy_fixed_regs (const_bitmap in)
2489 bitmap ret;
2491 ret = ALLOC_REG_SET (NULL);
2492 bitmap_and (ret, in, fixed_reg_set_regset);
2493 return ret;
2496 /* Apply record_store to all candidate stores in INSN. Mark INSN
2497 if some part of it is not a candidate store and assigns to a
2498 non-register target. */
2500 static void
2501 scan_insn (bb_info_t bb_info, rtx insn)
2503 rtx body;
2504 insn_info_t insn_info = (insn_info_t) pool_alloc (insn_info_pool);
2505 int mems_found = 0;
2506 memset (insn_info, 0, sizeof (struct insn_info));
2508 if (dump_file)
2509 fprintf (dump_file, "\n**scanning insn=%d\n",
2510 INSN_UID (insn));
2512 insn_info->prev_insn = bb_info->last_insn;
2513 insn_info->insn = insn;
2514 bb_info->last_insn = insn_info;
2516 if (DEBUG_INSN_P (insn))
2518 insn_info->cannot_delete = true;
2519 return;
2522 /* Cselib clears the table for this case, so we have to essentially
2523 do the same. */
2524 if (NONJUMP_INSN_P (insn)
2525 && volatile_insn_p (PATTERN (insn)))
2527 add_wild_read (bb_info);
2528 insn_info->cannot_delete = true;
2529 return;
2532 /* Look at all of the uses in the insn. */
2533 note_uses (&PATTERN (insn), check_mem_read_use, bb_info);
2535 if (CALL_P (insn))
2537 bool const_call;
2538 tree memset_call = NULL_TREE;
2540 insn_info->cannot_delete = true;
2542 /* Const functions cannot do anything bad i.e. read memory,
2543 however, they can read their parameters which may have
2544 been pushed onto the stack.
2545 memset and bzero don't read memory either. */
2546 const_call = RTL_CONST_CALL_P (insn);
2547 if (!const_call)
2549 rtx call = get_call_rtx_from (insn);
2550 if (call && GET_CODE (XEXP (XEXP (call, 0), 0)) == SYMBOL_REF)
2552 rtx symbol = XEXP (XEXP (call, 0), 0);
2553 if (SYMBOL_REF_DECL (symbol)
2554 && TREE_CODE (SYMBOL_REF_DECL (symbol)) == FUNCTION_DECL)
2556 if ((DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol))
2557 == BUILT_IN_NORMAL
2558 && (DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol))
2559 == BUILT_IN_MEMSET))
2560 || SYMBOL_REF_DECL (symbol) == block_clear_fn)
2561 memset_call = SYMBOL_REF_DECL (symbol);
2565 if (const_call || memset_call)
2567 insn_info_t i_ptr = active_local_stores;
2568 insn_info_t last = NULL;
2570 if (dump_file)
2571 fprintf (dump_file, "%s call %d\n",
2572 const_call ? "const" : "memset", INSN_UID (insn));
2574 /* See the head comment of the frame_read field. */
2575 if (reload_completed)
2576 insn_info->frame_read = true;
2578 /* Loop over the active stores and remove those which are
2579 killed by the const function call. */
2580 while (i_ptr)
2582 bool remove_store = false;
2584 /* The stack pointer based stores are always killed. */
2585 if (i_ptr->stack_pointer_based)
2586 remove_store = true;
2588 /* If the frame is read, the frame related stores are killed. */
2589 else if (insn_info->frame_read)
2591 store_info_t store_info = i_ptr->store_rec;
2593 /* Skip the clobbers. */
2594 while (!store_info->is_set)
2595 store_info = store_info->next;
2597 if (store_info->group_id >= 0
2598 && rtx_group_vec[store_info->group_id]->frame_related)
2599 remove_store = true;
2602 if (remove_store)
2604 if (dump_file)
2605 dump_insn_info ("removing from active", i_ptr);
2607 active_local_stores_len--;
2608 if (last)
2609 last->next_local_store = i_ptr->next_local_store;
2610 else
2611 active_local_stores = i_ptr->next_local_store;
2613 else
2614 last = i_ptr;
2616 i_ptr = i_ptr->next_local_store;
2619 if (memset_call)
2621 rtx args[3];
2622 if (get_call_args (insn, memset_call, args, 3)
2623 && CONST_INT_P (args[1])
2624 && CONST_INT_P (args[2])
2625 && INTVAL (args[2]) > 0)
2627 rtx mem = gen_rtx_MEM (BLKmode, args[0]);
2628 set_mem_size (mem, INTVAL (args[2]));
2629 body = gen_rtx_SET (VOIDmode, mem, args[1]);
2630 mems_found += record_store (body, bb_info);
2631 if (dump_file)
2632 fprintf (dump_file, "handling memset as BLKmode store\n");
2633 if (mems_found == 1)
2635 if (active_local_stores_len++
2636 >= PARAM_VALUE (PARAM_MAX_DSE_ACTIVE_LOCAL_STORES))
2638 active_local_stores_len = 1;
2639 active_local_stores = NULL;
2641 insn_info->fixed_regs_live
2642 = copy_fixed_regs (bb_info->regs_live);
2643 insn_info->next_local_store = active_local_stores;
2644 active_local_stores = insn_info;
2650 else
2651 /* Every other call, including pure functions, may read any memory
2652 that is not relative to the frame. */
2653 add_non_frame_wild_read (bb_info);
2655 return;
2658 /* Assuming that there are sets in these insns, we cannot delete
2659 them. */
2660 if ((GET_CODE (PATTERN (insn)) == CLOBBER)
2661 || volatile_refs_p (PATTERN (insn))
2662 || (!cfun->can_delete_dead_exceptions && !insn_nothrow_p (insn))
2663 || (RTX_FRAME_RELATED_P (insn))
2664 || find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX))
2665 insn_info->cannot_delete = true;
2667 body = PATTERN (insn);
2668 if (GET_CODE (body) == PARALLEL)
2670 int i;
2671 for (i = 0; i < XVECLEN (body, 0); i++)
2672 mems_found += record_store (XVECEXP (body, 0, i), bb_info);
2674 else
2675 mems_found += record_store (body, bb_info);
2677 if (dump_file)
2678 fprintf (dump_file, "mems_found = %d, cannot_delete = %s\n",
2679 mems_found, insn_info->cannot_delete ? "true" : "false");
2681 /* If we found some sets of mems, add it into the active_local_stores so
2682 that it can be locally deleted if found dead or used for
2683 replace_read and redundant constant store elimination. Otherwise mark
2684 it as cannot delete. This simplifies the processing later. */
2685 if (mems_found == 1)
2687 if (active_local_stores_len++
2688 >= PARAM_VALUE (PARAM_MAX_DSE_ACTIVE_LOCAL_STORES))
2690 active_local_stores_len = 1;
2691 active_local_stores = NULL;
2693 insn_info->fixed_regs_live = copy_fixed_regs (bb_info->regs_live);
2694 insn_info->next_local_store = active_local_stores;
2695 active_local_stores = insn_info;
2697 else
2698 insn_info->cannot_delete = true;
2702 /* Remove BASE from the set of active_local_stores. This is a
2703 callback from cselib that is used to get rid of the stores in
2704 active_local_stores. */
2706 static void
2707 remove_useless_values (cselib_val *base)
2709 insn_info_t insn_info = active_local_stores;
2710 insn_info_t last = NULL;
2712 while (insn_info)
2714 store_info_t store_info = insn_info->store_rec;
2715 bool del = false;
2717 /* If ANY of the store_infos match the cselib group that is
2718 being deleted, then the insn can not be deleted. */
2719 while (store_info)
2721 if ((store_info->group_id == -1)
2722 && (store_info->cse_base == base))
2724 del = true;
2725 break;
2727 store_info = store_info->next;
2730 if (del)
2732 active_local_stores_len--;
2733 if (last)
2734 last->next_local_store = insn_info->next_local_store;
2735 else
2736 active_local_stores = insn_info->next_local_store;
2737 free_store_info (insn_info);
2739 else
2740 last = insn_info;
2742 insn_info = insn_info->next_local_store;
2747 /* Do all of step 1. */
2749 static void
2750 dse_step1 (void)
2752 basic_block bb;
2753 bitmap regs_live = BITMAP_ALLOC (&reg_obstack);
2755 cselib_init (0);
2756 all_blocks = BITMAP_ALLOC (NULL);
2757 bitmap_set_bit (all_blocks, ENTRY_BLOCK);
2758 bitmap_set_bit (all_blocks, EXIT_BLOCK);
2760 FOR_ALL_BB (bb)
2762 insn_info_t ptr;
2763 bb_info_t bb_info = (bb_info_t) pool_alloc (bb_info_pool);
2765 memset (bb_info, 0, sizeof (struct bb_info));
2766 bitmap_set_bit (all_blocks, bb->index);
2767 bb_info->regs_live = regs_live;
2769 bitmap_copy (regs_live, DF_LR_IN (bb));
2770 df_simulate_initialize_forwards (bb, regs_live);
2772 bb_table[bb->index] = bb_info;
2773 cselib_discard_hook = remove_useless_values;
2775 if (bb->index >= NUM_FIXED_BLOCKS)
2777 rtx insn;
2779 cse_store_info_pool
2780 = create_alloc_pool ("cse_store_info_pool",
2781 sizeof (struct store_info), 100);
2782 active_local_stores = NULL;
2783 active_local_stores_len = 0;
2784 cselib_clear_table ();
2786 /* Scan the insns. */
2787 FOR_BB_INSNS (bb, insn)
2789 if (INSN_P (insn))
2790 scan_insn (bb_info, insn);
2791 cselib_process_insn (insn);
2792 if (INSN_P (insn))
2793 df_simulate_one_insn_forwards (bb, insn, regs_live);
2796 /* This is something of a hack, because the global algorithm
2797 is supposed to take care of the case where stores go dead
2798 at the end of the function. However, the global
2799 algorithm must take a more conservative view of block
2800 mode reads than the local alg does. So to get the case
2801 where you have a store to the frame followed by a non
2802 overlapping block more read, we look at the active local
2803 stores at the end of the function and delete all of the
2804 frame and spill based ones. */
2805 if (stores_off_frame_dead_at_return
2806 && (EDGE_COUNT (bb->succs) == 0
2807 || (single_succ_p (bb)
2808 && single_succ (bb) == EXIT_BLOCK_PTR
2809 && ! crtl->calls_eh_return)))
2811 insn_info_t i_ptr = active_local_stores;
2812 while (i_ptr)
2814 store_info_t store_info = i_ptr->store_rec;
2816 /* Skip the clobbers. */
2817 while (!store_info->is_set)
2818 store_info = store_info->next;
2819 if (store_info->alias_set && !i_ptr->cannot_delete)
2820 delete_dead_store_insn (i_ptr);
2821 else
2822 if (store_info->group_id >= 0)
2824 group_info_t group
2825 = rtx_group_vec[store_info->group_id];
2826 if (group->frame_related && !i_ptr->cannot_delete)
2827 delete_dead_store_insn (i_ptr);
2830 i_ptr = i_ptr->next_local_store;
2834 /* Get rid of the loads that were discovered in
2835 replace_read. Cselib is finished with this block. */
2836 while (deferred_change_list)
2838 deferred_change_t next = deferred_change_list->next;
2840 /* There is no reason to validate this change. That was
2841 done earlier. */
2842 *deferred_change_list->loc = deferred_change_list->reg;
2843 pool_free (deferred_change_pool, deferred_change_list);
2844 deferred_change_list = next;
2847 /* Get rid of all of the cselib based store_infos in this
2848 block and mark the containing insns as not being
2849 deletable. */
2850 ptr = bb_info->last_insn;
2851 while (ptr)
2853 if (ptr->contains_cselib_groups)
2855 store_info_t s_info = ptr->store_rec;
2856 while (s_info && !s_info->is_set)
2857 s_info = s_info->next;
2858 if (s_info
2859 && s_info->redundant_reason
2860 && s_info->redundant_reason->insn
2861 && !ptr->cannot_delete)
2863 if (dump_file)
2864 fprintf (dump_file, "Locally deleting insn %d "
2865 "because insn %d stores the "
2866 "same value and couldn't be "
2867 "eliminated\n",
2868 INSN_UID (ptr->insn),
2869 INSN_UID (s_info->redundant_reason->insn));
2870 delete_dead_store_insn (ptr);
2872 free_store_info (ptr);
2874 else
2876 store_info_t s_info;
2878 /* Free at least positions_needed bitmaps. */
2879 for (s_info = ptr->store_rec; s_info; s_info = s_info->next)
2880 if (s_info->is_large)
2882 BITMAP_FREE (s_info->positions_needed.large.bmap);
2883 s_info->is_large = false;
2886 ptr = ptr->prev_insn;
2889 free_alloc_pool (cse_store_info_pool);
2891 bb_info->regs_live = NULL;
2894 BITMAP_FREE (regs_live);
2895 cselib_finish ();
2896 rtx_group_table.empty ();
2900 /*----------------------------------------------------------------------------
2901 Second step.
2903 Assign each byte position in the stores that we are going to
2904 analyze globally to a position in the bitmaps. Returns true if
2905 there are any bit positions assigned.
2906 ----------------------------------------------------------------------------*/
2908 static void
2909 dse_step2_init (void)
2911 unsigned int i;
2912 group_info_t group;
2914 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
2916 /* For all non stack related bases, we only consider a store to
2917 be deletable if there are two or more stores for that
2918 position. This is because it takes one store to make the
2919 other store redundant. However, for the stores that are
2920 stack related, we consider them if there is only one store
2921 for the position. We do this because the stack related
2922 stores can be deleted if their is no read between them and
2923 the end of the function.
2925 To make this work in the current framework, we take the stack
2926 related bases add all of the bits from store1 into store2.
2927 This has the effect of making the eligible even if there is
2928 only one store. */
2930 if (stores_off_frame_dead_at_return && group->frame_related)
2932 bitmap_ior_into (group->store2_n, group->store1_n);
2933 bitmap_ior_into (group->store2_p, group->store1_p);
2934 if (dump_file)
2935 fprintf (dump_file, "group %d is frame related ", i);
2938 group->offset_map_size_n++;
2939 group->offset_map_n = XOBNEWVEC (&dse_obstack, int,
2940 group->offset_map_size_n);
2941 group->offset_map_size_p++;
2942 group->offset_map_p = XOBNEWVEC (&dse_obstack, int,
2943 group->offset_map_size_p);
2944 group->process_globally = false;
2945 if (dump_file)
2947 fprintf (dump_file, "group %d(%d+%d): ", i,
2948 (int)bitmap_count_bits (group->store2_n),
2949 (int)bitmap_count_bits (group->store2_p));
2950 bitmap_print (dump_file, group->store2_n, "n ", " ");
2951 bitmap_print (dump_file, group->store2_p, "p ", "\n");
2957 /* Init the offset tables for the normal case. */
2959 static bool
2960 dse_step2_nospill (void)
2962 unsigned int i;
2963 group_info_t group;
2964 /* Position 0 is unused because 0 is used in the maps to mean
2965 unused. */
2966 current_position = 1;
2967 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
2969 bitmap_iterator bi;
2970 unsigned int j;
2972 if (group == clear_alias_group)
2973 continue;
2975 memset (group->offset_map_n, 0, sizeof(int) * group->offset_map_size_n);
2976 memset (group->offset_map_p, 0, sizeof(int) * group->offset_map_size_p);
2977 bitmap_clear (group->group_kill);
2979 EXECUTE_IF_SET_IN_BITMAP (group->store2_n, 0, j, bi)
2981 bitmap_set_bit (group->group_kill, current_position);
2982 if (bitmap_bit_p (group->escaped_n, j))
2983 bitmap_set_bit (kill_on_calls, current_position);
2984 group->offset_map_n[j] = current_position++;
2985 group->process_globally = true;
2987 EXECUTE_IF_SET_IN_BITMAP (group->store2_p, 0, j, bi)
2989 bitmap_set_bit (group->group_kill, current_position);
2990 if (bitmap_bit_p (group->escaped_p, j))
2991 bitmap_set_bit (kill_on_calls, current_position);
2992 group->offset_map_p[j] = current_position++;
2993 group->process_globally = true;
2996 return current_position != 1;
3000 /* Init the offset tables for the spill case. */
3002 static bool
3003 dse_step2_spill (void)
3005 unsigned int j;
3006 group_info_t group = clear_alias_group;
3007 bitmap_iterator bi;
3009 /* Position 0 is unused because 0 is used in the maps to mean
3010 unused. */
3011 current_position = 1;
3013 if (dump_file)
3015 bitmap_print (dump_file, clear_alias_sets,
3016 "clear alias sets ", "\n");
3017 bitmap_print (dump_file, disqualified_clear_alias_sets,
3018 "disqualified clear alias sets ", "\n");
3021 memset (group->offset_map_n, 0, sizeof(int) * group->offset_map_size_n);
3022 memset (group->offset_map_p, 0, sizeof(int) * group->offset_map_size_p);
3023 bitmap_clear (group->group_kill);
3025 /* Remove the disqualified positions from the store2_p set. */
3026 bitmap_and_compl_into (group->store2_p, disqualified_clear_alias_sets);
3028 /* We do not need to process the store2_n set because
3029 alias_sets are always positive. */
3030 EXECUTE_IF_SET_IN_BITMAP (group->store2_p, 0, j, bi)
3032 bitmap_set_bit (group->group_kill, current_position);
3033 group->offset_map_p[j] = current_position++;
3034 group->process_globally = true;
3037 return current_position != 1;
3042 /*----------------------------------------------------------------------------
3043 Third step.
3045 Build the bit vectors for the transfer functions.
3046 ----------------------------------------------------------------------------*/
3049 /* Look up the bitmap index for OFFSET in GROUP_INFO. If it is not
3050 there, return 0. */
3052 static int
3053 get_bitmap_index (group_info_t group_info, HOST_WIDE_INT offset)
3055 if (offset < 0)
3057 HOST_WIDE_INT offset_p = -offset;
3058 if (offset_p >= group_info->offset_map_size_n)
3059 return 0;
3060 return group_info->offset_map_n[offset_p];
3062 else
3064 if (offset >= group_info->offset_map_size_p)
3065 return 0;
3066 return group_info->offset_map_p[offset];
3071 /* Process the STORE_INFOs into the bitmaps into GEN and KILL. KILL
3072 may be NULL. */
3074 static void
3075 scan_stores_nospill (store_info_t store_info, bitmap gen, bitmap kill)
3077 while (store_info)
3079 HOST_WIDE_INT i;
3080 group_info_t group_info
3081 = rtx_group_vec[store_info->group_id];
3082 if (group_info->process_globally)
3083 for (i = store_info->begin; i < store_info->end; i++)
3085 int index = get_bitmap_index (group_info, i);
3086 if (index != 0)
3088 bitmap_set_bit (gen, index);
3089 if (kill)
3090 bitmap_clear_bit (kill, index);
3093 store_info = store_info->next;
3098 /* Process the STORE_INFOs into the bitmaps into GEN and KILL. KILL
3099 may be NULL. */
3101 static void
3102 scan_stores_spill (store_info_t store_info, bitmap gen, bitmap kill)
3104 while (store_info)
3106 if (store_info->alias_set)
3108 int index = get_bitmap_index (clear_alias_group,
3109 store_info->alias_set);
3110 if (index != 0)
3112 bitmap_set_bit (gen, index);
3113 if (kill)
3114 bitmap_clear_bit (kill, index);
3117 store_info = store_info->next;
3122 /* Process the READ_INFOs into the bitmaps into GEN and KILL. KILL
3123 may be NULL. */
3125 static void
3126 scan_reads_nospill (insn_info_t insn_info, bitmap gen, bitmap kill)
3128 read_info_t read_info = insn_info->read_rec;
3129 int i;
3130 group_info_t group;
3132 /* If this insn reads the frame, kill all the frame related stores. */
3133 if (insn_info->frame_read)
3135 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
3136 if (group->process_globally && group->frame_related)
3138 if (kill)
3139 bitmap_ior_into (kill, group->group_kill);
3140 bitmap_and_compl_into (gen, group->group_kill);
3143 if (insn_info->non_frame_wild_read)
3145 /* Kill all non-frame related stores. Kill all stores of variables that
3146 escape. */
3147 if (kill)
3148 bitmap_ior_into (kill, kill_on_calls);
3149 bitmap_and_compl_into (gen, kill_on_calls);
3150 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
3151 if (group->process_globally && !group->frame_related)
3153 if (kill)
3154 bitmap_ior_into (kill, group->group_kill);
3155 bitmap_and_compl_into (gen, group->group_kill);
3158 while (read_info)
3160 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
3162 if (group->process_globally)
3164 if (i == read_info->group_id)
3166 if (read_info->begin > read_info->end)
3168 /* Begin > end for block mode reads. */
3169 if (kill)
3170 bitmap_ior_into (kill, group->group_kill);
3171 bitmap_and_compl_into (gen, group->group_kill);
3173 else
3175 /* The groups are the same, just process the
3176 offsets. */
3177 HOST_WIDE_INT j;
3178 for (j = read_info->begin; j < read_info->end; j++)
3180 int index = get_bitmap_index (group, j);
3181 if (index != 0)
3183 if (kill)
3184 bitmap_set_bit (kill, index);
3185 bitmap_clear_bit (gen, index);
3190 else
3192 /* The groups are different, if the alias sets
3193 conflict, clear the entire group. We only need
3194 to apply this test if the read_info is a cselib
3195 read. Anything with a constant base cannot alias
3196 something else with a different constant
3197 base. */
3198 if ((read_info->group_id < 0)
3199 && canon_true_dependence (group->base_mem,
3200 GET_MODE (group->base_mem),
3201 group->canon_base_addr,
3202 read_info->mem, NULL_RTX))
3204 if (kill)
3205 bitmap_ior_into (kill, group->group_kill);
3206 bitmap_and_compl_into (gen, group->group_kill);
3212 read_info = read_info->next;
3216 /* Process the READ_INFOs into the bitmaps into GEN and KILL. KILL
3217 may be NULL. */
3219 static void
3220 scan_reads_spill (read_info_t read_info, bitmap gen, bitmap kill)
3222 while (read_info)
3224 if (read_info->alias_set)
3226 int index = get_bitmap_index (clear_alias_group,
3227 read_info->alias_set);
3228 if (index != 0)
3230 if (kill)
3231 bitmap_set_bit (kill, index);
3232 bitmap_clear_bit (gen, index);
3236 read_info = read_info->next;
3241 /* Return the insn in BB_INFO before the first wild read or if there
3242 are no wild reads in the block, return the last insn. */
3244 static insn_info_t
3245 find_insn_before_first_wild_read (bb_info_t bb_info)
3247 insn_info_t insn_info = bb_info->last_insn;
3248 insn_info_t last_wild_read = NULL;
3250 while (insn_info)
3252 if (insn_info->wild_read)
3254 last_wild_read = insn_info->prev_insn;
3255 /* Block starts with wild read. */
3256 if (!last_wild_read)
3257 return NULL;
3260 insn_info = insn_info->prev_insn;
3263 if (last_wild_read)
3264 return last_wild_read;
3265 else
3266 return bb_info->last_insn;
3270 /* Scan the insns in BB_INFO starting at PTR and going to the top of
3271 the block in order to build the gen and kill sets for the block.
3272 We start at ptr which may be the last insn in the block or may be
3273 the first insn with a wild read. In the latter case we are able to
3274 skip the rest of the block because it just does not matter:
3275 anything that happens is hidden by the wild read. */
3277 static void
3278 dse_step3_scan (bool for_spills, basic_block bb)
3280 bb_info_t bb_info = bb_table[bb->index];
3281 insn_info_t insn_info;
3283 if (for_spills)
3284 /* There are no wild reads in the spill case. */
3285 insn_info = bb_info->last_insn;
3286 else
3287 insn_info = find_insn_before_first_wild_read (bb_info);
3289 /* In the spill case or in the no_spill case if there is no wild
3290 read in the block, we will need a kill set. */
3291 if (insn_info == bb_info->last_insn)
3293 if (bb_info->kill)
3294 bitmap_clear (bb_info->kill);
3295 else
3296 bb_info->kill = BITMAP_ALLOC (&dse_bitmap_obstack);
3298 else
3299 if (bb_info->kill)
3300 BITMAP_FREE (bb_info->kill);
3302 while (insn_info)
3304 /* There may have been code deleted by the dce pass run before
3305 this phase. */
3306 if (insn_info->insn && INSN_P (insn_info->insn))
3308 /* Process the read(s) last. */
3309 if (for_spills)
3311 scan_stores_spill (insn_info->store_rec, bb_info->gen, bb_info->kill);
3312 scan_reads_spill (insn_info->read_rec, bb_info->gen, bb_info->kill);
3314 else
3316 scan_stores_nospill (insn_info->store_rec, bb_info->gen, bb_info->kill);
3317 scan_reads_nospill (insn_info, bb_info->gen, bb_info->kill);
3321 insn_info = insn_info->prev_insn;
3326 /* Set the gen set of the exit block, and also any block with no
3327 successors that does not have a wild read. */
3329 static void
3330 dse_step3_exit_block_scan (bb_info_t bb_info)
3332 /* The gen set is all 0's for the exit block except for the
3333 frame_pointer_group. */
3335 if (stores_off_frame_dead_at_return)
3337 unsigned int i;
3338 group_info_t group;
3340 FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
3342 if (group->process_globally && group->frame_related)
3343 bitmap_ior_into (bb_info->gen, group->group_kill);
3349 /* Find all of the blocks that are not backwards reachable from the
3350 exit block or any block with no successors (BB). These are the
3351 infinite loops or infinite self loops. These blocks will still
3352 have their bits set in UNREACHABLE_BLOCKS. */
3354 static void
3355 mark_reachable_blocks (sbitmap unreachable_blocks, basic_block bb)
3357 edge e;
3358 edge_iterator ei;
3360 if (bitmap_bit_p (unreachable_blocks, bb->index))
3362 bitmap_clear_bit (unreachable_blocks, bb->index);
3363 FOR_EACH_EDGE (e, ei, bb->preds)
3365 mark_reachable_blocks (unreachable_blocks, e->src);
3370 /* Build the transfer functions for the function. */
3372 static void
3373 dse_step3 (bool for_spills)
3375 basic_block bb;
3376 sbitmap unreachable_blocks = sbitmap_alloc (last_basic_block);
3377 sbitmap_iterator sbi;
3378 bitmap all_ones = NULL;
3379 unsigned int i;
3381 bitmap_ones (unreachable_blocks);
3383 FOR_ALL_BB (bb)
3385 bb_info_t bb_info = bb_table[bb->index];
3386 if (bb_info->gen)
3387 bitmap_clear (bb_info->gen);
3388 else
3389 bb_info->gen = BITMAP_ALLOC (&dse_bitmap_obstack);
3391 if (bb->index == ENTRY_BLOCK)
3393 else if (bb->index == EXIT_BLOCK)
3394 dse_step3_exit_block_scan (bb_info);
3395 else
3396 dse_step3_scan (for_spills, bb);
3397 if (EDGE_COUNT (bb->succs) == 0)
3398 mark_reachable_blocks (unreachable_blocks, bb);
3400 /* If this is the second time dataflow is run, delete the old
3401 sets. */
3402 if (bb_info->in)
3403 BITMAP_FREE (bb_info->in);
3404 if (bb_info->out)
3405 BITMAP_FREE (bb_info->out);
3408 /* For any block in an infinite loop, we must initialize the out set
3409 to all ones. This could be expensive, but almost never occurs in
3410 practice. However, it is common in regression tests. */
3411 EXECUTE_IF_SET_IN_BITMAP (unreachable_blocks, 0, i, sbi)
3413 if (bitmap_bit_p (all_blocks, i))
3415 bb_info_t bb_info = bb_table[i];
3416 if (!all_ones)
3418 unsigned int j;
3419 group_info_t group;
3421 all_ones = BITMAP_ALLOC (&dse_bitmap_obstack);
3422 FOR_EACH_VEC_ELT (rtx_group_vec, j, group)
3423 bitmap_ior_into (all_ones, group->group_kill);
3425 if (!bb_info->out)
3427 bb_info->out = BITMAP_ALLOC (&dse_bitmap_obstack);
3428 bitmap_copy (bb_info->out, all_ones);
3433 if (all_ones)
3434 BITMAP_FREE (all_ones);
3435 sbitmap_free (unreachable_blocks);
3440 /*----------------------------------------------------------------------------
3441 Fourth step.
3443 Solve the bitvector equations.
3444 ----------------------------------------------------------------------------*/
3447 /* Confluence function for blocks with no successors. Create an out
3448 set from the gen set of the exit block. This block logically has
3449 the exit block as a successor. */
3453 static void
3454 dse_confluence_0 (basic_block bb)
3456 bb_info_t bb_info = bb_table[bb->index];
3458 if (bb->index == EXIT_BLOCK)
3459 return;
3461 if (!bb_info->out)
3463 bb_info->out = BITMAP_ALLOC (&dse_bitmap_obstack);
3464 bitmap_copy (bb_info->out, bb_table[EXIT_BLOCK]->gen);
3468 /* Propagate the information from the in set of the dest of E to the
3469 out set of the src of E. If the various in or out sets are not
3470 there, that means they are all ones. */
3472 static bool
3473 dse_confluence_n (edge e)
3475 bb_info_t src_info = bb_table[e->src->index];
3476 bb_info_t dest_info = bb_table[e->dest->index];
3478 if (dest_info->in)
3480 if (src_info->out)
3481 bitmap_and_into (src_info->out, dest_info->in);
3482 else
3484 src_info->out = BITMAP_ALLOC (&dse_bitmap_obstack);
3485 bitmap_copy (src_info->out, dest_info->in);
3488 return true;
3492 /* Propagate the info from the out to the in set of BB_INDEX's basic
3493 block. There are three cases:
3495 1) The block has no kill set. In this case the kill set is all
3496 ones. It does not matter what the out set of the block is, none of
3497 the info can reach the top. The only thing that reaches the top is
3498 the gen set and we just copy the set.
3500 2) There is a kill set but no out set and bb has successors. In
3501 this case we just return. Eventually an out set will be created and
3502 it is better to wait than to create a set of ones.
3504 3) There is both a kill and out set. We apply the obvious transfer
3505 function.
3508 static bool
3509 dse_transfer_function (int bb_index)
3511 bb_info_t bb_info = bb_table[bb_index];
3513 if (bb_info->kill)
3515 if (bb_info->out)
3517 /* Case 3 above. */
3518 if (bb_info->in)
3519 return bitmap_ior_and_compl (bb_info->in, bb_info->gen,
3520 bb_info->out, bb_info->kill);
3521 else
3523 bb_info->in = BITMAP_ALLOC (&dse_bitmap_obstack);
3524 bitmap_ior_and_compl (bb_info->in, bb_info->gen,
3525 bb_info->out, bb_info->kill);
3526 return true;
3529 else
3530 /* Case 2 above. */
3531 return false;
3533 else
3535 /* Case 1 above. If there is already an in set, nothing
3536 happens. */
3537 if (bb_info->in)
3538 return false;
3539 else
3541 bb_info->in = BITMAP_ALLOC (&dse_bitmap_obstack);
3542 bitmap_copy (bb_info->in, bb_info->gen);
3543 return true;
3548 /* Solve the dataflow equations. */
3550 static void
3551 dse_step4 (void)
3553 df_simple_dataflow (DF_BACKWARD, NULL, dse_confluence_0,
3554 dse_confluence_n, dse_transfer_function,
3555 all_blocks, df_get_postorder (DF_BACKWARD),
3556 df_get_n_blocks (DF_BACKWARD));
3557 if (dump_file)
3559 basic_block bb;
3561 fprintf (dump_file, "\n\n*** Global dataflow info after analysis.\n");
3562 FOR_ALL_BB (bb)
3564 bb_info_t bb_info = bb_table[bb->index];
3566 df_print_bb_index (bb, dump_file);
3567 if (bb_info->in)
3568 bitmap_print (dump_file, bb_info->in, " in: ", "\n");
3569 else
3570 fprintf (dump_file, " in: *MISSING*\n");
3571 if (bb_info->gen)
3572 bitmap_print (dump_file, bb_info->gen, " gen: ", "\n");
3573 else
3574 fprintf (dump_file, " gen: *MISSING*\n");
3575 if (bb_info->kill)
3576 bitmap_print (dump_file, bb_info->kill, " kill: ", "\n");
3577 else
3578 fprintf (dump_file, " kill: *MISSING*\n");
3579 if (bb_info->out)
3580 bitmap_print (dump_file, bb_info->out, " out: ", "\n");
3581 else
3582 fprintf (dump_file, " out: *MISSING*\n\n");
3589 /*----------------------------------------------------------------------------
3590 Fifth step.
3592 Delete the stores that can only be deleted using the global information.
3593 ----------------------------------------------------------------------------*/
3596 static void
3597 dse_step5_nospill (void)
3599 basic_block bb;
3600 FOR_EACH_BB (bb)
3602 bb_info_t bb_info = bb_table[bb->index];
3603 insn_info_t insn_info = bb_info->last_insn;
3604 bitmap v = bb_info->out;
3606 while (insn_info)
3608 bool deleted = false;
3609 if (dump_file && insn_info->insn)
3611 fprintf (dump_file, "starting to process insn %d\n",
3612 INSN_UID (insn_info->insn));
3613 bitmap_print (dump_file, v, " v: ", "\n");
3616 /* There may have been code deleted by the dce pass run before
3617 this phase. */
3618 if (insn_info->insn
3619 && INSN_P (insn_info->insn)
3620 && (!insn_info->cannot_delete)
3621 && (!bitmap_empty_p (v)))
3623 store_info_t store_info = insn_info->store_rec;
3625 /* Try to delete the current insn. */
3626 deleted = true;
3628 /* Skip the clobbers. */
3629 while (!store_info->is_set)
3630 store_info = store_info->next;
3632 if (store_info->alias_set)
3633 deleted = false;
3634 else
3636 HOST_WIDE_INT i;
3637 group_info_t group_info
3638 = rtx_group_vec[store_info->group_id];
3640 for (i = store_info->begin; i < store_info->end; i++)
3642 int index = get_bitmap_index (group_info, i);
3644 if (dump_file)
3645 fprintf (dump_file, "i = %d, index = %d\n", (int)i, index);
3646 if (index == 0 || !bitmap_bit_p (v, index))
3648 if (dump_file)
3649 fprintf (dump_file, "failing at i = %d\n", (int)i);
3650 deleted = false;
3651 break;
3655 if (deleted)
3657 if (dbg_cnt (dse)
3658 && check_for_inc_dec_1 (insn_info))
3660 delete_insn (insn_info->insn);
3661 insn_info->insn = NULL;
3662 globally_deleted++;
3666 /* We do want to process the local info if the insn was
3667 deleted. For instance, if the insn did a wild read, we
3668 no longer need to trash the info. */
3669 if (insn_info->insn
3670 && INSN_P (insn_info->insn)
3671 && (!deleted))
3673 scan_stores_nospill (insn_info->store_rec, v, NULL);
3674 if (insn_info->wild_read)
3676 if (dump_file)
3677 fprintf (dump_file, "wild read\n");
3678 bitmap_clear (v);
3680 else if (insn_info->read_rec
3681 || insn_info->non_frame_wild_read)
3683 if (dump_file && !insn_info->non_frame_wild_read)
3684 fprintf (dump_file, "regular read\n");
3685 else if (dump_file)
3686 fprintf (dump_file, "non-frame wild read\n");
3687 scan_reads_nospill (insn_info, v, NULL);
3691 insn_info = insn_info->prev_insn;
3697 static void
3698 dse_step5_spill (void)
3700 basic_block bb;
3701 FOR_EACH_BB (bb)
3703 bb_info_t bb_info = bb_table[bb->index];
3704 insn_info_t insn_info = bb_info->last_insn;
3705 bitmap v = bb_info->out;
3707 while (insn_info)
3709 bool deleted = false;
3710 /* There may have been code deleted by the dce pass run before
3711 this phase. */
3712 if (insn_info->insn
3713 && INSN_P (insn_info->insn)
3714 && (!insn_info->cannot_delete)
3715 && (!bitmap_empty_p (v)))
3717 /* Try to delete the current insn. */
3718 store_info_t store_info = insn_info->store_rec;
3719 deleted = true;
3721 while (store_info)
3723 if (store_info->alias_set)
3725 int index = get_bitmap_index (clear_alias_group,
3726 store_info->alias_set);
3727 if (index == 0 || !bitmap_bit_p (v, index))
3729 deleted = false;
3730 break;
3733 else
3734 deleted = false;
3735 store_info = store_info->next;
3737 if (deleted && dbg_cnt (dse)
3738 && check_for_inc_dec_1 (insn_info))
3740 if (dump_file)
3741 fprintf (dump_file, "Spill deleting insn %d\n",
3742 INSN_UID (insn_info->insn));
3743 delete_insn (insn_info->insn);
3744 spill_deleted++;
3745 insn_info->insn = NULL;
3749 if (insn_info->insn
3750 && INSN_P (insn_info->insn)
3751 && (!deleted))
3753 scan_stores_spill (insn_info->store_rec, v, NULL);
3754 scan_reads_spill (insn_info->read_rec, v, NULL);
3757 insn_info = insn_info->prev_insn;
3764 /*----------------------------------------------------------------------------
3765 Sixth step.
3767 Delete stores made redundant by earlier stores (which store the same
3768 value) that couldn't be eliminated.
3769 ----------------------------------------------------------------------------*/
3771 static void
3772 dse_step6 (void)
3774 basic_block bb;
3776 FOR_ALL_BB (bb)
3778 bb_info_t bb_info = bb_table[bb->index];
3779 insn_info_t insn_info = bb_info->last_insn;
3781 while (insn_info)
3783 /* There may have been code deleted by the dce pass run before
3784 this phase. */
3785 if (insn_info->insn
3786 && INSN_P (insn_info->insn)
3787 && !insn_info->cannot_delete)
3789 store_info_t s_info = insn_info->store_rec;
3791 while (s_info && !s_info->is_set)
3792 s_info = s_info->next;
3793 if (s_info
3794 && s_info->redundant_reason
3795 && s_info->redundant_reason->insn
3796 && INSN_P (s_info->redundant_reason->insn))
3798 rtx rinsn = s_info->redundant_reason->insn;
3799 if (dump_file)
3800 fprintf (dump_file, "Locally deleting insn %d "
3801 "because insn %d stores the "
3802 "same value and couldn't be "
3803 "eliminated\n",
3804 INSN_UID (insn_info->insn),
3805 INSN_UID (rinsn));
3806 delete_dead_store_insn (insn_info);
3809 insn_info = insn_info->prev_insn;
3814 /*----------------------------------------------------------------------------
3815 Seventh step.
3817 Destroy everything left standing.
3818 ----------------------------------------------------------------------------*/
3820 static void
3821 dse_step7 (void)
3823 bitmap_obstack_release (&dse_bitmap_obstack);
3824 obstack_free (&dse_obstack, NULL);
3826 if (clear_alias_sets)
3828 BITMAP_FREE (clear_alias_sets);
3829 BITMAP_FREE (disqualified_clear_alias_sets);
3830 free_alloc_pool (clear_alias_mode_pool);
3831 htab_delete (clear_alias_mode_table);
3834 end_alias_analysis ();
3835 free (bb_table);
3836 rtx_group_table.dispose ();
3837 rtx_group_vec.release ();
3838 BITMAP_FREE (all_blocks);
3839 BITMAP_FREE (scratch);
3841 free_alloc_pool (rtx_store_info_pool);
3842 free_alloc_pool (read_info_pool);
3843 free_alloc_pool (insn_info_pool);
3844 free_alloc_pool (bb_info_pool);
3845 free_alloc_pool (rtx_group_info_pool);
3846 free_alloc_pool (deferred_change_pool);
3850 /* -------------------------------------------------------------------------
3852 ------------------------------------------------------------------------- */
3854 /* Callback for running pass_rtl_dse. */
3856 static unsigned int
3857 rest_of_handle_dse (void)
3859 bool did_global = false;
3861 df_set_flags (DF_DEFER_INSN_RESCAN);
3863 /* Need the notes since we must track live hardregs in the forwards
3864 direction. */
3865 df_note_add_problem ();
3866 df_analyze ();
3868 dse_step0 ();
3869 dse_step1 ();
3870 dse_step2_init ();
3871 if (dse_step2_nospill ())
3873 df_set_flags (DF_LR_RUN_DCE);
3874 df_analyze ();
3875 did_global = true;
3876 if (dump_file)
3877 fprintf (dump_file, "doing global processing\n");
3878 dse_step3 (false);
3879 dse_step4 ();
3880 dse_step5_nospill ();
3883 /* For the instance of dse that runs after reload, we make a special
3884 pass to process the spills. These are special in that they are
3885 totally transparent, i.e, there is no aliasing issues that need
3886 to be considered. This means that the wild reads that kill
3887 everything else do not apply here. */
3888 if (clear_alias_sets && dse_step2_spill ())
3890 if (!did_global)
3892 df_set_flags (DF_LR_RUN_DCE);
3893 df_analyze ();
3895 did_global = true;
3896 if (dump_file)
3897 fprintf (dump_file, "doing global spill processing\n");
3898 dse_step3 (true);
3899 dse_step4 ();
3900 dse_step5_spill ();
3903 dse_step6 ();
3904 dse_step7 ();
3906 if (dump_file)
3907 fprintf (dump_file, "dse: local deletions = %d, global deletions = %d, spill deletions = %d\n",
3908 locally_deleted, globally_deleted, spill_deleted);
3909 return 0;
3912 static bool
3913 gate_dse1 (void)
3915 return optimize > 0 && flag_dse
3916 && dbg_cnt (dse1);
3919 static bool
3920 gate_dse2 (void)
3922 return optimize > 0 && flag_dse
3923 && dbg_cnt (dse2);
3926 struct rtl_opt_pass pass_rtl_dse1 =
3929 RTL_PASS,
3930 "dse1", /* name */
3931 OPTGROUP_NONE, /* optinfo_flags */
3932 gate_dse1, /* gate */
3933 rest_of_handle_dse, /* execute */
3934 NULL, /* sub */
3935 NULL, /* next */
3936 0, /* static_pass_number */
3937 TV_DSE1, /* tv_id */
3938 0, /* properties_required */
3939 0, /* properties_provided */
3940 0, /* properties_destroyed */
3941 0, /* todo_flags_start */
3942 TODO_df_finish | TODO_verify_rtl_sharing |
3943 TODO_ggc_collect /* todo_flags_finish */
3947 struct rtl_opt_pass pass_rtl_dse2 =
3950 RTL_PASS,
3951 "dse2", /* name */
3952 OPTGROUP_NONE, /* optinfo_flags */
3953 gate_dse2, /* gate */
3954 rest_of_handle_dse, /* execute */
3955 NULL, /* sub */
3956 NULL, /* next */
3957 0, /* static_pass_number */
3958 TV_DSE2, /* tv_id */
3959 0, /* properties_required */
3960 0, /* properties_provided */
3961 0, /* properties_destroyed */
3962 0, /* todo_flags_start */
3963 TODO_df_finish | TODO_verify_rtl_sharing |
3964 TODO_ggc_collect /* todo_flags_finish */