Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 1 | ; RUN: llc -verify-machineinstrs -mtriple=armv7k-apple-ios8.0 -mcpu=cortex-a7 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=OPT --check-prefix=TAILCALL %s |
| 2 | ; RUN: llc -O0 -verify-machineinstrs -mtriple=armv7k-apple-ios8.0 -mcpu=cortex-a7 -o - %s | FileCheck %s |
Manman Ren | f46262e | 2016-03-29 17:37:21 +0000 | [diff] [blame] | 3 | |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 4 | ; RUN: llc -verify-machineinstrs -mtriple=armv7-apple-ios -o - %s | FileCheck --check-prefix=CHECK --check-prefix=OPT %s |
| 5 | ; RUN: llc -O0 -verify-machineinstrs -mtriple=armv7-apple-ios -o - %s | FileCheck %s |
Manman Ren | f46262e | 2016-03-29 17:37:21 +0000 | [diff] [blame] | 6 | |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 7 | ; Parameter with swiftself should be allocated to r10. |
| 8 | ; CHECK-LABEL: swiftself_param: |
| 9 | ; CHECK: mov r0, r10 |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 10 | define i8 *@swiftself_param(i8* swiftself %addr0) "no-frame-pointer-elim"="true" { |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 11 | ret i8 *%addr0 |
Manman Ren | f46262e | 2016-03-29 17:37:21 +0000 | [diff] [blame] | 12 | } |
| 13 | |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 14 | ; Check that r10 is used to pass a swiftself argument. |
| 15 | ; CHECK-LABEL: call_swiftself: |
| 16 | ; CHECK: mov r10, r0 |
| 17 | ; CHECK: bl {{_?}}swiftself_param |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 18 | define i8 *@call_swiftself(i8* %arg) "no-frame-pointer-elim"="true" { |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 19 | %res = call i8 *@swiftself_param(i8* swiftself %arg) |
| 20 | ret i8 *%res |
| 21 | } |
Manman Ren | f46262e | 2016-03-29 17:37:21 +0000 | [diff] [blame] | 22 | |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 23 | ; r10 should be saved by the callee even if used for swiftself |
| 24 | ; CHECK-LABEL: swiftself_clobber: |
| 25 | ; CHECK: push {r10} |
| 26 | ; ... |
| 27 | ; CHECK: pop {r10} |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 28 | define i8 *@swiftself_clobber(i8* swiftself %addr0) "no-frame-pointer-elim"="true" { |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 29 | call void asm sideeffect "", "~{r10}"() |
| 30 | ret i8 *%addr0 |
| 31 | } |
Manman Ren | f46262e | 2016-03-29 17:37:21 +0000 | [diff] [blame] | 32 | |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 33 | ; Demonstrate that we do not need any movs when calling multiple functions |
| 34 | ; with swiftself argument. |
| 35 | ; CHECK-LABEL: swiftself_passthrough: |
| 36 | ; OPT-NOT: mov{{.*}}r10 |
| 37 | ; OPT: bl {{_?}}swiftself_param |
| 38 | ; OPT-NOT: mov{{.*}}r10 |
| 39 | ; OPT-NEXT: bl {{_?}}swiftself_param |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 40 | define void @swiftself_passthrough(i8* swiftself %addr0) "no-frame-pointer-elim"="true" { |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 41 | call i8 *@swiftself_param(i8* swiftself %addr0) |
| 42 | call i8 *@swiftself_param(i8* swiftself %addr0) |
Manman Ren | f46262e | 2016-03-29 17:37:21 +0000 | [diff] [blame] | 43 | ret void |
| 44 | } |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 45 | |
| 46 | ; We can use a tail call if the callee swiftself is the same as the caller one. |
| 47 | ; CHECK-LABEL: swiftself_tail: |
| 48 | ; TAILCALL: b {{_?}}swiftself_param |
| 49 | ; TAILCALL-NOT: pop |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 50 | define i8* @swiftself_tail(i8* swiftself %addr0) "no-frame-pointer-elim"="true" { |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 51 | call void asm sideeffect "", "~{r10}"() |
| 52 | %res = tail call i8* @swiftself_param(i8* swiftself %addr0) |
| 53 | ret i8* %res |
| 54 | } |
| 55 | |
| 56 | ; We can not use a tail call if the callee swiftself is not the same as the |
| 57 | ; caller one. |
| 58 | ; CHECK-LABEL: swiftself_notail: |
| 59 | ; CHECK: mov r10, r0 |
| 60 | ; CHECK: bl {{_?}}swiftself_param |
| 61 | ; CHECK: pop |
Oliver Stannard | 9aa6f01 | 2016-08-23 09:19:22 +0000 | [diff] [blame] | 62 | define i8* @swiftself_notail(i8* swiftself %addr0, i8* %addr1) nounwind "no-frame-pointer-elim"="true" { |
Matthias Braun | 707e02c | 2016-04-13 21:43:25 +0000 | [diff] [blame] | 63 | %res = tail call i8* @swiftself_param(i8* swiftself %addr1) |
| 64 | ret i8* %res |
| 65 | } |
Arnold Schwaighofer | db7bbcb | 2017-02-08 22:30:47 +0000 | [diff] [blame] | 66 | |
| 67 | ; We cannot pretend that 'r0' is alive across the thisreturn_attribute call as |
| 68 | ; we normally would. We marked the first parameter with swiftself which means it |
| 69 | ; will no longer be passed in r0. |
| 70 | declare swiftcc i8* @thisreturn_attribute(i8* returned swiftself) |
| 71 | ; OPT-LABEL: swiftself_nothisreturn: |
| 72 | ; OPT-DAG: mov [[CSREG:r[1-9].*]], r0 |
| 73 | ; OPT-DAG: ldr r10, [r10] |
| 74 | ; OPT: bl {{_?}}thisreturn_attribute |
| 75 | ; OPT: str r0, {{\[}}[[CSREG]] |
| 76 | define hidden swiftcc void @swiftself_nothisreturn(i8** noalias nocapture sret, i8** noalias nocapture readonly swiftself) { |
| 77 | entry: |
| 78 | %2 = load i8*, i8** %1, align 8 |
| 79 | %3 = tail call swiftcc i8* @thisreturn_attribute(i8* swiftself %2) |
| 80 | store i8* %3, i8** %0, align 8 |
| 81 | ret void |
| 82 | } |