Swift Calling Convention: add swiftself attribute.

Differential Revision: http://reviews.llvm.org/D17866

llvm-svn: 264754
diff --git a/llvm/test/Bitcode/attributes.ll b/llvm/test/Bitcode/attributes.ll
index 1b3526f..74b0386 100644
--- a/llvm/test/Bitcode/attributes.ll
+++ b/llvm/test/Bitcode/attributes.ll
@@ -287,6 +287,12 @@
   ret void
 }
 
+; CHECK: define void @f50(i8* swiftself)
+define void @f50(i8* swiftself)
+{
+  ret void;
+}
+
 ; CHECK: attributes #0 = { noreturn }
 ; CHECK: attributes #1 = { nounwind }
 ; CHECK: attributes #2 = { readnone }
diff --git a/llvm/test/CodeGen/AArch64/swiftself.ll b/llvm/test/CodeGen/AArch64/swiftself.ll
new file mode 100644
index 0000000..f93f8f3
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/swiftself.ll
@@ -0,0 +1,29 @@
+; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-apple-ios | FileCheck --check-prefix=CHECK-APPLE %s
+; RUN: llc -O0 -verify-machineinstrs < %s -mtriple=aarch64-apple-ios | FileCheck --check-prefix=CHECK-O0 %s
+
+; Parameter with swiftself should be allocated to x9.
+define void @check_swiftself(i32* swiftself %addr0) {
+; CHECK-APPLE-LABEL: check_swiftself:
+; CHECK-O0-LABEL: check_swiftself:
+
+    %val0 = load volatile i32, i32* %addr0
+; CHECK-APPLE: ldr w{{.*}}, [x9]
+; CHECK-O0: ldr w{{.*}}, [x9]
+    ret void
+}
+
+@var8_3 = global i8 0
+declare void @take_swiftself(i8* swiftself %addr0)
+
+define void @simple_args() {
+; CHECK-APPLE-LABEL: simple_args:
+; CHECK-O0-LABEL: simple_args:
+
+  call void @take_swiftself(i8* @var8_3)
+; CHECK-APPLE: add x9,
+; CHECK-APPLE: bl {{_?}}take_swiftself
+; CHECK-O0: add x9,
+; CHECK-O0: bl {{_?}}take_swiftself
+
+  ret void
+}
diff --git a/llvm/test/CodeGen/ARM/swiftself.ll b/llvm/test/CodeGen/ARM/swiftself.ll
new file mode 100644
index 0000000..cbeedc4
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/swiftself.ll
@@ -0,0 +1,32 @@
+; RUN: llc -verify-machineinstrs < %s -mtriple=armv7k-apple-ios8.0 -mcpu=cortex-a7 | FileCheck --check-prefix=CHECK-APPLE %s
+; RUN: llc -O0 -verify-machineinstrs < %s -mtriple=armv7k-apple-ios8.0 -mcpu=cortex-a7 | FileCheck --check-prefix=CHECK-O0 %s
+
+; RUN: llc -verify-machineinstrs < %s -mtriple=armv7-apple-ios | FileCheck --check-prefix=CHECK-APPLE %s
+; RUN: llc -O0 -verify-machineinstrs < %s -mtriple=armv7-apple-ios | FileCheck --check-prefix=CHECK-O0 %s
+
+; Parameter with swiftself should be allocated to r9.
+define void @check_swiftself(i32* swiftself %addr0) {
+; CHECK-APPLE-LABEL: check_swiftself:
+; CHECK-O0-LABEL: check_swiftself:
+
+    %val0 = load volatile i32, i32* %addr0
+; CHECK-APPLE: ldr r{{.*}}, [r9]
+; CHECK-O0: ldr r{{.*}}, [r9]
+    ret void
+}
+
+@var8_3 = global i8 0
+declare void @take_swiftself(i8* swiftself %addr0)
+
+define void @simple_args() {
+; CHECK-APPLE-LABEL: simple_args:
+; CHECK-O0-LABEL: simple_args:
+
+  call void @take_swiftself(i8* @var8_3)
+; CHECK-APPLE: add r9, pc
+; CHECK-APPLE: bl {{_?}}take_swiftself
+; CHECK-O0: add r9, pc
+; CHECK-O0: bl {{_?}}take_swiftself
+
+  ret void
+}
diff --git a/llvm/test/CodeGen/X86/swiftself.ll b/llvm/test/CodeGen/X86/swiftself.ll
new file mode 100644
index 0000000..14b0496
--- /dev/null
+++ b/llvm/test/CodeGen/X86/swiftself.ll
@@ -0,0 +1,41 @@
+; RUN: llc -verify-machineinstrs < %s -mtriple=x86_64-unknown-unknown | FileCheck %s
+; RUN: llc -O0 -verify-machineinstrs < %s -mtriple=x86_64-unknown-unknown | FileCheck --check-prefix=CHECK-O0 %s
+; RUN: llc -verify-machineinstrs < %s -march=x86 -mcpu=yonah -mtriple=i386-apple-darwin | FileCheck --check-prefix=CHECK-i386 %s
+; RUN: llc -O0 -verify-machineinstrs < %s -march=x86 -mcpu=yonah -mtriple=i386-apple-darwin | FileCheck --check-prefix=CHECK-i386-O0 %s
+
+; Parameter with swiftself should be allocated to r10.
+define void @check_swiftself(i32* swiftself %addr0) {
+; CHECK-LABEL: check_swiftself:
+; CHECK-O0-LABEL: check_swiftself:
+; CHECK-i386-LABEL: check_swiftself:
+; CHECK-i386-O0-LABEL: check_swiftself:
+
+  %val0 = load volatile i32, i32* %addr0
+; CHECK: movl (%r10),
+; CHECK-O0: movl (%r10),
+; CHECK-i386: movl {{[0-9a-f]+}}(%esp)
+; CHECK-i386-O0: movl {{[0-9a-f]+}}(%esp)
+  ret void
+}
+
+@var8_3 = global i8 0
+declare void @take_swiftself(i8* swiftself %addr0)
+
+define void @simple_args() {
+; CHECK-LABEL: simple_args:
+; CHECK-O0-LABEL: simple_args:
+; CHECK-i386-LABEL: simple_args:
+; CHECK-i386-O0-LABEL: simple_args:
+
+  call void @take_swiftself(i8* @var8_3)
+; CHECK: movl {{.*}}, %r10d
+; CHECK: callq {{_?}}take_swiftself
+; CHECK-O0: movabsq {{.*}}, %r10
+; CHECK-O0: callq {{_?}}take_swiftself
+; CHECK-i386: movl {{.*}}, (%esp)
+; CHECK-i386: calll {{.*}}take_swiftself
+; CHECK-i386-O0: movl {{.*}}, (%esp)
+; CHECK-i386-O0: calll {{.*}}take_swiftself
+
+  ret void
+}
diff --git a/llvm/test/Verifier/swiftself.ll b/llvm/test/Verifier/swiftself.ll
new file mode 100644
index 0000000..18789e11
--- /dev/null
+++ b/llvm/test/Verifier/swiftself.ll
@@ -0,0 +1,4 @@
+; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+
+declare void @a(i32* swiftself %a, i32* swiftself %b)
+; CHECK: Cannot have multiple 'swiftself' parameters!