From be1a81dc949480c24c0e173085bdad193c0579ce Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 26 Jul 2016 15:03:29 +0200
Subject: [PATCH] Introduce no_profile_instrument_function attribute
gcc/ChangeLog:
2016-07-26 Martin Liska <mliska@suse.cz>
PR gcov-profile/68025
* tree-profile.c (tree_profiling): Respect
no_profile_instrument_function attribute.
gcc/c-family/ChangeLog:
2016-07-26 Martin Liska <mliska@suse.cz>
PR gcov-profile/68025
* c-common.c (handle_no_profile_instrument_function_attribute):
gcc/testsuite/ChangeLog:
2016-07-26 Martin Liska <mliska@suse.cz>
PR gcov-profile/68025
* gcc.dg/no_profile_instrument_function-attr-1.c: New test.
---
gcc/c-family/c-common.c | 21 ++++++++++++++++++++
.../gcc.dg/no_profile_instrument_function-attr-1.c | 23 ++++++++++++++++++++++
gcc/tree-profile.c | 3 +++
3 files changed, 47 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c
@@ -353,6 +353,8 @@ static tree handle_tls_model_attribute (tree *, tree, tree, int,
bool *);
static tree handle_no_instrument_function_attribute (tree *, tree,
tree, int, bool *);
+static tree handle_no_profile_instrument_function_attribute (tree *, tree,
+ tree, int, bool *);
static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
static tree handle_no_limit_stack_attribute (tree *, tree, tree, int,
@@ -717,6 +719,9 @@ const struct attribute_spec c_common_attribute_table[] =
{ "no_instrument_function", 0, 0, true, false, false,
handle_no_instrument_function_attribute,
false },
+ { "no_profile_instrument_function", 0, 0, true, false, false,
+ handle_no_profile_instrument_function_attribute,
+ false },
{ "malloc", 0, 0, true, false, false,
handle_malloc_attribute, false },
{ "returns_twice", 0, 0, true, false, false,
@@ -8293,6 +8298,22 @@ handle_no_instrument_function_attribute (tree *node, tree name,
return NULL_TREE;
}
+/* Handle a "no_profile_instrument_function" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+static tree
+handle_no_profile_instrument_function_attribute (tree *node, tree name, tree,
+ int, bool *no_add_attrs)
+{
+ if (TREE_CODE (*node) != FUNCTION_DECL)
+ {
+ warning (OPT_Wattributes, "%qE attribute ignored", name);
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
+
/* Handle a "malloc" attribute; arguments as in
struct attribute_spec.handler. */
new file mode 100644
@@ -0,0 +1,23 @@
+/* { dg-options "-O2 -fprofile-generate -fdump-tree-optimized" } */
+
+__attribute__ ((no_profile_instrument_function))
+int foo()
+{
+ return 0;
+}
+
+__attribute__ ((no_profile_instrument_function))
+int bar()
+{
+ return 1;
+}
+
+int main ()
+{
+ return foo ();
+}
+
+/* { dg-final { scan-tree-dump-times "__gcov0\\.main.* = PROF_edge_counter" 1 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "__gcov_indirect_call_profiler_v2" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "__gcov_time_profiler" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "__gcov_init" 1 "optimized" } } */
@@ -524,6 +524,9 @@ tree_profiling (void)
if (DECL_SOURCE_LOCATION (node->decl) == BUILTINS_LOCATION)
continue;
+ if (lookup_attribute ("no_profile_instrument_function",
+ DECL_ATTRIBUTES (node->decl)))
+ continue;
/* Do not instrument extern inline functions when testing coverage.
While this is not perfectly consistent (early inlined extern inlines
will get acocunted), testsuite expects that. */
--
2.9.2