From patchwork Fri May 22 12:00:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 475585 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 39C951402BA for ; Fri, 22 May 2015 22:00:47 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=DPz6ymBp; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=SLHUNyhd0jOmexGCf FAJO7rHRYDajFSEj+mHFH5HuTuAQL0Yd6ItD2iDHzmE2+WogUTTd+08p6MTcJeKe 6s7AV1j4SUbkUz7S3SB7UmW4uIvrC+SvJMy8icAS1TgA8uyCqNWhaWtBXUCtbAni Askxs7FAsSM9197M/2almi/E7w= 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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=HUbUo1Oo+g7OOMqNPDDWLFC lExE=; b=DPz6ymBpDYgksyS4Q18jazZl7X9R8ApHaLzl5hM59LVAM+uNZx4kMwX MilAB92jXT5zkUDiTq+uYTRjhb8v0V3CYGw+J8PjoCsW41U177lGFU1r9q81ceOy sFvWInovQ1QE6vSVShx3HtdL41APiz92WtTswxFiU3jBpv1B4eP4= Received: (qmail 96848 invoked by alias); 22 May 2015 12:00:39 -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 96834 invoked by uid 89); 22 May 2015 12:00:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.4 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, SPAM_BODY, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 22 May 2015 12:00:37 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id B6117543019; Fri, 22 May 2015 14:00:32 +0200 (CEST) Date: Fri, 22 May 2015 14:00:32 +0200 From: Jan Hubicka To: Richard Biener Cc: Jan Hubicka , gcc-patches@gcc.gnu.org Subject: Re: Calculate TYPE_CANONICAL only for types that can be accessed in memory Message-ID: <20150522120032.GB75713@kam.mff.cuni.cz> References: <20150521181437.GB8821@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) > Now we have it spelled out 4 times ... makes sense to create a new > macro for it? (though I cannot think of a good name... > UNACCESSIBLE_TYPE_P ()?) Yep, actually I already made that version of patch yesterday but then got hooked by beers. This is better version (also with more sensible comments). I will commit it at afternoon if you have no further comments. * lto.c (hash_canonical_type): Be sure we hash only types that need alias set. (gimple_register_canonical_type_1): Do not produce canonical types for types that do not need alias sets. * tree.c (gimple_canonical_types_compatible_p): Sanity check that we do not try to compute canonical type for type that does not need alias set. (verify_type): Drop FIXME for METHOD_TYPE, update FIXME for FUNCITON_TYPE. * tree.h (type_with_alias_set_p): New. Index: lto/lto.c =================================================================== --- lto/lto.c (revision 223508) +++ lto/lto.c (working copy) @@ -309,6 +309,12 @@ hash_canonical_type (tree type) { inchash::hash hstate; + /* We compute alias sets only for types that needs them. + Be sure we do not recurse to something else as we can not hash incomplete + types in a way they would have same hash value as compatible complete + types. */ + gcc_checking_assert (type_with_alias_set_p (type)); + /* Combine a few common features of types so that types are grouped into smaller sets; when searching for existing matching types to merge, only existing types having the same features as the new type will be @@ -493,7 +495,7 @@ gimple_register_canonical_type_1 (tree t static void gimple_register_canonical_type (tree t) { - if (TYPE_CANONICAL (t)) + if (TYPE_CANONICAL (t) || !type_with_alias_set_p (t)) return; gimple_register_canonical_type_1 (t, hash_canonical_type (t)); Index: tree.c =================================================================== --- tree.c (revision 223508) +++ tree.c (working copy) @@ -12720,6 +12720,23 @@ gimple_canonical_types_compatible_p (con if (t1 == NULL_TREE || t2 == NULL_TREE) return false; + /* We consider complete types always compatible with incomplete type. + This does not make sense for canonical type calculation and thus we + need to ensure that we are never called on it. + + FIXME: For more correctness the function probably should have three modes + 1) mode assuming that types are complete mathcing their structure + 2) mode allowing incomplete types but producing equivalence classes + and thus ignoring all info from complete types + 3) mode allowing incomplete types to match complete but checking + compatibility between complete types. + + 1 and 2 can be used for canonical type calculation. 3 is the real + definition of type compatibility that can be used i.e. for warnings during + declaration merging. */ + + gcc_assert (!trust_type_canonical + || (type_with_alias_set_p (t1) && type_with_alias_set_p (t2))); /* If the types have been previously registered and found equal they still are. */ if (TYPE_CANONICAL (t1) && TYPE_CANONICAL (t2) @@ -12939,10 +12953,9 @@ verify_type (const_tree t) /* Method and function types can not be used to address memory and thus TYPE_CANONICAL really matters only for determining useless conversions. - FIXME: C++ FE does not agree with gimple_canonical_types_compatible_p - here. gimple_canonical_types_compatible_p calls comp_type_attributes - while for C++ FE the attributes does not make difference. */ - else if (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE) + FIXME: C++ FE produce declarations of builtin functions that are not + compatible with main variants. */ + else if (TREE_CODE (t) == FUNCTION_TYPE) ; else if (t != ct /* FIXME: gimple_canonical_types_compatible_p can not compare types Index: tree.h =================================================================== --- tree.h (revision 223508) +++ tree.h (working copy) @@ -5090,6 +5090,26 @@ int_bit_position (const_tree field) + wi::to_offset (DECL_FIELD_BIT_OFFSET (field))).to_shwi (); } +/* Return true if it makes sense to consider alias set for a type T. */ + +inline bool +type_with_alias_set_p (const_tree t) +{ + /* Function and method types are never accessed as memory locations. */ + if (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE) + return false; + + if (COMPLETE_TYPE_P (t)) + return true; + + /* Incomplete types can not be accessed in general except for arrays + where we can fetch its element despite we have no array bounds. */ + if (TREE_CODE (t) == ARRAY_TYPE && COMPLETE_TYPE_P (TREE_TYPE (t))) + return true; + + return false; +} + extern void gt_ggc_mx (tree &); extern void gt_pch_nx (tree &); extern void gt_pch_nx (tree &, gt_pointer_operator, void *);