1 /* Variable tracking routines for the GNU compiler.
2 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* This file contains the variable tracking pass. It computes where
22 variables are located (which registers or where in memory) at each position
23 in instruction stream and emits notes describing the locations.
24 Debug information (DWARF2 location lists) is finally generated from
26 With this debug information, it is possible to show variables
27 even when debugging optimized code.
29 How does the variable tracking pass work?
31 First, it scans RTL code for uses, stores and clobbers (register/memory
32 references in instructions), for call insns and for stack adjustments
33 separately for each basic block and saves them to an array of micro
35 The micro operations of one instruction are ordered so that
36 pre-modifying stack adjustment < use < use with no var < call insn <
37 < clobber < set < post-modifying stack adjustment
39 Then, a forward dataflow analysis is performed to find out how locations
40 of variables change through code and to propagate the variable locations
41 along control flow graph.
42 The IN set for basic block BB is computed as a union of OUT sets of BB's
43 predecessors, the OUT set for BB is copied from the IN set for BB and
44 is changed according to micro operations in BB.
46 The IN and OUT sets for basic blocks consist of a current stack adjustment
47 (used for adjusting offset of variables addressed using stack pointer),
48 the table of structures describing the locations of parts of a variable
49 and for each physical register a linked list for each physical register.
50 The linked list is a list of variable parts stored in the register,
51 i.e. it is a list of triplets (reg, decl, offset) where decl is
52 REG_EXPR (reg) and offset is REG_OFFSET (reg). The linked list is used for
53 effective deleting appropriate variable parts when we set or clobber the
56 There may be more than one variable part in a register. The linked lists
57 should be pretty short so it is a good data structure here.
58 For example in the following code, register allocator may assign same
59 register to variables A and B, and both of them are stored in the same
72 Finally, the NOTE_INSN_VAR_LOCATION notes describing the variable locations
73 are emitted to appropriate positions in RTL code. Each such a note describes
74 the location of one variable at the point in instruction stream where the
75 note is. There is no need to emit a note for each variable before each
76 instruction, we only emit these notes where the location of variable changes
77 (this means that we also emit notes for changes between the OUT set of the
78 previous block and the IN set of the current block).
80 The notes consist of two parts:
81 1. the declaration (from REG_EXPR or MEM_EXPR)
82 2. the location of a variable - it is either a simple register/memory
83 reference (for simple variables, for example int),
84 or a parallel of register/memory references (for a large variables
85 which consist of several parts, for example long long).
91 #include "coretypes.h"
96 #include "hard-reg-set.h"
97 #include "basic-block.h"
100 #include "insn-config.h"
103 #include "alloc-pool.h"
109 #include "tree-pass.h"
110 #include "tree-flow.h"
114 #include "diagnostic.h"
115 #include "tree-pretty-print.h"
116 #include "pointer-set.h"
120 /* var-tracking.c assumes that tree code with the same value as VALUE rtx code
121 has no chance to appear in REG_EXPR/MEM_EXPRs and isn't a decl.
122 Currently the value is the same as IDENTIFIER_NODE, which has such
123 a property. If this compile time assertion ever fails, make sure that
124 the new tree code that equals (int) VALUE has the same property. */
125 extern char check_value_val[(int) VALUE == (int) IDENTIFIER_NODE ? 1 : -1];
127 /* Type of micro operation. */
128 enum micro_operation_type
130 MO_USE, /* Use location (REG or MEM). */
131 MO_USE_NO_VAR,/* Use location which is not associated with a variable
132 or the variable is not trackable. */
133 MO_VAL_USE, /* Use location which is associated with a value. */
134 MO_VAL_LOC, /* Use location which appears in a debug insn. */
135 MO_VAL_SET, /* Set location associated with a value. */
136 MO_SET, /* Set location. */
137 MO_COPY, /* Copy the same portion of a variable from one
138 location to another. */
139 MO_CLOBBER, /* Clobber location. */
140 MO_CALL, /* Call insn. */
141 MO_ADJUST /* Adjust stack pointer. */
145 static const char * const ATTRIBUTE_UNUSED
146 micro_operation_type_name[] = {
159 /* Where shall the note be emitted? BEFORE or AFTER the instruction.
160 Notes emitted as AFTER_CALL are to take effect during the call,
161 rather than after the call. */
164 EMIT_NOTE_BEFORE_INSN,
165 EMIT_NOTE_AFTER_INSN,
166 EMIT_NOTE_AFTER_CALL_INSN
169 /* Structure holding information about micro operation. */
170 typedef struct micro_operation_def
172 /* Type of micro operation. */
173 enum micro_operation_type type;
175 /* The instruction which the micro operation is in, for MO_USE,
176 MO_USE_NO_VAR, MO_CALL and MO_ADJUST, or the subsequent
177 instruction or note in the original flow (before any var-tracking
178 notes are inserted, to simplify emission of notes), for MO_SET
183 /* Location. For MO_SET and MO_COPY, this is the SET that
184 performs the assignment, if known, otherwise it is the target
185 of the assignment. For MO_VAL_USE and MO_VAL_SET, it is a
186 CONCAT of the VALUE and the LOC associated with it. For
187 MO_VAL_LOC, it is a CONCAT of the VALUE and the VAR_LOCATION
188 associated with it. */
191 /* Stack adjustment. */
192 HOST_WIDE_INT adjust;
196 DEF_VEC_O(micro_operation);
197 DEF_VEC_ALLOC_O(micro_operation,heap);
199 /* A declaration of a variable, or an RTL value being handled like a
201 typedef void *decl_or_value;
203 /* Structure for passing some other parameters to function
204 emit_note_insn_var_location. */
205 typedef struct emit_note_data_def
207 /* The instruction which the note will be emitted before/after. */
210 /* Where the note will be emitted (before/after insn)? */
211 enum emit_note_where where;
213 /* The variables and values active at this point. */
217 /* Description of location of a part of a variable. The content of a physical
218 register is described by a chain of these structures.
219 The chains are pretty short (usually 1 or 2 elements) and thus
220 chain is the best data structure. */
221 typedef struct attrs_def
223 /* Pointer to next member of the list. */
224 struct attrs_def *next;
226 /* The rtx of register. */
229 /* The declaration corresponding to LOC. */
232 /* Offset from start of DECL. */
233 HOST_WIDE_INT offset;
236 /* Structure holding a refcounted hash table. If refcount > 1,
237 it must be first unshared before modified. */
238 typedef struct shared_hash_def
240 /* Reference count. */
243 /* Actual hash table. */
247 /* Structure holding the IN or OUT set for a basic block. */
248 typedef struct dataflow_set_def
250 /* Adjustment of stack offset. */
251 HOST_WIDE_INT stack_adjust;
253 /* Attributes for registers (lists of attrs). */
254 attrs regs[FIRST_PSEUDO_REGISTER];
256 /* Variable locations. */
259 /* Vars that is being traversed. */
260 shared_hash traversed_vars;
263 /* The structure (one for each basic block) containing the information
264 needed for variable tracking. */
265 typedef struct variable_tracking_info_def
267 /* The vector of micro operations. */
268 VEC(micro_operation, heap) *mos;
270 /* The IN and OUT set for dataflow analysis. */
274 /* The permanent-in dataflow set for this block. This is used to
275 hold values for which we had to compute entry values. ??? This
276 should probably be dynamically allocated, to avoid using more
277 memory in non-debug builds. */
280 /* Has the block been visited in DFS? */
283 /* Has the block been flooded in VTA? */
286 } *variable_tracking_info;
288 /* Structure for chaining the locations. */
289 typedef struct location_chain_def
291 /* Next element in the chain. */
292 struct location_chain_def *next;
294 /* The location (REG, MEM or VALUE). */
297 /* The "value" stored in this location. */
301 enum var_init_status init;
304 /* A vector of loc_exp_dep holds the active dependencies of a one-part
305 DV on VALUEs, i.e., the VALUEs expanded so as to form the current
306 location of DV. Each entry is also part of VALUE' s linked-list of
307 backlinks back to DV. */
308 typedef struct loc_exp_dep_s
310 /* The dependent DV. */
312 /* The dependency VALUE or DECL_DEBUG. */
314 /* The next entry in VALUE's backlinks list. */
315 struct loc_exp_dep_s *next;
316 /* A pointer to the pointer to this entry (head or prev's next) in
317 the doubly-linked list. */
318 struct loc_exp_dep_s **pprev;
321 DEF_VEC_O (loc_exp_dep);
323 /* This data structure is allocated for one-part variables at the time
324 of emitting notes. */
327 /* Doubly-linked list of dependent DVs. These are DVs whose cur_loc
328 computation used the expansion of this variable, and that ought
329 to be notified should this variable change. If the DV's cur_loc
330 expanded to NULL, all components of the loc list are regarded as
331 active, so that any changes in them give us a chance to get a
332 location. Otherwise, only components of the loc that expanded to
333 non-NULL are regarded as active dependencies. */
334 loc_exp_dep *backlinks;
335 /* This holds the LOC that was expanded into cur_loc. We need only
336 mark a one-part variable as changed if the FROM loc is removed,
337 or if it has no known location and a loc is added, or if it gets
338 a change notification from any of its active dependencies. */
340 /* The depth of the cur_loc expression. */
342 /* Dependencies actively used when expand FROM into cur_loc. */
343 VEC (loc_exp_dep, none) deps;
346 /* Structure describing one part of variable. */
347 typedef struct variable_part_def
349 /* Chain of locations of the part. */
350 location_chain loc_chain;
352 /* Location which was last emitted to location list. */
357 /* The offset in the variable, if !var->onepart. */
358 HOST_WIDE_INT offset;
360 /* Pointer to auxiliary data, if var->onepart and emit_notes. */
361 struct onepart_aux *onepaux;
365 /* Maximum number of location parts. */
366 #define MAX_VAR_PARTS 16
368 /* Enumeration type used to discriminate various types of one-part
370 typedef enum onepart_enum
372 /* Not a one-part variable. */
374 /* A one-part DECL that is not a DEBUG_EXPR_DECL. */
376 /* A DEBUG_EXPR_DECL. */
382 /* Structure describing where the variable is located. */
383 typedef struct variable_def
385 /* The declaration of the variable, or an RTL value being handled
386 like a declaration. */
389 /* Reference count. */
392 /* Number of variable parts. */
395 /* What type of DV this is, according to enum onepart_enum. */
396 ENUM_BITFIELD (onepart_enum) onepart : CHAR_BIT;
398 /* True if this variable_def struct is currently in the
399 changed_variables hash table. */
400 bool in_changed_variables;
402 /* The variable parts. */
403 variable_part var_part[1];
405 typedef const struct variable_def *const_variable;
407 /* Pointer to the BB's information specific to variable tracking pass. */
408 #define VTI(BB) ((variable_tracking_info) (BB)->aux)
410 /* Macro to access MEM_OFFSET as an HOST_WIDE_INT. Evaluates MEM twice. */
411 #define INT_MEM_OFFSET(mem) (MEM_OFFSET_KNOWN_P (mem) ? MEM_OFFSET (mem) : 0)
413 #if ENABLE_CHECKING && (GCC_VERSION >= 2007)
415 /* Access VAR's Ith part's offset, checking that it's not a one-part
417 #define VAR_PART_OFFSET(var, i) __extension__ \
418 (*({ variable const __v = (var); \
419 gcc_checking_assert (!__v->onepart); \
420 &__v->var_part[(i)].aux.offset; }))
422 /* Access VAR's one-part auxiliary data, checking that it is a
423 one-part variable. */
424 #define VAR_LOC_1PAUX(var) __extension__ \
425 (*({ variable const __v = (var); \
426 gcc_checking_assert (__v->onepart); \
427 &__v->var_part[0].aux.onepaux; }))
430 #define VAR_PART_OFFSET(var, i) ((var)->var_part[(i)].aux.offset)
431 #define VAR_LOC_1PAUX(var) ((var)->var_part[0].aux.onepaux)
434 /* These are accessor macros for the one-part auxiliary data. When
435 convenient for users, they're guarded by tests that the data was
437 #define VAR_LOC_DEP_LST(var) (VAR_LOC_1PAUX (var) \
438 ? VAR_LOC_1PAUX (var)->backlinks \
440 #define VAR_LOC_DEP_LSTP(var) (VAR_LOC_1PAUX (var) \
441 ? &VAR_LOC_1PAUX (var)->backlinks \
443 #define VAR_LOC_FROM(var) (VAR_LOC_1PAUX (var)->from)
444 #define VAR_LOC_DEPTH(var) (VAR_LOC_1PAUX (var)->depth)
445 #define VAR_LOC_DEP_VEC(var) (VAR_LOC_1PAUX (var) \
446 ? &VAR_LOC_1PAUX (var)->deps \
449 /* Alloc pool for struct attrs_def. */
450 static alloc_pool attrs_pool;
452 /* Alloc pool for struct variable_def with MAX_VAR_PARTS entries. */
453 static alloc_pool var_pool;
455 /* Alloc pool for struct variable_def with a single var_part entry. */
456 static alloc_pool valvar_pool;
458 /* Alloc pool for struct location_chain_def. */
459 static alloc_pool loc_chain_pool;
461 /* Alloc pool for struct shared_hash_def. */
462 static alloc_pool shared_hash_pool;
464 /* Changed variables, notes will be emitted for them. */
465 static htab_t changed_variables;
467 /* Shall notes be emitted? */
468 static bool emit_notes;
470 /* Values whose dynamic location lists have gone empty, but whose
471 cselib location lists are still usable. Use this to hold the
472 current location, the backlinks, etc, during emit_notes. */
473 static htab_t dropped_values;
475 /* Empty shared hashtable. */
476 static shared_hash empty_shared_hash;
478 /* Scratch register bitmap used by cselib_expand_value_rtx. */
479 static bitmap scratch_regs = NULL;
481 #ifdef HAVE_window_save
482 typedef struct GTY(()) parm_reg {
487 DEF_VEC_O(parm_reg_t);
488 DEF_VEC_ALLOC_O(parm_reg_t, gc);
490 /* Vector of windowed parameter registers, if any. */
491 static VEC(parm_reg_t, gc) *windowed_parm_regs = NULL;
494 /* Variable used to tell whether cselib_process_insn called our hook. */
495 static bool cselib_hook_called;
497 /* Local function prototypes. */
498 static void stack_adjust_offset_pre_post (rtx, HOST_WIDE_INT *,
500 static void insn_stack_adjust_offset_pre_post (rtx, HOST_WIDE_INT *,
502 static bool vt_stack_adjustments (void);
503 static hashval_t variable_htab_hash (const void *);
504 static int variable_htab_eq (const void *, const void *);
505 static void variable_htab_free (void *);
507 static void init_attrs_list_set (attrs *);
508 static void attrs_list_clear (attrs *);
509 static attrs attrs_list_member (attrs, decl_or_value, HOST_WIDE_INT);
510 static void attrs_list_insert (attrs *, decl_or_value, HOST_WIDE_INT, rtx);
511 static void attrs_list_copy (attrs *, attrs);
512 static void attrs_list_union (attrs *, attrs);
514 static void **unshare_variable (dataflow_set *set, void **slot, variable var,
515 enum var_init_status);
516 static void vars_copy (htab_t, htab_t);
517 static tree var_debug_decl (tree);
518 static void var_reg_set (dataflow_set *, rtx, enum var_init_status, rtx);
519 static void var_reg_delete_and_set (dataflow_set *, rtx, bool,
520 enum var_init_status, rtx);
521 static void var_reg_delete (dataflow_set *, rtx, bool);
522 static void var_regno_delete (dataflow_set *, int);
523 static void var_mem_set (dataflow_set *, rtx, enum var_init_status, rtx);
524 static void var_mem_delete_and_set (dataflow_set *, rtx, bool,
525 enum var_init_status, rtx);
526 static void var_mem_delete (dataflow_set *, rtx, bool);
528 static void dataflow_set_init (dataflow_set *);
529 static void dataflow_set_clear (dataflow_set *);
530 static void dataflow_set_copy (dataflow_set *, dataflow_set *);
531 static int variable_union_info_cmp_pos (const void *, const void *);
532 static void dataflow_set_union (dataflow_set *, dataflow_set *);
533 static location_chain find_loc_in_1pdv (rtx, variable, htab_t);
534 static bool canon_value_cmp (rtx, rtx);
535 static int loc_cmp (rtx, rtx);
536 static bool variable_part_different_p (variable_part *, variable_part *);
537 static bool onepart_variable_different_p (variable, variable);
538 static bool variable_different_p (variable, variable);
539 static bool dataflow_set_different (dataflow_set *, dataflow_set *);
540 static void dataflow_set_destroy (dataflow_set *);
542 static bool contains_symbol_ref (rtx);
543 static bool track_expr_p (tree, bool);
544 static bool same_variable_part_p (rtx, tree, HOST_WIDE_INT);
545 static int add_uses (rtx *, void *);
546 static void add_uses_1 (rtx *, void *);
547 static void add_stores (rtx, const_rtx, void *);
548 static bool compute_bb_dataflow (basic_block);
549 static bool vt_find_locations (void);
551 static void dump_attrs_list (attrs);
552 static int dump_var_slot (void **, void *);
553 static void dump_var (variable);
554 static void dump_vars (htab_t);
555 static void dump_dataflow_set (dataflow_set *);
556 static void dump_dataflow_sets (void);
558 static void set_dv_changed (decl_or_value, bool);
559 static void variable_was_changed (variable, dataflow_set *);
560 static void **set_slot_part (dataflow_set *, rtx, void **,
561 decl_or_value, HOST_WIDE_INT,
562 enum var_init_status, rtx);
563 static void set_variable_part (dataflow_set *, rtx,
564 decl_or_value, HOST_WIDE_INT,
565 enum var_init_status, rtx, enum insert_option);
566 static void **clobber_slot_part (dataflow_set *, rtx,
567 void **, HOST_WIDE_INT, rtx);
568 static void clobber_variable_part (dataflow_set *, rtx,
569 decl_or_value, HOST_WIDE_INT, rtx);
570 static void **delete_slot_part (dataflow_set *, rtx, void **, HOST_WIDE_INT);
571 static void delete_variable_part (dataflow_set *, rtx,
572 decl_or_value, HOST_WIDE_INT);
573 static int emit_note_insn_var_location (void **, void *);
574 static void emit_notes_for_changes (rtx, enum emit_note_where, shared_hash);
575 static int emit_notes_for_differences_1 (void **, void *);
576 static int emit_notes_for_differences_2 (void **, void *);
577 static void emit_notes_for_differences (rtx, dataflow_set *, dataflow_set *);
578 static void emit_notes_in_bb (basic_block, dataflow_set *);
579 static void vt_emit_notes (void);
581 static bool vt_get_decl_and_offset (rtx, tree *, HOST_WIDE_INT *);
582 static void vt_add_function_parameters (void);
583 static bool vt_initialize (void);
584 static void vt_finalize (void);
586 /* Given a SET, calculate the amount of stack adjustment it contains
587 PRE- and POST-modifying stack pointer.
588 This function is similar to stack_adjust_offset. */
591 stack_adjust_offset_pre_post (rtx pattern, HOST_WIDE_INT *pre,
594 rtx src = SET_SRC (pattern);
595 rtx dest = SET_DEST (pattern);
598 if (dest == stack_pointer_rtx)
600 /* (set (reg sp) (plus (reg sp) (const_int))) */
601 code = GET_CODE (src);
602 if (! (code == PLUS || code == MINUS)
603 || XEXP (src, 0) != stack_pointer_rtx
604 || !CONST_INT_P (XEXP (src, 1)))
608 *post += INTVAL (XEXP (src, 1));
610 *post -= INTVAL (XEXP (src, 1));
612 else if (MEM_P (dest))
614 /* (set (mem (pre_dec (reg sp))) (foo)) */
615 src = XEXP (dest, 0);
616 code = GET_CODE (src);
622 if (XEXP (src, 0) == stack_pointer_rtx)
624 rtx val = XEXP (XEXP (src, 1), 1);
625 /* We handle only adjustments by constant amount. */
626 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS &&
629 if (code == PRE_MODIFY)
630 *pre -= INTVAL (val);
632 *post -= INTVAL (val);
638 if (XEXP (src, 0) == stack_pointer_rtx)
640 *pre += GET_MODE_SIZE (GET_MODE (dest));
646 if (XEXP (src, 0) == stack_pointer_rtx)
648 *post += GET_MODE_SIZE (GET_MODE (dest));
654 if (XEXP (src, 0) == stack_pointer_rtx)
656 *pre -= GET_MODE_SIZE (GET_MODE (dest));
662 if (XEXP (src, 0) == stack_pointer_rtx)
664 *post -= GET_MODE_SIZE (GET_MODE (dest));
675 /* Given an INSN, calculate the amount of stack adjustment it contains
676 PRE- and POST-modifying stack pointer. */
679 insn_stack_adjust_offset_pre_post (rtx insn, HOST_WIDE_INT *pre,
687 pattern = PATTERN (insn);
688 if (RTX_FRAME_RELATED_P (insn))
690 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
692 pattern = XEXP (expr, 0);
695 if (GET_CODE (pattern) == SET)
696 stack_adjust_offset_pre_post (pattern, pre, post);
697 else if (GET_CODE (pattern) == PARALLEL
698 || GET_CODE (pattern) == SEQUENCE)
702 /* There may be stack adjustments inside compound insns. Search
704 for ( i = XVECLEN (pattern, 0) - 1; i >= 0; i--)
705 if (GET_CODE (XVECEXP (pattern, 0, i)) == SET)
706 stack_adjust_offset_pre_post (XVECEXP (pattern, 0, i), pre, post);
710 /* Compute stack adjustments for all blocks by traversing DFS tree.
711 Return true when the adjustments on all incoming edges are consistent.
712 Heavily borrowed from pre_and_rev_post_order_compute. */
715 vt_stack_adjustments (void)
717 edge_iterator *stack;
720 /* Initialize entry block. */
721 VTI (ENTRY_BLOCK_PTR)->visited = true;
722 VTI (ENTRY_BLOCK_PTR)->in.stack_adjust = INCOMING_FRAME_SP_OFFSET;
723 VTI (ENTRY_BLOCK_PTR)->out.stack_adjust = INCOMING_FRAME_SP_OFFSET;
725 /* Allocate stack for back-tracking up CFG. */
726 stack = XNEWVEC (edge_iterator, n_basic_blocks + 1);
729 /* Push the first edge on to the stack. */
730 stack[sp++] = ei_start (ENTRY_BLOCK_PTR->succs);
738 /* Look at the edge on the top of the stack. */
740 src = ei_edge (ei)->src;
741 dest = ei_edge (ei)->dest;
743 /* Check if the edge destination has been visited yet. */
744 if (!VTI (dest)->visited)
747 HOST_WIDE_INT pre, post, offset;
748 VTI (dest)->visited = true;
749 VTI (dest)->in.stack_adjust = offset = VTI (src)->out.stack_adjust;
751 if (dest != EXIT_BLOCK_PTR)
752 for (insn = BB_HEAD (dest);
753 insn != NEXT_INSN (BB_END (dest));
754 insn = NEXT_INSN (insn))
757 insn_stack_adjust_offset_pre_post (insn, &pre, &post);
758 offset += pre + post;
761 VTI (dest)->out.stack_adjust = offset;
763 if (EDGE_COUNT (dest->succs) > 0)
764 /* Since the DEST node has been visited for the first
765 time, check its successors. */
766 stack[sp++] = ei_start (dest->succs);
770 /* Check whether the adjustments on the edges are the same. */
771 if (VTI (dest)->in.stack_adjust != VTI (src)->out.stack_adjust)
777 if (! ei_one_before_end_p (ei))
778 /* Go to the next edge. */
779 ei_next (&stack[sp - 1]);
781 /* Return to previous level if there are no more edges. */
790 /* arg_pointer_rtx resp. frame_pointer_rtx if stack_pointer_rtx or
791 hard_frame_pointer_rtx is being mapped to it and offset for it. */
792 static rtx cfa_base_rtx;
793 static HOST_WIDE_INT cfa_base_offset;
795 /* Compute a CFA-based value for an ADJUSTMENT made to stack_pointer_rtx
796 or hard_frame_pointer_rtx. */
799 compute_cfa_pointer (HOST_WIDE_INT adjustment)
801 return plus_constant (cfa_base_rtx, adjustment + cfa_base_offset);
804 /* Adjustment for hard_frame_pointer_rtx to cfa base reg,
805 or -1 if the replacement shouldn't be done. */
806 static HOST_WIDE_INT hard_frame_pointer_adjustment = -1;
808 /* Data for adjust_mems callback. */
810 struct adjust_mem_data
813 enum machine_mode mem_mode;
814 HOST_WIDE_INT stack_adjust;
818 /* Helper for adjust_mems. Return 1 if *loc is unsuitable for
819 transformation of wider mode arithmetics to narrower mode,
820 -1 if it is suitable and subexpressions shouldn't be
821 traversed and 0 if it is suitable and subexpressions should
822 be traversed. Called through for_each_rtx. */
825 use_narrower_mode_test (rtx *loc, void *data)
827 rtx subreg = (rtx) data;
829 if (CONSTANT_P (*loc))
831 switch (GET_CODE (*loc))
834 if (cselib_lookup (*loc, GET_MODE (SUBREG_REG (subreg)), 0, VOIDmode))
836 if (!validate_subreg (GET_MODE (subreg), GET_MODE (*loc),
837 *loc, subreg_lowpart_offset (GET_MODE (subreg),
846 if (for_each_rtx (&XEXP (*loc, 0), use_narrower_mode_test, data))
855 /* Transform X into narrower mode MODE from wider mode WMODE. */
858 use_narrower_mode (rtx x, enum machine_mode mode, enum machine_mode wmode)
862 return lowpart_subreg (mode, x, wmode);
863 switch (GET_CODE (x))
866 return lowpart_subreg (mode, x, wmode);
870 op0 = use_narrower_mode (XEXP (x, 0), mode, wmode);
871 op1 = use_narrower_mode (XEXP (x, 1), mode, wmode);
872 return simplify_gen_binary (GET_CODE (x), mode, op0, op1);
874 op0 = use_narrower_mode (XEXP (x, 0), mode, wmode);
875 return simplify_gen_binary (ASHIFT, mode, op0, XEXP (x, 1));
881 /* Helper function for adjusting used MEMs. */
884 adjust_mems (rtx loc, const_rtx old_rtx, void *data)
886 struct adjust_mem_data *amd = (struct adjust_mem_data *) data;
887 rtx mem, addr = loc, tem;
888 enum machine_mode mem_mode_save;
890 switch (GET_CODE (loc))
893 /* Don't do any sp or fp replacements outside of MEM addresses
895 if (amd->mem_mode == VOIDmode && amd->store)
897 if (loc == stack_pointer_rtx
898 && !frame_pointer_needed
900 return compute_cfa_pointer (amd->stack_adjust);
901 else if (loc == hard_frame_pointer_rtx
902 && frame_pointer_needed
903 && hard_frame_pointer_adjustment != -1
905 return compute_cfa_pointer (hard_frame_pointer_adjustment);
906 gcc_checking_assert (loc != virtual_incoming_args_rtx);
912 mem = targetm.delegitimize_address (mem);
913 if (mem != loc && !MEM_P (mem))
914 return simplify_replace_fn_rtx (mem, old_rtx, adjust_mems, data);
917 addr = XEXP (mem, 0);
918 mem_mode_save = amd->mem_mode;
919 amd->mem_mode = GET_MODE (mem);
920 store_save = amd->store;
922 addr = simplify_replace_fn_rtx (addr, old_rtx, adjust_mems, data);
923 amd->store = store_save;
924 amd->mem_mode = mem_mode_save;
926 addr = targetm.delegitimize_address (addr);
927 if (addr != XEXP (mem, 0))
928 mem = replace_equiv_address_nv (mem, addr);
930 mem = avoid_constant_pool_reference (mem);
934 addr = gen_rtx_PLUS (GET_MODE (loc), XEXP (loc, 0),
935 GEN_INT (GET_CODE (loc) == PRE_INC
936 ? GET_MODE_SIZE (amd->mem_mode)
937 : -GET_MODE_SIZE (amd->mem_mode)));
941 addr = XEXP (loc, 0);
942 gcc_assert (amd->mem_mode != VOIDmode && amd->mem_mode != BLKmode);
943 addr = simplify_replace_fn_rtx (addr, old_rtx, adjust_mems, data);
944 tem = gen_rtx_PLUS (GET_MODE (loc), XEXP (loc, 0),
945 GEN_INT ((GET_CODE (loc) == PRE_INC
946 || GET_CODE (loc) == POST_INC)
947 ? GET_MODE_SIZE (amd->mem_mode)
948 : -GET_MODE_SIZE (amd->mem_mode)));
949 amd->side_effects = alloc_EXPR_LIST (0,
950 gen_rtx_SET (VOIDmode,
956 addr = XEXP (loc, 1);
959 addr = XEXP (loc, 0);
960 gcc_assert (amd->mem_mode != VOIDmode);
961 addr = simplify_replace_fn_rtx (addr, old_rtx, adjust_mems, data);
962 amd->side_effects = alloc_EXPR_LIST (0,
963 gen_rtx_SET (VOIDmode,
969 /* First try without delegitimization of whole MEMs and
970 avoid_constant_pool_reference, which is more likely to succeed. */
971 store_save = amd->store;
973 addr = simplify_replace_fn_rtx (SUBREG_REG (loc), old_rtx, adjust_mems,
975 amd->store = store_save;
976 mem = simplify_replace_fn_rtx (addr, old_rtx, adjust_mems, data);
977 if (mem == SUBREG_REG (loc))
982 tem = simplify_gen_subreg (GET_MODE (loc), mem,
983 GET_MODE (SUBREG_REG (loc)),
987 tem = simplify_gen_subreg (GET_MODE (loc), addr,
988 GET_MODE (SUBREG_REG (loc)),
991 tem = gen_rtx_raw_SUBREG (GET_MODE (loc), addr, SUBREG_BYTE (loc));
993 if (MAY_HAVE_DEBUG_INSNS
994 && GET_CODE (tem) == SUBREG
995 && (GET_CODE (SUBREG_REG (tem)) == PLUS
996 || GET_CODE (SUBREG_REG (tem)) == MINUS
997 || GET_CODE (SUBREG_REG (tem)) == MULT
998 || GET_CODE (SUBREG_REG (tem)) == ASHIFT)
999 && GET_MODE_CLASS (GET_MODE (tem)) == MODE_INT
1000 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (tem))) == MODE_INT
1001 && GET_MODE_SIZE (GET_MODE (tem))
1002 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (tem)))
1003 && subreg_lowpart_p (tem)
1004 && !for_each_rtx (&SUBREG_REG (tem), use_narrower_mode_test, tem))
1005 return use_narrower_mode (SUBREG_REG (tem), GET_MODE (tem),
1006 GET_MODE (SUBREG_REG (tem)));
1009 /* Don't do any replacements in second and following
1010 ASM_OPERANDS of inline-asm with multiple sets.
1011 ASM_OPERANDS_INPUT_VEC, ASM_OPERANDS_INPUT_CONSTRAINT_VEC
1012 and ASM_OPERANDS_LABEL_VEC need to be equal between
1013 all the ASM_OPERANDs in the insn and adjust_insn will
1015 if (ASM_OPERANDS_OUTPUT_IDX (loc) != 0)
1024 /* Helper function for replacement of uses. */
1027 adjust_mem_uses (rtx *x, void *data)
1029 rtx new_x = simplify_replace_fn_rtx (*x, NULL_RTX, adjust_mems, data);
1031 validate_change (NULL_RTX, x, new_x, true);
1034 /* Helper function for replacement of stores. */
1037 adjust_mem_stores (rtx loc, const_rtx expr, void *data)
1041 rtx new_dest = simplify_replace_fn_rtx (SET_DEST (expr), NULL_RTX,
1043 if (new_dest != SET_DEST (expr))
1045 rtx xexpr = CONST_CAST_RTX (expr);
1046 validate_change (NULL_RTX, &SET_DEST (xexpr), new_dest, true);
1051 /* Simplify INSN. Remove all {PRE,POST}_{INC,DEC,MODIFY} rtxes,
1052 replace them with their value in the insn and add the side-effects
1053 as other sets to the insn. */
1056 adjust_insn (basic_block bb, rtx insn)
1058 struct adjust_mem_data amd;
1061 #ifdef HAVE_window_save
1062 /* If the target machine has an explicit window save instruction, the
1063 transformation OUTGOING_REGNO -> INCOMING_REGNO is done there. */
1064 if (RTX_FRAME_RELATED_P (insn)
1065 && find_reg_note (insn, REG_CFA_WINDOW_SAVE, NULL_RTX))
1067 unsigned int i, nregs = VEC_length(parm_reg_t, windowed_parm_regs);
1068 rtx rtl = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs * 2));
1071 FOR_EACH_VEC_ELT (parm_reg_t, windowed_parm_regs, i, p)
1073 XVECEXP (rtl, 0, i * 2)
1074 = gen_rtx_SET (VOIDmode, p->incoming, p->outgoing);
1075 /* Do not clobber the attached DECL, but only the REG. */
1076 XVECEXP (rtl, 0, i * 2 + 1)
1077 = gen_rtx_CLOBBER (GET_MODE (p->outgoing),
1078 gen_raw_REG (GET_MODE (p->outgoing),
1079 REGNO (p->outgoing)));
1082 validate_change (NULL_RTX, &PATTERN (insn), rtl, true);
1087 amd.mem_mode = VOIDmode;
1088 amd.stack_adjust = -VTI (bb)->out.stack_adjust;
1089 amd.side_effects = NULL_RTX;
1092 note_stores (PATTERN (insn), adjust_mem_stores, &amd);
1095 if (GET_CODE (PATTERN (insn)) == PARALLEL
1096 && asm_noperands (PATTERN (insn)) > 0
1097 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1102 /* inline-asm with multiple sets is tiny bit more complicated,
1103 because the 3 vectors in ASM_OPERANDS need to be shared between
1104 all ASM_OPERANDS in the instruction. adjust_mems will
1105 not touch ASM_OPERANDS other than the first one, asm_noperands
1106 test above needs to be called before that (otherwise it would fail)
1107 and afterwards this code fixes it up. */
1108 note_uses (&PATTERN (insn), adjust_mem_uses, &amd);
1109 body = PATTERN (insn);
1110 set0 = XVECEXP (body, 0, 0);
1111 gcc_checking_assert (GET_CODE (set0) == SET
1112 && GET_CODE (SET_SRC (set0)) == ASM_OPERANDS
1113 && ASM_OPERANDS_OUTPUT_IDX (SET_SRC (set0)) == 0);
1114 for (i = 1; i < XVECLEN (body, 0); i++)
1115 if (GET_CODE (XVECEXP (body, 0, i)) != SET)
1119 set = XVECEXP (body, 0, i);
1120 gcc_checking_assert (GET_CODE (SET_SRC (set)) == ASM_OPERANDS
1121 && ASM_OPERANDS_OUTPUT_IDX (SET_SRC (set))
1123 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (set))
1124 != ASM_OPERANDS_INPUT_VEC (SET_SRC (set0))
1125 || ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set))
1126 != ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set0))
1127 || ASM_OPERANDS_LABEL_VEC (SET_SRC (set))
1128 != ASM_OPERANDS_LABEL_VEC (SET_SRC (set0)))
1130 rtx newsrc = shallow_copy_rtx (SET_SRC (set));
1131 ASM_OPERANDS_INPUT_VEC (newsrc)
1132 = ASM_OPERANDS_INPUT_VEC (SET_SRC (set0));
1133 ASM_OPERANDS_INPUT_CONSTRAINT_VEC (newsrc)
1134 = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set0));
1135 ASM_OPERANDS_LABEL_VEC (newsrc)
1136 = ASM_OPERANDS_LABEL_VEC (SET_SRC (set0));
1137 validate_change (NULL_RTX, &SET_SRC (set), newsrc, true);
1142 note_uses (&PATTERN (insn), adjust_mem_uses, &amd);
1144 /* For read-only MEMs containing some constant, prefer those
1146 set = single_set (insn);
1147 if (set && MEM_P (SET_SRC (set)) && MEM_READONLY_P (SET_SRC (set)))
1149 rtx note = find_reg_equal_equiv_note (insn);
1151 if (note && CONSTANT_P (XEXP (note, 0)))
1152 validate_change (NULL_RTX, &SET_SRC (set), XEXP (note, 0), true);
1155 if (amd.side_effects)
1157 rtx *pat, new_pat, s;
1160 pat = &PATTERN (insn);
1161 if (GET_CODE (*pat) == COND_EXEC)
1162 pat = &COND_EXEC_CODE (*pat);
1163 if (GET_CODE (*pat) == PARALLEL)
1164 oldn = XVECLEN (*pat, 0);
1167 for (s = amd.side_effects, newn = 0; s; newn++)
1169 new_pat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (oldn + newn));
1170 if (GET_CODE (*pat) == PARALLEL)
1171 for (i = 0; i < oldn; i++)
1172 XVECEXP (new_pat, 0, i) = XVECEXP (*pat, 0, i);
1174 XVECEXP (new_pat, 0, 0) = *pat;
1175 for (s = amd.side_effects, i = oldn; i < oldn + newn; i++, s = XEXP (s, 1))
1176 XVECEXP (new_pat, 0, i) = XEXP (s, 0);
1177 free_EXPR_LIST_list (&amd.side_effects);
1178 validate_change (NULL_RTX, pat, new_pat, true);
1182 /* Return true if a decl_or_value DV is a DECL or NULL. */
1184 dv_is_decl_p (decl_or_value dv)
1186 return !dv || (int) TREE_CODE ((tree) dv) != (int) VALUE;
1189 /* Return true if a decl_or_value is a VALUE rtl. */
1191 dv_is_value_p (decl_or_value dv)
1193 return dv && !dv_is_decl_p (dv);
1196 /* Return the decl in the decl_or_value. */
1198 dv_as_decl (decl_or_value dv)
1200 gcc_checking_assert (dv_is_decl_p (dv));
1204 /* Return the value in the decl_or_value. */
1206 dv_as_value (decl_or_value dv)
1208 gcc_checking_assert (dv_is_value_p (dv));
1212 /* Return the DEBUG_EXPR of a DEBUG_EXPR_DECL or the VALUE in DV. */
1214 dv_as_rtx (decl_or_value dv)
1218 if (dv_is_value_p (dv))
1219 return dv_as_value (dv);
1221 decl = dv_as_decl (dv);
1223 gcc_checking_assert (TREE_CODE (decl) == DEBUG_EXPR_DECL);
1224 return DECL_RTL_KNOWN_SET (decl);
1227 /* Return the opaque pointer in the decl_or_value. */
1228 static inline void *
1229 dv_as_opaque (decl_or_value dv)
1234 /* Return nonzero if a decl_or_value must not have more than one
1235 variable part. The returned value discriminates among various
1236 kinds of one-part DVs ccording to enum onepart_enum. */
1237 static inline onepart_enum_t
1238 dv_onepart_p (decl_or_value dv)
1242 if (!MAY_HAVE_DEBUG_INSNS)
1245 if (dv_is_value_p (dv))
1246 return ONEPART_VALUE;
1248 decl = dv_as_decl (dv);
1250 if (TREE_CODE (decl) == DEBUG_EXPR_DECL)
1251 return ONEPART_DEXPR;
1253 if (target_for_debug_bind (decl) != NULL_TREE)
1254 return ONEPART_VDECL;
1259 /* Return the variable pool to be used for a dv of type ONEPART. */
1260 static inline alloc_pool
1261 onepart_pool (onepart_enum_t onepart)
1263 return onepart ? valvar_pool : var_pool;
1266 /* Build a decl_or_value out of a decl. */
1267 static inline decl_or_value
1268 dv_from_decl (tree decl)
1272 gcc_checking_assert (dv_is_decl_p (dv));
1276 /* Build a decl_or_value out of a value. */
1277 static inline decl_or_value
1278 dv_from_value (rtx value)
1282 gcc_checking_assert (dv_is_value_p (dv));
1286 /* Return a value or the decl of a debug_expr as a decl_or_value. */
1287 static inline decl_or_value
1292 switch (GET_CODE (x))
1295 dv = dv_from_decl (DEBUG_EXPR_TREE_DECL (x));
1296 gcc_checking_assert (DECL_RTL_KNOWN_SET (DEBUG_EXPR_TREE_DECL (x)) == x);
1300 dv = dv_from_value (x);
1310 extern void debug_dv (decl_or_value dv);
1313 debug_dv (decl_or_value dv)
1315 if (dv_is_value_p (dv))
1316 debug_rtx (dv_as_value (dv));
1318 debug_generic_stmt (dv_as_decl (dv));
1321 typedef unsigned int dvuid;
1323 /* Return the uid of DV. */
1326 dv_uid (decl_or_value dv)
1328 if (dv_is_value_p (dv))
1329 return CSELIB_VAL_PTR (dv_as_value (dv))->uid;
1331 return DECL_UID (dv_as_decl (dv));
1334 /* Compute the hash from the uid. */
1336 static inline hashval_t
1337 dv_uid2hash (dvuid uid)
1342 /* The hash function for a mask table in a shared_htab chain. */
1344 static inline hashval_t
1345 dv_htab_hash (decl_or_value dv)
1347 return dv_uid2hash (dv_uid (dv));
1350 /* The hash function for variable_htab, computes the hash value
1351 from the declaration of variable X. */
1354 variable_htab_hash (const void *x)
1356 const_variable const v = (const_variable) x;
1358 return dv_htab_hash (v->dv);
1361 /* Compare the declaration of variable X with declaration Y. */
1364 variable_htab_eq (const void *x, const void *y)
1366 const_variable const v = (const_variable) x;
1367 decl_or_value dv = CONST_CAST2 (decl_or_value, const void *, y);
1369 return (dv_as_opaque (v->dv) == dv_as_opaque (dv));
1372 static void loc_exp_dep_clear (variable var);
1374 /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
1377 variable_htab_free (void *elem)
1380 variable var = (variable) elem;
1381 location_chain node, next;
1383 gcc_checking_assert (var->refcount > 0);
1386 if (var->refcount > 0)
1389 for (i = 0; i < var->n_var_parts; i++)
1391 for (node = var->var_part[i].loc_chain; node; node = next)
1394 pool_free (loc_chain_pool, node);
1396 var->var_part[i].loc_chain = NULL;
1398 if (var->onepart && VAR_LOC_1PAUX (var))
1400 loc_exp_dep_clear (var);
1401 if (VAR_LOC_DEP_LST (var))
1402 VAR_LOC_DEP_LST (var)->pprev = NULL;
1403 XDELETE (VAR_LOC_1PAUX (var));
1404 /* These may be reused across functions, so reset
1406 if (var->onepart == ONEPART_DEXPR)
1407 set_dv_changed (var->dv, true);
1409 pool_free (onepart_pool (var->onepart), var);
1412 /* Initialize the set (array) SET of attrs to empty lists. */
1415 init_attrs_list_set (attrs *set)
1419 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1423 /* Make the list *LISTP empty. */
1426 attrs_list_clear (attrs *listp)
1430 for (list = *listp; list; list = next)
1433 pool_free (attrs_pool, list);
1438 /* Return true if the pair of DECL and OFFSET is the member of the LIST. */
1441 attrs_list_member (attrs list, decl_or_value dv, HOST_WIDE_INT offset)
1443 for (; list; list = list->next)
1444 if (dv_as_opaque (list->dv) == dv_as_opaque (dv) && list->offset == offset)
1449 /* Insert the triplet DECL, OFFSET, LOC to the list *LISTP. */
1452 attrs_list_insert (attrs *listp, decl_or_value dv,
1453 HOST_WIDE_INT offset, rtx loc)
1457 list = (attrs) pool_alloc (attrs_pool);
1460 list->offset = offset;
1461 list->next = *listp;
1465 /* Copy all nodes from SRC and create a list *DSTP of the copies. */
1468 attrs_list_copy (attrs *dstp, attrs src)
1472 attrs_list_clear (dstp);
1473 for (; src; src = src->next)
1475 n = (attrs) pool_alloc (attrs_pool);
1478 n->offset = src->offset;
1484 /* Add all nodes from SRC which are not in *DSTP to *DSTP. */
1487 attrs_list_union (attrs *dstp, attrs src)
1489 for (; src; src = src->next)
1491 if (!attrs_list_member (*dstp, src->dv, src->offset))
1492 attrs_list_insert (dstp, src->dv, src->offset, src->loc);
1496 /* Combine nodes that are not onepart nodes from SRC and SRC2 into
1500 attrs_list_mpdv_union (attrs *dstp, attrs src, attrs src2)
1502 gcc_assert (!*dstp);
1503 for (; src; src = src->next)
1505 if (!dv_onepart_p (src->dv))
1506 attrs_list_insert (dstp, src->dv, src->offset, src->loc);
1508 for (src = src2; src; src = src->next)
1510 if (!dv_onepart_p (src->dv)
1511 && !attrs_list_member (*dstp, src->dv, src->offset))
1512 attrs_list_insert (dstp, src->dv, src->offset, src->loc);
1516 /* Shared hashtable support. */
1518 /* Return true if VARS is shared. */
1521 shared_hash_shared (shared_hash vars)
1523 return vars->refcount > 1;
1526 /* Return the hash table for VARS. */
1528 static inline htab_t
1529 shared_hash_htab (shared_hash vars)
1534 /* Return true if VAR is shared, or maybe because VARS is shared. */
1537 shared_var_p (variable var, shared_hash vars)
1539 /* Don't count an entry in the changed_variables table as a duplicate. */
1540 return ((var->refcount > 1 + (int) var->in_changed_variables)
1541 || shared_hash_shared (vars));
1544 /* Copy variables into a new hash table. */
1547 shared_hash_unshare (shared_hash vars)
1549 shared_hash new_vars = (shared_hash) pool_alloc (shared_hash_pool);
1550 gcc_assert (vars->refcount > 1);
1551 new_vars->refcount = 1;
1553 = htab_create (htab_elements (vars->htab) + 3, variable_htab_hash,
1554 variable_htab_eq, variable_htab_free);
1555 vars_copy (new_vars->htab, vars->htab);
1560 /* Increment reference counter on VARS and return it. */
1562 static inline shared_hash
1563 shared_hash_copy (shared_hash vars)
1569 /* Decrement reference counter and destroy hash table if not shared
1573 shared_hash_destroy (shared_hash vars)
1575 gcc_checking_assert (vars->refcount > 0);
1576 if (--vars->refcount == 0)
1578 htab_delete (vars->htab);
1579 pool_free (shared_hash_pool, vars);
1583 /* Unshare *PVARS if shared and return slot for DV. If INS is
1584 INSERT, insert it if not already present. */
1586 static inline void **
1587 shared_hash_find_slot_unshare_1 (shared_hash *pvars, decl_or_value dv,
1588 hashval_t dvhash, enum insert_option ins)
1590 if (shared_hash_shared (*pvars))
1591 *pvars = shared_hash_unshare (*pvars);
1592 return htab_find_slot_with_hash (shared_hash_htab (*pvars), dv, dvhash, ins);
1595 static inline void **
1596 shared_hash_find_slot_unshare (shared_hash *pvars, decl_or_value dv,
1597 enum insert_option ins)
1599 return shared_hash_find_slot_unshare_1 (pvars, dv, dv_htab_hash (dv), ins);
1602 /* Return slot for DV, if it is already present in the hash table.
1603 If it is not present, insert it only VARS is not shared, otherwise
1606 static inline void **
1607 shared_hash_find_slot_1 (shared_hash vars, decl_or_value dv, hashval_t dvhash)
1609 return htab_find_slot_with_hash (shared_hash_htab (vars), dv, dvhash,
1610 shared_hash_shared (vars)
1611 ? NO_INSERT : INSERT);
1614 static inline void **
1615 shared_hash_find_slot (shared_hash vars, decl_or_value dv)
1617 return shared_hash_find_slot_1 (vars, dv, dv_htab_hash (dv));
1620 /* Return slot for DV only if it is already present in the hash table. */
1622 static inline void **
1623 shared_hash_find_slot_noinsert_1 (shared_hash vars, decl_or_value dv,
1626 return htab_find_slot_with_hash (shared_hash_htab (vars), dv, dvhash,
1630 static inline void **
1631 shared_hash_find_slot_noinsert (shared_hash vars, decl_or_value dv)
1633 return shared_hash_find_slot_noinsert_1 (vars, dv, dv_htab_hash (dv));
1636 /* Return variable for DV or NULL if not already present in the hash
1639 static inline variable
1640 shared_hash_find_1 (shared_hash vars, decl_or_value dv, hashval_t dvhash)
1642 return (variable) htab_find_with_hash (shared_hash_htab (vars), dv, dvhash);
1645 static inline variable
1646 shared_hash_find (shared_hash vars, decl_or_value dv)
1648 return shared_hash_find_1 (vars, dv, dv_htab_hash (dv));
1651 /* Return true if TVAL is better than CVAL as a canonival value. We
1652 choose lowest-numbered VALUEs, using the RTX address as a
1653 tie-breaker. The idea is to arrange them into a star topology,
1654 such that all of them are at most one step away from the canonical
1655 value, and the canonical value has backlinks to all of them, in
1656 addition to all the actual locations. We don't enforce this
1657 topology throughout the entire dataflow analysis, though.
1661 canon_value_cmp (rtx tval, rtx cval)
1664 || CSELIB_VAL_PTR (tval)->uid < CSELIB_VAL_PTR (cval)->uid;
1667 static bool dst_can_be_shared;
1669 /* Return a copy of a variable VAR and insert it to dataflow set SET. */
1672 unshare_variable (dataflow_set *set, void **slot, variable var,
1673 enum var_init_status initialized)
1678 new_var = (variable) pool_alloc (onepart_pool (var->onepart));
1679 new_var->dv = var->dv;
1680 new_var->refcount = 1;
1682 new_var->n_var_parts = var->n_var_parts;
1683 new_var->onepart = var->onepart;
1684 new_var->in_changed_variables = false;
1686 if (! flag_var_tracking_uninit)
1687 initialized = VAR_INIT_STATUS_INITIALIZED;
1689 for (i = 0; i < var->n_var_parts; i++)
1691 location_chain node;
1692 location_chain *nextp;
1694 if (i == 0 && var->onepart)
1696 /* One-part auxiliary data is only used while emitting
1697 notes, so propagate it to the new variable in the active
1698 dataflow set. If we're not emitting notes, this will be
1700 gcc_checking_assert (!VAR_LOC_1PAUX (var) || emit_notes);
1701 VAR_LOC_1PAUX (new_var) = VAR_LOC_1PAUX (var);
1702 VAR_LOC_1PAUX (var) = NULL;
1705 VAR_PART_OFFSET (new_var, i) = VAR_PART_OFFSET (var, i);
1706 nextp = &new_var->var_part[i].loc_chain;
1707 for (node = var->var_part[i].loc_chain; node; node = node->next)
1709 location_chain new_lc;
1711 new_lc = (location_chain) pool_alloc (loc_chain_pool);
1712 new_lc->next = NULL;
1713 if (node->init > initialized)
1714 new_lc->init = node->init;
1716 new_lc->init = initialized;
1717 if (node->set_src && !(MEM_P (node->set_src)))
1718 new_lc->set_src = node->set_src;
1720 new_lc->set_src = NULL;
1721 new_lc->loc = node->loc;
1724 nextp = &new_lc->next;
1727 new_var->var_part[i].cur_loc = var->var_part[i].cur_loc;
1730 dst_can_be_shared = false;
1731 if (shared_hash_shared (set->vars))
1732 slot = shared_hash_find_slot_unshare (&set->vars, var->dv, NO_INSERT);
1733 else if (set->traversed_vars && set->vars != set->traversed_vars)
1734 slot = shared_hash_find_slot_noinsert (set->vars, var->dv);
1736 if (var->in_changed_variables)
1739 = htab_find_slot_with_hash (changed_variables, var->dv,
1740 dv_htab_hash (var->dv), NO_INSERT);
1741 gcc_assert (*cslot == (void *) var);
1742 var->in_changed_variables = false;
1743 variable_htab_free (var);
1745 new_var->in_changed_variables = true;
1750 /* Copy all variables from hash table SRC to hash table DST. */
1753 vars_copy (htab_t dst, htab_t src)
1758 FOR_EACH_HTAB_ELEMENT (src, var, variable, hi)
1762 dstp = htab_find_slot_with_hash (dst, var->dv,
1763 dv_htab_hash (var->dv),
1769 /* Map a decl to its main debug decl. */
1772 var_debug_decl (tree decl)
1774 if (decl && DECL_P (decl)
1775 && DECL_DEBUG_EXPR_IS_FROM (decl))
1777 tree debugdecl = DECL_DEBUG_EXPR (decl);
1778 if (debugdecl && DECL_P (debugdecl))
1785 /* Set the register LOC to contain DV, OFFSET. */
1788 var_reg_decl_set (dataflow_set *set, rtx loc, enum var_init_status initialized,
1789 decl_or_value dv, HOST_WIDE_INT offset, rtx set_src,
1790 enum insert_option iopt)
1793 bool decl_p = dv_is_decl_p (dv);
1796 dv = dv_from_decl (var_debug_decl (dv_as_decl (dv)));
1798 for (node = set->regs[REGNO (loc)]; node; node = node->next)
1799 if (dv_as_opaque (node->dv) == dv_as_opaque (dv)
1800 && node->offset == offset)
1803 attrs_list_insert (&set->regs[REGNO (loc)], dv, offset, loc);
1804 set_variable_part (set, loc, dv, offset, initialized, set_src, iopt);
1807 /* Set the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). */
1810 var_reg_set (dataflow_set *set, rtx loc, enum var_init_status initialized,
1813 tree decl = REG_EXPR (loc);
1814 HOST_WIDE_INT offset = REG_OFFSET (loc);
1816 var_reg_decl_set (set, loc, initialized,
1817 dv_from_decl (decl), offset, set_src, INSERT);
1820 static enum var_init_status
1821 get_init_value (dataflow_set *set, rtx loc, decl_or_value dv)
1825 enum var_init_status ret_val = VAR_INIT_STATUS_UNKNOWN;
1827 if (! flag_var_tracking_uninit)
1828 return VAR_INIT_STATUS_INITIALIZED;
1830 var = shared_hash_find (set->vars, dv);
1833 for (i = 0; i < var->n_var_parts && ret_val == VAR_INIT_STATUS_UNKNOWN; i++)
1835 location_chain nextp;
1836 for (nextp = var->var_part[i].loc_chain; nextp; nextp = nextp->next)
1837 if (rtx_equal_p (nextp->loc, loc))
1839 ret_val = nextp->init;
1848 /* Delete current content of register LOC in dataflow set SET and set
1849 the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). If
1850 MODIFY is true, any other live copies of the same variable part are
1851 also deleted from the dataflow set, otherwise the variable part is
1852 assumed to be copied from another location holding the same
1856 var_reg_delete_and_set (dataflow_set *set, rtx loc, bool modify,
1857 enum var_init_status initialized, rtx set_src)
1859 tree decl = REG_EXPR (loc);
1860 HOST_WIDE_INT offset = REG_OFFSET (loc);
1864 decl = var_debug_decl (decl);
1866 if (initialized == VAR_INIT_STATUS_UNKNOWN)
1867 initialized = get_init_value (set, loc, dv_from_decl (decl));
1869 nextp = &set->regs[REGNO (loc)];
1870 for (node = *nextp; node; node = next)
1873 if (dv_as_opaque (node->dv) != decl || node->offset != offset)
1875 delete_variable_part (set, node->loc, node->dv, node->offset);
1876 pool_free (attrs_pool, node);
1882 nextp = &node->next;
1886 clobber_variable_part (set, loc, dv_from_decl (decl), offset, set_src);
1887 var_reg_set (set, loc, initialized, set_src);
1890 /* Delete the association of register LOC in dataflow set SET with any
1891 variables that aren't onepart. If CLOBBER is true, also delete any
1892 other live copies of the same variable part, and delete the
1893 association with onepart dvs too. */
1896 var_reg_delete (dataflow_set *set, rtx loc, bool clobber)
1898 attrs *nextp = &set->regs[REGNO (loc)];
1903 tree decl = REG_EXPR (loc);
1904 HOST_WIDE_INT offset = REG_OFFSET (loc);
1906 decl = var_debug_decl (decl);
1908 clobber_variable_part (set, NULL, dv_from_decl (decl), offset, NULL);
1911 for (node = *nextp; node; node = next)
1914 if (clobber || !dv_onepart_p (node->dv))
1916 delete_variable_part (set, node->loc, node->dv, node->offset);
1917 pool_free (attrs_pool, node);
1921 nextp = &node->next;
1925 /* Delete content of register with number REGNO in dataflow set SET. */
1928 var_regno_delete (dataflow_set *set, int regno)
1930 attrs *reg = &set->regs[regno];
1933 for (node = *reg; node; node = next)
1936 delete_variable_part (set, node->loc, node->dv, node->offset);
1937 pool_free (attrs_pool, node);
1942 /* Set the location of DV, OFFSET as the MEM LOC. */
1945 var_mem_decl_set (dataflow_set *set, rtx loc, enum var_init_status initialized,
1946 decl_or_value dv, HOST_WIDE_INT offset, rtx set_src,
1947 enum insert_option iopt)
1949 if (dv_is_decl_p (dv))
1950 dv = dv_from_decl (var_debug_decl (dv_as_decl (dv)));
1952 set_variable_part (set, loc, dv, offset, initialized, set_src, iopt);
1955 /* Set the location part of variable MEM_EXPR (LOC) in dataflow set
1957 Adjust the address first if it is stack pointer based. */
1960 var_mem_set (dataflow_set *set, rtx loc, enum var_init_status initialized,
1963 tree decl = MEM_EXPR (loc);
1964 HOST_WIDE_INT offset = INT_MEM_OFFSET (loc);
1966 var_mem_decl_set (set, loc, initialized,
1967 dv_from_decl (decl), offset, set_src, INSERT);
1970 /* Delete and set the location part of variable MEM_EXPR (LOC) in
1971 dataflow set SET to LOC. If MODIFY is true, any other live copies
1972 of the same variable part are also deleted from the dataflow set,
1973 otherwise the variable part is assumed to be copied from another
1974 location holding the same part.
1975 Adjust the address first if it is stack pointer based. */
1978 var_mem_delete_and_set (dataflow_set *set, rtx loc, bool modify,
1979 enum var_init_status initialized, rtx set_src)
1981 tree decl = MEM_EXPR (loc);
1982 HOST_WIDE_INT offset = INT_MEM_OFFSET (loc);
1984 decl = var_debug_decl (decl);
1986 if (initialized == VAR_INIT_STATUS_UNKNOWN)
1987 initialized = get_init_value (set, loc, dv_from_decl (decl));
1990 clobber_variable_part (set, NULL, dv_from_decl (decl), offset, set_src);
1991 var_mem_set (set, loc, initialized, set_src);
1994 /* Delete the location part LOC from dataflow set SET. If CLOBBER is
1995 true, also delete any other live copies of the same variable part.
1996 Adjust the address first if it is stack pointer based. */
1999 var_mem_delete (dataflow_set *set, rtx loc, bool clobber)
2001 tree decl = MEM_EXPR (loc);
2002 HOST_WIDE_INT offset = INT_MEM_OFFSET (loc);
2004 decl = var_debug_decl (decl);
2006 clobber_variable_part (set, NULL, dv_from_decl (decl), offset, NULL);
2007 delete_variable_part (set, loc, dv_from_decl (decl), offset);
2010 /* Return true if LOC should not be expanded for location expressions,
2014 unsuitable_loc (rtx loc)
2016 switch (GET_CODE (loc))
2030 /* Bind a value to a location it was just stored in. If MODIFIED
2031 holds, assume the location was modified, detaching it from any
2032 values bound to it. */
2035 val_store (dataflow_set *set, rtx val, rtx loc, rtx insn, bool modified)
2037 cselib_val *v = CSELIB_VAL_PTR (val);
2039 gcc_assert (cselib_preserved_value_p (v));
2043 fprintf (dump_file, "%i: ", insn ? INSN_UID (insn) : 0);
2044 print_inline_rtx (dump_file, loc, 0);
2045 fprintf (dump_file, " evaluates to ");
2046 print_inline_rtx (dump_file, val, 0);
2049 struct elt_loc_list *l;
2050 for (l = v->locs; l; l = l->next)
2052 fprintf (dump_file, "\n%i: ", INSN_UID (l->setting_insn));
2053 print_inline_rtx (dump_file, l->loc, 0);
2056 fprintf (dump_file, "\n");
2059 gcc_checking_assert (!unsuitable_loc (loc));
2064 var_regno_delete (set, REGNO (loc));
2065 var_reg_decl_set (set, loc, VAR_INIT_STATUS_INITIALIZED,
2066 dv_from_value (val), 0, NULL_RTX, INSERT);
2068 else if (MEM_P (loc))
2069 var_mem_decl_set (set, loc, VAR_INIT_STATUS_INITIALIZED,
2070 dv_from_value (val), 0, NULL_RTX, INSERT);
2072 /* ??? Ideally we wouldn't get these, and use them from the static
2074 set_variable_part (set, loc, dv_from_value (val), 0,
2075 VAR_INIT_STATUS_INITIALIZED, NULL_RTX, INSERT);
2078 /* Reset this node, detaching all its equivalences. Return the slot
2079 in the variable hash table that holds dv, if there is one. */
2082 val_reset (dataflow_set *set, decl_or_value dv)
2084 variable var = shared_hash_find (set->vars, dv) ;
2085 location_chain node;
2088 if (!var || !var->n_var_parts)
2091 gcc_assert (var->n_var_parts == 1);
2094 for (node = var->var_part[0].loc_chain; node; node = node->next)
2095 if (GET_CODE (node->loc) == VALUE
2096 && canon_value_cmp (node->loc, cval))
2099 for (node = var->var_part[0].loc_chain; node; node = node->next)
2100 if (GET_CODE (node->loc) == VALUE && cval != node->loc)
2102 /* Redirect the equivalence link to the new canonical
2103 value, or simply remove it if it would point at
2106 set_variable_part (set, cval, dv_from_value (node->loc),
2107 0, node->init, node->set_src, NO_INSERT);
2108 delete_variable_part (set, dv_as_value (dv),
2109 dv_from_value (node->loc), 0);
2114 decl_or_value cdv = dv_from_value (cval);
2116 /* Keep the remaining values connected, accummulating links
2117 in the canonical value. */
2118 for (node = var->var_part[0].loc_chain; node; node = node->next)
2120 if (node->loc == cval)
2122 else if (GET_CODE (node->loc) == REG)
2123 var_reg_decl_set (set, node->loc, node->init, cdv, 0,
2124 node->set_src, NO_INSERT);
2125 else if (GET_CODE (node->loc) == MEM)
2126 var_mem_decl_set (set, node->loc, node->init, cdv, 0,
2127 node->set_src, NO_INSERT);
2129 set_variable_part (set, node->loc, cdv, 0,
2130 node->init, node->set_src, NO_INSERT);
2134 /* We remove this last, to make sure that the canonical value is not
2135 removed to the point of requiring reinsertion. */
2137 delete_variable_part (set, dv_as_value (dv), dv_from_value (cval), 0);
2139 clobber_variable_part (set, NULL, dv, 0, NULL);
2142 /* Find the values in a given location and map the val to another
2143 value, if it is unique, or add the location as one holding the
2147 val_resolve (dataflow_set *set, rtx val, rtx loc, rtx insn)
2149 decl_or_value dv = dv_from_value (val);
2151 if (dump_file && (dump_flags & TDF_DETAILS))
2154 fprintf (dump_file, "%i: ", INSN_UID (insn));
2156 fprintf (dump_file, "head: ");
2157 print_inline_rtx (dump_file, val, 0);
2158 fputs (" is at ", dump_file);
2159 print_inline_rtx (dump_file, loc, 0);
2160 fputc ('\n', dump_file);
2163 val_reset (set, dv);
2165 gcc_checking_assert (!unsuitable_loc (loc));
2169 attrs node, found = NULL;
2171 for (node = set->regs[REGNO (loc)]; node; node = node->next)
2172 if (dv_is_value_p (node->dv)
2173 && GET_MODE (dv_as_value (node->dv)) == GET_MODE (loc))
2177 /* Map incoming equivalences. ??? Wouldn't it be nice if
2178 we just started sharing the location lists? Maybe a
2179 circular list ending at the value itself or some
2181 set_variable_part (set, dv_as_value (node->dv),
2182 dv_from_value (val), node->offset,
2183 VAR_INIT_STATUS_INITIALIZED, NULL_RTX, INSERT);
2184 set_variable_part (set, val, node->dv, node->offset,
2185 VAR_INIT_STATUS_INITIALIZED, NULL_RTX, INSERT);
2188 /* If we didn't find any equivalence, we need to remember that
2189 this value is held in the named register. */
2191 var_reg_decl_set (set, loc, VAR_INIT_STATUS_INITIALIZED,
2192 dv_from_value (val), 0, NULL_RTX, INSERT);
2194 else if (MEM_P (loc))
2195 /* ??? Merge equivalent MEMs. */
2196 var_mem_decl_set (set, loc, VAR_INIT_STATUS_INITIALIZED,
2197 dv_from_value (val), 0, NULL_RTX, INSERT);
2199 /* ??? Ideally we wouldn't get these, and use them from the static
2201 /* ??? Merge equivalent expressions. */
2202 set_variable_part (set, loc, dv_from_value (val), 0,
2203 VAR_INIT_STATUS_INITIALIZED, NULL_RTX, INSERT);
2206 /* Initialize dataflow set SET to be empty.
2207 VARS_SIZE is the initial size of hash table VARS. */
2210 dataflow_set_init (dataflow_set *set)
2212 init_attrs_list_set (set->regs);
2213 set->vars = shared_hash_copy (empty_shared_hash);
2214 set->stack_adjust = 0;
2215 set->traversed_vars = NULL;
2218 /* Delete the contents of dataflow set SET. */
2221 dataflow_set_clear (dataflow_set *set)
2225 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2226 attrs_list_clear (&set->regs[i]);
2228 shared_hash_destroy (set->vars);
2229 set->vars = shared_hash_copy (empty_shared_hash);
2232 /* Copy the contents of dataflow set SRC to DST. */
2235 dataflow_set_copy (dataflow_set *dst, dataflow_set *src)
2239 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2240 attrs_list_copy (&dst->regs[i], src->regs[i]);
2242 shared_hash_destroy (dst->vars);
2243 dst->vars = shared_hash_copy (src->vars);
2244 dst->stack_adjust = src->stack_adjust;
2247 /* Information for merging lists of locations for a given offset of variable.
2249 struct variable_union_info
2251 /* Node of the location chain. */
2254 /* The sum of positions in the input chains. */
2257 /* The position in the chain of DST dataflow set. */
2261 /* Buffer for location list sorting and its allocated size. */
2262 static struct variable_union_info *vui_vec;
2263 static int vui_allocated;
2265 /* Compare function for qsort, order the structures by POS element. */
2268 variable_union_info_cmp_pos (const void *n1, const void *n2)
2270 const struct variable_union_info *const i1 =
2271 (const struct variable_union_info *) n1;
2272 const struct variable_union_info *const i2 =
2273 ( const struct variable_union_info *) n2;
2275 if (i1->pos != i2->pos)
2276 return i1->pos - i2->pos;
2278 return (i1->pos_dst - i2->pos_dst);
2281 /* Compute union of location parts of variable *SLOT and the same variable
2282 from hash table DATA. Compute "sorted" union of the location chains
2283 for common offsets, i.e. the locations of a variable part are sorted by
2284 a priority where the priority is the sum of the positions in the 2 chains
2285 (if a location is only in one list the position in the second list is
2286 defined to be larger than the length of the chains).
2287 When we are updating the location parts the newest location is in the
2288 beginning of the chain, so when we do the described "sorted" union
2289 we keep the newest locations in the beginning. */
2292 variable_union (variable src, dataflow_set *set)
2298 dstp = shared_hash_find_slot (set->vars, src->dv);
2299 if (!dstp || !*dstp)
2303 dst_can_be_shared = false;
2305 dstp = shared_hash_find_slot_unshare (&set->vars, src->dv, INSERT);
2309 /* Continue traversing the hash table. */
2313 dst = (variable) *dstp;
2315 gcc_assert (src->n_var_parts);
2316 gcc_checking_assert (src->onepart == dst->onepart);
2318 /* We can combine one-part variables very efficiently, because their
2319 entries are in canonical order. */
2322 location_chain *nodep, dnode, snode;
2324 gcc_assert (src->n_var_parts == 1
2325 && dst->n_var_parts == 1);
2327 snode = src->var_part[0].loc_chain;
2330 restart_onepart_unshared:
2331 nodep = &dst->var_part[0].loc_chain;
2337 int r = dnode ? loc_cmp (dnode->loc, snode->loc) : 1;
2341 location_chain nnode;
2343 if (shared_var_p (dst, set->vars))
2345 dstp = unshare_variable (set, dstp, dst,
2346 VAR_INIT_STATUS_INITIALIZED);
2347 dst = (variable)*dstp;
2348 goto restart_onepart_unshared;
2351 *nodep = nnode = (location_chain) pool_alloc (loc_chain_pool);
2352 nnode->loc = snode->loc;
2353 nnode->init = snode->init;
2354 if (!snode->set_src || MEM_P (snode->set_src))
2355 nnode->set_src = NULL;
2357 nnode->set_src = snode->set_src;
2358 nnode->next = dnode;
2362 gcc_checking_assert (rtx_equal_p (dnode->loc, snode->loc));
2365 snode = snode->next;
2367 nodep = &dnode->next;
2374 gcc_checking_assert (!src->onepart);
2376 /* Count the number of location parts, result is K. */
2377 for (i = 0, j = 0, k = 0;
2378 i < src->n_var_parts && j < dst->n_var_parts; k++)
2380 if (VAR_PART_OFFSET (src, i) == VAR_PART_OFFSET (dst, j))
2385 else if (VAR_PART_OFFSET (src, i) < VAR_PART_OFFSET (dst, j))
2390 k += src->n_var_parts - i;
2391 k += dst->n_var_parts - j;
2393 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
2394 thus there are at most MAX_VAR_PARTS different offsets. */
2395 gcc_checking_assert (dst->onepart ? k == 1 : k <= MAX_VAR_PARTS);
2397 if (dst->n_var_parts != k && shared_var_p (dst, set->vars))
2399 dstp = unshare_variable (set, dstp, dst, VAR_INIT_STATUS_UNKNOWN);
2400 dst = (variable)*dstp;
2403 i = src->n_var_parts - 1;
2404 j = dst->n_var_parts - 1;
2405 dst->n_var_parts = k;
2407 for (k--; k >= 0; k--)
2409 location_chain node, node2;
2411 if (i >= 0 && j >= 0
2412 && VAR_PART_OFFSET (src, i) == VAR_PART_OFFSET (dst, j))
2414 /* Compute the "sorted" union of the chains, i.e. the locations which
2415 are in both chains go first, they are sorted by the sum of
2416 positions in the chains. */
2419 struct variable_union_info *vui;
2421 /* If DST is shared compare the location chains.
2422 If they are different we will modify the chain in DST with
2423 high probability so make a copy of DST. */
2424 if (shared_var_p (dst, set->vars))
2426 for (node = src->var_part[i].loc_chain,
2427 node2 = dst->var_part[j].loc_chain; node && node2;
2428 node = node->next, node2 = node2->next)
2430 if (!((REG_P (node2->loc)
2431 && REG_P (node->loc)
2432 && REGNO (node2->loc) == REGNO (node->loc))
2433 || rtx_equal_p (node2->loc, node->loc)))
2435 if (node2->init < node->init)
2436 node2->init = node->init;
2442 dstp = unshare_variable (set, dstp, dst,
2443 VAR_INIT_STATUS_UNKNOWN);
2444 dst = (variable)*dstp;
2449 for (node = src->var_part[i].loc_chain; node; node = node->next)
2452 for (node = dst->var_part[j].loc_chain; node; node = node->next)
2457 /* The most common case, much simpler, no qsort is needed. */
2458 location_chain dstnode = dst->var_part[j].loc_chain;
2459 dst->var_part[k].loc_chain = dstnode;
2460 VAR_PART_OFFSET (dst, k) = VAR_PART_OFFSET(dst, j);
2462 for (node = src->var_part[i].loc_chain; node; node = node->next)
2463 if (!((REG_P (dstnode->loc)
2464 && REG_P (node->loc)
2465 && REGNO (dstnode->loc) == REGNO (node->loc))
2466 || rtx_equal_p (dstnode->loc, node->loc)))
2468 location_chain new_node;
2470 /* Copy the location from SRC. */
2471 new_node = (location_chain) pool_alloc (loc_chain_pool);
2472 new_node->loc = node->loc;
2473 new_node->init = node->init;
2474 if (!node->set_src || MEM_P (node->set_src))
2475 new_node->set_src = NULL;
2477 new_node->set_src = node->set_src;
2478 node2->next = new_node;
2485 if (src_l + dst_l > vui_allocated)
2487 vui_allocated = MAX (vui_allocated * 2, src_l + dst_l);
2488 vui_vec = XRESIZEVEC (struct variable_union_info, vui_vec,
2493 /* Fill in the locations from DST. */
2494 for (node = dst->var_part[j].loc_chain, jj = 0; node;
2495 node = node->next, jj++)
2498 vui[jj].pos_dst = jj;
2500 /* Pos plus value larger than a sum of 2 valid positions. */
2501 vui[jj].pos = jj + src_l + dst_l;
2504 /* Fill in the locations from SRC. */
2506 for (node = src->var_part[i].loc_chain, ii = 0; node;
2507 node = node->next, ii++)
2509 /* Find location from NODE. */
2510 for (jj = 0; jj < dst_l; jj++)
2512 if ((REG_P (vui[jj].lc->loc)
2513 && REG_P (node->loc)
2514 && REGNO (vui[jj].lc->loc) == REGNO (node->loc))
2515 || rtx_equal_p (vui[jj].lc->loc, node->loc))
2517 vui[jj].pos = jj + ii;
2521 if (jj >= dst_l) /* The location has not been found. */
2523 location_chain new_node;
2525 /* Copy the location from SRC. */
2526 new_node = (location_chain) pool_alloc (loc_chain_pool);
2527 new_node->loc = node->loc;
2528 new_node->init = node->init;
2529 if (!node->set_src || MEM_P (node->set_src))
2530 new_node->set_src = NULL;
2532 new_node->set_src = node->set_src;
2533 vui[n].lc = new_node;
2534 vui[n].pos_dst = src_l + dst_l;
2535 vui[n].pos = ii + src_l + dst_l;
2542 /* Special case still very common case. For dst_l == 2
2543 all entries dst_l ... n-1 are sorted, with for i >= dst_l
2544 vui[i].pos == i + src_l + dst_l. */
2545 if (vui[0].pos > vui[1].pos)
2547 /* Order should be 1, 0, 2... */
2548 dst->var_part[k].loc_chain = vui[1].lc;
2549 vui[1].lc->next = vui[0].lc;
2552 vui[0].lc->next = vui[2].lc;
2553 vui[n - 1].lc->next = NULL;
2556 vui[0].lc->next = NULL;
2561 dst->var_part[k].loc_chain = vui[0].lc;
2562 if (n >= 3 && vui[2].pos < vui[1].pos)
2564 /* Order should be 0, 2, 1, 3... */
2565 vui[0].lc->next = vui[2].lc;
2566 vui[2].lc->next = vui[1].lc;
2569 vui[1].lc->next = vui[3].lc;
2570 vui[n - 1].lc->next = NULL;
2573 vui[1].lc->next = NULL;
2578 /* Order should be 0, 1, 2... */
2580 vui[n - 1].lc->next = NULL;
2583 for (; ii < n; ii++)
2584 vui[ii - 1].lc->next = vui[ii].lc;
2588 qsort (vui, n, sizeof (struct variable_union_info),
2589 variable_union_info_cmp_pos);
2591 /* Reconnect the nodes in sorted order. */
2592 for (ii = 1; ii < n; ii++)
2593 vui[ii - 1].lc->next = vui[ii].lc;
2594 vui[n - 1].lc->next = NULL;
2595 dst->var_part[k].loc_chain = vui[0].lc;
2598 VAR_PART_OFFSET (dst, k) = VAR_PART_OFFSET (dst, j);
2603 else if ((i >= 0 && j >= 0
2604 && VAR_PART_OFFSET (src, i) < VAR_PART_OFFSET (dst, j))
2607 dst->var_part[k] = dst->var_part[j];
2610 else if ((i >= 0 && j >= 0
2611 && VAR_PART_OFFSET (src, i) > VAR_PART_OFFSET (dst, j))
2614 location_chain *nextp;
2616 /* Copy the chain from SRC. */
2617 nextp = &dst->var_part[k].loc_chain;
2618 for (node = src->var_part[i].loc_chain; node; node = node->next)
2620 location_chain new_lc;
2622 new_lc = (location_chain) pool_alloc (loc_chain_pool);
2623 new_lc->next = NULL;
2624 new_lc->init = node->init;
2625 if (!node->set_src || MEM_P (node->set_src))
2626 new_lc->set_src = NULL;
2628 new_lc->set_src = node->set_src;
2629 new_lc->loc = node->loc;
2632 nextp = &new_lc->next;
2635 VAR_PART_OFFSET (dst, k) = VAR_PART_OFFSET (src, i);
2638 dst->var_part[k].cur_loc = NULL;
2641 if (flag_var_tracking_uninit)
2642 for (i = 0; i < src->n_var_parts && i < dst->n_var_parts; i++)
2644 location_chain node, node2;
2645 for (node = src->var_part[i].loc_chain; node; node = node->next)
2646 for (node2 = dst->var_part[i].loc_chain; node2; node2 = node2->next)
2647 if (rtx_equal_p (node->loc, node2->loc))
2649 if (node->init > node2->init)
2650 node2->init = node->init;
2654 /* Continue traversing the hash table. */
2658 /* Compute union of dataflow sets SRC and DST and store it to DST. */
2661 dataflow_set_union (dataflow_set *dst, dataflow_set *src)
2665 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2666 attrs_list_union (&dst->regs[i], src->regs[i]);
2668 if (dst->vars == empty_shared_hash)
2670 shared_hash_destroy (dst->vars);
2671 dst->vars = shared_hash_copy (src->vars);
2678 FOR_EACH_HTAB_ELEMENT (shared_hash_htab (src->vars), var, variable, hi)
2679 variable_union (var, dst);
2683 /* Whether the value is currently being expanded. */
2684 #define VALUE_RECURSED_INTO(x) \
2685 (RTL_FLAG_CHECK2 ("VALUE_RECURSED_INTO", (x), VALUE, DEBUG_EXPR)->used)
2687 /* Whether no expansion was found, saving useless lookups.
2688 It must only be set when VALUE_CHANGED is clear. */
2689 #define NO_LOC_P(x) \
2690 (RTL_FLAG_CHECK2 ("NO_LOC_P", (x), VALUE, DEBUG_EXPR)->return_val)
2692 /* Whether cur_loc in the value needs to be (re)computed. */
2693 #define VALUE_CHANGED(x) \
2694 (RTL_FLAG_CHECK1 ("VALUE_CHANGED", (x), VALUE)->frame_related)
2695 /* Whether cur_loc in the decl needs to be (re)computed. */
2696 #define DECL_CHANGED(x) TREE_VISITED (x)
2698 /* Record (if NEWV) that DV needs to have its cur_loc recomputed. For
2699 user DECLs, this means they're in changed_variables. Values and
2700 debug exprs may be left with this flag set if no user variable
2701 requires them to be evaluated. */
2704 set_dv_changed (decl_or_value dv, bool newv)
2706 switch (dv_onepart_p (dv))
2710 NO_LOC_P (dv_as_value (dv)) = false;
2711 VALUE_CHANGED (dv_as_value (dv)) = newv;
2716 NO_LOC_P (DECL_RTL_KNOWN_SET (dv_as_decl (dv))) = false;
2717 /* Fall through... */
2720 DECL_CHANGED (dv_as_decl (dv)) = newv;
2725 /* Return true if DV needs to have its cur_loc recomputed. */
2728 dv_changed_p (decl_or_value dv)
2730 return (dv_is_value_p (dv)
2731 ? VALUE_CHANGED (dv_as_value (dv))
2732 : DECL_CHANGED (dv_as_decl (dv)));
2735 /* Return a location list node whose loc is rtx_equal to LOC, in the
2736 location list of a one-part variable or value VAR, or in that of
2737 any values recursively mentioned in the location lists. VARS must
2738 be in star-canonical form. */
2740 static location_chain
2741 find_loc_in_1pdv (rtx loc, variable var, htab_t vars)
2743 location_chain node;
2744 enum rtx_code loc_code;
2749 gcc_checking_assert (var->onepart);
2751 if (!var->n_var_parts)
2754 gcc_checking_assert (loc != dv_as_opaque (var->dv));
2756 loc_code = GET_CODE (loc);
2757 for (node = var->var_part[0].loc_chain; node; node = node->next)
2762 if (GET_CODE (node->loc) != loc_code)
2764 if (GET_CODE (node->loc) != VALUE)
2767 else if (loc == node->loc)
2769 else if (loc_code != VALUE)
2771 if (rtx_equal_p (loc, node->loc))
2776 /* Since we're in star-canonical form, we don't need to visit
2777 non-canonical nodes: one-part variables and non-canonical
2778 values would only point back to the canonical node. */
2779 if (dv_is_value_p (var->dv)
2780 && !canon_value_cmp (node->loc, dv_as_value (var->dv)))
2782 /* Skip all subsequent VALUEs. */
2783 while (node->next && GET_CODE (node->next->loc) == VALUE)
2786 gcc_checking_assert (!canon_value_cmp (node->loc,
2787 dv_as_value (var->dv)));
2788 if (loc == node->loc)
2794 gcc_checking_assert (node == var->var_part[0].loc_chain);
2795 gcc_checking_assert (!node->next);
2797 dv = dv_from_value (node->loc);
2798 rvar = (variable) htab_find_with_hash (vars, dv, dv_htab_hash (dv));
2799 return find_loc_in_1pdv (loc, rvar, vars);
2802 /* ??? Gotta look in cselib_val locations too. */
2807 /* Hash table iteration argument passed to variable_merge. */
2810 /* The set in which the merge is to be inserted. */
2812 /* The set that we're iterating in. */
2814 /* The set that may contain the other dv we are to merge with. */
2816 /* Number of onepart dvs in src. */
2817 int src_onepart_cnt;
2820 /* Insert LOC in *DNODE, if it's not there yet. The list must be in
2821 loc_cmp order, and it is maintained as such. */
2824 insert_into_intersection (location_chain *nodep, rtx loc,
2825 enum var_init_status status)
2827 location_chain node;
2830 for (node = *nodep; node; nodep = &node->next, node = *nodep)
2831 if ((r = loc_cmp (node->loc, loc)) == 0)
2833 node->init = MIN (node->init, status);
2839 node = (location_chain) pool_alloc (loc_chain_pool);
2842 node->set_src = NULL;
2843 node->init = status;
2844 node->next = *nodep;
2848 /* Insert in DEST the intersection of the locations present in both
2849 S1NODE and S2VAR, directly or indirectly. S1NODE is from a
2850 variable in DSM->cur, whereas S2VAR is from DSM->src. dvar is in
2854 intersect_loc_chains (rtx val, location_chain *dest, struct dfset_merge *dsm,
2855 location_chain s1node, variable s2var)
2857 dataflow_set *s1set = dsm->cur;
2858 dataflow_set *s2set = dsm->src;
2859 location_chain found;
2863 location_chain s2node;
2865 gcc_checking_assert (s2var->onepart);
2867 if (s2var->n_var_parts)
2869 s2node = s2var->var_part[0].loc_chain;
2871 for (; s1node && s2node;
2872 s1node = s1node->next, s2node = s2node->next)
2873 if (s1node->loc != s2node->loc)
2875 else if (s1node->loc == val)
2878 insert_into_intersection (dest, s1node->loc,
2879 MIN (s1node->init, s2node->init));
2883 for (; s1node; s1node = s1node->next)
2885 if (s1node->loc == val)
2888 if ((found = find_loc_in_1pdv (s1node->loc, s2var,
2889 shared_hash_htab (s2set->vars))))
2891 insert_into_intersection (dest, s1node->loc,
2892 MIN (s1node->init, found->init));
2896 if (GET_CODE (s1node->loc) == VALUE
2897 && !VALUE_RECURSED_INTO (s1node->loc))
2899 decl_or_value dv = dv_from_value (s1node->loc);
2900 variable svar = shared_hash_find (s1set->vars, dv);
2903 if (svar->n_var_parts == 1)
2905 VALUE_RECURSED_INTO (s1node->loc) = true;
2906 intersect_loc_chains (val, dest, dsm,
2907 svar->var_part[0].loc_chain,
2909 VALUE_RECURSED_INTO (s1node->loc) = false;
2914 /* ??? gotta look in cselib_val locations too. */
2916 /* ??? if the location is equivalent to any location in src,
2917 searched recursively
2919 add to dst the values needed to represent the equivalence
2921 telling whether locations S is equivalent to another dv's
2924 for each location D in the list
2926 if S and D satisfy rtx_equal_p, then it is present
2928 else if D is a value, recurse without cycles
2930 else if S and D have the same CODE and MODE
2932 for each operand oS and the corresponding oD
2934 if oS and oD are not equivalent, then S an D are not equivalent
2936 else if they are RTX vectors
2938 if any vector oS element is not equivalent to its respective oD,
2939 then S and D are not equivalent
2947 /* Return -1 if X should be before Y in a location list for a 1-part
2948 variable, 1 if Y should be before X, and 0 if they're equivalent
2949 and should not appear in the list. */
2952 loc_cmp (rtx x, rtx y)
2955 RTX_CODE code = GET_CODE (x);
2965 gcc_assert (GET_MODE (x) == GET_MODE (y));
2966 if (REGNO (x) == REGNO (y))
2968 else if (REGNO (x) < REGNO (y))
2981 gcc_assert (GET_MODE (x) == GET_MODE (y));
2982 return loc_cmp (XEXP (x, 0), XEXP (y, 0));
2988 if (GET_CODE (x) == VALUE)
2990 if (GET_CODE (y) != VALUE)
2992 /* Don't assert the modes are the same, that is true only
2993 when not recursing. (subreg:QI (value:SI 1:1) 0)
2994 and (subreg:QI (value:DI 2:2) 0) can be compared,
2995 even when the modes are different. */
2996 if (canon_value_cmp (x, y))
3002 if (GET_CODE (y) == VALUE)
3005 /* Entry value is the least preferable kind of expression. */
3006 if (GET_CODE (x) == ENTRY_VALUE)
3008 if (GET_CODE (y) != ENTRY_VALUE)
3010 gcc_assert (GET_MODE (x) == GET_MODE (y));
3011 return loc_cmp (XEXP (x, 0), XEXP (y, 0));
3014 if (GET_CODE (y) == ENTRY_VALUE)
3017 if (GET_CODE (x) == GET_CODE (y))
3018 /* Compare operands below. */;
3019 else if (GET_CODE (x) < GET_CODE (y))
3024 gcc_assert (GET_MODE (x) == GET_MODE (y));
3026 if (GET_CODE (x) == DEBUG_EXPR)
3028 if (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x))
3029 < DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (y)))
3031 gcc_checking_assert (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x))
3032 > DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (y)));
3036 fmt = GET_RTX_FORMAT (code);
3037 for (i = 0; i < GET_RTX_LENGTH (code); i++)
3041 if (XWINT (x, i) == XWINT (y, i))
3043 else if (XWINT (x, i) < XWINT (y, i))
3050 if (XINT (x, i) == XINT (y, i))
3052 else if (XINT (x, i) < XINT (y, i))
3059 /* Compare the vector length first. */
3060 if (XVECLEN (x, i) == XVECLEN (y, i))
3061 /* Compare the vectors elements. */;
3062 else if (XVECLEN (x, i) < XVECLEN (y, i))
3067 for (j = 0; j < XVECLEN (x, i); j++)
3068 if ((r = loc_cmp (XVECEXP (x, i, j),
3069 XVECEXP (y, i, j))))
3074 if ((r = loc_cmp (XEXP (x, i), XEXP (y, i))))
3080 if (XSTR (x, i) == XSTR (y, i))
3086 if ((r = strcmp (XSTR (x, i), XSTR (y, i))) == 0)
3094 /* These are just backpointers, so they don't matter. */
3101 /* It is believed that rtx's at this level will never
3102 contain anything but integers and other rtx's,
3103 except for within LABEL_REFs and SYMBOL_REFs. */
3112 /* Check the order of entries in one-part variables. */
3115 canonicalize_loc_order_check (void **slot, void *data ATTRIBUTE_UNUSED)
3117 variable var = (variable) *slot;
3118 location_chain node, next;
3120 #ifdef ENABLE_RTL_CHECKING
3122 for (i = 0; i < var->n_var_parts; i++)
3123 gcc_assert (var->var_part[0].cur_loc == NULL);
3124 gcc_assert (!var->in_changed_variables);
3130 gcc_assert (var->n_var_parts == 1);
3131 node = var->var_part[0].loc_chain;
3134 while ((next = node->next))
3136 gcc_assert (loc_cmp (node->loc, next->loc) < 0);
3144 /* Mark with VALUE_RECURSED_INTO values that have neighbors that are
3145 more likely to be chosen as canonical for an equivalence set.
3146 Ensure less likely values can reach more likely neighbors, making
3147 the connections bidirectional. */
3150 canonicalize_values_mark (void **slot, void *data)
3152 dataflow_set *set = (dataflow_set *)data;
3153 variable var = (variable) *slot;
3154 decl_or_value dv = var->dv;
3156 location_chain node;
3158 if (!dv_is_value_p (dv))
3161 gcc_checking_assert (var->n_var_parts == 1);
3163 val = dv_as_value (dv);
3165 for (node = var->var_part[0].loc_chain; node; node = node->next)
3166 if (GET_CODE (node->loc) == VALUE)
3168 if (canon_value_cmp (node->loc, val))
3169 VALUE_RECURSED_INTO (val) = true;
3172 decl_or_value odv = dv_from_value (node->loc);
3173 void **oslot = shared_hash_find_slot_noinsert (set->vars, odv);
3175 set_slot_part (set, val, oslot, odv, 0,
3176 node->init, NULL_RTX);
3178 VALUE_RECURSED_INTO (node->loc) = true;
3185 /* Remove redundant entries from equivalence lists in onepart
3186 variables, canonicalizing equivalence sets into star shapes. */
3189 canonicalize_values_star (void **slot, void *data)
3191 dataflow_set *set = (dataflow_set *)data;
3192 variable var = (variable) *slot;
3193 decl_or_value dv = var->dv;
3194 location_chain node;
3204 gcc_checking_assert (var->n_var_parts == 1);
3206 if (dv_is_value_p (dv))
3208 cval = dv_as_value (dv);
3209 if (!VALUE_RECURSED_INTO (cval))
3211 VALUE_RECURSED_INTO (cval) = false;
3221 gcc_assert (var->n_var_parts == 1);
3223 for (node = var->var_part[0].loc_chain; node; node = node->next)
3224 if (GET_CODE (node->loc) == VALUE)
3227 if (VALUE_RECURSED_INTO (node->loc))
3229 if (canon_value_cmp (node->loc, cval))
3238 if (!has_marks || dv_is_decl_p (dv))
3241 /* Keep it marked so that we revisit it, either after visiting a
3242 child node, or after visiting a new parent that might be
3244 VALUE_RECURSED_INTO (val) = true;
3246 for (node = var->var_part[0].loc_chain; node; node = node->next)
3247 if (GET_CODE (node->loc) == VALUE
3248 && VALUE_RECURSED_INTO (node->loc))
3252 VALUE_RECURSED_INTO (cval) = false;
3253 dv = dv_from_value (cval);
3254 slot = shared_hash_find_slot_noinsert (set->vars, dv);
3257 gcc_assert (dv_is_decl_p (var->dv));
3258 /* The canonical value was reset and dropped.
3260 clobber_variable_part (set, NULL, var->dv, 0, NULL);
3263 var = (variable)*slot;
3264 gcc_assert (dv_is_value_p (var->dv));
3265 if (var->n_var_parts == 0)
3267 gcc_assert (var->n_var_parts == 1);
3271 VALUE_RECURSED_INTO (val) = false;
3276 /* Push values to the canonical one. */
3277 cdv = dv_from_value (cval);
3278 cslot = shared_hash_find_slot_noinsert (set->vars, cdv);
3280 for (node = var->var_part[0].loc_chain; node; node = node->next)
3281 if (node->loc != cval)
3283 cslot = set_slot_part (set, node->loc, cslot, cdv, 0,
3284 node->init, NULL_RTX);
3285 if (GET_CODE (node->loc) == VALUE)
3287 decl_or_value ndv = dv_from_value (node->loc);
3289 set_variable_part (set, cval, ndv, 0, node->init, NULL_RTX,
3292 if (canon_value_cmp (node->loc, val))
3294 /* If it could have been a local minimum, it's not any more,
3295 since it's now neighbor to cval, so it may have to push
3296 to it. Conversely, if it wouldn't have prevailed over
3297 val, then whatever mark it has is fine: if it was to
3298 push, it will now push to a more canonical node, but if
3299 it wasn't, then it has already pushed any values it might
3301 VALUE_RECURSED_INTO (node->loc) = true;
3302 /* Make sure we visit node->loc by ensuring we cval is
3304 VALUE_RECURSED_INTO (cval) = true;
3306 else if (!VALUE_RECURSED_INTO (node->loc))
3307 /* If we have no need to "recurse" into this node, it's
3308 already "canonicalized", so drop the link to the old
3310 clobber_variable_part (set, cval, ndv, 0, NULL);
3312 else if (GET_CODE (node->loc) == REG)
3314 attrs list = set->regs[REGNO (node->loc)], *listp;
3316 /* Change an existing attribute referring to dv so that it
3317 refers to cdv, removing any duplicate this might
3318 introduce, and checking that no previous duplicates
3319 existed, all in a single pass. */
3323 if (list->offset == 0
3324 && (dv_as_opaque (list->dv) == dv_as_opaque (dv)
3325 || dv_as_opaque (list->dv) == dv_as_opaque (cdv)))
3332 if (dv_as_opaque (list->dv) == dv_as_opaque (dv))
3335 for (listp = &list->next; (list = *listp); listp = &list->next)
3340 if (dv_as_opaque (list->dv) == dv_as_opaque (cdv))
3342 *listp = list->next;
3343 pool_free (attrs_pool, list);
3348 gcc_assert (dv_as_opaque (list->dv) != dv_as_opaque (dv));
3351 else if (dv_as_opaque (list->dv) == dv_as_opaque (cdv))
3353 for (listp = &list->next; (list = *listp); listp = &list->next)
3358 if (dv_as_opaque (list->dv) == dv_as_opaque (dv))
3360 *listp = list->next;
3361 pool_free (attrs_pool, list);
3366 gcc_assert (dv_as_opaque (list->dv) != dv_as_opaque (cdv));
3375 if (list->offset == 0
3376 && (dv_as_opaque (list->dv) == dv_as_opaque (dv)
3377 || dv_as_opaque (list->dv) == dv_as_opaque (cdv)))
3387 set_slot_part (set, val, cslot, cdv, 0,
3388 VAR_INIT_STATUS_INITIALIZED, NULL_RTX);
3390 slot = clobber_slot_part (set, cval, slot, 0, NULL);
3392 /* Variable may have been unshared. */
3393 var = (variable)*slot;
3394 gcc_checking_assert (var->n_var_parts && var->var_part[0].loc_chain->loc == cval
3395 && var->var_part[0].loc_chain->next == NULL);
3397 if (VALUE_RECURSED_INTO (cval))
3398 goto restart_with_cval;
3403 /* Bind one-part variables to the canonical value in an equivalence
3404 set. Not doing this causes dataflow convergence failure in rare
3405 circumstances, see PR42873. Unfortunately we can't do this
3406 efficiently as part of canonicalize_values_star, since we may not
3407 have determined or even seen the canonical value of a set when we
3408 get to a variable that references another member of the set. */
3411 canonicalize_vars_star (void **slot, void *data)
3413 dataflow_set *set = (dataflow_set *)data;
3414 variable var = (variable) *slot;
3415 decl_or_value dv = var->dv;
3416 location_chain node;
3421 location_chain cnode;
3423 if (!var->onepart || var->onepart == ONEPART_VALUE)
3426 gcc_assert (var->n_var_parts == 1);
3428 node = var->var_part[0].loc_chain;
3430 if (GET_CODE (node->loc) != VALUE)
3433 gcc_assert (!node->next);
3436 /* Push values to the canonical one. */
3437 cdv = dv_from_value (cval);
3438 cslot = shared_hash_find_slot_noinsert (set->vars, cdv);
3441 cvar = (variable)*cslot;
3442 gcc_assert (cvar->n_var_parts == 1);
3444 cnode = cvar->var_part[0].loc_chain;
3446 /* CVAL is canonical if its value list contains non-VALUEs or VALUEs
3447 that are not “more canonical” than it. */
3448 if (GET_CODE (cnode->loc) != VALUE
3449 || !canon_value_cmp (cnode->loc, cval))
3452 /* CVAL was found to be non-canonical. Change the variable to point
3453 to the canonical VALUE. */
3454 gcc_assert (!cnode->next);
3457 slot = set_slot_part (set, cval, slot, dv, 0,
3458 node->init, node->set_src);
3459 clobber_slot_part (set, cval, slot, 0, node->set_src);
3464 /* Combine variable or value in *S1SLOT (in DSM->cur) with the
3465 corresponding entry in DSM->src. Multi-part variables are combined
3466 with variable_union, whereas onepart dvs are combined with
3470 variable_merge_over_cur (variable s1var, struct dfset_merge *dsm)
3472 dataflow_set *dst = dsm->dst;
3474 variable s2var, dvar = NULL;
3475 decl_or_value dv = s1var->dv;
3476 onepart_enum_t onepart = s1var->onepart;
3479 location_chain node, *nodep;
3481 /* If the incoming onepart variable has an empty location list, then
3482 the intersection will be just as empty. For other variables,
3483 it's always union. */
3484 gcc_checking_assert (s1var->n_var_parts
3485 && s1var->var_part[0].loc_chain);
3488 return variable_union (s1var, dst);
3490 gcc_checking_assert (s1var->n_var_parts == 1);
3492 dvhash = dv_htab_hash (dv);
3493 if (dv_is_value_p (dv))
3494 val = dv_as_value (dv);
3498 s2var = shared_hash_find_1 (dsm->src->vars, dv, dvhash);
3501 dst_can_be_shared = false;
3505 dsm->src_onepart_cnt--;
3506 gcc_assert (s2var->var_part[0].loc_chain
3507 && s2var->onepart == onepart
3508 && s2var->n_var_parts == 1);
3510 dstslot = shared_hash_find_slot_noinsert_1 (dst->vars, dv, dvhash);
3513 dvar = (variable)*dstslot;
3514 gcc_assert (dvar->refcount == 1
3515 && dvar->onepart == onepart
3516 && dvar->n_var_parts == 1);
3517 nodep = &dvar->var_part[0].loc_chain;
3525 if (!dstslot && !onepart_variable_different_p (s1var, s2var))
3527 dstslot = shared_hash_find_slot_unshare_1 (&dst->vars, dv,
3529 *dstslot = dvar = s2var;
3534 dst_can_be_shared = false;
3536 intersect_loc_chains (val, nodep, dsm,
3537 s1var->var_part[0].loc_chain, s2var);
3543 dvar = (variable) pool_alloc (onepart_pool (onepart));
3546 dvar->n_var_parts = 1;
3547 dvar->onepart = onepart;
3548 dvar->in_changed_variables = false;
3549 dvar->var_part[0].loc_chain = node;
3550 dvar->var_part[0].cur_loc = NULL;
3552 VAR_LOC_1PAUX (dvar) = NULL;
3554 VAR_PART_OFFSET (dvar, 0) = 0;
3557 = shared_hash_find_slot_unshare_1 (&dst->vars, dv, dvhash,
3559 gcc_assert (!*dstslot);
3567 nodep = &dvar->var_part[0].loc_chain;
3568 while ((node = *nodep))
3570 location_chain *nextp = &node->next;
3572 if (GET_CODE (node->loc) == REG)
3576 for (list = dst->regs[REGNO (node->loc)]; list; list = list->next)
3577 if (GET_MODE (node->loc) == GET_MODE (list->loc)
3578 && dv_is_value_p (list->dv))
3582 attrs_list_insert (&dst->regs[REGNO (node->loc)],
3584 /* If this value became canonical for another value that had
3585 this register, we want to leave it alone. */
3586 else if (dv_as_value (list->dv) != val)
3588 dstslot = set_slot_part (dst, dv_as_value (list->dv),
3590 node->init, NULL_RTX);
3591 dstslot = delete_slot_part (dst, node->loc, dstslot, 0);
3593 /* Since nextp points into the removed node, we can't
3594 use it. The pointer to the next node moved to nodep.
3595 However, if the variable we're walking is unshared
3596 during our walk, we'll keep walking the location list
3597 of the previously-shared variable, in which case the
3598 node won't have been removed, and we'll want to skip
3599 it. That's why we test *nodep here. */
3605 /* Canonicalization puts registers first, so we don't have to
3611 if (dvar != (variable)*dstslot)
3612 dvar = (variable)*dstslot;
3613 nodep = &dvar->var_part[0].loc_chain;
3617 /* Mark all referenced nodes for canonicalization, and make sure
3618 we have mutual equivalence links. */
3619 VALUE_RECURSED_INTO (val) = true;
3620 for (node = *nodep; node; node = node->next)
3621 if (GET_CODE (node->loc) == VALUE)
3623 VALUE_RECURSED_INTO (node->loc) = true;
3624 set_variable_part (dst, val, dv_from_value (node->loc), 0,
3625 node->init, NULL, INSERT);
3628 dstslot = shared_hash_find_slot_noinsert_1 (dst->vars, dv, dvhash);
3629 gcc_assert (*dstslot == dvar);
3630 canonicalize_values_star (dstslot, dst);
3631 gcc_checking_assert (dstslot
3632 == shared_hash_find_slot_noinsert_1 (dst->vars,
3634 dvar = (variable)*dstslot;
3638 bool has_value = false, has_other = false;
3640 /* If we have one value and anything else, we're going to
3641 canonicalize this, so make sure all values have an entry in
3642 the table and are marked for canonicalization. */
3643 for (node = *nodep; node; node = node->next)
3645 if (GET_CODE (node->loc) == VALUE)
3647 /* If this was marked during register canonicalization,
3648 we know we have to canonicalize values. */
3663 if (has_value && has_other)
3665 for (node = *nodep; node; node = node->next)
3667 if (GET_CODE (node->loc) == VALUE)
3669 decl_or_value dv = dv_from_value (node->loc);
3672 if (shared_hash_shared (dst->vars))
3673 slot = shared_hash_find_slot_noinsert (dst->vars, dv);
3675 slot = shared_hash_find_slot_unshare (&dst->vars, dv,
3679 variable var = (variable) pool_alloc (onepart_pool
3683 var->n_var_parts = 1;
3684 var->onepart = ONEPART_VALUE;
3685 var->in_changed_variables = false;
3686 var->var_part[0].loc_chain = NULL;
3687 var->var_part[0].cur_loc = NULL;
3688 VAR_LOC_1PAUX (var) = NULL;
3692 VALUE_RECURSED_INTO (node->loc) = true;
3696 dstslot = shared_hash_find_slot_noinsert_1 (dst->vars, dv, dvhash);
3697 gcc_assert (*dstslot == dvar);
3698 canonicalize_values_star (dstslot, dst);
3699 gcc_checking_assert (dstslot
3700 == shared_hash_find_slot_noinsert_1 (dst->vars,
3702 dvar = (variable)*dstslot;
3706 if (!onepart_variable_different_p (dvar, s2var))
3708 variable_htab_free (dvar);
3709 *dstslot = dvar = s2var;
3712 else if (s2var != s1var && !onepart_variable_different_p (dvar, s1var))
3714 variable_htab_free (dvar);
3715 *dstslot = dvar = s1var;
3717 dst_can_be_shared = false;
3720 dst_can_be_shared = false;
3725 /* Copy s2slot (in DSM->src) to DSM->dst if the variable is a
3726 multi-part variable. Unions of multi-part variables and
3727 intersections of one-part ones will be handled in
3728 variable_merge_over_cur(). */
3731 variable_merge_over_src (variable s2var, struct dfset_merge *dsm)
3733 dataflow_set *dst = dsm->dst;
3734 decl_or_value dv = s2var->dv;
3736 if (!s2var->onepart)
3738 void **dstp = shared_hash_find_slot (dst->vars, dv);
3744 dsm->src_onepart_cnt++;
3748 /* Combine dataflow set information from SRC2 into DST, using PDST
3749 to carry over information across passes. */
3752 dataflow_set_merge (dataflow_set *dst, dataflow_set *src2)
3754 dataflow_set cur = *dst;
3755 dataflow_set *src1 = &cur;
3756 struct dfset_merge dsm;
3758 size_t src1_elems, src2_elems;
3762 src1_elems = htab_elements (shared_hash_htab (src1->vars));
3763 src2_elems = htab_elements (shared_hash_htab (src2->vars));
3764 dataflow_set_init (dst);
3765 dst->stack_adjust = cur.stack_adjust;
3766 shared_hash_destroy (dst->vars);
3767 dst->vars = (shared_hash) pool_alloc (shared_hash_pool);
3768 dst->vars->refcount = 1;
3770 = htab_create (MAX (src1_elems, src2_elems), variable_htab_hash,
3771 variable_htab_eq, variable_htab_free);
3773 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3774 attrs_list_mpdv_union (&dst->regs[i], src1->regs[i], src2->regs[i]);
3779 dsm.src_onepart_cnt = 0;
3781 FOR_EACH_HTAB_ELEMENT (shared_hash_htab (dsm.src->vars), var, variable, hi)
3782 variable_merge_over_src (var, &dsm);
3783 FOR_EACH_HTAB_ELEMENT (shared_hash_htab (dsm.cur->vars), var, variable, hi)
3784 variable_merge_over_cur (var, &dsm);
3786 if (dsm.src_onepart_cnt)
3787 dst_can_be_shared = false;
3789 dataflow_set_destroy (src1);
3792 /* Mark register equivalences. */
3795 dataflow_set_equiv_regs (dataflow_set *set)
3800 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3802 rtx canon[NUM_MACHINE_MODES];
3804 /* If the list is empty or one entry, no need to canonicalize
3806 if (set->regs[i] == NULL || set->regs[i]->next == NULL)
3809 memset (canon, 0, sizeof (canon));
3811 for (list = set->regs[i]; list; list = list->next)
3812 if (list->offset == 0 && dv_is_value_p (list->dv))
3814 rtx val = dv_as_value (list->dv);
3815 rtx *cvalp = &canon[(int)GET_MODE (val)];
3818 if (canon_value_cmp (val, cval))
3822 for (list = set->regs[i]; list; list = list->next)
3823 if (list->offset == 0 && dv_onepart_p (list->dv))
3825 rtx cval = canon[(int)GET_MODE (list->loc)];
3830 if (dv_is_value_p (list->dv))
3832 rtx val = dv_as_value (list->dv);
3837 VALUE_RECURSED_INTO (val) = true;
3838 set_variable_part (set, val, dv_from_value (cval), 0,
3839 VAR_INIT_STATUS_INITIALIZED,
3843 VALUE_RECURSED_INTO (cval) = true;
3844 set_variable_part (set, cval, list->dv, 0,
3845 VAR_INIT_STATUS_INITIALIZED, NULL, NO_INSERT);
3848 for (listp = &set->regs[i]; (list = *listp);
3849 listp = list ? &list->next : listp)
3850 if (list->offset == 0 && dv_onepart_p (list->dv))
3852 rtx cval = canon[(int)GET_MODE (list->loc)];
3858 if (dv_is_value_p (list->dv))
3860 rtx val = dv_as_value (list->dv);
3861 if (!VALUE_RECURSED_INTO (val))
3865 slot = shared_hash_find_slot_noinsert (set->vars, list->dv);
3866 canonicalize_values_star (slot, set);
3873 /* Remove any redundant values in the location list of VAR, which must
3874 be unshared and 1-part. */
3877 remove_duplicate_values (variable var)
3879 location_chain node, *nodep;
3881 gcc_assert (var->onepart);
3882 gcc_assert (var->n_var_parts == 1);
3883 gcc_assert (var->refcount == 1);
3885 for (nodep = &var->var_part[0].loc_chain; (node = *nodep); )
3887 if (GET_CODE (node->loc) == VALUE)
3889 if (VALUE_RECURSED_INTO (node->loc))
3891 /* Remove duplicate value node. */
3892 *nodep = node->next;
3893 pool_free (loc_chain_pool, node);
3897 VALUE_RECURSED_INTO (node->loc) = true;
3899 nodep = &node->next;
3902 for (node = var->var_part[0].loc_chain; node; node = node->next)
3903 if (GET_CODE (node->loc) == VALUE)
3905 gcc_assert (VALUE_RECURSED_INTO (node->loc));
3906 VALUE_RECURSED_INTO (node->loc) = false;
3911 /* Hash table iteration argument passed to variable_post_merge. */
3912 struct dfset_post_merge
3914 /* The new input set for the current block. */
3916 /* Pointer to the permanent input set for the current block, or
3918 dataflow_set **permp;
3921 /* Create values for incoming expressions associated with one-part
3922 variables that don't have value numbers for them. */
3925 variable_post_merge_new_vals (void **slot, void *info)
3927 struct dfset_post_merge *dfpm = (struct dfset_post_merge *)info;
3928 dataflow_set *set = dfpm->set;
3929 variable var = (variable)*slot;
3930 location_chain node;
3932 if (!var->onepart || !var->n_var_parts)
3935 gcc_assert (var->n_var_parts == 1);
3937 if (dv_is_decl_p (var->dv))
3939 bool check_dupes = false;
3942 for (node = var->var_part[0].loc_chain; node; node = node->next)
3944 if (GET_CODE (node->loc) == VALUE)
3945 gcc_assert (!VALUE_RECURSED_INTO (node->loc));
3946 else if (GET_CODE (node->loc) == REG)
3948 attrs att, *attp, *curp = NULL;
3950 if (var->refcount != 1)
3952 slot = unshare_variable (set, slot, var,
3953 VAR_INIT_STATUS_INITIALIZED);
3954 var = (variable)*slot;
3958 for (attp = &set->regs[REGNO (node->loc)]; (att = *attp);
3960 if (att->offset == 0
3961 && GET_MODE (att->loc) == GET_MODE (node->loc))
3963 if (dv_is_value_p (att->dv))
3965 rtx cval = dv_as_value (att->dv);
3970 else if (dv_as_opaque (att->dv) == dv_as_opaque (var->dv))
3978 if ((*curp)->offset == 0
3979 && GET_MODE ((*curp)->loc) == GET_MODE (node->loc)
3980 && dv_as_opaque ((*curp)->dv) == dv_as_opaque (var->dv))
3983 curp = &(*curp)->next;
3994 *dfpm->permp = XNEW (dataflow_set);
3995 dataflow_set_init (*dfpm->permp);
3998 for (att = (*dfpm->permp)->regs[REGNO (node->loc)];
3999 att; att = att->next)
4000 if (GET_MODE (att->loc) == GET_MODE (node->loc))
4002 gcc_assert (att->offset == 0
4003 && dv_is_value_p (att->dv));
4004 val_reset (set, att->dv);
4011 cval = dv_as_value (cdv);
4015 /* Create a unique value to hold this register,
4016 that ought to be found and reused in
4017 subsequent rounds. */
4019 gcc_assert (!cselib_lookup (node->loc,
4020 GET_MODE (node->loc), 0,
4022 v = cselib_lookup (node->loc, GET_MODE (node->loc), 1,
4024 cselib_preserve_value (v);
4025 cselib_invalidate_rtx (node->loc);
4027 cdv = dv_from_value (cval);
4030 "Created new value %u:%u for reg %i\n",
4031 v->uid, v->hash, REGNO (node->loc));
4034 var_reg_decl_set (*dfpm->permp, node->loc,
4035 VAR_INIT_STATUS_INITIALIZED,
4036 cdv, 0, NULL, INSERT);
4042 /* Remove attribute referring to the decl, which now
4043 uses the value for the register, already existing or
4044 to be added when we bring perm in. */
4047 pool_free (attrs_pool, att);
4052 remove_duplicate_values (var);
4058 /* Reset values in the permanent set that are not associated with the
4059 chosen expression. */
4062 variable_post_merge_perm_vals (void **pslot, void *info)
4064 struct dfset_post_merge *dfpm = (struct dfset_post_merge *)info;
4065 dataflow_set *set = dfpm->set;
4066 variable pvar = (variable)*pslot, var;
4067 location_chain pnode;
4071 gcc_assert (dv_is_value_p (pvar->dv)
4072 && pvar->n_var_parts == 1);
4073 pnode = pvar->var_part[0].loc_chain;
4076 && REG_P (pnode->loc));
4080 var = shared_hash_find (set->vars, dv);
4083 /* Although variable_post_merge_new_vals may have made decls
4084 non-star-canonical, values that pre-existed in canonical form
4085 remain canonical, and newly-created values reference a single
4086 REG, so they are canonical as well. Since VAR has the
4087 location list for a VALUE, using find_loc_in_1pdv for it is
4088 fine, since VALUEs don't map back to DECLs. */
4089 if (find_loc_in_1pdv (pnode->loc, var, shared_hash_htab (set->vars)))
4091 val_reset (set, dv);
4094 for (att = set->regs[REGNO (pnode->loc)]; att; att = att->next)
4095 if (att->offset == 0
4096 && GET_MODE (att->loc) == GET_MODE (pnode->loc)
4097 && dv_is_value_p (att->dv))
4100 /* If there is a value associated with this register already, create
4102 if (att && dv_as_value (att->dv) != dv_as_value (dv))
4104 rtx cval = dv_as_value (att->dv);
4105 set_variable_part (set, cval, dv, 0, pnode->init, NULL, INSERT);
4106 set_variable_part (set, dv_as_value (dv), att->dv, 0, pnode->init,
4111 attrs_list_insert (&set->regs[REGNO (pnode->loc)],
4113 variable_union (pvar, set);
4119 /* Just checking stuff and registering register attributes for
4123 dataflow_post_merge_adjust (dataflow_set *set, dataflow_set **permp)
4125 struct dfset_post_merge dfpm;
4130 htab_traverse (shared_hash_htab (set->vars), variable_post_merge_new_vals,
4133 htab_traverse (shared_hash_htab ((*permp)->vars),
4134 variable_post_merge_perm_vals, &dfpm);
4135 htab_traverse (shared_hash_htab (set->vars), canonicalize_values_star, set);
4136 htab_traverse (shared_hash_htab (set->vars), canonicalize_vars_star, set);
4139 /* Return a node whose loc is a MEM that refers to EXPR in the
4140 location list of a one-part variable or value VAR, or in that of
4141 any values recursively mentioned in the location lists. */
4143 static location_chain
4144 find_mem_expr_in_1pdv (tree expr, rtx val, htab_t vars)
4146 location_chain node;
4149 location_chain where = NULL;
4154 gcc_assert (GET_CODE (val) == VALUE
4155 && !VALUE_RECURSED_INTO (val));
4157 dv = dv_from_value (val);
4158 var = (variable) htab_find_with_hash (vars, dv, dv_htab_hash (dv));
4163 gcc_assert (var->onepart);
4165 if (!var->n_var_parts)
4168 VALUE_RECURSED_INTO (val) = true;
4170 for (node = var->var_part[0].loc_chain; node; node = node->next)
4171 if (MEM_P (node->loc)
4172 && MEM_EXPR (node->loc) == expr
4173 && INT_MEM_OFFSET (node->loc) == 0)
4178 else if (GET_CODE (node->loc) == VALUE
4179 && !VALUE_RECURSED_INTO (node->loc)
4180 && (where = find_mem_expr_in_1pdv (expr, node->loc, vars)))
4183 VALUE_RECURSED_INTO (val) = false;
4188 /* Return TRUE if the value of MEM may vary across a call. */
4191 mem_dies_at_call (rtx mem)
4193 tree expr = MEM_EXPR (mem);
4199 decl = get_base_address (expr);
4207 return (may_be_aliased (decl)
4208 || (!TREE_READONLY (decl) && is_global_var (decl)));
4211 /* Remove all MEMs from the location list of a hash table entry for a
4212 one-part variable, except those whose MEM attributes map back to
4213 the variable itself, directly or within a VALUE. */
4216 dataflow_set_preserve_mem_locs (void **slot, void *data)
4218 dataflow_set *set = (dataflow_set *) data;
4219 variable var = (variable) *slot;
4221 if (var->onepart == ONEPART_VDECL || var->onepart == ONEPART_DEXPR)
4223 tree decl = dv_as_decl (var->dv);
4224 location_chain loc, *locp;
4225 bool changed = false;
4227 if (!var->n_var_parts)
4230 gcc_assert (var->n_var_parts == 1);
4232 if (shared_var_p (var, set->vars))
4234 for (loc = var->var_part[0].loc_chain; loc; loc = loc->next)
4236 /* We want to remove dying MEMs that doesn't refer to DECL. */
4237 if (GET_CODE (loc->loc) == MEM
4238 && (MEM_EXPR (loc->loc) != decl
4239 || INT_MEM_OFFSET (loc->loc) != 0)
4240 && !mem_dies_at_call (loc->loc))
4242 /* We want to move here MEMs that do refer to DECL. */
4243 else if (GET_CODE (loc->loc) == VALUE
4244 && find_mem_expr_in_1pdv (decl, loc->loc,
4245 shared_hash_htab (set->vars)))
4252 slot = unshare_variable (set, slot, var, VAR_INIT_STATUS_UNKNOWN);
4253 var = (variable)*slot;
4254 gcc_assert (var->n_var_parts == 1);
4257 for (locp = &var->var_part[0].loc_chain, loc = *locp;
4260 rtx old_loc = loc->loc;
4261 if (GET_CODE (old_loc) == VALUE)
4263 location_chain mem_node
4264 = find_mem_expr_in_1pdv (decl, loc->loc,
4265 shared_hash_htab (set->vars));
4267 /* ??? This picks up only one out of multiple MEMs that
4268 refer to the same variable. Do we ever need to be
4269 concerned about dealing with more than one, or, given
4270 that they should all map to the same variable
4271 location, their addresses will have been merged and
4272 they will be regarded as equivalent? */
4275 loc->loc = mem_node->loc;
4276 loc->set_src = mem_node->set_src;
4277 loc->init = MIN (loc->init, mem_node->init);
4281 if (GET_CODE (loc->loc) != MEM
4282 || (MEM_EXPR (loc->loc) == decl
4283 && INT_MEM_OFFSET (loc->loc) == 0)
4284 || !mem_dies_at_call (loc->loc))
4286 if (old_loc != loc->loc && emit_notes)
4288 if (old_loc == var->var_part[0].cur_loc)
4291 var->var_part[0].cur_loc = NULL;
4300 if (old_loc == var->var_part[0].cur_loc)
4303 var->var_part[0].cur_loc = NULL;
4307 pool_free (loc_chain_pool, loc);
4310 if (!var->var_part[0].loc_chain)
4316 variable_was_changed (var, set);
4322 /* Remove all MEMs from the location list of a hash table entry for a
4326 dataflow_set_remove_mem_locs (void **slot, void *data)
4328 dataflow_set *set = (dataflow_set *) data;
4329 variable var = (variable) *slot;
4331 if (var->onepart == ONEPART_VALUE)
4333 location_chain loc, *locp;
4334 bool changed = false;
4337 gcc_assert (var->n_var_parts == 1);
4339 if (shared_var_p (var, set->vars))
4341 for (loc = var->var_part[0].loc_chain; loc; loc = loc->next)
4342 if (GET_CODE (loc->loc) == MEM
4343 && mem_dies_at_call (loc->loc))
4349 slot = unshare_variable (set, slot, var, VAR_INIT_STATUS_UNKNOWN);
4350 var = (variable)*slot;
4351 gcc_assert (var->n_var_parts == 1);
4354 if (VAR_LOC_1PAUX (var))
4355 cur_loc = VAR_LOC_FROM (var);
4357 cur_loc = var->var_part[0].cur_loc;
4359 for (locp = &var->var_part[0].loc_chain, loc = *locp;
4362 if (GET_CODE (loc->loc) != MEM
4363 || !mem_dies_at_call (loc->loc))
4370 /* If we have deleted the location which was last emitted
4371 we have to emit new location so add the variable to set
4372 of changed variables. */
4373 if (cur_loc == loc->loc)
4376 var->var_part[0].cur_loc = NULL;
4377 if (VAR_LOC_1PAUX (var))
4378 VAR_LOC_FROM (var) = NULL;
4380 pool_free (loc_chain_pool, loc);
4383 if (!var->var_part[0].loc_chain)
4389 variable_was_changed (var, set);
4395 /* Remove all variable-location information about call-clobbered
4396 registers, as well as associations between MEMs and VALUEs. */
4399 dataflow_set_clear_at_call (dataflow_set *set)
4403 for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
4404 if (TEST_HARD_REG_BIT (regs_invalidated_by_call, r))
4405 var_regno_delete (set, r);
4407 if (MAY_HAVE_DEBUG_INSNS)
4409 set->traversed_vars = set->vars;
4410 htab_traverse (shared_hash_htab (set->vars),
4411 dataflow_set_preserve_mem_locs, set);
4412 set->traversed_vars = set->vars;
4413 htab_traverse (shared_hash_htab (set->vars), dataflow_set_remove_mem_locs,
4415 set->traversed_vars = NULL;
4420 variable_part_different_p (variable_part *vp1, variable_part *vp2)
4422 location_chain lc1, lc2;
4424 for (lc1 = vp1->loc_chain; lc1; lc1 = lc1->next)
4426 for (lc2 = vp2->loc_chain; lc2; lc2 = lc2->next)
4428 if (REG_P (lc1->loc) && REG_P (lc2->loc))
4430 if (REGNO (lc1->loc) == REGNO (lc2->loc))
4433 if (rtx_equal_p (lc1->loc, lc2->loc))
4442 /* Return true if one-part variables VAR1 and VAR2 are different.
4443 They must be in canonical order. */
4446 onepart_variable_different_p (variable var1, variable var2)
4448 location_chain lc1, lc2;
4453 gcc_assert (var1->n_var_parts == 1
4454 && var2->n_var_parts == 1);
4456 lc1 = var1->var_part[0].loc_chain;
4457 lc2 = var2->var_part[0].loc_chain;
4459 gcc_assert (lc1 && lc2);
4463 if (loc_cmp (lc1->loc, lc2->loc))
4472 /* Return true if variables VAR1 and VAR2 are different. */
4475 variable_different_p (variable var1, variable var2)
4482 if (var1->onepart != var2->onepart)
4485 if (var1->n_var_parts != var2->n_var_parts)
4488 if (var1->onepart && var1->n_var_parts)
4490 gcc_checking_assert (dv_as_opaque (var1->dv) == dv_as_opaque (var2->dv)
4491 && var1->n_var_parts == 1);
4492 /* One-part values have locations in a canonical order. */
4493 return onepart_variable_different_p (var1, var2);
4496 for (i = 0; i < var1->n_var_parts; i++)
4498 if (VAR_PART_OFFSET (var1, i) != VAR_PART_OFFSET (var2, i))
4500 if (variable_part_different_p (&var1->var_part[i], &var2->var_part[i]))
4502 if (variable_part_different_p (&var2->var_part[i], &var1->var_part[i]))
4508 /* Return true if dataflow sets OLD_SET and NEW_SET differ. */
4511 dataflow_set_different (dataflow_set *old_set, dataflow_set *new_set)
4516 if (old_set->vars == new_set->vars)
4519 if (htab_elements (shared_hash_htab (old_set->vars))
4520 != htab_elements (shared_hash_htab (new_set->vars)))
4523 FOR_EACH_HTAB_ELEMENT (shared_hash_htab (old_set->vars), var1, variable, hi)
4525 htab_t htab = shared_hash_htab (new_set->vars);
4526 variable var2 = (variable) htab_find_with_hash (htab, var1->dv,
4527 dv_htab_hash (var1->dv));
4530 if (dump_file && (dump_flags & TDF_DETAILS))
4532 fprintf (dump_file, "dataflow difference found: removal of:\n");
4538 if (variable_different_p (var1, var2))
4540 if (dump_file && (dump_flags & TDF_DETAILS))
4542 fprintf (dump_file, "dataflow difference found: "
4543 "old and new follow:\n");
4551 /* No need to traverse the second hashtab, if both have the same number
4552 of elements and the second one had all entries found in the first one,
4553 then it can't have any extra entries. */
4557 /* Free the contents of dataflow set SET. */
4560 dataflow_set_destroy (dataflow_set *set)
4564 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4565 attrs_list_clear (&set->regs[i]);
4567 shared_hash_destroy (set->vars);
4571 /* Return true if RTL X contains a SYMBOL_REF. */
4574 contains_symbol_ref (rtx x)
4583 code = GET_CODE (x);
4584 if (code == SYMBOL_REF)
4587 fmt = GET_RTX_FORMAT (code);
4588 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4592 if (contains_symbol_ref (XEXP (x, i)))
4595 else if (fmt[i] == 'E')
4598 for (j = 0; j < XVECLEN (x, i); j++)
4599 if (contains_symbol_ref (XVECEXP (x, i, j)))
4607 /* Shall EXPR be tracked? */
4610 track_expr_p (tree expr, bool need_rtl)
4615 if (TREE_CODE (expr) == DEBUG_EXPR_DECL)
4616 return DECL_RTL_SET_P (expr);
4618 /* If EXPR is not a parameter or a variable do not track it. */
4619 if (TREE_CODE (expr) != VAR_DECL && TREE_CODE (expr) != PARM_DECL)
4622 /* It also must have a name... */
4623 if (!DECL_NAME (expr) && need_rtl)
4626 /* ... and a RTL assigned to it. */
4627 decl_rtl = DECL_RTL_IF_SET (expr);
4628 if (!decl_rtl && need_rtl)
4631 /* If this expression is really a debug alias of some other declaration, we
4632 don't need to track this expression if the ultimate declaration is
4635 if (DECL_DEBUG_EXPR_IS_FROM (realdecl))
4637 realdecl = DECL_DEBUG_EXPR (realdecl);
4638 if (realdecl == NULL_TREE)
4640 else if (!DECL_P (realdecl))
4642 if (handled_component_p (realdecl))
4644 HOST_WIDE_INT bitsize, bitpos, maxsize;
4646 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize,
4648 if (!DECL_P (innerdecl)
4649 || DECL_IGNORED_P (innerdecl)
4650 || TREE_STATIC (innerdecl)
4652 || bitpos + bitsize > 256
4653 || bitsize != maxsize)
4663 /* Do not track EXPR if REALDECL it should be ignored for debugging
4665 if (DECL_IGNORED_P (realdecl))
4668 /* Do not track global variables until we are able to emit correct location
4670 if (TREE_STATIC (realdecl))
4673 /* When the EXPR is a DECL for alias of some variable (see example)
4674 the TREE_STATIC flag is not used. Disable tracking all DECLs whose
4675 DECL_RTL contains SYMBOL_REF.
4678 extern char **_dl_argv_internal __attribute__ ((alias ("_dl_argv")));
4681 if (decl_rtl && MEM_P (decl_rtl)
4682 && contains_symbol_ref (XEXP (decl_rtl, 0)))
4685 /* If RTX is a memory it should not be very large (because it would be
4686 an array or struct). */
4687 if (decl_rtl && MEM_P (decl_rtl))
4689 /* Do not track structures and arrays. */
4690 if (GET_MODE (decl_rtl) == BLKmode
4691 || AGGREGATE_TYPE_P (TREE_TYPE (realdecl)))
4693 if (MEM_SIZE_KNOWN_P (decl_rtl)
4694 && MEM_SIZE (decl_rtl) > MAX_VAR_PARTS)
4698 DECL_CHANGED (expr) = 0;
4699 DECL_CHANGED (realdecl) = 0;
4703 /* Determine whether a given LOC refers to the same variable part as
4707 same_variable_part_p (rtx loc, tree expr, HOST_WIDE_INT offset)
4710 HOST_WIDE_INT offset2;
4712 if (! DECL_P (expr))
4717 expr2 = REG_EXPR (loc);
4718 offset2 = REG_OFFSET (loc);
4720 else if (MEM_P (loc))
4722 expr2 = MEM_EXPR (loc);
4723 offset2 = INT_MEM_OFFSET (loc);
4728 if (! expr2 || ! DECL_P (expr2))
4731 expr = var_debug_decl (expr);
4732 expr2 = var_debug_decl (expr2);
4734 return (expr == expr2 && offset == offset2);
4737 /* LOC is a REG or MEM that we would like to track if possible.
4738 If EXPR is null, we don't know what expression LOC refers to,
4739 otherwise it refers to EXPR + OFFSET. STORE_REG_P is true if
4740 LOC is an lvalue register.
4742 Return true if EXPR is nonnull and if LOC, or some lowpart of it,
4743 is something we can track. When returning true, store the mode of
4744 the lowpart we can track in *MODE_OUT (if nonnull) and its offset
4745 from EXPR in *OFFSET_OUT (if nonnull). */
4748 track_loc_p (rtx loc, tree expr, HOST_WIDE_INT offset, bool store_reg_p,
4749 enum machine_mode *mode_out, HOST_WIDE_INT *offset_out)
4751 enum machine_mode mode;
4753 if (expr == NULL || !track_expr_p (expr, true))
4756 /* If REG was a paradoxical subreg, its REG_ATTRS will describe the
4757 whole subreg, but only the old inner part is really relevant. */
4758 mode = GET_MODE (loc);
4759 if (REG_P (loc) && !HARD_REGISTER_NUM_P (ORIGINAL_REGNO (loc)))
4761 enum machine_mode pseudo_mode;
4763 pseudo_mode = PSEUDO_REGNO_MODE (ORIGINAL_REGNO (loc));
4764 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (pseudo_mode))
4766 offset += byte_lowpart_offset (pseudo_mode, mode);
4771 /* If LOC is a paradoxical lowpart of EXPR, refer to EXPR itself.
4772 Do the same if we are storing to a register and EXPR occupies
4773 the whole of register LOC; in that case, the whole of EXPR is
4774 being changed. We exclude complex modes from the second case
4775 because the real and imaginary parts are represented as separate
4776 pseudo registers, even if the whole complex value fits into one
4778 if ((GET_MODE_SIZE (mode) > GET_MODE_SIZE (DECL_MODE (expr))
4780 && !COMPLEX_MODE_P (DECL_MODE (expr))
4781 && hard_regno_nregs[REGNO (loc)][DECL_MODE (expr)] == 1))
4782 && offset + byte_lowpart_offset (DECL_MODE (expr), mode) == 0)
4784 mode = DECL_MODE (expr);
4788 if (offset < 0 || offset >= MAX_VAR_PARTS)
4794 *offset_out = offset;
4798 /* Return the MODE lowpart of LOC, or null if LOC is not something we
4799 want to track. When returning nonnull, make sure that the attributes
4800 on the returned value are updated. */
4803 var_lowpart (enum machine_mode mode, rtx loc)
4805 unsigned int offset, reg_offset, regno;
4807 if (!REG_P (loc) && !MEM_P (loc))
4810 if (GET_MODE (loc) == mode)
4813 offset = byte_lowpart_offset (mode, GET_MODE (loc));
4816 return adjust_address_nv (loc, mode, offset);
4818 reg_offset = subreg_lowpart_offset (mode, GET_MODE (loc));
4819 regno = REGNO (loc) + subreg_regno_offset (REGNO (loc), GET_MODE (loc),
4821 return gen_rtx_REG_offset (loc, mode, regno, offset);
4824 /* Carry information about uses and stores while walking rtx. */
4826 struct count_use_info
4828 /* The insn where the RTX is. */
4831 /* The basic block where insn is. */
4834 /* The array of n_sets sets in the insn, as determined by cselib. */
4835 struct cselib_set *sets;
4838 /* True if we're counting stores, false otherwise. */
4842 /* Find a VALUE corresponding to X. */
4844 static inline cselib_val *
4845 find_use_val (rtx x, enum machine_mode mode, struct count_use_info *cui)
4851 /* This is called after uses are set up and before stores are
4852 processed by cselib, so it's safe to look up srcs, but not
4853 dsts. So we look up expressions that appear in srcs or in
4854 dest expressions, but we search the sets array for dests of
4858 /* Some targets represent memset and memcpy patterns
4859 by (set (mem:BLK ...) (reg:[QHSD]I ...)) or
4860 (set (mem:BLK ...) (const_int ...)) or
4861 (set (mem:BLK ...) (mem:BLK ...)). Don't return anything
4862 in that case, otherwise we end up with mode mismatches. */
4863 if (mode == BLKmode && MEM_P (x))
4865 for (i = 0; i < cui->n_sets; i++)
4866 if (cui->sets[i].dest == x)
4867 return cui->sets[i].src_elt;
4870 return cselib_lookup (x, mode, 0, VOIDmode);
4876 /* Helper function to get mode of MEM's address. */
4878 static inline enum machine_mode
4879 get_address_mode (rtx mem)
4881 enum machine_mode mode = GET_MODE (XEXP (mem, 0));
4882 if (mode != VOIDmode)
4884 return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
4887 /* Replace all registers and addresses in an expression with VALUE
4888 expressions that map back to them, unless the expression is a
4889 register. If no mapping is or can be performed, returns NULL. */
4892 replace_expr_with_values (rtx loc)
4894 if (REG_P (loc) || GET_CODE (loc) == ENTRY_VALUE)
4896 else if (MEM_P (loc))
4898 cselib_val *addr = cselib_lookup (XEXP (loc, 0),
4899 get_address_mode (loc), 0,
4902 return replace_equiv_address_nv (loc, addr->val_rtx);
4907 return cselib_subst_to_values (loc, VOIDmode);
4910 /* Determine what kind of micro operation to choose for a USE. Return
4911 MO_CLOBBER if no micro operation is to be generated. */
4913 static enum micro_operation_type
4914 use_type (rtx loc, struct count_use_info *cui, enum machine_mode *modep)
4918 if (cui && cui->sets)
4920 if (GET_CODE (loc) == VAR_LOCATION)
4922 if (track_expr_p (PAT_VAR_LOCATION_DECL (loc), false))
4924 rtx ploc = PAT_VAR_LOCATION_LOC (loc);
4925 if (! VAR_LOC_UNKNOWN_P (ploc))
4927 cselib_val *val = cselib_lookup (ploc, GET_MODE (loc), 1,
4930 /* ??? flag_float_store and volatile mems are never
4931 given values, but we could in theory use them for
4933 gcc_assert (val || 1);
4941 if (REG_P (loc) || MEM_P (loc))
4944 *modep = GET_MODE (loc);
4948 || (find_use_val (loc, GET_MODE (loc), cui)
4949 && cselib_lookup (XEXP (loc, 0),
4950 get_address_mode (loc), 0,
4956 cselib_val *val = find_use_val (loc, GET_MODE (loc), cui);
4958 if (val && !cselib_preserved_value_p (val))
4966 gcc_assert (REGNO (loc) < FIRST_PSEUDO_REGISTER);
4968 if (loc == cfa_base_rtx)
4970 expr = REG_EXPR (loc);
4973 return MO_USE_NO_VAR;
4974 else if (target_for_debug_bind (var_debug_decl (expr)))
4976 else if (track_loc_p (loc, expr, REG_OFFSET (loc),
4977 false, modep, NULL))
4980 return MO_USE_NO_VAR;
4982 else if (MEM_P (loc))
4984 expr = MEM_EXPR (loc);
4988 else if (target_for_debug_bind (var_debug_decl (expr)))
4990 else if (track_loc_p (loc, expr, INT_MEM_OFFSET (loc),
4991 false, modep, NULL))
5000 /* Log to OUT information about micro-operation MOPT involving X in
5004 log_op_type (rtx x, basic_block bb, rtx insn,
5005 enum micro_operation_type mopt, FILE *out)
5007 fprintf (out, "bb %i op %i insn %i %s ",
5008 bb->index, VEC_length (micro_operation, VTI (bb)->mos),
5009 INSN_UID (insn), micro_operation_type_name[mopt]);
5010 print_inline_rtx (out, x, 2);
5014 /* Tell whether the CONCAT used to holds a VALUE and its location
5015 needs value resolution, i.e., an attempt of mapping the location
5016 back to other incoming values. */
5017 #define VAL_NEEDS_RESOLUTION(x) \
5018 (RTL_FLAG_CHECK1 ("VAL_NEEDS_RESOLUTION", (x), CONCAT)->volatil)
5019 /* Whether the location in the CONCAT is a tracked expression, that
5020 should also be handled like a MO_USE. */
5021 #define VAL_HOLDS_TRACK_EXPR(x) \
5022 (RTL_FLAG_CHECK1 ("VAL_HOLDS_TRACK_EXPR", (x), CONCAT)->used)
5023 /* Whether the location in the CONCAT should be handled like a MO_COPY
5025 #define VAL_EXPR_IS_COPIED(x) \
5026 (RTL_FLAG_CHECK1 ("VAL_EXPR_IS_COPIED", (x), CONCAT)->jump)
5027 /* Whether the location in the CONCAT should be handled like a
5028 MO_CLOBBER as well. */
5029 #define VAL_EXPR_IS_CLOBBERED(x) \
5030 (RTL_FLAG_CHECK1 ("VAL_EXPR_IS_CLOBBERED", (x), CONCAT)->unchanging)
5031 /* Whether the location is a CONCAT of the MO_VAL_SET expression and
5032 a reverse operation that should be handled afterwards. */
5033 #define VAL_EXPR_HAS_REVERSE(x) \
5034 (RTL_FLAG_CHECK1 ("VAL_EXPR_HAS_REVERSE", (x), CONCAT)->return_val)
5036 /* All preserved VALUEs. */
5037 static VEC (rtx, heap) *preserved_values;
5039 /* Ensure VAL is preserved and remember it in a vector for vt_emit_notes. */
5042 preserve_value (cselib_val *val)
5044 cselib_preserve_value (val);
5045 VEC_safe_push (rtx, heap, preserved_values, val->val_rtx);
5048 /* Helper function for MO_VAL_LOC handling. Return non-zero if
5049 any rtxes not suitable for CONST use not replaced by VALUEs
5053 non_suitable_const (rtx *x, void *data ATTRIBUTE_UNUSED)
5058 switch (GET_CODE (*x))
5069 return !MEM_READONLY_P (*x);
5075 /* Add uses (register and memory references) LOC which will be tracked
5076 to VTI (bb)->mos. INSN is instruction which the LOC is part of. */
5079 add_uses (rtx *ploc, void *data)
5082 enum machine_mode mode = VOIDmode;
5083 struct count_use_info *cui = (struct count_use_info *)data;
5084 enum micro_operation_type type = use_type (loc, cui, &mode);
5086 if (type != MO_CLOBBER)
5088 basic_block bb = cui->bb;
5092 mo.u.loc = type == MO_USE ? var_lowpart (mode, loc) : loc;
5093 mo.insn = cui->insn;
5095 if (type == MO_VAL_LOC)
5098 rtx vloc = PAT_VAR_LOCATION_LOC (oloc);
5101 gcc_assert (cui->sets);
5104 && !REG_P (XEXP (vloc, 0))
5105 && !MEM_P (XEXP (vloc, 0)))
5108 enum machine_mode address_mode = get_address_mode (mloc);
5110 = cselib_lookup (XEXP (mloc, 0), address_mode, 0,
5113 if (val && !cselib_preserved_value_p (val))
5115 micro_operation moa;
5116 preserve_value (val);
5118 if (GET_CODE (XEXP (mloc, 0)) != ENTRY_VALUE
5119 && (GET_CODE (XEXP (mloc, 0)) != PLUS
5120 || XEXP (XEXP (mloc, 0), 0) != cfa_base_rtx
5121 || !CONST_INT_P (XEXP (XEXP (mloc, 0), 1))))
5123 mloc = cselib_subst_to_values (XEXP (mloc, 0),
5125 moa.type = MO_VAL_USE;
5126 moa.insn = cui->insn;
5127 moa.u.loc = gen_rtx_CONCAT (address_mode,
5128 val->val_rtx, mloc);
5129 if (dump_file && (dump_flags & TDF_DETAILS))
5130 log_op_type (moa.u.loc, cui->bb, cui->insn,
5131 moa.type, dump_file);
5132 VEC_safe_push (micro_operation, heap, VTI (bb)->mos,
5138 if (CONSTANT_P (vloc)
5139 && (GET_CODE (vloc) != CONST
5140 || for_each_rtx (&vloc, non_suitable_const, NULL)))
5141 /* For constants don't look up any value. */;
5142 else if (!VAR_LOC_UNKNOWN_P (vloc) && !unsuitable_loc (vloc)
5143 && (val = find_use_val (vloc, GET_MODE (oloc), cui)))
5145 enum machine_mode mode2;
5146 enum micro_operation_type type2;
5147 rtx nloc = replace_expr_with_values (vloc);
5151 oloc = shallow_copy_rtx (oloc);
5152 PAT_VAR_LOCATION_LOC (oloc) = nloc;
5155 oloc = gen_rtx_CONCAT (mode, val->val_rtx, oloc);
5157 type2 = use_type (vloc, 0, &mode2);
5159 gcc_assert (type2 == MO_USE || type2 == MO_USE_NO_VAR
5160 || type2 == MO_CLOBBER);
5162 if (type2 == MO_CLOBBER
5163 && !cselib_preserved_value_p (val))
5165 VAL_NEEDS_RESOLUTION (oloc) = 1;
5166 preserve_value (val);
5169 else if (!VAR_LOC_UNKNOWN_P (vloc))
5171 oloc = shallow_copy_rtx (oloc);
5172 PAT_VAR_LOCATION_LOC (oloc) = gen_rtx_UNKNOWN_VAR_LOC ();
5177 else if (type == MO_VAL_USE)
5179 enum machine_mode mode2 = VOIDmode;
5180 enum micro_operation_type type2;
5181 cselib_val *val = find_use_val (loc, GET_MODE (loc), cui);
5182 rtx vloc, oloc = loc, nloc;
5184 gcc_assert (cui->sets);
5187 && !REG_P (XEXP (oloc, 0))
5188 && !MEM_P (XEXP (oloc, 0)))
5191 enum machine_mode address_mode = get_address_mode (mloc);
5193 = cselib_lookup (XEXP (mloc, 0), address_mode, 0,
5196 if (val && !cselib_preserved_value_p (val))
5198 micro_operation moa;
5199 preserve_value (val);
5201 if (GET_CODE (XEXP (mloc, 0)) != ENTRY_VALUE
5202 && (GET_CODE (XEXP (mloc, 0)) != PLUS
5203 || XEXP (XEXP (mloc, 0), 0) != cfa_base_rtx
5204 || !CONST_INT_P (XEXP (XEXP (mloc, 0), 1))))
5206 mloc = cselib_subst_to_values (XEXP (mloc, 0),
5208 moa.type = MO_VAL_USE;
5209 moa.insn = cui->insn;
5210 moa.u.loc = gen_rtx_CONCAT (address_mode,
5211 val->val_rtx, mloc);
5212 if (dump_file && (dump_flags & TDF_DETAILS))
5213 log_op_type (moa.u.loc, cui->bb, cui->insn,
5214 moa.type, dump_file);
5215 VEC_safe_push (micro_operation, heap, VTI (bb)->mos,
5221 type2 = use_type (loc, 0, &mode2);
5223 gcc_assert (type2 == MO_USE || type2 == MO_USE_NO_VAR
5224 || type2 == MO_CLOBBER);
5226 if (type2 == MO_USE)
5227 vloc = var_lowpart (mode2, loc);
5231 /* The loc of a MO_VAL_USE may have two forms:
5233 (concat val src): val is at src, a value-based
5236 (concat (concat val use) src): same as above, with use as
5237 the MO_USE tracked value, if it differs from src.
5241 nloc = replace_expr_with_values (loc);
5246 oloc = gen_rtx_CONCAT (mode2, val->val_rtx, vloc);
5248 oloc = val->val_rtx;
5250 mo.u.loc = gen_rtx_CONCAT (mode, oloc, nloc);
5252 if (type2 == MO_USE)
5253 VAL_HOLDS_TRACK_EXPR (mo.u.loc) = 1;
5254 if (!cselib_preserved_value_p (val))
5256 VAL_NEEDS_RESOLUTION (mo.u.loc) = 1;
5257 preserve_value (val);
5261 gcc_assert (type == MO_USE || type == MO_USE_NO_VAR);
5263 if (dump_file && (dump_flags & TDF_DETAILS))
5264 log_op_type (mo.u.loc, cui->bb, cui->insn, mo.type, dump_file);
5265 VEC_safe_push (micro_operation, heap, VTI (bb)->mos, &mo);
5271 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
5274 add_uses_1 (rtx *x, void *cui)
5276 for_each_rtx (x, add_uses, cui);
5279 /* This is the value used during expansion of locations. We want it
5280 to be unbounded, so that variables expanded deep in a recursion
5281 nest are fully evaluated, so that their values are cached
5282 correctly. We avoid recursion cycles through other means, and we
5283 don't unshare RTL, so excess complexity is not a problem. */
5284 #define EXPR_DEPTH (INT_MAX)
5285 /* We use this to keep too-complex expressions from being emitted as
5286 location notes, and then to debug information. Users can trade
5287 compile time for ridiculously complex expressions, although they're
5288 seldom useful, and they may often have to be discarded as not
5289 representable anyway. */
5290 #define EXPR_USE_DEPTH (PARAM_VALUE (PARAM_MAX_VARTRACK_EXPR_DEPTH))
5292 /* Attempt to reverse the EXPR operation in the debug info. Say for
5293 reg1 = reg2 + 6 even when reg2 is no longer live we
5294 can express its value as VAL - 6. */
5297 reverse_op (rtx val, const_rtx expr)
5303 if (GET_CODE (expr) != SET)
5306 if (!REG_P (SET_DEST (expr)) || GET_MODE (val) != GET_MODE (SET_DEST (expr)))
5309 src = SET_SRC (expr);
5310 switch (GET_CODE (src))
5317 if (!REG_P (XEXP (src, 0)))
5322 if (!REG_P (XEXP (src, 0)) && !MEM_P (XEXP (src, 0)))
5329 if (!SCALAR_INT_MODE_P (GET_MODE (src)) || XEXP (src, 0) == cfa_base_rtx)
5332 v = cselib_lookup (XEXP (src, 0), GET_MODE (XEXP (src, 0)), 0, VOIDmode);
5333 if (!v || !cselib_preserved_value_p (v))
5336 switch (GET_CODE (src))
5340 if (GET_MODE (v->val_rtx) != GET_MODE (val))
5342 ret = gen_rtx_fmt_e (GET_CODE (src), GET_MODE (val), val);
5346 ret = gen_lowpart_SUBREG (GET_MODE (v->val_rtx), val);
5358 if (GET_MODE (v->val_rtx) != GET_MODE (val))
5360 arg = XEXP (src, 1);
5361 if (!CONST_INT_P (arg) && GET_CODE (arg) != SYMBOL_REF)
5363 arg = cselib_expand_value_rtx (arg, scratch_regs, 5);
5364 if (arg == NULL_RTX)
5366 if (!CONST_INT_P (arg) && GET_CODE (arg) != SYMBOL_REF)
5369 ret = simplify_gen_binary (code, GET_MODE (val), val, arg);
5371 /* Ensure ret isn't VALUE itself (which can happen e.g. for
5372 (plus (reg1) (reg2)) when reg2 is known to be 0), as that
5373 breaks a lot of routines during var-tracking. */
5374 ret = gen_rtx_fmt_ee (PLUS, GET_MODE (val), val, const0_rtx);
5380 return gen_rtx_CONCAT (GET_MODE (v->val_rtx), v->val_rtx, ret);
5383 /* Add stores (register and memory references) LOC which will be tracked
5384 to VTI (bb)->mos. EXPR is the RTL expression containing the store.
5385 CUIP->insn is instruction which the LOC is part of. */
5388 add_stores (rtx loc, const_rtx expr, void *cuip)
5390 enum machine_mode mode = VOIDmode, mode2;
5391 struct count_use_info *cui = (struct count_use_info *)cuip;
5392 basic_block bb = cui->bb;
5394 rtx oloc = loc, nloc, src = NULL;
5395 enum micro_operation_type type = use_type (loc, cui, &mode);
5396 bool track_p = false;
5398 bool resolve, preserve;
5401 if (type == MO_CLOBBER)
5408 gcc_assert (loc != cfa_base_rtx);
5409 if ((GET_CODE (expr) == CLOBBER && type != MO_VAL_SET)
5410 || !(track_p = use_type (loc, NULL, &mode2) == MO_USE)
5411 || GET_CODE (expr) == CLOBBER)
5413 mo.type = MO_CLOBBER;
5415 if (GET_CODE (expr) == SET
5416 && SET_DEST (expr) == loc
5417 && !unsuitable_loc (SET_SRC (expr))
5418 && find_use_val (loc, mode, cui))
5420 gcc_checking_assert (type == MO_VAL_SET);
5421 mo.u.loc = gen_rtx_SET (VOIDmode, loc, SET_SRC (expr));
5426 if (GET_CODE (expr) == SET
5427 && SET_DEST (expr) == loc
5428 && GET_CODE (SET_SRC (expr)) != ASM_OPERANDS)
5429 src = var_lowpart (mode2, SET_SRC (expr));
5430 loc = var_lowpart (mode2, loc);
5439 rtx xexpr = gen_rtx_SET (VOIDmode, loc, src);
5440 if (same_variable_part_p (src, REG_EXPR (loc), REG_OFFSET (loc)))
5447 mo.insn = cui->insn;
5449 else if (MEM_P (loc)
5450 && ((track_p = use_type (loc, NULL, &mode2) == MO_USE)
5453 if (MEM_P (loc) && type == MO_VAL_SET
5454 && !REG_P (XEXP (loc, 0))
5455 && !MEM_P (XEXP (loc, 0)))
5458 enum machine_mode address_mode = get_address_mode (mloc);
5459 cselib_val *val = cselib_lookup (XEXP (mloc, 0),
5463 if (val && !cselib_preserved_value_p (val))
5465 preserve_value (val);
5467 if (GET_CODE (XEXP (mloc, 0)) != ENTRY_VALUE
5468 && (GET_CODE (XEXP (mloc, 0)) != PLUS
5469 || XEXP (XEXP (mloc, 0), 0) != cfa_base_rtx
5470 || !CONST_INT_P (XEXP (XEXP (mloc, 0), 1))))
5472 mloc = cselib_subst_to_values (XEXP (mloc, 0),
5474 mo.type = MO_VAL_USE;
5475 mo.insn = cui->insn;
5476 mo.u.loc = gen_rtx_CONCAT (address_mode,
5477 val->val_rtx, mloc);
5478 if (dump_file && (dump_flags & TDF_DETAILS))
5479 log_op_type (mo.u.loc, cui->bb, cui->insn,
5480 mo.type, dump_file);
5481 VEC_safe_push (micro_operation, heap, VTI (bb)->mos, &mo);
5486 if (GET_CODE (expr) == CLOBBER || !track_p)
5488 mo.type = MO_CLOBBER;
5489 mo.u.loc = track_p ? var_lowpart (mode2, loc) : loc;
5493 if (GET_CODE (expr) == SET
5494 && SET_DEST (expr) == loc
5495 && GET_CODE (SET_SRC (expr)) != ASM_OPERANDS)
5496 src = var_lowpart (mode2, SET_SRC (expr));
5497 loc = var_lowpart (mode2, loc);
5506 rtx xexpr = gen_rtx_SET (VOIDmode, loc, src);
5507 if (same_variable_part_p (SET_SRC (xexpr),
5509 INT_MEM_OFFSET (loc)))
5516 mo.insn = cui->insn;
5521 if (type != MO_VAL_SET)
5522 goto log_and_return;
5524 v = find_use_val (oloc, mode, cui);
5527 goto log_and_return;
5529 resolve = preserve = !cselib_preserved_value_p (v);
5531 nloc = replace_expr_with_values (oloc);
5535 if (GET_CODE (PATTERN (cui->insn)) == COND_EXEC)
5537 cselib_val *oval = cselib_lookup (oloc, GET_MODE (oloc), 0, VOIDmode);
5539 gcc_assert (oval != v);
5540 gcc_assert (REG_P (oloc) || MEM_P (oloc));
5542 if (!cselib_preserved_value_p (oval))
5544 micro_operation moa;
5546 preserve_value (oval);
5548 moa.type = MO_VAL_USE;
5549 moa.u.loc = gen_rtx_CONCAT (mode, oval->val_rtx, oloc);
5550 VAL_NEEDS_RESOLUTION (moa.u.loc) = 1;
5551 moa.insn = cui->insn;
5553 if (dump_file && (dump_flags & TDF_DETAILS))
5554 log_op_type (moa.u.loc, cui->bb, cui->insn,
5555 moa.type, dump_file);
5556 VEC_safe_push (micro_operation, heap, VTI (bb)->mos, &moa);
5561 else if (resolve && GET_CODE (mo.u.loc) == SET)
5563 nloc = replace_expr_with_values (SET_SRC (expr));
5565 /* Avoid the mode mismatch between oexpr and expr. */
5566 if (!nloc && mode != mode2)
5568 nloc = SET_SRC (expr);
5569 gcc_assert (oloc == SET_DEST (expr));
5573 oloc = gen_rtx_SET (GET_MODE (mo.u.loc), oloc, nloc);
5576 if (oloc == SET_DEST (mo.u.loc))
5577 /* No point in duplicating. */
5579 if (!REG_P (SET_SRC (mo.u.loc)))
5585 if (GET_CODE (mo.u.loc) == SET
5586 && oloc == SET_DEST (mo.u.loc))
5587 /* No point in duplicating. */
5593 loc = gen_rtx_CONCAT (mode, v->val_rtx, oloc);
5595 if (mo.u.loc != oloc)
5596 loc = gen_rtx_CONCAT (GET_MODE (mo.u.loc), loc, mo.u.loc);
5598 /* The loc of a MO_VAL_SET may have various forms:
5600 (concat val dst): dst now holds val
5602 (concat val (set dst src)): dst now holds val, copied from src
5604 (concat (concat val dstv) dst): dst now holds val; dstv is dst
5605 after replacing mems and non-top-level regs with values.
5607 (concat (concat val dstv) (set dst src)): dst now holds val,
5608 copied from src. dstv is a value-based representation of dst, if
5609 it differs from dst. If resolution is needed, src is a REG, and
5610 its mode is the same as that of val.
5612 (concat (concat val (set dstv srcv)) (set dst src)): src
5613 copied to dst, holding val. dstv and srcv are value-based
5614 representations of dst and src, respectively.
5618 if (GET_CODE (PATTERN (cui->insn)) != COND_EXEC)
5620 reverse = reverse_op (v->val_rtx, expr);
5623 loc = gen_rtx_CONCAT (GET_MODE (mo.u.loc), loc, reverse);
5624 VAL_EXPR_HAS_REVERSE (loc) = 1;
5631 VAL_HOLDS_TRACK_EXPR (loc) = 1;
5634 VAL_NEEDS_RESOLUTION (loc) = resolve;
5637 if (mo.type == MO_CLOBBER)
5638 VAL_EXPR_IS_CLOBBERED (loc) = 1;
5639 if (mo.type == MO_COPY)
5640 VAL_EXPR_IS_COPIED (loc) = 1;
5642 mo.type = MO_VAL_SET;
5645 if (dump_file && (dump_flags & TDF_DETAILS))
5646 log_op_type (mo.u.loc, cui->bb, cui->insn, mo.type, dump_file);
5647 VEC_safe_push (micro_operation, heap, VTI (bb)->mos, &mo);
5650 /* Arguments to the call. */
5651 static rtx call_arguments;
5653 /* Compute call_arguments. */
5656 prepare_call_arguments (basic_block bb, rtx insn)
5659 rtx prev, cur, next;
5660 rtx call = PATTERN (insn);
5661 rtx this_arg = NULL_RTX;
5662 tree type = NULL_TREE, t, fndecl = NULL_TREE;
5663 tree obj_type_ref = NULL_TREE;
5664 CUMULATIVE_ARGS args_so_far_v;
5665 cumulative_args_t args_so_far;
5667 memset (&args_so_far_v, 0, sizeof (args_so_far_v));
5668 args_so_far = pack_cumulative_args (&args_so_far_v);
5669 if (GET_CODE (call) == PARALLEL)
5670 call = XVECEXP (call, 0, 0);
5671 if (GET_CODE (call) == SET)
5672 call = SET_SRC (call);
5673 if (GET_CODE (call) == CALL && MEM_P (XEXP (call, 0)))
5675 if (GET_CODE (XEXP (XEXP (call, 0), 0)) == SYMBOL_REF)
5677 rtx symbol = XEXP (XEXP (call, 0), 0);
5678 if (SYMBOL_REF_DECL (symbol))
5679 fndecl = SYMBOL_REF_DECL (symbol);
5681 if (fndecl == NULL_TREE)
5682 fndecl = MEM_EXPR (XEXP (call, 0));
5684 && TREE_CODE (TREE_TYPE (fndecl)) != FUNCTION_TYPE
5685 && TREE_CODE (TREE_TYPE (fndecl)) != METHOD_TYPE)
5687 if (fndecl && TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
5688 type = TREE_TYPE (fndecl);
5689 if (fndecl && TREE_CODE (fndecl) != FUNCTION_DECL)
5691 if (TREE_CODE (fndecl) == INDIRECT_REF
5692 && TREE_CODE (TREE_OPERAND (fndecl, 0)) == OBJ_TYPE_REF)
5693 obj_type_ref = TREE_OPERAND (fndecl, 0);
5698 for (t = TYPE_ARG_TYPES (type); t && t != void_list_node;
5700 if (TREE_CODE (TREE_VALUE (t)) == REFERENCE_TYPE
5701 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_VALUE (t))))
5703 if ((t == NULL || t == void_list_node) && obj_type_ref == NULL_TREE)
5707 int nargs ATTRIBUTE_UNUSED = list_length (TYPE_ARG_TYPES (type));
5708 link = CALL_INSN_FUNCTION_USAGE (insn);
5709 #ifndef PCC_STATIC_STRUCT_RETURN
5710 if (aggregate_value_p (TREE_TYPE (type), type)
5711 && targetm.calls.struct_value_rtx (type, 0) == 0)
5713 tree struct_addr = build_pointer_type (TREE_TYPE (type));
5714 enum machine_mode mode = TYPE_MODE (struct_addr);
5716 INIT_CUMULATIVE_ARGS (args_so_far_v, type, NULL_RTX, fndecl,
5718 reg = targetm.calls.function_arg (args_so_far, mode,
5720 targetm.calls.function_arg_advance (args_so_far, mode,
5722 if (reg == NULL_RTX)
5724 for (; link; link = XEXP (link, 1))
5725 if (GET_CODE (XEXP (link, 0)) == USE
5726 && MEM_P (XEXP (XEXP (link, 0), 0)))
5728 link = XEXP (link, 1);
5735 INIT_CUMULATIVE_ARGS (args_so_far_v, type, NULL_RTX, fndecl,
5737 if (obj_type_ref && TYPE_ARG_TYPES (type) != void_list_node)
5739 enum machine_mode mode;
5740 t = TYPE_ARG_TYPES (type);
5741 mode = TYPE_MODE (TREE_VALUE (t));
5742 this_arg = targetm.calls.function_arg (args_so_far, mode,
5743 TREE_VALUE (t), true);
5744 if (this_arg && !REG_P (this_arg))
5745 this_arg = NULL_RTX;
5746 else if (this_arg == NULL_RTX)
5748 for (; link; link = XEXP (link, 1))
5749 if (GET_CODE (XEXP (link, 0)) == USE
5750 && MEM_P (XEXP (XEXP (link, 0), 0)))
5752 this_arg = XEXP (XEXP (link, 0), 0);
5760 t = type ? TYPE_ARG_TYPES (type) : NULL_TREE;
5762 for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
5763 if (GET_CODE (XEXP (link, 0)) == USE)
5765 rtx item = NULL_RTX;
5766 x = XEXP (XEXP (link, 0), 0);
5767 if (GET_MODE (link) == VOIDmode
5768 || GET_MODE (link) == BLKmode
5769 || (GET_MODE (link) != GET_MODE (x)
5770 && (GET_MODE_CLASS (GET_MODE (link)) != MODE_INT
5771 || GET_MODE_CLASS (GET_MODE (x)) != MODE_INT)))
5772 /* Can't do anything for these, if the original type mode
5773 isn't known or can't be converted. */;
5776 cselib_val *val = cselib_lookup (x, GET_MODE (x), 0, VOIDmode);
5777 if (val && cselib_preserved_value_p (val))
5778 item = val->val_rtx;
5779 else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
5781 enum machine_mode mode = GET_MODE (x);
5783 while ((mode = GET_MODE_WIDER_MODE (mode)) != VOIDmode
5784 && GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
5786 rtx reg = simplify_subreg (mode, x, GET_MODE (x), 0);
5788 if (reg == NULL_RTX || !REG_P (reg))
5790 val = cselib_lookup (reg, mode, 0, VOIDmode);
5791 if (val && cselib_preserved_value_p (val))
5793 item = val->val_rtx;
5804 if (!frame_pointer_needed)
5806 struct adjust_mem_data amd;
5807 amd.mem_mode = VOIDmode;
5808 amd.stack_adjust = -VTI (bb)->out.stack_adjust;
5809 amd.side_effects = NULL_RTX;
5811 mem = simplify_replace_fn_rtx (mem, NULL_RTX, adjust_mems,
5813 gcc_assert (amd.side_effects == NULL_RTX);
5815 val = cselib_lookup (mem, GET_MODE (mem), 0, VOIDmode);
5816 if (val && cselib_preserved_value_p (val))
5817 item = val->val_rtx;
5818 else if (GET_MODE_CLASS (GET_MODE (mem)) != MODE_INT)
5820 /* For non-integer stack argument see also if they weren't
5821 initialized by integers. */
5822 enum machine_mode imode = int_mode_for_mode (GET_MODE (mem));
5823 if (imode != GET_MODE (mem) && imode != BLKmode)
5825 val = cselib_lookup (adjust_address_nv (mem, imode, 0),
5826 imode, 0, VOIDmode);
5827 if (val && cselib_preserved_value_p (val))
5828 item = lowpart_subreg (GET_MODE (x), val->val_rtx,
5836 if (GET_MODE (item) != GET_MODE (link))
5837 item = lowpart_subreg (GET_MODE (link), item, GET_MODE (item));
5838 if (GET_MODE (x2) != GET_MODE (link))
5839 x2 = lowpart_subreg (GET_MODE (link), x2, GET_MODE (x2));
5840 item = gen_rtx_CONCAT (GET_MODE (link), x2, item);
5842 = gen_rtx_EXPR_LIST (VOIDmode, item, call_arguments);
5844 if (t && t != void_list_node)
5846 tree argtype = TREE_VALUE (t);
5847 enum machine_mode mode = TYPE_MODE (argtype);
5849 if (pass_by_reference (&args_so_far_v, mode, argtype, true))
5851 argtype = build_pointer_type (argtype);
5852 mode = TYPE_MODE (argtype);
5854 reg = targetm.calls.function_arg (args_so_far, mode,
5856 if (TREE_CODE (argtype) == REFERENCE_TYPE
5857 && INTEGRAL_TYPE_P (TREE_TYPE (argtype))
5860 && GET_MODE (reg) == mode
5861 && GET_MODE_CLASS (mode) == MODE_INT
5863 && REGNO (x) == REGNO (reg)
5864 && GET_MODE (x) == mode
5867 enum machine_mode indmode
5868 = TYPE_MODE (TREE_TYPE (argtype));
5869 rtx mem = gen_rtx_MEM (indmode, x);
5870 cselib_val *val = cselib_lookup (mem, indmode, 0, VOIDmode);
5871 if (val && cselib_preserved_value_p (val))
5873 item = gen_rtx_CONCAT (indmode, mem, val->val_rtx);
5874 call_arguments = gen_rtx_EXPR_LIST (VOIDmode, item,
5879 struct elt_loc_list *l;
5882 /* Try harder, when passing address of a constant
5883 pool integer it can be easily read back. */
5884 item = XEXP (item, 1);
5885 if (GET_CODE (item) == SUBREG)
5886 item = SUBREG_REG (item);
5887 gcc_assert (GET_CODE (item) == VALUE);
5888 val = CSELIB_VAL_PTR (item);
5889 for (l = val->locs; l; l = l->next)
5890 if (GET_CODE (l->loc) == SYMBOL_REF
5891 && TREE_CONSTANT_POOL_ADDRESS_P (l->loc)
5892 && SYMBOL_REF_DECL (l->loc)
5893 && DECL_INITIAL (SYMBOL_REF_DECL (l->loc)))
5895 initial = DECL_INITIAL (SYMBOL_REF_DECL (l->loc));
5896 if (host_integerp (initial, 0))
5898 item = GEN_INT (tree_low_cst (initial, 0));
5899 item = gen_rtx_CONCAT (indmode, mem, item);
5901 = gen_rtx_EXPR_LIST (VOIDmode, item,
5908 targetm.calls.function_arg_advance (args_so_far, mode,
5914 /* Add debug arguments. */
5916 && TREE_CODE (fndecl) == FUNCTION_DECL
5917 && DECL_HAS_DEBUG_ARGS_P (fndecl))
5919 VEC(tree, gc) **debug_args = decl_debug_args_lookup (fndecl);
5924 for (ix = 0; VEC_iterate (tree, *debug_args, ix, param); ix += 2)
5927 tree dtemp = VEC_index (tree, *debug_args, ix + 1);
5928 enum machine_mode mode = DECL_MODE (dtemp);
5929 item = gen_rtx_DEBUG_PARAMETER_REF (mode, param);
5930 item = gen_rtx_CONCAT (mode, item, DECL_RTL_KNOWN_SET (dtemp));
5931 call_arguments = gen_rtx_EXPR_LIST (VOIDmode, item,
5937 /* Reverse call_arguments chain. */
5939 for (cur = call_arguments; cur; cur = next)
5941 next = XEXP (cur, 1);
5942 XEXP (cur, 1) = prev;
5945 call_arguments = prev;
5948 if (GET_CODE (x) == PARALLEL)
5949 x = XVECEXP (x, 0, 0);
5950 if (GET_CODE (x) == SET)
5952 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
5954 x = XEXP (XEXP (x, 0), 0);
5955 if (GET_CODE (x) == SYMBOL_REF)
5956 /* Don't record anything. */;
5957 else if (CONSTANT_P (x))
5959 x = gen_rtx_CONCAT (GET_MODE (x) == VOIDmode ? Pmode : GET_MODE (x),
5962 = gen_rtx_EXPR_LIST (VOIDmode, x, call_arguments);
5966 cselib_val *val = cselib_lookup (x, GET_MODE (x), 0, VOIDmode);
5967 if (val && cselib_preserved_value_p (val))
5969 x = gen_rtx_CONCAT (GET_MODE (x), pc_rtx, val->val_rtx);
5971 = gen_rtx_EXPR_LIST (VOIDmode, x, call_arguments);
5977 enum machine_mode mode
5978 = TYPE_MODE (TREE_TYPE (OBJ_TYPE_REF_EXPR (obj_type_ref)));
5979 rtx clobbered = gen_rtx_MEM (mode, this_arg);
5981 = tree_low_cst (OBJ_TYPE_REF_TOKEN (obj_type_ref), 0);
5983 clobbered = plus_constant (clobbered, token * GET_MODE_SIZE (mode));
5984 clobbered = gen_rtx_MEM (mode, clobbered);
5985 x = gen_rtx_CONCAT (mode, gen_rtx_CLOBBER (VOIDmode, pc_rtx), clobbered);
5987 = gen_rtx_EXPR_LIST (VOIDmode, x, call_arguments);
5991 /* Callback for cselib_record_sets_hook, that records as micro
5992 operations uses and stores in an insn after cselib_record_sets has
5993 analyzed the sets in an insn, but before it modifies the stored
5994 values in the internal tables, unless cselib_record_sets doesn't
5995 call it directly (perhaps because we're not doing cselib in the
5996 first place, in which case sets and n_sets will be 0). */
5999 add_with_sets (rtx insn, struct cselib_set *sets, int n_sets)
6001 basic_block bb = BLOCK_FOR_INSN (insn);
6003 struct count_use_info cui;
6004 micro_operation *mos;
6006 cselib_hook_called = true;
6011 cui.n_sets = n_sets;
6013 n1 = VEC_length (micro_operation, VTI (bb)->mos);
6014 cui.store_p = false;
6015 note_uses (&PATTERN (insn), add_uses_1, &cui);
6016 n2 = VEC_length (micro_operation, VTI (bb)->mos) - 1;
6017 mos = VEC_address (micro_operation, VTI (bb)->mos);
6019 /* Order the MO_USEs to be before MO_USE_NO_VARs and MO_VAL_USE, and
6023 while (n1 < n2 && mos[n1].type == MO_USE)
6025 while (n1 < n2 && mos[n2].type != MO_USE)
6037 n2 = VEC_length (micro_operation, VTI (bb)->mos) - 1;
6040 while (n1 < n2 && mos[n1].type != MO_VAL_LOC)
6042 while (n1 < n2 && mos[n2].type == MO_VAL_LOC)
6060 mo.u.loc = call_arguments;
6061 call_arguments = NULL_RTX;
6063 if (dump_file && (dump_flags & TDF_DETAILS))
6064 log_op_type (PATTERN (insn), bb, insn, mo.type, dump_file);
6065 VEC_safe_push (micro_operation, heap, VTI (bb)->mos, &mo);
6068 n1 = VEC_length (micro_operation, VTI (bb)->mos);
6069 /* This will record NEXT_INSN (insn), such that we can
6070 insert notes before it without worrying about any
6071 notes that MO_USEs might emit after the insn. */
6073 note_stores (PATTERN (insn), add_stores, &cui);
6074 n2 = VEC_length (micro_operation, VTI (bb)->mos) - 1;
6075 mos = VEC_address (micro_operation, VTI (bb)->mos);
6077 /* Order the MO_VAL_USEs first (note_stores does nothing
6078 on DEBUG_INSNs, so there are no MO_VAL_LOCs from this
6079 insn), then MO_CLOBBERs, then MO_SET/MO_COPY/MO_VAL_SET. */
6082 while (n1 < n2 && mos[n1].type == MO_VAL_USE)
6084 while (n1 < n2 && mos[n2].type != MO_VAL_USE)
6096 n2 = VEC_length (micro_operation, VTI (bb)->mos) - 1;
6099 while (n1 < n2 && mos[n1].type == MO_CLOBBER)
6101 while (n1 < n2 && mos[n2].type != MO_CLOBBER)
6114 static enum var_init_status
6115 find_src_status (dataflow_set *in, rtx src)
6117 tree decl = NULL_TREE;
6118 enum var_init_status status = VAR_INIT_STATUS_UNINITIALIZED;
6120 if (! flag_var_tracking_uninit)
6121 status = VAR_INIT_STATUS_INITIALIZED;
6123 if (src && REG_P (src))
6124 decl = var_debug_decl (REG_EXPR (src));
6125 else if (src && MEM_P (src))
6126 decl = var_debug_decl (MEM_EXPR (src));
6129 status = get_init_value (in, src, dv_from_decl (decl));
6134 /* SRC is the source of an assignment. Use SET to try to find what
6135 was ultimately assigned to SRC. Return that value if known,
6136 otherwise return SRC itself. */
6139 find_src_set_src (dataflow_set *set, rtx src)
6141 tree decl = NULL_TREE; /* The variable being copied around. */
6142 rtx set_src = NULL_RTX; /* The value for "decl" stored in "src". */
6144 location_chain nextp;
6148 if (src && REG_P (src))
6149 decl = var_debug_decl (REG_EXPR (src));
6150 else if (src && MEM_P (src))
6151 decl = var_debug_decl (MEM_EXPR (src));
6155 decl_or_value dv = dv_from_decl (decl);
6157 var = shared_hash_find (set->vars, dv);
6161 for (i = 0; i < var->n_var_parts && !found; i++)
6162 for (nextp = var->var_part[i].loc_chain; nextp && !found;
6163 nextp = nextp->next)
6164 if (rtx_equal_p (nextp->loc, src))
6166 set_src = nextp->set_src;
6176 /* Compute the changes of variable locations in the basic block BB. */
6179 compute_bb_dataflow (basic_block bb)
6182 micro_operation *mo;
6184 dataflow_set old_out;
6185 dataflow_set *in = &VTI (bb)->in;
6186 dataflow_set *out = &VTI (bb)->out;
6188 dataflow_set_init (&old_out);
6189 dataflow_set_copy (&old_out, out);
6190 dataflow_set_copy (out, in);
6192 FOR_EACH_VEC_ELT (micro_operation, VTI (bb)->mos, i, mo)
6194 rtx insn = mo->insn;
6199 dataflow_set_clear_at_call (out);
6204 rtx loc = mo->u.loc;
6207 var_reg_set (out, loc, VAR_INIT_STATUS_UNINITIALIZED, NULL);
6208 else if (MEM_P (loc))
6209 var_mem_set (out, loc, VAR_INIT_STATUS_UNINITIALIZED, NULL);
6215 rtx loc = mo->u.loc;
6219 if (GET_CODE (loc) == CONCAT)
6221 val = XEXP (loc, 0);
6222 vloc = XEXP (loc, 1);
6230 var = PAT_VAR_LOCATION_DECL (vloc);
6232 clobber_variable_part (out, NULL_RTX,
6233 dv_from_decl (var), 0, NULL_RTX);
6236 if (VAL_NEEDS_RESOLUTION (loc))
6237 val_resolve (out, val, PAT_VAR_LOCATION_LOC (vloc), insn);
6238 set_variable_part (out, val, dv_from_decl (var), 0,
6239 VAR_INIT_STATUS_INITIALIZED, NULL_RTX,
6242 else if (!VAR_LOC_UNKNOWN_P (PAT_VAR_LOCATION_LOC (vloc)))
6243 set_variable_part (out, PAT_VAR_LOCATION_LOC (vloc),
6244 dv_from_decl (var), 0,
6245 VAR_INIT_STATUS_INITIALIZED, NULL_RTX,
6252 rtx loc = mo->u.loc;
6253 rtx val, vloc, uloc;
6255 vloc = uloc = XEXP (loc, 1);
6256 val = XEXP (loc, 0);
6258 if (GET_CODE (val) == CONCAT)
6260 uloc = XEXP (val, 1);
6261 val = XEXP (val, 0);
6264 if (VAL_NEEDS_RESOLUTION (loc))
6265 val_resolve (out, val, vloc, insn);
6267 val_store (out, val, uloc, insn, false);
6269 if (VAL_HOLDS_TRACK_EXPR (loc))
6271 if (GET_CODE (uloc) == REG)
6272 var_reg_set (out, uloc, VAR_INIT_STATUS_UNINITIALIZED,
6274 else if (GET_CODE (uloc) == MEM)
6275 var_mem_set (out, uloc, VAR_INIT_STATUS_UNINITIALIZED,
6283 rtx loc = mo->u.loc;
6284 rtx val, vloc, uloc, reverse = NULL_RTX;
6287 if (VAL_EXPR_HAS_REVERSE (loc))
6289 reverse = XEXP (loc, 1);
6290 vloc = XEXP (loc, 0);
6292 uloc = XEXP (vloc, 1);
6293 val = XEXP (vloc, 0);
6296 if (GET_CODE (val) == CONCAT)
6298 vloc = XEXP (val, 1);
6299 val = XEXP (val, 0);
6302 if (GET_CODE (vloc) == SET)
6304 rtx vsrc = SET_SRC (vloc);
6306 gcc_assert (val != vsrc);
6307 gcc_assert (vloc == uloc || VAL_NEEDS_RESOLUTION (loc));
6309 vloc = SET_DEST (vloc);
6311 if (VAL_NEEDS_RESOLUTION (loc))
6312 val_resolve (out, val, vsrc, insn);
6314 else if (VAL_NEEDS_RESOLUTION (loc))
6316 gcc_assert (GET_CODE (uloc) == SET
6317 && GET_CODE (SET_SRC (uloc)) == REG);
6318 val_resolve (out, val, SET_SRC (uloc), insn);
6321 if (VAL_HOLDS_TRACK_EXPR (loc))
6323 if (VAL_EXPR_IS_CLOBBERED (loc))
6326 var_reg_delete (out, uloc, true);
6327 else if (MEM_P (uloc))
6328 var_mem_delete (out, uloc, true);
6332 bool copied_p = VAL_EXPR_IS_COPIED (loc);
6334 enum var_init_status status = VAR_INIT_STATUS_INITIALIZED;
6336 if (GET_CODE (uloc) == SET)
6338 set_src = SET_SRC (uloc);
6339 uloc = SET_DEST (uloc);
6344 if (flag_var_tracking_uninit)
6346 status = find_src_status (in, set_src);
6348 if (status == VAR_INIT_STATUS_UNKNOWN)
6349 status = find_src_status (out, set_src);
6352 set_src = find_src_set_src (in, set_src);
6356 var_reg_delete_and_set (out, uloc, !copied_p,
6358 else if (MEM_P (uloc))
6359 var_mem_delete_and_set (out, uloc, !copied_p,
6363 else if (REG_P (uloc))
6364 var_regno_delete (out, REGNO (uloc));
6366 val_store (out, val, vloc, insn, true);
6369 val_store (out, XEXP (reverse, 0), XEXP (reverse, 1),
6376 rtx loc = mo->u.loc;
6379 if (GET_CODE (loc) == SET)
6381 set_src = SET_SRC (loc);
6382 loc = SET_DEST (loc);
6386 var_reg_delete_and_set (out, loc, true, VAR_INIT_STATUS_INITIALIZED,
6388 else if (MEM_P (loc))
6389 var_mem_delete_and_set (out, loc, true, VAR_INIT_STATUS_INITIALIZED,
6396 rtx loc = mo->u.loc;
6397 enum var_init_status src_status;
6400 if (GET_CODE (loc) == SET)
6402 set_src = SET_SRC (loc);
6403 loc = SET_DEST (loc);
6406 if (! flag_var_tracking_uninit)
6407 src_status = VAR_INIT_STATUS_INITIALIZED;
6410 src_status = find_src_status (in, set_src);
6412 if (src_status == VAR_INIT_STATUS_UNKNOWN)
6413 src_status = find_src_status (out, set_src);
6416 set_src = find_src_set_src (in, set_src);
6419 var_reg_delete_and_set (out, loc, false, src_status, set_src);
6420 else if (MEM_P (loc))
6421 var_mem_delete_and_set (out, loc, false, src_status, set_src);
6427 rtx loc = mo->u.loc;
6430 var_reg_delete (out, loc, false);
6431 else if (MEM_P (loc))
6432 var_mem_delete (out, loc, false);
6438 rtx loc = mo->u.loc;
6441 var_reg_delete (out, loc, true);
6442 else if (MEM_P (loc))
6443 var_mem_delete (out, loc, true);
6448 out->stack_adjust += mo->u.adjust;
6453 if (MAY_HAVE_DEBUG_INSNS)
6455 dataflow_set_equiv_regs (out);
6456 htab_traverse (shared_hash_htab (out->vars), canonicalize_values_mark,
6458 htab_traverse (shared_hash_htab (out->vars), canonicalize_values_star,
6461 htab_traverse (shared_hash_htab (out->vars),
6462 canonicalize_loc_order_check, out);
6465 changed = dataflow_set_different (&old_out, out);
6466 dataflow_set_destroy (&old_out);
6470 /* Find the locations of variables in the whole function. */
6473 vt_find_locations (void)
6475 fibheap_t worklist, pending, fibheap_swap;
6476 sbitmap visited, in_worklist, in_pending, sbitmap_swap;
6483 int htabmax = PARAM_VALUE (PARAM_MAX_VARTRACK_SIZE);
6484 bool success = true;
6486 timevar_push (TV_VAR_TRACKING_DATAFLOW);
6487 /* Compute reverse completion order of depth first search of the CFG
6488 so that the data-flow runs faster. */
6489 rc_order = XNEWVEC (int, n_basic_blocks - NUM_FIXED_BLOCKS);
6490 bb_order = XNEWVEC (int, last_basic_block);
6491 pre_and_rev_post_order_compute (NULL, rc_order, false);
6492 for (i = 0; i < n_basic_blocks - NUM_FIXED_BLOCKS; i++)
6493 bb_order[rc_order[i]] = i;
6496 worklist = fibheap_new ();
6497 pending = fibheap_new ();
6498 visited = sbitmap_alloc (last_basic_block);
6499 in_worklist = sbitmap_alloc (last_basic_block);
6500 in_pending = sbitmap_alloc (last_basic_block);
6501 sbitmap_zero (in_worklist);
6504 fibheap_insert (pending, bb_order[bb->index], bb);
6505 sbitmap_ones (in_pending);
6507 while (success && !fibheap_empty (pending))
6509 fibheap_swap = pending;
6511 worklist = fibheap_swap;
6512 sbitmap_swap = in_pending;
6513 in_pending = in_worklist;
6514 in_worklist = sbitmap_swap;
6516 sbitmap_zero (visited);
6518 while (!fibheap_empty (worklist))
6520 bb = (basic_block) fibheap_extract_min (worklist);
6521 RESET_BIT (in_worklist, bb->index);
6522 gcc_assert (!TEST_BIT (visited, bb->index));
6523 if (!TEST_BIT (visited, bb->index))
6527 int oldinsz, oldoutsz;
6529 SET_BIT (visited, bb->index);
6531 if (VTI (bb)->in.vars)
6534 -= (htab_size (shared_hash_htab (VTI (bb)->in.vars))
6535 + htab_size (shared_hash_htab (VTI (bb)->out.vars)));
6537 = htab_elements (shared_hash_htab (VTI (bb)->in.vars));
6539 = htab_elements (shared_hash_htab (VTI (bb)->out.vars));
6542 oldinsz = oldoutsz = 0;
6544 if (MAY_HAVE_DEBUG_INSNS)
6546 dataflow_set *in = &VTI (bb)->in, *first_out = NULL;
6547 bool first = true, adjust = false;
6549 /* Calculate the IN set as the intersection of
6550 predecessor OUT sets. */
6552 dataflow_set_clear (in);
6553 dst_can_be_shared = true;
6555 FOR_EACH_EDGE (e, ei, bb->preds)
6556 if (!VTI (e->src)->flooded)
6557 gcc_assert (bb_order[bb->index]
6558 <= bb_order[e->src->index]);
6561 dataflow_set_copy (in, &VTI (e->src)->out);
6562 first_out = &VTI (e->src)->out;
6567 dataflow_set_merge (in, &VTI (e->src)->out);
6573 dataflow_post_merge_adjust (in, &VTI (bb)->permp);
6575 /* Merge and merge_adjust should keep entries in
6577 htab_traverse (shared_hash_htab (in->vars),
6578 canonicalize_loc_order_check,
6581 if (dst_can_be_shared)
6583 shared_hash_destroy (in->vars);
6584 in->vars = shared_hash_copy (first_out->vars);
6588 VTI (bb)->flooded = true;
6592 /* Calculate the IN set as union of predecessor OUT sets. */
6593 dataflow_set_clear (&VTI (bb)->in);
6594 FOR_EACH_EDGE (e, ei, bb->preds)
6595 dataflow_set_union (&VTI (bb)->in, &VTI (e->src)->out);
6598 changed = compute_bb_dataflow (bb);
6599 htabsz += (htab_size (shared_hash_htab (VTI (bb)->in.vars))
6600 + htab_size (shared_hash_htab (VTI (bb)->out.vars)));
6602 if (htabmax && htabsz > htabmax)
6604 if (MAY_HAVE_DEBUG_INSNS)
6605 inform (DECL_SOURCE_LOCATION (cfun->decl),
6606 "variable tracking size limit exceeded with "
6607 "-fvar-tracking-assignments, retrying without");
6609 inform (DECL_SOURCE_LOCATION (cfun->decl),
6610 "variable tracking size limit exceeded");
6617 FOR_EACH_EDGE (e, ei, bb->succs)
6619 if (e->dest == EXIT_BLOCK_PTR)
6622 if (TEST_BIT (visited, e->dest->index))
6624 if (!TEST_BIT (in_pending, e->dest->index))
6626 /* Send E->DEST to next round. */
6627 SET_BIT (in_pending, e->dest->index);
6628 fibheap_insert (pending,
6629 bb_order[e->dest->index],
6633 else if (!TEST_BIT (in_worklist, e->dest->index))
6635 /* Add E->DEST to current round. */
6636 SET_BIT (in_worklist, e->dest->index);
6637 fibheap_insert (worklist, bb_order[e->dest->index],
6645 "BB %i: in %i (was %i), out %i (was %i), rem %i + %i, tsz %i\n",
6647 (int)htab_elements (shared_hash_htab (VTI (bb)->in.vars)),
6649 (int)htab_elements (shared_hash_htab (VTI (bb)->out.vars)),
6651 (int)worklist->nodes, (int)pending->nodes, htabsz);
6653 if (dump_file && (dump_flags & TDF_DETAILS))
6655 fprintf (dump_file, "BB %i IN:\n", bb->index);
6656 dump_dataflow_set (&VTI (bb)->in);
6657 fprintf (dump_file, "BB %i OUT:\n", bb->index);
6658 dump_dataflow_set (&VTI (bb)->out);
6664 if (success && MAY_HAVE_DEBUG_INSNS)
6666 gcc_assert (VTI (bb)->flooded);
6669 fibheap_delete (worklist);
6670 fibheap_delete (pending);
6671 sbitmap_free (visited);
6672 sbitmap_free (in_worklist);
6673 sbitmap_free (in_pending);
6675 timevar_pop (TV_VAR_TRACKING_DATAFLOW);
6679 /* Print the content of the LIST to dump file. */
6682 dump_attrs_list (attrs list)
6684 for (; list; list = list->next)
6686 if (dv_is_decl_p (list->dv))
6687 print_mem_expr (dump_file, dv_as_decl (list->dv));
6689 print_rtl_single (dump_file, dv_as_value (list->dv));
6690 fprintf (dump_file, "+" HOST_WIDE_INT_PRINT_DEC, list->offset);
6692 fprintf (dump_file, "\n");
6695 /* Print the information about variable *SLOT to dump file. */
6698 dump_var_slot (void **slot, void *data ATTRIBUTE_UNUSED)
6700 variable var = (variable) *slot;
6704 /* Continue traversing the hash table. */
6708 /* Print the information about variable VAR to dump file. */
6711 dump_var (variable var)
6714 location_chain node;
6716 if (dv_is_decl_p (var->dv))
6718 const_tree decl = dv_as_decl (var->dv);
6720 if (DECL_NAME (decl))
6722 fprintf (dump_file, " name: %s",
6723 IDENTIFIER_POINTER (DECL_NAME (decl)));
6724 if (dump_flags & TDF_UID)
6725 fprintf (dump_file, "D.%u", DECL_UID (decl));
6727 else if (TREE_CODE (decl) == DEBUG_EXPR_DECL)
6728 fprintf (dump_file, " name: D#%u", DEBUG_TEMP_UID (decl));
6730 fprintf (dump_file, " name: D.%u", DECL_UID (decl));
6731 fprintf (dump_file, "\n");
6735 fputc (' ', dump_file);
6736 print_rtl_single (dump_file, dv_as_value (var->dv));
6739 for (i = 0; i < var->n_var_parts; i++)
6741 fprintf (dump_file, " offset %ld\n",
6742 (long)(var->onepart ? 0 : VAR_PART_OFFSET (var, i)));
6743 for (node = var->var_part[i].loc_chain; node; node = node->next)
6745 fprintf (dump_file, " ");
6746 if (node->init == VAR_INIT_STATUS_UNINITIALIZED)
6747 fprintf (dump_file, "[uninit]");
6748 print_rtl_single (dump_file, node->loc);
6753 /* Print the information about variables from hash table VARS to dump file. */
6756 dump_vars (htab_t vars)
6758 if (htab_elements (vars) > 0)
6760 fprintf (dump_file, "Variables:\n");
6761 htab_traverse (vars, dump_var_slot, NULL);
6765 /* Print the dataflow set SET to dump file. */
6768 dump_dataflow_set (dataflow_set *set)
6772 fprintf (dump_file, "Stack adjustment: " HOST_WIDE_INT_PRINT_DEC "\n",
6774 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
6778 fprintf (dump_file, "Reg %d:", i);
6779 dump_attrs_list (set->regs[i]);
6782 dump_vars (shared_hash_htab (set->vars));
6783 fprintf (dump_file, "\n");
6786 /* Print the IN and OUT sets for each basic block to dump file. */
6789 dump_dataflow_sets (void)
6795 fprintf (dump_file, "\nBasic block %d:\n", bb->index);
6796 fprintf (dump_file, "IN:\n");
6797 dump_dataflow_set (&VTI (bb)->in);
6798 fprintf (dump_file, "OUT:\n");
6799 dump_dataflow_set (&VTI (bb)->out);
6803 /* Return the variable for DV in dropped_values, inserting one if
6804 requested with INSERT. */
6806 static inline variable
6807 variable_from_dropped (decl_or_value dv, enum insert_option insert)
6811 onepart_enum_t onepart;
6813 slot = htab_find_slot_with_hash (dropped_values, dv, dv_htab_hash (dv),
6820 return (variable) *slot;
6822 gcc_checking_assert (insert == INSERT);
6824 onepart = dv_onepart_p (dv);
6826 gcc_checking_assert (onepart == ONEPART_VALUE || onepart == ONEPART_DEXPR);
6828 empty_var = (variable) pool_alloc (onepart_pool (onepart));
6830 empty_var->refcount = 1;
6831 empty_var->n_var_parts = 0;
6832 empty_var->onepart = onepart;
6833 empty_var->in_changed_variables = false;
6834 empty_var->var_part[0].loc_chain = NULL;
6835 empty_var->var_part[0].cur_loc = NULL;
6836 VAR_LOC_1PAUX (empty_var) = NULL;
6837 set_dv_changed (dv, true);
6844 /* Recover the one-part aux from dropped_values. */
6846 static struct onepart_aux *
6847 recover_dropped_1paux (variable var)
6851 gcc_checking_assert (var->onepart);
6853 if (VAR_LOC_1PAUX (var))
6854 return VAR_LOC_1PAUX (var);
6856 if (var->onepart == ONEPART_VDECL)
6859 dvar = variable_from_dropped (var->dv, NO_INSERT);
6864 VAR_LOC_1PAUX (var) = VAR_LOC_1PAUX (dvar);
6865 VAR_LOC_1PAUX (dvar) = NULL;
6867 return VAR_LOC_1PAUX (var);
6870 /* Add variable VAR to the hash table of changed variables and
6871 if it has no locations delete it from SET's hash table. */
6874 variable_was_changed (variable var, dataflow_set *set)
6876 hashval_t hash = dv_htab_hash (var->dv);
6882 /* Remember this decl or VALUE has been added to changed_variables. */
6883 set_dv_changed (var->dv, true);
6885 slot = htab_find_slot_with_hash (changed_variables,
6891 variable old_var = (variable) *slot;
6892 gcc_assert (old_var->in_changed_variables);
6893 old_var->in_changed_variables = false;
6894 if (var != old_var && var->onepart)
6896 /* Restore the auxiliary info from an empty variable
6897 previously created for changed_variables, so it is
6899 gcc_checking_assert (!VAR_LOC_1PAUX (var));
6900 VAR_LOC_1PAUX (var) = VAR_LOC_1PAUX (old_var);
6901 VAR_LOC_1PAUX (old_var) = NULL;
6903 variable_htab_free (*slot);
6906 if (set && var->n_var_parts == 0)
6908 onepart_enum_t onepart = var->onepart;
6909 variable empty_var = NULL;
6910 void **dslot = NULL;
6912 if (onepart == ONEPART_VALUE || onepart == ONEPART_DEXPR)
6914 dslot = htab_find_slot_with_hash (dropped_values, var->dv,
6915 dv_htab_hash (var->dv),
6917 empty_var = (variable) *dslot;
6921 gcc_checking_assert (!empty_var->in_changed_variables);
6922 if (!VAR_LOC_1PAUX (var))
6924 VAR_LOC_1PAUX (var) = VAR_LOC_1PAUX (empty_var);
6925 VAR_LOC_1PAUX (empty_var) = NULL;
6928 gcc_checking_assert (!VAR_LOC_1PAUX (empty_var));
6934 empty_var = (variable) pool_alloc (onepart_pool (onepart));
6935 empty_var->dv = var->dv;
6936 empty_var->refcount = 1;
6937 empty_var->n_var_parts = 0;
6938 empty_var->onepart = onepart;
6941 empty_var->refcount++;
6946 empty_var->refcount++;
6947 empty_var->in_changed_variables = true;
6951 empty_var->var_part[0].loc_chain = NULL;
6952 empty_var->var_part[0].cur_loc = NULL;
6953 VAR_LOC_1PAUX (empty_var) = VAR_LOC_1PAUX (var);
6954 VAR_LOC_1PAUX (var) = NULL;
6960 if (var->onepart && !VAR_LOC_1PAUX (var))
6961 recover_dropped_1paux (var);
6963 var->in_changed_variables = true;
6970 if (var->n_var_parts == 0)
6975 slot = shared_hash_find_slot_noinsert (set->vars, var->dv);
6978 if (shared_hash_shared (set->vars))
6979 slot = shared_hash_find_slot_unshare (&set->vars, var->dv,
6981 htab_clear_slot (shared_hash_htab (set->vars), slot);
6987 /* Look for the index in VAR->var_part corresponding to OFFSET.
6988 Return -1 if not found. If INSERTION_POINT is non-NULL, the
6989 referenced int will be set to the index that the part has or should
6990 have, if it should be inserted. */
6993 find_variable_location_part (variable var, HOST_WIDE_INT offset,
6994 int *insertion_point)
7003 if (insertion_point)
7004 *insertion_point = 0;
7006 return var->n_var_parts - 1;
7009 /* Find the location part. */
7011 high = var->n_var_parts;
7014 pos = (low + high) / 2;
7015 if (VAR_PART_OFFSET (var, pos) < offset)
7022 if (insertion_point)
7023 *insertion_point = pos;
7025 if (pos < var->n_var_parts && VAR_PART_OFFSET (var, pos) == offset)
7032 set_slot_part (dataflow_set *set, rtx loc, void **slot,
7033 decl_or_value dv, HOST_WIDE_INT offset,
7034 enum var_init_status initialized, rtx set_src)
7037 location_chain node, next;
7038 location_chain *nextp;
7040 onepart_enum_t onepart;
7042 var = (variable) *slot;
7045 onepart = var->onepart;
7047 onepart = dv_onepart_p (dv);
7049 gcc_checking_assert (offset == 0 || !onepart);
7050 gcc_checking_assert (loc != dv_as_opaque (dv));
7052 if (! flag_var_tracking_uninit)
7053 initialized = VAR_INIT_STATUS_INITIALIZED;
7057 /* Create new variable information. */
7058 var = (variable) pool_alloc (onepart_pool (onepart));
7061 var->n_var_parts = 1;
7062 var->onepart = onepart;
7063 var->in_changed_variables = false;
7065 VAR_LOC_1PAUX (var) = NULL;
7067 VAR_PART_OFFSET (var, 0) = offset;
7068 var->var_part[0].loc_chain = NULL;
7069 var->var_part[0].cur_loc = NULL;
7072 nextp = &var->var_part[0].loc_chain;
7078 gcc_assert (dv_as_opaque (var->dv) == dv_as_opaque (dv));
7082 if (GET_CODE (loc) == VALUE)
7084 for (nextp = &var->var_part[0].loc_chain; (node = *nextp);
7085 nextp = &node->next)
7086 if (GET_CODE (node->loc) == VALUE)
7088 if (node->loc == loc)
7093 if (canon_value_cmp (node->loc, loc))
7101 else if (REG_P (node->loc) || MEM_P (node->loc))
7109 else if (REG_P (loc))
7111 for (nextp = &var->var_part[0].loc_chain; (node = *nextp);
7112 nextp = &node->next)
7113 if (REG_P (node->loc))
7115 if (REGNO (node->loc) < REGNO (loc))
7119 if (REGNO (node->loc) == REGNO (loc))
7132 else if (MEM_P (loc))
7134 for (nextp = &var->var_part[0].loc_chain; (node = *nextp);
7135 nextp = &node->next)
7136 if (REG_P (node->loc))
7138 else if (MEM_P (node->loc))
7140 if ((r = loc_cmp (XEXP (node->loc, 0), XEXP (loc, 0))) >= 0)
7152 for (nextp = &var->var_part[0].loc_chain; (node = *nextp);
7153 nextp = &node->next)
7154 if ((r = loc_cmp (node->loc, loc)) >= 0)
7162 if (shared_var_p (var, set->vars))
7164 slot = unshare_variable (set, slot, var, initialized);
7165 var = (variable)*slot;
7166 for (nextp = &var->var_part[0].loc_chain; c;
7167 nextp = &(*nextp)->next)
7169 gcc_assert ((!node && !*nextp) || node->loc == (*nextp)->loc);
7176 gcc_assert (dv_as_decl (var->dv) == dv_as_decl (dv));
7178 pos = find_variable_location_part (var, offset, &inspos);
7182 node = var->var_part[pos].loc_chain;
7185 && ((REG_P (node->loc) && REG_P (loc)
7186 && REGNO (node->loc) == REGNO (loc))
7187 || rtx_equal_p (node->loc, loc)))
7189 /* LOC is in the beginning of the chain so we have nothing
7191 if (node->init < initialized)
7192 node->init = initialized;
7193 if (set_src != NULL)
7194 node->set_src = set_src;
7200 /* We have to make a copy of a shared variable. */
7201 if (shared_var_p (var, set->vars))
7203 slot = unshare_variable (set, slot, var, initialized);
7204 var = (variable)*slot;
7210 /* We have not found the location part, new one will be created. */
7212 /* We have to make a copy of the shared variable. */
7213 if (shared_var_p (var, set->vars))
7215 slot = unshare_variable (set, slot, var, initialized);
7216 var = (variable)*slot;
7219 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
7220 thus there are at most MAX_VAR_PARTS different offsets. */
7221 gcc_assert (var->n_var_parts < MAX_VAR_PARTS
7222 && (!var->n_var_parts || !onepart));
7224 /* We have to move the elements of array starting at index
7225 inspos to the next position. */
7226 for (pos = var->n_var_parts; pos > inspos; pos--)
7227 var->var_part[pos] = var->var_part[pos - 1];
7230 gcc_checking_assert (!onepart);
7231 VAR_PART_OFFSET (var, pos) = offset;
7232 var->var_part[pos].loc_chain = NULL;
7233 var->var_part[pos].cur_loc = NULL;
7236 /* Delete the location from the list. */
7237 nextp = &var->var_part[pos].loc_chain;
7238 for (node = var->var_part[pos].loc_chain; node; node = next)
7241 if ((REG_P (node->loc) && REG_P (loc)
7242 && REGNO (node->loc) == REGNO (loc))
7243 || rtx_equal_p (node->loc, loc))
7245 /* Save these values, to assign to the new node, before
7246 deleting this one. */
7247 if (node->init > initialized)
7248 initialized = node->init;
7249 if (node->set_src != NULL && set_src == NULL)
7250 set_src = node->set_src;
7251 if (var->var_part[pos].cur_loc == node->loc)
7252 var->var_part[pos].cur_loc = NULL;
7253 pool_free (loc_chain_pool, node);
7258 nextp = &node->next;
7261 nextp = &var->var_part[pos].loc_chain;
7264 /* Add the location to the beginning. */
7265 node = (location_chain) pool_alloc (loc_chain_pool);
7267 node->init = initialized;
7268 node->set_src = set_src;
7269 node->next = *nextp;
7272 /* If no location was emitted do so. */
7273 if (var->var_part[pos].cur_loc == NULL)
7274 variable_was_changed (var, set);
7279 /* Set the part of variable's location in the dataflow set SET. The
7280 variable part is specified by variable's declaration in DV and
7281 offset OFFSET and the part's location by LOC. IOPT should be
7282 NO_INSERT if the variable is known to be in SET already and the
7283 variable hash table must not be resized, and INSERT otherwise. */
7286 set_variable_part (dataflow_set *set, rtx loc,
7287 decl_or_value dv, HOST_WIDE_INT offset,
7288 enum var_init_status initialized, rtx set_src,
7289 enum insert_option iopt)
7293 if (iopt == NO_INSERT)
7294 slot = shared_hash_find_slot_noinsert (set->vars, dv);
7297 slot = shared_hash_find_slot (set->vars, dv);
7299 slot = shared_hash_find_slot_unshare (&set->vars, dv, iopt);
7301 set_slot_part (set, loc, slot, dv, offset, initialized, set_src);
7304 /* Remove all recorded register locations for the given variable part
7305 from dataflow set SET, except for those that are identical to loc.
7306 The variable part is specified by variable's declaration or value
7307 DV and offset OFFSET. */
7310 clobber_slot_part (dataflow_set *set, rtx loc, void **slot,
7311 HOST_WIDE_INT offset, rtx set_src)
7313 variable var = (variable) *slot;
7314 int pos = find_variable_location_part (var, offset, NULL);
7318 location_chain node, next;
7320 /* Remove the register locations from the dataflow set. */
7321 next = var->var_part[pos].loc_chain;
7322 for (node = next; node; node = next)
7325 if (node->loc != loc
7326 && (!flag_var_tracking_uninit
7329 || !rtx_equal_p (set_src, node->set_src)))
7331 if (REG_P (node->loc))
7336 /* Remove the variable part from the register's
7337 list, but preserve any other variable parts
7338 that might be regarded as live in that same
7340 anextp = &set->regs[REGNO (node->loc)];
7341 for (anode = *anextp; anode; anode = anext)
7343 anext = anode->next;
7344 if (dv_as_opaque (anode->dv) == dv_as_opaque (var->dv)
7345 && anode->offset == offset)
7347 pool_free (attrs_pool, anode);
7351 anextp = &anode->next;
7355 slot = delete_slot_part (set, node->loc, slot, offset);
7363 /* Remove all recorded register locations for the given variable part
7364 from dataflow set SET, except for those that are identical to loc.
7365 The variable part is specified by variable's declaration or value
7366 DV and offset OFFSET. */
7369 clobber_variable_part (dataflow_set *set, rtx loc, decl_or_value dv,
7370 HOST_WIDE_INT offset, rtx set_src)
7374 if (!dv_as_opaque (dv)
7375 || (!dv_is_value_p (dv) && ! DECL_P (dv_as_decl (dv))))
7378 slot = shared_hash_find_slot_noinsert (set->vars, dv);
7382 clobber_slot_part (set, loc, slot, offset, set_src);
7385 /* Delete the part of variable's location from dataflow set SET. The
7386 variable part is specified by its SET->vars slot SLOT and offset
7387 OFFSET and the part's location by LOC. */
7390 delete_slot_part (dataflow_set *set, rtx loc, void **slot,
7391 HOST_WIDE_INT offset)
7393 variable var = (variable) *slot;
7394 int pos = find_variable_location_part (var, offset, NULL);
7398 location_chain node, next;
7399 location_chain *nextp;
7403 if (shared_var_p (var, set->vars))
7405 /* If the variable contains the location part we have to
7406 make a copy of the variable. */
7407 for (node = var->var_part[pos].loc_chain; node;
7410 if ((REG_P (node->loc) && REG_P (loc)
7411 && REGNO (node->loc) == REGNO (loc))
7412 || rtx_equal_p (node->loc, loc))
7414 slot = unshare_variable (set, slot, var,
7415 VAR_INIT_STATUS_UNKNOWN);
7416 var = (variable)*slot;
7422 if (pos == 0 && var->onepart && VAR_LOC_1PAUX (var))
7423 cur_loc = VAR_LOC_FROM (var);
7425 cur_loc = var->var_part[pos].cur_loc;
7427 /* Delete the location part. */
7429 nextp = &var->var_part[pos].loc_chain;
7430 for (node = *nextp; node; node = next)
7433 if ((REG_P (node->loc) && REG_P (loc)
7434 && REGNO (node->loc) == REGNO (loc))
7435 || rtx_equal_p (node->loc, loc))
7437 /* If we have deleted the location which was last emitted
7438 we have to emit new location so add the variable to set
7439 of changed variables. */
7440 if (cur_loc == node->loc)
7443 var->var_part[pos].cur_loc = NULL;
7444 if (pos == 0 && var->onepart && VAR_LOC_1PAUX (var))
7445 VAR_LOC_FROM (var) = NULL;
7447 pool_free (loc_chain_pool, node);
7452 nextp = &node->next;
7455 if (var->var_part[pos].loc_chain == NULL)
7459 while (pos < var->n_var_parts)
7461 var->var_part[pos] = var->var_part[pos + 1];
7466 variable_was_changed (var, set);
7472 /* Delete the part of variable's location from dataflow set SET. The
7473 variable part is specified by variable's declaration or value DV
7474 and offset OFFSET and the part's location by LOC. */
7477 delete_variable_part (dataflow_set *set, rtx loc, decl_or_value dv,
7478 HOST_WIDE_INT offset)
7480 void **slot = shared_hash_find_slot_noinsert (set->vars, dv);
7484 delete_slot_part (set, loc, slot, offset);
7487 DEF_VEC_P (variable);
7488 DEF_VEC_ALLOC_P (variable, heap);
7490 DEF_VEC_ALLOC_P_STACK (rtx);
7491 #define VEC_rtx_stack_alloc(alloc) VEC_stack_alloc (rtx, alloc)
7493 /* Structure for passing some other parameters to function
7494 vt_expand_loc_callback. */
7495 struct expand_loc_callback_data
7497 /* The variables and values active at this point. */
7500 /* Stack of values and debug_exprs under expansion, and their
7502 VEC (rtx, stack) *expanding;
7504 /* Stack of values and debug_exprs whose expansion hit recursion
7505 cycles. They will have VALUE_RECURSED_INTO marked when added to
7506 this list. This flag will be cleared if any of its dependencies
7507 resolves to a valid location. So, if the flag remains set at the
7508 end of the search, we know no valid location for this one can
7510 VEC (rtx, stack) *pending;
7512 /* The maximum depth among the sub-expressions under expansion.
7513 Zero indicates no expansion so far. */
7517 /* Allocate the one-part auxiliary data structure for VAR, with enough
7518 room for COUNT dependencies. */
7521 loc_exp_dep_alloc (variable var, int count)
7525 gcc_checking_assert (var->onepart);
7527 /* We can be called with COUNT == 0 to allocate the data structure
7528 without any dependencies, e.g. for the backlinks only. However,
7529 if we are specifying a COUNT, then the dependency list must have
7530 been emptied before. It would be possible to adjust pointers or
7531 force it empty here, but this is better done at an earlier point
7532 in the algorithm, so we instead leave an assertion to catch
7534 gcc_checking_assert (!count
7535 || VEC_empty (loc_exp_dep, VAR_LOC_DEP_VEC (var)));
7537 if (VAR_LOC_1PAUX (var)
7538 && VEC_space (loc_exp_dep, VAR_LOC_DEP_VEC (var), count))
7541 allocsize = offsetof (struct onepart_aux, deps)
7542 + VEC_embedded_size (loc_exp_dep, count);
7544 if (VAR_LOC_1PAUX (var))
7546 VAR_LOC_1PAUX (var) = XRESIZEVAR (struct onepart_aux,
7547 VAR_LOC_1PAUX (var), allocsize);
7548 /* If the reallocation moves the onepaux structure, the
7549 back-pointer to BACKLINKS in the first list member will still
7550 point to its old location. Adjust it. */
7551 if (VAR_LOC_DEP_LST (var))
7552 VAR_LOC_DEP_LST (var)->pprev = VAR_LOC_DEP_LSTP (var);
7556 VAR_LOC_1PAUX (var) = XNEWVAR (struct onepart_aux, allocsize);
7557 *VAR_LOC_DEP_LSTP (var) = NULL;
7558 VAR_LOC_FROM (var) = NULL;
7559 VAR_LOC_DEPTH (var) = 0;
7561 VEC_embedded_init (loc_exp_dep, VAR_LOC_DEP_VEC (var), count);
7564 /* Remove all entries from the vector of active dependencies of VAR,
7565 removing them from the back-links lists too. */
7568 loc_exp_dep_clear (variable var)
7570 while (!VEC_empty (loc_exp_dep, VAR_LOC_DEP_VEC (var)))
7572 loc_exp_dep *led = VEC_last (loc_exp_dep, VAR_LOC_DEP_VEC (var));
7574 led->next->pprev = led->pprev;
7576 *led->pprev = led->next;
7577 VEC_pop (loc_exp_dep, VAR_LOC_DEP_VEC (var));
7581 /* Insert an active dependency from VAR on X to the vector of
7582 dependencies, and add the corresponding back-link to X's list of
7583 back-links in VARS. */
7586 loc_exp_insert_dep (variable var, rtx x, htab_t vars)
7592 dv = dv_from_rtx (x);
7594 /* ??? Build a vector of variables parallel to EXPANDING, to avoid
7595 an additional look up? */
7596 xvar = (variable) htab_find_with_hash (vars, dv, dv_htab_hash (dv));
7600 xvar = variable_from_dropped (dv, NO_INSERT);
7601 gcc_checking_assert (xvar);
7604 /* No point in adding the same backlink more than once. This may
7605 arise if say the same value appears in two complex expressions in
7606 the same loc_list, or even more than once in a single
7608 if (VAR_LOC_DEP_LST (xvar) && VAR_LOC_DEP_LST (xvar)->dv == var->dv)
7611 VEC_quick_push (loc_exp_dep, VAR_LOC_DEP_VEC (var), NULL);
7612 led = VEC_last (loc_exp_dep, VAR_LOC_DEP_VEC (var));
7616 loc_exp_dep_alloc (xvar, 0);
7617 led->pprev = VAR_LOC_DEP_LSTP (xvar);
7618 led->next = *led->pprev;
7620 led->next->pprev = &led->next;
7624 /* Create active dependencies of VAR on COUNT values starting at
7625 VALUE, and corresponding back-links to the entries in VARS. Return
7626 true if we found any pending-recursion results. */
7629 loc_exp_dep_set (variable var, rtx result, rtx *value, int count, htab_t vars)
7631 bool pending_recursion = false;
7633 gcc_checking_assert (VEC_empty (loc_exp_dep, VAR_LOC_DEP_VEC (var)));
7635 /* Set up all dependencies from last_child (as set up at the end of
7636 the loop above) to the end. */
7637 loc_exp_dep_alloc (var, count);
7643 if (!pending_recursion)
7644 pending_recursion = !result && VALUE_RECURSED_INTO (x);
7646 loc_exp_insert_dep (var, x, vars);
7649 return pending_recursion;
7652 /* Notify the back-links of IVAR that are pending recursion that we
7653 have found a non-NIL value for it, so they are cleared for another
7654 attempt to compute a current location. */
7657 notify_dependents_of_resolved_value (variable ivar, htab_t vars)
7659 loc_exp_dep *led, *next;
7661 for (led = VAR_LOC_DEP_LST (ivar); led; led = next)
7663 decl_or_value dv = led->dv;
7668 if (dv_is_value_p (dv))
7670 rtx value = dv_as_value (dv);
7672 /* If we have already resolved it, leave it alone. */
7673 if (!VALUE_RECURSED_INTO (value))
7676 /* Check that VALUE_RECURSED_INTO, true from the test above,
7677 implies NO_LOC_P. */
7678 gcc_checking_assert (NO_LOC_P (value));
7680 /* We won't notify variables that are being expanded,
7681 because their dependency list is cleared before
7683 VALUE_RECURSED_INTO (value) = false;
7685 gcc_checking_assert (dv_changed_p (dv));
7687 else if (!dv_changed_p (dv))
7690 var = (variable) htab_find_with_hash (vars, dv, dv_htab_hash (dv));
7693 var = variable_from_dropped (dv, NO_INSERT);
7696 notify_dependents_of_resolved_value (var, vars);
7699 next->pprev = led->pprev;
7707 static rtx vt_expand_loc_callback (rtx x, bitmap regs,
7708 int max_depth, void *data);
7710 /* Return the combined depth, when one sub-expression evaluated to
7711 BEST_DEPTH and the previous known depth was SAVED_DEPTH. */
7714 update_depth (int saved_depth, int best_depth)
7716 /* If we didn't find anything, stick with what we had. */
7720 /* If we found hadn't found anything, use the depth of the current
7721 expression. Do NOT add one extra level, we want to compute the
7722 maximum depth among sub-expressions. We'll increment it later,
7727 if (saved_depth < best_depth)
7733 /* Expand VAR to a location RTX, updating its cur_loc. Use REGS and
7734 DATA for cselib expand callback. If PENDRECP is given, indicate in
7735 it whether any sub-expression couldn't be fully evaluated because
7736 it is pending recursion resolution. */
7739 vt_expand_var_loc_chain (variable var, bitmap regs, void *data, bool *pendrecp)
7741 struct expand_loc_callback_data *elcd
7742 = (struct expand_loc_callback_data *) data;
7743 location_chain loc, next;
7745 int first_child, result_first_child, last_child;
7746 bool pending_recursion;
7747 rtx loc_from = NULL;
7748 struct elt_loc_list *cloc = NULL;
7749 int depth, saved_depth = elcd->depth;
7751 /* Clear all backlinks pointing at this, so that we're not notified
7752 while we're active. */
7753 loc_exp_dep_clear (var);
7755 if (var->onepart == ONEPART_VALUE)
7757 cselib_val *val = CSELIB_VAL_PTR (dv_as_value (var->dv));
7759 gcc_checking_assert (cselib_preserved_value_p (val));
7764 first_child = result_first_child = last_child
7765 = VEC_length (rtx, elcd->expanding);
7767 /* Attempt to expand each available location in turn. */
7768 for (next = loc = var->n_var_parts ? var->var_part[0].loc_chain : NULL;
7769 loc || cloc; loc = next)
7771 result_first_child = last_child;
7773 if (!loc || (GET_CODE (loc->loc) == ENTRY_VALUE && cloc))
7775 loc_from = cloc->loc;
7778 if (unsuitable_loc (loc_from))
7783 loc_from = loc->loc;
7787 gcc_checking_assert (!unsuitable_loc (loc_from));
7790 result = cselib_expand_value_rtx_cb (loc_from, regs, EXPR_DEPTH,
7791 vt_expand_loc_callback, data);
7792 last_child = VEC_length (rtx, elcd->expanding);
7796 depth = elcd->depth;
7798 gcc_checking_assert (depth || result_first_child == last_child);
7800 if (last_child - result_first_child != 1)
7803 if (depth <= EXPR_USE_DEPTH)
7809 /* Set it up in case we leave the loop. */
7812 result_first_child = first_child;
7815 /* Register all encountered dependencies as active. */
7816 pending_recursion = loc_exp_dep_set
7817 (var, result, VEC_address (rtx, elcd->expanding) + result_first_child,
7818 last_child - result_first_child, elcd->vars);
7820 VEC_truncate (rtx, elcd->expanding, first_child);
7822 /* Record where the expansion came from. */
7823 gcc_checking_assert (!result || !pending_recursion);
7824 VAR_LOC_FROM (var) = loc_from;
7825 VAR_LOC_DEPTH (var) = depth;
7827 elcd->depth = update_depth (saved_depth, depth);
7829 /* Indicate whether any of the dependencies are pending recursion
7832 *pendrecp = pending_recursion;
7834 if (!pendrecp || !pending_recursion)
7835 var->var_part[0].cur_loc = result;
7840 /* Callback for cselib_expand_value, that looks for expressions
7841 holding the value in the var-tracking hash tables. Return X for
7842 standard processing, anything else is to be used as-is. */
7845 vt_expand_loc_callback (rtx x, bitmap regs,
7846 int max_depth ATTRIBUTE_UNUSED,
7849 struct expand_loc_callback_data *elcd
7850 = (struct expand_loc_callback_data *) data;
7854 bool pending_recursion = false;
7855 bool from_empty = false;
7857 switch (GET_CODE (x))
7860 subreg = cselib_expand_value_rtx_cb (SUBREG_REG (x), regs,
7862 vt_expand_loc_callback, data);
7867 result = simplify_gen_subreg (GET_MODE (x), subreg,
7868 GET_MODE (SUBREG_REG (x)),
7871 /* Invalid SUBREGs are ok in debug info. ??? We could try
7872 alternate expansions for the VALUE as well. */
7874 result = gen_rtx_raw_SUBREG (GET_MODE (x), subreg, SUBREG_BYTE (x));
7880 dv = dv_from_rtx (x);
7887 VEC_safe_push (rtx, stack, elcd->expanding, x);
7889 /* Check that VALUE_RECURSED_INTO implies NO_LOC_P. */
7890 gcc_checking_assert (!VALUE_RECURSED_INTO (x) || NO_LOC_P (x));
7895 var = (variable) htab_find_with_hash (elcd->vars, dv, dv_htab_hash (dv));
7900 var = variable_from_dropped (dv, INSERT);
7903 gcc_checking_assert (var);
7905 if (!dv_changed_p (dv))
7907 gcc_checking_assert (!NO_LOC_P (x));
7908 gcc_checking_assert (var->var_part[0].cur_loc);
7909 gcc_checking_assert (VAR_LOC_1PAUX (var));
7910 gcc_checking_assert (VAR_LOC_1PAUX (var)->depth);
7912 elcd->depth = update_depth (elcd->depth, VAR_LOC_1PAUX (var)->depth);
7914 return var->var_part[0].cur_loc;
7917 VALUE_RECURSED_INTO (x) = true;
7918 /* This is tentative, but it makes some tests simpler. */
7919 NO_LOC_P (x) = true;
7921 gcc_checking_assert (var->n_var_parts == 1 || from_empty);
7923 result = vt_expand_var_loc_chain (var, regs, data, &pending_recursion);
7925 if (pending_recursion)
7927 gcc_checking_assert (!result);
7928 VEC_safe_push (rtx, stack, elcd->pending, x);
7932 NO_LOC_P (x) = !result;
7933 VALUE_RECURSED_INTO (x) = false;
7934 set_dv_changed (dv, false);
7937 notify_dependents_of_resolved_value (var, elcd->vars);
7943 /* While expanding variables, we may encounter recursion cycles
7944 because of mutual (possibly indirect) dependencies between two
7945 particular variables (or values), say A and B. If we're trying to
7946 expand A when we get to B, which in turn attempts to expand A, if
7947 we can't find any other expansion for B, we'll add B to this
7948 pending-recursion stack, and tentatively return NULL for its
7949 location. This tentative value will be used for any other
7950 occurrences of B, unless A gets some other location, in which case
7951 it will notify B that it is worth another try at computing a
7952 location for it, and it will use the location computed for A then.
7953 At the end of the expansion, the tentative NULL locations become
7954 final for all members of PENDING that didn't get a notification.
7955 This function performs this finalization of NULL locations. */
7958 resolve_expansions_pending_recursion (VEC (rtx, stack) *pending)
7960 while (!VEC_empty (rtx, pending))
7962 rtx x = VEC_pop (rtx, pending);
7965 if (!VALUE_RECURSED_INTO (x))
7968 gcc_checking_assert (NO_LOC_P (x));
7969 VALUE_RECURSED_INTO (x) = false;
7970 dv = dv_from_rtx (x);
7971 gcc_checking_assert (dv_changed_p (dv));
7972 set_dv_changed (dv, false);
7976 /* Initialize expand_loc_callback_data D with variable hash table V.
7977 It must be a macro because of alloca (VEC stack). */
7978 #define INIT_ELCD(d, v) \
7982 (d).expanding = VEC_alloc (rtx, stack, 4); \
7983 (d).pending = VEC_alloc (rtx, stack, 4); \
7987 /* Finalize expand_loc_callback_data D, resolved to location L. */
7988 #define FINI_ELCD(d, l) \
7991 resolve_expansions_pending_recursion ((d).pending); \
7992 VEC_free (rtx, stack, (d).pending); \
7993 VEC_free (rtx, stack, (d).expanding); \
7995 if ((l) && MEM_P (l)) \
7996 (l) = targetm.delegitimize_address (l); \
8000 /* Expand VALUEs and DEBUG_EXPRs in LOC to a location, using the
8001 equivalences in VARS, updating their CUR_LOCs in the process. */
8004 vt_expand_loc (rtx loc, htab_t vars)
8006 struct expand_loc_callback_data data;
8009 if (!MAY_HAVE_DEBUG_INSNS)
8012 INIT_ELCD (data, vars);
8014 result = cselib_expand_value_rtx_cb (loc, scratch_regs, EXPR_DEPTH,
8015 vt_expand_loc_callback, &data);
8017 FINI_ELCD (data, result);
8022 /* Expand the one-part VARiable to a location, using the equivalences
8023 in VARS, updating their CUR_LOCs in the process. */
8026 vt_expand_1pvar (variable var, htab_t vars)
8028 struct expand_loc_callback_data data;
8031 gcc_checking_assert (var->onepart && var->n_var_parts == 1);
8033 if (!dv_changed_p (var->dv))
8034 return var->var_part[0].cur_loc;
8036 INIT_ELCD (data, vars);
8038 loc = vt_expand_var_loc_chain (var, scratch_regs, &data, NULL);
8040 gcc_checking_assert (VEC_empty (rtx, data.expanding));
8042 FINI_ELCD (data, loc);
8047 /* Emit the NOTE_INSN_VAR_LOCATION for variable *VARP. DATA contains
8048 additional parameters: WHERE specifies whether the note shall be emitted
8049 before or after instruction INSN. */
8052 emit_note_insn_var_location (void **varp, void *data)
8054 variable var = (variable) *varp;
8055 rtx insn = ((emit_note_data *)data)->insn;
8056 enum emit_note_where where = ((emit_note_data *)data)->where;
8057 htab_t vars = ((emit_note_data *)data)->vars;
8059 int i, j, n_var_parts;
8061 enum var_init_status initialized = VAR_INIT_STATUS_UNINITIALIZED;
8062 HOST_WIDE_INT last_limit;
8063 tree type_size_unit;
8064 HOST_WIDE_INT offsets[MAX_VAR_PARTS];
8065 rtx loc[MAX_VAR_PARTS];
8069 gcc_checking_assert (var->onepart == NOT_ONEPART
8070 || var->onepart == ONEPART_VDECL);
8072 decl = dv_as_decl (var->dv);
8078 for (i = 0; i < var->n_var_parts; i++)
8079 if (var->var_part[i].cur_loc == NULL && var->var_part[i].loc_chain)
8080 var->var_part[i].cur_loc = var->var_part[i].loc_chain->loc;
8081 for (i = 0; i < var->n_var_parts; i++)
8083 enum machine_mode mode, wider_mode;
8085 HOST_WIDE_INT offset;
8087 if (i == 0 && var->onepart)
8089 gcc_checking_assert (var->n_var_parts == 1);
8091 initialized = VAR_INIT_STATUS_INITIALIZED;
8092 loc2 = vt_expand_1pvar (var, vars);
8096 if (last_limit < VAR_PART_OFFSET (var, i))
8101 else if (last_limit > VAR_PART_OFFSET (var, i))
8103 offset = VAR_PART_OFFSET (var, i);
8104 if (!var->var_part[i].cur_loc)
8109 for (lc = var->var_part[i].loc_chain; lc; lc = lc->next)
8110 if (var->var_part[i].cur_loc == lc->loc)
8112 initialized = lc->init;
8116 loc2 = var->var_part[i].cur_loc;
8119 offsets[n_var_parts] = offset;
8125 loc[n_var_parts] = loc2;
8126 mode = GET_MODE (var->var_part[i].cur_loc);
8127 if (mode == VOIDmode && var->onepart)
8128 mode = DECL_MODE (decl);
8129 last_limit = offsets[n_var_parts] + GET_MODE_SIZE (mode);
8131 /* Attempt to merge adjacent registers or memory. */
8132 wider_mode = GET_MODE_WIDER_MODE (mode);
8133 for (j = i + 1; j < var->n_var_parts; j++)
8134 if (last_limit <= VAR_PART_OFFSET (var, j))
8136 if (j < var->n_var_parts
8137 && wider_mode != VOIDmode
8138 && var->var_part[j].cur_loc
8139 && mode == GET_MODE (var->var_part[j].cur_loc)
8140 && (REG_P (loc[n_var_parts]) || MEM_P (loc[n_var_parts]))
8141 && last_limit == (var->onepart ? 0 : VAR_PART_OFFSET (var, j))
8142 && (loc2 = vt_expand_loc (var->var_part[j].cur_loc, vars))
8143 && GET_CODE (loc[n_var_parts]) == GET_CODE (loc2))
8147 if (REG_P (loc[n_var_parts])
8148 && hard_regno_nregs[REGNO (loc[n_var_parts])][mode] * 2
8149 == hard_regno_nregs[REGNO (loc[n_var_parts])][wider_mode]
8150 && end_hard_regno (mode, REGNO (loc[n_var_parts]))
8153 if (! WORDS_BIG_ENDIAN && ! BYTES_BIG_ENDIAN)
8154 new_loc = simplify_subreg (wider_mode, loc[n_var_parts],
8156 else if (WORDS_BIG_ENDIAN && BYTES_BIG_ENDIAN)
8157 new_loc = simplify_subreg (wider_mode, loc2, mode, 0);
8160 if (!REG_P (new_loc)
8161 || REGNO (new_loc) != REGNO (loc[n_var_parts]))
8164 REG_ATTRS (new_loc) = REG_ATTRS (loc[n_var_parts]);
8167 else if (MEM_P (loc[n_var_parts])
8168 && GET_CODE (XEXP (loc2, 0)) == PLUS
8169 && REG_P (XEXP (XEXP (loc2, 0), 0))
8170 && CONST_INT_P (XEXP (XEXP (loc2, 0), 1)))
8172 if ((REG_P (XEXP (loc[n_var_parts], 0))
8173 && rtx_equal_p (XEXP (loc[n_var_parts], 0),
8174 XEXP (XEXP (loc2, 0), 0))
8175 && INTVAL (XEXP (XEXP (loc2, 0), 1))
8176 == GET_MODE_SIZE (mode))
8177 || (GET_CODE (XEXP (loc[n_var_parts], 0)) == PLUS
8178 && CONST_INT_P (XEXP (XEXP (loc[n_var_parts], 0), 1))
8179 && rtx_equal_p (XEXP (XEXP (loc[n_var_parts], 0), 0),
8180 XEXP (XEXP (loc2, 0), 0))
8181 && INTVAL (XEXP (XEXP (loc[n_var_parts], 0), 1))
8182 + GET_MODE_SIZE (mode)
8183 == INTVAL (XEXP (XEXP (loc2, 0), 1))))
8184 new_loc = adjust_address_nv (loc[n_var_parts],
8190 loc[n_var_parts] = new_loc;
8192 last_limit = offsets[n_var_parts] + GET_MODE_SIZE (mode);
8198 type_size_unit = TYPE_SIZE_UNIT (TREE_TYPE (decl));
8199 if ((unsigned HOST_WIDE_INT) last_limit < TREE_INT_CST_LOW (type_size_unit))
8202 if (! flag_var_tracking_uninit)
8203 initialized = VAR_INIT_STATUS_INITIALIZED;
8207 note_vl = gen_rtx_VAR_LOCATION (VOIDmode, decl, NULL_RTX,
8209 else if (n_var_parts == 1)
8213 if (offsets[0] || GET_CODE (loc[0]) == PARALLEL)
8214 expr_list = gen_rtx_EXPR_LIST (VOIDmode, loc[0], GEN_INT (offsets[0]));
8218 note_vl = gen_rtx_VAR_LOCATION (VOIDmode, decl, expr_list,
8221 else if (n_var_parts)
8225 for (i = 0; i < n_var_parts; i++)
8227 = gen_rtx_EXPR_LIST (VOIDmode, loc[i], GEN_INT (offsets[i]));
8229 parallel = gen_rtx_PARALLEL (VOIDmode,
8230 gen_rtvec_v (n_var_parts, loc));
8231 note_vl = gen_rtx_VAR_LOCATION (VOIDmode, decl,
8232 parallel, (int) initialized);
8235 if (where != EMIT_NOTE_BEFORE_INSN)
8237 note = emit_note_after (NOTE_INSN_VAR_LOCATION, insn);
8238 if (where == EMIT_NOTE_AFTER_CALL_INSN)
8239 NOTE_DURING_CALL_P (note) = true;
8243 /* Make sure that the call related notes come first. */
8244 while (NEXT_INSN (insn)
8246 && NOTE_DURING_CALL_P (insn))
8247 insn = NEXT_INSN (insn);
8248 if (NOTE_P (insn) && NOTE_DURING_CALL_P (insn))
8249 note = emit_note_after (NOTE_INSN_VAR_LOCATION, insn);
8251 note = emit_note_before (NOTE_INSN_VAR_LOCATION, insn);
8253 NOTE_VAR_LOCATION (note) = note_vl;
8255 set_dv_changed (var->dv, false);
8256 gcc_assert (var->in_changed_variables);
8257 var->in_changed_variables = false;
8258 htab_clear_slot (changed_variables, varp);
8260 /* Continue traversing the hash table. */
8264 /* While traversing changed_variables, push onto DATA (a stack of RTX
8265 values) entries that aren't user variables. */
8268 values_to_stack (void **slot, void *data)
8270 VEC (rtx, stack) **changed_values_stack = (VEC (rtx, stack) **)data;
8271 variable var = (variable) *slot;
8273 if (var->onepart == ONEPART_VALUE)
8274 VEC_safe_push (rtx, stack, *changed_values_stack, dv_as_value (var->dv));
8275 else if (var->onepart == ONEPART_DEXPR)
8276 VEC_safe_push (rtx, stack, *changed_values_stack,
8277 DECL_RTL_KNOWN_SET (dv_as_decl (var->dv)));
8282 /* Remove from changed_variables the entry whose DV corresponds to
8283 value or debug_expr VAL. */
8285 remove_value_from_changed_variables (rtx val)
8287 decl_or_value dv = dv_from_rtx (val);
8291 slot = htab_find_slot_with_hash (changed_variables,
8292 dv, dv_htab_hash (dv), NO_INSERT);
8293 var = (variable) *slot;
8294 var->in_changed_variables = false;
8295 htab_clear_slot (changed_variables, slot);
8298 /* If VAL (a value or debug_expr) has backlinks to variables actively
8299 dependent on it in HTAB or in CHANGED_VARIABLES, mark them as
8300 changed, adding to CHANGED_VALUES_STACK any dependencies that may
8301 have dependencies of their own to notify. */
8304 notify_dependents_of_changed_value (rtx val, htab_t htab,
8305 VEC (rtx, stack) **changed_values_stack)
8310 decl_or_value dv = dv_from_rtx (val);
8312 slot = htab_find_slot_with_hash (changed_variables,
8313 dv, dv_htab_hash (dv), NO_INSERT);
8315 slot = htab_find_slot_with_hash (htab,
8316 dv, dv_htab_hash (dv), NO_INSERT);
8318 slot = htab_find_slot_with_hash (dropped_values,
8319 dv, dv_htab_hash (dv), NO_INSERT);
8320 var = (variable) *slot;
8322 while ((led = VAR_LOC_DEP_LST (var)))
8324 decl_or_value ldv = led->dv;
8328 /* Deactivate and remove the backlink, as it was “used up”. It
8329 makes no sense to attempt to notify the same entity again:
8330 either it will be recomputed and re-register an active
8331 dependency, or it will still have the changed mark. */
8333 led->next->pprev = led->pprev;
8335 *led->pprev = led->next;
8339 if (dv_changed_p (ldv))
8342 switch (dv_onepart_p (ldv))
8346 set_dv_changed (ldv, true);
8347 VEC_safe_push (rtx, stack, *changed_values_stack, dv_as_rtx (ldv));
8351 islot = htab_find_slot_with_hash (htab, ldv, dv_htab_hash (ldv),
8353 ivar = (variable) *islot;
8354 gcc_checking_assert (!VAR_LOC_DEP_LST (ivar));
8355 variable_was_changed (ivar, NULL);
8361 /* Take out of changed_variables any entries that don't refer to use
8362 variables. Back-propagate change notifications from values and
8363 debug_exprs to their active dependencies in HTAB or in
8364 CHANGED_VARIABLES. */
8367 process_changed_values (htab_t htab)
8371 VEC (rtx, stack) *changed_values_stack = VEC_alloc (rtx, stack, 20);
8373 /* Move values from changed_variables to changed_values_stack. */
8374 htab_traverse (changed_variables, values_to_stack, &changed_values_stack);
8376 /* Back-propagate change notifications in values while popping
8377 them from the stack. */
8378 for (n = i = VEC_length (rtx, changed_values_stack);
8379 i > 0; i = VEC_length (rtx, changed_values_stack))
8381 val = VEC_pop (rtx, changed_values_stack);
8382 notify_dependents_of_changed_value (val, htab, &changed_values_stack);
8384 /* This condition will hold when visiting each of the entries
8385 originally in changed_variables. We can't remove them
8386 earlier because this could drop the backlinks before we got a
8387 chance to use them. */
8390 remove_value_from_changed_variables (val);
8395 VEC_free (rtx, stack, changed_values_stack);
8398 /* Emit NOTE_INSN_VAR_LOCATION note for each variable from a chain
8399 CHANGED_VARIABLES and delete this chain. WHERE specifies whether
8400 the notes shall be emitted before of after instruction INSN. */
8403 emit_notes_for_changes (rtx insn, enum emit_note_where where,
8406 emit_note_data data;
8407 htab_t htab = shared_hash_htab (vars);
8409 if (!htab_elements (changed_variables))
8412 if (MAY_HAVE_DEBUG_INSNS)
8413 process_changed_values (htab);
8419 htab_traverse (changed_variables, emit_note_insn_var_location, &data);
8422 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it differs from the
8423 same variable in hash table DATA or is not there at all. */
8426 emit_notes_for_differences_1 (void **slot, void *data)
8428 htab_t new_vars = (htab_t) data;
8429 variable old_var, new_var;
8431 old_var = (variable) *slot;
8432 new_var = (variable) htab_find_with_hash (new_vars, old_var->dv,
8433 dv_htab_hash (old_var->dv));
8437 /* Variable has disappeared. */
8438 variable empty_var = NULL;
8440 if (old_var->onepart == ONEPART_VALUE
8441 || old_var->onepart == ONEPART_DEXPR)
8443 empty_var = variable_from_dropped (old_var->dv, NO_INSERT);
8446 gcc_checking_assert (!empty_var->in_changed_variables);
8447 if (!VAR_LOC_1PAUX (old_var))
8449 VAR_LOC_1PAUX (old_var) = VAR_LOC_1PAUX (empty_var);
8450 VAR_LOC_1PAUX (empty_var) = NULL;
8453 gcc_checking_assert (!VAR_LOC_1PAUX (empty_var));
8459 empty_var = (variable) pool_alloc (onepart_pool (old_var->onepart));
8460 empty_var->dv = old_var->dv;
8461 empty_var->refcount = 0;
8462 empty_var->n_var_parts = 0;
8463 empty_var->onepart = old_var->onepart;
8464 empty_var->in_changed_variables = false;
8467 if (empty_var->onepart)
8469 /* Propagate the auxiliary data to (ultimately)
8470 changed_variables. */
8471 empty_var->var_part[0].loc_chain = NULL;
8472 empty_var->var_part[0].cur_loc = NULL;
8473 VAR_LOC_1PAUX (empty_var) = VAR_LOC_1PAUX (old_var);
8474 VAR_LOC_1PAUX (old_var) = NULL;
8476 variable_was_changed (empty_var, NULL);
8477 /* Continue traversing the hash table. */
8480 /* Update cur_loc and one-part auxiliary data, before new_var goes
8481 through variable_was_changed. */
8482 if (old_var != new_var && new_var->onepart)
8484 gcc_checking_assert (VAR_LOC_1PAUX (new_var) == NULL);
8485 VAR_LOC_1PAUX (new_var) = VAR_LOC_1PAUX (old_var);
8486 VAR_LOC_1PAUX (old_var) = NULL;
8487 new_var->var_part[0].cur_loc = old_var->var_part[0].cur_loc;
8489 if (variable_different_p (old_var, new_var))
8490 variable_was_changed (new_var, NULL);
8492 /* Continue traversing the hash table. */
8496 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it is not in hash
8500 emit_notes_for_differences_2 (void **slot, void *data)
8502 htab_t old_vars = (htab_t) data;
8503 variable old_var, new_var;
8505 new_var = (variable) *slot;
8506 old_var = (variable) htab_find_with_hash (old_vars, new_var->dv,
8507 dv_htab_hash (new_var->dv));
8511 for (i = 0; i < new_var->n_var_parts; i++)
8512 new_var->var_part[i].cur_loc = NULL;
8513 variable_was_changed (new_var, NULL);
8516 /* Continue traversing the hash table. */
8520 /* Emit notes before INSN for differences between dataflow sets OLD_SET and
8524 emit_notes_for_differences (rtx insn, dataflow_set *old_set,
8525 dataflow_set *new_set)
8527 htab_traverse (shared_hash_htab (old_set->vars),
8528 emit_notes_for_differences_1,
8529 shared_hash_htab (new_set->vars));
8530 htab_traverse (shared_hash_htab (new_set->vars),
8531 emit_notes_for_differences_2,
8532 shared_hash_htab (old_set->vars));
8533 emit_notes_for_changes (insn, EMIT_NOTE_BEFORE_INSN, new_set->vars);
8536 /* Return the next insn after INSN that is not a NOTE_INSN_VAR_LOCATION. */
8539 next_non_note_insn_var_location (rtx insn)
8543 insn = NEXT_INSN (insn);
8546 || NOTE_KIND (insn) != NOTE_INSN_VAR_LOCATION)
8553 /* Emit the notes for changes of location parts in the basic block BB. */
8556 emit_notes_in_bb (basic_block bb, dataflow_set *set)
8559 micro_operation *mo;
8561 dataflow_set_clear (set);
8562 dataflow_set_copy (set, &VTI (bb)->in);
8564 FOR_EACH_VEC_ELT (micro_operation, VTI (bb)->mos, i, mo)
8566 rtx insn = mo->insn;
8567 rtx next_insn = next_non_note_insn_var_location (insn);
8572 dataflow_set_clear_at_call (set);
8573 emit_notes_for_changes (insn, EMIT_NOTE_AFTER_CALL_INSN, set->vars);
8575 rtx arguments = mo->u.loc, *p = &arguments, note;
8578 XEXP (XEXP (*p, 0), 1)
8579 = vt_expand_loc (XEXP (XEXP (*p, 0), 1),
8580 shared_hash_htab (set->vars));
8581 /* If expansion is successful, keep it in the list. */
8582 if (XEXP (XEXP (*p, 0), 1))
8584 /* Otherwise, if the following item is data_value for it,
8586 else if (XEXP (*p, 1)
8587 && REG_P (XEXP (XEXP (*p, 0), 0))
8588 && MEM_P (XEXP (XEXP (XEXP (*p, 1), 0), 0))
8589 && REG_P (XEXP (XEXP (XEXP (XEXP (*p, 1), 0), 0),
8591 && REGNO (XEXP (XEXP (*p, 0), 0))
8592 == REGNO (XEXP (XEXP (XEXP (XEXP (*p, 1), 0),
8594 *p = XEXP (XEXP (*p, 1), 1);
8595 /* Just drop this item. */
8599 note = emit_note_after (NOTE_INSN_CALL_ARG_LOCATION, insn);
8600 NOTE_VAR_LOCATION (note) = arguments;
8606 rtx loc = mo->u.loc;
8609 var_reg_set (set, loc, VAR_INIT_STATUS_UNINITIALIZED, NULL);
8611 var_mem_set (set, loc, VAR_INIT_STATUS_UNINITIALIZED, NULL);
8613 emit_notes_for_changes (insn, EMIT_NOTE_AFTER_INSN, set->vars);
8619 rtx loc = mo->u.loc;
8623 if (GET_CODE (loc) == CONCAT)
8625 val = XEXP (loc, 0);
8626 vloc = XEXP (loc, 1);
8634 var = PAT_VAR_LOCATION_DECL (vloc);
8636 clobber_variable_part (set, NULL_RTX,
8637 dv_from_decl (var), 0, NULL_RTX);
8640 if (VAL_NEEDS_RESOLUTION (loc))
8641 val_resolve (set, val, PAT_VAR_LOCATION_LOC (vloc), insn);
8642 set_variable_part (set, val, dv_from_decl (var), 0,
8643 VAR_INIT_STATUS_INITIALIZED, NULL_RTX,
8646 else if (!VAR_LOC_UNKNOWN_P (PAT_VAR_LOCATION_LOC (vloc)))
8647 set_variable_part (set, PAT_VAR_LOCATION_LOC (vloc),
8648 dv_from_decl (var), 0,
8649 VAR_INIT_STATUS_INITIALIZED, NULL_RTX,
8652 emit_notes_for_changes (insn, EMIT_NOTE_AFTER_INSN, set->vars);
8658 rtx loc = mo->u.loc;
8659 rtx val, vloc, uloc;
8661 vloc = uloc = XEXP (loc, 1);
8662 val = XEXP (loc, 0);
8664 if (GET_CODE (val) == CONCAT)
8666 uloc = XEXP (val, 1);
8667 val = XEXP (val, 0);
8670 if (VAL_NEEDS_RESOLUTION (loc))
8671 val_resolve (set, val, vloc, insn);
8673 val_store (set, val, uloc, insn, false);
8675 if (VAL_HOLDS_TRACK_EXPR (loc))
8677 if (GET_CODE (uloc) == REG)
8678 var_reg_set (set, uloc, VAR_INIT_STATUS_UNINITIALIZED,
8680 else if (GET_CODE (uloc) == MEM)
8681 var_mem_set (set, uloc, VAR_INIT_STATUS_UNINITIALIZED,
8685 emit_notes_for_changes (insn, EMIT_NOTE_BEFORE_INSN, set->vars);
8691 rtx loc = mo->u.loc;
8692 rtx val, vloc, uloc, reverse = NULL_RTX;
8695 if (VAL_EXPR_HAS_REVERSE (loc))
8697 reverse = XEXP (loc, 1);
8698 vloc = XEXP (loc, 0);
8700 uloc = XEXP (vloc, 1);
8701 val = XEXP (vloc, 0);
8704 if (GET_CODE (val) == CONCAT)
8706 vloc = XEXP (val, 1);
8707 val = XEXP (val, 0);
8710 if (GET_CODE (vloc) == SET)
8712 rtx vsrc = SET_SRC (vloc);
8714 gcc_assert (val != vsrc);
8715 gcc_assert (vloc == uloc || VAL_NEEDS_RESOLUTION (loc));
8717 vloc = SET_DEST (vloc);
8719 if (VAL_NEEDS_RESOLUTION (loc))
8720 val_resolve (set, val, vsrc, insn);
8722 else if (VAL_NEEDS_RESOLUTION (loc))
8724 gcc_assert (GET_CODE (uloc) == SET
8725 && GET_CODE (SET_SRC (uloc)) == REG);
8726 val_resolve (set, val, SET_SRC (uloc), insn);
8729 if (VAL_HOLDS_TRACK_EXPR (loc))
8731 if (VAL_EXPR_IS_CLOBBERED (loc))
8734 var_reg_delete (set, uloc, true);
8735 else if (MEM_P (uloc))
8736 var_mem_delete (set, uloc, true);
8740 bool copied_p = VAL_EXPR_IS_COPIED (loc);
8742 enum var_init_status status = VAR_INIT_STATUS_INITIALIZED;
8744 if (GET_CODE (uloc) == SET)
8746 set_src = SET_SRC (uloc);
8747 uloc = SET_DEST (uloc);
8752 status = find_src_status (set, set_src);
8754 set_src = find_src_set_src (set, set_src);
8758 var_reg_delete_and_set (set, uloc, !copied_p,
8760 else if (MEM_P (uloc))
8761 var_mem_delete_and_set (set, uloc, !copied_p,
8765 else if (REG_P (uloc))
8766 var_regno_delete (set, REGNO (uloc));
8768 val_store (set, val, vloc, insn, true);
8771 val_store (set, XEXP (reverse, 0), XEXP (reverse, 1),
8774 emit_notes_for_changes (next_insn, EMIT_NOTE_BEFORE_INSN,
8781 rtx loc = mo->u.loc;
8784 if (GET_CODE (loc) == SET)
8786 set_src = SET_SRC (loc);
8787 loc = SET_DEST (loc);
8791 var_reg_delete_and_set (set, loc, true, VAR_INIT_STATUS_INITIALIZED,
8794 var_mem_delete_and_set (set, loc, true, VAR_INIT_STATUS_INITIALIZED,
8797 emit_notes_for_changes (next_insn, EMIT_NOTE_BEFORE_INSN,
8804 rtx loc = mo->u.loc;
8805 enum var_init_status src_status;
8808 if (GET_CODE (loc) == SET)
8810 set_src = SET_SRC (loc);
8811 loc = SET_DEST (loc);
8814 src_status = find_src_status (set, set_src);
8815 set_src = find_src_set_src (set, set_src);
8818 var_reg_delete_and_set (set, loc, false, src_status, set_src);
8820 var_mem_delete_and_set (set, loc, false, src_status, set_src);
8822 emit_notes_for_changes (next_insn, EMIT_NOTE_BEFORE_INSN,
8829 rtx loc = mo->u.loc;
8832 var_reg_delete (set, loc, false);
8834 var_mem_delete (set, loc, false);
8836 emit_notes_for_changes (insn, EMIT_NOTE_AFTER_INSN, set->vars);
8842 rtx loc = mo->u.loc;
8845 var_reg_delete (set, loc, true);
8847 var_mem_delete (set, loc, true);
8849 emit_notes_for_changes (next_insn, EMIT_NOTE_BEFORE_INSN,
8855 set->stack_adjust += mo->u.adjust;
8861 /* Emit notes for the whole function. */
8864 vt_emit_notes (void)
8869 gcc_assert (!htab_elements (changed_variables));
8871 /* Free memory occupied by the out hash tables, as they aren't used
8874 dataflow_set_clear (&VTI (bb)->out);
8876 /* Enable emitting notes by functions (mainly by set_variable_part and
8877 delete_variable_part). */
8880 if (MAY_HAVE_DEBUG_INSNS)
8881 dropped_values = htab_create (cselib_get_next_uid () * 2,
8882 variable_htab_hash, variable_htab_eq,
8883 variable_htab_free);
8885 dataflow_set_init (&cur);
8889 /* Emit the notes for changes of variable locations between two
8890 subsequent basic blocks. */
8891 emit_notes_for_differences (BB_HEAD (bb), &cur, &VTI (bb)->in);
8893 /* Emit the notes for the changes in the basic block itself. */
8894 emit_notes_in_bb (bb, &cur);
8896 /* Free memory occupied by the in hash table, we won't need it
8898 dataflow_set_clear (&VTI (bb)->in);
8900 #ifdef ENABLE_CHECKING
8901 htab_traverse (shared_hash_htab (cur.vars),
8902 emit_notes_for_differences_1,
8903 shared_hash_htab (empty_shared_hash));
8905 dataflow_set_destroy (&cur);
8907 if (MAY_HAVE_DEBUG_INSNS)
8908 htab_delete (dropped_values);
8913 /* If there is a declaration and offset associated with register/memory RTL
8914 assign declaration to *DECLP and offset to *OFFSETP, and return true. */
8917 vt_get_decl_and_offset (rtx rtl, tree *declp, HOST_WIDE_INT *offsetp)
8921 if (REG_ATTRS (rtl))
8923 *declp = REG_EXPR (rtl);
8924 *offsetp = REG_OFFSET (rtl);
8928 else if (MEM_P (rtl))
8930 if (MEM_ATTRS (rtl))
8932 *declp = MEM_EXPR (rtl);
8933 *offsetp = INT_MEM_OFFSET (rtl);
8940 /* Mark the value for the ENTRY_VALUE of RTL as equivalent to EQVAL in
8944 create_entry_value (dataflow_set *out, rtx eqval, rtx rtl)
8946 rtx ev = gen_rtx_ENTRY_VALUE (GET_MODE (rtl));
8949 ENTRY_VALUE_EXP (ev) = rtl;
8951 val = cselib_lookup_from_insn (ev, GET_MODE (ev), true,
8952 VOIDmode, get_insns ());
8954 if (val->val_rtx != eqval)
8956 preserve_value (val);
8957 set_variable_part (out, val->val_rtx, dv_from_value (eqval), 0,
8958 VAR_INIT_STATUS_INITIALIZED, NULL_RTX, INSERT);
8959 set_variable_part (out, eqval, dv_from_value (val->val_rtx), 0,
8960 VAR_INIT_STATUS_INITIALIZED, NULL_RTX, INSERT);
8964 /* Insert function parameter PARM in IN and OUT sets of ENTRY_BLOCK. */
8967 vt_add_function_parameter (tree parm)
8969 rtx decl_rtl = DECL_RTL_IF_SET (parm);
8970 rtx incoming = DECL_INCOMING_RTL (parm);
8972 enum machine_mode mode;
8973 HOST_WIDE_INT offset;
8977 if (TREE_CODE (parm) != PARM_DECL)
8980 if (!decl_rtl || !incoming)
8983 if (GET_MODE (decl_rtl) == BLKmode || GET_MODE (incoming) == BLKmode)
8986 /* If there is a DRAP register, rewrite the incoming location of parameters
8987 passed on the stack into MEMs based on the argument pointer, as the DRAP
8988 register can be reused for other purposes and we do not track locations
8989 based on generic registers. But the prerequisite is that this argument
8990 pointer be also the virtual CFA pointer, see vt_initialize. */
8991 if (MEM_P (incoming)
8992 && stack_realign_drap
8993 && arg_pointer_rtx == cfa_base_rtx
8994 && (XEXP (incoming, 0) == crtl->args.internal_arg_pointer
8995 || (GET_CODE (XEXP (incoming, 0)) == PLUS
8996 && XEXP (XEXP (incoming, 0), 0)
8997 == crtl->args.internal_arg_pointer
8998 && CONST_INT_P (XEXP (XEXP (incoming, 0), 1)))))
9000 HOST_WIDE_INT off = -FIRST_PARM_OFFSET (current_function_decl);
9001 if (GET_CODE (XEXP (incoming, 0)) == PLUS)
9002 off += INTVAL (XEXP (XEXP (incoming, 0), 1));
9004 = replace_equiv_address_nv (incoming,
9005 plus_constant (arg_pointer_rtx, off));
9008 #ifdef HAVE_window_save
9009 /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
9010 If the target machine has an explicit window save instruction, the
9011 actual entry value is the corresponding OUTGOING_REGNO instead. */
9012 if (REG_P (incoming)
9013 && HARD_REGISTER_P (incoming)
9014 && OUTGOING_REGNO (REGNO (incoming)) != REGNO (incoming))
9017 = VEC_safe_push (parm_reg_t, gc, windowed_parm_regs, NULL);
9018 p->incoming = incoming;
9020 = gen_rtx_REG_offset (incoming, GET_MODE (incoming),
9021 OUTGOING_REGNO (REGNO (incoming)), 0);
9022 p->outgoing = incoming;
9024 else if (MEM_P (incoming)
9025 && REG_P (XEXP (incoming, 0))
9026 && HARD_REGISTER_P (XEXP (incoming, 0)))
9028 rtx reg = XEXP (incoming, 0);
9029 if (OUTGOING_REGNO (REGNO (reg)) != REGNO (reg))
9032 = VEC_safe_push (parm_reg_t, gc, windowed_parm_regs, NULL);
9034 reg = gen_raw_REG (GET_MODE (reg), OUTGOING_REGNO (REGNO (reg)));
9036 incoming = replace_equiv_address_nv (incoming, reg);
9041 if (!vt_get_decl_and_offset (incoming, &decl, &offset))
9043 if (REG_P (incoming) || MEM_P (incoming))
9045 /* This means argument is passed by invisible reference. */
9048 incoming = gen_rtx_MEM (GET_MODE (decl_rtl), incoming);
9052 if (!vt_get_decl_and_offset (decl_rtl, &decl, &offset))
9054 offset += byte_lowpart_offset (GET_MODE (incoming),
9055 GET_MODE (decl_rtl));
9064 /* Assume that DECL_RTL was a pseudo that got spilled to
9065 memory. The spill slot sharing code will force the
9066 memory to reference spill_slot_decl (%sfp), so we don't
9067 match above. That's ok, the pseudo must have referenced
9068 the entire parameter, so just reset OFFSET. */
9069 gcc_assert (decl == get_spill_slot_decl (false));
9073 if (!track_loc_p (incoming, parm, offset, false, &mode, &offset))
9076 out = &VTI (ENTRY_BLOCK_PTR)->out;
9078 dv = dv_from_decl (parm);
9080 if (target_for_debug_bind (parm)
9081 /* We can't deal with these right now, because this kind of
9082 variable is single-part. ??? We could handle parallels
9083 that describe multiple locations for the same single
9084 value, but ATM we don't. */
9085 && GET_CODE (incoming) != PARALLEL)
9089 /* ??? We shouldn't ever hit this, but it may happen because
9090 arguments passed by invisible reference aren't dealt with
9091 above: incoming-rtl will have Pmode rather than the
9092 expected mode for the type. */
9096 val = cselib_lookup_from_insn (var_lowpart (mode, incoming), mode, true,
9097 VOIDmode, get_insns ());
9099 /* ??? Float-typed values in memory are not handled by
9103 preserve_value (val);
9104 set_variable_part (out, val->val_rtx, dv, offset,
9105 VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
9106 dv = dv_from_value (val->val_rtx);
9110 if (REG_P (incoming))
9112 incoming = var_lowpart (mode, incoming);
9113 gcc_assert (REGNO (incoming) < FIRST_PSEUDO_REGISTER);
9114 attrs_list_insert (&out->regs[REGNO (incoming)], dv, offset,
9116 set_variable_part (out, incoming, dv, offset,
9117 VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
9118 if (dv_is_value_p (dv))
9120 create_entry_value (out, dv_as_value (dv), incoming);
9121 if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
9122 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (parm))))
9124 enum machine_mode indmode
9125 = TYPE_MODE (TREE_TYPE (TREE_TYPE (parm)));
9126 rtx mem = gen_rtx_MEM (indmode, incoming);
9127 cselib_val *val = cselib_lookup_from_insn (mem, indmode, true,
9132 preserve_value (val);
9133 set_variable_part (out, mem, dv_from_value (val->val_rtx), 0,
9134 VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
9135 create_entry_value (out, val->val_rtx, mem);
9140 else if (MEM_P (incoming))
9142 incoming = var_lowpart (mode, incoming);
9143 set_variable_part (out, incoming, dv, offset,
9144 VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
9148 /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK. */
9151 vt_add_function_parameters (void)
9155 for (parm = DECL_ARGUMENTS (current_function_decl);
9156 parm; parm = DECL_CHAIN (parm))
9157 vt_add_function_parameter (parm);
9159 if (DECL_HAS_VALUE_EXPR_P (DECL_RESULT (current_function_decl)))
9161 tree vexpr = DECL_VALUE_EXPR (DECL_RESULT (current_function_decl));
9163 if (TREE_CODE (vexpr) == INDIRECT_REF)
9164 vexpr = TREE_OPERAND (vexpr, 0);
9166 if (TREE_CODE (vexpr) == PARM_DECL
9167 && DECL_ARTIFICIAL (vexpr)
9168 && !DECL_IGNORED_P (vexpr)
9169 && DECL_NAMELESS (vexpr))
9170 vt_add_function_parameter (vexpr);
9174 /* Return true if INSN in the prologue initializes hard_frame_pointer_rtx. */
9177 fp_setter (rtx insn)
9179 rtx pat = PATTERN (insn);
9180 if (RTX_FRAME_RELATED_P (insn))
9182 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
9184 pat = XEXP (expr, 0);
9186 if (GET_CODE (pat) == SET)
9187 return SET_DEST (pat) == hard_frame_pointer_rtx;
9188 else if (GET_CODE (pat) == PARALLEL)
9191 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
9192 if (GET_CODE (XVECEXP (pat, 0, i)) == SET
9193 && SET_DEST (XVECEXP (pat, 0, i)) == hard_frame_pointer_rtx)
9199 /* Initialize cfa_base_rtx, create a preserved VALUE for it and
9200 ensure it isn't flushed during cselib_reset_table.
9201 Can be called only if frame_pointer_rtx resp. arg_pointer_rtx
9202 has been eliminated. */
9205 vt_init_cfa_base (void)
9209 #ifdef FRAME_POINTER_CFA_OFFSET
9210 cfa_base_rtx = frame_pointer_rtx;
9211 cfa_base_offset = -FRAME_POINTER_CFA_OFFSET (current_function_decl);
9213 cfa_base_rtx = arg_pointer_rtx;
9214 cfa_base_offset = -ARG_POINTER_CFA_OFFSET (current_function_decl);
9216 if (cfa_base_rtx == hard_frame_pointer_rtx
9217 || !fixed_regs[REGNO (cfa_base_rtx)])
9219 cfa_base_rtx = NULL_RTX;
9222 if (!MAY_HAVE_DEBUG_INSNS)
9225 /* Tell alias analysis that cfa_base_rtx should share
9226 find_base_term value with stack pointer or hard frame pointer. */
9227 if (!frame_pointer_needed)
9228 vt_equate_reg_base_value (cfa_base_rtx, stack_pointer_rtx);
9229 else if (!crtl->stack_realign_tried)
9230 vt_equate_reg_base_value (cfa_base_rtx, hard_frame_pointer_rtx);
9232 val = cselib_lookup_from_insn (cfa_base_rtx, GET_MODE (cfa_base_rtx), 1,
9233 VOIDmode, get_insns ());
9234 preserve_value (val);
9235 cselib_preserve_cfa_base_value (val, REGNO (cfa_base_rtx));
9236 var_reg_decl_set (&VTI (ENTRY_BLOCK_PTR)->out, cfa_base_rtx,
9237 VAR_INIT_STATUS_INITIALIZED, dv_from_value (val->val_rtx),
9238 0, NULL_RTX, INSERT);
9241 /* Allocate and initialize the data structures for variable tracking
9242 and parse the RTL to get the micro operations. */
9245 vt_initialize (void)
9247 basic_block bb, prologue_bb = single_succ (ENTRY_BLOCK_PTR);
9248 HOST_WIDE_INT fp_cfa_offset = -1;
9250 alloc_aux_for_blocks (sizeof (struct variable_tracking_info_def));
9252 attrs_pool = create_alloc_pool ("attrs_def pool",
9253 sizeof (struct attrs_def), 1024);
9254 var_pool = create_alloc_pool ("variable_def pool",
9255 sizeof (struct variable_def)
9256 + (MAX_VAR_PARTS - 1)
9257 * sizeof (((variable)NULL)->var_part[0]), 64);
9258 loc_chain_pool = create_alloc_pool ("location_chain_def pool",
9259 sizeof (struct location_chain_def),
9261 shared_hash_pool = create_alloc_pool ("shared_hash_def pool",
9262 sizeof (struct shared_hash_def), 256);
9263 empty_shared_hash = (shared_hash) pool_alloc (shared_hash_pool);
9264 empty_shared_hash->refcount = 1;
9265 empty_shared_hash->htab
9266 = htab_create (1, variable_htab_hash, variable_htab_eq,
9267 variable_htab_free);
9268 changed_variables = htab_create (10, variable_htab_hash, variable_htab_eq,
9269 variable_htab_free);
9271 /* Init the IN and OUT sets. */
9274 VTI (bb)->visited = false;
9275 VTI (bb)->flooded = false;
9276 dataflow_set_init (&VTI (bb)->in);
9277 dataflow_set_init (&VTI (bb)->out);
9278 VTI (bb)->permp = NULL;
9281 if (MAY_HAVE_DEBUG_INSNS)
9283 cselib_init (CSELIB_RECORD_MEMORY | CSELIB_PRESERVE_CONSTANTS);
9284 scratch_regs = BITMAP_ALLOC (NULL);
9285 valvar_pool = create_alloc_pool ("small variable_def pool",
9286 sizeof (struct variable_def), 256);
9287 preserved_values = VEC_alloc (rtx, heap, 256);
9291 scratch_regs = NULL;
9295 /* In order to factor out the adjustments made to the stack pointer or to
9296 the hard frame pointer and thus be able to use DW_OP_fbreg operations
9297 instead of individual location lists, we're going to rewrite MEMs based
9298 on them into MEMs based on the CFA by de-eliminating stack_pointer_rtx
9299 or hard_frame_pointer_rtx to the virtual CFA pointer frame_pointer_rtx
9300 resp. arg_pointer_rtx. We can do this either when there is no frame
9301 pointer in the function and stack adjustments are consistent for all
9302 basic blocks or when there is a frame pointer and no stack realignment.
9303 But we first have to check that frame_pointer_rtx resp. arg_pointer_rtx
9304 has been eliminated. */
9305 if (!frame_pointer_needed)
9309 if (!vt_stack_adjustments ())
9312 #ifdef FRAME_POINTER_CFA_OFFSET
9313 reg = frame_pointer_rtx;
9315 reg = arg_pointer_rtx;
9317 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9320 if (GET_CODE (elim) == PLUS)
9321 elim = XEXP (elim, 0);
9322 if (elim == stack_pointer_rtx)
9323 vt_init_cfa_base ();
9326 else if (!crtl->stack_realign_tried)
9330 #ifdef FRAME_POINTER_CFA_OFFSET
9331 reg = frame_pointer_rtx;
9332 fp_cfa_offset = FRAME_POINTER_CFA_OFFSET (current_function_decl);
9334 reg = arg_pointer_rtx;
9335 fp_cfa_offset = ARG_POINTER_CFA_OFFSET (current_function_decl);
9337 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9340 if (GET_CODE (elim) == PLUS)
9342 fp_cfa_offset -= INTVAL (XEXP (elim, 1));
9343 elim = XEXP (elim, 0);
9345 if (elim != hard_frame_pointer_rtx)
9352 /* If the stack is realigned and a DRAP register is used, we're going to
9353 rewrite MEMs based on it representing incoming locations of parameters
9354 passed on the stack into MEMs based on the argument pointer. Although
9355 we aren't going to rewrite other MEMs, we still need to initialize the
9356 virtual CFA pointer in order to ensure that the argument pointer will
9357 be seen as a constant throughout the function.
9359 ??? This doesn't work if FRAME_POINTER_CFA_OFFSET is defined. */
9360 else if (stack_realign_drap)
9364 #ifdef FRAME_POINTER_CFA_OFFSET
9365 reg = frame_pointer_rtx;
9367 reg = arg_pointer_rtx;
9369 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
9372 if (GET_CODE (elim) == PLUS)
9373 elim = XEXP (elim, 0);
9374 if (elim == hard_frame_pointer_rtx)
9375 vt_init_cfa_base ();
9379 hard_frame_pointer_adjustment = -1;
9381 vt_add_function_parameters ();
9386 HOST_WIDE_INT pre, post = 0;
9387 basic_block first_bb, last_bb;
9389 if (MAY_HAVE_DEBUG_INSNS)
9391 cselib_record_sets_hook = add_with_sets;
9392 if (dump_file && (dump_flags & TDF_DETAILS))
9393 fprintf (dump_file, "first value: %i\n",
9394 cselib_get_next_uid ());
9401 if (bb->next_bb == EXIT_BLOCK_PTR
9402 || ! single_pred_p (bb->next_bb))
9404 e = find_edge (bb, bb->next_bb);
9405 if (! e || (e->flags & EDGE_FALLTHRU) == 0)
9411 /* Add the micro-operations to the vector. */
9412 FOR_BB_BETWEEN (bb, first_bb, last_bb->next_bb, next_bb)
9414 HOST_WIDE_INT offset = VTI (bb)->out.stack_adjust;
9415 VTI (bb)->out.stack_adjust = VTI (bb)->in.stack_adjust;
9416 for (insn = BB_HEAD (bb); insn != NEXT_INSN (BB_END (bb));
9417 insn = NEXT_INSN (insn))
9421 if (!frame_pointer_needed)
9423 insn_stack_adjust_offset_pre_post (insn, &pre, &post);
9427 mo.type = MO_ADJUST;
9430 if (dump_file && (dump_flags & TDF_DETAILS))
9431 log_op_type (PATTERN (insn), bb, insn,
9432 MO_ADJUST, dump_file);
9433 VEC_safe_push (micro_operation, heap, VTI (bb)->mos,
9435 VTI (bb)->out.stack_adjust += pre;
9439 cselib_hook_called = false;
9440 adjust_insn (bb, insn);
9441 if (MAY_HAVE_DEBUG_INSNS)
9444 prepare_call_arguments (bb, insn);
9445 cselib_process_insn (insn);
9446 if (dump_file && (dump_flags & TDF_DETAILS))
9448 print_rtl_single (dump_file, insn);
9449 dump_cselib_table (dump_file);
9452 if (!cselib_hook_called)
9453 add_with_sets (insn, 0, 0);
9456 if (!frame_pointer_needed && post)
9459 mo.type = MO_ADJUST;
9462 if (dump_file && (dump_flags & TDF_DETAILS))
9463 log_op_type (PATTERN (insn), bb, insn,
9464 MO_ADJUST, dump_file);
9465 VEC_safe_push (micro_operation, heap, VTI (bb)->mos,
9467 VTI (bb)->out.stack_adjust += post;
9470 if (bb == prologue_bb
9471 && fp_cfa_offset != -1
9472 && hard_frame_pointer_adjustment == -1
9473 && RTX_FRAME_RELATED_P (insn)
9474 && fp_setter (insn))
9476 vt_init_cfa_base ();
9477 hard_frame_pointer_adjustment = fp_cfa_offset;
9481 gcc_assert (offset == VTI (bb)->out.stack_adjust);
9486 if (MAY_HAVE_DEBUG_INSNS)
9488 cselib_preserve_only_values ();
9489 cselib_reset_table (cselib_get_next_uid ());
9490 cselib_record_sets_hook = NULL;
9494 hard_frame_pointer_adjustment = -1;
9495 VTI (ENTRY_BLOCK_PTR)->flooded = true;
9496 cfa_base_rtx = NULL_RTX;
9500 /* Get rid of all debug insns from the insn stream. */
9503 delete_debug_insns (void)
9508 if (!MAY_HAVE_DEBUG_INSNS)
9513 FOR_BB_INSNS_SAFE (bb, insn, next)
9514 if (DEBUG_INSN_P (insn))
9519 /* Run a fast, BB-local only version of var tracking, to take care of
9520 information that we don't do global analysis on, such that not all
9521 information is lost. If SKIPPED holds, we're skipping the global
9522 pass entirely, so we should try to use information it would have
9523 handled as well.. */
9526 vt_debug_insns_local (bool skipped ATTRIBUTE_UNUSED)
9528 /* ??? Just skip it all for now. */
9529 delete_debug_insns ();
9532 /* Free the data structures needed for variable tracking. */
9541 VEC_free (micro_operation, heap, VTI (bb)->mos);
9546 dataflow_set_destroy (&VTI (bb)->in);
9547 dataflow_set_destroy (&VTI (bb)->out);
9548 if (VTI (bb)->permp)
9550 dataflow_set_destroy (VTI (bb)->permp);
9551 XDELETE (VTI (bb)->permp);
9554 free_aux_for_blocks ();
9555 htab_delete (empty_shared_hash->htab);
9556 htab_delete (changed_variables);
9557 free_alloc_pool (attrs_pool);
9558 free_alloc_pool (var_pool);
9559 free_alloc_pool (loc_chain_pool);
9560 free_alloc_pool (shared_hash_pool);
9562 if (MAY_HAVE_DEBUG_INSNS)
9564 free_alloc_pool (valvar_pool);
9565 VEC_free (rtx, heap, preserved_values);
9567 BITMAP_FREE (scratch_regs);
9568 scratch_regs = NULL;
9571 #ifdef HAVE_window_save
9572 VEC_free (parm_reg_t, gc, windowed_parm_regs);
9576 XDELETEVEC (vui_vec);
9581 /* The entry point to variable tracking pass. */
9583 static inline unsigned int
9584 variable_tracking_main_1 (void)
9588 if (flag_var_tracking_assignments < 0)
9590 delete_debug_insns ();
9594 if (n_basic_blocks > 500 && n_edges / n_basic_blocks >= 20)
9596 vt_debug_insns_local (true);
9600 mark_dfs_back_edges ();
9601 if (!vt_initialize ())
9604 vt_debug_insns_local (true);
9608 success = vt_find_locations ();
9610 if (!success && flag_var_tracking_assignments > 0)
9614 delete_debug_insns ();
9616 /* This is later restored by our caller. */
9617 flag_var_tracking_assignments = 0;
9619 success = vt_initialize ();
9620 gcc_assert (success);
9622 success = vt_find_locations ();
9628 vt_debug_insns_local (false);
9632 if (dump_file && (dump_flags & TDF_DETAILS))
9634 dump_dataflow_sets ();
9635 dump_flow_info (dump_file, dump_flags);
9638 timevar_push (TV_VAR_TRACKING_EMIT);
9640 timevar_pop (TV_VAR_TRACKING_EMIT);
9643 vt_debug_insns_local (false);
9648 variable_tracking_main (void)
9651 int save = flag_var_tracking_assignments;
9653 ret = variable_tracking_main_1 ();
9655 flag_var_tracking_assignments = save;
9661 gate_handle_var_tracking (void)
9663 return (flag_var_tracking && !targetm.delay_vartrack);
9668 struct rtl_opt_pass pass_variable_tracking =
9672 "vartrack", /* name */
9673 gate_handle_var_tracking, /* gate */
9674 variable_tracking_main, /* execute */
9677 0, /* static_pass_number */
9678 TV_VAR_TRACKING, /* tv_id */
9679 0, /* properties_required */
9680 0, /* properties_provided */
9681 0, /* properties_destroyed */
9682 0, /* todo_flags_start */
9683 TODO_verify_rtl_sharing /* todo_flags_finish */