This is an archive of the discontinued LLVM Phabricator instance.

[Clang][RISCV] Expose vlenb to user
ClosedPublic

Authored by eopXD on Jan 4 2023, 11:36 PM.

Details

Summary

This commit adds function vlenb into riscv_vector.h. vlenb is defined
through builtin function __builtin_rvv_vlenb, which is lowered to
llvm.read_register.

Diff Detail

Event Timeline

eopXD created this revision.Jan 4 2023, 11:36 PM
eopXD requested review of this revision.Jan 4 2023, 11:36 PM
clang/include/clang/Basic/riscv_vector.td
1555

Should we report errors if vwrite_csr(RVV_VLENB, some_value)?

eopXD retitled this revision from [Clang][RISCV] Expose vlenb to vread_csr to [Clang][RISCV] Expose vlenb to user.Jan 5 2023, 12:06 AM
eopXD edited the summary of this revision. (Show Details)
eopXD added a comment.Jan 5 2023, 12:13 AM

Upon a second thought, with future extensions of the intrinsics, we will add rounding mode and exception intrinsics. The exposure of vxsat, vxrm, and vcsr in vread_csr and vwrite_csr will confuse user and we should remove them. Furthermore, vstart is pretty much always kept to zero, and intrinsic users probably should not have access to them.

With the considerations above, I think vread_csr and vwrite_csr can be removed in the future when the rounding mode and exception intrinsics are added. This is why this patch is opening up a separate function to provide access to vlenb and not choose to extend another member in the enum.

eopXD edited the summary of this revision. (Show Details)Jan 5 2023, 12:13 AM
eopXD updated this revision to Diff 486486.Jan 5 2023, 12:16 AM
eopXD edited the summary of this revision. (Show Details)

Update code. Add function vlenb instead of extending inside the vread_csr function.

eopXD marked an inline comment as done.Jan 5 2023, 12:17 AM
eopXD added inline comments.
clang/include/clang/Basic/riscv_vector.td
1555

Thanks pointing this out. I think my second approach here won't create such problem.

clang/include/clang/Basic/riscv_vector.td
1565

Inline assembly may not be elegant since it can't be optimized in many ways. We can eliminate some redundant reads of vlenb currently(done in D125564). So I think we may add a builtin function and lower it to llvm.read_register?

eopXD updated this revision to Diff 487206.Jan 8 2023, 10:00 AM
eopXD marked an inline comment as not done.

Update code. Apply suggestion from @pcwang-thead.

eopXD edited the summary of this revision. (Show Details)Jan 8 2023, 10:01 AM
eopXD added a reviewer: pcwang-thead.
eopXD marked 2 inline comments as done.
eopXD added inline comments.
clang/include/clang/Basic/riscv_vector.td
1565

Thank you for the tip. Please review.

eopXD marked an inline comment as done.Jan 8 2023, 10:06 AM
pcwang-thead accepted this revision.EditedJan 8 2023, 8:26 PM

The code is OK to me, except a few small comments.

clang/include/clang/Basic/riscv_vector.td
1579

The value type of read_register is i32 in llvm/test/CodeGen/RISCV/vlenb.ll, but I don't insist on it.

clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
2

Add --check-globals or --global-value-regex to check if the metadata is vlenb exactly?

This revision is now accepted and ready to land.Jan 8 2023, 8:26 PM
craig.topper added inline comments.Jan 8 2023, 9:18 PM
clang/include/clang/Basic/riscv_vector.td
1579

Doesn't this need to match the size of long?

clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
2

Please test riscv32 as well

clang/include/clang/Basic/riscv_vector.td
1579

So what about i32 for rv32 and i64 for rv64?

eopXD updated this revision to Diff 487293.Jan 8 2023, 10:46 PM
eopXD marked 5 inline comments as done.

Address comments from Craig.

clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
34

Hmm, why would we emit version info here? I think we should avoid this.
I find a clang option -Qn that can disable emitting this by setting EmitVersionIdentMetadata to false.

eopXD updated this revision to Diff 487302.Jan 8 2023, 11:58 PM

Update code: Avoid emit clang version in test case.
@pcwang-thead Thank you for checking and providing the corresponding resolution. :)

eopXD marked an inline comment as done.Jan 8 2023, 11:58 PM
kito-cheng accepted this revision.Jan 9 2023, 12:03 AM
eopXD edited the summary of this revision. (Show Details)Jan 10 2023, 2:22 AM
This revision was landed with ongoing or failed builds.Jan 10 2023, 2:24 AM
This revision was automatically updated to reflect the committed changes.