From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 13F6D385840A for ; Fri, 1 Mar 2024 09:22:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13F6D385840A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 13F6D385840A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709284949; cv=none; b=U3Nvhg+ly3upQt1+VIyEFTE0hR0JoHDKoWPstRq3zYq3rGQOd0NIxiQrhNPlKH3tFoIh/U9foXu3YDosJHwYt//DC7VR2dR42XJ3KmLMaBAYjLHLEjway/uclinMgHfwHKzoT++9dAbNFMpDRriGGkP0FAlGNsdQEvDBr03FxiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709284949; c=relaxed/simple; bh=Sx3gGEciKH7WAjg5KnTXBYs6LDajQWBrB/exJ4MUHNI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=QmZDIe26C5eLrmJIUzsR4hze6jMs4zHQKR6lgBmeRFElPj4cmWA08nYoKGzSxsHqxQucqUSNc2Hb4UcDY+NooYr+n4d2UTU6399lqR2W4zP3OXWxABTtQWWyYQMPNxvScp8uJKUiq7rytLguSHz5zDEc6OlfBvVUy3t8Akze/IM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a441882f276so260387966b.2 for ; Fri, 01 Mar 2024 01:22:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709284942; x=1709889742; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bOuSPLpc4QRpZ52Ra5lKP1NuP5weeyYSwa7lC3jCYnY=; b=b0neAzdLuqWEM5YEJohW5lfWvGxJnVcOF+eGB3gktz2haTdlnHW5nxadFr9MGIODS8 C/5WWI8htzCXK1+y9h+ORcNWyqvFNcYW9WvxzA2GJzZFQ/UIKuOyvXBav0IbEL1mg6Yt T3VOvKAs/iq9NZ7sQNYcqBTw6DHqfjNuLYxzZW6Os5KjlQj2mH5iuC8ywaZTVsC/pf/i 18BovyWcvc57akDy6c0yvFCGodbNgglCl1JqwydNIw6wAifL1h6upGw5FItoPMDQn8LJ D1kArd7srTnV8JkuXeWIpIlGJH/CZvNnd+noGtSpl3AuhWsVyVa1o4zDep1xxGFMBHqR LDfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709284942; x=1709889742; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bOuSPLpc4QRpZ52Ra5lKP1NuP5weeyYSwa7lC3jCYnY=; b=R9/Cgs14IskS/tWTkDEDraOphU6+aZERvPJyRmHKv2zEBkIVIUDXdvBq/LL0u9X/Do UPciFNew5Sbo/QHw22sTin3lLWyRH2Ur4jWYGWpCqz5IqmieAg5reEpUFEhokzRlDdLr dLLwMjifFxE0fA5Y85KkiIWQFW1Qk0TU0Er4KkxW27j+IAszNCtxM39+hc151DSEVsEK /ncSkEfkxdTc7VcfY2Rvc5TDJA8W6RtN6kt4QQf1oW6hQRWj4FMrxtSdc6jVTtL/D+fP MsSnO5UpGksW+kMuWGENMIQD/GWOBanAHBGKVBH0wVnWJmjQfKgd4WmlSvPWArqF5W63 UWlA== X-Gm-Message-State: AOJu0YwcfIj1EScgS562gHFeXTDBv4gAiGwDu7OFzRSdNvuTvcfZH+W/ FRtAqTEaFvUa+Ndi2rGjYKDmxn1KnRzH+wC9TuAhsj8uFRQJRtCj2BkJ+dXIGuZ7h+ZTpqgsAgw 3eQi4mOl+Fqi9q+m1eCrzr5/OUjWCJ2oCrSJPQA== X-Google-Smtp-Source: AGHT+IGNijT2ccsOgbYVXUM68vBaAh1Jxik8JhiXhN5eu2Aq3pAXeSYdggyR+MJQOHmwBPVNLuyvtLWN4LkK2Wg6nOM= X-Received: by 2002:a17:906:830c:b0:a3e:dcd2:2746 with SMTP id j12-20020a170906830c00b00a3edcd22746mr843646ejx.3.1709284941363; Fri, 01 Mar 2024 01:22:21 -0800 (PST) MIME-Version: 1.0 References: <20240301091012.26986-1-xuli1@eswincomputing.com> In-Reply-To: <20240301091012.26986-1-xuli1@eswincomputing.com> From: Kito Cheng Date: Fri, 1 Mar 2024 17:22:09 +0800 Message-ID: Subject: Re: [PATCH v2] RISC-V: Add riscv_vector_cc function attribute To: Li Xu Cc: gcc-patches@gcc.gnu.org, palmer@dabbelt.com, juzhe.zhong@rivai.ai Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: LGTM, thanks :) On Fri, Mar 1, 2024 at 5:10=E2=80=AFPM Li Xu wro= te: > > From: xuli > > Standard vector calling convention variant will only enabled when functio= n > has vector argument or returning value by default, however user may also > want to invoke function without that during a vectorized loop at some sit= uation, > but it will cause a huge performance penalty due to vector register store= /restore. > > So user can declare function with this riscv_vector_cc attribute like bel= ow, that could enforce > function will use standard vector calling convention variant. > > void foo() __attribute__((riscv_vector_cc)); > [[riscv::vector_cc]] void foo(); // For C++11 and C23 > > For more details please reference the below link. > https://github.com/riscv-non-isa/riscv-c-api-doc/pull/67 > > gcc/ChangeLog: > > * config/riscv/riscv.cc (TARGET_GNU_ATTRIBUTES): Add riscv_vector= _cc > attribute to riscv_attribute_table. > (riscv_vector_cc_function_p): Return true if FUNC is a riscv_vect= or_cc function. > (riscv_fntype_abi): Add riscv_vector_cc attribute check. > * doc/extend.texi: Add riscv_vector_cc attribute description. > > gcc/testsuite/ChangeLog: > > * g++.target/riscv/rvv/base/attribute-riscv_vector_cc-error.C: Ne= w test. > * gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-callee-save= d.c: New test. > * gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-error.c: Ne= w test. > --- > gcc/config/riscv/riscv.cc | 55 ++++++++++++++++--- > gcc/doc/extend.texi | 10 ++++ > .../base/attribute-riscv_vector_cc-error.C | 21 +++++++ > .../attribute-riscv_vector_cc-callee-saved.c | 30 ++++++++++ > .../base/attribute-riscv_vector_cc-error.c | 11 ++++ > 5 files changed, 119 insertions(+), 8 deletions(-) > create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/attribute-ris= cv_vector_cc-error.C > create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/attribute-ris= cv_vector_cc-callee-saved.c > create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/attribute-ris= cv_vector_cc-error.c > > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc > index 4100abc9dd1..7f37f231796 100644 > --- a/gcc/config/riscv/riscv.cc > +++ b/gcc/config/riscv/riscv.cc > @@ -537,24 +537,52 @@ static tree riscv_handle_fndecl_attribute (tree *, = tree, tree, int, bool *); > static tree riscv_handle_type_attribute (tree *, tree, tree, int, bool *= ); > > /* Defining target-specific uses of __attribute__. */ > -TARGET_GNU_ATTRIBUTES (riscv_attribute_table, > +static const attribute_spec riscv_gnu_attributes[] =3D > { > /* Syntax: { name, min_len, max_len, decl_required, type_required, > function_type_required, affects_type_identity, handler, > exclude } */ > > /* The attribute telling no prologue/epilogue. */ > - { "naked", 0, 0, true, false, false, false, > - riscv_handle_fndecl_attribute, NULL }, > + {"naked", 0, 0, true, false, false, false, riscv_handle_fndecl_attribu= te, > + NULL}, > /* This attribute generates prologue/epilogue for interrupt handlers. = */ > - { "interrupt", 0, 1, false, true, true, false, > - riscv_handle_type_attribute, NULL }, > + {"interrupt", 0, 1, false, true, true, false, riscv_handle_type_attrib= ute, > + NULL}, > > /* The following two are used for the built-in properties of the Vecto= r type > and are not used externally */ > {"RVV sizeless type", 4, 4, false, true, false, true, NULL, NULL}, > - {"RVV type", 0, 0, false, true, false, true, NULL, NULL} > -}); > + {"RVV type", 0, 0, false, true, false, true, NULL, NULL}, > + /* This attribute is used to declare a function, forcing it to use the > + standard vector calling convention variant. Syntax: > + __attribute__((riscv_vector_cc)). */ > + {"riscv_vector_cc", 0, 0, false, true, true, true, NULL, NULL} > +}; > + > +static const scoped_attribute_specs riscv_gnu_attribute_table =3D > +{ > + "gnu", {riscv_gnu_attributes} > +}; > + > +static const attribute_spec riscv_attributes[] =3D > +{ > + /* This attribute is used to declare a function, forcing it to use the > + standard vector calling convention variant. Syntax: > + [[riscv::vector_cc]]. */ > + {"vector_cc", 0, 0, false, true, true, true, NULL, NULL} > +}; > + > +static const scoped_attribute_specs riscv_nongnu_attribute_table =3D > +{ > + "riscv", {riscv_attributes} > +}; > + > +static const scoped_attribute_specs *const riscv_attribute_table[] =3D > +{ > + &riscv_gnu_attribute_table, > + &riscv_nongnu_attribute_table > +}; > > /* Order for the CLOBBERs/USEs of gpr_save. */ > static const unsigned gpr_save_reg_order[] =3D { > @@ -5425,6 +5453,16 @@ riscv_arguments_is_vector_type_p (const_tree fntyp= e) > return false; > } > > +/* Return true if FUNC is a riscv_vector_cc function. > + For more details please reference the below link. > + https://github.com/riscv-non-isa/riscv-c-api-doc/pull/67 */ > +static bool > +riscv_vector_cc_function_p (const_tree fntype) > +{ > + return lookup_attribute ("vector_cc", TYPE_ATTRIBUTES (fntype)) !=3D N= ULL_TREE > + || lookup_attribute ("riscv_vector_cc", TYPE_ATTRIBUTES (fntype)= ) !=3D NULL_TREE; > +} > + > /* Implement TARGET_FNTYPE_ABI. */ > > static const predefined_function_abi & > @@ -5434,7 +5472,8 @@ riscv_fntype_abi (const_tree fntype) > reference the below link. > https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/389 */ > if (riscv_return_value_is_vector_type_p (fntype) > - || riscv_arguments_is_vector_type_p (fntype)) > + || riscv_arguments_is_vector_type_p (fntype) > + || riscv_vector_cc_function_p (fntype)) > return riscv_v_abi (); > > return default_function_abi; > diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi > index 2135dfde9c8..bc8126d2840 100644 > --- a/gcc/doc/extend.texi > +++ b/gcc/doc/extend.texi > @@ -6314,6 +6314,16 @@ Permissible values for this parameter are @code{us= er}, @code{supervisor}, > and @code{machine}. If there is no parameter, then it defaults to > @code{machine}. > > +@cindex @code{riscv_vector_cc} function attribute, RISC-V > +@item riscv_vector_cc > +Use this attribute to force the function to use the vector calling > +convention variant. > + > +@smallexample > +void foo() __attribute__((riscv_vector_cc)); > +[[riscv::vector_cc]] void foo(); // For C++11 and C23 > +@end smallexample > + > @end table > > The following target-specific function attributes are available for the > diff --git a/gcc/testsuite/g++.target/riscv/rvv/base/attribute-riscv_vect= or_cc-error.C b/gcc/testsuite/g++.target/riscv/rvv/base/attribute-riscv_vec= tor_cc-error.C > new file mode 100644 > index 00000000000..63a353bebd0 > --- /dev/null > +++ b/gcc/testsuite/g++.target/riscv/rvv/base/attribute-riscv_vector_cc-e= rror.C > @@ -0,0 +1,21 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64d -O1" } */ > + > +[[riscv::vector_cc]] void foo();// For C++11 and C23 > + > +[[riscv::vector_cc]] int var; /* { dg-warning "'vector_cc' attribute onl= y applies to function types" } */ > + > +void __attribute__((riscv_vector_cc)) func(); > +void __attribute__((riscv_vector_cc(1))) func_invalid(); /* { dg-error "= wrong number of arguments specified for 'riscv_vector_cc' attribute" } */ > + > +void test_no_attribute(int); > +void __attribute__((riscv_vector_cc)) test_no_attribute(int x) { } > + > +class test_cc { > + __attribute__((riscv_vector_cc)) void member_func(); > +}; > + > +void test_lambda() { > + __attribute__((riscv_vector_cc)) auto lambda =3D []() { /* { dg-warni= ng "'riscv_vector_cc' attribute only applies to function types" } */ > + }; > +} > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vect= or_cc-callee-saved.c b/gcc/testsuite/gcc.target/riscv/rvv/base/attribute-ri= scv_vector_cc-callee-saved.c > new file mode 100644 > index 00000000000..b47ecb3b828 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-c= allee-saved.c > @@ -0,0 +1,30 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64d" } */ > + > +void __attribute__((riscv_vector_cc)) bar1 (int a); > +void bar2 (); > + > +void __attribute__((riscv_vector_cc)) > +foo1 (int a) > +{ > + bar1 (a); > +} > + > +void __attribute__((riscv_vector_cc)) > +foo2 (int a) > +{ > + char data[1024]; > + bar2 (); > +} > + > +void > +foo3 (int *a) > +{ > + bar1 (*a); > +} > + > +/* { dg-final { scan-assembler-not {\.variant_cc\tbar2} } } */ > +/* { dg-final { scan-assembler-not {\.variant_cc\tfoo3} } } */ > +/* { dg-final { scan-assembler-times {\.variant_cc\tbar1} 1 } } */ > +/* { dg-final { scan-assembler-times {\.variant_cc\tfoo1} 1 } } */ > +/* { dg-final { scan-assembler-times {\.variant_cc\tfoo2} 1 } } */ > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vect= or_cc-error.c b/gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vec= tor_cc-error.c > new file mode 100644 > index 00000000000..ceb5e5bf6dd > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/attribute-riscv_vector_cc-e= rror.c > @@ -0,0 +1,11 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64d -O1" } */ > + > +__attribute__((riscv_vector_cc)) int var; /* { dg-warning "'riscv_vector= _cc' attribute only applies to function types" } */ > +[[riscv::vector_cc]] int var1; /* { dg-warning "'vector_cc' attribute on= ly applies to function types" } */ > + > +void __attribute__((riscv_vector_cc)) func(); > +void __attribute__((riscv_vector_cc(1))) func_invalid(); /* { dg-error "= wrong number of arguments specified for 'riscv_vector_cc' attribute" } */ > + > +void test_no_attribute(int); > +void __attribute__((riscv_vector_cc)) test_no_attribute(int x) { } > -- > 2.17.1 >