From patchwork Wed Oct 2 11:52:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 279707 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 666002C00A3 for ; Wed, 2 Oct 2013 21:52:28 +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=fC/+5pkfbieMzUiUi rM36d8QatYrV610M0cp6qS5XfIESA5Mi7DO7kuWGEhTntWm01UIlKSRnDq5zGJwj Neg5x+quqGfwEFhGUjw7EJErSIdVvi4uCSY9A0AbJPXsTw6fJttIGxLky6QjJ/k3 jhzKQmBKtIlP+ghBE3na3m3hEI= 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=xG5IWXLpFU9s+YAp3Gv+fnK rU0c=; b=Ges8a8Ax6YKBvp8VXvb2sLxOy0njgtECVBlAwkFyS8cwijGAXFJWlKB Qg6kGWYRknKKcEWvJl/eSMw6pscOf7MOF20ZcYbPJi5npemLUS9v8kHFPOMNYwRc /8xNyAxVmBGfeda64yNFJh9udC9gFi6JIQxSu4+c/DWeV0bVyhEs= Received: (qmail 18995 invoked by alias); 2 Oct 2013 11:52:21 -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 18983 invoked by uid 89); 2 Oct 2013 11:52:21 -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; Wed, 02 Oct 2013 11:52:21 +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 r92BqISm001890 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Oct 2013 07:52:19 -0400 Received: from [10.10.51.97] (vpn-51-97.rdu2.redhat.com [10.10.51.97]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r92BqHnd024079; Wed, 2 Oct 2013 07:52:17 -0400 Message-ID: <524C08F1.3060503@redhat.com> Date: Wed, 02 Oct 2013 07:52:17 -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: DJ Delorie CC: Tom Tromey , gcc-patches@gcc.gnu.org, richard.guenther@gmail.com, jakub@redhat.com 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> <5249B832.8000504@redhat.com> <878uyc4u5l.fsf@fleche.redhat.com> <201310012104.r91L44CD027928@greed.delorie.com> In-Reply-To: <201310012104.r91L44CD027928@greed.delorie.com> X-IsSubscribed: yes On 10/01/2013 05:04 PM, DJ Delorie wrote: > I'm typically against adding things to libiberty "because there's no > other place for them". The purpose of libiberty is to provide a > portability layer, not a trash can. However, htab is already in > there, and the argument for putting its accessors there is sound. I think it is the place they belong if someone wants them. Jakub didn't want to lose them, and Tom expressed an interest in them. > > However, most of the other functions in hashtab.h are of the form > htab_*(). Could these be changed to match that pattern? If these > functions are unused, it shouldn't matter to rename them. (although, > if they're unused, it shouldn't matter to discard them, either) I can easily rename them, like so. They are also here for the record now... If you don't want to approve this because it is unused (and I understand that), anyone can re-introduce them when they actually want to use them... 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, HTAB_FOR_EACH_ELEMENT, htab_first_element, htab_next_element): Rename and move to here. (htab_end_p): Rename, move and change boolean to int and 0/1. Index: gcc/tree-flow.h =================================================================== *** gcc/tree-flow.h (revision 203068) --- 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))) - static inline int get_lineno (const_gimple); /*--------------------------------------------------------------------------- --- 92,97 ---- Index: gcc/tree-flow-inline.h =================================================================== *** gcc/tree-flow-inline.h (revision 203068) --- 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 203067) --- include/hashtab.h (working copy) *************** extern hashval_t iterative_hash (const v *** 202,207 **** --- 202,269 ---- /* 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 HTAB_FOR_EACH_ELEMENT(HTAB, RESULT, TYPE, ITER) \ + for (RESULT = (TYPE) htab_first_element (&(ITER), (HTAB)); \ + !htab_end_p (&(ITER)); \ + RESULT = (TYPE) htab_next_element (&(ITER))) + + /* Initialize the hashtable iterator HTI to point to hashtable TABLE */ + + static inline void * + htab_first_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 + htab_end_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 * + htab_next_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 */