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

Commit

Permalink
RISCV: Add vector psabi checking.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Kito Cheng <[email protected]>
  • Loading branch information
Yanzhang Wang and kito-cheng committed Apr 20, 2023
1 parent ec92be4 commit 2c68135
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 0 deletions.
62 changes: 62 additions & 0 deletions gcc/config/riscv/riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3728,6 +3728,65 @@ riscv_pass_fpr_pair (machine_mode mode, unsigned regno1,
GEN_INT (offset2))));
}

static void
riscv_vector_psabi_warnning ()
{
warning (OPT_Wpsabi, "ABI for the vector type is currently in experimental"
"stage and may changes in the upcoming version of GCC.");
}

static bool
riscv_arg_has_vector (const_tree type)
{
bool is_vector = false;

switch (TREE_CODE (type))
{
case RECORD_TYPE:
if (!COMPLETE_TYPE_P (type))
break;

for (tree f = TYPE_FIELDS (type); f; f = DECL_CHAIN (f))
if (TREE_CODE (f) == FIELD_DECL)
{
if (!TYPE_P (TREE_TYPE (f)))
break;

if (VECTOR_TYPE_P (type))
is_vector = true;
else
is_vector = riscv_arg_has_vector (TREE_TYPE (f));
}

break;

case VECTOR_TYPE:
is_vector = true;
break;

default:
is_vector = 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 = 0;

if (type && riscv_arg_has_vector (type) && !warned)
{
riscv_vector_psabi_warnning ();
warned = 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
Expand Down Expand Up @@ -3812,6 +3871,9 @@ riscv_get_arg_info (struct riscv_arg_info *info, const CUMULATIVE_ARGS *cum,
}
}

/* Only check existing of vector type. */
riscv_pass_in_vector_p (type);

/* Work out the size of the argument. */
num_bytes = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode).to_constant ();
num_words = (num_bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
Expand Down
14 changes: 14 additions & 0 deletions gcc/testsuite/gcc.target/riscv/vector-abi-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-O0 -march=rv64gcv -mabi=lp64d" } */

#include "riscv_vector.h"

void
fun (vint32m1_t a) { } /* { dg-warning "the vector type" } */

void
bar ()
{
vint32m1_t a;
fun (a);
}
14 changes: 14 additions & 0 deletions gcc/testsuite/gcc.target/riscv/vector-abi-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-march=rv64gcv -mabi=lp64d" } */

#include "riscv_vector.h"

vint32m1_t
fun (vint32m1_t* a) { return *a; } /* { dg-warning "the vector type" } */

void
bar ()
{
vint32m1_t a;
fun (&a);
}
14 changes: 14 additions & 0 deletions gcc/testsuite/gcc.target/riscv/vector-abi-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-march=rv64gcv -mabi=lp64d" } */

#include "riscv_vector.h"

vint32m1_t*
fun (vint32m1_t* a) { return a; } /* { dg-bogus "the vector type" } */

void
bar ()
{
vint32m1_t a;
fun (&a);
}
16 changes: 16 additions & 0 deletions gcc/testsuite/gcc.target/riscv/vector-abi-4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* { dg-do compile } */
/* { dg-options "-march=rv64gcv -mabi=lp64d" } */

#include "riscv_vector.h"

typedef int v4si __attribute__ ((vector_size (16)));

v4si
fun (v4si a) { return a; } /* { dg-warning "the vector type" } */

void
bar ()
{
v4si a;
fun (a);
}
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/vector-abi-5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* { dg-options "-march=rv64gcv -mabi=lp64d" } */

#include "riscv_vector.h"
typedef int v4si __attribute__ ((vector_size (16)));

v4si*
fun (v4si* a) { return a; } /* { dg-bogus "the vector type" } */

void
bar ()
{
v4si a;
fun (&a);
}

0 comments on commit 2c68135

Please sign in to comment.