Skip to content

Commit aa3ca98

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 aa3ca98

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ static void configureWasm32(IRGenModule &IGM, const llvm::Triple &triple,
186186
SwiftTargetInfo &target) {
187187
target.LeastValidPointerValue =
188188
SWIFT_ABI_WASM32_LEAST_VALID_POINTER;
189+
190+
target.SupportsDirectReturningAtLeastTwoPointers =
191+
clang::CodeGen::swiftcall::shouldPassIndirectly(IGM.getClangCGM(),
192+
{IGM.PtrTy, IGM.PtrTy},
193+
/*asReturnValue*/ true);
189194
}
190195

191196
/// 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)