Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,22 +867,26 @@ void SignatureExpansion::expandCoroutineResult(bool forContinuation) {
}

// Find the maximal sequence of the component types that we can
// convince the ABI to pass directly.
// convince the ABI to pass directly if the target supports
// directly returning at least two pointers.
// When counting components, ignore the continuation pointer.
unsigned numDirectComponents = components.size() - 1;
SmallVector<llvm::Type*, 8> overflowTypes;
while (clang::CodeGen::swiftcall::
shouldPassIndirectly(IGM.ClangCodeGen->CGM(), components,
/*asReturnValue*/ true)) {
// If we added a pointer to the end of components, remove it.
if (!overflowTypes.empty()) components.pop_back();

// Remove the last component and add it as an overflow type.
overflowTypes.push_back(components.pop_back_val());
--numDirectComponents;

// Add a pointer to the end of components.
components.push_back(IGM.Int8PtrTy);
if (IGM.TargetInfo.SupportsDirectReturningAtLeastTwoPointers) {
while (clang::CodeGen::swiftcall::shouldPassIndirectly(
IGM.ClangCodeGen->CGM(), components,
/*asReturnValue*/ true)) {
// If we added a pointer to the end of components, remove it.
if (!overflowTypes.empty())
components.pop_back();

// Remove the last component and add it as an overflow type.
overflowTypes.push_back(components.pop_back_val());
--numDirectComponents;

// Add a pointer to the end of components.
components.push_back(IGM.Int8PtrTy);
}
}

// We'd better have been able to pass at least two pointers.
Expand Down
10 changes: 8 additions & 2 deletions lib/IRGen/SwiftTargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

#include "SwiftTargetInfo.h"
#include "IRGenModule.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/IR/DataLayout.h"
#include "swift/ABI/System.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/IRGenOptions.h"
#include "swift/Basic/Platform.h"
#include "clang/CodeGen/SwiftCallingConv.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/TargetParser/Triple.h"

using namespace swift;
using namespace irgen;
Expand Down Expand Up @@ -186,6 +187,11 @@ static void configureWasm32(IRGenModule &IGM, const llvm::Triple &triple,
SwiftTargetInfo &target) {
target.LeastValidPointerValue =
SWIFT_ABI_WASM32_LEAST_VALID_POINTER;

target.SupportsDirectReturningAtLeastTwoPointers =
clang::CodeGen::swiftcall::shouldPassIndirectly(IGM.getClangCGM(),
{IGM.PtrTy, IGM.PtrTy},
/*asReturnValue*/ true);
}

/// Configure a default target.
Expand Down
3 changes: 3 additions & 0 deletions lib/IRGen/SwiftTargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class SwiftTargetInfo {
bool SwiftRetainIgnoresNegativeValues = false;

bool UsableSwiftAsyncContextAddrIntrinsic = false;

/// True if the target supports directly returning at least two pointers.
bool SupportsDirectReturningAtLeastTwoPointers = true;
};

}
Expand Down