[PATCH] D143248: Emit CFI directives in epilogue and enable CFIFixup pass for RISC-V.
Shiva Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 1 01:21:17 PDT 2023
shiva0217 added a comment.
In D143248#4177761 <https://reviews.llvm.org/D143248#4177761>, @varunkumare99 wrote:
> In D143248#4131555 <https://reviews.llvm.org/D143248#4131555>, @shiva0217 wrote:
>
>> Hi Varun,
>>
>> It might be good to have a simple case to illustrate that cfi_remember_state and cfi_restore_state can be generated properly with epilogue CFI.
>> For examle, could the following case generated with cfi_remember_state and cfi_restore_state as GCC?
>>
>> extern void foo(void);
>> void f(int *i) {
>> if (*i == 0) {
>> *i = 1;
>> foo();
>> return;
>> } else {
>> __builtin_printf("Hi");
>> *i=0;
>> }
>> }
>
> Hi Shiva, the following is the assembly emitted.
>
> f:
> .Lfunc_begin0:
> .loc 0 2 0
> .cfi_startproc
> addi sp, sp, -16
> .cfi_def_cfa_offset 16
> sd ra, 8(sp)
> sd s0, 0(sp)
> .cfi_offset ra, -8
> .cfi_offset s0, -16
> .cfi_remember_state
> mv s0, a0
> .Ltmp0:
> .loc 0 3 6 prologue_end
> lw a0, 0(a0)
> .Ltmp1:
> .loc 0 3 6 is_stmt 0
> beqz a0, .LBB0_2
> .Ltmp2:
> .loc 0 8 3 is_stmt 1
> lui a0, %hi(.L.str)
> addi a0, a0, %lo(.L.str)
> call printf
> .Ltmp3:
> .loc 0 9 5
> sw zero, 0(s0)
> .Ltmp4:
> .loc 0 11 1
> ld ra, 8(sp)
> ld s0, 0(sp)
> .Ltmp5:
> .cfi_restore ra
> .cfi_restore s0
> .loc 0 11 1 epilogue_begin is_stmt 0
> addi sp, sp, 16
> .cfi_def_cfa_offset 0
> ret
> .LBB0_2:
> .cfi_restore_state
> .Ltmp6:
> .loc 0 0 1
> li a0, 1
> .Ltmp7:
> .loc 0 4 6 is_stmt 1
> sw a0, 0(s0)
> .loc 0 5 3
> ld ra, 8(sp)
> ld s0, 0(sp)
> .Ltmp8:
> .cfi_restore ra
> .cfi_restore s0
> .loc 0 5 3 epilogue_begin is_stmt 0
> addi sp, sp, 16
> .cfi_def_cfa_offset 0
> .Ltmp9:
> tail foo
> .Ltmp10:
> .Lfunc_end0:
> .size f, .Lfunc_end0-f
> .cfi_endproc
Hi Varun,
Could you add the case as a unit test?
Shouldn't all the epilogue CFI guard by EmitCFI?
The content of epilogue looks good to me.
Please wait for Maskray and Kito's comments.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143248/new/
https://reviews.llvm.org/D143248
More information about the llvm-commits
mailing list