1*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs -mtriple=aarch64-apple-ios -o - %s | FileCheck --check-prefix=CHECK --check-prefix=OPT %s 2*9880d681SAndroid Build Coastguard Worker; RUN: llc -O0 -verify-machineinstrs -mtriple=aarch64-apple-ios -o - %s | FileCheck %s 3*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs -mtriple=aarch64-unknown-linux-gnu -o - %s | FileCheck --check-prefix=CHECK --check-prefix=OPT %s 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Worker; Parameter with swiftself should be allocated to x20. 6*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: swiftself_param: 7*9880d681SAndroid Build Coastguard Worker; CHECK: mov x0, x20 8*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret 9*9880d681SAndroid Build Coastguard Workerdefine i8* @swiftself_param(i8* swiftself %addr0) { 10*9880d681SAndroid Build Coastguard Worker ret i8 *%addr0 11*9880d681SAndroid Build Coastguard Worker} 12*9880d681SAndroid Build Coastguard Worker 13*9880d681SAndroid Build Coastguard Worker; Check that x20 is used to pass a swiftself argument. 14*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: call_swiftself: 15*9880d681SAndroid Build Coastguard Worker; CHECK: mov x20, x0 16*9880d681SAndroid Build Coastguard Worker; CHECK: bl {{_?}}swiftself_param 17*9880d681SAndroid Build Coastguard Worker; CHECK: ret 18*9880d681SAndroid Build Coastguard Workerdefine i8 *@call_swiftself(i8* %arg) { 19*9880d681SAndroid Build Coastguard Worker %res = call i8 *@swiftself_param(i8* swiftself %arg) 20*9880d681SAndroid Build Coastguard Worker ret i8 *%res 21*9880d681SAndroid Build Coastguard Worker} 22*9880d681SAndroid Build Coastguard Worker 23*9880d681SAndroid Build Coastguard Worker; x20 should be saved by the callee even if used for swiftself 24*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: swiftself_clobber: 25*9880d681SAndroid Build Coastguard Worker; CHECK: {{stp|str}} {{.*}}x20{{.*}}sp 26*9880d681SAndroid Build Coastguard Worker; ... 27*9880d681SAndroid Build Coastguard Worker; CHECK: {{ldp|ldr}} {{.*}}x20{{.*}}sp 28*9880d681SAndroid Build Coastguard Worker; CHECK: ret 29*9880d681SAndroid Build Coastguard Workerdefine i8 *@swiftself_clobber(i8* swiftself %addr0) { 30*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "", "~{x20}"() 31*9880d681SAndroid Build Coastguard Worker ret i8 *%addr0 32*9880d681SAndroid Build Coastguard Worker} 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Worker; Demonstrate that we do not need any movs when calling multiple functions 35*9880d681SAndroid Build Coastguard Worker; with swiftself argument. 36*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: swiftself_passthrough: 37*9880d681SAndroid Build Coastguard Worker; OPT-NOT: mov{{.*}}x20 38*9880d681SAndroid Build Coastguard Worker; OPT: bl {{_?}}swiftself_param 39*9880d681SAndroid Build Coastguard Worker; OPT-NOT: mov{{.*}}x20 40*9880d681SAndroid Build Coastguard Worker; OPT-NEXT: bl {{_?}}swiftself_param 41*9880d681SAndroid Build Coastguard Worker; OPT: ret 42*9880d681SAndroid Build Coastguard Workerdefine void @swiftself_passthrough(i8* swiftself %addr0) { 43*9880d681SAndroid Build Coastguard Worker call i8 *@swiftself_param(i8* swiftself %addr0) 44*9880d681SAndroid Build Coastguard Worker call i8 *@swiftself_param(i8* swiftself %addr0) 45*9880d681SAndroid Build Coastguard Worker ret void 46*9880d681SAndroid Build Coastguard Worker} 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker; We can use a tail call if the callee swiftself is the same as the caller one. 49*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: swiftself_tail: 50*9880d681SAndroid Build Coastguard Worker; OPT: b {{_?}}swiftself_param 51*9880d681SAndroid Build Coastguard Worker; OPT-NOT: ret 52*9880d681SAndroid Build Coastguard Workerdefine i8* @swiftself_tail(i8* swiftself %addr0) { 53*9880d681SAndroid Build Coastguard Worker call void asm sideeffect "", "~{x20}"() 54*9880d681SAndroid Build Coastguard Worker %res = tail call i8* @swiftself_param(i8* swiftself %addr0) 55*9880d681SAndroid Build Coastguard Worker ret i8* %res 56*9880d681SAndroid Build Coastguard Worker} 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Worker; We can not use a tail call if the callee swiftself is not the same as the 59*9880d681SAndroid Build Coastguard Worker; caller one. 60*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: swiftself_notail: 61*9880d681SAndroid Build Coastguard Worker; CHECK: mov x20, x0 62*9880d681SAndroid Build Coastguard Worker; CHECK: bl {{_?}}swiftself_param 63*9880d681SAndroid Build Coastguard Worker; CHECK: ret 64*9880d681SAndroid Build Coastguard Workerdefine i8* @swiftself_notail(i8* swiftself %addr0, i8* %addr1) nounwind { 65*9880d681SAndroid Build Coastguard Worker %res = tail call i8* @swiftself_param(i8* swiftself %addr1) 66*9880d681SAndroid Build Coastguard Worker ret i8* %res 67*9880d681SAndroid Build Coastguard Worker} 68