From patchwork Tue Aug 27 14:36:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 270130 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 96B952C00DA for ; Wed, 28 Aug 2013 00:36:29 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=N2kbtQ+lC2p3d/QA7I w6NAlFunUbdI66FuFiRC7m9hUd8O5V6k2D8+MIQXdSiHdfV5ejOFPxzdl/n2bSyA 5DvcuHpLiEpLHxOYYYHkYeqIl4sW1yHdnluxCylKI5IYd+9b4AZo4dFxpZJFwXbJ uzn832pnXhi7gMrpAR1LqQM4w= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=vjW6h+r/481n08vBEcIPnr52 7Yc=; b=iGrU69XS7wC/Xib7hT5J3GK0ERQjCI//HeH0DknQ+ztItqMi8xqOmCSf 1dx9fEn2x+mSpwI7M4nVaAY6GfmmjUkKXoN2YSVqmbhv824E/QQHxvc2yLh8Wbi6 RMHqRbc6B48WPFxBy6T5KCGzZbQCRDxXS3tDVgrhIJzMaAlQDpE= Received: (qmail 23121 invoked by alias); 27 Aug 2013 14:36:23 -0000 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 Received: (qmail 23108 invoked by uid 89); 27 Aug 2013 14:36:22 -0000 Received: from mail-ie0-f180.google.com (HELO mail-ie0-f180.google.com) (209.85.223.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 27 Aug 2013 14:36:22 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=BAYES_00, KHOP_THREADED, NO_RELAYS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f180.google.com Received: by mail-ie0-f180.google.com with SMTP id x14so7115093ief.25 for ; Tue, 27 Aug 2013 07:36:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=iJaVdoJjA6SBl+U0evL4vmiDDvg87RFpoL8CrNOwGOQ=; b=XTFX1zRT1JIj5XLKbU7eKrYhFpYPx8+ODZpZ+Qv4jgJaoKLPwCr+gYqtP1qh98vcSX WjvprWf94aYUQtxMwrIw02ORp9AWlUq6B7EyqSI8YtvWR217EnGEKzmoQtsLd+XmWxO7 azqK+Pbb55/quIdJyj/jpS6/yYFwR7FgIqGLcFEnuNppwuK8atOLS4sVCP9T7m+vUGNj Zx3+APwVTbH//hyccMbZQRiJqqFzOXlB+WH63gWnftkoFCRwnSYX5ENoH3o8RWr44h3s gtNhOV7HFMAv4LHS9MbGezLRA26MqWKtkzqklSwujG9TDs/PYgSYx2Jaxw0vywvwTV4z krgg== X-Gm-Message-State: ALoCoQm3yWs8Nxa8CEqYxomljB2pB3847i/Flml1V6dzaGnZxUj2/YNq2+AXQ2YDAfDor0MyPYn4eoETg5uNy383Xgk6uap/ahOrPRpvM4EFABKF7eb0Qnj7SP+v5bXokb0XO0Urq4DCimWpKDqHQbzvAKnrYud2p6vkd4YZJxAN6CFk2ITiQRuQYhWDCOKho52M7xvvxzU+sI6qILDYlUIYYBrMKmVAnw== MIME-Version: 1.0 X-Received: by 10.50.119.70 with SMTP id ks6mr10490808igb.22.1377614179394; Tue, 27 Aug 2013 07:36:19 -0700 (PDT) Received: by 10.231.73.73 with HTTP; Tue, 27 Aug 2013 07:36:19 -0700 (PDT) In-Reply-To: References: Date: Tue, 27 Aug 2013 07:36:19 -0700 Message-ID: Subject: Re: [GOOGLE] Update AutoFDO annotation From: Dehao Chen To: Xinliang David Li Cc: GCC Patches Patch updated. Thanks, Dehao On Mon, Aug 26, 2013 at 4:11 PM, Xinliang David Li wrote: > Can you add missing documentation on functions like ...:get_count_info > -- documenting return value etc. Also it might be better to avoid > using 'set' as the local variable name. Change it to something more > specific. > > thanks, > > David > > On Thu, Aug 22, 2013 at 3:56 PM, Dehao Chen wrote: >> This patch has 2 changes: >> >> 1. Now that we have discriminator for inlined callsite, we don't need >> special handling for callsite location any more. >> 2. If a source line is mapped to multiple BBs, only the first BB will >> be annotated. >> 3. Before actual annotation, mark everythin BB/edge as not annotated. >> >> Bootstrapped and passed regression test. >> >> OK for google branch? >> >> Thanks, >> Dehao >> >> Index: gcc/auto-profile.c >> =================================================================== >> --- gcc/auto-profile.c (revision 201927) >> +++ gcc/auto-profile.c (working copy) >> @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see >> #include >> #include >> #include >> +#include >> >> #include "config.h" >> #include "system.h" >> @@ -100,6 +101,10 @@ typedef std::map icall_target >> (execution_count, value_profile_histogram). */ >> typedef std::pair count_info; >> >> +/* Set of inline_stack. Used to track if the profile is already used to >> + annotate the program. */ >> +typedef std::set location_set; >> + >> struct string_compare >> { >> bool operator() (const char *a, const char *b) const >> @@ -202,7 +207,8 @@ class autofdo_source_profile { >> const function_instance *get_function_instance_by_decl (tree decl) const; >> /* Find profile info for a given gimple STMT. If found, store the profile >> info in INFO, and return true; otherwise return false. */ >> - bool get_count_info (gimple stmt, count_info *info) const; >> + bool get_count_info (gimple stmt, count_info *info, >> + const location_set *set) const; >> /* Find total count of the callee of EDGE. */ >> gcov_type get_callsite_total_count (struct cgraph_edge *edge) const; >> >> @@ -284,17 +290,13 @@ static const char *get_original_name (const char * >> >> /* Return the combined location, which is a 32bit integer in which >> higher 16 bits stores the line offset of LOC to the start lineno >> - of DECL, The lower 16 bits stores the discrimnator of LOC if >> - USE_DISCR is true, otherwise 0. */ >> + of DECL, The lower 16 bits stores the discrimnator. */ >> >> static unsigned >> -get_combined_location (location_t loc, tree decl, bool use_discr) >> +get_combined_location (location_t loc, tree decl) >> { >> - if (use_discr) >> - return ((LOCATION_LINE (loc) - DECL_SOURCE_LINE (decl)) << 16) >> - | get_discriminator_from_locus (loc); >> - else >> - return (LOCATION_LINE (loc) - DECL_SOURCE_LINE (decl)) << 16; >> + return ((LOCATION_LINE (loc) - DECL_SOURCE_LINE (decl)) << 16) >> + | get_discriminator_from_locus (loc); >> } >> >> /* Return the function decl of a given lexical BLOCK. */ >> @@ -316,7 +318,7 @@ get_function_decl_from_block (tree block) >> } >> >> static void >> -get_inline_stack (gimple stmt, bool use_discr, inline_stack *stack) >> +get_inline_stack (gimple stmt, inline_stack *stack) >> { >> location_t locus = gimple_location (stmt); >> if (LOCATION_LOCUS (locus) == UNKNOWN_LOCATION) >> @@ -337,14 +339,13 @@ static void >> >> tree decl = get_function_decl_from_block (block); >> stack->push_back (std::make_pair ( >> - decl, get_combined_location (locus, decl, level == 0 && use_discr))); >> + decl, get_combined_location (locus, decl))); >> locus = tmp_locus; >> level++; >> } >> stack->push_back (std::make_pair ( >> current_function_decl, >> - get_combined_location (locus, current_function_decl, >> - level == 0 && use_discr))); >> + get_combined_location (locus, current_function_decl))); >> } >> >> >> @@ -523,14 +524,16 @@ const function_instance *autofdo_source_profile::g >> return ret == map_.end() ? NULL : ret->second; >> } >> >> -bool autofdo_source_profile::get_count_info (gimple stmt, >> - count_info *info) const >> +bool autofdo_source_profile::get_count_info (gimple stmt, count_info *info, >> + const location_set *set) const >> { >> if (LOCATION_LOCUS (gimple_location (stmt)) == cfun->function_end_locus) >> return false; >> >> inline_stack stack; >> - get_inline_stack (stmt, true, &stack); >> + get_inline_stack (stmt, &stack); >> + if (set && set->find(stack) != set->end()) >> + return false; >> if (stack.size () == 0) >> return false; >> const function_instance *s = get_function_instance_by_inline_stack (stack); >> @@ -544,7 +547,7 @@ gcov_type autofdo_source_profile::get_callsite_tot >> { >> inline_stack stack; >> stack.push_back (std::make_pair(edge->callee->symbol.decl, 0)); >> - get_inline_stack (edge->call_stmt, false, &stack); >> + get_inline_stack (edge->call_stmt, &stack); >> >> const function_instance *s = get_function_instance_by_inline_stack (stack); >> if (s == NULL) >> @@ -821,7 +824,7 @@ afdo_vpt (gimple stmt, const icall_target_map &map >> on statements. */ >> >> static gcov_type >> -afdo_get_bb_count (basic_block bb) >> +afdo_get_bb_count (basic_block bb, location_set *set) >> { >> gimple_stmt_iterator gsi; >> gcov_type max_count = 0; >> @@ -831,7 +834,7 @@ static gcov_type >> { >> count_info info; >> gimple stmt = gsi_stmt (gsi); >> - if (afdo_source_profile->get_count_info (stmt, &info)) >> + if (afdo_source_profile->get_count_info (stmt, &info, set)) >> { >> if (info.first > max_count) >> max_count = info.first; >> @@ -840,6 +843,14 @@ static gcov_type >> afdo_vpt (stmt, info.second); >> } >> } >> + >> + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) >> + { >> + inline_stack stack; >> + get_inline_stack (gsi_stmt (gsi), &stack); >> + if (stack.size() > 0) >> + set->insert(stack); >> + } >> if (has_annotated) >> { >> bb->flags |= BB_ANNOTATED; >> @@ -1220,9 +1231,22 @@ afdo_annotate_cfg (void) >> ENTRY_BLOCK_PTR->count = s->head_count (); >> gcov_type max_count = ENTRY_BLOCK_PTR->count; >> >> + location_set set; >> + >> FOR_EACH_BB (bb) >> { >> - bb->count = afdo_get_bb_count (bb); >> + edge e; >> + edge_iterator ei; >> + >> + bb->count = 0; >> + bb->flags &= (~BB_ANNOTATED); >> + FOR_EACH_EDGE (e, ei, bb->succs) >> + { >> + e->count = 0; >> + e->flags &= (~EDGE_ANNOTATED); >> + } >> + >> + bb->count = afdo_get_bb_count (bb, &set); >> if (bb->count > max_count) >> max_count = bb->count; >> } Index: gcc/auto-profile.c =================================================================== --- gcc/auto-profile.c (revision 201927) +++ gcc/auto-profile.c (working copy) @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include #include #include +#include #include "config.h" #include "system.h" @@ -100,6 +101,10 @@ typedef std::map icall_target (execution_count, value_profile_histogram). */ typedef std::pair count_info; +/* Set of inline_stack. Used to track if the profile is already used to + annotate the program. */ +typedef std::set location_set; + struct string_compare { bool operator() (const char *a, const char *b) const @@ -158,7 +163,8 @@ class function_instance { const function_instance *get_function_instance (const inline_stack &stack, unsigned level) const; - /* Return the profile info for LOC. */ + /* Store the profile info for LOC in INFO. Return TRUE if profile info + is found. */ bool get_count_info (location_t loc, count_info *info) const; private: @@ -200,9 +206,11 @@ class autofdo_source_profile { ~autofdo_source_profile (); /* For a given DECL, returns the top-level function_instance. */ const function_instance *get_function_instance_by_decl (tree decl) const; - /* Find profile info for a given gimple STMT. If found, store the profile - info in INFO, and return true; otherwise return false. */ - bool get_count_info (gimple stmt, count_info *info) const; + /* Find profile info for a given gimple STMT. If found, and if the location + of STMT does not exist in ANNOTATED, store the profile info in INFO, and + return true; otherwise return false. */ + bool get_count_info (gimple stmt, count_info *info, + const location_set *annotated) const; /* Find total count of the callee of EDGE. */ gcov_type get_callsite_total_count (struct cgraph_edge *edge) const; @@ -284,17 +292,13 @@ static const char *get_original_name (const char * /* Return the combined location, which is a 32bit integer in which higher 16 bits stores the line offset of LOC to the start lineno - of DECL, The lower 16 bits stores the discrimnator of LOC if - USE_DISCR is true, otherwise 0. */ + of DECL, The lower 16 bits stores the discrimnator. */ static unsigned -get_combined_location (location_t loc, tree decl, bool use_discr) +get_combined_location (location_t loc, tree decl) { - if (use_discr) - return ((LOCATION_LINE (loc) - DECL_SOURCE_LINE (decl)) << 16) - | get_discriminator_from_locus (loc); - else - return (LOCATION_LINE (loc) - DECL_SOURCE_LINE (decl)) << 16; + return ((LOCATION_LINE (loc) - DECL_SOURCE_LINE (decl)) << 16) + | get_discriminator_from_locus (loc); } /* Return the function decl of a given lexical BLOCK. */ @@ -315,8 +319,10 @@ get_function_decl_from_block (tree block) return decl; } +/* Store inline stack for STMT in STACK. */ + static void -get_inline_stack (gimple stmt, bool use_discr, inline_stack *stack) +get_inline_stack (gimple stmt, inline_stack *stack) { location_t locus = gimple_location (stmt); if (LOCATION_LOCUS (locus) == UNKNOWN_LOCATION) @@ -337,14 +343,13 @@ static void tree decl = get_function_decl_from_block (block); stack->push_back (std::make_pair ( - decl, get_combined_location (locus, decl, level == 0 && use_discr))); + decl, get_combined_location (locus, decl))); locus = tmp_locus; level++; } stack->push_back (std::make_pair ( current_function_decl, - get_combined_location (locus, current_function_decl, - level == 0 && use_discr))); + get_combined_location (locus, current_function_decl))); } @@ -523,14 +528,16 @@ const function_instance *autofdo_source_profile::g return ret == map_.end() ? NULL : ret->second; } -bool autofdo_source_profile::get_count_info (gimple stmt, - count_info *info) const +bool autofdo_source_profile::get_count_info ( + gimple stmt, count_info *info, const location_set *annotated) const { if (LOCATION_LOCUS (gimple_location (stmt)) == cfun->function_end_locus) return false; inline_stack stack; - get_inline_stack (stmt, true, &stack); + get_inline_stack (stmt, &stack); + if (annotated && annotated->find(stack) != annotated->end()) + return false; if (stack.size () == 0) return false; const function_instance *s = get_function_instance_by_inline_stack (stack); @@ -544,7 +551,7 @@ gcov_type autofdo_source_profile::get_callsite_tot { inline_stack stack; stack.push_back (std::make_pair(edge->callee->symbol.decl, 0)); - get_inline_stack (edge->call_stmt, false, &stack); + get_inline_stack (edge->call_stmt, &stack); const function_instance *s = get_function_instance_by_inline_stack (stack); if (s == NULL) @@ -818,10 +825,10 @@ afdo_vpt (gimple stmt, const icall_target_map &map } /* For a given BB, return its execution count, and annotate value profile - on statements. */ + on statements. Add the location of annotated stmt to ANNOTATED. */ static gcov_type -afdo_get_bb_count (basic_block bb) +afdo_get_bb_count (basic_block bb, location_set *annotated) { gimple_stmt_iterator gsi; gcov_type max_count = 0; @@ -831,7 +838,7 @@ static gcov_type { count_info info; gimple stmt = gsi_stmt (gsi); - if (afdo_source_profile->get_count_info (stmt, &info)) + if (afdo_source_profile->get_count_info (stmt, &info, annotated)) { if (info.first > max_count) max_count = info.first; @@ -840,6 +847,14 @@ static gcov_type afdo_vpt (stmt, info.second); } } + + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + inline_stack stack; + get_inline_stack (gsi_stmt (gsi), &stack); + if (stack.size() > 0) + annotated->insert(stack); + } if (has_annotated) { bb->flags |= BB_ANNOTATED; @@ -1220,9 +1235,22 @@ afdo_annotate_cfg (void) ENTRY_BLOCK_PTR->count = s->head_count (); gcov_type max_count = ENTRY_BLOCK_PTR->count; + location_set annotated_loc_set; + FOR_EACH_BB (bb) { - bb->count = afdo_get_bb_count (bb); + edge e; + edge_iterator ei; + + bb->count = 0; + bb->flags &= (~BB_ANNOTATED); + FOR_EACH_EDGE (e, ei, bb->succs) + { + e->count = 0; + e->flags &= (~EDGE_ANNOTATED); + } + + bb->count = afdo_get_bb_count (bb, &annotated_loc_set); if (bb->count > max_count) max_count = bb->count; }