From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 54434 invoked by alias); 2 Nov 2015 15:26:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 53365 invoked by uid 89); 2 Nov 2015 15:26:11 -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,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 02 Nov 2015 15:26:10 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id E20E08F271 for ; Mon, 2 Nov 2015 15:26:08 +0000 (UTC) Received: from redhat.com (ovpn-204-28.brq.redhat.com [10.40.204.28]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tA2FQ49n009506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 2 Nov 2015 10:26:07 -0500 Date: Mon, 02 Nov 2015 15:26:00 -0000 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [c++-delayed-folding] Introduce convert_to_complex_nofold Message-ID: <20151102152604.GJ3185@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-SW-Source: 2015-11/txt/msg00083.txt.bz2 The following introduces convert_to_complex_nofold, similarly to what I've done with convert_to_pointer. Nothing too surprising in the patch, I suppose. Now, what remains to do is to also introduce convert_to_real. Then we should be done with convert.c as convert_to_vector doesn't fold and convert_to_fixed isn't used in the C++ FE at all. More tomorrow. Bootstrapped/regtested on x86_64-linux, ok for branch? diff --git gcc/convert.c gcc/convert.c index ab3eb20..ec6ff37 100644 --- gcc/convert.c +++ gcc/convert.c @@ -40,6 +40,9 @@ along with GCC; see the file COPYING3. If not see #define maybe_fold_build1_loc(FOLD_P, LOC, CODE, TYPE, EXPR) \ ((FOLD_P) ? fold_build1_loc (LOC, CODE, TYPE, EXPR) \ : build1_loc (LOC, CODE, TYPE, EXPR)) +#define maybe_fold_build2_loc(FOLD_P, LOC, CODE, TYPE, EXPR1, EXPR2) \ + ((FOLD_P) ? fold_build2_loc (LOC, CODE, TYPE, EXPR1, EXPR2) \ + : build2_loc (LOC, CODE, TYPE, EXPR1, EXPR2)) /* Convert EXPR to some pointer or reference type TYPE. EXPR must be pointer, reference, integer, enumeral, or literal zero; @@ -968,11 +971,13 @@ convert_to_integer_nofold (tree type, tree expr) return convert_to_integer_1 (type, expr, CONSTANT_CLASS_P (expr)); } -/* Convert EXPR to the complex type TYPE in the usual ways. */ +/* Convert EXPR to the complex type TYPE in the usual ways. If FOLD_P is + true, try to fold the expression. */ -tree -convert_to_complex (tree type, tree expr) +static tree +convert_to_complex_1 (tree type, tree expr, bool fold_p) { + location_t loc = EXPR_LOCATION (expr); tree subtype = TREE_TYPE (type); switch (TREE_CODE (TREE_TYPE (expr))) @@ -993,43 +998,63 @@ convert_to_complex (tree type, tree expr) return expr; else if (TREE_CODE (expr) == COMPOUND_EXPR) { - tree t = convert_to_complex (type, TREE_OPERAND (expr, 1)); + tree t = convert_to_complex_1 (type, TREE_OPERAND (expr, 1), + fold_p); if (t == TREE_OPERAND (expr, 1)) return expr; return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (t), TREE_OPERAND (expr, 0), t); - } + } else if (TREE_CODE (expr) == COMPLEX_EXPR) - return fold_build2 (COMPLEX_EXPR, type, - convert (subtype, TREE_OPERAND (expr, 0)), - convert (subtype, TREE_OPERAND (expr, 1))); + return maybe_fold_build2_loc (fold_p, loc, COMPLEX_EXPR, type, + convert (subtype, + TREE_OPERAND (expr, 0)), + convert (subtype, + TREE_OPERAND (expr, 1))); else { expr = save_expr (expr); - return - fold_build2 (COMPLEX_EXPR, type, - convert (subtype, - fold_build1 (REALPART_EXPR, - TREE_TYPE (TREE_TYPE (expr)), - expr)), - convert (subtype, - fold_build1 (IMAGPART_EXPR, - TREE_TYPE (TREE_TYPE (expr)), - expr))); + tree realp = maybe_fold_build1_loc (fold_p, loc, REALPART_EXPR, + TREE_TYPE (TREE_TYPE (expr)), + expr); + tree imagp = maybe_fold_build1_loc (fold_p, loc, IMAGPART_EXPR, + TREE_TYPE (TREE_TYPE (expr)), + expr); + return maybe_fold_build2_loc (fold_p, loc, COMPLEX_EXPR, type, + convert (subtype, realp), + convert (subtype, imagp)); } } case POINTER_TYPE: case REFERENCE_TYPE: error ("pointer value used where a complex was expected"); - return convert_to_complex (type, integer_zero_node); + return convert_to_complex_1 (type, integer_zero_node, fold_p); default: error ("aggregate value used where a complex was expected"); - return convert_to_complex (type, integer_zero_node); + return convert_to_complex_1 (type, integer_zero_node, fold_p); } } +/* A wrapper around convert_to_complex_1 that always folds the + expression. */ + +tree +convert_to_complex (tree type, tree expr) +{ + return convert_to_complex_1 (type, expr, true); +} + +/* A wrapper around convert_to_complex_1 that only folds the + expression if it is CONSTANT_CLASS_P. */ + +tree +convert_to_complex_nofold (tree type, tree expr) +{ + return convert_to_complex_1 (type, expr, CONSTANT_CLASS_P (expr)); +} + /* Convert EXPR to the vector type TYPE in the usual ways. */ tree diff --git gcc/convert.h gcc/convert.h index 24fa6bf..6cb439e 100644 --- gcc/convert.h +++ gcc/convert.h @@ -27,6 +27,7 @@ extern tree convert_to_pointer_nofold (tree, tree); extern tree convert_to_real (tree, tree); extern tree convert_to_fixed (tree, tree); extern tree convert_to_complex (tree, tree); +extern tree convert_to_complex_nofold (tree, tree); extern tree convert_to_vector (tree, tree); #endif /* GCC_CONVERT_H */ diff --git gcc/cp/cvt.c gcc/cp/cvt.c index 04f6b81..1368f15 100644 --- gcc/cp/cvt.c +++ gcc/cp/cvt.c @@ -710,7 +710,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags, /* For complex data types, we need to perform componentwise conversion. */ else if (TREE_CODE (type) == COMPLEX_TYPE) - return convert_to_complex (type, e); + return convert_to_complex_nofold (type, e); else if (VECTOR_TYPE_P (type)) return convert_to_vector (type, e); else if (TREE_CODE (e) == TARGET_EXPR) @@ -848,7 +848,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags, if (code == REAL_TYPE) return convert_to_real (type, e); else if (code == COMPLEX_TYPE) - return convert_to_complex (type, e); + return convert_to_complex_nofold (type, e); } /* New C++ semantics: since assignment is now based on Marek