aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliushuyu <liushuyu011@gmail.com>2023-12-18 09:52:07 +0800
committerLulu Cheng <chenglulu@loongson.cn>2023-12-18 10:04:10 +0800
commit00d7c37df2e665d012e73a9d23ed02582ff93c81 (patch)
tree633ac4aa2e6021fd4ec3cc61dcaed38b7b20b2d6
parent73aeec31c5ef15b5a3877370353164a2a6aaa8a6 (diff)
downloadgcc-00d7c37df2e665d012e73a9d23ed02582ff93c81.zip
gcc-00d7c37df2e665d012e73a9d23ed02582ff93c81.tar.gz
gcc-00d7c37df2e665d012e73a9d23ed02582ff93c81.tar.bz2
LoongArch: Add support for D frontend.
gcc/ChangeLog: * config.gcc: Add loongarch-d.o to d_target_objs for LoongArch architecture. * config/loongarch/t-loongarch: Add object target for loongarch-d.cc. * config/loongarch/loongarch-d.cc (loongarch_d_target_versions): add interface function to define builtin D versions for LoongArch architecture. (loongarch_d_handle_target_float_abi): add interface function to define builtin D traits for LoongArch architecture. (loongarch_d_register_target_info): add interface function to register loongarch_d_handle_target_float_abi function. * config/loongarch/loongarch-d.h (loongarch_d_target_versions): add function prototype. (loongarch_d_register_target_info): Likewise. libphobos/ChangeLog: * configure.tgt: Enable libphobos for LoongArch architecture. * libdruntime/gcc/sections/elf.d: Add TLS_DTV_OFFSET constant for LoongArch64. * libdruntime/gcc/unwind/generic.d: Add __aligned__ constant for LoongArch64.
-rw-r--r--gcc/config.gcc1
-rw-r--r--gcc/config/loongarch/loongarch-d.cc77
-rw-r--r--gcc/config/loongarch/loongarch-d.h26
-rw-r--r--gcc/config/loongarch/t-loongarch4
-rw-r--r--libphobos/configure.tgt3
-rw-r--r--libphobos/libdruntime/gcc/sections/elf.d2
-rw-r--r--libphobos/libdruntime/gcc/unwind/generic.d1
7 files changed, 114 insertions, 0 deletions
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 9c4656b..f0676c8 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -482,6 +482,7 @@ mips*-*-*)
;;
loongarch*-*-*)
cpu_type=loongarch
+ d_target_objs="loongarch-d.o"
extra_headers="larchintrin.h lsxintrin.h lasxintrin.h"
extra_objs="loongarch-c.o loongarch-builtins.o loongarch-cpu.o loongarch-opts.o loongarch-def.o"
extra_gcc_objs="loongarch-driver.o loongarch-cpu.o loongarch-opts.o loongarch-def.o"
diff --git a/gcc/config/loongarch/loongarch-d.cc b/gcc/config/loongarch/loongarch-d.cc
new file mode 100644
index 0000000..9ac483c
--- /dev/null
+++ b/gcc/config/loongarch/loongarch-d.cc
@@ -0,0 +1,77 @@
+/* Subroutines for the D front end on the LoongArch architecture.
+ Copyright (C) 2023 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_d.h"
+#include "d/d-target.h"
+#include "d/d-target-def.h"
+
+/* Implement TARGET_D_CPU_VERSIONS for LoongArch targets. */
+
+void
+loongarch_d_target_versions (void)
+{
+ if (TARGET_64BIT)
+ d_add_builtin_version ("LoongArch64");
+ else
+ d_add_builtin_version ("LoongArch32");
+
+ if (TARGET_HARD_FLOAT_ABI)
+ {
+ d_add_builtin_version ("LoongArch_HardFloat");
+ d_add_builtin_version ("D_HardFloat");
+ }
+ else if (TARGET_SOFT_FLOAT_ABI)
+ {
+ d_add_builtin_version ("LoongArch_SoftFloat");
+ d_add_builtin_version ("D_SoftFloat");
+ }
+}
+
+/* Handle a call to `__traits(getTargetInfo, "floatAbi")'. */
+
+static tree
+loongarch_d_handle_target_float_abi (void)
+{
+ const char *abi;
+
+ if (TARGET_HARD_FLOAT_ABI)
+ abi = "hard";
+ else if (TARGET_SOFT_FLOAT_ABI)
+ abi = "soft";
+ else
+ abi = "";
+
+ return build_string_literal (strlen (abi) + 1, abi);
+}
+
+/* Implement TARGET_D_REGISTER_CPU_TARGET_INFO. */
+
+void
+loongarch_d_register_target_info (void)
+{
+ const struct d_target_info_spec handlers[] = {
+ {"floatAbi", loongarch_d_handle_target_float_abi},
+ {NULL, NULL},
+ };
+
+ d_add_target_info_handlers (handlers);
+}
diff --git a/gcc/config/loongarch/loongarch-d.h b/gcc/config/loongarch/loongarch-d.h
new file mode 100644
index 0000000..a2fb8d5
--- /dev/null
+++ b/gcc/config/loongarch/loongarch-d.h
@@ -0,0 +1,26 @@
+/* Definitions for the D front end on the LoongArch architecture.
+ Copyright (C) 2023 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/>. */
+
+/* Defined in loongarch-d.cc */
+extern void
+loongarch_d_target_versions (void);
+extern void
+loongarch_d_register_target_info (void);
+
+/* Target hooks for D language. */
+#define TARGET_D_CPU_VERSIONS loongarch_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO loongarch_d_register_target_info
diff --git a/gcc/config/loongarch/t-loongarch b/gcc/config/loongarch/t-loongarch
index 10a984f..93a8456 100644
--- a/gcc/config/loongarch/t-loongarch
+++ b/gcc/config/loongarch/t-loongarch
@@ -67,6 +67,10 @@ loongarch-cpu.o: $(srcdir)/config/loongarch/loongarch-cpu.cc $(LA_STR_H) \
loongarch-def.o: $(srcdir)/config/loongarch/loongarch-def.cc $(LA_STR_H)
$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
+loongarch-d.o: $(srcdir)/config/loongarch/loongarch-d.cc
+ $(COMPILE) $<
+ $(POSTCOMPILE)
+
$(srcdir)/config/loongarch/loongarch.opt: s-loongarch-opt ; @true
s-loongarch-opt: $(srcdir)/config/loongarch/genopts/genstr.sh \
$(srcdir)/config/loongarch/genopts/loongarch.opt.in \
diff --git a/libphobos/configure.tgt b/libphobos/configure.tgt
index 1f21f63..297852f 100644
--- a/libphobos/configure.tgt
+++ b/libphobos/configure.tgt
@@ -36,6 +36,9 @@ case "${target}" in
hppa-*-linux*)
LIBPHOBOS_SUPPORTED=yes
;;
+ loongarch*-*-linux*)
+ LIBPHOBOS_SUPPORTED=yes
+ ;;
mips*-*-linux*)
LIBPHOBOS_SUPPORTED=yes
;;
diff --git a/libphobos/libdruntime/gcc/sections/elf.d b/libphobos/libdruntime/gcc/sections/elf.d
index 5376957..d1316b2 100644
--- a/libphobos/libdruntime/gcc/sections/elf.d
+++ b/libphobos/libdruntime/gcc/sections/elf.d
@@ -1061,6 +1061,8 @@ else version (MIPS64)
enum TLS_DTV_OFFSET = 0x8000;
else version (IBMZ_Any)
enum TLS_DTV_OFFSET = 0x0;
+else version (LoongArch64)
+ enum TLS_DTV_OFFSET = 0x0;
else
static assert( false, "Platform not supported." );
diff --git a/libphobos/libdruntime/gcc/unwind/generic.d b/libphobos/libdruntime/gcc/unwind/generic.d
index e4bbb4b..2e74b63 100644
--- a/libphobos/libdruntime/gcc/unwind/generic.d
+++ b/libphobos/libdruntime/gcc/unwind/generic.d
@@ -141,6 +141,7 @@ else version (SPARC64) private enum __aligned__ = 16;
else version (SystemZ) private enum __aligned__ = 8;
else version (X86) private enum __aligned__ = 16;
else version (X86_64) private enum __aligned__ = 16;
+else version (LoongArch64) private enum __aligned__ = 16;
else static assert( false, "Platform not supported.");
align(__aligned__) struct _Unwind_Exception