Line data Source code
1 : /* Variable tracking routines for the GNU compiler.
2 : Copyright (C) 2002-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it
7 : under the terms of the GNU General Public License as published by
8 : the Free Software Foundation; either version 3, or (at your option)
9 : any later version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT
12 : ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 : or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 : License for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : /* This file contains the variable tracking pass. It computes where
21 : variables are located (which registers or where in memory) at each position
22 : in instruction stream and emits notes describing the locations.
23 : Debug information (DWARF2 location lists) is finally generated from
24 : these notes.
25 : With this debug information, it is possible to show variables
26 : even when debugging optimized code.
27 :
28 : How does the variable tracking pass work?
29 :
30 : First, it scans RTL code for uses, stores and clobbers (register/memory
31 : references in instructions), for call insns and for stack adjustments
32 : separately for each basic block and saves them to an array of micro
33 : operations.
34 : The micro operations of one instruction are ordered so that
35 : pre-modifying stack adjustment < use < use with no var < call insn <
36 : < clobber < set < post-modifying stack adjustment
37 :
38 : Then, a forward dataflow analysis is performed to find out how locations
39 : of variables change through code and to propagate the variable locations
40 : along control flow graph.
41 : The IN set for basic block BB is computed as a union of OUT sets of BB's
42 : predecessors, the OUT set for BB is copied from the IN set for BB and
43 : is changed according to micro operations in BB.
44 :
45 : The IN and OUT sets for basic blocks consist of a current stack adjustment
46 : (used for adjusting offset of variables addressed using stack pointer),
47 : the table of structures describing the locations of parts of a variable
48 : and for each physical register a linked list for each physical register.
49 : The linked list is a list of variable parts stored in the register,
50 : i.e. it is a list of triplets (reg, decl, offset) where decl is
51 : REG_EXPR (reg) and offset is REG_OFFSET (reg). The linked list is used for
52 : effective deleting appropriate variable parts when we set or clobber the
53 : register.
54 :
55 : There may be more than one variable part in a register. The linked lists
56 : should be pretty short so it is a good data structure here.
57 : For example in the following code, register allocator may assign same
58 : register to variables A and B, and both of them are stored in the same
59 : register in CODE:
60 :
61 : if (cond)
62 : set A;
63 : else
64 : set B;
65 : CODE;
66 : if (cond)
67 : use A;
68 : else
69 : use B;
70 :
71 : Finally, the NOTE_INSN_VAR_LOCATION notes describing the variable locations
72 : are emitted to appropriate positions in RTL code. Each such a note describes
73 : the location of one variable at the point in instruction stream where the
74 : note is. There is no need to emit a note for each variable before each
75 : instruction, we only emit these notes where the location of variable changes
76 : (this means that we also emit notes for changes between the OUT set of the
77 : previous block and the IN set of the current block).
78 :
79 : The notes consist of two parts:
80 : 1. the declaration (from REG_EXPR or MEM_EXPR)
81 : 2. the location of a variable - it is either a simple register/memory
82 : reference (for simple variables, for example int),
83 : or a parallel of register/memory references (for a large variables
84 : which consist of several parts, for example long long).
85 :
86 : */
87 :
88 : #include "config.h"
89 : #include "system.h"
90 : #include "coretypes.h"
91 : #include "backend.h"
92 : #include "target.h"
93 : #include "rtl.h"
94 : #include "tree.h"
95 : #include "cfghooks.h"
96 : #include "alloc-pool.h"
97 : #include "tree-pass.h"
98 : #include "memmodel.h"
99 : #include "tm_p.h"
100 : #include "insn-config.h"
101 : #include "regs.h"
102 : #include "emit-rtl.h"
103 : #include "recog.h"
104 : #include "diagnostic.h"
105 : #include "varasm.h"
106 : #include "stor-layout.h"
107 : #include "cfgrtl.h"
108 : #include "cfganal.h"
109 : #include "reload.h"
110 : #include "ira.h"
111 : #include "lra.h"
112 : #include "calls.h"
113 : #include "tree-dfa.h"
114 : #include "tree-ssa.h"
115 : #include "cselib.h"
116 : #include "tree-pretty-print.h"
117 : #include "rtl-iter.h"
118 : #include "fibonacci_heap.h"
119 : #include "print-rtl.h"
120 : #include "function-abi.h"
121 : #include "mux-utils.h"
122 :
123 : typedef fibonacci_heap <long, basic_block_def> bb_heap_t;
124 :
125 : /* var-tracking.cc assumes that tree code with the same value as VALUE rtx code
126 : has no chance to appear in REG_EXPR/MEM_EXPRs and isn't a decl.
127 : Currently the value is the same as IDENTIFIER_NODE, which has such
128 : a property. If this compile time assertion ever fails, make sure that
129 : the new tree code that equals (int) VALUE has the same property. */
130 : extern char check_value_val[(int) VALUE == (int) IDENTIFIER_NODE ? 1 : -1];
131 :
132 : /* Type of micro operation. */
133 : enum micro_operation_type
134 : {
135 : MO_USE, /* Use location (REG or MEM). */
136 : MO_USE_NO_VAR,/* Use location which is not associated with a variable
137 : or the variable is not trackable. */
138 : MO_VAL_USE, /* Use location which is associated with a value. */
139 : MO_VAL_LOC, /* Use location which appears in a debug insn. */
140 : MO_VAL_SET, /* Set location associated with a value. */
141 : MO_SET, /* Set location. */
142 : MO_COPY, /* Copy the same portion of a variable from one
143 : location to another. */
144 : MO_CLOBBER, /* Clobber location. */
145 : MO_CALL, /* Call insn. */
146 : MO_ADJUST /* Adjust stack pointer. */
147 :
148 : };
149 :
150 : static const char * const ATTRIBUTE_UNUSED
151 : micro_operation_type_name[] = {
152 : "MO_USE",
153 : "MO_USE_NO_VAR",
154 : "MO_VAL_USE",
155 : "MO_VAL_LOC",
156 : "MO_VAL_SET",
157 : "MO_SET",
158 : "MO_COPY",
159 : "MO_CLOBBER",
160 : "MO_CALL",
161 : "MO_ADJUST"
162 : };
163 :
164 : /* Where shall the note be emitted? BEFORE or AFTER the instruction.
165 : Notes emitted as AFTER_CALL are to take effect during the call,
166 : rather than after the call. */
167 : enum emit_note_where
168 : {
169 : EMIT_NOTE_BEFORE_INSN,
170 : EMIT_NOTE_AFTER_INSN,
171 : EMIT_NOTE_AFTER_CALL_INSN
172 : };
173 :
174 : /* Structure holding information about micro operation. */
175 : struct micro_operation
176 : {
177 : /* Type of micro operation. */
178 : enum micro_operation_type type;
179 :
180 : /* The instruction which the micro operation is in, for MO_USE,
181 : MO_USE_NO_VAR, MO_CALL and MO_ADJUST, or the subsequent
182 : instruction or note in the original flow (before any var-tracking
183 : notes are inserted, to simplify emission of notes), for MO_SET
184 : and MO_CLOBBER. */
185 : rtx_insn *insn;
186 :
187 : union {
188 : /* Location. For MO_SET and MO_COPY, this is the SET that
189 : performs the assignment, if known, otherwise it is the target
190 : of the assignment. For MO_VAL_USE and MO_VAL_SET, it is a
191 : CONCAT of the VALUE and the LOC associated with it. For
192 : MO_VAL_LOC, it is a CONCAT of the VALUE and the VAR_LOCATION
193 : associated with it. */
194 : rtx loc;
195 :
196 : /* Stack adjustment. */
197 : HOST_WIDE_INT adjust;
198 : } u;
199 : };
200 :
201 :
202 : /* A declaration of a variable, or an RTL value being handled like a
203 : declaration by pointer_mux. */
204 : typedef pointer_mux<tree_node, rtx_def> decl_or_value;
205 :
206 : /* Return true if a decl_or_value DV is a DECL or NULL. */
207 : static inline bool
208 47205547244 : dv_is_decl_p (decl_or_value dv)
209 : {
210 39316194975 : return dv.is_first ();
211 : }
212 :
213 : /* Return true if a decl_or_value is a VALUE rtl. */
214 : static inline bool
215 39378644119 : dv_is_value_p (decl_or_value dv)
216 : {
217 39378644119 : return dv && !dv_is_decl_p (dv);
218 : }
219 :
220 : /* Return the decl in the decl_or_value. */
221 : static inline tree
222 7411975139 : dv_as_decl (decl_or_value dv)
223 : {
224 7411975139 : gcc_checking_assert (dv_is_decl_p (dv));
225 7411975139 : return dv.known_first ();
226 : }
227 :
228 : /* Return the value in the decl_or_value. */
229 : static inline rtx
230 15364599925 : dv_as_value (decl_or_value dv)
231 : {
232 15364599925 : gcc_checking_assert (dv_is_value_p (dv));
233 15364599925 : return dv.known_second ();
234 : }
235 :
236 :
237 : /* Description of location of a part of a variable. The content of a physical
238 : register is described by a chain of these structures.
239 : The chains are pretty short (usually 1 or 2 elements) and thus
240 : chain is the best data structure. */
241 : struct attrs
242 : {
243 : /* Pointer to next member of the list. */
244 : attrs *next;
245 :
246 : /* The rtx of register. */
247 : rtx loc;
248 :
249 : /* The declaration corresponding to LOC. */
250 : decl_or_value dv;
251 :
252 : /* Offset from start of DECL. */
253 : HOST_WIDE_INT offset;
254 : };
255 :
256 : /* Structure for chaining the locations. */
257 : struct location_chain
258 : {
259 : /* Next element in the chain. */
260 : location_chain *next;
261 :
262 : /* The location (REG, MEM or VALUE). */
263 : rtx loc;
264 :
265 : /* The "value" stored in this location. */
266 : rtx set_src;
267 :
268 : /* Initialized? */
269 : enum var_init_status init;
270 : };
271 :
272 : /* A vector of loc_exp_dep holds the active dependencies of a one-part
273 : DV on VALUEs, i.e., the VALUEs expanded so as to form the current
274 : location of DV. Each entry is also part of VALUE' s linked-list of
275 : backlinks back to DV. */
276 : struct loc_exp_dep
277 : {
278 : /* The dependent DV. */
279 : decl_or_value dv;
280 : /* The dependency VALUE or DECL_DEBUG. */
281 : rtx value;
282 : /* The next entry in VALUE's backlinks list. */
283 : struct loc_exp_dep *next;
284 : /* A pointer to the pointer to this entry (head or prev's next) in
285 : the doubly-linked list. */
286 : struct loc_exp_dep **pprev;
287 : };
288 :
289 :
290 : /* This data structure holds information about the depth of a variable
291 : expansion. */
292 : struct expand_depth
293 : {
294 : /* This measures the complexity of the expanded expression. It
295 : grows by one for each level of expansion that adds more than one
296 : operand. */
297 : int complexity;
298 : /* This counts the number of ENTRY_VALUE expressions in an
299 : expansion. We want to minimize their use. */
300 : int entryvals;
301 : };
302 :
303 : /* Type for dependencies actively used when expand FROM into cur_loc. */
304 : typedef vec<loc_exp_dep, va_heap, vl_embed> deps_vec;
305 :
306 : /* This data structure is allocated for one-part variables at the time
307 : of emitting notes. */
308 : struct onepart_aux
309 : {
310 : /* Doubly-linked list of dependent DVs. These are DVs whose cur_loc
311 : computation used the expansion of this variable, and that ought
312 : to be notified should this variable change. If the DV's cur_loc
313 : expanded to NULL, all components of the loc list are regarded as
314 : active, so that any changes in them give us a chance to get a
315 : location. Otherwise, only components of the loc that expanded to
316 : non-NULL are regarded as active dependencies. */
317 : loc_exp_dep *backlinks;
318 : /* This holds the LOC that was expanded into cur_loc. We need only
319 : mark a one-part variable as changed if the FROM loc is removed,
320 : or if it has no known location and a loc is added, or if it gets
321 : a change notification from any of its active dependencies. */
322 : rtx from;
323 : /* The depth of the cur_loc expression. */
324 : expand_depth depth;
325 : /* Dependencies actively used when expand FROM into cur_loc. */
326 : deps_vec deps;
327 : };
328 :
329 : /* Structure describing one part of variable. */
330 : struct variable_part
331 : {
332 : /* Chain of locations of the part. */
333 : location_chain *loc_chain;
334 :
335 : /* Location which was last emitted to location list. */
336 : rtx cur_loc;
337 :
338 : union variable_aux
339 : {
340 : /* The offset in the variable, if !var->onepart. */
341 : HOST_WIDE_INT offset;
342 :
343 : /* Pointer to auxiliary data, if var->onepart and emit_notes. */
344 : struct onepart_aux *onepaux;
345 : } aux;
346 : };
347 :
348 : /* Maximum number of location parts. */
349 : #define MAX_VAR_PARTS 16
350 :
351 : /* Enumeration type used to discriminate various types of one-part
352 : variables. */
353 : enum onepart_enum
354 : {
355 : /* Not a one-part variable. */
356 : NOT_ONEPART = 0,
357 : /* A one-part DECL that is not a DEBUG_EXPR_DECL. */
358 : ONEPART_VDECL = 1,
359 : /* A DEBUG_EXPR_DECL. */
360 : ONEPART_DEXPR = 2,
361 : /* A VALUE. */
362 : ONEPART_VALUE = 3
363 : };
364 :
365 : /* Structure describing where the variable is located. */
366 : struct variable
367 : {
368 : /* The declaration of the variable, or an RTL value being handled
369 : like a declaration. */
370 : decl_or_value dv;
371 :
372 : /* Reference count. */
373 : int refcount;
374 :
375 : /* Number of variable parts. */
376 : char n_var_parts;
377 :
378 : /* What type of DV this is, according to enum onepart_enum. */
379 : ENUM_BITFIELD (onepart_enum) onepart : CHAR_BIT;
380 :
381 : /* True if this variable_def struct is currently in the
382 : changed_variables hash table. */
383 : bool in_changed_variables;
384 :
385 : /* The variable parts. */
386 : variable_part var_part[1];
387 : };
388 :
389 : /* Pointer to the BB's information specific to variable tracking pass. */
390 : #define VTI(BB) ((variable_tracking_info *) (BB)->aux)
391 :
392 : /* Return MEM_OFFSET (MEM) as a HOST_WIDE_INT, or 0 if we can't. */
393 :
394 : static inline HOST_WIDE_INT
395 20912498 : int_mem_offset (const_rtx mem)
396 : {
397 20912498 : HOST_WIDE_INT offset;
398 20912500 : if (MEM_OFFSET_KNOWN_P (mem) && MEM_OFFSET (mem).is_constant (&offset))
399 18025725 : return offset;
400 : return 0;
401 : }
402 :
403 : #if CHECKING_P && (GCC_VERSION >= 2007)
404 :
405 : /* Access VAR's Ith part's offset, checking that it's not a one-part
406 : variable. */
407 : #define VAR_PART_OFFSET(var, i) __extension__ \
408 : (*({ variable *const __v = (var); \
409 : gcc_checking_assert (!__v->onepart); \
410 : &__v->var_part[(i)].aux.offset; }))
411 :
412 : /* Access VAR's one-part auxiliary data, checking that it is a
413 : one-part variable. */
414 : #define VAR_LOC_1PAUX(var) __extension__ \
415 : (*({ variable *const __v = (var); \
416 : gcc_checking_assert (__v->onepart); \
417 : &__v->var_part[0].aux.onepaux; }))
418 :
419 : #else
420 : #define VAR_PART_OFFSET(var, i) ((var)->var_part[(i)].aux.offset)
421 : #define VAR_LOC_1PAUX(var) ((var)->var_part[0].aux.onepaux)
422 : #endif
423 :
424 : /* These are accessor macros for the one-part auxiliary data. When
425 : convenient for users, they're guarded by tests that the data was
426 : allocated. */
427 : #define VAR_LOC_DEP_LST(var) (VAR_LOC_1PAUX (var) \
428 : ? VAR_LOC_1PAUX (var)->backlinks \
429 : : NULL)
430 : #define VAR_LOC_DEP_LSTP(var) (VAR_LOC_1PAUX (var) \
431 : ? &VAR_LOC_1PAUX (var)->backlinks \
432 : : NULL)
433 : #define VAR_LOC_FROM(var) (VAR_LOC_1PAUX (var)->from)
434 : #define VAR_LOC_DEPTH(var) (VAR_LOC_1PAUX (var)->depth)
435 : #define VAR_LOC_DEP_VEC(var) var_loc_dep_vec (var)
436 :
437 : /* Implements the VAR_LOC_DEP_VEC above as a function to work around
438 : a bogus -Wnonnull (PR c/95554). */
439 :
440 : static inline deps_vec*
441 654581105 : var_loc_dep_vec (variable *var)
442 : {
443 654581105 : return VAR_LOC_1PAUX (var) ? &VAR_LOC_1PAUX (var)->deps : NULL;
444 : }
445 :
446 :
447 : typedef unsigned int dvuid;
448 :
449 : /* Return the uid of DV. */
450 :
451 : static inline dvuid
452 20720216528 : dv_uid (decl_or_value dv)
453 : {
454 20720216528 : if (dv_is_value_p (dv))
455 14034180430 : return CSELIB_VAL_PTR (dv_as_value (dv))->uid;
456 : else
457 6686036098 : return DECL_UID (dv_as_decl (dv));
458 : }
459 :
460 : /* Compute the hash from the uid. */
461 :
462 : static inline hashval_t
463 : dv_uid2hash (dvuid uid)
464 : {
465 : return uid;
466 : }
467 :
468 : /* The hash function for a mask table in a shared_htab chain. */
469 :
470 : static inline hashval_t
471 20720216528 : dv_htab_hash (decl_or_value dv)
472 : {
473 20720216528 : return dv_uid2hash (dv_uid (dv));
474 : }
475 :
476 : static void variable_htab_free (void *);
477 :
478 : /* Variable hashtable helpers. */
479 :
480 : struct variable_hasher : pointer_hash <variable>
481 : {
482 : typedef decl_or_value compare_type;
483 : static inline hashval_t hash (const variable *);
484 : static inline bool equal (const variable *, const decl_or_value);
485 : static inline void remove (variable *);
486 : };
487 :
488 : /* The hash function for variable_htab, computes the hash value
489 : from the declaration of variable X. */
490 :
491 : inline hashval_t
492 17255431625 : variable_hasher::hash (const variable *v)
493 : {
494 17255431625 : return dv_htab_hash (v->dv);
495 : }
496 :
497 : /* Compare the declaration of variable X with declaration Y. */
498 :
499 : inline bool
500 20155268143 : variable_hasher::equal (const variable *v, const decl_or_value y)
501 : {
502 20155268143 : return v->dv == y;
503 : }
504 :
505 : /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
506 :
507 : inline void
508 1106286107 : variable_hasher::remove (variable *var)
509 : {
510 1106286107 : variable_htab_free (var);
511 841385087 : }
512 :
513 : typedef hash_table<variable_hasher> variable_table_type;
514 : typedef variable_table_type::iterator variable_iterator_type;
515 :
516 : /* Structure for passing some other parameters to function
517 : emit_note_insn_var_location. */
518 : struct emit_note_data
519 : {
520 : /* The instruction which the note will be emitted before/after. */
521 : rtx_insn *insn;
522 :
523 : /* Where the note will be emitted (before/after insn)? */
524 : enum emit_note_where where;
525 :
526 : /* The variables and values active at this point. */
527 : variable_table_type *vars;
528 : };
529 :
530 : /* Structure holding a refcounted hash table. If refcount > 1,
531 : it must be first unshared before modified. */
532 : struct shared_hash
533 : {
534 : /* Reference count. */
535 : int refcount;
536 :
537 : /* Actual hash table. */
538 : variable_table_type *htab;
539 : };
540 :
541 : /* Structure holding the IN or OUT set for a basic block. */
542 : struct dataflow_set
543 : {
544 : /* Adjustment of stack offset. */
545 : HOST_WIDE_INT stack_adjust;
546 :
547 : /* Attributes for registers (lists of attrs). */
548 : attrs *regs[FIRST_PSEUDO_REGISTER];
549 :
550 : /* Variable locations. */
551 : shared_hash *vars;
552 :
553 : /* Vars that is being traversed. */
554 : shared_hash *traversed_vars;
555 : };
556 :
557 : /* The structure (one for each basic block) containing the information
558 : needed for variable tracking. */
559 : struct variable_tracking_info
560 : {
561 : /* The vector of micro operations. */
562 : vec<micro_operation> mos;
563 :
564 : /* The IN and OUT set for dataflow analysis. */
565 : dataflow_set in;
566 : dataflow_set out;
567 :
568 : /* The permanent-in dataflow set for this block. This is used to
569 : hold values for which we had to compute entry values. ??? This
570 : should probably be dynamically allocated, to avoid using more
571 : memory in non-debug builds. */
572 : dataflow_set *permp;
573 :
574 : /* Has the block been visited in DFS? */
575 : bool visited;
576 :
577 : /* Has the block been flooded in VTA? */
578 : bool flooded;
579 :
580 : };
581 :
582 : /* Alloc pool for struct attrs_def. */
583 : object_allocator<attrs> attrs_pool ("attrs pool");
584 :
585 : /* Alloc pool for struct variable_def with MAX_VAR_PARTS entries. */
586 :
587 : static pool_allocator var_pool
588 : ("variable_def pool", sizeof (variable) +
589 : (MAX_VAR_PARTS - 1) * sizeof (((variable *)NULL)->var_part[0]));
590 :
591 : /* Alloc pool for struct variable_def with a single var_part entry. */
592 : static pool_allocator valvar_pool
593 : ("small variable_def pool", sizeof (variable));
594 :
595 : /* Alloc pool for struct location_chain. */
596 : static object_allocator<location_chain> location_chain_pool
597 : ("location_chain pool");
598 :
599 : /* Alloc pool for struct shared_hash. */
600 : static object_allocator<shared_hash> shared_hash_pool ("shared_hash pool");
601 :
602 : /* Alloc pool for struct loc_exp_dep_s for NOT_ONEPART variables. */
603 : object_allocator<loc_exp_dep> loc_exp_dep_pool ("loc_exp_dep pool");
604 :
605 : /* Changed variables, notes will be emitted for them. */
606 : static variable_table_type *changed_variables;
607 :
608 : /* Shall notes be emitted? */
609 : static bool emit_notes;
610 :
611 : /* Values whose dynamic location lists have gone empty, but whose
612 : cselib location lists are still usable. Use this to hold the
613 : current location, the backlinks, etc, during emit_notes. */
614 : static variable_table_type *dropped_values;
615 :
616 : /* Empty shared hashtable. */
617 : static shared_hash *empty_shared_hash;
618 :
619 : /* Scratch register bitmap used by cselib_expand_value_rtx. */
620 : static bitmap scratch_regs = NULL;
621 :
622 : #ifdef HAVE_window_save
623 : struct GTY(()) parm_reg {
624 : rtx outgoing;
625 : rtx incoming;
626 : };
627 :
628 :
629 : /* Vector of windowed parameter registers, if any. */
630 : static vec<parm_reg, va_gc> *windowed_parm_regs = NULL;
631 : #endif
632 :
633 : /* Variable used to tell whether cselib_process_insn called our hook. */
634 : static bool cselib_hook_called;
635 :
636 : /* Local function prototypes. */
637 : static void stack_adjust_offset_pre_post (rtx, HOST_WIDE_INT *,
638 : HOST_WIDE_INT *);
639 : static void insn_stack_adjust_offset_pre_post (rtx_insn *, HOST_WIDE_INT *,
640 : HOST_WIDE_INT *);
641 : static bool vt_stack_adjustments (void);
642 :
643 : static void init_attrs_list_set (attrs **);
644 : static void attrs_list_clear (attrs **);
645 : static attrs *attrs_list_member (attrs *, decl_or_value, HOST_WIDE_INT);
646 : static void attrs_list_insert (attrs **, decl_or_value, HOST_WIDE_INT, rtx);
647 : static void attrs_list_copy (attrs **, attrs *);
648 : static void attrs_list_union (attrs **, attrs *);
649 :
650 : static variable **unshare_variable (dataflow_set *set, variable **slot,
651 : variable *var, enum var_init_status);
652 : static void vars_copy (variable_table_type *, variable_table_type *);
653 : static tree var_debug_decl (tree);
654 : static void var_reg_set (dataflow_set *, rtx, enum var_init_status, rtx);
655 : static void var_reg_delete_and_set (dataflow_set *, rtx, bool,
656 : enum var_init_status, rtx);
657 : static void var_reg_delete (dataflow_set *, rtx, bool);
658 : static void var_regno_delete (dataflow_set *, int);
659 : static void var_mem_set (dataflow_set *, rtx, enum var_init_status, rtx);
660 : static void var_mem_delete_and_set (dataflow_set *, rtx, bool,
661 : enum var_init_status, rtx);
662 : static void var_mem_delete (dataflow_set *, rtx, bool);
663 :
664 : static void dataflow_set_init (dataflow_set *);
665 : static void dataflow_set_clear (dataflow_set *);
666 : static void dataflow_set_copy (dataflow_set *, dataflow_set *);
667 : static int variable_union_info_cmp_pos (const void *, const void *);
668 : static void dataflow_set_union (dataflow_set *, dataflow_set *);
669 : static location_chain *find_loc_in_1pdv (rtx, variable *,
670 : variable_table_type *);
671 : static bool canon_value_cmp (rtx, rtx);
672 : static int loc_cmp (rtx, rtx);
673 : static bool variable_part_different_p (variable_part *, variable_part *);
674 : static bool onepart_variable_different_p (variable *, variable *);
675 : static bool variable_different_p (variable *, variable *);
676 : static bool dataflow_set_different (dataflow_set *, dataflow_set *);
677 : static void dataflow_set_destroy (dataflow_set *);
678 :
679 : static bool track_expr_p (tree, bool);
680 : static void add_uses_1 (rtx *, void *);
681 : static void add_stores (rtx, const_rtx, void *);
682 : static bool compute_bb_dataflow (basic_block);
683 : static bool vt_find_locations (void);
684 :
685 : static void dump_attrs_list (attrs *);
686 : static void dump_var (variable *);
687 : static void dump_vars (variable_table_type *);
688 : static void dump_dataflow_set (dataflow_set *);
689 : static void dump_dataflow_sets (void);
690 :
691 : static void set_dv_changed (decl_or_value, bool);
692 : static void variable_was_changed (variable *, dataflow_set *);
693 : static variable **set_slot_part (dataflow_set *, rtx, variable **,
694 : decl_or_value, HOST_WIDE_INT,
695 : enum var_init_status, rtx);
696 : static void set_variable_part (dataflow_set *, rtx,
697 : decl_or_value, HOST_WIDE_INT,
698 : enum var_init_status, rtx, enum insert_option);
699 : static variable **clobber_slot_part (dataflow_set *, rtx,
700 : variable **, HOST_WIDE_INT, rtx);
701 : static void clobber_variable_part (dataflow_set *, rtx,
702 : decl_or_value, HOST_WIDE_INT, rtx);
703 : static variable **delete_slot_part (dataflow_set *, rtx, variable **,
704 : HOST_WIDE_INT);
705 : static void delete_variable_part (dataflow_set *, rtx,
706 : decl_or_value, HOST_WIDE_INT);
707 : static void emit_notes_in_bb (basic_block, dataflow_set *);
708 : static void vt_emit_notes (void);
709 :
710 : static void vt_add_function_parameters (void);
711 : static bool vt_initialize (void);
712 : static void vt_finalize (void);
713 :
714 : /* Callback for stack_adjust_offset_pre_post, called via for_each_inc_dec. */
715 :
716 : static int
717 5281086 : stack_adjust_offset_pre_post_cb (rtx, rtx op, rtx dest, rtx src, rtx srcoff,
718 : void *arg)
719 : {
720 5281086 : if (dest != stack_pointer_rtx)
721 : return 0;
722 :
723 5281086 : switch (GET_CODE (op))
724 : {
725 3840168 : case PRE_INC:
726 3840168 : case PRE_DEC:
727 3840168 : ((HOST_WIDE_INT *)arg)[0] -= INTVAL (srcoff);
728 3840168 : return 0;
729 1427732 : case POST_INC:
730 1427732 : case POST_DEC:
731 1427732 : ((HOST_WIDE_INT *)arg)[1] -= INTVAL (srcoff);
732 1427732 : return 0;
733 13186 : case PRE_MODIFY:
734 13186 : case POST_MODIFY:
735 : /* We handle only adjustments by constant amount. */
736 13186 : gcc_assert (GET_CODE (src) == PLUS
737 : && CONST_INT_P (XEXP (src, 1))
738 : && XEXP (src, 0) == stack_pointer_rtx);
739 13186 : ((HOST_WIDE_INT *)arg)[GET_CODE (op) == POST_MODIFY]
740 13186 : -= INTVAL (XEXP (src, 1));
741 13186 : return 0;
742 0 : default:
743 0 : gcc_unreachable ();
744 : }
745 : }
746 :
747 : /* Given a SET, calculate the amount of stack adjustment it contains
748 : PRE- and POST-modifying stack pointer.
749 : This function is similar to stack_adjust_offset. */
750 :
751 : static void
752 67310024 : stack_adjust_offset_pre_post (rtx pattern, HOST_WIDE_INT *pre,
753 : HOST_WIDE_INT *post)
754 : {
755 67310024 : rtx src = SET_SRC (pattern);
756 67310024 : rtx dest = SET_DEST (pattern);
757 67310024 : enum rtx_code code;
758 :
759 67310024 : if (dest == stack_pointer_rtx)
760 : {
761 : /* (set (reg sp) (plus (reg sp) (const_int))) */
762 3232068 : code = GET_CODE (src);
763 3232068 : if (! (code == PLUS || code == MINUS)
764 3231538 : || XEXP (src, 0) != stack_pointer_rtx
765 3231538 : || !CONST_INT_P (XEXP (src, 1)))
766 3232068 : return;
767 :
768 3231418 : if (code == MINUS)
769 6 : *post += INTVAL (XEXP (src, 1));
770 : else
771 3231412 : *post -= INTVAL (XEXP (src, 1));
772 3231418 : return;
773 : }
774 64077956 : HOST_WIDE_INT res[2] = { 0, 0 };
775 64077956 : for_each_inc_dec (pattern, stack_adjust_offset_pre_post_cb, res);
776 64077956 : *pre += res[0];
777 64077956 : *post += res[1];
778 : }
779 :
780 : /* Given an INSN, calculate the amount of stack adjustment it contains
781 : PRE- and POST-modifying stack pointer. */
782 :
783 : static void
784 161512204 : insn_stack_adjust_offset_pre_post (rtx_insn *insn, HOST_WIDE_INT *pre,
785 : HOST_WIDE_INT *post)
786 : {
787 161512204 : rtx pattern;
788 :
789 161512204 : *pre = 0;
790 161512204 : *post = 0;
791 :
792 161512204 : pattern = PATTERN (insn);
793 161512204 : if (RTX_FRAME_RELATED_P (insn))
794 : {
795 4417457 : rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
796 4417457 : if (expr)
797 32 : pattern = XEXP (expr, 0);
798 : }
799 :
800 161512204 : if (GET_CODE (pattern) == SET)
801 58209228 : stack_adjust_offset_pre_post (pattern, pre, post);
802 103302976 : else if (GET_CODE (pattern) == PARALLEL
803 94566466 : || GET_CODE (pattern) == SEQUENCE)
804 : {
805 8736510 : int i;
806 :
807 : /* There may be stack adjustments inside compound insns. Search
808 : for them. */
809 27815833 : for ( i = XVECLEN (pattern, 0) - 1; i >= 0; i--)
810 19079323 : if (GET_CODE (XVECEXP (pattern, 0, i)) == SET)
811 9100796 : stack_adjust_offset_pre_post (XVECEXP (pattern, 0, i), pre, post);
812 : }
813 161512204 : }
814 :
815 : /* Compute stack adjustments for all blocks by traversing DFS tree.
816 : Return true when the adjustments on all incoming edges are consistent.
817 : Heavily borrowed from pre_and_rev_post_order_compute. */
818 :
819 : static bool
820 472503 : vt_stack_adjustments (void)
821 : {
822 472503 : edge_iterator *stack;
823 472503 : int sp;
824 :
825 : /* Initialize entry block. */
826 472503 : VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->visited = true;
827 472503 : VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->in.stack_adjust
828 472503 : = INCOMING_FRAME_SP_OFFSET;
829 472503 : VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->out.stack_adjust
830 472503 : = INCOMING_FRAME_SP_OFFSET;
831 :
832 : /* Allocate stack for back-tracking up CFG. */
833 472503 : stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1);
834 472503 : sp = 0;
835 :
836 : /* Push the first edge on to the stack. */
837 472503 : stack[sp++] = ei_start (ENTRY_BLOCK_PTR_FOR_FN (cfun)->succs);
838 :
839 17067618 : while (sp)
840 : {
841 16595182 : edge_iterator ei;
842 16595182 : basic_block src;
843 16595182 : basic_block dest;
844 :
845 : /* Look at the edge on the top of the stack. */
846 16595182 : ei = stack[sp - 1];
847 16595182 : src = ei_edge (ei)->src;
848 16595182 : dest = ei_edge (ei)->dest;
849 :
850 : /* Check if the edge destination has been visited yet. */
851 16595182 : if (!VTI (dest)->visited)
852 : {
853 6811439 : rtx_insn *insn;
854 6811439 : HOST_WIDE_INT pre, post, offset;
855 6811439 : VTI (dest)->visited = true;
856 6811439 : VTI (dest)->in.stack_adjust = offset = VTI (src)->out.stack_adjust;
857 :
858 6811439 : if (dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
859 101350896 : for (insn = BB_HEAD (dest);
860 101350896 : insn != NEXT_INSN (BB_END (dest));
861 95002411 : insn = NEXT_INSN (insn))
862 95002411 : if (INSN_P (insn))
863 : {
864 80760073 : insn_stack_adjust_offset_pre_post (insn, &pre, &post);
865 80760073 : offset += pre + post;
866 : }
867 :
868 6811439 : VTI (dest)->out.stack_adjust = offset;
869 :
870 12889573 : if (EDGE_COUNT (dest->succs) > 0)
871 : /* Since the DEST node has been visited for the first
872 : time, check its successors. */
873 6078134 : stack[sp++] = ei_start (dest->succs);
874 : }
875 : else
876 : {
877 : /* We can end up with different stack adjustments for the exit block
878 : of a shrink-wrapped function if stack_adjust_offset_pre_post
879 : doesn't understand the rtx pattern used to restore the stack
880 : pointer in the epilogue. For example, on s390(x), the stack
881 : pointer is often restored via a load-multiple instruction
882 : and so no stack_adjust offset is recorded for it. This means
883 : that the stack offset at the end of the epilogue block is the
884 : same as the offset before the epilogue, whereas other paths
885 : to the exit block will have the correct stack_adjust.
886 :
887 : It is safe to ignore these differences because (a) we never
888 : use the stack_adjust for the exit block in this pass and
889 : (b) dwarf2cfi checks whether the CFA notes in a shrink-wrapped
890 : function are correct.
891 :
892 : We must check whether the adjustments on other edges are
893 : the same though. */
894 9783743 : if (dest != EXIT_BLOCK_PTR_FOR_FN (cfun)
895 9180064 : && VTI (dest)->in.stack_adjust != VTI (src)->out.stack_adjust)
896 : {
897 67 : free (stack);
898 67 : return false;
899 : }
900 :
901 9783676 : if (! ei_one_before_end_p (ei))
902 : /* Go to the next edge. */
903 3233446 : ei_next (&stack[sp - 1]);
904 : else
905 : /* Return to previous level if there are no more edges. */
906 6550230 : sp--;
907 : }
908 : }
909 :
910 472436 : free (stack);
911 472436 : return true;
912 : }
913 :
914 : /* arg_pointer_rtx resp. frame_pointer_rtx if stack_pointer_rtx or
915 : hard_frame_pointer_rtx is being mapped to it and offset for it. */
916 : static rtx cfa_base_rtx;
917 : static HOST_WIDE_INT cfa_base_offset;
918 :
919 : /* Compute a CFA-based value for an ADJUSTMENT made to stack_pointer_rtx
920 : or hard_frame_pointer_rtx. */
921 :
922 : static inline rtx
923 20126502 : compute_cfa_pointer (poly_int64 adjustment)
924 : {
925 28746157 : return plus_constant (Pmode, cfa_base_rtx, adjustment + cfa_base_offset);
926 : }
927 :
928 : /* Adjustment for hard_frame_pointer_rtx to cfa base reg,
929 : or -1 if the replacement shouldn't be done. */
930 : static poly_int64 hard_frame_pointer_adjustment = -1;
931 :
932 : /* Data for adjust_mems callback. */
933 :
934 269652825 : class adjust_mem_data
935 : {
936 : public:
937 : bool store;
938 : machine_mode mem_mode;
939 : HOST_WIDE_INT stack_adjust;
940 : auto_vec<rtx> side_effects;
941 : };
942 :
943 : /* Helper for adjust_mems. Return true if X is suitable for
944 : transformation of wider mode arithmetics to narrower mode. */
945 :
946 : static bool
947 6672 : use_narrower_mode_test (rtx x, const_rtx subreg)
948 : {
949 6672 : subrtx_var_iterator::array_type array;
950 13366 : FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST)
951 : {
952 13344 : rtx x = *iter;
953 13344 : if (CONSTANT_P (x))
954 14 : iter.skip_subrtxes ();
955 : else
956 13330 : switch (GET_CODE (x))
957 : {
958 38 : case REG:
959 38 : if (cselib_lookup (x, GET_MODE (SUBREG_REG (subreg)), 0, VOIDmode))
960 6650 : return false;
961 8 : if (!validate_subreg (GET_MODE (subreg), GET_MODE (x), x,
962 8 : subreg_lowpart_offset (GET_MODE (subreg),
963 8 : GET_MODE (x))))
964 : return false;
965 : break;
966 : case PLUS:
967 : case MINUS:
968 : case MULT:
969 : break;
970 6672 : case ASHIFT:
971 6672 : if (GET_MODE (XEXP (x, 1)) != VOIDmode)
972 : {
973 6128 : enum machine_mode mode = GET_MODE (subreg);
974 6128 : rtx op1 = XEXP (x, 1);
975 6128 : enum machine_mode op1_mode = GET_MODE (op1);
976 6128 : if (GET_MODE_PRECISION (as_a <scalar_int_mode> (mode))
977 6128 : < GET_MODE_PRECISION (as_a <scalar_int_mode> (op1_mode)))
978 : {
979 35 : poly_uint64 byte = subreg_lowpart_offset (mode, op1_mode);
980 35 : if (GET_CODE (op1) == SUBREG || GET_CODE (op1) == CONCAT)
981 : {
982 0 : if (!simplify_subreg (mode, op1, op1_mode, byte))
983 0 : return false;
984 : }
985 35 : else if (!validate_subreg (mode, op1_mode, op1, byte))
986 : return false;
987 : }
988 : }
989 6672 : iter.substitute (XEXP (x, 0));
990 6672 : break;
991 : default:
992 : return false;
993 : }
994 : }
995 22 : return true;
996 6672 : }
997 :
998 : /* Transform X into narrower mode MODE from wider mode WMODE. */
999 :
1000 : static rtx
1001 44 : use_narrower_mode (rtx x, scalar_int_mode mode, scalar_int_mode wmode)
1002 : {
1003 44 : rtx op0, op1;
1004 44 : if (CONSTANT_P (x))
1005 14 : return lowpart_subreg (mode, x, wmode);
1006 30 : switch (GET_CODE (x))
1007 : {
1008 8 : case REG:
1009 8 : return lowpart_subreg (mode, x, wmode);
1010 0 : case PLUS:
1011 0 : case MINUS:
1012 0 : case MULT:
1013 0 : op0 = use_narrower_mode (XEXP (x, 0), mode, wmode);
1014 0 : op1 = use_narrower_mode (XEXP (x, 1), mode, wmode);
1015 0 : return simplify_gen_binary (GET_CODE (x), mode, op0, op1);
1016 22 : case ASHIFT:
1017 22 : op0 = use_narrower_mode (XEXP (x, 0), mode, wmode);
1018 22 : op1 = XEXP (x, 1);
1019 : /* Ensure shift amount is not wider than mode. */
1020 22 : if (GET_MODE (op1) == VOIDmode)
1021 0 : op1 = lowpart_subreg (mode, op1, wmode);
1022 22 : else if (GET_MODE_PRECISION (mode)
1023 22 : < GET_MODE_PRECISION (as_a <scalar_int_mode> (GET_MODE (op1))))
1024 13 : op1 = lowpart_subreg (mode, op1, GET_MODE (op1));
1025 22 : return simplify_gen_binary (ASHIFT, mode, op0, op1);
1026 0 : default:
1027 0 : gcc_unreachable ();
1028 : }
1029 : }
1030 :
1031 : /* Helper function for adjusting used MEMs. */
1032 :
1033 : static rtx
1034 304133113 : adjust_mems (rtx loc, const_rtx old_rtx, void *data)
1035 : {
1036 304133113 : class adjust_mem_data *amd = (class adjust_mem_data *) data;
1037 304133113 : rtx mem, addr = loc, tem;
1038 304133113 : machine_mode mem_mode_save;
1039 304133113 : bool store_save;
1040 304133113 : scalar_int_mode tem_mode, tem_subreg_mode;
1041 304133113 : poly_int64 size;
1042 304133113 : switch (GET_CODE (loc))
1043 : {
1044 64836541 : case REG:
1045 : /* Don't do any sp or fp replacements outside of MEM addresses
1046 : on the LHS. */
1047 64836541 : if (amd->mem_mode == VOIDmode && amd->store)
1048 : return loc;
1049 64804424 : if (loc == stack_pointer_rtx
1050 20379323 : && !frame_pointer_needed
1051 18286933 : && cfa_base_rtx)
1052 18286836 : return compute_cfa_pointer (amd->stack_adjust);
1053 46517588 : else if (loc == hard_frame_pointer_rtx
1054 2085953 : && frame_pointer_needed
1055 2085664 : && maybe_ne (hard_frame_pointer_adjustment, -1)
1056 48357254 : && cfa_base_rtx)
1057 1839666 : return compute_cfa_pointer (hard_frame_pointer_adjustment);
1058 44677922 : gcc_checking_assert (loc != virtual_incoming_args_rtx);
1059 : return loc;
1060 23150885 : case MEM:
1061 23150885 : mem = loc;
1062 23150885 : if (!amd->store)
1063 : {
1064 13731301 : mem = targetm.delegitimize_address (mem);
1065 13731301 : if (mem != loc && !MEM_P (mem))
1066 116438 : return simplify_replace_fn_rtx (mem, old_rtx, adjust_mems, data);
1067 : }
1068 :
1069 23034447 : addr = XEXP (mem, 0);
1070 23034447 : mem_mode_save = amd->mem_mode;
1071 23034447 : amd->mem_mode = GET_MODE (mem);
1072 23034447 : store_save = amd->store;
1073 23034447 : amd->store = false;
1074 23034447 : addr = simplify_replace_fn_rtx (addr, old_rtx, adjust_mems, data);
1075 23034447 : amd->store = store_save;
1076 23034447 : amd->mem_mode = mem_mode_save;
1077 23034447 : if (mem == loc)
1078 22989381 : addr = targetm.delegitimize_address (addr);
1079 23034447 : if (addr != XEXP (mem, 0))
1080 12514987 : mem = replace_equiv_address_nv (mem, addr);
1081 23034447 : if (!amd->store)
1082 13614863 : mem = avoid_constant_pool_reference (mem);
1083 : return mem;
1084 2379632 : case PRE_INC:
1085 2379632 : case PRE_DEC:
1086 4759264 : size = GET_MODE_SIZE (amd->mem_mode);
1087 4759264 : addr = plus_constant (GET_MODE (loc), XEXP (loc, 0),
1088 2379632 : GET_CODE (loc) == PRE_INC ? size : -size);
1089 : /* FALLTHRU */
1090 3182601 : case POST_INC:
1091 3182601 : case POST_DEC:
1092 3182601 : if (addr == loc)
1093 802969 : addr = XEXP (loc, 0);
1094 3182601 : gcc_assert (amd->mem_mode != VOIDmode && amd->mem_mode != BLKmode);
1095 3182601 : addr = simplify_replace_fn_rtx (addr, old_rtx, adjust_mems, data);
1096 6365202 : size = GET_MODE_SIZE (amd->mem_mode);
1097 3182601 : tem = plus_constant (GET_MODE (loc), XEXP (loc, 0),
1098 3182601 : (GET_CODE (loc) == PRE_INC
1099 3182601 : || GET_CODE (loc) == POST_INC) ? size : -size);
1100 3182601 : store_save = amd->store;
1101 3182601 : amd->store = false;
1102 3182601 : tem = simplify_replace_fn_rtx (tem, old_rtx, adjust_mems, data);
1103 3182601 : amd->store = store_save;
1104 3182601 : amd->side_effects.safe_push (gen_rtx_SET (XEXP (loc, 0), tem));
1105 3182601 : return addr;
1106 12381 : case PRE_MODIFY:
1107 12381 : addr = XEXP (loc, 1);
1108 : /* FALLTHRU */
1109 12381 : case POST_MODIFY:
1110 12381 : if (addr == loc)
1111 0 : addr = XEXP (loc, 0);
1112 12381 : gcc_assert (amd->mem_mode != VOIDmode);
1113 12381 : addr = simplify_replace_fn_rtx (addr, old_rtx, adjust_mems, data);
1114 12381 : store_save = amd->store;
1115 12381 : amd->store = false;
1116 12381 : tem = simplify_replace_fn_rtx (XEXP (loc, 1), old_rtx,
1117 : adjust_mems, data);
1118 12381 : amd->store = store_save;
1119 12381 : amd->side_effects.safe_push (gen_rtx_SET (XEXP (loc, 0), tem));
1120 12381 : return addr;
1121 84498 : case SUBREG:
1122 : /* First try without delegitimization of whole MEMs and
1123 : avoid_constant_pool_reference, which is more likely to succeed. */
1124 84498 : store_save = amd->store;
1125 84498 : amd->store = true;
1126 84498 : addr = simplify_replace_fn_rtx (SUBREG_REG (loc), old_rtx, adjust_mems,
1127 : data);
1128 84498 : amd->store = store_save;
1129 84498 : mem = simplify_replace_fn_rtx (addr, old_rtx, adjust_mems, data);
1130 84498 : if (mem == SUBREG_REG (loc))
1131 : {
1132 83683 : tem = loc;
1133 83683 : goto finish_subreg;
1134 : }
1135 1630 : tem = simplify_gen_subreg (GET_MODE (loc), mem,
1136 815 : GET_MODE (SUBREG_REG (loc)),
1137 815 : SUBREG_BYTE (loc));
1138 815 : if (tem)
1139 814 : goto finish_subreg;
1140 2 : tem = simplify_gen_subreg (GET_MODE (loc), addr,
1141 1 : GET_MODE (SUBREG_REG (loc)),
1142 1 : SUBREG_BYTE (loc));
1143 1 : if (tem == NULL_RTX)
1144 1 : tem = gen_rtx_raw_SUBREG (GET_MODE (loc), addr, SUBREG_BYTE (loc));
1145 0 : finish_subreg:
1146 84498 : if (MAY_HAVE_DEBUG_BIND_INSNS
1147 84498 : && GET_CODE (tem) == SUBREG
1148 84498 : && (GET_CODE (SUBREG_REG (tem)) == PLUS
1149 84498 : || GET_CODE (SUBREG_REG (tem)) == MINUS
1150 : || GET_CODE (SUBREG_REG (tem)) == MULT
1151 : || GET_CODE (SUBREG_REG (tem)) == ASHIFT)
1152 7485 : && is_a <scalar_int_mode> (GET_MODE (tem), &tem_mode)
1153 7462 : && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (tem)),
1154 : &tem_subreg_mode)
1155 7364 : && (GET_MODE_PRECISION (tem_mode)
1156 7364 : < GET_MODE_PRECISION (tem_subreg_mode))
1157 6688 : && subreg_lowpart_p (tem)
1158 91170 : && use_narrower_mode_test (SUBREG_REG (tem), tem))
1159 22 : return use_narrower_mode (SUBREG_REG (tem), tem_mode, tem_subreg_mode);
1160 : return tem;
1161 11629 : case ASM_OPERANDS:
1162 : /* Don't do any replacements in second and following
1163 : ASM_OPERANDS of inline-asm with multiple sets.
1164 : ASM_OPERANDS_INPUT_VEC, ASM_OPERANDS_INPUT_CONSTRAINT_VEC
1165 : and ASM_OPERANDS_LABEL_VEC need to be equal between
1166 : all the ASM_OPERANDs in the insn and adjust_insn will
1167 : fix this up. */
1168 11629 : if (ASM_OPERANDS_OUTPUT_IDX (loc) != 0)
1169 3895 : return loc;
1170 : break;
1171 : default:
1172 : break;
1173 : }
1174 : return NULL_RTX;
1175 : }
1176 :
1177 : /* Helper function for replacement of uses. */
1178 :
1179 : static void
1180 99796365 : adjust_mem_uses (rtx *x, void *data)
1181 : {
1182 99796365 : rtx new_x = simplify_replace_fn_rtx (*x, NULL_RTX, adjust_mems, data);
1183 99796365 : if (new_x != *x)
1184 11864087 : validate_change (NULL_RTX, x, new_x, true);
1185 99796365 : }
1186 :
1187 : /* Helper function for replacement of stores. */
1188 :
1189 : static void
1190 44147785 : adjust_mem_stores (rtx loc, const_rtx expr, void *data)
1191 : {
1192 44147785 : if (MEM_P (loc))
1193 : {
1194 9410148 : rtx new_dest = simplify_replace_fn_rtx (SET_DEST (expr), NULL_RTX,
1195 : adjust_mems, data);
1196 9410148 : if (new_dest != SET_DEST (expr))
1197 : {
1198 6558723 : rtx xexpr = const_cast<rtx> (expr);
1199 6558723 : validate_change (NULL_RTX, &SET_DEST (xexpr), new_dest, true);
1200 : }
1201 : }
1202 44147785 : }
1203 :
1204 : /* Simplify INSN. Remove all {PRE,POST}_{INC,DEC,MODIFY} rtxes,
1205 : replace them with their value in the insn and add the side-effects
1206 : as other sets to the insn. */
1207 :
1208 : static void
1209 89875653 : adjust_insn (basic_block bb, rtx_insn *insn)
1210 : {
1211 89875653 : rtx set;
1212 :
1213 : #ifdef HAVE_window_save
1214 : /* If the target machine has an explicit window save instruction, the
1215 : transformation OUTGOING_REGNO -> INCOMING_REGNO is done there. */
1216 : if (RTX_FRAME_RELATED_P (insn)
1217 : && find_reg_note (insn, REG_CFA_WINDOW_SAVE, NULL_RTX))
1218 : {
1219 : unsigned int i, nregs = vec_safe_length (windowed_parm_regs);
1220 : rtx rtl = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs * 2));
1221 : parm_reg *p;
1222 :
1223 : FOR_EACH_VEC_SAFE_ELT (windowed_parm_regs, i, p)
1224 : {
1225 : XVECEXP (rtl, 0, i * 2)
1226 : = gen_rtx_SET (p->incoming, p->outgoing);
1227 : /* Do not clobber the attached DECL, but only the REG. */
1228 : XVECEXP (rtl, 0, i * 2 + 1)
1229 : = gen_rtx_CLOBBER (GET_MODE (p->outgoing),
1230 : gen_raw_REG (GET_MODE (p->outgoing),
1231 : REGNO (p->outgoing)));
1232 : }
1233 :
1234 : validate_change (NULL_RTX, &PATTERN (insn), rtl, true);
1235 : return;
1236 : }
1237 : #endif
1238 :
1239 89875653 : adjust_mem_data amd;
1240 89875653 : amd.mem_mode = VOIDmode;
1241 89875653 : amd.stack_adjust = -VTI (bb)->out.stack_adjust;
1242 :
1243 89875653 : amd.store = true;
1244 89875653 : note_stores (insn, adjust_mem_stores, &amd);
1245 :
1246 89875653 : amd.store = false;
1247 89875653 : if (GET_CODE (PATTERN (insn)) == PARALLEL
1248 5037212 : && asm_noperands (PATTERN (insn)) > 0
1249 89886044 : && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1250 : {
1251 7734 : rtx body, set0;
1252 7734 : int i;
1253 :
1254 : /* inline-asm with multiple sets is tiny bit more complicated,
1255 : because the 3 vectors in ASM_OPERANDS need to be shared between
1256 : all ASM_OPERANDS in the instruction. adjust_mems will
1257 : not touch ASM_OPERANDS other than the first one, asm_noperands
1258 : test above needs to be called before that (otherwise it would fail)
1259 : and afterwards this code fixes it up. */
1260 7734 : note_uses (&PATTERN (insn), adjust_mem_uses, &amd);
1261 7734 : body = PATTERN (insn);
1262 7734 : set0 = XVECEXP (body, 0, 0);
1263 7734 : gcc_checking_assert (GET_CODE (set0) == SET
1264 : && GET_CODE (SET_SRC (set0)) == ASM_OPERANDS
1265 : && ASM_OPERANDS_OUTPUT_IDX (SET_SRC (set0)) == 0);
1266 11629 : for (i = 1; i < XVECLEN (body, 0); i++)
1267 11629 : if (GET_CODE (XVECEXP (body, 0, i)) != SET)
1268 : break;
1269 : else
1270 : {
1271 3895 : set = XVECEXP (body, 0, i);
1272 3895 : gcc_checking_assert (GET_CODE (SET_SRC (set)) == ASM_OPERANDS
1273 : && ASM_OPERANDS_OUTPUT_IDX (SET_SRC (set))
1274 : == i);
1275 3895 : if (ASM_OPERANDS_INPUT_VEC (SET_SRC (set))
1276 3895 : != ASM_OPERANDS_INPUT_VEC (SET_SRC (set0))
1277 3356 : || ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set))
1278 3356 : != ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set0))
1279 3356 : || ASM_OPERANDS_LABEL_VEC (SET_SRC (set))
1280 3356 : != ASM_OPERANDS_LABEL_VEC (SET_SRC (set0)))
1281 : {
1282 539 : rtx newsrc = shallow_copy_rtx (SET_SRC (set));
1283 539 : ASM_OPERANDS_INPUT_VEC (newsrc)
1284 539 : = ASM_OPERANDS_INPUT_VEC (SET_SRC (set0));
1285 539 : ASM_OPERANDS_INPUT_CONSTRAINT_VEC (newsrc)
1286 539 : = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set0));
1287 539 : ASM_OPERANDS_LABEL_VEC (newsrc)
1288 539 : = ASM_OPERANDS_LABEL_VEC (SET_SRC (set0));
1289 539 : validate_change (NULL_RTX, &SET_SRC (set), newsrc, true);
1290 : }
1291 : }
1292 : }
1293 : else
1294 89867919 : note_uses (&PATTERN (insn), adjust_mem_uses, &amd);
1295 :
1296 : /* For read-only MEMs containing some constant, prefer those
1297 : constants. */
1298 89875653 : set = single_set (insn);
1299 89875653 : if (set && MEM_P (SET_SRC (set)) && MEM_READONLY_P (SET_SRC (set)))
1300 : {
1301 34728 : rtx note = find_reg_equal_equiv_note (insn);
1302 :
1303 34728 : if (note && CONSTANT_P (XEXP (note, 0)))
1304 0 : validate_change (NULL_RTX, &SET_SRC (set), XEXP (note, 0), true);
1305 : }
1306 :
1307 93070635 : if (!amd.side_effects.is_empty ())
1308 : {
1309 3194982 : rtx *pat, new_pat;
1310 3194982 : int i, oldn;
1311 :
1312 3194982 : pat = &PATTERN (insn);
1313 3194982 : if (GET_CODE (*pat) == COND_EXEC)
1314 0 : pat = &COND_EXEC_CODE (*pat);
1315 3194982 : if (GET_CODE (*pat) == PARALLEL)
1316 17019 : oldn = XVECLEN (*pat, 0);
1317 : else
1318 : oldn = 1;
1319 3194982 : unsigned int newn = amd.side_effects.length ();
1320 3194982 : new_pat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (oldn + newn));
1321 3194982 : if (GET_CODE (*pat) == PARALLEL)
1322 51057 : for (i = 0; i < oldn; i++)
1323 34038 : XVECEXP (new_pat, 0, i) = XVECEXP (*pat, 0, i);
1324 : else
1325 3177963 : XVECEXP (new_pat, 0, 0) = *pat;
1326 :
1327 3194982 : rtx effect;
1328 3194982 : unsigned int j;
1329 9584946 : FOR_EACH_VEC_ELT_REVERSE (amd.side_effects, j, effect)
1330 3194982 : XVECEXP (new_pat, 0, j + oldn) = effect;
1331 3194982 : validate_change (NULL_RTX, pat, new_pat, true);
1332 : }
1333 89875653 : }
1334 :
1335 : /* Return the DEBUG_EXPR of a DEBUG_EXPR_DECL or the VALUE in DV. */
1336 : static inline rtx
1337 12031699 : dv_as_rtx (decl_or_value dv)
1338 : {
1339 12031699 : tree decl;
1340 :
1341 12031699 : if (dv_is_value_p (dv))
1342 9516573 : return dv_as_value (dv);
1343 :
1344 2515126 : decl = dv_as_decl (dv);
1345 :
1346 2515126 : gcc_checking_assert (TREE_CODE (decl) == DEBUG_EXPR_DECL);
1347 2515126 : return DECL_RTL_KNOWN_SET (decl);
1348 : }
1349 :
1350 : /* Return nonzero if a decl_or_value must not have more than one
1351 : variable part. The returned value discriminates among various
1352 : kinds of one-part DVs ccording to enum onepart_enum. */
1353 : static inline onepart_enum
1354 608851782 : dv_onepart_p (decl_or_value dv)
1355 : {
1356 608851782 : tree decl;
1357 :
1358 608851782 : if (!MAY_HAVE_DEBUG_BIND_INSNS)
1359 : return NOT_ONEPART;
1360 :
1361 608851423 : if (dv_is_value_p (dv))
1362 : return ONEPART_VALUE;
1363 :
1364 209042067 : decl = dv_as_decl (dv);
1365 :
1366 209042067 : if (TREE_CODE (decl) == DEBUG_EXPR_DECL)
1367 : return ONEPART_DEXPR;
1368 :
1369 179903898 : if (target_for_debug_bind (decl) != NULL_TREE)
1370 : return ONEPART_VDECL;
1371 :
1372 : return NOT_ONEPART;
1373 : }
1374 :
1375 : /* Return the variable pool to be used for a dv of type ONEPART. */
1376 : static inline pool_allocator &
1377 571213954 : onepart_pool (onepart_enum onepart)
1378 : {
1379 571213954 : return onepart ? valvar_pool : var_pool;
1380 : }
1381 :
1382 : /* Allocate a variable_def from the corresponding variable pool. */
1383 : static inline variable *
1384 285606977 : onepart_pool_allocate (onepart_enum onepart)
1385 : {
1386 270513586 : return (variable*) onepart_pool (onepart).allocate ();
1387 : }
1388 :
1389 : /* Build a decl_or_value out of a decl. */
1390 : static inline decl_or_value
1391 181990784 : dv_from_decl (tree decl)
1392 : {
1393 181990784 : decl_or_value dv = decl;
1394 181990784 : gcc_checking_assert (dv_is_decl_p (dv));
1395 181990784 : return dv;
1396 : }
1397 :
1398 : /* Build a decl_or_value out of a value. */
1399 : static inline decl_or_value
1400 1164864431 : dv_from_value (rtx value)
1401 : {
1402 1164864431 : decl_or_value dv = value;
1403 1164864431 : gcc_checking_assert (dv_is_value_p (dv));
1404 1164864431 : return dv;
1405 : }
1406 :
1407 : /* Return a value or the decl of a debug_expr as a decl_or_value. */
1408 : static inline decl_or_value
1409 411111875 : dv_from_rtx (rtx x)
1410 : {
1411 411111875 : decl_or_value dv;
1412 :
1413 411111875 : switch (GET_CODE (x))
1414 : {
1415 30659058 : case DEBUG_EXPR:
1416 30659058 : dv = dv_from_decl (DEBUG_EXPR_TREE_DECL (x));
1417 30659058 : gcc_checking_assert (DECL_RTL_KNOWN_SET (DEBUG_EXPR_TREE_DECL (x)) == x);
1418 : break;
1419 :
1420 380452817 : case VALUE:
1421 380452817 : dv = dv_from_value (x);
1422 380452817 : break;
1423 :
1424 0 : default:
1425 0 : gcc_unreachable ();
1426 : }
1427 :
1428 411111875 : return dv;
1429 : }
1430 :
1431 : extern void debug_dv (decl_or_value dv);
1432 :
1433 : DEBUG_FUNCTION void
1434 0 : debug_dv (decl_or_value dv)
1435 : {
1436 0 : if (dv_is_value_p (dv))
1437 0 : debug_rtx (dv_as_value (dv));
1438 : else
1439 0 : debug_generic_stmt (dv_as_decl (dv));
1440 0 : }
1441 :
1442 : static void loc_exp_dep_clear (variable *var);
1443 :
1444 : /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
1445 :
1446 : static void
1447 1255212894 : variable_htab_free (void *elem)
1448 : {
1449 1255212894 : int i;
1450 1255212894 : variable *var = (variable *) elem;
1451 1255212894 : location_chain *node, *next;
1452 :
1453 1255212894 : gcc_checking_assert (var->refcount > 0);
1454 :
1455 1255212894 : var->refcount--;
1456 1255212894 : if (var->refcount > 0)
1457 : return;
1458 :
1459 418101478 : for (i = 0; i < var->n_var_parts; i++)
1460 : {
1461 317451178 : for (node = var->var_part[i].loc_chain; node; node = next)
1462 : {
1463 184956677 : next = node->next;
1464 184956677 : delete node;
1465 : }
1466 132494501 : var->var_part[i].loc_chain = NULL;
1467 : }
1468 285606977 : if (var->onepart && VAR_LOC_1PAUX (var))
1469 : {
1470 41476722 : loc_exp_dep_clear (var);
1471 41476722 : if (VAR_LOC_DEP_LST (var))
1472 2270603 : VAR_LOC_DEP_LST (var)->pprev = NULL;
1473 41476722 : XDELETE (VAR_LOC_1PAUX (var));
1474 : /* These may be reused across functions, so reset
1475 : e.g. NO_LOC_P. */
1476 41476722 : if (var->onepart == ONEPART_DEXPR)
1477 2639394 : set_dv_changed (var->dv, true);
1478 : }
1479 287247537 : onepart_pool (var->onepart).remove (var);
1480 : }
1481 :
1482 : /* Initialize the set (array) SET of attrs to empty lists. */
1483 :
1484 : static void
1485 31028497 : init_attrs_list_set (attrs **set)
1486 : {
1487 31028497 : int i;
1488 :
1489 2885650221 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1490 2854621724 : set[i] = NULL;
1491 0 : }
1492 :
1493 : /* Make the list *LISTP empty. */
1494 :
1495 : static void
1496 8969061232 : attrs_list_clear (attrs **listp)
1497 : {
1498 8969061232 : attrs *list, *next;
1499 :
1500 9191982124 : for (list = *listp; list; list = next)
1501 : {
1502 222920892 : next = list->next;
1503 222920892 : delete list;
1504 : }
1505 8969061232 : *listp = NULL;
1506 8969061232 : }
1507 :
1508 : /* Return true if the pair of DECL and OFFSET is the member of the LIST. */
1509 :
1510 : static attrs *
1511 957178 : attrs_list_member (attrs *list, decl_or_value dv, HOST_WIDE_INT offset)
1512 : {
1513 1061571 : for (; list; list = list->next)
1514 932451 : if (list->dv == dv && list->offset == offset)
1515 : return list;
1516 : return NULL;
1517 : }
1518 :
1519 : /* Insert the triplet DECL, OFFSET, LOC to the list *LISTP. */
1520 :
1521 : static void
1522 85605856 : attrs_list_insert (attrs **listp, decl_or_value dv,
1523 : HOST_WIDE_INT offset, rtx loc)
1524 : {
1525 85605856 : attrs *list = new attrs;
1526 85605856 : list->loc = loc;
1527 85605856 : list->dv = dv;
1528 85605856 : list->offset = offset;
1529 85605856 : list->next = *listp;
1530 85605856 : *listp = list;
1531 85605856 : }
1532 :
1533 : /* Copy all nodes from SRC and create a list *DSTP of the copies. */
1534 :
1535 : static void
1536 3235103824 : attrs_list_copy (attrs **dstp, attrs *src)
1537 : {
1538 3235103824 : attrs_list_clear (dstp);
1539 3427365453 : for (; src; src = src->next)
1540 : {
1541 192261629 : attrs *n = new attrs;
1542 192261629 : n->loc = src->loc;
1543 192261629 : n->dv = src->dv;
1544 192261629 : n->offset = src->offset;
1545 192261629 : n->next = *dstp;
1546 192261629 : *dstp = n;
1547 : }
1548 3235103824 : }
1549 :
1550 : /* Add all nodes from SRC which are not in *DSTP to *DSTP. */
1551 :
1552 : static void
1553 11224 : attrs_list_union (attrs **dstp, attrs *src)
1554 : {
1555 11455 : for (; src; src = src->next)
1556 : {
1557 462 : if (!attrs_list_member (*dstp, src->dv, src->offset))
1558 197 : attrs_list_insert (dstp, src->dv, src->offset, src->loc);
1559 : }
1560 11224 : }
1561 :
1562 : /* Combine nodes that are not onepart nodes from SRC and SRC2 into
1563 : *DSTP. */
1564 :
1565 : static void
1566 396202784 : attrs_list_mpdv_union (attrs **dstp, attrs *src, attrs *src2)
1567 : {
1568 396202784 : gcc_assert (!*dstp);
1569 424701976 : for (; src; src = src->next)
1570 : {
1571 28499192 : if (!dv_onepart_p (src->dv))
1572 1660006 : attrs_list_insert (dstp, src->dv, src->offset, src->loc);
1573 : }
1574 428526338 : for (src = src2; src; src = src->next)
1575 : {
1576 32323554 : if (!dv_onepart_p (src->dv)
1577 33280501 : && !attrs_list_member (*dstp, src->dv, src->offset))
1578 128923 : attrs_list_insert (dstp, src->dv, src->offset, src->loc);
1579 : }
1580 396202784 : }
1581 :
1582 : /* Shared hashtable support. */
1583 :
1584 : /* Return true if VARS is shared. */
1585 :
1586 : static inline bool
1587 969630364 : shared_hash_shared (shared_hash *vars)
1588 : {
1589 969630364 : return vars->refcount > 1;
1590 : }
1591 :
1592 : /* Return the hash table for VARS. */
1593 :
1594 : static inline variable_table_type *
1595 2047759752 : shared_hash_htab (shared_hash *vars)
1596 : {
1597 2047759752 : return vars->htab;
1598 : }
1599 :
1600 : /* Return true if VAR is shared, or maybe because VARS is shared. */
1601 :
1602 : static inline bool
1603 1727516893 : shared_var_p (variable *var, shared_hash *vars)
1604 : {
1605 : /* Don't count an entry in the changed_variables table as a duplicate. */
1606 1727516893 : return ((var->refcount > 1 + (int) var->in_changed_variables)
1607 464337441 : || shared_hash_shared (vars));
1608 : }
1609 :
1610 : /* Copy variables into a new hash table. */
1611 :
1612 : static shared_hash *
1613 16639826 : shared_hash_unshare (shared_hash *vars)
1614 : {
1615 16639826 : shared_hash *new_vars = new shared_hash;
1616 16639826 : gcc_assert (vars->refcount > 1);
1617 16639826 : new_vars->refcount = 1;
1618 16639826 : new_vars->htab = new variable_table_type (vars->htab->elements () + 3);
1619 16639826 : vars_copy (new_vars->htab, vars->htab);
1620 16639826 : vars->refcount--;
1621 16639826 : return new_vars;
1622 : }
1623 :
1624 : /* Increment reference counter on VARS and return it. */
1625 :
1626 : static inline shared_hash *
1627 97497185 : shared_hash_copy (shared_hash *vars)
1628 : {
1629 97497185 : vars->refcount++;
1630 97497185 : return vars;
1631 : }
1632 :
1633 : /* Decrement reference counter and destroy hash table if not shared
1634 : anymore. */
1635 :
1636 : static void
1637 101803737 : shared_hash_destroy (shared_hash *vars)
1638 : {
1639 101803737 : gcc_checking_assert (vars->refcount > 0);
1640 101803737 : if (--vars->refcount == 0)
1641 : {
1642 20946378 : delete vars->htab;
1643 20946378 : delete vars;
1644 : }
1645 101803737 : }
1646 :
1647 : /* Unshare *PVARS if shared and return slot for DV. If INS is
1648 : INSERT, insert it if not already present. */
1649 :
1650 : static inline variable **
1651 141739694 : shared_hash_find_slot_unshare_1 (shared_hash **pvars, decl_or_value dv,
1652 : hashval_t dvhash, enum insert_option ins)
1653 : {
1654 141739694 : if (shared_hash_shared (*pvars))
1655 16639826 : *pvars = shared_hash_unshare (*pvars);
1656 141739694 : return shared_hash_htab (*pvars)->find_slot_with_hash (dv, dvhash, ins);
1657 : }
1658 :
1659 : static inline variable **
1660 16678162 : shared_hash_find_slot_unshare (shared_hash **pvars, decl_or_value dv,
1661 : enum insert_option ins)
1662 : {
1663 16678162 : return shared_hash_find_slot_unshare_1 (pvars, dv, dv_htab_hash (dv), ins);
1664 : }
1665 :
1666 : /* Return slot for DV, if it is already present in the hash table.
1667 : If it is not present, insert it only VARS is not shared, otherwise
1668 : return NULL. */
1669 :
1670 : static inline variable **
1671 225655784 : shared_hash_find_slot_1 (shared_hash *vars, decl_or_value dv, hashval_t dvhash)
1672 : {
1673 225655784 : return shared_hash_htab (vars)->find_slot_with_hash (dv, dvhash,
1674 225655784 : shared_hash_shared (vars)
1675 225655784 : ? NO_INSERT : INSERT);
1676 : }
1677 :
1678 : static inline variable **
1679 225655784 : shared_hash_find_slot (shared_hash *vars, decl_or_value dv)
1680 : {
1681 225655784 : return shared_hash_find_slot_1 (vars, dv, dv_htab_hash (dv));
1682 : }
1683 :
1684 : /* Return slot for DV only if it is already present in the hash table. */
1685 :
1686 : static inline variable **
1687 1005162563 : shared_hash_find_slot_noinsert_1 (shared_hash *vars, decl_or_value dv,
1688 : hashval_t dvhash)
1689 : {
1690 1005162563 : return shared_hash_htab (vars)->find_slot_with_hash (dv, dvhash, NO_INSERT);
1691 : }
1692 :
1693 : static inline variable **
1694 687958982 : shared_hash_find_slot_noinsert (shared_hash *vars, decl_or_value dv)
1695 : {
1696 687958982 : return shared_hash_find_slot_noinsert_1 (vars, dv, dv_htab_hash (dv));
1697 : }
1698 :
1699 : /* Return variable for DV or NULL if not already present in the hash
1700 : table. */
1701 :
1702 : static inline variable *
1703 226247224 : shared_hash_find_1 (shared_hash *vars, decl_or_value dv, hashval_t dvhash)
1704 : {
1705 452494448 : return shared_hash_htab (vars)->find_with_hash (dv, dvhash);
1706 : }
1707 :
1708 : static inline variable *
1709 55640466 : shared_hash_find (shared_hash *vars, decl_or_value dv)
1710 : {
1711 55640466 : return shared_hash_find_1 (vars, dv, dv_htab_hash (dv));
1712 : }
1713 :
1714 : /* Return true if TVAL is better than CVAL as a canonival value. We
1715 : choose lowest-numbered VALUEs, using the RTX address as a
1716 : tie-breaker. The idea is to arrange them into a star topology,
1717 : such that all of them are at most one step away from the canonical
1718 : value, and the canonical value has backlinks to all of them, in
1719 : addition to all the actual locations. We don't enforce this
1720 : topology throughout the entire dataflow analysis, though.
1721 : */
1722 :
1723 : static inline bool
1724 3364290613 : canon_value_cmp (rtx tval, rtx cval)
1725 : {
1726 3364290613 : return !cval
1727 1198416151 : || CSELIB_VAL_PTR (tval)->uid < CSELIB_VAL_PTR (cval)->uid;
1728 : }
1729 :
1730 : static bool dst_can_be_shared;
1731 :
1732 : /* Return a copy of a variable VAR and insert it to dataflow set SET. */
1733 :
1734 : static variable **
1735 57814399 : unshare_variable (dataflow_set *set, variable **slot, variable *var,
1736 : enum var_init_status initialized)
1737 : {
1738 57814399 : variable *new_var;
1739 57814399 : int i;
1740 :
1741 57814399 : new_var = onepart_pool_allocate (var->onepart);
1742 57814399 : new_var->dv = var->dv;
1743 57814399 : new_var->refcount = 1;
1744 57814399 : var->refcount--;
1745 57814399 : new_var->n_var_parts = var->n_var_parts;
1746 57814399 : new_var->onepart = var->onepart;
1747 57814399 : new_var->in_changed_variables = false;
1748 :
1749 57814399 : if (! flag_var_tracking_uninit)
1750 0 : initialized = VAR_INIT_STATUS_INITIALIZED;
1751 :
1752 116016419 : for (i = 0; i < var->n_var_parts; i++)
1753 : {
1754 58202020 : location_chain *node;
1755 58202020 : location_chain **nextp;
1756 :
1757 58202020 : if (i == 0 && var->onepart)
1758 : {
1759 : /* One-part auxiliary data is only used while emitting
1760 : notes, so propagate it to the new variable in the active
1761 : dataflow set. If we're not emitting notes, this will be
1762 : a no-op. */
1763 56998552 : gcc_checking_assert (!VAR_LOC_1PAUX (var) || emit_notes);
1764 56998552 : VAR_LOC_1PAUX (new_var) = VAR_LOC_1PAUX (var);
1765 56998552 : VAR_LOC_1PAUX (var) = NULL;
1766 56998552 : }
1767 : else
1768 1203468 : VAR_PART_OFFSET (new_var, i) = VAR_PART_OFFSET (var, i);
1769 58202020 : nextp = &new_var->var_part[i].loc_chain;
1770 143700266 : for (node = var->var_part[i].loc_chain; node; node = node->next)
1771 : {
1772 85498246 : location_chain *new_lc;
1773 :
1774 85498246 : new_lc = new location_chain;
1775 85498246 : new_lc->next = NULL;
1776 85498246 : if (node->init > initialized)
1777 58810217 : new_lc->init = node->init;
1778 : else
1779 26688029 : new_lc->init = initialized;
1780 85498246 : if (node->set_src && !(MEM_P (node->set_src)))
1781 74338 : new_lc->set_src = node->set_src;
1782 : else
1783 85423908 : new_lc->set_src = NULL;
1784 85498246 : new_lc->loc = node->loc;
1785 :
1786 85498246 : *nextp = new_lc;
1787 85498246 : nextp = &new_lc->next;
1788 : }
1789 :
1790 58202020 : new_var->var_part[i].cur_loc = var->var_part[i].cur_loc;
1791 : }
1792 :
1793 57814399 : dst_can_be_shared = false;
1794 57814399 : if (shared_hash_shared (set->vars))
1795 4977406 : slot = shared_hash_find_slot_unshare (&set->vars, var->dv, NO_INSERT);
1796 52836993 : else if (set->traversed_vars && set->vars != set->traversed_vars)
1797 212437 : slot = shared_hash_find_slot_noinsert (set->vars, var->dv);
1798 57814399 : *slot = new_var;
1799 57814399 : if (var->in_changed_variables)
1800 : {
1801 0 : variable **cslot
1802 0 : = changed_variables->find_slot_with_hash (var->dv,
1803 : dv_htab_hash (var->dv),
1804 : NO_INSERT);
1805 0 : gcc_assert (*cslot == (void *) var);
1806 0 : var->in_changed_variables = false;
1807 0 : variable_htab_free (var);
1808 0 : *cslot = new_var;
1809 0 : new_var->in_changed_variables = true;
1810 : }
1811 57814399 : return slot;
1812 : }
1813 :
1814 : /* Copy all variables from hash table SRC to hash table DST. */
1815 :
1816 : static void
1817 16639826 : vars_copy (variable_table_type *dst, variable_table_type *src)
1818 : {
1819 16639826 : variable_iterator_type hi;
1820 16639826 : variable *var;
1821 :
1822 638412777 : FOR_EACH_HASH_TABLE_ELEMENT (*src, var, variable, hi)
1823 : {
1824 621772951 : variable **dstp;
1825 621772951 : var->refcount++;
1826 621772951 : dstp = dst->find_slot_with_hash (var->dv, dv_htab_hash (var->dv), INSERT);
1827 621772951 : *dstp = var;
1828 : }
1829 16639826 : }
1830 :
1831 : /* Map a decl to its main debug decl. */
1832 :
1833 : static inline tree
1834 72952105 : var_debug_decl (tree decl)
1835 : {
1836 72952105 : if (decl && VAR_P (decl) && DECL_HAS_DEBUG_EXPR_P (decl))
1837 : {
1838 2462458 : tree debugdecl = DECL_DEBUG_EXPR (decl);
1839 2462458 : if (DECL_P (debugdecl))
1840 72952105 : decl = debugdecl;
1841 : }
1842 :
1843 72952105 : return decl;
1844 : }
1845 :
1846 : /* Set the register LOC to contain DV, OFFSET. */
1847 :
1848 : static void
1849 66208229 : var_reg_decl_set (dataflow_set *set, rtx loc, enum var_init_status initialized,
1850 : decl_or_value dv, HOST_WIDE_INT offset, rtx set_src,
1851 : enum insert_option iopt)
1852 : {
1853 66208229 : attrs *node;
1854 66208229 : bool decl_p = dv_is_decl_p (dv);
1855 :
1856 66208229 : if (decl_p)
1857 1622085 : dv = dv_from_decl (var_debug_decl (dv_as_decl (dv)));
1858 :
1859 69490102 : for (node = set->regs[REGNO (loc)]; node; node = node->next)
1860 4530285 : if (node->dv == dv && node->offset == offset)
1861 : break;
1862 66208229 : if (!node)
1863 64959817 : attrs_list_insert (&set->regs[REGNO (loc)], dv, offset, loc);
1864 66208229 : set_variable_part (set, loc, dv, offset, initialized, set_src, iopt);
1865 66208229 : }
1866 :
1867 : /* Return true if we should track a location that is OFFSET bytes from
1868 : a variable. Store the constant offset in *OFFSET_OUT if so. */
1869 :
1870 : static bool
1871 17784071 : track_offset_p (poly_int64 offset, HOST_WIDE_INT *offset_out)
1872 : {
1873 17784071 : HOST_WIDE_INT const_offset;
1874 15945336 : if (!offset.is_constant (&const_offset)
1875 17784071 : || !IN_RANGE (const_offset, 0, MAX_VAR_PARTS - 1))
1876 : return false;
1877 17783763 : *offset_out = const_offset;
1878 0 : return true;
1879 : }
1880 :
1881 : /* Return the offset of a register that track_offset_p says we
1882 : should track. */
1883 :
1884 : static HOST_WIDE_INT
1885 2061027 : get_tracked_reg_offset (rtx loc)
1886 : {
1887 2061027 : HOST_WIDE_INT offset;
1888 2061027 : if (!track_offset_p (REG_OFFSET (loc), &offset))
1889 0 : gcc_unreachable ();
1890 2061027 : return offset;
1891 : }
1892 :
1893 : /* Set the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). */
1894 :
1895 : static void
1896 1622085 : var_reg_set (dataflow_set *set, rtx loc, enum var_init_status initialized,
1897 : rtx set_src)
1898 : {
1899 1622085 : tree decl = REG_EXPR (loc);
1900 1622085 : HOST_WIDE_INT offset = get_tracked_reg_offset (loc);
1901 :
1902 1622085 : var_reg_decl_set (set, loc, initialized,
1903 : dv_from_decl (decl), offset, set_src, INSERT);
1904 1622085 : }
1905 :
1906 : static enum var_init_status
1907 174419 : get_init_value (dataflow_set *set, rtx loc, decl_or_value dv)
1908 : {
1909 174419 : variable *var;
1910 174419 : int i;
1911 174419 : enum var_init_status ret_val = VAR_INIT_STATUS_UNKNOWN;
1912 :
1913 174419 : if (! flag_var_tracking_uninit)
1914 : return VAR_INIT_STATUS_INITIALIZED;
1915 :
1916 174419 : var = shared_hash_find (set->vars, dv);
1917 174419 : if (var)
1918 : {
1919 364559 : for (i = 0; i < var->n_var_parts && ret_val == VAR_INIT_STATUS_UNKNOWN; i++)
1920 : {
1921 208077 : location_chain *nextp;
1922 310595 : for (nextp = var->var_part[i].loc_chain; nextp; nextp = nextp->next)
1923 227550 : if (rtx_equal_p (nextp->loc, loc))
1924 : {
1925 125032 : ret_val = nextp->init;
1926 125032 : break;
1927 : }
1928 : }
1929 : }
1930 :
1931 : return ret_val;
1932 : }
1933 :
1934 : /* Delete current content of register LOC in dataflow set SET and set
1935 : the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). If
1936 : MODIFY is true, any other live copies of the same variable part are
1937 : also deleted from the dataflow set, otherwise the variable part is
1938 : assumed to be copied from another location holding the same
1939 : part. */
1940 :
1941 : static void
1942 394245 : var_reg_delete_and_set (dataflow_set *set, rtx loc, bool modify,
1943 : enum var_init_status initialized, rtx set_src)
1944 : {
1945 394245 : tree decl = REG_EXPR (loc);
1946 394245 : HOST_WIDE_INT offset = get_tracked_reg_offset (loc);
1947 394245 : attrs *node, *next;
1948 394245 : attrs **nextp;
1949 :
1950 394245 : decl = var_debug_decl (decl);
1951 :
1952 394245 : if (initialized == VAR_INIT_STATUS_UNKNOWN)
1953 7882 : initialized = get_init_value (set, loc, dv_from_decl (decl));
1954 :
1955 394245 : nextp = &set->regs[REGNO (loc)];
1956 622487 : for (node = *nextp; node; node = next)
1957 : {
1958 228242 : next = node->next;
1959 228242 : if (node->dv != decl || node->offset != offset)
1960 : {
1961 203457 : delete_variable_part (set, node->loc, node->dv, node->offset);
1962 203457 : delete node;
1963 203457 : *nextp = next;
1964 : }
1965 : else
1966 : {
1967 24785 : node->loc = loc;
1968 24785 : nextp = &node->next;
1969 : }
1970 : }
1971 394245 : if (modify)
1972 266057 : clobber_variable_part (set, loc, dv_from_decl (decl), offset, set_src);
1973 394245 : var_reg_set (set, loc, initialized, set_src);
1974 394245 : }
1975 :
1976 : /* Delete the association of register LOC in dataflow set SET with any
1977 : variables that aren't onepart. If CLOBBER is true, also delete any
1978 : other live copies of the same variable part, and delete the
1979 : association with onepart dvs too. */
1980 :
1981 : static void
1982 62392387 : var_reg_delete (dataflow_set *set, rtx loc, bool clobber)
1983 : {
1984 62392387 : attrs **nextp = &set->regs[REGNO (loc)];
1985 62392387 : attrs *node, *next;
1986 :
1987 62392387 : HOST_WIDE_INT offset;
1988 62392387 : if (clobber && track_offset_p (REG_OFFSET (loc), &offset))
1989 : {
1990 13884001 : tree decl = REG_EXPR (loc);
1991 :
1992 13884001 : decl = var_debug_decl (decl);
1993 :
1994 13884001 : clobber_variable_part (set, NULL, dv_from_decl (decl), offset, NULL);
1995 : }
1996 :
1997 114899052 : for (node = *nextp; node; node = next)
1998 : {
1999 52506665 : next = node->next;
2000 52506665 : if (clobber || !dv_onepart_p (node->dv))
2001 : {
2002 3316215 : delete_variable_part (set, node->loc, node->dv, node->offset);
2003 3316215 : delete node;
2004 3316215 : *nextp = next;
2005 : }
2006 : else
2007 49190450 : nextp = &node->next;
2008 : }
2009 62392387 : }
2010 :
2011 : /* Delete content of register with number REGNO in dataflow set SET. */
2012 :
2013 : static void
2014 622638892 : var_regno_delete (dataflow_set *set, int regno)
2015 : {
2016 622638892 : attrs **reg = &set->regs[regno];
2017 622638892 : attrs *node, *next;
2018 :
2019 673362642 : for (node = *reg; node; node = next)
2020 : {
2021 50723750 : next = node->next;
2022 50723750 : delete_variable_part (set, node->loc, node->dv, node->offset);
2023 50723750 : delete node;
2024 : }
2025 622638892 : *reg = NULL;
2026 622638892 : }
2027 :
2028 : /* Return true if I is the negated value of a power of two. */
2029 : static bool
2030 197202 : negative_power_of_two_p (HOST_WIDE_INT i)
2031 : {
2032 197202 : unsigned HOST_WIDE_INT x = -(unsigned HOST_WIDE_INT)i;
2033 197202 : return pow2_or_zerop (x);
2034 : }
2035 :
2036 : /* Strip constant offsets and alignments off of LOC. Return the base
2037 : expression. */
2038 :
2039 : static rtx
2040 10275001 : vt_get_canonicalize_base (rtx loc)
2041 : {
2042 10275001 : while ((GET_CODE (loc) == PLUS
2043 10275001 : || GET_CODE (loc) == AND)
2044 0 : && GET_CODE (XEXP (loc, 1)) == CONST_INT
2045 10275001 : && (GET_CODE (loc) != AND
2046 0 : || negative_power_of_two_p (INTVAL (XEXP (loc, 1)))))
2047 0 : loc = XEXP (loc, 0);
2048 :
2049 10275001 : return loc;
2050 : }
2051 :
2052 : /* This caches canonicalized addresses for VALUEs, computed using
2053 : information in the global cselib table. */
2054 : static hash_map<rtx, rtx> *global_get_addr_cache;
2055 :
2056 : /* This caches canonicalized addresses for VALUEs, computed using
2057 : information from the global cache and information pertaining to a
2058 : basic block being analyzed. */
2059 : static hash_map<rtx, rtx> *local_get_addr_cache;
2060 :
2061 : static rtx vt_canonicalize_addr (dataflow_set *, rtx);
2062 :
2063 : /* Return the canonical address for LOC, that must be a VALUE, using a
2064 : cached global equivalence or computing it and storing it in the
2065 : global cache. */
2066 :
2067 : static rtx
2068 101700977 : get_addr_from_global_cache (rtx const loc)
2069 : {
2070 101700977 : rtx x;
2071 :
2072 101700977 : gcc_checking_assert (GET_CODE (loc) == VALUE);
2073 :
2074 101700977 : bool existed;
2075 101700977 : rtx *slot = &global_get_addr_cache->get_or_insert (loc, &existed);
2076 101700977 : if (existed)
2077 91603128 : return *slot;
2078 :
2079 10097849 : x = canon_rtx (get_addr (loc));
2080 :
2081 : /* Tentative, avoiding infinite recursion. */
2082 10097849 : *slot = x;
2083 :
2084 10097849 : if (x != loc)
2085 : {
2086 8336549 : rtx nx = vt_canonicalize_addr (NULL, x);
2087 8336549 : if (nx != x)
2088 : {
2089 : /* The table may have moved during recursion, recompute
2090 : SLOT. */
2091 4813238 : *global_get_addr_cache->get (loc) = x = nx;
2092 : }
2093 : }
2094 :
2095 : return x;
2096 : }
2097 :
2098 : /* Return the canonical address for LOC, that must be a VALUE, using a
2099 : cached local equivalence or computing it and storing it in the
2100 : local cache. */
2101 :
2102 : static rtx
2103 605692106 : get_addr_from_local_cache (dataflow_set *set, rtx const loc)
2104 : {
2105 605692106 : rtx x;
2106 605692106 : decl_or_value dv;
2107 605692106 : variable *var;
2108 605692106 : location_chain *l;
2109 :
2110 605692106 : gcc_checking_assert (GET_CODE (loc) == VALUE);
2111 :
2112 605692106 : bool existed;
2113 605692106 : rtx *slot = &local_get_addr_cache->get_or_insert (loc, &existed);
2114 605692106 : if (existed)
2115 510845859 : return *slot;
2116 :
2117 94846247 : x = get_addr_from_global_cache (loc);
2118 :
2119 : /* Tentative, avoiding infinite recursion. */
2120 94846247 : *slot = x;
2121 :
2122 : /* Recurse to cache local expansion of X, or if we need to search
2123 : for a VALUE in the expansion. */
2124 94846247 : if (x != loc)
2125 : {
2126 86998555 : rtx nx = vt_canonicalize_addr (set, x);
2127 86998555 : if (nx != x)
2128 : {
2129 7146309 : slot = local_get_addr_cache->get (loc);
2130 7146309 : *slot = x = nx;
2131 : }
2132 86998555 : return x;
2133 : }
2134 :
2135 7847692 : dv = dv_from_rtx (x);
2136 7847692 : var = shared_hash_find (set->vars, dv);
2137 7847692 : if (!var)
2138 : return x;
2139 :
2140 : /* Look for an improved equivalent expression. */
2141 13861256 : for (l = var->var_part[0].loc_chain; l; l = l->next)
2142 : {
2143 10275001 : rtx base = vt_get_canonicalize_base (l->loc);
2144 10275001 : if (GET_CODE (base) == VALUE
2145 10275001 : && canon_value_cmp (base, loc))
2146 : {
2147 3407840 : rtx nx = vt_canonicalize_addr (set, l->loc);
2148 3407840 : if (x != nx)
2149 : {
2150 3407840 : slot = local_get_addr_cache->get (loc);
2151 3407840 : *slot = x = nx;
2152 : }
2153 : break;
2154 : }
2155 : }
2156 :
2157 : return x;
2158 : }
2159 :
2160 : /* Canonicalize LOC using equivalences from SET in addition to those
2161 : in the cselib static table. It expects a VALUE-based expression,
2162 : and it will only substitute VALUEs with other VALUEs or
2163 : function-global equivalences, so that, if two addresses have base
2164 : VALUEs that are locally or globally related in ways that
2165 : memrefs_conflict_p cares about, they will both canonicalize to
2166 : expressions that have the same base VALUE.
2167 :
2168 : The use of VALUEs as canonical base addresses enables the canonical
2169 : RTXs to remain unchanged globally, if they resolve to a constant,
2170 : or throughout a basic block otherwise, so that they can be cached
2171 : and the cache needs not be invalidated when REGs, MEMs or such
2172 : change. */
2173 :
2174 : static rtx
2175 690268898 : vt_canonicalize_addr (dataflow_set *set, rtx oloc)
2176 : {
2177 690268898 : poly_int64 ofst = 0, term;
2178 690268898 : machine_mode mode = GET_MODE (oloc);
2179 690268898 : rtx loc = oloc;
2180 690268898 : rtx x;
2181 690268898 : bool retry = true;
2182 :
2183 690268898 : while (retry)
2184 : {
2185 776393120 : while (GET_CODE (loc) == PLUS
2186 776393120 : && poly_int_rtx_p (XEXP (loc, 1), &term))
2187 : {
2188 86124222 : ofst += term;
2189 86124222 : loc = XEXP (loc, 0);
2190 : }
2191 :
2192 : /* Alignment operations can't normally be combined, so just
2193 : canonicalize the base and we're done. We'll normally have
2194 : only one stack alignment anyway. */
2195 690268898 : if (GET_CODE (loc) == AND
2196 197227 : && GET_CODE (XEXP (loc, 1)) == CONST_INT
2197 690466100 : && negative_power_of_two_p (INTVAL (XEXP (loc, 1))))
2198 : {
2199 197199 : x = vt_canonicalize_addr (set, XEXP (loc, 0));
2200 197199 : if (x != XEXP (loc, 0))
2201 18107 : loc = gen_rtx_AND (mode, x, XEXP (loc, 1));
2202 : retry = false;
2203 : }
2204 :
2205 690268898 : if (GET_CODE (loc) == VALUE)
2206 : {
2207 612546836 : if (set)
2208 605692106 : loc = get_addr_from_local_cache (set, loc);
2209 : else
2210 6854730 : loc = get_addr_from_global_cache (loc);
2211 :
2212 : /* Consolidate plus_constants. */
2213 621251150 : while (maybe_ne (ofst, 0)
2214 26392930 : && GET_CODE (loc) == PLUS
2215 2001818598 : && poly_int_rtx_p (XEXP (loc, 1), &term))
2216 : {
2217 8704314 : ofst += term;
2218 8704314 : loc = XEXP (loc, 0);
2219 : }
2220 :
2221 : retry = false;
2222 : }
2223 : else
2224 : {
2225 77722062 : x = canon_rtx (loc);
2226 77722062 : if (retry)
2227 77524863 : retry = (x != loc);
2228 77524863 : loc = x;
2229 : }
2230 : }
2231 :
2232 : /* Add OFST back in. */
2233 690268898 : if (maybe_ne (ofst, 0))
2234 : {
2235 : /* Don't build new RTL if we can help it. */
2236 86088460 : if (strip_offset (oloc, &term) == loc && known_eq (term, ofst))
2237 : return oloc;
2238 :
2239 11905959 : loc = plus_constant (mode, loc, ofst);
2240 : }
2241 :
2242 : return loc;
2243 : }
2244 :
2245 : /* Return true iff there's a true dependence between MLOC and LOC.
2246 : MADDR must be a canonicalized version of MLOC's address. */
2247 :
2248 : static inline bool
2249 1435391795 : vt_canon_true_dep (dataflow_set *set, rtx mloc, rtx maddr, rtx loc)
2250 : {
2251 1435391795 : if (GET_CODE (loc) != MEM)
2252 : return false;
2253 :
2254 571959729 : rtx addr = vt_canonicalize_addr (set, XEXP (loc, 0));
2255 571959729 : if (!canon_true_dependence (mloc, GET_MODE (mloc), maddr, loc, addr))
2256 : return false;
2257 :
2258 : return true;
2259 : }
2260 :
2261 : /* Hold parameters for the hashtab traversal function
2262 : drop_overlapping_mem_locs, see below. */
2263 :
2264 : struct overlapping_mems
2265 : {
2266 : dataflow_set *set;
2267 : rtx loc, addr;
2268 : };
2269 :
2270 : /* Remove all MEMs that overlap with COMS->LOC from the location list
2271 : of a hash table entry for a onepart variable. COMS->ADDR must be a
2272 : canonicalized form of COMS->LOC's address, and COMS->LOC must be
2273 : canonicalized itself. */
2274 :
2275 : int
2276 1159077368 : drop_overlapping_mem_locs (variable **slot, overlapping_mems *coms)
2277 : {
2278 1159077368 : dataflow_set *set = coms->set;
2279 1159077368 : rtx mloc = coms->loc, addr = coms->addr;
2280 1159077368 : variable *var = *slot;
2281 :
2282 1159077368 : if (var->onepart != NOT_ONEPART)
2283 : {
2284 1154275037 : location_chain *loc, **locp;
2285 1154275037 : bool changed = false;
2286 1154275037 : rtx cur_loc;
2287 :
2288 1154275037 : gcc_assert (var->n_var_parts == 1);
2289 :
2290 1154275037 : if (shared_var_p (var, set->vars))
2291 : {
2292 2001507200 : for (loc = var->var_part[0].loc_chain; loc; loc = loc->next)
2293 1076121374 : if (vt_canon_true_dep (set, mloc, addr, loc->loc))
2294 : break;
2295 :
2296 930248173 : if (!loc)
2297 : return 1;
2298 :
2299 4862347 : slot = unshare_variable (set, slot, var, VAR_INIT_STATUS_UNKNOWN);
2300 4862347 : var = *slot;
2301 4862347 : gcc_assert (var->n_var_parts == 1);
2302 : }
2303 :
2304 228889211 : if (VAR_LOC_1PAUX (var))
2305 31478544 : cur_loc = VAR_LOC_FROM (var);
2306 : else
2307 197410667 : cur_loc = var->var_part[0].cur_loc;
2308 :
2309 228889211 : for (locp = &var->var_part[0].loc_chain, loc = *locp;
2310 588159632 : loc; loc = *locp)
2311 : {
2312 359270421 : if (!vt_canon_true_dep (set, mloc, addr, loc->loc))
2313 : {
2314 349614680 : locp = &loc->next;
2315 349614680 : continue;
2316 : }
2317 :
2318 9655741 : *locp = loc->next;
2319 : /* If we have deleted the location which was last emitted
2320 : we have to emit new location so add the variable to set
2321 : of changed variables. */
2322 9655741 : if (cur_loc == loc->loc)
2323 : {
2324 471485 : changed = true;
2325 471485 : var->var_part[0].cur_loc = NULL;
2326 471485 : if (VAR_LOC_1PAUX (var))
2327 471485 : VAR_LOC_FROM (var) = NULL;
2328 : }
2329 9655741 : delete loc;
2330 : }
2331 :
2332 228889211 : if (!var->var_part[0].loc_chain)
2333 : {
2334 4795298 : var->n_var_parts--;
2335 4795298 : changed = true;
2336 : }
2337 228889211 : if (changed)
2338 4863658 : variable_was_changed (var, set);
2339 : }
2340 :
2341 : return 1;
2342 : }
2343 :
2344 : /* Remove from SET all VALUE bindings to MEMs that overlap with LOC. */
2345 :
2346 : static void
2347 19369026 : clobber_overlapping_mems (dataflow_set *set, rtx loc)
2348 : {
2349 19369026 : struct overlapping_mems coms;
2350 :
2351 19369026 : gcc_checking_assert (GET_CODE (loc) == MEM);
2352 :
2353 19369026 : coms.set = set;
2354 19369026 : coms.loc = canon_rtx (loc);
2355 19369026 : coms.addr = vt_canonicalize_addr (set, XEXP (loc, 0));
2356 :
2357 19369026 : set->traversed_vars = set->vars;
2358 19369026 : shared_hash_htab (set->vars)
2359 1178446394 : ->traverse <overlapping_mems*, drop_overlapping_mem_locs> (&coms);
2360 19369026 : set->traversed_vars = NULL;
2361 19369026 : }
2362 :
2363 : /* Set the location of DV, OFFSET as the MEM LOC. */
2364 :
2365 : static void
2366 39380938 : var_mem_decl_set (dataflow_set *set, rtx loc, enum var_init_status initialized,
2367 : decl_or_value dv, HOST_WIDE_INT offset, rtx set_src,
2368 : enum insert_option iopt)
2369 : {
2370 39380938 : if (dv_is_decl_p (dv))
2371 70686 : dv = dv_from_decl (var_debug_decl (dv_as_decl (dv)));
2372 :
2373 39380938 : set_variable_part (set, loc, dv, offset, initialized, set_src, iopt);
2374 39380938 : }
2375 :
2376 : /* Set the location part of variable MEM_EXPR (LOC) in dataflow set
2377 : SET to LOC.
2378 : Adjust the address first if it is stack pointer based. */
2379 :
2380 : static void
2381 70686 : var_mem_set (dataflow_set *set, rtx loc, enum var_init_status initialized,
2382 : rtx set_src)
2383 : {
2384 70686 : tree decl = MEM_EXPR (loc);
2385 70686 : HOST_WIDE_INT offset = int_mem_offset (loc);
2386 :
2387 70686 : var_mem_decl_set (set, loc, initialized,
2388 : dv_from_decl (decl), offset, set_src, INSERT);
2389 70686 : }
2390 :
2391 : /* Delete and set the location part of variable MEM_EXPR (LOC) in
2392 : dataflow set SET to LOC. If MODIFY is true, any other live copies
2393 : of the same variable part are also deleted from the dataflow set,
2394 : otherwise the variable part is assumed to be copied from another
2395 : location holding the same part.
2396 : Adjust the address first if it is stack pointer based. */
2397 :
2398 : static void
2399 10317 : var_mem_delete_and_set (dataflow_set *set, rtx loc, bool modify,
2400 : enum var_init_status initialized, rtx set_src)
2401 : {
2402 10317 : tree decl = MEM_EXPR (loc);
2403 10317 : HOST_WIDE_INT offset = int_mem_offset (loc);
2404 :
2405 10317 : clobber_overlapping_mems (set, loc);
2406 10317 : decl = var_debug_decl (decl);
2407 :
2408 10317 : if (initialized == VAR_INIT_STATUS_UNKNOWN)
2409 448 : initialized = get_init_value (set, loc, dv_from_decl (decl));
2410 :
2411 10317 : if (modify)
2412 5183 : clobber_variable_part (set, NULL, dv_from_decl (decl), offset, set_src);
2413 10317 : var_mem_set (set, loc, initialized, set_src);
2414 10317 : }
2415 :
2416 : /* Delete the location part LOC from dataflow set SET. If CLOBBER is
2417 : true, also delete any other live copies of the same variable part.
2418 : Adjust the address first if it is stack pointer based. */
2419 :
2420 : static void
2421 6 : var_mem_delete (dataflow_set *set, rtx loc, bool clobber)
2422 : {
2423 6 : tree decl = MEM_EXPR (loc);
2424 6 : HOST_WIDE_INT offset = int_mem_offset (loc);
2425 :
2426 6 : clobber_overlapping_mems (set, loc);
2427 6 : decl = var_debug_decl (decl);
2428 6 : if (clobber)
2429 6 : clobber_variable_part (set, NULL, dv_from_decl (decl), offset, NULL);
2430 6 : delete_variable_part (set, loc, dv_from_decl (decl), offset);
2431 6 : }
2432 :
2433 : /* Return true if LOC should not be expanded for location expressions,
2434 : or used in them. */
2435 :
2436 : static inline bool
2437 267227842 : unsuitable_loc (rtx loc)
2438 : {
2439 17223350 : switch (GET_CODE (loc))
2440 : {
2441 : case PC:
2442 : case SCRATCH:
2443 : case ASM_INPUT:
2444 : case ASM_OPERANDS:
2445 : return true;
2446 :
2447 244183239 : default:
2448 244183239 : return false;
2449 : }
2450 : }
2451 :
2452 : /* Bind VAL to LOC in SET. If MODIFIED, detach LOC from any values
2453 : bound to it. */
2454 :
2455 : static inline void
2456 103215511 : val_bind (dataflow_set *set, rtx val, rtx loc, bool modified)
2457 : {
2458 103215511 : if (REG_P (loc))
2459 : {
2460 63905259 : if (modified)
2461 53231150 : var_regno_delete (set, REGNO (loc));
2462 63905259 : var_reg_decl_set (set, loc, VAR_INIT_STATUS_INITIALIZED,
2463 : dv_from_value (val), 0, NULL_RTX, INSERT);
2464 : }
2465 39310252 : else if (MEM_P (loc))
2466 : {
2467 39310252 : struct elt_loc_list *l = CSELIB_VAL_PTR (val)->locs;
2468 :
2469 39310252 : if (modified)
2470 19358703 : clobber_overlapping_mems (set, loc);
2471 :
2472 39310252 : if (l && GET_CODE (l->loc) == VALUE)
2473 997418 : l = canonical_cselib_val (CSELIB_VAL_PTR (l->loc))->locs;
2474 :
2475 : /* If this MEM is a global constant, we don't need it in the
2476 : dynamic tables. ??? We should test this before emitting the
2477 : micro-op in the first place. */
2478 49331622 : while (l)
2479 10021370 : if (GET_CODE (l->loc) == MEM && XEXP (l->loc, 0) == XEXP (loc, 0))
2480 : break;
2481 : else
2482 10021370 : l = l->next;
2483 :
2484 39310252 : if (!l)
2485 39310252 : var_mem_decl_set (set, loc, VAR_INIT_STATUS_INITIALIZED,
2486 : dv_from_value (val), 0, NULL_RTX, INSERT);
2487 : }
2488 : else
2489 : {
2490 : /* Other kinds of equivalences are necessarily static, at least
2491 : so long as we do not perform substitutions while merging
2492 : expressions. */
2493 0 : gcc_unreachable ();
2494 : set_variable_part (set, loc, dv_from_value (val), 0,
2495 : VAR_INIT_STATUS_INITIALIZED, NULL_RTX, INSERT);
2496 : }
2497 103215511 : }
2498 :
2499 : /* Bind a value to a location it was just stored in. If MODIFIED
2500 : holds, assume the location was modified, detaching it from any
2501 : values bound to it. */
2502 :
2503 : static void
2504 72589853 : val_store (dataflow_set *set, rtx val, rtx loc, rtx_insn *insn,
2505 : bool modified)
2506 : {
2507 72589853 : cselib_val *v = CSELIB_VAL_PTR (val);
2508 :
2509 72589853 : gcc_assert (cselib_preserved_value_p (v));
2510 :
2511 72589853 : if (dump_file)
2512 : {
2513 442 : fprintf (dump_file, "%i: ", insn ? INSN_UID (insn) : 0);
2514 442 : print_inline_rtx (dump_file, loc, 0);
2515 442 : fprintf (dump_file, " evaluates to ");
2516 442 : print_inline_rtx (dump_file, val, 0);
2517 442 : if (v->locs)
2518 : {
2519 : struct elt_loc_list *l;
2520 778 : for (l = v->locs; l; l = l->next)
2521 : {
2522 434 : fprintf (dump_file, "\n%i: ",
2523 434 : l->setting_insn ? INSN_UID (l->setting_insn) : -1);
2524 434 : print_inline_rtx (dump_file, l->loc, 0);
2525 : }
2526 : }
2527 442 : fprintf (dump_file, "\n");
2528 : }
2529 :
2530 72589853 : gcc_checking_assert (!unsuitable_loc (loc));
2531 :
2532 72589853 : val_bind (set, val, loc, modified);
2533 72589853 : }
2534 :
2535 : /* Clear (canonical address) slots that reference X. */
2536 :
2537 : bool
2538 0 : local_get_addr_clear_given_value (rtx const &, rtx *slot, rtx x)
2539 : {
2540 0 : if (vt_get_canonicalize_base (*slot) == x)
2541 0 : *slot = NULL;
2542 0 : return true;
2543 : }
2544 :
2545 : /* Reset this node, detaching all its equivalences. Return the slot
2546 : in the variable hash table that holds dv, if there is one. */
2547 :
2548 : static void
2549 41353616 : val_reset (dataflow_set *set, decl_or_value dv)
2550 : {
2551 41353616 : variable *var = shared_hash_find (set->vars, dv) ;
2552 41353616 : location_chain *node;
2553 41353616 : rtx cval;
2554 :
2555 41353616 : if (!var || !var->n_var_parts)
2556 : return;
2557 :
2558 0 : gcc_assert (var->n_var_parts == 1);
2559 :
2560 0 : if (var->onepart == ONEPART_VALUE)
2561 : {
2562 0 : rtx x = dv_as_value (dv);
2563 :
2564 : /* Relationships in the global cache don't change, so reset the
2565 : local cache entry only. */
2566 0 : rtx *slot = local_get_addr_cache->get (x);
2567 0 : if (slot)
2568 : {
2569 : /* If the value resolved back to itself, odds are that other
2570 : values may have cached it too. These entries now refer
2571 : to the old X, so detach them too. Entries that used the
2572 : old X but resolved to something else remain ok as long as
2573 : that something else isn't also reset. */
2574 0 : if (*slot == x)
2575 0 : local_get_addr_cache
2576 0 : ->traverse<rtx, local_get_addr_clear_given_value> (x);
2577 0 : *slot = NULL;
2578 : }
2579 : }
2580 :
2581 0 : cval = NULL;
2582 0 : for (node = var->var_part[0].loc_chain; node; node = node->next)
2583 0 : if (GET_CODE (node->loc) == VALUE
2584 0 : && canon_value_cmp (node->loc, cval))
2585 : cval = node->loc;
2586 :
2587 0 : for (node = var->var_part[0].loc_chain; node; node = node->next)
2588 0 : if (GET_CODE (node->loc) == VALUE && cval != node->loc)
2589 : {
2590 : /* Redirect the equivalence link to the new canonical
2591 : value, or simply remove it if it would point at
2592 : itself. */
2593 0 : if (cval)
2594 0 : set_variable_part (set, cval, dv_from_value (node->loc),
2595 : 0, node->init, node->set_src, NO_INSERT);
2596 0 : delete_variable_part (set, dv_as_value (dv),
2597 : dv_from_value (node->loc), 0);
2598 : }
2599 :
2600 0 : if (cval)
2601 : {
2602 0 : decl_or_value cdv = dv_from_value (cval);
2603 :
2604 : /* Keep the remaining values connected, accumulating links
2605 : in the canonical value. */
2606 0 : for (node = var->var_part[0].loc_chain; node; node = node->next)
2607 : {
2608 0 : if (node->loc == cval)
2609 0 : continue;
2610 0 : else if (GET_CODE (node->loc) == REG)
2611 0 : var_reg_decl_set (set, node->loc, node->init, cdv, 0,
2612 : node->set_src, NO_INSERT);
2613 0 : else if (GET_CODE (node->loc) == MEM)
2614 0 : var_mem_decl_set (set, node->loc, node->init, cdv, 0,
2615 : node->set_src, NO_INSERT);
2616 : else
2617 0 : set_variable_part (set, node->loc, cdv, 0,
2618 : node->init, node->set_src, NO_INSERT);
2619 : }
2620 : }
2621 :
2622 : /* We remove this last, to make sure that the canonical value is not
2623 : removed to the point of requiring reinsertion. */
2624 0 : if (cval)
2625 0 : delete_variable_part (set, dv_as_value (dv), dv_from_value (cval), 0);
2626 :
2627 0 : clobber_variable_part (set, NULL, dv, 0, NULL);
2628 : }
2629 :
2630 : /* Find the values in a given location and map the val to another
2631 : value, if it is unique, or add the location as one holding the
2632 : value. */
2633 :
2634 : static void
2635 41072647 : val_resolve (dataflow_set *set, rtx val, rtx loc, rtx_insn *insn)
2636 : {
2637 41072647 : decl_or_value dv = dv_from_value (val);
2638 :
2639 41072647 : if (dump_file && (dump_flags & TDF_DETAILS))
2640 : {
2641 6 : if (insn)
2642 6 : fprintf (dump_file, "%i: ", INSN_UID (insn));
2643 : else
2644 0 : fprintf (dump_file, "head: ");
2645 6 : print_inline_rtx (dump_file, val, 0);
2646 6 : fputs (" is at ", dump_file);
2647 6 : print_inline_rtx (dump_file, loc, 0);
2648 6 : fputc ('\n', dump_file);
2649 : }
2650 :
2651 41072647 : val_reset (set, dv);
2652 :
2653 41072647 : gcc_checking_assert (!unsuitable_loc (loc));
2654 :
2655 41072647 : if (REG_P (loc))
2656 : {
2657 21121098 : attrs *node, *found = NULL;
2658 :
2659 34567476 : for (node = set->regs[REGNO (loc)]; node; node = node->next)
2660 26892756 : if (dv_is_value_p (node->dv)
2661 12990304 : && GET_MODE (dv_as_value (node->dv)) == GET_MODE (loc))
2662 : {
2663 10446989 : found = node;
2664 :
2665 : /* Map incoming equivalences. ??? Wouldn't it be nice if
2666 : we just started sharing the location lists? Maybe a
2667 : circular list ending at the value itself or some
2668 : such. */
2669 10446989 : set_variable_part (set, dv_as_value (node->dv),
2670 : dv_from_value (val), node->offset,
2671 : VAR_INIT_STATUS_INITIALIZED, NULL_RTX, INSERT);
2672 10446989 : set_variable_part (set, val, node->dv, node->offset,
2673 : VAR_INIT_STATUS_INITIALIZED, NULL_RTX, INSERT);
2674 : }
2675 :
2676 : /* If we didn't find any equivalence, we need to remember that
2677 : this value is held in the named register. */
2678 21121098 : if (found)
2679 10446989 : return;
2680 : }
2681 : /* ??? Attempt to find and merge equivalent MEMs or other
2682 : expressions too. */
2683 :
2684 30625658 : val_bind (set, val, loc, false);
2685 : }
2686 :
2687 : /* Initialize dataflow set SET to be empty.
2688 : VARS_SIZE is the initial size of hash table VARS. */
2689 :
2690 : static void
2691 31028497 : dataflow_set_init (dataflow_set *set)
2692 : {
2693 31028497 : init_attrs_list_set (set->regs);
2694 31028497 : set->vars = shared_hash_copy (empty_shared_hash);
2695 31028497 : set->stack_adjust = 0;
2696 31028497 : set->traversed_vars = NULL;
2697 31028497 : }
2698 :
2699 : /* Delete the contents of dataflow set SET. */
2700 :
2701 : static void
2702 31297127 : dataflow_set_clear (dataflow_set *set)
2703 : {
2704 31297127 : int i;
2705 :
2706 2910632811 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2707 2879335684 : attrs_list_clear (&set->regs[i]);
2708 :
2709 31297127 : shared_hash_destroy (set->vars);
2710 31297127 : set->vars = shared_hash_copy (empty_shared_hash);
2711 31297127 : }
2712 :
2713 : /* Copy the contents of dataflow set SRC to DST. */
2714 :
2715 : static void
2716 35164172 : dataflow_set_copy (dataflow_set *dst, dataflow_set *src)
2717 : {
2718 35164172 : int i;
2719 :
2720 3270267996 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2721 3235103824 : attrs_list_copy (&dst->regs[i], src->regs[i]);
2722 :
2723 35164172 : shared_hash_destroy (dst->vars);
2724 35164172 : dst->vars = shared_hash_copy (src->vars);
2725 35164172 : dst->stack_adjust = src->stack_adjust;
2726 35164172 : }
2727 :
2728 : /* Information for merging lists of locations for a given offset of variable.
2729 : */
2730 : struct variable_union_info
2731 : {
2732 : /* Node of the location chain. */
2733 : location_chain *lc;
2734 :
2735 : /* The sum of positions in the input chains. */
2736 : int pos;
2737 :
2738 : /* The position in the chain of DST dataflow set. */
2739 : int pos_dst;
2740 : };
2741 :
2742 : /* Buffer for location list sorting and its allocated size. */
2743 : static struct variable_union_info *vui_vec;
2744 : static int vui_allocated;
2745 :
2746 : /* Compare function for qsort, order the structures by POS element. */
2747 :
2748 : static int
2749 228084 : variable_union_info_cmp_pos (const void *n1, const void *n2)
2750 : {
2751 228084 : const struct variable_union_info *const i1 =
2752 : (const struct variable_union_info *) n1;
2753 228084 : const struct variable_union_info *const i2 =
2754 : ( const struct variable_union_info *) n2;
2755 :
2756 228084 : if (i1->pos != i2->pos)
2757 223281 : return i1->pos - i2->pos;
2758 :
2759 4803 : return (i1->pos_dst - i2->pos_dst);
2760 : }
2761 :
2762 : /* Compute union of location parts of variable *SLOT and the same variable
2763 : from hash table DATA. Compute "sorted" union of the location chains
2764 : for common offsets, i.e. the locations of a variable part are sorted by
2765 : a priority where the priority is the sum of the positions in the 2 chains
2766 : (if a location is only in one list the position in the second list is
2767 : defined to be larger than the length of the chains).
2768 : When we are updating the location parts the newest location is in the
2769 : beginning of the chain, so when we do the described "sorted" union
2770 : we keep the newest locations in the beginning. */
2771 :
2772 : static int
2773 2004532 : variable_union (variable *src, dataflow_set *set)
2774 : {
2775 2004532 : variable *dst;
2776 2004532 : variable **dstp;
2777 2004532 : int i, j, k;
2778 :
2779 2004532 : dstp = shared_hash_find_slot (set->vars, src->dv);
2780 2004532 : if (!dstp || !*dstp)
2781 : {
2782 1080239 : src->refcount++;
2783 :
2784 1080239 : dst_can_be_shared = false;
2785 1080239 : if (!dstp)
2786 1 : dstp = shared_hash_find_slot_unshare (&set->vars, src->dv, INSERT);
2787 :
2788 1080239 : *dstp = src;
2789 :
2790 : /* Continue traversing the hash table. */
2791 1080239 : return 1;
2792 : }
2793 : else
2794 924293 : dst = *dstp;
2795 :
2796 924293 : gcc_assert (src->n_var_parts);
2797 924293 : gcc_checking_assert (src->onepart == dst->onepart);
2798 :
2799 : /* We can combine one-part variables very efficiently, because their
2800 : entries are in canonical order. */
2801 924293 : if (src->onepart)
2802 : {
2803 0 : location_chain **nodep, *dnode, *snode;
2804 :
2805 0 : gcc_assert (src->n_var_parts == 1
2806 : && dst->n_var_parts == 1);
2807 :
2808 0 : snode = src->var_part[0].loc_chain;
2809 0 : gcc_assert (snode);
2810 :
2811 0 : restart_onepart_unshared:
2812 0 : nodep = &dst->var_part[0].loc_chain;
2813 0 : dnode = *nodep;
2814 0 : gcc_assert (dnode);
2815 :
2816 0 : while (snode)
2817 : {
2818 0 : int r = dnode ? loc_cmp (dnode->loc, snode->loc) : 1;
2819 :
2820 0 : if (r > 0)
2821 : {
2822 0 : location_chain *nnode;
2823 :
2824 0 : if (shared_var_p (dst, set->vars))
2825 : {
2826 0 : dstp = unshare_variable (set, dstp, dst,
2827 : VAR_INIT_STATUS_INITIALIZED);
2828 0 : dst = *dstp;
2829 0 : goto restart_onepart_unshared;
2830 : }
2831 :
2832 0 : *nodep = nnode = new location_chain;
2833 0 : nnode->loc = snode->loc;
2834 0 : nnode->init = snode->init;
2835 0 : if (!snode->set_src || MEM_P (snode->set_src))
2836 0 : nnode->set_src = NULL;
2837 : else
2838 0 : nnode->set_src = snode->set_src;
2839 0 : nnode->next = dnode;
2840 0 : dnode = nnode;
2841 : }
2842 0 : else if (r == 0)
2843 0 : gcc_checking_assert (rtx_equal_p (dnode->loc, snode->loc));
2844 :
2845 0 : if (r >= 0)
2846 0 : snode = snode->next;
2847 :
2848 0 : nodep = &dnode->next;
2849 0 : dnode = *nodep;
2850 : }
2851 :
2852 : return 1;
2853 : }
2854 :
2855 : gcc_checking_assert (!src->onepart);
2856 :
2857 : /* Count the number of location parts, result is K. */
2858 1287968 : for (i = 0, j = 0, k = 0;
2859 2212261 : i < src->n_var_parts && j < dst->n_var_parts; k++)
2860 : {
2861 1287968 : if (VAR_PART_OFFSET (src, i) == VAR_PART_OFFSET (dst, j))
2862 : {
2863 1252515 : i++;
2864 1252515 : j++;
2865 : }
2866 35453 : else if (VAR_PART_OFFSET (src, i) < VAR_PART_OFFSET (dst, j))
2867 27176 : i++;
2868 : else
2869 8277 : j++;
2870 : }
2871 924293 : k += src->n_var_parts - i;
2872 924293 : k += dst->n_var_parts - j;
2873 :
2874 : /* We track only variables whose size is <= MAX_VAR_PARTS bytes
2875 : thus there are at most MAX_VAR_PARTS different offsets. */
2876 924293 : gcc_checking_assert (dst->onepart ? k == 1 : k <= MAX_VAR_PARTS);
2877 :
2878 924293 : if (dst->n_var_parts != k && shared_var_p (dst, set->vars))
2879 : {
2880 52417 : dstp = unshare_variable (set, dstp, dst, VAR_INIT_STATUS_UNKNOWN);
2881 52417 : dst = *dstp;
2882 : }
2883 :
2884 924293 : i = src->n_var_parts - 1;
2885 924293 : j = dst->n_var_parts - 1;
2886 924293 : dst->n_var_parts = k;
2887 :
2888 2245311 : for (k--; k >= 0; k--)
2889 : {
2890 1321018 : location_chain *node, *node2;
2891 :
2892 1321018 : if (i >= 0 && j >= 0
2893 1321018 : && VAR_PART_OFFSET (src, i) == VAR_PART_OFFSET (dst, j))
2894 : {
2895 : /* Compute the "sorted" union of the chains, i.e. the locations which
2896 : are in both chains go first, they are sorted by the sum of
2897 : positions in the chains. */
2898 1252515 : int dst_l, src_l;
2899 1252515 : int ii, jj, n;
2900 1252515 : struct variable_union_info *vui;
2901 :
2902 : /* If DST is shared compare the location chains.
2903 : If they are different we will modify the chain in DST with
2904 : high probability so make a copy of DST. */
2905 1252515 : if (shared_var_p (dst, set->vars))
2906 : {
2907 1168692 : for (node = src->var_part[i].loc_chain,
2908 2463320 : node2 = dst->var_part[j].loc_chain; node && node2;
2909 1294628 : node = node->next, node2 = node2->next)
2910 : {
2911 1889369 : if (!((REG_P (node2->loc)
2912 763589 : && REG_P (node->loc)
2913 761699 : && REGNO (node2->loc) == REGNO (node->loc))
2914 571175 : || rtx_equal_p (node2->loc, node->loc)))
2915 : {
2916 23566 : if (node2->init < node->init)
2917 1757 : node2->init = node->init;
2918 : break;
2919 : }
2920 : }
2921 1168692 : if (node || node2)
2922 : {
2923 71013 : dstp = unshare_variable (set, dstp, dst,
2924 : VAR_INIT_STATUS_UNKNOWN);
2925 71013 : dst = (variable *)*dstp;
2926 : }
2927 : }
2928 :
2929 1252515 : src_l = 0;
2930 2759160 : for (node = src->var_part[i].loc_chain; node; node = node->next)
2931 1506645 : src_l++;
2932 1252515 : dst_l = 0;
2933 2693532 : for (node = dst->var_part[j].loc_chain; node; node = node->next)
2934 1441017 : dst_l++;
2935 :
2936 1252515 : if (dst_l == 1)
2937 : {
2938 : /* The most common case, much simpler, no qsort is needed. */
2939 1084260 : location_chain *dstnode = dst->var_part[j].loc_chain;
2940 1084260 : dst->var_part[k].loc_chain = dstnode;
2941 1084260 : VAR_PART_OFFSET (dst, k) = VAR_PART_OFFSET (dst, j);
2942 1084260 : node2 = dstnode;
2943 2238390 : for (node = src->var_part[i].loc_chain; node; node = node->next)
2944 1572928 : if (!((REG_P (dstnode->loc)
2945 789966 : && REG_P (node->loc)
2946 788389 : && REGNO (dstnode->loc) == REGNO (node->loc))
2947 418798 : || rtx_equal_p (dstnode->loc, node->loc)))
2948 : {
2949 78937 : location_chain *new_node;
2950 :
2951 : /* Copy the location from SRC. */
2952 78937 : new_node = new location_chain;
2953 78937 : new_node->loc = node->loc;
2954 78937 : new_node->init = node->init;
2955 78937 : if (!node->set_src || MEM_P (node->set_src))
2956 76127 : new_node->set_src = NULL;
2957 : else
2958 2810 : new_node->set_src = node->set_src;
2959 78937 : node2->next = new_node;
2960 78937 : node2 = new_node;
2961 : }
2962 1084260 : node2->next = NULL;
2963 : }
2964 : else
2965 : {
2966 168255 : if (src_l + dst_l > vui_allocated)
2967 : {
2968 11070 : vui_allocated = MAX (vui_allocated * 2, src_l + dst_l);
2969 11070 : vui_vec = XRESIZEVEC (struct variable_union_info, vui_vec,
2970 : vui_allocated);
2971 : }
2972 168255 : vui = vui_vec;
2973 :
2974 : /* Fill in the locations from DST. */
2975 525012 : for (node = dst->var_part[j].loc_chain, jj = 0; node;
2976 356757 : node = node->next, jj++)
2977 : {
2978 356757 : vui[jj].lc = node;
2979 356757 : vui[jj].pos_dst = jj;
2980 :
2981 : /* Pos plus value larger than a sum of 2 valid positions. */
2982 356757 : vui[jj].pos = jj + src_l + dst_l;
2983 : }
2984 :
2985 : /* Fill in the locations from SRC. */
2986 168255 : n = dst_l;
2987 520770 : for (node = src->var_part[i].loc_chain, ii = 0; node;
2988 352515 : node = node->next, ii++)
2989 : {
2990 : /* Find location from NODE. */
2991 576926 : for (jj = 0; jj < dst_l; jj++)
2992 : {
2993 562439 : if ((REG_P (vui[jj].lc->loc)
2994 155355 : && REG_P (node->loc)
2995 128104 : && REGNO (vui[jj].lc->loc) == REGNO (node->loc))
2996 625068 : || rtx_equal_p (vui[jj].lc->loc, node->loc))
2997 : {
2998 338028 : vui[jj].pos = jj + ii;
2999 338028 : break;
3000 : }
3001 : }
3002 352515 : if (jj >= dst_l) /* The location has not been found. */
3003 : {
3004 14487 : location_chain *new_node;
3005 :
3006 : /* Copy the location from SRC. */
3007 14487 : new_node = new location_chain;
3008 14487 : new_node->loc = node->loc;
3009 14487 : new_node->init = node->init;
3010 14487 : if (!node->set_src || MEM_P (node->set_src))
3011 11541 : new_node->set_src = NULL;
3012 : else
3013 2946 : new_node->set_src = node->set_src;
3014 14487 : vui[n].lc = new_node;
3015 14487 : vui[n].pos_dst = src_l + dst_l;
3016 14487 : vui[n].pos = ii + src_l + dst_l;
3017 14487 : n++;
3018 : }
3019 : }
3020 :
3021 168255 : if (dst_l == 2)
3022 : {
3023 : /* Special case still very common case. For dst_l == 2
3024 : all entries dst_l ... n-1 are sorted, with for i >= dst_l
3025 : vui[i].pos == i + src_l + dst_l. */
3026 148496 : if (vui[0].pos > vui[1].pos)
3027 : {
3028 : /* Order should be 1, 0, 2... */
3029 4116 : dst->var_part[k].loc_chain = vui[1].lc;
3030 4116 : vui[1].lc->next = vui[0].lc;
3031 4116 : if (n >= 3)
3032 : {
3033 370 : vui[0].lc->next = vui[2].lc;
3034 370 : vui[n - 1].lc->next = NULL;
3035 : }
3036 : else
3037 3746 : vui[0].lc->next = NULL;
3038 : ii = 3;
3039 : }
3040 : else
3041 : {
3042 144380 : dst->var_part[k].loc_chain = vui[0].lc;
3043 144380 : if (n >= 3 && vui[2].pos < vui[1].pos)
3044 : {
3045 : /* Order should be 0, 2, 1, 3... */
3046 549 : vui[0].lc->next = vui[2].lc;
3047 549 : vui[2].lc->next = vui[1].lc;
3048 549 : if (n >= 4)
3049 : {
3050 25 : vui[1].lc->next = vui[3].lc;
3051 25 : vui[n - 1].lc->next = NULL;
3052 : }
3053 : else
3054 524 : vui[1].lc->next = NULL;
3055 : ii = 4;
3056 : }
3057 : else
3058 : {
3059 : /* Order should be 0, 1, 2... */
3060 143831 : ii = 1;
3061 143831 : vui[n - 1].lc->next = NULL;
3062 : }
3063 : }
3064 305187 : for (; ii < n; ii++)
3065 156691 : vui[ii - 1].lc->next = vui[ii].lc;
3066 : }
3067 : else
3068 : {
3069 19759 : qsort (vui, n, sizeof (struct variable_union_info),
3070 : variable_union_info_cmp_pos);
3071 :
3072 : /* Reconnect the nodes in sorted order. */
3073 80207 : for (ii = 1; ii < n; ii++)
3074 40689 : vui[ii - 1].lc->next = vui[ii].lc;
3075 19759 : vui[n - 1].lc->next = NULL;
3076 19759 : dst->var_part[k].loc_chain = vui[0].lc;
3077 : }
3078 :
3079 168255 : VAR_PART_OFFSET (dst, k) = VAR_PART_OFFSET (dst, j);
3080 : }
3081 1252515 : i--;
3082 1252515 : j--;
3083 : }
3084 68503 : else if ((i >= 0 && j >= 0
3085 33050 : && VAR_PART_OFFSET (src, i) < VAR_PART_OFFSET (dst, j))
3086 93744 : || i < 0)
3087 : {
3088 16086 : dst->var_part[k] = dst->var_part[j];
3089 16086 : j--;
3090 : }
3091 52417 : else if ((i >= 0 && j >= 0
3092 25241 : && VAR_PART_OFFSET (src, i) > VAR_PART_OFFSET (dst, j))
3093 52417 : || j < 0)
3094 : {
3095 52417 : location_chain **nextp;
3096 :
3097 : /* Copy the chain from SRC. */
3098 52417 : nextp = &dst->var_part[k].loc_chain;
3099 112497 : for (node = src->var_part[i].loc_chain; node; node = node->next)
3100 : {
3101 60080 : location_chain *new_lc;
3102 :
3103 60080 : new_lc = new location_chain;
3104 60080 : new_lc->next = NULL;
3105 60080 : new_lc->init = node->init;
3106 60080 : if (!node->set_src || MEM_P (node->set_src))
3107 58324 : new_lc->set_src = NULL;
3108 : else
3109 1756 : new_lc->set_src = node->set_src;
3110 60080 : new_lc->loc = node->loc;
3111 :
3112 60080 : *nextp = new_lc;
3113 60080 : nextp = &new_lc->next;
3114 : }
3115 :
3116 52417 : VAR_PART_OFFSET (dst, k) = VAR_PART_OFFSET (src, i);
3117 52417 : i--;
3118 : }
3119 1321018 : dst->var_part[k].cur_loc = NULL;
3120 : }
3121 :
3122 924293 : if (flag_var_tracking_uninit)
3123 2229225 : for (i = 0; i < src->n_var_parts && i < dst->n_var_parts; i++)
3124 : {
3125 1304932 : location_chain *node, *node2;
3126 2871657 : for (node = src->var_part[i].loc_chain; node; node = node->next)
3127 3780145 : for (node2 = dst->var_part[i].loc_chain; node2; node2 = node2->next)
3128 2213420 : if (rtx_equal_p (node->loc, node2->loc))
3129 : {
3130 1557707 : if (node->init > node2->init)
3131 6526 : node2->init = node->init;
3132 : }
3133 : }
3134 :
3135 : /* Continue traversing the hash table. */
3136 : return 1;
3137 : }
3138 :
3139 : /* Compute union of dataflow sets SRC and DST and store it to DST. */
3140 :
3141 : static void
3142 122 : dataflow_set_union (dataflow_set *dst, dataflow_set *src)
3143 : {
3144 122 : int i;
3145 :
3146 11346 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3147 11224 : attrs_list_union (&dst->regs[i], src->regs[i]);
3148 :
3149 122 : if (dst->vars == empty_shared_hash)
3150 : {
3151 98 : shared_hash_destroy (dst->vars);
3152 98 : dst->vars = shared_hash_copy (src->vars);
3153 : }
3154 : else
3155 : {
3156 24 : variable_iterator_type hi;
3157 24 : variable *var;
3158 :
3159 124 : FOR_EACH_HASH_TABLE_ELEMENT (*shared_hash_htab (src->vars),
3160 : var, variable, hi)
3161 38 : variable_union (var, dst);
3162 : }
3163 122 : }
3164 :
3165 : /* Whether the value is currently being expanded. */
3166 : #define VALUE_RECURSED_INTO(x) \
3167 : (RTL_FLAG_CHECK2 ("VALUE_RECURSED_INTO", (x), VALUE, DEBUG_EXPR)->used)
3168 :
3169 : /* Whether no expansion was found, saving useless lookups.
3170 : It must only be set when VALUE_CHANGED is clear. */
3171 : #define NO_LOC_P(x) \
3172 : (RTL_FLAG_CHECK2 ("NO_LOC_P", (x), VALUE, DEBUG_EXPR)->return_val)
3173 :
3174 : /* Whether cur_loc in the value needs to be (re)computed. */
3175 : #define VALUE_CHANGED(x) \
3176 : (RTL_FLAG_CHECK1 ("VALUE_CHANGED", (x), VALUE)->frame_related)
3177 : /* Whether cur_loc in the decl needs to be (re)computed. */
3178 : #define DECL_CHANGED(x) TREE_VISITED (x)
3179 :
3180 : /* Record (if NEWV) that DV needs to have its cur_loc recomputed. For
3181 : user DECLs, this means they're in changed_variables. Values and
3182 : debug exprs may be left with this flag set if no user variable
3183 : requires them to be evaluated. */
3184 :
3185 : static inline void
3186 310595444 : set_dv_changed (decl_or_value dv, bool newv)
3187 : {
3188 310595444 : switch (dv_onepart_p (dv))
3189 : {
3190 168946020 : case ONEPART_VALUE:
3191 168946020 : if (newv)
3192 136969948 : NO_LOC_P (dv_as_value (dv)) = false;
3193 168946020 : VALUE_CHANGED (dv_as_value (dv)) = newv;
3194 168946020 : break;
3195 :
3196 19843141 : case ONEPART_DEXPR:
3197 19843141 : if (newv)
3198 14512229 : NO_LOC_P (DECL_RTL_KNOWN_SET (dv_as_decl (dv))) = false;
3199 : /* Fall through. */
3200 :
3201 141649424 : default:
3202 141649424 : DECL_CHANGED (dv_as_decl (dv)) = newv;
3203 141649424 : break;
3204 : }
3205 310595444 : }
3206 :
3207 : /* Return true if DV needs to have its cur_loc recomputed. */
3208 :
3209 : static inline bool
3210 144099194 : dv_changed_p (decl_or_value dv)
3211 : {
3212 144099194 : return (dv_is_value_p (dv)
3213 78913172 : ? VALUE_CHANGED (dv_as_value (dv))
3214 65186022 : : DECL_CHANGED (dv_as_decl (dv)));
3215 : }
3216 :
3217 : /* Return a location list node whose loc is rtx_equal to LOC, in the
3218 : location list of a one-part variable or value VAR, or in that of
3219 : any values recursively mentioned in the location lists. VARS must
3220 : be in star-canonical form. */
3221 :
3222 : static location_chain *
3223 15438962 : find_loc_in_1pdv (rtx loc, variable *var, variable_table_type *vars)
3224 : {
3225 21200584 : location_chain *node;
3226 21200584 : enum rtx_code loc_code;
3227 :
3228 21200584 : if (!var)
3229 : return NULL;
3230 :
3231 20469273 : gcc_checking_assert (var->onepart);
3232 :
3233 20469273 : if (!var->n_var_parts)
3234 : return NULL;
3235 :
3236 20469273 : gcc_checking_assert (var->dv != loc);
3237 :
3238 20469273 : loc_code = GET_CODE (loc);
3239 39146096 : for (node = var->var_part[0].loc_chain; node; node = node->next)
3240 : {
3241 30527778 : decl_or_value dv;
3242 30527778 : variable *rvar;
3243 :
3244 30527778 : if (GET_CODE (node->loc) != loc_code)
3245 : {
3246 16915704 : if (GET_CODE (node->loc) != VALUE)
3247 31889812 : continue;
3248 : }
3249 13612074 : else if (loc == node->loc)
3250 6089333 : return node;
3251 8919390 : else if (loc_code != VALUE)
3252 : {
3253 2824954 : if (rtx_equal_p (loc, node->loc))
3254 : return node;
3255 2206222 : continue;
3256 : }
3257 :
3258 : /* Since we're in star-canonical form, we don't need to visit
3259 : non-canonical nodes: one-part variables and non-canonical
3260 : values would only point back to the canonical node. */
3261 9797151 : if (dv_is_value_p (var->dv)
3262 4957299 : && !canon_value_cmp (node->loc, dv_as_value (var->dv)))
3263 : {
3264 : /* Skip all subsequent VALUEs. */
3265 17349874 : while (node->next && GET_CODE (node->next->loc) == VALUE)
3266 : {
3267 14092262 : node = node->next;
3268 14092262 : gcc_checking_assert (!canon_value_cmp (node->loc,
3269 : dv_as_value (var->dv)));
3270 14092262 : if (loc == node->loc)
3271 : return node;
3272 : }
3273 3257612 : continue;
3274 : }
3275 :
3276 5761622 : gcc_checking_assert (node == var->var_part[0].loc_chain);
3277 5761622 : gcc_checking_assert (!node->next);
3278 :
3279 5761622 : dv = dv_from_value (node->loc);
3280 5761622 : rvar = vars->find_with_hash (dv, dv_htab_hash (dv));
3281 5761622 : return find_loc_in_1pdv (loc, rvar, vars);
3282 : }
3283 :
3284 : /* ??? Gotta look in cselib_val locations too. */
3285 :
3286 : return NULL;
3287 : }
3288 :
3289 : /* Hash table iteration argument passed to variable_merge. */
3290 : struct dfset_merge
3291 : {
3292 : /* The set in which the merge is to be inserted. */
3293 : dataflow_set *dst;
3294 : /* The set that we're iterating in. */
3295 : dataflow_set *cur;
3296 : /* The set that may contain the other dv we are to merge with. */
3297 : dataflow_set *src;
3298 : /* Number of onepart dvs in src. */
3299 : int src_onepart_cnt;
3300 : };
3301 :
3302 : /* Insert LOC in *DNODE, if it's not there yet. The list must be in
3303 : loc_cmp order, and it is maintained as such. */
3304 :
3305 : static void
3306 42104477 : insert_into_intersection (location_chain **nodep, rtx loc,
3307 : enum var_init_status status)
3308 : {
3309 42104477 : location_chain *node;
3310 42104477 : int r;
3311 :
3312 309181962 : for (node = *nodep; node; nodep = &node->next, node = *nodep)
3313 297066137 : if ((r = loc_cmp (node->loc, loc)) == 0)
3314 : {
3315 23822830 : node->init = MIN (node->init, status);
3316 23822830 : return;
3317 : }
3318 273243307 : else if (r > 0)
3319 : break;
3320 :
3321 18281647 : node = new location_chain;
3322 :
3323 18281647 : node->loc = loc;
3324 18281647 : node->set_src = NULL;
3325 18281647 : node->init = status;
3326 18281647 : node->next = *nodep;
3327 18281647 : *nodep = node;
3328 : }
3329 :
3330 : /* Insert in DEST the intersection of the locations present in both
3331 : S1NODE and S2VAR, directly or indirectly. S1NODE is from a
3332 : variable in DSM->cur, whereas S2VAR is from DSM->src. dvar is in
3333 : DSM->dst. */
3334 :
3335 : static void
3336 37517292 : intersect_loc_chains (rtx val, location_chain **dest, struct dfset_merge *dsm,
3337 : location_chain *s1node, variable *s2var)
3338 : {
3339 37517292 : dataflow_set *s1set = dsm->cur;
3340 37517292 : dataflow_set *s2set = dsm->src;
3341 37517292 : location_chain *found;
3342 :
3343 37517292 : if (s2var)
3344 : {
3345 37517292 : location_chain *s2node;
3346 :
3347 37517292 : gcc_checking_assert (s2var->onepart);
3348 :
3349 37517292 : if (s2var->n_var_parts)
3350 : {
3351 37517292 : s2node = s2var->var_part[0].loc_chain;
3352 :
3353 73532436 : for (; s1node && s2node;
3354 36015144 : s1node = s1node->next, s2node = s2node->next)
3355 48318083 : if (s1node->loc != s2node->loc)
3356 : break;
3357 36015144 : else if (s1node->loc == val)
3358 0 : continue;
3359 : else
3360 36015144 : insert_into_intersection (dest, s1node->loc,
3361 36015144 : MIN (s1node->init, s2node->init));
3362 : }
3363 : }
3364 :
3365 55760261 : for (; s1node; s1node = s1node->next)
3366 : {
3367 18242969 : if (s1node->loc == val)
3368 2804007 : continue;
3369 :
3370 15438962 : if ((found = find_loc_in_1pdv (s1node->loc, s2var,
3371 : shared_hash_htab (s2set->vars))))
3372 : {
3373 6089333 : insert_into_intersection (dest, s1node->loc,
3374 6089333 : MIN (s1node->init, found->init));
3375 6089333 : continue;
3376 : }
3377 :
3378 9349629 : if (GET_CODE (s1node->loc) == VALUE
3379 9349629 : && !VALUE_RECURSED_INTO (s1node->loc))
3380 : {
3381 5506001 : decl_or_value dv = dv_from_value (s1node->loc);
3382 5506001 : variable *svar = shared_hash_find (s1set->vars, dv);
3383 5506001 : if (svar)
3384 : {
3385 4957494 : if (svar->n_var_parts == 1)
3386 : {
3387 4957494 : VALUE_RECURSED_INTO (s1node->loc) = true;
3388 4957494 : intersect_loc_chains (val, dest, dsm,
3389 : svar->var_part[0].loc_chain,
3390 : s2var);
3391 4957494 : VALUE_RECURSED_INTO (s1node->loc) = false;
3392 : }
3393 : }
3394 : }
3395 :
3396 : /* ??? gotta look in cselib_val locations too. */
3397 :
3398 : /* ??? if the location is equivalent to any location in src,
3399 : searched recursively
3400 :
3401 : add to dst the values needed to represent the equivalence
3402 :
3403 : telling whether locations S is equivalent to another dv's
3404 : location list:
3405 :
3406 : for each location D in the list
3407 :
3408 : if S and D satisfy rtx_equal_p, then it is present
3409 :
3410 : else if D is a value, recurse without cycles
3411 :
3412 : else if S and D have the same CODE and MODE
3413 :
3414 : for each operand oS and the corresponding oD
3415 :
3416 : if oS and oD are not equivalent, then S an D are not equivalent
3417 :
3418 : else if they are RTX vectors
3419 :
3420 : if any vector oS element is not equivalent to its respective oD,
3421 : then S and D are not equivalent
3422 :
3423 : */
3424 :
3425 :
3426 : }
3427 37517292 : }
3428 :
3429 : /* Return -1 if X should be before Y in a location list for a 1-part
3430 : variable, 1 if Y should be before X, and 0 if they're equivalent
3431 : and should not appear in the list. */
3432 :
3433 : static int
3434 519093394 : loc_cmp (rtx x, rtx y)
3435 : {
3436 535458156 : int i, j, r;
3437 535458156 : RTX_CODE code = GET_CODE (x);
3438 535458156 : const char *fmt;
3439 :
3440 535458156 : if (x == y)
3441 : return 0;
3442 :
3443 411736189 : if (REG_P (x))
3444 : {
3445 50287794 : if (!REG_P (y))
3446 : return -1;
3447 4176018 : gcc_assert (GET_MODE (x) == GET_MODE (y));
3448 4176018 : if (REGNO (x) == REGNO (y))
3449 : return 0;
3450 4020699 : else if (REGNO (x) < REGNO (y))
3451 : return -1;
3452 : else
3453 : return 1;
3454 : }
3455 :
3456 361448395 : if (REG_P (y))
3457 : return 1;
3458 :
3459 355526972 : if (MEM_P (x))
3460 : {
3461 28853168 : if (!MEM_P (y))
3462 : return -1;
3463 16364762 : gcc_assert (GET_MODE (x) == GET_MODE (y));
3464 16364762 : return loc_cmp (XEXP (x, 0), XEXP (y, 0));
3465 : }
3466 :
3467 326673804 : if (MEM_P (y))
3468 : return 1;
3469 :
3470 324667776 : if (GET_CODE (x) == VALUE)
3471 : {
3472 324317991 : if (GET_CODE (y) != VALUE)
3473 : return -1;
3474 : /* Don't assert the modes are the same, that is true only
3475 : when not recursing. (subreg:QI (value:SI 1:1) 0)
3476 : and (subreg:QI (value:DI 2:2) 0) can be compared,
3477 : even when the modes are different. */
3478 395210426 : if (canon_value_cmp (x, y))
3479 : return -1;
3480 : else
3481 : return 1;
3482 : }
3483 :
3484 349785 : if (GET_CODE (y) == VALUE)
3485 : return 1;
3486 :
3487 : /* Entry value is the least preferable kind of expression. */
3488 90706 : if (GET_CODE (x) == ENTRY_VALUE)
3489 : {
3490 0 : if (GET_CODE (y) != ENTRY_VALUE)
3491 : return 1;
3492 0 : gcc_assert (GET_MODE (x) == GET_MODE (y));
3493 0 : return loc_cmp (ENTRY_VALUE_EXP (x), ENTRY_VALUE_EXP (y));
3494 : }
3495 :
3496 90706 : if (GET_CODE (y) == ENTRY_VALUE)
3497 : return -1;
3498 :
3499 90706 : if (GET_CODE (x) == GET_CODE (y))
3500 : /* Compare operands below. */;
3501 10279 : else if (GET_CODE (x) < GET_CODE (y))
3502 : return -1;
3503 : else
3504 : return 1;
3505 :
3506 80427 : gcc_assert (GET_MODE (x) == GET_MODE (y));
3507 :
3508 80427 : if (GET_CODE (x) == DEBUG_EXPR)
3509 : {
3510 0 : if (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x))
3511 0 : < DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (y)))
3512 : return -1;
3513 0 : gcc_checking_assert (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x))
3514 : > DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (y)));
3515 : return 1;
3516 : }
3517 :
3518 80427 : fmt = GET_RTX_FORMAT (code);
3519 91927 : for (i = 0; i < GET_RTX_LENGTH (code); i++)
3520 86237 : switch (fmt[i])
3521 : {
3522 70285 : case 'w':
3523 70285 : if (XWINT (x, i) == XWINT (y, i))
3524 : break;
3525 70121 : else if (XWINT (x, i) < XWINT (y, i))
3526 : return -1;
3527 : else
3528 : return 1;
3529 :
3530 0 : case 'n':
3531 0 : case 'i':
3532 0 : if (XINT (x, i) == XINT (y, i))
3533 : break;
3534 0 : else if (XINT (x, i) < XINT (y, i))
3535 : return -1;
3536 : else
3537 : return 1;
3538 :
3539 0 : case 'L':
3540 0 : if (XLOC (x, i) == XLOC (y, i))
3541 : break;
3542 0 : else if (XLOC (x, i) < XLOC (y, i))
3543 : return -1;
3544 : else
3545 : return 1;
3546 :
3547 0 : case 'p':
3548 11500 : r = compare_sizes_for_sort (SUBREG_BYTE (x), SUBREG_BYTE (y));
3549 0 : if (r != 0)
3550 0 : return r;
3551 : break;
3552 :
3553 0 : case 'V':
3554 0 : case 'E':
3555 : /* Compare the vector length first. */
3556 0 : if (XVECLEN (x, i) == XVECLEN (y, i))
3557 : /* Compare the vectors elements. */;
3558 0 : else if (XVECLEN (x, i) < XVECLEN (y, i))
3559 : return -1;
3560 : else
3561 : return 1;
3562 :
3563 0 : for (j = 0; j < XVECLEN (x, i); j++)
3564 0 : if ((r = loc_cmp (XVECEXP (x, i, j),
3565 0 : XVECEXP (y, i, j))))
3566 : return r;
3567 : break;
3568 :
3569 0 : case 'e':
3570 0 : if ((r = loc_cmp (XEXP (x, i), XEXP (y, i))))
3571 : return r;
3572 : break;
3573 :
3574 10270 : case 'S':
3575 10270 : case 's':
3576 10270 : if (XSTR (x, i) == XSTR (y, i))
3577 : break;
3578 4616 : if (!XSTR (x, i))
3579 : return -1;
3580 4616 : if (!XSTR (y, i))
3581 : return 1;
3582 4616 : if ((r = strcmp (XSTR (x, i), XSTR (y, i))) == 0)
3583 : break;
3584 4616 : else if (r < 0)
3585 : return -1;
3586 : else
3587 : return 1;
3588 :
3589 : case 'u':
3590 : /* These are just backpointers, so they don't matter. */
3591 : break;
3592 :
3593 : case '0':
3594 : case 't':
3595 : break;
3596 :
3597 : /* It is believed that rtx's at this level will never
3598 : contain anything but integers and other rtx's,
3599 : except for within LABEL_REFs and SYMBOL_REFs. */
3600 0 : default:
3601 0 : gcc_unreachable ();
3602 : }
3603 5690 : if (CONST_WIDE_INT_P (x))
3604 : {
3605 : /* Compare the vector length first. */
3606 8 : if (CONST_WIDE_INT_NUNITS (x) >= CONST_WIDE_INT_NUNITS (y))
3607 : return 1;
3608 : else if (CONST_WIDE_INT_NUNITS (x) < CONST_WIDE_INT_NUNITS (y))
3609 : return -1;
3610 :
3611 : /* Compare the vectors elements. */;
3612 : for (j = CONST_WIDE_INT_NUNITS (x) - 1; j >= 0 ; j--)
3613 : {
3614 : if (CONST_WIDE_INT_ELT (x, j) < CONST_WIDE_INT_ELT (y, j))
3615 : return -1;
3616 : if (CONST_WIDE_INT_ELT (x, j) > CONST_WIDE_INT_ELT (y, j))
3617 : return 1;
3618 : }
3619 : }
3620 :
3621 : return 0;
3622 : }
3623 :
3624 : /* Check the order of entries in one-part variables. */
3625 :
3626 : int
3627 507282973 : canonicalize_loc_order_check (variable **slot,
3628 : dataflow_set *data ATTRIBUTE_UNUSED)
3629 : {
3630 507282973 : variable *var = *slot;
3631 507282973 : location_chain *node, *next;
3632 :
3633 : #ifdef ENABLE_RTL_CHECKING
3634 : int i;
3635 : for (i = 0; i < var->n_var_parts; i++)
3636 : gcc_assert (var->var_part[0].cur_loc == NULL);
3637 : gcc_assert (!var->in_changed_variables);
3638 : #endif
3639 :
3640 507282973 : if (!var->onepart)
3641 : return 1;
3642 :
3643 504609611 : gcc_assert (var->n_var_parts == 1);
3644 504609611 : node = var->var_part[0].loc_chain;
3645 504609611 : gcc_assert (node);
3646 :
3647 597864891 : while ((next = node->next))
3648 : {
3649 93255280 : gcc_assert (loc_cmp (node->loc, next->loc) < 0);
3650 : node = next;
3651 : }
3652 :
3653 : return 1;
3654 : }
3655 :
3656 : /* Mark with VALUE_RECURSED_INTO values that have neighbors that are
3657 : more likely to be chosen as canonical for an equivalence set.
3658 : Ensure less likely values can reach more likely neighbors, making
3659 : the connections bidirectional. */
3660 :
3661 : int
3662 402509284 : canonicalize_values_mark (variable **slot, dataflow_set *set)
3663 : {
3664 402509284 : variable *var = *slot;
3665 402509284 : decl_or_value dv = var->dv;
3666 402509284 : rtx val;
3667 402509284 : location_chain *node;
3668 :
3669 402509284 : if (!dv_is_value_p (dv))
3670 : return 1;
3671 :
3672 245060912 : gcc_checking_assert (var->n_var_parts == 1);
3673 :
3674 245060912 : val = dv_as_value (dv);
3675 :
3676 567298093 : for (node = var->var_part[0].loc_chain; node; node = node->next)
3677 322237181 : if (GET_CODE (node->loc) == VALUE)
3678 : {
3679 137765562 : if (canon_value_cmp (node->loc, val))
3680 68882781 : VALUE_RECURSED_INTO (val) = true;
3681 : else
3682 : {
3683 68882781 : decl_or_value odv = dv_from_value (node->loc);
3684 68882781 : variable **oslot;
3685 68882781 : oslot = shared_hash_find_slot_noinsert (set->vars, odv);
3686 :
3687 68882781 : set_slot_part (set, val, oslot, odv, 0,
3688 : node->init, NULL_RTX);
3689 :
3690 68882781 : VALUE_RECURSED_INTO (node->loc) = true;
3691 : }
3692 : }
3693 :
3694 : return 1;
3695 : }
3696 :
3697 : /* Remove redundant entries from equivalence lists in onepart
3698 : variables, canonicalizing equivalence sets into star shapes. */
3699 :
3700 : int
3701 591085124 : canonicalize_values_star (variable **slot, dataflow_set *set)
3702 : {
3703 591085124 : variable *var = *slot;
3704 591085124 : decl_or_value dv = var->dv;
3705 591085124 : location_chain *node;
3706 591085124 : decl_or_value cdv;
3707 591085124 : rtx val, cval;
3708 591085124 : variable **cslot;
3709 591085124 : bool has_value;
3710 591085124 : bool has_marks;
3711 :
3712 591085124 : if (!var->onepart)
3713 : return 1;
3714 :
3715 588411762 : gcc_checking_assert (var->n_var_parts == 1);
3716 :
3717 588411762 : if (dv_is_value_p (dv))
3718 : {
3719 389219210 : cval = dv_as_value (dv);
3720 389219210 : if (!VALUE_RECURSED_INTO (cval))
3721 : return 1;
3722 151376223 : VALUE_RECURSED_INTO (cval) = false;
3723 : }
3724 : else
3725 : cval = NULL_RTX;
3726 :
3727 423467595 : restart:
3728 423467595 : val = cval;
3729 423467595 : has_value = false;
3730 423467595 : has_marks = false;
3731 :
3732 423467595 : gcc_assert (var->n_var_parts == 1);
3733 :
3734 1908958832 : for (node = var->var_part[0].loc_chain; node; node = node->next)
3735 1485491237 : if (GET_CODE (node->loc) == VALUE)
3736 : {
3737 1369546556 : has_value = true;
3738 1369546556 : if (VALUE_RECURSED_INTO (node->loc))
3739 333404775 : has_marks = true;
3740 2855037793 : if (canon_value_cmp (node->loc, cval))
3741 : cval = node->loc;
3742 : }
3743 :
3744 423467595 : if (!has_value)
3745 : return 1;
3746 :
3747 350159832 : if (cval == val)
3748 : {
3749 62366337 : if (!has_marks || dv_is_decl_p (dv))
3750 : return 1;
3751 :
3752 : /* Keep it marked so that we revisit it, either after visiting a
3753 : child node, or after visiting a new parent that might be
3754 : found out. */
3755 23877908 : VALUE_RECURSED_INTO (val) = true;
3756 :
3757 300262449 : for (node = var->var_part[0].loc_chain; node; node = node->next)
3758 300262449 : if (GET_CODE (node->loc) == VALUE
3759 300262449 : && VALUE_RECURSED_INTO (node->loc))
3760 : {
3761 : cval = node->loc;
3762 72898820 : restart_with_cval:
3763 72898820 : VALUE_RECURSED_INTO (cval) = false;
3764 72898820 : dv = dv_from_value (cval);
3765 72898820 : slot = shared_hash_find_slot_noinsert (set->vars, dv);
3766 72898820 : if (!slot)
3767 : {
3768 0 : gcc_assert (dv_is_decl_p (var->dv));
3769 : /* The canonical value was reset and dropped.
3770 : Remove it. */
3771 0 : clobber_variable_part (set, NULL, var->dv, 0, NULL);
3772 0 : return 1;
3773 : }
3774 72898820 : var = *slot;
3775 72898820 : gcc_assert (dv_is_value_p (var->dv));
3776 72898820 : if (var->n_var_parts == 0)
3777 : return 1;
3778 72898820 : gcc_assert (var->n_var_parts == 1);
3779 72898820 : goto restart;
3780 : }
3781 :
3782 0 : VALUE_RECURSED_INTO (val) = false;
3783 :
3784 0 : return 1;
3785 : }
3786 :
3787 : /* Push values to the canonical one. */
3788 287793495 : cdv = dv_from_value (cval);
3789 287793495 : cslot = shared_hash_find_slot_noinsert (set->vars, cdv);
3790 :
3791 577443271 : for (node = var->var_part[0].loc_chain; node; node = node->next)
3792 289649776 : if (node->loc != cval)
3793 : {
3794 1856281 : cslot = set_slot_part (set, node->loc, cslot, cdv, 0,
3795 : node->init, NULL_RTX);
3796 1856281 : if (GET_CODE (node->loc) == VALUE)
3797 : {
3798 135110 : decl_or_value ndv = dv_from_value (node->loc);
3799 :
3800 135110 : set_variable_part (set, cval, ndv, 0, node->init, NULL_RTX,
3801 : NO_INSERT);
3802 :
3803 135110 : if (canon_value_cmp (node->loc, val))
3804 : {
3805 : /* If it could have been a local minimum, it's not any more,
3806 : since it's now neighbor to cval, so it may have to push
3807 : to it. Conversely, if it wouldn't have prevailed over
3808 : val, then whatever mark it has is fine: if it was to
3809 : push, it will now push to a more canonical node, but if
3810 : it wasn't, then it has already pushed any values it might
3811 : have to. */
3812 71934 : VALUE_RECURSED_INTO (node->loc) = true;
3813 : /* Make sure we visit node->loc by ensuring we cval is
3814 : visited too. */
3815 71934 : VALUE_RECURSED_INTO (cval) = true;
3816 : }
3817 63176 : else if (!VALUE_RECURSED_INTO (node->loc))
3818 : /* If we have no need to "recurse" into this node, it's
3819 : already "canonicalized", so drop the link to the old
3820 : parent. */
3821 26825 : clobber_variable_part (set, cval, ndv, 0, NULL);
3822 : }
3823 1721171 : else if (GET_CODE (node->loc) == REG)
3824 : {
3825 940624 : attrs *list = set->regs[REGNO (node->loc)], **listp;
3826 :
3827 : /* Change an existing attribute referring to dv so that it
3828 : refers to cdv, removing any duplicate this might
3829 : introduce, and checking that no previous duplicates
3830 : existed, all in a single pass. */
3831 :
3832 953710 : while (list)
3833 : {
3834 953710 : if (list->offset == 0 && (list->dv == dv || list->dv == cdv))
3835 : break;
3836 :
3837 13086 : list = list->next;
3838 : }
3839 :
3840 0 : gcc_assert (list);
3841 940624 : if (list->dv == dv)
3842 : {
3843 940624 : list->dv = cdv;
3844 945315 : for (listp = &list->next; (list = *listp); listp = &list->next)
3845 : {
3846 4691 : if (list->offset)
3847 485 : continue;
3848 :
3849 4206 : if (list->dv == cdv)
3850 : {
3851 0 : *listp = list->next;
3852 0 : delete list;
3853 0 : list = *listp;
3854 0 : break;
3855 : }
3856 :
3857 4206 : gcc_assert (list->dv != dv);
3858 : }
3859 : }
3860 0 : else if (list->dv == cdv)
3861 : {
3862 0 : for (listp = &list->next; (list = *listp); listp = &list->next)
3863 : {
3864 0 : if (list->offset)
3865 0 : continue;
3866 :
3867 0 : if (list->dv == dv)
3868 : {
3869 0 : *listp = list->next;
3870 0 : delete list;
3871 0 : list = *listp;
3872 0 : break;
3873 : }
3874 :
3875 0 : gcc_assert (list->dv != cdv);
3876 : }
3877 : }
3878 : else
3879 0 : gcc_unreachable ();
3880 :
3881 940624 : if (flag_checking)
3882 940624 : while (list)
3883 : {
3884 0 : if (list->offset == 0 && (list->dv == dv || list->dv == cdv))
3885 0 : gcc_unreachable ();
3886 :
3887 0 : list = list->next;
3888 : }
3889 : }
3890 : }
3891 :
3892 287793495 : if (val)
3893 116553698 : set_slot_part (set, val, cslot, cdv, 0,
3894 : VAR_INIT_STATUS_INITIALIZED, NULL_RTX);
3895 :
3896 287793495 : slot = clobber_slot_part (set, cval, slot, 0, NULL);
3897 :
3898 : /* Variable may have been unshared. */
3899 287793495 : var = *slot;
3900 287793495 : gcc_checking_assert (var->n_var_parts && var->var_part[0].loc_chain->loc == cval
3901 : && var->var_part[0].loc_chain->next == NULL);
3902 :
3903 287793495 : if (VALUE_RECURSED_INTO (cval))
3904 49020912 : goto restart_with_cval;
3905 :
3906 : return 1;
3907 : }
3908 :
3909 : /* Bind one-part variables to the canonical value in an equivalence
3910 : set. Not doing this causes dataflow convergence failure in rare
3911 : circumstances, see PR42873. Unfortunately we can't do this
3912 : efficiently as part of canonicalize_values_star, since we may not
3913 : have determined or even seen the canonical value of a set when we
3914 : get to a variable that references another member of the set. */
3915 :
3916 : int
3917 104773738 : canonicalize_vars_star (variable **slot, dataflow_set *set)
3918 : {
3919 104773738 : variable *var = *slot;
3920 104773738 : decl_or_value dv = var->dv;
3921 104773738 : location_chain *node;
3922 104773738 : rtx cval;
3923 104773738 : decl_or_value cdv;
3924 104773738 : variable **cslot;
3925 104773738 : variable *cvar;
3926 104773738 : location_chain *cnode;
3927 :
3928 104773738 : if (!var->onepart || var->onepart == ONEPART_VALUE)
3929 : return 1;
3930 :
3931 43713208 : gcc_assert (var->n_var_parts == 1);
3932 :
3933 43713208 : node = var->var_part[0].loc_chain;
3934 :
3935 43713208 : if (GET_CODE (node->loc) != VALUE)
3936 : return 1;
3937 :
3938 37540372 : gcc_assert (!node->next);
3939 37540372 : cval = node->loc;
3940 :
3941 : /* Push values to the canonical one. */
3942 37540372 : cdv = dv_from_value (cval);
3943 37540372 : cslot = shared_hash_find_slot_noinsert (set->vars, cdv);
3944 37540372 : if (!cslot)
3945 : return 1;
3946 13478012 : cvar = *cslot;
3947 13478012 : gcc_assert (cvar->n_var_parts == 1);
3948 :
3949 13478012 : cnode = cvar->var_part[0].loc_chain;
3950 :
3951 : /* CVAL is canonical if its value list contains non-VALUEs or VALUEs
3952 : that are not “more canonical” than it. */
3953 13478012 : if (GET_CODE (cnode->loc) != VALUE
3954 13478012 : || !canon_value_cmp (cnode->loc, cval))
3955 : return 1;
3956 :
3957 : /* CVAL was found to be non-canonical. Change the variable to point
3958 : to the canonical VALUE. */
3959 551852 : gcc_assert (!cnode->next);
3960 551852 : cval = cnode->loc;
3961 :
3962 551852 : slot = set_slot_part (set, cval, slot, dv, 0,
3963 : node->init, node->set_src);
3964 551852 : clobber_slot_part (set, cval, slot, 0, node->set_src);
3965 :
3966 551852 : return 1;
3967 : }
3968 :
3969 : /* Combine variable or value in *S1SLOT (in DSM->cur) with the
3970 : corresponding entry in DSM->src. Multi-part variables are combined
3971 : with variable_union, whereas onepart dvs are combined with
3972 : intersection. */
3973 :
3974 : static int
3975 171985836 : variable_merge_over_cur (variable *s1var, struct dfset_merge *dsm)
3976 : {
3977 171985836 : dataflow_set *dst = dsm->dst;
3978 171985836 : variable **dstslot;
3979 171985836 : variable *s2var, *dvar = NULL;
3980 171985836 : decl_or_value dv = s1var->dv;
3981 171985836 : onepart_enum onepart = s1var->onepart;
3982 171985836 : rtx val;
3983 171985836 : hashval_t dvhash;
3984 171985836 : location_chain *node, **nodep;
3985 :
3986 : /* If the incoming onepart variable has an empty location list, then
3987 : the intersection will be just as empty. For other variables,
3988 : it's always union. */
3989 171985836 : gcc_checking_assert (s1var->n_var_parts
3990 : && s1var->var_part[0].loc_chain);
3991 :
3992 171985836 : if (!onepart)
3993 1379078 : return variable_union (s1var, dst);
3994 :
3995 170606758 : gcc_checking_assert (s1var->n_var_parts == 1);
3996 :
3997 170606758 : dvhash = dv_htab_hash (dv);
3998 170606758 : if (dv_is_value_p (dv))
3999 101714254 : val = dv_as_value (dv);
4000 : else
4001 : val = NULL;
4002 :
4003 170606758 : s2var = shared_hash_find_1 (dsm->src->vars, dv, dvhash);
4004 170606758 : if (!s2var)
4005 : {
4006 21007381 : dst_can_be_shared = false;
4007 21007381 : return 1;
4008 : }
4009 :
4010 149599377 : dsm->src_onepart_cnt--;
4011 149599377 : gcc_assert (s2var->var_part[0].loc_chain
4012 : && s2var->onepart == onepart
4013 : && s2var->n_var_parts == 1);
4014 :
4015 149599377 : dstslot = shared_hash_find_slot_noinsert_1 (dst->vars, dv, dvhash);
4016 149599377 : if (dstslot)
4017 : {
4018 22487270 : dvar = *dstslot;
4019 22487270 : gcc_assert (dvar->refcount == 1
4020 : && dvar->onepart == onepart
4021 : && dvar->n_var_parts == 1);
4022 22487270 : nodep = &dvar->var_part[0].loc_chain;
4023 : }
4024 : else
4025 : {
4026 127112107 : nodep = &node;
4027 127112107 : node = NULL;
4028 : }
4029 :
4030 149599377 : if (!dstslot && !onepart_variable_different_p (s1var, s2var))
4031 : {
4032 117039579 : dstslot = shared_hash_find_slot_unshare_1 (&dst->vars, dv,
4033 : dvhash, INSERT);
4034 117039579 : *dstslot = dvar = s2var;
4035 117039579 : dvar->refcount++;
4036 : }
4037 : else
4038 : {
4039 32559798 : dst_can_be_shared = false;
4040 :
4041 32559798 : intersect_loc_chains (val, nodep, dsm,
4042 : s1var->var_part[0].loc_chain, s2var);
4043 :
4044 32559798 : if (!dstslot)
4045 : {
4046 10072528 : if (node)
4047 : {
4048 8021953 : dvar = onepart_pool_allocate (onepart);
4049 8021953 : dvar->dv = dv;
4050 8021953 : dvar->refcount = 1;
4051 8021953 : dvar->n_var_parts = 1;
4052 8021953 : dvar->onepart = onepart;
4053 8021953 : dvar->in_changed_variables = false;
4054 8021953 : dvar->var_part[0].loc_chain = node;
4055 8021953 : dvar->var_part[0].cur_loc = NULL;
4056 8021953 : if (onepart)
4057 8021953 : VAR_LOC_1PAUX (dvar) = NULL;
4058 : else
4059 : VAR_PART_OFFSET (dvar, 0) = 0;
4060 :
4061 8021953 : dstslot
4062 8021953 : = shared_hash_find_slot_unshare_1 (&dst->vars, dv, dvhash,
4063 : INSERT);
4064 8021953 : gcc_assert (!*dstslot);
4065 8021953 : *dstslot = dvar;
4066 : }
4067 : else
4068 : return 1;
4069 : }
4070 : }
4071 :
4072 147548802 : nodep = &dvar->var_part[0].loc_chain;
4073 165201579 : while ((node = *nodep))
4074 : {
4075 154620391 : location_chain **nextp = &node->next;
4076 :
4077 154620391 : if (GET_CODE (node->loc) == REG)
4078 : {
4079 17652777 : attrs *list;
4080 :
4081 18515191 : for (list = dst->regs[REGNO (node->loc)]; list; list = list->next)
4082 910406 : if (GET_MODE (node->loc) == GET_MODE (list->loc)
4083 1374986 : && dv_is_value_p (list->dv))
4084 : break;
4085 :
4086 17652777 : if (!list)
4087 17604785 : attrs_list_insert (&dst->regs[REGNO (node->loc)],
4088 : dv, 0, node->loc);
4089 : /* If this value became canonical for another value that had
4090 : this register, we want to leave it alone. */
4091 47992 : else if (dv_as_value (list->dv) != val)
4092 : {
4093 31062 : dstslot = set_slot_part (dst, dv_as_value (list->dv),
4094 : dstslot, dv, 0,
4095 : node->init, NULL_RTX);
4096 31062 : dstslot = delete_slot_part (dst, node->loc, dstslot, 0);
4097 :
4098 : /* Since nextp points into the removed node, we can't
4099 : use it. The pointer to the next node moved to nodep.
4100 : However, if the variable we're walking is unshared
4101 : during our walk, we'll keep walking the location list
4102 : of the previously-shared variable, in which case the
4103 : node won't have been removed, and we'll want to skip
4104 : it. That's why we test *nodep here. */
4105 31062 : if (*nodep != node)
4106 31062 : nextp = nodep;
4107 : }
4108 : }
4109 : else
4110 : /* Canonicalization puts registers first, so we don't have to
4111 : walk it all. */
4112 : break;
4113 : nodep = nextp;
4114 : }
4115 :
4116 147548802 : if (dvar != *dstslot)
4117 : dvar = *dstslot;
4118 147548802 : nodep = &dvar->var_part[0].loc_chain;
4119 :
4120 147548802 : if (val)
4121 : {
4122 : /* Mark all referenced nodes for canonicalization, and make sure
4123 : we have mutual equivalence links. */
4124 83775976 : VALUE_RECURSED_INTO (val) = true;
4125 189746645 : for (node = *nodep; node; node = node->next)
4126 105970669 : if (GET_CODE (node->loc) == VALUE)
4127 : {
4128 47608848 : VALUE_RECURSED_INTO (node->loc) = true;
4129 47608848 : set_variable_part (dst, val, dv_from_value (node->loc), 0,
4130 : node->init, NULL, INSERT);
4131 : }
4132 :
4133 83775976 : dstslot = shared_hash_find_slot_noinsert_1 (dst->vars, dv, dvhash);
4134 83775976 : gcc_assert (*dstslot == dvar);
4135 83775976 : canonicalize_values_star (dstslot, dst);
4136 83775976 : gcc_checking_assert (dstslot
4137 : == shared_hash_find_slot_noinsert_1 (dst->vars,
4138 : dv, dvhash));
4139 83775976 : dvar = *dstslot;
4140 : }
4141 : else
4142 : {
4143 63772826 : bool has_value = false, has_other = false;
4144 :
4145 : /* If we have one value and anything else, we're going to
4146 : canonicalize this, so make sure all values have an entry in
4147 : the table and are marked for canonicalization. */
4148 127612314 : for (node = *nodep; node; node = node->next)
4149 : {
4150 63865614 : if (GET_CODE (node->loc) == VALUE)
4151 : {
4152 : /* If this was marked during register canonicalization,
4153 : we know we have to canonicalize values. */
4154 53621263 : if (has_value)
4155 : has_other = true;
4156 53614899 : has_value = true;
4157 53614899 : if (has_other)
4158 : break;
4159 : }
4160 : else
4161 : {
4162 10244351 : has_other = true;
4163 10244351 : if (has_value)
4164 : break;
4165 : }
4166 : }
4167 :
4168 63772826 : if (has_value && has_other)
4169 : {
4170 85094 : for (node = *nodep; node; node = node->next)
4171 : {
4172 58968 : if (GET_CODE (node->loc) == VALUE)
4173 : {
4174 38336 : decl_or_value dv = dv_from_value (node->loc);
4175 38336 : variable **slot = NULL;
4176 :
4177 38336 : if (shared_hash_shared (dst->vars))
4178 0 : slot = shared_hash_find_slot_noinsert (dst->vars, dv);
4179 0 : if (!slot)
4180 38336 : slot = shared_hash_find_slot_unshare (&dst->vars, dv,
4181 : INSERT);
4182 38336 : if (!*slot)
4183 : {
4184 19074 : variable *var = onepart_pool_allocate (ONEPART_VALUE);
4185 19074 : var->dv = dv;
4186 19074 : var->refcount = 1;
4187 19074 : var->n_var_parts = 1;
4188 19074 : var->onepart = ONEPART_VALUE;
4189 19074 : var->in_changed_variables = false;
4190 19074 : var->var_part[0].loc_chain = NULL;
4191 19074 : var->var_part[0].cur_loc = NULL;
4192 19074 : VAR_LOC_1PAUX (var) = NULL;
4193 19074 : *slot = var;
4194 : }
4195 :
4196 38336 : VALUE_RECURSED_INTO (node->loc) = true;
4197 : }
4198 : }
4199 :
4200 26126 : dstslot = shared_hash_find_slot_noinsert_1 (dst->vars, dv, dvhash);
4201 26126 : gcc_assert (*dstslot == dvar);
4202 26126 : canonicalize_values_star (dstslot, dst);
4203 26126 : gcc_checking_assert (dstslot
4204 : == shared_hash_find_slot_noinsert_1 (dst->vars,
4205 : dv, dvhash));
4206 26126 : dvar = *dstslot;
4207 : }
4208 : }
4209 :
4210 147548802 : if (!onepart_variable_different_p (dvar, s2var))
4211 : {
4212 141082904 : variable_htab_free (dvar);
4213 141082904 : *dstslot = dvar = s2var;
4214 141082904 : dvar->refcount++;
4215 : }
4216 6465898 : else if (s2var != s1var && !onepart_variable_different_p (dvar, s1var))
4217 : {
4218 4481245 : variable_htab_free (dvar);
4219 4481245 : *dstslot = dvar = s1var;
4220 4481245 : dvar->refcount++;
4221 4481245 : dst_can_be_shared = false;
4222 : }
4223 : else
4224 1984653 : dst_can_be_shared = false;
4225 :
4226 : return 1;
4227 : }
4228 :
4229 : /* Copy s2slot (in DSM->src) to DSM->dst if the variable is a
4230 : multi-part variable. Unions of multi-part variables and
4231 : intersections of one-part ones will be handled in
4232 : variable_merge_over_cur(). */
4233 :
4234 : static int
4235 201201743 : variable_merge_over_src (variable *s2var, struct dfset_merge *dsm)
4236 : {
4237 201201743 : dataflow_set *dst = dsm->dst;
4238 201201743 : decl_or_value dv = s2var->dv;
4239 :
4240 201201743 : if (!s2var->onepart)
4241 : {
4242 993054 : variable **dstp = shared_hash_find_slot (dst->vars, dv);
4243 993054 : *dstp = s2var;
4244 993054 : s2var->refcount++;
4245 993054 : return 1;
4246 : }
4247 :
4248 200208689 : dsm->src_onepart_cnt++;
4249 200208689 : return 1;
4250 : }
4251 :
4252 : /* Combine dataflow set information from SRC2 into DST, using PDST
4253 : to carry over information across passes. */
4254 :
4255 : static void
4256 4306552 : dataflow_set_merge (dataflow_set *dst, dataflow_set *src2)
4257 : {
4258 4306552 : dataflow_set cur = *dst;
4259 4306552 : dataflow_set *src1 = &cur;
4260 4306552 : struct dfset_merge dsm;
4261 4306552 : int i;
4262 4306552 : size_t src1_elems, src2_elems;
4263 4306552 : variable_iterator_type hi;
4264 4306552 : variable *var;
4265 :
4266 4306552 : src1_elems = shared_hash_htab (src1->vars)->elements ();
4267 4306552 : src2_elems = shared_hash_htab (src2->vars)->elements ();
4268 4306552 : dataflow_set_init (dst);
4269 4306552 : dst->stack_adjust = cur.stack_adjust;
4270 4306552 : shared_hash_destroy (dst->vars);
4271 4306552 : dst->vars = new shared_hash;
4272 4306552 : dst->vars->refcount = 1;
4273 4306552 : dst->vars->htab = new variable_table_type (MAX (src1_elems, src2_elems));
4274 :
4275 400509336 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4276 396202784 : attrs_list_mpdv_union (&dst->regs[i], src1->regs[i], src2->regs[i]);
4277 :
4278 4306552 : dsm.dst = dst;
4279 4306552 : dsm.src = src2;
4280 4306552 : dsm.cur = src1;
4281 4306552 : dsm.src_onepart_cnt = 0;
4282 :
4283 406710038 : FOR_EACH_HASH_TABLE_ELEMENT (*shared_hash_htab (dsm.src->vars),
4284 : var, variable, hi)
4285 201201743 : variable_merge_over_src (var, &dsm);
4286 348278224 : FOR_EACH_HASH_TABLE_ELEMENT (*shared_hash_htab (dsm.cur->vars),
4287 : var, variable, hi)
4288 171985836 : variable_merge_over_cur (var, &dsm);
4289 :
4290 4306552 : if (dsm.src_onepart_cnt)
4291 3953845 : dst_can_be_shared = false;
4292 :
4293 4306552 : dataflow_set_destroy (src1);
4294 4306552 : }
4295 :
4296 : /* Mark register equivalences. */
4297 :
4298 : static void
4299 9274363 : dataflow_set_equiv_regs (dataflow_set *set)
4300 : {
4301 9274363 : int i;
4302 9274363 : attrs *list, **listp;
4303 :
4304 862515759 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4305 : {
4306 853241396 : rtx canon[NUM_MACHINE_MODES];
4307 :
4308 : /* If the list is empty or one entry, no need to canonicalize
4309 : anything. */
4310 853241396 : if (set->regs[i] == NULL || set->regs[i]->next == NULL)
4311 850492847 : continue;
4312 :
4313 2748549 : memset (canon, 0, sizeof (canon));
4314 :
4315 8401047 : for (list = set->regs[i]; list; list = list->next)
4316 5652498 : if (list->offset == 0 && dv_is_value_p (list->dv))
4317 : {
4318 4496140 : rtx val = dv_as_value (list->dv);
4319 4496140 : rtx *cvalp = &canon[(int)GET_MODE (val)];
4320 4496140 : rtx cval = *cvalp;
4321 :
4322 10148638 : if (canon_value_cmp (val, cval))
4323 4496140 : *cvalp = val;
4324 : }
4325 :
4326 8401047 : for (list = set->regs[i]; list; list = list->next)
4327 5652498 : if (list->offset == 0 && dv_onepart_p (list->dv))
4328 : {
4329 4496140 : rtx cval = canon[(int)GET_MODE (list->loc)];
4330 :
4331 4496140 : if (!cval)
4332 0 : continue;
4333 :
4334 4496140 : if (dv_is_value_p (list->dv))
4335 : {
4336 4496140 : rtx val = dv_as_value (list->dv);
4337 :
4338 4496140 : if (val == cval)
4339 4496140 : continue;
4340 :
4341 0 : VALUE_RECURSED_INTO (val) = true;
4342 0 : set_variable_part (set, val, dv_from_value (cval), 0,
4343 : VAR_INIT_STATUS_INITIALIZED,
4344 : NULL, NO_INSERT);
4345 : }
4346 :
4347 0 : VALUE_RECURSED_INTO (cval) = true;
4348 0 : set_variable_part (set, cval, list->dv, 0,
4349 : VAR_INIT_STATUS_INITIALIZED, NULL, NO_INSERT);
4350 : }
4351 :
4352 14053545 : for (listp = &set->regs[i]; (list = *listp);
4353 : listp = list ? &list->next : listp)
4354 5652498 : if (list->offset == 0 && dv_onepart_p (list->dv))
4355 : {
4356 4496140 : rtx cval = canon[(int)GET_MODE (list->loc)];
4357 4496140 : variable **slot;
4358 :
4359 4496140 : if (!cval)
4360 0 : continue;
4361 :
4362 4496140 : if (dv_is_value_p (list->dv))
4363 : {
4364 4496140 : rtx val = dv_as_value (list->dv);
4365 4496140 : if (!VALUE_RECURSED_INTO (val))
4366 4496140 : continue;
4367 : }
4368 :
4369 0 : slot = shared_hash_find_slot_noinsert (set->vars, list->dv);
4370 0 : canonicalize_values_star (slot, set);
4371 0 : if (*listp != list)
4372 : list = NULL;
4373 : }
4374 : }
4375 9274363 : }
4376 :
4377 : /* Remove any redundant values in the location list of VAR, which must
4378 : be unshared and 1-part. */
4379 :
4380 : static void
4381 667377 : remove_duplicate_values (variable *var)
4382 : {
4383 667377 : location_chain *node, **nodep;
4384 :
4385 667377 : gcc_assert (var->onepart);
4386 667377 : gcc_assert (var->n_var_parts == 1);
4387 667377 : gcc_assert (var->refcount == 1);
4388 :
4389 1377560 : for (nodep = &var->var_part[0].loc_chain; (node = *nodep); )
4390 : {
4391 710183 : if (GET_CODE (node->loc) == VALUE)
4392 : {
4393 680885 : if (VALUE_RECURSED_INTO (node->loc))
4394 : {
4395 : /* Remove duplicate value node. */
4396 0 : *nodep = node->next;
4397 0 : delete node;
4398 0 : continue;
4399 : }
4400 : else
4401 680885 : VALUE_RECURSED_INTO (node->loc) = true;
4402 : }
4403 710183 : nodep = &node->next;
4404 : }
4405 :
4406 1377560 : for (node = var->var_part[0].loc_chain; node; node = node->next)
4407 710183 : if (GET_CODE (node->loc) == VALUE)
4408 : {
4409 680885 : gcc_assert (VALUE_RECURSED_INTO (node->loc));
4410 680885 : VALUE_RECURSED_INTO (node->loc) = false;
4411 : }
4412 667377 : }
4413 :
4414 :
4415 : /* Hash table iteration argument passed to variable_post_merge. */
4416 : struct dfset_post_merge
4417 : {
4418 : /* The new input set for the current block. */
4419 : dataflow_set *set;
4420 : /* Pointer to the permanent input set for the current block, or
4421 : NULL. */
4422 : dataflow_set **permp;
4423 : };
4424 :
4425 : /* Create values for incoming expressions associated with one-part
4426 : variables that don't have value numbers for them. */
4427 :
4428 : int
4429 104148322 : variable_post_merge_new_vals (variable **slot, dfset_post_merge *dfpm)
4430 : {
4431 104148322 : dataflow_set *set = dfpm->set;
4432 104148322 : variable *var = *slot;
4433 104148322 : location_chain *node;
4434 :
4435 104148322 : if (!var->onepart || !var->n_var_parts)
4436 : return 1;
4437 :
4438 103470114 : gcc_assert (var->n_var_parts == 1);
4439 :
4440 103470114 : if (dv_is_decl_p (var->dv))
4441 : {
4442 : bool check_dupes = false;
4443 :
4444 43713208 : restart:
4445 87472023 : for (node = var->var_part[0].loc_chain; node; node = node->next)
4446 : {
4447 43758815 : if (GET_CODE (node->loc) == VALUE)
4448 36872995 : gcc_assert (!VALUE_RECURSED_INTO (node->loc));
4449 6885820 : else if (GET_CODE (node->loc) == REG)
4450 : {
4451 680885 : attrs *att, **attp, **curp = NULL;
4452 :
4453 680885 : if (var->refcount != 1)
4454 : {
4455 0 : slot = unshare_variable (set, slot, var,
4456 : VAR_INIT_STATUS_INITIALIZED);
4457 0 : var = *slot;
4458 0 : goto restart;
4459 : }
4460 :
4461 1453226 : for (attp = &set->regs[REGNO (node->loc)]; (att = *attp);
4462 772341 : attp = &att->next)
4463 772341 : if (att->offset == 0
4464 771248 : && GET_MODE (att->loc) == GET_MODE (node->loc))
4465 : {
4466 770691 : if (dv_is_value_p (att->dv))
4467 : {
4468 0 : rtx cval = dv_as_value (att->dv);
4469 0 : node->loc = cval;
4470 0 : check_dupes = true;
4471 0 : break;
4472 : }
4473 770691 : else if (att->dv == var->dv)
4474 772341 : curp = attp;
4475 : }
4476 :
4477 680885 : if (!curp)
4478 : {
4479 : curp = attp;
4480 0 : while (*curp)
4481 0 : if ((*curp)->offset == 0
4482 0 : && GET_MODE ((*curp)->loc) == GET_MODE (node->loc)
4483 0 : && (*curp)->dv == var->dv)
4484 : break;
4485 : else
4486 0 : curp = &(*curp)->next;
4487 0 : gcc_assert (*curp);
4488 : }
4489 :
4490 680885 : if (!att)
4491 : {
4492 680885 : decl_or_value cdv;
4493 680885 : rtx cval;
4494 :
4495 680885 : if (!*dfpm->permp)
4496 : {
4497 282935 : *dfpm->permp = XNEW (dataflow_set);
4498 282935 : dataflow_set_init (*dfpm->permp);
4499 : }
4500 :
4501 680885 : for (att = (*dfpm->permp)->regs[REGNO (node->loc)];
4502 681045 : att; att = att->next)
4503 281129 : if (GET_MODE (att->loc) == GET_MODE (node->loc))
4504 : {
4505 280969 : gcc_assert (att->offset == 0
4506 : && dv_is_value_p (att->dv));
4507 280969 : val_reset (set, att->dv);
4508 280969 : break;
4509 : }
4510 :
4511 680885 : if (att)
4512 : {
4513 280969 : cdv = att->dv;
4514 280969 : cval = dv_as_value (cdv);
4515 : }
4516 : else
4517 : {
4518 : /* Create a unique value to hold this register,
4519 : that ought to be found and reused in
4520 : subsequent rounds. */
4521 399916 : cselib_val *v;
4522 399916 : gcc_assert (!cselib_lookup (node->loc,
4523 : GET_MODE (node->loc), 0,
4524 : VOIDmode));
4525 399916 : v = cselib_lookup (node->loc, GET_MODE (node->loc), 1,
4526 : VOIDmode);
4527 399916 : cselib_preserve_value (v);
4528 399916 : cselib_invalidate_rtx (node->loc);
4529 399916 : cval = v->val_rtx;
4530 399916 : cdv = dv_from_value (cval);
4531 399916 : if (dump_file)
4532 0 : fprintf (dump_file,
4533 : "Created new value %u:%u for reg %i\n",
4534 0 : v->uid, v->hash, REGNO (node->loc));
4535 : }
4536 :
4537 680885 : var_reg_decl_set (*dfpm->permp, node->loc,
4538 : VAR_INIT_STATUS_INITIALIZED,
4539 : cdv, 0, NULL, INSERT);
4540 :
4541 680885 : node->loc = cval;
4542 680885 : check_dupes = true;
4543 : }
4544 :
4545 : /* Remove attribute referring to the decl, which now
4546 : uses the value for the register, already existing or
4547 : to be added when we bring perm in. */
4548 680885 : att = *curp;
4549 680885 : *curp = att->next;
4550 680885 : delete att;
4551 : }
4552 : }
4553 :
4554 43713208 : if (check_dupes)
4555 667377 : remove_duplicate_values (var);
4556 : }
4557 :
4558 : return 1;
4559 : }
4560 :
4561 : /* Reset values in the permanent set that are not associated with the
4562 : chosen expression. */
4563 :
4564 : int
4565 625416 : variable_post_merge_perm_vals (variable **pslot, dfset_post_merge *dfpm)
4566 : {
4567 625416 : dataflow_set *set = dfpm->set;
4568 625416 : variable *pvar = *pslot, *var;
4569 625416 : location_chain *pnode;
4570 625416 : decl_or_value dv;
4571 625416 : attrs *att;
4572 :
4573 1250832 : gcc_assert (dv_is_value_p (pvar->dv)
4574 : && pvar->n_var_parts == 1);
4575 625416 : pnode = pvar->var_part[0].loc_chain;
4576 625416 : gcc_assert (pnode
4577 : && !pnode->next
4578 : && REG_P (pnode->loc));
4579 :
4580 625416 : dv = pvar->dv;
4581 :
4582 625416 : var = shared_hash_find (set->vars, dv);
4583 625416 : if (var)
4584 : {
4585 : /* Although variable_post_merge_new_vals may have made decls
4586 : non-star-canonical, values that pre-existed in canonical form
4587 : remain canonical, and newly-created values reference a single
4588 : REG, so they are canonical as well. Since VAR has the
4589 : location list for a VALUE, using find_loc_in_1pdv for it is
4590 : fine, since VALUEs don't map back to DECLs. */
4591 0 : if (find_loc_in_1pdv (pnode->loc, var, shared_hash_htab (set->vars)))
4592 : return 1;
4593 0 : val_reset (set, dv);
4594 : }
4595 :
4596 629867 : for (att = set->regs[REGNO (pnode->loc)]; att; att = att->next)
4597 4451 : if (att->offset == 0
4598 3604 : && GET_MODE (att->loc) == GET_MODE (pnode->loc)
4599 8055 : && dv_is_value_p (att->dv))
4600 : break;
4601 :
4602 : /* If there is a value associated with this register already, create
4603 : an equivalence. */
4604 625416 : if (att && dv_as_value (att->dv) != dv_as_value (dv))
4605 : {
4606 0 : rtx cval = dv_as_value (att->dv);
4607 0 : set_variable_part (set, cval, dv, 0, pnode->init, NULL, INSERT);
4608 0 : set_variable_part (set, dv_as_value (dv), att->dv, 0, pnode->init,
4609 : NULL, INSERT);
4610 : }
4611 625416 : else if (!att)
4612 : {
4613 625416 : attrs_list_insert (&set->regs[REGNO (pnode->loc)],
4614 : dv, 0, pnode->loc);
4615 625416 : variable_union (pvar, set);
4616 : }
4617 :
4618 : return 1;
4619 : }
4620 :
4621 : /* Just checking stuff and registering register attributes for
4622 : now. */
4623 :
4624 : static void
4625 2790275 : dataflow_post_merge_adjust (dataflow_set *set, dataflow_set **permp)
4626 : {
4627 2790275 : struct dfset_post_merge dfpm;
4628 :
4629 2790275 : dfpm.set = set;
4630 2790275 : dfpm.permp = permp;
4631 :
4632 2790275 : shared_hash_htab (set->vars)
4633 106938597 : ->traverse <dfset_post_merge*, variable_post_merge_new_vals> (&dfpm);
4634 2790275 : if (*permp)
4635 443729 : shared_hash_htab ((*permp)->vars)
4636 1069145 : ->traverse <dfset_post_merge*, variable_post_merge_perm_vals> (&dfpm);
4637 2790275 : shared_hash_htab (set->vars)
4638 510073297 : ->traverse <dataflow_set *, canonicalize_values_star> (set);
4639 2790275 : shared_hash_htab (set->vars)
4640 107564013 : ->traverse <dataflow_set *, canonicalize_vars_star> (set);
4641 2790275 : }
4642 :
4643 : /* Return a node whose loc is a MEM that refers to EXPR in the
4644 : location list of a one-part variable or value VAR, or in that of
4645 : any values recursively mentioned in the location lists. */
4646 :
4647 : static location_chain *
4648 102221119 : find_mem_expr_in_1pdv (tree expr, rtx val, variable_table_type *vars)
4649 : {
4650 102221119 : location_chain *node;
4651 102221119 : decl_or_value dv;
4652 102221119 : variable *var;
4653 102221119 : location_chain *where = NULL;
4654 :
4655 102221119 : if (!val)
4656 : return NULL;
4657 :
4658 102221119 : gcc_assert (GET_CODE (val) == VALUE
4659 : && !VALUE_RECURSED_INTO (val));
4660 :
4661 102221119 : dv = dv_from_value (val);
4662 102221119 : var = vars->find_with_hash (dv, dv_htab_hash (dv));
4663 :
4664 102221119 : if (!var)
4665 : return NULL;
4666 :
4667 48254830 : gcc_assert (var->onepart);
4668 :
4669 48254830 : if (!var->n_var_parts)
4670 : return NULL;
4671 :
4672 48254830 : VALUE_RECURSED_INTO (val) = true;
4673 :
4674 116732230 : for (node = var->var_part[0].loc_chain; node; node = node->next)
4675 69450088 : if (MEM_P (node->loc)
4676 15172313 : && MEM_EXPR (node->loc) == expr
4677 70421025 : && int_mem_offset (node->loc) == 0)
4678 : {
4679 : where = node;
4680 : break;
4681 : }
4682 68479151 : else if (GET_CODE (node->loc) == VALUE
4683 41999511 : && !VALUE_RECURSED_INTO (node->loc)
4684 89479781 : && (where = find_mem_expr_in_1pdv (expr, node->loc, vars)))
4685 : break;
4686 :
4687 48254830 : VALUE_RECURSED_INTO (val) = false;
4688 :
4689 48254830 : return where;
4690 : }
4691 :
4692 : /* Return TRUE if the value of MEM may vary across a call. */
4693 :
4694 : static bool
4695 97102185 : mem_dies_at_call (rtx mem)
4696 : {
4697 97102185 : tree expr = MEM_EXPR (mem);
4698 97102185 : tree decl;
4699 :
4700 97102185 : if (!expr)
4701 : return true;
4702 :
4703 87950753 : decl = get_base_address (expr);
4704 :
4705 87950753 : if (!decl)
4706 : return true;
4707 :
4708 87950753 : if (!DECL_P (decl))
4709 : return true;
4710 :
4711 80704017 : return (may_be_aliased (decl)
4712 80704017 : || (!TREE_READONLY (decl) && is_global_var (decl)));
4713 : }
4714 :
4715 : /* Remove all MEMs from the location list of a hash table entry for a
4716 : one-part variable, except those whose MEM attributes map back to
4717 : the variable itself, directly or within a VALUE. */
4718 :
4719 : int
4720 293025749 : dataflow_set_preserve_mem_locs (variable **slot, dataflow_set *set)
4721 : {
4722 293025749 : variable *var = *slot;
4723 :
4724 293025749 : if (var->onepart == ONEPART_VDECL || var->onepart == ONEPART_DEXPR)
4725 : {
4726 135511593 : tree decl = dv_as_decl (var->dv);
4727 135511593 : location_chain *loc, **locp;
4728 135511593 : bool changed = false;
4729 :
4730 135511593 : if (!var->n_var_parts)
4731 : return 1;
4732 :
4733 135511593 : gcc_assert (var->n_var_parts == 1);
4734 :
4735 135511593 : if (shared_var_p (var, set->vars))
4736 : {
4737 163985004 : for (loc = var->var_part[0].loc_chain; loc; loc = loc->next)
4738 : {
4739 : /* We want to remove dying MEMs that don't refer to DECL. */
4740 82238450 : if (GET_CODE (loc->loc) == MEM
4741 2199873 : && (MEM_EXPR (loc->loc) != decl
4742 1966270 : || int_mem_offset (loc->loc) != 0)
4743 82472053 : && mem_dies_at_call (loc->loc))
4744 : break;
4745 : /* We want to move here MEMs that do refer to DECL. */
4746 82233215 : else if (GET_CODE (loc->loc) == VALUE
4747 82233215 : && find_mem_expr_in_1pdv (decl, loc->loc,
4748 : shared_hash_htab (set->vars)))
4749 : break;
4750 : }
4751 :
4752 82236006 : if (!loc)
4753 : return 1;
4754 :
4755 489452 : slot = unshare_variable (set, slot, var, VAR_INIT_STATUS_UNKNOWN);
4756 489452 : var = *slot;
4757 489452 : gcc_assert (var->n_var_parts == 1);
4758 : }
4759 :
4760 53765039 : for (locp = &var->var_part[0].loc_chain, loc = *locp;
4761 107530502 : loc; loc = *locp)
4762 : {
4763 53765463 : rtx old_loc = loc->loc;
4764 53765463 : if (GET_CODE (old_loc) == VALUE)
4765 : {
4766 11832687 : location_chain *mem_node
4767 11832687 : = find_mem_expr_in_1pdv (decl, loc->loc,
4768 : shared_hash_htab (set->vars));
4769 :
4770 : /* ??? This picks up only one out of multiple MEMs that
4771 : refer to the same variable. Do we ever need to be
4772 : concerned about dealing with more than one, or, given
4773 : that they should all map to the same variable
4774 : location, their addresses will have been merged and
4775 : they will be regarded as equivalent? */
4776 11832687 : if (mem_node)
4777 : {
4778 486720 : loc->loc = mem_node->loc;
4779 486720 : loc->set_src = mem_node->set_src;
4780 973440 : loc->init = MIN (loc->init, mem_node->init);
4781 : }
4782 : }
4783 :
4784 107525669 : if (GET_CODE (loc->loc) != MEM
4785 536864 : || (MEM_EXPR (loc->loc) == decl
4786 530921 : && int_mem_offset (loc->loc) == 0)
4787 53771406 : || !mem_dies_at_call (loc->loc))
4788 : {
4789 53760206 : if (old_loc != loc->loc && emit_notes)
4790 : {
4791 241308 : if (old_loc == var->var_part[0].cur_loc)
4792 : {
4793 0 : changed = true;
4794 0 : var->var_part[0].cur_loc = NULL;
4795 : }
4796 : }
4797 53760206 : locp = &loc->next;
4798 53760206 : continue;
4799 : }
4800 :
4801 5257 : if (emit_notes)
4802 : {
4803 2391 : if (old_loc == var->var_part[0].cur_loc)
4804 : {
4805 0 : changed = true;
4806 0 : var->var_part[0].cur_loc = NULL;
4807 : }
4808 : }
4809 5257 : *locp = loc->next;
4810 5257 : delete loc;
4811 : }
4812 :
4813 53765039 : if (!var->var_part[0].loc_chain)
4814 : {
4815 4839 : var->n_var_parts--;
4816 4839 : changed = true;
4817 : }
4818 53765039 : if (changed)
4819 4839 : variable_was_changed (var, set);
4820 : }
4821 :
4822 : return 1;
4823 : }
4824 :
4825 : /* Remove all MEMs from the location list of a hash table entry for a
4826 : onepart variable. */
4827 :
4828 : int
4829 293020910 : dataflow_set_remove_mem_locs (variable **slot, dataflow_set *set)
4830 : {
4831 293020910 : variable *var = *slot;
4832 :
4833 293020910 : if (var->onepart != NOT_ONEPART)
4834 : {
4835 291773571 : location_chain *loc, **locp;
4836 291773571 : bool changed = false;
4837 291773571 : rtx cur_loc;
4838 :
4839 291773571 : gcc_assert (var->n_var_parts == 1);
4840 :
4841 291773571 : if (shared_var_p (var, set->vars))
4842 : {
4843 436833547 : for (loc = var->var_part[0].loc_chain; loc; loc = loc->next)
4844 234388885 : if (GET_CODE (loc->loc) == MEM
4845 234388885 : && mem_dies_at_call (loc->loc))
4846 : break;
4847 :
4848 208022231 : if (!loc)
4849 : return 1;
4850 :
4851 5577569 : slot = unshare_variable (set, slot, var, VAR_INIT_STATUS_UNKNOWN);
4852 5577569 : var = *slot;
4853 5577569 : gcc_assert (var->n_var_parts == 1);
4854 : }
4855 :
4856 89328909 : if (VAR_LOC_1PAUX (var))
4857 29701684 : cur_loc = VAR_LOC_FROM (var);
4858 : else
4859 59627225 : cur_loc = var->var_part[0].cur_loc;
4860 :
4861 89328909 : for (locp = &var->var_part[0].loc_chain, loc = *locp;
4862 196848058 : loc; loc = *locp)
4863 : {
4864 196840041 : if (GET_CODE (loc->loc) != MEM
4865 107519149 : || !mem_dies_at_call (loc->loc))
4866 : {
4867 89320892 : locp = &loc->next;
4868 89320892 : continue;
4869 : }
4870 :
4871 18198257 : *locp = loc->next;
4872 : /* If we have deleted the location which was last emitted
4873 : we have to emit new location so add the variable to set
4874 : of changed variables. */
4875 18198257 : if (cur_loc == loc->loc)
4876 : {
4877 334933 : changed = true;
4878 334933 : var->var_part[0].cur_loc = NULL;
4879 334933 : if (VAR_LOC_1PAUX (var))
4880 334933 : VAR_LOC_FROM (var) = NULL;
4881 : }
4882 18198257 : delete loc;
4883 : }
4884 :
4885 89328909 : if (!var->var_part[0].loc_chain)
4886 : {
4887 11986812 : var->n_var_parts--;
4888 11986812 : changed = true;
4889 : }
4890 89328909 : if (changed)
4891 12014987 : variable_was_changed (var, set);
4892 : }
4893 :
4894 : return 1;
4895 : }
4896 :
4897 : /* Remove all variable-location information about call-clobbered
4898 : registers, as well as associations between MEMs and VALUEs. */
4899 :
4900 : static void
4901 6834825 : dataflow_set_clear_at_call (dataflow_set *set, rtx_insn *call_insn)
4902 : {
4903 6834825 : unsigned int r;
4904 6834825 : hard_reg_set_iterator hrsi;
4905 :
4906 6834825 : HARD_REG_SET callee_clobbers
4907 6834825 : = insn_callee_abi (call_insn).full_reg_clobbers ();
4908 :
4909 576234607 : EXECUTE_IF_SET_IN_HARD_REG_SET (callee_clobbers, 0, r, hrsi)
4910 569399782 : var_regno_delete (set, r);
4911 :
4912 6834825 : if (MAY_HAVE_DEBUG_BIND_INSNS)
4913 : {
4914 6834741 : set->traversed_vars = set->vars;
4915 6834741 : shared_hash_htab (set->vars)
4916 299860490 : ->traverse <dataflow_set *, dataflow_set_preserve_mem_locs> (set);
4917 6834741 : set->traversed_vars = set->vars;
4918 6834741 : shared_hash_htab (set->vars)
4919 299855651 : ->traverse <dataflow_set *, dataflow_set_remove_mem_locs> (set);
4920 6834741 : set->traversed_vars = NULL;
4921 : }
4922 6834825 : }
4923 :
4924 : static bool
4925 655481 : variable_part_different_p (variable_part *vp1, variable_part *vp2)
4926 : {
4927 655481 : location_chain *lc1, *lc2;
4928 :
4929 1421047 : for (lc1 = vp1->loc_chain; lc1; lc1 = lc1->next)
4930 : {
4931 1015075 : for (lc2 = vp2->loc_chain; lc2; lc2 = lc2->next)
4932 : {
4933 972758 : if (REG_P (lc1->loc) && REG_P (lc2->loc))
4934 : {
4935 721295 : if (REGNO (lc1->loc) == REGNO (lc2->loc))
4936 : break;
4937 : }
4938 351133 : if (rtx_equal_p (lc1->loc, lc2->loc))
4939 : break;
4940 : }
4941 765566 : if (!lc2)
4942 : return true;
4943 : }
4944 : return false;
4945 : }
4946 :
4947 : /* Return true if one-part variables VAR1 and VAR2 are different.
4948 : They must be in canonical order. */
4949 :
4950 : static bool
4951 319091251 : onepart_variable_different_p (variable *var1, variable *var2)
4952 : {
4953 319091251 : location_chain *lc1, *lc2;
4954 :
4955 319091251 : if (var1 == var2)
4956 : return false;
4957 :
4958 89127889 : gcc_assert (var1->n_var_parts == 1
4959 : && var2->n_var_parts == 1);
4960 :
4961 89127889 : lc1 = var1->var_part[0].loc_chain;
4962 89127889 : lc2 = var2->var_part[0].loc_chain;
4963 :
4964 89127889 : gcc_assert (lc1 && lc2);
4965 :
4966 189174850 : while (lc1 && lc2)
4967 : {
4968 118313289 : if (loc_cmp (lc1->loc, lc2->loc))
4969 : return true;
4970 100046961 : lc1 = lc1->next;
4971 100046961 : lc2 = lc2->next;
4972 : }
4973 :
4974 70861561 : return lc1 != lc2;
4975 : }
4976 :
4977 : /* Return true if one-part variables VAR1 and VAR2 are different.
4978 : They must be in canonical order. */
4979 :
4980 : static void
4981 0 : dump_onepart_variable_differences (variable *var1, variable *var2)
4982 : {
4983 0 : location_chain *lc1, *lc2;
4984 :
4985 0 : gcc_assert (var1 != var2);
4986 0 : gcc_assert (dump_file);
4987 0 : gcc_assert (var1->dv == var2->dv);
4988 0 : gcc_assert (var1->n_var_parts == 1
4989 : && var2->n_var_parts == 1);
4990 :
4991 0 : lc1 = var1->var_part[0].loc_chain;
4992 0 : lc2 = var2->var_part[0].loc_chain;
4993 :
4994 0 : gcc_assert (lc1 && lc2);
4995 :
4996 0 : while (lc1 && lc2)
4997 : {
4998 0 : switch (loc_cmp (lc1->loc, lc2->loc))
4999 : {
5000 0 : case -1:
5001 0 : fprintf (dump_file, "removed: ");
5002 0 : print_rtl_single (dump_file, lc1->loc);
5003 0 : lc1 = lc1->next;
5004 0 : continue;
5005 0 : case 0:
5006 0 : break;
5007 0 : case 1:
5008 0 : fprintf (dump_file, "added: ");
5009 0 : print_rtl_single (dump_file, lc2->loc);
5010 0 : lc2 = lc2->next;
5011 0 : continue;
5012 0 : default:
5013 0 : gcc_unreachable ();
5014 : }
5015 0 : lc1 = lc1->next;
5016 0 : lc2 = lc2->next;
5017 : }
5018 :
5019 0 : while (lc1)
5020 : {
5021 0 : fprintf (dump_file, "removed: ");
5022 0 : print_rtl_single (dump_file, lc1->loc);
5023 0 : lc1 = lc1->next;
5024 : }
5025 :
5026 0 : while (lc2)
5027 : {
5028 0 : fprintf (dump_file, "added: ");
5029 0 : print_rtl_single (dump_file, lc2->loc);
5030 0 : lc2 = lc2->next;
5031 : }
5032 0 : }
5033 :
5034 : /* Return true if variables VAR1 and VAR2 are different. */
5035 :
5036 : static bool
5037 265847414 : variable_different_p (variable *var1, variable *var2)
5038 : {
5039 265847414 : int i;
5040 :
5041 265847414 : if (var1 == var2)
5042 : return false;
5043 :
5044 38251779 : if (var1->onepart != var2->onepart)
5045 : return true;
5046 :
5047 38251779 : if (var1->n_var_parts != var2->n_var_parts)
5048 : return true;
5049 :
5050 38207449 : if (var1->onepart && var1->n_var_parts)
5051 : {
5052 37964444 : gcc_checking_assert (var1->dv == var2->dv && var1->n_var_parts == 1);
5053 : /* One-part values have locations in a canonical order. */
5054 37964444 : return onepart_variable_different_p (var1, var2);
5055 : }
5056 :
5057 537111 : for (i = 0; i < var1->n_var_parts; i++)
5058 : {
5059 339531 : if (VAR_PART_OFFSET (var1, i) != VAR_PART_OFFSET (var2, i))
5060 : return true;
5061 336423 : if (variable_part_different_p (&var1->var_part[i], &var2->var_part[i]))
5062 : return true;
5063 319058 : if (variable_part_different_p (&var2->var_part[i], &var1->var_part[i]))
5064 : return true;
5065 : }
5066 : return false;
5067 : }
5068 :
5069 : /* Return true if dataflow sets OLD_SET and NEW_SET differ. */
5070 :
5071 : static bool
5072 9274460 : dataflow_set_different (dataflow_set *old_set, dataflow_set *new_set)
5073 : {
5074 9274460 : variable_iterator_type hi;
5075 9274460 : variable *var1;
5076 9274460 : bool diffound = false;
5077 9274460 : bool details = (dump_file && (dump_flags & TDF_DETAILS));
5078 :
5079 : #define RETRUE \
5080 : do \
5081 : { \
5082 : if (!details) \
5083 : return true; \
5084 : else \
5085 : diffound = true; \
5086 : } \
5087 : while (0)
5088 :
5089 9274460 : if (old_set->vars == new_set->vars)
5090 : return false;
5091 :
5092 9268892 : if (shared_hash_htab (old_set->vars)->elements ()
5093 9268892 : != shared_hash_htab (new_set->vars)->elements ())
5094 8726577 : RETRUE;
5095 :
5096 39236454 : FOR_EACH_HASH_TABLE_ELEMENT (*shared_hash_htab (old_set->vars),
5097 : var1, variable, hi)
5098 : {
5099 19497863 : variable_table_type *htab = shared_hash_htab (new_set->vars);
5100 19497863 : variable *var2 = htab->find_with_hash (var1->dv, dv_htab_hash (var1->dv));
5101 :
5102 19497863 : if (!var2)
5103 : {
5104 33049 : if (dump_file && (dump_flags & TDF_DETAILS))
5105 : {
5106 0 : fprintf (dump_file, "dataflow difference found: removal of:\n");
5107 0 : dump_var (var1);
5108 : }
5109 33049 : RETRUE;
5110 : }
5111 19464814 : else if (variable_different_p (var1, var2))
5112 : {
5113 117745 : if (details)
5114 : {
5115 0 : fprintf (dump_file, "dataflow difference found: "
5116 : "old and new follow:\n");
5117 0 : dump_var (var1);
5118 0 : if (dv_onepart_p (var1->dv))
5119 0 : dump_onepart_variable_differences (var1, var2);
5120 0 : dump_var (var2);
5121 : }
5122 0 : RETRUE;
5123 : }
5124 : }
5125 :
5126 : /* There's no need to traverse the second hashtab unless we want to
5127 : print the details. If both have the same number of elements and
5128 : the second one had all entries found in the first one, then the
5129 : second can't have any extra entries. */
5130 391522 : if (!details)
5131 : return diffound;
5132 :
5133 7 : FOR_EACH_HASH_TABLE_ELEMENT (*shared_hash_htab (new_set->vars),
5134 : var1, variable, hi)
5135 : {
5136 3 : variable_table_type *htab = shared_hash_htab (old_set->vars);
5137 3 : variable *var2 = htab->find_with_hash (var1->dv, dv_htab_hash (var1->dv));
5138 3 : if (!var2)
5139 : {
5140 3 : if (details)
5141 : {
5142 3 : fprintf (dump_file, "dataflow difference found: addition of:\n");
5143 3 : dump_var (var1);
5144 : }
5145 3 : RETRUE;
5146 : }
5147 : }
5148 :
5149 : #undef RETRUE
5150 :
5151 : return diffound;
5152 : }
5153 :
5154 : /* Free the contents of dataflow set SET. */
5155 :
5156 : static void
5157 31028497 : dataflow_set_destroy (dataflow_set *set)
5158 : {
5159 31028497 : int i;
5160 :
5161 2885650221 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
5162 2854621724 : attrs_list_clear (&set->regs[i]);
5163 :
5164 31028497 : shared_hash_destroy (set->vars);
5165 31028497 : set->vars = NULL;
5166 31028497 : }
5167 :
5168 : /* Return true if T is a tracked parameter with non-degenerate record type. */
5169 :
5170 : static bool
5171 4013118 : tracked_record_parameter_p (tree t)
5172 : {
5173 4013118 : if (TREE_CODE (t) != PARM_DECL)
5174 : return false;
5175 :
5176 360949 : if (DECL_MODE (t) == BLKmode)
5177 : return false;
5178 :
5179 179885 : tree type = TREE_TYPE (t);
5180 179885 : if (TREE_CODE (type) != RECORD_TYPE)
5181 : return false;
5182 :
5183 179698 : if (TYPE_FIELDS (type) == NULL_TREE
5184 179698 : || DECL_CHAIN (TYPE_FIELDS (type)) == NULL_TREE)
5185 1151 : return false;
5186 :
5187 : return true;
5188 : }
5189 :
5190 : /* Shall EXPR be tracked? */
5191 :
5192 : static bool
5193 79218967 : track_expr_p (tree expr, bool need_rtl)
5194 : {
5195 79218967 : rtx decl_rtl;
5196 79218967 : tree realdecl;
5197 :
5198 79218967 : if (TREE_CODE (expr) == DEBUG_EXPR_DECL)
5199 3225168 : return DECL_RTL_SET_P (expr);
5200 :
5201 : /* If EXPR is not a parameter or a variable do not track it. */
5202 75993799 : if (!VAR_P (expr) && TREE_CODE (expr) != PARM_DECL)
5203 : return 0;
5204 :
5205 : /* It also must have a name... */
5206 46620262 : if (!DECL_NAME (expr) && need_rtl)
5207 : return 0;
5208 :
5209 : /* ... and a RTL assigned to it. */
5210 45211032 : decl_rtl = DECL_RTL_IF_SET (expr);
5211 45211032 : if (!decl_rtl && need_rtl)
5212 : return 0;
5213 :
5214 : /* If this expression is really a debug alias of some other declaration, we
5215 : don't need to track this expression if the ultimate declaration is
5216 : ignored. */
5217 44930161 : realdecl = expr;
5218 44930161 : if (VAR_P (realdecl) && DECL_HAS_DEBUG_EXPR_P (realdecl))
5219 : {
5220 3507117 : realdecl = DECL_DEBUG_EXPR (realdecl);
5221 3507117 : if (!DECL_P (realdecl))
5222 : {
5223 3507117 : if (handled_component_p (realdecl)
5224 416448 : || (TREE_CODE (realdecl) == MEM_REF
5225 416448 : && TREE_CODE (TREE_OPERAND (realdecl, 0)) == ADDR_EXPR))
5226 : {
5227 3507117 : HOST_WIDE_INT bitsize, bitpos;
5228 3507117 : bool reverse;
5229 3507117 : tree innerdecl
5230 3507117 : = get_ref_base_and_extent_hwi (realdecl, &bitpos,
5231 : &bitsize, &reverse);
5232 3507117 : if (!innerdecl
5233 3507117 : || !DECL_P (innerdecl)
5234 3507117 : || DECL_IGNORED_P (innerdecl)
5235 : /* Do not track declarations for parts of tracked record
5236 : parameters since we want to track them as a whole. */
5237 3506699 : || tracked_record_parameter_p (innerdecl)
5238 3418786 : || TREE_STATIC (innerdecl)
5239 3418784 : || bitsize == 0
5240 6925901 : || bitpos + bitsize > 256)
5241 239185 : return 0;
5242 : else
5243 3267932 : realdecl = expr;
5244 : }
5245 : else
5246 : return 0;
5247 : }
5248 : }
5249 :
5250 : /* Do not track EXPR if REALDECL it should be ignored for debugging
5251 : purposes. */
5252 44690976 : if (DECL_IGNORED_P (realdecl))
5253 : return 0;
5254 :
5255 : /* Do not track global variables until we are able to emit correct location
5256 : list for them. */
5257 35853051 : if (TREE_STATIC (realdecl))
5258 : return 0;
5259 :
5260 : /* When the EXPR is a DECL for alias of some variable (see example)
5261 : the TREE_STATIC flag is not used. Disable tracking all DECLs whose
5262 : DECL_RTL contains SYMBOL_REF.
5263 :
5264 : Example:
5265 : extern char **_dl_argv_internal __attribute__ ((alias ("_dl_argv")));
5266 : char **_dl_argv;
5267 : */
5268 5446552 : if (decl_rtl && MEM_P (decl_rtl)
5269 36160718 : && contains_symbol_ref_p (XEXP (decl_rtl, 0)))
5270 : return 0;
5271 :
5272 : /* If RTX is a memory it should not be very large (because it would be
5273 : an array or struct). */
5274 35768318 : if (decl_rtl && MEM_P (decl_rtl))
5275 : {
5276 : /* Do not track structures and arrays. */
5277 354024 : if ((GET_MODE (decl_rtl) == BLKmode
5278 47864 : || AGGREGATE_TYPE_P (TREE_TYPE (realdecl)))
5279 376872 : && !tracked_record_parameter_p (realdecl))
5280 : return 0;
5281 38238 : if (MEM_SIZE_KNOWN_P (decl_rtl)
5282 38238 : && maybe_gt (MEM_SIZE (decl_rtl), MAX_VAR_PARTS))
5283 : return 0;
5284 : }
5285 :
5286 35452019 : DECL_CHANGED (expr) = 0;
5287 35452019 : DECL_CHANGED (realdecl) = 0;
5288 35452019 : return 1;
5289 : }
5290 :
5291 : /* Determine whether a given LOC refers to the same variable part as
5292 : EXPR+OFFSET. */
5293 :
5294 : static bool
5295 176920 : same_variable_part_p (rtx loc, tree expr, poly_int64 offset)
5296 : {
5297 176920 : tree expr2;
5298 176920 : poly_int64 offset2;
5299 :
5300 176920 : if (! DECL_P (expr))
5301 : return false;
5302 :
5303 176920 : if (REG_P (loc))
5304 : {
5305 92802 : expr2 = REG_EXPR (loc);
5306 92802 : offset2 = REG_OFFSET (loc);
5307 : }
5308 84118 : else if (MEM_P (loc))
5309 : {
5310 77332 : expr2 = MEM_EXPR (loc);
5311 77332 : offset2 = int_mem_offset (loc);
5312 : }
5313 : else
5314 : return false;
5315 :
5316 170134 : if (! expr2 || ! DECL_P (expr2))
5317 : return false;
5318 :
5319 125139 : expr = var_debug_decl (expr);
5320 125139 : expr2 = var_debug_decl (expr2);
5321 :
5322 125139 : return (expr == expr2 && known_eq (offset, offset2));
5323 : }
5324 :
5325 : /* LOC is a REG or MEM that we would like to track if possible.
5326 : If EXPR is null, we don't know what expression LOC refers to,
5327 : otherwise it refers to EXPR + OFFSET. STORE_REG_P is true if
5328 : LOC is an lvalue register.
5329 :
5330 : Return true if EXPR is nonnull and if LOC, or some lowpart of it,
5331 : is something we can track. When returning true, store the mode of
5332 : the lowpart we can track in *MODE_OUT (if nonnull) and its offset
5333 : from EXPR in *OFFSET_OUT (if nonnull). */
5334 :
5335 : static bool
5336 42084836 : track_loc_p (rtx loc, tree expr, poly_int64 offset, bool store_reg_p,
5337 : machine_mode *mode_out, HOST_WIDE_INT *offset_out)
5338 : {
5339 42084836 : machine_mode mode;
5340 :
5341 42084836 : if (expr == NULL || !track_expr_p (expr, true))
5342 40293450 : return false;
5343 :
5344 : /* If REG was a paradoxical subreg, its REG_ATTRS will describe the
5345 : whole subreg, but only the old inner part is really relevant. */
5346 1791386 : mode = GET_MODE (loc);
5347 1791386 : if (REG_P (loc) && !HARD_REGISTER_NUM_P (ORIGINAL_REGNO (loc)))
5348 : {
5349 709956 : machine_mode pseudo_mode;
5350 :
5351 709956 : pseudo_mode = PSEUDO_REGNO_MODE (ORIGINAL_REGNO (loc));
5352 709956 : if (paradoxical_subreg_p (mode, pseudo_mode))
5353 : {
5354 616 : offset += byte_lowpart_offset (pseudo_mode, mode);
5355 616 : mode = pseudo_mode;
5356 : }
5357 : }
5358 :
5359 : /* If LOC is a paradoxical lowpart of EXPR, refer to EXPR itself.
5360 : Do the same if we are storing to a register and EXPR occupies
5361 : the whole of register LOC; in that case, the whole of EXPR is
5362 : being changed. We exclude complex modes from the second case
5363 : because the real and imaginary parts are represented as separate
5364 : pseudo registers, even if the whole complex value fits into one
5365 : hard register. */
5366 1791386 : if ((paradoxical_subreg_p (mode, DECL_MODE (expr))
5367 1790536 : || (store_reg_p
5368 0 : && !COMPLEX_MODE_P (DECL_MODE (expr))
5369 0 : && hard_regno_nregs (REGNO (loc), DECL_MODE (expr)) == 1))
5370 3581922 : && known_eq (offset + byte_lowpart_offset (DECL_MODE (expr), mode), 0))
5371 : {
5372 850 : mode = DECL_MODE (expr);
5373 850 : offset = 0;
5374 : }
5375 :
5376 1791386 : HOST_WIDE_INT const_offset;
5377 42084836 : if (!track_offset_p (offset, &const_offset))
5378 : return false;
5379 :
5380 1791386 : if (mode_out)
5381 1791386 : *mode_out = mode;
5382 1791386 : if (offset_out)
5383 945495 : *offset_out = const_offset;
5384 : return true;
5385 : }
5386 :
5387 : /* Return the MODE lowpart of LOC, or null if LOC is not something we
5388 : want to track. When returning nonnull, make sure that the attributes
5389 : on the returned value are updated. */
5390 :
5391 : static rtx
5392 2746400 : var_lowpart (machine_mode mode, rtx loc)
5393 : {
5394 2746400 : unsigned int regno;
5395 :
5396 2746400 : if (GET_MODE (loc) == mode)
5397 : return loc;
5398 :
5399 7160 : if (!REG_P (loc) && !MEM_P (loc))
5400 : return NULL;
5401 :
5402 2301 : poly_uint64 offset = byte_lowpart_offset (mode, GET_MODE (loc));
5403 :
5404 2301 : if (MEM_P (loc))
5405 5 : return adjust_address_nv (loc, mode, offset);
5406 :
5407 2296 : poly_uint64 reg_offset = subreg_lowpart_offset (mode, GET_MODE (loc));
5408 2296 : regno = REGNO (loc) + subreg_regno_offset (REGNO (loc), GET_MODE (loc),
5409 : reg_offset, mode);
5410 2296 : return gen_rtx_REG_offset (loc, mode, regno, offset);
5411 : }
5412 :
5413 : /* Carry information about uses and stores while walking rtx. */
5414 :
5415 : struct count_use_info
5416 : {
5417 : /* The insn where the RTX is. */
5418 : rtx_insn *insn;
5419 :
5420 : /* The basic block where insn is. */
5421 : basic_block bb;
5422 :
5423 : /* The array of n_sets sets in the insn, as determined by cselib. */
5424 : struct cselib_set *sets;
5425 : int n_sets;
5426 :
5427 : /* True if we're counting stores, false otherwise. */
5428 : bool store_p;
5429 : };
5430 :
5431 : /* Find a VALUE corresponding to X. */
5432 :
5433 : static inline cselib_val *
5434 181835785 : find_use_val (rtx x, machine_mode mode, struct count_use_info *cui)
5435 : {
5436 181835785 : int i;
5437 :
5438 181835785 : if (cui->sets)
5439 : {
5440 : /* This is called after uses are set up and before stores are
5441 : processed by cselib, so it's safe to look up srcs, but not
5442 : dsts. So we look up expressions that appear in srcs or in
5443 : dest expressions, but we search the sets array for dests of
5444 : stores. */
5445 181835534 : if (cui->store_p)
5446 : {
5447 : /* Some targets represent memset and memcpy patterns
5448 : by (set (mem:BLK ...) (reg:[QHSD]I ...)) or
5449 : (set (mem:BLK ...) (const_int ...)) or
5450 : (set (mem:BLK ...) (mem:BLK ...)). Don't return anything
5451 : in that case, otherwise we end up with mode mismatches. */
5452 79440495 : if (mode == BLKmode && MEM_P (x))
5453 : return NULL;
5454 90167464 : for (i = 0; i < cui->n_sets; i++)
5455 85516859 : if (cui->sets[i].dest == x)
5456 73986669 : return cui->sets[i].src_elt;
5457 : }
5458 : else
5459 102395039 : return cselib_lookup (x, mode, 0, VOIDmode);
5460 : }
5461 :
5462 : return NULL;
5463 : }
5464 :
5465 : /* Replace all registers and addresses in an expression with VALUE
5466 : expressions that map back to them, unless the expression is a
5467 : register. If no mapping is or can be performed, returns NULL. */
5468 :
5469 : static rtx
5470 53125811 : replace_expr_with_values (rtx loc)
5471 : {
5472 53125811 : if (REG_P (loc) || GET_CODE (loc) == ENTRY_VALUE)
5473 : return NULL;
5474 17485453 : else if (MEM_P (loc))
5475 : {
5476 17485453 : cselib_val *addr = cselib_lookup (XEXP (loc, 0),
5477 17485453 : get_address_mode (loc), 0,
5478 17485453 : GET_MODE (loc));
5479 17485453 : if (addr)
5480 17485453 : return replace_equiv_address_nv (loc, addr->val_rtx);
5481 : else
5482 : return NULL;
5483 : }
5484 : else
5485 0 : return cselib_subst_to_values (loc, VOIDmode);
5486 : }
5487 :
5488 : /* Return true if X contains a DEBUG_EXPR. */
5489 :
5490 : static bool
5491 35448 : rtx_debug_expr_p (const_rtx x)
5492 : {
5493 35448 : subrtx_iterator::array_type array;
5494 131554 : FOR_EACH_SUBRTX (iter, array, x, ALL)
5495 96106 : if (GET_CODE (*iter) == DEBUG_EXPR)
5496 0 : return true;
5497 35448 : return false;
5498 35448 : }
5499 :
5500 : /* Determine what kind of micro operation to choose for a USE. Return
5501 : MO_CLOBBER if no micro operation is to be generated. */
5502 :
5503 : static enum micro_operation_type
5504 376915458 : use_type (rtx loc, struct count_use_info *cui, machine_mode *modep)
5505 : {
5506 376915458 : tree expr;
5507 :
5508 376915458 : if (cui && cui->sets)
5509 : {
5510 302272303 : if (GET_CODE (loc) == VAR_LOCATION)
5511 : {
5512 37134131 : if (track_expr_p (PAT_VAR_LOCATION_DECL (loc), false))
5513 : {
5514 36605822 : rtx ploc = PAT_VAR_LOCATION_LOC (loc);
5515 36605822 : if (! VAR_LOC_UNKNOWN_P (ploc))
5516 : {
5517 19731372 : cselib_val *val = cselib_lookup (ploc, GET_MODE (loc), 1,
5518 : VOIDmode);
5519 :
5520 : /* ??? flag_float_store and volatile mems are never
5521 : given values, but we could in theory use them for
5522 : locations. */
5523 36605822 : gcc_assert (val || 1);
5524 : }
5525 36605822 : return MO_VAL_LOC;
5526 : }
5527 : else
5528 : return MO_CLOBBER;
5529 : }
5530 :
5531 265138172 : if (REG_P (loc) || MEM_P (loc))
5532 : {
5533 112029813 : if (modep)
5534 112029813 : *modep = GET_MODE (loc);
5535 112029813 : if (cui->store_p)
5536 : {
5537 42552498 : if (REG_P (loc)
5538 42552498 : || (find_use_val (loc, GET_MODE (loc), cui)
5539 8582582 : && cselib_lookup (XEXP (loc, 0),
5540 9410068 : get_address_mode (loc), 0,
5541 8582582 : GET_MODE (loc))))
5542 41725012 : return MO_VAL_SET;
5543 : }
5544 : else
5545 : {
5546 69477315 : cselib_val *val = find_use_val (loc, GET_MODE (loc), cui);
5547 :
5548 69477315 : if (val && !cselib_preserved_value_p (val))
5549 : return MO_VAL_USE;
5550 : }
5551 : }
5552 : }
5553 :
5554 282361941 : if (REG_P (loc))
5555 : {
5556 94087595 : gcc_assert (REGNO (loc) < FIRST_PSEUDO_REGISTER);
5557 :
5558 94087595 : if (loc == cfa_base_rtx)
5559 : return MO_CLOBBER;
5560 73957987 : expr = REG_EXPR (loc);
5561 :
5562 38730035 : if (!expr)
5563 : return MO_USE_NO_VAR;
5564 38641394 : else if (target_for_debug_bind (var_debug_decl (expr)))
5565 : return MO_CLOBBER;
5566 24184213 : else if (track_loc_p (loc, expr, REG_OFFSET (loc),
5567 : false, modep, NULL))
5568 : return MO_USE;
5569 : else
5570 : return MO_USE_NO_VAR;
5571 : }
5572 188274346 : else if (MEM_P (loc))
5573 : {
5574 23951139 : expr = MEM_EXPR (loc);
5575 :
5576 23951139 : if (!expr)
5577 : return MO_CLOBBER;
5578 17779682 : else if (target_for_debug_bind (var_debug_decl (expr)))
5579 : return MO_CLOBBER;
5580 16938652 : else if (track_loc_p (loc, expr, int_mem_offset (loc),
5581 : false, modep, NULL)
5582 : /* Multi-part variables shouldn't refer to one-part
5583 : variable names such as VALUEs (never happens) or
5584 : DEBUG_EXPRs (only happens in the presence of debug
5585 : insns). */
5586 16938652 : && (!MAY_HAVE_DEBUG_BIND_INSNS
5587 35448 : || !rtx_debug_expr_p (XEXP (loc, 0))))
5588 35450 : return MO_USE;
5589 : else
5590 16903202 : return MO_CLOBBER;
5591 : }
5592 :
5593 : return MO_CLOBBER;
5594 : }
5595 :
5596 : /* Log to OUT information about micro-operation MOPT involving X in
5597 : INSN of BB. */
5598 :
5599 : static inline void
5600 16 : log_op_type (rtx x, basic_block bb, rtx_insn *insn,
5601 : enum micro_operation_type mopt, FILE *out)
5602 : {
5603 16 : fprintf (out, "bb %i op %i insn %i %s ",
5604 16 : bb->index, VTI (bb)->mos.length (),
5605 16 : INSN_UID (insn), micro_operation_type_name[mopt]);
5606 16 : print_inline_rtx (out, x, 2);
5607 16 : fputc ('\n', out);
5608 16 : }
5609 :
5610 : /* Tell whether the CONCAT used to holds a VALUE and its location
5611 : needs value resolution, i.e., an attempt of mapping the location
5612 : back to other incoming values. */
5613 : #define VAL_NEEDS_RESOLUTION(x) \
5614 : (RTL_FLAG_CHECK1 ("VAL_NEEDS_RESOLUTION", (x), CONCAT)->volatil)
5615 : /* Whether the location in the CONCAT is a tracked expression, that
5616 : should also be handled like a MO_USE. */
5617 : #define VAL_HOLDS_TRACK_EXPR(x) \
5618 : (RTL_FLAG_CHECK1 ("VAL_HOLDS_TRACK_EXPR", (x), CONCAT)->used)
5619 : /* Whether the location in the CONCAT should be handled like a MO_COPY
5620 : as well. */
5621 : #define VAL_EXPR_IS_COPIED(x) \
5622 : (RTL_FLAG_CHECK1 ("VAL_EXPR_IS_COPIED", (x), CONCAT)->jump)
5623 : /* Whether the location in the CONCAT should be handled like a
5624 : MO_CLOBBER as well. */
5625 : #define VAL_EXPR_IS_CLOBBERED(x) \
5626 : (RTL_FLAG_CHECK1 ("VAL_EXPR_IS_CLOBBERED", (x), CONCAT)->unchanging)
5627 :
5628 : /* All preserved VALUEs. */
5629 : static vec<rtx> preserved_values;
5630 :
5631 : /* Ensure VAL is preserved and remember it in a vector for vt_emit_notes. */
5632 :
5633 : static void
5634 41947422 : preserve_value (cselib_val *val)
5635 : {
5636 41947422 : cselib_preserve_value (val);
5637 41947422 : preserved_values.safe_push (val->val_rtx);
5638 41947422 : }
5639 :
5640 : /* Helper function for MO_VAL_LOC handling. Return non-zero if
5641 : any rtxes not suitable for CONST use not replaced by VALUEs
5642 : are discovered. */
5643 :
5644 : static bool
5645 83647 : non_suitable_const (const_rtx x)
5646 : {
5647 83647 : subrtx_iterator::array_type array;
5648 418235 : FOR_EACH_SUBRTX (iter, array, x, ALL)
5649 : {
5650 334588 : const_rtx x = *iter;
5651 334588 : switch (GET_CODE (x))
5652 : {
5653 : case REG:
5654 : case DEBUG_EXPR:
5655 : case PC:
5656 : case SCRATCH:
5657 : case ASM_INPUT:
5658 : case ASM_OPERANDS:
5659 0 : return true;
5660 0 : case MEM:
5661 0 : if (!MEM_READONLY_P (x))
5662 : return true;
5663 : break;
5664 : default:
5665 : break;
5666 : }
5667 : }
5668 83647 : return false;
5669 83647 : }
5670 :
5671 : /* Add uses (register and memory references) LOC which will be tracked
5672 : to VTI (bb)->mos. */
5673 :
5674 : static void
5675 254931189 : add_uses (rtx loc, struct count_use_info *cui)
5676 : {
5677 254931189 : machine_mode mode = VOIDmode;
5678 254931189 : enum micro_operation_type type = use_type (loc, cui, &mode);
5679 :
5680 254931189 : if (type != MO_CLOBBER)
5681 : {
5682 72664593 : basic_block bb = cui->bb;
5683 72664593 : micro_operation mo;
5684 :
5685 72664593 : mo.type = type;
5686 72664593 : mo.u.loc = type == MO_USE ? var_lowpart (mode, loc) : loc;
5687 72664593 : mo.insn = cui->insn;
5688 :
5689 72664593 : if (type == MO_VAL_LOC)
5690 : {
5691 36605822 : rtx oloc = loc;
5692 36605822 : rtx vloc = PAT_VAR_LOCATION_LOC (oloc);
5693 36605822 : cselib_val *val;
5694 :
5695 36605822 : gcc_assert (cui->sets);
5696 :
5697 36605822 : if (MEM_P (vloc)
5698 1154838 : && !REG_P (XEXP (vloc, 0))
5699 1082869 : && !MEM_P (XEXP (vloc, 0)))
5700 : {
5701 1076713 : rtx mloc = vloc;
5702 1076713 : machine_mode address_mode = get_address_mode (mloc);
5703 1076713 : cselib_val *val
5704 2153426 : = cselib_lookup (XEXP (mloc, 0), address_mode, 0,
5705 1076713 : GET_MODE (mloc));
5706 :
5707 1076713 : if (val && !cselib_preserved_value_p (val))
5708 260418 : preserve_value (val);
5709 : }
5710 :
5711 36605822 : if (CONSTANT_P (vloc)
5712 36605822 : && (GET_CODE (vloc) != CONST || non_suitable_const (vloc)))
5713 : /* For constants don't look up any value. */;
5714 16874450 : else if (!VAR_LOC_UNKNOWN_P (vloc) && !unsuitable_loc (vloc)
5715 51321150 : && (val = find_use_val (vloc, GET_MODE (oloc), cui)))
5716 : {
5717 17221829 : machine_mode mode2;
5718 17221829 : enum micro_operation_type type2;
5719 17221829 : rtx nloc = NULL;
5720 17221829 : bool resolvable = REG_P (vloc) || MEM_P (vloc);
5721 :
5722 17221829 : if (resolvable)
5723 6007786 : nloc = replace_expr_with_values (vloc);
5724 :
5725 6007786 : if (nloc)
5726 : {
5727 1153479 : oloc = shallow_copy_rtx (oloc);
5728 1153479 : PAT_VAR_LOCATION_LOC (oloc) = nloc;
5729 : }
5730 :
5731 17221829 : oloc = gen_rtx_CONCAT (mode, val->val_rtx, oloc);
5732 :
5733 17221829 : type2 = use_type (vloc, 0, &mode2);
5734 :
5735 17221829 : gcc_assert (type2 == MO_USE || type2 == MO_USE_NO_VAR
5736 : || type2 == MO_CLOBBER);
5737 :
5738 17221829 : if (type2 == MO_CLOBBER
5739 17221829 : && !cselib_preserved_value_p (val))
5740 : {
5741 4888473 : VAL_NEEDS_RESOLUTION (oloc) = resolvable;
5742 4888473 : preserve_value (val);
5743 : }
5744 : }
5745 16875971 : else if (!VAR_LOC_UNKNOWN_P (vloc))
5746 : {
5747 1521 : oloc = shallow_copy_rtx (oloc);
5748 1521 : PAT_VAR_LOCATION_LOC (oloc) = gen_rtx_UNKNOWN_VAR_LOC ();
5749 : }
5750 :
5751 36605822 : mo.u.loc = oloc;
5752 : }
5753 36058771 : else if (type == MO_VAL_USE)
5754 : {
5755 15694374 : machine_mode mode2 = VOIDmode;
5756 15694374 : enum micro_operation_type type2;
5757 15694374 : cselib_val *val = find_use_val (loc, GET_MODE (loc), cui);
5758 15694374 : rtx vloc, oloc = loc, nloc;
5759 :
5760 15694374 : gcc_assert (cui->sets);
5761 :
5762 15694374 : if (MEM_P (oloc)
5763 7749392 : && !REG_P (XEXP (oloc, 0))
5764 6682992 : && !MEM_P (XEXP (oloc, 0)))
5765 : {
5766 6681622 : rtx mloc = oloc;
5767 6681622 : machine_mode address_mode = get_address_mode (mloc);
5768 6681622 : cselib_val *val
5769 13363244 : = cselib_lookup (XEXP (mloc, 0), address_mode, 0,
5770 6681622 : GET_MODE (mloc));
5771 :
5772 6681622 : if (val && !cselib_preserved_value_p (val))
5773 2592009 : preserve_value (val);
5774 : }
5775 :
5776 15694374 : type2 = use_type (loc, 0, &mode2);
5777 :
5778 15694374 : gcc_assert (type2 == MO_USE || type2 == MO_USE_NO_VAR
5779 : || type2 == MO_CLOBBER);
5780 :
5781 15694374 : if (type2 == MO_USE)
5782 250869 : vloc = var_lowpart (mode2, loc);
5783 : else
5784 : vloc = oloc;
5785 :
5786 : /* The loc of a MO_VAL_USE may have two forms:
5787 :
5788 : (concat val src): val is at src, a value-based
5789 : representation.
5790 :
5791 : (concat (concat val use) src): same as above, with use as
5792 : the MO_USE tracked value, if it differs from src.
5793 :
5794 : */
5795 :
5796 15694374 : gcc_checking_assert (REG_P (loc) || MEM_P (loc));
5797 15694374 : nloc = replace_expr_with_values (loc);
5798 15694374 : if (!nloc)
5799 7944982 : nloc = oloc;
5800 :
5801 15694374 : if (vloc != nloc)
5802 7749623 : oloc = gen_rtx_CONCAT (mode2, val->val_rtx, vloc);
5803 : else
5804 7944751 : oloc = val->val_rtx;
5805 :
5806 15694374 : mo.u.loc = gen_rtx_CONCAT (mode, oloc, nloc);
5807 :
5808 15694374 : if (type2 == MO_USE)
5809 250869 : VAL_HOLDS_TRACK_EXPR (mo.u.loc) = 1;
5810 15694374 : if (!cselib_preserved_value_p (val))
5811 : {
5812 15694374 : VAL_NEEDS_RESOLUTION (mo.u.loc) = 1;
5813 15694374 : preserve_value (val);
5814 : }
5815 : }
5816 : else
5817 20364397 : gcc_assert (type == MO_USE || type == MO_USE_NO_VAR);
5818 :
5819 72664593 : if (dump_file && (dump_flags & TDF_DETAILS))
5820 4 : log_op_type (mo.u.loc, cui->bb, cui->insn, mo.type, dump_file);
5821 72664593 : VTI (bb)->mos.safe_push (mo);
5822 : }
5823 254931189 : }
5824 :
5825 : /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
5826 :
5827 : static void
5828 91983842 : add_uses_1 (rtx *x, void *cui)
5829 : {
5830 91983842 : subrtx_var_iterator::array_type array;
5831 346915031 : FOR_EACH_SUBRTX_VAR (iter, array, *x, NONCONST)
5832 254931189 : add_uses (*iter, (struct count_use_info *) cui);
5833 91983842 : }
5834 :
5835 : /* This is the value used during expansion of locations. We want it
5836 : to be unbounded, so that variables expanded deep in a recursion
5837 : nest are fully evaluated, so that their values are cached
5838 : correctly. We avoid recursion cycles through other means, and we
5839 : don't unshare RTL, so excess complexity is not a problem. */
5840 : #define EXPR_DEPTH (INT_MAX)
5841 : /* We use this to keep too-complex expressions from being emitted as
5842 : location notes, and then to debug information. Users can trade
5843 : compile time for ridiculously complex expressions, although they're
5844 : seldom useful, and they may often have to be discarded as not
5845 : representable anyway. */
5846 : #define EXPR_USE_DEPTH (param_max_vartrack_expr_depth)
5847 :
5848 : /* Attempt to reverse the EXPR operation in the debug info and record
5849 : it in the cselib table. Say for reg1 = reg2 + 6 even when reg2 is
5850 : no longer live we can express its value as VAL - 6. */
5851 :
5852 : static void
5853 31423651 : reverse_op (rtx val, const_rtx expr, rtx_insn *insn)
5854 : {
5855 31423651 : rtx src, arg, ret;
5856 31423651 : cselib_val *v;
5857 31423651 : struct elt_loc_list *l;
5858 31423651 : enum rtx_code code;
5859 31423651 : int count;
5860 :
5861 31423651 : if (GET_CODE (expr) != SET)
5862 : return;
5863 :
5864 31423651 : if (!REG_P (SET_DEST (expr)) || GET_MODE (val) != GET_MODE (SET_DEST (expr)))
5865 : return;
5866 :
5867 22824717 : src = SET_SRC (expr);
5868 22824717 : switch (GET_CODE (src))
5869 : {
5870 4182588 : case PLUS:
5871 4182588 : case MINUS:
5872 4182588 : case XOR:
5873 4182588 : case NOT:
5874 4182588 : case NEG:
5875 4182588 : if (!REG_P (XEXP (src, 0)))
5876 : return;
5877 : break;
5878 290132 : case SIGN_EXTEND:
5879 290132 : case ZERO_EXTEND:
5880 290132 : if (!REG_P (XEXP (src, 0)) && !MEM_P (XEXP (src, 0)))
5881 : return;
5882 : break;
5883 : default:
5884 : return;
5885 : }
5886 :
5887 4218222 : if (!SCALAR_INT_MODE_P (GET_MODE (src)) || XEXP (src, 0) == cfa_base_rtx)
5888 : return;
5889 :
5890 2917294 : v = cselib_lookup (XEXP (src, 0), GET_MODE (XEXP (src, 0)), 0, VOIDmode);
5891 2917294 : if (!v || !cselib_preserved_value_p (v))
5892 0 : return;
5893 :
5894 : /* Use canonical V to avoid creating multiple redundant expressions
5895 : for different VALUES equivalent to V. */
5896 2917294 : v = canonical_cselib_val (v);
5897 :
5898 : /* Adding a reverse op isn't useful if V already has an always valid
5899 : location. Ignore ENTRY_VALUE, while it is always constant, we should
5900 : prefer non-ENTRY_VALUE locations whenever possible. */
5901 8027671 : for (l = v->locs, count = 0; l; l = l->next, count++)
5902 5143344 : if (CONSTANT_P (l->loc)
5903 5143344 : && (GET_CODE (l->loc) != CONST || !references_value_p (l->loc, 0)))
5904 32067 : return;
5905 : /* Avoid creating too large locs lists. */
5906 5111277 : else if (count == param_max_vartrack_reverse_op_size)
5907 : return;
5908 :
5909 2884327 : switch (GET_CODE (src))
5910 : {
5911 42443 : case NOT:
5912 42443 : case NEG:
5913 42443 : if (GET_MODE (v->val_rtx) != GET_MODE (val))
5914 : return;
5915 42443 : ret = gen_rtx_fmt_e (GET_CODE (src), GET_MODE (val), val);
5916 42443 : break;
5917 254948 : case SIGN_EXTEND:
5918 254948 : case ZERO_EXTEND:
5919 254948 : ret = gen_lowpart_SUBREG (GET_MODE (v->val_rtx), val);
5920 254948 : break;
5921 46661 : case XOR:
5922 46661 : code = XOR;
5923 46661 : goto binary;
5924 2299610 : case PLUS:
5925 2299610 : code = MINUS;
5926 2299610 : goto binary;
5927 240665 : case MINUS:
5928 240665 : code = PLUS;
5929 240665 : goto binary;
5930 2586936 : binary:
5931 2586936 : if (GET_MODE (v->val_rtx) != GET_MODE (val))
5932 : return;
5933 2586936 : arg = XEXP (src, 1);
5934 2586936 : if (!CONST_INT_P (arg) && GET_CODE (arg) != SYMBOL_REF)
5935 : {
5936 705175 : arg = cselib_expand_value_rtx (arg, scratch_regs, 5);
5937 705175 : if (arg == NULL_RTX)
5938 : return;
5939 705175 : if (!CONST_INT_P (arg) && GET_CODE (arg) != SYMBOL_REF)
5940 : return;
5941 : }
5942 1886323 : ret = simplify_gen_binary (code, GET_MODE (val), val, arg);
5943 1886323 : break;
5944 0 : default:
5945 0 : gcc_unreachable ();
5946 : }
5947 :
5948 2183714 : cselib_add_permanent_equiv (v, ret, insn);
5949 : }
5950 :
5951 : /* Add stores (register and memory references) LOC which will be tracked
5952 : to VTI (bb)->mos. EXPR is the RTL expression containing the store.
5953 : CUIP->insn is instruction which the LOC is part of. */
5954 :
5955 : static void
5956 47342767 : add_stores (rtx loc, const_rtx expr, void *cuip)
5957 : {
5958 47342767 : machine_mode mode = VOIDmode, mode2;
5959 47342767 : struct count_use_info *cui = (struct count_use_info *)cuip;
5960 47342767 : basic_block bb = cui->bb;
5961 47342767 : micro_operation mo;
5962 47342767 : rtx oloc = loc, nloc, src = NULL;
5963 47342767 : enum micro_operation_type type = use_type (loc, cui, &mode);
5964 47342767 : bool track_p = false;
5965 47342767 : cselib_val *v;
5966 47342767 : bool resolve, preserve;
5967 :
5968 47342767 : if (type == MO_CLOBBER)
5969 9872838 : return;
5970 :
5971 41725363 : mode2 = mode;
5972 :
5973 41725363 : if (REG_P (loc))
5974 : {
5975 33142778 : gcc_assert (loc != cfa_base_rtx);
5976 4637318 : if ((GET_CODE (expr) == CLOBBER && type != MO_VAL_SET)
5977 33142714 : || !(track_p = use_type (loc, NULL, &mode2) == MO_USE)
5978 33320815 : || GET_CODE (expr) == CLOBBER)
5979 : {
5980 32965297 : mo.type = MO_CLOBBER;
5981 32965297 : mo.u.loc = loc;
5982 32965297 : if (GET_CODE (expr) == SET
5983 28327979 : && (SET_DEST (expr) == loc
5984 29276 : || (GET_CODE (SET_DEST (expr)) == STRICT_LOW_PART
5985 16257 : && XEXP (SET_DEST (expr), 0) == loc))
5986 28314960 : && !unsuitable_loc (SET_SRC (expr))
5987 61270963 : && find_use_val (loc, mode, cui))
5988 : {
5989 26992797 : gcc_checking_assert (type == MO_VAL_SET);
5990 26992797 : mo.u.loc = gen_rtx_SET (loc, SET_SRC (expr));
5991 : }
5992 : }
5993 : else
5994 : {
5995 177481 : if (GET_CODE (expr) == SET
5996 177481 : && SET_DEST (expr) == loc
5997 177331 : && GET_CODE (SET_SRC (expr)) != ASM_OPERANDS)
5998 177329 : src = var_lowpart (mode2, SET_SRC (expr));
5999 177481 : loc = var_lowpart (mode2, loc);
6000 :
6001 177481 : if (src == NULL)
6002 : {
6003 5003 : mo.type = MO_SET;
6004 5003 : mo.u.loc = loc;
6005 : }
6006 : else
6007 : {
6008 172478 : rtx xexpr = gen_rtx_SET (loc, src);
6009 172478 : if (same_variable_part_p (src, REG_EXPR (loc), REG_OFFSET (loc)))
6010 : {
6011 : /* If this is an instruction copying (part of) a parameter
6012 : passed by invisible reference to its register location,
6013 : pretend it's a SET so that the initial memory location
6014 : is discarded, as the parameter register can be reused
6015 : for other purposes and we do not track locations based
6016 : on generic registers. */
6017 66591 : if (MEM_P (src)
6018 9898 : && REG_EXPR (loc)
6019 9898 : && TREE_CODE (REG_EXPR (loc)) == PARM_DECL
6020 9896 : && DECL_MODE (REG_EXPR (loc)) != BLKmode
6021 9896 : && MEM_P (DECL_INCOMING_RTL (REG_EXPR (loc)))
6022 66591 : && XEXP (DECL_INCOMING_RTL (REG_EXPR (loc)), 0)
6023 9572 : != arg_pointer_rtx)
6024 6218 : mo.type = MO_SET;
6025 : else
6026 60373 : mo.type = MO_COPY;
6027 : }
6028 : else
6029 105887 : mo.type = MO_SET;
6030 172478 : mo.u.loc = xexpr;
6031 : }
6032 : }
6033 33142778 : mo.insn = cui->insn;
6034 : }
6035 8582585 : else if (MEM_P (loc)
6036 8582585 : && ((track_p = use_type (loc, NULL, &mode2) == MO_USE)
6037 8578132 : || cui->sets))
6038 : {
6039 8582585 : if (MEM_P (loc) && type == MO_VAL_SET
6040 8582582 : && !REG_P (XEXP (loc, 0))
6041 7970804 : && !MEM_P (XEXP (loc, 0)))
6042 : {
6043 7970804 : rtx mloc = loc;
6044 7970804 : machine_mode address_mode = get_address_mode (mloc);
6045 15941608 : cselib_val *val = cselib_lookup (XEXP (mloc, 0),
6046 : address_mode, 0,
6047 7970804 : GET_MODE (mloc));
6048 :
6049 7970804 : if (val && !cselib_preserved_value_p (val))
6050 3294058 : preserve_value (val);
6051 : }
6052 :
6053 8582585 : if (GET_CODE (expr) == CLOBBER || !track_p)
6054 : {
6055 8578135 : mo.type = MO_CLOBBER;
6056 17156267 : mo.u.loc = track_p ? var_lowpart (mode2, loc) : loc;
6057 : }
6058 : else
6059 : {
6060 4450 : if (GET_CODE (expr) == SET
6061 4450 : && SET_DEST (expr) == loc
6062 4450 : && GET_CODE (SET_SRC (expr)) != ASM_OPERANDS)
6063 4450 : src = var_lowpart (mode2, SET_SRC (expr));
6064 4450 : loc = var_lowpart (mode2, loc);
6065 :
6066 4450 : if (src == NULL)
6067 : {
6068 8 : mo.type = MO_SET;
6069 8 : mo.u.loc = loc;
6070 : }
6071 : else
6072 : {
6073 4442 : rtx xexpr = gen_rtx_SET (loc, src);
6074 4442 : if (same_variable_part_p (SET_SRC (xexpr),
6075 4442 : MEM_EXPR (loc),
6076 4442 : int_mem_offset (loc)))
6077 2549 : mo.type = MO_COPY;
6078 : else
6079 1893 : mo.type = MO_SET;
6080 4442 : mo.u.loc = xexpr;
6081 : }
6082 : }
6083 8582585 : mo.insn = cui->insn;
6084 : }
6085 : else
6086 0 : return;
6087 :
6088 41725363 : if (type != MO_VAL_SET)
6089 351 : goto log_and_return;
6090 :
6091 41725012 : v = find_use_val (oloc, mode, cui);
6092 :
6093 41725012 : if (!v)
6094 5968515 : goto log_and_return;
6095 :
6096 35756497 : resolve = preserve = !cselib_preserved_value_p (v);
6097 :
6098 : /* We cannot track values for multiple-part variables, so we track only
6099 : locations for tracked record parameters. */
6100 35756497 : if (track_p
6101 181861 : && REG_P (loc)
6102 177411 : && REG_EXPR (loc)
6103 35933908 : && tracked_record_parameter_p (REG_EXPR (loc)))
6104 : {
6105 : /* Although we don't use the value here, it could be used later by the
6106 : mere virtue of its existence as the operand of the reverse operation
6107 : that gave rise to it (typically extension/truncation). Make sure it
6108 : is preserved as required by vt_expand_var_loc_chain. */
6109 77412 : if (preserve)
6110 1356 : preserve_value (v);
6111 77412 : goto log_and_return;
6112 : }
6113 :
6114 35679085 : if (loc == stack_pointer_rtx
6115 5156296 : && (maybe_ne (hard_frame_pointer_adjustment, -1)
6116 4316605 : || (!frame_pointer_needed && !ACCUMULATE_OUTGOING_ARGS))
6117 40774213 : && preserve)
6118 1890125 : cselib_set_value_sp_based (v);
6119 :
6120 : /* Don't record MO_VAL_SET for VALUEs that can be described using
6121 : cfa_base_rtx or cfa_base_rtx + CONST_INT, cselib already knows
6122 : all the needed equivalences and they shouldn't change depending
6123 : on which register holds that VALUE in some instruction. */
6124 35679085 : if (!frame_pointer_needed
6125 30707930 : && cfa_base_rtx
6126 30705560 : && cselib_sp_derived_value_p (v)
6127 41211283 : && loc == stack_pointer_rtx)
6128 : {
6129 4255434 : if (preserve)
6130 1352363 : preserve_value (v);
6131 4255434 : return;
6132 : }
6133 :
6134 31423651 : nloc = replace_expr_with_values (oloc);
6135 31423651 : if (nloc)
6136 8582582 : oloc = nloc;
6137 :
6138 31423651 : if (GET_CODE (PATTERN (cui->insn)) == COND_EXEC)
6139 : {
6140 0 : cselib_val *oval = cselib_lookup (oloc, GET_MODE (oloc), 0, VOIDmode);
6141 :
6142 0 : if (oval == v)
6143 : return;
6144 0 : gcc_assert (REG_P (oloc) || MEM_P (oloc));
6145 :
6146 0 : if (oval && !cselib_preserved_value_p (oval))
6147 : {
6148 0 : micro_operation moa;
6149 :
6150 0 : preserve_value (oval);
6151 :
6152 0 : moa.type = MO_VAL_USE;
6153 0 : moa.u.loc = gen_rtx_CONCAT (mode, oval->val_rtx, oloc);
6154 0 : VAL_NEEDS_RESOLUTION (moa.u.loc) = 1;
6155 0 : moa.insn = cui->insn;
6156 :
6157 0 : if (dump_file && (dump_flags & TDF_DETAILS))
6158 0 : log_op_type (moa.u.loc, cui->bb, cui->insn,
6159 : moa.type, dump_file);
6160 0 : VTI (bb)->mos.safe_push (moa);
6161 : }
6162 :
6163 : resolve = false;
6164 : }
6165 31423651 : else if (resolve && GET_CODE (mo.u.loc) == SET)
6166 : {
6167 10155119 : if (REG_P (SET_SRC (expr)) || MEM_P (SET_SRC (expr)))
6168 0 : nloc = replace_expr_with_values (SET_SRC (expr));
6169 : else
6170 : nloc = NULL_RTX;
6171 :
6172 : /* Avoid the mode mismatch between oexpr and expr. */
6173 10155119 : if (!nloc && mode != mode2)
6174 : {
6175 0 : nloc = SET_SRC (expr);
6176 0 : gcc_assert (oloc == SET_DEST (expr));
6177 : }
6178 :
6179 10155119 : if (nloc && nloc != SET_SRC (mo.u.loc))
6180 0 : oloc = gen_rtx_SET (oloc, nloc);
6181 : else
6182 : {
6183 10155119 : if (oloc == SET_DEST (mo.u.loc))
6184 : /* No point in duplicating. */
6185 10155118 : oloc = mo.u.loc;
6186 10155119 : if (!REG_P (SET_SRC (mo.u.loc)))
6187 10155119 : resolve = false;
6188 : }
6189 : }
6190 : else if (!resolve)
6191 : {
6192 20378644 : if (GET_CODE (mo.u.loc) == SET
6193 12681935 : && oloc == SET_DEST (mo.u.loc))
6194 : /* No point in duplicating. */
6195 12677492 : oloc = mo.u.loc;
6196 : }
6197 : else
6198 : resolve = false;
6199 :
6200 31423651 : loc = gen_rtx_CONCAT (mode, v->val_rtx, oloc);
6201 :
6202 31423651 : if (mo.u.loc != oloc)
6203 8582748 : loc = gen_rtx_CONCAT (GET_MODE (mo.u.loc), loc, mo.u.loc);
6204 :
6205 : /* The loc of a MO_VAL_SET may have various forms:
6206 :
6207 : (concat val dst): dst now holds val
6208 :
6209 : (concat val (set dst src)): dst now holds val, copied from src
6210 :
6211 : (concat (concat val dstv) dst): dst now holds val; dstv is dst
6212 : after replacing mems and non-top-level regs with values.
6213 :
6214 : (concat (concat val dstv) (set dst src)): dst now holds val,
6215 : copied from src. dstv is a value-based representation of dst, if
6216 : it differs from dst. If resolution is needed, src is a REG, and
6217 : its mode is the same as that of val.
6218 :
6219 : (concat (concat val (set dstv srcv)) (set dst src)): src
6220 : copied to dst, holding val. dstv and srcv are value-based
6221 : representations of dst and src, respectively.
6222 :
6223 : */
6224 :
6225 31423651 : if (GET_CODE (PATTERN (cui->insn)) != COND_EXEC)
6226 31423651 : reverse_op (v->val_rtx, expr, cui->insn);
6227 :
6228 31423651 : mo.u.loc = loc;
6229 :
6230 31423651 : if (track_p)
6231 104449 : VAL_HOLDS_TRACK_EXPR (loc) = 1;
6232 31423651 : if (preserve)
6233 : {
6234 11045007 : VAL_NEEDS_RESOLUTION (loc) = resolve;
6235 11045007 : preserve_value (v);
6236 : }
6237 31423651 : if (mo.type == MO_CLOBBER)
6238 31319202 : VAL_EXPR_IS_CLOBBERED (loc) = 1;
6239 31423651 : if (mo.type == MO_COPY)
6240 19834 : VAL_EXPR_IS_COPIED (loc) = 1;
6241 :
6242 31423651 : mo.type = MO_VAL_SET;
6243 :
6244 37469929 : log_and_return:
6245 37469929 : if (dump_file && (dump_flags & TDF_DETAILS))
6246 8 : log_op_type (mo.u.loc, cui->bb, cui->insn, mo.type, dump_file);
6247 37469929 : VTI (bb)->mos.safe_push (mo);
6248 : }
6249 :
6250 : /* Arguments to the call. */
6251 : static rtx call_arguments;
6252 :
6253 : /* Compute call_arguments. */
6254 :
6255 : static void
6256 3141934 : prepare_call_arguments (basic_block bb, rtx_insn *insn)
6257 : {
6258 3141934 : rtx link, x, call;
6259 3141934 : rtx prev, cur, next;
6260 3141934 : rtx this_arg = NULL_RTX;
6261 3141934 : tree type = NULL_TREE, t, fndecl = NULL_TREE;
6262 3141934 : tree obj_type_ref = NULL_TREE;
6263 3141934 : CUMULATIVE_ARGS args_so_far_v;
6264 3141934 : cumulative_args_t args_so_far;
6265 :
6266 3141934 : memset (&args_so_far_v, 0, sizeof (args_so_far_v));
6267 3141934 : args_so_far = pack_cumulative_args (&args_so_far_v);
6268 3141934 : call = get_call_rtx_from (insn);
6269 3141934 : if (call)
6270 : {
6271 3141934 : if (GET_CODE (XEXP (XEXP (call, 0), 0)) == SYMBOL_REF)
6272 : {
6273 3016095 : rtx symbol = XEXP (XEXP (call, 0), 0);
6274 3016095 : if (SYMBOL_REF_DECL (symbol))
6275 : fndecl = SYMBOL_REF_DECL (symbol);
6276 : }
6277 3141934 : if (fndecl == NULL_TREE && MEM_P (XEXP (call, 0)))
6278 601176 : fndecl = MEM_EXPR (XEXP (call, 0));
6279 360343 : if (fndecl
6280 2901101 : && TREE_CODE (TREE_TYPE (fndecl)) != FUNCTION_TYPE
6281 857277 : && TREE_CODE (TREE_TYPE (fndecl)) != METHOD_TYPE)
6282 : fndecl = NULL_TREE;
6283 3141931 : if (fndecl && TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
6284 2849147 : type = TREE_TYPE (fndecl);
6285 3141934 : if (fndecl && TREE_CODE (fndecl) != FUNCTION_DECL)
6286 : {
6287 119510 : if (INDIRECT_REF_P (fndecl)
6288 119510 : && TREE_CODE (TREE_OPERAND (fndecl, 0)) == OBJ_TYPE_REF)
6289 0 : obj_type_ref = TREE_OPERAND (fndecl, 0);
6290 : fndecl = NULL_TREE;
6291 : }
6292 3141934 : if (type)
6293 : {
6294 8055507 : for (t = TYPE_ARG_TYPES (type); t && t != void_list_node;
6295 5206360 : t = TREE_CHAIN (t))
6296 5224835 : if (TREE_CODE (TREE_VALUE (t)) == REFERENCE_TYPE
6297 5224835 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_VALUE (t))))
6298 : break;
6299 2849147 : if ((t == NULL || t == void_list_node) && obj_type_ref == NULL_TREE)
6300 : type = NULL;
6301 : else
6302 : {
6303 18475 : int nargs ATTRIBUTE_UNUSED = list_length (TYPE_ARG_TYPES (type));
6304 18475 : link = CALL_INSN_FUNCTION_USAGE (insn);
6305 : #ifndef PCC_STATIC_STRUCT_RETURN
6306 18475 : if (aggregate_value_p (TREE_TYPE (type), type)
6307 18475 : && targetm.calls.struct_value_rtx (type, 0) == 0)
6308 : {
6309 717 : tree struct_addr = build_pointer_type (TREE_TYPE (type));
6310 717 : function_arg_info arg (struct_addr, /*named=*/true);
6311 717 : rtx reg;
6312 717 : INIT_CUMULATIVE_ARGS (args_so_far_v, type, NULL_RTX, fndecl,
6313 : nargs + 1);
6314 717 : reg = targetm.calls.function_arg (args_so_far, arg);
6315 717 : targetm.calls.function_arg_advance (args_so_far, arg);
6316 717 : if (reg == NULL_RTX)
6317 : {
6318 522 : for (; link; link = XEXP (link, 1))
6319 522 : if (GET_CODE (XEXP (link, 0)) == USE
6320 522 : && MEM_P (XEXP (XEXP (link, 0), 0)))
6321 : {
6322 316 : link = XEXP (link, 1);
6323 316 : break;
6324 : }
6325 : }
6326 : }
6327 : else
6328 : #endif
6329 17758 : INIT_CUMULATIVE_ARGS (args_so_far_v, type, NULL_RTX, fndecl,
6330 : nargs);
6331 18475 : if (obj_type_ref && TYPE_ARG_TYPES (type) != void_list_node)
6332 : {
6333 0 : t = TYPE_ARG_TYPES (type);
6334 0 : function_arg_info arg (TREE_VALUE (t), /*named=*/true);
6335 0 : this_arg = targetm.calls.function_arg (args_so_far, arg);
6336 0 : if (this_arg && !REG_P (this_arg))
6337 : this_arg = NULL_RTX;
6338 : else if (this_arg == NULL_RTX)
6339 : {
6340 0 : for (; link; link = XEXP (link, 1))
6341 0 : if (GET_CODE (XEXP (link, 0)) == USE
6342 0 : && MEM_P (XEXP (XEXP (link, 0), 0)))
6343 : {
6344 : this_arg = XEXP (XEXP (link, 0), 0);
6345 : break;
6346 : }
6347 : }
6348 : }
6349 : }
6350 : }
6351 : }
6352 18475 : t = type ? TYPE_ARG_TYPES (type) : NULL_TREE;
6353 :
6354 8822718 : for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
6355 5680784 : if (GET_CODE (XEXP (link, 0)) == USE)
6356 : {
6357 5634402 : rtx item = NULL_RTX;
6358 5634402 : x = XEXP (XEXP (link, 0), 0);
6359 5634402 : if (GET_MODE (link) == VOIDmode
6360 4661165 : || GET_MODE (link) == BLKmode
6361 3934642 : || (GET_MODE (link) != GET_MODE (x)
6362 106901 : && ((GET_MODE_CLASS (GET_MODE (link)) != MODE_INT
6363 106901 : && GET_MODE_CLASS (GET_MODE (link)) != MODE_PARTIAL_INT)
6364 106901 : || (GET_MODE_CLASS (GET_MODE (x)) != MODE_INT
6365 106901 : && GET_MODE_CLASS (GET_MODE (x)) != MODE_PARTIAL_INT))))
6366 : /* Can't do anything for these, if the original type mode
6367 : isn't known or can't be converted. */;
6368 3934642 : else if (REG_P (x))
6369 : {
6370 3925572 : cselib_val *val = cselib_lookup (x, GET_MODE (x), 0, VOIDmode);
6371 3925572 : scalar_int_mode mode;
6372 3925572 : if (val && cselib_preserved_value_p (val))
6373 3554767 : item = val->val_rtx;
6374 370805 : else if (is_a <scalar_int_mode> (GET_MODE (x), &mode))
6375 : {
6376 367437 : opt_scalar_int_mode mode_iter;
6377 389463 : FOR_EACH_WIDER_MODE (mode_iter, mode)
6378 : {
6379 389463 : mode = mode_iter.require ();
6380 781952 : if (GET_MODE_BITSIZE (mode) > BITS_PER_WORD)
6381 : break;
6382 :
6383 81947 : rtx reg = simplify_subreg (mode, x, GET_MODE (x), 0);
6384 81947 : if (reg == NULL_RTX || !REG_P (reg))
6385 0 : continue;
6386 81947 : val = cselib_lookup (reg, mode, 0, VOIDmode);
6387 81947 : if (val && cselib_preserved_value_p (val))
6388 : {
6389 59921 : item = val->val_rtx;
6390 59921 : break;
6391 : }
6392 : }
6393 : }
6394 : }
6395 9070 : else if (MEM_P (x))
6396 : {
6397 9070 : rtx mem = x;
6398 9070 : cselib_val *val;
6399 :
6400 9070 : if (!frame_pointer_needed)
6401 : {
6402 8622 : class adjust_mem_data amd;
6403 8622 : amd.mem_mode = VOIDmode;
6404 8622 : amd.stack_adjust = -VTI (bb)->out.stack_adjust;
6405 8622 : amd.store = true;
6406 8622 : mem = simplify_replace_fn_rtx (mem, NULL_RTX, adjust_mems,
6407 : &amd);
6408 8622 : gcc_assert (amd.side_effects.is_empty ());
6409 8622 : }
6410 9070 : val = cselib_lookup (mem, GET_MODE (mem), 0, VOIDmode);
6411 9070 : if (val && cselib_preserved_value_p (val))
6412 3233 : item = val->val_rtx;
6413 5837 : else if (GET_MODE_CLASS (GET_MODE (mem)) != MODE_INT
6414 5837 : && GET_MODE_CLASS (GET_MODE (mem)) != MODE_PARTIAL_INT)
6415 : {
6416 : /* For non-integer stack argument see also if they weren't
6417 : initialized by integers. */
6418 258 : scalar_int_mode imode;
6419 258 : if (int_mode_for_mode (GET_MODE (mem)).exists (&imode)
6420 223 : && imode != GET_MODE (mem))
6421 : {
6422 223 : val = cselib_lookup (adjust_address_nv (mem, imode, 0),
6423 : imode, 0, VOIDmode);
6424 223 : if (val && cselib_preserved_value_p (val))
6425 0 : item = lowpart_subreg (GET_MODE (x), val->val_rtx,
6426 : imode);
6427 : }
6428 : }
6429 : }
6430 3925472 : if (item)
6431 : {
6432 3617921 : rtx x2 = x;
6433 3617921 : if (GET_MODE (item) != GET_MODE (link))
6434 131701 : item = lowpart_subreg (GET_MODE (link), item, GET_MODE (item));
6435 3617921 : if (GET_MODE (x2) != GET_MODE (link))
6436 102003 : x2 = lowpart_subreg (GET_MODE (link), x2, GET_MODE (x2));
6437 3617921 : item = gen_rtx_CONCAT (GET_MODE (link), x2, item);
6438 3617921 : call_arguments
6439 3617921 : = gen_rtx_EXPR_LIST (VOIDmode, item, call_arguments);
6440 : }
6441 5634402 : if (t && t != void_list_node)
6442 : {
6443 64030 : rtx reg;
6444 64030 : function_arg_info arg (TREE_VALUE (t), /*named=*/true);
6445 64030 : apply_pass_by_reference_rules (&args_so_far_v, arg);
6446 64030 : reg = targetm.calls.function_arg (args_so_far, arg);
6447 64030 : if (TREE_CODE (arg.type) == REFERENCE_TYPE
6448 31608 : && INTEGRAL_TYPE_P (TREE_TYPE (arg.type))
6449 22018 : && reg
6450 19133 : && REG_P (reg)
6451 19133 : && GET_MODE (reg) == arg.mode
6452 19133 : && (GET_MODE_CLASS (arg.mode) == MODE_INT
6453 19133 : || GET_MODE_CLASS (arg.mode) == MODE_PARTIAL_INT)
6454 19133 : && REG_P (x)
6455 19113 : && REGNO (x) == REGNO (reg)
6456 18325 : && GET_MODE (x) == arg.mode
6457 82355 : && item)
6458 : {
6459 17927 : machine_mode indmode
6460 17927 : = TYPE_MODE (TREE_TYPE (arg.type));
6461 17927 : rtx mem = gen_rtx_MEM (indmode, x);
6462 17927 : cselib_val *val = cselib_lookup (mem, indmode, 0, VOIDmode);
6463 17927 : if (val && cselib_preserved_value_p (val))
6464 : {
6465 7447 : item = gen_rtx_CONCAT (indmode, mem, val->val_rtx);
6466 7447 : call_arguments = gen_rtx_EXPR_LIST (VOIDmode, item,
6467 : call_arguments);
6468 : }
6469 : else
6470 : {
6471 10480 : struct elt_loc_list *l;
6472 10480 : tree initial;
6473 :
6474 : /* Try harder, when passing address of a constant
6475 : pool integer it can be easily read back. */
6476 10480 : item = XEXP (item, 1);
6477 10480 : if (GET_CODE (item) == SUBREG)
6478 0 : item = SUBREG_REG (item);
6479 10480 : gcc_assert (GET_CODE (item) == VALUE);
6480 10480 : val = CSELIB_VAL_PTR (item);
6481 30326 : for (l = val->locs; l; l = l->next)
6482 22741 : if (GET_CODE (l->loc) == SYMBOL_REF
6483 3012 : && TREE_CONSTANT_POOL_ADDRESS_P (l->loc)
6484 2895 : && SYMBOL_REF_DECL (l->loc)
6485 25636 : && DECL_INITIAL (SYMBOL_REF_DECL (l->loc)))
6486 : {
6487 2895 : initial = DECL_INITIAL (SYMBOL_REF_DECL (l->loc));
6488 2895 : if (tree_fits_shwi_p (initial))
6489 : {
6490 2895 : item = GEN_INT (tree_to_shwi (initial));
6491 2895 : item = gen_rtx_CONCAT (indmode, mem, item);
6492 2895 : call_arguments
6493 2895 : = gen_rtx_EXPR_LIST (VOIDmode, item,
6494 : call_arguments);
6495 : }
6496 : break;
6497 : }
6498 : }
6499 : }
6500 64030 : targetm.calls.function_arg_advance (args_so_far, arg);
6501 64030 : t = TREE_CHAIN (t);
6502 : }
6503 : }
6504 :
6505 : /* Add debug arguments. */
6506 3141934 : if (fndecl
6507 2781588 : && TREE_CODE (fndecl) == FUNCTION_DECL
6508 5923522 : && DECL_HAS_DEBUG_ARGS_P (fndecl))
6509 : {
6510 64918 : vec<tree, va_gc> **debug_args = decl_debug_args_lookup (fndecl);
6511 64918 : if (debug_args)
6512 : {
6513 : unsigned int ix;
6514 : tree param;
6515 142012 : for (ix = 0; vec_safe_iterate (*debug_args, ix, ¶m); ix += 2)
6516 : {
6517 77094 : rtx item;
6518 77094 : tree dtemp = (**debug_args)[ix + 1];
6519 77094 : machine_mode mode = DECL_MODE (dtemp);
6520 77094 : item = gen_rtx_DEBUG_PARAMETER_REF (mode, param);
6521 77094 : item = gen_rtx_CONCAT (mode, item, DECL_RTL_KNOWN_SET (dtemp));
6522 77094 : call_arguments = gen_rtx_EXPR_LIST (VOIDmode, item,
6523 : call_arguments);
6524 : }
6525 : }
6526 : }
6527 :
6528 : /* Reverse call_arguments chain. */
6529 3141934 : prev = NULL_RTX;
6530 6847291 : for (cur = call_arguments; cur; cur = next)
6531 : {
6532 3705357 : next = XEXP (cur, 1);
6533 3705357 : XEXP (cur, 1) = prev;
6534 3705357 : prev = cur;
6535 : }
6536 3141934 : call_arguments = prev;
6537 :
6538 3141934 : x = get_call_rtx_from (insn);
6539 3141934 : if (x)
6540 : {
6541 3141934 : x = XEXP (XEXP (x, 0), 0);
6542 3141934 : if (GET_CODE (x) == SYMBOL_REF)
6543 : /* Don't record anything. */;
6544 125839 : else if (CONSTANT_P (x))
6545 : {
6546 1018 : x = gen_rtx_CONCAT (GET_MODE (x) == VOIDmode ? Pmode : GET_MODE (x),
6547 : pc_rtx, x);
6548 1018 : call_arguments
6549 1018 : = gen_rtx_EXPR_LIST (VOIDmode, x, call_arguments);
6550 : }
6551 : else
6552 : {
6553 124821 : cselib_val *val = cselib_lookup (x, GET_MODE (x), 0, VOIDmode);
6554 124821 : if (val && cselib_preserved_value_p (val))
6555 : {
6556 46835 : x = gen_rtx_CONCAT (GET_MODE (x), pc_rtx, val->val_rtx);
6557 46835 : call_arguments
6558 46835 : = gen_rtx_EXPR_LIST (VOIDmode, x, call_arguments);
6559 : }
6560 : }
6561 : }
6562 3141934 : if (this_arg)
6563 : {
6564 0 : machine_mode mode
6565 0 : = TYPE_MODE (TREE_TYPE (OBJ_TYPE_REF_EXPR (obj_type_ref)));
6566 0 : rtx clobbered = gen_rtx_MEM (mode, this_arg);
6567 0 : HOST_WIDE_INT token
6568 0 : = tree_to_shwi (OBJ_TYPE_REF_TOKEN (obj_type_ref));
6569 0 : if (token)
6570 0 : clobbered = plus_constant (mode, clobbered,
6571 0 : token * GET_MODE_SIZE (mode));
6572 0 : clobbered = gen_rtx_MEM (mode, clobbered);
6573 0 : x = gen_rtx_CONCAT (mode, gen_rtx_CLOBBER (VOIDmode, pc_rtx), clobbered);
6574 0 : call_arguments
6575 0 : = gen_rtx_EXPR_LIST (VOIDmode, x, call_arguments);
6576 : }
6577 3141934 : }
6578 :
6579 : /* Callback for cselib_record_sets_hook, that records as micro
6580 : operations uses and stores in an insn after cselib_record_sets has
6581 : analyzed the sets in an insn, but before it modifies the stored
6582 : values in the internal tables, unless cselib_record_sets doesn't
6583 : call it directly (perhaps because we're not doing cselib in the
6584 : first place, in which case sets and n_sets will be 0). */
6585 :
6586 : static void
6587 78868148 : add_with_sets (rtx_insn *insn, struct cselib_set *sets, int n_sets)
6588 : {
6589 78868148 : basic_block bb = BLOCK_FOR_INSN (insn);
6590 78868148 : int n1, n2;
6591 78868148 : struct count_use_info cui;
6592 78868148 : micro_operation *mos;
6593 :
6594 78868148 : cselib_hook_called = true;
6595 :
6596 78868148 : cui.insn = insn;
6597 78868148 : cui.bb = bb;
6598 78868148 : cui.sets = sets;
6599 78868148 : cui.n_sets = n_sets;
6600 :
6601 78868148 : n1 = VTI (bb)->mos.length ();
6602 78868148 : cui.store_p = false;
6603 78868148 : note_uses (&PATTERN (insn), add_uses_1, &cui);
6604 78868148 : n2 = VTI (bb)->mos.length () - 1;
6605 78868148 : mos = VTI (bb)->mos.address ();
6606 :
6607 : /* Order the MO_USEs to be before MO_USE_NO_VARs and MO_VAL_USE, and
6608 : MO_VAL_LOC last. */
6609 87452345 : while (n1 < n2)
6610 : {
6611 8727476 : while (n1 < n2 && mos[n1].type == MO_USE)
6612 143279 : n1++;
6613 18368487 : while (n1 < n2 && mos[n2].type != MO_USE)
6614 9784290 : n2--;
6615 8584197 : if (n1 < n2)
6616 114948 : std::swap (mos[n1], mos[n2]);
6617 : }
6618 :
6619 : n2 = VTI (bb)->mos.length () - 1;
6620 90110137 : while (n1 < n2)
6621 : {
6622 21026279 : while (n1 < n2 && mos[n1].type != MO_VAL_LOC)
6623 9784290 : n1++;
6624 11241989 : while (n1 < n2 && mos[n2].type == MO_VAL_LOC)
6625 0 : n2--;
6626 11241989 : if (n1 < n2)
6627 2901876 : std::swap (mos[n1], mos[n2]);
6628 : }
6629 :
6630 78868148 : if (CALL_P (insn))
6631 : {
6632 3141975 : micro_operation mo;
6633 :
6634 3141975 : mo.type = MO_CALL;
6635 3141975 : mo.insn = insn;
6636 3141975 : mo.u.loc = call_arguments;
6637 3141975 : call_arguments = NULL_RTX;
6638 :
6639 3141975 : if (dump_file && (dump_flags & TDF_DETAILS))
6640 2 : log_op_type (PATTERN (insn), bb, insn, mo.type, dump_file);
6641 3141975 : VTI (bb)->mos.safe_push (mo);
6642 : }
6643 :
6644 78868148 : n1 = VTI (bb)->mos.length ();
6645 : /* This will record NEXT_INSN (insn), such that we can
6646 : insert notes before it without worrying about any
6647 : notes that MO_USEs might emit after the insn. */
6648 78868148 : cui.store_p = true;
6649 78868148 : note_stores (insn, add_stores, &cui);
6650 78868148 : n2 = VTI (bb)->mos.length () - 1;
6651 78868148 : mos = VTI (bb)->mos.address ();
6652 :
6653 : /* Order the MO_VAL_USEs first (note_stores does nothing
6654 : on DEBUG_INSNs, so there are no MO_VAL_LOCs from this
6655 : insn), then MO_CLOBBERs, then MO_SET/MO_COPY/MO_VAL_SET. */
6656 82748823 : while (n1 < n2)
6657 : {
6658 3880675 : while (n1 < n2 && mos[n1].type == MO_VAL_USE)
6659 0 : n1++;
6660 7817216 : while (n1 < n2 && mos[n2].type != MO_VAL_USE)
6661 3936541 : n2--;
6662 3880675 : if (n1 < n2)
6663 0 : std::swap (mos[n1], mos[n2]);
6664 : }
6665 :
6666 : n2 = VTI (bb)->mos.length () - 1;
6667 82754024 : while (n1 < n2)
6668 : {
6669 7060980 : while (n1 < n2 && mos[n1].type == MO_CLOBBER)
6670 3175104 : n1++;
6671 4647313 : while (n1 < n2 && mos[n2].type != MO_CLOBBER)
6672 761437 : n2--;
6673 3885876 : if (n1 < n2)
6674 5201 : std::swap (mos[n1], mos[n2]);
6675 : }
6676 78868148 : }
6677 :
6678 : static enum var_init_status
6679 166089 : find_src_status (dataflow_set *in, rtx src)
6680 : {
6681 166089 : tree decl = NULL_TREE;
6682 166089 : enum var_init_status status = VAR_INIT_STATUS_UNINITIALIZED;
6683 :
6684 166089 : if (! flag_var_tracking_uninit)
6685 0 : status = VAR_INIT_STATUS_INITIALIZED;
6686 :
6687 166089 : if (src && REG_P (src))
6688 155148 : decl = var_debug_decl (REG_EXPR (src));
6689 10941 : else if (src && MEM_P (src))
6690 10941 : decl = var_debug_decl (MEM_EXPR (src));
6691 :
6692 166089 : if (src && decl)
6693 166089 : status = get_init_value (in, src, dv_from_decl (decl));
6694 :
6695 166089 : return status;
6696 : }
6697 :
6698 : /* SRC is the source of an assignment. Use SET to try to find what
6699 : was ultimately assigned to SRC. Return that value if known,
6700 : otherwise return SRC itself. */
6701 :
6702 : static rtx
6703 133322 : find_src_set_src (dataflow_set *set, rtx src)
6704 : {
6705 133322 : tree decl = NULL_TREE; /* The variable being copied around. */
6706 133322 : rtx set_src = NULL_RTX; /* The value for "decl" stored in "src". */
6707 133322 : variable *var;
6708 133322 : location_chain *nextp;
6709 133322 : int i;
6710 133322 : bool found;
6711 :
6712 133322 : if (src && REG_P (src))
6713 125895 : decl = var_debug_decl (REG_EXPR (src));
6714 7427 : else if (src && MEM_P (src))
6715 7427 : decl = var_debug_decl (MEM_EXPR (src));
6716 :
6717 133322 : if (src && decl)
6718 : {
6719 133322 : decl_or_value dv = dv_from_decl (decl);
6720 :
6721 133322 : var = shared_hash_find (set->vars, dv);
6722 133322 : if (var)
6723 : {
6724 : found = false;
6725 269009 : for (i = 0; i < var->n_var_parts && !found; i++)
6726 318919 : for (nextp = var->var_part[i].loc_chain; nextp && !found;
6727 165295 : nextp = nextp->next)
6728 165295 : if (rtx_equal_p (nextp->loc, src))
6729 : {
6730 96397 : set_src = nextp->set_src;
6731 96397 : found = true;
6732 : }
6733 :
6734 : }
6735 : }
6736 :
6737 133322 : return set_src;
6738 : }
6739 :
6740 : /* Compute the changes of variable locations in the basic block BB. */
6741 :
6742 : static bool
6743 9274460 : compute_bb_dataflow (basic_block bb)
6744 : {
6745 9274460 : unsigned int i;
6746 9274460 : micro_operation *mo;
6747 9274460 : bool changed;
6748 9274460 : dataflow_set old_out;
6749 9274460 : dataflow_set *in = &VTI (bb)->in;
6750 9274460 : dataflow_set *out = &VTI (bb)->out;
6751 :
6752 9274460 : dataflow_set_init (&old_out);
6753 9274460 : dataflow_set_copy (&old_out, out);
6754 9274460 : dataflow_set_copy (out, in);
6755 :
6756 9274460 : if (MAY_HAVE_DEBUG_BIND_INSNS)
6757 9274363 : local_get_addr_cache = new hash_map<rtx, rtx>;
6758 :
6759 166478524 : FOR_EACH_VEC_ELT (VTI (bb)->mos, i, mo)
6760 : {
6761 157204064 : rtx_insn *insn = mo->insn;
6762 :
6763 157204064 : switch (mo->type)
6764 : {
6765 3692850 : case MO_CALL:
6766 3692850 : dataflow_set_clear_at_call (out, insn);
6767 3692850 : break;
6768 :
6769 404120 : case MO_USE:
6770 404120 : {
6771 404120 : rtx loc = mo->u.loc;
6772 :
6773 404120 : if (REG_P (loc))
6774 400609 : var_reg_set (out, loc, VAR_INIT_STATUS_UNINITIALIZED, NULL);
6775 3511 : else if (MEM_P (loc))
6776 3511 : var_mem_set (out, loc, VAR_INIT_STATUS_UNINITIALIZED, NULL);
6777 : }
6778 : break;
6779 :
6780 49222353 : case MO_VAL_LOC:
6781 49222353 : {
6782 49222353 : rtx loc = mo->u.loc;
6783 49222353 : rtx val, vloc;
6784 49222353 : tree var;
6785 :
6786 49222353 : if (GET_CODE (loc) == CONCAT)
6787 : {
6788 23962433 : val = XEXP (loc, 0);
6789 23962433 : vloc = XEXP (loc, 1);
6790 : }
6791 : else
6792 : {
6793 : val = NULL_RTX;
6794 : vloc = loc;
6795 : }
6796 :
6797 49222353 : var = PAT_VAR_LOCATION_DECL (vloc);
6798 :
6799 49222353 : clobber_variable_part (out, NULL_RTX,
6800 : dv_from_decl (var), 0, NULL_RTX);
6801 49222353 : if (val)
6802 : {
6803 23962433 : if (VAL_NEEDS_RESOLUTION (loc))
6804 2435557 : val_resolve (out, val, PAT_VAR_LOCATION_LOC (vloc), insn);
6805 23962433 : set_variable_part (out, val, dv_from_decl (var), 0,
6806 : VAR_INIT_STATUS_INITIALIZED, NULL_RTX,
6807 : INSERT);
6808 : }
6809 25259920 : else if (!VAR_LOC_UNKNOWN_P (PAT_VAR_LOCATION_LOC (vloc)))
6810 3017236 : set_variable_part (out, PAT_VAR_LOCATION_LOC (vloc),
6811 : dv_from_decl (var), 0,
6812 : VAR_INIT_STATUS_INITIALIZED, NULL_RTX,
6813 : INSERT);
6814 : }
6815 : break;
6816 :
6817 21430776 : case MO_VAL_USE:
6818 21430776 : {
6819 21430776 : rtx loc = mo->u.loc;
6820 21430776 : rtx val, vloc, uloc;
6821 :
6822 21430776 : vloc = uloc = XEXP (loc, 1);
6823 21430776 : val = XEXP (loc, 0);
6824 :
6825 21430776 : if (GET_CODE (val) == CONCAT)
6826 : {
6827 10318513 : uloc = XEXP (val, 1);
6828 10318513 : val = XEXP (val, 0);
6829 : }
6830 :
6831 21430776 : if (VAL_NEEDS_RESOLUTION (loc))
6832 21430776 : val_resolve (out, val, vloc, insn);
6833 : else
6834 0 : val_store (out, val, uloc, insn, false);
6835 :
6836 21430776 : if (VAL_HOLDS_TRACK_EXPR (loc))
6837 : {
6838 304791 : if (GET_CODE (uloc) == REG)
6839 277583 : var_reg_set (out, uloc, VAR_INIT_STATUS_UNINITIALIZED,
6840 : NULL);
6841 27208 : else if (GET_CODE (uloc) == MEM)
6842 27208 : var_mem_set (out, uloc, VAR_INIT_STATUS_UNINITIALIZED,
6843 : NULL);
6844 : }
6845 : }
6846 : break;
6847 :
6848 41166204 : case MO_VAL_SET:
6849 41166204 : {
6850 41166204 : rtx loc = mo->u.loc;
6851 41166204 : rtx val, vloc, uloc;
6852 41166204 : rtx dstv, srcv;
6853 :
6854 41166204 : vloc = loc;
6855 41166204 : uloc = XEXP (vloc, 1);
6856 41166204 : val = XEXP (vloc, 0);
6857 41166204 : vloc = uloc;
6858 :
6859 41166204 : if (GET_CODE (uloc) == SET)
6860 : {
6861 30386386 : dstv = SET_DEST (uloc);
6862 30386386 : srcv = SET_SRC (uloc);
6863 : }
6864 : else
6865 : {
6866 : dstv = uloc;
6867 : srcv = NULL;
6868 : }
6869 :
6870 41166204 : if (GET_CODE (val) == CONCAT)
6871 : {
6872 10776325 : dstv = vloc = XEXP (val, 1);
6873 10776325 : val = XEXP (val, 0);
6874 : }
6875 :
6876 41166204 : if (GET_CODE (vloc) == SET)
6877 : {
6878 30380525 : srcv = SET_SRC (vloc);
6879 :
6880 30380525 : gcc_assert (val != srcv);
6881 30380525 : gcc_assert (vloc == uloc || VAL_NEEDS_RESOLUTION (loc));
6882 :
6883 30380525 : dstv = vloc = SET_DEST (vloc);
6884 :
6885 30380525 : if (VAL_NEEDS_RESOLUTION (loc))
6886 0 : val_resolve (out, val, srcv, insn);
6887 : }
6888 10785679 : else if (VAL_NEEDS_RESOLUTION (loc))
6889 : {
6890 0 : gcc_assert (GET_CODE (uloc) == SET
6891 : && GET_CODE (SET_SRC (uloc)) == REG);
6892 0 : val_resolve (out, val, SET_SRC (uloc), insn);
6893 : }
6894 :
6895 41166204 : if (VAL_HOLDS_TRACK_EXPR (loc))
6896 : {
6897 139089 : if (VAL_EXPR_IS_CLOBBERED (loc))
6898 : {
6899 0 : if (REG_P (uloc))
6900 0 : var_reg_delete (out, uloc, true);
6901 0 : else if (MEM_P (uloc))
6902 : {
6903 0 : gcc_assert (MEM_P (dstv));
6904 0 : gcc_assert (MEM_ATTRS (dstv) == MEM_ATTRS (uloc));
6905 0 : var_mem_delete (out, dstv, true);
6906 : }
6907 : }
6908 : else
6909 : {
6910 139089 : bool copied_p = VAL_EXPR_IS_COPIED (loc);
6911 139089 : rtx src = NULL, dst = uloc;
6912 139089 : enum var_init_status status = VAR_INIT_STATUS_INITIALIZED;
6913 :
6914 139089 : if (GET_CODE (uloc) == SET)
6915 : {
6916 133778 : src = SET_SRC (uloc);
6917 133778 : dst = SET_DEST (uloc);
6918 : }
6919 :
6920 139089 : if (copied_p)
6921 : {
6922 25963 : if (flag_var_tracking_uninit)
6923 : {
6924 25963 : status = find_src_status (in, src);
6925 :
6926 25963 : if (status == VAR_INIT_STATUS_UNKNOWN)
6927 19952 : status = find_src_status (out, src);
6928 : }
6929 :
6930 25963 : src = find_src_set_src (in, src);
6931 : }
6932 :
6933 139089 : if (REG_P (dst))
6934 133222 : var_reg_delete_and_set (out, dst, !copied_p,
6935 : status, srcv);
6936 5867 : else if (MEM_P (dst))
6937 : {
6938 5867 : gcc_assert (MEM_P (dstv));
6939 5867 : gcc_assert (MEM_ATTRS (dstv) == MEM_ATTRS (dst));
6940 5867 : var_mem_delete_and_set (out, dstv, !copied_p,
6941 : status, srcv);
6942 : }
6943 : }
6944 : }
6945 41027115 : else if (REG_P (uloc))
6946 4253 : var_regno_delete (out, REGNO (uloc));
6947 41022862 : else if (MEM_P (uloc))
6948 : {
6949 10770254 : gcc_checking_assert (GET_CODE (vloc) == MEM);
6950 10770254 : gcc_checking_assert (dstv == vloc);
6951 : if (dstv != vloc)
6952 : clobber_overlapping_mems (out, vloc);
6953 : }
6954 :
6955 41166204 : val_store (out, val, dstv, insn, true);
6956 : }
6957 41166204 : break;
6958 :
6959 39105 : case MO_SET:
6960 39105 : {
6961 39105 : rtx loc = mo->u.loc;
6962 39105 : rtx set_src = NULL;
6963 :
6964 39105 : if (GET_CODE (loc) == SET)
6965 : {
6966 38834 : set_src = SET_SRC (loc);
6967 38834 : loc = SET_DEST (loc);
6968 : }
6969 :
6970 39105 : if (REG_P (loc))
6971 39105 : var_reg_delete_and_set (out, loc, true, VAR_INIT_STATUS_INITIALIZED,
6972 : set_src);
6973 0 : else if (MEM_P (loc))
6974 0 : var_mem_delete_and_set (out, loc, true, VAR_INIT_STATUS_INITIALIZED,
6975 : set_src);
6976 : }
6977 : break;
6978 :
6979 44437 : case MO_COPY:
6980 44437 : {
6981 44437 : rtx loc = mo->u.loc;
6982 44437 : enum var_init_status src_status;
6983 44437 : rtx set_src = NULL;
6984 :
6985 44437 : if (GET_CODE (loc) == SET)
6986 : {
6987 44437 : set_src = SET_SRC (loc);
6988 44437 : loc = SET_DEST (loc);
6989 : }
6990 :
6991 44437 : if (! flag_var_tracking_uninit)
6992 : src_status = VAR_INIT_STATUS_INITIALIZED;
6993 : else
6994 : {
6995 44437 : src_status = find_src_status (in, set_src);
6996 :
6997 44437 : if (src_status == VAR_INIT_STATUS_UNKNOWN)
6998 12815 : src_status = find_src_status (out, set_src);
6999 : }
7000 :
7001 44437 : set_src = find_src_set_src (in, set_src);
7002 :
7003 44437 : if (REG_P (loc))
7004 44437 : var_reg_delete_and_set (out, loc, false, src_status, set_src);
7005 0 : else if (MEM_P (loc))
7006 0 : var_mem_delete_and_set (out, loc, false, src_status, set_src);
7007 : }
7008 : break;
7009 :
7010 28472112 : case MO_USE_NO_VAR:
7011 28472112 : {
7012 28472112 : rtx loc = mo->u.loc;
7013 :
7014 28472112 : if (REG_P (loc))
7015 28472112 : var_reg_delete (out, loc, false);
7016 0 : else if (MEM_P (loc))
7017 0 : var_mem_delete (out, loc, false);
7018 : }
7019 : break;
7020 :
7021 7915520 : case MO_CLOBBER:
7022 7915520 : {
7023 7915520 : rtx loc = mo->u.loc;
7024 :
7025 7915520 : if (REG_P (loc))
7026 7915517 : var_reg_delete (out, loc, true);
7027 3 : else if (MEM_P (loc))
7028 3 : var_mem_delete (out, loc, true);
7029 : }
7030 : break;
7031 :
7032 4816587 : case MO_ADJUST:
7033 4816587 : out->stack_adjust += mo->u.adjust;
7034 4816587 : break;
7035 : }
7036 : }
7037 :
7038 9274460 : if (MAY_HAVE_DEBUG_BIND_INSNS)
7039 : {
7040 18548726 : delete local_get_addr_cache;
7041 9274363 : local_get_addr_cache = NULL;
7042 :
7043 9274363 : dataflow_set_equiv_regs (out);
7044 9274363 : shared_hash_htab (out->vars)
7045 411783647 : ->traverse <dataflow_set *, canonicalize_values_mark> (out);
7046 9274363 : shared_hash_htab (out->vars)
7047 9274363 : ->traverse <dataflow_set *, canonicalize_values_star> (out);
7048 9274363 : if (flag_checking)
7049 9274355 : shared_hash_htab (out->vars)
7050 516557328 : ->traverse <dataflow_set *, canonicalize_loc_order_check> (out);
7051 : }
7052 9274460 : changed = dataflow_set_different (&old_out, out);
7053 9274460 : dataflow_set_destroy (&old_out);
7054 9274460 : return changed;
7055 : }
7056 :
7057 : /* Find the locations of variables in the whole function. */
7058 :
7059 : static bool
7060 496103 : vt_find_locations (void)
7061 : {
7062 496103 : bb_heap_t *worklist = new bb_heap_t (LONG_MIN);
7063 496103 : bb_heap_t *pending = new bb_heap_t (LONG_MIN);
7064 496103 : sbitmap in_worklist, in_pending;
7065 496103 : basic_block bb;
7066 496103 : edge e;
7067 496103 : int *bb_order;
7068 496103 : int *rc_order;
7069 496103 : int i;
7070 496103 : int htabsz = 0;
7071 496103 : int htabmax = param_max_vartrack_size;
7072 496103 : bool success = true;
7073 496103 : unsigned int n_blocks_processed = 0;
7074 :
7075 496103 : timevar_push (TV_VAR_TRACKING_DATAFLOW);
7076 : /* Compute reverse completion order of depth first search of the CFG
7077 : so that the data-flow runs faster. */
7078 496103 : rc_order = XNEWVEC (int, n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS);
7079 496103 : bb_order = XNEWVEC (int, last_basic_block_for_fn (cfun));
7080 496103 : auto_bitmap exit_bbs;
7081 496103 : bitmap_set_bit (exit_bbs, EXIT_BLOCK);
7082 496103 : auto_vec<std::pair<int, int> > toplevel_scc_extents;
7083 496103 : int n = rev_post_order_and_mark_dfs_back_seme
7084 496103 : (cfun, single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)), exit_bbs, true,
7085 : rc_order, &toplevel_scc_extents);
7086 8333096 : for (i = 0; i < n; i++)
7087 7340890 : bb_order[rc_order[i]] = i;
7088 :
7089 496103 : in_worklist = sbitmap_alloc (last_basic_block_for_fn (cfun));
7090 496103 : in_pending = sbitmap_alloc (last_basic_block_for_fn (cfun));
7091 496103 : bitmap_clear (in_worklist);
7092 496103 : bitmap_clear (in_pending);
7093 :
7094 : /* We're performing the dataflow iteration independently over the
7095 : toplevel SCCs plus leading non-cyclic entry blocks and separately
7096 : over the tail. That ensures best memory locality and the least
7097 : number of visited blocks. */
7098 496103 : unsigned extent = 0;
7099 496103 : int curr_start = -1;
7100 496103 : int curr_end = -1;
7101 740879 : do
7102 : {
7103 740879 : curr_start = curr_end + 1;
7104 740879 : if (toplevel_scc_extents.length () <= extent)
7105 495418 : curr_end = n - 1;
7106 : else
7107 245461 : curr_end = toplevel_scc_extents[extent++].second;
7108 :
7109 8081769 : for (int i = curr_start; i <= curr_end; ++i)
7110 : {
7111 7340890 : pending->insert (i, BASIC_BLOCK_FOR_FN (cfun, rc_order[i]));
7112 7340890 : bitmap_set_bit (in_pending, rc_order[i]);
7113 : }
7114 :
7115 1789325 : while (success && !pending->empty ())
7116 : {
7117 : std::swap (worklist, pending);
7118 : std::swap (in_worklist, in_pending);
7119 :
7120 10322905 : while (!worklist->empty ())
7121 : {
7122 9274460 : bool changed;
7123 9274460 : edge_iterator ei;
7124 9274460 : int oldinsz, oldoutsz;
7125 :
7126 9274460 : bb = worklist->extract_min ();
7127 9274460 : bitmap_clear_bit (in_worklist, bb->index);
7128 :
7129 9274460 : if (VTI (bb)->in.vars)
7130 : {
7131 9274460 : htabsz -= (shared_hash_htab (VTI (bb)->in.vars)->size ()
7132 9274460 : + shared_hash_htab (VTI (bb)->out.vars)->size ());
7133 9274460 : oldinsz = shared_hash_htab (VTI (bb)->in.vars)->elements ();
7134 9274460 : oldoutsz = shared_hash_htab (VTI (bb)->out.vars)->elements ();
7135 : }
7136 : else
7137 : oldinsz = oldoutsz = 0;
7138 :
7139 9274460 : if (MAY_HAVE_DEBUG_BIND_INSNS)
7140 : {
7141 9274363 : dataflow_set *in = &VTI (bb)->in, *first_out = NULL;
7142 9274363 : bool first = true, adjust = false;
7143 :
7144 : /* Calculate the IN set as the intersection of
7145 : predecessor OUT sets. */
7146 :
7147 9274363 : dataflow_set_clear (in);
7148 9274363 : dst_can_be_shared = true;
7149 :
7150 23216494 : FOR_EACH_EDGE (e, ei, bb->preds)
7151 13942131 : if (!VTI (e->src)->flooded)
7152 361216 : gcc_assert (bb_order[bb->index]
7153 : <= bb_order[e->src->index]);
7154 13580915 : else if (first)
7155 : {
7156 9274363 : dataflow_set_copy (in, &VTI (e->src)->out);
7157 9274363 : first_out = &VTI (e->src)->out;
7158 9274363 : first = false;
7159 : }
7160 : else
7161 : {
7162 4306552 : dataflow_set_merge (in, &VTI (e->src)->out);
7163 4306552 : adjust = true;
7164 : }
7165 :
7166 9274363 : if (adjust)
7167 : {
7168 2790275 : dataflow_post_merge_adjust (in, &VTI (bb)->permp);
7169 :
7170 2790275 : if (flag_checking)
7171 : /* Merge and merge_adjust should keep entries in
7172 : canonical order. */
7173 2790273 : shared_hash_htab (in->vars)
7174 : ->traverse <dataflow_set *,
7175 2790273 : canonicalize_loc_order_check> (in);
7176 :
7177 2790275 : if (dst_can_be_shared)
7178 : {
7179 7291 : shared_hash_destroy (in->vars);
7180 7291 : in->vars = shared_hash_copy (first_out->vars);
7181 : }
7182 : }
7183 :
7184 9274363 : VTI (bb)->flooded = true;
7185 : }
7186 : else
7187 : {
7188 : /* Calculate the IN set as union of predecessor OUT sets. */
7189 97 : dataflow_set_clear (&VTI (bb)->in);
7190 219 : FOR_EACH_EDGE (e, ei, bb->preds)
7191 122 : dataflow_set_union (&VTI (bb)->in, &VTI (e->src)->out);
7192 : }
7193 :
7194 9274460 : changed = compute_bb_dataflow (bb);
7195 9274460 : n_blocks_processed++;
7196 9274460 : htabsz += (shared_hash_htab (VTI (bb)->in.vars)->size ()
7197 9274460 : + shared_hash_htab (VTI (bb)->out.vars)->size ());
7198 :
7199 9274460 : if (htabmax && htabsz > htabmax)
7200 : {
7201 1 : if (MAY_HAVE_DEBUG_BIND_INSNS)
7202 1 : inform (DECL_SOURCE_LOCATION (cfun->decl),
7203 : "variable tracking size limit exceeded with "
7204 : "%<-fvar-tracking-assignments%>, retrying without");
7205 : else
7206 0 : inform (DECL_SOURCE_LOCATION (cfun->decl),
7207 : "variable tracking size limit exceeded");
7208 1 : success = false;
7209 1 : break;
7210 : }
7211 :
7212 9274459 : if (changed)
7213 : {
7214 22465429 : FOR_EACH_EDGE (e, ei, bb->succs)
7215 : {
7216 13588059 : if (e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
7217 613497 : continue;
7218 :
7219 : /* Iterate to an earlier block in RPO in the next
7220 : round, iterate to the same block immediately. */
7221 12974562 : if (bb_order[e->dest->index] < bb_order[bb->index])
7222 : {
7223 483564 : gcc_assert (bb_order[e->dest->index] >= curr_start);
7224 483564 : if (!bitmap_bit_p (in_pending, e->dest->index))
7225 : {
7226 : /* Send E->DEST to next round. */
7227 421129 : bitmap_set_bit (in_pending, e->dest->index);
7228 421129 : pending->insert (bb_order[e->dest->index],
7229 : e->dest);
7230 : }
7231 : }
7232 12490998 : else if (bb_order[e->dest->index] <= curr_end
7233 12490998 : && !bitmap_bit_p (in_worklist, e->dest->index))
7234 : {
7235 : /* Add E->DEST to current round or delay
7236 : processing if it is in the next SCC. */
7237 1512441 : bitmap_set_bit (in_worklist, e->dest->index);
7238 1512441 : worklist->insert (bb_order[e->dest->index],
7239 : e->dest);
7240 : }
7241 : }
7242 : }
7243 :
7244 9274459 : if (dump_file)
7245 77 : fprintf (dump_file,
7246 : "BB %i: in %i (was %i), out %i (was %i), rem %i + %i, "
7247 : "tsz %i\n", bb->index,
7248 77 : (int)shared_hash_htab (VTI (bb)->in.vars)->size (),
7249 : oldinsz,
7250 77 : (int)shared_hash_htab (VTI (bb)->out.vars)->size (),
7251 : oldoutsz,
7252 77 : (int)worklist->nodes (), (int)pending->nodes (),
7253 : htabsz);
7254 :
7255 9274459 : if (dump_file && (dump_flags & TDF_DETAILS))
7256 : {
7257 1 : fprintf (dump_file, "BB %i IN:\n", bb->index);
7258 1 : dump_dataflow_set (&VTI (bb)->in);
7259 1 : fprintf (dump_file, "BB %i OUT:\n", bb->index);
7260 1 : dump_dataflow_set (&VTI (bb)->out);
7261 : }
7262 : }
7263 : }
7264 : }
7265 740879 : while (curr_end != n - 1);
7266 :
7267 496103 : statistics_counter_event (cfun, "compute_bb_dataflow times",
7268 : n_blocks_processed);
7269 :
7270 496103 : if (success && MAY_HAVE_DEBUG_BIND_INSNS)
7271 7836859 : FOR_EACH_BB_FN (bb, cfun)
7272 7340798 : gcc_assert (VTI (bb)->flooded);
7273 :
7274 496103 : free (rc_order);
7275 496103 : free (bb_order);
7276 496103 : delete worklist;
7277 496103 : delete pending;
7278 496103 : sbitmap_free (in_worklist);
7279 496103 : sbitmap_free (in_pending);
7280 :
7281 496103 : timevar_pop (TV_VAR_TRACKING_DATAFLOW);
7282 496103 : return success;
7283 496103 : }
7284 :
7285 : /* Print the content of the LIST to dump file. */
7286 :
7287 : static void
7288 4 : dump_attrs_list (attrs *list)
7289 : {
7290 8 : for (; list; list = list->next)
7291 : {
7292 4 : if (dv_is_decl_p (list->dv))
7293 0 : print_mem_expr (dump_file, dv_as_decl (list->dv));
7294 : else
7295 4 : print_rtl_single (dump_file, dv_as_value (list->dv));
7296 4 : fprintf (dump_file, "+" HOST_WIDE_INT_PRINT_DEC, list->offset);
7297 : }
7298 4 : fprintf (dump_file, "\n");
7299 4 : }
7300 :
7301 : /* Print the information about variable *SLOT to dump file. */
7302 :
7303 : int
7304 6 : dump_var_tracking_slot (variable **slot, void *data ATTRIBUTE_UNUSED)
7305 : {
7306 6 : variable *var = *slot;
7307 :
7308 6 : dump_var (var);
7309 :
7310 : /* Continue traversing the hash table. */
7311 6 : return 1;
7312 : }
7313 :
7314 : /* Print the information about variable VAR to dump file. */
7315 :
7316 : static void
7317 9 : dump_var (variable *var)
7318 : {
7319 9 : int i;
7320 9 : location_chain *node;
7321 :
7322 9 : if (dv_is_decl_p (var->dv))
7323 : {
7324 3 : const_tree decl = dv_as_decl (var->dv);
7325 :
7326 3 : if (DECL_NAME (decl))
7327 : {
7328 6 : fprintf (dump_file, " name: %s",
7329 3 : IDENTIFIER_POINTER (DECL_NAME (decl)));
7330 3 : if (dump_flags & TDF_UID)
7331 0 : fprintf (dump_file, "D.%u", DECL_UID (decl));
7332 : }
7333 0 : else if (TREE_CODE (decl) == DEBUG_EXPR_DECL)
7334 0 : fprintf (dump_file, " name: D#%u", DEBUG_TEMP_UID (decl));
7335 : else
7336 0 : fprintf (dump_file, " name: D.%u", DECL_UID (decl));
7337 3 : fprintf (dump_file, "\n");
7338 : }
7339 : else
7340 : {
7341 6 : fputc (' ', dump_file);
7342 6 : print_rtl_single (dump_file, dv_as_value (var->dv));
7343 : }
7344 :
7345 18 : for (i = 0; i < var->n_var_parts; i++)
7346 : {
7347 9 : fprintf (dump_file, " offset " HOST_WIDE_INT_PRINT_DEC "\n",
7348 9 : var->onepart ? 0 : VAR_PART_OFFSET (var, i));
7349 21 : for (node = var->var_part[i].loc_chain; node; node = node->next)
7350 : {
7351 12 : fprintf (dump_file, " ");
7352 12 : if (node->init == VAR_INIT_STATUS_UNINITIALIZED)
7353 0 : fprintf (dump_file, "[uninit]");
7354 12 : print_rtl_single (dump_file, node->loc);
7355 : }
7356 : }
7357 9 : }
7358 :
7359 : /* Print the information about variables from hash table VARS to dump file. */
7360 :
7361 : static void
7362 4 : dump_vars (variable_table_type *vars)
7363 : {
7364 4 : if (!vars->is_empty ())
7365 : {
7366 2 : fprintf (dump_file, "Variables:\n");
7367 8 : vars->traverse <void *, dump_var_tracking_slot> (NULL);
7368 : }
7369 4 : }
7370 :
7371 : /* Print the dataflow set SET to dump file. */
7372 :
7373 : static void
7374 4 : dump_dataflow_set (dataflow_set *set)
7375 : {
7376 4 : int i;
7377 :
7378 4 : fprintf (dump_file, "Stack adjustment: " HOST_WIDE_INT_PRINT_DEC "\n",
7379 : set->stack_adjust);
7380 376 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
7381 : {
7382 368 : if (set->regs[i])
7383 : {
7384 4 : fprintf (dump_file, "Reg %d:", i);
7385 4 : dump_attrs_list (set->regs[i]);
7386 : }
7387 : }
7388 4 : dump_vars (shared_hash_htab (set->vars));
7389 4 : fprintf (dump_file, "\n");
7390 4 : }
7391 :
7392 : /* Print the IN and OUT sets for each basic block to dump file. */
7393 :
7394 : static void
7395 1 : dump_dataflow_sets (void)
7396 : {
7397 1 : basic_block bb;
7398 :
7399 2 : FOR_EACH_BB_FN (bb, cfun)
7400 : {
7401 1 : fprintf (dump_file, "\nBasic block %d:\n", bb->index);
7402 1 : fprintf (dump_file, "IN:\n");
7403 1 : dump_dataflow_set (&VTI (bb)->in);
7404 1 : fprintf (dump_file, "OUT:\n");
7405 1 : dump_dataflow_set (&VTI (bb)->out);
7406 : }
7407 1 : }
7408 :
7409 : /* Return the variable for DV in dropped_values, inserting one if
7410 : requested with INSERT. */
7411 :
7412 : static inline variable *
7413 187631209 : variable_from_dropped (decl_or_value dv, enum insert_option insert)
7414 : {
7415 187631209 : variable **slot;
7416 187631209 : variable *empty_var;
7417 187631209 : onepart_enum onepart;
7418 :
7419 187631209 : slot = dropped_values->find_slot_with_hash (dv, dv_htab_hash (dv), insert);
7420 :
7421 187631209 : if (!slot)
7422 : return NULL;
7423 :
7424 81415182 : if (*slot)
7425 : return *slot;
7426 :
7427 7052364 : gcc_checking_assert (insert == INSERT);
7428 :
7429 7052364 : onepart = dv_onepart_p (dv);
7430 :
7431 7052364 : gcc_checking_assert (onepart == ONEPART_VALUE || onepart == ONEPART_DEXPR);
7432 :
7433 7052364 : empty_var = onepart_pool_allocate (onepart);
7434 7052364 : empty_var->dv = dv;
7435 7052364 : empty_var->refcount = 1;
7436 7052364 : empty_var->n_var_parts = 0;
7437 7052364 : empty_var->onepart = onepart;
7438 7052364 : empty_var->in_changed_variables = false;
7439 7052364 : empty_var->var_part[0].loc_chain = NULL;
7440 7052364 : empty_var->var_part[0].cur_loc = NULL;
7441 7052364 : VAR_LOC_1PAUX (empty_var) = NULL;
7442 7052364 : set_dv_changed (dv, true);
7443 :
7444 7052364 : *slot = empty_var;
7445 :
7446 7052364 : return empty_var;
7447 : }
7448 :
7449 : /* Recover the one-part aux from dropped_values. */
7450 :
7451 : static struct onepart_aux *
7452 112440835 : recover_dropped_1paux (variable *var)
7453 : {
7454 112440835 : variable *dvar;
7455 :
7456 112440835 : gcc_checking_assert (var->onepart);
7457 :
7458 112440835 : if (VAR_LOC_1PAUX (var))
7459 : return VAR_LOC_1PAUX (var);
7460 :
7461 112440835 : if (var->onepart == ONEPART_VDECL)
7462 : return NULL;
7463 :
7464 90974004 : dvar = variable_from_dropped (var->dv, NO_INSERT);
7465 :
7466 90974004 : if (!dvar)
7467 : return NULL;
7468 :
7469 12427807 : VAR_LOC_1PAUX (var) = VAR_LOC_1PAUX (dvar);
7470 12427807 : VAR_LOC_1PAUX (dvar) = NULL;
7471 :
7472 12427807 : return VAR_LOC_1PAUX (var);
7473 : }
7474 :
7475 : /* Add variable VAR to the hash table of changed variables and
7476 : if it has no locations delete it from SET's hash table. */
7477 :
7478 : static void
7479 365410824 : variable_was_changed (variable *var, dataflow_set *set)
7480 : {
7481 365410824 : hashval_t hash = dv_htab_hash (var->dv);
7482 :
7483 365410824 : if (emit_notes)
7484 : {
7485 192782649 : variable **slot;
7486 :
7487 : /* Remember this decl or VALUE has been added to changed_variables. */
7488 192782649 : set_dv_changed (var->dv, true);
7489 :
7490 192782649 : slot = changed_variables->find_slot_with_hash (var->dv, hash, INSERT);
7491 :
7492 192782649 : if (*slot)
7493 : {
7494 3362638 : variable *old_var = *slot;
7495 3362638 : gcc_assert (old_var->in_changed_variables);
7496 3362638 : old_var->in_changed_variables = false;
7497 3362638 : if (var != old_var && var->onepart)
7498 : {
7499 : /* Restore the auxiliary info from an empty variable
7500 : previously created for changed_variables, so it is
7501 : not lost. */
7502 2938825 : gcc_checking_assert (!VAR_LOC_1PAUX (var));
7503 2938825 : VAR_LOC_1PAUX (var) = VAR_LOC_1PAUX (old_var);
7504 2938825 : VAR_LOC_1PAUX (old_var) = NULL;
7505 : }
7506 3362638 : variable_htab_free (*slot);
7507 : }
7508 :
7509 192782649 : if (set && var->n_var_parts == 0)
7510 : {
7511 34847351 : onepart_enum onepart = var->onepart;
7512 34847351 : variable *empty_var = NULL;
7513 34847351 : variable **dslot = NULL;
7514 :
7515 34847351 : if (onepart == ONEPART_VALUE || onepart == ONEPART_DEXPR)
7516 : {
7517 20542133 : dslot = dropped_values->find_slot_with_hash (var->dv,
7518 : dv_htab_hash (var->dv),
7519 : INSERT);
7520 20542133 : empty_var = *dslot;
7521 :
7522 20542133 : if (empty_var)
7523 : {
7524 6060624 : gcc_checking_assert (!empty_var->in_changed_variables);
7525 6060624 : if (!VAR_LOC_1PAUX (var))
7526 : {
7527 3585494 : VAR_LOC_1PAUX (var) = VAR_LOC_1PAUX (empty_var);
7528 3585494 : VAR_LOC_1PAUX (empty_var) = NULL;
7529 : }
7530 : else
7531 2475130 : gcc_checking_assert (!VAR_LOC_1PAUX (empty_var));
7532 : }
7533 : }
7534 :
7535 3585494 : if (!empty_var)
7536 : {
7537 28786727 : empty_var = onepart_pool_allocate (onepart);
7538 28786727 : empty_var->dv = var->dv;
7539 28786727 : empty_var->refcount = 1;
7540 28786727 : empty_var->n_var_parts = 0;
7541 28786727 : empty_var->onepart = onepart;
7542 28786727 : if (dslot)
7543 : {
7544 14481509 : empty_var->refcount++;
7545 14481509 : *dslot = empty_var;
7546 : }
7547 : }
7548 : else
7549 6060624 : empty_var->refcount++;
7550 34847351 : empty_var->in_changed_variables = true;
7551 34847351 : *slot = empty_var;
7552 34847351 : if (onepart)
7553 : {
7554 34542375 : empty_var->var_part[0].loc_chain = NULL;
7555 34542375 : empty_var->var_part[0].cur_loc = NULL;
7556 34542375 : VAR_LOC_1PAUX (empty_var) = VAR_LOC_1PAUX (var);
7557 34542375 : VAR_LOC_1PAUX (var) = NULL;
7558 : }
7559 34847351 : goto drop_var;
7560 : }
7561 : else
7562 : {
7563 157935298 : if (var->onepart && !VAR_LOC_1PAUX (var))
7564 112440835 : recover_dropped_1paux (var);
7565 157935298 : var->refcount++;
7566 157935298 : var->in_changed_variables = true;
7567 157935298 : *slot = var;
7568 : }
7569 : }
7570 : else
7571 : {
7572 172628175 : gcc_assert (set);
7573 172628175 : if (var->n_var_parts == 0)
7574 : {
7575 80044710 : variable **slot;
7576 :
7577 45197359 : drop_var:
7578 80044710 : slot = shared_hash_find_slot_noinsert (set->vars, var->dv);
7579 80044710 : if (slot)
7580 : {
7581 80044710 : if (shared_hash_shared (set->vars))
7582 0 : slot = shared_hash_find_slot_unshare (&set->vars, var->dv,
7583 : NO_INSERT);
7584 80044710 : shared_hash_htab (set->vars)->clear_slot (slot);
7585 : }
7586 : }
7587 : }
7588 365410824 : }
7589 :
7590 : /* Look for the index in VAR->var_part corresponding to OFFSET.
7591 : Return -1 if not found. If INSERTION_POINT is non-NULL, the
7592 : referenced int will be set to the index that the part has or should
7593 : have, if it should be inserted. */
7594 :
7595 : static inline int
7596 415204809 : find_variable_location_part (variable *var, HOST_WIDE_INT offset,
7597 : int *insertion_point)
7598 : {
7599 415204809 : int pos, low, high;
7600 :
7601 415204809 : if (var->onepart)
7602 : {
7603 412488011 : if (offset != 0)
7604 : return -1;
7605 :
7606 412487932 : if (insertion_point)
7607 0 : *insertion_point = 0;
7608 :
7609 412487932 : return var->n_var_parts - 1;
7610 : }
7611 :
7612 : /* Find the location part. */
7613 2716798 : low = 0;
7614 2716798 : high = var->n_var_parts;
7615 9344964 : while (low != high)
7616 : {
7617 3911368 : pos = (low + high) / 2;
7618 3911368 : if (VAR_PART_OFFSET (var, pos) < offset)
7619 737595 : low = pos + 1;
7620 : else
7621 : high = pos;
7622 : }
7623 2716798 : pos = low;
7624 :
7625 2716798 : if (insertion_point)
7626 1355850 : *insertion_point = pos;
7627 :
7628 2716798 : if (pos < var->n_var_parts && VAR_PART_OFFSET (var, pos) == offset)
7629 : return pos;
7630 :
7631 : return -1;
7632 : }
7633 :
7634 : static variable **
7635 410668982 : set_slot_part (dataflow_set *set, rtx loc, variable **slot,
7636 : decl_or_value dv, HOST_WIDE_INT offset,
7637 : enum var_init_status initialized, rtx set_src)
7638 : {
7639 410668982 : int pos;
7640 410668982 : location_chain *node, *next;
7641 410668982 : location_chain **nextp;
7642 410668982 : variable *var;
7643 410668982 : onepart_enum onepart;
7644 :
7645 410668982 : var = *slot;
7646 :
7647 410668982 : if (var)
7648 264263609 : onepart = var->onepart;
7649 : else
7650 146405373 : onepart = dv_onepart_p (dv);
7651 :
7652 410668982 : gcc_checking_assert (offset == 0 || !onepart);
7653 410668982 : gcc_checking_assert (dv != loc);
7654 :
7655 410668982 : if (! flag_var_tracking_uninit)
7656 50 : initialized = VAR_INIT_STATUS_INITIALIZED;
7657 :
7658 410668982 : if (!var)
7659 : {
7660 : /* Create new variable information. */
7661 146405373 : var = onepart_pool_allocate (onepart);
7662 146405373 : var->dv = dv;
7663 146405373 : var->refcount = 1;
7664 146405373 : var->n_var_parts = 1;
7665 146405373 : var->onepart = onepart;
7666 146405373 : var->in_changed_variables = false;
7667 146405373 : if (var->onepart)
7668 145983212 : VAR_LOC_1PAUX (var) = NULL;
7669 : else
7670 422161 : VAR_PART_OFFSET (var, 0) = offset;
7671 146405373 : var->var_part[0].loc_chain = NULL;
7672 146405373 : var->var_part[0].cur_loc = NULL;
7673 146405373 : *slot = var;
7674 146405373 : pos = 0;
7675 146405373 : nextp = &var->var_part[0].loc_chain;
7676 : }
7677 264263609 : else if (onepart)
7678 : {
7679 262907759 : int r = -1, c = 0;
7680 :
7681 262907759 : gcc_assert (var->dv == dv);
7682 :
7683 262907759 : pos = 0;
7684 :
7685 262907759 : if (GET_CODE (loc) == VALUE)
7686 : {
7687 1828190779 : for (nextp = &var->var_part[0].loc_chain; (node = *nextp);
7688 1606313525 : nextp = &node->next)
7689 1817472951 : if (GET_CODE (node->loc) == VALUE)
7690 : {
7691 1710837278 : if (node->loc == loc)
7692 : {
7693 : r = 0;
7694 : break;
7695 : }
7696 1501420551 : if (canon_value_cmp (node->loc, loc))
7697 1499677852 : c++;
7698 : else
7699 : {
7700 : r = 1;
7701 : break;
7702 : }
7703 : }
7704 106635673 : else if (REG_P (node->loc) || MEM_P (node->loc))
7705 106635673 : c++;
7706 : else
7707 : {
7708 : r = 1;
7709 : break;
7710 : }
7711 : }
7712 41030505 : else if (REG_P (loc))
7713 : {
7714 27752054 : for (nextp = &var->var_part[0].loc_chain; (node = *nextp);
7715 3437114 : nextp = &node->next)
7716 25064555 : if (REG_P (node->loc))
7717 : {
7718 6011743 : if (REGNO (node->loc) < REGNO (loc))
7719 3437114 : c++;
7720 : else
7721 : {
7722 2574629 : if (REGNO (node->loc) == REGNO (loc))
7723 : r = 0;
7724 : else
7725 : r = 1;
7726 : break;
7727 : }
7728 : }
7729 : else
7730 : {
7731 : r = 1;
7732 : break;
7733 : }
7734 : }
7735 16715565 : else if (MEM_P (loc))
7736 : {
7737 39115271 : for (nextp = &var->var_part[0].loc_chain; (node = *nextp);
7738 22399706 : nextp = &node->next)
7739 26814739 : if (REG_P (node->loc))
7740 13431620 : c++;
7741 13383119 : else if (MEM_P (node->loc))
7742 : {
7743 10458688 : if ((r = loc_cmp (XEXP (node->loc, 0), XEXP (loc, 0))) >= 0)
7744 : break;
7745 : else
7746 8968086 : c++;
7747 : }
7748 : else
7749 : {
7750 : r = 1;
7751 : break;
7752 : }
7753 : }
7754 : else
7755 0 : for (nextp = &var->var_part[0].loc_chain; (node = *nextp);
7756 0 : nextp = &node->next)
7757 0 : if ((r = loc_cmp (node->loc, loc)) >= 0)
7758 : break;
7759 : else
7760 0 : c++;
7761 :
7762 260333130 : if (r == 0)
7763 209710873 : return slot;
7764 :
7765 53196886 : if (shared_var_p (var, set->vars))
7766 : {
7767 13629648 : slot = unshare_variable (set, slot, var, initialized);
7768 13629648 : var = *slot;
7769 36483646 : for (nextp = &var->var_part[0].loc_chain; c;
7770 22853998 : nextp = &(*nextp)->next)
7771 22853998 : c--;
7772 13629648 : gcc_assert ((!node && !*nextp) || node->loc == (*nextp)->loc);
7773 : }
7774 : }
7775 : else
7776 : {
7777 1355850 : int inspos = 0;
7778 :
7779 1355850 : gcc_assert (dv_as_decl (var->dv) == dv_as_decl (dv));
7780 :
7781 1355850 : pos = find_variable_location_part (var, offset, &inspos);
7782 :
7783 1355850 : if (pos >= 0)
7784 : {
7785 1167377 : node = var->var_part[pos].loc_chain;
7786 :
7787 1167377 : if (node
7788 1167377 : && ((REG_P (node->loc) && REG_P (loc)
7789 1100472 : && REGNO (node->loc) == REGNO (loc))
7790 223100 : || rtx_equal_p (node->loc, loc)))
7791 : {
7792 : /* LOC is in the beginning of the chain so we have nothing
7793 : to do. */
7794 976148 : if (node->init < initialized)
7795 12967 : node->init = initialized;
7796 976148 : if (set_src != NULL)
7797 14299 : node->set_src = set_src;
7798 :
7799 976148 : return slot;
7800 : }
7801 : else
7802 : {
7803 : /* We have to make a copy of a shared variable. */
7804 191229 : if (shared_var_p (var, set->vars))
7805 : {
7806 79590 : slot = unshare_variable (set, slot, var, initialized);
7807 79590 : var = *slot;
7808 : }
7809 : }
7810 : }
7811 : else
7812 : {
7813 : /* We have not found the location part, new one will be created. */
7814 :
7815 : /* We have to make a copy of the shared variable. */
7816 188473 : if (shared_var_p (var, set->vars))
7817 : {
7818 39543 : slot = unshare_variable (set, slot, var, initialized);
7819 39543 : var = *slot;
7820 : }
7821 :
7822 : /* We track only variables whose size is <= MAX_VAR_PARTS bytes
7823 : thus there are at most MAX_VAR_PARTS different offsets. */
7824 188473 : gcc_assert (var->n_var_parts < MAX_VAR_PARTS
7825 : && (!var->n_var_parts || !onepart));
7826 :
7827 : /* We have to move the elements of array starting at index
7828 : inspos to the next position. */
7829 245291 : for (pos = var->n_var_parts; pos > inspos; pos--)
7830 56818 : var->var_part[pos] = var->var_part[pos - 1];
7831 :
7832 188473 : var->n_var_parts++;
7833 188473 : gcc_checking_assert (!onepart);
7834 188473 : VAR_PART_OFFSET (var, pos) = offset;
7835 188473 : var->var_part[pos].loc_chain = NULL;
7836 188473 : var->var_part[pos].cur_loc = NULL;
7837 : }
7838 :
7839 : /* Delete the location from the list. */
7840 379702 : nextp = &var->var_part[pos].loc_chain;
7841 581641 : for (node = var->var_part[pos].loc_chain; node; node = next)
7842 : {
7843 226193 : next = node->next;
7844 189875 : if ((REG_P (node->loc) && REG_P (loc)
7845 183753 : && REGNO (node->loc) == REGNO (loc))
7846 392902 : || rtx_equal_p (node->loc, loc))
7847 : {
7848 : /* Save these values, to assign to the new node, before
7849 : deleting this one. */
7850 24254 : if (node->init > initialized)
7851 19328 : initialized = node->init;
7852 24254 : if (node->set_src != NULL && set_src == NULL)
7853 24254 : set_src = node->set_src;
7854 24254 : if (var->var_part[pos].cur_loc == node->loc)
7855 5883 : var->var_part[pos].cur_loc = NULL;
7856 24254 : delete node;
7857 24254 : *nextp = next;
7858 24254 : break;
7859 : }
7860 : else
7861 201939 : nextp = &node->next;
7862 : }
7863 :
7864 379702 : nextp = &var->var_part[pos].loc_chain;
7865 : }
7866 :
7867 : /* Add the location to the beginning. */
7868 199981961 : node = new location_chain;
7869 199981961 : node->loc = loc;
7870 199981961 : node->init = initialized;
7871 199981961 : node->set_src = set_src;
7872 199981961 : node->next = *nextp;
7873 199981961 : *nextp = node;
7874 :
7875 : /* If no location was emitted do so. */
7876 199981961 : if (var->var_part[pos].cur_loc == NULL)
7877 195785028 : variable_was_changed (var, set);
7878 :
7879 : return slot;
7880 : }
7881 :
7882 : /* Set the part of variable's location in the dataflow set SET. The
7883 : variable part is specified by variable's declaration in DV and
7884 : offset OFFSET and the part's location by LOC. IOPT should be
7885 : NO_INSERT if the variable is known to be in SET already and the
7886 : variable hash table must not be resized, and INSERT otherwise. */
7887 :
7888 : static void
7889 222793308 : set_variable_part (dataflow_set *set, rtx loc,
7890 : decl_or_value dv, HOST_WIDE_INT offset,
7891 : enum var_init_status initialized, rtx set_src,
7892 : enum insert_option iopt)
7893 : {
7894 222793308 : variable **slot;
7895 :
7896 222793308 : if (iopt == NO_INSERT)
7897 135110 : slot = shared_hash_find_slot_noinsert (set->vars, dv);
7898 : else
7899 : {
7900 222658198 : slot = shared_hash_find_slot (set->vars, dv);
7901 222658198 : if (!slot)
7902 11662419 : slot = shared_hash_find_slot_unshare (&set->vars, dv, iopt);
7903 : }
7904 222793308 : set_slot_part (set, loc, slot, dv, offset, initialized, set_src);
7905 222793308 : }
7906 :
7907 : /* Remove all recorded register locations for the given variable part
7908 : from dataflow set SET, except for those that are identical to loc.
7909 : The variable part is specified by variable's declaration or value
7910 : DV and offset OFFSET. */
7911 :
7912 : static variable **
7913 322773781 : clobber_slot_part (dataflow_set *set, rtx loc, variable **slot,
7914 : HOST_WIDE_INT offset, rtx set_src)
7915 : {
7916 322773781 : variable *var = *slot;
7917 322773781 : int pos = find_variable_location_part (var, offset, NULL);
7918 :
7919 322773781 : if (pos >= 0)
7920 : {
7921 322742787 : location_chain *node, *next;
7922 :
7923 : /* Remove the register locations from the dataflow set. */
7924 322742787 : next = var->var_part[pos].loc_chain;
7925 647930054 : for (node = next; node; node = next)
7926 : {
7927 325187267 : next = node->next;
7928 325187267 : if (node->loc != loc
7929 325187267 : && (!flag_var_tracking_uninit
7930 36803297 : || !set_src
7931 62393 : || MEM_P (set_src)
7932 22820 : || !rtx_equal_p (set_src, node->set_src)))
7933 : {
7934 36800688 : if (REG_P (node->loc))
7935 : {
7936 962910 : attrs *anode, *anext;
7937 962910 : attrs **anextp;
7938 :
7939 : /* Remove the variable part from the register's
7940 : list, but preserve any other variable parts
7941 : that might be regarded as live in that same
7942 : register. */
7943 962910 : anextp = &set->regs[REGNO (node->loc)];
7944 1950803 : for (anode = *anextp; anode; anode = anext)
7945 : {
7946 987893 : anext = anode->next;
7947 987893 : if (anode->dv == var->dv && anode->offset == offset)
7948 : {
7949 22286 : delete anode;
7950 22286 : *anextp = anext;
7951 : }
7952 : else
7953 965607 : anextp = &anode->next;
7954 : }
7955 : }
7956 :
7957 36800688 : slot = delete_slot_part (set, node->loc, slot, offset);
7958 : }
7959 : }
7960 : }
7961 :
7962 322773781 : return slot;
7963 : }
7964 :
7965 : /* Remove all recorded register locations for the given variable part
7966 : from dataflow set SET, except for those that are identical to loc.
7967 : The variable part is specified by variable's declaration or value
7968 : DV and offset OFFSET. */
7969 :
7970 : static void
7971 100010247 : clobber_variable_part (dataflow_set *set, rtx loc, decl_or_value dv,
7972 : HOST_WIDE_INT offset, rtx set_src)
7973 : {
7974 100010247 : variable **slot;
7975 :
7976 186310474 : if (!dv || (!dv_is_value_p (dv) && ! DECL_P (dv_as_decl (dv))))
7977 : return;
7978 :
7979 86207829 : slot = shared_hash_find_slot_noinsert (set->vars, dv);
7980 86207829 : if (!slot)
7981 : return;
7982 :
7983 34428434 : clobber_slot_part (set, loc, slot, offset, set_src);
7984 : }
7985 :
7986 : /* Delete the part of variable's location from dataflow set SET. The
7987 : variable part is specified by its SET->vars slot SLOT and offset
7988 : OFFSET and the part's location by LOC. */
7989 :
7990 : static variable **
7991 91075178 : delete_slot_part (dataflow_set *set, rtx loc, variable **slot,
7992 : HOST_WIDE_INT offset)
7993 : {
7994 91075178 : variable *var = *slot;
7995 91075178 : int pos = find_variable_location_part (var, offset, NULL);
7996 :
7997 91075178 : if (pos >= 0)
7998 : {
7999 91075172 : location_chain *node, *next;
8000 91075172 : location_chain **nextp;
8001 91075172 : bool changed;
8002 91075172 : rtx cur_loc;
8003 :
8004 91075172 : if (shared_var_p (var, set->vars))
8005 : {
8006 : /* If the variable contains the location part we have to
8007 : make a copy of the variable. */
8008 33253433 : for (node = var->var_part[pos].loc_chain; node;
8009 240613 : node = node->next)
8010 : {
8011 20957734 : if ((REG_P (node->loc) && REG_P (loc)
8012 20957710 : && REGNO (node->loc) == REGNO (loc))
8013 33485046 : || rtx_equal_p (node->loc, loc))
8014 : {
8015 33012820 : slot = unshare_variable (set, slot, var,
8016 : VAR_INIT_STATUS_UNKNOWN);
8017 33012820 : var = *slot;
8018 33012820 : break;
8019 : }
8020 : }
8021 : }
8022 :
8023 91075172 : if (pos == 0 && var->onepart && VAR_LOC_1PAUX (var))
8024 20150950 : cur_loc = VAR_LOC_FROM (var);
8025 : else
8026 70924222 : cur_loc = var->var_part[pos].cur_loc;
8027 :
8028 : /* Delete the location part. */
8029 91075172 : changed = false;
8030 91075172 : nextp = &var->var_part[pos].loc_chain;
8031 93397260 : for (node = *nextp; node; node = next)
8032 : {
8033 93397260 : next = node->next;
8034 56809703 : if ((REG_P (node->loc) && REG_P (loc)
8035 56809577 : && REGNO (node->loc) == REGNO (loc))
8036 94969569 : || rtx_equal_p (node->loc, loc))
8037 : {
8038 : /* If we have deleted the location which was last emitted
8039 : we have to emit new location so add the variable to set
8040 : of changed variables. */
8041 91075172 : if (cur_loc == node->loc)
8042 : {
8043 16306551 : changed = true;
8044 16306551 : var->var_part[pos].cur_loc = NULL;
8045 16306551 : if (pos == 0 && var->onepart && VAR_LOC_1PAUX (var))
8046 15954349 : VAR_LOC_FROM (var) = NULL;
8047 : }
8048 91075172 : delete node;
8049 91075172 : *nextp = next;
8050 91075172 : break;
8051 : }
8052 : else
8053 2322088 : nextp = &node->next;
8054 : }
8055 :
8056 91075172 : if (var->var_part[pos].loc_chain == NULL)
8057 : {
8058 63607860 : changed = true;
8059 63607860 : var->n_var_parts--;
8060 63784818 : while (pos < var->n_var_parts)
8061 : {
8062 176958 : var->var_part[pos] = var->var_part[pos + 1];
8063 176958 : pos++;
8064 : }
8065 : }
8066 91075172 : if (changed)
8067 65803278 : variable_was_changed (var, set);
8068 : }
8069 :
8070 91075178 : return slot;
8071 : }
8072 :
8073 : /* Delete the part of variable's location from dataflow set SET. The
8074 : variable part is specified by variable's declaration or value DV
8075 : and offset OFFSET and the part's location by LOC. */
8076 :
8077 : static void
8078 54243428 : delete_variable_part (dataflow_set *set, rtx loc, decl_or_value dv,
8079 : HOST_WIDE_INT offset)
8080 : {
8081 54243428 : variable **slot = shared_hash_find_slot_noinsert (set->vars, dv);
8082 54243428 : if (!slot)
8083 : return;
8084 :
8085 54243428 : delete_slot_part (set, loc, slot, offset);
8086 : }
8087 :
8088 :
8089 : /* Structure for passing some other parameters to function
8090 : vt_expand_loc_callback. */
8091 42092599 : class expand_loc_callback_data
8092 : {
8093 : public:
8094 : /* The variables and values active at this point. */
8095 : variable_table_type *vars;
8096 :
8097 : /* Stack of values and debug_exprs under expansion, and their
8098 : children. */
8099 : auto_vec<rtx, 4> expanding;
8100 :
8101 : /* Stack of values and debug_exprs whose expansion hit recursion
8102 : cycles. They will have VALUE_RECURSED_INTO marked when added to
8103 : this list. This flag will be cleared if any of its dependencies
8104 : resolves to a valid location. So, if the flag remains set at the
8105 : end of the search, we know no valid location for this one can
8106 : possibly exist. */
8107 : auto_vec<rtx, 4> pending;
8108 :
8109 : /* The maximum depth among the sub-expressions under expansion.
8110 : Zero indicates no expansion so far. */
8111 : expand_depth depth;
8112 : };
8113 :
8114 : /* Allocate the one-part auxiliary data structure for VAR, with enough
8115 : room for COUNT dependencies. */
8116 :
8117 : static void
8118 141199991 : loc_exp_dep_alloc (variable *var, int count)
8119 : {
8120 141199991 : size_t allocsize;
8121 :
8122 141199991 : gcc_checking_assert (var->onepart);
8123 :
8124 : /* We can be called with COUNT == 0 to allocate the data structure
8125 : without any dependencies, e.g. for the backlinks only. However,
8126 : if we are specifying a COUNT, then the dependency list must have
8127 : been emptied before. It would be possible to adjust pointers or
8128 : force it empty here, but this is better done at an earlier point
8129 : in the algorithm, so we instead leave an assertion to catch
8130 : errors. */
8131 141199991 : gcc_checking_assert (!count
8132 : || VAR_LOC_DEP_VEC (var) == NULL
8133 : || VAR_LOC_DEP_VEC (var)->is_empty ());
8134 :
8135 141199991 : if (VAR_LOC_1PAUX (var) && VAR_LOC_DEP_VEC (var)->space (count))
8136 : return;
8137 :
8138 44188546 : allocsize = offsetof (struct onepart_aux, deps)
8139 44188546 : + deps_vec::embedded_size (count);
8140 :
8141 44188546 : if (VAR_LOC_1PAUX (var))
8142 : {
8143 2711824 : VAR_LOC_1PAUX (var) = XRESIZEVAR (struct onepart_aux,
8144 : VAR_LOC_1PAUX (var), allocsize);
8145 : /* If the reallocation moves the onepaux structure, the
8146 : back-pointer to BACKLINKS in the first list member will still
8147 : point to its old location. Adjust it. */
8148 2711824 : if (VAR_LOC_DEP_LST (var))
8149 1234617 : VAR_LOC_DEP_LST (var)->pprev = VAR_LOC_DEP_LSTP (var);
8150 : }
8151 : else
8152 : {
8153 41476722 : VAR_LOC_1PAUX (var) = XNEWVAR (struct onepart_aux, allocsize);
8154 41476722 : *VAR_LOC_DEP_LSTP (var) = NULL;
8155 41476722 : VAR_LOC_FROM (var) = NULL;
8156 41476722 : VAR_LOC_DEPTH (var).complexity = 0;
8157 41476722 : VAR_LOC_DEPTH (var).entryvals = 0;
8158 : }
8159 44188546 : VAR_LOC_DEP_VEC (var)->embedded_init (count);
8160 : }
8161 :
8162 : /* Remove all entries from the vector of active dependencies of VAR,
8163 : removing them from the back-links lists too. */
8164 :
8165 : static void
8166 119701165 : loc_exp_dep_clear (variable *var)
8167 : {
8168 182671570 : while (VAR_LOC_DEP_VEC (var) && !VAR_LOC_DEP_VEC (var)->is_empty ())
8169 : {
8170 62970405 : loc_exp_dep *led = &VAR_LOC_DEP_VEC (var)->last ();
8171 62970405 : if (led->next)
8172 9756142 : led->next->pprev = led->pprev;
8173 62970405 : if (led->pprev)
8174 24537654 : *led->pprev = led->next;
8175 62970405 : VAR_LOC_DEP_VEC (var)->pop ();
8176 : }
8177 119701165 : }
8178 :
8179 : /* Insert an active dependency from VAR on X to the vector of
8180 : dependencies, and add the corresponding back-link to X's list of
8181 : back-links in VARS. */
8182 :
8183 : static void
8184 63035810 : loc_exp_insert_dep (variable *var, rtx x, variable_table_type *vars)
8185 : {
8186 63035810 : decl_or_value dv;
8187 63035810 : variable *xvar;
8188 63035810 : loc_exp_dep *led;
8189 :
8190 63035810 : dv = dv_from_rtx (x);
8191 :
8192 : /* ??? Build a vector of variables parallel to EXPANDING, to avoid
8193 : an additional look up? */
8194 63035810 : xvar = vars->find_with_hash (dv, dv_htab_hash (dv));
8195 :
8196 63035810 : if (!xvar)
8197 : {
8198 30847862 : xvar = variable_from_dropped (dv, NO_INSERT);
8199 30847862 : gcc_checking_assert (xvar);
8200 : }
8201 :
8202 : /* No point in adding the same backlink more than once. This may
8203 : arise if say the same value appears in two complex expressions in
8204 : the same loc_list, or even more than once in a single
8205 : expression. */
8206 63035810 : if (VAR_LOC_DEP_LST (xvar) && VAR_LOC_DEP_LST (xvar)->dv == var->dv)
8207 60262 : return;
8208 :
8209 62975548 : if (var->onepart == NOT_ONEPART)
8210 5143 : led = new loc_exp_dep;
8211 : else
8212 : {
8213 62970405 : loc_exp_dep empty;
8214 62970405 : memset (&empty, 0, sizeof (empty));
8215 62970405 : VAR_LOC_DEP_VEC (var)->quick_push (empty);
8216 62970405 : led = &VAR_LOC_DEP_VEC (var)->last ();
8217 : }
8218 62975548 : led->dv = var->dv;
8219 62975548 : led->value = x;
8220 :
8221 62975548 : loc_exp_dep_alloc (xvar, 0);
8222 62975548 : led->pprev = VAR_LOC_DEP_LSTP (xvar);
8223 62975548 : led->next = *led->pprev;
8224 62975548 : if (led->next)
8225 21766225 : led->next->pprev = &led->next;
8226 62975548 : *led->pprev = led;
8227 : }
8228 :
8229 : /* Create active dependencies of VAR on COUNT values starting at
8230 : VALUE, and corresponding back-links to the entries in VARS. Return
8231 : true if we found any pending-recursion results. */
8232 :
8233 : static bool
8234 78224443 : loc_exp_dep_set (variable *var, rtx result, rtx *value, int count,
8235 : variable_table_type *vars)
8236 : {
8237 78224443 : bool pending_recursion = false;
8238 :
8239 78224443 : gcc_checking_assert (VAR_LOC_DEP_VEC (var) == NULL
8240 : || VAR_LOC_DEP_VEC (var)->is_empty ());
8241 :
8242 : /* Set up all dependencies from last_child (as set up at the end of
8243 : the loop above) to the end. */
8244 78224443 : loc_exp_dep_alloc (var, count);
8245 :
8246 219474564 : while (count--)
8247 : {
8248 63025678 : rtx x = *value++;
8249 :
8250 63025678 : if (!pending_recursion)
8251 61964686 : pending_recursion = !result && VALUE_RECURSED_INTO (x);
8252 :
8253 63025678 : loc_exp_insert_dep (var, x, vars);
8254 : }
8255 :
8256 78224443 : return pending_recursion;
8257 : }
8258 :
8259 : /* Notify the back-links of IVAR that are pending recursion that we
8260 : have found a non-NIL value for it, so they are cleared for another
8261 : attempt to compute a current location. */
8262 :
8263 : static void
8264 32930059 : notify_dependents_of_resolved_value (variable *ivar, variable_table_type *vars)
8265 : {
8266 32930059 : loc_exp_dep *led, *next;
8267 :
8268 68897595 : for (led = VAR_LOC_DEP_LST (ivar); led; led = next)
8269 : {
8270 3037477 : decl_or_value dv = led->dv;
8271 3037477 : variable *var;
8272 :
8273 3037477 : next = led->next;
8274 :
8275 3037477 : if (dv_is_value_p (dv))
8276 : {
8277 3037477 : rtx value = dv_as_value (dv);
8278 :
8279 : /* If we have already resolved it, leave it alone. */
8280 3037477 : if (!VALUE_RECURSED_INTO (value))
8281 217071 : continue;
8282 :
8283 : /* Check that VALUE_RECURSED_INTO, true from the test above,
8284 : implies NO_LOC_P. */
8285 2820406 : gcc_checking_assert (NO_LOC_P (value));
8286 :
8287 : /* We won't notify variables that are being expanded,
8288 : because their dependency list is cleared before
8289 : recursing. */
8290 2820406 : NO_LOC_P (value) = false;
8291 2820406 : VALUE_RECURSED_INTO (value) = false;
8292 :
8293 2820406 : gcc_checking_assert (dv_changed_p (dv));
8294 : }
8295 : else
8296 : {
8297 0 : gcc_checking_assert (dv_onepart_p (dv) != NOT_ONEPART);
8298 0 : if (!dv_changed_p (dv))
8299 0 : continue;
8300 : }
8301 :
8302 2820406 : var = vars->find_with_hash (dv, dv_htab_hash (dv));
8303 :
8304 2820406 : if (!var)
8305 2310035 : var = variable_from_dropped (dv, NO_INSERT);
8306 :
8307 2310035 : if (var)
8308 2820406 : notify_dependents_of_resolved_value (var, vars);
8309 :
8310 2820406 : if (next)
8311 708816 : next->pprev = led->pprev;
8312 2820406 : if (led->pprev)
8313 2820406 : *led->pprev = next;
8314 2820406 : led->next = NULL;
8315 2820406 : led->pprev = NULL;
8316 : }
8317 32930059 : }
8318 :
8319 : static rtx vt_expand_loc_callback (rtx x, bitmap regs,
8320 : int max_depth, void *data);
8321 :
8322 : /* Return the combined depth, when one sub-expression evaluated to
8323 : BEST_DEPTH and the previous known depth was SAVED_DEPTH. */
8324 :
8325 : static inline expand_depth
8326 101944982 : update_depth (expand_depth saved_depth, expand_depth best_depth)
8327 : {
8328 : /* If we didn't find anything, stick with what we had. */
8329 101944982 : if (!best_depth.complexity)
8330 15227299 : return saved_depth;
8331 :
8332 : /* If we found hadn't found anything, use the depth of the current
8333 : expression. Do NOT add one extra level, we want to compute the
8334 : maximum depth among sub-expressions. We'll increment it later,
8335 : if appropriate. */
8336 86717683 : if (!saved_depth.complexity)
8337 85736901 : return best_depth;
8338 :
8339 : /* Combine the entryval count so that regardless of which one we
8340 : return, the entryval count is accurate. */
8341 980782 : best_depth.entryvals = saved_depth.entryvals
8342 980782 : = best_depth.entryvals + saved_depth.entryvals;
8343 :
8344 980782 : if (saved_depth.complexity < best_depth.complexity)
8345 69954 : return best_depth;
8346 : else
8347 910828 : return saved_depth;
8348 : }
8349 :
8350 : /* Expand VAR to a location RTX, updating its cur_loc. Use REGS and
8351 : DATA for cselib expand callback. If PENDRECP is given, indicate in
8352 : it whether any sub-expression couldn't be fully evaluated because
8353 : it is pending recursion resolution. */
8354 :
8355 : static inline rtx
8356 78224443 : vt_expand_var_loc_chain (variable *var, bitmap regs, void *data,
8357 : bool *pendrecp)
8358 : {
8359 78224443 : class expand_loc_callback_data *elcd
8360 : = (class expand_loc_callback_data *) data;
8361 78224443 : location_chain *loc, *next;
8362 78224443 : rtx result = NULL;
8363 78224443 : int first_child, result_first_child, last_child;
8364 78224443 : bool pending_recursion;
8365 78224443 : rtx loc_from = NULL;
8366 78224443 : struct elt_loc_list *cloc = NULL;
8367 78224443 : expand_depth depth = { 0, 0 }, saved_depth = elcd->depth;
8368 78224443 : int wanted_entryvals, found_entryvals = 0;
8369 :
8370 : /* Clear all backlinks pointing at this, so that we're not notified
8371 : while we're active. */
8372 78224443 : loc_exp_dep_clear (var);
8373 :
8374 81225349 : retry:
8375 81225349 : if (var->onepart == ONEPART_VALUE)
8376 : {
8377 36228623 : cselib_val *val = CSELIB_VAL_PTR (dv_as_value (var->dv));
8378 :
8379 36228623 : gcc_checking_assert (cselib_preserved_value_p (val));
8380 :
8381 36228623 : cloc = val->locs;
8382 : }
8383 :
8384 162450698 : first_child = result_first_child = last_child
8385 81225349 : = elcd->expanding.length ();
8386 :
8387 81225349 : wanted_entryvals = found_entryvals;
8388 :
8389 : /* Attempt to expand each available location in turn. */
8390 81225349 : for (next = loc = var->n_var_parts ? var->var_part[0].loc_chain : NULL;
8391 103222466 : loc || cloc; loc = next)
8392 : {
8393 84994261 : result_first_child = last_child;
8394 :
8395 84994261 : if (!loc)
8396 : {
8397 23035309 : loc_from = cloc->loc;
8398 23035309 : next = loc;
8399 23035309 : cloc = cloc->next;
8400 23035309 : if (unsuitable_loc (loc_from))
8401 2538 : goto try_next_loc;
8402 : }
8403 : else
8404 : {
8405 61958952 : loc_from = loc->loc;
8406 61958952 : next = loc->next;
8407 : }
8408 :
8409 84991723 : gcc_checking_assert (!unsuitable_loc (loc_from));
8410 :
8411 84991723 : elcd->depth.complexity = elcd->depth.entryvals = 0;
8412 84991723 : result = cselib_expand_value_rtx_cb (loc_from, regs, EXPR_DEPTH,
8413 : vt_expand_loc_callback, data);
8414 84991723 : last_child = elcd->expanding.length ();
8415 :
8416 84991723 : if (result)
8417 : {
8418 66210270 : depth = elcd->depth;
8419 :
8420 66210270 : gcc_checking_assert (depth.complexity
8421 : || result_first_child == last_child);
8422 :
8423 66210270 : if (last_child - result_first_child != 1)
8424 : {
8425 17452345 : if (!depth.complexity && GET_CODE (result) == ENTRY_VALUE)
8426 1957752 : depth.entryvals++;
8427 17452345 : depth.complexity++;
8428 : }
8429 :
8430 66210270 : if (depth.complexity <= EXPR_USE_DEPTH)
8431 : {
8432 66209239 : if (depth.entryvals <= wanted_entryvals)
8433 : break;
8434 3212095 : else if (!found_entryvals || depth.entryvals < found_entryvals)
8435 21997117 : found_entryvals = depth.entryvals;
8436 : }
8437 :
8438 : result = NULL;
8439 : }
8440 :
8441 18781453 : try_next_loc:
8442 : /* Set it up in case we leave the loop. */
8443 : depth.complexity = depth.entryvals = 0;
8444 : loc_from = NULL;
8445 : result_first_child = first_child;
8446 : }
8447 :
8448 81225349 : if (!loc_from && wanted_entryvals < found_entryvals)
8449 : {
8450 : /* We found entries with ENTRY_VALUEs and skipped them. Since
8451 : we could not find any expansions without ENTRY_VALUEs, but we
8452 : found at least one with them, go back and get an entry with
8453 : the minimum number ENTRY_VALUE count that we found. We could
8454 : avoid looping, but since each sub-loc is already resolved,
8455 : the re-expansion should be trivial. ??? Should we record all
8456 : attempted locs as dependencies, so that we retry the
8457 : expansion should any of them change, in the hope it can give
8458 : us a new entry without an ENTRY_VALUE? */
8459 3000906 : elcd->expanding.truncate (first_child);
8460 3000906 : goto retry;
8461 : }
8462 :
8463 : /* Register all encountered dependencies as active. */
8464 78224443 : pending_recursion = loc_exp_dep_set
8465 156448886 : (var, result, elcd->expanding.address () + result_first_child,
8466 : last_child - result_first_child, elcd->vars);
8467 :
8468 78224443 : elcd->expanding.truncate (first_child);
8469 :
8470 : /* Record where the expansion came from. */
8471 78224443 : gcc_checking_assert (!result || !pending_recursion);
8472 78224443 : VAR_LOC_FROM (var) = loc_from;
8473 78224443 : VAR_LOC_DEPTH (var) = depth;
8474 :
8475 78224443 : gcc_checking_assert (!depth.complexity == !result);
8476 :
8477 78224443 : elcd->depth = update_depth (saved_depth, depth);
8478 :
8479 : /* Indicate whether any of the dependencies are pending recursion
8480 : resolution. */
8481 78224443 : if (pendrecp)
8482 40127390 : *pendrecp = pending_recursion;
8483 :
8484 78224443 : if (!pendrecp || !pending_recursion)
8485 72688473 : var->var_part[0].cur_loc = result;
8486 :
8487 78224443 : return result;
8488 : }
8489 :
8490 : /* Callback for cselib_expand_value, that looks for expressions
8491 : holding the value in the var-tracking hash tables. Return X for
8492 : standard processing, anything else is to be used as-is. */
8493 :
8494 : static rtx
8495 74195372 : vt_expand_loc_callback (rtx x, bitmap regs,
8496 : int max_depth ATTRIBUTE_UNUSED,
8497 : void *data)
8498 : {
8499 74195372 : class expand_loc_callback_data *elcd
8500 : = (class expand_loc_callback_data *) data;
8501 74195372 : decl_or_value dv;
8502 74195372 : variable *var;
8503 74195372 : rtx result, subreg;
8504 74195372 : bool pending_recursion = false;
8505 74195372 : bool from_empty = false;
8506 :
8507 74195372 : switch (GET_CODE (x))
8508 : {
8509 862174 : case SUBREG:
8510 862174 : subreg = cselib_expand_value_rtx_cb (SUBREG_REG (x), regs,
8511 : EXPR_DEPTH,
8512 : vt_expand_loc_callback, data);
8513 :
8514 862174 : if (!subreg)
8515 : return NULL;
8516 :
8517 1199132 : result = simplify_gen_subreg (GET_MODE (x), subreg,
8518 599566 : GET_MODE (SUBREG_REG (x)),
8519 599566 : SUBREG_BYTE (x));
8520 :
8521 : /* Invalid SUBREGs are ok in debug info. ??? We could try
8522 : alternate expansions for the VALUE as well. */
8523 599566 : if (!result && GET_MODE (subreg) != VOIDmode)
8524 2287 : result = gen_rtx_raw_SUBREG (GET_MODE (x), subreg, SUBREG_BYTE (x));
8525 :
8526 : return result;
8527 :
8528 73333198 : case DEBUG_EXPR:
8529 73333198 : case VALUE:
8530 73333198 : dv = dv_from_rtx (x);
8531 73333198 : break;
8532 :
8533 : default:
8534 : return x;
8535 : }
8536 :
8537 73333198 : elcd->expanding.safe_push (x);
8538 :
8539 : /* Check that VALUE_RECURSED_INTO implies NO_LOC_P. */
8540 73333198 : gcc_checking_assert (!VALUE_RECURSED_INTO (x) || NO_LOC_P (x));
8541 :
8542 73333198 : if (NO_LOC_P (x))
8543 : {
8544 9485269 : gcc_checking_assert (VALUE_RECURSED_INTO (x) || !dv_changed_p (dv));
8545 : return NULL;
8546 : }
8547 :
8548 63847929 : var = elcd->vars->find_with_hash (dv, dv_htab_hash (dv));
8549 :
8550 63847929 : if (!var)
8551 : {
8552 31896547 : from_empty = true;
8553 31896547 : var = variable_from_dropped (dv, INSERT);
8554 : }
8555 :
8556 31896547 : gcc_checking_assert (var);
8557 :
8558 63847929 : if (!dv_changed_p (dv))
8559 : {
8560 23720539 : gcc_checking_assert (!NO_LOC_P (x));
8561 23720539 : gcc_checking_assert (var->var_part[0].cur_loc);
8562 23720539 : gcc_checking_assert (VAR_LOC_1PAUX (var));
8563 23720539 : gcc_checking_assert (VAR_LOC_1PAUX (var)->depth.complexity);
8564 :
8565 23720539 : elcd->depth = update_depth (elcd->depth, VAR_LOC_1PAUX (var)->depth);
8566 :
8567 23720539 : return var->var_part[0].cur_loc;
8568 : }
8569 :
8570 40127390 : VALUE_RECURSED_INTO (x) = true;
8571 : /* This is tentative, but it makes some tests simpler. */
8572 40127390 : NO_LOC_P (x) = true;
8573 :
8574 40127390 : gcc_checking_assert (var->n_var_parts == 1 || from_empty);
8575 :
8576 40127390 : result = vt_expand_var_loc_chain (var, regs, data, &pending_recursion);
8577 :
8578 40127390 : if (pending_recursion)
8579 : {
8580 5535970 : gcc_checking_assert (!result);
8581 5535970 : elcd->pending.safe_push (x);
8582 : }
8583 : else
8584 : {
8585 34591420 : NO_LOC_P (x) = !result;
8586 34591420 : VALUE_RECURSED_INTO (x) = false;
8587 34591420 : set_dv_changed (dv, false);
8588 :
8589 34591420 : if (result)
8590 30109653 : notify_dependents_of_resolved_value (var, elcd->vars);
8591 : }
8592 :
8593 : return result;
8594 : }
8595 :
8596 : /* While expanding variables, we may encounter recursion cycles
8597 : because of mutual (possibly indirect) dependencies between two
8598 : particular variables (or values), say A and B. If we're trying to
8599 : expand A when we get to B, which in turn attempts to expand A, if
8600 : we can't find any other expansion for B, we'll add B to this
8601 : pending-recursion stack, and tentatively return NULL for its
8602 : location. This tentative value will be used for any other
8603 : occurrences of B, unless A gets some other location, in which case
8604 : it will notify B that it is worth another try at computing a
8605 : location for it, and it will use the location computed for A then.
8606 : At the end of the expansion, the tentative NULL locations become
8607 : final for all members of PENDING that didn't get a notification.
8608 : This function performs this finalization of NULL locations. */
8609 :
8610 : static void
8611 42092595 : resolve_expansions_pending_recursion (vec<rtx, va_heap> *pending)
8612 : {
8613 47628565 : while (!pending->is_empty ())
8614 : {
8615 5535970 : rtx x = pending->pop ();
8616 5535970 : decl_or_value dv;
8617 :
8618 5535970 : if (!VALUE_RECURSED_INTO (x))
8619 2820406 : continue;
8620 :
8621 2715564 : gcc_checking_assert (NO_LOC_P (x));
8622 2715564 : VALUE_RECURSED_INTO (x) = false;
8623 2715564 : dv = dv_from_rtx (x);
8624 2715564 : gcc_checking_assert (dv_changed_p (dv));
8625 2715564 : set_dv_changed (dv, false);
8626 : }
8627 42092595 : }
8628 :
8629 : /* Initialize expand_loc_callback_data D with variable hash table V.
8630 : It must be a macro because of alloca (vec stack). */
8631 : #define INIT_ELCD(d, v) \
8632 : do \
8633 : { \
8634 : (d).vars = (v); \
8635 : (d).depth.complexity = (d).depth.entryvals = 0; \
8636 : } \
8637 : while (0)
8638 : /* Finalize expand_loc_callback_data D, resolved to location L. */
8639 : #define FINI_ELCD(d, l) \
8640 : do \
8641 : { \
8642 : resolve_expansions_pending_recursion (&(d).pending); \
8643 : (d).pending.release (); \
8644 : (d).expanding.release (); \
8645 : \
8646 : if ((l) && MEM_P (l)) \
8647 : (l) = targetm.delegitimize_address (l); \
8648 : } \
8649 : while (0)
8650 :
8651 : /* Expand VALUEs and DEBUG_EXPRs in LOC to a location, using the
8652 : equivalences in VARS, updating their CUR_LOCs in the process. */
8653 :
8654 : static rtx
8655 3995546 : vt_expand_loc (rtx loc, variable_table_type *vars)
8656 : {
8657 3995546 : class expand_loc_callback_data data;
8658 3995546 : rtx result;
8659 :
8660 3995546 : if (!MAY_HAVE_DEBUG_BIND_INSNS)
8661 : return loc;
8662 :
8663 3995542 : INIT_ELCD (data, vars);
8664 :
8665 3995542 : result = cselib_expand_value_rtx_cb (loc, scratch_regs, EXPR_DEPTH,
8666 : vt_expand_loc_callback, &data);
8667 :
8668 3995542 : FINI_ELCD (data, result);
8669 :
8670 : return result;
8671 3995546 : }
8672 :
8673 : /* Expand the one-part VARiable to a location, using the equivalences
8674 : in VARS, updating their CUR_LOCs in the process. */
8675 :
8676 : static rtx
8677 38097053 : vt_expand_1pvar (variable *var, variable_table_type *vars)
8678 : {
8679 38097053 : class expand_loc_callback_data data;
8680 38097053 : rtx loc;
8681 :
8682 38097053 : gcc_checking_assert (var->onepart && var->n_var_parts == 1);
8683 :
8684 38097053 : if (!dv_changed_p (var->dv))
8685 0 : return var->var_part[0].cur_loc;
8686 :
8687 38097053 : INIT_ELCD (data, vars);
8688 :
8689 38097053 : loc = vt_expand_var_loc_chain (var, scratch_regs, &data, NULL);
8690 :
8691 38097053 : gcc_checking_assert (data.expanding.is_empty ());
8692 :
8693 38097053 : FINI_ELCD (data, loc);
8694 :
8695 : return loc;
8696 38097053 : }
8697 :
8698 : /* Emit the NOTE_INSN_VAR_LOCATION for variable *VARP. DATA contains
8699 : additional parameters: WHERE specifies whether the note shall be emitted
8700 : before or after instruction INSN. */
8701 :
8702 : int
8703 58782354 : emit_note_insn_var_location (variable **varp, emit_note_data *data)
8704 : {
8705 58782354 : variable *var = *varp;
8706 58782354 : rtx_insn *insn = data->insn;
8707 58782354 : enum emit_note_where where = data->where;
8708 58782354 : variable_table_type *vars = data->vars;
8709 58782354 : rtx_note *note;
8710 58782354 : rtx note_vl;
8711 58782354 : int i, j, n_var_parts;
8712 58782354 : bool complete;
8713 58782354 : enum var_init_status initialized = VAR_INIT_STATUS_UNINITIALIZED;
8714 58782354 : HOST_WIDE_INT last_limit;
8715 58782354 : HOST_WIDE_INT offsets[MAX_VAR_PARTS];
8716 58782354 : rtx loc[MAX_VAR_PARTS];
8717 58782354 : tree decl;
8718 58782354 : location_chain *lc;
8719 :
8720 58782354 : gcc_checking_assert (var->onepart == NOT_ONEPART
8721 : || var->onepart == ONEPART_VDECL);
8722 :
8723 58782354 : decl = dv_as_decl (var->dv);
8724 :
8725 58782354 : complete = true;
8726 58782354 : last_limit = 0;
8727 58782354 : n_var_parts = 0;
8728 58782354 : if (!var->onepart)
8729 1895789 : for (i = 0; i < var->n_var_parts; i++)
8730 899549 : if (var->var_part[i].cur_loc == NULL && var->var_part[i].loc_chain)
8731 662932 : var->var_part[i].cur_loc = var->var_part[i].loc_chain->loc;
8732 97593803 : for (i = 0; i < var->n_var_parts; i++)
8733 : {
8734 38930938 : machine_mode mode, wider_mode;
8735 38930938 : rtx loc2;
8736 38930938 : HOST_WIDE_INT offset, size, wider_size;
8737 :
8738 38930938 : if (i == 0 && var->onepart)
8739 : {
8740 38097053 : gcc_checking_assert (var->n_var_parts == 1);
8741 38097053 : offset = 0;
8742 38097053 : initialized = VAR_INIT_STATUS_INITIALIZED;
8743 38097053 : loc2 = vt_expand_1pvar (var, vars);
8744 : }
8745 : else
8746 : {
8747 833885 : if (last_limit < VAR_PART_OFFSET (var, i))
8748 : {
8749 : complete = false;
8750 58782354 : break;
8751 : }
8752 714396 : else if (last_limit > VAR_PART_OFFSET (var, i))
8753 38811449 : continue;
8754 694674 : offset = VAR_PART_OFFSET (var, i);
8755 694674 : loc2 = var->var_part[i].cur_loc;
8756 694674 : if (loc2 && GET_CODE (loc2) == MEM
8757 66954 : && GET_CODE (XEXP (loc2, 0)) == VALUE)
8758 : {
8759 10132 : rtx depval = XEXP (loc2, 0);
8760 :
8761 10132 : loc2 = vt_expand_loc (loc2, vars);
8762 :
8763 10132 : if (loc2)
8764 10132 : loc_exp_insert_dep (var, depval, vars);
8765 : }
8766 10132 : if (!loc2)
8767 : {
8768 0 : complete = false;
8769 0 : continue;
8770 : }
8771 694674 : gcc_checking_assert (GET_CODE (loc2) != VALUE);
8772 706537 : for (lc = var->var_part[i].loc_chain; lc; lc = lc->next)
8773 706537 : if (var->var_part[i].cur_loc == lc->loc)
8774 : {
8775 694674 : initialized = lc->init;
8776 694674 : break;
8777 : }
8778 694674 : gcc_assert (lc);
8779 : }
8780 :
8781 38791727 : offsets[n_var_parts] = offset;
8782 38791727 : if (!loc2)
8783 : {
8784 5209562 : complete = false;
8785 5209562 : continue;
8786 : }
8787 33582165 : loc[n_var_parts] = loc2;
8788 33582165 : mode = GET_MODE (var->var_part[i].cur_loc);
8789 33582165 : if (mode == VOIDmode && var->onepart)
8790 3299086 : mode = DECL_MODE (decl);
8791 : /* We ony track subparts of constant-sized objects, since at present
8792 : there's no representation for polynomial pieces. */
8793 67164330 : if (!GET_MODE_SIZE (mode).is_constant (&size))
8794 : {
8795 : complete = false;
8796 : continue;
8797 : }
8798 33582165 : last_limit = offsets[n_var_parts] + size;
8799 :
8800 : /* Attempt to merge adjacent registers or memory. */
8801 33601887 : for (j = i + 1; j < var->n_var_parts; j++)
8802 256039 : if (last_limit <= VAR_PART_OFFSET (var, j))
8803 : break;
8804 33582165 : if (j < var->n_var_parts
8805 236317 : && GET_MODE_WIDER_MODE (mode).exists (&wider_mode)
8806 472634 : && GET_MODE_SIZE (wider_mode).is_constant (&wider_size)
8807 236317 : && var->var_part[j].cur_loc
8808 236317 : && mode == GET_MODE (var->var_part[j].cur_loc)
8809 232279 : && (REG_P (loc[n_var_parts]) || MEM_P (loc[n_var_parts]))
8810 232279 : && last_limit == (var->onepart ? 0 : VAR_PART_OFFSET (var, j))
8811 232204 : && (loc2 = vt_expand_loc (var->var_part[j].cur_loc, vars))
8812 33814369 : && GET_CODE (loc[n_var_parts]) == GET_CODE (loc2))
8813 : {
8814 225410 : rtx new_loc = NULL;
8815 225410 : poly_int64 offset2;
8816 :
8817 225410 : if (REG_P (loc[n_var_parts])
8818 212691 : && hard_regno_nregs (REGNO (loc[n_var_parts]), mode) * 2
8819 212691 : == hard_regno_nregs (REGNO (loc[n_var_parts]), wider_mode)
8820 437491 : && end_hard_regno (mode, REGNO (loc[n_var_parts]))
8821 212081 : == REGNO (loc2))
8822 : {
8823 53752 : if (! WORDS_BIG_ENDIAN && ! BYTES_BIG_ENDIAN)
8824 53752 : new_loc = simplify_subreg (wider_mode, loc[n_var_parts],
8825 : mode, 0);
8826 : else if (WORDS_BIG_ENDIAN && BYTES_BIG_ENDIAN)
8827 : new_loc = simplify_subreg (wider_mode, loc2, mode, 0);
8828 53752 : if (new_loc)
8829 : {
8830 53752 : if (!REG_P (new_loc)
8831 53752 : || REGNO (new_loc) != REGNO (loc[n_var_parts]))
8832 : new_loc = NULL;
8833 : else
8834 53752 : REG_ATTRS (new_loc) = REG_ATTRS (loc[n_var_parts]);
8835 : }
8836 : }
8837 171658 : else if (MEM_P (loc[n_var_parts])
8838 12719 : && GET_CODE (XEXP (loc2, 0)) == PLUS
8839 12718 : && REG_P (XEXP (XEXP (loc2, 0), 0))
8840 184376 : && poly_int_rtx_p (XEXP (XEXP (loc2, 0), 1), &offset2))
8841 : {
8842 12718 : poly_int64 end1 = size;
8843 12718 : rtx base1 = strip_offset_and_add (XEXP (loc[n_var_parts], 0),
8844 : &end1);
8845 12718 : if (rtx_equal_p (base1, XEXP (XEXP (loc2, 0), 0))
8846 12718 : && known_eq (end1, offset2))
8847 11894 : new_loc = adjust_address_nv (loc[n_var_parts],
8848 : wider_mode, 0);
8849 : }
8850 :
8851 66470 : if (new_loc)
8852 : {
8853 65646 : loc[n_var_parts] = new_loc;
8854 65646 : mode = wider_mode;
8855 65646 : last_limit = offsets[n_var_parts] + wider_size;
8856 65646 : i = j;
8857 : }
8858 : }
8859 33582165 : ++n_var_parts;
8860 : }
8861 58782354 : poly_uint64 type_size_unit
8862 58782354 : = tree_to_poly_uint64 (TYPE_SIZE_UNIT (TREE_TYPE (decl)));
8863 58782354 : if (maybe_lt (poly_uint64 (last_limit), type_size_unit))
8864 25526910 : complete = false;
8865 :
8866 58782354 : if (! flag_var_tracking_uninit)
8867 2 : initialized = VAR_INIT_STATUS_INITIALIZED;
8868 :
8869 58782354 : note_vl = NULL_RTX;
8870 58782354 : if (!complete)
8871 25526910 : note_vl = gen_rtx_VAR_LOCATION (VOIDmode, decl, NULL_RTX, initialized);
8872 33255444 : else if (n_var_parts == 1)
8873 : {
8874 33088864 : rtx expr_list;
8875 :
8876 33088864 : if (offsets[0] || GET_CODE (loc[0]) == PARALLEL)
8877 0 : expr_list = gen_rtx_EXPR_LIST (VOIDmode, loc[0], GEN_INT (offsets[0]));
8878 : else
8879 : expr_list = loc[0];
8880 :
8881 33088864 : note_vl = gen_rtx_VAR_LOCATION (VOIDmode, decl, expr_list, initialized);
8882 : }
8883 166580 : else if (n_var_parts)
8884 : {
8885 : rtx parallel;
8886 :
8887 499764 : for (i = 0; i < n_var_parts; i++)
8888 333184 : loc[i]
8889 333184 : = gen_rtx_EXPR_LIST (VOIDmode, loc[i], GEN_INT (offsets[i]));
8890 :
8891 166580 : parallel = gen_rtx_PARALLEL (VOIDmode,
8892 : gen_rtvec_v (n_var_parts, loc));
8893 166580 : note_vl = gen_rtx_VAR_LOCATION (VOIDmode, decl,
8894 : parallel, initialized);
8895 : }
8896 :
8897 58782354 : if (where != EMIT_NOTE_BEFORE_INSN)
8898 : {
8899 32358923 : note = emit_note_after (NOTE_INSN_VAR_LOCATION, insn);
8900 32358923 : if (where == EMIT_NOTE_AFTER_CALL_INSN)
8901 3183208 : NOTE_DURING_CALL_P (note) = true;
8902 : }
8903 : else
8904 : {
8905 : /* Make sure that the call related notes come first. */
8906 26423431 : while (NEXT_INSN (insn)
8907 26423431 : && NOTE_P (insn)
8908 1366104 : && NOTE_KIND (insn) == NOTE_INSN_VAR_LOCATION
8909 26423431 : && NOTE_DURING_CALL_P (insn))
8910 : insn = NEXT_INSN (insn);
8911 26423431 : if (NOTE_P (insn)
8912 1366104 : && NOTE_KIND (insn) == NOTE_INSN_VAR_LOCATION
8913 26423431 : && NOTE_DURING_CALL_P (insn))
8914 0 : note = emit_note_after (NOTE_INSN_VAR_LOCATION, insn);
8915 : else
8916 26423431 : note = emit_note_before (NOTE_INSN_VAR_LOCATION, insn);
8917 : }
8918 58782354 : NOTE_VAR_LOCATION (note) = note_vl;
8919 :
8920 58782354 : set_dv_changed (var->dv, false);
8921 58782354 : gcc_assert (var->in_changed_variables);
8922 58782354 : var->in_changed_variables = false;
8923 58782354 : changed_variables->clear_slot (varp);
8924 :
8925 : /* Continue traversing the hash table. */
8926 58782354 : return 1;
8927 : }
8928 :
8929 : /* While traversing changed_variables, push onto DATA (a stack of RTX
8930 : values) entries that aren't user variables. */
8931 :
8932 : int
8933 172512840 : var_track_values_to_stack (variable **slot,
8934 : vec<rtx, va_heap> *changed_values_stack)
8935 : {
8936 172512840 : variable *var = *slot;
8937 :
8938 172512840 : if (var->onepart == ONEPART_VALUE)
8939 118038431 : changed_values_stack->safe_push (dv_as_value (var->dv));
8940 54474409 : else if (var->onepart == ONEPART_DEXPR)
8941 8035525 : changed_values_stack->safe_push (DECL_RTL_KNOWN_SET (dv_as_decl (var->dv)));
8942 :
8943 172512840 : return 1;
8944 : }
8945 :
8946 : /* Remove from changed_variables the entry whose DV corresponds to
8947 : value or debug_expr VAL. */
8948 : static void
8949 126073956 : remove_value_from_changed_variables (rtx val)
8950 : {
8951 126073956 : decl_or_value dv = dv_from_rtx (val);
8952 126073956 : variable **slot;
8953 126073956 : variable *var;
8954 :
8955 126073956 : slot = changed_variables->find_slot_with_hash (dv, dv_htab_hash (dv),
8956 : NO_INSERT);
8957 126073956 : var = *slot;
8958 126073956 : var->in_changed_variables = false;
8959 126073956 : changed_variables->clear_slot (slot);
8960 126073956 : }
8961 :
8962 : /* If VAL (a value or debug_expr) has backlinks to variables actively
8963 : dependent on it in HTAB or in CHANGED_VARIABLES, mark them as
8964 : changed, adding to CHANGED_VALUES_STACK any dependencies that may
8965 : have dependencies of their own to notify. */
8966 :
8967 : static void
8968 138105655 : notify_dependents_of_changed_value (rtx val, variable_table_type *htab,
8969 : vec<rtx, va_heap> *changed_values_stack)
8970 : {
8971 138105655 : variable **slot;
8972 138105655 : variable *var;
8973 138105655 : loc_exp_dep *led;
8974 138105655 : decl_or_value dv = dv_from_rtx (val);
8975 :
8976 138105655 : slot = changed_variables->find_slot_with_hash (dv, dv_htab_hash (dv),
8977 : NO_INSERT);
8978 138105655 : if (!slot)
8979 12031699 : slot = htab->find_slot_with_hash (dv, dv_htab_hash (dv), NO_INSERT);
8980 12031699 : if (!slot)
8981 8170088 : slot = dropped_values->find_slot_with_hash (dv, dv_htab_hash (dv),
8982 : NO_INSERT);
8983 138105655 : var = *slot;
8984 :
8985 171294973 : while ((led = VAR_LOC_DEP_LST (var)))
8986 : {
8987 33189318 : decl_or_value ldv = led->dv;
8988 33189318 : variable *ivar;
8989 :
8990 : /* Deactivate and remove the backlink, as it was “used up”. It
8991 : makes no sense to attempt to notify the same entity again:
8992 : either it will be recomputed and re-register an active
8993 : dependency, or it will still have the changed mark. */
8994 33189318 : if (led->next)
8995 8632707 : led->next->pprev = led->pprev;
8996 33189318 : if (led->pprev)
8997 33189318 : *led->pprev = led->next;
8998 33189318 : led->next = NULL;
8999 33189318 : led->pprev = NULL;
9000 :
9001 33189318 : if (dv_changed_p (ldv))
9002 8813225 : continue;
9003 :
9004 24376093 : switch (dv_onepart_p (ldv))
9005 : {
9006 12031699 : case ONEPART_VALUE:
9007 12031699 : case ONEPART_DEXPR:
9008 12031699 : set_dv_changed (ldv, true);
9009 12031699 : changed_values_stack->safe_push (dv_as_rtx (ldv));
9010 12031699 : break;
9011 :
9012 12341536 : case ONEPART_VDECL:
9013 12341536 : ivar = htab->find_with_hash (ldv, dv_htab_hash (ldv));
9014 12341536 : gcc_checking_assert (!VAR_LOC_DEP_LST (ivar));
9015 12341536 : variable_was_changed (ivar, NULL);
9016 12341536 : break;
9017 :
9018 2858 : case NOT_ONEPART:
9019 2858 : delete led;
9020 2858 : ivar = htab->find_with_hash (ldv, dv_htab_hash (ldv));
9021 2858 : if (ivar)
9022 : {
9023 2856 : int i = ivar->n_var_parts;
9024 5918 : while (i--)
9025 : {
9026 4876 : rtx loc = ivar->var_part[i].cur_loc;
9027 :
9028 4876 : if (loc && GET_CODE (loc) == MEM
9029 3237 : && XEXP (loc, 0) == val)
9030 : {
9031 1814 : variable_was_changed (ivar, NULL);
9032 1814 : break;
9033 : }
9034 : }
9035 : }
9036 : break;
9037 :
9038 : default:
9039 : gcc_unreachable ();
9040 : }
9041 : }
9042 138105655 : }
9043 :
9044 : /* Take out of changed_variables any entries that don't refer to use
9045 : variables. Back-propagate change notifications from values and
9046 : debug_exprs to their active dependencies in HTAB or in
9047 : CHANGED_VARIABLES. */
9048 :
9049 : static void
9050 85958505 : process_changed_values (variable_table_type *htab)
9051 : {
9052 85958505 : int i, n;
9053 85958505 : rtx val;
9054 85958505 : auto_vec<rtx, 20> changed_values_stack;
9055 :
9056 : /* Move values from changed_variables to changed_values_stack. */
9057 85958505 : changed_variables
9058 : ->traverse <vec<rtx, va_heap>*, var_track_values_to_stack>
9059 258471345 : (&changed_values_stack);
9060 :
9061 : /* Back-propagate change notifications in values while popping
9062 : them from the stack. */
9063 310022665 : for (n = i = changed_values_stack.length ();
9064 224064160 : i > 0; i = changed_values_stack.length ())
9065 : {
9066 138105655 : val = changed_values_stack.pop ();
9067 138105655 : notify_dependents_of_changed_value (val, htab, &changed_values_stack);
9068 :
9069 : /* This condition will hold when visiting each of the entries
9070 : originally in changed_variables. We can't remove them
9071 : earlier because this could drop the backlinks before we got a
9072 : chance to use them. */
9073 138105655 : if (i == n)
9074 : {
9075 126073956 : remove_value_from_changed_variables (val);
9076 126073956 : n--;
9077 : }
9078 : }
9079 85958505 : }
9080 :
9081 : /* Emit NOTE_INSN_VAR_LOCATION note for each variable from a chain
9082 : CHANGED_VARIABLES and delete this chain. WHERE specifies whether
9083 : the notes shall be emitted before of after instruction INSN. */
9084 :
9085 : static void
9086 120617381 : emit_notes_for_changes (rtx_insn *insn, enum emit_note_where where,
9087 : shared_hash *vars)
9088 : {
9089 120617381 : emit_note_data data;
9090 120617381 : variable_table_type *htab = shared_hash_htab (vars);
9091 :
9092 120617381 : if (changed_variables->is_empty ())
9093 34658792 : return;
9094 :
9095 85958589 : if (MAY_HAVE_DEBUG_BIND_INSNS)
9096 85958505 : process_changed_values (htab);
9097 :
9098 85958589 : data.insn = insn;
9099 85958589 : data.where = where;
9100 85958589 : data.vars = htab;
9101 :
9102 85958589 : changed_variables
9103 144740943 : ->traverse <emit_note_data*, emit_note_insn_var_location> (&data);
9104 : }
9105 :
9106 : /* Add variable *SLOT to the chain CHANGED_VARIABLES if it differs from the
9107 : same variable in hash table DATA or is not there at all. */
9108 :
9109 : int
9110 287822618 : emit_notes_for_differences_1 (variable **slot, variable_table_type *new_vars)
9111 : {
9112 287822618 : variable *old_var, *new_var;
9113 :
9114 287822618 : old_var = *slot;
9115 287822618 : new_var = new_vars->find_with_hash (old_var->dv, dv_htab_hash (old_var->dv));
9116 :
9117 287822618 : if (!new_var)
9118 : {
9119 : /* Variable has disappeared. */
9120 41440018 : variable *empty_var = NULL;
9121 :
9122 41440018 : if (old_var->onepart == ONEPART_VALUE
9123 41440018 : || old_var->onepart == ONEPART_DEXPR)
9124 : {
9125 31602761 : empty_var = variable_from_dropped (old_var->dv, NO_INSERT);
9126 31602761 : if (empty_var)
9127 : {
9128 3932931 : gcc_checking_assert (!empty_var->in_changed_variables);
9129 3932931 : if (!VAR_LOC_1PAUX (old_var))
9130 : {
9131 1825349 : VAR_LOC_1PAUX (old_var) = VAR_LOC_1PAUX (empty_var);
9132 1825349 : VAR_LOC_1PAUX (empty_var) = NULL;
9133 : }
9134 : else
9135 2107582 : gcc_checking_assert (!VAR_LOC_1PAUX (empty_var));
9136 : }
9137 : }
9138 :
9139 1825349 : if (!empty_var)
9140 : {
9141 37507087 : empty_var = onepart_pool_allocate (old_var->onepart);
9142 37507087 : empty_var->dv = old_var->dv;
9143 37507087 : empty_var->refcount = 0;
9144 37507087 : empty_var->n_var_parts = 0;
9145 37507087 : empty_var->onepart = old_var->onepart;
9146 37507087 : empty_var->in_changed_variables = false;
9147 : }
9148 :
9149 41440018 : if (empty_var->onepart)
9150 : {
9151 : /* Propagate the auxiliary data to (ultimately)
9152 : changed_variables. */
9153 41342442 : empty_var->var_part[0].loc_chain = NULL;
9154 41342442 : empty_var->var_part[0].cur_loc = NULL;
9155 41342442 : VAR_LOC_1PAUX (empty_var) = VAR_LOC_1PAUX (old_var);
9156 41342442 : VAR_LOC_1PAUX (old_var) = NULL;
9157 : }
9158 41440018 : variable_was_changed (empty_var, NULL);
9159 : /* Continue traversing the hash table. */
9160 41440018 : return 1;
9161 : }
9162 : /* Update cur_loc and one-part auxiliary data, before new_var goes
9163 : through variable_was_changed. */
9164 246382600 : if (old_var != new_var && new_var->onepart)
9165 : {
9166 33264948 : gcc_checking_assert (VAR_LOC_1PAUX (new_var) == NULL);
9167 33264948 : VAR_LOC_1PAUX (new_var) = VAR_LOC_1PAUX (old_var);
9168 33264948 : VAR_LOC_1PAUX (old_var) = NULL;
9169 33264948 : new_var->var_part[0].cur_loc = old_var->var_part[0].cur_loc;
9170 : }
9171 246382600 : if (variable_different_p (old_var, new_var))
9172 8383794 : variable_was_changed (new_var, NULL);
9173 :
9174 : /* Continue traversing the hash table. */
9175 : return 1;
9176 : }
9177 :
9178 : /* Add variable *SLOT to the chain CHANGED_VARIABLES if it is not in hash
9179 : table DATA. */
9180 :
9181 : int
9182 271154472 : emit_notes_for_differences_2 (variable **slot, variable_table_type *old_vars)
9183 : {
9184 271154472 : variable *old_var, *new_var;
9185 :
9186 271154472 : new_var = *slot;
9187 271154472 : old_var = old_vars->find_with_hash (new_var->dv, dv_htab_hash (new_var->dv));
9188 271154472 : if (!old_var)
9189 : {
9190 : int i;
9191 49637145 : for (i = 0; i < new_var->n_var_parts; i++)
9192 24865273 : new_var->var_part[i].cur_loc = NULL;
9193 24771872 : variable_was_changed (new_var, NULL);
9194 : }
9195 :
9196 : /* Continue traversing the hash table. */
9197 271154472 : return 1;
9198 : }
9199 :
9200 : /* Emit notes before INSN for differences between dataflow sets OLD_SET and
9201 : NEW_SET. */
9202 :
9203 : static void
9204 7340889 : emit_notes_for_differences (rtx_insn *insn, dataflow_set *old_set,
9205 : dataflow_set *new_set)
9206 : {
9207 7340889 : shared_hash_htab (old_set->vars)
9208 : ->traverse <variable_table_type *, emit_notes_for_differences_1>
9209 295163507 : (shared_hash_htab (new_set->vars));
9210 7340889 : shared_hash_htab (new_set->vars)
9211 : ->traverse <variable_table_type *, emit_notes_for_differences_2>
9212 278495361 : (shared_hash_htab (old_set->vars));
9213 7340889 : emit_notes_for_changes (insn, EMIT_NOTE_BEFORE_INSN, new_set->vars);
9214 7340889 : }
9215 :
9216 : /* Return the next insn after INSN that is not a NOTE_INSN_VAR_LOCATION. */
9217 :
9218 : static rtx_insn *
9219 117531839 : next_non_note_insn_var_location (rtx_insn *insn)
9220 : {
9221 119122131 : while (insn)
9222 : {
9223 119122131 : insn = NEXT_INSN (insn);
9224 119122131 : if (insn == 0
9225 119122131 : || !NOTE_P (insn)
9226 15651149 : || NOTE_KIND (insn) != NOTE_INSN_VAR_LOCATION)
9227 : break;
9228 : }
9229 :
9230 117531839 : return insn;
9231 : }
9232 :
9233 : /* Emit the notes for changes of location parts in the basic block BB. */
9234 :
9235 : static void
9236 7340889 : emit_notes_in_bb (basic_block bb, dataflow_set *set)
9237 : {
9238 7340889 : unsigned int i;
9239 7340889 : micro_operation *mo;
9240 :
9241 7340889 : dataflow_set_clear (set);
9242 7340889 : dataflow_set_copy (set, &VTI (bb)->in);
9243 :
9244 124872728 : FOR_EACH_VEC_ELT (VTI (bb)->mos, i, mo)
9245 : {
9246 117531839 : rtx_insn *insn = mo->insn;
9247 117531839 : rtx_insn *next_insn = next_non_note_insn_var_location (insn);
9248 :
9249 117531839 : switch (mo->type)
9250 : {
9251 3141975 : case MO_CALL:
9252 3141975 : dataflow_set_clear_at_call (set, insn);
9253 3141975 : emit_notes_for_changes (insn, EMIT_NOTE_AFTER_CALL_INSN, set->vars);
9254 3141975 : {
9255 3141975 : rtx arguments = mo->u.loc, *p = &arguments;
9256 6895185 : while (*p)
9257 : {
9258 3753210 : XEXP (XEXP (*p, 0), 1)
9259 3753210 : = vt_expand_loc (XEXP (XEXP (*p, 0), 1),
9260 : shared_hash_htab (set->vars));
9261 : /* If expansion is successful, keep it in the list. */
9262 3753210 : if (XEXP (XEXP (*p, 0), 1))
9263 : {
9264 3031657 : XEXP (XEXP (*p, 0), 1)
9265 3031657 : = copy_rtx_if_shared (XEXP (XEXP (*p, 0), 1));
9266 3031657 : p = &XEXP (*p, 1);
9267 : }
9268 : /* Otherwise, if the following item is data_value for it,
9269 : drop it too too. */
9270 721553 : else if (XEXP (*p, 1)
9271 384977 : && REG_P (XEXP (XEXP (*p, 0), 0))
9272 355920 : && MEM_P (XEXP (XEXP (XEXP (*p, 1), 0), 0))
9273 164 : && REG_P (XEXP (XEXP (XEXP (XEXP (*p, 1), 0), 0),
9274 : 0))
9275 721716 : && REGNO (XEXP (XEXP (*p, 0), 0))
9276 163 : == REGNO (XEXP (XEXP (XEXP (XEXP (*p, 1), 0),
9277 : 0), 0)))
9278 0 : *p = XEXP (XEXP (*p, 1), 1);
9279 : /* Just drop this item. */
9280 : else
9281 721553 : *p = XEXP (*p, 1);
9282 : }
9283 3141975 : add_reg_note (insn, REG_CALL_ARG_LOCATION, arguments);
9284 : }
9285 3141975 : break;
9286 :
9287 328429 : case MO_USE:
9288 328429 : {
9289 328429 : rtx loc = mo->u.loc;
9290 :
9291 328429 : if (REG_P (loc))
9292 325111 : var_reg_set (set, loc, VAR_INIT_STATUS_UNINITIALIZED, NULL);
9293 : else
9294 3318 : var_mem_set (set, loc, VAR_INIT_STATUS_UNINITIALIZED, NULL);
9295 :
9296 328429 : emit_notes_for_changes (insn, EMIT_NOTE_BEFORE_INSN, set->vars);
9297 : }
9298 328429 : break;
9299 :
9300 36605822 : case MO_VAL_LOC:
9301 36605822 : {
9302 36605822 : rtx loc = mo->u.loc;
9303 36605822 : rtx val, vloc;
9304 36605822 : tree var;
9305 :
9306 36605822 : if (GET_CODE (loc) == CONCAT)
9307 : {
9308 17221829 : val = XEXP (loc, 0);
9309 17221829 : vloc = XEXP (loc, 1);
9310 : }
9311 : else
9312 : {
9313 : val = NULL_RTX;
9314 : vloc = loc;
9315 : }
9316 :
9317 36605822 : var = PAT_VAR_LOCATION_DECL (vloc);
9318 :
9319 36605822 : clobber_variable_part (set, NULL_RTX,
9320 : dv_from_decl (var), 0, NULL_RTX);
9321 36605822 : if (val)
9322 : {
9323 17221829 : if (VAL_NEEDS_RESOLUTION (loc))
9324 1511940 : val_resolve (set, val, PAT_VAR_LOCATION_LOC (vloc), insn);
9325 17221829 : set_variable_part (set, val, dv_from_decl (var), 0,
9326 : VAR_INIT_STATUS_INITIALIZED, NULL_RTX,
9327 : INSERT);
9328 : }
9329 19383993 : else if (!VAR_LOC_UNKNOWN_P (PAT_VAR_LOCATION_LOC (vloc)))
9330 2508022 : set_variable_part (set, PAT_VAR_LOCATION_LOC (vloc),
9331 : dv_from_decl (var), 0,
9332 : VAR_INIT_STATUS_INITIALIZED, NULL_RTX,
9333 : INSERT);
9334 :
9335 36605822 : emit_notes_for_changes (insn, EMIT_NOTE_AFTER_INSN, set->vars);
9336 : }
9337 36605822 : break;
9338 :
9339 15694374 : case MO_VAL_USE:
9340 15694374 : {
9341 15694374 : rtx loc = mo->u.loc;
9342 15694374 : rtx val, vloc, uloc;
9343 :
9344 15694374 : vloc = uloc = XEXP (loc, 1);
9345 15694374 : val = XEXP (loc, 0);
9346 :
9347 15694374 : if (GET_CODE (val) == CONCAT)
9348 : {
9349 7749623 : uloc = XEXP (val, 1);
9350 7749623 : val = XEXP (val, 0);
9351 : }
9352 :
9353 15694374 : if (VAL_NEEDS_RESOLUTION (loc))
9354 15694374 : val_resolve (set, val, vloc, insn);
9355 : else
9356 0 : val_store (set, val, uloc, insn, false);
9357 :
9358 15694374 : if (VAL_HOLDS_TRACK_EXPR (loc))
9359 : {
9360 250869 : if (GET_CODE (uloc) == REG)
9361 224537 : var_reg_set (set, uloc, VAR_INIT_STATUS_UNINITIALIZED,
9362 : NULL);
9363 26332 : else if (GET_CODE (uloc) == MEM)
9364 26332 : var_mem_set (set, uloc, VAR_INIT_STATUS_UNINITIALIZED,
9365 : NULL);
9366 : }
9367 :
9368 15694374 : emit_notes_for_changes (insn, EMIT_NOTE_BEFORE_INSN, set->vars);
9369 : }
9370 15694374 : break;
9371 :
9372 31423649 : case MO_VAL_SET:
9373 31423649 : {
9374 31423649 : rtx loc = mo->u.loc;
9375 31423649 : rtx val, vloc, uloc;
9376 31423649 : rtx dstv, srcv;
9377 :
9378 31423649 : vloc = loc;
9379 31423649 : uloc = XEXP (vloc, 1);
9380 31423649 : val = XEXP (vloc, 0);
9381 31423649 : vloc = uloc;
9382 :
9383 31423649 : if (GET_CODE (uloc) == SET)
9384 : {
9385 22837052 : dstv = SET_DEST (uloc);
9386 22837052 : srcv = SET_SRC (uloc);
9387 : }
9388 : else
9389 : {
9390 : dstv = uloc;
9391 : srcv = NULL;
9392 : }
9393 :
9394 31423649 : if (GET_CODE (val) == CONCAT)
9395 : {
9396 8582748 : dstv = vloc = XEXP (val, 1);
9397 8582748 : val = XEXP (val, 0);
9398 : }
9399 :
9400 31423649 : if (GET_CODE (vloc) == SET)
9401 : {
9402 22832608 : srcv = SET_SRC (vloc);
9403 :
9404 22832608 : gcc_assert (val != srcv);
9405 22832608 : gcc_assert (vloc == uloc || VAL_NEEDS_RESOLUTION (loc));
9406 :
9407 22832608 : dstv = vloc = SET_DEST (vloc);
9408 :
9409 22832608 : if (VAL_NEEDS_RESOLUTION (loc))
9410 0 : val_resolve (set, val, srcv, insn);
9411 : }
9412 8591041 : else if (VAL_NEEDS_RESOLUTION (loc))
9413 : {
9414 0 : gcc_assert (GET_CODE (uloc) == SET
9415 : && GET_CODE (SET_SRC (uloc)) == REG);
9416 0 : val_resolve (set, val, SET_SRC (uloc), insn);
9417 : }
9418 :
9419 31423649 : if (VAL_HOLDS_TRACK_EXPR (loc))
9420 : {
9421 104449 : if (VAL_EXPR_IS_CLOBBERED (loc))
9422 : {
9423 0 : if (REG_P (uloc))
9424 0 : var_reg_delete (set, uloc, true);
9425 0 : else if (MEM_P (uloc))
9426 : {
9427 0 : gcc_assert (MEM_P (dstv));
9428 0 : gcc_assert (MEM_ATTRS (dstv) == MEM_ATTRS (uloc));
9429 0 : var_mem_delete (set, dstv, true);
9430 : }
9431 : }
9432 : else
9433 : {
9434 104449 : bool copied_p = VAL_EXPR_IS_COPIED (loc);
9435 104449 : rtx src = NULL, dst = uloc;
9436 104449 : enum var_init_status status = VAR_INIT_STATUS_INITIALIZED;
9437 :
9438 104449 : if (GET_CODE (uloc) == SET)
9439 : {
9440 99691 : src = SET_SRC (uloc);
9441 99691 : dst = SET_DEST (uloc);
9442 : }
9443 :
9444 104449 : if (copied_p)
9445 : {
9446 19834 : status = find_src_status (set, src);
9447 :
9448 19834 : src = find_src_set_src (set, src);
9449 : }
9450 :
9451 104449 : if (REG_P (dst))
9452 99999 : var_reg_delete_and_set (set, dst, !copied_p,
9453 : status, srcv);
9454 4450 : else if (MEM_P (dst))
9455 : {
9456 4450 : gcc_assert (MEM_P (dstv));
9457 4450 : gcc_assert (MEM_ATTRS (dstv) == MEM_ATTRS (dst));
9458 4450 : var_mem_delete_and_set (set, dstv, !copied_p,
9459 : status, srcv);
9460 : }
9461 : }
9462 : }
9463 31319200 : else if (REG_P (uloc))
9464 3707 : var_regno_delete (set, REGNO (uloc));
9465 31315493 : else if (MEM_P (uloc))
9466 : {
9467 8578132 : gcc_checking_assert (GET_CODE (vloc) == MEM);
9468 8578132 : gcc_checking_assert (vloc == dstv);
9469 : if (vloc != dstv)
9470 : clobber_overlapping_mems (set, vloc);
9471 : }
9472 :
9473 31423649 : val_store (set, val, dstv, insn, true);
9474 :
9475 31423649 : emit_notes_for_changes (next_insn, EMIT_NOTE_BEFORE_INSN,
9476 : set->vars);
9477 : }
9478 31423649 : break;
9479 :
9480 34394 : case MO_SET:
9481 34394 : {
9482 34394 : rtx loc = mo->u.loc;
9483 34394 : rtx set_src = NULL;
9484 :
9485 34394 : if (GET_CODE (loc) == SET)
9486 : {
9487 34141 : set_src = SET_SRC (loc);
9488 34141 : loc = SET_DEST (loc);
9489 : }
9490 :
9491 34394 : if (REG_P (loc))
9492 34394 : var_reg_delete_and_set (set, loc, true, VAR_INIT_STATUS_INITIALIZED,
9493 : set_src);
9494 : else
9495 0 : var_mem_delete_and_set (set, loc, true, VAR_INIT_STATUS_INITIALIZED,
9496 : set_src);
9497 :
9498 34394 : emit_notes_for_changes (next_insn, EMIT_NOTE_BEFORE_INSN,
9499 : set->vars);
9500 : }
9501 34394 : break;
9502 :
9503 43088 : case MO_COPY:
9504 43088 : {
9505 43088 : rtx loc = mo->u.loc;
9506 43088 : enum var_init_status src_status;
9507 43088 : rtx set_src = NULL;
9508 :
9509 43088 : if (GET_CODE (loc) == SET)
9510 : {
9511 43088 : set_src = SET_SRC (loc);
9512 43088 : loc = SET_DEST (loc);
9513 : }
9514 :
9515 43088 : src_status = find_src_status (set, set_src);
9516 43088 : set_src = find_src_set_src (set, set_src);
9517 :
9518 43088 : if (REG_P (loc))
9519 43088 : var_reg_delete_and_set (set, loc, false, src_status, set_src);
9520 : else
9521 0 : var_mem_delete_and_set (set, loc, false, src_status, set_src);
9522 :
9523 43088 : emit_notes_for_changes (next_insn, EMIT_NOTE_BEFORE_INSN,
9524 : set->vars);
9525 : }
9526 43088 : break;
9527 :
9528 20035966 : case MO_USE_NO_VAR:
9529 20035966 : {
9530 20035966 : rtx loc = mo->u.loc;
9531 :
9532 20035966 : if (REG_P (loc))
9533 20035966 : var_reg_delete (set, loc, false);
9534 : else
9535 0 : var_mem_delete (set, loc, false);
9536 :
9537 20035966 : emit_notes_for_changes (insn, EMIT_NOTE_AFTER_INSN, set->vars);
9538 : }
9539 20035966 : break;
9540 :
9541 5968795 : case MO_CLOBBER:
9542 5968795 : {
9543 5968795 : rtx loc = mo->u.loc;
9544 :
9545 5968795 : if (REG_P (loc))
9546 5968792 : var_reg_delete (set, loc, true);
9547 : else
9548 3 : var_mem_delete (set, loc, true);
9549 :
9550 5968795 : emit_notes_for_changes (next_insn, EMIT_NOTE_BEFORE_INSN,
9551 : set->vars);
9552 : }
9553 5968795 : break;
9554 :
9555 4255347 : case MO_ADJUST:
9556 4255347 : set->stack_adjust += mo->u.adjust;
9557 4255347 : break;
9558 : }
9559 : }
9560 7340889 : }
9561 :
9562 : /* Emit notes for the whole function. */
9563 :
9564 : static void
9565 496102 : vt_emit_notes (void)
9566 : {
9567 496102 : basic_block bb;
9568 496102 : dataflow_set cur;
9569 :
9570 496102 : gcc_assert (changed_variables->is_empty ());
9571 :
9572 : /* Free memory occupied by the out hash tables, as they aren't used
9573 : anymore. */
9574 7836991 : FOR_EACH_BB_FN (bb, cfun)
9575 7340889 : dataflow_set_clear (&VTI (bb)->out);
9576 :
9577 : /* Enable emitting notes by functions (mainly by set_variable_part and
9578 : delete_variable_part). */
9579 496102 : emit_notes = true;
9580 :
9581 496102 : if (MAY_HAVE_DEBUG_BIND_INSNS)
9582 496061 : dropped_values = new variable_table_type (cselib_get_next_uid () * 2);
9583 :
9584 496102 : dataflow_set_init (&cur);
9585 :
9586 7836991 : FOR_EACH_BB_FN (bb, cfun)
9587 : {
9588 : /* Emit the notes for changes of variable locations between two
9589 : subsequent basic blocks. */
9590 7340889 : emit_notes_for_differences (BB_HEAD (bb), &cur, &VTI (bb)->in);
9591 :
9592 7340889 : if (MAY_HAVE_DEBUG_BIND_INSNS)
9593 7340798 : local_get_addr_cache = new hash_map<rtx, rtx>;
9594 :
9595 : /* Emit the notes for the changes in the basic block itself. */
9596 7340889 : emit_notes_in_bb (bb, &cur);
9597 :
9598 7340889 : if (MAY_HAVE_DEBUG_BIND_INSNS)
9599 14681596 : delete local_get_addr_cache;
9600 7340889 : local_get_addr_cache = NULL;
9601 :
9602 : /* Free memory occupied by the in hash table, we won't need it
9603 : again. */
9604 7340889 : dataflow_set_clear (&VTI (bb)->in);
9605 : }
9606 :
9607 496102 : if (flag_checking)
9608 496101 : shared_hash_htab (cur.vars)
9609 : ->traverse <variable_table_type *, emit_notes_for_differences_1>
9610 496101 : (shared_hash_htab (empty_shared_hash));
9611 :
9612 496102 : dataflow_set_destroy (&cur);
9613 :
9614 496102 : if (MAY_HAVE_DEBUG_BIND_INSNS)
9615 496061 : delete dropped_values;
9616 496102 : dropped_values = NULL;
9617 :
9618 496102 : emit_notes = false;
9619 496102 : }
9620 :
9621 : /* If there is a declaration and offset associated with register/memory RTL
9622 : assign declaration to *DECLP and offset to *OFFSETP, and return true. */
9623 :
9624 : static bool
9625 962021 : vt_get_decl_and_offset (rtx rtl, tree *declp, poly_int64 *offsetp)
9626 : {
9627 962021 : if (REG_P (rtl))
9628 : {
9629 595207 : if (REG_ATTRS (rtl))
9630 : {
9631 595207 : *declp = REG_EXPR (rtl);
9632 595207 : *offsetp = REG_OFFSET (rtl);
9633 595207 : return true;
9634 : }
9635 : }
9636 366814 : else if (GET_CODE (rtl) == PARALLEL)
9637 : {
9638 23800 : tree decl = NULL_TREE;
9639 23800 : HOST_WIDE_INT offset = MAX_VAR_PARTS;
9640 23800 : int len = XVECLEN (rtl, 0), i;
9641 :
9642 71149 : for (i = 0; i < len; i++)
9643 : {
9644 47349 : rtx reg = XEXP (XVECEXP (rtl, 0, i), 0);
9645 47349 : if (!REG_P (reg) || !REG_ATTRS (reg))
9646 : break;
9647 47349 : if (!decl)
9648 23800 : decl = REG_EXPR (reg);
9649 47349 : if (REG_EXPR (reg) != decl)
9650 : break;
9651 47349 : HOST_WIDE_INT this_offset;
9652 47349 : if (!track_offset_p (REG_OFFSET (reg), &this_offset))
9653 : break;
9654 47349 : offset = MIN (offset, this_offset);
9655 : }
9656 :
9657 23800 : if (i == len)
9658 : {
9659 23800 : *declp = decl;
9660 23800 : *offsetp = offset;
9661 23800 : return true;
9662 : }
9663 : }
9664 343014 : else if (MEM_P (rtl))
9665 : {
9666 342964 : if (MEM_ATTRS (rtl))
9667 : {
9668 342935 : *declp = MEM_EXPR (rtl);
9669 342935 : *offsetp = int_mem_offset (rtl);
9670 342935 : return true;
9671 : }
9672 : }
9673 : return false;
9674 : }
9675 :
9676 : /* Record the value for the ENTRY_VALUE of RTL as a global equivalence
9677 : of VAL. */
9678 :
9679 : static void
9680 672837 : record_entry_value (cselib_val *val, rtx rtl)
9681 : {
9682 672837 : rtx ev = gen_rtx_ENTRY_VALUE (GET_MODE (rtl));
9683 :
9684 672837 : ENTRY_VALUE_EXP (ev) = rtl;
9685 :
9686 672837 : cselib_add_permanent_equiv (val, ev, get_insns ());
9687 672837 : }
9688 :
9689 : /* Insert function parameter PARM in IN and OUT sets of ENTRY_BLOCK. */
9690 :
9691 : static void
9692 989745 : vt_add_function_parameter (tree parm)
9693 : {
9694 989745 : rtx decl_rtl = DECL_RTL_IF_SET (parm);
9695 989745 : rtx incoming = DECL_INCOMING_RTL (parm);
9696 989745 : tree decl;
9697 989745 : machine_mode mode;
9698 989745 : poly_int64 offset;
9699 989745 : dataflow_set *out;
9700 989745 : decl_or_value dv;
9701 989745 : bool incoming_ok = true;
9702 :
9703 989745 : if (TREE_CODE (parm) != PARM_DECL)
9704 44250 : return;
9705 :
9706 989745 : if (!decl_rtl || !incoming)
9707 : return;
9708 :
9709 989745 : if (GET_MODE (decl_rtl) == BLKmode || GET_MODE (incoming) == BLKmode)
9710 : return;
9711 :
9712 : /* If there is a DRAP register or a pseudo in internal_arg_pointer,
9713 : rewrite the incoming location of parameters passed on the stack
9714 : into MEMs based on the argument pointer, so that incoming doesn't
9715 : depend on a pseudo. */
9716 961971 : poly_int64 incoming_offset = 0;
9717 961971 : if (MEM_P (incoming)
9718 961971 : && (strip_offset (XEXP (incoming, 0), &incoming_offset)
9719 342964 : == crtl->args.internal_arg_pointer))
9720 : {
9721 364 : HOST_WIDE_INT off = -FIRST_PARM_OFFSET (current_function_decl);
9722 364 : incoming
9723 364 : = replace_equiv_address_nv (incoming,
9724 364 : plus_constant (Pmode,
9725 : arg_pointer_rtx,
9726 : off + incoming_offset));
9727 : }
9728 :
9729 : #ifdef HAVE_window_save
9730 : /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
9731 : If the target machine has an explicit window save instruction, the
9732 : actual entry value is the corresponding OUTGOING_REGNO instead. */
9733 : if (HAVE_window_save && !crtl->uses_only_leaf_regs)
9734 : {
9735 : if (REG_P (incoming)
9736 : && HARD_REGISTER_P (incoming)
9737 : && OUTGOING_REGNO (REGNO (incoming)) != REGNO (incoming))
9738 : {
9739 : parm_reg p;
9740 : p.incoming = incoming;
9741 : incoming
9742 : = gen_rtx_REG_offset (incoming, GET_MODE (incoming),
9743 : OUTGOING_REGNO (REGNO (incoming)), 0);
9744 : p.outgoing = incoming;
9745 : vec_safe_push (windowed_parm_regs, p);
9746 : }
9747 : else if (GET_CODE (incoming) == PARALLEL)
9748 : {
9749 : rtx outgoing
9750 : = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (XVECLEN (incoming, 0)));
9751 : int i;
9752 :
9753 : for (i = 0; i < XVECLEN (incoming, 0); i++)
9754 : {
9755 : rtx reg = XEXP (XVECEXP (incoming, 0, i), 0);
9756 : parm_reg p;
9757 : p.incoming = reg;
9758 : reg = gen_rtx_REG_offset (reg, GET_MODE (reg),
9759 : OUTGOING_REGNO (REGNO (reg)), 0);
9760 : p.outgoing = reg;
9761 : XVECEXP (outgoing, 0, i)
9762 : = gen_rtx_EXPR_LIST (VOIDmode, reg,
9763 : XEXP (XVECEXP (incoming, 0, i), 1));
9764 : vec_safe_push (windowed_parm_regs, p);
9765 : }
9766 :
9767 : incoming = outgoing;
9768 : }
9769 : else if (MEM_P (incoming)
9770 : && REG_P (XEXP (incoming, 0))
9771 : && HARD_REGISTER_P (XEXP (incoming, 0)))
9772 : {
9773 : rtx reg = XEXP (incoming, 0);
9774 : if (OUTGOING_REGNO (REGNO (reg)) != REGNO (reg))
9775 : {
9776 : parm_reg p;
9777 : p.incoming = reg;
9778 : reg = gen_raw_REG (GET_MODE (reg), OUTGOING_REGNO (REGNO (reg)));
9779 : p.outgoing = reg;
9780 : vec_safe_push (windowed_parm_regs, p);
9781 : incoming = replace_equiv_address_nv (incoming, reg);
9782 : }
9783 : }
9784 : }
9785 : #endif
9786 :
9787 961971 : if (!vt_get_decl_and_offset (incoming, &decl, &offset))
9788 : {
9789 79 : incoming_ok = false;
9790 79 : if (MEM_P (incoming))
9791 : {
9792 : /* This means argument is passed by invisible reference. */
9793 29 : offset = 0;
9794 29 : decl = parm;
9795 : }
9796 : else
9797 : {
9798 50 : if (!vt_get_decl_and_offset (decl_rtl, &decl, &offset))
9799 : return;
9800 50 : offset += byte_lowpart_offset (GET_MODE (incoming),
9801 50 : GET_MODE (decl_rtl));
9802 : }
9803 : }
9804 :
9805 961971 : if (!decl)
9806 : return;
9807 :
9808 961971 : if (parm != decl)
9809 : {
9810 : /* If that DECL_RTL wasn't a pseudo that got spilled to
9811 : memory, bail out. Otherwise, the spill slot sharing code
9812 : will force the memory to reference spill_slot_decl (%sfp),
9813 : so we don't match above. That's ok, the pseudo must have
9814 : referenced the entire parameter, so just reset OFFSET. */
9815 0 : if (decl != get_spill_slot_decl (false))
9816 : return;
9817 0 : offset = 0;
9818 : }
9819 :
9820 961971 : HOST_WIDE_INT const_offset;
9821 961971 : if (!track_loc_p (incoming, parm, offset, false, &mode, &const_offset))
9822 : return;
9823 :
9824 945495 : out = &VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->out;
9825 :
9826 945495 : dv = dv_from_decl (parm);
9827 :
9828 945495 : if (target_for_debug_bind (parm)
9829 : /* We can't deal with these right now, because this kind of
9830 : variable is single-part. ??? We could handle parallels
9831 : that describe multiple locations for the same single
9832 : value, but ATM we don't. */
9833 945495 : && GET_CODE (incoming) != PARALLEL)
9834 : {
9835 881448 : cselib_val *val;
9836 881448 : rtx lowpart;
9837 :
9838 : /* ??? We shouldn't ever hit this, but it may happen because
9839 : arguments passed by invisible reference aren't dealt with
9840 : above: incoming-rtl will have Pmode rather than the
9841 : expected mode for the type. */
9842 881448 : if (const_offset)
9843 : return;
9844 :
9845 881448 : lowpart = var_lowpart (mode, incoming);
9846 881448 : if (!lowpart)
9847 : return;
9848 :
9849 881448 : val = cselib_lookup_from_insn (lowpart, mode, true,
9850 : VOIDmode, get_insns ());
9851 :
9852 : /* ??? Float-typed values in memory are not handled by
9853 : cselib. */
9854 881448 : if (val)
9855 : {
9856 881448 : preserve_value (val);
9857 881448 : set_variable_part (out, val->val_rtx, dv, const_offset,
9858 : VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
9859 881448 : dv = dv_from_value (val->val_rtx);
9860 : }
9861 :
9862 881448 : if (MEM_P (incoming))
9863 : {
9864 318506 : val = cselib_lookup_from_insn (XEXP (incoming, 0), mode, true,
9865 : VOIDmode, get_insns ());
9866 318506 : if (val)
9867 : {
9868 318506 : preserve_value (val);
9869 318506 : incoming = replace_equiv_address_nv (incoming, val->val_rtx);
9870 : }
9871 : }
9872 : }
9873 :
9874 945495 : if (REG_P (incoming))
9875 : {
9876 582015 : incoming = var_lowpart (mode, incoming);
9877 582015 : gcc_assert (REGNO (incoming) < FIRST_PSEUDO_REGISTER);
9878 582015 : attrs_list_insert (&out->regs[REGNO (incoming)], dv, const_offset,
9879 : incoming);
9880 582015 : set_variable_part (out, incoming, dv, const_offset,
9881 : VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
9882 582015 : if (dv_is_value_p (dv))
9883 : {
9884 562892 : record_entry_value (CSELIB_VAL_PTR (dv_as_value (dv)), incoming);
9885 562892 : if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
9886 562892 : && INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (parm))))
9887 : {
9888 8599 : machine_mode indmode
9889 8599 : = TYPE_MODE (TREE_TYPE (TREE_TYPE (parm)));
9890 8599 : rtx mem = gen_rtx_MEM (indmode, incoming);
9891 8599 : cselib_val *val = cselib_lookup_from_insn (mem, indmode, true,
9892 : VOIDmode,
9893 : get_insns ());
9894 8599 : if (val)
9895 : {
9896 8599 : preserve_value (val);
9897 8599 : record_entry_value (val, mem);
9898 8599 : set_variable_part (out, mem, dv_from_value (val->val_rtx), 0,
9899 : VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
9900 : }
9901 : }
9902 :
9903 562892 : if (GET_MODE_CLASS (mode) == MODE_INT)
9904 : {
9905 553158 : machine_mode wider_mode_iter;
9906 654504 : FOR_EACH_WIDER_MODE (wider_mode_iter, mode)
9907 : {
9908 1599999 : if (!HWI_COMPUTABLE_MODE_P (wider_mode_iter))
9909 : break;
9910 101346 : rtx wider_reg
9911 101346 : = gen_rtx_REG (wider_mode_iter, REGNO (incoming));
9912 101346 : cselib_val *wider_val
9913 101346 : = cselib_lookup_from_insn (wider_reg, wider_mode_iter, 1,
9914 : VOIDmode, get_insns ());
9915 101346 : preserve_value (wider_val);
9916 101346 : record_entry_value (wider_val, wider_reg);
9917 : }
9918 : }
9919 : }
9920 : }
9921 363480 : else if (GET_CODE (incoming) == PARALLEL && !dv_onepart_p (dv))
9922 : {
9923 22350 : int i;
9924 :
9925 : /* The following code relies on vt_get_decl_and_offset returning true for
9926 : incoming, which might not be always the case. */
9927 22350 : if (!incoming_ok)
9928 : return;
9929 67047 : for (i = 0; i < XVECLEN (incoming, 0); i++)
9930 : {
9931 44697 : rtx reg = XEXP (XVECEXP (incoming, 0, i), 0);
9932 : /* vt_get_decl_and_offset has already checked that the offset
9933 : is a valid variable part. */
9934 44697 : const_offset = get_tracked_reg_offset (reg);
9935 44697 : gcc_assert (REGNO (reg) < FIRST_PSEUDO_REGISTER);
9936 44697 : attrs_list_insert (&out->regs[REGNO (reg)], dv, const_offset, reg);
9937 44697 : set_variable_part (out, reg, dv, const_offset,
9938 : VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
9939 : }
9940 : }
9941 341130 : else if (MEM_P (incoming))
9942 : {
9943 339926 : incoming = var_lowpart (mode, incoming);
9944 339926 : set_variable_part (out, incoming, dv, const_offset,
9945 : VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
9946 : }
9947 : }
9948 :
9949 : /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK. */
9950 :
9951 : static void
9952 496103 : vt_add_function_parameters (void)
9953 : {
9954 496103 : tree parm;
9955 :
9956 496103 : for (parm = DECL_ARGUMENTS (current_function_decl);
9957 1438642 : parm; parm = DECL_CHAIN (parm))
9958 942539 : vt_add_function_parameter (parm);
9959 :
9960 496103 : if (DECL_HAS_VALUE_EXPR_P (DECL_RESULT (current_function_decl)))
9961 : {
9962 47206 : tree vexpr = DECL_VALUE_EXPR (DECL_RESULT (current_function_decl));
9963 :
9964 47206 : if (INDIRECT_REF_P (vexpr))
9965 41329 : vexpr = TREE_OPERAND (vexpr, 0);
9966 :
9967 47206 : if (TREE_CODE (vexpr) == PARM_DECL
9968 47206 : && DECL_ARTIFICIAL (vexpr)
9969 47206 : && !DECL_IGNORED_P (vexpr)
9970 94412 : && DECL_NAMELESS (vexpr))
9971 47206 : vt_add_function_parameter (vexpr);
9972 : }
9973 496103 : }
9974 :
9975 : /* Initialize cfa_base_rtx, create a preserved VALUE for it and
9976 : ensure it isn't flushed during cselib_reset_table.
9977 : Can be called only if frame_pointer_rtx resp. arg_pointer_rtx
9978 : has been eliminated. */
9979 :
9980 : static void
9981 495072 : vt_init_cfa_base (void)
9982 : {
9983 495072 : cselib_val *val;
9984 :
9985 : #ifdef FRAME_POINTER_CFA_OFFSET
9986 : cfa_base_rtx = frame_pointer_rtx;
9987 : cfa_base_offset = -FRAME_POINTER_CFA_OFFSET (current_function_decl);
9988 : #else
9989 495072 : cfa_base_rtx = arg_pointer_rtx;
9990 495072 : cfa_base_offset = -ARG_POINTER_CFA_OFFSET (current_function_decl);
9991 : #endif
9992 495072 : if (cfa_base_rtx == hard_frame_pointer_rtx
9993 495072 : || !fixed_regs[REGNO (cfa_base_rtx)])
9994 : {
9995 0 : cfa_base_rtx = NULL_RTX;
9996 0 : return;
9997 : }
9998 495072 : if (!MAY_HAVE_DEBUG_BIND_INSNS)
9999 : return;
10000 :
10001 : /* Tell alias analysis that cfa_base_rtx should share
10002 : find_base_term value with stack pointer or hard frame pointer. */
10003 495031 : if (!frame_pointer_needed)
10004 472262 : vt_equate_reg_base_value (cfa_base_rtx, stack_pointer_rtx);
10005 22769 : else if (!crtl->stack_realign_tried)
10006 22176 : vt_equate_reg_base_value (cfa_base_rtx, hard_frame_pointer_rtx);
10007 :
10008 495031 : val = cselib_lookup_from_insn (cfa_base_rtx, GET_MODE (cfa_base_rtx), 1,
10009 : VOIDmode, get_insns ());
10010 495031 : preserve_value (val);
10011 495031 : cselib_preserve_cfa_base_value (val, REGNO (cfa_base_rtx));
10012 : }
10013 :
10014 : /* Reemit INSN, a MARKER_DEBUG_INSN, as a note. */
10015 :
10016 : static rtx_insn *
10017 11008432 : reemit_marker_as_note (rtx_insn *insn)
10018 : {
10019 11008432 : gcc_checking_assert (DEBUG_MARKER_INSN_P (insn));
10020 :
10021 11008432 : enum insn_note kind = INSN_DEBUG_MARKER_KIND (insn);
10022 :
10023 : switch (kind)
10024 : {
10025 11008432 : case NOTE_INSN_BEGIN_STMT:
10026 11008432 : case NOTE_INSN_INLINE_ENTRY:
10027 11008432 : {
10028 11008432 : rtx_insn *note = NULL;
10029 11008432 : if (cfun->debug_nonbind_markers)
10030 : {
10031 10764850 : note = emit_note_before (kind, insn);
10032 10764850 : NOTE_MARKER_LOCATION (note) = INSN_LOCATION (insn);
10033 : }
10034 11008432 : delete_insn (insn);
10035 11008432 : return note;
10036 : }
10037 :
10038 0 : default:
10039 0 : gcc_unreachable ();
10040 : }
10041 : }
10042 :
10043 : /* Allocate and initialize the data structures for variable tracking
10044 : and parse the RTL to get the micro operations. */
10045 :
10046 : static bool
10047 496170 : vt_initialize (void)
10048 : {
10049 496170 : basic_block bb;
10050 496170 : poly_int64 fp_cfa_offset = -1;
10051 :
10052 496170 : alloc_aux_for_blocks (sizeof (variable_tracking_info));
10053 :
10054 496170 : empty_shared_hash = shared_hash_pool.allocate ();
10055 496170 : empty_shared_hash->refcount = 1;
10056 496170 : empty_shared_hash->htab = new variable_table_type (1);
10057 496170 : changed_variables = new variable_table_type (10);
10058 :
10059 : /* Init the IN and OUT sets. */
10060 8830394 : FOR_ALL_BB_FN (bb, cfun)
10061 : {
10062 8334224 : VTI (bb)->visited = false;
10063 8334224 : VTI (bb)->flooded = false;
10064 8334224 : dataflow_set_init (&VTI (bb)->in);
10065 8334224 : dataflow_set_init (&VTI (bb)->out);
10066 8334224 : VTI (bb)->permp = NULL;
10067 : }
10068 :
10069 496170 : if (MAY_HAVE_DEBUG_BIND_INSNS)
10070 : {
10071 496129 : cselib_init (CSELIB_RECORD_MEMORY | CSELIB_PRESERVE_CONSTANTS);
10072 496129 : scratch_regs = BITMAP_ALLOC (NULL);
10073 496129 : preserved_values.create (256);
10074 496129 : global_get_addr_cache = new hash_map<rtx, rtx>;
10075 : }
10076 : else
10077 : {
10078 41 : scratch_regs = NULL;
10079 41 : global_get_addr_cache = NULL;
10080 : }
10081 :
10082 496170 : if (MAY_HAVE_DEBUG_BIND_INSNS)
10083 : {
10084 496129 : rtx reg, expr;
10085 496129 : int ofst;
10086 496129 : cselib_val *val;
10087 :
10088 : #ifdef FRAME_POINTER_CFA_OFFSET
10089 : reg = frame_pointer_rtx;
10090 : ofst = FRAME_POINTER_CFA_OFFSET (current_function_decl);
10091 : #else
10092 496129 : reg = arg_pointer_rtx;
10093 496129 : ofst = ARG_POINTER_CFA_OFFSET (current_function_decl);
10094 : #endif
10095 :
10096 496129 : ofst -= INCOMING_FRAME_SP_OFFSET;
10097 :
10098 496129 : val = cselib_lookup_from_insn (reg, GET_MODE (reg), 1,
10099 : VOIDmode, get_insns ());
10100 496129 : preserve_value (val);
10101 496129 : if (reg != hard_frame_pointer_rtx && fixed_regs[REGNO (reg)])
10102 496129 : cselib_preserve_cfa_base_value (val, REGNO (reg));
10103 496129 : if (ofst)
10104 : {
10105 496129 : cselib_val *valsp
10106 992258 : = cselib_lookup_from_insn (stack_pointer_rtx,
10107 496129 : GET_MODE (stack_pointer_rtx), 1,
10108 : VOIDmode, get_insns ());
10109 496129 : preserve_value (valsp);
10110 496129 : expr = plus_constant (GET_MODE (reg), reg, ofst);
10111 : /* This cselib_add_permanent_equiv call needs to be done before
10112 : the other cselib_add_permanent_equiv a few lines later,
10113 : because after that one is done, cselib_lookup on this expr
10114 : will due to the cselib SP_DERIVED_VALUE_P optimizations
10115 : return valsp and so no permanent equivalency will be added. */
10116 496129 : cselib_add_permanent_equiv (valsp, expr, get_insns ());
10117 : }
10118 :
10119 992258 : expr = plus_constant (GET_MODE (stack_pointer_rtx),
10120 496129 : stack_pointer_rtx, -ofst);
10121 496129 : cselib_add_permanent_equiv (val, expr, get_insns ());
10122 : }
10123 :
10124 : /* In order to factor out the adjustments made to the stack pointer or to
10125 : the hard frame pointer and thus be able to use DW_OP_fbreg operations
10126 : instead of individual location lists, we're going to rewrite MEMs based
10127 : on them into MEMs based on the CFA by de-eliminating stack_pointer_rtx
10128 : or hard_frame_pointer_rtx to the virtual CFA pointer frame_pointer_rtx
10129 : resp. arg_pointer_rtx. We can do this either when there is no frame
10130 : pointer in the function and stack adjustments are consistent for all
10131 : basic blocks or when there is a frame pointer and no stack realignment.
10132 : But we first have to check that frame_pointer_rtx resp. arg_pointer_rtx
10133 : has been eliminated. */
10134 496170 : if (!frame_pointer_needed)
10135 : {
10136 472503 : rtx reg, elim;
10137 :
10138 472503 : if (!vt_stack_adjustments ())
10139 : return false;
10140 :
10141 : #ifdef FRAME_POINTER_CFA_OFFSET
10142 : reg = frame_pointer_rtx;
10143 : #else
10144 472436 : reg = arg_pointer_rtx;
10145 : #endif
10146 472436 : elim = (ira_use_lra_p
10147 472436 : ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
10148 0 : : eliminate_regs (reg, VOIDmode, NULL_RTX));
10149 472436 : if (elim != reg)
10150 : {
10151 472436 : if (GET_CODE (elim) == PLUS)
10152 472436 : elim = XEXP (elim, 0);
10153 472436 : if (elim == stack_pointer_rtx)
10154 472303 : vt_init_cfa_base ();
10155 : }
10156 : }
10157 23667 : else if (!crtl->stack_realign_tried)
10158 : {
10159 22176 : rtx reg, elim;
10160 :
10161 : #ifdef FRAME_POINTER_CFA_OFFSET
10162 : reg = frame_pointer_rtx;
10163 : fp_cfa_offset = FRAME_POINTER_CFA_OFFSET (current_function_decl);
10164 : #else
10165 22176 : reg = arg_pointer_rtx;
10166 22176 : fp_cfa_offset = ARG_POINTER_CFA_OFFSET (current_function_decl);
10167 : #endif
10168 22176 : elim = (ira_use_lra_p
10169 22176 : ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
10170 0 : : eliminate_regs (reg, VOIDmode, NULL_RTX));
10171 22176 : if (elim != reg)
10172 : {
10173 22176 : if (GET_CODE (elim) == PLUS)
10174 : {
10175 22176 : fp_cfa_offset -= rtx_to_poly_int64 (XEXP (elim, 1));
10176 22176 : elim = XEXP (elim, 0);
10177 : }
10178 22176 : if (elim != hard_frame_pointer_rtx)
10179 : fp_cfa_offset = -1;
10180 : }
10181 : else
10182 : fp_cfa_offset = -1;
10183 : }
10184 :
10185 : /* If the stack is realigned and a DRAP register is used, we're going to
10186 : rewrite MEMs based on it representing incoming locations of parameters
10187 : passed on the stack into MEMs based on the argument pointer. Although
10188 : we aren't going to rewrite other MEMs, we still need to initialize the
10189 : virtual CFA pointer in order to ensure that the argument pointer will
10190 : be seen as a constant throughout the function.
10191 :
10192 : ??? This doesn't work if FRAME_POINTER_CFA_OFFSET is defined. */
10193 1491 : else if (stack_realign_drap)
10194 : {
10195 593 : rtx reg, elim;
10196 :
10197 : #ifdef FRAME_POINTER_CFA_OFFSET
10198 : reg = frame_pointer_rtx;
10199 : #else
10200 593 : reg = arg_pointer_rtx;
10201 : #endif
10202 593 : elim = (ira_use_lra_p
10203 593 : ? lra_eliminate_regs (reg, VOIDmode, NULL_RTX)
10204 0 : : eliminate_regs (reg, VOIDmode, NULL_RTX));
10205 593 : if (elim != reg)
10206 : {
10207 593 : if (GET_CODE (elim) == PLUS)
10208 593 : elim = XEXP (elim, 0);
10209 593 : if (elim == hard_frame_pointer_rtx)
10210 593 : vt_init_cfa_base ();
10211 : }
10212 : }
10213 :
10214 496103 : hard_frame_pointer_adjustment = -1;
10215 :
10216 496103 : vt_add_function_parameters ();
10217 :
10218 496103 : bool record_sp_value = false;
10219 4887961 : FOR_EACH_BB_FN (bb, cfun)
10220 : {
10221 4391858 : rtx_insn *insn;
10222 4391858 : basic_block first_bb, last_bb;
10223 :
10224 4391858 : if (MAY_HAVE_DEBUG_BIND_INSNS)
10225 : {
10226 4391782 : cselib_record_sets_hook = add_with_sets;
10227 4391782 : if (dump_file && (dump_flags & TDF_DETAILS))
10228 1 : fprintf (dump_file, "first value: %i\n",
10229 : cselib_get_next_uid ());
10230 : }
10231 :
10232 4391858 : if (MAY_HAVE_DEBUG_BIND_INSNS
10233 4391782 : && cfa_base_rtx
10234 4349047 : && !frame_pointer_needed
10235 3939348 : && record_sp_value)
10236 3467086 : cselib_record_sp_cfa_base_equiv (-cfa_base_offset
10237 3467086 : - VTI (bb)->in.stack_adjust,
10238 : BB_HEAD (bb));
10239 7340890 : record_sp_value = true;
10240 :
10241 : first_bb = bb;
10242 10289922 : for (;;)
10243 : {
10244 7340890 : edge e;
10245 7340890 : if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
10246 7340890 : || ! single_pred_p (bb->next_bb))
10247 : break;
10248 4714364 : e = find_edge (bb, bb->next_bb);
10249 4714364 : if (! e || (e->flags & EDGE_FALLTHRU) == 0)
10250 : break;
10251 2949032 : bb = bb->next_bb;
10252 2949032 : }
10253 4391858 : last_bb = bb;
10254 :
10255 : /* Add the micro-operations to the vector. */
10256 11732748 : FOR_BB_BETWEEN (bb, first_bb, last_bb->next_bb, next_bb)
10257 : {
10258 7340890 : HOST_WIDE_INT offset = VTI (bb)->out.stack_adjust;
10259 7340890 : VTI (bb)->out.stack_adjust = VTI (bb)->in.stack_adjust;
10260 :
10261 7340890 : rtx_insn *next;
10262 226879070 : FOR_BB_INSNS_SAFE (bb, insn, next)
10263 : {
10264 106098645 : if (INSN_P (insn))
10265 : {
10266 89875653 : HOST_WIDE_INT pre = 0, post = 0;
10267 :
10268 89875653 : if (!frame_pointer_needed)
10269 : {
10270 80752131 : insn_stack_adjust_offset_pre_post (insn, &pre, &post);
10271 80752131 : if (pre)
10272 : {
10273 1926209 : micro_operation mo;
10274 1926209 : mo.type = MO_ADJUST;
10275 1926209 : mo.u.adjust = pre;
10276 1926209 : mo.insn = insn;
10277 1926209 : if (dump_file && (dump_flags & TDF_DETAILS))
10278 1 : log_op_type (PATTERN (insn), bb, insn,
10279 : MO_ADJUST, dump_file);
10280 1926209 : VTI (bb)->mos.safe_push (mo);
10281 : }
10282 : }
10283 :
10284 89875653 : cselib_hook_called = false;
10285 89875653 : adjust_insn (bb, insn);
10286 :
10287 89875653 : if (pre)
10288 1926209 : VTI (bb)->out.stack_adjust += pre;
10289 :
10290 89875653 : if (DEBUG_MARKER_INSN_P (insn))
10291 : {
10292 11007505 : reemit_marker_as_note (insn);
10293 11007505 : continue;
10294 : }
10295 :
10296 78868148 : if (MAY_HAVE_DEBUG_BIND_INSNS)
10297 : {
10298 78867726 : if (CALL_P (insn))
10299 3141934 : prepare_call_arguments (bb, insn);
10300 78867726 : cselib_process_insn (insn);
10301 78867726 : if (dump_file && (dump_flags & TDF_DETAILS))
10302 : {
10303 11 : if (dump_flags & TDF_SLIM)
10304 11 : dump_insn_slim (dump_file, insn);
10305 : else
10306 0 : print_rtl_single (dump_file, insn);
10307 11 : dump_cselib_table (dump_file);
10308 : }
10309 : }
10310 78868148 : if (!cselib_hook_called)
10311 422 : add_with_sets (insn, 0, 0);
10312 78868148 : cancel_changes (0);
10313 :
10314 78868148 : if (post)
10315 : {
10316 2329138 : micro_operation mo;
10317 2329138 : mo.type = MO_ADJUST;
10318 2329138 : mo.u.adjust = post;
10319 2329138 : mo.insn = insn;
10320 2329138 : if (dump_file && (dump_flags & TDF_DETAILS))
10321 1 : log_op_type (PATTERN (insn), bb, insn,
10322 : MO_ADJUST, dump_file);
10323 2329138 : VTI (bb)->mos.safe_push (mo);
10324 2329138 : VTI (bb)->out.stack_adjust += post;
10325 : }
10326 :
10327 78868148 : if (maybe_ne (fp_cfa_offset, -1)
10328 7365246 : && known_eq (hard_frame_pointer_adjustment, -1)
10329 78987673 : && fp_setter_insn (insn))
10330 : {
10331 22176 : vt_init_cfa_base ();
10332 22176 : hard_frame_pointer_adjustment = fp_cfa_offset;
10333 : /* Disassociate sp from fp now. */
10334 22176 : if (MAY_HAVE_DEBUG_BIND_INSNS)
10335 : {
10336 22176 : cselib_val *v;
10337 22176 : cselib_invalidate_rtx (stack_pointer_rtx);
10338 36042 : v = cselib_lookup (stack_pointer_rtx, Pmode, 1,
10339 : VOIDmode);
10340 22176 : if (v && !cselib_preserved_value_p (v))
10341 : {
10342 22176 : cselib_set_value_sp_based (v);
10343 22176 : preserve_value (v);
10344 : }
10345 : }
10346 : }
10347 : }
10348 : }
10349 7340890 : gcc_assert (offset == VTI (bb)->out.stack_adjust);
10350 : }
10351 :
10352 4391858 : bb = last_bb;
10353 :
10354 4391858 : if (MAY_HAVE_DEBUG_BIND_INSNS)
10355 : {
10356 4391782 : cselib_preserve_only_values ();
10357 4391782 : cselib_reset_table (cselib_get_next_uid ());
10358 4391782 : cselib_record_sets_hook = NULL;
10359 : }
10360 : }
10361 :
10362 496103 : hard_frame_pointer_adjustment = -1;
10363 496103 : VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->flooded = true;
10364 496103 : cfa_base_rtx = NULL_RTX;
10365 496103 : return true;
10366 : }
10367 :
10368 : /* This is *not* reset after each function. It gives each
10369 : NOTE_INSN_DELETED_DEBUG_LABEL in the entire compilation
10370 : a unique label number. */
10371 :
10372 : static int debug_label_num = 1;
10373 :
10374 : /* Remove from the insn stream a single debug insn used for
10375 : variable tracking at assignments. */
10376 :
10377 : static inline void
10378 37136897 : delete_vta_debug_insn (rtx_insn *insn)
10379 : {
10380 37136897 : if (DEBUG_MARKER_INSN_P (insn))
10381 : {
10382 927 : reemit_marker_as_note (insn);
10383 927 : return;
10384 : }
10385 :
10386 37135970 : tree decl = INSN_VAR_LOCATION_DECL (insn);
10387 37135970 : if (TREE_CODE (decl) == LABEL_DECL
10388 9373 : && DECL_NAME (decl)
10389 37145217 : && !DECL_RTL_SET_P (decl))
10390 : {
10391 8481 : PUT_CODE (insn, NOTE);
10392 8481 : NOTE_KIND (insn) = NOTE_INSN_DELETED_DEBUG_LABEL;
10393 8481 : NOTE_DELETED_LABEL_NAME (insn)
10394 8481 : = IDENTIFIER_POINTER (DECL_NAME (decl));
10395 8481 : SET_DECL_RTL (decl, insn);
10396 8481 : CODE_LABEL_NUMBER (insn) = debug_label_num++;
10397 : }
10398 : else
10399 37127489 : delete_insn (insn);
10400 : }
10401 :
10402 : /* Remove from the insn stream all debug insns used for variable
10403 : tracking at assignments. USE_CFG should be false if the cfg is no
10404 : longer usable. */
10405 :
10406 : void
10407 496173 : delete_vta_debug_insns (bool use_cfg)
10408 : {
10409 496173 : basic_block bb;
10410 496173 : rtx_insn *insn, *next;
10411 :
10412 496173 : if (!MAY_HAVE_DEBUG_INSNS)
10413 : return;
10414 :
10415 496169 : if (use_cfg)
10416 7838021 : FOR_EACH_BB_FN (bb, cfun)
10417 : {
10418 297817564 : FOR_BB_INSNS_SAFE (bb, insn, next)
10419 141566929 : if (DEBUG_INSN_P (insn))
10420 37136893 : delete_vta_debug_insn (insn);
10421 : }
10422 : else
10423 12 : for (insn = get_insns (); insn; insn = next)
10424 : {
10425 11 : next = NEXT_INSN (insn);
10426 11 : if (DEBUG_INSN_P (insn))
10427 4 : delete_vta_debug_insn (insn);
10428 : }
10429 : }
10430 :
10431 : /* Run a fast, BB-local only version of var tracking, to take care of
10432 : information that we don't do global analysis on, such that not all
10433 : information is lost. If SKIPPED holds, we're skipping the global
10434 : pass entirely, so we should try to use information it would have
10435 : handled as well.. */
10436 :
10437 : static void
10438 496169 : vt_debug_insns_local (bool skipped ATTRIBUTE_UNUSED)
10439 : {
10440 : /* ??? Just skip it all for now. */
10441 0 : delete_vta_debug_insns (true);
10442 0 : }
10443 :
10444 : /* Free the data structures needed for variable tracking. */
10445 :
10446 : static void
10447 496170 : vt_finalize (void)
10448 : {
10449 496170 : basic_block bb;
10450 :
10451 7838054 : FOR_EACH_BB_FN (bb, cfun)
10452 : {
10453 7341884 : VTI (bb)->mos.release ();
10454 : }
10455 :
10456 8830394 : FOR_ALL_BB_FN (bb, cfun)
10457 : {
10458 8334224 : dataflow_set_destroy (&VTI (bb)->in);
10459 8334224 : dataflow_set_destroy (&VTI (bb)->out);
10460 8334224 : if (VTI (bb)->permp)
10461 : {
10462 282935 : dataflow_set_destroy (VTI (bb)->permp);
10463 282935 : XDELETE (VTI (bb)->permp);
10464 : }
10465 : }
10466 496170 : free_aux_for_blocks ();
10467 496170 : delete empty_shared_hash->htab;
10468 496170 : empty_shared_hash->htab = NULL;
10469 496170 : delete changed_variables;
10470 496170 : changed_variables = NULL;
10471 496170 : attrs_pool.release ();
10472 496170 : var_pool.release ();
10473 496170 : location_chain_pool.release ();
10474 496170 : shared_hash_pool.release ();
10475 :
10476 496170 : if (MAY_HAVE_DEBUG_BIND_INSNS)
10477 : {
10478 496129 : if (global_get_addr_cache)
10479 496129 : delete global_get_addr_cache;
10480 496129 : global_get_addr_cache = NULL;
10481 496129 : loc_exp_dep_pool.release ();
10482 496129 : valvar_pool.release ();
10483 496129 : preserved_values.release ();
10484 496129 : cselib_finish ();
10485 496129 : BITMAP_FREE (scratch_regs);
10486 496129 : scratch_regs = NULL;
10487 : }
10488 :
10489 : #ifdef HAVE_window_save
10490 : vec_free (windowed_parm_regs);
10491 : #endif
10492 :
10493 496170 : if (vui_vec)
10494 8573 : XDELETEVEC (vui_vec);
10495 496170 : vui_vec = NULL;
10496 496170 : vui_allocated = 0;
10497 496170 : }
10498 :
10499 : /* The entry point to variable tracking pass. */
10500 :
10501 : static inline unsigned int
10502 496171 : variable_tracking_main_1 (void)
10503 : {
10504 496171 : bool success;
10505 :
10506 : /* We won't be called as a separate pass if flag_var_tracking is not
10507 : set, but final may call us to turn debug markers into notes. */
10508 496171 : if ((!flag_var_tracking && MAY_HAVE_DEBUG_INSNS)
10509 496171 : || flag_var_tracking_assignments < 0
10510 : /* Var-tracking right now assumes the IR doesn't contain
10511 : any pseudos at this point. */
10512 496169 : || targetm.no_register_allocation)
10513 : {
10514 2 : delete_vta_debug_insns (true);
10515 2 : return 0;
10516 : }
10517 :
10518 496169 : if (!flag_var_tracking)
10519 : return 0;
10520 :
10521 496169 : if (n_basic_blocks_for_fn (cfun) > 500
10522 453 : && n_edges_for_fn (cfun) / n_basic_blocks_for_fn (cfun) >= 20)
10523 : {
10524 0 : vt_debug_insns_local (true);
10525 0 : return 0;
10526 : }
10527 :
10528 496169 : if (!vt_initialize ())
10529 : {
10530 67 : vt_finalize ();
10531 67 : vt_debug_insns_local (true);
10532 67 : return 0;
10533 : }
10534 :
10535 496102 : success = vt_find_locations ();
10536 :
10537 496102 : if (!success && flag_var_tracking_assignments > 0)
10538 : {
10539 1 : vt_finalize ();
10540 :
10541 1 : delete_vta_debug_insns (true);
10542 :
10543 : /* This is later restored by our caller. */
10544 1 : flag_var_tracking_assignments = 0;
10545 :
10546 1 : success = vt_initialize ();
10547 1 : gcc_assert (success);
10548 :
10549 1 : success = vt_find_locations ();
10550 : }
10551 :
10552 1 : if (!success)
10553 : {
10554 0 : vt_finalize ();
10555 0 : vt_debug_insns_local (false);
10556 0 : return 0;
10557 : }
10558 :
10559 496102 : if (dump_file && (dump_flags & TDF_DETAILS))
10560 : {
10561 1 : dump_dataflow_sets ();
10562 1 : dump_reg_info (dump_file);
10563 1 : dump_flow_info (dump_file, dump_flags);
10564 : }
10565 :
10566 496102 : timevar_push (TV_VAR_TRACKING_EMIT);
10567 496102 : vt_emit_notes ();
10568 496102 : timevar_pop (TV_VAR_TRACKING_EMIT);
10569 :
10570 496102 : vt_finalize ();
10571 496102 : vt_debug_insns_local (false);
10572 496102 : return 0;
10573 : }
10574 :
10575 : unsigned int
10576 496171 : variable_tracking_main (void)
10577 : {
10578 496171 : unsigned int ret;
10579 496171 : int save = flag_var_tracking_assignments;
10580 :
10581 496171 : ret = variable_tracking_main_1 ();
10582 :
10583 496171 : flag_var_tracking_assignments = save;
10584 :
10585 496171 : return ret;
10586 : }
10587 :
10588 : namespace {
10589 :
10590 : const pass_data pass_data_variable_tracking =
10591 : {
10592 : RTL_PASS, /* type */
10593 : "vartrack", /* name */
10594 : OPTGROUP_NONE, /* optinfo_flags */
10595 : TV_VAR_TRACKING, /* tv_id */
10596 : 0, /* properties_required */
10597 : 0, /* properties_provided */
10598 : 0, /* properties_destroyed */
10599 : 0, /* todo_flags_start */
10600 : 0, /* todo_flags_finish */
10601 : };
10602 :
10603 : class pass_variable_tracking : public rtl_opt_pass
10604 : {
10605 : public:
10606 287872 : pass_variable_tracking (gcc::context *ctxt)
10607 575744 : : rtl_opt_pass (pass_data_variable_tracking, ctxt)
10608 : {}
10609 :
10610 : /* opt_pass methods: */
10611 1480955 : bool gate (function *) final override
10612 : {
10613 1480955 : return (flag_var_tracking && !targetm.delay_vartrack);
10614 : }
10615 :
10616 496171 : unsigned int execute (function *) final override
10617 : {
10618 496171 : return variable_tracking_main ();
10619 : }
10620 :
10621 : }; // class pass_variable_tracking
10622 :
10623 : } // anon namespace
10624 :
10625 : rtl_opt_pass *
10626 287872 : make_pass_variable_tracking (gcc::context *ctxt)
10627 : {
10628 287872 : return new pass_variable_tracking (ctxt);
10629 : }
|