1 /* Variable tracking routines for the GNU compiler.
2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
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 < set < clobber < 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"
95 #include "hard-reg-set.h"
96 #include "basic-block.h"
99 #include "insn-config.h"
102 #include "alloc-pool.h"
108 #include "tree-pass.h"
110 /* Type of micro operation. */
111 enum micro_operation_type
113 MO_USE
, /* Use location (REG or MEM). */
114 MO_USE_NO_VAR
,/* Use location which is not associated with a variable
115 or the variable is not trackable. */
116 MO_SET
, /* Set location. */
117 MO_CLOBBER
, /* Clobber location. */
118 MO_CALL
, /* Call insn. */
119 MO_ADJUST
/* Adjust stack pointer. */
122 /* Where shall the note be emitted? BEFORE or AFTER the instruction. */
125 EMIT_NOTE_BEFORE_INSN
,
129 /* Structure holding information about micro operation. */
130 typedef struct micro_operation_def
132 /* Type of micro operation. */
133 enum micro_operation_type type
;
139 /* Stack adjustment. */
140 HOST_WIDE_INT adjust
;
143 /* The instruction which the micro operation is in. */
147 /* Structure for passing some other parameters to function
148 emit_note_insn_var_location. */
149 typedef struct emit_note_data_def
151 /* The instruction which the note will be emitted before/after. */
154 /* Where the note will be emitted (before/after insn)? */
155 enum emit_note_where where
;
158 /* Description of location of a part of a variable. The content of a physical
159 register is described by a chain of these structures.
160 The chains are pretty short (usually 1 or 2 elements) and thus
161 chain is the best data structure. */
162 typedef struct attrs_def
164 /* Pointer to next member of the list. */
165 struct attrs_def
*next
;
167 /* The rtx of register. */
170 /* The declaration corresponding to LOC. */
173 /* Offset from start of DECL. */
174 HOST_WIDE_INT offset
;
177 /* Structure holding the IN or OUT set for a basic block. */
178 typedef struct dataflow_set_def
180 /* Adjustment of stack offset. */
181 HOST_WIDE_INT stack_adjust
;
183 /* Attributes for registers (lists of attrs). */
184 attrs regs
[FIRST_PSEUDO_REGISTER
];
186 /* Variable locations. */
190 /* The structure (one for each basic block) containing the information
191 needed for variable tracking. */
192 typedef struct variable_tracking_info_def
194 /* Number of micro operations stored in the MOS array. */
197 /* The array of micro operations. */
198 micro_operation
*mos
;
200 /* The IN and OUT set for dataflow analysis. */
204 /* Has the block been visited in DFS? */
206 } *variable_tracking_info
;
208 /* Structure for chaining the locations. */
209 typedef struct location_chain_def
211 /* Next element in the chain. */
212 struct location_chain_def
*next
;
214 /* The location (REG or MEM). */
218 /* Structure describing one part of variable. */
219 typedef struct variable_part_def
221 /* Chain of locations of the part. */
222 location_chain loc_chain
;
224 /* Location which was last emitted to location list. */
227 /* The offset in the variable. */
228 HOST_WIDE_INT offset
;
231 /* Maximum number of location parts. */
232 #define MAX_VAR_PARTS 16
234 /* Structure describing where the variable is located. */
235 typedef struct variable_def
237 /* The declaration of the variable. */
240 /* Reference count. */
243 /* Number of variable parts. */
246 /* The variable parts. */
247 variable_part var_part
[MAX_VAR_PARTS
];
250 /* Hash function for DECL for VARIABLE_HTAB. */
251 #define VARIABLE_HASH_VAL(decl) (DECL_UID (decl))
253 /* Pointer to the BB's information specific to variable tracking pass. */
254 #define VTI(BB) ((variable_tracking_info) (BB)->aux)
256 /* Alloc pool for struct attrs_def. */
257 static alloc_pool attrs_pool
;
259 /* Alloc pool for struct variable_def. */
260 static alloc_pool var_pool
;
262 /* Alloc pool for struct location_chain_def. */
263 static alloc_pool loc_chain_pool
;
265 /* Changed variables, notes will be emitted for them. */
266 static htab_t changed_variables
;
268 /* Shall notes be emitted? */
269 static bool emit_notes
;
271 /* Local function prototypes. */
272 static void stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
274 static void insn_stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
276 static void bb_stack_adjust_offset (basic_block
);
277 static bool vt_stack_adjustments (void);
278 static rtx
adjust_stack_reference (rtx
, HOST_WIDE_INT
);
279 static hashval_t
variable_htab_hash (const void *);
280 static int variable_htab_eq (const void *, const void *);
281 static void variable_htab_free (void *);
283 static void init_attrs_list_set (attrs
*);
284 static void attrs_list_clear (attrs
*);
285 static attrs
attrs_list_member (attrs
, tree
, HOST_WIDE_INT
);
286 static void attrs_list_insert (attrs
*, tree
, HOST_WIDE_INT
, rtx
);
287 static void attrs_list_copy (attrs
*, attrs
);
288 static void attrs_list_union (attrs
*, attrs
);
290 static void vars_clear (htab_t
);
291 static variable
unshare_variable (dataflow_set
*set
, variable var
);
292 static int vars_copy_1 (void **, void *);
293 static void vars_copy (htab_t
, htab_t
);
294 static void var_reg_delete_and_set (dataflow_set
*, rtx
);
295 static void var_reg_delete (dataflow_set
*, rtx
);
296 static void var_regno_delete (dataflow_set
*, int);
297 static void var_mem_delete_and_set (dataflow_set
*, rtx
);
298 static void var_mem_delete (dataflow_set
*, rtx
);
300 static void dataflow_set_init (dataflow_set
*, int);
301 static void dataflow_set_clear (dataflow_set
*);
302 static void dataflow_set_copy (dataflow_set
*, dataflow_set
*);
303 static int variable_union_info_cmp_pos (const void *, const void *);
304 static int variable_union (void **, void *);
305 static void dataflow_set_union (dataflow_set
*, dataflow_set
*);
306 static bool variable_part_different_p (variable_part
*, variable_part
*);
307 static bool variable_different_p (variable
, variable
, bool);
308 static int dataflow_set_different_1 (void **, void *);
309 static int dataflow_set_different_2 (void **, void *);
310 static bool dataflow_set_different (dataflow_set
*, dataflow_set
*);
311 static void dataflow_set_destroy (dataflow_set
*);
313 static bool contains_symbol_ref (rtx
);
314 static bool track_expr_p (tree
);
315 static int count_uses (rtx
*, void *);
316 static void count_uses_1 (rtx
*, void *);
317 static void count_stores (rtx
, rtx
, void *);
318 static int add_uses (rtx
*, void *);
319 static void add_uses_1 (rtx
*, void *);
320 static void add_stores (rtx
, rtx
, void *);
321 static bool compute_bb_dataflow (basic_block
);
322 static void vt_find_locations (void);
324 static void dump_attrs_list (attrs
);
325 static int dump_variable (void **, void *);
326 static void dump_vars (htab_t
);
327 static void dump_dataflow_set (dataflow_set
*);
328 static void dump_dataflow_sets (void);
330 static void variable_was_changed (variable
, htab_t
);
331 static void set_variable_part (dataflow_set
*, rtx
, tree
, HOST_WIDE_INT
);
332 static void delete_variable_part (dataflow_set
*, rtx
, tree
, HOST_WIDE_INT
);
333 static int emit_note_insn_var_location (void **, void *);
334 static void emit_notes_for_changes (rtx
, enum emit_note_where
);
335 static int emit_notes_for_differences_1 (void **, void *);
336 static int emit_notes_for_differences_2 (void **, void *);
337 static void emit_notes_for_differences (rtx
, dataflow_set
*, dataflow_set
*);
338 static void emit_notes_in_bb (basic_block
);
339 static void vt_emit_notes (void);
341 static bool vt_get_decl_and_offset (rtx
, tree
*, HOST_WIDE_INT
*);
342 static void vt_add_function_parameters (void);
343 static void vt_initialize (void);
344 static void vt_finalize (void);
346 /* Given a SET, calculate the amount of stack adjustment it contains
347 PRE- and POST-modifying stack pointer.
348 This function is similar to stack_adjust_offset. */
351 stack_adjust_offset_pre_post (rtx pattern
, HOST_WIDE_INT
*pre
,
354 rtx src
= SET_SRC (pattern
);
355 rtx dest
= SET_DEST (pattern
);
358 if (dest
== stack_pointer_rtx
)
360 /* (set (reg sp) (plus (reg sp) (const_int))) */
361 code
= GET_CODE (src
);
362 if (! (code
== PLUS
|| code
== MINUS
)
363 || XEXP (src
, 0) != stack_pointer_rtx
364 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
368 *post
+= INTVAL (XEXP (src
, 1));
370 *post
-= INTVAL (XEXP (src
, 1));
372 else if (MEM_P (dest
))
374 /* (set (mem (pre_dec (reg sp))) (foo)) */
375 src
= XEXP (dest
, 0);
376 code
= GET_CODE (src
);
382 if (XEXP (src
, 0) == stack_pointer_rtx
)
384 rtx val
= XEXP (XEXP (src
, 1), 1);
385 /* We handle only adjustments by constant amount. */
386 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
&&
387 GET_CODE (val
) == CONST_INT
);
389 if (code
== PRE_MODIFY
)
390 *pre
-= INTVAL (val
);
392 *post
-= INTVAL (val
);
398 if (XEXP (src
, 0) == stack_pointer_rtx
)
400 *pre
+= GET_MODE_SIZE (GET_MODE (dest
));
406 if (XEXP (src
, 0) == stack_pointer_rtx
)
408 *post
+= GET_MODE_SIZE (GET_MODE (dest
));
414 if (XEXP (src
, 0) == stack_pointer_rtx
)
416 *pre
-= GET_MODE_SIZE (GET_MODE (dest
));
422 if (XEXP (src
, 0) == stack_pointer_rtx
)
424 *post
-= GET_MODE_SIZE (GET_MODE (dest
));
435 /* Given an INSN, calculate the amount of stack adjustment it contains
436 PRE- and POST-modifying stack pointer. */
439 insn_stack_adjust_offset_pre_post (rtx insn
, HOST_WIDE_INT
*pre
,
445 if (GET_CODE (PATTERN (insn
)) == SET
)
446 stack_adjust_offset_pre_post (PATTERN (insn
), pre
, post
);
447 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
448 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
452 /* There may be stack adjustments inside compound insns. Search
454 for ( i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
455 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
456 stack_adjust_offset_pre_post (XVECEXP (PATTERN (insn
), 0, i
),
461 /* Compute stack adjustment in basic block BB. */
464 bb_stack_adjust_offset (basic_block bb
)
466 HOST_WIDE_INT offset
;
469 offset
= VTI (bb
)->in
.stack_adjust
;
470 for (i
= 0; i
< VTI (bb
)->n_mos
; i
++)
472 if (VTI (bb
)->mos
[i
].type
== MO_ADJUST
)
473 offset
+= VTI (bb
)->mos
[i
].u
.adjust
;
474 else if (VTI (bb
)->mos
[i
].type
!= MO_CALL
)
476 if (MEM_P (VTI (bb
)->mos
[i
].u
.loc
))
478 VTI (bb
)->mos
[i
].u
.loc
479 = adjust_stack_reference (VTI (bb
)->mos
[i
].u
.loc
, -offset
);
483 VTI (bb
)->out
.stack_adjust
= offset
;
486 /* Compute stack adjustments for all blocks by traversing DFS tree.
487 Return true when the adjustments on all incoming edges are consistent.
488 Heavily borrowed from pre_and_rev_post_order_compute. */
491 vt_stack_adjustments (void)
493 edge_iterator
*stack
;
496 /* Initialize entry block. */
497 VTI (ENTRY_BLOCK_PTR
)->visited
= true;
498 VTI (ENTRY_BLOCK_PTR
)->out
.stack_adjust
= INCOMING_FRAME_SP_OFFSET
;
500 /* Allocate stack for back-tracking up CFG. */
501 stack
= xmalloc ((n_basic_blocks
+ 1) * sizeof (edge_iterator
));
504 /* Push the first edge on to the stack. */
505 stack
[sp
++] = ei_start (ENTRY_BLOCK_PTR
->succs
);
513 /* Look at the edge on the top of the stack. */
515 src
= ei_edge (ei
)->src
;
516 dest
= ei_edge (ei
)->dest
;
518 /* Check if the edge destination has been visited yet. */
519 if (!VTI (dest
)->visited
)
521 VTI (dest
)->visited
= true;
522 VTI (dest
)->in
.stack_adjust
= VTI (src
)->out
.stack_adjust
;
523 bb_stack_adjust_offset (dest
);
525 if (EDGE_COUNT (dest
->succs
) > 0)
526 /* Since the DEST node has been visited for the first
527 time, check its successors. */
528 stack
[sp
++] = ei_start (dest
->succs
);
532 /* Check whether the adjustments on the edges are the same. */
533 if (VTI (dest
)->in
.stack_adjust
!= VTI (src
)->out
.stack_adjust
)
539 if (! ei_one_before_end_p (ei
))
540 /* Go to the next edge. */
541 ei_next (&stack
[sp
- 1]);
543 /* Return to previous level if there are no more edges. */
552 /* Adjust stack reference MEM by ADJUSTMENT bytes and make it relative
553 to the argument pointer. Return the new rtx. */
556 adjust_stack_reference (rtx mem
, HOST_WIDE_INT adjustment
)
560 #ifdef FRAME_POINTER_CFA_OFFSET
561 adjustment
-= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
562 cfa
= plus_constant (frame_pointer_rtx
, adjustment
);
564 adjustment
-= ARG_POINTER_CFA_OFFSET (current_function_decl
);
565 cfa
= plus_constant (arg_pointer_rtx
, adjustment
);
568 addr
= replace_rtx (copy_rtx (XEXP (mem
, 0)), stack_pointer_rtx
, cfa
);
569 tmp
= simplify_rtx (addr
);
573 return replace_equiv_address_nv (mem
, addr
);
576 /* The hash function for variable_htab, computes the hash value
577 from the declaration of variable X. */
580 variable_htab_hash (const void *x
)
582 const variable v
= (const variable
) x
;
584 return (VARIABLE_HASH_VAL (v
->decl
));
587 /* Compare the declaration of variable X with declaration Y. */
590 variable_htab_eq (const void *x
, const void *y
)
592 const variable v
= (const variable
) x
;
593 const tree decl
= (const tree
) y
;
595 return (VARIABLE_HASH_VAL (v
->decl
) == VARIABLE_HASH_VAL (decl
));
598 /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
601 variable_htab_free (void *elem
)
604 variable var
= (variable
) elem
;
605 location_chain node
, next
;
607 gcc_assert (var
->refcount
> 0);
610 if (var
->refcount
> 0)
613 for (i
= 0; i
< var
->n_var_parts
; i
++)
615 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= next
)
618 pool_free (loc_chain_pool
, node
);
620 var
->var_part
[i
].loc_chain
= NULL
;
622 pool_free (var_pool
, var
);
625 /* Initialize the set (array) SET of attrs to empty lists. */
628 init_attrs_list_set (attrs
*set
)
632 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
636 /* Make the list *LISTP empty. */
639 attrs_list_clear (attrs
*listp
)
643 for (list
= *listp
; list
; list
= next
)
646 pool_free (attrs_pool
, list
);
651 /* Return true if the pair of DECL and OFFSET is the member of the LIST. */
654 attrs_list_member (attrs list
, tree decl
, HOST_WIDE_INT offset
)
656 for (; list
; list
= list
->next
)
657 if (list
->decl
== decl
&& list
->offset
== offset
)
662 /* Insert the triplet DECL, OFFSET, LOC to the list *LISTP. */
665 attrs_list_insert (attrs
*listp
, tree decl
, HOST_WIDE_INT offset
, rtx loc
)
669 list
= pool_alloc (attrs_pool
);
672 list
->offset
= offset
;
677 /* Copy all nodes from SRC and create a list *DSTP of the copies. */
680 attrs_list_copy (attrs
*dstp
, attrs src
)
684 attrs_list_clear (dstp
);
685 for (; src
; src
= src
->next
)
687 n
= pool_alloc (attrs_pool
);
690 n
->offset
= src
->offset
;
696 /* Add all nodes from SRC which are not in *DSTP to *DSTP. */
699 attrs_list_union (attrs
*dstp
, attrs src
)
701 for (; src
; src
= src
->next
)
703 if (!attrs_list_member (*dstp
, src
->decl
, src
->offset
))
704 attrs_list_insert (dstp
, src
->decl
, src
->offset
, src
->loc
);
708 /* Delete all variables from hash table VARS. */
711 vars_clear (htab_t vars
)
716 /* Return a copy of a variable VAR and insert it to dataflow set SET. */
719 unshare_variable (dataflow_set
*set
, variable var
)
725 new_var
= pool_alloc (var_pool
);
726 new_var
->decl
= var
->decl
;
727 new_var
->refcount
= 1;
729 new_var
->n_var_parts
= var
->n_var_parts
;
731 for (i
= 0; i
< var
->n_var_parts
; i
++)
734 location_chain
*nextp
;
736 new_var
->var_part
[i
].offset
= var
->var_part
[i
].offset
;
737 nextp
= &new_var
->var_part
[i
].loc_chain
;
738 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
740 location_chain new_lc
;
742 new_lc
= pool_alloc (loc_chain_pool
);
744 new_lc
->loc
= node
->loc
;
747 nextp
= &new_lc
->next
;
750 /* We are at the basic block boundary when copying variable description
751 so set the CUR_LOC to be the first element of the chain. */
752 if (new_var
->var_part
[i
].loc_chain
)
753 new_var
->var_part
[i
].cur_loc
= new_var
->var_part
[i
].loc_chain
->loc
;
755 new_var
->var_part
[i
].cur_loc
= NULL
;
758 slot
= htab_find_slot_with_hash (set
->vars
, new_var
->decl
,
759 VARIABLE_HASH_VAL (new_var
->decl
),
765 /* Add a variable from *SLOT to hash table DATA and increase its reference
769 vars_copy_1 (void **slot
, void *data
)
771 htab_t dst
= (htab_t
) data
;
774 src
= *(variable
*) slot
;
777 dstp
= (variable
*) htab_find_slot_with_hash (dst
, src
->decl
,
778 VARIABLE_HASH_VAL (src
->decl
),
782 /* Continue traversing the hash table. */
786 /* Copy all variables from hash table SRC to hash table DST. */
789 vars_copy (htab_t dst
, htab_t src
)
792 htab_traverse (src
, vars_copy_1
, dst
);
795 /* Delete current content of register LOC in dataflow set SET
796 and set the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). */
799 var_reg_delete_and_set (dataflow_set
*set
, rtx loc
)
801 tree decl
= REG_EXPR (loc
);
802 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
806 nextp
= &set
->regs
[REGNO (loc
)];
807 for (node
= *nextp
; node
; node
= next
)
810 if (node
->decl
!= decl
|| node
->offset
!= offset
)
812 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
813 pool_free (attrs_pool
, node
);
822 if (set
->regs
[REGNO (loc
)] == NULL
)
823 attrs_list_insert (&set
->regs
[REGNO (loc
)], decl
, offset
, loc
);
824 set_variable_part (set
, loc
, decl
, offset
);
827 /* Delete current content of register LOC in dataflow set SET. */
830 var_reg_delete (dataflow_set
*set
, rtx loc
)
832 attrs
*reg
= &set
->regs
[REGNO (loc
)];
835 for (node
= *reg
; node
; node
= next
)
838 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
839 pool_free (attrs_pool
, node
);
844 /* Delete content of register with number REGNO in dataflow set SET. */
847 var_regno_delete (dataflow_set
*set
, int regno
)
849 attrs
*reg
= &set
->regs
[regno
];
852 for (node
= *reg
; node
; node
= next
)
855 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
856 pool_free (attrs_pool
, node
);
861 /* Delete and set the location part of variable MEM_EXPR (LOC)
862 in dataflow set SET to LOC.
863 Adjust the address first if it is stack pointer based. */
866 var_mem_delete_and_set (dataflow_set
*set
, rtx loc
)
868 tree decl
= MEM_EXPR (loc
);
869 HOST_WIDE_INT offset
= MEM_OFFSET (loc
) ? INTVAL (MEM_OFFSET (loc
)) : 0;
871 set_variable_part (set
, loc
, decl
, offset
);
874 /* Delete the location part LOC from dataflow set SET.
875 Adjust the address first if it is stack pointer based. */
878 var_mem_delete (dataflow_set
*set
, rtx loc
)
880 tree decl
= MEM_EXPR (loc
);
881 HOST_WIDE_INT offset
= MEM_OFFSET (loc
) ? INTVAL (MEM_OFFSET (loc
)) : 0;
883 delete_variable_part (set
, loc
, decl
, offset
);
886 /* Initialize dataflow set SET to be empty.
887 VARS_SIZE is the initial size of hash table VARS. */
890 dataflow_set_init (dataflow_set
*set
, int vars_size
)
892 init_attrs_list_set (set
->regs
);
893 set
->vars
= htab_create (vars_size
, variable_htab_hash
, variable_htab_eq
,
895 set
->stack_adjust
= 0;
898 /* Delete the contents of dataflow set SET. */
901 dataflow_set_clear (dataflow_set
*set
)
905 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
906 attrs_list_clear (&set
->regs
[i
]);
908 vars_clear (set
->vars
);
911 /* Copy the contents of dataflow set SRC to DST. */
914 dataflow_set_copy (dataflow_set
*dst
, dataflow_set
*src
)
918 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
919 attrs_list_copy (&dst
->regs
[i
], src
->regs
[i
]);
921 vars_copy (dst
->vars
, src
->vars
);
922 dst
->stack_adjust
= src
->stack_adjust
;
925 /* Information for merging lists of locations for a given offset of variable.
927 struct variable_union_info
929 /* Node of the location chain. */
932 /* The sum of positions in the input chains. */
935 /* The position in the chains of SRC and DST dataflow sets. */
940 /* Compare function for qsort, order the structures by POS element. */
943 variable_union_info_cmp_pos (const void *n1
, const void *n2
)
945 const struct variable_union_info
*i1
= n1
;
946 const struct variable_union_info
*i2
= n2
;
948 if (i1
->pos
!= i2
->pos
)
949 return i1
->pos
- i2
->pos
;
951 return (i1
->pos_dst
- i2
->pos_dst
);
954 /* Compute union of location parts of variable *SLOT and the same variable
955 from hash table DATA. Compute "sorted" union of the location chains
956 for common offsets, i.e. the locations of a variable part are sorted by
957 a priority where the priority is the sum of the positions in the 2 chains
958 (if a location is only in one list the position in the second list is
959 defined to be larger than the length of the chains).
960 When we are updating the location parts the newest location is in the
961 beginning of the chain, so when we do the described "sorted" union
962 we keep the newest locations in the beginning. */
965 variable_union (void **slot
, void *data
)
967 variable src
, dst
, *dstp
;
968 dataflow_set
*set
= (dataflow_set
*) data
;
971 src
= *(variable
*) slot
;
972 dstp
= (variable
*) htab_find_slot_with_hash (set
->vars
, src
->decl
,
973 VARIABLE_HASH_VAL (src
->decl
),
979 /* If CUR_LOC of some variable part is not the first element of
980 the location chain we are going to change it so we have to make
981 a copy of the variable. */
982 for (k
= 0; k
< src
->n_var_parts
; k
++)
984 gcc_assert (!src
->var_part
[k
].loc_chain
985 == !src
->var_part
[k
].cur_loc
);
986 if (src
->var_part
[k
].loc_chain
)
988 gcc_assert (src
->var_part
[k
].cur_loc
);
989 if (src
->var_part
[k
].cur_loc
!= src
->var_part
[k
].loc_chain
->loc
)
993 if (k
< src
->n_var_parts
)
994 unshare_variable (set
, src
);
998 /* Continue traversing the hash table. */
1004 gcc_assert (src
->n_var_parts
);
1006 /* Count the number of location parts, result is K. */
1007 for (i
= 0, j
= 0, k
= 0;
1008 i
< src
->n_var_parts
&& j
< dst
->n_var_parts
; k
++)
1010 if (src
->var_part
[i
].offset
== dst
->var_part
[j
].offset
)
1015 else if (src
->var_part
[i
].offset
< dst
->var_part
[j
].offset
)
1020 k
+= src
->n_var_parts
- i
;
1021 k
+= dst
->n_var_parts
- j
;
1023 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
1024 thus there are at most MAX_VAR_PARTS different offsets. */
1025 gcc_assert (k
<= MAX_VAR_PARTS
);
1027 if (dst
->refcount
> 1 && dst
->n_var_parts
!= k
)
1028 dst
= unshare_variable (set
, dst
);
1030 i
= src
->n_var_parts
- 1;
1031 j
= dst
->n_var_parts
- 1;
1032 dst
->n_var_parts
= k
;
1034 for (k
--; k
>= 0; k
--)
1036 location_chain node
, node2
;
1038 if (i
>= 0 && j
>= 0
1039 && src
->var_part
[i
].offset
== dst
->var_part
[j
].offset
)
1041 /* Compute the "sorted" union of the chains, i.e. the locations which
1042 are in both chains go first, they are sorted by the sum of
1043 positions in the chains. */
1046 struct variable_union_info
*vui
;
1048 /* If DST is shared compare the location chains.
1049 If they are different we will modify the chain in DST with
1050 high probability so make a copy of DST. */
1051 if (dst
->refcount
> 1)
1053 for (node
= src
->var_part
[i
].loc_chain
,
1054 node2
= dst
->var_part
[j
].loc_chain
; node
&& node2
;
1055 node
= node
->next
, node2
= node2
->next
)
1057 if (!((REG_P (node2
->loc
)
1058 && REG_P (node
->loc
)
1059 && REGNO (node2
->loc
) == REGNO (node
->loc
))
1060 || rtx_equal_p (node2
->loc
, node
->loc
)))
1064 dst
= unshare_variable (set
, dst
);
1068 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1071 for (node
= dst
->var_part
[j
].loc_chain
; node
; node
= node
->next
)
1073 vui
= xcalloc (src_l
+ dst_l
, sizeof (struct variable_union_info
));
1075 /* Fill in the locations from DST. */
1076 for (node
= dst
->var_part
[j
].loc_chain
, jj
= 0; node
;
1077 node
= node
->next
, jj
++)
1080 vui
[jj
].pos_dst
= jj
;
1082 /* Value larger than a sum of 2 valid positions. */
1083 vui
[jj
].pos_src
= src_l
+ dst_l
;
1086 /* Fill in the locations from SRC. */
1088 for (node
= src
->var_part
[i
].loc_chain
, ii
= 0; node
;
1089 node
= node
->next
, ii
++)
1091 /* Find location from NODE. */
1092 for (jj
= 0; jj
< dst_l
; jj
++)
1094 if ((REG_P (vui
[jj
].lc
->loc
)
1095 && REG_P (node
->loc
)
1096 && REGNO (vui
[jj
].lc
->loc
) == REGNO (node
->loc
))
1097 || rtx_equal_p (vui
[jj
].lc
->loc
, node
->loc
))
1099 vui
[jj
].pos_src
= ii
;
1103 if (jj
>= dst_l
) /* The location has not been found. */
1105 location_chain new_node
;
1107 /* Copy the location from SRC. */
1108 new_node
= pool_alloc (loc_chain_pool
);
1109 new_node
->loc
= node
->loc
;
1110 vui
[n
].lc
= new_node
;
1111 vui
[n
].pos_src
= ii
;
1112 vui
[n
].pos_dst
= src_l
+ dst_l
;
1117 for (ii
= 0; ii
< src_l
+ dst_l
; ii
++)
1118 vui
[ii
].pos
= vui
[ii
].pos_src
+ vui
[ii
].pos_dst
;
1120 qsort (vui
, n
, sizeof (struct variable_union_info
),
1121 variable_union_info_cmp_pos
);
1123 /* Reconnect the nodes in sorted order. */
1124 for (ii
= 1; ii
< n
; ii
++)
1125 vui
[ii
- 1].lc
->next
= vui
[ii
].lc
;
1126 vui
[n
- 1].lc
->next
= NULL
;
1128 dst
->var_part
[k
].loc_chain
= vui
[0].lc
;
1129 dst
->var_part
[k
].offset
= dst
->var_part
[j
].offset
;
1135 else if ((i
>= 0 && j
>= 0
1136 && src
->var_part
[i
].offset
< dst
->var_part
[j
].offset
)
1139 dst
->var_part
[k
] = dst
->var_part
[j
];
1142 else if ((i
>= 0 && j
>= 0
1143 && src
->var_part
[i
].offset
> dst
->var_part
[j
].offset
)
1146 location_chain
*nextp
;
1148 /* Copy the chain from SRC. */
1149 nextp
= &dst
->var_part
[k
].loc_chain
;
1150 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1152 location_chain new_lc
;
1154 new_lc
= pool_alloc (loc_chain_pool
);
1155 new_lc
->next
= NULL
;
1156 new_lc
->loc
= node
->loc
;
1159 nextp
= &new_lc
->next
;
1162 dst
->var_part
[k
].offset
= src
->var_part
[i
].offset
;
1166 /* We are at the basic block boundary when computing union
1167 so set the CUR_LOC to be the first element of the chain. */
1168 if (dst
->var_part
[k
].loc_chain
)
1169 dst
->var_part
[k
].cur_loc
= dst
->var_part
[k
].loc_chain
->loc
;
1171 dst
->var_part
[k
].cur_loc
= NULL
;
1174 /* Continue traversing the hash table. */
1178 /* Compute union of dataflow sets SRC and DST and store it to DST. */
1181 dataflow_set_union (dataflow_set
*dst
, dataflow_set
*src
)
1185 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1186 attrs_list_union (&dst
->regs
[i
], src
->regs
[i
]);
1188 htab_traverse (src
->vars
, variable_union
, dst
);
1191 /* Flag whether two dataflow sets being compared contain different data. */
1193 dataflow_set_different_value
;
1196 variable_part_different_p (variable_part
*vp1
, variable_part
*vp2
)
1198 location_chain lc1
, lc2
;
1200 for (lc1
= vp1
->loc_chain
; lc1
; lc1
= lc1
->next
)
1202 for (lc2
= vp2
->loc_chain
; lc2
; lc2
= lc2
->next
)
1204 if (REG_P (lc1
->loc
) && REG_P (lc2
->loc
))
1206 if (REGNO (lc1
->loc
) == REGNO (lc2
->loc
))
1209 if (rtx_equal_p (lc1
->loc
, lc2
->loc
))
1218 /* Return true if variables VAR1 and VAR2 are different.
1219 If COMPARE_CURRENT_LOCATION is true compare also the cur_loc of each
1223 variable_different_p (variable var1
, variable var2
,
1224 bool compare_current_location
)
1231 if (var1
->n_var_parts
!= var2
->n_var_parts
)
1234 for (i
= 0; i
< var1
->n_var_parts
; i
++)
1236 if (var1
->var_part
[i
].offset
!= var2
->var_part
[i
].offset
)
1238 if (compare_current_location
)
1240 if (!((REG_P (var1
->var_part
[i
].cur_loc
)
1241 && REG_P (var2
->var_part
[i
].cur_loc
)
1242 && (REGNO (var1
->var_part
[i
].cur_loc
)
1243 == REGNO (var2
->var_part
[i
].cur_loc
)))
1244 || rtx_equal_p (var1
->var_part
[i
].cur_loc
,
1245 var2
->var_part
[i
].cur_loc
)))
1248 if (variable_part_different_p (&var1
->var_part
[i
], &var2
->var_part
[i
]))
1250 if (variable_part_different_p (&var2
->var_part
[i
], &var1
->var_part
[i
]))
1256 /* Compare variable *SLOT with the same variable in hash table DATA
1257 and set DATAFLOW_SET_DIFFERENT_VALUE if they are different. */
1260 dataflow_set_different_1 (void **slot
, void *data
)
1262 htab_t htab
= (htab_t
) data
;
1263 variable var1
, var2
;
1265 var1
= *(variable
*) slot
;
1266 var2
= htab_find_with_hash (htab
, var1
->decl
,
1267 VARIABLE_HASH_VAL (var1
->decl
));
1270 dataflow_set_different_value
= true;
1272 /* Stop traversing the hash table. */
1276 if (variable_different_p (var1
, var2
, false))
1278 dataflow_set_different_value
= true;
1280 /* Stop traversing the hash table. */
1284 /* Continue traversing the hash table. */
1288 /* Compare variable *SLOT with the same variable in hash table DATA
1289 and set DATAFLOW_SET_DIFFERENT_VALUE if they are different. */
1292 dataflow_set_different_2 (void **slot
, void *data
)
1294 htab_t htab
= (htab_t
) data
;
1295 variable var1
, var2
;
1297 var1
= *(variable
*) slot
;
1298 var2
= htab_find_with_hash (htab
, var1
->decl
,
1299 VARIABLE_HASH_VAL (var1
->decl
));
1302 dataflow_set_different_value
= true;
1304 /* Stop traversing the hash table. */
1308 /* If both variables are defined they have been already checked for
1310 gcc_assert (!variable_different_p (var1
, var2
, false));
1312 /* Continue traversing the hash table. */
1316 /* Return true if dataflow sets OLD_SET and NEW_SET differ. */
1319 dataflow_set_different (dataflow_set
*old_set
, dataflow_set
*new_set
)
1321 dataflow_set_different_value
= false;
1323 htab_traverse (old_set
->vars
, dataflow_set_different_1
, new_set
->vars
);
1324 if (!dataflow_set_different_value
)
1326 /* We have compared the variables which are in both hash tables
1327 so now only check whether there are some variables in NEW_SET->VARS
1328 which are not in OLD_SET->VARS. */
1329 htab_traverse (new_set
->vars
, dataflow_set_different_2
, old_set
->vars
);
1331 return dataflow_set_different_value
;
1334 /* Free the contents of dataflow set SET. */
1337 dataflow_set_destroy (dataflow_set
*set
)
1341 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1342 attrs_list_clear (&set
->regs
[i
]);
1344 htab_delete (set
->vars
);
1348 /* Return true if RTL X contains a SYMBOL_REF. */
1351 contains_symbol_ref (rtx x
)
1360 code
= GET_CODE (x
);
1361 if (code
== SYMBOL_REF
)
1364 fmt
= GET_RTX_FORMAT (code
);
1365 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1369 if (contains_symbol_ref (XEXP (x
, i
)))
1372 else if (fmt
[i
] == 'E')
1375 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1376 if (contains_symbol_ref (XVECEXP (x
, i
, j
)))
1384 /* Shall EXPR be tracked? */
1387 track_expr_p (tree expr
)
1392 /* If EXPR is not a parameter or a variable do not track it. */
1393 if (TREE_CODE (expr
) != VAR_DECL
&& TREE_CODE (expr
) != PARM_DECL
)
1396 /* It also must have a name... */
1397 if (!DECL_NAME (expr
))
1400 /* ... and a RTL assigned to it. */
1401 decl_rtl
= DECL_RTL_IF_SET (expr
);
1405 /* If this expression is really a debug alias of some other declaration, we
1406 don't need to track this expression if the ultimate declaration is
1409 if (DECL_DEBUG_EXPR_IS_FROM (realdecl
) && DECL_DEBUG_EXPR (realdecl
))
1411 realdecl
= DECL_DEBUG_EXPR (realdecl
);
1412 /* ??? We don't yet know how to emit DW_OP_piece for variable
1413 that has been SRA'ed. */
1414 if (!DECL_P (realdecl
))
1418 /* Do not track EXPR if REALDECL it should be ignored for debugging
1420 if (DECL_IGNORED_P (realdecl
))
1423 /* Do not track global variables until we are able to emit correct location
1425 if (TREE_STATIC (realdecl
))
1428 /* When the EXPR is a DECL for alias of some variable (see example)
1429 the TREE_STATIC flag is not used. Disable tracking all DECLs whose
1430 DECL_RTL contains SYMBOL_REF.
1433 extern char **_dl_argv_internal __attribute__ ((alias ("_dl_argv")));
1436 if (MEM_P (decl_rtl
)
1437 && contains_symbol_ref (XEXP (decl_rtl
, 0)))
1440 /* If RTX is a memory it should not be very large (because it would be
1441 an array or struct). */
1442 if (MEM_P (decl_rtl
))
1444 /* Do not track structures and arrays. */
1445 if (GET_MODE (decl_rtl
) == BLKmode
)
1447 if (MEM_SIZE (decl_rtl
)
1448 && INTVAL (MEM_SIZE (decl_rtl
)) > MAX_VAR_PARTS
)
1455 /* Count uses (register and memory references) LOC which will be tracked.
1456 INSN is instruction which the LOC is part of. */
1459 count_uses (rtx
*loc
, void *insn
)
1461 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1465 gcc_assert (REGNO (*loc
) < FIRST_PSEUDO_REGISTER
);
1468 else if (MEM_P (*loc
)
1470 && track_expr_p (MEM_EXPR (*loc
)))
1478 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
1481 count_uses_1 (rtx
*x
, void *insn
)
1483 for_each_rtx (x
, count_uses
, insn
);
1486 /* Count stores (register and memory references) LOC which will be tracked.
1487 INSN is instruction which the LOC is part of. */
1490 count_stores (rtx loc
, rtx expr ATTRIBUTE_UNUSED
, void *insn
)
1492 count_uses (&loc
, insn
);
1495 /* Add uses (register and memory references) LOC which will be tracked
1496 to VTI (bb)->mos. INSN is instruction which the LOC is part of. */
1499 add_uses (rtx
*loc
, void *insn
)
1503 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1504 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1506 mo
->type
= ((REG_EXPR (*loc
) && track_expr_p (REG_EXPR (*loc
)))
1507 ? MO_USE
: MO_USE_NO_VAR
);
1509 mo
->insn
= (rtx
) insn
;
1511 else if (MEM_P (*loc
)
1513 && track_expr_p (MEM_EXPR (*loc
)))
1515 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1516 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1520 mo
->insn
= (rtx
) insn
;
1526 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
1529 add_uses_1 (rtx
*x
, void *insn
)
1531 for_each_rtx (x
, add_uses
, insn
);
1534 /* Add stores (register and memory references) LOC which will be tracked
1535 to VTI (bb)->mos. EXPR is the RTL expression containing the store.
1536 INSN is instruction which the LOC is part of. */
1539 add_stores (rtx loc
, rtx expr
, void *insn
)
1543 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1544 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1546 mo
->type
= ((GET_CODE (expr
) != CLOBBER
&& REG_EXPR (loc
)
1547 && track_expr_p (REG_EXPR (loc
)))
1548 ? MO_SET
: MO_CLOBBER
);
1550 mo
->insn
= (rtx
) insn
;
1552 else if (MEM_P (loc
)
1554 && track_expr_p (MEM_EXPR (loc
)))
1556 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1557 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1559 mo
->type
= GET_CODE (expr
) == CLOBBER
? MO_CLOBBER
: MO_SET
;
1561 mo
->insn
= (rtx
) insn
;
1565 /* Compute the changes of variable locations in the basic block BB. */
1568 compute_bb_dataflow (basic_block bb
)
1572 dataflow_set old_out
;
1573 dataflow_set
*in
= &VTI (bb
)->in
;
1574 dataflow_set
*out
= &VTI (bb
)->out
;
1576 dataflow_set_init (&old_out
, htab_elements (VTI (bb
)->out
.vars
) + 3);
1577 dataflow_set_copy (&old_out
, out
);
1578 dataflow_set_copy (out
, in
);
1580 n
= VTI (bb
)->n_mos
;
1581 for (i
= 0; i
< n
; i
++)
1583 switch (VTI (bb
)->mos
[i
].type
)
1586 for (r
= 0; r
< FIRST_PSEUDO_REGISTER
; r
++)
1587 if (TEST_HARD_REG_BIT (call_used_reg_set
, r
))
1588 var_regno_delete (out
, r
);
1594 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
1597 var_reg_delete_and_set (out
, loc
);
1598 else if (MEM_P (loc
))
1599 var_mem_delete_and_set (out
, loc
);
1606 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
1609 var_reg_delete (out
, loc
);
1610 else if (MEM_P (loc
))
1611 var_mem_delete (out
, loc
);
1616 out
->stack_adjust
+= VTI (bb
)->mos
[i
].u
.adjust
;
1621 changed
= dataflow_set_different (&old_out
, out
);
1622 dataflow_set_destroy (&old_out
);
1626 /* Find the locations of variables in the whole function. */
1629 vt_find_locations (void)
1631 fibheap_t worklist
, pending
, fibheap_swap
;
1632 sbitmap visited
, in_worklist
, in_pending
, sbitmap_swap
;
1639 /* Compute reverse completion order of depth first search of the CFG
1640 so that the data-flow runs faster. */
1641 rc_order
= xmalloc ((n_basic_blocks
- NUM_FIXED_BLOCKS
) * sizeof (int));
1642 bb_order
= xmalloc (last_basic_block
* sizeof (int));
1643 pre_and_rev_post_order_compute (NULL
, rc_order
, false);
1644 for (i
= 0; i
< n_basic_blocks
- NUM_FIXED_BLOCKS
; i
++)
1645 bb_order
[rc_order
[i
]] = i
;
1648 worklist
= fibheap_new ();
1649 pending
= fibheap_new ();
1650 visited
= sbitmap_alloc (last_basic_block
);
1651 in_worklist
= sbitmap_alloc (last_basic_block
);
1652 in_pending
= sbitmap_alloc (last_basic_block
);
1653 sbitmap_zero (in_worklist
);
1656 fibheap_insert (pending
, bb_order
[bb
->index
], bb
);
1657 sbitmap_ones (in_pending
);
1659 while (!fibheap_empty (pending
))
1661 fibheap_swap
= pending
;
1663 worklist
= fibheap_swap
;
1664 sbitmap_swap
= in_pending
;
1665 in_pending
= in_worklist
;
1666 in_worklist
= sbitmap_swap
;
1668 sbitmap_zero (visited
);
1670 while (!fibheap_empty (worklist
))
1672 bb
= fibheap_extract_min (worklist
);
1673 RESET_BIT (in_worklist
, bb
->index
);
1674 if (!TEST_BIT (visited
, bb
->index
))
1679 SET_BIT (visited
, bb
->index
);
1681 /* Calculate the IN set as union of predecessor OUT sets. */
1682 dataflow_set_clear (&VTI (bb
)->in
);
1683 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
1685 dataflow_set_union (&VTI (bb
)->in
, &VTI (e
->src
)->out
);
1688 changed
= compute_bb_dataflow (bb
);
1691 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1693 if (e
->dest
== EXIT_BLOCK_PTR
)
1699 if (TEST_BIT (visited
, e
->dest
->index
))
1701 if (!TEST_BIT (in_pending
, e
->dest
->index
))
1703 /* Send E->DEST to next round. */
1704 SET_BIT (in_pending
, e
->dest
->index
);
1705 fibheap_insert (pending
,
1706 bb_order
[e
->dest
->index
],
1710 else if (!TEST_BIT (in_worklist
, e
->dest
->index
))
1712 /* Add E->DEST to current round. */
1713 SET_BIT (in_worklist
, e
->dest
->index
);
1714 fibheap_insert (worklist
, bb_order
[e
->dest
->index
],
1724 fibheap_delete (worklist
);
1725 fibheap_delete (pending
);
1726 sbitmap_free (visited
);
1727 sbitmap_free (in_worklist
);
1728 sbitmap_free (in_pending
);
1731 /* Print the content of the LIST to dump file. */
1734 dump_attrs_list (attrs list
)
1736 for (; list
; list
= list
->next
)
1738 print_mem_expr (dump_file
, list
->decl
);
1739 fprintf (dump_file
, "+" HOST_WIDE_INT_PRINT_DEC
, list
->offset
);
1741 fprintf (dump_file
, "\n");
1744 /* Print the information about variable *SLOT to dump file. */
1747 dump_variable (void **slot
, void *data ATTRIBUTE_UNUSED
)
1749 variable var
= *(variable
*) slot
;
1751 location_chain node
;
1753 fprintf (dump_file
, " name: %s\n",
1754 IDENTIFIER_POINTER (DECL_NAME (var
->decl
)));
1755 for (i
= 0; i
< var
->n_var_parts
; i
++)
1757 fprintf (dump_file
, " offset %ld\n",
1758 (long) var
->var_part
[i
].offset
);
1759 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1761 fprintf (dump_file
, " ");
1762 print_rtl_single (dump_file
, node
->loc
);
1766 /* Continue traversing the hash table. */
1770 /* Print the information about variables from hash table VARS to dump file. */
1773 dump_vars (htab_t vars
)
1775 if (htab_elements (vars
) > 0)
1777 fprintf (dump_file
, "Variables:\n");
1778 htab_traverse (vars
, dump_variable
, NULL
);
1782 /* Print the dataflow set SET to dump file. */
1785 dump_dataflow_set (dataflow_set
*set
)
1789 fprintf (dump_file
, "Stack adjustment: " HOST_WIDE_INT_PRINT_DEC
"\n",
1791 for (i
= 1; i
< FIRST_PSEUDO_REGISTER
; i
++)
1795 fprintf (dump_file
, "Reg %d:", i
);
1796 dump_attrs_list (set
->regs
[i
]);
1799 dump_vars (set
->vars
);
1800 fprintf (dump_file
, "\n");
1803 /* Print the IN and OUT sets for each basic block to dump file. */
1806 dump_dataflow_sets (void)
1812 fprintf (dump_file
, "\nBasic block %d:\n", bb
->index
);
1813 fprintf (dump_file
, "IN:\n");
1814 dump_dataflow_set (&VTI (bb
)->in
);
1815 fprintf (dump_file
, "OUT:\n");
1816 dump_dataflow_set (&VTI (bb
)->out
);
1820 /* Add variable VAR to the hash table of changed variables and
1821 if it has no locations delete it from hash table HTAB. */
1824 variable_was_changed (variable var
, htab_t htab
)
1826 hashval_t hash
= VARIABLE_HASH_VAL (var
->decl
);
1832 slot
= (variable
*) htab_find_slot_with_hash (changed_variables
,
1833 var
->decl
, hash
, INSERT
);
1835 if (htab
&& var
->n_var_parts
== 0)
1840 empty_var
= pool_alloc (var_pool
);
1841 empty_var
->decl
= var
->decl
;
1842 empty_var
->refcount
= 1;
1843 empty_var
->n_var_parts
= 0;
1846 old
= htab_find_slot_with_hash (htab
, var
->decl
, hash
,
1849 htab_clear_slot (htab
, old
);
1859 if (var
->n_var_parts
== 0)
1861 void **slot
= htab_find_slot_with_hash (htab
, var
->decl
, hash
,
1864 htab_clear_slot (htab
, slot
);
1869 /* Set the part of variable's location in the dataflow set SET. The variable
1870 part is specified by variable's declaration DECL and offset OFFSET and the
1871 part's location by LOC. */
1874 set_variable_part (dataflow_set
*set
, rtx loc
, tree decl
, HOST_WIDE_INT offset
)
1877 location_chain node
, next
;
1878 location_chain
*nextp
;
1882 slot
= htab_find_slot_with_hash (set
->vars
, decl
,
1883 VARIABLE_HASH_VAL (decl
), INSERT
);
1886 /* Create new variable information. */
1887 var
= pool_alloc (var_pool
);
1890 var
->n_var_parts
= 1;
1891 var
->var_part
[0].offset
= offset
;
1892 var
->var_part
[0].loc_chain
= NULL
;
1893 var
->var_part
[0].cur_loc
= NULL
;
1899 var
= (variable
) *slot
;
1901 /* Find the location part. */
1903 high
= var
->n_var_parts
;
1906 pos
= (low
+ high
) / 2;
1907 if (var
->var_part
[pos
].offset
< offset
)
1914 if (pos
< var
->n_var_parts
&& var
->var_part
[pos
].offset
== offset
)
1916 node
= var
->var_part
[pos
].loc_chain
;
1919 && ((REG_P (node
->loc
) && REG_P (loc
)
1920 && REGNO (node
->loc
) == REGNO (loc
))
1921 || rtx_equal_p (node
->loc
, loc
)))
1923 /* LOC is in the beginning of the chain so we have nothing
1929 /* We have to make a copy of a shared variable. */
1930 if (var
->refcount
> 1)
1931 var
= unshare_variable (set
, var
);
1936 /* We have not found the location part, new one will be created. */
1938 /* We have to make a copy of the shared variable. */
1939 if (var
->refcount
> 1)
1940 var
= unshare_variable (set
, var
);
1942 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
1943 thus there are at most MAX_VAR_PARTS different offsets. */
1944 gcc_assert (var
->n_var_parts
< MAX_VAR_PARTS
);
1946 /* We have to move the elements of array starting at index low to the
1948 for (high
= var
->n_var_parts
; high
> low
; high
--)
1949 var
->var_part
[high
] = var
->var_part
[high
- 1];
1952 var
->var_part
[pos
].offset
= offset
;
1953 var
->var_part
[pos
].loc_chain
= NULL
;
1954 var
->var_part
[pos
].cur_loc
= NULL
;
1958 /* Delete the location from the list. */
1959 nextp
= &var
->var_part
[pos
].loc_chain
;
1960 for (node
= var
->var_part
[pos
].loc_chain
; node
; node
= next
)
1963 if ((REG_P (node
->loc
) && REG_P (loc
)
1964 && REGNO (node
->loc
) == REGNO (loc
))
1965 || rtx_equal_p (node
->loc
, loc
))
1967 pool_free (loc_chain_pool
, node
);
1972 nextp
= &node
->next
;
1975 /* Add the location to the beginning. */
1976 node
= pool_alloc (loc_chain_pool
);
1978 node
->next
= var
->var_part
[pos
].loc_chain
;
1979 var
->var_part
[pos
].loc_chain
= node
;
1981 /* If no location was emitted do so. */
1982 if (var
->var_part
[pos
].cur_loc
== NULL
)
1984 var
->var_part
[pos
].cur_loc
= loc
;
1985 variable_was_changed (var
, set
->vars
);
1989 /* Delete the part of variable's location from dataflow set SET. The variable
1990 part is specified by variable's declaration DECL and offset OFFSET and the
1991 part's location by LOC. */
1994 delete_variable_part (dataflow_set
*set
, rtx loc
, tree decl
,
1995 HOST_WIDE_INT offset
)
2000 slot
= htab_find_slot_with_hash (set
->vars
, decl
, VARIABLE_HASH_VAL (decl
),
2004 variable var
= (variable
) *slot
;
2006 /* Find the location part. */
2008 high
= var
->n_var_parts
;
2011 pos
= (low
+ high
) / 2;
2012 if (var
->var_part
[pos
].offset
< offset
)
2019 if (pos
< var
->n_var_parts
&& var
->var_part
[pos
].offset
== offset
)
2021 location_chain node
, next
;
2022 location_chain
*nextp
;
2025 if (var
->refcount
> 1)
2027 /* If the variable contains the location part we have to
2028 make a copy of the variable. */
2029 for (node
= var
->var_part
[pos
].loc_chain
; node
;
2032 if ((REG_P (node
->loc
) && REG_P (loc
)
2033 && REGNO (node
->loc
) == REGNO (loc
))
2034 || rtx_equal_p (node
->loc
, loc
))
2036 var
= unshare_variable (set
, var
);
2042 /* Delete the location part. */
2043 nextp
= &var
->var_part
[pos
].loc_chain
;
2044 for (node
= *nextp
; node
; node
= next
)
2047 if ((REG_P (node
->loc
) && REG_P (loc
)
2048 && REGNO (node
->loc
) == REGNO (loc
))
2049 || rtx_equal_p (node
->loc
, loc
))
2051 pool_free (loc_chain_pool
, node
);
2056 nextp
= &node
->next
;
2059 /* If we have deleted the location which was last emitted
2060 we have to emit new location so add the variable to set
2061 of changed variables. */
2062 if (var
->var_part
[pos
].cur_loc
2064 && REG_P (var
->var_part
[pos
].cur_loc
)
2065 && REGNO (loc
) == REGNO (var
->var_part
[pos
].cur_loc
))
2066 || rtx_equal_p (loc
, var
->var_part
[pos
].cur_loc
)))
2069 if (var
->var_part
[pos
].loc_chain
)
2070 var
->var_part
[pos
].cur_loc
= var
->var_part
[pos
].loc_chain
->loc
;
2075 if (var
->var_part
[pos
].loc_chain
== NULL
)
2078 while (pos
< var
->n_var_parts
)
2080 var
->var_part
[pos
] = var
->var_part
[pos
+ 1];
2085 variable_was_changed (var
, set
->vars
);
2090 /* Emit the NOTE_INSN_VAR_LOCATION for variable *VARP. DATA contains
2091 additional parameters: WHERE specifies whether the note shall be emitted
2092 before of after instruction INSN. */
2095 emit_note_insn_var_location (void **varp
, void *data
)
2097 variable var
= *(variable
*) varp
;
2098 rtx insn
= ((emit_note_data
*)data
)->insn
;
2099 enum emit_note_where where
= ((emit_note_data
*)data
)->where
;
2101 int i
, j
, n_var_parts
;
2103 HOST_WIDE_INT last_limit
;
2104 tree type_size_unit
;
2105 HOST_WIDE_INT offsets
[MAX_VAR_PARTS
];
2106 rtx loc
[MAX_VAR_PARTS
];
2108 gcc_assert (var
->decl
);
2113 for (i
= 0; i
< var
->n_var_parts
; i
++)
2115 enum machine_mode mode
, wider_mode
;
2117 if (last_limit
< var
->var_part
[i
].offset
)
2122 else if (last_limit
> var
->var_part
[i
].offset
)
2124 offsets
[n_var_parts
] = var
->var_part
[i
].offset
;
2125 loc
[n_var_parts
] = var
->var_part
[i
].loc_chain
->loc
;
2126 mode
= GET_MODE (loc
[n_var_parts
]);
2127 last_limit
= offsets
[n_var_parts
] + GET_MODE_SIZE (mode
);
2129 /* Attempt to merge adjacent registers or memory. */
2130 wider_mode
= GET_MODE_WIDER_MODE (mode
);
2131 for (j
= i
+ 1; j
< var
->n_var_parts
; j
++)
2132 if (last_limit
<= var
->var_part
[j
].offset
)
2134 if (j
< var
->n_var_parts
2135 && wider_mode
!= VOIDmode
2136 && GET_CODE (loc
[n_var_parts
])
2137 == GET_CODE (var
->var_part
[j
].loc_chain
->loc
)
2138 && mode
== GET_MODE (var
->var_part
[j
].loc_chain
->loc
)
2139 && last_limit
== var
->var_part
[j
].offset
)
2142 rtx loc2
= var
->var_part
[j
].loc_chain
->loc
;
2144 if (REG_P (loc
[n_var_parts
])
2145 && hard_regno_nregs
[REGNO (loc
[n_var_parts
])][mode
] * 2
2146 == hard_regno_nregs
[REGNO (loc
[n_var_parts
])][wider_mode
]
2147 && REGNO (loc
[n_var_parts
])
2148 + hard_regno_nregs
[REGNO (loc
[n_var_parts
])][mode
]
2151 if (! WORDS_BIG_ENDIAN
&& ! BYTES_BIG_ENDIAN
)
2152 new_loc
= simplify_subreg (wider_mode
, loc
[n_var_parts
],
2154 else if (WORDS_BIG_ENDIAN
&& BYTES_BIG_ENDIAN
)
2155 new_loc
= simplify_subreg (wider_mode
, loc2
, mode
, 0);
2158 if (!REG_P (new_loc
)
2159 || REGNO (new_loc
) != REGNO (loc
[n_var_parts
]))
2162 REG_ATTRS (new_loc
) = REG_ATTRS (loc
[n_var_parts
]);
2165 else if (MEM_P (loc
[n_var_parts
])
2166 && GET_CODE (XEXP (loc2
, 0)) == PLUS
2167 && GET_CODE (XEXP (XEXP (loc2
, 0), 0)) == REG
2168 && GET_CODE (XEXP (XEXP (loc2
, 0), 1)) == CONST_INT
)
2170 if ((GET_CODE (XEXP (loc
[n_var_parts
], 0)) == REG
2171 && rtx_equal_p (XEXP (loc
[n_var_parts
], 0),
2172 XEXP (XEXP (loc2
, 0), 0))
2173 && INTVAL (XEXP (XEXP (loc2
, 0), 1))
2174 == GET_MODE_SIZE (mode
))
2175 || (GET_CODE (XEXP (loc
[n_var_parts
], 0)) == PLUS
2176 && GET_CODE (XEXP (XEXP (loc
[n_var_parts
], 0), 1))
2178 && rtx_equal_p (XEXP (XEXP (loc
[n_var_parts
], 0), 0),
2179 XEXP (XEXP (loc2
, 0), 0))
2180 && INTVAL (XEXP (XEXP (loc
[n_var_parts
], 0), 1))
2181 + GET_MODE_SIZE (mode
)
2182 == INTVAL (XEXP (XEXP (loc2
, 0), 1))))
2183 new_loc
= adjust_address_nv (loc
[n_var_parts
],
2189 loc
[n_var_parts
] = new_loc
;
2191 last_limit
= offsets
[n_var_parts
] + GET_MODE_SIZE (mode
);
2197 type_size_unit
= TYPE_SIZE_UNIT (TREE_TYPE (var
->decl
));
2198 if ((unsigned HOST_WIDE_INT
) last_limit
< TREE_INT_CST_LOW (type_size_unit
))
2201 if (where
== EMIT_NOTE_AFTER_INSN
)
2202 note
= emit_note_after (NOTE_INSN_VAR_LOCATION
, insn
);
2204 note
= emit_note_before (NOTE_INSN_VAR_LOCATION
, insn
);
2208 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2211 else if (n_var_parts
== 1)
2214 = gen_rtx_EXPR_LIST (VOIDmode
, loc
[0], GEN_INT (offsets
[0]));
2216 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2219 else if (n_var_parts
)
2223 for (i
= 0; i
< n_var_parts
; i
++)
2225 = gen_rtx_EXPR_LIST (VOIDmode
, loc
[i
], GEN_INT (offsets
[i
]));
2227 parallel
= gen_rtx_PARALLEL (VOIDmode
,
2228 gen_rtvec_v (n_var_parts
, loc
));
2229 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2233 htab_clear_slot (changed_variables
, varp
);
2235 /* When there are no location parts the variable has been already
2236 removed from hash table and a new empty variable was created.
2237 Free the empty variable. */
2238 if (var
->n_var_parts
== 0)
2240 pool_free (var_pool
, var
);
2243 /* Continue traversing the hash table. */
2247 /* Emit NOTE_INSN_VAR_LOCATION note for each variable from a chain
2248 CHANGED_VARIABLES and delete this chain. WHERE specifies whether the notes
2249 shall be emitted before of after instruction INSN. */
2252 emit_notes_for_changes (rtx insn
, enum emit_note_where where
)
2254 emit_note_data data
;
2258 htab_traverse (changed_variables
, emit_note_insn_var_location
, &data
);
2261 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it differs from the
2262 same variable in hash table DATA or is not there at all. */
2265 emit_notes_for_differences_1 (void **slot
, void *data
)
2267 htab_t new_vars
= (htab_t
) data
;
2268 variable old_var
, new_var
;
2270 old_var
= *(variable
*) slot
;
2271 new_var
= htab_find_with_hash (new_vars
, old_var
->decl
,
2272 VARIABLE_HASH_VAL (old_var
->decl
));
2276 /* Variable has disappeared. */
2279 empty_var
= pool_alloc (var_pool
);
2280 empty_var
->decl
= old_var
->decl
;
2281 empty_var
->refcount
= 1;
2282 empty_var
->n_var_parts
= 0;
2283 variable_was_changed (empty_var
, NULL
);
2285 else if (variable_different_p (old_var
, new_var
, true))
2287 variable_was_changed (new_var
, NULL
);
2290 /* Continue traversing the hash table. */
2294 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it is not in hash
2298 emit_notes_for_differences_2 (void **slot
, void *data
)
2300 htab_t old_vars
= (htab_t
) data
;
2301 variable old_var
, new_var
;
2303 new_var
= *(variable
*) slot
;
2304 old_var
= htab_find_with_hash (old_vars
, new_var
->decl
,
2305 VARIABLE_HASH_VAL (new_var
->decl
));
2308 /* Variable has appeared. */
2309 variable_was_changed (new_var
, NULL
);
2312 /* Continue traversing the hash table. */
2316 /* Emit notes before INSN for differences between dataflow sets OLD_SET and
2320 emit_notes_for_differences (rtx insn
, dataflow_set
*old_set
,
2321 dataflow_set
*new_set
)
2323 htab_traverse (old_set
->vars
, emit_notes_for_differences_1
, new_set
->vars
);
2324 htab_traverse (new_set
->vars
, emit_notes_for_differences_2
, old_set
->vars
);
2325 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2328 /* Emit the notes for changes of location parts in the basic block BB. */
2331 emit_notes_in_bb (basic_block bb
)
2336 dataflow_set_init (&set
, htab_elements (VTI (bb
)->in
.vars
) + 3);
2337 dataflow_set_copy (&set
, &VTI (bb
)->in
);
2339 for (i
= 0; i
< VTI (bb
)->n_mos
; i
++)
2341 rtx insn
= VTI (bb
)->mos
[i
].insn
;
2343 switch (VTI (bb
)->mos
[i
].type
)
2349 for (r
= 0; r
< FIRST_PSEUDO_REGISTER
; r
++)
2350 if (TEST_HARD_REG_BIT (call_used_reg_set
, r
))
2352 var_regno_delete (&set
, r
);
2354 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2361 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
2364 var_reg_delete_and_set (&set
, loc
);
2366 var_mem_delete_and_set (&set
, loc
);
2368 if (VTI (bb
)->mos
[i
].type
== MO_USE
)
2369 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2371 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2378 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
2381 var_reg_delete (&set
, loc
);
2383 var_mem_delete (&set
, loc
);
2385 if (VTI (bb
)->mos
[i
].type
== MO_USE_NO_VAR
)
2386 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2388 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2393 set
.stack_adjust
+= VTI (bb
)->mos
[i
].u
.adjust
;
2397 dataflow_set_destroy (&set
);
2400 /* Emit notes for the whole function. */
2403 vt_emit_notes (void)
2406 dataflow_set
*last_out
;
2409 gcc_assert (!htab_elements (changed_variables
));
2411 /* Enable emitting notes by functions (mainly by set_variable_part and
2412 delete_variable_part). */
2415 dataflow_set_init (&empty
, 7);
2420 /* Emit the notes for changes of variable locations between two
2421 subsequent basic blocks. */
2422 emit_notes_for_differences (BB_HEAD (bb
), last_out
, &VTI (bb
)->in
);
2424 /* Emit the notes for the changes in the basic block itself. */
2425 emit_notes_in_bb (bb
);
2427 last_out
= &VTI (bb
)->out
;
2429 dataflow_set_destroy (&empty
);
2433 /* If there is a declaration and offset associated with register/memory RTL
2434 assign declaration to *DECLP and offset to *OFFSETP, and return true. */
2437 vt_get_decl_and_offset (rtx rtl
, tree
*declp
, HOST_WIDE_INT
*offsetp
)
2441 if (REG_ATTRS (rtl
))
2443 *declp
= REG_EXPR (rtl
);
2444 *offsetp
= REG_OFFSET (rtl
);
2448 else if (MEM_P (rtl
))
2450 if (MEM_ATTRS (rtl
))
2452 *declp
= MEM_EXPR (rtl
);
2453 *offsetp
= MEM_OFFSET (rtl
) ? INTVAL (MEM_OFFSET (rtl
)) : 0;
2460 /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK. */
2463 vt_add_function_parameters (void)
2467 for (parm
= DECL_ARGUMENTS (current_function_decl
);
2468 parm
; parm
= TREE_CHAIN (parm
))
2470 rtx decl_rtl
= DECL_RTL_IF_SET (parm
);
2471 rtx incoming
= DECL_INCOMING_RTL (parm
);
2473 HOST_WIDE_INT offset
;
2476 if (TREE_CODE (parm
) != PARM_DECL
)
2479 if (!DECL_NAME (parm
))
2482 if (!decl_rtl
|| !incoming
)
2485 if (GET_MODE (decl_rtl
) == BLKmode
|| GET_MODE (incoming
) == BLKmode
)
2488 if (!vt_get_decl_and_offset (incoming
, &decl
, &offset
))
2489 if (!vt_get_decl_and_offset (decl_rtl
, &decl
, &offset
))
2495 gcc_assert (parm
== decl
);
2497 out
= &VTI (ENTRY_BLOCK_PTR
)->out
;
2499 if (REG_P (incoming
))
2501 gcc_assert (REGNO (incoming
) < FIRST_PSEUDO_REGISTER
);
2502 attrs_list_insert (&out
->regs
[REGNO (incoming
)],
2503 parm
, offset
, incoming
);
2504 set_variable_part (out
, incoming
, parm
, offset
);
2506 else if (MEM_P (incoming
))
2507 set_variable_part (out
, incoming
, parm
, offset
);
2511 /* Allocate and initialize the data structures for variable tracking
2512 and parse the RTL to get the micro operations. */
2515 vt_initialize (void)
2519 alloc_aux_for_blocks (sizeof (struct variable_tracking_info_def
));
2524 HOST_WIDE_INT pre
, post
= 0;
2526 /* Count the number of micro operations. */
2527 VTI (bb
)->n_mos
= 0;
2528 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
2529 insn
= NEXT_INSN (insn
))
2533 if (!frame_pointer_needed
)
2535 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
2541 note_uses (&PATTERN (insn
), count_uses_1
, insn
);
2542 note_stores (PATTERN (insn
), count_stores
, insn
);
2548 /* Add the micro-operations to the array. */
2549 VTI (bb
)->mos
= xmalloc (VTI (bb
)->n_mos
2550 * sizeof (struct micro_operation_def
));
2551 VTI (bb
)->n_mos
= 0;
2552 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
2553 insn
= NEXT_INSN (insn
))
2559 if (!frame_pointer_needed
)
2561 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
2564 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2566 mo
->type
= MO_ADJUST
;
2572 n1
= VTI (bb
)->n_mos
;
2573 note_uses (&PATTERN (insn
), add_uses_1
, insn
);
2574 n2
= VTI (bb
)->n_mos
- 1;
2576 /* Order the MO_USEs to be before MO_USE_NO_VARs. */
2579 while (n1
< n2
&& VTI (bb
)->mos
[n1
].type
== MO_USE
)
2581 while (n1
< n2
&& VTI (bb
)->mos
[n2
].type
== MO_USE_NO_VAR
)
2587 sw
= VTI (bb
)->mos
[n1
];
2588 VTI (bb
)->mos
[n1
] = VTI (bb
)->mos
[n2
];
2589 VTI (bb
)->mos
[n2
] = sw
;
2595 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2601 n1
= VTI (bb
)->n_mos
;
2602 note_stores (PATTERN (insn
), add_stores
, insn
);
2603 n2
= VTI (bb
)->n_mos
- 1;
2605 /* Order the MO_SETs to be before MO_CLOBBERs. */
2608 while (n1
< n2
&& VTI (bb
)->mos
[n1
].type
== MO_SET
)
2610 while (n1
< n2
&& VTI (bb
)->mos
[n2
].type
== MO_CLOBBER
)
2616 sw
= VTI (bb
)->mos
[n1
];
2617 VTI (bb
)->mos
[n1
] = VTI (bb
)->mos
[n2
];
2618 VTI (bb
)->mos
[n2
] = sw
;
2622 if (!frame_pointer_needed
&& post
)
2624 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2626 mo
->type
= MO_ADJUST
;
2627 mo
->u
.adjust
= post
;
2634 /* Init the IN and OUT sets. */
2637 VTI (bb
)->visited
= false;
2638 dataflow_set_init (&VTI (bb
)->in
, 7);
2639 dataflow_set_init (&VTI (bb
)->out
, 7);
2642 attrs_pool
= create_alloc_pool ("attrs_def pool",
2643 sizeof (struct attrs_def
), 1024);
2644 var_pool
= create_alloc_pool ("variable_def pool",
2645 sizeof (struct variable_def
), 64);
2646 loc_chain_pool
= create_alloc_pool ("location_chain_def pool",
2647 sizeof (struct location_chain_def
),
2649 changed_variables
= htab_create (10, variable_htab_hash
, variable_htab_eq
,
2651 vt_add_function_parameters ();
2654 /* Free the data structures needed for variable tracking. */
2663 free (VTI (bb
)->mos
);
2668 dataflow_set_destroy (&VTI (bb
)->in
);
2669 dataflow_set_destroy (&VTI (bb
)->out
);
2671 free_aux_for_blocks ();
2672 free_alloc_pool (attrs_pool
);
2673 free_alloc_pool (var_pool
);
2674 free_alloc_pool (loc_chain_pool
);
2675 htab_delete (changed_variables
);
2678 /* The entry point to variable tracking pass. */
2681 variable_tracking_main (void)
2683 if (n_basic_blocks
> 500 && n_edges
/ n_basic_blocks
>= 20)
2686 mark_dfs_back_edges ();
2688 if (!frame_pointer_needed
)
2690 if (!vt_stack_adjustments ())
2697 vt_find_locations ();
2702 dump_dataflow_sets ();
2703 dump_flow_info (dump_file
);
2710 gate_handle_var_tracking (void)
2712 return (flag_var_tracking
);
2717 struct tree_opt_pass pass_variable_tracking
=
2719 "vartrack", /* name */
2720 gate_handle_var_tracking
, /* gate */
2721 variable_tracking_main
, /* execute */
2724 0, /* static_pass_number */
2725 TV_VAR_TRACKING
, /* tv_id */
2726 0, /* properties_required */
2727 0, /* properties_provided */
2728 0, /* properties_destroyed */
2729 0, /* todo_flags_start */
2730 TODO_dump_func
, /* todo_flags_finish */