aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-10-07 11:03:59 +0000
committerGitHub <noreply@github.com>2022-10-07 11:03:59 +0000
commitbef31ea273689021f0fc8168f417edf386060512 (patch)
treefab6e519636bbfa69207b7b5faff4bbfe61eaef7 /gcc
parente623ee314fbc9503067bbb379a4055dd4d5d245b (diff)
parentbb5efc657ae66a96cf83604efa069ca76b5dd8e4 (diff)
downloadgcc-bef31ea273689021f0fc8168f417edf386060512.zip
gcc-bef31ea273689021f0fc8168f417edf386060512.tar.gz
gcc-bef31ea273689021f0fc8168f417edf386060512.tar.bz2
Merge #1543
1543: Reintroduce targetrustm hooks without the maze of macro definitions in target headers r=CohenArthur a=ibuclaw - Adds skeleton support and documentation for targetrustm hooks. - Re-adds previously reverted `TARGET_RUST_CPU_INFO` target hook. - Re-adds the previously reverted `TARGET_RUST_OS_INFO` target hook. - Implements `TARGET_RUST_CPU_INFO` hook for x86 (only a subset of the original i386-rust.cc was re-added) - Implements `TARGET_RUST_OS_INFO` hook for darwin (covers both x86 and powerpc). There's quite a bit to unpick from what was removed, but I hope this shows how firstly `rust-target.h` and `tm_rust.h` should be kept as empty as possible for the `default-rust.cc` source file that pulls in these headers; secondly all rust macros and declarations be put in rust-specific headers, then pulled into tm_rust.h as-needed. From every other `${target}-rust.cc` file, you can include as much as you like in order to pry out the information you need to get at. I've verified this does work as expected with the `-frust-dump-target_options` switch, e.g with `-mavx2` ``` target_endian: "little" target_pointer_width: "64" target_feature: "fxsr" target_feature: "popcnt" target_feature: "avx2" target_feature: "ssse3" target_feature: "sse4.1" target_feature: "sse3" target_feature: "avx" target_feature: "sse" target_feature: "xsave" target_feature: "sse4.2" target_feature: "sse2" target_feature: "mmx" target_arch: "x86_64" ``` I've also built a few darwin cross compilers with the following results on i686-darwin ``` target_pointer_width: "32" target_env: "" target_vendor: "apple" target_endian: "little" target_os: "macos" target_family: "unix" target_feature: "sse3" target_feature: "sse" target_feature: "sse2" target_feature: "mmx" target_arch: "x86" ``` and on powerpc64-darwin ``` target_pointer_width: "64" target_env: "" target_vendor: "apple" target_endian: "big" target_os: "macos" target_family: "unix" ``` Co-authored-by: Iain Buclaw <ibuclaw@gdcproject.org>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/Makefile.in34
-rw-r--r--gcc/config.gcc27
-rw-r--r--gcc/config/darwin-rust.cc44
-rw-r--r--gcc/config/default-rust.cc29
-rw-r--r--gcc/config/i386/i386-rust.cc129
-rw-r--r--gcc/config/i386/i386-rust.h22
-rw-r--r--gcc/config/i386/t-i3864
-rw-r--r--gcc/config/t-darwin4
-rwxr-xr-xgcc/configure21
-rw-r--r--gcc/configure.ac14
-rw-r--r--gcc/doc/tm.texi26
-rw-r--r--gcc/doc/tm.texi.in17
-rw-r--r--gcc/genhooks.cc1
-rw-r--r--gcc/rust/rust-lang.cc2
-rw-r--r--gcc/rust/rust-session-manager.cc8
-rw-r--r--gcc/rust/rust-target-def.h20
-rw-r--r--gcc/rust/rust-target.def52
-rw-r--r--gcc/rust/rust-target.h35
18 files changed, 483 insertions, 6 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 59b67d9..27ae592 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -573,6 +573,8 @@ tm_p_file_list=@tm_p_file_list@
tm_p_include_list=@tm_p_include_list@
tm_d_file_list=@tm_d_file_list@
tm_d_include_list=@tm_d_include_list@
+tm_rust_file_list=@tm_rust_file_list@
+tm_rust_include_list=@tm_rust_include_list@
build_xm_file_list=@build_xm_file_list@
build_xm_include_list=@build_xm_include_list@
build_xm_defines=@build_xm_defines@
@@ -866,6 +868,7 @@ CONFIG_H = config.h $(host_xm_file_list)
TCONFIG_H = tconfig.h $(xm_file_list)
TM_P_H = tm_p.h $(tm_p_file_list)
TM_D_H = tm_d.h $(tm_d_file_list)
+TM_RUST_H = tm_rust.h $(tm_rust_file_list)
GTM_H = tm.h $(tm_file_list) insn-constants.h
TM_H = $(GTM_H) insn-flags.h $(OPTIONS_H)
@@ -924,10 +927,12 @@ TARGET_DEF = target.def target-hooks-macros.h target-insns.def
C_TARGET_DEF = c-family/c-target.def target-hooks-macros.h
COMMON_TARGET_DEF = common/common-target.def target-hooks-macros.h
D_TARGET_DEF = d/d-target.def target-hooks-macros.h
+RUST_TARGET_DEF = rust/rust-target.def target-hooks-macros.h
TARGET_H = $(TM_H) target.h $(TARGET_DEF) insn-modes.h insn-codes.h
C_TARGET_H = c-family/c-target.h $(C_TARGET_DEF)
COMMON_TARGET_H = common/common-target.h $(INPUT_H) $(COMMON_TARGET_DEF)
D_TARGET_H = d/d-target.h $(D_TARGET_DEF)
+RUST_TARGET_H = rust/rust-target.h $(RUST_TARGET_DEF)
MACHMODE_H = machmode.h mode-classes.def
HOOKS_H = hooks.h
HOSTHOOKS_DEF_H = hosthooks-def.h $(HOOKS_H)
@@ -1231,6 +1236,9 @@ D_TARGET_OBJS=@d_target_objs@
# Target specific, Fortran specific object file
FORTRAN_TARGET_OBJS=@fortran_target_objs@
+# Target specific, Rust specific object file
+RUST_TARGET_OBJS=@rust_target_objs@
+
# Object files for gcc many-languages driver.
GCC_OBJS = gcc.o gcc-main.o ggc-none.o
@@ -1938,6 +1946,7 @@ tconfig.h: cs-tconfig.h ; @true
tm.h: cs-tm.h ; @true
tm_p.h: cs-tm_p.h ; @true
tm_d.h: cs-tm_d.h ; @true
+tm_rust.h: cs-tm_rust.h ; @true
cs-config.h: Makefile
TARGET_CPU_DEFAULT="" \
@@ -1969,6 +1978,11 @@ cs-tm_d.h: Makefile
HEADERS="$(tm_d_include_list)" DEFINES="" \
$(SHELL) $(srcdir)/mkconfig.sh tm_d.h
+cs-tm_rust.h: Makefile
+ TARGET_CPU_DEFAULT="" \
+ HEADERS="$(tm_rust_include_list)" DEFINES="" \
+ $(SHELL) $(srcdir)/mkconfig.sh tm_rust.h
+
# Don't automatically run autoconf, since configure.ac might be accidentally
# newer than configure. Also, this writes into the source directory which
# might be on a read-only file system. If configured for maintainer mode
@@ -2305,6 +2319,12 @@ default-d.o: config/default-d.cc
$(COMPILE) $<
$(POSTCOMPILE)
+# Files used by the Rust language front end.
+
+default-rust.o: config/default-rust.cc
+ $(COMPILE) $<
+ $(POSTCOMPILE)
+
# Language-independent files.
DRIVER_DEFINES = \
@@ -2610,6 +2630,15 @@ s-d-target-hooks-def-h: build/genhooks$(build_exeext)
d/d-target-hooks-def.h
$(STAMP) s-d-target-hooks-def-h
+rust/rust-target-hooks-def.h: s-rust-target-hooks-def-h; @true
+
+s-rust-target-hooks-def-h: build/genhooks$(build_exeext)
+ $(RUN_GEN) build/genhooks$(build_exeext) "Rust Target Hook" \
+ > tmp-rust-target-hooks-def.h
+ $(SHELL) $(srcdir)/../move-if-change tmp-rust-target-hooks-def.h \
+ rust/rust-target-hooks-def.h
+ $(STAMP) s-rust-target-hooks-def-h
+
# check if someone mistakenly only changed tm.texi.
# We use a different pathname here to avoid a circular dependency.
s-tm-texi: $(srcdir)/doc/../doc/tm.texi
@@ -2634,6 +2663,7 @@ s-tm-texi: build/genhooks$(build_exeext) $(srcdir)/doc/tm.texi.in
|| test $(srcdir)/doc/tm.texi -nt $(srcdir)/c-family/c-target.def \
|| test $(srcdir)/doc/tm.texi -nt $(srcdir)/common/common-target.def \
|| test $(srcdir)/doc/tm.texi -nt $(srcdir)/d/d-target.def \
+ || test $(srcdir)/doc/tm.texi -nt $(srcdir)/rust/rust-target.def \
); then \
echo >&2 ; \
echo You should edit $(srcdir)/doc/tm.texi.in rather than $(srcdir)/doc/tm.texi . >&2 ; \
@@ -2792,6 +2822,7 @@ generated_files = config.h tm.h $(TM_P_H) $(TM_D_H) $(TM_H) multilib.h \
common/common-target-hooks-def.h pass-instances.def \
gimple-match.cc generic-match.cc \
c-family/c-target-hooks-def.h d/d-target-hooks-def.h \
+ $(TM_RUST_H) rust/rust-target-hooks-def.h \
case-cfn-macros.h \
cfn-operators.pd omp-device-properties.h
@@ -2926,7 +2957,8 @@ build/genrecog.o : genrecog.cc $(RTL_BASE_H) $(BCONFIG_H) $(SYSTEM_H) \
$(CORETYPES_H) $(GTM_H) errors.h $(READ_MD_H) $(GENSUPPORT_H) \
$(HASH_TABLE_H) inchash.h
build/genhooks.o : genhooks.cc $(TARGET_DEF) $(C_TARGET_DEF) \
- $(COMMON_TARGET_DEF) $(D_TARGET_DEF) $(BCONFIG_H) $(SYSTEM_H) errors.h
+ $(COMMON_TARGET_DEF) $(D_TARGET_DEF) $(RUST_TARGET_DEF) $(BCONFIG_H) \
+ $(SYSTEM_H) errors.h
build/genmddump.o : genmddump.cc $(RTL_BASE_H) $(BCONFIG_H) $(SYSTEM_H) \
$(CORETYPES_H) $(GTM_H) errors.h $(READ_MD_H) $(GENSUPPORT_H)
build/genmatch.o : genmatch.cc $(BCONFIG_H) $(SYSTEM_H) \
diff --git a/gcc/config.gcc b/gcc/config.gcc
index c1b1215..4cd81c8 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -90,6 +90,9 @@
# tm_d_file A list of headers with definitions of target hook
# macros for the D compiler.
#
+# tm_rust_file list of headers with definitions of target hook
+# macros for the Rust compiler.
+#
# out_file The name of the machine description C support
# file, if different from "$cpu_type/$cpu_type.c".
#
@@ -149,6 +152,9 @@
# fortran_target_objs List of extra target-dependent objects that be
# linked into the fortran compiler only.
#
+# rust_target_objs List of extra target-dependent objects that be
+# linked into the Rust compiler only.
+#
# target_gtfiles List of extra source files with type information.
#
# xm_defines List of macros to define when compiling for the
@@ -201,6 +207,9 @@
#
# target_has_targetdm Set to yes or no depending on whether the target
# has its own definition of targetdm.
+#
+# target_has_targetrustm Set to yes or no depending on whether the target
+# has its own definition of targetrustm.
out_file=
common_out_file=
@@ -218,9 +227,11 @@ c_target_objs=
cxx_target_objs=
d_target_objs=
fortran_target_objs=
+rust_target_objs=
target_has_targetcm=no
target_has_targetm_common=yes
target_has_targetdm=no
+target_has_targetrustm=no
tm_defines=
xm_defines=
# Set this to force installation and use of collect2.
@@ -569,6 +580,16 @@ then
tm_d_file="${tm_d_file} ${cpu_type}/${cpu_type}-d.h"
fi
+tm_rust_file=
+if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-rust.h
+then
+ tm_rust_file="${cpu_type}/${cpu_type}-rust.h"
+fi
+if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-rust.cc
+then
+ rust_target_objs="${rust_target_objs} ${cpu_type}-rust.o"
+fi
+
extra_modes=
if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-modes.def
then
@@ -735,8 +756,10 @@ case ${target} in
cxx_target_objs="${cxx_target_objs} darwin-c.o"
d_target_objs="${d_target_objs} darwin-d.o"
fortran_target_objs="darwin-f.o"
+ rust_target_objs="${rust_target_objs} darwin-rust.o"
target_has_targetcm=yes
target_has_targetdm=yes
+ target_has_targetrustm=yes
extra_objs="${extra_objs} darwin.o"
extra_gcc_objs="darwin-driver.o"
default_use_cxa_atexit=yes
@@ -3544,6 +3567,10 @@ if [ "$target_has_targetdm" = "no" ]; then
d_target_objs="$d_target_objs default-d.o"
fi
+if [ "$target_has_targetrustm" = "no" ]; then
+ rust_target_objs="$rust_target_objs default-rust.o"
+fi
+
# Support for --with-cpu and related options (and a few unrelated options,
# too).
case ${with_cpu} in
diff --git a/gcc/config/darwin-rust.cc b/gcc/config/darwin-rust.cc
new file mode 100644
index 0000000..4b014b8
--- /dev/null
+++ b/gcc/config/darwin-rust.cc
@@ -0,0 +1,44 @@
+/* Darwin support needed only by Rust front-end.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+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 "tm.h"
+#include "tm_rust.h"
+#include "rust/rust-target.h"
+#include "rust/rust-target-def.h"
+
+/* Implement TARGET_RUST_OS_INFO for Darwin targets. */
+
+static void
+darwin_rust_target_os_info (void)
+{
+ rust_add_target_info ("target_family", "unix");
+
+ /* TODO: rust actually has "macos", "ios", and "tvos" for darwin targets, but
+ gcc seems to have no current support for them, so assuming that target_os
+ is always macos for now. */
+ rust_add_target_info ("target_os", "macos");
+ rust_add_target_info ("target_vendor", "apple");
+ rust_add_target_info ("target_env", "");
+}
+
+#undef TARGET_RUST_OS_INFO
+#define TARGET_RUST_OS_INFO darwin_rust_target_os_info
+
+struct gcc_targetrustm targetrustm = TARGETRUSTM_INITIALIZER;
diff --git a/gcc/config/default-rust.cc b/gcc/config/default-rust.cc
new file mode 100644
index 0000000..aa098cb
--- /dev/null
+++ b/gcc/config/default-rust.cc
@@ -0,0 +1,29 @@
+/* Default Rust language target hooks initializer.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+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 "tm_rust.h"
+#include "rust/rust-target.h"
+#include "rust/rust-target-def.h"
+
+/* Do not include tm.h or tm_p.h here; definitions needed by the target
+ architecture to initialize targetrustm should instead be added to tm_rust.h.
+ */
+
+struct gcc_targetrustm targetrustm = TARGETRUSTM_INITIALIZER;
diff --git a/gcc/config/i386/i386-rust.cc b/gcc/config/i386/i386-rust.cc
new file mode 100644
index 0000000..a00c4f8
--- /dev/null
+++ b/gcc/config/i386/i386-rust.cc
@@ -0,0 +1,129 @@
+/* Subroutines for the Rust front end on the x86 architecture.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+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/>. */
+
+#define IN_TARGET_CODE 1
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "tm_rust.h"
+#include "rust/rust-target.h"
+
+/* Implement TARGET_RUST_CPU_INFO for x86 targets. */
+
+void
+ix86_rust_target_cpu_info (void)
+{
+ if (TARGET_64BIT)
+ rust_add_target_info ("target_arch", "x86_64");
+ else
+ rust_add_target_info ("target_arch", "x86");
+
+ // features officially "stabilised" in rustc
+ if (TARGET_MMX)
+ rust_add_target_info ("target_feature", "mmx");
+ if (TARGET_SSE)
+ rust_add_target_info ("target_feature", "sse");
+ if (TARGET_SSE2)
+ rust_add_target_info ("target_feature", "sse2");
+ if (TARGET_SSE3)
+ rust_add_target_info ("target_feature", "sse3");
+ if (TARGET_SSSE3)
+ rust_add_target_info ("target_feature", "ssse3");
+ if (TARGET_SSE4_1)
+ rust_add_target_info ("target_feature", "sse4.1");
+ if (TARGET_SSE4_2)
+ rust_add_target_info ("target_feature", "sse4.2");
+ if (TARGET_AES)
+ rust_add_target_info ("target_feature", "aes");
+ if (TARGET_SHA)
+ rust_add_target_info ("target_feature", "sha");
+ if (TARGET_AVX)
+ rust_add_target_info ("target_feature", "avx");
+ if (TARGET_AVX2)
+ rust_add_target_info ("target_feature", "avx2");
+ if (TARGET_AVX512F)
+ rust_add_target_info ("target_feature", "avx512f");
+ if (TARGET_AVX512ER)
+ rust_add_target_info ("target_feature", "avx512er");
+ if (TARGET_AVX512CD)
+ rust_add_target_info ("target_feature", "avx512cd");
+ if (TARGET_AVX512PF)
+ rust_add_target_info ("target_feature", "avx512pf");
+ if (TARGET_AVX512DQ)
+ rust_add_target_info ("target_feature", "avx512dq");
+ if (TARGET_AVX512BW)
+ rust_add_target_info ("target_feature", "avx512bw");
+ if (TARGET_AVX512VL)
+ rust_add_target_info ("target_feature", "avx512vl");
+ if (TARGET_AVX512VBMI)
+ rust_add_target_info ("target_feature", "avx512vbmi");
+ if (TARGET_AVX512IFMA)
+ rust_add_target_info ("target_feature", "avx512ifma");
+ if (TARGET_AVX512VPOPCNTDQ)
+ rust_add_target_info ("target_feature", "avx512vpopcntdq");
+ if (TARGET_FMA)
+ rust_add_target_info ("target_feature", "fma");
+ if (TARGET_RTM)
+ rust_add_target_info ("target_feature", "rtm");
+ if (TARGET_SSE4A)
+ rust_add_target_info ("target_feature", "sse4a");
+ if (TARGET_BMI)
+ {
+ rust_add_target_info ("target_feature", "bmi1");
+ rust_add_target_info ("target_feature", "bmi");
+ }
+ if (TARGET_BMI2)
+ rust_add_target_info ("target_feature", "bmi2");
+ if (TARGET_LZCNT)
+ rust_add_target_info ("target_feature", "lzcnt");
+ if (TARGET_TBM)
+ rust_add_target_info ("target_feature", "tbm");
+ if (TARGET_POPCNT)
+ rust_add_target_info ("target_feature", "popcnt");
+ if (TARGET_RDRND)
+ {
+ rust_add_target_info ("target_feature", "rdrand");
+ rust_add_target_info ("target_feature", "rdrnd");
+ }
+ if (TARGET_F16C)
+ rust_add_target_info ("target_feature", "f16c");
+ if (TARGET_RDSEED)
+ rust_add_target_info ("target_feature", "rdseed");
+ if (TARGET_ADX)
+ rust_add_target_info ("target_feature", "adx");
+ if (TARGET_FXSR)
+ rust_add_target_info ("target_feature", "fxsr");
+ if (TARGET_XSAVE)
+ rust_add_target_info ("target_feature", "xsave");
+ if (TARGET_XSAVEOPT)
+ rust_add_target_info ("target_feature", "xsaveopt");
+ if (TARGET_XSAVEC)
+ rust_add_target_info ("target_feature", "xsavec");
+ if (TARGET_XSAVES)
+ rust_add_target_info ("target_feature", "xsaves");
+ if (TARGET_VPCLMULQDQ)
+ {
+ rust_add_target_info ("target_feature", "pclmulqdq");
+ rust_add_target_info ("target_feature", "vpclmulqdq");
+ }
+ if (TARGET_CMPXCHG16B)
+ rust_add_target_info ("target_feature", "cmpxchg16b");
+ if (TARGET_MOVBE)
+ rust_add_target_info ("target_feature", "movbe");
+}
diff --git a/gcc/config/i386/i386-rust.h b/gcc/config/i386/i386-rust.h
new file mode 100644
index 0000000..a837e2f
--- /dev/null
+++ b/gcc/config/i386/i386-rust.h
@@ -0,0 +1,22 @@
+/* Definitions for the Rust front end on the x86 architecture.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+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/>. */
+
+/* In i386-rust.cc */
+extern void ix86_rust_target_cpu_info (void);
+
+/* Target CPU info for Rust. */
+#define TARGET_RUST_CPU_INFO ix86_rust_target_cpu_info
diff --git a/gcc/config/i386/t-i386 b/gcc/config/i386/t-i386
index 4e2a0ef..61ddfca 100644
--- a/gcc/config/i386/t-i386
+++ b/gcc/config/i386/t-i386
@@ -46,6 +46,10 @@ i386-d.o: $(srcdir)/config/i386/i386-d.cc
$(COMPILE) $<
$(POSTCOMPILE)
+i386-rust.o: $(srcdir)/config/i386/i386-rust.cc
+ $(COMPILE) $<
+ $(POSTCOMPILE)
+
i386-options.o: $(srcdir)/config/i386/i386-options.cc
$(COMPILE) $<
$(POSTCOMPILE)
diff --git a/gcc/config/t-darwin b/gcc/config/t-darwin
index 879539e..6862e5a 100644
--- a/gcc/config/t-darwin
+++ b/gcc/config/t-darwin
@@ -34,6 +34,10 @@ darwin-f.o: $(srcdir)/config/darwin-f.cc
$(COMPILE) $<
$(POSTCOMPILE)
+darwin-rust.o: $(srcdir)/config/darwin-rust.cc
+ $(COMPILE) $<
+ $(POSTCOMPILE)
+
darwin-driver.o: $(srcdir)/config/darwin-driver.cc
$(COMPILE) $<
$(POSTCOMPILE)
diff --git a/gcc/configure b/gcc/configure
index 70a013e..66271fc 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -644,6 +644,7 @@ ISLLIBS
GMPINC
GMPLIBS
target_cpu_default
+rust_target_objs
d_target_objs
fortran_target_objs
cxx_target_objs
@@ -652,6 +653,8 @@ use_gcc_stdint
xm_defines
xm_include_list
xm_file_list
+tm_rust_include_list
+tm_rust_file_list
tm_d_include_list
tm_d_file_list
tm_p_include_list
@@ -13427,6 +13430,17 @@ for f in $tm_d_file; do
esac
done
+tm_rust_file_list=
+tm_rust_include_list=
+for f in $tm_rust_file; do
+ case $f in
+ * )
+ tm_rust_file_list="${tm_rust_file_list} \$(srcdir)/config/$f"
+ tm_rust_include_list="${tm_rust_include_list} config/$f"
+ ;;
+ esac
+done
+
xm_file_list=
xm_include_list=
for f in $xm_file; do
@@ -19689,7 +19703,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 19692 "configure"
+#line 19706 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -19795,7 +19809,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 19798 "configure"
+#line 19812 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -31648,6 +31662,9 @@ fi
+
+
+
# Echo link setup.
if test x${build} = x${host} ; then
if test x${host} = x${target} ; then
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 96e10d7..c8998aa 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2362,6 +2362,17 @@ for f in $tm_d_file; do
esac
done
+tm_rust_file_list=
+tm_rust_include_list=
+for f in $tm_rust_file; do
+ case $f in
+ * )
+ tm_rust_file_list="${tm_rust_file_list} \$(srcdir)/config/$f"
+ tm_rust_include_list="${tm_rust_include_list} config/$f"
+ ;;
+ esac
+done
+
xm_file_list=
xm_include_list=
for f in $xm_file; do
@@ -7310,6 +7321,8 @@ AC_SUBST(tm_p_file_list)
AC_SUBST(tm_p_include_list)
AC_SUBST(tm_d_file_list)
AC_SUBST(tm_d_include_list)
+AC_SUBST(tm_rust_file_list)
+AC_SUBST(tm_rust_include_list)
AC_SUBST(xm_file_list)
AC_SUBST(xm_include_list)
AC_SUBST(xm_defines)
@@ -7318,6 +7331,7 @@ AC_SUBST(c_target_objs)
AC_SUBST(cxx_target_objs)
AC_SUBST(fortran_target_objs)
AC_SUBST(d_target_objs)
+AC_SUBST(rust_target_objs)
AC_SUBST(target_cpu_default)
AC_SUBST_FILE(language_hooks)
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 858bfb8..75ae4b2 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -53,6 +53,7 @@ through the macros defined in the @file{.h} file.
* PCH Target:: Validity checking for precompiled headers.
* C++ ABI:: Controlling C++ ABI changes.
* D Language and ABI:: Controlling D ABI changes.
+* Rust Language and ABI:: Controlling Rust ABI changes.
* Named Address Spaces:: Adding support for named address spaces
* Misc:: Everything else.
@end menu
@@ -115,6 +116,14 @@ initialize @code{targetdm} themselves, they should set
@code{target_has_targetdm=yes} in @file{config.gcc}; otherwise a default
definition is used.
+Similarly, there is a @code{targetrustm} variable for hooks that are
+specific to the Rust language front end, documented as ``Rust Target
+Hook''. This is declared in @file{rust/rust-target.h}, the initializer
+@code{TARGETRUSTM_INITIALIZER} in @file{rust/rust-target-def.h}.
+If targets initialize @code{targetrustm} themselves, they should set
+@code{target_has_targetrustm=yes} in @file{config.gcc}; otherwise a
+default definition is used.
+
@node Driver
@section Controlling the Compilation Driver, @file{gcc}
@cindex driver
@@ -10874,6 +10883,23 @@ if they have external linkage. If this flag is false, then instantiated
decls will be emitted as weak symbols. The default is @code{false}.
@end deftypevr
+@node Rust Language and ABI
+@section Rust ABI parameters
+@cindex parameters, rust abi
+
+@deftypefn {Rust Target Hook} void TARGET_RUST_CPU_INFO (void)
+Declare all environmental CPU info and features relating to the target CPU
+using the function @code{rust_add_target_info}, which takes a string
+representing the feature key and a string representing the feature value.
+Configuration pairs predefined by this hook apply to all files that are being
+compiled.
+@end deftypefn
+
+@deftypefn {Rust Target Hook} void TARGET_RUST_OS_INFO (void)
+Similar to @code{TARGET_RUST_CPU_INFO}, but is used for configuration info
+relating to the target operating system.
+@end deftypefn
+
@node Named Address Spaces
@section Adding support for named address spaces
@cindex named address spaces
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 21b849e..c8c2b8b 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -53,6 +53,7 @@ through the macros defined in the @file{.h} file.
* PCH Target:: Validity checking for precompiled headers.
* C++ ABI:: Controlling C++ ABI changes.
* D Language and ABI:: Controlling D ABI changes.
+* Rust Language and ABI:: Controlling Rust ABI changes.
* Named Address Spaces:: Adding support for named address spaces
* Misc:: Everything else.
@end menu
@@ -115,6 +116,14 @@ initialize @code{targetdm} themselves, they should set
@code{target_has_targetdm=yes} in @file{config.gcc}; otherwise a default
definition is used.
+Similarly, there is a @code{targetrustm} variable for hooks that are
+specific to the Rust language front end, documented as ``Rust Target
+Hook''. This is declared in @file{rust/rust-target.h}, the initializer
+@code{TARGETRUSTM_INITIALIZER} in @file{rust/rust-target-def.h}.
+If targets initialize @code{targetrustm} themselves, they should set
+@code{target_has_targetrustm=yes} in @file{config.gcc}; otherwise a
+default definition is used.
+
@node Driver
@section Controlling the Compilation Driver, @file{gcc}
@cindex driver
@@ -7119,6 +7128,14 @@ floating-point support; they are not included in this mechanism.
@hook TARGET_D_TEMPLATES_ALWAYS_COMDAT
+@node Rust Language and ABI
+@section Rust ABI parameters
+@cindex parameters, rust abi
+
+@hook TARGET_RUST_CPU_INFO
+
+@hook TARGET_RUST_OS_INFO
+
@node Named Address Spaces
@section Adding support for named address spaces
@cindex named address spaces
diff --git a/gcc/genhooks.cc b/gcc/genhooks.cc
index 6bae85d..4e1338d 100644
--- a/gcc/genhooks.cc
+++ b/gcc/genhooks.cc
@@ -35,6 +35,7 @@ static struct hook_desc hook_array[] = {
#include "c-family/c-target.def"
#include "common/common-target.def"
#include "d/d-target.def"
+#include "rust/rust-target.def"
#undef DEFHOOK
};
diff --git a/gcc/rust/rust-lang.cc b/gcc/rust/rust-lang.cc
index c9af790..ed822cc 100644
--- a/gcc/rust/rust-lang.cc
+++ b/gcc/rust/rust-lang.cc
@@ -104,8 +104,6 @@ struct GTY (()) language_function
void
rust_add_target_info (const char *key, const char *value)
{
- sorry ("TODO");
-
Rust::Session::get_instance ().options.target_data.insert_key_value_pair (
key, value);
}
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index a6291a3..ef1a85d 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -42,7 +42,8 @@
#include "diagnostic.h"
#include "input.h"
#include "selftest.h"
-#include "target.h"
+#include "tm.h"
+#include "rust-target.h"
extern bool
saw_errors (void);
@@ -135,6 +136,11 @@ validate_crate_name (const std::string &crate_name, Error &error)
void
Session::init ()
{
+ // initialize target hooks
+ targetrustm.rust_cpu_info ();
+ targetrustm.rust_os_info ();
+
+ // target-independent values that should exist in all targets
options.target_data.insert_key_value_pair ("target_pointer_width",
std::to_string (POINTER_SIZE));
options.target_data.insert_key_value_pair ("target_endian", BYTES_BIG_ENDIAN
diff --git a/gcc/rust/rust-target-def.h b/gcc/rust/rust-target-def.h
new file mode 100644
index 0000000..8534c4b
--- /dev/null
+++ b/gcc/rust/rust-target-def.h
@@ -0,0 +1,20 @@
+/* Default initializers for Rust target hooks.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+ This program 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.
+
+ This program 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 this program; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+#include "rust/rust-target-hooks-def.h"
+#include "tree.h"
+#include "hooks.h"
diff --git a/gcc/rust/rust-target.def b/gcc/rust/rust-target.def
new file mode 100644
index 0000000..9c72c1c
--- /dev/null
+++ b/gcc/rust/rust-target.def
@@ -0,0 +1,52 @@
+/* Target hook definitions for the Rust front end.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+ This program 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.
+
+ This program 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 this program; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+/* See target-hooks-macros.h for details of macros that should be
+ provided by the including file, and how to use them here. */
+
+#include "target-hooks-macros.h"
+
+#undef HOOK_TYPE
+#define HOOK_TYPE "Rust Target Hook"
+
+HOOK_VECTOR (TARGETRUSTM_INITIALIZER, gcc_targetrustm)
+
+#undef HOOK_PREFIX
+#define HOOK_PREFIX "TARGET_"
+
+/* Environmental CPU info and features (e.g. endianness, pointer size) relating
+ to the target CPU. */
+DEFHOOK
+(rust_cpu_info,
+ "Declare all environmental CPU info and features relating to the target CPU\n\
+using the function @code{rust_add_target_info}, which takes a string\n\
+representing the feature key and a string representing the feature value.\n\
+Configuration pairs predefined by this hook apply to all files that are being\n\
+compiled.",
+ void, (void),
+ hook_void_void)
+
+/* Environmental OS info relating to the target OS. */
+DEFHOOK
+(rust_os_info,
+ "Similar to @code{TARGET_RUST_CPU_INFO}, but is used for configuration info\n\
+relating to the target operating system.",
+ void, (void),
+ hook_void_void)
+
+/* Close the 'struct gcc_targetrustm' definition. */
+HOOK_VECTOR_END (C90_EMPTY_HACK)
diff --git a/gcc/rust/rust-target.h b/gcc/rust/rust-target.h
new file mode 100644
index 0000000..7fcdfc9
--- /dev/null
+++ b/gcc/rust/rust-target.h
@@ -0,0 +1,35 @@
+/* Data structure definitions for target-specific Rust behavior.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+ This program 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.
+
+ This program 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 this program; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef GCC_RUST_TARGET_H
+#define GCC_RUST_TARGET_H
+
+#define DEFHOOKPOD(NAME, DOC, TYPE, INIT) TYPE NAME;
+#define DEFHOOK(NAME, DOC, TYPE, PARAMS, INIT) TYPE (*NAME) PARAMS;
+#define DEFHOOK_UNDOC DEFHOOK
+#define HOOKSTRUCT(FRAGMENT) FRAGMENT
+
+#include "rust-target.def"
+
+/* Used by target to add target-related info. */
+extern void
+rust_add_target_info (const char *, const char *);
+
+/* Each target can provide their own. */
+extern struct gcc_targetrustm targetrustm;
+
+#endif /* GCC_RUST_TARGET_H */