From patchwork Wed Oct 20 18:04:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 68463 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 ECC04B70CD for ; Thu, 21 Oct 2010 05:04:20 +1100 (EST) Received: (qmail 31962 invoked by alias); 20 Oct 2010 18:04:19 -0000 Received: (qmail 31947 invoked by uid 22791); 20 Oct 2010 18:04:17 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL, BAYES_00, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Oct 2010 18:04:09 +0000 Received: from eggs.gnu.org ([140.186.70.92]:32775) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1P8d1D-0005mG-Ow for gcc-patches@gnu.org; Wed, 20 Oct 2010 14:04:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8d1C-0001vs-2k for gcc-patches@gnu.org; Wed, 20 Oct 2010 14:04:07 -0400 Received: from smtp201.iad.emailsrvr.com ([207.97.245.201]:39946) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8d1B-0001vZ-W8 for gcc-patches@gnu.org; Wed, 20 Oct 2010 14:04:06 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp40.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 56DAF35030E for ; Wed, 20 Oct 2010 14:04:05 -0400 (EDT) Received: from dynamic8.wm-web.iad.mlsrvr.com (dynamic8.wm-web.iad1a.rsapps.net [192.168.2.149]) by smtp40.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 44E553502FF for ; Wed, 20 Oct 2010 14:04:05 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic8.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 36054305007D for ; Wed, 20 Oct 2010 14:04:05 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Wed, 20 Oct 2010 20:04:05 +0200 (CEST) Date: Wed, 20 Oct 2010 20:04:05 +0200 (CEST) Subject: Objc - merged classname hashtable patch from apple/trunk From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1287597845.218432219@192.168.2.230> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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 This merge from FSF apple/trunk provides a (small) speedup for compiling Objective-C. Committed to trunk (preapproved by Mike). Thanks 2010-10-20 Nicola Pero Merge from 'apple/trunk' branch on FSF servers. Obvious updates to gcc_alloc_xxx calls in hash_init and hash_class_name_enter to get it to compile in the current trunk. 2006-01-27 Fariborz Jahanian Radar 4345837 * objc/objc-act.c (hash_class_name_enter): New. (hash_class_name_lookup): New. (objc_declare_alias): Enter alias name into hash table. (objc_declare_class): Enter class name into hash table. (objc_is_class_name): Do a hash look up of class name. (hash_init): Initialize the two new hash tables. * objc-act.h: Added cls_name_hash_list and als_name_hash_list declarations, removed class_chain and alias_chain. Index: gcc/objc/objc-act.c =================================================================== --- gcc/objc/objc-act.c (revision 165714) +++ gcc/objc/objc-act.c (working copy) @@ -211,6 +211,14 @@ static const char *synth_id_with_class_suffix (con hash *nst_method_hash_list = 0; hash *cls_method_hash_list = 0; +/* Hash tables to manage the global pool of class names. */ + +hash *cls_name_hash_list = 0; +hash *als_name_hash_list = 0; + +static void hash_class_name_enter (hash *, tree, tree); +static hash hash_class_name_lookup (hash *, tree); + static hash hash_lookup (hash *, tree); static tree lookup_method (tree, tree); static tree lookup_method_static (tree, tree, int); @@ -3586,7 +3594,8 @@ objc_declare_alias (tree alias_ident, tree class_i #ifdef OBJCPLUS pop_lang_context (); #endif - alias_chain = tree_cons (underlying_class, alias_ident, alias_chain); + hash_class_name_enter (als_name_hash_list, alias_ident, + underlying_class); } } @@ -3628,7 +3637,7 @@ objc_declare_class (tree ident_list) record = xref_tag (RECORD_TYPE, ident); INIT_TYPE_OBJC_INFO (record); TYPE_OBJC_INTERFACE (record) = ident; - class_chain = tree_cons (NULL_TREE, ident, class_chain); + hash_class_name_enter (cls_name_hash_list, ident, NULL_TREE); } } } @@ -3636,7 +3645,7 @@ objc_declare_class (tree ident_list) tree objc_is_class_name (tree ident) { - tree chain; + hash target; if (ident && TREE_CODE (ident) == IDENTIFIER_NODE && identifier_global_value (ident)) @@ -3661,16 +3670,15 @@ objc_is_class_name (tree ident) if (lookup_interface (ident)) return ident; - for (chain = class_chain; chain; chain = TREE_CHAIN (chain)) - { - if (ident == TREE_VALUE (chain)) - return ident; - } + target = hash_class_name_lookup (cls_name_hash_list, ident); + if (target) + return target->key; - for (chain = alias_chain; chain; chain = TREE_CHAIN (chain)) + target = hash_class_name_lookup (als_name_hash_list, ident); + if (target) { - if (ident == TREE_VALUE (chain)) - return TREE_PURPOSE (chain); + gcc_assert (target->list && target->list->value); + return target->list->value; } return 0; @@ -7483,11 +7491,62 @@ hash_init (void) nst_method_hash_list = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE); cls_method_hash_list = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE); + cls_name_hash_list = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE); + als_name_hash_list = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE); + /* Initialize the hash table used to hold the constant string objects. */ string_htab = htab_create_ggc (31, string_hash, string_eq, NULL); } +/* This routine adds sel_name to the hash list. sel_name is a class or alias + name for the class. If alias name, then value is its underlying class. + If class, the value is NULL_TREE. */ + +static void +hash_class_name_enter (hash *hashlist, tree sel_name, tree value) +{ + hash obj; + int slot = hash_func (sel_name) % SIZEHASHTABLE; + + obj = ggc_alloc_hashed_entry (); + if (value != NULL_TREE) + { + /* Save the underlying class for the 'alias' in the hash table */ + attr obj_attr = ggc_alloc_hashed_attribute (); + obj_attr->value = value; + obj->list = obj_attr; + } + else + obj->list = 0; + obj->next = hashlist[slot]; + obj->key = sel_name; + + hashlist[slot] = obj; /* append to front */ + +} + +/* + Searches in the hash table looking for a match for class or alias name. +*/ + +static hash +hash_class_name_lookup (hash *hashlist, tree sel_name) +{ + hash target; + + target = hashlist[hash_func (sel_name) % SIZEHASHTABLE]; + + while (target) + { + if (sel_name == target->key) + return target; + + target = target->next; + } + return 0; +} + /* WARNING!!!! hash_enter is called with a method, and will peek inside to find its selector! But hash_lookup is given a selector directly, and looks for the selector that's inside the found Index: gcc/objc/ChangeLog =================================================================== --- gcc/objc/ChangeLog (revision 165714) +++ gcc/objc/ChangeLog (working copy) @@ -1,5 +1,23 @@ 2010-10-20 Nicola Pero + Merge from 'apple/trunk' branch on FSF servers. Obvious updates + to gcc_alloc_xxx calls in hash_init and hash_class_name_enter to + get it to compile in the current trunk. + + 2006-01-27 Fariborz Jahanian + + Radar 4345837 + * objc/objc-act.c (hash_class_name_enter): New. + (hash_class_name_lookup): New. + (objc_declare_alias): Enter alias name into hash table. + (objc_declare_class): Enter class name into hash table. + (objc_is_class_name): Do a hash look up of class name. + (hash_init): Initialize the two new hash tables. + * objc-act.h: Added cls_name_hash_list and als_name_hash_list + declarations, removed class_chain and alias_chain. + +2010-10-20 Nicola Pero + * objc-lang.c (finish_file): Removed. * objc-act.c (objc_finish_file): Renamed to objc_write_global_declarations. Do not try to instantiate C++ Index: gcc/objc/objc-act.h =================================================================== --- gcc/objc/objc-act.h (revision 165714) +++ gcc/objc/objc-act.h (working copy) @@ -156,6 +156,9 @@ struct GTY(()) hashed_entry { extern GTY ((length ("SIZEHASHTABLE"))) hash *nst_method_hash_list; extern GTY ((length ("SIZEHASHTABLE"))) hash *cls_method_hash_list; +extern GTY ((length ("SIZEHASHTABLE"))) hash *cls_name_hash_list; +extern GTY ((length ("SIZEHASHTABLE"))) hash *als_name_hash_list; + #define SIZEHASHTABLE 257 /* Objective-C/Objective-C++ @implementation list. */ @@ -200,8 +203,6 @@ enum objc_tree_index OCTI_NST_TYPE, OCTI_PROTO_TYPE, - OCTI_CLS_CHAIN, - OCTI_ALIAS_CHAIN, OCTI_INTF_CHAIN, OCTI_PROTO_CHAIN, OCTI_IMPL_CHAIN, @@ -338,8 +339,6 @@ extern GTY(()) tree objc_global_trees[OCTI_MAX]; (TREE_CODE (TYPE) == POINTER_TYPE \ && TREE_TYPE (TYPE) == objc_super_template) -#define class_chain objc_global_trees[OCTI_CLS_CHAIN] -#define alias_chain objc_global_trees[OCTI_ALIAS_CHAIN] #define interface_chain objc_global_trees[OCTI_INTF_CHAIN] #define protocol_chain objc_global_trees[OCTI_PROTO_CHAIN] #define implemented_classes objc_global_trees[OCTI_IMPL_CHAIN]