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]

Avoid global state for -finstrument-functions-exclude- options


This patch, relative to a tree with
<http://gcc.gnu.org/ml/gcc-patches/2010-11/msg01778.html> (pending
review) applied, eliminates use of global data in handling
-finstrument-functions-exclude- options.  The VECs used by those
options move into the gcc_options structure, and the
flag_instrument_functions_exclude_p function that looks at them, being
only used in gimplify.c, moves into that file and is made static.
(There are still some changes related to other options needed before
opts.c ceases to use any tree interfaces.)

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  OK to
commit?

2010-11-17  Joseph Myers  <joseph@codesourcery.com>

	* common.opt (flag_instrument_functions_exclude_functions,
	flag_instrument_functions_exclude_files): New Variable
	definitions.
	* flags.h (flag_instrument_functions_exclude_p): Don't declare.
	* gimplify.c (char_p): Declare type and vectors.
	(flag_instrument_functions_exclude_p): Moved from opts.c.  Make
	static.
	* opts.c (flag_instrument_functions_exclude_functions,
	flag_instrument_functions_exclude_files): Remove.
	(add_comma_separated_to_vector): Take void **.
	(flag_instrument_functions_exclude_p): Move to gimplify.c.
	(common_handle_option): Use options structure for
	-finstrument-functions-exclude- options.

diff -rupN --exclude=.svn gcc-mainline-0/gcc/common.opt gcc-mainline/gcc/common.opt
--- gcc-mainline-0/gcc/common.opt	2010-11-17 12:28:27.000000000 -0800
+++ gcc-mainline/gcc/common.opt	2010-11-17 12:38:37.000000000 -0800
@@ -105,6 +105,14 @@ enum symbol_visibility default_visibilit
 Variable
 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC
 
+; These two are really VEC(char_p,heap) *.
+
+Variable
+void *flag_instrument_functions_exclude_functions
+
+Variable
+void *flag_instrument_functions_exclude_files
+
 ###
 Driver
 
diff -rupN --exclude=.svn gcc-mainline-0/gcc/flags.h gcc-mainline/gcc/flags.h
--- gcc-mainline-0/gcc/flags.h	2010-11-10 09:57:06.000000000 -0800
+++ gcc-mainline/gcc/flags.h	2010-11-17 12:42:47.000000000 -0800
@@ -159,10 +159,6 @@ extern enum stack_check_type flag_stack_
 #define abi_version_at_least(N) \
   (flag_abi_version == 0 || flag_abi_version >= (N))
 
-/* Return whether the function should be excluded from
-   instrumentation.  */
-extern bool flag_instrument_functions_exclude_p (tree fndecl);
-
 /* True if overflow wraps around for the given integral type.  That
    is, TYPE_MAX + 1 == TYPE_MIN.  */
 #define TYPE_OVERFLOW_WRAPS(TYPE) \
diff -rupN --exclude=.svn gcc-mainline-0/gcc/gimplify.c gcc-mainline/gcc/gimplify.c
--- gcc-mainline-0/gcc/gimplify.c	2010-11-05 06:05:02.000000000 -0700
+++ gcc-mainline/gcc/gimplify.c	2010-11-17 12:44:23.000000000 -0800
@@ -7762,6 +7762,46 @@ gimplify_body (tree *body_p, tree fndecl
   return outer_bind;
 }
 
+typedef char *char_p; /* For DEF_VEC_P.  */
+DEF_VEC_P(char_p);
+DEF_VEC_ALLOC_P(char_p,heap);
+
+/* Return whether we should exclude FNDECL from instrumentation.  */
+
+static bool
+flag_instrument_functions_exclude_p (tree fndecl)
+{
+  VEC(char_p,heap) *vec;
+
+  vec = (VEC(char_p,heap) *) flag_instrument_functions_exclude_functions;
+  if (VEC_length (char_p, vec) > 0)
+    {
+      const char *name;
+      int i;
+      char *s;
+
+      name = lang_hooks.decl_printable_name (fndecl, 0);
+      FOR_EACH_VEC_ELT (char_p, vec, i, s)
+	if (strstr (name, s) != NULL)
+	  return true;
+    }
+
+  vec = (VEC(char_p,heap) *) flag_instrument_functions_exclude_files;
+  if (VEC_length (char_p, vec) > 0)
+    {
+      const char *name;
+      int i;
+      char *s;
+
+      name = DECL_SOURCE_FILE (fndecl);
+      FOR_EACH_VEC_ELT (char_p, vec, i, s)
+	if (strstr (name, s) != NULL)
+	  return true;
+    }
+
+  return false;
+}
+
 /* Entry point to the gimplification pass.  FNDECL is the FUNCTION_DECL
    node for the function we want to gimplify.
 
diff -rupN --exclude=.svn gcc-mainline-0/gcc/opts.c gcc-mainline/gcc/opts.c
--- gcc-mainline-0/gcc/opts.c	2010-11-17 12:28:27.000000000 -0800
+++ gcc-mainline/gcc/opts.c	2010-11-17 12:44:07.000000000 -0800
@@ -319,15 +319,10 @@ struct visibility_flags visibility_optio
 /* What to print when a switch has no documentation.  */
 static const char undocumented_msg[] = N_("This switch lacks documentation");
 
-/* Functions excluded from profiling.  */
-
 typedef char *char_p; /* For DEF_VEC_P.  */
 DEF_VEC_P(char_p);
 DEF_VEC_ALLOC_P(char_p,heap);
 
-static VEC(char_p,heap) *flag_instrument_functions_exclude_functions;
-static VEC(char_p,heap) *flag_instrument_functions_exclude_files;
-
 typedef const char *const_char_p; /* For DEF_VEC_P.  */
 DEF_VEC_P(const_char_p);
 DEF_VEC_ALLOC_P(const_char_p,heap);
@@ -542,12 +537,13 @@ add_input_filename (const char *filename
 /* Add comma-separated strings to a char_p vector.  */
 
 static void
-add_comma_separated_to_vector (VEC(char_p,heap) **pvec, const char* arg)
+add_comma_separated_to_vector (void **pvec, const char *arg)
 {
   char *tmp;
   char *r;
   char *w;
   char *token_start;
+  VEC(char_p,heap) *vec = (VEC(char_p,heap) *) *pvec;
 
   /* We never free this string.  */
   tmp = xstrdup (arg);
@@ -562,7 +558,7 @@ add_comma_separated_to_vector (VEC(char_
 	{
 	  *w++ = '\0';
 	  ++r;
-	  VEC_safe_push (char_p, heap, *pvec, token_start);
+	  VEC_safe_push (char_p, heap, vec, token_start);
 	  token_start = w;
 	}
       if (*r == '\\' && r[1] == ',')
@@ -574,43 +570,11 @@ add_comma_separated_to_vector (VEC(char_
 	*w++ = *r++;
     }
   if (*token_start != '\0')
-    VEC_safe_push (char_p, heap, *pvec, token_start);
-}
-
-/* Return whether we should exclude FNDECL from instrumentation.  */
-
-bool
-flag_instrument_functions_exclude_p (tree fndecl)
-{
-  if (VEC_length (char_p, flag_instrument_functions_exclude_functions) > 0)
-    {
-      const char *name;
-      int i;
-      char *s;
+    VEC_safe_push (char_p, heap, vec, token_start);
 
-      name = lang_hooks.decl_printable_name (fndecl, 0);
-      FOR_EACH_VEC_ELT (char_p, flag_instrument_functions_exclude_functions,
-			i, s)
-	if (strstr (name, s) != NULL)
-	  return true;
-    }
-
-  if (VEC_length (char_p, flag_instrument_functions_exclude_files) > 0)
-    {
-      const char *name;
-      int i;
-      char *s;
-
-      name = DECL_SOURCE_FILE (fndecl);
-      FOR_EACH_VEC_ELT (char_p, flag_instrument_functions_exclude_files, i, s)
-	if (strstr (name, s) != NULL)
-	  return true;
-    }
-
-  return false;
+  *pvec = vec;
 }
 
-
 /* Handle the vector of command line options (located at LOC), storing
    the results of processing DECODED_OPTIONS and DECODED_OPTIONS_COUNT
    in OPTS and OPTS_SET and using DC for diagnostic state.  LANG_MASK
@@ -1915,12 +1879,12 @@ common_handle_option (struct gcc_options
 
     case OPT_finstrument_functions_exclude_function_list_:
       add_comma_separated_to_vector
-	(&flag_instrument_functions_exclude_functions, arg);
+	(&opts->x_flag_instrument_functions_exclude_functions, arg);
       break;
 
     case OPT_finstrument_functions_exclude_file_list_:
       add_comma_separated_to_vector
-	(&flag_instrument_functions_exclude_files, arg);
+	(&opts->x_flag_instrument_functions_exclude_files, arg);
       break;
 
     case OPT_fmessage_length_:

-- 
Joseph S. Myers
joseph@codesourcery.com


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