xref: /llvm-project/llvm/test/CodeGen/RISCV/patchable-function-entry.ll (revision 7620f03ef7a662384d67b6bd1fad8582dfe9dd82)
1;; Test the function attribute "patchable-function-entry".
2; RUN: llc -mtriple=riscv32 --riscv-no-aliases < %s | FileCheck %s --check-prefixes=CHECK,RV32,NORVC
3; RUN: llc -mtriple=riscv64 --riscv-no-aliases < %s | FileCheck %s --check-prefixes=CHECK,RV64,NORVC
4; RUN: llc -mtriple=riscv32 -mattr=+c --riscv-no-aliases < %s | FileCheck %s --check-prefixes=CHECK,RV32,RVC
5; RUN: llc -mtriple=riscv64 -mattr=+c --riscv-no-aliases < %s | FileCheck %s --check-prefixes=CHECK,RV64,RVC
6
7define void @f0() "patchable-function-entry"="0" {
8; CHECK-LABEL: f0:
9; CHECK-NEXT:  .Lfunc_begin0:
10; CHECK-NOT:     {{addi|c.nop}}
11; NORVC:         jalr zero, 0(ra)
12; RVC:           c.jr ra
13; CHECK-NOT:   .section __patchable_function_entries
14  ret void
15}
16
17define void @f1() "patchable-function-entry"="1" {
18; CHECK-LABEL: f1:
19; CHECK-NEXT: .Lfunc_begin1:
20; NORVC:         addi zero, zero, 0
21; NORVC-NEXT:    jalr zero, 0(ra)
22; RVC:           c.nop
23; RVC-NEXT:      c.jr ra
24; CHECK:       .section __patchable_function_entries,"awo",@progbits,f1{{$}}
25; 32:          .p2align 2
26; 32-NEXT:     .word .Lfunc_begin1
27; 64:          .p2align 3
28; 64-NEXT:     .quad .Lfunc_begin1
29  ret void
30}
31
32$f5 = comdat any
33define void @f5() "patchable-function-entry"="5" comdat {
34; CHECK-LABEL: f5:
35; CHECK-NEXT:  .Lfunc_begin2:
36; NORVC-COUNT-5: addi zero, zero, 0
37; NORVC-NEXT:    jalr zero, 0(ra)
38; RVC-COUNT-5:   c.nop
39; RVC-NEXT:      c.jr ra
40; CHECK:       .section __patchable_function_entries,"awoG",@progbits,f5,f5,comdat{{$}}
41; RV32:        .p2align 2
42; RV32-NEXT:   .word .Lfunc_begin2
43; RV64:        .p2align 3
44; RV64-NEXT:   .quad .Lfunc_begin2
45  ret void
46}
47
48;; -fpatchable-function-entry=3,2
49;; "patchable-function-prefix" emits data before the function entry label.
50define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="2" {
51; CHECK-LABEL: .type f3_2,@function
52; CHECK-NEXT:  .Ltmp0:
53; NORVC-COUNT-2: addi zero, zero, 0
54; RVC-COUNT-2:   c.nop
55; CHECK-NEXT:  f3_2:  # @f3_2
56; CHECK:       # %bb.0:
57; NORVC-NEXT:    addi zero, zero, 0
58; NORVC-NEXT:    addi sp, sp, -16
59; RVC-NEXT:      c.nop
60; RVC-NEXT:      c.addi sp, -16
61;; .size does not include the prefix.
62; CHECK:      .Lfunc_end3:
63; CHECK-NEXT: .size f3_2, .Lfunc_end3-f3_2
64; CHECK:      .section __patchable_function_entries,"awo",@progbits,f3_2{{$}}
65; RV32:       .p2align 2
66; RV32-NEXT:  .word .Ltmp0
67; RV64:       .p2align 3
68; RV64-NEXT:  .quad .Ltmp0
69  %frame = alloca i8, i32 16
70  ret void
71}
72