Remove global state from gcc/tracer.c

Richard Henderson rth@redhat.com
Thu May 23 20:32:00 GMT 2013


>  /* The Ith entry is the number of objects on a page or order I.  */
>  
> -static unsigned objects_per_page_table[NUM_ORDERS];
> +DEFINE_STATIC_STATE_ARRAY(unsigned, objects_per_page_table, NUM_ORDERS)
>  
>  /* The Ith entry is the size of an object on a page of order I.  */
>  
> -static size_t object_size_table[NUM_ORDERS];
> +DEFINE_STATIC_STATE_ARRAY(size_t, object_size_table, NUM_ORDERS)
>  
>  /* The Ith entry is a pair of numbers (mult, shift) such that
>     ((k * mult) >> shift) mod 2^32 == (k / OBJECT_SIZE(I)) mod 2^32,
>     for all k evenly divisible by OBJECT_SIZE(I).  */
>  
> -static struct
> +struct inverse_table_def
>  {
>    size_t mult;
>    unsigned int shift;
> -}
> -inverse_table[NUM_ORDERS];
> +};
> +DEFINE_STATIC_STATE_ARRAY(inverse_table_def, inverse_table, NUM_ORDERS)
>  
>  /* A page_entry records the status of an allocation page.  This
>     structure is dynamically sized to fit the bitmap in_use_p.  */
> @@ -343,7 +346,7 @@ struct free_object
>  #endif
>  
>  /* The rest of the global variables.  */
> -static struct globals
> +struct globals
>  {
>    /* The Nth element in this array is a page with objects of size 2^N.
>       If there are any pages with free objects, they will be at the
> @@ -457,7 +460,11 @@ static struct globals
>      /* The overhead for each of the allocation orders.  */
>      unsigned long long total_overhead_per_order[NUM_ORDERS];
>    } stats;
> -} G;
> +};
> +
> +DEFINE_STATIC_STATE(globals, G)

Be careful here.  Note that all of the arrays that you convert are notionally
static constants defining the bucket sizes for the algorithm, except we don't
actually compute them at compile time.  They would be true global data shared
by all threads.

The G structure contains all of the data that you'd actually want to put into
the "universe".

That said, I'd really like to avoid ultra-macroization as with

> +#define probability_cutoff \
> +   universe.tracer_c->x_probability_cutoff
> +#define branch_ratio_cutoff \
> +   universe.tracer_c->x_branch_ratio_cutoff
> +#define bb_seen \
> +   universe.tracer_c->x_bb_seen

if we can avoid it.

I think we need more weigh in from other maintainers on this, rather than
iterating a 5th time today...


r~



More information about the Gcc-patches mailing list