Skip to content

Commit 9e60894

Browse files
committed
[NFC] IRGen: Deduplicated function implementation.
The same explosion is used for every object regardless of whether the call is sync or async.
1 parent 256d46a commit 9e60894

File tree

2 files changed

+38
-74
lines changed

2 files changed

+38
-74
lines changed

lib/IRGen/EntryPointArgumentEmission.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ class NativeCCEntryPointArgumentEmission
5151
virtual llvm::Value *getSelfWitnessTable() = 0;
5252
virtual llvm::Value *getSelfMetadata() = 0;
5353
virtual llvm::Value *getCoroutineBuffer() = 0;
54-
virtual Explosion
54+
Explosion
5555
explosionForObject(IRGenFunction &IGF, unsigned index, SILArgument *param,
5656
SILType paramTy, const LoadableTypeInfo &loadableParamTI,
5757
const LoadableTypeInfo &loadableArgTI,
5858
std::function<Explosion(unsigned index, unsigned size)>
59-
explosionForArgument) = 0;
59+
explosionForArgument);
6060
};
6161

6262
} // end namespace irgen

lib/IRGen/IRGenSIL.cpp

Lines changed: 36 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,42 @@ static AsyncContextLayout getAsyncContextLayout(IRGenSILFunction &IGF) {
15671567
return getAsyncContextLayout(IGF.IGM, IGF.CurSILFn);
15681568
}
15691569

1570+
Explosion NativeCCEntryPointArgumentEmission::explosionForObject(
1571+
IRGenFunction &IGF, unsigned index, SILArgument *param, SILType paramTy,
1572+
const LoadableTypeInfo &loadableParamTI,
1573+
const LoadableTypeInfo &loadableArgTI,
1574+
std::function<Explosion(unsigned index, unsigned size)>
1575+
explosionForArgument) {
1576+
Explosion paramValues;
1577+
// If the explosion must be passed indirectly, load the value from the
1578+
// indirect address.
1579+
auto &nativeSchema = loadableArgTI.nativeParameterValueSchema(IGF.IGM);
1580+
if (nativeSchema.requiresIndirect()) {
1581+
Explosion paramExplosion = explosionForArgument(index, 1);
1582+
Address paramAddr =
1583+
loadableParamTI.getAddressForPointer(paramExplosion.claimNext());
1584+
if (loadableParamTI.getStorageType() != loadableArgTI.getStorageType())
1585+
paramAddr = loadableArgTI.getAddressForPointer(IGF.Builder.CreateBitCast(
1586+
paramAddr.getAddress(),
1587+
loadableArgTI.getStorageType()->getPointerTo()));
1588+
loadableArgTI.loadAsTake(IGF, paramAddr, paramValues);
1589+
} else {
1590+
if (!nativeSchema.empty()) {
1591+
// Otherwise, we map from the native convention to the type's explosion
1592+
// schema.
1593+
Explosion nativeParam;
1594+
unsigned size = nativeSchema.size();
1595+
Explosion paramExplosion = explosionForArgument(index, size);
1596+
paramExplosion.transferInto(nativeParam, size);
1597+
paramValues = nativeSchema.mapFromNative(IGF.IGM, IGF, nativeParam,
1598+
param->getType());
1599+
} else {
1600+
assert(loadableParamTI.getSchema().empty());
1601+
}
1602+
}
1603+
return paramValues;
1604+
}
1605+
15701606
namespace {
15711607
class SyncEntryPointArgumentEmission
15721608
: public virtual EntryPointArgumentEmission {
@@ -1652,42 +1688,6 @@ class SyncNativeCCEntryPointArgumentEmission final
16521688
llvm::Value *getCoroutineBuffer() override {
16531689
return allParamValues.claimNext();
16541690
}
1655-
Explosion
1656-
explosionForObject(IRGenFunction &IGF, unsigned index, SILArgument *param,
1657-
SILType paramTy, const LoadableTypeInfo &loadableParamTI,
1658-
const LoadableTypeInfo &loadableArgTI,
1659-
std::function<Explosion(unsigned index, unsigned size)>
1660-
explosionForArgument) override {
1661-
Explosion paramValues;
1662-
// If the explosion must be passed indirectly, load the value from the
1663-
// indirect address.
1664-
auto &nativeSchema = loadableArgTI.nativeParameterValueSchema(IGF.IGM);
1665-
if (nativeSchema.requiresIndirect()) {
1666-
Explosion paramExplosion = explosionForArgument(index, 1);
1667-
Address paramAddr =
1668-
loadableParamTI.getAddressForPointer(paramExplosion.claimNext());
1669-
if (loadableParamTI.getStorageType() != loadableArgTI.getStorageType())
1670-
paramAddr =
1671-
loadableArgTI.getAddressForPointer(IGF.Builder.CreateBitCast(
1672-
paramAddr.getAddress(),
1673-
loadableArgTI.getStorageType()->getPointerTo()));
1674-
loadableArgTI.loadAsTake(IGF, paramAddr, paramValues);
1675-
} else {
1676-
if (!nativeSchema.empty()) {
1677-
// Otherwise, we map from the native convention to the type's explosion
1678-
// schema.
1679-
Explosion nativeParam;
1680-
unsigned size = nativeSchema.size();
1681-
Explosion paramExplosion = explosionForArgument(index, size);
1682-
paramExplosion.transferInto(nativeParam, size);
1683-
paramValues = nativeSchema.mapFromNative(IGF.IGM, IGF, nativeParam,
1684-
param->getType());
1685-
} else {
1686-
assert(loadableParamTI.getSchema().empty());
1687-
}
1688-
}
1689-
return paramValues;
1690-
};
16911691

16921692
public:
16931693
using SyncEntryPointArgumentEmission::requiresIndirectResult;
@@ -1767,42 +1767,6 @@ class AsyncNativeCCEntryPointArgumentEmission final
17671767
llvm_unreachable(
17681768
"async functions do not use a fixed size coroutine buffer");
17691769
}
1770-
Explosion
1771-
explosionForObject(IRGenFunction &IGF, unsigned index, SILArgument *param,
1772-
SILType paramTy, const LoadableTypeInfo &loadableParamTI,
1773-
const LoadableTypeInfo &loadableArgTI,
1774-
std::function<Explosion(unsigned index, unsigned size)>
1775-
explosionForArgument) override {
1776-
Explosion paramValues;
1777-
// If the explosion must be passed indirectly, load the value from the
1778-
// indirect address.
1779-
auto &nativeSchema = loadableArgTI.nativeParameterValueSchema(IGF.IGM);
1780-
if (nativeSchema.requiresIndirect()) {
1781-
Explosion paramExplosion = explosionForArgument(index, 1);
1782-
Address paramAddr =
1783-
loadableParamTI.getAddressForPointer(paramExplosion.claimNext());
1784-
if (loadableParamTI.getStorageType() != loadableArgTI.getStorageType())
1785-
paramAddr =
1786-
loadableArgTI.getAddressForPointer(IGF.Builder.CreateBitCast(
1787-
paramAddr.getAddress(),
1788-
loadableArgTI.getStorageType()->getPointerTo()));
1789-
loadableArgTI.loadAsTake(IGF, paramAddr, paramValues);
1790-
} else {
1791-
if (!nativeSchema.empty()) {
1792-
// Otherwise, we map from the native convention to the type's explosion
1793-
// schema.
1794-
Explosion nativeParam;
1795-
unsigned size = nativeSchema.size();
1796-
Explosion paramExplosion = explosionForArgument(index, size);
1797-
paramExplosion.transferInto(nativeParam, size);
1798-
paramValues = nativeSchema.mapFromNative(IGF.IGM, IGF, nativeParam,
1799-
param->getType());
1800-
} else {
1801-
assert(loadableParamTI.getSchema().empty());
1802-
}
1803-
}
1804-
return paramValues;
1805-
};
18061770
};
18071771

18081772
std::unique_ptr<NativeCCEntryPointArgumentEmission>

0 commit comments

Comments
 (0)