@@ -1331,15 +1331,16 @@ llvm::CallInst *IRBuilder::CreateCall(const FunctionPointer &fn,
1331
1331
1332
1332
// / Emit the result of this call to memory.
1333
1333
void CallEmission::emitToMemory (Address addr,
1334
- const LoadableTypeInfo &indirectedResultTI) {
1334
+ const LoadableTypeInfo &indirectedResultTI,
1335
+ bool isOutlined) {
1335
1336
assert (LastArgWritten <= 1 );
1336
1337
1337
1338
// If the call is naturally to an explosion, emit it that way and
1338
1339
// then initialize the temporary.
1339
1340
if (LastArgWritten == 0 ) {
1340
1341
Explosion result;
1341
- emitToExplosion (result);
1342
- indirectedResultTI.initialize (IGF, result, addr);
1342
+ emitToExplosion (result, isOutlined );
1343
+ indirectedResultTI.initialize (IGF, result, addr, isOutlined );
1343
1344
return ;
1344
1345
}
1345
1346
@@ -1373,7 +1374,7 @@ void CallEmission::emitToMemory(Address addr,
1373
1374
}
1374
1375
1375
1376
// / Emit the result of this call to an explosion.
1376
- void CallEmission::emitToExplosion (Explosion &out) {
1377
+ void CallEmission::emitToExplosion (Explosion &out, bool isOutlined ) {
1377
1378
assert (LastArgWritten <= 1 );
1378
1379
1379
1380
SILFunctionConventions fnConv (getCallee ().getSubstFunctionType (),
@@ -1389,8 +1390,8 @@ void CallEmission::emitToExplosion(Explosion &out) {
1389
1390
StackAddress ctemp = substResultTI.allocateStack (IGF, substResultType,
1390
1391
false , " call.aggresult" );
1391
1392
Address temp = ctemp.getAddress ();
1392
- emitToMemory (temp, substResultTI);
1393
-
1393
+ emitToMemory (temp, substResultTI, isOutlined );
1394
+
1394
1395
// We can use a take.
1395
1396
substResultTI.loadAsTake (IGF, temp, out);
1396
1397
@@ -1600,13 +1601,13 @@ static llvm::Type *getOutputType(TranslationDirection direction, unsigned index,
1600
1601
: nativeSchema[index].getScalarType ());
1601
1602
}
1602
1603
1603
-
1604
- static void emitCoerceAndExpand (IRGenFunction &IGF,
1605
- Explosion &in, Explosion &out, SILType paramTy,
1604
+ static void emitCoerceAndExpand (IRGenFunction &IGF, Explosion &in,
1605
+ Explosion &out, SILType paramTy,
1606
1606
const LoadableTypeInfo ¶mTI,
1607
1607
llvm::StructType *coercionTy,
1608
- ArrayRef<llvm::Type*> expandedTys,
1609
- TranslationDirection direction) {
1608
+ ArrayRef<llvm::Type *> expandedTys,
1609
+ TranslationDirection direction,
1610
+ bool isOutlined) {
1610
1611
// If we can directly coerce the scalar values, avoid going through memory.
1611
1612
auto schema = paramTI.getSchema ();
1612
1613
if (canCoerceToSchema (IGF.IGM , expandedTys, schema)) {
@@ -1641,7 +1642,7 @@ static void emitCoerceAndExpand(IRGenFunction &IGF,
1641
1642
// If we're translating *to* the foreign expansion, do an ordinary
1642
1643
// initialization from the input explosion.
1643
1644
if (direction == TranslationDirection::ToForeign) {
1644
- paramTI.initialize (IGF, in, temporary);
1645
+ paramTI.initialize (IGF, in, temporary, isOutlined );
1645
1646
}
1646
1647
1647
1648
Address coercedTemporary =
@@ -1689,7 +1690,8 @@ static void emitCoerceAndExpand(IRGenFunction &IGF,
1689
1690
1690
1691
static void emitDirectExternalArgument (IRGenFunction &IGF, SILType argType,
1691
1692
const clang::CodeGen::ABIArgInfo &AI,
1692
- Explosion &in, Explosion &out) {
1693
+ Explosion &in, Explosion &out,
1694
+ bool isOutlined) {
1693
1695
bool IsDirectFlattened = AI.isDirect () && AI.getCanBeFlattened ();
1694
1696
bool IsIndirect = !AI.isDirect ();
1695
1697
@@ -1725,7 +1727,7 @@ static void emitDirectExternalArgument(IRGenFunction &IGF, SILType argType,
1725
1727
// Store to a temporary.
1726
1728
Address tempOfArgTy = IGF.Builder .CreateBitCast (
1727
1729
temporary, argTI.getStorageType ()->getPointerTo ());
1728
- argTI.initializeFromParams (IGF, in, tempOfArgTy, argType);
1730
+ argTI.initializeFromParams (IGF, in, tempOfArgTy, argType, isOutlined );
1729
1731
1730
1732
// Bitcast the temporary to the expected type.
1731
1733
Address coercedAddr =
@@ -1783,11 +1785,10 @@ namespace {
1783
1785
1784
1786
// / Given a Swift value explosion in 'in', produce a Clang expansion
1785
1787
// / (according to ABIArgInfo::Expand) in 'out'.
1786
- static void emitClangExpandedArgument (IRGenFunction &IGF,
1787
- Explosion &in, Explosion &out,
1788
- clang::CanQualType clangType,
1789
- SILType swiftType,
1790
- const LoadableTypeInfo &swiftTI) {
1788
+ static void
1789
+ emitClangExpandedArgument (IRGenFunction &IGF, Explosion &in, Explosion &out,
1790
+ clang::CanQualType clangType, SILType swiftType,
1791
+ const LoadableTypeInfo &swiftTI, bool isOutlined) {
1791
1792
// If Clang's expansion schema matches Swift's, great.
1792
1793
auto swiftSchema = swiftTI.getSchema ();
1793
1794
if (doesClangExpansionMatchSchema (IGF.IGM , clangType, swiftSchema)) {
@@ -1797,7 +1798,7 @@ static void emitClangExpandedArgument(IRGenFunction &IGF,
1797
1798
// Otherwise, materialize to a temporary.
1798
1799
Address temp = swiftTI.allocateStack (IGF, swiftType, false ,
1799
1800
" clang-expand-arg.temp" ).getAddress ();
1800
- swiftTI.initialize (IGF, in, temp);
1801
+ swiftTI.initialize (IGF, in, temp, isOutlined );
1801
1802
1802
1803
Address castTemp = IGF.Builder .CreateBitCast (temp, IGF.IGM .Int8PtrTy );
1803
1804
ClangExpandLoadEmitter (IGF, out).visit (clangType, castTemp);
@@ -1827,7 +1828,8 @@ void irgen::emitClangExpandedParameter(IRGenFunction &IGF,
1827
1828
}
1828
1829
1829
1830
static void externalizeArguments (IRGenFunction &IGF, const Callee &callee,
1830
- Explosion &in, Explosion &out) {
1831
+ Explosion &in, Explosion &out,
1832
+ bool isOutlined) {
1831
1833
auto silConv = IGF.IGM .silConv ;
1832
1834
auto fnType = callee.getOrigFunctionType ();
1833
1835
auto params = fnType->getParameters ();
@@ -1889,7 +1891,7 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
1889
1891
break ;
1890
1892
}
1891
1893
1892
- emitDirectExternalArgument (IGF, paramType, AI, in, out);
1894
+ emitDirectExternalArgument (IGF, paramType, AI, in, out, isOutlined );
1893
1895
break ;
1894
1896
}
1895
1897
case clang::CodeGen::ABIArgInfo::Indirect: {
@@ -1906,7 +1908,7 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
1906
1908
}
1907
1909
}
1908
1910
1909
- ti.initialize (IGF, in, addr);
1911
+ ti.initialize (IGF, in, addr, isOutlined );
1910
1912
1911
1913
out.add (addr.getAddress ());
1912
1914
break ;
@@ -1916,12 +1918,13 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
1916
1918
emitCoerceAndExpand (IGF, in, out, paramType, paramTI,
1917
1919
AI.getCoerceAndExpandType (),
1918
1920
AI.getCoerceAndExpandTypeSequence (),
1919
- TranslationDirection::ToForeign);
1921
+ TranslationDirection::ToForeign, isOutlined );
1920
1922
break ;
1921
1923
}
1922
1924
case clang::CodeGen::ABIArgInfo::Expand:
1923
- emitClangExpandedArgument (IGF, in, out, clangParamTy, paramType,
1924
- cast<LoadableTypeInfo>(IGF.getTypeInfo (paramType)));
1925
+ emitClangExpandedArgument (
1926
+ IGF, in, out, clangParamTy, paramType,
1927
+ cast<LoadableTypeInfo>(IGF.getTypeInfo (paramType)), isOutlined);
1925
1928
break ;
1926
1929
case clang::CodeGen::ABIArgInfo::Ignore:
1927
1930
break ;
@@ -1934,7 +1937,8 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
1934
1937
1935
1938
// / Returns whether allocas are needed.
1936
1939
bool irgen::addNativeArgument (IRGenFunction &IGF, Explosion &in,
1937
- SILParameterInfo origParamInfo, Explosion &out) {
1940
+ SILParameterInfo origParamInfo, Explosion &out,
1941
+ bool isOutlined) {
1938
1942
// Addresses consist of a single pointer argument.
1939
1943
if (IGF.IGM .silConv .isSILIndirect (origParamInfo)) {
1940
1944
out.add (in.claimNext ());
@@ -1948,7 +1952,7 @@ bool irgen::addNativeArgument(IRGenFunction &IGF, Explosion &in,
1948
1952
// Pass the argument indirectly.
1949
1953
auto buf = IGF.createAlloca (ti.getStorageType (),
1950
1954
ti.getFixedAlignment (), " " );
1951
- ti.initialize (IGF, in, buf);
1955
+ ti.initialize (IGF, in, buf, isOutlined );
1952
1956
out.add (buf.getAddress ());
1953
1957
return true ;
1954
1958
} else {
@@ -1962,7 +1966,8 @@ bool irgen::addNativeArgument(IRGenFunction &IGF, Explosion &in,
1962
1966
// calling convention.
1963
1967
Explosion nonNativeParam;
1964
1968
ti.reexplode (IGF, in, nonNativeParam);
1965
- Explosion nativeParam = nativeSchema.mapIntoNative (IGF.IGM , IGF, nonNativeParam, paramType);
1969
+ Explosion nativeParam = nativeSchema.mapIntoNative (
1970
+ IGF.IGM , IGF, nonNativeParam, paramType, isOutlined);
1966
1971
nativeParam.transferInto (out, nativeParam.size ());
1967
1972
return false ;
1968
1973
}
@@ -2047,10 +2052,9 @@ static void emitDirectForeignParameter(IRGenFunction &IGF, Explosion &in,
2047
2052
2048
2053
void irgen::emitForeignParameter (IRGenFunction &IGF, Explosion ¶ms,
2049
2054
ForeignFunctionInfo foreignInfo,
2050
- unsigned foreignParamIndex,
2051
- SILType paramTy,
2055
+ unsigned foreignParamIndex, SILType paramTy,
2052
2056
const LoadableTypeInfo ¶mTI,
2053
- Explosion ¶mExplosion) {
2057
+ Explosion ¶mExplosion, bool isOutlined ) {
2054
2058
assert (foreignInfo.ClangInfo );
2055
2059
auto &FI = *foreignInfo.ClangInfo ;
2056
2060
@@ -2088,7 +2092,7 @@ void irgen::emitForeignParameter(IRGenFunction &IGF, Explosion ¶ms,
2088
2092
emitCoerceAndExpand (IGF, params, paramExplosion, paramTy, paramTI,
2089
2093
AI.getCoerceAndExpandType (),
2090
2094
AI.getCoerceAndExpandTypeSequence (),
2091
- TranslationDirection::ToNative);
2095
+ TranslationDirection::ToNative, isOutlined );
2092
2096
break ;
2093
2097
}
2094
2098
@@ -2102,7 +2106,7 @@ void irgen::emitForeignParameter(IRGenFunction &IGF, Explosion ¶ms,
2102
2106
2103
2107
2104
2108
// / Add a new set of arguments to the function.
2105
- void CallEmission::setArgs (Explosion &original,
2109
+ void CallEmission::setArgs (Explosion &original, bool isOutlined,
2106
2110
WitnessMetadata *witnessMetadata) {
2107
2111
// Convert arguments to a representation appropriate to the calling
2108
2112
// convention.
@@ -2119,15 +2123,15 @@ void CallEmission::setArgs(Explosion &original,
2119
2123
case SILFunctionTypeRepresentation::ObjCMethod:
2120
2124
adjusted.add (getCallee ().getObjCMethodReceiver ());
2121
2125
adjusted.add (getCallee ().getObjCMethodSelector ());
2122
- externalizeArguments (IGF, getCallee (), original, adjusted);
2126
+ externalizeArguments (IGF, getCallee (), original, adjusted, isOutlined );
2123
2127
break ;
2124
2128
2125
2129
case SILFunctionTypeRepresentation::Block:
2126
2130
adjusted.add (getCallee ().getBlockObject ());
2127
2131
LLVM_FALLTHROUGH;
2128
2132
2129
2133
case SILFunctionTypeRepresentation::CFunctionPointer:
2130
- externalizeArguments (IGF, getCallee (), original, adjusted);
2134
+ externalizeArguments (IGF, getCallee (), original, adjusted, isOutlined );
2131
2135
break ;
2132
2136
2133
2137
case SILFunctionTypeRepresentation::WitnessMethod:
@@ -2152,7 +2156,7 @@ void CallEmission::setArgs(Explosion &original,
2152
2156
params = params.drop_back ();
2153
2157
}
2154
2158
for (auto param : params) {
2155
- addNativeArgument (IGF, original, param, adjusted);
2159
+ addNativeArgument (IGF, original, param, adjusted, isOutlined );
2156
2160
}
2157
2161
2158
2162
// Anything else, just pass along. This will include things like
@@ -2577,7 +2581,8 @@ Explosion NativeConventionSchema::mapFromNative(IRGenModule &IGM,
2577
2581
Explosion NativeConventionSchema::mapIntoNative (IRGenModule &IGM,
2578
2582
IRGenFunction &IGF,
2579
2583
Explosion &fromNonNative,
2580
- SILType type) const {
2584
+ SILType type,
2585
+ bool isOutlined) const {
2581
2586
if (fromNonNative.size () == 0 ) {
2582
2587
assert (empty () && " Empty explosion must match the native convention" );
2583
2588
return Explosion ();
@@ -2668,7 +2673,7 @@ Explosion NativeConventionSchema::mapIntoNative(IRGenModule &IGM,
2668
2673
// Initialize the memory of the temporary.
2669
2674
Address storageAddr = Builder.CreateBitCast (
2670
2675
temporary, loadableTI.getStorageType ()->getPointerTo ());
2671
- loadableTI.initialize (IGF, fromNonNative, storageAddr);
2676
+ loadableTI.initialize (IGF, fromNonNative, storageAddr, isOutlined );
2672
2677
2673
2678
// Load the expanded type elements from memory.
2674
2679
auto coercionAddr = Builder.CreateElementBitCast (temporary, coercionTy);
@@ -2710,7 +2715,7 @@ Explosion NativeConventionSchema::mapIntoNative(IRGenModule &IGM,
2710
2715
}
2711
2716
2712
2717
void IRGenFunction::emitScalarReturn (SILType resultType, Explosion &result,
2713
- bool isSwiftCCReturn) {
2718
+ bool isSwiftCCReturn, bool isOutlined ) {
2714
2719
if (result.size () == 0 ) {
2715
2720
assert (IGM.getTypeInfo (resultType).nativeReturnValueSchema (IGM).empty () &&
2716
2721
" Empty explosion must match the native calling convention" );
@@ -2726,7 +2731,7 @@ void IRGenFunction::emitScalarReturn(SILType resultType, Explosion &result,
2726
2731
assert (!nativeSchema.requiresIndirect ());
2727
2732
2728
2733
Explosion native =
2729
- nativeSchema.mapIntoNative (IGM, *this , result, resultType);
2734
+ nativeSchema.mapIntoNative (IGM, *this , result, resultType, isOutlined );
2730
2735
if (native.size () == 1 ) {
2731
2736
Builder.CreateRet (native.claimNext ());
2732
2737
return ;
0 commit comments