From patchwork Sun Sep 24 21:40:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liushuyu X-Patchwork-Id: 144144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp849680vqu; Sun, 24 Sep 2023 14:41:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+mBu92x2yQ5WW2UxR4vqtaRFA9mf0AxiaBahXW5kxsV/VbKlJjBJ2pojtoGhxQSQxkj51 X-Received: by 2002:a05:6512:3b28:b0:503:437:b14a with SMTP id f40-20020a0565123b2800b005030437b14amr5272091lfv.27.1695591711607; Sun, 24 Sep 2023 14:41:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695591711; cv=none; d=google.com; s=arc-20160816; b=XrWUbXavlnBYttBY92lX8CJ2V1kIjwCQ8OK4Vf48kb53bhWMFbwjLZpDEK1NU99bM2 6yo+TqxRQJGSlqRy3A4RL/yy4qc9gVBpFvIB2lB0psvjCOWZ20u45+QHwPXnsoqfUO2Y /EZPVw2pVf6lntr2O7oeMXF39uFVxuLsp7VHKvqEnqQL2KMdLsyCGiStYdxWJ0d6XJVT fXtmH+SCfKWMQN+aBq8mbNCBlEFIwJa/kRzCpOpou4MqMlXBtJgOxp5wifOrK2K7e9uv kIeFVQDALalUhSebbu1/fbMtQeKSM3xvz51WXeMJApwZEXsSDw4uXd9o0XylySAmi7Zg tgPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=l6xCzr2iK8fktKW+t22h83rzhAe1s2UsVfKLi+RDfes=; fh=GLhfC6uSoKlQoQFxk4G3p+HuTS5jYh3P8Z+exisoETw=; b=WN1XCY6jYVtlZPiLc9YrCEBDDmsV3HE0edZAZdK7qF4C4911IXEfzJAQeNAp1CDzRU laMJSuLxVqbqwu2i7iIKczsHIBeEo/DRZtulVHuXboFrg1sJWC8H6rxGvGccBYYyhjnf 9FaE1iTuQMHIQsFi8xpXq08SSlByMTL/upGxVRuHRFMSoNRyQEJwG23DYlVdPCD3roXl b+Ia8rl1eXmr9tGik6eMHgV3qftVZuqgLXFJf2op1NEedZh+ZsgFFsUXy+x2Bki9NuDi wETYAVCRGSdMlLK/QAop6nRbIThHp57Diljq8rpXxR667bMm98NOFdeZYHgzDJDduA9k qvlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VKg9lmlO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w5-20020a056402128500b00530b639af77si7587120edv.394.2023.09.24.14.41.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 14:41:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VKg9lmlO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BD434385DC33 for ; Sun, 24 Sep 2023 21:41:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id BC0793858C66 for ; Sun, 24 Sep 2023 21:40:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC0793858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-690f2719ab2so1336174b3a.0 for ; Sun, 24 Sep 2023 14:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695591655; x=1696196455; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l6xCzr2iK8fktKW+t22h83rzhAe1s2UsVfKLi+RDfes=; b=VKg9lmlO7r8Jmg8UIveKYRlJ/48uQ5LcRbqGn1McyMQAkzslhGcwZcL5J5d8WNF6wu RRWOPYnOa6ikyRp9G5IwoBj08mCLDa9Qy2Hu7+ZRIde6pd3i3xxL8j04vqM3euJEyc65 FmC6fQxpVsS3ceuzFlrshmiqzmfXV70k35cbWB5ZeWVLUkMQFMrpelhOOLnZT3hhqGir yy5naW7P6sFf7L/5ifQE72DPa/f/zc84h9UGWX5MUZY9diB35PopLEBe8WtbAR9eg1S5 y9ArGlByxr3FWnTIAVZveGWS9uTo2S72AwEedQRY0RLmctmVue1ZuHOemy4hnqC4nl8d jlVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695591655; x=1696196455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l6xCzr2iK8fktKW+t22h83rzhAe1s2UsVfKLi+RDfes=; b=XTqU3EV5j+NDjjh7q8FpJKsck2OOjcJvFem05FBdPuD1Wv3gmZE3REa6ToFQp8qNr4 Xttk+N+DTyIIA4MyVDovXXVSgKJJcnHTOY4L/k5vcp9o3AAtNjPXLR/M5zHA8DeSh7c4 d02UsB0eJTJbQ3LPybsaqadFpceu53lOkf9XEFyinCIoCP9HD6+Cb8+D5Y2LJ1Ja+8aR FYaTxNjVDzQ4Ft4Xcr+tQBlP+XOKI5AEnmOG1DxDUEggrdriYBjYAiLjBxgyDy2p8WtZ 1L+Ql4ebTihpO670wY9rEVRJgn4u9Pg34pzVa104h5lGKGYNETMdT2EF3sAkRQhDLSbi HpaA== X-Gm-Message-State: AOJu0Yxn+5oew2pB05GdIL/TYhYJxDFpvs0IaulSz7f/DPIJOIvL9Pc3 FBsBw884XJqjohrgDLw/U2L4Wtci/OSUdcDy X-Received: by 2002:a17:902:e5d1:b0:1c1:fbec:bc3f with SMTP id u17-20020a170902e5d100b001c1fbecbc3fmr6767751plf.5.1695591655480; Sun, 24 Sep 2023 14:40:55 -0700 (PDT) Received: from liushuyu-p15.lan ([2001:56a:fa55:2000:5f51:4954:51e1:8176]) by smtp.gmail.com with ESMTPSA id jc6-20020a17090325c600b001c5de42c185sm1477844plb.253.2023.09.24.14.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 14:40:55 -0700 (PDT) From: Zixing Liu To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw , Zixing Liu Subject: [PATCH v2 1/1] gcc/d: add LoongArch64 support for D frontend Date: Sun, 24 Sep 2023 15:40:33 -0600 Message-ID: <20230924214038.30221-2-liushuyu011@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230924214038.30221-1-liushuyu011@gmail.com> References: <20230924214038.30221-1-liushuyu011@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777956774334918646 X-GMAIL-MSGID: 1777956774334918646 gcc/ChangeLog: * config.gcc: add loongarch-d.o to d_target_objs for LoongArch architecture. gcc/config/ChangeLog: * 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. * loongarch/loongarch-d.h: (loongarch_d_target_versions): add function prototype. (loongarch_d_register_target_info): Likewise. * loongarch/t-loongarch: add object target for loongarch-d.cc. libphobos/ChangeLog: * configure.tgt: enable libphobos for LoongArch architecture. * configure: Regenerate. * libdruntime/gcc/sections/elf.d: add TLS_DTV_OFFSET constant for LoongArch64. * libdruntime/gcc/unwind/generic.d: add __aligned__ constant for LoongArch64. * libdruntime/Makefile.in: Regenerate. Signed-off-by: Zixing Liu --- gcc/config.gcc | 1 + gcc/config/loongarch/loongarch-d.cc | 77 ++++++++++++++++++++++ gcc/config/loongarch/loongarch-d.h | 26 ++++++++ gcc/config/loongarch/t-loongarch | 4 ++ libphobos/configure.tgt | 3 + libphobos/libdruntime/gcc/sections/elf.d | 2 + libphobos/libdruntime/gcc/unwind/generic.d | 1 + 7 files changed, 114 insertions(+) create mode 100644 gcc/config/loongarch/loongarch-d.cc create mode 100644 gcc/config/loongarch/loongarch-d.h diff --git a/gcc/config.gcc b/gcc/config.gcc index ee46d96bf62..782d933b497 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -480,6 +480,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 00000000000..9ac483c39a7 --- /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 +. */ + +#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 00000000000..5ef7bdfa9a0 --- /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 +. */ + +/* 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 9b06fa84bcc..a67af95bf66 100644 --- a/gcc/config/loongarch/t-loongarch +++ b/gcc/config/loongarch/t-loongarch @@ -63,6 +63,10 @@ loongarch-cpu.o: $(srcdir)/config/loongarch/loongarch-cpu.cc $(LA_STR_H) loongarch-def.o: $(srcdir)/config/loongarch/loongarch-def.c $(LA_STR_H) $(CC) -c $(ALL_CFLAGS) $(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 1f21f63620c..6e656c4a351 100644 --- a/libphobos/configure.tgt +++ b/libphobos/configure.tgt @@ -52,6 +52,9 @@ case "${target}" in s390*-linux*) LIBPHOBOS_SUPPORTED=yes ;; + loongarch*-*-linux*) + LIBPHOBOS_SUPPORTED=yes + ;; sparc*-*-solaris2.11*) LIBPHOBOS_SUPPORTED=yes ;; diff --git a/libphobos/libdruntime/gcc/sections/elf.d b/libphobos/libdruntime/gcc/sections/elf.d index 5376957befd..d1316b2915f 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 e4bbb4b01dc..2e74b6319bf 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