xref: /llvm-project/llvm/test/CodeGen/AArch64/GlobalISel/swiftself.ll (revision 46584de02c1a38a0ccde85cb5c16331380966c36)
1; RUN: llc -verify-machineinstrs -mtriple=aarch64-apple-ios -o - %s -global-isel | FileCheck %s
2
3; Parameter with swiftself should be allocated to x20.
4; CHECK-LABEL: swiftself_param:
5; CHECK: mov x0, x20
6; CHECK-NEXT: ret
7define ptr @swiftself_param(ptr swiftself %addr0) {
8  ret ptr %addr0
9}
10
11; Check that x20 is used to pass a swiftself argument.
12; CHECK-LABEL: call_swiftself:
13; CHECK: mov x20, x0
14; CHECK: bl {{_?}}swiftself_param
15; CHECK: ret
16define ptr @call_swiftself(ptr %arg) {
17  %res = call ptr @swiftself_param(ptr swiftself %arg)
18  ret ptr %res
19}
20
21; Demonstrate that we do not need any movs when calling multiple functions
22; with swiftself argument.
23; CHECK-LABEL: swiftself_passthrough:
24; CHECK-NOT: mov{{.*}}x20
25; CHECK: bl {{_?}}swiftself_param
26; CHECK-NOT: mov{{.*}}x20
27; CHECK-NEXT: bl {{_?}}swiftself_param
28; CHECK: ret
29define void @swiftself_passthrough(ptr swiftself %addr0) {
30  call ptr @swiftself_param(ptr swiftself %addr0)
31  call ptr @swiftself_param(ptr swiftself %addr0)
32  ret void
33}
34
35; We can not use a tail call if the callee swiftself is not the same as the
36; caller one.
37; CHECK-LABEL: swiftself_notail:
38; CHECK: mov x20, x0
39; CHECK: bl {{_?}}swiftself_param
40; CHECK: ret
41define ptr @swiftself_notail(ptr swiftself %addr0, ptr %addr1) nounwind {
42  %res = tail call ptr @swiftself_param(ptr swiftself %addr1)
43  ret ptr %res
44}
45
46; We cannot pretend that 'x0' is alive across the thisreturn_attribute call as
47; we normally would. We marked the first parameter with swiftself which means it
48; will no longer be passed in x0.
49declare swiftcc ptr @thisreturn_attribute(ptr returned swiftself)
50; CHECK-LABEL: swiftself_nothisreturn:
51; CHECK-DAG: ldr  x20, [x20]
52; CHECK-DAG: mov [[CSREG:x[1-9].*]], x8
53; CHECK: bl {{_?}}thisreturn_attribute
54; CHECK: str x0, [[[CSREG]]
55; CHECK: ret
56define hidden swiftcc void @swiftself_nothisreturn(ptr noalias nocapture sret(ptr), ptr noalias nocapture readonly swiftself) {
57entry:
58  %2 = load ptr, ptr %1, align 8
59  %3 = tail call swiftcc ptr @thisreturn_attribute(ptr swiftself %2)
60  store ptr %3, ptr %0, align 8
61  ret void
62}
63
64; Check that x20 is used to pass a swiftself argument when the parameter is
65; only in the declaration's arguments.
66; CHECK-LABEL: _swiftself_not_on_call_params:
67; CHECK: mov x20, x0
68; CHECK: bl {{_?}}swiftself_param
69; CHECK: ret
70define ptr @swiftself_not_on_call_params(ptr %arg) {
71  %res = call ptr @swiftself_param(ptr %arg)
72  ret ptr %res
73}
74