On Sat, 2025-01-25 at 23:30 -0800, Andi Kleen wrote:
> From: Andi Kleen <a...@gcc.gnu.org>
> 
> While the input line cache size now tunable it's better if the
> compiler
> auto tunes it. Otherwise large files needing random file access will
> still have to search many lines to find the right lines.
> 
> Add support for allocating one line anchor per hundred input lines.
> This means an overhead of ~235k per 1M input lines on 64bit, which
> seems reasonable.
> 
> gcc/ChangeLog:
> 
>       PR preprocessor/118168
>       * input.cc (file_cache_slot::get_next_line): Implement
>       dynamic sizing of m_line_record based on input length.
>       * params.opt: (param_file_cache_lines): Set to 0 to size
>       dynamically.
> ---
>  gcc/input.cc   | 11 ++++++++---
>  gcc/params.opt |  2 +-
>  2 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/gcc/input.cc b/gcc/input.cc
> index b3fe38eb77c..d5d7dbb043e 100644
> --- a/gcc/input.cc
> +++ b/gcc/input.cc
> @@ -194,7 +194,7 @@ public:
>  
>  };
>  
> -size_t file_cache_slot::line_record_size = 100;
> +size_t file_cache_slot::line_record_size = 0;
>  size_t file_cache_slot::recent_cached_lines_shift = 8;
>  
>  /* Tune file_cache.  */
> @@ -865,8 +865,13 @@ file_cache_slot::get_next_line (char **line,
> ssize_t *line_len)
>        size_t delta = rlen >= 1 ?
>       m_line_num - m_line_record[rlen - 1].line_num : 1;
>  
> +      size_t max_size = line_record_size;
> +      /* One anchor per hundred input lines.  */
> +      if (max_size == 0)
> +     max_size = m_line_num / 100;
> +
>        /* If we're too far beyond drop half of the lines to
> rebalance.  */
> -      if (rlen == line_record_size && delta >= spacing*2)
> +      if (rlen == max_size && delta >= spacing*2)
>       {
>         size_t j = 0;
>         for (size_t i = 1; i < rlen; i += 2)
> @@ -876,7 +881,7 @@ file_cache_slot::get_next_line (char **line,
> ssize_t *line_len)
>         spacing *= 2;
>       }
>  
> -      if (rlen < line_record_size && delta >= spacing)
> +      if (rlen < max_size && delta >= spacing)
>       m_line_record.safe_push
>         (file_cache_slot::line_info (m_line_num,
>                                      m_line_start_idx,
> diff --git a/gcc/params.opt b/gcc/params.opt
> index 5d234a607c0..a56c20af2f8 100644
> --- a/gcc/params.opt
> +++ b/gcc/params.opt
> @@ -139,7 +139,7 @@ Common Joined UInteger
> Var(param_file_cache_files) Init(16) Param
>  Max number of files in the file cache.
>  
>  -param=file-cache-lines=
> -Common Joined UInteger Var(param_file_cache_lines) Init(100) Param
> +Common Joined UInteger Var(param_file_cache_lines) Init(0) Param
>  Max number of lines to index into file cache.
>  
>  -param=fsm-scale-path-stmts=

Please update the description line to indicate that 0 is automatic.

OK for trunk with that change, once the prerequisites are in.

Thanks
Dave

Reply via email to