Skip to content

Commit 02fa099

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 3e0ea3a commit 02fa099

File tree

4 files changed

+130
-80
lines changed

4 files changed

+130
-80
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ void SignatureExpansion::expandCoroutineResult(bool forContinuation) {
856856
auto fnConv = getSILFuncConventions();
857857
for (auto yield : FnType->getYields()) {
858858
YieldSchema schema(IGM, fnConv, yield);
859-
860859
// If the individual value must be yielded indirectly, add a pointer.
861860
if (schema.isIndirect()) {
862861
components.push_back(schema.getIndirectPointerType(IGM));
@@ -870,26 +869,30 @@ void SignatureExpansion::expandCoroutineResult(bool forContinuation) {
870869
}
871870

872871
// Find the maximal sequence of the component types that we can
873-
// convince the ABI to pass directly.
872+
// convince the ABI to pass directly if the target supports
873+
// directly returning at least two pointers.
874874
// When counting components, ignore the continuation pointer.
875-
unsigned numDirectComponents = components.size() - 1;
876875
SmallVector<llvm::Type*, 8> overflowTypes;
877-
while (clang::CodeGen::swiftcall::
878-
shouldPassIndirectly(IGM.ClangCodeGen->CGM(), components,
879-
/*asReturnValue*/ true)) {
880-
// If we added a pointer to the end of components, remove it.
881-
if (!overflowTypes.empty()) components.pop_back();
876+
unsigned numDirectComponents = components.size() - 1;
877+
if (IGM.TargetInfo.SupportsDirectReturningAtLeastTwoPointers) {
878+
while (clang::CodeGen::swiftcall::shouldPassIndirectly(
879+
IGM.ClangCodeGen->CGM(), components,
880+
/*asReturnValue*/ true)) {
881+
// If we added a pointer to the end of components, remove it.
882+
if (!overflowTypes.empty())
883+
components.pop_back();
882884

883-
// Remove the last component and add it as an overflow type.
884-
overflowTypes.push_back(components.pop_back_val());
885-
--numDirectComponents;
885+
// Remove the last component and add it as an overflow type.
886+
overflowTypes.push_back(components.pop_back_val());
887+
--numDirectComponents;
886888

887-
// Add a pointer to the end of components.
888-
components.push_back(IGM.Int8PtrTy);
889-
}
889+
// Add a pointer to the end of components.
890+
components.push_back(IGM.Int8PtrTy);
891+
}
890892

891-
// We'd better have been able to pass at least two pointers.
892-
assert(components.size() >= 2 || overflowTypes.empty());
893+
// We'd better have been able to pass at least two pointers.
894+
assert(components.size() >= 2 || overflowTypes.empty());
895+
}
893896
CoroInfo.NumDirectYieldComponents = numDirectComponents;
894897

895898
// Replace the pointer type we added to components with the real

0 commit comments

Comments
 (0)