gcc/ * alloc-pool.c, asan.c, auto-inc-dec.c, basic-block.h, bb-reorder.c, bitmap.c, bitmap.h, bt-load.c, builtins.c, calls.c, cfgcleanup.c, cfgexpand.c, cfghooks.c, cfgloop.c, cfgloopmanip.c, cfgrtl.c, cgraph.c, cgraph.h, cgraphbuild.c, cgraphclones.c, cgraphunit.c, collect2.c, combine-stack-adj.c, combine.c, compare-elim.c, context.c, context.h, cprop.c, cse.c, cselib.c, dbxout.c, dce.c, defaults.h, df-core.c, df-problems.c, df-scan.c, df.h, diagnostic.c, double-int.c, dse.c, dumpfile.c, dwarf2asm.c, dwarf2cfi.c, dwarf2out.c, emit-rtl.c, errors.c, except.c, expmed.c, expr.c, file-find.c, final.c, fixed-value.c, fold-const.c, function.c, fwprop.c, gcc-ar.c, gcc.c, gcov-io.c, gcov-io.h, gcov.c, gcse.c, genattr-common.c, genattr.c, genattrtab.c, genautomata.c, genconfig.c, genemit.c, genextract.c, genflags.c, gengenrtl.c, gengtype-state.c, gengtype.c, genmodes.c, genopinit.c, genoutput.c, genpeep.c, genpreds.c, genrecog.c, gensupport.c, ggc-common.c, ggc-page.c, gimple-fold.c, gimple-low.c, gimple-pretty-print.c, gimple-ssa-strength-reduction.c, gimple.c, gimple.h, godump.c, graphite-clast-to-gimple.c, graphite-optimize-isl.c, graphite-poly.h, graphite-sese-to-poly.c, graphite.c, haifa-sched.c, hash-table.c, hash-table.h, hwint.c, hwint.h, ifcvt.c, incpath.c, init-regs.c, input.h, intl.c, intl.h, ipa-cp.c, ipa-devirt.c, ipa-inline-analysis.c, ipa-inline.c, ipa-profile.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa-utils.c, ipa.c, ira-build.c, ira.c, jump.c, loop-doloop.c, loop-init.c, loop-invariant.c, loop-iv.c, lower-subreg.c, lto-cgraph.c, lto-streamer-in.c, lto-streamer-out.c, lto-wrapper.c, mcf.c, mode-switching.c, modulo-sched.c, omp-low.c, optabs.c, opts.c, pass_manager.h, passes.c, plugin.c, postreload-gcse.c, postreload.c, predict.c, prefix.c, pretty-print.c, print-rtl.c, print-tree.c, profile.c, read-md.c, real.c, real.h, recog.c, ree.c, reg-stack.c, regcprop.c, reginfo.c, regmove.c, regrename.c, regs.h, regstat.c, reload1.c, reorg.c, rtl.c, rtl.h, rtlanal.c, sbitmap.c, sched-rgn.c, sdbout.c, sel-sched-ir.c, sel-sched.c, sparseset.c, stack-ptr-mod.c, statistics.c, stmt.c, stor-layout.c, store-motion.c, streamer-hooks.h, system.h, target-hooks-macros.h, targhooks.c, targhooks.h, toplev.c, tracer.c, trans-mem.c, tree-browser.c, tree-call-cdce.c, tree-cfg.c, tree-cfgcleanup.c, tree-complex.c, tree-data-ref.c, tree-data-ref.h, tree-eh.c, tree-emutls.c, tree-flow.h, tree-if-conv.c, tree-into-ssa.c, tree-iterator.c, tree-loop-distribution.c, tree-mudflap.c, tree-nested.c, tree-nomudflap.c, tree-nrv.c, tree-object-size.c, tree-optimize.c, tree-pass.h, tree-pretty-print.c, tree-profile.c, tree-scalar-evolution.c, tree-sra.c, tree-ssa-ccp.c, tree-ssa-coalesce.c, tree-ssa-copy.c, tree-ssa-copyrename.c, tree-ssa-dce.c, tree-ssa-dom.c, tree-ssa-dse.c, tree-ssa-forwprop.c, tree-ssa-ifcombine.c, tree-ssa-live.c, tree-ssa-loop-ch.c, tree-ssa-loop-im.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-prefetch.c, tree-ssa-loop.c, tree-ssa-math-opts.c, tree-ssa-operands.c, tree-ssa-phiopt.c, tree-ssa-phiprop.c, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sink.c, tree-ssa-strlen.c, tree-ssa-structalias.c, tree-ssa-threadedge.c, tree-ssa-threadupdate.c, tree-ssa-uncprop.c, tree-ssa-uninit.c, tree-ssa.c, tree-ssanames.c, tree-stdarg.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-data-refs.c, tree-vect-generic.c, tree-vect-loop-manip.c, tree-vect-stmts.c, tree-vectorizer.c, tree-vectorizer.h, tree-vrp.c, tree.c, tree.h, tsan.c, tsystem.h, value-prof.c, var-tracking.c, varasm.c, vec.h, vmsdbgout.c, vtable-verify.c, web.c: Add missing whitespace before "(". From-SVN: r203004
297 lines
6.7 KiB
C
297 lines
6.7 KiB
C
/* Generate code to allocate RTL structures.
|
||
Copyright (C) 1997-2013 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 "bconfig.h"
|
||
#include "system.h"
|
||
|
||
struct rtx_definition
|
||
{
|
||
const char *const enumname, *const name, *const format;
|
||
};
|
||
|
||
/* rtl.def needs CONST_DOUBLE_FORMAT, but we don't care what
|
||
CONST_DOUBLE_FORMAT is because we're not going to be generating
|
||
anything for CONST_DOUBLE anyway. */
|
||
#define CONST_DOUBLE_FORMAT ""
|
||
|
||
#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) { #ENUM, NAME, FORMAT },
|
||
|
||
static const struct rtx_definition defs[] =
|
||
{
|
||
#include "rtl.def" /* rtl expressions are documented here */
|
||
};
|
||
#define NUM_RTX_CODE ARRAY_SIZE (defs)
|
||
|
||
static const char *formats[NUM_RTX_CODE];
|
||
|
||
/* Decode a format letter into a C type string. */
|
||
|
||
static const char *
|
||
type_from_format (int c)
|
||
{
|
||
switch (c)
|
||
{
|
||
case 'i':
|
||
return "int ";
|
||
|
||
case 'w':
|
||
return "HOST_WIDE_INT ";
|
||
|
||
case 's':
|
||
return "const char *";
|
||
|
||
case 'e': case 'u':
|
||
return "rtx ";
|
||
|
||
case 'E':
|
||
return "rtvec ";
|
||
case 't':
|
||
return "tree ";
|
||
case 'B':
|
||
return "basic_block ";
|
||
default:
|
||
gcc_unreachable ();
|
||
}
|
||
}
|
||
|
||
/* Decode a format letter into the proper accessor function. */
|
||
|
||
static const char *
|
||
accessor_from_format (int c)
|
||
{
|
||
switch (c)
|
||
{
|
||
case 'i':
|
||
return "XINT";
|
||
|
||
case 'w':
|
||
return "XWINT";
|
||
|
||
case 's':
|
||
return "XSTR";
|
||
|
||
case 'e': case 'u':
|
||
return "XEXP";
|
||
|
||
case 'E':
|
||
return "XVEC";
|
||
|
||
case 't':
|
||
return "XTREE";
|
||
|
||
case 'B':
|
||
return "XBBDEF";
|
||
|
||
default:
|
||
gcc_unreachable ();
|
||
}
|
||
}
|
||
|
||
/* Return nonzero if we should ignore FMT, an RTL format, when making
|
||
the list of formats we write routines to create. */
|
||
|
||
static int
|
||
special_format (const char *fmt)
|
||
{
|
||
return (strchr (fmt, '*') != 0
|
||
|| strchr (fmt, 'V') != 0
|
||
|| strchr (fmt, 'S') != 0
|
||
|| strchr (fmt, 'n') != 0);
|
||
}
|
||
|
||
/* Return nonzero if the RTL code given by index IDX is one that we should
|
||
generate a gen_rtx_raw_FOO macro for, not gen_rtx_FOO (because gen_rtx_FOO
|
||
is a wrapper in emit-rtl.c). */
|
||
|
||
static int
|
||
special_rtx (int idx)
|
||
{
|
||
return (strcmp (defs[idx].enumname, "CONST_INT") == 0
|
||
|| strcmp (defs[idx].enumname, "REG") == 0
|
||
|| strcmp (defs[idx].enumname, "SUBREG") == 0
|
||
|| strcmp (defs[idx].enumname, "MEM") == 0
|
||
|| strcmp (defs[idx].enumname, "PC") == 0
|
||
|| strcmp (defs[idx].enumname, "CC0") == 0
|
||
|| strcmp (defs[idx].enumname, "RETURN") == 0
|
||
|| strcmp (defs[idx].enumname, "SIMPLE_RETURN") == 0
|
||
|| strcmp (defs[idx].enumname, "CONST_VECTOR") == 0);
|
||
}
|
||
|
||
/* Return nonzero if the RTL code given by index IDX is one that we should
|
||
generate no macro for at all (because gen_rtx_FOO is never used or
|
||
cannot have the obvious interface). */
|
||
|
||
static int
|
||
excluded_rtx (int idx)
|
||
{
|
||
return ((strcmp (defs[idx].enumname, "CONST_DOUBLE") == 0)
|
||
|| (strcmp (defs[idx].enumname, "CONST_FIXED") == 0));
|
||
}
|
||
|
||
/* Place a list of all format specifiers we use into the array FORMAT. */
|
||
|
||
static void
|
||
find_formats (void)
|
||
{
|
||
unsigned int i;
|
||
|
||
for (i = 0; i < NUM_RTX_CODE; i++)
|
||
{
|
||
const char **f;
|
||
|
||
if (special_format (defs[i].format))
|
||
continue;
|
||
|
||
for (f = formats; *f; f++)
|
||
if (! strcmp (*f, defs[i].format))
|
||
break;
|
||
|
||
if (*f == 0)
|
||
*f = defs[i].format;
|
||
}
|
||
}
|
||
|
||
|
||
/* Generate macros to generate RTL of code IDX using the functions we
|
||
write. */
|
||
|
||
static void
|
||
genmacro (int idx)
|
||
{
|
||
const char *p;
|
||
int i;
|
||
|
||
/* We write a macro that defines gen_rtx_RTLCODE to be an equivalent to
|
||
gen_rtx_fmt_FORMAT where FORMAT is the RTX_FORMAT of RTLCODE. */
|
||
|
||
if (excluded_rtx (idx))
|
||
/* Don't define a macro for this code. */
|
||
return;
|
||
|
||
printf ("#define gen_rtx_%s%s(MODE",
|
||
special_rtx (idx) ? "raw_" : "", defs[idx].enumname);
|
||
|
||
for (p = defs[idx].format, i = 0; *p != 0; p++)
|
||
if (*p != '0')
|
||
printf (", ARG%d", i++);
|
||
|
||
printf (") \\\n gen_rtx_fmt_%s (%s, (MODE)",
|
||
defs[idx].format, defs[idx].enumname);
|
||
|
||
for (p = defs[idx].format, i = 0; *p != 0; p++)
|
||
if (*p != '0')
|
||
printf (", (ARG%d)", i++);
|
||
|
||
puts (")");
|
||
}
|
||
|
||
/* Generate the code for the function to generate RTL whose
|
||
format is FORMAT. */
|
||
|
||
static void
|
||
gendef (const char *format)
|
||
{
|
||
const char *p;
|
||
int i, j;
|
||
|
||
/* Start by writing the definition of the function name and the types
|
||
of the arguments. */
|
||
|
||
printf ("static inline rtx\ngen_rtx_fmt_%s_stat (RTX_CODE code, enum machine_mode mode", format);
|
||
for (p = format, i = 0; *p != 0; p++)
|
||
if (*p != '0')
|
||
printf (",\n\t%sarg%d", type_from_format (*p), i++);
|
||
|
||
puts (" MEM_STAT_DECL)");
|
||
|
||
/* Now write out the body of the function itself, which allocates
|
||
the memory and initializes it. */
|
||
puts ("{");
|
||
puts (" rtx rt;");
|
||
puts (" rt = rtx_alloc_stat (code PASS_MEM_STAT);\n");
|
||
|
||
puts (" PUT_MODE (rt, mode);");
|
||
|
||
for (p = format, i = j = 0; *p ; ++p, ++i)
|
||
if (*p != '0')
|
||
printf (" %s (rt, %d) = arg%d;\n", accessor_from_format (*p), i, j++);
|
||
else
|
||
printf (" X0EXP (rt, %d) = NULL_RTX;\n", i);
|
||
|
||
puts ("\n return rt;\n}\n");
|
||
printf ("#define gen_rtx_fmt_%s(c, m", format);
|
||
for (p = format, i = 0; *p != 0; p++)
|
||
if (*p != '0')
|
||
printf (", p%i",i++);
|
||
printf (")\\\n gen_rtx_fmt_%s_stat (c, m", format);
|
||
for (p = format, i = 0; *p != 0; p++)
|
||
if (*p != '0')
|
||
printf (", p%i",i++);
|
||
printf (" MEM_STAT_INFO)\n\n");
|
||
}
|
||
|
||
/* Generate the documentation header for files we write. */
|
||
|
||
static void
|
||
genlegend (void)
|
||
{
|
||
puts ("/* Generated automatically by gengenrtl from rtl.def. */\n");
|
||
}
|
||
|
||
/* Generate the text of the header file we make, genrtl.h. */
|
||
|
||
static void
|
||
genheader (void)
|
||
{
|
||
unsigned int i;
|
||
const char **fmt;
|
||
|
||
puts ("#ifndef GCC_GENRTL_H");
|
||
puts ("#define GCC_GENRTL_H\n");
|
||
puts ("#include \"statistics.h\"\n");
|
||
|
||
for (fmt = formats; *fmt; ++fmt)
|
||
gendef (*fmt);
|
||
|
||
putchar ('\n');
|
||
|
||
for (i = 0; i < NUM_RTX_CODE; i++)
|
||
if (! special_format (defs[i].format))
|
||
genmacro (i);
|
||
|
||
puts ("\n#endif /* GCC_GENRTL_H */");
|
||
}
|
||
|
||
/* This is the main program. */
|
||
|
||
int
|
||
main (void)
|
||
{
|
||
find_formats ();
|
||
genlegend ();
|
||
|
||
genheader ();
|
||
|
||
if (ferror (stdout) || fflush (stdout) || fclose (stdout))
|
||
return FATAL_EXIT_CODE;
|
||
|
||
return SUCCESS_EXIT_CODE;
|
||
}
|