From patchwork Tue Sep 5 07:44:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 137482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1522620vqo; Tue, 5 Sep 2023 00:47:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzwqVxxrStoldEleYdAeCc7pR+7psg8t10D9QoBIjBiq6JCr6p90kStEDSbe1Bh7EIhbV2 X-Received: by 2002:a17:907:78c1:b0:9a1:c991:a51c with SMTP id kv1-20020a17090778c100b009a1c991a51cmr8773980ejc.2.1693900052674; Tue, 05 Sep 2023 00:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693900052; cv=none; d=google.com; s=arc-20160816; b=ELYT5K33nZQMGImKvSkgzLbIWMq3xSmeiWl0laAS2pfzTko9CEjYf9nGNeHY0kVNnU 1AAtSST0q/XDzyEOoD9kD/Zg4N8o92aUjXX2Ok2WOeR+lgH07f0nr4tQJ6lXPTvhiMkX R+857y1HwUJT8+9Qv0yHB+BqjTn8T+xgNon31S+LZKx3vLvcboOcFO7K3+65Uc+I6RVL mDBpPEoRrV5Ydmfn9iiG+TPFYauPWEuClsLHUC5uD7gOX2FCCnSb5MjAcggQsCYnEPY6 v+MyP89NVwNHinX4/mXp9FGkhohRGXw+2RCByzuGWmQAvN9gm76kGoyA780VX0sP3NXt rscg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dmarc-filter:delivered-to; bh=Uc34p+EpKiXu4rKhRNcJeNf9wVxgQIENeqTOtkj3AmE=; fh=z1Czm7N8XVhq5qJjafWBUpBTaSinYhfkdyGcUUXhnkM=; b=IjFMslNUMzH32NHqdlfihPPIiRQtg518fHkS/KR8T8Bfl/c8PLypWXViiyu4Z3mKAS YWyKIBZS4G8aCyBAYI1lRkCOz/PkNKYAk8EfRkXtGXuIZH3IyRc49l0TKigMCF0QND/+ 2khuj7tFv7jE18siW25u836NWIKOLpb7AGN3xeC92xxYtH/8JjTTvM9aXJ5d0dLk2WUS sx2qztPfBb+zrpMMa8+ZOPUw7MfWpdorC5LJ+v7AWN5vOpy09pMwgL63EfFrwH++RGlY rh4RCLq1BjOqjtiRENY1oYyYkX37+6L4B2cFs+ok+dEntAc2ISV8pr0pCQKYtLljIBVZ x2nQ== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h22-20020a17090634d600b0099bcb54fae7si7503036ejb.512.2023.09.05.00.47.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 00:47:32 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 198D0383139B for ; Tue, 5 Sep 2023 07:46:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgeu1.qq.com (smtpbgeu1.qq.com [52.59.177.22]) by sourceware.org (Postfix) with ESMTPS id 68C84385842C for ; Tue, 5 Sep 2023 07:45:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68C84385842C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp69t1693899904tnb67ryx Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 05 Sep 2023 15:45:03 +0800 (CST) X-QQ-SSF: 01400000000000C0F000000A0000000 X-QQ-FEAT: 3M0okmaRx3itXpapJGwA5XzQA2uPxXRQjZS13hT3YBjx9tpaEOdx+c3nWb7zW oB3jRpOLSwlensaE3eM+lYsg87qLIftXUedaI5Gya/fdONYzi/2+2RYx1X8UhThoIGfcojJ k1nAFNsFZNm2uiwHwPmB73OqSbx8J8JJjy4aD+6M014Vyz9LWhBaNGx0RaTPaWQjA5ptIcU Zp+1FDgUoxdfZvgIA2li3z8n3aCDDTyvYgjGqn95vvFgG7u9fLcKTavWpWyHwaxD42NNgr5 0AVN+ALh1FJlUW0YOf7AfrwWu/xgWCJD7O6+3Y161G54iIC5fSGfEy31AuhRChq1lys48XV JCoguQU5KZg3mDJC9PEYaiK3siVwTMDfQuHNoX0pwtpfuWRCw3D556ngeZBozcGpZyX/mMZ 2LTXCzS0DFs= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 2335680096996577901 From: Lehua Ding To: gcc-patches@gcc.gnu.org Subject: [PATCH V5 3/3] RISC-V: Part-3: Output .variant_cc directive for vector function Date: Tue, 5 Sep 2023 15:44:52 +0800 Message-Id: <20230905074452.3714603-4-lehua.ding@rivai.ai> X-Mailer: git-send-email 2.36.3 In-Reply-To: <20230905074452.3714603-1-lehua.ding@rivai.ai> References: <20230905074452.3714603-1-lehua.ding@rivai.ai> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz6a-0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, TXREP, T_SPF_HELO_TEMPERROR 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: , Cc: lehua.ding@rivai.ai, kito.cheng@gmail.com, juzhe.zhong@rivai.ai Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776182941956573790 X-GMAIL-MSGID: 1776182941956573790 Functions which follow vector calling convention variant need be annotated by .variant_cc directive according the RISC-V Assembly Programmer's Manual[1] and RISC-V ELF Specification[2]. [1] https://github.com/riscv-non-isa/riscv-asm-manual/blob/master/riscv-asm.md#pseudo-ops [2] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#dynamic-linking gcc/ChangeLog: * config/riscv/riscv-protos.h (riscv_declare_function_name): Add protos. (riscv_asm_output_alias): Ditto. (riscv_asm_output_external): Ditto. * config/riscv/riscv.cc (riscv_asm_output_variant_cc): Output .variant_cc directive for vector function. (riscv_declare_function_name): Ditto. (riscv_asm_output_alias): Ditto. (riscv_asm_output_external): Ditto. * config/riscv/riscv.h (ASM_DECLARE_FUNCTION_NAME): Implement ASM_DECLARE_FUNCTION_NAME. (ASM_OUTPUT_DEF_FROM_DECLS): Implement ASM_OUTPUT_DEF_FROM_DECLS. (ASM_OUTPUT_EXTERNAL): Implement ASM_OUTPUT_EXTERNAL. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/abi-call-variant_cc.c: New test. --- gcc/config/riscv/riscv-protos.h | 3 ++ gcc/config/riscv/riscv.cc | 48 +++++++++++++++++++ gcc/config/riscv/riscv.h | 15 ++++++ .../riscv/rvv/base/abi-call-variant_cc.c | 39 +++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/abi-call-variant_cc.c diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 970d5a899f6..5885ef78218 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -102,6 +102,9 @@ extern bool riscv_split_64bit_move_p (rtx, rtx); extern void riscv_split_doubleword_move (rtx, rtx); extern const char *riscv_output_move (rtx, rtx); extern const char *riscv_output_return (); +extern void riscv_declare_function_name (FILE *, const char *, tree); +extern void riscv_asm_output_alias (FILE *, const tree, const tree); +extern void riscv_asm_output_external (FILE *, const tree, const char *); extern bool riscv_zcmp_valid_stack_adj_bytes_p (HOST_WIDE_INT, int); diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 41c9941de65..dabb341a571 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -7718,6 +7718,54 @@ riscv_emit_attribute () riscv_stack_boundary / 8); } +/* Output .variant_cc for function symbol which follows vector calling + convention. */ + +static void +riscv_asm_output_variant_cc (FILE *stream, const tree decl, const char *name) +{ + if (TREE_CODE (decl) == FUNCTION_DECL) + { + riscv_cc cc = (riscv_cc) fndecl_abi (decl).id (); + if (cc == RISCV_CC_V) + { + fprintf (stream, "\t.variant_cc\t"); + assemble_name (stream, name); + fprintf (stream, "\n"); + } + } +} + +/* Implement ASM_DECLARE_FUNCTION_NAME. */ + +void +riscv_declare_function_name (FILE *stream, const char *name, tree fndecl) +{ + riscv_asm_output_variant_cc (stream, fndecl, name); + ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "function"); + ASM_OUTPUT_LABEL (stream, name); +} + +/* Implement ASM_OUTPUT_DEF_FROM_DECLS. */ + +void +riscv_asm_output_alias (FILE *stream, const tree decl, const tree target) +{ + const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); + const char *value = IDENTIFIER_POINTER (target); + riscv_asm_output_variant_cc (stream, decl, name); + ASM_OUTPUT_DEF (stream, name, value); +} + +/* Implement ASM_OUTPUT_EXTERNAL. */ + +void +riscv_asm_output_external (FILE *stream, tree decl, const char *name) +{ + default_elf_asm_output_external (stream, decl, name); + riscv_asm_output_variant_cc (stream, decl, name); +} + /* Implement TARGET_ASM_FILE_START. */ static void diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 68be4f37b9d..7ac78847b3a 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -1049,6 +1049,21 @@ while (0) #define ASM_COMMENT_START "#" +/* Add output .variant_cc directive for specific function definition. */ +#undef ASM_DECLARE_FUNCTION_NAME +#define ASM_DECLARE_FUNCTION_NAME(STR, NAME, DECL) \ + riscv_declare_function_name (STR, NAME, DECL) + +/* Add output .variant_cc directive for specific alias definition. */ +#undef ASM_OUTPUT_DEF_FROM_DECLS +#define ASM_OUTPUT_DEF_FROM_DECLS(STR, DECL, TARGET) \ + riscv_asm_output_alias (STR, DECL, TARGET) + +/* Add output .variant_cc directive for specific extern function. */ +#undef ASM_OUTPUT_EXTERNAL +#define ASM_OUTPUT_EXTERNAL(STR, DECL, NAME) \ + riscv_asm_output_external (STR, DECL, NAME) + #undef SIZE_TYPE #define SIZE_TYPE (POINTER_SIZE == 64 ? "long unsigned int" : "unsigned int") diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/abi-call-variant_cc.c b/gcc/testsuite/gcc.target/riscv/rvv/base/abi-call-variant_cc.c new file mode 100644 index 00000000000..4e45203f5b5 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/abi-call-variant_cc.c @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 --param=riscv-vector-abi -Wno-psabi" } */ + +#include "riscv_vector.h" + +void +f_undef1 (vint8m1_t a); +void +f_undef2 (vint8m1x8_t a); +void +f_undef3 (vbool1_t a); +vint8m1_t +f_undef4 (); + +void +bar_real (vint8m1_t a, vint8m1x8_t b, vbool1_t c) +{ + f_undef1 (a); + f_undef2 (b); + f_undef3 (c); +} + +__attribute__ ((alias ("bar_real"))) void +bar_alias (vint8m1_t a, vint8m1x8_t b, vbool1_t c); + +void +f_1 (vint8m1_t *a, vint8m1x8_t *b, vbool1_t *c) +{ + bar_alias (*a, *b, *c); + *a = f_undef4 (); +} + +/* { dg-final { scan-assembler-times {\.variant_cc\tbar_real} 1 } } */ +/* { dg-final { scan-assembler-times {\.variant_cc\tbar_alias} 1 } } */ +/* { dg-final { scan-assembler-times {\.variant_cc\tf_1} 0 } } */ +/* { dg-final { scan-assembler-times {\.variant_cc\tf_undef1} 1 } } */ +/* { dg-final { scan-assembler-times {\.variant_cc\tf_undef2} 1 } } */ +/* { dg-final { scan-assembler-times {\.variant_cc\tf_undef3} 1 } } */ +/* { dg-final { scan-assembler-times {\.variant_cc\tf_undef4} 1 } } */