1 /* Variable tracking routines for the GNU compiler.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file contains the variable tracking pass. It computes where
21 variables are located (which registers or where in memory) at each position
22 in instruction stream and emits notes describing the locations.
23 Debug information (DWARF2 location lists) is finally generated from
25 With this debug information, it is possible to show variables
26 even when debugging optimized code.
28 How does the variable tracking pass work?
30 First, it scans RTL code for uses, stores and clobbers (register/memory
31 references in instructions), for call insns and for stack adjustments
32 separately for each basic block and saves them to an array of micro
34 The micro operations of one instruction are ordered so that
35 pre-modifying stack adjustment < use < use with no var < call insn <
36 < clobber < set < post-modifying stack adjustment
38 Then, a forward dataflow analysis is performed to find out how locations
39 of variables change through code and to propagate the variable locations
40 along control flow graph.
41 The IN set for basic block BB is computed as a union of OUT sets of BB's
42 predecessors, the OUT set for BB is copied from the IN set for BB and
43 is changed according to micro operations in BB.
45 The IN and OUT sets for basic blocks consist of a current stack adjustment
46 (used for adjusting offset of variables addressed using stack pointer),
47 the table of structures describing the locations of parts of a variable
48 and for each physical register a linked list for each physical register.
49 The linked list is a list of variable parts stored in the register,
50 i.e. it is a list of triplets (reg, decl, offset) where decl is
51 REG_EXPR (reg) and offset is REG_OFFSET (reg). The linked list is used for
52 effective deleting appropriate variable parts when we set or clobber the
55 There may be more than one variable part in a register. The linked lists
56 should be pretty short so it is a good data structure here.
57 For example in the following code, register allocator may assign same
58 register to variables A and B, and both of them are stored in the same
71 Finally, the NOTE_INSN_VAR_LOCATION notes describing the variable locations
72 are emitted to appropriate positions in RTL code. Each such a note describes
73 the location of one variable at the point in instruction stream where the
74 note is. There is no need to emit a note for each variable before each
75 instruction, we only emit these notes where the location of variable changes
76 (this means that we also emit notes for changes between the OUT set of the
77 previous block and the IN set of the current block).
79 The notes consist of two parts:
80 1. the declaration (from REG_EXPR or MEM_EXPR)
81 2. the location of a variable - it is either a simple register/memory
82 reference (for simple variables, for example int),
83 or a parallel of register/memory references (for a large variables
84 which consist of several parts, for example long long).
90 #include "coretypes.h"
95 #include "hard-reg-set.h"
96 #include "basic-block.h"
98 #include "insn-config.h"
101 #include "alloc-pool.h"
103 #include "hash-table.h"
106 #include "tree-pass.h"
107 #include "tree-flow.h"
111 #include "diagnostic.h"
112 #include "tree-pretty-print.h"
113 #include "pointer-set.h"
118 /* var-tracking.c assumes that tree code with the same value as VALUE rtx code
119 has no chance to appear in REG_EXPR/MEM_EXPRs and isn't a decl.
120 Currently the value is the same as IDENTIFIER_NODE, which has such
121 a property. If this compile time assertion ever fails, make sure that
122 the new tree code that equals (int) VALUE has the same property. */
123 extern char check_value_val
[(int) VALUE
== (int) IDENTIFIER_NODE
? 1 : -1];
125 /* Type of micro operation. */
126 enum micro_operation_type
128 MO_USE
, /* Use location (REG or MEM). */
129 MO_USE_NO_VAR
,/* Use location which is not associated with a variable
130 or the variable is not trackable. */
131 MO_VAL_USE
, /* Use location which is associated with a value. */
132 MO_VAL_LOC
, /* Use location which appears in a debug insn. */
133 MO_VAL_SET
, /* Set location associated with a value. */
134 MO_SET
, /* Set location. */
135 MO_COPY
, /* Copy the same portion of a variable from one
136 location to another. */
137 MO_CLOBBER
, /* Clobber location. */
138 MO_CALL
, /* Call insn. */
139 MO_ADJUST
/* Adjust stack pointer. */
143 static const char * const ATTRIBUTE_UNUSED
144 micro_operation_type_name
[] = {
157 /* Where shall the note be emitted? BEFORE or AFTER the instruction.
158 Notes emitted as AFTER_CALL are to take effect during the call,
159 rather than after the call. */
162 EMIT_NOTE_BEFORE_INSN
,
163 EMIT_NOTE_AFTER_INSN
,
164 EMIT_NOTE_AFTER_CALL_INSN
167 /* Structure holding information about micro operation. */
168 typedef struct micro_operation_def
170 /* Type of micro operation. */
171 enum micro_operation_type type
;
173 /* The instruction which the micro operation is in, for MO_USE,
174 MO_USE_NO_VAR, MO_CALL and MO_ADJUST, or the subsequent
175 instruction or note in the original flow (before any var-tracking
176 notes are inserted, to simplify emission of notes), for MO_SET
181 /* Location. For MO_SET and MO_COPY, this is the SET that
182 performs the assignment, if known, otherwise it is the target
183 of the assignment. For MO_VAL_USE and MO_VAL_SET, it is a
184 CONCAT of the VALUE and the LOC associated with it. For
185 MO_VAL_LOC, it is a CONCAT of the VALUE and the VAR_LOCATION
186 associated with it. */
189 /* Stack adjustment. */
190 HOST_WIDE_INT adjust
;
195 /* A declaration of a variable, or an RTL value being handled like a
197 typedef void *decl_or_value
;
199 /* Return true if a decl_or_value DV is a DECL or NULL. */
201 dv_is_decl_p (decl_or_value dv
)
203 return !dv
|| (int) TREE_CODE ((tree
) dv
) != (int) VALUE
;
206 /* Return true if a decl_or_value is a VALUE rtl. */
208 dv_is_value_p (decl_or_value dv
)
210 return dv
&& !dv_is_decl_p (dv
);
213 /* Return the decl in the decl_or_value. */
215 dv_as_decl (decl_or_value dv
)
217 gcc_checking_assert (dv_is_decl_p (dv
));
221 /* Return the value in the decl_or_value. */
223 dv_as_value (decl_or_value dv
)
225 gcc_checking_assert (dv_is_value_p (dv
));
229 /* Return the opaque pointer in the decl_or_value. */
231 dv_as_opaque (decl_or_value dv
)
237 /* Description of location of a part of a variable. The content of a physical
238 register is described by a chain of these structures.
239 The chains are pretty short (usually 1 or 2 elements) and thus
240 chain is the best data structure. */
241 typedef struct attrs_def
243 /* Pointer to next member of the list. */
244 struct attrs_def
*next
;
246 /* The rtx of register. */
249 /* The declaration corresponding to LOC. */
252 /* Offset from start of DECL. */
253 HOST_WIDE_INT offset
;
256 /* Structure for chaining the locations. */
257 typedef struct location_chain_def
259 /* Next element in the chain. */
260 struct location_chain_def
*next
;
262 /* The location (REG, MEM or VALUE). */
265 /* The "value" stored in this location. */
269 enum var_init_status init
;
272 /* A vector of loc_exp_dep holds the active dependencies of a one-part
273 DV on VALUEs, i.e., the VALUEs expanded so as to form the current
274 location of DV. Each entry is also part of VALUE' s linked-list of
275 backlinks back to DV. */
276 typedef struct loc_exp_dep_s
278 /* The dependent DV. */
280 /* The dependency VALUE or DECL_DEBUG. */
282 /* The next entry in VALUE's backlinks list. */
283 struct loc_exp_dep_s
*next
;
284 /* A pointer to the pointer to this entry (head or prev's next) in
285 the doubly-linked list. */
286 struct loc_exp_dep_s
**pprev
;
290 /* This data structure holds information about the depth of a variable
292 typedef struct expand_depth_struct
294 /* This measures the complexity of the expanded expression. It
295 grows by one for each level of expansion that adds more than one
298 /* This counts the number of ENTRY_VALUE expressions in an
299 expansion. We want to minimize their use. */
303 /* This data structure is allocated for one-part variables at the time
304 of emitting notes. */
307 /* Doubly-linked list of dependent DVs. These are DVs whose cur_loc
308 computation used the expansion of this variable, and that ought
309 to be notified should this variable change. If the DV's cur_loc
310 expanded to NULL, all components of the loc list are regarded as
311 active, so that any changes in them give us a chance to get a
312 location. Otherwise, only components of the loc that expanded to
313 non-NULL are regarded as active dependencies. */
314 loc_exp_dep
*backlinks
;
315 /* This holds the LOC that was expanded into cur_loc. We need only
316 mark a one-part variable as changed if the FROM loc is removed,
317 or if it has no known location and a loc is added, or if it gets
318 a change notification from any of its active dependencies. */
320 /* The depth of the cur_loc expression. */
322 /* Dependencies actively used when expand FROM into cur_loc. */
323 vec
<loc_exp_dep
, va_heap
, vl_embed
> deps
;
326 /* Structure describing one part of variable. */
327 typedef struct variable_part_def
329 /* Chain of locations of the part. */
330 location_chain loc_chain
;
332 /* Location which was last emitted to location list. */
337 /* The offset in the variable, if !var->onepart. */
338 HOST_WIDE_INT offset
;
340 /* Pointer to auxiliary data, if var->onepart and emit_notes. */
341 struct onepart_aux
*onepaux
;
345 /* Maximum number of location parts. */
346 #define MAX_VAR_PARTS 16
348 /* Enumeration type used to discriminate various types of one-part
350 typedef enum onepart_enum
352 /* Not a one-part variable. */
354 /* A one-part DECL that is not a DEBUG_EXPR_DECL. */
356 /* A DEBUG_EXPR_DECL. */
362 /* Structure describing where the variable is located. */
363 typedef struct variable_def
365 /* The declaration of the variable, or an RTL value being handled
366 like a declaration. */
369 /* Reference count. */
372 /* Number of variable parts. */
375 /* What type of DV this is, according to enum onepart_enum. */
376 ENUM_BITFIELD (onepart_enum
) onepart
: CHAR_BIT
;
378 /* True if this variable_def struct is currently in the
379 changed_variables hash table. */
380 bool in_changed_variables
;
382 /* The variable parts. */
383 variable_part var_part
[1];
385 typedef const struct variable_def
*const_variable
;
387 /* Pointer to the BB's information specific to variable tracking pass. */
388 #define VTI(BB) ((variable_tracking_info) (BB)->aux)
390 /* Macro to access MEM_OFFSET as an HOST_WIDE_INT. Evaluates MEM twice. */
391 #define INT_MEM_OFFSET(mem) (MEM_OFFSET_KNOWN_P (mem) ? MEM_OFFSET (mem) : 0)
393 #if ENABLE_CHECKING && (GCC_VERSION >= 2007)
395 /* Access VAR's Ith part's offset, checking that it's not a one-part
397 #define VAR_PART_OFFSET(var, i) __extension__ \
398 (*({ variable const __v = (var); \
399 gcc_checking_assert (!__v->onepart); \
400 &__v->var_part[(i)].aux.offset; }))
402 /* Access VAR's one-part auxiliary data, checking that it is a
403 one-part variable. */
404 #define VAR_LOC_1PAUX(var) __extension__ \
405 (*({ variable const __v = (var); \
406 gcc_checking_assert (__v->onepart); \
407 &__v->var_part[0].aux.onepaux; }))
410 #define VAR_PART_OFFSET(var, i) ((var)->var_part[(i)].aux.offset)
411 #define VAR_LOC_1PAUX(var) ((var)->var_part[0].aux.onepaux)
414 /* These are accessor macros for the one-part auxiliary data. When
415 convenient for users, they're guarded by tests that the data was
417 #define VAR_LOC_DEP_LST(var) (VAR_LOC_1PAUX (var) \
418 ? VAR_LOC_1PAUX (var)->backlinks \
420 #define VAR_LOC_DEP_LSTP(var) (VAR_LOC_1PAUX (var) \
421 ? &VAR_LOC_1PAUX (var)->backlinks \
423 #define VAR_LOC_FROM(var) (VAR_LOC_1PAUX (var)->from)
424 #define VAR_LOC_DEPTH(var) (VAR_LOC_1PAUX (var)->depth)
425 #define VAR_LOC_DEP_VEC(var) (VAR_LOC_1PAUX (var) \
426 ? &VAR_LOC_1PAUX (var)->deps \
431 typedef unsigned int dvuid
;
433 /* Return the uid of DV. */
436 dv_uid (decl_or_value dv
)
438 if (dv_is_value_p (dv
))
439 return CSELIB_VAL_PTR (dv_as_value (dv
))->uid
;
441 return DECL_UID (dv_as_decl (dv
));
444 /* Compute the hash from the uid. */
446 static inline hashval_t
447 dv_uid2hash (dvuid uid
)
452 /* The hash function for a mask table in a shared_htab chain. */
454 static inline hashval_t
455 dv_htab_hash (decl_or_value dv
)
457 return dv_uid2hash (dv_uid (dv
));
460 static void variable_htab_free (void *);
462 /* Variable hashtable helpers. */
464 struct variable_hasher
466 typedef variable_def value_type
;
467 typedef void compare_type
;
468 static inline hashval_t
hash (const value_type
*);
469 static inline bool equal (const value_type
*, const compare_type
*);
470 static inline void remove (value_type
*);
473 /* The hash function for variable_htab, computes the hash value
474 from the declaration of variable X. */
477 variable_hasher::hash (const value_type
*v
)
479 return dv_htab_hash (v
->dv
);
482 /* Compare the declaration of variable X with declaration Y. */
485 variable_hasher::equal (const value_type
*v
, const compare_type
*y
)
487 decl_or_value dv
= CONST_CAST2 (decl_or_value
, const void *, y
);
489 return (dv_as_opaque (v
->dv
) == dv_as_opaque (dv
));
492 /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
495 variable_hasher::remove (value_type
*var
)
497 variable_htab_free (var
);
500 typedef hash_table
<variable_hasher
> variable_table_type
;
501 typedef variable_table_type::iterator variable_iterator_type
;
503 /* Structure for passing some other parameters to function
504 emit_note_insn_var_location. */
505 typedef struct emit_note_data_def
507 /* The instruction which the note will be emitted before/after. */
510 /* Where the note will be emitted (before/after insn)? */
511 enum emit_note_where where
;
513 /* The variables and values active at this point. */
514 variable_table_type vars
;
517 /* Structure holding a refcounted hash table. If refcount > 1,
518 it must be first unshared before modified. */
519 typedef struct shared_hash_def
521 /* Reference count. */
524 /* Actual hash table. */
525 variable_table_type htab
;
528 /* Structure holding the IN or OUT set for a basic block. */
529 typedef struct dataflow_set_def
531 /* Adjustment of stack offset. */
532 HOST_WIDE_INT stack_adjust
;
534 /* Attributes for registers (lists of attrs). */
535 attrs regs
[FIRST_PSEUDO_REGISTER
];
537 /* Variable locations. */
540 /* Vars that is being traversed. */
541 shared_hash traversed_vars
;
544 /* The structure (one for each basic block) containing the information
545 needed for variable tracking. */
546 typedef struct variable_tracking_info_def
548 /* The vector of micro operations. */
549 vec
<micro_operation
> mos
;
551 /* The IN and OUT set for dataflow analysis. */
555 /* The permanent-in dataflow set for this block. This is used to
556 hold values for which we had to compute entry values. ??? This
557 should probably be dynamically allocated, to avoid using more
558 memory in non-debug builds. */
561 /* Has the block been visited in DFS? */
564 /* Has the block been flooded in VTA? */
567 } *variable_tracking_info
;
569 /* Alloc pool for struct attrs_def. */
570 static alloc_pool attrs_pool
;
572 /* Alloc pool for struct variable_def with MAX_VAR_PARTS entries. */
573 static alloc_pool var_pool
;
575 /* Alloc pool for struct variable_def with a single var_part entry. */
576 static alloc_pool valvar_pool
;
578 /* Alloc pool for struct location_chain_def. */
579 static alloc_pool loc_chain_pool
;
581 /* Alloc pool for struct shared_hash_def. */
582 static alloc_pool shared_hash_pool
;
584 /* Alloc pool for struct loc_exp_dep_s for NOT_ONEPART variables. */
585 static alloc_pool loc_exp_dep_pool
;
587 /* Changed variables, notes will be emitted for them. */
588 static variable_table_type changed_variables
;
590 /* Shall notes be emitted? */
591 static bool emit_notes
;
593 /* Values whose dynamic location lists have gone empty, but whose
594 cselib location lists are still usable. Use this to hold the
595 current location, the backlinks, etc, during emit_notes. */
596 static variable_table_type dropped_values
;
598 /* Empty shared hashtable. */
599 static shared_hash empty_shared_hash
;
601 /* Scratch register bitmap used by cselib_expand_value_rtx. */
602 static bitmap scratch_regs
= NULL
;
604 #ifdef HAVE_window_save
605 typedef struct GTY(()) parm_reg
{
611 /* Vector of windowed parameter registers, if any. */
612 static vec
<parm_reg_t
, va_gc
> *windowed_parm_regs
= NULL
;
615 /* Variable used to tell whether cselib_process_insn called our hook. */
616 static bool cselib_hook_called
;
618 /* Local function prototypes. */
619 static void stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
621 static void insn_stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
623 static bool vt_stack_adjustments (void);
625 static void init_attrs_list_set (attrs
*);
626 static void attrs_list_clear (attrs
*);
627 static attrs
attrs_list_member (attrs
, decl_or_value
, HOST_WIDE_INT
);
628 static void attrs_list_insert (attrs
*, decl_or_value
, HOST_WIDE_INT
, rtx
);
629 static void attrs_list_copy (attrs
*, attrs
);
630 static void attrs_list_union (attrs
*, attrs
);
632 static variable_def
**unshare_variable (dataflow_set
*set
, variable_def
**slot
,
633 variable var
, enum var_init_status
);
634 static void vars_copy (variable_table_type
, variable_table_type
);
635 static tree
var_debug_decl (tree
);
636 static void var_reg_set (dataflow_set
*, rtx
, enum var_init_status
, rtx
);
637 static void var_reg_delete_and_set (dataflow_set
*, rtx
, bool,
638 enum var_init_status
, rtx
);
639 static void var_reg_delete (dataflow_set
*, rtx
, bool);
640 static void var_regno_delete (dataflow_set
*, int);
641 static void var_mem_set (dataflow_set
*, rtx
, enum var_init_status
, rtx
);
642 static void var_mem_delete_and_set (dataflow_set
*, rtx
, bool,
643 enum var_init_status
, rtx
);
644 static void var_mem_delete (dataflow_set
*, rtx
, bool);
646 static void dataflow_set_init (dataflow_set
*);
647 static void dataflow_set_clear (dataflow_set
*);
648 static void dataflow_set_copy (dataflow_set
*, dataflow_set
*);
649 static int variable_union_info_cmp_pos (const void *, const void *);
650 static void dataflow_set_union (dataflow_set
*, dataflow_set
*);
651 static location_chain
find_loc_in_1pdv (rtx
, variable
, variable_table_type
);
652 static bool canon_value_cmp (rtx
, rtx
);
653 static int loc_cmp (rtx
, rtx
);
654 static bool variable_part_different_p (variable_part
*, variable_part
*);
655 static bool onepart_variable_different_p (variable
, variable
);
656 static bool variable_different_p (variable
, variable
);
657 static bool dataflow_set_different (dataflow_set
*, dataflow_set
*);
658 static void dataflow_set_destroy (dataflow_set
*);
660 static bool contains_symbol_ref (rtx
);
661 static bool track_expr_p (tree
, bool);
662 static bool same_variable_part_p (rtx
, tree
, HOST_WIDE_INT
);
663 static int add_uses (rtx
*, void *);
664 static void add_uses_1 (rtx
*, void *);
665 static void add_stores (rtx
, const_rtx
, void *);
666 static bool compute_bb_dataflow (basic_block
);
667 static bool vt_find_locations (void);
669 static void dump_attrs_list (attrs
);
670 static void dump_var (variable
);
671 static void dump_vars (variable_table_type
);
672 static void dump_dataflow_set (dataflow_set
*);
673 static void dump_dataflow_sets (void);
675 static void set_dv_changed (decl_or_value
, bool);
676 static void variable_was_changed (variable
, dataflow_set
*);
677 static variable_def
**set_slot_part (dataflow_set
*, rtx
, variable_def
**,
678 decl_or_value
, HOST_WIDE_INT
,
679 enum var_init_status
, rtx
);
680 static void set_variable_part (dataflow_set
*, rtx
,
681 decl_or_value
, HOST_WIDE_INT
,
682 enum var_init_status
, rtx
, enum insert_option
);
683 static variable_def
**clobber_slot_part (dataflow_set
*, rtx
,
684 variable_def
**, HOST_WIDE_INT
, rtx
);
685 static void clobber_variable_part (dataflow_set
*, rtx
,
686 decl_or_value
, HOST_WIDE_INT
, rtx
);
687 static variable_def
**delete_slot_part (dataflow_set
*, rtx
, variable_def
**,
689 static void delete_variable_part (dataflow_set
*, rtx
,
690 decl_or_value
, HOST_WIDE_INT
);
691 static void emit_notes_in_bb (basic_block
, dataflow_set
*);
692 static void vt_emit_notes (void);
694 static bool vt_get_decl_and_offset (rtx
, tree
*, HOST_WIDE_INT
*);
695 static void vt_add_function_parameters (void);
696 static bool vt_initialize (void);
697 static void vt_finalize (void);
699 /* Given a SET, calculate the amount of stack adjustment it contains
700 PRE- and POST-modifying stack pointer.
701 This function is similar to stack_adjust_offset. */
704 stack_adjust_offset_pre_post (rtx pattern
, HOST_WIDE_INT
*pre
,
707 rtx src
= SET_SRC (pattern
);
708 rtx dest
= SET_DEST (pattern
);
711 if (dest
== stack_pointer_rtx
)
713 /* (set (reg sp) (plus (reg sp) (const_int))) */
714 code
= GET_CODE (src
);
715 if (! (code
== PLUS
|| code
== MINUS
)
716 || XEXP (src
, 0) != stack_pointer_rtx
717 || !CONST_INT_P (XEXP (src
, 1)))
721 *post
+= INTVAL (XEXP (src
, 1));
723 *post
-= INTVAL (XEXP (src
, 1));
725 else if (MEM_P (dest
))
727 /* (set (mem (pre_dec (reg sp))) (foo)) */
728 src
= XEXP (dest
, 0);
729 code
= GET_CODE (src
);
735 if (XEXP (src
, 0) == stack_pointer_rtx
)
737 rtx val
= XEXP (XEXP (src
, 1), 1);
738 /* We handle only adjustments by constant amount. */
739 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
&&
742 if (code
== PRE_MODIFY
)
743 *pre
-= INTVAL (val
);
745 *post
-= INTVAL (val
);
751 if (XEXP (src
, 0) == stack_pointer_rtx
)
753 *pre
+= GET_MODE_SIZE (GET_MODE (dest
));
759 if (XEXP (src
, 0) == stack_pointer_rtx
)
761 *post
+= GET_MODE_SIZE (GET_MODE (dest
));
767 if (XEXP (src
, 0) == stack_pointer_rtx
)
769 *pre
-= GET_MODE_SIZE (GET_MODE (dest
));
775 if (XEXP (src
, 0) == stack_pointer_rtx
)
777 *post
-= GET_MODE_SIZE (GET_MODE (dest
));
788 /* Given an INSN, calculate the amount of stack adjustment it contains
789 PRE- and POST-modifying stack pointer. */
792 insn_stack_adjust_offset_pre_post (rtx insn
, HOST_WIDE_INT
*pre
,
800 pattern
= PATTERN (insn
);
801 if (RTX_FRAME_RELATED_P (insn
))
803 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
805 pattern
= XEXP (expr
, 0);
808 if (GET_CODE (pattern
) == SET
)
809 stack_adjust_offset_pre_post (pattern
, pre
, post
);
810 else if (GET_CODE (pattern
) == PARALLEL
811 || GET_CODE (pattern
) == SEQUENCE
)
815 /* There may be stack adjustments inside compound insns. Search
817 for ( i
= XVECLEN (pattern
, 0) - 1; i
>= 0; i
--)
818 if (GET_CODE (XVECEXP (pattern
, 0, i
)) == SET
)
819 stack_adjust_offset_pre_post (XVECEXP (pattern
, 0, i
), pre
, post
);
823 /* Compute stack adjustments for all blocks by traversing DFS tree.
824 Return true when the adjustments on all incoming edges are consistent.
825 Heavily borrowed from pre_and_rev_post_order_compute. */
828 vt_stack_adjustments (void)
830 edge_iterator
*stack
;
833 /* Initialize entry block. */
834 VTI (ENTRY_BLOCK_PTR
)->visited
= true;
835 VTI (ENTRY_BLOCK_PTR
)->in
.stack_adjust
= INCOMING_FRAME_SP_OFFSET
;
836 VTI (ENTRY_BLOCK_PTR
)->out
.stack_adjust
= INCOMING_FRAME_SP_OFFSET
;
838 /* Allocate stack for back-tracking up CFG. */
839 stack
= XNEWVEC (edge_iterator
, n_basic_blocks
+ 1);
842 /* Push the first edge on to the stack. */
843 stack
[sp
++] = ei_start (ENTRY_BLOCK_PTR
->succs
);
851 /* Look at the edge on the top of the stack. */
853 src
= ei_edge (ei
)->src
;
854 dest
= ei_edge (ei
)->dest
;
856 /* Check if the edge destination has been visited yet. */
857 if (!VTI (dest
)->visited
)
860 HOST_WIDE_INT pre
, post
, offset
;
861 VTI (dest
)->visited
= true;
862 VTI (dest
)->in
.stack_adjust
= offset
= VTI (src
)->out
.stack_adjust
;
864 if (dest
!= EXIT_BLOCK_PTR
)
865 for (insn
= BB_HEAD (dest
);
866 insn
!= NEXT_INSN (BB_END (dest
));
867 insn
= NEXT_INSN (insn
))
870 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
871 offset
+= pre
+ post
;
874 VTI (dest
)->out
.stack_adjust
= offset
;
876 if (EDGE_COUNT (dest
->succs
) > 0)
877 /* Since the DEST node has been visited for the first
878 time, check its successors. */
879 stack
[sp
++] = ei_start (dest
->succs
);
883 /* Check whether the adjustments on the edges are the same. */
884 if (VTI (dest
)->in
.stack_adjust
!= VTI (src
)->out
.stack_adjust
)
890 if (! ei_one_before_end_p (ei
))
891 /* Go to the next edge. */
892 ei_next (&stack
[sp
- 1]);
894 /* Return to previous level if there are no more edges. */
903 /* arg_pointer_rtx resp. frame_pointer_rtx if stack_pointer_rtx or
904 hard_frame_pointer_rtx is being mapped to it and offset for it. */
905 static rtx cfa_base_rtx
;
906 static HOST_WIDE_INT cfa_base_offset
;
908 /* Compute a CFA-based value for an ADJUSTMENT made to stack_pointer_rtx
909 or hard_frame_pointer_rtx. */
912 compute_cfa_pointer (HOST_WIDE_INT adjustment
)
914 return plus_constant (Pmode
, cfa_base_rtx
, adjustment
+ cfa_base_offset
);
917 /* Adjustment for hard_frame_pointer_rtx to cfa base reg,
918 or -1 if the replacement shouldn't be done. */
919 static HOST_WIDE_INT hard_frame_pointer_adjustment
= -1;
921 /* Data for adjust_mems callback. */
923 struct adjust_mem_data
926 enum machine_mode mem_mode
;
927 HOST_WIDE_INT stack_adjust
;
931 /* Helper for adjust_mems. Return 1 if *loc is unsuitable for
932 transformation of wider mode arithmetics to narrower mode,
933 -1 if it is suitable and subexpressions shouldn't be
934 traversed and 0 if it is suitable and subexpressions should
935 be traversed. Called through for_each_rtx. */
938 use_narrower_mode_test (rtx
*loc
, void *data
)
940 rtx subreg
= (rtx
) data
;
942 if (CONSTANT_P (*loc
))
944 switch (GET_CODE (*loc
))
947 if (cselib_lookup (*loc
, GET_MODE (SUBREG_REG (subreg
)), 0, VOIDmode
))
949 if (!validate_subreg (GET_MODE (subreg
), GET_MODE (*loc
),
950 *loc
, subreg_lowpart_offset (GET_MODE (subreg
),
959 if (for_each_rtx (&XEXP (*loc
, 0), use_narrower_mode_test
, data
))
968 /* Transform X into narrower mode MODE from wider mode WMODE. */
971 use_narrower_mode (rtx x
, enum machine_mode mode
, enum machine_mode wmode
)
975 return lowpart_subreg (mode
, x
, wmode
);
976 switch (GET_CODE (x
))
979 return lowpart_subreg (mode
, x
, wmode
);
983 op0
= use_narrower_mode (XEXP (x
, 0), mode
, wmode
);
984 op1
= use_narrower_mode (XEXP (x
, 1), mode
, wmode
);
985 return simplify_gen_binary (GET_CODE (x
), mode
, op0
, op1
);
987 op0
= use_narrower_mode (XEXP (x
, 0), mode
, wmode
);
988 return simplify_gen_binary (ASHIFT
, mode
, op0
, XEXP (x
, 1));
994 /* Helper function for adjusting used MEMs. */
997 adjust_mems (rtx loc
, const_rtx old_rtx
, void *data
)
999 struct adjust_mem_data
*amd
= (struct adjust_mem_data
*) data
;
1000 rtx mem
, addr
= loc
, tem
;
1001 enum machine_mode mem_mode_save
;
1003 switch (GET_CODE (loc
))
1006 /* Don't do any sp or fp replacements outside of MEM addresses
1008 if (amd
->mem_mode
== VOIDmode
&& amd
->store
)
1010 if (loc
== stack_pointer_rtx
1011 && !frame_pointer_needed
1013 return compute_cfa_pointer (amd
->stack_adjust
);
1014 else if (loc
== hard_frame_pointer_rtx
1015 && frame_pointer_needed
1016 && hard_frame_pointer_adjustment
!= -1
1018 return compute_cfa_pointer (hard_frame_pointer_adjustment
);
1019 gcc_checking_assert (loc
!= virtual_incoming_args_rtx
);
1025 mem
= targetm
.delegitimize_address (mem
);
1026 if (mem
!= loc
&& !MEM_P (mem
))
1027 return simplify_replace_fn_rtx (mem
, old_rtx
, adjust_mems
, data
);
1030 addr
= XEXP (mem
, 0);
1031 mem_mode_save
= amd
->mem_mode
;
1032 amd
->mem_mode
= GET_MODE (mem
);
1033 store_save
= amd
->store
;
1035 addr
= simplify_replace_fn_rtx (addr
, old_rtx
, adjust_mems
, data
);
1036 amd
->store
= store_save
;
1037 amd
->mem_mode
= mem_mode_save
;
1039 addr
= targetm
.delegitimize_address (addr
);
1040 if (addr
!= XEXP (mem
, 0))
1041 mem
= replace_equiv_address_nv (mem
, addr
);
1043 mem
= avoid_constant_pool_reference (mem
);
1047 addr
= gen_rtx_PLUS (GET_MODE (loc
), XEXP (loc
, 0),
1048 GEN_INT (GET_CODE (loc
) == PRE_INC
1049 ? GET_MODE_SIZE (amd
->mem_mode
)
1050 : -GET_MODE_SIZE (amd
->mem_mode
)));
1054 addr
= XEXP (loc
, 0);
1055 gcc_assert (amd
->mem_mode
!= VOIDmode
&& amd
->mem_mode
!= BLKmode
);
1056 addr
= simplify_replace_fn_rtx (addr
, old_rtx
, adjust_mems
, data
);
1057 tem
= gen_rtx_PLUS (GET_MODE (loc
), XEXP (loc
, 0),
1058 GEN_INT ((GET_CODE (loc
) == PRE_INC
1059 || GET_CODE (loc
) == POST_INC
)
1060 ? GET_MODE_SIZE (amd
->mem_mode
)
1061 : -GET_MODE_SIZE (amd
->mem_mode
)));
1062 amd
->side_effects
= alloc_EXPR_LIST (0,
1063 gen_rtx_SET (VOIDmode
,
1069 addr
= XEXP (loc
, 1);
1072 addr
= XEXP (loc
, 0);
1073 gcc_assert (amd
->mem_mode
!= VOIDmode
);
1074 addr
= simplify_replace_fn_rtx (addr
, old_rtx
, adjust_mems
, data
);
1075 amd
->side_effects
= alloc_EXPR_LIST (0,
1076 gen_rtx_SET (VOIDmode
,
1082 /* First try without delegitimization of whole MEMs and
1083 avoid_constant_pool_reference, which is more likely to succeed. */
1084 store_save
= amd
->store
;
1086 addr
= simplify_replace_fn_rtx (SUBREG_REG (loc
), old_rtx
, adjust_mems
,
1088 amd
->store
= store_save
;
1089 mem
= simplify_replace_fn_rtx (addr
, old_rtx
, adjust_mems
, data
);
1090 if (mem
== SUBREG_REG (loc
))
1095 tem
= simplify_gen_subreg (GET_MODE (loc
), mem
,
1096 GET_MODE (SUBREG_REG (loc
)),
1100 tem
= simplify_gen_subreg (GET_MODE (loc
), addr
,
1101 GET_MODE (SUBREG_REG (loc
)),
1103 if (tem
== NULL_RTX
)
1104 tem
= gen_rtx_raw_SUBREG (GET_MODE (loc
), addr
, SUBREG_BYTE (loc
));
1106 if (MAY_HAVE_DEBUG_INSNS
1107 && GET_CODE (tem
) == SUBREG
1108 && (GET_CODE (SUBREG_REG (tem
)) == PLUS
1109 || GET_CODE (SUBREG_REG (tem
)) == MINUS
1110 || GET_CODE (SUBREG_REG (tem
)) == MULT
1111 || GET_CODE (SUBREG_REG (tem
)) == ASHIFT
)
1112 && GET_MODE_CLASS (GET_MODE (tem
)) == MODE_INT
1113 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (tem
))) == MODE_INT
1114 && GET_MODE_SIZE (GET_MODE (tem
))
1115 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (tem
)))
1116 && subreg_lowpart_p (tem
)
1117 && !for_each_rtx (&SUBREG_REG (tem
), use_narrower_mode_test
, tem
))
1118 return use_narrower_mode (SUBREG_REG (tem
), GET_MODE (tem
),
1119 GET_MODE (SUBREG_REG (tem
)));
1122 /* Don't do any replacements in second and following
1123 ASM_OPERANDS of inline-asm with multiple sets.
1124 ASM_OPERANDS_INPUT_VEC, ASM_OPERANDS_INPUT_CONSTRAINT_VEC
1125 and ASM_OPERANDS_LABEL_VEC need to be equal between
1126 all the ASM_OPERANDs in the insn and adjust_insn will
1128 if (ASM_OPERANDS_OUTPUT_IDX (loc
) != 0)
1137 /* Helper function for replacement of uses. */
1140 adjust_mem_uses (rtx
*x
, void *data
)
1142 rtx new_x
= simplify_replace_fn_rtx (*x
, NULL_RTX
, adjust_mems
, data
);
1144 validate_change (NULL_RTX
, x
, new_x
, true);
1147 /* Helper function for replacement of stores. */
1150 adjust_mem_stores (rtx loc
, const_rtx expr
, void *data
)
1154 rtx new_dest
= simplify_replace_fn_rtx (SET_DEST (expr
), NULL_RTX
,
1156 if (new_dest
!= SET_DEST (expr
))
1158 rtx xexpr
= CONST_CAST_RTX (expr
);
1159 validate_change (NULL_RTX
, &SET_DEST (xexpr
), new_dest
, true);
1164 /* Simplify INSN. Remove all {PRE,POST}_{INC,DEC,MODIFY} rtxes,
1165 replace them with their value in the insn and add the side-effects
1166 as other sets to the insn. */
1169 adjust_insn (basic_block bb
, rtx insn
)
1171 struct adjust_mem_data amd
;
1174 #ifdef HAVE_window_save
1175 /* If the target machine has an explicit window save instruction, the
1176 transformation OUTGOING_REGNO -> INCOMING_REGNO is done there. */
1177 if (RTX_FRAME_RELATED_P (insn
)
1178 && find_reg_note (insn
, REG_CFA_WINDOW_SAVE
, NULL_RTX
))
1180 unsigned int i
, nregs
= vec_safe_length (windowed_parm_regs
);
1181 rtx rtl
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (nregs
* 2));
1184 FOR_EACH_VEC_SAFE_ELT (windowed_parm_regs
, i
, p
)
1186 XVECEXP (rtl
, 0, i
* 2)
1187 = gen_rtx_SET (VOIDmode
, p
->incoming
, p
->outgoing
);
1188 /* Do not clobber the attached DECL, but only the REG. */
1189 XVECEXP (rtl
, 0, i
* 2 + 1)
1190 = gen_rtx_CLOBBER (GET_MODE (p
->outgoing
),
1191 gen_raw_REG (GET_MODE (p
->outgoing
),
1192 REGNO (p
->outgoing
)));
1195 validate_change (NULL_RTX
, &PATTERN (insn
), rtl
, true);
1200 amd
.mem_mode
= VOIDmode
;
1201 amd
.stack_adjust
= -VTI (bb
)->out
.stack_adjust
;
1202 amd
.side_effects
= NULL_RTX
;
1205 note_stores (PATTERN (insn
), adjust_mem_stores
, &amd
);
1208 if (GET_CODE (PATTERN (insn
)) == PARALLEL
1209 && asm_noperands (PATTERN (insn
)) > 0
1210 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == SET
)
1215 /* inline-asm with multiple sets is tiny bit more complicated,
1216 because the 3 vectors in ASM_OPERANDS need to be shared between
1217 all ASM_OPERANDS in the instruction. adjust_mems will
1218 not touch ASM_OPERANDS other than the first one, asm_noperands
1219 test above needs to be called before that (otherwise it would fail)
1220 and afterwards this code fixes it up. */
1221 note_uses (&PATTERN (insn
), adjust_mem_uses
, &amd
);
1222 body
= PATTERN (insn
);
1223 set0
= XVECEXP (body
, 0, 0);
1224 gcc_checking_assert (GET_CODE (set0
) == SET
1225 && GET_CODE (SET_SRC (set0
)) == ASM_OPERANDS
1226 && ASM_OPERANDS_OUTPUT_IDX (SET_SRC (set0
)) == 0);
1227 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1228 if (GET_CODE (XVECEXP (body
, 0, i
)) != SET
)
1232 set
= XVECEXP (body
, 0, i
);
1233 gcc_checking_assert (GET_CODE (SET_SRC (set
)) == ASM_OPERANDS
1234 && ASM_OPERANDS_OUTPUT_IDX (SET_SRC (set
))
1236 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (set
))
1237 != ASM_OPERANDS_INPUT_VEC (SET_SRC (set0
))
1238 || ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set
))
1239 != ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set0
))
1240 || ASM_OPERANDS_LABEL_VEC (SET_SRC (set
))
1241 != ASM_OPERANDS_LABEL_VEC (SET_SRC (set0
)))
1243 rtx newsrc
= shallow_copy_rtx (SET_SRC (set
));
1244 ASM_OPERANDS_INPUT_VEC (newsrc
)
1245 = ASM_OPERANDS_INPUT_VEC (SET_SRC (set0
));
1246 ASM_OPERANDS_INPUT_CONSTRAINT_VEC (newsrc
)
1247 = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set0
));
1248 ASM_OPERANDS_LABEL_VEC (newsrc
)
1249 = ASM_OPERANDS_LABEL_VEC (SET_SRC (set0
));
1250 validate_change (NULL_RTX
, &SET_SRC (set
), newsrc
, true);
1255 note_uses (&PATTERN (insn
), adjust_mem_uses
, &amd
);
1257 /* For read-only MEMs containing some constant, prefer those
1259 set
= single_set (insn
);
1260 if (set
&& MEM_P (SET_SRC (set
)) && MEM_READONLY_P (SET_SRC (set
)))
1262 rtx note
= find_reg_equal_equiv_note (insn
);
1264 if (note
&& CONSTANT_P (XEXP (note
, 0)))
1265 validate_change (NULL_RTX
, &SET_SRC (set
), XEXP (note
, 0), true);
1268 if (amd
.side_effects
)
1270 rtx
*pat
, new_pat
, s
;
1273 pat
= &PATTERN (insn
);
1274 if (GET_CODE (*pat
) == COND_EXEC
)
1275 pat
= &COND_EXEC_CODE (*pat
);
1276 if (GET_CODE (*pat
) == PARALLEL
)
1277 oldn
= XVECLEN (*pat
, 0);
1280 for (s
= amd
.side_effects
, newn
= 0; s
; newn
++)
1282 new_pat
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (oldn
+ newn
));
1283 if (GET_CODE (*pat
) == PARALLEL
)
1284 for (i
= 0; i
< oldn
; i
++)
1285 XVECEXP (new_pat
, 0, i
) = XVECEXP (*pat
, 0, i
);
1287 XVECEXP (new_pat
, 0, 0) = *pat
;
1288 for (s
= amd
.side_effects
, i
= oldn
; i
< oldn
+ newn
; i
++, s
= XEXP (s
, 1))
1289 XVECEXP (new_pat
, 0, i
) = XEXP (s
, 0);
1290 free_EXPR_LIST_list (&amd
.side_effects
);
1291 validate_change (NULL_RTX
, pat
, new_pat
, true);
1295 /* Return the DEBUG_EXPR of a DEBUG_EXPR_DECL or the VALUE in DV. */
1297 dv_as_rtx (decl_or_value dv
)
1301 if (dv_is_value_p (dv
))
1302 return dv_as_value (dv
);
1304 decl
= dv_as_decl (dv
);
1306 gcc_checking_assert (TREE_CODE (decl
) == DEBUG_EXPR_DECL
);
1307 return DECL_RTL_KNOWN_SET (decl
);
1310 /* Return nonzero if a decl_or_value must not have more than one
1311 variable part. The returned value discriminates among various
1312 kinds of one-part DVs ccording to enum onepart_enum. */
1313 static inline onepart_enum_t
1314 dv_onepart_p (decl_or_value dv
)
1318 if (!MAY_HAVE_DEBUG_INSNS
)
1321 if (dv_is_value_p (dv
))
1322 return ONEPART_VALUE
;
1324 decl
= dv_as_decl (dv
);
1326 if (TREE_CODE (decl
) == DEBUG_EXPR_DECL
)
1327 return ONEPART_DEXPR
;
1329 if (target_for_debug_bind (decl
) != NULL_TREE
)
1330 return ONEPART_VDECL
;
1335 /* Return the variable pool to be used for a dv of type ONEPART. */
1336 static inline alloc_pool
1337 onepart_pool (onepart_enum_t onepart
)
1339 return onepart
? valvar_pool
: var_pool
;
1342 /* Build a decl_or_value out of a decl. */
1343 static inline decl_or_value
1344 dv_from_decl (tree decl
)
1348 gcc_checking_assert (dv_is_decl_p (dv
));
1352 /* Build a decl_or_value out of a value. */
1353 static inline decl_or_value
1354 dv_from_value (rtx value
)
1358 gcc_checking_assert (dv_is_value_p (dv
));
1362 /* Return a value or the decl of a debug_expr as a decl_or_value. */
1363 static inline decl_or_value
1368 switch (GET_CODE (x
))
1371 dv
= dv_from_decl (DEBUG_EXPR_TREE_DECL (x
));
1372 gcc_checking_assert (DECL_RTL_KNOWN_SET (DEBUG_EXPR_TREE_DECL (x
)) == x
);
1376 dv
= dv_from_value (x
);
1386 extern void debug_dv (decl_or_value dv
);
1389 debug_dv (decl_or_value dv
)
1391 if (dv_is_value_p (dv
))
1392 debug_rtx (dv_as_value (dv
));
1394 debug_generic_stmt (dv_as_decl (dv
));
1397 static void loc_exp_dep_clear (variable var
);
1399 /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
1402 variable_htab_free (void *elem
)
1405 variable var
= (variable
) elem
;
1406 location_chain node
, next
;
1408 gcc_checking_assert (var
->refcount
> 0);
1411 if (var
->refcount
> 0)
1414 for (i
= 0; i
< var
->n_var_parts
; i
++)
1416 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= next
)
1419 pool_free (loc_chain_pool
, node
);
1421 var
->var_part
[i
].loc_chain
= NULL
;
1423 if (var
->onepart
&& VAR_LOC_1PAUX (var
))
1425 loc_exp_dep_clear (var
);
1426 if (VAR_LOC_DEP_LST (var
))
1427 VAR_LOC_DEP_LST (var
)->pprev
= NULL
;
1428 XDELETE (VAR_LOC_1PAUX (var
));
1429 /* These may be reused across functions, so reset
1431 if (var
->onepart
== ONEPART_DEXPR
)
1432 set_dv_changed (var
->dv
, true);
1434 pool_free (onepart_pool (var
->onepart
), var
);
1437 /* Initialize the set (array) SET of attrs to empty lists. */
1440 init_attrs_list_set (attrs
*set
)
1444 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1448 /* Make the list *LISTP empty. */
1451 attrs_list_clear (attrs
*listp
)
1455 for (list
= *listp
; list
; list
= next
)
1458 pool_free (attrs_pool
, list
);
1463 /* Return true if the pair of DECL and OFFSET is the member of the LIST. */
1466 attrs_list_member (attrs list
, decl_or_value dv
, HOST_WIDE_INT offset
)
1468 for (; list
; list
= list
->next
)
1469 if (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
) && list
->offset
== offset
)
1474 /* Insert the triplet DECL, OFFSET, LOC to the list *LISTP. */
1477 attrs_list_insert (attrs
*listp
, decl_or_value dv
,
1478 HOST_WIDE_INT offset
, rtx loc
)
1482 list
= (attrs
) pool_alloc (attrs_pool
);
1485 list
->offset
= offset
;
1486 list
->next
= *listp
;
1490 /* Copy all nodes from SRC and create a list *DSTP of the copies. */
1493 attrs_list_copy (attrs
*dstp
, attrs src
)
1497 attrs_list_clear (dstp
);
1498 for (; src
; src
= src
->next
)
1500 n
= (attrs
) pool_alloc (attrs_pool
);
1503 n
->offset
= src
->offset
;
1509 /* Add all nodes from SRC which are not in *DSTP to *DSTP. */
1512 attrs_list_union (attrs
*dstp
, attrs src
)
1514 for (; src
; src
= src
->next
)
1516 if (!attrs_list_member (*dstp
, src
->dv
, src
->offset
))
1517 attrs_list_insert (dstp
, src
->dv
, src
->offset
, src
->loc
);
1521 /* Combine nodes that are not onepart nodes from SRC and SRC2 into
1525 attrs_list_mpdv_union (attrs
*dstp
, attrs src
, attrs src2
)
1527 gcc_assert (!*dstp
);
1528 for (; src
; src
= src
->next
)
1530 if (!dv_onepart_p (src
->dv
))
1531 attrs_list_insert (dstp
, src
->dv
, src
->offset
, src
->loc
);
1533 for (src
= src2
; src
; src
= src
->next
)
1535 if (!dv_onepart_p (src
->dv
)
1536 && !attrs_list_member (*dstp
, src
->dv
, src
->offset
))
1537 attrs_list_insert (dstp
, src
->dv
, src
->offset
, src
->loc
);
1541 /* Shared hashtable support. */
1543 /* Return true if VARS is shared. */
1546 shared_hash_shared (shared_hash vars
)
1548 return vars
->refcount
> 1;
1551 /* Return the hash table for VARS. */
1553 static inline variable_table_type
1554 shared_hash_htab (shared_hash vars
)
1559 /* Return true if VAR is shared, or maybe because VARS is shared. */
1562 shared_var_p (variable var
, shared_hash vars
)
1564 /* Don't count an entry in the changed_variables table as a duplicate. */
1565 return ((var
->refcount
> 1 + (int) var
->in_changed_variables
)
1566 || shared_hash_shared (vars
));
1569 /* Copy variables into a new hash table. */
1572 shared_hash_unshare (shared_hash vars
)
1574 shared_hash new_vars
= (shared_hash
) pool_alloc (shared_hash_pool
);
1575 gcc_assert (vars
->refcount
> 1);
1576 new_vars
->refcount
= 1;
1577 new_vars
->htab
.create (vars
->htab
.elements () + 3);
1578 vars_copy (new_vars
->htab
, vars
->htab
);
1583 /* Increment reference counter on VARS and return it. */
1585 static inline shared_hash
1586 shared_hash_copy (shared_hash vars
)
1592 /* Decrement reference counter and destroy hash table if not shared
1596 shared_hash_destroy (shared_hash vars
)
1598 gcc_checking_assert (vars
->refcount
> 0);
1599 if (--vars
->refcount
== 0)
1601 vars
->htab
.dispose ();
1602 pool_free (shared_hash_pool
, vars
);
1606 /* Unshare *PVARS if shared and return slot for DV. If INS is
1607 INSERT, insert it if not already present. */
1609 static inline variable_def
**
1610 shared_hash_find_slot_unshare_1 (shared_hash
*pvars
, decl_or_value dv
,
1611 hashval_t dvhash
, enum insert_option ins
)
1613 if (shared_hash_shared (*pvars
))
1614 *pvars
= shared_hash_unshare (*pvars
);
1615 return shared_hash_htab (*pvars
).find_slot_with_hash (dv
, dvhash
, ins
);
1618 static inline variable_def
**
1619 shared_hash_find_slot_unshare (shared_hash
*pvars
, decl_or_value dv
,
1620 enum insert_option ins
)
1622 return shared_hash_find_slot_unshare_1 (pvars
, dv
, dv_htab_hash (dv
), ins
);
1625 /* Return slot for DV, if it is already present in the hash table.
1626 If it is not present, insert it only VARS is not shared, otherwise
1629 static inline variable_def
**
1630 shared_hash_find_slot_1 (shared_hash vars
, decl_or_value dv
, hashval_t dvhash
)
1632 return shared_hash_htab (vars
).find_slot_with_hash (dv
, dvhash
,
1633 shared_hash_shared (vars
)
1634 ? NO_INSERT
: INSERT
);
1637 static inline variable_def
**
1638 shared_hash_find_slot (shared_hash vars
, decl_or_value dv
)
1640 return shared_hash_find_slot_1 (vars
, dv
, dv_htab_hash (dv
));
1643 /* Return slot for DV only if it is already present in the hash table. */
1645 static inline variable_def
**
1646 shared_hash_find_slot_noinsert_1 (shared_hash vars
, decl_or_value dv
,
1649 return shared_hash_htab (vars
).find_slot_with_hash (dv
, dvhash
, NO_INSERT
);
1652 static inline variable_def
**
1653 shared_hash_find_slot_noinsert (shared_hash vars
, decl_or_value dv
)
1655 return shared_hash_find_slot_noinsert_1 (vars
, dv
, dv_htab_hash (dv
));
1658 /* Return variable for DV or NULL if not already present in the hash
1661 static inline variable
1662 shared_hash_find_1 (shared_hash vars
, decl_or_value dv
, hashval_t dvhash
)
1664 return shared_hash_htab (vars
).find_with_hash (dv
, dvhash
);
1667 static inline variable
1668 shared_hash_find (shared_hash vars
, decl_or_value dv
)
1670 return shared_hash_find_1 (vars
, dv
, dv_htab_hash (dv
));
1673 /* Return true if TVAL is better than CVAL as a canonival value. We
1674 choose lowest-numbered VALUEs, using the RTX address as a
1675 tie-breaker. The idea is to arrange them into a star topology,
1676 such that all of them are at most one step away from the canonical
1677 value, and the canonical value has backlinks to all of them, in
1678 addition to all the actual locations. We don't enforce this
1679 topology throughout the entire dataflow analysis, though.
1683 canon_value_cmp (rtx tval
, rtx cval
)
1686 || CSELIB_VAL_PTR (tval
)->uid
< CSELIB_VAL_PTR (cval
)->uid
;
1689 static bool dst_can_be_shared
;
1691 /* Return a copy of a variable VAR and insert it to dataflow set SET. */
1693 static variable_def
**
1694 unshare_variable (dataflow_set
*set
, variable_def
**slot
, variable var
,
1695 enum var_init_status initialized
)
1700 new_var
= (variable
) pool_alloc (onepart_pool (var
->onepart
));
1701 new_var
->dv
= var
->dv
;
1702 new_var
->refcount
= 1;
1704 new_var
->n_var_parts
= var
->n_var_parts
;
1705 new_var
->onepart
= var
->onepart
;
1706 new_var
->in_changed_variables
= false;
1708 if (! flag_var_tracking_uninit
)
1709 initialized
= VAR_INIT_STATUS_INITIALIZED
;
1711 for (i
= 0; i
< var
->n_var_parts
; i
++)
1713 location_chain node
;
1714 location_chain
*nextp
;
1716 if (i
== 0 && var
->onepart
)
1718 /* One-part auxiliary data is only used while emitting
1719 notes, so propagate it to the new variable in the active
1720 dataflow set. If we're not emitting notes, this will be
1722 gcc_checking_assert (!VAR_LOC_1PAUX (var
) || emit_notes
);
1723 VAR_LOC_1PAUX (new_var
) = VAR_LOC_1PAUX (var
);
1724 VAR_LOC_1PAUX (var
) = NULL
;
1727 VAR_PART_OFFSET (new_var
, i
) = VAR_PART_OFFSET (var
, i
);
1728 nextp
= &new_var
->var_part
[i
].loc_chain
;
1729 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1731 location_chain new_lc
;
1733 new_lc
= (location_chain
) pool_alloc (loc_chain_pool
);
1734 new_lc
->next
= NULL
;
1735 if (node
->init
> initialized
)
1736 new_lc
->init
= node
->init
;
1738 new_lc
->init
= initialized
;
1739 if (node
->set_src
&& !(MEM_P (node
->set_src
)))
1740 new_lc
->set_src
= node
->set_src
;
1742 new_lc
->set_src
= NULL
;
1743 new_lc
->loc
= node
->loc
;
1746 nextp
= &new_lc
->next
;
1749 new_var
->var_part
[i
].cur_loc
= var
->var_part
[i
].cur_loc
;
1752 dst_can_be_shared
= false;
1753 if (shared_hash_shared (set
->vars
))
1754 slot
= shared_hash_find_slot_unshare (&set
->vars
, var
->dv
, NO_INSERT
);
1755 else if (set
->traversed_vars
&& set
->vars
!= set
->traversed_vars
)
1756 slot
= shared_hash_find_slot_noinsert (set
->vars
, var
->dv
);
1758 if (var
->in_changed_variables
)
1760 variable_def
**cslot
1761 = changed_variables
.find_slot_with_hash (var
->dv
,
1762 dv_htab_hash (var
->dv
), NO_INSERT
);
1763 gcc_assert (*cslot
== (void *) var
);
1764 var
->in_changed_variables
= false;
1765 variable_htab_free (var
);
1767 new_var
->in_changed_variables
= true;
1772 /* Copy all variables from hash table SRC to hash table DST. */
1775 vars_copy (variable_table_type dst
, variable_table_type src
)
1777 variable_iterator_type hi
;
1780 FOR_EACH_HASH_TABLE_ELEMENT (src
, var
, variable
, hi
)
1782 variable_def
**dstp
;
1784 dstp
= dst
.find_slot_with_hash (var
->dv
, dv_htab_hash (var
->dv
), INSERT
);
1789 /* Map a decl to its main debug decl. */
1792 var_debug_decl (tree decl
)
1794 if (decl
&& TREE_CODE (decl
) == VAR_DECL
1795 && DECL_HAS_DEBUG_EXPR_P (decl
))
1797 tree debugdecl
= DECL_DEBUG_EXPR (decl
);
1798 if (DECL_P (debugdecl
))
1805 /* Set the register LOC to contain DV, OFFSET. */
1808 var_reg_decl_set (dataflow_set
*set
, rtx loc
, enum var_init_status initialized
,
1809 decl_or_value dv
, HOST_WIDE_INT offset
, rtx set_src
,
1810 enum insert_option iopt
)
1813 bool decl_p
= dv_is_decl_p (dv
);
1816 dv
= dv_from_decl (var_debug_decl (dv_as_decl (dv
)));
1818 for (node
= set
->regs
[REGNO (loc
)]; node
; node
= node
->next
)
1819 if (dv_as_opaque (node
->dv
) == dv_as_opaque (dv
)
1820 && node
->offset
== offset
)
1823 attrs_list_insert (&set
->regs
[REGNO (loc
)], dv
, offset
, loc
);
1824 set_variable_part (set
, loc
, dv
, offset
, initialized
, set_src
, iopt
);
1827 /* Set the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). */
1830 var_reg_set (dataflow_set
*set
, rtx loc
, enum var_init_status initialized
,
1833 tree decl
= REG_EXPR (loc
);
1834 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
1836 var_reg_decl_set (set
, loc
, initialized
,
1837 dv_from_decl (decl
), offset
, set_src
, INSERT
);
1840 static enum var_init_status
1841 get_init_value (dataflow_set
*set
, rtx loc
, decl_or_value dv
)
1845 enum var_init_status ret_val
= VAR_INIT_STATUS_UNKNOWN
;
1847 if (! flag_var_tracking_uninit
)
1848 return VAR_INIT_STATUS_INITIALIZED
;
1850 var
= shared_hash_find (set
->vars
, dv
);
1853 for (i
= 0; i
< var
->n_var_parts
&& ret_val
== VAR_INIT_STATUS_UNKNOWN
; i
++)
1855 location_chain nextp
;
1856 for (nextp
= var
->var_part
[i
].loc_chain
; nextp
; nextp
= nextp
->next
)
1857 if (rtx_equal_p (nextp
->loc
, loc
))
1859 ret_val
= nextp
->init
;
1868 /* Delete current content of register LOC in dataflow set SET and set
1869 the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). If
1870 MODIFY is true, any other live copies of the same variable part are
1871 also deleted from the dataflow set, otherwise the variable part is
1872 assumed to be copied from another location holding the same
1876 var_reg_delete_and_set (dataflow_set
*set
, rtx loc
, bool modify
,
1877 enum var_init_status initialized
, rtx set_src
)
1879 tree decl
= REG_EXPR (loc
);
1880 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
1884 decl
= var_debug_decl (decl
);
1886 if (initialized
== VAR_INIT_STATUS_UNKNOWN
)
1887 initialized
= get_init_value (set
, loc
, dv_from_decl (decl
));
1889 nextp
= &set
->regs
[REGNO (loc
)];
1890 for (node
= *nextp
; node
; node
= next
)
1893 if (dv_as_opaque (node
->dv
) != decl
|| node
->offset
!= offset
)
1895 delete_variable_part (set
, node
->loc
, node
->dv
, node
->offset
);
1896 pool_free (attrs_pool
, node
);
1902 nextp
= &node
->next
;
1906 clobber_variable_part (set
, loc
, dv_from_decl (decl
), offset
, set_src
);
1907 var_reg_set (set
, loc
, initialized
, set_src
);
1910 /* Delete the association of register LOC in dataflow set SET with any
1911 variables that aren't onepart. If CLOBBER is true, also delete any
1912 other live copies of the same variable part, and delete the
1913 association with onepart dvs too. */
1916 var_reg_delete (dataflow_set
*set
, rtx loc
, bool clobber
)
1918 attrs
*nextp
= &set
->regs
[REGNO (loc
)];
1923 tree decl
= REG_EXPR (loc
);
1924 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
1926 decl
= var_debug_decl (decl
);
1928 clobber_variable_part (set
, NULL
, dv_from_decl (decl
), offset
, NULL
);
1931 for (node
= *nextp
; node
; node
= next
)
1934 if (clobber
|| !dv_onepart_p (node
->dv
))
1936 delete_variable_part (set
, node
->loc
, node
->dv
, node
->offset
);
1937 pool_free (attrs_pool
, node
);
1941 nextp
= &node
->next
;
1945 /* Delete content of register with number REGNO in dataflow set SET. */
1948 var_regno_delete (dataflow_set
*set
, int regno
)
1950 attrs
*reg
= &set
->regs
[regno
];
1953 for (node
= *reg
; node
; node
= next
)
1956 delete_variable_part (set
, node
->loc
, node
->dv
, node
->offset
);
1957 pool_free (attrs_pool
, node
);
1962 /* Return true if I is the negated value of a power of two. */
1964 negative_power_of_two_p (HOST_WIDE_INT i
)
1966 unsigned HOST_WIDE_INT x
= -(unsigned HOST_WIDE_INT
)i
;
1967 return x
== (x
& -x
);
1970 /* Strip constant offsets and alignments off of LOC. Return the base
1974 vt_get_canonicalize_base (rtx loc
)
1976 while ((GET_CODE (loc
) == PLUS
1977 || GET_CODE (loc
) == AND
)
1978 && GET_CODE (XEXP (loc
, 1)) == CONST_INT
1979 && (GET_CODE (loc
) != AND
1980 || negative_power_of_two_p (INTVAL (XEXP (loc
, 1)))))
1981 loc
= XEXP (loc
, 0);
1986 /* This caches canonicalized addresses for VALUEs, computed using
1987 information in the global cselib table. */
1988 static struct pointer_map_t
*global_get_addr_cache
;
1990 /* This caches canonicalized addresses for VALUEs, computed using
1991 information from the global cache and information pertaining to a
1992 basic block being analyzed. */
1993 static struct pointer_map_t
*local_get_addr_cache
;
1995 static rtx
vt_canonicalize_addr (dataflow_set
*, rtx
);
1997 /* Return the canonical address for LOC, that must be a VALUE, using a
1998 cached global equivalence or computing it and storing it in the
2002 get_addr_from_global_cache (rtx
const loc
)
2007 gcc_checking_assert (GET_CODE (loc
) == VALUE
);
2009 slot
= pointer_map_insert (global_get_addr_cache
, loc
);
2013 x
= canon_rtx (get_addr (loc
));
2015 /* Tentative, avoiding infinite recursion. */
2020 rtx nx
= vt_canonicalize_addr (NULL
, x
);
2023 /* The table may have moved during recursion, recompute
2025 slot
= pointer_map_contains (global_get_addr_cache
, loc
);
2033 /* Return the canonical address for LOC, that must be a VALUE, using a
2034 cached local equivalence or computing it and storing it in the
2038 get_addr_from_local_cache (dataflow_set
*set
, rtx
const loc
)
2046 gcc_checking_assert (GET_CODE (loc
) == VALUE
);
2048 slot
= pointer_map_insert (local_get_addr_cache
, loc
);
2052 x
= get_addr_from_global_cache (loc
);
2054 /* Tentative, avoiding infinite recursion. */
2057 /* Recurse to cache local expansion of X, or if we need to search
2058 for a VALUE in the expansion. */
2061 rtx nx
= vt_canonicalize_addr (set
, x
);
2064 slot
= pointer_map_contains (local_get_addr_cache
, loc
);
2070 dv
= dv_from_rtx (x
);
2071 var
= shared_hash_find (set
->vars
, dv
);
2075 /* Look for an improved equivalent expression. */
2076 for (l
= var
->var_part
[0].loc_chain
; l
; l
= l
->next
)
2078 rtx base
= vt_get_canonicalize_base (l
->loc
);
2079 if (GET_CODE (base
) == VALUE
2080 && canon_value_cmp (base
, loc
))
2082 rtx nx
= vt_canonicalize_addr (set
, l
->loc
);
2085 slot
= pointer_map_contains (local_get_addr_cache
, loc
);
2095 /* Canonicalize LOC using equivalences from SET in addition to those
2096 in the cselib static table. It expects a VALUE-based expression,
2097 and it will only substitute VALUEs with other VALUEs or
2098 function-global equivalences, so that, if two addresses have base
2099 VALUEs that are locally or globally related in ways that
2100 memrefs_conflict_p cares about, they will both canonicalize to
2101 expressions that have the same base VALUE.
2103 The use of VALUEs as canonical base addresses enables the canonical
2104 RTXs to remain unchanged globally, if they resolve to a constant,
2105 or throughout a basic block otherwise, so that they can be cached
2106 and the cache needs not be invalidated when REGs, MEMs or such
2110 vt_canonicalize_addr (dataflow_set
*set
, rtx oloc
)
2112 HOST_WIDE_INT ofst
= 0;
2113 enum machine_mode mode
= GET_MODE (oloc
);
2120 while (GET_CODE (loc
) == PLUS
2121 && GET_CODE (XEXP (loc
, 1)) == CONST_INT
)
2123 ofst
+= INTVAL (XEXP (loc
, 1));
2124 loc
= XEXP (loc
, 0);
2127 /* Alignment operations can't normally be combined, so just
2128 canonicalize the base and we're done. We'll normally have
2129 only one stack alignment anyway. */
2130 if (GET_CODE (loc
) == AND
2131 && GET_CODE (XEXP (loc
, 1)) == CONST_INT
2132 && negative_power_of_two_p (INTVAL (XEXP (loc
, 1))))
2134 x
= vt_canonicalize_addr (set
, XEXP (loc
, 0));
2135 if (x
!= XEXP (loc
, 0))
2136 loc
= gen_rtx_AND (mode
, x
, XEXP (loc
, 1));
2140 if (GET_CODE (loc
) == VALUE
)
2143 loc
= get_addr_from_local_cache (set
, loc
);
2145 loc
= get_addr_from_global_cache (loc
);
2147 /* Consolidate plus_constants. */
2148 while (ofst
&& GET_CODE (loc
) == PLUS
2149 && GET_CODE (XEXP (loc
, 1)) == CONST_INT
)
2151 ofst
+= INTVAL (XEXP (loc
, 1));
2152 loc
= XEXP (loc
, 0);
2159 x
= canon_rtx (loc
);
2166 /* Add OFST back in. */
2169 /* Don't build new RTL if we can help it. */
2170 if (GET_CODE (oloc
) == PLUS
2171 && XEXP (oloc
, 0) == loc
2172 && INTVAL (XEXP (oloc
, 1)) == ofst
)
2175 loc
= plus_constant (mode
, loc
, ofst
);
2181 /* Return true iff there's a true dependence between MLOC and LOC.
2182 MADDR must be a canonicalized version of MLOC's address. */
2185 vt_canon_true_dep (dataflow_set
*set
, rtx mloc
, rtx maddr
, rtx loc
)
2187 if (GET_CODE (loc
) != MEM
)
2190 rtx addr
= vt_canonicalize_addr (set
, XEXP (loc
, 0));
2191 if (!canon_true_dependence (mloc
, GET_MODE (mloc
), maddr
, loc
, addr
))
2197 /* Hold parameters for the hashtab traversal function
2198 drop_overlapping_mem_locs, see below. */
2200 struct overlapping_mems
2206 /* Remove all MEMs that overlap with COMS->LOC from the location list
2207 of a hash table entry for a value. COMS->ADDR must be a
2208 canonicalized form of COMS->LOC's address, and COMS->LOC must be
2209 canonicalized itself. */
2212 drop_overlapping_mem_locs (variable_def
**slot
, overlapping_mems
*coms
)
2214 dataflow_set
*set
= coms
->set
;
2215 rtx mloc
= coms
->loc
, addr
= coms
->addr
;
2216 variable var
= *slot
;
2218 if (var
->onepart
== ONEPART_VALUE
)
2220 location_chain loc
, *locp
;
2221 bool changed
= false;
2224 gcc_assert (var
->n_var_parts
== 1);
2226 if (shared_var_p (var
, set
->vars
))
2228 for (loc
= var
->var_part
[0].loc_chain
; loc
; loc
= loc
->next
)
2229 if (vt_canon_true_dep (set
, mloc
, addr
, loc
->loc
))
2235 slot
= unshare_variable (set
, slot
, var
, VAR_INIT_STATUS_UNKNOWN
);
2237 gcc_assert (var
->n_var_parts
== 1);
2240 if (VAR_LOC_1PAUX (var
))
2241 cur_loc
= VAR_LOC_FROM (var
);
2243 cur_loc
= var
->var_part
[0].cur_loc
;
2245 for (locp
= &var
->var_part
[0].loc_chain
, loc
= *locp
;
2248 if (!vt_canon_true_dep (set
, mloc
, addr
, loc
->loc
))
2255 /* If we have deleted the location which was last emitted
2256 we have to emit new location so add the variable to set
2257 of changed variables. */
2258 if (cur_loc
== loc
->loc
)
2261 var
->var_part
[0].cur_loc
= NULL
;
2262 if (VAR_LOC_1PAUX (var
))
2263 VAR_LOC_FROM (var
) = NULL
;
2265 pool_free (loc_chain_pool
, loc
);
2268 if (!var
->var_part
[0].loc_chain
)
2274 variable_was_changed (var
, set
);
2280 /* Remove from SET all VALUE bindings to MEMs that overlap with LOC. */
2283 clobber_overlapping_mems (dataflow_set
*set
, rtx loc
)
2285 struct overlapping_mems coms
;
2287 gcc_checking_assert (GET_CODE (loc
) == MEM
);
2290 coms
.loc
= canon_rtx (loc
);
2291 coms
.addr
= vt_canonicalize_addr (set
, XEXP (loc
, 0));
2293 set
->traversed_vars
= set
->vars
;
2294 shared_hash_htab (set
->vars
)
2295 .traverse
<overlapping_mems
*, drop_overlapping_mem_locs
> (&coms
);
2296 set
->traversed_vars
= NULL
;
2299 /* Set the location of DV, OFFSET as the MEM LOC. */
2302 var_mem_decl_set (dataflow_set
*set
, rtx loc
, enum var_init_status initialized
,
2303 decl_or_value dv
, HOST_WIDE_INT offset
, rtx set_src
,
2304 enum insert_option iopt
)
2306 if (dv_is_decl_p (dv
))
2307 dv
= dv_from_decl (var_debug_decl (dv_as_decl (dv
)));
2309 set_variable_part (set
, loc
, dv
, offset
, initialized
, set_src
, iopt
);
2312 /* Set the location part of variable MEM_EXPR (LOC) in dataflow set
2314 Adjust the address first if it is stack pointer based. */
2317 var_mem_set (dataflow_set
*set
, rtx loc
, enum var_init_status initialized
,
2320 tree decl
= MEM_EXPR (loc
);
2321 HOST_WIDE_INT offset
= INT_MEM_OFFSET (loc
);
2323 var_mem_decl_set (set
, loc
, initialized
,
2324 dv_from_decl (decl
), offset
, set_src
, INSERT
);
2327 /* Delete and set the location part of variable MEM_EXPR (LOC) in
2328 dataflow set SET to LOC. If MODIFY is true, any other live copies
2329 of the same variable part are also deleted from the dataflow set,
2330 otherwise the variable part is assumed to be copied from another
2331 location holding the same part.
2332 Adjust the address first if it is stack pointer based. */
2335 var_mem_delete_and_set (dataflow_set
*set
, rtx loc
, bool modify
,
2336 enum var_init_status initialized
, rtx set_src
)
2338 tree decl
= MEM_EXPR (loc
);
2339 HOST_WIDE_INT offset
= INT_MEM_OFFSET (loc
);
2341 clobber_overlapping_mems (set
, loc
);
2342 decl
= var_debug_decl (decl
);
2344 if (initialized
== VAR_INIT_STATUS_UNKNOWN
)
2345 initialized
= get_init_value (set
, loc
, dv_from_decl (decl
));
2348 clobber_variable_part (set
, NULL
, dv_from_decl (decl
), offset
, set_src
);
2349 var_mem_set (set
, loc
, initialized
, set_src
);
2352 /* Delete the location part LOC from dataflow set SET. If CLOBBER is
2353 true, also delete any other live copies of the same variable part.
2354 Adjust the address first if it is stack pointer based. */
2357 var_mem_delete (dataflow_set
*set
, rtx loc
, bool clobber
)
2359 tree decl
= MEM_EXPR (loc
);
2360 HOST_WIDE_INT offset
= INT_MEM_OFFSET (loc
);
2362 clobber_overlapping_mems (set
, loc
);
2363 decl
= var_debug_decl (decl
);
2365 clobber_variable_part (set
, NULL
, dv_from_decl (decl
), offset
, NULL
);
2366 delete_variable_part (set
, loc
, dv_from_decl (decl
), offset
);
2369 /* Return true if LOC should not be expanded for location expressions,
2373 unsuitable_loc (rtx loc
)
2375 switch (GET_CODE (loc
))
2389 /* Bind VAL to LOC in SET. If MODIFIED, detach LOC from any values
2393 val_bind (dataflow_set
*set
, rtx val
, rtx loc
, bool modified
)
2398 var_regno_delete (set
, REGNO (loc
));
2399 var_reg_decl_set (set
, loc
, VAR_INIT_STATUS_INITIALIZED
,
2400 dv_from_value (val
), 0, NULL_RTX
, INSERT
);
2402 else if (MEM_P (loc
))
2404 struct elt_loc_list
*l
= CSELIB_VAL_PTR (val
)->locs
;
2407 clobber_overlapping_mems (set
, loc
);
2409 if (l
&& GET_CODE (l
->loc
) == VALUE
)
2410 l
= canonical_cselib_val (CSELIB_VAL_PTR (l
->loc
))->locs
;
2412 /* If this MEM is a global constant, we don't need it in the
2413 dynamic tables. ??? We should test this before emitting the
2414 micro-op in the first place. */
2416 if (GET_CODE (l
->loc
) == MEM
&& XEXP (l
->loc
, 0) == XEXP (loc
, 0))
2422 var_mem_decl_set (set
, loc
, VAR_INIT_STATUS_INITIALIZED
,
2423 dv_from_value (val
), 0, NULL_RTX
, INSERT
);
2427 /* Other kinds of equivalences are necessarily static, at least
2428 so long as we do not perform substitutions while merging
2431 set_variable_part (set
, loc
, dv_from_value (val
), 0,
2432 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
, INSERT
);
2436 /* Bind a value to a location it was just stored in. If MODIFIED
2437 holds, assume the location was modified, detaching it from any
2438 values bound to it. */
2441 val_store (dataflow_set
*set
, rtx val
, rtx loc
, rtx insn
, bool modified
)
2443 cselib_val
*v
= CSELIB_VAL_PTR (val
);
2445 gcc_assert (cselib_preserved_value_p (v
));
2449 fprintf (dump_file
, "%i: ", insn
? INSN_UID (insn
) : 0);
2450 print_inline_rtx (dump_file
, loc
, 0);
2451 fprintf (dump_file
, " evaluates to ");
2452 print_inline_rtx (dump_file
, val
, 0);
2455 struct elt_loc_list
*l
;
2456 for (l
= v
->locs
; l
; l
= l
->next
)
2458 fprintf (dump_file
, "\n%i: ", INSN_UID (l
->setting_insn
));
2459 print_inline_rtx (dump_file
, l
->loc
, 0);
2462 fprintf (dump_file
, "\n");
2465 gcc_checking_assert (!unsuitable_loc (loc
));
2467 val_bind (set
, val
, loc
, modified
);
2470 /* Clear (canonical address) slots that reference X. */
2473 local_get_addr_clear_given_value (const void *v ATTRIBUTE_UNUSED
,
2474 void **slot
, void *x
)
2476 if (vt_get_canonicalize_base ((rtx
)*slot
) == x
)
2481 /* Reset this node, detaching all its equivalences. Return the slot
2482 in the variable hash table that holds dv, if there is one. */
2485 val_reset (dataflow_set
*set
, decl_or_value dv
)
2487 variable var
= shared_hash_find (set
->vars
, dv
) ;
2488 location_chain node
;
2491 if (!var
|| !var
->n_var_parts
)
2494 gcc_assert (var
->n_var_parts
== 1);
2496 if (var
->onepart
== ONEPART_VALUE
)
2498 rtx x
= dv_as_value (dv
);
2501 /* Relationships in the global cache don't change, so reset the
2502 local cache entry only. */
2503 slot
= pointer_map_contains (local_get_addr_cache
, x
);
2506 /* If the value resolved back to itself, odds are that other
2507 values may have cached it too. These entries now refer
2508 to the old X, so detach them too. Entries that used the
2509 old X but resolved to something else remain ok as long as
2510 that something else isn't also reset. */
2512 pointer_map_traverse (local_get_addr_cache
,
2513 local_get_addr_clear_given_value
, x
);
2519 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
2520 if (GET_CODE (node
->loc
) == VALUE
2521 && canon_value_cmp (node
->loc
, cval
))
2524 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
2525 if (GET_CODE (node
->loc
) == VALUE
&& cval
!= node
->loc
)
2527 /* Redirect the equivalence link to the new canonical
2528 value, or simply remove it if it would point at
2531 set_variable_part (set
, cval
, dv_from_value (node
->loc
),
2532 0, node
->init
, node
->set_src
, NO_INSERT
);
2533 delete_variable_part (set
, dv_as_value (dv
),
2534 dv_from_value (node
->loc
), 0);
2539 decl_or_value cdv
= dv_from_value (cval
);
2541 /* Keep the remaining values connected, accummulating links
2542 in the canonical value. */
2543 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
2545 if (node
->loc
== cval
)
2547 else if (GET_CODE (node
->loc
) == REG
)
2548 var_reg_decl_set (set
, node
->loc
, node
->init
, cdv
, 0,
2549 node
->set_src
, NO_INSERT
);
2550 else if (GET_CODE (node
->loc
) == MEM
)
2551 var_mem_decl_set (set
, node
->loc
, node
->init
, cdv
, 0,
2552 node
->set_src
, NO_INSERT
);
2554 set_variable_part (set
, node
->loc
, cdv
, 0,
2555 node
->init
, node
->set_src
, NO_INSERT
);
2559 /* We remove this last, to make sure that the canonical value is not
2560 removed to the point of requiring reinsertion. */
2562 delete_variable_part (set
, dv_as_value (dv
), dv_from_value (cval
), 0);
2564 clobber_variable_part (set
, NULL
, dv
, 0, NULL
);
2567 /* Find the values in a given location and map the val to another
2568 value, if it is unique, or add the location as one holding the
2572 val_resolve (dataflow_set
*set
, rtx val
, rtx loc
, rtx insn
)
2574 decl_or_value dv
= dv_from_value (val
);
2576 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2579 fprintf (dump_file
, "%i: ", INSN_UID (insn
));
2581 fprintf (dump_file
, "head: ");
2582 print_inline_rtx (dump_file
, val
, 0);
2583 fputs (" is at ", dump_file
);
2584 print_inline_rtx (dump_file
, loc
, 0);
2585 fputc ('\n', dump_file
);
2588 val_reset (set
, dv
);
2590 gcc_checking_assert (!unsuitable_loc (loc
));
2594 attrs node
, found
= NULL
;
2596 for (node
= set
->regs
[REGNO (loc
)]; node
; node
= node
->next
)
2597 if (dv_is_value_p (node
->dv
)
2598 && GET_MODE (dv_as_value (node
->dv
)) == GET_MODE (loc
))
2602 /* Map incoming equivalences. ??? Wouldn't it be nice if
2603 we just started sharing the location lists? Maybe a
2604 circular list ending at the value itself or some
2606 set_variable_part (set
, dv_as_value (node
->dv
),
2607 dv_from_value (val
), node
->offset
,
2608 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
, INSERT
);
2609 set_variable_part (set
, val
, node
->dv
, node
->offset
,
2610 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
, INSERT
);
2613 /* If we didn't find any equivalence, we need to remember that
2614 this value is held in the named register. */
2618 /* ??? Attempt to find and merge equivalent MEMs or other
2621 val_bind (set
, val
, loc
, false);
2624 /* Initialize dataflow set SET to be empty.
2625 VARS_SIZE is the initial size of hash table VARS. */
2628 dataflow_set_init (dataflow_set
*set
)
2630 init_attrs_list_set (set
->regs
);
2631 set
->vars
= shared_hash_copy (empty_shared_hash
);
2632 set
->stack_adjust
= 0;
2633 set
->traversed_vars
= NULL
;
2636 /* Delete the contents of dataflow set SET. */
2639 dataflow_set_clear (dataflow_set
*set
)
2643 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2644 attrs_list_clear (&set
->regs
[i
]);
2646 shared_hash_destroy (set
->vars
);
2647 set
->vars
= shared_hash_copy (empty_shared_hash
);
2650 /* Copy the contents of dataflow set SRC to DST. */
2653 dataflow_set_copy (dataflow_set
*dst
, dataflow_set
*src
)
2657 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2658 attrs_list_copy (&dst
->regs
[i
], src
->regs
[i
]);
2660 shared_hash_destroy (dst
->vars
);
2661 dst
->vars
= shared_hash_copy (src
->vars
);
2662 dst
->stack_adjust
= src
->stack_adjust
;
2665 /* Information for merging lists of locations for a given offset of variable.
2667 struct variable_union_info
2669 /* Node of the location chain. */
2672 /* The sum of positions in the input chains. */
2675 /* The position in the chain of DST dataflow set. */
2679 /* Buffer for location list sorting and its allocated size. */
2680 static struct variable_union_info
*vui_vec
;
2681 static int vui_allocated
;
2683 /* Compare function for qsort, order the structures by POS element. */
2686 variable_union_info_cmp_pos (const void *n1
, const void *n2
)
2688 const struct variable_union_info
*const i1
=
2689 (const struct variable_union_info
*) n1
;
2690 const struct variable_union_info
*const i2
=
2691 ( const struct variable_union_info
*) n2
;
2693 if (i1
->pos
!= i2
->pos
)
2694 return i1
->pos
- i2
->pos
;
2696 return (i1
->pos_dst
- i2
->pos_dst
);
2699 /* Compute union of location parts of variable *SLOT and the same variable
2700 from hash table DATA. Compute "sorted" union of the location chains
2701 for common offsets, i.e. the locations of a variable part are sorted by
2702 a priority where the priority is the sum of the positions in the 2 chains
2703 (if a location is only in one list the position in the second list is
2704 defined to be larger than the length of the chains).
2705 When we are updating the location parts the newest location is in the
2706 beginning of the chain, so when we do the described "sorted" union
2707 we keep the newest locations in the beginning. */
2710 variable_union (variable src
, dataflow_set
*set
)
2713 variable_def
**dstp
;
2716 dstp
= shared_hash_find_slot (set
->vars
, src
->dv
);
2717 if (!dstp
|| !*dstp
)
2721 dst_can_be_shared
= false;
2723 dstp
= shared_hash_find_slot_unshare (&set
->vars
, src
->dv
, INSERT
);
2727 /* Continue traversing the hash table. */
2733 gcc_assert (src
->n_var_parts
);
2734 gcc_checking_assert (src
->onepart
== dst
->onepart
);
2736 /* We can combine one-part variables very efficiently, because their
2737 entries are in canonical order. */
2740 location_chain
*nodep
, dnode
, snode
;
2742 gcc_assert (src
->n_var_parts
== 1
2743 && dst
->n_var_parts
== 1);
2745 snode
= src
->var_part
[0].loc_chain
;
2748 restart_onepart_unshared
:
2749 nodep
= &dst
->var_part
[0].loc_chain
;
2755 int r
= dnode
? loc_cmp (dnode
->loc
, snode
->loc
) : 1;
2759 location_chain nnode
;
2761 if (shared_var_p (dst
, set
->vars
))
2763 dstp
= unshare_variable (set
, dstp
, dst
,
2764 VAR_INIT_STATUS_INITIALIZED
);
2766 goto restart_onepart_unshared
;
2769 *nodep
= nnode
= (location_chain
) pool_alloc (loc_chain_pool
);
2770 nnode
->loc
= snode
->loc
;
2771 nnode
->init
= snode
->init
;
2772 if (!snode
->set_src
|| MEM_P (snode
->set_src
))
2773 nnode
->set_src
= NULL
;
2775 nnode
->set_src
= snode
->set_src
;
2776 nnode
->next
= dnode
;
2780 gcc_checking_assert (rtx_equal_p (dnode
->loc
, snode
->loc
));
2783 snode
= snode
->next
;
2785 nodep
= &dnode
->next
;
2792 gcc_checking_assert (!src
->onepart
);
2794 /* Count the number of location parts, result is K. */
2795 for (i
= 0, j
= 0, k
= 0;
2796 i
< src
->n_var_parts
&& j
< dst
->n_var_parts
; k
++)
2798 if (VAR_PART_OFFSET (src
, i
) == VAR_PART_OFFSET (dst
, j
))
2803 else if (VAR_PART_OFFSET (src
, i
) < VAR_PART_OFFSET (dst
, j
))
2808 k
+= src
->n_var_parts
- i
;
2809 k
+= dst
->n_var_parts
- j
;
2811 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
2812 thus there are at most MAX_VAR_PARTS different offsets. */
2813 gcc_checking_assert (dst
->onepart
? k
== 1 : k
<= MAX_VAR_PARTS
);
2815 if (dst
->n_var_parts
!= k
&& shared_var_p (dst
, set
->vars
))
2817 dstp
= unshare_variable (set
, dstp
, dst
, VAR_INIT_STATUS_UNKNOWN
);
2821 i
= src
->n_var_parts
- 1;
2822 j
= dst
->n_var_parts
- 1;
2823 dst
->n_var_parts
= k
;
2825 for (k
--; k
>= 0; k
--)
2827 location_chain node
, node2
;
2829 if (i
>= 0 && j
>= 0
2830 && VAR_PART_OFFSET (src
, i
) == VAR_PART_OFFSET (dst
, j
))
2832 /* Compute the "sorted" union of the chains, i.e. the locations which
2833 are in both chains go first, they are sorted by the sum of
2834 positions in the chains. */
2837 struct variable_union_info
*vui
;
2839 /* If DST is shared compare the location chains.
2840 If they are different we will modify the chain in DST with
2841 high probability so make a copy of DST. */
2842 if (shared_var_p (dst
, set
->vars
))
2844 for (node
= src
->var_part
[i
].loc_chain
,
2845 node2
= dst
->var_part
[j
].loc_chain
; node
&& node2
;
2846 node
= node
->next
, node2
= node2
->next
)
2848 if (!((REG_P (node2
->loc
)
2849 && REG_P (node
->loc
)
2850 && REGNO (node2
->loc
) == REGNO (node
->loc
))
2851 || rtx_equal_p (node2
->loc
, node
->loc
)))
2853 if (node2
->init
< node
->init
)
2854 node2
->init
= node
->init
;
2860 dstp
= unshare_variable (set
, dstp
, dst
,
2861 VAR_INIT_STATUS_UNKNOWN
);
2862 dst
= (variable
)*dstp
;
2867 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
2870 for (node
= dst
->var_part
[j
].loc_chain
; node
; node
= node
->next
)
2875 /* The most common case, much simpler, no qsort is needed. */
2876 location_chain dstnode
= dst
->var_part
[j
].loc_chain
;
2877 dst
->var_part
[k
].loc_chain
= dstnode
;
2878 VAR_PART_OFFSET (dst
, k
) = VAR_PART_OFFSET(dst
, j
);
2880 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
2881 if (!((REG_P (dstnode
->loc
)
2882 && REG_P (node
->loc
)
2883 && REGNO (dstnode
->loc
) == REGNO (node
->loc
))
2884 || rtx_equal_p (dstnode
->loc
, node
->loc
)))
2886 location_chain new_node
;
2888 /* Copy the location from SRC. */
2889 new_node
= (location_chain
) pool_alloc (loc_chain_pool
);
2890 new_node
->loc
= node
->loc
;
2891 new_node
->init
= node
->init
;
2892 if (!node
->set_src
|| MEM_P (node
->set_src
))
2893 new_node
->set_src
= NULL
;
2895 new_node
->set_src
= node
->set_src
;
2896 node2
->next
= new_node
;
2903 if (src_l
+ dst_l
> vui_allocated
)
2905 vui_allocated
= MAX (vui_allocated
* 2, src_l
+ dst_l
);
2906 vui_vec
= XRESIZEVEC (struct variable_union_info
, vui_vec
,
2911 /* Fill in the locations from DST. */
2912 for (node
= dst
->var_part
[j
].loc_chain
, jj
= 0; node
;
2913 node
= node
->next
, jj
++)
2916 vui
[jj
].pos_dst
= jj
;
2918 /* Pos plus value larger than a sum of 2 valid positions. */
2919 vui
[jj
].pos
= jj
+ src_l
+ dst_l
;
2922 /* Fill in the locations from SRC. */
2924 for (node
= src
->var_part
[i
].loc_chain
, ii
= 0; node
;
2925 node
= node
->next
, ii
++)
2927 /* Find location from NODE. */
2928 for (jj
= 0; jj
< dst_l
; jj
++)
2930 if ((REG_P (vui
[jj
].lc
->loc
)
2931 && REG_P (node
->loc
)
2932 && REGNO (vui
[jj
].lc
->loc
) == REGNO (node
->loc
))
2933 || rtx_equal_p (vui
[jj
].lc
->loc
, node
->loc
))
2935 vui
[jj
].pos
= jj
+ ii
;
2939 if (jj
>= dst_l
) /* The location has not been found. */
2941 location_chain new_node
;
2943 /* Copy the location from SRC. */
2944 new_node
= (location_chain
) pool_alloc (loc_chain_pool
);
2945 new_node
->loc
= node
->loc
;
2946 new_node
->init
= node
->init
;
2947 if (!node
->set_src
|| MEM_P (node
->set_src
))
2948 new_node
->set_src
= NULL
;
2950 new_node
->set_src
= node
->set_src
;
2951 vui
[n
].lc
= new_node
;
2952 vui
[n
].pos_dst
= src_l
+ dst_l
;
2953 vui
[n
].pos
= ii
+ src_l
+ dst_l
;
2960 /* Special case still very common case. For dst_l == 2
2961 all entries dst_l ... n-1 are sorted, with for i >= dst_l
2962 vui[i].pos == i + src_l + dst_l. */
2963 if (vui
[0].pos
> vui
[1].pos
)
2965 /* Order should be 1, 0, 2... */
2966 dst
->var_part
[k
].loc_chain
= vui
[1].lc
;
2967 vui
[1].lc
->next
= vui
[0].lc
;
2970 vui
[0].lc
->next
= vui
[2].lc
;
2971 vui
[n
- 1].lc
->next
= NULL
;
2974 vui
[0].lc
->next
= NULL
;
2979 dst
->var_part
[k
].loc_chain
= vui
[0].lc
;
2980 if (n
>= 3 && vui
[2].pos
< vui
[1].pos
)
2982 /* Order should be 0, 2, 1, 3... */
2983 vui
[0].lc
->next
= vui
[2].lc
;
2984 vui
[2].lc
->next
= vui
[1].lc
;
2987 vui
[1].lc
->next
= vui
[3].lc
;
2988 vui
[n
- 1].lc
->next
= NULL
;
2991 vui
[1].lc
->next
= NULL
;
2996 /* Order should be 0, 1, 2... */
2998 vui
[n
- 1].lc
->next
= NULL
;
3001 for (; ii
< n
; ii
++)
3002 vui
[ii
- 1].lc
->next
= vui
[ii
].lc
;
3006 qsort (vui
, n
, sizeof (struct variable_union_info
),
3007 variable_union_info_cmp_pos
);
3009 /* Reconnect the nodes in sorted order. */
3010 for (ii
= 1; ii
< n
; ii
++)
3011 vui
[ii
- 1].lc
->next
= vui
[ii
].lc
;
3012 vui
[n
- 1].lc
->next
= NULL
;
3013 dst
->var_part
[k
].loc_chain
= vui
[0].lc
;
3016 VAR_PART_OFFSET (dst
, k
) = VAR_PART_OFFSET (dst
, j
);
3021 else if ((i
>= 0 && j
>= 0
3022 && VAR_PART_OFFSET (src
, i
) < VAR_PART_OFFSET (dst
, j
))
3025 dst
->var_part
[k
] = dst
->var_part
[j
];
3028 else if ((i
>= 0 && j
>= 0
3029 && VAR_PART_OFFSET (src
, i
) > VAR_PART_OFFSET (dst
, j
))
3032 location_chain
*nextp
;
3034 /* Copy the chain from SRC. */
3035 nextp
= &dst
->var_part
[k
].loc_chain
;
3036 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
3038 location_chain new_lc
;
3040 new_lc
= (location_chain
) pool_alloc (loc_chain_pool
);
3041 new_lc
->next
= NULL
;
3042 new_lc
->init
= node
->init
;
3043 if (!node
->set_src
|| MEM_P (node
->set_src
))
3044 new_lc
->set_src
= NULL
;
3046 new_lc
->set_src
= node
->set_src
;
3047 new_lc
->loc
= node
->loc
;
3050 nextp
= &new_lc
->next
;
3053 VAR_PART_OFFSET (dst
, k
) = VAR_PART_OFFSET (src
, i
);
3056 dst
->var_part
[k
].cur_loc
= NULL
;
3059 if (flag_var_tracking_uninit
)
3060 for (i
= 0; i
< src
->n_var_parts
&& i
< dst
->n_var_parts
; i
++)
3062 location_chain node
, node2
;
3063 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
3064 for (node2
= dst
->var_part
[i
].loc_chain
; node2
; node2
= node2
->next
)
3065 if (rtx_equal_p (node
->loc
, node2
->loc
))
3067 if (node
->init
> node2
->init
)
3068 node2
->init
= node
->init
;
3072 /* Continue traversing the hash table. */
3076 /* Compute union of dataflow sets SRC and DST and store it to DST. */
3079 dataflow_set_union (dataflow_set
*dst
, dataflow_set
*src
)
3083 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3084 attrs_list_union (&dst
->regs
[i
], src
->regs
[i
]);
3086 if (dst
->vars
== empty_shared_hash
)
3088 shared_hash_destroy (dst
->vars
);
3089 dst
->vars
= shared_hash_copy (src
->vars
);
3093 variable_iterator_type hi
;
3096 FOR_EACH_HASH_TABLE_ELEMENT (shared_hash_htab (src
->vars
),
3098 variable_union (var
, dst
);
3102 /* Whether the value is currently being expanded. */
3103 #define VALUE_RECURSED_INTO(x) \
3104 (RTL_FLAG_CHECK2 ("VALUE_RECURSED_INTO", (x), VALUE, DEBUG_EXPR)->used)
3106 /* Whether no expansion was found, saving useless lookups.
3107 It must only be set when VALUE_CHANGED is clear. */
3108 #define NO_LOC_P(x) \
3109 (RTL_FLAG_CHECK2 ("NO_LOC_P", (x), VALUE, DEBUG_EXPR)->return_val)
3111 /* Whether cur_loc in the value needs to be (re)computed. */
3112 #define VALUE_CHANGED(x) \
3113 (RTL_FLAG_CHECK1 ("VALUE_CHANGED", (x), VALUE)->frame_related)
3114 /* Whether cur_loc in the decl needs to be (re)computed. */
3115 #define DECL_CHANGED(x) TREE_VISITED (x)
3117 /* Record (if NEWV) that DV needs to have its cur_loc recomputed. For
3118 user DECLs, this means they're in changed_variables. Values and
3119 debug exprs may be left with this flag set if no user variable
3120 requires them to be evaluated. */
3123 set_dv_changed (decl_or_value dv
, bool newv
)
3125 switch (dv_onepart_p (dv
))
3129 NO_LOC_P (dv_as_value (dv
)) = false;
3130 VALUE_CHANGED (dv_as_value (dv
)) = newv
;
3135 NO_LOC_P (DECL_RTL_KNOWN_SET (dv_as_decl (dv
))) = false;
3136 /* Fall through... */
3139 DECL_CHANGED (dv_as_decl (dv
)) = newv
;
3144 /* Return true if DV needs to have its cur_loc recomputed. */
3147 dv_changed_p (decl_or_value dv
)
3149 return (dv_is_value_p (dv
)
3150 ? VALUE_CHANGED (dv_as_value (dv
))
3151 : DECL_CHANGED (dv_as_decl (dv
)));
3154 /* Return a location list node whose loc is rtx_equal to LOC, in the
3155 location list of a one-part variable or value VAR, or in that of
3156 any values recursively mentioned in the location lists. VARS must
3157 be in star-canonical form. */
3159 static location_chain
3160 find_loc_in_1pdv (rtx loc
, variable var
, variable_table_type vars
)
3162 location_chain node
;
3163 enum rtx_code loc_code
;
3168 gcc_checking_assert (var
->onepart
);
3170 if (!var
->n_var_parts
)
3173 gcc_checking_assert (loc
!= dv_as_opaque (var
->dv
));
3175 loc_code
= GET_CODE (loc
);
3176 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
3181 if (GET_CODE (node
->loc
) != loc_code
)
3183 if (GET_CODE (node
->loc
) != VALUE
)
3186 else if (loc
== node
->loc
)
3188 else if (loc_code
!= VALUE
)
3190 if (rtx_equal_p (loc
, node
->loc
))
3195 /* Since we're in star-canonical form, we don't need to visit
3196 non-canonical nodes: one-part variables and non-canonical
3197 values would only point back to the canonical node. */
3198 if (dv_is_value_p (var
->dv
)
3199 && !canon_value_cmp (node
->loc
, dv_as_value (var
->dv
)))
3201 /* Skip all subsequent VALUEs. */
3202 while (node
->next
&& GET_CODE (node
->next
->loc
) == VALUE
)
3205 gcc_checking_assert (!canon_value_cmp (node
->loc
,
3206 dv_as_value (var
->dv
)));
3207 if (loc
== node
->loc
)
3213 gcc_checking_assert (node
== var
->var_part
[0].loc_chain
);
3214 gcc_checking_assert (!node
->next
);
3216 dv
= dv_from_value (node
->loc
);
3217 rvar
= vars
.find_with_hash (dv
, dv_htab_hash (dv
));
3218 return find_loc_in_1pdv (loc
, rvar
, vars
);
3221 /* ??? Gotta look in cselib_val locations too. */
3226 /* Hash table iteration argument passed to variable_merge. */
3229 /* The set in which the merge is to be inserted. */
3231 /* The set that we're iterating in. */
3233 /* The set that may contain the other dv we are to merge with. */
3235 /* Number of onepart dvs in src. */
3236 int src_onepart_cnt
;
3239 /* Insert LOC in *DNODE, if it's not there yet. The list must be in
3240 loc_cmp order, and it is maintained as such. */
3243 insert_into_intersection (location_chain
*nodep
, rtx loc
,
3244 enum var_init_status status
)
3246 location_chain node
;
3249 for (node
= *nodep
; node
; nodep
= &node
->next
, node
= *nodep
)
3250 if ((r
= loc_cmp (node
->loc
, loc
)) == 0)
3252 node
->init
= MIN (node
->init
, status
);
3258 node
= (location_chain
) pool_alloc (loc_chain_pool
);
3261 node
->set_src
= NULL
;
3262 node
->init
= status
;
3263 node
->next
= *nodep
;
3267 /* Insert in DEST the intersection of the locations present in both
3268 S1NODE and S2VAR, directly or indirectly. S1NODE is from a
3269 variable in DSM->cur, whereas S2VAR is from DSM->src. dvar is in
3273 intersect_loc_chains (rtx val
, location_chain
*dest
, struct dfset_merge
*dsm
,
3274 location_chain s1node
, variable s2var
)
3276 dataflow_set
*s1set
= dsm
->cur
;
3277 dataflow_set
*s2set
= dsm
->src
;
3278 location_chain found
;
3282 location_chain s2node
;
3284 gcc_checking_assert (s2var
->onepart
);
3286 if (s2var
->n_var_parts
)
3288 s2node
= s2var
->var_part
[0].loc_chain
;
3290 for (; s1node
&& s2node
;
3291 s1node
= s1node
->next
, s2node
= s2node
->next
)
3292 if (s1node
->loc
!= s2node
->loc
)
3294 else if (s1node
->loc
== val
)
3297 insert_into_intersection (dest
, s1node
->loc
,
3298 MIN (s1node
->init
, s2node
->init
));
3302 for (; s1node
; s1node
= s1node
->next
)
3304 if (s1node
->loc
== val
)
3307 if ((found
= find_loc_in_1pdv (s1node
->loc
, s2var
,
3308 shared_hash_htab (s2set
->vars
))))
3310 insert_into_intersection (dest
, s1node
->loc
,
3311 MIN (s1node
->init
, found
->init
));
3315 if (GET_CODE (s1node
->loc
) == VALUE
3316 && !VALUE_RECURSED_INTO (s1node
->loc
))
3318 decl_or_value dv
= dv_from_value (s1node
->loc
);
3319 variable svar
= shared_hash_find (s1set
->vars
, dv
);
3322 if (svar
->n_var_parts
== 1)
3324 VALUE_RECURSED_INTO (s1node
->loc
) = true;
3325 intersect_loc_chains (val
, dest
, dsm
,
3326 svar
->var_part
[0].loc_chain
,
3328 VALUE_RECURSED_INTO (s1node
->loc
) = false;
3333 /* ??? gotta look in cselib_val locations too. */
3335 /* ??? if the location is equivalent to any location in src,
3336 searched recursively
3338 add to dst the values needed to represent the equivalence
3340 telling whether locations S is equivalent to another dv's
3343 for each location D in the list
3345 if S and D satisfy rtx_equal_p, then it is present
3347 else if D is a value, recurse without cycles
3349 else if S and D have the same CODE and MODE
3351 for each operand oS and the corresponding oD
3353 if oS and oD are not equivalent, then S an D are not equivalent
3355 else if they are RTX vectors
3357 if any vector oS element is not equivalent to its respective oD,
3358 then S and D are not equivalent
3366 /* Return -1 if X should be before Y in a location list for a 1-part
3367 variable, 1 if Y should be before X, and 0 if they're equivalent
3368 and should not appear in the list. */
3371 loc_cmp (rtx x
, rtx y
)
3374 RTX_CODE code
= GET_CODE (x
);
3384 gcc_assert (GET_MODE (x
) == GET_MODE (y
));
3385 if (REGNO (x
) == REGNO (y
))
3387 else if (REGNO (x
) < REGNO (y
))
3400 gcc_assert (GET_MODE (x
) == GET_MODE (y
));
3401 return loc_cmp (XEXP (x
, 0), XEXP (y
, 0));
3407 if (GET_CODE (x
) == VALUE
)
3409 if (GET_CODE (y
) != VALUE
)
3411 /* Don't assert the modes are the same, that is true only
3412 when not recursing. (subreg:QI (value:SI 1:1) 0)
3413 and (subreg:QI (value:DI 2:2) 0) can be compared,
3414 even when the modes are different. */
3415 if (canon_value_cmp (x
, y
))
3421 if (GET_CODE (y
) == VALUE
)
3424 /* Entry value is the least preferable kind of expression. */
3425 if (GET_CODE (x
) == ENTRY_VALUE
)
3427 if (GET_CODE (y
) != ENTRY_VALUE
)
3429 gcc_assert (GET_MODE (x
) == GET_MODE (y
));
3430 return loc_cmp (ENTRY_VALUE_EXP (x
), ENTRY_VALUE_EXP (y
));
3433 if (GET_CODE (y
) == ENTRY_VALUE
)
3436 if (GET_CODE (x
) == GET_CODE (y
))
3437 /* Compare operands below. */;
3438 else if (GET_CODE (x
) < GET_CODE (y
))
3443 gcc_assert (GET_MODE (x
) == GET_MODE (y
));
3445 if (GET_CODE (x
) == DEBUG_EXPR
)
3447 if (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x
))
3448 < DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (y
)))
3450 gcc_checking_assert (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x
))
3451 > DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (y
)));
3455 fmt
= GET_RTX_FORMAT (code
);
3456 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
3460 if (XWINT (x
, i
) == XWINT (y
, i
))
3462 else if (XWINT (x
, i
) < XWINT (y
, i
))
3469 if (XINT (x
, i
) == XINT (y
, i
))
3471 else if (XINT (x
, i
) < XINT (y
, i
))
3478 /* Compare the vector length first. */
3479 if (XVECLEN (x
, i
) == XVECLEN (y
, i
))
3480 /* Compare the vectors elements. */;
3481 else if (XVECLEN (x
, i
) < XVECLEN (y
, i
))
3486 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3487 if ((r
= loc_cmp (XVECEXP (x
, i
, j
),
3488 XVECEXP (y
, i
, j
))))
3493 if ((r
= loc_cmp (XEXP (x
, i
), XEXP (y
, i
))))
3499 if (XSTR (x
, i
) == XSTR (y
, i
))
3505 if ((r
= strcmp (XSTR (x
, i
), XSTR (y
, i
))) == 0)
3513 /* These are just backpointers, so they don't matter. */
3520 /* It is believed that rtx's at this level will never
3521 contain anything but integers and other rtx's,
3522 except for within LABEL_REFs and SYMBOL_REFs. */
3531 /* Check the order of entries in one-part variables. */
3534 canonicalize_loc_order_check (variable_def
**slot
,
3535 dataflow_set
*data ATTRIBUTE_UNUSED
)
3537 variable var
= *slot
;
3538 location_chain node
, next
;
3540 #ifdef ENABLE_RTL_CHECKING
3542 for (i
= 0; i
< var
->n_var_parts
; i
++)
3543 gcc_assert (var
->var_part
[0].cur_loc
== NULL
);
3544 gcc_assert (!var
->in_changed_variables
);
3550 gcc_assert (var
->n_var_parts
== 1);
3551 node
= var
->var_part
[0].loc_chain
;
3554 while ((next
= node
->next
))
3556 gcc_assert (loc_cmp (node
->loc
, next
->loc
) < 0);
3564 /* Mark with VALUE_RECURSED_INTO values that have neighbors that are
3565 more likely to be chosen as canonical for an equivalence set.
3566 Ensure less likely values can reach more likely neighbors, making
3567 the connections bidirectional. */
3570 canonicalize_values_mark (variable_def
**slot
, dataflow_set
*set
)
3572 variable var
= *slot
;
3573 decl_or_value dv
= var
->dv
;
3575 location_chain node
;
3577 if (!dv_is_value_p (dv
))
3580 gcc_checking_assert (var
->n_var_parts
== 1);
3582 val
= dv_as_value (dv
);
3584 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
3585 if (GET_CODE (node
->loc
) == VALUE
)
3587 if (canon_value_cmp (node
->loc
, val
))
3588 VALUE_RECURSED_INTO (val
) = true;
3591 decl_or_value odv
= dv_from_value (node
->loc
);
3592 variable_def
**oslot
;
3593 oslot
= shared_hash_find_slot_noinsert (set
->vars
, odv
);
3595 set_slot_part (set
, val
, oslot
, odv
, 0,
3596 node
->init
, NULL_RTX
);
3598 VALUE_RECURSED_INTO (node
->loc
) = true;
3605 /* Remove redundant entries from equivalence lists in onepart
3606 variables, canonicalizing equivalence sets into star shapes. */
3609 canonicalize_values_star (variable_def
**slot
, dataflow_set
*set
)
3611 variable var
= *slot
;
3612 decl_or_value dv
= var
->dv
;
3613 location_chain node
;
3616 variable_def
**cslot
;
3623 gcc_checking_assert (var
->n_var_parts
== 1);
3625 if (dv_is_value_p (dv
))
3627 cval
= dv_as_value (dv
);
3628 if (!VALUE_RECURSED_INTO (cval
))
3630 VALUE_RECURSED_INTO (cval
) = false;
3640 gcc_assert (var
->n_var_parts
== 1);
3642 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
3643 if (GET_CODE (node
->loc
) == VALUE
)
3646 if (VALUE_RECURSED_INTO (node
->loc
))
3648 if (canon_value_cmp (node
->loc
, cval
))
3657 if (!has_marks
|| dv_is_decl_p (dv
))
3660 /* Keep it marked so that we revisit it, either after visiting a
3661 child node, or after visiting a new parent that might be
3663 VALUE_RECURSED_INTO (val
) = true;
3665 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
3666 if (GET_CODE (node
->loc
) == VALUE
3667 && VALUE_RECURSED_INTO (node
->loc
))
3671 VALUE_RECURSED_INTO (cval
) = false;
3672 dv
= dv_from_value (cval
);
3673 slot
= shared_hash_find_slot_noinsert (set
->vars
, dv
);
3676 gcc_assert (dv_is_decl_p (var
->dv
));
3677 /* The canonical value was reset and dropped.
3679 clobber_variable_part (set
, NULL
, var
->dv
, 0, NULL
);
3683 gcc_assert (dv_is_value_p (var
->dv
));
3684 if (var
->n_var_parts
== 0)
3686 gcc_assert (var
->n_var_parts
== 1);
3690 VALUE_RECURSED_INTO (val
) = false;
3695 /* Push values to the canonical one. */
3696 cdv
= dv_from_value (cval
);
3697 cslot
= shared_hash_find_slot_noinsert (set
->vars
, cdv
);
3699 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
3700 if (node
->loc
!= cval
)
3702 cslot
= set_slot_part (set
, node
->loc
, cslot
, cdv
, 0,
3703 node
->init
, NULL_RTX
);
3704 if (GET_CODE (node
->loc
) == VALUE
)
3706 decl_or_value ndv
= dv_from_value (node
->loc
);
3708 set_variable_part (set
, cval
, ndv
, 0, node
->init
, NULL_RTX
,
3711 if (canon_value_cmp (node
->loc
, val
))
3713 /* If it could have been a local minimum, it's not any more,
3714 since it's now neighbor to cval, so it may have to push
3715 to it. Conversely, if it wouldn't have prevailed over
3716 val, then whatever mark it has is fine: if it was to
3717 push, it will now push to a more canonical node, but if
3718 it wasn't, then it has already pushed any values it might
3720 VALUE_RECURSED_INTO (node
->loc
) = true;
3721 /* Make sure we visit node->loc by ensuring we cval is
3723 VALUE_RECURSED_INTO (cval
) = true;
3725 else if (!VALUE_RECURSED_INTO (node
->loc
))
3726 /* If we have no need to "recurse" into this node, it's
3727 already "canonicalized", so drop the link to the old
3729 clobber_variable_part (set
, cval
, ndv
, 0, NULL
);
3731 else if (GET_CODE (node
->loc
) == REG
)
3733 attrs list
= set
->regs
[REGNO (node
->loc
)], *listp
;
3735 /* Change an existing attribute referring to dv so that it
3736 refers to cdv, removing any duplicate this might
3737 introduce, and checking that no previous duplicates
3738 existed, all in a single pass. */
3742 if (list
->offset
== 0
3743 && (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
)
3744 || dv_as_opaque (list
->dv
) == dv_as_opaque (cdv
)))
3751 if (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
))
3754 for (listp
= &list
->next
; (list
= *listp
); listp
= &list
->next
)
3759 if (dv_as_opaque (list
->dv
) == dv_as_opaque (cdv
))
3761 *listp
= list
->next
;
3762 pool_free (attrs_pool
, list
);
3767 gcc_assert (dv_as_opaque (list
->dv
) != dv_as_opaque (dv
));
3770 else if (dv_as_opaque (list
->dv
) == dv_as_opaque (cdv
))
3772 for (listp
= &list
->next
; (list
= *listp
); listp
= &list
->next
)
3777 if (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
))
3779 *listp
= list
->next
;
3780 pool_free (attrs_pool
, list
);
3785 gcc_assert (dv_as_opaque (list
->dv
) != dv_as_opaque (cdv
));
3794 if (list
->offset
== 0
3795 && (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
)
3796 || dv_as_opaque (list
->dv
) == dv_as_opaque (cdv
)))
3806 set_slot_part (set
, val
, cslot
, cdv
, 0,
3807 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
);
3809 slot
= clobber_slot_part (set
, cval
, slot
, 0, NULL
);
3811 /* Variable may have been unshared. */
3813 gcc_checking_assert (var
->n_var_parts
&& var
->var_part
[0].loc_chain
->loc
== cval
3814 && var
->var_part
[0].loc_chain
->next
== NULL
);
3816 if (VALUE_RECURSED_INTO (cval
))
3817 goto restart_with_cval
;
3822 /* Bind one-part variables to the canonical value in an equivalence
3823 set. Not doing this causes dataflow convergence failure in rare
3824 circumstances, see PR42873. Unfortunately we can't do this
3825 efficiently as part of canonicalize_values_star, since we may not
3826 have determined or even seen the canonical value of a set when we
3827 get to a variable that references another member of the set. */
3830 canonicalize_vars_star (variable_def
**slot
, dataflow_set
*set
)
3832 variable var
= *slot
;
3833 decl_or_value dv
= var
->dv
;
3834 location_chain node
;
3837 variable_def
**cslot
;
3839 location_chain cnode
;
3841 if (!var
->onepart
|| var
->onepart
== ONEPART_VALUE
)
3844 gcc_assert (var
->n_var_parts
== 1);
3846 node
= var
->var_part
[0].loc_chain
;
3848 if (GET_CODE (node
->loc
) != VALUE
)
3851 gcc_assert (!node
->next
);
3854 /* Push values to the canonical one. */
3855 cdv
= dv_from_value (cval
);
3856 cslot
= shared_hash_find_slot_noinsert (set
->vars
, cdv
);
3860 gcc_assert (cvar
->n_var_parts
== 1);
3862 cnode
= cvar
->var_part
[0].loc_chain
;
3864 /* CVAL is canonical if its value list contains non-VALUEs or VALUEs
3865 that are not “more canonical” than it. */
3866 if (GET_CODE (cnode
->loc
) != VALUE
3867 || !canon_value_cmp (cnode
->loc
, cval
))
3870 /* CVAL was found to be non-canonical. Change the variable to point
3871 to the canonical VALUE. */
3872 gcc_assert (!cnode
->next
);
3875 slot
= set_slot_part (set
, cval
, slot
, dv
, 0,
3876 node
->init
, node
->set_src
);
3877 clobber_slot_part (set
, cval
, slot
, 0, node
->set_src
);
3882 /* Combine variable or value in *S1SLOT (in DSM->cur) with the
3883 corresponding entry in DSM->src. Multi-part variables are combined
3884 with variable_union, whereas onepart dvs are combined with
3888 variable_merge_over_cur (variable s1var
, struct dfset_merge
*dsm
)
3890 dataflow_set
*dst
= dsm
->dst
;
3891 variable_def
**dstslot
;
3892 variable s2var
, dvar
= NULL
;
3893 decl_or_value dv
= s1var
->dv
;
3894 onepart_enum_t onepart
= s1var
->onepart
;
3897 location_chain node
, *nodep
;
3899 /* If the incoming onepart variable has an empty location list, then
3900 the intersection will be just as empty. For other variables,
3901 it's always union. */
3902 gcc_checking_assert (s1var
->n_var_parts
3903 && s1var
->var_part
[0].loc_chain
);
3906 return variable_union (s1var
, dst
);
3908 gcc_checking_assert (s1var
->n_var_parts
== 1);
3910 dvhash
= dv_htab_hash (dv
);
3911 if (dv_is_value_p (dv
))
3912 val
= dv_as_value (dv
);
3916 s2var
= shared_hash_find_1 (dsm
->src
->vars
, dv
, dvhash
);
3919 dst_can_be_shared
= false;
3923 dsm
->src_onepart_cnt
--;
3924 gcc_assert (s2var
->var_part
[0].loc_chain
3925 && s2var
->onepart
== onepart
3926 && s2var
->n_var_parts
== 1);
3928 dstslot
= shared_hash_find_slot_noinsert_1 (dst
->vars
, dv
, dvhash
);
3932 gcc_assert (dvar
->refcount
== 1
3933 && dvar
->onepart
== onepart
3934 && dvar
->n_var_parts
== 1);
3935 nodep
= &dvar
->var_part
[0].loc_chain
;
3943 if (!dstslot
&& !onepart_variable_different_p (s1var
, s2var
))
3945 dstslot
= shared_hash_find_slot_unshare_1 (&dst
->vars
, dv
,
3947 *dstslot
= dvar
= s2var
;
3952 dst_can_be_shared
= false;
3954 intersect_loc_chains (val
, nodep
, dsm
,
3955 s1var
->var_part
[0].loc_chain
, s2var
);
3961 dvar
= (variable
) pool_alloc (onepart_pool (onepart
));
3964 dvar
->n_var_parts
= 1;
3965 dvar
->onepart
= onepart
;
3966 dvar
->in_changed_variables
= false;
3967 dvar
->var_part
[0].loc_chain
= node
;
3968 dvar
->var_part
[0].cur_loc
= NULL
;
3970 VAR_LOC_1PAUX (dvar
) = NULL
;
3972 VAR_PART_OFFSET (dvar
, 0) = 0;
3975 = shared_hash_find_slot_unshare_1 (&dst
->vars
, dv
, dvhash
,
3977 gcc_assert (!*dstslot
);
3985 nodep
= &dvar
->var_part
[0].loc_chain
;
3986 while ((node
= *nodep
))
3988 location_chain
*nextp
= &node
->next
;
3990 if (GET_CODE (node
->loc
) == REG
)
3994 for (list
= dst
->regs
[REGNO (node
->loc
)]; list
; list
= list
->next
)
3995 if (GET_MODE (node
->loc
) == GET_MODE (list
->loc
)
3996 && dv_is_value_p (list
->dv
))
4000 attrs_list_insert (&dst
->regs
[REGNO (node
->loc
)],
4002 /* If this value became canonical for another value that had
4003 this register, we want to leave it alone. */
4004 else if (dv_as_value (list
->dv
) != val
)
4006 dstslot
= set_slot_part (dst
, dv_as_value (list
->dv
),
4008 node
->init
, NULL_RTX
);
4009 dstslot
= delete_slot_part (dst
, node
->loc
, dstslot
, 0);
4011 /* Since nextp points into the removed node, we can't
4012 use it. The pointer to the next node moved to nodep.
4013 However, if the variable we're walking is unshared
4014 during our walk, we'll keep walking the location list
4015 of the previously-shared variable, in which case the
4016 node won't have been removed, and we'll want to skip
4017 it. That's why we test *nodep here. */
4023 /* Canonicalization puts registers first, so we don't have to
4029 if (dvar
!= *dstslot
)
4031 nodep
= &dvar
->var_part
[0].loc_chain
;
4035 /* Mark all referenced nodes for canonicalization, and make sure
4036 we have mutual equivalence links. */
4037 VALUE_RECURSED_INTO (val
) = true;
4038 for (node
= *nodep
; node
; node
= node
->next
)
4039 if (GET_CODE (node
->loc
) == VALUE
)
4041 VALUE_RECURSED_INTO (node
->loc
) = true;
4042 set_variable_part (dst
, val
, dv_from_value (node
->loc
), 0,
4043 node
->init
, NULL
, INSERT
);
4046 dstslot
= shared_hash_find_slot_noinsert_1 (dst
->vars
, dv
, dvhash
);
4047 gcc_assert (*dstslot
== dvar
);
4048 canonicalize_values_star (dstslot
, dst
);
4049 gcc_checking_assert (dstslot
4050 == shared_hash_find_slot_noinsert_1 (dst
->vars
,
4056 bool has_value
= false, has_other
= false;
4058 /* If we have one value and anything else, we're going to
4059 canonicalize this, so make sure all values have an entry in
4060 the table and are marked for canonicalization. */
4061 for (node
= *nodep
; node
; node
= node
->next
)
4063 if (GET_CODE (node
->loc
) == VALUE
)
4065 /* If this was marked during register canonicalization,
4066 we know we have to canonicalize values. */
4081 if (has_value
&& has_other
)
4083 for (node
= *nodep
; node
; node
= node
->next
)
4085 if (GET_CODE (node
->loc
) == VALUE
)
4087 decl_or_value dv
= dv_from_value (node
->loc
);
4088 variable_def
**slot
= NULL
;
4090 if (shared_hash_shared (dst
->vars
))
4091 slot
= shared_hash_find_slot_noinsert (dst
->vars
, dv
);
4093 slot
= shared_hash_find_slot_unshare (&dst
->vars
, dv
,
4097 variable var
= (variable
) pool_alloc (onepart_pool
4101 var
->n_var_parts
= 1;
4102 var
->onepart
= ONEPART_VALUE
;
4103 var
->in_changed_variables
= false;
4104 var
->var_part
[0].loc_chain
= NULL
;
4105 var
->var_part
[0].cur_loc
= NULL
;
4106 VAR_LOC_1PAUX (var
) = NULL
;
4110 VALUE_RECURSED_INTO (node
->loc
) = true;
4114 dstslot
= shared_hash_find_slot_noinsert_1 (dst
->vars
, dv
, dvhash
);
4115 gcc_assert (*dstslot
== dvar
);
4116 canonicalize_values_star (dstslot
, dst
);
4117 gcc_checking_assert (dstslot
4118 == shared_hash_find_slot_noinsert_1 (dst
->vars
,
4124 if (!onepart_variable_different_p (dvar
, s2var
))
4126 variable_htab_free (dvar
);
4127 *dstslot
= dvar
= s2var
;
4130 else if (s2var
!= s1var
&& !onepart_variable_different_p (dvar
, s1var
))
4132 variable_htab_free (dvar
);
4133 *dstslot
= dvar
= s1var
;
4135 dst_can_be_shared
= false;
4138 dst_can_be_shared
= false;
4143 /* Copy s2slot (in DSM->src) to DSM->dst if the variable is a
4144 multi-part variable. Unions of multi-part variables and
4145 intersections of one-part ones will be handled in
4146 variable_merge_over_cur(). */
4149 variable_merge_over_src (variable s2var
, struct dfset_merge
*dsm
)
4151 dataflow_set
*dst
= dsm
->dst
;
4152 decl_or_value dv
= s2var
->dv
;
4154 if (!s2var
->onepart
)
4156 variable_def
**dstp
= shared_hash_find_slot (dst
->vars
, dv
);
4162 dsm
->src_onepart_cnt
++;
4166 /* Combine dataflow set information from SRC2 into DST, using PDST
4167 to carry over information across passes. */
4170 dataflow_set_merge (dataflow_set
*dst
, dataflow_set
*src2
)
4172 dataflow_set cur
= *dst
;
4173 dataflow_set
*src1
= &cur
;
4174 struct dfset_merge dsm
;
4176 size_t src1_elems
, src2_elems
;
4177 variable_iterator_type hi
;
4180 src1_elems
= shared_hash_htab (src1
->vars
).elements ();
4181 src2_elems
= shared_hash_htab (src2
->vars
).elements ();
4182 dataflow_set_init (dst
);
4183 dst
->stack_adjust
= cur
.stack_adjust
;
4184 shared_hash_destroy (dst
->vars
);
4185 dst
->vars
= (shared_hash
) pool_alloc (shared_hash_pool
);
4186 dst
->vars
->refcount
= 1;
4187 dst
->vars
->htab
.create (MAX (src1_elems
, src2_elems
));
4189 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4190 attrs_list_mpdv_union (&dst
->regs
[i
], src1
->regs
[i
], src2
->regs
[i
]);
4195 dsm
.src_onepart_cnt
= 0;
4197 FOR_EACH_HASH_TABLE_ELEMENT (shared_hash_htab (dsm
.src
->vars
),
4199 variable_merge_over_src (var
, &dsm
);
4200 FOR_EACH_HASH_TABLE_ELEMENT (shared_hash_htab (dsm
.cur
->vars
),
4202 variable_merge_over_cur (var
, &dsm
);
4204 if (dsm
.src_onepart_cnt
)
4205 dst_can_be_shared
= false;
4207 dataflow_set_destroy (src1
);
4210 /* Mark register equivalences. */
4213 dataflow_set_equiv_regs (dataflow_set
*set
)
4218 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4220 rtx canon
[NUM_MACHINE_MODES
];
4222 /* If the list is empty or one entry, no need to canonicalize
4224 if (set
->regs
[i
] == NULL
|| set
->regs
[i
]->next
== NULL
)
4227 memset (canon
, 0, sizeof (canon
));
4229 for (list
= set
->regs
[i
]; list
; list
= list
->next
)
4230 if (list
->offset
== 0 && dv_is_value_p (list
->dv
))
4232 rtx val
= dv_as_value (list
->dv
);
4233 rtx
*cvalp
= &canon
[(int)GET_MODE (val
)];
4236 if (canon_value_cmp (val
, cval
))
4240 for (list
= set
->regs
[i
]; list
; list
= list
->next
)
4241 if (list
->offset
== 0 && dv_onepart_p (list
->dv
))
4243 rtx cval
= canon
[(int)GET_MODE (list
->loc
)];
4248 if (dv_is_value_p (list
->dv
))
4250 rtx val
= dv_as_value (list
->dv
);
4255 VALUE_RECURSED_INTO (val
) = true;
4256 set_variable_part (set
, val
, dv_from_value (cval
), 0,
4257 VAR_INIT_STATUS_INITIALIZED
,
4261 VALUE_RECURSED_INTO (cval
) = true;
4262 set_variable_part (set
, cval
, list
->dv
, 0,
4263 VAR_INIT_STATUS_INITIALIZED
, NULL
, NO_INSERT
);
4266 for (listp
= &set
->regs
[i
]; (list
= *listp
);
4267 listp
= list
? &list
->next
: listp
)
4268 if (list
->offset
== 0 && dv_onepart_p (list
->dv
))
4270 rtx cval
= canon
[(int)GET_MODE (list
->loc
)];
4271 variable_def
**slot
;
4276 if (dv_is_value_p (list
->dv
))
4278 rtx val
= dv_as_value (list
->dv
);
4279 if (!VALUE_RECURSED_INTO (val
))
4283 slot
= shared_hash_find_slot_noinsert (set
->vars
, list
->dv
);
4284 canonicalize_values_star (slot
, set
);
4291 /* Remove any redundant values in the location list of VAR, which must
4292 be unshared and 1-part. */
4295 remove_duplicate_values (variable var
)
4297 location_chain node
, *nodep
;
4299 gcc_assert (var
->onepart
);
4300 gcc_assert (var
->n_var_parts
== 1);
4301 gcc_assert (var
->refcount
== 1);
4303 for (nodep
= &var
->var_part
[0].loc_chain
; (node
= *nodep
); )
4305 if (GET_CODE (node
->loc
) == VALUE
)
4307 if (VALUE_RECURSED_INTO (node
->loc
))
4309 /* Remove duplicate value node. */
4310 *nodep
= node
->next
;
4311 pool_free (loc_chain_pool
, node
);
4315 VALUE_RECURSED_INTO (node
->loc
) = true;
4317 nodep
= &node
->next
;
4320 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
4321 if (GET_CODE (node
->loc
) == VALUE
)
4323 gcc_assert (VALUE_RECURSED_INTO (node
->loc
));
4324 VALUE_RECURSED_INTO (node
->loc
) = false;
4329 /* Hash table iteration argument passed to variable_post_merge. */
4330 struct dfset_post_merge
4332 /* The new input set for the current block. */
4334 /* Pointer to the permanent input set for the current block, or
4336 dataflow_set
**permp
;
4339 /* Create values for incoming expressions associated with one-part
4340 variables that don't have value numbers for them. */
4343 variable_post_merge_new_vals (variable_def
**slot
, dfset_post_merge
*dfpm
)
4345 dataflow_set
*set
= dfpm
->set
;
4346 variable var
= *slot
;
4347 location_chain node
;
4349 if (!var
->onepart
|| !var
->n_var_parts
)
4352 gcc_assert (var
->n_var_parts
== 1);
4354 if (dv_is_decl_p (var
->dv
))
4356 bool check_dupes
= false;
4359 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
4361 if (GET_CODE (node
->loc
) == VALUE
)
4362 gcc_assert (!VALUE_RECURSED_INTO (node
->loc
));
4363 else if (GET_CODE (node
->loc
) == REG
)
4365 attrs att
, *attp
, *curp
= NULL
;
4367 if (var
->refcount
!= 1)
4369 slot
= unshare_variable (set
, slot
, var
,
4370 VAR_INIT_STATUS_INITIALIZED
);
4375 for (attp
= &set
->regs
[REGNO (node
->loc
)]; (att
= *attp
);
4377 if (att
->offset
== 0
4378 && GET_MODE (att
->loc
) == GET_MODE (node
->loc
))
4380 if (dv_is_value_p (att
->dv
))
4382 rtx cval
= dv_as_value (att
->dv
);
4387 else if (dv_as_opaque (att
->dv
) == dv_as_opaque (var
->dv
))
4395 if ((*curp
)->offset
== 0
4396 && GET_MODE ((*curp
)->loc
) == GET_MODE (node
->loc
)
4397 && dv_as_opaque ((*curp
)->dv
) == dv_as_opaque (var
->dv
))
4400 curp
= &(*curp
)->next
;
4411 *dfpm
->permp
= XNEW (dataflow_set
);
4412 dataflow_set_init (*dfpm
->permp
);
4415 for (att
= (*dfpm
->permp
)->regs
[REGNO (node
->loc
)];
4416 att
; att
= att
->next
)
4417 if (GET_MODE (att
->loc
) == GET_MODE (node
->loc
))
4419 gcc_assert (att
->offset
== 0
4420 && dv_is_value_p (att
->dv
));
4421 val_reset (set
, att
->dv
);
4428 cval
= dv_as_value (cdv
);
4432 /* Create a unique value to hold this register,
4433 that ought to be found and reused in
4434 subsequent rounds. */
4436 gcc_assert (!cselib_lookup (node
->loc
,
4437 GET_MODE (node
->loc
), 0,
4439 v
= cselib_lookup (node
->loc
, GET_MODE (node
->loc
), 1,
4441 cselib_preserve_value (v
);
4442 cselib_invalidate_rtx (node
->loc
);
4444 cdv
= dv_from_value (cval
);
4447 "Created new value %u:%u for reg %i\n",
4448 v
->uid
, v
->hash
, REGNO (node
->loc
));
4451 var_reg_decl_set (*dfpm
->permp
, node
->loc
,
4452 VAR_INIT_STATUS_INITIALIZED
,
4453 cdv
, 0, NULL
, INSERT
);
4459 /* Remove attribute referring to the decl, which now
4460 uses the value for the register, already existing or
4461 to be added when we bring perm in. */
4464 pool_free (attrs_pool
, att
);
4469 remove_duplicate_values (var
);
4475 /* Reset values in the permanent set that are not associated with the
4476 chosen expression. */
4479 variable_post_merge_perm_vals (variable_def
**pslot
, dfset_post_merge
*dfpm
)
4481 dataflow_set
*set
= dfpm
->set
;
4482 variable pvar
= *pslot
, var
;
4483 location_chain pnode
;
4487 gcc_assert (dv_is_value_p (pvar
->dv
)
4488 && pvar
->n_var_parts
== 1);
4489 pnode
= pvar
->var_part
[0].loc_chain
;
4492 && REG_P (pnode
->loc
));
4496 var
= shared_hash_find (set
->vars
, dv
);
4499 /* Although variable_post_merge_new_vals may have made decls
4500 non-star-canonical, values that pre-existed in canonical form
4501 remain canonical, and newly-created values reference a single
4502 REG, so they are canonical as well. Since VAR has the
4503 location list for a VALUE, using find_loc_in_1pdv for it is
4504 fine, since VALUEs don't map back to DECLs. */
4505 if (find_loc_in_1pdv (pnode
->loc
, var
, shared_hash_htab (set
->vars
)))
4507 val_reset (set
, dv
);
4510 for (att
= set
->regs
[REGNO (pnode
->loc
)]; att
; att
= att
->next
)
4511 if (att
->offset
== 0
4512 && GET_MODE (att
->loc
) == GET_MODE (pnode
->loc
)
4513 && dv_is_value_p (att
->dv
))
4516 /* If there is a value associated with this register already, create
4518 if (att
&& dv_as_value (att
->dv
) != dv_as_value (dv
))
4520 rtx cval
= dv_as_value (att
->dv
);
4521 set_variable_part (set
, cval
, dv
, 0, pnode
->init
, NULL
, INSERT
);
4522 set_variable_part (set
, dv_as_value (dv
), att
->dv
, 0, pnode
->init
,
4527 attrs_list_insert (&set
->regs
[REGNO (pnode
->loc
)],
4529 variable_union (pvar
, set
);
4535 /* Just checking stuff and registering register attributes for
4539 dataflow_post_merge_adjust (dataflow_set
*set
, dataflow_set
**permp
)
4541 struct dfset_post_merge dfpm
;
4546 shared_hash_htab (set
->vars
)
4547 .traverse
<dfset_post_merge
*, variable_post_merge_new_vals
> (&dfpm
);
4549 shared_hash_htab ((*permp
)->vars
)
4550 .traverse
<dfset_post_merge
*, variable_post_merge_perm_vals
> (&dfpm
);
4551 shared_hash_htab (set
->vars
)
4552 .traverse
<dataflow_set
*, canonicalize_values_star
> (set
);
4553 shared_hash_htab (set
->vars
)
4554 .traverse
<dataflow_set
*, canonicalize_vars_star
> (set
);
4557 /* Return a node whose loc is a MEM that refers to EXPR in the
4558 location list of a one-part variable or value VAR, or in that of
4559 any values recursively mentioned in the location lists. */
4561 static location_chain
4562 find_mem_expr_in_1pdv (tree expr
, rtx val
, variable_table_type vars
)
4564 location_chain node
;
4567 location_chain where
= NULL
;
4572 gcc_assert (GET_CODE (val
) == VALUE
4573 && !VALUE_RECURSED_INTO (val
));
4575 dv
= dv_from_value (val
);
4576 var
= vars
.find_with_hash (dv
, dv_htab_hash (dv
));
4581 gcc_assert (var
->onepart
);
4583 if (!var
->n_var_parts
)
4586 VALUE_RECURSED_INTO (val
) = true;
4588 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
4589 if (MEM_P (node
->loc
)
4590 && MEM_EXPR (node
->loc
) == expr
4591 && INT_MEM_OFFSET (node
->loc
) == 0)
4596 else if (GET_CODE (node
->loc
) == VALUE
4597 && !VALUE_RECURSED_INTO (node
->loc
)
4598 && (where
= find_mem_expr_in_1pdv (expr
, node
->loc
, vars
)))
4601 VALUE_RECURSED_INTO (val
) = false;
4606 /* Return TRUE if the value of MEM may vary across a call. */
4609 mem_dies_at_call (rtx mem
)
4611 tree expr
= MEM_EXPR (mem
);
4617 decl
= get_base_address (expr
);
4625 return (may_be_aliased (decl
)
4626 || (!TREE_READONLY (decl
) && is_global_var (decl
)));
4629 /* Remove all MEMs from the location list of a hash table entry for a
4630 one-part variable, except those whose MEM attributes map back to
4631 the variable itself, directly or within a VALUE. */
4634 dataflow_set_preserve_mem_locs (variable_def
**slot
, dataflow_set
*set
)
4636 variable var
= *slot
;
4638 if (var
->onepart
== ONEPART_VDECL
|| var
->onepart
== ONEPART_DEXPR
)
4640 tree decl
= dv_as_decl (var
->dv
);
4641 location_chain loc
, *locp
;
4642 bool changed
= false;
4644 if (!var
->n_var_parts
)
4647 gcc_assert (var
->n_var_parts
== 1);
4649 if (shared_var_p (var
, set
->vars
))
4651 for (loc
= var
->var_part
[0].loc_chain
; loc
; loc
= loc
->next
)
4653 /* We want to remove dying MEMs that doesn't refer to DECL. */
4654 if (GET_CODE (loc
->loc
) == MEM
4655 && (MEM_EXPR (loc
->loc
) != decl
4656 || INT_MEM_OFFSET (loc
->loc
) != 0)
4657 && !mem_dies_at_call (loc
->loc
))
4659 /* We want to move here MEMs that do refer to DECL. */
4660 else if (GET_CODE (loc
->loc
) == VALUE
4661 && find_mem_expr_in_1pdv (decl
, loc
->loc
,
4662 shared_hash_htab (set
->vars
)))
4669 slot
= unshare_variable (set
, slot
, var
, VAR_INIT_STATUS_UNKNOWN
);
4671 gcc_assert (var
->n_var_parts
== 1);
4674 for (locp
= &var
->var_part
[0].loc_chain
, loc
= *locp
;
4677 rtx old_loc
= loc
->loc
;
4678 if (GET_CODE (old_loc
) == VALUE
)
4680 location_chain mem_node
4681 = find_mem_expr_in_1pdv (decl
, loc
->loc
,
4682 shared_hash_htab (set
->vars
));
4684 /* ??? This picks up only one out of multiple MEMs that
4685 refer to the same variable. Do we ever need to be
4686 concerned about dealing with more than one, or, given
4687 that they should all map to the same variable
4688 location, their addresses will have been merged and
4689 they will be regarded as equivalent? */
4692 loc
->loc
= mem_node
->loc
;
4693 loc
->set_src
= mem_node
->set_src
;
4694 loc
->init
= MIN (loc
->init
, mem_node
->init
);
4698 if (GET_CODE (loc
->loc
) != MEM
4699 || (MEM_EXPR (loc
->loc
) == decl
4700 && INT_MEM_OFFSET (loc
->loc
) == 0)
4701 || !mem_dies_at_call (loc
->loc
))
4703 if (old_loc
!= loc
->loc
&& emit_notes
)
4705 if (old_loc
== var
->var_part
[0].cur_loc
)
4708 var
->var_part
[0].cur_loc
= NULL
;
4717 if (old_loc
== var
->var_part
[0].cur_loc
)
4720 var
->var_part
[0].cur_loc
= NULL
;
4724 pool_free (loc_chain_pool
, loc
);
4727 if (!var
->var_part
[0].loc_chain
)
4733 variable_was_changed (var
, set
);
4739 /* Remove all MEMs from the location list of a hash table entry for a
4743 dataflow_set_remove_mem_locs (variable_def
**slot
, dataflow_set
*set
)
4745 variable var
= *slot
;
4747 if (var
->onepart
== ONEPART_VALUE
)
4749 location_chain loc
, *locp
;
4750 bool changed
= false;
4753 gcc_assert (var
->n_var_parts
== 1);
4755 if (shared_var_p (var
, set
->vars
))
4757 for (loc
= var
->var_part
[0].loc_chain
; loc
; loc
= loc
->next
)
4758 if (GET_CODE (loc
->loc
) == MEM
4759 && mem_dies_at_call (loc
->loc
))
4765 slot
= unshare_variable (set
, slot
, var
, VAR_INIT_STATUS_UNKNOWN
);
4767 gcc_assert (var
->n_var_parts
== 1);
4770 if (VAR_LOC_1PAUX (var
))
4771 cur_loc
= VAR_LOC_FROM (var
);
4773 cur_loc
= var
->var_part
[0].cur_loc
;
4775 for (locp
= &var
->var_part
[0].loc_chain
, loc
= *locp
;
4778 if (GET_CODE (loc
->loc
) != MEM
4779 || !mem_dies_at_call (loc
->loc
))
4786 /* If we have deleted the location which was last emitted
4787 we have to emit new location so add the variable to set
4788 of changed variables. */
4789 if (cur_loc
== loc
->loc
)
4792 var
->var_part
[0].cur_loc
= NULL
;
4793 if (VAR_LOC_1PAUX (var
))
4794 VAR_LOC_FROM (var
) = NULL
;
4796 pool_free (loc_chain_pool
, loc
);
4799 if (!var
->var_part
[0].loc_chain
)
4805 variable_was_changed (var
, set
);
4811 /* Remove all variable-location information about call-clobbered
4812 registers, as well as associations between MEMs and VALUEs. */
4815 dataflow_set_clear_at_call (dataflow_set
*set
)
4818 hard_reg_set_iterator hrsi
;
4820 EXECUTE_IF_SET_IN_HARD_REG_SET (regs_invalidated_by_call
, 0, r
, hrsi
)
4821 var_regno_delete (set
, r
);
4823 if (MAY_HAVE_DEBUG_INSNS
)
4825 set
->traversed_vars
= set
->vars
;
4826 shared_hash_htab (set
->vars
)
4827 .traverse
<dataflow_set
*, dataflow_set_preserve_mem_locs
> (set
);
4828 set
->traversed_vars
= set
->vars
;
4829 shared_hash_htab (set
->vars
)
4830 .traverse
<dataflow_set
*, dataflow_set_remove_mem_locs
> (set
);
4831 set
->traversed_vars
= NULL
;
4836 variable_part_different_p (variable_part
*vp1
, variable_part
*vp2
)
4838 location_chain lc1
, lc2
;
4840 for (lc1
= vp1
->loc_chain
; lc1
; lc1
= lc1
->next
)
4842 for (lc2
= vp2
->loc_chain
; lc2
; lc2
= lc2
->next
)
4844 if (REG_P (lc1
->loc
) && REG_P (lc2
->loc
))
4846 if (REGNO (lc1
->loc
) == REGNO (lc2
->loc
))
4849 if (rtx_equal_p (lc1
->loc
, lc2
->loc
))
4858 /* Return true if one-part variables VAR1 and VAR2 are different.
4859 They must be in canonical order. */
4862 onepart_variable_different_p (variable var1
, variable var2
)
4864 location_chain lc1
, lc2
;
4869 gcc_assert (var1
->n_var_parts
== 1
4870 && var2
->n_var_parts
== 1);
4872 lc1
= var1
->var_part
[0].loc_chain
;
4873 lc2
= var2
->var_part
[0].loc_chain
;
4875 gcc_assert (lc1
&& lc2
);
4879 if (loc_cmp (lc1
->loc
, lc2
->loc
))
4888 /* Return true if variables VAR1 and VAR2 are different. */
4891 variable_different_p (variable var1
, variable var2
)
4898 if (var1
->onepart
!= var2
->onepart
)
4901 if (var1
->n_var_parts
!= var2
->n_var_parts
)
4904 if (var1
->onepart
&& var1
->n_var_parts
)
4906 gcc_checking_assert (dv_as_opaque (var1
->dv
) == dv_as_opaque (var2
->dv
)
4907 && var1
->n_var_parts
== 1);
4908 /* One-part values have locations in a canonical order. */
4909 return onepart_variable_different_p (var1
, var2
);
4912 for (i
= 0; i
< var1
->n_var_parts
; i
++)
4914 if (VAR_PART_OFFSET (var1
, i
) != VAR_PART_OFFSET (var2
, i
))
4916 if (variable_part_different_p (&var1
->var_part
[i
], &var2
->var_part
[i
]))
4918 if (variable_part_different_p (&var2
->var_part
[i
], &var1
->var_part
[i
]))
4924 /* Return true if dataflow sets OLD_SET and NEW_SET differ. */
4927 dataflow_set_different (dataflow_set
*old_set
, dataflow_set
*new_set
)
4929 variable_iterator_type hi
;
4932 if (old_set
->vars
== new_set
->vars
)
4935 if (shared_hash_htab (old_set
->vars
).elements ()
4936 != shared_hash_htab (new_set
->vars
).elements ())
4939 FOR_EACH_HASH_TABLE_ELEMENT (shared_hash_htab (old_set
->vars
),
4942 variable_table_type htab
= shared_hash_htab (new_set
->vars
);
4943 variable var2
= htab
.find_with_hash (var1
->dv
, dv_htab_hash (var1
->dv
));
4946 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4948 fprintf (dump_file
, "dataflow difference found: removal of:\n");
4954 if (variable_different_p (var1
, var2
))
4956 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4958 fprintf (dump_file
, "dataflow difference found: "
4959 "old and new follow:\n");
4967 /* No need to traverse the second hashtab, if both have the same number
4968 of elements and the second one had all entries found in the first one,
4969 then it can't have any extra entries. */
4973 /* Free the contents of dataflow set SET. */
4976 dataflow_set_destroy (dataflow_set
*set
)
4980 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4981 attrs_list_clear (&set
->regs
[i
]);
4983 shared_hash_destroy (set
->vars
);
4987 /* Return true if RTL X contains a SYMBOL_REF. */
4990 contains_symbol_ref (rtx x
)
4999 code
= GET_CODE (x
);
5000 if (code
== SYMBOL_REF
)
5003 fmt
= GET_RTX_FORMAT (code
);
5004 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
5008 if (contains_symbol_ref (XEXP (x
, i
)))
5011 else if (fmt
[i
] == 'E')
5014 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
5015 if (contains_symbol_ref (XVECEXP (x
, i
, j
)))
5023 /* Shall EXPR be tracked? */
5026 track_expr_p (tree expr
, bool need_rtl
)
5031 if (TREE_CODE (expr
) == DEBUG_EXPR_DECL
)
5032 return DECL_RTL_SET_P (expr
);
5034 /* If EXPR is not a parameter or a variable do not track it. */
5035 if (TREE_CODE (expr
) != VAR_DECL
&& TREE_CODE (expr
) != PARM_DECL
)
5038 /* It also must have a name... */
5039 if (!DECL_NAME (expr
) && need_rtl
)
5042 /* ... and a RTL assigned to it. */
5043 decl_rtl
= DECL_RTL_IF_SET (expr
);
5044 if (!decl_rtl
&& need_rtl
)
5047 /* If this expression is really a debug alias of some other declaration, we
5048 don't need to track this expression if the ultimate declaration is
5051 if (TREE_CODE (realdecl
) == VAR_DECL
&& DECL_HAS_DEBUG_EXPR_P (realdecl
))
5053 realdecl
= DECL_DEBUG_EXPR (realdecl
);
5054 if (!DECL_P (realdecl
))
5056 if (handled_component_p (realdecl
)
5057 || (TREE_CODE (realdecl
) == MEM_REF
5058 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5060 HOST_WIDE_INT bitsize
, bitpos
, maxsize
;
5062 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
,
5064 if (!DECL_P (innerdecl
)
5065 || DECL_IGNORED_P (innerdecl
)
5066 || TREE_STATIC (innerdecl
)
5068 || bitpos
+ bitsize
> 256
5069 || bitsize
!= maxsize
)
5079 /* Do not track EXPR if REALDECL it should be ignored for debugging
5081 if (DECL_IGNORED_P (realdecl
))
5084 /* Do not track global variables until we are able to emit correct location
5086 if (TREE_STATIC (realdecl
))
5089 /* When the EXPR is a DECL for alias of some variable (see example)
5090 the TREE_STATIC flag is not used. Disable tracking all DECLs whose
5091 DECL_RTL contains SYMBOL_REF.
5094 extern char **_dl_argv_internal __attribute__ ((alias ("_dl_argv")));
5097 if (decl_rtl
&& MEM_P (decl_rtl
)
5098 && contains_symbol_ref (XEXP (decl_rtl
, 0)))
5101 /* If RTX is a memory it should not be very large (because it would be
5102 an array or struct). */
5103 if (decl_rtl
&& MEM_P (decl_rtl
))
5105 /* Do not track structures and arrays. */
5106 if (GET_MODE (decl_rtl
) == BLKmode
5107 || AGGREGATE_TYPE_P (TREE_TYPE (realdecl
)))
5109 if (MEM_SIZE_KNOWN_P (decl_rtl
)
5110 && MEM_SIZE (decl_rtl
) > MAX_VAR_PARTS
)
5114 DECL_CHANGED (expr
) = 0;
5115 DECL_CHANGED (realdecl
) = 0;
5119 /* Determine whether a given LOC refers to the same variable part as
5123 same_variable_part_p (rtx loc
, tree expr
, HOST_WIDE_INT offset
)
5126 HOST_WIDE_INT offset2
;
5128 if (! DECL_P (expr
))
5133 expr2
= REG_EXPR (loc
);
5134 offset2
= REG_OFFSET (loc
);
5136 else if (MEM_P (loc
))
5138 expr2
= MEM_EXPR (loc
);
5139 offset2
= INT_MEM_OFFSET (loc
);
5144 if (! expr2
|| ! DECL_P (expr2
))
5147 expr
= var_debug_decl (expr
);
5148 expr2
= var_debug_decl (expr2
);
5150 return (expr
== expr2
&& offset
== offset2
);
5153 /* LOC is a REG or MEM that we would like to track if possible.
5154 If EXPR is null, we don't know what expression LOC refers to,
5155 otherwise it refers to EXPR + OFFSET. STORE_REG_P is true if
5156 LOC is an lvalue register.
5158 Return true if EXPR is nonnull and if LOC, or some lowpart of it,
5159 is something we can track. When returning true, store the mode of
5160 the lowpart we can track in *MODE_OUT (if nonnull) and its offset
5161 from EXPR in *OFFSET_OUT (if nonnull). */
5164 track_loc_p (rtx loc
, tree expr
, HOST_WIDE_INT offset
, bool store_reg_p
,
5165 enum machine_mode
*mode_out
, HOST_WIDE_INT
*offset_out
)
5167 enum machine_mode mode
;
5169 if (expr
== NULL
|| !track_expr_p (expr
, true))
5172 /* If REG was a paradoxical subreg, its REG_ATTRS will describe the
5173 whole subreg, but only the old inner part is really relevant. */
5174 mode
= GET_MODE (loc
);
5175 if (REG_P (loc
) && !HARD_REGISTER_NUM_P (ORIGINAL_REGNO (loc
)))
5177 enum machine_mode pseudo_mode
;
5179 pseudo_mode
= PSEUDO_REGNO_MODE (ORIGINAL_REGNO (loc
));
5180 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (pseudo_mode
))
5182 offset
+= byte_lowpart_offset (pseudo_mode
, mode
);
5187 /* If LOC is a paradoxical lowpart of EXPR, refer to EXPR itself.
5188 Do the same if we are storing to a register and EXPR occupies
5189 the whole of register LOC; in that case, the whole of EXPR is
5190 being changed. We exclude complex modes from the second case
5191 because the real and imaginary parts are represented as separate
5192 pseudo registers, even if the whole complex value fits into one
5194 if ((GET_MODE_SIZE (mode
) > GET_MODE_SIZE (DECL_MODE (expr
))
5196 && !COMPLEX_MODE_P (DECL_MODE (expr
))
5197 && hard_regno_nregs
[REGNO (loc
)][DECL_MODE (expr
)] == 1))
5198 && offset
+ byte_lowpart_offset (DECL_MODE (expr
), mode
) == 0)
5200 mode
= DECL_MODE (expr
);
5204 if (offset
< 0 || offset
>= MAX_VAR_PARTS
)
5210 *offset_out
= offset
;
5214 /* Return the MODE lowpart of LOC, or null if LOC is not something we
5215 want to track. When returning nonnull, make sure that the attributes
5216 on the returned value are updated. */
5219 var_lowpart (enum machine_mode mode
, rtx loc
)
5221 unsigned int offset
, reg_offset
, regno
;
5223 if (GET_MODE (loc
) == mode
)
5226 if (!REG_P (loc
) && !MEM_P (loc
))
5229 offset
= byte_lowpart_offset (mode
, GET_MODE (loc
));
5232 return adjust_address_nv (loc
, mode
, offset
);
5234 reg_offset
= subreg_lowpart_offset (mode
, GET_MODE (loc
));
5235 regno
= REGNO (loc
) + subreg_regno_offset (REGNO (loc
), GET_MODE (loc
),
5237 return gen_rtx_REG_offset (loc
, mode
, regno
, offset
);
5240 /* Carry information about uses and stores while walking rtx. */
5242 struct count_use_info
5244 /* The insn where the RTX is. */
5247 /* The basic block where insn is. */
5250 /* The array of n_sets sets in the insn, as determined by cselib. */
5251 struct cselib_set
*sets
;
5254 /* True if we're counting stores, false otherwise. */
5258 /* Find a VALUE corresponding to X. */
5260 static inline cselib_val
*
5261 find_use_val (rtx x
, enum machine_mode mode
, struct count_use_info
*cui
)
5267 /* This is called after uses are set up and before stores are
5268 processed by cselib, so it's safe to look up srcs, but not
5269 dsts. So we look up expressions that appear in srcs or in
5270 dest expressions, but we search the sets array for dests of
5274 /* Some targets represent memset and memcpy patterns
5275 by (set (mem:BLK ...) (reg:[QHSD]I ...)) or
5276 (set (mem:BLK ...) (const_int ...)) or
5277 (set (mem:BLK ...) (mem:BLK ...)). Don't return anything
5278 in that case, otherwise we end up with mode mismatches. */
5279 if (mode
== BLKmode
&& MEM_P (x
))
5281 for (i
= 0; i
< cui
->n_sets
; i
++)
5282 if (cui
->sets
[i
].dest
== x
)
5283 return cui
->sets
[i
].src_elt
;
5286 return cselib_lookup (x
, mode
, 0, VOIDmode
);
5292 /* Replace all registers and addresses in an expression with VALUE
5293 expressions that map back to them, unless the expression is a
5294 register. If no mapping is or can be performed, returns NULL. */
5297 replace_expr_with_values (rtx loc
)
5299 if (REG_P (loc
) || GET_CODE (loc
) == ENTRY_VALUE
)
5301 else if (MEM_P (loc
))
5303 cselib_val
*addr
= cselib_lookup (XEXP (loc
, 0),
5304 get_address_mode (loc
), 0,
5307 return replace_equiv_address_nv (loc
, addr
->val_rtx
);
5312 return cselib_subst_to_values (loc
, VOIDmode
);
5315 /* Return true if *X is a DEBUG_EXPR. Usable as an argument to
5316 for_each_rtx to tell whether there are any DEBUG_EXPRs within
5320 rtx_debug_expr_p (rtx
*x
, void *data ATTRIBUTE_UNUSED
)
5324 return GET_CODE (loc
) == DEBUG_EXPR
;
5327 /* Determine what kind of micro operation to choose for a USE. Return
5328 MO_CLOBBER if no micro operation is to be generated. */
5330 static enum micro_operation_type
5331 use_type (rtx loc
, struct count_use_info
*cui
, enum machine_mode
*modep
)
5335 if (cui
&& cui
->sets
)
5337 if (GET_CODE (loc
) == VAR_LOCATION
)
5339 if (track_expr_p (PAT_VAR_LOCATION_DECL (loc
), false))
5341 rtx ploc
= PAT_VAR_LOCATION_LOC (loc
);
5342 if (! VAR_LOC_UNKNOWN_P (ploc
))
5344 cselib_val
*val
= cselib_lookup (ploc
, GET_MODE (loc
), 1,
5347 /* ??? flag_float_store and volatile mems are never
5348 given values, but we could in theory use them for
5350 gcc_assert (val
|| 1);
5358 if (REG_P (loc
) || MEM_P (loc
))
5361 *modep
= GET_MODE (loc
);
5365 || (find_use_val (loc
, GET_MODE (loc
), cui
)
5366 && cselib_lookup (XEXP (loc
, 0),
5367 get_address_mode (loc
), 0,
5373 cselib_val
*val
= find_use_val (loc
, GET_MODE (loc
), cui
);
5375 if (val
&& !cselib_preserved_value_p (val
))
5383 gcc_assert (REGNO (loc
) < FIRST_PSEUDO_REGISTER
);
5385 if (loc
== cfa_base_rtx
)
5387 expr
= REG_EXPR (loc
);
5390 return MO_USE_NO_VAR
;
5391 else if (target_for_debug_bind (var_debug_decl (expr
)))
5393 else if (track_loc_p (loc
, expr
, REG_OFFSET (loc
),
5394 false, modep
, NULL
))
5397 return MO_USE_NO_VAR
;
5399 else if (MEM_P (loc
))
5401 expr
= MEM_EXPR (loc
);
5405 else if (target_for_debug_bind (var_debug_decl (expr
)))
5407 else if (track_loc_p (loc
, expr
, INT_MEM_OFFSET (loc
),
5409 /* Multi-part variables shouldn't refer to one-part
5410 variable names such as VALUEs (never happens) or
5411 DEBUG_EXPRs (only happens in the presence of debug
5413 && (!MAY_HAVE_DEBUG_INSNS
5414 || !for_each_rtx (&XEXP (loc
, 0), rtx_debug_expr_p
, NULL
)))
5423 /* Log to OUT information about micro-operation MOPT involving X in
5427 log_op_type (rtx x
, basic_block bb
, rtx insn
,
5428 enum micro_operation_type mopt
, FILE *out
)
5430 fprintf (out
, "bb %i op %i insn %i %s ",
5431 bb
->index
, VTI (bb
)->mos
.length (),
5432 INSN_UID (insn
), micro_operation_type_name
[mopt
]);
5433 print_inline_rtx (out
, x
, 2);
5437 /* Tell whether the CONCAT used to holds a VALUE and its location
5438 needs value resolution, i.e., an attempt of mapping the location
5439 back to other incoming values. */
5440 #define VAL_NEEDS_RESOLUTION(x) \
5441 (RTL_FLAG_CHECK1 ("VAL_NEEDS_RESOLUTION", (x), CONCAT)->volatil)
5442 /* Whether the location in the CONCAT is a tracked expression, that
5443 should also be handled like a MO_USE. */
5444 #define VAL_HOLDS_TRACK_EXPR(x) \
5445 (RTL_FLAG_CHECK1 ("VAL_HOLDS_TRACK_EXPR", (x), CONCAT)->used)
5446 /* Whether the location in the CONCAT should be handled like a MO_COPY
5448 #define VAL_EXPR_IS_COPIED(x) \
5449 (RTL_FLAG_CHECK1 ("VAL_EXPR_IS_COPIED", (x), CONCAT)->jump)
5450 /* Whether the location in the CONCAT should be handled like a
5451 MO_CLOBBER as well. */
5452 #define VAL_EXPR_IS_CLOBBERED(x) \
5453 (RTL_FLAG_CHECK1 ("VAL_EXPR_IS_CLOBBERED", (x), CONCAT)->unchanging)
5455 /* All preserved VALUEs. */
5456 static vec
<rtx
> preserved_values
;
5458 /* Ensure VAL is preserved and remember it in a vector for vt_emit_notes. */
5461 preserve_value (cselib_val
*val
)
5463 cselib_preserve_value (val
);
5464 preserved_values
.safe_push (val
->val_rtx
);
5467 /* Helper function for MO_VAL_LOC handling. Return non-zero if
5468 any rtxes not suitable for CONST use not replaced by VALUEs
5472 non_suitable_const (rtx
*x
, void *data ATTRIBUTE_UNUSED
)
5477 switch (GET_CODE (*x
))
5488 return !MEM_READONLY_P (*x
);
5494 /* Add uses (register and memory references) LOC which will be tracked
5495 to VTI (bb)->mos. INSN is instruction which the LOC is part of. */
5498 add_uses (rtx
*ploc
, void *data
)
5501 enum machine_mode mode
= VOIDmode
;
5502 struct count_use_info
*cui
= (struct count_use_info
*)data
;
5503 enum micro_operation_type type
= use_type (loc
, cui
, &mode
);
5505 if (type
!= MO_CLOBBER
)
5507 basic_block bb
= cui
->bb
;
5511 mo
.u
.loc
= type
== MO_USE
? var_lowpart (mode
, loc
) : loc
;
5512 mo
.insn
= cui
->insn
;
5514 if (type
== MO_VAL_LOC
)
5517 rtx vloc
= PAT_VAR_LOCATION_LOC (oloc
);
5520 gcc_assert (cui
->sets
);
5523 && !REG_P (XEXP (vloc
, 0))
5524 && !MEM_P (XEXP (vloc
, 0)))
5527 enum machine_mode address_mode
= get_address_mode (mloc
);
5529 = cselib_lookup (XEXP (mloc
, 0), address_mode
, 0,
5532 if (val
&& !cselib_preserved_value_p (val
))
5533 preserve_value (val
);
5536 if (CONSTANT_P (vloc
)
5537 && (GET_CODE (vloc
) != CONST
5538 || for_each_rtx (&vloc
, non_suitable_const
, NULL
)))
5539 /* For constants don't look up any value. */;
5540 else if (!VAR_LOC_UNKNOWN_P (vloc
) && !unsuitable_loc (vloc
)
5541 && (val
= find_use_val (vloc
, GET_MODE (oloc
), cui
)))
5543 enum machine_mode mode2
;
5544 enum micro_operation_type type2
;
5546 bool resolvable
= REG_P (vloc
) || MEM_P (vloc
);
5549 nloc
= replace_expr_with_values (vloc
);
5553 oloc
= shallow_copy_rtx (oloc
);
5554 PAT_VAR_LOCATION_LOC (oloc
) = nloc
;
5557 oloc
= gen_rtx_CONCAT (mode
, val
->val_rtx
, oloc
);
5559 type2
= use_type (vloc
, 0, &mode2
);
5561 gcc_assert (type2
== MO_USE
|| type2
== MO_USE_NO_VAR
5562 || type2
== MO_CLOBBER
);
5564 if (type2
== MO_CLOBBER
5565 && !cselib_preserved_value_p (val
))
5567 VAL_NEEDS_RESOLUTION (oloc
) = resolvable
;
5568 preserve_value (val
);
5571 else if (!VAR_LOC_UNKNOWN_P (vloc
))
5573 oloc
= shallow_copy_rtx (oloc
);
5574 PAT_VAR_LOCATION_LOC (oloc
) = gen_rtx_UNKNOWN_VAR_LOC ();
5579 else if (type
== MO_VAL_USE
)
5581 enum machine_mode mode2
= VOIDmode
;
5582 enum micro_operation_type type2
;
5583 cselib_val
*val
= find_use_val (loc
, GET_MODE (loc
), cui
);
5584 rtx vloc
, oloc
= loc
, nloc
;
5586 gcc_assert (cui
->sets
);
5589 && !REG_P (XEXP (oloc
, 0))
5590 && !MEM_P (XEXP (oloc
, 0)))
5593 enum machine_mode address_mode
= get_address_mode (mloc
);
5595 = cselib_lookup (XEXP (mloc
, 0), address_mode
, 0,
5598 if (val
&& !cselib_preserved_value_p (val
))
5599 preserve_value (val
);
5602 type2
= use_type (loc
, 0, &mode2
);
5604 gcc_assert (type2
== MO_USE
|| type2
== MO_USE_NO_VAR
5605 || type2
== MO_CLOBBER
);
5607 if (type2
== MO_USE
)
5608 vloc
= var_lowpart (mode2
, loc
);
5612 /* The loc of a MO_VAL_USE may have two forms:
5614 (concat val src): val is at src, a value-based
5617 (concat (concat val use) src): same as above, with use as
5618 the MO_USE tracked value, if it differs from src.
5622 gcc_checking_assert (REG_P (loc
) || MEM_P (loc
));
5623 nloc
= replace_expr_with_values (loc
);
5628 oloc
= gen_rtx_CONCAT (mode2
, val
->val_rtx
, vloc
);
5630 oloc
= val
->val_rtx
;
5632 mo
.u
.loc
= gen_rtx_CONCAT (mode
, oloc
, nloc
);
5634 if (type2
== MO_USE
)
5635 VAL_HOLDS_TRACK_EXPR (mo
.u
.loc
) = 1;
5636 if (!cselib_preserved_value_p (val
))
5638 VAL_NEEDS_RESOLUTION (mo
.u
.loc
) = 1;
5639 preserve_value (val
);
5643 gcc_assert (type
== MO_USE
|| type
== MO_USE_NO_VAR
);
5645 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
5646 log_op_type (mo
.u
.loc
, cui
->bb
, cui
->insn
, mo
.type
, dump_file
);
5647 VTI (bb
)->mos
.safe_push (mo
);
5653 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
5656 add_uses_1 (rtx
*x
, void *cui
)
5658 for_each_rtx (x
, add_uses
, cui
);
5661 /* This is the value used during expansion of locations. We want it
5662 to be unbounded, so that variables expanded deep in a recursion
5663 nest are fully evaluated, so that their values are cached
5664 correctly. We avoid recursion cycles through other means, and we
5665 don't unshare RTL, so excess complexity is not a problem. */
5666 #define EXPR_DEPTH (INT_MAX)
5667 /* We use this to keep too-complex expressions from being emitted as
5668 location notes, and then to debug information. Users can trade
5669 compile time for ridiculously complex expressions, although they're
5670 seldom useful, and they may often have to be discarded as not
5671 representable anyway. */
5672 #define EXPR_USE_DEPTH (PARAM_VALUE (PARAM_MAX_VARTRACK_EXPR_DEPTH))
5674 /* Attempt to reverse the EXPR operation in the debug info and record
5675 it in the cselib table. Say for reg1 = reg2 + 6 even when reg2 is
5676 no longer live we can express its value as VAL - 6. */
5679 reverse_op (rtx val
, const_rtx expr
, rtx insn
)
5683 struct elt_loc_list
*l
;
5687 if (GET_CODE (expr
) != SET
)
5690 if (!REG_P (SET_DEST (expr
)) || GET_MODE (val
) != GET_MODE (SET_DEST (expr
)))
5693 src
= SET_SRC (expr
);
5694 switch (GET_CODE (src
))
5701 if (!REG_P (XEXP (src
, 0)))
5706 if (!REG_P (XEXP (src
, 0)) && !MEM_P (XEXP (src
, 0)))
5713 if (!SCALAR_INT_MODE_P (GET_MODE (src
)) || XEXP (src
, 0) == cfa_base_rtx
)
5716 v
= cselib_lookup (XEXP (src
, 0), GET_MODE (XEXP (src
, 0)), 0, VOIDmode
);
5717 if (!v
|| !cselib_preserved_value_p (v
))
5720 /* Use canonical V to avoid creating multiple redundant expressions
5721 for different VALUES equivalent to V. */
5722 v
= canonical_cselib_val (v
);
5724 /* Adding a reverse op isn't useful if V already has an always valid
5725 location. Ignore ENTRY_VALUE, while it is always constant, we should
5726 prefer non-ENTRY_VALUE locations whenever possible. */
5727 for (l
= v
->locs
, count
= 0; l
; l
= l
->next
, count
++)
5728 if (CONSTANT_P (l
->loc
)
5729 && (GET_CODE (l
->loc
) != CONST
|| !references_value_p (l
->loc
, 0)))
5731 /* Avoid creating too large locs lists. */
5732 else if (count
== PARAM_VALUE (PARAM_MAX_VARTRACK_REVERSE_OP_SIZE
))
5735 switch (GET_CODE (src
))
5739 if (GET_MODE (v
->val_rtx
) != GET_MODE (val
))
5741 ret
= gen_rtx_fmt_e (GET_CODE (src
), GET_MODE (val
), val
);
5745 ret
= gen_lowpart_SUBREG (GET_MODE (v
->val_rtx
), val
);
5757 if (GET_MODE (v
->val_rtx
) != GET_MODE (val
))
5759 arg
= XEXP (src
, 1);
5760 if (!CONST_INT_P (arg
) && GET_CODE (arg
) != SYMBOL_REF
)
5762 arg
= cselib_expand_value_rtx (arg
, scratch_regs
, 5);
5763 if (arg
== NULL_RTX
)
5765 if (!CONST_INT_P (arg
) && GET_CODE (arg
) != SYMBOL_REF
)
5768 ret
= simplify_gen_binary (code
, GET_MODE (val
), val
, arg
);
5770 /* Ensure ret isn't VALUE itself (which can happen e.g. for
5771 (plus (reg1) (reg2)) when reg2 is known to be 0), as that
5772 breaks a lot of routines during var-tracking. */
5773 ret
= gen_rtx_fmt_ee (PLUS
, GET_MODE (val
), val
, const0_rtx
);
5779 cselib_add_permanent_equiv (v
, ret
, insn
);
5782 /* Add stores (register and memory references) LOC which will be tracked
5783 to VTI (bb)->mos. EXPR is the RTL expression containing the store.
5784 CUIP->insn is instruction which the LOC is part of. */
5787 add_stores (rtx loc
, const_rtx expr
, void *cuip
)
5789 enum machine_mode mode
= VOIDmode
, mode2
;
5790 struct count_use_info
*cui
= (struct count_use_info
*)cuip
;
5791 basic_block bb
= cui
->bb
;
5793 rtx oloc
= loc
, nloc
, src
= NULL
;
5794 enum micro_operation_type type
= use_type (loc
, cui
, &mode
);
5795 bool track_p
= false;
5797 bool resolve
, preserve
;
5799 if (type
== MO_CLOBBER
)
5806 gcc_assert (loc
!= cfa_base_rtx
);
5807 if ((GET_CODE (expr
) == CLOBBER
&& type
!= MO_VAL_SET
)
5808 || !(track_p
= use_type (loc
, NULL
, &mode2
) == MO_USE
)
5809 || GET_CODE (expr
) == CLOBBER
)
5811 mo
.type
= MO_CLOBBER
;
5813 if (GET_CODE (expr
) == SET
5814 && SET_DEST (expr
) == loc
5815 && !unsuitable_loc (SET_SRC (expr
))
5816 && find_use_val (loc
, mode
, cui
))
5818 gcc_checking_assert (type
== MO_VAL_SET
);
5819 mo
.u
.loc
= gen_rtx_SET (VOIDmode
, loc
, SET_SRC (expr
));
5824 if (GET_CODE (expr
) == SET
5825 && SET_DEST (expr
) == loc
5826 && GET_CODE (SET_SRC (expr
)) != ASM_OPERANDS
)
5827 src
= var_lowpart (mode2
, SET_SRC (expr
));
5828 loc
= var_lowpart (mode2
, loc
);
5837 rtx xexpr
= gen_rtx_SET (VOIDmode
, loc
, src
);
5838 if (same_variable_part_p (src
, REG_EXPR (loc
), REG_OFFSET (loc
)))
5840 /* If this is an instruction copying (part of) a parameter
5841 passed by invisible reference to its register location,
5842 pretend it's a SET so that the initial memory location
5843 is discarded, as the parameter register can be reused
5844 for other purposes and we do not track locations based
5845 on generic registers. */
5848 && TREE_CODE (REG_EXPR (loc
)) == PARM_DECL
5849 && DECL_MODE (REG_EXPR (loc
)) != BLKmode
5850 && MEM_P (DECL_INCOMING_RTL (REG_EXPR (loc
)))
5851 && XEXP (DECL_INCOMING_RTL (REG_EXPR (loc
)), 0)
5862 mo
.insn
= cui
->insn
;
5864 else if (MEM_P (loc
)
5865 && ((track_p
= use_type (loc
, NULL
, &mode2
) == MO_USE
)
5868 if (MEM_P (loc
) && type
== MO_VAL_SET
5869 && !REG_P (XEXP (loc
, 0))
5870 && !MEM_P (XEXP (loc
, 0)))
5873 enum machine_mode address_mode
= get_address_mode (mloc
);
5874 cselib_val
*val
= cselib_lookup (XEXP (mloc
, 0),
5878 if (val
&& !cselib_preserved_value_p (val
))
5879 preserve_value (val
);
5882 if (GET_CODE (expr
) == CLOBBER
|| !track_p
)
5884 mo
.type
= MO_CLOBBER
;
5885 mo
.u
.loc
= track_p
? var_lowpart (mode2
, loc
) : loc
;
5889 if (GET_CODE (expr
) == SET
5890 && SET_DEST (expr
) == loc
5891 && GET_CODE (SET_SRC (expr
)) != ASM_OPERANDS
)
5892 src
= var_lowpart (mode2
, SET_SRC (expr
));
5893 loc
= var_lowpart (mode2
, loc
);
5902 rtx xexpr
= gen_rtx_SET (VOIDmode
, loc
, src
);
5903 if (same_variable_part_p (SET_SRC (xexpr
),
5905 INT_MEM_OFFSET (loc
)))
5912 mo
.insn
= cui
->insn
;
5917 if (type
!= MO_VAL_SET
)
5918 goto log_and_return
;
5920 v
= find_use_val (oloc
, mode
, cui
);
5923 goto log_and_return
;
5925 resolve
= preserve
= !cselib_preserved_value_p (v
);
5927 if (loc
== stack_pointer_rtx
5928 && hard_frame_pointer_adjustment
!= -1
5930 cselib_set_value_sp_based (v
);
5932 nloc
= replace_expr_with_values (oloc
);
5936 if (GET_CODE (PATTERN (cui
->insn
)) == COND_EXEC
)
5938 cselib_val
*oval
= cselib_lookup (oloc
, GET_MODE (oloc
), 0, VOIDmode
);
5940 gcc_assert (oval
!= v
);
5941 gcc_assert (REG_P (oloc
) || MEM_P (oloc
));
5943 if (oval
&& !cselib_preserved_value_p (oval
))
5945 micro_operation moa
;
5947 preserve_value (oval
);
5949 moa
.type
= MO_VAL_USE
;
5950 moa
.u
.loc
= gen_rtx_CONCAT (mode
, oval
->val_rtx
, oloc
);
5951 VAL_NEEDS_RESOLUTION (moa
.u
.loc
) = 1;
5952 moa
.insn
= cui
->insn
;
5954 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
5955 log_op_type (moa
.u
.loc
, cui
->bb
, cui
->insn
,
5956 moa
.type
, dump_file
);
5957 VTI (bb
)->mos
.safe_push (moa
);
5962 else if (resolve
&& GET_CODE (mo
.u
.loc
) == SET
)
5964 if (REG_P (SET_SRC (expr
)) || MEM_P (SET_SRC (expr
)))
5965 nloc
= replace_expr_with_values (SET_SRC (expr
));
5969 /* Avoid the mode mismatch between oexpr and expr. */
5970 if (!nloc
&& mode
!= mode2
)
5972 nloc
= SET_SRC (expr
);
5973 gcc_assert (oloc
== SET_DEST (expr
));
5976 if (nloc
&& nloc
!= SET_SRC (mo
.u
.loc
))
5977 oloc
= gen_rtx_SET (GET_MODE (mo
.u
.loc
), oloc
, nloc
);
5980 if (oloc
== SET_DEST (mo
.u
.loc
))
5981 /* No point in duplicating. */
5983 if (!REG_P (SET_SRC (mo
.u
.loc
)))
5989 if (GET_CODE (mo
.u
.loc
) == SET
5990 && oloc
== SET_DEST (mo
.u
.loc
))
5991 /* No point in duplicating. */
5997 loc
= gen_rtx_CONCAT (mode
, v
->val_rtx
, oloc
);
5999 if (mo
.u
.loc
!= oloc
)
6000 loc
= gen_rtx_CONCAT (GET_MODE (mo
.u
.loc
), loc
, mo
.u
.loc
);
6002 /* The loc of a MO_VAL_SET may have various forms:
6004 (concat val dst): dst now holds val
6006 (concat val (set dst src)): dst now holds val, copied from src
6008 (concat (concat val dstv) dst): dst now holds val; dstv is dst
6009 after replacing mems and non-top-level regs with values.
6011 (concat (concat val dstv) (set dst src)): dst now holds val,
6012 copied from src. dstv is a value-based representation of dst, if
6013 it differs from dst. If resolution is needed, src is a REG, and
6014 its mode is the same as that of val.
6016 (concat (concat val (set dstv srcv)) (set dst src)): src
6017 copied to dst, holding val. dstv and srcv are value-based
6018 representations of dst and src, respectively.
6022 if (GET_CODE (PATTERN (cui
->insn
)) != COND_EXEC
)
6023 reverse_op (v
->val_rtx
, expr
, cui
->insn
);
6028 VAL_HOLDS_TRACK_EXPR (loc
) = 1;
6031 VAL_NEEDS_RESOLUTION (loc
) = resolve
;
6034 if (mo
.type
== MO_CLOBBER
)
6035 VAL_EXPR_IS_CLOBBERED (loc
) = 1;
6036 if (mo
.type
== MO_COPY
)
6037 VAL_EXPR_IS_COPIED (loc
) = 1;
6039 mo
.type
= MO_VAL_SET
;
6042 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
6043 log_op_type (mo
.u
.loc
, cui
->bb
, cui
->insn
, mo
.type
, dump_file
);
6044 VTI (bb
)->mos
.safe_push (mo
);
6047 /* Arguments to the call. */
6048 static rtx call_arguments
;
6050 /* Compute call_arguments. */
6053 prepare_call_arguments (basic_block bb
, rtx insn
)
6056 rtx prev
, cur
, next
;
6057 rtx this_arg
= NULL_RTX
;
6058 tree type
= NULL_TREE
, t
, fndecl
= NULL_TREE
;
6059 tree obj_type_ref
= NULL_TREE
;
6060 CUMULATIVE_ARGS args_so_far_v
;
6061 cumulative_args_t args_so_far
;
6063 memset (&args_so_far_v
, 0, sizeof (args_so_far_v
));
6064 args_so_far
= pack_cumulative_args (&args_so_far_v
);
6065 call
= get_call_rtx_from (insn
);
6068 if (GET_CODE (XEXP (XEXP (call
, 0), 0)) == SYMBOL_REF
)
6070 rtx symbol
= XEXP (XEXP (call
, 0), 0);
6071 if (SYMBOL_REF_DECL (symbol
))
6072 fndecl
= SYMBOL_REF_DECL (symbol
);
6074 if (fndecl
== NULL_TREE
)
6075 fndecl
= MEM_EXPR (XEXP (call
, 0));
6077 && TREE_CODE (TREE_TYPE (fndecl
)) != FUNCTION_TYPE
6078 && TREE_CODE (TREE_TYPE (fndecl
)) != METHOD_TYPE
)
6080 if (fndecl
&& TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
6081 type
= TREE_TYPE (fndecl
);
6082 if (fndecl
&& TREE_CODE (fndecl
) != FUNCTION_DECL
)
6084 if (TREE_CODE (fndecl
) == INDIRECT_REF
6085 && TREE_CODE (TREE_OPERAND (fndecl
, 0)) == OBJ_TYPE_REF
)
6086 obj_type_ref
= TREE_OPERAND (fndecl
, 0);
6091 for (t
= TYPE_ARG_TYPES (type
); t
&& t
!= void_list_node
;
6093 if (TREE_CODE (TREE_VALUE (t
)) == REFERENCE_TYPE
6094 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_VALUE (t
))))
6096 if ((t
== NULL
|| t
== void_list_node
) && obj_type_ref
== NULL_TREE
)
6100 int nargs ATTRIBUTE_UNUSED
= list_length (TYPE_ARG_TYPES (type
));
6101 link
= CALL_INSN_FUNCTION_USAGE (insn
);
6102 #ifndef PCC_STATIC_STRUCT_RETURN
6103 if (aggregate_value_p (TREE_TYPE (type
), type
)
6104 && targetm
.calls
.struct_value_rtx (type
, 0) == 0)
6106 tree struct_addr
= build_pointer_type (TREE_TYPE (type
));
6107 enum machine_mode mode
= TYPE_MODE (struct_addr
);
6109 INIT_CUMULATIVE_ARGS (args_so_far_v
, type
, NULL_RTX
, fndecl
,
6111 reg
= targetm
.calls
.function_arg (args_so_far
, mode
,
6113 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
6115 if (reg
== NULL_RTX
)
6117 for (; link
; link
= XEXP (link
, 1))
6118 if (GET_CODE (XEXP (link
, 0)) == USE
6119 && MEM_P (XEXP (XEXP (link
, 0), 0)))
6121 link
= XEXP (link
, 1);
6128 INIT_CUMULATIVE_ARGS (args_so_far_v
, type
, NULL_RTX
, fndecl
,
6130 if (obj_type_ref
&& TYPE_ARG_TYPES (type
) != void_list_node
)
6132 enum machine_mode mode
;
6133 t
= TYPE_ARG_TYPES (type
);
6134 mode
= TYPE_MODE (TREE_VALUE (t
));
6135 this_arg
= targetm
.calls
.function_arg (args_so_far
, mode
,
6136 TREE_VALUE (t
), true);
6137 if (this_arg
&& !REG_P (this_arg
))
6138 this_arg
= NULL_RTX
;
6139 else if (this_arg
== NULL_RTX
)
6141 for (; link
; link
= XEXP (link
, 1))
6142 if (GET_CODE (XEXP (link
, 0)) == USE
6143 && MEM_P (XEXP (XEXP (link
, 0), 0)))
6145 this_arg
= XEXP (XEXP (link
, 0), 0);
6153 t
= type
? TYPE_ARG_TYPES (type
) : NULL_TREE
;
6155 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
6156 if (GET_CODE (XEXP (link
, 0)) == USE
)
6158 rtx item
= NULL_RTX
;
6159 x
= XEXP (XEXP (link
, 0), 0);
6160 if (GET_MODE (link
) == VOIDmode
6161 || GET_MODE (link
) == BLKmode
6162 || (GET_MODE (link
) != GET_MODE (x
)
6163 && (GET_MODE_CLASS (GET_MODE (link
)) != MODE_INT
6164 || GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
)))
6165 /* Can't do anything for these, if the original type mode
6166 isn't known or can't be converted. */;
6169 cselib_val
*val
= cselib_lookup (x
, GET_MODE (x
), 0, VOIDmode
);
6170 if (val
&& cselib_preserved_value_p (val
))
6171 item
= val
->val_rtx
;
6172 else if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_INT
)
6174 enum machine_mode mode
= GET_MODE (x
);
6176 while ((mode
= GET_MODE_WIDER_MODE (mode
)) != VOIDmode
6177 && GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
6179 rtx reg
= simplify_subreg (mode
, x
, GET_MODE (x
), 0);
6181 if (reg
== NULL_RTX
|| !REG_P (reg
))
6183 val
= cselib_lookup (reg
, mode
, 0, VOIDmode
);
6184 if (val
&& cselib_preserved_value_p (val
))
6186 item
= val
->val_rtx
;
6197 if (!frame_pointer_needed
)
6199 struct adjust_mem_data amd
;
6200 amd
.mem_mode
= VOIDmode
;
6201 amd
.stack_adjust
= -VTI (bb
)->out
.stack_adjust
;
6202 amd
.side_effects
= NULL_RTX
;
6204 mem
= simplify_replace_fn_rtx (mem
, NULL_RTX
, adjust_mems
,
6206 gcc_assert (amd
.side_effects
== NULL_RTX
);
6208 val
= cselib_lookup (mem
, GET_MODE (mem
), 0, VOIDmode
);
6209 if (val
&& cselib_preserved_value_p (val
))
6210 item
= val
->val_rtx
;
6211 else if (GET_MODE_CLASS (GET_MODE (mem
)) != MODE_INT
)
6213 /* For non-integer stack argument see also if they weren't
6214 initialized by integers. */
6215 enum machine_mode imode
= int_mode_for_mode (GET_MODE (mem
));
6216 if (imode
!= GET_MODE (mem
) && imode
!= BLKmode
)
6218 val
= cselib_lookup (adjust_address_nv (mem
, imode
, 0),
6219 imode
, 0, VOIDmode
);
6220 if (val
&& cselib_preserved_value_p (val
))
6221 item
= lowpart_subreg (GET_MODE (x
), val
->val_rtx
,
6229 if (GET_MODE (item
) != GET_MODE (link
))
6230 item
= lowpart_subreg (GET_MODE (link
), item
, GET_MODE (item
));
6231 if (GET_MODE (x2
) != GET_MODE (link
))
6232 x2
= lowpart_subreg (GET_MODE (link
), x2
, GET_MODE (x2
));
6233 item
= gen_rtx_CONCAT (GET_MODE (link
), x2
, item
);
6235 = gen_rtx_EXPR_LIST (VOIDmode
, item
, call_arguments
);
6237 if (t
&& t
!= void_list_node
)
6239 tree argtype
= TREE_VALUE (t
);
6240 enum machine_mode mode
= TYPE_MODE (argtype
);
6242 if (pass_by_reference (&args_so_far_v
, mode
, argtype
, true))
6244 argtype
= build_pointer_type (argtype
);
6245 mode
= TYPE_MODE (argtype
);
6247 reg
= targetm
.calls
.function_arg (args_so_far
, mode
,
6249 if (TREE_CODE (argtype
) == REFERENCE_TYPE
6250 && INTEGRAL_TYPE_P (TREE_TYPE (argtype
))
6253 && GET_MODE (reg
) == mode
6254 && GET_MODE_CLASS (mode
) == MODE_INT
6256 && REGNO (x
) == REGNO (reg
)
6257 && GET_MODE (x
) == mode
6260 enum machine_mode indmode
6261 = TYPE_MODE (TREE_TYPE (argtype
));
6262 rtx mem
= gen_rtx_MEM (indmode
, x
);
6263 cselib_val
*val
= cselib_lookup (mem
, indmode
, 0, VOIDmode
);
6264 if (val
&& cselib_preserved_value_p (val
))
6266 item
= gen_rtx_CONCAT (indmode
, mem
, val
->val_rtx
);
6267 call_arguments
= gen_rtx_EXPR_LIST (VOIDmode
, item
,
6272 struct elt_loc_list
*l
;
6275 /* Try harder, when passing address of a constant
6276 pool integer it can be easily read back. */
6277 item
= XEXP (item
, 1);
6278 if (GET_CODE (item
) == SUBREG
)
6279 item
= SUBREG_REG (item
);
6280 gcc_assert (GET_CODE (item
) == VALUE
);
6281 val
= CSELIB_VAL_PTR (item
);
6282 for (l
= val
->locs
; l
; l
= l
->next
)
6283 if (GET_CODE (l
->loc
) == SYMBOL_REF
6284 && TREE_CONSTANT_POOL_ADDRESS_P (l
->loc
)
6285 && SYMBOL_REF_DECL (l
->loc
)
6286 && DECL_INITIAL (SYMBOL_REF_DECL (l
->loc
)))
6288 initial
= DECL_INITIAL (SYMBOL_REF_DECL (l
->loc
));
6289 if (host_integerp (initial
, 0))
6291 item
= GEN_INT (tree_low_cst (initial
, 0));
6292 item
= gen_rtx_CONCAT (indmode
, mem
, item
);
6294 = gen_rtx_EXPR_LIST (VOIDmode
, item
,
6301 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
6307 /* Add debug arguments. */
6309 && TREE_CODE (fndecl
) == FUNCTION_DECL
6310 && DECL_HAS_DEBUG_ARGS_P (fndecl
))
6312 vec
<tree
, va_gc
> **debug_args
= decl_debug_args_lookup (fndecl
);
6317 for (ix
= 0; vec_safe_iterate (*debug_args
, ix
, ¶m
); ix
+= 2)
6320 tree dtemp
= (**debug_args
)[ix
+ 1];
6321 enum machine_mode mode
= DECL_MODE (dtemp
);
6322 item
= gen_rtx_DEBUG_PARAMETER_REF (mode
, param
);
6323 item
= gen_rtx_CONCAT (mode
, item
, DECL_RTL_KNOWN_SET (dtemp
));
6324 call_arguments
= gen_rtx_EXPR_LIST (VOIDmode
, item
,
6330 /* Reverse call_arguments chain. */
6332 for (cur
= call_arguments
; cur
; cur
= next
)
6334 next
= XEXP (cur
, 1);
6335 XEXP (cur
, 1) = prev
;
6338 call_arguments
= prev
;
6340 x
= get_call_rtx_from (insn
);
6343 x
= XEXP (XEXP (x
, 0), 0);
6344 if (GET_CODE (x
) == SYMBOL_REF
)
6345 /* Don't record anything. */;
6346 else if (CONSTANT_P (x
))
6348 x
= gen_rtx_CONCAT (GET_MODE (x
) == VOIDmode
? Pmode
: GET_MODE (x
),
6351 = gen_rtx_EXPR_LIST (VOIDmode
, x
, call_arguments
);
6355 cselib_val
*val
= cselib_lookup (x
, GET_MODE (x
), 0, VOIDmode
);
6356 if (val
&& cselib_preserved_value_p (val
))
6358 x
= gen_rtx_CONCAT (GET_MODE (x
), pc_rtx
, val
->val_rtx
);
6360 = gen_rtx_EXPR_LIST (VOIDmode
, x
, call_arguments
);
6366 enum machine_mode mode
6367 = TYPE_MODE (TREE_TYPE (OBJ_TYPE_REF_EXPR (obj_type_ref
)));
6368 rtx clobbered
= gen_rtx_MEM (mode
, this_arg
);
6370 = tree_low_cst (OBJ_TYPE_REF_TOKEN (obj_type_ref
), 0);
6372 clobbered
= plus_constant (mode
, clobbered
,
6373 token
* GET_MODE_SIZE (mode
));
6374 clobbered
= gen_rtx_MEM (mode
, clobbered
);
6375 x
= gen_rtx_CONCAT (mode
, gen_rtx_CLOBBER (VOIDmode
, pc_rtx
), clobbered
);
6377 = gen_rtx_EXPR_LIST (VOIDmode
, x
, call_arguments
);
6381 /* Callback for cselib_record_sets_hook, that records as micro
6382 operations uses and stores in an insn after cselib_record_sets has
6383 analyzed the sets in an insn, but before it modifies the stored
6384 values in the internal tables, unless cselib_record_sets doesn't
6385 call it directly (perhaps because we're not doing cselib in the
6386 first place, in which case sets and n_sets will be 0). */
6389 add_with_sets (rtx insn
, struct cselib_set
*sets
, int n_sets
)
6391 basic_block bb
= BLOCK_FOR_INSN (insn
);
6393 struct count_use_info cui
;
6394 micro_operation
*mos
;
6396 cselib_hook_called
= true;
6401 cui
.n_sets
= n_sets
;
6403 n1
= VTI (bb
)->mos
.length ();
6404 cui
.store_p
= false;
6405 note_uses (&PATTERN (insn
), add_uses_1
, &cui
);
6406 n2
= VTI (bb
)->mos
.length () - 1;
6407 mos
= VTI (bb
)->mos
.address ();
6409 /* Order the MO_USEs to be before MO_USE_NO_VARs and MO_VAL_USE, and
6413 while (n1
< n2
&& mos
[n1
].type
== MO_USE
)
6415 while (n1
< n2
&& mos
[n2
].type
!= MO_USE
)
6427 n2
= VTI (bb
)->mos
.length () - 1;
6430 while (n1
< n2
&& mos
[n1
].type
!= MO_VAL_LOC
)
6432 while (n1
< n2
&& mos
[n2
].type
== MO_VAL_LOC
)
6450 mo
.u
.loc
= call_arguments
;
6451 call_arguments
= NULL_RTX
;
6453 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
6454 log_op_type (PATTERN (insn
), bb
, insn
, mo
.type
, dump_file
);
6455 VTI (bb
)->mos
.safe_push (mo
);
6458 n1
= VTI (bb
)->mos
.length ();
6459 /* This will record NEXT_INSN (insn), such that we can
6460 insert notes before it without worrying about any
6461 notes that MO_USEs might emit after the insn. */
6463 note_stores (PATTERN (insn
), add_stores
, &cui
);
6464 n2
= VTI (bb
)->mos
.length () - 1;
6465 mos
= VTI (bb
)->mos
.address ();
6467 /* Order the MO_VAL_USEs first (note_stores does nothing
6468 on DEBUG_INSNs, so there are no MO_VAL_LOCs from this
6469 insn), then MO_CLOBBERs, then MO_SET/MO_COPY/MO_VAL_SET. */
6472 while (n1
< n2
&& mos
[n1
].type
== MO_VAL_USE
)
6474 while (n1
< n2
&& mos
[n2
].type
!= MO_VAL_USE
)
6486 n2
= VTI (bb
)->mos
.length () - 1;
6489 while (n1
< n2
&& mos
[n1
].type
== MO_CLOBBER
)
6491 while (n1
< n2
&& mos
[n2
].type
!= MO_CLOBBER
)
6504 static enum var_init_status
6505 find_src_status (dataflow_set
*in
, rtx src
)
6507 tree decl
= NULL_TREE
;
6508 enum var_init_status status
= VAR_INIT_STATUS_UNINITIALIZED
;
6510 if (! flag_var_tracking_uninit
)
6511 status
= VAR_INIT_STATUS_INITIALIZED
;
6513 if (src
&& REG_P (src
))
6514 decl
= var_debug_decl (REG_EXPR (src
));
6515 else if (src
&& MEM_P (src
))
6516 decl
= var_debug_decl (MEM_EXPR (src
));
6519 status
= get_init_value (in
, src
, dv_from_decl (decl
));
6524 /* SRC is the source of an assignment. Use SET to try to find what
6525 was ultimately assigned to SRC. Return that value if known,
6526 otherwise return SRC itself. */
6529 find_src_set_src (dataflow_set
*set
, rtx src
)
6531 tree decl
= NULL_TREE
; /* The variable being copied around. */
6532 rtx set_src
= NULL_RTX
; /* The value for "decl" stored in "src". */
6534 location_chain nextp
;
6538 if (src
&& REG_P (src
))
6539 decl
= var_debug_decl (REG_EXPR (src
));
6540 else if (src
&& MEM_P (src
))
6541 decl
= var_debug_decl (MEM_EXPR (src
));
6545 decl_or_value dv
= dv_from_decl (decl
);
6547 var
= shared_hash_find (set
->vars
, dv
);
6551 for (i
= 0; i
< var
->n_var_parts
&& !found
; i
++)
6552 for (nextp
= var
->var_part
[i
].loc_chain
; nextp
&& !found
;
6553 nextp
= nextp
->next
)
6554 if (rtx_equal_p (nextp
->loc
, src
))
6556 set_src
= nextp
->set_src
;
6566 /* Compute the changes of variable locations in the basic block BB. */
6569 compute_bb_dataflow (basic_block bb
)
6572 micro_operation
*mo
;
6574 dataflow_set old_out
;
6575 dataflow_set
*in
= &VTI (bb
)->in
;
6576 dataflow_set
*out
= &VTI (bb
)->out
;
6578 dataflow_set_init (&old_out
);
6579 dataflow_set_copy (&old_out
, out
);
6580 dataflow_set_copy (out
, in
);
6582 if (MAY_HAVE_DEBUG_INSNS
)
6583 local_get_addr_cache
= pointer_map_create ();
6585 FOR_EACH_VEC_ELT (VTI (bb
)->mos
, i
, mo
)
6587 rtx insn
= mo
->insn
;
6592 dataflow_set_clear_at_call (out
);
6597 rtx loc
= mo
->u
.loc
;
6600 var_reg_set (out
, loc
, VAR_INIT_STATUS_UNINITIALIZED
, NULL
);
6601 else if (MEM_P (loc
))
6602 var_mem_set (out
, loc
, VAR_INIT_STATUS_UNINITIALIZED
, NULL
);
6608 rtx loc
= mo
->u
.loc
;
6612 if (GET_CODE (loc
) == CONCAT
)
6614 val
= XEXP (loc
, 0);
6615 vloc
= XEXP (loc
, 1);
6623 var
= PAT_VAR_LOCATION_DECL (vloc
);
6625 clobber_variable_part (out
, NULL_RTX
,
6626 dv_from_decl (var
), 0, NULL_RTX
);
6629 if (VAL_NEEDS_RESOLUTION (loc
))
6630 val_resolve (out
, val
, PAT_VAR_LOCATION_LOC (vloc
), insn
);
6631 set_variable_part (out
, val
, dv_from_decl (var
), 0,
6632 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
,
6635 else if (!VAR_LOC_UNKNOWN_P (PAT_VAR_LOCATION_LOC (vloc
)))
6636 set_variable_part (out
, PAT_VAR_LOCATION_LOC (vloc
),
6637 dv_from_decl (var
), 0,
6638 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
,
6645 rtx loc
= mo
->u
.loc
;
6646 rtx val
, vloc
, uloc
;
6648 vloc
= uloc
= XEXP (loc
, 1);
6649 val
= XEXP (loc
, 0);
6651 if (GET_CODE (val
) == CONCAT
)
6653 uloc
= XEXP (val
, 1);
6654 val
= XEXP (val
, 0);
6657 if (VAL_NEEDS_RESOLUTION (loc
))
6658 val_resolve (out
, val
, vloc
, insn
);
6660 val_store (out
, val
, uloc
, insn
, false);
6662 if (VAL_HOLDS_TRACK_EXPR (loc
))
6664 if (GET_CODE (uloc
) == REG
)
6665 var_reg_set (out
, uloc
, VAR_INIT_STATUS_UNINITIALIZED
,
6667 else if (GET_CODE (uloc
) == MEM
)
6668 var_mem_set (out
, uloc
, VAR_INIT_STATUS_UNINITIALIZED
,
6676 rtx loc
= mo
->u
.loc
;
6677 rtx val
, vloc
, uloc
;
6681 uloc
= XEXP (vloc
, 1);
6682 val
= XEXP (vloc
, 0);
6685 if (GET_CODE (uloc
) == SET
)
6687 dstv
= SET_DEST (uloc
);
6688 srcv
= SET_SRC (uloc
);
6696 if (GET_CODE (val
) == CONCAT
)
6698 dstv
= vloc
= XEXP (val
, 1);
6699 val
= XEXP (val
, 0);
6702 if (GET_CODE (vloc
) == SET
)
6704 srcv
= SET_SRC (vloc
);
6706 gcc_assert (val
!= srcv
);
6707 gcc_assert (vloc
== uloc
|| VAL_NEEDS_RESOLUTION (loc
));
6709 dstv
= vloc
= SET_DEST (vloc
);
6711 if (VAL_NEEDS_RESOLUTION (loc
))
6712 val_resolve (out
, val
, srcv
, insn
);
6714 else if (VAL_NEEDS_RESOLUTION (loc
))
6716 gcc_assert (GET_CODE (uloc
) == SET
6717 && GET_CODE (SET_SRC (uloc
)) == REG
);
6718 val_resolve (out
, val
, SET_SRC (uloc
), insn
);
6721 if (VAL_HOLDS_TRACK_EXPR (loc
))
6723 if (VAL_EXPR_IS_CLOBBERED (loc
))
6726 var_reg_delete (out
, uloc
, true);
6727 else if (MEM_P (uloc
))
6729 gcc_assert (MEM_P (dstv
));
6730 gcc_assert (MEM_ATTRS (dstv
) == MEM_ATTRS (uloc
));
6731 var_mem_delete (out
, dstv
, true);
6736 bool copied_p
= VAL_EXPR_IS_COPIED (loc
);
6737 rtx src
= NULL
, dst
= uloc
;
6738 enum var_init_status status
= VAR_INIT_STATUS_INITIALIZED
;
6740 if (GET_CODE (uloc
) == SET
)
6742 src
= SET_SRC (uloc
);
6743 dst
= SET_DEST (uloc
);
6748 if (flag_var_tracking_uninit
)
6750 status
= find_src_status (in
, src
);
6752 if (status
== VAR_INIT_STATUS_UNKNOWN
)
6753 status
= find_src_status (out
, src
);
6756 src
= find_src_set_src (in
, src
);
6760 var_reg_delete_and_set (out
, dst
, !copied_p
,
6762 else if (MEM_P (dst
))
6764 gcc_assert (MEM_P (dstv
));
6765 gcc_assert (MEM_ATTRS (dstv
) == MEM_ATTRS (dst
));
6766 var_mem_delete_and_set (out
, dstv
, !copied_p
,
6771 else if (REG_P (uloc
))
6772 var_regno_delete (out
, REGNO (uloc
));
6773 else if (MEM_P (uloc
))
6775 gcc_checking_assert (GET_CODE (vloc
) == MEM
);
6776 gcc_checking_assert (dstv
== vloc
);
6778 clobber_overlapping_mems (out
, vloc
);
6781 val_store (out
, val
, dstv
, insn
, true);
6787 rtx loc
= mo
->u
.loc
;
6790 if (GET_CODE (loc
) == SET
)
6792 set_src
= SET_SRC (loc
);
6793 loc
= SET_DEST (loc
);
6797 var_reg_delete_and_set (out
, loc
, true, VAR_INIT_STATUS_INITIALIZED
,
6799 else if (MEM_P (loc
))
6800 var_mem_delete_and_set (out
, loc
, true, VAR_INIT_STATUS_INITIALIZED
,
6807 rtx loc
= mo
->u
.loc
;
6808 enum var_init_status src_status
;
6811 if (GET_CODE (loc
) == SET
)
6813 set_src
= SET_SRC (loc
);
6814 loc
= SET_DEST (loc
);
6817 if (! flag_var_tracking_uninit
)
6818 src_status
= VAR_INIT_STATUS_INITIALIZED
;
6821 src_status
= find_src_status (in
, set_src
);
6823 if (src_status
== VAR_INIT_STATUS_UNKNOWN
)
6824 src_status
= find_src_status (out
, set_src
);
6827 set_src
= find_src_set_src (in
, set_src
);
6830 var_reg_delete_and_set (out
, loc
, false, src_status
, set_src
);
6831 else if (MEM_P (loc
))
6832 var_mem_delete_and_set (out
, loc
, false, src_status
, set_src
);
6838 rtx loc
= mo
->u
.loc
;
6841 var_reg_delete (out
, loc
, false);
6842 else if (MEM_P (loc
))
6843 var_mem_delete (out
, loc
, false);
6849 rtx loc
= mo
->u
.loc
;
6852 var_reg_delete (out
, loc
, true);
6853 else if (MEM_P (loc
))
6854 var_mem_delete (out
, loc
, true);
6859 out
->stack_adjust
+= mo
->u
.adjust
;
6864 if (MAY_HAVE_DEBUG_INSNS
)
6866 pointer_map_destroy (local_get_addr_cache
);
6867 local_get_addr_cache
= NULL
;
6869 dataflow_set_equiv_regs (out
);
6870 shared_hash_htab (out
->vars
)
6871 .traverse
<dataflow_set
*, canonicalize_values_mark
> (out
);
6872 shared_hash_htab (out
->vars
)
6873 .traverse
<dataflow_set
*, canonicalize_values_star
> (out
);
6875 shared_hash_htab (out
->vars
)
6876 .traverse
<dataflow_set
*, canonicalize_loc_order_check
> (out
);
6879 changed
= dataflow_set_different (&old_out
, out
);
6880 dataflow_set_destroy (&old_out
);
6884 /* Find the locations of variables in the whole function. */
6887 vt_find_locations (void)
6889 fibheap_t worklist
, pending
, fibheap_swap
;
6890 sbitmap visited
, in_worklist
, in_pending
, sbitmap_swap
;
6897 int htabmax
= PARAM_VALUE (PARAM_MAX_VARTRACK_SIZE
);
6898 bool success
= true;
6900 timevar_push (TV_VAR_TRACKING_DATAFLOW
);
6901 /* Compute reverse completion order of depth first search of the CFG
6902 so that the data-flow runs faster. */
6903 rc_order
= XNEWVEC (int, n_basic_blocks
- NUM_FIXED_BLOCKS
);
6904 bb_order
= XNEWVEC (int, last_basic_block
);
6905 pre_and_rev_post_order_compute (NULL
, rc_order
, false);
6906 for (i
= 0; i
< n_basic_blocks
- NUM_FIXED_BLOCKS
; i
++)
6907 bb_order
[rc_order
[i
]] = i
;
6910 worklist
= fibheap_new ();
6911 pending
= fibheap_new ();
6912 visited
= sbitmap_alloc (last_basic_block
);
6913 in_worklist
= sbitmap_alloc (last_basic_block
);
6914 in_pending
= sbitmap_alloc (last_basic_block
);
6915 bitmap_clear (in_worklist
);
6918 fibheap_insert (pending
, bb_order
[bb
->index
], bb
);
6919 bitmap_ones (in_pending
);
6921 while (success
&& !fibheap_empty (pending
))
6923 fibheap_swap
= pending
;
6925 worklist
= fibheap_swap
;
6926 sbitmap_swap
= in_pending
;
6927 in_pending
= in_worklist
;
6928 in_worklist
= sbitmap_swap
;
6930 bitmap_clear (visited
);
6932 while (!fibheap_empty (worklist
))
6934 bb
= (basic_block
) fibheap_extract_min (worklist
);
6935 bitmap_clear_bit (in_worklist
, bb
->index
);
6936 gcc_assert (!bitmap_bit_p (visited
, bb
->index
));
6937 if (!bitmap_bit_p (visited
, bb
->index
))
6941 int oldinsz
, oldoutsz
;
6943 bitmap_set_bit (visited
, bb
->index
);
6945 if (VTI (bb
)->in
.vars
)
6948 -= shared_hash_htab (VTI (bb
)->in
.vars
).size ()
6949 + shared_hash_htab (VTI (bb
)->out
.vars
).size ();
6950 oldinsz
= shared_hash_htab (VTI (bb
)->in
.vars
).elements ();
6951 oldoutsz
= shared_hash_htab (VTI (bb
)->out
.vars
).elements ();
6954 oldinsz
= oldoutsz
= 0;
6956 if (MAY_HAVE_DEBUG_INSNS
)
6958 dataflow_set
*in
= &VTI (bb
)->in
, *first_out
= NULL
;
6959 bool first
= true, adjust
= false;
6961 /* Calculate the IN set as the intersection of
6962 predecessor OUT sets. */
6964 dataflow_set_clear (in
);
6965 dst_can_be_shared
= true;
6967 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
6968 if (!VTI (e
->src
)->flooded
)
6969 gcc_assert (bb_order
[bb
->index
]
6970 <= bb_order
[e
->src
->index
]);
6973 dataflow_set_copy (in
, &VTI (e
->src
)->out
);
6974 first_out
= &VTI (e
->src
)->out
;
6979 dataflow_set_merge (in
, &VTI (e
->src
)->out
);
6985 dataflow_post_merge_adjust (in
, &VTI (bb
)->permp
);
6987 /* Merge and merge_adjust should keep entries in
6989 shared_hash_htab (in
->vars
)
6990 .traverse
<dataflow_set
*,
6991 canonicalize_loc_order_check
> (in
);
6993 if (dst_can_be_shared
)
6995 shared_hash_destroy (in
->vars
);
6996 in
->vars
= shared_hash_copy (first_out
->vars
);
7000 VTI (bb
)->flooded
= true;
7004 /* Calculate the IN set as union of predecessor OUT sets. */
7005 dataflow_set_clear (&VTI (bb
)->in
);
7006 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
7007 dataflow_set_union (&VTI (bb
)->in
, &VTI (e
->src
)->out
);
7010 changed
= compute_bb_dataflow (bb
);
7011 htabsz
+= shared_hash_htab (VTI (bb
)->in
.vars
).size ()
7012 + shared_hash_htab (VTI (bb
)->out
.vars
).size ();
7014 if (htabmax
&& htabsz
> htabmax
)
7016 if (MAY_HAVE_DEBUG_INSNS
)
7017 inform (DECL_SOURCE_LOCATION (cfun
->decl
),
7018 "variable tracking size limit exceeded with "
7019 "-fvar-tracking-assignments, retrying without");
7021 inform (DECL_SOURCE_LOCATION (cfun
->decl
),
7022 "variable tracking size limit exceeded");
7029 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
7031 if (e
->dest
== EXIT_BLOCK_PTR
)
7034 if (bitmap_bit_p (visited
, e
->dest
->index
))
7036 if (!bitmap_bit_p (in_pending
, e
->dest
->index
))
7038 /* Send E->DEST to next round. */
7039 bitmap_set_bit (in_pending
, e
->dest
->index
);
7040 fibheap_insert (pending
,
7041 bb_order
[e
->dest
->index
],
7045 else if (!bitmap_bit_p (in_worklist
, e
->dest
->index
))
7047 /* Add E->DEST to current round. */
7048 bitmap_set_bit (in_worklist
, e
->dest
->index
);
7049 fibheap_insert (worklist
, bb_order
[e
->dest
->index
],
7057 "BB %i: in %i (was %i), out %i (was %i), rem %i + %i, tsz %i\n",
7059 (int)shared_hash_htab (VTI (bb
)->in
.vars
).size (),
7061 (int)shared_hash_htab (VTI (bb
)->out
.vars
).size (),
7063 (int)worklist
->nodes
, (int)pending
->nodes
, htabsz
);
7065 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
7067 fprintf (dump_file
, "BB %i IN:\n", bb
->index
);
7068 dump_dataflow_set (&VTI (bb
)->in
);
7069 fprintf (dump_file
, "BB %i OUT:\n", bb
->index
);
7070 dump_dataflow_set (&VTI (bb
)->out
);
7076 if (success
&& MAY_HAVE_DEBUG_INSNS
)
7078 gcc_assert (VTI (bb
)->flooded
);
7081 fibheap_delete (worklist
);
7082 fibheap_delete (pending
);
7083 sbitmap_free (visited
);
7084 sbitmap_free (in_worklist
);
7085 sbitmap_free (in_pending
);
7087 timevar_pop (TV_VAR_TRACKING_DATAFLOW
);
7091 /* Print the content of the LIST to dump file. */
7094 dump_attrs_list (attrs list
)
7096 for (; list
; list
= list
->next
)
7098 if (dv_is_decl_p (list
->dv
))
7099 print_mem_expr (dump_file
, dv_as_decl (list
->dv
));
7101 print_rtl_single (dump_file
, dv_as_value (list
->dv
));
7102 fprintf (dump_file
, "+" HOST_WIDE_INT_PRINT_DEC
, list
->offset
);
7104 fprintf (dump_file
, "\n");
7107 /* Print the information about variable *SLOT to dump file. */
7110 dump_var_tracking_slot (variable_def
**slot
, void *data ATTRIBUTE_UNUSED
)
7112 variable var
= *slot
;
7116 /* Continue traversing the hash table. */
7120 /* Print the information about variable VAR to dump file. */
7123 dump_var (variable var
)
7126 location_chain node
;
7128 if (dv_is_decl_p (var
->dv
))
7130 const_tree decl
= dv_as_decl (var
->dv
);
7132 if (DECL_NAME (decl
))
7134 fprintf (dump_file
, " name: %s",
7135 IDENTIFIER_POINTER (DECL_NAME (decl
)));
7136 if (dump_flags
& TDF_UID
)
7137 fprintf (dump_file
, "D.%u", DECL_UID (decl
));
7139 else if (TREE_CODE (decl
) == DEBUG_EXPR_DECL
)
7140 fprintf (dump_file
, " name: D#%u", DEBUG_TEMP_UID (decl
));
7142 fprintf (dump_file
, " name: D.%u", DECL_UID (decl
));
7143 fprintf (dump_file
, "\n");
7147 fputc (' ', dump_file
);
7148 print_rtl_single (dump_file
, dv_as_value (var
->dv
));
7151 for (i
= 0; i
< var
->n_var_parts
; i
++)
7153 fprintf (dump_file
, " offset %ld\n",
7154 (long)(var
->onepart
? 0 : VAR_PART_OFFSET (var
, i
)));
7155 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
7157 fprintf (dump_file
, " ");
7158 if (node
->init
== VAR_INIT_STATUS_UNINITIALIZED
)
7159 fprintf (dump_file
, "[uninit]");
7160 print_rtl_single (dump_file
, node
->loc
);
7165 /* Print the information about variables from hash table VARS to dump file. */
7168 dump_vars (variable_table_type vars
)
7170 if (vars
.elements () > 0)
7172 fprintf (dump_file
, "Variables:\n");
7173 vars
.traverse
<void *, dump_var_tracking_slot
> (NULL
);
7177 /* Print the dataflow set SET to dump file. */
7180 dump_dataflow_set (dataflow_set
*set
)
7184 fprintf (dump_file
, "Stack adjustment: " HOST_WIDE_INT_PRINT_DEC
"\n",
7186 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
7190 fprintf (dump_file
, "Reg %d:", i
);
7191 dump_attrs_list (set
->regs
[i
]);
7194 dump_vars (shared_hash_htab (set
->vars
));
7195 fprintf (dump_file
, "\n");
7198 /* Print the IN and OUT sets for each basic block to dump file. */
7201 dump_dataflow_sets (void)
7207 fprintf (dump_file
, "\nBasic block %d:\n", bb
->index
);
7208 fprintf (dump_file
, "IN:\n");
7209 dump_dataflow_set (&VTI (bb
)->in
);
7210 fprintf (dump_file
, "OUT:\n");
7211 dump_dataflow_set (&VTI (bb
)->out
);
7215 /* Return the variable for DV in dropped_values, inserting one if
7216 requested with INSERT. */
7218 static inline variable
7219 variable_from_dropped (decl_or_value dv
, enum insert_option insert
)
7221 variable_def
**slot
;
7223 onepart_enum_t onepart
;
7225 slot
= dropped_values
.find_slot_with_hash (dv
, dv_htab_hash (dv
), insert
);
7233 gcc_checking_assert (insert
== INSERT
);
7235 onepart
= dv_onepart_p (dv
);
7237 gcc_checking_assert (onepart
== ONEPART_VALUE
|| onepart
== ONEPART_DEXPR
);
7239 empty_var
= (variable
) pool_alloc (onepart_pool (onepart
));
7241 empty_var
->refcount
= 1;
7242 empty_var
->n_var_parts
= 0;
7243 empty_var
->onepart
= onepart
;
7244 empty_var
->in_changed_variables
= false;
7245 empty_var
->var_part
[0].loc_chain
= NULL
;
7246 empty_var
->var_part
[0].cur_loc
= NULL
;
7247 VAR_LOC_1PAUX (empty_var
) = NULL
;
7248 set_dv_changed (dv
, true);
7255 /* Recover the one-part aux from dropped_values. */
7257 static struct onepart_aux
*
7258 recover_dropped_1paux (variable var
)
7262 gcc_checking_assert (var
->onepart
);
7264 if (VAR_LOC_1PAUX (var
))
7265 return VAR_LOC_1PAUX (var
);
7267 if (var
->onepart
== ONEPART_VDECL
)
7270 dvar
= variable_from_dropped (var
->dv
, NO_INSERT
);
7275 VAR_LOC_1PAUX (var
) = VAR_LOC_1PAUX (dvar
);
7276 VAR_LOC_1PAUX (dvar
) = NULL
;
7278 return VAR_LOC_1PAUX (var
);
7281 /* Add variable VAR to the hash table of changed variables and
7282 if it has no locations delete it from SET's hash table. */
7285 variable_was_changed (variable var
, dataflow_set
*set
)
7287 hashval_t hash
= dv_htab_hash (var
->dv
);
7291 variable_def
**slot
;
7293 /* Remember this decl or VALUE has been added to changed_variables. */
7294 set_dv_changed (var
->dv
, true);
7296 slot
= changed_variables
.find_slot_with_hash (var
->dv
, hash
, INSERT
);
7300 variable old_var
= *slot
;
7301 gcc_assert (old_var
->in_changed_variables
);
7302 old_var
->in_changed_variables
= false;
7303 if (var
!= old_var
&& var
->onepart
)
7305 /* Restore the auxiliary info from an empty variable
7306 previously created for changed_variables, so it is
7308 gcc_checking_assert (!VAR_LOC_1PAUX (var
));
7309 VAR_LOC_1PAUX (var
) = VAR_LOC_1PAUX (old_var
);
7310 VAR_LOC_1PAUX (old_var
) = NULL
;
7312 variable_htab_free (*slot
);
7315 if (set
&& var
->n_var_parts
== 0)
7317 onepart_enum_t onepart
= var
->onepart
;
7318 variable empty_var
= NULL
;
7319 variable_def
**dslot
= NULL
;
7321 if (onepart
== ONEPART_VALUE
|| onepart
== ONEPART_DEXPR
)
7323 dslot
= dropped_values
.find_slot_with_hash (var
->dv
,
7324 dv_htab_hash (var
->dv
),
7330 gcc_checking_assert (!empty_var
->in_changed_variables
);
7331 if (!VAR_LOC_1PAUX (var
))
7333 VAR_LOC_1PAUX (var
) = VAR_LOC_1PAUX (empty_var
);
7334 VAR_LOC_1PAUX (empty_var
) = NULL
;
7337 gcc_checking_assert (!VAR_LOC_1PAUX (empty_var
));
7343 empty_var
= (variable
) pool_alloc (onepart_pool (onepart
));
7344 empty_var
->dv
= var
->dv
;
7345 empty_var
->refcount
= 1;
7346 empty_var
->n_var_parts
= 0;
7347 empty_var
->onepart
= onepart
;
7350 empty_var
->refcount
++;
7355 empty_var
->refcount
++;
7356 empty_var
->in_changed_variables
= true;
7360 empty_var
->var_part
[0].loc_chain
= NULL
;
7361 empty_var
->var_part
[0].cur_loc
= NULL
;
7362 VAR_LOC_1PAUX (empty_var
) = VAR_LOC_1PAUX (var
);
7363 VAR_LOC_1PAUX (var
) = NULL
;
7369 if (var
->onepart
&& !VAR_LOC_1PAUX (var
))
7370 recover_dropped_1paux (var
);
7372 var
->in_changed_variables
= true;
7379 if (var
->n_var_parts
== 0)
7381 variable_def
**slot
;
7384 slot
= shared_hash_find_slot_noinsert (set
->vars
, var
->dv
);
7387 if (shared_hash_shared (set
->vars
))
7388 slot
= shared_hash_find_slot_unshare (&set
->vars
, var
->dv
,
7390 shared_hash_htab (set
->vars
).clear_slot (slot
);
7396 /* Look for the index in VAR->var_part corresponding to OFFSET.
7397 Return -1 if not found. If INSERTION_POINT is non-NULL, the
7398 referenced int will be set to the index that the part has or should
7399 have, if it should be inserted. */
7402 find_variable_location_part (variable var
, HOST_WIDE_INT offset
,
7403 int *insertion_point
)
7412 if (insertion_point
)
7413 *insertion_point
= 0;
7415 return var
->n_var_parts
- 1;
7418 /* Find the location part. */
7420 high
= var
->n_var_parts
;
7423 pos
= (low
+ high
) / 2;
7424 if (VAR_PART_OFFSET (var
, pos
) < offset
)
7431 if (insertion_point
)
7432 *insertion_point
= pos
;
7434 if (pos
< var
->n_var_parts
&& VAR_PART_OFFSET (var
, pos
) == offset
)
7440 static variable_def
**
7441 set_slot_part (dataflow_set
*set
, rtx loc
, variable_def
**slot
,
7442 decl_or_value dv
, HOST_WIDE_INT offset
,
7443 enum var_init_status initialized
, rtx set_src
)
7446 location_chain node
, next
;
7447 location_chain
*nextp
;
7449 onepart_enum_t onepart
;
7454 onepart
= var
->onepart
;
7456 onepart
= dv_onepart_p (dv
);
7458 gcc_checking_assert (offset
== 0 || !onepart
);
7459 gcc_checking_assert (loc
!= dv_as_opaque (dv
));
7461 if (! flag_var_tracking_uninit
)
7462 initialized
= VAR_INIT_STATUS_INITIALIZED
;
7466 /* Create new variable information. */
7467 var
= (variable
) pool_alloc (onepart_pool (onepart
));
7470 var
->n_var_parts
= 1;
7471 var
->onepart
= onepart
;
7472 var
->in_changed_variables
= false;
7474 VAR_LOC_1PAUX (var
) = NULL
;
7476 VAR_PART_OFFSET (var
, 0) = offset
;
7477 var
->var_part
[0].loc_chain
= NULL
;
7478 var
->var_part
[0].cur_loc
= NULL
;
7481 nextp
= &var
->var_part
[0].loc_chain
;
7487 gcc_assert (dv_as_opaque (var
->dv
) == dv_as_opaque (dv
));
7491 if (GET_CODE (loc
) == VALUE
)
7493 for (nextp
= &var
->var_part
[0].loc_chain
; (node
= *nextp
);
7494 nextp
= &node
->next
)
7495 if (GET_CODE (node
->loc
) == VALUE
)
7497 if (node
->loc
== loc
)
7502 if (canon_value_cmp (node
->loc
, loc
))
7510 else if (REG_P (node
->loc
) || MEM_P (node
->loc
))
7518 else if (REG_P (loc
))
7520 for (nextp
= &var
->var_part
[0].loc_chain
; (node
= *nextp
);
7521 nextp
= &node
->next
)
7522 if (REG_P (node
->loc
))
7524 if (REGNO (node
->loc
) < REGNO (loc
))
7528 if (REGNO (node
->loc
) == REGNO (loc
))
7541 else if (MEM_P (loc
))
7543 for (nextp
= &var
->var_part
[0].loc_chain
; (node
= *nextp
);
7544 nextp
= &node
->next
)
7545 if (REG_P (node
->loc
))
7547 else if (MEM_P (node
->loc
))
7549 if ((r
= loc_cmp (XEXP (node
->loc
, 0), XEXP (loc
, 0))) >= 0)
7561 for (nextp
= &var
->var_part
[0].loc_chain
; (node
= *nextp
);
7562 nextp
= &node
->next
)
7563 if ((r
= loc_cmp (node
->loc
, loc
)) >= 0)
7571 if (shared_var_p (var
, set
->vars
))
7573 slot
= unshare_variable (set
, slot
, var
, initialized
);
7575 for (nextp
= &var
->var_part
[0].loc_chain
; c
;
7576 nextp
= &(*nextp
)->next
)
7578 gcc_assert ((!node
&& !*nextp
) || node
->loc
== (*nextp
)->loc
);
7585 gcc_assert (dv_as_decl (var
->dv
) == dv_as_decl (dv
));
7587 pos
= find_variable_location_part (var
, offset
, &inspos
);
7591 node
= var
->var_part
[pos
].loc_chain
;
7594 && ((REG_P (node
->loc
) && REG_P (loc
)
7595 && REGNO (node
->loc
) == REGNO (loc
))
7596 || rtx_equal_p (node
->loc
, loc
)))
7598 /* LOC is in the beginning of the chain so we have nothing
7600 if (node
->init
< initialized
)
7601 node
->init
= initialized
;
7602 if (set_src
!= NULL
)
7603 node
->set_src
= set_src
;
7609 /* We have to make a copy of a shared variable. */
7610 if (shared_var_p (var
, set
->vars
))
7612 slot
= unshare_variable (set
, slot
, var
, initialized
);
7619 /* We have not found the location part, new one will be created. */
7621 /* We have to make a copy of the shared variable. */
7622 if (shared_var_p (var
, set
->vars
))
7624 slot
= unshare_variable (set
, slot
, var
, initialized
);
7628 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
7629 thus there are at most MAX_VAR_PARTS different offsets. */
7630 gcc_assert (var
->n_var_parts
< MAX_VAR_PARTS
7631 && (!var
->n_var_parts
|| !onepart
));
7633 /* We have to move the elements of array starting at index
7634 inspos to the next position. */
7635 for (pos
= var
->n_var_parts
; pos
> inspos
; pos
--)
7636 var
->var_part
[pos
] = var
->var_part
[pos
- 1];
7639 gcc_checking_assert (!onepart
);
7640 VAR_PART_OFFSET (var
, pos
) = offset
;
7641 var
->var_part
[pos
].loc_chain
= NULL
;
7642 var
->var_part
[pos
].cur_loc
= NULL
;
7645 /* Delete the location from the list. */
7646 nextp
= &var
->var_part
[pos
].loc_chain
;
7647 for (node
= var
->var_part
[pos
].loc_chain
; node
; node
= next
)
7650 if ((REG_P (node
->loc
) && REG_P (loc
)
7651 && REGNO (node
->loc
) == REGNO (loc
))
7652 || rtx_equal_p (node
->loc
, loc
))
7654 /* Save these values, to assign to the new node, before
7655 deleting this one. */
7656 if (node
->init
> initialized
)
7657 initialized
= node
->init
;
7658 if (node
->set_src
!= NULL
&& set_src
== NULL
)
7659 set_src
= node
->set_src
;
7660 if (var
->var_part
[pos
].cur_loc
== node
->loc
)
7661 var
->var_part
[pos
].cur_loc
= NULL
;
7662 pool_free (loc_chain_pool
, node
);
7667 nextp
= &node
->next
;
7670 nextp
= &var
->var_part
[pos
].loc_chain
;
7673 /* Add the location to the beginning. */
7674 node
= (location_chain
) pool_alloc (loc_chain_pool
);
7676 node
->init
= initialized
;
7677 node
->set_src
= set_src
;
7678 node
->next
= *nextp
;
7681 /* If no location was emitted do so. */
7682 if (var
->var_part
[pos
].cur_loc
== NULL
)
7683 variable_was_changed (var
, set
);
7688 /* Set the part of variable's location in the dataflow set SET. The
7689 variable part is specified by variable's declaration in DV and
7690 offset OFFSET and the part's location by LOC. IOPT should be
7691 NO_INSERT if the variable is known to be in SET already and the
7692 variable hash table must not be resized, and INSERT otherwise. */
7695 set_variable_part (dataflow_set
*set
, rtx loc
,
7696 decl_or_value dv
, HOST_WIDE_INT offset
,
7697 enum var_init_status initialized
, rtx set_src
,
7698 enum insert_option iopt
)
7700 variable_def
**slot
;
7702 if (iopt
== NO_INSERT
)
7703 slot
= shared_hash_find_slot_noinsert (set
->vars
, dv
);
7706 slot
= shared_hash_find_slot (set
->vars
, dv
);
7708 slot
= shared_hash_find_slot_unshare (&set
->vars
, dv
, iopt
);
7710 set_slot_part (set
, loc
, slot
, dv
, offset
, initialized
, set_src
);
7713 /* Remove all recorded register locations for the given variable part
7714 from dataflow set SET, except for those that are identical to loc.
7715 The variable part is specified by variable's declaration or value
7716 DV and offset OFFSET. */
7718 static variable_def
**
7719 clobber_slot_part (dataflow_set
*set
, rtx loc
, variable_def
**slot
,
7720 HOST_WIDE_INT offset
, rtx set_src
)
7722 variable var
= *slot
;
7723 int pos
= find_variable_location_part (var
, offset
, NULL
);
7727 location_chain node
, next
;
7729 /* Remove the register locations from the dataflow set. */
7730 next
= var
->var_part
[pos
].loc_chain
;
7731 for (node
= next
; node
; node
= next
)
7734 if (node
->loc
!= loc
7735 && (!flag_var_tracking_uninit
7738 || !rtx_equal_p (set_src
, node
->set_src
)))
7740 if (REG_P (node
->loc
))
7745 /* Remove the variable part from the register's
7746 list, but preserve any other variable parts
7747 that might be regarded as live in that same
7749 anextp
= &set
->regs
[REGNO (node
->loc
)];
7750 for (anode
= *anextp
; anode
; anode
= anext
)
7752 anext
= anode
->next
;
7753 if (dv_as_opaque (anode
->dv
) == dv_as_opaque (var
->dv
)
7754 && anode
->offset
== offset
)
7756 pool_free (attrs_pool
, anode
);
7760 anextp
= &anode
->next
;
7764 slot
= delete_slot_part (set
, node
->loc
, slot
, offset
);
7772 /* Remove all recorded register locations for the given variable part
7773 from dataflow set SET, except for those that are identical to loc.
7774 The variable part is specified by variable's declaration or value
7775 DV and offset OFFSET. */
7778 clobber_variable_part (dataflow_set
*set
, rtx loc
, decl_or_value dv
,
7779 HOST_WIDE_INT offset
, rtx set_src
)
7781 variable_def
**slot
;
7783 if (!dv_as_opaque (dv
)
7784 || (!dv_is_value_p (dv
) && ! DECL_P (dv_as_decl (dv
))))
7787 slot
= shared_hash_find_slot_noinsert (set
->vars
, dv
);
7791 clobber_slot_part (set
, loc
, slot
, offset
, set_src
);
7794 /* Delete the part of variable's location from dataflow set SET. The
7795 variable part is specified by its SET->vars slot SLOT and offset
7796 OFFSET and the part's location by LOC. */
7798 static variable_def
**
7799 delete_slot_part (dataflow_set
*set
, rtx loc
, variable_def
**slot
,
7800 HOST_WIDE_INT offset
)
7802 variable var
= *slot
;
7803 int pos
= find_variable_location_part (var
, offset
, NULL
);
7807 location_chain node
, next
;
7808 location_chain
*nextp
;
7812 if (shared_var_p (var
, set
->vars
))
7814 /* If the variable contains the location part we have to
7815 make a copy of the variable. */
7816 for (node
= var
->var_part
[pos
].loc_chain
; node
;
7819 if ((REG_P (node
->loc
) && REG_P (loc
)
7820 && REGNO (node
->loc
) == REGNO (loc
))
7821 || rtx_equal_p (node
->loc
, loc
))
7823 slot
= unshare_variable (set
, slot
, var
,
7824 VAR_INIT_STATUS_UNKNOWN
);
7831 if (pos
== 0 && var
->onepart
&& VAR_LOC_1PAUX (var
))
7832 cur_loc
= VAR_LOC_FROM (var
);
7834 cur_loc
= var
->var_part
[pos
].cur_loc
;
7836 /* Delete the location part. */
7838 nextp
= &var
->var_part
[pos
].loc_chain
;
7839 for (node
= *nextp
; node
; node
= next
)
7842 if ((REG_P (node
->loc
) && REG_P (loc
)
7843 && REGNO (node
->loc
) == REGNO (loc
))
7844 || rtx_equal_p (node
->loc
, loc
))
7846 /* If we have deleted the location which was last emitted
7847 we have to emit new location so add the variable to set
7848 of changed variables. */
7849 if (cur_loc
== node
->loc
)
7852 var
->var_part
[pos
].cur_loc
= NULL
;
7853 if (pos
== 0 && var
->onepart
&& VAR_LOC_1PAUX (var
))
7854 VAR_LOC_FROM (var
) = NULL
;
7856 pool_free (loc_chain_pool
, node
);
7861 nextp
= &node
->next
;
7864 if (var
->var_part
[pos
].loc_chain
== NULL
)
7868 while (pos
< var
->n_var_parts
)
7870 var
->var_part
[pos
] = var
->var_part
[pos
+ 1];
7875 variable_was_changed (var
, set
);
7881 /* Delete the part of variable's location from dataflow set SET. The
7882 variable part is specified by variable's declaration or value DV
7883 and offset OFFSET and the part's location by LOC. */
7886 delete_variable_part (dataflow_set
*set
, rtx loc
, decl_or_value dv
,
7887 HOST_WIDE_INT offset
)
7889 variable_def
**slot
= shared_hash_find_slot_noinsert (set
->vars
, dv
);
7893 delete_slot_part (set
, loc
, slot
, offset
);
7897 /* Structure for passing some other parameters to function
7898 vt_expand_loc_callback. */
7899 struct expand_loc_callback_data
7901 /* The variables and values active at this point. */
7902 variable_table_type vars
;
7904 /* Stack of values and debug_exprs under expansion, and their
7906 vec
<rtx
, va_stack
> expanding
;
7908 /* Stack of values and debug_exprs whose expansion hit recursion
7909 cycles. They will have VALUE_RECURSED_INTO marked when added to
7910 this list. This flag will be cleared if any of its dependencies
7911 resolves to a valid location. So, if the flag remains set at the
7912 end of the search, we know no valid location for this one can
7914 vec
<rtx
, va_stack
> pending
;
7916 /* The maximum depth among the sub-expressions under expansion.
7917 Zero indicates no expansion so far. */
7921 /* Allocate the one-part auxiliary data structure for VAR, with enough
7922 room for COUNT dependencies. */
7925 loc_exp_dep_alloc (variable var
, int count
)
7929 gcc_checking_assert (var
->onepart
);
7931 /* We can be called with COUNT == 0 to allocate the data structure
7932 without any dependencies, e.g. for the backlinks only. However,
7933 if we are specifying a COUNT, then the dependency list must have
7934 been emptied before. It would be possible to adjust pointers or
7935 force it empty here, but this is better done at an earlier point
7936 in the algorithm, so we instead leave an assertion to catch
7938 gcc_checking_assert (!count
7939 || VAR_LOC_DEP_VEC (var
) == NULL
7940 || VAR_LOC_DEP_VEC (var
)->is_empty ());
7942 if (VAR_LOC_1PAUX (var
) && VAR_LOC_DEP_VEC (var
)->space (count
))
7945 allocsize
= offsetof (struct onepart_aux
, deps
)
7946 + vec
<loc_exp_dep
, va_heap
, vl_embed
>::embedded_size (count
);
7948 if (VAR_LOC_1PAUX (var
))
7950 VAR_LOC_1PAUX (var
) = XRESIZEVAR (struct onepart_aux
,
7951 VAR_LOC_1PAUX (var
), allocsize
);
7952 /* If the reallocation moves the onepaux structure, the
7953 back-pointer to BACKLINKS in the first list member will still
7954 point to its old location. Adjust it. */
7955 if (VAR_LOC_DEP_LST (var
))
7956 VAR_LOC_DEP_LST (var
)->pprev
= VAR_LOC_DEP_LSTP (var
);
7960 VAR_LOC_1PAUX (var
) = XNEWVAR (struct onepart_aux
, allocsize
);
7961 *VAR_LOC_DEP_LSTP (var
) = NULL
;
7962 VAR_LOC_FROM (var
) = NULL
;
7963 VAR_LOC_DEPTH (var
).complexity
= 0;
7964 VAR_LOC_DEPTH (var
).entryvals
= 0;
7966 VAR_LOC_DEP_VEC (var
)->embedded_init (count
);
7969 /* Remove all entries from the vector of active dependencies of VAR,
7970 removing them from the back-links lists too. */
7973 loc_exp_dep_clear (variable var
)
7975 while (VAR_LOC_DEP_VEC (var
) && !VAR_LOC_DEP_VEC (var
)->is_empty ())
7977 loc_exp_dep
*led
= &VAR_LOC_DEP_VEC (var
)->last ();
7979 led
->next
->pprev
= led
->pprev
;
7981 *led
->pprev
= led
->next
;
7982 VAR_LOC_DEP_VEC (var
)->pop ();
7986 /* Insert an active dependency from VAR on X to the vector of
7987 dependencies, and add the corresponding back-link to X's list of
7988 back-links in VARS. */
7991 loc_exp_insert_dep (variable var
, rtx x
, variable_table_type vars
)
7997 dv
= dv_from_rtx (x
);
7999 /* ??? Build a vector of variables parallel to EXPANDING, to avoid
8000 an additional look up? */
8001 xvar
= vars
.find_with_hash (dv
, dv_htab_hash (dv
));
8005 xvar
= variable_from_dropped (dv
, NO_INSERT
);
8006 gcc_checking_assert (xvar
);
8009 /* No point in adding the same backlink more than once. This may
8010 arise if say the same value appears in two complex expressions in
8011 the same loc_list, or even more than once in a single
8013 if (VAR_LOC_DEP_LST (xvar
) && VAR_LOC_DEP_LST (xvar
)->dv
== var
->dv
)
8016 if (var
->onepart
== NOT_ONEPART
)
8017 led
= (loc_exp_dep
*) pool_alloc (loc_exp_dep_pool
);
8021 memset (&empty
, 0, sizeof (empty
));
8022 VAR_LOC_DEP_VEC (var
)->quick_push (empty
);
8023 led
= &VAR_LOC_DEP_VEC (var
)->last ();
8028 loc_exp_dep_alloc (xvar
, 0);
8029 led
->pprev
= VAR_LOC_DEP_LSTP (xvar
);
8030 led
->next
= *led
->pprev
;
8032 led
->next
->pprev
= &led
->next
;
8036 /* Create active dependencies of VAR on COUNT values starting at
8037 VALUE, and corresponding back-links to the entries in VARS. Return
8038 true if we found any pending-recursion results. */
8041 loc_exp_dep_set (variable var
, rtx result
, rtx
*value
, int count
,
8042 variable_table_type vars
)
8044 bool pending_recursion
= false;
8046 gcc_checking_assert (VAR_LOC_DEP_VEC (var
) == NULL
8047 || VAR_LOC_DEP_VEC (var
)->is_empty ());
8049 /* Set up all dependencies from last_child (as set up at the end of
8050 the loop above) to the end. */
8051 loc_exp_dep_alloc (var
, count
);
8057 if (!pending_recursion
)
8058 pending_recursion
= !result
&& VALUE_RECURSED_INTO (x
);
8060 loc_exp_insert_dep (var
, x
, vars
);
8063 return pending_recursion
;
8066 /* Notify the back-links of IVAR that are pending recursion that we
8067 have found a non-NIL value for it, so they are cleared for another
8068 attempt to compute a current location. */
8071 notify_dependents_of_resolved_value (variable ivar
, variable_table_type vars
)
8073 loc_exp_dep
*led
, *next
;
8075 for (led
= VAR_LOC_DEP_LST (ivar
); led
; led
= next
)
8077 decl_or_value dv
= led
->dv
;
8082 if (dv_is_value_p (dv
))
8084 rtx value
= dv_as_value (dv
);
8086 /* If we have already resolved it, leave it alone. */
8087 if (!VALUE_RECURSED_INTO (value
))
8090 /* Check that VALUE_RECURSED_INTO, true from the test above,
8091 implies NO_LOC_P. */
8092 gcc_checking_assert (NO_LOC_P (value
));
8094 /* We won't notify variables that are being expanded,
8095 because their dependency list is cleared before
8097 NO_LOC_P (value
) = false;
8098 VALUE_RECURSED_INTO (value
) = false;
8100 gcc_checking_assert (dv_changed_p (dv
));
8104 gcc_checking_assert (dv_onepart_p (dv
) != NOT_ONEPART
);
8105 if (!dv_changed_p (dv
))
8109 var
= vars
.find_with_hash (dv
, dv_htab_hash (dv
));
8112 var
= variable_from_dropped (dv
, NO_INSERT
);
8115 notify_dependents_of_resolved_value (var
, vars
);
8118 next
->pprev
= led
->pprev
;
8126 static rtx
vt_expand_loc_callback (rtx x
, bitmap regs
,
8127 int max_depth
, void *data
);
8129 /* Return the combined depth, when one sub-expression evaluated to
8130 BEST_DEPTH and the previous known depth was SAVED_DEPTH. */
8132 static inline expand_depth
8133 update_depth (expand_depth saved_depth
, expand_depth best_depth
)
8135 /* If we didn't find anything, stick with what we had. */
8136 if (!best_depth
.complexity
)
8139 /* If we found hadn't found anything, use the depth of the current
8140 expression. Do NOT add one extra level, we want to compute the
8141 maximum depth among sub-expressions. We'll increment it later,
8143 if (!saved_depth
.complexity
)
8146 /* Combine the entryval count so that regardless of which one we
8147 return, the entryval count is accurate. */
8148 best_depth
.entryvals
= saved_depth
.entryvals
8149 = best_depth
.entryvals
+ saved_depth
.entryvals
;
8151 if (saved_depth
.complexity
< best_depth
.complexity
)
8157 /* Expand VAR to a location RTX, updating its cur_loc. Use REGS and
8158 DATA for cselib expand callback. If PENDRECP is given, indicate in
8159 it whether any sub-expression couldn't be fully evaluated because
8160 it is pending recursion resolution. */
8163 vt_expand_var_loc_chain (variable var
, bitmap regs
, void *data
, bool *pendrecp
)
8165 struct expand_loc_callback_data
*elcd
8166 = (struct expand_loc_callback_data
*) data
;
8167 location_chain loc
, next
;
8169 int first_child
, result_first_child
, last_child
;
8170 bool pending_recursion
;
8171 rtx loc_from
= NULL
;
8172 struct elt_loc_list
*cloc
= NULL
;
8173 expand_depth depth
= { 0, 0 }, saved_depth
= elcd
->depth
;
8174 int wanted_entryvals
, found_entryvals
= 0;
8176 /* Clear all backlinks pointing at this, so that we're not notified
8177 while we're active. */
8178 loc_exp_dep_clear (var
);
8181 if (var
->onepart
== ONEPART_VALUE
)
8183 cselib_val
*val
= CSELIB_VAL_PTR (dv_as_value (var
->dv
));
8185 gcc_checking_assert (cselib_preserved_value_p (val
));
8190 first_child
= result_first_child
= last_child
8191 = elcd
->expanding
.length ();
8193 wanted_entryvals
= found_entryvals
;
8195 /* Attempt to expand each available location in turn. */
8196 for (next
= loc
= var
->n_var_parts
? var
->var_part
[0].loc_chain
: NULL
;
8197 loc
|| cloc
; loc
= next
)
8199 result_first_child
= last_child
;
8203 loc_from
= cloc
->loc
;
8206 if (unsuitable_loc (loc_from
))
8211 loc_from
= loc
->loc
;
8215 gcc_checking_assert (!unsuitable_loc (loc_from
));
8217 elcd
->depth
.complexity
= elcd
->depth
.entryvals
= 0;
8218 result
= cselib_expand_value_rtx_cb (loc_from
, regs
, EXPR_DEPTH
,
8219 vt_expand_loc_callback
, data
);
8220 last_child
= elcd
->expanding
.length ();
8224 depth
= elcd
->depth
;
8226 gcc_checking_assert (depth
.complexity
8227 || result_first_child
== last_child
);
8229 if (last_child
- result_first_child
!= 1)
8231 if (!depth
.complexity
&& GET_CODE (result
) == ENTRY_VALUE
)
8236 if (depth
.complexity
<= EXPR_USE_DEPTH
)
8238 if (depth
.entryvals
<= wanted_entryvals
)
8240 else if (!found_entryvals
|| depth
.entryvals
< found_entryvals
)
8241 found_entryvals
= depth
.entryvals
;
8247 /* Set it up in case we leave the loop. */
8248 depth
.complexity
= depth
.entryvals
= 0;
8250 result_first_child
= first_child
;
8253 if (!loc_from
&& wanted_entryvals
< found_entryvals
)
8255 /* We found entries with ENTRY_VALUEs and skipped them. Since
8256 we could not find any expansions without ENTRY_VALUEs, but we
8257 found at least one with them, go back and get an entry with
8258 the minimum number ENTRY_VALUE count that we found. We could
8259 avoid looping, but since each sub-loc is already resolved,
8260 the re-expansion should be trivial. ??? Should we record all
8261 attempted locs as dependencies, so that we retry the
8262 expansion should any of them change, in the hope it can give
8263 us a new entry without an ENTRY_VALUE? */
8264 elcd
->expanding
.truncate (first_child
);
8268 /* Register all encountered dependencies as active. */
8269 pending_recursion
= loc_exp_dep_set
8270 (var
, result
, elcd
->expanding
.address () + result_first_child
,
8271 last_child
- result_first_child
, elcd
->vars
);
8273 elcd
->expanding
.truncate (first_child
);
8275 /* Record where the expansion came from. */
8276 gcc_checking_assert (!result
|| !pending_recursion
);
8277 VAR_LOC_FROM (var
) = loc_from
;
8278 VAR_LOC_DEPTH (var
) = depth
;
8280 gcc_checking_assert (!depth
.complexity
== !result
);
8282 elcd
->depth
= update_depth (saved_depth
, depth
);
8284 /* Indicate whether any of the dependencies are pending recursion
8287 *pendrecp
= pending_recursion
;
8289 if (!pendrecp
|| !pending_recursion
)
8290 var
->var_part
[0].cur_loc
= result
;
8295 /* Callback for cselib_expand_value, that looks for expressions
8296 holding the value in the var-tracking hash tables. Return X for
8297 standard processing, anything else is to be used as-is. */
8300 vt_expand_loc_callback (rtx x
, bitmap regs
,
8301 int max_depth ATTRIBUTE_UNUSED
,
8304 struct expand_loc_callback_data
*elcd
8305 = (struct expand_loc_callback_data
*) data
;
8309 bool pending_recursion
= false;
8310 bool from_empty
= false;
8312 switch (GET_CODE (x
))
8315 subreg
= cselib_expand_value_rtx_cb (SUBREG_REG (x
), regs
,
8317 vt_expand_loc_callback
, data
);
8322 result
= simplify_gen_subreg (GET_MODE (x
), subreg
,
8323 GET_MODE (SUBREG_REG (x
)),
8326 /* Invalid SUBREGs are ok in debug info. ??? We could try
8327 alternate expansions for the VALUE as well. */
8329 result
= gen_rtx_raw_SUBREG (GET_MODE (x
), subreg
, SUBREG_BYTE (x
));
8335 dv
= dv_from_rtx (x
);
8342 elcd
->expanding
.safe_push (x
);
8344 /* Check that VALUE_RECURSED_INTO implies NO_LOC_P. */
8345 gcc_checking_assert (!VALUE_RECURSED_INTO (x
) || NO_LOC_P (x
));
8349 gcc_checking_assert (VALUE_RECURSED_INTO (x
) || !dv_changed_p (dv
));
8353 var
= elcd
->vars
.find_with_hash (dv
, dv_htab_hash (dv
));
8358 var
= variable_from_dropped (dv
, INSERT
);
8361 gcc_checking_assert (var
);
8363 if (!dv_changed_p (dv
))
8365 gcc_checking_assert (!NO_LOC_P (x
));
8366 gcc_checking_assert (var
->var_part
[0].cur_loc
);
8367 gcc_checking_assert (VAR_LOC_1PAUX (var
));
8368 gcc_checking_assert (VAR_LOC_1PAUX (var
)->depth
.complexity
);
8370 elcd
->depth
= update_depth (elcd
->depth
, VAR_LOC_1PAUX (var
)->depth
);
8372 return var
->var_part
[0].cur_loc
;
8375 VALUE_RECURSED_INTO (x
) = true;
8376 /* This is tentative, but it makes some tests simpler. */
8377 NO_LOC_P (x
) = true;
8379 gcc_checking_assert (var
->n_var_parts
== 1 || from_empty
);
8381 result
= vt_expand_var_loc_chain (var
, regs
, data
, &pending_recursion
);
8383 if (pending_recursion
)
8385 gcc_checking_assert (!result
);
8386 elcd
->pending
.safe_push (x
);
8390 NO_LOC_P (x
) = !result
;
8391 VALUE_RECURSED_INTO (x
) = false;
8392 set_dv_changed (dv
, false);
8395 notify_dependents_of_resolved_value (var
, elcd
->vars
);
8401 /* While expanding variables, we may encounter recursion cycles
8402 because of mutual (possibly indirect) dependencies between two
8403 particular variables (or values), say A and B. If we're trying to
8404 expand A when we get to B, which in turn attempts to expand A, if
8405 we can't find any other expansion for B, we'll add B to this
8406 pending-recursion stack, and tentatively return NULL for its
8407 location. This tentative value will be used for any other
8408 occurrences of B, unless A gets some other location, in which case
8409 it will notify B that it is worth another try at computing a
8410 location for it, and it will use the location computed for A then.
8411 At the end of the expansion, the tentative NULL locations become
8412 final for all members of PENDING that didn't get a notification.
8413 This function performs this finalization of NULL locations. */
8416 resolve_expansions_pending_recursion (vec
<rtx
, va_stack
> pending
)
8418 while (!pending
.is_empty ())
8420 rtx x
= pending
.pop ();
8423 if (!VALUE_RECURSED_INTO (x
))
8426 gcc_checking_assert (NO_LOC_P (x
));
8427 VALUE_RECURSED_INTO (x
) = false;
8428 dv
= dv_from_rtx (x
);
8429 gcc_checking_assert (dv_changed_p (dv
));
8430 set_dv_changed (dv
, false);
8434 /* Initialize expand_loc_callback_data D with variable hash table V.
8435 It must be a macro because of alloca (vec stack). */
8436 #define INIT_ELCD(d, v) \
8440 vec_stack_alloc (rtx, (d).expanding, 4); \
8441 vec_stack_alloc (rtx, (d).pending, 4); \
8442 (d).depth.complexity = (d).depth.entryvals = 0; \
8445 /* Finalize expand_loc_callback_data D, resolved to location L. */
8446 #define FINI_ELCD(d, l) \
8449 resolve_expansions_pending_recursion ((d).pending); \
8450 (d).pending.release (); \
8451 (d).expanding.release (); \
8453 if ((l) && MEM_P (l)) \
8454 (l) = targetm.delegitimize_address (l); \
8458 /* Expand VALUEs and DEBUG_EXPRs in LOC to a location, using the
8459 equivalences in VARS, updating their CUR_LOCs in the process. */
8462 vt_expand_loc (rtx loc
, variable_table_type vars
)
8464 struct expand_loc_callback_data data
;
8467 if (!MAY_HAVE_DEBUG_INSNS
)
8470 INIT_ELCD (data
, vars
);
8472 result
= cselib_expand_value_rtx_cb (loc
, scratch_regs
, EXPR_DEPTH
,
8473 vt_expand_loc_callback
, &data
);
8475 FINI_ELCD (data
, result
);
8480 /* Expand the one-part VARiable to a location, using the equivalences
8481 in VARS, updating their CUR_LOCs in the process. */
8484 vt_expand_1pvar (variable var
, variable_table_type vars
)
8486 struct expand_loc_callback_data data
;
8489 gcc_checking_assert (var
->onepart
&& var
->n_var_parts
== 1);
8491 if (!dv_changed_p (var
->dv
))
8492 return var
->var_part
[0].cur_loc
;
8494 INIT_ELCD (data
, vars
);
8496 loc
= vt_expand_var_loc_chain (var
, scratch_regs
, &data
, NULL
);
8498 gcc_checking_assert (data
.expanding
.is_empty ());
8500 FINI_ELCD (data
, loc
);
8505 /* Emit the NOTE_INSN_VAR_LOCATION for variable *VARP. DATA contains
8506 additional parameters: WHERE specifies whether the note shall be emitted
8507 before or after instruction INSN. */
8510 emit_note_insn_var_location (variable_def
**varp
, emit_note_data
*data
)
8512 variable var
= *varp
;
8513 rtx insn
= data
->insn
;
8514 enum emit_note_where where
= data
->where
;
8515 variable_table_type vars
= data
->vars
;
8517 int i
, j
, n_var_parts
;
8519 enum var_init_status initialized
= VAR_INIT_STATUS_UNINITIALIZED
;
8520 HOST_WIDE_INT last_limit
;
8521 tree type_size_unit
;
8522 HOST_WIDE_INT offsets
[MAX_VAR_PARTS
];
8523 rtx loc
[MAX_VAR_PARTS
];
8527 gcc_checking_assert (var
->onepart
== NOT_ONEPART
8528 || var
->onepart
== ONEPART_VDECL
);
8530 decl
= dv_as_decl (var
->dv
);
8536 for (i
= 0; i
< var
->n_var_parts
; i
++)
8537 if (var
->var_part
[i
].cur_loc
== NULL
&& var
->var_part
[i
].loc_chain
)
8538 var
->var_part
[i
].cur_loc
= var
->var_part
[i
].loc_chain
->loc
;
8539 for (i
= 0; i
< var
->n_var_parts
; i
++)
8541 enum machine_mode mode
, wider_mode
;
8543 HOST_WIDE_INT offset
;
8545 if (i
== 0 && var
->onepart
)
8547 gcc_checking_assert (var
->n_var_parts
== 1);
8549 initialized
= VAR_INIT_STATUS_INITIALIZED
;
8550 loc2
= vt_expand_1pvar (var
, vars
);
8554 if (last_limit
< VAR_PART_OFFSET (var
, i
))
8559 else if (last_limit
> VAR_PART_OFFSET (var
, i
))
8561 offset
= VAR_PART_OFFSET (var
, i
);
8562 loc2
= var
->var_part
[i
].cur_loc
;
8563 if (loc2
&& GET_CODE (loc2
) == MEM
8564 && GET_CODE (XEXP (loc2
, 0)) == VALUE
)
8566 rtx depval
= XEXP (loc2
, 0);
8568 loc2
= vt_expand_loc (loc2
, vars
);
8571 loc_exp_insert_dep (var
, depval
, vars
);
8578 gcc_checking_assert (GET_CODE (loc2
) != VALUE
);
8579 for (lc
= var
->var_part
[i
].loc_chain
; lc
; lc
= lc
->next
)
8580 if (var
->var_part
[i
].cur_loc
== lc
->loc
)
8582 initialized
= lc
->init
;
8588 offsets
[n_var_parts
] = offset
;
8594 loc
[n_var_parts
] = loc2
;
8595 mode
= GET_MODE (var
->var_part
[i
].cur_loc
);
8596 if (mode
== VOIDmode
&& var
->onepart
)
8597 mode
= DECL_MODE (decl
);
8598 last_limit
= offsets
[n_var_parts
] + GET_MODE_SIZE (mode
);
8600 /* Attempt to merge adjacent registers or memory. */
8601 wider_mode
= GET_MODE_WIDER_MODE (mode
);
8602 for (j
= i
+ 1; j
< var
->n_var_parts
; j
++)
8603 if (last_limit
<= VAR_PART_OFFSET (var
, j
))
8605 if (j
< var
->n_var_parts
8606 && wider_mode
!= VOIDmode
8607 && var
->var_part
[j
].cur_loc
8608 && mode
== GET_MODE (var
->var_part
[j
].cur_loc
)
8609 && (REG_P (loc
[n_var_parts
]) || MEM_P (loc
[n_var_parts
]))
8610 && last_limit
== (var
->onepart
? 0 : VAR_PART_OFFSET (var
, j
))
8611 && (loc2
= vt_expand_loc (var
->var_part
[j
].cur_loc
, vars
))
8612 && GET_CODE (loc
[n_var_parts
]) == GET_CODE (loc2
))
8616 if (REG_P (loc
[n_var_parts
])
8617 && hard_regno_nregs
[REGNO (loc
[n_var_parts
])][mode
] * 2
8618 == hard_regno_nregs
[REGNO (loc
[n_var_parts
])][wider_mode
]
8619 && end_hard_regno (mode
, REGNO (loc
[n_var_parts
]))
8622 if (! WORDS_BIG_ENDIAN
&& ! BYTES_BIG_ENDIAN
)
8623 new_loc
= simplify_subreg (wider_mode
, loc
[n_var_parts
],
8625 else if (WORDS_BIG_ENDIAN
&& BYTES_BIG_ENDIAN
)
8626 new_loc
= simplify_subreg (wider_mode
, loc2
, mode
, 0);
8629 if (!REG_P (new_loc
)
8630 || REGNO (new_loc
) != REGNO (loc
[n_var_parts
]))
8633 REG_ATTRS (new_loc
) = REG_ATTRS (loc
[n_var_parts
]);
8636 else if (MEM_P (loc
[n_var_parts
])
8637 && GET_CODE (XEXP (loc2
, 0)) == PLUS
8638 && REG_P (XEXP (XEXP (loc2
, 0), 0))
8639 && CONST_INT_P (XEXP (XEXP (loc2
, 0), 1)))
8641 if ((REG_P (XEXP (loc
[n_var_parts
], 0))
8642 && rtx_equal_p (XEXP (loc
[n_var_parts
], 0),
8643 XEXP (XEXP (loc2
, 0), 0))
8644 && INTVAL (XEXP (XEXP (loc2
, 0), 1))
8645 == GET_MODE_SIZE (mode
))
8646 || (GET_CODE (XEXP (loc
[n_var_parts
], 0)) == PLUS
8647 && CONST_INT_P (XEXP (XEXP (loc
[n_var_parts
], 0), 1))
8648 && rtx_equal_p (XEXP (XEXP (loc
[n_var_parts
], 0), 0),
8649 XEXP (XEXP (loc2
, 0), 0))
8650 && INTVAL (XEXP (XEXP (loc
[n_var_parts
], 0), 1))
8651 + GET_MODE_SIZE (mode
)
8652 == INTVAL (XEXP (XEXP (loc2
, 0), 1))))
8653 new_loc
= adjust_address_nv (loc
[n_var_parts
],
8659 loc
[n_var_parts
] = new_loc
;
8661 last_limit
= offsets
[n_var_parts
] + GET_MODE_SIZE (mode
);
8667 type_size_unit
= TYPE_SIZE_UNIT (TREE_TYPE (decl
));
8668 if ((unsigned HOST_WIDE_INT
) last_limit
< TREE_INT_CST_LOW (type_size_unit
))
8671 if (! flag_var_tracking_uninit
)
8672 initialized
= VAR_INIT_STATUS_INITIALIZED
;
8676 note_vl
= gen_rtx_VAR_LOCATION (VOIDmode
, decl
, NULL_RTX
,
8678 else if (n_var_parts
== 1)
8682 if (offsets
[0] || GET_CODE (loc
[0]) == PARALLEL
)
8683 expr_list
= gen_rtx_EXPR_LIST (VOIDmode
, loc
[0], GEN_INT (offsets
[0]));
8687 note_vl
= gen_rtx_VAR_LOCATION (VOIDmode
, decl
, expr_list
,
8690 else if (n_var_parts
)
8694 for (i
= 0; i
< n_var_parts
; i
++)
8696 = gen_rtx_EXPR_LIST (VOIDmode
, loc
[i
], GEN_INT (offsets
[i
]));
8698 parallel
= gen_rtx_PARALLEL (VOIDmode
,
8699 gen_rtvec_v (n_var_parts
, loc
));
8700 note_vl
= gen_rtx_VAR_LOCATION (VOIDmode
, decl
,
8701 parallel
, (int) initialized
);
8704 if (where
!= EMIT_NOTE_BEFORE_INSN
)
8706 note
= emit_note_after (NOTE_INSN_VAR_LOCATION
, insn
);
8707 if (where
== EMIT_NOTE_AFTER_CALL_INSN
)
8708 NOTE_DURING_CALL_P (note
) = true;
8712 /* Make sure that the call related notes come first. */
8713 while (NEXT_INSN (insn
)
8715 && ((NOTE_KIND (insn
) == NOTE_INSN_VAR_LOCATION
8716 && NOTE_DURING_CALL_P (insn
))
8717 || NOTE_KIND (insn
) == NOTE_INSN_CALL_ARG_LOCATION
))
8718 insn
= NEXT_INSN (insn
);
8720 && ((NOTE_KIND (insn
) == NOTE_INSN_VAR_LOCATION
8721 && NOTE_DURING_CALL_P (insn
))
8722 || NOTE_KIND (insn
) == NOTE_INSN_CALL_ARG_LOCATION
))
8723 note
= emit_note_after (NOTE_INSN_VAR_LOCATION
, insn
);
8725 note
= emit_note_before (NOTE_INSN_VAR_LOCATION
, insn
);
8727 NOTE_VAR_LOCATION (note
) = note_vl
;
8729 set_dv_changed (var
->dv
, false);
8730 gcc_assert (var
->in_changed_variables
);
8731 var
->in_changed_variables
= false;
8732 changed_variables
.clear_slot (varp
);
8734 /* Continue traversing the hash table. */
8738 /* While traversing changed_variables, push onto DATA (a stack of RTX
8739 values) entries that aren't user variables. */
8742 var_track_values_to_stack (variable_def
**slot
,
8743 vec
<rtx
, va_stack
> *changed_values_stack
)
8745 variable var
= *slot
;
8747 if (var
->onepart
== ONEPART_VALUE
)
8748 changed_values_stack
->safe_push (dv_as_value (var
->dv
));
8749 else if (var
->onepart
== ONEPART_DEXPR
)
8750 changed_values_stack
->safe_push (DECL_RTL_KNOWN_SET (dv_as_decl (var
->dv
)));
8755 /* Remove from changed_variables the entry whose DV corresponds to
8756 value or debug_expr VAL. */
8758 remove_value_from_changed_variables (rtx val
)
8760 decl_or_value dv
= dv_from_rtx (val
);
8761 variable_def
**slot
;
8764 slot
= changed_variables
.find_slot_with_hash (dv
, dv_htab_hash (dv
),
8767 var
->in_changed_variables
= false;
8768 changed_variables
.clear_slot (slot
);
8771 /* If VAL (a value or debug_expr) has backlinks to variables actively
8772 dependent on it in HTAB or in CHANGED_VARIABLES, mark them as
8773 changed, adding to CHANGED_VALUES_STACK any dependencies that may
8774 have dependencies of their own to notify. */
8777 notify_dependents_of_changed_value (rtx val
, variable_table_type htab
,
8778 vec
<rtx
, va_stack
> *changed_values_stack
)
8780 variable_def
**slot
;
8783 decl_or_value dv
= dv_from_rtx (val
);
8785 slot
= changed_variables
.find_slot_with_hash (dv
, dv_htab_hash (dv
),
8788 slot
= htab
.find_slot_with_hash (dv
, dv_htab_hash (dv
), NO_INSERT
);
8790 slot
= dropped_values
.find_slot_with_hash (dv
, dv_htab_hash (dv
),
8794 while ((led
= VAR_LOC_DEP_LST (var
)))
8796 decl_or_value ldv
= led
->dv
;
8799 /* Deactivate and remove the backlink, as it was “used up”. It
8800 makes no sense to attempt to notify the same entity again:
8801 either it will be recomputed and re-register an active
8802 dependency, or it will still have the changed mark. */
8804 led
->next
->pprev
= led
->pprev
;
8806 *led
->pprev
= led
->next
;
8810 if (dv_changed_p (ldv
))
8813 switch (dv_onepart_p (ldv
))
8817 set_dv_changed (ldv
, true);
8818 changed_values_stack
->safe_push (dv_as_rtx (ldv
));
8822 ivar
= htab
.find_with_hash (ldv
, dv_htab_hash (ldv
));
8823 gcc_checking_assert (!VAR_LOC_DEP_LST (ivar
));
8824 variable_was_changed (ivar
, NULL
);
8828 pool_free (loc_exp_dep_pool
, led
);
8829 ivar
= htab
.find_with_hash (ldv
, dv_htab_hash (ldv
));
8832 int i
= ivar
->n_var_parts
;
8835 rtx loc
= ivar
->var_part
[i
].cur_loc
;
8837 if (loc
&& GET_CODE (loc
) == MEM
8838 && XEXP (loc
, 0) == val
)
8840 variable_was_changed (ivar
, NULL
);
8853 /* Take out of changed_variables any entries that don't refer to use
8854 variables. Back-propagate change notifications from values and
8855 debug_exprs to their active dependencies in HTAB or in
8856 CHANGED_VARIABLES. */
8859 process_changed_values (variable_table_type htab
)
8863 vec
<rtx
, va_stack
> changed_values_stack
;
8865 vec_stack_alloc (rtx
, changed_values_stack
, 20);
8867 /* Move values from changed_variables to changed_values_stack. */
8869 .traverse
<vec
<rtx
, va_stack
>*, var_track_values_to_stack
>
8870 (&changed_values_stack
);
8872 /* Back-propagate change notifications in values while popping
8873 them from the stack. */
8874 for (n
= i
= changed_values_stack
.length ();
8875 i
> 0; i
= changed_values_stack
.length ())
8877 val
= changed_values_stack
.pop ();
8878 notify_dependents_of_changed_value (val
, htab
, &changed_values_stack
);
8880 /* This condition will hold when visiting each of the entries
8881 originally in changed_variables. We can't remove them
8882 earlier because this could drop the backlinks before we got a
8883 chance to use them. */
8886 remove_value_from_changed_variables (val
);
8891 changed_values_stack
.release ();
8894 /* Emit NOTE_INSN_VAR_LOCATION note for each variable from a chain
8895 CHANGED_VARIABLES and delete this chain. WHERE specifies whether
8896 the notes shall be emitted before of after instruction INSN. */
8899 emit_notes_for_changes (rtx insn
, enum emit_note_where where
,
8902 emit_note_data data
;
8903 variable_table_type htab
= shared_hash_htab (vars
);
8905 if (!changed_variables
.elements ())
8908 if (MAY_HAVE_DEBUG_INSNS
)
8909 process_changed_values (htab
);
8916 .traverse
<emit_note_data
*, emit_note_insn_var_location
> (&data
);
8919 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it differs from the
8920 same variable in hash table DATA or is not there at all. */
8923 emit_notes_for_differences_1 (variable_def
**slot
, variable_table_type new_vars
)
8925 variable old_var
, new_var
;
8928 new_var
= new_vars
.find_with_hash (old_var
->dv
, dv_htab_hash (old_var
->dv
));
8932 /* Variable has disappeared. */
8933 variable empty_var
= NULL
;
8935 if (old_var
->onepart
== ONEPART_VALUE
8936 || old_var
->onepart
== ONEPART_DEXPR
)
8938 empty_var
= variable_from_dropped (old_var
->dv
, NO_INSERT
);
8941 gcc_checking_assert (!empty_var
->in_changed_variables
);
8942 if (!VAR_LOC_1PAUX (old_var
))
8944 VAR_LOC_1PAUX (old_var
) = VAR_LOC_1PAUX (empty_var
);
8945 VAR_LOC_1PAUX (empty_var
) = NULL
;
8948 gcc_checking_assert (!VAR_LOC_1PAUX (empty_var
));
8954 empty_var
= (variable
) pool_alloc (onepart_pool (old_var
->onepart
));
8955 empty_var
->dv
= old_var
->dv
;
8956 empty_var
->refcount
= 0;
8957 empty_var
->n_var_parts
= 0;
8958 empty_var
->onepart
= old_var
->onepart
;
8959 empty_var
->in_changed_variables
= false;
8962 if (empty_var
->onepart
)
8964 /* Propagate the auxiliary data to (ultimately)
8965 changed_variables. */
8966 empty_var
->var_part
[0].loc_chain
= NULL
;
8967 empty_var
->var_part
[0].cur_loc
= NULL
;
8968 VAR_LOC_1PAUX (empty_var
) = VAR_LOC_1PAUX (old_var
);
8969 VAR_LOC_1PAUX (old_var
) = NULL
;
8971 variable_was_changed (empty_var
, NULL
);
8972 /* Continue traversing the hash table. */
8975 /* Update cur_loc and one-part auxiliary data, before new_var goes
8976 through variable_was_changed. */
8977 if (old_var
!= new_var
&& new_var
->onepart
)
8979 gcc_checking_assert (VAR_LOC_1PAUX (new_var
) == NULL
);
8980 VAR_LOC_1PAUX (new_var
) = VAR_LOC_1PAUX (old_var
);
8981 VAR_LOC_1PAUX (old_var
) = NULL
;
8982 new_var
->var_part
[0].cur_loc
= old_var
->var_part
[0].cur_loc
;
8984 if (variable_different_p (old_var
, new_var
))
8985 variable_was_changed (new_var
, NULL
);
8987 /* Continue traversing the hash table. */
8991 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it is not in hash
8995 emit_notes_for_differences_2 (variable_def
**slot
, variable_table_type old_vars
)
8997 variable old_var
, new_var
;
9000 old_var
= old_vars
.find_with_hash (new_var
->dv
, dv_htab_hash (new_var
->dv
));
9004 for (i
= 0; i
< new_var
->n_var_parts
; i
++)
9005 new_var
->var_part
[i
].cur_loc
= NULL
;
9006 variable_was_changed (new_var
, NULL
);
9009 /* Continue traversing the hash table. */
9013 /* Emit notes before INSN for differences between dataflow sets OLD_SET and
9017 emit_notes_for_differences (rtx insn
, dataflow_set
*old_set
,
9018 dataflow_set
*new_set
)
9020 shared_hash_htab (old_set
->vars
)
9021 .traverse
<variable_table_type
, emit_notes_for_differences_1
>
9022 (shared_hash_htab (new_set
->vars
));
9023 shared_hash_htab (new_set
->vars
)
9024 .traverse
<variable_table_type
, emit_notes_for_differences_2
>
9025 (shared_hash_htab (old_set
->vars
));
9026 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
, new_set
->vars
);
9029 /* Return the next insn after INSN that is not a NOTE_INSN_VAR_LOCATION. */
9032 next_non_note_insn_var_location (rtx insn
)
9036 insn
= NEXT_INSN (insn
);
9039 || NOTE_KIND (insn
) != NOTE_INSN_VAR_LOCATION
)
9046 /* Emit the notes for changes of location parts in the basic block BB. */
9049 emit_notes_in_bb (basic_block bb
, dataflow_set
*set
)
9052 micro_operation
*mo
;
9054 dataflow_set_clear (set
);
9055 dataflow_set_copy (set
, &VTI (bb
)->in
);
9057 FOR_EACH_VEC_ELT (VTI (bb
)->mos
, i
, mo
)
9059 rtx insn
= mo
->insn
;
9060 rtx next_insn
= next_non_note_insn_var_location (insn
);
9065 dataflow_set_clear_at_call (set
);
9066 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_CALL_INSN
, set
->vars
);
9068 rtx arguments
= mo
->u
.loc
, *p
= &arguments
, note
;
9071 XEXP (XEXP (*p
, 0), 1)
9072 = vt_expand_loc (XEXP (XEXP (*p
, 0), 1),
9073 shared_hash_htab (set
->vars
));
9074 /* If expansion is successful, keep it in the list. */
9075 if (XEXP (XEXP (*p
, 0), 1))
9077 /* Otherwise, if the following item is data_value for it,
9079 else if (XEXP (*p
, 1)
9080 && REG_P (XEXP (XEXP (*p
, 0), 0))
9081 && MEM_P (XEXP (XEXP (XEXP (*p
, 1), 0), 0))
9082 && REG_P (XEXP (XEXP (XEXP (XEXP (*p
, 1), 0), 0),
9084 && REGNO (XEXP (XEXP (*p
, 0), 0))
9085 == REGNO (XEXP (XEXP (XEXP (XEXP (*p
, 1), 0),
9087 *p
= XEXP (XEXP (*p
, 1), 1);
9088 /* Just drop this item. */
9092 note
= emit_note_after (NOTE_INSN_CALL_ARG_LOCATION
, insn
);
9093 NOTE_VAR_LOCATION (note
) = arguments
;
9099 rtx loc
= mo
->u
.loc
;
9102 var_reg_set (set
, loc
, VAR_INIT_STATUS_UNINITIALIZED
, NULL
);
9104 var_mem_set (set
, loc
, VAR_INIT_STATUS_UNINITIALIZED
, NULL
);
9106 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
, set
->vars
);
9112 rtx loc
= mo
->u
.loc
;
9116 if (GET_CODE (loc
) == CONCAT
)
9118 val
= XEXP (loc
, 0);
9119 vloc
= XEXP (loc
, 1);
9127 var
= PAT_VAR_LOCATION_DECL (vloc
);
9129 clobber_variable_part (set
, NULL_RTX
,
9130 dv_from_decl (var
), 0, NULL_RTX
);
9133 if (VAL_NEEDS_RESOLUTION (loc
))
9134 val_resolve (set
, val
, PAT_VAR_LOCATION_LOC (vloc
), insn
);
9135 set_variable_part (set
, val
, dv_from_decl (var
), 0,
9136 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
,
9139 else if (!VAR_LOC_UNKNOWN_P (PAT_VAR_LOCATION_LOC (vloc
)))
9140 set_variable_part (set
, PAT_VAR_LOCATION_LOC (vloc
),
9141 dv_from_decl (var
), 0,
9142 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
,
9145 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
, set
->vars
);
9151 rtx loc
= mo
->u
.loc
;
9152 rtx val
, vloc
, uloc
;
9154 vloc
= uloc
= XEXP (loc
, 1);
9155 val
= XEXP (loc
, 0);
9157 if (GET_CODE (val
) == CONCAT
)
9159 uloc
= XEXP (val
, 1);
9160 val
= XEXP (val
, 0);
9163 if (VAL_NEEDS_RESOLUTION (loc
))
9164 val_resolve (set
, val
, vloc
, insn
);
9166 val_store (set
, val
, uloc
, insn
, false);
9168 if (VAL_HOLDS_TRACK_EXPR (loc
))
9170 if (GET_CODE (uloc
) == REG
)
9171 var_reg_set (set
, uloc
, VAR_INIT_STATUS_UNINITIALIZED
,
9173 else if (GET_CODE (uloc
) == MEM
)
9174 var_mem_set (set
, uloc
, VAR_INIT_STATUS_UNINITIALIZED
,
9178 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
, set
->vars
);
9184 rtx loc
= mo
->u
.loc
;
9185 rtx val
, vloc
, uloc
;
9189 uloc
= XEXP (vloc
, 1);
9190 val
= XEXP (vloc
, 0);
9193 if (GET_CODE (uloc
) == SET
)
9195 dstv
= SET_DEST (uloc
);
9196 srcv
= SET_SRC (uloc
);
9204 if (GET_CODE (val
) == CONCAT
)
9206 dstv
= vloc
= XEXP (val
, 1);
9207 val
= XEXP (val
, 0);
9210 if (GET_CODE (vloc
) == SET
)
9212 srcv
= SET_SRC (vloc
);
9214 gcc_assert (val
!= srcv
);
9215 gcc_assert (vloc
== uloc
|| VAL_NEEDS_RESOLUTION (loc
));
9217 dstv
= vloc
= SET_DEST (vloc
);
9219 if (VAL_NEEDS_RESOLUTION (loc
))
9220 val_resolve (set
, val
, srcv
, insn
);
9222 else if (VAL_NEEDS_RESOLUTION (loc
))
9224 gcc_assert (GET_CODE (uloc
) == SET
9225 && GET_CODE (SET_SRC (uloc
)) == REG
);
9226 val_resolve (set
, val
, SET_SRC (uloc
), insn
);
9229 if (VAL_HOLDS_TRACK_EXPR (loc
))
9231 if (VAL_EXPR_IS_CLOBBERED (loc
))
9234 var_reg_delete (set
, uloc
, true);
9235 else if (MEM_P (uloc
))
9237 gcc_assert (MEM_P (dstv
));
9238 gcc_assert (MEM_ATTRS (dstv
) == MEM_ATTRS (uloc
));
9239 var_mem_delete (set
, dstv
, true);
9244 bool copied_p
= VAL_EXPR_IS_COPIED (loc
);
9245 rtx src
= NULL
, dst
= uloc
;
9246 enum var_init_status status
= VAR_INIT_STATUS_INITIALIZED
;
9248 if (GET_CODE (uloc
) == SET
)
9250 src
= SET_SRC (uloc
);
9251 dst
= SET_DEST (uloc
);
9256 status
= find_src_status (set
, src
);
9258 src
= find_src_set_src (set
, src
);
9262 var_reg_delete_and_set (set
, dst
, !copied_p
,
9264 else if (MEM_P (dst
))
9266 gcc_assert (MEM_P (dstv
));
9267 gcc_assert (MEM_ATTRS (dstv
) == MEM_ATTRS (dst
));
9268 var_mem_delete_and_set (set
, dstv
, !copied_p
,
9273 else if (REG_P (uloc
))
9274 var_regno_delete (set
, REGNO (uloc
));
9275 else if (MEM_P (uloc
))
9277 gcc_checking_assert (GET_CODE (vloc
) == MEM
);
9278 gcc_checking_assert (vloc
== dstv
);
9280 clobber_overlapping_mems (set
, vloc
);
9283 val_store (set
, val
, dstv
, insn
, true);
9285 emit_notes_for_changes (next_insn
, EMIT_NOTE_BEFORE_INSN
,
9292 rtx loc
= mo
->u
.loc
;
9295 if (GET_CODE (loc
) == SET
)
9297 set_src
= SET_SRC (loc
);
9298 loc
= SET_DEST (loc
);
9302 var_reg_delete_and_set (set
, loc
, true, VAR_INIT_STATUS_INITIALIZED
,
9305 var_mem_delete_and_set (set
, loc
, true, VAR_INIT_STATUS_INITIALIZED
,
9308 emit_notes_for_changes (next_insn
, EMIT_NOTE_BEFORE_INSN
,
9315 rtx loc
= mo
->u
.loc
;
9316 enum var_init_status src_status
;
9319 if (GET_CODE (loc
) == SET
)
9321 set_src
= SET_SRC (loc
);
9322 loc
= SET_DEST (loc
);
9325 src_status
= find_src_status (set
, set_src
);
9326 set_src
= find_src_set_src (set
, set_src
);
9329 var_reg_delete_and_set (set
, loc
, false, src_status
, set_src
);
9331 var_mem_delete_and_set (set
, loc
, false, src_status
, set_src
);
9333 emit_notes_for_changes (next_insn
, EMIT_NOTE_BEFORE_INSN
,
9340 rtx loc
= mo
->u
.loc
;
9343 var_reg_delete (set
, loc
, false);
9345 var_mem_delete (set
, loc
, false);
9347 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
, set
->vars
);
9353 rtx loc
= mo
->u
.loc
;
9356 var_reg_delete (set
, loc
, true);
9358 var_mem_delete (set
, loc
, true);
9360 emit_notes_for_changes (next_insn
, EMIT_NOTE_BEFORE_INSN
,
9366 set
->stack_adjust
+= mo
->u
.adjust
;
9372 /* Emit notes for the whole function. */
9375 vt_emit_notes (void)
9380 gcc_assert (!changed_variables
.elements ());
9382 /* Free memory occupied by the out hash tables, as they aren't used
9385 dataflow_set_clear (&VTI (bb
)->out
);
9387 /* Enable emitting notes by functions (mainly by set_variable_part and
9388 delete_variable_part). */
9391 if (MAY_HAVE_DEBUG_INSNS
)
9393 dropped_values
.create (cselib_get_next_uid () * 2);
9394 loc_exp_dep_pool
= create_alloc_pool ("loc_exp_dep pool",
9395 sizeof (loc_exp_dep
), 64);
9398 dataflow_set_init (&cur
);
9402 /* Emit the notes for changes of variable locations between two
9403 subsequent basic blocks. */
9404 emit_notes_for_differences (BB_HEAD (bb
), &cur
, &VTI (bb
)->in
);
9406 if (MAY_HAVE_DEBUG_INSNS
)
9407 local_get_addr_cache
= pointer_map_create ();
9409 /* Emit the notes for the changes in the basic block itself. */
9410 emit_notes_in_bb (bb
, &cur
);
9412 if (MAY_HAVE_DEBUG_INSNS
)
9413 pointer_map_destroy (local_get_addr_cache
);
9414 local_get_addr_cache
= NULL
;
9416 /* Free memory occupied by the in hash table, we won't need it
9418 dataflow_set_clear (&VTI (bb
)->in
);
9420 #ifdef ENABLE_CHECKING
9421 shared_hash_htab (cur
.vars
)
9422 .traverse
<variable_table_type
, emit_notes_for_differences_1
>
9423 (shared_hash_htab (empty_shared_hash
));
9425 dataflow_set_destroy (&cur
);
9427 if (MAY_HAVE_DEBUG_INSNS
)
9428 dropped_values
.dispose ();
9433 /* If there is a declaration and offset associated with register/memory RTL
9434 assign declaration to *DECLP and offset to *OFFSETP, and return true. */
9437 vt_get_decl_and_offset (rtx rtl
, tree
*declp
, HOST_WIDE_INT
*offsetp
)
9441 if (REG_ATTRS (rtl
))
9443 *declp
= REG_EXPR (rtl
);
9444 *offsetp
= REG_OFFSET (rtl
);
9448 else if (MEM_P (rtl
))
9450 if (MEM_ATTRS (rtl
))
9452 *declp
= MEM_EXPR (rtl
);
9453 *offsetp
= INT_MEM_OFFSET (rtl
);
9460 /* Record the value for the ENTRY_VALUE of RTL as a global equivalence
9464 record_entry_value (cselib_val
*val
, rtx rtl
)
9466 rtx ev
= gen_rtx_ENTRY_VALUE (GET_MODE (rtl
));
9468 ENTRY_VALUE_EXP (ev
) = rtl
;
9470 cselib_add_permanent_equiv (val
, ev
, get_insns ());
9473 /* Insert function parameter PARM in IN and OUT sets of ENTRY_BLOCK. */
9476 vt_add_function_parameter (tree parm
)
9478 rtx decl_rtl
= DECL_RTL_IF_SET (parm
);
9479 rtx incoming
= DECL_INCOMING_RTL (parm
);
9481 enum machine_mode mode
;
9482 HOST_WIDE_INT offset
;
9486 if (TREE_CODE (parm
) != PARM_DECL
)
9489 if (!decl_rtl
|| !incoming
)
9492 if (GET_MODE (decl_rtl
) == BLKmode
|| GET_MODE (incoming
) == BLKmode
)
9495 /* If there is a DRAP register or a pseudo in internal_arg_pointer,
9496 rewrite the incoming location of parameters passed on the stack
9497 into MEMs based on the argument pointer, so that incoming doesn't
9498 depend on a pseudo. */
9499 if (MEM_P (incoming
)
9500 && (XEXP (incoming
, 0) == crtl
->args
.internal_arg_pointer
9501 || (GET_CODE (XEXP (incoming
, 0)) == PLUS
9502 && XEXP (XEXP (incoming
, 0), 0)
9503 == crtl
->args
.internal_arg_pointer
9504 && CONST_INT_P (XEXP (XEXP (incoming
, 0), 1)))))
9506 HOST_WIDE_INT off
= -FIRST_PARM_OFFSET (current_function_decl
);
9507 if (GET_CODE (XEXP (incoming
, 0)) == PLUS
)
9508 off
+= INTVAL (XEXP (XEXP (incoming
, 0), 1));
9510 = replace_equiv_address_nv (incoming
,
9511 plus_constant (Pmode
,
9512 arg_pointer_rtx
, off
));
9515 #ifdef HAVE_window_save
9516 /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
9517 If the target machine has an explicit window save instruction, the
9518 actual entry value is the corresponding OUTGOING_REGNO instead. */
9519 if (HAVE_window_save
&& !crtl
->uses_only_leaf_regs
)
9521 if (REG_P (incoming
)
9522 && HARD_REGISTER_P (incoming
)
9523 && OUTGOING_REGNO (REGNO (incoming
)) != REGNO (incoming
))
9526 p
.incoming
= incoming
;
9528 = gen_rtx_REG_offset (incoming
, GET_MODE (incoming
),
9529 OUTGOING_REGNO (REGNO (incoming
)), 0);
9530 p
.outgoing
= incoming
;
9531 vec_safe_push (windowed_parm_regs
, p
);
9533 else if (MEM_P (incoming
)
9534 && REG_P (XEXP (incoming
, 0))
9535 && HARD_REGISTER_P (XEXP (incoming
, 0)))
9537 rtx reg
= XEXP (incoming
, 0);
9538 if (OUTGOING_REGNO (REGNO (reg
)) != REGNO (reg
))
9542 reg
= gen_raw_REG (GET_MODE (reg
), OUTGOING_REGNO (REGNO (reg
)));
9544 vec_safe_push (windowed_parm_regs
, p
);
9545 incoming
= replace_equiv_address_nv (incoming
, reg
);
9551 if (!vt_get_decl_and_offset (incoming
, &decl
, &offset
))
9553 if (MEM_P (incoming
))
9555 /* This means argument is passed by invisible reference. */
9561 if (!vt_get_decl_and_offset (decl_rtl
, &decl
, &offset
))
9563 offset
+= byte_lowpart_offset (GET_MODE (incoming
),
9564 GET_MODE (decl_rtl
));
9573 /* If that DECL_RTL wasn't a pseudo that got spilled to
9574 memory, bail out. Otherwise, the spill slot sharing code
9575 will force the memory to reference spill_slot_decl (%sfp),
9576 so we don't match above. That's ok, the pseudo must have
9577 referenced the entire parameter, so just reset OFFSET. */
9578 if (decl
!= get_spill_slot_decl (false))
9583 if (!track_loc_p (incoming
, parm
, offset
, false, &mode
, &offset
))
9586 out
= &VTI (ENTRY_BLOCK_PTR
)->out
;
9588 dv
= dv_from_decl (parm
);
9590 if (target_for_debug_bind (parm
)
9591 /* We can't deal with these right now, because this kind of
9592 variable is single-part. ??? We could handle parallels
9593 that describe multiple locations for the same single
9594 value, but ATM we don't. */
9595 && GET_CODE (incoming
) != PARALLEL
)
9600 /* ??? We shouldn't ever hit this, but it may happen because
9601 arguments passed by invisible reference aren't dealt with
9602 above: incoming-rtl will have Pmode rather than the
9603 expected mode for the type. */
9607 lowpart
= var_lowpart (mode
, incoming
);
9611 val
= cselib_lookup_from_insn (lowpart
, mode
, true,
9612 VOIDmode
, get_insns ());
9614 /* ??? Float-typed values in memory are not handled by
9618 preserve_value (val
);
9619 set_variable_part (out
, val
->val_rtx
, dv
, offset
,
9620 VAR_INIT_STATUS_INITIALIZED
, NULL
, INSERT
);
9621 dv
= dv_from_value (val
->val_rtx
);
9624 if (MEM_P (incoming
))
9626 val
= cselib_lookup_from_insn (XEXP (incoming
, 0), mode
, true,
9627 VOIDmode
, get_insns ());
9630 preserve_value (val
);
9631 incoming
= replace_equiv_address_nv (incoming
, val
->val_rtx
);
9636 if (REG_P (incoming
))
9638 incoming
= var_lowpart (mode
, incoming
);
9639 gcc_assert (REGNO (incoming
) < FIRST_PSEUDO_REGISTER
);
9640 attrs_list_insert (&out
->regs
[REGNO (incoming
)], dv
, offset
,
9642 set_variable_part (out
, incoming
, dv
, offset
,
9643 VAR_INIT_STATUS_INITIALIZED
, NULL
, INSERT
);
9644 if (dv_is_value_p (dv
))
9646 record_entry_value (CSELIB_VAL_PTR (dv_as_value (dv
)), incoming
);
9647 if (TREE_CODE (TREE_TYPE (parm
)) == REFERENCE_TYPE
9648 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (parm
))))
9650 enum machine_mode indmode
9651 = TYPE_MODE (TREE_TYPE (TREE_TYPE (parm
)));
9652 rtx mem
= gen_rtx_MEM (indmode
, incoming
);
9653 cselib_val
*val
= cselib_lookup_from_insn (mem
, indmode
, true,
9658 preserve_value (val
);
9659 record_entry_value (val
, mem
);
9660 set_variable_part (out
, mem
, dv_from_value (val
->val_rtx
), 0,
9661 VAR_INIT_STATUS_INITIALIZED
, NULL
, INSERT
);
9666 else if (MEM_P (incoming
))
9668 incoming
= var_lowpart (mode
, incoming
);
9669 set_variable_part (out
, incoming
, dv
, offset
,
9670 VAR_INIT_STATUS_INITIALIZED
, NULL
, INSERT
);
9674 /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK. */
9677 vt_add_function_parameters (void)
9681 for (parm
= DECL_ARGUMENTS (current_function_decl
);
9682 parm
; parm
= DECL_CHAIN (parm
))
9683 vt_add_function_parameter (parm
);
9685 if (DECL_HAS_VALUE_EXPR_P (DECL_RESULT (current_function_decl
)))
9687 tree vexpr
= DECL_VALUE_EXPR (DECL_RESULT (current_function_decl
));
9689 if (TREE_CODE (vexpr
) == INDIRECT_REF
)
9690 vexpr
= TREE_OPERAND (vexpr
, 0);
9692 if (TREE_CODE (vexpr
) == PARM_DECL
9693 && DECL_ARTIFICIAL (vexpr
)
9694 && !DECL_IGNORED_P (vexpr
)
9695 && DECL_NAMELESS (vexpr
))
9696 vt_add_function_parameter (vexpr
);
9700 /* Initialize cfa_base_rtx, create a preserved VALUE for it and
9701 ensure it isn't flushed during cselib_reset_table.
9702 Can be called only if frame_pointer_rtx resp. arg_pointer_rtx
9703 has been eliminated. */
9706 vt_init_cfa_base (void)
9710 #ifdef FRAME_POINTER_CFA_OFFSET
9711 cfa_base_rtx
= frame_pointer_rtx
;
9712 cfa_base_offset
= -FRAME_POINTER_CFA_OFFSET (current_function_decl
);
9714 cfa_base_rtx
= arg_pointer_rtx
;
9715 cfa_base_offset
= -ARG_POINTER_CFA_OFFSET (current_function_decl
);
9717 if (cfa_base_rtx
== hard_frame_pointer_rtx
9718 || !fixed_regs
[REGNO (cfa_base_rtx
)])
9720 cfa_base_rtx
= NULL_RTX
;
9723 if (!MAY_HAVE_DEBUG_INSNS
)
9726 /* Tell alias analysis that cfa_base_rtx should share
9727 find_base_term value with stack pointer or hard frame pointer. */
9728 if (!frame_pointer_needed
)
9729 vt_equate_reg_base_value (cfa_base_rtx
, stack_pointer_rtx
);
9730 else if (!crtl
->stack_realign_tried
)
9731 vt_equate_reg_base_value (cfa_base_rtx
, hard_frame_pointer_rtx
);
9733 val
= cselib_lookup_from_insn (cfa_base_rtx
, GET_MODE (cfa_base_rtx
), 1,
9734 VOIDmode
, get_insns ());
9735 preserve_value (val
);
9736 cselib_preserve_cfa_base_value (val
, REGNO (cfa_base_rtx
));
9739 /* Allocate and initialize the data structures for variable tracking
9740 and parse the RTL to get the micro operations. */
9743 vt_initialize (void)
9746 HOST_WIDE_INT fp_cfa_offset
= -1;
9748 alloc_aux_for_blocks (sizeof (struct variable_tracking_info_def
));
9750 attrs_pool
= create_alloc_pool ("attrs_def pool",
9751 sizeof (struct attrs_def
), 1024);
9752 var_pool
= create_alloc_pool ("variable_def pool",
9753 sizeof (struct variable_def
)
9754 + (MAX_VAR_PARTS
- 1)
9755 * sizeof (((variable
)NULL
)->var_part
[0]), 64);
9756 loc_chain_pool
= create_alloc_pool ("location_chain_def pool",
9757 sizeof (struct location_chain_def
),
9759 shared_hash_pool
= create_alloc_pool ("shared_hash_def pool",
9760 sizeof (struct shared_hash_def
), 256);
9761 empty_shared_hash
= (shared_hash
) pool_alloc (shared_hash_pool
);
9762 empty_shared_hash
->refcount
= 1;
9763 empty_shared_hash
->htab
.create (1);
9764 changed_variables
.create (10);
9766 /* Init the IN and OUT sets. */
9769 VTI (bb
)->visited
= false;
9770 VTI (bb
)->flooded
= false;
9771 dataflow_set_init (&VTI (bb
)->in
);
9772 dataflow_set_init (&VTI (bb
)->out
);
9773 VTI (bb
)->permp
= NULL
;
9776 if (MAY_HAVE_DEBUG_INSNS
)
9778 cselib_init (CSELIB_RECORD_MEMORY
| CSELIB_PRESERVE_CONSTANTS
);
9779 scratch_regs
= BITMAP_ALLOC (NULL
);
9780 valvar_pool
= create_alloc_pool ("small variable_def pool",
9781 sizeof (struct variable_def
), 256);
9782 preserved_values
.create (256);
9783 global_get_addr_cache
= pointer_map_create ();
9787 scratch_regs
= NULL
;
9789 global_get_addr_cache
= NULL
;
9792 if (MAY_HAVE_DEBUG_INSNS
)
9798 #ifdef FRAME_POINTER_CFA_OFFSET
9799 reg
= frame_pointer_rtx
;
9800 ofst
= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
9802 reg
= arg_pointer_rtx
;
9803 ofst
= ARG_POINTER_CFA_OFFSET (current_function_decl
);
9806 ofst
-= INCOMING_FRAME_SP_OFFSET
;
9808 val
= cselib_lookup_from_insn (reg
, GET_MODE (reg
), 1,
9809 VOIDmode
, get_insns ());
9810 preserve_value (val
);
9811 cselib_preserve_cfa_base_value (val
, REGNO (reg
));
9812 expr
= plus_constant (GET_MODE (stack_pointer_rtx
),
9813 stack_pointer_rtx
, -ofst
);
9814 cselib_add_permanent_equiv (val
, expr
, get_insns ());
9818 val
= cselib_lookup_from_insn (stack_pointer_rtx
,
9819 GET_MODE (stack_pointer_rtx
), 1,
9820 VOIDmode
, get_insns ());
9821 preserve_value (val
);
9822 expr
= plus_constant (GET_MODE (reg
), reg
, ofst
);
9823 cselib_add_permanent_equiv (val
, expr
, get_insns ());
9827 /* In order to factor out the adjustments made to the stack pointer or to
9828 the hard frame pointer and thus be able to use DW_OP_fbreg operations
9829 instead of individual location lists, we're going to rewrite MEMs based
9830 on them into MEMs based on the CFA by de-eliminating stack_pointer_rtx
9831 or hard_frame_pointer_rtx to the virtual CFA pointer frame_pointer_rtx
9832 resp. arg_pointer_rtx. We can do this either when there is no frame
9833 pointer in the function and stack adjustments are consistent for all
9834 basic blocks or when there is a frame pointer and no stack realignment.
9835 But we first have to check that frame_pointer_rtx resp. arg_pointer_rtx
9836 has been eliminated. */
9837 if (!frame_pointer_needed
)
9841 if (!vt_stack_adjustments ())
9844 #ifdef FRAME_POINTER_CFA_OFFSET
9845 reg
= frame_pointer_rtx
;
9847 reg
= arg_pointer_rtx
;
9849 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
9852 if (GET_CODE (elim
) == PLUS
)
9853 elim
= XEXP (elim
, 0);
9854 if (elim
== stack_pointer_rtx
)
9855 vt_init_cfa_base ();
9858 else if (!crtl
->stack_realign_tried
)
9862 #ifdef FRAME_POINTER_CFA_OFFSET
9863 reg
= frame_pointer_rtx
;
9864 fp_cfa_offset
= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
9866 reg
= arg_pointer_rtx
;
9867 fp_cfa_offset
= ARG_POINTER_CFA_OFFSET (current_function_decl
);
9869 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
9872 if (GET_CODE (elim
) == PLUS
)
9874 fp_cfa_offset
-= INTVAL (XEXP (elim
, 1));
9875 elim
= XEXP (elim
, 0);
9877 if (elim
!= hard_frame_pointer_rtx
)
9884 /* If the stack is realigned and a DRAP register is used, we're going to
9885 rewrite MEMs based on it representing incoming locations of parameters
9886 passed on the stack into MEMs based on the argument pointer. Although
9887 we aren't going to rewrite other MEMs, we still need to initialize the
9888 virtual CFA pointer in order to ensure that the argument pointer will
9889 be seen as a constant throughout the function.
9891 ??? This doesn't work if FRAME_POINTER_CFA_OFFSET is defined. */
9892 else if (stack_realign_drap
)
9896 #ifdef FRAME_POINTER_CFA_OFFSET
9897 reg
= frame_pointer_rtx
;
9899 reg
= arg_pointer_rtx
;
9901 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
9904 if (GET_CODE (elim
) == PLUS
)
9905 elim
= XEXP (elim
, 0);
9906 if (elim
== hard_frame_pointer_rtx
)
9907 vt_init_cfa_base ();
9911 hard_frame_pointer_adjustment
= -1;
9913 vt_add_function_parameters ();
9918 HOST_WIDE_INT pre
, post
= 0;
9919 basic_block first_bb
, last_bb
;
9921 if (MAY_HAVE_DEBUG_INSNS
)
9923 cselib_record_sets_hook
= add_with_sets
;
9924 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
9925 fprintf (dump_file
, "first value: %i\n",
9926 cselib_get_next_uid ());
9933 if (bb
->next_bb
== EXIT_BLOCK_PTR
9934 || ! single_pred_p (bb
->next_bb
))
9936 e
= find_edge (bb
, bb
->next_bb
);
9937 if (! e
|| (e
->flags
& EDGE_FALLTHRU
) == 0)
9943 /* Add the micro-operations to the vector. */
9944 FOR_BB_BETWEEN (bb
, first_bb
, last_bb
->next_bb
, next_bb
)
9946 HOST_WIDE_INT offset
= VTI (bb
)->out
.stack_adjust
;
9947 VTI (bb
)->out
.stack_adjust
= VTI (bb
)->in
.stack_adjust
;
9948 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
9949 insn
= NEXT_INSN (insn
))
9953 if (!frame_pointer_needed
)
9955 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
9959 mo
.type
= MO_ADJUST
;
9962 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
9963 log_op_type (PATTERN (insn
), bb
, insn
,
9964 MO_ADJUST
, dump_file
);
9965 VTI (bb
)->mos
.safe_push (mo
);
9966 VTI (bb
)->out
.stack_adjust
+= pre
;
9970 cselib_hook_called
= false;
9971 adjust_insn (bb
, insn
);
9972 if (MAY_HAVE_DEBUG_INSNS
)
9975 prepare_call_arguments (bb
, insn
);
9976 cselib_process_insn (insn
);
9977 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
9979 print_rtl_single (dump_file
, insn
);
9980 dump_cselib_table (dump_file
);
9983 if (!cselib_hook_called
)
9984 add_with_sets (insn
, 0, 0);
9987 if (!frame_pointer_needed
&& post
)
9990 mo
.type
= MO_ADJUST
;
9993 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
9994 log_op_type (PATTERN (insn
), bb
, insn
,
9995 MO_ADJUST
, dump_file
);
9996 VTI (bb
)->mos
.safe_push (mo
);
9997 VTI (bb
)->out
.stack_adjust
+= post
;
10000 if (fp_cfa_offset
!= -1
10001 && hard_frame_pointer_adjustment
== -1
10002 && fp_setter_insn (insn
))
10004 vt_init_cfa_base ();
10005 hard_frame_pointer_adjustment
= fp_cfa_offset
;
10006 /* Disassociate sp from fp now. */
10007 if (MAY_HAVE_DEBUG_INSNS
)
10010 cselib_invalidate_rtx (stack_pointer_rtx
);
10011 v
= cselib_lookup (stack_pointer_rtx
, Pmode
, 1,
10013 if (v
&& !cselib_preserved_value_p (v
))
10015 cselib_set_value_sp_based (v
);
10016 preserve_value (v
);
10022 gcc_assert (offset
== VTI (bb
)->out
.stack_adjust
);
10027 if (MAY_HAVE_DEBUG_INSNS
)
10029 cselib_preserve_only_values ();
10030 cselib_reset_table (cselib_get_next_uid ());
10031 cselib_record_sets_hook
= NULL
;
10035 hard_frame_pointer_adjustment
= -1;
10036 VTI (ENTRY_BLOCK_PTR
)->flooded
= true;
10037 cfa_base_rtx
= NULL_RTX
;
10041 /* This is *not* reset after each function. It gives each
10042 NOTE_INSN_DELETED_DEBUG_LABEL in the entire compilation
10043 a unique label number. */
10045 static int debug_label_num
= 1;
10047 /* Get rid of all debug insns from the insn stream. */
10050 delete_debug_insns (void)
10055 if (!MAY_HAVE_DEBUG_INSNS
)
10060 FOR_BB_INSNS_SAFE (bb
, insn
, next
)
10061 if (DEBUG_INSN_P (insn
))
10063 tree decl
= INSN_VAR_LOCATION_DECL (insn
);
10064 if (TREE_CODE (decl
) == LABEL_DECL
10065 && DECL_NAME (decl
)
10066 && !DECL_RTL_SET_P (decl
))
10068 PUT_CODE (insn
, NOTE
);
10069 NOTE_KIND (insn
) = NOTE_INSN_DELETED_DEBUG_LABEL
;
10070 NOTE_DELETED_LABEL_NAME (insn
)
10071 = IDENTIFIER_POINTER (DECL_NAME (decl
));
10072 SET_DECL_RTL (decl
, insn
);
10073 CODE_LABEL_NUMBER (insn
) = debug_label_num
++;
10076 delete_insn (insn
);
10081 /* Run a fast, BB-local only version of var tracking, to take care of
10082 information that we don't do global analysis on, such that not all
10083 information is lost. If SKIPPED holds, we're skipping the global
10084 pass entirely, so we should try to use information it would have
10085 handled as well.. */
10088 vt_debug_insns_local (bool skipped ATTRIBUTE_UNUSED
)
10090 /* ??? Just skip it all for now. */
10091 delete_debug_insns ();
10094 /* Free the data structures needed for variable tracking. */
10103 VTI (bb
)->mos
.release ();
10108 dataflow_set_destroy (&VTI (bb
)->in
);
10109 dataflow_set_destroy (&VTI (bb
)->out
);
10110 if (VTI (bb
)->permp
)
10112 dataflow_set_destroy (VTI (bb
)->permp
);
10113 XDELETE (VTI (bb
)->permp
);
10116 free_aux_for_blocks ();
10117 empty_shared_hash
->htab
.dispose ();
10118 changed_variables
.dispose ();
10119 free_alloc_pool (attrs_pool
);
10120 free_alloc_pool (var_pool
);
10121 free_alloc_pool (loc_chain_pool
);
10122 free_alloc_pool (shared_hash_pool
);
10124 if (MAY_HAVE_DEBUG_INSNS
)
10126 if (global_get_addr_cache
)
10127 pointer_map_destroy (global_get_addr_cache
);
10128 global_get_addr_cache
= NULL
;
10129 if (loc_exp_dep_pool
)
10130 free_alloc_pool (loc_exp_dep_pool
);
10131 loc_exp_dep_pool
= NULL
;
10132 free_alloc_pool (valvar_pool
);
10133 preserved_values
.release ();
10135 BITMAP_FREE (scratch_regs
);
10136 scratch_regs
= NULL
;
10139 #ifdef HAVE_window_save
10140 vec_free (windowed_parm_regs
);
10144 XDELETEVEC (vui_vec
);
10149 /* The entry point to variable tracking pass. */
10151 static inline unsigned int
10152 variable_tracking_main_1 (void)
10156 if (flag_var_tracking_assignments
< 0)
10158 delete_debug_insns ();
10162 if (n_basic_blocks
> 500 && n_edges
/ n_basic_blocks
>= 20)
10164 vt_debug_insns_local (true);
10168 mark_dfs_back_edges ();
10169 if (!vt_initialize ())
10172 vt_debug_insns_local (true);
10176 success
= vt_find_locations ();
10178 if (!success
&& flag_var_tracking_assignments
> 0)
10182 delete_debug_insns ();
10184 /* This is later restored by our caller. */
10185 flag_var_tracking_assignments
= 0;
10187 success
= vt_initialize ();
10188 gcc_assert (success
);
10190 success
= vt_find_locations ();
10196 vt_debug_insns_local (false);
10200 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10202 dump_dataflow_sets ();
10203 dump_reg_info (dump_file
);
10204 dump_flow_info (dump_file
, dump_flags
);
10207 timevar_push (TV_VAR_TRACKING_EMIT
);
10209 timevar_pop (TV_VAR_TRACKING_EMIT
);
10212 vt_debug_insns_local (false);
10217 variable_tracking_main (void)
10220 int save
= flag_var_tracking_assignments
;
10222 ret
= variable_tracking_main_1 ();
10224 flag_var_tracking_assignments
= save
;
10230 gate_handle_var_tracking (void)
10232 return (flag_var_tracking
&& !targetm
.delay_vartrack
);
10239 const pass_data pass_data_variable_tracking
=
10241 RTL_PASS
, /* type */
10242 "vartrack", /* name */
10243 OPTGROUP_NONE
, /* optinfo_flags */
10244 true, /* has_gate */
10245 true, /* has_execute */
10246 TV_VAR_TRACKING
, /* tv_id */
10247 0, /* properties_required */
10248 0, /* properties_provided */
10249 0, /* properties_destroyed */
10250 0, /* todo_flags_start */
10251 ( TODO_verify_rtl_sharing
| TODO_verify_flow
), /* todo_flags_finish */
10254 class pass_variable_tracking
: public rtl_opt_pass
10257 pass_variable_tracking(gcc::context
*ctxt
)
10258 : rtl_opt_pass(pass_data_variable_tracking
, ctxt
)
10261 /* opt_pass methods: */
10262 bool gate () { return gate_handle_var_tracking (); }
10263 unsigned int execute () { return variable_tracking_main (); }
10265 }; // class pass_variable_tracking
10267 } // anon namespace
10270 make_pass_variable_tracking (gcc::context
*ctxt
)
10272 return new pass_variable_tracking (ctxt
);