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, 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) (DECL_UID (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 tree frame_base_decl
;
270 /* Stack adjust caused by function prologue. */
271 static HOST_WIDE_INT frame_stack_adjust
;
273 /* Local function prototypes. */
274 static void stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
276 static void insn_stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
278 static void bb_stack_adjust_offset (basic_block
);
279 static HOST_WIDE_INT
prologue_stack_adjust (void);
280 static bool vt_stack_adjustments (void);
281 static rtx
adjust_stack_reference (rtx
, HOST_WIDE_INT
);
282 static hashval_t
variable_htab_hash (const void *);
283 static int variable_htab_eq (const void *, const void *);
284 static void variable_htab_free (void *);
286 static void init_attrs_list_set (attrs
*);
287 static void attrs_list_clear (attrs
*);
288 static attrs
attrs_list_member (attrs
, tree
, HOST_WIDE_INT
);
289 static void attrs_list_insert (attrs
*, tree
, HOST_WIDE_INT
, rtx
);
290 static void attrs_list_copy (attrs
*, attrs
);
291 static void attrs_list_union (attrs
*, attrs
);
293 static void vars_clear (htab_t
);
294 static variable
unshare_variable (dataflow_set
*set
, variable var
);
295 static int vars_copy_1 (void **, void *);
296 static void vars_copy (htab_t
, htab_t
);
297 static void var_reg_delete_and_set (dataflow_set
*, rtx
);
298 static void var_reg_delete (dataflow_set
*, rtx
);
299 static void var_regno_delete (dataflow_set
*, int);
300 static void var_mem_delete_and_set (dataflow_set
*, rtx
);
301 static void var_mem_delete (dataflow_set
*, rtx
);
303 static void dataflow_set_init (dataflow_set
*, int);
304 static void dataflow_set_clear (dataflow_set
*);
305 static void dataflow_set_copy (dataflow_set
*, dataflow_set
*);
306 static int variable_union_info_cmp_pos (const void *, const void *);
307 static int variable_union (void **, void *);
308 static void dataflow_set_union (dataflow_set
*, dataflow_set
*);
309 static bool variable_part_different_p (variable_part
*, variable_part
*);
310 static bool variable_different_p (variable
, variable
, bool);
311 static int dataflow_set_different_1 (void **, void *);
312 static int dataflow_set_different_2 (void **, void *);
313 static bool dataflow_set_different (dataflow_set
*, dataflow_set
*);
314 static void dataflow_set_destroy (dataflow_set
*);
316 static bool contains_symbol_ref (rtx
);
317 static bool track_expr_p (tree
);
318 static int count_uses (rtx
*, void *);
319 static void count_uses_1 (rtx
*, void *);
320 static void count_stores (rtx
, rtx
, void *);
321 static int add_uses (rtx
*, void *);
322 static void add_uses_1 (rtx
*, void *);
323 static void add_stores (rtx
, rtx
, void *);
324 static bool compute_bb_dataflow (basic_block
);
325 static void vt_find_locations (void);
327 static void dump_attrs_list (attrs
);
328 static int dump_variable (void **, void *);
329 static void dump_vars (htab_t
);
330 static void dump_dataflow_set (dataflow_set
*);
331 static void dump_dataflow_sets (void);
333 static void variable_was_changed (variable
, htab_t
);
334 static void set_frame_base_location (dataflow_set
*, rtx
);
335 static void set_variable_part (dataflow_set
*, rtx
, tree
, HOST_WIDE_INT
);
336 static void delete_variable_part (dataflow_set
*, rtx
, tree
, HOST_WIDE_INT
);
337 static int emit_note_insn_var_location (void **, void *);
338 static void emit_notes_for_changes (rtx
, enum emit_note_where
);
339 static int emit_notes_for_differences_1 (void **, void *);
340 static int emit_notes_for_differences_2 (void **, void *);
341 static void emit_notes_for_differences (rtx
, dataflow_set
*, dataflow_set
*);
342 static void emit_notes_in_bb (basic_block
);
343 static void vt_emit_notes (void);
345 static bool vt_get_decl_and_offset (rtx
, tree
*, HOST_WIDE_INT
*);
346 static void vt_add_function_parameters (void);
347 static void vt_initialize (void);
348 static void vt_finalize (void);
350 /* Given a SET, calculate the amount of stack adjustment it contains
351 PRE- and POST-modifying stack pointer.
352 This function is similar to stack_adjust_offset. */
355 stack_adjust_offset_pre_post (rtx pattern
, HOST_WIDE_INT
*pre
,
358 rtx src
= SET_SRC (pattern
);
359 rtx dest
= SET_DEST (pattern
);
362 if (dest
== stack_pointer_rtx
)
364 /* (set (reg sp) (plus (reg sp) (const_int))) */
365 code
= GET_CODE (src
);
366 if (! (code
== PLUS
|| code
== MINUS
)
367 || XEXP (src
, 0) != stack_pointer_rtx
368 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
372 *post
+= INTVAL (XEXP (src
, 1));
374 *post
-= INTVAL (XEXP (src
, 1));
376 else if (MEM_P (dest
))
378 /* (set (mem (pre_dec (reg sp))) (foo)) */
379 src
= XEXP (dest
, 0);
380 code
= GET_CODE (src
);
386 if (XEXP (src
, 0) == stack_pointer_rtx
)
388 rtx val
= XEXP (XEXP (src
, 1), 1);
389 /* We handle only adjustments by constant amount. */
390 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
391 GET_CODE (val
) != CONST_INT
)
393 if (code
== PRE_MODIFY
)
394 *pre
-= INTVAL (val
);
396 *post
-= INTVAL (val
);
402 if (XEXP (src
, 0) == stack_pointer_rtx
)
404 *pre
+= GET_MODE_SIZE (GET_MODE (dest
));
410 if (XEXP (src
, 0) == stack_pointer_rtx
)
412 *post
+= GET_MODE_SIZE (GET_MODE (dest
));
418 if (XEXP (src
, 0) == stack_pointer_rtx
)
420 *pre
-= GET_MODE_SIZE (GET_MODE (dest
));
426 if (XEXP (src
, 0) == stack_pointer_rtx
)
428 *post
-= GET_MODE_SIZE (GET_MODE (dest
));
439 /* Given an INSN, calculate the amount of stack adjustment it contains
440 PRE- and POST-modifying stack pointer. */
443 insn_stack_adjust_offset_pre_post (rtx insn
, HOST_WIDE_INT
*pre
,
449 if (GET_CODE (PATTERN (insn
)) == SET
)
450 stack_adjust_offset_pre_post (PATTERN (insn
), pre
, post
);
451 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
452 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
456 /* There may be stack adjustments inside compound insns. Search
458 for ( i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
459 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
460 stack_adjust_offset_pre_post (XVECEXP (PATTERN (insn
), 0, i
),
465 /* Compute stack adjustment in basic block BB. */
468 bb_stack_adjust_offset (basic_block bb
)
470 HOST_WIDE_INT offset
;
473 offset
= VTI (bb
)->in
.stack_adjust
;
474 for (i
= 0; i
< VTI (bb
)->n_mos
; i
++)
476 if (VTI (bb
)->mos
[i
].type
== MO_ADJUST
)
477 offset
+= VTI (bb
)->mos
[i
].u
.adjust
;
478 else if (VTI (bb
)->mos
[i
].type
!= MO_CALL
)
480 if (MEM_P (VTI (bb
)->mos
[i
].u
.loc
))
482 VTI (bb
)->mos
[i
].u
.loc
483 = adjust_stack_reference (VTI (bb
)->mos
[i
].u
.loc
, -offset
);
487 VTI (bb
)->out
.stack_adjust
= offset
;
490 /* Compute stack adjustment caused by function prologue. */
493 prologue_stack_adjust (void)
495 HOST_WIDE_INT offset
= 0;
496 basic_block bb
= ENTRY_BLOCK_PTR
->next_bb
;
503 end
= NEXT_INSN (BB_END (bb
));
504 for (insn
= BB_HEAD (bb
); insn
!= end
; insn
= NEXT_INSN (insn
))
507 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_PROLOGUE_END
)
514 insn_stack_adjust_offset_pre_post (insn
, &tmp
, &tmp
);
522 /* Compute stack adjustments for all blocks by traversing DFS tree.
523 Return true when the adjustments on all incoming edges are consistent.
524 Heavily borrowed from flow_depth_first_order_compute. */
527 vt_stack_adjustments (void)
529 edge_iterator
*stack
;
532 /* Initialize entry block. */
533 VTI (ENTRY_BLOCK_PTR
)->visited
= true;
534 VTI (ENTRY_BLOCK_PTR
)->out
.stack_adjust
= frame_stack_adjust
;
536 /* Allocate stack for back-tracking up CFG. */
537 stack
= xmalloc ((n_basic_blocks
+ 1) * sizeof (edge_iterator
));
540 /* Push the first edge on to the stack. */
541 stack
[sp
++] = ei_start (ENTRY_BLOCK_PTR
->succs
);
549 /* Look at the edge on the top of the stack. */
551 src
= ei_edge (ei
)->src
;
552 dest
= ei_edge (ei
)->dest
;
554 /* Check if the edge destination has been visited yet. */
555 if (!VTI (dest
)->visited
)
557 VTI (dest
)->visited
= true;
558 VTI (dest
)->in
.stack_adjust
= VTI (src
)->out
.stack_adjust
;
559 bb_stack_adjust_offset (dest
);
561 if (EDGE_COUNT (dest
->succs
) > 0)
562 /* Since the DEST node has been visited for the first
563 time, check its successors. */
564 stack
[sp
++] = ei_start (dest
->succs
);
568 /* Check whether the adjustments on the edges are the same. */
569 if (VTI (dest
)->in
.stack_adjust
!= VTI (src
)->out
.stack_adjust
)
575 if (! ei_one_before_end_p (ei
))
576 /* Go to the next edge. */
577 ei_next (&stack
[sp
- 1]);
579 /* Return to previous level if there are no more edges. */
588 /* Adjust stack reference MEM by ADJUSTMENT bytes and return the new rtx. */
591 adjust_stack_reference (rtx mem
, HOST_WIDE_INT adjustment
)
599 adjusted_mem
= copy_rtx (mem
);
600 XEXP (adjusted_mem
, 0) = replace_rtx (XEXP (adjusted_mem
, 0),
602 gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
603 GEN_INT (adjustment
)));
604 tmp
= simplify_rtx (XEXP (adjusted_mem
, 0));
606 XEXP (adjusted_mem
, 0) = tmp
;
611 /* The hash function for variable_htab, computes the hash value
612 from the declaration of variable X. */
615 variable_htab_hash (const void *x
)
617 const variable v
= (const variable
) x
;
619 return (VARIABLE_HASH_VAL (v
->decl
));
622 /* Compare the declaration of variable X with declaration Y. */
625 variable_htab_eq (const void *x
, const void *y
)
627 const variable v
= (const variable
) x
;
628 const tree decl
= (const tree
) y
;
630 return (VARIABLE_HASH_VAL (v
->decl
) == VARIABLE_HASH_VAL (decl
));
633 /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
636 variable_htab_free (void *elem
)
639 variable var
= (variable
) elem
;
640 location_chain node
, next
;
642 #ifdef ENABLE_CHECKING
643 if (var
->refcount
<= 0)
648 if (var
->refcount
> 0)
651 for (i
= 0; i
< var
->n_var_parts
; i
++)
653 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= next
)
656 pool_free (loc_chain_pool
, node
);
658 var
->var_part
[i
].loc_chain
= NULL
;
660 pool_free (var_pool
, var
);
663 /* Initialize the set (array) SET of attrs to empty lists. */
666 init_attrs_list_set (attrs
*set
)
670 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
674 /* Make the list *LISTP empty. */
677 attrs_list_clear (attrs
*listp
)
681 for (list
= *listp
; list
; list
= next
)
684 pool_free (attrs_pool
, list
);
689 /* Return true if the pair of DECL and OFFSET is the member of the LIST. */
692 attrs_list_member (attrs list
, tree decl
, HOST_WIDE_INT offset
)
694 for (; list
; list
= list
->next
)
695 if (list
->decl
== decl
&& list
->offset
== offset
)
700 /* Insert the triplet DECL, OFFSET, LOC to the list *LISTP. */
703 attrs_list_insert (attrs
*listp
, tree decl
, HOST_WIDE_INT offset
, rtx loc
)
707 list
= pool_alloc (attrs_pool
);
710 list
->offset
= offset
;
715 /* Copy all nodes from SRC and create a list *DSTP of the copies. */
718 attrs_list_copy (attrs
*dstp
, attrs src
)
722 attrs_list_clear (dstp
);
723 for (; src
; src
= src
->next
)
725 n
= pool_alloc (attrs_pool
);
728 n
->offset
= src
->offset
;
734 /* Add all nodes from SRC which are not in *DSTP to *DSTP. */
737 attrs_list_union (attrs
*dstp
, attrs src
)
739 for (; src
; src
= src
->next
)
741 if (!attrs_list_member (*dstp
, src
->decl
, src
->offset
))
742 attrs_list_insert (dstp
, src
->decl
, src
->offset
, src
->loc
);
746 /* Delete all variables from hash table VARS. */
749 vars_clear (htab_t vars
)
754 /* Return a copy of a variable VAR and insert it to dataflow set SET. */
757 unshare_variable (dataflow_set
*set
, variable var
)
763 new_var
= pool_alloc (var_pool
);
764 new_var
->decl
= var
->decl
;
765 new_var
->refcount
= 1;
767 new_var
->n_var_parts
= var
->n_var_parts
;
769 for (i
= 0; i
< var
->n_var_parts
; i
++)
772 location_chain
*nextp
;
774 new_var
->var_part
[i
].offset
= var
->var_part
[i
].offset
;
775 nextp
= &new_var
->var_part
[i
].loc_chain
;
776 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
778 location_chain new_lc
;
780 new_lc
= pool_alloc (loc_chain_pool
);
782 new_lc
->loc
= node
->loc
;
785 nextp
= &new_lc
->next
;
788 /* We are at the basic block boundary when copying variable description
789 so set the CUR_LOC to be the first element of the chain. */
790 if (new_var
->var_part
[i
].loc_chain
)
791 new_var
->var_part
[i
].cur_loc
= new_var
->var_part
[i
].loc_chain
->loc
;
793 new_var
->var_part
[i
].cur_loc
= NULL
;
796 slot
= htab_find_slot_with_hash (set
->vars
, new_var
->decl
,
797 VARIABLE_HASH_VAL (new_var
->decl
),
803 /* Add a variable from *SLOT to hash table DATA and increase its reference
807 vars_copy_1 (void **slot
, void *data
)
809 htab_t dst
= (htab_t
) data
;
812 src
= *(variable
*) slot
;
815 dstp
= (variable
*) htab_find_slot_with_hash (dst
, src
->decl
,
816 VARIABLE_HASH_VAL (src
->decl
),
820 /* Continue traversing the hash table. */
824 /* Copy all variables from hash table SRC to hash table DST. */
827 vars_copy (htab_t dst
, htab_t src
)
830 htab_traverse (src
, vars_copy_1
, dst
);
833 /* Delete current content of register LOC in dataflow set SET
834 and set the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). */
837 var_reg_delete_and_set (dataflow_set
*set
, rtx loc
)
839 tree decl
= REG_EXPR (loc
);
840 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
844 nextp
= &set
->regs
[REGNO (loc
)];
845 for (node
= *nextp
; node
; node
= next
)
848 if (node
->decl
!= decl
|| node
->offset
!= offset
)
850 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
851 pool_free (attrs_pool
, node
);
860 if (set
->regs
[REGNO (loc
)] == NULL
)
861 attrs_list_insert (&set
->regs
[REGNO (loc
)], decl
, offset
, loc
);
862 set_variable_part (set
, loc
, decl
, offset
);
865 /* Delete current content of register LOC in dataflow set SET. */
868 var_reg_delete (dataflow_set
*set
, rtx loc
)
870 attrs
*reg
= &set
->regs
[REGNO (loc
)];
873 for (node
= *reg
; node
; node
= next
)
876 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
877 pool_free (attrs_pool
, node
);
882 /* Delete content of register with number REGNO in dataflow set SET. */
885 var_regno_delete (dataflow_set
*set
, int regno
)
887 attrs
*reg
= &set
->regs
[regno
];
890 for (node
= *reg
; node
; node
= next
)
893 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
894 pool_free (attrs_pool
, node
);
899 /* Delete and set the location part of variable MEM_EXPR (LOC)
900 in dataflow set SET to LOC.
901 Adjust the address first if it is stack pointer based. */
904 var_mem_delete_and_set (dataflow_set
*set
, rtx loc
)
906 tree decl
= MEM_EXPR (loc
);
907 HOST_WIDE_INT offset
= MEM_OFFSET (loc
) ? INTVAL (MEM_OFFSET (loc
)) : 0;
909 set_variable_part (set
, loc
, decl
, offset
);
912 /* Delete the location part LOC from dataflow set SET.
913 Adjust the address first if it is stack pointer based. */
916 var_mem_delete (dataflow_set
*set
, rtx loc
)
918 tree decl
= MEM_EXPR (loc
);
919 HOST_WIDE_INT offset
= MEM_OFFSET (loc
) ? INTVAL (MEM_OFFSET (loc
)) : 0;
921 delete_variable_part (set
, loc
, decl
, offset
);
924 /* Initialize dataflow set SET to be empty.
925 VARS_SIZE is the initial size of hash table VARS. */
928 dataflow_set_init (dataflow_set
*set
, int vars_size
)
930 init_attrs_list_set (set
->regs
);
931 set
->vars
= htab_create (vars_size
, variable_htab_hash
, variable_htab_eq
,
933 set
->stack_adjust
= 0;
936 /* Delete the contents of dataflow set SET. */
939 dataflow_set_clear (dataflow_set
*set
)
943 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
944 attrs_list_clear (&set
->regs
[i
]);
946 vars_clear (set
->vars
);
949 /* Copy the contents of dataflow set SRC to DST. */
952 dataflow_set_copy (dataflow_set
*dst
, dataflow_set
*src
)
956 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
957 attrs_list_copy (&dst
->regs
[i
], src
->regs
[i
]);
959 vars_copy (dst
->vars
, src
->vars
);
960 dst
->stack_adjust
= src
->stack_adjust
;
963 /* Information for merging lists of locations for a given offset of variable.
965 struct variable_union_info
967 /* Node of the location chain. */
970 /* The sum of positions in the input chains. */
973 /* The position in the chains of SRC and DST dataflow sets. */
978 /* Compare function for qsort, order the structures by POS element. */
981 variable_union_info_cmp_pos (const void *n1
, const void *n2
)
983 const struct variable_union_info
*i1
= n1
;
984 const struct variable_union_info
*i2
= n2
;
986 if (i1
->pos
!= i2
->pos
)
987 return i1
->pos
- i2
->pos
;
989 return (i1
->pos_dst
- i2
->pos_dst
);
992 /* Compute union of location parts of variable *SLOT and the same variable
993 from hash table DATA. Compute "sorted" union of the location chains
994 for common offsets, i.e. the locations of a variable part are sorted by
995 a priority where the priority is the sum of the positions in the 2 chains
996 (if a location is only in one list the position in the second list is
997 defined to be larger than the length of the chains).
998 When we are updating the location parts the newest location is in the
999 beginning of the chain, so when we do the described "sorted" union
1000 we keep the newest locations in the beginning. */
1003 variable_union (void **slot
, void *data
)
1005 variable src
, dst
, *dstp
;
1006 dataflow_set
*set
= (dataflow_set
*) data
;
1009 src
= *(variable
*) slot
;
1010 dstp
= (variable
*) htab_find_slot_with_hash (set
->vars
, src
->decl
,
1011 VARIABLE_HASH_VAL (src
->decl
),
1017 /* If CUR_LOC of some variable part is not the first element of
1018 the location chain we are going to change it so we have to make
1019 a copy of the variable. */
1020 for (k
= 0; k
< src
->n_var_parts
; k
++)
1022 if (src
->var_part
[k
].loc_chain
)
1024 #ifdef ENABLE_CHECKING
1025 if (src
->var_part
[k
].cur_loc
== NULL
)
1028 if (src
->var_part
[k
].cur_loc
!= src
->var_part
[k
].loc_chain
->loc
)
1031 #ifdef ENABLE_CHECKING
1034 if (src
->var_part
[k
].cur_loc
!= NULL
)
1039 if (k
< src
->n_var_parts
)
1040 unshare_variable (set
, src
);
1044 /* Continue traversing the hash table. */
1050 #ifdef ENABLE_CHECKING
1051 if (src
->n_var_parts
== 0)
1055 /* Count the number of location parts, result is K. */
1056 for (i
= 0, j
= 0, k
= 0;
1057 i
< src
->n_var_parts
&& j
< dst
->n_var_parts
; k
++)
1059 if (src
->var_part
[i
].offset
== dst
->var_part
[j
].offset
)
1064 else if (src
->var_part
[i
].offset
< dst
->var_part
[j
].offset
)
1069 k
+= src
->n_var_parts
- i
;
1070 k
+= dst
->n_var_parts
- j
;
1071 #ifdef ENABLE_CHECKING
1072 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
1073 thus there are at most MAX_VAR_PARTS different offsets. */
1074 if (k
> MAX_VAR_PARTS
)
1078 if (dst
->refcount
> 1 && dst
->n_var_parts
!= k
)
1079 dst
= unshare_variable (set
, dst
);
1081 i
= src
->n_var_parts
- 1;
1082 j
= dst
->n_var_parts
- 1;
1083 dst
->n_var_parts
= k
;
1085 for (k
--; k
>= 0; k
--)
1087 location_chain node
, node2
;
1089 if (i
>= 0 && j
>= 0
1090 && src
->var_part
[i
].offset
== dst
->var_part
[j
].offset
)
1092 /* Compute the "sorted" union of the chains, i.e. the locations which
1093 are in both chains go first, they are sorted by the sum of
1094 positions in the chains. */
1097 struct variable_union_info
*vui
;
1099 /* If DST is shared compare the location chains.
1100 If they are different we will modify the chain in DST with
1101 high probability so make a copy of DST. */
1102 if (dst
->refcount
> 1)
1104 for (node
= src
->var_part
[i
].loc_chain
,
1105 node2
= dst
->var_part
[j
].loc_chain
; node
&& node2
;
1106 node
= node
->next
, node2
= node2
->next
)
1108 if (!((REG_P (node2
->loc
)
1109 && REG_P (node
->loc
)
1110 && REGNO (node2
->loc
) == REGNO (node
->loc
))
1111 || rtx_equal_p (node2
->loc
, node
->loc
)))
1115 dst
= unshare_variable (set
, dst
);
1119 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1122 for (node
= dst
->var_part
[j
].loc_chain
; node
; node
= node
->next
)
1124 vui
= xcalloc (src_l
+ dst_l
, sizeof (struct variable_union_info
));
1126 /* Fill in the locations from DST. */
1127 for (node
= dst
->var_part
[j
].loc_chain
, jj
= 0; node
;
1128 node
= node
->next
, jj
++)
1131 vui
[jj
].pos_dst
= jj
;
1133 /* Value larger than a sum of 2 valid positions. */
1134 vui
[jj
].pos_src
= src_l
+ dst_l
;
1137 /* Fill in the locations from SRC. */
1139 for (node
= src
->var_part
[i
].loc_chain
, ii
= 0; node
;
1140 node
= node
->next
, ii
++)
1142 /* Find location from NODE. */
1143 for (jj
= 0; jj
< dst_l
; jj
++)
1145 if ((REG_P (vui
[jj
].lc
->loc
)
1146 && REG_P (node
->loc
)
1147 && REGNO (vui
[jj
].lc
->loc
) == REGNO (node
->loc
))
1148 || rtx_equal_p (vui
[jj
].lc
->loc
, node
->loc
))
1150 vui
[jj
].pos_src
= ii
;
1154 if (jj
>= dst_l
) /* The location has not been found. */
1156 location_chain new_node
;
1158 /* Copy the location from SRC. */
1159 new_node
= pool_alloc (loc_chain_pool
);
1160 new_node
->loc
= node
->loc
;
1161 vui
[n
].lc
= new_node
;
1162 vui
[n
].pos_src
= ii
;
1163 vui
[n
].pos_dst
= src_l
+ dst_l
;
1168 for (ii
= 0; ii
< src_l
+ dst_l
; ii
++)
1169 vui
[ii
].pos
= vui
[ii
].pos_src
+ vui
[ii
].pos_dst
;
1171 qsort (vui
, n
, sizeof (struct variable_union_info
),
1172 variable_union_info_cmp_pos
);
1174 /* Reconnect the nodes in sorted order. */
1175 for (ii
= 1; ii
< n
; ii
++)
1176 vui
[ii
- 1].lc
->next
= vui
[ii
].lc
;
1177 vui
[n
- 1].lc
->next
= NULL
;
1179 dst
->var_part
[k
].loc_chain
= vui
[0].lc
;
1180 dst
->var_part
[k
].offset
= dst
->var_part
[j
].offset
;
1186 else if ((i
>= 0 && j
>= 0
1187 && src
->var_part
[i
].offset
< dst
->var_part
[j
].offset
)
1190 dst
->var_part
[k
] = dst
->var_part
[j
];
1193 else if ((i
>= 0 && j
>= 0
1194 && src
->var_part
[i
].offset
> dst
->var_part
[j
].offset
)
1197 location_chain
*nextp
;
1199 /* Copy the chain from SRC. */
1200 nextp
= &dst
->var_part
[k
].loc_chain
;
1201 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1203 location_chain new_lc
;
1205 new_lc
= pool_alloc (loc_chain_pool
);
1206 new_lc
->next
= NULL
;
1207 new_lc
->loc
= node
->loc
;
1210 nextp
= &new_lc
->next
;
1213 dst
->var_part
[k
].offset
= src
->var_part
[i
].offset
;
1217 /* We are at the basic block boundary when computing union
1218 so set the CUR_LOC to be the first element of the chain. */
1219 if (dst
->var_part
[k
].loc_chain
)
1220 dst
->var_part
[k
].cur_loc
= dst
->var_part
[k
].loc_chain
->loc
;
1222 dst
->var_part
[k
].cur_loc
= NULL
;
1225 /* Continue traversing the hash table. */
1229 /* Compute union of dataflow sets SRC and DST and store it to DST. */
1232 dataflow_set_union (dataflow_set
*dst
, dataflow_set
*src
)
1236 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1237 attrs_list_union (&dst
->regs
[i
], src
->regs
[i
]);
1239 htab_traverse (src
->vars
, variable_union
, dst
);
1242 /* Flag whether two dataflow sets being compared contain different data. */
1244 dataflow_set_different_value
;
1247 variable_part_different_p (variable_part
*vp1
, variable_part
*vp2
)
1249 location_chain lc1
, lc2
;
1251 for (lc1
= vp1
->loc_chain
; lc1
; lc1
= lc1
->next
)
1253 for (lc2
= vp2
->loc_chain
; lc2
; lc2
= lc2
->next
)
1255 if (REG_P (lc1
->loc
) && REG_P (lc2
->loc
))
1257 if (REGNO (lc1
->loc
) == REGNO (lc2
->loc
))
1260 if (rtx_equal_p (lc1
->loc
, lc2
->loc
))
1269 /* Return true if variables VAR1 and VAR2 are different.
1270 If COMPARE_CURRENT_LOCATION is true compare also the cur_loc of each
1274 variable_different_p (variable var1
, variable var2
,
1275 bool compare_current_location
)
1282 if (var1
->n_var_parts
!= var2
->n_var_parts
)
1285 for (i
= 0; i
< var1
->n_var_parts
; i
++)
1287 if (var1
->var_part
[i
].offset
!= var2
->var_part
[i
].offset
)
1289 if (compare_current_location
)
1291 if (!((REG_P (var1
->var_part
[i
].cur_loc
)
1292 && REG_P (var2
->var_part
[i
].cur_loc
)
1293 && (REGNO (var1
->var_part
[i
].cur_loc
)
1294 == REGNO (var2
->var_part
[i
].cur_loc
)))
1295 || rtx_equal_p (var1
->var_part
[i
].cur_loc
,
1296 var2
->var_part
[i
].cur_loc
)))
1299 if (variable_part_different_p (&var1
->var_part
[i
], &var2
->var_part
[i
]))
1301 if (variable_part_different_p (&var2
->var_part
[i
], &var1
->var_part
[i
]))
1307 /* Compare variable *SLOT with the same variable in hash table DATA
1308 and set DATAFLOW_SET_DIFFERENT_VALUE if they are different. */
1311 dataflow_set_different_1 (void **slot
, void *data
)
1313 htab_t htab
= (htab_t
) data
;
1314 variable var1
, var2
;
1316 var1
= *(variable
*) slot
;
1317 var2
= htab_find_with_hash (htab
, var1
->decl
,
1318 VARIABLE_HASH_VAL (var1
->decl
));
1321 dataflow_set_different_value
= true;
1323 /* Stop traversing the hash table. */
1327 if (variable_different_p (var1
, var2
, false))
1329 dataflow_set_different_value
= true;
1331 /* Stop traversing the hash table. */
1335 /* Continue traversing the hash table. */
1339 /* Compare variable *SLOT with the same variable in hash table DATA
1340 and set DATAFLOW_SET_DIFFERENT_VALUE if they are different. */
1343 dataflow_set_different_2 (void **slot
, void *data
)
1345 htab_t htab
= (htab_t
) data
;
1346 variable var1
, var2
;
1348 var1
= *(variable
*) slot
;
1349 var2
= htab_find_with_hash (htab
, var1
->decl
,
1350 VARIABLE_HASH_VAL (var1
->decl
));
1353 dataflow_set_different_value
= true;
1355 /* Stop traversing the hash table. */
1359 #ifdef ENABLE_CHECKING
1360 /* If both variables are defined they have been already checked for
1362 if (variable_different_p (var1
, var2
, false))
1366 /* Continue traversing the hash table. */
1370 /* Return true if dataflow sets OLD_SET and NEW_SET differ. */
1373 dataflow_set_different (dataflow_set
*old_set
, dataflow_set
*new_set
)
1375 dataflow_set_different_value
= false;
1377 htab_traverse (old_set
->vars
, dataflow_set_different_1
, new_set
->vars
);
1378 if (!dataflow_set_different_value
)
1380 /* We have compared the variables which are in both hash tables
1381 so now only check whether there are some variables in NEW_SET->VARS
1382 which are not in OLD_SET->VARS. */
1383 htab_traverse (new_set
->vars
, dataflow_set_different_2
, old_set
->vars
);
1385 return dataflow_set_different_value
;
1388 /* Free the contents of dataflow set SET. */
1391 dataflow_set_destroy (dataflow_set
*set
)
1395 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1396 attrs_list_clear (&set
->regs
[i
]);
1398 htab_delete (set
->vars
);
1402 /* Return true if RTL X contains a SYMBOL_REF. */
1405 contains_symbol_ref (rtx x
)
1414 code
= GET_CODE (x
);
1415 if (code
== SYMBOL_REF
)
1418 fmt
= GET_RTX_FORMAT (code
);
1419 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1423 if (contains_symbol_ref (XEXP (x
, i
)))
1426 else if (fmt
[i
] == 'E')
1429 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1430 if (contains_symbol_ref (XVECEXP (x
, i
, j
)))
1438 /* Shall EXPR be tracked? */
1441 track_expr_p (tree expr
)
1446 /* If EXPR is not a parameter or a variable do not track it. */
1447 if (TREE_CODE (expr
) != VAR_DECL
&& TREE_CODE (expr
) != PARM_DECL
)
1450 /* It also must have a name... */
1451 if (!DECL_NAME (expr
))
1454 /* ... and a RTL assigned to it. */
1455 decl_rtl
= DECL_RTL_IF_SET (expr
);
1459 /* If this expression is really a debug alias of some other declaration, we
1460 don't need to track this expression if the ultimate declaration is
1463 if (DECL_DEBUG_EXPR (realdecl
)
1464 && DECL_DEBUG_EXPR_IS_FROM (realdecl
))
1466 realdecl
= DECL_DEBUG_EXPR (realdecl
);
1467 /* ??? We don't yet know how to emit DW_OP_piece for variable
1468 that has been SRA'ed. */
1469 if (!DECL_P (realdecl
))
1473 /* Do not track EXPR if REALDECL it should be ignored for debugging
1475 if (DECL_IGNORED_P (realdecl
))
1478 /* Do not track global variables until we are able to emit correct location
1480 if (TREE_STATIC (realdecl
))
1483 /* When the EXPR is a DECL for alias of some variable (see example)
1484 the TREE_STATIC flag is not used. Disable tracking all DECLs whose
1485 DECL_RTL contains SYMBOL_REF.
1488 extern char **_dl_argv_internal __attribute__ ((alias ("_dl_argv")));
1491 if (MEM_P (decl_rtl
)
1492 && contains_symbol_ref (XEXP (decl_rtl
, 0)))
1495 /* If RTX is a memory it should not be very large (because it would be
1496 an array or struct). */
1497 if (MEM_P (decl_rtl
))
1499 /* Do not track structures and arrays. */
1500 if (GET_MODE (decl_rtl
) == BLKmode
)
1502 if (MEM_SIZE (decl_rtl
)
1503 && INTVAL (MEM_SIZE (decl_rtl
)) > MAX_VAR_PARTS
)
1510 /* Count uses (register and memory references) LOC which will be tracked.
1511 INSN is instruction which the LOC is part of. */
1514 count_uses (rtx
*loc
, void *insn
)
1516 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1520 #ifdef ENABLE_CHECKING
1521 if (REGNO (*loc
) >= FIRST_PSEUDO_REGISTER
)
1526 else if (MEM_P (*loc
)
1528 && track_expr_p (MEM_EXPR (*loc
)))
1536 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
1539 count_uses_1 (rtx
*x
, void *insn
)
1541 for_each_rtx (x
, count_uses
, insn
);
1544 /* Count stores (register and memory references) LOC which will be tracked.
1545 INSN is instruction which the LOC is part of. */
1548 count_stores (rtx loc
, rtx expr ATTRIBUTE_UNUSED
, void *insn
)
1550 count_uses (&loc
, insn
);
1553 /* Add uses (register and memory references) LOC which will be tracked
1554 to VTI (bb)->mos. INSN is instruction which the LOC is part of. */
1557 add_uses (rtx
*loc
, void *insn
)
1561 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1562 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1564 mo
->type
= ((REG_EXPR (*loc
) && track_expr_p (REG_EXPR (*loc
)))
1565 ? MO_USE
: MO_USE_NO_VAR
);
1567 mo
->insn
= (rtx
) insn
;
1569 else if (MEM_P (*loc
)
1571 && track_expr_p (MEM_EXPR (*loc
)))
1573 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1574 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1578 mo
->insn
= (rtx
) insn
;
1584 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
1587 add_uses_1 (rtx
*x
, void *insn
)
1589 for_each_rtx (x
, add_uses
, insn
);
1592 /* Add stores (register and memory references) LOC which will be tracked
1593 to VTI (bb)->mos. EXPR is the RTL expression containing the store.
1594 INSN is instruction which the LOC is part of. */
1597 add_stores (rtx loc
, rtx expr
, void *insn
)
1601 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1602 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1604 mo
->type
= ((GET_CODE (expr
) != CLOBBER
&& REG_EXPR (loc
)
1605 && track_expr_p (REG_EXPR (loc
)))
1606 ? MO_SET
: MO_CLOBBER
);
1608 mo
->insn
= (rtx
) insn
;
1610 else if (MEM_P (loc
)
1612 && track_expr_p (MEM_EXPR (loc
)))
1614 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1615 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1617 mo
->type
= GET_CODE (expr
) == CLOBBER
? MO_CLOBBER
: MO_SET
;
1619 mo
->insn
= (rtx
) insn
;
1623 /* Compute the changes of variable locations in the basic block BB. */
1626 compute_bb_dataflow (basic_block bb
)
1630 dataflow_set old_out
;
1631 dataflow_set
*in
= &VTI (bb
)->in
;
1632 dataflow_set
*out
= &VTI (bb
)->out
;
1634 dataflow_set_init (&old_out
, htab_elements (VTI (bb
)->out
.vars
) + 3);
1635 dataflow_set_copy (&old_out
, out
);
1636 dataflow_set_copy (out
, in
);
1638 n
= VTI (bb
)->n_mos
;
1639 for (i
= 0; i
< n
; i
++)
1641 switch (VTI (bb
)->mos
[i
].type
)
1644 for (r
= 0; r
< FIRST_PSEUDO_REGISTER
; r
++)
1645 if (TEST_HARD_REG_BIT (call_used_reg_set
, r
))
1646 var_regno_delete (out
, r
);
1652 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
1655 var_reg_delete_and_set (out
, loc
);
1656 else if (MEM_P (loc
))
1657 var_mem_delete_and_set (out
, loc
);
1664 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
1667 var_reg_delete (out
, loc
);
1668 else if (MEM_P (loc
))
1669 var_mem_delete (out
, loc
);
1677 out
->stack_adjust
+= VTI (bb
)->mos
[i
].u
.adjust
;
1678 base
= gen_rtx_MEM (Pmode
, plus_constant (stack_pointer_rtx
,
1679 out
->stack_adjust
));
1680 set_frame_base_location (out
, base
);
1686 changed
= dataflow_set_different (&old_out
, out
);
1687 dataflow_set_destroy (&old_out
);
1691 /* Find the locations of variables in the whole function. */
1694 vt_find_locations (void)
1696 fibheap_t worklist
, pending
, fibheap_swap
;
1697 sbitmap visited
, in_worklist
, in_pending
, sbitmap_swap
;
1704 /* Compute reverse completion order of depth first search of the CFG
1705 so that the data-flow runs faster. */
1706 rc_order
= xmalloc (n_basic_blocks
* sizeof (int));
1707 bb_order
= xmalloc (last_basic_block
* sizeof (int));
1708 flow_depth_first_order_compute (NULL
, rc_order
);
1709 for (i
= 0; i
< n_basic_blocks
; i
++)
1710 bb_order
[rc_order
[i
]] = i
;
1713 worklist
= fibheap_new ();
1714 pending
= fibheap_new ();
1715 visited
= sbitmap_alloc (last_basic_block
);
1716 in_worklist
= sbitmap_alloc (last_basic_block
);
1717 in_pending
= sbitmap_alloc (last_basic_block
);
1718 sbitmap_zero (in_worklist
);
1721 fibheap_insert (pending
, bb_order
[bb
->index
], bb
);
1722 sbitmap_ones (in_pending
);
1724 while (!fibheap_empty (pending
))
1726 fibheap_swap
= pending
;
1728 worklist
= fibheap_swap
;
1729 sbitmap_swap
= in_pending
;
1730 in_pending
= in_worklist
;
1731 in_worklist
= sbitmap_swap
;
1733 sbitmap_zero (visited
);
1735 while (!fibheap_empty (worklist
))
1737 bb
= fibheap_extract_min (worklist
);
1738 RESET_BIT (in_worklist
, bb
->index
);
1739 if (!TEST_BIT (visited
, bb
->index
))
1744 SET_BIT (visited
, bb
->index
);
1746 /* Calculate the IN set as union of predecessor OUT sets. */
1747 dataflow_set_clear (&VTI (bb
)->in
);
1748 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
1750 dataflow_set_union (&VTI (bb
)->in
, &VTI (e
->src
)->out
);
1753 changed
= compute_bb_dataflow (bb
);
1756 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1758 if (e
->dest
== EXIT_BLOCK_PTR
)
1764 if (TEST_BIT (visited
, e
->dest
->index
))
1766 if (!TEST_BIT (in_pending
, e
->dest
->index
))
1768 /* Send E->DEST to next round. */
1769 SET_BIT (in_pending
, e
->dest
->index
);
1770 fibheap_insert (pending
,
1771 bb_order
[e
->dest
->index
],
1775 else if (!TEST_BIT (in_worklist
, e
->dest
->index
))
1777 /* Add E->DEST to current round. */
1778 SET_BIT (in_worklist
, e
->dest
->index
);
1779 fibheap_insert (worklist
, bb_order
[e
->dest
->index
],
1789 fibheap_delete (worklist
);
1790 fibheap_delete (pending
);
1791 sbitmap_free (visited
);
1792 sbitmap_free (in_worklist
);
1793 sbitmap_free (in_pending
);
1796 /* Print the content of the LIST to dump file. */
1799 dump_attrs_list (attrs list
)
1801 for (; list
; list
= list
->next
)
1803 print_mem_expr (dump_file
, list
->decl
);
1804 fprintf (dump_file
, "+");
1805 fprintf (dump_file
, HOST_WIDE_INT_PRINT_DEC
, list
->offset
);
1807 fprintf (dump_file
, "\n");
1810 /* Print the information about variable *SLOT to dump file. */
1813 dump_variable (void **slot
, void *data ATTRIBUTE_UNUSED
)
1815 variable var
= *(variable
*) slot
;
1817 location_chain node
;
1819 fprintf (dump_file
, " name: %s\n",
1820 IDENTIFIER_POINTER (DECL_NAME (var
->decl
)));
1821 for (i
= 0; i
< var
->n_var_parts
; i
++)
1823 fprintf (dump_file
, " offset %ld\n",
1824 (long) var
->var_part
[i
].offset
);
1825 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1827 fprintf (dump_file
, " ");
1828 print_rtl_single (dump_file
, node
->loc
);
1832 /* Continue traversing the hash table. */
1836 /* Print the information about variables from hash table VARS to dump file. */
1839 dump_vars (htab_t vars
)
1841 if (htab_elements (vars
) > 0)
1843 fprintf (dump_file
, "Variables:\n");
1844 htab_traverse (vars
, dump_variable
, NULL
);
1848 /* Print the dataflow set SET to dump file. */
1851 dump_dataflow_set (dataflow_set
*set
)
1855 fprintf (dump_file
, "Stack adjustment: ");
1856 fprintf (dump_file
, HOST_WIDE_INT_PRINT_DEC
, set
->stack_adjust
);
1857 fprintf (dump_file
, "\n");
1858 for (i
= 1; i
< FIRST_PSEUDO_REGISTER
; i
++)
1862 fprintf (dump_file
, "Reg %d:", i
);
1863 dump_attrs_list (set
->regs
[i
]);
1866 dump_vars (set
->vars
);
1867 fprintf (dump_file
, "\n");
1870 /* Print the IN and OUT sets for each basic block to dump file. */
1873 dump_dataflow_sets (void)
1879 fprintf (dump_file
, "\nBasic block %d:\n", bb
->index
);
1880 fprintf (dump_file
, "IN:\n");
1881 dump_dataflow_set (&VTI (bb
)->in
);
1882 fprintf (dump_file
, "OUT:\n");
1883 dump_dataflow_set (&VTI (bb
)->out
);
1887 /* Add variable VAR to the hash table of changed variables and
1888 if it has no locations delete it from hash table HTAB. */
1891 variable_was_changed (variable var
, htab_t htab
)
1893 hashval_t hash
= VARIABLE_HASH_VAL (var
->decl
);
1899 slot
= (variable
*) htab_find_slot_with_hash (changed_variables
,
1900 var
->decl
, hash
, INSERT
);
1902 if (htab
&& var
->n_var_parts
== 0)
1907 empty_var
= pool_alloc (var_pool
);
1908 empty_var
->decl
= var
->decl
;
1909 empty_var
->refcount
= 1;
1910 empty_var
->n_var_parts
= 0;
1913 old
= htab_find_slot_with_hash (htab
, var
->decl
, hash
,
1916 htab_clear_slot (htab
, old
);
1925 #ifdef ENABLE_CHECKING
1929 if (var
->n_var_parts
== 0)
1931 void **slot
= htab_find_slot_with_hash (htab
, var
->decl
, hash
,
1934 htab_clear_slot (htab
, slot
);
1939 /* Set the location of frame_base_decl to LOC in dataflow set SET. This
1940 function expects that frame_base_decl has already one location for offset 0
1941 in the variable table. */
1944 set_frame_base_location (dataflow_set
*set
, rtx loc
)
1948 var
= htab_find_with_hash (set
->vars
, frame_base_decl
,
1949 VARIABLE_HASH_VAL (frame_base_decl
));
1950 #ifdef ENABLE_CHECKING
1953 if (var
->n_var_parts
!= 1)
1955 if (var
->var_part
[0].offset
!= 0)
1957 if (!var
->var_part
[0].loc_chain
)
1961 /* If frame_base_decl is shared unshare it first. */
1962 if (var
->refcount
> 1)
1963 var
= unshare_variable (set
, var
);
1965 var
->var_part
[0].loc_chain
->loc
= loc
;
1966 var
->var_part
[0].cur_loc
= loc
;
1967 variable_was_changed (var
, set
->vars
);
1970 /* Set the part of variable's location in the dataflow set SET. The variable
1971 part is specified by variable's declaration DECL and offset OFFSET and the
1972 part's location by LOC. */
1975 set_variable_part (dataflow_set
*set
, rtx loc
, tree decl
, HOST_WIDE_INT offset
)
1978 location_chain node
, next
;
1979 location_chain
*nextp
;
1983 slot
= htab_find_slot_with_hash (set
->vars
, decl
,
1984 VARIABLE_HASH_VAL (decl
), INSERT
);
1987 /* Create new variable information. */
1988 var
= pool_alloc (var_pool
);
1991 var
->n_var_parts
= 1;
1992 var
->var_part
[0].offset
= offset
;
1993 var
->var_part
[0].loc_chain
= NULL
;
1994 var
->var_part
[0].cur_loc
= NULL
;
2000 var
= (variable
) *slot
;
2002 /* Find the location part. */
2004 high
= var
->n_var_parts
;
2007 pos
= (low
+ high
) / 2;
2008 if (var
->var_part
[pos
].offset
< offset
)
2015 if (pos
< var
->n_var_parts
&& var
->var_part
[pos
].offset
== offset
)
2017 node
= var
->var_part
[pos
].loc_chain
;
2020 && ((REG_P (node
->loc
) && REG_P (loc
)
2021 && REGNO (node
->loc
) == REGNO (loc
))
2022 || rtx_equal_p (node
->loc
, loc
)))
2024 /* LOC is in the beginning of the chain so we have nothing
2030 /* We have to make a copy of a shared variable. */
2031 if (var
->refcount
> 1)
2032 var
= unshare_variable (set
, var
);
2037 /* We have not found the location part, new one will be created. */
2039 /* We have to make a copy of the shared variable. */
2040 if (var
->refcount
> 1)
2041 var
= unshare_variable (set
, var
);
2043 #ifdef ENABLE_CHECKING
2044 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
2045 thus there are at most MAX_VAR_PARTS different offsets. */
2046 if (var
->n_var_parts
>= MAX_VAR_PARTS
)
2050 /* We have to move the elements of array starting at index low to the
2052 for (high
= var
->n_var_parts
; high
> low
; high
--)
2053 var
->var_part
[high
] = var
->var_part
[high
- 1];
2056 var
->var_part
[pos
].offset
= offset
;
2057 var
->var_part
[pos
].loc_chain
= NULL
;
2058 var
->var_part
[pos
].cur_loc
= NULL
;
2062 /* Delete the location from the list. */
2063 nextp
= &var
->var_part
[pos
].loc_chain
;
2064 for (node
= var
->var_part
[pos
].loc_chain
; node
; node
= next
)
2067 if ((REG_P (node
->loc
) && REG_P (loc
)
2068 && REGNO (node
->loc
) == REGNO (loc
))
2069 || rtx_equal_p (node
->loc
, loc
))
2071 pool_free (loc_chain_pool
, node
);
2076 nextp
= &node
->next
;
2079 /* Add the location to the beginning. */
2080 node
= pool_alloc (loc_chain_pool
);
2082 node
->next
= var
->var_part
[pos
].loc_chain
;
2083 var
->var_part
[pos
].loc_chain
= node
;
2085 /* If no location was emitted do so. */
2086 if (var
->var_part
[pos
].cur_loc
== NULL
)
2088 var
->var_part
[pos
].cur_loc
= loc
;
2089 variable_was_changed (var
, set
->vars
);
2093 /* Delete the part of variable's location from dataflow set SET. The variable
2094 part is specified by variable's declaration DECL and offset OFFSET and the
2095 part's location by LOC. */
2098 delete_variable_part (dataflow_set
*set
, rtx loc
, tree decl
,
2099 HOST_WIDE_INT offset
)
2104 slot
= htab_find_slot_with_hash (set
->vars
, decl
, VARIABLE_HASH_VAL (decl
),
2108 variable var
= (variable
) *slot
;
2110 /* Find the location part. */
2112 high
= var
->n_var_parts
;
2115 pos
= (low
+ high
) / 2;
2116 if (var
->var_part
[pos
].offset
< offset
)
2123 if (pos
< var
->n_var_parts
&& var
->var_part
[pos
].offset
== offset
)
2125 location_chain node
, next
;
2126 location_chain
*nextp
;
2129 if (var
->refcount
> 1)
2131 /* If the variable contains the location part we have to
2132 make a copy of the variable. */
2133 for (node
= var
->var_part
[pos
].loc_chain
; node
;
2136 if ((REG_P (node
->loc
) && REG_P (loc
)
2137 && REGNO (node
->loc
) == REGNO (loc
))
2138 || rtx_equal_p (node
->loc
, loc
))
2140 var
= unshare_variable (set
, var
);
2146 /* Delete the location part. */
2147 nextp
= &var
->var_part
[pos
].loc_chain
;
2148 for (node
= *nextp
; node
; node
= next
)
2151 if ((REG_P (node
->loc
) && REG_P (loc
)
2152 && REGNO (node
->loc
) == REGNO (loc
))
2153 || rtx_equal_p (node
->loc
, loc
))
2155 pool_free (loc_chain_pool
, node
);
2160 nextp
= &node
->next
;
2163 /* If we have deleted the location which was last emitted
2164 we have to emit new location so add the variable to set
2165 of changed variables. */
2166 if (var
->var_part
[pos
].cur_loc
2168 && REG_P (var
->var_part
[pos
].cur_loc
)
2169 && REGNO (loc
) == REGNO (var
->var_part
[pos
].cur_loc
))
2170 || rtx_equal_p (loc
, var
->var_part
[pos
].cur_loc
)))
2173 if (var
->var_part
[pos
].loc_chain
)
2174 var
->var_part
[pos
].cur_loc
= var
->var_part
[pos
].loc_chain
->loc
;
2179 if (var
->var_part
[pos
].loc_chain
== NULL
)
2182 while (pos
< var
->n_var_parts
)
2184 var
->var_part
[pos
] = var
->var_part
[pos
+ 1];
2189 variable_was_changed (var
, set
->vars
);
2194 /* Emit the NOTE_INSN_VAR_LOCATION for variable *VARP. DATA contains
2195 additional parameters: WHERE specifies whether the note shall be emitted
2196 before of after instruction INSN. */
2199 emit_note_insn_var_location (void **varp
, void *data
)
2201 variable var
= *(variable
*) varp
;
2202 rtx insn
= ((emit_note_data
*)data
)->insn
;
2203 enum emit_note_where where
= ((emit_note_data
*)data
)->where
;
2207 HOST_WIDE_INT last_limit
;
2208 tree type_size_unit
;
2210 #ifdef ENABLE_CHECKING
2217 for (i
= 0; i
< var
->n_var_parts
; i
++)
2219 if (last_limit
< var
->var_part
[i
].offset
)
2225 = (var
->var_part
[i
].offset
2226 + GET_MODE_SIZE (GET_MODE (var
->var_part
[i
].loc_chain
->loc
)));
2228 type_size_unit
= TYPE_SIZE_UNIT (TREE_TYPE (var
->decl
));
2229 if ((unsigned HOST_WIDE_INT
) last_limit
< TREE_INT_CST_LOW (type_size_unit
))
2232 if (where
== EMIT_NOTE_AFTER_INSN
)
2233 note
= emit_note_after (NOTE_INSN_VAR_LOCATION
, insn
);
2235 note
= emit_note_before (NOTE_INSN_VAR_LOCATION
, insn
);
2239 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2242 else if (var
->n_var_parts
== 1)
2245 = gen_rtx_EXPR_LIST (VOIDmode
,
2246 var
->var_part
[0].loc_chain
->loc
,
2247 GEN_INT (var
->var_part
[0].offset
));
2249 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2252 else if (var
->n_var_parts
)
2254 rtx argp
[MAX_VAR_PARTS
];
2257 for (i
= 0; i
< var
->n_var_parts
; i
++)
2258 argp
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, var
->var_part
[i
].loc_chain
->loc
,
2259 GEN_INT (var
->var_part
[i
].offset
));
2260 parallel
= gen_rtx_PARALLEL (VOIDmode
,
2261 gen_rtvec_v (var
->n_var_parts
, argp
));
2262 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2266 htab_clear_slot (changed_variables
, varp
);
2268 /* When there are no location parts the variable has been already
2269 removed from hash table and a new empty variable was created.
2270 Free the empty variable. */
2271 if (var
->n_var_parts
== 0)
2273 pool_free (var_pool
, var
);
2276 /* Continue traversing the hash table. */
2280 /* Emit NOTE_INSN_VAR_LOCATION note for each variable from a chain
2281 CHANGED_VARIABLES and delete this chain. WHERE specifies whether the notes
2282 shall be emitted before of after instruction INSN. */
2285 emit_notes_for_changes (rtx insn
, enum emit_note_where where
)
2287 emit_note_data data
;
2291 htab_traverse (changed_variables
, emit_note_insn_var_location
, &data
);
2294 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it differs from the
2295 same variable in hash table DATA or is not there at all. */
2298 emit_notes_for_differences_1 (void **slot
, void *data
)
2300 htab_t new_vars
= (htab_t
) data
;
2301 variable old_var
, new_var
;
2303 old_var
= *(variable
*) slot
;
2304 new_var
= htab_find_with_hash (new_vars
, old_var
->decl
,
2305 VARIABLE_HASH_VAL (old_var
->decl
));
2309 /* Variable has disappeared. */
2312 empty_var
= pool_alloc (var_pool
);
2313 empty_var
->decl
= old_var
->decl
;
2314 empty_var
->refcount
= 1;
2315 empty_var
->n_var_parts
= 0;
2316 variable_was_changed (empty_var
, NULL
);
2318 else if (variable_different_p (old_var
, new_var
, true))
2320 variable_was_changed (new_var
, NULL
);
2323 /* Continue traversing the hash table. */
2327 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it is not in hash
2331 emit_notes_for_differences_2 (void **slot
, void *data
)
2333 htab_t old_vars
= (htab_t
) data
;
2334 variable old_var
, new_var
;
2336 new_var
= *(variable
*) slot
;
2337 old_var
= htab_find_with_hash (old_vars
, new_var
->decl
,
2338 VARIABLE_HASH_VAL (new_var
->decl
));
2341 /* Variable has appeared. */
2342 variable_was_changed (new_var
, NULL
);
2345 /* Continue traversing the hash table. */
2349 /* Emit notes before INSN for differences between dataflow sets OLD_SET and
2353 emit_notes_for_differences (rtx insn
, dataflow_set
*old_set
,
2354 dataflow_set
*new_set
)
2356 htab_traverse (old_set
->vars
, emit_notes_for_differences_1
, new_set
->vars
);
2357 htab_traverse (new_set
->vars
, emit_notes_for_differences_2
, old_set
->vars
);
2358 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2361 /* Emit the notes for changes of location parts in the basic block BB. */
2364 emit_notes_in_bb (basic_block bb
)
2369 dataflow_set_init (&set
, htab_elements (VTI (bb
)->in
.vars
) + 3);
2370 dataflow_set_copy (&set
, &VTI (bb
)->in
);
2372 for (i
= 0; i
< VTI (bb
)->n_mos
; i
++)
2374 rtx insn
= VTI (bb
)->mos
[i
].insn
;
2376 switch (VTI (bb
)->mos
[i
].type
)
2382 for (r
= 0; r
< FIRST_PSEUDO_REGISTER
; r
++)
2383 if (TEST_HARD_REG_BIT (call_used_reg_set
, r
))
2385 var_regno_delete (&set
, r
);
2387 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2394 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
2397 var_reg_delete_and_set (&set
, loc
);
2399 var_mem_delete_and_set (&set
, loc
);
2401 if (VTI (bb
)->mos
[i
].type
== MO_USE
)
2402 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2404 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2411 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
2414 var_reg_delete (&set
, loc
);
2416 var_mem_delete (&set
, loc
);
2418 if (VTI (bb
)->mos
[i
].type
== MO_USE_NO_VAR
)
2419 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2421 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2429 set
.stack_adjust
+= VTI (bb
)->mos
[i
].u
.adjust
;
2430 base
= gen_rtx_MEM (Pmode
, plus_constant (stack_pointer_rtx
,
2432 set_frame_base_location (&set
, base
);
2433 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2438 dataflow_set_destroy (&set
);
2441 /* Emit notes for the whole function. */
2444 vt_emit_notes (void)
2447 dataflow_set
*last_out
;
2450 #ifdef ENABLE_CHECKING
2451 if (htab_elements (changed_variables
))
2455 /* Enable emitting notes by functions (mainly by set_variable_part and
2456 delete_variable_part). */
2459 dataflow_set_init (&empty
, 7);
2464 /* Emit the notes for changes of variable locations between two
2465 subsequent basic blocks. */
2466 emit_notes_for_differences (BB_HEAD (bb
), last_out
, &VTI (bb
)->in
);
2468 /* Emit the notes for the changes in the basic block itself. */
2469 emit_notes_in_bb (bb
);
2471 last_out
= &VTI (bb
)->out
;
2473 dataflow_set_destroy (&empty
);
2477 /* If there is a declaration and offset associated with register/memory RTL
2478 assign declaration to *DECLP and offset to *OFFSETP, and return true. */
2481 vt_get_decl_and_offset (rtx rtl
, tree
*declp
, HOST_WIDE_INT
*offsetp
)
2485 if (REG_ATTRS (rtl
))
2487 *declp
= REG_EXPR (rtl
);
2488 *offsetp
= REG_OFFSET (rtl
);
2492 else if (MEM_P (rtl
))
2494 if (MEM_ATTRS (rtl
))
2496 *declp
= MEM_EXPR (rtl
);
2497 *offsetp
= MEM_OFFSET (rtl
) ? INTVAL (MEM_OFFSET (rtl
)) : 0;
2504 /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK. */
2507 vt_add_function_parameters (void)
2511 for (parm
= DECL_ARGUMENTS (current_function_decl
);
2512 parm
; parm
= TREE_CHAIN (parm
))
2514 rtx decl_rtl
= DECL_RTL_IF_SET (parm
);
2515 rtx incoming
= DECL_INCOMING_RTL (parm
);
2517 HOST_WIDE_INT offset
;
2520 if (TREE_CODE (parm
) != PARM_DECL
)
2523 if (!DECL_NAME (parm
))
2526 if (!decl_rtl
|| !incoming
)
2529 if (GET_MODE (decl_rtl
) == BLKmode
|| GET_MODE (incoming
) == BLKmode
)
2532 if (!vt_get_decl_and_offset (incoming
, &decl
, &offset
))
2533 if (!vt_get_decl_and_offset (decl_rtl
, &decl
, &offset
))
2539 #ifdef ENABLE_CHECKING
2544 incoming
= eliminate_regs (incoming
, 0, NULL_RTX
);
2545 out
= &VTI (ENTRY_BLOCK_PTR
)->out
;
2547 if (REG_P (incoming
))
2549 #ifdef ENABLE_CHECKING
2550 if (REGNO (incoming
) >= FIRST_PSEUDO_REGISTER
)
2553 attrs_list_insert (&out
->regs
[REGNO (incoming
)],
2554 parm
, offset
, incoming
);
2555 set_variable_part (out
, incoming
, parm
, offset
);
2557 else if (MEM_P (incoming
))
2559 set_variable_part (out
, incoming
, parm
, offset
);
2564 /* Allocate and initialize the data structures for variable tracking
2565 and parse the RTL to get the micro operations. */
2568 vt_initialize (void)
2572 alloc_aux_for_blocks (sizeof (struct variable_tracking_info_def
));
2577 HOST_WIDE_INT pre
, post
;
2579 /* Count the number of micro operations. */
2580 VTI (bb
)->n_mos
= 0;
2581 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
2582 insn
= NEXT_INSN (insn
))
2586 if (!frame_pointer_needed
)
2588 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
2594 note_uses (&PATTERN (insn
), count_uses_1
, insn
);
2595 note_stores (PATTERN (insn
), count_stores
, insn
);
2601 /* Add the micro-operations to the array. */
2602 VTI (bb
)->mos
= xmalloc (VTI (bb
)->n_mos
2603 * sizeof (struct micro_operation_def
));
2604 VTI (bb
)->n_mos
= 0;
2605 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
2606 insn
= NEXT_INSN (insn
))
2612 if (!frame_pointer_needed
)
2614 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
2617 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2619 mo
->type
= MO_ADJUST
;
2625 n1
= VTI (bb
)->n_mos
;
2626 note_uses (&PATTERN (insn
), add_uses_1
, insn
);
2627 n2
= VTI (bb
)->n_mos
- 1;
2629 /* Order the MO_USEs to be before MO_USE_NO_VARs. */
2632 while (n1
< n2
&& VTI (bb
)->mos
[n1
].type
== MO_USE
)
2634 while (n1
< n2
&& VTI (bb
)->mos
[n2
].type
== MO_USE_NO_VAR
)
2640 sw
= VTI (bb
)->mos
[n1
];
2641 VTI (bb
)->mos
[n1
] = VTI (bb
)->mos
[n2
];
2642 VTI (bb
)->mos
[n2
] = sw
;
2648 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2654 n1
= VTI (bb
)->n_mos
;
2655 note_stores (PATTERN (insn
), add_stores
, insn
);
2656 n2
= VTI (bb
)->n_mos
- 1;
2658 /* Order the MO_SETs to be before MO_CLOBBERs. */
2661 while (n1
< n2
&& VTI (bb
)->mos
[n1
].type
== MO_SET
)
2663 while (n1
< n2
&& VTI (bb
)->mos
[n2
].type
== MO_CLOBBER
)
2669 sw
= VTI (bb
)->mos
[n1
];
2670 VTI (bb
)->mos
[n1
] = VTI (bb
)->mos
[n2
];
2671 VTI (bb
)->mos
[n2
] = sw
;
2675 if (!frame_pointer_needed
&& post
)
2677 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2679 mo
->type
= MO_ADJUST
;
2680 mo
->u
.adjust
= post
;
2687 /* Init the IN and OUT sets. */
2690 VTI (bb
)->visited
= false;
2691 dataflow_set_init (&VTI (bb
)->in
, 7);
2692 dataflow_set_init (&VTI (bb
)->out
, 7);
2695 attrs_pool
= create_alloc_pool ("attrs_def pool",
2696 sizeof (struct attrs_def
), 1024);
2697 var_pool
= create_alloc_pool ("variable_def pool",
2698 sizeof (struct variable_def
), 64);
2699 loc_chain_pool
= create_alloc_pool ("location_chain_def pool",
2700 sizeof (struct location_chain_def
),
2702 changed_variables
= htab_create (10, variable_htab_hash
, variable_htab_eq
,
2704 vt_add_function_parameters ();
2706 if (!frame_pointer_needed
)
2710 /* Create fake variable for tracking stack pointer changes. */
2711 frame_base_decl
= make_node (VAR_DECL
);
2712 DECL_NAME (frame_base_decl
) = get_identifier ("___frame_base_decl");
2713 TREE_TYPE (frame_base_decl
) = char_type_node
;
2714 DECL_ARTIFICIAL (frame_base_decl
) = 1;
2715 DECL_IGNORED_P (frame_base_decl
) = 1;
2717 /* Set its initial "location". */
2718 frame_stack_adjust
= -prologue_stack_adjust ();
2719 base
= gen_rtx_MEM (Pmode
, plus_constant (stack_pointer_rtx
,
2720 frame_stack_adjust
));
2721 set_variable_part (&VTI (ENTRY_BLOCK_PTR
)->out
, base
, frame_base_decl
, 0);
2725 frame_base_decl
= NULL
;
2729 /* Free the data structures needed for variable tracking. */
2738 free (VTI (bb
)->mos
);
2743 dataflow_set_destroy (&VTI (bb
)->in
);
2744 dataflow_set_destroy (&VTI (bb
)->out
);
2746 free_aux_for_blocks ();
2747 free_alloc_pool (attrs_pool
);
2748 free_alloc_pool (var_pool
);
2749 free_alloc_pool (loc_chain_pool
);
2750 htab_delete (changed_variables
);
2753 /* The entry point to variable tracking pass. */
2756 variable_tracking_main (void)
2758 if (n_basic_blocks
> 500 && n_edges
/ n_basic_blocks
>= 20)
2761 mark_dfs_back_edges ();
2763 if (!frame_pointer_needed
)
2765 if (!vt_stack_adjustments ())
2772 vt_find_locations ();
2777 dump_dataflow_sets ();
2778 dump_flow_info (dump_file
);