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]

[yara-branch] a patch for cleaning and speeding up


This patch contains some cleaning up and speeding up. Stack memory is compacted now at the end of allocation instead of after each freeing stack memory (there is no visible degradation on SPEC except minor 0.001% code size increase for SPECFP2000). Also the table for hard register masks is used now instead of calculating mask each time.

Vlad

2006-03-22 Vladimir Makarov <vmakarov@redhat.com>

	* yara.c (reg_mode_hard_regset): New global variable.
	(set_reg_mode_hard_regset): New function.
	(yara_init_once): Call the function.
	* yara-color.c (choose_global_hard_reg, try_change_allocno): Use
	reg_mode_hard_regset instead of function ior_hard_reg_set_by_mode.
	(mem_can_assignment_compare, assign_global_can_allocnos,
	print_can_disposition): Don't use CAN_REMOVED_P.
	(yara_color): Call compact stack.
	* yara-final.c (get_reg_set_and_memory_slots,
	copy_can_be_moved_through_insn_allocno_p): Use
	reg_mode_hard_regset instead of function
	ior_hard_reg_set_by_mode.
	* yara-int.h (YARA_NO_SLOT_MOVE): Remove.
	(YARA_NO_REGCLASS_BEFORE, YARA_CLEAN_AFTER,
	YARA_PRIORITY_COLORING, YARA_NO_UPDATE_COSTS): Change values.
	(struct can): Remove removed_p, internal_copy_cost, clued_can,
	clued_can_copy_cost, dividing_nodes.
	(CAN_REMOVED_P, CAN_INTERNAL_COPY_COST, CAN_CLUED_CAN,
	CAN_CLUED_CAN_COPY_COST, CAN_DIVIDING_NODES): Remove.
	(compact_stack): New prototype.
	(ior_hard_reg_set_by_mode, and_compl_hard_reg_set_by_mode):
	Remove.
	(reg_mode_hard_regset): New external definition.
	(create_can, print_can): Don't use CAN_REMOVED_P,
	CAN_INTERNAL_COPY_COST, CAN_DIVIDING_NODES.
	* yara-trans.c (try_can_conflict_slot_moves, try_can_slot_move,
	try_copy_conflict_slot_moves, try_copy_slot_move): Remove.
	(deallocate_allocno_memory_slot): Don't call
	try_can_conflict_slot_moves.
	(deallocate_copy_memory_slot): Don't call
	try_copy_conflict_slot_moves.
	(can_compare, compact_stack): New functions.
	(ior_hard_reg_set_by_mode, and_compl_hard_reg_set_by_mode):
	Remove.
	(assign_copy_secondary, assign_allocno_hard_regno,
	assign_one_allocno, assign_elimination_reg,
	find_interm_elimination_reg): Use reg_mode_hard_regset instead of
	function ior_hard_reg_set_by_mode.



Index: yara.c
===================================================================
--- yara.c	(revision 112203)
+++ yara.c	(working copy)
@@ -49,6 +49,12 @@ Software Foundation, 51 Franklin Street,
 FILE *yara_dump_file;
 int yara_max_uid; /* before the allocation */
 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 regs.  An
+   element is defined only if the corresponding value of
+   HARD_REGNO_MODE_OK is true.  */
+HARD_REG_SET reg_mode_hard_regset [FIRST_PSEUDO_REGISTER] [NUM_MACHINE_MODES];
 int memory_move_cost [MAX_MACHINE_MODE] [N_REG_CLASSES] [2];
 int register_move_cost [MAX_MACHINE_MODE] [N_REG_CLASSES] [N_REG_CLASSES];
 bool class_subset_p [N_REG_CLASSES] [N_REG_CLASSES];
@@ -79,6 +85,28 @@ set_inner_mode (void)
 
 
 
+/* The function sets up map REG_MODE_HARD_REGSET.  */
+static void
+set_reg_mode_hard_regset (void)
+{
+  int i, m, hard_regno;
+
+  for (m = 0; m < NUM_MACHINE_MODES; m++)
+    for (hard_regno = 0; hard_regno < FIRST_PSEUDO_REGISTER; hard_regno++)
+      {
+	CLEAR_HARD_REG_SET (reg_mode_hard_regset [hard_regno] [m]);
+	if (HARD_REGNO_MODE_OK (hard_regno, m))
+	  for (i = hard_regno_nregs [hard_regno] [m] - 1; i >= 0; i--)
+	    {
+	      gcc_assert (hard_regno + i < FIRST_PSEUDO_REGISTER);
+	      SET_HARD_REG_BIT (reg_mode_hard_regset [hard_regno] [m],
+				hard_regno + i);
+	    }
+      }
+}
+
+
+
 static void
 set_class_subset_and_move_costs (void)
 {
@@ -363,6 +391,7 @@ yara_init_once (void)
   CLEAR_HARD_REG_SET (zero_hard_reg_set);
   SET_HARD_REG_SET (one_hard_reg_set);
   set_inner_mode ();
+  set_reg_mode_hard_regset ();
   set_class_subset_and_move_costs ();
   set_non_alloc_regs ();
   set_up_class_hard_regs ();
Index: yara-color.c
===================================================================
--- yara-color.c	(revision 112203)
+++ yara-color.c	(working copy)
@@ -1280,17 +1280,17 @@ choose_global_hard_reg (can_t can)
 	    if (cover_class != CAN_COVER_CLASS (conflict_can)
 		|| CAN_ASSIGNED_P (conflict_can))
 	      continue;
-	    ior_hard_reg_set_by_mode (best_hard_regno, mode,
-				      &CAN_CONFLICT_HARD_REGS (conflict_can));
+	    IOR_HARD_REG_SET (CAN_CONFLICT_HARD_REGS (conflict_can),
+			      reg_mode_hard_regset [best_hard_regno] [mode]);
 	    can_vec2 = CAN_CONFLICT_CAN_VEC (conflict_can);
 	    for (j = 0; (conflict_can2 = can_vec2 [j]) != NULL; j++)
 	      {
 		if (cover_class != CAN_COVER_CLASS (conflict_can2)
 		    || CAN_ASSIGNED_P (conflict_can2))
 		  continue;
-		ior_hard_reg_set_by_mode
-		  (best_hard_regno, mode,
-		   &CAN_BIASED_HARD_REGS (conflict_can2));
+		IOR_HARD_REG_SET (CAN_BIASED_HARD_REGS (conflict_can2),
+				  reg_mode_hard_regset 
+				  [best_hard_regno] [mode]);
 	      }
 	  }
     }
@@ -1839,18 +1839,10 @@ mem_can_assignment_compare (const void *
   can_t c2 = *(can_t *) c2p;
   int diff;
 
-  if (CAN_REMOVED_P (c1) && ! CAN_REMOVED_P (c2))
-    return 1;
-  else if (! CAN_REMOVED_P (c1) && CAN_REMOVED_P (c2))
-    return -1;
-  else
-    {
-      diff = ((CAN_MEMORY_COST (c2) + CAN_INTERNAL_COPY_COST (c2))
-	      - (CAN_MEMORY_COST (c1) + CAN_INTERNAL_COPY_COST (c1)));
-      if (diff != 0)
-	return diff;
-      return CAN_NUM (c1) - CAN_NUM (c2);
-    }
+  diff = (CAN_MEMORY_COST (c2) - CAN_MEMORY_COST (c1));
+  if (diff != 0)
+    return diff;
+  return CAN_NUM (c1) - CAN_NUM (c2);
 }
 
 /* Propagate can allocation to the corresponding allocnos.  */
@@ -1872,8 +1864,6 @@ assign_global_can_allocnos (void)
   for (i = 0; i < cans_num; i++)
     {
       can = sorted_cans [i];
-      if (CAN_REMOVED_P (can))
- 	continue;
       if (! CAN_GLOBAL_P (can))
 	continue;
       cover_class = CAN_COVER_CLASS (can);
@@ -2555,10 +2545,7 @@ print_can_disposition (FILE *f, bool glo
       can = cans [i];
       if (CAN_GLOBAL_P (can) ^ global_p)
 	continue;
-      if (CAN_REMOVED_P (can))
-	fprintf (f, "  %4d:--", CAN_NUM (can));
-      else
-	fprintf (f, "  %4d:%2d", CAN_NUM (can), CAN_HARD_REGNO (can));
+      fprintf (f, "  %4d:%2d", CAN_NUM (can), CAN_HARD_REGNO (can));
       num++;
       if (num % 8 == 0)
 	fprintf (f, "\n");
@@ -2607,7 +2594,8 @@ try_change_allocno (allocno_t old, bool 
 
       start = get_maximal_part_start_hard_regno (new_allocno_hard_regno, old);
       gcc_assert (start >= 0);
-      ior_hard_reg_set_by_mode (start, get_allocation_mode (old), &regs);
+      IOR_HARD_REG_SET
+	(regs, reg_mode_hard_regset [start] [get_allocation_mode (old)]);
       AND_COMPL_HARD_REG_SET (regs, no_alloc_regs);
       cl = smallest_superset_class (regs);
     }
@@ -3025,6 +3013,7 @@ yara_color (void)
   eliminate_virtual_registers (provide_allocno_elimination_class_hard_reg);
   if ((YARA_PARAMS & YARA_NO_ALLOCNO_COALESCING) == 0)
     coalesce_allocnos ();
+  compact_stack ();
   reload_in_progress = 0;
   yara_free (saved_conflict_cans);
   yara_free_bitmap (conflict_can_bitmap);
Index: yara-final.c
===================================================================
--- yara-final.c	(revision 112203)
+++ yara-final.c	(working copy)
@@ -1450,8 +1450,9 @@ get_reg_set_and_memory_slots (copy_t cp,
 	      && ALLOCNO_REGNO (src) >= 0)
 	    {
 	      gcc_assert (HARD_REGISTER_NUM_P (ALLOCNO_REGNO (src)));
-	      ior_hard_reg_set_by_mode (ALLOCNO_REGNO (src),
-					ALLOCNO_MODE (src), regs);
+	      IOR_HARD_REG_SET (*regs,
+				reg_mode_hard_regset 
+				[ALLOCNO_REGNO (src)] [ALLOCNO_MODE (src)]);
 	    }
 	}
     }
@@ -1466,8 +1467,9 @@ get_reg_set_and_memory_slots (copy_t cp,
 	      && ALLOCNO_REGNO (dst) >= 0)
 	    {
 	      gcc_assert (HARD_REGISTER_NUM_P (ALLOCNO_REGNO (dst)));
-	      ior_hard_reg_set_by_mode (ALLOCNO_REGNO (dst),
-					ALLOCNO_MODE (dst), regs);
+	      IOR_HARD_REG_SET (*regs,
+				reg_mode_hard_regset 
+				[ALLOCNO_REGNO (dst)] [ALLOCNO_MODE (dst)]);
 	    }
 	}
     }
@@ -1546,7 +1548,8 @@ copy_can_be_moved_through_insn_allocno_p
   if (INSN_ALLOCNO_USE_WITHOUT_CHANGE_P (a) && ALLOCNO_REGNO (a) >= 0)
     {
       gcc_assert (HARD_REGISTER_NUM_P (ALLOCNO_REGNO (a)));
-      ior_hard_reg_set_by_mode (ALLOCNO_REGNO (a), ALLOCNO_MODE (a), &a_regs);
+      IOR_HARD_REG_SET
+	(a_regs, reg_mode_hard_regset [ALLOCNO_REGNO (a)] [ALLOCNO_MODE (a)]);
     }
   a_slot = ALLOCNO_MEMORY_SLOT (a);
   AND_HARD_REG_SET (a_regs, regs);
Index: yara-int.h
===================================================================
--- yara-int.h	(revision 112203)
+++ yara-int.h	(working copy)
@@ -27,11 +27,10 @@ Software Foundation, 51 Franklin Street,
 #define YARA_NO_ALLOCNO_COALESCING 8
 #define YARA_NO_COPY_SYNC 16
 #define YARA_NO_MOVE_SYNC 32
-#define YARA_NO_SLOT_MOVE 64
-#define YARA_NO_REGCLASS_BEFORE 128
-#define YARA_CLEAN_AFTER 256
-#define YARA_PRIORITY_COLORING 512
-#define YARA_NO_UPDATE_COSTS 1024
+#define YARA_NO_REGCLASS_BEFORE 64
+#define YARA_CLEAN_AFTER 128
+#define YARA_PRIORITY_COLORING 256
+#define YARA_NO_UPDATE_COSTS 512
 
 
 #ifdef ENABLE_CHECKING
@@ -746,8 +745,6 @@ struct can
   bool global_p;
   /* True if we already spilled the can during local allocation.  */  
   bool spill_p;
-  /* True if the can has been clued to another one.  */
-  bool removed_p;
   /* True if hard register or memory has been assigned to the can.  */
   bool assigned_p;
   /* Mode of allocnos belonging to the can.  */
@@ -768,16 +765,6 @@ struct can
   /* Cans in a bucket chained by the following two members.  */
   struct can *next_bucket_can;
   struct can *prev_bucket_can;
-  /* Cost of internal copies.  */
-  int internal_copy_cost;
-  /* The best can to clue with given can.  The subsequent two members
-     are defined only if the following member value is not NULL.  */
-  struct can *clued_can;
-  /* Cost of copies between given can and the clued can.  */
-  int clued_can_copy_cost;
-  /* Number of common conflict graph nodes on distance from 1 from
-     give node and the clued node.  */
-  int dividing_nodes;
 };
 
 #define CAN_NUM(C) ((C)->can_num)
@@ -793,7 +780,6 @@ struct can
 #define CAN_IN_GRAPH_P(C) ((C)->in_graph_p)
 #define CAN_GLOBAL_P(C) ((C)->global_p)
 #define CAN_SPILL_P(C) ((C)->spill_p)
-#define CAN_REMOVED_P(C) ((C)->removed_p)
 #define CAN_ASSIGNED_P(C) ((C)->assigned_p)
 #define CAN_MODE(C) ((C)->mode)
 #define CAN_COPIES(C) ((C)->can_copies)
@@ -804,10 +790,6 @@ struct can
 #define CAN_MEMORY_COST(C) ((C)->memory_cost)
 #define CAN_NEXT_BUCKET_CAN(C) ((C)->next_bucket_can)
 #define CAN_PREV_BUCKET_CAN(C) ((C)->prev_bucket_can)
-#define CAN_INTERNAL_COPY_COST(C) ((C)->internal_copy_cost)
-#define CAN_CLUED_CAN(C) ((C)->clued_can)
-#define CAN_CLUED_CAN_COPY_COST(C) ((C)->clued_can_copy_cost)
-#define CAN_DIVIDING_NODES(C) ((C)->dividing_nodes)
 
 /* Array of references to cans.  */
 extern can_t *cans;
@@ -936,11 +918,10 @@ extern int get_paradoxical_subreg_memory
 extern enum machine_mode get_copy_mode (copy_t);
 extern void get_copy_loc (copy_t, bool, enum machine_mode *,
 			  int *, struct memory_slot **, int *);
+void compact_stack (void);
 extern bool hard_reg_in_set_p (int, enum machine_mode, HARD_REG_SET);
 extern bool hard_reg_not_in_set_p (int, enum machine_mode, HARD_REG_SET);
-extern void ior_hard_reg_set_by_mode (int, enum machine_mode, HARD_REG_SET *);
-extern void and_compl_hard_reg_set_by_mode (int, enum machine_mode,
-					    HARD_REG_SET *);
+
 extern int allocno_copy_cost (allocno_t);
 #ifdef HAVE_ANY_SECONDARY_MOVES
 extern void unassign_copy_secondary (copy_t);
@@ -1005,6 +986,8 @@ extern void yara_rewrite (void);
 extern HARD_REG_SET zero_hard_reg_set;
 extern HARD_REG_SET one_hard_reg_set;
 extern unsigned char mode_inner_mode [NUM_MACHINE_MODES];
+extern HARD_REG_SET reg_mode_hard_regset
+                    [FIRST_PSEUDO_REGISTER] [NUM_MACHINE_MODES];
 extern int memory_move_cost [MAX_MACHINE_MODE] [N_REG_CLASSES] [2];
 extern int register_move_cost [MAX_MACHINE_MODE] [N_REG_CLASSES]
                               [N_REG_CLASSES];
Index: yara-ir.c
===================================================================
--- yara-ir.c	(revision 112203)
+++ yara-ir.c	(working copy)
@@ -4841,7 +4841,6 @@ create_can (void)
   CLEAR_HARD_REG_SET (CAN_BIASED_HARD_REGS (can));
   CAN_FREQ (can) = 0;
   CAN_IN_GRAPH_P (can) = false;
-  CAN_REMOVED_P (can) = false;
   CAN_ASSIGNED_P (can) = false;
   CAN_HARD_REGNO (can) = -1;
   CAN_SLOTNO (can) = CAN_NUM (can);
@@ -4853,8 +4852,6 @@ create_can (void)
   CAN_HARD_REG_COSTS (can) = NULL;
   CAN_COPIES (can) = NULL;
   CAN_LEFT_CONFLICTS_NUM (can) = -1;
-  CAN_INTERNAL_COPY_COST (can) = 0;
-  CAN_DIVIDING_NODES (can) = 0;
   CAN_COVER_CLASS (can) = NO_REGS;
   CAN_MEMORY_COST (can) = CAN_COVER_CLASS_COST (can) = 0;
   CAN_NEXT_BUCKET_CAN (can) = CAN_PREV_BUCKET_CAN (can) = NULL;
@@ -5715,16 +5712,14 @@ print_can (FILE *f, can_t can)
   allocno_t a, *can_allocnos;
 
   fprintf
-    (f, "%scan#%d (%s %s(%d,%d) freq %d (call %d) r%d m%d %s%s%s%sconfl %d dividing %d) allocnos:\n  ",
+    (f, "%scan#%d (%s %s(%d,%d) freq %d (call %d) r%d m%d %s%s%sconfl %d) allocnos:\n  ",
      (CAN_GLOBAL_P (can) ? "g" : ""), CAN_NUM (can),
      GET_MODE_NAME (CAN_MODE (can)), reg_class_names [CAN_COVER_CLASS (can)],
      CAN_COVER_CLASS_COST (can), CAN_MEMORY_COST (can),
      CAN_FREQ (can), CAN_CALL_FREQ (can), CAN_HARD_REGNO (can),
      CAN_SLOTNO (can),
      (CAN_CALL_P (can) ? "call " : ""), (CAN_IN_GRAPH_P (can) ? "in " : ""),
-     (CAN_REMOVED_P (can) ? "removed " : ""),
-     (CAN_SPILL_P (can) ? "spill " : ""), CAN_LEFT_CONFLICTS_NUM (can),
-     CAN_DIVIDING_NODES (can));
+     (CAN_SPILL_P (can) ? "spill " : ""), CAN_LEFT_CONFLICTS_NUM (can));
   can_allocnos = CAN_ALLOCNOS (can);
   for (i = 0; (a = can_allocnos [i]) != NULL; i++)
     {
Index: yara-trans.c
===================================================================
--- yara-trans.c	(revision 112203)
+++ yara-trans.c	(working copy)
@@ -85,13 +85,7 @@ static void remove_memory_slot_end (int)
 static void increase_align_count (int);
 static void decrease_align_count (int);
 static void initiate_memory_slots (void);
-static void try_can_conflict_slot_moves (can_t);
 static void register_slot_start_change (int, struct memory_slot *);
-static void try_can_slot_move (can_t);
-#ifdef SECONDARY_MEMORY_NEEDED
-static void try_copy_conflict_slot_moves (copy_t);
-static void try_copy_slot_move (copy_t);
-#endif
 static void register_memory_slot_usage (struct memory_slot *, int);
 static void unregister_memory_slot_usage (struct memory_slot *, int);
 static void allocate_allocno_memory_slot (allocno_t);
@@ -100,6 +94,7 @@ static void deallocate_allocno_memory_sl
 static void allocate_copy_memory_slot (copy_t);
 static void deallocate_copy_memory_slot (copy_t);
 #endif
+static int can_compare (const void *, const void *);
 static void finish_memory_slots (void);
 
 static void set_up_temp_mems_and_addresses (void);
@@ -636,36 +631,6 @@ can_copy_conflict_p (can_t can, copy_t c
 #endif
 
 static void
-try_can_conflict_slot_moves (can_t can)
-{
-  unsigned int i;
-  int num;
-  can_t another_can, *can_vec;
-  bitmap_iterator bi;
-
-  can_vec = CAN_CONFLICT_CAN_VEC (can);
-  for (i = 0; (another_can = can_vec [i]) != NULL; i++)
-    {
-      num = CAN_SLOTNO (another_can);
-      if (can_memory_slots [num] != NULL
-	  && can_memory_slots [num]->mem == NULL_RTX)
-	try_can_slot_move (another_can);
-    }
-#ifdef SECONDARY_MEMORY_NEEDED
-  EXECUTE_IF_SET_IN_BITMAP (secondary_memory_copies, 0, i, bi)
-    {
-      if (can_copy_conflict_p (can, copies [i]))
-	{
-	  gcc_assert (COPY_SECONDARY_CHANGE_ADDR (copies [i]) != NULL
-		      && COPY_MEMORY_SLOT (copies [i]) != NULL
-		      && COPY_MEMORY_SLOT (copies [i])->mem == NULL_RTX);
-	  try_copy_slot_move (copies [i]);
-	}
-    }
-#endif
-}
-
-static void
 register_slot_start_change (int new, struct memory_slot *slot)
 {
   log_memory_slot (slot);
@@ -678,103 +643,6 @@ register_slot_start_change (int new, str
 #endif
 }
 
-static void
-try_can_slot_move (can_t can)
-{
-  unsigned int i;
-  int *vec;
-  int start, align;
-  struct memory_slot *conflict_slot;
-  struct memory_slot *slot = can_memory_slots [CAN_SLOTNO (can)];
-  int num;
-  bitmap_iterator bi;
-
-  gcc_assert (slot != NULL && slot->mem == NULL_RTX);
-  align = slotno_max_ref_align [CAN_SLOTNO (can)];
-  free_all_stack_memory ();
-  vec = slotno_conflicts [CAN_SLOTNO (can)];
-  if (vec != NULL)
-    for (i = 0; (num = vec [i]) >= 0; i++)
-      if ((conflict_slot = can_memory_slots [num]) != NULL
-	  && conflict_slot->mem == NULL_RTX)
-	reserve_stack_memory (conflict_slot->start, conflict_slot->size);
-#ifdef SECONDARY_MEMORY_NEEDED
-  EXECUTE_IF_SET_IN_BITMAP (secondary_memory_copies, 0, i, bi)
-    {
-      if (can_copy_conflict_p (can, copies [i]))
-	{
-	  gcc_assert (COPY_SECONDARY_CHANGE_ADDR (copies [i]) != NULL);
-	  conflict_slot = COPY_MEMORY_SLOT (copies [i]);
-	  gcc_assert (conflict_slot != NULL
-		      && conflict_slot->mem == NULL_RTX);
-	  reserve_stack_memory (conflict_slot->start, conflict_slot->size);
-	}
-      }
-#endif
-  start = find_free_stack_memory (slot->size, align);
-  gcc_assert (slot->start >= start);
-  if (start == slot->start)
-    return;
-  register_slot_start_change (start, slot);
-  slot->start = start;
-  if ((YARA_PARAMS & YARA_NO_SLOT_MOVE) == 0)
-    try_can_conflict_slot_moves (can);
-}
-
-#ifdef SECONDARY_MEMORY_NEEDED
-static void
-try_copy_conflict_slot_moves (copy_t cp)
-{
-  int i;
-  allocno_t a;
-  can_t can;
-  allocno_t *vec;
-
-  vec = COPY_ALLOCNO_CONFLICT_VEC (cp);
-  for (i = 0; (a = vec [i]) != NULL; i++)
-    {
-      can = ALLOCNO_CAN (a);
-      if (can == NULL)
-	continue;
-      if (can_memory_slots [CAN_SLOTNO (can)] != NULL
-	  && can_memory_slots [CAN_SLOTNO (can)]->mem == NULL_RTX)
-	try_can_slot_move (can);
-    }
-}
-
-static void
-try_copy_slot_move (copy_t cp)
-{
-  int i, start, align;
-  allocno_t a;
-  can_t can;
-  struct memory_slot *conflict_slot;
-  struct memory_slot *slot = COPY_MEMORY_SLOT (cp);
-  allocno_t *vec;
-
-  gcc_assert (slot != NULL);
-  free_all_stack_memory ();
-  align = get_stack_align (COPY_MEMORY_MODE (cp)) / BITS_PER_UNIT;
-  vec = COPY_ALLOCNO_CONFLICT_VEC (cp);
-  for (i = 0; (a = vec [i]) != NULL; i++)
-    {
-      can = ALLOCNO_CAN (a);
-      if (can == NULL)
-	continue;
-      if ((conflict_slot = can_memory_slots [CAN_SLOTNO (can)]) != NULL
-	  && conflict_slot->mem == NULL_RTX)
-	reserve_stack_memory (conflict_slot->start, conflict_slot->size);
-    }
-  start = find_free_stack_memory (slot->size, align);
-  gcc_assert (slot->start >= start);
-  if (start == slot->start)
-    return;
-  register_slot_start_change (start, slot);
-  slot->start = start;
-  try_copy_conflict_slot_moves (cp);
-}
-#endif
-
 void
 print_memory_slot (FILE *f, const char *head, int indent,
 		   struct memory_slot *slot)
@@ -1142,12 +1010,8 @@ deallocate_allocno_memory_slot (allocno_
     {
 #ifdef REGNO_SLOT
       regno_memory_slots [regno] = NULL;
-      if ((YARA_PARAMS & YARA_NO_SLOT_MOVE) == 0)
-	try_regno_conflict_slot_moves (regno);
 #else
       can_memory_slots [num] = NULL;
-      if ((YARA_PARAMS & YARA_NO_SLOT_MOVE) == 0)
-	try_can_conflict_slot_moves (can);
 #endif
     }
   ALLOCNO_MEMORY_SLOT_OFFSET (a) = 0;
@@ -1199,11 +1063,123 @@ deallocate_copy_memory_slot (copy_t cp)
   unregister_memory_slot_usage (slot, align);
   COPY_MEMORY_SLOT (cp) = NULL;
   bitmap_clear_bit (secondary_memory_copies, COPY_NUM (cp));
-  if (slot->allocnos_num == 0)
-    try_copy_conflict_slot_moves (cp);
 }
 #endif
 
+/* The function is used to sort cans in order to put cans with higher
+   memory cost first.  */
+static int
+can_compare (const void *c1p, const void *c2p)
+{
+  can_t c1 = *(can_t *) c1p;
+  can_t c2 = *(can_t *) c2p;
+  int diff;
+
+  diff = (CAN_MEMORY_COST (c2) - CAN_MEMORY_COST (c1));
+  if (diff != 0)
+    return diff;
+  return CAN_NUM (c1) - CAN_NUM (c2);
+}
+
+/* The following function tries to compact stack.  It might decrease
+   (but never increase) the displacement from the stack start.  */
+void
+compact_stack (void)
+{
+  int i, j, n, slot_no;
+  can_t can;
+  int *vec;
+  int start, align;
+  allocno_t a, *a_vec;
+  copy_t cp;
+  struct memory_slot *slot, *conflict_slot;
+  bitmap_iterator bi;
+  varray_type slot_memory_can_varray;
+
+  /* Sort cans to consider more higher cost can moves first.  */
+  VARRAY_GENERIC_PTR_NOGC_INIT (slot_memory_can_varray,
+				cans_num, "cans with slot memory");
+  for (i = 0; i < cans_num; i++)
+    {
+      can = cans [i];
+      if (can == NULL)
+	continue;
+      slot_no = CAN_SLOTNO (can);
+      if ((slot = can_memory_slots [slot_no]) == NULL || slot->mem != NULL_RTX)
+	continue;
+      VARRAY_PUSH_GENERIC_PTR (slot_memory_can_varray, can);
+    }
+  if (VARRAY_ACTIVE_SIZE (slot_memory_can_varray) != 0)
+    qsort (&VARRAY_GENERIC_PTR (slot_memory_can_varray, 0),
+	   VARRAY_ACTIVE_SIZE (slot_memory_can_varray),
+	   sizeof (can_t), can_compare);
+  /* Try to move can slots to closer stack start.  */
+  for (i = 0; i < (int) VARRAY_ACTIVE_SIZE (slot_memory_can_varray); i++)
+    {
+      can = VARRAY_GENERIC_PTR (slot_memory_can_varray, i);
+      if (can == NULL)
+	continue;
+      slot_no = CAN_SLOTNO (can);
+      if ((slot = can_memory_slots [slot_no]) == NULL || slot->mem != NULL_RTX)
+	continue;
+      align = slotno_max_ref_align [slot_no];
+      free_all_stack_memory ();
+      vec = slotno_conflicts [slot_no];
+      if (vec != NULL)
+	for (j = 0; (n = vec [j]) >= 0; j++)
+	  if ((conflict_slot = can_memory_slots [n]) != NULL
+	      && conflict_slot->mem == NULL_RTX)
+	    reserve_stack_memory (conflict_slot->start, conflict_slot->size);
+#ifdef SECONDARY_MEMORY_NEEDED
+      EXECUTE_IF_SET_IN_BITMAP (secondary_memory_copies, 0, j, bi)
+	{
+	  if (can_copy_conflict_p (can, copies [j]))
+	    {
+	      gcc_assert (COPY_SECONDARY_CHANGE_ADDR (copies [j]) != NULL);
+	      conflict_slot = COPY_MEMORY_SLOT (copies [j]);
+	      gcc_assert (conflict_slot != NULL
+			  && conflict_slot->mem == NULL_RTX);
+	      reserve_stack_memory (conflict_slot->start, conflict_slot->size);
+	    }
+	}
+#endif
+      start = find_free_stack_memory (slot->size, align);
+      gcc_assert (slot->start >= start);
+      if (start == slot->start)
+	continue;
+      register_slot_start_change (start, slot);
+      slot->start = start;
+    }
+  VARRAY_FREE (slot_memory_can_varray);
+#ifdef SECONDARY_MEMORY_NEEDED
+  /* Try to move slots used for secondary memory closer to the stack
+     start.  */
+  EXECUTE_IF_SET_IN_BITMAP (secondary_memory_copies, 0, i, bi)
+    {
+      cp = copies [i];
+      slot = COPY_MEMORY_SLOT (cp);
+      free_all_stack_memory ();
+      align = get_stack_align (COPY_MEMORY_MODE (cp)) / BITS_PER_UNIT;
+      a_vec = COPY_ALLOCNO_CONFLICT_VEC (cp);
+      for (j = 0; (a = a_vec [j]) != NULL; j++)
+	{
+	  can = ALLOCNO_CAN (a);
+	  if (can == NULL)
+	    continue;
+	  if ((conflict_slot = can_memory_slots [CAN_SLOTNO (can)]) != NULL
+	      && conflict_slot->mem == NULL_RTX)
+	    reserve_stack_memory (conflict_slot->start, conflict_slot->size);
+	}
+      start = find_free_stack_memory (slot->size, align);
+      gcc_assert (slot->start >= start);
+      if (start == slot->start)
+	continue;
+      register_slot_start_change (start, slot);
+      slot->start = start;
+    }
+#endif
+}
+
 static void
 finish_memory_slots (void)
 {
@@ -1258,28 +1234,6 @@ hard_reg_not_in_set_p (int hard_regno, e
   return true;
 }
 
-void
-ior_hard_reg_set_by_mode (int hard_regno, enum machine_mode mode,
-			  HARD_REG_SET *hard_regset)
-{
-  int i;
-
-  gcc_assert (hard_regno >= 0 && HARD_REGISTER_NUM_P (hard_regno));
-  for (i = hard_regno_nregs [hard_regno] [mode] - 1; i >= 0; i--)
-    SET_HARD_REG_BIT (*hard_regset, hard_regno + i);
-}
-
-void
-and_compl_hard_reg_set_by_mode (int hard_regno, enum machine_mode mode,
-				HARD_REG_SET *hard_regset)
-{
-  int i;
-
-  gcc_assert (hard_regno >= 0 && HARD_REGISTER_NUM_P (hard_regno));
-  for (i = hard_regno_nregs [hard_regno] [mode] - 1; i >= 0; i--)
-    CLEAR_HARD_REG_BIT (*hard_regset, hard_regno + i);
-}
-
 
 
 static GTY(()) rtx temp_const_int;
@@ -1807,9 +1761,9 @@ assign_copy_secondary (copy_t cp)
 	    x = temp_reg [(int) mode];
 	    REGNO (x) = regno;
 	    reg_renumber [regno] = ALLOCNO_HARD_REGNO (a2);
-	    ior_hard_reg_set_by_mode (ALLOCNO_HARD_REGNO (a2), mode,
-				      &prohibited_hard_regs);
-	    
+	    IOR_HARD_REG_SET
+	      (prohibited_hard_regs,
+	       reg_mode_hard_regset [ALLOCNO_HARD_REGNO (a2)] [mode]);
 	  }
 	else if ((slot = ALLOCNO_MEMORY_SLOT (a2)) != NULL)
 	  {
@@ -1960,11 +1914,12 @@ assign_copy_secondary (copy_t cp)
 	    if (interm_hard_regno < 0)
 	      return false;
 	    mark_regno_allocation (interm_hard_regno, interm_mode);
-	    ior_hard_reg_set_by_mode (interm_hard_regno, interm_mode,
-				      &COPY_INTERM_SCRATCH_HARD_REGSET (cp));
-	    
-	    ior_hard_reg_set_by_mode (interm_hard_regno, interm_mode,
-				      &prohibited_hard_regs);
+	    IOR_HARD_REG_SET
+	      (COPY_INTERM_SCRATCH_HARD_REGSET (cp),
+	       reg_mode_hard_regset [interm_hard_regno] [interm_mode]);
+	    IOR_HARD_REG_SET
+	      (prohibited_hard_regs,
+	       reg_mode_hard_regset [interm_hard_regno] [interm_mode]);
 	  }
 	if (scratch_class != NO_REGS)
 	  {
@@ -1978,9 +1933,9 @@ assign_copy_secondary (copy_t cp)
 		return false;
 	      }
 	    mark_regno_allocation (scratch_hard_regno, scratch_mode);
-	    ior_hard_reg_set_by_mode (scratch_hard_regno, scratch_mode,
-				      &COPY_INTERM_SCRATCH_HARD_REGSET (cp));
-	    
+	    IOR_HARD_REG_SET
+	      (COPY_INTERM_SCRATCH_HARD_REGSET (cp),
+	       reg_mode_hard_regset [scratch_hard_regno] [scratch_mode]);
 	  }
 	COPY_ICODE (cp) = icode;
 	COPY_INTERM_MODE (cp) = interm_mode;
@@ -2505,7 +2460,8 @@ assign_allocno_hard_regno (allocno_t a, 
   start = get_maximal_part_start_hard_regno (hard_regno, a);
   gcc_assert (start >= 0);
   mark_regno_allocation (start, allocation_mode);
-  ior_hard_reg_set_by_mode (start, allocation_mode, &ALLOCNO_HARD_REGSET (a));
+  IOR_HARD_REG_SET
+    (ALLOCNO_HARD_REGSET (a), reg_mode_hard_regset [start] [allocation_mode]);
   global_allocation_cost += allocno_copy_cost (a);
   return true;
 }
@@ -2604,7 +2560,8 @@ assign_one_allocno (allocno_t a, enum re
   start = get_maximal_part_start_hard_regno (hard_regno, a);
   gcc_assert (start >= 0);
   mark_regno_allocation (start, allocation_mode);
-  ior_hard_reg_set_by_mode (start, allocation_mode, &ALLOCNO_HARD_REGSET (a));
+  IOR_HARD_REG_SET
+    (ALLOCNO_HARD_REGSET (a), reg_mode_hard_regset [start] [allocation_mode]);
   global_allocation_cost += allocno_copy_cost (a);
   return true;
 }
@@ -2782,8 +2739,8 @@ assign_elimination_reg (allocno_t a, enu
     += COST_FACTOR * register_move_cost [Pmode] [BASE_REG_CLASS] [cl];
   INSN_ALLOCNO_INTERM_ELIMINATION_REGNO (a) = hard_regno;
   mark_regno_allocation (hard_regno, Pmode);
-  ior_hard_reg_set_by_mode (hard_regno, Pmode,
-			    &INSN_ALLOCNO_INTERM_ELIMINATION_REGSET (a));
+  IOR_HARD_REG_SET (INSN_ALLOCNO_INTERM_ELIMINATION_REGSET (a),
+		    reg_mode_hard_regset [hard_regno] [Pmode]);
   return true;
 }
 
@@ -3084,8 +3041,9 @@ find_interm_elimination_reg (allocno_t a
     {
       INSN_ALLOCNO_INTERM_ELIMINATION_REGNO (a) = interm_elimination_regno;
       mark_regno_allocation (interm_elimination_regno, Pmode);
-      ior_hard_reg_set_by_mode (interm_elimination_regno, Pmode,
-				&INSN_ALLOCNO_INTERM_ELIMINATION_REGSET (a));
+      IOR_HARD_REG_SET
+	(INSN_ALLOCNO_INTERM_ELIMINATION_REGSET (a),
+	 reg_mode_hard_regset [interm_elimination_regno] [Pmode]);
       return true;
     }
   if (assign_elimination_reg (a, cl, possible_regs, -1))

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