From patchwork Mon Dec 17 19:32:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lawrence Crowl X-Patchwork-Id: 206981 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 160A02C0086 for ; Tue, 18 Dec 2012 06:33:03 +1100 (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=1356377584; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received: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=S+tr7OS 6dEYTmxYPfdHmfe85uwo=; b=Mekeh6Bu21mC699VVue/CEM83TtNHIU4ZsFrMde cdkKdIy4LzY+YJCxRKqPZ6gnphojL3fBnMYV7YVoYQy+xvvSF6BT4AvuB4N/Y+ha BzUVGnzTuD7hkdpIAKiudsDIF7ZXIatlnDUA/C87ZpLOEf+9MYoQ2eoLCseWtM+k vNJ8= 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:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Cc:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Sd5h30mC8iXSwNpsDwpEOwn5l1oHwOAZ1t7eaXI1x43Vca1H2jeR2sO4RIXZvE h4rct/3hjJnPXNrhkYMKJcIUlrtBiUpO8P/ehGMD+dJiXQUuVDOrveTtb9SOnhKK 8ArbZPs8ZELC7LkQ4i7yGQUiSAiC58jau4d0UobtW4Rd4=; Received: (qmail 15877 invoked by alias); 17 Dec 2012 19:33:00 -0000 Received: (qmail 15867 invoked by uid 22791); 17 Dec 2012 19:32:59 -0000 X-SWARE-Spam-Status: No, hits=-5.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-ie0-f175.google.com (HELO mail-ie0-f175.google.com) (209.85.223.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 17 Dec 2012 19:32:53 +0000 Received: by mail-ie0-f175.google.com with SMTP id qd14so9488101ieb.20 for ; Mon, 17 Dec 2012 11:32:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=Y1nsYIGSZCFpCVLk613kUS2pFFKd8VC6nn6Hx9AbU10=; b=CGEAzTAMLD2B8SX8uuxSuW9r1YcVjspB00+st150FLkns+AMVciSSw1SOyKySVu9Hz qtMkpYHVJPOirM++rbIK7kHrILaNRAlX9iEc4lrv+RGVUO7mzdUwaWBQOdT+G92fzZPS MA0yqjsXNn/qAqON7fGEYjTiXA2ic0iNQxJgbCnnWi+Z3Ln81vHfkDKsaM/GKjsol49D TtVXdRHhkW9HRupXQZU3gtxalYXu0JzaZHvGJUe6kzcmovxmaw+KyVcQhXGvKD6fxqSi viQWIt6YgONttWyV3JOIr7/i2ouIluTebx5vHENR2hi846kR45e9UxU9t+8+6mVLjaB1 R9Mg== MIME-Version: 1.0 Received: by 10.50.42.169 with SMTP id p9mr10296495igl.17.1355772772954; Mon, 17 Dec 2012 11:32:52 -0800 (PST) Received: by 10.231.108.73 with HTTP; Mon, 17 Dec 2012 11:32:52 -0800 (PST) Date: Mon, 17 Dec 2012 11:32:52 -0800 Message-ID: Subject: [cxx-conversion] Convert statistics.c'statistics_hashes to hash_table. From: Lawrence Crowl To: gcc-patches List Cc: Diego Novillo X-Gm-Message-State: ALoCoQkWGn2lV36xGFYeH9hAagsKYZ8DANigE12BADedLrDFIXuOGQQ0kRqJ9hO6Ki7yHxjQ9pIC7A8dRTNESU+CV3swFxAJnVFpIbWSshkttVK1MlRwzPPOl+2zooBB8sZH/gGfQmjw86XcYMRd4O1F9qx+GGBghno+9WmV1cO9g3hi8IfSxtrgm6ph57YnLRhtTGWORbRI 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 Convert statistics.c'statistics_hashes from htab_t to hash_table. Fold hash_statistics_eq into new struct stats_counter_hasher. Update dependent calls and types. Tested on x86_64. Okay for branch? Index: gcc/statistics.c =================================================================== --- gcc/statistics.c (revision 194549) +++ gcc/statistics.c (working copy) @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. #include "tree-pass.h" #include "tree-dump.h" #include "statistics.h" -#include "hashtab.h" +#include "hash-table.h" #include "function.h" static int statistics_dump_nr; @@ -43,42 +43,52 @@ typedef struct statistics_counter_s { unsigned HOST_WIDE_INT prev_dumped_count; } statistics_counter_t; -/* Array of statistic hashes, indexed by pass id. */ -static htab_t *statistics_hashes; -static unsigned nr_statistics_hashes; +/* Hashtable helpers. */ + +struct stats_counter_hasher +{ + typedef statistics_counter_t value_type; + typedef statistics_counter_t compare_type; + static inline hashval_t hash (const value_type *); + static inline bool equal (const value_type *, const compare_type *); + static inline void remove (value_type *); +}; /* Hash a statistic counter by its string ID. */ -static hashval_t -hash_statistics_hash (const void *p) +inline hashval_t +stats_counter_hasher::hash (const value_type *c) { - const statistics_counter_t *const c = (const statistics_counter_t *)p; return htab_hash_string (c->id) + c->val; } /* Compare two statistic counters by their string IDs. */ -static int -hash_statistics_eq (const void *p, const void *q) +inline bool +stats_counter_hasher::equal (const value_type *c1, const compare_type *c2) { - const statistics_counter_t *const c1 = (const statistics_counter_t *)p; - const statistics_counter_t *const c2 = (const statistics_counter_t *)q; return c1->val == c2->val && strcmp (c1->id, c2->id) == 0; } /* Free a statistics entry. */ -static void -hash_statistics_free (void *p) +inline void +stats_counter_hasher::remove (value_type *v) { - free (CONST_CAST(char *, ((statistics_counter_t *)p)->id)); - free (p); + free (CONST_CAST(char *, v->id)); + free (v); } +typedef hash_table stats_counter_table_type; + +/* Array of statistic hashes, indexed by pass id. */ +static stats_counter_table_type *statistics_hashes; +static unsigned nr_statistics_hashes; + /* Return the current hashtable to be used for recording or printing statistics. */ -static htab_t +static stats_counter_table_type curr_statistics_hash (void) { unsigned idx; @@ -87,20 +97,20 @@ curr_statistics_hash (void) idx = current_pass->static_pass_number; if (idx < nr_statistics_hashes - && statistics_hashes[idx] != NULL) + && statistics_hashes[idx].is_created ()) return statistics_hashes[idx]; if (idx >= nr_statistics_hashes) { - statistics_hashes = XRESIZEVEC (struct htab *, statistics_hashes, idx+1); + statistics_hashes = XRESIZEVEC (stats_counter_table_type, + statistics_hashes, idx+1); memset (statistics_hashes + nr_statistics_hashes, 0, - (idx + 1 - nr_statistics_hashes) * sizeof (htab_t)); + (idx + 1 - nr_statistics_hashes) + * sizeof (stats_counter_table_type)); nr_statistics_hashes = idx + 1; } - statistics_hashes[idx] = htab_create (15, hash_statistics_hash, - hash_statistics_eq, - hash_statistics_free); + statistics_hashes[idx].create (15); return statistics_hashes[idx]; } @@ -108,10 +118,11 @@ curr_statistics_hash (void) /* Helper for statistics_fini_pass. Print the counter difference since the last dump for the pass dump files. */ -static int -statistics_fini_pass_1 (void **slot, void *data ATTRIBUTE_UNUSED) +int +statistics_fini_pass_1 (statistics_counter_t **slot, + void *data ATTRIBUTE_UNUSED) { - statistics_counter_t *counter = (statistics_counter_t *)*slot; + statistics_counter_t *counter = *slot; unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count; if (count == 0) return 1; @@ -128,10 +139,11 @@ statistics_fini_pass_1 (void **slot, voi /* Helper for statistics_fini_pass. Print the counter difference since the last dump for the statistics dump. */ -static int -statistics_fini_pass_2 (void **slot, void *data ATTRIBUTE_UNUSED) +int +statistics_fini_pass_2 (statistics_counter_t **slot, + void *data ATTRIBUTE_UNUSED) { - statistics_counter_t *counter = (statistics_counter_t *)*slot; + statistics_counter_t *counter = *slot; unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count; if (count == 0) return 1; @@ -158,10 +170,11 @@ statistics_fini_pass_2 (void **slot, voi /* Helper for statistics_fini_pass, reset the counters. */ -static int -statistics_fini_pass_3 (void **slot, void *data ATTRIBUTE_UNUSED) +int +statistics_fini_pass_3 (statistics_counter_t **slot, + void *data ATTRIBUTE_UNUSED) { - statistics_counter_t *counter = (statistics_counter_t *)*slot; + statistics_counter_t *counter = *slot; counter->prev_dumped_count = counter->count; return 1; } @@ -180,26 +193,25 @@ statistics_fini_pass (void) fprintf (dump_file, "\n"); fprintf (dump_file, "Pass statistics:\n"); fprintf (dump_file, "----------------\n"); - htab_traverse_noresize (curr_statistics_hash (), - statistics_fini_pass_1, NULL); + curr_statistics_hash () + .traverse_noresize (NULL); fprintf (dump_file, "\n"); } if (statistics_dump_file && !(statistics_dump_flags & TDF_STATS || statistics_dump_flags & TDF_DETAILS)) - htab_traverse_noresize (curr_statistics_hash (), - statistics_fini_pass_2, NULL); - htab_traverse_noresize (curr_statistics_hash (), - statistics_fini_pass_3, NULL); + curr_statistics_hash () + .traverse_noresize (NULL); + curr_statistics_hash () + .traverse_noresize (NULL); } /* Helper for printing summary information. */ -static int -statistics_fini_1 (void **slot, void *data) +int +statistics_fini_1 (statistics_counter_t **slot, opt_pass *pass) { - struct opt_pass *pass = (struct opt_pass *)data; - statistics_counter_t *counter = (statistics_counter_t *)*slot; + statistics_counter_t *counter = *slot; if (counter->count == 0) return 1; if (counter->histogram_p) @@ -231,10 +243,11 @@ statistics_fini (void) { unsigned i; for (i = 0; i < nr_statistics_hashes; ++i) - if (statistics_hashes[i] != NULL + if (statistics_hashes[i].is_created () && get_pass_for_id (i) != NULL) - htab_traverse_noresize (statistics_hashes[i], - statistics_fini_1, get_pass_for_id (i)); + statistics_hashes[i] + .traverse_noresize + (get_pass_for_id (i)); } dump_end (statistics_dump_nr, statistics_dump_file); @@ -262,14 +275,14 @@ statistics_init (void) and HISTOGRAM_P. */ static statistics_counter_t * -lookup_or_add_counter (htab_t hash, const char *id, int val, +lookup_or_add_counter (stats_counter_table_type hash, const char *id, int val, bool histogram_p) { statistics_counter_t **counter; statistics_counter_t c; c.id = id; c.val = val; - counter = (statistics_counter_t **) htab_find_slot (hash, &c, INSERT); + counter = hash.find_slot (&c, INSERT); if (!*counter) { *counter = XNEW (struct statistics_counter_s);