This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/7] GCOV: introduce global vector of functions


gcc/ChangeLog:

2017-11-09  Martin Liska  <mliska@suse.cz>

	* gcov.c (read_graph_file): Store to global vector of functions.
	(read_count_file): Iterate the vector.
	(process_file): Likewise.
	(generate_results): Likewise.
	(release_structures): Likewise.
---
 gcc/gcov.c | 108 +++++++++++++++++++++++++------------------------------------
 1 file changed, 44 insertions(+), 64 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 846a2326196..83239639247 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -392,10 +392,8 @@ public:
   unsigned src;  /* Source file */
 };
 
-/* Holds a list of function basic block graphs.  */
-

-static function_t *functions;
-static function_t **fn_end = &functions;
+/* Vector of all functions.  */
+static vector<function_t *> functions;
 
 /* Vector of source files.  */
 static vector<source_info> sources;
@@ -532,8 +530,8 @@ static void generate_results (const char *);
 static void create_file_names (const char *);
 static char *canonicalize_name (const char *);
 static unsigned find_source (const char *);
-static function_t *read_graph_file (void);
-static int read_count_file (function_t *);
+static void read_graph_file (void);
+static int read_count_file (void);
 static void solve_flow_graph (function_t *);
 static void find_exception_blocks (function_t *);
 static void add_branch_counts (coverage_t *, const arc_t *);
@@ -1095,42 +1093,40 @@ struct function_start_pair_hash : typed_noop_remove <function_start>
 static void
 process_file (const char *file_name)
 {
-  function_t *fns;
-
   create_file_names (file_name);
-  fns = read_graph_file ();
-  if (!fns)
+  read_graph_file ();
+  if (functions.empty ())
     return;
 
-  read_count_file (fns);
+  read_count_file ();
 
   hash_map<function_start_pair_hash, function_t *> fn_map;
 
   /* Identify group functions.  */
-  for (function_t *f = fns; f; f = f->next)
-    if (!f->artificial)
+  for (vector<function_t *>::iterator it = functions.begin ();
+       it != functions.end (); it++)
+    if (!(*it)->artificial)
       {
 	function_start needle;
-	needle.source_file_idx = f->src;
-	needle.start_line = f->start_line;
+	needle.source_file_idx = (*it)->src;
+	needle.start_line = (*it)->start_line;
 
 	function_t **slot = fn_map.get (needle);
 	if (slot)
 	  {
-	    gcc_assert ((*slot)->end_line == f->end_line);
+	    gcc_assert ((*slot)->end_line == (*it)->end_line);
 	    (*slot)->is_group = 1;
-	    f->is_group = 1;
+	    (*it)->is_group = 1;
 	  }
 	else
-	  fn_map.put (needle, f);
+	  fn_map.put (needle, *it);
       }
 
-  while (fns)
+  for (vector<function_t *>::iterator it = functions.begin ();
+       it != functions.end (); it++)
     {
-      function_t *fn = fns;
+      function_t *fn = *it;
 
-      fns = fn->next;
-      fn->next = NULL;
       if (fn->counts || no_data_file)
 	{
 	  unsigned src = fn->src;
@@ -1177,14 +1173,12 @@ process_file (const char *file_name)
 	      if (fn->has_catch)
 		find_exception_blocks (fn);
 	    }
-
-	  *fn_end = fn;
-	  fn_end = &fn->next;
 	}
       else
-	/* The function was not in the executable -- some other
-	   instance must have been selected.  */
-	delete fn;
+	{
+	  /* The function was not in the executable -- some other
+	     instance must have been selected.  */
+	}
     }
 }
 
@@ -1222,10 +1216,10 @@ output_gcov_file (const char *file_name, source_info *src)
 static void
 generate_results (const char *file_name)
 {
-  function_t *fn;
-
-  for (fn = functions; fn; fn = fn->next)
+  for (vector<function_t *>::iterator it = functions.begin ();
+       it != functions.end (); it++)
     {
+      function_t *fn = *it;
       coverage_t coverage;
       if (fn->artificial)
 	continue;
@@ -1291,13 +1285,11 @@ generate_results (const char *file_name)
 static void
 release_structures (void)
 {
-  function_t *fn;
+  for (vector<function_t *>::iterator it = functions.begin ();
+       it != functions.end (); it++)
+    delete (*it);
 
-  while ((fn = functions))
-    {
-      functions = fn->next;
-      delete fn;
-    }
+  functions.resize (0);
 }
 
 /* Generate the names of the graph and data files.  If OBJECT_DIRECTORY
@@ -1455,29 +1447,26 @@ find_source (const char *file_name)
   return idx;
 }
 
-/* Read the notes file.  Return list of functions read -- in reverse order.  */
+/* Read the notes file.  Save functions to FUNCTIONS global vector.  */
 
-static function_t *
+static void
 read_graph_file (void)
 {
   unsigned version;
   unsigned current_tag = 0;
-  function_t *fn = NULL;
-  function_t *fns = NULL;
-  function_t **fns_end = &fns;
   unsigned tag;
 
   if (!gcov_open (bbg_file_name, 1))
     {
       fnotice (stderr, "%s:cannot open notes file\n", bbg_file_name);
-      return fns;
+      return;
     }
   bbg_file_time = gcov_time ();
   if (!gcov_magic (gcov_read_unsigned (), GCOV_NOTE_MAGIC))
     {
       fnotice (stderr, "%s:not a gcov notes file\n", bbg_file_name);
       gcov_close ();
-      return fns;
+      return;
     }
 
   version = gcov_read_unsigned ();
@@ -1493,6 +1482,7 @@ read_graph_file (void)
     }
   bbg_stamp = gcov_read_unsigned ();
 
+  function_t *fn = NULL;
   while ((tag = gcov_read_unsigned ()))
     {
       unsigned length = gcov_read_unsigned ();
@@ -1514,7 +1504,8 @@ read_graph_file (void)
 	  unsigned start_column = gcov_read_unsigned ();
 	  unsigned end_line = gcov_read_unsigned ();
 
-	  fn = new function_t;
+	  fn = new function_t ();
+	  functions.push_back (fn);
 	  fn->name = function_name;
 	  if (flag_demangled_names)
 	    {
@@ -1531,9 +1522,6 @@ read_graph_file (void)
 	  fn->end_line = end_line;
 	  fn->artificial = artificial;
 
-	  fn->next = NULL;
-	  *fns_end = fn;
-	  fns_end = &fn->next;
 	  current_tag = tag;
 	}
       else if (fn && tag == GCOV_TAG_BLOCKS)
@@ -1659,17 +1647,15 @@ read_graph_file (void)
     }
   gcov_close ();
 
-  if (!fns)
+  if (functions.empty ())
     fnotice (stderr, "%s:no functions found\n", bbg_file_name);
-
-  return fns;
 }
 
 /* Reads profiles from the count file and attach to each
    function. Return nonzero if fatal error.  */
 
 static int
-read_count_file (function_t *fns)
+read_count_file (void)
 {
   unsigned ix;
   unsigned version;
@@ -1726,26 +1712,20 @@ read_count_file (function_t *fns)
       else if (tag == GCOV_TAG_FUNCTION && length == GCOV_TAG_FUNCTION_LENGTH)
 	{
 	  unsigned ident;
-	  struct function_info *fn_n;
 
 	  /* Try to find the function in the list.  To speed up the
 	     search, first start from the last function found.  */
 	  ident = gcov_read_unsigned ();
-	  fn_n = fns;
-	  for (fn = fn ? fn->next : NULL; ; fn = fn->next)
+
+	  fn = NULL;
+	  for (vector<function_t *>::reverse_iterator it = functions.rbegin ();
+	       it != functions.rend (); it++)
 	    {
-	      if (fn)
-		;
-	      else if ((fn = fn_n))
-		fn_n = NULL;
-	      else
+	      if ((*it)->ident == ident)
 		{
-		  fnotice (stderr, "%s:unknown function '%u'\n",
-			   da_file_name, ident);
+		  fn = *it;
 		  break;
 		}
-	      if (fn->ident == ident)
-		break;
 	    }
 
 	  if (!fn)
-- 
2.14.3



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]