]> granicus.if.org Git - llvm/commitdiff
CodeGen: support SwiftError SwiftCC on Windows x64
authorSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 20 Sep 2017 18:40:59 +0000 (18:40 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 20 Sep 2017 18:40:59 +0000 (18:40 +0000)
Add support for passing SwiftError through a register on the Windows x64
calling convention.  This allows the use of swifterror attributes on
parameters which is used by the swift front end for the `Error`
parameter.  This partially enables building the swift standard library
for Windows x86_64.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313791 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/Target/X86/X86CallingConv.td
test/CodeGen/X86/swift-error.ll [new file with mode: 0644]

index 9acaa446447b24a2b26da29c25fe9dacd4c73d97..15d06871e70d9c6abb9dd64ad7abeb1039c4306a 100644 (file)
@@ -1253,6 +1253,8 @@ static void propagateSwiftErrorVRegs(FunctionLoweringInfo *FuncInfo) {
       // If we don't need a phi create a copy to the upward exposed vreg.
       if (!needPHI) {
         assert(UpwardsUse);
+        assert(!VRegs.empty() &&
+               "No predecessors?  Is the Calling Convention correct?");
         unsigned DestReg = UUseVReg;
         BuildMI(*MBB, MBB->getFirstNonPHI(), DLoc, TII->get(TargetOpcode::COPY),
                 DestReg)
index 26461986427d2d8be14eefafd681ae26f7aea187..64c813915785bf2c1d194cd6912b3a7091fbdd72 100644 (file)
@@ -592,6 +592,9 @@ def CC_X86_Win64_C : CallingConv<[
   // The 'nest' parameter, if any, is passed in R10.
   CCIfNest<CCAssignToReg<[R10]>>,
 
+  // A SwiftError is passed in R12.
+  CCIfSwiftError<CCIfType<[i64], CCAssignToReg<[R12]>>>,
+
   // 128 bit vectors are passed by pointer
   CCIfType<[v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], CCPassIndirect<i64>>,
 
diff --git a/test/CodeGen/X86/swift-error.ll b/test/CodeGen/X86/swift-error.ll
new file mode 100644 (file)
index 0000000..5fb67d4
--- /dev/null
@@ -0,0 +1,18 @@
+; RUN: llc -mtriple x86_64-unknown-windows-msvc -filetype asm -o - %s | FileCheck %s
+
+%swift.error = type opaque
+
+declare swiftcc void @f(%swift.error** swifterror)
+
+define swiftcc void @g(i8*, i8*, i8*, i8*, %swift.error** swifterror %error) {
+entry:
+  call swiftcc void @f(%swift.error** nonnull nocapture swifterror %error)
+  ret void
+}
+
+; CHECK-LABEL: g
+; CHECK: pushq   %r12
+; CHECK: callq   f
+; CHECK: popq    %r12
+; CHECK: retq
+