summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-19 15:20:16 +0000
committermarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-19 15:20:16 +0000
commit85fbea9709061ce97395dec59cddefcc62e787a9 (patch)
tree606d4253fc1a5473eb60955880ac752e49f992bb
parentc16b7ed55398d2ea55d9ab35519f20cc053b9d0a (diff)
downloadgcc-85fbea9709061ce97395dec59cddefcc62e787a9.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219848 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-family/ChangeLog4
-rw-r--r--gcc/c-family/c-common.c21
-rw-r--r--gcc/doc/extend.texi6
-rw-r--r--gcc/ipa-icf.c10
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/ipa/ipa-icf-33.c27
7 files changed, 78 insertions, 0 deletions
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 <mliska@suse.cz>
+
+ * 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 <ramana.radhakrishnan@arm.com>
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 <mliska@suse.cz>
+
+ * c-common.c (handle_noicf_attribute): New function.
+
2015-01-15 Thomas Schwinge <thomas@codesourcery.com>
Bernd Schmidt <bernds@codesourcery.com>
James Norris <jnorris@codesourcery.com>
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 <mliska@suse.cz>
+
+ * gcc.dg/ipa/ipa-icf-33.c: New test.
+
2015-01-19 Felix Yang <felix.yang@huawei.com>
Haijian Zhang <z.zhanghaijian@huawei.com>
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 <stdio.h>
+
+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" } } */