From patchwork Thu Aug 31 12:26:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 137290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c792:0:b0:3f2:4152:657d with SMTP id b18csp206414vqu; Thu, 31 Aug 2023 05:29:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBeAAf9UbCV4XBbqXQ+22VTIW4z3u8u25KrHzxZvYNtnkUfVl9FJ2PSMNcSx3CFZHIUMY4 X-Received: by 2002:a2e:3813:0:b0:2bc:fd7b:8ded with SMTP id f19-20020a2e3813000000b002bcfd7b8dedmr4417434lja.20.1693484942135; Thu, 31 Aug 2023 05:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693484942; cv=none; d=google.com; s=arc-20160816; b=xL9w4xUcdMZcbrUoqHLMhVYV4w1OwJU6kT9Eh38G94j4FQoV63ea7Kt/yTdrGNuTd1 beUWXwIPBWdIkhqTzwROrbBJioOaBpTffS10JBe7P3cobgX5EQ05eoIX2bIc734uv+8e 8KdCoUhPnfapbL2u72QRS/66USMg0470nUwqcIO+uagbDlKw7ymcjLETgPKm0jQIQdnC cvNZsWy5Fsc05QgTcLrLv2CakGaZ8mFqvgvwTQfEKYDpXOYeGdJRXKCdSHa046QgJx2t latpmNoW6OqkCcROkpJLOyYcxGdQpha9IQJqtpgJqbcCxpc7pXcabuwueN/6EhrAnM3A A4dg== 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=Y++J+R/Oxb0KwCkA0F6n6Ni+VulLChb3DFTN2YMTj/g=; fh=flMKfU26Zf2bCSWDpkELM+XX9P5dENvjDCVykGrzV2k=; b=y2GdEKMM1D0Y4MJy3EM6QAkICi2em7LdY9SUcmk79aHX1AqtFRz3iUv+8MTQsMOJJ5 uo5oONLqJFdtZ66bTeEg979hzTsmnz+Wz2cNozjDIHxTowBkCx4o8LVD+xpaEik6aQs9 kNO6fgGPpeyCjxI4u3OJJeIHGS1vs7teMaLX9l/B+dZnjXVY5cJy+PC0X02pkyPHXunb upIyq/1Iax8gJ5d0HGha6j8VqdS46tYq2B977d/1i2kJT47daeQY9bGQ15G5tyirFmi9 942xG+A30BZMw4F96NoakTipOyHZrgARYCAv9JIG4cvA2DL9mFvRzy1Sy0kwDFvWGiPt UEgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d22-20020a1709067f1600b009a190ce8502si941240ejr.120.2023.08.31.05.29.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 05:29:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 84DB1385734F for ; Thu, 31 Aug 2023 12:27:42 +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 9A5D03858C62 for ; Thu, 31 Aug 2023 12:26:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A5D03858C62 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: bizesmtp86t1693484788tg5kmbq5 Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 31 Aug 2023 20:26:28 +0800 (CST) X-QQ-SSF: 01400000000000C0F000000A0000000 X-QQ-FEAT: zT6n3Y95oi1pCzTu4zZe3GLQoJSGhsLyAFNn8sxb7BIZFg1WMo2v41BwEnTxF QGHqP0AAnkauEuQP1f1OaCwCet4WH59kkpraYqoI5DSBSt6+UV6Iz0h/UCPfphWQiVmq5+a yr4zaBub5KJoHYxJXZ9r6lg6VNQEFh0iNIc+DPBBPA6eL8MackS1IRmG4TqFtGpaCDKIrz0 cYkU0JmzgvdroUpXALyUUUCeRMC/jrufQSdJa6Ciz/JGQuhHe1Bq8syuUBW+ALPlaq3oYkw yBhVvC2o06TgL5nraKc9Ws8sI/JqrCIsdvVCVf78e3Il1Gth/sCql6s1+OcnJwec5LuyYLI P7GAD6ZrgTRWNbetw61hHFpgW5Nyc99o9V2x8C2V4w4K/yZDEd5uOvecJPzZoXiwHYI6koQ zfjxYAMRATU= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 4436514053466529091 From: Lehua Ding To: gcc-patches@gcc.gnu.org Subject: [PATCH V4 3/3] RISC-V: Part-3: Output .variant_cc directive for vector function Date: Thu, 31 Aug 2023 20:26:18 +0800 Message-Id: <20230831122618.3516601-4-lehua.ding@rivai.ai> X-Mailer: git-send-email 2.36.3 In-Reply-To: <20230831122618.3516601-1-lehua.ding@rivai.ai> References: <20230831122618.3516601-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.4 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: 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: 1775747666750912328 X-GMAIL-MSGID: 1775747666750912328 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 3761ff3b86b..5853808694f 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 0605298fcb3..5b9b504d1bc 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -7708,6 +7708,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 222aeec2b24..22a419a44e4 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -1046,6 +1046,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 } } */