diff mbox

[7/9] ira-color

Message ID alpine.LNX.2.21.1704011919300.3249@anthias.pfeifer.com
State New
Headers show

Commit Message

Gerald Pfeifer April 1, 2017, 5:21 p.m. UTC
On Sat, 1 Apr 2017, Andrew Jenner wrote:
> In the course of working with ia16, I found a case where the sorted_allocnos
> array in ira-color.c requires more than ira_allocnos_num entries. The
> following patch allows this array to expand when this happens.
> 
> 2017-04-01  Andrew Jenner  <andrew@codesourcery.com>
> 
> 	* ira-color.c (n_sorted_allocnos): New variable.
> 	(improve_allocation): Use it.
> 	(ira_initiate_assign): Initialize it.
> 	(fast_allocation): Likewise.

General improvements/fixes like this you may want to submit independently
of your port and copy the respective maintainers (such as Vladimir for
register allocation who I'm adding now).

Gerald

Comments

Jeff Law April 3, 2017, 3:28 p.m. UTC | #1
On 04/01/2017 11:21 AM, Gerald Pfeifer wrote:
> On Sat, 1 Apr 2017, Andrew Jenner wrote:
>> In the course of working with ia16, I found a case where the
>> sorted_allocnos
>> array in ira-color.c requires more than ira_allocnos_num entries. The
>> following patch allows this array to expand when this happens.
>>
>> 2017-04-01  Andrew Jenner  <andrew@codesourcery.com>
>>
>>     * ira-color.c (n_sorted_allocnos): New variable.
>>     (improve_allocation): Use it.
>>     (ira_initiate_assign): Initialize it.
>>     (fast_allocation): Likewise.
>
> General improvements/fixes like this you may want to submit independently
> of your port and copy the respective maintainers (such as Vladimir for
> register allocation who I'm adding now).
Right.  ANd it would be helpful to have more information on how this 
happened.  Otherwise Vlad and the rest of the team have to guess what 
might have happened -- we might guess wrong leading to an incorrect 
conclusion about the correctness of the patch.

Testcases help considerably as well.

jeff
diff mbox

Patch

Index: gcc/ira-color.c
===================================================================
--- gcc/ira-color.c	(revision 475331)
+++ gcc/ira-color.c	(revision 475455)
@@ -178,6 +178,7 @@  static bitmap consideration_allocno_bitm

 /* All allocnos sorted according their priorities.  */
 static ira_allocno_t *sorted_allocnos;
+static int n_sorted_allocnos;

 /* Vec representing the stack of allocnos used during coloring.  */
 static vec<ira_allocno_t> allocno_stack_vec;
@@ -2937,6 +2938,17 @@  improve_allocation (void)
 		/* No intersection.  */
 		continue;
 	      ALLOCNO_HARD_REGNO (conflict_a) = -1;
+	      if (n == n_sorted_allocnos)
+		{
+		  ira_allocno_t *sorted_allocnos_expanded
+		    = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t)
+						      * n_sorted_allocnos * 2);
+		  memcpy (sorted_allocnos_expanded, sorted_allocnos,
+			  sizeof (ira_allocno_t) * n_sorted_allocnos);
+		  ira_free (sorted_allocnos);
+		  sorted_allocnos = sorted_allocnos_expanded;
+		  n_sorted_allocnos *= 2;
+		}
 	      sorted_allocnos[n++] = conflict_a;
 	      if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
 		fprintf (ira_dump_file, "Spilling a%dr%d for a%dr%d\n",
@@ -4740,6 +4752,7 @@  ira_initiate_assign (void)
   sorted_allocnos
     = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t)
 				      * ira_allocnos_num);
+  n_sorted_allocnos = ira_allocnos_num;
   consideration_allocno_bitmap = ira_allocate_bitmap ();
   initiate_cost_update ();
   allocno_priorities = (int *) ira_allocate (sizeof (int) * ira_allocnos_num);
@@ -4797,6 +4810,7 @@  fast_allocation (void)

   sorted_allocnos = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t)
 						    * ira_allocnos_num);
+  n_sorted_allocnos = ira_allocnos_num;
   num = 0;
   FOR_EACH_ALLOCNO (a, ai)
     sorted_allocnos[num++] = a;