From patchwork Wed Apr 10 23:47:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 235518 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 "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id AE41D2C00BD for ; Thu, 11 Apr 2013 09:47:15 +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:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=u2ihl4qbWld23zy+D+be34EHmy6vPDZuVJIbj/pyp0n enkbzyC32uXykpmZdGHftA1pd9kijO6GXnSu2u3ddhorEI53jFIa04SCkiXm1BIm Ox2sFuFJtX1O1vLWd30c3POZJDwLJOykDwtymcae5U6vU9Q91vVIFYuIT99qsavY = 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:date:message-id:subject:from:to:cc:content-type; s=default; bh=Csai4hWZ6QpcxFDk9wx9vZb4U3c=; b=Fcauvp3sWptLMCqg2 IslqxSFJEDTSTwTM+q5F9l/Mc3AiuzCMXmYxVzj7OCu5V682U/e2YjVRE3PfjK32 Tdp0LGqYilY/BplySKvOdr+ChGELaImgQWvC2YmTGFYXUg1fPYsYgyLRVTLbTyEW UIzFFQXLg9CGTxUYzL4y3CVql4= Received: (qmail 30574 invoked by alias); 10 Apr 2013 23:47:08 -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 30524 invoked by uid 89); 10 Apr 2013 23:47:07 -0000 X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mail-ee0-f43.google.com (HELO mail-ee0-f43.google.com) (74.125.83.43) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 10 Apr 2013 23:47:06 +0000 Received: by mail-ee0-f43.google.com with SMTP id e50so497189eek.16 for ; Wed, 10 Apr 2013 16:47:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to:cc :content-type:x-gm-message-state; bh=jiEbUEqMAg4Jd4ylJVNMrBx9MiilRYi1phkUAyuGYY0=; b=T7wRce2Tf51X5kVbDaOyRv7Yhc3V5lDcKCaoRbOSWl6Hu/kIYSSHKXvc+moxLlzP2G 8PgO54St/mGQw76RQiAlSukzDbbZFCJDMwiTvre3Yy6OanJU6pgk76KQI/tM9h8ZkCRh +QyzFvjqjrQE7CcKA2pq7eXva3Vz+CiYXcDOvxZupcz5XS54UYekQsK+TTUn10miOs9D 11cbhOCkz2Vqm6EB4C2Ylv4VSwkSxmS50wPDDpgj228OIi4ckkrPLFnsdHcppnll1pPs 8mD5E+Xg8TVoS2ZmZNsG4WmQQqyOFbqEvkgU4jqnEwMIRUCtMC8KE+75LSsn0RmrB08W Fmcg== MIME-Version: 1.0 X-Received: by 10.14.207.200 with SMTP id n48mr10822024eeo.4.1365637624672; Wed, 10 Apr 2013 16:47:04 -0700 (PDT) Received: by 10.15.90.193 with HTTP; Wed, 10 Apr 2013 16:47:04 -0700 (PDT) Date: Wed, 10 Apr 2013 16:47:04 -0700 Message-ID: Subject: [Google] Use line offset instead of absolute lineno to represent AutoFDO profile From: Dehao Chen To: GCC Patches Cc: David Li X-Gm-Message-State: ALoCoQkhB84UE7yx2OpfLy+xQEmv+Zg0nXA02Gee73k7P19WEAQ/HEF8KMUJ5XjZHCIJWWxrQU+v4moAWGdS/qBGxCshs1p8ufBNXRNQvSJ4BnvqylAqqCdZcsT/gbzBBU6Cuw9xWGPZPIVAMJ8QCmjNL1EmceNzcZaIGsx6JrNjMvRdWHG/Juv3Yy3hoXzzH29dG2+lsvDQ Hi, This patch 1. Uses relative line offset (lineno - start_lineno_of_function) to represent AutoFDO profile. This ensures profile still work for modified source code. 2. When matching the profile, add function name (bfd_name) to match the inline stack. Bootstrapped and passed regression tests. Is it okay for google branches? Thanks, Dehao @@ -1064,12 +1073,15 @@ read_profile (void) * sizeof (struct gcov_callsite_pos)); for (k = 0; k < gcov_functions[i].stacks[j].size; k++) { + gcov_unsigned_t line, start_line; gcov_functions[i].stacks[j].stack[k].func = file_names[gcov_read_unsigned ()]; gcov_functions[i].stacks[j].stack[k].file = file_names[gcov_read_unsigned ()]; + line = gcov_read_unsigned (); + start_line = gcov_read_unsigned (); gcov_functions[i].stacks[j].stack[k].line = - gcov_read_unsigned (); + line > start_line ? line - start_line : 0; gcov_functions[i].stacks[j].stack[k].discr = gcov_read_unsigned (); } diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c index d0ab1dc..07125e1 100644 --- a/gcc/auto-profile.c +++ b/gcc/auto-profile.c @@ -267,7 +267,9 @@ afdo_stack_hash (const void *stack) for (i = 0; i < s->size; i++) { const struct gcov_callsite_pos *p = s->stack + i; const char *file = afdo_get_filename (p->file); + const char *func = afdo_get_bfd_name (p->func); h = iterative_hash (file, strlen (file), h); + h = iterative_hash (func, strlen (func), h); h = iterative_hash (&p->line, sizeof (p->line), h); if (i == 0) h = iterative_hash (&p->discr, sizeof (p->discr), h); @@ -311,6 +313,7 @@ afdo_stack_eq (const void *p, const void *q) const struct gcov_callsite_pos *p1 = s1->stack + i; const struct gcov_callsite_pos *p2 = s2->stack + i; if (strcmp (afdo_get_filename(p1->file), afdo_get_filename(p2->file)) + || strcmp (afdo_get_bfd_name(p1->func), afdo_get_bfd_name (p2->func)) || p1->line != p2->line || (i== 0 && p1->discr != p2->discr)) return 0; } @@ -538,10 +541,10 @@ get_inline_stack_size_by_edge (struct cgraph_edge *edge) return size; } -/* Return the function name of a given lexical BLOCK. */ +/* Return the function decl of a given lexical BLOCK. */ -static const char * -get_function_name_from_block (tree block) +static tree +get_function_decl_from_block (tree block) { tree decl; for (decl = BLOCK_ABSTRACT_ORIGIN (block); @@ -549,7 +552,7 @@ get_function_name_from_block (tree block) decl = BLOCK_ABSTRACT_ORIGIN (decl)) if (TREE_CODE (decl) == FUNCTION_DECL) break; - return decl ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)) : NULL; + return decl; } /* Store the inline stack of STMT to POS_STACK, return the size of the @@ -583,16 +586,22 @@ get_inline_stack_by_stmt (gimple stmt, tree decl, block && (TREE_CODE (block) == BLOCK); block = BLOCK_SUPERCONTEXT (block)) { + tree decl = get_function_decl_from_block (block); if (LOCATION_LOCUS (BLOCK_SOURCE_LOCATION (block)) == UNKNOWN_LOCATION) continue; loc = BLOCK_SOURCE_LOCATION (block); pos_stack[idx].file = expand_location (loc).file; pos_stack[idx].line = expand_location (loc).line; - pos_stack[idx - 1].func = get_function_name_from_block (block); + pos_stack[idx - 1].func = + decl ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)) : NULL; + pos_stack[idx - 1].line -= decl ? DECL_SOURCE_LINE (decl) : 0; pos_stack[idx++].discr = 0; } if (decl) - pos_stack[idx - 1].func = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); + { + pos_stack[idx - 1].func = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); + pos_stack[idx - 1].line -= DECL_SOURCE_LINE (decl); + } return idx; }