[Mesa-dev] [PATCH 14/16] i965: Compute the number of live registers at each IP.

Kenneth Graunke kenneth at whitecape.org
Thu Dec 19 15:40:09 PST 2013


On 12/19/2013 01:40 PM, Matt Turner wrote:
> From: Kenneth Graunke <kenneth at whitecape.org>
> 
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> ---
>  src/mesa/drivers/dri/i965/brw_fs.cpp         | 18 ++++++++++++++++++
>  src/mesa/drivers/dri/i965/brw_fs.h           |  3 +++
>  src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |  1 +
>  3 files changed, 22 insertions(+)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
> index 12b6d4a..2c7b3ae 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
> @@ -3219,6 +3219,24 @@ fs_visitor::assign_binding_table_offsets()
>     assign_common_binding_table_offsets(next_binding_table_offset);
>  }
>  
> +void
> +fs_visitor::calculate_register_pressure()
> +{
> +   calculate_live_intervals();
> +
> +   int num_instructions = 0;
> +   foreach_list(node, &this->instructions) {
> +      ++num_instructions;
> +   }
> +
> +   regs_live_at_ip = rzalloc_array(mem_ctx, int, num_instructions);
> +
> +   for (int reg = 0; reg < virtual_grf_count; reg++) {
> +      for (int ip = virtual_grf_start[reg]; ip <= virtual_grf_end[reg]; ip++)
> +         regs_live_at_ip[ip] += virtual_grf_sizes[reg];

I wasn't sure whether I wanted to increment this by one (# of VGRFs), or
by VGRF size (estimate of actual HW reg use).  I think it would be
useful to store both.  Perhaps add a second array called vgrfs_live_at_ip[]?

Patch 2 should probably have a slightly better commit message:

i965/fs: Show register pressure in dump_instructions() output.

Dumping the number of live registers at each IP allows us to see
register pressure and identify any local maxima.  This should
aid in debugging passes designed to reduce register pressure, as
well as optimizations that suddenly trigger spilling.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>

> +   }
> +}
> +
>  bool
>  fs_visitor::run()
>  {
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
> index 07360ae..bee8cdf 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.h
> +++ b/src/mesa/drivers/dri/i965/brw_fs.h
> @@ -309,6 +309,7 @@ public:
>     void setup_pull_constants();
>     void invalidate_live_intervals();
>     void calculate_live_intervals();
> +   void calculate_register_pressure();
>     bool opt_algebraic();
>     bool opt_cse();
>     bool opt_cse_local(bblock_t *block, exec_list *aeb);
> @@ -447,6 +448,8 @@ public:
>     int *virtual_grf_end;
>     brw::fs_live_variables *live_intervals;
>  
> +   int *regs_live_at_ip;
> +
>     /* This is the map from UNIFORM hw_reg + reg_offset as generated by
>      * the visitor to the packed uniform number after
>      * remove_dead_constants() that represents the actual uploaded
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> index 869b636..c5bacc2 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> @@ -2933,6 +2933,7 @@ fs_visitor::fs_visitor(struct brw_context *brw,
>     this->virtual_grf_start = NULL;
>     this->virtual_grf_end = NULL;
>     this->live_intervals = NULL;
> +   this->regs_live_at_ip = NULL;
>  
>     this->params_remap = NULL;
>     this->nr_params_remap = 0;
> 


More information about the mesa-dev mailing list