1 /* Variable tracking routines for the GNU compiler.
2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 /* This file contains the variable tracking pass. It computes where
22 variables are located (which registers or where in memory) at each position
23 in instruction stream and emits notes describing the locations.
24 Debug information (DWARF2 location lists) is finally generated from
26 With this debug information, it is possible to show variables
27 even when debugging optimized code.
29 How does the variable tracking pass work?
31 First, it scans RTL code for uses, stores and clobbers (register/memory
32 references in instructions), for call insns and for stack adjustments
33 separately for each basic block and saves them to an array of micro
35 The micro operations of one instruction are ordered so that
36 pre-modifying stack adjustment < use < use with no var < call insn <
37 < set < clobber < post-modifying stack adjustment
39 Then, a forward dataflow analysis is performed to find out how locations
40 of variables change through code and to propagate the variable locations
41 along control flow graph.
42 The IN set for basic block BB is computed as a union of OUT sets of BB's
43 predecessors, the OUT set for BB is copied from the IN set for BB and
44 is changed according to micro operations in BB.
46 The IN and OUT sets for basic blocks consist of a current stack adjustment
47 (used for adjusting offset of variables addressed using stack pointer),
48 the table of structures describing the locations of parts of a variable
49 and for each physical register a linked list for each physical register.
50 The linked list is a list of variable parts stored in the register,
51 i.e. it is a list of triplets (reg, decl, offset) where decl is
52 REG_EXPR (reg) and offset is REG_OFFSET (reg). The linked list is used for
53 effective deleting appropriate variable parts when we set or clobber the
56 There may be more than one variable part in a register. The linked lists
57 should be pretty short so it is a good data structure here.
58 For example in the following code, register allocator may assign same
59 register to variables A and B, and both of them are stored in the same
72 Finally, the NOTE_INSN_VAR_LOCATION notes describing the variable locations
73 are emitted to appropriate positions in RTL code. Each such a note describes
74 the location of one variable at the point in instruction stream where the
75 note is. There is no need to emit a note for each variable before each
76 instruction, we only emit these notes where the location of variable changes
77 (this means that we also emit notes for changes between the OUT set of the
78 previous block and the IN set of the current block).
80 The notes consist of two parts:
81 1. the declaration (from REG_EXPR or MEM_EXPR)
82 2. the location of a variable - it is either a simple register/memory
83 reference (for simple variables, for example int),
84 or a parallel of register/memory references (for a large variables
85 which consist of several parts, for example long long).
91 #include "coretypes.h"
95 #include "hard-reg-set.h"
96 #include "basic-block.h"
99 #include "insn-config.h"
102 #include "alloc-pool.h"
108 #include "tree-pass.h"
110 /* Type of micro operation. */
111 enum micro_operation_type
113 MO_USE
, /* Use location (REG or MEM). */
114 MO_USE_NO_VAR
,/* Use location which is not associated with a variable
115 or the variable is not trackable. */
116 MO_SET
, /* Set location. */
117 MO_CLOBBER
, /* Clobber location. */
118 MO_CALL
, /* Call insn. */
119 MO_ADJUST
/* Adjust stack pointer. */
122 /* Where shall the note be emitted? BEFORE or AFTER the instruction. */
125 EMIT_NOTE_BEFORE_INSN
,
129 /* Structure holding information about micro operation. */
130 typedef struct micro_operation_def
132 /* Type of micro operation. */
133 enum micro_operation_type type
;
139 /* Stack adjustment. */
140 HOST_WIDE_INT adjust
;
143 /* The instruction which the micro operation is in. */
147 /* Structure for passing some other parameters to function
148 emit_note_insn_var_location. */
149 typedef struct emit_note_data_def
151 /* The instruction which the note will be emitted before/after. */
154 /* Where the note will be emitted (before/after insn)? */
155 enum emit_note_where where
;
158 /* Description of location of a part of a variable. The content of a physical
159 register is described by a chain of these structures.
160 The chains are pretty short (usually 1 or 2 elements) and thus
161 chain is the best data structure. */
162 typedef struct attrs_def
164 /* Pointer to next member of the list. */
165 struct attrs_def
*next
;
167 /* The rtx of register. */
170 /* The declaration corresponding to LOC. */
173 /* Offset from start of DECL. */
174 HOST_WIDE_INT offset
;
177 /* Structure holding the IN or OUT set for a basic block. */
178 typedef struct dataflow_set_def
180 /* Adjustment of stack offset. */
181 HOST_WIDE_INT stack_adjust
;
183 /* Attributes for registers (lists of attrs). */
184 attrs regs
[FIRST_PSEUDO_REGISTER
];
186 /* Variable locations. */
190 /* The structure (one for each basic block) containing the information
191 needed for variable tracking. */
192 typedef struct variable_tracking_info_def
194 /* Number of micro operations stored in the MOS array. */
197 /* The array of micro operations. */
198 micro_operation
*mos
;
200 /* The IN and OUT set for dataflow analysis. */
204 /* Has the block been visited in DFS? */
206 } *variable_tracking_info
;
208 /* Structure for chaining the locations. */
209 typedef struct location_chain_def
211 /* Next element in the chain. */
212 struct location_chain_def
*next
;
214 /* The location (REG or MEM). */
218 /* Structure describing one part of variable. */
219 typedef struct variable_part_def
221 /* Chain of locations of the part. */
222 location_chain loc_chain
;
224 /* Location which was last emitted to location list. */
227 /* The offset in the variable. */
228 HOST_WIDE_INT offset
;
231 /* Maximum number of location parts. */
232 #define MAX_VAR_PARTS 16
234 /* Structure describing where the variable is located. */
235 typedef struct variable_def
237 /* The declaration of the variable. */
240 /* Reference count. */
243 /* Number of variable parts. */
246 /* The variable parts. */
247 variable_part var_part
[MAX_VAR_PARTS
];
250 /* Hash function for DECL for VARIABLE_HTAB. */
251 #define VARIABLE_HASH_VAL(decl) (DECL_UID (decl))
253 /* Pointer to the BB's information specific to variable tracking pass. */
254 #define VTI(BB) ((variable_tracking_info) (BB)->aux)
256 /* Macro to access MEM_OFFSET as an HOST_WIDE_INT. Evaluates MEM twice. */
257 #define INT_MEM_OFFSET(mem) (MEM_OFFSET (mem) ? INTVAL (MEM_OFFSET (mem)) : 0)
259 /* Alloc pool for struct attrs_def. */
260 static alloc_pool attrs_pool
;
262 /* Alloc pool for struct variable_def. */
263 static alloc_pool var_pool
;
265 /* Alloc pool for struct location_chain_def. */
266 static alloc_pool loc_chain_pool
;
268 /* Changed variables, notes will be emitted for them. */
269 static htab_t changed_variables
;
271 /* Shall notes be emitted? */
272 static bool emit_notes
;
274 /* Local function prototypes. */
275 static void stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
277 static void insn_stack_adjust_offset_pre_post (rtx
, HOST_WIDE_INT
*,
279 static void bb_stack_adjust_offset (basic_block
);
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_variable_part (dataflow_set
*, rtx
, tree
, HOST_WIDE_INT
);
335 static void delete_variable_part (dataflow_set
*, rtx
, tree
, HOST_WIDE_INT
);
336 static int emit_note_insn_var_location (void **, void *);
337 static void emit_notes_for_changes (rtx
, enum emit_note_where
);
338 static int emit_notes_for_differences_1 (void **, void *);
339 static int emit_notes_for_differences_2 (void **, void *);
340 static void emit_notes_for_differences (rtx
, dataflow_set
*, dataflow_set
*);
341 static void emit_notes_in_bb (basic_block
);
342 static void vt_emit_notes (void);
344 static bool vt_get_decl_and_offset (rtx
, tree
*, HOST_WIDE_INT
*);
345 static void vt_add_function_parameters (void);
346 static void vt_initialize (void);
347 static void vt_finalize (void);
349 /* Given a SET, calculate the amount of stack adjustment it contains
350 PRE- and POST-modifying stack pointer.
351 This function is similar to stack_adjust_offset. */
354 stack_adjust_offset_pre_post (rtx pattern
, HOST_WIDE_INT
*pre
,
357 rtx src
= SET_SRC (pattern
);
358 rtx dest
= SET_DEST (pattern
);
361 if (dest
== stack_pointer_rtx
)
363 /* (set (reg sp) (plus (reg sp) (const_int))) */
364 code
= GET_CODE (src
);
365 if (! (code
== PLUS
|| code
== MINUS
)
366 || XEXP (src
, 0) != stack_pointer_rtx
367 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
371 *post
+= INTVAL (XEXP (src
, 1));
373 *post
-= INTVAL (XEXP (src
, 1));
375 else if (MEM_P (dest
))
377 /* (set (mem (pre_dec (reg sp))) (foo)) */
378 src
= XEXP (dest
, 0);
379 code
= GET_CODE (src
);
385 if (XEXP (src
, 0) == stack_pointer_rtx
)
387 rtx val
= XEXP (XEXP (src
, 1), 1);
388 /* We handle only adjustments by constant amount. */
389 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
&&
390 GET_CODE (val
) == CONST_INT
);
392 if (code
== PRE_MODIFY
)
393 *pre
-= INTVAL (val
);
395 *post
-= INTVAL (val
);
401 if (XEXP (src
, 0) == stack_pointer_rtx
)
403 *pre
+= GET_MODE_SIZE (GET_MODE (dest
));
409 if (XEXP (src
, 0) == stack_pointer_rtx
)
411 *post
+= GET_MODE_SIZE (GET_MODE (dest
));
417 if (XEXP (src
, 0) == stack_pointer_rtx
)
419 *pre
-= GET_MODE_SIZE (GET_MODE (dest
));
425 if (XEXP (src
, 0) == stack_pointer_rtx
)
427 *post
-= GET_MODE_SIZE (GET_MODE (dest
));
438 /* Given an INSN, calculate the amount of stack adjustment it contains
439 PRE- and POST-modifying stack pointer. */
442 insn_stack_adjust_offset_pre_post (rtx insn
, HOST_WIDE_INT
*pre
,
448 if (GET_CODE (PATTERN (insn
)) == SET
)
449 stack_adjust_offset_pre_post (PATTERN (insn
), pre
, post
);
450 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
451 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
455 /* There may be stack adjustments inside compound insns. Search
457 for ( i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
458 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
459 stack_adjust_offset_pre_post (XVECEXP (PATTERN (insn
), 0, i
),
464 /* Compute stack adjustment in basic block BB. */
467 bb_stack_adjust_offset (basic_block bb
)
469 HOST_WIDE_INT offset
;
472 offset
= VTI (bb
)->in
.stack_adjust
;
473 for (i
= 0; i
< VTI (bb
)->n_mos
; i
++)
475 if (VTI (bb
)->mos
[i
].type
== MO_ADJUST
)
476 offset
+= VTI (bb
)->mos
[i
].u
.adjust
;
477 else if (VTI (bb
)->mos
[i
].type
!= MO_CALL
)
479 if (MEM_P (VTI (bb
)->mos
[i
].u
.loc
))
481 VTI (bb
)->mos
[i
].u
.loc
482 = adjust_stack_reference (VTI (bb
)->mos
[i
].u
.loc
, -offset
);
486 VTI (bb
)->out
.stack_adjust
= offset
;
489 /* Compute stack adjustments for all blocks by traversing DFS tree.
490 Return true when the adjustments on all incoming edges are consistent.
491 Heavily borrowed from flow_depth_first_order_compute. */
494 vt_stack_adjustments (void)
496 edge_iterator
*stack
;
499 /* Initialize entry block. */
500 VTI (ENTRY_BLOCK_PTR
)->visited
= true;
501 VTI (ENTRY_BLOCK_PTR
)->out
.stack_adjust
= INCOMING_FRAME_SP_OFFSET
;
503 /* Allocate stack for back-tracking up CFG. */
504 stack
= xmalloc ((n_basic_blocks
+ 1) * sizeof (edge_iterator
));
507 /* Push the first edge on to the stack. */
508 stack
[sp
++] = ei_start (ENTRY_BLOCK_PTR
->succs
);
516 /* Look at the edge on the top of the stack. */
518 src
= ei_edge (ei
)->src
;
519 dest
= ei_edge (ei
)->dest
;
521 /* Check if the edge destination has been visited yet. */
522 if (!VTI (dest
)->visited
)
524 VTI (dest
)->visited
= true;
525 VTI (dest
)->in
.stack_adjust
= VTI (src
)->out
.stack_adjust
;
526 bb_stack_adjust_offset (dest
);
528 if (EDGE_COUNT (dest
->succs
) > 0)
529 /* Since the DEST node has been visited for the first
530 time, check its successors. */
531 stack
[sp
++] = ei_start (dest
->succs
);
535 /* Check whether the adjustments on the edges are the same. */
536 if (VTI (dest
)->in
.stack_adjust
!= VTI (src
)->out
.stack_adjust
)
542 if (! ei_one_before_end_p (ei
))
543 /* Go to the next edge. */
544 ei_next (&stack
[sp
- 1]);
546 /* Return to previous level if there are no more edges. */
555 /* Adjust stack reference MEM by ADJUSTMENT bytes and make it relative
556 to the argument pointer. Return the new rtx. */
559 adjust_stack_reference (rtx mem
, HOST_WIDE_INT adjustment
)
563 #ifdef FRAME_POINTER_CFA_OFFSET
564 adjustment
-= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
565 cfa
= plus_constant (frame_pointer_rtx
, adjustment
);
567 adjustment
-= ARG_POINTER_CFA_OFFSET (current_function_decl
);
568 cfa
= plus_constant (arg_pointer_rtx
, adjustment
);
571 addr
= replace_rtx (copy_rtx (XEXP (mem
, 0)), stack_pointer_rtx
, cfa
);
572 tmp
= simplify_rtx (addr
);
576 return replace_equiv_address_nv (mem
, addr
);
579 /* The hash function for variable_htab, computes the hash value
580 from the declaration of variable X. */
583 variable_htab_hash (const void *x
)
585 const variable v
= (const variable
) x
;
587 return (VARIABLE_HASH_VAL (v
->decl
));
590 /* Compare the declaration of variable X with declaration Y. */
593 variable_htab_eq (const void *x
, const void *y
)
595 const variable v
= (const variable
) x
;
596 const tree decl
= (const tree
) y
;
598 return (VARIABLE_HASH_VAL (v
->decl
) == VARIABLE_HASH_VAL (decl
));
601 /* Free the element of VARIABLE_HTAB (its type is struct variable_def). */
604 variable_htab_free (void *elem
)
607 variable var
= (variable
) elem
;
608 location_chain node
, next
;
610 gcc_assert (var
->refcount
> 0);
613 if (var
->refcount
> 0)
616 for (i
= 0; i
< var
->n_var_parts
; i
++)
618 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= next
)
621 pool_free (loc_chain_pool
, node
);
623 var
->var_part
[i
].loc_chain
= NULL
;
625 pool_free (var_pool
, var
);
628 /* Initialize the set (array) SET of attrs to empty lists. */
631 init_attrs_list_set (attrs
*set
)
635 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
639 /* Make the list *LISTP empty. */
642 attrs_list_clear (attrs
*listp
)
646 for (list
= *listp
; list
; list
= next
)
649 pool_free (attrs_pool
, list
);
654 /* Return true if the pair of DECL and OFFSET is the member of the LIST. */
657 attrs_list_member (attrs list
, tree decl
, HOST_WIDE_INT offset
)
659 for (; list
; list
= list
->next
)
660 if (list
->decl
== decl
&& list
->offset
== offset
)
665 /* Insert the triplet DECL, OFFSET, LOC to the list *LISTP. */
668 attrs_list_insert (attrs
*listp
, tree decl
, HOST_WIDE_INT offset
, rtx loc
)
672 list
= pool_alloc (attrs_pool
);
675 list
->offset
= offset
;
680 /* Copy all nodes from SRC and create a list *DSTP of the copies. */
683 attrs_list_copy (attrs
*dstp
, attrs src
)
687 attrs_list_clear (dstp
);
688 for (; src
; src
= src
->next
)
690 n
= pool_alloc (attrs_pool
);
693 n
->offset
= src
->offset
;
699 /* Add all nodes from SRC which are not in *DSTP to *DSTP. */
702 attrs_list_union (attrs
*dstp
, attrs src
)
704 for (; src
; src
= src
->next
)
706 if (!attrs_list_member (*dstp
, src
->decl
, src
->offset
))
707 attrs_list_insert (dstp
, src
->decl
, src
->offset
, src
->loc
);
711 /* Delete all variables from hash table VARS. */
714 vars_clear (htab_t vars
)
719 /* Return a copy of a variable VAR and insert it to dataflow set SET. */
722 unshare_variable (dataflow_set
*set
, variable var
)
728 new_var
= pool_alloc (var_pool
);
729 new_var
->decl
= var
->decl
;
730 new_var
->refcount
= 1;
732 new_var
->n_var_parts
= var
->n_var_parts
;
734 for (i
= 0; i
< var
->n_var_parts
; i
++)
737 location_chain
*nextp
;
739 new_var
->var_part
[i
].offset
= var
->var_part
[i
].offset
;
740 nextp
= &new_var
->var_part
[i
].loc_chain
;
741 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
743 location_chain new_lc
;
745 new_lc
= pool_alloc (loc_chain_pool
);
747 new_lc
->loc
= node
->loc
;
750 nextp
= &new_lc
->next
;
753 /* We are at the basic block boundary when copying variable description
754 so set the CUR_LOC to be the first element of the chain. */
755 if (new_var
->var_part
[i
].loc_chain
)
756 new_var
->var_part
[i
].cur_loc
= new_var
->var_part
[i
].loc_chain
->loc
;
758 new_var
->var_part
[i
].cur_loc
= NULL
;
761 slot
= htab_find_slot_with_hash (set
->vars
, new_var
->decl
,
762 VARIABLE_HASH_VAL (new_var
->decl
),
768 /* Add a variable from *SLOT to hash table DATA and increase its reference
772 vars_copy_1 (void **slot
, void *data
)
774 htab_t dst
= (htab_t
) data
;
777 src
= *(variable
*) slot
;
780 dstp
= (variable
*) htab_find_slot_with_hash (dst
, src
->decl
,
781 VARIABLE_HASH_VAL (src
->decl
),
785 /* Continue traversing the hash table. */
789 /* Copy all variables from hash table SRC to hash table DST. */
792 vars_copy (htab_t dst
, htab_t src
)
795 htab_traverse (src
, vars_copy_1
, dst
);
798 /* Delete current content of register LOC in dataflow set SET
799 and set the register to contain REG_EXPR (LOC), REG_OFFSET (LOC). */
802 var_reg_delete_and_set (dataflow_set
*set
, rtx loc
)
804 tree decl
= REG_EXPR (loc
);
805 HOST_WIDE_INT offset
= REG_OFFSET (loc
);
809 nextp
= &set
->regs
[REGNO (loc
)];
810 for (node
= *nextp
; node
; node
= next
)
813 if (node
->decl
!= decl
|| node
->offset
!= offset
)
815 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
816 pool_free (attrs_pool
, node
);
825 if (set
->regs
[REGNO (loc
)] == NULL
)
826 attrs_list_insert (&set
->regs
[REGNO (loc
)], decl
, offset
, loc
);
827 set_variable_part (set
, loc
, decl
, offset
);
830 /* Delete current content of register LOC in dataflow set SET. */
833 var_reg_delete (dataflow_set
*set
, rtx loc
)
835 attrs
*reg
= &set
->regs
[REGNO (loc
)];
838 for (node
= *reg
; node
; node
= next
)
841 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
842 pool_free (attrs_pool
, node
);
847 /* Delete content of register with number REGNO in dataflow set SET. */
850 var_regno_delete (dataflow_set
*set
, int regno
)
852 attrs
*reg
= &set
->regs
[regno
];
855 for (node
= *reg
; node
; node
= next
)
858 delete_variable_part (set
, node
->loc
, node
->decl
, node
->offset
);
859 pool_free (attrs_pool
, node
);
864 /* Delete and set the location part of variable MEM_EXPR (LOC)
865 in dataflow set SET to LOC.
866 Adjust the address first if it is stack pointer based. */
869 var_mem_delete_and_set (dataflow_set
*set
, rtx loc
)
871 tree decl
= MEM_EXPR (loc
);
872 HOST_WIDE_INT offset
= INT_MEM_OFFSET (loc
);
874 set_variable_part (set
, loc
, decl
, offset
);
877 /* Delete the location part LOC from dataflow set SET.
878 Adjust the address first if it is stack pointer based. */
881 var_mem_delete (dataflow_set
*set
, rtx loc
)
883 tree decl
= MEM_EXPR (loc
);
884 HOST_WIDE_INT offset
= INT_MEM_OFFSET (loc
);
886 delete_variable_part (set
, loc
, decl
, offset
);
889 /* Initialize dataflow set SET to be empty.
890 VARS_SIZE is the initial size of hash table VARS. */
893 dataflow_set_init (dataflow_set
*set
, int vars_size
)
895 init_attrs_list_set (set
->regs
);
896 set
->vars
= htab_create (vars_size
, variable_htab_hash
, variable_htab_eq
,
898 set
->stack_adjust
= 0;
901 /* Delete the contents of dataflow set SET. */
904 dataflow_set_clear (dataflow_set
*set
)
908 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
909 attrs_list_clear (&set
->regs
[i
]);
911 vars_clear (set
->vars
);
914 /* Copy the contents of dataflow set SRC to DST. */
917 dataflow_set_copy (dataflow_set
*dst
, dataflow_set
*src
)
921 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
922 attrs_list_copy (&dst
->regs
[i
], src
->regs
[i
]);
924 vars_copy (dst
->vars
, src
->vars
);
925 dst
->stack_adjust
= src
->stack_adjust
;
928 /* Information for merging lists of locations for a given offset of variable.
930 struct variable_union_info
932 /* Node of the location chain. */
935 /* The sum of positions in the input chains. */
938 /* The position in the chains of SRC and DST dataflow sets. */
943 /* Compare function for qsort, order the structures by POS element. */
946 variable_union_info_cmp_pos (const void *n1
, const void *n2
)
948 const struct variable_union_info
*i1
= n1
;
949 const struct variable_union_info
*i2
= n2
;
951 if (i1
->pos
!= i2
->pos
)
952 return i1
->pos
- i2
->pos
;
954 return (i1
->pos_dst
- i2
->pos_dst
);
957 /* Compute union of location parts of variable *SLOT and the same variable
958 from hash table DATA. Compute "sorted" union of the location chains
959 for common offsets, i.e. the locations of a variable part are sorted by
960 a priority where the priority is the sum of the positions in the 2 chains
961 (if a location is only in one list the position in the second list is
962 defined to be larger than the length of the chains).
963 When we are updating the location parts the newest location is in the
964 beginning of the chain, so when we do the described "sorted" union
965 we keep the newest locations in the beginning. */
968 variable_union (void **slot
, void *data
)
970 variable src
, dst
, *dstp
;
971 dataflow_set
*set
= (dataflow_set
*) data
;
974 src
= *(variable
*) slot
;
975 dstp
= (variable
*) htab_find_slot_with_hash (set
->vars
, src
->decl
,
976 VARIABLE_HASH_VAL (src
->decl
),
982 /* If CUR_LOC of some variable part is not the first element of
983 the location chain we are going to change it so we have to make
984 a copy of the variable. */
985 for (k
= 0; k
< src
->n_var_parts
; k
++)
987 gcc_assert (!src
->var_part
[k
].loc_chain
988 == !src
->var_part
[k
].cur_loc
);
989 if (src
->var_part
[k
].loc_chain
)
991 gcc_assert (src
->var_part
[k
].cur_loc
);
992 if (src
->var_part
[k
].cur_loc
!= src
->var_part
[k
].loc_chain
->loc
)
996 if (k
< src
->n_var_parts
)
997 unshare_variable (set
, src
);
1001 /* Continue traversing the hash table. */
1007 gcc_assert (src
->n_var_parts
);
1009 /* Count the number of location parts, result is K. */
1010 for (i
= 0, j
= 0, k
= 0;
1011 i
< src
->n_var_parts
&& j
< dst
->n_var_parts
; k
++)
1013 if (src
->var_part
[i
].offset
== dst
->var_part
[j
].offset
)
1018 else if (src
->var_part
[i
].offset
< dst
->var_part
[j
].offset
)
1023 k
+= src
->n_var_parts
- i
;
1024 k
+= dst
->n_var_parts
- j
;
1026 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
1027 thus there are at most MAX_VAR_PARTS different offsets. */
1028 gcc_assert (k
<= MAX_VAR_PARTS
);
1030 if (dst
->refcount
> 1 && dst
->n_var_parts
!= k
)
1031 dst
= unshare_variable (set
, dst
);
1033 i
= src
->n_var_parts
- 1;
1034 j
= dst
->n_var_parts
- 1;
1035 dst
->n_var_parts
= k
;
1037 for (k
--; k
>= 0; k
--)
1039 location_chain node
, node2
;
1041 if (i
>= 0 && j
>= 0
1042 && src
->var_part
[i
].offset
== dst
->var_part
[j
].offset
)
1044 /* Compute the "sorted" union of the chains, i.e. the locations which
1045 are in both chains go first, they are sorted by the sum of
1046 positions in the chains. */
1049 struct variable_union_info
*vui
;
1051 /* If DST is shared compare the location chains.
1052 If they are different we will modify the chain in DST with
1053 high probability so make a copy of DST. */
1054 if (dst
->refcount
> 1)
1056 for (node
= src
->var_part
[i
].loc_chain
,
1057 node2
= dst
->var_part
[j
].loc_chain
; node
&& node2
;
1058 node
= node
->next
, node2
= node2
->next
)
1060 if (!((REG_P (node2
->loc
)
1061 && REG_P (node
->loc
)
1062 && REGNO (node2
->loc
) == REGNO (node
->loc
))
1063 || rtx_equal_p (node2
->loc
, node
->loc
)))
1067 dst
= unshare_variable (set
, dst
);
1071 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1074 for (node
= dst
->var_part
[j
].loc_chain
; node
; node
= node
->next
)
1076 vui
= xcalloc (src_l
+ dst_l
, sizeof (struct variable_union_info
));
1078 /* Fill in the locations from DST. */
1079 for (node
= dst
->var_part
[j
].loc_chain
, jj
= 0; node
;
1080 node
= node
->next
, jj
++)
1083 vui
[jj
].pos_dst
= jj
;
1085 /* Value larger than a sum of 2 valid positions. */
1086 vui
[jj
].pos_src
= src_l
+ dst_l
;
1089 /* Fill in the locations from SRC. */
1091 for (node
= src
->var_part
[i
].loc_chain
, ii
= 0; node
;
1092 node
= node
->next
, ii
++)
1094 /* Find location from NODE. */
1095 for (jj
= 0; jj
< dst_l
; jj
++)
1097 if ((REG_P (vui
[jj
].lc
->loc
)
1098 && REG_P (node
->loc
)
1099 && REGNO (vui
[jj
].lc
->loc
) == REGNO (node
->loc
))
1100 || rtx_equal_p (vui
[jj
].lc
->loc
, node
->loc
))
1102 vui
[jj
].pos_src
= ii
;
1106 if (jj
>= dst_l
) /* The location has not been found. */
1108 location_chain new_node
;
1110 /* Copy the location from SRC. */
1111 new_node
= pool_alloc (loc_chain_pool
);
1112 new_node
->loc
= node
->loc
;
1113 vui
[n
].lc
= new_node
;
1114 vui
[n
].pos_src
= ii
;
1115 vui
[n
].pos_dst
= src_l
+ dst_l
;
1120 for (ii
= 0; ii
< src_l
+ dst_l
; ii
++)
1121 vui
[ii
].pos
= vui
[ii
].pos_src
+ vui
[ii
].pos_dst
;
1123 qsort (vui
, n
, sizeof (struct variable_union_info
),
1124 variable_union_info_cmp_pos
);
1126 /* Reconnect the nodes in sorted order. */
1127 for (ii
= 1; ii
< n
; ii
++)
1128 vui
[ii
- 1].lc
->next
= vui
[ii
].lc
;
1129 vui
[n
- 1].lc
->next
= NULL
;
1131 dst
->var_part
[k
].loc_chain
= vui
[0].lc
;
1132 dst
->var_part
[k
].offset
= dst
->var_part
[j
].offset
;
1138 else if ((i
>= 0 && j
>= 0
1139 && src
->var_part
[i
].offset
< dst
->var_part
[j
].offset
)
1142 dst
->var_part
[k
] = dst
->var_part
[j
];
1145 else if ((i
>= 0 && j
>= 0
1146 && src
->var_part
[i
].offset
> dst
->var_part
[j
].offset
)
1149 location_chain
*nextp
;
1151 /* Copy the chain from SRC. */
1152 nextp
= &dst
->var_part
[k
].loc_chain
;
1153 for (node
= src
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1155 location_chain new_lc
;
1157 new_lc
= pool_alloc (loc_chain_pool
);
1158 new_lc
->next
= NULL
;
1159 new_lc
->loc
= node
->loc
;
1162 nextp
= &new_lc
->next
;
1165 dst
->var_part
[k
].offset
= src
->var_part
[i
].offset
;
1169 /* We are at the basic block boundary when computing union
1170 so set the CUR_LOC to be the first element of the chain. */
1171 if (dst
->var_part
[k
].loc_chain
)
1172 dst
->var_part
[k
].cur_loc
= dst
->var_part
[k
].loc_chain
->loc
;
1174 dst
->var_part
[k
].cur_loc
= NULL
;
1177 /* Continue traversing the hash table. */
1181 /* Compute union of dataflow sets SRC and DST and store it to DST. */
1184 dataflow_set_union (dataflow_set
*dst
, dataflow_set
*src
)
1188 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1189 attrs_list_union (&dst
->regs
[i
], src
->regs
[i
]);
1191 htab_traverse (src
->vars
, variable_union
, dst
);
1194 /* Flag whether two dataflow sets being compared contain different data. */
1196 dataflow_set_different_value
;
1199 variable_part_different_p (variable_part
*vp1
, variable_part
*vp2
)
1201 location_chain lc1
, lc2
;
1203 for (lc1
= vp1
->loc_chain
; lc1
; lc1
= lc1
->next
)
1205 for (lc2
= vp2
->loc_chain
; lc2
; lc2
= lc2
->next
)
1207 if (REG_P (lc1
->loc
) && REG_P (lc2
->loc
))
1209 if (REGNO (lc1
->loc
) == REGNO (lc2
->loc
))
1212 if (rtx_equal_p (lc1
->loc
, lc2
->loc
))
1221 /* Return true if variables VAR1 and VAR2 are different.
1222 If COMPARE_CURRENT_LOCATION is true compare also the cur_loc of each
1226 variable_different_p (variable var1
, variable var2
,
1227 bool compare_current_location
)
1234 if (var1
->n_var_parts
!= var2
->n_var_parts
)
1237 for (i
= 0; i
< var1
->n_var_parts
; i
++)
1239 if (var1
->var_part
[i
].offset
!= var2
->var_part
[i
].offset
)
1241 if (compare_current_location
)
1243 if (!((REG_P (var1
->var_part
[i
].cur_loc
)
1244 && REG_P (var2
->var_part
[i
].cur_loc
)
1245 && (REGNO (var1
->var_part
[i
].cur_loc
)
1246 == REGNO (var2
->var_part
[i
].cur_loc
)))
1247 || rtx_equal_p (var1
->var_part
[i
].cur_loc
,
1248 var2
->var_part
[i
].cur_loc
)))
1251 if (variable_part_different_p (&var1
->var_part
[i
], &var2
->var_part
[i
]))
1253 if (variable_part_different_p (&var2
->var_part
[i
], &var1
->var_part
[i
]))
1259 /* Compare variable *SLOT with the same variable in hash table DATA
1260 and set DATAFLOW_SET_DIFFERENT_VALUE if they are different. */
1263 dataflow_set_different_1 (void **slot
, void *data
)
1265 htab_t htab
= (htab_t
) data
;
1266 variable var1
, var2
;
1268 var1
= *(variable
*) slot
;
1269 var2
= htab_find_with_hash (htab
, var1
->decl
,
1270 VARIABLE_HASH_VAL (var1
->decl
));
1273 dataflow_set_different_value
= true;
1275 /* Stop traversing the hash table. */
1279 if (variable_different_p (var1
, var2
, false))
1281 dataflow_set_different_value
= true;
1283 /* Stop traversing the hash table. */
1287 /* Continue traversing the hash table. */
1291 /* Compare variable *SLOT with the same variable in hash table DATA
1292 and set DATAFLOW_SET_DIFFERENT_VALUE if they are different. */
1295 dataflow_set_different_2 (void **slot
, void *data
)
1297 htab_t htab
= (htab_t
) data
;
1298 variable var1
, var2
;
1300 var1
= *(variable
*) slot
;
1301 var2
= htab_find_with_hash (htab
, var1
->decl
,
1302 VARIABLE_HASH_VAL (var1
->decl
));
1305 dataflow_set_different_value
= true;
1307 /* Stop traversing the hash table. */
1311 /* If both variables are defined they have been already checked for
1313 gcc_assert (!variable_different_p (var1
, var2
, false));
1315 /* Continue traversing the hash table. */
1319 /* Return true if dataflow sets OLD_SET and NEW_SET differ. */
1322 dataflow_set_different (dataflow_set
*old_set
, dataflow_set
*new_set
)
1324 dataflow_set_different_value
= false;
1326 htab_traverse (old_set
->vars
, dataflow_set_different_1
, new_set
->vars
);
1327 if (!dataflow_set_different_value
)
1329 /* We have compared the variables which are in both hash tables
1330 so now only check whether there are some variables in NEW_SET->VARS
1331 which are not in OLD_SET->VARS. */
1332 htab_traverse (new_set
->vars
, dataflow_set_different_2
, old_set
->vars
);
1334 return dataflow_set_different_value
;
1337 /* Free the contents of dataflow set SET. */
1340 dataflow_set_destroy (dataflow_set
*set
)
1344 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1345 attrs_list_clear (&set
->regs
[i
]);
1347 htab_delete (set
->vars
);
1351 /* Return true if RTL X contains a SYMBOL_REF. */
1354 contains_symbol_ref (rtx x
)
1363 code
= GET_CODE (x
);
1364 if (code
== SYMBOL_REF
)
1367 fmt
= GET_RTX_FORMAT (code
);
1368 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1372 if (contains_symbol_ref (XEXP (x
, i
)))
1375 else if (fmt
[i
] == 'E')
1378 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1379 if (contains_symbol_ref (XVECEXP (x
, i
, j
)))
1387 /* Shall EXPR be tracked? */
1390 track_expr_p (tree expr
)
1395 /* If EXPR is not a parameter or a variable do not track it. */
1396 if (TREE_CODE (expr
) != VAR_DECL
&& TREE_CODE (expr
) != PARM_DECL
)
1399 /* It also must have a name... */
1400 if (!DECL_NAME (expr
))
1403 /* ... and a RTL assigned to it. */
1404 decl_rtl
= DECL_RTL_IF_SET (expr
);
1408 /* If this expression is really a debug alias of some other declaration, we
1409 don't need to track this expression if the ultimate declaration is
1412 if (DECL_DEBUG_EXPR_IS_FROM (realdecl
) && DECL_DEBUG_EXPR (realdecl
))
1414 realdecl
= DECL_DEBUG_EXPR (realdecl
);
1415 /* ??? We don't yet know how to emit DW_OP_piece for variable
1416 that has been SRA'ed. */
1417 if (!DECL_P (realdecl
))
1421 /* Do not track EXPR if REALDECL it should be ignored for debugging
1423 if (DECL_IGNORED_P (realdecl
))
1426 /* Do not track global variables until we are able to emit correct location
1428 if (TREE_STATIC (realdecl
))
1431 /* When the EXPR is a DECL for alias of some variable (see example)
1432 the TREE_STATIC flag is not used. Disable tracking all DECLs whose
1433 DECL_RTL contains SYMBOL_REF.
1436 extern char **_dl_argv_internal __attribute__ ((alias ("_dl_argv")));
1439 if (MEM_P (decl_rtl
)
1440 && contains_symbol_ref (XEXP (decl_rtl
, 0)))
1443 /* If RTX is a memory it should not be very large (because it would be
1444 an array or struct). */
1445 if (MEM_P (decl_rtl
))
1447 /* Do not track structures and arrays. */
1448 if (GET_MODE (decl_rtl
) == BLKmode
)
1450 if (MEM_SIZE (decl_rtl
)
1451 && INTVAL (MEM_SIZE (decl_rtl
)) > MAX_VAR_PARTS
)
1458 /* Return true if OFFSET is a valid offset for a register or memory
1459 access we want to track. This is used to reject out-of-bounds
1460 accesses that can cause assertions to fail later. Note that we
1461 don't reject negative offsets because they can be generated for
1462 paradoxical subregs on big-endian architectures. */
1465 offset_valid_for_tracked_p (HOST_WIDE_INT offset
)
1467 return (-MAX_VAR_PARTS
< offset
) && (offset
< MAX_VAR_PARTS
);
1470 /* Count uses (register and memory references) LOC which will be tracked.
1471 INSN is instruction which the LOC is part of. */
1474 count_uses (rtx
*loc
, void *insn
)
1476 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1480 gcc_assert (REGNO (*loc
) < FIRST_PSEUDO_REGISTER
);
1483 else if (MEM_P (*loc
)
1485 && track_expr_p (MEM_EXPR (*loc
))
1486 && offset_valid_for_tracked_p (INT_MEM_OFFSET (*loc
)))
1494 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
1497 count_uses_1 (rtx
*x
, void *insn
)
1499 for_each_rtx (x
, count_uses
, insn
);
1502 /* Count stores (register and memory references) LOC which will be tracked.
1503 INSN is instruction which the LOC is part of. */
1506 count_stores (rtx loc
, rtx expr ATTRIBUTE_UNUSED
, void *insn
)
1508 count_uses (&loc
, insn
);
1511 /* Add uses (register and memory references) LOC which will be tracked
1512 to VTI (bb)->mos. INSN is instruction which the LOC is part of. */
1515 add_uses (rtx
*loc
, void *insn
)
1519 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1520 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1523 && track_expr_p (REG_EXPR (*loc
))
1524 && offset_valid_for_tracked_p (REG_OFFSET (*loc
)))
1527 mo
->type
= MO_USE_NO_VAR
;
1529 mo
->insn
= (rtx
) insn
;
1531 else if (MEM_P (*loc
)
1533 && track_expr_p (MEM_EXPR (*loc
))
1534 && offset_valid_for_tracked_p (INT_MEM_OFFSET (*loc
)))
1536 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1537 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1541 mo
->insn
= (rtx
) insn
;
1547 /* Helper function for finding all uses of REG/MEM in X in insn INSN. */
1550 add_uses_1 (rtx
*x
, void *insn
)
1552 for_each_rtx (x
, add_uses
, insn
);
1555 /* Add stores (register and memory references) LOC which will be tracked
1556 to VTI (bb)->mos. EXPR is the RTL expression containing the store.
1557 INSN is instruction which the LOC is part of. */
1560 add_stores (rtx loc
, rtx expr
, void *insn
)
1564 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1565 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1567 if (GET_CODE (expr
) != CLOBBER
1569 && track_expr_p (REG_EXPR (loc
))
1570 && offset_valid_for_tracked_p (REG_OFFSET (loc
)))
1573 mo
->type
= MO_CLOBBER
;
1575 mo
->insn
= (rtx
) insn
;
1577 else if (MEM_P (loc
)
1579 && track_expr_p (MEM_EXPR (loc
))
1580 && offset_valid_for_tracked_p (INT_MEM_OFFSET (loc
)))
1582 basic_block bb
= BLOCK_FOR_INSN ((rtx
) insn
);
1583 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
1585 mo
->type
= GET_CODE (expr
) == CLOBBER
? MO_CLOBBER
: MO_SET
;
1587 mo
->insn
= (rtx
) insn
;
1591 /* Compute the changes of variable locations in the basic block BB. */
1594 compute_bb_dataflow (basic_block bb
)
1598 dataflow_set old_out
;
1599 dataflow_set
*in
= &VTI (bb
)->in
;
1600 dataflow_set
*out
= &VTI (bb
)->out
;
1602 dataflow_set_init (&old_out
, htab_elements (VTI (bb
)->out
.vars
) + 3);
1603 dataflow_set_copy (&old_out
, out
);
1604 dataflow_set_copy (out
, in
);
1606 n
= VTI (bb
)->n_mos
;
1607 for (i
= 0; i
< n
; i
++)
1609 switch (VTI (bb
)->mos
[i
].type
)
1612 for (r
= 0; r
< FIRST_PSEUDO_REGISTER
; r
++)
1613 if (TEST_HARD_REG_BIT (call_used_reg_set
, r
))
1614 var_regno_delete (out
, r
);
1620 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
1623 var_reg_delete_and_set (out
, loc
);
1624 else if (MEM_P (loc
))
1625 var_mem_delete_and_set (out
, loc
);
1632 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
1635 var_reg_delete (out
, loc
);
1636 else if (MEM_P (loc
))
1637 var_mem_delete (out
, loc
);
1642 out
->stack_adjust
+= VTI (bb
)->mos
[i
].u
.adjust
;
1647 changed
= dataflow_set_different (&old_out
, out
);
1648 dataflow_set_destroy (&old_out
);
1652 /* Find the locations of variables in the whole function. */
1655 vt_find_locations (void)
1657 fibheap_t worklist
, pending
, fibheap_swap
;
1658 sbitmap visited
, in_worklist
, in_pending
, sbitmap_swap
;
1665 /* Compute reverse completion order of depth first search of the CFG
1666 so that the data-flow runs faster. */
1667 rc_order
= xmalloc (n_basic_blocks
* sizeof (int));
1668 bb_order
= xmalloc (last_basic_block
* sizeof (int));
1669 flow_depth_first_order_compute (NULL
, rc_order
);
1670 for (i
= 0; i
< n_basic_blocks
; i
++)
1671 bb_order
[rc_order
[i
]] = i
;
1674 worklist
= fibheap_new ();
1675 pending
= fibheap_new ();
1676 visited
= sbitmap_alloc (last_basic_block
);
1677 in_worklist
= sbitmap_alloc (last_basic_block
);
1678 in_pending
= sbitmap_alloc (last_basic_block
);
1679 sbitmap_zero (in_worklist
);
1682 fibheap_insert (pending
, bb_order
[bb
->index
], bb
);
1683 sbitmap_ones (in_pending
);
1685 while (!fibheap_empty (pending
))
1687 fibheap_swap
= pending
;
1689 worklist
= fibheap_swap
;
1690 sbitmap_swap
= in_pending
;
1691 in_pending
= in_worklist
;
1692 in_worklist
= sbitmap_swap
;
1694 sbitmap_zero (visited
);
1696 while (!fibheap_empty (worklist
))
1698 bb
= fibheap_extract_min (worklist
);
1699 RESET_BIT (in_worklist
, bb
->index
);
1700 if (!TEST_BIT (visited
, bb
->index
))
1705 SET_BIT (visited
, bb
->index
);
1707 /* Calculate the IN set as union of predecessor OUT sets. */
1708 dataflow_set_clear (&VTI (bb
)->in
);
1709 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
1711 dataflow_set_union (&VTI (bb
)->in
, &VTI (e
->src
)->out
);
1714 changed
= compute_bb_dataflow (bb
);
1717 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1719 if (e
->dest
== EXIT_BLOCK_PTR
)
1725 if (TEST_BIT (visited
, e
->dest
->index
))
1727 if (!TEST_BIT (in_pending
, e
->dest
->index
))
1729 /* Send E->DEST to next round. */
1730 SET_BIT (in_pending
, e
->dest
->index
);
1731 fibheap_insert (pending
,
1732 bb_order
[e
->dest
->index
],
1736 else if (!TEST_BIT (in_worklist
, e
->dest
->index
))
1738 /* Add E->DEST to current round. */
1739 SET_BIT (in_worklist
, e
->dest
->index
);
1740 fibheap_insert (worklist
, bb_order
[e
->dest
->index
],
1750 fibheap_delete (worklist
);
1751 fibheap_delete (pending
);
1752 sbitmap_free (visited
);
1753 sbitmap_free (in_worklist
);
1754 sbitmap_free (in_pending
);
1757 /* Print the content of the LIST to dump file. */
1760 dump_attrs_list (attrs list
)
1762 for (; list
; list
= list
->next
)
1764 print_mem_expr (dump_file
, list
->decl
);
1765 fprintf (dump_file
, "+" HOST_WIDE_INT_PRINT_DEC
, list
->offset
);
1767 fprintf (dump_file
, "\n");
1770 /* Print the information about variable *SLOT to dump file. */
1773 dump_variable (void **slot
, void *data ATTRIBUTE_UNUSED
)
1775 variable var
= *(variable
*) slot
;
1777 location_chain node
;
1779 fprintf (dump_file
, " name: %s\n",
1780 IDENTIFIER_POINTER (DECL_NAME (var
->decl
)));
1781 for (i
= 0; i
< var
->n_var_parts
; i
++)
1783 fprintf (dump_file
, " offset %ld\n",
1784 (long) var
->var_part
[i
].offset
);
1785 for (node
= var
->var_part
[i
].loc_chain
; node
; node
= node
->next
)
1787 fprintf (dump_file
, " ");
1788 print_rtl_single (dump_file
, node
->loc
);
1792 /* Continue traversing the hash table. */
1796 /* Print the information about variables from hash table VARS to dump file. */
1799 dump_vars (htab_t vars
)
1801 if (htab_elements (vars
) > 0)
1803 fprintf (dump_file
, "Variables:\n");
1804 htab_traverse (vars
, dump_variable
, NULL
);
1808 /* Print the dataflow set SET to dump file. */
1811 dump_dataflow_set (dataflow_set
*set
)
1815 fprintf (dump_file
, "Stack adjustment: " HOST_WIDE_INT_PRINT_DEC
"\n",
1817 for (i
= 1; i
< FIRST_PSEUDO_REGISTER
; i
++)
1821 fprintf (dump_file
, "Reg %d:", i
);
1822 dump_attrs_list (set
->regs
[i
]);
1825 dump_vars (set
->vars
);
1826 fprintf (dump_file
, "\n");
1829 /* Print the IN and OUT sets for each basic block to dump file. */
1832 dump_dataflow_sets (void)
1838 fprintf (dump_file
, "\nBasic block %d:\n", bb
->index
);
1839 fprintf (dump_file
, "IN:\n");
1840 dump_dataflow_set (&VTI (bb
)->in
);
1841 fprintf (dump_file
, "OUT:\n");
1842 dump_dataflow_set (&VTI (bb
)->out
);
1846 /* Add variable VAR to the hash table of changed variables and
1847 if it has no locations delete it from hash table HTAB. */
1850 variable_was_changed (variable var
, htab_t htab
)
1852 hashval_t hash
= VARIABLE_HASH_VAL (var
->decl
);
1858 slot
= (variable
*) htab_find_slot_with_hash (changed_variables
,
1859 var
->decl
, hash
, INSERT
);
1861 if (htab
&& var
->n_var_parts
== 0)
1866 empty_var
= pool_alloc (var_pool
);
1867 empty_var
->decl
= var
->decl
;
1868 empty_var
->refcount
= 1;
1869 empty_var
->n_var_parts
= 0;
1872 old
= htab_find_slot_with_hash (htab
, var
->decl
, hash
,
1875 htab_clear_slot (htab
, old
);
1885 if (var
->n_var_parts
== 0)
1887 void **slot
= htab_find_slot_with_hash (htab
, var
->decl
, hash
,
1890 htab_clear_slot (htab
, slot
);
1895 /* Set the part of variable's location in the dataflow set SET. The variable
1896 part is specified by variable's declaration DECL and offset OFFSET and the
1897 part's location by LOC. */
1900 set_variable_part (dataflow_set
*set
, rtx loc
, tree decl
, HOST_WIDE_INT offset
)
1903 location_chain node
, next
;
1904 location_chain
*nextp
;
1908 slot
= htab_find_slot_with_hash (set
->vars
, decl
,
1909 VARIABLE_HASH_VAL (decl
), INSERT
);
1912 /* Create new variable information. */
1913 var
= pool_alloc (var_pool
);
1916 var
->n_var_parts
= 1;
1917 var
->var_part
[0].offset
= offset
;
1918 var
->var_part
[0].loc_chain
= NULL
;
1919 var
->var_part
[0].cur_loc
= NULL
;
1925 var
= (variable
) *slot
;
1927 /* Find the location part. */
1929 high
= var
->n_var_parts
;
1932 pos
= (low
+ high
) / 2;
1933 if (var
->var_part
[pos
].offset
< offset
)
1940 if (pos
< var
->n_var_parts
&& var
->var_part
[pos
].offset
== offset
)
1942 node
= var
->var_part
[pos
].loc_chain
;
1945 && ((REG_P (node
->loc
) && REG_P (loc
)
1946 && REGNO (node
->loc
) == REGNO (loc
))
1947 || rtx_equal_p (node
->loc
, loc
)))
1949 /* LOC is in the beginning of the chain so we have nothing
1955 /* We have to make a copy of a shared variable. */
1956 if (var
->refcount
> 1)
1957 var
= unshare_variable (set
, var
);
1962 /* We have not found the location part, new one will be created. */
1964 /* We have to make a copy of the shared variable. */
1965 if (var
->refcount
> 1)
1966 var
= unshare_variable (set
, var
);
1968 /* We track only variables whose size is <= MAX_VAR_PARTS bytes
1969 thus there are at most MAX_VAR_PARTS different offsets. */
1970 gcc_assert (var
->n_var_parts
< MAX_VAR_PARTS
);
1972 /* We have to move the elements of array starting at index low to the
1974 for (high
= var
->n_var_parts
; high
> low
; high
--)
1975 var
->var_part
[high
] = var
->var_part
[high
- 1];
1978 var
->var_part
[pos
].offset
= offset
;
1979 var
->var_part
[pos
].loc_chain
= NULL
;
1980 var
->var_part
[pos
].cur_loc
= NULL
;
1984 /* Delete the location from the list. */
1985 nextp
= &var
->var_part
[pos
].loc_chain
;
1986 for (node
= var
->var_part
[pos
].loc_chain
; node
; node
= next
)
1989 if ((REG_P (node
->loc
) && REG_P (loc
)
1990 && REGNO (node
->loc
) == REGNO (loc
))
1991 || rtx_equal_p (node
->loc
, loc
))
1993 pool_free (loc_chain_pool
, node
);
1998 nextp
= &node
->next
;
2001 /* Add the location to the beginning. */
2002 node
= pool_alloc (loc_chain_pool
);
2004 node
->next
= var
->var_part
[pos
].loc_chain
;
2005 var
->var_part
[pos
].loc_chain
= node
;
2007 /* If no location was emitted do so. */
2008 if (var
->var_part
[pos
].cur_loc
== NULL
)
2010 var
->var_part
[pos
].cur_loc
= loc
;
2011 variable_was_changed (var
, set
->vars
);
2015 /* Delete the part of variable's location from dataflow set SET. The variable
2016 part is specified by variable's declaration DECL and offset OFFSET and the
2017 part's location by LOC. */
2020 delete_variable_part (dataflow_set
*set
, rtx loc
, tree decl
,
2021 HOST_WIDE_INT offset
)
2026 slot
= htab_find_slot_with_hash (set
->vars
, decl
, VARIABLE_HASH_VAL (decl
),
2030 variable var
= (variable
) *slot
;
2032 /* Find the location part. */
2034 high
= var
->n_var_parts
;
2037 pos
= (low
+ high
) / 2;
2038 if (var
->var_part
[pos
].offset
< offset
)
2045 if (pos
< var
->n_var_parts
&& var
->var_part
[pos
].offset
== offset
)
2047 location_chain node
, next
;
2048 location_chain
*nextp
;
2051 if (var
->refcount
> 1)
2053 /* If the variable contains the location part we have to
2054 make a copy of the variable. */
2055 for (node
= var
->var_part
[pos
].loc_chain
; node
;
2058 if ((REG_P (node
->loc
) && REG_P (loc
)
2059 && REGNO (node
->loc
) == REGNO (loc
))
2060 || rtx_equal_p (node
->loc
, loc
))
2062 var
= unshare_variable (set
, var
);
2068 /* Delete the location part. */
2069 nextp
= &var
->var_part
[pos
].loc_chain
;
2070 for (node
= *nextp
; node
; node
= next
)
2073 if ((REG_P (node
->loc
) && REG_P (loc
)
2074 && REGNO (node
->loc
) == REGNO (loc
))
2075 || rtx_equal_p (node
->loc
, loc
))
2077 pool_free (loc_chain_pool
, node
);
2082 nextp
= &node
->next
;
2085 /* If we have deleted the location which was last emitted
2086 we have to emit new location so add the variable to set
2087 of changed variables. */
2088 if (var
->var_part
[pos
].cur_loc
2090 && REG_P (var
->var_part
[pos
].cur_loc
)
2091 && REGNO (loc
) == REGNO (var
->var_part
[pos
].cur_loc
))
2092 || rtx_equal_p (loc
, var
->var_part
[pos
].cur_loc
)))
2095 if (var
->var_part
[pos
].loc_chain
)
2096 var
->var_part
[pos
].cur_loc
= var
->var_part
[pos
].loc_chain
->loc
;
2101 if (var
->var_part
[pos
].loc_chain
== NULL
)
2104 while (pos
< var
->n_var_parts
)
2106 var
->var_part
[pos
] = var
->var_part
[pos
+ 1];
2111 variable_was_changed (var
, set
->vars
);
2116 /* Emit the NOTE_INSN_VAR_LOCATION for variable *VARP. DATA contains
2117 additional parameters: WHERE specifies whether the note shall be emitted
2118 before of after instruction INSN. */
2121 emit_note_insn_var_location (void **varp
, void *data
)
2123 variable var
= *(variable
*) varp
;
2124 rtx insn
= ((emit_note_data
*)data
)->insn
;
2125 enum emit_note_where where
= ((emit_note_data
*)data
)->where
;
2127 int i
, j
, n_var_parts
;
2129 HOST_WIDE_INT last_limit
;
2130 tree type_size_unit
;
2131 HOST_WIDE_INT offsets
[MAX_VAR_PARTS
];
2132 rtx loc
[MAX_VAR_PARTS
];
2134 gcc_assert (var
->decl
);
2139 for (i
= 0; i
< var
->n_var_parts
; i
++)
2141 enum machine_mode mode
, wider_mode
;
2143 if (last_limit
< var
->var_part
[i
].offset
)
2148 else if (last_limit
> var
->var_part
[i
].offset
)
2150 offsets
[n_var_parts
] = var
->var_part
[i
].offset
;
2151 loc
[n_var_parts
] = var
->var_part
[i
].loc_chain
->loc
;
2152 mode
= GET_MODE (loc
[n_var_parts
]);
2153 last_limit
= offsets
[n_var_parts
] + GET_MODE_SIZE (mode
);
2155 /* Attempt to merge adjacent registers or memory. */
2156 wider_mode
= GET_MODE_WIDER_MODE (mode
);
2157 for (j
= i
+ 1; j
< var
->n_var_parts
; j
++)
2158 if (last_limit
<= var
->var_part
[j
].offset
)
2160 if (j
< var
->n_var_parts
2161 && wider_mode
!= VOIDmode
2162 && GET_CODE (loc
[n_var_parts
])
2163 == GET_CODE (var
->var_part
[j
].loc_chain
->loc
)
2164 && mode
== GET_MODE (var
->var_part
[j
].loc_chain
->loc
)
2165 && last_limit
== var
->var_part
[j
].offset
)
2168 rtx loc2
= var
->var_part
[j
].loc_chain
->loc
;
2170 if (REG_P (loc
[n_var_parts
])
2171 && hard_regno_nregs
[REGNO (loc
[n_var_parts
])][mode
] * 2
2172 == hard_regno_nregs
[REGNO (loc
[n_var_parts
])][wider_mode
]
2173 && REGNO (loc
[n_var_parts
])
2174 + hard_regno_nregs
[REGNO (loc
[n_var_parts
])][mode
]
2177 if (! WORDS_BIG_ENDIAN
&& ! BYTES_BIG_ENDIAN
)
2178 new_loc
= simplify_subreg (wider_mode
, loc
[n_var_parts
],
2180 else if (WORDS_BIG_ENDIAN
&& BYTES_BIG_ENDIAN
)
2181 new_loc
= simplify_subreg (wider_mode
, loc2
, mode
, 0);
2184 if (!REG_P (new_loc
)
2185 || REGNO (new_loc
) != REGNO (loc
[n_var_parts
]))
2188 REG_ATTRS (new_loc
) = REG_ATTRS (loc
[n_var_parts
]);
2191 else if (MEM_P (loc
[n_var_parts
])
2192 && GET_CODE (XEXP (loc2
, 0)) == PLUS
2193 && GET_CODE (XEXP (XEXP (loc2
, 0), 0)) == REG
2194 && GET_CODE (XEXP (XEXP (loc2
, 0), 1)) == CONST_INT
)
2196 if ((GET_CODE (XEXP (loc
[n_var_parts
], 0)) == REG
2197 && rtx_equal_p (XEXP (loc
[n_var_parts
], 0),
2198 XEXP (XEXP (loc2
, 0), 0))
2199 && INTVAL (XEXP (XEXP (loc2
, 0), 1))
2200 == GET_MODE_SIZE (mode
))
2201 || (GET_CODE (XEXP (loc
[n_var_parts
], 0)) == PLUS
2202 && GET_CODE (XEXP (XEXP (loc
[n_var_parts
], 0), 1))
2204 && rtx_equal_p (XEXP (XEXP (loc
[n_var_parts
], 0), 0),
2205 XEXP (XEXP (loc2
, 0), 0))
2206 && INTVAL (XEXP (XEXP (loc
[n_var_parts
], 0), 1))
2207 + GET_MODE_SIZE (mode
)
2208 == INTVAL (XEXP (XEXP (loc2
, 0), 1))))
2209 new_loc
= adjust_address_nv (loc
[n_var_parts
],
2215 loc
[n_var_parts
] = new_loc
;
2217 last_limit
= offsets
[n_var_parts
] + GET_MODE_SIZE (mode
);
2223 type_size_unit
= TYPE_SIZE_UNIT (TREE_TYPE (var
->decl
));
2224 if ((unsigned HOST_WIDE_INT
) last_limit
< TREE_INT_CST_LOW (type_size_unit
))
2227 if (where
== EMIT_NOTE_AFTER_INSN
)
2228 note
= emit_note_after (NOTE_INSN_VAR_LOCATION
, insn
);
2230 note
= emit_note_before (NOTE_INSN_VAR_LOCATION
, insn
);
2234 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2237 else if (n_var_parts
== 1)
2240 = gen_rtx_EXPR_LIST (VOIDmode
, loc
[0], GEN_INT (offsets
[0]));
2242 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2245 else if (n_var_parts
)
2249 for (i
= 0; i
< n_var_parts
; i
++)
2251 = gen_rtx_EXPR_LIST (VOIDmode
, loc
[i
], GEN_INT (offsets
[i
]));
2253 parallel
= gen_rtx_PARALLEL (VOIDmode
,
2254 gen_rtvec_v (n_var_parts
, loc
));
2255 NOTE_VAR_LOCATION (note
) = gen_rtx_VAR_LOCATION (VOIDmode
, var
->decl
,
2259 htab_clear_slot (changed_variables
, varp
);
2261 /* When there are no location parts the variable has been already
2262 removed from hash table and a new empty variable was created.
2263 Free the empty variable. */
2264 if (var
->n_var_parts
== 0)
2266 pool_free (var_pool
, var
);
2269 /* Continue traversing the hash table. */
2273 /* Emit NOTE_INSN_VAR_LOCATION note for each variable from a chain
2274 CHANGED_VARIABLES and delete this chain. WHERE specifies whether the notes
2275 shall be emitted before of after instruction INSN. */
2278 emit_notes_for_changes (rtx insn
, enum emit_note_where where
)
2280 emit_note_data data
;
2284 htab_traverse (changed_variables
, emit_note_insn_var_location
, &data
);
2287 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it differs from the
2288 same variable in hash table DATA or is not there at all. */
2291 emit_notes_for_differences_1 (void **slot
, void *data
)
2293 htab_t new_vars
= (htab_t
) data
;
2294 variable old_var
, new_var
;
2296 old_var
= *(variable
*) slot
;
2297 new_var
= htab_find_with_hash (new_vars
, old_var
->decl
,
2298 VARIABLE_HASH_VAL (old_var
->decl
));
2302 /* Variable has disappeared. */
2305 empty_var
= pool_alloc (var_pool
);
2306 empty_var
->decl
= old_var
->decl
;
2307 empty_var
->refcount
= 1;
2308 empty_var
->n_var_parts
= 0;
2309 variable_was_changed (empty_var
, NULL
);
2311 else if (variable_different_p (old_var
, new_var
, true))
2313 variable_was_changed (new_var
, NULL
);
2316 /* Continue traversing the hash table. */
2320 /* Add variable *SLOT to the chain CHANGED_VARIABLES if it is not in hash
2324 emit_notes_for_differences_2 (void **slot
, void *data
)
2326 htab_t old_vars
= (htab_t
) data
;
2327 variable old_var
, new_var
;
2329 new_var
= *(variable
*) slot
;
2330 old_var
= htab_find_with_hash (old_vars
, new_var
->decl
,
2331 VARIABLE_HASH_VAL (new_var
->decl
));
2334 /* Variable has appeared. */
2335 variable_was_changed (new_var
, NULL
);
2338 /* Continue traversing the hash table. */
2342 /* Emit notes before INSN for differences between dataflow sets OLD_SET and
2346 emit_notes_for_differences (rtx insn
, dataflow_set
*old_set
,
2347 dataflow_set
*new_set
)
2349 htab_traverse (old_set
->vars
, emit_notes_for_differences_1
, new_set
->vars
);
2350 htab_traverse (new_set
->vars
, emit_notes_for_differences_2
, old_set
->vars
);
2351 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2354 /* Emit the notes for changes of location parts in the basic block BB. */
2357 emit_notes_in_bb (basic_block bb
)
2362 dataflow_set_init (&set
, htab_elements (VTI (bb
)->in
.vars
) + 3);
2363 dataflow_set_copy (&set
, &VTI (bb
)->in
);
2365 for (i
= 0; i
< VTI (bb
)->n_mos
; i
++)
2367 rtx insn
= VTI (bb
)->mos
[i
].insn
;
2369 switch (VTI (bb
)->mos
[i
].type
)
2375 for (r
= 0; r
< FIRST_PSEUDO_REGISTER
; r
++)
2376 if (TEST_HARD_REG_BIT (call_used_reg_set
, r
))
2378 var_regno_delete (&set
, r
);
2380 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2387 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
2390 var_reg_delete_and_set (&set
, loc
);
2392 var_mem_delete_and_set (&set
, loc
);
2394 if (VTI (bb
)->mos
[i
].type
== MO_USE
)
2395 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2397 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2404 rtx loc
= VTI (bb
)->mos
[i
].u
.loc
;
2407 var_reg_delete (&set
, loc
);
2409 var_mem_delete (&set
, loc
);
2411 if (VTI (bb
)->mos
[i
].type
== MO_USE_NO_VAR
)
2412 emit_notes_for_changes (insn
, EMIT_NOTE_BEFORE_INSN
);
2414 emit_notes_for_changes (insn
, EMIT_NOTE_AFTER_INSN
);
2419 set
.stack_adjust
+= VTI (bb
)->mos
[i
].u
.adjust
;
2423 dataflow_set_destroy (&set
);
2426 /* Emit notes for the whole function. */
2429 vt_emit_notes (void)
2432 dataflow_set
*last_out
;
2435 gcc_assert (!htab_elements (changed_variables
));
2437 /* Enable emitting notes by functions (mainly by set_variable_part and
2438 delete_variable_part). */
2441 dataflow_set_init (&empty
, 7);
2446 /* Emit the notes for changes of variable locations between two
2447 subsequent basic blocks. */
2448 emit_notes_for_differences (BB_HEAD (bb
), last_out
, &VTI (bb
)->in
);
2450 /* Emit the notes for the changes in the basic block itself. */
2451 emit_notes_in_bb (bb
);
2453 last_out
= &VTI (bb
)->out
;
2455 dataflow_set_destroy (&empty
);
2459 /* If there is a declaration and offset associated with register/memory RTL
2460 assign declaration to *DECLP and offset to *OFFSETP, and return true. */
2463 vt_get_decl_and_offset (rtx rtl
, tree
*declp
, HOST_WIDE_INT
*offsetp
)
2467 if (REG_ATTRS (rtl
))
2469 *declp
= REG_EXPR (rtl
);
2470 *offsetp
= REG_OFFSET (rtl
);
2474 else if (MEM_P (rtl
))
2476 if (MEM_ATTRS (rtl
))
2478 *declp
= MEM_EXPR (rtl
);
2479 *offsetp
= INT_MEM_OFFSET (rtl
);
2486 /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK. */
2489 vt_add_function_parameters (void)
2493 for (parm
= DECL_ARGUMENTS (current_function_decl
);
2494 parm
; parm
= TREE_CHAIN (parm
))
2496 rtx decl_rtl
= DECL_RTL_IF_SET (parm
);
2497 rtx incoming
= DECL_INCOMING_RTL (parm
);
2499 HOST_WIDE_INT offset
;
2502 if (TREE_CODE (parm
) != PARM_DECL
)
2505 if (!DECL_NAME (parm
))
2508 if (!decl_rtl
|| !incoming
)
2511 if (GET_MODE (decl_rtl
) == BLKmode
|| GET_MODE (incoming
) == BLKmode
)
2514 if (!vt_get_decl_and_offset (incoming
, &decl
, &offset
))
2515 if (!vt_get_decl_and_offset (decl_rtl
, &decl
, &offset
))
2521 gcc_assert (parm
== decl
);
2523 out
= &VTI (ENTRY_BLOCK_PTR
)->out
;
2525 if (REG_P (incoming
))
2527 gcc_assert (REGNO (incoming
) < FIRST_PSEUDO_REGISTER
);
2528 attrs_list_insert (&out
->regs
[REGNO (incoming
)],
2529 parm
, offset
, incoming
);
2530 set_variable_part (out
, incoming
, parm
, offset
);
2532 else if (MEM_P (incoming
))
2533 set_variable_part (out
, incoming
, parm
, offset
);
2537 /* Allocate and initialize the data structures for variable tracking
2538 and parse the RTL to get the micro operations. */
2541 vt_initialize (void)
2545 alloc_aux_for_blocks (sizeof (struct variable_tracking_info_def
));
2550 HOST_WIDE_INT pre
, post
= 0;
2552 /* Count the number of micro operations. */
2553 VTI (bb
)->n_mos
= 0;
2554 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
2555 insn
= NEXT_INSN (insn
))
2559 if (!frame_pointer_needed
)
2561 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
2567 note_uses (&PATTERN (insn
), count_uses_1
, insn
);
2568 note_stores (PATTERN (insn
), count_stores
, insn
);
2574 /* Add the micro-operations to the array. */
2575 VTI (bb
)->mos
= xmalloc (VTI (bb
)->n_mos
2576 * sizeof (struct micro_operation_def
));
2577 VTI (bb
)->n_mos
= 0;
2578 for (insn
= BB_HEAD (bb
); insn
!= NEXT_INSN (BB_END (bb
));
2579 insn
= NEXT_INSN (insn
))
2585 if (!frame_pointer_needed
)
2587 insn_stack_adjust_offset_pre_post (insn
, &pre
, &post
);
2590 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2592 mo
->type
= MO_ADJUST
;
2598 n1
= VTI (bb
)->n_mos
;
2599 note_uses (&PATTERN (insn
), add_uses_1
, insn
);
2600 n2
= VTI (bb
)->n_mos
- 1;
2602 /* Order the MO_USEs to be before MO_USE_NO_VARs. */
2605 while (n1
< n2
&& VTI (bb
)->mos
[n1
].type
== MO_USE
)
2607 while (n1
< n2
&& VTI (bb
)->mos
[n2
].type
== MO_USE_NO_VAR
)
2613 sw
= VTI (bb
)->mos
[n1
];
2614 VTI (bb
)->mos
[n1
] = VTI (bb
)->mos
[n2
];
2615 VTI (bb
)->mos
[n2
] = sw
;
2621 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2627 n1
= VTI (bb
)->n_mos
;
2628 note_stores (PATTERN (insn
), add_stores
, insn
);
2629 n2
= VTI (bb
)->n_mos
- 1;
2631 /* Order the MO_SETs to be before MO_CLOBBERs. */
2634 while (n1
< n2
&& VTI (bb
)->mos
[n1
].type
== MO_SET
)
2636 while (n1
< n2
&& VTI (bb
)->mos
[n2
].type
== MO_CLOBBER
)
2642 sw
= VTI (bb
)->mos
[n1
];
2643 VTI (bb
)->mos
[n1
] = VTI (bb
)->mos
[n2
];
2644 VTI (bb
)->mos
[n2
] = sw
;
2648 if (!frame_pointer_needed
&& post
)
2650 micro_operation
*mo
= VTI (bb
)->mos
+ VTI (bb
)->n_mos
++;
2652 mo
->type
= MO_ADJUST
;
2653 mo
->u
.adjust
= post
;
2660 /* Init the IN and OUT sets. */
2663 VTI (bb
)->visited
= false;
2664 dataflow_set_init (&VTI (bb
)->in
, 7);
2665 dataflow_set_init (&VTI (bb
)->out
, 7);
2668 attrs_pool
= create_alloc_pool ("attrs_def pool",
2669 sizeof (struct attrs_def
), 1024);
2670 var_pool
= create_alloc_pool ("variable_def pool",
2671 sizeof (struct variable_def
), 64);
2672 loc_chain_pool
= create_alloc_pool ("location_chain_def pool",
2673 sizeof (struct location_chain_def
),
2675 changed_variables
= htab_create (10, variable_htab_hash
, variable_htab_eq
,
2677 vt_add_function_parameters ();
2680 /* Free the data structures needed for variable tracking. */
2689 free (VTI (bb
)->mos
);
2694 dataflow_set_destroy (&VTI (bb
)->in
);
2695 dataflow_set_destroy (&VTI (bb
)->out
);
2697 free_aux_for_blocks ();
2698 free_alloc_pool (attrs_pool
);
2699 free_alloc_pool (var_pool
);
2700 free_alloc_pool (loc_chain_pool
);
2701 htab_delete (changed_variables
);
2704 /* The entry point to variable tracking pass. */
2707 variable_tracking_main (void)
2709 if (n_basic_blocks
> 500 && n_edges
/ n_basic_blocks
>= 20)
2712 mark_dfs_back_edges ();
2714 if (!frame_pointer_needed
)
2716 if (!vt_stack_adjustments ())
2723 vt_find_locations ();
2728 dump_dataflow_sets ();
2729 dump_flow_info (dump_file
);
2736 gate_handle_var_tracking (void)
2738 return (flag_var_tracking
);
2743 struct tree_opt_pass pass_variable_tracking
=
2745 "vartrack", /* name */
2746 gate_handle_var_tracking
, /* gate */
2747 variable_tracking_main
, /* execute */
2750 0, /* static_pass_number */
2751 TV_VAR_TRACKING
, /* tv_id */
2752 0, /* properties_required */
2753 0, /* properties_provided */
2754 0, /* properties_destroyed */
2755 0, /* todo_flags_start */
2756 TODO_dump_func
, /* todo_flags_finish */