From patchwork Wed Apr 17 16:00:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teresa Johnson X-Patchwork-Id: 237271 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 942EE2C050F for ; Thu, 18 Apr 2013 02:01:01 +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:date :to:subject:mime-version:content-type:content-transfer-encoding :message-id:from; q=dns; s=default; b=BQ2JuGS29ZrfLyz2bp647IA4Nq CPHyabyN5lfDlogr0dtIqkS38tAbao/HjYv006JXnp/QkhWVy2/NGzOZGn6qnHSi inoo4WRU5mDzMiWKWleQHc1Z4+4iB9EHLTBu2l9B6Kgd7a4LEQYYRt+d8JJ2PS9H hLO9cYhArugKtfJE8= 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:date :to:subject:mime-version:content-type:content-transfer-encoding :message-id:from; s=default; bh=15vLg7FVXzbjGkZN3Fq6Emq5xZA=; b= EkYlDjW02C/1VdHBQKsA4FpsxW4arFWlachXPC29HDqAn2C3McDvvtlImM9KVt7d Slq3GXxuLHBoeTS8skFzOMq0/59KaeGQ3gHwRjYi3mSIpYyPK8DZn2OSO0hrdmgI puDhOeQIP/ESxPTyDKpNDjpJhZmq+Hc3bPI6rDNR8ik= Received: (qmail 25264 invoked by alias); 17 Apr 2013 16:00:54 -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 25253 invoked by uid 89); 17 Apr 2013 16:00:54 -0000 X-Spam-SWARE-Status: No, score=-5.2 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-ve0-f201.google.com (HELO mail-ve0-f201.google.com) (209.85.128.201) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 17 Apr 2013 16:00:53 +0000 Received: by mail-ve0-f201.google.com with SMTP id jz10so174779veb.2 for ; Wed, 17 Apr 2013 09:00:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:date:to:subject:user-agent:mime-version:content-type :content-transfer-encoding:message-id:from:x-gm-message-state; bh=+WqxRFDnA3oW8tqn22teWS/iBKZYOmmJRVRjEzQmDdg=; b=nc1umxTjSYwu3VM1unAyFejjU+0qGr8A+32Ytmhz4Eo3QSSmpSBlOTX3kEu7guaV24 Gt92SWJKuZ0LsFXSscDVZ1MxmLNZMw+kEfeSrkn59WSOlozqWnZ4YzR06LBODUuACXHB By6aYQJ6GuiW7Kr1tJdOnNO+iiYWMOw8O06hmnvFW1xh1cciOm5hqVmQCGUNaA3ciesm QPaRNDG6JIy5w+pJLgokryw95X+qrSyZbdcPcJhJeOW4jWOvo8aXRmlU6J/kKUkmCIC9 ACdOPv9PD2mhM98VSYgEXLKvHJWpDiHu5hSPx482Do8psF8sXVnGDs2DWpHZGnlPjUow SQ4Q== X-Received: by 10.236.226.3 with SMTP id a3mr3323794yhq.12.1366214451289; Wed, 17 Apr 2013 09:00:51 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id h30si1361619yhi.1.2013.04.17.09.00.51 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Wed, 17 Apr 2013 09:00:51 -0700 (PDT) Received: from tjsboxrox.mtv.corp.google.com (tjsboxrox.mtv.corp.google.com [172.17.129.49]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id DC19F5AB49F; Wed, 17 Apr 2013 09:00:50 -0700 (PDT) Received: by tjsboxrox.mtv.corp.google.com (Postfix, from userid 147431) id 73DB880250; Wed, 17 Apr 2013 09:00:50 -0700 (PDT) Date: Wed, 17 Apr 2013 09:00:50 -0700 To: gcc-patches@gcc.gnu.org, davidxl@google.com, reply@codereview.appspotmail.com Subject: [google] Add libgcov interface for accessing profile directory (issue8726046) User-Agent: Heirloom mailx 12.5 6/20/10 MIME-Version: 1.0 Message-Id: <20130417160050.73DB880250@tjsboxrox.mtv.corp.google.com> From: tejohnson@google.com (Teresa Johnson) X-Gm-Message-State: ALoCoQmSiHoWmJHzGsRn9UI/z20kwSgEEpbScLneaOdjGSIiJjrFimuwKEok6t/1GZJyIP4FpXQB/DgMtYZm7eeYzbvwbBfdS7Rcounkk7W7TQszuFPw4Vkn9dsNFhv+4vGyamxuXredFAcTO5vgybTp5YoX0cL5/vnqAhHqfbg9/jqlOvlFS3uZ7ya/oO2H/Zqyk6qyxVIO Patch to add interface for querying the profile directory prefix specified to the -fprofile-generate= option. Google ref b/8629045. Tested with regression tests and internal test. Ok for google branches? 2013-04-17 Teresa Johnson * libgcc/libgcov.c (__gcov_get_profile_prefix): New function. * gcc/tree-profile.c (tree_init_instrumentation): New function. * gcc/coverage.c (get_const_string_type): Make non-static. (coverage_init): Invoke tree_init_instrumentation(). * gcc/coverage.h (get_const_string_type): Declare. (tree_init_instrumentation): Ditto. --- This patch is available for review at http://codereview.appspot.com/8726046 Index: libgcc/libgcov.c =================================================================== --- libgcc/libgcov.c (revision 197640) +++ libgcc/libgcov.c (working copy) @@ -183,6 +183,14 @@ unsigned int __gcov_sampling_enabled () return __gcov_has_sampling; } +/* Profile directory prefix specified to -fprofile-generate=. */ +extern char * __gcov_profile_prefix; + +char *__gcov_get_profile_prefix () +{ + return __gcov_profile_prefix; +} + /* Per thread sample counter. */ THREAD_PREFIX gcov_unsigned_t __gcov_sample_counter = 0; Index: gcc/tree-profile.c =================================================================== --- gcc/tree-profile.c (revision 197640) +++ gcc/tree-profile.c (working copy) @@ -165,6 +165,9 @@ static struct pointer_set_t *instrumentation_to_be /* extern __thread gcov_unsigned_t __gcov_sample_counter */ static GTY(()) tree gcov_sample_counter_decl = NULL_TREE; +/* extern gcov_unsigned_t __gcov_profile_prefix */ +static tree GTY(()) gcov_profile_prefix_decl = NULL_TREE; + /* extern gcov_unsigned_t __gcov_sampling_period */ static tree GTY(()) gcov_sampling_period_decl = NULL_TREE; @@ -407,6 +410,41 @@ cleanup_instrumentation_sampling (void) } } +/* Initialization function for FDO instrumentation. */ + +void +tree_init_instrumentation (void) +{ + if (!gcov_profile_prefix_decl) + { + tree prefix_ptr; + int prefix_len; + tree prefix_string; + + /* Construct an initializer for __gcov_profile_prefix. */ + gcov_profile_prefix_decl = + build_decl (UNKNOWN_LOCATION, VAR_DECL, + get_identifier ("__gcov_profile_prefix"), + get_const_string_type ()); + TREE_PUBLIC (gcov_profile_prefix_decl) = 1; + DECL_ARTIFICIAL (gcov_profile_prefix_decl) = 1; + make_decl_one_only (gcov_profile_prefix_decl, + DECL_ASSEMBLER_NAME (gcov_profile_prefix_decl)); + TREE_STATIC (gcov_profile_prefix_decl) = 1; + + prefix_len = strlen (profile_data_prefix); + prefix_string = build_string (prefix_len + 1, profile_data_prefix); + TREE_TYPE (prefix_string) = build_array_type + (char_type_node, build_index_type + (build_int_cst (NULL_TREE, prefix_len))); + prefix_ptr = build1 (ADDR_EXPR, get_const_string_type (), + prefix_string); + + DECL_INITIAL (gcov_profile_prefix_decl) = prefix_ptr; + varpool_finalize_decl (gcov_profile_prefix_decl); + } +} + /* Initialization function for FDO sampling. */ void Index: gcc/coverage.c =================================================================== --- gcc/coverage.c (revision 197640) +++ gcc/coverage.c (working copy) @@ -227,7 +227,7 @@ get_gcov_unsigned_t (void) /* Return the type node for const char *. */ -static tree +tree get_const_string_type (void) { return build_pointer_type @@ -2879,6 +2879,7 @@ coverage_init (const char *filename, const char* s /* Define variables which are referenced at runtime by libgcov. */ if (profiling_enabled_p ()) { + tree_init_instrumentation (); tree_init_dyn_ipa_parameters (); init_pmu_profiling (); tree_init_instrumentation_sampling (); Index: gcc/coverage.h =================================================================== --- gcc/coverage.h (revision 197640) +++ gcc/coverage.h (working copy) @@ -82,6 +82,7 @@ extern bool pmu_data_present (void); extern tree get_gcov_type (void); extern tree get_gcov_unsigned_t (void); +extern tree get_const_string_type (void); /* Mark this module as containing asm statements. */ extern void coverage_has_asm_stmt (void); @@ -89,5 +90,6 @@ extern void coverage_has_asm_stmt (void); /* Defined in tree-profile.c. */ extern void tree_init_instrumentation_sampling (void); extern void tree_init_dyn_ipa_parameters (void); +extern void tree_init_instrumentation (void); #endif