From patchwork Tue Nov 16 22:40:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 71467 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 91222B7130 for ; Wed, 17 Nov 2010 09:40:29 +1100 (EST) Received: (qmail 14269 invoked by alias); 16 Nov 2010 22:40:27 -0000 Received: (qmail 14083 invoked by uid 22791); 16 Nov 2010 22:40:24 -0000 X-SWARE-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_CC, TW_CX, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Nov 2010 22:40:19 +0000 Received: from hpaq12.eem.corp.google.com (hpaq12.eem.corp.google.com [172.25.149.12]) by smtp-out.google.com with ESMTP id oAGMeGsR014299 for ; Tue, 16 Nov 2010 14:40:16 -0800 Received: from pvg6 (pvg6.prod.google.com [10.241.210.134]) by hpaq12.eem.corp.google.com with ESMTP id oAGMeESs013067 for ; Tue, 16 Nov 2010 14:40:15 -0800 Received: by pvg6 with SMTP id 6so439148pvg.9 for ; Tue, 16 Nov 2010 14:40:14 -0800 (PST) Received: by 10.142.180.16 with SMTP id c16mr7379934wff.26.1289947213955; Tue, 16 Nov 2010 14:40:13 -0800 (PST) Received: from coign.google.com (dhcp-172-22-124-185.mtv.corp.google.com [172.22.124.185]) by mx.google.com with ESMTPS id w14sm1927098wfd.6.2010.11.16.14.40.12 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 16 Nov 2010 14:40:13 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Work with different hash table implementations Date: Tue, 16 Nov 2010 14:40:10 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true 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 gccgo patch checks for which hash table implementations are available, and uses a preprocessor macro to pick one. This is more or less copied from gold. This works with a compiler which provides std::unordered_map, std::tr1::unordered_map, or __gnu_cxx::hash_map. This is purely for portability, so that a cross-gccgo can be built by a compiler which doesn't provide std::tr1::unordered_map. Committed to gccgo branch. Ian Index: configure.ac =================================================================== --- configure.ac (revision 166782) +++ configure.ac (working copy) @@ -909,6 +909,18 @@ AC_CHECK_HEADER(pthread.h, [have_pthread gcc_AC_C_CHAR_BIT AC_C_BIGENDIAN +# -------------------- +# Checks for C++ headers +# -------------------- + +AC_LANG_PUSH(C++) + +AC_CHECK_HEADERS(unordered_map) +AC_CHECK_HEADERS(tr1/unordered_map) +AC_CHECK_HEADERS(ext/hash_map) + +AC_LANG_POP(C++) + # -------- # UNSORTED # -------- Index: go/go-system.h =================================================================== --- go/go-system.h (revision 166822) +++ go/go-system.h (working copy) @@ -26,7 +26,72 @@ #include #include -#include + +#if defined(HAVE_UNORDERED_MAP) + +# include + +# define Unordered_map(KEYTYPE, VALTYPE) \ + std::unordered_map + +# define Unordered_map_hash(KEYTYPE, VALTYPE, HASHFN, EQFN) \ + std::unordered_map + +#elif defined(HAVE_TR1_UNORDERED_MAP) + +# include + +# define Unordered_map(KEYTYPE, VALTYPE) \ + std::tr1::unordered_map + +# define Unordered_map_hash(KEYTYPE, VALTYPE, HASHFN, EQFN) \ + std::tr1::unordered_map + +#elif defined(HAVE_EXT_HASH_MAP) + +# include + +# define Unordered_map(KEYTYPE, VALTYPE) \ + __gnu_cxx::hash_map + +# define Unordered_map_hash(KEYTYPE, VALTYPE, HASHFN, EQFN) \ + __gnu_cxx::hash_map + +// Provide hash functions for strings and pointers. + +namespace __gnu_cxx +{ + +template<> +struct hash +{ + size_t + operator()(std::string s) const + { return __stl_hash_string(s.c_str()); } +}; + +template +struct hash +{ + size_t + operator()(T* p) const + { return reinterpret_cast(p); } +}; + +} + +#else + +# include + +# define Unordered_map(KEYTYPE, VALTYPE) \ + std::map + +// We could make this work by writing an adapter class which +// implemented operator< in terms of the hash function. +# error "requires hash table type" + +#endif // We don't really need iostream, but some versions of gmp.h include // it when compiled with C++, which means that we need to include it diff -r ca804e7183fe go/export.h --- a/go/export.h Tue Nov 16 12:48:08 2010 -0800 +++ b/go/export.h Tue Nov 16 14:36:13 2010 -0800 @@ -163,7 +163,7 @@ register_builtin_type(Gogo*, const char* name, Builtin_code); // Mapping from Type objects to a constant index. - typedef std::tr1::unordered_map Type_refs; + typedef Unordered_map(const Type*, int) Type_refs; // The stream to which we are writing data. Stream* stream_; diff -r ca804e7183fe go/gogo.h --- a/go/gogo.h Tue Nov 16 12:48:08 2010 -0800 +++ b/go/gogo.h Tue Nov 16 14:36:13 2010 -0800 @@ -612,12 +612,12 @@ typedef std::map Sys_names; // Hash table mapping map types to map descriptor decls. - typedef std::tr1::unordered_map Map_descriptors; + typedef Unordered_map_hash(const Map_type*, tree, Type_hash_identical, + Type_identical) Map_descriptors; // Map unnamed types to type descriptor decls. - typedef std::tr1::unordered_map Type_descriptor_decls; + typedef Unordered_map_hash(const Type*, tree, Type_hash_identical, + Type_identical) Type_descriptor_decls; // The package we are compiling. Package* package_; @@ -932,7 +932,7 @@ private: // Type for mapping from label names to Label objects. - typedef std::tr1::unordered_map Labels; + typedef Unordered_map(std::string, Label*) Labels; tree make_receiver_parm_decl(Gogo*, Named_object*, tree); @@ -1846,7 +1846,7 @@ { public: // Type for mapping from names to objects. - typedef std::tr1::unordered_map Contour; + typedef Unordered_map(std::string, Named_object*) Contour; Bindings(Bindings* enclosing); diff -r ca804e7183fe go/types.cc --- a/go/types.cc Tue Nov 16 12:48:08 2010 -0800 +++ b/go/types.cc Tue Nov 16 14:36:13 2010 -0800 @@ -3167,7 +3167,7 @@ Pointer_type* Type::make_pointer_type(Type* to_type) { - typedef std::tr1::unordered_map Hashtable; + typedef Unordered_map(Type*, Pointer_type*) Hashtable; static Hashtable pointer_types; Hashtable::const_iterator p = pointer_types.find(to_type); if (p != pointer_types.end()) diff -r ca804e7183fe go/types.h --- a/go/types.h Tue Nov 16 12:48:08 2010 -0800 +++ b/go/types.h Tue Nov 16 14:36:13 2010 -0800 @@ -308,7 +308,7 @@ class Methods { private: - typedef std::tr1::unordered_map Method_map; + typedef Unordered_map(std::string, Method*) Method_map; public: typedef Method_map::const_iterator const_iterator; @@ -1078,8 +1078,8 @@ // A mapping from Type to tree, used to ensure that the GIMPLE // representation of identical types is identical. - typedef std::tr1::unordered_map Type_trees; + typedef Unordered_map_hash(const Type*, tree, Type_hash_identical, + Type_identical) Type_trees; static Type_trees type_trees; @@ -2577,9 +2577,8 @@ private: // A mapping from interfaces to the associated interface method // tables for this type. This maps to a decl. - typedef std::tr1::unordered_map Interface_method_tables; + typedef Unordered_map_hash(const Interface_type*, tree, Type_hash_identical, + Type_identical) Interface_method_tables; // A pointer back to the Named_object for this type. Named_object* named_object_;