public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Sriraman Tallam <tmsriram@google.com>
To: Jason Merrill <jason@redhat.com>
Cc: David Li <davidxl@google.com>, "H.J. Lu" <hjl.tools@gmail.com>,
		gcc-patches List <gcc-patches@gcc.gnu.org>,
	Jan Hubicka <jh@suse.cz>, 	Diego Novillo <dnovillo@google.com>
Subject: Re: User directed Function Multiversioning via Function Overloading (issue5752064)
Date: Tue, 13 Nov 2012 01:11:00 -0000	[thread overview]
Message-ID: <CAAs8Hmwa80GxP=eHEq0KZSKqA4Y9QtfbU-ATx1g42PRTpcjkuA@mail.gmail.com> (raw)
In-Reply-To: <50A08349.4070101@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1204 bytes --]

Hi Jason,

   Made the changes. Also fixed one more segfault bug when ifunc is
not supported.

Thanks,
-Sri.

On Sun, Nov 11, 2012 at 9:04 PM, Jason Merrill <jason@redhat.com> wrote:
> On 11/09/2012 08:33 PM, Sriraman Tallam wrote:
>>
>> +         /* Skip calling decls_match for versioned functions.  */
>> +          if (DECL_FUNCTION_VERSIONED (fn)
>> +             && DECL_FUNCTION_VERSIONED (TREE_PURPOSE (match)))
>> +           continue;
>> +         if (!decls_match (fn, TREE_PURPOSE (match)))
>> +            break;
>
>
> This seems like it would allow multiple versioned functions from different
> namespaces; I want to allow mismatches only if they are versions of the same
> function.  I was thinking
>
>
>          for (match = TREE_CHAIN (matches); match; match = TREE_CHAIN
> (match))
>             if (!decls_match (fn, TREE_PURPOSE (match))
>                 && !targetm.target_option.function_versions (fn,
> TREE_PURPOSE (match)))
>               break;
>
>> +      error_at (input_location, "Call/Pointer to multiversioned function"
>> +                " without a default cannot be dispatched");
>
>
> Let's just say "use of multiversioned  function without a default".
>
> Jason
>

[-- Attachment #2: mv_patch.txt --]
[-- Type: text/plain, Size: 9215 bytes --]

	* cgraph.c (insert_new_cgraph_node_version): Use cgraph_get_node
	instead of cgraph_get_create_node.
	* cp/class.c (mark_versions_used): Remove.
	(resolve_address_of_overloaded_function): Do not call decls_match
	for versioned functions. Call get_function_versions_dispatcher.
	* cp/decl.c (duplicate_decls): Add comments.
	* cp/call.c (get_function_version_dispatcher): Expose function.
	(mark_versions_used): Expose function.
	* cp/cp-tree.h (mark_versions_used): New declaration.
	(get_function_version_dispatcher): Ditto.
	* config/i386/i386.c (ix86_get_function_versions_dispatcher): Move ifunc
	not supported code to the end.
	* testsuite/g++.dg/mv4.C: Add require ifunc. Change error message.
	* testsuite/g++.dg/mv5.C: Add require ifunc.
	* testsuite/g++.dg/mv6.C: Add require ifunc.

Index: cgraph.c
===================================================================
--- cgraph.c	(revision 193452)
+++ cgraph.c	(working copy)
@@ -206,7 +206,7 @@ insert_new_cgraph_node_version (struct cgraph_node
 void
 delete_function_version (tree decl)
 {
-  struct cgraph_node *decl_node = cgraph_get_create_node (decl);
+  struct cgraph_node *decl_node = cgraph_get_node (decl);
   struct cgraph_function_version_info *decl_v = NULL;
 
   if (decl_node == NULL)
Index: testsuite/g++.dg/mv4.C
===================================================================
--- testsuite/g++.dg/mv4.C	(revision 193452)
+++ testsuite/g++.dg/mv4.C	(working copy)
@@ -3,6 +3,7 @@
    and its pointer is taken.  */
 
 /* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-ifunc "" }  */
 /* { dg-options "-O2 -mno-sse -mno-popcnt" } */
 
 int __attribute__ ((target ("sse")))
@@ -18,6 +19,6 @@ foo ()
 
 int main ()
 {
-  int (*p)() = &foo; /* { dg-error "Pointer to a multiversioned function without a default is not allowed" {} } */
+  int (*p)() = &foo; /* { dg-error "Use of multiversioned function without a default" {} } */
   return (*p)();
 }
Index: testsuite/g++.dg/mv6.C
===================================================================
--- testsuite/g++.dg/mv6.C	(revision 193452)
+++ testsuite/g++.dg/mv6.C	(working copy)
@@ -1,6 +1,7 @@
 /* Test to check if member version multiversioning works correctly.  */
 
 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-ifunc "" }  */
 
 class Foo
 {
Index: testsuite/g++.dg/mv5.C
===================================================================
--- testsuite/g++.dg/mv5.C	(revision 193452)
+++ testsuite/g++.dg/mv5.C	(working copy)
@@ -2,6 +2,7 @@
    marked comdat with inline keyword.  */
 
 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-ifunc "" }  */
 /* { dg-options "-O2  -mno-popcnt" } */
 
 
Index: cp/class.c
===================================================================
--- cp/class.c	(revision 193452)
+++ cp/class.c	(working copy)
@@ -7068,38 +7068,6 @@ pop_lang_context (void)
 {
   current_lang_name = VEC_pop (tree, current_lang_base);
 }
-
-/* fn is a function version dispatcher that is marked used. Mark all the 
-   semantically identical function versions it will dispatch as used.  */
-
-static void
-mark_versions_used (tree fn)
-{
-  struct cgraph_node *node;
-  struct cgraph_function_version_info *node_v;
-  struct cgraph_function_version_info *it_v;
-
-  gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
-
-  node = cgraph_get_node (fn);
-  if (node == NULL)
-    return;
-
-  gcc_assert (node->dispatcher_function);
-
-  node_v = get_cgraph_node_version (node);
-  if (node_v == NULL)
-    return;
-
-  /* All semantically identical versions are chained.  Traverse and mark each
-     one of them as used.  */
-  it_v = node_v->next;
-  while (it_v != NULL)
-    {
-      mark_used (it_v->this_node->symbol.decl);
-      it_v = it_v->next;
-    }
-}
 \f
 /* Type instantiation routines.  */
 
@@ -7315,22 +7283,13 @@ resolve_address_of_overloaded_function (tree targe
 
       fn = TREE_PURPOSE (matches);
 
-      /* For multi-versioned functions, more than one match is just fine.
-	 Call decls_match to make sure they are different because they are
-	 versioned.  */
-      if (DECL_FUNCTION_VERSIONED (fn))
-	{
-          for (match = TREE_CHAIN (matches); match; match = TREE_CHAIN (match))
-  	    if (!DECL_FUNCTION_VERSIONED (TREE_PURPOSE (match))
-	        || decls_match (fn, TREE_PURPOSE (match)))
-	      break;
-	}
-      else
-	{
-          for (match = TREE_CHAIN (matches); match; match = TREE_CHAIN (match))
-  	    if (!decls_match (fn, TREE_PURPOSE (match)))
-	      break;
-	}
+      /* For multi-versioned functions, more than one match is just fine and
+	 decls_match will return false as they are different.  */
+      for (match = TREE_CHAIN (matches); match; match = TREE_CHAIN (match))
+	if (!decls_match (fn, TREE_PURPOSE (match))
+	    && !targetm.target_option.function_versions (fn,
+	         TREE_PURPOSE (match)))
+          break;
 
       if (match)
 	{
@@ -7377,17 +7336,9 @@ resolve_address_of_overloaded_function (tree targe
      function version at run-time.  */
   if (DECL_FUNCTION_VERSIONED (fn))
     {
-      tree dispatcher_decl = NULL;
-      gcc_assert (targetm.get_function_versions_dispatcher);
-      dispatcher_decl = targetm.get_function_versions_dispatcher (fn);
-      if (!dispatcher_decl)
-	{
-	  error_at (input_location, "Pointer to a multiversioned function"
-		    " without a default is not allowed");
-	  return error_mark_node;
-	}
-      retrofit_lang_decl (dispatcher_decl);
-      fn = dispatcher_decl;
+      fn = get_function_version_dispatcher (fn);
+      if (fn == NULL)
+	return error_mark_node;
       /* Mark all the versions corresponding to the dispatcher as used.  */
       if (!(flags & tf_conv))
 	mark_versions_used (fn);
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 193452)
+++ cp/decl.c	(working copy)
@@ -2307,12 +2307,15 @@ duplicate_decls (tree newdecl, tree olddecl, bool
   else if (DECL_PRESERVE_P (newdecl))
     DECL_PRESERVE_P (olddecl) = 1;
 
-  /* If the olddecl is a version, so is the newdecl.  */
+  /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
+     to olddecl and deleted.  */
   if (TREE_CODE (newdecl) == FUNCTION_DECL
       && DECL_FUNCTION_VERSIONED (olddecl))
     {
+      /* Set the flag for newdecl so that it gets copied to olddecl.  */
       DECL_FUNCTION_VERSIONED (newdecl) = 1;
-      /* newdecl will be purged and is no longer a version.  */
+      /* newdecl will be purged after copying to olddecl and is no longer
+         a version.  */
       delete_function_version (newdecl);
     }
 
Index: cp/call.c
===================================================================
--- cp/call.c	(revision 193452)
+++ cp/call.c	(working copy)
@@ -6517,7 +6517,7 @@ magic_varargs_p (tree fn)
 
 /* Returns the decl of the dispatcher function if FN is a function version.  */
 
-static tree
+tree
 get_function_version_dispatcher (tree fn)
 {
   tree dispatcher_decl = NULL;
@@ -6530,8 +6530,8 @@ get_function_version_dispatcher (tree fn)
 
   if (dispatcher_decl == NULL)
     {
-      error_at (input_location, "Call to multiversioned function"
-                " without a default is not allowed");
+      error_at (input_location, "Use of multiversioned function "
+				"without a default");
       return NULL;
     }
 
@@ -6543,7 +6543,7 @@ get_function_version_dispatcher (tree fn)
 /* fn is a function version dispatcher that is marked used. Mark all the 
    semantically identical function versions it will dispatch as used.  */
 
-static void
+void
 mark_versions_used (tree fn)
 {
   struct cgraph_node *node;
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h	(revision 193452)
+++ cp/cp-tree.h	(working copy)
@@ -4971,6 +4971,8 @@ extern bool is_list_ctor			(tree);
 #ifdef ENABLE_CHECKING
 extern void validate_conversion_obstack		(void);
 #endif /* ENABLE_CHECKING */
+extern void mark_versions_used			(tree);
+extern tree get_function_version_dispatcher	(tree);
 
 /* in class.c */
 extern tree build_vfield_ref			(tree, tree);
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 193452)
+++ config/i386/i386.c	(working copy)
@@ -28926,11 +28926,6 @@ ix86_get_function_versions_dispatcher (void *decl)
 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE) && HAVE_GNU_INDIRECT_FUNCTION
   /* Right now, the dispatching is done via ifunc.  */
   dispatch_decl = make_dispatcher_decl (default_node->symbol.decl); 
-#else
-  error_at (DECL_SOURCE_LOCATION (default_node->symbol.decl),
-	    "Multiversioning needs ifunc which is not supported "
-	    "in this configuration");
-#endif
 
   dispatcher_node = cgraph_get_create_node (dispatch_decl);
   gcc_assert (dispatcher_node != NULL);
@@ -28947,7 +28942,11 @@ ix86_get_function_versions_dispatcher (void *decl)
       it_v->dispatcher_resolver = dispatch_decl;
       it_v = it_v->next;
     }
-
+#else
+  error_at (DECL_SOURCE_LOCATION (default_node->symbol.decl),
+	    "Multiversioning needs ifunc which is not supported "
+	    "in this configuration");
+#endif
   return dispatch_decl;
 }
 

  reply	other threads:[~2012-11-13  1:11 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-07  0:47 Sriraman Tallam
2012-03-07 14:05 ` Richard Guenther
2012-03-07 19:08   ` Sriraman Tallam
2012-03-08 21:37     ` Xinliang David Li
2012-03-08 21:00   ` Xinliang David Li
2012-03-09 20:04   ` Sriraman Tallam
2012-04-27  5:09     ` Sriraman Tallam
2012-04-27 13:39       ` H.J. Lu
2012-04-27 14:35         ` Sriraman Tallam
2012-04-27 14:39           ` H.J. Lu
2012-04-27 14:53             ` Sriraman Tallam
2012-04-27 15:36               ` H.J. Lu
2012-04-27 15:45                 ` Sriraman Tallam
2012-05-01 23:51                 ` Sriraman Tallam
2012-05-02  0:09                   ` H.J. Lu
2012-05-02  2:45                     ` Sriraman Tallam
2012-05-02 13:42                       ` H.J. Lu
2012-05-02 15:08                         ` Sriraman Tallam
2012-05-02 16:06                           ` H.J. Lu
2012-05-02 17:44                             ` Sriraman Tallam
2012-05-02 18:04                               ` H.J. Lu
2012-05-07 16:58                                 ` Sriraman Tallam
2012-05-09 19:01                                   ` Sriraman Tallam
2012-05-10 17:55                                     ` H.J. Lu
2012-05-12  2:04                                       ` Sriraman Tallam
2012-05-12 13:38                                         ` H.J. Lu
2012-05-14 18:29                                           ` Sriraman Tallam
2012-05-26  0:07                                             ` H.J. Lu
2012-05-26  0:16                                               ` Sriraman Tallam
2012-05-26  0:27                                                 ` H.J. Lu
2012-05-26  1:54                                                   ` Sriraman Tallam
     [not found]                                                     ` <CAMe9rOowm9K7r1xnRdRjW5Y4Ay+WxgSsBLTgGvq24z=i42AS+g@mail.gmail.com>
     [not found]                                                       ` <CAAs8HmzeQigcLQyfkC02u=6gCTLkjLLa_jYmp+b1HEtpMCrYWw@mail.gmail.com>
2012-05-26  5:06                                                         ` H.J. Lu
2012-05-26 22:35                                                           ` Sriraman Tallam
2012-05-26 23:56                                                             ` H.J. Lu
2012-05-27  0:24                                                               ` Sriraman Tallam
2012-05-27  2:06                                                                 ` H.J. Lu
2012-05-27  2:23                                                                   ` Sriraman Tallam
2012-05-27  2:31                                                                     ` H.J. Lu
2012-05-27 19:02                                                                     ` Ian Lance Taylor
2012-06-04 19:01                                             ` Sriraman Tallam
2012-06-04 21:36                                               ` H.J. Lu
2012-06-04 22:29                                                 ` Sriraman Tallam
2012-06-05 13:56                                                   ` H.J. Lu
2012-06-14 20:35                                               ` Sriraman Tallam
2012-06-20  1:10                                                 ` Sriraman Tallam
2012-07-06  9:14                                                 ` Richard Guenther
2012-07-06 17:38                                                   ` Sriraman Tallam
2012-07-07  6:06                                                 ` Jason Merrill
2012-07-07 18:38                                                   ` Xinliang David Li
2012-07-08 11:21                                                     ` Jason Merrill
2012-07-09 21:27                                                       ` Xinliang David Li
2012-07-10  9:46                                                         ` Jason Merrill
2012-07-10 16:09                                                           ` Xinliang David Li
     [not found]                                                             ` <CAAs8HmxHF38ktt6syjWp-MpjiX+6NcXh7_8Xn6iKnAiF2vRymQ@mail.gmail.com>
2012-07-19 20:40                                                               ` Jason Merrill
2012-07-30 19:16                                                                 ` Sriraman Tallam
2012-08-25  0:34                                                                   ` Sriraman Tallam
2012-09-18 16:29                                                                     ` Sriraman Tallam
2012-10-05 17:07                                                                       ` Xinliang David Li
2012-10-05 17:44                                                                     ` Jason Merrill
2012-10-05 18:14                                                                       ` Jason Merrill
2012-10-05 21:58                                                                       ` Sriraman Tallam
2012-10-05 22:50                                                                         ` Jason Merrill
2012-10-05 23:45                                                                           ` Sriraman Tallam
2012-10-05 18:32                                                                     ` Jason Merrill
2012-10-11  0:13                                                                       ` Sriraman Tallam
2012-10-12 22:41                                                                         ` Sriraman Tallam
2012-10-19 15:23                                                                           ` Diego Novillo
2012-10-20  4:29                                                                             ` Sriraman Tallam
2012-10-23 21:21                                                                               ` Sriraman Tallam
2012-10-26 16:53                                                                                 ` Jan Hubicka
2012-10-28  4:31                                                                                   ` Sriraman Tallam
2012-10-29 13:05                                                                                     ` Jan Hubicka
2012-10-29 17:56                                                                                       ` Sriraman Tallam
2012-10-30 19:18                                                                                     ` Jason Merrill
2012-10-31  0:58                                                                                       ` Sriraman Tallam
     [not found]                                                                                       ` <CAAs8Hmw09giv-5_v0irhByTjTJV=kD58rCAD2SAz7M8zrwjBOA@mail.gmail.com>
2012-10-31 14:27                                                                                         ` Jason Merrill
2012-11-02  2:53                                                                                           ` Sriraman Tallam
2012-11-06  2:38                                                                                             ` Sriraman Tallam
2012-11-06 15:52                                                                                               ` Jason Merrill
2012-11-06 18:17                                                                                                 ` Sriraman Tallam
2012-11-10  1:33                                                                                                 ` Sriraman Tallam
2012-11-12  5:04                                                                                                   ` Jason Merrill
2012-11-13  1:11                                                                                                     ` Sriraman Tallam [this message]
2012-11-13  2:39                                                                                                       ` Jason Merrill
2012-11-13 21:57                                                                                                         ` Sriraman Tallam
2012-11-17 22:23                                                                                                           ` H.J. Lu
2012-11-06 22:15                                                                                               ` Gerald Pfeifer
2012-10-26 14:11                                                                               ` Diego Novillo
2012-10-26 16:54 Xinliang David Li
2012-10-26 17:28 ` Sriraman Tallam
2012-11-06 22:17 Dominique Dhumieres
2012-11-07  1:16 ` Gerald Pfeifer
2012-11-07  8:53   ` Dominique Dhumieres

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAs8Hmwa80GxP=eHEq0KZSKqA4Y9QtfbU-ATx1g42PRTpcjkuA@mail.gmail.com' \
    --to=tmsriram@google.com \
    --cc=davidxl@google.com \
    --cc=dnovillo@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=jason@redhat.com \
    --cc=jh@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).