Skip to content

Commit 57e2068

Browse files
committed
LoadableByAddress: If a SILFunction has a polymorphic lowered type it also has a generic environment
1 parent 41c4afc commit 57e2068

File tree

1 file changed

+4
-75
lines changed

1 file changed

+4
-75
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,6 @@ static bool shouldTransformResults(GenericEnvironment *genEnv,
250250
static bool modResultType(SILFunction *F, irgen::IRGenModule &Mod) {
251251
GenericEnvironment *genEnv = F->getGenericEnvironment();
252252
auto loweredTy = F->getLoweredFunctionType();
253-
if (!genEnv && loweredTy->isPolymorphic()) {
254-
genEnv = getGenericEnvironment(loweredTy);
255-
}
256253

257254
return shouldTransformResults(genEnv, loweredTy, Mod);
258255
}
@@ -538,10 +535,6 @@ void LargeValueVisitor::visitApply(ApplySite applySite) {
538535
return visitInstr(applySite.getInstruction());
539536
}
540537
GenericEnvironment *genEnv = pass.F->getGenericEnvironment();
541-
auto loweredTy = pass.F->getLoweredFunctionType();
542-
if (!genEnv && loweredTy->isPolymorphic()) {
543-
genEnv = getGenericEnvironment(loweredTy);
544-
}
545538
for (Operand &operand : applySite.getArgumentOperands()) {
546539
SILValue currOperand = operand.get();
547540
SILType silType = currOperand->getType();
@@ -622,10 +615,6 @@ static bool shouldConvertBBArg(SILArgument *arg, irgen::IRGenModule &Mod) {
622615
auto *F = arg->getFunction();
623616
SILType storageType = arg->getType();
624617
GenericEnvironment *genEnv = F->getGenericEnvironment();
625-
auto loweredTy = F->getLoweredFunctionType();
626-
if (!genEnv && loweredTy->isPolymorphic()) {
627-
genEnv = getGenericEnvironment(loweredTy);
628-
}
629618
CanType currCanType = storageType.getSwiftRValueType();
630619
if (auto funcType = dyn_cast<SILFunctionType>(currCanType)) {
631620
if (funcType->isPolymorphic()) {
@@ -711,10 +700,6 @@ void LargeValueVisitor::visitDestroyValueInst(DestroyValueInst *instr) {
711700

712701
void LargeValueVisitor::visitResultTyInst(SingleValueInstruction *instr) {
713702
GenericEnvironment *genEnv = instr->getFunction()->getGenericEnvironment();
714-
auto loweredTy = instr->getFunction()->getLoweredFunctionType();
715-
if (!genEnv && loweredTy->isPolymorphic()) {
716-
genEnv = getGenericEnvironment(loweredTy);
717-
}
718703
SILType currSILType = instr->getType().getObjectType();
719704
SILType newSILType = getNewSILType(genEnv, currSILType, pass.Mod);
720705
if (currSILType != newSILType) {
@@ -778,10 +763,6 @@ static bool modNonFuncTypeResultType(GenericEnvironment *genEnv,
778763
static bool modNonFuncTypeResultType(SILFunction *F, irgen::IRGenModule &Mod) {
779764
GenericEnvironment *genEnv = F->getGenericEnvironment();
780765
auto loweredTy = F->getLoweredFunctionType();
781-
if (!genEnv && loweredTy->isPolymorphic()) {
782-
genEnv = getGenericEnvironment(loweredTy);
783-
}
784-
785766
return modNonFuncTypeResultType(genEnv, loweredTy, Mod);
786767
}
787768

@@ -960,11 +941,6 @@ static bool usesContainApplies(LoadInst *unoptimizableLoad,
960941
SILType currType = unoptimizableLoad->getType().getObjectType();
961942
GenericEnvironment *genEnv =
962943
unoptimizableLoad->getFunction()->getGenericEnvironment();
963-
auto loweredTy =
964-
unoptimizableLoad->getFunction()->getLoweredFunctionType();
965-
if (!genEnv && loweredTy->isPolymorphic()) {
966-
genEnv = getGenericEnvironment(loweredTy);
967-
}
968944
SILType newSILType = getNewSILType(genEnv, currType, Mod);
969945
if (currType == newSILType) {
970946
break;
@@ -1019,10 +995,6 @@ void LoadableStorageAllocation::replaceLoadWithCopyAddrForModifiable(
1019995
SILType currType = unoptimizableLoad->getType().getObjectType();
1020996
GenericEnvironment *genEnv =
1021997
userIns->getFunction()->getGenericEnvironment();
1022-
auto loweredTy = userIns->getFunction()->getLoweredFunctionType();
1023-
if (!genEnv && loweredTy->isPolymorphic()) {
1024-
genEnv = getGenericEnvironment(loweredTy);
1025-
}
1026998
SILType newSILType = getNewSILType(genEnv, currType, pass.Mod);
1027999
if (currType == newSILType) {
10281000
break;
@@ -1142,9 +1114,6 @@ SILArgument *LoadableStorageAllocation::replaceArgType(SILBuilder &argBuilder,
11421114
void LoadableStorageAllocation::insertIndirectReturnArgs() {
11431115
GenericEnvironment *genEnv = pass.F->getGenericEnvironment();
11441116
auto loweredTy = pass.F->getLoweredFunctionType();
1145-
if (!genEnv && loweredTy->isPolymorphic()) {
1146-
genEnv = getGenericEnvironment(loweredTy);
1147-
}
11481117
auto singleResult = loweredTy->getSingleResult();
11491118
SILType resultStorageType = singleResult.getSILStorageType();
11501119
auto canType = resultStorageType.getSwiftRValueType();
@@ -1169,10 +1138,6 @@ void LoadableStorageAllocation::convertIndirectFunctionArgs() {
11691138
SILBuilderWithScope argBuilder(entry->begin());
11701139

11711140
GenericEnvironment *genEnv = pass.F->getGenericEnvironment();
1172-
auto loweredTy = pass.F->getLoweredFunctionType();
1173-
if (!genEnv && loweredTy->isPolymorphic()) {
1174-
genEnv = getGenericEnvironment(loweredTy);
1175-
}
11761141

11771142
for (SILArgument *arg : entry->getArguments()) {
11781143
SILType storageType = arg->getType();
@@ -1212,7 +1177,6 @@ static void convertBBArgType(SILBuilder &argBuilder, SILType newSILType,
12121177
}
12131178

12141179
void LoadableStorageAllocation::convertApplyResults() {
1215-
auto &silModule = pass.F->getModule();
12161180
for (auto &BB : *pass.F) {
12171181
for (auto &II : BB) {
12181182
auto *currIns = &II;
@@ -1273,10 +1237,6 @@ void LoadableStorageAllocation::
12731237
for (SILArgument *arg : entry->getArguments()) {
12741238
SILType storageType = arg->getType();
12751239
GenericEnvironment *genEnv = pass.F->getGenericEnvironment();
1276-
auto loweredTy = pass.F->getLoweredFunctionType();
1277-
if (!genEnv && loweredTy->isPolymorphic()) {
1278-
genEnv = getGenericEnvironment(loweredTy);
1279-
}
12801240
SILType newSILType = getNewSILType(genEnv, storageType, pass.Mod);
12811241
if (!isLargeLoadableType(genEnv, storageType, pass.Mod) &&
12821242
(newSILType != storageType)) {
@@ -1292,10 +1252,6 @@ void LoadableStorageAllocation::
12921252
void LoadableStorageAllocation::convertIndirectBasicBlockArgs() {
12931253
SILBasicBlock *entry = pass.F->getEntryBlock();
12941254
GenericEnvironment *genEnv = pass.F->getGenericEnvironment();
1295-
auto loweredTy = pass.F->getLoweredFunctionType();
1296-
if (!genEnv && loweredTy->isPolymorphic()) {
1297-
genEnv = getGenericEnvironment(loweredTy);
1298-
}
12991255
for (SILBasicBlock &BB : *pass.F) {
13001256
if (&BB == entry) {
13011257
// Already took care of function args
@@ -1555,10 +1511,6 @@ static bool allUsesAreReplaceable(SingleValueInstruction *instr,
15551511
SILType currType = instr->getType().getObjectType();
15561512
GenericEnvironment *genEnv =
15571513
instr->getFunction()->getGenericEnvironment();
1558-
auto loweredTy = instr->getFunction()->getLoweredFunctionType();
1559-
if (!genEnv && loweredTy->isPolymorphic()) {
1560-
genEnv = getGenericEnvironment(loweredTy);
1561-
}
15621514
SILType newSILType = getNewSILType(genEnv, currType, Mod);
15631515
if (currType == newSILType) {
15641516
allUsesAreReplaceable = false;
@@ -1652,10 +1604,7 @@ static void rewriteFunction(StructLoweringState &pass,
16521604
LoadableStorageAllocation &allocator) {
16531605

16541606
GenericEnvironment *genEnv = pass.F->getGenericEnvironment();
1655-
auto loweredTy = pass.F->getLoweredFunctionType();
1656-
if (!genEnv && loweredTy->isPolymorphic()) {
1657-
genEnv = getGenericEnvironment(loweredTy);
1658-
}
1607+
16591608
bool repeat = false;
16601609
llvm::SetVector<SILInstruction *> currentModApplies;
16611610
do {
@@ -2046,9 +1995,6 @@ static void rewriteFunction(StructLoweringState &pass,
20461995
static bool rewriteFunctionReturn(StructLoweringState &pass) {
20471996
GenericEnvironment *genEnv = pass.F->getGenericEnvironment();
20481997
auto loweredTy = pass.F->getLoweredFunctionType();
2049-
if (!genEnv && loweredTy->isPolymorphic()) {
2050-
genEnv = getGenericEnvironment(loweredTy);
2051-
}
20521998
SILFunction *F = pass.F;
20531999
SILType resultTy = loweredTy->getAllResultsType();
20542000
SILType newSILType = getNewSILType(genEnv, resultTy, pass.Mod);
@@ -2090,7 +2036,7 @@ void LoadableByAddress::runOnFunction(SILFunction *F) {
20902036
if (!genEnv && loweredTy->isPolymorphic()) {
20912037
genEnv = getGenericEnvironment(loweredTy);
20922038
}
2093-
if (shouldTransformFunctionType(genEnv, F->getLoweredFunctionType(),
2039+
if (shouldTransformFunctionType(genEnv, loweredTy,
20942040
*currIRMod)) {
20952041
modFuncs.insert(F);
20962042
}
@@ -2276,10 +2222,6 @@ void LoadableByAddress::recreateUncheckedEnumDataInstrs() {
22762222
funcType->getGenericSignature());
22772223
SILType origType = enumInstr->getType();
22782224
GenericEnvironment *genEnv = F->getGenericEnvironment();
2279-
auto loweredTy = F->getLoweredFunctionType();
2280-
if (!genEnv && loweredTy->isPolymorphic()) {
2281-
genEnv = getGenericEnvironment(loweredTy);
2282-
}
22832225
SILType newType = getNewSILType(genEnv, origType, *currIRMod);
22842226
auto caseTy = enumInstr->getOperand()->getType().getEnumElementType(
22852227
enumInstr->getElement(), F->getModule());
@@ -2310,10 +2252,6 @@ void LoadableByAddress::recreateUncheckedTakeEnumDataAddrInst() {
23102252
funcType->getGenericSignature());
23112253
SILType origType = enumInstr->getType();
23122254
GenericEnvironment *genEnv = F->getGenericEnvironment();
2313-
auto loweredTy = F->getLoweredFunctionType();
2314-
if (!genEnv && loweredTy->isPolymorphic()) {
2315-
genEnv = getGenericEnvironment(loweredTy);
2316-
}
23172255
SILType newType = getNewSILType(genEnv, origType, *currIRMod);
23182256
auto caseTy = enumInstr->getOperand()->getType().getEnumElementType(
23192257
enumInstr->getElement(), F->getModule());
@@ -2365,10 +2303,6 @@ void LoadableByAddress::recreateConvInstrs() {
23652303
currSILFunctionType->getGenericSignature());
23662304
GenericEnvironment *genEnv =
23672305
convInstr->getFunction()->getGenericEnvironment();
2368-
auto loweredTy = convInstr->getFunction()->getLoweredFunctionType();
2369-
if (!genEnv && loweredTy->isPolymorphic()) {
2370-
genEnv = getGenericEnvironment(loweredTy);
2371-
}
23722306
CanSILFunctionType newFnType =
23732307
getNewSILFunctionType(genEnv, currSILFunctionType, *currIRMod);
23742308
SILType newType = SILType::getPrimitiveObjectType(newFnType);
@@ -2408,10 +2342,6 @@ void LoadableByAddress::recreateBuiltinInstrs() {
24082342
getIRGenModule()->IRGen.getGenModule(builtinInstr->getFunction());
24092343
auto *F = builtinInstr->getFunction();
24102344
GenericEnvironment *genEnv = F->getGenericEnvironment();
2411-
auto loweredTy = F->getLoweredFunctionType();
2412-
if (!genEnv && loweredTy->isPolymorphic()) {
2413-
genEnv = getGenericEnvironment(loweredTy);
2414-
}
24152345
auto resultTy = builtinInstr->getType();
24162346
auto newResultTy = getNewSILType(genEnv, resultTy, *currIRMod);
24172347

@@ -2436,9 +2366,8 @@ void LoadableByAddress::updateLoweredTypes(SILFunction *F) {
24362366
Lowering::GenericContextScope GenericScope(getModule()->Types,
24372367
funcType->getGenericSignature());
24382368
GenericEnvironment *genEnv = F->getGenericEnvironment();
2439-
auto loweredTy = F->getLoweredFunctionType();
2440-
if (!genEnv && loweredTy->isPolymorphic()) {
2441-
genEnv = getGenericEnvironment(loweredTy);
2369+
if (!genEnv && funcType->isPolymorphic()) {
2370+
genEnv = getGenericEnvironment(funcType);
24422371
}
24432372
auto newFuncTy = getNewSILFunctionType(genEnv, funcType, *currIRMod);
24442373
F->rewriteLoweredTypeUnsafe(newFuncTy);

0 commit comments

Comments
 (0)