[clang] [llvm] [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs (PR #76777)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 4 23:24:32 PST 2024


koute wrote:

Side note: shouldn't we also update `compiler-rt/lib/builtins/riscv/{save, restore}.S`? E.g. with something like this:

```patch
diff --git a/compiler-rt/lib/builtins/riscv/restore.S b/compiler-rt/lib/builtins/riscv/restore.S
index 73f64a920d66..2e185ecae3f7 100644
--- a/compiler-rt/lib/builtins/riscv/restore.S
+++ b/compiler-rt/lib/builtins/riscv/restore.S
@@ -20,6 +20,46 @@
 
   .text
 
+#if __riscv_abi_rve == 1
+
+#if __riscv_xlen == 32
+  .globl  __riscv_restore_2
+  .type   __riscv_restore_2, at function
+  .globl  __riscv_restore_1
+  .type   __riscv_restore_1, at function
+  .globl  __riscv_restore_0
+  .type   __riscv_restore_0, at function
+__riscv_restore_1:
+__riscv_restore_0:
+  lw      s1,  4(sp)
+  lw      s0,  8(sp)
+  lw      ra,  12(sp)
+  addi    sp, sp, 16
+  ret
+#elif __riscv_xlen == 64
+  .globl  __riscv_restore_2
+  .type   __riscv_restore_2, at function
+__riscv_restore_2:
+  ld      s1,  8(sp)
+  addi    sp, sp, 16
+  // fallthrough into __riscv_restore_1/0
+
+  .globl  __riscv_restore_1
+  .type   __riscv_restore_1, at function
+  .globl  __riscv_restore_0
+  .type   __riscv_restore_0, at function
+__riscv_restore_1:
+__riscv_restore_0:
+  ld      s0,  0(sp)
+  ld      ra,  8(sp)
+  addi    sp, sp, 16
+  ret
+#else
+# error "xlen must be 32 or 64 for save-restore implementation
+#endif
+
+#else
+
 #if __riscv_xlen == 32
 
   .globl  __riscv_restore_12
@@ -164,3 +204,5 @@ __riscv_restore_0:
 #else
 # error "xlen must be 32 or 64 for save-restore implementation
 #endif
+
+#endif
diff --git a/compiler-rt/lib/builtins/riscv/save.S b/compiler-rt/lib/builtins/riscv/save.S
index 85501aeb4c2e..86b62a369cd0 100644
--- a/compiler-rt/lib/builtins/riscv/save.S
+++ b/compiler-rt/lib/builtins/riscv/save.S
@@ -16,6 +16,54 @@
 
   .text
 
+#if __riscv_abi_rve == 1
+
+#if __riscv_xlen == 32
+  .globl  __riscv_save_2
+  .type   __riscv_save_2, at function
+  .globl  __riscv_save_1
+  .type   __riscv_save_1, at function
+  .globl  __riscv_save_0
+  .type   __riscv_save_0, at function
+__riscv_save_3:
+__riscv_save_2:
+__riscv_save_1:
+__riscv_save_0:
+  addi    sp, sp, -16
+  sw      s1,  4(sp)
+  sw      s0,  8(sp)
+  sw      ra,  12(sp)
+  jr      t0
+#elif __riscv_xlen == 64
+  .globl  __riscv_save_2
+  .type   __riscv_save_2, at function
+__riscv_save_3:
+__riscv_save_2:
+  addi   sp, sp, -112
+  li     t1, 80
+.Lriscv_save_3_2:
+  sd     s1, 88(sp)
+  sd     s0, 96(sp)
+  sd     ra, 104(sp)
+  add    sp, sp, t1
+  jr     t0
+
+  .globl  __riscv_save_1
+  .type   __riscv_save_1, at function
+  .globl  __riscv_save_0
+  .type   __riscv_save_0, at function
+__riscv_save_1:
+__riscv_save_0:
+  addi   sp, sp, -16
+  sd     s0, 0(sp)
+  sd     ra, 8(sp)
+  jr     t0
+#else
+# error "xlen must be 32 or 64 for save-restore implementation
+#endif
+
+#else
+
 #if __riscv_xlen == 32
 
   .globl  __riscv_save_12
@@ -184,3 +232,5 @@ __riscv_save_0:
 #else
 # error "xlen must be 32 or 64 for save-restore implementation
 #endif
+
+#endif
```

(I don't remember why exactly since I did it a long time ago, but for some reason I do have this patch in my LLVM fork, so it probably was necessary for *something*.)

https://github.com/llvm/llvm-project/pull/76777


More information about the cfe-commits mailing list