Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8337780

RISC-V: C2: Change C calling convention for sp to NS

XMLWordPrintable

    • b10
    • riscv
    • linux

        We can change the C calling convention for sp to NS as sp is always saved and restored by the prolog/epilog code.
        This could reduce the frame size by 16 bytes for each C2 runtime stub as we do not have to save sp on the method entry.
        Here is an example, when sp is SOE, the generated code would be:
        ```
        Decoding RuntimeStub - _complete_monitor_locking_Java 0x0000003f676d6a08 [0x0000003f676d6a80, 0x0000003f676d6b08] (136 bytes)
        --------------------------------------------------------------------------------
          0x0000003f676d6a80: nop
          0x0000003f676d6a84: addi sp,sp,-32
          0x0000003f676d6a86: sd s0,16(sp)
          0x0000003f676d6a88: sd ra,24(sp)
          0x0000003f676d6a8a: sd sp,0(sp)
          0x0000003f676d6a8c: sd sp,928(s7)
          0x0000003f676d6a90: mv a0,a1
          0x0000003f676d6a92: mv a1,a2
          0x0000003f676d6a94: mv a2,s7
          0x0000003f676d6a96: auipc t1,0x0
          0x0000003f676d6a9a: addi t1,t1,44 # 0x0000003f676d6ac2
          0x0000003f676d6a9e: lui t0,0x1fc
          0x0000003f676d6aa2: addi t0,t0,-108 # 0x00000000001fbf94
          0x0000003f676d6aa6: slli t0,t0,0xb
          0x0000003f676d6aaa: addi t0,t0,1589
          0x0000003f676d6aae: slli t0,t0,0x6
          0x0000003f676d6ab2: addi t0,t0,14
          0x0000003f676d6ab6: addi sp,sp,-16
          0x0000003f676d6aba: sd t1,8(sp)
          0x0000003f676d6abe: jalr t0
          0x0000003f676d6ac2: nop
          0x0000003f676d6ac6: lui zero,0x0
          0x0000003f676d6aca: sext.w zero,zero
          0x0000003f676d6ace: addi sp,sp,16
          0x0000003f676d6ad2: sd zero,928(s7)
          0x0000003f676d6ad6: sd zero,936(s7)
          0x0000003f676d6ada: ld t2,8(s7)
          0x0000003f676d6ade: bnez t2,0x0000003f676d6aec
          0x0000003f676d6ae2: ld sp,0(sp)
          0x0000003f676d6ae4: ld s0,16(sp)
          0x0000003f676d6ae6: ld ra,24(sp)
          0x0000003f676d6ae8: addi sp,sp,32
          0x0000003f676d6aea: ret
          0x0000003f676d6aec: li t6,0
          0x0000003f676d6af0: lui t2,0x3f67
          0x0000003f676d6af4: addiw t2,t2,1487 # 0x0000000003f675cf
          0x0000003f676d6af8: slli t2,t2,0xc
          0x0000003f676d6afa: addi t2,t2,832
          0x0000003f676d6afe: ld sp,0(sp)
          0x0000003f676d6b00: ld s0,16(sp)
          0x0000003f676d6b02: ld ra,24(sp)
          0x0000003f676d6b04: addi sp,sp,32
          0x0000003f676d6b06: jr
        ```
        after we change to NS, it only generates the following code:
        ```
        Decoding RuntimeStub - _complete_monitor_locking_Java 0x0000003f676d6688 [0x0000003f676d6700, 0x0000003f676d6788] (136 bytes)
        --------------------------------------------------------------------------------
          0x0000003f676d6700: nop
          0x0000003f676d6704: addi sp,sp,-16
          0x0000003f676d6706: sd s0,0(sp)
          0x0000003f676d6708: sd ra,8(sp)
          0x0000003f676d670a: sd sp,928(s7)
          0x0000003f676d670e: mv a0,a1
          0x0000003f676d6710: mv a1,a2
          0x0000003f676d6712: mv a2,s7
          0x0000003f676d6714: auipc t1,0x0
          0x0000003f676d6718: addi t1,t1,44 # 0x0000003f676d6740
          0x0000003f676d671c: lui t0,0x1fc
          0x0000003f676d6720: addi t0,t0,-107 # 0x00000000001fbf95
          0x0000003f676d6724: slli t0,t0,0xb
          0x0000003f676d6728: addi t0,t0,316
          0x0000003f676d672c: slli t0,t0,0x6
          0x0000003f676d6730: addi t0,t0,12
          0x0000003f676d6734: addi sp,sp,-16
          0x0000003f676d6738: sd t1,8(sp)
          0x0000003f676d673c: jalr t0
          0x0000003f676d6740: nop
          0x0000003f676d6744: lui zero,0x0
          0x0000003f676d6748: sext.w zero,zero
          0x0000003f676d674c: addi sp,sp,16
          0x0000003f676d6750: sd zero,928(s7)
          0x0000003f676d6754: sd zero,936(s7)
          0x0000003f676d6758: ld t2,8(s7)
          0x0000003f676d675c: bnez t2,0x0000003f676d6768
          0x0000003f676d6760: ld s0,0(sp)
          0x0000003f676d6762: ld ra,8(sp)
          0x0000003f676d6764: addi sp,sp,16
          0x0000003f676d6766: ret
          0x0000003f676d6768: li t6,0
          0x0000003f676d676c: lui t2,0x3f67
          0x0000003f676d6770: addiw t2,t2,1487 # 0x0000000003f675cf
          0x0000003f676d6774: slli t2,t2,0xc
          0x0000003f676d6776: addi t2,t2,832
          0x0000003f676d677a: ld s0,0(sp)
          0x0000003f676d677c: ld ra,8(sp)
          0x0000003f676d677e: addi sp,sp,16
          0x0000003f676d6780: jr t2
        ```

        We also checked the calling convention type for sp on other platforms (AArch64, PPC, x86, x64, S390), and they are all treated as NS.

              fjiang Feilong Jiang
              fjiang Feilong Jiang
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: