From patchwork Mon Jun 4 06:17:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 162642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C80F5B6FC5 for ; Mon, 4 Jun 2012 16:17:33 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1339395454; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=iWAS1W2mhMVnDgw3dglXfxmT11U=; b=WCQxFRTdFrjRAw7jfPyoqxfVYQ2+bG6QkXyyMF6BJLBCX4PpjyU9h6uuRY5SpJ kw3UrSoLas6wKYzccSaviiaFIHk+PMZZuck3krt8cOBaYSiDZ1l59h1sbXgyAKXc 1yT8P3BSF4wPnqWApIic3tF57b3ndTj+w+kBVdb7YU+zc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:Cc:Content-Type:X-System-Of-Record:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=BVJNIh0ftLiqIVMYiLkOK8+QPS9xaTidgUBmvmFaOvf6XuBLdkqTY8ldKbY7XS qOKhz6/ZTO29ckfet97rt7jbn3NZYCaM3t2cVb2J7zkKyNxr1eCR5FJWrHWJ3WTw dFkdnYFysP2HorA2DtkA/Ybblp4G3TqKCHKxfKkNR10U8=; Received: (qmail 3326 invoked by alias); 4 Jun 2012 06:17:28 -0000 Received: (qmail 3314 invoked by uid 22791); 4 Jun 2012 06:17:25 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_FD, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-pb0-f47.google.com (HELO mail-pb0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Jun 2012 06:17:10 +0000 Received: by pbbrq2 with SMTP id rq2so5432421pbb.20 for ; Sun, 03 Jun 2012 23:17:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-system-of-record:x-gm-message-state; bh=abiSkMS8j6PyP2GGDb5HDm+s4+akeNdfAGKO9Pg4s7c=; b=VJ1CfJy7xfE8D1e7zVP3b4WkHvXviyCUiEX3kSAQs3ufCyuX8fH9Tu0FfC44GK4cqa EOzB642UvkhD4K1OLT5N5a+kTZErJQUCPzUwVyiGpdCPoBWlz+VxwyLXALRWv+V5CaMz ZuECvYaa81JO6cOn+o9pUEVnN8xwwDUbs1kz5S7NiOw15guLthTCzzhVO13NHngvEaGT gHCALCWMgFle5KFoXP7qQm2Eld2WFQkCgdDThLfe/XUShcXB7NmcBP2Ab5Vf26FEBewh wwLC8ZLVmsWz8Cxq2iozdh5qvEpx+yKPQiiql847hnC6wPbbtV7PVDdf7uIR0nYhRahW cUYA== Received: by 10.68.132.34 with SMTP id or2mr36485955pbb.118.1338790629788; Sun, 03 Jun 2012 23:17:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.132.34 with SMTP id or2mr36485901pbb.118.1338790629393; Sun, 03 Jun 2012 23:17:09 -0700 (PDT) Received: by 10.68.204.198 with HTTP; Sun, 3 Jun 2012 23:17:09 -0700 (PDT) In-Reply-To: References: <20120602093629.GA3485@atrey.karlin.mff.cuni.cz> <20120602100600.GF20329@kam.mff.cuni.cz> <20120602181115.GA3921@kam.mff.cuni.cz> Date: Mon, 4 Jun 2012 14:17:09 +0800 Message-ID: Subject: Re: [google] Add options to pattern match function name for hotness attributes From: Dehao Chen To: Xinliang David Li Cc: Jan Hubicka , gcc-patches@gcc.gnu.org X-System-Of-Record: true X-Gm-Message-State: ALoCoQnIPG8QFuK9JbXKoCsgZWEVr9+ZQ0LLQKpJd0n1t6qutIr1h2FPzzkiDA1Uyl5DQGCYplOQOyM0w7nq/q32/15wuKCPyPKwX/yGEsaZcts76g+KVZsLnWuZyvwX21w+S83tmXAcX15xJAcnwAAElYcMTPgpNQ== X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org I've updated the patch using deferred option. http://codereview.appspot.com/6281047 Thanks, Dehao The new patch: 2012-06-01 Dehao Chen * gcc/cgraph.c (cgraph_match_attribute_by_name): New function. (cgraph_node): Add attribute to function decl. * gcc/opts-global.c (add_attribute_list_to_vector): New function. (handle_common_deferred_options): Handle new options. * gcc/opts.c (common_handle_option): Handle new options. * gcc/opts.h (attribute_pair): New type. * gcc/common.opt (flag_function_attribute_list): New option. On Sun, Jun 3, 2012 at 9:14 PM, Dehao Chen wrote: > Thank you guys for the comments, I'll update the patch to : > > 1. generalize the flag to enable other annotations such always_inline. > 2. change to use deferred option. > > Thanks, > Dehao > > On Sun, Jun 3, 2012 at 12:40 PM, Xinliang David Li wrote: >> On Sat, Jun 2, 2012 at 11:11 AM, Jan Hubicka wrote: >>>> Actually Dehao also plans to teach the static predictor to understand >>>> standard library functions more (e.g IO functions) and add more naming >>> >>> How this differ from annotating the library? >> >> I find them more suitable to be compiler heuristic than being >> function's attribute -- attribute is a much stronger assertion. >> >>> >>> There are indeed quite some possibilities to do about library calls.... >>> >>> One thing I always wondered about is how to tell predictor that paths containing >>> heavy IO functions don't need to be really opimized to death, since their execution >>> time is dominated by the IO... >>> >> >> Yes -- if branch predictor does the right thing and if function >> splitter is powerful enough, the IO code can be outlined and optimized >> for size :) >> >> >>>> based heuristics such as 'error, success, failure, fatal etc). >>> >>> yeah, this is also mentioned by some branch prediction papers. It is bit kludgy >>> in nature (i.e. it won't understand programs written in Czech language) but it >>> is an heuristics after all. >>> >> >> right. >> >> thanks, >> >> David >> >>> Honza >>>> >>>> thanks, >>>> >>>> David >>>> >>>> > Honza >>>> >> >>>> >> thanks, >>>> >> >>>> >> David >>>> >> > Honza Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 188050) +++ gcc/doc/invoke.texi (working copy) @@ -362,7 +362,8 @@ -fdelete-null-pointer-checks -fdse -fdevirtualize -fdse @gol -fearly-inlining -fipa-sra -fexpensive-optimizations -ffast-math @gol -ffinite-math-only -ffloat-store -fexcess-precision=@var{style} @gol --fforward-propagate -ffp-contract=@var{style} -ffunction-sections @gol +-fforward-propagate -ffp-contract=@var{style} @gol +-ffunction-attribute-list -ffunction-sections @gol -fgcse -fgcse-after-reload -fgcse-las -fgcse-lm -fgraphite-identity @gol -fgcse-sm -fif-conversion -fif-conversion2 -findirect-inlining @gol -finline-functions -finline-functions-called-once -finline-limit=@var{n} @gol @@ -8585,6 +8586,10 @@ specify this option and you may have problems with debugging if you specify both this option and @option{-g}. +@item -ffunction-attribute-list +@opindex ffunction-attribute-list +List of function name patterns that will be applied specified attribute. + @item -fbranch-target-load-optimize @opindex fbranch-target-load-optimize Perform branch target register load optimization before prologue / epilogue Index: gcc/cgraph.c =================================================================== --- gcc/cgraph.c (revision 188050) +++ gcc/cgraph.c (working copy) @@ -99,6 +99,7 @@ #include "ipa-utils.h" #include "lto-streamer.h" #include "l-ipo.h" +#include "opts.h" const char * const ld_plugin_symbol_resolution_names[]= { @@ -520,6 +521,32 @@ } } +/* Match FNDECL's name with user specified patterns. If match is found, add + attributes to FNDECL. + name matches with pattern, iff one of the following conditions satisfy: + 1. strcmp (name, pattern) != 0 + 2. pattern[len - 1] = '*' && strncmp (name, pattern, len - 1) != 0 */ +static void +cgraph_match_attribute_by_name (tree fndecl) +{ + unsigned i; + attribute_pair_p p; + const char *name = lang_hooks.decl_printable_name(fndecl, 0); + + if (!name) + return; + + FOR_EACH_VEC_ELT (attribute_pair_p, function_attribute_list, i, p) + { + char *n = p->name; + int len = strlen (n); + if ((n[len - 1] == '*' && !strncmp (name, n, len - 1)) + || !strcmp (name, n)) + decl_attributes (&fndecl, tree_cons ( + get_identifier (p->attribute), NULL, NULL), 0); + } +} + /* Return cgraph node assigned to DECL. Create new one when needed. */ struct cgraph_node * @@ -554,6 +581,7 @@ node->origin->nested = node; } cgraph_add_assembler_hash_node (node); + cgraph_match_attribute_by_name (decl); return node; } Index: gcc/opts.c =================================================================== --- gcc/opts.c (revision 188050) +++ gcc/opts.c (working copy) @@ -1647,6 +1647,10 @@ /* Deferred. */ break; + case OPT_ffunction_attribute_list_: + /* Deferred. */ + break; + case OPT_fsched_verbose_: #ifdef INSN_SCHEDULING /* Handled with Var in common.opt. */ Index: gcc/opts.h =================================================================== --- gcc/opts.h (revision 188050) +++ gcc/opts.h (working copy) @@ -272,6 +272,15 @@ struct cl_option_handler_func handlers[3]; }; +typedef struct { + char *name; + char *attribute; +} attribute_pair; +typedef attribute_pair *attribute_pair_p; +DEF_VEC_P(attribute_pair_p); +DEF_VEC_ALLOC_P(attribute_pair_p,heap); +extern VEC(attribute_pair_p,heap) *function_attribute_list; + /* Input file names. */ extern const char **in_fnames; Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 188050) +++ gcc/common.opt (working copy) @@ -1242,6 +1242,10 @@ Common Report Var(flag_function_sections) Place each function into its own section +ffunction-attribute-list= +Common Joined RejectNegative Var(common_deferred_options) Defer +-ffunction-attribute-list=attribute:name,... Add attribute to named functions + fgcda= Common Joined RejectNegative Var(gcov_da_name) Set the gcov data file name. Index: gcc/opts-global.c =================================================================== --- gcc/opts-global.c (revision 188050) +++ gcc/opts-global.c (working copy) @@ -50,6 +50,8 @@ const char **in_fnames; unsigned num_in_fnames; +VEC(attribute_pair_p,heap) *function_attribute_list; + /* Return a malloced slash-separated list of languages in MASK. */ static char * @@ -79,6 +81,66 @@ return result; } +/* Add strings like attribute_str:name1,name2... to a char_pair_p vector. */ + +static void +add_attribute_list_to_vector (void **pvec, const char *arg) +{ + char *tmp; + char *r; + char *w; + char *token_start; + char *attribute; + VEC(attribute_pair_p,heap) *vec = (VEC(attribute_pair_p,heap) *) *pvec; + + /* We never free this string. */ + tmp = xstrdup (arg); + attribute = tmp; + + for (r = tmp; *r != '\0' && *r != ':'; ++r) + ; + + if (*r != ':') + return; + + *r = '\0'; + ++r; + w = r; + token_start = r; + + while (*r != '\0') + { + if (*r == ',') + { + attribute_pair_p p = + (attribute_pair_p) xmalloc (sizeof (attribute_pair)); + p->name = token_start; + p->attribute = attribute; + *w++ = '\0'; + ++r; + VEC_safe_push (attribute_pair_p, heap, vec, p); + token_start = w; + } + if (*r == '\\' && r[1] == ',') + { + *w++ = ','; + r += 2; + } + else + *w++ = *r++; + } + if (*token_start != '\0') + { + attribute_pair_p p = + (attribute_pair_p) xmalloc (sizeof (attribute_pair)); + p->name = token_start; + p->attribute = attribute; + VEC_safe_push (attribute_pair_p, heap, vec, p); + } + + *pvec = vec; +} + /* Complain that switch DECODED does not apply to this front end (mask LANG_MASK). */ @@ -452,6 +514,10 @@ set_random_seed (opt->arg); break; + case OPT_ffunction_attribute_list_: + add_attribute_list_to_vector(&function_attribute_list, opt->arg); + break; + case OPT_fstack_limit: /* The real switch is -fno-stack-limit. */ if (!opt->value)