Skip to content

Commit

Permalink
Support Xuantie CPUs.
Browse files Browse the repository at this point in the history
	Xuantie E9xx CPUs: E906, E907
	Xuantie C9xx CPUs: C906, C910
  • Loading branch information
Cooper-Qu committed Oct 17, 2021
1 parent 9955d46 commit f342d03
Show file tree
Hide file tree
Showing 2,396 changed files with 361,667 additions and 301 deletions.
41 changes: 30 additions & 11 deletions gcc/Makefile.in
Expand Up @@ -1075,7 +1075,8 @@ GNATMAKE = @GNATMAKE@
# Libs needed (at present) just for jcf-dump.
LDEXP_LIB = @LDEXP_LIB@

ZSTD_LIB = @ZSTD_LIB@
ZSTD_INC = @ZSTD_CPPFLAGS@
ZSTD_LIB = @ZSTD_LDFLAGS@ @ZSTD_LIB@

# Likewise, for use in the tools that must run on this machine
# even if we are cross-building GCC.
Expand Down Expand Up @@ -1148,6 +1149,15 @@ export STRIP_FOR_TARGET
export RANLIB_FOR_TARGET
export libsubdir

number_series0:=1 2 3 4 5 6 7 8 9
number_series1:=0 $(number_series0)
number_series2:=$(foreach i,$(number_series0),$(addprefix $(i),$(number_series1)))
number_series3:=$(addprefix 0,$(number_series1)) $(number_series2)
number_series4:=$(foreach i,$(number_series0),$(addprefix $(i),$(number_series3)))
number_series5:=$(addprefix 0,$(number_series3)) $(number_series4)
number_series6:=$(foreach i,$(number_series0),$(addprefix $(i),$(number_series5)))
number_series:=$(number_series0) $(number_series2) $(number_series4) $(number_series6)

FLAGS_TO_PASS = \
"ADA_CFLAGS=$(ADA_CFLAGS)" \
"BISON=$(BISON)" \
Expand Down Expand Up @@ -1246,13 +1256,27 @@ ANALYZER_OBJS = \
# We put the *-match.o and insn-*.o files first so that a parallel make
# will build them sooner, because they are large and otherwise tend to be
# the last objects to finish building.

# target overrides
INSN-GENERATED-SPLIT-FILE=$(foreach o, $(tmake_file), $(o)-splitgen)
-include $(INSN-GENERATED-SPLIT-FILE)

INSN-GENERATED-SPLIT-NUM ?= 0

insn-generated-split-num = $(wordlist 1,$(shell expr $(INSN-GENERATED-SPLIT-NUM) + 1),$(number_series))

insn-emit-split-c := $(foreach o, $(insn-generated-split-num), insn-emit$(o).c)
insn-emit-split-obj = $(patsubst %.c,%.o, $(insn-emit-split-c))
$(insn-emit-split-c): insn-emit.c

OBJS = \
gimple-match.o \
generic-match.o \
insn-attrtab.o \
insn-automata.o \
insn-dfatab.o \
insn-emit.o \
$(insn-emit-split-obj) \
insn-extract.o \
insn-latencytab.o \
insn-modes.o \
Expand Down Expand Up @@ -2278,7 +2302,7 @@ CFLAGS-version.o += -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
version.o: $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)

# lto-compress.o needs $(ZLIBINC) added to the include flags.
CFLAGS-lto-compress.o += $(ZLIBINC)
CFLAGS-lto-compress.o += $(ZLIBINC) $(ZSTD_INC)

CFLAGS-lto-streamer-in.o += -DTARGET_MACHINE=\"$(target_noncanonical)\"

Expand Down Expand Up @@ -2363,6 +2387,9 @@ $(simple_generated_c:insn-%.c=s-%): s-%: build/gen%$(build_exeext)
$(RUN_GEN) build/gen$*$(build_exeext) $(md_file) \
$(filter insn-conditions.md,$^) > tmp-$*.c
$(SHELL) $(srcdir)/../move-if-change tmp-$*.c insn-$*.c
$*v=$$(echo $$(csplit insn-$*.c /parallel\ compilation/ -k -s {$(INSN-GENERATED-SPLIT-NUM)} -f insn-$* -b "%d.c" 2>&1));\
[ ! "$$$*v" ] || grep "match not found" <<< $$$*v
[ -s insn-$*0.c ] || (for i in $(insn-generated-split-num); do touch insn-$*$$i.c; done && echo "" > insn-$*.c)
$(STAMP) s-$*

# gencheck doesn't read the machine description, and the file produced
Expand Down Expand Up @@ -4078,18 +4105,10 @@ $(patsubst %,%-subtargets,$(lang_checks)): check-%-subtargets:
check_p_tool=$(firstword $(subst _, ,$*))
check_p_count=$(check_$(check_p_tool)_parallelize)
check_p_subno=$(word 2,$(subst _, ,$*))
check_p_numbers0:=1 2 3 4 5 6 7 8 9
check_p_numbers1:=0 $(check_p_numbers0)
check_p_numbers2:=$(foreach i,$(check_p_numbers0),$(addprefix $(i),$(check_p_numbers1)))
check_p_numbers3:=$(addprefix 0,$(check_p_numbers1)) $(check_p_numbers2)
check_p_numbers4:=$(foreach i,$(check_p_numbers0),$(addprefix $(i),$(check_p_numbers3)))
check_p_numbers5:=$(addprefix 0,$(check_p_numbers3)) $(check_p_numbers4)
check_p_numbers6:=$(foreach i,$(check_p_numbers0),$(addprefix $(i),$(check_p_numbers5)))
check_p_numbers:=$(check_p_numbers0) $(check_p_numbers2) $(check_p_numbers4) $(check_p_numbers6)
check_p_subdir=$(subst _,,$*)
check_p_subdirs=$(wordlist 1,$(check_p_count),$(wordlist 1, \
$(if $(GCC_TEST_PARALLEL_SLOTS),$(GCC_TEST_PARALLEL_SLOTS),128), \
$(check_p_numbers)))
$(number_series)))

# For parallelized check-% targets, this decides whether parallelization
# is desirable (if -jN is used). If desirable, recursive make is run with
Expand Down
5 changes: 5 additions & 0 deletions gcc/combine.c
Expand Up @@ -15054,7 +15054,12 @@ make_more_copies (void)
static unsigned int
rest_of_handle_combine (void)
{
#ifdef TARGET_XTHEAD_COMBINE_COPY
if (TARGET_XTHEAD_COMBINE_COPY)
make_more_copies ();
#else
make_more_copies ();
#endif

df_set_flags (DF_LR_RUN_DCE + DF_DEFER_INSN_RESCAN);
df_note_add_problem ();
Expand Down
112 changes: 70 additions & 42 deletions gcc/common/config/riscv/riscv-common.c
Expand Up @@ -270,42 +270,38 @@ riscv_subset_list::parsing_subset_version (const char *p,
unsigned version = 0;
unsigned major = 0;
unsigned minor = 0;
char np;
*explicit_version_p = false;

for (; *p; ++p)
{
if (*p == 'p')
{
np = *(p + 1);

if (!ISDIGIT (np))
{
/* Might be beginning of `p` extension. */
if (std_ext_p)
{
*major_version = version;
*minor_version = 0;
*explicit_version_p = true;
return p;
}
else
{
error_at (m_loc, "%<-march=%s%>: Expect number "
"after %<%dp%>.", m_arch, version);
return NULL;
}
}

major = version;
major_p = false;
version = 0;
}
else if (ISDIGIT (*p))
version = (version * 10) + (*p - '0');
else
break;
}
/* If we got `p`, that means we are still parsing standard extension. */
gcc_assert (std_ext_p || *p != 'p');

if (*p != 'p') {
for (; *p; ++p)
{
if (*p == 'p')
{
if (!ISDIGIT (*(p+1)))
{
error_at (m_loc, "%<-march=%s%>: Expect number "
"after %<%dp%>.", m_arch, version);
return NULL;
}
if (!major_p)
{
error_at (m_loc, "%<-march=%s%>: ISA version with more than 2 "
"level is not supported.", m_arch);
return NULL;
}
major = version;
major_p = false;
version = 0;
}
else if (ISDIGIT (*p))
version = (version * 10) + (*p - '0');
else
break;
}
}

if (major_p)
major = version;
Expand Down Expand Up @@ -399,7 +395,7 @@ riscv_subset_list::parse_std_ext (const char *p)
return NULL;
}

while (*p)
while (p != NULL && *p)
{
char subset[2] = {0, 0};

Expand Down Expand Up @@ -455,14 +451,14 @@ riscv_subset_list::parse_std_ext (const char *p)
explicitly given by user or not. */
void
riscv_subset_list::handle_implied_ext (const char *ext,
int major_version,
int minor_version,
bool explicit_version_p)
int major_version,
int minor_version,
bool explicit_version_p)
{
riscv_implied_info_t *implied_info;
for (implied_info = &riscv_implied_info[0];
implied_info->ext;
++implied_info)
implied_info->ext;
++implied_info)
{
if (strcmp (ext, implied_info->ext) != 0)
continue;
Expand Down Expand Up @@ -521,6 +517,8 @@ riscv_subset_list::parse_multiletter_ext (const char *p,
/* default_minor_version= */ 0,
/* std_ext_p= */ FALSE,
&explicit_version_p);
if (end_of_version == NULL)
return NULL;

*q = '\0';

Expand All @@ -533,6 +531,7 @@ riscv_subset_list::parse_multiletter_ext (const char *p,
}

add (subset, major_version, minor_version, explicit_version_p);

free (subset);
p += end_of_version - subset;

Expand Down Expand Up @@ -604,10 +603,23 @@ riscv_subset_list::parse (const char *arch, location_t loc)
if (*p != '\0')
{
error_at (loc, "%<-march=%s%>: unexpected ISA string at end: %qs",
arch, p);
arch, p);
goto fail;
}

/* Compatible with X-Thead old extension instruction names. */
riscv_subset_t *implied_subset;
if ((implied_subset = subset_list->lookup ("xthead")))
{
if (subset_list->m_xlen == 32)
if (subset_list->lookup ("e"))
implied_subset->name = "xtheadse";
else
implied_subset->name = "xtheade";
else if (subset_list->m_xlen == 64)
implied_subset->name = "xtheadc";
}

return subset_list;

fail:
Expand Down Expand Up @@ -645,6 +657,14 @@ static const riscv_ext_flag_table_t riscv_ext_flag_table[] =
{"f", &gcc_options::x_target_flags, MASK_HARD_FLOAT},
{"d", &gcc_options::x_target_flags, MASK_DOUBLE_FLOAT},
{"c", &gcc_options::x_target_flags, MASK_RVC},

{"xtheadc", &gcc_options::x_target_flags, MASK_XTHEAD_C | MASK_XTHEAD},
{"xtheade", &gcc_options::x_target_flags, MASK_XTHEAD_E | MASK_XTHEAD},
{"xtheadse", &gcc_options::x_target_flags, MASK_XTHEAD_SE |MASK_XTHEAD},
{"v", &gcc_options::x_target_flags, MASK_VECTOR},
{"p", &gcc_options::x_target_flags, MASK_DSP},
{"zpsfoperand", &gcc_options::x_target_flags, MASK_ZPSFOPERAND},

{NULL, NULL, 0}
};

Expand Down Expand Up @@ -675,16 +695,24 @@ riscv_parse_arch_string (const char *isa,
else if (subset_list->xlen () == 64)
opts->x_target_flags |= MASK_64BIT;


for (arch_ext_flag_tab = &riscv_ext_flag_table[0];
arch_ext_flag_tab->ext;
++arch_ext_flag_tab)
{
if (subset_list->lookup (arch_ext_flag_tab->ext))
opts->*arch_ext_flag_tab->var_ref |= arch_ext_flag_tab->mask;
}

if (subset_list->lookup ("p") && subset_list->xlen () == 64)
opts->x_target_flags |= MASK_ZPSFOPERAND;
}

if (subset_list->lookup ("xcki"))
error_at (loc, "The ISA name 'xcki' is no longer maintained, please use 'xthead{c,e,se}' instead");

if (subset_list->lookup ("xcrypto"))
error_at (loc, "The ISA name 'xcrypto' is no longer maintained, please use 'xtheade' instead");

if (current_subset_list)
delete current_subset_list;

Expand Down
8 changes: 6 additions & 2 deletions gcc/config.gcc
Expand Up @@ -527,6 +527,7 @@ riscv*)
cpu_type=riscv
extra_objs="riscv-builtins.o riscv-c.o riscv-sr.o riscv-shorten-memrefs.o"
d_target_objs="riscv-d.o"
extra_headers="riscv-vector.h riscv-dsp.h"
;;
rs6000*-*-*)
extra_options="${extra_options} g.opt fused-madd.opt rs6000/rs6000-tables.opt"
Expand Down Expand Up @@ -4552,13 +4553,15 @@ case "${target}" in
# pick a default based on the ISA, preferring soft-float
# unless the D extension is present.
case "${with_abi}" in
ilp32 | ilp32e | ilp32f | ilp32d | lp64 | lp64f | lp64d)
ilp32 | ilp32e | ilp32f | ilp32d | lp64 | lp64f | lp64d | lp64v | lp64dv)
;;
"")
case "${with_arch}" in
rv32*d* | rv32g*) with_abi=ilp32d ;;
rv32e*) with_abi=ilp32e ;;
rv32*) with_abi=ilp32 ;;
rv64*d*v* | rv64g*v*) with_abi=lp64dv ;;
rv64*v*) with_abi=lp64v ;;
rv64*d* | rv64g*) with_abi=lp64d ;;
rv64*) with_abi=lp64 ;;
esac
Expand All @@ -4576,7 +4579,8 @@ case "${target}" in
| ilp32d,rv32*d* | ilp32d,rv32g* \
| lp64,rv64* \
| lp64f,rv64*f* | lp64f,rv64g* \
| lp64d,rv64*d* | lp64d,rv64g*)
| lp64d,rv64*d* | lp64d,rv64g* \
| lp64dv,rv64*d*v* | lp64dv,rv64g*v* | lp64v,rv64*v*)
;;
*)
echo "--with-abi=${with_abi} is not supported for ISA ${with_arch}" 1>&2
Expand Down

0 comments on commit f342d03

Please sign in to comment.