[llvm] r352408 - [CodeExtractor] Add support for the `swifterror` attribute

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 28 11:13:37 PST 2019


Author: vedantk
Date: Mon Jan 28 11:13:37 2019
New Revision: 352408

URL: http://llvm.org/viewvc/llvm-project?rev=352408&view=rev
Log:
[CodeExtractor] Add support for the `swifterror` attribute

When passing a `swifterror` argument or alloca as an input to an
extraction region, mark the input parameter `swifterror`.

Added:
    llvm/trunk/test/Transforms/HotColdSplit/swifterror.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp

Modified: llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp?rev=352408&r1=352407&r2=352408&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp Mon Jan 28 11:13:37 2019
@@ -961,11 +961,18 @@ CallInst *CodeExtractor::emitCallAndSwit
   CallInst *call = nullptr;
 
   // Add inputs as params, or to be filled into the struct
-  for (Value *input : inputs)
+  unsigned ArgNo = 0;
+  SmallVector<unsigned, 1> SwiftErrorArgs;
+  for (Value *input : inputs) {
     if (AggregateArgs)
       StructValues.push_back(input);
-    else
+    else {
       params.push_back(input);
+      if (input->isSwiftError())
+        SwiftErrorArgs.push_back(ArgNo);
+    }
+    ++ArgNo;
+  }
 
   // Create allocas for the outputs
   for (Value *output : outputs) {
@@ -1021,6 +1028,12 @@ CallInst *CodeExtractor::emitCallAndSwit
   }
   codeReplacer->getInstList().push_back(call);
 
+  // Set swifterror parameter attributes.
+  for (unsigned SwiftErrArgNo : SwiftErrorArgs) {
+    call->addParamAttr(SwiftErrArgNo, Attribute::SwiftError);
+    newFunction->addParamAttr(SwiftErrArgNo, Attribute::SwiftError);
+  }
+
   Function::arg_iterator OutputArgBegin = newFunction->arg_begin();
   unsigned FirstOut = inputs.size();
   if (!AggregateArgs)

Added: llvm/trunk/test/Transforms/HotColdSplit/swifterror.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/HotColdSplit/swifterror.ll?rev=352408&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/HotColdSplit/swifterror.ll (added)
+++ llvm/trunk/test/Transforms/HotColdSplit/swifterror.ll Mon Jan 28 11:13:37 2019
@@ -0,0 +1,43 @@
+; RUN: opt -hotcoldsplit -hotcoldsplit-threshold=0 -S < %s | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.14.0"
+
+%swift_error = type {i64, i8}
+
+declare void @sink() cold
+
+; CHECK-LABEL: define {{.*}}@in_arg(
+; CHECK: call void @in_arg.cold.1(%swift_error** swifterror
+define void @in_arg(%swift_error** swifterror %error_ptr_ref) {
+  br i1 undef, label %cold, label %exit
+
+cold:
+  store %swift_error* undef, %swift_error** %error_ptr_ref
+  call void @sink()
+  br label %exit
+
+exit:
+  ret void
+}
+
+; CHECK-LABEL: define {{.*}}@in_alloca(
+; CHECK: call void @in_alloca.cold.1(%swift_error** swifterror
+define void @in_alloca() {
+  %err = alloca swifterror %swift_error*
+  br i1 undef, label %cold, label %exit
+
+cold:
+  store %swift_error* undef, %swift_error** %err
+  call void @sink()
+  br label %exit
+
+exit:
+  ret void
+}
+
+; CHECK-LABEL: define {{.*}}@in_arg.cold.1({{.*}} swifterror
+; CHECK: call {{.*}}@sink
+
+; CHECK-LABEL: define {{.*}}@in_alloca.cold.1({{.*}} swifterror
+; CHECK: call {{.*}}@sink




More information about the llvm-commits mailing list