Skip to content

Commit 62d823c

Browse files
author
Joe Shajrawi
committed
Code size: Do not use a global state for isOutlined
1 parent 5aff089 commit 62d823c

29 files changed

+463
-492
lines changed

lib/IRGen/CallEmission.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ class CallEmission {
7373
}
7474

7575
/// Set the arguments to the function from an explosion.
76-
void setArgs(Explosion &arg, WitnessMetadata *witnessMetadata = nullptr);
77-
76+
void setArgs(Explosion &arg, bool isOutlined,
77+
WitnessMetadata *witnessMetadata = nullptr);
78+
7879
void addAttribute(unsigned Index, llvm::Attribute::AttrKind Attr);
7980

80-
void emitToMemory(Address addr, const LoadableTypeInfo &substResultTI);
81-
void emitToExplosion(Explosion &out);
81+
void emitToMemory(Address addr, const LoadableTypeInfo &substResultTI,
82+
bool isOutlined);
83+
void emitToExplosion(Explosion &out, bool isOutlined);
8284
};
8385

8486

lib/IRGen/FixedTypeInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class FixedTypeInfo : public TypeInfo {
8383

8484
// We can give these reasonable default implementations.
8585

86-
void initializeWithTake(IRGenFunction &IGF, Address destAddr,
87-
Address srcAddr, SILType T) const override;
86+
void initializeWithTake(IRGenFunction &IGF, Address destAddr, Address srcAddr,
87+
SILType T, bool isOutlined) const override;
8888

8989
llvm::Value *getSize(IRGenFunction &IGF, SILType T) const override;
9090
llvm::Value *getAlignmentMask(IRGenFunction &IGF, SILType T) const override;

lib/IRGen/GenCall.cpp

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,15 +1331,16 @@ llvm::CallInst *IRBuilder::CreateCall(const FunctionPointer &fn,
13311331

13321332
/// Emit the result of this call to memory.
13331333
void CallEmission::emitToMemory(Address addr,
1334-
const LoadableTypeInfo &indirectedResultTI) {
1334+
const LoadableTypeInfo &indirectedResultTI,
1335+
bool isOutlined) {
13351336
assert(LastArgWritten <= 1);
13361337

13371338
// If the call is naturally to an explosion, emit it that way and
13381339
// then initialize the temporary.
13391340
if (LastArgWritten == 0) {
13401341
Explosion result;
1341-
emitToExplosion(result);
1342-
indirectedResultTI.initialize(IGF, result, addr);
1342+
emitToExplosion(result, isOutlined);
1343+
indirectedResultTI.initialize(IGF, result, addr, isOutlined);
13431344
return;
13441345
}
13451346

@@ -1373,7 +1374,7 @@ void CallEmission::emitToMemory(Address addr,
13731374
}
13741375

13751376
/// Emit the result of this call to an explosion.
1376-
void CallEmission::emitToExplosion(Explosion &out) {
1377+
void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
13771378
assert(LastArgWritten <= 1);
13781379

13791380
SILFunctionConventions fnConv(getCallee().getSubstFunctionType(),
@@ -1389,8 +1390,8 @@ void CallEmission::emitToExplosion(Explosion &out) {
13891390
StackAddress ctemp = substResultTI.allocateStack(IGF, substResultType,
13901391
false, "call.aggresult");
13911392
Address temp = ctemp.getAddress();
1392-
emitToMemory(temp, substResultTI);
1393-
1393+
emitToMemory(temp, substResultTI, isOutlined);
1394+
13941395
// We can use a take.
13951396
substResultTI.loadAsTake(IGF, temp, out);
13961397

@@ -1600,13 +1601,13 @@ static llvm::Type *getOutputType(TranslationDirection direction, unsigned index,
16001601
: nativeSchema[index].getScalarType());
16011602
}
16021603

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,
16061606
const LoadableTypeInfo &paramTI,
16071607
llvm::StructType *coercionTy,
1608-
ArrayRef<llvm::Type*> expandedTys,
1609-
TranslationDirection direction) {
1608+
ArrayRef<llvm::Type *> expandedTys,
1609+
TranslationDirection direction,
1610+
bool isOutlined) {
16101611
// If we can directly coerce the scalar values, avoid going through memory.
16111612
auto schema = paramTI.getSchema();
16121613
if (canCoerceToSchema(IGF.IGM, expandedTys, schema)) {
@@ -1641,7 +1642,7 @@ static void emitCoerceAndExpand(IRGenFunction &IGF,
16411642
// If we're translating *to* the foreign expansion, do an ordinary
16421643
// initialization from the input explosion.
16431644
if (direction == TranslationDirection::ToForeign) {
1644-
paramTI.initialize(IGF, in, temporary);
1645+
paramTI.initialize(IGF, in, temporary, isOutlined);
16451646
}
16461647

16471648
Address coercedTemporary =
@@ -1689,7 +1690,8 @@ static void emitCoerceAndExpand(IRGenFunction &IGF,
16891690

16901691
static void emitDirectExternalArgument(IRGenFunction &IGF, SILType argType,
16911692
const clang::CodeGen::ABIArgInfo &AI,
1692-
Explosion &in, Explosion &out) {
1693+
Explosion &in, Explosion &out,
1694+
bool isOutlined) {
16931695
bool IsDirectFlattened = AI.isDirect() && AI.getCanBeFlattened();
16941696
bool IsIndirect = !AI.isDirect();
16951697

@@ -1725,7 +1727,7 @@ static void emitDirectExternalArgument(IRGenFunction &IGF, SILType argType,
17251727
// Store to a temporary.
17261728
Address tempOfArgTy = IGF.Builder.CreateBitCast(
17271729
temporary, argTI.getStorageType()->getPointerTo());
1728-
argTI.initializeFromParams(IGF, in, tempOfArgTy, argType);
1730+
argTI.initializeFromParams(IGF, in, tempOfArgTy, argType, isOutlined);
17291731

17301732
// Bitcast the temporary to the expected type.
17311733
Address coercedAddr =
@@ -1783,11 +1785,10 @@ namespace {
17831785

17841786
/// Given a Swift value explosion in 'in', produce a Clang expansion
17851787
/// (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) {
17911792
// If Clang's expansion schema matches Swift's, great.
17921793
auto swiftSchema = swiftTI.getSchema();
17931794
if (doesClangExpansionMatchSchema(IGF.IGM, clangType, swiftSchema)) {
@@ -1797,7 +1798,7 @@ static void emitClangExpandedArgument(IRGenFunction &IGF,
17971798
// Otherwise, materialize to a temporary.
17981799
Address temp = swiftTI.allocateStack(IGF, swiftType, false,
17991800
"clang-expand-arg.temp").getAddress();
1800-
swiftTI.initialize(IGF, in, temp);
1801+
swiftTI.initialize(IGF, in, temp, isOutlined);
18011802

18021803
Address castTemp = IGF.Builder.CreateBitCast(temp, IGF.IGM.Int8PtrTy);
18031804
ClangExpandLoadEmitter(IGF, out).visit(clangType, castTemp);
@@ -1827,7 +1828,8 @@ void irgen::emitClangExpandedParameter(IRGenFunction &IGF,
18271828
}
18281829

18291830
static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
1830-
Explosion &in, Explosion &out) {
1831+
Explosion &in, Explosion &out,
1832+
bool isOutlined) {
18311833
auto silConv = IGF.IGM.silConv;
18321834
auto fnType = callee.getOrigFunctionType();
18331835
auto params = fnType->getParameters();
@@ -1889,7 +1891,7 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
18891891
break;
18901892
}
18911893

1892-
emitDirectExternalArgument(IGF, paramType, AI, in, out);
1894+
emitDirectExternalArgument(IGF, paramType, AI, in, out, isOutlined);
18931895
break;
18941896
}
18951897
case clang::CodeGen::ABIArgInfo::Indirect: {
@@ -1906,7 +1908,7 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
19061908
}
19071909
}
19081910

1909-
ti.initialize(IGF, in, addr);
1911+
ti.initialize(IGF, in, addr, isOutlined);
19101912

19111913
out.add(addr.getAddress());
19121914
break;
@@ -1916,12 +1918,13 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
19161918
emitCoerceAndExpand(IGF, in, out, paramType, paramTI,
19171919
AI.getCoerceAndExpandType(),
19181920
AI.getCoerceAndExpandTypeSequence(),
1919-
TranslationDirection::ToForeign);
1921+
TranslationDirection::ToForeign, isOutlined);
19201922
break;
19211923
}
19221924
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);
19251928
break;
19261929
case clang::CodeGen::ABIArgInfo::Ignore:
19271930
break;
@@ -1934,7 +1937,8 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
19341937

19351938
/// Returns whether allocas are needed.
19361939
bool irgen::addNativeArgument(IRGenFunction &IGF, Explosion &in,
1937-
SILParameterInfo origParamInfo, Explosion &out) {
1940+
SILParameterInfo origParamInfo, Explosion &out,
1941+
bool isOutlined) {
19381942
// Addresses consist of a single pointer argument.
19391943
if (IGF.IGM.silConv.isSILIndirect(origParamInfo)) {
19401944
out.add(in.claimNext());
@@ -1948,7 +1952,7 @@ bool irgen::addNativeArgument(IRGenFunction &IGF, Explosion &in,
19481952
// Pass the argument indirectly.
19491953
auto buf = IGF.createAlloca(ti.getStorageType(),
19501954
ti.getFixedAlignment(), "");
1951-
ti.initialize(IGF, in, buf);
1955+
ti.initialize(IGF, in, buf, isOutlined);
19521956
out.add(buf.getAddress());
19531957
return true;
19541958
} else {
@@ -1962,7 +1966,8 @@ bool irgen::addNativeArgument(IRGenFunction &IGF, Explosion &in,
19621966
// calling convention.
19631967
Explosion nonNativeParam;
19641968
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);
19661971
nativeParam.transferInto(out, nativeParam.size());
19671972
return false;
19681973
}
@@ -2047,10 +2052,9 @@ static void emitDirectForeignParameter(IRGenFunction &IGF, Explosion &in,
20472052

20482053
void irgen::emitForeignParameter(IRGenFunction &IGF, Explosion &params,
20492054
ForeignFunctionInfo foreignInfo,
2050-
unsigned foreignParamIndex,
2051-
SILType paramTy,
2055+
unsigned foreignParamIndex, SILType paramTy,
20522056
const LoadableTypeInfo &paramTI,
2053-
Explosion &paramExplosion) {
2057+
Explosion &paramExplosion, bool isOutlined) {
20542058
assert(foreignInfo.ClangInfo);
20552059
auto &FI = *foreignInfo.ClangInfo;
20562060

@@ -2088,7 +2092,7 @@ void irgen::emitForeignParameter(IRGenFunction &IGF, Explosion &params,
20882092
emitCoerceAndExpand(IGF, params, paramExplosion, paramTy, paramTI,
20892093
AI.getCoerceAndExpandType(),
20902094
AI.getCoerceAndExpandTypeSequence(),
2091-
TranslationDirection::ToNative);
2095+
TranslationDirection::ToNative, isOutlined);
20922096
break;
20932097
}
20942098

@@ -2102,7 +2106,7 @@ void irgen::emitForeignParameter(IRGenFunction &IGF, Explosion &params,
21022106

21032107

21042108
/// Add a new set of arguments to the function.
2105-
void CallEmission::setArgs(Explosion &original,
2109+
void CallEmission::setArgs(Explosion &original, bool isOutlined,
21062110
WitnessMetadata *witnessMetadata) {
21072111
// Convert arguments to a representation appropriate to the calling
21082112
// convention.
@@ -2119,15 +2123,15 @@ void CallEmission::setArgs(Explosion &original,
21192123
case SILFunctionTypeRepresentation::ObjCMethod:
21202124
adjusted.add(getCallee().getObjCMethodReceiver());
21212125
adjusted.add(getCallee().getObjCMethodSelector());
2122-
externalizeArguments(IGF, getCallee(), original, adjusted);
2126+
externalizeArguments(IGF, getCallee(), original, adjusted, isOutlined);
21232127
break;
21242128

21252129
case SILFunctionTypeRepresentation::Block:
21262130
adjusted.add(getCallee().getBlockObject());
21272131
LLVM_FALLTHROUGH;
21282132

21292133
case SILFunctionTypeRepresentation::CFunctionPointer:
2130-
externalizeArguments(IGF, getCallee(), original, adjusted);
2134+
externalizeArguments(IGF, getCallee(), original, adjusted, isOutlined);
21312135
break;
21322136

21332137
case SILFunctionTypeRepresentation::WitnessMethod:
@@ -2152,7 +2156,7 @@ void CallEmission::setArgs(Explosion &original,
21522156
params = params.drop_back();
21532157
}
21542158
for (auto param : params) {
2155-
addNativeArgument(IGF, original, param, adjusted);
2159+
addNativeArgument(IGF, original, param, adjusted, isOutlined);
21562160
}
21572161

21582162
// Anything else, just pass along. This will include things like
@@ -2577,7 +2581,8 @@ Explosion NativeConventionSchema::mapFromNative(IRGenModule &IGM,
25772581
Explosion NativeConventionSchema::mapIntoNative(IRGenModule &IGM,
25782582
IRGenFunction &IGF,
25792583
Explosion &fromNonNative,
2580-
SILType type) const {
2584+
SILType type,
2585+
bool isOutlined) const {
25812586
if (fromNonNative.size() == 0) {
25822587
assert(empty() && "Empty explosion must match the native convention");
25832588
return Explosion();
@@ -2668,7 +2673,7 @@ Explosion NativeConventionSchema::mapIntoNative(IRGenModule &IGM,
26682673
// Initialize the memory of the temporary.
26692674
Address storageAddr = Builder.CreateBitCast(
26702675
temporary, loadableTI.getStorageType()->getPointerTo());
2671-
loadableTI.initialize(IGF, fromNonNative, storageAddr);
2676+
loadableTI.initialize(IGF, fromNonNative, storageAddr, isOutlined);
26722677

26732678
// Load the expanded type elements from memory.
26742679
auto coercionAddr = Builder.CreateElementBitCast(temporary, coercionTy);
@@ -2710,7 +2715,7 @@ Explosion NativeConventionSchema::mapIntoNative(IRGenModule &IGM,
27102715
}
27112716

27122717
void IRGenFunction::emitScalarReturn(SILType resultType, Explosion &result,
2713-
bool isSwiftCCReturn) {
2718+
bool isSwiftCCReturn, bool isOutlined) {
27142719
if (result.size() == 0) {
27152720
assert(IGM.getTypeInfo(resultType).nativeReturnValueSchema(IGM).empty() &&
27162721
"Empty explosion must match the native calling convention");
@@ -2726,7 +2731,7 @@ void IRGenFunction::emitScalarReturn(SILType resultType, Explosion &result,
27262731
assert(!nativeSchema.requiresIndirect());
27272732

27282733
Explosion native =
2729-
nativeSchema.mapIntoNative(IGM, *this, result, resultType);
2734+
nativeSchema.mapIntoNative(IGM, *this, result, resultType, isOutlined);
27302735
if (native.size() == 1) {
27312736
Builder.CreateRet(native.claimNext());
27322737
return;

lib/IRGen/GenCall.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ namespace irgen {
8585

8686
void emitForeignParameter(IRGenFunction &IGF, Explosion &params,
8787
ForeignFunctionInfo foreignInfo,
88-
unsigned foreignParamIndex,
89-
SILType paramTy, const LoadableTypeInfo &paramTI,
90-
Explosion &paramExplosion);
91-
88+
unsigned foreignParamIndex, SILType paramTy,
89+
const LoadableTypeInfo &paramTI,
90+
Explosion &paramExplosion, bool isOutlined);
9291

9392
void emitClangExpandedParameter(IRGenFunction &IGF,
9493
Explosion &in, Explosion &out,
@@ -97,8 +96,9 @@ namespace irgen {
9796
const LoadableTypeInfo &swiftTI);
9897

9998
bool addNativeArgument(IRGenFunction &IGF, Explosion &in,
100-
SILParameterInfo origParamInfo, Explosion &args);
101-
99+
SILParameterInfo origParamInfo, Explosion &args,
100+
bool isOutlined);
101+
102102
/// Allocate a stack buffer of the appropriate size to bitwise-coerce a value
103103
/// between two LLVM types.
104104
std::pair<Address, Size>

0 commit comments

Comments
 (0)