From patchwork Sat Nov 7 13:23:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 541297 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 C80FB1409A0 for ; Sun, 8 Nov 2015 00:23:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=ct/1ZD/6; 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Ud/JcsZoGBSfoC/r Eq4hq/WV8Hh1mykNFNT5ImiqqoZHKRIl420WtKlW/RJj0PCdax98SsmCIdI6hC5e G1laClCtRyrrgYdliIjthHdP6WoPljQXS7X7YBjetG93ecOGt9epkKVNOmR3n9Y5 y7xVNSPfAq3D3lzXbXemAY7T7PM= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=MNH67LvE1T0+nPog/jChvE JF28k=; b=ct/1ZD/6xCl57L0M+JRENcnHpgbg1i4BUfsFthCWEI+syzK8dUVxwI in44ZsnwUl+CYDlFXefO00doVA2xdMEzqmAv/dyTEhUYMF72nnBL54ML8x2Rn+PU MreLU2xD0CPfKE+FWxmFvW49equzRgN+6rFp+uXBKY5MowlL+OK90= Received: (qmail 114756 invoked by alias); 7 Nov 2015 13:23:28 -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 114741 invoked by uid 89); 7 Nov 2015 13:23:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_05, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 07 Nov 2015 13:23:25 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-5-kZ1BgsfgQF2FT3ERy3b7Pw-1; Sat, 07 Nov 2015 13:23:20 +0000 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 7 Nov 2015 13:23:19 +0000 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Replace match.pd DEFINE_MATH_FNs with auto-generated lists Date: Sat, 07 Nov 2015 13:23:19 +0000 Message-ID: <87h9kyose0.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: kZ1BgsfgQF2FT3ERy3b7Pw-1 This patch autogenerates the operator lists for maths functions like SQRT, adding an additional entry for internal functions. E.g.: (define_operator_list SQRT BUILT_IN_SQRTF BUILT_IN_SQRT BUILT_IN_SQRTL IFN_SQRT) and: (define_operator_list CABS BUILT_IN_CABSF BUILT_IN_CABS BUILT_IN_CABSL null) (since there's no internal function for CABS). Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. OK to install? Thanks, Richard gcc/ * Makefile.in (MOSTLYCLEANFILES): Add cfn-operators.pd. (generated_files): Likewise. (s-cfn-operators, cfn-operators.pd): New rules. (s-match): Depend on cfn-operators.pd. * gencfn-macros.c: Expand comment to describe -o behavior. (print_define_operator_list): New function. (main): Accept -o. Call print_define_operator_list. * genmatch.c (main): Add "." to the include path. * match.pd (DEFINE_MATH_FN): Delete. Include cfn-operators.pd instead. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 298bb38..a21aaf5 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1566,7 +1566,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \ tm-preds.h tm-constrs.h checksum-options gimple-match.c generic-match.c \ tree-check.h min-insn-modes.c insn-modes.c insn-modes.h \ genrtl.h gt-*.h gtype-*.h gtype-desc.c gtyp-input.list \ - case-cfn-macros.h \ + case-cfn-macros.h cfn-operators.pd \ xgcc$(exeext) cpp$(exeext) $(FULL_DRIVER_NAME) \ $(EXTRA_PROGRAMS) gcc-cross$(exeext) \ $(SPECS) collect2$(exeext) gcc-ar$(exeext) gcc-nm$(exeext) \ @@ -2252,6 +2252,14 @@ s-case-cfn-macros: build/gencfn-macros$(build_exeext) $(STAMP) s-case-cfn-macros case-cfn-macros.h: s-case-cfn-macros; @true +s-cfn-operators: build/gencfn-macros$(build_exeext) + $(RUN_GEN) build/gencfn-macros$(build_exeext) -o \ + > tmp-cfn-operators.pd + $(SHELL) $(srcdir)/../move-if-change tmp-cfn-operators.pd \ + cfn-operators.pd + $(STAMP) s-cfn-operators +cfn-operators.pd: s-cfn-operators; @true + target-hooks-def.h: s-target-hooks-def-h; @true # make sure that when we build info files, the used tm.texi is up to date. $(srcdir)/doc/tm.texi: s-tm-texi; @true @@ -2318,7 +2326,7 @@ s-tm-texi: build/genhooks$(build_exeext) $(srcdir)/doc/tm.texi.in gimple-match.c: s-match gimple-match-head.c ; @true generic-match.c: s-match generic-match-head.c ; @true -s-match: build/genmatch$(build_exeext) $(srcdir)/match.pd +s-match: build/genmatch$(build_exeext) $(srcdir)/match.pd cfn-operators.pd $(RUN_GEN) build/genmatch$(build_exeext) --gimple $(srcdir)/match.pd \ > tmp-gimple-match.c $(RUN_GEN) build/genmatch$(build_exeext) --generic $(srcdir)/match.pd \ @@ -2439,7 +2447,8 @@ generated_files = config.h tm.h $(TM_P_H) $(TM_H) multilib.h \ $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h gcov-iov.h \ options.h target-hooks-def.h insn-opinit.h \ common/common-target-hooks-def.h pass-instances.def \ - c-family/c-target-hooks-def.h params.list case-cfn-macros.h + c-family/c-target-hooks-def.h params.list case-cfn-macros.h \ + cfn-operators.pd # # How to compile object files to run on the build machine. diff --git a/gcc/gencfn-macros.c b/gcc/gencfn-macros.c index 5ee3af0..401c429 100644 --- a/gcc/gencfn-macros.c +++ b/gcc/gencfn-macros.c @@ -40,7 +40,27 @@ along with GCC; see the file COPYING3. If not see case CFN_BUILT_IN_SQRTL: case CFN_SQRT: - The macros for groups with no internal function drop the last line. */ + The macros for groups with no internal function drop the last line. + + When run with -o, the generator prints a similar list of + define_operator_list directives, for use by match.pd. Each operator + list starts with the built-in functions, in order of ascending type width. + This is followed by an entry for the internal function, or "null" if there + is no internal function for the group. For example: + + (define_operator_list SQRT + BUILT_IN_SQRTF + BUILT_IN_SQRT + BUILT_IN_SQRTL + IFN_SQRT) + + and: + + (define_operator_list CABS + BUILT_IN_CABSF + BUILT_IN_CABS + BUILT_IN_CABSL + null) */ #include "bconfig.h" #include "system.h" @@ -89,6 +109,23 @@ print_case_cfn (const char *name, bool internal_p, printf ("\n"); } +/* Print an operator list for all combined functions related to NAME, + with the null-terminated list of suffixes in SUFFIXES. INTERNAL_P + says whether CFN_ also exists. */ + +static void +print_define_operator_list (const char *name, bool internal_p, + const char *const *suffixes) +{ + printf ("(define_operator_list %s\n", name); + for (unsigned int i = 0; suffixes[i]; ++i) + printf (" BUILT_IN_%s%s\n", name, suffixes[i]); + if (internal_p) + printf (" IFN_%s)\n", name); + else + printf (" null)\n"); +} + const char *const builtin_names[] = { #define DEF_BUILTIN(ENUM, N, C, T, LT, B, F, NA, AT, IM, COND) \ #ENUM, @@ -126,9 +163,10 @@ main (int argc, char **argv) progname = argv[0]; if (argc != 2 || argv[1][0] != '-' - || argv[1][1] != 'c' + || !strchr ("co", argv[1][1]) || argv[1][2]) - fatal ("usage: %s -c > file", progname); + fatal ("usage: %s [-c|-o] > file", progname); + int type = argv[1][1]; /* Collect the set of built-in and internal functions. */ string_set builtins; @@ -165,7 +203,11 @@ main (int argc, char **argv) if (is_group (&builtins, root, suffix_lists[j])) { bool internal_p = internal_fns.contains (root); - print_case_cfn (root, internal_p, suffix_lists[j]); + if (type == 'c') + print_case_cfn (root, internal_p, suffix_lists[j]); + else + print_define_operator_list (root, internal_p, + suffix_lists[j]); } } } diff --git a/gcc/genmatch.c b/gcc/genmatch.c index cff32b0..7139476 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -4638,6 +4638,11 @@ main (int argc, char **argv) cpp_callbacks *cb = cpp_get_callbacks (r); cb->error = error_cb; + /* Add the build directory to the #include "" search path. */ + cpp_dir *dir = XCNEW (cpp_dir); + dir->name = ASTRDUP ("."); + cpp_set_include_chains (r, dir, NULL, false); + if (!cpp_read_main_file (r, input)) return 1; cpp_define (r, gimple ? "GIMPLE=1": "GENERIC=1"); diff --git a/gcc/match.pd b/gcc/match.pd index e8ccb85..1f9de49 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -47,10 +47,7 @@ along with GCC; see the file COPYING3. If not see (define_operator_list simple_comparison lt le eq ne ge gt) (define_operator_list swapped_simple_comparison gt ge eq ne le lt) -/* Define an operand list for math function FN, with float, double and - long double variants (in that order). */ -#define DEFINE_MATH_FN(FN) \ - (define_operator_list FN BUILT_IN_##FN##F BUILT_IN_##FN BUILT_IN_##FN##L) +#include "cfn-operators.pd" /* Define operand lists for math rounding functions {,i,l,ll}FN, where the versions prefixed with "i" return an int, those prefixed with @@ -62,10 +59,6 @@ along with GCC; see the file COPYING3. If not see X for all double functions, in the same order XL for all long double functions, in the same order. */ #define DEFINE_INT_AND_FLOAT_ROUND_FN(FN) \ - DEFINE_MATH_FN (FN) \ - DEFINE_MATH_FN (I##FN) \ - DEFINE_MATH_FN (L##FN) \ - DEFINE_MATH_FN (LL##FN) \ (define_operator_list X##FN##F BUILT_IN_I##FN##F \ BUILT_IN_L##FN##F \ BUILT_IN_LL##FN##F) \ @@ -76,39 +69,6 @@ along with GCC; see the file COPYING3. If not see BUILT_IN_L##FN##L \ BUILT_IN_LL##FN##L) -DEFINE_MATH_FN (LOG) -DEFINE_MATH_FN (EXP) -DEFINE_MATH_FN (LOG2) -DEFINE_MATH_FN (EXP2) -DEFINE_MATH_FN (LOG10) -DEFINE_MATH_FN (EXP10) -DEFINE_MATH_FN (POW) -DEFINE_MATH_FN (POW10) -DEFINE_MATH_FN (POWI) -DEFINE_MATH_FN (SQRT) -DEFINE_MATH_FN (CBRT) -DEFINE_MATH_FN (SIN) -DEFINE_MATH_FN (COS) -DEFINE_MATH_FN (TAN) -DEFINE_MATH_FN (ATAN) -DEFINE_MATH_FN (COSH) -DEFINE_MATH_FN (CEXP) -DEFINE_MATH_FN (CEXPI) -DEFINE_MATH_FN (CPROJ) -DEFINE_MATH_FN (CCOS) -DEFINE_MATH_FN (CCOSH) -DEFINE_MATH_FN (HYPOT) -DEFINE_MATH_FN (COPYSIGN) -DEFINE_MATH_FN (CABS) -DEFINE_MATH_FN (TRUNC) -DEFINE_MATH_FN (NEARBYINT) -DEFINE_MATH_FN (SIGNBIT) -DEFINE_MATH_FN (FMIN) -DEFINE_MATH_FN (FMAX) -DEFINE_MATH_FN (LDEXP) -DEFINE_MATH_FN (SCALBN) -DEFINE_MATH_FN (SCALBLN) - DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR) DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL) DEFINE_INT_AND_FLOAT_ROUND_FN (ROUND)