From patchwork Tue Nov 17 09:23:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 545444 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 C61EE14141B for ; Tue, 17 Nov 2015 20:24:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=X7ZscdC0; 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:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=TnxdCUH8anAflbbXtt/ZsYUdoCR7h2nAnibQ82TgVU2au9/3C4FH6 TaQ5wx+n3FsktiE3ozN2Sh+Mz4J1XMvsXr/JkJV0S5takKFHKaPFnWiIC3RPDULb U+8hExJ+3yZu6qMWQvVubu1Sm/dcwFcdV8SVGqQu9InVN1ZTy0Vx44= 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:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=+71weTOczq17LfCxSz1A4MxIDyo=; b=X7ZscdC05Ucf1CRwTfMx/oXX2JpU 6fSSqhV5NbE0AUfHrp6WKDOPU+Q4+ZhM2TBJ9LhKfp3RYWInVAWZXK/U444pNSET HrPHbDLYeL5YA/1St5nA+HOrTBUpHeqgEo0sK/8YTR/i0B6zquzwZpj9ED7HqWXz ES5NMdFJJF1WrRU= Received: (qmail 118040 invoked by alias); 17 Nov 2015 09:23:53 -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 118022 invoked by uid 89); 17 Nov 2015 09:23:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, 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) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Nov 2015 09:23:50 +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-18-czMduhO9R0CVrU-sCdJQOA-1; Tue, 17 Nov 2015 09:23:45 +0000 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 17 Nov 2015 09:23:45 +0000 From: Richard Sandiford To: Richard Biener Mail-Followup-To: Richard Biener , GCC Patches , richard.sandiford@arm.com Cc: GCC Patches Subject: Re: Replace match.pd DEFINE_MATH_FNs with auto-generated lists References: <87h9kyose0.fsf@e105548-lin.cambridge.arm.com> <87bnb1mx3u.fsf@e105548-lin.cambridge.arm.com> <37FBF7EA-03D3-4C49-A69C-534CA996266F@gmail.com> Date: Tue, 17 Nov 2015 09:23:45 +0000 In-Reply-To: <37FBF7EA-03D3-4C49-A69C-534CA996266F@gmail.com> (Richard Biener's message of "Tue, 10 Nov 2015 21:24:44 +0100") Message-ID: <871tbpkmhq.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: czMduhO9R0CVrU-sCdJQOA-1 Richard Biener writes: > On November 10, 2015 9:13:25 PM GMT+01:00, Richard Sandiford > wrote: >>Richard Biener writes: >>> On Sat, Nov 7, 2015 at 2:23 PM, Richard Sandiford >>> wrote: >>>> 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); >>> >>> Does that work on non-UNIX hosts? >> >>Bah, hadn't thought about that. >> >>> I wonder if there is sth >>> better we can use by passing some -DXXX=... to the genmatch >>> build command from the Makefile? >> >>toplev.c has: >> >> src_pwd = getpwd (); >> if (!src_pwd) >> src_pwd = "."; >> >>where getpwd is a libiberty function. Maybe we can use that? > > Looks like so. OK, here's the updated patch. Tested as before. 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 the current directory 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 ba8108d..0fd8d99 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1570,7 +1570,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) \ @@ -2256,6 +2256,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 @@ -2322,7 +2330,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 \ @@ -2443,7 +2451,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 4df5689..3a20a48 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -4638,6 +4638,13 @@ 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 = getpwd (); + if (!dir->name) + 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 15bf2c9..e86cc8b 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)