From patchwork Mon Sep 30 17:43:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 279202 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 did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F34882C00F8 for ; Tue, 1 Oct 2013 03:43:26 +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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=SpOeHTqZEtAi3q6oe BY+s2/zew7U37T3FemgwTX4h+ibtWxbbhHHUjw1SGk3/UTXOR3QfNj37r0YKgnMj hvymA7huPF7QtDP0ipnE60/1Nm+oGRxT5fsNKuIo+M7OVSR0YShTJWMil/FvXuc9 i2v9PjXzWyKKBRx3jcuTYG9J9U= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=a0xep71ADDECbRGfJk5elNh 3m/A=; b=hS28JWjgBRAxqj4Sk6w1Q+SJVLLX3GtDAuGHQKwbUbpzrf2jscXvUqM KxEiPDhmcSeDgQqe+xs5yT5KTQ/0UMrGAZDUJWcKnAfRFfuM8TZe2rF0Cneq+ERZ UeS/q01CI2QuKqnJKiPzENnKCflO3bafjovSYYoxgNMqECAR9klk= Received: (qmail 30193 invoked by alias); 30 Sep 2013 17:43:19 -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 30183 invoked by uid 89); 30 Sep 2013 17:43:19 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Sep 2013 17:43:19 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8UHhG5n021551 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 30 Sep 2013 13:43:16 -0400 Received: from [10.10.55.194] (vpn-55-194.rdu2.redhat.com [10.10.55.194]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8UHhEeH027000; Mon, 30 Sep 2013 13:43:15 -0400 Message-ID: <5249B832.8000504@redhat.com> Date: Mon, 30 Sep 2013 13:43:14 -0400 From: Andrew MacLeod User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8 MIME-Version: 1.0 To: Tom Tromey CC: gcc-patches , Richard Biener , Jakub Jelinek Subject: Re: [patch] move htab_iterator References: <52499D4C.1040507@redhat.com> <8761tib8c9.fsf@fleche.redhat.com> <5249A4B7.801@redhat.com> <87pprq9rap.fsf@fleche.redhat.com> In-Reply-To: <87pprq9rap.fsf@fleche.redhat.com> X-IsSubscribed: yes On 09/30/2013 01:02 PM, Tom Tromey wrote: > Tom> How about putting it into libiberty? > Tom> That way other hashtab users, like gdb, can use it. > > Andrew> I have no problem with that, but Jakub didn't seem to think it > Andrew> belonged there. > > All I found was this: > > http://gcc.gnu.org/ml/gcc-patches/2013-09/msg00721.html > > Quoting from it: "It doesn't belong to hashtab.h, because that is a > libiberty API, this style of iterators is GCC specific." > > I think that's an accurate assessment of the current code, but I don't > see why it has to continue to be that way. > > My argument in favor of moving it to libiberty is that other programs > can then use it; and furthermore that since it is tightly tied to the > hashtab implementation, it ought to be maintained there in order to > preserve the module boundary. > > So, please reconsider. > Sure, how's this? And who has to approve the libiberty bits? Bootstrapping now... but since its unused I doubt that will be an issue :-)... Andrew gcc * tree-flow.h (htab_iterator, FOR_EACH_HTAB_ELEMENT): Move from here. * tree-flow-inline.h (first_htab_element, end_htab_p, next_htab_element): Also move from here. include * hashtab.h (htab_iterator, FOR_EACH_HTAB_ELEMENT, first_htab_element, end_htab_p, next_htab_element): Move to here. Change boolean to int and 0/1. Index: gcc/tree-flow.h =================================================================== *** gcc/tree-flow.h (revision 203034) --- gcc/tree-flow.h (working copy) *************** struct GTY(()) gimple_df { *** 92,112 **** htab_t GTY ((param_is (struct tm_restart_node))) tm_restart; }; - - typedef struct - { - htab_t htab; - PTR *slot; - PTR *limit; - } htab_iterator; - - /* Iterate through the elements of hashtable HTAB, using htab_iterator ITER, - storing each element in RESULT, which is of type TYPE. */ - #define FOR_EACH_HTAB_ELEMENT(HTAB, RESULT, TYPE, ITER) \ - for (RESULT = (TYPE) first_htab_element (&(ITER), (HTAB)); \ - !end_htab_p (&(ITER)); \ - RESULT = (TYPE) next_htab_element (&(ITER))) - /* It is advantageous to avoid things like life analysis for variables which do not need PHI nodes. This enum describes whether or not a particular variable may need a PHI node. */ --- 92,97 ---- Index: gcc/tree-flow-inline.h =================================================================== *** gcc/tree-flow-inline.h (revision 203034) --- gcc/tree-flow-inline.h (working copy) *************** gimple_vop (const struct function *fun) *** 42,93 **** return fun->gimple_df->vop; } - /* Initialize the hashtable iterator HTI to point to hashtable TABLE */ - - static inline void * - first_htab_element (htab_iterator *hti, htab_t table) - { - hti->htab = table; - hti->slot = table->entries; - hti->limit = hti->slot + htab_size (table); - do - { - PTR x = *(hti->slot); - if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY) - break; - } while (++(hti->slot) < hti->limit); - - if (hti->slot < hti->limit) - return *(hti->slot); - return NULL; - } - - /* Return current non-empty/deleted slot of the hashtable pointed to by HTI, - or NULL if we have reached the end. */ - - static inline bool - end_htab_p (const htab_iterator *hti) - { - if (hti->slot >= hti->limit) - return true; - return false; - } - - /* Advance the hashtable iterator pointed to by HTI to the next element of the - hashtable. */ - - static inline void * - next_htab_element (htab_iterator *hti) - { - while (++(hti->slot) < hti->limit) - { - PTR x = *(hti->slot); - if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY) - return x; - }; - return NULL; - } - /* Get the number of the next statement uid to be allocated. */ static inline unsigned int gimple_stmt_max_uid (struct function *fn) --- 42,47 ---- Index: include/hashtab.h =================================================================== *** include/hashtab.h (revision 203034) --- include/hashtab.h (working copy) *************** extern hashval_t iterative_hash (const v *** 202,207 **** --- 202,270 ---- /* Shorthand for hashing something with an intrinsic size. */ #define iterative_hash_object(OB,INIT) iterative_hash (&OB, sizeof (OB), INIT) + /* GCC style hash table iterator. */ + + typedef struct + { + htab_t htab; + PTR *slot; + PTR *limit; + } htab_iterator; + + /* Iterate through the elements of hashtable HTAB, using htab_iterator ITER, + storing each element in RESULT, which is of type TYPE. */ + #define FOR_EACH_HTAB_ELEMENT(HTAB, RESULT, TYPE, ITER) \ + for (RESULT = (TYPE) first_htab_element (&(ITER), (HTAB)); \ + !end_htab_p (&(ITER)); \ + RESULT = (TYPE) next_htab_element (&(ITER))) + + + /* Initialize the hashtable iterator HTI to point to hashtable TABLE */ + + static inline void * + first_htab_element (htab_iterator *hti, htab_t table) + { + hti->htab = table; + hti->slot = table->entries; + hti->limit = hti->slot + htab_size (table); + do + { + PTR x = *(hti->slot); + if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY) + break; + } while (++(hti->slot) < hti->limit); + + if (hti->slot < hti->limit) + return *(hti->slot); + return NULL; + } + + /* Return current non-empty/deleted slot of the hashtable pointed to by HTI, + or NULL if we have reached the end. */ + + static inline int + end_htab_p (const htab_iterator *hti) + { + if (hti->slot >= hti->limit) + return 1; + return 0; + } + + /* Advance the hashtable iterator pointed to by HTI to the next element of the + hashtable. */ + + static inline void * + next_htab_element (htab_iterator *hti) + { + while (++(hti->slot) < hti->limit) + { + PTR x = *(hti->slot); + if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY) + return x; + }; + return NULL; + } + #ifdef __cplusplus } #endif /* __cplusplus */