Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 2c68135

Browse files
Yanzhang Wangkito-cheng
andcommitted
RISCV: Add vector psabi checking.
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_vector_psabi_warnning): (riscv_arg_has_vector): (riscv_pass_in_vector_p): (riscv_get_arg_info): 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 <yanzhang.wang@intel.com> Co-authored-by: Kito Cheng <kito.cheng@sifive.com>
1 parent ec92be4 commit 2c68135

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed

gcc/config/riscv/riscv.cc

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,6 +3728,65 @@ riscv_pass_fpr_pair (machine_mode mode, unsigned regno1,
37283728
GEN_INT (offset2))));
37293729
}
37303730

3731+
static void
3732+
riscv_vector_psabi_warnning ()
3733+
{
3734+
warning (OPT_Wpsabi, "ABI for the vector type is currently in experimental"
3735+
"stage and may changes in the upcoming version of GCC.");
3736+
}
3737+
3738+
static bool
3739+
riscv_arg_has_vector (const_tree type)
3740+
{
3741+
bool is_vector = false;
3742+
3743+
switch (TREE_CODE (type))
3744+
{
3745+
case RECORD_TYPE:
3746+
if (!COMPLETE_TYPE_P (type))
3747+
break;
3748+
3749+
for (tree f = TYPE_FIELDS (type); f; f = DECL_CHAIN (f))
3750+
if (TREE_CODE (f) == FIELD_DECL)
3751+
{
3752+
if (!TYPE_P (TREE_TYPE (f)))
3753+
break;
3754+
3755+
if (VECTOR_TYPE_P (type))
3756+
is_vector = true;
3757+
else
3758+
is_vector = riscv_arg_has_vector (TREE_TYPE (f));
3759+
}
3760+
3761+
break;
3762+
3763+
case VECTOR_TYPE:
3764+
is_vector = true;
3765+
break;
3766+
3767+
default:
3768+
is_vector = false;
3769+
break;
3770+
}
3771+
3772+
return is_vector;
3773+
}
3774+
3775+
/* Pass the type to check whether it's a vector type or contains vector type.
3776+
Only check the value type and no checking for vector pointer type. */
3777+
3778+
static void
3779+
riscv_pass_in_vector_p (const_tree type)
3780+
{
3781+
static int warned = 0;
3782+
3783+
if (type && riscv_arg_has_vector (type) && !warned)
3784+
{
3785+
riscv_vector_psabi_warnning ();
3786+
warned = 1;
3787+
}
3788+
}
3789+
37313790
/* Fill INFO with information about a single argument, and return an
37323791
RTL pattern to pass or return the argument. CUM is the cumulative
37333792
state for earlier arguments. MODE is the mode of this argument and
@@ -3812,6 +3871,9 @@ riscv_get_arg_info (struct riscv_arg_info *info, const CUMULATIVE_ARGS *cum,
38123871
}
38133872
}
38143873

3874+
/* Only check existing of vector type. */
3875+
riscv_pass_in_vector_p (type);
3876+
38153877
/* Work out the size of the argument. */
38163878
num_bytes = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode).to_constant ();
38173879
num_words = (num_bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O0 -march=rv64gcv -mabi=lp64d" } */
3+
4+
#include "riscv_vector.h"
5+
6+
void
7+
fun (vint32m1_t a) { } /* { dg-warning "the vector type" } */
8+
9+
void
10+
bar ()
11+
{
12+
vint32m1_t a;
13+
fun (a);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-march=rv64gcv -mabi=lp64d" } */
3+
4+
#include "riscv_vector.h"
5+
6+
vint32m1_t
7+
fun (vint32m1_t* a) { return *a; } /* { dg-warning "the vector type" } */
8+
9+
void
10+
bar ()
11+
{
12+
vint32m1_t a;
13+
fun (&a);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-march=rv64gcv -mabi=lp64d" } */
3+
4+
#include "riscv_vector.h"
5+
6+
vint32m1_t*
7+
fun (vint32m1_t* a) { return a; } /* { dg-bogus "the vector type" } */
8+
9+
void
10+
bar ()
11+
{
12+
vint32m1_t a;
13+
fun (&a);
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-march=rv64gcv -mabi=lp64d" } */
3+
4+
#include "riscv_vector.h"
5+
6+
typedef int v4si __attribute__ ((vector_size (16)));
7+
8+
v4si
9+
fun (v4si a) { return a; } /* { dg-warning "the vector type" } */
10+
11+
void
12+
bar ()
13+
{
14+
v4si a;
15+
fun (a);
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-march=rv64gcv -mabi=lp64d" } */
3+
4+
#include "riscv_vector.h"
5+
typedef int v4si __attribute__ ((vector_size (16)));
6+
7+
v4si*
8+
fun (v4si* a) { return a; } /* { dg-bogus "the vector type" } */
9+
10+
void
11+
bar ()
12+
{
13+
v4si a;
14+
fun (&a);
15+
}

0 commit comments

Comments
 (0)