Skip to content

Revert "[Async CC] Never map to native explosions." #34749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
11 changes: 0 additions & 11 deletions lib/IRGen/EntryPointArgumentEmission.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ class Value;
}

namespace swift {

class SILArgument;

namespace irgen {

class Explosion;
struct GenericRequirement;
class LoadableTypeInfo;
class TypeInfo;

class EntryPointArgumentEmission {

Expand All @@ -49,12 +44,6 @@ class NativeCCEntryPointArgumentEmission
virtual llvm::Value *getSelfWitnessTable() = 0;
virtual llvm::Value *getSelfMetadata() = 0;
virtual llvm::Value *getCoroutineBuffer() = 0;
virtual Explosion
explosionForObject(IRGenFunction &IGF, unsigned index, SILArgument *param,
SILType paramTy, const LoadableTypeInfo &loadableParamTI,
const LoadableTypeInfo &loadableArgTI,
std::function<Explosion(unsigned index, unsigned size)>
explosionForArgument) = 0;
};

} // end namespace irgen
Expand Down
88 changes: 35 additions & 53 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,42 +1262,6 @@ class SyncNativeCCEntryPointArgumentEmission final
llvm::Value *getCoroutineBuffer() override {
return allParamValues.claimNext();
}
Explosion
explosionForObject(IRGenFunction &IGF, unsigned index, SILArgument *param,
SILType paramTy, const LoadableTypeInfo &loadableParamTI,
const LoadableTypeInfo &loadableArgTI,
std::function<Explosion(unsigned index, unsigned size)>
explosionForArgument) override {
Explosion paramValues;
// If the explosion must be passed indirectly, load the value from the
// indirect address.
auto &nativeSchema = loadableArgTI.nativeParameterValueSchema(IGF.IGM);
if (nativeSchema.requiresIndirect()) {
Explosion paramExplosion = explosionForArgument(index, 1);
Address paramAddr =
loadableParamTI.getAddressForPointer(paramExplosion.claimNext());
if (loadableParamTI.getStorageType() != loadableArgTI.getStorageType())
paramAddr =
loadableArgTI.getAddressForPointer(IGF.Builder.CreateBitCast(
paramAddr.getAddress(),
loadableArgTI.getStorageType()->getPointerTo()));
loadableArgTI.loadAsTake(IGF, paramAddr, paramValues);
} else {
if (!nativeSchema.empty()) {
// Otherwise, we map from the native convention to the type's explosion
// schema.
Explosion nativeParam;
unsigned size = nativeSchema.size();
Explosion paramExplosion = explosionForArgument(index, size);
paramExplosion.transferInto(nativeParam, size);
paramValues = nativeSchema.mapFromNative(IGF.IGM, IGF, nativeParam,
param->getType());
} else {
assert(loadableParamTI.getSchema().empty());
}
}
return paramValues;
};

public:
using SyncEntryPointArgumentEmission::requiresIndirectResult;
Expand Down Expand Up @@ -1348,8 +1312,10 @@ class AsyncNativeCCEntryPointArgumentEmission final
return loadValue(contextLayout);
}
Explosion getArgumentExplosion(unsigned index, unsigned size) override {
assert(size > 0);
auto argumentLayout = layout.getArgumentLayout(index);
auto result = loadExplosion(argumentLayout);
assert(result.size() == size);
return result;
}
bool requiresIndirectResult(SILType retType) override { return false; }
Expand Down Expand Up @@ -1414,14 +1380,6 @@ class AsyncNativeCCEntryPointArgumentEmission final
llvm_unreachable(
"async functions do not use a fixed size coroutine buffer");
}
Explosion
explosionForObject(IRGenFunction &IGF, unsigned index, SILArgument *param,
SILType paramTy, const LoadableTypeInfo &loadableParamTI,
const LoadableTypeInfo &loadableArgTI,
std::function<Explosion(unsigned index, unsigned size)>
explosionForArgument) override {
return explosionForArgument(index, 1);
};
};

std::unique_ptr<NativeCCEntryPointArgumentEmission>
Expand Down Expand Up @@ -1696,9 +1654,8 @@ static ArrayRef<SILArgument *> emitEntryPointIndirectReturn(
}

template <typename ExplosionForArgument>
static void bindParameter(IRGenSILFunction &IGF,
NativeCCEntryPointArgumentEmission &emission,
unsigned index, SILArgument *param, SILType paramTy,
static void bindParameter(IRGenSILFunction &IGF, unsigned index,
SILArgument *param, SILType paramTy,
ExplosionForArgument explosionForArgument) {
// Pull out the parameter value and its formal type.
auto &paramTI = IGF.getTypeInfo(IGF.CurSILFn->mapTypeIntoContext(paramTy));
Expand All @@ -1707,11 +1664,36 @@ static void bindParameter(IRGenSILFunction &IGF,
// If the SIL parameter isn't passed indirectly, we need to map it
// to an explosion.
if (param->getType().isObject()) {
Explosion paramValues;
auto &loadableParamTI = cast<LoadableTypeInfo>(paramTI);
auto &loadableArgTI = cast<LoadableTypeInfo>(argTI);
auto paramValues =
emission.explosionForObject(IGF, index, param, paramTy, loadableParamTI,
loadableArgTI, explosionForArgument);
auto &loadableArgTI = cast<LoadableTypeInfo>(paramTI);
// If the explosion must be passed indirectly, load the value from the
// indirect address.
auto &nativeSchema = argTI.nativeParameterValueSchema(IGF.IGM);
if (nativeSchema.requiresIndirect()) {
Explosion paramExplosion = explosionForArgument(index, 1);
Address paramAddr =
loadableParamTI.getAddressForPointer(paramExplosion.claimNext());
if (paramTI.getStorageType() != argTI.getStorageType())
paramAddr =
loadableArgTI.getAddressForPointer(IGF.Builder.CreateBitCast(
paramAddr.getAddress(),
loadableArgTI.getStorageType()->getPointerTo()));
loadableArgTI.loadAsTake(IGF, paramAddr, paramValues);
} else {
if (!nativeSchema.empty()) {
// Otherwise, we map from the native convention to the type's explosion
// schema.
Explosion nativeParam;
unsigned size = nativeSchema.size();
Explosion paramExplosion = explosionForArgument(index, size);
paramExplosion.transferInto(nativeParam, size);
paramValues = nativeSchema.mapFromNative(IGF.IGM, IGF, nativeParam,
param->getType());
} else {
assert(paramTI.getSchema().empty());
}
}
IGF.setLoweredExplosion(param, paramValues);
return;
}
Expand Down Expand Up @@ -1782,7 +1764,7 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF,
params = params.drop_back();

bindParameter(
IGF, *emission, 0, selfParam,
IGF, 0, selfParam,
conv.getSILArgumentType(conv.getNumSILArguments() - 1,
IGF.IGM.getMaximalTypeExpansionContext()),
[&](unsigned startIndex, unsigned size) {
Expand All @@ -1806,7 +1788,7 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF,
unsigned i = 0;
for (SILArgument *param : params) {
auto argIdx = conv.getSILArgIndexOfFirstParam() + i;
bindParameter(IGF, *emission, i, param,
bindParameter(IGF, i, param,
conv.getSILArgumentType(
argIdx, IGF.IGM.getMaximalTypeExpansionContext()),
[&](unsigned index, unsigned size) {
Expand Down
75 changes: 0 additions & 75 deletions test/IRGen/async/run-call-struct_five_bools-to-void.sil

This file was deleted.

26 changes: 0 additions & 26 deletions validation-test/compiler_crashers_2_fixed/rdar71260972.sil

This file was deleted.