@@ -1231,7 +1231,7 @@ class AddressMaterialization {
1231
1231
return storage.storageAddress ;
1232
1232
1233
1233
if (storage.isUseProjection ) {
1234
- materializeUseProjectionStorage (storage, /* intoPhiOperand*/ false );
1234
+ recursivelyMaterializeStorage (storage, /* intoPhiOperand*/ false );
1235
1235
} else {
1236
1236
assert (storage.isDefProjection );
1237
1237
storage.storageAddress = materializeDefProjection (origValue);
@@ -1241,8 +1241,8 @@ class AddressMaterialization {
1241
1241
1242
1242
void initializeOperand (Operand *operand);
1243
1243
1244
- SILValue materializeUseProjectionStorage (ValueStorage &storage,
1245
- bool intoPhiOperand);
1244
+ SILValue recursivelyMaterializeStorage (ValueStorage &storage,
1245
+ bool intoPhiOperand);
1246
1246
1247
1247
SILValue materializeDefProjection (SILValue origValue);
1248
1248
@@ -1257,8 +1257,8 @@ class AddressMaterialization {
1257
1257
1258
1258
SILValue materializeComposingUser (SingleValueInstruction *user,
1259
1259
bool intoPhiOperand) {
1260
- return materializeUseProjectionStorage (
1261
- pass. valueStorageMap . getStorage (user), intoPhiOperand);
1260
+ return recursivelyMaterializeStorage (pass. valueStorageMap . getStorage (user),
1261
+ intoPhiOperand);
1262
1262
}
1263
1263
};
1264
1264
} // anonymous namespace
@@ -1290,19 +1290,26 @@ void AddressMaterialization::initializeOperand(Operand *operand) {
1290
1290
StoreOwnershipQualifier::Init);
1291
1291
}
1292
1292
1293
- // Recursively materialize the address for storage at the point that a use
1294
- // projects into it via either a composing-use (struct, tuple, enum) or phi
1295
- // projection. This only materializes the address that the operands project
1296
- // into. It does not materialize the storage for the result. e.g. it
1297
- // materializes init_enum_data_addr, not inject_enum_addr .
1293
+ // Recursively materialize the address for storage at the point that an operand
1294
+ // may project into it via either a composing-use (struct, tuple, enum) or phi
1295
+ // projection.
1296
+ //
1297
+ // Precondition: \p storage is not a def-projection .
1298
1298
//
1299
1299
// If \p intoPhiOperand is true, this materializes the address in the path that
1300
- // reaches a phi operand, not the phi block itself.
1300
+ // reaches a phi operand, not the phi block itself. Do not map the storage onto
1301
+ // the materialized address.
1301
1302
//
1302
1303
// If \p intoPhiOperand is false, then the materialized address is guaranteed to
1303
1304
// domaninate the composing user. Map the user onto this address to avoid
1304
1305
// rematerialization.
1305
- SILValue AddressMaterialization::materializeUseProjectionStorage (
1306
+ //
1307
+ // Note: This only materializes the address for the purpose of projection an
1308
+ // operand into the storage. It does not materialize the final address of
1309
+ // storage after materializing the result. In particular, it materializes
1310
+ // init_enum_data_addr, but not inject_enum_addr.
1311
+ //
1312
+ SILValue AddressMaterialization::recursivelyMaterializeStorage (
1306
1313
ValueStorage &storage, bool intoPhiOperand = false ) {
1307
1314
// If this storage is already materialized, then simply return its
1308
1315
// address. This not only avoids redundant projections, but is necessary for
@@ -1331,7 +1338,7 @@ SILValue AddressMaterialization::materializeUseProjectionStorage(
1331
1338
return recordAddress (useStorage.storage .storageAddress );
1332
1339
}
1333
1340
if (storage.isPhiProjection ()) {
1334
- return recordAddress (materializeUseProjectionStorage (
1341
+ return recordAddress (recursivelyMaterializeStorage (
1335
1342
pass.valueStorageMap .getProjectedStorage (storage).storage ,
1336
1343
/* intoPhiOperand*/ true ));
1337
1344
}
@@ -1566,8 +1573,8 @@ void PhiRewriter::materializeOperand(PhiOperand phiOper) {
1566
1573
1567
1574
auto &phiStorage = pass.valueStorageMap .getStorage (phiOper.getValue ());
1568
1575
SILValue phiAddress =
1569
- addrMat.materializeUseProjectionStorage (phiStorage,
1570
- /* intoPhiOperand*/ true );
1576
+ addrMat.recursivelyMaterializeStorage (phiStorage,
1577
+ /* intoPhiOperand*/ true );
1571
1578
1572
1579
if (!movePos.foundAntiDependenceCycle ) {
1573
1580
createPhiMove (builder, phiOperAddress, phiAddress);
0 commit comments