1 /* Variable tracking routines for the GNU compiler.
2 Copyright (C) 2002, 2003, 2004 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, 59 Temple Place - Suite 330, 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"
106 /* Type of micro operation. */
107 enum micro_operation_type
109 MO_USE
, /* Use location (REG or MEM). */
110 MO_USE_NO_VAR
,/* Use location which is not associated with a variable
111 or the variable is not trackable. */
112 MO_SET
, /* Set location. */
113 MO_CLOBBER
, /* Clobber location. */
114 MO_CALL
, /* Call insn. */
115 MO_ADJUST
/* Adjust stack pointer. */
118 /* Where shall the note be emitted? BEFORE or AFTER the instruction. */
121 EMIT_NOTE_BEFORE_INSN
,
125 /* Structure holding information about micro operation. */
126 typedef struct micro_operation_def
128 /* Type of micro operation. */
129 enum micro_operation_type type
;
135 /* Stack adjustment. */
136 HOST_WIDE_INT adjust
;
139 /* The instruction which the micro operation is in. */
143 /* Structure for passing some other parameters to function
144 emit_note_insn_var_location. */
145 typedef struct emit_note_data_def
147 /* The instruction which the note will be emitted before/after. */
150 /* Where the note will be emitted (before/after insn)? */
151 enum emit_note_where where
;
154 /* Description of location of a part of a variable. The content of a physical
155 register is described by a chain of these structures.
156 The chains are pretty short (usually 1 or 2 elements) and thus
157 chain is the best data structure. */
158 typedef struct attrs_def
160 /* Pointer to next member of the list. */
161 struct attrs_def
*next
;
163 /* The rtx of register. */
166 /* The declaration corresponding to LOC. */
169 /* Offset from start of DECL. */
170 HOST_WIDE_INT offset
;
173 /* Structure holding the IN or OUT set for a basic block. */
174 typedef struct dataflow_set_def
176 /* Adjustment of stack offset. */
177 HOST_WIDE_INT stack_adjust
;
179 /* Attributes for registers (lists of attrs). */
180 attrs regs
[FIRST_PSEUDO_REGISTER
];
182 /* Variable locations. */
186 /* The structure (one for each basic block) containing the information
187 needed for variable tracking. */
188 typedef struct variable_tracking_info_def
190 /* Number of micro operations stored in the MOS array. */
193 /* The array of micro operations. */
194 micro_operation
*mos
;
196 /* The IN and OUT set for dataflow analysis. */
200 /* Has the block been visited in DFS? */
202 } *variable_tracking_info
;
204 /* Structure for chaining the locations. */
205 typedef struct location_chain_def
207 /* Next element in the chain. */
208 struct location_chain_def
*next
;
210 /* The location (REG or MEM). */
214 /* Structure describing one part of variable. */
215 typedef struct variable_part_def
217 /* Chain of locations of the part. */
218 location_chain loc_chain
;
220 /* Location which was last emitted to location list. */
223 /* The offset in the variable. */
224 HOST_WIDE_INT offset
;
227 /* Maximum number of location parts. */
228 #define MAX_VAR_PARTS 16
230 /* Structure describing where the variable is located. */
231 typedef struct variable_def
233 /* The declaration of the variable. */
236 /* Reference count. */
239 /* Number of variable parts. */
242 /* The variable parts. */
243 variable_part var_part
[MAX_VAR_PARTS
];
246 /* Hash function for DECL for VARIABLE_HTAB. */
247 #define VARIABLE_HASH_VAL(decl) ((size_t) (decl))
249 /* Pointer to the BB's information specific to variable tracking pass. */
250 #define VTI(BB) ((variable_tracking_info) (BB)->aux)
252 /* Alloc pool for struct attrs_def. */
253 static alloc_pool attrs_pool
;
255 /* Alloc pool for struct variable_def. */
256 static alloc_pool var_pool
;
258 /* Alloc pool for struct location_chain_def. */
259 static alloc_pool loc_chain_pool
;
261 /* Changed variables, notes will be emitted for them. */
262 static htab_t changed_variables
;
264 /* Shall notes be emitted? */
265 static bool emit_notes
;
267 /* Fake variable for stack pointer. */
268 GTY(()) tree frame_base_decl
;
270 /* Local function prototypes. */
271 static void stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
273 static void insn_stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
275 static void bb_stack_adjust_offset (basic_block
);
276 static HOST_WIDE_INT
prologue_stack_adjust (void);
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
);
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_frame_base_location (dataflow_set
*, rtx
);
332 static void set_variable_part (dataflow_set
*, rtx
, tree
, HOST_WIDE_INT
);
333 static void delete_variable_part (dataflow_set
*, rtx
, tree
, HOST_WIDE_INT
);
334 static int emit_note_insn_var_location (void **, void *);
335 static void emit_notes_for_changes (rtx
, enum emit_note_where
);
336 static int emit_notes_for_differences_1 (void **, void *);
337 static int emit_notes_for_differences_2 (void **, void *);
338 static void emit_notes_for_differences (rtx
, dataflow_set
*, dataflow_set
*);
339 static void emit_notes_in_bb (basic_block
);
340 static void vt_emit_notes (void);
342 static bool vt_get_decl_and_offset (rtx
, tree
*, HOST_WIDE_INT
*);
343 static void vt_add_function_parameters (void);
344 static void vt_initialize (void);
345 static void vt_finalize (void);
347 /* Given a SET, calculate the amount of stack adjustment it contains
348 PRE- and POST-modifying stack pointer.
349 This function is similar to stack_adjust_offset. */
352 stack_adjust_offset_pre_post (rtx pattern
, HOST_WIDE_INT
*pre
,
355 rtx src
= SET_SRC (pattern
);
356 rtx dest
= SET_DEST (pattern
);
359 if (dest
== stack_pointer_rtx
)
361 /* (set (reg sp) (plus (reg sp) (const_int))) */
362 code
= GET_CODE (src
);
363 if (! (code
== PLUS
|| code
== MINUS
)
364 || XEXP (src
, 0) != stack_pointer_rtx
365 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
369 *post
+= INTVAL (XEXP (src
, 1));
371 *post
-= INTVAL (XEXP (src
, 1));
373 else if (GET_CODE (dest
) == MEM
)
375 /* (set (mem (pre_dec (reg sp))) (foo)) */
376 src
= XEXP (dest
, 0);
377 code
= GET_CODE (src
);
383 if (XEXP (src
, 0) == stack_pointer_rtx
)
385 rtx val
= XEXP (XEXP (src
, 1), 1);
386 /* We handle only adjustments by constant amount. */
387 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
388 GET_CODE (val
) != CONST_INT
)
390 if (code
== PRE_MODIFY
)
391 *pre
-= INTVAL (val
);
393 *post
-= INTVAL (val
);
399 if (XEXP (src
, 0) == stack_pointer_rtx
)
401 *pre
+= GET_MODE_SIZE (GET_MODE (dest
));
407 if (XEXP (src
, 0) == stack_pointer_rtx
)
409 *post
+= GET_MODE_SIZE (GET_MODE (dest
));
415 if (XEXP (src
, 0) == stack_pointer_rtx
)
417 *pre
-= GET_MODE_SIZE (GET_MODE (dest
));
423 if (XEXP (src
, 0) == stack_pointer_rtx
)
425 *post
-= GET_MODE_SIZE (GET_MODE (dest
));
436 /* Given an INSN, calculate the amount of stack adjustment it contains
437 PRE- and POST-modifying stack pointer. */
440 insn_stack_adjust_offset_pre_post (rtx insn
, HOST_WIDE_INT
*pre
,
446 if (GET_CODE (PATTERN (insn
)) == SET
)
447 stack_adjust_offset_pre_post (PATTERN (insn
), pre
, post
);
448 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
449 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
453 /* There may be stack adjustments inside compound insns. Search
455 for ( i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
456 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
457 stack_adjust_offset_pre_post (XVECEXP (PATTERN (insn
), 0, i
),
462 /* Compute stack adjustment in basic block BB. */
465 bb_stack_adjust_offset (basic_block bb
)
467 HOST_WIDE_INT offset
;
470 offset
= VTI (bb
)->in
.stack_adjust
;
471 for (i
= 0; i
< VTI (bb
)->n_mos
; i
++)
473 if (VTI (bb
)->mos
[i
].type
== MO_ADJUST
)
474 offset
+= VTI (bb
)->mos
[i
].u
.adjust
;
475 else if (VTI (bb
)->mos
[i
].type
!= MO_CALL
)
477 if (GET_CODE (VTI (bb
)->mos
[i
].u
.loc
) == MEM
)
479 VTI (bb
)->mos
[i
].u
.loc
480 = adjust_stack_reference (VTI (bb
)->mos
[i
].u
.loc
, -offset
);
484 VTI (bb
)->out
.stack_adjust
= offset
;
487 /* Compute stack adjustment caused by function prolog. */
490 prologue_stack_adjust (void)
492 HOST_WIDE_INT offset
= 0;
493 basic_block bb
= ENTRY_BLOCK_PTR
->next_bb
;
500 end
= NEXT_INSN (BB_END (bb
));
501 for (insn
= BB_HEAD (bb
); insn
!= end
; insn
= NEXT_INSN (insn
))
503 if (GET_CODE (insn
) == NOTE
504 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_PROLOGUE_END
)
511 insn_stack_adjust_offset_pre_post (insn
, &tmp
, &tmp
);
519 /* Compute stack adjustments for all blocks by traversing DFS tree.
520 Return true when the adjustments on all incoming edges are consistent.
521 Heavily borrowed from flow_depth_first_order_compute. */
524 vt_stack_adjustments (void)
529 /* Initialize entry block. */
530 VTI (ENTRY_BLOCK_PTR
)->visited
= true;
531 VTI (ENTRY_BLOCK_PTR
)->out
.stack_adjust
= 0;
533 /* Allocate stack for back-tracking up CFG. */
534 stack
= xmalloc ((n_basic_blocks
+ 1) * sizeof (edge
));
537 /* Push the first edge on to the stack. */
538 stack
[sp
++] = ENTRY_BLOCK_PTR
->succ
;
546 /* Look at the edge on the top of the stack. */
551 /* Check if the edge destination has been visited yet. */
552 if (!VTI (dest
)->visited
)
554 VTI (dest
)->visited
= true;
555 VTI (dest
)->in
.stack_adjust
= VTI (src
)->out
.stack_adjust
;
556 bb_stack_adjust_offset (dest
);
559 /* Since the DEST node has been visited for the first
560 time, check its successors. */
561 stack
[sp
++] = dest
->succ
;
565 /* Check whether the adjustments on the edges are the same. */
566 if (VTI (dest
)->in
.stack_adjust
!= VTI (src
)->out
.stack_adjust
)
573 /* Go to the next edge. */
574 stack
[sp
- 1] = e
->succ_next
;
576 /* Return to previous level if there are no more edges. */
585 /* Adjust stack reference MEM by ADJUSTMENT bytes and return the new rtx. */
588 adjust_stack_reference (rtx mem
, HOST_WIDE_INT adjustment
)
593 adjusted_mem
= copy_rtx (mem
);
594 XEXP (adjusted_mem
, 0) = replace_rtx (XEXP (adjusted_mem
, 0),
596 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
597 GEN_INT (adjustment
)));
598 tmp
= simplify_rtx (XEXP (adjusted_mem
, 0));
600 XEXP (adjusted_mem
, 0) = tmp
;
605 /* The hash function for variable_htab, computes the hash value
606 from the declaration of variable X. */
609 variable_htab_hash (const void *x
)
611 const variable v
= (const variable
) x
;
613 return (VARIABLE_HASH_VAL (v
->decl
));
616 /* Compare the declaration of variable X with declaration Y. */
619 variable_htab_eq (const void *x
, const void *y
)
621 const variable v
= (const variable
) x
;
622 const tree decl
= (const tree
) y
;
624 return (VARIABLE_HASH_VAL (v
->decl
) == VARIABLE_HASH_VAL (decl
));
627 /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
630 variable_htab_free (void *elem
)
633 variable var
= (variable
) elem
;
634 location_chain node
, next
;
636 #ifdef ENABLE_CHECKING
637 if (var
->refcount
<= 0)
642 if (var
->refcount
> 0)
645 for (i
= 0; i
< var
->n_var_parts
; i
++)
647 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= next
)
650 pool_free (loc_chain_pool
, node
);
652 var
->var_part
[i
].loc_chain
= NULL
;
654 pool_free (var_pool
, var
);
657 /* Initialize the set (array) SET of attrs to empty lists. */
660 init_attrs_list_set (attrs
*set
)
664 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
668 /* Make the list *LISTP empty. */
671 attrs_list_clear (attrs
*listp
)
675 for (list
= *listp
; list
; list
= next
)
678 pool_free (attrs_pool
, list
);
683 /* Return true if the pair of DECL and OFFSET is the member of the LIST. */
686 attrs_list_member (attrs list
, tree decl
, HOST_WIDE_INT offset
)
688 for (; list
; list
= list
->next
)
689 if (list
->decl
== decl
&& list
->offset
== offset
)
694 /* Insert the triplet DECL, OFFSET, LOC to the list *LISTP. */
697 attrs_list_insert (attrs
*listp
, tree decl
, HOST_WIDE_INT offset
, rtx loc
)
701 list
= pool_alloc (attrs_pool
);
704 list
->offset
= offset
;
709 /* Copy all nodes from SRC and create a list *DSTP of the copies. */
712 attrs_list_copy (attrs
*dstp
, attrs src
)
716 attrs_list_clear (dstp
);
717 for (; src
; src
= src
->next
)
719 n
= pool_alloc (attrs_pool
);
722 n
->offset
= src
->offset
;
728 /* Add all nodes from SRC which are not in *DSTP to *DSTP. */
731 attrs_list_union (attrs
*dstp
, attrs src
)
733 for (; src
; src
= src
->next
)
735 if (!attrs_list_member (*dstp
, src
->decl
, src
->offset
))
736 attrs_list_insert (dstp
, src
->decl
, src
->offset
, src
->loc
);
740 /* Delete all variables from hash table VARS. */
743 vars_clear (htab_t vars
)
748 /* Return a copy of a variable VAR and insert it to dataflow set SET. */
751 unshare_variable (dataflow_set
*set
, variable var
)
757 new_var
= pool_alloc (var_pool
);
758 new_var
->decl
= var
->decl
;
759 new_var
->refcount
= 1;
761 new_var
->n_var_parts
= var
->n_var_parts
;
763 for (i
= 0; i
< var
->n_var_parts
; i
++)
766 location_chain
*nextp
;
768 new_var
->var_part
[i
].offset
= var
->var_part
[i
].offset
;
769 nextp
= &new_var
->var_part
[i
].loc_chain
;
770 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
772 location_chain new_lc
;
774 new_lc
= pool_alloc (loc_chain_pool
);
776 new_lc
->loc
= node
->loc
;
779 nextp
= &new_lc
->next
;
782 /* We are at the basic block boundary when copying variable description
783 so set the CUR_LOC to be the first element of the chain. */
784 if (new_var
->var_part
[i
].loc_chain
)
785 new_var
->var_part
[i
].cur_loc
= new_var
->var_part
[i
].loc_chain
->loc
;
787 new_var
->var_part
[i
].cur_loc
= NULL
;
790 slot
= htab_find_slot_with_hash (set
->vars
, new_var
->decl
,
791 VARIABLE_HASH_VAL (new_var
->decl
),
797 /* Add a variable from *SLOT to hash table DATA and increase its reference
801 vars_copy_1 (void **slot
, void *data
)
803 htab_t dst
= (htab_t
) data
;
806 src
= *(variable
*) slot
;
809 dstp
= (variable
*) htab_find_slot_with_hash (dst
, src
->decl
,
810 VARIABLE_HASH_VAL (src
->decl
),
814 /* Continue traversing the hash table. */
818 /* Copy all variables from hash table SRC to hash table DST. */
821 vars_copy (htab_t dst
, htab_t src
)
824 htab_traverse (src
, vars_copy_1
, dst
);
827 /* Delete current content of register LOC in dataflow set SET
828 and set the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). */
831 var_reg_delete_and_set (dataflow_set
*set
, rtx loc
)
833 tree decl
= REG_EXPR (loc
);
834 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
838 nextp
= &set
->regs
[REGNO (loc
)];
839 for (node
= *nextp
; node
; node
= next
)
842 if (node
->decl
!= decl
|| node
->offset
!= offset
)
844 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
845 pool_free (attrs_pool
, node
);
854 if (set
->regs
[REGNO (loc
)] == NULL
)
855 attrs_list_insert (&set
->regs
[REGNO (loc
)], decl
, offset
, loc
);
856 set_variable_part (set
, loc
, decl
, offset
);
859 /* Delete current content of register LOC in dataflow set SET. */
862 var_reg_delete (dataflow_set
*set
, rtx loc
)
864 attrs
*reg
= &set
->regs
[REGNO (loc
)];
867 for (node
= *reg
; node
; node
= next
)
870 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
871 pool_free (attrs_pool
, node
);
876 /* Delete content of register with number REGNO in dataflow set SET. */
879 var_regno_delete (dataflow_set
*set
, int regno
)
881 attrs
*reg
= &set
->regs
[regno
];
884 for (node
= *reg
; node
; node
= next
)
887 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
888 pool_free (attrs_pool
, node
);
893 /* Delete and set the location part of variable MEM_EXPR (LOC)
894 in dataflow set SET to LOC.
895 Adjust the address first if it is stack pointer based. */
898 var_mem_delete_and_set (dataflow_set
*set
, rtx loc
)
900 tree decl
= MEM_EXPR (loc
);
901 HOST_WIDE_INT offset
= MEM_OFFSET (loc
) ? INTVAL (MEM_OFFSET (loc
)) : 0;
903 set_variable_part (set
, loc
, decl
, offset
);
906 /* Delete the location part LOC from dataflow set SET.
907 Adjust the address first if it is stack pointer based. */
910 var_mem_delete (dataflow_set
*set
, rtx loc
)
912 tree decl
= MEM_EXPR (loc
);
913 HOST_WIDE_INT offset
= MEM_OFFSET (loc
) ? INTVAL (MEM_OFFSET (loc
)) : 0;
915 delete_variable_part (set
, loc
, decl
, offset
);
918 /* Initialize dataflow set SET to be empty.
919 VARS_SIZE is the initial size of hash table VARS. */
922 dataflow_set_init (dataflow_set
*set
, int vars_size
)
924 init_attrs_list_set (set
->regs
);
925 set
->vars
= htab_create (vars_size
, variable_htab_hash
, variable_htab_eq
,
927 set
->stack_adjust
= 0;
930 /* Delete the contents of dataflow set SET. */
933 dataflow_set_clear (dataflow_set
*set
)
937 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
938 attrs_list_clear (&set
->regs
[i
]);
940 vars_clear (set
->vars
);
943 /* Copy the contents of dataflow set SRC to DST. */
946 dataflow_set_copy (dataflow_set
*dst
, dataflow_set
*src
)
950 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
951 attrs_list_copy (&dst
->regs
[i
], src
->regs
[i
]);
953 vars_copy (dst
->vars
, src
->vars
);
954 dst
->stack_adjust
= src
->stack_adjust
;
957 /* Information for merging lists of locations for a given offset of variable.
959 struct variable_union_info
961 /* Node of the location chain. */
964 /* The sum of positions in the input chains. */
967 /* The position in the chains of SRC and DST dataflow sets. */
972 /* Compare function for qsort, order the structures by POS element. */
975 variable_union_info_cmp_pos (const void *n1
, const void *n2
)
977 const struct variable_union_info
*i1
= n1
;
978 const struct variable_union_info
*i2
= n2
;
980 if (i1
->pos
!= i2
->pos
)
981 return i1
->pos
- i2
->pos
;
983 return (i1
->pos_dst
- i2
->pos_dst
);
986 /* Compute union of location parts of variable *SLOT and the same variable
987 from hash table DATA. Compute "sorted" union of the location chains
988 for common offsets, i.e. the locations of a variable part are sorted by
989 a priority where the priority is the sum of the positions in the 2 chains
990 (if a location is only in one list the position in the second list is
991 defined to be larger than the length of the chains).
992 When we are updating the location parts the newest location is in the
993 beginning of the chain, so when we do the described "sorted" union
994 we keep the newest locations in the beginning. */
997 variable_union (void **slot
, void *data
)
999 variable src
, dst
, *dstp
;
1000 dataflow_set
*set
= (dataflow_set
*) data
;
1003 src
= *(variable
*) slot
;
1004 dstp
= (variable
*) htab_find_slot_with_hash (set
->vars
, src
->decl
,
1005 VARIABLE_HASH_VAL (src
->decl
),
1011 /* If CUR_LOC of some variable part is not the first element of
1012 the location chain we are going to change it so we have to make
1013 a copy of the variable. */
1014 for (k
= 0; k
< src
->n_var_parts
; k
++)
1016 if (src
->var_part
[k
].loc_chain
)
1018 #ifdef ENABLE_CHECKING
1019 if (src
->var_part
[k
].cur_loc
== NULL
)
1022 if (src
->var_part
[k
].cur_loc
!= src
->var_part
[k
].loc_chain
->loc
)
1025 #ifdef ENABLE_CHECKING
1028 if (src
->var_part
[k
].cur_loc
!= NULL
)
1033 if (k
< src
->n_var_parts
)
1034 unshare_variable (set
, src
);
1038 /* Continue traversing the hash table. */
1044 #ifdef ENABLE_CHECKING
1045 if (src
->n_var_parts
== 0)
1049 /* Count the number of location parts, result is K. */
1050 for (i
= 0, j
= 0, k
= 0;
1051 i
< src
->n_var_parts
&& j
< dst
->n_var_parts
; k
++)
1053 if (src
->var_part
[i
].offset
== dst
->var_part
[j
].offset
)
1058 else if (src
->var_part
[i
].offset
< dst
->var_part
[j
].offset
)
1063 k
+= src
->n_var_parts
- i
;
1064 k
+= dst
->n_var_parts
- j
;
1065 #ifdef ENABLE_CHECKING
1066 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
1067 thus there are at most MAX_VAR_PARTS different offsets. */
1068 if (k
> MAX_VAR_PARTS
)
1072 if (dst
->refcount
> 1 && dst
->n_var_parts
!= k
)
1073 dst
= unshare_variable (set
, dst
);
1075 i
= src
->n_var_parts
- 1;
1076 j
= dst
->n_var_parts
- 1;
1077 dst
->n_var_parts
= k
;
1079 for (k
--; k
>= 0; k
--)
1081 location_chain node
, node2
;
1083 if (i
>= 0 && j
>= 0
1084 && src
->var_part
[i
].offset
== dst
->var_part
[j
].offset
)
1086 /* Compute the "sorted" union of the chains, i.e. the locations which
1087 are in both chains go first, they are sorted by the sum of
1088 positions in the chains. */
1091 struct variable_union_info
*vui
;
1093 /* If DST is shared compare the location chains.
1094 If they are different we will modify the chain in DST with
1095 high probability so make a copy of DST. */
1096 if (dst
->refcount
> 1)
1098 for (node
= src
->var_part
[i
].loc_chain
,
1099 node2
= dst
->var_part
[j
].loc_chain
; node
&& node2
;
1100 node
= node
->next
, node2
= node2
->next
)
1102 if (!((GET_CODE (node2
->loc
) == REG
1103 && GET_CODE (node
->loc
) == REG
1104 && REGNO (node2
->loc
) == REGNO (node
->loc
))
1105 || rtx_equal_p (node2
->loc
, node
->loc
)))
1109 dst
= unshare_variable (set
, dst
);
1113 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1116 for (node
= dst
->var_part
[j
].loc_chain
; node
; node
= node
->next
)
1118 vui
= xcalloc (src_l
+ dst_l
, sizeof (struct variable_union_info
));
1120 /* Fill in the locations from DST. */
1121 for (node
= dst
->var_part
[j
].loc_chain
, jj
= 0; node
;
1122 node
= node
->next
, jj
++)
1125 vui
[jj
].pos_dst
= jj
;
1127 /* Value larger than a sum of 2 valid positions. */
1128 vui
[jj
].pos_src
= src_l
+ dst_l
;
1131 /* Fill in the locations from SRC. */
1133 for (node
= src
->var_part
[i
].loc_chain
, ii
= 0; node
;
1134 node
= node
->next
, ii
++)
1136 /* Find location from NODE. */
1137 for (jj
= 0; jj
< dst_l
; jj
++)
1139 if ((GET_CODE (vui
[jj
].lc
->loc
) == REG
1140 && GET_CODE (node
->loc
) == REG
1141 && REGNO (vui
[jj
].lc
->loc
) == REGNO (node
->loc
))
1142 || rtx_equal_p (vui
[jj
].lc
->loc
, node
->loc
))
1144 vui
[jj
].pos_src
= ii
;
1148 if (jj
>= dst_l
) /* The location has not been found. */
1150 location_chain new_node
;
1152 /* Copy the location from SRC. */
1153 new_node
= pool_alloc (loc_chain_pool
);
1154 new_node
->loc
= node
->loc
;
1155 vui
[n
].lc
= new_node
;
1156 vui
[n
].pos_src
= ii
;
1157 vui
[n
].pos_dst
= src_l
+ dst_l
;
1162 for (ii
= 0; ii
< src_l
+ dst_l
; ii
++)
1163 vui
[ii
].pos
= vui
[ii
].pos_src
+ vui
[ii
].pos_dst
;
1165 qsort (vui
, n
, sizeof (struct variable_union_info
),
1166 variable_union_info_cmp_pos
);
1168 /* Reconnect the nodes in sorted order. */
1169 for (ii
= 1; ii
< n
; ii
++)
1170 vui
[ii
- 1].lc
->next
= vui
[ii
].lc
;
1171 vui
[n
- 1].lc
->next
= NULL
;
1173 dst
->var_part
[k
].loc_chain
= vui
[0].lc
;
1174 dst
->var_part
[k
].offset
= dst
->var_part
[j
].offset
;
1180 else if ((i
>= 0 && j
>= 0
1181 && src
->var_part
[i
].offset
< dst
->var_part
[j
].offset
)
1184 dst
->var_part
[k
] = dst
->var_part
[j
];
1187 else if ((i
>= 0 && j
>= 0
1188 && src
->var_part
[i
].offset
> dst
->var_part
[j
].offset
)
1191 location_chain
*nextp
;
1193 /* Copy the chain from SRC. */
1194 nextp
= &dst
->var_part
[k
].loc_chain
;
1195 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1197 location_chain new_lc
;
1199 new_lc
= pool_alloc (loc_chain_pool
);
1200 new_lc
->next
= NULL
;
1201 new_lc
->loc
= node
->loc
;
1204 nextp
= &new_lc
->next
;
1207 dst
->var_part
[k
].offset
= src
->var_part
[i
].offset
;
1211 /* We are at the basic block boundary when computing union
1212 so set the CUR_LOC to be the first element of the chain. */
1213 if (dst
->var_part
[k
].loc_chain
)
1214 dst
->var_part
[k
].cur_loc
= dst
->var_part
[k
].loc_chain
->loc
;
1216 dst
->var_part
[k
].cur_loc
= NULL
;
1219 /* Continue traversing the hash table. */
1223 /* Compute union of dataflow sets SRC and DST and store it to DST. */
1226 dataflow_set_union (dataflow_set
*dst
, dataflow_set
*src
)
1230 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1231 attrs_list_union (&dst
->regs
[i
], src
->regs
[i
]);
1233 htab_traverse (src
->vars
, variable_union
, dst
);
1236 /* Flag whether two dataflow sets being compared contain different data. */
1238 dataflow_set_different_value
;
1241 variable_part_different_p (variable_part
*vp1
, variable_part
*vp2
)
1243 location_chain lc1
, lc2
;
1245 for (lc1
= vp1
->loc_chain
; lc1
; lc1
= lc1
->next
)
1247 for (lc2
= vp2
->loc_chain
; lc2
; lc2
= lc2
->next
)
1249 if (GET_CODE (lc1
->loc
) == REG
&& GET_CODE (lc2
->loc
) == REG
)
1251 if (REGNO (lc1
->loc
) == REGNO (lc2
->loc
))
1254 if (rtx_equal_p (lc1
->loc
, lc2
->loc
))
1263 /* Return true if variables VAR1 and VAR2 are different (only the first
1264 location in the list of locations is checked for each offset,
1265 i.e. when true is returned a note should be emitted). */
1268 variable_different_p (variable var1
, variable var2
)
1275 if (var1
->n_var_parts
!= var2
->n_var_parts
)
1278 for (i
= 0; i
< var1
->n_var_parts
; i
++)
1280 if (var1
->var_part
[i
].offset
!= var2
->var_part
[i
].offset
)
1282 if (variable_part_different_p (&var1
->var_part
[i
], &var2
->var_part
[i
]))
1284 if (variable_part_different_p (&var2
->var_part
[i
], &var1
->var_part
[i
]))
1290 /* Compare variable *SLOT with the same variable in hash table DATA
1291 and set DATAFLOW_SET_DIFFERENT_VALUE if they are different. */
1294 dataflow_set_different_1 (void **slot
, void *data
)
1296 htab_t htab
= (htab_t
) data
;
1297 variable var1
, var2
;
1299 var1
= *(variable
*) slot
;
1300 var2
= htab_find_with_hash (htab
, var1
->decl
,
1301 VARIABLE_HASH_VAL (var1
->decl
));
1304 dataflow_set_different_value
= true;
1306 /* Stop traversing the hash table. */
1310 if (variable_different_p (var1
, var2
))
1312 dataflow_set_different_value
= true;
1314 /* Stop traversing the hash table. */
1318 /* Continue traversing the hash table. */
1322 /* Compare variable *SLOT with the same variable in hash table DATA
1323 and set DATAFLOW_SET_DIFFERENT_VALUE if they are different. */
1326 dataflow_set_different_2 (void **slot
, void *data
)
1328 htab_t htab
= (htab_t
) data
;
1329 variable var1
, var2
;
1331 var1
= *(variable
*) slot
;
1332 var2
= htab_find_with_hash (htab
, var1
->decl
,
1333 VARIABLE_HASH_VAL (var1
->decl
));
1336 dataflow_set_different_value
= true;
1338 /* Stop traversing the hash table. */
1342 #ifdef ENABLE_CHECKING
1343 /* If both variables are defined they have been already checked for
1345 if (variable_different_p (var1
, var2
))
1349 /* Continue traversing the hash table. */
1353 /* Return true if dataflow sets OLD_SET and NEW_SET differ. */
1356 dataflow_set_different (dataflow_set
*old_set
, dataflow_set
*new_set
)
1358 dataflow_set_different_value
= false;
1360 htab_traverse (old_set
->vars
, dataflow_set_different_1
, new_set
->vars
);
1361 if (!dataflow_set_different_value
)
1363 /* We have compared the variables which are in both hash tables
1364 so now only check whether there are some variables in NEW_SET->VARS
1365 which are not in OLD_SET->VARS. */
1366 htab_traverse (new_set
->vars
, dataflow_set_different_2
, old_set
->vars
);
1368 return dataflow_set_different_value
;
1371 /* Free the contents of dataflow set SET. */
1374 dataflow_set_destroy (dataflow_set
*set
)
1378 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1379 attrs_list_clear (&set
->regs
[i
]);
1381 htab_delete (set
->vars
);
1385 /* Return true if RTL X contains a SYMBOL_REF. */
1388 contains_symbol_ref (rtx x
)
1397 code
= GET_CODE (x
);
1398 if (code
== SYMBOL_REF
)
1401 fmt
= GET_RTX_FORMAT (code
);
1402 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1406 if (contains_symbol_ref (XEXP (x
, i
)))
1409 else if (fmt
[i
] == 'E')
1412 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1413 if (contains_symbol_ref (XVECEXP (x
, i
, j
)))
1421 /* Shall EXPR be tracked? */
1424 track_expr_p (tree expr
)
1428 /* If EXPR is not a parameter or a variable do not track it. */
1429 if (TREE_CODE (expr
) != VAR_DECL
&& TREE_CODE (expr
) != PARM_DECL
)
1432 /* It also must have a name... */
1433 if (!DECL_NAME (expr
))
1436 /* ... and a RTL assigned to it. */
1437 decl_rtl
= DECL_RTL_IF_SET (expr
);
1441 /* Do not track EXPR if it should be ignored for debugging purposes. */
1442 if (DECL_IGNORED_P (expr
))
1445 /* Do not track global variables until we are able to emit correct location
1447 if (TREE_STATIC (expr
))
1450 /* When the EXPR is a DECL for alias of some variable (see example)
1451 the TREE_STATIC flag is not used. Disable tracking all DECLs whose
1452 DECL_RTL contains SYMBOL_REF.
1455 extern char **_dl_argv_internal __attribute__ ((alias ("_dl_argv")));
1458 if (GET_CODE (decl_rtl
) == MEM
1459 && contains_symbol_ref (XEXP (decl_rtl
, 0)))
1462 /* If RTX is a memory it should not be very large (because it would be
1463 an array or struct). */
1464 if (GET_CODE (decl_rtl
) == MEM
)
1466 /* Do not track structures and arrays. */
1467 if (GET_MODE (decl_rtl
) == BLKmode
)
1469 if (MEM_SIZE (decl_rtl
)
1470 && INTVAL (MEM_SIZE (decl_rtl
)) > MAX_VAR_PARTS
)
1477 /* Count uses (register and memory references) LOC which will be tracked.
1478 INSN is instruction which the LOC is part of. */
1481 count_uses (rtx
*loc
, void *insn
)
1483 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1485 if (GET_CODE (*loc
) == REG
)
1487 #ifdef ENABLE_CHECKING
1488 if (REGNO (*loc
) >= FIRST_PSEUDO_REGISTER
)
1493 else if (GET_CODE (*loc
) == MEM
1495 && track_expr_p (MEM_EXPR (*loc
)))
1503 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
1506 count_uses_1 (rtx
*x
, void *insn
)
1508 for_each_rtx (x
, count_uses
, insn
);
1511 /* Count stores (register and memory references) LOC which will be tracked.
1512 INSN is instruction which the LOC is part of. */
1515 count_stores (rtx loc
, rtx expr ATTRIBUTE_UNUSED
, void *insn
)
1517 count_uses (&loc
, insn
);
1520 /* Add uses (register and memory references) LOC which will be tracked
1521 to VTI (bb)->mos. INSN is instruction which the LOC is part of. */
1524 add_uses (rtx
*loc
, void *insn
)
1526 if (GET_CODE (*loc
) == REG
)
1528 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1529 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1531 mo
->type
= ((REG_EXPR (*loc
) && track_expr_p (REG_EXPR (*loc
)))
1532 ? MO_USE
: MO_USE_NO_VAR
);
1534 mo
->insn
= (rtx
) insn
;
1536 else if (GET_CODE (*loc
) == MEM
1538 && track_expr_p (MEM_EXPR (*loc
)))
1540 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1541 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1545 mo
->insn
= (rtx
) insn
;
1551 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
1554 add_uses_1 (rtx
*x
, void *insn
)
1556 for_each_rtx (x
, add_uses
, insn
);
1559 /* Add stores (register and memory references) LOC which will be tracked
1560 to VTI (bb)->mos. EXPR is the RTL expression containing the store.
1561 INSN is instruction which the LOC is part of. */
1564 add_stores (rtx loc
, rtx expr
, void *insn
)
1566 if (GET_CODE (loc
) == REG
)
1568 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1569 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1571 mo
->type
= ((GET_CODE (expr
) != CLOBBER
&& REG_EXPR (loc
)
1572 && track_expr_p (REG_EXPR (loc
)))
1573 ? MO_SET
: MO_CLOBBER
);
1575 mo
->insn
= (rtx
) insn
;
1577 else if (GET_CODE (loc
) == MEM
1579 && track_expr_p (MEM_EXPR (loc
)))
1581 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1582 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1584 mo
->type
= GET_CODE (expr
) == CLOBBER
? MO_CLOBBER
: MO_SET
;
1586 mo
->insn
= (rtx
) insn
;
1590 /* Compute the changes of variable locations in the basic block BB. */
1593 compute_bb_dataflow (basic_block bb
)
1597 dataflow_set old_out
;
1598 dataflow_set
*in
= &VTI (bb
)->in
;
1599 dataflow_set
*out
= &VTI (bb
)->out
;
1601 dataflow_set_init (&old_out
, htab_elements (VTI (bb
)->out
.vars
) + 3);
1602 dataflow_set_copy (&old_out
, out
);
1603 dataflow_set_copy (out
, in
);
1605 n
= VTI (bb
)->n_mos
;
1606 for (i
= 0; i
< n
; i
++)
1608 switch (VTI (bb
)->mos
[i
].type
)
1611 for (r
= 0; r
< FIRST_PSEUDO_REGISTER
; r
++)
1612 if (TEST_HARD_REG_BIT (call_used_reg_set
, r
))
1613 var_regno_delete (out
, r
);
1619 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
1621 if (GET_CODE (loc
) == REG
)
1622 var_reg_delete_and_set (out
, loc
);
1623 else if (GET_CODE (loc
) == MEM
)
1624 var_mem_delete_and_set (out
, loc
);
1631 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
1633 if (GET_CODE (loc
) == REG
)
1634 var_reg_delete (out
, loc
);
1635 else if (GET_CODE (loc
) == MEM
)
1636 var_mem_delete (out
, loc
);
1644 out
->stack_adjust
+= VTI (bb
)->mos
[i
].u
.adjust
;
1645 base
= gen_rtx_MEM (Pmode
,
1646 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
1647 GEN_INT (out
->stack_adjust
)));
1648 set_frame_base_location (out
, base
);
1654 changed
= dataflow_set_different (&old_out
, out
);
1655 dataflow_set_destroy (&old_out
);
1659 /* Find the locations of variables in the whole function. */
1662 vt_find_locations (void)
1664 fibheap_t worklist
, pending
, fibheap_swap
;
1665 sbitmap visited
, in_worklist
, in_pending
, sbitmap_swap
;
1672 /* Compute reverse completion order of depth first search of the CFG
1673 so that the data-flow runs faster. */
1674 rc_order
= xmalloc (n_basic_blocks
* sizeof (int));
1675 bb_order
= xmalloc (last_basic_block
* sizeof (int));
1676 flow_depth_first_order_compute (NULL
, rc_order
);
1677 for (i
= 0; i
< n_basic_blocks
; i
++)
1678 bb_order
[rc_order
[i
]] = i
;
1681 worklist
= fibheap_new ();
1682 pending
= fibheap_new ();
1683 visited
= sbitmap_alloc (last_basic_block
);
1684 in_worklist
= sbitmap_alloc (last_basic_block
);
1685 in_pending
= sbitmap_alloc (last_basic_block
);
1686 sbitmap_zero (in_worklist
);
1687 sbitmap_zero (in_pending
);
1691 fibheap_insert (pending
, bb_order
[bb
->index
], bb
);
1692 SET_BIT (in_pending
, bb
->index
);
1695 while (!fibheap_empty (pending
))
1697 fibheap_swap
= pending
;
1699 worklist
= fibheap_swap
;
1700 sbitmap_swap
= in_pending
;
1701 in_pending
= in_worklist
;
1702 in_worklist
= sbitmap_swap
;
1704 sbitmap_zero (visited
);
1706 while (!fibheap_empty (worklist
))
1708 bb
= fibheap_extract_min (worklist
);
1709 RESET_BIT (in_worklist
, bb
->index
);
1710 if (!TEST_BIT (visited
, bb
->index
))
1714 SET_BIT (visited
, bb
->index
);
1716 /* Calculate the IN set as union of predecessor OUT sets. */
1717 dataflow_set_clear (&VTI (bb
)->in
);
1718 for (e
= bb
->pred
; e
; e
= e
->pred_next
)
1720 dataflow_set_union (&VTI (bb
)->in
, &VTI (e
->src
)->out
);
1723 changed
= compute_bb_dataflow (bb
);
1726 for (e
= bb
->succ
; e
; e
= e
->succ_next
)
1728 if (e
->dest
== EXIT_BLOCK_PTR
)
1734 if (TEST_BIT (visited
, e
->dest
->index
))
1736 if (!TEST_BIT (in_pending
, e
->dest
->index
))
1738 /* Send E->DEST to next round. */
1739 SET_BIT (in_pending
, e
->dest
->index
);
1740 fibheap_insert (pending
,
1741 bb_order
[e
->dest
->index
],
1745 else if (!TEST_BIT (in_worklist
, e
->dest
->index
))
1747 /* Add E->DEST to current round. */
1748 SET_BIT (in_worklist
, e
->dest
->index
);
1749 fibheap_insert (worklist
, bb_order
[e
->dest
->index
],
1759 fibheap_delete (worklist
);
1760 fibheap_delete (pending
);
1761 sbitmap_free (visited
);
1762 sbitmap_free (in_worklist
);
1763 sbitmap_free (in_pending
);
1766 /* Print the content of the LIST to dump file. */
1769 dump_attrs_list (attrs list
)
1771 for (; list
; list
= list
->next
)
1773 print_mem_expr (dump_file
, list
->decl
);
1774 fprintf (dump_file
, "+");
1775 fprintf (dump_file
, HOST_WIDE_INT_PRINT_DEC
, list
->offset
);
1777 fprintf (dump_file
, "\n");
1780 /* Print the information about variable *SLOT to dump file. */
1783 dump_variable (void **slot
, void *data ATTRIBUTE_UNUSED
)
1785 variable var
= *(variable
*) slot
;
1787 location_chain node
;
1789 fprintf (dump_file
, " name: %s\n",
1790 IDENTIFIER_POINTER (DECL_NAME (var
->decl
)));
1791 for (i
= 0; i
< var
->n_var_parts
; i
++)
1793 fprintf (dump_file
, " offset %ld\n",
1794 (long) var
->var_part
[i
].offset
);
1795 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1797 fprintf (dump_file
, " ");
1798 print_rtl_single (dump_file
, node
->loc
);
1802 /* Continue traversing the hash table. */
1806 /* Print the information about variables from hash table VARS to dump file. */
1809 dump_vars (htab_t vars
)
1811 if (htab_elements (vars
) > 0)
1813 fprintf (dump_file
, "Variables:\n");
1814 htab_traverse (vars
, dump_variable
, NULL
);
1818 /* Print the dataflow set SET to dump file. */
1821 dump_dataflow_set (dataflow_set
*set
)
1825 fprintf (dump_file
, "Stack adjustment: ");
1826 fprintf (dump_file
, HOST_WIDE_INT_PRINT_DEC
, set
->stack_adjust
);
1827 fprintf (dump_file
, "\n");
1828 for (i
= 1; i
< FIRST_PSEUDO_REGISTER
; i
++)
1832 fprintf (dump_file
, "Reg %d:", i
);
1833 dump_attrs_list (set
->regs
[i
]);
1836 dump_vars (set
->vars
);
1837 fprintf (dump_file
, "\n");
1840 /* Print the IN and OUT sets for each basic block to dump file. */
1843 dump_dataflow_sets (void)
1849 fprintf (dump_file
, "\nBasic block %d:\n", bb
->index
);
1850 fprintf (dump_file
, "IN:\n");
1851 dump_dataflow_set (&VTI (bb
)->in
);
1852 fprintf (dump_file
, "OUT:\n");
1853 dump_dataflow_set (&VTI (bb
)->out
);
1857 /* Add variable VAR to the hash table of changed variables and
1858 if it has no locations delete it from hash table HTAB. */
1861 variable_was_changed (variable var
, htab_t htab
)
1863 hashval_t hash
= VARIABLE_HASH_VAL (var
->decl
);
1869 slot
= (variable
*) htab_find_slot_with_hash (changed_variables
,
1870 var
->decl
, hash
, INSERT
);
1872 if (htab
&& var
->n_var_parts
== 0)
1877 empty_var
= pool_alloc (var_pool
);
1878 empty_var
->decl
= var
->decl
;
1879 empty_var
->refcount
= 1;
1880 empty_var
->n_var_parts
= 0;
1883 old
= htab_find_slot_with_hash (htab
, var
->decl
, hash
,
1886 htab_clear_slot (htab
, old
);
1895 #ifdef ENABLE_CHECKING
1899 if (var
->n_var_parts
== 0)
1901 void **slot
= htab_find_slot_with_hash (htab
, var
->decl
, hash
,
1904 htab_clear_slot (htab
, slot
);
1909 /* Set the location of frame_base_decl to LOC in dataflow set SET. This
1910 function expects that
1911 frame_base_decl has already one location for offset 0 in the variable table.
1915 set_frame_base_location (dataflow_set
*set
, rtx loc
)
1919 var
= htab_find_with_hash (set
->vars
, frame_base_decl
,
1920 VARIABLE_HASH_VAL (frame_base_decl
));
1921 #ifdef ENABLE_CHECKING
1924 if (var
->n_var_parts
!= 1)
1926 if (var
->var_part
[0].offset
!= 0)
1928 if (!var
->var_part
[0].loc_chain
)
1932 /* If frame_base_decl is shared unshare it first. */
1933 if (var
->refcount
> 1)
1934 var
= unshare_variable (set
, var
);
1936 var
->var_part
[0].loc_chain
->loc
= loc
;
1937 var
->var_part
[0].cur_loc
= loc
;
1938 variable_was_changed (var
, set
->vars
);
1941 /* Set the part of variable's location in the dataflow set SET. The variable
1942 part is specified by variable's declaration DECL and offset OFFSET and the
1943 part's location by LOC. */
1946 set_variable_part (dataflow_set
*set
, rtx loc
, tree decl
, HOST_WIDE_INT offset
)
1949 location_chain node
, next
;
1950 location_chain
*nextp
;
1954 slot
= htab_find_slot_with_hash (set
->vars
, decl
,
1955 VARIABLE_HASH_VAL (decl
), INSERT
);
1958 /* Create new variable information. */
1959 var
= pool_alloc (var_pool
);
1962 var
->n_var_parts
= 1;
1963 var
->var_part
[0].offset
= offset
;
1964 var
->var_part
[0].loc_chain
= NULL
;
1965 var
->var_part
[0].cur_loc
= NULL
;
1971 var
= (variable
) *slot
;
1973 /* Find the location part. */
1975 high
= var
->n_var_parts
;
1978 pos
= (low
+ high
) / 2;
1979 if (var
->var_part
[pos
].offset
< offset
)
1986 if (pos
< var
->n_var_parts
&& var
->var_part
[pos
].offset
== offset
)
1988 node
= var
->var_part
[pos
].loc_chain
;
1991 && ((GET_CODE (node
->loc
) == REG
&& GET_CODE (loc
) == REG
1992 && REGNO (node
->loc
) == REGNO (loc
))
1993 || rtx_equal_p (node
->loc
, loc
)))
1995 /* LOC is in the beginning of the chain so we have nothing
2001 /* We have to make a copy of a shared variable. */
2002 if (var
->refcount
> 1)
2003 var
= unshare_variable (set
, var
);
2008 /* We have not found the location part, new one will be created. */
2010 /* We have to make a copy of the shared variable. */
2011 if (var
->refcount
> 1)
2012 var
= unshare_variable (set
, var
);
2014 #ifdef ENABLE_CHECKING
2015 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
2016 thus there are at most MAX_VAR_PARTS different offsets. */
2017 if (var
->n_var_parts
>= MAX_VAR_PARTS
)
2021 /* We have to move the elements of array starting at index low to the
2023 for (high
= var
->n_var_parts
; high
> low
; high
--)
2024 var
->var_part
[high
] = var
->var_part
[high
- 1];
2027 var
->var_part
[pos
].offset
= offset
;
2028 var
->var_part
[pos
].loc_chain
= NULL
;
2029 var
->var_part
[pos
].cur_loc
= NULL
;
2033 /* Delete the location from the list. */
2034 nextp
= &var
->var_part
[pos
].loc_chain
;
2035 for (node
= var
->var_part
[pos
].loc_chain
; node
; node
= next
)
2038 if ((GET_CODE (node
->loc
) == REG
&& GET_CODE (loc
) == REG
2039 && REGNO (node
->loc
) == REGNO (loc
))
2040 || rtx_equal_p (node
->loc
, loc
))
2042 pool_free (loc_chain_pool
, node
);
2047 nextp
= &node
->next
;
2050 /* Add the location to the beginning. */
2051 node
= pool_alloc (loc_chain_pool
);
2053 node
->next
= var
->var_part
[pos
].loc_chain
;
2054 var
->var_part
[pos
].loc_chain
= node
;
2056 /* If no location was emitted do so. */
2057 if (var
->var_part
[pos
].cur_loc
== NULL
)
2059 var
->var_part
[pos
].cur_loc
= loc
;
2060 variable_was_changed (var
, set
->vars
);
2064 /* Delete the part of variable's location from dataflow set SET. The variable
2065 part is specified by variable's declaration DECL and offset OFFSET and the
2066 part's location by LOC. */
2069 delete_variable_part (dataflow_set
*set
, rtx loc
, tree decl
,
2070 HOST_WIDE_INT offset
)
2075 slot
= htab_find_slot_with_hash (set
->vars
, decl
, VARIABLE_HASH_VAL (decl
),
2079 variable var
= (variable
) *slot
;
2081 /* Find the location part. */
2083 high
= var
->n_var_parts
;
2086 pos
= (low
+ high
) / 2;
2087 if (var
->var_part
[pos
].offset
< offset
)
2094 if (pos
< var
->n_var_parts
&& var
->var_part
[pos
].offset
== offset
)
2096 location_chain node
, next
;
2097 location_chain
*nextp
;
2100 if (var
->refcount
> 1)
2102 /* If the variable contains the location part we have to
2103 make a copy of the variable. */
2104 for (node
= var
->var_part
[pos
].loc_chain
; node
;
2107 if ((GET_CODE (node
->loc
) == REG
&& GET_CODE (loc
) == REG
2108 && REGNO (node
->loc
) == REGNO (loc
))
2109 || rtx_equal_p (node
->loc
, loc
))
2111 var
= unshare_variable (set
, var
);
2117 /* Delete the location part. */
2118 nextp
= &var
->var_part
[pos
].loc_chain
;
2119 for (node
= *nextp
; node
; node
= next
)
2122 if ((GET_CODE (node
->loc
) == REG
&& GET_CODE (loc
) == REG
2123 && REGNO (node
->loc
) == REGNO (loc
))
2124 || rtx_equal_p (node
->loc
, loc
))
2126 pool_free (loc_chain_pool
, node
);
2131 nextp
= &node
->next
;
2134 /* If we have deleted the location which was last emitted
2135 we have to emit new location so add the variable to set
2136 of changed variables. */
2137 if (var
->var_part
[pos
].cur_loc
2138 && ((GET_CODE (loc
) == REG
2139 && GET_CODE (var
->var_part
[pos
].cur_loc
) == REG
2140 && REGNO (loc
) == REGNO (var
->var_part
[pos
].cur_loc
))
2141 || rtx_equal_p (loc
, var
->var_part
[pos
].cur_loc
)))
2144 if (var
->var_part
[pos
].loc_chain
)
2145 var
->var_part
[pos
].cur_loc
= var
->var_part
[pos
].loc_chain
->loc
;
2150 if (var
->var_part
[pos
].loc_chain
== NULL
)
2153 while (pos
< var
->n_var_parts
)
2155 var
->var_part
[pos
] = var
->var_part
[pos
+ 1];
2160 variable_was_changed (var
, set
->vars
);
2165 /* Emit the NOTE_INSN_VAR_LOCATION for variable *VARP. DATA contains
2166 additional parameters: WHERE specifies whether the note shall be emitted
2167 before of after instruction INSN. */
2170 emit_note_insn_var_location (void **varp
, void *data
)
2172 variable var
= *(variable
*) varp
;
2173 rtx insn
= ((emit_note_data
*)data
)->insn
;
2174 enum emit_note_where where
= ((emit_note_data
*)data
)->where
;
2178 HOST_WIDE_INT last_limit
;
2179 tree type_size_unit
;
2181 #ifdef ENABLE_CHECKING
2188 for (i
= 0; i
< var
->n_var_parts
; i
++)
2190 if (last_limit
< var
->var_part
[i
].offset
)
2196 = (var
->var_part
[i
].offset
2197 + GET_MODE_SIZE (GET_MODE (var
->var_part
[i
].loc_chain
->loc
)));
2199 type_size_unit
= TYPE_SIZE_UNIT (TREE_TYPE (var
->decl
));
2200 if ((unsigned HOST_WIDE_INT
) last_limit
< TREE_INT_CST_LOW (type_size_unit
))
2203 if (where
== EMIT_NOTE_AFTER_INSN
)
2204 note
= emit_note_after (NOTE_INSN_VAR_LOCATION
, insn
);
2206 note
= emit_note_before (NOTE_INSN_VAR_LOCATION
, insn
);
2210 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2213 else if (var
->n_var_parts
== 1)
2216 = gen_rtx_EXPR_LIST (VOIDmode
,
2217 var
->var_part
[0].loc_chain
->loc
,
2218 GEN_INT (var
->var_part
[0].offset
));
2220 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2223 else if (var
->n_var_parts
)
2225 rtx argp
[MAX_VAR_PARTS
];
2228 for (i
= 0; i
< var
->n_var_parts
; i
++)
2229 argp
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, var
->var_part
[i
].loc_chain
->loc
,
2230 GEN_INT (var
->var_part
[i
].offset
));
2231 parallel
= gen_rtx_PARALLEL (VOIDmode
,
2232 gen_rtvec_v (var
->n_var_parts
, argp
));
2233 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2237 htab_clear_slot (changed_variables
, varp
);
2239 /* When there are no location parts the variable has been already
2240 removed from hash table and a new empty variable was created.
2241 Free the empty variable. */
2242 if (var
->n_var_parts
== 0)
2244 pool_free (var_pool
, var
);
2247 /* Continue traversing the hash table. */
2251 /* Emit NOTE_INSN_VAR_LOCATION note for each variable from a chain
2252 CHANGED_VARIABLES and delete this chain. WHERE specifies whether the notes
2253 shall be emitted before of after instruction INSN. */
2256 emit_notes_for_changes (rtx insn
, enum emit_note_where where
)
2258 emit_note_data data
;
2262 htab_traverse (changed_variables
, emit_note_insn_var_location
, &data
);
2265 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it differs from the
2266 same variable in hash table DATA or is not there at all. */
2269 emit_notes_for_differences_1 (void **slot
, void *data
)
2271 htab_t new_vars
= (htab_t
) data
;
2272 variable old_var
, new_var
;
2274 old_var
= *(variable
*) slot
;
2275 new_var
= htab_find_with_hash (new_vars
, old_var
->decl
,
2276 VARIABLE_HASH_VAL (old_var
->decl
));
2280 /* Variable has disappeared. */
2283 empty_var
= pool_alloc (var_pool
);
2284 empty_var
->decl
= old_var
->decl
;
2285 empty_var
->refcount
= 1;
2286 empty_var
->n_var_parts
= 0;
2287 variable_was_changed (empty_var
, NULL
);
2289 else if (variable_different_p (old_var
, new_var
))
2291 variable_was_changed (new_var
, NULL
);
2294 /* Continue traversing the hash table. */
2298 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it is not in hash
2302 emit_notes_for_differences_2 (void **slot
, void *data
)
2304 htab_t old_vars
= (htab_t
) data
;
2305 variable old_var
, new_var
;
2307 new_var
= *(variable
*) slot
;
2308 old_var
= htab_find_with_hash (old_vars
, new_var
->decl
,
2309 VARIABLE_HASH_VAL (new_var
->decl
));
2312 /* Variable has appeared. */
2313 variable_was_changed (new_var
, NULL
);
2316 /* Continue traversing the hash table. */
2320 /* Emit notes before INSN for differences between dataflow sets OLD_SET and
2324 emit_notes_for_differences (rtx insn
, dataflow_set
*old_set
,
2325 dataflow_set
*new_set
)
2327 htab_traverse (old_set
->vars
, emit_notes_for_differences_1
, new_set
->vars
);
2328 htab_traverse (new_set
->vars
, emit_notes_for_differences_2
, old_set
->vars
);
2329 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2332 /* Emit the notes for changes of location parts in the basic block BB. */
2335 emit_notes_in_bb (basic_block bb
)
2340 dataflow_set_init (&set
, htab_elements (VTI (bb
)->in
.vars
) + 3);
2341 dataflow_set_copy (&set
, &VTI (bb
)->in
);
2343 for (i
= 0; i
< VTI (bb
)->n_mos
; i
++)
2345 rtx insn
= VTI (bb
)->mos
[i
].insn
;
2347 switch (VTI (bb
)->mos
[i
].type
)
2353 for (r
= 0; r
< FIRST_PSEUDO_REGISTER
; r
++)
2354 if (TEST_HARD_REG_BIT (call_used_reg_set
, r
))
2356 var_regno_delete (&set
, r
);
2358 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2365 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
2367 if (GET_CODE (loc
) == REG
)
2368 var_reg_delete_and_set (&set
, loc
);
2370 var_mem_delete_and_set (&set
, loc
);
2372 if (VTI (bb
)->mos
[i
].type
== MO_USE
)
2373 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2375 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2382 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
2384 if (GET_CODE (loc
) == REG
)
2385 var_reg_delete (&set
, loc
);
2387 var_mem_delete (&set
, loc
);
2389 if (VTI (bb
)->mos
[i
].type
== MO_USE_NO_VAR
)
2390 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2392 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2400 set
.stack_adjust
+= VTI (bb
)->mos
[i
].u
.adjust
;
2401 base
= gen_rtx_MEM (Pmode
,
2402 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
2403 GEN_INT (set
.stack_adjust
)));
2404 set_frame_base_location (&set
, base
);
2405 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2410 dataflow_set_destroy (&set
);
2413 /* Emit notes for the whole function. */
2416 vt_emit_notes (void)
2419 dataflow_set
*last_out
;
2422 #ifdef ENABLE_CHECKING
2423 if (htab_elements (changed_variables
))
2427 /* Enable emitting notes by functions (mainly by set_variable_part and
2428 delete_variable_part). */
2431 dataflow_set_init (&empty
, 7);
2436 /* Emit the notes for changes of variable locations between two
2437 subsequent basic blocks. */
2438 emit_notes_for_differences (BB_HEAD (bb
), last_out
, &VTI (bb
)->in
);
2440 /* Emit the notes for the changes in the basic block itself. */
2441 emit_notes_in_bb (bb
);
2443 last_out
= &VTI (bb
)->out
;
2445 dataflow_set_destroy (&empty
);
2449 /* If there is a declaration and offset associated with register/memory RTL
2450 assign declaration to *DECLP and offset to *OFFSETP, and return true. */
2453 vt_get_decl_and_offset (rtx rtl
, tree
*declp
, HOST_WIDE_INT
*offsetp
)
2455 if (GET_CODE (rtl
) == REG
)
2457 if (REG_ATTRS (rtl
))
2459 *declp
= REG_EXPR (rtl
);
2460 *offsetp
= REG_OFFSET (rtl
);
2464 else if (GET_CODE (rtl
) == MEM
)
2466 if (MEM_ATTRS (rtl
))
2468 *declp
= MEM_EXPR (rtl
);
2469 *offsetp
= MEM_OFFSET (rtl
) ? INTVAL (MEM_OFFSET (rtl
)) : 0;
2476 /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK. */
2479 vt_add_function_parameters (void)
2482 HOST_WIDE_INT stack_adjust
= 0;
2484 if (!frame_pointer_needed
)
2485 stack_adjust
= prologue_stack_adjust ();
2487 for (parm
= DECL_ARGUMENTS (current_function_decl
);
2488 parm
; parm
= TREE_CHAIN (parm
))
2490 rtx decl_rtl
= DECL_RTL_IF_SET (parm
);
2491 rtx incoming
= DECL_INCOMING_RTL (parm
);
2493 HOST_WIDE_INT offset
;
2496 if (TREE_CODE (parm
) != PARM_DECL
)
2499 if (!DECL_NAME (parm
))
2502 if (!decl_rtl
|| !incoming
)
2505 if (GET_MODE (decl_rtl
) == BLKmode
|| GET_MODE (incoming
) == BLKmode
)
2508 if (!vt_get_decl_and_offset (incoming
, &decl
, &offset
))
2509 if (!vt_get_decl_and_offset (decl_rtl
, &decl
, &offset
))
2515 #ifdef ENABLE_CHECKING
2520 incoming
= eliminate_regs (incoming
, 0, NULL_RTX
);
2521 if (!frame_pointer_needed
&& GET_CODE (incoming
) == MEM
)
2522 incoming
= adjust_stack_reference (incoming
, -stack_adjust
);
2523 out
= &VTI (ENTRY_BLOCK_PTR
)->out
;
2525 if (GET_CODE (incoming
) == REG
)
2527 #ifdef ENABLE_CHECKING
2528 if (REGNO (incoming
) >= FIRST_PSEUDO_REGISTER
)
2531 attrs_list_insert (&out
->regs
[REGNO (incoming
)],
2532 parm
, offset
, incoming
);
2533 set_variable_part (out
, incoming
, parm
, offset
);
2535 else if (GET_CODE (incoming
) == MEM
)
2537 set_variable_part (out
, incoming
, parm
, offset
);
2542 /* Allocate and initialize the data structures for variable tracking
2543 and parse the RTL to get the micro operations. */
2546 vt_initialize (void)
2550 alloc_aux_for_blocks (sizeof (struct variable_tracking_info_def
));
2555 HOST_WIDE_INT pre
, post
;
2557 /* Count the number of micro operations. */
2558 VTI (bb
)->n_mos
= 0;
2559 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
2560 insn
= NEXT_INSN (insn
))
2564 if (!frame_pointer_needed
)
2566 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
2572 note_uses (&PATTERN (insn
), count_uses_1
, insn
);
2573 note_stores (PATTERN (insn
), count_stores
, insn
);
2574 if (GET_CODE (insn
) == CALL_INSN
)
2579 /* Add the micro-operations to the array. */
2580 VTI (bb
)->mos
= xmalloc (VTI (bb
)->n_mos
2581 * sizeof (struct micro_operation_def
));
2582 VTI (bb
)->n_mos
= 0;
2583 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
2584 insn
= NEXT_INSN (insn
))
2590 if (!frame_pointer_needed
)
2592 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
2595 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2597 mo
->type
= MO_ADJUST
;
2603 n1
= VTI (bb
)->n_mos
;
2604 note_uses (&PATTERN (insn
), add_uses_1
, insn
);
2605 n2
= VTI (bb
)->n_mos
- 1;
2607 /* Order the MO_USEs to be before MO_USE_NO_VARs. */
2610 while (n1
< n2
&& VTI (bb
)->mos
[n1
].type
== MO_USE
)
2612 while (n1
< n2
&& VTI (bb
)->mos
[n2
].type
== MO_USE_NO_VAR
)
2618 sw
= VTI (bb
)->mos
[n1
];
2619 VTI (bb
)->mos
[n1
] = VTI (bb
)->mos
[n2
];
2620 VTI (bb
)->mos
[n2
] = sw
;
2624 if (GET_CODE (insn
) == CALL_INSN
)
2626 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2632 n1
= VTI (bb
)->n_mos
;
2633 note_stores (PATTERN (insn
), add_stores
, insn
);
2634 n2
= VTI (bb
)->n_mos
- 1;
2636 /* Order the MO_SETs to be before MO_CLOBBERs. */
2639 while (n1
< n2
&& VTI (bb
)->mos
[n1
].type
== MO_SET
)
2641 while (n1
< n2
&& VTI (bb
)->mos
[n2
].type
== MO_CLOBBER
)
2647 sw
= VTI (bb
)->mos
[n1
];
2648 VTI (bb
)->mos
[n1
] = VTI (bb
)->mos
[n2
];
2649 VTI (bb
)->mos
[n2
] = sw
;
2653 if (!frame_pointer_needed
&& post
)
2655 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2657 mo
->type
= MO_ADJUST
;
2658 mo
->u
.adjust
= post
;
2665 /* Init the IN and OUT sets. */
2668 VTI (bb
)->visited
= false;
2669 dataflow_set_init (&VTI (bb
)->in
, 7);
2670 dataflow_set_init (&VTI (bb
)->out
, 7);
2673 attrs_pool
= create_alloc_pool ("attrs_def pool",
2674 sizeof (struct attrs_def
), 1024);
2675 var_pool
= create_alloc_pool ("variable_def pool",
2676 sizeof (struct variable_def
), 64);
2677 loc_chain_pool
= create_alloc_pool ("location_chain_def pool",
2678 sizeof (struct location_chain_def
),
2680 changed_variables
= htab_create (10, variable_htab_hash
, variable_htab_eq
,
2682 vt_add_function_parameters ();
2684 if (!frame_pointer_needed
)
2688 /* Create fake variable for tracking stack pointer changes. */
2689 frame_base_decl
= make_node (VAR_DECL
);
2690 DECL_NAME (frame_base_decl
) = get_identifier ("___frame_base_decl");
2691 TREE_TYPE (frame_base_decl
) = char_type_node
;
2692 DECL_ARTIFICIAL (frame_base_decl
) = 1;
2694 /* Set its initial "location". */
2695 base
= gen_rtx_MEM (Pmode
, stack_pointer_rtx
);
2696 set_variable_part (&VTI (ENTRY_BLOCK_PTR
)->out
, base
, frame_base_decl
, 0);
2700 frame_base_decl
= NULL
;
2704 /* Free the data structures needed for variable tracking. */
2713 free (VTI (bb
)->mos
);
2718 dataflow_set_destroy (&VTI (bb
)->in
);
2719 dataflow_set_destroy (&VTI (bb
)->out
);
2721 free_aux_for_blocks ();
2722 free_alloc_pool (attrs_pool
);
2723 free_alloc_pool (var_pool
);
2724 free_alloc_pool (loc_chain_pool
);
2725 htab_delete (changed_variables
);
2728 /* The entry point to variable tracking pass. */
2731 variable_tracking_main (void)
2733 if (n_basic_blocks
> 500 && n_edges
/ n_basic_blocks
>= 20)
2736 mark_dfs_back_edges ();
2738 if (!frame_pointer_needed
)
2740 if (!vt_stack_adjustments ())
2747 vt_find_locations ();
2752 dump_dataflow_sets ();
2753 dump_flow_info (dump_file
);