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

RISCV: Add vector psabi checking. #376

Open
wants to merge 7 commits into
base: rvv-submission-v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 110 additions & 1 deletion gcc/config/riscv/riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3728,6 +3728,98 @@ riscv_pass_fpr_pair (machine_mode mode, unsigned regno1,
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 = TYPE_SIZE (type);
if (size && TREE_CODE (size) == 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 = 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)
{
tree field_type = 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 = riscv_scalable_vector_type_p (field_type);
else
is_vector = riscv_arg_has_vector (field_type);
}

break;

case VECTOR_TYPE:
kito-cheng marked this conversation as resolved.
Show resolved Hide resolved
is_vector = riscv_scalable_vector_type_p (type);
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;
yanzhang-dev marked this conversation as resolved.
Show resolved Hide resolved

if (type && riscv_arg_has_vector (type) && !warned)
{
warning (OPT_Wpsabi, "ABI for the scalable vector type is currently in "
"experimental stage and may changes in the upcoming version of "
"GCC.");
warned = 1;
}
}

/* Initialize a variable CUM of type CUMULATIVE_ARGS
for a call to a function whose data type is FNTYPE.
For a library call, FNTYPE is 0. */

void
init_cumulative_args (CUMULATIVE_ARGS *cum, /* Argument info to initialize */
tree fntype, /* tree ptr for function decl */
rtx libname, /* SYMBOL_REF of library name or 0 */
tree fndecl,
int caller)
{
memset (cum, 0, sizeof (*cum));

if (fndecl)
{
const tree_function_decl &fn = FUNCTION_DECL_CHECK (fndecl)->function_decl;

if (fn.built_in_class == NOT_BUILT_IN)
cum->rvv_psabi_warning = 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 +3904,12 @@ riscv_get_arg_info (struct riscv_arg_info *info, const CUMULATIVE_ARGS *cum,
}
}

if (cum->rvv_psabi_warning)
{
/* 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 Expand Up @@ -3899,7 +3997,18 @@ riscv_function_value (const_tree type, const_tree func, machine_mode mode)
}

memset (&args, 0, sizeof args);
return riscv_get_arg_info (&info, &args, mode, type, true, true);

const_tree arg_type = type;
if (func && DECL_RESULT (func))
{
const tree_function_decl &fn = FUNCTION_DECL_CHECK(func)->function_decl;
if (fn.built_in_class == NOT_BUILT_IN)
args.rvv_psabi_warning = 1;

arg_type = TREE_TYPE (DECL_RESULT (func));
}

return riscv_get_arg_info (&info, &args, mode, arg_type, true, true);
}

/* Implement TARGET_PASS_BY_REFERENCE. */
Expand Down
6 changes: 5 additions & 1 deletion gcc/config/riscv/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,14 +671,18 @@ typedef struct {

/* Number of floating-point registers used so far, likewise. */
unsigned int num_fprs;

bool rvv_psabi_warning;
} CUMULATIVE_ARGS;

/* Initialize a variable CUM of type CUMULATIVE_ARGS
for a call to a function whose data type is FNTYPE.
For a library call, FNTYPE is 0. */

void init_cumulative_args (CUMULATIVE_ARGS *, tree, rtx, tree, int);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to riscv_init_cumulative_args and put into riscv-protos.h.

#define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT, N_NAMED_ARGS) \
memset (&(CUM), 0, sizeof (CUM))
init_cumulative_args (&(CUM), (FNTYPE), (LIBNAME), (INDIRECT), \
(N_NAMED_ARGS) != -1)

#define EPILOGUE_USES(REGNO) riscv_epilogue_uses (REGNO)

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" } */
kito-cheng marked this conversation as resolved.
Show resolved Hide resolved

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-bogus "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" } */

typedef int v4si __attribute__ ((vector_size (16)));
struct A { int a; v4si b; };

void
fun (struct A a) {} /* { dg-bogus "the vector type" } */

void
bar ()
{
struct A a;
fun (a);
}