This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, CHKP] Keep instrumentation references consistency when merging cgraph nodes
- From: Ilya Enkovich <enkovich dot gnu at gmail dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 2 Dec 2014 16:54:19 +0300
- Subject: [PATCH, CHKP] Keep instrumentation references consistency when merging cgraph nodes
- Authentication-results: sourceware.org; auth=none
Hi,
Currently cgraph nodes merge may break instrumented_version references. It depends on order nodes are read and merged and therefore problem is not nicely reproducible. I couldn't make a small reproducer. This patch fixes problem and 253.perlbmk benchmark build with '-O3 -flto -fcheck-pointer-bounds -mmpx'. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for trunk?
Thanks,
Ilya
--
2014-12-02 Ilya Enkovich <ilya.enkovich@intel.com>
* lto-cgraph.c (input_cgraph_1): Don't break existing
instrumentation clone references.
* lto/lto-symtab.c (lto_cgraph_replace_node): Redirect
instrumented_version references appropriately.
diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index d424e14..b310b44 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -1562,7 +1562,18 @@ input_cgraph_1 (struct lto_file_decl_data *file_data,
cnode->instrumented_version = cgraph_node::get (cnode->orig_decl);
if (cnode->instrumented_version)
- cnode->instrumented_version->instrumented_version = cnode;
+ {
+ /* We may have multiple nodes for a single function which
+ will be merged later. To have a proper merge we need
+ to keep instrumentation_version reference between nodes
+ consistent: each instrumented_version reference should
+ have proper reverse reference. Thus don't break existing
+ instrumented_version reference if it already exists. */
+ if (cnode->instrumented_version->instrumented_version)
+ cnode->instrumented_version = NULL;
+ else
+ cnode->instrumented_version->instrumented_version = cnode;
+ }
/* Restore decl names reference. */
if (IDENTIFIER_TRANSPARENT_ALIAS (DECL_ASSEMBLER_NAME (cnode->decl))
diff --git a/gcc/lto/lto-symtab.c b/gcc/lto/lto-symtab.c
index 4c4e48a..f5d82a7 100644
--- a/gcc/lto/lto-symtab.c
+++ b/gcc/lto/lto-symtab.c
@@ -99,6 +99,20 @@ lto_cgraph_replace_node (struct cgraph_node *node,
/* Redirect incomming references. */
prevailing_node->clone_referring (node);
+ /* Fix instrumentation references. */
+ if (node->instrumented_version)
+ {
+ gcc_assert (node->instrumentation_clone
+ == prevailing_node->instrumentation_clone);
+ node->instrumented_version->instrumented_version = prevailing_node;
+ if (!prevailing_node->instrumented_version)
+ prevailing_node->instrumented_version = node->instrumented_version;
+ /* Need to reset node->instrumented_version to NULL,
+ otherwise node removal code would reset
+ node->instrumented_version->instrumented_version. */
+ node->instrumented_version = NULL;
+ }
+
ipa_merge_profiles (prevailing_node, node);
lto_free_function_in_decl_state_for_node (node);