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

Conversation

yanzhang-dev
Copy link

This patch adds support to check function's argument or return is vector type and throw warning.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_legitimize_move): (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/testsuite/gcc.target/riscv/vector-abi-2.c Show resolved Hide resolved
gcc/config/riscv/riscv.cc Outdated Show resolved Hide resolved
gcc/config/riscv/riscv.cc Outdated Show resolved Hide resolved
gcc/config/riscv/riscv.cc Show resolved Hide resolved
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]>
@zhongjuzhe
Copy link
Collaborator

Not familiar with ABI. I think it's all kito's call :)

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

Choose a reason for hiding this comment

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

will the message become something like in experimentalstage and ... instead of in experimental stage and ... after joining?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. You're right. Will modify it in the fix commit.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, thank you!

gcc/config/riscv/riscv.cc Show resolved Hide resolved
intrinsic vector type. Because we can't get the decl for the params. */

static bool
riscv_arg_has_vector_size_attribute (const_tree type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

riscv_scalable_vector_type_p

Copy link
Author

Choose a reason for hiding this comment

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

Done.

if (!TYPE_P (TREE_TYPE (f)))
break;

/* If there's vector_size attribute, ignore it. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ignore it if it's fixed length vector.

Copy link
Author

Choose a reason for hiding this comment

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

Done.


/* If there's vector_size attribute, ignore it. */
if (VECTOR_TYPE_P (TREE_TYPE (f)))
is_vector = !riscv_arg_has_vector_size_attribute (type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

riscv_arg_has_vector_size_attribute (TREE_TYPE (f))?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, you're right. It should be the field type.

Comment on lines 3737 to 3742
tree size = TYPE_SIZE (type);
if (size && TREE_CODE (size) == INTEGER_CST)
return true;

/* For the data type like vint32m1_t, the size code is POLY_INT_CST. */
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The return value should be inverted after function rename :)

Copy link
Author

Choose a reason for hiding this comment

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

Oh understand. Could I know why the intrinsic vector type is named as scalable vector ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's the term defined in AArch64 SVE actually, and we follow to use that term in our backend too , e.g. riscv.cc:riscv_v_adjust_scalable_frame


if (type && riscv_arg_has_vector (type) && !warned)
{
warning (OPT_Wpsabi, "ABI for the vector type is currently in "
Copy link
Collaborator

Choose a reason for hiding this comment

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

vector -> scalable vector, that should more clear that it's exclude fixed length vector.

@yanzhang-dev
Copy link
Author

Hi @kito-cheng , The commit 51fbc2e tries to fix the warning on intrinsic APIs. I'm not sure whether it's a right solution ?

I think the problem is we want to distinguish below 3 scenarios,

  1. vint32m1_t fun(xxx) -> warning on return type.
  2. vint32m1_t a = fun(xxx) -> no warning
  3. xxx fun(vint32m1_t) -> warning on arg.

Both three will call riscv_pass_by_reference and then call riscv_get_arg_info. So we can't put the checking in get_arg_info. My solution moves the checking into function_arg and function_value. It can successfully distinguish the three.

But there's another new issue. When compiling with -flto, the warning will disappear and will show when do the linking. So I skip the the lto in tests.

Copy link
Collaborator

@kito-cheng kito-cheng left a comment

Choose a reason for hiding this comment

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

Only one minor comment, you can go to mailing list after you address that :)

} 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants