On Sat, 2025-01-25 at 23:30 -0800, Andi Kleen wrote:
> From: Andi Kleen <a...@gcc.gnu.org>
> 
> The input machinery to read the source code independent of the lexer
> has a range of hard coded maximum array sizes that can impact
> performance.
> Make them tunable.
> 
> input.cc is part of libcommon so it cannot direct access params
> without a level of indirection.

Thanks; this patch is OK for trunk

Dave

> 
> gcc/ChangeLog:
> 
>       PR preprocessor/118168
>       * input.cc (file_cache::tune): New function.
>       * input.h (class file_cache): Make tunables non const.
>       * params.opt: Add new tunables.
>       * toplev.cc (toplev::main): Initialize input buffer context
>       tunables.
> ---
>  gcc/input.cc   | 18 +++++++++++++++++-
>  gcc/input.h    |  4 +++-
>  gcc/params.opt |  8 ++++++++
>  gcc/toplev.cc  |  2 ++
>  4 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/input.cc b/gcc/input.cc
> index 7ed80cad13f..f824c34e0cc 100644
> --- a/gcc/input.cc
> +++ b/gcc/input.cc
> @@ -79,6 +79,10 @@ public:
>    void evict ();
>    void set_content (const char *buf, size_t sz);
>  
> +  static void tune(size_t line_record_size_) {
> +      line_record_size = line_record_size_;
> +  }
> +
>   private:
>    /* These are information used to store a line boundary.  */
>    class line_info
> @@ -116,7 +120,7 @@ public:
>    bool goto_next_line ();
>  
>    static const size_t buffer_size = 4 * 1024;
> -  static const size_t line_record_size = 100;
> +  static size_t line_record_size;
>  
>    /* The number of time this file has been accessed.  This is used
>       to designate which file cache to evict from the cache
> @@ -189,6 +193,18 @@ public:
>  
>  };
>  
> +size_t file_cache_slot::line_record_size = 100;
> +
> +/* Tune file_cache.  */
> +void
> +file_cache::tune (size_t num_file_slots_, size_t lines)
> +{
> +  num_file_slots = num_file_slots_;
> +  file_cache_slot::tune (lines);
> +}
> +
> +size_t file_cache::num_file_slots = 16;
> +
>  static const char *
>  find_end_of_line (const char *s, size_t len);
>  
> diff --git a/gcc/input.h b/gcc/input.h
> index 18ccf4429fc..a60afe80681 100644
> --- a/gcc/input.h
> +++ b/gcc/input.h
> @@ -161,13 +161,15 @@ class file_cache
>                            const char *buffer,
>                            size_t sz);
>  
> +  static void tune(size_t num_file_slots_, size_t lines);
> +
>   private:
>    file_cache_slot *evicted_cache_tab_entry (unsigned
> *highest_use_count);
>    file_cache_slot *add_file (const char *file_path);
>    file_cache_slot *lookup_file (const char *file_path);
>  
>   private:
> -  static const size_t num_file_slots = 16;
> +  static size_t num_file_slots;
>    file_cache_slot *m_file_slots;
>    input_context m_input_context;
>  };
> diff --git a/gcc/params.opt b/gcc/params.opt
> index b5e7800d7e4..5d234a607c0 100644
> --- a/gcc/params.opt
> +++ b/gcc/params.opt
> @@ -134,6 +134,14 @@ Maximum size (in bytes) of objects tracked
> bytewise by dead store elimination.
>  Common Joined UInteger Var(param_early_inlining_insns) Init(6)
> Optimization Param
>  Maximal estimated growth of function body caused by early inlining
> of single call.
>  
> +-param=file-cache-files=
> +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
> +Max number of lines to index into file cache.
> +
>  -param=fsm-scale-path-stmts=
>  Common Joined UInteger Var(param_fsm_scale_path_stmts) Init(2)
> IntegerRange(1, 10) Param Optimization
>  Scale factor to apply to the number of statements in a threading
> path crossing a loop backedge when comparing to max-jump-thread-
> duplication-stmts.
> diff --git a/gcc/toplev.cc b/gcc/toplev.cc
> index d45a12cab45..e03af8b1805 100644
> --- a/gcc/toplev.cc
> +++ b/gcc/toplev.cc
> @@ -2333,6 +2333,8 @@ toplev::main (int argc, char **argv)
>                 UNKNOWN_LOCATION, global_dc,
>                 targetm.target_option.override);
>  
> +  file_cache::tune (param_file_cache_files, param_file_cache_lines);
> +
>    handle_common_deferred_options ();
>  
>    init_local_tick ();

Reply via email to