diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2015-12-02 09:06:28 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2015-12-02 09:06:28 +0000 |
commit | 886456e210ef12d77f625ace8f312ab23d208aff (patch) | |
tree | 5b44d07d2d4f3d21be039ca6d049269722224bbf /gcc/genemit.c | |
parent | e970b4b0002d0bc24cf4461fb0eadd7ee2241cab (diff) | |
download | gcc-886456e210ef12d77f625ace8f312ab23d208aff.zip gcc-886456e210ef12d77f625ace8f312ab23d208aff.tar.gz gcc-886456e210ef12d77f625ace8f312ab23d208aff.tar.bz2 |
Check for invalid FAILs
This patch makes it a compile-time error for an internal-fn optab
to FAIL. There are certainly other optabs and patterns besides these
that aren't allowed to fail, but this at least deals with the immediate
point of controversy.
Tested normally on x86_64-linux-gnu. Also tested by building one
configuration per cpu directory. arc-elf and pdp11 didn't build
for unrelated reasons, but I checked that insn-emit.o built for
both without error.
gcc/
* Makefile.in (GENSUPPORT_H): New macro.
(build/gensupport.o, build/read-rtl.o, build/genattr.o)
(build/genattr-common.o, build/genattrtab.o, build/genautomata.o)
(build/gencodes.o, build/genconditions.o, build/genconfig.o)
(build/genconstants.o, build/genextract.o, build/genflags.o)
(build/gentarget-def.o): Use it.
(build/genemit.o): Likewise. Depend on internal-fn.def.
* genopinit.c: Move block comment to optabs.def.
(optab_tag, optab_def): Move to gensupport.h
(pattern): Likewise, renaming to optab_pattern.
(match_pattern): Move to gensupport.c
(gen_insn): Use find_optab.
(patterns, pattern_cmp): Replace pattern with optab_pattern.
(main): Likewise. Use num_optabs.
* optabs.def: Add comment that was previously in genopinit.c.
* gensupport.h (optab_tag): Moved from genopinit.c
(optab_def): Likewise, expanding commentary.
(optab_pattern): Likewise, after renaming from pattern.
(optabs, num_optabs, find_optab): Declare.
* gensupport.c (optabs): Moved from genopinit.c.
(num_optabs): New variable.
(match_pattern): Moved from genopinit.c.
(find_optab): New function, extracted from genopinit.c:gen_insn.
* genemit.c (nofail_optabs): New variable.
(emit_c_code): New function.
(gen_expand): Check whether the instruction is an optab that isn't
allowed to fail. Call emit_c_code.
(gen_split): Call emit_c_code here too.
(main): Initialize nofail_optabs. Don't emit FAIL and DONE here.
From-SVN: r231160
Diffstat (limited to 'gcc/genemit.c')
-rw-r--r-- | gcc/genemit.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/gcc/genemit.c b/gcc/genemit.c index e92f757..cd85a80 100644 --- a/gcc/genemit.c +++ b/gcc/genemit.c @@ -51,6 +51,8 @@ struct clobber_ent static void output_peephole2_scratches (rtx); +/* True for <X>_optab if that optab isn't allowed to fail. */ +static bool nofail_optabs[NUM_OPTABS]; static void print_code (RTX_CODE code) @@ -285,6 +287,28 @@ gen_emit_seq (rtvec vec, char *used) } } +/* Emit the given C code to the output file. The code is allowed to + fail if CAN_FAIL_P. NAME describes what we're generating, + for use in error messages. */ + +static void +emit_c_code (const char *code, bool can_fail_p, const char *name) +{ + if (can_fail_p) + printf ("#define FAIL return (end_sequence (), _val)\n"); + else + printf ("#define FAIL _Pragma (\"GCC error \\\"%s cannot FAIL\\\"\")" + " (void)0\n", name); + printf ("#define DONE return (_val = get_insns ()," + "end_sequence (), _val)\n"); + + print_md_ptr_loc (code); + printf ("%s\n", code); + + printf ("#undef DONE\n"); + printf ("#undef FAIL\n"); +} + /* Generate the `gen_...' function for a DEFINE_INSN. */ static void @@ -478,8 +502,15 @@ gen_expand (md_rtx_info *info) /* Output the special code to be executed before the sequence is generated. */ - print_md_ptr_loc (XSTR (expand, 3)); - printf ("%s\n", XSTR (expand, 3)); + optab_pattern p; + bool can_fail_p = true; + if (find_optab (&p, XSTR (expand, 0))) + { + gcc_assert (p.op < NUM_OPTABS); + if (nofail_optabs[p.op]) + can_fail_p = false; + } + emit_c_code (XSTR (expand, 3), can_fail_p, XSTR (expand, 0)); /* Output code to copy the arguments back out of `operands' (unless we aren't going to use them at all). */ @@ -569,10 +600,7 @@ gen_split (md_rtx_info *info) before the actual construction. */ if (XSTR (split, 3)) - { - print_md_ptr_loc (XSTR (split, 3)); - printf ("%s\n", XSTR (split, 3)); - } + emit_c_code (XSTR (split, 3), true, name); /* Output code to copy the arguments back out of `operands' */ for (i = 0; i < stats.num_operand_vars; i++) @@ -724,6 +752,10 @@ main (int argc, char **argv) if (!init_rtx_reader_args (argc, argv)) return (FATAL_EXIT_CODE); +#define DEF_INTERNAL_OPTAB_FN(NAME, FLAGS, OPTAB, TYPE) \ + nofail_optabs[OPTAB##_optab] = true; +#include "internal-fn.def" + /* Assign sequential codes to all entries in the machine description in parallel with the tables in insn-output.c. */ @@ -764,8 +796,6 @@ from the machine description file `md'. */\n\n"); printf ("#include \"ggc.h\"\n"); printf ("#include \"dumpfile.h\"\n"); printf ("#include \"target.h\"\n\n"); - printf ("#define FAIL return (end_sequence (), _val)\n"); - printf ("#define DONE return (_val = get_insns (), end_sequence (), _val)\n\n"); /* Read the machine description. */ |