@@ -1262,6 +1262,42 @@ class SyncNativeCCEntryPointArgumentEmission final
1262
1262
llvm::Value *getCoroutineBuffer () override {
1263
1263
return allParamValues.claimNext ();
1264
1264
}
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
+ };
1265
1301
1266
1302
public:
1267
1303
using SyncEntryPointArgumentEmission::requiresIndirectResult;
@@ -1312,10 +1348,8 @@ class AsyncNativeCCEntryPointArgumentEmission final
1312
1348
return loadValue (contextLayout);
1313
1349
}
1314
1350
Explosion getArgumentExplosion (unsigned index, unsigned size) override {
1315
- assert (size > 0 );
1316
1351
auto argumentLayout = layout.getArgumentLayout (index);
1317
1352
auto result = loadExplosion (argumentLayout);
1318
- assert (result.size () == size);
1319
1353
return result;
1320
1354
}
1321
1355
bool requiresIndirectResult (SILType retType) override { return false ; }
@@ -1380,6 +1414,14 @@ class AsyncNativeCCEntryPointArgumentEmission final
1380
1414
llvm_unreachable (
1381
1415
" async functions do not use a fixed size coroutine buffer" );
1382
1416
}
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
+ };
1383
1425
};
1384
1426
1385
1427
std::unique_ptr<NativeCCEntryPointArgumentEmission>
@@ -1654,8 +1696,9 @@ static ArrayRef<SILArgument *> emitEntryPointIndirectReturn(
1654
1696
}
1655
1697
1656
1698
template <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,
1659
1702
ExplosionForArgument explosionForArgument) {
1660
1703
// Pull out the parameter value and its formal type.
1661
1704
auto ¶mTI = IGF.getTypeInfo (IGF.CurSILFn ->mapTypeIntoContext (paramTy));
@@ -1664,36 +1707,11 @@ static void bindParameter(IRGenSILFunction &IGF, unsigned index,
1664
1707
// If the SIL parameter isn't passed indirectly, we need to map it
1665
1708
// to an explosion.
1666
1709
if (param->getType ().isObject ()) {
1667
- Explosion paramValues;
1668
1710
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);
1697
1715
IGF.setLoweredExplosion (param, paramValues);
1698
1716
return ;
1699
1717
}
@@ -1764,7 +1782,7 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF,
1764
1782
params = params.drop_back ();
1765
1783
1766
1784
bindParameter (
1767
- IGF, 0 , selfParam,
1785
+ IGF, *emission, 0 , selfParam,
1768
1786
conv.getSILArgumentType (conv.getNumSILArguments () - 1 ,
1769
1787
IGF.IGM .getMaximalTypeExpansionContext ()),
1770
1788
[&](unsigned startIndex, unsigned size) {
@@ -1788,7 +1806,7 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF,
1788
1806
unsigned i = 0 ;
1789
1807
for (SILArgument *param : params) {
1790
1808
auto argIdx = conv.getSILArgIndexOfFirstParam () + i;
1791
- bindParameter (IGF, i, param,
1809
+ bindParameter (IGF, *emission, i, param,
1792
1810
conv.getSILArgumentType (
1793
1811
argIdx, IGF.IGM .getMaximalTypeExpansionContext ()),
1794
1812
[&](unsigned index, unsigned size) {
0 commit comments