From 185c9e56217b2b645736972721840ea5720e7da4 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 19 Jan 2015 16:20:16 +0100 Subject: [PATCH] IPA ICF: add no_icf attribute. * c-common.c (handle_noicf_attribute): New function. * doc/extend.texi (no_icf): Add new attribute description. * ipa-icf.c (sem_item_optimizer::merge_classes): Handle cases where the pass attempts to merge a function with no_icf attribute. * gcc.dg/ipa/ipa-icf-33.c: New test. From-SVN: r219848 --- gcc/ChangeLog | 6 ++++++ gcc/c-family/ChangeLog | 4 ++++ gcc/c-family/c-common.c | 21 +++++++++++++++++++++ gcc/doc/extend.texi | 6 ++++++ gcc/ipa-icf.c | 10 ++++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/ipa/ipa-icf-33.c | 27 +++++++++++++++++++++++++++ 7 files changed, 78 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/ipa/ipa-icf-33.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8a5a1de970b..48341c53e1c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-01-19 Martin Liska + + * doc/extend.texi (no_icf): Add new attribute description. + * ipa-icf.c (sem_item_optimizer::merge_classes): Handle cases + where the pass attempts to merge a function with no_icf attribute. + 2015-01-19 Ramana Radhakrishnan PR target/64532 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index e0ad21506ad..df56b310992 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,7 @@ +2015-01-19 Martin Liska + + * c-common.c (handle_noicf_attribute): New function. + 2015-01-15 Thomas Schwinge Bernd Schmidt James Norris diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index eb132c537fe..3c18d1cc915 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -330,6 +330,7 @@ static tree handle_no_sanitize_undefined_attribute (tree *, tree, tree, int, static tree handle_stack_protect_attribute (tree *, tree, tree, int, bool *); static tree handle_noinline_attribute (tree *, tree, tree, int, bool *); static tree handle_noclone_attribute (tree *, tree, tree, int, bool *); +static tree handle_noicf_attribute (tree *, tree, tree, int, bool *); static tree handle_leaf_attribute (tree *, tree, tree, int, bool *); static tree handle_always_inline_attribute (tree *, tree, tree, int, bool *); @@ -664,6 +665,8 @@ const struct attribute_spec c_common_attribute_table[] = handle_noinline_attribute, false }, { "noclone", 0, 0, true, false, false, handle_noclone_attribute, false }, + { "no_icf", 0, 0, true, false, false, + handle_noicf_attribute, false }, { "leaf", 0, 0, true, false, false, handle_leaf_attribute, false }, { "always_inline", 0, 0, true, false, false, @@ -6853,6 +6856,24 @@ handle_noclone_attribute (tree *node, tree name, return NULL_TREE; } +/* Handle a "no_icf" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_noicf_attribute (tree *node, tree name, + tree ARG_UNUSED (args), + int ARG_UNUSED (flags), 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 "always_inline" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index bf6d7102147..ba921e914bd 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2195,6 +2195,7 @@ attribute specification inside double parentheses. The following attributes are currently defined for functions on all targets: @code{aligned}, @code{alloc_size}, @code{alloc_align}, @code{assume_aligned}, @code{noreturn}, @code{returns_twice}, @code{noinline}, @code{noclone}, +@code{no_icf}, @code{always_inline}, @code{flatten}, @code{pure}, @code{const}, @code{nothrow}, @code{sentinel}, @code{format}, @code{format_arg}, @code{no_instrument_function}, @code{no_split_stack}, @@ -3475,6 +3476,11 @@ cloning---a mechanism that produces specialized copies of functions and which is (currently) performed by interprocedural constant propagation. +@item no_icf +@cindex @code{no_icf} function attribute +This function attribute prevents a functions from being merged with another +semantically equivalent function. + @item nonnull (@var{arg-index}, @dots{}) @cindex @code{nonnull} function attribute The @code{nonnull} attribute specifies that some function parameters should diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index 0ac01a9c3d0..a91fd98b807 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -2373,6 +2373,16 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count) source->asm_name (), alias->asm_name ()); } + if (lookup_attribute ("no_icf", DECL_ATTRIBUTES (alias->decl))) + { + if (dump_file) + fprintf (dump_file, + "Merge operation is skipped due to no_icf " + "attribute.\n\n"); + + continue; + } + if (dump_file && (dump_flags & TDF_DETAILS)) { source->dump_to_file (dump_file); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8f6a88fd418..fa357a3bc34 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-01-19 Martin Liska + + * gcc.dg/ipa/ipa-icf-33.c: New test. + 2015-01-19 Felix Yang Haijian Zhang diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-icf-33.c b/gcc/testsuite/gcc.dg/ipa/ipa-icf-33.c new file mode 100644 index 00000000000..d7e814dda3a --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-icf-33.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O0 -fipa-icf -fdump-ipa-icf" } */ + +#include + +static int +__attribute__ ((no_icf)) +foo() +{ + return 2; +} + +static int +__attribute__ ((no_icf)) +bar() +{ + return 2; +} + +int main() +{ + return foo() - bar(); +} + +/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */ +/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */ +/* { dg-final { cleanup-ipa-dump "icf" } } */ -- 2.30.2