]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add tunables for input buffer
authorAndi Kleen <ak@gcc.gnu.org>
Wed, 25 Dec 2024 19:54:13 +0000 (11:54 -0800)
committerAndi Kleen <ak@gcc.gnu.org>
Mon, 3 Feb 2025 05:40:37 +0000 (21:40 -0800)
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.

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
gcc/input.h
gcc/params.opt
gcc/toplev.cc

index 9f3cc6651e8333f7d15cebeb5b758006c4a314ca..8605202fed2cf829e8fa2831852bb54560d39856 100644 (file)
@@ -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
@@ -192,6 +196,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);
 
index 18ccf4429fc5002abd58caefe0454bdd8c8ff13f..a60afe80681ff91867327024b1a20439e6b04f10 100644 (file)
@@ -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;
 };
index b5e7800d7e49caeb1e7f906525e258497077d03d..5d234a607c02a3e27fd916366e529551bd257176 100644 (file)
@@ -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.
index d45a12cab45f75d801d2500bee4afa9353ae25cd..e03af8b18056dfa2a8ac19cf74352a2b5bcab83d 100644 (file)
@@ -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 ();