From patchwork Sat Feb 9 20:36:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: C++ PATCH to decls_match to improve efficiency of version checking Date: Sat, 09 Feb 2013 10:36:55 -0000 From: Jason Merrill X-Patchwork-Id: 219445 Message-Id: <5116B367.2040401@redhat.com> To: gcc-patches List While looking at 56247 I noticed that the new multiversioning code was unnecessarily duplicating the calls to compare parameter and return types of a function. Fixed by moving the version code a little later. Tested x86_64-pc-linux-gnu, applying to trunk. commit 3c47969eacbc63b68740e48c0e9dae06b20ddf08 Author: Jason Merrill Date: Fri Feb 8 18:37:58 2013 -0500 * decl.c (decls_match): Check versions later. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5317fcf..5a9ad2c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -976,36 +976,6 @@ decls_match (tree newdecl, tree olddecl) if (t1 != t2) return 0; - /* The decls dont match if they correspond to two different versions - of the same function. Disallow extern "C" functions to be - versions for now. */ - if (compparms (p1, p2) - && same_type_p (TREE_TYPE (f1), TREE_TYPE (f2)) - && !DECL_EXTERN_C_P (newdecl) - && !DECL_EXTERN_C_P (olddecl) - && targetm.target_option.function_versions (newdecl, olddecl)) - { - /* Mark functions as versions if necessary. Modify the mangled decl - name if necessary. */ - if (DECL_FUNCTION_VERSIONED (newdecl) - && DECL_FUNCTION_VERSIONED (olddecl)) - return 0; - if (!DECL_FUNCTION_VERSIONED (newdecl)) - { - DECL_FUNCTION_VERSIONED (newdecl) = 1; - if (DECL_ASSEMBLER_NAME_SET_P (newdecl)) - mangle_decl (newdecl); - } - if (!DECL_FUNCTION_VERSIONED (olddecl)) - { - DECL_FUNCTION_VERSIONED (olddecl) = 1; - if (DECL_ASSEMBLER_NAME_SET_P (olddecl)) - mangle_decl (olddecl); - } - record_function_versions (olddecl, newdecl); - return 0; - } - if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl) && ! (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))) @@ -1063,6 +1033,35 @@ decls_match (tree newdecl, tree olddecl) } else types_match = 0; + + /* The decls dont match if they correspond to two different versions + of the same function. Disallow extern "C" functions to be + versions for now. */ + if (types_match + && !DECL_EXTERN_C_P (newdecl) + && !DECL_EXTERN_C_P (olddecl) + && targetm.target_option.function_versions (newdecl, olddecl)) + { + /* Mark functions as versions if necessary. Modify the mangled decl + name if necessary. */ + if (DECL_FUNCTION_VERSIONED (newdecl) + && DECL_FUNCTION_VERSIONED (olddecl)) + return 0; + if (!DECL_FUNCTION_VERSIONED (newdecl)) + { + DECL_FUNCTION_VERSIONED (newdecl) = 1; + if (DECL_ASSEMBLER_NAME_SET_P (newdecl)) + mangle_decl (newdecl); + } + if (!DECL_FUNCTION_VERSIONED (olddecl)) + { + DECL_FUNCTION_VERSIONED (olddecl) = 1; + if (DECL_ASSEMBLER_NAME_SET_P (olddecl)) + mangle_decl (olddecl); + } + record_function_versions (olddecl, newdecl); + return 0; + } } else if (TREE_CODE (newdecl) == TEMPLATE_DECL) {