Skip to content

Commit f6b81f8

Browse files
[IRGen][wasm] Disable manual indirection for coroutine yielding results
`clang::CodeGen::swiftcall::shouldPassIndirectly` now returns true for multiple scalar values on wasm targets because the Wasm MVP does not support multiple return values. For such targets where we can't directly return two pointers, we should not attempt to indirect at this stage because the later MC lowering will also indirect the return.
1 parent a07ea37 commit f6b81f8

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -867,22 +867,26 @@ void SignatureExpansion::expandCoroutineResult(bool forContinuation) {
867867
}
868868

869869
// Find the maximal sequence of the component types that we can
870-
// convince the ABI to pass directly.
870+
// convince the ABI to pass directly if the target supports
871+
// directly returning at least two pointers.
871872
// When counting components, ignore the continuation pointer.
872873
unsigned numDirectComponents = components.size() - 1;
873874
SmallVector<llvm::Type*, 8> overflowTypes;
874-
while (clang::CodeGen::swiftcall::
875-
shouldPassIndirectly(IGM.ClangCodeGen->CGM(), components,
876-
/*asReturnValue*/ true)) {
877-
// If we added a pointer to the end of components, remove it.
878-
if (!overflowTypes.empty()) components.pop_back();
879-
880-
// Remove the last component and add it as an overflow type.
881-
overflowTypes.push_back(components.pop_back_val());
882-
--numDirectComponents;
883-
884-
// Add a pointer to the end of components.
885-
components.push_back(IGM.Int8PtrTy);
875+
if (IGM.TargetInfo.SupportsDirectReturningAtLeastTwoPointers) {
876+
while (clang::CodeGen::swiftcall::shouldPassIndirectly(
877+
IGM.ClangCodeGen->CGM(), components,
878+
/*asReturnValue*/ true)) {
879+
// If we added a pointer to the end of components, remove it.
880+
if (!overflowTypes.empty())
881+
components.pop_back();
882+
883+
// Remove the last component and add it as an overflow type.
884+
overflowTypes.push_back(components.pop_back_val());
885+
--numDirectComponents;
886+
887+
// Add a pointer to the end of components.
888+
components.push_back(IGM.Int8PtrTy);
889+
}
886890
}
887891

888892
// We'd better have been able to pass at least two pointers.

lib/IRGen/SwiftTargetInfo.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
#include "SwiftTargetInfo.h"
1919
#include "IRGenModule.h"
20-
#include "llvm/TargetParser/Triple.h"
21-
#include "llvm/IR/DataLayout.h"
2220
#include "swift/ABI/System.h"
2321
#include "swift/AST/ASTContext.h"
2422
#include "swift/AST/IRGenOptions.h"
2523
#include "swift/Basic/Platform.h"
24+
#include "clang/CodeGen/SwiftCallingConv.h"
25+
#include "llvm/IR/DataLayout.h"
26+
#include "llvm/TargetParser/Triple.h"
2627

2728
using namespace swift;
2829
using namespace irgen;
@@ -186,6 +187,11 @@ static void configureWasm32(IRGenModule &IGM, const llvm::Triple &triple,
186187
SwiftTargetInfo &target) {
187188
target.LeastValidPointerValue =
188189
SWIFT_ABI_WASM32_LEAST_VALID_POINTER;
190+
191+
target.SupportsDirectReturningAtLeastTwoPointers =
192+
clang::CodeGen::swiftcall::shouldPassIndirectly(IGM.getClangCGM(),
193+
{IGM.PtrTy, IGM.PtrTy},
194+
/*asReturnValue*/ true);
189195
}
190196

191197
/// Configure a default target.

lib/IRGen/SwiftTargetInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ class SwiftTargetInfo {
115115
bool SwiftRetainIgnoresNegativeValues = false;
116116

117117
bool UsableSwiftAsyncContextAddrIntrinsic = false;
118+
119+
/// True if the target supports directly returning at least two pointers.
120+
bool SupportsDirectReturningAtLeastTwoPointers = true;
118121
};
119122

120123
}

0 commit comments

Comments
 (0)