From patchwork Thu Nov 9 10:24:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 836273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-466365-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="azoK+pku"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yXfTK23RQz9s71 for ; Thu, 9 Nov 2017 21:26:13 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :resent-from:resent-to:resent-date:resent-message-id:message-id :in-reply-to:references:from:date:subject:to:cc; q=dns; s= default; b=p2P1CKAStazgXL8a97yJfjrm1Dma1m9VfBomIqmSOjTlHcWdKSG5b /nLYsB2/kMoHosIb3i1HcMHhy1WHNa9nq861B+wJKRKDpHsrfSP2WIUaXZ7aKvL9 ztlRc1NRdUNcjveoegLruK23btnqMVvxNAkAt/vIgCBrqvBvLbgPIA= 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 :resent-from:resent-to:resent-date:resent-message-id:message-id :in-reply-to:references:from:date:subject:to:cc; s=default; bh=G ioCrMNwhihZhofEN9vDCOowv4c=; b=azoK+pkuZLGuGAc0VO3iMlEzFd/8pfRws dLqjmG4asISEunlYqFZOFOGcLRve0u2dX3rEtFiEmv//DiBgFOFKZjL5DE4MBgv7 A7dUAA+3rgpWqDbIKZBu16ibCDavnUp2MqEKd/EDld7hCL6BfzUCVwR5CVcyjKQc wACZpDplIg= Received: (qmail 55461 invoked by alias); 9 Nov 2017 10:25:18 -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 55310 invoked by uid 89); 9 Nov 2017 10:25:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Nov 2017 10:25:01 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8652BACB1 for ; Thu, 9 Nov 2017 10:24:58 +0000 (UTC) Resent-From: =?utf-8?q?Martin_Li=C5=A1ka?= Resent-To: GCC Patches Resent-Date: Thu, 9 Nov 2017 11:24:58 +0100 Resent-Message-ID: <9000ede1-bfc1-acd8-2d43-eae9afd440a9@suse.cz> Resent-User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 Message-Id: <4f83c4d37f9f908ba98953842f431370096c9583.1510223055.git.mliska@suse.cz> In-Reply-To: References: From: marxin Date: Thu, 9 Nov 2017 11:24:05 +0100 Subject: [PATCH 1/7] GCOV: introduce global vector of functions To: gcc-patches@gcc.gnu.org Cc: nathan@acm.org X-IsSubscribed: yes gcc/ChangeLog: 2017-11-09 Martin Liska * gcov.c (read_graph_file): Store to global vector of functions. (read_count_file): Iterate the vector. (process_file): Likewise. (generate_results): Likewise. (release_structures): Likewise. --- gcc/gcov.c | 108 +++++++++++++++++++++++++------------------------------------ 1 file changed, 44 insertions(+), 64 deletions(-) static vector sources; @@ -532,8 +530,8 @@ static void generate_results (const char *); static void create_file_names (const char *); static char *canonicalize_name (const char *); static unsigned find_source (const char *); -static function_t *read_graph_file (void); -static int read_count_file (function_t *); +static void read_graph_file (void); +static int read_count_file (void); static void solve_flow_graph (function_t *); static void find_exception_blocks (function_t *); static void add_branch_counts (coverage_t *, const arc_t *); @@ -1095,42 +1093,40 @@ struct function_start_pair_hash : typed_noop_remove static void process_file (const char *file_name) { - function_t *fns; - create_file_names (file_name); - fns = read_graph_file (); - if (!fns) + read_graph_file (); + if (functions.empty ()) return; - read_count_file (fns); + read_count_file (); hash_map fn_map; /* Identify group functions. */ - for (function_t *f = fns; f; f = f->next) - if (!f->artificial) + for (vector::iterator it = functions.begin (); + it != functions.end (); it++) + if (!(*it)->artificial) { function_start needle; - needle.source_file_idx = f->src; - needle.start_line = f->start_line; + needle.source_file_idx = (*it)->src; + needle.start_line = (*it)->start_line; function_t **slot = fn_map.get (needle); if (slot) { - gcc_assert ((*slot)->end_line == f->end_line); + gcc_assert ((*slot)->end_line == (*it)->end_line); (*slot)->is_group = 1; - f->is_group = 1; + (*it)->is_group = 1; } else - fn_map.put (needle, f); + fn_map.put (needle, *it); } - while (fns) + for (vector::iterator it = functions.begin (); + it != functions.end (); it++) { - function_t *fn = fns; + function_t *fn = *it; - fns = fn->next; - fn->next = NULL; if (fn->counts || no_data_file) { unsigned src = fn->src; @@ -1177,14 +1173,12 @@ process_file (const char *file_name) if (fn->has_catch) find_exception_blocks (fn); } - - *fn_end = fn; - fn_end = &fn->next; } else - /* The function was not in the executable -- some other - instance must have been selected. */ - delete fn; + { + /* The function was not in the executable -- some other + instance must have been selected. */ + } } } @@ -1222,10 +1216,10 @@ output_gcov_file (const char *file_name, source_info *src) static void generate_results (const char *file_name) { - function_t *fn; - - for (fn = functions; fn; fn = fn->next) + for (vector::iterator it = functions.begin (); + it != functions.end (); it++) { + function_t *fn = *it; coverage_t coverage; if (fn->artificial) continue; @@ -1291,13 +1285,11 @@ generate_results (const char *file_name) static void release_structures (void) { - function_t *fn; + for (vector::iterator it = functions.begin (); + it != functions.end (); it++) + delete (*it); - while ((fn = functions)) - { - functions = fn->next; - delete fn; - } + functions.resize (0); } /* Generate the names of the graph and data files. If OBJECT_DIRECTORY @@ -1455,29 +1447,26 @@ find_source (const char *file_name) return idx; } -/* Read the notes file. Return list of functions read -- in reverse order. */ +/* Read the notes file. Save functions to FUNCTIONS global vector. */ -static function_t * +static void read_graph_file (void) { unsigned version; unsigned current_tag = 0; - function_t *fn = NULL; - function_t *fns = NULL; - function_t **fns_end = &fns; unsigned tag; if (!gcov_open (bbg_file_name, 1)) { fnotice (stderr, "%s:cannot open notes file\n", bbg_file_name); - return fns; + return; } bbg_file_time = gcov_time (); if (!gcov_magic (gcov_read_unsigned (), GCOV_NOTE_MAGIC)) { fnotice (stderr, "%s:not a gcov notes file\n", bbg_file_name); gcov_close (); - return fns; + return; } version = gcov_read_unsigned (); @@ -1493,6 +1482,7 @@ read_graph_file (void) } bbg_stamp = gcov_read_unsigned (); + function_t *fn = NULL; while ((tag = gcov_read_unsigned ())) { unsigned length = gcov_read_unsigned (); @@ -1514,7 +1504,8 @@ read_graph_file (void) unsigned start_column = gcov_read_unsigned (); unsigned end_line = gcov_read_unsigned (); - fn = new function_t; + fn = new function_t (); + functions.push_back (fn); fn->name = function_name; if (flag_demangled_names) { @@ -1531,9 +1522,6 @@ read_graph_file (void) fn->end_line = end_line; fn->artificial = artificial; - fn->next = NULL; - *fns_end = fn; - fns_end = &fn->next; current_tag = tag; } else if (fn && tag == GCOV_TAG_BLOCKS) @@ -1659,17 +1647,15 @@ read_graph_file (void) } gcov_close (); - if (!fns) + if (functions.empty ()) fnotice (stderr, "%s:no functions found\n", bbg_file_name); - - return fns; } /* Reads profiles from the count file and attach to each function. Return nonzero if fatal error. */ static int -read_count_file (function_t *fns) +read_count_file (void) { unsigned ix; unsigned version; @@ -1726,26 +1712,20 @@ read_count_file (function_t *fns) else if (tag == GCOV_TAG_FUNCTION && length == GCOV_TAG_FUNCTION_LENGTH) { unsigned ident; - struct function_info *fn_n; /* Try to find the function in the list. To speed up the search, first start from the last function found. */ ident = gcov_read_unsigned (); - fn_n = fns; - for (fn = fn ? fn->next : NULL; ; fn = fn->next) + + fn = NULL; + for (vector::reverse_iterator it = functions.rbegin (); + it != functions.rend (); it++) { - if (fn) - ; - else if ((fn = fn_n)) - fn_n = NULL; - else + if ((*it)->ident == ident) { - fnotice (stderr, "%s:unknown function '%u'\n", - da_file_name, ident); + fn = *it; break; } - if (fn->ident == ident) - break; } if (!fn) diff --git a/gcc/gcov.c b/gcc/gcov.c index 846a2326196..83239639247 100644 --- a/gcc/gcov.c +++ b/gcc/gcov.c @@ -392,10 +392,8 @@ public: unsigned src; /* Source file */ }; -/* Holds a list of function basic block graphs. */ - -static function_t *functions; -static function_t **fn_end = &functions; +/* Vector of all functions. */ +static vector functions; /* Vector of source files. */