User directed Function Multiversioning via Function Overloading (issue5752064)

Jason Merrill jason@redhat.com
Tue Nov 6 15:52:00 GMT 2012


On 11/05/2012 09:38 PM, Sriraman Tallam wrote:
> +      /* 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;
> +	}

I still don't understand what this code is supposed to be doing.  Please 
remove it and instead modify the other loop to allow mismatches that are 
versions of the same function.

> +  /* If the olddecl is a version, so is the newdecl.  */
> +  if (TREE_CODE (newdecl) == FUNCTION_DECL
> +      && DECL_FUNCTION_VERSIONED (olddecl))
> +    {
> +      DECL_FUNCTION_VERSIONED (newdecl) = 1;
> +      /* newdecl will be purged and is no longer a version.  */
> +      delete_function_version (newdecl);
> +    }

Please make the comment clearer that the reason we're setting the flag 
on the newdecl is so that it'll be copied back into the olddecl; 
otherwise it seems odd to say it's a version and then it isn't a version.

> +  /* If a pointer to a function that is multi-versioned is requested, the
> +     pointer to the dispatcher function is returned instead.  This works
> +     well because indirectly calling the function will dispatch the right
> +     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;

This code should use the get_function_version_dispatcher function in 
cp/call.c.

Jason



More information about the Gcc-patches mailing list