This adds infrastructure to create generic-match.c (empty for now). Richard.
2014-06-24 Richard Biener <rguent...@suse.de> * Makefile.in (OBJS): Add generic-match.o. (.PRECIOUS): Likewise. (MOSTLYCLEANFILES): Add generic-match.c. (generic-match.c): New rule. (s-match): Amend. * generic-match-head.c: New file. * genmatch.c (write_gimple): Rename to ... (write_header): ... this and support generic-match.c creation. (main): Recognize -gimple and -generic switches and adjust what we output. Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 211887) +++ gcc/Makefile.in (working copy) @@ -1237,6 +1237,7 @@ OBJS = \ gimple-fold.o \ gimple-low.o \ gimple-match.o \ + generic-match.o \ gimple-pretty-print.o \ gimple-ssa-isolate-paths.o \ gimple-ssa-strength-reduction.o \ @@ -1509,7 +1510,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-con insn-output.c insn-recog.c insn-emit.c insn-extract.c insn-peep.c \ insn-attr.h insn-attr-common.h insn-attrtab.c insn-dfatab.c \ insn-latencytab.c insn-opinit.c insn-opinit.h insn-preds.c insn-constants.h \ - tm-preds.h tm-constrs.h checksum-options gimple-match.c \ + 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 \ xgcc$(exeext) cpp$(exeext) \ @@ -2023,7 +2024,7 @@ $(common_out_object_file): $(common_out_ .PRECIOUS: insn-config.h insn-flags.h insn-codes.h insn-constants.h \ insn-emit.c insn-recog.c insn-extract.c insn-output.c insn-peep.c \ insn-attr.h insn-attr-common.h insn-attrtab.c insn-dfatab.c \ - insn-latencytab.c insn-preds.c gimple-match.c + insn-latencytab.c insn-preds.c gimple-match.c generic-match.c # Dependencies for the md file. The first time through, we just assume # the md file itself and the generated dependency file (in order to get @@ -2233,12 +2234,17 @@ s-tm-texi: build/genhooks$(build_exeext) fi 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 - $(RUN_GEN) build/genmatch$(build_exeext) $(srcdir)/match.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 \ + > tmp-generic-match.c $(SHELL) $(srcdir)/../move-if-change tmp-gimple-match.c \ gimple-match.c + $(SHELL) $(srcdir)/../move-if-change tmp-generic-match.c \ + generic-match.c $(STAMP) s-match GTFILES = $(CPP_ID_DATA_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ Index: gcc/generic-match-head.c =================================================================== --- gcc/generic-match-head.c (revision 0) +++ gcc/generic-match-head.c (working copy) @@ -0,0 +1,74 @@ +/* Preamble and helpers for the autogenerated generic-match.c file. + Copyright (C) 2014 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tree.h" +#include "stringpool.h" +#include "stor-layout.h" +#include "flags.h" +#include "function.h" +#include "basic-block.h" +#include "tree-ssa-alias.h" +#include "internal-fn.h" +#include "gimple-expr.h" +#include "is-a.h" +#include "gimple.h" +#include "gimple-ssa.h" +#include "tree-ssanames.h" +#include "gimple-fold.h" +#include "gimple-iterator.h" +#include "expr.h" +#include "tree-dfa.h" +#include "builtins.h" + +#define INTEGER_CST_P(node) (TREE_CODE(node) == INTEGER_CST) +#define integral_op_p(node) INTEGRAL_TYPE_P(TREE_TYPE(node)) +#define REAL_CST_P(node) (TREE_CODE(node) == REAL_CST) + + +/* Helper to transparently allow tree codes and builtin function codes + exist in one storage entity. */ +class code_helper +{ +public: + code_helper () {} + code_helper (tree_code code) : rep ((int) code) {} + code_helper (built_in_function fn) : rep (-(int) fn) {} + operator tree_code () const { return (tree_code) rep; } + operator built_in_function () const { return (built_in_function) -rep; } + bool is_tree_code () const { return rep > 0; } + bool is_fn_code () const { return rep < 0; } +private: + int rep; +}; + + +/* Return whether T is a constant that we'll dispatch to fold to + evaluate fully constant expressions. */ + +static inline bool +constant_for_folding (tree t) +{ + return (CONSTANT_CLASS_P (t) + /* The following is only interesting to string builtins. */ + || (TREE_CODE (t) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)); +} Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 211932) +++ gcc/genmatch.c (working copy) @@ -1232,13 +1232,13 @@ outline_c_exprs (FILE *f, struct operand } static void -write_gimple (FILE *f, vec<simplify *>& simplifiers) +write_header (FILE *f, vec<simplify *>& simplifiers, const char *head) { fprintf (f, "/* Generated automatically by the program `genmatch' from\n"); fprintf (f, " a IL pattern matching and simplification description. */\n"); /* Include the header instead of writing it awkwardly quoted here. */ - fprintf (f, "\n#include \"gimple-match-head.c\"\n"); + fprintf (f, "\n#include \"%s\"\n", head); /* Outline complex C expressions to helper functions. */ for (unsigned i = 0; i < simplifiers.length (); ++i) @@ -1542,7 +1542,7 @@ main(int argc, char **argv) progname = "genmatch"; - if (argc != 2) + if (argc != 3) return 1; line_table = XCNEW (struct line_maps); @@ -1554,7 +1554,7 @@ main(int argc, char **argv) cpp_callbacks *cb = cpp_get_callbacks (r); cb->error = error_cb; - if (!cpp_read_main_file (r, argv[1])) + if (!cpp_read_main_file (r, argv[2])) return 1; /* Pre-seed operators. */ @@ -1604,8 +1604,18 @@ main(int argc, char **argv) dt.print (stderr); - write_gimple (stdout, simplifiers); - dt.gen_gimple (stdout); + if (strcmp (argv[1], "-gimple") == 0) + { + write_header (stdout, simplifiers, "gimple-match-head.c"); + dt.gen_gimple (stdout); + } + else if (strcmp (argv[1], "-generic") == 0) + { + write_header (stdout, simplifiers, "generic-match-head.c"); + //dt.gen_generic (stdout); + } + else + return 1; cpp_finish (r, NULL); cpp_destroy (r);