From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x934.google.com (mail-ua1-x934.google.com [IPv6:2607:f8b0:4864:20::934]) by sourceware.org (Postfix) with ESMTPS id 62E2F3858D33 for ; Thu, 27 Apr 2023 15:41:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 62E2F3858D33 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-ua1-x934.google.com with SMTP id a1e0cc1a2514c-77aad9ad986so4269409241.0 for ; Thu, 27 Apr 2023 08:41:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682610114; x=1685202114; 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=bTHC1QeTnq9GIrJQKm9ZzqRUYE1G0TxKJ3qp6C7AQHc=; b=EK7EnkWFeazQcPfyZPkFGU5pAq2kKiRK8rIXnyn11J+L5nEKA+04nA1Aa/m8uxNfYf WqbXNCdp2ti0emReWp64RJcN4z15M6v6wUeAZG+F/kGrc31nPCIe0Ug71iIQ9JU8vj0R jxJQhFTJoEt5hQcA5LGWf9+rwekky3+79g78nEOMnx1nyxxgPZh3un3iXBwd3S6O8yGZ Chf6nGYlYBCTOMnY6c43BZnvGthqMsmOLO1lG0T3sUk/bzWIN+T4n5bPOLkYTvC8rJAq qsAVDriQ6w90UdFzqLhEbi8pXyZ53kK7EcVpdlDfosU9iDrAcTV+p3Jwo3w68PDSBhcQ N6rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682610114; x=1685202114; 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=bTHC1QeTnq9GIrJQKm9ZzqRUYE1G0TxKJ3qp6C7AQHc=; b=h7W9QXKWdqWNRHPXyONHwLAU3o2vU8hoUbe/Oo4zFzV7LbMb/ZjrqJzXs0myiogfMD R1ujw4ttWz0A37v2ibRJ99rXh+ZmEP+OdZPbfpyAJcIAqFiEXA5TXKVCkZe7rx2lhQ0D 30R7V8y0/B1MerMqw2QD5QBO4NEsAkBJdPuIzMDussEsTXuYtab21kHion0XzXK8aitI 2gAxZxYHAazjaU8MVCggvgFlA387tmz/GKYT5mG39xh7toFRw2ZQYo3m9YIloLne5vuc iak4esN/wgclbwmXaI+BovraSzF16dja39LrWneIQkTEQY/P303kfE8lho4iiZduypZF e32w== X-Gm-Message-State: AC+VfDylpKWtVSQu/x+b8PXn2KOOkCl8Ov9+yYeoyl4jD13yur8Q7qSL LCfaCZHxSWSHz+waC3f7ZeKz1wziAVkvLhw/GM8= X-Google-Smtp-Source: ACHHUZ4/4OCRRrBa0els/htiaPRB1NHmxM8vI9N/bGdtJmqrp5f0eJVCvzuhBRwwpXi1QWCnTWNQMYj5WNj/3CscRlM= X-Received: by 2002:a67:cb12:0:b0:42e:28b2:aa99 with SMTP id b18-20020a67cb12000000b0042e28b2aa99mr2416662vsl.14.1682610114230; Thu, 27 Apr 2023 08:41:54 -0700 (PDT) MIME-Version: 1.0 References: <20230426123743.3210243-1-yanzhang.wang@intel.com> <20230427031242.662721-1-yanzhang.wang@intel.com> In-Reply-To: <20230427031242.662721-1-yanzhang.wang@intel.com> From: Kito Cheng Date: Thu, 27 Apr 2023 23:41:43 +0800 Message-ID: Subject: Re: [PATCH v3] RISCV: Add vector psabi checking. To: yanzhang.wang@intel.com Cc: gcc-patches@gcc.gnu.org, juzhe.zhong@rivai.ai, kito.cheng@sifive.com, pan2.li@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.8 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: Ooops, I found that it also warns on intrinsic functions, could you try to find some way to exclude that? e.g. #include "riscv_vector.h" void foo(int32_t *in1, int32_t *in2, int32_t *in3, int32_t *out, size_t n, int cond) { size_t vl; if (cond) vl =3D __riscv_vsetvlmax_e32m1(); else vl =3D __riscv_vsetvlmax_e16mf2(); for (size_t i =3D 0; i < n; i +=3D 1) { vint32m1_t a =3D __riscv_vle32_v_i32m1(in1, vl); // warning: ABI for the scalable vector type is currently in experimental stage and may changes in the upcoming version of GCC. [-Wpsabi] vint32m1_t b =3D __riscv_vle32_v_i32m1_tu(a, in2, vl); vint32m1_t c =3D __riscv_vle32_v_i32m1_tu(b, in3, vl); __riscv_vse32_v_i32m1(out, c, vl); } } On Thu, Apr 27, 2023 at 11:13=E2=80=AFAM yanzhang.wang--- via Gcc-patches wrote: > > From: Yanzhang Wang > > This patch adds support to check function's argument or return is vector = type > and throw warning if yes. > > gcc/ChangeLog: > > * config/riscv/riscv.cc: > (riscv_scalable_vector_type_p): Determine whether the type is sca= lable vector. > (riscv_arg_has_vector): Determine whether the arg is vector type. > (riscv_pass_in_vector_p): Check the vector type param is passed b= y value. > (riscv_get_arg_info): Add the checking. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/vector-abi-1.c: New test. > * gcc.target/riscv/vector-abi-2.c: New test. > * gcc.target/riscv/vector-abi-3.c: New test. > * gcc.target/riscv/vector-abi-4.c: New test. > * gcc.target/riscv/vector-abi-5.c: New test. > > Signed-off-by: Yanzhang Wang > Co-authored-by: Kito Cheng > --- > gcc/config/riscv/riscv.cc | 73 +++++++++++++++++++ > gcc/testsuite/gcc.target/riscv/vector-abi-1.c | 14 ++++ > gcc/testsuite/gcc.target/riscv/vector-abi-2.c | 14 ++++ > gcc/testsuite/gcc.target/riscv/vector-abi-3.c | 14 ++++ > gcc/testsuite/gcc.target/riscv/vector-abi-4.c | 16 ++++ > gcc/testsuite/gcc.target/riscv/vector-abi-5.c | 15 ++++ > 6 files changed, 146 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/riscv/vector-abi-1.c > create mode 100644 gcc/testsuite/gcc.target/riscv/vector-abi-2.c > create mode 100644 gcc/testsuite/gcc.target/riscv/vector-abi-3.c > create mode 100644 gcc/testsuite/gcc.target/riscv/vector-abi-4.c > create mode 100644 gcc/testsuite/gcc.target/riscv/vector-abi-5.c > > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc > index 76eee4a55e9..06e9fe7d924 100644 > --- a/gcc/config/riscv/riscv.cc > +++ b/gcc/config/riscv/riscv.cc > @@ -3728,6 +3728,76 @@ riscv_pass_fpr_pair (machine_mode mode, unsigned r= egno1, > GEN_INT (offset2)))); > } > > +/* Use the TYPE_SIZE to distinguish the type with vector_size attribute = and > + intrinsic vector type. Because we can't get the decl for the params.= */ > + > +static bool > +riscv_scalable_vector_type_p (const_tree type) > +{ > + tree size =3D TYPE_SIZE (type); > + if (size && TREE_CODE (size) =3D=3D INTEGER_CST) > + return false; > + > + /* For the data type like vint32m1_t, the size code is POLY_INT_CST. = */ > + return true; > +} > + > +static bool > +riscv_arg_has_vector (const_tree type) > +{ > + bool is_vector =3D false; > + > + switch (TREE_CODE (type)) > + { > + case RECORD_TYPE: > + if (!COMPLETE_TYPE_P (type)) > + break; > + > + for (tree f =3D TYPE_FIELDS (type); f; f =3D DECL_CHAIN (f)) > + if (TREE_CODE (f) =3D=3D FIELD_DECL) > + { > + tree field_type =3D TREE_TYPE (f); > + if (!TYPE_P (field_type)) > + break; > + > + /* Ignore it if it's fixed length vector. */ > + if (VECTOR_TYPE_P (field_type)) > + is_vector =3D riscv_scalable_vector_type_p (field_type); > + else > + is_vector =3D riscv_arg_has_vector (field_type); > + } > + > + break; > + > + case VECTOR_TYPE: > + is_vector =3D riscv_scalable_vector_type_p (type); > + break; > + > + default: > + is_vector =3D false; > + break; > + } > + > + return is_vector; > +} > + > +/* Pass the type to check whether it's a vector type or contains vector = type. > + Only check the value type and no checking for vector pointer type. *= / > + > +static void > +riscv_pass_in_vector_p (const_tree type) > +{ > + static int warned =3D 0; > + > + if (type && riscv_arg_has_vector (type) && !warned) > + { > + warning (OPT_Wpsabi, "ABI for the scalable vector type is currentl= y in " > + "experimental stage and may changes in the upcoming versio= n of " > + "GCC."); > + warned =3D 1; > + } > +} > + > /* Fill INFO with information about a single argument, and return an > RTL pattern to pass or return the argument. CUM is the cumulative > state for earlier arguments. MODE is the mode of this argument and > @@ -3812,6 +3882,9 @@ riscv_get_arg_info (struct riscv_arg_info *info, co= nst CUMULATIVE_ARGS *cum, > } > } > > + /* Only check existing of vector type. */ > + riscv_pass_in_vector_p (type); > + > /* Work out the size of the argument. */ > num_bytes =3D type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode).t= o_constant (); > num_words =3D (num_bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; > diff --git a/gcc/testsuite/gcc.target/riscv/vector-abi-1.c b/gcc/testsuit= e/gcc.target/riscv/vector-abi-1.c > new file mode 100644 > index 00000000000..969f14277a4 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/vector-abi-1.c > @@ -0,0 +1,14 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O0 -march=3Drv64gcv -mabi=3Dlp64d" } */ > + > +#include "riscv_vector.h" > + > +void > +fun (vint32m1_t a) { } /* { dg-warning "the scalable vector type" } */ > + > +void > +bar () > +{ > + vint32m1_t a; > + fun (a); > +} > diff --git a/gcc/testsuite/gcc.target/riscv/vector-abi-2.c b/gcc/testsuit= e/gcc.target/riscv/vector-abi-2.c > new file mode 100644 > index 00000000000..b752760b76f > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/vector-abi-2.c > @@ -0,0 +1,14 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64d" } */ > + > +#include "riscv_vector.h" > + > +vint32m1_t > +fun (vint32m1_t* a) { return *a; } /* { dg-warning "the scalable vecto= r type" } */ > + > +void > +bar () > +{ > + vint32m1_t a; > + fun (&a); > +} > diff --git a/gcc/testsuite/gcc.target/riscv/vector-abi-3.c b/gcc/testsuit= e/gcc.target/riscv/vector-abi-3.c > new file mode 100644 > index 00000000000..90ece60cc6f > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/vector-abi-3.c > @@ -0,0 +1,14 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64d" } */ > + > +#include "riscv_vector.h" > + > +vint32m1_t* > +fun (vint32m1_t* a) { return a; } /* { dg-bogus "the scalable vector t= ype" } */ > + > +void > +bar () > +{ > + vint32m1_t a; > + fun (&a); > +} > diff --git a/gcc/testsuite/gcc.target/riscv/vector-abi-4.c b/gcc/testsuit= e/gcc.target/riscv/vector-abi-4.c > new file mode 100644 > index 00000000000..ecf6d4cc26b > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/vector-abi-4.c > @@ -0,0 +1,16 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64d" } */ > + > +#include "riscv_vector.h" > + > +typedef int v4si __attribute__ ((vector_size (16))); > + > +v4si > +fun (v4si a) { return a; } /* { dg-bogus "the scalable vector type" } = */ > + > +void > +bar () > +{ > + v4si a; > + fun (a); > +} > diff --git a/gcc/testsuite/gcc.target/riscv/vector-abi-5.c b/gcc/testsuit= e/gcc.target/riscv/vector-abi-5.c > new file mode 100644 > index 00000000000..6053e0783b6 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/vector-abi-5.c > @@ -0,0 +1,15 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64d" } */ > + > +typedef int v4si __attribute__ ((vector_size (16))); > +struct A { int a; v4si b; }; > + > +void > +fun (struct A a) {} /* { dg-bogus "the scalable vector type" } */ > + > +void > +bar () > +{ > + struct A a; > + fun (a); > +} > -- > 2.40.0 >