This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Variable tracking


Hello,

this patch adds variable tracking pass - it tracks where the variables
are located at each position in code and generates location lists.
GDB 6.x can read this information and show value of variables even
in optimized code, i.e. variables in registers, variables on stack
addressed using stack pointer, variables whose location changes in the
function, ...
Variable tracking takes about 2% of compile time and is enabled by
default when compiling with debug info and optimization.

I know GCC is in stage 2 but GDB people would like GCC to generate
location lists...
I think the risk of breaking something is really small. The risk is
almost zero when we disable it by default.

Bootstrapped/regtested x86-64.
OK for mainline?

Josef

2003-10-09  Josef Zlomek  <zlomekj@suse.cz>,
            Daniel Berlin <dberlin@dberlin.org>

	Josef Zlomek <zlomekj@suse.cz>
	* Makefile.in (var-tracking.o): New.
	* common.opt (fvar-tracking): New.
	* gengtype.c (adjust_field_rtx_def): NOTE_INSN_VAR_LOCATION was added.
	* print-rtl.c (print_rtx): Likewise.
        * rtl.c (note_insn_name): Likewise.
        * rtl.def (VAR_LOCATION): New.
        * rtl.h (NOTE_VAR_LOCATION): New.
        (NOTE_VAR_LOCATION_DECL): New.
        (NOTE_VAR_LOCATION_LOC): New.
        (enum insn_note): NOTE_INSN_VAR_LOCATION was added.
        (note_all_uses): New exported function.
        (variable_tracking_main): New exported function.
        * rtlanal.c (note_all_uses): New function.
	* opts.c (common_handle_option): Add OPT_fvar_tracking.
        * timevar.def (TV_VAR_TRACKING): New.
        * toplev.c (enum dump_file_index): Added DFI_vartrack.
        (dump_file): "vartrack" was added (-dV).
        (flag_var_tracking): New.
        (f_options): "var-tracking" was added.
	(rest_of_handle_variable_tracking): New function.
        (rest_of_compilation): Run variable tracking.
	(process_options): If user has not specified flag_var_tracking set it
	according to optimize, debug_info_level and debug_hooks.
	* toplev.h (flag_var_tracking): New.
	* tree.h (frame_base_decl): New.
        * var-tracking.c: New file.
        * doc/invoke.texi: Added -dV and -fvar-tracking.
        * doc/passes.texi: Added variable tracking pass.

	Daniel Berlin <dberlin@dberlin.org>
	* debug.h (struct gcc_debug_hooks): Added var_location debug hook.
	* dbxout.c (dbx_debug_hooks): Likewise.
	(xcoff_debug): Likewise.
	* debug.c (do_nothing_debug_hooks): Likewise.
	* dwarf2out.c (dwarf2_debug_hooks): Likewise.
	* dwarfout.c (dwarf_debug_hooks): Likewise.
	* sdbout.c (sdb_debug_hooks): Likewise.
	* vmsdbgout.c (vmsdbg_debug_hooks): Likewise.
	* final.c (final_scan_insn): Call var_location debug hook for each 
	NOTE_INSN_VAR_LOCATION. 
        * dwarf2out.c (struct gcc_debug_hooks): Call dwarf2out_begin_function
        at the beginning of function, call dwarf2out_var_location for
        NOTE_INSN_VAR_LOCATION note.
	(struct var_loc_node, struct var_loc_list_def, loclabel_num,
	decl_loc_table, decl_loc_table_allocated, decl_loc_table_in_use,
	DECL_LOC_TABLE_INCREMENT): New.
	(lookup_decl_loc): New function.
	(add_var_loc_to_decl): New function.
	(output_loc_list): Fix bug, if separate_line_info_table_in_use
	output addr instead of delta, Location list terminators should be
	DWARF2_ADDR_SIZE long.
	(output_die): Use dw2_asm_output_offset, not dw2_asm_output_delta, for
	location list labels.
	(based_loc_descr): Added parameter can_use_fbreg, DW_OP_fbreg is used
	only if can_use_fbreg.
	(mem_loc_descriptor): Added parameter can_use_fbreg, pass it to other
	functions.
	(loc_descriptor): Likewise. Process VAR_LOCATION.
	(concat_loc_descriptor): Call loc_descriptor with can_use_fbreg == true.
	(loc_descriptor_from_tree): Call mem_loc_descriptor with
	can_use_fbreg == true.
	(add_location_or_const_value_attribute): Added parameter enum
	dwarf_attribute attr, generate attribute ATTR.  Create the location list.
	(add_bound_info): Call loc_descriptor with can_use_fbreg == true.
	(gen_formal_parameter_die): Call add_location_or_const_value_attribute
	with attr == DW_AT_location.
	(gen_subprogram_die): Generate the location list for DW_AT_frame_base
	if frame_base_decl is defined and has a location list.
	(gen_variable_die): Call add_location_or_const_value_attribute with
	attr == DW_AT_location.
        (dwarf2out_var_location): New function.
        (dwarf2out_begin_function): New function.
	(dwarf2out_init): Create decl_loc_table and initialize
	decl_loc_table_allocated and decl_loc_table_in_use.

Index: Makefile.in
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/Makefile.in,v
retrieving revision 1.1168
diff -c -3 -p -r1.1168 Makefile.in
*** Makefile.in	8 Oct 2003 12:24:06 -0000	1.1168
--- Makefile.in	9 Oct 2003 17:13:06 -0000
*************** OBJS-common = \
*** 838,844 ****
   insn-extract.o insn-opinit.o insn-output.o insn-peep.o insn-recog.o	   \
   integrate.o intl.o jump.o  langhooks.o lcm.o lists.o local-alloc.o  	   \
   loop.o optabs.o options.o opts.o params.o postreload.o predict.o	   \
!  print-rtl.o print-tree.o value-prof.o					   \
   profile.o ra.o ra-build.o ra-colorize.o ra-debug.o ra-rewrite.o	   \
   real.o recog.o reg-stack.o regclass.o regmove.o regrename.o		   \
   reload.o reload1.o reorg.o resource.o rtl.o rtlanal.o rtl-error.o	   \
--- 838,844 ----
   insn-extract.o insn-opinit.o insn-output.o insn-peep.o insn-recog.o	   \
   integrate.o intl.o jump.o  langhooks.o lcm.o lists.o local-alloc.o  	   \
   loop.o optabs.o options.o opts.o params.o postreload.o predict.o	   \
!  print-rtl.o print-tree.o value-prof.o var-tracking.o			   \
   profile.o ra.o ra-build.o ra-colorize.o ra-debug.o ra-rewrite.o	   \
   real.o recog.o reg-stack.o regclass.o regmove.o regrename.o		   \
   reload.o reload1.o reorg.o resource.o rtl.o rtlanal.o rtl-error.o	   \
*************** ssa-ccp.o : ssa-ccp.c $(CONFIG_H) $(SYST
*** 1643,1648 ****
--- 1643,1651 ----
  df.o : df.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
     insn-config.h $(RECOG_H) function.h $(REGS_H) alloc-pool.h hard-reg-set.h \
     $(BASIC_BLOCK_H) df.h $(FIBHEAP_H)
+ var-tracking.o : var-tracking.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
+    $(RTL_H) $(TREE_H) hard-reg-set.h insn-config.h reload.h flags.h \
+    $(BASIC_BLOCK_H) output.h sbitmap.h alloc-pool.h $(FIBHEAP_H) $(HASHTAB_H)
  conflict.o : conflict.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(OBSTACK_H) \
     $(HASHTAB_H) $(RTL_H) hard-reg-set.h $(BASIC_BLOCK_H)
  profile.o : profile.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
Index: common.opt
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/common.opt,v
retrieving revision 1.16
diff -c -3 -p -r1.16 common.opt
*** common.opt	3 Sep 2003 20:57:31 -0000	1.16
--- common.opt	9 Oct 2003 16:08:38 -0000
*************** funwind-tables
*** 695,700 ****
--- 695,704 ----
  Common
  Just generate unwind tables for exception handling
  
+ fvar-tracking
+ Common
+ Perform variable tracking
+ 
  fverbose-asm
  Common
  Add extra commentary to assembler output
Index: dbxout.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/dbxout.c,v
retrieving revision 1.163
diff -c -3 -p -r1.163 dbxout.c
*** dbxout.c	5 Oct 2003 13:09:48 -0000	1.163
--- dbxout.c	6 Oct 2003 06:59:09 -0000
*************** const struct gcc_debug_hooks dbx_debug_h
*** 389,395 ****
    debug_nothing_tree,		/* deferred_inline_function */
    debug_nothing_tree,		/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   dbxout_handle_pch		/* handle_pch */
  };
  #endif /* DBX_DEBUGGING_INFO  */
  
--- 389,396 ----
    debug_nothing_tree,		/* deferred_inline_function */
    debug_nothing_tree,		/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   dbxout_handle_pch,		/* handle_pch */
!   debug_nothing_rtx		/* var_location */
  };
  #endif /* DBX_DEBUGGING_INFO  */
  
*************** const struct gcc_debug_hooks xcoff_debug
*** 416,422 ****
    debug_nothing_tree,		/* deferred_inline_function */
    debug_nothing_tree,		/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   dbxout_handle_pch		/* handle_pch */
  };
  #endif /* XCOFF_DEBUGGING_INFO  */
  
--- 417,424 ----
    debug_nothing_tree,		/* deferred_inline_function */
    debug_nothing_tree,		/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   dbxout_handle_pch,		/* handle_pch */
!   debug_nothing_rtx		/* var_location */
  };
  #endif /* XCOFF_DEBUGGING_INFO  */
  
Index: debug.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/debug.c,v
retrieving revision 1.13
diff -c -3 -p -r1.13 debug.c
*** debug.c	29 Jun 2003 15:19:13 -0000	1.13
--- debug.c	26 Sep 2003 18:12:19 -0000
*************** const struct gcc_debug_hooks do_nothing_
*** 44,50 ****
    debug_nothing_tree,		/* deferred_inline_function */
    debug_nothing_tree,		/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   debug_nothing_int		/* handle_pch */
  };
  
  /* This file contains implementations of each debug hook that do
--- 44,51 ----
    debug_nothing_tree,		/* deferred_inline_function */
    debug_nothing_tree,		/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   debug_nothing_int,		/* handle_pch */
!   debug_nothing_rtx		/* var_location */
  };
  
  /* This file contains implementations of each debug hook that do
Index: debug.h
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/debug.h,v
retrieving revision 1.15
diff -c -3 -p -r1.15 debug.h
*** debug.h	6 Jul 2003 18:59:38 -0000	1.15
--- debug.h	26 Sep 2003 18:12:19 -0000
*************** struct gcc_debug_hooks
*** 105,110 ****
--- 105,113 ----
    /* Called after the start and before the end of writing a PCH file.
       The parameter is 0 if after the start, 1 if before the end.  */
    void (* handle_pch) (unsigned int);
+ 
+   /* Called from final_scan_insn for any NOTE_INSN_VAR_LOCATION note. */
+   void (* var_location) PARAMS ((rtx));
  };
  
  extern const struct gcc_debug_hooks *debug_hooks;
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/dwarf2out.c,v
retrieving revision 1.457
diff -c -3 -p -r1.457 dwarf2out.c
*** dwarf2out.c	6 Oct 2003 22:25:15 -0000	1.457
--- dwarf2out.c	9 Oct 2003 12:00:29 -0000
*************** static void dwarf2out_end_block (unsigne
*** 3233,3238 ****
--- 3233,3240 ----
  static bool dwarf2out_ignore_block (tree);
  static void dwarf2out_global_decl (tree);
  static void dwarf2out_abstract_function (tree);
+ static void dwarf2out_var_location (rtx);
+ static void dwarf2out_begin_function (tree);
  
  /* The debug hooks structure.  */
  
*************** const struct gcc_debug_hooks dwarf2_debu
*** 3251,3257 ****
    dwarf2out_begin_prologue,
    debug_nothing_int_charstar,	/* end_prologue */
    dwarf2out_end_epilogue,
!   debug_nothing_tree,		/* begin_function */
    debug_nothing_int,		/* end_function */
    dwarf2out_decl,		/* function_decl */
    dwarf2out_global_decl,
--- 3253,3259 ----
    dwarf2out_begin_prologue,
    debug_nothing_int_charstar,	/* end_prologue */
    dwarf2out_end_epilogue,
!   dwarf2out_begin_function,
    debug_nothing_int,		/* end_function */
    dwarf2out_decl,		/* function_decl */
    dwarf2out_global_decl,
*************** const struct gcc_debug_hooks dwarf2_debu
*** 3261,3267 ****
       something tries to reference them.  */
    dwarf2out_abstract_function,	/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   debug_nothing_int		/* handle_pch */
  };
  #endif
  
--- 3263,3270 ----
       something tries to reference them.  */
    dwarf2out_abstract_function,	/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   debug_nothing_int,		/* handle_pch */
!   dwarf2out_var_location	/* var_location */
  };
  #endif
  
*************** static GTY(()) unsigned decl_die_table_i
*** 3466,3471 ****
--- 3469,3509 ----
     decl_die_table.  */
  #define DECL_DIE_TABLE_INCREMENT 256
  
+ /* Node of the variable location list.  */
+ struct var_loc_node GTY ((chain_next ("%h.next")))
+ {
+   rtx GTY (()) var_loc_note;
+   const char * GTY (()) label;
+   struct var_loc_node * GTY (()) next;
+ };
+ 
+ /* Variable location list.  */
+ struct var_loc_list_def GTY (())
+ {
+   struct var_loc_node * GTY (()) first;
+ 
+   /* Do not mark the last element of the chained list because
+      it is marked through the chain.  */
+   struct var_loc_node * GTY ((skip ("%h"))) last;
+ };
+ typedef struct var_loc_list_def var_loc_list;
+ 
+ /* Unique label counter.  */
+ static unsigned int loclabel_num = 0;
+ 
+ /* Table of decl location linked lists.  */
+ static GTY ((length ("decl_loc_table_allocated"))) var_loc_list *decl_loc_table;
+ 
+ /* Number of elements in the decl_loc_table that are allocated.  */
+ static unsigned decl_loc_table_allocated;
+ 
+ /* Number of elements in the decl_loc_table that are in use.  */
+ static unsigned decl_loc_table_in_use;
+ 
+ /* Size (in elements) of increments by which we may expand the
+    decl_die_table.  */
+ #define DECL_LOC_TABLE_INCREMENT 256
+ 
  /* A pointer to the base of a list of references to DIE's that
     are uniquely identified by their tag, presence/absence of
     children DIE's, and list of attribute/value pairs.  */
*************** static dw_die_ref new_die (enum dwarf_ta
*** 3635,3641 ****
--- 3673,3681 ----
  static dw_die_ref lookup_type_die (tree);
  static void equate_type_number_to_die (tree, dw_die_ref);
  static dw_die_ref lookup_decl_die (tree);
+ static var_loc_list *lookup_decl_loc (tree);
  static void equate_decl_number_to_die (tree, dw_die_ref);
+ static void add_var_loc_to_decl (tree, struct var_loc_node *);
  static void print_spaces (FILE *);
  static void print_die (dw_die_ref, FILE *);
  static void print_dwarf_line_table (FILE *);
*************** static dw_loc_descr_ref reg_loc_descript
*** 3701,3711 ****
  static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
  static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
  static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
! static dw_loc_descr_ref based_loc_descr (unsigned, long);
  static int is_based_loc (rtx);
! static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode);
  static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
! static dw_loc_descr_ref loc_descriptor (rtx);
  static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
  static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
  static tree field_type (tree);
--- 3741,3751 ----
  static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
  static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
  static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
! static dw_loc_descr_ref based_loc_descr (unsigned, long, bool);
  static int is_based_loc (rtx);
! static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode, bool);
  static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx);
! static dw_loc_descr_ref loc_descriptor (rtx, bool);
  static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
  static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
  static tree field_type (tree);
*************** static void add_AT_location_description	
*** 3718,3724 ****
  static void add_data_member_location_attribute (dw_die_ref, tree);
  static void add_const_value_attribute (dw_die_ref, rtx);
  static rtx rtl_for_decl_location (tree);
! static void add_location_or_const_value_attribute (dw_die_ref, tree);
  static void tree_add_const_value_attribute (dw_die_ref, tree);
  static void add_name_attribute (dw_die_ref, const char *);
  static void add_comp_dir_attribute (dw_die_ref);
--- 3758,3765 ----
  static void add_data_member_location_attribute (dw_die_ref, tree);
  static void add_const_value_attribute (dw_die_ref, rtx);
  static rtx rtl_for_decl_location (tree);
! static void add_location_or_const_value_attribute (dw_die_ref, tree,
! 						   enum dwarf_attribute);
  static void tree_add_const_value_attribute (dw_die_ref, tree);
  static void add_name_attribute (dw_die_ref, const char *);
  static void add_comp_dir_attribute (dw_die_ref);
*************** lookup_decl_die (tree decl)
*** 5149,5154 ****
--- 5190,5206 ----
    return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
  }
  
+ /* Return the var_loc list associated with a given declaration.  */
+ 
+ static inline var_loc_list *
+ lookup_decl_loc (decl)
+      tree decl;
+ {
+   unsigned decl_id = DECL_UID (decl);
+ 
+   return (decl_id < decl_loc_table_in_use ? &decl_loc_table[decl_id] : NULL);
+ }
+ 
  /* Equate a DIE to a particular declaration.  */
  
  static void
*************** equate_decl_number_to_die (tree decl, dw
*** 5177,5182 ****
--- 5229,5284 ----
  
    decl_die_table[decl_id] = decl_die;
  }
+ 
+ /* Add a variable location node to the linked list for DECL.  */
+ 
+ static void
+ add_var_loc_to_decl (decl, loc)
+      tree decl;
+      struct var_loc_node *loc;
+ {
+   unsigned int decl_id = DECL_UID (decl);
+   unsigned int num_allocated;
+   var_loc_list *temp;
+ 
+   if (decl_id >= decl_loc_table_allocated)
+     {
+       num_allocated = ((decl_id + 1 + DECL_LOC_TABLE_INCREMENT - 1)
+ 		       / DECL_LOC_TABLE_INCREMENT)
+ 		      * DECL_LOC_TABLE_INCREMENT;
+ 
+       decl_loc_table = ggc_realloc (decl_loc_table,
+ 				    sizeof (var_loc_list) * num_allocated);
+ 
+       memset (&decl_loc_table[decl_loc_table_allocated], 0,
+ 	      (num_allocated - decl_loc_table_allocated)
+ 	      * sizeof (var_loc_list));
+       decl_loc_table_allocated = num_allocated;
+     }
+ 
+   if (decl_id >= decl_loc_table_in_use)
+     decl_loc_table_in_use = decl_id + 1;
+ 
+   temp = &decl_loc_table[decl_id];
+   if (temp->last)
+     {
+       /* If the current location is the same as the end of the list,
+ 	 we have nothing to do.  */
+       if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
+ 			NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
+ 	{
+ 	  /* Add LOC to the end of list and update LAST.  */
+ 	  temp->last->next = loc;
+ 	  temp->last = loc;
+ 	}
+     }
+   /* Do not add empty location to the beginning of the list.  */
+   else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
+     {
+       temp->first = loc;
+       temp->last = loc;
+     }
+ }
  
  /* Keep track of the number of spaces used to indent the
     output of the debugging routines that print the structure of
*************** output_loc_list (dw_loc_list_ref list_he
*** 6479,6485 ****
    /* ??? This shouldn't be needed now that we've forced the
       compilation unit base address to zero when there is code
       in more than one section.  */
!   if (strcmp (curr->section, ".text") == 0)
      {
        /* dw2_asm_output_data will mask off any extra bits in the ~0.  */
        dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
--- 6581,6587 ----
    /* ??? This shouldn't be needed now that we've forced the
       compilation unit base address to zero when there is code
       in more than one section.  */
!   if (strcmp (curr->section, ".text") != 0)
      {
        /* dw2_asm_output_data will mask off any extra bits in the ~0.  */
        dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
*************** output_loc_list (dw_loc_list_ref list_he
*** 6488,6503 ****
  			     "Location list base address specifier base");
      }
  
    for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
      {
        unsigned long size;
! 
!       dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
! 			    "Location list begin address (%s)",
! 			    list_head->ll_symbol);
!       dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
! 			    "Location list end address (%s)",
! 			    list_head->ll_symbol);
        size = size_of_locs (curr->expr);
  
        /* Output the block length for this list of location operations.  */
--- 6590,6617 ----
  			     "Location list base address specifier base");
      }
  
+   /* Walk the location list, and output each range + expression.  */
    for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
      {
        unsigned long size;
!       if (separate_line_info_table_in_use == 0)
! 	{
! 	  dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
! 				"Location list begin address (%s)",
! 				list_head->ll_symbol);
! 	  dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
! 				"Location list end address (%s)",
! 				list_head->ll_symbol);
! 	}
!       else
! 	{
! 	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
! 			       "Location list begin address (%s)",
! 			       list_head->ll_symbol);
! 	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
! 			       "Location list end address (%s)",
! 			       list_head->ll_symbol);
! 	}
        size = size_of_locs (curr->expr);
  
        /* Output the block length for this list of location operations.  */
*************** output_loc_list (dw_loc_list_ref list_he
*** 6508,6517 ****
        output_loc_sequence (curr->expr);
      }
  
!   dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
  		       "Location list terminator begin (%s)",
  		       list_head->ll_symbol);
!   dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
  		       "Location list terminator end (%s)",
  		       list_head->ll_symbol);
  }
--- 6622,6631 ----
        output_loc_sequence (curr->expr);
      }
  
!   dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
  		       "Location list terminator begin (%s)",
  		       list_head->ll_symbol);
!   dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
  		       "Location list terminator end (%s)",
  		       list_head->ll_symbol);
  }
*************** output_die (dw_die_ref die)
*** 6630,6637 ****
  
  	    if (sym == 0)
  	      abort ();
! 	    dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
! 				  loc_section_label, "%s", name);
  	  }
  	  break;
  
--- 6744,6750 ----
  
  	    if (sym == 0)
  	      abort ();
! 	    dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, "%s", name);
  	  }
  	  break;
  
*************** int_loc_descriptor (HOST_WIDE_INT i)
*** 8105,8111 ****
  /* Return a location descriptor that designates a base+offset location.  */
  
  static dw_loc_descr_ref
! based_loc_descr (unsigned int reg, long int offset)
  {
    dw_loc_descr_ref loc_result;
    /* For the "frame base", we use the frame pointer or stack pointer
--- 8218,8224 ----
  /* Return a location descriptor that designates a base+offset location.  */
  
  static dw_loc_descr_ref
! based_loc_descr (unsigned int reg, long int offset, bool can_use_fbreg)
  {
    dw_loc_descr_ref loc_result;
    /* For the "frame base", we use the frame pointer or stack pointer
*************** based_loc_descr (unsigned int reg, long 
*** 8115,8121 ****
  					 ? HARD_FRAME_POINTER_REGNUM
  					 : STACK_POINTER_REGNUM);
  
!   if (reg == fp_reg)
      loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
    else if (reg <= 31)
      loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
--- 8228,8234 ----
  					 ? HARD_FRAME_POINTER_REGNUM
  					 : STACK_POINTER_REGNUM);
  
!   if (reg == fp_reg && can_use_fbreg)
      loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
    else if (reg <= 31)
      loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
*************** is_based_loc (rtx rtl)
*** 8152,8158 ****
     Return 0 if we can't represent the location.  */
  
  static dw_loc_descr_ref
! mem_loc_descriptor (rtx rtl, enum machine_mode mode)
  {
    dw_loc_descr_ref mem_loc_result = NULL;
  
--- 8265,8271 ----
     Return 0 if we can't represent the location.  */
  
  static dw_loc_descr_ref
! mem_loc_descriptor (rtx rtl, enum machine_mode mode, bool can_use_fbreg)
  {
    dw_loc_descr_ref mem_loc_result = NULL;
  
*************** mem_loc_descriptor (rtx rtl, enum machin
*** 8198,8208 ****
  	 memory) so DWARF consumers need to be aware of the subtle
  	 distinction between OP_REG and OP_BASEREG.  */
        if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
! 	mem_loc_result = based_loc_descr (reg_number (rtl), 0);
        break;
  
      case MEM:
!       mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
        if (mem_loc_result != 0)
  	add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
        break;
--- 8311,8322 ----
  	 memory) so DWARF consumers need to be aware of the subtle
  	 distinction between OP_REG and OP_BASEREG.  */
        if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
! 	mem_loc_result = based_loc_descr (reg_number (rtl), 0, can_use_fbreg);
        break;
  
      case MEM:
!       mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
! 					   can_use_fbreg);
        if (mem_loc_result != 0)
  	add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
        break;
*************** mem_loc_descriptor (rtx rtl, enum machin
*** 8269,8278 ****
      plus:
        if (is_based_loc (rtl))
  	mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
! 					  INTVAL (XEXP (rtl, 1)));
        else
  	{
! 	  mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
  	  if (mem_loc_result == 0)
  	    break;
  
--- 8383,8394 ----
      plus:
        if (is_based_loc (rtl))
  	mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
! 					  INTVAL (XEXP (rtl, 1)),
! 					  can_use_fbreg);
        else
  	{
! 	  mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
! 					       can_use_fbreg);
  	  if (mem_loc_result == 0)
  	    break;
  
*************** mem_loc_descriptor (rtx rtl, enum machin
*** 8284,8290 ****
  	  else
  	    {
  	      add_loc_descr (&mem_loc_result,
! 			     mem_loc_descriptor (XEXP (rtl, 1), mode));
  	      add_loc_descr (&mem_loc_result,
  			     new_loc_descr (DW_OP_plus, 0, 0));
  	    }
--- 8400,8407 ----
  	  else
  	    {
  	      add_loc_descr (&mem_loc_result,
! 			     mem_loc_descriptor (XEXP (rtl, 1), mode,
! 						 can_use_fbreg));
  	      add_loc_descr (&mem_loc_result,
  			     new_loc_descr (DW_OP_plus, 0, 0));
  	    }
*************** mem_loc_descriptor (rtx rtl, enum machin
*** 8295,8302 ****
        {
  	/* If a pseudo-reg is optimized away, it is possible for it to
  	   be replaced with a MEM containing a multiply.  */
! 	dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
! 	dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
  
  	if (op0 == 0 || op1 == 0)
  	  break;
--- 8412,8421 ----
        {
  	/* If a pseudo-reg is optimized away, it is possible for it to
  	   be replaced with a MEM containing a multiply.  */
! 	dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
! 						   can_use_fbreg);
! 	dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
! 						   can_use_fbreg);
  
  	if (op0 == 0 || op1 == 0)
  	  break;
*************** mem_loc_descriptor (rtx rtl, enum machin
*** 8315,8325 ****
        /* If this is a MEM, return its address.  Otherwise, we can't
  	 represent this.  */
        if (GET_CODE (XEXP (rtl, 0)) == MEM)
! 	return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
        else
  	return 0;
  
      default:
        abort ();
      }
  
--- 8434,8447 ----
        /* If this is a MEM, return its address.  Otherwise, we can't
  	 represent this.  */
        if (GET_CODE (XEXP (rtl, 0)) == MEM)
! 	return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode,
! 				   can_use_fbreg);
        else
  	return 0;
  
      default:
+       fprintf (stderr, "\nInvalid mem_loc_descriptor RTL:\n");
+       print_rtl (stderr, rtl);
        abort ();
      }
  
*************** static dw_loc_descr_ref
*** 8333,8340 ****
  concat_loc_descriptor (rtx x0, rtx x1)
  {
    dw_loc_descr_ref cc_loc_result = NULL;
!   dw_loc_descr_ref x0_ref = loc_descriptor (x0);
!   dw_loc_descr_ref x1_ref = loc_descriptor (x1);
  
    if (x0_ref == 0 || x1_ref == 0)
      return 0;
--- 8455,8462 ----
  concat_loc_descriptor (rtx x0, rtx x1)
  {
    dw_loc_descr_ref cc_loc_result = NULL;
!   dw_loc_descr_ref x0_ref = loc_descriptor (x0, true);
!   dw_loc_descr_ref x1_ref = loc_descriptor (x1, true);
  
    if (x0_ref == 0 || x1_ref == 0)
      return 0;
*************** concat_loc_descriptor (rtx x0, rtx x1)
*** 8361,8370 ****
     If we don't know how to describe it, return 0.  */
  
  static dw_loc_descr_ref
! loc_descriptor (rtx rtl)
  {
    dw_loc_descr_ref loc_result = NULL;
  
    switch (GET_CODE (rtl))
      {
      case SUBREG:
--- 8483,8495 ----
     If we don't know how to describe it, return 0.  */
  
  static dw_loc_descr_ref
! loc_descriptor (rtx rtl, bool can_use_fbreg)
  {
    dw_loc_descr_ref loc_result = NULL;
  
+   if (!rtl)
+     return 0;
+ 
    switch (GET_CODE (rtl))
      {
      case SUBREG:
*************** loc_descriptor (rtx rtl)
*** 8382,8396 ****
        break;
  
      case MEM:
!       loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
        break;
  
      case CONCAT:
        loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
        break;
  
      default:
!       abort ();
      }
  
    return loc_result;
--- 8507,8557 ----
        break;
  
      case MEM:
!       loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
! 				       can_use_fbreg);
        break;
  
      case CONCAT:
        loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
        break;
  
+     case VAR_LOCATION:
+       /* Single part.  */
+       if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
+ 	{
+ 	  loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), can_use_fbreg);
+ 	}
+       /* Multiple parts.  */
+       else
+ 	{
+ 	  rtvec par_elems = XVEC (XEXP (rtl, 1), 0);
+ 	  int num_elem = GET_NUM_ELEM (par_elems);
+ 	  enum machine_mode mode;
+ 	  int i;
+ 
+ 	  /* Create the first one, so we have something to add to.  */
+ 	  loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
+ 				       can_use_fbreg);
+ 	  mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
+ 	  add_loc_descr (&loc_result,
+ 			 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (mode), 0));
+ 	  for (i = 1; i < num_elem; i++)
+ 	    {
+ 	      dw_loc_descr_ref temp;
+ 
+ 	      temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
+ 				     can_use_fbreg);
+ 	      add_loc_descr (&loc_result, temp);
+ 	      mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
+ 	      add_loc_descr (&loc_result,
+ 			     new_loc_descr (DW_OP_piece,
+ 					    GET_MODE_SIZE (mode), 0));
+ 	    }
+ 	}
+       break;
+ 
      default:
!       return 0;
      }
  
    return loc_result;
*************** loc_descriptor_from_tree (tree loc, int 
*** 8504,8510 ****
  		rtl = XEXP (rtl, 0);
  	      }
  
! 	    ret = mem_loc_descriptor (rtl, mode);
  	  }
        }
        break;
--- 8665,8671 ----
  		rtl = XEXP (rtl, 0);
  	      }
  
! 	    ret = mem_loc_descriptor (rtl, mode, true);
  	  }
        }
        break;
*************** loc_descriptor_from_tree (tree loc, int 
*** 8588,8594 ****
  	rtl = (*targetm.delegitimize_address) (rtl);
  
  	indirect_p = 1;
! 	ret = mem_loc_descriptor (rtl, mode);
  	break;
        }
  
--- 8749,8755 ----
  	rtl = (*targetm.delegitimize_address) (rtl);
  
  	indirect_p = 1;
! 	ret = mem_loc_descriptor (rtl, mode, true);
  	break;
        }
  
*************** rtl_for_decl_location (tree decl)
*** 9397,9412 ****
     function call evaluates to a compile-time constant address.  */
  
  static void
! add_location_or_const_value_attribute (dw_die_ref die, tree decl)
  {
    rtx rtl;
    dw_loc_descr_ref descr;
  
    if (TREE_CODE (decl) == ERROR_MARK)
      return;
    else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
      abort ();
  
    rtl = rtl_for_decl_location (decl);
    if (rtl == NULL_RTX)
      return;
--- 9558,9667 ----
     function call evaluates to a compile-time constant address.  */
  
  static void
! add_location_or_const_value_attribute (dw_die_ref die, tree decl,
! 				       enum dwarf_attribute attr)
  {
    rtx rtl;
    dw_loc_descr_ref descr;
+   var_loc_list *loc_list;
  
    if (TREE_CODE (decl) == ERROR_MARK)
      return;
    else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
      abort ();
  
+   /* See if we possibly have multiple locations for this variable.  */
+   loc_list = lookup_decl_loc (decl);
+ 
+   /* If it truly has multiple locations, the first and last node will
+      differ.  */
+   if (loc_list && loc_list->first != loc_list->last)
+     {
+       const char *secname;
+       const char *endname;
+       dw_loc_list_ref list;
+       rtx varloc;
+       struct var_loc_node *node;
+ 
+       /* We need to figure out what section we should use as the base
+ 	 for the address ranges where a given location is valid.
+ 	 1. If this particular DECL has a section associated with it,
+ 	 use that.
+ 	 2. If this function has a section associated with it, use
+ 	 that.
+ 	 3. Otherwise, use the text section.
+ 	 XXX: If you split a variable across multiple sections, this
+ 	 won't notice.  */
+ 
+       if (DECL_SECTION_NAME (decl))
+ 	{
+ 	  tree sectree = DECL_SECTION_NAME (decl);
+ 	  secname = TREE_STRING_POINTER (sectree);
+ 	}
+       else if (current_function_decl
+ 	       && DECL_SECTION_NAME (current_function_decl))
+ 	{
+ 	  tree sectree = DECL_SECTION_NAME (current_function_decl);
+ 	  secname = TREE_STRING_POINTER (sectree);
+ 	}
+       else
+ 	secname = TEXT_SECTION_NAME;
+ 
+       /* Now that we know what section we are using for a base,
+          actually construct the list of locations.
+ 	 The first location information is what is passed to the
+ 	 function that creates the location list, and the remaining
+ 	 locations just get added on to that list.
+ 	 Note that we only know the start address for a location
+ 	 (IE location changes), so to build the range, we use
+ 	 the range [current location start, next location start].
+ 	 This means we have to special case the last node, and generate
+ 	 a range of [last location start, end of function label].  */
+ 
+       node = loc_list->first;
+       varloc = NOTE_VAR_LOCATION (node->var_loc_note);
+       list = new_loc_list (loc_descriptor (varloc, attr != DW_AT_frame_base),
+ 			   node->label, node->next->label, secname, 1);
+       node = node->next;
+ 
+       for (; node->next; node = node->next)
+ 	if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
+ 	  {
+ 	    /* The variable has a location between NODE->LABEL and
+ 	       NODE->NEXT->LABEL.  */
+ 	    varloc = NOTE_VAR_LOCATION (node->var_loc_note);
+ 	    add_loc_descr_to_loc_list (&list,
+ 				       loc_descriptor (varloc,
+ 						       attr != DW_AT_frame_base),
+ 				       node->label, node->next->label, secname);
+ 	  }
+ 
+       /* If the variable has a location at the last label
+ 	 it keeps its location until the end of function.  */
+       if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
+ 	{
+ 	  char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
+ 
+ 	  varloc = NOTE_VAR_LOCATION (node->var_loc_note);
+ 	  if (!current_function_decl)
+ 	    endname = text_end_label;
+ 	  else
+ 	    {
+ 	      ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
+ 					   current_function_funcdef_no);
+ 	      endname = ggc_strdup (label_id);
+ 	    }
+ 	  add_loc_descr_to_loc_list (&list,
+ 				     loc_descriptor (varloc,
+ 						     attr != DW_AT_frame_base),
+ 				     node->label, endname, secname);
+ 	}
+ 
+       /* Finally, add the location list to the DIE, and we are done.  */
+       add_AT_loc_list (die, attr, list);
+       return;
+     }
+ 
    rtl = rtl_for_decl_location (decl);
    if (rtl == NULL_RTX)
      return;
*************** add_location_or_const_value_attribute (d
*** 9443,9451 ****
  	case REG:
  	case SUBREG:
  	case CONCAT:
! 	  descr = loc_descriptor (rtl);
  	}
!       add_AT_location_description (die, DW_AT_location, descr);
        break;
  
      default:
--- 9698,9706 ----
  	case REG:
  	case SUBREG:
  	case CONCAT:
! 	  descr = loc_descriptor (rtl, true);
  	}
!       add_AT_location_description (die, attr, descr);
        break;
  
      default:
*************** add_bound_info (dw_die_ref subrange_die,
*** 9583,9589 ****
  	  add_AT_flag (decl_die, DW_AT_artificial, 1);
  	  add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
  	  add_AT_location_description (decl_die, DW_AT_location,
! 				       loc_descriptor (loc));
  	  add_AT_die_ref (subrange_die, bound_attr, decl_die);
  	}
  
--- 9838,9844 ----
  	  add_AT_flag (decl_die, DW_AT_artificial, 1);
  	  add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
  	  add_AT_location_description (decl_die, DW_AT_location,
! 				       loc_descriptor (loc, true));
  	  add_AT_die_ref (subrange_die, bound_attr, decl_die);
  	}
  
*************** gen_formal_parameter_die (tree node, dw_
*** 10397,10403 ****
  
        equate_decl_number_to_die (node, parm_die);
        if (! DECL_ABSTRACT (node))
! 	add_location_or_const_value_attribute (parm_die, node);
  
        break;
  
--- 10652,10658 ----
  
        equate_decl_number_to_die (node, parm_die);
        if (! DECL_ABSTRACT (node))
! 	add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
  
        break;
  
*************** gen_subprogram_die (tree decl, dw_die_re
*** 10725,10733 ****
        /* Define the "frame base" location for this routine.  We use the
  	 frame pointer or stack pointer registers, since the RTL for local
  	 variables is relative to one of them.  */
!       fp_reg
! 	= frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
!       add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
  
  #if 0
        /* ??? This fails for nested inline functions, because context_display
--- 10980,10996 ----
        /* Define the "frame base" location for this routine.  We use the
  	 frame pointer or stack pointer registers, since the RTL for local
  	 variables is relative to one of them.  */
!       if (frame_base_decl && lookup_decl_loc (frame_base_decl) != NULL)
! 	{
! 	  add_location_or_const_value_attribute (subr_die, frame_base_decl,
! 						 DW_AT_frame_base);
! 	}
!       else
! 	{
! 	  fp_reg
! 	    = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
! 	  add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
! 	}
  
  #if 0
        /* ??? This fails for nested inline functions, because context_display
*************** gen_variable_die (tree decl, dw_die_ref 
*** 10896,10902 ****
  
    if (! declaration && ! DECL_ABSTRACT (decl))
      {
!       add_location_or_const_value_attribute (var_die, decl);
        add_pubname (decl, var_die);
      }
    else
--- 11159,11165 ----
  
    if (! declaration && ! DECL_ABSTRACT (decl))
      {
!       add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
        add_pubname (decl, var_die);
      }
    else
*************** init_file_table (void)
*** 12185,12190 ****
--- 12448,12510 ----
    file_table_last_lookup_index = 0;
  }
  
+ /* Called by the final INSN scan whenever we see a var location.  We
+    use it to drop labels in the right places, and throw the location in
+    our lookup table.  */
+ 
+ static void
+ dwarf2out_var_location (loc_note)
+      rtx loc_note;
+ {
+   char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
+   struct var_loc_node *newloc;
+   rtx prev_insn;
+   static rtx last_insn;
+   static const char *last_label;
+ 
+   if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
+     return;
+   prev_insn = PREV_INSN (loc_note);
+ 
+   newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
+   /* If the insn we processed last time is the previous insn
+      and it is also a var location note, use the label we emitted
+      last time.  */
+   if (last_insn != NULL_RTX
+       && last_insn == prev_insn
+       && GET_CODE (prev_insn) == NOTE
+       && NOTE_LINE_NUMBER (prev_insn) == NOTE_INSN_VAR_LOCATION)
+     {
+       newloc->label = last_label;
+     }
+   else
+     {
+       ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num++);
+       ASM_OUTPUT_LABEL (asm_out_file, loclabel);
+       newloc->label = ggc_strdup (loclabel);
+     }
+   newloc->var_loc_note = loc_note;
+   newloc->next = NULL;
+ 
+   last_insn = loc_note;
+   last_label = newloc->label;
+ 
+   add_var_loc_to_decl (NOTE_VAR_LOCATION_DECL (loc_note), newloc);
+ }
+ 
+ /* We need to reset the locations at the beginning of each
+    function. We can't do this in the end_function hook, because the
+    declarations that use the locations won't have been outputted when
+    that hook is called.  */
+ 
+ static void
+ dwarf2out_begin_function (unused)
+      tree unused ATTRIBUTE_UNUSED;
+ {
+   decl_loc_table_in_use = 0;
+   memset (decl_loc_table, 0,
+ 	  sizeof (struct var_loc_node *) * decl_loc_table_allocated);
+ }
  /* Output a label to mark the beginning of a source code line entry
     and record information relating to this source line, in
     'line_info_table' for later output of the .debug_line section.  */
*************** dwarf2out_init (const char *filename ATT
*** 12362,12367 ****
--- 12682,12693 ----
  				      * sizeof (dw_die_ref));
    decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
    decl_die_table_in_use = 0;
+ 
+   /* Allocate the initial hunk of the decl_loc_table.  */
+   decl_loc_table = ggc_alloc_cleared (DECL_LOC_TABLE_INCREMENT
+ 				      * sizeof (var_loc_list));
+   decl_loc_table_allocated = DECL_LOC_TABLE_INCREMENT;
+   decl_loc_table_in_use = 0;
  
    /* Allocate the initial hunk of the decl_scope_table.  */
    VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
Index: dwarfout.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/dwarfout.c,v
retrieving revision 1.137
diff -c -3 -p -r1.137 dwarfout.c
*** dwarfout.c	22 Sep 2003 05:09:12 -0000	1.137
--- dwarfout.c	26 Sep 2003 18:12:19 -0000
*************** const struct gcc_debug_hooks dwarf_debug
*** 1294,1300 ****
    dwarfout_deferred_inline_function,
    debug_nothing_tree,		/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   debug_nothing_int		/* handle_pch */
  };
  
  /************************ general utility functions **************************/
--- 1294,1301 ----
    dwarfout_deferred_inline_function,
    debug_nothing_tree,		/* outlining_inline_function */
    debug_nothing_rtx,		/* label */
!   debug_nothing_int,		/* handle_pch */
!   debug_nothing_rtx		/* var_location */
  };
  
  /************************ general utility functions **************************/
Index: final.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/final.c,v
retrieving revision 1.291
diff -c -3 -p -r1.291 final.c
*** final.c	5 Oct 2003 19:50:54 -0000	1.291
--- final.c	6 Oct 2003 06:59:10 -0000
*************** final_scan_insn (rtx insn, FILE *file, i
*** 1777,1782 ****
--- 1777,1786 ----
  	  ASM_OUTPUT_DEBUG_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
  	  break;
  
+ 	case NOTE_INSN_VAR_LOCATION:
+ 	  (*debug_hooks->var_location) (insn);
+ 	  break;
+ 
  	case 0:
  	  break;
  
Index: gengtype.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/gengtype.c,v
retrieving revision 1.39
diff -c -3 -p -r1.39 gengtype.c
*** gengtype.c	14 Aug 2003 03:10:49 -0000	1.39
--- gengtype.c	26 Sep 2003 18:12:19 -0000
*************** adjust_field_rtx_def (type_p t, options_
*** 450,455 ****
--- 450,456 ----
  	    break;
  
  	  case NOTE_INSN_EXPECTED_VALUE:
+ 	  case NOTE_INSN_VAR_LOCATION:
  	    note_flds->name = "rtx";
  	    note_flds->type = rtx_tp;
  	    break;
Index: opts.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/opts.c,v
retrieving revision 1.38
diff -c -3 -p -r1.38 opts.c
*** opts.c	5 Sep 2003 05:36:47 -0000	1.38
--- opts.c	9 Oct 2003 16:09:45 -0000
*************** common_handle_option (size_t scode, cons
*** 1386,1391 ****
--- 1386,1395 ----
        flag_unwind_tables = value;
        break;
  
+     case OPT_fvar_tracking:
+       flag_var_tracking = value;
+       break;
+ 
      case OPT_fverbose_asm:
        flag_verbose_asm = value;
        break;
Index: print-rtl.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/print-rtl.c,v
retrieving revision 1.101
diff -c -3 -p -r1.101 print-rtl.c
*** print-rtl.c	8 Jul 2003 00:35:42 -0000	1.101
--- print-rtl.c	26 Sep 2003 18:12:19 -0000
*************** print_rtx (rtx in_rtx)
*** 307,312 ****
--- 307,320 ----
  		  fprintf (outfile, " [ ERROR ]");
  		break;
  
+ 	      case NOTE_INSN_VAR_LOCATION:
+ 		fprintf (outfile, " (");
+ 		print_mem_expr (outfile, NOTE_VAR_LOCATION_DECL (in_rtx));
+ 		fprintf (outfile, " ");
+ 		print_rtx (NOTE_VAR_LOCATION_LOC (in_rtx));
+ 		fprintf (outfile, ")");
+ 		break;
+ 
  	      default:
  		{
  		  const char * const str = X0STR (in_rtx, i);
Index: rtl.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/rtl.c,v
retrieving revision 1.126
diff -c -3 -p -r1.126 rtl.c
*** rtl.c	30 Jul 2003 19:23:31 -0000	1.126
--- rtl.c	26 Sep 2003 18:12:19 -0000
*************** const char * const note_insn_name[NOTE_I
*** 219,225 ****
    "NOTE_INSN_EH_REGION_BEG", "NOTE_INSN_EH_REGION_END",
    "NOTE_INSN_REPEATED_LINE_NUMBER",
    "NOTE_INSN_BASIC_BLOCK", "NOTE_INSN_EXPECTED_VALUE",
!   "NOTE_INSN_PREDICTION"
  };
  
  const char * const reg_note_name[] =
--- 219,225 ----
    "NOTE_INSN_EH_REGION_BEG", "NOTE_INSN_EH_REGION_END",
    "NOTE_INSN_REPEATED_LINE_NUMBER",
    "NOTE_INSN_BASIC_BLOCK", "NOTE_INSN_EXPECTED_VALUE",
!   "NOTE_INSN_PREDICTION", "NOTE_INSN_VAR_LOCATION"
  };
  
  const char * const reg_note_name[] =
Index: rtl.def
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/rtl.def,v
retrieving revision 1.72
diff -c -3 -p -r1.72 rtl.def
*** rtl.def	11 Jul 2003 23:49:43 -0000	1.72
--- rtl.def	26 Sep 2003 18:12:19 -0000
*************** DEF_RTL_EXPR(US_TRUNCATE, "us_truncate",
*** 1222,1227 ****
--- 1222,1229 ----
     of canonical RTL.  It is, however, easier to manipulate this way.  */
  DEF_RTL_EXPR(PHI, "phi", "E", 'x')
  
+ /* Information about the variable and its location.  */
+ DEF_RTL_EXPR(VAR_LOCATION, "var_location", "te", 'x')
  
  /*
  Local variables:
Index: rtl.h
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/rtl.h,v
retrieving revision 1.435
diff -c -3 -p -r1.435 rtl.h
*** rtl.h	12 Sep 2003 15:07:50 -0000	1.435
--- rtl.h	26 Sep 2003 18:12:19 -0000
*************** extern const char * const reg_note_name[
*** 791,796 ****
--- 791,797 ----
  #define NOTE_EXPECTED_VALUE(INSN) XCEXP (INSN, 4, NOTE)
  #define NOTE_PREDICTION(INSN)   XCINT (INSN, 4, NOTE)
  #define NOTE_PRECONDITIONED(INSN)   XCINT (INSN, 4, NOTE)
+ #define NOTE_VAR_LOCATION(INSN)	XCEXP (INSN, 4, NOTE)
  
  /* In a NOTE that is a line number, this is the line number.
     Other kinds of NOTEs are identified by negative numbers here.  */
*************** extern const char * const reg_note_name[
*** 806,811 ****
--- 807,818 ----
  #define NOTE_PREDICTION_FLAGS(INSN) (XCINT(INSN, 4, NOTE)&0xff)
  #define NOTE_PREDICT(ALG,FLAGS)     ((ALG<<8)+(FLAGS))
  
+ /* Variable declaration and the location of a variable.  */
+ #define NOTE_VAR_LOCATION_DECL(INSN)	(XCTREE (XCEXP (INSN, 4, NOTE), \
+ 						 0, VAR_LOCATION))
+ #define NOTE_VAR_LOCATION_LOC(INSN)	(XCEXP (XCEXP (INSN, 4, NOTE),  \
+ 						1, VAR_LOCATION))
+   
  /* Codes that appear in the NOTE_LINE_NUMBER field
     for kinds of notes that are not line numbers.
  
*************** enum insn_note
*** 889,894 ****
--- 896,904 ----
    /* Record a prediction.  Uses NOTE_PREDICTION.  */
    NOTE_INSN_PREDICTION,
  
+   /* The location of a variable.  */
+   NOTE_INSN_VAR_LOCATION,
+ 
    NOTE_INSN_MAX
  };
  
*************** extern int reg_overlap_mentioned_p (rtx,
*** 1666,1671 ****
--- 1676,1682 ----
  extern rtx set_of (rtx, rtx);
  extern void note_stores (rtx, void (*) (rtx, rtx, void *), void *);
  extern void note_uses (rtx *, void (*) (rtx *, void *), void *);
+ extern void note_all_uses (rtx, void (*) (rtx, void *), void *);
  extern rtx reg_set_last (rtx, rtx);
  extern int dead_or_set_p (rtx, rtx);
  extern int dead_or_set_regno_p (rtx, unsigned int);
*************** extern void invert_br_probabilities (rtx
*** 2291,2295 ****
--- 2302,2309 ----
  extern bool expensive_function_p (int);
  /* In tracer.c */
  extern void tracer (void);
+ 
+ /* In var-tracking.c */
+ extern void variable_tracking_main (void);
  
  #endif /* ! GCC_RTL_H */
Index: rtlanal.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/rtlanal.c,v
retrieving revision 1.168
diff -c -3 -p -r1.168 rtlanal.c
*** rtlanal.c	24 Aug 2003 09:02:32 -0000	1.168
--- rtlanal.c	26 Sep 2003 18:12:19 -0000
*************** note_uses (rtx *pbody, void (*fun) (rtx 
*** 1762,1767 ****
--- 1762,1860 ----
      }
  }
  
+ /* Like notes_uses, but call FUN for each expression that is being
+    referenced in PBODY, a pointer to the PATTERN of an insn, and for all
+    interior subexpressions.  FUN receives a pointer to the expression and the
+    DATA passed to this function.  */
+ 
+ void
+ note_all_uses (rtx body, void (*fun) (rtx, void *), void *data)
+ {
+   int i;
+ 
+   if (body == NULL_RTX)
+     return;
+ 
+   switch (GET_CODE (body))
+     {
+       case REG:
+ 	(*fun) (body, data);
+ 	return;
+ 
+       case MEM:
+ 	(*fun) (body, data);
+ 	note_all_uses (XEXP (body, 0), fun, data);
+ 	return;
+ 
+       case SET:
+ 	note_all_uses (SET_SRC (body), fun, data);
+ 
+ 	/* Fallthru.  */
+       case CLOBBER:
+ 	{
+ 	  rtx dest = SET_DEST (body);
+ 
+ 	  /* Note the uses in DEST, for example the uses in
+ 	     (mem/s:DI (plus:DI (reg/v/f:DI 3 rbx [orig:81 prev ] [81])
+ 			(const_int 24 [0x18])) [0 <variable>.rtx+0 S8 A64])
+ 	   
+ 	     are (reg/v/f:DI 3 rbx [orig:81 prev ] [81])
+ 	     and (const_int 24 [0x18]).  */
+ 
+ 	  while (GET_CODE (dest) == SUBREG
+ 		 || GET_CODE (dest) == ZERO_EXTRACT
+ 		 || GET_CODE (dest) == SIGN_EXTRACT
+ 		 || GET_CODE (dest) == STRICT_LOW_PART)
+ 	    {
+ 	      if (GET_CODE (dest) == ZERO_EXTRACT
+ 		  || GET_CODE (dest) == SIGN_EXTRACT)
+ 		{
+ 		  /* Note the uses in parameters.  */
+ 		  (*fun) (XEXP (dest, 1), data);
+ 		  (*fun) (XEXP (dest, 2), data);
+ 		}
+ 	      dest = XEXP (dest, 0);
+ 	    }
+ 
+ 	  /* If the DEST is a memory, note uses in its subexpressions.  */
+ 	  if (GET_CODE (dest) == MEM)
+ 	    note_all_uses (XEXP (body, 0), fun, data);
+ 	}
+ 	return;
+ 
+       default:
+ 	{
+ 	  int length = GET_RTX_LENGTH (GET_CODE (body));
+ 	  const char *format = GET_RTX_FORMAT (GET_CODE (body));
+ 
+ 	  for (i = 0; i < length; i++)
+ 	    {
+ 	      switch (format[i])
+ 		{
+ 		  case 'e':
+ 		    note_all_uses (XEXP (body, i), fun, data);
+ 		    break;
+ 
+ 		  case 'V':
+ 		  case 'E':
+ 		    if (XVEC (body, i) != 0)
+ 		      {
+ 			int j;
+ 			for (j = 0; j < XVECLEN (body, i); j++)
+ 			  note_all_uses (XVECEXP (body, i, j), fun, data);
+ 		      }
+ 		    break;
+ 
+ 		  default:
+ 		    /* Nothing to do.  */
+ 		    break;
+ 		}
+ 	    }
+ 	}
+         return;
+     }
+ }
+ 
  /* Return nonzero if X's old contents don't survive after INSN.
     This will be true if X is (cc0) or if X is a register and
     X dies in INSN or because INSN entirely sets X.
Index: sdbout.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/sdbout.c,v
retrieving revision 1.80
diff -c -3 -p -r1.80 sdbout.c
*** sdbout.c	30 Sep 2003 21:48:53 -0000	1.80
--- sdbout.c	1 Oct 2003 13:56:00 -0000
*************** const struct gcc_debug_hooks sdb_debug_h
*** 334,340 ****
    debug_nothing_tree,		/* deferred_inline_function */
    debug_nothing_tree,		/* outlining_inline_function */
    sdbout_label,			/* label */
!   debug_nothing_int		/* handle_pch */
  };
  
  /* Return a unique string to name an anonymous type.  */
--- 334,341 ----
    debug_nothing_tree,		/* deferred_inline_function */
    debug_nothing_tree,		/* outlining_inline_function */
    sdbout_label,			/* label */
!   debug_nothing_int,		/* handle_pch */
!   debug_nothing_rtx		/* var_location */
  };
  
  /* Return a unique string to name an anonymous type.  */
Index: timevar.def
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/timevar.def,v
retrieving revision 1.19
diff -c -3 -p -r1.19 timevar.def
*** timevar.def	9 Jul 2003 01:20:22 -0000	1.19
--- timevar.def	26 Sep 2003 18:12:19 -0000
*************** DEFTIMEVAR (TV_SSA_DCE               , "
*** 96,101 ****
--- 96,102 ----
  DEFTIMEVAR (TV_FROM_SSA              , "convert from SSA")
  DEFTIMEVAR (TV_FINAL                 , "final")
  DEFTIMEVAR (TV_SYMOUT                , "symout")
+ DEFTIMEVAR (TV_VAR_TRACKING          , "variable tracking")
  
  /* Everything else in rest_of_compilation not included above.  */
  DEFTIMEVAR (TV_REST_OF_COMPILATION   , "rest of compilation")
Index: toplev.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/toplev.c,v
retrieving revision 1.830
diff -c -3 -p -r1.830 toplev.c
*** toplev.c	28 Sep 2003 04:56:33 -0000	1.830
--- toplev.c	1 Oct 2003 13:56:01 -0000
*************** static void rest_of_handle_reorder_block
*** 153,158 ****
--- 153,159 ----
  #ifdef STACK_REGS
  static void rest_of_handle_stack_regs (tree, rtx);
  #endif
+ static void rest_of_handle_variable_tracking (tree, rtx);
  static void rest_of_handle_machine_reorg (tree, rtx);
  #ifdef DELAY_SLOTS
  static void rest_of_handle_delay_slots (tree, rtx);
*************** enum dump_file_index
*** 284,289 ****
--- 285,291 ----
    DFI_branch_target_load,
    DFI_sched2,
    DFI_stack,
+   DFI_vartrack,
    DFI_mach,
    DFI_dbr,
    DFI_MAX
*************** enum dump_file_index
*** 295,301 ****
     Remaining -d letters:
  
  	"            m   q         "
! 	"         JK   O Q    V  YZ"
  */
  
  static struct dump_file_info dump_file[DFI_MAX] =
--- 297,303 ----
     Remaining -d letters:
  
  	"            m   q         "
! 	"         JK   O Q       YZ"
  */
  
  static struct dump_file_info dump_file[DFI_MAX] =
*************** static struct dump_file_info dump_file[D
*** 337,342 ****
--- 339,345 ----
    { "btl",	'd', 1, 0, 0 }, /* Yes, duplicate enable switch.  */
    { "sched2",	'R', 1, 0, 0 },
    { "stack",	'k', 1, 0, 0 },
+   { "vartrack",	'V', 1, 0, 0 },
    { "mach",	'M', 1, 0, 0 },
    { "dbr",	'd', 0, 0, 0 },
  };
*************** int flag_tracer = 0;
*** 953,958 ****
--- 956,968 ----
  
  int flag_unit_at_a_time = 0;
  
+ /* Nonzero if we should track variables.  When
+    flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING it will be set according
+    to optimize, debug_info_level and debug_hooks in process_options ().  */
+  
+ #define AUTODETECT_FLAG_VAR_TRACKING 2
+ int flag_var_tracking = AUTODETECT_FLAG_VAR_TRACKING;
+ 
  /* Values of the -falign-* flags: how much to align labels in code.
     0 means `use default', 1 means `don't align'.
     For each variable, there is an _log variant which is the power
*************** static const lang_independent_options f_
*** 1130,1136 ****
    {"mem-report", &mem_report, 1 },
    { "trapv", &flag_trapv, 1 },
    { "wrapv", &flag_wrapv, 1 },
!   { "new-ra", &flag_new_regalloc, 1 }
  };
  
  /* Here is a table, controlled by the tm.h file, listing each -m switch
--- 1140,1147 ----
    {"mem-report", &mem_report, 1 },
    { "trapv", &flag_trapv, 1 },
    { "wrapv", &flag_wrapv, 1 },
!   { "new-ra", &flag_new_regalloc, 1 },
!   { "var-tracking", &flag_var_tracking, 1}
  };
  
  /* Here is a table, controlled by the tm.h file, listing each -m switch
*************** rest_of_handle_stack_regs (tree decl, rt
*** 2120,2125 ****
--- 2131,2148 ----
  }
  #endif
  
+ /* Track the variables, ie. compute where the variable is stored at each position in function.  */
+ static void
+ rest_of_handle_variable_tracking (tree decl, rtx insns)
+ {
+   timevar_push (TV_VAR_TRACKING);
+   open_dump_file (DFI_vartrack, decl);
+ 
+   variable_tracking_main ();
+ 
+   close_dump_file (DFI_vartrack, print_rtl_with_bb, insns);
+   timevar_pop (TV_VAR_TRACKING);
+ }
  
  /* Machine independent reorg pass.  */
  static void
*************** rest_of_compilation (tree decl)
*** 3524,3529 ****
--- 3547,3555 ----
  
    compute_alignments ();
  
+   if (flag_var_tracking)
+     rest_of_handle_variable_tracking (decl, insns);
+ 
    /* CFG is no longer maintained up-to-date.  */
    free_bb_for_insn ();
  
*************** process_options (void)
*** 4258,4263 ****
--- 4284,4299 ----
    else
      error ("target system does not support the \"%s\" debug format",
  	   debug_type_names[write_symbols]);
+ 
+   /* Now we know which debug output will be used so we can set
+      flag_var_tracking if user has not specified it.  */
+   if (flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING)
+     {
+       /* User has not specified -f(no-)var-tracking so autodetect it.  */
+       flag_var_tracking
+ 	= (optimize >= 1 && debug_info_level >= DINFO_LEVEL_NORMAL
+ 	   && debug_hooks->var_location != do_nothing_debug_hooks.var_location);
+     }
  
    /* If auxiliary info generation is desired, open the output file.
       This goes in the same directory as the source file--unlike
Index: toplev.h
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/toplev.h,v
retrieving revision 1.114
diff -c -3 -p -r1.114 toplev.h
*** toplev.h	8 Sep 2003 15:56:18 -0000	1.114
--- toplev.h	9 Oct 2003 16:10:22 -0000
*************** extern int flag_ssa_ccp;
*** 123,128 ****
--- 123,129 ----
  extern int flag_ssa_dce;
  extern int time_report;
  extern int flag_new_regalloc;
+ extern int flag_var_tracking;
  
  extern void display_target_options (void);
  extern void print_version (FILE *, const char *);
Index: tree.h
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/tree.h,v
retrieving revision 1.447
diff -c -3 -p -r1.447 tree.h
*** tree.h	28 Sep 2003 19:09:49 -0000	1.447
--- tree.h	3 Oct 2003 06:44:15 -0000
*************** enum ptrmemfunc_vbit_where_t
*** 2044,2049 ****
--- 2044,2050 ----
  
  #define NULL_TREE (tree) NULL
  
+ extern tree frame_base_decl;
  extern tree decl_assembler_name (tree);
  
  /* Compute the number of bytes occupied by 'node'.  This routine only
Index: var-tracking.c
===================================================================
RCS file: var-tracking.c
diff -N var-tracking.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- var-tracking.c	9 Oct 2003 17:11:46 -0000
***************
*** 0 ****
--- 1,2465 ----
+ /* Variable tracking routines for the GNU compiler.
+    Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ 
+    This file is part of GCC.
+ 
+    GCC is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2, or (at your option)
+    any later version.
+ 
+    GCC is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+    License for more details.
+ 
+    You should have received a copy of the GNU General Public License
+    along with GCC; see the file COPYING.  If not, write to the Free
+    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+    02111-1307, USA.  */
+ 
+ /* This file contains the variable tracking pass.  It computes where
+    variables are located (which registers or where in memory) at each position
+    in instruction stream and emits notes describing the locations.
+    Debug information (DWARF2 location lists) is finally generated from
+    these notes.
+    With this debug information, it is possible to show variables
+    even when debugging optimized code.
+ 
+    How does the variable tracking pass work?
+ 
+    First, it scans RTL code for uses, stores and clobbers (register/memory
+    references in instructions), for call insns and for stack adjustments
+    separately for each basic block and saves them to an array of micro
+    operations.
+    The micro operations of one instruction are ordered so that
+    pre-modifying stack adjustment < use < call insn < set < clobber <
+      < post-modifying stack adjustment
+ 
+    Then, a forward dataflow analysis is performed to find out how locations
+    of variables change through code and to propagate the variable locations
+    along control flow graph.  Hybrid Search Algorithm is used for dataflow
+    analysis (as well as in df.c).
+    The IN set for basic block BB is computed as a union of OUT sets of BB's
+    predecessors, the OUT set for BB is copied from the IN set for BB and
+    is changed according to micro operations in BB.
+ 
+    The IN and OUT sets for basic blocks consist of a current stack adjustment
+    (used for adjusting offset of variables addressed using stack pointer),
+    the table of structures describing the locations of parts of a variable
+    and for each physical register a linked list for each physical register.
+    The linked list is a list of variable parts stored in the register,
+    i.e. it is a list of triplets (reg, decl, offset) where decl is
+    REG_EXPR (reg) and offset is REG_OFFSET (reg).  The linked list is used for
+    effective deleting appropriate variable parts when we set or clobber the
+    register.
+ 
+    There may be more than one variable part in a register.  The linked lists
+    should be pretty short so it is a good data structure here.
+    For example in the following code, register allocator may assign same
+    register to variables A and B, and both of them are stored in the same
+    register in CODE:
+ 
+      if (cond)
+        set A;
+      else
+        set B;
+      CODE;
+      if (cond)
+        use A;
+      else
+        use B;
+ 
+    Finally, the NOTE_INSN_VAR_LOCATION notes describing the variable locations
+    are emitted to appropriate positions in RTL code.  Each such a note describes
+    the location of one variable at the point in instruction stream where the
+    note is.  There is no need to emit a note for each variable before each
+    instruction, we only emit these notes where the location of variable changes
+    (this means that we also emit notes for changes between the OUT set of the
+    previous block and the IN set of the current block).
+ 
+    The notes consist of two parts:
+    1. the declaration (from REG_EXPR or MEM_EXPR)
+    2. the location of a variable - it is either a simple register/memory
+       reference (for simple variables, for example int),
+       or a parallel of register/memory references (for a large variables
+       which consist of several parts, for example long long).
+ 
+ 
+    References:
+    "Implementation Techniques for Efficient Data-Flow Analysis of Large
+    Programs"
+    D. C. Atkinson, W. G. Griswold.
+    http://citeseer.nj.nec.com/atkinson01implementation.html
+ 
+ */
+ 
+ #include "config.h"
+ #include "system.h"
+ #include "coretypes.h"
+ #include "tm.h"
+ #include "rtl.h"
+ #include "tree.h"
+ #include "hard-reg-set.h"
+ #include "basic-block.h"
+ #include "flags.h"
+ #include "output.h"
+ #include "insn-config.h"
+ #include "reload.h"
+ #include "sbitmap.h"
+ #include "alloc-pool.h"
+ #include "fibheap.h"
+ #include "hashtab.h"
+ 
+ /* Type of micro operation.  */
+ enum micro_operation_type
+ {
+   MO_USE,	/* Use location (REG or MEM).  */
+   MO_SET,	/* Set location.  */
+   MO_CLOBBER,	/* Clobber location.  */
+   MO_CALL,	/* Call insn.  */
+   MO_ADJUST	/* Adjust stack pointer. */
+ };
+ 
+ /* Where shall the note be emitted?  BEFORE or AFTER the instruction.  */
+ enum emit_note_where
+ {
+   EMIT_NOTE_BEFORE_INSN,
+   EMIT_NOTE_AFTER_INSN
+ };
+ 
+ /* Structure holding information about micro operation.  */
+ typedef struct micro_operation_def
+ {
+   /* Type of micro operation.  */
+   enum micro_operation_type type;
+ 
+   union {
+     /* Location.  */
+     rtx loc;
+ 
+     /* Stack adjustment.  */
+     HOST_WIDE_INT adjust;
+   } u;
+ 
+   /* The instruction which the micro operation is in.  */
+   rtx insn;
+ } micro_operation;
+ 
+ /* Structure for passing some other parameters to function
+    emit_note_insn_var_location.  */
+ typedef struct emit_note_data_def
+ {
+   /* The instruction which the note will be emitted before/after.  */
+   rtx insn;
+ 
+   /* Where the note will be emitted (before/after insn)?  */
+   enum emit_note_where where;
+ } emit_note_data;
+ 
+ /* Description of location of a part of a variable.  The content of a physical
+    register is described by a chain of these structures.
+    The chains are pretty short (usually 1 or 2 elements) and thus
+    chain is the best data structure.  */
+ typedef struct attrs_def
+ {
+   /* Pointer to next member of the list.  */
+   struct attrs_def *next;
+ 
+   /* The rtx of register.  */
+   rtx loc;
+ 
+   /* The declaration corresponding to LOC.  */
+   tree decl;
+ 
+   /* Offset from start of DECL.  */
+   HOST_WIDE_INT offset;
+ } *attrs;
+ 
+ /* Structure holding the IN or OUT set for a basic block.  */
+ typedef struct dataflow_set_def
+ {
+   /* Adjustment of stack offset.  */
+   HOST_WIDE_INT stack_adjust;
+ 
+   /* Attributes for registers (lists of attrs).  */
+   attrs regs[FIRST_PSEUDO_REGISTER];
+ 
+   /* Variable locations.  */
+   htab_t vars;
+ } dataflow_set;
+ 
+ /* The structure (one for each basic block) containing the information
+    needed for variable tracking.  */
+ typedef struct variable_tracking_info_def
+ {
+   /* Number of micro operations stored in the MOS array.  */
+   int n_mos;
+ 
+   /* The array of micro operations.  */
+   micro_operation *mos;
+ 
+   /* The IN and OUT set for dataflow analysis.  */
+   dataflow_set in;
+   dataflow_set out;
+ 
+   /* Has the block been visited in DFS?  */
+   bool visited;
+ } *variable_tracking_info;
+ 
+ /* Structure for chaining the locations.  */
+ typedef struct location_chain_def
+ {
+   /* Next element in the chain.  */
+   struct location_chain_def *next;
+ 
+   /* The location (REG or MEM).  */
+   rtx loc;
+ } *location_chain;
+ 
+ /* Structure describing one part of variable.  */
+ typedef struct var_part_def
+ {
+   location_chain loc_chain;
+ 
+   /* The offset in the variable.  */
+   HOST_WIDE_INT offset;
+ } var_part;
+ 
+ /* Maximum number of location parts.  */
+ #define MAX_VAR_PARTS 16
+ 
+ /* Structure describing where the variable is located.  */
+ typedef struct variable_def
+ {
+   /* The declaration of the variable.  */
+   tree decl;
+ 
+   /* Number of variable parts.  */
+   int n_var_parts;
+ 
+   /* The variable parts.  */
+   var_part var_part[MAX_VAR_PARTS];
+ } *variable;
+ 
+ /* Hash function for DECL for VARIABLE_HTAB.  */
+ #define VARIABLE_HASH_VAL(decl) ((size_t) (decl))
+ 
+ /* Pointer to the BB's information specific to variable tracking pass.  */
+ #define VTI(BB) ((variable_tracking_info) (BB)->aux)
+ 
+ /* Alloc pool for struct attrs_def.  */
+ static alloc_pool attrs_pool;
+ 
+ /* Alloc pool for struct variable_def.  */
+ static alloc_pool var_pool;
+ 
+ /* Alloc pool for struct location_chain_def.  */
+ static alloc_pool loc_chain_pool;
+ 
+ /* Changed variables, notes will be emitted for them.  */
+ static htab_t changed_variables;
+ 
+ /* Shall notes be emitted?  */
+ static bool emit_notes;
+ 
+ /* Fake variable for stack pointer.  */
+ tree frame_base_decl;
+ 
+ /* Local function prototypes.  */
+ static void stack_adjust_offset_pre_post (rtx, HOST_WIDE_INT *,
+ 					  HOST_WIDE_INT *);
+ static void insn_stack_adjust_offset_pre_post (rtx, HOST_WIDE_INT *,
+ 					       HOST_WIDE_INT *);
+ static HOST_WIDE_INT bb_stack_adjust_offset (basic_block);
+ static HOST_WIDE_INT prologue_stack_adjust (void);
+ static bool vt_stack_adjustments (void);
+ static rtx adjust_stack_reference (rtx, HOST_WIDE_INT);
+ static hashval_t variable_htab_hash (const void *);
+ static int variable_htab_eq (const void *, const void *);
+ static void variable_htab_free (void *);
+ 
+ static void init_attrs_list_set (attrs *);
+ static void attrs_list_clear (attrs *);
+ static attrs attrs_list_member (attrs, tree, HOST_WIDE_INT);
+ static void attrs_list_insert (attrs *, tree, HOST_WIDE_INT, rtx);
+ static void attrs_list_copy (attrs *, attrs);
+ static void attrs_list_union (attrs *, attrs);
+ 
+ static void vars_clear (htab_t);
+ static int vars_copy_1 (void **, void *);
+ static void vars_copy (htab_t, htab_t);
+ static void var_reg_delete_and_set (dataflow_set *, rtx);
+ static void var_reg_delete (dataflow_set *, rtx);
+ static void var_regno_delete (dataflow_set *, int);
+ static void var_mem_delete_and_set (dataflow_set *, rtx);
+ static void var_mem_delete (dataflow_set *, rtx);
+ 
+ static void dataflow_set_init (dataflow_set *, int);
+ static void dataflow_set_clear (dataflow_set *);
+ static void dataflow_set_copy (dataflow_set *, dataflow_set *);
+ static int variable_union_info_cmp_pos (const void *, const void *);
+ static int variable_union (void **, void *);
+ static void dataflow_set_union (dataflow_set *, dataflow_set *);
+ static bool variable_part_different_p (var_part *, var_part *);
+ static bool variable_different_p (variable, variable);
+ static int dataflow_set_different_1 (void **, void *);
+ static int dataflow_set_different_2 (void **, void *);
+ static bool dataflow_set_different (dataflow_set *, dataflow_set *);
+ static void dataflow_set_destroy (dataflow_set *);
+ 
+ static bool track_expr_p (tree);
+ static void count_uses (rtx, void *);
+ static void count_stores (rtx, rtx, void *);
+ static void add_uses (rtx, void *);
+ static void add_stores (rtx, rtx, void *);
+ static bool compute_bb_dataflow (basic_block);
+ static void vt_hybrid_search (basic_block, sbitmap, sbitmap);
+ static void vt_iterative_dataflow (int *);
+ 
+ static void dump_attrs_list (attrs);
+ static int dump_variable (void **, void *);
+ static void dump_vars (htab_t);
+ static void dump_dataflow_set (dataflow_set *);
+ static void dump_dataflow_sets (void);
+ 
+ static void variable_was_changed (variable, htab_t);
+ static void set_variable_part (dataflow_set *, rtx, tree, HOST_WIDE_INT);
+ static void delete_variable_part (dataflow_set *, rtx, tree, HOST_WIDE_INT);
+ static int emit_note_insn_var_location (void **, void *);
+ static void emit_notes_for_changes (rtx, enum emit_note_where);
+ static int emit_notes_for_differences_1 (void **, void *);
+ static int emit_notes_for_differences_2 (void **, void *);
+ static void emit_notes_for_differences (rtx, dataflow_set *, dataflow_set *);
+ static void emit_notes_in_bb (basic_block);
+ static void vt_emit_notes (void);
+ 
+ static bool vt_get_decl_and_offset (rtx, tree *, HOST_WIDE_INT *);
+ static void vt_add_function_parameters (void);
+ static void vt_initialize (void);
+ static void vt_finalize (void);
+ 
+ /* Given a SET, calculate the amount of stack adjustment it contains
+    PRE- and POST-modifying stack pointer.
+    This function is similar to stack_adjust_offset.  */
+ 
+ static void
+ stack_adjust_offset_pre_post (rtx pattern, HOST_WIDE_INT *pre,
+ 			      HOST_WIDE_INT *post)
+ {
+   rtx src = SET_SRC (pattern);
+   rtx dest = SET_DEST (pattern);
+   enum rtx_code code;
+ 
+   if (dest == stack_pointer_rtx)
+     {
+       /* (set (reg sp) (plus (reg sp) (const_int))) */
+       code = GET_CODE (src);
+       if (! (code == PLUS || code == MINUS)
+ 	  || XEXP (src, 0) != stack_pointer_rtx
+ 	  || GET_CODE (XEXP (src, 1)) != CONST_INT)
+ 	return;
+ 
+       if (code == MINUS)
+ 	*post += INTVAL (XEXP (src, 1));
+       else
+ 	*post -= INTVAL (XEXP (src, 1));
+     }
+   else if (GET_CODE (dest) == MEM)
+     {
+       /* (set (mem (pre_dec (reg sp))) (foo)) */
+       src = XEXP (dest, 0);
+       code = GET_CODE (src);
+ 
+       switch (code)
+ 	{
+ 	case PRE_MODIFY:
+ 	case POST_MODIFY:
+ 	  if (XEXP (src, 0) == stack_pointer_rtx)
+ 	    {
+ 	      rtx val = XEXP (XEXP (src, 1), 1);
+ 	      /* We handle only adjustments by constant amount.  */
+ 	      if (GET_CODE (XEXP (src, 1)) != PLUS ||
+ 		  GET_CODE (val) != CONST_INT)
+ 		abort ();
+ 	      if (code == PRE_MODIFY)
+ 		*pre -= INTVAL (val);
+ 	      else
+ 		*post -= INTVAL (val);
+ 	      break;
+ 	    }
+ 	  return;
+ 
+ 	case PRE_DEC:
+ 	  if (XEXP (src, 0) == stack_pointer_rtx)
+ 	    {
+ 	      *pre += GET_MODE_SIZE (GET_MODE (dest));
+ 	      break;
+ 	    }
+ 	  return;
+ 
+ 	case POST_DEC:
+ 	  if (XEXP (src, 0) == stack_pointer_rtx)
+ 	    {
+ 	      *post += GET_MODE_SIZE (GET_MODE (dest));
+ 	      break;
+ 	    }
+ 	  return;
+ 
+ 	case PRE_INC:
+ 	  if (XEXP (src, 0) == stack_pointer_rtx)
+ 	    {
+ 	      *pre -= GET_MODE_SIZE (GET_MODE (dest));
+ 	      break;
+ 	    }
+ 	  return;
+ 
+ 	case POST_INC:
+ 	  if (XEXP (src, 0) == stack_pointer_rtx)
+ 	    {
+ 	      *post -= GET_MODE_SIZE (GET_MODE (dest));
+ 	      break;
+ 	    }
+ 	  return;
+ 
+ 	default:
+ 	  return;
+ 	}
+     }
+ }
+ 
+ /* Given an INSN, calculate the amount of stack adjustment it contains
+    PRE- and POST-modifying stack pointer.  */
+ 
+ static void
+ insn_stack_adjust_offset_pre_post (rtx insn, HOST_WIDE_INT *pre,
+ 				   HOST_WIDE_INT *post)
+ {
+   *pre = 0;
+   *post = 0;
+ 
+   if (GET_CODE (PATTERN (insn)) == SET)
+     stack_adjust_offset_pre_post (PATTERN (insn), pre, post);
+   else if (GET_CODE (PATTERN (insn)) == PARALLEL
+ 	   || GET_CODE (PATTERN (insn)) == SEQUENCE)
+     {
+       int i;
+ 
+       /* There may be stack adjustments inside compound insns.  Search
+ 	 for them.  */
+       for ( i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
+ 	if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
+ 	  stack_adjust_offset_pre_post (XVECEXP (PATTERN (insn), 0, i),
+ 					pre, post);
+     }
+ }
+ 
+ /* Compute stack adjustnment in basic block BB.  */
+ 
+ static HOST_WIDE_INT
+ bb_stack_adjust_offset (basic_block bb)
+ {
+   HOST_WIDE_INT offset = 0;
+   int i;
+ 
+   for (i = 0; i < VTI (bb)->n_mos; i++)
+     if (VTI (bb)->mos[i].type == MO_ADJUST)
+       offset += VTI (bb)->mos[i].u.adjust;
+ 
+   return offset;
+ }
+ 
+ /* Compute stack adjustment caused by function prolog.  */
+ 
+ static HOST_WIDE_INT
+ prologue_stack_adjust (void)
+ {
+   HOST_WIDE_INT offset = 0;
+   basic_block bb = ENTRY_BLOCK_PTR->next_bb;
+   rtx insn;
+   rtx end;
+ 
+   if (!bb->end)
+     return 0;
+ 
+   end = NEXT_INSN (bb->end);
+   for (insn = bb->head; insn != end; insn = NEXT_INSN (insn))
+     {
+       if (GET_CODE (insn) == NOTE
+ 	  && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
+ 	break;
+ 
+       if (INSN_P (insn))
+ 	{
+ 	  HOST_WIDE_INT tmp;
+ 
+ 	  insn_stack_adjust_offset_pre_post (insn, &tmp, &tmp);
+ 	  offset += tmp;
+ 	}
+     }
+ 
+   return offset;
+ }
+ 
+ /* Compute stack adjustments for all blocks by traversing DFS tree.
+    Return true when the adjustments on all incoming edges are consistent.
+    Heavily borrowed from flow_depth_first_order_compute.  */
+ 
+ static bool
+ vt_stack_adjustments (void)
+ {
+   edge *stack;
+   int sp;
+ 
+   /* Initialize enttry block.  */
+   VTI (ENTRY_BLOCK_PTR)->visited = true;
+   VTI (ENTRY_BLOCK_PTR)->out.stack_adjust = 0;
+ 
+   /* Allocate stack for back-tracking up CFG.  */
+   stack = xmalloc ((n_basic_blocks + 1) * sizeof (edge));
+   sp = 0;
+ 
+   /* Push the first edge on to the stack.  */
+   stack[sp++] = ENTRY_BLOCK_PTR->succ;
+ 
+   while (sp)
+     {
+       edge e;
+       basic_block src;
+       basic_block dest;
+ 
+       /* Look at the edge on the top of the stack.  */
+       e = stack[sp - 1];
+       src = e->src;
+       dest = e->dest;
+ 
+       /* Check if the edge destination has been visited yet.  */
+       if (!VTI (dest)->visited)
+ 	{
+ 	  VTI (dest)->visited = true;
+ 	  VTI (dest)->in.stack_adjust = VTI (src)->out.stack_adjust;
+ 	  VTI (dest)->out.stack_adjust = (VTI (dest)->in.stack_adjust +
+ 					  bb_stack_adjust_offset (dest));
+ 
+ 	  if (dest->succ)
+ 	    /* Since the DEST node has been visited for the first
+ 	       time, check its successors.  */
+ 	    stack[sp++] = dest->succ;
+ 	}
+       else
+ 	{
+ 	  /* Check whether the adjustments on the edges are the same.  */
+ 	  if (VTI (dest)->in.stack_adjust != VTI (src)->out.stack_adjust)
+ 	    {
+ 	      free (stack);
+ 	      return false;
+ 	    }
+ 
+ 	  if (e->succ_next)
+ 	    /* Go to the next edge.  */
+ 	    stack[sp - 1] = e->succ_next;
+ 	  else
+ 	    /* Return to previous level if there are no more edges.  */
+ 	    sp--;
+ 	}
+     }
+ 
+   free (stack);
+   return true;
+ }
+ 
+ /* Adjust stack reference MEM by ADJUSTMENT bytes and return the new rtx.  */
+ 
+ static rtx
+ adjust_stack_reference (rtx mem, HOST_WIDE_INT adjustment)
+ {
+   rtx adjusted_mem;
+   rtx tmp;
+ 
+   if (frame_pointer_needed)
+     return mem;
+ 
+   adjusted_mem = copy_rtx (mem);
+   XEXP (adjusted_mem, 0) = replace_rtx (XEXP (adjusted_mem, 0),
+ 					stack_pointer_rtx,
+ 					gen_rtx_PLUS (Pmode, stack_pointer_rtx,
+ 						      GEN_INT (adjustment)));
+   tmp = simplify_rtx (XEXP (adjusted_mem, 0));
+   if (tmp)
+     XEXP (adjusted_mem, 0) = tmp;
+ 
+   return adjusted_mem;
+ }
+ 
+ /* The hash function for variable_htab, computes the hash value
+    from the declaration of variable X.  */
+ 
+ static hashval_t
+ variable_htab_hash (const void *x)
+ {
+   const variable v = (const variable) x;
+ 
+   return (VARIABLE_HASH_VAL (v->decl));
+ }
+ 
+ /* Compare the declaration of variable X with declaration Y.  */
+ 
+ static int
+ variable_htab_eq (const void *x, const void *y)
+ {
+   const variable v = (const variable) x;
+   const tree decl = (const tree) y;
+ 
+   return (VARIABLE_HASH_VAL (v->decl) == VARIABLE_HASH_VAL (decl));
+ }
+ 
+ /* Free the element of VARIABLE_HTAB (its type is struct variable_def).  */
+ 
+ static void
+ variable_htab_free (void *elem)
+ {
+   int i;
+   variable var = (variable) elem;
+   location_chain node, next;
+ 
+   for (i = 0; i < var->n_var_parts; i++)
+     {
+       for (node = var->var_part[i].loc_chain; node; node = next)
+ 	{
+ 	  next = node->next;
+ 	  pool_free (loc_chain_pool, node);
+ 	}
+       var->var_part[i].loc_chain = NULL;
+     }
+   pool_free (var_pool, var);
+ }
+ 
+ /* Initialize the set (array) SET of attrs to empty lists.  */
+ 
+ static void
+ init_attrs_list_set (attrs *set)
+ {
+   int i;
+ 
+   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+     set[i] = NULL;
+ }
+ 
+ /* Make the list *LISTP empty.  */
+ 
+ static void
+ attrs_list_clear (attrs *listp)
+ {
+   attrs list, next;
+ 
+   for (list = *listp; list; list = next)
+     {
+       next = list->next;
+       pool_free (attrs_pool, list);
+     }
+   *listp = NULL;
+ }
+ 
+ /* Return true if the pair of DECL and OFFSET is the member of the LIST.  */
+ 
+ static attrs
+ attrs_list_member (attrs list, tree decl, HOST_WIDE_INT offset)
+ {
+   for (; list; list = list->next)
+     if (list->decl == decl && list->offset == offset)
+       return list;
+   return NULL;
+ }
+ 
+ /* Insert the triplet DECL, OFFSET, LOC to the list *LISTP.  */
+ 
+ static void
+ attrs_list_insert (attrs *listp, tree decl, HOST_WIDE_INT offset, rtx loc)
+ {
+   attrs list;
+ 
+   list = pool_alloc (attrs_pool);
+   list->loc = loc;
+   list->decl = decl;
+   list->offset = offset;
+   list->next = *listp;
+   *listp = list;
+ }
+ 
+ /* Copy all nodes from SRC and create a list *DSTP of the copies.  */
+ 
+ static void
+ attrs_list_copy (attrs *dstp, attrs src)
+ {
+   attrs n;
+ 
+   attrs_list_clear (dstp);
+   for (; src; src = src->next)
+     {
+       n = pool_alloc (attrs_pool);
+       n->loc = src->loc;
+       n->decl = src->decl;
+       n->offset = src->offset;
+       n->next = *dstp;
+       *dstp = n;
+     }
+ }
+ 
+ /* Add all nodes from SRC which are not in *DSTP to *DSTP.  */
+ 
+ static void
+ attrs_list_union (attrs *dstp, attrs src)
+ {
+   for (; src; src = src->next)
+     {
+       if (!attrs_list_member (*dstp, src->decl, src->offset))
+ 	attrs_list_insert (dstp, src->decl, src->offset, src->loc);
+     }
+ }
+ 
+ /* Delete all variables from hash table VARS.  */
+ 
+ static void
+ vars_clear (htab_t vars)
+ {
+   htab_empty (vars);
+ }
+ 
+ /* Copy one variable from *SLOT to hash table DATA.  */
+ 
+ static int
+ vars_copy_1 (void **slot, void *data)
+ {
+   htab_t dst = (htab_t) data;
+   variable src, *dstp, var;
+   int i;
+ 
+   src = *(variable *) slot;
+   dstp = (variable *) htab_find_slot_with_hash (dst, src->decl,
+ 						VARIABLE_HASH_VAL (src->decl),
+ 						INSERT);
+   var = pool_alloc (var_pool);
+   var->decl = src->decl;
+   var->n_var_parts = src->n_var_parts;
+   *dstp = (void *) var;
+ 
+   for (i = 0; i < var->n_var_parts; i++)
+     {
+       location_chain last, node;
+ 
+       var->var_part[i].offset = src->var_part[i].offset;
+       last = NULL;
+       for (node = src->var_part[i].loc_chain; node; node = node->next)
+ 	{
+ 	  location_chain new_lc;
+ 
+ 	  new_lc = pool_alloc (loc_chain_pool);
+ 	  new_lc->next = NULL;
+ 	  new_lc->loc = node->loc;
+ 
+ 	  if (last)
+ 	    last->next = new_lc;
+ 	  else
+ 	    var->var_part[i].loc_chain = new_lc;
+ 	  last = new_lc;
+ 	}
+     }
+ 
+   /* Continue traversing the hash table.  */
+   return 1;
+ }
+ 
+ /* Copy all variables from hash table SRC to hash table DST.  */
+ 
+ static void
+ vars_copy (htab_t dst, htab_t src)
+ {
+   vars_clear (dst);
+   htab_traverse (src, vars_copy_1, dst);
+ }
+ 
+ /* Delete current content of register LOC in dataflow set SET
+    and set the register to contain REG_EXPR (LOC), REG_OFFSET (LOC).  */
+ 
+ static void
+ var_reg_delete_and_set (dataflow_set *set, rtx loc)
+ {
+   attrs *reg = &set->regs[REGNO (loc)];
+   tree decl = REG_EXPR (loc);
+   HOST_WIDE_INT offset = REG_OFFSET (loc);
+   attrs node, prev, next;
+ 
+   prev = NULL;
+   for (node = *reg; node; node = next)
+     {
+       next = node->next;
+       if (node->decl != decl || node->offset != offset)
+ 	{
+ 	  delete_variable_part (set, node->loc, node->decl, node->offset);
+ 
+ 	  if (prev)
+ 	    prev->next = next;
+ 	  else
+ 	    *reg = next;
+ 	  pool_free (attrs_pool, node);
+ 	}
+       else
+ 	{
+ 	  node->loc = loc;
+ 	  prev = node;
+ 	}
+     }
+   if (*reg == NULL)
+     attrs_list_insert (reg, decl, offset, loc);
+   set_variable_part (set, loc, decl, offset);
+ }
+ 
+ /* Delete current content of register LOC in dataflow set SET.  */
+ 
+ static void
+ var_reg_delete (dataflow_set *set, rtx loc)
+ {
+   attrs *reg = &set->regs[REGNO (loc)];
+   attrs node, next;
+ 
+   for (node = *reg; node; node = next)
+     {
+       next = node->next;
+       delete_variable_part (set, node->loc, node->decl, node->offset);
+       pool_free (attrs_pool, node);
+     }
+   *reg = NULL;
+ }
+ 
+ /* Delete content of register with number REGNO in dataflow set SET.  */
+ 
+ static void
+ var_regno_delete (dataflow_set *set, int regno)
+ {
+   attrs *reg = &set->regs[regno];
+   attrs node, next;
+ 
+   for (node = *reg; node; node = next)
+     {
+       next = node->next;
+       delete_variable_part (set, node->loc, node->decl, node->offset);
+       pool_free (attrs_pool, node);
+     }
+   *reg = NULL;
+ }
+ 
+ /* Delete and set the location part of variable MEM_EXPR (LOC)
+    in dataflow set SET to LOC.
+    Adjust the address first if it is stack pointer based.  */
+ 
+ static void
+ var_mem_delete_and_set (dataflow_set *set, rtx loc)
+ {
+   tree decl = MEM_EXPR (loc);
+   HOST_WIDE_INT offset = MEM_OFFSET (loc) ? INTVAL (MEM_OFFSET (loc)) : 0;
+ 
+   loc = adjust_stack_reference (loc, -set->stack_adjust);
+   set_variable_part (set, loc, decl, offset);
+ }
+ 
+ /* Delete the location part LOC from dataflow set SET.
+    Adjust the address first if it is stack pointer based.  */
+ 
+ static void
+ var_mem_delete (dataflow_set *set, rtx loc)
+ {
+   tree decl = MEM_EXPR (loc);
+   HOST_WIDE_INT offset = MEM_OFFSET (loc) ? INTVAL (MEM_OFFSET (loc)) : 0;
+ 
+   loc = adjust_stack_reference (loc, -set->stack_adjust);
+ 
+   delete_variable_part (set, loc, decl, offset);
+ }
+ 
+ /* Initialize dataflow set SET to be empty. 
+    VARS_SIZE is the initial size of hash table VARS.  */
+ 
+ static void
+ dataflow_set_init (dataflow_set *set, int vars_size)
+ {
+   init_attrs_list_set (set->regs);
+   set->vars = htab_create (vars_size, variable_htab_hash, variable_htab_eq,
+ 			   variable_htab_free);
+   set->stack_adjust = 0;
+ }
+ 
+ /* Delete the contents of dataflow set SET.  */
+ 
+ static void
+ dataflow_set_clear (dataflow_set *set)
+ {
+   int i;
+ 
+   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+     attrs_list_clear (&set->regs[i]);
+ 
+   vars_clear (set->vars);
+ }
+ 
+ /* Copy the contents of dataflow set SRC to DST.  */
+ 
+ static void
+ dataflow_set_copy (dataflow_set *dst, dataflow_set *src)
+ {
+   int i;
+ 
+   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+     attrs_list_copy (&dst->regs[i], src->regs[i]);
+ 
+   vars_copy (dst->vars, src->vars);
+   dst->stack_adjust = src->stack_adjust;
+ }
+ 
+ /* Information for merging lists of locations for a given offset of variable.
+  */
+ struct variable_union_info
+ {
+   /* Node of the location chain.  */
+   location_chain lc;
+ 
+   /* The sum of positions in the input chains.  */
+   int pos;
+ 
+   /* The position in the chains of SRC and DST dataflow sets.  */
+   int pos_src;
+   int pos_dst;
+ };
+ 
+ /* Compare function for qsort, order the structures by POS element.  */
+ 
+ static int
+ variable_union_info_cmp_pos (const void *n1, const void *n2)
+ {
+   const struct variable_union_info *i1 = n1;
+   const struct variable_union_info *i2 = n2;
+ 
+   if (i1->pos != i2->pos)
+     return i1->pos - i2->pos;
+   
+   return (i1->pos_dst - i2->pos_dst);
+ }
+ 
+ /* Compute union of location parts of variable *SLOT and the same variable
+    from hash table DATA.  Compute "sorted" union of the location chains
+    for common offsets, i.e. the locations of a variable part are sorted by
+    a priority where the priority is the sum of the positions in the 2 chains
+    (if a location is only in one list the position in the second list is defined
+    to be larger than the length of the chains).
+    When we are updating the location parts the newest location is in the
+    beginning of the chain, so when we do the described "sorted" union
+    we keep the newest locations in the beginning.  */
+ 
+ static int
+ variable_union (void **slot, void *data)
+ {
+   variable src, dst, *dstp;
+   dataflow_set *set = (dataflow_set *) data;
+   int i, j, k;
+ 
+   src = *(variable *) slot;
+   dstp = (variable *) htab_find_slot_with_hash (set->vars, src->decl,
+ 						VARIABLE_HASH_VAL (src->decl),
+ 						INSERT);
+   if (!*dstp)
+     {
+       *dstp = dst = pool_alloc (var_pool);
+       dst->decl = src->decl;
+       dst->n_var_parts = 0;
+     }
+   else
+     dst = *dstp;
+ 
+ #ifdef ENABLE_CHECKING
+   if (src->n_var_parts == 0)
+     abort ();
+ #endif
+ 
+   /* Count the number of location parts, result is K.  */
+   for (i = 0, j = 0, k = 0;
+        i < src->n_var_parts && j < dst->n_var_parts; k++)
+     {
+       if (src->var_part[i].offset == dst->var_part[j].offset)
+ 	{
+ 	  i++;
+ 	  j++;
+ 	}
+       else if (src->var_part[i].offset < dst->var_part[j].offset)
+ 	i++;
+       else
+ 	j++;
+     }
+   if (i < src->n_var_parts)
+     k += src->n_var_parts - i;
+   if (j < dst->n_var_parts)
+     k += dst->n_var_parts - j;
+ #ifdef ENABLE_CHECKING
+   /* We track only variables whose size is <= MAX_VAR_PARTS bytes
+      thus there are at most MAX_VAR_PARTS different offsets.  */
+   if (k > MAX_VAR_PARTS)
+     abort ();
+ #endif
+ 
+   i = src->n_var_parts - 1;
+   j = dst->n_var_parts - 1;
+   dst->n_var_parts = k;
+ 
+   for (k--; k >= 0; k--)
+     {
+       location_chain node;
+ 
+       if (i >= 0 && j >= 0
+ 	  && src->var_part[i].offset == dst->var_part[j].offset)
+ 	{
+ 	  /* Compute the "sorted" union of the chains, i.e. the locations which
+ 	     are in both chains go first, they are sorted by the sum of
+ 	     positions in the chains.  */
+ 	  int dst_l, src_l;
+ 	  int ii, jj, n;
+ 	  struct variable_union_info *vui;
+ 	  
+ 	  src_l = 0;
+ 	  for (node = src->var_part[i].loc_chain; node; node = node->next)
+ 	    src_l++;
+ 	  dst_l = 0;
+ 	  for (node = dst->var_part[j].loc_chain; node; node = node->next)
+ 	    dst_l++;
+ 	  vui = xcalloc (src_l + dst_l, sizeof (struct variable_union_info));
+ 
+ 	  /* Fill in the locations from DST.  */
+ 	  for (node = dst->var_part[j].loc_chain, jj = 0; node;
+ 	       node = node->next, jj++)
+ 	    {
+ 	      vui[jj].lc = node;
+ 	      vui[jj].pos_dst = jj;
+ 
+ 	      /* Value larger than a sum of 2 valid positions.  */
+ 	      vui[jj].pos_src = src_l + dst_l;
+ 	    }
+ 
+ 	  /* Fill in the locations from SRC.  */
+ 	  n = dst_l;
+ 	  for (node = src->var_part[i].loc_chain, ii = 0; node;
+ 	       node = node->next, ii++)
+ 	    {
+ 	      /* Find location from NODE.  */
+ 	      for (jj = 0; jj < dst_l; jj++)
+ 		{
+ 		  if ((GET_CODE (vui[jj].lc->loc) == REG
+ 		       && GET_CODE (node->loc) == REG
+ 		       && REGNO (vui[jj].lc->loc) == REGNO (node->loc))
+ 		      || rtx_equal_p (vui[jj].lc->loc, node->loc))
+ 		    {
+ 		      vui[jj].pos_src = ii;
+ 		      break;
+ 		    }
+ 		}
+ 	      if (jj >= dst_l)	/* The location has not been found.  */
+ 		{
+ 		  location_chain new_node;
+ 
+ 		  /* Copy the location from SRC.  */
+ 		  new_node = pool_alloc (loc_chain_pool);
+ 		  new_node->loc = node->loc;
+ 		  vui[n].lc = new_node;
+ 		  vui[n].pos_src = ii;
+ 		  vui[n].pos_dst = src_l + dst_l;
+ 		  n++;
+ 		}
+ 	    }
+ 
+ 	  for (ii = 0; ii < src_l + dst_l; ii++)
+ 	    vui[ii].pos = vui[ii].pos_src + vui[ii].pos_dst;
+ 
+ 	  qsort (vui, n, sizeof (struct variable_union_info),
+ 		 variable_union_info_cmp_pos);
+ 
+ 	  /* Reconnect the nodes in sorted order.  */
+ 	  for (ii = 1; ii < n; ii++)
+ 	    vui[ii - 1].lc->next = vui[ii].lc;
+ 	  vui[n - 1].lc->next = NULL;
+ 
+ 	  dst->var_part[k].loc_chain = vui[0].lc;
+ 	  dst->var_part[k].offset = dst->var_part[j].offset;
+ 
+ 	  free (vui);
+ 	  i--;
+ 	  j--;
+ 	}
+       else if ((i >= 0 && j >= 0
+ 		&& src->var_part[i].offset < dst->var_part[j].offset)
+ 	       || i < 0)
+ 	{
+ 	  dst->var_part[k] = dst->var_part[j];
+ 	  j--;
+ 	}
+       else if ((i >= 0 && j >= 0
+ 		&& src->var_part[i].offset > dst->var_part[j].offset)
+ 	       || j < 0)
+ 	{
+ 	  location_chain last = NULL;
+ 
+ 	  /* Copy the chain from SRC.  */
+ 	  for (node = src->var_part[i].loc_chain; node; node = node->next)
+ 	    {
+ 	      location_chain new_lc;
+ 
+ 	      new_lc = pool_alloc (loc_chain_pool);
+ 	      new_lc->next = NULL;
+ 	      new_lc->loc = node->loc;
+ 
+ 	      if (last)
+ 		last->next = new_lc;
+ 	      else
+ 		dst->var_part[k].loc_chain = new_lc;
+ 	      last = new_lc;
+ 	    }
+ 
+ 	  dst->var_part[k].offset = src->var_part[i].offset;
+ 	  i--;
+ 	}
+     }
+ 
+   /* Continue traversing the hash table.  */
+   return 1;
+ }
+ 
+ /* Compute union of dataflow sets SRC and DST and store it to DST.  */
+ 
+ static void
+ dataflow_set_union (dataflow_set *dst, dataflow_set *src)
+ {
+   int i;
+ 
+   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+     attrs_list_union (&dst->regs[i], src->regs[i]);
+ 
+   htab_traverse (src->vars, variable_union, dst);
+ }
+ 
+ /* Flag whether two dataflow sets being compared contain different data.  */
+ static bool
+ dataflow_set_different_value;
+ 
+ static bool
+ variable_part_different_p (var_part *vp1, var_part *vp2)
+ {
+   location_chain lc1, lc2;
+ 
+   for (lc1 = vp1->loc_chain; lc1; lc1 = lc1->next)
+     {
+       for (lc2 = vp2->loc_chain; lc2; lc2 = lc2->next)
+ 	{
+ 	  if (GET_CODE (lc1->loc) == REG && GET_CODE (lc2->loc) == REG)
+ 	    {
+ 	      if (REGNO (lc1->loc) == REGNO (lc2->loc))
+ 		break;
+ 	    }
+ 	  if (rtx_equal_p (lc1->loc, lc2->loc))
+ 	    break;
+ 	}
+       if (!lc2)
+ 	return true;
+     }
+   return false;
+ }
+ 
+ /* Return true if variables VAR1 and VAR2 are different (only the first
+    location in the list of locations is checked for each offset,
+    i.e. when true is returned a note should be emitted).  */
+ 
+ static bool
+ variable_different_p (variable var1, variable var2)
+ {
+   int i;
+ 
+   if (var1->n_var_parts != var2->n_var_parts)
+     return true;
+ 
+   for (i = 0; i < var1->n_var_parts; i++)
+     {
+       if (var1->var_part[i].offset != var2->var_part[i].offset)
+ 	return true;
+       if (variable_part_different_p (&var1->var_part[i], &var2->var_part[i]))
+ 	return true;
+       if (variable_part_different_p (&var2->var_part[i], &var1->var_part[i]))
+ 	return true;
+     }
+   return false;
+ }
+ 
+ /* Compare variable *SLOT with the same variable in hash table DATA
+    and set DATAFLOW_SET_DIFFERENT_VALUE if they are different.  */
+ 
+ static int
+ dataflow_set_different_1 (void **slot, void *data)
+ {
+   htab_t htab = (htab_t) data;
+   variable var1, var2;
+ 
+   var1 = *(variable *) slot;
+   var2 = (variable) htab_find_with_hash (htab, var1->decl,
+ 					 VARIABLE_HASH_VAL (var1->decl));
+   if (!var2)
+     {
+       dataflow_set_different_value = true;
+ 
+       /* Stop traversing the hash table.   */
+       return 0;
+     }
+ 
+   if (variable_different_p (var1, var2))
+     {
+       dataflow_set_different_value = true;
+ 
+       /* Stop traversing the hash table.   */
+       return 0;
+     }
+ 
+   /* Continue traversing the hash table.  */
+   return 1;
+ }
+ 
+ /* Compare variable *SLOT with the same variable in hash table DATA
+    and set DATAFLOW_SET_DIFFERENT_VALUE if they are different.  */
+ 
+ static int
+ dataflow_set_different_2 (void **slot, void *data)
+ {
+   htab_t htab = (htab_t) data;
+   variable var1, var2;
+ 
+   var1 = *(variable *) slot;
+   var2 = (variable) htab_find_with_hash (htab, var1->decl,
+ 					 VARIABLE_HASH_VAL (var1->decl));
+   if (!var2)
+     {
+       dataflow_set_different_value = true;
+ 
+       /* Stop traversing the hash table.   */
+       return 0;
+     }
+ 
+ #ifdef ENABLE_CHECKING
+   /* If both variables are defined they have been already checked for
+      equivalence.  */
+   if (variable_different_p (var1, var2))
+     abort ();
+ #endif
+ 
+   /* Continue traversing the hash table.  */
+   return 1;
+ }
+ 
+ /* Return true if dataflow sets OLD_SET and NEW_SET differ.  */
+ 
+ static bool
+ dataflow_set_different (dataflow_set *old_set, dataflow_set *new_set)
+ {
+   dataflow_set_different_value = false;
+ 
+   htab_traverse (old_set->vars, dataflow_set_different_1, new_set->vars);
+   if (!dataflow_set_different_value)
+     {
+       /* We have compared the variables which are in both hash tables
+ 	 so now only check whether there are some variables in NEW_SET->VARS
+ 	 which are not in OLD_SET->VARS.  */
+       htab_traverse (new_set->vars, dataflow_set_different_2, old_set->vars);
+     }
+   return dataflow_set_different_value;
+ }
+ 
+ /* Free the contents of dataflow set SET.  */
+ 
+ static void
+ dataflow_set_destroy (dataflow_set *set)
+ {
+   int i;
+ 
+   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+     attrs_list_clear (&set->regs[i]);
+ 
+   htab_delete (set->vars);
+   set->vars = NULL;
+ }
+ 
+ /* Shall EXPR be tracked?  */
+ 
+ static bool
+ track_expr_p (tree expr)
+ {
+   rtx decl_rtl;
+ 
+   /* If EXPR is not a parameter or a variable do not track it.  */
+   if (TREE_CODE (expr) != VAR_DECL && TREE_CODE (expr) != PARM_DECL)
+     return 0;
+ 
+   /* It also must have a name...  */
+   if (!DECL_NAME (expr))
+     return 0;
+ 
+   /* ... and a RTL assigned to it.  */
+   decl_rtl = DECL_RTL_IF_SET (expr);
+   if (!decl_rtl)
+     return 0;
+ 
+   /* Do not track global variables until we are able to emit correct location
+      list for them.  */
+   if (TREE_STATIC (expr))
+     return 0;
+ 
+   /* If RTX is a memory it should not be very large (because it would be
+      an array or struct).  */
+   if (GET_CODE (decl_rtl) == MEM)
+     {
+       /* Do not track structures and arrays.  */
+       if (GET_MODE (decl_rtl) == BLKmode)
+ 	return 0;
+       if (MEM_SIZE (decl_rtl)
+ 	  && INTVAL (MEM_SIZE (decl_rtl)) > MAX_VAR_PARTS)
+ 	return 0;
+     }
+ 
+   return 1;
+ }
+ 
+ /* Count uses (register and memory references) LOC which will be tracked.
+    INSN is instruction which the LOC is part of.  */
+ 
+ static void
+ count_uses (rtx loc, void *insn)
+ {
+   basic_block bb = BLOCK_FOR_INSN ((rtx) insn);
+ 
+   if (GET_CODE (loc) == REG)
+     {
+ #ifdef ENABLE_CHECKING
+       if (REGNO (loc) >= FIRST_PSEUDO_REGISTER)
+ 	abort ();
+ #endif
+       VTI (bb)->n_mos++;
+     }
+   else if (GET_CODE (loc) == MEM
+ 	   && MEM_EXPR (loc)
+ 	   && track_expr_p (MEM_EXPR (loc)))
+     {
+       VTI (bb)->n_mos++;
+     }
+ }
+ 
+ /* Count stores (register and memory references) LOC which will be tracked.
+    INSN is instruction which the LOC is part of.  */
+ 
+ static void
+ count_stores (rtx loc, rtx expr ATTRIBUTE_UNUSED, void *insn)
+ {
+   count_uses (loc, insn);
+ }
+ 
+ /* Add uses (register and memory references) LOC which will be tracked
+    to VTI (bb)->mos.  INSN is instruction which the LOC is part of.  */
+ 
+ static void
+ add_uses (rtx loc, void *insn)
+ {
+   if (GET_CODE (loc) == REG
+       || (GET_CODE (loc) == MEM
+ 	  && MEM_EXPR (loc)
+ 	  && track_expr_p (MEM_EXPR (loc))))
+     {
+       basic_block bb = BLOCK_FOR_INSN ((rtx) insn);
+       micro_operation *mo = VTI (bb)->mos + VTI (bb)->n_mos++;
+ 
+       mo->type = MO_USE;
+       mo->u.loc = loc;
+       mo->insn = (rtx) insn;
+     }
+ }
+ 
+ /* Add stores (register and memory references) LOC which will be tracked
+    to VTI (bb)->mos. EXPR is the RTL expression containing the store.
+    INSN is instruction which the LOC is part of.  */
+ 
+ static void
+ add_stores (rtx loc, rtx expr, void *insn)
+ {
+   if (GET_CODE (loc) == REG
+       || (GET_CODE (loc) == MEM
+ 	  && MEM_EXPR (loc)
+ 	  && track_expr_p (MEM_EXPR (loc))))
+     {
+       basic_block bb = BLOCK_FOR_INSN ((rtx) insn);
+       micro_operation *mo = VTI (bb)->mos + VTI (bb)->n_mos++;
+ 
+       mo->type = GET_CODE (expr) == CLOBBER ? MO_CLOBBER : MO_SET;
+       mo->u.loc = loc;
+       mo->insn = (rtx) insn;
+     }
+ }
+ 
+ /* Compute the changes of variable locations in the basic block BB.  */
+ 
+ static bool
+ compute_bb_dataflow (basic_block bb)
+ {
+   int i, n, r;
+   bool changed;
+   dataflow_set old_out;
+   dataflow_set *in = &VTI (bb)->in;
+   dataflow_set *out = &VTI (bb)->out;
+ 
+   dataflow_set_init (&old_out, htab_elements (VTI (bb)->out.vars) + 3);
+   dataflow_set_copy (&old_out, out);
+   dataflow_set_copy (out, in);
+ 
+   n = VTI (bb)->n_mos;
+   for (i = 0; i < n; i++)
+     {
+       switch (VTI (bb)->mos[i].type)
+ 	{
+ 	  case MO_CALL:
+ 	    for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
+ 	      if (TEST_HARD_REG_BIT (call_used_reg_set, r))
+ 		var_regno_delete (out, r);
+ 	    break;
+ 
+ 	  case MO_USE:
+ 	  case MO_SET:
+ 	  case MO_CLOBBER:
+ 	    {
+ 	      rtx loc = VTI (bb)->mos[i].u.loc;
+ 
+ 	      if (GET_CODE (loc) == REG)
+ 		{
+ 		  if (VTI (bb)->mos[i].type != MO_CLOBBER
+ 		      && REG_EXPR (loc) && track_expr_p (REG_EXPR (loc)))
+ 		    var_reg_delete_and_set (out, loc);
+ 		  else
+ 		    var_reg_delete (out, loc);
+ 		}
+ 	      else if (GET_CODE (loc) == MEM
+ 		       && MEM_EXPR (loc)
+ 		       && track_expr_p (MEM_EXPR (loc)))
+ 		{
+ 		  if (VTI (bb)->mos[i].type != MO_CLOBBER)
+ 		    var_mem_delete_and_set (out, loc);
+ 		  else
+ 		    var_mem_delete (out, loc);
+ 		}
+ 	    }
+ 	    break;
+ 
+ 	  case MO_ADJUST:
+ 	    {
+ 	      rtx base;
+ 
+ 	      out->stack_adjust += VTI (bb)->mos[i].u.adjust;
+ 	      base = gen_rtx_MEM (Pmode,
+ 				  gen_rtx_PLUS (Pmode, stack_pointer_rtx,
+ 						GEN_INT (out->stack_adjust)));
+ 	      set_variable_part (out, base, frame_base_decl, 0);
+ 	    }
+ 	    break;
+ 	}
+     }
+ 
+   changed = dataflow_set_different (&old_out, out);
+   dataflow_set_destroy (&old_out);
+   return changed;
+ }
+ 
+ /* Hybrid search.  It is the same as hybrid_search_bitmap in df.c but modified
+    for different data structures.
+    Search from basic block BB and use the bitmaps VISITED and PENDING
+    to control the searching.  */
+ 
+ static void
+ vt_hybrid_search (basic_block bb, sbitmap visited, sbitmap pending)
+ {
+   bool changed;
+   edge e;
+ 
+   SET_BIT (visited, bb->index);
+   if (TEST_BIT (pending, bb->index))
+     {
+       /* Calculate the IN set as union of predecessor OUT sets.  */
+       dataflow_set_clear (&VTI (bb)->in);
+       for (e = bb->pred; e; e = e->pred_next)
+ 	{
+ 	  dataflow_set_union (&VTI (bb)->in, &VTI (e->src)->out);
+ 	}
+ 
+       RESET_BIT (pending, bb->index);
+       changed = compute_bb_dataflow (bb);
+ 
+       if (changed)
+ 	{
+ 	  for (e = bb->succ; e; e = e->succ_next)
+ 	    {
+ 	      if (e->dest == EXIT_BLOCK_PTR || e->dest->index == bb->index)
+ 		continue;
+ 	      SET_BIT (pending, e->dest->index);
+ 	    }
+ 	}
+     }
+   for (e = bb->succ; e != 0; e = e->succ_next)
+     {
+       if (e->dest == EXIT_BLOCK_PTR || e->dest->index == bb->index)
+ 	continue;
+       if (!TEST_BIT (visited, e->dest->index))
+ 	vt_hybrid_search (e->dest, visited, pending);
+     }
+ }
+ 
+ /* This function will perform iterative dataflow, producing the in and out
+    sets.  It is the same as iterative_dataflow_bitmap in df.c but modified
+    for different data structures.
+    BB_ORDER is the order to iterate in (should map block numbers -> order).
+    Because this is a forward dataflow problem we pass in a mapping of block
+    number to rc_order (like df->inverse_rc_map).  */
+ 
+ static void
+ vt_iterative_dataflow (int *bb_order)
+ {
+   fibheap_t worklist;
+   basic_block bb;
+   sbitmap visited, pending;
+ 
+   pending = sbitmap_alloc (last_basic_block);
+   visited = sbitmap_alloc (last_basic_block);
+   sbitmap_zero (pending);
+   sbitmap_zero (visited);
+   worklist = fibheap_new ();
+ 
+   FOR_EACH_BB (bb)
+     {
+       fibheap_insert (worklist, bb_order[bb->index], bb);
+       SET_BIT (pending, bb->index);
+     }
+   while (sbitmap_first_set_bit (pending) != -1)
+     {
+       while (!fibheap_empty (worklist))
+ 	{
+ 	  bb = fibheap_extract_min (worklist);
+ 	  if (!TEST_BIT (visited, bb->index))
+ 	    vt_hybrid_search (bb, visited, pending);
+ 	}
+       if (sbitmap_first_set_bit (pending) != -1)
+ 	{
+ 	  FOR_EACH_BB (bb)
+ 	    {
+ 	      fibheap_insert (worklist, bb_order[bb->index], bb);
+ 	    }
+ 	  sbitmap_zero (visited);
+ 	}
+       else
+ 	{
+ 	  break;
+ 	}
+     }
+   sbitmap_free (pending);
+   sbitmap_free (visited);
+   fibheap_delete (worklist);
+ }
+ 
+ /* Print the content of the LIST to dump file.  */
+ 
+ static void
+ dump_attrs_list (attrs list)
+ {
+   for (; list; list = list->next)
+     {
+       print_mem_expr (rtl_dump_file, list->decl);
+       fprintf (rtl_dump_file, "+");
+       fprintf (rtl_dump_file, HOST_WIDE_INT_PRINT_DEC, list->offset);
+     }
+   fprintf (rtl_dump_file, "\n");
+ }
+ 
+ /* Print the information about variable *SLOT to dump file.  */
+ 
+ static int
+ dump_variable (void **slot, void *data ATTRIBUTE_UNUSED)
+ {
+   variable var = *(variable *) slot;
+   int i;
+   location_chain node;
+ 
+   fprintf (rtl_dump_file, "  name: %s\n",
+ 	   IDENTIFIER_POINTER (DECL_NAME (var->decl)));
+   for (i = 0; i < var->n_var_parts; i++)
+     {
+       fprintf (rtl_dump_file, "    offset %ld\n",
+ 	       (long) var->var_part[i].offset);
+       for (node = var->var_part[i].loc_chain; node; node = node->next)
+ 	{
+ 	  fprintf (rtl_dump_file, "      ");
+ 	  print_rtl_single (rtl_dump_file, node->loc);
+ 	}
+     }
+ 
+   /* Continue traversing the hash table.  */
+   return 1;
+ }
+ 
+ /* Print the information about variables from hash table VARS to dump file.  */
+ static void
+ dump_vars (htab_t vars)
+ {
+   if (htab_elements (vars) > 0)
+     {
+       fprintf (rtl_dump_file, "Variables:\n");
+       htab_traverse (vars, dump_variable, NULL);
+     }
+ }
+ 
+ /* Print the dataflow set SET to dump file.  */
+ 
+ static void
+ dump_dataflow_set (dataflow_set *set)
+ {
+   int i;
+ 
+   fprintf (rtl_dump_file, "Stack adjustment: ");
+   fprintf (rtl_dump_file, HOST_WIDE_INT_PRINT_DEC, set->stack_adjust);
+   fprintf (rtl_dump_file, "\n");
+   for (i = 1; i < FIRST_PSEUDO_REGISTER; i++)
+     {
+       if (set->regs[i])
+ 	{
+ 	  fprintf (rtl_dump_file, "Reg %d:", i);
+ 	  dump_attrs_list (set->regs[i]);
+ 	}
+     }
+   dump_vars (set->vars);
+   fprintf (rtl_dump_file, "\n");
+ }
+ 
+ /* Print the IN and OUT sets for each basic block to dump file.  */
+ 
+ static void
+ dump_dataflow_sets (void)
+ {
+   basic_block bb;
+ 
+   FOR_EACH_BB (bb)
+     {
+       fprintf (rtl_dump_file, "\nBasic block %d:\n", bb->index);
+       fprintf (rtl_dump_file, "IN:\n");
+       dump_dataflow_set (&VTI (bb)->in);
+       fprintf (rtl_dump_file, "OUT:\n");
+       dump_dataflow_set (&VTI (bb)->out);
+     }
+ }
+ 
+ /* Add variable VAR to the hash table of changed variables and
+    if it has no locations delete it from hash table HTAB.  */
+ 
+ static void
+ variable_was_changed (variable var, htab_t htab)
+ {
+   hashval_t hash = VARIABLE_HASH_VAL (var->decl);
+ 
+   if (emit_notes)
+     {
+       variable *slot;
+ 
+       slot = (variable *) htab_find_slot_with_hash (changed_variables,
+ 						    var->decl, hash, INSERT);
+ 
+       if (htab && var->n_var_parts == 0)
+ 	{
+ 	  variable empty_var;
+ 	  void **old;
+ 
+ 	  empty_var = pool_alloc (var_pool);
+ 	  empty_var->decl = var->decl;
+ 	  empty_var->n_var_parts = 0;
+ 	  *slot = empty_var;
+ 
+ 	  old = htab_find_slot_with_hash (htab, var->decl, hash,
+ 					  NO_INSERT);
+ 	  if (old)
+ 	    htab_clear_slot (htab, old);
+ 	}
+       else
+ 	{
+ 	  *slot = var;
+ 	}
+     }
+   else
+     {
+ #ifdef ENABLE_CHECKING
+       if (!htab)
+ 	abort ();
+ #endif
+       if (var->n_var_parts == 0)
+ 	{
+ 	  void **slot = htab_find_slot_with_hash (htab, var->decl, hash,
+ 						  NO_INSERT);
+ 	  if (slot)
+ 	    htab_clear_slot (htab, slot);
+ 	}
+     }
+ }
+ 
+ /* Set the part of variable's location in the dataflow set SET.  The variable
+    part is specified by variable's declaration DECL and offset OFFSET and the
+    part's location by LOC.  */
+ 
+ static void
+ set_variable_part (dataflow_set *set, rtx loc, tree decl, HOST_WIDE_INT offset)
+ {
+   int pos, low, high;
+   location_chain node, prev, next;
+   bool changed;
+   variable var;
+   void **slot;
+   
+   slot = htab_find_slot_with_hash (set->vars, decl,
+ 				   VARIABLE_HASH_VAL (decl), INSERT);
+   if (!*slot)
+     {
+       /* Create new variable information.  */
+       var = pool_alloc (var_pool);
+       var->decl = decl;
+       var->n_var_parts = 1;
+       var->var_part[0].offset = offset;
+       var->var_part[0].loc_chain = NULL;
+       *slot = var;
+       pos = 0;
+     }
+   else
+     {
+       var = (variable) *slot;
+ 
+       /* Find the location part.  */
+       low = 0;
+       high = var->n_var_parts;
+       while (low != high)
+ 	{
+ 	  pos = (low + high) / 2;
+ 	  if (var->var_part[pos].offset < offset)
+ 	    low = pos + 1;
+ 	  else
+ 	    high = pos;
+ 	}
+       pos = low;
+ 
+       if (pos == var->n_var_parts || var->var_part[pos].offset != offset)
+ 	{
+ 	  /* We have not find the location part, new one will be created.  */
+ 
+ #ifdef ENABLE_CHECKING
+ 	  /* We track only variables whose size is <= MAX_VAR_PARTS bytes
+ 	     thus there are at most MAX_VAR_PARTS different offsets.  */
+ 	  if (var->n_var_parts >= MAX_VAR_PARTS)
+ 	    abort ();
+ #endif
+ 
+ 	  /* We have to move the elements of array starting at index low to the
+ 	     next position.  */
+ 	  for (high = var->n_var_parts; high > low; high--)
+ 	    var->var_part[high] = var->var_part[high - 1];
+ 
+ 	  var->n_var_parts++;
+ 	  var->var_part[pos].offset = offset;
+ 	  var->var_part[pos].loc_chain = NULL;
+ 	}
+     }
+ 
+   changed = true;
+   /* Delete the location from list.  */
+   prev = NULL;
+   for (node = var->var_part[pos].loc_chain; node; node = next)
+     {
+       next = node->next;
+       if ((GET_CODE (node->loc) == REG && GET_CODE (loc) == REG
+ 	   && REGNO (node->loc) == REGNO (loc))
+ 	  || rtx_equal_p (node->loc, loc))
+ 	{
+ 	  if (prev)
+ 	    prev->next = next;
+ 	  else
+ 	    {
+ 	      var->var_part[pos].loc_chain = next;
+ 	      changed = false;
+ 	    }
+ 	  pool_free (loc_chain_pool, node);
+ 	  break;
+ 	}
+       else
+ 	prev = node;
+     }
+ 
+   if (changed)
+     variable_was_changed (var, set->vars);
+ 
+   /* Add the location to the beginning.  */
+   node = pool_alloc (loc_chain_pool);
+   node->loc = loc;
+   node->next = var->var_part[pos].loc_chain;
+   var->var_part[pos].loc_chain = node;
+ }
+ 
+ /* Delete the part of variable's location from dataflow set SET.  The variable
+    part is specified by variable's declaration DECL and offset OFFSET and the
+    part's location by LOC.  */
+ 
+ static void
+ delete_variable_part (dataflow_set *set, rtx loc, tree decl,
+ 		      HOST_WIDE_INT offset)
+ {
+   int pos, low, high;
+   void **slot;
+     
+   slot = htab_find_slot_with_hash (set->vars, decl, VARIABLE_HASH_VAL (decl),
+ 				   NO_INSERT);
+   if (slot)
+     {
+       variable var = (variable) *slot;
+ 
+       /* Find the location part.  */
+       low = 0;
+       high = var->n_var_parts;
+       while (low != high)
+ 	{
+ 	  pos = (low + high) / 2;
+ 	  if (var->var_part[pos].offset < offset)
+ 	    low = pos + 1;
+ 	  else
+ 	    high = pos;
+ 	}
+       pos = low;
+ 
+       if (pos < var->n_var_parts && var->var_part[pos].offset == offset)
+ 	{
+ 	  location_chain node, prev, next;
+ 	  bool changed;
+ 
+ 	  /* Delete the location part.  */
+ 	  changed = false;
+ 	  prev = NULL;
+ 	  for (node = var->var_part[pos].loc_chain; node; node = next)
+ 	    {
+ 	      next = node->next;
+ 	      if ((GET_CODE (node->loc) == REG && GET_CODE (loc) == REG
+ 		   && REGNO (node->loc) == REGNO (loc))
+ 		  || rtx_equal_p (node->loc, loc))
+ 		{
+ 		  if (prev)
+ 		    prev->next = next;
+ 		  else
+ 		    {
+ 		      var->var_part[pos].loc_chain = next;
+ 		      changed = true;
+ 		    }
+ 		  pool_free (loc_chain_pool, node);
+ 		  break;
+ 		}
+ 	      else
+ 		prev = node;
+ 	    }
+ 	    if (var->var_part[pos].loc_chain == NULL)
+ 	      {
+ 		var->n_var_parts--;
+ 		while (pos < var->n_var_parts)
+ 		  {
+ 		    var->var_part[pos] = var->var_part[pos + 1];
+ 		    pos++;
+ 		  }
+ 	      }
+ 	    if (changed)
+ 	      variable_was_changed (var, set->vars);
+ 	}
+     }
+ }
+ 
+ /* Emit the NOTE_INSN_VAR_LOCATION for variable *VARP.  DATA contains additional
+    parameters: WHERE specifies whether the note shall be emitted before of after
+    instruction INSN.  */
+ 
+ static int
+ emit_note_insn_var_location (void **varp, void *data)
+ {
+   variable var = *(variable *) varp;
+   rtx insn = ((emit_note_data *)data)->insn;
+   enum emit_note_where where = ((emit_note_data *)data)->where;
+   rtx note;
+   int i;
+   bool complete;
+   HOST_WIDE_INT last_limit;
+   tree type_size_unit;
+ 
+ #ifdef ENABLE_CHECKING
+   if (!var->decl)
+     abort ();
+ #endif
+ 
+   complete = true;
+   last_limit = 0;
+   for (i = 0; i < var->n_var_parts; i++)
+     {
+       if (last_limit < var->var_part[i].offset)
+ 	{
+ 	  complete = false;
+ 	  break;
+ 	}
+       last_limit
+ 	= (var->var_part[i].offset
+ 	   + GET_MODE_SIZE (GET_MODE (var->var_part[i].loc_chain->loc)));
+     }
+   type_size_unit = TYPE_SIZE_UNIT (TREE_TYPE (var->decl));
+   if ((unsigned HOST_WIDE_INT) last_limit < TREE_INT_CST_LOW (type_size_unit))
+     complete = false;
+ 
+   if (where == EMIT_NOTE_AFTER_INSN)
+     note = emit_note_after (NOTE_INSN_VAR_LOCATION, insn);
+   else
+     note = emit_note_before (NOTE_INSN_VAR_LOCATION, insn);
+ 
+   if (!complete)
+     {
+       NOTE_VAR_LOCATION (note) = gen_rtx_VAR_LOCATION (VOIDmode, var->decl,
+ 						       NULL_RTX);
+     }
+   else if (var->n_var_parts == 1)
+     {
+       rtx expr_list
+ 	= gen_rtx_EXPR_LIST (VOIDmode,
+ 			     var->var_part[0].loc_chain->loc,
+ 			     GEN_INT (var->var_part[0].offset));
+ 
+       NOTE_VAR_LOCATION (note) = gen_rtx_VAR_LOCATION (VOIDmode, var->decl,
+ 						       expr_list);
+     }
+   else if (var->n_var_parts)
+     {
+       rtx argp[MAX_VAR_PARTS];
+       rtx parallel;
+ 
+       for (i = 0; i < var->n_var_parts; i++)
+ 	argp[i] = gen_rtx_EXPR_LIST (VOIDmode, var->var_part[i].loc_chain->loc,
+ 				     GEN_INT (var->var_part[i].offset));
+       parallel = gen_rtx_PARALLEL (VOIDmode,
+ 				   gen_rtvec_v (var->n_var_parts, argp));
+       NOTE_VAR_LOCATION (note) = gen_rtx_VAR_LOCATION (VOIDmode, var->decl,
+ 						       parallel);
+     }
+ 
+   htab_clear_slot (changed_variables, varp);
+ 
+   /* When there are no location parts the variable has been already
+      removed from hash table and a new empty variable was created.
+      Free the empty variable.  */
+   if (var->n_var_parts == 0)
+     {
+       pool_free (var_pool, var);
+     }
+ 
+   /* Continue traversing the hash table.  */
+   return 1;
+ }
+ 
+ /* Emit NOTE_INSN_VAR_LOCATION note for each variable from a chain
+    CHANGED_VARIABLES and delete this chain.  WHERE specifies whether the notes
+    shall be emitted before of after instruction INSN.  */
+ 
+ static void
+ emit_notes_for_changes (rtx insn, enum emit_note_where where)
+ {
+   emit_note_data data;
+ 
+   data.insn = insn;
+   data.where = where;
+   htab_traverse (changed_variables, emit_note_insn_var_location, &data);
+ }
+ 
+ /* Add variable *SLOT to the chain CHANGED_VARIABLES if it differs from the
+    same variable in hash table DATA or is not there at all.  */
+ 
+ static int
+ emit_notes_for_differences_1 (void **slot, void *data)
+ {
+   htab_t new_vars = (htab_t) data;
+   variable old_var, new_var;
+ 
+   old_var = *(variable *) slot;
+   new_var = (variable) htab_find_with_hash (new_vars, old_var->decl,
+ 					    VARIABLE_HASH_VAL (old_var->decl));
+ 
+   if (!new_var)
+     {
+       /* Variable has disappeared.  */
+       variable empty_var;
+ 
+       empty_var = pool_alloc (var_pool);
+       empty_var->decl = old_var->decl;
+       empty_var->n_var_parts = 0;
+       variable_was_changed (empty_var, NULL);
+     }
+   else if (variable_different_p (old_var, new_var))
+     {
+       variable_was_changed (new_var, NULL);
+     }
+ 
+   /* Continue traversing the hash table.  */
+   return 1;
+ }
+ 
+ /* Add variable *SLOT to the chain CHANGED_VARIABLES if it is not in hash
+    table DATA.  */
+ 
+ static int
+ emit_notes_for_differences_2 (void **slot, void *data)
+ {
+   htab_t old_vars = (htab_t) data;
+   variable old_var, new_var;
+ 
+   new_var = *(variable *) slot;
+   old_var = (variable) htab_find_with_hash (old_vars, new_var->decl,
+ 					    VARIABLE_HASH_VAL (new_var->decl));
+   if (!old_var)
+     {
+       /* Variable has appeared.  */
+       variable_was_changed (new_var, NULL);
+     }
+ 
+   /* Continue traversing the hash table.  */
+   return 1;
+ }
+ 
+ /* Emit notes before INSN for differences between dataflow sets OLD_SET and
+    NEW_SET.  */
+ 
+ static void
+ emit_notes_for_differences (rtx insn, dataflow_set *old_set,
+ 			    dataflow_set *new_set)
+ {
+   htab_traverse (old_set->vars, emit_notes_for_differences_1, new_set->vars);
+   htab_traverse (new_set->vars, emit_notes_for_differences_2, old_set->vars);
+   emit_notes_for_changes (insn, EMIT_NOTE_BEFORE_INSN);
+ }
+ 
+ /* Emit the notes for changes of location parts in the basic block BB.  */
+ 
+ static void
+ emit_notes_in_bb (basic_block bb)
+ {
+   int i;
+   dataflow_set set;
+ 
+   dataflow_set_init (&set, htab_elements (VTI (bb)->in.vars) + 3);
+   dataflow_set_copy (&set, &VTI (bb)->in);
+ 
+   for (i = 0; i < VTI (bb)->n_mos; i++)
+     {
+       rtx insn = VTI (bb)->mos[i].insn;
+ 
+       switch (VTI (bb)->mos[i].type)
+ 	{
+ 	  case MO_CALL:
+ 	    {
+ 	      int r;
+ 
+ 	      for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
+ 		if (TEST_HARD_REG_BIT (call_used_reg_set, r))
+ 		  {
+ 		    var_regno_delete (&set, r);
+ 		  }
+ 	      emit_notes_for_changes (insn, EMIT_NOTE_AFTER_INSN);
+ 	    }
+ 	    break;
+ 
+ 	  case MO_USE:
+ 	  case MO_SET:
+ 	  case MO_CLOBBER:
+ 	    {
+ 	      rtx loc = VTI (bb)->mos[i].u.loc;
+ 
+ 	      if (GET_CODE (loc) == REG)
+ 		{
+ 		  if (VTI (bb)->mos[i].type != MO_CLOBBER
+ 		      && REG_EXPR (loc) && track_expr_p (REG_EXPR (loc)))
+ 		    var_reg_delete_and_set (&set, loc);
+ 		  else
+ 		    var_reg_delete (&set, loc);
+ 		}
+ 	      else if (GET_CODE (loc) == MEM
+ 		       && MEM_EXPR (loc)
+ 		       && track_expr_p (MEM_EXPR (loc)))
+ 		{
+ 		  if (VTI (bb)->mos[i].type != MO_CLOBBER)
+ 		    var_mem_delete_and_set (&set, loc);
+ 		  else
+ 		    var_mem_delete (&set, loc);
+ 		}
+ 
+ 	      if (VTI (bb)->mos[i].type == MO_USE)
+ 		emit_notes_for_changes (insn, EMIT_NOTE_BEFORE_INSN);
+ 	      else
+ 		emit_notes_for_changes (insn, EMIT_NOTE_AFTER_INSN);
+ 	    }
+ 	    break;
+ 
+ 	  case MO_ADJUST:
+ 	    {
+ 	      rtx base;
+ 
+ 	      set.stack_adjust += VTI (bb)->mos[i].u.adjust;
+ 	      base = gen_rtx_MEM (Pmode,
+ 				  gen_rtx_PLUS (Pmode, stack_pointer_rtx,
+ 						GEN_INT (set.stack_adjust)));
+ 	      set_variable_part (&set, base, frame_base_decl, 0);
+ 	      emit_notes_for_changes (insn, EMIT_NOTE_AFTER_INSN);
+ 	    }
+ 	    break;
+ 	}
+     }
+   dataflow_set_destroy (&set);
+ }
+ 
+ /* Emit notes for the whole function.  */
+ 
+ static void
+ vt_emit_notes (void)
+ {
+   basic_block bb;
+   dataflow_set *last_out;
+   dataflow_set empty;
+ 
+ #ifdef ENABLE_CHECKING
+   if (htab_elements (changed_variables))
+     abort ();
+ #endif
+ 
+   /* Enable emitting notes by functions (mainly by set_variable_part and
+      delete_variable_part).  */
+   emit_notes = true;
+ 
+   dataflow_set_init (&empty, 7);
+   last_out = &empty;
+ 
+   FOR_EACH_BB (bb)
+     {
+       /* Emit the notes for changes of variable locations between two
+ 	 subsequent basic blocks.  */
+       emit_notes_for_differences (bb->head, last_out, &VTI (bb)->in);
+ 
+       /* Emit the notes for the changes in the basic block itself.  */
+       emit_notes_in_bb (bb);
+ 
+       last_out = &VTI (bb)->out;
+     }
+   dataflow_set_destroy (&empty);
+   emit_notes = false;
+ }
+ 
+ /* If there is a declaration and offset associated with register/memory RTL
+    assign declaration to *DECLP and offset to *OFFSETP, and return true.  */
+ 
+ static bool
+ vt_get_decl_and_offset (rtx rtl, tree *declp, HOST_WIDE_INT *offsetp)
+ {
+   if (GET_CODE (rtl) == REG)
+     {
+       if (REG_ATTRS (rtl))
+ 	{
+ 	  *declp = REG_EXPR (rtl);
+ 	  *offsetp = REG_OFFSET (rtl);
+ 	  return true;
+ 	}
+     }
+   else if (GET_CODE (rtl) == MEM)
+     {
+       if (MEM_ATTRS (rtl))
+ 	{
+ 	  *declp = MEM_EXPR (rtl);
+ 	  *offsetp = MEM_OFFSET (rtl) ? INTVAL (MEM_OFFSET (rtl)) : 0;
+ 	  return true;
+ 	}
+     }
+   return false;
+ }
+ 
+ /* Insert function parameters to IN and OUT sets of ENTRY_BLOCK.  */
+ 
+ static void
+ vt_add_function_parameters (void)
+ {
+   tree parm;
+   HOST_WIDE_INT stack_adjust = 0;
+   
+   if (!frame_pointer_needed)
+     stack_adjust = prologue_stack_adjust ();
+ 
+   for (parm = DECL_ARGUMENTS (current_function_decl);
+        parm; parm = TREE_CHAIN (parm))
+     {
+       rtx decl_rtl = DECL_RTL_IF_SET (parm);
+       rtx incoming = DECL_INCOMING_RTL (parm);
+       tree decl;
+       HOST_WIDE_INT offset;
+       dataflow_set *in, *out;
+ 
+       if (TREE_CODE (parm) != PARM_DECL)
+ 	continue;
+ 
+       if (!DECL_NAME (parm))
+ 	continue;
+ 
+       if (!decl_rtl || !incoming)
+ 	continue;
+ 
+       if (GET_MODE (decl_rtl) == BLKmode || GET_MODE (incoming) == BLKmode)
+ 	continue;
+ 
+       if (!vt_get_decl_and_offset (incoming, &decl, &offset))
+ 	if (!vt_get_decl_and_offset (decl_rtl, &decl, &offset))
+ 	  continue;
+ 
+       if (!decl)
+ 	continue;
+ 
+       if (parm != decl)
+ 	abort ();
+ 
+       incoming = eliminate_regs (incoming, 0, NULL_RTX);
+       if (GET_CODE (incoming) == MEM)
+ 	incoming = adjust_stack_reference (incoming, -stack_adjust);
+       in = &VTI (ENTRY_BLOCK_PTR)->in;
+       out = &VTI (ENTRY_BLOCK_PTR)->out;
+ 
+       if (GET_CODE (incoming) == REG)
+ 	{
+ 	  if (REGNO (incoming) >= FIRST_PSEUDO_REGISTER)
+ 	    abort ();
+ 	  attrs_list_insert (&in->regs[REGNO (incoming)],
+ 			     parm, offset, incoming);
+ 	  attrs_list_insert (&out->regs[REGNO (incoming)],
+ 			     parm, offset, incoming);
+ 	  set_variable_part (in, incoming, parm, offset);
+ 	  set_variable_part (out, incoming, parm, offset);
+ 	}
+       else if (GET_CODE (incoming) == MEM)
+ 	{
+ 	  set_variable_part (in, incoming, parm, offset);
+ 	  set_variable_part (out, incoming, parm, offset);
+ 	}
+     }
+ }
+ 
+ /* Allocate and initialize the data structures for variable tracking
+    and parse the RTL to get the micro operations.  */
+ 
+ static void
+ vt_initialize (void)
+ {
+   basic_block bb;
+ 
+   alloc_aux_for_blocks (sizeof (struct variable_tracking_info_def));
+ 
+   FOR_EACH_BB (bb)
+     {
+       rtx insn;
+       HOST_WIDE_INT pre, post;
+ 
+       /* Count the number of micro operations.  */
+       VTI (bb)->n_mos = 0;
+       for (insn = bb->head; insn != NEXT_INSN (bb->end);
+ 	   insn = NEXT_INSN (insn))
+ 	{
+ 	  if (INSN_P (insn))
+ 	    {
+ 	      if (!frame_pointer_needed)
+ 		{
+ 		  insn_stack_adjust_offset_pre_post (insn, &pre, &post);
+ 		  if (pre)
+ 		    VTI (bb)->n_mos++;
+ 		  if (post)
+ 		    VTI (bb)->n_mos++;
+ 		}
+ 	      note_all_uses (PATTERN (insn), count_uses, insn);
+ 	      note_stores (PATTERN (insn), count_stores, insn);
+ 	      if (GET_CODE (insn) == CALL_INSN)
+ 		VTI (bb)->n_mos++;
+ 	    }
+ 	}
+ 
+       /* Add the nicro-operations to the array.  */
+       VTI (bb)->mos = xmalloc (VTI (bb)->n_mos
+ 			       * sizeof (struct micro_operation_def));
+       VTI (bb)->n_mos = 0;
+       for (insn = bb->head; insn != NEXT_INSN (bb->end);
+ 	   insn = NEXT_INSN (insn))
+ 	{
+ 	  if (INSN_P (insn))
+ 	    {
+ 	      int n1, n2;
+ 
+ 	      if (!frame_pointer_needed)
+ 		{
+ 		  insn_stack_adjust_offset_pre_post (insn, &pre, &post);
+ 		  if (pre)
+ 		    {
+ 		      micro_operation *mo = VTI (bb)->mos + VTI (bb)->n_mos++;
+ 
+ 		      mo->type = MO_ADJUST;
+ 		      mo->u.adjust = pre;
+ 		      mo->insn = insn;
+ 		    }
+ 		}
+ 
+ 	      note_all_uses (PATTERN (insn), add_uses, insn);
+ 
+ 	      if (GET_CODE (insn) == CALL_INSN)
+ 		{
+ 		  micro_operation *mo = VTI (bb)->mos + VTI (bb)->n_mos++;
+ 
+ 		  mo->type = MO_CALL;
+ 		  mo->insn = insn;
+ 		}
+ 
+ 	      n1 = VTI (bb)->n_mos;
+ 	      note_stores (PATTERN (insn), add_stores, insn);
+ 	      n2 = VTI (bb)->n_mos - 1;
+ 
+ 	      /* Order the MO_SETs to be before MO_CLOBBERs.  */
+ 	      n2 = VTI (bb)->n_mos - 1;
+ 	      while (n1 < n2)
+ 		{
+ 		  while (n1 < n2 && VTI (bb)->mos[n1].type == MO_SET)
+ 		    n1++;
+ 		  while (n1 < n2 && VTI (bb)->mos[n2].type == MO_CLOBBER)
+ 		    n2--;
+ 		  if (n1 < n2)
+ 		    {
+ 		      micro_operation sw;
+ 
+ 		      sw = VTI (bb)->mos[n1];
+ 		      VTI (bb)->mos[n1] = VTI (bb)->mos[n2];
+ 		      VTI (bb)->mos[n2] = sw;
+ 		    }
+ 		}
+ 
+ 	      if (!frame_pointer_needed && post)
+ 		{
+ 		  micro_operation *mo = VTI (bb)->mos + VTI (bb)->n_mos++;
+ 
+ 		  mo->type = MO_ADJUST;
+ 		  mo->u.adjust = post;
+ 		  mo->insn = insn;
+ 		}
+ 	    }
+ 	}
+     }
+ 
+   /* Init the IN and OUT sets.  */
+   FOR_ALL_BB (bb)
+     {
+       VTI (bb)->visited = false;
+       dataflow_set_init (&VTI (bb)->in, 7);
+       dataflow_set_init (&VTI (bb)->out, 7);
+     }
+ 
+   attrs_pool = create_alloc_pool ("attrs_def pool",
+ 				  sizeof (struct attrs_def), 1024);
+   var_pool = create_alloc_pool ("variable_def pool",
+ 				sizeof (struct variable_def), 64);
+   loc_chain_pool = create_alloc_pool ("location_chain_def pool",
+ 				      sizeof (struct location_chain_def),
+ 				      1024);
+   changed_variables = htab_create (10, variable_htab_hash, variable_htab_eq,
+ 				   NULL);
+   vt_add_function_parameters ();
+ 
+   if (!frame_pointer_needed)
+     {
+       rtx base;
+ 
+       /* Create fake variable for tracking stack pointer changes.  */
+       frame_base_decl = make_node (VAR_DECL);
+       DECL_NAME (frame_base_decl) = get_identifier ("___frame_base_decl");
+       TREE_TYPE (frame_base_decl) = char_type_node;
+       DECL_ARTIFICIAL (frame_base_decl) = 1;
+ 
+       /* Set its initial "location".  */
+       base = gen_rtx_MEM (Pmode, stack_pointer_rtx);
+       set_variable_part (&VTI (ENTRY_BLOCK_PTR)->in, base, frame_base_decl, 0);
+       set_variable_part (&VTI (ENTRY_BLOCK_PTR)->out, base, frame_base_decl, 0);
+     }
+   else
+     {
+       frame_base_decl = NULL;
+     }
+ }
+ 
+ /* Free the data structures needed for variable tracking.  */
+ 
+ static void
+ vt_finalize (void)
+ {
+   basic_block bb;
+ 
+   FOR_EACH_BB (bb)
+     {
+       free (VTI (bb)->mos);
+     }
+ 
+   FOR_ALL_BB (bb)
+     {
+       dataflow_set_destroy (&VTI (bb)->in);
+       dataflow_set_destroy (&VTI (bb)->out);
+     }
+   free_aux_for_blocks ();
+   free_alloc_pool (attrs_pool);
+   free_alloc_pool (var_pool);
+   free_alloc_pool (loc_chain_pool);
+   htab_delete (changed_variables);
+ }
+ 
+ /* The entry point to variable tracking pass.  */
+ 
+ void
+ variable_tracking_main (void)
+ {
+   int i;
+   int *rc_order;
+   int *bb_order;
+ 
+   mark_dfs_back_edges ();
+   vt_initialize ();
+   if (!frame_pointer_needed)
+     {
+       if (!vt_stack_adjustments ())
+ 	{
+ 	  vt_finalize ();
+ 	  return;
+ 	}
+     }
+ 
+   /* Compute reverse completion order of depth first search of the CFG
+      so that the dataflow could possibly run faster.  */
+   rc_order = (int *) xmalloc (n_basic_blocks * sizeof (int));
+   bb_order = (int *) xmalloc (last_basic_block * sizeof (int));
+   flow_depth_first_order_compute (NULL, rc_order);
+   for (i = 0; i < n_basic_blocks; i++)
+     bb_order[rc_order[i]] = i;
+   free (rc_order);
+ 
+   vt_iterative_dataflow (bb_order);
+   vt_emit_notes ();
+ 
+   if (rtl_dump_file)
+     {
+       dump_dataflow_sets ();
+       dump_flow_info (rtl_dump_file);
+     }
+ 
+   free (bb_order);
+   vt_finalize ();
+ }
Index: vmsdbgout.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/vmsdbgout.c,v
retrieving revision 1.29
diff -c -3 -p -r1.29 vmsdbgout.c
*** vmsdbgout.c	19 Jul 2003 14:47:14 -0000	1.29
--- vmsdbgout.c	26 Sep 2003 18:12:19 -0000
*************** const struct gcc_debug_hooks vmsdbg_debu
*** 189,195 ****
     debug_nothing_tree,		/* deferred_inline_function */
     vmsdbgout_abstract_function,
     debug_nothing_rtx,		/* label */
!    debug_nothing_int		/* handle_pch */
  };
  
  /* Definitions of defaults for assembler-dependent names of various
--- 189,196 ----
     debug_nothing_tree,		/* deferred_inline_function */
     vmsdbgout_abstract_function,
     debug_nothing_rtx,		/* label */
!    debug_nothing_int,		/* handle_pch */
!    debug_nothing_rtx		/* var_location */
  };
  
  /* Definitions of defaults for assembler-dependent names of various
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.343
diff -c -3 -p -r1.343 invoke.texi
*** doc/invoke.texi	7 Oct 2003 16:28:37 -0000	1.343
--- doc/invoke.texi	9 Oct 2003 05:38:12 -0000
*************** in the following sections.
*** 258,264 ****
  -p  -pg  -print-file-name=@var{library}  -print-libgcc-file-name @gol
  -print-multi-directory  -print-multi-lib @gol
  -print-prog-name=@var{program}  -print-search-dirs  -Q @gol
! -save-temps  -time}
  
  @item Optimization Options
  @xref{Optimize Options,,Options that Control Optimization}.
--- 258,264 ----
  -p  -pg  -print-file-name=@var{library}  -print-libgcc-file-name @gol
  -print-multi-directory  -print-multi-lib @gol
  -print-prog-name=@var{program}  -print-search-dirs  -Q @gol
! -save-temps  -time -fvar-tracking}
  
  @item Optimization Options
  @xref{Optimize Options,,Options that Control Optimization}.
*************** Also turns on @option{-dp} annotation.
*** 3404,3409 ****
--- 3404,3412 ----
  For each of the other indicated dump files (except for
  @file{@var{file}.01.rtl}), dump a representation of the control flow graph
  suitable for viewing with VCG to @file{@var{file}.@var{pass}.vcg}.
+ @item V
+ @opindex dV
+ Dump after variable tracking, to @file{@var{file}.35.vartrack}.
  @item x
  @opindex dx
  Just generate RTL for a function instead of compiling it.  Usually used
*************** The first number on each line is the ``u
*** 3524,3529 ****
--- 3527,3542 ----
  executing the program itself.  The second number is ``system time,''
  time spent executing operating system routines on behalf of the program.
  Both numbers are in seconds.
+ 
+ @item -fvar-tracking
+ @opindex fvar-tracking
+ Run variable tracking pass. It computes where variables are stored at each
+ position in code. Better debugging information is then generated
+ (if the debugging information format supports this information).
+ 
+ It is enabled by default when compiling with optimization (@option{-Os},
+ @option{-O}, @option{-O2}, ...), debugging information (@option{-g}) and
+ the debug info format supports it.
  
  @item -print-file-name=@var{library}
  @opindex print-file-name
Index: doc/passes.texi
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/doc/passes.texi,v
retrieving revision 1.27
diff -c -3 -p -r1.27 passes.texi
*** doc/passes.texi	25 Jul 2003 11:48:02 -0000	1.27
--- doc/passes.texi	26 Sep 2003 18:12:19 -0000
*************** The option @option{-dB} causes a debuggi
*** 546,551 ****
--- 546,563 ----
  this pass.  This dump file's name is made by appending @samp{.bbro} to
  the input file name.
  
+ @cindex variable tracking
+ @item
+ Variable tracking.  This pass computes where the variables are stored at each
+ position in code and generates notes describing the variable locations
+ to RTL code.  The debugging information is then generated according to these
+ notes if the debugging information format supports this information.
+ 
+ @opindex dV
+ The option @option{-dV} causes a debugging dump of the RTL code after
+ this pass.  This dump file's name is made by appending @samp{.vartrack}
+ to the input file name.
+ 
  @cindex delayed branch scheduling
  @cindex scheduling, delayed branch
  @item


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]