genemit: Split insn-emit.cc into several partitions.

On riscv insn-emit.cc has grown to over 1.2 mio lines of code and
compiling it takes considerable time.
Therefore, this patch adjust genemit to create several partitions
(insn-emit-1.cc to insn-emit-n.cc).  The available patterns are
written to the given files in a sequential fashion.

Similar to match.pd a configure option --with-emitinsn-partitions=num
is introduced that makes the number of partition configurable.

gcc/ChangeLog:

	PR bootstrap/84402
	PR target/111600

	* Makefile.in: Handle split insn-emit.cc.
	* configure: Regenerate.
	* configure.ac: Add --with-insnemit-partitions.
	* genemit.cc (output_peephole2_scratches): Print to file instead
	of stdout.
	(print_code): Ditto.
	(gen_rtx_scratch): Ditto.
	(gen_exp): Ditto.
	(gen_emit_seq): Ditto.
	(emit_c_code): Ditto.
	(gen_insn): Ditto.
	(gen_expand): Ditto.
	(gen_split): Ditto.
	(output_add_clobbers): Ditto.
	(output_added_clobbers_hard_reg_p): Ditto.
	(print_overload_arguments): Ditto.
	(print_overload_test): Ditto.
	(handle_overloaded_code_for): Ditto.
	(handle_overloaded_gen): Ditto.
	(print_header): New function.
	(handle_arg): New function.
	(main): Split output into 10 files.
	* gensupport.cc (count_patterns): New function.
	* gensupport.h (count_patterns): Define.
	* read-md.cc (md_reader::print_md_ptr_loc): Add file argument.
	* read-md.h (class md_reader): Change definition.
This commit is contained in:
Robin Dapp 2023-10-12 11:23:26 +02:00
parent 15404016d9
commit 184378027e
8 changed files with 422 additions and 255 deletions

View File

@ -236,6 +236,13 @@ GIMPLE_MATCH_PD_SEQ_O = $(patsubst %, gimple-match-%.o, $(MATCH_SPLITS_SEQ))
GENERIC_MATCH_PD_SEQ_SRC = $(patsubst %, generic-match-%.cc, $(MATCH_SPLITS_SEQ))
GENERIC_MATCH_PD_SEQ_O = $(patsubst %, generic-match-%.o, $(MATCH_SPLITS_SEQ))
# The number of splits to be made for the insn-emit files.
NUM_INSNEMIT_SPLITS = @DEFAULT_INSNEMIT_PARTITIONS@
INSNEMIT_SPLITS_SEQ = $(wordlist 1,$(NUM_INSNEMIT_SPLITS),$(one_to_9999))
INSNEMIT_SEQ_SRC = $(patsubst %, insn-emit-%.cc, $(INSNEMIT_SPLITS_SEQ))
INSNEMIT_SEQ_TMP = $(patsubst %, tmp-emit-%.cc, $(INSNEMIT_SPLITS_SEQ))
INSNEMIT_SEQ_O = $(patsubst %, insn-emit-%.o, $(INSNEMIT_SPLITS_SEQ))
# These files are to have specific diagnostics suppressed, or are not to
# be subject to -Werror:
# flex output may yield harmless "no previous prototype" warnings
@ -1356,7 +1363,7 @@ OBJS = \
insn-attrtab.o \
insn-automata.o \
insn-dfatab.o \
insn-emit.o \
$(INSNEMIT_SEQ_O) \
insn-extract.o \
insn-latencytab.o \
insn-modes.o \
@ -1857,7 +1864,8 @@ TREECHECKING = @TREECHECKING@
FULL_DRIVER_NAME=$(target_noncanonical)-gcc-$(version)$(exeext)
MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \
insn-output.cc insn-recog.cc insn-emit.cc insn-extract.cc insn-peep.cc \
insn-output.cc insn-recog.cc $(INSNEMIT_SEQ_SRC) \
insn-extract.cc insn-peep.cc \
insn-attr.h insn-attr-common.h insn-attrtab.cc insn-dfatab.cc \
insn-latencytab.cc insn-opinit.cc insn-opinit.h insn-preds.cc insn-constants.h \
tm-preds.h tm-constrs.h checksum-options $(GIMPLE_MATCH_PD_SEQ_SRC) \
@ -2489,11 +2497,11 @@ $(common_out_object_file): $(common_out_file)
# and compile them.
.PRECIOUS: insn-config.h insn-flags.h insn-codes.h insn-constants.h \
insn-emit.cc insn-recog.cc insn-extract.cc insn-output.cc insn-peep.cc \
insn-attr.h insn-attr-common.h insn-attrtab.cc insn-dfatab.cc \
insn-latencytab.cc insn-preds.cc $(GIMPLE_MATCH_PD_SEQ_SRC) \
$(GENERIC_MATCH_PD_SEQ_SRC) gimple-match-auto.h generic-match-auto.h \
insn-target-def.h
$(INSNEMIT_SEQ_SRC) insn-recog.cc insn-extract.cc insn-output.cc \
insn-peep.cc insn-attr.h insn-attr-common.h insn-attrtab.cc \
insn-dfatab.cc insn-latencytab.cc insn-preds.cc \
$(GIMPLE_MATCH_PD_SEQ_SRC) $(GENERIC_MATCH_PD_SEQ_SRC) \
gimple-match-auto.h generic-match-auto.h insn-target-def.h
# 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
@ -2516,7 +2524,7 @@ s-mddeps: $(md_file) $(MD_INCLUDES) build/genmddeps$(build_exeext)
simple_rtl_generated_h = insn-attr.h insn-attr-common.h insn-codes.h \
insn-config.h insn-flags.h insn-target-def.h
simple_rtl_generated_c = insn-automata.cc insn-emit.cc \
simple_rtl_generated_c = insn-automata.cc \
insn-extract.cc insn-output.cc \
insn-peep.cc insn-recog.cc
@ -2545,8 +2553,20 @@ $(simple_generated_c:insn-%.cc=s-%): s-%: build/gen%$(build_exeext)
$(SHELL) $(srcdir)/../move-if-change tmp-$*.cc insn-$*.cc
$(STAMP) s-$*
# genemit splits its output into different files and doesn't write to
# stdout. (but rather to tmp-emit-01.cc..tmp-emit-10.cc)
$(INSNEMIT_SEQ_SRC): s-tmp-emit; @true
s-tmp-emit: build/genemit$(build_exeext) $(MD_DEPS) insn-conditions.md
$(RUN_GEN) build/genemit$(build_exeext) $(md_file) insn-conditions.md \
$(addprefix -O,${INSNEMIT_SEQ_TMP})
$(foreach id, $(INSNEMIT_SPLITS_SEQ), \
$(SHELL) $(srcdir)/../move-if-change tmp-emit-$(id).cc \
insn-emit-$(id).cc;)
$(STAMP) s-tmp-emit
# gencheck doesn't read the machine description, and the file produced
# doesn't use the insn-* convention.
tree-check.h: s-check ; @true
s-check : build/gencheck$(build_exeext)
$(RUN_GEN) build/gencheck$(build_exeext) > tmp-check.h

24
gcc/configure vendored
View File

@ -844,6 +844,7 @@ enable_gcov
enable_shared
enable_fixed_point
enable_decimal_float
DEFAULT_INSNEMIT_PARTITIONS
DEFAULT_MATCHPD_PARTITIONS
with_float
with_cpu
@ -973,6 +974,7 @@ enable_multilib
enable_multiarch
with_stack_clash_protection_guard_size
with_matchpd_partitions
with_insnemit_partitions
enable___cxa_atexit
enable_decimal_float
enable_fixed_point
@ -1846,6 +1848,9 @@ Optional Packages:
--with-matchpd-partitions=num
Set the number of partitions to make for gimple and
generic when splitting match.pd. [default=10]
--with-insnemit-partitions=num
Set the number of partitions of insn-emit.cc for
genemit to create. [default=10]
--with-dwarf2 force the default debug format to be DWARF 2 (or
later)
--with-specs=SPECS add SPECS to driver command-line processing
@ -7948,6 +7953,21 @@ fi
# Specify the number of splits of insn-emit.cc to generate.
# Check whether --with-insnemit-partitions was given.
if test "${with_insnemit_partitions+set}" = set; then :
withval=$with_insnemit_partitions; DEFAULT_INSNEMIT_PARTITIONS="$with_insnemit_partitions"
else
DEFAULT_INSNEMIT_PARTITIONS=10
fi
if (test $DEFAULT_INSNEMIT_PARTITIONS -lt 1); then
as_fn_error $? "Invalid value $DEFAULT_INSNEMIT_PARTITIONS for --with-insnemit-partitions. Cannot be negative." "$LINENO" 5
fi
# Enable __cxa_atexit for C++.
# Check whether --enable-__cxa_atexit was given.
if test "${enable___cxa_atexit+set}" = set; then :
@ -19980,7 +20000,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 19983 "configure"
#line 19995 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -20086,7 +20106,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 20089 "configure"
#line 20101 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H

View File

@ -956,6 +956,19 @@ fi
AC_SUBST(DEFAULT_MATCHPD_PARTITIONS)
# Specify the number of splits of insn-emit.cc to generate.
AC_ARG_WITH(insnemit-partitions,
[AS_HELP_STRING([--with-insnemit-partitions=num],
[Set the number of partitions of insn-emit.cc for genemit to create. [default=10]])],
[DEFAULT_INSNEMIT_PARTITIONS="$with_insnemit_partitions"], [DEFAULT_INSNEMIT_PARTITIONS=10])
if (test $DEFAULT_INSNEMIT_PARTITIONS -lt 1); then
AC_MSG_ERROR(m4_normalize([
Invalid value $DEFAULT_INSNEMIT_PARTITIONS for --with-insnemit-partitions. \
Cannot be negative.]))
fi
AC_SUBST(DEFAULT_INSNEMIT_PARTITIONS)
# Enable __cxa_atexit for C++.
AC_ARG_ENABLE(__cxa_atexit,
[AS_HELP_STRING([--enable-__cxa_atexit], [enable __cxa_atexit for C++])],

File diff suppressed because it is too large Load Diff

View File

@ -3131,6 +3131,61 @@ init_rtx_reader_args (int argc, const char **argv)
return init_rtx_reader_args_cb (argc, argv, 0);
}
/* Count the number of patterns in all queues and return the count. */
int
count_patterns ()
{
int count = 0, truth = 1;
rtx def;
class queue_elem *cur = define_attr_queue;
while (cur)
{
def = cur->data;
truth = maybe_eval_c_test (get_c_test (def));
if (truth || !insn_elision)
count++;
cur = cur->next;
}
cur = define_pred_queue;
while (cur)
{
def = cur->data;
truth = maybe_eval_c_test (get_c_test (def));
if (truth || !insn_elision)
count++;
cur = cur->next;
}
cur = define_insn_queue;
truth = 1;
while (cur)
{
def = cur->data;
truth = maybe_eval_c_test (get_c_test (def));
if (truth || !insn_elision)
count++;
cur = cur->next;
}
cur = other_queue;
truth = 1;
while (cur)
{
def = cur->data;
truth = maybe_eval_c_test (get_c_test (def));
if (truth || !insn_elision)
count++;
cur = cur->next;
}
return count;
}
/* Try to read a single rtx from the file. Return true on success,
describing it in *INFO. */

View File

@ -130,6 +130,7 @@ extern rtx add_implicit_parallel (rtvec);
extern rtx_reader *init_rtx_reader_args_cb (int, const char **,
bool (*)(const char *));
extern rtx_reader *init_rtx_reader_args (int, const char **);
extern int count_patterns ();
extern bool read_md_rtx (md_rtx_info *);
extern unsigned int get_num_insn_codes ();

View File

@ -132,9 +132,9 @@ md_reader::fprint_md_ptr_loc (FILE *outf, const void *ptr)
/* Special fprint_md_ptr_loc for writing to STDOUT. */
void
md_reader::print_md_ptr_loc (const void *ptr)
md_reader::print_md_ptr_loc (const void *ptr, FILE *file)
{
fprint_md_ptr_loc (stdout, ptr);
fprint_md_ptr_loc (file, ptr);
}
/* Return a condition that satisfies both COND1 and COND2. Either string

View File

@ -194,7 +194,7 @@ class md_reader
const struct ptr_loc *get_md_ptr_loc (const void *ptr);
void copy_md_ptr_loc (const void *new_ptr, const void *old_ptr);
void fprint_md_ptr_loc (FILE *outf, const void *ptr);
void print_md_ptr_loc (const void *ptr);
void print_md_ptr_loc (const void *ptr, FILE * = stdout);
struct enum_type *lookup_enum_type (const char *name);
void traverse_enum_types (htab_trav callback, void *info);