1 /* Variable tracking routines for the GNU compiler.
2 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* This file contains the variable tracking pass. It computes where
22 variables are located (which registers or where in memory) at each position
23 in instruction stream and emits notes describing the locations.
24 Debug information (DWARF2 location lists) is finally generated from
26 With this debug information, it is possible to show variables
27 even when debugging optimized code.
29 How does the variable tracking pass work?
31 First, it scans RTL code for uses, stores and clobbers (register/memory
32 references in instructions), for call insns and for stack adjustments
33 separately for each basic block and saves them to an array of micro
35 The micro operations of one instruction are ordered so that
36 pre-modifying stack adjustment < use < use with no var < call insn <
37 < clobber < set < post-modifying stack adjustment
39 Then, a forward dataflow analysis is performed to find out how locations
40 of variables change through code and to propagate the variable locations
41 along control flow graph.
42 The IN set for basic block BB is computed as a union of OUT sets of BB's
43 predecessors, the OUT set for BB is copied from the IN set for BB and
44 is changed according to micro operations in BB.
46 The IN and OUT sets for basic blocks consist of a current stack adjustment
47 (used for adjusting offset of variables addressed using stack pointer),
48 the table of structures describing the locations of parts of a variable
49 and for each physical register a linked list for each physical register.
50 The linked list is a list of variable parts stored in the register,
51 i.e. it is a list of triplets (reg, decl, offset) where decl is
52 REG_EXPR (reg) and offset is REG_OFFSET (reg). The linked list is used for
53 effective deleting appropriate variable parts when we set or clobber the
56 There may be more than one variable part in a register. The linked lists
57 should be pretty short so it is a good data structure here.
58 For example in the following code, register allocator may assign same
59 register to variables A and B, and both of them are stored in the same
72 Finally, the NOTE_INSN_VAR_LOCATION notes describing the variable locations
73 are emitted to appropriate positions in RTL code. Each such a note describes
74 the location of one variable at the point in instruction stream where the
75 note is. There is no need to emit a note for each variable before each
76 instruction, we only emit these notes where the location of variable changes
77 (this means that we also emit notes for changes between the OUT set of the
78 previous block and the IN set of the current block).
80 The notes consist of two parts:
81 1. the declaration (from REG_EXPR or MEM_EXPR)
82 2. the location of a variable - it is either a simple register/memory
83 reference (for simple variables, for example int),
84 or a parallel of register/memory references (for a large variables
85 which consist of several parts, for example long long).
91 #include "coretypes.h"
96 #include "hard-reg-set.h"
97 #include "basic-block.h"
99 #include "insn-config.h"
102 #include "alloc-pool.h"
108 #include "tree-pass.h"
109 #include "tree-flow.h"
113 #include "diagnostic.h"
114 #include "tree-pretty-print.h"
115 #include "pointer-set.h"
120 /* var-tracking.c assumes that tree code with the same value as VALUE rtx code
121 has no chance to appear in REG_EXPR/MEM_EXPRs and isn't a decl.
122 Currently the value is the same as IDENTIFIER_NODE, which has such
123 a property. If this compile time assertion ever fails, make sure that
124 the new tree code that equals (int) VALUE has the same property. */
125 extern char check_value_val
[(int) VALUE
== (int) IDENTIFIER_NODE
? 1 : -1];
127 /* Type of micro operation. */
128 enum micro_operation_type
130 MO_USE
, /* Use location (REG or MEM). */
131 MO_USE_NO_VAR
,/* Use location which is not associated with a variable
132 or the variable is not trackable. */
133 MO_VAL_USE
, /* Use location which is associated with a value. */
134 MO_VAL_LOC
, /* Use location which appears in a debug insn. */
135 MO_VAL_SET
, /* Set location associated with a value. */
136 MO_SET
, /* Set location. */
137 MO_COPY
, /* Copy the same portion of a variable from one
138 location to another. */
139 MO_CLOBBER
, /* Clobber location. */
140 MO_CALL
, /* Call insn. */
141 MO_ADJUST
/* Adjust stack pointer. */
145 static const char * const ATTRIBUTE_UNUSED
146 micro_operation_type_name
[] = {
159 /* Where shall the note be emitted? BEFORE or AFTER the instruction.
160 Notes emitted as AFTER_CALL are to take effect during the call,
161 rather than after the call. */
164 EMIT_NOTE_BEFORE_INSN
,
165 EMIT_NOTE_AFTER_INSN
,
166 EMIT_NOTE_AFTER_CALL_INSN
169 /* Structure holding information about micro operation. */
170 typedef struct micro_operation_def
172 /* Type of micro operation. */
173 enum micro_operation_type type
;
175 /* The instruction which the micro operation is in, for MO_USE,
176 MO_USE_NO_VAR, MO_CALL and MO_ADJUST, or the subsequent
177 instruction or note in the original flow (before any var-tracking
178 notes are inserted, to simplify emission of notes), for MO_SET
183 /* Location. For MO_SET and MO_COPY, this is the SET that
184 performs the assignment, if known, otherwise it is the target
185 of the assignment. For MO_VAL_USE and MO_VAL_SET, it is a
186 CONCAT of the VALUE and the LOC associated with it. For
187 MO_VAL_LOC, it is a CONCAT of the VALUE and the VAR_LOCATION
188 associated with it. */
191 /* Stack adjustment. */
192 HOST_WIDE_INT adjust
;
196 DEF_VEC_O(micro_operation
);
197 DEF_VEC_ALLOC_O(micro_operation
,heap
);
199 /* A declaration of a variable, or an RTL value being handled like a
201 typedef void *decl_or_value
;
203 /* Structure for passing some other parameters to function
204 emit_note_insn_var_location. */
205 typedef struct emit_note_data_def
207 /* The instruction which the note will be emitted before/after. */
210 /* Where the note will be emitted (before/after insn)? */
211 enum emit_note_where where
;
213 /* The variables and values active at this point. */
217 /* Description of location of a part of a variable. The content of a physical
218 register is described by a chain of these structures.
219 The chains are pretty short (usually 1 or 2 elements) and thus
220 chain is the best data structure. */
221 typedef struct attrs_def
223 /* Pointer to next member of the list. */
224 struct attrs_def
*next
;
226 /* The rtx of register. */
229 /* The declaration corresponding to LOC. */
232 /* Offset from start of DECL. */
233 HOST_WIDE_INT offset
;
236 /* Structure holding a refcounted hash table. If refcount > 1,
237 it must be first unshared before modified. */
238 typedef struct shared_hash_def
240 /* Reference count. */
243 /* Actual hash table. */
247 /* Structure holding the IN or OUT set for a basic block. */
248 typedef struct dataflow_set_def
250 /* Adjustment of stack offset. */
251 HOST_WIDE_INT stack_adjust
;
253 /* Attributes for registers (lists of attrs). */
254 attrs regs
[FIRST_PSEUDO_REGISTER
];
256 /* Variable locations. */
259 /* Vars that is being traversed. */
260 shared_hash traversed_vars
;
263 /* The structure (one for each basic block) containing the information
264 needed for variable tracking. */
265 typedef struct variable_tracking_info_def
267 /* The vector of micro operations. */
268 VEC(micro_operation
, heap
) *mos
;
270 /* The IN and OUT set for dataflow analysis. */
274 /* The permanent-in dataflow set for this block. This is used to
275 hold values for which we had to compute entry values. ??? This
276 should probably be dynamically allocated, to avoid using more
277 memory in non-debug builds. */
280 /* Has the block been visited in DFS? */
283 /* Has the block been flooded in VTA? */
286 } *variable_tracking_info
;
288 /* Structure for chaining the locations. */
289 typedef struct location_chain_def
291 /* Next element in the chain. */
292 struct location_chain_def
*next
;
294 /* The location (REG, MEM or VALUE). */
297 /* The "value" stored in this location. */
301 enum var_init_status init
;
304 /* A vector of loc_exp_dep holds the active dependencies of a one-part
305 DV on VALUEs, i.e., the VALUEs expanded so as to form the current
306 location of DV. Each entry is also part of VALUE' s linked-list of
307 backlinks back to DV. */
308 typedef struct loc_exp_dep_s
310 /* The dependent DV. */
312 /* The dependency VALUE or DECL_DEBUG. */
314 /* The next entry in VALUE's backlinks list. */
315 struct loc_exp_dep_s
*next
;
316 /* A pointer to the pointer to this entry (head or prev's next) in
317 the doubly-linked list. */
318 struct loc_exp_dep_s
**pprev
;
321 DEF_VEC_O (loc_exp_dep
);
323 /* This data structure holds information about the depth of a variable
325 typedef struct expand_depth_struct
327 /* This measures the complexity of the expanded expression. It
328 grows by one for each level of expansion that adds more than one
331 /* This counts the number of ENTRY_VALUE expressions in an
332 expansion. We want to minimize their use. */
336 /* This data structure is allocated for one-part variables at the time
337 of emitting notes. */
340 /* Doubly-linked list of dependent DVs. These are DVs whose cur_loc
341 computation used the expansion of this variable, and that ought
342 to be notified should this variable change. If the DV's cur_loc
343 expanded to NULL, all components of the loc list are regarded as
344 active, so that any changes in them give us a chance to get a
345 location. Otherwise, only components of the loc that expanded to
346 non-NULL are regarded as active dependencies. */
347 loc_exp_dep
*backlinks
;
348 /* This holds the LOC that was expanded into cur_loc. We need only
349 mark a one-part variable as changed if the FROM loc is removed,
350 or if it has no known location and a loc is added, or if it gets
351 a change notification from any of its active dependencies. */
353 /* The depth of the cur_loc expression. */
355 /* Dependencies actively used when expand FROM into cur_loc. */
356 VEC (loc_exp_dep
, none
) deps
;
359 /* Structure describing one part of variable. */
360 typedef struct variable_part_def
362 /* Chain of locations of the part. */
363 location_chain loc_chain
;
365 /* Location which was last emitted to location list. */
370 /* The offset in the variable, if !var->onepart. */
371 HOST_WIDE_INT offset
;
373 /* Pointer to auxiliary data, if var->onepart and emit_notes. */
374 struct onepart_aux
*onepaux
;
378 /* Maximum number of location parts. */
379 #define MAX_VAR_PARTS 16
381 /* Enumeration type used to discriminate various types of one-part
383 typedef enum onepart_enum
385 /* Not a one-part variable. */
387 /* A one-part DECL that is not a DEBUG_EXPR_DECL. */
389 /* A DEBUG_EXPR_DECL. */
395 /* Structure describing where the variable is located. */
396 typedef struct variable_def
398 /* The declaration of the variable, or an RTL value being handled
399 like a declaration. */
402 /* Reference count. */
405 /* Number of variable parts. */
408 /* What type of DV this is, according to enum onepart_enum. */
409 ENUM_BITFIELD (onepart_enum
) onepart
: CHAR_BIT
;
411 /* True if this variable_def struct is currently in the
412 changed_variables hash table. */
413 bool in_changed_variables
;
415 /* The variable parts. */
416 variable_part var_part
[1];
418 typedef const struct variable_def
*const_variable
;
420 /* Pointer to the BB's information specific to variable tracking pass. */
421 #define VTI(BB) ((variable_tracking_info) (BB)->aux)
423 /* Macro to access MEM_OFFSET as an HOST_WIDE_INT. Evaluates MEM twice. */
424 #define INT_MEM_OFFSET(mem) (MEM_OFFSET_KNOWN_P (mem) ? MEM_OFFSET (mem) : 0)
426 #if ENABLE_CHECKING && (GCC_VERSION >= 2007)
428 /* Access VAR's Ith part's offset, checking that it's not a one-part
430 #define VAR_PART_OFFSET(var, i) __extension__ \
431 (*({ variable const __v = (var); \
432 gcc_checking_assert (!__v->onepart); \
433 &__v->var_part[(i)].aux.offset; }))
435 /* Access VAR's one-part auxiliary data, checking that it is a
436 one-part variable. */
437 #define VAR_LOC_1PAUX(var) __extension__ \
438 (*({ variable const __v = (var); \
439 gcc_checking_assert (__v->onepart); \
440 &__v->var_part[0].aux.onepaux; }))
443 #define VAR_PART_OFFSET(var, i) ((var)->var_part[(i)].aux.offset)
444 #define VAR_LOC_1PAUX(var) ((var)->var_part[0].aux.onepaux)
447 /* These are accessor macros for the one-part auxiliary data. When
448 convenient for users, they're guarded by tests that the data was
450 #define VAR_LOC_DEP_LST(var) (VAR_LOC_1PAUX (var) \
451 ? VAR_LOC_1PAUX (var)->backlinks \
453 #define VAR_LOC_DEP_LSTP(var) (VAR_LOC_1PAUX (var) \
454 ? &VAR_LOC_1PAUX (var)->backlinks \
456 #define VAR_LOC_FROM(var) (VAR_LOC_1PAUX (var)->from)
457 #define VAR_LOC_DEPTH(var) (VAR_LOC_1PAUX (var)->depth)
458 #define VAR_LOC_DEP_VEC(var) (VAR_LOC_1PAUX (var) \
459 ? &VAR_LOC_1PAUX (var)->deps \
462 /* Alloc pool for struct attrs_def. */
463 static alloc_pool attrs_pool
;
465 /* Alloc pool for struct variable_def with MAX_VAR_PARTS entries. */
466 static alloc_pool var_pool
;
468 /* Alloc pool for struct variable_def with a single var_part entry. */
469 static alloc_pool valvar_pool
;
471 /* Alloc pool for struct location_chain_def. */
472 static alloc_pool loc_chain_pool
;
474 /* Alloc pool for struct shared_hash_def. */
475 static alloc_pool shared_hash_pool
;
477 /* Alloc pool for struct loc_exp_dep_s for NOT_ONEPART variables. */
478 static alloc_pool loc_exp_dep_pool
;
480 /* Changed variables, notes will be emitted for them. */
481 static htab_t changed_variables
;
483 /* Shall notes be emitted? */
484 static bool emit_notes
;
486 /* Values whose dynamic location lists have gone empty, but whose
487 cselib location lists are still usable. Use this to hold the
488 current location, the backlinks, etc, during emit_notes. */
489 static htab_t dropped_values
;
491 /* Empty shared hashtable. */
492 static shared_hash empty_shared_hash
;
494 /* Scratch register bitmap used by cselib_expand_value_rtx. */
495 static bitmap scratch_regs
= NULL
;
497 #ifdef HAVE_window_save
498 typedef struct GTY(()) parm_reg
{
503 DEF_VEC_O(parm_reg_t
);
504 DEF_VEC_ALLOC_O(parm_reg_t
, gc
);
506 /* Vector of windowed parameter registers, if any. */
507 static VEC(parm_reg_t
, gc
) *windowed_parm_regs
= NULL
;
510 /* Variable used to tell whether cselib_process_insn called our hook. */
511 static bool cselib_hook_called
;
513 /* Local function prototypes. */
514 static void stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
516 static void insn_stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
518 static bool vt_stack_adjustments (void);
519 static hashval_t
variable_htab_hash (const void *);
520 static int variable_htab_eq (const void *, const void *);
521 static void variable_htab_free (void *);
523 static void init_attrs_list_set (attrs
*);
524 static void attrs_list_clear (attrs
*);
525 static attrs
attrs_list_member (attrs
, decl_or_value
, HOST_WIDE_INT
);
526 static void attrs_list_insert (attrs
*, decl_or_value
, HOST_WIDE_INT
, rtx
);
527 static void attrs_list_copy (attrs
*, attrs
);
528 static void attrs_list_union (attrs
*, attrs
);
530 static void **unshare_variable (dataflow_set
*set
, void **slot
, variable var
,
531 enum var_init_status
);
532 static void vars_copy (htab_t
, htab_t
);
533 static tree
var_debug_decl (tree
);
534 static void var_reg_set (dataflow_set
*, rtx
, enum var_init_status
, rtx
);
535 static void var_reg_delete_and_set (dataflow_set
*, rtx
, bool,
536 enum var_init_status
, rtx
);
537 static void var_reg_delete (dataflow_set
*, rtx
, bool);
538 static void var_regno_delete (dataflow_set
*, int);
539 static void var_mem_set (dataflow_set
*, rtx
, enum var_init_status
, rtx
);
540 static void var_mem_delete_and_set (dataflow_set
*, rtx
, bool,
541 enum var_init_status
, rtx
);
542 static void var_mem_delete (dataflow_set
*, rtx
, bool);
544 static void dataflow_set_init (dataflow_set
*);
545 static void dataflow_set_clear (dataflow_set
*);
546 static void dataflow_set_copy (dataflow_set
*, dataflow_set
*);
547 static int variable_union_info_cmp_pos (const void *, const void *);
548 static void dataflow_set_union (dataflow_set
*, dataflow_set
*);
549 static location_chain
find_loc_in_1pdv (rtx
, variable
, htab_t
);
550 static bool canon_value_cmp (rtx
, rtx
);
551 static int loc_cmp (rtx
, rtx
);
552 static bool variable_part_different_p (variable_part
*, variable_part
*);
553 static bool onepart_variable_different_p (variable
, variable
);
554 static bool variable_different_p (variable
, variable
);
555 static bool dataflow_set_different (dataflow_set
*, dataflow_set
*);
556 static void dataflow_set_destroy (dataflow_set
*);
558 static bool contains_symbol_ref (rtx
);
559 static bool track_expr_p (tree
, bool);
560 static bool same_variable_part_p (rtx
, tree
, HOST_WIDE_INT
);
561 static int add_uses (rtx
*, void *);
562 static void add_uses_1 (rtx
*, void *);
563 static void add_stores (rtx
, const_rtx
, void *);
564 static bool compute_bb_dataflow (basic_block
);
565 static bool vt_find_locations (void);
567 static void dump_attrs_list (attrs
);
568 static int dump_var_slot (void **, void *);
569 static void dump_var (variable
);
570 static void dump_vars (htab_t
);
571 static void dump_dataflow_set (dataflow_set
*);
572 static void dump_dataflow_sets (void);
574 static void set_dv_changed (decl_or_value
, bool);
575 static void variable_was_changed (variable
, dataflow_set
*);
576 static void **set_slot_part (dataflow_set
*, rtx
, void **,
577 decl_or_value
, HOST_WIDE_INT
,
578 enum var_init_status
, rtx
);
579 static void set_variable_part (dataflow_set
*, rtx
,
580 decl_or_value
, HOST_WIDE_INT
,
581 enum var_init_status
, rtx
, enum insert_option
);
582 static void **clobber_slot_part (dataflow_set
*, rtx
,
583 void **, HOST_WIDE_INT
, rtx
);
584 static void clobber_variable_part (dataflow_set
*, rtx
,
585 decl_or_value
, HOST_WIDE_INT
, rtx
);
586 static void **delete_slot_part (dataflow_set
*, rtx
, void **, HOST_WIDE_INT
);
587 static void delete_variable_part (dataflow_set
*, rtx
,
588 decl_or_value
, HOST_WIDE_INT
);
589 static int emit_note_insn_var_location (void **, void *);
590 static void emit_notes_for_changes (rtx
, enum emit_note_where
, shared_hash
);
591 static int emit_notes_for_differences_1 (void **, void *);
592 static int emit_notes_for_differences_2 (void **, void *);
593 static void emit_notes_for_differences (rtx
, dataflow_set
*, dataflow_set
*);
594 static void emit_notes_in_bb (basic_block
, dataflow_set
*);
595 static void vt_emit_notes (void);
597 static bool vt_get_decl_and_offset (rtx
, tree
*, HOST_WIDE_INT
*);
598 static void vt_add_function_parameters (void);
599 static bool vt_initialize (void);
600 static void vt_finalize (void);
602 /* Given a SET, calculate the amount of stack adjustment it contains
603 PRE- and POST-modifying stack pointer.
604 This function is similar to stack_adjust_offset. */
607 stack_adjust_offset_pre_post (rtx pattern
, HOST_WIDE_INT
*pre
,
610 rtx src
= SET_SRC (pattern
);
611 rtx dest
= SET_DEST (pattern
);
614 if (dest
== stack_pointer_rtx
)
616 /* (set (reg sp) (plus (reg sp) (const_int))) */
617 code
= GET_CODE (src
);
618 if (! (code
== PLUS
|| code
== MINUS
)
619 || XEXP (src
, 0) != stack_pointer_rtx
620 || !CONST_INT_P (XEXP (src
, 1)))
624 *post
+= INTVAL (XEXP (src
, 1));
626 *post
-= INTVAL (XEXP (src
, 1));
628 else if (MEM_P (dest
))
630 /* (set (mem (pre_dec (reg sp))) (foo)) */
631 src
= XEXP (dest
, 0);
632 code
= GET_CODE (src
);
638 if (XEXP (src
, 0) == stack_pointer_rtx
)
640 rtx val
= XEXP (XEXP (src
, 1), 1);
641 /* We handle only adjustments by constant amount. */
642 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
&&
645 if (code
== PRE_MODIFY
)
646 *pre
-= INTVAL (val
);
648 *post
-= INTVAL (val
);
654 if (XEXP (src
, 0) == stack_pointer_rtx
)
656 *pre
+= GET_MODE_SIZE (GET_MODE (dest
));
662 if (XEXP (src
, 0) == stack_pointer_rtx
)
664 *post
+= GET_MODE_SIZE (GET_MODE (dest
));
670 if (XEXP (src
, 0) == stack_pointer_rtx
)
672 *pre
-= GET_MODE_SIZE (GET_MODE (dest
));
678 if (XEXP (src
, 0) == stack_pointer_rtx
)
680 *post
-= GET_MODE_SIZE (GET_MODE (dest
));
691 /* Given an INSN, calculate the amount of stack adjustment it contains
692 PRE- and POST-modifying stack pointer. */
695 insn_stack_adjust_offset_pre_post (rtx insn
, HOST_WIDE_INT
*pre
,
703 pattern
= PATTERN (insn
);
704 if (RTX_FRAME_RELATED_P (insn
))
706 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
708 pattern
= XEXP (expr
, 0);
711 if (GET_CODE (pattern
) == SET
)
712 stack_adjust_offset_pre_post (pattern
, pre
, post
);
713 else if (GET_CODE (pattern
) == PARALLEL
714 || GET_CODE (pattern
) == SEQUENCE
)
718 /* There may be stack adjustments inside compound insns. Search
720 for ( i
= XVECLEN (pattern
, 0) - 1; i
>= 0; i
--)
721 if (GET_CODE (XVECEXP (pattern
, 0, i
)) == SET
)
722 stack_adjust_offset_pre_post (XVECEXP (pattern
, 0, i
), pre
, post
);
726 /* Compute stack adjustments for all blocks by traversing DFS tree.
727 Return true when the adjustments on all incoming edges are consistent.
728 Heavily borrowed from pre_and_rev_post_order_compute. */
731 vt_stack_adjustments (void)
733 edge_iterator
*stack
;
736 /* Initialize entry block. */
737 VTI (ENTRY_BLOCK_PTR
)->visited
= true;
738 VTI (ENTRY_BLOCK_PTR
)->in
.stack_adjust
= INCOMING_FRAME_SP_OFFSET
;
739 VTI (ENTRY_BLOCK_PTR
)->out
.stack_adjust
= INCOMING_FRAME_SP_OFFSET
;
741 /* Allocate stack for back-tracking up CFG. */
742 stack
= XNEWVEC (edge_iterator
, n_basic_blocks
+ 1);
745 /* Push the first edge on to the stack. */
746 stack
[sp
++] = ei_start (ENTRY_BLOCK_PTR
->succs
);
754 /* Look at the edge on the top of the stack. */
756 src
= ei_edge (ei
)->src
;
757 dest
= ei_edge (ei
)->dest
;
759 /* Check if the edge destination has been visited yet. */
760 if (!VTI (dest
)->visited
)
763 HOST_WIDE_INT pre
, post
, offset
;
764 VTI (dest
)->visited
= true;
765 VTI (dest
)->in
.stack_adjust
= offset
= VTI (src
)->out
.stack_adjust
;
767 if (dest
!= EXIT_BLOCK_PTR
)
768 for (insn
= BB_HEAD (dest
);
769 insn
!= NEXT_INSN (BB_END (dest
));
770 insn
= NEXT_INSN (insn
))
773 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
774 offset
+= pre
+ post
;
777 VTI (dest
)->out
.stack_adjust
= offset
;
779 if (EDGE_COUNT (dest
->succs
) > 0)
780 /* Since the DEST node has been visited for the first
781 time, check its successors. */
782 stack
[sp
++] = ei_start (dest
->succs
);
786 /* Check whether the adjustments on the edges are the same. */
787 if (VTI (dest
)->in
.stack_adjust
!= VTI (src
)->out
.stack_adjust
)
793 if (! ei_one_before_end_p (ei
))
794 /* Go to the next edge. */
795 ei_next (&stack
[sp
- 1]);
797 /* Return to previous level if there are no more edges. */
806 /* arg_pointer_rtx resp. frame_pointer_rtx if stack_pointer_rtx or
807 hard_frame_pointer_rtx is being mapped to it and offset for it. */
808 static rtx cfa_base_rtx
;
809 static HOST_WIDE_INT cfa_base_offset
;
811 /* Compute a CFA-based value for an ADJUSTMENT made to stack_pointer_rtx
812 or hard_frame_pointer_rtx. */
815 compute_cfa_pointer (HOST_WIDE_INT adjustment
)
817 return plus_constant (Pmode
, cfa_base_rtx
, adjustment
+ cfa_base_offset
);
820 /* Adjustment for hard_frame_pointer_rtx to cfa base reg,
821 or -1 if the replacement shouldn't be done. */
822 static HOST_WIDE_INT hard_frame_pointer_adjustment
= -1;
824 /* Data for adjust_mems callback. */
826 struct adjust_mem_data
829 enum machine_mode mem_mode
;
830 HOST_WIDE_INT stack_adjust
;
834 /* Helper for adjust_mems. Return 1 if *loc is unsuitable for
835 transformation of wider mode arithmetics to narrower mode,
836 -1 if it is suitable and subexpressions shouldn't be
837 traversed and 0 if it is suitable and subexpressions should
838 be traversed. Called through for_each_rtx. */
841 use_narrower_mode_test (rtx
*loc
, void *data
)
843 rtx subreg
= (rtx
) data
;
845 if (CONSTANT_P (*loc
))
847 switch (GET_CODE (*loc
))
850 if (cselib_lookup (*loc
, GET_MODE (SUBREG_REG (subreg
)), 0, VOIDmode
))
852 if (!validate_subreg (GET_MODE (subreg
), GET_MODE (*loc
),
853 *loc
, subreg_lowpart_offset (GET_MODE (subreg
),
862 if (for_each_rtx (&XEXP (*loc
, 0), use_narrower_mode_test
, data
))
871 /* Transform X into narrower mode MODE from wider mode WMODE. */
874 use_narrower_mode (rtx x
, enum machine_mode mode
, enum machine_mode wmode
)
878 return lowpart_subreg (mode
, x
, wmode
);
879 switch (GET_CODE (x
))
882 return lowpart_subreg (mode
, x
, wmode
);
886 op0
= use_narrower_mode (XEXP (x
, 0), mode
, wmode
);
887 op1
= use_narrower_mode (XEXP (x
, 1), mode
, wmode
);
888 return simplify_gen_binary (GET_CODE (x
), mode
, op0
, op1
);
890 op0
= use_narrower_mode (XEXP (x
, 0), mode
, wmode
);
891 return simplify_gen_binary (ASHIFT
, mode
, op0
, XEXP (x
, 1));
897 /* Helper function for adjusting used MEMs. */
900 adjust_mems (rtx loc
, const_rtx old_rtx
, void *data
)
902 struct adjust_mem_data
*amd
= (struct adjust_mem_data
*) data
;
903 rtx mem
, addr
= loc
, tem
;
904 enum machine_mode mem_mode_save
;
906 switch (GET_CODE (loc
))
909 /* Don't do any sp or fp replacements outside of MEM addresses
911 if (amd
->mem_mode
== VOIDmode
&& amd
->store
)
913 if (loc
== stack_pointer_rtx
914 && !frame_pointer_needed
916 return compute_cfa_pointer (amd
->stack_adjust
);
917 else if (loc
== hard_frame_pointer_rtx
918 && frame_pointer_needed
919 && hard_frame_pointer_adjustment
!= -1
921 return compute_cfa_pointer (hard_frame_pointer_adjustment
);
922 gcc_checking_assert (loc
!= virtual_incoming_args_rtx
);
928 mem
= targetm
.delegitimize_address (mem
);
929 if (mem
!= loc
&& !MEM_P (mem
))
930 return simplify_replace_fn_rtx (mem
, old_rtx
, adjust_mems
, data
);
933 addr
= XEXP (mem
, 0);
934 mem_mode_save
= amd
->mem_mode
;
935 amd
->mem_mode
= GET_MODE (mem
);
936 store_save
= amd
->store
;
938 addr
= simplify_replace_fn_rtx (addr
, old_rtx
, adjust_mems
, data
);
939 amd
->store
= store_save
;
940 amd
->mem_mode
= mem_mode_save
;
942 addr
= targetm
.delegitimize_address (addr
);
943 if (addr
!= XEXP (mem
, 0))
944 mem
= replace_equiv_address_nv (mem
, addr
);
946 mem
= avoid_constant_pool_reference (mem
);
950 addr
= gen_rtx_PLUS (GET_MODE (loc
), XEXP (loc
, 0),
951 GEN_INT (GET_CODE (loc
) == PRE_INC
952 ? GET_MODE_SIZE (amd
->mem_mode
)
953 : -GET_MODE_SIZE (amd
->mem_mode
)));
957 addr
= XEXP (loc
, 0);
958 gcc_assert (amd
->mem_mode
!= VOIDmode
&& amd
->mem_mode
!= BLKmode
);
959 addr
= simplify_replace_fn_rtx (addr
, old_rtx
, adjust_mems
, data
);
960 tem
= gen_rtx_PLUS (GET_MODE (loc
), XEXP (loc
, 0),
961 GEN_INT ((GET_CODE (loc
) == PRE_INC
962 || GET_CODE (loc
) == POST_INC
)
963 ? GET_MODE_SIZE (amd
->mem_mode
)
964 : -GET_MODE_SIZE (amd
->mem_mode
)));
965 amd
->side_effects
= alloc_EXPR_LIST (0,
966 gen_rtx_SET (VOIDmode
,
972 addr
= XEXP (loc
, 1);
975 addr
= XEXP (loc
, 0);
976 gcc_assert (amd
->mem_mode
!= VOIDmode
);
977 addr
= simplify_replace_fn_rtx (addr
, old_rtx
, adjust_mems
, data
);
978 amd
->side_effects
= alloc_EXPR_LIST (0,
979 gen_rtx_SET (VOIDmode
,
985 /* First try without delegitimization of whole MEMs and
986 avoid_constant_pool_reference, which is more likely to succeed. */
987 store_save
= amd
->store
;
989 addr
= simplify_replace_fn_rtx (SUBREG_REG (loc
), old_rtx
, adjust_mems
,
991 amd
->store
= store_save
;
992 mem
= simplify_replace_fn_rtx (addr
, old_rtx
, adjust_mems
, data
);
993 if (mem
== SUBREG_REG (loc
))
998 tem
= simplify_gen_subreg (GET_MODE (loc
), mem
,
999 GET_MODE (SUBREG_REG (loc
)),
1003 tem
= simplify_gen_subreg (GET_MODE (loc
), addr
,
1004 GET_MODE (SUBREG_REG (loc
)),
1006 if (tem
== NULL_RTX
)
1007 tem
= gen_rtx_raw_SUBREG (GET_MODE (loc
), addr
, SUBREG_BYTE (loc
));
1009 if (MAY_HAVE_DEBUG_INSNS
1010 && GET_CODE (tem
) == SUBREG
1011 && (GET_CODE (SUBREG_REG (tem
)) == PLUS
1012 || GET_CODE (SUBREG_REG (tem
)) == MINUS
1013 || GET_CODE (SUBREG_REG (tem
)) == MULT
1014 || GET_CODE (SUBREG_REG (tem
)) == ASHIFT
)
1015 && GET_MODE_CLASS (GET_MODE (tem
)) == MODE_INT
1016 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (tem
))) == MODE_INT
1017 && GET_MODE_SIZE (GET_MODE (tem
))
1018 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (tem
)))
1019 && subreg_lowpart_p (tem
)
1020 && !for_each_rtx (&SUBREG_REG (tem
), use_narrower_mode_test
, tem
))
1021 return use_narrower_mode (SUBREG_REG (tem
), GET_MODE (tem
),
1022 GET_MODE (SUBREG_REG (tem
)));
1025 /* Don't do any replacements in second and following
1026 ASM_OPERANDS of inline-asm with multiple sets.
1027 ASM_OPERANDS_INPUT_VEC, ASM_OPERANDS_INPUT_CONSTRAINT_VEC
1028 and ASM_OPERANDS_LABEL_VEC need to be equal between
1029 all the ASM_OPERANDs in the insn and adjust_insn will
1031 if (ASM_OPERANDS_OUTPUT_IDX (loc
) != 0)
1040 /* Helper function for replacement of uses. */
1043 adjust_mem_uses (rtx
*x
, void *data
)
1045 rtx new_x
= simplify_replace_fn_rtx (*x
, NULL_RTX
, adjust_mems
, data
);
1047 validate_change (NULL_RTX
, x
, new_x
, true);
1050 /* Helper function for replacement of stores. */
1053 adjust_mem_stores (rtx loc
, const_rtx expr
, void *data
)
1057 rtx new_dest
= simplify_replace_fn_rtx (SET_DEST (expr
), NULL_RTX
,
1059 if (new_dest
!= SET_DEST (expr
))
1061 rtx xexpr
= CONST_CAST_RTX (expr
);
1062 validate_change (NULL_RTX
, &SET_DEST (xexpr
), new_dest
, true);
1067 /* Simplify INSN. Remove all {PRE,POST}_{INC,DEC,MODIFY} rtxes,
1068 replace them with their value in the insn and add the side-effects
1069 as other sets to the insn. */
1072 adjust_insn (basic_block bb
, rtx insn
)
1074 struct adjust_mem_data amd
;
1077 #ifdef HAVE_window_save
1078 /* If the target machine has an explicit window save instruction, the
1079 transformation OUTGOING_REGNO -> INCOMING_REGNO is done there. */
1080 if (RTX_FRAME_RELATED_P (insn
)
1081 && find_reg_note (insn
, REG_CFA_WINDOW_SAVE
, NULL_RTX
))
1083 unsigned int i
, nregs
= VEC_length(parm_reg_t
, windowed_parm_regs
);
1084 rtx rtl
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (nregs
* 2));
1087 FOR_EACH_VEC_ELT (parm_reg_t
, windowed_parm_regs
, i
, p
)
1089 XVECEXP (rtl
, 0, i
* 2)
1090 = gen_rtx_SET (VOIDmode
, p
->incoming
, p
->outgoing
);
1091 /* Do not clobber the attached DECL, but only the REG. */
1092 XVECEXP (rtl
, 0, i
* 2 + 1)
1093 = gen_rtx_CLOBBER (GET_MODE (p
->outgoing
),
1094 gen_raw_REG (GET_MODE (p
->outgoing
),
1095 REGNO (p
->outgoing
)));
1098 validate_change (NULL_RTX
, &PATTERN (insn
), rtl
, true);
1103 amd
.mem_mode
= VOIDmode
;
1104 amd
.stack_adjust
= -VTI (bb
)->out
.stack_adjust
;
1105 amd
.side_effects
= NULL_RTX
;
1108 note_stores (PATTERN (insn
), adjust_mem_stores
, &amd
);
1111 if (GET_CODE (PATTERN (insn
)) == PARALLEL
1112 && asm_noperands (PATTERN (insn
)) > 0
1113 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == SET
)
1118 /* inline-asm with multiple sets is tiny bit more complicated,
1119 because the 3 vectors in ASM_OPERANDS need to be shared between
1120 all ASM_OPERANDS in the instruction. adjust_mems will
1121 not touch ASM_OPERANDS other than the first one, asm_noperands
1122 test above needs to be called before that (otherwise it would fail)
1123 and afterwards this code fixes it up. */
1124 note_uses (&PATTERN (insn
), adjust_mem_uses
, &amd
);
1125 body
= PATTERN (insn
);
1126 set0
= XVECEXP (body
, 0, 0);
1127 gcc_checking_assert (GET_CODE (set0
) == SET
1128 && GET_CODE (SET_SRC (set0
)) == ASM_OPERANDS
1129 && ASM_OPERANDS_OUTPUT_IDX (SET_SRC (set0
)) == 0);
1130 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1131 if (GET_CODE (XVECEXP (body
, 0, i
)) != SET
)
1135 set
= XVECEXP (body
, 0, i
);
1136 gcc_checking_assert (GET_CODE (SET_SRC (set
)) == ASM_OPERANDS
1137 && ASM_OPERANDS_OUTPUT_IDX (SET_SRC (set
))
1139 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (set
))
1140 != ASM_OPERANDS_INPUT_VEC (SET_SRC (set0
))
1141 || ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set
))
1142 != ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set0
))
1143 || ASM_OPERANDS_LABEL_VEC (SET_SRC (set
))
1144 != ASM_OPERANDS_LABEL_VEC (SET_SRC (set0
)))
1146 rtx newsrc
= shallow_copy_rtx (SET_SRC (set
));
1147 ASM_OPERANDS_INPUT_VEC (newsrc
)
1148 = ASM_OPERANDS_INPUT_VEC (SET_SRC (set0
));
1149 ASM_OPERANDS_INPUT_CONSTRAINT_VEC (newsrc
)
1150 = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (SET_SRC (set0
));
1151 ASM_OPERANDS_LABEL_VEC (newsrc
)
1152 = ASM_OPERANDS_LABEL_VEC (SET_SRC (set0
));
1153 validate_change (NULL_RTX
, &SET_SRC (set
), newsrc
, true);
1158 note_uses (&PATTERN (insn
), adjust_mem_uses
, &amd
);
1160 /* For read-only MEMs containing some constant, prefer those
1162 set
= single_set (insn
);
1163 if (set
&& MEM_P (SET_SRC (set
)) && MEM_READONLY_P (SET_SRC (set
)))
1165 rtx note
= find_reg_equal_equiv_note (insn
);
1167 if (note
&& CONSTANT_P (XEXP (note
, 0)))
1168 validate_change (NULL_RTX
, &SET_SRC (set
), XEXP (note
, 0), true);
1171 if (amd
.side_effects
)
1173 rtx
*pat
, new_pat
, s
;
1176 pat
= &PATTERN (insn
);
1177 if (GET_CODE (*pat
) == COND_EXEC
)
1178 pat
= &COND_EXEC_CODE (*pat
);
1179 if (GET_CODE (*pat
) == PARALLEL
)
1180 oldn
= XVECLEN (*pat
, 0);
1183 for (s
= amd
.side_effects
, newn
= 0; s
; newn
++)
1185 new_pat
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (oldn
+ newn
));
1186 if (GET_CODE (*pat
) == PARALLEL
)
1187 for (i
= 0; i
< oldn
; i
++)
1188 XVECEXP (new_pat
, 0, i
) = XVECEXP (*pat
, 0, i
);
1190 XVECEXP (new_pat
, 0, 0) = *pat
;
1191 for (s
= amd
.side_effects
, i
= oldn
; i
< oldn
+ newn
; i
++, s
= XEXP (s
, 1))
1192 XVECEXP (new_pat
, 0, i
) = XEXP (s
, 0);
1193 free_EXPR_LIST_list (&amd
.side_effects
);
1194 validate_change (NULL_RTX
, pat
, new_pat
, true);
1198 /* Return true if a decl_or_value DV is a DECL or NULL. */
1200 dv_is_decl_p (decl_or_value dv
)
1202 return !dv
|| (int) TREE_CODE ((tree
) dv
) != (int) VALUE
;
1205 /* Return true if a decl_or_value is a VALUE rtl. */
1207 dv_is_value_p (decl_or_value dv
)
1209 return dv
&& !dv_is_decl_p (dv
);
1212 /* Return the decl in the decl_or_value. */
1214 dv_as_decl (decl_or_value dv
)
1216 gcc_checking_assert (dv_is_decl_p (dv
));
1220 /* Return the value in the decl_or_value. */
1222 dv_as_value (decl_or_value dv
)
1224 gcc_checking_assert (dv_is_value_p (dv
));
1228 /* Return the DEBUG_EXPR of a DEBUG_EXPR_DECL or the VALUE in DV. */
1230 dv_as_rtx (decl_or_value dv
)
1234 if (dv_is_value_p (dv
))
1235 return dv_as_value (dv
);
1237 decl
= dv_as_decl (dv
);
1239 gcc_checking_assert (TREE_CODE (decl
) == DEBUG_EXPR_DECL
);
1240 return DECL_RTL_KNOWN_SET (decl
);
1243 /* Return the opaque pointer in the decl_or_value. */
1244 static inline void *
1245 dv_as_opaque (decl_or_value dv
)
1250 /* Return nonzero if a decl_or_value must not have more than one
1251 variable part. The returned value discriminates among various
1252 kinds of one-part DVs ccording to enum onepart_enum. */
1253 static inline onepart_enum_t
1254 dv_onepart_p (decl_or_value dv
)
1258 if (!MAY_HAVE_DEBUG_INSNS
)
1261 if (dv_is_value_p (dv
))
1262 return ONEPART_VALUE
;
1264 decl
= dv_as_decl (dv
);
1266 if (TREE_CODE (decl
) == DEBUG_EXPR_DECL
)
1267 return ONEPART_DEXPR
;
1269 if (target_for_debug_bind (decl
) != NULL_TREE
)
1270 return ONEPART_VDECL
;
1275 /* Return the variable pool to be used for a dv of type ONEPART. */
1276 static inline alloc_pool
1277 onepart_pool (onepart_enum_t onepart
)
1279 return onepart
? valvar_pool
: var_pool
;
1282 /* Build a decl_or_value out of a decl. */
1283 static inline decl_or_value
1284 dv_from_decl (tree decl
)
1288 gcc_checking_assert (dv_is_decl_p (dv
));
1292 /* Build a decl_or_value out of a value. */
1293 static inline decl_or_value
1294 dv_from_value (rtx value
)
1298 gcc_checking_assert (dv_is_value_p (dv
));
1302 /* Return a value or the decl of a debug_expr as a decl_or_value. */
1303 static inline decl_or_value
1308 switch (GET_CODE (x
))
1311 dv
= dv_from_decl (DEBUG_EXPR_TREE_DECL (x
));
1312 gcc_checking_assert (DECL_RTL_KNOWN_SET (DEBUG_EXPR_TREE_DECL (x
)) == x
);
1316 dv
= dv_from_value (x
);
1326 extern void debug_dv (decl_or_value dv
);
1329 debug_dv (decl_or_value dv
)
1331 if (dv_is_value_p (dv
))
1332 debug_rtx (dv_as_value (dv
));
1334 debug_generic_stmt (dv_as_decl (dv
));
1337 typedef unsigned int dvuid
;
1339 /* Return the uid of DV. */
1342 dv_uid (decl_or_value dv
)
1344 if (dv_is_value_p (dv
))
1345 return CSELIB_VAL_PTR (dv_as_value (dv
))->uid
;
1347 return DECL_UID (dv_as_decl (dv
));
1350 /* Compute the hash from the uid. */
1352 static inline hashval_t
1353 dv_uid2hash (dvuid uid
)
1358 /* The hash function for a mask table in a shared_htab chain. */
1360 static inline hashval_t
1361 dv_htab_hash (decl_or_value dv
)
1363 return dv_uid2hash (dv_uid (dv
));
1366 /* The hash function for variable_htab, computes the hash value
1367 from the declaration of variable X. */
1370 variable_htab_hash (const void *x
)
1372 const_variable
const v
= (const_variable
) x
;
1374 return dv_htab_hash (v
->dv
);
1377 /* Compare the declaration of variable X with declaration Y. */
1380 variable_htab_eq (const void *x
, const void *y
)
1382 const_variable
const v
= (const_variable
) x
;
1383 decl_or_value dv
= CONST_CAST2 (decl_or_value
, const void *, y
);
1385 return (dv_as_opaque (v
->dv
) == dv_as_opaque (dv
));
1388 static void loc_exp_dep_clear (variable var
);
1390 /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
1393 variable_htab_free (void *elem
)
1396 variable var
= (variable
) elem
;
1397 location_chain node
, next
;
1399 gcc_checking_assert (var
->refcount
> 0);
1402 if (var
->refcount
> 0)
1405 for (i
= 0; i
< var
->n_var_parts
; i
++)
1407 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= next
)
1410 pool_free (loc_chain_pool
, node
);
1412 var
->var_part
[i
].loc_chain
= NULL
;
1414 if (var
->onepart
&& VAR_LOC_1PAUX (var
))
1416 loc_exp_dep_clear (var
);
1417 if (VAR_LOC_DEP_LST (var
))
1418 VAR_LOC_DEP_LST (var
)->pprev
= NULL
;
1419 XDELETE (VAR_LOC_1PAUX (var
));
1420 /* These may be reused across functions, so reset
1422 if (var
->onepart
== ONEPART_DEXPR
)
1423 set_dv_changed (var
->dv
, true);
1425 pool_free (onepart_pool (var
->onepart
), var
);
1428 /* Initialize the set (array) SET of attrs to empty lists. */
1431 init_attrs_list_set (attrs
*set
)
1435 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1439 /* Make the list *LISTP empty. */
1442 attrs_list_clear (attrs
*listp
)
1446 for (list
= *listp
; list
; list
= next
)
1449 pool_free (attrs_pool
, list
);
1454 /* Return true if the pair of DECL and OFFSET is the member of the LIST. */
1457 attrs_list_member (attrs list
, decl_or_value dv
, HOST_WIDE_INT offset
)
1459 for (; list
; list
= list
->next
)
1460 if (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
) && list
->offset
== offset
)
1465 /* Insert the triplet DECL, OFFSET, LOC to the list *LISTP. */
1468 attrs_list_insert (attrs
*listp
, decl_or_value dv
,
1469 HOST_WIDE_INT offset
, rtx loc
)
1473 list
= (attrs
) pool_alloc (attrs_pool
);
1476 list
->offset
= offset
;
1477 list
->next
= *listp
;
1481 /* Copy all nodes from SRC and create a list *DSTP of the copies. */
1484 attrs_list_copy (attrs
*dstp
, attrs src
)
1488 attrs_list_clear (dstp
);
1489 for (; src
; src
= src
->next
)
1491 n
= (attrs
) pool_alloc (attrs_pool
);
1494 n
->offset
= src
->offset
;
1500 /* Add all nodes from SRC which are not in *DSTP to *DSTP. */
1503 attrs_list_union (attrs
*dstp
, attrs src
)
1505 for (; src
; src
= src
->next
)
1507 if (!attrs_list_member (*dstp
, src
->dv
, src
->offset
))
1508 attrs_list_insert (dstp
, src
->dv
, src
->offset
, src
->loc
);
1512 /* Combine nodes that are not onepart nodes from SRC and SRC2 into
1516 attrs_list_mpdv_union (attrs
*dstp
, attrs src
, attrs src2
)
1518 gcc_assert (!*dstp
);
1519 for (; src
; src
= src
->next
)
1521 if (!dv_onepart_p (src
->dv
))
1522 attrs_list_insert (dstp
, src
->dv
, src
->offset
, src
->loc
);
1524 for (src
= src2
; src
; src
= src
->next
)
1526 if (!dv_onepart_p (src
->dv
)
1527 && !attrs_list_member (*dstp
, src
->dv
, src
->offset
))
1528 attrs_list_insert (dstp
, src
->dv
, src
->offset
, src
->loc
);
1532 /* Shared hashtable support. */
1534 /* Return true if VARS is shared. */
1537 shared_hash_shared (shared_hash vars
)
1539 return vars
->refcount
> 1;
1542 /* Return the hash table for VARS. */
1544 static inline htab_t
1545 shared_hash_htab (shared_hash vars
)
1550 /* Return true if VAR is shared, or maybe because VARS is shared. */
1553 shared_var_p (variable var
, shared_hash vars
)
1555 /* Don't count an entry in the changed_variables table as a duplicate. */
1556 return ((var
->refcount
> 1 + (int) var
->in_changed_variables
)
1557 || shared_hash_shared (vars
));
1560 /* Copy variables into a new hash table. */
1563 shared_hash_unshare (shared_hash vars
)
1565 shared_hash new_vars
= (shared_hash
) pool_alloc (shared_hash_pool
);
1566 gcc_assert (vars
->refcount
> 1);
1567 new_vars
->refcount
= 1;
1569 = htab_create (htab_elements (vars
->htab
) + 3, variable_htab_hash
,
1570 variable_htab_eq
, variable_htab_free
);
1571 vars_copy (new_vars
->htab
, vars
->htab
);
1576 /* Increment reference counter on VARS and return it. */
1578 static inline shared_hash
1579 shared_hash_copy (shared_hash vars
)
1585 /* Decrement reference counter and destroy hash table if not shared
1589 shared_hash_destroy (shared_hash vars
)
1591 gcc_checking_assert (vars
->refcount
> 0);
1592 if (--vars
->refcount
== 0)
1594 htab_delete (vars
->htab
);
1595 pool_free (shared_hash_pool
, vars
);
1599 /* Unshare *PVARS if shared and return slot for DV. If INS is
1600 INSERT, insert it if not already present. */
1602 static inline void **
1603 shared_hash_find_slot_unshare_1 (shared_hash
*pvars
, decl_or_value dv
,
1604 hashval_t dvhash
, enum insert_option ins
)
1606 if (shared_hash_shared (*pvars
))
1607 *pvars
= shared_hash_unshare (*pvars
);
1608 return htab_find_slot_with_hash (shared_hash_htab (*pvars
), dv
, dvhash
, ins
);
1611 static inline void **
1612 shared_hash_find_slot_unshare (shared_hash
*pvars
, decl_or_value dv
,
1613 enum insert_option ins
)
1615 return shared_hash_find_slot_unshare_1 (pvars
, dv
, dv_htab_hash (dv
), ins
);
1618 /* Return slot for DV, if it is already present in the hash table.
1619 If it is not present, insert it only VARS is not shared, otherwise
1622 static inline void **
1623 shared_hash_find_slot_1 (shared_hash vars
, decl_or_value dv
, hashval_t dvhash
)
1625 return htab_find_slot_with_hash (shared_hash_htab (vars
), dv
, dvhash
,
1626 shared_hash_shared (vars
)
1627 ? NO_INSERT
: INSERT
);
1630 static inline void **
1631 shared_hash_find_slot (shared_hash vars
, decl_or_value dv
)
1633 return shared_hash_find_slot_1 (vars
, dv
, dv_htab_hash (dv
));
1636 /* Return slot for DV only if it is already present in the hash table. */
1638 static inline void **
1639 shared_hash_find_slot_noinsert_1 (shared_hash vars
, decl_or_value dv
,
1642 return htab_find_slot_with_hash (shared_hash_htab (vars
), dv
, dvhash
,
1646 static inline void **
1647 shared_hash_find_slot_noinsert (shared_hash vars
, decl_or_value dv
)
1649 return shared_hash_find_slot_noinsert_1 (vars
, dv
, dv_htab_hash (dv
));
1652 /* Return variable for DV or NULL if not already present in the hash
1655 static inline variable
1656 shared_hash_find_1 (shared_hash vars
, decl_or_value dv
, hashval_t dvhash
)
1658 return (variable
) htab_find_with_hash (shared_hash_htab (vars
), dv
, dvhash
);
1661 static inline variable
1662 shared_hash_find (shared_hash vars
, decl_or_value dv
)
1664 return shared_hash_find_1 (vars
, dv
, dv_htab_hash (dv
));
1667 /* Return true if TVAL is better than CVAL as a canonival value. We
1668 choose lowest-numbered VALUEs, using the RTX address as a
1669 tie-breaker. The idea is to arrange them into a star topology,
1670 such that all of them are at most one step away from the canonical
1671 value, and the canonical value has backlinks to all of them, in
1672 addition to all the actual locations. We don't enforce this
1673 topology throughout the entire dataflow analysis, though.
1677 canon_value_cmp (rtx tval
, rtx cval
)
1680 || CSELIB_VAL_PTR (tval
)->uid
< CSELIB_VAL_PTR (cval
)->uid
;
1683 static bool dst_can_be_shared
;
1685 /* Return a copy of a variable VAR and insert it to dataflow set SET. */
1688 unshare_variable (dataflow_set
*set
, void **slot
, variable var
,
1689 enum var_init_status initialized
)
1694 new_var
= (variable
) pool_alloc (onepart_pool (var
->onepart
));
1695 new_var
->dv
= var
->dv
;
1696 new_var
->refcount
= 1;
1698 new_var
->n_var_parts
= var
->n_var_parts
;
1699 new_var
->onepart
= var
->onepart
;
1700 new_var
->in_changed_variables
= false;
1702 if (! flag_var_tracking_uninit
)
1703 initialized
= VAR_INIT_STATUS_INITIALIZED
;
1705 for (i
= 0; i
< var
->n_var_parts
; i
++)
1707 location_chain node
;
1708 location_chain
*nextp
;
1710 if (i
== 0 && var
->onepart
)
1712 /* One-part auxiliary data is only used while emitting
1713 notes, so propagate it to the new variable in the active
1714 dataflow set. If we're not emitting notes, this will be
1716 gcc_checking_assert (!VAR_LOC_1PAUX (var
) || emit_notes
);
1717 VAR_LOC_1PAUX (new_var
) = VAR_LOC_1PAUX (var
);
1718 VAR_LOC_1PAUX (var
) = NULL
;
1721 VAR_PART_OFFSET (new_var
, i
) = VAR_PART_OFFSET (var
, i
);
1722 nextp
= &new_var
->var_part
[i
].loc_chain
;
1723 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1725 location_chain new_lc
;
1727 new_lc
= (location_chain
) pool_alloc (loc_chain_pool
);
1728 new_lc
->next
= NULL
;
1729 if (node
->init
> initialized
)
1730 new_lc
->init
= node
->init
;
1732 new_lc
->init
= initialized
;
1733 if (node
->set_src
&& !(MEM_P (node
->set_src
)))
1734 new_lc
->set_src
= node
->set_src
;
1736 new_lc
->set_src
= NULL
;
1737 new_lc
->loc
= node
->loc
;
1740 nextp
= &new_lc
->next
;
1743 new_var
->var_part
[i
].cur_loc
= var
->var_part
[i
].cur_loc
;
1746 dst_can_be_shared
= false;
1747 if (shared_hash_shared (set
->vars
))
1748 slot
= shared_hash_find_slot_unshare (&set
->vars
, var
->dv
, NO_INSERT
);
1749 else if (set
->traversed_vars
&& set
->vars
!= set
->traversed_vars
)
1750 slot
= shared_hash_find_slot_noinsert (set
->vars
, var
->dv
);
1752 if (var
->in_changed_variables
)
1755 = htab_find_slot_with_hash (changed_variables
, var
->dv
,
1756 dv_htab_hash (var
->dv
), NO_INSERT
);
1757 gcc_assert (*cslot
== (void *) var
);
1758 var
->in_changed_variables
= false;
1759 variable_htab_free (var
);
1761 new_var
->in_changed_variables
= true;
1766 /* Copy all variables from hash table SRC to hash table DST. */
1769 vars_copy (htab_t dst
, htab_t src
)
1774 FOR_EACH_HTAB_ELEMENT (src
, var
, variable
, hi
)
1778 dstp
= htab_find_slot_with_hash (dst
, var
->dv
,
1779 dv_htab_hash (var
->dv
),
1785 /* Map a decl to its main debug decl. */
1788 var_debug_decl (tree decl
)
1790 if (decl
&& DECL_P (decl
)
1791 && DECL_DEBUG_EXPR_IS_FROM (decl
))
1793 tree debugdecl
= DECL_DEBUG_EXPR (decl
);
1794 if (debugdecl
&& DECL_P (debugdecl
))
1801 /* Set the register LOC to contain DV, OFFSET. */
1804 var_reg_decl_set (dataflow_set
*set
, rtx loc
, enum var_init_status initialized
,
1805 decl_or_value dv
, HOST_WIDE_INT offset
, rtx set_src
,
1806 enum insert_option iopt
)
1809 bool decl_p
= dv_is_decl_p (dv
);
1812 dv
= dv_from_decl (var_debug_decl (dv_as_decl (dv
)));
1814 for (node
= set
->regs
[REGNO (loc
)]; node
; node
= node
->next
)
1815 if (dv_as_opaque (node
->dv
) == dv_as_opaque (dv
)
1816 && node
->offset
== offset
)
1819 attrs_list_insert (&set
->regs
[REGNO (loc
)], dv
, offset
, loc
);
1820 set_variable_part (set
, loc
, dv
, offset
, initialized
, set_src
, iopt
);
1823 /* Set the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). */
1826 var_reg_set (dataflow_set
*set
, rtx loc
, enum var_init_status initialized
,
1829 tree decl
= REG_EXPR (loc
);
1830 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
1832 var_reg_decl_set (set
, loc
, initialized
,
1833 dv_from_decl (decl
), offset
, set_src
, INSERT
);
1836 static enum var_init_status
1837 get_init_value (dataflow_set
*set
, rtx loc
, decl_or_value dv
)
1841 enum var_init_status ret_val
= VAR_INIT_STATUS_UNKNOWN
;
1843 if (! flag_var_tracking_uninit
)
1844 return VAR_INIT_STATUS_INITIALIZED
;
1846 var
= shared_hash_find (set
->vars
, dv
);
1849 for (i
= 0; i
< var
->n_var_parts
&& ret_val
== VAR_INIT_STATUS_UNKNOWN
; i
++)
1851 location_chain nextp
;
1852 for (nextp
= var
->var_part
[i
].loc_chain
; nextp
; nextp
= nextp
->next
)
1853 if (rtx_equal_p (nextp
->loc
, loc
))
1855 ret_val
= nextp
->init
;
1864 /* Delete current content of register LOC in dataflow set SET and set
1865 the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). If
1866 MODIFY is true, any other live copies of the same variable part are
1867 also deleted from the dataflow set, otherwise the variable part is
1868 assumed to be copied from another location holding the same
1872 var_reg_delete_and_set (dataflow_set
*set
, rtx loc
, bool modify
,
1873 enum var_init_status initialized
, rtx set_src
)
1875 tree decl
= REG_EXPR (loc
);
1876 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
1880 decl
= var_debug_decl (decl
);
1882 if (initialized
== VAR_INIT_STATUS_UNKNOWN
)
1883 initialized
= get_init_value (set
, loc
, dv_from_decl (decl
));
1885 nextp
= &set
->regs
[REGNO (loc
)];
1886 for (node
= *nextp
; node
; node
= next
)
1889 if (dv_as_opaque (node
->dv
) != decl
|| node
->offset
!= offset
)
1891 delete_variable_part (set
, node
->loc
, node
->dv
, node
->offset
);
1892 pool_free (attrs_pool
, node
);
1898 nextp
= &node
->next
;
1902 clobber_variable_part (set
, loc
, dv_from_decl (decl
), offset
, set_src
);
1903 var_reg_set (set
, loc
, initialized
, set_src
);
1906 /* Delete the association of register LOC in dataflow set SET with any
1907 variables that aren't onepart. If CLOBBER is true, also delete any
1908 other live copies of the same variable part, and delete the
1909 association with onepart dvs too. */
1912 var_reg_delete (dataflow_set
*set
, rtx loc
, bool clobber
)
1914 attrs
*nextp
= &set
->regs
[REGNO (loc
)];
1919 tree decl
= REG_EXPR (loc
);
1920 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
1922 decl
= var_debug_decl (decl
);
1924 clobber_variable_part (set
, NULL
, dv_from_decl (decl
), offset
, NULL
);
1927 for (node
= *nextp
; node
; node
= next
)
1930 if (clobber
|| !dv_onepart_p (node
->dv
))
1932 delete_variable_part (set
, node
->loc
, node
->dv
, node
->offset
);
1933 pool_free (attrs_pool
, node
);
1937 nextp
= &node
->next
;
1941 /* Delete content of register with number REGNO in dataflow set SET. */
1944 var_regno_delete (dataflow_set
*set
, int regno
)
1946 attrs
*reg
= &set
->regs
[regno
];
1949 for (node
= *reg
; node
; node
= next
)
1952 delete_variable_part (set
, node
->loc
, node
->dv
, node
->offset
);
1953 pool_free (attrs_pool
, node
);
1958 /* Hold parameters for the hashtab traversal function
1959 drop_overlapping_mem_locs, see below. */
1961 struct overlapping_mems
1967 /* Remove all MEMs that overlap with COMS->LOC from the location list
1968 of a hash table entry for a value. COMS->ADDR must be a
1969 canonicalized form of COMS->LOC's address, and COMS->LOC must be
1970 canonicalized itself. */
1973 drop_overlapping_mem_locs (void **slot
, void *data
)
1975 struct overlapping_mems
*coms
= (struct overlapping_mems
*)data
;
1976 dataflow_set
*set
= coms
->set
;
1977 rtx mloc
= coms
->loc
, addr
= coms
->addr
;
1978 variable var
= (variable
) *slot
;
1980 if (var
->onepart
== ONEPART_VALUE
)
1982 location_chain loc
, *locp
;
1983 bool changed
= false;
1986 gcc_assert (var
->n_var_parts
== 1);
1988 if (shared_var_p (var
, set
->vars
))
1990 for (loc
= var
->var_part
[0].loc_chain
; loc
; loc
= loc
->next
)
1991 if (GET_CODE (loc
->loc
) == MEM
1992 && canon_true_dependence (mloc
, GET_MODE (mloc
), addr
,
1999 slot
= unshare_variable (set
, slot
, var
, VAR_INIT_STATUS_UNKNOWN
);
2000 var
= (variable
)*slot
;
2001 gcc_assert (var
->n_var_parts
== 1);
2004 if (VAR_LOC_1PAUX (var
))
2005 cur_loc
= VAR_LOC_FROM (var
);
2007 cur_loc
= var
->var_part
[0].cur_loc
;
2009 for (locp
= &var
->var_part
[0].loc_chain
, loc
= *locp
;
2012 if (GET_CODE (loc
->loc
) != MEM
2013 || !canon_true_dependence (mloc
, GET_MODE (mloc
), addr
,
2021 /* If we have deleted the location which was last emitted
2022 we have to emit new location so add the variable to set
2023 of changed variables. */
2024 if (cur_loc
== loc
->loc
)
2027 var
->var_part
[0].cur_loc
= NULL
;
2028 if (VAR_LOC_1PAUX (var
))
2029 VAR_LOC_FROM (var
) = NULL
;
2031 pool_free (loc_chain_pool
, loc
);
2034 if (!var
->var_part
[0].loc_chain
)
2040 variable_was_changed (var
, set
);
2046 /* Remove from SET all VALUE bindings to MEMs that overlap with LOC. */
2049 clobber_overlapping_mems (dataflow_set
*set
, rtx loc
)
2051 struct overlapping_mems coms
;
2054 coms
.loc
= canon_rtx (loc
);
2055 coms
.addr
= canon_rtx (get_addr (XEXP (loc
, 0)));
2057 set
->traversed_vars
= set
->vars
;
2058 htab_traverse (shared_hash_htab (set
->vars
),
2059 drop_overlapping_mem_locs
, &coms
);
2060 set
->traversed_vars
= NULL
;
2063 /* Set the location of DV, OFFSET as the MEM LOC. */
2066 var_mem_decl_set (dataflow_set
*set
, rtx loc
, enum var_init_status initialized
,
2067 decl_or_value dv
, HOST_WIDE_INT offset
, rtx set_src
,
2068 enum insert_option iopt
)
2070 if (dv_is_decl_p (dv
))
2071 dv
= dv_from_decl (var_debug_decl (dv_as_decl (dv
)));
2073 set_variable_part (set
, loc
, dv
, offset
, initialized
, set_src
, iopt
);
2076 /* Set the location part of variable MEM_EXPR (LOC) in dataflow set
2078 Adjust the address first if it is stack pointer based. */
2081 var_mem_set (dataflow_set
*set
, rtx loc
, enum var_init_status initialized
,
2084 tree decl
= MEM_EXPR (loc
);
2085 HOST_WIDE_INT offset
= INT_MEM_OFFSET (loc
);
2087 var_mem_decl_set (set
, loc
, initialized
,
2088 dv_from_decl (decl
), offset
, set_src
, INSERT
);
2091 /* Delete and set the location part of variable MEM_EXPR (LOC) in
2092 dataflow set SET to LOC. If MODIFY is true, any other live copies
2093 of the same variable part are also deleted from the dataflow set,
2094 otherwise the variable part is assumed to be copied from another
2095 location holding the same part.
2096 Adjust the address first if it is stack pointer based. */
2099 var_mem_delete_and_set (dataflow_set
*set
, rtx loc
, bool modify
,
2100 enum var_init_status initialized
, rtx set_src
)
2102 tree decl
= MEM_EXPR (loc
);
2103 HOST_WIDE_INT offset
= INT_MEM_OFFSET (loc
);
2105 clobber_overlapping_mems (set
, loc
);
2106 decl
= var_debug_decl (decl
);
2108 if (initialized
== VAR_INIT_STATUS_UNKNOWN
)
2109 initialized
= get_init_value (set
, loc
, dv_from_decl (decl
));
2112 clobber_variable_part (set
, NULL
, dv_from_decl (decl
), offset
, set_src
);
2113 var_mem_set (set
, loc
, initialized
, set_src
);
2116 /* Delete the location part LOC from dataflow set SET. If CLOBBER is
2117 true, also delete any other live copies of the same variable part.
2118 Adjust the address first if it is stack pointer based. */
2121 var_mem_delete (dataflow_set
*set
, rtx loc
, bool clobber
)
2123 tree decl
= MEM_EXPR (loc
);
2124 HOST_WIDE_INT offset
= INT_MEM_OFFSET (loc
);
2126 clobber_overlapping_mems (set
, loc
);
2127 decl
= var_debug_decl (decl
);
2129 clobber_variable_part (set
, NULL
, dv_from_decl (decl
), offset
, NULL
);
2130 delete_variable_part (set
, loc
, dv_from_decl (decl
), offset
);
2133 /* Return true if LOC should not be expanded for location expressions,
2137 unsuitable_loc (rtx loc
)
2139 switch (GET_CODE (loc
))
2153 /* Bind VAL to LOC in SET. If MODIFIED, detach LOC from any values
2157 val_bind (dataflow_set
*set
, rtx val
, rtx loc
, bool modified
)
2162 var_regno_delete (set
, REGNO (loc
));
2163 var_reg_decl_set (set
, loc
, VAR_INIT_STATUS_INITIALIZED
,
2164 dv_from_value (val
), 0, NULL_RTX
, INSERT
);
2166 else if (MEM_P (loc
))
2168 struct elt_loc_list
*l
= CSELIB_VAL_PTR (val
)->locs
;
2171 clobber_overlapping_mems (set
, loc
);
2173 if (l
&& GET_CODE (l
->loc
) == VALUE
)
2174 l
= canonical_cselib_val (CSELIB_VAL_PTR (l
->loc
))->locs
;
2176 /* If this MEM is a global constant, we don't need it in the
2177 dynamic tables. ??? We should test this before emitting the
2178 micro-op in the first place. */
2180 if (GET_CODE (l
->loc
) == MEM
&& XEXP (l
->loc
, 0) == XEXP (loc
, 0))
2186 var_mem_decl_set (set
, loc
, VAR_INIT_STATUS_INITIALIZED
,
2187 dv_from_value (val
), 0, NULL_RTX
, INSERT
);
2191 /* Other kinds of equivalences are necessarily static, at least
2192 so long as we do not perform substitutions while merging
2195 set_variable_part (set
, loc
, dv_from_value (val
), 0,
2196 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
, INSERT
);
2200 /* Bind a value to a location it was just stored in. If MODIFIED
2201 holds, assume the location was modified, detaching it from any
2202 values bound to it. */
2205 val_store (dataflow_set
*set
, rtx val
, rtx loc
, rtx insn
, bool modified
)
2207 cselib_val
*v
= CSELIB_VAL_PTR (val
);
2209 gcc_assert (cselib_preserved_value_p (v
));
2213 fprintf (dump_file
, "%i: ", insn
? INSN_UID (insn
) : 0);
2214 print_inline_rtx (dump_file
, loc
, 0);
2215 fprintf (dump_file
, " evaluates to ");
2216 print_inline_rtx (dump_file
, val
, 0);
2219 struct elt_loc_list
*l
;
2220 for (l
= v
->locs
; l
; l
= l
->next
)
2222 fprintf (dump_file
, "\n%i: ", INSN_UID (l
->setting_insn
));
2223 print_inline_rtx (dump_file
, l
->loc
, 0);
2226 fprintf (dump_file
, "\n");
2229 gcc_checking_assert (!unsuitable_loc (loc
));
2231 val_bind (set
, val
, loc
, modified
);
2234 /* Reset this node, detaching all its equivalences. Return the slot
2235 in the variable hash table that holds dv, if there is one. */
2238 val_reset (dataflow_set
*set
, decl_or_value dv
)
2240 variable var
= shared_hash_find (set
->vars
, dv
) ;
2241 location_chain node
;
2244 if (!var
|| !var
->n_var_parts
)
2247 gcc_assert (var
->n_var_parts
== 1);
2250 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
2251 if (GET_CODE (node
->loc
) == VALUE
2252 && canon_value_cmp (node
->loc
, cval
))
2255 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
2256 if (GET_CODE (node
->loc
) == VALUE
&& cval
!= node
->loc
)
2258 /* Redirect the equivalence link to the new canonical
2259 value, or simply remove it if it would point at
2262 set_variable_part (set
, cval
, dv_from_value (node
->loc
),
2263 0, node
->init
, node
->set_src
, NO_INSERT
);
2264 delete_variable_part (set
, dv_as_value (dv
),
2265 dv_from_value (node
->loc
), 0);
2270 decl_or_value cdv
= dv_from_value (cval
);
2272 /* Keep the remaining values connected, accummulating links
2273 in the canonical value. */
2274 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
2276 if (node
->loc
== cval
)
2278 else if (GET_CODE (node
->loc
) == REG
)
2279 var_reg_decl_set (set
, node
->loc
, node
->init
, cdv
, 0,
2280 node
->set_src
, NO_INSERT
);
2281 else if (GET_CODE (node
->loc
) == MEM
)
2282 var_mem_decl_set (set
, node
->loc
, node
->init
, cdv
, 0,
2283 node
->set_src
, NO_INSERT
);
2285 set_variable_part (set
, node
->loc
, cdv
, 0,
2286 node
->init
, node
->set_src
, NO_INSERT
);
2290 /* We remove this last, to make sure that the canonical value is not
2291 removed to the point of requiring reinsertion. */
2293 delete_variable_part (set
, dv_as_value (dv
), dv_from_value (cval
), 0);
2295 clobber_variable_part (set
, NULL
, dv
, 0, NULL
);
2298 /* Find the values in a given location and map the val to another
2299 value, if it is unique, or add the location as one holding the
2303 val_resolve (dataflow_set
*set
, rtx val
, rtx loc
, rtx insn
)
2305 decl_or_value dv
= dv_from_value (val
);
2307 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2310 fprintf (dump_file
, "%i: ", INSN_UID (insn
));
2312 fprintf (dump_file
, "head: ");
2313 print_inline_rtx (dump_file
, val
, 0);
2314 fputs (" is at ", dump_file
);
2315 print_inline_rtx (dump_file
, loc
, 0);
2316 fputc ('\n', dump_file
);
2319 val_reset (set
, dv
);
2321 gcc_checking_assert (!unsuitable_loc (loc
));
2325 attrs node
, found
= NULL
;
2327 for (node
= set
->regs
[REGNO (loc
)]; node
; node
= node
->next
)
2328 if (dv_is_value_p (node
->dv
)
2329 && GET_MODE (dv_as_value (node
->dv
)) == GET_MODE (loc
))
2333 /* Map incoming equivalences. ??? Wouldn't it be nice if
2334 we just started sharing the location lists? Maybe a
2335 circular list ending at the value itself or some
2337 set_variable_part (set
, dv_as_value (node
->dv
),
2338 dv_from_value (val
), node
->offset
,
2339 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
, INSERT
);
2340 set_variable_part (set
, val
, node
->dv
, node
->offset
,
2341 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
, INSERT
);
2344 /* If we didn't find any equivalence, we need to remember that
2345 this value is held in the named register. */
2349 /* ??? Attempt to find and merge equivalent MEMs or other
2352 val_bind (set
, val
, loc
, false);
2355 /* Initialize dataflow set SET to be empty.
2356 VARS_SIZE is the initial size of hash table VARS. */
2359 dataflow_set_init (dataflow_set
*set
)
2361 init_attrs_list_set (set
->regs
);
2362 set
->vars
= shared_hash_copy (empty_shared_hash
);
2363 set
->stack_adjust
= 0;
2364 set
->traversed_vars
= NULL
;
2367 /* Delete the contents of dataflow set SET. */
2370 dataflow_set_clear (dataflow_set
*set
)
2374 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2375 attrs_list_clear (&set
->regs
[i
]);
2377 shared_hash_destroy (set
->vars
);
2378 set
->vars
= shared_hash_copy (empty_shared_hash
);
2381 /* Copy the contents of dataflow set SRC to DST. */
2384 dataflow_set_copy (dataflow_set
*dst
, dataflow_set
*src
)
2388 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2389 attrs_list_copy (&dst
->regs
[i
], src
->regs
[i
]);
2391 shared_hash_destroy (dst
->vars
);
2392 dst
->vars
= shared_hash_copy (src
->vars
);
2393 dst
->stack_adjust
= src
->stack_adjust
;
2396 /* Information for merging lists of locations for a given offset of variable.
2398 struct variable_union_info
2400 /* Node of the location chain. */
2403 /* The sum of positions in the input chains. */
2406 /* The position in the chain of DST dataflow set. */
2410 /* Buffer for location list sorting and its allocated size. */
2411 static struct variable_union_info
*vui_vec
;
2412 static int vui_allocated
;
2414 /* Compare function for qsort, order the structures by POS element. */
2417 variable_union_info_cmp_pos (const void *n1
, const void *n2
)
2419 const struct variable_union_info
*const i1
=
2420 (const struct variable_union_info
*) n1
;
2421 const struct variable_union_info
*const i2
=
2422 ( const struct variable_union_info
*) n2
;
2424 if (i1
->pos
!= i2
->pos
)
2425 return i1
->pos
- i2
->pos
;
2427 return (i1
->pos_dst
- i2
->pos_dst
);
2430 /* Compute union of location parts of variable *SLOT and the same variable
2431 from hash table DATA. Compute "sorted" union of the location chains
2432 for common offsets, i.e. the locations of a variable part are sorted by
2433 a priority where the priority is the sum of the positions in the 2 chains
2434 (if a location is only in one list the position in the second list is
2435 defined to be larger than the length of the chains).
2436 When we are updating the location parts the newest location is in the
2437 beginning of the chain, so when we do the described "sorted" union
2438 we keep the newest locations in the beginning. */
2441 variable_union (variable src
, dataflow_set
*set
)
2447 dstp
= shared_hash_find_slot (set
->vars
, src
->dv
);
2448 if (!dstp
|| !*dstp
)
2452 dst_can_be_shared
= false;
2454 dstp
= shared_hash_find_slot_unshare (&set
->vars
, src
->dv
, INSERT
);
2458 /* Continue traversing the hash table. */
2462 dst
= (variable
) *dstp
;
2464 gcc_assert (src
->n_var_parts
);
2465 gcc_checking_assert (src
->onepart
== dst
->onepart
);
2467 /* We can combine one-part variables very efficiently, because their
2468 entries are in canonical order. */
2471 location_chain
*nodep
, dnode
, snode
;
2473 gcc_assert (src
->n_var_parts
== 1
2474 && dst
->n_var_parts
== 1);
2476 snode
= src
->var_part
[0].loc_chain
;
2479 restart_onepart_unshared
:
2480 nodep
= &dst
->var_part
[0].loc_chain
;
2486 int r
= dnode
? loc_cmp (dnode
->loc
, snode
->loc
) : 1;
2490 location_chain nnode
;
2492 if (shared_var_p (dst
, set
->vars
))
2494 dstp
= unshare_variable (set
, dstp
, dst
,
2495 VAR_INIT_STATUS_INITIALIZED
);
2496 dst
= (variable
)*dstp
;
2497 goto restart_onepart_unshared
;
2500 *nodep
= nnode
= (location_chain
) pool_alloc (loc_chain_pool
);
2501 nnode
->loc
= snode
->loc
;
2502 nnode
->init
= snode
->init
;
2503 if (!snode
->set_src
|| MEM_P (snode
->set_src
))
2504 nnode
->set_src
= NULL
;
2506 nnode
->set_src
= snode
->set_src
;
2507 nnode
->next
= dnode
;
2511 gcc_checking_assert (rtx_equal_p (dnode
->loc
, snode
->loc
));
2514 snode
= snode
->next
;
2516 nodep
= &dnode
->next
;
2523 gcc_checking_assert (!src
->onepart
);
2525 /* Count the number of location parts, result is K. */
2526 for (i
= 0, j
= 0, k
= 0;
2527 i
< src
->n_var_parts
&& j
< dst
->n_var_parts
; k
++)
2529 if (VAR_PART_OFFSET (src
, i
) == VAR_PART_OFFSET (dst
, j
))
2534 else if (VAR_PART_OFFSET (src
, i
) < VAR_PART_OFFSET (dst
, j
))
2539 k
+= src
->n_var_parts
- i
;
2540 k
+= dst
->n_var_parts
- j
;
2542 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
2543 thus there are at most MAX_VAR_PARTS different offsets. */
2544 gcc_checking_assert (dst
->onepart
? k
== 1 : k
<= MAX_VAR_PARTS
);
2546 if (dst
->n_var_parts
!= k
&& shared_var_p (dst
, set
->vars
))
2548 dstp
= unshare_variable (set
, dstp
, dst
, VAR_INIT_STATUS_UNKNOWN
);
2549 dst
= (variable
)*dstp
;
2552 i
= src
->n_var_parts
- 1;
2553 j
= dst
->n_var_parts
- 1;
2554 dst
->n_var_parts
= k
;
2556 for (k
--; k
>= 0; k
--)
2558 location_chain node
, node2
;
2560 if (i
>= 0 && j
>= 0
2561 && VAR_PART_OFFSET (src
, i
) == VAR_PART_OFFSET (dst
, j
))
2563 /* Compute the "sorted" union of the chains, i.e. the locations which
2564 are in both chains go first, they are sorted by the sum of
2565 positions in the chains. */
2568 struct variable_union_info
*vui
;
2570 /* If DST is shared compare the location chains.
2571 If they are different we will modify the chain in DST with
2572 high probability so make a copy of DST. */
2573 if (shared_var_p (dst
, set
->vars
))
2575 for (node
= src
->var_part
[i
].loc_chain
,
2576 node2
= dst
->var_part
[j
].loc_chain
; node
&& node2
;
2577 node
= node
->next
, node2
= node2
->next
)
2579 if (!((REG_P (node2
->loc
)
2580 && REG_P (node
->loc
)
2581 && REGNO (node2
->loc
) == REGNO (node
->loc
))
2582 || rtx_equal_p (node2
->loc
, node
->loc
)))
2584 if (node2
->init
< node
->init
)
2585 node2
->init
= node
->init
;
2591 dstp
= unshare_variable (set
, dstp
, dst
,
2592 VAR_INIT_STATUS_UNKNOWN
);
2593 dst
= (variable
)*dstp
;
2598 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
2601 for (node
= dst
->var_part
[j
].loc_chain
; node
; node
= node
->next
)
2606 /* The most common case, much simpler, no qsort is needed. */
2607 location_chain dstnode
= dst
->var_part
[j
].loc_chain
;
2608 dst
->var_part
[k
].loc_chain
= dstnode
;
2609 VAR_PART_OFFSET (dst
, k
) = VAR_PART_OFFSET(dst
, j
);
2611 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
2612 if (!((REG_P (dstnode
->loc
)
2613 && REG_P (node
->loc
)
2614 && REGNO (dstnode
->loc
) == REGNO (node
->loc
))
2615 || rtx_equal_p (dstnode
->loc
, node
->loc
)))
2617 location_chain new_node
;
2619 /* Copy the location from SRC. */
2620 new_node
= (location_chain
) pool_alloc (loc_chain_pool
);
2621 new_node
->loc
= node
->loc
;
2622 new_node
->init
= node
->init
;
2623 if (!node
->set_src
|| MEM_P (node
->set_src
))
2624 new_node
->set_src
= NULL
;
2626 new_node
->set_src
= node
->set_src
;
2627 node2
->next
= new_node
;
2634 if (src_l
+ dst_l
> vui_allocated
)
2636 vui_allocated
= MAX (vui_allocated
* 2, src_l
+ dst_l
);
2637 vui_vec
= XRESIZEVEC (struct variable_union_info
, vui_vec
,
2642 /* Fill in the locations from DST. */
2643 for (node
= dst
->var_part
[j
].loc_chain
, jj
= 0; node
;
2644 node
= node
->next
, jj
++)
2647 vui
[jj
].pos_dst
= jj
;
2649 /* Pos plus value larger than a sum of 2 valid positions. */
2650 vui
[jj
].pos
= jj
+ src_l
+ dst_l
;
2653 /* Fill in the locations from SRC. */
2655 for (node
= src
->var_part
[i
].loc_chain
, ii
= 0; node
;
2656 node
= node
->next
, ii
++)
2658 /* Find location from NODE. */
2659 for (jj
= 0; jj
< dst_l
; jj
++)
2661 if ((REG_P (vui
[jj
].lc
->loc
)
2662 && REG_P (node
->loc
)
2663 && REGNO (vui
[jj
].lc
->loc
) == REGNO (node
->loc
))
2664 || rtx_equal_p (vui
[jj
].lc
->loc
, node
->loc
))
2666 vui
[jj
].pos
= jj
+ ii
;
2670 if (jj
>= dst_l
) /* The location has not been found. */
2672 location_chain new_node
;
2674 /* Copy the location from SRC. */
2675 new_node
= (location_chain
) pool_alloc (loc_chain_pool
);
2676 new_node
->loc
= node
->loc
;
2677 new_node
->init
= node
->init
;
2678 if (!node
->set_src
|| MEM_P (node
->set_src
))
2679 new_node
->set_src
= NULL
;
2681 new_node
->set_src
= node
->set_src
;
2682 vui
[n
].lc
= new_node
;
2683 vui
[n
].pos_dst
= src_l
+ dst_l
;
2684 vui
[n
].pos
= ii
+ src_l
+ dst_l
;
2691 /* Special case still very common case. For dst_l == 2
2692 all entries dst_l ... n-1 are sorted, with for i >= dst_l
2693 vui[i].pos == i + src_l + dst_l. */
2694 if (vui
[0].pos
> vui
[1].pos
)
2696 /* Order should be 1, 0, 2... */
2697 dst
->var_part
[k
].loc_chain
= vui
[1].lc
;
2698 vui
[1].lc
->next
= vui
[0].lc
;
2701 vui
[0].lc
->next
= vui
[2].lc
;
2702 vui
[n
- 1].lc
->next
= NULL
;
2705 vui
[0].lc
->next
= NULL
;
2710 dst
->var_part
[k
].loc_chain
= vui
[0].lc
;
2711 if (n
>= 3 && vui
[2].pos
< vui
[1].pos
)
2713 /* Order should be 0, 2, 1, 3... */
2714 vui
[0].lc
->next
= vui
[2].lc
;
2715 vui
[2].lc
->next
= vui
[1].lc
;
2718 vui
[1].lc
->next
= vui
[3].lc
;
2719 vui
[n
- 1].lc
->next
= NULL
;
2722 vui
[1].lc
->next
= NULL
;
2727 /* Order should be 0, 1, 2... */
2729 vui
[n
- 1].lc
->next
= NULL
;
2732 for (; ii
< n
; ii
++)
2733 vui
[ii
- 1].lc
->next
= vui
[ii
].lc
;
2737 qsort (vui
, n
, sizeof (struct variable_union_info
),
2738 variable_union_info_cmp_pos
);
2740 /* Reconnect the nodes in sorted order. */
2741 for (ii
= 1; ii
< n
; ii
++)
2742 vui
[ii
- 1].lc
->next
= vui
[ii
].lc
;
2743 vui
[n
- 1].lc
->next
= NULL
;
2744 dst
->var_part
[k
].loc_chain
= vui
[0].lc
;
2747 VAR_PART_OFFSET (dst
, k
) = VAR_PART_OFFSET (dst
, j
);
2752 else if ((i
>= 0 && j
>= 0
2753 && VAR_PART_OFFSET (src
, i
) < VAR_PART_OFFSET (dst
, j
))
2756 dst
->var_part
[k
] = dst
->var_part
[j
];
2759 else if ((i
>= 0 && j
>= 0
2760 && VAR_PART_OFFSET (src
, i
) > VAR_PART_OFFSET (dst
, j
))
2763 location_chain
*nextp
;
2765 /* Copy the chain from SRC. */
2766 nextp
= &dst
->var_part
[k
].loc_chain
;
2767 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
2769 location_chain new_lc
;
2771 new_lc
= (location_chain
) pool_alloc (loc_chain_pool
);
2772 new_lc
->next
= NULL
;
2773 new_lc
->init
= node
->init
;
2774 if (!node
->set_src
|| MEM_P (node
->set_src
))
2775 new_lc
->set_src
= NULL
;
2777 new_lc
->set_src
= node
->set_src
;
2778 new_lc
->loc
= node
->loc
;
2781 nextp
= &new_lc
->next
;
2784 VAR_PART_OFFSET (dst
, k
) = VAR_PART_OFFSET (src
, i
);
2787 dst
->var_part
[k
].cur_loc
= NULL
;
2790 if (flag_var_tracking_uninit
)
2791 for (i
= 0; i
< src
->n_var_parts
&& i
< dst
->n_var_parts
; i
++)
2793 location_chain node
, node2
;
2794 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
2795 for (node2
= dst
->var_part
[i
].loc_chain
; node2
; node2
= node2
->next
)
2796 if (rtx_equal_p (node
->loc
, node2
->loc
))
2798 if (node
->init
> node2
->init
)
2799 node2
->init
= node
->init
;
2803 /* Continue traversing the hash table. */
2807 /* Compute union of dataflow sets SRC and DST and store it to DST. */
2810 dataflow_set_union (dataflow_set
*dst
, dataflow_set
*src
)
2814 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2815 attrs_list_union (&dst
->regs
[i
], src
->regs
[i
]);
2817 if (dst
->vars
== empty_shared_hash
)
2819 shared_hash_destroy (dst
->vars
);
2820 dst
->vars
= shared_hash_copy (src
->vars
);
2827 FOR_EACH_HTAB_ELEMENT (shared_hash_htab (src
->vars
), var
, variable
, hi
)
2828 variable_union (var
, dst
);
2832 /* Whether the value is currently being expanded. */
2833 #define VALUE_RECURSED_INTO(x) \
2834 (RTL_FLAG_CHECK2 ("VALUE_RECURSED_INTO", (x), VALUE, DEBUG_EXPR)->used)
2836 /* Whether no expansion was found, saving useless lookups.
2837 It must only be set when VALUE_CHANGED is clear. */
2838 #define NO_LOC_P(x) \
2839 (RTL_FLAG_CHECK2 ("NO_LOC_P", (x), VALUE, DEBUG_EXPR)->return_val)
2841 /* Whether cur_loc in the value needs to be (re)computed. */
2842 #define VALUE_CHANGED(x) \
2843 (RTL_FLAG_CHECK1 ("VALUE_CHANGED", (x), VALUE)->frame_related)
2844 /* Whether cur_loc in the decl needs to be (re)computed. */
2845 #define DECL_CHANGED(x) TREE_VISITED (x)
2847 /* Record (if NEWV) that DV needs to have its cur_loc recomputed. For
2848 user DECLs, this means they're in changed_variables. Values and
2849 debug exprs may be left with this flag set if no user variable
2850 requires them to be evaluated. */
2853 set_dv_changed (decl_or_value dv
, bool newv
)
2855 switch (dv_onepart_p (dv
))
2859 NO_LOC_P (dv_as_value (dv
)) = false;
2860 VALUE_CHANGED (dv_as_value (dv
)) = newv
;
2865 NO_LOC_P (DECL_RTL_KNOWN_SET (dv_as_decl (dv
))) = false;
2866 /* Fall through... */
2869 DECL_CHANGED (dv_as_decl (dv
)) = newv
;
2874 /* Return true if DV needs to have its cur_loc recomputed. */
2877 dv_changed_p (decl_or_value dv
)
2879 return (dv_is_value_p (dv
)
2880 ? VALUE_CHANGED (dv_as_value (dv
))
2881 : DECL_CHANGED (dv_as_decl (dv
)));
2884 /* Return a location list node whose loc is rtx_equal to LOC, in the
2885 location list of a one-part variable or value VAR, or in that of
2886 any values recursively mentioned in the location lists. VARS must
2887 be in star-canonical form. */
2889 static location_chain
2890 find_loc_in_1pdv (rtx loc
, variable var
, htab_t vars
)
2892 location_chain node
;
2893 enum rtx_code loc_code
;
2898 gcc_checking_assert (var
->onepart
);
2900 if (!var
->n_var_parts
)
2903 gcc_checking_assert (loc
!= dv_as_opaque (var
->dv
));
2905 loc_code
= GET_CODE (loc
);
2906 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
2911 if (GET_CODE (node
->loc
) != loc_code
)
2913 if (GET_CODE (node
->loc
) != VALUE
)
2916 else if (loc
== node
->loc
)
2918 else if (loc_code
!= VALUE
)
2920 if (rtx_equal_p (loc
, node
->loc
))
2925 /* Since we're in star-canonical form, we don't need to visit
2926 non-canonical nodes: one-part variables and non-canonical
2927 values would only point back to the canonical node. */
2928 if (dv_is_value_p (var
->dv
)
2929 && !canon_value_cmp (node
->loc
, dv_as_value (var
->dv
)))
2931 /* Skip all subsequent VALUEs. */
2932 while (node
->next
&& GET_CODE (node
->next
->loc
) == VALUE
)
2935 gcc_checking_assert (!canon_value_cmp (node
->loc
,
2936 dv_as_value (var
->dv
)));
2937 if (loc
== node
->loc
)
2943 gcc_checking_assert (node
== var
->var_part
[0].loc_chain
);
2944 gcc_checking_assert (!node
->next
);
2946 dv
= dv_from_value (node
->loc
);
2947 rvar
= (variable
) htab_find_with_hash (vars
, dv
, dv_htab_hash (dv
));
2948 return find_loc_in_1pdv (loc
, rvar
, vars
);
2951 /* ??? Gotta look in cselib_val locations too. */
2956 /* Hash table iteration argument passed to variable_merge. */
2959 /* The set in which the merge is to be inserted. */
2961 /* The set that we're iterating in. */
2963 /* The set that may contain the other dv we are to merge with. */
2965 /* Number of onepart dvs in src. */
2966 int src_onepart_cnt
;
2969 /* Insert LOC in *DNODE, if it's not there yet. The list must be in
2970 loc_cmp order, and it is maintained as such. */
2973 insert_into_intersection (location_chain
*nodep
, rtx loc
,
2974 enum var_init_status status
)
2976 location_chain node
;
2979 for (node
= *nodep
; node
; nodep
= &node
->next
, node
= *nodep
)
2980 if ((r
= loc_cmp (node
->loc
, loc
)) == 0)
2982 node
->init
= MIN (node
->init
, status
);
2988 node
= (location_chain
) pool_alloc (loc_chain_pool
);
2991 node
->set_src
= NULL
;
2992 node
->init
= status
;
2993 node
->next
= *nodep
;
2997 /* Insert in DEST the intersection of the locations present in both
2998 S1NODE and S2VAR, directly or indirectly. S1NODE is from a
2999 variable in DSM->cur, whereas S2VAR is from DSM->src. dvar is in
3003 intersect_loc_chains (rtx val
, location_chain
*dest
, struct dfset_merge
*dsm
,
3004 location_chain s1node
, variable s2var
)
3006 dataflow_set
*s1set
= dsm
->cur
;
3007 dataflow_set
*s2set
= dsm
->src
;
3008 location_chain found
;
3012 location_chain s2node
;
3014 gcc_checking_assert (s2var
->onepart
);
3016 if (s2var
->n_var_parts
)
3018 s2node
= s2var
->var_part
[0].loc_chain
;
3020 for (; s1node
&& s2node
;
3021 s1node
= s1node
->next
, s2node
= s2node
->next
)
3022 if (s1node
->loc
!= s2node
->loc
)
3024 else if (s1node
->loc
== val
)
3027 insert_into_intersection (dest
, s1node
->loc
,
3028 MIN (s1node
->init
, s2node
->init
));
3032 for (; s1node
; s1node
= s1node
->next
)
3034 if (s1node
->loc
== val
)
3037 if ((found
= find_loc_in_1pdv (s1node
->loc
, s2var
,
3038 shared_hash_htab (s2set
->vars
))))
3040 insert_into_intersection (dest
, s1node
->loc
,
3041 MIN (s1node
->init
, found
->init
));
3045 if (GET_CODE (s1node
->loc
) == VALUE
3046 && !VALUE_RECURSED_INTO (s1node
->loc
))
3048 decl_or_value dv
= dv_from_value (s1node
->loc
);
3049 variable svar
= shared_hash_find (s1set
->vars
, dv
);
3052 if (svar
->n_var_parts
== 1)
3054 VALUE_RECURSED_INTO (s1node
->loc
) = true;
3055 intersect_loc_chains (val
, dest
, dsm
,
3056 svar
->var_part
[0].loc_chain
,
3058 VALUE_RECURSED_INTO (s1node
->loc
) = false;
3063 /* ??? gotta look in cselib_val locations too. */
3065 /* ??? if the location is equivalent to any location in src,
3066 searched recursively
3068 add to dst the values needed to represent the equivalence
3070 telling whether locations S is equivalent to another dv's
3073 for each location D in the list
3075 if S and D satisfy rtx_equal_p, then it is present
3077 else if D is a value, recurse without cycles
3079 else if S and D have the same CODE and MODE
3081 for each operand oS and the corresponding oD
3083 if oS and oD are not equivalent, then S an D are not equivalent
3085 else if they are RTX vectors
3087 if any vector oS element is not equivalent to its respective oD,
3088 then S and D are not equivalent
3096 /* Return -1 if X should be before Y in a location list for a 1-part
3097 variable, 1 if Y should be before X, and 0 if they're equivalent
3098 and should not appear in the list. */
3101 loc_cmp (rtx x
, rtx y
)
3104 RTX_CODE code
= GET_CODE (x
);
3114 gcc_assert (GET_MODE (x
) == GET_MODE (y
));
3115 if (REGNO (x
) == REGNO (y
))
3117 else if (REGNO (x
) < REGNO (y
))
3130 gcc_assert (GET_MODE (x
) == GET_MODE (y
));
3131 return loc_cmp (XEXP (x
, 0), XEXP (y
, 0));
3137 if (GET_CODE (x
) == VALUE
)
3139 if (GET_CODE (y
) != VALUE
)
3141 /* Don't assert the modes are the same, that is true only
3142 when not recursing. (subreg:QI (value:SI 1:1) 0)
3143 and (subreg:QI (value:DI 2:2) 0) can be compared,
3144 even when the modes are different. */
3145 if (canon_value_cmp (x
, y
))
3151 if (GET_CODE (y
) == VALUE
)
3154 /* Entry value is the least preferable kind of expression. */
3155 if (GET_CODE (x
) == ENTRY_VALUE
)
3157 if (GET_CODE (y
) != ENTRY_VALUE
)
3159 gcc_assert (GET_MODE (x
) == GET_MODE (y
));
3160 return loc_cmp (ENTRY_VALUE_EXP (x
), ENTRY_VALUE_EXP (y
));
3163 if (GET_CODE (y
) == ENTRY_VALUE
)
3166 if (GET_CODE (x
) == GET_CODE (y
))
3167 /* Compare operands below. */;
3168 else if (GET_CODE (x
) < GET_CODE (y
))
3173 gcc_assert (GET_MODE (x
) == GET_MODE (y
));
3175 if (GET_CODE (x
) == DEBUG_EXPR
)
3177 if (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x
))
3178 < DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (y
)))
3180 gcc_checking_assert (DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (x
))
3181 > DEBUG_TEMP_UID (DEBUG_EXPR_TREE_DECL (y
)));
3185 fmt
= GET_RTX_FORMAT (code
);
3186 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++)
3190 if (XWINT (x
, i
) == XWINT (y
, i
))
3192 else if (XWINT (x
, i
) < XWINT (y
, i
))
3199 if (XINT (x
, i
) == XINT (y
, i
))
3201 else if (XINT (x
, i
) < XINT (y
, i
))
3208 /* Compare the vector length first. */
3209 if (XVECLEN (x
, i
) == XVECLEN (y
, i
))
3210 /* Compare the vectors elements. */;
3211 else if (XVECLEN (x
, i
) < XVECLEN (y
, i
))
3216 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3217 if ((r
= loc_cmp (XVECEXP (x
, i
, j
),
3218 XVECEXP (y
, i
, j
))))
3223 if ((r
= loc_cmp (XEXP (x
, i
), XEXP (y
, i
))))
3229 if (XSTR (x
, i
) == XSTR (y
, i
))
3235 if ((r
= strcmp (XSTR (x
, i
), XSTR (y
, i
))) == 0)
3243 /* These are just backpointers, so they don't matter. */
3250 /* It is believed that rtx's at this level will never
3251 contain anything but integers and other rtx's,
3252 except for within LABEL_REFs and SYMBOL_REFs. */
3261 /* Check the order of entries in one-part variables. */
3264 canonicalize_loc_order_check (void **slot
, void *data ATTRIBUTE_UNUSED
)
3266 variable var
= (variable
) *slot
;
3267 location_chain node
, next
;
3269 #ifdef ENABLE_RTL_CHECKING
3271 for (i
= 0; i
< var
->n_var_parts
; i
++)
3272 gcc_assert (var
->var_part
[0].cur_loc
== NULL
);
3273 gcc_assert (!var
->in_changed_variables
);
3279 gcc_assert (var
->n_var_parts
== 1);
3280 node
= var
->var_part
[0].loc_chain
;
3283 while ((next
= node
->next
))
3285 gcc_assert (loc_cmp (node
->loc
, next
->loc
) < 0);
3293 /* Mark with VALUE_RECURSED_INTO values that have neighbors that are
3294 more likely to be chosen as canonical for an equivalence set.
3295 Ensure less likely values can reach more likely neighbors, making
3296 the connections bidirectional. */
3299 canonicalize_values_mark (void **slot
, void *data
)
3301 dataflow_set
*set
= (dataflow_set
*)data
;
3302 variable var
= (variable
) *slot
;
3303 decl_or_value dv
= var
->dv
;
3305 location_chain node
;
3307 if (!dv_is_value_p (dv
))
3310 gcc_checking_assert (var
->n_var_parts
== 1);
3312 val
= dv_as_value (dv
);
3314 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
3315 if (GET_CODE (node
->loc
) == VALUE
)
3317 if (canon_value_cmp (node
->loc
, val
))
3318 VALUE_RECURSED_INTO (val
) = true;
3321 decl_or_value odv
= dv_from_value (node
->loc
);
3322 void **oslot
= shared_hash_find_slot_noinsert (set
->vars
, odv
);
3324 set_slot_part (set
, val
, oslot
, odv
, 0,
3325 node
->init
, NULL_RTX
);
3327 VALUE_RECURSED_INTO (node
->loc
) = true;
3334 /* Remove redundant entries from equivalence lists in onepart
3335 variables, canonicalizing equivalence sets into star shapes. */
3338 canonicalize_values_star (void **slot
, void *data
)
3340 dataflow_set
*set
= (dataflow_set
*)data
;
3341 variable var
= (variable
) *slot
;
3342 decl_or_value dv
= var
->dv
;
3343 location_chain node
;
3353 gcc_checking_assert (var
->n_var_parts
== 1);
3355 if (dv_is_value_p (dv
))
3357 cval
= dv_as_value (dv
);
3358 if (!VALUE_RECURSED_INTO (cval
))
3360 VALUE_RECURSED_INTO (cval
) = false;
3370 gcc_assert (var
->n_var_parts
== 1);
3372 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
3373 if (GET_CODE (node
->loc
) == VALUE
)
3376 if (VALUE_RECURSED_INTO (node
->loc
))
3378 if (canon_value_cmp (node
->loc
, cval
))
3387 if (!has_marks
|| dv_is_decl_p (dv
))
3390 /* Keep it marked so that we revisit it, either after visiting a
3391 child node, or after visiting a new parent that might be
3393 VALUE_RECURSED_INTO (val
) = true;
3395 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
3396 if (GET_CODE (node
->loc
) == VALUE
3397 && VALUE_RECURSED_INTO (node
->loc
))
3401 VALUE_RECURSED_INTO (cval
) = false;
3402 dv
= dv_from_value (cval
);
3403 slot
= shared_hash_find_slot_noinsert (set
->vars
, dv
);
3406 gcc_assert (dv_is_decl_p (var
->dv
));
3407 /* The canonical value was reset and dropped.
3409 clobber_variable_part (set
, NULL
, var
->dv
, 0, NULL
);
3412 var
= (variable
)*slot
;
3413 gcc_assert (dv_is_value_p (var
->dv
));
3414 if (var
->n_var_parts
== 0)
3416 gcc_assert (var
->n_var_parts
== 1);
3420 VALUE_RECURSED_INTO (val
) = false;
3425 /* Push values to the canonical one. */
3426 cdv
= dv_from_value (cval
);
3427 cslot
= shared_hash_find_slot_noinsert (set
->vars
, cdv
);
3429 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
3430 if (node
->loc
!= cval
)
3432 cslot
= set_slot_part (set
, node
->loc
, cslot
, cdv
, 0,
3433 node
->init
, NULL_RTX
);
3434 if (GET_CODE (node
->loc
) == VALUE
)
3436 decl_or_value ndv
= dv_from_value (node
->loc
);
3438 set_variable_part (set
, cval
, ndv
, 0, node
->init
, NULL_RTX
,
3441 if (canon_value_cmp (node
->loc
, val
))
3443 /* If it could have been a local minimum, it's not any more,
3444 since it's now neighbor to cval, so it may have to push
3445 to it. Conversely, if it wouldn't have prevailed over
3446 val, then whatever mark it has is fine: if it was to
3447 push, it will now push to a more canonical node, but if
3448 it wasn't, then it has already pushed any values it might
3450 VALUE_RECURSED_INTO (node
->loc
) = true;
3451 /* Make sure we visit node->loc by ensuring we cval is
3453 VALUE_RECURSED_INTO (cval
) = true;
3455 else if (!VALUE_RECURSED_INTO (node
->loc
))
3456 /* If we have no need to "recurse" into this node, it's
3457 already "canonicalized", so drop the link to the old
3459 clobber_variable_part (set
, cval
, ndv
, 0, NULL
);
3461 else if (GET_CODE (node
->loc
) == REG
)
3463 attrs list
= set
->regs
[REGNO (node
->loc
)], *listp
;
3465 /* Change an existing attribute referring to dv so that it
3466 refers to cdv, removing any duplicate this might
3467 introduce, and checking that no previous duplicates
3468 existed, all in a single pass. */
3472 if (list
->offset
== 0
3473 && (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
)
3474 || dv_as_opaque (list
->dv
) == dv_as_opaque (cdv
)))
3481 if (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
))
3484 for (listp
= &list
->next
; (list
= *listp
); listp
= &list
->next
)
3489 if (dv_as_opaque (list
->dv
) == dv_as_opaque (cdv
))
3491 *listp
= list
->next
;
3492 pool_free (attrs_pool
, list
);
3497 gcc_assert (dv_as_opaque (list
->dv
) != dv_as_opaque (dv
));
3500 else if (dv_as_opaque (list
->dv
) == dv_as_opaque (cdv
))
3502 for (listp
= &list
->next
; (list
= *listp
); listp
= &list
->next
)
3507 if (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
))
3509 *listp
= list
->next
;
3510 pool_free (attrs_pool
, list
);
3515 gcc_assert (dv_as_opaque (list
->dv
) != dv_as_opaque (cdv
));
3524 if (list
->offset
== 0
3525 && (dv_as_opaque (list
->dv
) == dv_as_opaque (dv
)
3526 || dv_as_opaque (list
->dv
) == dv_as_opaque (cdv
)))
3536 set_slot_part (set
, val
, cslot
, cdv
, 0,
3537 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
);
3539 slot
= clobber_slot_part (set
, cval
, slot
, 0, NULL
);
3541 /* Variable may have been unshared. */
3542 var
= (variable
)*slot
;
3543 gcc_checking_assert (var
->n_var_parts
&& var
->var_part
[0].loc_chain
->loc
== cval
3544 && var
->var_part
[0].loc_chain
->next
== NULL
);
3546 if (VALUE_RECURSED_INTO (cval
))
3547 goto restart_with_cval
;
3552 /* Bind one-part variables to the canonical value in an equivalence
3553 set. Not doing this causes dataflow convergence failure in rare
3554 circumstances, see PR42873. Unfortunately we can't do this
3555 efficiently as part of canonicalize_values_star, since we may not
3556 have determined or even seen the canonical value of a set when we
3557 get to a variable that references another member of the set. */
3560 canonicalize_vars_star (void **slot
, void *data
)
3562 dataflow_set
*set
= (dataflow_set
*)data
;
3563 variable var
= (variable
) *slot
;
3564 decl_or_value dv
= var
->dv
;
3565 location_chain node
;
3570 location_chain cnode
;
3572 if (!var
->onepart
|| var
->onepart
== ONEPART_VALUE
)
3575 gcc_assert (var
->n_var_parts
== 1);
3577 node
= var
->var_part
[0].loc_chain
;
3579 if (GET_CODE (node
->loc
) != VALUE
)
3582 gcc_assert (!node
->next
);
3585 /* Push values to the canonical one. */
3586 cdv
= dv_from_value (cval
);
3587 cslot
= shared_hash_find_slot_noinsert (set
->vars
, cdv
);
3590 cvar
= (variable
)*cslot
;
3591 gcc_assert (cvar
->n_var_parts
== 1);
3593 cnode
= cvar
->var_part
[0].loc_chain
;
3595 /* CVAL is canonical if its value list contains non-VALUEs or VALUEs
3596 that are not “more canonical” than it. */
3597 if (GET_CODE (cnode
->loc
) != VALUE
3598 || !canon_value_cmp (cnode
->loc
, cval
))
3601 /* CVAL was found to be non-canonical. Change the variable to point
3602 to the canonical VALUE. */
3603 gcc_assert (!cnode
->next
);
3606 slot
= set_slot_part (set
, cval
, slot
, dv
, 0,
3607 node
->init
, node
->set_src
);
3608 clobber_slot_part (set
, cval
, slot
, 0, node
->set_src
);
3613 /* Combine variable or value in *S1SLOT (in DSM->cur) with the
3614 corresponding entry in DSM->src. Multi-part variables are combined
3615 with variable_union, whereas onepart dvs are combined with
3619 variable_merge_over_cur (variable s1var
, struct dfset_merge
*dsm
)
3621 dataflow_set
*dst
= dsm
->dst
;
3623 variable s2var
, dvar
= NULL
;
3624 decl_or_value dv
= s1var
->dv
;
3625 onepart_enum_t onepart
= s1var
->onepart
;
3628 location_chain node
, *nodep
;
3630 /* If the incoming onepart variable has an empty location list, then
3631 the intersection will be just as empty. For other variables,
3632 it's always union. */
3633 gcc_checking_assert (s1var
->n_var_parts
3634 && s1var
->var_part
[0].loc_chain
);
3637 return variable_union (s1var
, dst
);
3639 gcc_checking_assert (s1var
->n_var_parts
== 1);
3641 dvhash
= dv_htab_hash (dv
);
3642 if (dv_is_value_p (dv
))
3643 val
= dv_as_value (dv
);
3647 s2var
= shared_hash_find_1 (dsm
->src
->vars
, dv
, dvhash
);
3650 dst_can_be_shared
= false;
3654 dsm
->src_onepart_cnt
--;
3655 gcc_assert (s2var
->var_part
[0].loc_chain
3656 && s2var
->onepart
== onepart
3657 && s2var
->n_var_parts
== 1);
3659 dstslot
= shared_hash_find_slot_noinsert_1 (dst
->vars
, dv
, dvhash
);
3662 dvar
= (variable
)*dstslot
;
3663 gcc_assert (dvar
->refcount
== 1
3664 && dvar
->onepart
== onepart
3665 && dvar
->n_var_parts
== 1);
3666 nodep
= &dvar
->var_part
[0].loc_chain
;
3674 if (!dstslot
&& !onepart_variable_different_p (s1var
, s2var
))
3676 dstslot
= shared_hash_find_slot_unshare_1 (&dst
->vars
, dv
,
3678 *dstslot
= dvar
= s2var
;
3683 dst_can_be_shared
= false;
3685 intersect_loc_chains (val
, nodep
, dsm
,
3686 s1var
->var_part
[0].loc_chain
, s2var
);
3692 dvar
= (variable
) pool_alloc (onepart_pool (onepart
));
3695 dvar
->n_var_parts
= 1;
3696 dvar
->onepart
= onepart
;
3697 dvar
->in_changed_variables
= false;
3698 dvar
->var_part
[0].loc_chain
= node
;
3699 dvar
->var_part
[0].cur_loc
= NULL
;
3701 VAR_LOC_1PAUX (dvar
) = NULL
;
3703 VAR_PART_OFFSET (dvar
, 0) = 0;
3706 = shared_hash_find_slot_unshare_1 (&dst
->vars
, dv
, dvhash
,
3708 gcc_assert (!*dstslot
);
3716 nodep
= &dvar
->var_part
[0].loc_chain
;
3717 while ((node
= *nodep
))
3719 location_chain
*nextp
= &node
->next
;
3721 if (GET_CODE (node
->loc
) == REG
)
3725 for (list
= dst
->regs
[REGNO (node
->loc
)]; list
; list
= list
->next
)
3726 if (GET_MODE (node
->loc
) == GET_MODE (list
->loc
)
3727 && dv_is_value_p (list
->dv
))
3731 attrs_list_insert (&dst
->regs
[REGNO (node
->loc
)],
3733 /* If this value became canonical for another value that had
3734 this register, we want to leave it alone. */
3735 else if (dv_as_value (list
->dv
) != val
)
3737 dstslot
= set_slot_part (dst
, dv_as_value (list
->dv
),
3739 node
->init
, NULL_RTX
);
3740 dstslot
= delete_slot_part (dst
, node
->loc
, dstslot
, 0);
3742 /* Since nextp points into the removed node, we can't
3743 use it. The pointer to the next node moved to nodep.
3744 However, if the variable we're walking is unshared
3745 during our walk, we'll keep walking the location list
3746 of the previously-shared variable, in which case the
3747 node won't have been removed, and we'll want to skip
3748 it. That's why we test *nodep here. */
3754 /* Canonicalization puts registers first, so we don't have to
3760 if (dvar
!= (variable
)*dstslot
)
3761 dvar
= (variable
)*dstslot
;
3762 nodep
= &dvar
->var_part
[0].loc_chain
;
3766 /* Mark all referenced nodes for canonicalization, and make sure
3767 we have mutual equivalence links. */
3768 VALUE_RECURSED_INTO (val
) = true;
3769 for (node
= *nodep
; node
; node
= node
->next
)
3770 if (GET_CODE (node
->loc
) == VALUE
)
3772 VALUE_RECURSED_INTO (node
->loc
) = true;
3773 set_variable_part (dst
, val
, dv_from_value (node
->loc
), 0,
3774 node
->init
, NULL
, INSERT
);
3777 dstslot
= shared_hash_find_slot_noinsert_1 (dst
->vars
, dv
, dvhash
);
3778 gcc_assert (*dstslot
== dvar
);
3779 canonicalize_values_star (dstslot
, dst
);
3780 gcc_checking_assert (dstslot
3781 == shared_hash_find_slot_noinsert_1 (dst
->vars
,
3783 dvar
= (variable
)*dstslot
;
3787 bool has_value
= false, has_other
= false;
3789 /* If we have one value and anything else, we're going to
3790 canonicalize this, so make sure all values have an entry in
3791 the table and are marked for canonicalization. */
3792 for (node
= *nodep
; node
; node
= node
->next
)
3794 if (GET_CODE (node
->loc
) == VALUE
)
3796 /* If this was marked during register canonicalization,
3797 we know we have to canonicalize values. */
3812 if (has_value
&& has_other
)
3814 for (node
= *nodep
; node
; node
= node
->next
)
3816 if (GET_CODE (node
->loc
) == VALUE
)
3818 decl_or_value dv
= dv_from_value (node
->loc
);
3821 if (shared_hash_shared (dst
->vars
))
3822 slot
= shared_hash_find_slot_noinsert (dst
->vars
, dv
);
3824 slot
= shared_hash_find_slot_unshare (&dst
->vars
, dv
,
3828 variable var
= (variable
) pool_alloc (onepart_pool
3832 var
->n_var_parts
= 1;
3833 var
->onepart
= ONEPART_VALUE
;
3834 var
->in_changed_variables
= false;
3835 var
->var_part
[0].loc_chain
= NULL
;
3836 var
->var_part
[0].cur_loc
= NULL
;
3837 VAR_LOC_1PAUX (var
) = NULL
;
3841 VALUE_RECURSED_INTO (node
->loc
) = true;
3845 dstslot
= shared_hash_find_slot_noinsert_1 (dst
->vars
, dv
, dvhash
);
3846 gcc_assert (*dstslot
== dvar
);
3847 canonicalize_values_star (dstslot
, dst
);
3848 gcc_checking_assert (dstslot
3849 == shared_hash_find_slot_noinsert_1 (dst
->vars
,
3851 dvar
= (variable
)*dstslot
;
3855 if (!onepart_variable_different_p (dvar
, s2var
))
3857 variable_htab_free (dvar
);
3858 *dstslot
= dvar
= s2var
;
3861 else if (s2var
!= s1var
&& !onepart_variable_different_p (dvar
, s1var
))
3863 variable_htab_free (dvar
);
3864 *dstslot
= dvar
= s1var
;
3866 dst_can_be_shared
= false;
3869 dst_can_be_shared
= false;
3874 /* Copy s2slot (in DSM->src) to DSM->dst if the variable is a
3875 multi-part variable. Unions of multi-part variables and
3876 intersections of one-part ones will be handled in
3877 variable_merge_over_cur(). */
3880 variable_merge_over_src (variable s2var
, struct dfset_merge
*dsm
)
3882 dataflow_set
*dst
= dsm
->dst
;
3883 decl_or_value dv
= s2var
->dv
;
3885 if (!s2var
->onepart
)
3887 void **dstp
= shared_hash_find_slot (dst
->vars
, dv
);
3893 dsm
->src_onepart_cnt
++;
3897 /* Combine dataflow set information from SRC2 into DST, using PDST
3898 to carry over information across passes. */
3901 dataflow_set_merge (dataflow_set
*dst
, dataflow_set
*src2
)
3903 dataflow_set cur
= *dst
;
3904 dataflow_set
*src1
= &cur
;
3905 struct dfset_merge dsm
;
3907 size_t src1_elems
, src2_elems
;
3911 src1_elems
= htab_elements (shared_hash_htab (src1
->vars
));
3912 src2_elems
= htab_elements (shared_hash_htab (src2
->vars
));
3913 dataflow_set_init (dst
);
3914 dst
->stack_adjust
= cur
.stack_adjust
;
3915 shared_hash_destroy (dst
->vars
);
3916 dst
->vars
= (shared_hash
) pool_alloc (shared_hash_pool
);
3917 dst
->vars
->refcount
= 1;
3919 = htab_create (MAX (src1_elems
, src2_elems
), variable_htab_hash
,
3920 variable_htab_eq
, variable_htab_free
);
3922 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3923 attrs_list_mpdv_union (&dst
->regs
[i
], src1
->regs
[i
], src2
->regs
[i
]);
3928 dsm
.src_onepart_cnt
= 0;
3930 FOR_EACH_HTAB_ELEMENT (shared_hash_htab (dsm
.src
->vars
), var
, variable
, hi
)
3931 variable_merge_over_src (var
, &dsm
);
3932 FOR_EACH_HTAB_ELEMENT (shared_hash_htab (dsm
.cur
->vars
), var
, variable
, hi
)
3933 variable_merge_over_cur (var
, &dsm
);
3935 if (dsm
.src_onepart_cnt
)
3936 dst_can_be_shared
= false;
3938 dataflow_set_destroy (src1
);
3941 /* Mark register equivalences. */
3944 dataflow_set_equiv_regs (dataflow_set
*set
)
3949 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3951 rtx canon
[NUM_MACHINE_MODES
];
3953 /* If the list is empty or one entry, no need to canonicalize
3955 if (set
->regs
[i
] == NULL
|| set
->regs
[i
]->next
== NULL
)
3958 memset (canon
, 0, sizeof (canon
));
3960 for (list
= set
->regs
[i
]; list
; list
= list
->next
)
3961 if (list
->offset
== 0 && dv_is_value_p (list
->dv
))
3963 rtx val
= dv_as_value (list
->dv
);
3964 rtx
*cvalp
= &canon
[(int)GET_MODE (val
)];
3967 if (canon_value_cmp (val
, cval
))
3971 for (list
= set
->regs
[i
]; list
; list
= list
->next
)
3972 if (list
->offset
== 0 && dv_onepart_p (list
->dv
))
3974 rtx cval
= canon
[(int)GET_MODE (list
->loc
)];
3979 if (dv_is_value_p (list
->dv
))
3981 rtx val
= dv_as_value (list
->dv
);
3986 VALUE_RECURSED_INTO (val
) = true;
3987 set_variable_part (set
, val
, dv_from_value (cval
), 0,
3988 VAR_INIT_STATUS_INITIALIZED
,
3992 VALUE_RECURSED_INTO (cval
) = true;
3993 set_variable_part (set
, cval
, list
->dv
, 0,
3994 VAR_INIT_STATUS_INITIALIZED
, NULL
, NO_INSERT
);
3997 for (listp
= &set
->regs
[i
]; (list
= *listp
);
3998 listp
= list
? &list
->next
: listp
)
3999 if (list
->offset
== 0 && dv_onepart_p (list
->dv
))
4001 rtx cval
= canon
[(int)GET_MODE (list
->loc
)];
4007 if (dv_is_value_p (list
->dv
))
4009 rtx val
= dv_as_value (list
->dv
);
4010 if (!VALUE_RECURSED_INTO (val
))
4014 slot
= shared_hash_find_slot_noinsert (set
->vars
, list
->dv
);
4015 canonicalize_values_star (slot
, set
);
4022 /* Remove any redundant values in the location list of VAR, which must
4023 be unshared and 1-part. */
4026 remove_duplicate_values (variable var
)
4028 location_chain node
, *nodep
;
4030 gcc_assert (var
->onepart
);
4031 gcc_assert (var
->n_var_parts
== 1);
4032 gcc_assert (var
->refcount
== 1);
4034 for (nodep
= &var
->var_part
[0].loc_chain
; (node
= *nodep
); )
4036 if (GET_CODE (node
->loc
) == VALUE
)
4038 if (VALUE_RECURSED_INTO (node
->loc
))
4040 /* Remove duplicate value node. */
4041 *nodep
= node
->next
;
4042 pool_free (loc_chain_pool
, node
);
4046 VALUE_RECURSED_INTO (node
->loc
) = true;
4048 nodep
= &node
->next
;
4051 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
4052 if (GET_CODE (node
->loc
) == VALUE
)
4054 gcc_assert (VALUE_RECURSED_INTO (node
->loc
));
4055 VALUE_RECURSED_INTO (node
->loc
) = false;
4060 /* Hash table iteration argument passed to variable_post_merge. */
4061 struct dfset_post_merge
4063 /* The new input set for the current block. */
4065 /* Pointer to the permanent input set for the current block, or
4067 dataflow_set
**permp
;
4070 /* Create values for incoming expressions associated with one-part
4071 variables that don't have value numbers for them. */
4074 variable_post_merge_new_vals (void **slot
, void *info
)
4076 struct dfset_post_merge
*dfpm
= (struct dfset_post_merge
*)info
;
4077 dataflow_set
*set
= dfpm
->set
;
4078 variable var
= (variable
)*slot
;
4079 location_chain node
;
4081 if (!var
->onepart
|| !var
->n_var_parts
)
4084 gcc_assert (var
->n_var_parts
== 1);
4086 if (dv_is_decl_p (var
->dv
))
4088 bool check_dupes
= false;
4091 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
4093 if (GET_CODE (node
->loc
) == VALUE
)
4094 gcc_assert (!VALUE_RECURSED_INTO (node
->loc
));
4095 else if (GET_CODE (node
->loc
) == REG
)
4097 attrs att
, *attp
, *curp
= NULL
;
4099 if (var
->refcount
!= 1)
4101 slot
= unshare_variable (set
, slot
, var
,
4102 VAR_INIT_STATUS_INITIALIZED
);
4103 var
= (variable
)*slot
;
4107 for (attp
= &set
->regs
[REGNO (node
->loc
)]; (att
= *attp
);
4109 if (att
->offset
== 0
4110 && GET_MODE (att
->loc
) == GET_MODE (node
->loc
))
4112 if (dv_is_value_p (att
->dv
))
4114 rtx cval
= dv_as_value (att
->dv
);
4119 else if (dv_as_opaque (att
->dv
) == dv_as_opaque (var
->dv
))
4127 if ((*curp
)->offset
== 0
4128 && GET_MODE ((*curp
)->loc
) == GET_MODE (node
->loc
)
4129 && dv_as_opaque ((*curp
)->dv
) == dv_as_opaque (var
->dv
))
4132 curp
= &(*curp
)->next
;
4143 *dfpm
->permp
= XNEW (dataflow_set
);
4144 dataflow_set_init (*dfpm
->permp
);
4147 for (att
= (*dfpm
->permp
)->regs
[REGNO (node
->loc
)];
4148 att
; att
= att
->next
)
4149 if (GET_MODE (att
->loc
) == GET_MODE (node
->loc
))
4151 gcc_assert (att
->offset
== 0
4152 && dv_is_value_p (att
->dv
));
4153 val_reset (set
, att
->dv
);
4160 cval
= dv_as_value (cdv
);
4164 /* Create a unique value to hold this register,
4165 that ought to be found and reused in
4166 subsequent rounds. */
4168 gcc_assert (!cselib_lookup (node
->loc
,
4169 GET_MODE (node
->loc
), 0,
4171 v
= cselib_lookup (node
->loc
, GET_MODE (node
->loc
), 1,
4173 cselib_preserve_value (v
);
4174 cselib_invalidate_rtx (node
->loc
);
4176 cdv
= dv_from_value (cval
);
4179 "Created new value %u:%u for reg %i\n",
4180 v
->uid
, v
->hash
, REGNO (node
->loc
));
4183 var_reg_decl_set (*dfpm
->permp
, node
->loc
,
4184 VAR_INIT_STATUS_INITIALIZED
,
4185 cdv
, 0, NULL
, INSERT
);
4191 /* Remove attribute referring to the decl, which now
4192 uses the value for the register, already existing or
4193 to be added when we bring perm in. */
4196 pool_free (attrs_pool
, att
);
4201 remove_duplicate_values (var
);
4207 /* Reset values in the permanent set that are not associated with the
4208 chosen expression. */
4211 variable_post_merge_perm_vals (void **pslot
, void *info
)
4213 struct dfset_post_merge
*dfpm
= (struct dfset_post_merge
*)info
;
4214 dataflow_set
*set
= dfpm
->set
;
4215 variable pvar
= (variable
)*pslot
, var
;
4216 location_chain pnode
;
4220 gcc_assert (dv_is_value_p (pvar
->dv
)
4221 && pvar
->n_var_parts
== 1);
4222 pnode
= pvar
->var_part
[0].loc_chain
;
4225 && REG_P (pnode
->loc
));
4229 var
= shared_hash_find (set
->vars
, dv
);
4232 /* Although variable_post_merge_new_vals may have made decls
4233 non-star-canonical, values that pre-existed in canonical form
4234 remain canonical, and newly-created values reference a single
4235 REG, so they are canonical as well. Since VAR has the
4236 location list for a VALUE, using find_loc_in_1pdv for it is
4237 fine, since VALUEs don't map back to DECLs. */
4238 if (find_loc_in_1pdv (pnode
->loc
, var
, shared_hash_htab (set
->vars
)))
4240 val_reset (set
, dv
);
4243 for (att
= set
->regs
[REGNO (pnode
->loc
)]; att
; att
= att
->next
)
4244 if (att
->offset
== 0
4245 && GET_MODE (att
->loc
) == GET_MODE (pnode
->loc
)
4246 && dv_is_value_p (att
->dv
))
4249 /* If there is a value associated with this register already, create
4251 if (att
&& dv_as_value (att
->dv
) != dv_as_value (dv
))
4253 rtx cval
= dv_as_value (att
->dv
);
4254 set_variable_part (set
, cval
, dv
, 0, pnode
->init
, NULL
, INSERT
);
4255 set_variable_part (set
, dv_as_value (dv
), att
->dv
, 0, pnode
->init
,
4260 attrs_list_insert (&set
->regs
[REGNO (pnode
->loc
)],
4262 variable_union (pvar
, set
);
4268 /* Just checking stuff and registering register attributes for
4272 dataflow_post_merge_adjust (dataflow_set
*set
, dataflow_set
**permp
)
4274 struct dfset_post_merge dfpm
;
4279 htab_traverse (shared_hash_htab (set
->vars
), variable_post_merge_new_vals
,
4282 htab_traverse (shared_hash_htab ((*permp
)->vars
),
4283 variable_post_merge_perm_vals
, &dfpm
);
4284 htab_traverse (shared_hash_htab (set
->vars
), canonicalize_values_star
, set
);
4285 htab_traverse (shared_hash_htab (set
->vars
), canonicalize_vars_star
, set
);
4288 /* Return a node whose loc is a MEM that refers to EXPR in the
4289 location list of a one-part variable or value VAR, or in that of
4290 any values recursively mentioned in the location lists. */
4292 static location_chain
4293 find_mem_expr_in_1pdv (tree expr
, rtx val
, htab_t vars
)
4295 location_chain node
;
4298 location_chain where
= NULL
;
4303 gcc_assert (GET_CODE (val
) == VALUE
4304 && !VALUE_RECURSED_INTO (val
));
4306 dv
= dv_from_value (val
);
4307 var
= (variable
) htab_find_with_hash (vars
, dv
, dv_htab_hash (dv
));
4312 gcc_assert (var
->onepart
);
4314 if (!var
->n_var_parts
)
4317 VALUE_RECURSED_INTO (val
) = true;
4319 for (node
= var
->var_part
[0].loc_chain
; node
; node
= node
->next
)
4320 if (MEM_P (node
->loc
)
4321 && MEM_EXPR (node
->loc
) == expr
4322 && INT_MEM_OFFSET (node
->loc
) == 0)
4327 else if (GET_CODE (node
->loc
) == VALUE
4328 && !VALUE_RECURSED_INTO (node
->loc
)
4329 && (where
= find_mem_expr_in_1pdv (expr
, node
->loc
, vars
)))
4332 VALUE_RECURSED_INTO (val
) = false;
4337 /* Return TRUE if the value of MEM may vary across a call. */
4340 mem_dies_at_call (rtx mem
)
4342 tree expr
= MEM_EXPR (mem
);
4348 decl
= get_base_address (expr
);
4356 return (may_be_aliased (decl
)
4357 || (!TREE_READONLY (decl
) && is_global_var (decl
)));
4360 /* Remove all MEMs from the location list of a hash table entry for a
4361 one-part variable, except those whose MEM attributes map back to
4362 the variable itself, directly or within a VALUE. */
4365 dataflow_set_preserve_mem_locs (void **slot
, void *data
)
4367 dataflow_set
*set
= (dataflow_set
*) data
;
4368 variable var
= (variable
) *slot
;
4370 if (var
->onepart
== ONEPART_VDECL
|| var
->onepart
== ONEPART_DEXPR
)
4372 tree decl
= dv_as_decl (var
->dv
);
4373 location_chain loc
, *locp
;
4374 bool changed
= false;
4376 if (!var
->n_var_parts
)
4379 gcc_assert (var
->n_var_parts
== 1);
4381 if (shared_var_p (var
, set
->vars
))
4383 for (loc
= var
->var_part
[0].loc_chain
; loc
; loc
= loc
->next
)
4385 /* We want to remove dying MEMs that doesn't refer to DECL. */
4386 if (GET_CODE (loc
->loc
) == MEM
4387 && (MEM_EXPR (loc
->loc
) != decl
4388 || INT_MEM_OFFSET (loc
->loc
) != 0)
4389 && !mem_dies_at_call (loc
->loc
))
4391 /* We want to move here MEMs that do refer to DECL. */
4392 else if (GET_CODE (loc
->loc
) == VALUE
4393 && find_mem_expr_in_1pdv (decl
, loc
->loc
,
4394 shared_hash_htab (set
->vars
)))
4401 slot
= unshare_variable (set
, slot
, var
, VAR_INIT_STATUS_UNKNOWN
);
4402 var
= (variable
)*slot
;
4403 gcc_assert (var
->n_var_parts
== 1);
4406 for (locp
= &var
->var_part
[0].loc_chain
, loc
= *locp
;
4409 rtx old_loc
= loc
->loc
;
4410 if (GET_CODE (old_loc
) == VALUE
)
4412 location_chain mem_node
4413 = find_mem_expr_in_1pdv (decl
, loc
->loc
,
4414 shared_hash_htab (set
->vars
));
4416 /* ??? This picks up only one out of multiple MEMs that
4417 refer to the same variable. Do we ever need to be
4418 concerned about dealing with more than one, or, given
4419 that they should all map to the same variable
4420 location, their addresses will have been merged and
4421 they will be regarded as equivalent? */
4424 loc
->loc
= mem_node
->loc
;
4425 loc
->set_src
= mem_node
->set_src
;
4426 loc
->init
= MIN (loc
->init
, mem_node
->init
);
4430 if (GET_CODE (loc
->loc
) != MEM
4431 || (MEM_EXPR (loc
->loc
) == decl
4432 && INT_MEM_OFFSET (loc
->loc
) == 0)
4433 || !mem_dies_at_call (loc
->loc
))
4435 if (old_loc
!= loc
->loc
&& emit_notes
)
4437 if (old_loc
== var
->var_part
[0].cur_loc
)
4440 var
->var_part
[0].cur_loc
= NULL
;
4449 if (old_loc
== var
->var_part
[0].cur_loc
)
4452 var
->var_part
[0].cur_loc
= NULL
;
4456 pool_free (loc_chain_pool
, loc
);
4459 if (!var
->var_part
[0].loc_chain
)
4465 variable_was_changed (var
, set
);
4471 /* Remove all MEMs from the location list of a hash table entry for a
4475 dataflow_set_remove_mem_locs (void **slot
, void *data
)
4477 dataflow_set
*set
= (dataflow_set
*) data
;
4478 variable var
= (variable
) *slot
;
4480 if (var
->onepart
== ONEPART_VALUE
)
4482 location_chain loc
, *locp
;
4483 bool changed
= false;
4486 gcc_assert (var
->n_var_parts
== 1);
4488 if (shared_var_p (var
, set
->vars
))
4490 for (loc
= var
->var_part
[0].loc_chain
; loc
; loc
= loc
->next
)
4491 if (GET_CODE (loc
->loc
) == MEM
4492 && mem_dies_at_call (loc
->loc
))
4498 slot
= unshare_variable (set
, slot
, var
, VAR_INIT_STATUS_UNKNOWN
);
4499 var
= (variable
)*slot
;
4500 gcc_assert (var
->n_var_parts
== 1);
4503 if (VAR_LOC_1PAUX (var
))
4504 cur_loc
= VAR_LOC_FROM (var
);
4506 cur_loc
= var
->var_part
[0].cur_loc
;
4508 for (locp
= &var
->var_part
[0].loc_chain
, loc
= *locp
;
4511 if (GET_CODE (loc
->loc
) != MEM
4512 || !mem_dies_at_call (loc
->loc
))
4519 /* If we have deleted the location which was last emitted
4520 we have to emit new location so add the variable to set
4521 of changed variables. */
4522 if (cur_loc
== loc
->loc
)
4525 var
->var_part
[0].cur_loc
= NULL
;
4526 if (VAR_LOC_1PAUX (var
))
4527 VAR_LOC_FROM (var
) = NULL
;
4529 pool_free (loc_chain_pool
, loc
);
4532 if (!var
->var_part
[0].loc_chain
)
4538 variable_was_changed (var
, set
);
4544 /* Remove all variable-location information about call-clobbered
4545 registers, as well as associations between MEMs and VALUEs. */
4548 dataflow_set_clear_at_call (dataflow_set
*set
)
4552 for (r
= 0; r
< FIRST_PSEUDO_REGISTER
; r
++)
4553 if (TEST_HARD_REG_BIT (regs_invalidated_by_call
, r
))
4554 var_regno_delete (set
, r
);
4556 if (MAY_HAVE_DEBUG_INSNS
)
4558 set
->traversed_vars
= set
->vars
;
4559 htab_traverse (shared_hash_htab (set
->vars
),
4560 dataflow_set_preserve_mem_locs
, set
);
4561 set
->traversed_vars
= set
->vars
;
4562 htab_traverse (shared_hash_htab (set
->vars
), dataflow_set_remove_mem_locs
,
4564 set
->traversed_vars
= NULL
;
4569 variable_part_different_p (variable_part
*vp1
, variable_part
*vp2
)
4571 location_chain lc1
, lc2
;
4573 for (lc1
= vp1
->loc_chain
; lc1
; lc1
= lc1
->next
)
4575 for (lc2
= vp2
->loc_chain
; lc2
; lc2
= lc2
->next
)
4577 if (REG_P (lc1
->loc
) && REG_P (lc2
->loc
))
4579 if (REGNO (lc1
->loc
) == REGNO (lc2
->loc
))
4582 if (rtx_equal_p (lc1
->loc
, lc2
->loc
))
4591 /* Return true if one-part variables VAR1 and VAR2 are different.
4592 They must be in canonical order. */
4595 onepart_variable_different_p (variable var1
, variable var2
)
4597 location_chain lc1
, lc2
;
4602 gcc_assert (var1
->n_var_parts
== 1
4603 && var2
->n_var_parts
== 1);
4605 lc1
= var1
->var_part
[0].loc_chain
;
4606 lc2
= var2
->var_part
[0].loc_chain
;
4608 gcc_assert (lc1
&& lc2
);
4612 if (loc_cmp (lc1
->loc
, lc2
->loc
))
4621 /* Return true if variables VAR1 and VAR2 are different. */
4624 variable_different_p (variable var1
, variable var2
)
4631 if (var1
->onepart
!= var2
->onepart
)
4634 if (var1
->n_var_parts
!= var2
->n_var_parts
)
4637 if (var1
->onepart
&& var1
->n_var_parts
)
4639 gcc_checking_assert (dv_as_opaque (var1
->dv
) == dv_as_opaque (var2
->dv
)
4640 && var1
->n_var_parts
== 1);
4641 /* One-part values have locations in a canonical order. */
4642 return onepart_variable_different_p (var1
, var2
);
4645 for (i
= 0; i
< var1
->n_var_parts
; i
++)
4647 if (VAR_PART_OFFSET (var1
, i
) != VAR_PART_OFFSET (var2
, i
))
4649 if (variable_part_different_p (&var1
->var_part
[i
], &var2
->var_part
[i
]))
4651 if (variable_part_different_p (&var2
->var_part
[i
], &var1
->var_part
[i
]))
4657 /* Return true if dataflow sets OLD_SET and NEW_SET differ. */
4660 dataflow_set_different (dataflow_set
*old_set
, dataflow_set
*new_set
)
4665 if (old_set
->vars
== new_set
->vars
)
4668 if (htab_elements (shared_hash_htab (old_set
->vars
))
4669 != htab_elements (shared_hash_htab (new_set
->vars
)))
4672 FOR_EACH_HTAB_ELEMENT (shared_hash_htab (old_set
->vars
), var1
, variable
, hi
)
4674 htab_t htab
= shared_hash_htab (new_set
->vars
);
4675 variable var2
= (variable
) htab_find_with_hash (htab
, var1
->dv
,
4676 dv_htab_hash (var1
->dv
));
4679 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4681 fprintf (dump_file
, "dataflow difference found: removal of:\n");
4687 if (variable_different_p (var1
, var2
))
4689 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4691 fprintf (dump_file
, "dataflow difference found: "
4692 "old and new follow:\n");
4700 /* No need to traverse the second hashtab, if both have the same number
4701 of elements and the second one had all entries found in the first one,
4702 then it can't have any extra entries. */
4706 /* Free the contents of dataflow set SET. */
4709 dataflow_set_destroy (dataflow_set
*set
)
4713 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4714 attrs_list_clear (&set
->regs
[i
]);
4716 shared_hash_destroy (set
->vars
);
4720 /* Return true if RTL X contains a SYMBOL_REF. */
4723 contains_symbol_ref (rtx x
)
4732 code
= GET_CODE (x
);
4733 if (code
== SYMBOL_REF
)
4736 fmt
= GET_RTX_FORMAT (code
);
4737 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4741 if (contains_symbol_ref (XEXP (x
, i
)))
4744 else if (fmt
[i
] == 'E')
4747 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4748 if (contains_symbol_ref (XVECEXP (x
, i
, j
)))
4756 /* Shall EXPR be tracked? */
4759 track_expr_p (tree expr
, bool need_rtl
)
4764 if (TREE_CODE (expr
) == DEBUG_EXPR_DECL
)
4765 return DECL_RTL_SET_P (expr
);
4767 /* If EXPR is not a parameter or a variable do not track it. */
4768 if (TREE_CODE (expr
) != VAR_DECL
&& TREE_CODE (expr
) != PARM_DECL
)
4771 /* It also must have a name... */
4772 if (!DECL_NAME (expr
) && need_rtl
)
4775 /* ... and a RTL assigned to it. */
4776 decl_rtl
= DECL_RTL_IF_SET (expr
);
4777 if (!decl_rtl
&& need_rtl
)
4780 /* If this expression is really a debug alias of some other declaration, we
4781 don't need to track this expression if the ultimate declaration is
4784 if (DECL_DEBUG_EXPR_IS_FROM (realdecl
))
4786 realdecl
= DECL_DEBUG_EXPR (realdecl
);
4787 if (realdecl
== NULL_TREE
)
4789 else if (!DECL_P (realdecl
))
4791 if (handled_component_p (realdecl
))
4793 HOST_WIDE_INT bitsize
, bitpos
, maxsize
;
4795 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
,
4797 if (!DECL_P (innerdecl
)
4798 || DECL_IGNORED_P (innerdecl
)
4799 || TREE_STATIC (innerdecl
)
4801 || bitpos
+ bitsize
> 256
4802 || bitsize
!= maxsize
)
4812 /* Do not track EXPR if REALDECL it should be ignored for debugging
4814 if (DECL_IGNORED_P (realdecl
))
4817 /* Do not track global variables until we are able to emit correct location
4819 if (TREE_STATIC (realdecl
))
4822 /* When the EXPR is a DECL for alias of some variable (see example)
4823 the TREE_STATIC flag is not used. Disable tracking all DECLs whose
4824 DECL_RTL contains SYMBOL_REF.
4827 extern char **_dl_argv_internal __attribute__ ((alias ("_dl_argv")));
4830 if (decl_rtl
&& MEM_P (decl_rtl
)
4831 && contains_symbol_ref (XEXP (decl_rtl
, 0)))
4834 /* If RTX is a memory it should not be very large (because it would be
4835 an array or struct). */
4836 if (decl_rtl
&& MEM_P (decl_rtl
))
4838 /* Do not track structures and arrays. */
4839 if (GET_MODE (decl_rtl
) == BLKmode
4840 || AGGREGATE_TYPE_P (TREE_TYPE (realdecl
)))
4842 if (MEM_SIZE_KNOWN_P (decl_rtl
)
4843 && MEM_SIZE (decl_rtl
) > MAX_VAR_PARTS
)
4847 DECL_CHANGED (expr
) = 0;
4848 DECL_CHANGED (realdecl
) = 0;
4852 /* Determine whether a given LOC refers to the same variable part as
4856 same_variable_part_p (rtx loc
, tree expr
, HOST_WIDE_INT offset
)
4859 HOST_WIDE_INT offset2
;
4861 if (! DECL_P (expr
))
4866 expr2
= REG_EXPR (loc
);
4867 offset2
= REG_OFFSET (loc
);
4869 else if (MEM_P (loc
))
4871 expr2
= MEM_EXPR (loc
);
4872 offset2
= INT_MEM_OFFSET (loc
);
4877 if (! expr2
|| ! DECL_P (expr2
))
4880 expr
= var_debug_decl (expr
);
4881 expr2
= var_debug_decl (expr2
);
4883 return (expr
== expr2
&& offset
== offset2
);
4886 /* LOC is a REG or MEM that we would like to track if possible.
4887 If EXPR is null, we don't know what expression LOC refers to,
4888 otherwise it refers to EXPR + OFFSET. STORE_REG_P is true if
4889 LOC is an lvalue register.
4891 Return true if EXPR is nonnull and if LOC, or some lowpart of it,
4892 is something we can track. When returning true, store the mode of
4893 the lowpart we can track in *MODE_OUT (if nonnull) and its offset
4894 from EXPR in *OFFSET_OUT (if nonnull). */
4897 track_loc_p (rtx loc
, tree expr
, HOST_WIDE_INT offset
, bool store_reg_p
,
4898 enum machine_mode
*mode_out
, HOST_WIDE_INT
*offset_out
)
4900 enum machine_mode mode
;
4902 if (expr
== NULL
|| !track_expr_p (expr
, true))
4905 /* If REG was a paradoxical subreg, its REG_ATTRS will describe the
4906 whole subreg, but only the old inner part is really relevant. */
4907 mode
= GET_MODE (loc
);
4908 if (REG_P (loc
) && !HARD_REGISTER_NUM_P (ORIGINAL_REGNO (loc
)))
4910 enum machine_mode pseudo_mode
;
4912 pseudo_mode
= PSEUDO_REGNO_MODE (ORIGINAL_REGNO (loc
));
4913 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (pseudo_mode
))
4915 offset
+= byte_lowpart_offset (pseudo_mode
, mode
);
4920 /* If LOC is a paradoxical lowpart of EXPR, refer to EXPR itself.
4921 Do the same if we are storing to a register and EXPR occupies
4922 the whole of register LOC; in that case, the whole of EXPR is
4923 being changed. We exclude complex modes from the second case
4924 because the real and imaginary parts are represented as separate
4925 pseudo registers, even if the whole complex value fits into one
4927 if ((GET_MODE_SIZE (mode
) > GET_MODE_SIZE (DECL_MODE (expr
))
4929 && !COMPLEX_MODE_P (DECL_MODE (expr
))
4930 && hard_regno_nregs
[REGNO (loc
)][DECL_MODE (expr
)] == 1))
4931 && offset
+ byte_lowpart_offset (DECL_MODE (expr
), mode
) == 0)
4933 mode
= DECL_MODE (expr
);
4937 if (offset
< 0 || offset
>= MAX_VAR_PARTS
)
4943 *offset_out
= offset
;
4947 /* Return the MODE lowpart of LOC, or null if LOC is not something we
4948 want to track. When returning nonnull, make sure that the attributes
4949 on the returned value are updated. */
4952 var_lowpart (enum machine_mode mode
, rtx loc
)
4954 unsigned int offset
, reg_offset
, regno
;
4956 if (!REG_P (loc
) && !MEM_P (loc
))
4959 if (GET_MODE (loc
) == mode
)
4962 offset
= byte_lowpart_offset (mode
, GET_MODE (loc
));
4965 return adjust_address_nv (loc
, mode
, offset
);
4967 reg_offset
= subreg_lowpart_offset (mode
, GET_MODE (loc
));
4968 regno
= REGNO (loc
) + subreg_regno_offset (REGNO (loc
), GET_MODE (loc
),
4970 return gen_rtx_REG_offset (loc
, mode
, regno
, offset
);
4973 /* Carry information about uses and stores while walking rtx. */
4975 struct count_use_info
4977 /* The insn where the RTX is. */
4980 /* The basic block where insn is. */
4983 /* The array of n_sets sets in the insn, as determined by cselib. */
4984 struct cselib_set
*sets
;
4987 /* True if we're counting stores, false otherwise. */
4991 /* Find a VALUE corresponding to X. */
4993 static inline cselib_val
*
4994 find_use_val (rtx x
, enum machine_mode mode
, struct count_use_info
*cui
)
5000 /* This is called after uses are set up and before stores are
5001 processed by cselib, so it's safe to look up srcs, but not
5002 dsts. So we look up expressions that appear in srcs or in
5003 dest expressions, but we search the sets array for dests of
5007 /* Some targets represent memset and memcpy patterns
5008 by (set (mem:BLK ...) (reg:[QHSD]I ...)) or
5009 (set (mem:BLK ...) (const_int ...)) or
5010 (set (mem:BLK ...) (mem:BLK ...)). Don't return anything
5011 in that case, otherwise we end up with mode mismatches. */
5012 if (mode
== BLKmode
&& MEM_P (x
))
5014 for (i
= 0; i
< cui
->n_sets
; i
++)
5015 if (cui
->sets
[i
].dest
== x
)
5016 return cui
->sets
[i
].src_elt
;
5019 return cselib_lookup (x
, mode
, 0, VOIDmode
);
5025 /* Replace all registers and addresses in an expression with VALUE
5026 expressions that map back to them, unless the expression is a
5027 register. If no mapping is or can be performed, returns NULL. */
5030 replace_expr_with_values (rtx loc
)
5032 if (REG_P (loc
) || GET_CODE (loc
) == ENTRY_VALUE
)
5034 else if (MEM_P (loc
))
5036 cselib_val
*addr
= cselib_lookup (XEXP (loc
, 0),
5037 get_address_mode (loc
), 0,
5040 return replace_equiv_address_nv (loc
, addr
->val_rtx
);
5045 return cselib_subst_to_values (loc
, VOIDmode
);
5048 /* Return true if *X is a DEBUG_EXPR. Usable as an argument to
5049 for_each_rtx to tell whether there are any DEBUG_EXPRs within
5053 rtx_debug_expr_p (rtx
*x
, void *data ATTRIBUTE_UNUSED
)
5057 return GET_CODE (loc
) == DEBUG_EXPR
;
5060 /* Determine what kind of micro operation to choose for a USE. Return
5061 MO_CLOBBER if no micro operation is to be generated. */
5063 static enum micro_operation_type
5064 use_type (rtx loc
, struct count_use_info
*cui
, enum machine_mode
*modep
)
5068 if (cui
&& cui
->sets
)
5070 if (GET_CODE (loc
) == VAR_LOCATION
)
5072 if (track_expr_p (PAT_VAR_LOCATION_DECL (loc
), false))
5074 rtx ploc
= PAT_VAR_LOCATION_LOC (loc
);
5075 if (! VAR_LOC_UNKNOWN_P (ploc
))
5077 cselib_val
*val
= cselib_lookup (ploc
, GET_MODE (loc
), 1,
5080 /* ??? flag_float_store and volatile mems are never
5081 given values, but we could in theory use them for
5083 gcc_assert (val
|| 1);
5091 if (REG_P (loc
) || MEM_P (loc
))
5094 *modep
= GET_MODE (loc
);
5098 || (find_use_val (loc
, GET_MODE (loc
), cui
)
5099 && cselib_lookup (XEXP (loc
, 0),
5100 get_address_mode (loc
), 0,
5106 cselib_val
*val
= find_use_val (loc
, GET_MODE (loc
), cui
);
5108 if (val
&& !cselib_preserved_value_p (val
))
5116 gcc_assert (REGNO (loc
) < FIRST_PSEUDO_REGISTER
);
5118 if (loc
== cfa_base_rtx
)
5120 expr
= REG_EXPR (loc
);
5123 return MO_USE_NO_VAR
;
5124 else if (target_for_debug_bind (var_debug_decl (expr
)))
5126 else if (track_loc_p (loc
, expr
, REG_OFFSET (loc
),
5127 false, modep
, NULL
))
5130 return MO_USE_NO_VAR
;
5132 else if (MEM_P (loc
))
5134 expr
= MEM_EXPR (loc
);
5138 else if (target_for_debug_bind (var_debug_decl (expr
)))
5140 else if (track_loc_p (loc
, expr
, INT_MEM_OFFSET (loc
),
5142 /* Multi-part variables shouldn't refer to one-part
5143 variable names such as VALUEs (never happens) or
5144 DEBUG_EXPRs (only happens in the presence of debug
5146 && (!MAY_HAVE_DEBUG_INSNS
5147 || !for_each_rtx (&XEXP (loc
, 0), rtx_debug_expr_p
, NULL
)))
5156 /* Log to OUT information about micro-operation MOPT involving X in
5160 log_op_type (rtx x
, basic_block bb
, rtx insn
,
5161 enum micro_operation_type mopt
, FILE *out
)
5163 fprintf (out
, "bb %i op %i insn %i %s ",
5164 bb
->index
, VEC_length (micro_operation
, VTI (bb
)->mos
),
5165 INSN_UID (insn
), micro_operation_type_name
[mopt
]);
5166 print_inline_rtx (out
, x
, 2);
5170 /* Tell whether the CONCAT used to holds a VALUE and its location
5171 needs value resolution, i.e., an attempt of mapping the location
5172 back to other incoming values. */
5173 #define VAL_NEEDS_RESOLUTION(x) \
5174 (RTL_FLAG_CHECK1 ("VAL_NEEDS_RESOLUTION", (x), CONCAT)->volatil)
5175 /* Whether the location in the CONCAT is a tracked expression, that
5176 should also be handled like a MO_USE. */
5177 #define VAL_HOLDS_TRACK_EXPR(x) \
5178 (RTL_FLAG_CHECK1 ("VAL_HOLDS_TRACK_EXPR", (x), CONCAT)->used)
5179 /* Whether the location in the CONCAT should be handled like a MO_COPY
5181 #define VAL_EXPR_IS_COPIED(x) \
5182 (RTL_FLAG_CHECK1 ("VAL_EXPR_IS_COPIED", (x), CONCAT)->jump)
5183 /* Whether the location in the CONCAT should be handled like a
5184 MO_CLOBBER as well. */
5185 #define VAL_EXPR_IS_CLOBBERED(x) \
5186 (RTL_FLAG_CHECK1 ("VAL_EXPR_IS_CLOBBERED", (x), CONCAT)->unchanging)
5188 /* All preserved VALUEs. */
5189 static VEC (rtx
, heap
) *preserved_values
;
5191 /* Ensure VAL is preserved and remember it in a vector for vt_emit_notes. */
5194 preserve_value (cselib_val
*val
)
5196 cselib_preserve_value (val
);
5197 VEC_safe_push (rtx
, heap
, preserved_values
, val
->val_rtx
);
5200 /* Helper function for MO_VAL_LOC handling. Return non-zero if
5201 any rtxes not suitable for CONST use not replaced by VALUEs
5205 non_suitable_const (rtx
*x
, void *data ATTRIBUTE_UNUSED
)
5210 switch (GET_CODE (*x
))
5221 return !MEM_READONLY_P (*x
);
5227 /* Add uses (register and memory references) LOC which will be tracked
5228 to VTI (bb)->mos. INSN is instruction which the LOC is part of. */
5231 add_uses (rtx
*ploc
, void *data
)
5234 enum machine_mode mode
= VOIDmode
;
5235 struct count_use_info
*cui
= (struct count_use_info
*)data
;
5236 enum micro_operation_type type
= use_type (loc
, cui
, &mode
);
5238 if (type
!= MO_CLOBBER
)
5240 basic_block bb
= cui
->bb
;
5244 mo
.u
.loc
= type
== MO_USE
? var_lowpart (mode
, loc
) : loc
;
5245 mo
.insn
= cui
->insn
;
5247 if (type
== MO_VAL_LOC
)
5250 rtx vloc
= PAT_VAR_LOCATION_LOC (oloc
);
5253 gcc_assert (cui
->sets
);
5256 && !REG_P (XEXP (vloc
, 0))
5257 && !MEM_P (XEXP (vloc
, 0)))
5260 enum machine_mode address_mode
= get_address_mode (mloc
);
5262 = cselib_lookup (XEXP (mloc
, 0), address_mode
, 0,
5265 if (val
&& !cselib_preserved_value_p (val
))
5266 preserve_value (val
);
5269 if (CONSTANT_P (vloc
)
5270 && (GET_CODE (vloc
) != CONST
5271 || for_each_rtx (&vloc
, non_suitable_const
, NULL
)))
5272 /* For constants don't look up any value. */;
5273 else if (!VAR_LOC_UNKNOWN_P (vloc
) && !unsuitable_loc (vloc
)
5274 && (val
= find_use_val (vloc
, GET_MODE (oloc
), cui
)))
5276 enum machine_mode mode2
;
5277 enum micro_operation_type type2
;
5279 bool resolvable
= REG_P (vloc
) || MEM_P (vloc
);
5282 nloc
= replace_expr_with_values (vloc
);
5286 oloc
= shallow_copy_rtx (oloc
);
5287 PAT_VAR_LOCATION_LOC (oloc
) = nloc
;
5290 oloc
= gen_rtx_CONCAT (mode
, val
->val_rtx
, oloc
);
5292 type2
= use_type (vloc
, 0, &mode2
);
5294 gcc_assert (type2
== MO_USE
|| type2
== MO_USE_NO_VAR
5295 || type2
== MO_CLOBBER
);
5297 if (type2
== MO_CLOBBER
5298 && !cselib_preserved_value_p (val
))
5300 VAL_NEEDS_RESOLUTION (oloc
) = resolvable
;
5301 preserve_value (val
);
5304 else if (!VAR_LOC_UNKNOWN_P (vloc
))
5306 oloc
= shallow_copy_rtx (oloc
);
5307 PAT_VAR_LOCATION_LOC (oloc
) = gen_rtx_UNKNOWN_VAR_LOC ();
5312 else if (type
== MO_VAL_USE
)
5314 enum machine_mode mode2
= VOIDmode
;
5315 enum micro_operation_type type2
;
5316 cselib_val
*val
= find_use_val (loc
, GET_MODE (loc
), cui
);
5317 rtx vloc
, oloc
= loc
, nloc
;
5319 gcc_assert (cui
->sets
);
5322 && !REG_P (XEXP (oloc
, 0))
5323 && !MEM_P (XEXP (oloc
, 0)))
5326 enum machine_mode address_mode
= get_address_mode (mloc
);
5328 = cselib_lookup (XEXP (mloc
, 0), address_mode
, 0,
5331 if (val
&& !cselib_preserved_value_p (val
))
5332 preserve_value (val
);
5335 type2
= use_type (loc
, 0, &mode2
);
5337 gcc_assert (type2
== MO_USE
|| type2
== MO_USE_NO_VAR
5338 || type2
== MO_CLOBBER
);
5340 if (type2
== MO_USE
)
5341 vloc
= var_lowpart (mode2
, loc
);
5345 /* The loc of a MO_VAL_USE may have two forms:
5347 (concat val src): val is at src, a value-based
5350 (concat (concat val use) src): same as above, with use as
5351 the MO_USE tracked value, if it differs from src.
5355 gcc_checking_assert (REG_P (loc
) || MEM_P (loc
));
5356 nloc
= replace_expr_with_values (loc
);
5361 oloc
= gen_rtx_CONCAT (mode2
, val
->val_rtx
, vloc
);
5363 oloc
= val
->val_rtx
;
5365 mo
.u
.loc
= gen_rtx_CONCAT (mode
, oloc
, nloc
);
5367 if (type2
== MO_USE
)
5368 VAL_HOLDS_TRACK_EXPR (mo
.u
.loc
) = 1;
5369 if (!cselib_preserved_value_p (val
))
5371 VAL_NEEDS_RESOLUTION (mo
.u
.loc
) = 1;
5372 preserve_value (val
);
5376 gcc_assert (type
== MO_USE
|| type
== MO_USE_NO_VAR
);
5378 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
5379 log_op_type (mo
.u
.loc
, cui
->bb
, cui
->insn
, mo
.type
, dump_file
);
5380 VEC_safe_push (micro_operation
, heap
, VTI (bb
)->mos
, &mo
);
5386 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
5389 add_uses_1 (rtx
*x
, void *cui
)
5391 for_each_rtx (x
, add_uses
, cui
);
5394 /* This is the value used during expansion of locations. We want it
5395 to be unbounded, so that variables expanded deep in a recursion
5396 nest are fully evaluated, so that their values are cached
5397 correctly. We avoid recursion cycles through other means, and we
5398 don't unshare RTL, so excess complexity is not a problem. */
5399 #define EXPR_DEPTH (INT_MAX)
5400 /* We use this to keep too-complex expressions from being emitted as
5401 location notes, and then to debug information. Users can trade
5402 compile time for ridiculously complex expressions, although they're
5403 seldom useful, and they may often have to be discarded as not
5404 representable anyway. */
5405 #define EXPR_USE_DEPTH (PARAM_VALUE (PARAM_MAX_VARTRACK_EXPR_DEPTH))
5407 /* Attempt to reverse the EXPR operation in the debug info and record
5408 it in the cselib table. Say for reg1 = reg2 + 6 even when reg2 is
5409 no longer live we can express its value as VAL - 6. */
5412 reverse_op (rtx val
, const_rtx expr
, rtx insn
)
5416 struct elt_loc_list
*l
;
5419 if (GET_CODE (expr
) != SET
)
5422 if (!REG_P (SET_DEST (expr
)) || GET_MODE (val
) != GET_MODE (SET_DEST (expr
)))
5425 src
= SET_SRC (expr
);
5426 switch (GET_CODE (src
))
5433 if (!REG_P (XEXP (src
, 0)))
5438 if (!REG_P (XEXP (src
, 0)) && !MEM_P (XEXP (src
, 0)))
5445 if (!SCALAR_INT_MODE_P (GET_MODE (src
)) || XEXP (src
, 0) == cfa_base_rtx
)
5448 v
= cselib_lookup (XEXP (src
, 0), GET_MODE (XEXP (src
, 0)), 0, VOIDmode
);
5449 if (!v
|| !cselib_preserved_value_p (v
))
5452 /* Use canonical V to avoid creating multiple redundant expressions
5453 for different VALUES equivalent to V. */
5454 v
= canonical_cselib_val (v
);
5456 /* Adding a reverse op isn't useful if V already has an always valid
5457 location. Ignore ENTRY_VALUE, while it is always constant, we should
5458 prefer non-ENTRY_VALUE locations whenever possible. */
5459 for (l
= v
->locs
; l
; l
= l
->next
)
5460 if (CONSTANT_P (l
->loc
)
5461 && (GET_CODE (l
->loc
) != CONST
|| !references_value_p (l
->loc
, 0)))
5464 switch (GET_CODE (src
))
5468 if (GET_MODE (v
->val_rtx
) != GET_MODE (val
))
5470 ret
= gen_rtx_fmt_e (GET_CODE (src
), GET_MODE (val
), val
);
5474 ret
= gen_lowpart_SUBREG (GET_MODE (v
->val_rtx
), val
);
5486 if (GET_MODE (v
->val_rtx
) != GET_MODE (val
))
5488 arg
= XEXP (src
, 1);
5489 if (!CONST_INT_P (arg
) && GET_CODE (arg
) != SYMBOL_REF
)
5491 arg
= cselib_expand_value_rtx (arg
, scratch_regs
, 5);
5492 if (arg
== NULL_RTX
)
5494 if (!CONST_INT_P (arg
) && GET_CODE (arg
) != SYMBOL_REF
)
5497 ret
= simplify_gen_binary (code
, GET_MODE (val
), val
, arg
);
5499 /* Ensure ret isn't VALUE itself (which can happen e.g. for
5500 (plus (reg1) (reg2)) when reg2 is known to be 0), as that
5501 breaks a lot of routines during var-tracking. */
5502 ret
= gen_rtx_fmt_ee (PLUS
, GET_MODE (val
), val
, const0_rtx
);
5508 cselib_add_permanent_equiv (v
, ret
, insn
);
5511 /* Add stores (register and memory references) LOC which will be tracked
5512 to VTI (bb)->mos. EXPR is the RTL expression containing the store.
5513 CUIP->insn is instruction which the LOC is part of. */
5516 add_stores (rtx loc
, const_rtx expr
, void *cuip
)
5518 enum machine_mode mode
= VOIDmode
, mode2
;
5519 struct count_use_info
*cui
= (struct count_use_info
*)cuip
;
5520 basic_block bb
= cui
->bb
;
5522 rtx oloc
= loc
, nloc
, src
= NULL
;
5523 enum micro_operation_type type
= use_type (loc
, cui
, &mode
);
5524 bool track_p
= false;
5526 bool resolve
, preserve
;
5528 if (type
== MO_CLOBBER
)
5535 gcc_assert (loc
!= cfa_base_rtx
);
5536 if ((GET_CODE (expr
) == CLOBBER
&& type
!= MO_VAL_SET
)
5537 || !(track_p
= use_type (loc
, NULL
, &mode2
) == MO_USE
)
5538 || GET_CODE (expr
) == CLOBBER
)
5540 mo
.type
= MO_CLOBBER
;
5542 if (GET_CODE (expr
) == SET
5543 && SET_DEST (expr
) == loc
5544 && !unsuitable_loc (SET_SRC (expr
))
5545 && find_use_val (loc
, mode
, cui
))
5547 gcc_checking_assert (type
== MO_VAL_SET
);
5548 mo
.u
.loc
= gen_rtx_SET (VOIDmode
, loc
, SET_SRC (expr
));
5553 if (GET_CODE (expr
) == SET
5554 && SET_DEST (expr
) == loc
5555 && GET_CODE (SET_SRC (expr
)) != ASM_OPERANDS
)
5556 src
= var_lowpart (mode2
, SET_SRC (expr
));
5557 loc
= var_lowpart (mode2
, loc
);
5566 rtx xexpr
= gen_rtx_SET (VOIDmode
, loc
, src
);
5567 if (same_variable_part_p (src
, REG_EXPR (loc
), REG_OFFSET (loc
)))
5574 mo
.insn
= cui
->insn
;
5576 else if (MEM_P (loc
)
5577 && ((track_p
= use_type (loc
, NULL
, &mode2
) == MO_USE
)
5580 if (MEM_P (loc
) && type
== MO_VAL_SET
5581 && !REG_P (XEXP (loc
, 0))
5582 && !MEM_P (XEXP (loc
, 0)))
5585 enum machine_mode address_mode
= get_address_mode (mloc
);
5586 cselib_val
*val
= cselib_lookup (XEXP (mloc
, 0),
5590 if (val
&& !cselib_preserved_value_p (val
))
5591 preserve_value (val
);
5594 if (GET_CODE (expr
) == CLOBBER
|| !track_p
)
5596 mo
.type
= MO_CLOBBER
;
5597 mo
.u
.loc
= track_p
? var_lowpart (mode2
, loc
) : loc
;
5601 if (GET_CODE (expr
) == SET
5602 && SET_DEST (expr
) == loc
5603 && GET_CODE (SET_SRC (expr
)) != ASM_OPERANDS
)
5604 src
= var_lowpart (mode2
, SET_SRC (expr
));
5605 loc
= var_lowpart (mode2
, loc
);
5614 rtx xexpr
= gen_rtx_SET (VOIDmode
, loc
, src
);
5615 if (same_variable_part_p (SET_SRC (xexpr
),
5617 INT_MEM_OFFSET (loc
)))
5624 mo
.insn
= cui
->insn
;
5629 if (type
!= MO_VAL_SET
)
5630 goto log_and_return
;
5632 v
= find_use_val (oloc
, mode
, cui
);
5635 goto log_and_return
;
5637 resolve
= preserve
= !cselib_preserved_value_p (v
);
5639 nloc
= replace_expr_with_values (oloc
);
5643 if (GET_CODE (PATTERN (cui
->insn
)) == COND_EXEC
)
5645 cselib_val
*oval
= cselib_lookup (oloc
, GET_MODE (oloc
), 0, VOIDmode
);
5647 gcc_assert (oval
!= v
);
5648 gcc_assert (REG_P (oloc
) || MEM_P (oloc
));
5650 if (oval
&& !cselib_preserved_value_p (oval
))
5652 micro_operation moa
;
5654 preserve_value (oval
);
5656 moa
.type
= MO_VAL_USE
;
5657 moa
.u
.loc
= gen_rtx_CONCAT (mode
, oval
->val_rtx
, oloc
);
5658 VAL_NEEDS_RESOLUTION (moa
.u
.loc
) = 1;
5659 moa
.insn
= cui
->insn
;
5661 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
5662 log_op_type (moa
.u
.loc
, cui
->bb
, cui
->insn
,
5663 moa
.type
, dump_file
);
5664 VEC_safe_push (micro_operation
, heap
, VTI (bb
)->mos
, &moa
);
5669 else if (resolve
&& GET_CODE (mo
.u
.loc
) == SET
)
5671 if (REG_P (SET_SRC (expr
)) || MEM_P (SET_SRC (expr
)))
5672 nloc
= replace_expr_with_values (SET_SRC (expr
));
5676 /* Avoid the mode mismatch between oexpr and expr. */
5677 if (!nloc
&& mode
!= mode2
)
5679 nloc
= SET_SRC (expr
);
5680 gcc_assert (oloc
== SET_DEST (expr
));
5683 if (nloc
&& nloc
!= SET_SRC (mo
.u
.loc
))
5684 oloc
= gen_rtx_SET (GET_MODE (mo
.u
.loc
), oloc
, nloc
);
5687 if (oloc
== SET_DEST (mo
.u
.loc
))
5688 /* No point in duplicating. */
5690 if (!REG_P (SET_SRC (mo
.u
.loc
)))
5696 if (GET_CODE (mo
.u
.loc
) == SET
5697 && oloc
== SET_DEST (mo
.u
.loc
))
5698 /* No point in duplicating. */
5704 loc
= gen_rtx_CONCAT (mode
, v
->val_rtx
, oloc
);
5706 if (mo
.u
.loc
!= oloc
)
5707 loc
= gen_rtx_CONCAT (GET_MODE (mo
.u
.loc
), loc
, mo
.u
.loc
);
5709 /* The loc of a MO_VAL_SET may have various forms:
5711 (concat val dst): dst now holds val
5713 (concat val (set dst src)): dst now holds val, copied from src
5715 (concat (concat val dstv) dst): dst now holds val; dstv is dst
5716 after replacing mems and non-top-level regs with values.
5718 (concat (concat val dstv) (set dst src)): dst now holds val,
5719 copied from src. dstv is a value-based representation of dst, if
5720 it differs from dst. If resolution is needed, src is a REG, and
5721 its mode is the same as that of val.
5723 (concat (concat val (set dstv srcv)) (set dst src)): src
5724 copied to dst, holding val. dstv and srcv are value-based
5725 representations of dst and src, respectively.
5729 if (GET_CODE (PATTERN (cui
->insn
)) != COND_EXEC
)
5730 reverse_op (v
->val_rtx
, expr
, cui
->insn
);
5735 VAL_HOLDS_TRACK_EXPR (loc
) = 1;
5738 VAL_NEEDS_RESOLUTION (loc
) = resolve
;
5741 if (mo
.type
== MO_CLOBBER
)
5742 VAL_EXPR_IS_CLOBBERED (loc
) = 1;
5743 if (mo
.type
== MO_COPY
)
5744 VAL_EXPR_IS_COPIED (loc
) = 1;
5746 mo
.type
= MO_VAL_SET
;
5749 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
5750 log_op_type (mo
.u
.loc
, cui
->bb
, cui
->insn
, mo
.type
, dump_file
);
5751 VEC_safe_push (micro_operation
, heap
, VTI (bb
)->mos
, &mo
);
5754 /* Arguments to the call. */
5755 static rtx call_arguments
;
5757 /* Compute call_arguments. */
5760 prepare_call_arguments (basic_block bb
, rtx insn
)
5763 rtx prev
, cur
, next
;
5764 rtx call
= PATTERN (insn
);
5765 rtx this_arg
= NULL_RTX
;
5766 tree type
= NULL_TREE
, t
, fndecl
= NULL_TREE
;
5767 tree obj_type_ref
= NULL_TREE
;
5768 CUMULATIVE_ARGS args_so_far_v
;
5769 cumulative_args_t args_so_far
;
5771 memset (&args_so_far_v
, 0, sizeof (args_so_far_v
));
5772 args_so_far
= pack_cumulative_args (&args_so_far_v
);
5773 if (GET_CODE (call
) == PARALLEL
)
5774 call
= XVECEXP (call
, 0, 0);
5775 if (GET_CODE (call
) == SET
)
5776 call
= SET_SRC (call
);
5777 if (GET_CODE (call
) == CALL
&& MEM_P (XEXP (call
, 0)))
5779 if (GET_CODE (XEXP (XEXP (call
, 0), 0)) == SYMBOL_REF
)
5781 rtx symbol
= XEXP (XEXP (call
, 0), 0);
5782 if (SYMBOL_REF_DECL (symbol
))
5783 fndecl
= SYMBOL_REF_DECL (symbol
);
5785 if (fndecl
== NULL_TREE
)
5786 fndecl
= MEM_EXPR (XEXP (call
, 0));
5788 && TREE_CODE (TREE_TYPE (fndecl
)) != FUNCTION_TYPE
5789 && TREE_CODE (TREE_TYPE (fndecl
)) != METHOD_TYPE
)
5791 if (fndecl
&& TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
5792 type
= TREE_TYPE (fndecl
);
5793 if (fndecl
&& TREE_CODE (fndecl
) != FUNCTION_DECL
)
5795 if (TREE_CODE (fndecl
) == INDIRECT_REF
5796 && TREE_CODE (TREE_OPERAND (fndecl
, 0)) == OBJ_TYPE_REF
)
5797 obj_type_ref
= TREE_OPERAND (fndecl
, 0);
5802 for (t
= TYPE_ARG_TYPES (type
); t
&& t
!= void_list_node
;
5804 if (TREE_CODE (TREE_VALUE (t
)) == REFERENCE_TYPE
5805 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_VALUE (t
))))
5807 if ((t
== NULL
|| t
== void_list_node
) && obj_type_ref
== NULL_TREE
)
5811 int nargs ATTRIBUTE_UNUSED
= list_length (TYPE_ARG_TYPES (type
));
5812 link
= CALL_INSN_FUNCTION_USAGE (insn
);
5813 #ifndef PCC_STATIC_STRUCT_RETURN
5814 if (aggregate_value_p (TREE_TYPE (type
), type
)
5815 && targetm
.calls
.struct_value_rtx (type
, 0) == 0)
5817 tree struct_addr
= build_pointer_type (TREE_TYPE (type
));
5818 enum machine_mode mode
= TYPE_MODE (struct_addr
);
5820 INIT_CUMULATIVE_ARGS (args_so_far_v
, type
, NULL_RTX
, fndecl
,
5822 reg
= targetm
.calls
.function_arg (args_so_far
, mode
,
5824 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
5826 if (reg
== NULL_RTX
)
5828 for (; link
; link
= XEXP (link
, 1))
5829 if (GET_CODE (XEXP (link
, 0)) == USE
5830 && MEM_P (XEXP (XEXP (link
, 0), 0)))
5832 link
= XEXP (link
, 1);
5839 INIT_CUMULATIVE_ARGS (args_so_far_v
, type
, NULL_RTX
, fndecl
,
5841 if (obj_type_ref
&& TYPE_ARG_TYPES (type
) != void_list_node
)
5843 enum machine_mode mode
;
5844 t
= TYPE_ARG_TYPES (type
);
5845 mode
= TYPE_MODE (TREE_VALUE (t
));
5846 this_arg
= targetm
.calls
.function_arg (args_so_far
, mode
,
5847 TREE_VALUE (t
), true);
5848 if (this_arg
&& !REG_P (this_arg
))
5849 this_arg
= NULL_RTX
;
5850 else if (this_arg
== NULL_RTX
)
5852 for (; link
; link
= XEXP (link
, 1))
5853 if (GET_CODE (XEXP (link
, 0)) == USE
5854 && MEM_P (XEXP (XEXP (link
, 0), 0)))
5856 this_arg
= XEXP (XEXP (link
, 0), 0);
5864 t
= type
? TYPE_ARG_TYPES (type
) : NULL_TREE
;
5866 for (link
= CALL_INSN_FUNCTION_USAGE (insn
); link
; link
= XEXP (link
, 1))
5867 if (GET_CODE (XEXP (link
, 0)) == USE
)
5869 rtx item
= NULL_RTX
;
5870 x
= XEXP (XEXP (link
, 0), 0);
5871 if (GET_MODE (link
) == VOIDmode
5872 || GET_MODE (link
) == BLKmode
5873 || (GET_MODE (link
) != GET_MODE (x
)
5874 && (GET_MODE_CLASS (GET_MODE (link
)) != MODE_INT
5875 || GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
)))
5876 /* Can't do anything for these, if the original type mode
5877 isn't known or can't be converted. */;
5880 cselib_val
*val
= cselib_lookup (x
, GET_MODE (x
), 0, VOIDmode
);
5881 if (val
&& cselib_preserved_value_p (val
))
5882 item
= val
->val_rtx
;
5883 else if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_INT
)
5885 enum machine_mode mode
= GET_MODE (x
);
5887 while ((mode
= GET_MODE_WIDER_MODE (mode
)) != VOIDmode
5888 && GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
5890 rtx reg
= simplify_subreg (mode
, x
, GET_MODE (x
), 0);
5892 if (reg
== NULL_RTX
|| !REG_P (reg
))
5894 val
= cselib_lookup (reg
, mode
, 0, VOIDmode
);
5895 if (val
&& cselib_preserved_value_p (val
))
5897 item
= val
->val_rtx
;
5908 if (!frame_pointer_needed
)
5910 struct adjust_mem_data amd
;
5911 amd
.mem_mode
= VOIDmode
;
5912 amd
.stack_adjust
= -VTI (bb
)->out
.stack_adjust
;
5913 amd
.side_effects
= NULL_RTX
;
5915 mem
= simplify_replace_fn_rtx (mem
, NULL_RTX
, adjust_mems
,
5917 gcc_assert (amd
.side_effects
== NULL_RTX
);
5919 val
= cselib_lookup (mem
, GET_MODE (mem
), 0, VOIDmode
);
5920 if (val
&& cselib_preserved_value_p (val
))
5921 item
= val
->val_rtx
;
5922 else if (GET_MODE_CLASS (GET_MODE (mem
)) != MODE_INT
)
5924 /* For non-integer stack argument see also if they weren't
5925 initialized by integers. */
5926 enum machine_mode imode
= int_mode_for_mode (GET_MODE (mem
));
5927 if (imode
!= GET_MODE (mem
) && imode
!= BLKmode
)
5929 val
= cselib_lookup (adjust_address_nv (mem
, imode
, 0),
5930 imode
, 0, VOIDmode
);
5931 if (val
&& cselib_preserved_value_p (val
))
5932 item
= lowpart_subreg (GET_MODE (x
), val
->val_rtx
,
5940 if (GET_MODE (item
) != GET_MODE (link
))
5941 item
= lowpart_subreg (GET_MODE (link
), item
, GET_MODE (item
));
5942 if (GET_MODE (x2
) != GET_MODE (link
))
5943 x2
= lowpart_subreg (GET_MODE (link
), x2
, GET_MODE (x2
));
5944 item
= gen_rtx_CONCAT (GET_MODE (link
), x2
, item
);
5946 = gen_rtx_EXPR_LIST (VOIDmode
, item
, call_arguments
);
5948 if (t
&& t
!= void_list_node
)
5950 tree argtype
= TREE_VALUE (t
);
5951 enum machine_mode mode
= TYPE_MODE (argtype
);
5953 if (pass_by_reference (&args_so_far_v
, mode
, argtype
, true))
5955 argtype
= build_pointer_type (argtype
);
5956 mode
= TYPE_MODE (argtype
);
5958 reg
= targetm
.calls
.function_arg (args_so_far
, mode
,
5960 if (TREE_CODE (argtype
) == REFERENCE_TYPE
5961 && INTEGRAL_TYPE_P (TREE_TYPE (argtype
))
5964 && GET_MODE (reg
) == mode
5965 && GET_MODE_CLASS (mode
) == MODE_INT
5967 && REGNO (x
) == REGNO (reg
)
5968 && GET_MODE (x
) == mode
5971 enum machine_mode indmode
5972 = TYPE_MODE (TREE_TYPE (argtype
));
5973 rtx mem
= gen_rtx_MEM (indmode
, x
);
5974 cselib_val
*val
= cselib_lookup (mem
, indmode
, 0, VOIDmode
);
5975 if (val
&& cselib_preserved_value_p (val
))
5977 item
= gen_rtx_CONCAT (indmode
, mem
, val
->val_rtx
);
5978 call_arguments
= gen_rtx_EXPR_LIST (VOIDmode
, item
,
5983 struct elt_loc_list
*l
;
5986 /* Try harder, when passing address of a constant
5987 pool integer it can be easily read back. */
5988 item
= XEXP (item
, 1);
5989 if (GET_CODE (item
) == SUBREG
)
5990 item
= SUBREG_REG (item
);
5991 gcc_assert (GET_CODE (item
) == VALUE
);
5992 val
= CSELIB_VAL_PTR (item
);
5993 for (l
= val
->locs
; l
; l
= l
->next
)
5994 if (GET_CODE (l
->loc
) == SYMBOL_REF
5995 && TREE_CONSTANT_POOL_ADDRESS_P (l
->loc
)
5996 && SYMBOL_REF_DECL (l
->loc
)
5997 && DECL_INITIAL (SYMBOL_REF_DECL (l
->loc
)))
5999 initial
= DECL_INITIAL (SYMBOL_REF_DECL (l
->loc
));
6000 if (host_integerp (initial
, 0))
6002 item
= GEN_INT (tree_low_cst (initial
, 0));
6003 item
= gen_rtx_CONCAT (indmode
, mem
, item
);
6005 = gen_rtx_EXPR_LIST (VOIDmode
, item
,
6012 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
6018 /* Add debug arguments. */
6020 && TREE_CODE (fndecl
) == FUNCTION_DECL
6021 && DECL_HAS_DEBUG_ARGS_P (fndecl
))
6023 VEC(tree
, gc
) **debug_args
= decl_debug_args_lookup (fndecl
);
6028 for (ix
= 0; VEC_iterate (tree
, *debug_args
, ix
, param
); ix
+= 2)
6031 tree dtemp
= VEC_index (tree
, *debug_args
, ix
+ 1);
6032 enum machine_mode mode
= DECL_MODE (dtemp
);
6033 item
= gen_rtx_DEBUG_PARAMETER_REF (mode
, param
);
6034 item
= gen_rtx_CONCAT (mode
, item
, DECL_RTL_KNOWN_SET (dtemp
));
6035 call_arguments
= gen_rtx_EXPR_LIST (VOIDmode
, item
,
6041 /* Reverse call_arguments chain. */
6043 for (cur
= call_arguments
; cur
; cur
= next
)
6045 next
= XEXP (cur
, 1);
6046 XEXP (cur
, 1) = prev
;
6049 call_arguments
= prev
;
6052 if (GET_CODE (x
) == PARALLEL
)
6053 x
= XVECEXP (x
, 0, 0);
6054 if (GET_CODE (x
) == SET
)
6056 if (GET_CODE (x
) == CALL
&& MEM_P (XEXP (x
, 0)))
6058 x
= XEXP (XEXP (x
, 0), 0);
6059 if (GET_CODE (x
) == SYMBOL_REF
)
6060 /* Don't record anything. */;
6061 else if (CONSTANT_P (x
))
6063 x
= gen_rtx_CONCAT (GET_MODE (x
) == VOIDmode
? Pmode
: GET_MODE (x
),
6066 = gen_rtx_EXPR_LIST (VOIDmode
, x
, call_arguments
);
6070 cselib_val
*val
= cselib_lookup (x
, GET_MODE (x
), 0, VOIDmode
);
6071 if (val
&& cselib_preserved_value_p (val
))
6073 x
= gen_rtx_CONCAT (GET_MODE (x
), pc_rtx
, val
->val_rtx
);
6075 = gen_rtx_EXPR_LIST (VOIDmode
, x
, call_arguments
);
6081 enum machine_mode mode
6082 = TYPE_MODE (TREE_TYPE (OBJ_TYPE_REF_EXPR (obj_type_ref
)));
6083 rtx clobbered
= gen_rtx_MEM (mode
, this_arg
);
6085 = tree_low_cst (OBJ_TYPE_REF_TOKEN (obj_type_ref
), 0);
6087 clobbered
= plus_constant (mode
, clobbered
,
6088 token
* GET_MODE_SIZE (mode
));
6089 clobbered
= gen_rtx_MEM (mode
, clobbered
);
6090 x
= gen_rtx_CONCAT (mode
, gen_rtx_CLOBBER (VOIDmode
, pc_rtx
), clobbered
);
6092 = gen_rtx_EXPR_LIST (VOIDmode
, x
, call_arguments
);
6096 /* Callback for cselib_record_sets_hook, that records as micro
6097 operations uses and stores in an insn after cselib_record_sets has
6098 analyzed the sets in an insn, but before it modifies the stored
6099 values in the internal tables, unless cselib_record_sets doesn't
6100 call it directly (perhaps because we're not doing cselib in the
6101 first place, in which case sets and n_sets will be 0). */
6104 add_with_sets (rtx insn
, struct cselib_set
*sets
, int n_sets
)
6106 basic_block bb
= BLOCK_FOR_INSN (insn
);
6108 struct count_use_info cui
;
6109 micro_operation
*mos
;
6111 cselib_hook_called
= true;
6116 cui
.n_sets
= n_sets
;
6118 n1
= VEC_length (micro_operation
, VTI (bb
)->mos
);
6119 cui
.store_p
= false;
6120 note_uses (&PATTERN (insn
), add_uses_1
, &cui
);
6121 n2
= VEC_length (micro_operation
, VTI (bb
)->mos
) - 1;
6122 mos
= VEC_address (micro_operation
, VTI (bb
)->mos
);
6124 /* Order the MO_USEs to be before MO_USE_NO_VARs and MO_VAL_USE, and
6128 while (n1
< n2
&& mos
[n1
].type
== MO_USE
)
6130 while (n1
< n2
&& mos
[n2
].type
!= MO_USE
)
6142 n2
= VEC_length (micro_operation
, VTI (bb
)->mos
) - 1;
6145 while (n1
< n2
&& mos
[n1
].type
!= MO_VAL_LOC
)
6147 while (n1
< n2
&& mos
[n2
].type
== MO_VAL_LOC
)
6165 mo
.u
.loc
= call_arguments
;
6166 call_arguments
= NULL_RTX
;
6168 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
6169 log_op_type (PATTERN (insn
), bb
, insn
, mo
.type
, dump_file
);
6170 VEC_safe_push (micro_operation
, heap
, VTI (bb
)->mos
, &mo
);
6173 n1
= VEC_length (micro_operation
, VTI (bb
)->mos
);
6174 /* This will record NEXT_INSN (insn), such that we can
6175 insert notes before it without worrying about any
6176 notes that MO_USEs might emit after the insn. */
6178 note_stores (PATTERN (insn
), add_stores
, &cui
);
6179 n2
= VEC_length (micro_operation
, VTI (bb
)->mos
) - 1;
6180 mos
= VEC_address (micro_operation
, VTI (bb
)->mos
);
6182 /* Order the MO_VAL_USEs first (note_stores does nothing
6183 on DEBUG_INSNs, so there are no MO_VAL_LOCs from this
6184 insn), then MO_CLOBBERs, then MO_SET/MO_COPY/MO_VAL_SET. */
6187 while (n1
< n2
&& mos
[n1
].type
== MO_VAL_USE
)
6189 while (n1
< n2
&& mos
[n2
].type
!= MO_VAL_USE
)
6201 n2
= VEC_length (micro_operation
, VTI (bb
)->mos
) - 1;
6204 while (n1
< n2
&& mos
[n1
].type
== MO_CLOBBER
)
6206 while (n1
< n2
&& mos
[n2
].type
!= MO_CLOBBER
)
6219 static enum var_init_status
6220 find_src_status (dataflow_set
*in
, rtx src
)
6222 tree decl
= NULL_TREE
;
6223 enum var_init_status status
= VAR_INIT_STATUS_UNINITIALIZED
;
6225 if (! flag_var_tracking_uninit
)
6226 status
= VAR_INIT_STATUS_INITIALIZED
;
6228 if (src
&& REG_P (src
))
6229 decl
= var_debug_decl (REG_EXPR (src
));
6230 else if (src
&& MEM_P (src
))
6231 decl
= var_debug_decl (MEM_EXPR (src
));
6234 status
= get_init_value (in
, src
, dv_from_decl (decl
));
6239 /* SRC is the source of an assignment. Use SET to try to find what
6240 was ultimately assigned to SRC. Return that value if known,
6241 otherwise return SRC itself. */
6244 find_src_set_src (dataflow_set
*set
, rtx src
)
6246 tree decl
= NULL_TREE
; /* The variable being copied around. */
6247 rtx set_src
= NULL_RTX
; /* The value for "decl" stored in "src". */
6249 location_chain nextp
;
6253 if (src
&& REG_P (src
))
6254 decl
= var_debug_decl (REG_EXPR (src
));
6255 else if (src
&& MEM_P (src
))
6256 decl
= var_debug_decl (MEM_EXPR (src
));
6260 decl_or_value dv
= dv_from_decl (decl
);
6262 var
= shared_hash_find (set
->vars
, dv
);
6266 for (i
= 0; i
< var
->n_var_parts
&& !found
; i
++)
6267 for (nextp
= var
->var_part
[i
].loc_chain
; nextp
&& !found
;
6268 nextp
= nextp
->next
)
6269 if (rtx_equal_p (nextp
->loc
, src
))
6271 set_src
= nextp
->set_src
;
6281 /* Compute the changes of variable locations in the basic block BB. */
6284 compute_bb_dataflow (basic_block bb
)
6287 micro_operation
*mo
;
6289 dataflow_set old_out
;
6290 dataflow_set
*in
= &VTI (bb
)->in
;
6291 dataflow_set
*out
= &VTI (bb
)->out
;
6293 dataflow_set_init (&old_out
);
6294 dataflow_set_copy (&old_out
, out
);
6295 dataflow_set_copy (out
, in
);
6297 FOR_EACH_VEC_ELT (micro_operation
, VTI (bb
)->mos
, i
, mo
)
6299 rtx insn
= mo
->insn
;
6304 dataflow_set_clear_at_call (out
);
6309 rtx loc
= mo
->u
.loc
;
6312 var_reg_set (out
, loc
, VAR_INIT_STATUS_UNINITIALIZED
, NULL
);
6313 else if (MEM_P (loc
))
6314 var_mem_set (out
, loc
, VAR_INIT_STATUS_UNINITIALIZED
, NULL
);
6320 rtx loc
= mo
->u
.loc
;
6324 if (GET_CODE (loc
) == CONCAT
)
6326 val
= XEXP (loc
, 0);
6327 vloc
= XEXP (loc
, 1);
6335 var
= PAT_VAR_LOCATION_DECL (vloc
);
6337 clobber_variable_part (out
, NULL_RTX
,
6338 dv_from_decl (var
), 0, NULL_RTX
);
6341 if (VAL_NEEDS_RESOLUTION (loc
))
6342 val_resolve (out
, val
, PAT_VAR_LOCATION_LOC (vloc
), insn
);
6343 set_variable_part (out
, val
, dv_from_decl (var
), 0,
6344 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
,
6347 else if (!VAR_LOC_UNKNOWN_P (PAT_VAR_LOCATION_LOC (vloc
)))
6348 set_variable_part (out
, PAT_VAR_LOCATION_LOC (vloc
),
6349 dv_from_decl (var
), 0,
6350 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
,
6357 rtx loc
= mo
->u
.loc
;
6358 rtx val
, vloc
, uloc
;
6360 vloc
= uloc
= XEXP (loc
, 1);
6361 val
= XEXP (loc
, 0);
6363 if (GET_CODE (val
) == CONCAT
)
6365 uloc
= XEXP (val
, 1);
6366 val
= XEXP (val
, 0);
6369 if (VAL_NEEDS_RESOLUTION (loc
))
6370 val_resolve (out
, val
, vloc
, insn
);
6372 val_store (out
, val
, uloc
, insn
, false);
6374 if (VAL_HOLDS_TRACK_EXPR (loc
))
6376 if (GET_CODE (uloc
) == REG
)
6377 var_reg_set (out
, uloc
, VAR_INIT_STATUS_UNINITIALIZED
,
6379 else if (GET_CODE (uloc
) == MEM
)
6380 var_mem_set (out
, uloc
, VAR_INIT_STATUS_UNINITIALIZED
,
6388 rtx loc
= mo
->u
.loc
;
6389 rtx val
, vloc
, uloc
;
6393 uloc
= XEXP (vloc
, 1);
6394 val
= XEXP (vloc
, 0);
6397 if (GET_CODE (uloc
) == SET
)
6399 dstv
= SET_DEST (uloc
);
6400 srcv
= SET_SRC (uloc
);
6408 if (GET_CODE (val
) == CONCAT
)
6410 dstv
= vloc
= XEXP (val
, 1);
6411 val
= XEXP (val
, 0);
6414 if (GET_CODE (vloc
) == SET
)
6416 srcv
= SET_SRC (vloc
);
6418 gcc_assert (val
!= srcv
);
6419 gcc_assert (vloc
== uloc
|| VAL_NEEDS_RESOLUTION (loc
));
6421 dstv
= vloc
= SET_DEST (vloc
);
6423 if (VAL_NEEDS_RESOLUTION (loc
))
6424 val_resolve (out
, val
, srcv
, insn
);
6426 else if (VAL_NEEDS_RESOLUTION (loc
))
6428 gcc_assert (GET_CODE (uloc
) == SET
6429 && GET_CODE (SET_SRC (uloc
)) == REG
);
6430 val_resolve (out
, val
, SET_SRC (uloc
), insn
);
6433 if (VAL_HOLDS_TRACK_EXPR (loc
))
6435 if (VAL_EXPR_IS_CLOBBERED (loc
))
6438 var_reg_delete (out
, uloc
, true);
6439 else if (MEM_P (uloc
))
6441 gcc_assert (MEM_P (dstv
));
6442 gcc_assert (MEM_ATTRS (dstv
) == MEM_ATTRS (uloc
));
6443 var_mem_delete (out
, dstv
, true);
6448 bool copied_p
= VAL_EXPR_IS_COPIED (loc
);
6449 rtx src
= NULL
, dst
= uloc
;
6450 enum var_init_status status
= VAR_INIT_STATUS_INITIALIZED
;
6452 if (GET_CODE (uloc
) == SET
)
6454 src
= SET_SRC (uloc
);
6455 dst
= SET_DEST (uloc
);
6460 if (flag_var_tracking_uninit
)
6462 status
= find_src_status (in
, src
);
6464 if (status
== VAR_INIT_STATUS_UNKNOWN
)
6465 status
= find_src_status (out
, src
);
6468 src
= find_src_set_src (in
, src
);
6472 var_reg_delete_and_set (out
, dst
, !copied_p
,
6474 else if (MEM_P (dst
))
6476 gcc_assert (MEM_P (dstv
));
6477 gcc_assert (MEM_ATTRS (dstv
) == MEM_ATTRS (dst
));
6478 var_mem_delete_and_set (out
, dstv
, !copied_p
,
6483 else if (REG_P (uloc
))
6484 var_regno_delete (out
, REGNO (uloc
));
6485 else if (MEM_P (uloc
))
6486 clobber_overlapping_mems (out
, uloc
);
6488 val_store (out
, val
, dstv
, insn
, true);
6494 rtx loc
= mo
->u
.loc
;
6497 if (GET_CODE (loc
) == SET
)
6499 set_src
= SET_SRC (loc
);
6500 loc
= SET_DEST (loc
);
6504 var_reg_delete_and_set (out
, loc
, true, VAR_INIT_STATUS_INITIALIZED
,
6506 else if (MEM_P (loc
))
6507 var_mem_delete_and_set (out
, loc
, true, VAR_INIT_STATUS_INITIALIZED
,
6514 rtx loc
= mo
->u
.loc
;
6515 enum var_init_status src_status
;
6518 if (GET_CODE (loc
) == SET
)
6520 set_src
= SET_SRC (loc
);
6521 loc
= SET_DEST (loc
);
6524 if (! flag_var_tracking_uninit
)
6525 src_status
= VAR_INIT_STATUS_INITIALIZED
;
6528 src_status
= find_src_status (in
, set_src
);
6530 if (src_status
== VAR_INIT_STATUS_UNKNOWN
)
6531 src_status
= find_src_status (out
, set_src
);
6534 set_src
= find_src_set_src (in
, set_src
);
6537 var_reg_delete_and_set (out
, loc
, false, src_status
, set_src
);
6538 else if (MEM_P (loc
))
6539 var_mem_delete_and_set (out
, loc
, false, src_status
, set_src
);
6545 rtx loc
= mo
->u
.loc
;
6548 var_reg_delete (out
, loc
, false);
6549 else if (MEM_P (loc
))
6550 var_mem_delete (out
, loc
, false);
6556 rtx loc
= mo
->u
.loc
;
6559 var_reg_delete (out
, loc
, true);
6560 else if (MEM_P (loc
))
6561 var_mem_delete (out
, loc
, true);
6566 out
->stack_adjust
+= mo
->u
.adjust
;
6571 if (MAY_HAVE_DEBUG_INSNS
)
6573 dataflow_set_equiv_regs (out
);
6574 htab_traverse (shared_hash_htab (out
->vars
), canonicalize_values_mark
,
6576 htab_traverse (shared_hash_htab (out
->vars
), canonicalize_values_star
,
6579 htab_traverse (shared_hash_htab (out
->vars
),
6580 canonicalize_loc_order_check
, out
);
6583 changed
= dataflow_set_different (&old_out
, out
);
6584 dataflow_set_destroy (&old_out
);
6588 /* Find the locations of variables in the whole function. */
6591 vt_find_locations (void)
6593 fibheap_t worklist
, pending
, fibheap_swap
;
6594 sbitmap visited
, in_worklist
, in_pending
, sbitmap_swap
;
6601 int htabmax
= PARAM_VALUE (PARAM_MAX_VARTRACK_SIZE
);
6602 bool success
= true;
6604 timevar_push (TV_VAR_TRACKING_DATAFLOW
);
6605 /* Compute reverse completion order of depth first search of the CFG
6606 so that the data-flow runs faster. */
6607 rc_order
= XNEWVEC (int, n_basic_blocks
- NUM_FIXED_BLOCKS
);
6608 bb_order
= XNEWVEC (int, last_basic_block
);
6609 pre_and_rev_post_order_compute (NULL
, rc_order
, false);
6610 for (i
= 0; i
< n_basic_blocks
- NUM_FIXED_BLOCKS
; i
++)
6611 bb_order
[rc_order
[i
]] = i
;
6614 worklist
= fibheap_new ();
6615 pending
= fibheap_new ();
6616 visited
= sbitmap_alloc (last_basic_block
);
6617 in_worklist
= sbitmap_alloc (last_basic_block
);
6618 in_pending
= sbitmap_alloc (last_basic_block
);
6619 sbitmap_zero (in_worklist
);
6622 fibheap_insert (pending
, bb_order
[bb
->index
], bb
);
6623 sbitmap_ones (in_pending
);
6625 while (success
&& !fibheap_empty (pending
))
6627 fibheap_swap
= pending
;
6629 worklist
= fibheap_swap
;
6630 sbitmap_swap
= in_pending
;
6631 in_pending
= in_worklist
;
6632 in_worklist
= sbitmap_swap
;
6634 sbitmap_zero (visited
);
6636 while (!fibheap_empty (worklist
))
6638 bb
= (basic_block
) fibheap_extract_min (worklist
);
6639 RESET_BIT (in_worklist
, bb
->index
);
6640 gcc_assert (!TEST_BIT (visited
, bb
->index
));
6641 if (!TEST_BIT (visited
, bb
->index
))
6645 int oldinsz
, oldoutsz
;
6647 SET_BIT (visited
, bb
->index
);
6649 if (VTI (bb
)->in
.vars
)
6652 -= (htab_size (shared_hash_htab (VTI (bb
)->in
.vars
))
6653 + htab_size (shared_hash_htab (VTI (bb
)->out
.vars
)));
6655 = htab_elements (shared_hash_htab (VTI (bb
)->in
.vars
));
6657 = htab_elements (shared_hash_htab (VTI (bb
)->out
.vars
));
6660 oldinsz
= oldoutsz
= 0;
6662 if (MAY_HAVE_DEBUG_INSNS
)
6664 dataflow_set
*in
= &VTI (bb
)->in
, *first_out
= NULL
;
6665 bool first
= true, adjust
= false;
6667 /* Calculate the IN set as the intersection of
6668 predecessor OUT sets. */
6670 dataflow_set_clear (in
);
6671 dst_can_be_shared
= true;
6673 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
6674 if (!VTI (e
->src
)->flooded
)
6675 gcc_assert (bb_order
[bb
->index
]
6676 <= bb_order
[e
->src
->index
]);
6679 dataflow_set_copy (in
, &VTI (e
->src
)->out
);
6680 first_out
= &VTI (e
->src
)->out
;
6685 dataflow_set_merge (in
, &VTI (e
->src
)->out
);
6691 dataflow_post_merge_adjust (in
, &VTI (bb
)->permp
);
6693 /* Merge and merge_adjust should keep entries in
6695 htab_traverse (shared_hash_htab (in
->vars
),
6696 canonicalize_loc_order_check
,
6699 if (dst_can_be_shared
)
6701 shared_hash_destroy (in
->vars
);
6702 in
->vars
= shared_hash_copy (first_out
->vars
);
6706 VTI (bb
)->flooded
= true;
6710 /* Calculate the IN set as union of predecessor OUT sets. */
6711 dataflow_set_clear (&VTI (bb
)->in
);
6712 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
6713 dataflow_set_union (&VTI (bb
)->in
, &VTI (e
->src
)->out
);
6716 changed
= compute_bb_dataflow (bb
);
6717 htabsz
+= (htab_size (shared_hash_htab (VTI (bb
)->in
.vars
))
6718 + htab_size (shared_hash_htab (VTI (bb
)->out
.vars
)));
6720 if (htabmax
&& htabsz
> htabmax
)
6722 if (MAY_HAVE_DEBUG_INSNS
)
6723 inform (DECL_SOURCE_LOCATION (cfun
->decl
),
6724 "variable tracking size limit exceeded with "
6725 "-fvar-tracking-assignments, retrying without");
6727 inform (DECL_SOURCE_LOCATION (cfun
->decl
),
6728 "variable tracking size limit exceeded");
6735 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
6737 if (e
->dest
== EXIT_BLOCK_PTR
)
6740 if (TEST_BIT (visited
, e
->dest
->index
))
6742 if (!TEST_BIT (in_pending
, e
->dest
->index
))
6744 /* Send E->DEST to next round. */
6745 SET_BIT (in_pending
, e
->dest
->index
);
6746 fibheap_insert (pending
,
6747 bb_order
[e
->dest
->index
],
6751 else if (!TEST_BIT (in_worklist
, e
->dest
->index
))
6753 /* Add E->DEST to current round. */
6754 SET_BIT (in_worklist
, e
->dest
->index
);
6755 fibheap_insert (worklist
, bb_order
[e
->dest
->index
],
6763 "BB %i: in %i (was %i), out %i (was %i), rem %i + %i, tsz %i\n",
6765 (int)htab_elements (shared_hash_htab (VTI (bb
)->in
.vars
)),
6767 (int)htab_elements (shared_hash_htab (VTI (bb
)->out
.vars
)),
6769 (int)worklist
->nodes
, (int)pending
->nodes
, htabsz
);
6771 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
6773 fprintf (dump_file
, "BB %i IN:\n", bb
->index
);
6774 dump_dataflow_set (&VTI (bb
)->in
);
6775 fprintf (dump_file
, "BB %i OUT:\n", bb
->index
);
6776 dump_dataflow_set (&VTI (bb
)->out
);
6782 if (success
&& MAY_HAVE_DEBUG_INSNS
)
6784 gcc_assert (VTI (bb
)->flooded
);
6787 fibheap_delete (worklist
);
6788 fibheap_delete (pending
);
6789 sbitmap_free (visited
);
6790 sbitmap_free (in_worklist
);
6791 sbitmap_free (in_pending
);
6793 timevar_pop (TV_VAR_TRACKING_DATAFLOW
);
6797 /* Print the content of the LIST to dump file. */
6800 dump_attrs_list (attrs list
)
6802 for (; list
; list
= list
->next
)
6804 if (dv_is_decl_p (list
->dv
))
6805 print_mem_expr (dump_file
, dv_as_decl (list
->dv
));
6807 print_rtl_single (dump_file
, dv_as_value (list
->dv
));
6808 fprintf (dump_file
, "+" HOST_WIDE_INT_PRINT_DEC
, list
->offset
);
6810 fprintf (dump_file
, "\n");
6813 /* Print the information about variable *SLOT to dump file. */
6816 dump_var_slot (void **slot
, void *data ATTRIBUTE_UNUSED
)
6818 variable var
= (variable
) *slot
;
6822 /* Continue traversing the hash table. */
6826 /* Print the information about variable VAR to dump file. */
6829 dump_var (variable var
)
6832 location_chain node
;
6834 if (dv_is_decl_p (var
->dv
))
6836 const_tree decl
= dv_as_decl (var
->dv
);
6838 if (DECL_NAME (decl
))
6840 fprintf (dump_file
, " name: %s",
6841 IDENTIFIER_POINTER (DECL_NAME (decl
)));
6842 if (dump_flags
& TDF_UID
)
6843 fprintf (dump_file
, "D.%u", DECL_UID (decl
));
6845 else if (TREE_CODE (decl
) == DEBUG_EXPR_DECL
)
6846 fprintf (dump_file
, " name: D#%u", DEBUG_TEMP_UID (decl
));
6848 fprintf (dump_file
, " name: D.%u", DECL_UID (decl
));
6849 fprintf (dump_file
, "\n");
6853 fputc (' ', dump_file
);
6854 print_rtl_single (dump_file
, dv_as_value (var
->dv
));
6857 for (i
= 0; i
< var
->n_var_parts
; i
++)
6859 fprintf (dump_file
, " offset %ld\n",
6860 (long)(var
->onepart
? 0 : VAR_PART_OFFSET (var
, i
)));
6861 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
6863 fprintf (dump_file
, " ");
6864 if (node
->init
== VAR_INIT_STATUS_UNINITIALIZED
)
6865 fprintf (dump_file
, "[uninit]");
6866 print_rtl_single (dump_file
, node
->loc
);
6871 /* Print the information about variables from hash table VARS to dump file. */
6874 dump_vars (htab_t vars
)
6876 if (htab_elements (vars
) > 0)
6878 fprintf (dump_file
, "Variables:\n");
6879 htab_traverse (vars
, dump_var_slot
, NULL
);
6883 /* Print the dataflow set SET to dump file. */
6886 dump_dataflow_set (dataflow_set
*set
)
6890 fprintf (dump_file
, "Stack adjustment: " HOST_WIDE_INT_PRINT_DEC
"\n",
6892 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
6896 fprintf (dump_file
, "Reg %d:", i
);
6897 dump_attrs_list (set
->regs
[i
]);
6900 dump_vars (shared_hash_htab (set
->vars
));
6901 fprintf (dump_file
, "\n");
6904 /* Print the IN and OUT sets for each basic block to dump file. */
6907 dump_dataflow_sets (void)
6913 fprintf (dump_file
, "\nBasic block %d:\n", bb
->index
);
6914 fprintf (dump_file
, "IN:\n");
6915 dump_dataflow_set (&VTI (bb
)->in
);
6916 fprintf (dump_file
, "OUT:\n");
6917 dump_dataflow_set (&VTI (bb
)->out
);
6921 /* Return the variable for DV in dropped_values, inserting one if
6922 requested with INSERT. */
6924 static inline variable
6925 variable_from_dropped (decl_or_value dv
, enum insert_option insert
)
6929 onepart_enum_t onepart
;
6931 slot
= htab_find_slot_with_hash (dropped_values
, dv
, dv_htab_hash (dv
),
6938 return (variable
) *slot
;
6940 gcc_checking_assert (insert
== INSERT
);
6942 onepart
= dv_onepart_p (dv
);
6944 gcc_checking_assert (onepart
== ONEPART_VALUE
|| onepart
== ONEPART_DEXPR
);
6946 empty_var
= (variable
) pool_alloc (onepart_pool (onepart
));
6948 empty_var
->refcount
= 1;
6949 empty_var
->n_var_parts
= 0;
6950 empty_var
->onepart
= onepart
;
6951 empty_var
->in_changed_variables
= false;
6952 empty_var
->var_part
[0].loc_chain
= NULL
;
6953 empty_var
->var_part
[0].cur_loc
= NULL
;
6954 VAR_LOC_1PAUX (empty_var
) = NULL
;
6955 set_dv_changed (dv
, true);
6962 /* Recover the one-part aux from dropped_values. */
6964 static struct onepart_aux
*
6965 recover_dropped_1paux (variable var
)
6969 gcc_checking_assert (var
->onepart
);
6971 if (VAR_LOC_1PAUX (var
))
6972 return VAR_LOC_1PAUX (var
);
6974 if (var
->onepart
== ONEPART_VDECL
)
6977 dvar
= variable_from_dropped (var
->dv
, NO_INSERT
);
6982 VAR_LOC_1PAUX (var
) = VAR_LOC_1PAUX (dvar
);
6983 VAR_LOC_1PAUX (dvar
) = NULL
;
6985 return VAR_LOC_1PAUX (var
);
6988 /* Add variable VAR to the hash table of changed variables and
6989 if it has no locations delete it from SET's hash table. */
6992 variable_was_changed (variable var
, dataflow_set
*set
)
6994 hashval_t hash
= dv_htab_hash (var
->dv
);
7000 /* Remember this decl or VALUE has been added to changed_variables. */
7001 set_dv_changed (var
->dv
, true);
7003 slot
= htab_find_slot_with_hash (changed_variables
,
7009 variable old_var
= (variable
) *slot
;
7010 gcc_assert (old_var
->in_changed_variables
);
7011 old_var
->in_changed_variables
= false;
7012 if (var
!= old_var
&& var
->onepart
)
7014 /* Restore the auxiliary info from an empty variable
7015 previously created for changed_variables, so it is
7017 gcc_checking_assert (!VAR_LOC_1PAUX (var
));
7018 VAR_LOC_1PAUX (var
) = VAR_LOC_1PAUX (old_var
);
7019 VAR_LOC_1PAUX (old_var
) = NULL
;
7021 variable_htab_free (*slot
);
7024 if (set
&& var
->n_var_parts
== 0)
7026 onepart_enum_t onepart
= var
->onepart
;
7027 variable empty_var
= NULL
;
7028 void **dslot
= NULL
;
7030 if (onepart
== ONEPART_VALUE
|| onepart
== ONEPART_DEXPR
)
7032 dslot
= htab_find_slot_with_hash (dropped_values
, var
->dv
,
7033 dv_htab_hash (var
->dv
),
7035 empty_var
= (variable
) *dslot
;
7039 gcc_checking_assert (!empty_var
->in_changed_variables
);
7040 if (!VAR_LOC_1PAUX (var
))
7042 VAR_LOC_1PAUX (var
) = VAR_LOC_1PAUX (empty_var
);
7043 VAR_LOC_1PAUX (empty_var
) = NULL
;
7046 gcc_checking_assert (!VAR_LOC_1PAUX (empty_var
));
7052 empty_var
= (variable
) pool_alloc (onepart_pool (onepart
));
7053 empty_var
->dv
= var
->dv
;
7054 empty_var
->refcount
= 1;
7055 empty_var
->n_var_parts
= 0;
7056 empty_var
->onepart
= onepart
;
7059 empty_var
->refcount
++;
7064 empty_var
->refcount
++;
7065 empty_var
->in_changed_variables
= true;
7069 empty_var
->var_part
[0].loc_chain
= NULL
;
7070 empty_var
->var_part
[0].cur_loc
= NULL
;
7071 VAR_LOC_1PAUX (empty_var
) = VAR_LOC_1PAUX (var
);
7072 VAR_LOC_1PAUX (var
) = NULL
;
7078 if (var
->onepart
&& !VAR_LOC_1PAUX (var
))
7079 recover_dropped_1paux (var
);
7081 var
->in_changed_variables
= true;
7088 if (var
->n_var_parts
== 0)
7093 slot
= shared_hash_find_slot_noinsert (set
->vars
, var
->dv
);
7096 if (shared_hash_shared (set
->vars
))
7097 slot
= shared_hash_find_slot_unshare (&set
->vars
, var
->dv
,
7099 htab_clear_slot (shared_hash_htab (set
->vars
), slot
);
7105 /* Look for the index in VAR->var_part corresponding to OFFSET.
7106 Return -1 if not found. If INSERTION_POINT is non-NULL, the
7107 referenced int will be set to the index that the part has or should
7108 have, if it should be inserted. */
7111 find_variable_location_part (variable var
, HOST_WIDE_INT offset
,
7112 int *insertion_point
)
7121 if (insertion_point
)
7122 *insertion_point
= 0;
7124 return var
->n_var_parts
- 1;
7127 /* Find the location part. */
7129 high
= var
->n_var_parts
;
7132 pos
= (low
+ high
) / 2;
7133 if (VAR_PART_OFFSET (var
, pos
) < offset
)
7140 if (insertion_point
)
7141 *insertion_point
= pos
;
7143 if (pos
< var
->n_var_parts
&& VAR_PART_OFFSET (var
, pos
) == offset
)
7150 set_slot_part (dataflow_set
*set
, rtx loc
, void **slot
,
7151 decl_or_value dv
, HOST_WIDE_INT offset
,
7152 enum var_init_status initialized
, rtx set_src
)
7155 location_chain node
, next
;
7156 location_chain
*nextp
;
7158 onepart_enum_t onepart
;
7160 var
= (variable
) *slot
;
7163 onepart
= var
->onepart
;
7165 onepart
= dv_onepart_p (dv
);
7167 gcc_checking_assert (offset
== 0 || !onepart
);
7168 gcc_checking_assert (loc
!= dv_as_opaque (dv
));
7170 if (! flag_var_tracking_uninit
)
7171 initialized
= VAR_INIT_STATUS_INITIALIZED
;
7175 /* Create new variable information. */
7176 var
= (variable
) pool_alloc (onepart_pool (onepart
));
7179 var
->n_var_parts
= 1;
7180 var
->onepart
= onepart
;
7181 var
->in_changed_variables
= false;
7183 VAR_LOC_1PAUX (var
) = NULL
;
7185 VAR_PART_OFFSET (var
, 0) = offset
;
7186 var
->var_part
[0].loc_chain
= NULL
;
7187 var
->var_part
[0].cur_loc
= NULL
;
7190 nextp
= &var
->var_part
[0].loc_chain
;
7196 gcc_assert (dv_as_opaque (var
->dv
) == dv_as_opaque (dv
));
7200 if (GET_CODE (loc
) == VALUE
)
7202 for (nextp
= &var
->var_part
[0].loc_chain
; (node
= *nextp
);
7203 nextp
= &node
->next
)
7204 if (GET_CODE (node
->loc
) == VALUE
)
7206 if (node
->loc
== loc
)
7211 if (canon_value_cmp (node
->loc
, loc
))
7219 else if (REG_P (node
->loc
) || MEM_P (node
->loc
))
7227 else if (REG_P (loc
))
7229 for (nextp
= &var
->var_part
[0].loc_chain
; (node
= *nextp
);
7230 nextp
= &node
->next
)
7231 if (REG_P (node
->loc
))
7233 if (REGNO (node
->loc
) < REGNO (loc
))
7237 if (REGNO (node
->loc
) == REGNO (loc
))
7250 else if (MEM_P (loc
))
7252 for (nextp
= &var
->var_part
[0].loc_chain
; (node
= *nextp
);
7253 nextp
= &node
->next
)
7254 if (REG_P (node
->loc
))
7256 else if (MEM_P (node
->loc
))
7258 if ((r
= loc_cmp (XEXP (node
->loc
, 0), XEXP (loc
, 0))) >= 0)
7270 for (nextp
= &var
->var_part
[0].loc_chain
; (node
= *nextp
);
7271 nextp
= &node
->next
)
7272 if ((r
= loc_cmp (node
->loc
, loc
)) >= 0)
7280 if (shared_var_p (var
, set
->vars
))
7282 slot
= unshare_variable (set
, slot
, var
, initialized
);
7283 var
= (variable
)*slot
;
7284 for (nextp
= &var
->var_part
[0].loc_chain
; c
;
7285 nextp
= &(*nextp
)->next
)
7287 gcc_assert ((!node
&& !*nextp
) || node
->loc
== (*nextp
)->loc
);
7294 gcc_assert (dv_as_decl (var
->dv
) == dv_as_decl (dv
));
7296 pos
= find_variable_location_part (var
, offset
, &inspos
);
7300 node
= var
->var_part
[pos
].loc_chain
;
7303 && ((REG_P (node
->loc
) && REG_P (loc
)
7304 && REGNO (node
->loc
) == REGNO (loc
))
7305 || rtx_equal_p (node
->loc
, loc
)))
7307 /* LOC is in the beginning of the chain so we have nothing
7309 if (node
->init
< initialized
)
7310 node
->init
= initialized
;
7311 if (set_src
!= NULL
)
7312 node
->set_src
= set_src
;
7318 /* We have to make a copy of a shared variable. */
7319 if (shared_var_p (var
, set
->vars
))
7321 slot
= unshare_variable (set
, slot
, var
, initialized
);
7322 var
= (variable
)*slot
;
7328 /* We have not found the location part, new one will be created. */
7330 /* We have to make a copy of the shared variable. */
7331 if (shared_var_p (var
, set
->vars
))
7333 slot
= unshare_variable (set
, slot
, var
, initialized
);
7334 var
= (variable
)*slot
;
7337 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
7338 thus there are at most MAX_VAR_PARTS different offsets. */
7339 gcc_assert (var
->n_var_parts
< MAX_VAR_PARTS
7340 && (!var
->n_var_parts
|| !onepart
));
7342 /* We have to move the elements of array starting at index
7343 inspos to the next position. */
7344 for (pos
= var
->n_var_parts
; pos
> inspos
; pos
--)
7345 var
->var_part
[pos
] = var
->var_part
[pos
- 1];
7348 gcc_checking_assert (!onepart
);
7349 VAR_PART_OFFSET (var
, pos
) = offset
;
7350 var
->var_part
[pos
].loc_chain
= NULL
;
7351 var
->var_part
[pos
].cur_loc
= NULL
;
7354 /* Delete the location from the list. */
7355 nextp
= &var
->var_part
[pos
].loc_chain
;
7356 for (node
= var
->var_part
[pos
].loc_chain
; node
; node
= next
)
7359 if ((REG_P (node
->loc
) && REG_P (loc
)
7360 && REGNO (node
->loc
) == REGNO (loc
))
7361 || rtx_equal_p (node
->loc
, loc
))
7363 /* Save these values, to assign to the new node, before
7364 deleting this one. */
7365 if (node
->init
> initialized
)
7366 initialized
= node
->init
;
7367 if (node
->set_src
!= NULL
&& set_src
== NULL
)
7368 set_src
= node
->set_src
;
7369 if (var
->var_part
[pos
].cur_loc
== node
->loc
)
7370 var
->var_part
[pos
].cur_loc
= NULL
;
7371 pool_free (loc_chain_pool
, node
);
7376 nextp
= &node
->next
;
7379 nextp
= &var
->var_part
[pos
].loc_chain
;
7382 /* Add the location to the beginning. */
7383 node
= (location_chain
) pool_alloc (loc_chain_pool
);
7385 node
->init
= initialized
;
7386 node
->set_src
= set_src
;
7387 node
->next
= *nextp
;
7390 /* If no location was emitted do so. */
7391 if (var
->var_part
[pos
].cur_loc
== NULL
)
7392 variable_was_changed (var
, set
);
7397 /* Set the part of variable's location in the dataflow set SET. The
7398 variable part is specified by variable's declaration in DV and
7399 offset OFFSET and the part's location by LOC. IOPT should be
7400 NO_INSERT if the variable is known to be in SET already and the
7401 variable hash table must not be resized, and INSERT otherwise. */
7404 set_variable_part (dataflow_set
*set
, rtx loc
,
7405 decl_or_value dv
, HOST_WIDE_INT offset
,
7406 enum var_init_status initialized
, rtx set_src
,
7407 enum insert_option iopt
)
7411 if (iopt
== NO_INSERT
)
7412 slot
= shared_hash_find_slot_noinsert (set
->vars
, dv
);
7415 slot
= shared_hash_find_slot (set
->vars
, dv
);
7417 slot
= shared_hash_find_slot_unshare (&set
->vars
, dv
, iopt
);
7419 set_slot_part (set
, loc
, slot
, dv
, offset
, initialized
, set_src
);
7422 /* Remove all recorded register locations for the given variable part
7423 from dataflow set SET, except for those that are identical to loc.
7424 The variable part is specified by variable's declaration or value
7425 DV and offset OFFSET. */
7428 clobber_slot_part (dataflow_set
*set
, rtx loc
, void **slot
,
7429 HOST_WIDE_INT offset
, rtx set_src
)
7431 variable var
= (variable
) *slot
;
7432 int pos
= find_variable_location_part (var
, offset
, NULL
);
7436 location_chain node
, next
;
7438 /* Remove the register locations from the dataflow set. */
7439 next
= var
->var_part
[pos
].loc_chain
;
7440 for (node
= next
; node
; node
= next
)
7443 if (node
->loc
!= loc
7444 && (!flag_var_tracking_uninit
7447 || !rtx_equal_p (set_src
, node
->set_src
)))
7449 if (REG_P (node
->loc
))
7454 /* Remove the variable part from the register's
7455 list, but preserve any other variable parts
7456 that might be regarded as live in that same
7458 anextp
= &set
->regs
[REGNO (node
->loc
)];
7459 for (anode
= *anextp
; anode
; anode
= anext
)
7461 anext
= anode
->next
;
7462 if (dv_as_opaque (anode
->dv
) == dv_as_opaque (var
->dv
)
7463 && anode
->offset
== offset
)
7465 pool_free (attrs_pool
, anode
);
7469 anextp
= &anode
->next
;
7473 slot
= delete_slot_part (set
, node
->loc
, slot
, offset
);
7481 /* Remove all recorded register locations for the given variable part
7482 from dataflow set SET, except for those that are identical to loc.
7483 The variable part is specified by variable's declaration or value
7484 DV and offset OFFSET. */
7487 clobber_variable_part (dataflow_set
*set
, rtx loc
, decl_or_value dv
,
7488 HOST_WIDE_INT offset
, rtx set_src
)
7492 if (!dv_as_opaque (dv
)
7493 || (!dv_is_value_p (dv
) && ! DECL_P (dv_as_decl (dv
))))
7496 slot
= shared_hash_find_slot_noinsert (set
->vars
, dv
);
7500 clobber_slot_part (set
, loc
, slot
, offset
, set_src
);
7503 /* Delete the part of variable's location from dataflow set SET. The
7504 variable part is specified by its SET->vars slot SLOT and offset
7505 OFFSET and the part's location by LOC. */
7508 delete_slot_part (dataflow_set
*set
, rtx loc
, void **slot
,
7509 HOST_WIDE_INT offset
)
7511 variable var
= (variable
) *slot
;
7512 int pos
= find_variable_location_part (var
, offset
, NULL
);
7516 location_chain node
, next
;
7517 location_chain
*nextp
;
7521 if (shared_var_p (var
, set
->vars
))
7523 /* If the variable contains the location part we have to
7524 make a copy of the variable. */
7525 for (node
= var
->var_part
[pos
].loc_chain
; node
;
7528 if ((REG_P (node
->loc
) && REG_P (loc
)
7529 && REGNO (node
->loc
) == REGNO (loc
))
7530 || rtx_equal_p (node
->loc
, loc
))
7532 slot
= unshare_variable (set
, slot
, var
,
7533 VAR_INIT_STATUS_UNKNOWN
);
7534 var
= (variable
)*slot
;
7540 if (pos
== 0 && var
->onepart
&& VAR_LOC_1PAUX (var
))
7541 cur_loc
= VAR_LOC_FROM (var
);
7543 cur_loc
= var
->var_part
[pos
].cur_loc
;
7545 /* Delete the location part. */
7547 nextp
= &var
->var_part
[pos
].loc_chain
;
7548 for (node
= *nextp
; node
; node
= next
)
7551 if ((REG_P (node
->loc
) && REG_P (loc
)
7552 && REGNO (node
->loc
) == REGNO (loc
))
7553 || rtx_equal_p (node
->loc
, loc
))
7555 /* If we have deleted the location which was last emitted
7556 we have to emit new location so add the variable to set
7557 of changed variables. */
7558 if (cur_loc
== node
->loc
)
7561 var
->var_part
[pos
].cur_loc
= NULL
;
7562 if (pos
== 0 && var
->onepart
&& VAR_LOC_1PAUX (var
))
7563 VAR_LOC_FROM (var
) = NULL
;
7565 pool_free (loc_chain_pool
, node
);
7570 nextp
= &node
->next
;
7573 if (var
->var_part
[pos
].loc_chain
== NULL
)
7577 while (pos
< var
->n_var_parts
)
7579 var
->var_part
[pos
] = var
->var_part
[pos
+ 1];
7584 variable_was_changed (var
, set
);
7590 /* Delete the part of variable's location from dataflow set SET. The
7591 variable part is specified by variable's declaration or value DV
7592 and offset OFFSET and the part's location by LOC. */
7595 delete_variable_part (dataflow_set
*set
, rtx loc
, decl_or_value dv
,
7596 HOST_WIDE_INT offset
)
7598 void **slot
= shared_hash_find_slot_noinsert (set
->vars
, dv
);
7602 delete_slot_part (set
, loc
, slot
, offset
);
7605 DEF_VEC_P (variable
);
7606 DEF_VEC_ALLOC_P (variable
, heap
);
7608 DEF_VEC_ALLOC_P_STACK (rtx
);
7609 #define VEC_rtx_stack_alloc(alloc) VEC_stack_alloc (rtx, alloc)
7611 /* Structure for passing some other parameters to function
7612 vt_expand_loc_callback. */
7613 struct expand_loc_callback_data
7615 /* The variables and values active at this point. */
7618 /* Stack of values and debug_exprs under expansion, and their
7620 VEC (rtx
, stack
) *expanding
;
7622 /* Stack of values and debug_exprs whose expansion hit recursion
7623 cycles. They will have VALUE_RECURSED_INTO marked when added to
7624 this list. This flag will be cleared if any of its dependencies
7625 resolves to a valid location. So, if the flag remains set at the
7626 end of the search, we know no valid location for this one can
7628 VEC (rtx
, stack
) *pending
;
7630 /* The maximum depth among the sub-expressions under expansion.
7631 Zero indicates no expansion so far. */
7635 /* Allocate the one-part auxiliary data structure for VAR, with enough
7636 room for COUNT dependencies. */
7639 loc_exp_dep_alloc (variable var
, int count
)
7643 gcc_checking_assert (var
->onepart
);
7645 /* We can be called with COUNT == 0 to allocate the data structure
7646 without any dependencies, e.g. for the backlinks only. However,
7647 if we are specifying a COUNT, then the dependency list must have
7648 been emptied before. It would be possible to adjust pointers or
7649 force it empty here, but this is better done at an earlier point
7650 in the algorithm, so we instead leave an assertion to catch
7652 gcc_checking_assert (!count
7653 || VEC_empty (loc_exp_dep
, VAR_LOC_DEP_VEC (var
)));
7655 if (VAR_LOC_1PAUX (var
)
7656 && VEC_space (loc_exp_dep
, VAR_LOC_DEP_VEC (var
), count
))
7659 allocsize
= offsetof (struct onepart_aux
, deps
)
7660 + VEC_embedded_size (loc_exp_dep
, count
);
7662 if (VAR_LOC_1PAUX (var
))
7664 VAR_LOC_1PAUX (var
) = XRESIZEVAR (struct onepart_aux
,
7665 VAR_LOC_1PAUX (var
), allocsize
);
7666 /* If the reallocation moves the onepaux structure, the
7667 back-pointer to BACKLINKS in the first list member will still
7668 point to its old location. Adjust it. */
7669 if (VAR_LOC_DEP_LST (var
))
7670 VAR_LOC_DEP_LST (var
)->pprev
= VAR_LOC_DEP_LSTP (var
);
7674 VAR_LOC_1PAUX (var
) = XNEWVAR (struct onepart_aux
, allocsize
);
7675 *VAR_LOC_DEP_LSTP (var
) = NULL
;
7676 VAR_LOC_FROM (var
) = NULL
;
7677 VAR_LOC_DEPTH (var
).complexity
= 0;
7678 VAR_LOC_DEPTH (var
).entryvals
= 0;
7680 VEC_embedded_init (loc_exp_dep
, VAR_LOC_DEP_VEC (var
), count
);
7683 /* Remove all entries from the vector of active dependencies of VAR,
7684 removing them from the back-links lists too. */
7687 loc_exp_dep_clear (variable var
)
7689 while (!VEC_empty (loc_exp_dep
, VAR_LOC_DEP_VEC (var
)))
7691 loc_exp_dep
*led
= VEC_last (loc_exp_dep
, VAR_LOC_DEP_VEC (var
));
7693 led
->next
->pprev
= led
->pprev
;
7695 *led
->pprev
= led
->next
;
7696 VEC_pop (loc_exp_dep
, VAR_LOC_DEP_VEC (var
));
7700 /* Insert an active dependency from VAR on X to the vector of
7701 dependencies, and add the corresponding back-link to X's list of
7702 back-links in VARS. */
7705 loc_exp_insert_dep (variable var
, rtx x
, htab_t vars
)
7711 dv
= dv_from_rtx (x
);
7713 /* ??? Build a vector of variables parallel to EXPANDING, to avoid
7714 an additional look up? */
7715 xvar
= (variable
) htab_find_with_hash (vars
, dv
, dv_htab_hash (dv
));
7719 xvar
= variable_from_dropped (dv
, NO_INSERT
);
7720 gcc_checking_assert (xvar
);
7723 /* No point in adding the same backlink more than once. This may
7724 arise if say the same value appears in two complex expressions in
7725 the same loc_list, or even more than once in a single
7727 if (VAR_LOC_DEP_LST (xvar
) && VAR_LOC_DEP_LST (xvar
)->dv
== var
->dv
)
7730 if (var
->onepart
== NOT_ONEPART
)
7731 led
= (loc_exp_dep
*) pool_alloc (loc_exp_dep_pool
);
7734 VEC_quick_push (loc_exp_dep
, VAR_LOC_DEP_VEC (var
), NULL
);
7735 led
= VEC_last (loc_exp_dep
, VAR_LOC_DEP_VEC (var
));
7740 loc_exp_dep_alloc (xvar
, 0);
7741 led
->pprev
= VAR_LOC_DEP_LSTP (xvar
);
7742 led
->next
= *led
->pprev
;
7744 led
->next
->pprev
= &led
->next
;
7748 /* Create active dependencies of VAR on COUNT values starting at
7749 VALUE, and corresponding back-links to the entries in VARS. Return
7750 true if we found any pending-recursion results. */
7753 loc_exp_dep_set (variable var
, rtx result
, rtx
*value
, int count
, htab_t vars
)
7755 bool pending_recursion
= false;
7757 gcc_checking_assert (VEC_empty (loc_exp_dep
, VAR_LOC_DEP_VEC (var
)));
7759 /* Set up all dependencies from last_child (as set up at the end of
7760 the loop above) to the end. */
7761 loc_exp_dep_alloc (var
, count
);
7767 if (!pending_recursion
)
7768 pending_recursion
= !result
&& VALUE_RECURSED_INTO (x
);
7770 loc_exp_insert_dep (var
, x
, vars
);
7773 return pending_recursion
;
7776 /* Notify the back-links of IVAR that are pending recursion that we
7777 have found a non-NIL value for it, so they are cleared for another
7778 attempt to compute a current location. */
7781 notify_dependents_of_resolved_value (variable ivar
, htab_t vars
)
7783 loc_exp_dep
*led
, *next
;
7785 for (led
= VAR_LOC_DEP_LST (ivar
); led
; led
= next
)
7787 decl_or_value dv
= led
->dv
;
7792 if (dv_is_value_p (dv
))
7794 rtx value
= dv_as_value (dv
);
7796 /* If we have already resolved it, leave it alone. */
7797 if (!VALUE_RECURSED_INTO (value
))
7800 /* Check that VALUE_RECURSED_INTO, true from the test above,
7801 implies NO_LOC_P. */
7802 gcc_checking_assert (NO_LOC_P (value
));
7804 /* We won't notify variables that are being expanded,
7805 because their dependency list is cleared before
7807 NO_LOC_P (value
) = false;
7808 VALUE_RECURSED_INTO (value
) = false;
7810 gcc_checking_assert (dv_changed_p (dv
));
7814 gcc_checking_assert (dv_onepart_p (dv
) != NOT_ONEPART
);
7815 if (!dv_changed_p (dv
))
7819 var
= (variable
) htab_find_with_hash (vars
, dv
, dv_htab_hash (dv
));
7822 var
= variable_from_dropped (dv
, NO_INSERT
);
7825 notify_dependents_of_resolved_value (var
, vars
);
7828 next
->pprev
= led
->pprev
;
7836 static rtx
vt_expand_loc_callback (rtx x
, bitmap regs
,
7837 int max_depth
, void *data
);
7839 /* Return the combined depth, when one sub-expression evaluated to
7840 BEST_DEPTH and the previous known depth was SAVED_DEPTH. */
7842 static inline expand_depth
7843 update_depth (expand_depth saved_depth
, expand_depth best_depth
)
7845 /* If we didn't find anything, stick with what we had. */
7846 if (!best_depth
.complexity
)
7849 /* If we found hadn't found anything, use the depth of the current
7850 expression. Do NOT add one extra level, we want to compute the
7851 maximum depth among sub-expressions. We'll increment it later,
7853 if (!saved_depth
.complexity
)
7856 /* Combine the entryval count so that regardless of which one we
7857 return, the entryval count is accurate. */
7858 best_depth
.entryvals
= saved_depth
.entryvals
7859 = best_depth
.entryvals
+ saved_depth
.entryvals
;
7861 if (saved_depth
.complexity
< best_depth
.complexity
)
7867 /* Expand VAR to a location RTX, updating its cur_loc. Use REGS and
7868 DATA for cselib expand callback. If PENDRECP is given, indicate in
7869 it whether any sub-expression couldn't be fully evaluated because
7870 it is pending recursion resolution. */
7873 vt_expand_var_loc_chain (variable var
, bitmap regs
, void *data
, bool *pendrecp
)
7875 struct expand_loc_callback_data
*elcd
7876 = (struct expand_loc_callback_data
*) data
;
7877 location_chain loc
, next
;
7879 int first_child
, result_first_child
, last_child
;
7880 bool pending_recursion
;
7881 rtx loc_from
= NULL
;
7882 struct elt_loc_list
*cloc
= NULL
;
7883 expand_depth depth
= { 0, 0 }, saved_depth
= elcd
->depth
;
7884 int wanted_entryvals
, found_entryvals
= 0;
7886 /* Clear all backlinks pointing at this, so that we're not notified
7887 while we're active. */
7888 loc_exp_dep_clear (var
);
7891 if (var
->onepart
== ONEPART_VALUE
)
7893 cselib_val
*val
= CSELIB_VAL_PTR (dv_as_value (var
->dv
));
7895 gcc_checking_assert (cselib_preserved_value_p (val
));
7900 first_child
= result_first_child
= last_child
7901 = VEC_length (rtx
, elcd
->expanding
);
7903 wanted_entryvals
= found_entryvals
;
7905 /* Attempt to expand each available location in turn. */
7906 for (next
= loc
= var
->n_var_parts
? var
->var_part
[0].loc_chain
: NULL
;
7907 loc
|| cloc
; loc
= next
)
7909 result_first_child
= last_child
;
7913 loc_from
= cloc
->loc
;
7916 if (unsuitable_loc (loc_from
))
7921 loc_from
= loc
->loc
;
7925 gcc_checking_assert (!unsuitable_loc (loc_from
));
7927 elcd
->depth
.complexity
= elcd
->depth
.entryvals
= 0;
7928 result
= cselib_expand_value_rtx_cb (loc_from
, regs
, EXPR_DEPTH
,
7929 vt_expand_loc_callback
, data
);
7930 last_child
= VEC_length (rtx
, elcd
->expanding
);
7934 depth
= elcd
->depth
;
7936 gcc_checking_assert (depth
.complexity
7937 || result_first_child
== last_child
);
7939 if (last_child
- result_first_child
!= 1)
7941 if (!depth
.complexity
&& GET_CODE (result
) == ENTRY_VALUE
)
7946 if (depth
.complexity
<= EXPR_USE_DEPTH
)
7948 if (depth
.entryvals
<= wanted_entryvals
)
7950 else if (!found_entryvals
|| depth
.entryvals
< found_entryvals
)
7951 found_entryvals
= depth
.entryvals
;
7957 /* Set it up in case we leave the loop. */
7958 depth
.complexity
= depth
.entryvals
= 0;
7960 result_first_child
= first_child
;
7963 if (!loc_from
&& wanted_entryvals
< found_entryvals
)
7965 /* We found entries with ENTRY_VALUEs and skipped them. Since
7966 we could not find any expansions without ENTRY_VALUEs, but we
7967 found at least one with them, go back and get an entry with
7968 the minimum number ENTRY_VALUE count that we found. We could
7969 avoid looping, but since each sub-loc is already resolved,
7970 the re-expansion should be trivial. ??? Should we record all
7971 attempted locs as dependencies, so that we retry the
7972 expansion should any of them change, in the hope it can give
7973 us a new entry without an ENTRY_VALUE? */
7974 VEC_truncate (rtx
, elcd
->expanding
, first_child
);
7978 /* Register all encountered dependencies as active. */
7979 pending_recursion
= loc_exp_dep_set
7980 (var
, result
, VEC_address (rtx
, elcd
->expanding
) + result_first_child
,
7981 last_child
- result_first_child
, elcd
->vars
);
7983 VEC_truncate (rtx
, elcd
->expanding
, first_child
);
7985 /* Record where the expansion came from. */
7986 gcc_checking_assert (!result
|| !pending_recursion
);
7987 VAR_LOC_FROM (var
) = loc_from
;
7988 VAR_LOC_DEPTH (var
) = depth
;
7990 gcc_checking_assert (!depth
.complexity
== !result
);
7992 elcd
->depth
= update_depth (saved_depth
, depth
);
7994 /* Indicate whether any of the dependencies are pending recursion
7997 *pendrecp
= pending_recursion
;
7999 if (!pendrecp
|| !pending_recursion
)
8000 var
->var_part
[0].cur_loc
= result
;
8005 /* Callback for cselib_expand_value, that looks for expressions
8006 holding the value in the var-tracking hash tables. Return X for
8007 standard processing, anything else is to be used as-is. */
8010 vt_expand_loc_callback (rtx x
, bitmap regs
,
8011 int max_depth ATTRIBUTE_UNUSED
,
8014 struct expand_loc_callback_data
*elcd
8015 = (struct expand_loc_callback_data
*) data
;
8019 bool pending_recursion
= false;
8020 bool from_empty
= false;
8022 switch (GET_CODE (x
))
8025 subreg
= cselib_expand_value_rtx_cb (SUBREG_REG (x
), regs
,
8027 vt_expand_loc_callback
, data
);
8032 result
= simplify_gen_subreg (GET_MODE (x
), subreg
,
8033 GET_MODE (SUBREG_REG (x
)),
8036 /* Invalid SUBREGs are ok in debug info. ??? We could try
8037 alternate expansions for the VALUE as well. */
8039 result
= gen_rtx_raw_SUBREG (GET_MODE (x
), subreg
, SUBREG_BYTE (x
));
8045 dv
= dv_from_rtx (x
);
8052 VEC_safe_push (rtx
, stack
, elcd
->expanding
, x
);
8054 /* Check that VALUE_RECURSED_INTO implies NO_LOC_P. */
8055 gcc_checking_assert (!VALUE_RECURSED_INTO (x
) || NO_LOC_P (x
));
8059 gcc_checking_assert (VALUE_RECURSED_INTO (x
) || !dv_changed_p (dv
));
8063 var
= (variable
) htab_find_with_hash (elcd
->vars
, dv
, dv_htab_hash (dv
));
8068 var
= variable_from_dropped (dv
, INSERT
);
8071 gcc_checking_assert (var
);
8073 if (!dv_changed_p (dv
))
8075 gcc_checking_assert (!NO_LOC_P (x
));
8076 gcc_checking_assert (var
->var_part
[0].cur_loc
);
8077 gcc_checking_assert (VAR_LOC_1PAUX (var
));
8078 gcc_checking_assert (VAR_LOC_1PAUX (var
)->depth
.complexity
);
8080 elcd
->depth
= update_depth (elcd
->depth
, VAR_LOC_1PAUX (var
)->depth
);
8082 return var
->var_part
[0].cur_loc
;
8085 VALUE_RECURSED_INTO (x
) = true;
8086 /* This is tentative, but it makes some tests simpler. */
8087 NO_LOC_P (x
) = true;
8089 gcc_checking_assert (var
->n_var_parts
== 1 || from_empty
);
8091 result
= vt_expand_var_loc_chain (var
, regs
, data
, &pending_recursion
);
8093 if (pending_recursion
)
8095 gcc_checking_assert (!result
);
8096 VEC_safe_push (rtx
, stack
, elcd
->pending
, x
);
8100 NO_LOC_P (x
) = !result
;
8101 VALUE_RECURSED_INTO (x
) = false;
8102 set_dv_changed (dv
, false);
8105 notify_dependents_of_resolved_value (var
, elcd
->vars
);
8111 /* While expanding variables, we may encounter recursion cycles
8112 because of mutual (possibly indirect) dependencies between two
8113 particular variables (or values), say A and B. If we're trying to
8114 expand A when we get to B, which in turn attempts to expand A, if
8115 we can't find any other expansion for B, we'll add B to this
8116 pending-recursion stack, and tentatively return NULL for its
8117 location. This tentative value will be used for any other
8118 occurrences of B, unless A gets some other location, in which case
8119 it will notify B that it is worth another try at computing a
8120 location for it, and it will use the location computed for A then.
8121 At the end of the expansion, the tentative NULL locations become
8122 final for all members of PENDING that didn't get a notification.
8123 This function performs this finalization of NULL locations. */
8126 resolve_expansions_pending_recursion (VEC (rtx
, stack
) *pending
)
8128 while (!VEC_empty (rtx
, pending
))
8130 rtx x
= VEC_pop (rtx
, pending
);
8133 if (!VALUE_RECURSED_INTO (x
))
8136 gcc_checking_assert (NO_LOC_P (x
));
8137 VALUE_RECURSED_INTO (x
) = false;
8138 dv
= dv_from_rtx (x
);
8139 gcc_checking_assert (dv_changed_p (dv
));
8140 set_dv_changed (dv
, false);
8144 /* Initialize expand_loc_callback_data D with variable hash table V.
8145 It must be a macro because of alloca (VEC stack). */
8146 #define INIT_ELCD(d, v) \
8150 (d).expanding = VEC_alloc (rtx, stack, 4); \
8151 (d).pending = VEC_alloc (rtx, stack, 4); \
8152 (d).depth.complexity = (d).depth.entryvals = 0; \
8155 /* Finalize expand_loc_callback_data D, resolved to location L. */
8156 #define FINI_ELCD(d, l) \
8159 resolve_expansions_pending_recursion ((d).pending); \
8160 VEC_free (rtx, stack, (d).pending); \
8161 VEC_free (rtx, stack, (d).expanding); \
8163 if ((l) && MEM_P (l)) \
8164 (l) = targetm.delegitimize_address (l); \
8168 /* Expand VALUEs and DEBUG_EXPRs in LOC to a location, using the
8169 equivalences in VARS, updating their CUR_LOCs in the process. */
8172 vt_expand_loc (rtx loc
, htab_t vars
)
8174 struct expand_loc_callback_data data
;
8177 if (!MAY_HAVE_DEBUG_INSNS
)
8180 INIT_ELCD (data
, vars
);
8182 result
= cselib_expand_value_rtx_cb (loc
, scratch_regs
, EXPR_DEPTH
,
8183 vt_expand_loc_callback
, &data
);
8185 FINI_ELCD (data
, result
);
8190 /* Expand the one-part VARiable to a location, using the equivalences
8191 in VARS, updating their CUR_LOCs in the process. */
8194 vt_expand_1pvar (variable var
, htab_t vars
)
8196 struct expand_loc_callback_data data
;
8199 gcc_checking_assert (var
->onepart
&& var
->n_var_parts
== 1);
8201 if (!dv_changed_p (var
->dv
))
8202 return var
->var_part
[0].cur_loc
;
8204 INIT_ELCD (data
, vars
);
8206 loc
= vt_expand_var_loc_chain (var
, scratch_regs
, &data
, NULL
);
8208 gcc_checking_assert (VEC_empty (rtx
, data
.expanding
));
8210 FINI_ELCD (data
, loc
);
8215 /* Emit the NOTE_INSN_VAR_LOCATION for variable *VARP. DATA contains
8216 additional parameters: WHERE specifies whether the note shall be emitted
8217 before or after instruction INSN. */
8220 emit_note_insn_var_location (void **varp
, void *data
)
8222 variable var
= (variable
) *varp
;
8223 rtx insn
= ((emit_note_data
*)data
)->insn
;
8224 enum emit_note_where where
= ((emit_note_data
*)data
)->where
;
8225 htab_t vars
= ((emit_note_data
*)data
)->vars
;
8227 int i
, j
, n_var_parts
;
8229 enum var_init_status initialized
= VAR_INIT_STATUS_UNINITIALIZED
;
8230 HOST_WIDE_INT last_limit
;
8231 tree type_size_unit
;
8232 HOST_WIDE_INT offsets
[MAX_VAR_PARTS
];
8233 rtx loc
[MAX_VAR_PARTS
];
8237 gcc_checking_assert (var
->onepart
== NOT_ONEPART
8238 || var
->onepart
== ONEPART_VDECL
);
8240 decl
= dv_as_decl (var
->dv
);
8246 for (i
= 0; i
< var
->n_var_parts
; i
++)
8247 if (var
->var_part
[i
].cur_loc
== NULL
&& var
->var_part
[i
].loc_chain
)
8248 var
->var_part
[i
].cur_loc
= var
->var_part
[i
].loc_chain
->loc
;
8249 for (i
= 0; i
< var
->n_var_parts
; i
++)
8251 enum machine_mode mode
, wider_mode
;
8253 HOST_WIDE_INT offset
;
8255 if (i
== 0 && var
->onepart
)
8257 gcc_checking_assert (var
->n_var_parts
== 1);
8259 initialized
= VAR_INIT_STATUS_INITIALIZED
;
8260 loc2
= vt_expand_1pvar (var
, vars
);
8264 if (last_limit
< VAR_PART_OFFSET (var
, i
))
8269 else if (last_limit
> VAR_PART_OFFSET (var
, i
))
8271 offset
= VAR_PART_OFFSET (var
, i
);
8272 loc2
= var
->var_part
[i
].cur_loc
;
8273 if (loc2
&& GET_CODE (loc2
) == MEM
8274 && GET_CODE (XEXP (loc2
, 0)) == VALUE
)
8276 rtx depval
= XEXP (loc2
, 0);
8278 loc2
= vt_expand_loc (loc2
, vars
);
8281 loc_exp_insert_dep (var
, depval
, vars
);
8288 gcc_checking_assert (GET_CODE (loc2
) != VALUE
);
8289 for (lc
= var
->var_part
[i
].loc_chain
; lc
; lc
= lc
->next
)
8290 if (var
->var_part
[i
].cur_loc
== lc
->loc
)
8292 initialized
= lc
->init
;
8298 offsets
[n_var_parts
] = offset
;
8304 loc
[n_var_parts
] = loc2
;
8305 mode
= GET_MODE (var
->var_part
[i
].cur_loc
);
8306 if (mode
== VOIDmode
&& var
->onepart
)
8307 mode
= DECL_MODE (decl
);
8308 last_limit
= offsets
[n_var_parts
] + GET_MODE_SIZE (mode
);
8310 /* Attempt to merge adjacent registers or memory. */
8311 wider_mode
= GET_MODE_WIDER_MODE (mode
);
8312 for (j
= i
+ 1; j
< var
->n_var_parts
; j
++)
8313 if (last_limit
<= VAR_PART_OFFSET (var
, j
))
8315 if (j
< var
->n_var_parts
8316 && wider_mode
!= VOIDmode
8317 && var
->var_part
[j
].cur_loc
8318 && mode
== GET_MODE (var
->var_part
[j
].cur_loc
)
8319 && (REG_P (loc
[n_var_parts
]) || MEM_P (loc
[n_var_parts
]))
8320 && last_limit
== (var
->onepart
? 0 : VAR_PART_OFFSET (var
, j
))
8321 && (loc2
= vt_expand_loc (var
->var_part
[j
].cur_loc
, vars
))
8322 && GET_CODE (loc
[n_var_parts
]) == GET_CODE (loc2
))
8326 if (REG_P (loc
[n_var_parts
])
8327 && hard_regno_nregs
[REGNO (loc
[n_var_parts
])][mode
] * 2
8328 == hard_regno_nregs
[REGNO (loc
[n_var_parts
])][wider_mode
]
8329 && end_hard_regno (mode
, REGNO (loc
[n_var_parts
]))
8332 if (! WORDS_BIG_ENDIAN
&& ! BYTES_BIG_ENDIAN
)
8333 new_loc
= simplify_subreg (wider_mode
, loc
[n_var_parts
],
8335 else if (WORDS_BIG_ENDIAN
&& BYTES_BIG_ENDIAN
)
8336 new_loc
= simplify_subreg (wider_mode
, loc2
, mode
, 0);
8339 if (!REG_P (new_loc
)
8340 || REGNO (new_loc
) != REGNO (loc
[n_var_parts
]))
8343 REG_ATTRS (new_loc
) = REG_ATTRS (loc
[n_var_parts
]);
8346 else if (MEM_P (loc
[n_var_parts
])
8347 && GET_CODE (XEXP (loc2
, 0)) == PLUS
8348 && REG_P (XEXP (XEXP (loc2
, 0), 0))
8349 && CONST_INT_P (XEXP (XEXP (loc2
, 0), 1)))
8351 if ((REG_P (XEXP (loc
[n_var_parts
], 0))
8352 && rtx_equal_p (XEXP (loc
[n_var_parts
], 0),
8353 XEXP (XEXP (loc2
, 0), 0))
8354 && INTVAL (XEXP (XEXP (loc2
, 0), 1))
8355 == GET_MODE_SIZE (mode
))
8356 || (GET_CODE (XEXP (loc
[n_var_parts
], 0)) == PLUS
8357 && CONST_INT_P (XEXP (XEXP (loc
[n_var_parts
], 0), 1))
8358 && rtx_equal_p (XEXP (XEXP (loc
[n_var_parts
], 0), 0),
8359 XEXP (XEXP (loc2
, 0), 0))
8360 && INTVAL (XEXP (XEXP (loc
[n_var_parts
], 0), 1))
8361 + GET_MODE_SIZE (mode
)
8362 == INTVAL (XEXP (XEXP (loc2
, 0), 1))))
8363 new_loc
= adjust_address_nv (loc
[n_var_parts
],
8369 loc
[n_var_parts
] = new_loc
;
8371 last_limit
= offsets
[n_var_parts
] + GET_MODE_SIZE (mode
);
8377 type_size_unit
= TYPE_SIZE_UNIT (TREE_TYPE (decl
));
8378 if ((unsigned HOST_WIDE_INT
) last_limit
< TREE_INT_CST_LOW (type_size_unit
))
8381 if (! flag_var_tracking_uninit
)
8382 initialized
= VAR_INIT_STATUS_INITIALIZED
;
8386 note_vl
= gen_rtx_VAR_LOCATION (VOIDmode
, decl
, NULL_RTX
,
8388 else if (n_var_parts
== 1)
8392 if (offsets
[0] || GET_CODE (loc
[0]) == PARALLEL
)
8393 expr_list
= gen_rtx_EXPR_LIST (VOIDmode
, loc
[0], GEN_INT (offsets
[0]));
8397 note_vl
= gen_rtx_VAR_LOCATION (VOIDmode
, decl
, expr_list
,
8400 else if (n_var_parts
)
8404 for (i
= 0; i
< n_var_parts
; i
++)
8406 = gen_rtx_EXPR_LIST (VOIDmode
, loc
[i
], GEN_INT (offsets
[i
]));
8408 parallel
= gen_rtx_PARALLEL (VOIDmode
,
8409 gen_rtvec_v (n_var_parts
, loc
));
8410 note_vl
= gen_rtx_VAR_LOCATION (VOIDmode
, decl
,
8411 parallel
, (int) initialized
);
8414 if (where
!= EMIT_NOTE_BEFORE_INSN
)
8416 note
= emit_note_after (NOTE_INSN_VAR_LOCATION
, insn
);
8417 if (where
== EMIT_NOTE_AFTER_CALL_INSN
)
8418 NOTE_DURING_CALL_P (note
) = true;
8422 /* Make sure that the call related notes come first. */
8423 while (NEXT_INSN (insn
)
8425 && ((NOTE_KIND (insn
) == NOTE_INSN_VAR_LOCATION
8426 && NOTE_DURING_CALL_P (insn
))
8427 || NOTE_KIND (insn
) == NOTE_INSN_CALL_ARG_LOCATION
))
8428 insn
= NEXT_INSN (insn
);
8430 && ((NOTE_KIND (insn
) == NOTE_INSN_VAR_LOCATION
8431 && NOTE_DURING_CALL_P (insn
))
8432 || NOTE_KIND (insn
) == NOTE_INSN_CALL_ARG_LOCATION
))
8433 note
= emit_note_after (NOTE_INSN_VAR_LOCATION
, insn
);
8435 note
= emit_note_before (NOTE_INSN_VAR_LOCATION
, insn
);
8437 NOTE_VAR_LOCATION (note
) = note_vl
;
8439 set_dv_changed (var
->dv
, false);
8440 gcc_assert (var
->in_changed_variables
);
8441 var
->in_changed_variables
= false;
8442 htab_clear_slot (changed_variables
, varp
);
8444 /* Continue traversing the hash table. */
8448 /* While traversing changed_variables, push onto DATA (a stack of RTX
8449 values) entries that aren't user variables. */
8452 values_to_stack (void **slot
, void *data
)
8454 VEC (rtx
, stack
) **changed_values_stack
= (VEC (rtx
, stack
) **)data
;
8455 variable var
= (variable
) *slot
;
8457 if (var
->onepart
== ONEPART_VALUE
)
8458 VEC_safe_push (rtx
, stack
, *changed_values_stack
, dv_as_value (var
->dv
));
8459 else if (var
->onepart
== ONEPART_DEXPR
)
8460 VEC_safe_push (rtx
, stack
, *changed_values_stack
,
8461 DECL_RTL_KNOWN_SET (dv_as_decl (var
->dv
)));
8466 /* Remove from changed_variables the entry whose DV corresponds to
8467 value or debug_expr VAL. */
8469 remove_value_from_changed_variables (rtx val
)
8471 decl_or_value dv
= dv_from_rtx (val
);
8475 slot
= htab_find_slot_with_hash (changed_variables
,
8476 dv
, dv_htab_hash (dv
), NO_INSERT
);
8477 var
= (variable
) *slot
;
8478 var
->in_changed_variables
= false;
8479 htab_clear_slot (changed_variables
, slot
);
8482 /* If VAL (a value or debug_expr) has backlinks to variables actively
8483 dependent on it in HTAB or in CHANGED_VARIABLES, mark them as
8484 changed, adding to CHANGED_VALUES_STACK any dependencies that may
8485 have dependencies of their own to notify. */
8488 notify_dependents_of_changed_value (rtx val
, htab_t htab
,
8489 VEC (rtx
, stack
) **changed_values_stack
)
8494 decl_or_value dv
= dv_from_rtx (val
);
8496 slot
= htab_find_slot_with_hash (changed_variables
,
8497 dv
, dv_htab_hash (dv
), NO_INSERT
);
8499 slot
= htab_find_slot_with_hash (htab
,
8500 dv
, dv_htab_hash (dv
), NO_INSERT
);
8502 slot
= htab_find_slot_with_hash (dropped_values
,
8503 dv
, dv_htab_hash (dv
), NO_INSERT
);
8504 var
= (variable
) *slot
;
8506 while ((led
= VAR_LOC_DEP_LST (var
)))
8508 decl_or_value ldv
= led
->dv
;
8511 /* Deactivate and remove the backlink, as it was “used up”. It
8512 makes no sense to attempt to notify the same entity again:
8513 either it will be recomputed and re-register an active
8514 dependency, or it will still have the changed mark. */
8516 led
->next
->pprev
= led
->pprev
;
8518 *led
->pprev
= led
->next
;
8522 if (dv_changed_p (ldv
))
8525 switch (dv_onepart_p (ldv
))
8529 set_dv_changed (ldv
, true);
8530 VEC_safe_push (rtx
, stack
, *changed_values_stack
, dv_as_rtx (ldv
));
8534 ivar
= (variable
) htab_find_with_hash (htab
, ldv
, dv_htab_hash (ldv
));
8535 gcc_checking_assert (!VAR_LOC_DEP_LST (ivar
));
8536 variable_was_changed (ivar
, NULL
);
8540 pool_free (loc_exp_dep_pool
, led
);
8541 ivar
= (variable
) htab_find_with_hash (htab
, ldv
, dv_htab_hash (ldv
));
8544 int i
= ivar
->n_var_parts
;
8547 rtx loc
= ivar
->var_part
[i
].cur_loc
;
8549 if (loc
&& GET_CODE (loc
) == MEM
8550 && XEXP (loc
, 0) == val
)
8552 variable_was_changed (ivar
, NULL
);
8565 /* Take out of changed_variables any entries that don't refer to use
8566 variables. Back-propagate change notifications from values and
8567 debug_exprs to their active dependencies in HTAB or in
8568 CHANGED_VARIABLES. */
8571 process_changed_values (htab_t htab
)
8575 VEC (rtx
, stack
) *changed_values_stack
= VEC_alloc (rtx
, stack
, 20);
8577 /* Move values from changed_variables to changed_values_stack. */
8578 htab_traverse (changed_variables
, values_to_stack
, &changed_values_stack
);
8580 /* Back-propagate change notifications in values while popping
8581 them from the stack. */
8582 for (n
= i
= VEC_length (rtx
, changed_values_stack
);
8583 i
> 0; i
= VEC_length (rtx
, changed_values_stack
))
8585 val
= VEC_pop (rtx
, changed_values_stack
);
8586 notify_dependents_of_changed_value (val
, htab
, &changed_values_stack
);
8588 /* This condition will hold when visiting each of the entries
8589 originally in changed_variables. We can't remove them
8590 earlier because this could drop the backlinks before we got a
8591 chance to use them. */
8594 remove_value_from_changed_variables (val
);
8599 VEC_free (rtx
, stack
, changed_values_stack
);
8602 /* Emit NOTE_INSN_VAR_LOCATION note for each variable from a chain
8603 CHANGED_VARIABLES and delete this chain. WHERE specifies whether
8604 the notes shall be emitted before of after instruction INSN. */
8607 emit_notes_for_changes (rtx insn
, enum emit_note_where where
,
8610 emit_note_data data
;
8611 htab_t htab
= shared_hash_htab (vars
);
8613 if (!htab_elements (changed_variables
))
8616 if (MAY_HAVE_DEBUG_INSNS
)
8617 process_changed_values (htab
);
8623 htab_traverse (changed_variables
, emit_note_insn_var_location
, &data
);
8626 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it differs from the
8627 same variable in hash table DATA or is not there at all. */
8630 emit_notes_for_differences_1 (void **slot
, void *data
)
8632 htab_t new_vars
= (htab_t
) data
;
8633 variable old_var
, new_var
;
8635 old_var
= (variable
) *slot
;
8636 new_var
= (variable
) htab_find_with_hash (new_vars
, old_var
->dv
,
8637 dv_htab_hash (old_var
->dv
));
8641 /* Variable has disappeared. */
8642 variable empty_var
= NULL
;
8644 if (old_var
->onepart
== ONEPART_VALUE
8645 || old_var
->onepart
== ONEPART_DEXPR
)
8647 empty_var
= variable_from_dropped (old_var
->dv
, NO_INSERT
);
8650 gcc_checking_assert (!empty_var
->in_changed_variables
);
8651 if (!VAR_LOC_1PAUX (old_var
))
8653 VAR_LOC_1PAUX (old_var
) = VAR_LOC_1PAUX (empty_var
);
8654 VAR_LOC_1PAUX (empty_var
) = NULL
;
8657 gcc_checking_assert (!VAR_LOC_1PAUX (empty_var
));
8663 empty_var
= (variable
) pool_alloc (onepart_pool (old_var
->onepart
));
8664 empty_var
->dv
= old_var
->dv
;
8665 empty_var
->refcount
= 0;
8666 empty_var
->n_var_parts
= 0;
8667 empty_var
->onepart
= old_var
->onepart
;
8668 empty_var
->in_changed_variables
= false;
8671 if (empty_var
->onepart
)
8673 /* Propagate the auxiliary data to (ultimately)
8674 changed_variables. */
8675 empty_var
->var_part
[0].loc_chain
= NULL
;
8676 empty_var
->var_part
[0].cur_loc
= NULL
;
8677 VAR_LOC_1PAUX (empty_var
) = VAR_LOC_1PAUX (old_var
);
8678 VAR_LOC_1PAUX (old_var
) = NULL
;
8680 variable_was_changed (empty_var
, NULL
);
8681 /* Continue traversing the hash table. */
8684 /* Update cur_loc and one-part auxiliary data, before new_var goes
8685 through variable_was_changed. */
8686 if (old_var
!= new_var
&& new_var
->onepart
)
8688 gcc_checking_assert (VAR_LOC_1PAUX (new_var
) == NULL
);
8689 VAR_LOC_1PAUX (new_var
) = VAR_LOC_1PAUX (old_var
);
8690 VAR_LOC_1PAUX (old_var
) = NULL
;
8691 new_var
->var_part
[0].cur_loc
= old_var
->var_part
[0].cur_loc
;
8693 if (variable_different_p (old_var
, new_var
))
8694 variable_was_changed (new_var
, NULL
);
8696 /* Continue traversing the hash table. */
8700 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it is not in hash
8704 emit_notes_for_differences_2 (void **slot
, void *data
)
8706 htab_t old_vars
= (htab_t
) data
;
8707 variable old_var
, new_var
;
8709 new_var
= (variable
) *slot
;
8710 old_var
= (variable
) htab_find_with_hash (old_vars
, new_var
->dv
,
8711 dv_htab_hash (new_var
->dv
));
8715 for (i
= 0; i
< new_var
->n_var_parts
; i
++)
8716 new_var
->var_part
[i
].cur_loc
= NULL
;
8717 variable_was_changed (new_var
, NULL
);
8720 /* Continue traversing the hash table. */
8724 /* Emit notes before INSN for differences between dataflow sets OLD_SET and
8728 emit_notes_for_differences (rtx insn
, dataflow_set
*old_set
,
8729 dataflow_set
*new_set
)
8731 htab_traverse (shared_hash_htab (old_set
->vars
),
8732 emit_notes_for_differences_1
,
8733 shared_hash_htab (new_set
->vars
));
8734 htab_traverse (shared_hash_htab (new_set
->vars
),
8735 emit_notes_for_differences_2
,
8736 shared_hash_htab (old_set
->vars
));
8737 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
, new_set
->vars
);
8740 /* Return the next insn after INSN that is not a NOTE_INSN_VAR_LOCATION. */
8743 next_non_note_insn_var_location (rtx insn
)
8747 insn
= NEXT_INSN (insn
);
8750 || NOTE_KIND (insn
) != NOTE_INSN_VAR_LOCATION
)
8757 /* Emit the notes for changes of location parts in the basic block BB. */
8760 emit_notes_in_bb (basic_block bb
, dataflow_set
*set
)
8763 micro_operation
*mo
;
8765 dataflow_set_clear (set
);
8766 dataflow_set_copy (set
, &VTI (bb
)->in
);
8768 FOR_EACH_VEC_ELT (micro_operation
, VTI (bb
)->mos
, i
, mo
)
8770 rtx insn
= mo
->insn
;
8771 rtx next_insn
= next_non_note_insn_var_location (insn
);
8776 dataflow_set_clear_at_call (set
);
8777 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_CALL_INSN
, set
->vars
);
8779 rtx arguments
= mo
->u
.loc
, *p
= &arguments
, note
;
8782 XEXP (XEXP (*p
, 0), 1)
8783 = vt_expand_loc (XEXP (XEXP (*p
, 0), 1),
8784 shared_hash_htab (set
->vars
));
8785 /* If expansion is successful, keep it in the list. */
8786 if (XEXP (XEXP (*p
, 0), 1))
8788 /* Otherwise, if the following item is data_value for it,
8790 else if (XEXP (*p
, 1)
8791 && REG_P (XEXP (XEXP (*p
, 0), 0))
8792 && MEM_P (XEXP (XEXP (XEXP (*p
, 1), 0), 0))
8793 && REG_P (XEXP (XEXP (XEXP (XEXP (*p
, 1), 0), 0),
8795 && REGNO (XEXP (XEXP (*p
, 0), 0))
8796 == REGNO (XEXP (XEXP (XEXP (XEXP (*p
, 1), 0),
8798 *p
= XEXP (XEXP (*p
, 1), 1);
8799 /* Just drop this item. */
8803 note
= emit_note_after (NOTE_INSN_CALL_ARG_LOCATION
, insn
);
8804 NOTE_VAR_LOCATION (note
) = arguments
;
8810 rtx loc
= mo
->u
.loc
;
8813 var_reg_set (set
, loc
, VAR_INIT_STATUS_UNINITIALIZED
, NULL
);
8815 var_mem_set (set
, loc
, VAR_INIT_STATUS_UNINITIALIZED
, NULL
);
8817 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
, set
->vars
);
8823 rtx loc
= mo
->u
.loc
;
8827 if (GET_CODE (loc
) == CONCAT
)
8829 val
= XEXP (loc
, 0);
8830 vloc
= XEXP (loc
, 1);
8838 var
= PAT_VAR_LOCATION_DECL (vloc
);
8840 clobber_variable_part (set
, NULL_RTX
,
8841 dv_from_decl (var
), 0, NULL_RTX
);
8844 if (VAL_NEEDS_RESOLUTION (loc
))
8845 val_resolve (set
, val
, PAT_VAR_LOCATION_LOC (vloc
), insn
);
8846 set_variable_part (set
, val
, dv_from_decl (var
), 0,
8847 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
,
8850 else if (!VAR_LOC_UNKNOWN_P (PAT_VAR_LOCATION_LOC (vloc
)))
8851 set_variable_part (set
, PAT_VAR_LOCATION_LOC (vloc
),
8852 dv_from_decl (var
), 0,
8853 VAR_INIT_STATUS_INITIALIZED
, NULL_RTX
,
8856 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
, set
->vars
);
8862 rtx loc
= mo
->u
.loc
;
8863 rtx val
, vloc
, uloc
;
8865 vloc
= uloc
= XEXP (loc
, 1);
8866 val
= XEXP (loc
, 0);
8868 if (GET_CODE (val
) == CONCAT
)
8870 uloc
= XEXP (val
, 1);
8871 val
= XEXP (val
, 0);
8874 if (VAL_NEEDS_RESOLUTION (loc
))
8875 val_resolve (set
, val
, vloc
, insn
);
8877 val_store (set
, val
, uloc
, insn
, false);
8879 if (VAL_HOLDS_TRACK_EXPR (loc
))
8881 if (GET_CODE (uloc
) == REG
)
8882 var_reg_set (set
, uloc
, VAR_INIT_STATUS_UNINITIALIZED
,
8884 else if (GET_CODE (uloc
) == MEM
)
8885 var_mem_set (set
, uloc
, VAR_INIT_STATUS_UNINITIALIZED
,
8889 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
, set
->vars
);
8895 rtx loc
= mo
->u
.loc
;
8896 rtx val
, vloc
, uloc
;
8900 uloc
= XEXP (vloc
, 1);
8901 val
= XEXP (vloc
, 0);
8904 if (GET_CODE (uloc
) == SET
)
8906 dstv
= SET_DEST (uloc
);
8907 srcv
= SET_SRC (uloc
);
8915 if (GET_CODE (val
) == CONCAT
)
8917 dstv
= vloc
= XEXP (val
, 1);
8918 val
= XEXP (val
, 0);
8921 if (GET_CODE (vloc
) == SET
)
8923 srcv
= SET_SRC (vloc
);
8925 gcc_assert (val
!= srcv
);
8926 gcc_assert (vloc
== uloc
|| VAL_NEEDS_RESOLUTION (loc
));
8928 dstv
= vloc
= SET_DEST (vloc
);
8930 if (VAL_NEEDS_RESOLUTION (loc
))
8931 val_resolve (set
, val
, srcv
, insn
);
8933 else if (VAL_NEEDS_RESOLUTION (loc
))
8935 gcc_assert (GET_CODE (uloc
) == SET
8936 && GET_CODE (SET_SRC (uloc
)) == REG
);
8937 val_resolve (set
, val
, SET_SRC (uloc
), insn
);
8940 if (VAL_HOLDS_TRACK_EXPR (loc
))
8942 if (VAL_EXPR_IS_CLOBBERED (loc
))
8945 var_reg_delete (set
, uloc
, true);
8946 else if (MEM_P (uloc
))
8948 gcc_assert (MEM_P (dstv
));
8949 gcc_assert (MEM_ATTRS (dstv
) == MEM_ATTRS (uloc
));
8950 var_mem_delete (set
, dstv
, true);
8955 bool copied_p
= VAL_EXPR_IS_COPIED (loc
);
8956 rtx src
= NULL
, dst
= uloc
;
8957 enum var_init_status status
= VAR_INIT_STATUS_INITIALIZED
;
8959 if (GET_CODE (uloc
) == SET
)
8961 src
= SET_SRC (uloc
);
8962 dst
= SET_DEST (uloc
);
8967 status
= find_src_status (set
, src
);
8969 src
= find_src_set_src (set
, src
);
8973 var_reg_delete_and_set (set
, dst
, !copied_p
,
8975 else if (MEM_P (dst
))
8977 gcc_assert (MEM_P (dstv
));
8978 gcc_assert (MEM_ATTRS (dstv
) == MEM_ATTRS (dst
));
8979 var_mem_delete_and_set (set
, dstv
, !copied_p
,
8984 else if (REG_P (uloc
))
8985 var_regno_delete (set
, REGNO (uloc
));
8986 else if (MEM_P (uloc
))
8987 clobber_overlapping_mems (set
, uloc
);
8989 val_store (set
, val
, dstv
, insn
, true);
8991 emit_notes_for_changes (next_insn
, EMIT_NOTE_BEFORE_INSN
,
8998 rtx loc
= mo
->u
.loc
;
9001 if (GET_CODE (loc
) == SET
)
9003 set_src
= SET_SRC (loc
);
9004 loc
= SET_DEST (loc
);
9008 var_reg_delete_and_set (set
, loc
, true, VAR_INIT_STATUS_INITIALIZED
,
9011 var_mem_delete_and_set (set
, loc
, true, VAR_INIT_STATUS_INITIALIZED
,
9014 emit_notes_for_changes (next_insn
, EMIT_NOTE_BEFORE_INSN
,
9021 rtx loc
= mo
->u
.loc
;
9022 enum var_init_status src_status
;
9025 if (GET_CODE (loc
) == SET
)
9027 set_src
= SET_SRC (loc
);
9028 loc
= SET_DEST (loc
);
9031 src_status
= find_src_status (set
, set_src
);
9032 set_src
= find_src_set_src (set
, set_src
);
9035 var_reg_delete_and_set (set
, loc
, false, src_status
, set_src
);
9037 var_mem_delete_and_set (set
, loc
, false, src_status
, set_src
);
9039 emit_notes_for_changes (next_insn
, EMIT_NOTE_BEFORE_INSN
,
9046 rtx loc
= mo
->u
.loc
;
9049 var_reg_delete (set
, loc
, false);
9051 var_mem_delete (set
, loc
, false);
9053 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
, set
->vars
);
9059 rtx loc
= mo
->u
.loc
;
9062 var_reg_delete (set
, loc
, true);
9064 var_mem_delete (set
, loc
, true);
9066 emit_notes_for_changes (next_insn
, EMIT_NOTE_BEFORE_INSN
,
9072 set
->stack_adjust
+= mo
->u
.adjust
;
9078 /* Emit notes for the whole function. */
9081 vt_emit_notes (void)
9086 gcc_assert (!htab_elements (changed_variables
));
9088 /* Free memory occupied by the out hash tables, as they aren't used
9091 dataflow_set_clear (&VTI (bb
)->out
);
9093 /* Enable emitting notes by functions (mainly by set_variable_part and
9094 delete_variable_part). */
9097 if (MAY_HAVE_DEBUG_INSNS
)
9099 dropped_values
= htab_create (cselib_get_next_uid () * 2,
9100 variable_htab_hash
, variable_htab_eq
,
9101 variable_htab_free
);
9102 loc_exp_dep_pool
= create_alloc_pool ("loc_exp_dep pool",
9103 sizeof (loc_exp_dep
), 64);
9106 dataflow_set_init (&cur
);
9110 /* Emit the notes for changes of variable locations between two
9111 subsequent basic blocks. */
9112 emit_notes_for_differences (BB_HEAD (bb
), &cur
, &VTI (bb
)->in
);
9114 /* Emit the notes for the changes in the basic block itself. */
9115 emit_notes_in_bb (bb
, &cur
);
9117 /* Free memory occupied by the in hash table, we won't need it
9119 dataflow_set_clear (&VTI (bb
)->in
);
9121 #ifdef ENABLE_CHECKING
9122 htab_traverse (shared_hash_htab (cur
.vars
),
9123 emit_notes_for_differences_1
,
9124 shared_hash_htab (empty_shared_hash
));
9126 dataflow_set_destroy (&cur
);
9128 if (MAY_HAVE_DEBUG_INSNS
)
9130 free_alloc_pool (loc_exp_dep_pool
);
9131 loc_exp_dep_pool
= NULL
;
9132 htab_delete (dropped_values
);
9138 /* If there is a declaration and offset associated with register/memory RTL
9139 assign declaration to *DECLP and offset to *OFFSETP, and return true. */
9142 vt_get_decl_and_offset (rtx rtl
, tree
*declp
, HOST_WIDE_INT
*offsetp
)
9146 if (REG_ATTRS (rtl
))
9148 *declp
= REG_EXPR (rtl
);
9149 *offsetp
= REG_OFFSET (rtl
);
9153 else if (MEM_P (rtl
))
9155 if (MEM_ATTRS (rtl
))
9157 *declp
= MEM_EXPR (rtl
);
9158 *offsetp
= INT_MEM_OFFSET (rtl
);
9165 /* Record the value for the ENTRY_VALUE of RTL as a global equivalence
9169 record_entry_value (cselib_val
*val
, rtx rtl
)
9171 rtx ev
= gen_rtx_ENTRY_VALUE (GET_MODE (rtl
));
9173 ENTRY_VALUE_EXP (ev
) = rtl
;
9175 cselib_add_permanent_equiv (val
, ev
, get_insns ());
9178 /* Insert function parameter PARM in IN and OUT sets of ENTRY_BLOCK. */
9181 vt_add_function_parameter (tree parm
)
9183 rtx decl_rtl
= DECL_RTL_IF_SET (parm
);
9184 rtx incoming
= DECL_INCOMING_RTL (parm
);
9186 enum machine_mode mode
;
9187 HOST_WIDE_INT offset
;
9191 if (TREE_CODE (parm
) != PARM_DECL
)
9194 if (!decl_rtl
|| !incoming
)
9197 if (GET_MODE (decl_rtl
) == BLKmode
|| GET_MODE (incoming
) == BLKmode
)
9200 /* If there is a DRAP register, rewrite the incoming location of parameters
9201 passed on the stack into MEMs based on the argument pointer, as the DRAP
9202 register can be reused for other purposes and we do not track locations
9203 based on generic registers. But the prerequisite is that this argument
9204 pointer be also the virtual CFA pointer, see vt_initialize. */
9205 if (MEM_P (incoming
)
9206 && stack_realign_drap
9207 && arg_pointer_rtx
== cfa_base_rtx
9208 && (XEXP (incoming
, 0) == crtl
->args
.internal_arg_pointer
9209 || (GET_CODE (XEXP (incoming
, 0)) == PLUS
9210 && XEXP (XEXP (incoming
, 0), 0)
9211 == crtl
->args
.internal_arg_pointer
9212 && CONST_INT_P (XEXP (XEXP (incoming
, 0), 1)))))
9214 HOST_WIDE_INT off
= -FIRST_PARM_OFFSET (current_function_decl
);
9215 if (GET_CODE (XEXP (incoming
, 0)) == PLUS
)
9216 off
+= INTVAL (XEXP (XEXP (incoming
, 0), 1));
9218 = replace_equiv_address_nv (incoming
,
9219 plus_constant (Pmode
,
9220 arg_pointer_rtx
, off
));
9223 #ifdef HAVE_window_save
9224 /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
9225 If the target machine has an explicit window save instruction, the
9226 actual entry value is the corresponding OUTGOING_REGNO instead. */
9227 if (REG_P (incoming
)
9228 && HARD_REGISTER_P (incoming
)
9229 && OUTGOING_REGNO (REGNO (incoming
)) != REGNO (incoming
))
9232 = VEC_safe_push (parm_reg_t
, gc
, windowed_parm_regs
, NULL
);
9233 p
->incoming
= incoming
;
9235 = gen_rtx_REG_offset (incoming
, GET_MODE (incoming
),
9236 OUTGOING_REGNO (REGNO (incoming
)), 0);
9237 p
->outgoing
= incoming
;
9239 else if (MEM_P (incoming
)
9240 && REG_P (XEXP (incoming
, 0))
9241 && HARD_REGISTER_P (XEXP (incoming
, 0)))
9243 rtx reg
= XEXP (incoming
, 0);
9244 if (OUTGOING_REGNO (REGNO (reg
)) != REGNO (reg
))
9247 = VEC_safe_push (parm_reg_t
, gc
, windowed_parm_regs
, NULL
);
9249 reg
= gen_raw_REG (GET_MODE (reg
), OUTGOING_REGNO (REGNO (reg
)));
9251 incoming
= replace_equiv_address_nv (incoming
, reg
);
9256 if (!vt_get_decl_and_offset (incoming
, &decl
, &offset
))
9258 if (REG_P (incoming
) || MEM_P (incoming
))
9260 /* This means argument is passed by invisible reference. */
9263 incoming
= gen_rtx_MEM (GET_MODE (decl_rtl
), incoming
);
9267 if (!vt_get_decl_and_offset (decl_rtl
, &decl
, &offset
))
9269 offset
+= byte_lowpart_offset (GET_MODE (incoming
),
9270 GET_MODE (decl_rtl
));
9279 /* Assume that DECL_RTL was a pseudo that got spilled to
9280 memory. The spill slot sharing code will force the
9281 memory to reference spill_slot_decl (%sfp), so we don't
9282 match above. That's ok, the pseudo must have referenced
9283 the entire parameter, so just reset OFFSET. */
9284 gcc_assert (decl
== get_spill_slot_decl (false));
9288 if (!track_loc_p (incoming
, parm
, offset
, false, &mode
, &offset
))
9291 out
= &VTI (ENTRY_BLOCK_PTR
)->out
;
9293 dv
= dv_from_decl (parm
);
9295 if (target_for_debug_bind (parm
)
9296 /* We can't deal with these right now, because this kind of
9297 variable is single-part. ??? We could handle parallels
9298 that describe multiple locations for the same single
9299 value, but ATM we don't. */
9300 && GET_CODE (incoming
) != PARALLEL
)
9304 /* ??? We shouldn't ever hit this, but it may happen because
9305 arguments passed by invisible reference aren't dealt with
9306 above: incoming-rtl will have Pmode rather than the
9307 expected mode for the type. */
9311 val
= cselib_lookup_from_insn (var_lowpart (mode
, incoming
), mode
, true,
9312 VOIDmode
, get_insns ());
9314 /* ??? Float-typed values in memory are not handled by
9318 preserve_value (val
);
9319 set_variable_part (out
, val
->val_rtx
, dv
, offset
,
9320 VAR_INIT_STATUS_INITIALIZED
, NULL
, INSERT
);
9321 dv
= dv_from_value (val
->val_rtx
);
9325 if (REG_P (incoming
))
9327 incoming
= var_lowpart (mode
, incoming
);
9328 gcc_assert (REGNO (incoming
) < FIRST_PSEUDO_REGISTER
);
9329 attrs_list_insert (&out
->regs
[REGNO (incoming
)], dv
, offset
,
9331 set_variable_part (out
, incoming
, dv
, offset
,
9332 VAR_INIT_STATUS_INITIALIZED
, NULL
, INSERT
);
9333 if (dv_is_value_p (dv
))
9335 record_entry_value (CSELIB_VAL_PTR (dv_as_value (dv
)), incoming
);
9336 if (TREE_CODE (TREE_TYPE (parm
)) == REFERENCE_TYPE
9337 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (parm
))))
9339 enum machine_mode indmode
9340 = TYPE_MODE (TREE_TYPE (TREE_TYPE (parm
)));
9341 rtx mem
= gen_rtx_MEM (indmode
, incoming
);
9342 cselib_val
*val
= cselib_lookup_from_insn (mem
, indmode
, true,
9347 preserve_value (val
);
9348 record_entry_value (val
, mem
);
9349 set_variable_part (out
, mem
, dv_from_value (val
->val_rtx
), 0,
9350 VAR_INIT_STATUS_INITIALIZED
, NULL
, INSERT
);
9355 else if (MEM_P (incoming
))
9357 incoming
= var_lowpart (mode
, incoming
);
9358 set_variable_part (out
, incoming
, dv
, offset
,
9359 VAR_INIT_STATUS_INITIALIZED
, NULL
, INSERT
);
9363 /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK. */
9366 vt_add_function_parameters (void)
9370 for (parm
= DECL_ARGUMENTS (current_function_decl
);
9371 parm
; parm
= DECL_CHAIN (parm
))
9372 vt_add_function_parameter (parm
);
9374 if (DECL_HAS_VALUE_EXPR_P (DECL_RESULT (current_function_decl
)))
9376 tree vexpr
= DECL_VALUE_EXPR (DECL_RESULT (current_function_decl
));
9378 if (TREE_CODE (vexpr
) == INDIRECT_REF
)
9379 vexpr
= TREE_OPERAND (vexpr
, 0);
9381 if (TREE_CODE (vexpr
) == PARM_DECL
9382 && DECL_ARTIFICIAL (vexpr
)
9383 && !DECL_IGNORED_P (vexpr
)
9384 && DECL_NAMELESS (vexpr
))
9385 vt_add_function_parameter (vexpr
);
9389 /* Return true if INSN in the prologue initializes hard_frame_pointer_rtx. */
9392 fp_setter (rtx insn
)
9394 rtx pat
= PATTERN (insn
);
9395 if (RTX_FRAME_RELATED_P (insn
))
9397 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
9399 pat
= XEXP (expr
, 0);
9401 if (GET_CODE (pat
) == SET
)
9402 return SET_DEST (pat
) == hard_frame_pointer_rtx
;
9403 else if (GET_CODE (pat
) == PARALLEL
)
9406 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; i
--)
9407 if (GET_CODE (XVECEXP (pat
, 0, i
)) == SET
9408 && SET_DEST (XVECEXP (pat
, 0, i
)) == hard_frame_pointer_rtx
)
9414 /* Initialize cfa_base_rtx, create a preserved VALUE for it and
9415 ensure it isn't flushed during cselib_reset_table.
9416 Can be called only if frame_pointer_rtx resp. arg_pointer_rtx
9417 has been eliminated. */
9420 vt_init_cfa_base (void)
9424 #ifdef FRAME_POINTER_CFA_OFFSET
9425 cfa_base_rtx
= frame_pointer_rtx
;
9426 cfa_base_offset
= -FRAME_POINTER_CFA_OFFSET (current_function_decl
);
9428 cfa_base_rtx
= arg_pointer_rtx
;
9429 cfa_base_offset
= -ARG_POINTER_CFA_OFFSET (current_function_decl
);
9431 if (cfa_base_rtx
== hard_frame_pointer_rtx
9432 || !fixed_regs
[REGNO (cfa_base_rtx
)])
9434 cfa_base_rtx
= NULL_RTX
;
9437 if (!MAY_HAVE_DEBUG_INSNS
)
9440 /* Tell alias analysis that cfa_base_rtx should share
9441 find_base_term value with stack pointer or hard frame pointer. */
9442 if (!frame_pointer_needed
)
9443 vt_equate_reg_base_value (cfa_base_rtx
, stack_pointer_rtx
);
9444 else if (!crtl
->stack_realign_tried
)
9445 vt_equate_reg_base_value (cfa_base_rtx
, hard_frame_pointer_rtx
);
9447 val
= cselib_lookup_from_insn (cfa_base_rtx
, GET_MODE (cfa_base_rtx
), 1,
9448 VOIDmode
, get_insns ());
9449 preserve_value (val
);
9450 cselib_preserve_cfa_base_value (val
, REGNO (cfa_base_rtx
));
9451 var_reg_decl_set (&VTI (ENTRY_BLOCK_PTR
)->out
, cfa_base_rtx
,
9452 VAR_INIT_STATUS_INITIALIZED
, dv_from_value (val
->val_rtx
),
9453 0, NULL_RTX
, INSERT
);
9456 /* Allocate and initialize the data structures for variable tracking
9457 and parse the RTL to get the micro operations. */
9460 vt_initialize (void)
9462 basic_block bb
, prologue_bb
= single_succ (ENTRY_BLOCK_PTR
);
9463 HOST_WIDE_INT fp_cfa_offset
= -1;
9465 alloc_aux_for_blocks (sizeof (struct variable_tracking_info_def
));
9467 attrs_pool
= create_alloc_pool ("attrs_def pool",
9468 sizeof (struct attrs_def
), 1024);
9469 var_pool
= create_alloc_pool ("variable_def pool",
9470 sizeof (struct variable_def
)
9471 + (MAX_VAR_PARTS
- 1)
9472 * sizeof (((variable
)NULL
)->var_part
[0]), 64);
9473 loc_chain_pool
= create_alloc_pool ("location_chain_def pool",
9474 sizeof (struct location_chain_def
),
9476 shared_hash_pool
= create_alloc_pool ("shared_hash_def pool",
9477 sizeof (struct shared_hash_def
), 256);
9478 empty_shared_hash
= (shared_hash
) pool_alloc (shared_hash_pool
);
9479 empty_shared_hash
->refcount
= 1;
9480 empty_shared_hash
->htab
9481 = htab_create (1, variable_htab_hash
, variable_htab_eq
,
9482 variable_htab_free
);
9483 changed_variables
= htab_create (10, variable_htab_hash
, variable_htab_eq
,
9484 variable_htab_free
);
9486 /* Init the IN and OUT sets. */
9489 VTI (bb
)->visited
= false;
9490 VTI (bb
)->flooded
= false;
9491 dataflow_set_init (&VTI (bb
)->in
);
9492 dataflow_set_init (&VTI (bb
)->out
);
9493 VTI (bb
)->permp
= NULL
;
9496 if (MAY_HAVE_DEBUG_INSNS
)
9498 cselib_init (CSELIB_RECORD_MEMORY
| CSELIB_PRESERVE_CONSTANTS
);
9499 scratch_regs
= BITMAP_ALLOC (NULL
);
9500 valvar_pool
= create_alloc_pool ("small variable_def pool",
9501 sizeof (struct variable_def
), 256);
9502 preserved_values
= VEC_alloc (rtx
, heap
, 256);
9506 scratch_regs
= NULL
;
9510 /* In order to factor out the adjustments made to the stack pointer or to
9511 the hard frame pointer and thus be able to use DW_OP_fbreg operations
9512 instead of individual location lists, we're going to rewrite MEMs based
9513 on them into MEMs based on the CFA by de-eliminating stack_pointer_rtx
9514 or hard_frame_pointer_rtx to the virtual CFA pointer frame_pointer_rtx
9515 resp. arg_pointer_rtx. We can do this either when there is no frame
9516 pointer in the function and stack adjustments are consistent for all
9517 basic blocks or when there is a frame pointer and no stack realignment.
9518 But we first have to check that frame_pointer_rtx resp. arg_pointer_rtx
9519 has been eliminated. */
9520 if (!frame_pointer_needed
)
9524 if (!vt_stack_adjustments ())
9527 #ifdef FRAME_POINTER_CFA_OFFSET
9528 reg
= frame_pointer_rtx
;
9530 reg
= arg_pointer_rtx
;
9532 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
9535 if (GET_CODE (elim
) == PLUS
)
9536 elim
= XEXP (elim
, 0);
9537 if (elim
== stack_pointer_rtx
)
9538 vt_init_cfa_base ();
9541 else if (!crtl
->stack_realign_tried
)
9545 #ifdef FRAME_POINTER_CFA_OFFSET
9546 reg
= frame_pointer_rtx
;
9547 fp_cfa_offset
= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
9549 reg
= arg_pointer_rtx
;
9550 fp_cfa_offset
= ARG_POINTER_CFA_OFFSET (current_function_decl
);
9552 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
9555 if (GET_CODE (elim
) == PLUS
)
9557 fp_cfa_offset
-= INTVAL (XEXP (elim
, 1));
9558 elim
= XEXP (elim
, 0);
9560 if (elim
!= hard_frame_pointer_rtx
)
9567 /* If the stack is realigned and a DRAP register is used, we're going to
9568 rewrite MEMs based on it representing incoming locations of parameters
9569 passed on the stack into MEMs based on the argument pointer. Although
9570 we aren't going to rewrite other MEMs, we still need to initialize the
9571 virtual CFA pointer in order to ensure that the argument pointer will
9572 be seen as a constant throughout the function.
9574 ??? This doesn't work if FRAME_POINTER_CFA_OFFSET is defined. */
9575 else if (stack_realign_drap
)
9579 #ifdef FRAME_POINTER_CFA_OFFSET
9580 reg
= frame_pointer_rtx
;
9582 reg
= arg_pointer_rtx
;
9584 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
9587 if (GET_CODE (elim
) == PLUS
)
9588 elim
= XEXP (elim
, 0);
9589 if (elim
== hard_frame_pointer_rtx
)
9590 vt_init_cfa_base ();
9594 hard_frame_pointer_adjustment
= -1;
9596 vt_add_function_parameters ();
9601 HOST_WIDE_INT pre
, post
= 0;
9602 basic_block first_bb
, last_bb
;
9604 if (MAY_HAVE_DEBUG_INSNS
)
9606 cselib_record_sets_hook
= add_with_sets
;
9607 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
9608 fprintf (dump_file
, "first value: %i\n",
9609 cselib_get_next_uid ());
9616 if (bb
->next_bb
== EXIT_BLOCK_PTR
9617 || ! single_pred_p (bb
->next_bb
))
9619 e
= find_edge (bb
, bb
->next_bb
);
9620 if (! e
|| (e
->flags
& EDGE_FALLTHRU
) == 0)
9626 /* Add the micro-operations to the vector. */
9627 FOR_BB_BETWEEN (bb
, first_bb
, last_bb
->next_bb
, next_bb
)
9629 HOST_WIDE_INT offset
= VTI (bb
)->out
.stack_adjust
;
9630 VTI (bb
)->out
.stack_adjust
= VTI (bb
)->in
.stack_adjust
;
9631 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
9632 insn
= NEXT_INSN (insn
))
9636 if (!frame_pointer_needed
)
9638 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
9642 mo
.type
= MO_ADJUST
;
9645 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
9646 log_op_type (PATTERN (insn
), bb
, insn
,
9647 MO_ADJUST
, dump_file
);
9648 VEC_safe_push (micro_operation
, heap
, VTI (bb
)->mos
,
9650 VTI (bb
)->out
.stack_adjust
+= pre
;
9654 cselib_hook_called
= false;
9655 adjust_insn (bb
, insn
);
9656 if (MAY_HAVE_DEBUG_INSNS
)
9659 prepare_call_arguments (bb
, insn
);
9660 cselib_process_insn (insn
);
9661 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
9663 print_rtl_single (dump_file
, insn
);
9664 dump_cselib_table (dump_file
);
9667 if (!cselib_hook_called
)
9668 add_with_sets (insn
, 0, 0);
9671 if (!frame_pointer_needed
&& post
)
9674 mo
.type
= MO_ADJUST
;
9677 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
9678 log_op_type (PATTERN (insn
), bb
, insn
,
9679 MO_ADJUST
, dump_file
);
9680 VEC_safe_push (micro_operation
, heap
, VTI (bb
)->mos
,
9682 VTI (bb
)->out
.stack_adjust
+= post
;
9685 if (bb
== prologue_bb
9686 && fp_cfa_offset
!= -1
9687 && hard_frame_pointer_adjustment
== -1
9688 && RTX_FRAME_RELATED_P (insn
)
9689 && fp_setter (insn
))
9691 vt_init_cfa_base ();
9692 hard_frame_pointer_adjustment
= fp_cfa_offset
;
9696 gcc_assert (offset
== VTI (bb
)->out
.stack_adjust
);
9701 if (MAY_HAVE_DEBUG_INSNS
)
9703 cselib_preserve_only_values ();
9704 cselib_reset_table (cselib_get_next_uid ());
9705 cselib_record_sets_hook
= NULL
;
9709 hard_frame_pointer_adjustment
= -1;
9710 VTI (ENTRY_BLOCK_PTR
)->flooded
= true;
9711 cfa_base_rtx
= NULL_RTX
;
9715 /* This is *not* reset after each function. It gives each
9716 NOTE_INSN_DELETED_DEBUG_LABEL in the entire compilation
9717 a unique label number. */
9719 static int debug_label_num
= 1;
9721 /* Get rid of all debug insns from the insn stream. */
9724 delete_debug_insns (void)
9729 if (!MAY_HAVE_DEBUG_INSNS
)
9734 FOR_BB_INSNS_SAFE (bb
, insn
, next
)
9735 if (DEBUG_INSN_P (insn
))
9737 tree decl
= INSN_VAR_LOCATION_DECL (insn
);
9738 if (TREE_CODE (decl
) == LABEL_DECL
9740 && !DECL_RTL_SET_P (decl
))
9742 PUT_CODE (insn
, NOTE
);
9743 NOTE_KIND (insn
) = NOTE_INSN_DELETED_DEBUG_LABEL
;
9744 NOTE_DELETED_LABEL_NAME (insn
)
9745 = IDENTIFIER_POINTER (DECL_NAME (decl
));
9746 SET_DECL_RTL (decl
, insn
);
9747 CODE_LABEL_NUMBER (insn
) = debug_label_num
++;
9755 /* Run a fast, BB-local only version of var tracking, to take care of
9756 information that we don't do global analysis on, such that not all
9757 information is lost. If SKIPPED holds, we're skipping the global
9758 pass entirely, so we should try to use information it would have
9759 handled as well.. */
9762 vt_debug_insns_local (bool skipped ATTRIBUTE_UNUSED
)
9764 /* ??? Just skip it all for now. */
9765 delete_debug_insns ();
9768 /* Free the data structures needed for variable tracking. */
9777 VEC_free (micro_operation
, heap
, VTI (bb
)->mos
);
9782 dataflow_set_destroy (&VTI (bb
)->in
);
9783 dataflow_set_destroy (&VTI (bb
)->out
);
9784 if (VTI (bb
)->permp
)
9786 dataflow_set_destroy (VTI (bb
)->permp
);
9787 XDELETE (VTI (bb
)->permp
);
9790 free_aux_for_blocks ();
9791 htab_delete (empty_shared_hash
->htab
);
9792 htab_delete (changed_variables
);
9793 free_alloc_pool (attrs_pool
);
9794 free_alloc_pool (var_pool
);
9795 free_alloc_pool (loc_chain_pool
);
9796 free_alloc_pool (shared_hash_pool
);
9798 if (MAY_HAVE_DEBUG_INSNS
)
9800 free_alloc_pool (valvar_pool
);
9801 VEC_free (rtx
, heap
, preserved_values
);
9803 BITMAP_FREE (scratch_regs
);
9804 scratch_regs
= NULL
;
9807 #ifdef HAVE_window_save
9808 VEC_free (parm_reg_t
, gc
, windowed_parm_regs
);
9812 XDELETEVEC (vui_vec
);
9817 /* The entry point to variable tracking pass. */
9819 static inline unsigned int
9820 variable_tracking_main_1 (void)
9824 if (flag_var_tracking_assignments
< 0)
9826 delete_debug_insns ();
9830 if (n_basic_blocks
> 500 && n_edges
/ n_basic_blocks
>= 20)
9832 vt_debug_insns_local (true);
9836 mark_dfs_back_edges ();
9837 if (!vt_initialize ())
9840 vt_debug_insns_local (true);
9844 success
= vt_find_locations ();
9846 if (!success
&& flag_var_tracking_assignments
> 0)
9850 delete_debug_insns ();
9852 /* This is later restored by our caller. */
9853 flag_var_tracking_assignments
= 0;
9855 success
= vt_initialize ();
9856 gcc_assert (success
);
9858 success
= vt_find_locations ();
9864 vt_debug_insns_local (false);
9868 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
9870 dump_dataflow_sets ();
9871 dump_flow_info (dump_file
, dump_flags
);
9874 timevar_push (TV_VAR_TRACKING_EMIT
);
9876 timevar_pop (TV_VAR_TRACKING_EMIT
);
9879 vt_debug_insns_local (false);
9884 variable_tracking_main (void)
9887 int save
= flag_var_tracking_assignments
;
9889 ret
= variable_tracking_main_1 ();
9891 flag_var_tracking_assignments
= save
;
9897 gate_handle_var_tracking (void)
9899 return (flag_var_tracking
&& !targetm
.delay_vartrack
);
9904 struct rtl_opt_pass pass_variable_tracking
=
9908 "vartrack", /* name */
9909 gate_handle_var_tracking
, /* gate */
9910 variable_tracking_main
, /* execute */
9913 0, /* static_pass_number */
9914 TV_VAR_TRACKING
, /* tv_id */
9915 0, /* properties_required */
9916 0, /* properties_provided */
9917 0, /* properties_destroyed */
9918 0, /* todo_flags_start */
9919 TODO_verify_rtl_sharing
/* todo_flags_finish */