@@ -250,9 +250,6 @@ static bool shouldTransformResults(GenericEnvironment *genEnv,
250
250
static bool modResultType (SILFunction *F, irgen::IRGenModule &Mod) {
251
251
GenericEnvironment *genEnv = F->getGenericEnvironment ();
252
252
auto loweredTy = F->getLoweredFunctionType ();
253
- if (!genEnv && loweredTy->isPolymorphic ()) {
254
- genEnv = getGenericEnvironment (loweredTy);
255
- }
256
253
257
254
return shouldTransformResults (genEnv, loweredTy, Mod);
258
255
}
@@ -538,10 +535,6 @@ void LargeValueVisitor::visitApply(ApplySite applySite) {
538
535
return visitInstr (applySite.getInstruction ());
539
536
}
540
537
GenericEnvironment *genEnv = pass.F ->getGenericEnvironment ();
541
- auto loweredTy = pass.F ->getLoweredFunctionType ();
542
- if (!genEnv && loweredTy->isPolymorphic ()) {
543
- genEnv = getGenericEnvironment (loweredTy);
544
- }
545
538
for (Operand &operand : applySite.getArgumentOperands ()) {
546
539
SILValue currOperand = operand.get ();
547
540
SILType silType = currOperand->getType ();
@@ -622,10 +615,6 @@ static bool shouldConvertBBArg(SILArgument *arg, irgen::IRGenModule &Mod) {
622
615
auto *F = arg->getFunction ();
623
616
SILType storageType = arg->getType ();
624
617
GenericEnvironment *genEnv = F->getGenericEnvironment ();
625
- auto loweredTy = F->getLoweredFunctionType ();
626
- if (!genEnv && loweredTy->isPolymorphic ()) {
627
- genEnv = getGenericEnvironment (loweredTy);
628
- }
629
618
CanType currCanType = storageType.getSwiftRValueType ();
630
619
if (auto funcType = dyn_cast<SILFunctionType>(currCanType)) {
631
620
if (funcType->isPolymorphic ()) {
@@ -711,10 +700,6 @@ void LargeValueVisitor::visitDestroyValueInst(DestroyValueInst *instr) {
711
700
712
701
void LargeValueVisitor::visitResultTyInst (SingleValueInstruction *instr) {
713
702
GenericEnvironment *genEnv = instr->getFunction ()->getGenericEnvironment ();
714
- auto loweredTy = instr->getFunction ()->getLoweredFunctionType ();
715
- if (!genEnv && loweredTy->isPolymorphic ()) {
716
- genEnv = getGenericEnvironment (loweredTy);
717
- }
718
703
SILType currSILType = instr->getType ().getObjectType ();
719
704
SILType newSILType = getNewSILType (genEnv, currSILType, pass.Mod );
720
705
if (currSILType != newSILType) {
@@ -778,10 +763,6 @@ static bool modNonFuncTypeResultType(GenericEnvironment *genEnv,
778
763
static bool modNonFuncTypeResultType (SILFunction *F, irgen::IRGenModule &Mod) {
779
764
GenericEnvironment *genEnv = F->getGenericEnvironment ();
780
765
auto loweredTy = F->getLoweredFunctionType ();
781
- if (!genEnv && loweredTy->isPolymorphic ()) {
782
- genEnv = getGenericEnvironment (loweredTy);
783
- }
784
-
785
766
return modNonFuncTypeResultType (genEnv, loweredTy, Mod);
786
767
}
787
768
@@ -960,11 +941,6 @@ static bool usesContainApplies(LoadInst *unoptimizableLoad,
960
941
SILType currType = unoptimizableLoad->getType ().getObjectType ();
961
942
GenericEnvironment *genEnv =
962
943
unoptimizableLoad->getFunction ()->getGenericEnvironment ();
963
- auto loweredTy =
964
- unoptimizableLoad->getFunction ()->getLoweredFunctionType ();
965
- if (!genEnv && loweredTy->isPolymorphic ()) {
966
- genEnv = getGenericEnvironment (loweredTy);
967
- }
968
944
SILType newSILType = getNewSILType (genEnv, currType, Mod);
969
945
if (currType == newSILType) {
970
946
break ;
@@ -1019,10 +995,6 @@ void LoadableStorageAllocation::replaceLoadWithCopyAddrForModifiable(
1019
995
SILType currType = unoptimizableLoad->getType ().getObjectType ();
1020
996
GenericEnvironment *genEnv =
1021
997
userIns->getFunction ()->getGenericEnvironment ();
1022
- auto loweredTy = userIns->getFunction ()->getLoweredFunctionType ();
1023
- if (!genEnv && loweredTy->isPolymorphic ()) {
1024
- genEnv = getGenericEnvironment (loweredTy);
1025
- }
1026
998
SILType newSILType = getNewSILType (genEnv, currType, pass.Mod );
1027
999
if (currType == newSILType) {
1028
1000
break ;
@@ -1142,9 +1114,6 @@ SILArgument *LoadableStorageAllocation::replaceArgType(SILBuilder &argBuilder,
1142
1114
void LoadableStorageAllocation::insertIndirectReturnArgs () {
1143
1115
GenericEnvironment *genEnv = pass.F ->getGenericEnvironment ();
1144
1116
auto loweredTy = pass.F ->getLoweredFunctionType ();
1145
- if (!genEnv && loweredTy->isPolymorphic ()) {
1146
- genEnv = getGenericEnvironment (loweredTy);
1147
- }
1148
1117
auto singleResult = loweredTy->getSingleResult ();
1149
1118
SILType resultStorageType = singleResult.getSILStorageType ();
1150
1119
auto canType = resultStorageType.getSwiftRValueType ();
@@ -1169,10 +1138,6 @@ void LoadableStorageAllocation::convertIndirectFunctionArgs() {
1169
1138
SILBuilderWithScope argBuilder (entry->begin ());
1170
1139
1171
1140
GenericEnvironment *genEnv = pass.F ->getGenericEnvironment ();
1172
- auto loweredTy = pass.F ->getLoweredFunctionType ();
1173
- if (!genEnv && loweredTy->isPolymorphic ()) {
1174
- genEnv = getGenericEnvironment (loweredTy);
1175
- }
1176
1141
1177
1142
for (SILArgument *arg : entry->getArguments ()) {
1178
1143
SILType storageType = arg->getType ();
@@ -1212,7 +1177,6 @@ static void convertBBArgType(SILBuilder &argBuilder, SILType newSILType,
1212
1177
}
1213
1178
1214
1179
void LoadableStorageAllocation::convertApplyResults () {
1215
- auto &silModule = pass.F ->getModule ();
1216
1180
for (auto &BB : *pass.F ) {
1217
1181
for (auto &II : BB) {
1218
1182
auto *currIns = &II;
@@ -1273,10 +1237,6 @@ void LoadableStorageAllocation::
1273
1237
for (SILArgument *arg : entry->getArguments ()) {
1274
1238
SILType storageType = arg->getType ();
1275
1239
GenericEnvironment *genEnv = pass.F ->getGenericEnvironment ();
1276
- auto loweredTy = pass.F ->getLoweredFunctionType ();
1277
- if (!genEnv && loweredTy->isPolymorphic ()) {
1278
- genEnv = getGenericEnvironment (loweredTy);
1279
- }
1280
1240
SILType newSILType = getNewSILType (genEnv, storageType, pass.Mod );
1281
1241
if (!isLargeLoadableType (genEnv, storageType, pass.Mod ) &&
1282
1242
(newSILType != storageType)) {
@@ -1292,10 +1252,6 @@ void LoadableStorageAllocation::
1292
1252
void LoadableStorageAllocation::convertIndirectBasicBlockArgs () {
1293
1253
SILBasicBlock *entry = pass.F ->getEntryBlock ();
1294
1254
GenericEnvironment *genEnv = pass.F ->getGenericEnvironment ();
1295
- auto loweredTy = pass.F ->getLoweredFunctionType ();
1296
- if (!genEnv && loweredTy->isPolymorphic ()) {
1297
- genEnv = getGenericEnvironment (loweredTy);
1298
- }
1299
1255
for (SILBasicBlock &BB : *pass.F ) {
1300
1256
if (&BB == entry) {
1301
1257
// Already took care of function args
@@ -1555,10 +1511,6 @@ static bool allUsesAreReplaceable(SingleValueInstruction *instr,
1555
1511
SILType currType = instr->getType ().getObjectType ();
1556
1512
GenericEnvironment *genEnv =
1557
1513
instr->getFunction ()->getGenericEnvironment ();
1558
- auto loweredTy = instr->getFunction ()->getLoweredFunctionType ();
1559
- if (!genEnv && loweredTy->isPolymorphic ()) {
1560
- genEnv = getGenericEnvironment (loweredTy);
1561
- }
1562
1514
SILType newSILType = getNewSILType (genEnv, currType, Mod);
1563
1515
if (currType == newSILType) {
1564
1516
allUsesAreReplaceable = false ;
@@ -1652,10 +1604,7 @@ static void rewriteFunction(StructLoweringState &pass,
1652
1604
LoadableStorageAllocation &allocator) {
1653
1605
1654
1606
GenericEnvironment *genEnv = pass.F ->getGenericEnvironment ();
1655
- auto loweredTy = pass.F ->getLoweredFunctionType ();
1656
- if (!genEnv && loweredTy->isPolymorphic ()) {
1657
- genEnv = getGenericEnvironment (loweredTy);
1658
- }
1607
+
1659
1608
bool repeat = false ;
1660
1609
llvm::SetVector<SILInstruction *> currentModApplies;
1661
1610
do {
@@ -2046,9 +1995,6 @@ static void rewriteFunction(StructLoweringState &pass,
2046
1995
static bool rewriteFunctionReturn (StructLoweringState &pass) {
2047
1996
GenericEnvironment *genEnv = pass.F ->getGenericEnvironment ();
2048
1997
auto loweredTy = pass.F ->getLoweredFunctionType ();
2049
- if (!genEnv && loweredTy->isPolymorphic ()) {
2050
- genEnv = getGenericEnvironment (loweredTy);
2051
- }
2052
1998
SILFunction *F = pass.F ;
2053
1999
SILType resultTy = loweredTy->getAllResultsType ();
2054
2000
SILType newSILType = getNewSILType (genEnv, resultTy, pass.Mod );
@@ -2090,7 +2036,7 @@ void LoadableByAddress::runOnFunction(SILFunction *F) {
2090
2036
if (!genEnv && loweredTy->isPolymorphic ()) {
2091
2037
genEnv = getGenericEnvironment (loweredTy);
2092
2038
}
2093
- if (shouldTransformFunctionType (genEnv, F-> getLoweredFunctionType () ,
2039
+ if (shouldTransformFunctionType (genEnv, loweredTy ,
2094
2040
*currIRMod)) {
2095
2041
modFuncs.insert (F);
2096
2042
}
@@ -2276,10 +2222,6 @@ void LoadableByAddress::recreateUncheckedEnumDataInstrs() {
2276
2222
funcType->getGenericSignature ());
2277
2223
SILType origType = enumInstr->getType ();
2278
2224
GenericEnvironment *genEnv = F->getGenericEnvironment ();
2279
- auto loweredTy = F->getLoweredFunctionType ();
2280
- if (!genEnv && loweredTy->isPolymorphic ()) {
2281
- genEnv = getGenericEnvironment (loweredTy);
2282
- }
2283
2225
SILType newType = getNewSILType (genEnv, origType, *currIRMod);
2284
2226
auto caseTy = enumInstr->getOperand ()->getType ().getEnumElementType (
2285
2227
enumInstr->getElement (), F->getModule ());
@@ -2310,10 +2252,6 @@ void LoadableByAddress::recreateUncheckedTakeEnumDataAddrInst() {
2310
2252
funcType->getGenericSignature ());
2311
2253
SILType origType = enumInstr->getType ();
2312
2254
GenericEnvironment *genEnv = F->getGenericEnvironment ();
2313
- auto loweredTy = F->getLoweredFunctionType ();
2314
- if (!genEnv && loweredTy->isPolymorphic ()) {
2315
- genEnv = getGenericEnvironment (loweredTy);
2316
- }
2317
2255
SILType newType = getNewSILType (genEnv, origType, *currIRMod);
2318
2256
auto caseTy = enumInstr->getOperand ()->getType ().getEnumElementType (
2319
2257
enumInstr->getElement (), F->getModule ());
@@ -2365,10 +2303,6 @@ void LoadableByAddress::recreateConvInstrs() {
2365
2303
currSILFunctionType->getGenericSignature ());
2366
2304
GenericEnvironment *genEnv =
2367
2305
convInstr->getFunction ()->getGenericEnvironment ();
2368
- auto loweredTy = convInstr->getFunction ()->getLoweredFunctionType ();
2369
- if (!genEnv && loweredTy->isPolymorphic ()) {
2370
- genEnv = getGenericEnvironment (loweredTy);
2371
- }
2372
2306
CanSILFunctionType newFnType =
2373
2307
getNewSILFunctionType (genEnv, currSILFunctionType, *currIRMod);
2374
2308
SILType newType = SILType::getPrimitiveObjectType (newFnType);
@@ -2408,10 +2342,6 @@ void LoadableByAddress::recreateBuiltinInstrs() {
2408
2342
getIRGenModule ()->IRGen .getGenModule (builtinInstr->getFunction ());
2409
2343
auto *F = builtinInstr->getFunction ();
2410
2344
GenericEnvironment *genEnv = F->getGenericEnvironment ();
2411
- auto loweredTy = F->getLoweredFunctionType ();
2412
- if (!genEnv && loweredTy->isPolymorphic ()) {
2413
- genEnv = getGenericEnvironment (loweredTy);
2414
- }
2415
2345
auto resultTy = builtinInstr->getType ();
2416
2346
auto newResultTy = getNewSILType (genEnv, resultTy, *currIRMod);
2417
2347
@@ -2436,9 +2366,8 @@ void LoadableByAddress::updateLoweredTypes(SILFunction *F) {
2436
2366
Lowering::GenericContextScope GenericScope (getModule ()->Types ,
2437
2367
funcType->getGenericSignature ());
2438
2368
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);
2442
2371
}
2443
2372
auto newFuncTy = getNewSILFunctionType (genEnv, funcType, *currIRMod);
2444
2373
F->rewriteLoweredTypeUnsafe (newFuncTy);
0 commit comments