@@ -1262,6 +1262,42 @@ class SyncNativeCCEntryPointArgumentEmission final
12621262 llvm::Value *getCoroutineBuffer () override {
12631263 return allParamValues.claimNext ();
12641264 }
1265+ Explosion
1266+ explosionForObject (IRGenFunction &IGF, unsigned index, SILArgument *param,
1267+ SILType paramTy, const LoadableTypeInfo &loadableParamTI,
1268+ const LoadableTypeInfo &loadableArgTI,
1269+ std::function<Explosion(unsigned index, unsigned size)>
1270+ explosionForArgument) override {
1271+ Explosion paramValues;
1272+ // If the explosion must be passed indirectly, load the value from the
1273+ // indirect address.
1274+ auto &nativeSchema = loadableArgTI.nativeParameterValueSchema (IGF.IGM );
1275+ if (nativeSchema.requiresIndirect ()) {
1276+ Explosion paramExplosion = explosionForArgument (index, 1 );
1277+ Address paramAddr =
1278+ loadableParamTI.getAddressForPointer (paramExplosion.claimNext ());
1279+ if (loadableParamTI.getStorageType () != loadableArgTI.getStorageType ())
1280+ paramAddr =
1281+ loadableArgTI.getAddressForPointer (IGF.Builder .CreateBitCast (
1282+ paramAddr.getAddress (),
1283+ loadableArgTI.getStorageType ()->getPointerTo ()));
1284+ loadableArgTI.loadAsTake (IGF, paramAddr, paramValues);
1285+ } else {
1286+ if (!nativeSchema.empty ()) {
1287+ // Otherwise, we map from the native convention to the type's explosion
1288+ // schema.
1289+ Explosion nativeParam;
1290+ unsigned size = nativeSchema.size ();
1291+ Explosion paramExplosion = explosionForArgument (index, size);
1292+ paramExplosion.transferInto (nativeParam, size);
1293+ paramValues = nativeSchema.mapFromNative (IGF.IGM , IGF, nativeParam,
1294+ param->getType ());
1295+ } else {
1296+ assert (loadableParamTI.getSchema ().empty ());
1297+ }
1298+ }
1299+ return paramValues;
1300+ };
12651301
12661302public:
12671303 using SyncEntryPointArgumentEmission::requiresIndirectResult;
@@ -1312,10 +1348,8 @@ class AsyncNativeCCEntryPointArgumentEmission final
13121348 return loadValue (contextLayout);
13131349 }
13141350 Explosion getArgumentExplosion (unsigned index, unsigned size) override {
1315- assert (size > 0 );
13161351 auto argumentLayout = layout.getArgumentLayout (index);
13171352 auto result = loadExplosion (argumentLayout);
1318- assert (result.size () == size);
13191353 return result;
13201354 }
13211355 bool requiresIndirectResult (SILType retType) override { return false ; }
@@ -1380,6 +1414,14 @@ class AsyncNativeCCEntryPointArgumentEmission final
13801414 llvm_unreachable (
13811415 " async functions do not use a fixed size coroutine buffer" );
13821416 }
1417+ Explosion
1418+ explosionForObject (IRGenFunction &IGF, unsigned index, SILArgument *param,
1419+ SILType paramTy, const LoadableTypeInfo &loadableParamTI,
1420+ const LoadableTypeInfo &loadableArgTI,
1421+ std::function<Explosion(unsigned index, unsigned size)>
1422+ explosionForArgument) override {
1423+ return explosionForArgument (index, 1 );
1424+ };
13831425};
13841426
13851427std::unique_ptr<NativeCCEntryPointArgumentEmission>
@@ -1654,8 +1696,9 @@ static ArrayRef<SILArgument *> emitEntryPointIndirectReturn(
16541696}
16551697
16561698template <typename ExplosionForArgument>
1657- static void bindParameter (IRGenSILFunction &IGF, unsigned index,
1658- SILArgument *param, SILType paramTy,
1699+ static void bindParameter (IRGenSILFunction &IGF,
1700+ NativeCCEntryPointArgumentEmission &emission,
1701+ unsigned index, SILArgument *param, SILType paramTy,
16591702 ExplosionForArgument explosionForArgument) {
16601703 // Pull out the parameter value and its formal type.
16611704 auto ¶mTI = IGF.getTypeInfo (IGF.CurSILFn ->mapTypeIntoContext (paramTy));
@@ -1664,36 +1707,11 @@ static void bindParameter(IRGenSILFunction &IGF, unsigned index,
16641707 // If the SIL parameter isn't passed indirectly, we need to map it
16651708 // to an explosion.
16661709 if (param->getType ().isObject ()) {
1667- Explosion paramValues;
16681710 auto &loadableParamTI = cast<LoadableTypeInfo>(paramTI);
1669- auto &loadableArgTI = cast<LoadableTypeInfo>(paramTI);
1670- // If the explosion must be passed indirectly, load the value from the
1671- // indirect address.
1672- auto &nativeSchema = argTI.nativeParameterValueSchema (IGF.IGM );
1673- if (nativeSchema.requiresIndirect ()) {
1674- Explosion paramExplosion = explosionForArgument (index, 1 );
1675- Address paramAddr =
1676- loadableParamTI.getAddressForPointer (paramExplosion.claimNext ());
1677- if (paramTI.getStorageType () != argTI.getStorageType ())
1678- paramAddr =
1679- loadableArgTI.getAddressForPointer (IGF.Builder .CreateBitCast (
1680- paramAddr.getAddress (),
1681- loadableArgTI.getStorageType ()->getPointerTo ()));
1682- loadableArgTI.loadAsTake (IGF, paramAddr, paramValues);
1683- } else {
1684- if (!nativeSchema.empty ()) {
1685- // Otherwise, we map from the native convention to the type's explosion
1686- // schema.
1687- Explosion nativeParam;
1688- unsigned size = nativeSchema.size ();
1689- Explosion paramExplosion = explosionForArgument (index, size);
1690- paramExplosion.transferInto (nativeParam, size);
1691- paramValues = nativeSchema.mapFromNative (IGF.IGM , IGF, nativeParam,
1692- param->getType ());
1693- } else {
1694- assert (paramTI.getSchema ().empty ());
1695- }
1696- }
1711+ auto &loadableArgTI = cast<LoadableTypeInfo>(argTI);
1712+ auto paramValues =
1713+ emission.explosionForObject (IGF, index, param, paramTy, loadableParamTI,
1714+ loadableArgTI, explosionForArgument);
16971715 IGF.setLoweredExplosion (param, paramValues);
16981716 return ;
16991717 }
@@ -1764,7 +1782,7 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF,
17641782 params = params.drop_back ();
17651783
17661784 bindParameter (
1767- IGF, 0 , selfParam,
1785+ IGF, *emission, 0 , selfParam,
17681786 conv.getSILArgumentType (conv.getNumSILArguments () - 1 ,
17691787 IGF.IGM .getMaximalTypeExpansionContext ()),
17701788 [&](unsigned startIndex, unsigned size) {
@@ -1788,7 +1806,7 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF,
17881806 unsigned i = 0 ;
17891807 for (SILArgument *param : params) {
17901808 auto argIdx = conv.getSILArgIndexOfFirstParam () + i;
1791- bindParameter (IGF, i, param,
1809+ bindParameter (IGF, *emission, i, param,
17921810 conv.getSILArgumentType (
17931811 argIdx, IGF.IGM .getMaximalTypeExpansionContext ()),
17941812 [&](unsigned index, unsigned size) {
0 commit comments