[PATCH] D156642: libunwind: riscv: disable vector test when __riscv_v not defined

Sean Cross via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 30 21:25:45 PDT 2023


xobs created this revision.
xobs added a reviewer: whitequark.
xobs added a project: libunwind.
Herald added subscribers: VincentWu, vkmr, sameer.abuasal, s.egerton, Jim, benna, psnobl, PkmX, rogfer01, shiva0217, kito-cheng, simoncook, asb, arichardson.
Herald added a project: All.
xobs requested review of this revision.
Herald added subscribers: libcxx-commits, llvm-commits, wangpc, eopXD.
Herald added a project: LLVM.
Herald added a reviewer: libunwind.

The commit ca0b4d58eaad405ea74b4db82ecb14b3cfdeccb7 <https://reviews.llvm.org/rGca0b4d58eaad405ea74b4db82ecb14b3cfdeccb7> (https://reviews.llvm.org/D136264) added a code path that uses the `csrr` instruction to read the vector length. This works fine when compiling under risc-v with the -g arch, such as rv32gc or rv64gc. However, depending on the vintage of the compiler, it does not work when compiling with an arch such as riscv32imac.

Older versions of the spec add csr instructions by default, but newer versions of the spec removed those instructions. This means that this file needs to be compiled under `rv32imac` or `rv32imac_zicsr` depending on the compiler version.

This patch adds a check for `__riscv_v` as a compiler define. Because the -V extension came out after the architecture rename to _zicsr, this patch will continue to work on newer compilers.

https://reviews.llvm.org/D136264#4545515


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156642

Files:
  libunwind/src/Registers.hpp


Index: libunwind/src/Registers.hpp
===================================================================
--- libunwind/src/Registers.hpp
+++ libunwind/src/Registers.hpp
@@ -4101,11 +4101,13 @@
     return 0;
   if ((regNum > 0) && (regNum < 32))
     return _registers[regNum];
+#if defined(__riscv_v)
   if (regNum == UNW_RISCV_VLENB) {
     reg_t vlenb;
     __asm__("csrr %0, 0xC22" : "=r"(vlenb));
     return vlenb;
   }
+#endif
   _LIBUNWIND_ABORT("unsupported riscv register");
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156642.545506.patch
Type: text/x-patch
Size: 488 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230731/2b7bb86d/attachment.bin>


More information about the llvm-commits mailing list