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]

[ira] inter-procedural RA bug fix and IRA code cleaning


This patch fixes inter-procedural RA regressions and cleans IRA code.

Vlad

2008-03-28 Vladimir Makarov <vmakarov@redhat.com>

	* ira-conflicts.c, global.c, regmove.c, function.c,
	ira-emit.c, alias.c, reload1.c: Add comments, fix comments.

	* reload.h: Add 2008 to the Copyright.
	
	* caller-save.c: Add comments.
	(reg_save_code, reg_restore_code, initiate_saved_hard_regs,
	new_saved_hard_reg, finish_saved_hard_regs,
	saved_hard_reg_compare_func, calculate_local_save_info,
	set_up_bb_rts_numbers, rpost_cmp, calculate_save_in_out,
	calculate_save_here, make_global_save_analysis,
	print_hard_reg_set_and_mode, print_hard_reg_set, print_save_data,
	set_hard_reg_saved, add_stored_regs): Add prototypes.
	
	* df-scan.c (df_get_call_refs): Use
	get_call_invalidated_used_regs.

	* ira-int.h: Add comments.
	(loop_tree_node): Rename inner to children.
	(ira_allocate_regset, ira_free_regset): Remove.
	(reassign_conflict_allocnos): Remove one parameter.

	* ira-color.c: Add comments.
	(setup_curr_costs): Rename to update_curr_costs.
	(allocno_cost_compare_func, print_coalesced_allocno,
	allocno_reload_assign): Add prototypes.
	(reassign_conflict_allocnos): Remove one parameter.

	* ira-lives.c: Add comments.
	(make_regno_dead, make_regno_born_and_dead,
	create_start_finish_chains, print_allocno_live_ranges,
	print_live_ranges): Add protoypes.

	* ira-build.c: Add comments.
	(copy_allocno_live_range_list): Make it static.

	* ira.c: Add comments.
	(setup_cover_classes): Rename to
	setup_cover_and_important_classes.
	(free_register_move_costs, chain_freq_compare, chain_bb_compare,
	ira): New prototypes.
	(mode_inner_mode, setup_inner_mode, ira_allocate_regset,
	ira_free_regset): Remove.

	* ira.h: Add comments.
	(SECONDARY_INPUT_RELOAD_CLASS,
	SECONDARY_OUTPUT_RELOAD_CLASS, HAVE_SECONDARY_RELOADS,
	MEMORY_MOVE_COST, reg_equiv_memory_loc_varray, reg_equiv_constant,
	reg_equiv_memory_loc, reg_equiv_address, reg_equiv_mem, ira):
	Remove.
	
	* ira-costs.c: Add comments.
	(find_allocno_class_costs): Make common class a cover class.
	

Index: ira-conflicts.c
===================================================================
--- ira-conflicts.c	(revision 133412)
+++ ira-conflicts.c	(working copy)
@@ -38,8 +38,9 @@ Software Foundation, 51 Franklin Street,
 #include "df.h"
 #include "ira-int.h"
 
-/* The file contains code is analogous to one in global but the code
-   works on the allocno basis.  */
+/* This file contains code responsible for allocno conflict creation,
+   allocno copy creation and allocno info accumulation on upper level
+   regions.  */
 
 static void build_conflict_bit_table (void);
 static void mirror_conflicts (void);
@@ -65,7 +66,10 @@ static void print_conflicts (FILE *, int
 /* allocnos_num array of allocnos_num array of bits, recording whether
    two allocno's conflict (can't go in the same hardware register).
 
-   `conflicts' is symmetric after the call to mirror_conflicts.  */
+   `conflicts' is symmetric after the call to mirror_conflicts.
+
+   Some arrays will be used as conflict bit vector of the
+   corresponding allocnos see function build_allocno_conflicts.  */
 static INT_TYPE **conflicts;
 
 /* Two macros to test 1 in an element of `conflicts'.  */
@@ -73,7 +77,7 @@ static INT_TYPE **conflicts;
  (conflicts[(I)] [(unsigned) (J) / INT_BITS]				\
   & ((INT_TYPE) 1 << ((unsigned) (J) % INT_BITS)))
 
-/* Bit mask for allocnos live at current point in the scan.  */
+/* Bit vector for allocnos live at the current program point.  */
 static INT_TYPE *allocnos_live;
 
 
@@ -167,6 +171,8 @@ commutative_constraint_p (const char *st
 	ignore_p = FALSE;
       else if (! ignore_p)
 	{
+	  /* Usually `%' is the first constraint character but the
+	     documentation does not require this.  */
 	  if (c == '%')
 	    return TRUE;
 	}
@@ -554,6 +560,10 @@ add_insn_allocno_copies (rtx insn)
 		      }
 		    else
 		      {
+			/* This copy is created to decrease register
+			   shuffling.  The copy will not correspond to
+			   a real move insn, so make the frequency
+			   smaller.  */
 			cp = add_allocno_copy
 			     (ira_curr_regno_allocno_map [REGNO (dup)],
 			      ira_curr_regno_allocno_map [REGNO (operand)],
@@ -568,7 +578,7 @@ add_insn_allocno_copies (rtx insn)
     }
 }
 
-/* The function adds copies originated from bb given by
+/* The function adds copies originated from BB given by
    LOOP_TREE_NODE.  */
 static void
 add_copies (loop_tree_node_t loop_tree_node)
@@ -584,10 +594,11 @@ add_copies (loop_tree_node_t loop_tree_n
       add_insn_allocno_copies (insn);
 }
 
-/* The function propagates info about allocno A to the corresponding
+/* The function propagates some info about allocno A (see comments
+   about accumulated info in allocno definition) to the corresponding
    allocno on upper loop tree level.  So allocnos on upper levels
    accumulate information about the corresponding allocnos in nested
-   loops.  */
+   regions.  */
 static void
 propagate_allocno_info (allocno_t a)
 {
@@ -636,8 +647,8 @@ propagate_allocno_info (allocno_t a)
     }
 }
 
-/* The function propagates info about allocnos to the corresponding
-   allocnos on upper loop tree level.  */
+/* The function propagates some info about allocnos to the
+   corresponding allocnos on upper loop tree level.  */
 static void
 propagate_info (void)
 {
@@ -652,8 +663,8 @@ propagate_info (void)
 }
 
 /* The function returns TRUE if live ranges of allocnos A1 and A2
-   intersect.  It checks intersection of the corresponding live ranges
-   for this.  */
+   intersect.  It is used to find a conflict for new allocnos or
+   allocnos with the different cover classes.  */
 int
 allocno_live_ranges_intersect_p (allocno_t a1, allocno_t a2)
 {
@@ -665,6 +676,7 @@ allocno_live_ranges_intersect_p (allocno
       && (ORIGINAL_REGNO (ALLOCNO_REG (a1))
 	  == ORIGINAL_REGNO (ALLOCNO_REG (a2))))
     return FALSE;
+  /* Remember the ranges are always kept ordered.  */
   for (r1 = ALLOCNO_LIVE_RANGES (a1), r2 = ALLOCNO_LIVE_RANGES (a2);
        r1 != NULL && r2 != NULL;)
     {
@@ -680,7 +692,7 @@ allocno_live_ranges_intersect_p (allocno
 
 /* The function returns TRUE if live ranges of pseudo-registers REGNO1
    and REGNO2 intersect.  It should be used when there is only one
-   region.  */
+   region.  Currently it is used during the reload work.  */
 int
 pseudo_live_ranges_intersect_p (int regno1, int regno2)
 {
@@ -696,7 +708,9 @@ pseudo_live_ranges_intersect_p (int regn
   return allocno_live_ranges_intersect_p (a1, a2);
 }
 
-/* Remove copies involving conflicting allocnos.  */
+/* Remove copies involving conflicting allocnos.  We can not do this
+   at the copy creation time because there are no conflicts at that
+   time yet.  */
 static void
 remove_conflict_allocno_copies (void)
 {
@@ -728,8 +742,9 @@ remove_conflict_allocno_copies (void)
   VARRAY_FREE (conflict_allocno_copy_varray);
 }
 
-/* The function builds conflict vectors or bit conflict vectors of all
-   allocnos from the conflict table.  */
+/* The function builds conflict vectors or bit conflict vectors
+   (whatever is more profitable) of all allocnos from the conflict
+   table.  */
 static void
 build_allocno_conflicts (void)
 {
@@ -803,7 +818,7 @@ build_allocno_conflicts (void)
 
 
 /* The function propagates information about allocnos modified inside
-   the loops.  */
+   the loop given by its LOOP_TREE_NODE to its father.  */
 static void
 propagate_modified_regnos (loop_tree_node_t loop_tree_node)
 {
@@ -844,8 +859,8 @@ print_hard_reg_set (FILE *file, const ch
   fprintf (file, "\n");
 }
 
-/* The function outputs information about allocno or regno (if REG_P)
-   conflicts to FILE.  */
+/* The function prints information about allocno or only regno (if
+   REG_P) conflicts to FILE.  */
 static void
 print_conflicts (FILE *file, int reg_p)
 {
@@ -894,8 +909,8 @@ print_conflicts (FILE *file, int reg_p)
   fprintf (file, "\n");
 }
 
-/* The function outputs information about allocno or regno (if REG_P)
-   conflicts to stderr.  */
+/* The function prints information about allocno or only regno (if
+   REG_P) conflicts to stderr.  */
 void
 debug_conflicts (int reg_p)
 {
@@ -904,7 +919,8 @@ debug_conflicts (int reg_p)
 
 
 
-/* Entry function which builds allocno conflicts.  */
+/* Entry function which builds allocno conflicts and allocno copies
+   and accumulate some allocno info on upper level regions.  */
 void
 ira_build_conflicts (void)
 {
Index: reload.h
===================================================================
--- reload.h	(revision 133412)
+++ reload.h	(working copy)
@@ -1,6 +1,6 @@
-/* Communication between reload.c and reload1.c.
-   Copyright (C) 1987, 1991, 1992, 1993, 1994, 1995, 1997, 1998,
-   1999, 2000, 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
+/* Communication between reload.c, reload1.c and the rest of compiler.
+   Copyright (C) 1987, 1991, 1992, 1993, 1994, 1995, 1997, 1998, 1999,
+   2000, 2001, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
Index: df-scan.c
===================================================================
--- df-scan.c	(revision 133412)
+++ df-scan.c	(working copy)
@@ -3063,10 +3063,10 @@ df_get_call_refs (struct df_collection_r
                   enum df_ref_flags flags)
 {
   rtx note;
-  bitmap_iterator bi;
   unsigned int ui;
   bool is_sibling_call;
   unsigned int i;
+  HARD_REG_SET clobbered_regs;
   bitmap defs_generated = BITMAP_ALLOC (&df_bitmap_obstack);
 
   /* Do not generate clobbers for registers that are the result of the
@@ -3117,17 +3117,18 @@ df_get_call_refs (struct df_collection_r
       }
 
   is_sibling_call = SIBLING_CALL_P (insn);
-  EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, ui, bi)
-    {
-      if (!global_regs[ui]
-	  && (!bitmap_bit_p (defs_generated, ui))
-	  && (!is_sibling_call
-	      || !bitmap_bit_p (df->exit_block_uses, ui)
-	      || refers_to_regno_p (ui, ui+1, 
-				    current_function_return_rtx, NULL)))
-        df_ref_record (collection_rec, regno_reg_rtx[ui], 
-		       NULL, bb, insn, DF_REF_REG_DEF, DF_REF_MAY_CLOBBER | flags);
-    }
+  get_call_invalidated_used_regs (insn, &clobbered_regs, true);
+  for (ui = 0; ui < FIRST_PSEUDO_REGISTER; ui++)
+    if (TEST_HARD_REG_BIT (clobbered_regs, ui)
+	&& !global_regs[ui]
+	&& (!bitmap_bit_p (defs_generated, ui))
+	&& (!is_sibling_call
+	    || !bitmap_bit_p (df->exit_block_uses, ui)
+	    || refers_to_regno_p (ui, ui+1, 
+				  current_function_return_rtx, NULL)))
+      df_ref_record (collection_rec, regno_reg_rtx[ui], 
+		     NULL, bb, insn, DF_REF_REG_DEF,
+		     DF_REF_MAY_CLOBBER | flags);
 
   BITMAP_FREE (defs_generated);
   return;
Index: caller-save.c
===================================================================
--- caller-save.c	(revision 133412)
+++ caller-save.c	(working copy)
@@ -98,7 +98,29 @@ static int n_regs_saved;
 static HARD_REG_SET referenced_regs;
 
 
+static int reg_save_code (int, enum machine_mode);
+static int reg_restore_code (int, enum machine_mode);
+
+struct saved_hard_reg;
+static void initiate_saved_hard_regs (void);
+static struct saved_hard_reg *new_saved_hard_reg (int, int);
+static void finish_saved_hard_regs (void);
+static int saved_hard_reg_compare_func (const void *, const void *);
+static void calculate_local_save_info (void);
+static void set_up_bb_rts_numbers (void);
+static int rpost_cmp (const void *, const void *);
+static void calculate_save_in_out (void);
+static int calculate_save_here (void);
+static void make_global_save_analysis (void);
+static void print_hard_reg_set_and_mode (FILE *, HARD_REG_SET,
+					 unsigned char *);
+static void print_hard_reg_set (FILE *, HARD_REG_SET);
+static void print_save_data (FILE *);
+static void set_hard_reg_saved (HARD_REG_SET, unsigned char *,
+				enum machine_mode *);
+
 static void mark_set_regs (rtx, const_rtx, void *);
+static void add_stored_regs (rtx, const_rtx, void *);
 static void mark_referenced_regs (rtx);
 static int insert_save (struct insn_chain *, int, int, HARD_REG_SET *,
 			enum machine_mode *);
@@ -107,7 +129,9 @@ static int insert_restore (struct insn_c
 static struct insn_chain *insert_one_insn (struct insn_chain *, int, int,
 					   rtx);
 static void add_stored_regs (rtx, const_rtx, void *);
+
 
+
 static GTY(()) rtx savepat;
 static GTY(()) rtx restpat;
 static GTY(()) rtx test_reg;
@@ -300,7 +324,8 @@ init_save_areas (void)
 }
 
 /* The structure represents a hard register which should be saved
-   through the call.  */
+   through the call.  It is used when the integrated register
+   allocator (IRA) is used and sharing save slots is on.  */
 struct saved_hard_reg
 {
   /* Order number starting with 0.  */
@@ -315,20 +340,21 @@ struct saved_hard_reg
   /* True if it is first hard register in the chain of hard registers
      sharing the same stack slot.  */
   int first_p;
-  /* Order number of the next hard register with the same slot in the
-     chain.  -1 represents end of the chain.  */
+  /* Order number of the next hard register structure with the same
+     slot in the chain.  -1 represents end of the chain.  */
   int next;
 };
 
 /* Map: hard register number to the corresponding structure.  */
 static struct saved_hard_reg *hard_reg_map [FIRST_PSEUDO_REGISTER];
 
-/* The number of all structures representing hard register should be
-   saved.  */
+/* The number of all structures representing hard registers should be
+   saved, in order words, the number of used elements in the following
+   array.  */
 static int saved_regs_num;
 
 /* Pointers to all the structures.  Index is the order number of the
-   structure.  */
+   corresponding structure.  */
 static struct saved_hard_reg *all_saved_regs [FIRST_PSEUDO_REGISTER];
 
 /* First called function for work with saved hard registers.  */
@@ -369,8 +395,8 @@ finish_saved_hard_regs (void)
     free (all_saved_regs [i]);
 }
 
-/* The function is used to sort the saved hard registers according
-   their frequency.  */
+/* The function is used to sort the saved hard register structures
+   according their frequency.  */
 static int
 saved_hard_reg_compare_func (const void *v1p, const void *v2p)
 {
@@ -395,7 +421,8 @@ saved_hard_reg_compare_func (const void 
    used as spill registers), but it should not be significant.
 
    For IRA we use priority coloring to decrease stack slots needed for
-   saving hard registers through calls.
+   saving hard registers through calls.  We build conflicts for them
+   to do coloring.
 
    Future work:
 
@@ -480,8 +507,7 @@ setup_save_areas (void)
 	     isn't.  */
 	  CLEAR_HARD_REG_SET (this_insn_sets);
 	  note_stores (PATTERN (insn), mark_set_regs, &this_insn_sets);
-	  /* Sibcalls are considered to set the return value,
-	     compare flow.c:propagate_one_insn.  */
+	  /* Sibcalls are considered to set the return value.  */
 	  if (SIBLING_CALL_P (insn) && current_function_return_rtx)
 	    mark_set_regs (current_function_return_rtx, NULL_RTX,
 			   &this_insn_sets);
@@ -726,8 +752,12 @@ setup_save_areas (void)
       if (regno_save_mem[i][j] != 0)
 	set_mem_alias_set (regno_save_mem[i][j], get_frame_alias_set ());
 }
+
 
 
+/* This page contains code for global analysis for better placement
+   save/restore insn when IRA is used.  */
+
 /* The following structure contains basic block data flow information
    used to calculate hard registers to save at BB ends.  Data flow
    equation is bidirectional because we don't want to put save/restore
@@ -736,10 +766,11 @@ struct bb_info
 {
   /* The basic block reverse post-order number.  */
   int rts_number;
-  /* True if save_in should empty for this block.  */
+  /* True if save_in should be empty for this block.  */
   int empty_save_in_p;
-  /* Hard registers correspondingly used (or set) and should be saved but
-     not used (or used) afterward in the basic block.  */
+  /* Hard registers should be saved through calls in the basic block
+     and correspondingly mentioned in the BB but not used after the BB
+     and set in the BB and used after the BB.  */
   HARD_REG_SET kill, gen;
   /* Registers needed to be saved at the start and end of the basic
      block.  */
@@ -747,7 +778,7 @@ struct bb_info
   /* Hard registers living at the start of the basic block.  */
   HARD_REG_SET live_at_start;
   /* We don't want to generate save/restore insns on edges because it
-     changes CFG during reload.  To prevent this we use the following
+     changes CFG during the reload.  To prevent this we use the following
      set.  This set defines what hard registers should be saved at the
      end of basic block. */
   HARD_REG_SET save_here;
@@ -824,6 +855,8 @@ calculate_local_save_info (void)
 		  int nregs;
 		  enum machine_mode mode;
 		  
+		  /* Remember live_throughout can contain spilled
+		     registers when IRA is used.  */
 		  if (flag_ira && r < 0)
 		    continue;
 		  gcc_assert (r >= 0);
@@ -853,8 +886,7 @@ calculate_local_save_info (void)
 		 that is set isn't.  */
 	      CLEAR_HARD_REG_SET (this_insn_sets);
 	      note_stores (PATTERN (insn), mark_set_regs, &this_insn_sets);
-	      /* Sibcalls are considered to set the return value,
-		 compare flow.c:propagate_one_insn.  */
+	      /* Sibcalls are considered to set the return value.  */
 	      if (SIBLING_CALL_P (insn) && current_function_return_rtx)
 		mark_set_regs (current_function_return_rtx, NULL_RTX,
 			       &this_insn_sets);
@@ -886,6 +918,7 @@ calculate_local_save_info (void)
 	    }
 	  COPY_HARD_REG_SET (bb_info->kill, kill);
 	  SET_HARD_REG_SET (bb_info->save_out);
+	  /* We don't use LIVE for IRA.  */
 	  REG_SET_TO_HARD_REG_SET
 	    (bb_info->live_at_start,
 	     flag_ira ? DF_LR_IN (bb) : DF_LIVE_IN (bb));
@@ -942,8 +975,8 @@ rpost_cmp (const void *bb1, const void *
                  | ^ (pred.save_out - pred.save_here) ^ bb.live_at_start
      bb.save_out = (bb.save_in - bb.kill) U bb.gen.
 
-   See function calculate_save_here to know how SAVE_HERE is
-   calculated  */
+   The function also calculates save_in_mode and save_out_mode.
+*/
 static void
 calculate_save_in_out (void)
 {
@@ -1083,12 +1116,12 @@ calculate_save_here (void)
   return changed_p;
 }
 
-/* The function calculates global save information used to put
+/* The function calculates the global save information used to put
    save/restore code without generating new blocks.  This is a
    bidirectional data flow problem (calculation of SAVE_IN and
-   SAVE_OUT is a forward data flow problem and SAVE_HERE is a backward
-   one).  It is complicated by calculation of modes for
-   saving/restoring call used hard registers.  */
+   SAVE_OUT is a forward data flow problem and SAVE_HERE is backward
+   one).  It is complicated by necessity of calculation of modes for
+   saving/restoring callee clobbered hard registers.  */
 static void
 make_global_save_analysis (void)
 {
@@ -1131,7 +1164,7 @@ print_hard_reg_set (FILE *f, HARD_REG_SE
       fprintf (f, " %d %s", i, reg_names [i]);
 }
 
-/* Print save information for each block to file F.  */  
+/* Print the save information for each block to file F.  */  
 static void
 print_save_data (FILE *f)
 {
@@ -1159,13 +1192,14 @@ print_save_data (FILE *f)
     }
 }
 
-/* Print save information for each block to stderr.  */  
+/* Print the save information for each block to stderr.  */  
 void
 debug_save_data (void)
 {
   print_save_data (stderr);
 }
 
+
 /* Setup hard registers in SET to save.  Setup also their save modes
    in SAVE_MODE from FROM_SAVE_MODE.  */  
 static void
@@ -1186,6 +1220,8 @@ set_hard_reg_saved (HARD_REG_SET set, un
       save_mode [regno] = VOIDmode;
 }
 
+
+
 /* Find the places where hard regs are live across calls and save them.  */
 
 void
@@ -1199,6 +1235,7 @@ save_call_clobbered_regs (void)
 
   if (flag_ira && flag_ira_move_spills)
     {
+      /* Do global analysis for better placement of spill code. */
       alloc_aux_for_blocks (sizeof (struct bb_info));
       make_global_save_analysis ();
     }
@@ -1282,6 +1319,8 @@ save_call_clobbered_regs (void)
 		  int nregs;
 		  enum machine_mode mode;
 
+		  /* Remember live_throughout can contain spilled
+		     registers when IRA is used.  */
 		  if (flag_ira && r < 0)
 		    continue;
 		  gcc_assert (r >= 0);
Index: ira-int.h
===================================================================
--- ira-int.h	(revision 133412)
+++ ira-int.h	(working copy)
@@ -1,4 +1,4 @@
-/* Integrated Register Allocator intercommunication header file.
+/* Integrated Register Allocator (IRA) intercommunication header file.
    Copyright (C) 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
@@ -37,8 +37,8 @@ Software Foundation, 51 Franklin Street,
 /* Compute register frequency from edge frequency FREQ.  It is
    analogous to REG_FREQ_FROM_BB.  When optimizing for size, or
    profile driven feedback is available and the function is never
-   executed, frequency is always equivalent.  Otherwise rescale edge
-   frequency.  */
+   executed, frequency is always equivalent.  Otherwise rescale the
+   edge frequency.  */
 #define REG_FREQ_FROM_EDGE_FREQ(freq)					      \
   (optimize_size || (flag_branch_probabilities && !ENTRY_BLOCK_PTR->count)    \
    ? REG_FREQ_MAX : (freq * REG_FREQ_MAX / BB_FREQ_MAX)			      \
@@ -47,58 +47,71 @@ Software Foundation, 51 Franklin Street,
 /* All natural loops.  */
 extern struct loops ira_loops;
 
-/* The flag value used internally.  */
+/* A modified value of flag `-fira-verbose' used internally.  */
 extern int internal_flag_ira_verbose;
 
 /* Dump file of the allocator if it is not NULL.  */
 extern FILE *ira_dump_file;
 
-/* Allocno live range, allocno, and copy of allocnos.  */
-typedef struct loop_tree_node *loop_tree_node_t;
+/* Typedefs for pointers to allocno live range, allocno, and copy of
+   allocnos.  */
 typedef struct allocno_live_range *allocno_live_range_t;
 typedef struct allocno *allocno_t;
 typedef struct allocno_copy *copy_t;
 
-/* The following structure describes loop tree node (block or loop).
-   We need such tree because the loop tree from cfgloop.h is not
-   convenient for the optimization (because basic blocks are not a
-   part of the tree from cfgloop.h).  We also use the nodes for
+/* Typedef for pointer to the subsequent structure.  */
+typedef struct loop_tree_node *loop_tree_node_t;
+
+/* In general case, IRA is a regional allocator.  The regions are
+   nested and form a tree.  Currently regions are natural loops.  The
+   following structure describes loop tree node (representing basic
+   block or loop).  We need such tree because the loop tree from
+   cfgloop.h is not convenient for the optimization: basic blocks are
+   not a part of the tree from cfgloop.h.  We also use the nodes for
    storing additional information about basic blocks/loops for the
-   register allocation.  */
+   register allocation purposes.  */
 struct loop_tree_node
 {
-  /* The node represents basic block if inner == NULL.  */
+  /* The node represents basic block if children == NULL.  */
   basic_block bb;    /* NULL for loop.  */
   struct loop *loop; /* NULL for BB.  */
-  /* The next node on the same tree level.  */
+  /* The next node on the same father.  */
   loop_tree_node_t next;
   /* The first node immediately inside the node.  */
-  loop_tree_node_t inner;
-  /* The node containing given node.  */
+  loop_tree_node_t children;
+  /* The node immediately containing given node.  */
   loop_tree_node_t father;
 
   /* Loop level in range [0, ira_loop_tree_height).  */
   int level;
 
-  /* Allocnos in loop corresponding to regnos.  If it is NULL the loop
-     is not included in the loop tree (e.g. it has abnormal enter/exit
-     edges).  */
+  /* All the following members are defined only for nodes representing
+     loops.  */
+
+  /* Allocnos in the loop corresponding to their regnos.  If it is
+     NULL the loop does not form a separate register allocation region
+     (e.g. because it has abnormal enter/exit edges and we can not put
+     code for register shuffling on the edges if a different
+     allocation is used for a pseudo-register on different sides of
+     the edges).  Caps are not in the map (remember we can have more
+     one cap with the same regno in a region).  */
   allocno_t *regno_allocno_map;
 
-  /* Maximal register pressure inside loop for given class (defined
-     only for cover_class).  */
+  /* Maximal register pressure inside loop for given register class
+     (defined only for the cover classes).  */
   int reg_pressure [N_REG_CLASSES];
 
-  /* Allocnos referred in the loop node.  */
+  /* Numbers of allocnos referred in the loop node.  */
   bitmap mentioned_allocnos;
 
-  /* Regnos modified in the loop node (including its subloops).  */
+  /* Regnos of pseudos modified in the loop node (including its
+     subloops).  */
   bitmap modified_regnos;
 
-  /* Allocnos living at the loop borders.  */
+  /* Numbers of allocnos living at the loop borders.  */
   bitmap border_allocnos;
 
-  /* Copies referred in the loop node.  */
+  /* Numbers of copies referred in the corresponding loop.  */
   bitmap local_copies;
 };
 
@@ -108,16 +121,16 @@ extern loop_tree_node_t ira_loop_tree_ro
 /* Height of the loop tree.  */
 extern int ira_loop_tree_height;
 
-/* All basic block data are referred through the following array.  We
-   can not use member `aux' for this because it is used for insertion
-   of insns on edges.  */
+/* All nodes representing basic blocks are referred through the
+   following array.  We can not use basic block member `aux' for this
+   because it is used for insertion of insns on edges.  */
 extern loop_tree_node_t ira_bb_nodes;
 
-/* Two access macros to the basic block data.  */
+/* Two access macros to the nodes representing basic blocks.  */
 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
 #define IRA_BB_NODE_BY_INDEX(index) __extension__			\
 (({ loop_tree_node_t _node = (&ira_bb_nodes [index]);	\
-     if (_node->inner != NULL || _node->loop != NULL || _node->bb == NULL)\
+     if (_node->children != NULL || _node->loop != NULL || _node->bb == NULL)\
        {								\
          fprintf (stderr,						\
                   "\n%s: %d: error in %s: it is not a block node\n",	\
@@ -131,14 +144,15 @@ extern loop_tree_node_t ira_bb_nodes;
 
 #define IRA_BB_NODE(bb) IRA_BB_NODE_BY_INDEX ((bb)->index)
 
-/* All loop data are referred through the following array.  */
+/* All nodes representing loops are referred through the following
+   array.  */
 extern loop_tree_node_t ira_loop_nodes;
 
-/* Two access macros to the loop data.  */
+/* Two access macros to the nodes representing loops.  */
 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
 #define IRA_LOOP_NODE_BY_INDEX(index) __extension__			\
 (({ loop_tree_node_t const _node = (&ira_loop_nodes [index]);\
-     if (_node->inner == NULL || _node->bb != NULL || _node->loop == NULL)\
+     if (_node->children == NULL || _node->bb != NULL || _node->loop == NULL)\
        {								\
          fprintf (stderr,						\
                   "\n%s: %d: error in %s: it is not a loop node\n",	\
@@ -154,8 +168,12 @@ extern loop_tree_node_t ira_loop_nodes;
 
 
 
-/* The structure describes program points where a given allocno
-   lives.  */
+/* The structure describes program points where a given allocno lives.
+   To save memory we store allocno conflicts only for the same cover
+   class allocnos which is enough to assign hard registers.  To find
+   conflicts for other allocnos (e.g. to assign stack memory slot) we
+   use the live ranges.  If the live ranges of two allocnos are
+   intersected, the allocnos are in conflict.  */
 struct allocno_live_range
 {
   /* Allocno whose live range is described by given structure.  */
@@ -169,39 +187,58 @@ struct allocno_live_range
   allocno_live_range_t start_next, finish_next;
 };
 
-/* Program points are enumerated by number from range
-   0..MAX_POINT-1.  */
+/* Program points are enumerated by number from range 0..MAX_POINT-1.
+   There are approximately tow times more program points than insns.
+   One program points correspond points between subsequent insns and
+   other ones correspond to points after usage of input operands but
+   before setting the output operands in insns.  */
 extern int max_point;
 
 /* Arrays of size MAX_POINT mapping a program point to the allocno
    live ranges with given start/finish point.  */
 extern allocno_live_range_t *start_point_ranges, *finish_point_ranges;
 
-/* Node representing allocnos (allocation entity).  */
+/* A structure representing an allocno (allocation entity).  Allocno
+   represents a pseudo-register in an allocation region.  If
+   pseudo-register does not live in a region but it lives in the
+   nested regions, it is represented in the region by special allocno
+   called *cap*.  There may be more one cap representing the same
+   pseudo-register in region.  It means that the corresponding
+   pseudo-register lives in more one non-intersected subregion.  */
 struct allocno
 {
-  /* The allocno order number starting with 0.  */
+  /* The allocno order number starting with 0.  Each allocno has an
+     unique number and the number is never changed for the
+     allocno.  */
   int num;
   /* Regno for allocno or cap.  */
   int regno;
-  /* Mode of the allocno.  */
+  /* Mode of the allocno which is the mode of the corresponding
+     pseudo-register.  */
   enum machine_mode mode;
   /* Final rtx representation of the allocno.  */
   rtx reg;
   /* Hard register assigned to given allocno.  Negative value means
      that memory was allocated to the allocno.  During the reload,
-     spilled allocno has value the corresponding stack slot number (0,
-     ...) - 2.  Value -1 is used for allonos spilled by the reload
-     which did not get stack slot yet.  */
+     spilled allocno has value equal to the corresponding stack slot
+     number (0, ...) - 2.  Value -1 is used for allocnos spilled by the
+     reload (at this point pseudo-register has only one allocno) which
+     did not get stack slot yet.  */
   int hard_regno;
   /* Allocnos with the same regno are linked by the following member.
-     Allocnos corresponding to inner loops are first in the list
-     (depth-first tarverse).  */
+     Allocnos corresponding to inner loops are first in the list (it
+     corresponds to depth-first traverse of the loops).  */
   allocno_t next_regno_allocno;
-  /* There may be different allocnos with the same regno.  They are
-     bound to a loop tree node.  */
+  /* There may be different allocnos with the same regno in different
+     regions.  Allocnos are bound to the corresponding loop tree node.
+     Pseudo-register may have only one regular allocno with given loop
+     tree node but more than one cap (see comments above).  */
   loop_tree_node_t loop_tree_node;
-  /* Accumulated usage references of the allocno.  */
+  /* Accumulated usage references of the allocno.  Here and below,
+     word 'accumulated' means info for given region and all nested
+     subregions.  In this case, 'accumulated' means sum of references
+     of the corresponding pseudo-register in this region and in all
+     nested subregions recursively. */
   int nrefs;
   /* Accumulated frequency of usage of the allocno.  */
   int freq;
@@ -211,21 +248,29 @@ struct allocno
   /* Minimal accumulated cost of usage register of the cover class for
      the allocno.  */
   int cover_class_cost;
-  /* Minimal accumulated, and updated costs of memory for the
-     allocno.  */
+  /* Minimal accumulated, and updated costs of memory for the allocno.
+     At the allocation start, the original and updated costs are
+     equal.  The updated cost may be changed after finishing
+     allocation in a region and starting allocation in a subregion.
+     The change reflects the cost of spill/restore code on the
+     subregion border if we assign memory to the pseudo in the
+     subregion.  */
   int memory_cost, updated_memory_cost;
   /* Accumulated number of points where the allocno lives and there is
-     excess pressure for its class.  */
+     excess pressure for its class.  Excess pressure for a register
+     class at some point means that there are more allocnos of given
+     register class living at the point than number of hard-registers
+     of the class available for the allocation.  */
   int excess_pressure_points_num;
   /* Copies to other non-conflicting allocnos.  The copies can
      represent move insn or potential move insn usually because of two
-     operand constraints.  */
+     operand insn constraints.  */
   copy_t allocno_copies;
   /* It is a allocno (cap) representing given allocno on upper loop tree
      level.  */
   allocno_t cap;
   /* It is a link to allocno (cap) on lower loop level represented by
-     given cap.  Null if it is not a cap.  */
+     given cap.  Null if given allocno is not a cap.  */
   allocno_t cap_member;
   /* Coalesced allocnos form a cyclic list.  One allocno given by
      FIRST_COALESCED_ALLOCNO represents all coalesced allocnos.  The
@@ -233,18 +278,19 @@ struct allocno
   allocno_t first_coalesced_allocno;
   allocno_t next_coalesced_allocno;
   /* Pointer to structures describing at what program point the
-     allocno lives.  We always maintain the condition that *ranges in
-     the list are not intersected and ordered by decreasing their
-     program points*.  */
+     allocno lives.  We always maintain the list in such way that *the
+     ranges in the list are not intersected and ordered by decreasing
+     their program points*.  */
   allocno_live_range_t live_ranges;
-  /* Vector of conflicting allocnos with NULL end marker if
-     CONFLICT_VEC_P is true or conflict bit vector otherwise.  Only
-     allocnos with the same cover class are in the vector or in the
-     bit vector.  */
+  /* Vector of accumulated conflicting allocnos with NULL end marker
+     (if CONFLICT_VEC_P is true) or conflict bit vector otherwise.
+     Only allocnos with the same cover class are in the vector or in
+     the bit vector.  */
   void *conflict_allocno_array;
   /* Allocated size of the previous array.  */
   unsigned int conflict_allocno_array_size;
-  /* Number of accumulated conflicts in the previous array.  */
+  /* Number of accumulated conflicts in the vector of conflicting
+     allocnos.  */
   int conflict_allocnos_num;
   /* Initial and accumulated hard registers conflicting with this
      allocno and as a consequences can not be assigned to the
@@ -253,33 +299,39 @@ struct allocno
   /* Accumulated frequency of calls which given allocno
      intersects.  */
   int call_freq;
-  /* Start index of calls intersected by the allocno in
+  /* Start index of calls intersected by the allocno in array
      regno_calls [regno].  */
   int calls_crossed_start;
   /* Length of the previous array (number of the intersected calls).  */
   int calls_crossed_num;
   /* Non NULL if we remove restoring value from given allocno to
-     MEM_OPTIMIZED_DEST at the end of loop because the value is not
-     changed in loop.  */
+     MEM_OPTIMIZED_DEST at loop exit (see ira-emit.c) because the
+     allocno value is not changed inside the loop.  */
   allocno_t mem_optimized_dest;
-  /* TRUE if the allocno was a destination of removed move at the end
-     of loop because the value is not changed in loop.  */
+  /* TRUE if the allocno assigned to memory was a destination of
+     removed move (see ira-emit.c) at loop exit because the value of
+     the corresponding pseudo-register is not changed inside the
+     loop.  */
   unsigned int mem_optimized_dest_p : 1;
-  /* TRUE if the correspdonding pseudo-register has disjoint live
-     ranges and the other allocnos except this one changed regno.  */
+  /* TRUE if the corresponding pseudo-register has disjoint live
+     ranges and the other allocnos of the pseudo-register except this
+     one changed REG.  */
   unsigned int somewhere_renamed_p : 1;
-  /* TRUE if the allocno child has been renamed, in other words, got a
-     new pseudo-register.  */
+  /* TRUE if allocno with the same REGNO in a subregion has been
+     renamed, in other words, got a new pseudo-register.  */
   unsigned int child_renamed_p : 1;
-  /* In the reload, we should not reassign a hard register to the
-     allocno got memory if the flag value is TRUE.  */
+  /* During the reload, value TRUE means that we should not reassign a
+     hard register to the allocno got memory earlier.  It is set up
+     when we removed memory-memory move insn before each iteration of
+     the reload.  */
   unsigned int dont_reassign_p : 1;
 #ifdef STACK_REGS
-  /* Set to TRUE if allocno can't be allocated in the stack
-     register.  */
+  /* Set to TRUE if allocno can't be assigned to the stack hard
+     register correspondingly in this region and area including the
+     region and all its subregions recursively.  */
   unsigned int no_stack_reg_p : 1, total_no_stack_reg_p : 1;
 #endif
-  /* TRUE value means than the allocno was not removed from the
+  /* TRUE value means that the allocno was not removed yet from the
      conflicting graph during colouring.  */
   unsigned int in_graph_p : 1;
   /* TRUE if a hard register or memory has been assigned to the
@@ -289,25 +341,38 @@ struct allocno
      colorable.  */
   unsigned int may_be_spilled_p : 1;
   /* TRUE if conflicts for given allocno are represented by vector of
-     pointer to the allocnos.  Otherwise, we use a bit vector where a
-     bit with given index represents allocno with the same number.  */
+     pointers to the conflicting allocnos.  Otherwise, we use a bit
+     vector where a bit with given index represents allocno with the
+     same number.  */
   unsigned int conflict_vec_p : 1;
-  /* Array of additional costs (accumulated and the one updated during
-     coloring) for hard regno of allocno cover class.  If given
-     allocno represents a set of allocnos the current costs represents
-     costs of the all set.  */
+  /* Array of usage costs (accumulated and the one updated during
+     coloring) for each hard register of the allocno cover class.  The
+     member value can be NULL if all costs are the same and equal to
+     COVER_CLASS_COST.  For example, the costs of two different hard
+     registers can be different if one hard register is callee-saved
+     and another one is callee-used and the allocno lives through
+     calls.  Another example can be case when for some insn the
+     corresponding pseudo-register value should be put in specific
+     register class (e.g. AREG for x86) which is a strict subset of
+     the allocno cover class (GENERAL_REGS for x86).  We have updated
+     costs to reflect the situation when the usage cost of a hard
+     register is decreased because the allocno is connected to another
+     allocno by a copy and the another allocno has been assigned to
+     the hard register.  */
   int *hard_reg_costs, *updated_hard_reg_costs;
   /* Array of decreasing costs (accumulated and the one updated during
-     coloring) for conflicting allocnos for hard regno of the allocno
-     cover class.  The member values can be NULL if all costs are the
-     same.  If given allocno represents a set of allocnos the current
-     costs represents costs of the all set.  */
+     coloring) for allocnos conflicting with given allocno for hard
+     regno of the allocno cover class.  The member value can be NULL
+     if all costs are the same.  These costs are used to reflect
+     preferences of other allocnos not assigned yet during assigning
+     to given allocno.  */
   int *conflict_hard_reg_costs, *updated_conflict_hard_reg_costs;
-  /* Number of allocnos with TRUE in_graph_p value and conflicting with
-     given allocno.  */
+  /* Number of the same cover class allocnos with TRUE in_graph_p
+     value and conflicting with given allocno during each point of
+     graph coloring.  */
   int left_conflicts_num;
-  /* Number of hard register of the allocno cover class really
-     availiable for the allocno allocation.  */
+  /* Number of hard registers of the allocno cover class really
+     available for the allocno allocation.  */
   int available_regs_num;
   /* Allocnos in a bucket (used in coloring) chained by the following
      two members.  */
@@ -317,8 +382,8 @@ struct allocno
   int temp;
 };
 
-/* All members of the allocno node should be accessed only through the
-   following macros.  */
+/* All members of the allocno structures should be accessed only
+   through the following macros.  */
 #define ALLOCNO_NUM(A) ((A)->num)
 #define ALLOCNO_REGNO(A) ((A)->regno)
 #define ALLOCNO_REG(A) ((A)->reg)
@@ -374,7 +439,8 @@ struct allocno
 #define ALLOCNO_NEXT_COALESCED_ALLOCNO(A) ((A)->next_coalesced_allocno)
 #define ALLOCNO_LIVE_RANGES(A) ((A)->live_ranges)
 
-/* Map regno -> allocnos.  */
+/* Map regno -> allocnos with given regno (see comments for 
+   allocno member `next_regno_allocno').  */
 extern allocno_t *regno_allocno_map;
 
 /* Array of references to all allocnos.  The order number of the
@@ -385,46 +451,49 @@ extern allocno_t *allocnos;
 /* Sizes of the previous array.  */
 extern int allocnos_num;
 
-/* The following structure represents a copy of given allocno to
-   another allocno.  The copies represent move insns or potential move
-   insns usually because of two operand constraints. */
+/* The following structure represents a copy of two allocnos.  The
+   copies represent move insns or potential move insns usually because
+   of two operand insn constraints. */
 struct allocno_copy
 {
-  /* The order number of the copy node starting with 0.  */
+  /* The unique order number of the copy node starting with 0.  */
   int num;
-  /* Allocno connected by the copy.  The first one should have smaller
-     order number than the second one.  */
+  /* Allocnos connected by the copy.  The first allocno should have
+     smaller order number than the second one.  */
   allocno_t first, second;
   /* Execution frequency of the copy.  */
   int freq;
-  /* It is an insn which is an origion of the copy.  It may be a move
+  /* It is an insn which is an origin of the copy.  It may be a move
      insn or insn whose operand should be the same as the result
-     (2-operand insns).  The member value for copy created to remove
-     register shuffle is NULL.  */
+     (2-operand insns).  To remove register shuffle, we create copies
+     between allocno which is output of an insn and allocno becoming
+     dead in the insn.  The member value for the copy created to
+     remove register shuffle is NULL and the frequency is smaller than
+     the corresponding insn execution frequency.  */
   rtx insn;
-  /* Copies with the same allocno as FIRST are linked by the two
+  /* All copies with the same allocno as FIRST are linked by the two
      following members.  */
   copy_t prev_first_allocno_copy, next_first_allocno_copy;
-  /* Copies with the same allocno as SECOND are linked by the two
+  /* All copies with the same allocno as SECOND are linked by the two
      following members.  */
   copy_t prev_second_allocno_copy, next_second_allocno_copy;
   /* Region from which given copy is originated.  */
   loop_tree_node_t loop_tree_node;
 };
 
-/* Array of references to copies.  The order number of the copy
-   corresponds to the index in the array.  Removed allocnos
-   have NULL element value.  */
+/* Array of references to all copies.  The order number of the copy
+   corresponds to the index in the array.  Removed copies have NULL
+   element value.  */
 extern copy_t *copies;
 
 /* Size of the previous array.  */
 extern int copies_num;
 
 /* The following structure describes a stack slot used for spilled
-   registers.  */
+   pseudo-registers.  */
 struct spilled_reg_stack_slot
 {
-  /* pseudo-registers have used the stack slot.  */
+  /* pseudo-registers assigned to the stack slot.  */
   regset_head spilled_regs;
   /* RTL representation of the stack slot.  */
   rtx mem;
@@ -435,30 +504,31 @@ struct spilled_reg_stack_slot
 /* The number of elements in the following array.  */
 extern int spilled_reg_stack_slots_num;
 
-/* The following array contains description of spilled registers stack
-   slots have been used in current function so far.  */
+/* The following array contains info about spilled pseudo-registers
+   stack slots used in current function so far.  */
 extern struct spilled_reg_stack_slot *spilled_reg_stack_slots;
 
-/* Correspondingly overall cost of the allocation, cost of hard
-   register usage for the allocnos, cost of memory usage for the
-   allocnos, cost of loads, stores and register move insns generated
-   for register live range splitting.  */
+/* Correspondingly overall cost of the allocation, cost of the
+   allocnos assigned to hard-registers, cost of the allocnos assigned
+   to memory, cost of loads, stores and register move insns generated
+   for pseudo-register live range splitting (see ira-emit.c).  */
 extern int overall_cost;
 extern int reg_cost, mem_cost;
 extern int load_cost, store_cost, shuffle_cost;
 extern int move_loops_num, additional_jumps_num;
 
 /* Map: register class x machine mode -> number of hard registers of
-   given class needed to store value of given mode.  If the number is
-   different, the size will be negative.  */
+   given class needed to store value of given mode.  If the number for
+   some hard-registers of the register class is different, the size
+   will be negative.  */
 extern int reg_class_nregs [N_REG_CLASSES] [MAX_MACHINE_MODE];
 
 /* Maximal value of the previous array elements.  */
 extern int max_nregs;
 
-/* The number of bits in each element of `allocnos_live' and what
-   type that element has.  We use the largest integer format on the
-   host machine.  */
+/* The number of bits in each element of array used to implement a bit
+   vector of allocnos and what type that element has.  We use the
+   largest integer format on the host machine.  */
 #define INT_BITS HOST_BITS_PER_WIDE_INT
 #define INT_TYPE HOST_WIDE_INT
 
@@ -477,23 +547,23 @@ extern int max_nregs;
    & ((INT_TYPE) 1 << ((unsigned) (I) % INT_BITS)))
 
 
-/* The iterator for allocno set.  */
+/* The iterator for allocno set implemented ed as allocno bit
+   vector.  */
 typedef struct {
 
-  /* The allocno bit vector.  */
+  /* Array containing the allocno bit vector.  */
   INT_TYPE *vec;
 
-  /* The number of the current element in the vector (of type
-     allocno_t or INT_TYPE).  */
+  /* The number of the current element in the vector.  */
   unsigned int word_num;
 
-  /* The number of element (bits) in the bit vector.  */
+  /* The number of bits in the bit vector.  */
   unsigned int nel;
 
-  /* The current bit index of bit vector.  */
+  /* The current bit index of the bit vector.  */
   unsigned int bit_num;
 
-  /* The word of bit vector currently visited.  */
+  /* The word of the bit vector currently visited.  */
   unsigned INT_TYPE word;
 } allocno_set_iterator;
 
@@ -535,7 +605,7 @@ allocno_set_iter_cond (allocno_set_itera
   return TRUE;
 }
 
-/* Advance to the next allocno.  */
+/* Advance to the next allocno in the set.  */
 static inline void
 allocno_set_iter_next (allocno_set_iterator *i)
 {
@@ -558,52 +628,59 @@ allocno_set_iter_next (allocno_set_itera
 extern HARD_REG_SET zero_hard_reg_set;
 extern HARD_REG_SET one_hard_reg_set;
 
-/* A mode whose value is immediately contained in given mode
-   value.  */
-extern unsigned char mode_inner_mode [NUM_MACHINE_MODES];
-
-/* Map hard regs X modes -> number registers for store value of given
-   mode starting with given hard register.  */
+/* Map: hard regs X modes -> set of hard registers for storing value
+   of given mode starting with given hard register.  */
 extern HARD_REG_SET reg_mode_hard_regset
                     [FIRST_PSEUDO_REGISTER] [NUM_MACHINE_MODES];
 
-/* Array analog of macros MEMORY_MOVE_COST and REGISTER_MOVE_COST.  */
+/* Arrays analogous to macros MEMORY_MOVE_COST and
+   REGISTER_MOVE_COST.  */
 extern short memory_move_cost [MAX_MACHINE_MODE] [N_REG_CLASSES] [2];
 extern move_table *register_move_cost [MAX_MACHINE_MODE];
 
-/* Similar to move_cost, but here we don't have to move if the first
-   index is a subset of the second (taking registers available for
-   allocation into account) so in that case the cost is zero.  */
+/* Similar to may_move_in_cost but it is calculated in IRA instead of
+   regclass.  Another difference we take only available hard registers
+   into account to figure out that one register class is a subset of
+   the another one.  */
 extern move_table *register_may_move_in_cost [MAX_MACHINE_MODE];
 
-/* Similar, but here we don't have to move if the first index is a
-   superset of the second (taking registers available for allocation
-   into account) so in that case the cost is zero.  */
+/* Similar to may_move_out_cost but it is calculated in IRA instead of
+   regclass.  Another difference we take only available hard registers
+   into account to figure out that one register class is a subset of
+   the another one.  */
 extern move_table *register_may_move_out_cost [MAX_MACHINE_MODE];
 
-/* Register class subset relation.  */
+/* Register class subset relation: TRUE if the first class is a subset
+   of the second one considering only hard registers available for the
+   allocation.  */
 extern int class_subset_p [N_REG_CLASSES] [N_REG_CLASSES];
 
-/* Hard registers which can be used for the allocation of given
-   register class.  */
+/* Array of number of hard registers of given class which are
+   available for the allocation.  The order is defined by the
+   allocation order.  */
 extern short class_hard_regs [N_REG_CLASSES] [FIRST_PSEUDO_REGISTER];
 
-/* The size of the above array for given register class.  */
+/* The number of elements of the above array for given register
+   class.  */
 extern int class_hard_regs_num [N_REG_CLASSES];
 
 /* Index (in class_hard_regs) for given register class and hard
-   register.  */
+   register (in general case a hard register can belong to several
+   register classes).  The index is negative for hard registers
+   unavailable for the allocation. */
 extern short class_hard_reg_index [N_REG_CLASSES] [FIRST_PSEUDO_REGISTER];
 
-/* Hard registers can not be used for the register allocator.  */
+/* Function specific hard registers can not be used for the register
+   allocation.  */
 extern HARD_REG_SET no_alloc_regs;
 
-/* Number of class hard registers available for the register
+/* Number of given class hard registers available for the register
    allocation for given classes.  */
 extern int available_class_regs [N_REG_CLASSES];
 
-/* Array whose values are hard regset of hard registers of given
-   register class whose HARD_REGNO_MODE_OK values are zero.  */
+/* Array whose values are hard regset of hard registers available for
+   the allocation of given register class whose HARD_REGNO_MODE_OK
+   values for given mode are zero.  */
 extern HARD_REG_SET prohibited_class_mode_regs
                     [N_REG_CLASSES] [NUM_MACHINE_MODES];
 
@@ -612,33 +689,42 @@ extern HARD_REG_SET prohibited_class_mod
    prohibited.  */
 extern HARD_REG_SET prohibited_mode_move_regs [NUM_MACHINE_MODES];
 
-/* Number of cover classes.  */
+/* Number of cover classes.  Cover classes is non-intersected register
+   classes containing all hard-registers available for the
+   allocation.  */
 extern int reg_class_cover_size;
 
-/* The array containing cover classes whose hard registers are used
-   for the allocation.  */
+/* The array containing cover classes (see also comments for macro
+   IRA_COVER_CLASSES).  Only first REG_CLASS_COVER_SIZE elements are
+   used for this.  */
 extern enum reg_class reg_class_cover [N_REG_CLASSES];
 
 /* The value is number of elements in the subsequent array.  */
 extern int important_classes_num;
 
-/* The array containing classes which are subclasses of cover
-   classes.  */
+/* The array containing classes (including cover classes) which are
+   subclasses of cover classes.  Such classes is important for
+   calculation of the hard register usage costs.  */
 extern enum reg_class important_classes [N_REG_CLASSES];
 
-/* The array containing order numbers of important classes (they are
-   subclasses of cover classes).  */
+/* The array containing indexes of important classes in the previous
+   array.  The array elements are defined only for important
+   classes.  */
 extern int important_class_nums [N_REG_CLASSES];
 
-/* Map of register classes to corresponding cover class containing the
-   given class.  */
+/* Map of all register classes to corresponding cover class containing
+   the given class.  If given class is not a subset of a cover class,
+   we translate it into the cheapest cover class.  */
 extern enum reg_class class_translate [N_REG_CLASSES];
 
 /* The biggest important class inside of intersection of the two
-   classes (taking only registers available for allocation).  */
+   classes (that is calculated taking only hard registers available
+   for allocation into account).  */
 extern enum reg_class reg_class_intersect [N_REG_CLASSES] [N_REG_CLASSES];
+
 /* The biggest important class inside of union of the two classes
-   (taking only registers available for allocation).  */
+   (that is calculated taking only hard registers available for
+   allocation into account).  */
 extern enum reg_class reg_class_union [N_REG_CLASSES] [N_REG_CLASSES];
 
 extern void set_non_alloc_regs (int);
@@ -647,27 +733,30 @@ extern void *ira_reallocate (void *, siz
 extern void ira_free (void *addr);
 extern bitmap ira_allocate_bitmap (void);
 extern void ira_free_bitmap (bitmap);
-extern regset ira_allocate_regset (void);
-extern void ira_free_regset (regset);
 extern void print_disposition (FILE *);
 extern void debug_disposition (void);
 extern void debug_class_cover (void);
 extern void init_register_move_cost (enum machine_mode);
 
-/* Length of the two following arrays.  */
+/* The length of the two following arrays.  */
 extern int reg_equiv_len;
 
-/* Regno invariant flags.  */
+/* The element value is TRUE if the corresponding regno value is
+   invariant.  */
 extern int *reg_equiv_invariant_p;
 
-/* Regno equivalent constants.  */
+/* The element value is equiv constant of given pseudo-register or
+   NULL_RTX.  */
 extern rtx *reg_equiv_const;
 
 /* ira-build.c */
 
-/* The current loop tree node.  */
+/* The current loop tree node and its regno allocno map.  */
 extern loop_tree_node_t ira_curr_loop_tree_node;
 extern allocno_t *ira_curr_regno_allocno_map;
+
+/* Array of vectors containing calls given pseudo-register lives
+   through.  */
 extern VEC(rtx, heap) **regno_calls;
 
 extern int add_regno_call (int, rtx);
@@ -710,7 +799,8 @@ extern void tune_allocno_costs_and_cover
 
 /* ira-lives.c */
 
-/* Number of ints required to hold allocnos_num bits.  */
+/* Number of ints of type INT_TYPE required to hold allocnos_num
+   bits.  */
 extern int allocno_set_words;
 
 extern void rebuild_start_finish_chains (void);
@@ -729,7 +819,7 @@ extern void ira_build_conflicts (void);
 
 /* ira-color.c */
 extern int loop_edge_freq (loop_tree_node_t, int, int);
-extern void reassign_conflict_allocnos (int, int);
+extern void reassign_conflict_allocnos (int);
 extern void initiate_ira_assign (void);
 extern void finish_ira_assign (void);
 extern void ira_color (void);
@@ -822,7 +912,7 @@ copy_iter_cond (copy_iterator *i, copy_t
 /* The iterator for allocno conflicts.  */
 typedef struct {
 
-  /* TRUE if the conflicts are represented by vectors of allocnos.  */
+  /* TRUE if the conflicts are represented by vector of allocnos.  */
   int allocno_conflict_vec_p;
 
   /* The conflict vector or conflict bit vector.  */
@@ -832,13 +922,16 @@ typedef struct {
      allocno_t or INT_TYPE).  */
   unsigned int word_num;
 
-  /* The bit vector size.  */
+  /* The bit vector size.  It is defined only if
+     ALLOCNO_CONFLICT_VEC_P is FALSE.  */
   unsigned int size;
 
-  /* The current bit index of bit vector.  */
+  /* The current bit index of bit vector.  It is defined only if
+     ALLOCNO_CONFLICT_VEC_P is FALSE.  */
   unsigned int bit_num;
 
-  /* The word of bit vector currently visited.  */
+  /* The word of bit vector currently visited.  It is defined only if
+     ALLOCNO_CONFLICT_VEC_P is FALSE.  */
   unsigned INT_TYPE word;
 } allocno_conflict_iterator;
 
@@ -861,8 +954,9 @@ allocno_conflict_iter_init (allocno_conf
     }
 }
 
-/* Return TRUE if we have more allocnos to visit, in which case *A is
-   set to the allocno to be visited.  Otherwise, return FALSE.  */
+/* Return TRUE if we have more conflicting allocnos to visit, in which
+   case *A is set to the allocno to be visited.  Otherwise, return
+   FALSE.  */
 static inline int
 allocno_conflict_iter_cond (allocno_conflict_iterator *i, allocno_t *a)
 {
@@ -913,9 +1007,10 @@ allocno_conflict_iter_next (allocno_conf
     }
 }
 
-/* Loop over all elements of ALLOCNO conflicts.  In each iteration, A
-   is set to the next conflicting allocno.  ITER is an instance of
-   allocno_conflict_iterator used to iterate the conflicts.  */
+/* Loop over all allocnos conflicting with ALLOCNO.  In each
+   iteration, A is set to the next conflicting allocno.  ITER is an
+   instance of allocno_conflict_iterator used to iterate the
+   conflicts.  */
 #define FOR_EACH_ALLOCNO_CONFLICT(ALLOCNO, A, ITER)			\
   for (allocno_conflict_iter_init (&(ITER), (ALLOCNO));			\
        allocno_conflict_iter_cond (&(ITER), &(A));			\
@@ -923,7 +1018,7 @@ allocno_conflict_iter_next (allocno_conf
 
 
 
-/* The function returns nonzero if hard registers starting with
+/* The function returns TRUE if hard registers starting with
    HARD_REGNO and containing value of MODE are not in set
    HARD_REGSET.  */
 static inline int
@@ -941,8 +1036,12 @@ hard_reg_not_in_set_p (int hard_regno, e
 
 
 
-/* Allocate cost vector *VEC and initialize the elements by VAL if it
-   is necessary */
+/* To save memory we use a lazy approach for allocation and
+   initialization of the cost vectors.  We do this only when it is
+   really necessary.  */
+
+/* Allocate cost vector *VEC for hard registers of COVER_CLASS and
+   initialize the elements by VAL if it is necessary */
 static inline void
 allocate_and_set_costs (int **vec, enum reg_class cover_class, int val)
 {
@@ -957,8 +1056,8 @@ allocate_and_set_costs (int **vec, enum 
     reg_costs [i] = val;
 }
 
-/* Allocate cost vector *VEC and copy values of SRC into the vector if
-   it is necessary */
+/* Allocate cost vector *VEC for hard registers of COVER_CLASS and
+   copy values of vector SRC into the vector if it is necessary */
 static inline void
 allocate_and_copy_costs (int **vec, enum reg_class cover_class, int *src)
 {
@@ -971,8 +1070,9 @@ allocate_and_copy_costs (int **vec, enum
   memcpy (*vec, src, sizeof (int) * len);
 }
 
-/* Allocate cost vector *VEC and copy values of SRC into the vector or
-   initialize it by VAL (if SRC is null).  */
+/* Allocate cost vector *VEC for hard registers of COVER_CLASS and
+   copy values of vector SRC into the vector or initialize it by VAL
+   (if SRC is null).  */
 static inline void
 allocate_and_set_or_copy_costs (int **vec, enum reg_class cover_class,
 				int val, int *src)
Index: ira-color.c
===================================================================
--- ira-color.c	(revision 133412)
+++ ira-color.c	(working copy)
@@ -41,12 +41,16 @@ Software Foundation, 51 Franklin Street,
 #include "df.h"
 #include "ira-int.h"
 
-/* We use optimistic colouring.  */
+/* This file contains code for regional graph coloring, spill/restore
+   code placement optimization, and code helping the reload pass to do
+   a better job.  */
 
 static void initiate_cost_update (void);
 static void finish_cost_update (void);
 static void update_copy_costs_1 (allocno_t, int, int, int);
 static void update_copy_costs (allocno_t, int);
+static int allocno_cost_compare_func (const void *, const void *);
+static void print_coalesced_allocno (allocno_t);
 static int assign_hard_reg (allocno_t, int);
 
 static void add_allocno_to_bucket (allocno_t, allocno_t *);
@@ -73,13 +77,13 @@ static void color_allocnos (void);
 
 static void print_loop_title (loop_tree_node_t);
 static void color_pass (loop_tree_node_t);
-static int allocno_priority_compare_func (const void *, const void *);
-static void start_allocno_priorities (allocno_t *, int);
 static void do_coloring (void);
 
 static void move_spill_restore (void);
 
-static void setup_curr_costs (allocno_t);
+static void update_curr_costs (allocno_t);
+static void start_allocno_priorities (allocno_t *, int);
+static int allocno_priority_compare_func (const void *, const void *);
 
 static int coalesced_pseudo_reg_freq_compare (const void *, const void *);
 static int coalesced_pseudo_reg_slot_compare (const void *, const void *);
@@ -87,6 +91,7 @@ static void setup_coalesced_allocno_cost
 static int collect_spilled_coalesced_allocnos (int *, int, allocno_t *);
 static int coalesce_spill_slots (allocno_t *, int);
 
+static int allocno_reload_assign (allocno_t, HARD_REG_SET);
 static int pseudo_reg_compare (const void *, const void *);
 
 static int calculate_spill_cost (int *, rtx, rtx, rtx,
@@ -101,7 +106,7 @@ static bitmap coloring_allocno_bitmap;
    allocnos.  */
 static bitmap consideration_allocno_bitmap;
 
-/* TRUE if we coalesced some allocnos.  In other words, if we have
+/* TRUE if we coalesced some allocnos.  In other words, if we got
    loops formed by members first_coalesced_allocno and
    next_coalesced_allocno containing more one allocno.  */
 static int allocno_coalesced_p;
@@ -110,27 +115,33 @@ static int allocno_coalesced_p;
    coalescing.  */
 static bitmap processed_coalesced_allocno_bitmap;
 
-/* All allocnos sorted accoring their priorities.  */
+/* All allocnos sorted according their priorities.  */
 static allocno_t *sorted_allocnos;
 
 /* Array used to sort allocnos to choose an allocno for spilling.  */
 static allocno_t *sorted_allocnos_for_spilling;
 
+/* Varray representing the stack of allocnos used during coloring.  */
+static varray_type allocno_stack_varray;
+
 
 
-/* This page contains function to choose hard register for allocnos.  */
+/* This page contains functions used to choose hard registers for
+   allocnos.  */
 
 /* Array whose element value is TRUE if the corresponding hard
-   register already allocated for a allocno.  */
+   register was already allocated for an allocno.  */
 static int allocated_hardreg_p [FIRST_PSEUDO_REGISTER];
 
-/* Array used to check already processed allocanos during the current
+/* Array used to check already processed allocnos during the current
    update_copy_costs call.  */
 static int *allocno_update_cost_check;
+
 /* The current value of update_copy_cost call count.  */
 static int update_cost_check;
 
-/* Allocate and initialize data necessary for update_copy_costs.  */
+/* Allocate and initialize data necessary for function
+   update_copy_costs.  */
 static void
 initiate_cost_update (void)
 {
@@ -139,15 +150,17 @@ initiate_cost_update (void)
   update_cost_check = 0;
 }
 
-/* Deallocate data used by update_copy_costs.  */
+/* Deallocate data used by function update_copy_costs.  */
 static void
 finish_cost_update (void)
 {
   ira_free (allocno_update_cost_check);
 }
 
-/* The function updates costs (decrease if DECR_P) of the allocnos
-   connected by copies with ALLOCNO.  */
+/* This recursive function updates costs (decrease if DECR_P) of the
+   unassigned allocnos connected by copies with ALLOCNO.  This update
+   increases chances to remove some copies.  Copy cost is proportional
+   the copy frequency divided by DIVISOR.  */
 static void
 update_copy_costs_1 (allocno_t allocno, int hard_regno,
 		     int decr_p, int divisor)
@@ -212,6 +225,8 @@ update_copy_costs_1 (allocno_t allocno, 
     }
 }
 
+/* Entry function to update costs of allocnos to increase chances to
+   remove some copies as the result of subsequent assignment.  */
 static void
 update_copy_costs (allocno_t allocno, int decr_p)
 {
@@ -219,8 +234,8 @@ update_copy_costs (allocno_t allocno, in
   update_copy_costs_1 (allocno, ALLOCNO_HARD_REGNO (allocno), decr_p, 1);
 }
 
-/* The function is used to sort allocnos according to the profit to
-   use a hard register instead of memory for them. */
+/* The function is used to sort allocnos according to the profit of
+   usage of a hard register instead of memory for them. */
 static int
 allocno_cost_compare_func (const void *v1p, const void *v2p)
 {
@@ -232,8 +247,8 @@ allocno_cost_compare_func (const void *v
   if (c1 - c2)
     return c1 - c2;
 
-  /* If regs are equally good, sort by allocnos, so that the results of
-     qsort leave nothing to chance.  */
+  /* If regs are equally good, sort by allocno numbers, so that the
+     results of qsort leave nothing to chance.  */
   return ALLOCNO_NUM (p1) - ALLOCNO_NUM (p2);
 }
 
@@ -253,12 +268,13 @@ print_coalesced_allocno (allocno_t alloc
     }
 }
 
-/* Varray representing the stack of allocnos used during coloring.  */
-static varray_type allocno_stack_varray;
-
-/* Function choosing a hard register for ALLOCNO.  If RETRY_P is
-   nonzero, it means that the function called from
-   `reassign_pseudos'. */
+/* Function choosing a hard register for ALLOCNO (or for all coalesced
+   allocnos represented by ALLOCNO).  If RETRY_P is TRUE, it means
+   that the function called from function `reassign_conflict_allocnos'
+   and `allocno_reload_assign'.  The function implements the
+   optimistic coalescing too: if we failed to assign a hard register
+   to set of the coalesced allocnos, we put them onto the coloring
+   stack for subsequent separate assigning.  */
 static int
 assign_hard_reg (allocno_t allocno, int retry_p)
 {
@@ -317,6 +333,7 @@ assign_hard_reg (allocno_t allocno, int 
 	    costs [i] += cost;
 	    full_costs [i] += cost;
 	  }
+      /* Take preferences of conflicting allocnos into account.  */
       FOR_EACH_ALLOCNO_CONFLICT (a, conflict_allocno, aci)
 	/* Reload can give another class so we need to check all
 	   allocnos.  */
@@ -363,6 +380,7 @@ assign_hard_reg (allocno_t allocno, int 
       if (a == allocno)
 	break;
     }
+  /* Take copies into account.  */
   for (a = ALLOCNO_NEXT_COALESCED_ALLOCNO (allocno);;
        a = ALLOCNO_NEXT_COALESCED_ALLOCNO (a))
     {
@@ -398,8 +416,8 @@ assign_hard_reg (allocno_t allocno, int 
     }
   min_cost = min_full_cost = INT_MAX;
   /* We don't care about giving callee saved registers to allocnos no
-     living through calls because call used register are allocated
-     first (it is usual practice to put them first in
+     living through calls because call clobbered registers are
+     allocated first (it is usual practice to put them first in
      REG_ALLOC_ORDER).  */
   for (i = 0; i < class_size; i++)
     {
@@ -417,8 +435,8 @@ assign_hard_reg (allocno_t allocno, int 
       full_cost = full_costs [i];
       if (! allocated_hardreg_p [hard_regno]
 	  && hard_reg_not_in_set_p (hard_regno, mode, call_used_reg_set))
-	/* We need to save/restore the register in epilogue/prologue.
-	   Therefore we increase the cost.  */
+	/* We need to save/restore the hard register in
+	   epilogue/prologue.  Therefore we increase the cost.  */
 	{
 	  /* ??? If only part is call clobbered.  */
 	  class = REGNO_REG_CLASS (hard_regno);
@@ -475,8 +493,8 @@ assign_hard_reg (allocno_t allocno, int 
       ALLOCNO_ASSIGNED_P (a) = TRUE;
       if (best_hard_regno >= 0)
 	update_copy_costs (a, TRUE);
-      /* We don't need updated costs anymore: */
       ira_assert (ALLOCNO_COVER_CLASS (a) == cover_class);
+      /* We don't need updated costs anymore: */
       free_allocno_updated_costs (a);
       if (a == allocno)
 	break;
@@ -486,16 +504,16 @@ assign_hard_reg (allocno_t allocno, int 
 
 
 
-/* This page contains allocator based on Chaitin algorithm.  */
+/* This page contains allocator based on Chaitin-Briggs algorithm.  */
 
-/* Bucket of allocnos allocno be colored currently without spilling.  */
+/* Bucket of allocnos that can colored currently without spilling.  */
 static allocno_t colorable_allocno_bucket;
 
-/* Bucket of allocnos allocno might be not colored currently without
+/* Bucket of allocnos that might be not colored currently without
    spilling.  */
 static allocno_t uncolorable_allocno_bucket;
 
-/* Add ALLOCNO to *BUCKET_PTR bucket.  ALLOCNO should be not in a bucket
+/* Add ALLOCNO to bucket *BUCKET_PTR.  ALLOCNO should be not in a bucket
    before the call.  */
 static void
 add_allocno_to_bucket (allocno_t allocno, allocno_t *bucket_ptr)
@@ -554,7 +572,7 @@ bucket_allocno_compare_func (const void 
   return ALLOCNO_NUM (a2) - ALLOCNO_NUM (a1);
 }
 
-/* Function sorts a given bucket and returns the result through
+/* Function sorts bucket *BUCKET_PTR and returns the result through
    BUCKET_PTR.  */
 static void
 sort_bucket (allocno_t *bucket_ptr)
@@ -580,7 +598,7 @@ sort_bucket (allocno_t *bucket_ptr)
   *bucket_ptr = head;
 }
 
-/* Add ALLOCNO to *BUCKET_PTR bucket maintaining the order according
+/* Add ALLOCNO to bucket *BUCKET_PTR maintaining the order according
    their priority.  ALLOCNO should be not in a bucket before the
    call.  */
 static void
@@ -603,7 +621,7 @@ add_allocno_to_ordered_bucket (allocno_t
     ALLOCNO_PREV_BUCKET_ALLOCNO (before) = allocno;
 }
 
-/* Delete ALLOCNO from *BUCKET_PTR bucket.  It should be there before
+/* Delete ALLOCNO from bucket *BUCKET_PTR.  It should be there before
    the call.  */
 static void
 delete_allocno_from_bucket (allocno_t allocno, allocno_t *bucket_ptr)
@@ -624,8 +642,9 @@ delete_allocno_from_bucket (allocno_t al
 }
 
 /* The function puts ALLOCNO onto the coloring stack without removing
-   it from the bucket.  Such action can result in moving conflicting
-   allocnos from the uncolorable bucket to the colorable one.  */
+   it from its bucket.  Pushing allocno to the coloring stack can
+   result in moving conflicting allocnos from the uncolorable bucket
+   to the colorable one.  */
 static void
 push_allocno_to_stack (allocno_t allocno)
 {
@@ -688,8 +707,8 @@ push_allocno_to_stack (allocno_t allocno
 }
 
 /* The function puts ALLOCNO onto the coloring stack and removes it
-   from the bucket.  The allocno is in the colorable bucket if
-   COLORABLE_P is nonzero.  */
+   from its bucket.  The allocno is in the colorable bucket if
+   COLORABLE_P is TRUE.  */
 static void
 remove_allocno_from_bucket_and_push (allocno_t allocno, int colorable_p)
 {
@@ -742,7 +761,7 @@ push_allocno_to_spill (allocno_t allocno
   push_allocno_to_stack (allocno);
 }
 
-/* The function returns frequency of exit edges (if EXIT_P) or enter
+/* The function returns frequency of exit edges (if EXIT_P) or entry
    from/to the loop given by its LOOP_NODE.  */ 
 int
 loop_edge_freq (loop_tree_node_t loop_node, int regno, int exit_p)
@@ -943,7 +962,8 @@ push_allocnos_to_stack (void)
     }
 }
 
-/* Assign hard registers to allocnos on the coloring stack.  */
+/* Pop the coloring stack and assign hard registers to the popped
+   allocnos.  */
 static void
 pop_allocnos_from_stack (void)
 {
@@ -1126,7 +1146,7 @@ put_allocno_into_bucket (allocno_t alloc
     add_allocno_to_bucket (allocno, &uncolorable_allocno_bucket);
 }
 
-/* The function is used to sort allocnos according to their
+/* The function is used to sort allocnos according to their execution
    frequencies.  */
 static int
 copy_freq_compare_func (const void *v1p, const void *v2p)
@@ -1144,8 +1164,9 @@ copy_freq_compare_func (const void *v1p,
   return cp1->num - cp2->num;
 }
 
-/* The function merges two sets of coalesced allocnos given by
-   allocnos A1 and A2 (more accurately merging A2 into A1).  */
+/* The function merges two sets of coalesced allocnos given
+   correspondingly by allocnos A1 and A2 (more accurately merging A2
+   set into A1 set).  */
 static void
 merge_allocnos (allocno_t a1, allocno_t a2)
 {
@@ -1167,9 +1188,12 @@ merge_allocnos (allocno_t a1, allocno_t 
   ALLOCNO_NEXT_COALESCED_ALLOCNO (last) = next;
 }
 
-/* The function returns non-zero if there are conflicting allocnos
-   from two sets of coalesced allocnos given by allocnos A1 and A2.
-   If RELOAD_P is true, we use live ranges to find conflicts.  */
+/* The function returns TRUE if there are conflicting allocnos from
+   two sets of coalesced allocnos given correspondingly by allocnos
+   A1 and A2.  If RELOAD_P is TRUE, we use live ranges to find
+   conflicts because conflicts are represented only for allocnos of
+   the same cover class and during the reload pass we coalesce
+   allocnos for sharing stack memory slots.  */
 static int
 coalesced_allocno_conflict_p (allocno_t a1, allocno_t a2, int reload_p)
 {
@@ -1217,8 +1241,10 @@ coalesced_allocno_conflict_p (allocno_t 
   return FALSE;
 }
 
-/* The major function for aggressive coalescing.  For the reload
-   (RELOAD_P) we coalesce only spilled allocnos.  */
+/* The major function for aggressive allocno coalescing.  For the
+   reload pass (RELOAD_P) we coalesce only spilled allocnos.  If some
+   allocnos have been coalesced, we set up flag
+   allocno_coalesced_p.  */
 static void
 coalesce_allocnos (int reload_p)
 {
@@ -1232,8 +1258,7 @@ coalesce_allocnos (int reload_p)
 
   sorted_copies = ira_allocate (copies_num * sizeof (copy_t));
   cp_num = 0;
-  /* Collect copies.  We can not use copies for this because some
-     copies are actually removed.  */
+  /* Collect copies.  */
   EXECUTE_IF_SET_IN_BITMAP (coloring_allocno_bitmap, 0, j, bi)
     {
       a = allocnos [j];
@@ -1273,6 +1298,7 @@ coalesce_allocnos (int reload_p)
 	}
     }
   qsort (sorted_copies, cp_num, sizeof (copy_t), copy_freq_compare_func);
+  /* Coalesced copies, most frequently executed first.  */
   for (; cp_num != 0;)
     {
       for (i = 0; i < cp_num; i++)
@@ -1293,6 +1319,7 @@ coalesce_allocnos (int reload_p)
 	      break;
 	    }
 	}
+      /* Collect the rest of copies.  */
       for (n = 0; i < cp_num; i++)
 	{
 	  cp = sorted_copies [i];
@@ -1395,9 +1422,10 @@ print_loop_title (loop_tree_node_t loop_
   fprintf (ira_dump_file, "\n");
 }
 
-/* The function implements Chaitin-Briggs coloring for allocnos inside
-   loop (in extreme case it can be all function) given by the
-   corresponding LOOP_TREE_NODE.  */
+/* The function does coloring for allocnos inside loop (in extreme
+   case it can be all function) given by the corresponding
+   LOOP_TREE_NODE.  The function is called for each loop during
+   top-down traverse of the loop tree.  */
 static void
 color_pass (loop_tree_node_t loop_tree_node)
 {
@@ -1425,10 +1453,10 @@ color_pass (loop_tree_node_t loop_tree_n
 	continue;
       bitmap_clear_bit (coloring_allocno_bitmap, ALLOCNO_NUM (a));
     }
-  /* Color all mentioned including transparent.  */
+  /* Color all mentioned allocnos including transparent ones.  */
   color_allocnos ();
-  /* Update costs for subloops.  */
-  for (subloop_node = loop_tree_node->inner;
+  /* Update costs of the corresponding allocnos in the subloops.  */
+  for (subloop_node = loop_tree_node->children;
        subloop_node != NULL;
        subloop_node = subloop_node->next)
     if (subloop_node->bb == NULL)
@@ -1563,57 +1591,8 @@ color_pass (loop_tree_node_t loop_tree_n
 	}
 }
 
-/* Map: allocno number -> allocno prioirity.  */
-static int *allocno_priorities;
-
-/* Allocate array ALLOCNO_PRIORITIES and set up priorities for N allocnos in
-   array CONSIDERATION_ALLOCNOS.  */
-static void
-start_allocno_priorities (allocno_t *consideration_allocnos, int n)
-{
-  int i, length;
-  allocno_t a;
-  allocno_live_range_t r;
-
-  for (i = 0; i < n; i++)
-    {
-      a = consideration_allocnos [i];
-      for (length = 0, r = ALLOCNO_LIVE_RANGES (a); r != NULL; r = r->next)
-	length += r->finish - r->start + 1;
-      if (length == 0)
-	{
-	  allocno_priorities [ALLOCNO_NUM (a)] = 0;
-	  continue;
-	}
-      ira_assert (length > 0 && ALLOCNO_NREFS (a) > 0);
-      allocno_priorities [ALLOCNO_NUM (a)]
-	= (((double) (floor_log2 (ALLOCNO_NREFS (a)) * ALLOCNO_FREQ (a))
-	    / length)
-	   * (10000 / REG_FREQ_MAX) * PSEUDO_REGNO_SIZE (ALLOCNO_REGNO (a)));
-    }
-}
-
-/* The function is used to sort allocnos according to their priorities
-   which are calculated analogous to ones in file `global.c'.  */
-static int
-allocno_priority_compare_func (const void *v1p, const void *v2p)
-{
-  allocno_t a1 = *(const allocno_t *) v1p, a2 = *(const allocno_t *) v2p;
-  int pri1, pri2;
-
-  pri1 = allocno_priorities [ALLOCNO_NUM (a1)];
-  pri2 = allocno_priorities [ALLOCNO_NUM (a2)];
-  if (pri2 - pri1)
-    return pri2 - pri1;
-
-  /* If regs are equally good, sort by allocnos, so that the results of
-     qsort leave nothing to chance.  */
-  return ALLOCNO_NUM (a1) - ALLOCNO_NUM (a2);
-}
-
-/* The function initialized common data for cloring and calls
-   functions to do Chaitin-Briggs, regional, and Chow's priority-based
-   coloring.  */
+/* The function initialized common data for coloring and calls
+   functions to do Chaitin-Briggs and regional coloring.  */
 static void
 do_coloring (void)
 {
@@ -1632,10 +1611,11 @@ do_coloring (void)
 
 
 
-/* The functions moves future spill/restore code to less frequent
-   points (if it is profitable) by reassigning some allocnos to memory
-   which means make longer live-range where the corresponding
-   pseudo-registers will be in memory.  */
+/* The functions moves spill/restore code, which are to be generated
+   in ira-emit.c, to less frequent points (if it is profitable) by
+   reassigning some allocnos (in loop with subloops containing in
+   another loop) to memory which results in longer live-range where
+   the corresponding pseudo-registers will be in memory.  */
 static void
 move_spill_restore (void)
 {
@@ -1658,10 +1638,11 @@ move_spill_restore (void)
 	  loop_node = ALLOCNO_LOOP_TREE_NODE (a);
 	  if (ALLOCNO_CAP_MEMBER (a) != NULL
 	      || (hard_regno = ALLOCNO_HARD_REGNO (a)) < 0
-	      || loop_node->inner == NULL
+	      || loop_node->children == NULL
 	      /* don't do the optimization because it can create
-		 copies and reload can spill an allocno set by copy
-		 although the allocno will not get memory slot.  */
+		 copies and the reload pass can spill the allocno set
+		 by copy although the allocno will not get memory
+		 slot.  */
 	      || reg_equiv_invariant_p [regno]
 	      || reg_equiv_const [regno] != NULL_RTX)
 	    continue;
@@ -1673,7 +1654,7 @@ move_spill_restore (void)
 		  - (ALLOCNO_HARD_REG_COSTS (a) == NULL
 		     ? ALLOCNO_COVER_CLASS_COST (a)
 		     : ALLOCNO_HARD_REG_COSTS (a) [index]));
-	  for (subloop_node = loop_node->inner;
+	  for (subloop_node = loop_node->children;
 	       subloop_node != NULL;
 	       subloop_node = subloop_node->next)
 	    {
@@ -1682,7 +1663,7 @@ move_spill_restore (void)
 	      subloop_allocno = subloop_node->regno_allocno_map [regno];
 	      if (subloop_allocno == NULL)
 		continue;
-	      /* We have accumulated cost.  To get a real cost of
+	      /* We have accumulated cost.  To get the real cost of
 		 allocno usage in the loop we should subtract costs of
 		 the subloop allocnos.  */
 	      cost -= (ALLOCNO_MEMORY_COST (subloop_allocno)
@@ -1741,10 +1722,11 @@ move_spill_restore (void)
 
 
 
-/* Set up current hard reg costs and current conflict hard reg costs
-   for allocno A.  */
+/* Update current hard reg costs and current conflict hard reg costs
+   for allocno A.  It is done by processing its copies containing
+   other allocnos already assigned.  */
 static void
-setup_curr_costs (allocno_t a)
+update_curr_costs (allocno_t a)
 {
   int i, hard_regno, cost;
   enum machine_mode mode;
@@ -1793,12 +1775,63 @@ setup_curr_costs (allocno_t a)
     }
 }
 
-/* Try to assign hard registers to the unassigned allocnos and allocnos
-   conflicting with them or conflicting with allocnos whose regno >=
-   START_REGNO.  We only try to assign a hard register to allocnos
-   which do not live across calls if NO_CALL_CROSS_P.  */
+/* Map: allocno number -> allocno priority.  */
+static int *allocno_priorities;
+
+/* Allocate array ALLOCNO_PRIORITIES and set up priorities for N allocnos in
+   array CONSIDERATION_ALLOCNOS.  */
+static void
+start_allocno_priorities (allocno_t *consideration_allocnos, int n)
+{
+  int i, length;
+  allocno_t a;
+  allocno_live_range_t r;
+
+  for (i = 0; i < n; i++)
+    {
+      a = consideration_allocnos [i];
+      for (length = 0, r = ALLOCNO_LIVE_RANGES (a); r != NULL; r = r->next)
+	length += r->finish - r->start + 1;
+      if (length == 0)
+	{
+	  allocno_priorities [ALLOCNO_NUM (a)] = 0;
+	  continue;
+	}
+      ira_assert (length > 0 && ALLOCNO_NREFS (a) > 0);
+      allocno_priorities [ALLOCNO_NUM (a)]
+	= (((double) (floor_log2 (ALLOCNO_NREFS (a)) * ALLOCNO_FREQ (a))
+	    / length)
+	   * (10000 / REG_FREQ_MAX) * PSEUDO_REGNO_SIZE (ALLOCNO_REGNO (a)));
+    }
+}
+
+/* The function is used to sort allocnos according to their priorities
+   which are calculated analogous to ones in file `global.c'.  */
+static int
+allocno_priority_compare_func (const void *v1p, const void *v2p)
+{
+  allocno_t a1 = *(const allocno_t *) v1p, a2 = *(const allocno_t *) v2p;
+  int pri1, pri2;
+
+  pri1 = allocno_priorities [ALLOCNO_NUM (a1)];
+  pri2 = allocno_priorities [ALLOCNO_NUM (a2)];
+  if (pri2 - pri1)
+    return pri2 - pri1;
+
+  /* If regs are equally good, sort by allocnos, so that the results of
+     qsort leave nothing to chance.  */
+  return ALLOCNO_NUM (a1) - ALLOCNO_NUM (a2);
+}
+
+/* Try to assign hard registers to the unassigned allocnos and
+   allocnos conflicting with them or conflicting with allocnos whose
+   regno >= START_REGNO.  The function is called after spill/restore
+   placement optimization and ira_flattening, so more allocnos
+   (including ones created in ira-emit.c) will have a chance to get a
+   hard register.  We use simple assignment algorithm based on
+   priorities.  */
 void
-reassign_conflict_allocnos (int start_regno, int no_call_cross_p)
+reassign_conflict_allocnos (int start_regno)
 {
   int i, allocnos_to_color_num;
   allocno_t a, conflict_a;
@@ -1814,8 +1847,7 @@ reassign_conflict_allocnos (int start_re
       if (! ALLOCNO_ASSIGNED_P (a)
 	  && ! bitmap_bit_p (allocnos_to_color, ALLOCNO_NUM (a)))
 	{
-	  if (ALLOCNO_COVER_CLASS (a) != NO_REGS
-	      && (! no_call_cross_p || ALLOCNO_CALLS_CROSSED_NUM (a) == 0))
+	  if (ALLOCNO_COVER_CLASS (a) != NO_REGS)
 	    sorted_allocnos [allocnos_to_color_num++] = a;
 	  else
 	    {
@@ -1832,8 +1864,7 @@ reassign_conflict_allocnos (int start_re
       FOR_EACH_ALLOCNO_CONFLICT (a, conflict_a, aci)
 	{
 	  ira_assert (cover_class == ALLOCNO_COVER_CLASS (conflict_a));
-	  if ((no_call_cross_p  && ALLOCNO_CALLS_CROSSED_NUM (conflict_a) != 0)
-	      || bitmap_bit_p (allocnos_to_color, ALLOCNO_NUM (conflict_a)))
+	  if (bitmap_bit_p (allocnos_to_color, ALLOCNO_NUM (conflict_a)))
 	    continue;
 	  bitmap_set_bit (allocnos_to_color, ALLOCNO_NUM (conflict_a));
 	  sorted_allocnos [allocnos_to_color_num++] = conflict_a;
@@ -1852,7 +1883,7 @@ reassign_conflict_allocnos (int start_re
       ALLOCNO_ASSIGNED_P (a) = FALSE;
       ira_assert (ALLOCNO_UPDATED_HARD_REG_COSTS (a) == NULL);
       ira_assert (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) == NULL);
-      setup_curr_costs (a);
+      update_curr_costs (a);
     }
   for (i = 0; i < allocnos_to_color_num; i++)
     {
@@ -1870,14 +1901,21 @@ reassign_conflict_allocnos (int start_re
 
 
 
+/* This page contains code to coalesce memory stack slots used by
+   spilled allocnos.  This results in smaller stack frame, better data
+   locality, and in smaller code for some architectures like
+   x86/x86_64 where insn size depends on address displacement value.
+   On the other hand, it can worsen insn scheduling after the RA but
+   in practice it is less important than smaller stack frames.  */
+
 /* Usage cost and order number of coalesced allocno set to which
    given pseudo register belongs to.  */
 static int *regno_coalesced_allocno_cost;
 static int *regno_coalesced_allocno_num;
 
 /* The function is used to sort pseudos according frequencies of
-   coalesced allocnos they belong to (putting most frequently ones
-   first), and according to coalesced allocno numbers.  */
+   coalesced allocno sets they belong to (putting most frequently ones
+   first), and according to coalesced allocno set order numbers.  */
 static int
 coalesced_pseudo_reg_freq_compare (const void *v1p, const void *v2p)
 {
@@ -1931,8 +1969,8 @@ coalesced_pseudo_reg_slot_compare (const
 }
 
 /* Setup REGNO_COALESCED_ALLOCNO_COST and REGNO_COALESCED_ALLOCNO_NUM
-   for allocnos represented by their regnos given in array
-   PSEUDO_REGNOS of length N.  */
+   for coalesced allocno sets containing allocnos with their regnos
+   given in array PSEUDO_REGNOS of length N.  */
 static void
 setup_coalesced_allocno_costs_and_nums (int *pseudo_regnos, int n)
 {
@@ -1971,10 +2009,11 @@ setup_coalesced_allocno_costs_and_nums (
 }
 
 /* The function collects spilled allocnos representing coalesced
-   allocnos (the first coalseced allocno) in array
-   SPILLED_COALESCED_ALLOCNOS and returns the number of the collected
-   allocnos.  The allocnos are given by their regnos in array
-   PSEUDO_REGNOS of length N.  */
+   allocno sets (the first coalesced allocno).  The collected allocnos
+   are returned through array SPILLED_COALESCED_ALLOCNOS.  The
+   function returns the number of the collected allocnos.  The
+   allocnos are given by their regnos in array PSEUDO_REGNOS of length
+   N.  */
 static int
 collect_spilled_coalesced_allocnos (int *pseudo_regnos, int n,
 				    allocno_t *spilled_coalesced_allocnos)
@@ -1994,9 +2033,11 @@ collect_spilled_coalesced_allocnos (int 
   return num;
 }
 
-/* Coalesce allocnos whose in array SPILLED_COALESCED_ALLOCNOS of
-   length NUM.  Return TRUE if some allocnos were really
-   coalesced.  */
+/* We have coalesced allocnos involving in copies.  This function
+   coalesces allocnos further in order to share the same memory stack
+   slot.  Allocnos representing sets of allocnos coalesced before the
+   call are given in array SPILLED_COALESCED_ALLOCNOS of length NUM.
+   Return TRUE if some allocnos were coalesced in the function.  */
 static int
 coalesce_spill_slots (allocno_t *spilled_coalesced_allocnos, int num)
 {
@@ -2004,7 +2045,6 @@ coalesce_spill_slots (allocno_t *spilled
   allocno_t allocno, a;
   int merged_p = FALSE;
 
-  /* Further coalescing spilled allocnos.  */
   /* Coalesce non-conflicting spilled allocnos preferring most
      frequently used.  */
   for (i = 0; i < num; i++)
@@ -2040,7 +2080,9 @@ coalesce_spill_slots (allocno_t *spilled
 
 /* The function sorts pseudo-register numbers in array PSEUDO_REGNOS
    of length N for subsequent assigning stack slots to them in the
-   reload.  */
+   reload pass.  To do this we coalesce spilled allocnos first to
+   decrease the number of memory-memory move insns.  This function is
+   called by the reload.  */
 void
 sort_regnos_for_alter_reg (int *pseudo_regnos, int n,
 			   unsigned int *reg_max_ref_width)
@@ -2070,11 +2112,12 @@ sort_regnos_for_alter_reg (int *pseudo_r
   memset (regno_coalesced_allocno_num, 0, max_regno * sizeof (int));
   setup_coalesced_allocno_costs_and_nums (pseudo_regnos, n);
   /* Sort regnos according frequencies of the corresponding coalesced
-     allocnos.  */
+     allocno sets.  */
   qsort (pseudo_regnos, n, sizeof (int), coalesced_pseudo_reg_freq_compare);
   spilled_coalesced_allocnos
     = ira_allocate (allocnos_num * sizeof (allocno_t));
-  /* Collect allocnos representing spilled coalesced allocnos.  */
+  /* Collect allocnos representing the spilled coalesced allocno
+     sets.  */
   num = collect_spilled_coalesced_allocnos (pseudo_regnos, n,
 					    spilled_coalesced_allocnos);
   if (flag_ira_share_spill_slots
@@ -2087,7 +2130,7 @@ sort_regnos_for_alter_reg (int *pseudo_r
     }
   ira_free_bitmap (processed_coalesced_allocno_bitmap);
   allocno_coalesced_p = FALSE;
-  /* Assign stack slot numbers to spilled allocnos, use smaller
+  /* Assign stack slot numbers to spilled allocno sets, use smaller
      numbers for most frequently used coalesced allocnos.  -1 is
      reserved for dynamic search of stack slots for pseudos spilled by
      the reload.  */
@@ -2127,7 +2170,7 @@ sort_regnos_for_alter_reg (int *pseudo_r
   regno_max_ref_width = reg_max_ref_width;
   qsort (pseudo_regnos, n, sizeof (int), coalesced_pseudo_reg_slot_compare);
   /* Uncoalesce allocnos which is necessary for (re)assigning during
-     the reload.  */
+     the reload pass.  */
   FOR_EACH_ALLOCNO (a, ai)
     {
       ALLOCNO_FIRST_COALESCED_ALLOCNO (a) = a;
@@ -2139,8 +2182,12 @@ sort_regnos_for_alter_reg (int *pseudo_r
 
 
 
-/* The function called from the reload to mark changes in the
-   allocation of REGNO made by the reload.  */
+/* This page contains code used by the reload pass to improve the
+   final code.  */
+
+/* The function is called from the reload pass to mark changes in the
+   allocation of REGNO made by the reload.  Remember that reg_renumber
+   reflects the change result.  */
 void
 mark_allocation_change (int regno)
 {
@@ -2179,12 +2226,15 @@ mark_allocation_change (int regno)
       update_copy_costs (a, TRUE);
     }
   else
-    /* Reload chages class of the allocno.  */
+    /* Reload changed class of the allocno.  */
     cost = 0;
   overall_cost += cost;
 }
 
-/* This function is called when the reload deletes memory-memory move.  */
+/* This function is called when the reload deletes memory-memory move.
+   In this case we marks that the allocation of the corresponding
+   allocnos should be not changed in future.  Otherwise we risk to get
+   a wrong code.  */
 void
 mark_memory_move_deletion (int dst_regno, int src_regno)
 {
@@ -2200,7 +2250,7 @@ mark_memory_move_deletion (int dst_regno
 
 /* The function tries to assign a hard register (except for
    FORBIDDEN_REGS) to allocno A and return TRUE in the case of
-   success.  */
+   success.  That is an analog of retry_global_alloc for IRA.  */
 static int
 allocno_reload_assign (allocno_t a, HARD_REG_SET forbidden_regs)
 {
@@ -2215,7 +2265,7 @@ allocno_reload_assign (allocno_t a, HARD
   ira_assert (ALLOCNO_UPDATED_HARD_REG_COSTS (a) == NULL);
   ira_assert (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) == NULL);
   cover_class = ALLOCNO_COVER_CLASS (a);
-  setup_curr_costs (a);
+  update_curr_costs (a);
   assign_hard_reg (a, TRUE);
   hard_regno = ALLOCNO_HARD_REGNO (a);
   reg_renumber [regno] = hard_regno;
@@ -2239,8 +2289,9 @@ allocno_reload_assign (allocno_t a, HARD
 	}
     }
 
-  /* If we found a register, modify the RTL for the register to show
-     the hard register, and mark that register live.  */
+  /* If we found a hard register, modify the RTL for the pseudo
+     register to show the hard register, and mark the pseudo register
+     live.  */
   if (reg_renumber[regno] >= 0)
     {
       if (internal_flag_ira_verbose > 3 && ira_dump_file != NULL)
@@ -2272,8 +2323,10 @@ pseudo_reg_compare (const void *v1p, con
    SPILLED_PSEUDO_REGS (there are NUM of them) or spilled pseudos
    conflicting with pseudos in SPILLED_PSEUDO_REGS.  It returns TRUE
    and update SPILLED, if the allocation has been changed.  The
-   function doesn't use BAD_SPILL_REGS and corresponding hard
-   registers in PSEUDO_FORBIDDEN_REGS and PSEUDO_PREVIOUS_REGS.  */
+   function doesn't use BAD_SPILL_REGS and hard registers in
+   PSEUDO_FORBIDDEN_REGS and PSEUDO_PREVIOUS_REGS for the
+   corresponding pseudos.  The function is called by the reload pass
+   at the end of each reload iteration.  */
 int
 reassign_pseudos (int *spilled_pseudo_regs, int num,
 		  HARD_REG_SET bad_spill_regs,
@@ -2288,6 +2341,8 @@ reassign_pseudos (int *spilled_pseudo_re
   if (num > 1)
     qsort (spilled_pseudo_regs, num, sizeof (int), pseudo_reg_compare);
   changed_p = FALSE;
+  /* Try to assign hard registers to pseudos from
+     SPILLED_PSEUDO_REGS.  */
   for (m = i = 0; i < num; i++)
     {
       regno = spilled_pseudo_regs [i];
@@ -2321,6 +2376,8 @@ reassign_pseudos (int *spilled_pseudo_re
 	fprintf (ira_dump_file, " %d", spilled_pseudo_regs [i]);
       fprintf (ira_dump_file, "\n");
     }
+  /* Try to assign hard registers to pseudos conflicting with ones
+     from SPILLED_PSEUDO_REGS.  */
   for (i = n = 0; i < m; i++)
     {
       regno = spilled_pseudo_regs [i];
@@ -2364,11 +2421,10 @@ reassign_pseudos (int *spilled_pseudo_re
   return changed_p;
 }
 
-
-
-/* The function called by the reload returns already allocated stack
-   slot (if any) for REGNO with given INHERENT_SIZE and
-   TOTAL_SIZE.  */
+/* The function is called by the reload pass and returns already
+   allocated stack slot (if any) for REGNO with given INHERENT_SIZE
+   and TOTAL_SIZE.  In the case of failure to find a slot which can be
+   used for REGNO, the function returns NULL.  */
 rtx
 reuse_stack_slot (int regno, unsigned int inherent_size,
 		  unsigned int total_size)
@@ -2397,8 +2453,8 @@ reuse_stack_slot (int regno, unsigned in
     {
       best_cost = best_slot_num = -1;
       x = NULL_RTX;
-      /* It means that the pseudo was spilled by the reload, try to
-	 reuse a slot.  */
+      /* It means that the pseudo was spilled in the reload pass, try
+	 to reuse a slot.  */
       for (slot_num = 0; slot_num < spilled_reg_stack_slots_num; slot_num++)
 	{
 	  slot = &spilled_reg_stack_slots [slot_num];
@@ -2478,8 +2534,9 @@ reuse_stack_slot (int regno, unsigned in
   return x;
 }
 
-/* The function called by the reload when a new stack slot X with
-   TOTAL_SIZE was allocated for REGNO.  */
+/* The function is called by the reload pass every time when a new
+   stack slot X with TOTAL_SIZE was allocated for REGNO.  We store
+   this info for subsequent reuse_stack_slot calls.  */
 void
 mark_new_stack_slot (rtx x, int regno, unsigned int total_size)
 {
@@ -2507,11 +2564,11 @@ mark_new_stack_slot (rtx x, int regno, u
 
 
 /* Return spill cost for pseudo-registers whose numbers are in array
-   regnos (end marker is a negative number) for reload with given IN
-   and OUT for INSN.  Return also number points (through
+   REGNOS (with a negative number as an end marker) for reload with
+   given IN and OUT for INSN.  Return also number points (through
    EXCESS_PRESSURE_LIVE_LENGTH) where the pseudo-register lives and
    the register pressure is high, number of references of the
-   pesudo-registers (through NREFS), number of call used
+   pseudo-registers (through NREFS), number of callee-clobbered
    hard-registers occupied by the pseudo-registers (through
    CALL_USED_COUNT), and the first hard regno occupied by the
    pseudo-registers (through FIRST_HARD_REGNO).  */
@@ -2570,8 +2627,10 @@ calculate_spill_cost (int *regnos, rtx i
 }
 
 /* Return TRUE if spilling pseudo-registers whose numbers are in array
-   REGNOS is better spilling pseudo-registers with numbers in
-   OTHER_REGNOS for reload with given IN and OUT for INSN. */
+   REGNOS is better than spilling pseudo-registers with numbers in
+   OTHER_REGNOS for reload with given IN and OUT for INSN.  The
+   function used by the reload pass to make better register spilling
+   decisions.  */
 int
 better_spill_reload_regno_p (int *regnos, int *other_regnos,
 			     rtx in, rtx out, rtx insn)
@@ -2606,7 +2665,9 @@ better_spill_reload_regno_p (int *regnos
 
 
 /* The function returns (through CALL_CLOBBERED_REGS) hard registers
-   changed by all function calls in REGNO live range.  */
+   changed by all function calls inside REGNO live range.  The
+   function is used to improve code for saving/restore callee-clobbered
+   hard registers around calls (see caller-saves.c).  */
 void
 collect_pseudo_call_clobbered_regs (int regno,
 				    HARD_REG_SET (*call_clobbered_regs))
Index: global.c
===================================================================
--- global.c	(revision 133412)
+++ global.c	(working copy)
@@ -1378,6 +1378,7 @@ mark_elimination (int from, int to)
 
   FOR_EACH_BB (bb)
     {
+      /* We don't use LIVE info in IRA.  */
       regset r = (flag_ira ? DF_LR_IN (bb) : DF_LIVE_IN (bb));
       if (REGNO_REG_SET_P (r, from))
 	{
@@ -1452,6 +1453,9 @@ build_insn_chain (void)
 
       EXECUTE_IF_SET_IN_BITMAP (df_get_live_out (bb), FIRST_PSEUDO_REGISTER, i, bi)
 	{
+	  /* Consider spilled pseudos too for IRA because they still
+	     have a chance to get hard-registers in the reload when
+	     IRA is used.  */
 	  if (reg_renumber[i] >= 0 || flag_ira)
 	    bitmap_set_bit (live_relevant_regs, i);
 	}
@@ -1489,6 +1493,10 @@ build_insn_chain (void)
 			    if (!fixed_regs[regno])
 			      bitmap_set_bit (&c->dead_or_set, regno);
 			  }
+			/* Consider spilled pseudos too for IRA
+			   because they still have a chance to get
+			   hard-registers in the reload when IRA is
+			   used.  */
 			else if (reg_renumber[regno] >= 0 || flag_ira)
 			  bitmap_set_bit (&c->dead_or_set, regno);
 		      }
@@ -1590,11 +1598,19 @@ build_insn_chain (void)
 			    if (!fixed_regs[regno])
 			      bitmap_set_bit (&c->dead_or_set, regno);
 			  }
+			/* Consider spilled pseudos too for IRA
+			   because they still have a chance to get
+			   hard-registers in the reload when IRA is
+			   used.  */
 			else if (reg_renumber[regno] >= 0 || flag_ira)
 			  bitmap_set_bit (&c->dead_or_set, regno);
 		      }
 		    
 		    if (regno < FIRST_PSEUDO_REGISTER
+			/* Consider spilled pseudos too for IRA
+			   because they still have a chance to get
+			   hard-registers in the reload when IRA is
+			   used.  */
 			|| reg_renumber[regno] >= 0 || flag_ira)
 		      {
 			if (GET_CODE (reg) == SUBREG
Index: ira-lives.c
===================================================================
--- ira-lives.c	(revision 133412)
+++ ira-lives.c	(working copy)
@@ -1,4 +1,4 @@
-/* IRA processing allocno lives.
+/* IRA processing allocno lives to build allocno live ranges.
    Copyright (C) 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
@@ -38,11 +38,14 @@ Software Foundation, 51 Franklin Street,
 #include "df.h"
 #include "ira-int.h"
 
-/* The file contains code is analogous to one in global but the code
-   works on the allocno basis.  */
+/* The code in this file is similar to one in global but the code
+   works on the allocno basis and creates live ranges instead of
+   pseudo-register conflicts.  */
 
 static void make_regno_born (int);
 static void update_allocno_pressure_excess_length (allocno_t);
+static void make_regno_dead (int);
+static void make_regno_born_and_dead (int);
 static void set_allocno_live (allocno_t);
 static void clear_allocno_live (allocno_t);
 static void mark_reg_store (rtx, const_rtx, void *);
@@ -53,9 +56,15 @@ static enum reg_class single_reg_class (
 static enum reg_class single_reg_operand_class (int);
 static void process_single_reg_class_operands (int, int);
 static void process_bb_node_lives (loop_tree_node_t);
-
-/* Program points are enumerated by number from range
-   0..MAX_POINT-1.  */
+static void create_start_finish_chains (void);
+static void print_allocno_live_ranges (FILE *, allocno_t);
+static void print_live_ranges (FILE *);
+
+/* Program points are enumerated by number from range 0..MAX_POINT-1.
+   There are approximately tow times more program points than insns.
+   One program points correspond points between subsequent insns and
+   other ones correspond to points after usage of input operands but
+   before setting the output operands in insns.  */
 int max_point;
 
 /* Arrays of size MAX_POINT mapping a program point to the allocno
@@ -65,11 +74,16 @@ allocno_live_range_t *start_point_ranges
 /* Number of the current program point.  */
 static int curr_point;
 
-/* Point where register pressure excess started of -1 if there is no
-   register pressure excess.  */
+/* Point where register pressure excess started or -1 if there is no
+   register pressure excess.  Excess pressure for a register class at
+   some point means that there are more allocnos of given register
+   class living at the point than number of hard-registers of the
+   class available for the allocation.  It is defined only for cover
+   classes.  */
 static int high_pressure_start_point [N_REG_CLASSES];
 
-/* Number of ints required to hold allocnos_num bits.  */
+/* Number of ints of type INT_TYPE required to hold allocnos_num
+   bits.  */
 int allocno_set_words;
 
 /* Set, clear or test bit number I in `allocnos_live',
@@ -78,22 +92,22 @@ int allocno_set_words;
 #define CLEAR_ALLOCNO_LIVE(I) CLEAR_ALLOCNO_SET_BIT (allocnos_live, I)
 #define TEST_ALLOCNO_LIVE(I) TEST_ALLOCNO_SET_BIT (allocnos_live, I)
 
-/* Bit mask for allocnos live at current point in the scan.  */
+/* Bit vector for allocnos live at current point in the scan.  */
 static INT_TYPE *allocnos_live;
 
-/* The same as previous but as bitmap.  */
+/* The same as previous but as a bitmap.  */
 static bitmap allocnos_live_bitmap;
 
-/* Set of hard regs (except eliminable ones) currently live (during
-   scan of all insns).  */
+/* Set of hard regs (except eliminable ones) currently live.  */
 static HARD_REG_SET hard_regs_live;
 
-/* Loop tree node corresponding to the current basic block.  */
+/* The loop tree node corresponding to the current basic block.  */
 static loop_tree_node_t curr_bb_node;
 
 /* The function processing birth of register REGNO.  It updates living
    hard regs and conflict hard regs for living allocnos or starts a
-   new live range for allocno corresponding to REGNO.  */
+   new live range for the allocno corresponding to REGNO if it is
+   necessary.  */
 static void
 make_regno_born (int regno)
 {
@@ -141,7 +155,7 @@ update_allocno_pressure_excess_length (a
 }
 
 /* The function processing death of register REGNO.  It updates live
-   hard regs or finish the current live range for allocno
+   hard regs or finish the current live range for the allocno
    corresponding to REGNO.  */
 static void
 make_regno_dead (int regno)
@@ -166,16 +180,20 @@ make_regno_dead (int regno)
 /* The function processing birth and, right after then, death of
    register REGNO.  */
 static void
-make_regno_born_and_died (int regno)
+make_regno_born_and_dead (int regno)
 {
   make_regno_born (regno);
   make_regno_dead (regno);
 }
 
-/* The current pressure for the current basic block.  */
+/* The current register pressures for each cover class for the current
+   basic block.  */
 static int curr_reg_pressure [N_REG_CLASSES];
 
-/* The function marks allocno A as currently living.  */
+/* The function marks allocno A as currently living and updates
+   current register pressure, maximal register pressure for the
+   current BB, start point of the register pressure excess, and
+   conflicting hard registers of A.  */
 static void
 set_allocno_live (allocno_t a)
 {
@@ -199,7 +217,10 @@ set_allocno_live (allocno_t a)
     curr_bb_node->reg_pressure [cover_class] = curr_reg_pressure [cover_class];
 }
 
-/* The function marks allocno A as currently not living.  */
+/* The function marks allocno A as currently not living and updates
+   current register pressure, start point of the register pressure
+   excess, and register pressure excess length for living
+   allocnos.  */
 static void
 clear_allocno_live (allocno_t a)
 {
@@ -233,11 +254,10 @@ clear_allocno_live (allocno_t a)
 static VEC(rtx, heap) *regs_set;
 
 /* Handle the case where REG is set by the insn being scanned, during
-   the scan to accumulate conflicts.  Store a 1 in hard_regs_live or
-   allocnos_live for this register or the
-   corresponding allocno, record how many consecutive hardware
-   registers it actually needs, and record a conflict with all other
-   reg allocnos already live.
+   the scan to build live ranges and calculate reg pressure info.
+   Store a 1 in hard_regs_live or allocnos_live for this register or
+   the corresponding allocno, record how many consecutive hardware
+   registers it actually needs.
 
    Note that even if REG does not remain alive after this insn, we
    must mark it here as live, to ensure a conflict between REG and any
@@ -312,9 +332,10 @@ mark_reg_clobber (rtx reg, const_rtx set
     mark_reg_store (reg, setter, data);
 }
 
-/* Record that REG (or the corresponding allocno) has conflicts with
-   all the allocno currently live.  Do not mark REG (or the allocno)
-   itself as live.  */
+/* Record that hard register REG (if it is a hard register) has
+   conflicts with all the allocno currently live or the corresponding
+   allocno lives at just the current program point.  Do not mark REG
+   (or the allocno) itself as live.  */
 static void
 mark_reg_conflicts (rtx reg)
 {
@@ -329,14 +350,14 @@ mark_reg_conflicts (rtx reg)
   regno = REGNO (reg);
 
   if (regno >= FIRST_PSEUDO_REGISTER)
-    make_regno_born_and_died (regno);
+    make_regno_born_and_dead (regno);
   else if (! TEST_HARD_REG_BIT (no_alloc_regs, regno))
     {
       int last = regno + hard_regno_nregs [regno] [GET_MODE (reg)];
 
       while (regno < last)
 	{
-	  make_regno_born_and_died (regno);
+	  make_regno_born_and_dead (regno);
 	  regno++;
 	}
     }
@@ -344,7 +365,7 @@ mark_reg_conflicts (rtx reg)
 
 /* Mark REG (or the corresponding allocno) as being dead (following
    the insn being scanned now).  Store a 0 in hard_regs_live or
-   allocnos_live for this register.  */
+   allocnos_live for the register.  */
 static void
 mark_reg_death (rtx reg)
 {
@@ -395,9 +416,7 @@ mark_reg_death (rtx reg)
 
 /* The function checks that CONSTRAINTS permits to use only one hard
    register.  If it is so, the function returns the class of the hard
-   register.  Otherwise it returns NO_REGS.
-
-   EQUIV_COSNT ??? */
+   register.  Otherwise it returns NO_REGS.  */
 static enum reg_class
 single_reg_class (const char *constraints, rtx op, rtx equiv_const)
 {
@@ -539,10 +558,10 @@ single_reg_operand_class (int op_num)
 			   recog_data.operand [op_num], NULL_RTX);
 }
 
-/* The function processes input (if IN_P) or output operands of insn
-   with FREQ to find allocno which can use only one hard register and
-   makes other currently living reg allocnos conflicting with the hard
-   register.  */
+/* The function processes input operands, if IN_P, or output operands
+   otherwise of the current insn with FREQ to find allocno which can
+   use only one hard register and makes other currently living
+   allocnos conflicting with the hard register.  */
 static void
 process_single_reg_class_operands (int in_p, int freq)
 {
@@ -617,7 +636,10 @@ process_single_reg_class_operands (int i
 }
 
 /* The function processes insns of the basic block given by its
-   LOOP_TREE_NODE to update allocno conflict table.  */
+   LOOP_TREE_NODE to update allocno live ranges, allocno hard register
+   conflicts, intersected calls, and register pressure info for
+   allocnos for the basic block for and regions containing the basic
+   block.  */
 static void
 process_bb_node_lives (loop_tree_node_t loop_tree_node)
 {
@@ -645,7 +667,6 @@ process_bb_node_lives (loop_tree_node_t 
       memset (allocnos_live, 0, allocno_set_words * sizeof (INT_TYPE));
       REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_in);
       AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
-      /* ??? !!!! No alloc regs for pressure */
       AND_COMPL_HARD_REG_SET (hard_regs_live, no_alloc_regs);
       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
 	if (TEST_HARD_REG_BIT (hard_regs_live, i))
@@ -682,16 +703,16 @@ process_bb_node_lives (loop_tree_node_t 
 	      
 	      if (regno == INVALID_REGNUM)
 		break;
-	      make_regno_born_and_died (regno);
+	      make_regno_born_and_dead (regno);
 	    }
 	}
 #endif
       
-      /* Reg allocnos can't go in stack regs at the start of a basic block
+      /* Allocnos can't go in stack regs at the start of a basic block
 	 that is reached by an abnormal edge. Likewise for call
 	 clobbered regs, because caller-save, fixup_abnormal_edges and
 	 possibly the table driven EH machinery are not quite ready to
-	 handle such reg allocnos live across such edges.  */
+	 handle such allocnos live across such edges.  */
       FOR_EACH_EDGE (e, ei, bb->preds)
 	if (e->flags & EDGE_ABNORMAL)
 	  break;
@@ -705,7 +726,7 @@ process_bb_node_lives (loop_tree_node_t 
 	      ALLOCNO_TOTAL_NO_STACK_REG_P (allocnos [px]) = TRUE;
 	    }
 	  for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
-	    make_regno_born_and_died (px);
+	    make_regno_born_and_dead (px);
 #endif
 	  /* No need to record conflicts for call clobbered regs if we
 	     have nonlocal labels around, as we don't ever try to
@@ -713,12 +734,11 @@ process_bb_node_lives (loop_tree_node_t 
 	  if (! current_function_has_nonlocal_label)
 	    for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
 	      if (call_used_regs [px])
-		make_regno_born_and_died (px);
+		make_regno_born_and_dead (px);
 	}
   
       /* Scan the code of this basic block, noting which allocnos and
-	 hard regs are born or die.  When one is born, record a
-	 conflict with all others currently live.  */
+	 hard regs are born or die.  */
       FOR_BB_INSNS (bb, insn)
 	{
 	  rtx link;
@@ -752,6 +772,7 @@ process_bb_node_lives (loop_tree_node_t 
 	      mark_reg_death (XEXP (link, 0));
 	  
 	  curr_point++;
+
 	  if (CALL_P (insn))
 	    {
 	      HARD_REG_SET clobbered_regs;
@@ -777,10 +798,9 @@ process_bb_node_lives (loop_tree_node_t 
 		}
 	    }
 	  
-	  /* Mark any allocnos set in INSN as live, and mark them as
-	     conflicting with all other live reg allocnos.  Clobbers are
-	     processed again, so they conflict with the reg allocnos that
-	     are set.  */
+	  /* Mark any allocnos set in INSN as live.  Clobbers are
+	     processed again, so they will conflict with the reg
+	     allocnos that are set.  */
 	  note_stores (PATTERN (insn), mark_reg_store, NULL);
 	  
 #ifdef AUTO_INC_DEC
@@ -839,9 +859,11 @@ process_bb_node_lives (loop_tree_node_t 
        {
 	 make_regno_dead (ALLOCNO_REGNO (allocnos [i]));
        }
+
       curr_point++;
+
     }
-  /* Propagate register pressure: */
+  /* Propagate register pressure to upper loop tree nodes: */
   if (loop_tree_node != ira_loop_tree_root)
     for (i = 0; i < reg_class_cover_size; i++)
       {
@@ -855,6 +877,8 @@ process_bb_node_lives (loop_tree_node_t 
       }
 }
 
+/* The function creates and sets up START_POINT_RANGES and
+   FINISH_POINT_RANGES.  */
 static void
 create_start_finish_chains (void)
 {
@@ -880,6 +904,9 @@ create_start_finish_chains (void)
     }
 }
 
+/* The function is used to rebuild START_POINT_RANGES and
+   FINISH_POINT_RANGES after new live ranges and program points were
+   added as a result if new insn generation.  */
 void
 rebuild_start_finish_chains (void)
 {
@@ -888,6 +915,7 @@ rebuild_start_finish_chains (void)
   create_start_finish_chains ();
 }
 
+/* The function prints live ranges R to file F.  */
 void
 print_live_range_list (FILE *f, allocno_live_range_t r)
 {
@@ -896,12 +924,14 @@ print_live_range_list (FILE *f, allocno_
   fprintf (f, "\n");
 }
 
+/* The function prints live ranges R to stderr.  */
 void
 debug_live_range_list (allocno_live_range_t r)
 {
   print_live_range_list (stderr, r);
 }
 
+/* The function prints live ranges of allocno A to file F.  */
 static void
 print_allocno_live_ranges (FILE *f, allocno_t a)
 {
@@ -909,12 +939,14 @@ print_allocno_live_ranges (FILE *f, allo
   print_live_range_list (f, ALLOCNO_LIVE_RANGES (a));
 }
 
+/* The function prints live ranges of allocno A to stderr.  */
 void
 debug_allocno_live_ranges (allocno_t a)
 {
   print_allocno_live_ranges (stderr, a);
 }
 
+/* The function prints live ranges of all allocnos to file F.  */
 static void
 print_live_ranges (FILE *f)
 {
@@ -925,16 +957,16 @@ print_live_ranges (FILE *f)
     print_allocno_live_ranges (f, a);
 }
 
+/* The function prints live ranges of all allocnos to stderr.  */
 void
 debug_live_ranges (void)
 {
   print_live_ranges (stderr);
 }
 
-/* The function creates live ranges, set up CONFLICT_HARD_REGS and
-   TOTAL_CONFLICT_HARD_REGS for allocnos.  It also modifies hard reg
-   costs for allocnos whose hard register is actually fixed in an
-   insn.  */
+/* The main entry function creates live ranges, set up
+   CONFLICT_HARD_REGS and TOTAL_CONFLICT_HARD_REGS for allocnos, and
+   calculate register pressure info.  */
 void
 create_allocno_live_ranges (void)
 {
@@ -955,6 +987,8 @@ create_allocno_live_ranges (void)
   ira_free (allocnos_live);
 }
 
+/* The function frees arrays START_POINT_RANGES and
+   FINISH_POINT_RANGES.  */
 void
 finish_allocno_live_ranges (void)
 {
Index: regmove.c
===================================================================
--- regmove.c	(revision 133412)
+++ regmove.c	(working copy)
@@ -1118,8 +1118,8 @@ regmove_optimize (rtx f, int nregs)
 
   for (pass = 0; pass <= 2; pass++)
     {
-      if ((! flag_regmove || flag_ira)
-	  && pass >= flag_expensive_optimizations)
+      /* We need fewer optimizations for IRA.  */
+      if ((! flag_regmove || flag_ira) && pass >= flag_expensive_optimizations)
 	goto done;
 
       if (dump_file)
@@ -1167,6 +1167,8 @@ regmove_optimize (rtx f, int nregs)
 		    }
 		}
 	    }
+
+	  /* All optimizations important for IRA have been done.  */
 	  if (! flag_regmove || flag_ira)
 	    continue;
 
Index: function.c
===================================================================
--- function.c	(revision 133412)
+++ function.c	(working copy)
@@ -5603,7 +5603,7 @@ get_call_invalidated_used_regs (const_rt
   node = decl == NULL ? NULL : cgraph_node (decl);
   if (! flag_ira || ! flag_ira_ipra || node == NULL
       /* This is a call of the function itself.  We don't know used
-	 register yet.  So take the worst case.  */
+	 registers yet.  So take the worst case.  */
       || node->decl == cfun->decl)
     {
       if (clobbered_p)
Index: ira-emit.c
===================================================================
--- ira-emit.c	(revision 133412)
+++ ira-emit.c	(working copy)
@@ -45,7 +45,37 @@ Software Foundation, 51 Franklin Street,
 #include "df.h"
 #include "ira-int.h"
 
-struct move;
+
+/* The structure represents an allocno move.  The both allocnos have
+   the same origional regno but different allocation.  */
+struct move
+{
+  /* The allocnos involved in the move.  */
+  allocno_t from, to;
+  /* The next move in the move sequence.  */
+  struct move *next;
+  /* Used for finding dependencies.  */
+  int visited_p;
+  /* The size of the following array. */
+  int deps_num;
+  /* Moves on which given move depends on.  Dependency can be cyclic.
+     It means we need a temporary to generates the moves.  Sequence
+     A1->A2, B1->B2 where A1 and B2 are assigned to reg R1 and A2 and
+     B1 are assigned to reg R2 is an example of the cyclic
+     dependencies.  */
+  struct move **deps;
+  /* First insn generated for the move.  */
+  rtx insn;
+};
+
+/* Array of moves (indexed by BB index) which should be put at the
+   start/end of the corresponding basic blocks.  */
+static struct move **at_bb_start, **at_bb_end;
+
+/* Max regno before renaming some pseudo-registers.  For example, the
+   same pseudo-register can be renamed in a loop if its allocation is
+   different outside the loop.  */
+static int max_regno_before_changing;
 
 static struct move *create_move (allocno_t, allocno_t);
 static void free_move (struct move *);
@@ -72,33 +102,6 @@ static void add_range_and_copies_from_mo
 						 bitmap, int);
 static void add_ranges_and_copies (void);
 
-/* The structure represents allocno shuffling.  */
-struct move
-{
-  /* The shuffled allocnos.  */
-  allocno_t from, to;
-  /* The next move in the sequence.  */
-  struct move *next;
-  /* Use for finding dependencies.  */
-  int visited_p;
-  /* The size of the following array. */
-  int deps_num;
-  /* Moves on which given move depends on.  Dependency can be cyclic.
-     It means we need a temporary to generates the moves.  */
-  struct move **deps;
-  /* First insn generated for the move.  */
-  rtx insn;
-};
-
-/* Array of moves (indexed by BB index) which should be put at the
-   start/end of the corresponding blocks.  */
-static struct move **at_bb_start, **at_bb_end;
-
-/* Max regno before renaming some pseudo-registers.  For example, the
-   same pseudo-register can be renamed in loop if its allocation is
-   different outside the loop.  */
-static int max_regno_before_changing;
-
 /* The function returns new move of allocnos TO and FROM.  */
 static struct move *
 create_move (allocno_t to, allocno_t from)
@@ -140,7 +143,7 @@ free_move_list (struct move *head)
 }
 
 /* The function returns nonzero if the the move list LIST1 and LIST2
-   are equal (two moves are equal if they shuffles the same
+   are equal (two moves are equal if they involve the same
    allocnos).  */
 static int
 eq_move_lists_p (struct move *list1, struct move *list2)
@@ -153,30 +156,29 @@ eq_move_lists_p (struct move *list1, str
 }
 
 /* This recursive function changes pseudo-registers in *LOC if it is
-   necessary.  The function returns non-zero if a change was done.  */
+   necessary.  The function returns TRUE if a change was done.  */
 static int
 change_regs (rtx *loc)
 {
-  int i, regno, result = 0;
+  int i, regno, result = FALSE;
   const char *fmt;
   enum rtx_code code;
 
   if (*loc == NULL_RTX)
-    return 0;
+    return FALSE;
   code = GET_CODE (*loc);
   if (code == REG)
     {
       regno = REGNO (*loc);
       if (regno < FIRST_PSEUDO_REGISTER)
-	return 0;
+	return FALSE;
       if (regno >= max_regno_before_changing)
 	/* It is a shared register which was changed already.  */
-	return 0;
-      /* ??? That is for reg_equal.  */
-      if (ira_curr_loop_tree_node->regno_allocno_map [regno] == NULL)
-	return 0;
-      *loc = ALLOCNO_REG (ira_curr_loop_tree_node->regno_allocno_map [regno]);
-      return 1;
+	return FALSE;
+      if (ira_curr_regno_allocno_map [regno] == NULL)
+	return FALSE;
+      *loc = ALLOCNO_REG (ira_curr_regno_allocno_map [regno]);
+      return TRUE;
     }
 
   fmt = GET_RTX_FORMAT (code);
@@ -234,7 +236,7 @@ create_new_reg (rtx original_reg)
   return new_reg;
 }
 
-/* The function returns non-zero if loop given by SUBNODE inside the
+/* The function returns TRUE if loop given by SUBNODE inside the
    loop given by NODE.  */
 static int
 subloop_tree_node_p (loop_tree_node_t subnode, loop_tree_node_t node)
@@ -245,7 +247,7 @@ subloop_tree_node_p (loop_tree_node_t su
   return FALSE;
 }
 
-/* The function sets up field `reg' to REG for allocnos which has the
+/* The function sets up member `reg' to REG for allocnos which has the
    same regno as ALLOCNO and which are inside the loop corresponding to
    ALLOCNO. */
 static void
@@ -277,8 +279,10 @@ set_allocno_reg (allocno_t allocno, rtx 
     }
 }
 
-/* The following function returns nonzero if move insn of SRC_ALLOCNO
-   to DEST_ALLOCNO does not change value of the destination.  */
+/* The following function returns TRUE if move of SRC_ALLOCNO to
+   DEST_ALLOCNO does not change value of the destination.  One possible
+   reason for this is the situation when SRC_ALLOCNO is not modified
+   in the corresponding loop.  */
 static int
 not_modified_p (allocno_t src_allocno, allocno_t dest_allocno)
 {
@@ -302,7 +306,7 @@ not_modified_p (allocno_t src_allocno, a
 
 /* The function generates and attaches moves to the edge E.  It looks
    at the final regnos of allocnos living on the edge with the same
-   original regno to find what moves should be generated.  */
+   original regno to figure out when moves should be generated.  */
 static void
 generate_edge_moves (edge e)
 {
@@ -351,13 +355,14 @@ generate_edge_moves (edge e)
 /* Bitmap of allocnos local for the current loop.  */
 static bitmap local_allocno_bitmap;
 
-/* This bitmap is used to find that we need to generate and use a new
-   pseudo-register when processing allocnos with the same original
+/* This bitmap is used to find that we need to generate and to use a
+   new pseudo-register when processing allocnos with the same original
    regno.  */
 static bitmap used_regno_bitmap;
 
 /* This bitmap contains regnos of allocnos which were renamed locally
-   because the allocnos correspond to disjoint live ranges.  */
+   because the allocnos correspond to disjoint live ranges in loops
+   with a common parent.  */
 static bitmap renamed_regno_bitmap;
 
 /* The following function changes (if necessary) pseudo-registers
@@ -402,12 +407,12 @@ change_loop (loop_tree_node_t node)
 	  cover_class = ALLOCNO_COVER_CLASS (allocno);
 	  father_allocno = map [regno];
 	  ira_assert (regno < reg_equiv_len);
-	  /* We generate the same register move because the reload can
-	     put a allocno into memory in this case we will have live
-	     range splitting.  If it does not happen such the same
-	     hard register moves will be removed.  The worst case when
-	     the both allocnos are put into memory by the reload is
-	     very rare.  */
+	  /* We generate the same hard register move because the
+	     reload pass can put an allocno into memory in this case
+	     we will have live range splitting.  If it does not happen
+	     such the same hard register moves will be removed.  The
+	     worst case when the both allocnos are put into memory by
+	     the reload is very rare.  */
 	  if (father_allocno != NULL
 	      && (ALLOCNO_HARD_REGNO (allocno)
 		  == ALLOCNO_HARD_REGNO (father_allocno))
@@ -457,7 +462,7 @@ change_loop (loop_tree_node_t node)
     }
 }
 
-/* The function sets up flag somewhere_renamed_p.  */
+/* The function processes to set up flag somewhere_renamed_p.  */
 static void
 set_allocno_somewhere_renamed_p (void)
 {
@@ -474,8 +479,8 @@ set_allocno_somewhere_renamed_p (void)
     }
 }
 
-/* The function returns nonzero if move lists on all edges in vector
-   VEC are equal.  */
+/* The function returns nonzero if move lists on all edges given in
+   vector VEC are equal.  */
 static int
 eq_edge_move_lists_p (VEC(edge,gc) *vec)
 {
@@ -489,10 +494,10 @@ eq_edge_move_lists_p (VEC(edge,gc) *vec)
   return TRUE;
 }
 
-/* The function looks at all enter edges (if START_P) or exit edges of
+/* The function looks at all entry edges (if START_P) or exit edges of
    basic block BB and puts move lists at the BB start or end if it is
    possible.  In other words, it decreases code duplication of
-   shuffling allocnos.  */
+   allocno moves.  */
 static void
 unify_moves (basic_block bb, int start_p)
 {
@@ -546,8 +551,8 @@ static varray_type move_varray;
    `allocno_last_set_check'.  */
 static int curr_tick;
 
-/* This recursive function traverses dependecies of MOVE and do
-   toplogical sorting (in depth-first order).  */
+/* This recursive function traverses dependencies of MOVE and produces
+   topological sorting (in depth-first order).  */
 static void
 traverse_moves (struct move *move)
 {
@@ -641,7 +646,8 @@ modify_move_list (struct move *list)
 		set_move = hard_regno_last_set [hard_regno + i];
 		/* It does not matter what loop_tree_node (of TO or
 		   FROM) to use for the new allocno because of
-		   subsequent IR flattening.  */
+		   subsequent IRA internal representation
+		   flattening.  */
 		new_allocno
 		  = create_allocno (ALLOCNO_REGNO (set_move->to), FALSE,
 				    ALLOCNO_LOOP_TREE_NODE (set_move->to));
@@ -682,8 +688,8 @@ modify_move_list (struct move *list)
   return first;
 }
 
-/* The function generates rtx move insns from the move list LIST.  It
-   updates allocation cost using move execution frequency FERQ.  */
+/* The function generates RTX move insns from the move list LIST.  It
+   updates allocation cost using move execution frequency FREQ.  */
 static rtx
 emit_move_list (struct move *list, int freq)
 {
@@ -737,7 +743,7 @@ emit_move_list (struct move *list, int f
   return result;
 }
 
-/* The function generates rtx move insns from move lists attached to
+/* The function generates RTX move insns from move lists attached to
    basic blocks and edges.  */
 static void
 emit_moves (void)
@@ -793,8 +799,9 @@ emit_moves (void)
     }
 }
 
-/* Update costs of A and its parents from reading (if READ_P) or
-   writing A on an execution path with FREQ.  */
+/* Update costs of A and corresponding allocnos on upper levels on the
+   loop tree from reading (if READ_P) or writing A on an execution
+   path with FREQ.  */
 static void
 update_costs (allocno_t a, int read_p, int freq)
 {
@@ -814,9 +821,9 @@ update_costs (allocno_t a, int read_p, i
 }
 
 /* The function processes moves from LIST with execution FREQ to add
-   ranges, copies, and modify costs.  All regnos living through the
-   list is in LIVE_THROUGH, and the loop tree node used to find
-   corresponding allocnos is NODE.  */
+   ranges, copies, and modify costs for allocnos involved in the
+   moves.  All regnos living through the list is in LIVE_THROUGH, and
+   the loop tree node used to find corresponding allocnos is NODE.  */
 static void
 add_range_and_copies_from_move_list (struct move *list, loop_tree_node_t node,
 				     bitmap live_through, int freq)
@@ -916,7 +923,7 @@ add_range_and_copies_from_move_list (str
 }
 
 /* The function processes all move list to add ranges, conflicts,
-   copies, and modify costs.  */
+   copies, and modify costs for allocnos involved in the moves.  */
 static void
 add_ranges_and_copies (void)
 {
@@ -950,8 +957,9 @@ add_ranges_and_copies (void)
   ira_free_bitmap (live_through);
 }
 
-/* Entry function changing code and generating allocno shuffling for
-   the regional (LOOPS_P is TRUE in this case) register allocation.  */
+/* The entry function changes code and generates shuffling allocnos on
+   region borders for the regional (LOOPS_P is TRUE in this case)
+   register allocation.  */
 void
 ira_emit (int loops_p)
 {
Index: alias.c
===================================================================
--- alias.c	(revision 133412)
+++ alias.c	(working copy)
@@ -2016,9 +2016,9 @@ nonoverlapping_memrefs_p (const_rtx x, c
 
   if (flag_ira && reload_completed)
     {
-      /* We need this code for IRA because stack slot sharing.  RTL in
-	 decl can be different than RTL used in insns.  It is safe
-	 code although it can be conservative sometime.  */
+      /* We need this code for IRA because of stack slot sharing.  RTL
+	 in decl can be different than RTL used in insns.  It is a
+	 safe code although it can be conservative sometime.  */
       x_addr = canon_rtx (get_addr (XEXP (x, 0)));
       y_addr = canon_rtx (get_addr (XEXP (y, 0)));
       
Index: ira-build.c
===================================================================
--- ira-build.c	(revision 133412)
+++ ira-build.c	(working copy)
@@ -1,4 +1,4 @@
-/* Building allocnos for IRA.
+/* Building internal representation for IRA.
    Copyright (C) 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
@@ -65,7 +65,6 @@ static void propagate_info_to_cap (alloc
 static allocno_live_range_t copy_allocno_live_range (allocno_live_range_t);
 static allocno_live_range_t
   copy_allocno_live_range_list (allocno_live_range_t);
-
 static void finish_allocno (allocno_t);
 static void finish_allocnos (void);
 
@@ -94,33 +93,41 @@ static void check_and_add_conflicts (all
 static void add_conflict_with_underlying_allocnos (allocno_t,
 						   loop_tree_node_t, int);
 
+
+
 /* The root of the loop tree corresponding to the all function.  */
 loop_tree_node_t ira_loop_tree_root;
 
 /* Height of the loop tree.  */
 int ira_loop_tree_height;
 
-/* All basic block data are referred through the following array.  We
-   can not use member `aux' for this because it is used for insertion
-   of insns on edges.  */
+/* All nodes representing basic blocks are referred through the
+   following array.  We can not use basic block member `aux' for this
+   because it is used for insertion of insns on edges.  */
 loop_tree_node_t ira_bb_nodes;
 
-/* All loop data are referred through the following array.  */
+/* All nodes representing loops are referred through the following
+   array.  */
 loop_tree_node_t ira_loop_nodes;
 
-/* Map regno -> allocnos.  */
+/* Map regno -> allocnos with given regno (see comments for 
+   allocno member `next_regno_allocno').  */
 allocno_t *regno_allocno_map;
 
-/* Array of references to all allocnos and their size.  The order
-   number of the allocno corresponds to the index in the array.
-   Removed allocnos have NULL element value.  */
+/* Array of references to all allocnos.  The order number of the
+   allocno corresponds to the index in the array.  Removed allocnos
+   have NULL element value.  */
 allocno_t *allocnos;
+
+/* Sizes of the previous array.  */
 int allocnos_num;
 
-/* Array of references to copies and its size.  The order number of
-   the copy corresponds to the index in the array.  Removed allocnos
-   have NULL element value.  */
+/* Array of references to all copies.  The order number of the copy
+   corresponds to the index in the array.  Removed copies have NULL
+   element value.  */
 copy_t *copies;
+
+/* Size of the previous array.  */
 int copies_num;
 
 
@@ -130,10 +137,10 @@ int copies_num;
    basic block.  */
 static int last_basic_block_before_change;
 
-/* The following function creates the loop tree nodes.  If LOOPS_P is
-   zero, the nodes corresponding to the loops (except the root which
-   corresponds the all function) will be not created (it will be done
-   only for basic blocks).  */
+/* The following function allocates the loop tree nodes.  If LOOPS_P
+   is FALSE, the nodes corresponding to the loops (except the root
+   which corresponds the all function) will be not allocated but nodes
+   will still be allocated for basic blocks.  */
 static void
 create_loop_tree_nodes (int loops_p)
 {
@@ -236,7 +243,7 @@ finish_loop_tree_nodes (void)
 
 
 
-/* The following recursive functions adds loop to the loop tree
+/* The following recursive function adds loop to the loop tree
    hierarchy.  The loop is added only once.  */
 static void
 add_loop_to_tree (struct loop *loop)
@@ -244,12 +251,13 @@ add_loop_to_tree (struct loop *loop)
   struct loop *father;
   loop_tree_node_t loop_node, father_node;
 
-  /* Can not use loop node access macros because of potential checking
-     and because the nodes are not initialized yet.  */
+  /* We can not use loop node access macros here because of potential
+     checking and because the nodes are not initialized enough
+     yet.  */
   if (loop_outer (loop) != NULL)
     add_loop_to_tree (loop_outer (loop));
   if (ira_loop_nodes [loop->num].regno_allocno_map != NULL
-      && ira_loop_nodes [loop->num].inner == NULL)
+      && ira_loop_nodes [loop->num].children == NULL)
     {
       /* We have not added loop node to the tree yet.  */
       loop_node = &ira_loop_nodes [loop->num];
@@ -268,15 +276,16 @@ add_loop_to_tree (struct loop *loop)
       else
 	{
 	  father_node = &ira_loop_nodes [father->num];
-	  loop_node->next = father_node->inner;
-	  father_node->inner = loop_node;
+	  loop_node->next = father_node->children;
+	  father_node->children = loop_node;
 	  loop_node->father = father_node;
 	}
     }
 }
 
-/* Enumerate loops in loop with root LOOP_NODE starting with LEVEL and
-   return maximal value of level in the tree + 1.  */
+/* The recursive function sets up levels of nodes of the tree given
+   its root LOOP_NODE.  The enumeration starts with LEVEL.  The
+   function returns maximal value of level in the tree + 1.  */
 static int
 setup_loop_tree_level (loop_tree_node_t loop_node, int level)
 {
@@ -286,7 +295,7 @@ setup_loop_tree_level (loop_tree_node_t 
   ira_assert (loop_node->bb == NULL);
   loop_node->level = level;
   max_height = level + 1;
-  for (subloop_node = loop_node->inner;
+  for (subloop_node = loop_node->children;
        subloop_node != NULL;
        subloop_node = subloop_node->next)
     if (subloop_node->bb == NULL)
@@ -299,8 +308,9 @@ setup_loop_tree_level (loop_tree_node_t 
 }
 
 /* The following function creates the loop tree.  The algorithm is
-   designed to provide correct order of loops (by the last loop BB)
-   and basic blocks in chain formed by next.  */
+   designed to provide correct order of loops (they are ordered by
+   their last loop BB) and basic blocks in the chain formed by member
+   next.  */
 static void
 form_loop_tree (void)
 {
@@ -310,17 +320,18 @@ form_loop_tree (void)
   loop_tree_node_t bb_node, loop_node;
   loop_p loop;
 
-  /* Can not use loop/bb node access macros because of potential
-     checking and the nodes are not initialized yet.  */
+  /* We can not use loop/bb node access macros because of potential
+     checking and because the nodes are not initialized enough
+     yet.  */
   for (i = 0; VEC_iterate (loop_p, ira_loops.larray, i, loop); i++)
      if (ira_loop_nodes [i].regno_allocno_map != NULL)
-       ira_loop_nodes [i].inner = NULL;
+       ira_loop_nodes [i].children = NULL;
   FOR_EACH_BB_REVERSE (bb)
     {
       bb_node = &ira_bb_nodes [bb->index];
       bb_node->bb = bb;
       bb_node->loop = NULL;
-      bb_node->inner = NULL;
+      bb_node->children = NULL;
       bb_node->next = NULL;
       for (father = bb->loop_father;
 	   father != NULL;
@@ -329,9 +340,9 @@ form_loop_tree (void)
 	  break;
       add_loop_to_tree (father);
       loop_node = &ira_loop_nodes [father->num];
-      bb_node->next = loop_node->inner;
+      bb_node->next = loop_node->children;
       bb_node->father = loop_node;
-      loop_node->inner = bb_node;
+      loop_node->children = bb_node;
     }
   ira_loop_tree_root = IRA_LOOP_NODE_BY_INDEX (ira_loops.tree_root->num);
   ira_loop_tree_height = setup_loop_tree_level (ira_loop_tree_root, 0);
@@ -341,7 +352,7 @@ form_loop_tree (void)
 
 
 /* The function rebuilds REGNO_ALLOCNO_MAP and REGNO_ALLOCNO_MAPs of
-   the loops using only allocno info.  */
+   the loops using.  */
 static void
 rebuild_regno_allocno_maps (void)
 {
@@ -368,6 +379,7 @@ rebuild_regno_allocno_maps (void)
   FOR_EACH_ALLOCNO (a, ai)
     {
       if (ALLOCNO_CAP_MEMBER (a) != NULL)
+	/* Caps are not in the regno allocno maps.  */
 	continue;
       regno = ALLOCNO_REGNO (a);
       loop_tree_node = ALLOCNO_LOOP_TREE_NODE (a);
@@ -382,14 +394,15 @@ rebuild_regno_allocno_maps (void)
 
 
 
-/* Array of vectors containing calls intersected by pseudo-registers.  */
+/* Array of vectors containing calls given pseudo-register lives
+   through.  */
 VEC(rtx, heap) **regno_calls;
 
 /* The length of the previous array.  */
 static int regno_calls_num;
 
 /* The function initializes array of vectors containing calls
-   intersected by pseudo-registers.  */
+   intersected by live ranges of pseudo-registers.  */
 static void
 initiate_calls (void)
 {
@@ -398,7 +411,7 @@ initiate_calls (void)
   memset (regno_calls, 0, regno_calls_num * sizeof (VEC(rtx, heap) *));
 }
 
-/* The function expands array of vectors containing calls for all
+/* The function expands array of the vectors containing calls for
    pseudo-registers.  */
 static void
 expand_calls (void)
@@ -416,7 +429,7 @@ expand_calls (void)
 }
 
 /* The function removes NULL elements from vectors containing calls
-   intersected by pseudo-registers.  */
+   intersected by live ranges of pseudo-registers.  */
 static void
 compress_calls (void)
 {
@@ -434,7 +447,8 @@ compress_calls (void)
     }
 }
 
-/* The function adds CALL to REGNO's vector of intersected calls.  */
+/* The function adds CALL to REGNO's vector of intersected calls and
+   returns the element index in the vector.  */
 int
 add_regno_call (int regno, rtx call)
 {
@@ -448,8 +462,8 @@ add_regno_call (int regno, rtx call)
   return result;
 }
 
-/* The function frees array of vectors containing calls
-   intersected by pseudo-registers.  */
+/* The function frees array of vectors containing calls intersected by
+   live ranges of pseudo-registers.  */
 static void
 finish_calls (void)
 {
@@ -487,7 +501,7 @@ initiate_allocnos (void)
 
 /* The function creates and returns allocno corresponding to REGNO in
    LOOP_TREE_NODE.  Add the allocno to the list of allocnos with the
-   same regno if ! CAP_P.  */
+   same regno if CAP_P is FALSE.  */
 allocno_t
 create_allocno (int regno, int cap_p, loop_tree_node_t loop_tree_node)
 {
@@ -502,7 +516,8 @@ create_allocno (int regno, int cap_p, lo
       regno_allocno_map [regno] = a;
       if (loop_tree_node->regno_allocno_map [regno] == NULL)
 	/* Remember that we can create temporary allocnos to break
-	   cycles in register shuffle.  */
+	   cycles in register shuffle on region borders (see
+	   ira-emit.c).  */
 	loop_tree_node->regno_allocno_map [regno] = a;
     }
   ALLOCNO_CAP (a) = NULL;
@@ -554,18 +569,18 @@ create_allocno (int regno, int cap_p, lo
   return a;
 }
 
-/* The function returns TRUE if conflict vector with NUM elemnents is
+/* The function returns TRUE if conflict vector with NUM elements is
    more profitable than conflict bit vector for A.  */
 int
 conflict_vector_profitable_p (allocno_t a ATTRIBUTE_UNUSED, int num)
 {
   int nw = (allocnos_num + INT_BITS - 1) / INT_BITS;
 
-  return sizeof (allocno_t) * num < 2 * nw * sizeof (INT_TYPE);
+  return sizeof (allocno_t) * (num + 1) < nw * sizeof (INT_TYPE);
 }
 
-/* The function allocates and initialize conflict vector of A for NUM
-   allocnos.  */
+/* The function allocates and initializes conflict vector of A for NUM
+   conflicting allocnos.  */
 void
 allocate_allocno_conflict_vec (allocno_t a, int num)
 {
@@ -597,7 +612,8 @@ allocate_allocno_conflict_bit_vec (alloc
 }
 
 /* The function allocates and initializes conflict vector or conflict
-   bit vector of A for NUM allocnos whatever is more profitable.  */
+   bit vector of A for NUM conflicting allocnos whatever is more
+   profitable.  */
 void
 allocate_allocno_conflicts (allocno_t a, int num)
 {
@@ -607,7 +623,7 @@ allocate_allocno_conflicts (allocno_t a,
     allocate_allocno_conflict_bit_vec (a);
 }
 
-/* The function adds A2 to to the conflicts of A1.  */
+/* The function adds A2 to the conflicts of A1.  */
 static void
 add_to_allocno_conflicts (allocno_t a1, allocno_t a2)
 {
@@ -619,7 +635,8 @@ add_to_allocno_conflicts (allocno_t a1, 
       allocno_t *vec;
 
       num = ALLOCNO_CONFLICT_ALLOCNOS_NUM (a1) + 2;
-      if (ALLOCNO_CONFLICT_ALLOCNO_ARRAY_SIZE (a1) >=  num * sizeof (allocno_t))
+      if (ALLOCNO_CONFLICT_ALLOCNO_ARRAY_SIZE (a1)
+	  >=  num * sizeof (allocno_t))
 	vec = ALLOCNO_CONFLICT_ALLOCNO_ARRAY (a1);
       else
 	{
@@ -661,7 +678,7 @@ add_to_allocno_conflicts (allocno_t a1, 
     }
 }
 
-/* The function adds A1 to conflict vector of A2 and vise versa.  */
+/* The function adds A1 to the conflicts of A2 and vise versa.  */
 void
 add_allocno_conflict (allocno_t a1, allocno_t a2)
 {
@@ -669,7 +686,8 @@ add_allocno_conflict (allocno_t a1, allo
   add_to_allocno_conflicts (a2, a1);
 }
 
-/* Remove conflicts of A which are wrong now.  */
+/* Remove conflicts of A which are wrong now.  Use allocno live ranges
+   for this, live ranges are always correct.  */
 static void
 remove_wrong_conflicts (allocno_t a)
 {
@@ -763,11 +781,12 @@ change_allocno_conflicts (allocno_t a, a
     }
 }
 
-/* The array used to find duplications in conflict vecs of
+/* The array used to find duplications in conflict vectors of
    allocnos.  */
 static int *allocno_conflict_check;
-/* The value used to mark allocation presence in conflict vec of the
-   current allocno.  */
+
+/* The value used to mark allocation presence in conflict vector of
+   the current allocno.  */
 static int curr_allocno_conflict_check_tick;
 
 /* The function removes duplications in conflict vector of A.  */
@@ -811,8 +830,8 @@ compress_conflict_vecs (void)
   ira_free (allocno_conflict_check);
 }
 
-/* This recursive function outputs allocno A and if it is cap the
-   function outputs members.  */
+/* This recursive function outputs allocno A and if it is a cap the
+   function outputs its members.  */
 void
 print_expanded_allocno (allocno_t a)
 {
@@ -843,7 +862,6 @@ create_cap_allocno (allocno_t a)
 	      && ALLOCNO_NEXT_COALESCED_ALLOCNO (a) == a);
   father = ALLOCNO_LOOP_TREE_NODE (a)->father;
   cap = create_allocno (ALLOCNO_REGNO (a), TRUE, father);
-  /* We just need to set a mode giving the same size.  */
   ALLOCNO_MODE (cap) = ALLOCNO_MODE (a);
   ALLOCNO_COVER_CLASS (cap) = ALLOCNO_COVER_CLASS (a);
   ALLOCNO_AVAILABLE_REGS_NUM (cap) = ALLOCNO_AVAILABLE_REGS_NUM (a);
@@ -851,7 +869,6 @@ create_cap_allocno (allocno_t a)
   bitmap_set_bit (father->mentioned_allocnos, ALLOCNO_NUM (cap));
   ALLOCNO_CAP (a) = cap;
   ALLOCNO_COVER_CLASS_COST (cap) = ALLOCNO_COVER_CLASS_COST (a);
-  /* ??? memory_cost */
   ALLOCNO_MEMORY_COST (cap) = ALLOCNO_MEMORY_COST (a);
   ALLOCNO_UPDATED_MEMORY_COST (cap) = ALLOCNO_UPDATED_MEMORY_COST (a);
   if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
@@ -863,8 +880,8 @@ create_cap_allocno (allocno_t a)
   return cap;
 }
 
-/* The function propagate info obtained during conflicts building to
-   CAP.  */
+/* The function propagates info to CAP from its member.  We propagate
+   info which is not available at the cap creation time.  */
 static void
 propagate_info_to_cap (allocno_t cap)
 {
@@ -922,9 +939,9 @@ propagate_info_to_cap (allocno_t cap)
       if (father_a != NULL
 	  && find_allocno_copy (cap, father_a,
 				cp->insn, cp->loop_tree_node) == NULL)
-	/* Upper level allocno might be not existing because it is
-	   not mentioned or lived on the border.  It is just
-	   living on bb start of the loop.  */
+	/* Upper level allocno might be not existing because it is not
+	   mentioned or lived on the region border.  It is just living
+	   on BB start of the loop.  */
 	add_allocno_copy (cap, father_a, cp->freq, cp->insn,
 			  cp->loop_tree_node);
     }
@@ -969,7 +986,7 @@ propagate_info_to_cap (allocno_t cap)
 }
 
 
-/* Create and return allocno live range with give attributes.  */
+/* Create and return allocno live range with given attributes.  */
 allocno_live_range_t
 create_allocno_live_range (allocno_t a, int start, int finish,
 			   allocno_live_range_t next)
@@ -984,8 +1001,8 @@ create_allocno_live_range (allocno_t a, 
   return p;
 }
 
-/* Create and return allocno live range with give attributes.  */
-allocno_live_range_t
+/* Copy allocno live range R and return the result.  */
+static allocno_live_range_t
 copy_allocno_live_range (allocno_live_range_t r)
 {
   allocno_live_range_t p;
@@ -995,8 +1012,9 @@ copy_allocno_live_range (allocno_live_ra
   return p;
 }
 
-/* Create and return allocno live range with give attributes.  */
-allocno_live_range_t
+/* Copy allocno live range list given by its head R and return the
+   result.  */
+static allocno_live_range_t
 copy_allocno_live_range_list (allocno_live_range_t r)
 {
   allocno_live_range_t p, first, last;
@@ -1022,6 +1040,7 @@ finish_allocno_live_range (allocno_live_
   pool_free (allocno_live_range_pool, r);
 }
 
+/* Free updated register costs of allocno A.  */
 void
 free_allocno_updated_costs (allocno_t a)
 {
@@ -1242,9 +1261,10 @@ swap_allocno_copy_ends_if_necessary (cop
   cp->next_second_allocno_copy = temp_cp;
 }
 
-/* The function creates (or updates frequency) and returns new copy of
-   allocnos FIRST and SECOND with frequency FREQ corresponding to move
-   insn INSN (if any) and originated from LOOP_TREE_NODE.  */
+/* The function creates (or updates frequency if the copy already
+   exists) and returns the copy of allocnos FIRST and SECOND with
+   frequency FREQ corresponding to move insn INSN (if any) and
+   originated from LOOP_TREE_NODE.  */
 copy_t
 add_allocno_copy (allocno_t first, allocno_t second, int freq, rtx insn,
 		  loop_tree_node_t loop_tree_node)
@@ -1263,7 +1283,7 @@ add_allocno_copy (allocno_t first, alloc
   return cp;
 }
 
-/* Print info about copies connecting allocno A into file F.  */
+/* Print info about copies involving allocno A into file F.  */
 static void
 print_allocno_copies (FILE *f, allocno_t a)
 {
@@ -1291,6 +1311,7 @@ print_allocno_copies (FILE *f, allocno_t
   fprintf (f, "\n");
 }
 
+/* Print info about copies involving allocno A into stderr.  */
 void
 debug_allocno_copies (allocno_t a)
 {
@@ -1320,7 +1341,7 @@ finish_copies (void)
 
 
 
-/* Pools for cost vectors.  */
+/* Pools for cost vectors.  It is defined only for cover classes.  */
 static alloc_pool cost_vector_pool [N_REG_CLASSES];
 
 /* The function initiates work with hard register cost vectors.  It
@@ -1336,7 +1357,7 @@ initiate_cost_vectors (void)
       cover_class = reg_class_cover [i];
       cost_vector_pool [cover_class]
 	= create_alloc_pool ("cost vectors",
-			     sizeof (int) * class_hard_regs_num [cover_class] + 32,
+			     sizeof (int) * class_hard_regs_num [cover_class],
 			     100);
     }
 }
@@ -1374,15 +1395,16 @@ finish_cost_vectors (void)
 
 
 
-/* The current loop tree node and its map.  */
+/* The current loop tree node and its regno allocno map.  */
 loop_tree_node_t ira_curr_loop_tree_node;
 allocno_t *ira_curr_regno_allocno_map;
 
-/* The recursive function traverses loop tree node with root LOOP_NODE
+/* The recursive function traverses loop tree with root LOOP_NODE
    calling non-null functions PREORDER_FUNC and POSTORDER_FUNC
    correspondingly in preorder and postorder.  The function sets up
-   IRA_CURR_LOOP_TREE_NODE.  If BB_FIRST_P, BB of LOOP_NODE is
-   processed before its subloops.  */
+   IRA_CURR_LOOP_TREE_NODE and IRA_CURR_REGNO_ALLOCNO_MAP.  If
+   BB_FIRST_P, basic block nodes of LOOP_NODE is processed before its
+   subloop nodes.  */
 void
 traverse_loop_tree (int bb_first_p, loop_tree_node_t loop_node,
 		    void (*preorder_func) (loop_tree_node_t),
@@ -1398,7 +1420,7 @@ traverse_loop_tree (int bb_first_p, loop
   if (preorder_func != NULL)
     (*preorder_func) (loop_node);
   
-  for (subloop_node = loop_node->inner;
+  for (subloop_node = loop_node->children;
        subloop_node != NULL;
        subloop_node = subloop_node->next)
     if (! bb_first_p || subloop_node->bb != NULL)
@@ -1411,7 +1433,7 @@ traverse_loop_tree (int bb_first_p, loop
       }
 
   if (bb_first_p)
-    for (subloop_node = loop_node->inner;
+    for (subloop_node = loop_node->children;
 	 subloop_node != NULL;
 	 subloop_node = subloop_node->next)
       if (subloop_node->bb == NULL)
@@ -1429,12 +1451,12 @@ traverse_loop_tree (int bb_first_p, loop
 
 
 
-/* The current basic block.  */
+/* The basic block currently being processed.  */
 static basic_block curr_bb;
 
 /* This recursive function creates allocnos corresponding to
    pseudo-registers containing in X.  Nonzero OUTPUT_P means that X is
-   lvalue.  */
+   a lvalue.  */
 static void
 create_insn_allocnos (rtx x, int output_p)
 {
@@ -1450,7 +1472,7 @@ create_insn_allocnos (rtx x, int output_
 	{
 	  allocno_t a;
 
-	  if ((a = ira_curr_loop_tree_node->regno_allocno_map [regno]) == NULL)
+	  if ((a = ira_curr_regno_allocno_map [regno]) == NULL)
 	    a = create_allocno (regno, FALSE, ira_curr_loop_tree_node);
 	  
 	  ALLOCNO_NREFS (a)++;
@@ -1498,8 +1520,8 @@ create_insn_allocnos (rtx x, int output_
 }
 
 /* The function creates allocnos corresponding to pseudo-registers
-   living in basic blocks represented by the corresponding loop tree
-   node BB_NODE.  */
+   living in the basic block represented by the corresponding loop
+   tree node BB_NODE.  */
 static void
 create_bb_allocnos (loop_tree_node_t bb_node)
 {
@@ -1507,7 +1529,6 @@ create_bb_allocnos (loop_tree_node_t bb_
   rtx insn;
   unsigned int i;
   bitmap_iterator bi;
-  allocno_t *map;
 
   curr_bb = bb = bb_node->bb;
   ira_assert (bb != NULL);
@@ -1516,39 +1537,37 @@ create_bb_allocnos (loop_tree_node_t bb_
       create_insn_allocnos (PATTERN (insn), FALSE);
   /* It might be a allocno living through from one subloop to
      another.  */
-  map = ira_curr_loop_tree_node->regno_allocno_map;
   EXECUTE_IF_SET_IN_REG_SET (DF_LR_IN (bb), FIRST_PSEUDO_REGISTER, i, bi)
-    if (map [i] == NULL)
+    if (ira_curr_regno_allocno_map [i] == NULL)
       create_allocno (i, FALSE, ira_curr_loop_tree_node);
 }
 
 /* The function creates allocnos corresponding to pseudo-registers
-   living on edge E (a loop enter or exit).  It also finds allocnos
-   living on the loop border. */
+   living on edge E (a loop entry or exit).  It also marks the
+   allocnos as living on the loop border. */
 static void
 create_loop_allocnos (edge e)
 {
   unsigned int i;
   bitmap live_in_regs, border_allocnos;
   bitmap_iterator bi;
-  allocno_t *map;
 
   live_in_regs = DF_LR_IN (e->dest);
-  map = ira_curr_loop_tree_node->regno_allocno_map;
   border_allocnos = ira_curr_loop_tree_node->border_allocnos;
   EXECUTE_IF_SET_IN_REG_SET (DF_LR_OUT (e->src),
 			     FIRST_PSEUDO_REGISTER, i, bi)
     if (bitmap_bit_p (live_in_regs, i))
       {
-	if (map [i] == NULL)
+	if (ira_curr_regno_allocno_map [i] == NULL)
 	  create_allocno (i, FALSE, ira_curr_loop_tree_node);
-	bitmap_set_bit (border_allocnos, ALLOCNO_NUM (map [i]));
+	bitmap_set_bit (border_allocnos,
+			ALLOCNO_NUM (ira_curr_regno_allocno_map [i]));
       }
 }
 
 /* The function creates allocnos corresponding to pseudo-registers
    living in loop represented by the corresponding loop tree node
-   LOOP_NODE.  */
+   LOOP_NODE.  The function is called by traverse_loop_tree.  */
 static void
 create_loop_tree_node_allocnos (loop_tree_node_t loop_node)
 {
@@ -1582,15 +1601,15 @@ create_allocnos (void)
   allocno_t a, father_a;
   loop_tree_node_t father;
 
-  /* We need to process BB first to correctly link allocnos by
-     next_regno_allocno field.  */
+  /* We need to process BB first to correctly link allocnos by member
+     next_regno_allocno.  */
   traverse_loop_tree (TRUE, ira_loop_tree_root,
 		      create_loop_tree_node_allocnos, NULL);
   if (flag_ira_algorithm != IRA_ALGORITHM_REGIONAL
       && flag_ira_algorithm != IRA_ALGORITHM_MIXED)
     return;
   /* Propagate number of references and frequencies for regional
-     register allocator.  */
+     register allocation.  */
   for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
     for (a = regno_allocno_map [i];
 	 a != NULL;
@@ -1627,7 +1646,8 @@ create_loop_tree_node_caps (loop_tree_no
       create_cap_allocno (allocnos [i]);
 }
 
-/* The function propagate info to caps mentioned in LOOP_NODE.  */
+/* The function propagate info (not available at the cap creation
+   time) to caps mentioned in LOOP_NODE.  */
 static void
 propagate_info_to_loop_tree_node_caps (loop_tree_node_t loop_node)
 {
@@ -1647,7 +1667,15 @@ propagate_info_to_loop_tree_node_caps (l
 
 
 
-/* The function merges ranges R1 and R2 and returns the result.  */
+/* The page contains code transforming more one region internal
+   representation (IR) to one region IR which is necessary for the
+   reload.  This transformation is called IR flattening.  We might
+   just rebuild the IR for one region but we don't do it because it
+   takes a lot of time.  */
+
+/* The function merges ranges R1 and R2 and returns the result.  The
+   function maintains the order of ranges and tries to minimize number
+   of the result ranges.  */
 static allocno_live_range_t 
 merge_ranges (allocno_live_range_t r1, allocno_live_range_t r2)
 {
@@ -1723,8 +1751,8 @@ merge_ranges (allocno_live_range_t r1, a
   return first;
 }
 
-/* The function returns immediate common dominator of two loop tree
-   nodes N1 and N2.  */
+/* This recursive function returns immediate common dominator of two
+   loop tree nodes N1 and N2.  */
 static loop_tree_node_t
 common_loop_tree_node_dominator (loop_tree_node_t n1, loop_tree_node_t n2)
 {
@@ -1745,8 +1773,8 @@ static allocno_t *regno_top_level_allocn
 
 
 /* The function check conflicts A with allocnos conflicting with
-   OTHER_ALLOCNO and add them (more accurately corresponding final IR
-   allocnos) if it is necessary.  */
+   OTHER_ALLOCNO and add them (more accurately corresponding allocnos
+   represented in the flattened IR) if it is necessary.  */
 static void
 check_and_add_conflicts (allocno_t a, allocno_t other_allocno)
 {
@@ -1773,9 +1801,9 @@ check_and_add_conflicts (allocno_t a, al
 
 /* This recursive function checks and adds (if necessary) conflicts
    with A processing conflicts of allocnos corresponding to A in
-   subloops.  If GO_DEEPER_P is false, the function stops to go deeper
-   in loop tree when allocno which will represent allocno in final IR
-   is achieved. */
+   subloops of LOOP_NODE.  If GO_DEEPER_P is FALSE, the function stops
+   to go deeper in loop tree when an allocno which will be represented
+   in the final flattened IR is achieved. */
 static void
 add_conflict_with_underlying_allocnos (allocno_t a,
 				       loop_tree_node_t loop_node,
@@ -1784,7 +1812,7 @@ add_conflict_with_underlying_allocnos (a
   loop_tree_node_t subloop_node;
   allocno_t subloop_a;
 
-  for (subloop_node = loop_node->inner;
+  for (subloop_node = loop_node->children;
        subloop_node != NULL;
        subloop_node = subloop_node->next)
     {
@@ -1805,7 +1833,9 @@ add_conflict_with_underlying_allocnos (a
 /* The function flattens IR.  In other words, the function transforms
    IR as it were build with one region (without loops).  We could make
    it much simpler by rebuilding IR with one region, but unfortunately
-   it takes a lot of time.  */
+   it takes a lot of time.  MAX_REGNO_BEFORE_EMIT and
+   MAX_POINT_BEFORE_EMIT are correspondingly MAX_REG_NUM () and
+   MAX_POINT before emitting insns on the loop borders.  */
 void
 ira_flattening (int max_regno_before_emit, int max_point_before_emit)
 {
@@ -1829,7 +1859,7 @@ ira_flattening (int max_regno_before_emi
   memset (regno_top_level_allocno_map, 0, max_reg_num () * sizeof (allocno_t));
   expand_calls ();
   new_allocnos_p = renamed_p = FALSE;
-  /* Updating accumulated attributes.  */
+  /* Fix final allocno attributes.  */
   for (i = max_regno_before_emit - 1; i >= FIRST_PSEUDO_REGISTER; i--)
     {
       propagate_p = FALSE;
@@ -1941,7 +1971,7 @@ ira_flattening (int max_regno_before_emi
 	      ira_assert (father_a != NULL);
 	      stop_p = first != a;
 	      /* Remember that exit can be to a grandparent (not only
-		 a parent) or a child of grandparent.  */
+		 to a parent) or a child of the grandparent.  */
 	      for (first = a;;)
 		{
 		  if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL)
@@ -1989,7 +2019,8 @@ ira_flattening (int max_regno_before_emi
 	    = VEC_length (rtx, regno_calls [REGNO (ALLOCNO_REG (a))]);
 	}
     }
-  /* Mark copies for removing and change allocnos in copies.  */
+  /* Mark some copies for removing and change allocnos in the rest
+     copies.  */
   FOR_EACH_COPY (cp, ci)
     {
       if (ALLOCNO_CAP_MEMBER (cp->first) != NULL
@@ -2040,11 +2071,11 @@ ira_flattening (int max_regno_before_emi
   if (new_allocnos_p)
     {
       /* Add conflicting allocnos from lower levels.  If we have a situation
-	 A1----conflict---B1
-	 A2----conflict---B2
+	 A1----conflict---B1 : father
+	 A2----conflict---B2 : child
 	 
-	 and A1 and A2 will be presented by themselves in final IR and
-	 B1 and B2 will be presented by B1, then we need to check
+	 and A1 and A2 will be presented by themselves in the final IR
+	 and B1 and B2 will be presented by B1, then we need to check
 	 conflict A2 and B1.
    
 	 There is another situation when we should check and add
@@ -2084,8 +2115,7 @@ ira_flattening (int max_regno_before_emi
 	r->allocno = a;
     }
   ira_free (temp_change_bit_vec);
-  /* Remove allocnos on lower levels of the loop tree and
-     enumerate allocnos.  */
+  /* Remove unnecessary allocnos on lower levels of the loop tree.  */
   FOR_EACH_ALLOCNO (a, ai)
     {
       if (ALLOCNO_LOOP_TREE_NODE (a) != ira_loop_tree_root
@@ -2108,7 +2138,7 @@ ira_flattening (int max_regno_before_emi
       ira_assert (ALLOCNO_UPDATED_HARD_REG_COSTS (a) == NULL);
       ira_assert (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) == NULL);
     }
-  /* Remove unnecessary copies, and enumerate copies.  */
+  /* Remove unnecessary copies.  */
   FOR_EACH_COPY (cp, ci)
     {
       if (cp->loop_tree_node == NULL)
@@ -2174,14 +2204,15 @@ ira_flattening (int max_regno_before_emi
 
 
 
-/* This entry function creates internal representation for IRA
-   (allocnos, copies, loop tree nodes).  If LOOPS_P is zero the nodes
+/* This entry function creates internal representation (IR) for IRA
+   (allocnos, copies, loop tree nodes).  If LOOPS_P is FALSE the nodes
    corresponding to the loops (except the root which corresponds the
    all function) and correspondingly allocnos for the loops will be
-   not created (it will be done only for basic blocks).  Such value is
-   used for Chaitin-Briggs and Chow's priority coloring.  The function
-   returns nonzero if we generates loop structure (besides node
-   representing all function) for regional allocation.  */
+   not created.  Such parameter value is used for Chaitin-Briggs
+   coloring.  The function returns TRUE if we generate loop structure
+   (besides nodes representing all function and the basic blocks) for
+   regional allocation.  It means that we really need to flatten IR
+   before the reload.  */
 int
 ira_build (int loops_p)
 {
Index: ira.c
===================================================================
--- ira.c	(revision 133412)
+++ ira.c	(working copy)
@@ -1,4 +1,4 @@
-/* Integrated Register Allocator entry point.
+/* Integrated Register Allocator (IRA) entry point.
    Copyright (C) 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
@@ -21,33 +21,37 @@ Software Foundation, 51 Franklin Street,
 02110-1301, USA.  */
 
 /* The integrated register allocator (IRA) is called integrated
-   because register coalescing and register live range splitting are
-   done on-the-fly during coloring.  Register coalescing is done by
-   hard register preferencing during hard register assigning.  The
-   live range splitting is a byproduct of the regional register
-   allocation.
+   because register coalescing, register live range splitting, and
+   choosing a better hard register are done on-the-fly during
+   coloring.  Register coalescing and choosing a cheaper hard register
+   is done by hard register preferencing during hard register
+   assigning.  The live range splitting is a byproduct of the regional
+   register allocation.
 
    The regional allocation is top-down process.  The first we do
    allocation for all function then we improve it for loops then their
    subloops and so on.  To reduce register shuffling, the same
-   mechanism of hard register prefrencing is used.  This approach
-   works as good as Callahan-Koblentz algorithm but it is simpler.
-   We use Chaitin-Briggs coloring for each loop (or function) with
-   optional biased coloring.  If pseudo-registers got different
-   location on loop borders we rename them inside the loop and
-   generate pseudo-register move insns.  Some optimizations (like
-   removing redundant stores, moving register shuffling to less
-   frequent points, and code duplication reducing) to minimize effect
-   of register shuffling is done
-
-   If we don't improve register allocation for loops we get classic
-   Chaitin-Briggs coloring (only instead of separate pass of
-   coalescing, we use hard register preferencing).
-
-   Optionally we implements Chow's priority coloring only for all
-   function.  It is quite analogous to the current gcc global register
-   allocator only we use more sophisticated hard register
-   preferencing.
+   mechanism of hard register preferencing is used.  This approach
+   works as good as Callahan-Koblentz algorithm but it is simpler.  We
+   use Chaitin-Briggs coloring for each region (loop or all function).
+   If pseudo-registers got different location on loop borders we
+   rename them inside the loop and generate pseudo-register move
+   insns.  Some optimizations (like removing redundant stores, moving
+   register shuffling to less frequent points, and code duplication
+   reducing) to minimize effect of register shuffling are done.
+
+   If we don't improve register allocation for loops (or there are no
+   loops at all) we get classic Chaitin-Briggs coloring (only instead
+   of separate pass of coalescing, we use hard register preferencing).
+   In any case, before the reload work, we have one region IRA
+   internal representation.
+
+   IRA also has better integration with the reload pass than the old
+   register allocator.  Pseudo-registers spilled by IRA or the reload
+   have still a chance to get hard-registers when the reload evicts
+   some pseudo-registers from hard-registers.  IRA helps to choose
+   better pseudos for spilling based on their live ranges and to
+   coalesce stack slots allocated for the spilled pseudo-registers.
 
    Literature is worth to read for better understanding the code:
 
@@ -64,6 +68,8 @@ Software Foundation, 51 Franklin Street,
    o Guei-Yuan Lueh, Thomas Gross, and Ali-Reza Adl-Tabatabai. Global
      Register Allocation Based on Graph Fusion.
 
+   o Vladimir Makarov. The Integrated Register Allocator for GCC.
+
 */
 
 
@@ -93,7 +99,6 @@ Software Foundation, 51 Franklin Street,
 #include "ggc.h"
 #include "ira-int.h"
 
-static void setup_inner_mode (void);
 static void setup_reg_mode_hard_regset (void);
 static void setup_class_hard_regs (void);
 static void setup_available_class_regs (void);
@@ -101,7 +106,7 @@ static void setup_alloc_regs (int);
 static void setup_class_subset_and_memory_move_costs (void);
 static void setup_reg_subclasses (void);
 #ifdef IRA_COVER_CLASSES
-static void setup_cover_classes (void);
+static void setup_cover_and_important_classes (void);
 static void setup_class_translate (void);
 static void setup_reg_class_intersect_union (void);
 #endif
@@ -109,6 +114,7 @@ static void print_class_cover (FILE *);
 static void find_reg_class_closure (void);
 static void setup_reg_class_nregs (void);
 static void setup_prohibited_class_mode_regs (void);
+static void free_register_move_costs (void);
 static void setup_prohibited_mode_move_regs (void);
 static int insn_contains_asm_1 (rtx *, void *);
 static int insn_contains_asm (rtx);
@@ -127,14 +133,17 @@ static void print_redundant_copies (void
 #endif
 static void setup_preferred_alternate_classes (void);
 static void expand_reg_info (int);
+static int chain_freq_compare (const void *, const void *);
+static int chain_bb_compare (const void *, const void *);
 
+static void ira (FILE *);
 static bool gate_ira (void);
 static unsigned int rest_of_handle_ira (void);
 
-/* The flag value used internally.  */
+/* A modified value of flag `-fira-verbose' used internally.  */
 int internal_flag_ira_verbose;
 
-/* Dump file for IRA.  */
+/* Dump file of the allocator if it is not NULL.  */
 FILE *ira_dump_file;
 
 /* Pools for allocnos, copies, allocno live ranges.  */
@@ -143,26 +152,21 @@ alloc_pool allocno_pool, copy_pool, allo
 /* The number of elements in the following array.  */
 int spilled_reg_stack_slots_num;
 
-/* The following array contains description of spilled registers stack
-   slots have been used in the current function so far.  */
+/* The following array contains info about spilled pseudo-registers
+   stack slots used in current function so far.  */
 struct spilled_reg_stack_slot *spilled_reg_stack_slots;
 
-/* The following variable values are correspondingly overall cost of
-   the allocation, cost of hard register usage for the allocnos, cost
-   of memory usage for the allocnos, cost of loads, stores and register
-   move insns generated for register live range splitting.  */
+/* Correspondingly overall cost of the allocation, cost of the
+   allocnos assigned to hard-registers, cost of the allocnos assigned
+   to memory, cost of loads, stores and register move insns generated
+   for pseudo-register live range splitting (see ira-emit.c).  */
 int overall_cost;
 int reg_cost, mem_cost;
 int load_cost, store_cost, shuffle_cost;
 int move_loops_num, additional_jumps_num;
 
-/* A mode whose value is immediately contained in given mode
-   value.  */
-unsigned char mode_inner_mode [NUM_MACHINE_MODES];
-
-/* The following array is a map hard regs X modes -> number registers
-   for store value of given mode starting with given hard
-   register.  */
+/* Map: hard regs X modes -> set of hard registers for storing value
+   of given mode starting with given hard register.  */
 HARD_REG_SET reg_mode_hard_regset [FIRST_PSEUDO_REGISTER] [NUM_MACHINE_MODES];
 
 /* The following two variables are array analog of macros
@@ -170,18 +174,21 @@ HARD_REG_SET reg_mode_hard_regset [FIRST
 short int memory_move_cost [MAX_MACHINE_MODE] [N_REG_CLASSES] [2];
 move_table *register_move_cost [MAX_MACHINE_MODE];
 
-/* Similar to move_cost, but here we don't have to move if the first
-   index is a subset of the second (taking registers available for
-   allocation into account) so in that case the cost is zero.  */
+/* Similar to may_move_in_cost but it is calculated in IRA instead of
+   regclass.  Another difference we take only available hard registers
+   into account to figure out that one register class is a subset of
+   the another one.  */
 move_table *register_may_move_in_cost [MAX_MACHINE_MODE];
 
-/* Similar, but here we don't have to move if the first index is a
-   superset of the second (taking registers available for allocation
-   into account) so in that case the cost is zero.  */
+/* Similar to may_move_out_cost but it is calculated in IRA instead of
+   regclass.  Another difference we take only available hard registers
+   into account to figure out that one register class is a subset of
+   the another one.  */
 move_table *register_may_move_out_cost [MAX_MACHINE_MODE];
 
-/* Nonzero value of element of the following array means that the
-   1st class is a subset of the 2nd class.  */
+/* Register class subset relation: TRUE if the first class is a subset
+   of the second one considering only hard registers available for the
+   allocation.  */
 int class_subset_p [N_REG_CLASSES] [N_REG_CLASSES];
 
 /* Temporary hard reg set used for different calculation.  */
@@ -189,28 +196,6 @@ static HARD_REG_SET temp_hard_regset;
 
 
 
-/* The function sets up mode_inner_mode array.  */
-static void
-setup_inner_mode (void)
-{
-  int i;
-  enum machine_mode wider;
-
-  for (i = 0; i < NUM_MACHINE_MODES; i++)
-    mode_inner_mode [i] = VOIDmode;
-  for (i = 0; i < NUM_MACHINE_MODES; i++)
-    {
-      wider = GET_MODE_WIDER_MODE (i);
-      if (wider != VOIDmode)
-	{
-	  ira_assert (mode_inner_mode [wider] == VOIDmode);
-	  mode_inner_mode [wider] = i;
-	}
-    }
-}
-
-
-
 /* The function sets up map REG_MODE_HARD_REGSET.  */
 static void
 setup_reg_mode_hard_regset (void)
@@ -230,20 +215,23 @@ setup_reg_mode_hard_regset (void)
 
 
 
-/* Hard registers can not be used for the register allocator for all
-   functions of the current compile unit.  */
+/* Hard registers that can not be used for the register allocator for
+   all functions of the current compilation unit.  */
 static HARD_REG_SET no_unit_alloc_regs;
 
-/* Hard registers which can be used for the allocation of given
-   register class.  The order is defined by the allocation order.  */
+/* Array of number of hard registers of given class which are
+   available for the allocation.  The order is defined by the
+   allocation order.  */
 short class_hard_regs [N_REG_CLASSES] [FIRST_PSEUDO_REGISTER];
 
-/* The size of the above array for given register class.  */
+/* The number of elements of the above array for given register
+   class.  */
 int class_hard_regs_num [N_REG_CLASSES];
 
 /* Index (in class_hard_regs) for given register class and hard
    register (in general case a hard register can belong to several
-   register classes).  */
+   register classes).  The index is negative for hard registers
+   unavailable for the allocation. */
 short class_hard_reg_index [N_REG_CLASSES] [FIRST_PSEUDO_REGISTER];
 
 /* The function sets up the three arrays declared above.  */
@@ -284,7 +272,7 @@ setup_class_hard_regs (void)
     }
 }
 
-/* Number of class hard registers available for the register
+/* Number of given class hard registers available for the register
    allocation for given classes.  */
 int available_class_regs [N_REG_CLASSES];
 
@@ -305,10 +293,10 @@ setup_available_class_regs (void)
     }
 }
 
-/* The function setting up different global variables defining hard
-   registers for the allocation.  It depends on USE_HARD_FRAME_P whose
-   nonzero value means that we can use hard frame pointer for the
-   allocation.  */
+/* The function setting up different global variables defining info
+   about hard registers for the allocation.  It depends on
+   USE_HARD_FRAME_P whose nonzero value means that we can use hard
+   frame pointer for the allocation.  */
 static void
 setup_alloc_regs (int use_hard_frame_p)
 {
@@ -404,7 +392,7 @@ ira_free (void *addr ATTRIBUTE_UNUSED)
 }
 
 
-/* The function allocates bitmap for IRA.  */
+/* The function allocates and returns bitmap for IRA.  */
 bitmap
 ira_allocate_bitmap (void)
 {
@@ -418,20 +406,6 @@ ira_free_bitmap (bitmap b ATTRIBUTE_UNUS
   /* do nothing */
 }
 
-/* The function allocates regset for IRA.  */
-regset
-ira_allocate_regset (void)
-{
-  return ALLOC_REG_SET (&ira_bitmap_obstack);
-}
-
-/* The function frees regset R allocated for IRA.  */
-void
-ira_free_regset (regset r ATTRIBUTE_UNUSED)
-{
-  /* do nothing */
-}
-
 
 
 /* The function outputs information about allocation of all allocnos
@@ -481,7 +455,7 @@ debug_disposition (void)
    excluded from the consideration).  */
 static enum reg_class alloc_reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
 
-/* The function initializes the tables of subclasses of each reg
+/* The function initializes the table of subclasses of each reg
    class.  */
 static void
 setup_reg_subclasses (void)
@@ -521,31 +495,35 @@ setup_reg_subclasses (void)
 
 
 
-/* The value is size of the subsequent array.  */
+/* Number of cover classes.  Cover classes is non-intersected register
+   classes containing all hard-registers available for the
+   allocation.  */
 int reg_class_cover_size;
 
-/* The array containing cover classes whose hard registers are used
-   for the allocation -- see also comments for macro
-   IRA_COVER_CLASSES.  */
+/* The array containing cover classes (see also comments for macro
+   IRA_COVER_CLASSES).  Only first REG_CLASS_COVER_SIZE elements are
+   used for this.  */
 enum reg_class reg_class_cover [N_REG_CLASSES];
 
 /* The value is number of elements in the subsequent array.  */
 int important_classes_num;
 
-/* The array containing classes which are subclasses of cover
-   classes.  */
+/* The array containing classes (including cover classes) which are
+   subclasses of cover classes.  Such classes is important for
+   calculation of the hard register usage costs.  */
 enum reg_class important_classes [N_REG_CLASSES];
 
-/* The array containing order numbers of important classes (they are
-   subclasses of cover classes).  */
+/* The array containing indexes of important classes in the previous
+   array.  The array elements are defined only for important
+   classes.  */
 int important_class_nums [N_REG_CLASSES];
 
 #ifdef IRA_COVER_CLASSES
 
-/* The function checks IRA_COVER_CLASSES and sets the two global
+/* The function checks IRA_COVER_CLASSES and sets the four global
    variables defined above.  */
 static void
-setup_cover_classes (void)
+setup_cover_and_important_classes (void)
 {
   int i, j;
   enum reg_class cl;
@@ -589,9 +567,9 @@ setup_cover_classes (void)
 }
 #endif
 
-/* Map of register classes to corresponding cover class containing the
-   given class.  If given class is not a subset of a cover class, we
-   translate it into the cheapest cover class.  */
+/* Map of all register classes to corresponding cover class containing
+   the given class.  If given class is not a subset of a cover class,
+   we translate it into the cheapest cover class.  */
 enum reg_class class_translate [N_REG_CLASSES];
 
 #ifdef IRA_COVER_CLASSES
@@ -666,9 +644,14 @@ setup_class_translate (void)
 }
 #endif
 
-/* The biggest important class inside of intersection of the two classes.  */
+/* The biggest important class inside of intersection of the two
+   classes (that is calculated taking only hard registers available
+   for allocation into account).  */
 enum reg_class reg_class_intersect [N_REG_CLASSES] [N_REG_CLASSES];
-/* The biggest important class inside of union of the two classes.  */
+
+/* The biggest important class inside of union of the two classes
+   (that is calculated taking only hard registers available for
+   allocation into account).  */
 enum reg_class reg_class_union [N_REG_CLASSES] [N_REG_CLASSES];
 
 #ifdef IRA_COVER_CLASSES
@@ -749,14 +732,14 @@ debug_class_cover (void)
   print_class_cover (stderr);
 }
 
-/* Function setting up different arrays concerning class subsets and
-   cover classes.  */
+/* Function setting up different arrays concerning class subsets,
+   cover and important classes.  */
 static void
 find_reg_class_closure (void)
 {
   setup_reg_subclasses ();
 #ifdef IRA_COVER_CLASSES
-  setup_cover_classes ();
+  setup_cover_and_important_classes ();
   setup_class_translate ();
   setup_reg_class_intersect_union ();
 #endif
@@ -791,8 +774,9 @@ setup_reg_class_nregs (void)
 
 
 
-/* Array whose values are hard regset of hard registers of given
-   register class whose HARD_REGNO_MODE_OK values are zero.  */
+/* Array whose values are hard regset of hard registers available for
+   the allocation of given register class whose HARD_REGNO_MODE_OK
+   values for given mode are zero.  */
 HARD_REG_SET prohibited_class_mode_regs [N_REG_CLASSES] [NUM_MACHINE_MODES];
 
 /* The function setting up PROHIBITED_CLASS_MODE_REGS.  */
@@ -835,7 +819,7 @@ init_register_move_cost (enum machine_mo
   if (move_cost [mode] == NULL)
     init_move_cost (mode);
   register_move_cost [mode] = move_cost [mode];
-  /* Don't use ira_allocate becuase the tables exist out of scope of a
+  /* Don't use ira_allocate because the tables exist out of scope of a
      IRA call.  */
   register_may_move_in_cost [mode]
     = (move_table *) xmalloc (sizeof (move_table) * N_REG_CLASSES);
@@ -863,8 +847,9 @@ init_register_move_cost (enum machine_mo
 HARD_REG_SET zero_hard_reg_set;
 HARD_REG_SET one_hard_reg_set;
 
-/* Function called once during compiler work.  It sets up different
-   arrays whose values don't depend on the compiled function.  */
+/* The function called once during compiler work.  It sets up
+   different arrays whose values don't depend on the compiled
+   function.  */
 void
 init_ira_once (void)
 {
@@ -878,7 +863,6 @@ init_ira_once (void)
       register_may_move_in_cost [mode] = NULL;
       register_may_move_out_cost [mode] = NULL;
     }
-  setup_inner_mode ();
   init_ira_costs_once ();
 }
 
@@ -973,24 +957,23 @@ setup_prohibited_mode_move_regs (void)
 
 
 
-/* Function specific hard registers excluded from the allocation.  */
+/* Function specific hard registers that can not be used for the
+   register allocation.  */
 HARD_REG_SET no_alloc_regs;
 
-/* Return true if *LOC contains an asm.  */
-
+/* Return TRUE if *LOC contains an asm.  */
 static int
 insn_contains_asm_1 (rtx *loc, void *data ATTRIBUTE_UNUSED)
 {
   if ( !*loc)
     return 0;
   if (GET_CODE (*loc) == ASM_OPERANDS)
-    return 1;
-  return 0;
+    return TRUE;
+  return FALSE;
 }
 
 
 /* Return true if INSN contains an ASM.  */
-
 static int
 insn_contains_asm (rtx insn)
 {
@@ -1041,8 +1024,8 @@ setup_eliminable_regset (void)
   int i;
   /* Like regs_ever_live, but 1 if a reg is set or clobbered from an
      asm.  Unlike regs_ever_live, elements of this array corresponding
-     to eliminable regs like the frame pointer are set if an asm sets
-     them.  */
+     to eliminable regs (like the frame pointer) are set if an asm
+     sets them.  */
   char *regs_asm_clobbered = alloca (FIRST_PSEUDO_REGISTER * sizeof (char));
 #ifdef ELIMINABLE_REGS
   static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
@@ -1111,14 +1094,15 @@ setup_eliminable_regset (void)
 /* The length of the following two arrays.  */
 int reg_equiv_len;
 
-/* The element value is nonzero if the corresponding regno value is
+/* The element value is TRUE if the corresponding regno value is
    invariant.  */
 int *reg_equiv_invariant_p;
 
-/* The element value is equiv constant or NULL_RTX.  */
+/* The element value is equiv constant of given pseudo-register or
+   NULL_RTX.  */
 rtx *reg_equiv_const;
 
-/* The function sets up the two array declaraed above.  */
+/* The function sets up the two array declared above.  */
 static void
 find_reg_equiv_invariant_const (void)
 {
@@ -1146,11 +1130,11 @@ find_reg_equiv_invariant_const (void)
 		 objects to LEGITIMATE_PIC_OPERAND_P.  */
 	      || (CONSTANT_P (x) && LEGITIMATE_PIC_OPERAND_P (x)))
 	    {
-	      /* It can happen that a REG_EQUIV note contains a MEM that
-		 is not a legitimate memory operand.  As later stages of
-		 reload assume that all addresses found in the
-		 reg_equiv_* arrays were originally legitimate, we
-		 ignore such REG_EQUIV notes.  */
+	      /* It can happen that a REG_EQUIV note contains a MEM
+		 that is not a legitimate memory operand.  As later
+		 stages of the reload assume that all addresses found
+		 in the reg_equiv_* arrays were originally legitimate,
+		 we ignore such REG_EQUIV notes.  */
 	      if (memory_operand (x, VOIDmode))
 		invariant_p = MEM_READONLY_P (x);
 	      else if (function_invariant_p (x))
@@ -1171,7 +1155,7 @@ find_reg_equiv_invariant_const (void)
 
 
 /* The function sets up REG_RENUMBER and CALLER_SAVE_NEEDED (used by
-   reload) from the allocation found by IRA.  */
+   the reload) from the allocation found by IRA.  */
 static void
 setup_reg_renumber (void)
 {
@@ -1221,8 +1205,8 @@ setup_allocno_assignment_flags (void)
 	free_allocno_updated_costs (a);
       hard_regno = ALLOCNO_HARD_REGNO (a);
       /* Don't assign hard registers to allocnos which are destination
-	 of removed store at the end of loop.  It has a few sense to
-	 keep the same value in different hard registers.  It is also
+	 of removed store at the end of loop.  It has no sense to keep
+	 the same value in different hard registers.  It is also
 	 impossible to assign hard registers correctly to such
 	 allocnos because the cost info and info about intersected
 	 calls are incorrect for them.  */
@@ -1236,8 +1220,7 @@ setup_allocno_assignment_flags (void)
 }
 
 /* The function evaluates overall allocation cost and costs for using
-   registers and memory for allocnos.  */
-
+   hard registers and memory for allocnos.  */
 static void
 calculate_allocation_cost (void)
 {
@@ -1286,7 +1269,9 @@ calculate_allocation_cost (void)
 }
 
 #ifdef ENABLE_IRA_CHECKING
-/* The function checks correctness of the allocation.  */
+/* The function checks correctness of the allocation.  We do need this
+   because of complicated code to transform more one region internal
+   representation into one region representation.  */
 static void
 check_allocation (void)
 {
@@ -1370,7 +1355,7 @@ fix_reg_equiv_init (void)
 }
 
 #ifdef ENABLE_IRA_CHECKING
-/* The function prints redundant memory memory copies. */
+/* The function prints redundant memory-memory copies.  */
 static void
 print_redundant_copies (void)
 {
@@ -1424,6 +1409,8 @@ setup_preferred_alternate_classes (void)
 
 
 
+/* Regional allocation can create new pseudo-registers.  The function
+   expands some arrays for pseudo-registers.  */
 static void
 expand_reg_info (int old_size)
 {
@@ -1440,7 +1427,13 @@ expand_reg_info (int old_size)
 
 
 
-/* Map bb index -> order number in the BB chain.  */
+/* This page contains code for sorting the insn chain used by the
+   reload.  In old register allocator, the insn chain order
+   corresponds to the order of insns in RTL.  By putting insns with
+   higher execution frequency first, the reload has a better chance to
+   generate less expensive operand reloads for such insns.  */
+
+/* Map bb index -> order number in the BB chain in RTL code.  */
 static int *basic_block_order_nums;
 
 /* The function is used to sort insn chain according insn execution
@@ -1475,8 +1468,8 @@ chain_bb_compare (const void *v1p, const
   return (char *) v1p - (char *) v2p;
 }
 
-/* The function sorts insn chain according insn frequencies (if
-   FREQ_P) or insn original order.  */
+/* The function sorts insn chain according to insn frequencies if
+   FREQ_P or according to insn original order otherwise.  */
 void
 sort_insn_chain (int freq_p)
 {
@@ -1519,7 +1512,7 @@ sort_insn_chain (int freq_p)
 struct loops ira_loops;
 
 /* This is the main entry of IRA.  */
-void
+static void
 ira (FILE *f)
 {
   int overall_cost_before, loops_p, allocated_reg_info_size;
@@ -1620,19 +1613,21 @@ ira (FILE *f)
       if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
 	fprintf (ira_dump_file, "Flattening IR\n");
       ira_flattening (max_regno_before_ira, max_point_before_emit);
-      /* New insns were generated: add notes and recaclulate live
+      /* New insns were generated: add notes and recalculate live
 	 info.  */
       df_analyze ();
+
       {
 	basic_block bb;
-
+	
 	FOR_ALL_BB (bb)
 	  bb->loop_father = NULL;
 	current_loops = NULL;
       }
+
       setup_allocno_assignment_flags ();
       initiate_ira_assign ();
-      reassign_conflict_allocnos (max_regno, FALSE);
+      reassign_conflict_allocnos (max_regno);
     }
 
   setup_reg_renumber ();
@@ -1693,9 +1688,6 @@ ira (FILE *f)
 
   ira_destroy ();
 
-#if 0
-  ira_assert  (current_loops == &ira_loops);
-#endif
   flow_loops_free (&ira_loops);
   free_dominance_info (CDI_DOMINATORS);
   FOR_ALL_BB (bb)
@@ -1749,8 +1741,8 @@ rest_of_handle_ira (void)
 
 struct tree_opt_pass pass_ira =
 {
-  "ira",                               /* name */
-  gate_ira,                            /* gate */
+  "ira",                                /* name */
+  gate_ira,                             /* gate */
   rest_of_handle_ira,		        /* execute */
   NULL,                                 /* sub */
   NULL,                                 /* next */
Index: ira.h
===================================================================
--- ira.h	(revision 133412)
+++ ira.h	(working copy)
@@ -1,5 +1,5 @@
-/* Communication between the Integrated Register Allocator and rest of
-   the compiler.
+/* Communication between the Integrated Register Allocator (IRA) and
+   the rest of the compiler.
    Copyright (C) 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
@@ -21,45 +21,12 @@ along with GCC; see the file COPYING.  I
 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301, USA.  */
 
-
-/* If secondary reloads are the same for inputs and outputs, define those
-   macros here.  */
-
-#ifdef SECONDARY_RELOAD_CLASS
-#define SECONDARY_INPUT_RELOAD_CLASS(CLASS, MODE, X) \
-  SECONDARY_RELOAD_CLASS (CLASS, MODE, X)
-#define SECONDARY_OUTPUT_RELOAD_CLASS(CLASS, MODE, X) \
-  SECONDARY_RELOAD_CLASS (CLASS, MODE, X)
-#endif
-
-/* If either macro is defined, show that we need secondary reloads.  */
-#if defined(SECONDARY_INPUT_RELOAD_CLASS) || defined(SECONDARY_OUTPUT_RELOAD_CLASS)
-#define HAVE_SECONDARY_RELOADS
-#endif
-
-/* If MEMORY_MOVE_COST isn't defined, give it a default here.  */
-#ifndef MEMORY_MOVE_COST
-#ifdef HAVE_SECONDARY_RELOADS
-#define MEMORY_MOVE_COST(MODE,CLASS,IN) \
-  (4 + memory_move_secondary_cost ((MODE), (CLASS), (IN)))
-#else
-#define MEMORY_MOVE_COST(MODE,CLASS,IN) 4
-#endif
-#endif
-
-extern GTY (()) struct varray_head_tag *reg_equiv_memory_loc_varray;
-extern rtx *reg_equiv_constant;
-extern rtx *reg_equiv_memory_loc;
-extern rtx *reg_equiv_address;
-extern rtx *reg_equiv_mem;
-
 extern void init_ira_once (void);
 extern void init_ira (void);
 extern void finish_ira_once (void);
 extern rtx ira_eliminate_regs (rtx, enum machine_mode);
 extern void sort_insn_chain (int);
 
-extern void ira (FILE *);
 extern void sort_regnos_for_alter_reg (int *, int, unsigned int *);
 extern void mark_allocation_change (int);
 extern void mark_memory_move_deletion (int, int);
Index: ira-costs.c
===================================================================
--- ira-costs.c	(revision 133412)
+++ ira-costs.c	(working copy)
@@ -1,4 +1,4 @@
-/* Compute cover class of the allocnos and their hard register costs.
+/* IRA hard register and memory cost calculation for allocnos.
    Copyright (C) 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
@@ -39,45 +39,29 @@ Software Foundation, 51 Franklin Street,
 #include "params.h"
 #include "ira-int.h"
 
-/* The file contains code is analogous to one in regclass but the code
+/* The file contains code is similar to one in regclass but the code
    works on the allocno basis.  */
 
-struct costs;
-
-static void record_reg_classes (int, int, rtx *, enum machine_mode *,
-				const char **, rtx, struct costs **,
-				enum reg_class *);
-static inline int ok_for_index_p_nonstrict (rtx);
-static inline int ok_for_base_p_nonstrict (rtx, enum machine_mode,
-					   enum rtx_code, enum rtx_code);
-static void record_address_regs (enum machine_mode, rtx x, int,
-				 enum rtx_code, enum rtx_code, int scale);
-static void record_operand_costs (rtx, struct costs **, enum reg_class *);
-static rtx scan_one_insn (rtx);
-static void print_costs (FILE *);
-static void process_bb_node_for_costs (loop_tree_node_t);
-static void find_allocno_class_costs (void);
-static void process_bb_node_for_hard_reg_moves (loop_tree_node_t);
-static void setup_allocno_cover_class_and_costs (void);
-static void free_ira_costs (void);
-
 #ifdef FORBIDDEN_INC_DEC_CLASSES
 /* Indexed by n, is nonzero if (REG n) is used in an auto-inc or
    auto-dec context.  */
 static char *in_inc_dec;
 #endif
 
-/* The `costs' struct records the cost of using a hard register of
-   each class and of using memory for each allocno.  We use this data
-   to set up register and costs.  */
+/* The `costs' struct records the cost of using hard registers of each
+   class considered for the calculation and of using memory for each
+   allocno.  */
 struct costs
 {
   int mem_cost;
-  /* Costs for important register classes start here.  */
+  /* Costs for register classes start here.  We process only some
+     register classes (cover classes on the 1st cost calculation
+     iteration and important classes on the 2nd iteration).  */
   int cost [1];
 };
 
-/* Initialized once.  It is a size of the allocated struct costs.  */
+/* Initialized once.  It is a maximal possible size of the allocated
+   struct costs.  */
 static int max_struct_costs_size;
 
 /* Allocated and initialized once, and used to initialize cost values
@@ -95,13 +79,15 @@ static struct costs *this_op_costs [MAX_
    allocno.  */
 static struct costs *total_costs;
 
-/* Classes used for cost calculation.  */
+/* Classes used for cost calculation.  They may be different on
+   different iterations of the cost calculations.  */
 static enum reg_class *cost_classes;
 
 /* The size of the previous array.  */
 static int cost_classes_num;
 
-/* The array containing order numbers of cost classes.  */
+/* Map: cost class -> order number (they start with 0) of the cost
+   class.  */
 static int cost_class_nums [N_REG_CLASSES];
 
 /* It is the current size of struct costs.  */
@@ -112,15 +98,38 @@ static int struct_costs_size;
 #define COSTS_OF_ALLOCNO(arr, num) \
   ((struct costs *) ((char *) (arr) + (num) * struct_costs_size))
 
-/* Record register class preferences of each allocno.  */
+/* Record register class preferences of each allocno.  Null value
+   means no preferences.  It happens on the 1st iteration of the cost
+   calculation.  */
 static enum reg_class *allocno_pref;
 
 /* Allocated buffers for allocno_pref.  */
 static enum reg_class *allocno_pref_buffer;
 
-/* Frequency of executions of the current insn.  */
+/* Execution frequency of the current insn.  */
 static int frequency;
 
+static int copy_cost (rtx, enum machine_mode, enum reg_class, int,
+		      secondary_reload_info *);
+static void record_reg_classes (int, int, rtx *, enum machine_mode *,
+				const char **, rtx, struct costs **,
+				enum reg_class *);
+static inline int ok_for_index_p_nonstrict (rtx);
+static inline int ok_for_base_p_nonstrict (rtx, enum machine_mode,
+					   enum rtx_code, enum rtx_code);
+static void record_address_regs (enum machine_mode, rtx x, int,
+				 enum rtx_code, enum rtx_code, int scale);
+static void record_operand_costs (rtx, struct costs **, enum reg_class *);
+static rtx scan_one_insn (rtx);
+static void print_costs (FILE *);
+static void process_bb_node_for_costs (loop_tree_node_t);
+static void find_allocno_class_costs (void);
+static void process_bb_node_for_hard_reg_moves (loop_tree_node_t);
+static void setup_allocno_cover_class_and_costs (void);
+static void free_ira_costs (void);
+
+
+
 /* Compute the cost of loading X into (if TO_P is nonzero) or from (if
    TO_P is zero) a register of class CLASS in mode MODE.  X must not
    be a pseudo register.  */
@@ -171,8 +180,8 @@ copy_cost (rtx x, enum machine_mode mode
 
 
 
-/* Record the cost of using memory or registers of various classes for
-   the operands in INSN.
+/* Record the cost of using memory or hard registers of various
+   classes for the operands in INSN.
 
    N_ALTS is the number of alternatives.
    N_OPS is the number of operands.
@@ -269,7 +278,7 @@ record_reg_classes (int n_alts, int n_op
 	      else if (! REG_P (ops [j])
 		       || REGNO (ops [j]) < FIRST_PSEUDO_REGISTER)
 		{
-		  /* This op is a allocno but the one it matches is
+		  /* This op is an allocno but the one it matches is
 		     not.  */
 
 		  /* If we can't put the other operand into a
@@ -278,7 +287,7 @@ record_reg_classes (int n_alts, int n_op
 		  if (classes [j] == NO_REGS)
 		    alt_fail = 1;
 		  /* Otherwise, add to the cost of this alternative
-		     the cost to copy the other operand to the
+		     the cost to copy the other operand to the hard
 		     register used for this operand.  */
 		  else
 		    alt_cost
@@ -289,7 +298,7 @@ record_reg_classes (int n_alts, int n_op
 		  /* The costs of this operand are not the same as the
 		     other operand since move costs are not symmetric.
 		     Moreover, if we cannot tie them, this alternative
-		     needs to do a copy, which is one instruction.  */
+		     needs to do a copy, which is one insn.  */
 		  struct costs *pp = this_op_costs [i];
 
 		  if (register_move_cost [mode] == NULL)
@@ -500,8 +509,8 @@ record_reg_classes (int n_alts, int n_op
 		      if (address_operand (op, GET_MODE (op)))
 			win = 1;
 		      /* We know this operand is an address, so we
-			 want it to be allocated to a register that
-			 can be the base of an address,
+			 want it to be allocated to a hard register
+			 that can be the base of an address,
 			 i.e. BASE_REG_CLASS.  */
 		      classes [i]
 			= reg_class_union [classes [i]]
@@ -648,15 +657,15 @@ record_reg_classes (int n_alts, int n_op
     }
 
   /* If this insn is a single set copying operand 1 to operand 0 and
-     one operand is a allocno with the other a hard reg or a allocno
-     that prefers a register that is in its own register class then we
-     may want to adjust the cost of that register class to -1.
+     one operand is an allocno with the other a hard reg or an allocno
+     that prefers a hard register that is in its own register class
+     then we may want to adjust the cost of that register class to -1.
 
      Avoid the adjustment if the source does not die to avoid
      stressing of register allocator by preferrencing two colliding
      registers into single class.
 
-     Also avoid the adjustment if a copy between registers of the
+     Also avoid the adjustment if a copy between hard registers of the
      class is expensive (ten times the cost of a default copy is
      considered arbitrarily expensive).  This avoids losing when the
      preferred class is very expensive as the source of a copy
@@ -711,8 +720,8 @@ ok_for_index_p_nonstrict (rtx reg)
   return regno >= FIRST_PSEUDO_REGISTER || REGNO_OK_FOR_INDEX_P (regno);
 }
 
-/* A version of regno_ok_for_base_p for use during regclass, when all
-   allocnos should count as OK.  Arguments as for
+/* A version of regno_ok_for_base_p for use here, when all
+   pseudo-registers should count as OK.  Arguments as for
    regno_ok_for_base_p.  */
 static inline int
 ok_for_base_p_nonstrict (rtx reg, enum machine_mode mode,
@@ -852,7 +861,7 @@ record_address_regs (enum machine_mode m
       }
       break;
 
-      /* Double the importance of a allocno that is incremented or
+      /* Double the importance of an allocno that is incremented or
 	 decremented, since it would take two extra insns if it ends
 	 up in the wrong place.  */
     case POST_MODIFY:
@@ -868,7 +877,7 @@ record_address_regs (enum machine_mode m
     case PRE_INC:
     case POST_DEC:
     case PRE_DEC:
-      /* Double the importance of a allocno that is incremented or
+      /* Double the importance of an allocno that is incremented or
 	 decremented, since it would take two extra insns if it ends
 	 up in the wrong place.  If the operand is a pseudo-register,
 	 show it is being used in an INC_DEC context.  */
@@ -1045,7 +1054,7 @@ scan_one_insn (rtx insn)
 
 
 
-/* Dump allocnos costs.  */
+/* Print allocnos costs to file F.  */
 static void
 print_costs (FILE *f)
 {
@@ -1086,8 +1095,8 @@ print_costs (FILE *f)
     }
 }
 
-/* The function traverses basic blocks represented by LOOP_TREE_NODE
-   to find the costs of the allocnos.  */
+/* The function traverses BB represented by LOOP_TREE_NODE to update
+   the allocno costs.  */
 static void
 process_bb_node_for_costs (loop_tree_node_t loop_tree_node)
 {
@@ -1104,8 +1113,8 @@ process_bb_node_for_costs (loop_tree_nod
     insn = scan_one_insn (insn);
 }
 
-/* Entry function to find costs of each class for pesudos and their
-   best classes. */
+/* Find costs of register classes and memory for allocnos and their
+   best costs. */
 static void
 find_allocno_class_costs (void)
 {
@@ -1120,7 +1129,7 @@ find_allocno_class_costs (void)
 
   allocno_pref = NULL;
   /* Normally we scan the insns once and determine the best class to
-     use for each allocno.  However, if -fexpensive_optimizations are
+     use for each allocno.  However, if -fexpensive-optimizations are
      on, we do so twice, the second time using the tentative best
      classes to guide the selection.  */
   for (pass = 0; pass <= flag_expensive_optimizations; pass++)
@@ -1130,6 +1139,8 @@ find_allocno_class_costs (void)
 		 pass);
       if (pass != flag_expensive_optimizations)
 	{
+	  /* On the 1st iteration we calculates costs only for cover
+	     classes.  */
 	  for (cost_classes_num = 0;
 	       cost_classes_num < reg_class_cover_size;
 	       cost_classes_num++)
@@ -1168,11 +1179,11 @@ find_allocno_class_costs (void)
       traverse_loop_tree (FALSE, ira_loop_tree_root,
 			  process_bb_node_for_costs, NULL);
 
-      /* Now for each allocno look at how desirable each class is and
-	 find which class is preferred.  */
       if (pass == 0)
 	allocno_pref = allocno_pref_buffer;
 
+      /* Now for each allocno look at how desirable each class is and
+	 find which class is preferred.  */
       for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
 	{
 	  allocno_t a, father_a;
@@ -1187,6 +1198,7 @@ find_allocno_class_costs (void)
 	  if (regno_allocno_map [i] == NULL)
 	    continue;
 	  memset (temp_costs, 0, struct_costs_size);
+	  /* Find cost of all allocnos with the same regno.  */
 	  for (a = regno_allocno_map [i];
 	       a != NULL;
 	       a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
@@ -1197,6 +1209,8 @@ find_allocno_class_costs (void)
 		  && (father = ALLOCNO_LOOP_TREE_NODE (a)->father) != NULL
 		  && (father_a = father->regno_allocno_map [i]) != NULL)
 		{
+		  /* Propagate costs to upper levels in the region
+		     tree.  */
 		  father_a_num = ALLOCNO_NUM (father_a);
 		  for (k = 0; k < cost_classes_num; k++)
 		    COSTS_OF_ALLOCNO (total_costs, father_a_num)->cost [k]
@@ -1216,6 +1230,8 @@ find_allocno_class_costs (void)
 	    }
 	  best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1;
 	  best = ALL_REGS;
+	  /* Find best common class for all allocnos with the same
+	     regno.  */
 	  for (k = 0; k < cost_classes_num; k++)
 	    {
 	      class = cost_classes [k];
@@ -1242,11 +1258,10 @@ find_allocno_class_costs (void)
 	  if (best_cost > temp_costs->mem_cost)
 	    common_class = NO_REGS;
 	  else
-	    {
-	      common_class = best;
-	      if (class_subset_p [best] [class_translate [best]])
-		common_class = class_translate [best];
-	    }
+	    /* Make the common class a cover class.  Remember all
+	       allocnos with the same regno should have the same cover
+	       class.  */
+	    common_class = class_translate [best];
 	  for (a = regno_allocno_map [i];
 	       a != NULL;
 	       a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
@@ -1256,8 +1271,8 @@ find_allocno_class_costs (void)
 		best = NO_REGS;
 	      else
 		{	      
-		  /* Finding best class which is cover class for the
-		     register.  */
+		  /* Finding best class which is subset of the common
+		     class.  */
 		  best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1;
 		  best = ALL_REGS;
 		  for (k = 0; k < cost_classes_num; k++)
@@ -1325,8 +1340,8 @@ find_allocno_class_costs (void)
 /* Process moves involving hard regs to modify allocno hard register
    costs.  We can do this only after determining allocno cover class.
    If a hard register forms a register class, than moves with the hard
-   register are already taken into account slightly in class costs for
-   the allocno.  */
+   register are already taken into account in class costs for the
+   allocno.  */
 static void
 process_bb_node_for_hard_reg_moves (loop_tree_node_t loop_tree_node)
 {
@@ -1392,6 +1407,8 @@ process_bb_node_for_hard_reg_moves (loop
       if (flag_ira_algorithm == IRA_ALGORITHM_REGIONAL
 	  || flag_ira_algorithm == IRA_ALGORITHM_MIXED)
 	{
+	  /* Propagate changes to the upper levels in the region
+	     tree.  */
 	  loop_tree_node_t father;
 	  int regno = ALLOCNO_REGNO (a);
 	  
@@ -1465,8 +1482,7 @@ setup_allocno_cover_class_and_costs (voi
 
 
 
-/* Function called once during compiler work.  It sets up init_cost
-   whose values don't depend on the compiled function.  */
+/* Function called once during compiler work.  */
 void
 init_ira_costs_once (void)
 {
@@ -1482,7 +1498,7 @@ init_ira_costs_once (void)
   cost_classes = NULL;
 }
 
-/* The function frees different cost vectors.  */
+/* The function frees allocated temporary cost vectors.  */
 static void
 free_ira_costs (void)
 {
@@ -1564,8 +1580,8 @@ ira_costs (void)
 
 
 /* This function changes hard register costs for allocnos which lives
-   trough function calls.  The function is called only when we found
-   all intersected calls during building allocno conflicts.  */
+   through function calls.  The function is called only when we found
+   all intersected calls during building allocno live ranges.  */
 void
 tune_allocno_costs_and_cover_classes (void)
 {
Index: reload1.c
===================================================================
--- reload1.c	(revision 133412)
+++ reload1.c	(working copy)
@@ -548,10 +548,10 @@ compute_use_by_pseudos (HARD_REG_SET *to
 
       if (r < 0)
 	{
-	  /* reload_combine uses the information from
-	     DF_LIVE_IN (BASIC_BLOCK), which might still
-	     contain registers that have not actually been allocated
-	     since they have an equivalence.  */
+	  /* reload_combine uses the information from DF_LIVE_IN,
+	     which might still contain registers that have not
+	     actually been allocated since they have an
+	     equivalence.  */
 	  gcc_assert (flag_ira || reload_completed);
 	}
       else
@@ -897,6 +897,8 @@ reload (rtx first, int global)
     temp_pseudo_reg_arr [n++] = i;
   
   if (flag_ira)
+    /* Ask IRA to order pseudo-registers for better stack slot
+       sharing.  */
     sort_regnos_for_alter_reg (temp_pseudo_reg_arr, n, reg_max_ref_width);
 
   for (i = 0; i < n; i++)
@@ -1049,7 +1051,11 @@ reload (rtx first, int global)
       calculate_needs_all_insns (global);
 
       if (! flag_ira)
+	/* Don't do it for IRA.  We need this info because we don't
+	   change live_throughout and dead_or_set for chains when IRA
+	   is used.  */
 	CLEAR_REG_SET (&spilled_pseudos);
+
       did_spill = 0;
 
       something_changed = 0;
@@ -1108,6 +1114,8 @@ reload (rtx first, int global)
     }
 
   if (flag_ira)
+    /* Restore the original insn chain order for correct reload
+       work.  */
     sort_insn_chain (FALSE);
 
   /* If global-alloc was run, notify it of any register eliminations we have
@@ -1616,6 +1624,7 @@ calculate_needs_all_insns (int global)
 				       [REGNO (SET_DEST (set))]))))
 		{
 		  if (flag_ira)
+		    /* Inform IRA about the insn deletion.  */
 		    mark_memory_move_deletion (REGNO (SET_DEST (set)),
 					       REGNO (SET_SRC (set)));
 		  delete_insn (insn);
@@ -1721,6 +1730,8 @@ count_pseudo (int reg)
 
   if (REGNO_REG_SET_P (&pseudos_counted, reg)
       || REGNO_REG_SET_P (&spilled_pseudos, reg)
+      /* Ignore spilled pseudo-registers which can be here only if IRA
+	 is used.  */
       || (flag_ira && r < 0))
     return;
 
@@ -1800,6 +1811,8 @@ count_spilled_pseudo (int spilled, int s
   int r = reg_renumber[reg];
   int nregs = hard_regno_nregs[r][PSEUDO_REGNO_MODE (reg)];
 
+  /* Ignore spilled pseudo-registers which can be here only if IRA is
+     used.  */
   if ((flag_ira && r < 0)
       || REGNO_REG_SET_P (&spilled_pseudos, reg)
       || spilled + spilled_nregs <= r || r + nregs <= spilled)
@@ -1870,6 +1883,8 @@ find_reg (struct insn_chain *chain, int 
 
 	  if (flag_ira)
 	    {
+	      /* Ask IRA to find a better pseudo-register for
+		 spilling.  */
 	      for (n = j = 0; j < this_nregs; j++)
 		{
 		  int r = hard_regno_to_pseudo_regno [regno + j];
@@ -1883,7 +1898,8 @@ find_reg (struct insn_chain *chain, int 
 	      if (best_reg < 0
 		  || better_spill_reload_regno_p (regno_pseudo_regs,
 						  best_regno_pseudo_regs,
-						  rl->in, rl->out, chain->insn))
+						  rl->in, rl->out,
+						  chain->insn))
 		{
 		  best_reg = regno;
 		  for (j = 0;; j++)
@@ -2149,6 +2165,7 @@ alter_reg (int i, int from_reg, bool don
       bool shared_p = false;
 
       if (flag_ira)
+	/* Mark the spill for IRA.  */
 	SET_REGNO_REG_SET (&spilled_pseudos, i);
       x = (dont_share_p || ! flag_ira
 	   ? NULL_RTX : reuse_stack_slot (i, inherent_size, total_size));
@@ -2182,6 +2199,7 @@ alter_reg (int i, int from_reg, bool don
 	  dse_record_singleton_alias_set (alias_set, mode);
 
 	  if (! dont_share_p && flag_ira)
+	    /* Inform IRA about allocation a new stack slot.  */
 	    mark_new_stack_slot (x, i, total_size);
 	}
 
@@ -3936,6 +3954,7 @@ finish_spills (int global)
 	/* Mark it as no longer having a hard register home.  */
 	reg_renumber[i] = -1;
 	if (flag_ira)
+	  /* Inform IRA about the change.  */
 	  mark_allocation_change (i);
 	/* We will need to scan everything again.  */
 	something_changed = 1;
@@ -3964,13 +3983,13 @@ finish_spills (int global)
 	    }
 	}
 
-      /* Retry allocating the spilled pseudos.  For each reg, merge the
-	 various reg sets that indicate which hard regs can't be used,
-	 and call retry_global_alloc.
-	 We change spill_pseudos here to only contain pseudos that did not
-	 get a new hard register.  */
       if (! flag_ira)
 	{
+	  /* Retry allocating the spilled pseudos.  For each reg,
+	     merge the various reg sets that indicate which hard regs
+	     can't be used, and call retry_global_alloc.  We change
+	     spill_pseudos here to only contain pseudos that did not
+	     get a new hard register.  */
 	  for (i = FIRST_PSEUDO_REGISTER; i < (unsigned)max_regno; i++)
 	    if (reg_old_renumber[i] != reg_renumber[i])
 	      {
@@ -3986,6 +4005,10 @@ finish_spills (int global)
 	}
       else
 	{
+	  /* Retry allocating the pseudos spilled in IRA and the
+	     reload.  For each reg, merge the various reg sets that
+	     indicate which hard regs can't be used, and call
+	     reassign_pseudos.  */
 	  unsigned int n;
 
 	  for (n = 0, i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
@@ -4013,6 +4036,9 @@ finish_spills (int global)
 
       if (! flag_ira)
 	{
+	  /* Don't do it for IRA because IRA and the reload still can
+	     assign hard registers to the spilled pseudos on next
+	     reload iterations.  */
 	  AND_COMPL_REG_SET (&chain->live_throughout, &spilled_pseudos);
 	  AND_COMPL_REG_SET (&chain->dead_or_set, &spilled_pseudos);
 	}
@@ -6881,6 +6907,7 @@ emit_input_reload_insns (struct insn_cha
 		{
 		  reg_renumber[REGNO (old)] = REGNO (rl->reg_rtx);
 		  if (flag_ira)
+		    /* Inform IRA about the change.  */
 		    mark_allocation_change (REGNO (old));
 		  alter_reg (REGNO (old), -1, false);
 		}
@@ -8357,6 +8384,7 @@ delete_output_reload (rtx insn, int j, i
       /* For the debugging info, say the pseudo lives in this reload reg.  */
       reg_renumber[REGNO (reg)] = REGNO (rld[j].reg_rtx);
       if (flag_ira)
+	/* Inform IRA about the change.  */
 	mark_allocation_change (REGNO (reg));
       alter_reg (REGNO (reg), -1, false);
     }

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